Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / view / tabvwshh.cxx
blob6aa43f3c2ebdec1a7aa89eb220fe86dea5fa90ea
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <config_features.h>
22 #include <svx/svdmark.hxx>
23 #include <svx/svdoole2.hxx>
24 #include <svx/svdview.hxx>
25 #include <sfx2/app.hxx>
26 #include <sfx2/objsh.hxx>
27 #include <sfx2/request.hxx>
28 #include <basic/sbxcore.hxx>
29 #include <svl/whiter.hxx>
30 #include <vcl/msgbox.hxx>
32 #include "tabvwsh.hxx"
33 #include "client.hxx"
34 #include "document.hxx"
35 #include "docsh.hxx"
36 #include "sc.hrc"
37 #include "drwlayer.hxx"
38 #include "retypepassdlg.hxx"
39 #include "tabprotection.hxx"
41 using namespace com::sun::star;
43 void ScTabViewShell::ExecuteSbx( SfxRequest& /* rReq */ )
45 // SID_RANGE_OFFSET (Offset),
46 // SID_PIVOT_CREATE (DataPilotCreate) - removed (old Basic)
49 void ScTabViewShell::GetSbxState( SfxItemSet& /* rSet */ )
51 // SID_RANGE_REGION (CurrentRegion) - removed (old Basic)
54 void ScTabViewShell::ExecuteObject( SfxRequest& rReq )
56 sal_uInt16 nSlotId = rReq.GetSlot();
57 const SfxItemSet* pReqArgs = rReq.GetArgs();
59 // Always activate/deactivate object in the visible View
61 ScTabViewShell* pVisibleSh = this;
62 if ( nSlotId == SID_OLE_SELECT || nSlotId == SID_OLE_ACTIVATE || nSlotId == SID_OLE_DEACTIVATE )
64 OSL_FAIL("old slot SID_OLE...");
67 switch (nSlotId)
69 case SID_OLE_SELECT:
70 case SID_OLE_ACTIVATE:
72 // In both cases, first select in the visible View
74 OUString aName;
75 SdrView* pDrView = GetSdrView();
76 if (pDrView)
78 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
79 if (rMarkList.GetMarkCount() == 1)
80 aName = ScDrawLayer::GetVisibleName( rMarkList.GetMark(0)->GetMarkedSdrObj() );
82 pVisibleSh->SelectObject( aName );
84 // activate
86 if ( nSlotId == SID_OLE_ACTIVATE )
87 pVisibleSh->DoVerb( 0 );
89 break;
90 case SID_OLE_DEACTIVATE:
91 pVisibleSh->DeactivateOle();
92 break;
94 case SID_OBJECT_LEFT:
95 case SID_OBJECT_TOP:
96 case SID_OBJECT_WIDTH:
97 case SID_OBJECT_HEIGHT:
99 bool bDone = false;
100 const SfxPoolItem* pItem;
101 if ( pReqArgs && pReqArgs->GetItemState( nSlotId, true, &pItem ) == SfxItemState::SET )
103 long nNewVal = static_cast<const SfxInt32Item*>(pItem)->GetValue();
104 if ( nNewVal < 0 )
105 nNewVal = 0;
107 //! convert from something into 1/100mm ??????
109 SdrView* pDrView = GetSdrView();
110 if ( pDrView )
112 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
113 if (rMarkList.GetMarkCount() == 1)
115 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
116 Rectangle aRect = pObj->GetLogicRect();
118 if ( nSlotId == SID_OBJECT_LEFT )
119 pDrView->MoveMarkedObj( Size( nNewVal - aRect.Left(), 0 ) );
120 else if ( nSlotId == SID_OBJECT_TOP )
121 pDrView->MoveMarkedObj( Size( 0, nNewVal - aRect.Top() ) );
122 else if ( nSlotId == SID_OBJECT_WIDTH )
123 pDrView->ResizeMarkedObj( aRect.TopLeft(),
124 Fraction( nNewVal, aRect.GetWidth() ),
125 Fraction( 1, 1 ) );
126 else // if ( nSlotId == SID_OBJECT_HEIGHT )
127 pDrView->ResizeMarkedObj( aRect.TopLeft(),
128 Fraction( 1, 1 ),
129 Fraction( nNewVal, aRect.GetHeight() ) );
130 bDone = true;
134 #if HAVE_FEATURE_SCRIPTING
135 if (!bDone)
136 SbxBase::SetError( ERRCODE_SBX_BAD_PARAMETER ); // basic error
137 #endif
139 break;
144 static uno::Reference < embed::XEmbeddedObject > lcl_GetSelectedObj( SdrView* pDrView ) //! member of ScDrawView?
146 uno::Reference < embed::XEmbeddedObject > xRet;
147 if (pDrView)
149 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
150 if (rMarkList.GetMarkCount() == 1)
152 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
153 if (pObj->GetObjIdentifier() == OBJ_OLE2)
155 SdrOle2Obj* pOle2Obj = static_cast<SdrOle2Obj*>(pObj);
156 xRet = pOle2Obj->GetObjRef();
161 return xRet;
164 void ScTabViewShell::GetObjectState( SfxItemSet& rSet )
166 // SID_OLE_OBJECT - removed (old Basic)
168 SfxWhichIter aIter(rSet);
169 sal_uInt16 nWhich = aIter.FirstWhich();
170 while ( nWhich )
172 switch (nWhich)
174 case SID_ACTIVE_OBJ_NAME:
176 OUString aName;
177 uno::Reference < embed::XEmbeddedObject > xOLE = lcl_GetSelectedObj( GetSdrView() );
178 if (xOLE.is())
180 aName = GetViewData().GetSfxDocShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xOLE );
182 rSet.Put( SfxStringItem( nWhich, aName ) );
184 break;
185 case SID_OBJECT_LEFT:
186 case SID_OBJECT_TOP:
187 case SID_OBJECT_WIDTH:
188 case SID_OBJECT_HEIGHT:
190 SdrView* pDrView = GetSdrView();
191 if ( pDrView )
193 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
194 if (rMarkList.GetMarkCount() == 1)
196 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
197 Rectangle aRect = pObj->GetLogicRect();
199 long nVal;
200 if ( nWhich == SID_OBJECT_LEFT )
201 nVal = aRect.Left();
202 else if ( nWhich == SID_OBJECT_TOP )
203 nVal = aRect.Top();
204 else if ( nWhich == SID_OBJECT_WIDTH )
205 nVal = aRect.GetWidth();
206 else // if ( nWhich == SID_OBJECT_HEIGHT )
207 nVal = aRect.GetHeight();
209 //! convert from 1/100mm to something else ??????
211 rSet.Put( SfxInt32Item( nWhich, nVal ) );
215 break;
217 nWhich = aIter.NextWhich();
221 void ScTabViewShell::AddAccessibilityObject( SfxListener& rObject )
223 if (!pAccessibilityBroadcaster)
224 pAccessibilityBroadcaster = new SfxBroadcaster;
226 rObject.StartListening( *pAccessibilityBroadcaster );
227 ScDocument* pDoc = GetViewData().GetDocument();
228 if (pDoc)
229 pDoc->AddUnoObject(rObject);
232 void ScTabViewShell::RemoveAccessibilityObject( SfxListener& rObject )
234 SolarMutexGuard g;
236 if (pAccessibilityBroadcaster)
238 rObject.EndListening( *pAccessibilityBroadcaster );
239 ScDocument* pDoc = GetViewData().GetDocument();
240 if (pDoc)
241 pDoc->RemoveUnoObject(rObject);
243 else
245 OSL_FAIL("no accessibility broadcaster?");
249 void ScTabViewShell::BroadcastAccessibility( const SfxHint &rHint )
251 if (pAccessibilityBroadcaster)
252 pAccessibilityBroadcaster->Broadcast( rHint );
255 bool ScTabViewShell::HasAccessibilityObjects()
257 return pAccessibilityBroadcaster != nullptr;
260 bool ScTabViewShell::ExecuteRetypePassDlg(ScPasswordHash eDesiredHash)
262 ScDocument* pDoc = GetViewData().GetDocument();
264 VclPtrInstance< ScRetypePassDlg > pDlg(GetDialogParent());
265 pDlg->SetDataFromDocument(*pDoc);
266 pDlg->SetDesiredHash(eDesiredHash);
267 if (pDlg->Execute() != RET_OK)
268 return false;
270 pDlg->WriteNewDataToDocument(*pDoc);
271 return true;
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */