1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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...");
62 case SID_OLE_ACTIVATE
:
64 // In both cases, first select in the visible View
67 SdrView
* pDrView
= GetScDrawView();
70 const SdrMarkList
& rMarkList
= pDrView
->GetMarkedObjectList();
71 if (rMarkList
.GetMarkCount() == 1)
72 aName
= ScDrawLayer::GetVisibleName( rMarkList
.GetMark(0)->GetMarkedSdrObj() );
74 pVisibleSh
->SelectObject( aName
);
78 if ( nSlotId
== SID_OLE_ACTIVATE
)
79 pVisibleSh
->DoVerb(css::embed::EmbedVerbs::MS_OLEVERB_PRIMARY
);
82 case SID_OLE_DEACTIVATE
:
83 pVisibleSh
->DeactivateOle();
88 case SID_OBJECT_WIDTH
:
89 case SID_OBJECT_HEIGHT
:
92 const SfxPoolItem
* pItem
;
93 if ( pReqArgs
&& pReqArgs
->GetItemState( nSlotId
, true, &pItem
) == SfxItemState::SET
)
95 tools::Long nNewVal
= static_cast<const SfxInt32Item
*>(pItem
)->GetValue();
99 //! convert from something into 1/100mm ??????
101 SdrView
* pDrView
= GetScDrawView();
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() ),
118 else // if ( nSlotId == SID_OBJECT_HEIGHT )
119 pDrView
->ResizeMarkedObj( aRect
.TopLeft(),
121 Fraction( nNewVal
, aRect
.GetHeight() ) );
126 #if HAVE_FEATURE_SCRIPTING
128 SbxBase::SetError( ERRCODE_BASIC_BAD_PARAMETER
); // basic error
138 static uno::Reference
< embed::XEmbeddedObject
> lcl_GetSelectedObj( const SdrView
* pDrView
) //! member of ScDrawView?
140 uno::Reference
< embed::XEmbeddedObject
> xRet
;
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();
158 void ScTabViewShell::GetObjectState( SfxItemSet
& rSet
)
160 SfxWhichIter
aIter(rSet
);
161 sal_uInt16 nWhich
= aIter
.FirstWhich();
166 case SID_ACTIVE_OBJ_NAME
:
169 uno::Reference
< embed::XEmbeddedObject
> xOLE
= lcl_GetSelectedObj( GetScDrawView() );
172 aName
= GetViewData().GetSfxDocShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xOLE
);
174 rSet
.Put( SfxStringItem( nWhich
, aName
) );
177 case SID_OBJECT_LEFT
:
179 case SID_OBJECT_WIDTH
:
180 case SID_OBJECT_HEIGHT
:
182 SdrView
* pDrView
= GetScDrawView();
185 const SdrMarkList
& rMarkList
= pDrView
->GetMarkedObjectList();
186 if (rMarkList
.GetMarkCount() == 1)
188 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
189 tools::Rectangle aRect
= pObj
->GetLogicRect();
192 if ( nWhich
== SID_OBJECT_LEFT
)
194 else if ( nWhich
== SID_OBJECT_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
) );
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
)
227 if (pAccessibilityBroadcaster
)
229 rObject
.EndListening( *pAccessibilityBroadcaster
);
230 ScDocument
& rDoc
= GetViewData().GetDocument();
231 rDoc
.RemoveUnoObject(rObject
);
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
)
260 aDlg
.WriteNewDataToDocument(rDoc
);
264 void ScTabViewShell::ExecuteOnlyActiveSheetSavedDlg()
266 ScOnlyActiveSheetSavedDlg
aDlg(GetFrameWeld());
270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */