Bump version to 4.2-24
[LibreOffice.git] / sfx2 / source / doc / objembed.cxx
blob32cfcaf270e2a93ce7e37d5ed5de8537535bc982
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/container/XChild.hpp>
21 #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
22 #include <com/sun/star/embed/XComponentSupplier.hpp>
23 #include <com/sun/star/embed/XEmbedPersist.hpp>
24 #include <com/sun/star/util/XCloseable.hpp>
25 #include <com/sun/star/embed/EmbedStates.hpp>
27 #include <sfx2/objsh.hxx>
28 #include <sfx2/app.hxx>
29 #include "objshimp.hxx"
30 #include <sfx2/sfx.hrc>
31 #include <sfx2/event.hxx>
33 #include <comphelper/seqstream.hxx>
34 #include <comphelper/processfactory.hxx>
35 #include <comphelper/storagehelper.hxx>
36 #include <svtools/embedtransfer.hxx>
37 #include <vcl/outdev.hxx>
38 #include <vcl/gdimtf.hxx>
40 using namespace ::com::sun::star;
42 // -----------------------------------------------------------------------
43 // TODO/LATER: this workaround must be replaced by API in future if possible
44 SfxObjectShell* SfxObjectShell::GetParentShellByModel_Impl()
46 SfxObjectShell* pResult = NULL;
48 try {
49 uno::Reference< container::XChild > xChildModel( GetModel(), uno::UNO_QUERY );
50 if ( xChildModel.is() )
52 uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
53 if ( xParentTunnel.is() )
55 SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
56 pResult = reinterpret_cast<SfxObjectShell*>(xParentTunnel->getSomething(
57 uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
61 catch( uno::Exception& )
63 // TODO: error handling
66 return pResult;
69 // -----------------------------------------------------------------------
70 Printer* SfxObjectShell::GetDocumentPrinter()
72 SfxObjectShell* pParent = GetParentShellByModel_Impl();
73 if ( pParent )
74 return pParent->GetDocumentPrinter();
75 return NULL;
78 // -----------------------------------------------------------------------
79 OutputDevice* SfxObjectShell::GetDocumentRefDev()
81 SfxObjectShell* pParent = GetParentShellByModel_Impl();
82 if ( pParent )
83 return pParent->GetDocumentRefDev();
84 return NULL;
87 // -----------------------------------------------------------------------
88 void SfxObjectShell::OnDocumentPrinterChanged( Printer* /*pNewPrinter*/ )
90 // virtual method
93 // -----------------------------------------------------------------------
94 Rectangle SfxObjectShell::GetVisArea( sal_uInt16 nAspect ) const
96 if( nAspect == ASPECT_CONTENT )
97 return pImp->m_aVisArea;
98 else if( nAspect == ASPECT_THUMBNAIL )
100 Rectangle aRect;
101 aRect.SetSize( OutputDevice::LogicToLogic( Size( 5000, 5000 ),
102 MAP_100TH_MM, GetMapUnit() ) );
103 return aRect;
105 return Rectangle();
108 // -----------------------------------------------------------------------
109 const Rectangle& SfxObjectShell::GetVisArea() const
111 pImp->m_aVisArea = GetVisArea( ASPECT_CONTENT );
112 return pImp->m_aVisArea;
115 // -----------------------------------------------------------------------
116 void SfxObjectShell::SetVisArea( const Rectangle & rVisArea )
118 if( pImp->m_aVisArea != rVisArea )
120 pImp->m_aVisArea = rVisArea;
121 if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
123 if ( IsEnableSetModified() )
124 SetModified( sal_True );
126 SFX_APP()->NotifyEvent(SfxEventHint( SFX_EVENT_VISAREACHANGED, GlobalEventConfig::GetEventName(STR_EVENT_VISAREACHANGED), this));
131 // -----------------------------------------------------------------------
132 void SfxObjectShell::SetVisAreaSize( const Size & rVisSize )
134 SetVisArea( Rectangle( GetVisArea().TopLeft(), rVisSize ) );
137 // -----------------------------------------------------------------------
138 sal_uIntPtr SfxObjectShell::GetMiscStatus() const
140 return 0;
143 // -----------------------------------------------------------------------
144 MapUnit SfxObjectShell::GetMapUnit() const
146 return pImp->m_nMapUnit;
149 // -----------------------------------------------------------------------
150 void SfxObjectShell::SetMapUnit( MapUnit nMapUnit )
152 pImp->m_nMapUnit = nMapUnit;
155 // -----------------------------------------------------------------------
156 void SfxObjectShell::FillTransferableObjectDescriptor( TransferableObjectDescriptor& rDesc ) const
158 sal_uInt32 nClipFormat;
159 OUString aAppName, aShortName;
160 FillClass( &rDesc.maClassName, &nClipFormat, &aAppName, &rDesc.maTypeName, &aShortName, SOFFICE_FILEFORMAT_CURRENT );
162 rDesc.mnViewAspect = ASPECT_CONTENT;
163 rDesc.mnOle2Misc = GetMiscStatus();
164 rDesc.maSize = OutputDevice::LogicToLogic( GetVisArea().GetSize(), GetMapUnit(), MAP_100TH_MM );
165 rDesc.maDragStartPos = Point();
166 rDesc.maDisplayName = "";
167 rDesc.mbCanLink = sal_False;
170 // -----------------------------------------------------------------------
171 void SfxObjectShell::DoDraw( OutputDevice* pDev,
172 const Point & rObjPos,
173 const Size & rSize,
174 const JobSetup & rSetup,
175 sal_uInt16 nAspect )
177 MapMode aMod = pDev->GetMapMode();
178 Size aSize = GetVisArea( nAspect ).GetSize();
179 MapMode aWilliMode( GetMapUnit() );
180 aSize = pDev->LogicToLogic( aSize, &aWilliMode, &aMod );
181 if( aSize.Width() && aSize.Height() )
183 Fraction aXF( rSize.Width(), aSize.Width() );
184 Fraction aYF( rSize.Height(), aSize.Height() );
186 DoDraw_Impl( pDev, rObjPos, aXF, aYF, rSetup, nAspect );
190 // -----------------------------------------------------------------------
191 void SfxObjectShell::DoDraw_Impl( OutputDevice* pDev,
192 const Point & rViewPos,
193 const Fraction & rScaleX,
194 const Fraction & rScaleY,
195 const JobSetup & rSetup,
196 sal_uInt16 nAspect )
198 Rectangle aVisArea = GetVisArea( nAspect );
199 // MapUnit des Ziels
200 MapMode aMapMode( GetMapUnit() );
201 aMapMode.SetScaleX( rScaleX );
202 aMapMode.SetScaleY( rScaleY );
204 // Target in Pixels
205 Point aOrg = pDev->LogicToLogic( rViewPos, NULL, &aMapMode );
206 Point aDelta = aOrg - aVisArea.TopLeft();
208 // Origin moved according to the viewable area
209 // Origin set with Scale
210 aMapMode.SetOrigin( aDelta );
212 // Secure the Device settings
213 pDev->Push();
215 Region aRegion;
216 if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
218 aRegion = pDev->GetClipRegion();
219 aRegion = pDev->LogicToPixel( aRegion );
221 pDev->SetRelativeMapMode( aMapMode );
223 GDIMetaFile * pMtf = pDev->GetConnectMetaFile();
224 if( pMtf )
226 if( pMtf->IsRecord() && pDev->GetOutDevType() != OUTDEV_PRINTER )
227 pMtf->Stop();
228 else
229 pMtf = NULL;
231 if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
233 aRegion = pDev->PixelToLogic( aRegion );
234 pDev->SetClipRegion( aRegion );
236 if( pMtf )
237 pMtf->Record( pDev );
239 Draw( pDev, rSetup, nAspect );
241 // Restore Device settings
242 pDev->Pop();
246 comphelper::EmbeddedObjectContainer& SfxObjectShell::GetEmbeddedObjectContainer() const
248 if ( !pImp->mpObjectContainer )
249 pImp->mpObjectContainer = new comphelper::EmbeddedObjectContainer( ((SfxObjectShell*)this)->GetStorage(), GetModel() );
250 return *pImp->mpObjectContainer;
253 void SfxObjectShell::ClearEmbeddedObjects()
255 // frees alle space taken by embedded objects
256 DELETEZ( pImp->mpObjectContainer );
259 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */