Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / doc / objembed.cxx
blob1a04f9711ebe6d58da390cd22c8c85c3f85ff600
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 <tools/fract.hxx>
38 #include <vcl/outdev.hxx>
39 #include <vcl/gdimtf.hxx>
41 using namespace ::com::sun::star;
44 // TODO/LATER: this workaround must be replaced by API in future if possible
45 SfxObjectShell* SfxObjectShell::GetParentShellByModel_Impl()
47 SfxObjectShell* pResult = NULL;
49 try {
50 uno::Reference< container::XChild > xChildModel( GetModel(), uno::UNO_QUERY );
51 if ( xChildModel.is() )
53 uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
54 if ( xParentTunnel.is() )
56 SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
57 pResult = reinterpret_cast<SfxObjectShell*>(xParentTunnel->getSomething(
58 uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
62 catch( uno::Exception& )
64 // TODO: error handling
67 return pResult;
71 Printer* SfxObjectShell::GetDocumentPrinter()
73 SfxObjectShell* pParent = GetParentShellByModel_Impl();
74 if ( pParent )
75 return pParent->GetDocumentPrinter();
76 return NULL;
80 OutputDevice* SfxObjectShell::GetDocumentRefDev()
82 SfxObjectShell* pParent = GetParentShellByModel_Impl();
83 if ( pParent )
84 return pParent->GetDocumentRefDev();
85 return NULL;
89 void SfxObjectShell::OnDocumentPrinterChanged( Printer* /*pNewPrinter*/ )
91 // virtual method
95 Rectangle SfxObjectShell::GetVisArea( sal_uInt16 nAspect ) const
97 if( nAspect == ASPECT_CONTENT )
98 return pImp->m_aVisArea;
99 else if( nAspect == ASPECT_THUMBNAIL )
101 Rectangle aRect;
102 aRect.SetSize( OutputDevice::LogicToLogic( Size( 5000, 5000 ),
103 MAP_100TH_MM, GetMapUnit() ) );
104 return aRect;
106 return Rectangle();
110 const Rectangle& SfxObjectShell::GetVisArea() const
112 pImp->m_aVisArea = GetVisArea( ASPECT_CONTENT );
113 return pImp->m_aVisArea;
117 void SfxObjectShell::SetVisArea( const Rectangle & rVisArea )
119 if( pImp->m_aVisArea != rVisArea )
121 pImp->m_aVisArea = rVisArea;
122 if ( GetCreateMode() == SfxObjectCreateMode::EMBEDDED )
124 if ( IsEnableSetModified() )
125 SetModified( true );
127 SfxGetpApp()->NotifyEvent(SfxEventHint( SFX_EVENT_VISAREACHANGED, GlobalEventConfig::GetEventName(GlobalEventId::VISAREACHANGED), this));
133 void SfxObjectShell::SetVisAreaSize( const Size & rVisSize )
135 SetVisArea( Rectangle( GetVisArea().TopLeft(), rVisSize ) );
139 sal_uIntPtr SfxObjectShell::GetMiscStatus() const
141 return 0;
145 MapUnit SfxObjectShell::GetMapUnit() const
147 return pImp->m_nMapUnit;
151 void SfxObjectShell::SetMapUnit( MapUnit nMapUnit )
153 pImp->m_nMapUnit = nMapUnit;
157 void SfxObjectShell::FillTransferableObjectDescriptor( TransferableObjectDescriptor& rDesc ) const
159 SotClipboardFormatId nClipFormat;
160 OUString aAppName, aShortName;
161 FillClass( &rDesc.maClassName, &nClipFormat, &aAppName, &rDesc.maTypeName, &aShortName, SOFFICE_FILEFORMAT_CURRENT );
163 rDesc.mnViewAspect = ASPECT_CONTENT;
164 rDesc.mnOle2Misc = GetMiscStatus();
165 rDesc.maSize = OutputDevice::LogicToLogic( GetVisArea().GetSize(), GetMapUnit(), MAP_100TH_MM );
166 rDesc.maDragStartPos = Point();
167 rDesc.maDisplayName.clear();
168 rDesc.mbCanLink = false;
172 void SfxObjectShell::DoDraw( OutputDevice* pDev,
173 const Point & rObjPos,
174 const Size & rSize,
175 const JobSetup & rSetup,
176 sal_uInt16 nAspect )
178 MapMode aMod = pDev->GetMapMode();
179 Size aSize = GetVisArea( nAspect ).GetSize();
180 MapMode aWilliMode( GetMapUnit() );
181 aSize = pDev->LogicToLogic( aSize, &aWilliMode, &aMod );
182 if( aSize.Width() && aSize.Height() )
184 Fraction aXF( rSize.Width(), aSize.Width() );
185 Fraction aYF( rSize.Height(), aSize.Height() );
187 DoDraw_Impl( pDev, rObjPos, aXF, aYF, rSetup, nAspect );
192 void SfxObjectShell::DoDraw_Impl( OutputDevice* pDev,
193 const Point & rViewPos,
194 const Fraction & rScaleX,
195 const Fraction & rScaleY,
196 const JobSetup & rSetup,
197 sal_uInt16 nAspect )
199 Rectangle aVisArea = GetVisArea( nAspect );
200 // MapUnit des Ziels
201 MapMode aMapMode( GetMapUnit() );
202 aMapMode.SetScaleX( rScaleX );
203 aMapMode.SetScaleY( rScaleY );
205 // Target in Pixels
206 Point aOrg = pDev->LogicToLogic( rViewPos, NULL, &aMapMode );
207 Point aDelta = aOrg - aVisArea.TopLeft();
209 // Origin moved according to the viewable area
210 // Origin set with Scale
211 aMapMode.SetOrigin( aDelta );
213 // Secure the Device settings
214 pDev->Push();
216 vcl::Region aRegion;
217 if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
219 aRegion = pDev->GetClipRegion();
220 aRegion = pDev->LogicToPixel( aRegion );
222 pDev->SetRelativeMapMode( aMapMode );
224 GDIMetaFile * pMtf = pDev->GetConnectMetaFile();
225 if( pMtf )
227 if( pMtf->IsRecord() && pDev->GetOutDevType() != OUTDEV_PRINTER )
228 pMtf->Stop();
229 else
230 pMtf = NULL;
232 if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
234 aRegion = pDev->PixelToLogic( aRegion );
235 pDev->SetClipRegion( aRegion );
237 if( pMtf )
238 pMtf->Record( pDev );
240 Draw( pDev, rSetup, nAspect );
242 // Restore Device settings
243 pDev->Pop();
247 comphelper::EmbeddedObjectContainer& SfxObjectShell::GetEmbeddedObjectContainer() const
249 if ( !pImp->mpObjectContainer )
250 pImp->mpObjectContainer = new comphelper::EmbeddedObjectContainer( const_cast<SfxObjectShell*>(this)->GetStorage(), GetModel() );
251 return *pImp->mpObjectContainer;
254 void SfxObjectShell::ClearEmbeddedObjects()
256 // frees alle space taken by embedded objects
257 DELETEZ( pImp->mpObjectContainer );
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */