File: | home/maarten/src/libreoffice/core/svx/source/unodraw/UnoGraphicExporter.cxx |
Warning: | line 727, column 37 Forming reference to null pointer |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
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 <vector> | ||||||||||||||||
21 | #include <com/sun/star/io/XOutputStream.hpp> | ||||||||||||||||
22 | #include <com/sun/star/beans/XPropertySet.hpp> | ||||||||||||||||
23 | #include <com/sun/star/container/XChild.hpp> | ||||||||||||||||
24 | #include <com/sun/star/lang/XServiceInfo.hpp> | ||||||||||||||||
25 | #include <com/sun/star/lang/XComponent.hpp> | ||||||||||||||||
26 | #include <com/sun/star/drawing/XShape.hpp> | ||||||||||||||||
27 | #include <com/sun/star/drawing/XDrawPage.hpp> | ||||||||||||||||
28 | #include <com/sun/star/drawing/XGraphicExportFilter.hpp> | ||||||||||||||||
29 | #include <com/sun/star/graphic/XGraphic.hpp> | ||||||||||||||||
30 | #include <com/sun/star/graphic/XGraphicRenderer.hpp> | ||||||||||||||||
31 | #include <com/sun/star/task/XStatusIndicator.hpp> | ||||||||||||||||
32 | #include <com/sun/star/task/XInteractionHandler.hpp> | ||||||||||||||||
33 | #include <com/sun/star/task/XInteractionContinuation.hpp> | ||||||||||||||||
34 | #include <com/sun/star/uno/XComponentContext.hpp> | ||||||||||||||||
35 | |||||||||||||||||
36 | #include <tools/debug.hxx> | ||||||||||||||||
37 | #include <tools/diagnose_ex.h> | ||||||||||||||||
38 | #include <tools/urlobj.hxx> | ||||||||||||||||
39 | #include <comphelper/interaction.hxx> | ||||||||||||||||
40 | #include <framework/interaction.hxx> | ||||||||||||||||
41 | #include <com/sun/star/drawing/GraphicFilterRequest.hpp> | ||||||||||||||||
42 | #include <com/sun/star/util/URL.hpp> | ||||||||||||||||
43 | #include <cppuhelper/implbase.hxx> | ||||||||||||||||
44 | #include <cppuhelper/supportsservice.hxx> | ||||||||||||||||
45 | #include <vcl/metaact.hxx> | ||||||||||||||||
46 | #include <vcl/svapp.hxx> | ||||||||||||||||
47 | #include <vcl/virdev.hxx> | ||||||||||||||||
48 | #include <svl/outstrm.hxx> | ||||||||||||||||
49 | #include <sdr/contact/objectcontactofobjlistpainter.hxx> | ||||||||||||||||
50 | #include <svx/sdr/contact/viewobjectcontact.hxx> | ||||||||||||||||
51 | #include <svx/sdr/contact/viewcontact.hxx> | ||||||||||||||||
52 | #include <svx/sdr/contact/displayinfo.hxx> | ||||||||||||||||
53 | #include <editeng/numitem.hxx> | ||||||||||||||||
54 | #include <svx/svdograf.hxx> | ||||||||||||||||
55 | #include <svx/xoutbmp.hxx> | ||||||||||||||||
56 | #include <vcl/graphicfilter.hxx> | ||||||||||||||||
57 | #include <svx/unoapi.hxx> | ||||||||||||||||
58 | #include <svx/svdpage.hxx> | ||||||||||||||||
59 | #include <svx/svdmodel.hxx> | ||||||||||||||||
60 | #include <svx/fmview.hxx> | ||||||||||||||||
61 | #include <svx/fmmodel.hxx> | ||||||||||||||||
62 | #include <svx/unopage.hxx> | ||||||||||||||||
63 | #include <svx/svdoutl.hxx> | ||||||||||||||||
64 | #include <svx/xlineit0.hxx> | ||||||||||||||||
65 | #include <editeng/flditem.hxx> | ||||||||||||||||
66 | #include "UnoGraphicExporter.hxx" | ||||||||||||||||
67 | #include <memory> | ||||||||||||||||
68 | |||||||||||||||||
69 | #define MAX_EXT_PIX2048 2048 | ||||||||||||||||
70 | |||||||||||||||||
71 | using namespace ::comphelper; | ||||||||||||||||
72 | using namespace ::cppu; | ||||||||||||||||
73 | using namespace ::com::sun::star; | ||||||||||||||||
74 | using namespace ::com::sun::star::uno; | ||||||||||||||||
75 | using namespace ::com::sun::star::util; | ||||||||||||||||
76 | using namespace ::com::sun::star::container; | ||||||||||||||||
77 | using namespace ::com::sun::star::drawing; | ||||||||||||||||
78 | using namespace ::com::sun::star::lang; | ||||||||||||||||
79 | using namespace ::com::sun::star::document; | ||||||||||||||||
80 | using namespace ::com::sun::star::beans; | ||||||||||||||||
81 | using namespace ::com::sun::star::task; | ||||||||||||||||
82 | |||||||||||||||||
83 | // #i102251# | ||||||||||||||||
84 | #include <editeng/editstat.hxx> | ||||||||||||||||
85 | |||||||||||||||||
86 | namespace { | ||||||||||||||||
87 | |||||||||||||||||
88 | struct ExportSettings | ||||||||||||||||
89 | { | ||||||||||||||||
90 | OUString maFilterName; | ||||||||||||||||
91 | OUString maMediaType; | ||||||||||||||||
92 | URL maURL; | ||||||||||||||||
93 | css::uno::Reference< css::io::XOutputStream > mxOutputStream; | ||||||||||||||||
94 | css::uno::Reference< css::graphic::XGraphicRenderer > mxGraphicRenderer; | ||||||||||||||||
95 | css::uno::Reference< css::task::XStatusIndicator > mxStatusIndicator; | ||||||||||||||||
96 | css::uno::Reference< css::task::XInteractionHandler > mxInteractionHandler; | ||||||||||||||||
97 | |||||||||||||||||
98 | sal_Int32 mnWidth; | ||||||||||||||||
99 | sal_Int32 mnHeight; | ||||||||||||||||
100 | bool mbExportOnlyBackground; | ||||||||||||||||
101 | bool mbScrollText; | ||||||||||||||||
102 | bool mbUseHighContrast; | ||||||||||||||||
103 | bool mbTranslucent; | ||||||||||||||||
104 | |||||||||||||||||
105 | Sequence< PropertyValue > maFilterData; | ||||||||||||||||
106 | |||||||||||||||||
107 | Fraction maScaleX; | ||||||||||||||||
108 | Fraction maScaleY; | ||||||||||||||||
109 | |||||||||||||||||
110 | TriState meAntiAliasing = TRISTATE_INDET; | ||||||||||||||||
111 | |||||||||||||||||
112 | explicit ExportSettings(const SdrModel* pSdrModel); | ||||||||||||||||
113 | }; | ||||||||||||||||
114 | |||||||||||||||||
115 | ExportSettings::ExportSettings(const SdrModel* pSdrModel) | ||||||||||||||||
116 | : mnWidth( 0 ) | ||||||||||||||||
117 | ,mnHeight( 0 ) | ||||||||||||||||
118 | ,mbExportOnlyBackground( false ) | ||||||||||||||||
119 | ,mbScrollText( false ) | ||||||||||||||||
120 | ,mbUseHighContrast( false ) | ||||||||||||||||
121 | ,mbTranslucent( false ) | ||||||||||||||||
122 | ,maScaleX( 1, 1 ) | ||||||||||||||||
123 | ,maScaleY( 1, 1 ) | ||||||||||||||||
124 | { | ||||||||||||||||
125 | if (pSdrModel) | ||||||||||||||||
126 | { | ||||||||||||||||
127 | maScaleX = pSdrModel->GetScaleFraction(); | ||||||||||||||||
128 | maScaleY = pSdrModel->GetScaleFraction(); | ||||||||||||||||
129 | } | ||||||||||||||||
130 | } | ||||||||||||||||
131 | |||||||||||||||||
132 | /** implements a component to export shapes or pages to external graphic formats. | ||||||||||||||||
133 | |||||||||||||||||
134 | @implements com.sun.star.drawing.GraphicExportFilter | ||||||||||||||||
135 | */ | ||||||||||||||||
136 | class GraphicExporter : public WeakImplHelper< XGraphicExportFilter, XServiceInfo > | ||||||||||||||||
137 | { | ||||||||||||||||
138 | public: | ||||||||||||||||
139 | GraphicExporter(); | ||||||||||||||||
140 | |||||||||||||||||
141 | // XFilter | ||||||||||||||||
142 | virtual sal_Bool SAL_CALL filter( const Sequence< PropertyValue >& aDescriptor ) override; | ||||||||||||||||
143 | virtual void SAL_CALL cancel( ) override; | ||||||||||||||||
144 | |||||||||||||||||
145 | // XExporter | ||||||||||||||||
146 | virtual void SAL_CALL setSourceDocument( const Reference< XComponent >& xDoc ) override; | ||||||||||||||||
147 | |||||||||||||||||
148 | // XServiceInfo | ||||||||||||||||
149 | virtual OUString SAL_CALL getImplementationName( ) override; | ||||||||||||||||
150 | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; | ||||||||||||||||
151 | virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; | ||||||||||||||||
152 | |||||||||||||||||
153 | // XMimeTypeInfo | ||||||||||||||||
154 | virtual sal_Bool SAL_CALL supportsMimeType( const OUString& MimeTypeName ) override; | ||||||||||||||||
155 | virtual Sequence< OUString > SAL_CALL getSupportedMimeTypeNames( ) override; | ||||||||||||||||
156 | |||||||||||||||||
157 | VclPtr<VirtualDevice> CreatePageVDev( SdrPage* pPage, long nWidthPixel, long nHeightPixel ) const; | ||||||||||||||||
158 | |||||||||||||||||
159 | DECL_LINK( CalcFieldValueHdl, EditFieldInfo*, void )static void LinkStubCalcFieldValueHdl(void *, EditFieldInfo*) ; void CalcFieldValueHdl(EditFieldInfo*); | ||||||||||||||||
160 | |||||||||||||||||
161 | void ParseSettings( const Sequence< PropertyValue >& aDescriptor, ExportSettings& rSettings ); | ||||||||||||||||
162 | bool GetGraphic( ExportSettings const & rSettings, Graphic& aGraphic, bool bVectorType ); | ||||||||||||||||
163 | |||||||||||||||||
164 | private: | ||||||||||||||||
165 | Reference< XShape > mxShape; | ||||||||||||||||
166 | Reference< XDrawPage > mxPage; | ||||||||||||||||
167 | Reference< XShapes > mxShapes; | ||||||||||||||||
168 | Graphic maGraphic; | ||||||||||||||||
169 | |||||||||||||||||
170 | SvxDrawPage* mpUnoPage; | ||||||||||||||||
171 | |||||||||||||||||
172 | Link<EditFieldInfo*,void> maOldCalcFieldValueHdl; | ||||||||||||||||
173 | sal_Int32 mnPageNumber; | ||||||||||||||||
174 | SdrPage* mpCurrentPage; | ||||||||||||||||
175 | SdrModel* mpDoc; | ||||||||||||||||
176 | }; | ||||||||||||||||
177 | |||||||||||||||||
178 | /** creates a bitmap that is optionally transparent from a metafile | ||||||||||||||||
179 | */ | ||||||||||||||||
180 | BitmapEx GetBitmapFromMetaFile( const GDIMetaFile& rMtf,bool bIsSelection, const Size* pSize ) | ||||||||||||||||
181 | { | ||||||||||||||||
182 | // use new primitive conversion tooling | ||||||||||||||||
183 | basegfx::B2DRange aRange(basegfx::B2DPoint(0.0, 0.0)); | ||||||||||||||||
184 | sal_uInt32 nMaximumQuadraticPixels(500000); | ||||||||||||||||
185 | |||||||||||||||||
186 | if(pSize) | ||||||||||||||||
187 | { | ||||||||||||||||
188 | // use 100th mm for primitive bitmap converter tool, input is pixel | ||||||||||||||||
189 | // use a real OutDev to get the correct DPI, the static LogicToLogic assumes 72dpi which is wrong (!) | ||||||||||||||||
190 | const Size aSize100th(Application::GetDefaultDevice()->PixelToLogic(*pSize, MapMode(MapUnit::Map100thMM))); | ||||||||||||||||
191 | |||||||||||||||||
192 | aRange.expand(basegfx::B2DPoint(aSize100th.Width(), aSize100th.Height())); | ||||||||||||||||
193 | |||||||||||||||||
194 | // when explicitly pixels are requested from the GraphicExporter, use a *very* high limit | ||||||||||||||||
195 | // of 16gb (4096x4096 pixels), else use the default for the converters | ||||||||||||||||
196 | nMaximumQuadraticPixels = std::min(sal_uInt32(4096 * 4096), sal_uInt32(pSize->Width() * pSize->Height())); | ||||||||||||||||
197 | } | ||||||||||||||||
198 | else | ||||||||||||||||
199 | { | ||||||||||||||||
200 | // use 100th mm for primitive bitmap converter tool | ||||||||||||||||
201 | const Size aSize100th(OutputDevice::LogicToLogic(rMtf.GetPrefSize(), rMtf.GetPrefMapMode(), MapMode(MapUnit::Map100thMM))); | ||||||||||||||||
202 | |||||||||||||||||
203 | aRange.expand(basegfx::B2DPoint(aSize100th.Width(), aSize100th.Height())); | ||||||||||||||||
204 | } | ||||||||||||||||
205 | |||||||||||||||||
206 | // get hairline and full bound rect to evtl. correct logic size by the | ||||||||||||||||
207 | // equivalent of one pixel to make those visible at right and bottom | ||||||||||||||||
208 | tools::Rectangle aHairlineRect; | ||||||||||||||||
209 | const tools::Rectangle aRect(rMtf.GetBoundRect(*Application::GetDefaultDevice(), &aHairlineRect)); | ||||||||||||||||
210 | |||||||||||||||||
211 | if(!aRect.IsEmpty()) | ||||||||||||||||
212 | { | ||||||||||||||||
213 | GDIMetaFile aMtf(rMtf); | ||||||||||||||||
214 | |||||||||||||||||
215 | if (bIsSelection) | ||||||||||||||||
216 | { | ||||||||||||||||
217 | // tdf#105998 Correct the Metafile using information from it's real sizes measured | ||||||||||||||||
218 | // using rMtf.GetBoundRect above and a copy | ||||||||||||||||
219 | const Size aOnePixelInMtf( | ||||||||||||||||
220 | Application::GetDefaultDevice()->PixelToLogic( | ||||||||||||||||
221 | Size(1, 1), | ||||||||||||||||
222 | rMtf.GetPrefMapMode())); | ||||||||||||||||
223 | const Size aHalfPixelInMtf( | ||||||||||||||||
224 | (aOnePixelInMtf.getWidth() + 1) / 2, | ||||||||||||||||
225 | (aOnePixelInMtf.getHeight() + 1) / 2); | ||||||||||||||||
226 | const bool bHairlineBR( | ||||||||||||||||
227 | !aHairlineRect.IsEmpty() && (aRect.Right() == aHairlineRect.Right() || aRect.Bottom() == aHairlineRect.Bottom())); | ||||||||||||||||
228 | |||||||||||||||||
229 | // Move the content to (0,0), usually TopLeft ist slightly | ||||||||||||||||
230 | // negative. For better visualization, add a half pixel, too | ||||||||||||||||
231 | aMtf.Move( | ||||||||||||||||
232 | aHalfPixelInMtf.getWidth() - aRect.Left(), | ||||||||||||||||
233 | aHalfPixelInMtf.getHeight() - aRect.Top()); | ||||||||||||||||
234 | |||||||||||||||||
235 | // Do not Scale, but set the PrefSize. Some levels deeper the | ||||||||||||||||
236 | // MetafilePrimitive will add a mapping to the decomposition | ||||||||||||||||
237 | // (and possibly a clipping) to map the graphic content to | ||||||||||||||||
238 | // a unit coordinate system. | ||||||||||||||||
239 | // Size is the measured size plus one pixel if needed (bHairlineBR) | ||||||||||||||||
240 | // and the moved half pixwel from above | ||||||||||||||||
241 | aMtf.SetPrefSize( | ||||||||||||||||
242 | Size( | ||||||||||||||||
243 | aRect.getWidth() + (bHairlineBR ? aOnePixelInMtf.getWidth() : 0) + aHalfPixelInMtf.getWidth(), | ||||||||||||||||
244 | aRect.getHeight() + (bHairlineBR ? aOnePixelInMtf.getHeight() : 0) + aHalfPixelInMtf.getHeight())); | ||||||||||||||||
245 | } | ||||||||||||||||
246 | |||||||||||||||||
247 | return convertMetafileToBitmapEx(aMtf, aRange, nMaximumQuadraticPixels); | ||||||||||||||||
248 | } | ||||||||||||||||
249 | |||||||||||||||||
250 | return BitmapEx(); | ||||||||||||||||
251 | } | ||||||||||||||||
252 | |||||||||||||||||
253 | Size* CalcSize( sal_Int32 nWidth, sal_Int32 nHeight, const Size& aBoundSize, Size& aOutSize ) | ||||||||||||||||
254 | { | ||||||||||||||||
255 | if( (nWidth == 0) && (nHeight == 0) ) | ||||||||||||||||
256 | return nullptr; | ||||||||||||||||
257 | |||||||||||||||||
258 | if( (nWidth == 0) && (nHeight != 0) && (aBoundSize.Height() != 0) ) | ||||||||||||||||
259 | { | ||||||||||||||||
260 | nWidth = ( nHeight * aBoundSize.Width() ) / aBoundSize.Height(); | ||||||||||||||||
261 | } | ||||||||||||||||
262 | else if( (nWidth != 0) && (nHeight == 0) && (aBoundSize.Width() != 0) ) | ||||||||||||||||
263 | { | ||||||||||||||||
264 | nHeight = ( nWidth * aBoundSize.Height() ) / aBoundSize.Width(); | ||||||||||||||||
265 | } | ||||||||||||||||
266 | |||||||||||||||||
267 | aOutSize.setWidth( nWidth ); | ||||||||||||||||
268 | aOutSize.setHeight( nHeight ); | ||||||||||||||||
269 | |||||||||||||||||
270 | return &aOutSize; | ||||||||||||||||
271 | } | ||||||||||||||||
272 | |||||||||||||||||
273 | class ImplExportCheckVisisbilityRedirector : public sdr::contact::ViewObjectContactRedirector | ||||||||||||||||
274 | { | ||||||||||||||||
275 | public: | ||||||||||||||||
276 | explicit ImplExportCheckVisisbilityRedirector( SdrPage* pCurrentPage ); | ||||||||||||||||
277 | |||||||||||||||||
278 | virtual drawinglayer::primitive2d::Primitive2DContainer createRedirectedPrimitive2DSequence( | ||||||||||||||||
279 | const sdr::contact::ViewObjectContact& rOriginal, | ||||||||||||||||
280 | const sdr::contact::DisplayInfo& rDisplayInfo) override; | ||||||||||||||||
281 | |||||||||||||||||
282 | private: | ||||||||||||||||
283 | SdrPage* mpCurrentPage; | ||||||||||||||||
284 | }; | ||||||||||||||||
285 | |||||||||||||||||
286 | ImplExportCheckVisisbilityRedirector::ImplExportCheckVisisbilityRedirector( SdrPage* pCurrentPage ) | ||||||||||||||||
287 | : ViewObjectContactRedirector(), mpCurrentPage( pCurrentPage ) | ||||||||||||||||
288 | { | ||||||||||||||||
289 | } | ||||||||||||||||
290 | |||||||||||||||||
291 | drawinglayer::primitive2d::Primitive2DContainer ImplExportCheckVisisbilityRedirector::createRedirectedPrimitive2DSequence( | ||||||||||||||||
292 | const sdr::contact::ViewObjectContact& rOriginal, | ||||||||||||||||
293 | const sdr::contact::DisplayInfo& rDisplayInfo) | ||||||||||||||||
294 | { | ||||||||||||||||
295 | SdrObject* pObject = rOriginal.GetViewContact().TryToGetSdrObject(); | ||||||||||||||||
296 | |||||||||||||||||
297 | if(pObject) | ||||||||||||||||
298 | { | ||||||||||||||||
299 | SdrPage* pPage = mpCurrentPage; | ||||||||||||||||
300 | |||||||||||||||||
301 | if(nullptr == pPage) | ||||||||||||||||
302 | { | ||||||||||||||||
303 | pPage = pObject->getSdrPageFromSdrObject(); | ||||||||||||||||
304 | } | ||||||||||||||||
305 | |||||||||||||||||
306 | if( (pPage == nullptr) || pPage->checkVisibility(rOriginal, rDisplayInfo, false) ) | ||||||||||||||||
307 | { | ||||||||||||||||
308 | return sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo); | ||||||||||||||||
309 | } | ||||||||||||||||
310 | |||||||||||||||||
311 | return drawinglayer::primitive2d::Primitive2DContainer(); | ||||||||||||||||
312 | } | ||||||||||||||||
313 | else | ||||||||||||||||
314 | { | ||||||||||||||||
315 | // not an object, maybe a page | ||||||||||||||||
316 | return sdr::contact::ViewObjectContactRedirector::createRedirectedPrimitive2DSequence(rOriginal, rDisplayInfo); | ||||||||||||||||
317 | } | ||||||||||||||||
318 | } | ||||||||||||||||
319 | |||||||||||||||||
320 | GraphicExporter::GraphicExporter() | ||||||||||||||||
321 | : mpUnoPage( nullptr ), mnPageNumber(-1), mpCurrentPage(nullptr), mpDoc( nullptr ) | ||||||||||||||||
322 | { | ||||||||||||||||
323 | } | ||||||||||||||||
324 | |||||||||||||||||
325 | IMPL_LINK(GraphicExporter, CalcFieldValueHdl, EditFieldInfo*, pInfo, void)void GraphicExporter::LinkStubCalcFieldValueHdl(void * instance , EditFieldInfo* data) { return static_cast<GraphicExporter *>(instance)->CalcFieldValueHdl(data); } void GraphicExporter ::CalcFieldValueHdl(EditFieldInfo* pInfo) | ||||||||||||||||
326 | { | ||||||||||||||||
327 | if( pInfo ) | ||||||||||||||||
328 | { | ||||||||||||||||
329 | if( mpCurrentPage ) | ||||||||||||||||
330 | { | ||||||||||||||||
331 | pInfo->SetSdrPage( mpCurrentPage ); | ||||||||||||||||
332 | } | ||||||||||||||||
333 | else if( mnPageNumber != -1 ) | ||||||||||||||||
334 | { | ||||||||||||||||
335 | const SvxFieldData* pField = pInfo->GetField().GetField(); | ||||||||||||||||
336 | if( dynamic_cast<const SvxPageField*>( pField) ) | ||||||||||||||||
337 | { | ||||||||||||||||
338 | OUString aPageNumValue; | ||||||||||||||||
339 | bool bUpper = false; | ||||||||||||||||
340 | |||||||||||||||||
341 | switch(mpDoc->GetPageNumType()) | ||||||||||||||||
342 | { | ||||||||||||||||
343 | case css::style::NumberingType::CHARS_UPPER_LETTER: | ||||||||||||||||
344 | aPageNumValue += OUStringChar( sal_Unicode((mnPageNumber - 1) % 26 + 'A') ); | ||||||||||||||||
345 | break; | ||||||||||||||||
346 | case css::style::NumberingType::CHARS_LOWER_LETTER: | ||||||||||||||||
347 | aPageNumValue += OUStringChar( sal_Unicode((mnPageNumber - 1) % 26 + 'a') ); | ||||||||||||||||
348 | break; | ||||||||||||||||
349 | case css::style::NumberingType::ROMAN_UPPER: | ||||||||||||||||
350 | bUpper = true; | ||||||||||||||||
351 | [[fallthrough]]; | ||||||||||||||||
352 | case css::style::NumberingType::ROMAN_LOWER: | ||||||||||||||||
353 | aPageNumValue += SvxNumberFormat::CreateRomanString(mnPageNumber, bUpper); | ||||||||||||||||
354 | break; | ||||||||||||||||
355 | case css::style::NumberingType::NUMBER_NONE: | ||||||||||||||||
356 | aPageNumValue = " "; | ||||||||||||||||
357 | break; | ||||||||||||||||
358 | default: | ||||||||||||||||
359 | aPageNumValue += OUString::number( mnPageNumber ); | ||||||||||||||||
360 | } | ||||||||||||||||
361 | |||||||||||||||||
362 | pInfo->SetRepresentation( aPageNumValue ); | ||||||||||||||||
363 | |||||||||||||||||
364 | return; | ||||||||||||||||
365 | } | ||||||||||||||||
366 | } | ||||||||||||||||
367 | } | ||||||||||||||||
368 | |||||||||||||||||
369 | maOldCalcFieldValueHdl.Call( pInfo ); | ||||||||||||||||
370 | |||||||||||||||||
371 | if( pInfo && mpCurrentPage ) | ||||||||||||||||
372 | pInfo->SetSdrPage( nullptr ); | ||||||||||||||||
373 | } | ||||||||||||||||
374 | |||||||||||||||||
375 | /** creates a virtual device for the given page | ||||||||||||||||
376 | |||||||||||||||||
377 | @return the returned VirtualDevice is owned by the caller | ||||||||||||||||
378 | */ | ||||||||||||||||
379 | VclPtr<VirtualDevice> GraphicExporter::CreatePageVDev( SdrPage* pPage, long nWidthPixel, long nHeightPixel ) const | ||||||||||||||||
380 | { | ||||||||||||||||
381 | VclPtr<VirtualDevice> pVDev = VclPtr<VirtualDevice>::Create(); | ||||||||||||||||
382 | MapMode aMM( MapUnit::Map100thMM ); | ||||||||||||||||
383 | |||||||||||||||||
384 | Point aPoint( 0, 0 ); | ||||||||||||||||
385 | Size aPageSize(pPage->GetSize()); | ||||||||||||||||
386 | |||||||||||||||||
387 | // use scaling? | ||||||||||||||||
388 | if( nWidthPixel != 0 ) | ||||||||||||||||
389 | { | ||||||||||||||||
390 | const Fraction aFrac( nWidthPixel, pVDev->LogicToPixel( aPageSize, aMM ).Width() ); | ||||||||||||||||
391 | |||||||||||||||||
392 | aMM.SetScaleX( aFrac ); | ||||||||||||||||
393 | |||||||||||||||||
394 | if( nHeightPixel == 0 ) | ||||||||||||||||
395 | aMM.SetScaleY( aFrac ); | ||||||||||||||||
396 | } | ||||||||||||||||
397 | |||||||||||||||||
398 | if( nHeightPixel != 0 ) | ||||||||||||||||
399 | { | ||||||||||||||||
400 | const Fraction aFrac( nHeightPixel, pVDev->LogicToPixel( aPageSize, aMM ).Height() ); | ||||||||||||||||
401 | |||||||||||||||||
402 | if( nWidthPixel == 0 ) | ||||||||||||||||
403 | aMM.SetScaleX( aFrac ); | ||||||||||||||||
404 | |||||||||||||||||
405 | aMM.SetScaleY( aFrac ); | ||||||||||||||||
406 | } | ||||||||||||||||
407 | |||||||||||||||||
408 | pVDev->SetMapMode( aMM ); | ||||||||||||||||
409 | bool bSuccess(false); | ||||||||||||||||
410 | |||||||||||||||||
411 | // #i122820# If available, use pixel size directly | ||||||||||||||||
412 | if(nWidthPixel && nHeightPixel) | ||||||||||||||||
413 | { | ||||||||||||||||
414 | bSuccess = pVDev->SetOutputSizePixel(Size(nWidthPixel, nHeightPixel)); | ||||||||||||||||
415 | } | ||||||||||||||||
416 | else | ||||||||||||||||
417 | { | ||||||||||||||||
418 | bSuccess = pVDev->SetOutputSize(aPageSize); | ||||||||||||||||
419 | } | ||||||||||||||||
420 | |||||||||||||||||
421 | if(bSuccess) | ||||||||||||||||
422 | { | ||||||||||||||||
423 | std::unique_ptr<SdrView> pView(new SdrView(*mpDoc, pVDev)); | ||||||||||||||||
424 | |||||||||||||||||
425 | pView->SetPageVisible( false ); | ||||||||||||||||
426 | pView->SetBordVisible( false ); | ||||||||||||||||
427 | pView->SetGridVisible( false ); | ||||||||||||||||
428 | pView->SetHlplVisible( false ); | ||||||||||||||||
429 | pView->SetGlueVisible( false ); | ||||||||||||||||
430 | pView->ShowSdrPage(pPage); | ||||||||||||||||
431 | |||||||||||||||||
432 | vcl::Region aRegion (tools::Rectangle( aPoint, aPageSize ) ); | ||||||||||||||||
433 | |||||||||||||||||
434 | ImplExportCheckVisisbilityRedirector aRedirector( mpCurrentPage ); | ||||||||||||||||
435 | |||||||||||||||||
436 | pView->CompleteRedraw(pVDev, aRegion, &aRedirector); | ||||||||||||||||
437 | } | ||||||||||||||||
438 | else | ||||||||||||||||
439 | { | ||||||||||||||||
440 | OSL_ENSURE(false, "Could not get a VirtualDevice of requested size (!)")do { if (true && (!(false))) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/svx/source/unodraw/UnoGraphicExporter.cxx" ":" "440" ": "), "%s", "Could not get a VirtualDevice of requested size (!)" ); } } while (false); | ||||||||||||||||
441 | } | ||||||||||||||||
442 | |||||||||||||||||
443 | return pVDev; | ||||||||||||||||
444 | } | ||||||||||||||||
445 | |||||||||||||||||
446 | void GraphicExporter::ParseSettings( const Sequence< PropertyValue >& aDescriptor, ExportSettings& rSettings ) | ||||||||||||||||
447 | { | ||||||||||||||||
448 | for( const PropertyValue& rValue : aDescriptor ) | ||||||||||||||||
449 | { | ||||||||||||||||
450 | if ( rValue.Name == "FilterName" ) | ||||||||||||||||
451 | { | ||||||||||||||||
452 | rValue.Value >>= rSettings.maFilterName; | ||||||||||||||||
453 | } | ||||||||||||||||
454 | else if ( rValue.Name == "MediaType" ) | ||||||||||||||||
455 | { | ||||||||||||||||
456 | rValue.Value >>= rSettings.maMediaType; | ||||||||||||||||
457 | } | ||||||||||||||||
458 | else if ( rValue.Name == "URL" ) | ||||||||||||||||
459 | { | ||||||||||||||||
460 | if( !( rValue.Value >>= rSettings.maURL ) ) | ||||||||||||||||
461 | { | ||||||||||||||||
462 | rValue.Value >>= rSettings.maURL.Complete; | ||||||||||||||||
463 | } | ||||||||||||||||
464 | } | ||||||||||||||||
465 | else if ( rValue.Name == "OutputStream" ) | ||||||||||||||||
466 | { | ||||||||||||||||
467 | rValue.Value >>= rSettings.mxOutputStream; | ||||||||||||||||
468 | } | ||||||||||||||||
469 | else if ( rValue.Name == "GraphicRenderer" ) | ||||||||||||||||
470 | { | ||||||||||||||||
471 | rValue.Value >>= rSettings.mxGraphicRenderer; | ||||||||||||||||
472 | } | ||||||||||||||||
473 | else if ( rValue.Name == "StatusIndicator" ) | ||||||||||||||||
474 | { | ||||||||||||||||
475 | rValue.Value >>= rSettings.mxStatusIndicator; | ||||||||||||||||
476 | } | ||||||||||||||||
477 | else if ( rValue.Name == "InteractionHandler" ) | ||||||||||||||||
478 | { | ||||||||||||||||
479 | rValue.Value >>= rSettings.mxInteractionHandler; | ||||||||||||||||
480 | } | ||||||||||||||||
481 | else if( rValue.Name == "Width" ) // for compatibility reasons, deprecated | ||||||||||||||||
482 | { | ||||||||||||||||
483 | rValue.Value >>= rSettings.mnWidth; | ||||||||||||||||
484 | } | ||||||||||||||||
485 | else if( rValue.Name == "Height" ) // for compatibility reasons, deprecated | ||||||||||||||||
486 | { | ||||||||||||||||
487 | rValue.Value >>= rSettings.mnHeight; | ||||||||||||||||
488 | } | ||||||||||||||||
489 | else if( rValue.Name == "ExportOnlyBackground" ) // for compatibility reasons, deprecated | ||||||||||||||||
490 | { | ||||||||||||||||
491 | rValue.Value >>= rSettings.mbExportOnlyBackground; | ||||||||||||||||
492 | } | ||||||||||||||||
493 | else if ( rValue.Name == "FilterData" ) | ||||||||||||||||
494 | { | ||||||||||||||||
495 | rValue.Value >>= rSettings.maFilterData; | ||||||||||||||||
496 | |||||||||||||||||
497 | for( PropertyValue& rDataValue : rSettings.maFilterData ) | ||||||||||||||||
498 | { | ||||||||||||||||
499 | if ( rDataValue.Name == "Translucent" ) | ||||||||||||||||
500 | { | ||||||||||||||||
501 | if ( !( rDataValue.Value >>= rSettings.mbTranslucent ) ) // SJ: TODO: The GIF Transparency is stored as int32 in | ||||||||||||||||
502 | { // configuration files, this has to be changed to boolean | ||||||||||||||||
503 | sal_Int32 nTranslucent = 0; | ||||||||||||||||
504 | if ( rDataValue.Value >>= nTranslucent ) | ||||||||||||||||
505 | rSettings.mbTranslucent = nTranslucent != 0; | ||||||||||||||||
506 | } | ||||||||||||||||
507 | } | ||||||||||||||||
508 | else if ( rDataValue.Name == "PixelWidth" ) | ||||||||||||||||
509 | { | ||||||||||||||||
510 | rDataValue.Value >>= rSettings.mnWidth; | ||||||||||||||||
511 | } | ||||||||||||||||
512 | else if ( rDataValue.Name == "PixelHeight" ) | ||||||||||||||||
513 | { | ||||||||||||||||
514 | rDataValue.Value >>= rSettings.mnHeight; | ||||||||||||||||
515 | } | ||||||||||||||||
516 | else if( rDataValue.Name == "Width" ) // for compatibility reasons, deprecated | ||||||||||||||||
517 | { | ||||||||||||||||
518 | rDataValue.Value >>= rSettings.mnWidth; | ||||||||||||||||
519 | rDataValue.Name = "PixelWidth"; | ||||||||||||||||
520 | } | ||||||||||||||||
521 | else if( rDataValue.Name == "Height" ) // for compatibility reasons, deprecated | ||||||||||||||||
522 | { | ||||||||||||||||
523 | rDataValue.Value >>= rSettings.mnHeight; | ||||||||||||||||
524 | rDataValue.Name = "PixelHeight"; | ||||||||||||||||
525 | } | ||||||||||||||||
526 | else if ( rDataValue.Name == "ExportOnlyBackground" ) | ||||||||||||||||
527 | { | ||||||||||||||||
528 | rDataValue.Value >>= rSettings.mbExportOnlyBackground; | ||||||||||||||||
529 | } | ||||||||||||||||
530 | else if ( rDataValue.Name == "HighContrast" ) | ||||||||||||||||
531 | { | ||||||||||||||||
532 | rDataValue.Value >>= rSettings.mbUseHighContrast; | ||||||||||||||||
533 | } | ||||||||||||||||
534 | else if ( rDataValue.Name == "PageNumber" ) | ||||||||||||||||
535 | { | ||||||||||||||||
536 | rDataValue.Value >>= mnPageNumber; | ||||||||||||||||
537 | } | ||||||||||||||||
538 | else if ( rDataValue.Name == "ScrollText" ) | ||||||||||||||||
539 | { | ||||||||||||||||
540 | // #110496# Read flag solitary scroll text metafile | ||||||||||||||||
541 | rDataValue.Value >>= rSettings.mbScrollText; | ||||||||||||||||
542 | } | ||||||||||||||||
543 | else if ( rDataValue.Name == "CurrentPage" ) | ||||||||||||||||
544 | { | ||||||||||||||||
545 | Reference< XDrawPage > xPage; | ||||||||||||||||
546 | rDataValue.Value >>= xPage; | ||||||||||||||||
547 | if( xPage.is() ) | ||||||||||||||||
548 | { | ||||||||||||||||
549 | SvxDrawPage* pUnoPage = comphelper::getUnoTunnelImplementation<SvxDrawPage>( xPage ); | ||||||||||||||||
550 | if( pUnoPage && pUnoPage->GetSdrPage() ) | ||||||||||||||||
551 | mpCurrentPage = pUnoPage->GetSdrPage(); | ||||||||||||||||
552 | } | ||||||||||||||||
553 | } | ||||||||||||||||
554 | else if ( rDataValue.Name == "ScaleXNumerator" ) | ||||||||||||||||
555 | { | ||||||||||||||||
556 | sal_Int32 nVal = 1; | ||||||||||||||||
557 | if( rDataValue.Value >>= nVal ) | ||||||||||||||||
558 | rSettings.maScaleX = Fraction( nVal, rSettings.maScaleX.GetDenominator() ); | ||||||||||||||||
559 | } | ||||||||||||||||
560 | else if ( rDataValue.Name == "ScaleXDenominator" ) | ||||||||||||||||
561 | { | ||||||||||||||||
562 | sal_Int32 nVal = 1; | ||||||||||||||||
563 | if( rDataValue.Value >>= nVal ) | ||||||||||||||||
564 | rSettings.maScaleX = Fraction( rSettings.maScaleX.GetNumerator(), nVal ); | ||||||||||||||||
565 | } | ||||||||||||||||
566 | else if ( rDataValue.Name == "ScaleYNumerator" ) | ||||||||||||||||
567 | { | ||||||||||||||||
568 | sal_Int32 nVal = 1; | ||||||||||||||||
569 | if( rDataValue.Value >>= nVal ) | ||||||||||||||||
570 | rSettings.maScaleY = Fraction( nVal, rSettings.maScaleY.GetDenominator() ); | ||||||||||||||||
571 | } | ||||||||||||||||
572 | else if ( rDataValue.Name == "ScaleYDenominator" ) | ||||||||||||||||
573 | { | ||||||||||||||||
574 | sal_Int32 nVal = 1; | ||||||||||||||||
575 | if( rDataValue.Value >>= nVal ) | ||||||||||||||||
576 | rSettings.maScaleY = Fraction( rSettings.maScaleY.GetNumerator(), nVal ); | ||||||||||||||||
577 | } | ||||||||||||||||
578 | else if (rDataValue.Name == "AntiAliasing") | ||||||||||||||||
579 | { | ||||||||||||||||
580 | bool bAntiAliasing; | ||||||||||||||||
581 | if (rDataValue.Value >>= bAntiAliasing) | ||||||||||||||||
582 | rSettings.meAntiAliasing = bAntiAliasing ? TRISTATE_TRUE : TRISTATE_FALSE; | ||||||||||||||||
583 | } | ||||||||||||||||
584 | } | ||||||||||||||||
585 | } | ||||||||||||||||
586 | } | ||||||||||||||||
587 | |||||||||||||||||
588 | // putting the StatusIndicator that we got from the MediaDescriptor into our local FilterData copy | ||||||||||||||||
589 | if ( rSettings.mxStatusIndicator.is() ) | ||||||||||||||||
590 | { | ||||||||||||||||
591 | int i = rSettings.maFilterData.getLength(); | ||||||||||||||||
592 | rSettings.maFilterData.realloc( i + 1 ); | ||||||||||||||||
593 | rSettings.maFilterData[ i ].Name = "StatusIndicator"; | ||||||||||||||||
594 | rSettings.maFilterData[ i ].Value <<= rSettings.mxStatusIndicator; | ||||||||||||||||
595 | } | ||||||||||||||||
596 | } | ||||||||||||||||
597 | |||||||||||||||||
598 | bool GraphicExporter::GetGraphic( ExportSettings const & rSettings, Graphic& aGraphic, bool bVectorType ) | ||||||||||||||||
599 | { | ||||||||||||||||
600 | if( !mpDoc
| ||||||||||||||||
601 | return false; | ||||||||||||||||
602 | |||||||||||||||||
603 | SdrPage* pPage = mpUnoPage->GetSdrPage(); | ||||||||||||||||
604 | if( !pPage
| ||||||||||||||||
605 | return false; | ||||||||||||||||
606 | |||||||||||||||||
607 | ScopedVclPtrInstance< VirtualDevice > aVDev; | ||||||||||||||||
608 | const MapMode aMap( mpDoc->GetScaleUnit(), Point(), rSettings.maScaleX, rSettings.maScaleY ); | ||||||||||||||||
609 | |||||||||||||||||
610 | SdrOutliner& rOutl=mpDoc->GetDrawOutliner(); | ||||||||||||||||
611 | maOldCalcFieldValueHdl = rOutl.GetCalcFieldValueHdl(); | ||||||||||||||||
612 | rOutl.SetCalcFieldValueHdl( LINK(this, GraphicExporter, CalcFieldValueHdl)::tools::detail::makeLink( ::tools::detail::castTo<GraphicExporter *>(this), &GraphicExporter::LinkStubCalcFieldValueHdl ) ); | ||||||||||||||||
613 | rOutl.SetBackgroundColor( pPage->GetPageBackgroundColor() ); | ||||||||||||||||
614 | |||||||||||||||||
615 | // #i102251# | ||||||||||||||||
616 | const EEControlBits nOldCntrl(rOutl.GetControlWord()); | ||||||||||||||||
617 | EEControlBits nCntrl = nOldCntrl & ~EEControlBits::ONLINESPELLING; | ||||||||||||||||
618 | rOutl.SetControlWord(nCntrl); | ||||||||||||||||
619 | |||||||||||||||||
620 | SdrObject* pTempBackgroundShape = nullptr; | ||||||||||||||||
621 | std::vector< SdrObject* > aShapes; | ||||||||||||||||
622 | bool bRet = true; | ||||||||||||||||
623 | |||||||||||||||||
624 | // export complete page? | ||||||||||||||||
625 | if ( !mxShape.is() ) | ||||||||||||||||
626 | { | ||||||||||||||||
627 | if( rSettings.mbExportOnlyBackground ) | ||||||||||||||||
628 | { | ||||||||||||||||
629 | const SdrPageProperties* pCorrectProperties = pPage->getCorrectSdrPageProperties(); | ||||||||||||||||
630 | |||||||||||||||||
631 | if(pCorrectProperties) | ||||||||||||||||
632 | { | ||||||||||||||||
633 | pTempBackgroundShape = new SdrRectObj( | ||||||||||||||||
634 | *mpDoc, | ||||||||||||||||
635 | tools::Rectangle(Point(0,0), pPage->GetSize())); | ||||||||||||||||
636 | pTempBackgroundShape->SetMergedItemSet(pCorrectProperties->GetItemSet()); | ||||||||||||||||
637 | pTempBackgroundShape->SetMergedItem(XLineStyleItem(drawing::LineStyle_NONE)); | ||||||||||||||||
638 | pTempBackgroundShape->NbcSetStyleSheet(pCorrectProperties->GetStyleSheet(), true); | ||||||||||||||||
639 | aShapes.push_back(pTempBackgroundShape); | ||||||||||||||||
640 | } | ||||||||||||||||
641 | } | ||||||||||||||||
642 | else | ||||||||||||||||
643 | { | ||||||||||||||||
644 | const Size aSize( pPage->GetSize() ); | ||||||||||||||||
645 | |||||||||||||||||
646 | // generate a bitmap to convert it to a pixel format. | ||||||||||||||||
647 | // For gif pictures there can also be a vector format used (bTranslucent) | ||||||||||||||||
648 | if ( !bVectorType
| ||||||||||||||||
649 | { | ||||||||||||||||
650 | long nWidthPix = 0; | ||||||||||||||||
651 | long nHeightPix = 0; | ||||||||||||||||
652 | if ( rSettings.mnWidth > 0 && rSettings.mnHeight > 0 ) | ||||||||||||||||
653 | { | ||||||||||||||||
654 | nWidthPix = rSettings.mnWidth; | ||||||||||||||||
655 | nHeightPix = rSettings.mnHeight; | ||||||||||||||||
656 | } | ||||||||||||||||
657 | else | ||||||||||||||||
658 | { | ||||||||||||||||
659 | const Size aSizePix( Application::GetDefaultDevice()->LogicToPixel( aSize, aMap ) ); | ||||||||||||||||
660 | if (aSizePix.Width() > MAX_EXT_PIX2048 || aSizePix.Height() > MAX_EXT_PIX2048) | ||||||||||||||||
661 | { | ||||||||||||||||
662 | if (aSizePix.Width() > MAX_EXT_PIX2048) | ||||||||||||||||
663 | nWidthPix = MAX_EXT_PIX2048; | ||||||||||||||||
664 | else | ||||||||||||||||
665 | nWidthPix = aSizePix.Width(); | ||||||||||||||||
666 | if (aSizePix.Height() > MAX_EXT_PIX2048) | ||||||||||||||||
667 | nHeightPix = MAX_EXT_PIX2048; | ||||||||||||||||
668 | else | ||||||||||||||||
669 | nHeightPix = aSizePix.Height(); | ||||||||||||||||
670 | |||||||||||||||||
671 | double fWidthDif = static_cast<double>(aSizePix.Width()) / nWidthPix; | ||||||||||||||||
672 | double fHeightDif = static_cast<double>(aSizePix.Height()) / nHeightPix; | ||||||||||||||||
673 | |||||||||||||||||
674 | if (fWidthDif > fHeightDif) | ||||||||||||||||
675 | nHeightPix = static_cast<long>(aSizePix.Height() / fWidthDif); | ||||||||||||||||
676 | else | ||||||||||||||||
677 | nWidthPix = static_cast<long>(aSizePix.Width() / fHeightDif); | ||||||||||||||||
678 | } | ||||||||||||||||
679 | else | ||||||||||||||||
680 | { | ||||||||||||||||
681 | nWidthPix = aSizePix.Width(); | ||||||||||||||||
682 | nHeightPix = aSizePix.Height(); | ||||||||||||||||
683 | } | ||||||||||||||||
684 | } | ||||||||||||||||
685 | |||||||||||||||||
686 | std::unique_ptr<SdrView> xLocalView; | ||||||||||||||||
687 | |||||||||||||||||
688 | if (FmFormModel* pFormModel = dynamic_cast<FmFormModel*>(mpDoc)) | ||||||||||||||||
689 | { | ||||||||||||||||
690 | xLocalView.reset(new FmFormView(*pFormModel, aVDev)); | ||||||||||||||||
691 | } | ||||||||||||||||
692 | else | ||||||||||||||||
693 | { | ||||||||||||||||
694 | xLocalView.reset(new SdrView(*mpDoc, aVDev)); | ||||||||||||||||
695 | } | ||||||||||||||||
696 | |||||||||||||||||
697 | ScopedVclPtr<VirtualDevice> pVDev(CreatePageVDev( pPage, nWidthPix, nHeightPix )); | ||||||||||||||||
698 | |||||||||||||||||
699 | if( pVDev ) | ||||||||||||||||
700 | { | ||||||||||||||||
701 | aGraphic = pVDev->GetBitmapEx( Point(), pVDev->GetOutputSize() ); | ||||||||||||||||
702 | aGraphic.SetPrefMapMode( aMap ); | ||||||||||||||||
703 | aGraphic.SetPrefSize( aSize ); | ||||||||||||||||
704 | } | ||||||||||||||||
705 | } | ||||||||||||||||
706 | // create a metafile to export a vector format | ||||||||||||||||
707 | else | ||||||||||||||||
708 | { | ||||||||||||||||
709 | GDIMetaFile aMtf; | ||||||||||||||||
710 | |||||||||||||||||
711 | aVDev->SetMapMode( aMap ); | ||||||||||||||||
712 | if( rSettings.mbUseHighContrast ) | ||||||||||||||||
713 | aVDev->SetDrawMode( aVDev->GetDrawMode() | DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient ); | ||||||||||||||||
714 | aVDev->EnableOutput( false ); | ||||||||||||||||
715 | aMtf.Record( aVDev ); | ||||||||||||||||
716 | Size aNewSize; | ||||||||||||||||
717 | |||||||||||||||||
718 | // create a view | ||||||||||||||||
719 | std::unique_ptr< SdrView > pView; | ||||||||||||||||
720 | |||||||||||||||||
721 | if (FmFormModel *pFormModel = dynamic_cast<FmFormModel*>(mpDoc)) | ||||||||||||||||
722 | { | ||||||||||||||||
723 | pView.reset(new FmFormView(*pFormModel, aVDev)); | ||||||||||||||||
724 | } | ||||||||||||||||
725 | else | ||||||||||||||||
726 | { | ||||||||||||||||
727 | pView.reset(new SdrView(*mpDoc, aVDev)); | ||||||||||||||||
| |||||||||||||||||
728 | } | ||||||||||||||||
729 | |||||||||||||||||
730 | pView->SetBordVisible( false ); | ||||||||||||||||
731 | pView->SetPageVisible( false ); | ||||||||||||||||
732 | pView->ShowSdrPage( pPage ); | ||||||||||||||||
733 | |||||||||||||||||
734 | // tdf#96922 completely deactivate EditView PageVisualization, including | ||||||||||||||||
735 | // PageBackground (formerly 'wiese'). | ||||||||||||||||
736 | pView->SetPagePaintingAllowed(false); | ||||||||||||||||
737 | |||||||||||||||||
738 | const Point aNewOrg( pPage->GetLeftBorder(), pPage->GetUpperBorder() ); | ||||||||||||||||
739 | aNewSize = Size( aSize.Width() - pPage->GetLeftBorder() - pPage->GetRightBorder(), | ||||||||||||||||
740 | aSize.Height() - pPage->GetUpperBorder() - pPage->GetLowerBorder() ); | ||||||||||||||||
741 | const tools::Rectangle aClipRect( aNewOrg, aNewSize ); | ||||||||||||||||
742 | MapMode aVMap( aMap ); | ||||||||||||||||
743 | |||||||||||||||||
744 | aVDev->Push(); | ||||||||||||||||
745 | aVMap.SetOrigin( Point( -aNewOrg.X(), -aNewOrg.Y() ) ); | ||||||||||||||||
746 | aVDev->SetRelativeMapMode( aVMap ); | ||||||||||||||||
747 | aVDev->IntersectClipRegion( aClipRect ); | ||||||||||||||||
748 | |||||||||||||||||
749 | // Use new StandardCheckVisisbilityRedirector | ||||||||||||||||
750 | ImplExportCheckVisisbilityRedirector aRedirector( mpCurrentPage ); | ||||||||||||||||
751 | |||||||||||||||||
752 | pView->CompleteRedraw(aVDev, vcl::Region(tools::Rectangle(aNewOrg, aNewSize)), &aRedirector); | ||||||||||||||||
753 | |||||||||||||||||
754 | aVDev->Pop(); | ||||||||||||||||
755 | |||||||||||||||||
756 | aMtf.Stop(); | ||||||||||||||||
757 | aMtf.WindStart(); | ||||||||||||||||
758 | aMtf.SetPrefMapMode( aMap ); | ||||||||||||||||
759 | aMtf.SetPrefSize( aNewSize ); | ||||||||||||||||
760 | |||||||||||||||||
761 | // AW: Here the current version was filtering out the MetaActionType::CLIPREGIONs | ||||||||||||||||
762 | // from the metafile. I asked some other developers why this was done, but no | ||||||||||||||||
763 | // one knew a direct reason. Since it's in for long time, it may be an old | ||||||||||||||||
764 | // piece of code. MetaFiles save and load ClipRegions with polygons with preserving | ||||||||||||||||
765 | // the polygons, so a resolution-independent roundtrip is supported. Removed this | ||||||||||||||||
766 | // code since it destroys some MetaFiles where ClipRegions are used. Anyways, | ||||||||||||||||
767 | // just filtering them out is a hack, at least the encapsulated content would need | ||||||||||||||||
768 | // to be clipped geometrically. | ||||||||||||||||
769 | aGraphic = Graphic(aMtf); | ||||||||||||||||
770 | |||||||||||||||||
771 | pView->HideSdrPage(); | ||||||||||||||||
772 | |||||||||||||||||
773 | if( rSettings.mbTranslucent ) | ||||||||||||||||
774 | { | ||||||||||||||||
775 | Size aOutSize; | ||||||||||||||||
776 | aGraphic = GetBitmapFromMetaFile( aGraphic.GetGDIMetaFile(), false, CalcSize( rSettings.mnWidth, rSettings.mnHeight, aNewSize, aOutSize ) ); | ||||||||||||||||
777 | } | ||||||||||||||||
778 | } | ||||||||||||||||
779 | } | ||||||||||||||||
780 | } | ||||||||||||||||
781 | |||||||||||||||||
782 | // export only single shape or shape collection | ||||||||||||||||
783 | else | ||||||||||||||||
784 | { | ||||||||||||||||
785 | // build list of SdrObject | ||||||||||||||||
786 | if( mxShapes.is() ) | ||||||||||||||||
787 | { | ||||||||||||||||
788 | Reference< XShape > xShape; | ||||||||||||||||
789 | const sal_Int32 nCount = mxShapes->getCount(); | ||||||||||||||||
790 | |||||||||||||||||
791 | for( sal_Int32 nIndex = 0; nIndex < nCount; nIndex++ ) | ||||||||||||||||
792 | { | ||||||||||||||||
793 | mxShapes->getByIndex( nIndex ) >>= xShape; | ||||||||||||||||
794 | SdrObject* pObj = GetSdrObjectFromXShape( xShape ); | ||||||||||||||||
795 | if( pObj ) | ||||||||||||||||
796 | aShapes.push_back( pObj ); | ||||||||||||||||
797 | } | ||||||||||||||||
798 | } | ||||||||||||||||
799 | else | ||||||||||||||||
800 | { | ||||||||||||||||
801 | // only one shape | ||||||||||||||||
802 | SdrObject* pObj = GetSdrObjectFromXShape( mxShape ); | ||||||||||||||||
803 | if( pObj ) | ||||||||||||||||
804 | aShapes.push_back( pObj ); | ||||||||||||||||
805 | } | ||||||||||||||||
806 | |||||||||||||||||
807 | if( aShapes.empty() ) | ||||||||||||||||
808 | bRet = false; | ||||||||||||||||
809 | } | ||||||||||||||||
810 | |||||||||||||||||
811 | if( bRet && !aShapes.empty() ) | ||||||||||||||||
812 | { | ||||||||||||||||
813 | // special treatment for only one SdrGrafObj that has text | ||||||||||||||||
814 | bool bSingleGraphic = false; | ||||||||||||||||
815 | |||||||||||||||||
816 | if( 1 == aShapes.size() ) | ||||||||||||||||
817 | { | ||||||||||||||||
818 | if( !bVectorType ) | ||||||||||||||||
819 | { | ||||||||||||||||
820 | SdrObject* pObj = aShapes.front(); | ||||||||||||||||
821 | if( dynamic_cast<const SdrGrafObj*>( pObj) && !static_cast<SdrGrafObj*>(pObj)->HasText() ) | ||||||||||||||||
822 | { | ||||||||||||||||
823 | aGraphic = static_cast<SdrGrafObj*>(pObj)->GetTransformedGraphic(); | ||||||||||||||||
824 | if ( aGraphic.GetType() == GraphicType::Bitmap ) | ||||||||||||||||
825 | { | ||||||||||||||||
826 | Size aSizePixel( aGraphic.GetSizePixel() ); | ||||||||||||||||
827 | if( rSettings.mnWidth && rSettings.mnHeight && | ||||||||||||||||
828 | ( ( rSettings.mnWidth != aSizePixel.Width() ) || | ||||||||||||||||
829 | ( rSettings.mnHeight != aSizePixel.Height() ) ) ) | ||||||||||||||||
830 | { | ||||||||||||||||
831 | BitmapEx aBmpEx( aGraphic.GetBitmapEx() ); | ||||||||||||||||
832 | // export: use highest quality | ||||||||||||||||
833 | aBmpEx.Scale( Size( rSettings.mnWidth, rSettings.mnHeight ), BmpScaleFlag::Lanczos ); | ||||||||||||||||
834 | aGraphic = aBmpEx; | ||||||||||||||||
835 | } | ||||||||||||||||
836 | |||||||||||||||||
837 | // #118804# only accept for bitmap graphics, else the | ||||||||||||||||
838 | // conversion to bitmap will happen anywhere without size control | ||||||||||||||||
839 | // as evtl. defined in rSettings.mnWidth/mnHeight | ||||||||||||||||
840 | bSingleGraphic = true; | ||||||||||||||||
841 | } | ||||||||||||||||
842 | } | ||||||||||||||||
843 | } | ||||||||||||||||
844 | else if( rSettings.mbScrollText ) | ||||||||||||||||
845 | { | ||||||||||||||||
846 | SdrObject* pObj = aShapes.front(); | ||||||||||||||||
847 | if( dynamic_cast<const SdrTextObj*>( pObj) | ||||||||||||||||
848 | && static_cast<SdrTextObj*>(pObj)->HasText() ) | ||||||||||||||||
849 | { | ||||||||||||||||
850 | tools::Rectangle aScrollRectangle; | ||||||||||||||||
851 | tools::Rectangle aPaintRectangle; | ||||||||||||||||
852 | |||||||||||||||||
853 | const std::unique_ptr< GDIMetaFile > pMtf( | ||||||||||||||||
854 | static_cast<SdrTextObj*>(pObj)->GetTextScrollMetaFileAndRectangle( | ||||||||||||||||
855 | aScrollRectangle, aPaintRectangle ) ); | ||||||||||||||||
856 | |||||||||||||||||
857 | // take the larger one of the two rectangles (that | ||||||||||||||||
858 | // should be the bound rect of the retrieved | ||||||||||||||||
859 | // metafile) | ||||||||||||||||
860 | tools::Rectangle aTextRect; | ||||||||||||||||
861 | |||||||||||||||||
862 | if( aScrollRectangle.IsInside( aPaintRectangle ) ) | ||||||||||||||||
863 | aTextRect = aScrollRectangle; | ||||||||||||||||
864 | else | ||||||||||||||||
865 | aTextRect = aPaintRectangle; | ||||||||||||||||
866 | |||||||||||||||||
867 | // setup pref size and mapmode | ||||||||||||||||
868 | pMtf->SetPrefSize( aTextRect.GetSize() ); | ||||||||||||||||
869 | |||||||||||||||||
870 | // set actual origin (mtf is at actual shape | ||||||||||||||||
871 | // output position) | ||||||||||||||||
872 | MapMode aLocalMapMode( aMap ); | ||||||||||||||||
873 | aLocalMapMode.SetOrigin( | ||||||||||||||||
874 | Point( -aPaintRectangle.Left(), | ||||||||||||||||
875 | -aPaintRectangle.Top() ) ); | ||||||||||||||||
876 | pMtf->SetPrefMapMode( aLocalMapMode ); | ||||||||||||||||
877 | |||||||||||||||||
878 | pMtf->AddAction( new MetaCommentAction( | ||||||||||||||||
879 | "XTEXT_SCROLLRECT", 0, | ||||||||||||||||
880 | reinterpret_cast<sal_uInt8 const*>(&aScrollRectangle), | ||||||||||||||||
881 | sizeof( tools::Rectangle ) ) ); | ||||||||||||||||
882 | pMtf->AddAction( new MetaCommentAction( | ||||||||||||||||
883 | "XTEXT_PAINTRECT", 0, | ||||||||||||||||
884 | reinterpret_cast<sal_uInt8 const*>(&aPaintRectangle), | ||||||||||||||||
885 | sizeof( tools::Rectangle ) ) ); | ||||||||||||||||
886 | |||||||||||||||||
887 | aGraphic = Graphic( *pMtf ); | ||||||||||||||||
888 | |||||||||||||||||
889 | bSingleGraphic = true; | ||||||||||||||||
890 | } | ||||||||||||||||
891 | } | ||||||||||||||||
892 | } | ||||||||||||||||
893 | |||||||||||||||||
894 | if( !bSingleGraphic ) | ||||||||||||||||
895 | { | ||||||||||||||||
896 | // create a metafile for all shapes | ||||||||||||||||
897 | ScopedVclPtrInstance< VirtualDevice > aOut; | ||||||||||||||||
898 | |||||||||||||||||
899 | // calculate bound rect for all shapes | ||||||||||||||||
900 | tools::Rectangle aBound; | ||||||||||||||||
901 | |||||||||||||||||
902 | { | ||||||||||||||||
903 | for( SdrObject* pObj : aShapes ) | ||||||||||||||||
904 | { | ||||||||||||||||
905 | tools::Rectangle aR1(pObj->GetCurrentBoundRect()); | ||||||||||||||||
906 | if (aBound.IsEmpty()) | ||||||||||||||||
907 | aBound=aR1; | ||||||||||||||||
908 | else | ||||||||||||||||
909 | aBound.Union(aR1); | ||||||||||||||||
910 | } | ||||||||||||||||
911 | } | ||||||||||||||||
912 | |||||||||||||||||
913 | aOut->EnableOutput( false ); | ||||||||||||||||
914 | aOut->SetMapMode( aMap ); | ||||||||||||||||
915 | if( rSettings.mbUseHighContrast ) | ||||||||||||||||
916 | aOut->SetDrawMode( aOut->GetDrawMode() | DrawModeFlags::SettingsLine | DrawModeFlags::SettingsFill | DrawModeFlags::SettingsText | DrawModeFlags::SettingsGradient ); | ||||||||||||||||
917 | |||||||||||||||||
918 | GDIMetaFile aMtf; | ||||||||||||||||
919 | aMtf.Clear(); | ||||||||||||||||
920 | aMtf.Record( aOut ); | ||||||||||||||||
921 | |||||||||||||||||
922 | MapMode aOutMap( aMap ); | ||||||||||||||||
923 | aOutMap.SetOrigin( Point( -aBound.TopLeft().X(), -aBound.TopLeft().Y() ) ); | ||||||||||||||||
924 | aOut->SetRelativeMapMode( aOutMap ); | ||||||||||||||||
925 | |||||||||||||||||
926 | sdr::contact::DisplayInfo aDisplayInfo; | ||||||||||||||||
927 | |||||||||||||||||
928 | if(mpCurrentPage) | ||||||||||||||||
929 | { | ||||||||||||||||
930 | if(mpCurrentPage->TRG_HasMasterPage() && pPage->IsMasterPage()) | ||||||||||||||||
931 | { | ||||||||||||||||
932 | // MasterPage is processed as another page's SubContent | ||||||||||||||||
933 | aDisplayInfo.SetProcessLayers(mpCurrentPage->TRG_GetMasterPageVisibleLayers()); | ||||||||||||||||
934 | aDisplayInfo.SetSubContentActive(true); | ||||||||||||||||
935 | } | ||||||||||||||||
936 | } | ||||||||||||||||
937 | |||||||||||||||||
938 | if(!aShapes.empty()) | ||||||||||||||||
939 | { | ||||||||||||||||
940 | // more effective way to paint a vector of SdrObjects. Hand over the processed page | ||||||||||||||||
941 | // to have it in the | ||||||||||||||||
942 | sdr::contact::ObjectContactOfObjListPainter aMultiObjectPainter(*aOut, aShapes, mpCurrentPage); | ||||||||||||||||
943 | ImplExportCheckVisisbilityRedirector aCheckVisibilityRedirector(mpCurrentPage); | ||||||||||||||||
944 | aMultiObjectPainter.SetViewObjectContactRedirector(&aCheckVisibilityRedirector); | ||||||||||||||||
945 | |||||||||||||||||
946 | aMultiObjectPainter.ProcessDisplay(aDisplayInfo); | ||||||||||||||||
947 | } | ||||||||||||||||
948 | |||||||||||||||||
949 | aMtf.Stop(); | ||||||||||||||||
950 | aMtf.WindStart(); | ||||||||||||||||
951 | |||||||||||||||||
952 | const Size aExtSize( aOut->PixelToLogic( Size( 0, 0 ) ) ); | ||||||||||||||||
953 | Size aBoundSize( aBound.GetWidth() + ( aExtSize.Width() ), | ||||||||||||||||
954 | aBound.GetHeight() + ( aExtSize.Height() ) ); | ||||||||||||||||
955 | |||||||||||||||||
956 | aMtf.SetPrefMapMode( aMap ); | ||||||||||||||||
957 | aMtf.SetPrefSize( aBoundSize ); | ||||||||||||||||
958 | |||||||||||||||||
959 | if( !bVectorType ) | ||||||||||||||||
960 | { | ||||||||||||||||
961 | Size aOutSize; | ||||||||||||||||
962 | aGraphic = GetBitmapFromMetaFile( aMtf, true, CalcSize( rSettings.mnWidth, rSettings.mnHeight, aBoundSize, aOutSize ) ); | ||||||||||||||||
963 | } | ||||||||||||||||
964 | else | ||||||||||||||||
965 | { | ||||||||||||||||
966 | aGraphic = aMtf; | ||||||||||||||||
967 | } | ||||||||||||||||
968 | } | ||||||||||||||||
969 | } | ||||||||||||||||
970 | |||||||||||||||||
971 | if(pTempBackgroundShape) | ||||||||||||||||
972 | { | ||||||||||||||||
973 | SdrObject::Free(pTempBackgroundShape); | ||||||||||||||||
974 | } | ||||||||||||||||
975 | |||||||||||||||||
976 | rOutl.SetCalcFieldValueHdl( maOldCalcFieldValueHdl ); | ||||||||||||||||
977 | |||||||||||||||||
978 | // #i102251# | ||||||||||||||||
979 | rOutl.SetControlWord(nOldCntrl); | ||||||||||||||||
980 | |||||||||||||||||
981 | return bRet; | ||||||||||||||||
982 | |||||||||||||||||
983 | } | ||||||||||||||||
984 | |||||||||||||||||
985 | // XFilter | ||||||||||||||||
986 | sal_Bool SAL_CALL GraphicExporter::filter( const Sequence< PropertyValue >& aDescriptor ) | ||||||||||||||||
987 | { | ||||||||||||||||
988 | ::SolarMutexGuard aGuard; | ||||||||||||||||
989 | |||||||||||||||||
990 | if( maGraphic.IsNone() && nullptr == mpUnoPage ) | ||||||||||||||||
991 | return false; | ||||||||||||||||
992 | |||||||||||||||||
993 | if( maGraphic.IsNone() && ( nullptr == mpUnoPage->GetSdrPage() || nullptr == mpDoc ) ) | ||||||||||||||||
994 | return false; | ||||||||||||||||
995 | |||||||||||||||||
996 | GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter(); | ||||||||||||||||
997 | |||||||||||||||||
998 | // get the arguments from the descriptor | ||||||||||||||||
999 | ExportSettings aSettings(mpDoc); | ||||||||||||||||
1000 | ParseSettings(aDescriptor, aSettings); | ||||||||||||||||
1001 | |||||||||||||||||
1002 | const sal_uInt16 nFilter = !aSettings.maMediaType.isEmpty() | ||||||||||||||||
1003 | ? rFilter.GetExportFormatNumberForMediaType( aSettings.maMediaType ) | ||||||||||||||||
1004 | : rFilter.GetExportFormatNumberForShortName( aSettings.maFilterName ); | ||||||||||||||||
1005 | bool bVectorType = !rFilter.IsExportPixelFormat( nFilter ); | ||||||||||||||||
1006 | |||||||||||||||||
1007 | // create the output stuff | ||||||||||||||||
1008 | Graphic aGraphic = maGraphic; | ||||||||||||||||
1009 | |||||||||||||||||
1010 | ErrCode nStatus = ERRCODE_NONEErrCode(0); | ||||||||||||||||
1011 | if (maGraphic.IsNone()) | ||||||||||||||||
1012 | { | ||||||||||||||||
1013 | SvtOptionsDrawinglayer aOptions; | ||||||||||||||||
1014 | bool bAntiAliasing = aOptions.IsAntiAliasing(); | ||||||||||||||||
1015 | AllSettings aAllSettings = Application::GetSettings(); | ||||||||||||||||
1016 | StyleSettings aStyleSettings = aAllSettings.GetStyleSettings(); | ||||||||||||||||
1017 | bool bUseFontAAFromSystem = aStyleSettings.GetUseFontAAFromSystem(); | ||||||||||||||||
1018 | if (aSettings.meAntiAliasing != TRISTATE_INDET) | ||||||||||||||||
1019 | { | ||||||||||||||||
1020 | // This is safe to do globally as we own the solar mutex. | ||||||||||||||||
1021 | aOptions.SetAntiAliasing(aSettings.meAntiAliasing == TRISTATE_TRUE); | ||||||||||||||||
1022 | // Opt in to have AA affect font rendering as well. | ||||||||||||||||
1023 | aStyleSettings.SetUseFontAAFromSystem(false); | ||||||||||||||||
1024 | aAllSettings.SetStyleSettings(aStyleSettings); | ||||||||||||||||
1025 | Application::SetSettings(aAllSettings); | ||||||||||||||||
1026 | } | ||||||||||||||||
1027 | nStatus = GetGraphic( aSettings, aGraphic, bVectorType ) ? ERRCODE_NONEErrCode(0) : ERRCODE_GRFILTER_FILTERERRORErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 5); | ||||||||||||||||
1028 | if (aSettings.meAntiAliasing != TRISTATE_INDET) | ||||||||||||||||
1029 | { | ||||||||||||||||
1030 | aOptions.SetAntiAliasing(bAntiAliasing); | ||||||||||||||||
1031 | aStyleSettings.SetUseFontAAFromSystem(bUseFontAAFromSystem); | ||||||||||||||||
1032 | aAllSettings.SetStyleSettings(aStyleSettings); | ||||||||||||||||
1033 | Application::SetSettings(aAllSettings); | ||||||||||||||||
1034 | } | ||||||||||||||||
1035 | } | ||||||||||||||||
1036 | |||||||||||||||||
1037 | if( nStatus == ERRCODE_NONEErrCode(0) ) | ||||||||||||||||
1038 | { | ||||||||||||||||
1039 | // export graphic only if it has a size | ||||||||||||||||
1040 | const Size aGraphSize( aGraphic.GetPrefSize() ); | ||||||||||||||||
1041 | if ( aGraphSize.IsEmpty() ) | ||||||||||||||||
1042 | { | ||||||||||||||||
1043 | nStatus = ERRCODE_GRFILTER_FILTERERRORErrCode(ErrCodeArea::Vcl, ErrCodeClass::General, 5); | ||||||||||||||||
1044 | } | ||||||||||||||||
1045 | else | ||||||||||||||||
1046 | { | ||||||||||||||||
1047 | // now we have a graphic, so export it | ||||||||||||||||
1048 | if( aSettings.mxGraphicRenderer.is() ) | ||||||||||||||||
1049 | { | ||||||||||||||||
1050 | // render graphic directly into given renderer | ||||||||||||||||
1051 | aSettings.mxGraphicRenderer->render( aGraphic.GetXGraphic() ); | ||||||||||||||||
1052 | } | ||||||||||||||||
1053 | else if( aSettings.mxOutputStream.is() ) | ||||||||||||||||
1054 | { | ||||||||||||||||
1055 | // TODO: Either utilize optional XSeekable functionality for the | ||||||||||||||||
1056 | // SvOutputStream, or adapt the graphic filter to not seek anymore. | ||||||||||||||||
1057 | SvMemoryStream aStream( 1024, 1024 ); | ||||||||||||||||
1058 | |||||||||||||||||
1059 | nStatus = rFilter.ExportGraphic( aGraphic,"", aStream, nFilter, &aSettings.maFilterData ); | ||||||||||||||||
1060 | |||||||||||||||||
1061 | // copy temp stream to XOutputStream | ||||||||||||||||
1062 | SvOutputStream aOutputStream( aSettings.mxOutputStream ); | ||||||||||||||||
1063 | aStream.Seek(0); | ||||||||||||||||
1064 | aOutputStream.WriteStream( aStream ); | ||||||||||||||||
1065 | } | ||||||||||||||||
1066 | else | ||||||||||||||||
1067 | { | ||||||||||||||||
1068 | INetURLObject aURLObject( aSettings.maURL.Complete ); | ||||||||||||||||
1069 | DBG_ASSERT( aURLObject.GetProtocol() != INetProtocol::NotValid, "invalid URL" )do { if (true && (!(aURLObject.GetProtocol() != INetProtocol ::NotValid))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN ), ("legacy.tools"), ("/home/maarten/src/libreoffice/core/svx/source/unodraw/UnoGraphicExporter.cxx" ":" "1069" ": "), "%s", "invalid URL"); } } while (false); | ||||||||||||||||
1070 | |||||||||||||||||
1071 | nStatus = XOutBitmap::ExportGraphic( aGraphic, aURLObject, rFilter, nFilter, &aSettings.maFilterData ); | ||||||||||||||||
1072 | } | ||||||||||||||||
1073 | } | ||||||||||||||||
1074 | } | ||||||||||||||||
1075 | |||||||||||||||||
1076 | if ( aSettings.mxInteractionHandler.is() && ( nStatus != ERRCODE_NONEErrCode(0) ) ) | ||||||||||||||||
1077 | { | ||||||||||||||||
1078 | Any aInteraction; | ||||||||||||||||
1079 | Sequence< css::uno::Reference< css::task::XInteractionContinuation > > lContinuations(1); | ||||||||||||||||
1080 | ::comphelper::OInteractionApprove* pApprove = new ::comphelper::OInteractionApprove(); | ||||||||||||||||
1081 | lContinuations[0].set(static_cast< XInteractionContinuation* >(pApprove), UNO_QUERY); | ||||||||||||||||
1082 | |||||||||||||||||
1083 | GraphicFilterRequest aErrorCode; | ||||||||||||||||
1084 | aErrorCode.ErrCode = sal_uInt32(nStatus); | ||||||||||||||||
1085 | aInteraction <<= aErrorCode; | ||||||||||||||||
1086 | aSettings.mxInteractionHandler->handle( framework::InteractionRequest::CreateRequest( aInteraction, lContinuations ) ); | ||||||||||||||||
1087 | } | ||||||||||||||||
1088 | return nStatus == ERRCODE_NONEErrCode(0); | ||||||||||||||||
1089 | } | ||||||||||||||||
1090 | |||||||||||||||||
1091 | void SAL_CALL GraphicExporter::cancel() | ||||||||||||||||
1092 | { | ||||||||||||||||
1093 | } | ||||||||||||||||
1094 | |||||||||||||||||
1095 | // XExporter | ||||||||||||||||
1096 | |||||||||||||||||
1097 | /** the source 'document' could be a XDrawPage, a XShape or a generic XShapes */ | ||||||||||||||||
1098 | void SAL_CALL GraphicExporter::setSourceDocument( const Reference< lang::XComponent >& xComponent ) | ||||||||||||||||
1099 | { | ||||||||||||||||
1100 | ::SolarMutexGuard aGuard; | ||||||||||||||||
1101 | |||||||||||||||||
1102 | mxShapes = nullptr; | ||||||||||||||||
1103 | mpUnoPage = nullptr; | ||||||||||||||||
1104 | |||||||||||||||||
1105 | try | ||||||||||||||||
1106 | { | ||||||||||||||||
1107 | // any break inside this one loop while will throw an IllegalArgumentException | ||||||||||||||||
1108 | do | ||||||||||||||||
1109 | { | ||||||||||||||||
1110 | mxPage.set( xComponent, UNO_QUERY ); | ||||||||||||||||
1111 | mxShapes.set( xComponent, UNO_QUERY ); | ||||||||||||||||
1112 | mxShape.set( xComponent, UNO_QUERY ); | ||||||||||||||||
1113 | |||||||||||||||||
1114 | // Step 1: try a generic XShapes | ||||||||||||||||
1115 | if( !mxPage.is() && !mxShape.is() && mxShapes.is() ) | ||||||||||||||||
1116 | { | ||||||||||||||||
1117 | // we do not support empty shape collections | ||||||||||||||||
1118 | if( 0 == mxShapes->getCount() ) | ||||||||||||||||
1119 | break; | ||||||||||||||||
1120 | |||||||||||||||||
1121 | // get first shape to detect corresponding page and model | ||||||||||||||||
1122 | mxShapes->getByIndex(0) >>= mxShape; | ||||||||||||||||
1123 | } | ||||||||||||||||
1124 | else | ||||||||||||||||
1125 | { | ||||||||||||||||
1126 | mxShapes = nullptr; | ||||||||||||||||
1127 | } | ||||||||||||||||
1128 | |||||||||||||||||
1129 | // Step 2: try a shape | ||||||||||||||||
1130 | if( mxShape.is() ) | ||||||||||||||||
1131 | { | ||||||||||||||||
1132 | if( nullptr == GetSdrObjectFromXShape( mxShape ) ) | ||||||||||||||||
1133 | { | ||||||||||||||||
1134 | // This is not a Draw shape, let's see if it's a Writer one. | ||||||||||||||||
1135 | uno::Reference<beans::XPropertySet> xPropertySet(mxShape, uno::UNO_QUERY); | ||||||||||||||||
1136 | if (!xPropertySet.is()) | ||||||||||||||||
1137 | break; | ||||||||||||||||
1138 | uno::Reference<graphic::XGraphic> xGraphic( | ||||||||||||||||
1139 | xPropertySet->getPropertyValue("Graphic"), uno::UNO_QUERY); | ||||||||||||||||
1140 | if (!xGraphic.is()) | ||||||||||||||||
1141 | break; | ||||||||||||||||
1142 | |||||||||||||||||
1143 | maGraphic = Graphic(xGraphic); | ||||||||||||||||
1144 | if (!maGraphic.IsNone()) | ||||||||||||||||
1145 | return; | ||||||||||||||||
1146 | else | ||||||||||||||||
1147 | break; | ||||||||||||||||
1148 | } | ||||||||||||||||
1149 | |||||||||||||||||
1150 | // get page for this shape | ||||||||||||||||
1151 | Reference< XChild > xChild( mxShape, UNO_QUERY ); | ||||||||||||||||
1152 | if( !xChild.is() ) | ||||||||||||||||
1153 | break; | ||||||||||||||||
1154 | |||||||||||||||||
1155 | Reference< XInterface > xInt; | ||||||||||||||||
1156 | do | ||||||||||||||||
1157 | { | ||||||||||||||||
1158 | xInt = xChild->getParent(); | ||||||||||||||||
1159 | mxPage.set( xInt, UNO_QUERY ); | ||||||||||||||||
1160 | if( !mxPage.is() ) | ||||||||||||||||
1161 | xChild.set( xInt, UNO_QUERY ); | ||||||||||||||||
1162 | } | ||||||||||||||||
1163 | while( !mxPage.is() && xChild.is() ); | ||||||||||||||||
1164 | |||||||||||||||||
1165 | if( !mxPage.is() ) | ||||||||||||||||
1166 | break; | ||||||||||||||||
1167 | } | ||||||||||||||||
1168 | |||||||||||||||||
1169 | // Step 3: check the page | ||||||||||||||||
1170 | if( !mxPage.is() ) | ||||||||||||||||
1171 | break; | ||||||||||||||||
1172 | |||||||||||||||||
1173 | mpUnoPage = comphelper::getUnoTunnelImplementation<SvxDrawPage>( mxPage ); | ||||||||||||||||
1174 | |||||||||||||||||
1175 | if( nullptr == mpUnoPage || nullptr == mpUnoPage->GetSdrPage() ) | ||||||||||||||||
1176 | break; | ||||||||||||||||
1177 | |||||||||||||||||
1178 | mpDoc = &mpUnoPage->GetSdrPage()->getSdrModelFromSdrPage(); | ||||||||||||||||
1179 | |||||||||||||||||
1180 | // Step 4: If we got a generic XShapes test all contained shapes | ||||||||||||||||
1181 | // if they belong to the same XDrawPage | ||||||||||||||||
1182 | |||||||||||||||||
1183 | if( mxShapes.is() ) | ||||||||||||||||
1184 | { | ||||||||||||||||
1185 | SdrPage* pPage = mpUnoPage->GetSdrPage(); | ||||||||||||||||
1186 | SdrObject* pObj; | ||||||||||||||||
1187 | Reference< XShape > xShape; | ||||||||||||||||
1188 | |||||||||||||||||
1189 | bool bOk = true; | ||||||||||||||||
1190 | |||||||||||||||||
1191 | const sal_Int32 nCount = mxShapes->getCount(); | ||||||||||||||||
1192 | |||||||||||||||||
1193 | // test all but the first shape if they have the same page than | ||||||||||||||||
1194 | // the first shape | ||||||||||||||||
1195 | for( sal_Int32 nIndex = 1; bOk && ( nIndex < nCount ); nIndex++ ) | ||||||||||||||||
1196 | { | ||||||||||||||||
1197 | mxShapes->getByIndex( nIndex ) >>= xShape; | ||||||||||||||||
1198 | pObj = GetSdrObjectFromXShape( xShape ); | ||||||||||||||||
1199 | bOk = pObj && pObj->getSdrPageFromSdrObject() == pPage; | ||||||||||||||||
1200 | } | ||||||||||||||||
1201 | |||||||||||||||||
1202 | if( !bOk ) | ||||||||||||||||
1203 | break; | ||||||||||||||||
1204 | } | ||||||||||||||||
1205 | |||||||||||||||||
1206 | // no errors so far | ||||||||||||||||
1207 | return; | ||||||||||||||||
1208 | } | ||||||||||||||||
1209 | while( false ); | ||||||||||||||||
1210 | } | ||||||||||||||||
1211 | catch( Exception& ) | ||||||||||||||||
1212 | { | ||||||||||||||||
1213 | } | ||||||||||||||||
1214 | |||||||||||||||||
1215 | throw IllegalArgumentException(); | ||||||||||||||||
1216 | } | ||||||||||||||||
1217 | |||||||||||||||||
1218 | // XServiceInfo | ||||||||||||||||
1219 | OUString SAL_CALL GraphicExporter::getImplementationName( ) | ||||||||||||||||
1220 | { | ||||||||||||||||
1221 | return "com.sun.star.comp.Draw.GraphicExporter"; | ||||||||||||||||
1222 | } | ||||||||||||||||
1223 | |||||||||||||||||
1224 | sal_Bool SAL_CALL GraphicExporter::supportsService( const OUString& ServiceName ) | ||||||||||||||||
1225 | { | ||||||||||||||||
1226 | return cppu::supportsService(this, ServiceName); | ||||||||||||||||
1227 | } | ||||||||||||||||
1228 | |||||||||||||||||
1229 | Sequence< OUString > SAL_CALL GraphicExporter::getSupportedServiceNames( ) | ||||||||||||||||
1230 | { | ||||||||||||||||
1231 | Sequence< OUString > aSupportedServiceNames { "com.sun.star.drawing.GraphicExportFilter" }; | ||||||||||||||||
1232 | return aSupportedServiceNames; | ||||||||||||||||
1233 | } | ||||||||||||||||
1234 | |||||||||||||||||
1235 | // XMimeTypeInfo | ||||||||||||||||
1236 | sal_Bool SAL_CALL GraphicExporter::supportsMimeType( const OUString& rMimeTypeName ) | ||||||||||||||||
1237 | { | ||||||||||||||||
1238 | GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter(); | ||||||||||||||||
1239 | sal_uInt16 nCount = rFilter.GetExportFormatCount(); | ||||||||||||||||
1240 | sal_uInt16 nFilter; | ||||||||||||||||
1241 | for( nFilter = 0; nFilter < nCount; nFilter++ ) | ||||||||||||||||
1242 | { | ||||||||||||||||
1243 | if( rMimeTypeName == rFilter.GetExportFormatMediaType( nFilter ) ) | ||||||||||||||||
1244 | { | ||||||||||||||||
1245 | return true; | ||||||||||||||||
1246 | } | ||||||||||||||||
1247 | } | ||||||||||||||||
1248 | |||||||||||||||||
1249 | return false; | ||||||||||||||||
1250 | } | ||||||||||||||||
1251 | |||||||||||||||||
1252 | Sequence< OUString > SAL_CALL GraphicExporter::getSupportedMimeTypeNames( ) | ||||||||||||||||
1253 | { | ||||||||||||||||
1254 | GraphicFilter &rFilter = GraphicFilter::GetGraphicFilter(); | ||||||||||||||||
1255 | sal_uInt16 nCount = rFilter.GetExportFormatCount(); | ||||||||||||||||
1256 | sal_uInt16 nFilter; | ||||||||||||||||
1257 | sal_uInt16 nFound = 0; | ||||||||||||||||
1258 | |||||||||||||||||
1259 | Sequence< OUString > aSeq( nCount ); | ||||||||||||||||
1260 | OUString* pStr = aSeq.getArray(); | ||||||||||||||||
1261 | |||||||||||||||||
1262 | for( nFilter = 0; nFilter < nCount; nFilter++ ) | ||||||||||||||||
1263 | { | ||||||||||||||||
1264 | OUString aMimeType( rFilter.GetExportFormatMediaType( nFilter ) ); | ||||||||||||||||
1265 | if( !aMimeType.isEmpty() ) | ||||||||||||||||
1266 | { | ||||||||||||||||
1267 | *pStr++ = aMimeType; | ||||||||||||||||
1268 | nFound++; | ||||||||||||||||
1269 | } | ||||||||||||||||
1270 | } | ||||||||||||||||
1271 | |||||||||||||||||
1272 | if( nFound < nCount ) | ||||||||||||||||
1273 | aSeq.realloc( nFound ); | ||||||||||||||||
1274 | |||||||||||||||||
1275 | return aSeq; | ||||||||||||||||
1276 | } | ||||||||||||||||
1277 | |||||||||||||||||
1278 | } | ||||||||||||||||
1279 | |||||||||||||||||
1280 | Graphic SvxGetGraphicForShape( SdrObject& rShape ) | ||||||||||||||||
1281 | { | ||||||||||||||||
1282 | Graphic aGraphic; | ||||||||||||||||
1283 | try | ||||||||||||||||
1284 | { | ||||||||||||||||
1285 | rtl::Reference< GraphicExporter > xExporter( new GraphicExporter() ); | ||||||||||||||||
| |||||||||||||||||
1286 | Reference< XComponent > xComp( rShape.getUnoShape(), UNO_QUERY_THROW ); | ||||||||||||||||
1287 | xExporter->setSourceDocument( xComp ); | ||||||||||||||||
1288 | ExportSettings aSettings(&rShape.getSdrModelFromSdrObject()); | ||||||||||||||||
1289 | xExporter->GetGraphic( aSettings, aGraphic, true/*bVector*/ ); | ||||||||||||||||
1290 | } | ||||||||||||||||
1291 | catch( Exception& ) | ||||||||||||||||
1292 | { | ||||||||||||||||
1293 | TOOLS_WARN_EXCEPTION("svx", "")do { css::uno::Any tools_warn_exception( DbgGetCaughtException () ); do { if (true) { switch (sal_detail_log_report(::SAL_DETAIL_LOG_LEVEL_WARN , "svx")) { case SAL_DETAIL_LOG_ACTION_IGNORE: break; case SAL_DETAIL_LOG_ACTION_LOG : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "" << " " << exceptionToString(tools_warn_exception )) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ( "svx"), ("/home/maarten/src/libreoffice/core/svx/source/unodraw/UnoGraphicExporter.cxx" ":" "1293" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "" << " " << exceptionToString (tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "" << " " << exceptionToString (tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("svx"), ("/home/maarten/src/libreoffice/core/svx/source/unodraw/UnoGraphicExporter.cxx" ":" "1293" ": "), sal_detail_stream, 0); }; break; case SAL_DETAIL_LOG_ACTION_FATAL : if (sizeof ::sal::detail::getResult( ::sal::detail::StreamStart () << "" << " " << exceptionToString(tools_warn_exception )) == 1) { ::sal_detail_log( (::SAL_DETAIL_LOG_LEVEL_WARN), ( "svx"), ("/home/maarten/src/libreoffice/core/svx/source/unodraw/UnoGraphicExporter.cxx" ":" "1293" ": "), ::sal::detail::unwrapStream( ::sal::detail ::StreamStart() << "" << " " << exceptionToString (tools_warn_exception)), 0); } else { ::std::ostringstream sal_detail_stream ; sal_detail_stream << "" << " " << exceptionToString (tools_warn_exception); ::sal::detail::log( (::SAL_DETAIL_LOG_LEVEL_WARN ), ("svx"), ("/home/maarten/src/libreoffice/core/svx/source/unodraw/UnoGraphicExporter.cxx" ":" "1293" ": "), sal_detail_stream, 0); }; std::abort(); break ; } } } while (false); } while (false); | ||||||||||||||||
1294 | } | ||||||||||||||||
1295 | return aGraphic; | ||||||||||||||||
1296 | } | ||||||||||||||||
1297 | |||||||||||||||||
1298 | extern "C" SAL_DLLPUBLIC_EXPORT__attribute__ ((visibility("default"))) css::uno::XInterface * | ||||||||||||||||
1299 | com_sun_star_comp_Draw_GraphicExporter_get_implementation( | ||||||||||||||||
1300 | css::uno::XComponentContext *, | ||||||||||||||||
1301 | css::uno::Sequence<css::uno::Any> const &) | ||||||||||||||||
1302 | { | ||||||||||||||||
1303 | return cppu::acquire(new GraphicExporter); | ||||||||||||||||
1304 | } | ||||||||||||||||
1305 | |||||||||||||||||
1306 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_RTL_REF_HXX | ||||||||
21 | #define INCLUDED_RTL_REF_HXX | ||||||||
22 | |||||||||
23 | #include "sal/config.h" | ||||||||
24 | |||||||||
25 | #include <cassert> | ||||||||
26 | #include <cstddef> | ||||||||
27 | #include <functional> | ||||||||
28 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
29 | #include <type_traits> | ||||||||
30 | #endif | ||||||||
31 | |||||||||
32 | #include "sal/types.h" | ||||||||
33 | |||||||||
34 | namespace rtl | ||||||||
35 | { | ||||||||
36 | |||||||||
37 | /** Template reference class for reference type. | ||||||||
38 | */ | ||||||||
39 | template <class reference_type> | ||||||||
40 | class Reference | ||||||||
41 | { | ||||||||
42 | /** The <b>reference_type</b> body pointer. | ||||||||
43 | */ | ||||||||
44 | reference_type * m_pBody; | ||||||||
45 | |||||||||
46 | |||||||||
47 | public: | ||||||||
48 | /** Constructor... | ||||||||
49 | */ | ||||||||
50 | Reference() | ||||||||
51 | : m_pBody (NULL__null) | ||||||||
52 | {} | ||||||||
53 | |||||||||
54 | |||||||||
55 | /** Constructor... | ||||||||
56 | */ | ||||||||
57 | Reference (reference_type * pBody, __sal_NoAcquire) | ||||||||
58 | : m_pBody (pBody) | ||||||||
59 | { | ||||||||
60 | } | ||||||||
61 | |||||||||
62 | /** Constructor... | ||||||||
63 | */ | ||||||||
64 | Reference (reference_type * pBody) | ||||||||
65 | : m_pBody (pBody) | ||||||||
66 | { | ||||||||
67 | if (m_pBody
| ||||||||
68 | m_pBody->acquire(); | ||||||||
69 | } | ||||||||
70 | |||||||||
71 | /** Copy constructor... | ||||||||
72 | */ | ||||||||
73 | Reference (const Reference<reference_type> & handle) | ||||||||
74 | : m_pBody (handle.m_pBody) | ||||||||
75 | { | ||||||||
76 | if (m_pBody) | ||||||||
77 | m_pBody->acquire(); | ||||||||
78 | } | ||||||||
79 | |||||||||
80 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
81 | /** Move constructor... | ||||||||
82 | */ | ||||||||
83 | Reference (Reference<reference_type> && handle) noexcept | ||||||||
84 | : m_pBody (handle.m_pBody) | ||||||||
85 | { | ||||||||
86 | handle.m_pBody = nullptr; | ||||||||
87 | } | ||||||||
88 | #endif | ||||||||
89 | |||||||||
90 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
91 | /** Up-casting conversion constructor: Copies interface reference. | ||||||||
92 | |||||||||
93 | Does not work for up-casts to ambiguous bases. | ||||||||
94 | |||||||||
95 | @param rRef another reference | ||||||||
96 | */ | ||||||||
97 | template< class derived_type > | ||||||||
98 | inline Reference( | ||||||||
99 | const Reference< derived_type > & rRef, | ||||||||
100 | std::enable_if_t<std::is_base_of_v<reference_type, derived_type>, int> = 0 ) | ||||||||
101 | : m_pBody (rRef.get()) | ||||||||
102 | { | ||||||||
103 | if (m_pBody) | ||||||||
104 | m_pBody->acquire(); | ||||||||
105 | } | ||||||||
106 | #endif | ||||||||
107 | |||||||||
108 | /** Destructor... | ||||||||
109 | */ | ||||||||
110 | ~Reference() COVERITY_NOEXCEPT_FALSE | ||||||||
111 | { | ||||||||
112 | if (m_pBody) | ||||||||
113 | m_pBody->release(); | ||||||||
114 | } | ||||||||
115 | |||||||||
116 | /** Set... | ||||||||
117 | Similar to assignment. | ||||||||
118 | */ | ||||||||
119 | Reference<reference_type> & | ||||||||
120 | SAL_CALL set (reference_type * pBody) | ||||||||
121 | { | ||||||||
122 | if (pBody) | ||||||||
123 | pBody->acquire(); | ||||||||
124 | reference_type * const pOld = m_pBody; | ||||||||
125 | m_pBody = pBody; | ||||||||
126 | if (pOld) | ||||||||
127 | pOld->release(); | ||||||||
128 | return *this; | ||||||||
129 | } | ||||||||
130 | |||||||||
131 | /** Assignment. | ||||||||
132 | Unbinds this instance from its body (if bound) and | ||||||||
133 | bind it to the body represented by the handle. | ||||||||
134 | */ | ||||||||
135 | Reference<reference_type> & | ||||||||
136 | SAL_CALL operator= (const Reference<reference_type> & handle) | ||||||||
137 | { | ||||||||
138 | return set( handle.m_pBody ); | ||||||||
139 | } | ||||||||
140 | |||||||||
141 | #ifdef LIBO_INTERNAL_ONLY1 | ||||||||
142 | /** Assignment. | ||||||||
143 | * Unbinds this instance from its body (if bound), | ||||||||
144 | * bind it to the body represented by the handle, and | ||||||||
145 | * set the body represented by the handle to nullptr. | ||||||||
146 | */ | ||||||||
147 | Reference<reference_type> & | ||||||||
148 | operator= (Reference<reference_type> && handle) | ||||||||
149 | { | ||||||||
150 | // self-movement guts ourself | ||||||||
151 | if (m_pBody) | ||||||||
152 | m_pBody->release(); | ||||||||
153 | m_pBody = handle.m_pBody; | ||||||||
154 | handle.m_pBody = nullptr; | ||||||||
155 | return *this; | ||||||||
156 | } | ||||||||
157 | #endif | ||||||||
158 | |||||||||
159 | /** Assignment... | ||||||||
160 | */ | ||||||||
161 | Reference<reference_type> & | ||||||||
162 | SAL_CALL operator= (reference_type * pBody) | ||||||||
163 | { | ||||||||
164 | return set( pBody ); | ||||||||
165 | } | ||||||||
166 | |||||||||
167 | /** Unbind the body from this handle. | ||||||||
168 | Note that for a handle representing a large body, | ||||||||
169 | "handle.clear().set(new body());" _might_ | ||||||||
170 | perform a little bit better than "handle.set(new body());", | ||||||||
171 | since in the second case two large objects exist in memory | ||||||||
172 | (the old body and the new body). | ||||||||
173 | */ | ||||||||
174 | Reference<reference_type> & SAL_CALL clear() | ||||||||
175 | { | ||||||||
176 | if (m_pBody) | ||||||||
177 | { | ||||||||
178 | reference_type * const pOld = m_pBody; | ||||||||
179 | m_pBody = NULL__null; | ||||||||
180 | pOld->release(); | ||||||||
181 | } | ||||||||
182 | return *this; | ||||||||
183 | } | ||||||||
184 | |||||||||
185 | |||||||||
186 | /** Get the body. Can be used instead of operator->(). | ||||||||
187 | I.e. handle->someBodyOp() and handle.get()->someBodyOp() | ||||||||
188 | are the same. | ||||||||
189 | */ | ||||||||
190 | reference_type * SAL_CALL get() const | ||||||||
191 | { | ||||||||
192 | return m_pBody; | ||||||||
193 | } | ||||||||
194 | |||||||||
195 | |||||||||
196 | /** Probably most common used: handle->someBodyOp(). | ||||||||
197 | */ | ||||||||
198 | reference_type * SAL_CALL operator->() const | ||||||||
199 | { | ||||||||
200 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 200, __extension__ __PRETTY_FUNCTION__)); | ||||||||
201 | return m_pBody; | ||||||||
202 | } | ||||||||
203 | |||||||||
204 | |||||||||
205 | /** Allows (*handle).someBodyOp(). | ||||||||
206 | */ | ||||||||
207 | reference_type & SAL_CALL operator*() const | ||||||||
208 | { | ||||||||
209 | assert(m_pBody != NULL)(static_cast <bool> (m_pBody != __null) ? void (0) : __assert_fail ("m_pBody != NULL", "/home/maarten/src/libreoffice/core/include/rtl/ref.hxx" , 209, __extension__ __PRETTY_FUNCTION__)); | ||||||||
210 | return *m_pBody; | ||||||||
211 | } | ||||||||
212 | |||||||||
213 | |||||||||
214 | /** Returns True if the handle does point to a valid body. | ||||||||
215 | */ | ||||||||
216 | bool SAL_CALL is() const | ||||||||
217 | { | ||||||||
218 | return (m_pBody != NULL__null); | ||||||||
219 | } | ||||||||
220 | |||||||||
221 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
222 | /** Returns True if the handle does point to a valid body. | ||||||||
223 | */ | ||||||||
224 | explicit operator bool() const | ||||||||
225 | { | ||||||||
226 | return is(); | ||||||||
227 | } | ||||||||
228 | #endif | ||||||||
229 | |||||||||
230 | /** Returns True if this points to pBody. | ||||||||
231 | */ | ||||||||
232 | bool SAL_CALL operator== (const reference_type * pBody) const | ||||||||
233 | { | ||||||||
234 | return (m_pBody == pBody); | ||||||||
235 | } | ||||||||
236 | |||||||||
237 | |||||||||
238 | /** Returns True if handle points to the same body. | ||||||||
239 | */ | ||||||||
240 | bool | ||||||||
241 | SAL_CALL operator== (const Reference<reference_type> & handle) const | ||||||||
242 | { | ||||||||
243 | return (m_pBody == handle.m_pBody); | ||||||||
244 | } | ||||||||
245 | |||||||||
246 | |||||||||
247 | /** Needed to place References into STL collection. | ||||||||
248 | */ | ||||||||
249 | bool | ||||||||
250 | SAL_CALL operator!= (const Reference<reference_type> & handle) const | ||||||||
251 | { | ||||||||
252 | return (m_pBody != handle.m_pBody); | ||||||||
253 | } | ||||||||
254 | |||||||||
255 | |||||||||
256 | /** Needed to place References into STL collection. | ||||||||
257 | */ | ||||||||
258 | bool | ||||||||
259 | SAL_CALL operator< (const Reference<reference_type> & handle) const | ||||||||
260 | { | ||||||||
261 | return (m_pBody < handle.m_pBody); | ||||||||
262 | } | ||||||||
263 | |||||||||
264 | |||||||||
265 | /** Needed to place References into STL collection. | ||||||||
266 | */ | ||||||||
267 | bool | ||||||||
268 | SAL_CALL operator> (const Reference<reference_type> & handle) const | ||||||||
269 | { | ||||||||
270 | return (m_pBody > handle.m_pBody); | ||||||||
271 | } | ||||||||
272 | }; | ||||||||
273 | |||||||||
274 | } // namespace rtl | ||||||||
275 | |||||||||
276 | #if defined LIBO_INTERNAL_ONLY1 | ||||||||
277 | namespace std | ||||||||
278 | { | ||||||||
279 | |||||||||
280 | /// @cond INTERNAL | ||||||||
281 | /** | ||||||||
282 | Make rtl::Reference hashable by default for use in STL containers. | ||||||||
283 | |||||||||
284 | @since LibreOffice 6.3 | ||||||||
285 | */ | ||||||||
286 | template<typename T> | ||||||||
287 | struct hash<::rtl::Reference<T>> | ||||||||
288 | { | ||||||||
289 | std::size_t operator()(::rtl::Reference<T> const & s) const | ||||||||
290 | { return std::size_t(s.get()); } | ||||||||
291 | }; | ||||||||
292 | /// @endcond | ||||||||
293 | |||||||||
294 | } | ||||||||
295 | |||||||||
296 | #endif | ||||||||
297 | |||||||||
298 | #endif /* ! INCLUDED_RTL_REF_HXX */ | ||||||||
299 | |||||||||
300 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_COM_SUN_STAR_UNO_REFERENCE_H |
20 | #define INCLUDED_COM_SUN_STAR_UNO_REFERENCE_H |
21 | |
22 | #include "sal/config.h" |
23 | |
24 | #include <cassert> |
25 | #include <cstddef> |
26 | |
27 | #if defined LIBO_INTERNAL_ONLY1 |
28 | #include <type_traits> |
29 | #endif |
30 | |
31 | #include "rtl/alloc.h" |
32 | |
33 | namespace com |
34 | { |
35 | namespace sun |
36 | { |
37 | namespace star |
38 | { |
39 | namespace uno |
40 | { |
41 | |
42 | class RuntimeException; |
43 | class XInterface; |
44 | class Type; |
45 | class Any; |
46 | |
47 | /** Enum defining UNO_REF_NO_ACQUIRE for setting reference without acquiring a given interface. |
48 | Deprecated, please use SAL_NO_ACQUIRE. |
49 | @deprecated |
50 | */ |
51 | enum UnoReference_NoAcquire |
52 | { |
53 | /** This enum value can be used for creating a reference granting a given interface, |
54 | i.e. transferring ownership to it. |
55 | */ |
56 | UNO_REF_NO_ACQUIRE |
57 | }; |
58 | |
59 | /** This base class serves as a base class for all template reference classes and |
60 | has been introduced due to compiler problems with templated operators ==, =!. |
61 | */ |
62 | class BaseReference |
63 | { |
64 | protected: |
65 | /** the interface pointer |
66 | */ |
67 | XInterface * _pInterface; |
68 | |
69 | /** Queries given interface for type rType. |
70 | |
71 | @param pInterface interface pointer |
72 | @param rType interface type |
73 | @return interface of demanded type (may be null) |
74 | */ |
75 | inline static XInterface * SAL_CALL iquery( XInterface * pInterface, const Type & rType ); |
76 | /** Queries given interface for type rType. |
77 | Throws a RuntimeException if the demanded interface cannot be queried. |
78 | |
79 | @param pInterface interface pointer |
80 | @param rType interface type |
81 | @return interface of demanded type |
82 | */ |
83 | inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface, const Type & rType ); |
84 | |
85 | public: |
86 | /** Gets interface pointer. This call does not acquire the interface. |
87 | |
88 | @return UNacquired interface pointer |
89 | */ |
90 | XInterface * SAL_CALL get() const |
91 | { return _pInterface; } |
92 | |
93 | /** Checks if reference is null. |
94 | |
95 | @return true if reference acquires an interface, i.e. true if it is not null |
96 | */ |
97 | bool SAL_CALL is() const |
98 | { return (NULL__null != _pInterface); } |
99 | |
100 | #if defined LIBO_INTERNAL_ONLY1 |
101 | /** Checks if reference is null. |
102 | |
103 | @return true if reference acquires an interface, i.e. true if it is not null |
104 | */ |
105 | explicit operator bool() const |
106 | { return is(); } |
107 | #endif |
108 | |
109 | /** Equality operator: compares two interfaces |
110 | Checks if both references are null or refer to the same object. |
111 | |
112 | @param pInterface another interface |
113 | @return true if both references are null or refer to the same object, false otherwise |
114 | */ |
115 | inline bool SAL_CALL operator == ( XInterface * pInterface ) const; |
116 | /** Inequality operator: compares two interfaces |
117 | Checks if both references are null or refer to the same object. |
118 | |
119 | @param pInterface another interface |
120 | @return false if both references are null or refer to the same object, true otherwise |
121 | */ |
122 | inline bool SAL_CALL operator != ( XInterface * pInterface ) const; |
123 | |
124 | /** Equality operator: compares two interfaces |
125 | Checks if both references are null or refer to the same object. |
126 | |
127 | @param rRef another reference |
128 | @return true if both references are null or refer to the same object, false otherwise |
129 | */ |
130 | inline bool SAL_CALL operator == ( const BaseReference & rRef ) const; |
131 | /** Inequality operator: compares two interfaces |
132 | Checks if both references are null or refer to the same object. |
133 | |
134 | @param rRef another reference |
135 | @return false if both references are null or refer to the same object, true otherwise |
136 | */ |
137 | inline bool SAL_CALL operator != ( const BaseReference & rRef ) const; |
138 | |
139 | /** Needed by some STL containers. |
140 | |
141 | @param rRef another reference |
142 | @return true, if this reference is less than rRef |
143 | */ |
144 | inline bool SAL_CALL operator < ( const BaseReference & rRef ) const; |
145 | }; |
146 | |
147 | /** Enum defining UNO_QUERY for implicit interface query. |
148 | */ |
149 | enum UnoReference_Query |
150 | { |
151 | /** This enum value can be used for implicit interface query. |
152 | */ |
153 | UNO_QUERY |
154 | }; |
155 | /** Enum defining UNO_QUERY_THROW for implicit interface query. |
156 | If the demanded interface is unavailable, then a RuntimeException is thrown. |
157 | */ |
158 | enum UnoReference_QueryThrow |
159 | { |
160 | /** This enum value can be used for implicit interface query. |
161 | */ |
162 | UNO_QUERY_THROW |
163 | }; |
164 | /** Enum defining UNO_SET_THROW for throwing if attempts are made to assign a null |
165 | interface |
166 | |
167 | @since UDK 3.2.8 |
168 | */ |
169 | enum UnoReference_SetThrow |
170 | { |
171 | UNO_SET_THROW |
172 | }; |
173 | |
174 | /** Template reference class for interface type derived from BaseReference. |
175 | A special constructor given the UNO_QUERY identifier queries interfaces |
176 | for reference type. |
177 | */ |
178 | template< class interface_type > |
179 | class SAL_DLLPUBLIC_RTTI__attribute__ ((type_visibility("default"))) Reference : public BaseReference |
180 | { |
181 | /** Queries given interface for type interface_type. |
182 | |
183 | @param pInterface interface pointer |
184 | @return interface of demanded type (may be null) |
185 | */ |
186 | inline static XInterface * SAL_CALL iquery( XInterface * pInterface ); |
187 | /** Queries given interface for type interface_type. |
188 | Throws a RuntimeException if the demanded interface cannot be queried. |
189 | |
190 | @param pInterface interface pointer |
191 | @return interface of demanded type |
192 | */ |
193 | inline static XInterface * SAL_CALL iquery_throw( XInterface * pInterface ); |
194 | /** Returns the given interface if it is not <NULL/>, throws a RuntimeException otherwise. |
195 | |
196 | @param pInterface interface pointer |
197 | @return pInterface |
198 | */ |
199 | inline static interface_type * SAL_CALL iset_throw( interface_type * pInterface ); |
200 | |
201 | /** Cast from an "interface pointer" (e.g., BaseReference::_pInterface) to a |
202 | pointer to this interface_type. |
203 | |
204 | To work around ambiguities in the case of multiple-inheritance interface |
205 | types (which inherit XInterface more than once), use reinterpret_cast |
206 | (resp. a sequence of two static_casts, to avoid warnings about |
207 | reinterpret_cast used between related classes) to switch from a pointer |
208 | to XInterface to a pointer to this derived interface_type. In |
209 | principle, this is not guaranteed to work. In practice, it seems to |
210 | work on all supported platforms. |
211 | */ |
212 | static interface_type * castFromXInterface(XInterface * p) { |
213 | return static_cast< interface_type * >(static_cast< void * >(p)); |
214 | } |
215 | |
216 | /** Cast from a pointer to this interface_type to an "interface pointer" |
217 | (e.g., BaseReference::_pInterface). |
218 | |
219 | To work around ambiguities in the case of multiple-inheritance interface |
220 | types (which inherit XInterface more than once), use reinterpret_cast |
221 | (resp. a sequence of two static_casts, to avoid warnings about |
222 | reinterpret_cast used between related classes) to switch from a pointer |
223 | to this derived interface_type to a pointer to XInterface. In |
224 | principle, this is not guaranteed to work. In practice, it seems to |
225 | work on all supported platforms. |
226 | */ |
227 | static XInterface * castToXInterface(interface_type * p) { |
228 | return static_cast< XInterface * >(static_cast< void * >(p)); |
229 | } |
230 | |
231 | public: |
232 | /// @cond INTERNAL |
233 | // these are here to force memory de/allocation to sal lib. |
234 | static void * SAL_CALL operator new ( ::size_t nSize ) |
235 | { return ::rtl_allocateMemory( nSize ); } |
236 | static void SAL_CALL operator delete ( void * pMem ) |
237 | { ::rtl_freeMemory( pMem ); } |
238 | static void * SAL_CALL operator new ( ::size_t, void * pMem ) |
239 | { return pMem; } |
240 | static void SAL_CALL operator delete ( void *, void * ) |
241 | {} |
242 | /// @endcond |
243 | |
244 | /** Destructor: Releases interface if set. |
245 | */ |
246 | inline ~Reference() COVERITY_NOEXCEPT_FALSE; |
247 | |
248 | /** Default Constructor: Sets null reference. |
249 | */ |
250 | inline Reference(); |
251 | |
252 | /** Copy constructor: Copies interface reference. |
253 | |
254 | @param rRef another reference |
255 | */ |
256 | inline Reference( const Reference< interface_type > & rRef ); |
257 | |
258 | #if defined LIBO_INTERNAL_ONLY1 |
259 | /** Move constructor |
260 | |
261 | @param rRef another reference |
262 | */ |
263 | inline Reference( Reference< interface_type > && rRef ) noexcept; |
264 | |
265 | /** Up-casting conversion constructor: Copies interface reference. |
266 | |
267 | Does not work for up-casts to ambiguous bases. For the special case of |
268 | up-casting to Reference< XInterface >, see the corresponding conversion |
269 | operator. |
270 | |
271 | @param rRef another reference |
272 | */ |
273 | template< class derived_type > |
274 | inline Reference( |
275 | const Reference< derived_type > & rRef, |
276 | std::enable_if_t< |
277 | std::is_base_of_v<interface_type, derived_type> |
278 | && !std::is_same_v<interface_type, XInterface>, void *> = nullptr); |
279 | #endif |
280 | |
281 | /** Constructor: Sets given interface pointer. |
282 | |
283 | @param pInterface an interface pointer |
284 | */ |
285 | inline Reference( interface_type * pInterface ); |
286 | |
287 | /** Constructor: Sets given interface pointer without acquiring it. |
288 | |
289 | @param pInterface another reference |
290 | @param dummy SAL_NO_ACQUIRE to force obvious distinction to other constructors |
291 | */ |
292 | inline Reference( interface_type * pInterface, __sal_NoAcquire dummy); |
293 | /** Constructor: Sets given interface pointer without acquiring it. |
294 | Deprecated, please use SAL_NO_ACQUIRE version. |
295 | |
296 | @deprecated |
297 | @param pInterface another reference |
298 | @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to other constructors |
299 | */ |
300 | inline SAL_DEPRECATED("use SAL_NO_ACQUIRE version")__attribute__((deprecated("use SAL_NO_ACQUIRE version"))) Reference( interface_type * pInterface, UnoReference_NoAcquire dummy ); |
301 | |
302 | /** Constructor: Queries given interface for reference interface type (interface_type). |
303 | |
304 | @param rRef another reference |
305 | @param dummy UNO_QUERY to force obvious distinction to other constructors |
306 | */ |
307 | inline Reference( const BaseReference & rRef, UnoReference_Query dummy ); |
308 | /** Constructor: Queries given interface for reference interface type (interface_type). |
309 | |
310 | @param pInterface an interface pointer |
311 | @param dummy UNO_QUERY to force obvious distinction to other constructors |
312 | */ |
313 | inline Reference( XInterface * pInterface, UnoReference_Query dummy); |
314 | /** Constructor: Queries given any for reference interface type (interface_type). |
315 | |
316 | @param rAny an any |
317 | @param dummy UNO_QUERY to force obvious distinction to other constructors |
318 | */ |
319 | inline Reference( const Any & rAny, UnoReference_Query dummy); |
320 | /** Constructor: Queries given interface for reference interface type (interface_type). |
321 | Throws a RuntimeException if the demanded interface cannot be queried. |
322 | |
323 | @param rRef another reference |
324 | @param dummy UNO_QUERY_THROW to force obvious distinction |
325 | to other constructors |
326 | */ |
327 | inline Reference( const BaseReference & rRef, UnoReference_QueryThrow dummy ); |
328 | #ifdef LIBO_INTERNAL_ONLY1 |
329 | /** |
330 | Prevent code from calling the QUERY_THROW constructor, when they meant to use the SET_THROW constructor. |
331 | */ |
332 | Reference( const Reference< interface_type > & rRef, UnoReference_QueryThrow dummy ) = delete; |
333 | #endif |
334 | /** Constructor: Queries given interface for reference interface type (interface_type). |
335 | Throws a RuntimeException if the demanded interface cannot be queried. |
336 | |
337 | @param pInterface an interface pointer |
338 | @param dummy UNO_QUERY_THROW to force obvious distinction |
339 | to other constructors |
340 | */ |
341 | inline Reference( XInterface * pInterface, UnoReference_QueryThrow dummy ); |
342 | /** Constructor: Queries given any for reference interface type (interface_type). |
343 | Throws a RuntimeException if the demanded interface cannot be queried. |
344 | |
345 | @param rAny an any |
346 | @param dummy UNO_QUERY_THROW to force obvious distinction |
347 | to other constructors |
348 | */ |
349 | inline Reference( const Any & rAny, UnoReference_QueryThrow dummy ); |
350 | /** Constructor: assigns from the given interface of the same type. Throws a RuntimeException |
351 | if the source interface is NULL. |
352 | |
353 | @param rRef another interface reference of the same type |
354 | @param dummy UNO_SET_THROW to distinguish from default copy constructor |
355 | |
356 | @since UDK 3.2.8 |
357 | */ |
358 | inline Reference( const Reference< interface_type > & rRef, UnoReference_SetThrow dummy ); |
359 | /** Constructor: assigns from the given interface of the same type. Throws a RuntimeException |
360 | if the source interface is NULL. |
361 | |
362 | @param pInterface an interface pointer |
363 | @param dummy UNO_SET_THROW to distinguish from default assignment constructor |
364 | |
365 | @since UDK 3.2.8 |
366 | */ |
367 | inline Reference( interface_type * pInterface, UnoReference_SetThrow dummy ); |
368 | |
369 | /** Cast operator to Reference< XInterface >: Reference objects are binary compatible and |
370 | any interface must be derived from com.sun.star.uno.XInterface. |
371 | This a useful direct cast possibility. |
372 | */ |
373 | SAL_CALL operator const Reference< XInterface > & () const |
374 | { return * reinterpret_cast< const Reference< XInterface > * >( this ); } |
375 | |
376 | /** Dereference operator: Used to call interface methods. |
377 | |
378 | @return UNacquired interface pointer |
379 | */ |
380 | interface_type * SAL_CALL operator -> () const { |
381 | assert(_pInterface != NULL)(static_cast <bool> (_pInterface != __null) ? void (0) : __assert_fail ("_pInterface != NULL", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Reference.h" , 381, __extension__ __PRETTY_FUNCTION__)); |
382 | return castFromXInterface(_pInterface); |
383 | } |
384 | |
385 | /** Indirection operator. |
386 | |
387 | @since LibreOffice 6.3 |
388 | @return UNacquired interface reference |
389 | */ |
390 | interface_type & SAL_CALL operator * () const { |
391 | assert(_pInterface != NULL)(static_cast <bool> (_pInterface != __null) ? void (0) : __assert_fail ("_pInterface != NULL", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Reference.h" , 391, __extension__ __PRETTY_FUNCTION__)); |
392 | return *castFromXInterface(_pInterface); |
393 | } |
394 | |
395 | /** Gets interface pointer. This call does not acquire the interface. |
396 | |
397 | @return UNacquired interface pointer |
398 | */ |
399 | interface_type * SAL_CALL get() const |
400 | { return castFromXInterface(_pInterface); } |
401 | |
402 | /** Clears reference, i.e. releases interface. Reference is null after clear() call. |
403 | */ |
404 | inline void SAL_CALL clear(); |
405 | |
406 | /** Sets the given interface. An interface already set will be released. |
407 | |
408 | @param rRef another reference |
409 | @return true, if non-null interface was set |
410 | */ |
411 | inline bool SAL_CALL set( const Reference< interface_type > & rRef ); |
412 | /** Sets the given interface. An interface already set will be released. |
413 | |
414 | @param pInterface another interface |
415 | @return true, if non-null interface was set |
416 | */ |
417 | inline bool SAL_CALL set( interface_type * pInterface ); |
418 | |
419 | /** Sets interface pointer without acquiring it. An interface already set will be released. |
420 | |
421 | @param pInterface an interface pointer |
422 | @param dummy SAL_NO_ACQUIRE to force obvious distinction to set methods |
423 | @return true, if non-null interface was set |
424 | */ |
425 | inline bool SAL_CALL set( interface_type * pInterface, __sal_NoAcquire dummy); |
426 | /** Sets interface pointer without acquiring it. An interface already set will be released. |
427 | Deprecated, please use SAL_NO_ACQUIRE version. |
428 | |
429 | @deprecated |
430 | @param pInterface an interface pointer |
431 | @param dummy UNO_REF_NO_ACQUIRE to force obvious distinction to set methods |
432 | @return true, if non-null interface was set |
433 | */ |
434 | inline SAL_DEPRECATED("use SAL_NO_ACQUIRE version")__attribute__((deprecated("use SAL_NO_ACQUIRE version"))) bool SAL_CALL set( interface_type * pInterface, UnoReference_NoAcquire dummy); |
435 | |
436 | /** Queries given interface for reference interface type (interface_type) and sets it. |
437 | An interface already set will be released. |
438 | |
439 | @param pInterface an interface pointer |
440 | @param dummy UNO_QUERY to force obvious distinction to set methods |
441 | @return true, if non-null interface was set |
442 | */ |
443 | inline bool SAL_CALL set( XInterface * pInterface, UnoReference_Query dummy ); |
444 | /** Queries given interface for reference interface type (interface_type) and sets it. |
445 | An interface already set will be released. |
446 | |
447 | @param rRef another reference |
448 | @param dummy UNO_QUERY to force obvious distinction to set methods |
449 | @return true, if non-null interface was set |
450 | */ |
451 | inline bool SAL_CALL set( const BaseReference & rRef, UnoReference_Query dummy); |
452 | |
453 | /** Queries given any for reference interface type (interface_type) |
454 | and sets it. An interface already set will be released. |
455 | |
456 | @param rAny |
457 | an Any containing an interface |
458 | @param dummy |
459 | UNO_QUERY to force obvious distinction |
460 | to set methods |
461 | @return |
462 | true, if non-null interface was set |
463 | */ |
464 | inline bool set( Any const & rAny, UnoReference_Query dummy ); |
465 | |
466 | /** Queries given interface for reference interface type (interface_type) and sets it. |
467 | An interface already set will be released. |
468 | Throws a RuntimeException if the demanded interface cannot be set. |
469 | |
470 | @param pInterface an interface pointer |
471 | @param dummy UNO_QUERY_THROW to force obvious distinction |
472 | to set methods |
473 | */ |
474 | inline void SAL_CALL set( XInterface * pInterface, UnoReference_QueryThrow dummy ); |
475 | /** Queries given interface for reference interface type (interface_type) and sets it. |
476 | An interface already set will be released. |
477 | Throws a RuntimeException if the demanded interface cannot be set. |
478 | |
479 | @param rRef another reference |
480 | @param dummy UNO_QUERY_THROW to force obvious distinction |
481 | to set methods |
482 | */ |
483 | inline void SAL_CALL set( const BaseReference & rRef, UnoReference_QueryThrow dummy ); |
484 | #ifdef LIBO_INTERNAL_ONLY1 |
485 | /** |
486 | Prevent code from calling the QUERY_THROW version, when they meant to use the SET_THROW version. |
487 | */ |
488 | void set( const Reference< interface_type > & rRef, UnoReference_QueryThrow dummy ) = delete; |
489 | #endif |
490 | |
491 | /** Queries given any for reference interface type (interface_type) and |
492 | sets it. An interface already set will be released. |
493 | Throws a RuntimeException if the demanded interface cannot be set. |
494 | |
495 | @param rAny |
496 | an Any containing an interface |
497 | @param dummy |
498 | UNO_QUERY_THROW to force obvious distinction to set methods |
499 | */ |
500 | inline void set( Any const & rAny, UnoReference_QueryThrow dummy); |
501 | /** sets the given interface |
502 | An interface already set will be released. |
503 | Throws a RuntimeException if the source interface is @b NULL. |
504 | |
505 | @param pInterface an interface pointer |
506 | @param dummy UNO_SET_THROW to force obvious distinction to other set methods |
507 | |
508 | @since UDK 3.2.8 |
509 | */ |
510 | inline void SAL_CALL set( interface_type * pInterface, UnoReference_SetThrow dummy); |
511 | /** sets the given interface |
512 | An interface already set will be released. |
513 | Throws a RuntimeException if the source interface is @b NULL. |
514 | |
515 | @param rRef an interface reference |
516 | @param dummy UNO_SET_THROW to force obvious distinction to other set methods |
517 | |
518 | @since UDK 3.2.8 |
519 | */ |
520 | inline void SAL_CALL set( const Reference< interface_type > & rRef, UnoReference_SetThrow dummy); |
521 | |
522 | |
523 | /** Assignment operator: Acquires given interface pointer and sets reference. |
524 | An interface already set will be released. |
525 | |
526 | @param pInterface an interface pointer |
527 | @return this reference |
528 | */ |
529 | inline Reference< interface_type > & SAL_CALL operator = ( interface_type * pInterface ); |
530 | /** Assignment operator: Acquires given interface reference and sets reference. |
531 | An interface already set will be released. |
532 | |
533 | @param rRef an interface reference |
534 | @return this reference |
535 | */ |
536 | inline Reference< interface_type > & SAL_CALL operator = ( const Reference< interface_type > & rRef ); |
537 | #if defined LIBO_INTERNAL_ONLY1 |
538 | /** Assignment move operator: Acquires given interface reference and sets reference. |
539 | An interface already set will be released. |
540 | |
541 | @param rRef an interface reference |
542 | @return this reference |
543 | */ |
544 | inline Reference< interface_type > & SAL_CALL operator = ( Reference< interface_type > && rRef ) noexcept; |
545 | #endif |
546 | /** Queries given interface reference for type interface_type. |
547 | |
548 | @param rRef interface reference |
549 | @return interface reference of demanded type (may be null) |
550 | */ |
551 | SAL_WARN_UNUSED_RESULT[[nodiscard]] inline static Reference< interface_type > SAL_CALL query( const BaseReference & rRef ); |
552 | /** Queries given interface for type interface_type. |
553 | |
554 | @param pInterface interface pointer |
555 | @return interface reference of demanded type (may be null) |
556 | */ |
557 | SAL_WARN_UNUSED_RESULT[[nodiscard]] inline static Reference< interface_type > SAL_CALL query( XInterface * pInterface ); |
558 | }; |
559 | |
560 | } |
561 | } |
562 | } |
563 | } |
564 | |
565 | #endif |
566 | |
567 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |
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 | #ifndef INCLUDED_TOOLS_LINK_HXX |
21 | #define INCLUDED_TOOLS_LINK_HXX |
22 | |
23 | #include <sal/config.h> |
24 | |
25 | #include <sal/macros.h> |
26 | #include <sal/types.h> |
27 | |
28 | #define DECL_LINK(Member, ArgType, RetType)static RetType LinkStubMember(void *, ArgType); RetType Member (ArgType) \ |
29 | static RetType LinkStub##Member(void *, ArgType); \ |
30 | RetType Member(ArgType) |
31 | |
32 | #define DECL_STATIC_LINK(Class, Member, ArgType, RetType)static RetType LinkStubMember(void *, ArgType); static RetType Member(Class *, ArgType) \ |
33 | static RetType LinkStub##Member(void *, ArgType); \ |
34 | static RetType Member(Class *, ArgType) |
35 | |
36 | #define DECL_DLLPRIVATE_LINK(Member, ArgType, RetType)__attribute__ ((visibility("hidden"))) static RetType LinkStubMember (void *, ArgType); __attribute__ ((visibility("hidden"))) RetType Member(ArgType) \ |
37 | SAL_DLLPRIVATE__attribute__ ((visibility("hidden"))) static RetType LinkStub##Member(void *, ArgType); \ |
38 | SAL_DLLPRIVATE__attribute__ ((visibility("hidden"))) RetType Member(ArgType) |
39 | |
40 | #define DECL_DLLPRIVATE_STATIC_LINK(Class, Member, ArgType, RetType)__attribute__ ((visibility("hidden"))) static RetType LinkStubMember (void *, ArgType); __attribute__ ((visibility("hidden"))) static RetType Member(Class *, ArgType) \ |
41 | SAL_DLLPRIVATE__attribute__ ((visibility("hidden"))) static RetType LinkStub##Member(void *, ArgType); \ |
42 | SAL_DLLPRIVATE__attribute__ ((visibility("hidden"))) static RetType Member(Class *, ArgType) |
43 | |
44 | #define IMPL_LINK(Class, Member, ArgType, ArgName, RetType)RetType Class::LinkStubMember(void * instance, ArgType data) { return static_cast<Class *>(instance)->Member(data) ; } RetType Class::Member(ArgType ArgName) \ |
45 | RetType Class::LinkStub##Member(void * instance, ArgType data) { \ |
46 | return static_cast<Class *>(instance)->Member(data); \ |
47 | } \ |
48 | RetType Class::Member(ArgType ArgName) |
49 | |
50 | #define IMPL_LINK_NOARG(Class, Member, ArgType, RetType)RetType Class::LinkStubMember(void * instance, ArgType data) { return static_cast<Class *>(instance)->Member(data) ; } RetType Class::Member(__attribute__ ((unused)) ArgType) \ |
51 | RetType Class::LinkStub##Member(void * instance, ArgType data) { \ |
52 | return static_cast<Class *>(instance)->Member(data); \ |
53 | } \ |
54 | RetType Class::Member(SAL_UNUSED_PARAMETER__attribute__ ((unused)) ArgType) |
55 | |
56 | #define IMPL_STATIC_LINK( \RetType Class::LinkStubMember(void * instance, ArgType data) { return Member(static_cast<Class *>(instance), data); } RetType Class::Member(__attribute__ ((unused)) Class *, ArgType ArgName) |
57 | Class, Member, ArgType, ArgName, RetType)RetType Class::LinkStubMember(void * instance, ArgType data) { return Member(static_cast<Class *>(instance), data); } RetType Class::Member(__attribute__ ((unused)) Class *, ArgType ArgName) \ |
58 | RetType Class::LinkStub##Member(void * instance, ArgType data) { \ |
59 | return Member(static_cast<Class *>(instance), data); \ |
60 | } \ |
61 | RetType Class::Member(SAL_UNUSED_PARAMETER__attribute__ ((unused)) Class *, ArgType ArgName) |
62 | |
63 | #define IMPL_STATIC_LINK_NOARG( \RetType Class::LinkStubMember(void * instance, ArgType data) { return Member(static_cast<Class *>(instance), data); } RetType Class::Member( __attribute__ ((unused)) Class *, __attribute__ ((unused)) ArgType) |
64 | Class, Member, ArgType, RetType)RetType Class::LinkStubMember(void * instance, ArgType data) { return Member(static_cast<Class *>(instance), data); } RetType Class::Member( __attribute__ ((unused)) Class *, __attribute__ ((unused)) ArgType) \ |
65 | RetType Class::LinkStub##Member(void * instance, ArgType data) { \ |
66 | return Member(static_cast<Class *>(instance), data); \ |
67 | } \ |
68 | RetType Class::Member( \ |
69 | SAL_UNUSED_PARAMETER__attribute__ ((unused)) Class *, SAL_UNUSED_PARAMETER__attribute__ ((unused)) ArgType) |
70 | |
71 | #ifdef DBG_UTIL |
72 | #define LINK(Instance, Class, Member)::tools::detail::makeLink( ::tools::detail::castTo<Class * >(Instance), &Class::LinkStubMember) ::tools::detail::makeLink( \ |
73 | ::tools::detail::castTo<Class *>(Instance), &Class::LinkStub##Member, __FILE__"/home/maarten/src/libreoffice/core/include/tools/link.hxx", __LINE__73, SAL_STRINGIFY(Class::LinkStub##Member)"Class::LinkStub##Member") |
74 | #else |
75 | #define LINK(Instance, Class, Member)::tools::detail::makeLink( ::tools::detail::castTo<Class * >(Instance), &Class::LinkStubMember) ::tools::detail::makeLink( \ |
76 | ::tools::detail::castTo<Class *>(Instance), &Class::LinkStub##Member) |
77 | #endif |
78 | |
79 | template<typename Arg, typename Ret> |
80 | class SAL_WARN_UNUSED__attribute__((warn_unused)) Link { |
81 | public: |
82 | typedef Ret Stub(void *, Arg); |
83 | |
84 | #ifdef DBG_UTIL |
85 | Link() |
86 | : function_(nullptr) |
87 | , instance_(nullptr) |
88 | , file_("unknown") |
89 | , line_(0) |
90 | , target_("unknown") |
91 | { |
92 | } |
93 | |
94 | Link(void* instance, Stub* function, const char* const file = "unknown", const int line = 0, |
95 | const char* const target = "unknown") |
96 | : function_(function) |
97 | , instance_(instance) |
98 | , file_(file) |
99 | , line_(line) |
100 | , target_(target) |
101 | { |
102 | } |
103 | #else |
104 | Link(): function_(nullptr), instance_(nullptr) {} |
105 | |
106 | Link(void * instance, Stub * function): |
107 | function_(function), instance_(instance) {} |
108 | #endif |
109 | |
110 | Ret Call(Arg data) const |
111 | { return function_ == nullptr ? Ret() : (*function_)(instance_, data); } |
112 | |
113 | bool IsSet() const { return function_ != nullptr; } |
114 | |
115 | bool operator !() const { return !IsSet(); } |
116 | |
117 | bool operator <(Link const & other) const { |
118 | char* ptr1 = reinterpret_cast<char*>(function_); |
119 | char* ptr2 = reinterpret_cast<char*>(other.function_); |
120 | if (ptr1 < ptr2) |
121 | return true; |
122 | else if (ptr1 > ptr2) |
123 | return false; |
124 | else |
125 | return instance_ < other.instance_; |
126 | }; |
127 | |
128 | bool operator ==(Link const & other) const |
129 | { return function_ == other.function_ && instance_ == other.instance_; }; |
130 | |
131 | void *GetInstance() const { return instance_; } |
132 | |
133 | #ifdef DBG_UTIL |
134 | const char* getSourceFilename() const { return file_; } |
135 | int getSourceLineNumber() const { return line_; } |
136 | const char* getTargetName() const { return target_; } |
137 | #endif |
138 | |
139 | private: |
140 | Stub * function_; |
141 | void * instance_; |
142 | |
143 | #ifdef DBG_UTIL |
144 | /// Support tracing link source and target. |
145 | /// When debugging async events, it's often critical |
146 | /// to find out not only where a link leads (i.e. the target |
147 | /// function), but also where it was created (file:line). |
148 | const char* file_; |
149 | int line_; |
150 | const char* target_; |
151 | #endif |
152 | }; |
153 | |
154 | // Class used to indicate that the Call() parameter is not in use: |
155 | class LinkParamNone { LinkParamNone() = delete; }; |
156 | |
157 | namespace tools::detail { |
158 | |
159 | // Avoids loplugin:redundantcast in LINK macro, in the common case that Instance |
160 | // is already of type Class * (instead of a derived type): |
161 | template<typename To, typename From> To castTo(From from) |
162 | { return static_cast<To>(from); } |
163 | |
164 | #ifdef DBG_UTIL |
165 | template<typename Arg, typename Ret> |
166 | Link<Arg, Ret> makeLink(void * instance, Ret (* function)(void *, Arg), const char* file, int line, const char* target) { |
167 | return Link<Arg, Ret>(instance, function, file, line, target); |
168 | } |
169 | #else |
170 | template<typename Arg, typename Ret> |
171 | Link<Arg, Ret> makeLink(void * instance, Ret (* function)(void *, Arg)) { |
172 | return Link<Arg, Ret>(instance, function); |
173 | } |
174 | #endif |
175 | |
176 | } |
177 | |
178 | #endif |
179 | |
180 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |