xref: /trunk/main/sc/source/ui/app/client.cxx (revision 9dac8d9b)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10b3f79822SAndrew Rist  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19b3f79822SAndrew Rist  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sc.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <com/sun/star/embed/XEmbeddedObject.hpp>
31cdf0e10cSrcweir #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
34cdf0e10cSrcweir #include <sfx2/objsh.hxx>
35cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
36cdf0e10cSrcweir #include <sot/sotref.hxx>
37cdf0e10cSrcweir #include <svx/svditer.hxx>
38cdf0e10cSrcweir #include <svx/svdobj.hxx>
39cdf0e10cSrcweir #include <svx/svdmodel.hxx>
40cdf0e10cSrcweir #include <svx/svdpage.hxx>
41cdf0e10cSrcweir #include <svx/svdoole2.hxx>
42cdf0e10cSrcweir #include <svx/svdview.hxx>
43cdf0e10cSrcweir #include <svx/svdograf.hxx>
44cdf0e10cSrcweir #include <svtools/embedhlp.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include "client.hxx"
47cdf0e10cSrcweir #include "tabvwsh.hxx"
48cdf0e10cSrcweir #include "docsh.hxx"
49cdf0e10cSrcweir 
50cdf0e10cSrcweir using namespace com::sun::star;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir //------------------------------------------------------------------------
53cdf0e10cSrcweir 
ScClient(ScTabViewShell * pViewShell,Window * pDraw,SdrModel * pSdrModel,SdrOle2Obj * pObj)54cdf0e10cSrcweir ScClient::ScClient( ScTabViewShell* pViewShell, Window* pDraw, SdrModel* pSdrModel, SdrOle2Obj* pObj ) :
55cdf0e10cSrcweir     SfxInPlaceClient( pViewShell, pDraw, pObj->GetAspect() ),
56cdf0e10cSrcweir 	pModel( pSdrModel ),
57cdf0e10cSrcweir 	pGrafEdit( 0 )
58cdf0e10cSrcweir {
59cdf0e10cSrcweir     SetObject( pObj->GetObjRef() );
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
~ScClient()62cdf0e10cSrcweir __EXPORT ScClient::~ScClient()
63cdf0e10cSrcweir {
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
GetDrawObj()66cdf0e10cSrcweir SdrOle2Obj* ScClient::GetDrawObj()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir     uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
69cdf0e10cSrcweir 	SdrOle2Obj* pOle2Obj = NULL;
70cdf0e10cSrcweir     String aName = GetViewShell()->GetObjectShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	sal_uInt16 nPages = pModel->GetPageCount();
73cdf0e10cSrcweir 	for (sal_uInt16 nPNr=0; nPNr<nPages && !pOle2Obj; nPNr++)
74cdf0e10cSrcweir 	{
75cdf0e10cSrcweir 		SdrPage* pPage = pModel->GetPage(nPNr);
76cdf0e10cSrcweir 		SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
77cdf0e10cSrcweir 		SdrObject* pObject = aIter.Next();
78cdf0e10cSrcweir 		while (pObject && !pOle2Obj)
79cdf0e10cSrcweir 		{
80cdf0e10cSrcweir 			if ( pObject->GetObjIdentifier() == OBJ_OLE2 )
81cdf0e10cSrcweir 			{
82cdf0e10cSrcweir 				// name from InfoObject is PersistName
83cdf0e10cSrcweir 				if ( ((SdrOle2Obj*)pObject)->GetPersistName() == aName )
84cdf0e10cSrcweir 					pOle2Obj = (SdrOle2Obj*)pObject;
85cdf0e10cSrcweir 			}
86cdf0e10cSrcweir 			pObject = aIter.Next();
87cdf0e10cSrcweir 		}
88cdf0e10cSrcweir 	}
89cdf0e10cSrcweir 	return pOle2Obj;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
RequestNewObjectArea(Rectangle & aLogicRect)92cdf0e10cSrcweir void __EXPORT ScClient::RequestNewObjectArea( Rectangle& aLogicRect )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 	SfxViewShell* pSfxViewSh = GetViewShell();
95cdf0e10cSrcweir 	ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
96cdf0e10cSrcweir 	if (!pViewSh)
97cdf0e10cSrcweir 	{
98cdf0e10cSrcweir         DBG_ERROR("Wrong ViewShell");
99cdf0e10cSrcweir 		return;
100cdf0e10cSrcweir 	}
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 	Rectangle aOldRect = GetObjArea();
103cdf0e10cSrcweir 	SdrOle2Obj*  pDrawObj = GetDrawObj();
104cdf0e10cSrcweir 	if ( pDrawObj )
105cdf0e10cSrcweir 	{
106cdf0e10cSrcweir 		if ( pDrawObj->IsResizeProtect() )
107cdf0e10cSrcweir 			aLogicRect.SetSize( aOldRect.GetSize() );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 		if ( pDrawObj->IsMoveProtect() )
110cdf0e10cSrcweir 			aLogicRect.SetPos( aOldRect.TopLeft() );
111cdf0e10cSrcweir 	}
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 	sal_uInt16 nTab = pViewSh->GetViewData()->GetTabNo();
114cdf0e10cSrcweir 	SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(static_cast<sal_Int16>(nTab)));
115cdf0e10cSrcweir 	if ( pPage && aLogicRect != aOldRect )
116cdf0e10cSrcweir 	{
117cdf0e10cSrcweir 		Point aPos;
118cdf0e10cSrcweir 		Size aSize = pPage->GetSize();
119cdf0e10cSrcweir 		if ( aSize.Width() < 0 )
120cdf0e10cSrcweir 		{
121cdf0e10cSrcweir 			aPos.X() = aSize.Width() + 1;		// negative
122cdf0e10cSrcweir 			aSize.Width() = -aSize.Width();		// positive
123cdf0e10cSrcweir 		}
124cdf0e10cSrcweir 		Rectangle aPageRect( aPos, aSize );
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 		if (aLogicRect.Right() > aPageRect.Right())
127cdf0e10cSrcweir 		{
128cdf0e10cSrcweir 			long nDiff = aLogicRect.Right() - aPageRect.Right();
129cdf0e10cSrcweir 			aLogicRect.Left() -= nDiff;
130cdf0e10cSrcweir 			aLogicRect.Right() -= nDiff;
131cdf0e10cSrcweir 		}
132cdf0e10cSrcweir 		if (aLogicRect.Bottom() > aPageRect.Bottom())
133cdf0e10cSrcweir 		{
134cdf0e10cSrcweir 			long nDiff = aLogicRect.Bottom() - aPageRect.Bottom();
135cdf0e10cSrcweir 			aLogicRect.Top() -= nDiff;
136cdf0e10cSrcweir 			aLogicRect.Bottom() -= nDiff;
137cdf0e10cSrcweir 		}
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 		if (aLogicRect.Left() < aPageRect.Left())
140cdf0e10cSrcweir 		{
141cdf0e10cSrcweir 			long nDiff = aLogicRect.Left() - aPageRect.Left();
142cdf0e10cSrcweir 			aLogicRect.Right() -= nDiff;
143cdf0e10cSrcweir 			aLogicRect.Left() -= nDiff;
144cdf0e10cSrcweir 		}
145cdf0e10cSrcweir 		if (aLogicRect.Top() < aPageRect.Top())
146cdf0e10cSrcweir 		{
147cdf0e10cSrcweir 			long nDiff = aLogicRect.Top() - aPageRect.Top();
148cdf0e10cSrcweir 			aLogicRect.Bottom() -= nDiff;
149cdf0e10cSrcweir 			aLogicRect.Top() -= nDiff;
150cdf0e10cSrcweir 		}
151cdf0e10cSrcweir 	}
152cdf0e10cSrcweir }
153cdf0e10cSrcweir 
ObjectAreaChanged()154cdf0e10cSrcweir void __EXPORT ScClient::ObjectAreaChanged()
155cdf0e10cSrcweir {
156cdf0e10cSrcweir 	SfxViewShell* pSfxViewSh = GetViewShell();
157cdf0e10cSrcweir 	ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
158cdf0e10cSrcweir 	if (!pViewSh)
159cdf0e10cSrcweir 	{
160cdf0e10cSrcweir         DBG_ERROR("Wrong ViewShell");
161cdf0e10cSrcweir 		return;
162cdf0e10cSrcweir 	}
163cdf0e10cSrcweir 
164*9dac8d9bSPeter 	//	adopt position and size into document
165cdf0e10cSrcweir 	SdrOle2Obj* pDrawObj = GetDrawObj();
166cdf0e10cSrcweir 	if (pDrawObj)
167cdf0e10cSrcweir 	{
168079eb148SJürgen Schmidt         Rectangle aNewRectangle(GetScaledObjArea());
169079eb148SJürgen Schmidt 
170079eb148SJürgen Schmidt         // #i118524# if sheared/rotated, center to non-rotated LogicRect
171079eb148SJürgen Schmidt         pDrawObj->setSuppressSetVisAreaSize(true);
172079eb148SJürgen Schmidt 
173079eb148SJürgen Schmidt         if(pDrawObj->GetGeoStat().nDrehWink || pDrawObj->GetGeoStat().nShearWink)
174079eb148SJürgen Schmidt         {
175079eb148SJürgen Schmidt             pDrawObj->SetLogicRect( aNewRectangle );
176079eb148SJürgen Schmidt 
177079eb148SJürgen Schmidt             const Rectangle& rBoundRect = pDrawObj->GetCurrentBoundRect();
178079eb148SJürgen Schmidt             const Point aDelta(aNewRectangle.Center() - rBoundRect.Center());
179079eb148SJürgen Schmidt 
180079eb148SJürgen Schmidt             aNewRectangle.Move(aDelta.X(), aDelta.Y());
181079eb148SJürgen Schmidt         }
182079eb148SJürgen Schmidt 
183079eb148SJürgen Schmidt         pDrawObj->SetLogicRect( aNewRectangle );
184079eb148SJürgen Schmidt         pDrawObj->setSuppressSetVisAreaSize(false);
185cdf0e10cSrcweir 
186cdf0e10cSrcweir         //  set document modified (SdrModel::SetChanged is not used)
187cdf0e10cSrcweir         // TODO/LATER: is there a reason that this code is not executed in Draw?
188cdf0e10cSrcweir //        SfxViewShell* pSfxViewSh = GetViewShell();
189cdf0e10cSrcweir //        ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
190cdf0e10cSrcweir         if (pViewSh)
191cdf0e10cSrcweir             pViewSh->GetViewData()->GetDocShell()->SetDrawModified();
192cdf0e10cSrcweir 	}
193cdf0e10cSrcweir 
194cdf0e10cSrcweir 	if (pDrawObj)
195cdf0e10cSrcweir 		pViewSh->ScrollToObject( pDrawObj );
196cdf0e10cSrcweir }
197cdf0e10cSrcweir 
ViewChanged()198cdf0e10cSrcweir void __EXPORT ScClient::ViewChanged()
199cdf0e10cSrcweir {
200cdf0e10cSrcweir 	if ( GetAspect() == embed::Aspects::MSOLE_ICON )
201cdf0e10cSrcweir 	{
202cdf0e10cSrcweir 		// the iconified object seems not to need such a scaling handling
203cdf0e10cSrcweir 		// since the replacement image and the size a completely controlled by the container
204cdf0e10cSrcweir 		// TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
205cdf0e10cSrcweir 
206cdf0e10cSrcweir 		return;
207cdf0e10cSrcweir 	}
208cdf0e10cSrcweir 
209cdf0e10cSrcweir     uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     // TODO/LEAN: working with Visual Area can switch object to running state
212cdf0e10cSrcweir     awt::Size aSz;
213cdf0e10cSrcweir 	try {
214cdf0e10cSrcweir 		aSz = xObj->getVisualAreaSize( GetAspect() );
215cdf0e10cSrcweir 	} catch ( embed::NoVisualAreaSizeException& )
216cdf0e10cSrcweir 	{
217cdf0e10cSrcweir         DBG_ERROR("The visual area size must be available!\n");
218cdf0e10cSrcweir 	}
219cdf0e10cSrcweir 
220cdf0e10cSrcweir     MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( GetAspect() ) );
221cdf0e10cSrcweir     Size aVisSize = OutputDevice::LogicToLogic( Size( aSz.Width, aSz.Height ), aMapUnit, MAP_100TH_MM );
222cdf0e10cSrcweir 
223*9dac8d9bSPeter 	//	adopt size into the document
224cdf0e10cSrcweir 	SdrOle2Obj* pDrawObj = GetDrawObj();
225cdf0e10cSrcweir 	if (pDrawObj)
226cdf0e10cSrcweir 	{
227cdf0e10cSrcweir 		Rectangle aLogicRect = pDrawObj->GetLogicRect();
228cdf0e10cSrcweir         Fraction aFractX = GetScaleWidth();
229cdf0e10cSrcweir         Fraction aFractY = GetScaleHeight();
230cdf0e10cSrcweir         aFractX *= aVisSize.Width();
231cdf0e10cSrcweir         aFractY *= aVisSize.Height();
232*9dac8d9bSPeter         aVisSize = Size( (long) aFractX, (long) aFractY );      // scale for Draw-Model
233cdf0e10cSrcweir 
234*9dac8d9bSPeter         //  pClientData->SetObjArea before pDrawObj->SetLogicRect, to avoid wrong
235*9dac8d9bSPeter         //  scale calculations:
236cdf0e10cSrcweir         //Rectangle aObjArea = aLogicRect;
237*9dac8d9bSPeter         //aObjArea.SetSize( aVisSize );          // Size of document from Server
238cdf0e10cSrcweir         //SetObjArea( aObjArea );
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 		SfxViewShell* pSfxViewSh = GetViewShell();
241cdf0e10cSrcweir 		ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
242cdf0e10cSrcweir 		if ( pViewSh )
243cdf0e10cSrcweir 		{
244cdf0e10cSrcweir 			Window* pWin = pViewSh->GetActiveWin();
245cdf0e10cSrcweir 			if ( pWin->LogicToPixel( aVisSize ) != pWin->LogicToPixel( aLogicRect.GetSize() ) )
246cdf0e10cSrcweir 			{
247cdf0e10cSrcweir 				aLogicRect.SetSize( aVisSize );
248cdf0e10cSrcweir 				pDrawObj->SetLogicRect( aLogicRect );
249cdf0e10cSrcweir 
250cdf0e10cSrcweir 				//	set document modified (SdrModel::SetChanged is not used)
251cdf0e10cSrcweir 				pViewSh->GetViewData()->GetDocShell()->SetDrawModified();
252cdf0e10cSrcweir 			}
253cdf0e10cSrcweir 		}
254cdf0e10cSrcweir 	}
255cdf0e10cSrcweir }
256cdf0e10cSrcweir 
MakeVisible()257cdf0e10cSrcweir void __EXPORT ScClient::MakeVisible()
258cdf0e10cSrcweir {
259cdf0e10cSrcweir 	SdrOle2Obj* pDrawObj = GetDrawObj();
260cdf0e10cSrcweir 	if (pDrawObj)
261cdf0e10cSrcweir 	{
262cdf0e10cSrcweir 		SfxViewShell* pSfxViewSh = GetViewShell();
263cdf0e10cSrcweir 		ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
264cdf0e10cSrcweir 		if (pViewSh)
265cdf0e10cSrcweir 			pViewSh->ScrollToObject( pDrawObj );
266cdf0e10cSrcweir 	}
267cdf0e10cSrcweir }
268cdf0e10cSrcweir 
269