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