1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sc.hxx"
26
27
28
29 // INCLUDE ---------------------------------------------------------------
30
31 #include <svx/svdmark.hxx>
32 #include <svx/svdoole2.hxx>
33 #include <svx/svdview.hxx>
34 #include <sfx2/app.hxx>
35 #include <sfx2/objsh.hxx>
36 #include <sfx2/request.hxx>
37 #include <basic/sbxcore.hxx>
38 #include <svl/whiter.hxx>
39 #include <vcl/msgbox.hxx>
40
41 #include "tabvwsh.hxx"
42 #include "client.hxx"
43 #include "document.hxx"
44 #include "docsh.hxx"
45 #include "sc.hrc"
46 #include "drwlayer.hxx" // GetVisibleName
47 #include "retypepassdlg.hxx"
48 #include "tabprotection.hxx"
49
50 #include <memory>
51
52 using namespace com::sun::star;
53
54 //------------------------------------------------------------------
55
ExecuteSbx(SfxRequest &)56 void ScTabViewShell::ExecuteSbx( SfxRequest& /* rReq */ )
57 {
58 // SID_RANGE_OFFSET (Offset),
59 // SID_PIVOT_CREATE (DataPilotCreate) - removed (old Basic)
60 }
61
GetSbxState(SfxItemSet &)62 void ScTabViewShell::GetSbxState( SfxItemSet& /* rSet */ )
63 {
64 // SID_RANGE_REGION (CurrentRegion) - removed (old Basic)
65 }
66
67 //------------------------------------------------------------------
68
ExecuteObject(SfxRequest & rReq)69 void ScTabViewShell::ExecuteObject( SfxRequest& rReq )
70 {
71 sal_uInt16 nSlotId = rReq.GetSlot();
72 const SfxItemSet* pReqArgs = rReq.GetArgs();
73
74 // Objekte aktivieren/deaktivieren immer auf der sichtbaren View
75
76 ScTabViewShell* pVisibleSh = this;
77 if ( nSlotId == SID_OLE_SELECT || nSlotId == SID_OLE_ACTIVATE || nSlotId == SID_OLE_DEACTIVATE )
78 {
79 DBG_ERROR("old slot SID_OLE...");
80 }
81
82 switch (nSlotId)
83 {
84 case SID_OLE_SELECT:
85 case SID_OLE_ACTIVATE:
86 {
87 // in beiden Faellen erstmal auf der sichtbaren View selektieren
88
89 String aName;
90 SdrView* pDrView = GetSdrView();
91 if (pDrView)
92 {
93 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
94 if (rMarkList.GetMarkCount() == 1)
95 aName = ScDrawLayer::GetVisibleName( rMarkList.GetMark(0)->GetMarkedSdrObj() );
96 }
97 pVisibleSh->SelectObject( aName );
98
99 // aktivieren
100
101 if ( nSlotId == SID_OLE_ACTIVATE )
102 pVisibleSh->DoVerb( 0 );
103 }
104 break;
105 case SID_OLE_DEACTIVATE:
106 pVisibleSh->DeactivateOle();
107 break;
108
109 case SID_OBJECT_LEFT:
110 case SID_OBJECT_TOP:
111 case SID_OBJECT_WIDTH:
112 case SID_OBJECT_HEIGHT:
113 {
114 sal_Bool bDone = sal_False;
115 const SfxPoolItem* pItem;
116 if ( pReqArgs && pReqArgs->GetItemState( nSlotId, sal_True, &pItem ) == SFX_ITEM_SET )
117 {
118 long nNewVal = ((const SfxInt32Item*)pItem)->GetValue();
119 if ( nNewVal < 0 )
120 nNewVal = 0;
121
122 //! von irgendwas in 1/100mm umrechnen ??????
123
124 SdrView* pDrView = GetSdrView();
125 if ( pDrView )
126 {
127 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
128 if (rMarkList.GetMarkCount() == 1)
129 {
130 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
131 Rectangle aRect = pObj->GetLogicRect();
132
133 if ( nSlotId == SID_OBJECT_LEFT )
134 pDrView->MoveMarkedObj( Size( nNewVal - aRect.Left(), 0 ) );
135 else if ( nSlotId == SID_OBJECT_TOP )
136 pDrView->MoveMarkedObj( Size( 0, nNewVal - aRect.Top() ) );
137 else if ( nSlotId == SID_OBJECT_WIDTH )
138 pDrView->ResizeMarkedObj( aRect.TopLeft(),
139 Fraction( nNewVal, aRect.GetWidth() ),
140 Fraction( 1, 1 ) );
141 else // if ( nSlotId == SID_OBJECT_HEIGHT )
142 pDrView->ResizeMarkedObj( aRect.TopLeft(),
143 Fraction( 1, 1 ),
144 Fraction( nNewVal, aRect.GetHeight() ) );
145 bDone = sal_True;
146 }
147 }
148 }
149 if (!bDone)
150 SbxBase::SetError( SbxERR_BAD_PARAMETER ); // Basic-Fehler
151 }
152 break;
153
154 }
155 }
156
lcl_GetSelectedObj(SdrView * pDrView)157 uno::Reference < embed::XEmbeddedObject > lcl_GetSelectedObj( SdrView* pDrView ) //! Member von ScDrawView?
158 {
159 uno::Reference < embed::XEmbeddedObject > xRet;
160 if (pDrView)
161 {
162 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
163 if (rMarkList.GetMarkCount() == 1)
164 {
165 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
166 if (pObj->GetObjIdentifier() == OBJ_OLE2)
167 {
168 SdrOle2Obj* pOle2Obj = (SdrOle2Obj*) pObj;
169 xRet = pOle2Obj->GetObjRef();
170 }
171 }
172 }
173
174 return xRet;
175 }
176
GetObjectState(SfxItemSet & rSet)177 void ScTabViewShell::GetObjectState( SfxItemSet& rSet )
178 {
179 // SID_OLE_OBJECT - removed (old Basic)
180
181 SfxWhichIter aIter(rSet);
182 sal_uInt16 nWhich = aIter.FirstWhich();
183 while ( nWhich )
184 {
185 switch (nWhich)
186 {
187 case SID_ACTIVE_OBJ_NAME:
188 {
189 String aName;
190 uno::Reference < embed::XEmbeddedObject > xOLE = lcl_GetSelectedObj( GetSdrView() );
191 if (xOLE.is())
192 {
193 aName = GetViewData()->GetSfxDocShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xOLE );
194 }
195 rSet.Put( SfxStringItem( nWhich, aName ) );
196 }
197 break;
198 case SID_OBJECT_LEFT:
199 case SID_OBJECT_TOP:
200 case SID_OBJECT_WIDTH:
201 case SID_OBJECT_HEIGHT:
202 {
203 SdrView* pDrView = GetSdrView();
204 if ( pDrView )
205 {
206 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
207 if (rMarkList.GetMarkCount() == 1)
208 {
209 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
210 Rectangle aRect = pObj->GetLogicRect();
211
212 long nVal;
213 if ( nWhich == SID_OBJECT_LEFT )
214 nVal = aRect.Left();
215 else if ( nWhich == SID_OBJECT_TOP )
216 nVal = aRect.Top();
217 else if ( nWhich == SID_OBJECT_WIDTH )
218 nVal = aRect.GetWidth();
219 else // if ( nWhich == SID_OBJECT_HEIGHT )
220 nVal = aRect.GetHeight();
221
222 //! von 1/100mm in irgendwas umrechnen ??????
223
224 rSet.Put( SfxInt32Item( nWhich, nVal ) );
225 }
226 }
227 }
228 break;
229 }
230 nWhich = aIter.NextWhich();
231 }
232 }
233
AddAccessibilityObject(SfxListener & rObject)234 void ScTabViewShell::AddAccessibilityObject( SfxListener& rObject )
235 {
236 if (!pAccessibilityBroadcaster)
237 pAccessibilityBroadcaster = new SfxBroadcaster;
238
239 rObject.StartListening( *pAccessibilityBroadcaster );
240 ScDocument* pDoc = GetViewData()->GetDocument();
241 if (pDoc)
242 pDoc->AddUnoObject(rObject);
243 }
244
RemoveAccessibilityObject(SfxListener & rObject)245 void ScTabViewShell::RemoveAccessibilityObject( SfxListener& rObject )
246 {
247 if (pAccessibilityBroadcaster)
248 {
249 rObject.EndListening( *pAccessibilityBroadcaster );
250 ScDocument* pDoc = GetViewData()->GetDocument();
251 if (pDoc)
252 pDoc->RemoveUnoObject(rObject);
253 }
254 else
255 {
256 DBG_ERROR("kein Accessibility-Broadcaster?");
257 }
258 }
259
BroadcastAccessibility(const SfxHint & rHint)260 void ScTabViewShell::BroadcastAccessibility( const SfxHint &rHint )
261 {
262 if (pAccessibilityBroadcaster)
263 pAccessibilityBroadcaster->Broadcast( rHint );
264 }
265
HasAccessibilityObjects()266 sal_Bool ScTabViewShell::HasAccessibilityObjects()
267 {
268 return pAccessibilityBroadcaster != NULL;
269 }
270
ExecuteRetypePassDlg(ScPasswordHash eDesiredHash)271 bool ScTabViewShell::ExecuteRetypePassDlg(ScPasswordHash eDesiredHash)
272 {
273 using ::std::auto_ptr;
274
275 ScDocument* pDoc = GetViewData()->GetDocument();
276
277 auto_ptr<ScRetypePassDlg> pDlg(new ScRetypePassDlg(GetDialogParent()));
278 pDlg->SetDataFromDocument(*pDoc);
279 pDlg->SetDesiredHash(eDesiredHash);
280 if (pDlg->Execute() != RET_OK)
281 return false;
282
283 pDlg->WriteNewDataToDocument(*pDoc);
284 return true;
285 }
286
287
288
289
290