tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / sc / source / ui / view / tabvwshh.cxx
blobd82be8b084bc0ac35285aee65e925a354ecdbc68
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 <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>
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 #include <onlyactivesheetsaveddlg.hxx>
42 #include <com/sun/star/embed/EmbedVerbs.hpp>
44 using namespace com::sun::star;
46 void ScTabViewShell::ExecuteObject( const SfxRequest& rReq )
48 sal_uInt16 nSlotId = rReq.GetSlot();
49 const SfxItemSet* pReqArgs = rReq.GetArgs();
51 // Always activate/deactivate object in the visible View
53 ScTabViewShell* pVisibleSh = this;
54 if ( nSlotId == SID_OLE_SELECT || nSlotId == SID_OLE_ACTIVATE || nSlotId == SID_OLE_DEACTIVATE )
56 OSL_FAIL("old slot SID_OLE...");
59 switch (nSlotId)
61 case SID_OLE_SELECT:
62 case SID_OLE_ACTIVATE:
64 // In both cases, first select in the visible View
66 OUString aName;
67 SdrView* pDrView = GetScDrawView();
68 if (pDrView)
70 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
71 if (rMarkList.GetMarkCount() == 1)
72 aName = ScDrawLayer::GetVisibleName( rMarkList.GetMark(0)->GetMarkedSdrObj() );
74 pVisibleSh->SelectObject( aName );
76 // activate
78 if ( nSlotId == SID_OLE_ACTIVATE )
79 pVisibleSh->DoVerb(css::embed::EmbedVerbs::MS_OLEVERB_PRIMARY);
81 break;
82 case SID_OLE_DEACTIVATE:
83 pVisibleSh->DeactivateOle();
84 break;
86 case SID_OBJECT_LEFT:
87 case SID_OBJECT_TOP:
88 case SID_OBJECT_WIDTH:
89 case SID_OBJECT_HEIGHT:
91 bool bDone = false;
92 const SfxPoolItem* pItem;
93 if ( pReqArgs && pReqArgs->GetItemState( nSlotId, true, &pItem ) == SfxItemState::SET )
95 tools::Long nNewVal = static_cast<const SfxInt32Item*>(pItem)->GetValue();
96 if ( nNewVal < 0 )
97 nNewVal = 0;
99 //! convert from something into 1/100mm ??????
101 SdrView* pDrView = GetScDrawView();
102 if ( pDrView )
104 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
105 if (rMarkList.GetMarkCount() == 1)
107 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
108 tools::Rectangle aRect = pObj->GetLogicRect();
110 if ( nSlotId == SID_OBJECT_LEFT )
111 pDrView->MoveMarkedObj( Size( nNewVal - aRect.Left(), 0 ) );
112 else if ( nSlotId == SID_OBJECT_TOP )
113 pDrView->MoveMarkedObj( Size( 0, nNewVal - aRect.Top() ) );
114 else if ( nSlotId == SID_OBJECT_WIDTH )
115 pDrView->ResizeMarkedObj( aRect.TopLeft(),
116 Fraction( nNewVal, aRect.GetWidth() ),
117 Fraction( 1, 1 ) );
118 else // if ( nSlotId == SID_OBJECT_HEIGHT )
119 pDrView->ResizeMarkedObj( aRect.TopLeft(),
120 Fraction( 1, 1 ),
121 Fraction( nNewVal, aRect.GetHeight() ) );
122 bDone = true;
126 #if HAVE_FEATURE_SCRIPTING
127 if (!bDone)
128 SbxBase::SetError( ERRCODE_BASIC_BAD_PARAMETER ); // basic error
129 #else
130 (void)bDone;
131 #endif
133 break;
138 static uno::Reference < embed::XEmbeddedObject > lcl_GetSelectedObj( const SdrView* pDrView ) //! member of ScDrawView?
140 uno::Reference < embed::XEmbeddedObject > xRet;
141 if (pDrView)
143 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
144 if (rMarkList.GetMarkCount() == 1)
146 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
147 if (pObj->GetObjIdentifier() == SdrObjKind::OLE2)
149 SdrOle2Obj* pOle2Obj = static_cast<SdrOle2Obj*>(pObj);
150 xRet = pOle2Obj->GetObjRef();
155 return xRet;
158 void ScTabViewShell::GetObjectState( SfxItemSet& rSet )
160 SfxWhichIter aIter(rSet);
161 sal_uInt16 nWhich = aIter.FirstWhich();
162 while ( nWhich )
164 switch (nWhich)
166 case SID_ACTIVE_OBJ_NAME:
168 OUString aName;
169 uno::Reference < embed::XEmbeddedObject > xOLE = lcl_GetSelectedObj( GetScDrawView() );
170 if (xOLE.is())
172 aName = GetViewData().GetSfxDocShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xOLE );
174 rSet.Put( SfxStringItem( nWhich, aName ) );
176 break;
177 case SID_OBJECT_LEFT:
178 case SID_OBJECT_TOP:
179 case SID_OBJECT_WIDTH:
180 case SID_OBJECT_HEIGHT:
182 SdrView* pDrView = GetScDrawView();
183 if ( pDrView )
185 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
186 if (rMarkList.GetMarkCount() == 1)
188 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
189 tools::Rectangle aRect = pObj->GetLogicRect();
191 tools::Long nVal;
192 if ( nWhich == SID_OBJECT_LEFT )
193 nVal = aRect.Left();
194 else if ( nWhich == SID_OBJECT_TOP )
195 nVal = aRect.Top();
196 else if ( nWhich == SID_OBJECT_WIDTH )
197 nVal = aRect.GetWidth();
198 else // if ( nWhich == SID_OBJECT_HEIGHT )
199 nVal = aRect.GetHeight();
201 //! convert from 1/100mm to something else ??????
203 rSet.Put( SfxInt32Item( TypedWhichId<SfxInt32Item>(nWhich), nVal ) );
207 break;
209 nWhich = aIter.NextWhich();
213 void ScTabViewShell::AddAccessibilityObject( SfxListener& rObject )
215 if (!pAccessibilityBroadcaster)
216 pAccessibilityBroadcaster.reset( new SfxBroadcaster );
218 rObject.StartListening( *pAccessibilityBroadcaster );
219 ScDocument& rDoc = GetViewData().GetDocument();
220 rDoc.AddUnoObject(rObject);
223 void ScTabViewShell::RemoveAccessibilityObject( SfxListener& rObject )
225 SolarMutexGuard g;
227 if (pAccessibilityBroadcaster)
229 rObject.EndListening( *pAccessibilityBroadcaster );
230 ScDocument& rDoc = GetViewData().GetDocument();
231 rDoc.RemoveUnoObject(rObject);
233 else
235 OSL_FAIL("no accessibility broadcaster?");
239 void ScTabViewShell::BroadcastAccessibility( const SfxHint &rHint )
241 if (pAccessibilityBroadcaster)
242 pAccessibilityBroadcaster->Broadcast( rHint );
245 bool ScTabViewShell::HasAccessibilityObjects() const
247 return pAccessibilityBroadcaster && pAccessibilityBroadcaster->HasListeners();
250 bool ScTabViewShell::ExecuteRetypePassDlg(ScPasswordHash eDesiredHash)
252 ScDocument& rDoc = GetViewData().GetDocument();
254 ScRetypePassDlg aDlg(GetFrameWeld());
255 aDlg.SetDataFromDocument(rDoc);
256 aDlg.SetDesiredHash(eDesiredHash);
257 if (aDlg.run() != RET_OK)
258 return false;
260 aDlg.WriteNewDataToDocument(rDoc);
261 return true;
264 void ScTabViewShell::ExecuteOnlyActiveSheetSavedDlg()
266 ScOnlyActiveSheetSavedDlg aDlg(GetFrameWeld());
267 aDlg.run();
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */