LibreOffice Module sc (master)  1
tabvwshh.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <config_features.h>
21 
22 #include <basic/sberrors.hxx>
23 #include <svx/svdmark.hxx>
24 #include <svx/svdoole2.hxx>
25 #include <svx/svdview.hxx>
26 #include <sfx2/objsh.hxx>
27 #include <sfx2/request.hxx>
28 #include <basic/sbxcore.hxx>
29 #include <svl/stritem.hxx>
30 #include <svl/whiter.hxx>
31 #include <vcl/svapp.hxx>
32 
33 #include <tabvwsh.hxx>
34 #include <document.hxx>
35 #include <sc.hrc>
36 #include <drwlayer.hxx>
37 #include <retypepassdlg.hxx>
38 #include <tabprotection.hxx>
39 
40 using namespace com::sun::star;
41 
43 {
44  sal_uInt16 nSlotId = rReq.GetSlot();
45  const SfxItemSet* pReqArgs = rReq.GetArgs();
46 
47  // Always activate/deactivate object in the visible View
48 
49  ScTabViewShell* pVisibleSh = this;
50  if ( nSlotId == SID_OLE_SELECT || nSlotId == SID_OLE_ACTIVATE || nSlotId == SID_OLE_DEACTIVATE )
51  {
52  OSL_FAIL("old slot SID_OLE...");
53  }
54 
55  switch (nSlotId)
56  {
57  case SID_OLE_SELECT:
58  case SID_OLE_ACTIVATE:
59  {
60  // In both cases, first select in the visible View
61 
62  OUString aName;
63  SdrView* pDrView = GetScDrawView();
64  if (pDrView)
65  {
66  const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
67  if (rMarkList.GetMarkCount() == 1)
68  aName = ScDrawLayer::GetVisibleName( rMarkList.GetMark(0)->GetMarkedSdrObj() );
69  }
70  pVisibleSh->SelectObject( aName );
71 
72  // activate
73 
74  if ( nSlotId == SID_OLE_ACTIVATE )
75  pVisibleSh->DoVerb( 0 );
76  }
77  break;
78  case SID_OLE_DEACTIVATE:
79  pVisibleSh->DeactivateOle();
80  break;
81 
82  case SID_OBJECT_LEFT:
83  case SID_OBJECT_TOP:
84  case SID_OBJECT_WIDTH:
85  case SID_OBJECT_HEIGHT:
86  {
87  bool bDone = false;
88  const SfxPoolItem* pItem;
89  if ( pReqArgs && pReqArgs->GetItemState( nSlotId, true, &pItem ) == SfxItemState::SET )
90  {
91  tools::Long nNewVal = static_cast<const SfxInt32Item*>(pItem)->GetValue();
92  if ( nNewVal < 0 )
93  nNewVal = 0;
94 
96 
97  SdrView* pDrView = GetScDrawView();
98  if ( pDrView )
99  {
100  const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
101  if (rMarkList.GetMarkCount() == 1)
102  {
103  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
104  tools::Rectangle aRect = pObj->GetLogicRect();
105 
106  if ( nSlotId == SID_OBJECT_LEFT )
107  pDrView->MoveMarkedObj( Size( nNewVal - aRect.Left(), 0 ) );
108  else if ( nSlotId == SID_OBJECT_TOP )
109  pDrView->MoveMarkedObj( Size( 0, nNewVal - aRect.Top() ) );
110  else if ( nSlotId == SID_OBJECT_WIDTH )
111  pDrView->ResizeMarkedObj( aRect.TopLeft(),
112  Fraction( nNewVal, aRect.GetWidth() ),
113  Fraction( 1, 1 ) );
114  else // if ( nSlotId == SID_OBJECT_HEIGHT )
115  pDrView->ResizeMarkedObj( aRect.TopLeft(),
116  Fraction( 1, 1 ),
117  Fraction( nNewVal, aRect.GetHeight() ) );
118  bDone = true;
119  }
120  }
121  }
122 #if HAVE_FEATURE_SCRIPTING
123  if (!bDone)
125 #endif
126  }
127  break;
128 
129  }
130 }
131 
132 static uno::Reference < embed::XEmbeddedObject > lcl_GetSelectedObj( const SdrView* pDrView )
133 {
134  uno::Reference < embed::XEmbeddedObject > xRet;
135  if (pDrView)
136  {
137  const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
138  if (rMarkList.GetMarkCount() == 1)
139  {
140  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
141  if (pObj->GetObjIdentifier() == OBJ_OLE2)
142  {
143  SdrOle2Obj* pOle2Obj = static_cast<SdrOle2Obj*>(pObj);
144  xRet = pOle2Obj->GetObjRef();
145  }
146  }
147  }
148 
149  return xRet;
150 }
151 
153 {
154  SfxWhichIter aIter(rSet);
155  sal_uInt16 nWhich = aIter.FirstWhich();
156  while ( nWhich )
157  {
158  switch (nWhich)
159  {
160  case SID_ACTIVE_OBJ_NAME:
161  {
162  OUString aName;
163  uno::Reference < embed::XEmbeddedObject > xOLE = lcl_GetSelectedObj( GetScDrawView() );
164  if (xOLE.is())
165  {
166  aName = GetViewData().GetSfxDocShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xOLE );
167  }
168  rSet.Put( SfxStringItem( nWhich, aName ) );
169  }
170  break;
171  case SID_OBJECT_LEFT:
172  case SID_OBJECT_TOP:
173  case SID_OBJECT_WIDTH:
174  case SID_OBJECT_HEIGHT:
175  {
176  SdrView* pDrView = GetScDrawView();
177  if ( pDrView )
178  {
179  const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
180  if (rMarkList.GetMarkCount() == 1)
181  {
182  SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
183  tools::Rectangle aRect = pObj->GetLogicRect();
184 
185  tools::Long nVal;
186  if ( nWhich == SID_OBJECT_LEFT )
187  nVal = aRect.Left();
188  else if ( nWhich == SID_OBJECT_TOP )
189  nVal = aRect.Top();
190  else if ( nWhich == SID_OBJECT_WIDTH )
191  nVal = aRect.GetWidth();
192  else // if ( nWhich == SID_OBJECT_HEIGHT )
193  nVal = aRect.GetHeight();
194 
196 
197  rSet.Put( SfxInt32Item( nWhich, nVal ) );
198  }
199  }
200  }
201  break;
202  }
203  nWhich = aIter.NextWhich();
204  }
205 }
206 
208 {
209  if (!pAccessibilityBroadcaster)
210  pAccessibilityBroadcaster.reset( new SfxBroadcaster );
211 
212  rObject.StartListening( *pAccessibilityBroadcaster );
213  ScDocument& rDoc = GetViewData().GetDocument();
214  rDoc.AddUnoObject(rObject);
215 }
216 
218 {
219  SolarMutexGuard g;
220 
221  if (pAccessibilityBroadcaster)
222  {
223  rObject.EndListening( *pAccessibilityBroadcaster );
224  ScDocument& rDoc = GetViewData().GetDocument();
225  rDoc.RemoveUnoObject(rObject);
226  }
227  else
228  {
229  OSL_FAIL("no accessibility broadcaster?");
230  }
231 }
232 
234 {
235  if (pAccessibilityBroadcaster)
236  pAccessibilityBroadcaster->Broadcast( rHint );
237 }
238 
240 {
241  return pAccessibilityBroadcaster != nullptr;
242 }
243 
245 {
246  ScDocument& rDoc = GetViewData().GetDocument();
247 
249  aDlg.SetDataFromDocument(rDoc);
250  aDlg.SetDesiredHash(eDesiredHash);
251  if (aDlg.run() != RET_OK)
252  return false;
253 
254  aDlg.WriteNewDataToDocument(rDoc);
255  return true;
256 }
257 
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Point TopLeft() const
size_t GetMarkCount() const
OBJ_OLE2
css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef() const
std::string GetValue
void AddAccessibilityObject(SfxListener &rObject)
Definition: tabvwshh.cxx:207
long Long
void GetObjectState(SfxItemSet &rSet)
Definition: tabvwshh.cxx:152
sal_uInt16 FirstWhich()
bool ExecuteRetypePassDlg(ScPasswordHash eDesiredHash)
Definition: tabvwshh.cxx:244
tools::Long GetWidth() const
SdrMark * GetMark(size_t nNum) const
const SfxItemSet * GetArgs() const
sal_uInt16 NextWhich()
tools::Long Left() const
void BroadcastAccessibility(const SfxHint &rHint)
Definition: tabvwshh.cxx:233
void SetDataFromDocument(const ScDocument &rDoc)
virtual short run() override
void SetDesiredHash(ScPasswordHash eHash)
ScPasswordHash
static void SetError(ErrCode)
SdrObject * GetMarkedSdrObj() const
static uno::Reference< embed::XEmbeddedObject > lcl_GetSelectedObj(const SdrView *pDrView)
member of ScDrawView?
Definition: tabvwshh.cxx:132
void WriteNewDataToDocument(ScDocument &rDoc) const
Write the new set of password data to the document instance to overwrite the current ones...
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
void ResizeMarkedObj(const Point &rRef, const Fraction &xFact, const Fraction &yFact, bool bCopy=false)
virtual sal_uInt16 GetObjIdentifier() const
const SdrMarkList & GetMarkedObjectList() const
void ExecuteObject(const SfxRequest &rReq)
Definition: tabvwshh.cxx:42
virtual ErrCode DoVerb(tools::Long nVerb) override
Definition: tabvwshb.cxx:262
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
tools::Long Top() const
void DeactivateOle()
Definition: tabvwshb.cxx:290
void AddUnoObject(SfxListener &rObject)
Definition: documen3.cxx:893
#define ERRCODE_BASIC_BAD_PARAMETER
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_uInt16 GetSlot() const
bool HasAccessibilityObjects() const
Definition: tabvwshh.cxx:239
bool SelectObject(const OUString &rName)
Definition: tabvwsh2.cxx:449
void RemoveAccessibilityObject(SfxListener &rObject)
Definition: tabvwshh.cxx:217
OUString aName
RET_OK
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
void RemoveUnoObject(SfxListener &rObject)
Definition: documen3.cxx:901
static OUString GetVisibleName(const SdrObject *pObj)
Definition: drwlayer.cxx:1889
tools::Long GetHeight() const
virtual const tools::Rectangle & GetLogicRect() const
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
void MoveMarkedObj(const Size &rSiz, bool bCopy=false)