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#include <sfx2/sfxbasemodel.hxx>
25
27#include <tools/fract.hxx>
28#include <vcl/transfer.hxx>
29#include <vcl/outdev.hxx>
30#include <vcl/gdimtf.hxx>
31
32using namespace ::com::sun::star;
33
34
36{
38 if ( pParent )
39 return pParent->GetDocumentPrinter();
40 return nullptr;
41}
42
43
45{
47 if ( pParent )
48 return pParent->GetDocumentRefDev();
49 return nullptr;
50}
51
52
54{
55 // virtual method
56}
57
58
60{
61 if( nAspect == ASPECT_CONTENT )
62 return pImpl->m_aVisArea;
63 else if( nAspect == ASPECT_THUMBNAIL )
64 {
65 tools::Rectangle aRect;
66 aRect.SetSize( OutputDevice::LogicToLogic( Size( 5000, 5000 ),
67 MapMode(MapUnit::Map100thMM), MapMode(GetMapUnit())));
68 return aRect;
69 }
70 return tools::Rectangle();
71}
72
73
75{
76 pImpl->m_aVisArea = GetVisArea( ASPECT_CONTENT );
77 return pImpl->m_aVisArea;
78}
79
80
82{
83 if( pImpl->m_aVisArea != rVisArea )
84 {
85 pImpl->m_aVisArea = rVisArea;
87 {
89 // Base forms use EMBEDDED but they actually live in their own
90 // frame - resizing that shouldn't set it to modified.
91 && pImpl->pBaseModel
92 && pImpl->pBaseModel->getIdentifier() != "com.sun.star.sdb.FormDesign")
93 {
95 }
96
98 }
99 }
100}
101
102
103void SfxObjectShell::SetVisAreaSize( const Size & rVisSize )
104{
105 SetVisArea( tools::Rectangle( GetVisArea().TopLeft(), rVisSize ) );
106}
107
108
110{
111 return pImpl->m_nMapUnit;
112}
113
114
116{
117 pImpl->m_nMapUnit = nMapUnit;
118}
119
120
122{
123 SotClipboardFormatId nClipFormat;
124 FillClass( &rDesc.maClassName, &nClipFormat, &rDesc.maTypeName, SOFFICE_FILEFORMAT_CURRENT );
125
127 rDesc.maSize = OutputDevice::LogicToLogic(GetVisArea().GetSize(), MapMode(GetMapUnit()), MapMode(MapUnit::Map100thMM));
128 rDesc.maDragStartPos = Point();
129 rDesc.maDisplayName.clear();
130}
131
133 const Point & rObjPos,
134 const Size & rSize,
135 const JobSetup & rSetup,
136 sal_uInt16 nAspect,
137 bool bOutputForScreen )
138{
139 if (!rSize.Width() || !rSize.Height())
140 return;
141
142 MapMode aMod = pDev->GetMapMode();
143 Size aSize = GetVisArea( nAspect ).GetSize();
144 MapMode aWilliMode( GetMapUnit() );
145 aSize = pDev->LogicToLogic( aSize, &aWilliMode, &aMod );
146 if( aSize.Width() && aSize.Height() )
147 {
148 Fraction aXF( rSize.Width(), aSize.Width() );
149 Fraction aYF( rSize.Height(), aSize.Height() );
150
151 DoDraw_Impl(pDev, rObjPos, aXF, aYF, rSetup, nAspect, bOutputForScreen);
152 }
153}
154
156 const Point & rViewPos,
157 const Fraction & rScaleX,
158 const Fraction & rScaleY,
159 const JobSetup & rSetup,
160 sal_uInt16 nAspect,
161 bool bOutputForScreen )
162{
163 tools::Rectangle aVisArea = GetVisArea( nAspect );
164 // MapUnit of the target
165 MapMode aMapMode( GetMapUnit() );
166 aMapMode.SetScaleX( rScaleX );
167 aMapMode.SetScaleY( rScaleY );
168
169 // Target in Pixels
170 Point aOrg = pDev->LogicToLogic( rViewPos, nullptr, &aMapMode );
171 Point aDelta = aOrg - aVisArea.TopLeft();
172
173 // Origin moved according to the viewable area
174 // Origin set with Scale
175 aMapMode.SetOrigin( aDelta );
176
177 // Secure the Device settings
178 pDev->Push();
179
180 vcl::Region aRegion;
181 if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
182 {
183 aRegion = pDev->GetClipRegion();
184 aRegion = pDev->LogicToPixel( aRegion );
185 }
186 pDev->SetRelativeMapMode( aMapMode );
187
188 GDIMetaFile * pMtf = pDev->GetConnectMetaFile();
189 if( pMtf )
190 {
191 if( pMtf->IsRecord() && pDev->GetOutDevType() != OUTDEV_PRINTER )
192 pMtf->Stop();
193 else
194 pMtf = nullptr;
195 }
196 if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
197 {
198 aRegion = pDev->PixelToLogic( aRegion );
199 pDev->SetClipRegion( aRegion );
200 }
201 if( pMtf )
202 pMtf->Record( pDev );
203
204 Draw( pDev, rSetup, nAspect, bOutputForScreen );
205
206 // Restore Device settings
207 pDev->Pop();
208
209}
210
212{
213 if ( !pImpl->mxObjectContainer )
214 pImpl->mxObjectContainer.reset(new comphelper::EmbeddedObjectContainer( const_cast<SfxObjectShell*>(this)->GetStorage(), GetModel() ));
215 return *pImpl->mxObjectContainer;
216}
217
219{
220 // frees all space taken by embedded objects
221 pImpl->mxObjectContainer.reset();
222}
223
224/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxApplication * SfxGetpApp()
Definition: app.hxx:231
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:338
comphelper::EmbeddedObjectContainer & GetEmbeddedObjectContainer() const
Definition: objembed.cxx:211
void FillTransferableObjectDescriptor(TransferableObjectDescriptor &rDesc) const
Definition: objembed.cxx:121
virtual void OnDocumentPrinterChanged(Printer *pNewPrinter)
Definition: objembed.cxx:53
virtual OutputDevice * GetDocumentRefDev()
Definition: objembed.cxx:44
MapUnit GetMapUnit() const
Definition: objembed.cxx:109
bool IsEnableSetModified() const
Definition: objmisc.cxx:248
virtual void SetVisArea(const tools::Rectangle &rVisArea)
Definition: objembed.cxx:81
virtual void Draw(OutputDevice *, const JobSetup &rSetup, sal_uInt16 nAspect, bool bOutputForScreen)=0
void SetVisAreaSize(const Size &rVisSize)
Definition: objembed.cxx:103
static SfxObjectShell * GetParentShell(const css::uno::Reference< css::uno::XInterface > &xChild)
Definition: objxtor.cxx:1056
void SetMapUnit(MapUnit nMUnit)
Definition: objembed.cxx:115
css::uno::Reference< css::frame::XModel3 > GetModel() const
Definition: objxtor.cxx:838
void DoDraw(OutputDevice *, const Point &rObjPos, const Size &rSize, const JobSetup &rSetup, sal_uInt16 nAspect=ASPECT_CONTENT, bool bOutputForScreen=false)
Definition: objembed.cxx:132
std::unique_ptr< struct SfxObjectShell_Impl > pImpl
Definition: objsh.hxx:185
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:155
css::uno::Reference< css::embed::XStorage > const & GetStorage()
Definition: objstor.cxx:3260
const tools::Rectangle & GetVisArea() const
Definition: objembed.cxx:74
virtual Printer * GetDocumentPrinter()
Definition: objembed.cxx:35
virtual void FillClass(SvGlobalName *pClassName, SotClipboardFormatId *pFormat, OUString *pFullTypeName, sal_Int32 nVersion, bool bTemplate=false) const =0
SfxObjectCreateMode GetCreateMode() const
Definition: objsh.hxx:487
void ClearEmbeddedObjects()
Definition: objembed.cxx:218
virtual void SetModified(bool bModified=true)
Definition: objmisc.cxx:301
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:83
#define ASPECT_THUMBNAIL
Definition: objsh.hxx:84
OUTDEV_PRINTER