1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tabvwshh.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
36 // INCLUDE ---------------------------------------------------------------
38 #include <svx/svdmark.hxx>
39 #include <svx/svdoole2.hxx>
40 #include <svx/svdview.hxx>
41 #include <sfx2/app.hxx>
42 #include <sfx2/objsh.hxx>
43 #include <sfx2/request.hxx>
44 #include <basic/sbxcore.hxx>
45 #include <svtools/whiter.hxx>
46 #include <vcl/msgbox.hxx>
48 #include "tabvwsh.hxx"
50 #include "document.hxx"
53 #include "drwlayer.hxx" // GetVisibleName
54 #include "retypepassdlg.hxx"
55 #include "tabprotection.hxx"
59 using namespace com::sun::star
;
61 //------------------------------------------------------------------
63 void ScTabViewShell::ExecuteSbx( SfxRequest
& /* rReq */ )
65 // SID_RANGE_OFFSET (Offset),
66 // SID_PIVOT_CREATE (DataPilotCreate) - removed (old Basic)
69 void ScTabViewShell::GetSbxState( SfxItemSet
& /* rSet */ )
71 // SID_RANGE_REGION (CurrentRegion) - removed (old Basic)
74 //------------------------------------------------------------------
76 void ScTabViewShell::ExecuteObject( SfxRequest
& rReq
)
78 USHORT nSlotId
= rReq
.GetSlot();
79 const SfxItemSet
* pReqArgs
= rReq
.GetArgs();
81 // Objekte aktivieren/deaktivieren immer auf der sichtbaren View
83 ScTabViewShell
* pVisibleSh
= this;
84 if ( nSlotId
== SID_OLE_SELECT
|| nSlotId
== SID_OLE_ACTIVATE
|| nSlotId
== SID_OLE_DEACTIVATE
)
86 DBG_ERROR("old slot SID_OLE...");
92 case SID_OLE_ACTIVATE
:
94 // in beiden Faellen erstmal auf der sichtbaren View selektieren
97 SdrView
* pDrView
= GetSdrView();
100 const SdrMarkList
& rMarkList
= pDrView
->GetMarkedObjectList();
101 if (rMarkList
.GetMarkCount() == 1)
102 aName
= ScDrawLayer::GetVisibleName( rMarkList
.GetMark(0)->GetMarkedSdrObj() );
104 pVisibleSh
->SelectObject( aName
);
108 if ( nSlotId
== SID_OLE_ACTIVATE
)
109 pVisibleSh
->DoVerb( 0 );
112 case SID_OLE_DEACTIVATE
:
113 pVisibleSh
->DeactivateOle();
116 case SID_OBJECT_LEFT
:
118 case SID_OBJECT_WIDTH
:
119 case SID_OBJECT_HEIGHT
:
122 const SfxPoolItem
* pItem
;
123 if ( pReqArgs
&& pReqArgs
->GetItemState( nSlotId
, TRUE
, &pItem
) == SFX_ITEM_SET
)
125 long nNewVal
= ((const SfxInt32Item
*)pItem
)->GetValue();
129 //! von irgendwas in 1/100mm umrechnen ??????
131 SdrView
* pDrView
= GetSdrView();
134 const SdrMarkList
& rMarkList
= pDrView
->GetMarkedObjectList();
135 if (rMarkList
.GetMarkCount() == 1)
137 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
138 Rectangle aRect
= pObj
->GetLogicRect();
140 if ( nSlotId
== SID_OBJECT_LEFT
)
141 pDrView
->MoveMarkedObj( Size( nNewVal
- aRect
.Left(), 0 ) );
142 else if ( nSlotId
== SID_OBJECT_TOP
)
143 pDrView
->MoveMarkedObj( Size( 0, nNewVal
- aRect
.Top() ) );
144 else if ( nSlotId
== SID_OBJECT_WIDTH
)
145 pDrView
->ResizeMarkedObj( aRect
.TopLeft(),
146 Fraction( nNewVal
, aRect
.GetWidth() ),
148 else // if ( nSlotId == SID_OBJECT_HEIGHT )
149 pDrView
->ResizeMarkedObj( aRect
.TopLeft(),
151 Fraction( nNewVal
, aRect
.GetHeight() ) );
157 SbxBase::SetError( SbxERR_BAD_PARAMETER
); // Basic-Fehler
164 uno::Reference
< embed::XEmbeddedObject
> lcl_GetSelectedObj( SdrView
* pDrView
) //! Member von ScDrawView?
166 uno::Reference
< embed::XEmbeddedObject
> xRet
;
169 const SdrMarkList
& rMarkList
= pDrView
->GetMarkedObjectList();
170 if (rMarkList
.GetMarkCount() == 1)
172 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
173 if (pObj
->GetObjIdentifier() == OBJ_OLE2
)
175 SdrOle2Obj
* pOle2Obj
= (SdrOle2Obj
*) pObj
;
176 xRet
= pOle2Obj
->GetObjRef();
184 void ScTabViewShell::GetObjectState( SfxItemSet
& rSet
)
186 // SID_OLE_OBJECT - removed (old Basic)
188 SfxWhichIter
aIter(rSet
);
189 USHORT nWhich
= aIter
.FirstWhich();
194 case SID_ACTIVE_OBJ_NAME
:
197 uno::Reference
< embed::XEmbeddedObject
> xOLE
= lcl_GetSelectedObj( GetSdrView() );
200 aName
= GetViewData()->GetSfxDocShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xOLE
);
202 rSet
.Put( SfxStringItem( nWhich
, aName
) );
205 case SID_OBJECT_LEFT
:
207 case SID_OBJECT_WIDTH
:
208 case SID_OBJECT_HEIGHT
:
210 SdrView
* pDrView
= GetSdrView();
213 const SdrMarkList
& rMarkList
= pDrView
->GetMarkedObjectList();
214 if (rMarkList
.GetMarkCount() == 1)
216 SdrObject
* pObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
217 Rectangle aRect
= pObj
->GetLogicRect();
220 if ( nWhich
== SID_OBJECT_LEFT
)
222 else if ( nWhich
== SID_OBJECT_TOP
)
224 else if ( nWhich
== SID_OBJECT_WIDTH
)
225 nVal
= aRect
.GetWidth();
226 else // if ( nWhich == SID_OBJECT_HEIGHT )
227 nVal
= aRect
.GetHeight();
229 //! von 1/100mm in irgendwas umrechnen ??????
231 rSet
.Put( SfxInt32Item( nWhich
, nVal
) );
237 nWhich
= aIter
.NextWhich();
241 void ScTabViewShell::AddAccessibilityObject( SfxListener
& rObject
)
243 if (!pAccessibilityBroadcaster
)
244 pAccessibilityBroadcaster
= new SfxBroadcaster
;
246 rObject
.StartListening( *pAccessibilityBroadcaster
);
247 ScDocument
* pDoc
= GetViewData()->GetDocument();
249 pDoc
->AddUnoObject(rObject
);
252 void ScTabViewShell::RemoveAccessibilityObject( SfxListener
& rObject
)
254 if (pAccessibilityBroadcaster
)
256 rObject
.EndListening( *pAccessibilityBroadcaster
);
257 ScDocument
* pDoc
= GetViewData()->GetDocument();
259 pDoc
->RemoveUnoObject(rObject
);
263 DBG_ERROR("kein Accessibility-Broadcaster?");
267 void ScTabViewShell::BroadcastAccessibility( const SfxHint
&rHint
)
269 if (pAccessibilityBroadcaster
)
270 pAccessibilityBroadcaster
->Broadcast( rHint
);
273 BOOL
ScTabViewShell::HasAccessibilityObjects()
275 return pAccessibilityBroadcaster
!= NULL
;
278 bool ScTabViewShell::ExecuteRetypePassDlg(ScPasswordHash eDesiredHash
)
280 using ::std::auto_ptr
;
282 ScDocument
* pDoc
= GetViewData()->GetDocument();
284 auto_ptr
<ScRetypePassDlg
> pDlg(new ScRetypePassDlg(GetDialogParent()));
285 pDlg
->SetDataFromDocument(*pDoc
);
286 pDlg
->SetDesiredHash(eDesiredHash
);
287 if (pDlg
->Execute() != RET_OK
)
290 pDlg
->WriteNewDataToDocument(*pDoc
);