merge the formfield patch from ooo-build
[ooovba.git] / sfx2 / source / doc / objembed.cxx
blobc50539a0bd126aaa43d8181d11e49cbfe614866e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: objembed.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sfx2.hxx"
33 #include <com/sun/star/container/XChild.hpp>
34 #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
35 #include <com/sun/star/embed/XComponentSupplier.hpp>
36 #include <com/sun/star/embed/XEmbedPersist.hpp>
37 #include <com/sun/star/util/XCloseable.hpp>
38 #include <com/sun/star/embed/EmbedStates.hpp>
40 #include <sfx2/objsh.hxx>
41 #include <sfx2/app.hxx>
42 #include "objshimp.hxx"
43 #include <sfx2/sfx.hrc>
44 #include <sfx2/event.hxx>
46 #include <comphelper/seqstream.hxx>
47 #include <comphelper/processfactory.hxx>
48 #include <comphelper/storagehelper.hxx>
49 #include <svtools/embedtransfer.hxx>
50 #include <vcl/outdev.hxx>
51 #include <vcl/gdimtf.hxx>
53 using namespace ::com::sun::star;
55 // -----------------------------------------------------------------------
56 // TODO/LATER: this workaround must be replaced by API in future if possible
57 SfxObjectShell* SfxObjectShell::GetParentShellByModel_Impl()
59 SfxObjectShell* pResult = NULL;
61 try {
62 uno::Reference< container::XChild > xChildModel( GetModel(), uno::UNO_QUERY );
63 if ( xChildModel.is() )
65 uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
66 if ( xParentTunnel.is() )
68 SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
69 pResult = reinterpret_cast<SfxObjectShell*>(xParentTunnel->getSomething(
70 uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
74 catch( uno::Exception& )
76 // TODO: error handling
79 return pResult;
82 // -----------------------------------------------------------------------
83 Printer* SfxObjectShell::GetDocumentPrinter()
85 SfxObjectShell* pParent = GetParentShellByModel_Impl();
86 if ( pParent )
87 return pParent->GetDocumentPrinter();
88 return NULL;
91 // -----------------------------------------------------------------------
92 OutputDevice* SfxObjectShell::GetDocumentRefDev()
94 SfxObjectShell* pParent = GetParentShellByModel_Impl();
95 if ( pParent )
96 return pParent->GetDocumentRefDev();
97 return NULL;
100 // -----------------------------------------------------------------------
101 void SfxObjectShell::OnDocumentPrinterChanged( Printer* /*pNewPrinter*/ )
103 // virtual method
106 // -----------------------------------------------------------------------
107 Rectangle SfxObjectShell::GetVisArea( USHORT nAspect ) const
109 if( nAspect == ASPECT_CONTENT )
110 return pImp->m_aVisArea;
111 else if( nAspect == ASPECT_THUMBNAIL )
113 Rectangle aRect;
114 aRect.SetSize( OutputDevice::LogicToLogic( Size( 5000, 5000 ),
115 MAP_100TH_MM, GetMapUnit() ) );
116 return aRect;
118 return Rectangle();
121 // -----------------------------------------------------------------------
122 const Rectangle& SfxObjectShell::GetVisArea() const
124 pImp->m_aVisArea = GetVisArea( ASPECT_CONTENT );
125 return pImp->m_aVisArea;
128 // -----------------------------------------------------------------------
129 void SfxObjectShell::SetVisArea( const Rectangle & rVisArea )
131 if( pImp->m_aVisArea != rVisArea )
133 pImp->m_aVisArea = rVisArea;
134 if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
136 if ( IsEnableSetModified() )
137 SetModified( TRUE );
139 SFX_APP()->NotifyEvent(SfxEventHint( SFX_EVENT_VISAREACHANGED, GlobalEventConfig::GetEventName(STR_EVENT_VISAREACHANGED), this));
142 Size aSize (GetVisArea().GetSize());
143 if ( GetIPEnv() && GetIPEnv()->GetEditWin() )
144 ViewChanged( ASPECT_CONTENT );
148 // OutPlace die Gr"o\se des MDI-Fensters anpassen
149 // Unbedingt den Gr"o\senvergleich machen, spart nicht nur Zeit, sondern
150 // vermeidet auch Rundungsfehler !
152 // in case of ole outplace editing the frame should be found
153 SfxViewFrame* pFrameToResize = pFrame ? pFrame : SfxViewFrame::GetFirst( GetObjectShell() );
155 if ( pFrameToResize && !pIPF && rRect.GetSize() != aSize &&
156 !pFrameToResize->IsAdjustPosSizePixelLocked_Impl() )
159 // Zuerst die logischen Koordinaten von IP-Objekt und EditWindow
160 // ber"ucksichtigen
161 SfxViewShell *pShell = pFrameToResize->GetViewShell();
162 Window *pWindow = pShell->GetWindow();
164 // Da in den Applikationen bei der R"ucktransformation immer die
165 // Eckpunkte tranformiert werden und nicht die Size (um die Ecken
166 // alignen zu k"onnen), transformieren wir hier auch die Punkte, um
167 // m"oglichst wenig Rundungsfehler zu erhalten.
168 Rectangle aRect = pWindow->LogicToPixel( rRect );
169 Size aSize = aRect.GetSize();
170 pShell->GetWindow()->SetSizePixel( aSize );
171 pFrameToResize->DoAdjustPosSizePixel( pShell, Point(), aSize );
174 // bei InPlace die View skalieren
175 if ( GetIPEnv() && GetIPEnv()->GetEditWin() && !bDisableViewScaling && pIPF )
176 pIPF->GetEnv_Impl()->MakeScale( rRect.GetSize(), GetMapUnit(),
177 pIPF->GetViewShell()->GetWindow()->GetOutputSizePixel() );
183 // -----------------------------------------------------------------------
184 void SfxObjectShell::SetVisAreaSize( const Size & rVisSize )
186 SetVisArea( Rectangle( GetVisArea().TopLeft(), rVisSize ) );
189 // -----------------------------------------------------------------------
190 ULONG SfxObjectShell::GetMiscStatus() const
192 return 0;
195 // -----------------------------------------------------------------------
196 MapUnit SfxObjectShell::GetMapUnit() const
198 return pImp->m_nMapUnit;
201 // -----------------------------------------------------------------------
202 void SfxObjectShell::SetMapUnit( MapUnit nMapUnit )
204 pImp->m_nMapUnit = nMapUnit;
207 // -----------------------------------------------------------------------
208 void SfxObjectShell::FillTransferableObjectDescriptor( TransferableObjectDescriptor& rDesc ) const
210 sal_uInt32 nClipFormat;
211 String aAppName, aShortName;
212 FillClass( &rDesc.maClassName, &nClipFormat, &aAppName, &rDesc.maTypeName, &aShortName, SOFFICE_FILEFORMAT_CURRENT );
214 rDesc.mnViewAspect = ASPECT_CONTENT;
215 rDesc.mnOle2Misc = GetMiscStatus();
216 rDesc.maSize = OutputDevice::LogicToLogic( GetVisArea().GetSize(), GetMapUnit(), MAP_100TH_MM );
217 rDesc.maDragStartPos = Point();
218 rDesc.maDisplayName = String();
219 rDesc.mbCanLink = FALSE;
222 // -----------------------------------------------------------------------
223 void SfxObjectShell::DoDraw( OutputDevice* pDev,
224 const Point & rObjPos,
225 const Size & rSize,
226 const JobSetup & rSetup,
227 USHORT nAspect )
229 MapMode aMod = pDev->GetMapMode();
230 Size aSize = GetVisArea( nAspect ).GetSize();
231 MapMode aWilliMode( GetMapUnit() );
232 aSize = pDev->LogicToLogic( aSize, &aWilliMode, &aMod );
233 if( aSize.Width() && aSize.Height() )
235 Fraction aXF( rSize.Width(), aSize.Width() );
236 Fraction aYF( rSize.Height(), aSize.Height() );
238 //REMOVE Point aOrg = rObjPos;
239 //REMOVE aMod.SetMapUnit( MAP_100TH_MM );
240 //REMOVE aSize = pDev->LogicToLogic( GetVisArea( nAspect ).GetSize(), &aMod, &aWilliMode );
241 DoDraw_Impl( pDev, rObjPos, aXF, aYF, rSetup, nAspect );
245 // -----------------------------------------------------------------------
246 void SfxObjectShell::DoDraw_Impl( OutputDevice* pDev,
247 const Point & rViewPos,
248 const Fraction & rScaleX,
249 const Fraction & rScaleY,
250 const JobSetup & rSetup,
251 USHORT nAspect )
253 Rectangle aVisArea = GetVisArea( nAspect );
254 // MapUnit des Ziels
255 MapMode aMapMode( GetMapUnit() );
256 aMapMode.SetScaleX( rScaleX );
257 aMapMode.SetScaleY( rScaleY );
259 // Ziel in Pixel
260 Point aOrg = pDev->LogicToLogic( rViewPos, NULL, &aMapMode );
261 Point aDelta = aOrg - aVisArea.TopLeft();
263 // Origin entsprechend zum sichtbaren Bereich verschieben
264 // Origin mit Scale setzen
265 aMapMode.SetOrigin( aDelta );
267 // Deviceeinstellungen sichern
268 pDev->Push();
270 Region aRegion;
271 if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
273 aRegion = pDev->GetClipRegion();
274 aRegion = pDev->LogicToPixel( aRegion );
276 pDev->SetRelativeMapMode( aMapMode );
278 GDIMetaFile * pMtf = pDev->GetConnectMetaFile();
279 if( pMtf )
281 if( pMtf->IsRecord() && pDev->GetOutDevType() != OUTDEV_PRINTER )
282 pMtf->Stop();
283 else
284 pMtf = NULL;
286 // #ifndef UNX
287 if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
288 // #endif
290 aRegion = pDev->PixelToLogic( aRegion );
291 pDev->SetClipRegion( aRegion );
293 if( pMtf )
294 pMtf->Record( pDev );
296 //REMOVE SvOutPlaceObjectRef xOutRef( this );
297 //REMOVE if ( xOutRef.Is() )
298 //REMOVE xOutRef->DrawObject( pDev, rSetup, rSize, nAspect );
299 //REMOVE else
300 Draw( pDev, rSetup, nAspect );
301 //REMOVE DrawHatch( pDev, aVisArea.TopLeft(), aVisArea.GetSize() );
303 // Deviceeinstellungen wieder herstellen
304 pDev->Pop();
308 comphelper::EmbeddedObjectContainer& SfxObjectShell::GetEmbeddedObjectContainer() const
310 if ( !pImp->mpObjectContainer )
311 pImp->mpObjectContainer = new comphelper::EmbeddedObjectContainer( ((SfxObjectShell*)this)->GetStorage(), pImp->xModel );
312 return *pImp->mpObjectContainer;
315 void SfxObjectShell::ClearEmbeddedObjects()
317 // frees alle space taken by embedded objects
318 DELETEZ( pImp->mpObjectContainer );