xref: /AOO41X/main/sc/source/ui/app/client.cxx (revision 079eb1488ee4ac40ff007e1c91ed115eaf2e5efa)
1cdf0e10cSrcweir /*************************************************************************
2cdf0e10cSrcweir  *
3cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4cdf0e10cSrcweir  *
5cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6cdf0e10cSrcweir  *
7cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8cdf0e10cSrcweir  *
9cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10cdf0e10cSrcweir  *
11cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14cdf0e10cSrcweir  *
15cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20cdf0e10cSrcweir  *
21cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25cdf0e10cSrcweir  *
26cdf0e10cSrcweir  ************************************************************************/
27cdf0e10cSrcweir 
28cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29cdf0e10cSrcweir #include "precompiled_sc.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // INCLUDE ---------------------------------------------------------------
32cdf0e10cSrcweir 
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <com/sun/star/embed/XEmbeddedObject.hpp>
35cdf0e10cSrcweir #include <com/sun/star/embed/NoVisualAreaSizeException.hpp>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
38cdf0e10cSrcweir #include <sfx2/objsh.hxx>
39cdf0e10cSrcweir #include <sfx2/viewfrm.hxx>
40cdf0e10cSrcweir #include <sot/sotref.hxx>
41cdf0e10cSrcweir #include <svx/svditer.hxx>
42cdf0e10cSrcweir #include <svx/svdobj.hxx>
43cdf0e10cSrcweir #include <svx/svdmodel.hxx>
44cdf0e10cSrcweir #include <svx/svdpage.hxx>
45cdf0e10cSrcweir #include <svx/svdoole2.hxx>
46cdf0e10cSrcweir #include <svx/svdview.hxx>
47cdf0e10cSrcweir #include <svx/svdograf.hxx>
48cdf0e10cSrcweir #include <svtools/embedhlp.hxx>
49cdf0e10cSrcweir 
50cdf0e10cSrcweir #include "client.hxx"
51cdf0e10cSrcweir #include "tabvwsh.hxx"
52cdf0e10cSrcweir #include "docsh.hxx"
53cdf0e10cSrcweir 
54cdf0e10cSrcweir using namespace com::sun::star;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir //------------------------------------------------------------------------
57cdf0e10cSrcweir 
58cdf0e10cSrcweir ScClient::ScClient( ScTabViewShell* pViewShell, Window* pDraw, SdrModel* pSdrModel, SdrOle2Obj* pObj ) :
59cdf0e10cSrcweir     SfxInPlaceClient( pViewShell, pDraw, pObj->GetAspect() ),
60cdf0e10cSrcweir 	pModel( pSdrModel ),
61cdf0e10cSrcweir 	pGrafEdit( 0 )
62cdf0e10cSrcweir {
63cdf0e10cSrcweir     SetObject( pObj->GetObjRef() );
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir __EXPORT ScClient::~ScClient()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir SdrOle2Obj* ScClient::GetDrawObj()
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
73cdf0e10cSrcweir 	SdrOle2Obj* pOle2Obj = NULL;
74cdf0e10cSrcweir     String aName = GetViewShell()->GetObjectShell()->GetEmbeddedObjectContainer().GetEmbeddedObjectName( xObj );
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 	sal_uInt16 nPages = pModel->GetPageCount();
77cdf0e10cSrcweir 	for (sal_uInt16 nPNr=0; nPNr<nPages && !pOle2Obj; nPNr++)
78cdf0e10cSrcweir 	{
79cdf0e10cSrcweir 		SdrPage* pPage = pModel->GetPage(nPNr);
80cdf0e10cSrcweir 		SdrObjListIter aIter( *pPage, IM_DEEPNOGROUPS );
81cdf0e10cSrcweir 		SdrObject* pObject = aIter.Next();
82cdf0e10cSrcweir 		while (pObject && !pOle2Obj)
83cdf0e10cSrcweir 		{
84cdf0e10cSrcweir 			if ( pObject->GetObjIdentifier() == OBJ_OLE2 )
85cdf0e10cSrcweir 			{
86cdf0e10cSrcweir 				// name from InfoObject is PersistName
87cdf0e10cSrcweir 				if ( ((SdrOle2Obj*)pObject)->GetPersistName() == aName )
88cdf0e10cSrcweir 					pOle2Obj = (SdrOle2Obj*)pObject;
89cdf0e10cSrcweir 			}
90cdf0e10cSrcweir 			pObject = aIter.Next();
91cdf0e10cSrcweir 		}
92cdf0e10cSrcweir 	}
93cdf0e10cSrcweir 	return pOle2Obj;
94cdf0e10cSrcweir }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir void __EXPORT ScClient::RequestNewObjectArea( Rectangle& aLogicRect )
97cdf0e10cSrcweir {
98cdf0e10cSrcweir 	SfxViewShell* pSfxViewSh = GetViewShell();
99cdf0e10cSrcweir 	ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
100cdf0e10cSrcweir 	if (!pViewSh)
101cdf0e10cSrcweir 	{
102cdf0e10cSrcweir         DBG_ERROR("Wrong ViewShell");
103cdf0e10cSrcweir 		return;
104cdf0e10cSrcweir 	}
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	Rectangle aOldRect = GetObjArea();
107cdf0e10cSrcweir 	SdrOle2Obj*  pDrawObj = GetDrawObj();
108cdf0e10cSrcweir 	if ( pDrawObj )
109cdf0e10cSrcweir 	{
110cdf0e10cSrcweir 		if ( pDrawObj->IsResizeProtect() )
111cdf0e10cSrcweir 			aLogicRect.SetSize( aOldRect.GetSize() );
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 		if ( pDrawObj->IsMoveProtect() )
114cdf0e10cSrcweir 			aLogicRect.SetPos( aOldRect.TopLeft() );
115cdf0e10cSrcweir 	}
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	sal_uInt16 nTab = pViewSh->GetViewData()->GetTabNo();
118cdf0e10cSrcweir 	SdrPage* pPage = pModel->GetPage(static_cast<sal_uInt16>(static_cast<sal_Int16>(nTab)));
119cdf0e10cSrcweir 	if ( pPage && aLogicRect != aOldRect )
120cdf0e10cSrcweir 	{
121cdf0e10cSrcweir 		Point aPos;
122cdf0e10cSrcweir 		Size aSize = pPage->GetSize();
123cdf0e10cSrcweir 		if ( aSize.Width() < 0 )
124cdf0e10cSrcweir 		{
125cdf0e10cSrcweir 			aPos.X() = aSize.Width() + 1;		// negative
126cdf0e10cSrcweir 			aSize.Width() = -aSize.Width();		// positive
127cdf0e10cSrcweir 		}
128cdf0e10cSrcweir 		Rectangle aPageRect( aPos, aSize );
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 		if (aLogicRect.Right() > aPageRect.Right())
131cdf0e10cSrcweir 		{
132cdf0e10cSrcweir 			long nDiff = aLogicRect.Right() - aPageRect.Right();
133cdf0e10cSrcweir 			aLogicRect.Left() -= nDiff;
134cdf0e10cSrcweir 			aLogicRect.Right() -= nDiff;
135cdf0e10cSrcweir 		}
136cdf0e10cSrcweir 		if (aLogicRect.Bottom() > aPageRect.Bottom())
137cdf0e10cSrcweir 		{
138cdf0e10cSrcweir 			long nDiff = aLogicRect.Bottom() - aPageRect.Bottom();
139cdf0e10cSrcweir 			aLogicRect.Top() -= nDiff;
140cdf0e10cSrcweir 			aLogicRect.Bottom() -= nDiff;
141cdf0e10cSrcweir 		}
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 		if (aLogicRect.Left() < aPageRect.Left())
144cdf0e10cSrcweir 		{
145cdf0e10cSrcweir 			long nDiff = aLogicRect.Left() - aPageRect.Left();
146cdf0e10cSrcweir 			aLogicRect.Right() -= nDiff;
147cdf0e10cSrcweir 			aLogicRect.Left() -= nDiff;
148cdf0e10cSrcweir 		}
149cdf0e10cSrcweir 		if (aLogicRect.Top() < aPageRect.Top())
150cdf0e10cSrcweir 		{
151cdf0e10cSrcweir 			long nDiff = aLogicRect.Top() - aPageRect.Top();
152cdf0e10cSrcweir 			aLogicRect.Bottom() -= nDiff;
153cdf0e10cSrcweir 			aLogicRect.Top() -= nDiff;
154cdf0e10cSrcweir 		}
155cdf0e10cSrcweir 	}
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir void __EXPORT ScClient::ObjectAreaChanged()
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	SfxViewShell* pSfxViewSh = GetViewShell();
161cdf0e10cSrcweir 	ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
162cdf0e10cSrcweir 	if (!pViewSh)
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir         DBG_ERROR("Wrong ViewShell");
165cdf0e10cSrcweir 		return;
166cdf0e10cSrcweir 	}
167cdf0e10cSrcweir 
168cdf0e10cSrcweir 	//	Position und Groesse ins Dokument uebernehmen
169cdf0e10cSrcweir 	SdrOle2Obj* pDrawObj = GetDrawObj();
170cdf0e10cSrcweir 	if (pDrawObj)
171cdf0e10cSrcweir 	{
172*079eb148SJürgen Schmidt         Rectangle aNewRectangle(GetScaledObjArea());
173*079eb148SJürgen Schmidt 
174*079eb148SJürgen Schmidt         // #i118524# if sheared/rotated, center to non-rotated LogicRect
175*079eb148SJürgen Schmidt         pDrawObj->setSuppressSetVisAreaSize(true);
176*079eb148SJürgen Schmidt 
177*079eb148SJürgen Schmidt         if(pDrawObj->GetGeoStat().nDrehWink || pDrawObj->GetGeoStat().nShearWink)
178*079eb148SJürgen Schmidt         {
179*079eb148SJürgen Schmidt             pDrawObj->SetLogicRect( aNewRectangle );
180*079eb148SJürgen Schmidt 
181*079eb148SJürgen Schmidt             const Rectangle& rBoundRect = pDrawObj->GetCurrentBoundRect();
182*079eb148SJürgen Schmidt             const Point aDelta(aNewRectangle.Center() - rBoundRect.Center());
183*079eb148SJürgen Schmidt 
184*079eb148SJürgen Schmidt             aNewRectangle.Move(aDelta.X(), aDelta.Y());
185*079eb148SJürgen Schmidt         }
186*079eb148SJürgen Schmidt 
187*079eb148SJürgen Schmidt         pDrawObj->SetLogicRect( aNewRectangle );
188*079eb148SJürgen Schmidt         pDrawObj->setSuppressSetVisAreaSize(false);
189cdf0e10cSrcweir 
190cdf0e10cSrcweir         //  set document modified (SdrModel::SetChanged is not used)
191cdf0e10cSrcweir         // TODO/LATER: is there a reason that this code is not executed in Draw?
192cdf0e10cSrcweir //        SfxViewShell* pSfxViewSh = GetViewShell();
193cdf0e10cSrcweir //        ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
194cdf0e10cSrcweir         if (pViewSh)
195cdf0e10cSrcweir             pViewSh->GetViewData()->GetDocShell()->SetDrawModified();
196cdf0e10cSrcweir 	}
197cdf0e10cSrcweir 
198cdf0e10cSrcweir 	if (pDrawObj)
199cdf0e10cSrcweir 		pViewSh->ScrollToObject( pDrawObj );
200cdf0e10cSrcweir }
201cdf0e10cSrcweir 
202cdf0e10cSrcweir void __EXPORT ScClient::ViewChanged()
203cdf0e10cSrcweir {
204cdf0e10cSrcweir 	if ( GetAspect() == embed::Aspects::MSOLE_ICON )
205cdf0e10cSrcweir 	{
206cdf0e10cSrcweir 		// the iconified object seems not to need such a scaling handling
207cdf0e10cSrcweir 		// since the replacement image and the size a completely controlled by the container
208cdf0e10cSrcweir 		// TODO/LATER: when the icon exchange is implemented the scaling handling might be required again here
209cdf0e10cSrcweir 
210cdf0e10cSrcweir 		return;
211cdf0e10cSrcweir 	}
212cdf0e10cSrcweir 
213cdf0e10cSrcweir     uno::Reference < embed::XEmbeddedObject > xObj = GetObject();
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     // TODO/LEAN: working with Visual Area can switch object to running state
216cdf0e10cSrcweir     awt::Size aSz;
217cdf0e10cSrcweir 	try {
218cdf0e10cSrcweir 		aSz = xObj->getVisualAreaSize( GetAspect() );
219cdf0e10cSrcweir 	} catch ( embed::NoVisualAreaSizeException& )
220cdf0e10cSrcweir 	{
221cdf0e10cSrcweir         DBG_ERROR("The visual area size must be available!\n");
222cdf0e10cSrcweir 	}
223cdf0e10cSrcweir 
224cdf0e10cSrcweir     MapUnit aMapUnit = VCLUnoHelper::UnoEmbed2VCLMapUnit( xObj->getMapUnit( GetAspect() ) );
225cdf0e10cSrcweir     Size aVisSize = OutputDevice::LogicToLogic( Size( aSz.Width, aSz.Height ), aMapUnit, MAP_100TH_MM );
226cdf0e10cSrcweir 
227cdf0e10cSrcweir 	//	Groesse ins Dokument uebernehmen
228cdf0e10cSrcweir 	SdrOle2Obj* pDrawObj = GetDrawObj();
229cdf0e10cSrcweir 	if (pDrawObj)
230cdf0e10cSrcweir 	{
231cdf0e10cSrcweir 		Rectangle aLogicRect = pDrawObj->GetLogicRect();
232cdf0e10cSrcweir         Fraction aFractX = GetScaleWidth();
233cdf0e10cSrcweir         Fraction aFractY = GetScaleHeight();
234cdf0e10cSrcweir         aFractX *= aVisSize.Width();
235cdf0e10cSrcweir         aFractY *= aVisSize.Height();
236cdf0e10cSrcweir         aVisSize = Size( (long) aFractX, (long) aFractY );      // skaliert fuer Draw-Model
237cdf0e10cSrcweir 
238cdf0e10cSrcweir         //  pClientData->SetObjArea vor pDrawObj->SetLogicRect, damit keine
239cdf0e10cSrcweir         //  falschen Skalierungen ausgerechnet werden:
240cdf0e10cSrcweir         //Rectangle aObjArea = aLogicRect;
241cdf0e10cSrcweir         //aObjArea.SetSize( aVisSize );          // Dokument-Groesse vom Server
242cdf0e10cSrcweir         //SetObjArea( aObjArea );
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 		SfxViewShell* pSfxViewSh = GetViewShell();
245cdf0e10cSrcweir 		ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
246cdf0e10cSrcweir 		if ( pViewSh )
247cdf0e10cSrcweir 		{
248cdf0e10cSrcweir 			Window* pWin = pViewSh->GetActiveWin();
249cdf0e10cSrcweir 			if ( pWin->LogicToPixel( aVisSize ) != pWin->LogicToPixel( aLogicRect.GetSize() ) )
250cdf0e10cSrcweir 			{
251cdf0e10cSrcweir 				aLogicRect.SetSize( aVisSize );
252cdf0e10cSrcweir 				pDrawObj->SetLogicRect( aLogicRect );
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 				//	set document modified (SdrModel::SetChanged is not used)
255cdf0e10cSrcweir 				pViewSh->GetViewData()->GetDocShell()->SetDrawModified();
256cdf0e10cSrcweir 			}
257cdf0e10cSrcweir 		}
258cdf0e10cSrcweir 	}
259cdf0e10cSrcweir }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir void __EXPORT ScClient::MakeVisible()
262cdf0e10cSrcweir {
263cdf0e10cSrcweir 	SdrOle2Obj* pDrawObj = GetDrawObj();
264cdf0e10cSrcweir 	if (pDrawObj)
265cdf0e10cSrcweir 	{
266cdf0e10cSrcweir 		SfxViewShell* pSfxViewSh = GetViewShell();
267cdf0e10cSrcweir 		ScTabViewShell* pViewSh = PTR_CAST( ScTabViewShell, pSfxViewSh );
268cdf0e10cSrcweir 		if (pViewSh)
269cdf0e10cSrcweir 			pViewSh->ScrollToObject( pDrawObj );
270cdf0e10cSrcweir 	}
271cdf0e10cSrcweir }
272cdf0e10cSrcweir 
273