Line data Source code
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 <svx/svdmark.hxx>
21 : #include <svx/svdoole2.hxx>
22 : #include <svx/svdview.hxx>
23 : #include <sfx2/app.hxx>
24 : #include <sfx2/objsh.hxx>
25 : #include <sfx2/request.hxx>
26 : #include <basic/sbxcore.hxx>
27 : #include <svl/whiter.hxx>
28 : #include <vcl/msgbox.hxx>
29 :
30 : #include "tabvwsh.hxx"
31 : #include "client.hxx"
32 : #include "document.hxx"
33 : #include "docsh.hxx"
34 : #include "sc.hrc"
35 : #include "drwlayer.hxx" // GetVisibleName
36 : #include "retypepassdlg.hxx"
37 : #include "tabprotection.hxx"
38 :
39 : #include <memory>
40 :
41 : using namespace com::sun::star;
42 :
43 : //------------------------------------------------------------------
44 :
45 0 : void ScTabViewShell::ExecuteSbx( SfxRequest& /* rReq */ )
46 : {
47 : // SID_RANGE_OFFSET (Offset),
48 : // SID_PIVOT_CREATE (DataPilotCreate) - removed (old Basic)
49 0 : }
50 :
51 0 : void ScTabViewShell::GetSbxState( SfxItemSet& /* rSet */ )
52 : {
53 : // SID_RANGE_REGION (CurrentRegion) - removed (old Basic)
54 0 : }
55 :
56 : //------------------------------------------------------------------
57 :
58 0 : void ScTabViewShell::ExecuteObject( SfxRequest& rReq )
59 : {
60 0 : sal_uInt16 nSlotId = rReq.GetSlot();
61 0 : const SfxItemSet* pReqArgs = rReq.GetArgs();
62 :
63 : // Objekte aktivieren/deaktivieren immer auf der sichtbaren View
64 :
65 0 : ScTabViewShell* pVisibleSh = this;
66 : if ( nSlotId == SID_OLE_SELECT || nSlotId == SID_OLE_ACTIVATE || nSlotId == SID_OLE_DEACTIVATE )
67 : {
68 : OSL_FAIL("old slot SID_OLE...");
69 : }
70 :
71 0 : switch (nSlotId)
72 : {
73 : case SID_OLE_SELECT:
74 : case SID_OLE_ACTIVATE:
75 : {
76 : // in beiden Faellen erstmal auf der sichtbaren View selektieren
77 :
78 0 : String aName;
79 0 : SdrView* pDrView = GetSdrView();
80 0 : if (pDrView)
81 : {
82 0 : const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
83 0 : if (rMarkList.GetMarkCount() == 1)
84 0 : aName = ScDrawLayer::GetVisibleName( rMarkList.GetMark(0)->GetMarkedSdrObj() );
85 : }
86 0 : pVisibleSh->SelectObject( aName );
87 :
88 : // aktivieren
89 :
90 0 : if ( nSlotId == SID_OLE_ACTIVATE )
91 0 : pVisibleSh->DoVerb( 0 );
92 : }
93 0 : break;
94 : case SID_OLE_DEACTIVATE:
95 0 : pVisibleSh->DeactivateOle();
96 0 : break;
97 :
98 : case SID_OBJECT_LEFT:
99 : case SID_OBJECT_TOP:
100 : case SID_OBJECT_WIDTH:
101 : case SID_OBJECT_HEIGHT:
102 : {
103 0 : sal_Bool bDone = false;
104 : const SfxPoolItem* pItem;
105 0 : if ( pReqArgs && pReqArgs->GetItemState( nSlotId, sal_True, &pItem ) == SFX_ITEM_SET )
106 : {
107 0 : long nNewVal = ((const SfxInt32Item*)pItem)->GetValue();
108 0 : if ( nNewVal < 0 )
109 0 : nNewVal = 0;
110 :
111 : //! von irgendwas in 1/100mm umrechnen ??????
112 :
113 0 : SdrView* pDrView = GetSdrView();
114 0 : if ( pDrView )
115 : {
116 0 : const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
117 0 : if (rMarkList.GetMarkCount() == 1)
118 : {
119 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
120 0 : Rectangle aRect = pObj->GetLogicRect();
121 :
122 0 : if ( nSlotId == SID_OBJECT_LEFT )
123 0 : pDrView->MoveMarkedObj( Size( nNewVal - aRect.Left(), 0 ) );
124 0 : else if ( nSlotId == SID_OBJECT_TOP )
125 0 : pDrView->MoveMarkedObj( Size( 0, nNewVal - aRect.Top() ) );
126 0 : else if ( nSlotId == SID_OBJECT_WIDTH )
127 : pDrView->ResizeMarkedObj( aRect.TopLeft(),
128 : Fraction( nNewVal, aRect.GetWidth() ),
129 0 : Fraction( 1, 1 ) );
130 : else // if ( nSlotId == SID_OBJECT_HEIGHT )
131 : pDrView->ResizeMarkedObj( aRect.TopLeft(),
132 : Fraction( 1, 1 ),
133 0 : Fraction( nNewVal, aRect.GetHeight() ) );
134 0 : bDone = sal_True;
135 : }
136 : }
137 : }
138 : #ifndef DISABLE_SCRIPTING
139 0 : if (!bDone)
140 0 : SbxBase::SetError( SbxERR_BAD_PARAMETER ); // Basic-Fehler
141 : #endif
142 : }
143 0 : break;
144 :
145 : }
146 0 : }
147 :
148 0 : static uno::Reference < embed::XEmbeddedObject > lcl_GetSelectedObj( SdrView* pDrView ) //! Member von ScDrawView?
149 : {
150 0 : uno::Reference < embed::XEmbeddedObject > xRet;
151 0 : if (pDrView)
152 : {
153 0 : const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
154 0 : if (rMarkList.GetMarkCount() == 1)
155 : {
156 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
157 0 : if (pObj->GetObjIdentifier() == OBJ_OLE2)
158 : {
159 0 : SdrOle2Obj* pOle2Obj = (SdrOle2Obj*) pObj;
160 0 : xRet = pOle2Obj->GetObjRef();
161 : }
162 : }
163 : }
164 :
165 0 : return xRet;
166 : }
167 :
168 0 : void ScTabViewShell::GetObjectState( SfxItemSet& rSet )
169 : {
170 : // SID_OLE_OBJECT - removed (old Basic)
171 :
172 0 : SfxWhichIter aIter(rSet);
173 0 : sal_uInt16 nWhich = aIter.FirstWhich();
174 0 : while ( nWhich )
175 : {
176 0 : switch (nWhich)
177 : {
178 : case SID_ACTIVE_OBJ_NAME:
179 : {
180 0 : String aName;
181 0 : uno::Reference < embed::XEmbeddedObject > xOLE = lcl_GetSelectedObj( GetSdrView() );
182 0 : if (xOLE.is())
183 : {
184 0 : aName = GetViewData()->GetSfxDocShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xOLE );
185 : }
186 0 : rSet.Put( SfxStringItem( nWhich, aName ) );
187 : }
188 0 : break;
189 : case SID_OBJECT_LEFT:
190 : case SID_OBJECT_TOP:
191 : case SID_OBJECT_WIDTH:
192 : case SID_OBJECT_HEIGHT:
193 : {
194 0 : SdrView* pDrView = GetSdrView();
195 0 : if ( pDrView )
196 : {
197 0 : const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
198 0 : if (rMarkList.GetMarkCount() == 1)
199 : {
200 0 : SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
201 0 : Rectangle aRect = pObj->GetLogicRect();
202 :
203 : long nVal;
204 0 : if ( nWhich == SID_OBJECT_LEFT )
205 0 : nVal = aRect.Left();
206 0 : else if ( nWhich == SID_OBJECT_TOP )
207 0 : nVal = aRect.Top();
208 0 : else if ( nWhich == SID_OBJECT_WIDTH )
209 0 : nVal = aRect.GetWidth();
210 : else // if ( nWhich == SID_OBJECT_HEIGHT )
211 0 : nVal = aRect.GetHeight();
212 :
213 : //! von 1/100mm in irgendwas umrechnen ??????
214 :
215 0 : rSet.Put( SfxInt32Item( nWhich, nVal ) );
216 : }
217 : }
218 : }
219 0 : break;
220 : }
221 0 : nWhich = aIter.NextWhich();
222 0 : }
223 0 : }
224 :
225 0 : void ScTabViewShell::AddAccessibilityObject( SfxListener& rObject )
226 : {
227 0 : if (!pAccessibilityBroadcaster)
228 0 : pAccessibilityBroadcaster = new SfxBroadcaster;
229 :
230 0 : rObject.StartListening( *pAccessibilityBroadcaster );
231 0 : ScDocument* pDoc = GetViewData()->GetDocument();
232 0 : if (pDoc)
233 0 : pDoc->AddUnoObject(rObject);
234 0 : }
235 :
236 0 : void ScTabViewShell::RemoveAccessibilityObject( SfxListener& rObject )
237 : {
238 0 : if (pAccessibilityBroadcaster)
239 : {
240 0 : rObject.EndListening( *pAccessibilityBroadcaster );
241 0 : ScDocument* pDoc = GetViewData()->GetDocument();
242 0 : if (pDoc)
243 0 : pDoc->RemoveUnoObject(rObject);
244 : }
245 : else
246 : {
247 : OSL_FAIL("kein Accessibility-Broadcaster?");
248 : }
249 0 : }
250 :
251 0 : void ScTabViewShell::BroadcastAccessibility( const SfxHint &rHint )
252 : {
253 0 : if (pAccessibilityBroadcaster)
254 0 : pAccessibilityBroadcaster->Broadcast( rHint );
255 0 : }
256 :
257 0 : sal_Bool ScTabViewShell::HasAccessibilityObjects()
258 : {
259 0 : return pAccessibilityBroadcaster != NULL;
260 : }
261 :
262 0 : bool ScTabViewShell::ExecuteRetypePassDlg(ScPasswordHash eDesiredHash)
263 : {
264 : using ::std::auto_ptr;
265 :
266 0 : ScDocument* pDoc = GetViewData()->GetDocument();
267 :
268 0 : auto_ptr<ScRetypePassDlg> pDlg(new ScRetypePassDlg(GetDialogParent()));
269 0 : pDlg->SetDataFromDocument(*pDoc);
270 0 : pDlg->SetDesiredHash(eDesiredHash);
271 0 : if (pDlg->Execute() != RET_OK)
272 0 : return false;
273 :
274 0 : pDlg->WriteNewDataToDocument(*pDoc);
275 0 : return true;
276 15 : }
277 :
278 :
279 :
280 :
281 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|