LibreOffice Module sfx2 (master) 1
objembed.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <sfx2/objsh.hxx>
21#include <sfx2/app.hxx>
22#include <objshimp.hxx>
23#include <sfx2/event.hxx>
24
26#include <tools/fract.hxx>
27#include <vcl/transfer.hxx>
28#include <vcl/outdev.hxx>
29#include <vcl/gdimtf.hxx>
30
31using namespace ::com::sun::star;
32
33
35{
37 if ( pParent )
38 return pParent->GetDocumentPrinter();
39 return nullptr;
40}
41
42
44{
46 if ( pParent )
47 return pParent->GetDocumentRefDev();
48 return nullptr;
49}
50
51
53{
54 // virtual method
55}
56
57
59{
60 if( nAspect == ASPECT_CONTENT )
61 return pImpl->m_aVisArea;
62 else if( nAspect == ASPECT_THUMBNAIL )
63 {
64 tools::Rectangle aRect;
65 aRect.SetSize( OutputDevice::LogicToLogic( Size( 5000, 5000 ),
66 MapMode(MapUnit::Map100thMM), MapMode(GetMapUnit())));
67 return aRect;
68 }
69 return tools::Rectangle();
70}
71
72
74{
75 pImpl->m_aVisArea = GetVisArea( ASPECT_CONTENT );
76 return pImpl->m_aVisArea;
77}
78
79
81{
82 if( pImpl->m_aVisArea != rVisArea )
83 {
84 pImpl->m_aVisArea = rVisArea;
86 {
87 if ( IsEnableSetModified() )
89
91 }
92 }
93}
94
95
96void SfxObjectShell::SetVisAreaSize( const Size & rVisSize )
97{
99}
100
101
103{
104 return pImpl->m_nMapUnit;
105}
106
107
109{
110 pImpl->m_nMapUnit = nMapUnit;
111}
112
113
115{
116 SotClipboardFormatId nClipFormat;
117 FillClass( &rDesc.maClassName, &nClipFormat, &rDesc.maTypeName, SOFFICE_FILEFORMAT_CURRENT );
118
120 rDesc.maSize = OutputDevice::LogicToLogic(GetVisArea().GetSize(), MapMode(GetMapUnit()), MapMode(MapUnit::Map100thMM));
121 rDesc.maDragStartPos = Point();
122 rDesc.maDisplayName.clear();
123}
124
126 const Point & rObjPos,
127 const Size & rSize,
128 const JobSetup & rSetup,
129 sal_uInt16 nAspect,
130 bool bOutputForScreen )
131{
132 if (!rSize.Width() || !rSize.Height())
133 return;
134
135 MapMode aMod = pDev->GetMapMode();
136 Size aSize = GetVisArea( nAspect ).GetSize();
137 MapMode aWilliMode( GetMapUnit() );
138 aSize = pDev->LogicToLogic( aSize, &aWilliMode, &aMod );
139 if( aSize.Width() && aSize.Height() )
140 {
141 Fraction aXF( rSize.Width(), aSize.Width() );
142 Fraction aYF( rSize.Height(), aSize.Height() );
143
144 DoDraw_Impl(pDev, rObjPos, aXF, aYF, rSetup, nAspect, bOutputForScreen);
145 }
146}
147
149 const Point & rViewPos,
150 const Fraction & rScaleX,
151 const Fraction & rScaleY,
152 const JobSetup & rSetup,
153 sal_uInt16 nAspect,
154 bool bOutputForScreen )
155{
156 tools::Rectangle aVisArea = GetVisArea( nAspect );
157 // MapUnit of the target
158 MapMode aMapMode( GetMapUnit() );
159 aMapMode.SetScaleX( rScaleX );
160 aMapMode.SetScaleY( rScaleY );
161
162 // Target in Pixels
163 Point aOrg = pDev->LogicToLogic( rViewPos, nullptr, &aMapMode );
164 Point aDelta = aOrg - aVisArea.TopLeft();
165
166 // Origin moved according to the viewable area
167 // Origin set with Scale
168 aMapMode.SetOrigin( aDelta );
169
170 // Secure the Device settings
171 pDev->Push();
172
173 vcl::Region aRegion;
174 if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
175 {
176 aRegion = pDev->GetClipRegion();
177 aRegion = pDev->LogicToPixel( aRegion );
178 }
179 pDev->SetRelativeMapMode( aMapMode );
180
181 GDIMetaFile * pMtf = pDev->GetConnectMetaFile();
182 if( pMtf )
183 {
184 if( pMtf->IsRecord() && pDev->GetOutDevType() != OUTDEV_PRINTER )
185 pMtf->Stop();
186 else
187 pMtf = nullptr;
188 }
189 if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
190 {
191 aRegion = pDev->PixelToLogic( aRegion );
192 pDev->SetClipRegion( aRegion );
193 }
194 if( pMtf )
195 pMtf->Record( pDev );
196
197 Draw( pDev, rSetup, nAspect, bOutputForScreen );
198
199 // Restore Device settings
200 pDev->Pop();
201
202}
203
205{
206 if ( !pImpl->mxObjectContainer )
207 pImpl->mxObjectContainer.reset(new comphelper::EmbeddedObjectContainer( const_cast<SfxObjectShell*>(this)->GetStorage(), GetModel() ));
208 return *pImpl->mxObjectContainer;
209}
210
212{
213 // frees all space taken by embedded objects
214 pImpl->mxObjectContainer.reset();
215}
216
217/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxApplication * SfxGetpApp()
Definition: app.hxx:232
bool IsRecord() const
void Record(OutputDevice *pOutDev)
static OUString GetEventName(GlobalEventId nID)
void SetOrigin(const Point &rOrigin)
void SetScaleY(const Fraction &rScaleY)
void SetScaleX(const Fraction &rScaleX)
GDIMetaFile * GetConnectMetaFile() const
vcl::Region GetClipRegion() const
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
bool IsClipRegion() const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
void SetClipRegion()
void SetRelativeMapMode(const MapMode &rNewMapMode)
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
const MapMode & GetMapMode() const
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
OutDevType GetOutDevType() const
void NotifyEvent(const SfxEventHint &rEvent, bool bSynchron=true)
Definition: appcfg.cxx:722
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
Definition: objembed.cxx:204
void FillTransferableObjectDescriptor(TransferableObjectDescriptor &rDesc) const
Definition: objembed.cxx:114
virtual void OnDocumentPrinterChanged(Printer *pNewPrinter)
Definition: objembed.cxx:52
virtual OutputDevice * GetDocumentRefDev()
Definition: objembed.cxx:43
MapUnit GetMapUnit() const
Definition: objembed.cxx:102
bool IsEnableSetModified() const
Definition: objmisc.cxx:248
virtual void SetVisArea(const tools::Rectangle &rVisArea)
Definition: objembed.cxx:80
virtual void Draw(OutputDevice *, const JobSetup &rSetup, sal_uInt16 nAspect, bool bOutputForScreen)=0
void SetVisAreaSize(const Size &rVisSize)
Definition: objembed.cxx:96
static SfxObjectShell * GetParentShell(const css::uno::Reference< css::uno::XInterface > &xChild)
Definition: objxtor.cxx:1048
void SetMapUnit(MapUnit nMUnit)
Definition: objembed.cxx:108
css::uno::Reference< css::frame::XModel3 > GetModel() const
Definition: objxtor.cxx:830
void DoDraw(OutputDevice *, const Point &rObjPos, const Size &rSize, const JobSetup &rSetup, sal_uInt16 nAspect=ASPECT_CONTENT, bool bOutputForScreen=false)
Definition: objembed.cxx:125
std::unique_ptr< struct SfxObjectShell_Impl > pImpl
Definition: objsh.hxx:183
SAL_DLLPRIVATE void DoDraw_Impl(OutputDevice *pDev, const Point &rViewPos, const Fraction &rScaleX, const Fraction &rScaleY, const JobSetup &rSetup, sal_uInt16 nAspect, bool bOutputForScreen)
Definition: objembed.cxx:148
css::uno::Reference< css::embed::XStorage > const & GetStorage()
Definition: objstor.cxx:3261
const tools::Rectangle & GetVisArea() const
Definition: objembed.cxx:73
virtual Printer * GetDocumentPrinter()
Definition: objembed.cxx:34
virtual void FillClass(SvGlobalName *pClassName, SotClipboardFormatId *pFormat, OUString *pFullTypeName, sal_Int32 nVersion, bool bTemplate=false) const =0
SfxObjectCreateMode GetCreateMode() const
Definition: objsh.hxx:479
void ClearEmbeddedObjects()
Definition: objembed.cxx:211
virtual void SetModified(bool bModified=true)
Definition: objmisc.cxx:297
constexpr tools::Long Height() const
constexpr tools::Long Width() const
void SetSize(const Size &)
constexpr Point TopLeft() const
constexpr Size GetSize() const
#define SOFFICE_FILEFORMAT_CURRENT
SotClipboardFormatId
MapUnit
#define ASPECT_CONTENT
Definition: objsh.hxx:81
#define ASPECT_THUMBNAIL
Definition: objsh.hxx:82
OUTDEV_PRINTER