xref: /aoo41x/main/sc/source/ui/view/tabvwshh.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_sc.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <svx/svdmark.hxx>
36*cdf0e10cSrcweir #include <svx/svdoole2.hxx>
37*cdf0e10cSrcweir #include <svx/svdview.hxx>
38*cdf0e10cSrcweir #include <sfx2/app.hxx>
39*cdf0e10cSrcweir #include <sfx2/objsh.hxx>
40*cdf0e10cSrcweir #include <sfx2/request.hxx>
41*cdf0e10cSrcweir #include <basic/sbxcore.hxx>
42*cdf0e10cSrcweir #include <svl/whiter.hxx>
43*cdf0e10cSrcweir #include <vcl/msgbox.hxx>
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include "tabvwsh.hxx"
46*cdf0e10cSrcweir #include "client.hxx"
47*cdf0e10cSrcweir #include "document.hxx"
48*cdf0e10cSrcweir #include "docsh.hxx"
49*cdf0e10cSrcweir #include "sc.hrc"
50*cdf0e10cSrcweir #include "drwlayer.hxx"		// GetVisibleName
51*cdf0e10cSrcweir #include "retypepassdlg.hxx"
52*cdf0e10cSrcweir #include "tabprotection.hxx"
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir #include <memory>
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir using namespace com::sun::star;
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir //------------------------------------------------------------------
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir void ScTabViewShell::ExecuteSbx( SfxRequest& /* rReq */ )
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir 	//	SID_RANGE_OFFSET (Offset),
63*cdf0e10cSrcweir 	//	SID_PIVOT_CREATE (DataPilotCreate) - removed (old Basic)
64*cdf0e10cSrcweir }
65*cdf0e10cSrcweir 
66*cdf0e10cSrcweir void ScTabViewShell::GetSbxState( SfxItemSet& /* rSet */ )
67*cdf0e10cSrcweir {
68*cdf0e10cSrcweir 	//	SID_RANGE_REGION (CurrentRegion) - removed (old Basic)
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir //------------------------------------------------------------------
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir void ScTabViewShell::ExecuteObject( SfxRequest& rReq )
74*cdf0e10cSrcweir {
75*cdf0e10cSrcweir 	sal_uInt16 nSlotId = rReq.GetSlot();
76*cdf0e10cSrcweir 	const SfxItemSet* pReqArgs = rReq.GetArgs();
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir 		//	Objekte aktivieren/deaktivieren immer auf der sichtbaren View
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir 	ScTabViewShell* pVisibleSh = this;
81*cdf0e10cSrcweir 	if ( nSlotId == SID_OLE_SELECT || nSlotId == SID_OLE_ACTIVATE || nSlotId == SID_OLE_DEACTIVATE )
82*cdf0e10cSrcweir 	{
83*cdf0e10cSrcweir 		DBG_ERROR("old slot SID_OLE...");
84*cdf0e10cSrcweir 	}
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir 	switch (nSlotId)
87*cdf0e10cSrcweir 	{
88*cdf0e10cSrcweir 		case SID_OLE_SELECT:
89*cdf0e10cSrcweir 		case SID_OLE_ACTIVATE:
90*cdf0e10cSrcweir 			{
91*cdf0e10cSrcweir 				//	in beiden Faellen erstmal auf der sichtbaren View selektieren
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir 				String aName;
94*cdf0e10cSrcweir 				SdrView* pDrView = GetSdrView();
95*cdf0e10cSrcweir 				if (pDrView)
96*cdf0e10cSrcweir 				{
97*cdf0e10cSrcweir 					const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
98*cdf0e10cSrcweir 					if (rMarkList.GetMarkCount() == 1)
99*cdf0e10cSrcweir 						aName = ScDrawLayer::GetVisibleName( rMarkList.GetMark(0)->GetMarkedSdrObj() );
100*cdf0e10cSrcweir 				}
101*cdf0e10cSrcweir 				pVisibleSh->SelectObject( aName );
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 				//	aktivieren
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 				if ( nSlotId == SID_OLE_ACTIVATE )
106*cdf0e10cSrcweir 					pVisibleSh->DoVerb( 0 );
107*cdf0e10cSrcweir 			}
108*cdf0e10cSrcweir 			break;
109*cdf0e10cSrcweir 		case SID_OLE_DEACTIVATE:
110*cdf0e10cSrcweir             pVisibleSh->DeactivateOle();
111*cdf0e10cSrcweir 			break;
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir 		case SID_OBJECT_LEFT:
114*cdf0e10cSrcweir 		case SID_OBJECT_TOP:
115*cdf0e10cSrcweir 		case SID_OBJECT_WIDTH:
116*cdf0e10cSrcweir 		case SID_OBJECT_HEIGHT:
117*cdf0e10cSrcweir 			{
118*cdf0e10cSrcweir 				sal_Bool bDone = sal_False;
119*cdf0e10cSrcweir 				const SfxPoolItem* pItem;
120*cdf0e10cSrcweir 				if ( pReqArgs && pReqArgs->GetItemState( nSlotId, sal_True, &pItem ) == SFX_ITEM_SET )
121*cdf0e10cSrcweir 				{
122*cdf0e10cSrcweir 					long nNewVal = ((const SfxInt32Item*)pItem)->GetValue();
123*cdf0e10cSrcweir 					if ( nNewVal < 0 )
124*cdf0e10cSrcweir 						nNewVal = 0;
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir 					//!	von irgendwas in 1/100mm umrechnen ??????
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 					SdrView* pDrView = GetSdrView();
129*cdf0e10cSrcweir 					if ( pDrView )
130*cdf0e10cSrcweir 					{
131*cdf0e10cSrcweir 						const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
132*cdf0e10cSrcweir 						if (rMarkList.GetMarkCount() == 1)
133*cdf0e10cSrcweir 						{
134*cdf0e10cSrcweir 							SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
135*cdf0e10cSrcweir 							Rectangle aRect = pObj->GetLogicRect();
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir 							if ( nSlotId == SID_OBJECT_LEFT )
138*cdf0e10cSrcweir 								pDrView->MoveMarkedObj( Size( nNewVal - aRect.Left(), 0 ) );
139*cdf0e10cSrcweir 							else if ( nSlotId == SID_OBJECT_TOP )
140*cdf0e10cSrcweir 								pDrView->MoveMarkedObj( Size( 0, nNewVal - aRect.Top() ) );
141*cdf0e10cSrcweir 							else if ( nSlotId == SID_OBJECT_WIDTH )
142*cdf0e10cSrcweir 								pDrView->ResizeMarkedObj( aRect.TopLeft(),
143*cdf0e10cSrcweir 												Fraction( nNewVal, aRect.GetWidth() ),
144*cdf0e10cSrcweir 												Fraction( 1, 1 ) );
145*cdf0e10cSrcweir 							else // if ( nSlotId == SID_OBJECT_HEIGHT )
146*cdf0e10cSrcweir 								pDrView->ResizeMarkedObj( aRect.TopLeft(),
147*cdf0e10cSrcweir 												Fraction( 1, 1 ),
148*cdf0e10cSrcweir 												Fraction( nNewVal, aRect.GetHeight() ) );
149*cdf0e10cSrcweir 							bDone = sal_True;
150*cdf0e10cSrcweir 						}
151*cdf0e10cSrcweir 					}
152*cdf0e10cSrcweir 				}
153*cdf0e10cSrcweir 				if (!bDone)
154*cdf0e10cSrcweir 					SbxBase::SetError( SbxERR_BAD_PARAMETER );	// Basic-Fehler
155*cdf0e10cSrcweir 			}
156*cdf0e10cSrcweir 			break;
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir 	}
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir uno::Reference < embed::XEmbeddedObject > lcl_GetSelectedObj( SdrView* pDrView )       //! Member von ScDrawView?
162*cdf0e10cSrcweir {
163*cdf0e10cSrcweir     uno::Reference < embed::XEmbeddedObject > xRet;
164*cdf0e10cSrcweir 	if (pDrView)
165*cdf0e10cSrcweir 	{
166*cdf0e10cSrcweir 		const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
167*cdf0e10cSrcweir 		if (rMarkList.GetMarkCount() == 1)
168*cdf0e10cSrcweir 		{
169*cdf0e10cSrcweir 			SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
170*cdf0e10cSrcweir 			if (pObj->GetObjIdentifier() == OBJ_OLE2)
171*cdf0e10cSrcweir 			{
172*cdf0e10cSrcweir 				SdrOle2Obj* pOle2Obj = (SdrOle2Obj*) pObj;
173*cdf0e10cSrcweir 				xRet = pOle2Obj->GetObjRef();
174*cdf0e10cSrcweir 			}
175*cdf0e10cSrcweir 		}
176*cdf0e10cSrcweir 	}
177*cdf0e10cSrcweir 
178*cdf0e10cSrcweir 	return xRet;
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir void ScTabViewShell::GetObjectState( SfxItemSet& rSet )
182*cdf0e10cSrcweir {
183*cdf0e10cSrcweir 	//	SID_OLE_OBJECT - removed (old Basic)
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir 	SfxWhichIter aIter(rSet);
186*cdf0e10cSrcweir 	sal_uInt16 nWhich = aIter.FirstWhich();
187*cdf0e10cSrcweir 	while ( nWhich )
188*cdf0e10cSrcweir 	{
189*cdf0e10cSrcweir 		switch (nWhich)
190*cdf0e10cSrcweir 		{
191*cdf0e10cSrcweir 			case SID_ACTIVE_OBJ_NAME:
192*cdf0e10cSrcweir 				{
193*cdf0e10cSrcweir 					String aName;
194*cdf0e10cSrcweir                     uno::Reference < embed::XEmbeddedObject > xOLE = lcl_GetSelectedObj( GetSdrView() );
195*cdf0e10cSrcweir                     if (xOLE.is())
196*cdf0e10cSrcweir 					{
197*cdf0e10cSrcweir                         aName = GetViewData()->GetSfxDocShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xOLE );
198*cdf0e10cSrcweir 					}
199*cdf0e10cSrcweir 					rSet.Put( SfxStringItem( nWhich, aName ) );
200*cdf0e10cSrcweir 				}
201*cdf0e10cSrcweir 				break;
202*cdf0e10cSrcweir 			case SID_OBJECT_LEFT:
203*cdf0e10cSrcweir 			case SID_OBJECT_TOP:
204*cdf0e10cSrcweir 			case SID_OBJECT_WIDTH:
205*cdf0e10cSrcweir 			case SID_OBJECT_HEIGHT:
206*cdf0e10cSrcweir 				{
207*cdf0e10cSrcweir 					SdrView* pDrView = GetSdrView();
208*cdf0e10cSrcweir 					if ( pDrView )
209*cdf0e10cSrcweir 					{
210*cdf0e10cSrcweir 						const SdrMarkList& rMarkList = pDrView->GetMarkedObjectList();
211*cdf0e10cSrcweir 						if (rMarkList.GetMarkCount() == 1)
212*cdf0e10cSrcweir 						{
213*cdf0e10cSrcweir 							SdrObject* pObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
214*cdf0e10cSrcweir 							Rectangle aRect = pObj->GetLogicRect();
215*cdf0e10cSrcweir 
216*cdf0e10cSrcweir 							long nVal;
217*cdf0e10cSrcweir 							if ( nWhich == SID_OBJECT_LEFT )
218*cdf0e10cSrcweir 								nVal = aRect.Left();
219*cdf0e10cSrcweir 							else if ( nWhich == SID_OBJECT_TOP )
220*cdf0e10cSrcweir 								nVal = aRect.Top();
221*cdf0e10cSrcweir 							else if ( nWhich == SID_OBJECT_WIDTH )
222*cdf0e10cSrcweir 								nVal = aRect.GetWidth();
223*cdf0e10cSrcweir 							else // if ( nWhich == SID_OBJECT_HEIGHT )
224*cdf0e10cSrcweir 								nVal = aRect.GetHeight();
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir 							//!	von 1/100mm in irgendwas umrechnen ??????
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 							rSet.Put( SfxInt32Item( nWhich, nVal ) );
229*cdf0e10cSrcweir 						}
230*cdf0e10cSrcweir 					}
231*cdf0e10cSrcweir 				}
232*cdf0e10cSrcweir 				break;
233*cdf0e10cSrcweir 		}
234*cdf0e10cSrcweir 		nWhich = aIter.NextWhich();
235*cdf0e10cSrcweir 	}
236*cdf0e10cSrcweir }
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir void ScTabViewShell::AddAccessibilityObject( SfxListener& rObject )
239*cdf0e10cSrcweir {
240*cdf0e10cSrcweir 	if (!pAccessibilityBroadcaster)
241*cdf0e10cSrcweir 		pAccessibilityBroadcaster = new SfxBroadcaster;
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir 	rObject.StartListening( *pAccessibilityBroadcaster );
244*cdf0e10cSrcweir 	ScDocument* pDoc = GetViewData()->GetDocument();
245*cdf0e10cSrcweir 	if (pDoc)
246*cdf0e10cSrcweir 		pDoc->AddUnoObject(rObject);
247*cdf0e10cSrcweir }
248*cdf0e10cSrcweir 
249*cdf0e10cSrcweir void ScTabViewShell::RemoveAccessibilityObject( SfxListener& rObject )
250*cdf0e10cSrcweir {
251*cdf0e10cSrcweir 	if (pAccessibilityBroadcaster)
252*cdf0e10cSrcweir 	{
253*cdf0e10cSrcweir 		rObject.EndListening( *pAccessibilityBroadcaster );
254*cdf0e10cSrcweir 		ScDocument* pDoc = GetViewData()->GetDocument();
255*cdf0e10cSrcweir 		if (pDoc)
256*cdf0e10cSrcweir 			pDoc->RemoveUnoObject(rObject);
257*cdf0e10cSrcweir 	}
258*cdf0e10cSrcweir 	else
259*cdf0e10cSrcweir 	{
260*cdf0e10cSrcweir 		DBG_ERROR("kein Accessibility-Broadcaster?");
261*cdf0e10cSrcweir 	}
262*cdf0e10cSrcweir }
263*cdf0e10cSrcweir 
264*cdf0e10cSrcweir void ScTabViewShell::BroadcastAccessibility( const SfxHint &rHint )
265*cdf0e10cSrcweir {
266*cdf0e10cSrcweir 	if (pAccessibilityBroadcaster)
267*cdf0e10cSrcweir 		pAccessibilityBroadcaster->Broadcast( rHint );
268*cdf0e10cSrcweir }
269*cdf0e10cSrcweir 
270*cdf0e10cSrcweir sal_Bool ScTabViewShell::HasAccessibilityObjects()
271*cdf0e10cSrcweir {
272*cdf0e10cSrcweir 	return pAccessibilityBroadcaster != NULL;
273*cdf0e10cSrcweir }
274*cdf0e10cSrcweir 
275*cdf0e10cSrcweir bool ScTabViewShell::ExecuteRetypePassDlg(ScPasswordHash eDesiredHash)
276*cdf0e10cSrcweir {
277*cdf0e10cSrcweir     using ::std::auto_ptr;
278*cdf0e10cSrcweir 
279*cdf0e10cSrcweir     ScDocument* pDoc = GetViewData()->GetDocument();
280*cdf0e10cSrcweir 
281*cdf0e10cSrcweir     auto_ptr<ScRetypePassDlg> pDlg(new ScRetypePassDlg(GetDialogParent()));
282*cdf0e10cSrcweir     pDlg->SetDataFromDocument(*pDoc);
283*cdf0e10cSrcweir     pDlg->SetDesiredHash(eDesiredHash);
284*cdf0e10cSrcweir     if (pDlg->Execute() != RET_OK)
285*cdf0e10cSrcweir         return false;
286*cdf0e10cSrcweir 
287*cdf0e10cSrcweir     pDlg->WriteNewDataToDocument(*pDoc);
288*cdf0e10cSrcweir     return true;
289*cdf0e10cSrcweir }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir 
293*cdf0e10cSrcweir 
294