Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / sfx2 / source / doc / objembed.cxx
blob3b2f7331daa1a3d528c0512c5b69060a12070d39
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <com/sun/star/container/XChild.hpp>
30 #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
31 #include <com/sun/star/embed/XComponentSupplier.hpp>
32 #include <com/sun/star/embed/XEmbedPersist.hpp>
33 #include <com/sun/star/util/XCloseable.hpp>
34 #include <com/sun/star/embed/EmbedStates.hpp>
36 #include <sfx2/objsh.hxx>
37 #include <sfx2/app.hxx>
38 #include "objshimp.hxx"
39 #include <sfx2/sfx.hrc>
40 #include <sfx2/event.hxx>
42 #include <comphelper/seqstream.hxx>
43 #include <comphelper/processfactory.hxx>
44 #include <comphelper/storagehelper.hxx>
45 #include <svtools/embedtransfer.hxx>
46 #include <vcl/outdev.hxx>
47 #include <vcl/gdimtf.hxx>
49 using namespace ::com::sun::star;
51 // -----------------------------------------------------------------------
52 // TODO/LATER: this workaround must be replaced by API in future if possible
53 SfxObjectShell* SfxObjectShell::GetParentShellByModel_Impl()
55 SfxObjectShell* pResult = NULL;
57 try {
58 uno::Reference< container::XChild > xChildModel( GetModel(), uno::UNO_QUERY );
59 if ( xChildModel.is() )
61 uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
62 if ( xParentTunnel.is() )
64 SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
65 pResult = reinterpret_cast<SfxObjectShell*>(xParentTunnel->getSomething(
66 uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
70 catch( uno::Exception& )
72 // TODO: error handling
75 return pResult;
78 // -----------------------------------------------------------------------
79 Printer* SfxObjectShell::GetDocumentPrinter()
81 SfxObjectShell* pParent = GetParentShellByModel_Impl();
82 if ( pParent )
83 return pParent->GetDocumentPrinter();
84 return NULL;
87 // -----------------------------------------------------------------------
88 OutputDevice* SfxObjectShell::GetDocumentRefDev()
90 SfxObjectShell* pParent = GetParentShellByModel_Impl();
91 if ( pParent )
92 return pParent->GetDocumentRefDev();
93 return NULL;
96 // -----------------------------------------------------------------------
97 void SfxObjectShell::OnDocumentPrinterChanged( Printer* /*pNewPrinter*/ )
99 // virtual method
102 // -----------------------------------------------------------------------
103 Rectangle SfxObjectShell::GetVisArea( sal_uInt16 nAspect ) const
105 if( nAspect == ASPECT_CONTENT )
106 return pImp->m_aVisArea;
107 else if( nAspect == ASPECT_THUMBNAIL )
109 Rectangle aRect;
110 aRect.SetSize( OutputDevice::LogicToLogic( Size( 5000, 5000 ),
111 MAP_100TH_MM, GetMapUnit() ) );
112 return aRect;
114 return Rectangle();
117 // -----------------------------------------------------------------------
118 const Rectangle& SfxObjectShell::GetVisArea() const
120 pImp->m_aVisArea = GetVisArea( ASPECT_CONTENT );
121 return pImp->m_aVisArea;
124 // -----------------------------------------------------------------------
125 void SfxObjectShell::SetVisArea( const Rectangle & rVisArea )
127 if( pImp->m_aVisArea != rVisArea )
129 pImp->m_aVisArea = rVisArea;
130 if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
132 if ( IsEnableSetModified() )
133 SetModified( sal_True );
135 SFX_APP()->NotifyEvent(SfxEventHint( SFX_EVENT_VISAREACHANGED, GlobalEventConfig::GetEventName(STR_EVENT_VISAREACHANGED), this));
140 // -----------------------------------------------------------------------
141 void SfxObjectShell::SetVisAreaSize( const Size & rVisSize )
143 SetVisArea( Rectangle( GetVisArea().TopLeft(), rVisSize ) );
146 // -----------------------------------------------------------------------
147 sal_uIntPtr SfxObjectShell::GetMiscStatus() const
149 return 0;
152 // -----------------------------------------------------------------------
153 MapUnit SfxObjectShell::GetMapUnit() const
155 return pImp->m_nMapUnit;
158 // -----------------------------------------------------------------------
159 void SfxObjectShell::SetMapUnit( MapUnit nMapUnit )
161 pImp->m_nMapUnit = nMapUnit;
164 // -----------------------------------------------------------------------
165 void SfxObjectShell::FillTransferableObjectDescriptor( TransferableObjectDescriptor& rDesc ) const
167 sal_uInt32 nClipFormat;
168 String aAppName, aShortName;
169 FillClass( &rDesc.maClassName, &nClipFormat, &aAppName, &rDesc.maTypeName, &aShortName, SOFFICE_FILEFORMAT_CURRENT );
171 rDesc.mnViewAspect = ASPECT_CONTENT;
172 rDesc.mnOle2Misc = GetMiscStatus();
173 rDesc.maSize = OutputDevice::LogicToLogic( GetVisArea().GetSize(), GetMapUnit(), MAP_100TH_MM );
174 rDesc.maDragStartPos = Point();
175 rDesc.maDisplayName = String();
176 rDesc.mbCanLink = sal_False;
179 // -----------------------------------------------------------------------
180 void SfxObjectShell::DoDraw( OutputDevice* pDev,
181 const Point & rObjPos,
182 const Size & rSize,
183 const JobSetup & rSetup,
184 sal_uInt16 nAspect )
186 MapMode aMod = pDev->GetMapMode();
187 Size aSize = GetVisArea( nAspect ).GetSize();
188 MapMode aWilliMode( GetMapUnit() );
189 aSize = pDev->LogicToLogic( aSize, &aWilliMode, &aMod );
190 if( aSize.Width() && aSize.Height() )
192 Fraction aXF( rSize.Width(), aSize.Width() );
193 Fraction aYF( rSize.Height(), aSize.Height() );
195 DoDraw_Impl( pDev, rObjPos, aXF, aYF, rSetup, nAspect );
199 // -----------------------------------------------------------------------
200 void SfxObjectShell::DoDraw_Impl( OutputDevice* pDev,
201 const Point & rViewPos,
202 const Fraction & rScaleX,
203 const Fraction & rScaleY,
204 const JobSetup & rSetup,
205 sal_uInt16 nAspect )
207 Rectangle aVisArea = GetVisArea( nAspect );
208 // MapUnit des Ziels
209 MapMode aMapMode( GetMapUnit() );
210 aMapMode.SetScaleX( rScaleX );
211 aMapMode.SetScaleY( rScaleY );
213 // Target in Pixels
214 Point aOrg = pDev->LogicToLogic( rViewPos, NULL, &aMapMode );
215 Point aDelta = aOrg - aVisArea.TopLeft();
217 // Origin moved according to the viewable area
218 // Origin set with Scale
219 aMapMode.SetOrigin( aDelta );
221 // Secure the Device settings
222 pDev->Push();
224 Region aRegion;
225 if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
227 aRegion = pDev->GetClipRegion();
228 aRegion = pDev->LogicToPixel( aRegion );
230 pDev->SetRelativeMapMode( aMapMode );
232 GDIMetaFile * pMtf = pDev->GetConnectMetaFile();
233 if( pMtf )
235 if( pMtf->IsRecord() && pDev->GetOutDevType() != OUTDEV_PRINTER )
236 pMtf->Stop();
237 else
238 pMtf = NULL;
240 if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
242 aRegion = pDev->PixelToLogic( aRegion );
243 pDev->SetClipRegion( aRegion );
245 if( pMtf )
246 pMtf->Record( pDev );
248 Draw( pDev, rSetup, nAspect );
250 // Restore Device settings
251 pDev->Pop();
255 comphelper::EmbeddedObjectContainer& SfxObjectShell::GetEmbeddedObjectContainer() const
257 if ( !pImp->mpObjectContainer )
258 pImp->mpObjectContainer = new comphelper::EmbeddedObjectContainer( ((SfxObjectShell*)this)->GetStorage(), GetModel() );
259 return *pImp->mpObjectContainer;
262 void SfxObjectShell::ClearEmbeddedObjects()
264 // frees alle space taken by embedded objects
265 DELETEZ( pImp->mpObjectContainer );
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */