LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / sfx2 / source / doc / objembed.cxx
blob1253eb75e593cb56449563141e5df28802140e9c
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 <sfx2/objsh.hxx>
21 #include <sfx2/app.hxx>
22 #include <objshimp.hxx>
23 #include <sfx2/event.hxx>
25 #include <comphelper/fileformat.h>
26 #include <tools/fract.hxx>
27 #include <vcl/transfer.hxx>
28 #include <vcl/outdev.hxx>
29 #include <vcl/gdimtf.hxx>
31 using namespace ::com::sun::star;
34 Printer* SfxObjectShell::GetDocumentPrinter()
36 SfxObjectShell* pParent = GetParentShell(GetModel());
37 if ( pParent )
38 return pParent->GetDocumentPrinter();
39 return nullptr;
43 OutputDevice* SfxObjectShell::GetDocumentRefDev()
45 SfxObjectShell* pParent = GetParentShell(GetModel());
46 if ( pParent )
47 return pParent->GetDocumentRefDev();
48 return nullptr;
52 void SfxObjectShell::OnDocumentPrinterChanged( Printer* /*pNewPrinter*/ )
54 // virtual method
58 tools::Rectangle SfxObjectShell::GetVisArea( sal_uInt16 nAspect ) const
60 if( nAspect == ASPECT_CONTENT )
61 return pImpl->m_aVisArea;
62 else if( nAspect == ASPECT_THUMBNAIL )
64 tools::Rectangle aRect;
65 aRect.SetSize( OutputDevice::LogicToLogic( Size( 5000, 5000 ),
66 MapMode(MapUnit::Map100thMM), MapMode(GetMapUnit())));
67 return aRect;
69 return tools::Rectangle();
73 const tools::Rectangle& SfxObjectShell::GetVisArea() const
75 pImpl->m_aVisArea = GetVisArea( ASPECT_CONTENT );
76 return pImpl->m_aVisArea;
80 void SfxObjectShell::SetVisArea( const tools::Rectangle & rVisArea )
82 if( pImpl->m_aVisArea != rVisArea )
84 pImpl->m_aVisArea = rVisArea;
85 if ( GetCreateMode() == SfxObjectCreateMode::EMBEDDED )
87 if ( IsEnableSetModified() )
88 SetModified();
90 SfxGetpApp()->NotifyEvent(SfxEventHint( SfxEventHintId::VisAreaChanged, GlobalEventConfig::GetEventName(GlobalEventId::VISAREACHANGED), this));
96 void SfxObjectShell::SetVisAreaSize( const Size & rVisSize )
98 SetVisArea( tools::Rectangle( GetVisArea().TopLeft(), rVisSize ) );
102 MapUnit SfxObjectShell::GetMapUnit() const
104 return pImpl->m_nMapUnit;
108 void SfxObjectShell::SetMapUnit( MapUnit nMapUnit )
110 pImpl->m_nMapUnit = nMapUnit;
114 void SfxObjectShell::FillTransferableObjectDescriptor( TransferableObjectDescriptor& rDesc ) const
116 SotClipboardFormatId nClipFormat;
117 FillClass( &rDesc.maClassName, &nClipFormat, &rDesc.maTypeName, SOFFICE_FILEFORMAT_CURRENT );
119 rDesc.mnViewAspect = ASPECT_CONTENT;
120 rDesc.maSize = OutputDevice::LogicToLogic(GetVisArea().GetSize(), MapMode(GetMapUnit()), MapMode(MapUnit::Map100thMM));
121 rDesc.maDragStartPos = Point();
122 rDesc.maDisplayName.clear();
126 void SfxObjectShell::DoDraw( OutputDevice* pDev,
127 const Point & rObjPos,
128 const Size & rSize,
129 const JobSetup & rSetup,
130 sal_uInt16 nAspect )
132 MapMode aMod = pDev->GetMapMode();
133 Size aSize = GetVisArea( nAspect ).GetSize();
134 MapMode aWilliMode( GetMapUnit() );
135 aSize = pDev->LogicToLogic( aSize, &aWilliMode, &aMod );
136 if( aSize.Width() && aSize.Height() )
138 Fraction aXF( rSize.Width(), aSize.Width() );
139 Fraction aYF( rSize.Height(), aSize.Height() );
141 DoDraw_Impl( pDev, rObjPos, aXF, aYF, rSetup, nAspect );
146 void SfxObjectShell::DoDraw_Impl( OutputDevice* pDev,
147 const Point & rViewPos,
148 const Fraction & rScaleX,
149 const Fraction & rScaleY,
150 const JobSetup & rSetup,
151 sal_uInt16 nAspect )
153 tools::Rectangle aVisArea = GetVisArea( nAspect );
154 // MapUnit of the target
155 MapMode aMapMode( GetMapUnit() );
156 aMapMode.SetScaleX( rScaleX );
157 aMapMode.SetScaleY( rScaleY );
159 // Target in Pixels
160 Point aOrg = pDev->LogicToLogic( rViewPos, nullptr, &aMapMode );
161 Point aDelta = aOrg - aVisArea.TopLeft();
163 // Origin moved according to the viewable area
164 // Origin set with Scale
165 aMapMode.SetOrigin( aDelta );
167 // Secure the Device settings
168 pDev->Push();
170 vcl::Region aRegion;
171 if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
173 aRegion = pDev->GetClipRegion();
174 aRegion = pDev->LogicToPixel( aRegion );
176 pDev->SetRelativeMapMode( aMapMode );
178 GDIMetaFile * pMtf = pDev->GetConnectMetaFile();
179 if( pMtf )
181 if( pMtf->IsRecord() && pDev->GetOutDevType() != OUTDEV_PRINTER )
182 pMtf->Stop();
183 else
184 pMtf = nullptr;
186 if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
188 aRegion = pDev->PixelToLogic( aRegion );
189 pDev->SetClipRegion( aRegion );
191 if( pMtf )
192 pMtf->Record( pDev );
194 Draw( pDev, rSetup, nAspect );
196 // Restore Device settings
197 pDev->Pop();
201 comphelper::EmbeddedObjectContainer& SfxObjectShell::GetEmbeddedObjectContainer() const
203 if ( !pImpl->mxObjectContainer )
204 pImpl->mxObjectContainer.reset(new comphelper::EmbeddedObjectContainer( const_cast<SfxObjectShell*>(this)->GetStorage(), GetModel() ));
205 return *pImpl->mxObjectContainer;
208 void SfxObjectShell::ClearEmbeddedObjects()
210 // frees all space taken by embedded objects
211 pImpl->mxObjectContainer.reset();
214 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */