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 #include <osl/diagnose.h>
33
34 #include <tabvwsh.hxx>
35 #include <document.hxx>
36 #include <sc.hrc>
37 #include <drwlayer.hxx>
38 #include <retypepassdlg.hxx>
39 #include <tabprotection.hxx>
40
41 #include <com/sun/star/embed/EmbedVerbs.hpp>
42
43 using namespace com::sun::star;
44
ExecuteObject(const SfxRequest & rReq)45 void ScTabViewShell::ExecuteObject( const SfxRequest& rReq )
46 {
47 sal_uInt16 nSlotId = rReq.GetSlot();
48 const SfxItemSet* pReqArgs = rReq.GetArgs();
49
50 // Always activate/deactivate object in the visible View
51
52 ScTabViewShell* pVisibleSh = this;
53 if ( nSlotId == SID_OLE_SELECT || nSlotId == SID_OLE_ACTIVATE || nSlotId == SID_OLE_DEACTIVATE )
54 {
55 OSL_FAIL("old slot SID_OLE...");
56 }
57
58 switch (nSlotId)
59 {
60 case SID_OLE_SELECT:
61 case SID_OLE_ACTIVATE:
62 {
63 // In both cases, first select in the visible View
64
65 OUString aName;
66 SdrView* pDrView = GetScDrawView();
67 if (pDrView)
68 {
69 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
70 if (rMarkList.GetMarkCount() == 1)
71 aName = ScDrawLayer::GetVisibleName( rMarkList.GetMark(0)->GetMarkedSdrObj() );
72 }
73 pVisibleSh->SelectObject( aName );
74
75 // activate
76
77 if ( nSlotId == SID_OLE_ACTIVATE )
78 pVisibleSh->DoVerb(css::embed::EmbedVerbs::MS_OLEVERB_PRIMARY);
79 }
80 break;
81 case SID_OLE_DEACTIVATE:
82 pVisibleSh->DeactivateOle();
83 break;
84
85 case SID_OBJECT_LEFT:
86 case SID_OBJECT_TOP:
87 case SID_OBJECT_WIDTH:
88 case SID_OBJECT_HEIGHT:
89 {
90 bool bDone = false;
91 const SfxPoolItem* pItem;
92 if ( pReqArgs && pReqArgs->GetItemState( nSlotId, true, &pItem ) == SfxItemState::SET )
93 {
94 tools::Long nNewVal = static_cast<const SfxInt32Item*>(pItem)->GetValue();
95 if ( nNewVal < 0 )
96 nNewVal = 0;
97
98 //! convert from something into 1/100mm ??????
99
100 SdrView* pDrView = GetScDrawView();
101 if ( pDrView )
102 {
103 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
104 if (rMarkList.GetMarkCount() == 1)
105 {
106 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
107 tools::Rectangle aRect = pObj->GetLogicRect();
108
109 if ( nSlotId == SID_OBJECT_LEFT )
110 pDrView->MoveMarkedObj( Size( nNewVal - aRect.Left(), 0 ) );
111 else if ( nSlotId == SID_OBJECT_TOP )
112 pDrView->MoveMarkedObj( Size( 0, nNewVal - aRect.Top() ) );
113 else if ( nSlotId == SID_OBJECT_WIDTH )
114 pDrView->ResizeMarkedObj( aRect.TopLeft(),
115 Fraction( nNewVal, aRect.GetWidth() ),
116 Fraction( 1, 1 ) );
117 else // if ( nSlotId == SID_OBJECT_HEIGHT )
118 pDrView->ResizeMarkedObj( aRect.TopLeft(),
119 Fraction( 1, 1 ),
120 Fraction( nNewVal, aRect.GetHeight() ) );
121 bDone = true;
122 }
123 }
124 }
125 #if HAVE_FEATURE_SCRIPTING
126 if (!bDone)
127 SbxBase::SetError( ERRCODE_BASIC_BAD_PARAMETER ); // basic error
128 #endif
129 }
130 break;
131
132 }
133 }
134
lcl_GetSelectedObj(const SdrView * pDrView)135 static uno::Reference < embed::XEmbeddedObject > lcl_GetSelectedObj( const SdrView* pDrView ) //! member of ScDrawView?
136 {
137 uno::Reference < embed::XEmbeddedObject > xRet;
138 if (pDrView)
139 {
140 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
141 if (rMarkList.GetMarkCount() == 1)
142 {
143 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
144 if (pObj->GetObjIdentifier() == OBJ_OLE2)
145 {
146 SdrOle2Obj* pOle2Obj = static_cast<SdrOle2Obj*>(pObj);
147 xRet = pOle2Obj->GetObjRef();
148 }
149 }
150 }
151
152 return xRet;
153 }
154
GetObjectState(SfxItemSet & rSet)155 void ScTabViewShell::GetObjectState( SfxItemSet& rSet )
156 {
157 SfxWhichIter aIter(rSet);
158 sal_uInt16 nWhich = aIter.FirstWhich();
159 while ( nWhich )
160 {
161 switch (nWhich)
162 {
163 case SID_ACTIVE_OBJ_NAME:
164 {
165 OUString aName;
166 uno::Reference < embed::XEmbeddedObject > xOLE = lcl_GetSelectedObj( GetScDrawView() );
167 if (xOLE.is())
168 {
169 aName = GetViewData().GetSfxDocShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xOLE );
170 }
171 rSet.Put( SfxStringItem( nWhich, aName ) );
172 }
173 break;
174 case SID_OBJECT_LEFT:
175 case SID_OBJECT_TOP:
176 case SID_OBJECT_WIDTH:
177 case SID_OBJECT_HEIGHT:
178 {
179 SdrView* pDrView = GetScDrawView();
180 if ( pDrView )
181 {
182 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
183 if (rMarkList.GetMarkCount() == 1)
184 {
185 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
186 tools::Rectangle aRect = pObj->GetLogicRect();
187
188 tools::Long nVal;
189 if ( nWhich == SID_OBJECT_LEFT )
190 nVal = aRect.Left();
191 else if ( nWhich == SID_OBJECT_TOP )
192 nVal = aRect.Top();
193 else if ( nWhich == SID_OBJECT_WIDTH )
194 nVal = aRect.GetWidth();
195 else // if ( nWhich == SID_OBJECT_HEIGHT )
196 nVal = aRect.GetHeight();
197
198 //! convert from 1/100mm to something else ??????
199
200 rSet.Put( SfxInt32Item( nWhich, nVal ) );
201 }
202 }
203 }
204 break;
205 }
206 nWhich = aIter.NextWhich();
207 }
208 }
209
AddAccessibilityObject(SfxListener & rObject)210 void ScTabViewShell::AddAccessibilityObject( SfxListener& rObject )
211 {
212 if (!pAccessibilityBroadcaster)
213 pAccessibilityBroadcaster.reset( new SfxBroadcaster );
214
215 rObject.StartListening( *pAccessibilityBroadcaster );
216 ScDocument& rDoc = GetViewData().GetDocument();
217 rDoc.AddUnoObject(rObject);
218 }
219
RemoveAccessibilityObject(SfxListener & rObject)220 void ScTabViewShell::RemoveAccessibilityObject( SfxListener& rObject )
221 {
222 SolarMutexGuard g;
223
224 if (pAccessibilityBroadcaster)
225 {
226 rObject.EndListening( *pAccessibilityBroadcaster );
227 ScDocument& rDoc = GetViewData().GetDocument();
228 rDoc.RemoveUnoObject(rObject);
229 }
230 else
231 {
232 OSL_FAIL("no accessibility broadcaster?");
233 }
234 }
235
BroadcastAccessibility(const SfxHint & rHint)236 void ScTabViewShell::BroadcastAccessibility( const SfxHint &rHint )
237 {
238 if (pAccessibilityBroadcaster)
239 pAccessibilityBroadcaster->Broadcast( rHint );
240 }
241
HasAccessibilityObjects() const242 bool ScTabViewShell::HasAccessibilityObjects() const
243 {
244 return pAccessibilityBroadcaster != nullptr;
245 }
246
ExecuteRetypePassDlg(ScPasswordHash eDesiredHash)247 bool ScTabViewShell::ExecuteRetypePassDlg(ScPasswordHash eDesiredHash)
248 {
249 ScDocument& rDoc = GetViewData().GetDocument();
250
251 ScRetypePassDlg aDlg(GetFrameWeld());
252 aDlg.SetDataFromDocument(rDoc);
253 aDlg.SetDesiredHash(eDesiredHash);
254 if (aDlg.run() != RET_OK)
255 return false;
256
257 aDlg.WriteNewDataToDocument(rDoc);
258 return true;
259 }
260
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
262