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 <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"
34 #include "document.hxx"
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...");
70 case SID_OLE_ACTIVATE
:
72 // In both cases, first select in the visible View
75 SdrView
* pDrView
= GetSdrView();
78 const SdrMarkList
& rMarkList
= pDrView
->GetMarkedObjectList();
79 if (rMarkList
.GetMarkCount() == 1)
80 aName
= ScDrawLayer::GetVisibleName( rMarkList
.GetMark(0)->GetMarkedSdrObj() );
82 pVisibleSh
->SelectObject( aName
);
86 if ( nSlotId
== SID_OLE_ACTIVATE
)
87 pVisibleSh
->DoVerb( 0 );
90 case SID_OLE_DEACTIVATE
:
91 pVisibleSh
->DeactivateOle();
96 case SID_OBJECT_WIDTH
:
97 case SID_OBJECT_HEIGHT
:
100 const SfxPoolItem
* pItem
;
101 if ( pReqArgs
&& pReqArgs
->GetItemState( nSlotId
, true, &pItem
) == SfxItemState::SET
)
103 long nNewVal
= static_cast<const SfxInt32Item
*>(pItem
)->GetValue();
107 //! convert from something into 1/100mm ??????
109 SdrView
* pDrView
= GetSdrView();
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() ),
126 else // if ( nSlotId == SID_OBJECT_HEIGHT )
127 pDrView
->ResizeMarkedObj( aRect
.TopLeft(),
129 Fraction( nNewVal
, aRect
.GetHeight() ) );
134 #if HAVE_FEATURE_SCRIPTING
136 SbxBase::SetError( ERRCODE_SBX_BAD_PARAMETER
); // basic error
144 static uno::Reference
< embed::XEmbeddedObject
> lcl_GetSelectedObj( SdrView
* pDrView
) //! member of ScDrawView?
146 uno::Reference
< embed::XEmbeddedObject
> xRet
;
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();
164 void ScTabViewShell::GetObjectState( SfxItemSet
& rSet
)
166 // SID_OLE_OBJECT - removed (old Basic)
168 SfxWhichIter
aIter(rSet
);
169 sal_uInt16 nWhich
= aIter
.FirstWhich();
174 case SID_ACTIVE_OBJ_NAME
:
177 uno::Reference
< embed::XEmbeddedObject
> xOLE
= lcl_GetSelectedObj( GetSdrView() );
180 aName
= GetViewData().GetSfxDocShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xOLE
);
182 rSet
.Put( SfxStringItem( nWhich
, aName
) );
185 case SID_OBJECT_LEFT
:
187 case SID_OBJECT_WIDTH
:
188 case SID_OBJECT_HEIGHT
:
190 SdrView
* pDrView
= GetSdrView();
193 const SdrMarkList
& rMarkList
= pDrView
->GetMarkedObjectList();
194 if (rMarkList
.GetMarkCount() == 1)
196 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
197 Rectangle aRect
= pObj
->GetLogicRect();
200 if ( nWhich
== SID_OBJECT_LEFT
)
202 else if ( nWhich
== SID_OBJECT_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
) );
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();
229 pDoc
->AddUnoObject(rObject
);
232 void ScTabViewShell::RemoveAccessibilityObject( SfxListener
& rObject
)
236 if (pAccessibilityBroadcaster
)
238 rObject
.EndListening( *pAccessibilityBroadcaster
);
239 ScDocument
* pDoc
= GetViewData().GetDocument();
241 pDoc
->RemoveUnoObject(rObject
);
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
)
270 pDlg
->WriteNewDataToDocument(*pDoc
);
274 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */