xref: /aoo41x/main/sfx2/source/doc/objembed.cxx (revision d119d52d)
1*d119d52dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*d119d52dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*d119d52dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*d119d52dSAndrew Rist  * distributed with this work for additional information
6*d119d52dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*d119d52dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*d119d52dSAndrew Rist  * "License"); you may not use this file except in compliance
9*d119d52dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*d119d52dSAndrew Rist  *
11*d119d52dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*d119d52dSAndrew Rist  *
13*d119d52dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*d119d52dSAndrew Rist  * software distributed under the License is distributed on an
15*d119d52dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*d119d52dSAndrew Rist  * KIND, either express or implied.  See the License for the
17*d119d52dSAndrew Rist  * specific language governing permissions and limitations
18*d119d52dSAndrew Rist  * under the License.
19*d119d52dSAndrew Rist  *
20*d119d52dSAndrew Rist  *************************************************************/
21*d119d52dSAndrew Rist 
22*d119d52dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sfx2.hxx"
26cdf0e10cSrcweir #include <com/sun/star/container/XChild.hpp>
27cdf0e10cSrcweir #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
28cdf0e10cSrcweir #include <com/sun/star/embed/XComponentSupplier.hpp>
29cdf0e10cSrcweir #include <com/sun/star/embed/XEmbedPersist.hpp>
30cdf0e10cSrcweir #include <com/sun/star/util/XCloseable.hpp>
31cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <sfx2/objsh.hxx>
34cdf0e10cSrcweir #include <sfx2/app.hxx>
35cdf0e10cSrcweir #include "objshimp.hxx"
36cdf0e10cSrcweir #include <sfx2/sfx.hrc>
37cdf0e10cSrcweir #include <sfx2/event.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <comphelper/seqstream.hxx>
40cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
41cdf0e10cSrcweir #include <comphelper/storagehelper.hxx>
42cdf0e10cSrcweir #include <svtools/embedtransfer.hxx>
43cdf0e10cSrcweir #include <vcl/outdev.hxx>
44cdf0e10cSrcweir #include <vcl/gdimtf.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir using namespace ::com::sun::star;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir // -----------------------------------------------------------------------
49cdf0e10cSrcweir // TODO/LATER: this workaround must be replaced by API in future if possible
GetParentShellByModel_Impl()50cdf0e10cSrcweir SfxObjectShell* SfxObjectShell::GetParentShellByModel_Impl()
51cdf0e10cSrcweir {
52cdf0e10cSrcweir 	SfxObjectShell* pResult = NULL;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 	try {
55cdf0e10cSrcweir 		uno::Reference< container::XChild > xChildModel( GetModel(), uno::UNO_QUERY );
56cdf0e10cSrcweir 		if ( xChildModel.is() )
57cdf0e10cSrcweir 		{
58cdf0e10cSrcweir 			uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
59cdf0e10cSrcweir 			if ( xParentTunnel.is() )
60cdf0e10cSrcweir 			{
61cdf0e10cSrcweir 				SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
62cdf0e10cSrcweir 				pResult = reinterpret_cast<SfxObjectShell*>(xParentTunnel->getSomething(
63cdf0e10cSrcweir                                                 uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
64cdf0e10cSrcweir 			}
65cdf0e10cSrcweir 		}
66cdf0e10cSrcweir 	}
67cdf0e10cSrcweir 	catch( uno::Exception& )
68cdf0e10cSrcweir 	{
69cdf0e10cSrcweir 		// TODO: error handling
70cdf0e10cSrcweir 	}
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	return pResult;
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir // -----------------------------------------------------------------------
GetDocumentPrinter()76cdf0e10cSrcweir Printer* SfxObjectShell::GetDocumentPrinter()
77cdf0e10cSrcweir {
78cdf0e10cSrcweir 	SfxObjectShell* pParent = GetParentShellByModel_Impl();
79cdf0e10cSrcweir 	if ( pParent )
80cdf0e10cSrcweir 		return pParent->GetDocumentPrinter();
81cdf0e10cSrcweir 	return NULL;
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir // -----------------------------------------------------------------------
GetDocumentRefDev()85cdf0e10cSrcweir OutputDevice* SfxObjectShell::GetDocumentRefDev()
86cdf0e10cSrcweir {
87cdf0e10cSrcweir 	SfxObjectShell* pParent = GetParentShellByModel_Impl();
88cdf0e10cSrcweir 	if ( pParent )
89cdf0e10cSrcweir 		return pParent->GetDocumentRefDev();
90cdf0e10cSrcweir 	return NULL;
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir // -----------------------------------------------------------------------
OnDocumentPrinterChanged(Printer *)94cdf0e10cSrcweir void SfxObjectShell::OnDocumentPrinterChanged( Printer* /*pNewPrinter*/ )
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	// virtual method
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir // -----------------------------------------------------------------------
GetVisArea(sal_uInt16 nAspect) const100cdf0e10cSrcweir Rectangle SfxObjectShell::GetVisArea( sal_uInt16 nAspect ) const
101cdf0e10cSrcweir {
102cdf0e10cSrcweir 	if( nAspect == ASPECT_CONTENT )
103cdf0e10cSrcweir 		return pImp->m_aVisArea;
104cdf0e10cSrcweir 	else if( nAspect == ASPECT_THUMBNAIL )
105cdf0e10cSrcweir 	{
106cdf0e10cSrcweir 		Rectangle aRect;
107cdf0e10cSrcweir 		aRect.SetSize( OutputDevice::LogicToLogic( Size( 5000, 5000 ),
108cdf0e10cSrcweir 										 MAP_100TH_MM, GetMapUnit() ) );
109cdf0e10cSrcweir 		return aRect;
110cdf0e10cSrcweir 	}
111cdf0e10cSrcweir 	return Rectangle();
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir // -----------------------------------------------------------------------
GetVisArea() const115cdf0e10cSrcweir const Rectangle& SfxObjectShell::GetVisArea() const
116cdf0e10cSrcweir {
117cdf0e10cSrcweir 	pImp->m_aVisArea = GetVisArea( ASPECT_CONTENT );
118cdf0e10cSrcweir 	return pImp->m_aVisArea;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir 
121cdf0e10cSrcweir // -----------------------------------------------------------------------
SetVisArea(const Rectangle & rVisArea)122cdf0e10cSrcweir void SfxObjectShell::SetVisArea( const Rectangle & rVisArea )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir     if( pImp->m_aVisArea != rVisArea )
125cdf0e10cSrcweir 	{
126cdf0e10cSrcweir         pImp->m_aVisArea = rVisArea;
127cdf0e10cSrcweir         if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
128cdf0e10cSrcweir         {
129cdf0e10cSrcweir 			if ( IsEnableSetModified() )
130cdf0e10cSrcweir             	SetModified( sal_True );
131cdf0e10cSrcweir 
132cdf0e10cSrcweir            	SFX_APP()->NotifyEvent(SfxEventHint( SFX_EVENT_VISAREACHANGED, GlobalEventConfig::GetEventName(STR_EVENT_VISAREACHANGED), this));
133cdf0e10cSrcweir 
134cdf0e10cSrcweir             /*
135cdf0e10cSrcweir             Size aSize (GetVisArea().GetSize());
136cdf0e10cSrcweir             if ( GetIPEnv() && GetIPEnv()->GetEditWin() )
137cdf0e10cSrcweir                 ViewChanged( ASPECT_CONTENT );
138cdf0e10cSrcweir             */
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 
141cdf0e10cSrcweir             // OutPlace die Gr"o\se des MDI-Fensters anpassen
142cdf0e10cSrcweir             // Unbedingt den Gr"o\senvergleich machen, spart nicht nur Zeit, sondern
143cdf0e10cSrcweir             // vermeidet auch Rundungsfehler !
144cdf0e10cSrcweir             /*
145cdf0e10cSrcweir                 // in case of ole outplace editing the frame should be found
146cdf0e10cSrcweir                 SfxViewFrame* pFrameToResize = pFrame ? pFrame : SfxViewFrame::GetFirst( GetObjectShell() );
147cdf0e10cSrcweir 
148cdf0e10cSrcweir                 if ( pFrameToResize && !pIPF && rRect.GetSize() != aSize &&
149cdf0e10cSrcweir                     !pFrameToResize->IsAdjustPosSizePixelLocked_Impl() )
150cdf0e10cSrcweir 
151cdf0e10cSrcweir                 {
152cdf0e10cSrcweir                     // Zuerst die logischen Koordinaten von IP-Objekt und EditWindow
153cdf0e10cSrcweir                     // ber"ucksichtigen
154cdf0e10cSrcweir                     SfxViewShell *pShell = pFrameToResize->GetViewShell();
155cdf0e10cSrcweir                     Window *pWindow = pShell->GetWindow();
156cdf0e10cSrcweir 
157cdf0e10cSrcweir                     // Da in den Applikationen bei der R"ucktransformation immer die
158cdf0e10cSrcweir                     // Eckpunkte tranformiert werden und nicht die Size (um die Ecken
159cdf0e10cSrcweir                     // alignen zu k"onnen), transformieren wir hier auch die Punkte, um
160cdf0e10cSrcweir                     // m"oglichst wenig Rundungsfehler zu erhalten.
161cdf0e10cSrcweir                     Rectangle aRect = pWindow->LogicToPixel( rRect );
162cdf0e10cSrcweir                     Size aSize = aRect.GetSize();
163cdf0e10cSrcweir                     pShell->GetWindow()->SetSizePixel( aSize );
164cdf0e10cSrcweir                     pFrameToResize->DoAdjustPosSizePixel( pShell, Point(), aSize );
165cdf0e10cSrcweir                 }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir             // bei InPlace die View skalieren
168cdf0e10cSrcweir             if ( GetIPEnv() && GetIPEnv()->GetEditWin() && !bDisableViewScaling && pIPF )
169cdf0e10cSrcweir                 pIPF->GetEnv_Impl()->MakeScale( rRect.GetSize(), GetMapUnit(),
170cdf0e10cSrcweir                             pIPF->GetViewShell()->GetWindow()->GetOutputSizePixel() );
171cdf0e10cSrcweir            */
172cdf0e10cSrcweir         }
173cdf0e10cSrcweir     }
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir // -----------------------------------------------------------------------
SetVisAreaSize(const Size & rVisSize)177cdf0e10cSrcweir void SfxObjectShell::SetVisAreaSize( const Size & rVisSize )
178cdf0e10cSrcweir {
179cdf0e10cSrcweir 	SetVisArea( Rectangle( GetVisArea().TopLeft(), rVisSize ) );
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir // -----------------------------------------------------------------------
GetMiscStatus() const183cdf0e10cSrcweir sal_uIntPtr SfxObjectShell::GetMiscStatus() const
184cdf0e10cSrcweir {
185cdf0e10cSrcweir 	return 0;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir // -----------------------------------------------------------------------
GetMapUnit() const189cdf0e10cSrcweir MapUnit SfxObjectShell::GetMapUnit() const
190cdf0e10cSrcweir {
191cdf0e10cSrcweir 	return pImp->m_nMapUnit;
192cdf0e10cSrcweir }
193cdf0e10cSrcweir 
194cdf0e10cSrcweir // -----------------------------------------------------------------------
SetMapUnit(MapUnit nMapUnit)195cdf0e10cSrcweir void SfxObjectShell::SetMapUnit( MapUnit nMapUnit )
196cdf0e10cSrcweir {
197cdf0e10cSrcweir 	pImp->m_nMapUnit = nMapUnit;
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir // -----------------------------------------------------------------------
FillTransferableObjectDescriptor(TransferableObjectDescriptor & rDesc) const201cdf0e10cSrcweir void SfxObjectShell::FillTransferableObjectDescriptor( TransferableObjectDescriptor& rDesc ) const
202cdf0e10cSrcweir {
203cdf0e10cSrcweir 	sal_uInt32 nClipFormat;
204cdf0e10cSrcweir 	String aAppName, aShortName;
205cdf0e10cSrcweir 	FillClass( &rDesc.maClassName, &nClipFormat, &aAppName, &rDesc.maTypeName, &aShortName, SOFFICE_FILEFORMAT_CURRENT );
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 	rDesc.mnViewAspect = ASPECT_CONTENT;
208cdf0e10cSrcweir 	rDesc.mnOle2Misc = GetMiscStatus();
209cdf0e10cSrcweir 	rDesc.maSize = OutputDevice::LogicToLogic( GetVisArea().GetSize(), GetMapUnit(), MAP_100TH_MM );
210cdf0e10cSrcweir 	rDesc.maDragStartPos = Point();
211cdf0e10cSrcweir 	rDesc.maDisplayName = String();
212cdf0e10cSrcweir 	rDesc.mbCanLink = sal_False;
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir // -----------------------------------------------------------------------
DoDraw(OutputDevice * pDev,const Point & rObjPos,const Size & rSize,const JobSetup & rSetup,sal_uInt16 nAspect)216cdf0e10cSrcweir void SfxObjectShell::DoDraw( OutputDevice* pDev,
217cdf0e10cSrcweir 							const Point & rObjPos,
218cdf0e10cSrcweir 							const Size & rSize,
219cdf0e10cSrcweir 							const JobSetup & rSetup,
220cdf0e10cSrcweir 							sal_uInt16 nAspect )
221cdf0e10cSrcweir {
222cdf0e10cSrcweir 	MapMode aMod = pDev->GetMapMode();
223cdf0e10cSrcweir 	Size aSize = GetVisArea( nAspect ).GetSize();
224cdf0e10cSrcweir 	MapMode aWilliMode( GetMapUnit() );
225cdf0e10cSrcweir 	aSize = pDev->LogicToLogic( aSize, &aWilliMode, &aMod );
226cdf0e10cSrcweir 	if( aSize.Width() && aSize.Height() )
227cdf0e10cSrcweir 	{
228cdf0e10cSrcweir 		Fraction aXF( rSize.Width(), aSize.Width() );
229cdf0e10cSrcweir 		Fraction aYF( rSize.Height(), aSize.Height() );
230cdf0e10cSrcweir 
231cdf0e10cSrcweir //REMOVE			Point aOrg = rObjPos;
232cdf0e10cSrcweir //REMOVE			aMod.SetMapUnit( MAP_100TH_MM );
233cdf0e10cSrcweir //REMOVE			aSize = pDev->LogicToLogic( GetVisArea( nAspect ).GetSize(), &aMod, &aWilliMode );
234cdf0e10cSrcweir 		DoDraw_Impl( pDev, rObjPos, aXF, aYF, rSetup, nAspect );
235cdf0e10cSrcweir 	}
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir // -----------------------------------------------------------------------
DoDraw_Impl(OutputDevice * pDev,const Point & rViewPos,const Fraction & rScaleX,const Fraction & rScaleY,const JobSetup & rSetup,sal_uInt16 nAspect)239cdf0e10cSrcweir void SfxObjectShell::DoDraw_Impl( OutputDevice* pDev,
240cdf0e10cSrcweir 							   const Point & rViewPos,
241cdf0e10cSrcweir 							   const Fraction & rScaleX,
242cdf0e10cSrcweir 							   const Fraction & rScaleY,
243cdf0e10cSrcweir 							   const JobSetup & rSetup,
244cdf0e10cSrcweir 							   sal_uInt16 nAspect )
245cdf0e10cSrcweir {
246cdf0e10cSrcweir 	Rectangle aVisArea  = GetVisArea( nAspect );
247cdf0e10cSrcweir 	// MapUnit des Ziels
248cdf0e10cSrcweir 	MapMode aMapMode( GetMapUnit() );
249cdf0e10cSrcweir 	aMapMode.SetScaleX( rScaleX );
250cdf0e10cSrcweir 	aMapMode.SetScaleY( rScaleY );
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 	// Ziel in Pixel
253cdf0e10cSrcweir 	Point aOrg	 = pDev->LogicToLogic( rViewPos, NULL, &aMapMode );
254cdf0e10cSrcweir 	Point aDelta = aOrg - aVisArea.TopLeft();
255cdf0e10cSrcweir 
256cdf0e10cSrcweir 	// Origin entsprechend zum sichtbaren Bereich verschieben
257cdf0e10cSrcweir 	// Origin mit Scale setzen
258cdf0e10cSrcweir 	aMapMode.SetOrigin( aDelta );
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 	// Deviceeinstellungen sichern
261cdf0e10cSrcweir 	pDev->Push();
262cdf0e10cSrcweir 
263cdf0e10cSrcweir 	Region aRegion;
264cdf0e10cSrcweir 	if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
265cdf0e10cSrcweir 	{
266cdf0e10cSrcweir 		aRegion = pDev->GetClipRegion();
267cdf0e10cSrcweir 		aRegion = pDev->LogicToPixel( aRegion );
268cdf0e10cSrcweir 	}
269cdf0e10cSrcweir 	pDev->SetRelativeMapMode( aMapMode );
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 	GDIMetaFile * pMtf = pDev->GetConnectMetaFile();
272cdf0e10cSrcweir 	if( pMtf )
273cdf0e10cSrcweir 	{
274cdf0e10cSrcweir 		if( pMtf->IsRecord() && pDev->GetOutDevType() != OUTDEV_PRINTER )
275cdf0e10cSrcweir 			pMtf->Stop();
276cdf0e10cSrcweir 		else
277cdf0e10cSrcweir 			pMtf = NULL;
278cdf0e10cSrcweir 	}
279cdf0e10cSrcweir // #ifndef UNX
280cdf0e10cSrcweir 	if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
281cdf0e10cSrcweir // #endif
282cdf0e10cSrcweir 	{
283cdf0e10cSrcweir 		aRegion = pDev->PixelToLogic( aRegion );
284cdf0e10cSrcweir 		pDev->SetClipRegion( aRegion );
285cdf0e10cSrcweir 	}
286cdf0e10cSrcweir 	if( pMtf )
287cdf0e10cSrcweir 		pMtf->Record( pDev );
288cdf0e10cSrcweir 
289cdf0e10cSrcweir //REMOVE		SvOutPlaceObjectRef xOutRef( this );
290cdf0e10cSrcweir //REMOVE		if ( xOutRef.Is() )
291cdf0e10cSrcweir //REMOVE			xOutRef->DrawObject( pDev, rSetup, rSize, nAspect );
292cdf0e10cSrcweir //REMOVE		else
293cdf0e10cSrcweir 		Draw( pDev, rSetup, nAspect );
294cdf0e10cSrcweir //REMOVE		DrawHatch( pDev, aVisArea.TopLeft(), aVisArea.GetSize() );
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 	// Deviceeinstellungen wieder herstellen
297cdf0e10cSrcweir 	pDev->Pop();
298cdf0e10cSrcweir 
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
GetEmbeddedObjectContainer() const301cdf0e10cSrcweir comphelper::EmbeddedObjectContainer& SfxObjectShell::GetEmbeddedObjectContainer() const
302cdf0e10cSrcweir {
303cdf0e10cSrcweir     if ( !pImp->mpObjectContainer )
304cdf0e10cSrcweir         pImp->mpObjectContainer = new comphelper::EmbeddedObjectContainer( ((SfxObjectShell*)this)->GetStorage(), GetModel() );
305cdf0e10cSrcweir     return *pImp->mpObjectContainer;
306cdf0e10cSrcweir }
307cdf0e10cSrcweir 
ClearEmbeddedObjects()308cdf0e10cSrcweir void SfxObjectShell::ClearEmbeddedObjects()
309cdf0e10cSrcweir {
310cdf0e10cSrcweir     // frees alle space taken by embedded objects
311cdf0e10cSrcweir     DELETEZ( pImp->mpObjectContainer );
312cdf0e10cSrcweir }
313cdf0e10cSrcweir 
314