Update ooo320-m1
[ooovba.git] / sc / source / ui / view / tabvwshh.cxx
blob2f9f21f0e568c9c9e7442d8f25724cc27e2daa97
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 $
10 * $Revision: 1.16 $
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"
49 #include "client.hxx"
50 #include "document.hxx"
51 #include "docsh.hxx"
52 #include "sc.hrc"
53 #include "drwlayer.hxx" // GetVisibleName
54 #include "retypepassdlg.hxx"
55 #include "tabprotection.hxx"
57 #include <memory>
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...");
89 switch (nSlotId)
91 case SID_OLE_SELECT:
92 case SID_OLE_ACTIVATE:
94 // in beiden Faellen erstmal auf der sichtbaren View selektieren
96 String aName;
97 SdrView* pDrView = GetSdrView();
98 if (pDrView)
100 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
101 if (rMarkList.GetMarkCount() == 1)
102 aName = ScDrawLayer::GetVisibleName( rMarkList.GetMark(0)->GetMarkedSdrObj() );
104 pVisibleSh->SelectObject( aName );
106 // aktivieren
108 if ( nSlotId == SID_OLE_ACTIVATE )
109 pVisibleSh->DoVerb( 0 );
111 break;
112 case SID_OLE_DEACTIVATE:
113 pVisibleSh->DeactivateOle();
114 break;
116 case SID_OBJECT_LEFT:
117 case SID_OBJECT_TOP:
118 case SID_OBJECT_WIDTH:
119 case SID_OBJECT_HEIGHT:
121 BOOL bDone = FALSE;
122 const SfxPoolItem* pItem;
123 if ( pReqArgs && pReqArgs->GetItemState( nSlotId, TRUE, &pItem ) == SFX_ITEM_SET )
125 long nNewVal = ((const SfxInt32Item*)pItem)->GetValue();
126 if ( nNewVal < 0 )
127 nNewVal = 0;
129 //! von irgendwas in 1/100mm umrechnen ??????
131 SdrView* pDrView = GetSdrView();
132 if ( pDrView )
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() ),
147 Fraction( 1, 1 ) );
148 else // if ( nSlotId == SID_OBJECT_HEIGHT )
149 pDrView->ResizeMarkedObj( aRect.TopLeft(),
150 Fraction( 1, 1 ),
151 Fraction( nNewVal, aRect.GetHeight() ) );
152 bDone = TRUE;
156 if (!bDone)
157 SbxBase::SetError( SbxERR_BAD_PARAMETER ); // Basic-Fehler
159 break;
164 uno::Reference < embed::XEmbeddedObject > lcl_GetSelectedObj( SdrView* pDrView ) //! Member von ScDrawView?
166 uno::Reference < embed::XEmbeddedObject > xRet;
167 if (pDrView)
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();
181 return xRet;
184 void ScTabViewShell::GetObjectState( SfxItemSet& rSet )
186 // SID_OLE_OBJECT - removed (old Basic)
188 SfxWhichIter aIter(rSet);
189 USHORT nWhich = aIter.FirstWhich();
190 while ( nWhich )
192 switch (nWhich)
194 case SID_ACTIVE_OBJ_NAME:
196 String aName;
197 uno::Reference < embed::XEmbeddedObject > xOLE = lcl_GetSelectedObj( GetSdrView() );
198 if (xOLE.is())
200 aName = GetViewData()->GetSfxDocShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xOLE );
202 rSet.Put( SfxStringItem( nWhich, aName ) );
204 break;
205 case SID_OBJECT_LEFT:
206 case SID_OBJECT_TOP:
207 case SID_OBJECT_WIDTH:
208 case SID_OBJECT_HEIGHT:
210 SdrView* pDrView = GetSdrView();
211 if ( pDrView )
213 const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
214 if (rMarkList.GetMarkCount() == 1)
216 SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
217 Rectangle aRect = pObj->GetLogicRect();
219 long nVal;
220 if ( nWhich == SID_OBJECT_LEFT )
221 nVal = aRect.Left();
222 else if ( nWhich == SID_OBJECT_TOP )
223 nVal = aRect.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 ) );
235 break;
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();
248 if (pDoc)
249 pDoc->AddUnoObject(rObject);
252 void ScTabViewShell::RemoveAccessibilityObject( SfxListener& rObject )
254 if (pAccessibilityBroadcaster)
256 rObject.EndListening( *pAccessibilityBroadcaster );
257 ScDocument* pDoc = GetViewData()->GetDocument();
258 if (pDoc)
259 pDoc->RemoveUnoObject(rObject);
261 else
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)
288 return false;
290 pDlg->WriteNewDataToDocument(*pDoc);
291 return true;