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