1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/lang/XUnoTunnel.hpp>
23 #include <sfx2/objsh.hxx>
24 #include <sfx2/app.hxx>
25 #include <objshimp.hxx>
26 #include <sfx2/event.hxx>
28 #include <comphelper/fileformat.h>
29 #include <tools/fract.hxx>
30 #include <vcl/transfer.hxx>
31 #include <vcl/outdev.hxx>
32 #include <vcl/gdimtf.hxx>
34 using namespace ::com::sun::star
;
37 Printer
* SfxObjectShell::GetDocumentPrinter()
39 SfxObjectShell
* pParent
= GetParentShell(GetModel());
41 return pParent
->GetDocumentPrinter();
46 OutputDevice
* SfxObjectShell::GetDocumentRefDev()
48 SfxObjectShell
* pParent
= GetParentShell(GetModel());
50 return pParent
->GetDocumentRefDev();
55 void SfxObjectShell::OnDocumentPrinterChanged( Printer
* /*pNewPrinter*/ )
61 tools::Rectangle
SfxObjectShell::GetVisArea( sal_uInt16 nAspect
) const
63 if( nAspect
== ASPECT_CONTENT
)
64 return pImpl
->m_aVisArea
;
65 else if( nAspect
== ASPECT_THUMBNAIL
)
67 tools::Rectangle aRect
;
68 aRect
.SetSize( OutputDevice::LogicToLogic( Size( 5000, 5000 ),
69 MapMode(MapUnit::Map100thMM
), MapMode(GetMapUnit())));
72 return tools::Rectangle();
76 const tools::Rectangle
& SfxObjectShell::GetVisArea() const
78 pImpl
->m_aVisArea
= GetVisArea( ASPECT_CONTENT
);
79 return pImpl
->m_aVisArea
;
83 void SfxObjectShell::SetVisArea( const tools::Rectangle
& rVisArea
)
85 if( pImpl
->m_aVisArea
!= rVisArea
)
87 pImpl
->m_aVisArea
= rVisArea
;
88 if ( GetCreateMode() == SfxObjectCreateMode::EMBEDDED
)
90 if ( IsEnableSetModified() )
93 SfxGetpApp()->NotifyEvent(SfxEventHint( SfxEventHintId::VisAreaChanged
, GlobalEventConfig::GetEventName(GlobalEventId::VISAREACHANGED
), this));
99 void SfxObjectShell::SetVisAreaSize( const Size
& rVisSize
)
101 SetVisArea( tools::Rectangle( GetVisArea().TopLeft(), rVisSize
) );
105 MapUnit
SfxObjectShell::GetMapUnit() const
107 return pImpl
->m_nMapUnit
;
111 void SfxObjectShell::SetMapUnit( MapUnit nMapUnit
)
113 pImpl
->m_nMapUnit
= nMapUnit
;
117 void SfxObjectShell::FillTransferableObjectDescriptor( TransferableObjectDescriptor
& rDesc
) const
119 SotClipboardFormatId nClipFormat
;
120 FillClass( &rDesc
.maClassName
, &nClipFormat
, &rDesc
.maTypeName
, SOFFICE_FILEFORMAT_CURRENT
);
122 rDesc
.mnViewAspect
= ASPECT_CONTENT
;
123 rDesc
.maSize
= OutputDevice::LogicToLogic(GetVisArea().GetSize(), MapMode(GetMapUnit()), MapMode(MapUnit::Map100thMM
));
124 rDesc
.maDragStartPos
= Point();
125 rDesc
.maDisplayName
.clear();
129 void SfxObjectShell::DoDraw( OutputDevice
* pDev
,
130 const Point
& rObjPos
,
132 const JobSetup
& rSetup
,
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() )
141 Fraction
aXF( rSize
.Width(), aSize
.Width() );
142 Fraction
aYF( rSize
.Height(), aSize
.Height() );
144 DoDraw_Impl( pDev
, rObjPos
, aXF
, aYF
, rSetup
, nAspect
);
149 void SfxObjectShell::DoDraw_Impl( OutputDevice
* pDev
,
150 const Point
& rViewPos
,
151 const Fraction
& rScaleX
,
152 const Fraction
& rScaleY
,
153 const JobSetup
& rSetup
,
156 tools::Rectangle aVisArea
= GetVisArea( nAspect
);
157 // MapUnit of the target
158 MapMode
aMapMode( GetMapUnit() );
159 aMapMode
.SetScaleX( rScaleX
);
160 aMapMode
.SetScaleY( rScaleY
);
163 Point aOrg
= pDev
->LogicToLogic( rViewPos
, nullptr, &aMapMode
);
164 Point aDelta
= aOrg
- aVisArea
.TopLeft();
166 // Origin moved according to the viewable area
167 // Origin set with Scale
168 aMapMode
.SetOrigin( aDelta
);
170 // Secure the Device settings
174 if( pDev
->IsClipRegion() && pDev
->GetOutDevType() != OUTDEV_PRINTER
)
176 aRegion
= pDev
->GetClipRegion();
177 aRegion
= pDev
->LogicToPixel( aRegion
);
179 pDev
->SetRelativeMapMode( aMapMode
);
181 GDIMetaFile
* pMtf
= pDev
->GetConnectMetaFile();
184 if( pMtf
->IsRecord() && pDev
->GetOutDevType() != OUTDEV_PRINTER
)
189 if( pDev
->IsClipRegion() && pDev
->GetOutDevType() != OUTDEV_PRINTER
)
191 aRegion
= pDev
->PixelToLogic( aRegion
);
192 pDev
->SetClipRegion( aRegion
);
195 pMtf
->Record( pDev
);
197 Draw( pDev
, rSetup
, nAspect
);
199 // Restore Device settings
204 comphelper::EmbeddedObjectContainer
& SfxObjectShell::GetEmbeddedObjectContainer() const
206 if ( !pImpl
->mxObjectContainer
)
207 pImpl
->mxObjectContainer
.reset(new comphelper::EmbeddedObjectContainer( const_cast<SfxObjectShell
*>(this)->GetStorage(), GetModel() ));
208 return *pImpl
->mxObjectContainer
;
211 void SfxObjectShell::ClearEmbeddedObjects()
213 // frees all space taken by embedded objects
214 pImpl
->mxObjectContainer
.reset();
217 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */