File: | home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx |
Warning: | line 830, column 17 2nd function call argument is an uninitialized value |
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 <xlchart.hxx> | |||
21 | ||||
22 | #include <com/sun/star/container/XNameContainer.hpp> | |||
23 | #include <com/sun/star/awt/Size.hpp> | |||
24 | #include <com/sun/star/awt/Gradient.hpp> | |||
25 | #include <com/sun/star/drawing/Hatch.hpp> | |||
26 | #include <com/sun/star/drawing/LineDash.hpp> | |||
27 | #include <com/sun/star/drawing/LineStyle.hpp> | |||
28 | #include <com/sun/star/drawing/FillStyle.hpp> | |||
29 | #include <com/sun/star/drawing/BitmapMode.hpp> | |||
30 | #include <com/sun/star/chart/DataLabelPlacement.hpp> | |||
31 | #include <com/sun/star/chart/XAxisXSupplier.hpp> | |||
32 | #include <com/sun/star/chart/XAxisYSupplier.hpp> | |||
33 | #include <com/sun/star/chart/XAxisZSupplier.hpp> | |||
34 | #include <com/sun/star/chart/XChartDocument.hpp> | |||
35 | #include <com/sun/star/chart/XSecondAxisTitleSupplier.hpp> | |||
36 | #include <com/sun/star/chart2/Symbol.hpp> | |||
37 | #include <com/sun/star/chart2/XChartDocument.hpp> | |||
38 | #include <com/sun/star/lang/XMultiServiceFactory.hpp> | |||
39 | ||||
40 | #include <rtl/math.hxx> | |||
41 | #include <sal/macros.h> | |||
42 | #include <svl/itemset.hxx> | |||
43 | #include <svx/xfillit0.hxx> | |||
44 | #include <svx/xflclit.hxx> | |||
45 | #include <svx/xfltrit.hxx> | |||
46 | #include <svx/xflgrit.hxx> | |||
47 | #include <svx/xbtmpit.hxx> | |||
48 | #include <svx/unomid.hxx> | |||
49 | #include <filter/msfilter/escherex.hxx> | |||
50 | #include <xlroot.hxx> | |||
51 | #include <xlstyle.hxx> | |||
52 | #include <xltools.hxx> | |||
53 | ||||
54 | using namespace css; | |||
55 | ||||
56 | // Common ===================================================================== | |||
57 | ||||
58 | XclChRectangle::XclChRectangle() : | |||
59 | mnX( 0 ), | |||
60 | mnY( 0 ), | |||
61 | mnWidth( 0 ), | |||
62 | mnHeight( 0 ) | |||
63 | { | |||
64 | } | |||
65 | ||||
66 | XclChDataPointPos::XclChDataPointPos( sal_uInt16 nSeriesIdx, sal_uInt16 nPointIdx ) : | |||
67 | mnSeriesIdx( nSeriesIdx ), | |||
68 | mnPointIdx( nPointIdx ) | |||
69 | { | |||
70 | } | |||
71 | ||||
72 | bool operator<( const XclChDataPointPos& rL, const XclChDataPointPos& rR ) | |||
73 | { | |||
74 | return (rL.mnSeriesIdx < rR.mnSeriesIdx) || | |||
75 | ((rL.mnSeriesIdx == rR.mnSeriesIdx) && (rL.mnPointIdx < rR.mnPointIdx)); | |||
76 | } | |||
77 | ||||
78 | XclChFrBlock::XclChFrBlock( sal_uInt16 nType ) : | |||
79 | mnType( nType ), | |||
80 | mnContext( 0 ), | |||
81 | mnValue1( 0 ), | |||
82 | mnValue2( 0 ) | |||
83 | { | |||
84 | } | |||
85 | ||||
86 | // Frame formatting =========================================================== | |||
87 | ||||
88 | XclChFramePos::XclChFramePos() : | |||
89 | mnTLMode( EXC_CHFRAMEPOS_PARENT ), | |||
90 | mnBRMode( EXC_CHFRAMEPOS_PARENT ) | |||
91 | { | |||
92 | } | |||
93 | ||||
94 | XclChLineFormat::XclChLineFormat() : | |||
95 | maColor( COL_BLACK ), | |||
96 | mnPattern( EXC_CHLINEFORMAT_SOLID ), | |||
97 | mnWeight( EXC_CHLINEFORMAT_SINGLE ), | |||
98 | mnFlags( EXC_CHLINEFORMAT_AUTO ) | |||
99 | { | |||
100 | } | |||
101 | ||||
102 | XclChAreaFormat::XclChAreaFormat() : | |||
103 | maPattColor( COL_WHITE ), | |||
104 | maBackColor( COL_BLACK ), | |||
105 | mnPattern( EXC_PATT_SOLID ), | |||
106 | mnFlags( EXC_CHAREAFORMAT_AUTO ) | |||
107 | { | |||
108 | } | |||
109 | ||||
110 | XclChEscherFormat::XclChEscherFormat() | |||
111 | { | |||
112 | } | |||
113 | ||||
114 | XclChEscherFormat::~XclChEscherFormat() | |||
115 | { | |||
116 | } | |||
117 | ||||
118 | XclChPicFormat::XclChPicFormat() : | |||
119 | mnBmpMode( EXC_CHPICFORMAT_NONE ), | |||
120 | mnFlags( EXC_CHPICFORMAT_TOPBOTTOM | EXC_CHPICFORMAT_FRONTBACK | EXC_CHPICFORMAT_LEFTRIGHT ), | |||
121 | mfScale( 0.5 ) | |||
122 | { | |||
123 | } | |||
124 | ||||
125 | XclChFrame::XclChFrame() : | |||
126 | mnFormat( EXC_CHFRAME_STANDARD ), | |||
127 | mnFlags( EXC_CHFRAME_AUTOSIZE | EXC_CHFRAME_AUTOPOS ) | |||
128 | { | |||
129 | } | |||
130 | ||||
131 | // Source links =============================================================== | |||
132 | ||||
133 | XclChSourceLink::XclChSourceLink() : | |||
134 | mnDestType( EXC_CHSRCLINK_TITLE ), | |||
135 | mnLinkType( EXC_CHSRCLINK_DEFAULT ), | |||
136 | mnFlags( 0 ), | |||
137 | mnNumFmtIdx( 0 ) | |||
138 | { | |||
139 | } | |||
140 | ||||
141 | // Text ======================================================================= | |||
142 | ||||
143 | XclChObjectLink::XclChObjectLink() : | |||
144 | mnTarget( EXC_CHOBJLINK_NONE ) | |||
145 | { | |||
146 | } | |||
147 | ||||
148 | XclChFrLabelProps::XclChFrLabelProps() : | |||
149 | mnFlags( 0 ) | |||
150 | { | |||
151 | } | |||
152 | ||||
153 | XclChText::XclChText() : | |||
154 | maTextColor( COL_BLACK ), | |||
155 | mnHAlign( EXC_CHTEXT_ALIGN_CENTER ), | |||
156 | mnVAlign( EXC_CHTEXT_ALIGN_CENTER ), | |||
157 | mnBackMode( EXC_CHTEXT_TRANSPARENT ), | |||
158 | mnFlags( EXC_CHTEXT_AUTOCOLOR | EXC_CHTEXT_AUTOFILL ), | |||
159 | mnFlags2( EXC_CHTEXT_POS_DEFAULT ), | |||
160 | mnRotation( EXC_ROT_NONE ) | |||
161 | { | |||
162 | } | |||
163 | ||||
164 | // Data series ================================================================ | |||
165 | ||||
166 | XclChMarkerFormat::XclChMarkerFormat() : | |||
167 | maLineColor( COL_BLACK ), | |||
168 | maFillColor( COL_WHITE ), | |||
169 | mnMarkerSize( EXC_CHMARKERFORMAT_SINGLESIZE ), | |||
170 | mnMarkerType( EXC_CHMARKERFORMAT_NOSYMBOL ), | |||
171 | mnFlags( EXC_CHMARKERFORMAT_AUTO ) | |||
172 | { | |||
173 | }; | |||
174 | ||||
175 | XclCh3dDataFormat::XclCh3dDataFormat() : | |||
176 | mnBase( EXC_CH3DDATAFORMAT_RECT ), | |||
177 | mnTop( EXC_CH3DDATAFORMAT_STRAIGHT ) | |||
178 | { | |||
179 | } | |||
180 | ||||
181 | XclChDataFormat::XclChDataFormat() : | |||
182 | mnFormatIdx( EXC_CHDATAFORMAT_DEFAULT ), | |||
183 | mnFlags( 0 ) | |||
184 | { | |||
185 | } | |||
186 | ||||
187 | XclChSerTrendLine::XclChSerTrendLine() : | |||
188 | mfForecastFor( 0.0 ), | |||
189 | mfForecastBack( 0.0 ), | |||
190 | mnLineType( EXC_CHSERTREND_POLYNOMIAL ), | |||
191 | mnOrder( 1 ), | |||
192 | mnShowEquation( 0 ), | |||
193 | mnShowRSquared( 0 ) | |||
194 | { | |||
195 | /* Set all bits in mfIntercept to 1 (that is -1.#NAN) to indicate that | |||
196 | there is no interception point. Cannot use ::rtl::math::setNan() here | |||
197 | cause it misses the sign bit. */ | |||
198 | sal_math_Double* pDouble = reinterpret_cast< sal_math_Double* >( &mfIntercept ); | |||
199 | pDouble->w32_parts.msw = pDouble->w32_parts.lsw = 0xFFFFFFFF; | |||
200 | } | |||
201 | ||||
202 | XclChSerErrorBar::XclChSerErrorBar() : | |||
203 | mfValue( 0.0 ), | |||
204 | mnValueCount( 1 ), | |||
205 | mnBarType( EXC_CHSERERR_NONE ), | |||
206 | mnSourceType( EXC_CHSERERR_FIXED ), | |||
207 | mnLineEnd( EXC_CHSERERR_END_TSHAPE ) | |||
208 | { | |||
209 | } | |||
210 | ||||
211 | XclChSeries::XclChSeries() : | |||
212 | mnCategType( EXC_CHSERIES_NUMERIC ), | |||
213 | mnValueType( EXC_CHSERIES_NUMERIC ), | |||
214 | mnBubbleType( EXC_CHSERIES_NUMERIC ), | |||
215 | mnCategCount( 0 ), | |||
216 | mnValueCount( 0 ), | |||
217 | mnBubbleCount( 0 ) | |||
218 | { | |||
219 | } | |||
220 | ||||
221 | // Chart type groups ========================================================== | |||
222 | ||||
223 | XclChType::XclChType() : | |||
224 | mnOverlap( 0 ), | |||
225 | mnGap( 150 ), | |||
226 | mnRotation( 0 ), | |||
227 | mnPieHole( 0 ), | |||
228 | mnBubbleSize( 100 ), | |||
229 | mnBubbleType( EXC_CHSCATTER_AREA ), | |||
230 | mnFlags( 0 ) | |||
231 | { | |||
232 | } | |||
233 | ||||
234 | XclChChart3d::XclChChart3d() : | |||
235 | mnRotation( 20 ), | |||
236 | mnElevation( 15 ), | |||
237 | mnEyeDist( 30 ), | |||
238 | mnRelHeight( 100 ), | |||
239 | mnRelDepth( 100 ), | |||
240 | mnDepthGap( 150 ), | |||
241 | mnFlags( EXC_CHCHART3D_AUTOHEIGHT ) | |||
242 | { | |||
243 | } | |||
244 | ||||
245 | XclChLegend::XclChLegend() : | |||
246 | mnDockMode( EXC_CHLEGEND_RIGHT ), | |||
247 | mnSpacing( EXC_CHLEGEND_MEDIUM ), | |||
248 | mnFlags( EXC_CHLEGEND_DOCKED | EXC_CHLEGEND_AUTOSERIES | | |||
249 | EXC_CHLEGEND_AUTOPOSX | EXC_CHLEGEND_AUTOPOSY | EXC_CHLEGEND_STACKED ) | |||
250 | { | |||
251 | } | |||
252 | ||||
253 | XclChTypeGroup::XclChTypeGroup() : | |||
254 | mnFlags( 0 ), | |||
255 | mnGroupIdx( EXC_CHSERGROUP_NONE ) | |||
256 | { | |||
257 | } | |||
258 | ||||
259 | XclChProperties::XclChProperties() : | |||
260 | mnFlags( 0 ), | |||
261 | mnEmptyMode( EXC_CHPROPS_EMPTY_SKIP ) | |||
262 | { | |||
263 | } | |||
264 | ||||
265 | // Axes ======================================================================= | |||
266 | ||||
267 | XclChLabelRange::XclChLabelRange() : | |||
268 | mnCross( 1 ), | |||
269 | mnLabelFreq( 1 ), | |||
270 | mnTickFreq( 1 ), | |||
271 | mnFlags( 0 ) | |||
272 | { | |||
273 | } | |||
274 | ||||
275 | XclChDateRange::XclChDateRange() : | |||
276 | mnMinDate( 0 ), | |||
277 | mnMaxDate( 0 ), | |||
278 | mnMajorStep( 0 ), | |||
279 | mnMajorUnit( EXC_CHDATERANGE_DAYS ), | |||
280 | mnMinorStep( 0 ), | |||
281 | mnMinorUnit( EXC_CHDATERANGE_DAYS ), | |||
282 | mnBaseUnit( EXC_CHDATERANGE_DAYS ), | |||
283 | mnCross( 0 ), | |||
284 | mnFlags( EXC_CHDATERANGE_AUTOMIN | EXC_CHDATERANGE_AUTOMAX | | |||
285 | EXC_CHDATERANGE_AUTOMAJOR | EXC_CHDATERANGE_AUTOMINOR | | |||
286 | EXC_CHDATERANGE_AUTOBASE | EXC_CHDATERANGE_AUTOCROSS | | |||
287 | EXC_CHDATERANGE_AUTODATE ) | |||
288 | { | |||
289 | } | |||
290 | ||||
291 | XclChValueRange::XclChValueRange() : | |||
292 | mfMin( 0.0 ), | |||
293 | mfMax( 0.0 ), | |||
294 | mfMajorStep( 0.0 ), | |||
295 | mfMinorStep( 0.0 ), | |||
296 | mfCross( 0.0 ), | |||
297 | mnFlags( EXC_CHVALUERANGE_AUTOMIN | EXC_CHVALUERANGE_AUTOMAX | | |||
298 | EXC_CHVALUERANGE_AUTOMAJOR | EXC_CHVALUERANGE_AUTOMINOR | | |||
299 | EXC_CHVALUERANGE_AUTOCROSS | EXC_CHVALUERANGE_BIT8 ) | |||
300 | { | |||
301 | } | |||
302 | ||||
303 | XclChTick::XclChTick() : | |||
304 | maTextColor( COL_BLACK ), | |||
305 | mnMajor( EXC_CHTICK_INSIDE | EXC_CHTICK_OUTSIDE ), | |||
306 | mnMinor( 0 ), | |||
307 | mnLabelPos( EXC_CHTICK_NEXT ), | |||
308 | mnBackMode( EXC_CHTICK_TRANSPARENT ), | |||
309 | mnFlags( EXC_CHTICK_AUTOCOLOR | EXC_CHTICK_AUTOROT ), | |||
310 | mnRotation( EXC_ROT_NONE ) | |||
311 | { | |||
312 | } | |||
313 | ||||
314 | XclChAxis::XclChAxis() : | |||
315 | mnType( EXC_CHAXIS_NONE ) | |||
316 | { | |||
317 | } | |||
318 | ||||
319 | sal_Int32 XclChAxis::GetApiAxisDimension() const | |||
320 | { | |||
321 | sal_Int32 nApiAxisDim = EXC_CHART_AXIS_NONE; | |||
322 | switch( mnType ) | |||
323 | { | |||
324 | case EXC_CHAXIS_X: nApiAxisDim = EXC_CHART_AXIS_X; break; | |||
325 | case EXC_CHAXIS_Y: nApiAxisDim = EXC_CHART_AXIS_Y; break; | |||
326 | case EXC_CHAXIS_Z: nApiAxisDim = EXC_CHART_AXIS_Z; break; | |||
327 | } | |||
328 | return nApiAxisDim; | |||
329 | } | |||
330 | ||||
331 | XclChAxesSet::XclChAxesSet() : | |||
332 | mnAxesSetId( EXC_CHAXESSET_PRIMARY ) | |||
333 | { | |||
334 | } | |||
335 | ||||
336 | sal_Int32 XclChAxesSet::GetApiAxesSetIndex() const | |||
337 | { | |||
338 | sal_Int32 nApiAxesSetIdx = EXC_CHART_AXESSET_NONE; | |||
339 | switch( mnAxesSetId ) | |||
340 | { | |||
341 | case EXC_CHAXESSET_PRIMARY: nApiAxesSetIdx = EXC_CHART_AXESSET_PRIMARY; break; | |||
342 | case EXC_CHAXESSET_SECONDARY: nApiAxesSetIdx = EXC_CHART_AXESSET_SECONDARY; break; | |||
343 | } | |||
344 | return nApiAxesSetIdx; | |||
345 | } | |||
346 | ||||
347 | // Static helper functions ==================================================== | |||
348 | ||||
349 | sal_uInt16 XclChartHelper::GetSeriesLineAutoColorIdx( sal_uInt16 nFormatIdx ) | |||
350 | { | |||
351 | static const sal_uInt16 spnLineColors[] = | |||
352 | { | |||
353 | 32, 33, 34, 35, 36, 37, 38, 39, | |||
354 | 40, 41, 42, 43, 44, 45, 46, 47, | |||
355 | 48, 49, 50, 51, 52, 53, 54, 55, | |||
356 | 56, 57, 58, 59, 60, 61, 62, 8, | |||
357 | 9, 10, 11, 12, 13, 14, 15, 16, | |||
358 | 17, 18, 19, 20, 21, 22, 23, 24, | |||
359 | 25, 26, 27, 28, 29, 30, 31, 63 | |||
360 | }; | |||
361 | return spnLineColors[ nFormatIdx % SAL_N_ELEMENTS( spnLineColors )(sizeof(sal_n_array_size(spnLineColors))) ]; | |||
362 | } | |||
363 | ||||
364 | sal_uInt16 XclChartHelper::GetSeriesFillAutoColorIdx( sal_uInt16 nFormatIdx ) | |||
365 | { | |||
366 | static const sal_uInt16 spnFillColors[] = | |||
367 | { | |||
368 | 24, 25, 26, 27, 28, 29, 30, 31, | |||
369 | 32, 33, 34, 35, 36, 37, 38, 39, | |||
370 | 40, 41, 42, 43, 44, 45, 46, 47, | |||
371 | 48, 49, 50, 51, 52, 53, 54, 55, | |||
372 | 56, 57, 58, 59, 60, 61, 62, 63, | |||
373 | 8, 9, 10, 11, 12, 13, 14, 15, | |||
374 | 16, 17, 18, 19, 20, 21, 22, 23 | |||
375 | }; | |||
376 | return spnFillColors[ nFormatIdx % SAL_N_ELEMENTS( spnFillColors )(sizeof(sal_n_array_size(spnFillColors))) ]; | |||
377 | } | |||
378 | ||||
379 | sal_uInt8 XclChartHelper::GetSeriesFillAutoTransp( sal_uInt16 nFormatIdx ) | |||
380 | { | |||
381 | static const sal_uInt8 spnTrans[] = { 0x00, 0x40, 0x20, 0x60, 0x70 }; | |||
382 | return spnTrans[ (nFormatIdx / 56) % SAL_N_ELEMENTS( spnTrans )(sizeof(sal_n_array_size(spnTrans))) ]; | |||
383 | } | |||
384 | ||||
385 | sal_uInt16 XclChartHelper::GetAutoMarkerType( sal_uInt16 nFormatIdx ) | |||
386 | { | |||
387 | static const sal_uInt16 spnSymbols[] = { | |||
388 | EXC_CHMARKERFORMAT_DIAMOND, EXC_CHMARKERFORMAT_SQUARE, EXC_CHMARKERFORMAT_TRIANGLE, | |||
389 | EXC_CHMARKERFORMAT_CROSS, EXC_CHMARKERFORMAT_STAR, EXC_CHMARKERFORMAT_CIRCLE, | |||
390 | EXC_CHMARKERFORMAT_PLUS, EXC_CHMARKERFORMAT_DOWJ, EXC_CHMARKERFORMAT_STDDEV }; | |||
391 | return spnSymbols[ nFormatIdx % SAL_N_ELEMENTS( spnSymbols )(sizeof(sal_n_array_size(spnSymbols))) ]; | |||
392 | } | |||
393 | ||||
394 | bool XclChartHelper::HasMarkerFillColor( sal_uInt16 nMarkerType ) | |||
395 | { | |||
396 | static const bool spbFilled[] = { | |||
397 | false, true, true, true, false, false, false, false, true, false }; | |||
398 | return (nMarkerType < SAL_N_ELEMENTS( spbFilled )(sizeof(sal_n_array_size(spbFilled)))) && spbFilled[ nMarkerType ]; | |||
399 | } | |||
400 | ||||
401 | OUString XclChartHelper::GetErrorBarValuesRole( sal_uInt8 nBarType ) | |||
402 | { | |||
403 | switch( nBarType ) | |||
404 | { | |||
405 | case EXC_CHSERERR_XPLUS: return EXC_CHPROP_ROLE_ERRORBARS_POSX"error-bars-x-positive"; | |||
406 | case EXC_CHSERERR_XMINUS: return EXC_CHPROP_ROLE_ERRORBARS_NEGX"error-bars-x-negative"; | |||
407 | case EXC_CHSERERR_YPLUS: return EXC_CHPROP_ROLE_ERRORBARS_POSY"error-bars-y-positive"; | |||
408 | case EXC_CHSERERR_YMINUS: return EXC_CHPROP_ROLE_ERRORBARS_NEGY"error-bars-y-negative"; | |||
409 | default: OSL_FAIL( "XclChartHelper::GetErrorBarValuesRole - unknown bar type" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "409" ": "), "%s", "XclChartHelper::GetErrorBarValuesRole - unknown bar type" ); } } while (false); | |||
410 | } | |||
411 | return OUString(); | |||
412 | } | |||
413 | ||||
414 | // Chart formatting info provider ============================================= | |||
415 | ||||
416 | namespace { | |||
417 | ||||
418 | const XclChFormatInfo spFmtInfos[] = | |||
419 | { | |||
420 | // object type property mode auto line color auto line weight auto pattern color missing frame type create delete isframe | |||
421 | { EXC_CHOBJTYPE_BACKGROUND, EXC_CHPROPMODE_COMMON, EXC_COLOR_CHWINDOWTEXT, EXC_CHLINEFORMAT_HAIR, EXC_COLOR_CHWINDOWBACK, EXC_CHFRAMETYPE_INVISIBLE, true, true, true }, | |||
422 | { EXC_CHOBJTYPE_PLOTFRAME, EXC_CHPROPMODE_COMMON, EXC_COLOR_CHWINDOWTEXT, EXC_CHLINEFORMAT_HAIR, EXC_COLOR_CHWINDOWBACK, EXC_CHFRAMETYPE_INVISIBLE, true, true, true }, | |||
423 | { EXC_CHOBJTYPE_WALL3D, EXC_CHPROPMODE_COMMON, EXC_COLOR_CHWINDOWTEXT, EXC_CHLINEFORMAT_HAIR, EXC_COLOR_CHWINDOWBACK, EXC_CHFRAMETYPE_AUTO, true, false, true }, | |||
424 | { EXC_CHOBJTYPE_FLOOR3D, EXC_CHPROPMODE_COMMON, EXC_COLOR_CHWINDOWTEXT, EXC_CHLINEFORMAT_HAIR, 23, EXC_CHFRAMETYPE_AUTO, true, false, true }, | |||
425 | { EXC_CHOBJTYPE_TEXT, EXC_CHPROPMODE_COMMON, EXC_COLOR_CHWINDOWTEXT, EXC_CHLINEFORMAT_HAIR, EXC_COLOR_CHWINDOWBACK, EXC_CHFRAMETYPE_INVISIBLE, false, true, true }, | |||
426 | { EXC_CHOBJTYPE_LEGEND, EXC_CHPROPMODE_COMMON, EXC_COLOR_CHWINDOWTEXT, EXC_CHLINEFORMAT_HAIR, EXC_COLOR_CHWINDOWBACK, EXC_CHFRAMETYPE_AUTO, true, true, true }, | |||
427 | { EXC_CHOBJTYPE_LINEARSERIES, EXC_CHPROPMODE_LINEARSERIES, 0xFFFF, EXC_CHLINEFORMAT_SINGLE, EXC_COLOR_CHWINDOWBACK, EXC_CHFRAMETYPE_AUTO, false, false, false }, | |||
428 | { EXC_CHOBJTYPE_FILLEDSERIES, EXC_CHPROPMODE_FILLEDSERIES, EXC_COLOR_CHBORDERAUTO, EXC_CHLINEFORMAT_SINGLE, 0xFFFF, EXC_CHFRAMETYPE_AUTO, false, false, true }, | |||
429 | { EXC_CHOBJTYPE_AXISLINE, EXC_CHPROPMODE_COMMON, EXC_COLOR_CHWINDOWTEXT, EXC_CHLINEFORMAT_HAIR, EXC_COLOR_CHWINDOWBACK, EXC_CHFRAMETYPE_AUTO, false, false, false }, | |||
430 | { EXC_CHOBJTYPE_GRIDLINE, EXC_CHPROPMODE_COMMON, EXC_COLOR_CHWINDOWTEXT, EXC_CHLINEFORMAT_HAIR, EXC_COLOR_CHWINDOWBACK, EXC_CHFRAMETYPE_INVISIBLE, false, true, false }, | |||
431 | { EXC_CHOBJTYPE_TRENDLINE, EXC_CHPROPMODE_COMMON, EXC_COLOR_CHWINDOWTEXT, EXC_CHLINEFORMAT_DOUBLE, EXC_COLOR_CHWINDOWBACK, EXC_CHFRAMETYPE_INVISIBLE, false, false, false }, | |||
432 | { EXC_CHOBJTYPE_ERRORBAR, EXC_CHPROPMODE_COMMON, EXC_COLOR_CHWINDOWTEXT, EXC_CHLINEFORMAT_SINGLE, EXC_COLOR_CHWINDOWBACK, EXC_CHFRAMETYPE_INVISIBLE, false, false, false }, | |||
433 | { EXC_CHOBJTYPE_CONNECTLINE, EXC_CHPROPMODE_COMMON, EXC_COLOR_CHWINDOWTEXT, EXC_CHLINEFORMAT_HAIR, EXC_COLOR_CHWINDOWBACK, EXC_CHFRAMETYPE_INVISIBLE, false, false, false }, | |||
434 | { EXC_CHOBJTYPE_HILOLINE, EXC_CHPROPMODE_LINEARSERIES, EXC_COLOR_CHWINDOWTEXT, EXC_CHLINEFORMAT_HAIR, EXC_COLOR_CHWINDOWBACK, EXC_CHFRAMETYPE_INVISIBLE, false, false, false }, | |||
435 | { EXC_CHOBJTYPE_WHITEDROPBAR, EXC_CHPROPMODE_COMMON, EXC_COLOR_CHWINDOWTEXT, EXC_CHLINEFORMAT_HAIR, EXC_COLOR_CHWINDOWBACK, EXC_CHFRAMETYPE_INVISIBLE, false, false, true }, | |||
436 | { EXC_CHOBJTYPE_BLACKDROPBAR, EXC_CHPROPMODE_COMMON, EXC_COLOR_CHWINDOWTEXT, EXC_CHLINEFORMAT_HAIR, EXC_COLOR_CHWINDOWTEXT, EXC_CHFRAMETYPE_INVISIBLE, false, false, true } | |||
437 | }; | |||
438 | ||||
439 | } | |||
440 | ||||
441 | XclChFormatInfoProvider::XclChFormatInfoProvider() | |||
442 | { | |||
443 | for(auto const &rIt : spFmtInfos) | |||
444 | maInfoMap[ rIt.meObjType ] = &rIt; | |||
445 | } | |||
446 | ||||
447 | const XclChFormatInfo& XclChFormatInfoProvider::GetFormatInfo( XclChObjectType eObjType ) const | |||
448 | { | |||
449 | XclFmtInfoMap::const_iterator aIt = maInfoMap.find( eObjType ); | |||
450 | OSL_ENSURE( aIt != maInfoMap.end(), "XclChFormatInfoProvider::GetFormatInfo - unknown object type" )do { if (true && (!(aIt != maInfoMap.end()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "450" ": "), "%s", "XclChFormatInfoProvider::GetFormatInfo - unknown object type" ); } } while (false); | |||
451 | return (aIt == maInfoMap.end()) ? *spFmtInfos : *aIt->second; | |||
452 | } | |||
453 | ||||
454 | // Chart type info provider =================================================== | |||
455 | ||||
456 | namespace { | |||
457 | ||||
458 | // chart type service names | |||
459 | const char SERVICE_CHART2_AREA[] = "com.sun.star.chart2.AreaChartType"; | |||
460 | const char SERVICE_CHART2_CANDLE[] = "com.sun.star.chart2.CandleStickChartType"; | |||
461 | const char SERVICE_CHART2_COLUMN[] = "com.sun.star.chart2.ColumnChartType"; | |||
462 | const char SERVICE_CHART2_LINE[] = "com.sun.star.chart2.LineChartType"; | |||
463 | const char SERVICE_CHART2_NET[] = "com.sun.star.chart2.NetChartType"; | |||
464 | const char SERVICE_CHART2_FILLEDNET[] = "com.sun.star.chart2.FilledNetChartType"; | |||
465 | const char SERVICE_CHART2_PIE[] = "com.sun.star.chart2.PieChartType"; | |||
466 | const char SERVICE_CHART2_SCATTER[] = "com.sun.star.chart2.ScatterChartType"; | |||
467 | const char SERVICE_CHART2_BUBBLE[] = "com.sun.star.chart2.BubbleChartType"; | |||
468 | const char SERVICE_CHART2_SURFACE[] = "com.sun.star.chart2.ColumnChartType"; // Todo | |||
469 | ||||
470 | namespace csscd = css::chart::DataLabelPlacement; | |||
471 | ||||
472 | const XclChTypeInfo spTypeInfos[] = | |||
473 | { | |||
474 | // chart type chart type category record id service varied point color def label pos comb2d 3d polar area2d area3d 1stvis xcateg swap stack revers betw | |||
475 | { EXC_CHTYPEID_BAR, EXC_CHTYPECATEG_BAR, EXC_ID_CHBAR, SERVICE_CHART2_COLUMN, EXC_CHVARPOINT_SINGLE, csscd::OUTSIDE, true, true, false, true, true, false, true, false, true, false, true }, | |||
476 | { EXC_CHTYPEID_HORBAR, EXC_CHTYPECATEG_BAR, EXC_ID_CHBAR, SERVICE_CHART2_COLUMN, EXC_CHVARPOINT_SINGLE, csscd::OUTSIDE, false, true, false, true, true, false, true, true, true, false, true }, | |||
477 | { EXC_CHTYPEID_LINE, EXC_CHTYPECATEG_LINE, EXC_ID_CHLINE, SERVICE_CHART2_LINE, EXC_CHVARPOINT_SINGLE, csscd::RIGHT, true, true, false, false, true, false, true, false, true, false, false }, | |||
478 | { EXC_CHTYPEID_AREA, EXC_CHTYPECATEG_LINE, EXC_ID_CHAREA, SERVICE_CHART2_AREA, EXC_CHVARPOINT_NONE, csscd::CENTER, true, true, false, true, true, false, true, false, true, true, false }, | |||
479 | { EXC_CHTYPEID_STOCK, EXC_CHTYPECATEG_LINE, EXC_ID_CHLINE, SERVICE_CHART2_CANDLE, EXC_CHVARPOINT_NONE, csscd::RIGHT, true, false, false, false, false, false, true, false, true, false, false }, | |||
480 | { EXC_CHTYPEID_RADARLINE, EXC_CHTYPECATEG_RADAR, EXC_ID_CHRADARLINE, SERVICE_CHART2_NET, EXC_CHVARPOINT_SINGLE, csscd::TOP, false, false, true, false, true, false, true, false, false, false, false }, | |||
481 | { EXC_CHTYPEID_RADARAREA, EXC_CHTYPECATEG_RADAR, EXC_ID_CHRADARAREA, SERVICE_CHART2_FILLEDNET, EXC_CHVARPOINT_NONE, csscd::TOP, false, false, true, true, true, false, true, false, false, true, false }, | |||
482 | { EXC_CHTYPEID_PIE, EXC_CHTYPECATEG_PIE, EXC_ID_CHPIE, SERVICE_CHART2_PIE, EXC_CHVARPOINT_MULTI, csscd::AVOID_OVERLAP, false, true, true, true, true, true, true, false, false, false, false }, | |||
483 | { EXC_CHTYPEID_DONUT, EXC_CHTYPECATEG_PIE, EXC_ID_CHPIE, SERVICE_CHART2_PIE, EXC_CHVARPOINT_MULTI, csscd::AVOID_OVERLAP, false, true, true, true, true, false, true, false, false, false, false }, | |||
484 | { EXC_CHTYPEID_PIEEXT, EXC_CHTYPECATEG_PIE, EXC_ID_CHPIEEXT, SERVICE_CHART2_PIE, EXC_CHVARPOINT_MULTI, csscd::AVOID_OVERLAP, false, false, true, true, true, true, true, false, false, false, false }, | |||
485 | { EXC_CHTYPEID_SCATTER, EXC_CHTYPECATEG_SCATTER, EXC_ID_CHSCATTER, SERVICE_CHART2_SCATTER, EXC_CHVARPOINT_SINGLE, csscd::RIGHT, true, false, false, false, true, false, false, false, false, false, false }, | |||
486 | { EXC_CHTYPEID_BUBBLES, EXC_CHTYPECATEG_SCATTER, EXC_ID_CHSCATTER, SERVICE_CHART2_BUBBLE, EXC_CHVARPOINT_SINGLE, csscd::RIGHT, false, false, false, true, true, false, false, false, false, false, false }, | |||
487 | { EXC_CHTYPEID_SURFACE, EXC_CHTYPECATEG_SURFACE, EXC_ID_CHSURFACE, SERVICE_CHART2_SURFACE, EXC_CHVARPOINT_NONE, csscd::RIGHT, false, true, false, true, true, false, true, false, false, false, false }, | |||
488 | { EXC_CHTYPEID_UNKNOWN, EXC_CHTYPECATEG_BAR, EXC_ID_CHBAR, SERVICE_CHART2_COLUMN, EXC_CHVARPOINT_SINGLE, csscd::OUTSIDE, true, true, false, true, true, false, true, false, true, false, true } | |||
489 | }; | |||
490 | ||||
491 | } // namespace | |||
492 | ||||
493 | XclChExtTypeInfo::XclChExtTypeInfo( const XclChTypeInfo& rTypeInfo ) : | |||
494 | XclChTypeInfo( rTypeInfo ), | |||
495 | mb3dChart( false ), | |||
496 | mbSpline( false ) | |||
497 | { | |||
498 | } | |||
499 | ||||
500 | void XclChExtTypeInfo::Set( const XclChTypeInfo& rTypeInfo, bool b3dChart, bool bSpline ) | |||
501 | { | |||
502 | static_cast< XclChTypeInfo& >( *this ) = rTypeInfo; | |||
503 | mb3dChart = mbSupports3d && b3dChart; | |||
504 | mbSpline = bSpline; | |||
505 | } | |||
506 | ||||
507 | XclChTypeInfoProvider::XclChTypeInfoProvider() | |||
508 | { | |||
509 | for(const auto &rIt : spTypeInfos) | |||
510 | maInfoMap[ rIt.meTypeId ] = &rIt; | |||
511 | } | |||
512 | ||||
513 | const XclChTypeInfo& XclChTypeInfoProvider::GetTypeInfo( XclChTypeId eTypeId ) const | |||
514 | { | |||
515 | XclChTypeInfoMap::const_iterator aIt = maInfoMap.find( eTypeId ); | |||
516 | OSL_ENSURE( aIt != maInfoMap.end(), "XclChTypeInfoProvider::GetTypeInfo - unknown chart type" )do { if (true && (!(aIt != maInfoMap.end()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "516" ": "), "%s", "XclChTypeInfoProvider::GetTypeInfo - unknown chart type" ); } } while (false); | |||
517 | return (aIt == maInfoMap.end()) ? *maInfoMap.rbegin()->second : *aIt->second; | |||
518 | } | |||
519 | ||||
520 | const XclChTypeInfo& XclChTypeInfoProvider::GetTypeInfoFromRecId( sal_uInt16 nRecId ) const | |||
521 | { | |||
522 | for(const auto &rIt : spTypeInfos) | |||
523 | { | |||
524 | if(rIt.mnRecId == nRecId) | |||
525 | return rIt; | |||
526 | } | |||
527 | OSL_FAIL( "XclChTypeInfoProvider::GetTypeInfoFromRecId - unknown record id" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "527" ": "), "%s", "XclChTypeInfoProvider::GetTypeInfoFromRecId - unknown record id" ); } } while (false); | |||
528 | return GetTypeInfo( EXC_CHTYPEID_UNKNOWN ); | |||
529 | } | |||
530 | ||||
531 | const XclChTypeInfo& XclChTypeInfoProvider::GetTypeInfoFromService( const OUString& rServiceName ) const | |||
532 | { | |||
533 | for(auto const &rIt : spTypeInfos) | |||
534 | if( rServiceName.equalsAscii( rIt.mpcServiceName ) ) | |||
535 | return rIt; | |||
536 | OSL_FAIL( "XclChTypeInfoProvider::GetTypeInfoFromService - unknown service name" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "536" ": "), "%s", "XclChTypeInfoProvider::GetTypeInfoFromService - unknown service name" ); } } while (false); | |||
537 | return GetTypeInfo( EXC_CHTYPEID_UNKNOWN ); | |||
538 | } | |||
539 | ||||
540 | // Property helpers =========================================================== | |||
541 | ||||
542 | XclChObjectTable::XclChObjectTable(uno::Reference<lang::XMultiServiceFactory> const & xFactory, | |||
543 | const OUString& rServiceName, const OUString& rObjNameBase ) : | |||
544 | mxFactory( xFactory ), | |||
545 | maServiceName( rServiceName ), | |||
546 | maObjNameBase( rObjNameBase ), | |||
547 | mnIndex( 0 ) | |||
548 | { | |||
549 | } | |||
550 | ||||
551 | uno::Any XclChObjectTable::GetObject( const OUString& rObjName ) | |||
552 | { | |||
553 | // get object table | |||
554 | if( !mxContainer.is() ) | |||
555 | mxContainer.set(ScfApiHelper::CreateInstance( mxFactory, maServiceName ), uno::UNO_QUERY); | |||
556 | OSL_ENSURE( mxContainer.is(), "XclChObjectTable::GetObject - container not found" )do { if (true && (!(mxContainer.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "556" ": "), "%s", "XclChObjectTable::GetObject - container not found" ); } } while (false); | |||
557 | ||||
558 | uno::Any aObj; | |||
559 | if( mxContainer.is() ) | |||
560 | { | |||
561 | // get object from container | |||
562 | try | |||
563 | { | |||
564 | aObj = mxContainer->getByName( rObjName ); | |||
565 | } | |||
566 | catch (uno::Exception &) | |||
567 | { | |||
568 | OSL_FAIL( "XclChObjectTable::GetObject - object not found" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "568" ": "), "%s", "XclChObjectTable::GetObject - object not found" ); } } while (false); | |||
569 | } | |||
570 | } | |||
571 | return aObj; | |||
572 | } | |||
573 | ||||
574 | OUString XclChObjectTable::InsertObject(const uno::Any& rObj) | |||
575 | { | |||
576 | ||||
577 | // create object table | |||
578 | if( !mxContainer.is() ) | |||
579 | mxContainer.set(ScfApiHelper::CreateInstance( mxFactory, maServiceName ), uno::UNO_QUERY); | |||
580 | OSL_ENSURE( mxContainer.is(), "XclChObjectTable::InsertObject - container not found" )do { if (true && (!(mxContainer.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "580" ": "), "%s", "XclChObjectTable::InsertObject - container not found" ); } } while (false); | |||
581 | ||||
582 | OUString aObjName; | |||
583 | if( mxContainer.is() ) | |||
584 | { | |||
585 | // create new unused identifier | |||
586 | do | |||
587 | { | |||
588 | aObjName = maObjNameBase + OUString::number( ++mnIndex ); | |||
589 | } | |||
590 | while( mxContainer->hasByName( aObjName ) ); | |||
591 | ||||
592 | // insert object | |||
593 | try | |||
594 | { | |||
595 | mxContainer->insertByName( aObjName, rObj ); | |||
596 | } | |||
597 | catch (uno::Exception &) | |||
598 | { | |||
599 | OSL_FAIL( "XclChObjectTable::InsertObject - cannot insert object" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "599" ": "), "%s", "XclChObjectTable::InsertObject - cannot insert object" ); } } while (false); | |||
600 | aObjName.clear(); | |||
601 | } | |||
602 | } | |||
603 | return aObjName; | |||
604 | } | |||
605 | ||||
606 | // Property names ------------------------------------------------------------- | |||
607 | ||||
608 | namespace { | |||
609 | ||||
610 | /** Property names for line style in common objects. */ | |||
611 | const char* const sppcLineNamesCommon[] = | |||
612 | { "LineStyle", "LineWidth", "LineColor", "LineTransparence", "LineDashName", nullptr }; | |||
613 | /** Property names for line style in linear series objects. */ | |||
614 | const char* const sppcLineNamesLinear[] = | |||
615 | { "LineStyle", "LineWidth", "Color", "Transparency", "LineDashName", nullptr }; | |||
616 | /** Property names for line style in filled series objects. */ | |||
617 | const char* const sppcLineNamesFilled[] = | |||
618 | { "BorderStyle", "BorderWidth", "BorderColor", "BorderTransparency", "BorderDashName", nullptr }; | |||
619 | ||||
620 | /** Property names for solid area style in common objects. */ | |||
621 | const char* const sppcAreaNamesCommon[] = { "FillStyle", "FillColor", "FillTransparence", nullptr }; | |||
622 | /** Property names for solid area style in filled series objects. */ | |||
623 | const char* const sppcAreaNamesFilled[] = { "FillStyle", "Color", "Transparency", nullptr }; | |||
624 | /** Property names for gradient area style in common objects. */ | |||
625 | const char* const sppcGradNamesCommon[] = { "FillStyle", "FillGradientName", nullptr }; | |||
626 | /** Property names for gradient area style in filled series objects. */ | |||
627 | const char* const sppcGradNamesFilled[] = { "FillStyle", "GradientName", nullptr }; | |||
628 | /** Property names for hatch area style in common objects. */ | |||
629 | const char* const sppcHatchNamesCommon[] = { "FillStyle", "FillHatchName", "FillColor", "FillBackground", nullptr }; | |||
630 | /** Property names for hatch area style in filled series objects. */ | |||
631 | const char* const sppcHatchNamesFilled[] = { "FillStyle", "HatchName", "Color", "FillBackground", nullptr }; | |||
632 | /** Property names for bitmap area style. */ | |||
633 | const char* const sppcBitmapNames[] = { "FillStyle", "FillBitmapName", "FillBitmapMode", nullptr }; | |||
634 | ||||
635 | } // namespace | |||
636 | ||||
637 | XclChPropSetHelper::XclChPropSetHelper() : | |||
638 | maLineHlpCommon( sppcLineNamesCommon ), | |||
639 | maLineHlpLinear( sppcLineNamesLinear ), | |||
640 | maLineHlpFilled( sppcLineNamesFilled ), | |||
641 | maAreaHlpCommon( sppcAreaNamesCommon ), | |||
642 | maAreaHlpFilled( sppcAreaNamesFilled ), | |||
643 | maGradHlpCommon( sppcGradNamesCommon ), | |||
644 | maGradHlpFilled( sppcGradNamesFilled ), | |||
645 | maHatchHlpCommon( sppcHatchNamesCommon ), | |||
646 | maHatchHlpFilled( sppcHatchNamesFilled ), | |||
647 | maBitmapHlp( sppcBitmapNames ) | |||
648 | { | |||
649 | } | |||
650 | ||||
651 | // read properties ------------------------------------------------------------ | |||
652 | ||||
653 | void XclChPropSetHelper::ReadLineProperties( | |||
654 | XclChLineFormat& rLineFmt, XclChObjectTable& rDashTable, | |||
655 | const ScfPropertySet& rPropSet, XclChPropertyMode ePropMode ) | |||
656 | { | |||
657 | // read properties from property set | |||
658 | drawing::LineStyle eApiStyle = drawing::LineStyle_NONE; | |||
659 | sal_Int32 nApiWidth = 0; | |||
660 | sal_Int16 nApiTrans = 0; | |||
661 | uno::Any aDashNameAny; | |||
662 | ||||
663 | ScfPropSetHelper& rLineHlp = GetLineHelper( ePropMode ); | |||
664 | rLineHlp.ReadFromPropertySet( rPropSet ); | |||
665 | rLineHlp >> eApiStyle >> nApiWidth >> rLineFmt.maColor >> nApiTrans >> aDashNameAny; | |||
666 | ||||
667 | // clear automatic flag | |||
668 | ::set_flag( rLineFmt.mnFlags, EXC_CHLINEFORMAT_AUTO, false ); | |||
669 | ||||
670 | // line width | |||
671 | if( nApiWidth <= 0 ) rLineFmt.mnWeight = EXC_CHLINEFORMAT_HAIR; | |||
672 | else if( nApiWidth <= 35 ) rLineFmt.mnWeight = EXC_CHLINEFORMAT_SINGLE; | |||
673 | else if( nApiWidth <= 70 ) rLineFmt.mnWeight = EXC_CHLINEFORMAT_DOUBLE; | |||
674 | else rLineFmt.mnWeight = EXC_CHLINEFORMAT_TRIPLE; | |||
675 | ||||
676 | // line style | |||
677 | switch( eApiStyle ) | |||
678 | { | |||
679 | case drawing::LineStyle_NONE: | |||
680 | rLineFmt.mnPattern = EXC_CHLINEFORMAT_NONE; | |||
681 | break; | |||
682 | case drawing::LineStyle_SOLID: | |||
683 | { | |||
684 | if( nApiTrans < 13 ) rLineFmt.mnPattern = EXC_CHLINEFORMAT_SOLID; | |||
685 | else if( nApiTrans < 38 ) rLineFmt.mnPattern = EXC_CHLINEFORMAT_DARKTRANS; | |||
686 | else if( nApiTrans < 63 ) rLineFmt.mnPattern = EXC_CHLINEFORMAT_MEDTRANS; | |||
687 | else if( nApiTrans < 100 ) rLineFmt.mnPattern = EXC_CHLINEFORMAT_LIGHTTRANS; | |||
688 | else rLineFmt.mnPattern = EXC_CHLINEFORMAT_NONE; | |||
689 | } | |||
690 | break; | |||
691 | case drawing::LineStyle_DASH: | |||
692 | { | |||
693 | rLineFmt.mnPattern = EXC_CHLINEFORMAT_SOLID; | |||
694 | OUString aDashName; | |||
695 | drawing::LineDash aApiDash; | |||
696 | if( (aDashNameAny >>= aDashName) && (rDashTable.GetObject( aDashName ) >>= aApiDash) ) | |||
697 | { | |||
698 | // reorder dashes that are shorter than dots | |||
699 | if( (aApiDash.Dashes == 0) || (aApiDash.DashLen < aApiDash.DotLen) ) | |||
700 | { | |||
701 | ::std::swap( aApiDash.Dashes, aApiDash.Dots ); | |||
702 | ::std::swap( aApiDash.DashLen, aApiDash.DotLen ); | |||
703 | } | |||
704 | // ignore dots that are nearly equal to dashes | |||
705 | if( aApiDash.DotLen * 3 > aApiDash.DashLen * 2 ) | |||
706 | aApiDash.Dots = 0; | |||
707 | ||||
708 | // convert line dash to predefined Excel dash types | |||
709 | if( (aApiDash.Dashes == 1) && (aApiDash.Dots >= 1) ) | |||
710 | // one dash and one or more dots | |||
711 | rLineFmt.mnPattern = (aApiDash.Dots == 1) ? | |||
712 | EXC_CHLINEFORMAT_DASHDOT : EXC_CHLINEFORMAT_DASHDOTDOT; | |||
713 | else if( aApiDash.Dashes >= 1 ) | |||
714 | // one or more dashes and no dots (also: dash-dash-dot) | |||
715 | rLineFmt.mnPattern = (aApiDash.DashLen < 250) ? | |||
716 | EXC_CHLINEFORMAT_DOT : EXC_CHLINEFORMAT_DASH; | |||
717 | } | |||
718 | } | |||
719 | break; | |||
720 | default: | |||
721 | OSL_FAIL( "XclChPropSetHelper::ReadLineProperties - unknown line style" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "721" ": "), "%s", "XclChPropSetHelper::ReadLineProperties - unknown line style" ); } } while (false); | |||
722 | rLineFmt.mnPattern = EXC_CHLINEFORMAT_SOLID; | |||
723 | } | |||
724 | } | |||
725 | ||||
726 | bool XclChPropSetHelper::ReadAreaProperties( XclChAreaFormat& rAreaFmt, | |||
727 | const ScfPropertySet& rPropSet, XclChPropertyMode ePropMode ) | |||
728 | { | |||
729 | // read properties from property set | |||
730 | drawing::FillStyle eApiStyle = drawing::FillStyle_NONE; | |||
731 | sal_Int16 nTransparency = 0; | |||
732 | ||||
733 | ScfPropSetHelper& rAreaHlp = GetAreaHelper( ePropMode ); | |||
734 | rAreaHlp.ReadFromPropertySet( rPropSet ); | |||
735 | rAreaHlp >> eApiStyle >> rAreaFmt.maPattColor >> nTransparency; | |||
736 | ||||
737 | // clear automatic flag | |||
738 | ::set_flag( rAreaFmt.mnFlags, EXC_CHAREAFORMAT_AUTO, false ); | |||
739 | ||||
740 | // set fill style transparent or solid (set solid for anything but transparent) | |||
741 | rAreaFmt.mnPattern = (eApiStyle == drawing::FillStyle_NONE) ? EXC_PATT_NONE : EXC_PATT_SOLID; | |||
742 | ||||
743 | // return true to indicate complex fill (gradient, bitmap, solid transparency) | |||
744 | return (eApiStyle != drawing::FillStyle_NONE) && ((eApiStyle != drawing::FillStyle_SOLID) || (nTransparency > 0)); | |||
745 | } | |||
746 | ||||
747 | void XclChPropSetHelper::ReadEscherProperties( | |||
748 | XclChEscherFormat& rEscherFmt, XclChPicFormat& rPicFmt, | |||
749 | XclChObjectTable& rGradientTable, XclChObjectTable& rHatchTable, XclChObjectTable& rBitmapTable, | |||
750 | const ScfPropertySet& rPropSet, XclChPropertyMode ePropMode ) | |||
751 | { | |||
752 | // read style and transparency properties from property set | |||
753 | drawing::FillStyle eApiStyle = drawing::FillStyle_NONE; | |||
754 | Color aColor; | |||
755 | sal_Int16 nTransparency = 0; | |||
756 | ||||
757 | ScfPropSetHelper& rAreaHlp = GetAreaHelper( ePropMode ); | |||
758 | rAreaHlp.ReadFromPropertySet( rPropSet ); | |||
759 | rAreaHlp >> eApiStyle >> aColor >> nTransparency; | |||
| ||||
760 | ||||
761 | switch( eApiStyle ) | |||
762 | { | |||
763 | case drawing::FillStyle_SOLID: | |||
764 | { | |||
765 | OSL_ENSURE( nTransparency > 0, "XclChPropSetHelper::ReadEscherProperties - unexpected solid area without transparency" )do { if (true && (!(nTransparency > 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "765" ": "), "%s", "XclChPropSetHelper::ReadEscherProperties - unexpected solid area without transparency" ); } } while (false); | |||
766 | if( (0 < nTransparency) && (nTransparency <= 100) ) | |||
767 | { | |||
768 | // convert to Escher properties | |||
769 | sal_uInt32 nEscherColor = 0x02000000; | |||
770 | ::insert_value( nEscherColor, aColor.GetBlue(), 16, 8 ); | |||
771 | ::insert_value( nEscherColor, aColor.GetGreen(), 8, 8 ); | |||
772 | ::insert_value( nEscherColor, aColor.GetRed(), 0, 8 ); | |||
773 | sal_uInt32 nEscherOpacity = static_cast< sal_uInt32 >( (100 - nTransparency) * 655.36 ); | |||
774 | rEscherFmt.mxEscherSet = std::make_shared<EscherPropertyContainer>(); | |||
775 | rEscherFmt.mxEscherSet->AddOpt( ESCHER_Prop_fillType384, ESCHER_FillSolid ); | |||
776 | rEscherFmt.mxEscherSet->AddOpt( ESCHER_Prop_fillColor385, nEscherColor ); | |||
777 | rEscherFmt.mxEscherSet->AddOpt( ESCHER_Prop_fillOpacity386, nEscherOpacity ); | |||
778 | rEscherFmt.mxEscherSet->AddOpt( ESCHER_Prop_fillBackColor387, 0x02FFFFFF ); | |||
779 | rEscherFmt.mxEscherSet->AddOpt( ESCHER_Prop_fillBackOpacity388, 0x00010000 ); | |||
780 | rEscherFmt.mxEscherSet->AddOpt( ESCHER_Prop_fNoFillHitTest447, 0x001F001C ); | |||
781 | } | |||
782 | } | |||
783 | break; | |||
784 | case drawing::FillStyle_GRADIENT: | |||
785 | { | |||
786 | // extract gradient from global gradient table | |||
787 | OUString aGradientName; | |||
788 | ScfPropSetHelper& rGradHlp = GetGradientHelper( ePropMode ); | |||
789 | rGradHlp.ReadFromPropertySet( rPropSet ); | |||
790 | rGradHlp >> eApiStyle >> aGradientName; | |||
791 | awt::Gradient aGradient; | |||
792 | if( rGradientTable.GetObject( aGradientName ) >>= aGradient ) | |||
793 | { | |||
794 | // convert to Escher properties | |||
795 | rEscherFmt.mxEscherSet = std::make_shared<EscherPropertyContainer>(); | |||
796 | rEscherFmt.mxEscherSet->CreateGradientProperties( aGradient ); | |||
797 | } | |||
798 | } | |||
799 | break; | |||
800 | case drawing::FillStyle_HATCH: | |||
801 | { | |||
802 | // extract hatch from global hatch table | |||
803 | OUString aHatchName; | |||
804 | bool bFillBackground; | |||
805 | ScfPropSetHelper& rHatchHlp = GetHatchHelper( ePropMode ); | |||
806 | rHatchHlp.ReadFromPropertySet( rPropSet ); | |||
807 | rHatchHlp >> eApiStyle >> aHatchName >> aColor >> bFillBackground; | |||
808 | drawing::Hatch aHatch; | |||
809 | if( rHatchTable.GetObject( aHatchName ) >>= aHatch ) | |||
810 | { | |||
811 | // convert to Escher properties | |||
812 | rEscherFmt.mxEscherSet = std::make_shared<EscherPropertyContainer>(); | |||
813 | rEscherFmt.mxEscherSet->CreateEmbeddedHatchProperties( aHatch, aColor, bFillBackground ); | |||
814 | rPicFmt.mnBmpMode = EXC_CHPICFORMAT_STACK; | |||
815 | } | |||
816 | } | |||
817 | break; | |||
818 | case drawing::FillStyle_BITMAP: | |||
819 | { | |||
820 | // extract bitmap URL from global bitmap table | |||
821 | OUString aBitmapName; | |||
822 | drawing::BitmapMode eApiBmpMode; | |||
823 | maBitmapHlp.ReadFromPropertySet( rPropSet ); | |||
824 | maBitmapHlp >> eApiStyle >> aBitmapName >> eApiBmpMode; | |||
825 | uno::Reference<awt::XBitmap> xBitmap; | |||
826 | if (rBitmapTable.GetObject( aBitmapName ) >>= xBitmap) | |||
827 | { | |||
828 | // convert to Escher properties | |||
829 | rEscherFmt.mxEscherSet = std::make_shared<EscherPropertyContainer>(); | |||
830 | rEscherFmt.mxEscherSet->CreateEmbeddedBitmapProperties( xBitmap, eApiBmpMode ); | |||
| ||||
831 | rPicFmt.mnBmpMode = (eApiBmpMode == drawing::BitmapMode_REPEAT) ? | |||
832 | EXC_CHPICFORMAT_STACK : EXC_CHPICFORMAT_STRETCH; | |||
833 | } | |||
834 | } | |||
835 | break; | |||
836 | default: | |||
837 | OSL_FAIL( "XclChPropSetHelper::ReadEscherProperties - unknown fill style" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "837" ": "), "%s", "XclChPropSetHelper::ReadEscherProperties - unknown fill style" ); } } while (false); | |||
838 | } | |||
839 | } | |||
840 | ||||
841 | void XclChPropSetHelper::ReadMarkerProperties( | |||
842 | XclChMarkerFormat& rMarkerFmt, const ScfPropertySet& rPropSet, sal_uInt16 nFormatIdx ) | |||
843 | { | |||
844 | chart2::Symbol aApiSymbol; | |||
845 | if( !rPropSet.GetProperty( aApiSymbol, EXC_CHPROP_SYMBOL"Symbol" ) ) | |||
846 | return; | |||
847 | ||||
848 | // clear automatic flag | |||
849 | ::set_flag( rMarkerFmt.mnFlags, EXC_CHMARKERFORMAT_AUTO, false ); | |||
850 | ||||
851 | // symbol style | |||
852 | switch( aApiSymbol.Style ) | |||
853 | { | |||
854 | case chart2::SymbolStyle_NONE: | |||
855 | rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_NOSYMBOL; | |||
856 | break; | |||
857 | case chart2::SymbolStyle_STANDARD: | |||
858 | switch( aApiSymbol.StandardSymbol ) | |||
859 | { | |||
860 | case 0: rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_SQUARE; break; // square | |||
861 | case 1: rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_DIAMOND; break; // diamond | |||
862 | case 2: rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_STDDEV; break; // arrow down | |||
863 | case 3: rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_TRIANGLE; break; // arrow up | |||
864 | case 4: rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_DOWJ; break; // arrow right, same as import | |||
865 | case 5: rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_PLUS; break; // arrow left | |||
866 | case 6: rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_CROSS; break; // bow tie | |||
867 | case 7: rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_STAR; break; // sand glass | |||
868 | case 8: rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_CIRCLE; break; // circle new in LibO3.5 | |||
869 | case 9: rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_DIAMOND; break; // star new in LibO3.5 | |||
870 | case 10: rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_CROSS; break; // X new in LibO3.5 | |||
871 | case 11: rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_PLUS; break; // plus new in LibO3.5 | |||
872 | case 12: rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_STAR; break; // asterisk new in LibO3.5 | |||
873 | case 13: rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_STDDEV; break; // horizontal bar new in LibO3.5 | |||
874 | case 14: rMarkerFmt.mnMarkerType = EXC_CHMARKERFORMAT_STAR; break; // vertical bar new in LibO3.5 | |||
875 | default: rMarkerFmt.mnMarkerType = XclChartHelper::GetAutoMarkerType( nFormatIdx ); | |||
876 | } | |||
877 | break; | |||
878 | default: | |||
879 | rMarkerFmt.mnMarkerType = XclChartHelper::GetAutoMarkerType( nFormatIdx ); | |||
880 | } | |||
881 | bool bHasFillColor = XclChartHelper::HasMarkerFillColor( rMarkerFmt.mnMarkerType ); | |||
882 | ::set_flag( rMarkerFmt.mnFlags, EXC_CHMARKERFORMAT_NOFILL, !bHasFillColor ); | |||
883 | ||||
884 | // symbol size | |||
885 | sal_Int32 nApiSize = (aApiSymbol.Size.Width + aApiSymbol.Size.Height + 1) / 2; | |||
886 | rMarkerFmt.mnMarkerSize = XclTools::GetTwipsFromHmm( nApiSize ); | |||
887 | ||||
888 | // symbol colors | |||
889 | rMarkerFmt.maLineColor = Color( aApiSymbol.BorderColor ); | |||
890 | rMarkerFmt.maFillColor = Color( aApiSymbol.FillColor ); | |||
891 | } | |||
892 | ||||
893 | sal_uInt16 XclChPropSetHelper::ReadRotationProperties( const ScfPropertySet& rPropSet, bool bSupportsStacked ) | |||
894 | { | |||
895 | // chart2 handles rotation as double in the range [0,360) | |||
896 | double fAngle = 0.0; | |||
897 | rPropSet.GetProperty( fAngle, EXC_CHPROP_TEXTROTATION"TextRotation" ); | |||
898 | bool bStacked = bSupportsStacked && rPropSet.GetBoolProperty( EXC_CHPROP_STACKCHARACTERS"StackCharacters" ); | |||
899 | return bStacked ? EXC_ROT_STACKED : | |||
900 | XclTools::GetXclRotation( static_cast< sal_Int32 >( fAngle * 100.0 + 0.5 ) ); | |||
901 | } | |||
902 | ||||
903 | // write properties ----------------------------------------------------------- | |||
904 | ||||
905 | void XclChPropSetHelper::WriteLineProperties( | |||
906 | ScfPropertySet& rPropSet, XclChObjectTable& rDashTable, | |||
907 | const XclChLineFormat& rLineFmt, XclChPropertyMode ePropMode ) | |||
908 | { | |||
909 | // line width | |||
910 | sal_Int32 nApiWidth = 0; // 0 is the width of a hair line | |||
911 | switch( rLineFmt.mnWeight ) | |||
912 | { | |||
913 | case EXC_CHLINEFORMAT_SINGLE: nApiWidth = 35; break; | |||
914 | case EXC_CHLINEFORMAT_DOUBLE: nApiWidth = 70; break; | |||
915 | case EXC_CHLINEFORMAT_TRIPLE: nApiWidth = 105; break; | |||
916 | } | |||
917 | ||||
918 | // line style | |||
919 | drawing::LineStyle eApiStyle = drawing::LineStyle_NONE; | |||
920 | sal_Int16 nApiTrans = 0; | |||
921 | sal_Int32 nDotLen = ::std::min< sal_Int32 >( rLineFmt.mnWeight + 105, 210 ); | |||
922 | drawing::LineDash aApiDash( drawing::DashStyle_RECT, 0, nDotLen, 0, 4 * nDotLen, nDotLen ); | |||
923 | ||||
924 | switch( rLineFmt.mnPattern ) | |||
925 | { | |||
926 | case EXC_CHLINEFORMAT_SOLID: | |||
927 | eApiStyle = drawing::LineStyle_SOLID; | |||
928 | break; | |||
929 | case EXC_CHLINEFORMAT_DARKTRANS: | |||
930 | eApiStyle = drawing::LineStyle_SOLID; nApiTrans = 25; | |||
931 | break; | |||
932 | case EXC_CHLINEFORMAT_MEDTRANS: | |||
933 | eApiStyle = drawing::LineStyle_SOLID; nApiTrans = 50; | |||
934 | break; | |||
935 | case EXC_CHLINEFORMAT_LIGHTTRANS: | |||
936 | eApiStyle = drawing::LineStyle_SOLID; nApiTrans = 75; | |||
937 | break; | |||
938 | case EXC_CHLINEFORMAT_DASH: | |||
939 | eApiStyle = drawing::LineStyle_DASH; aApiDash.Dashes = 1; | |||
940 | break; | |||
941 | case EXC_CHLINEFORMAT_DOT: | |||
942 | eApiStyle = drawing::LineStyle_DASH; aApiDash.Dots = 1; | |||
943 | break; | |||
944 | case EXC_CHLINEFORMAT_DASHDOT: | |||
945 | eApiStyle = drawing::LineStyle_DASH; aApiDash.Dashes = aApiDash.Dots = 1; | |||
946 | break; | |||
947 | case EXC_CHLINEFORMAT_DASHDOTDOT: | |||
948 | eApiStyle = drawing::LineStyle_DASH; aApiDash.Dashes = 1; aApiDash.Dots = 2; | |||
949 | break; | |||
950 | } | |||
951 | ||||
952 | // line color | |||
953 | sal_Int32 nApiColor = sal_Int32( rLineFmt.maColor ); | |||
954 | ||||
955 | // try to insert the dash style and receive its name | |||
956 | uno::Any aDashNameAny; | |||
957 | if( eApiStyle == drawing::LineStyle_DASH ) | |||
958 | { | |||
959 | OUString aDashName = rDashTable.InsertObject( uno::makeAny( aApiDash ) ); | |||
960 | if( !aDashName.isEmpty() ) | |||
961 | aDashNameAny <<= aDashName; | |||
962 | } | |||
963 | ||||
964 | // write the properties | |||
965 | ScfPropSetHelper& rLineHlp = GetLineHelper( ePropMode ); | |||
966 | rLineHlp.InitializeWrite(); | |||
967 | rLineHlp << eApiStyle << nApiWidth << nApiColor << nApiTrans << aDashNameAny; | |||
968 | rLineHlp.WriteToPropertySet( rPropSet ); | |||
969 | } | |||
970 | ||||
971 | void XclChPropSetHelper::WriteAreaProperties( ScfPropertySet& rPropSet, | |||
972 | const XclChAreaFormat& rAreaFmt, XclChPropertyMode ePropMode ) | |||
973 | { | |||
974 | drawing::FillStyle eFillStyle = drawing::FillStyle_NONE; | |||
975 | Color aColor; | |||
976 | ||||
977 | // fill color | |||
978 | if( rAreaFmt.mnPattern != EXC_PATT_NONE ) | |||
979 | { | |||
980 | eFillStyle = drawing::FillStyle_SOLID; | |||
981 | aColor = XclTools::GetPatternColor( rAreaFmt.maPattColor, rAreaFmt.maBackColor, rAreaFmt.mnPattern ); | |||
982 | } | |||
983 | ||||
984 | // write the properties | |||
985 | ScfPropSetHelper& rAreaHlp = GetAreaHelper( ePropMode ); | |||
986 | rAreaHlp.InitializeWrite(); | |||
987 | rAreaHlp << eFillStyle << aColor << sal_Int16(0)/*nTransparency*/; | |||
988 | rAreaHlp.WriteToPropertySet( rPropSet ); | |||
989 | } | |||
990 | ||||
991 | void XclChPropSetHelper::WriteEscherProperties( ScfPropertySet& rPropSet, | |||
992 | XclChObjectTable& rGradientTable, XclChObjectTable& rBitmapTable, | |||
993 | const XclChEscherFormat& rEscherFmt, const XclChPicFormat* pPicFmt, | |||
994 | sal_uInt32 nDffFillType, XclChPropertyMode ePropMode ) | |||
995 | { | |||
996 | if( !rEscherFmt.mxItemSet ) | |||
997 | return; | |||
998 | ||||
999 | const XFillStyleItem* pStyleItem = rEscherFmt.mxItemSet->GetItem<XFillStyleItem>( XATTR_FILLSTYLE, false ); | |||
1000 | if( !pStyleItem ) | |||
1001 | return; | |||
1002 | ||||
1003 | switch( pStyleItem->GetValue() ) | |||
1004 | { | |||
1005 | case drawing::FillStyle_SOLID: | |||
1006 | // #i84812# Excel 2007 writes Escher properties for solid fill | |||
1007 | if( const XFillColorItem* pColorItem = rEscherFmt.mxItemSet->GetItem<XFillColorItem>( XATTR_FILLCOLOR, false ) ) | |||
1008 | { | |||
1009 | // get solid transparence too | |||
1010 | const XFillTransparenceItem* pTranspItem = rEscherFmt.mxItemSet->GetItem<XFillTransparenceItem>( XATTR_FILLTRANSPARENCE, false ); | |||
1011 | sal_uInt16 nTransp = pTranspItem ? pTranspItem->GetValue() : 0; | |||
1012 | ScfPropSetHelper& rAreaHlp = GetAreaHelper( ePropMode ); | |||
1013 | rAreaHlp.InitializeWrite(); | |||
1014 | rAreaHlp << drawing::FillStyle_SOLID << pColorItem->GetColorValue() << static_cast< sal_Int16 >( nTransp ); | |||
1015 | rAreaHlp.WriteToPropertySet( rPropSet ); | |||
1016 | } | |||
1017 | break; | |||
1018 | case drawing::FillStyle_GRADIENT: | |||
1019 | if( const XFillGradientItem* pGradItem = rEscherFmt.mxItemSet->GetItem<XFillGradientItem>( XATTR_FILLGRADIENT, false ) ) | |||
1020 | { | |||
1021 | uno::Any aGradientAny; | |||
1022 | if( pGradItem->QueryValue( aGradientAny, MID_FILLGRADIENT1 ) ) | |||
1023 | { | |||
1024 | OUString aGradName = rGradientTable.InsertObject( aGradientAny ); | |||
1025 | if( !aGradName.isEmpty() ) | |||
1026 | { | |||
1027 | ScfPropSetHelper& rGradHlp = GetGradientHelper( ePropMode ); | |||
1028 | rGradHlp.InitializeWrite(); | |||
1029 | rGradHlp << drawing::FillStyle_GRADIENT << aGradName; | |||
1030 | rGradHlp.WriteToPropertySet( rPropSet ); | |||
1031 | } | |||
1032 | } | |||
1033 | } | |||
1034 | break; | |||
1035 | case drawing::FillStyle_BITMAP: | |||
1036 | if( const XFillBitmapItem* pBmpItem = rEscherFmt.mxItemSet->GetItem<XFillBitmapItem>( XATTR_FILLBITMAP, false ) ) | |||
1037 | { | |||
1038 | uno::Any aBitmapAny; | |||
1039 | if (pBmpItem->QueryValue(aBitmapAny, MID_BITMAP8)) | |||
1040 | { | |||
1041 | OUString aBmpName = rBitmapTable.InsertObject( aBitmapAny ); | |||
1042 | if( !aBmpName.isEmpty() ) | |||
1043 | { | |||
1044 | /* #i71810# Caller decides whether to use a CHPICFORMAT record for bitmap mode. | |||
1045 | If not passed, detect fill mode from the DFF property 'fill-type'. */ | |||
1046 | bool bStretch = pPicFmt ? (pPicFmt->mnBmpMode == EXC_CHPICFORMAT_STRETCH) : (nDffFillType == mso_fillPicture); | |||
1047 | drawing::BitmapMode eApiBmpMode = bStretch ? drawing::BitmapMode_STRETCH : drawing::BitmapMode_REPEAT; | |||
1048 | maBitmapHlp.InitializeWrite(); | |||
1049 | maBitmapHlp << drawing::FillStyle_BITMAP << aBmpName << eApiBmpMode; | |||
1050 | maBitmapHlp.WriteToPropertySet( rPropSet ); | |||
1051 | } | |||
1052 | } | |||
1053 | } | |||
1054 | break; | |||
1055 | default: | |||
1056 | OSL_FAIL( "XclChPropSetHelper::WriteEscherProperties - unknown fill mode" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "1056" ": "), "%s", "XclChPropSetHelper::WriteEscherProperties - unknown fill mode" ); } } while (false); | |||
1057 | } | |||
1058 | } | |||
1059 | ||||
1060 | void XclChPropSetHelper::WriteMarkerProperties( | |||
1061 | ScfPropertySet& rPropSet, const XclChMarkerFormat& rMarkerFmt ) | |||
1062 | { | |||
1063 | // symbol style | |||
1064 | chart2::Symbol aApiSymbol; | |||
1065 | aApiSymbol.Style = chart2::SymbolStyle_STANDARD; | |||
1066 | switch( rMarkerFmt.mnMarkerType ) | |||
1067 | { | |||
1068 | case EXC_CHMARKERFORMAT_NOSYMBOL: aApiSymbol.Style = chart2::SymbolStyle_NONE; break; | |||
1069 | case EXC_CHMARKERFORMAT_SQUARE: aApiSymbol.StandardSymbol = 0; break; // square | |||
1070 | case EXC_CHMARKERFORMAT_DIAMOND: aApiSymbol.StandardSymbol = 1; break; // diamond | |||
1071 | case EXC_CHMARKERFORMAT_TRIANGLE: aApiSymbol.StandardSymbol = 3; break; // arrow up | |||
1072 | case EXC_CHMARKERFORMAT_CROSS: aApiSymbol.StandardSymbol = 10; break; // X, legacy bow tie | |||
1073 | case EXC_CHMARKERFORMAT_STAR: aApiSymbol.StandardSymbol = 12; break; // asterisk, legacy sand glass | |||
1074 | case EXC_CHMARKERFORMAT_DOWJ: aApiSymbol.StandardSymbol = 4; break; // arrow right, same as export | |||
1075 | case EXC_CHMARKERFORMAT_STDDEV: aApiSymbol.StandardSymbol = 13; break; // horizontal bar, legacy arrow down | |||
1076 | case EXC_CHMARKERFORMAT_CIRCLE: aApiSymbol.StandardSymbol = 8; break; // circle, legacy arrow right | |||
1077 | case EXC_CHMARKERFORMAT_PLUS: aApiSymbol.StandardSymbol = 11; break; // plus, legacy arrow left | |||
1078 | default: break; | |||
1079 | } | |||
1080 | ||||
1081 | // symbol size | |||
1082 | sal_Int32 nApiSize = XclTools::GetHmmFromTwips( rMarkerFmt.mnMarkerSize ); | |||
1083 | aApiSymbol.Size = awt::Size( nApiSize, nApiSize ); | |||
1084 | ||||
1085 | // symbol colors | |||
1086 | aApiSymbol.FillColor = sal_Int32( rMarkerFmt.maFillColor ); | |||
1087 | aApiSymbol.BorderColor = ::get_flag( rMarkerFmt.mnFlags, EXC_CHMARKERFORMAT_NOLINE ) ? | |||
1088 | aApiSymbol.FillColor : sal_Int32( rMarkerFmt.maLineColor ); | |||
1089 | ||||
1090 | // set the property | |||
1091 | rPropSet.SetProperty( EXC_CHPROP_SYMBOL"Symbol", aApiSymbol ); | |||
1092 | } | |||
1093 | ||||
1094 | void XclChPropSetHelper::WriteRotationProperties( | |||
1095 | ScfPropertySet& rPropSet, sal_uInt16 nRotation, bool bSupportsStacked ) | |||
1096 | { | |||
1097 | if( nRotation != EXC_CHART_AUTOROTATION ) | |||
1098 | { | |||
1099 | // chart2 handles rotation as double in the range [0,360) | |||
1100 | double fAngle = XclTools::GetScRotation( nRotation, 0 ) / 100.0; | |||
1101 | rPropSet.SetProperty( EXC_CHPROP_TEXTROTATION"TextRotation", fAngle ); | |||
1102 | if( bSupportsStacked ) | |||
1103 | rPropSet.SetProperty( EXC_CHPROP_STACKCHARACTERS"StackCharacters", nRotation == EXC_ROT_STACKED ); | |||
1104 | } | |||
1105 | } | |||
1106 | ||||
1107 | // private -------------------------------------------------------------------- | |||
1108 | ||||
1109 | ScfPropSetHelper& XclChPropSetHelper::GetLineHelper( XclChPropertyMode ePropMode ) | |||
1110 | { | |||
1111 | switch( ePropMode ) | |||
1112 | { | |||
1113 | case EXC_CHPROPMODE_COMMON: return maLineHlpCommon; | |||
1114 | case EXC_CHPROPMODE_LINEARSERIES: return maLineHlpLinear; | |||
1115 | case EXC_CHPROPMODE_FILLEDSERIES: return maLineHlpFilled; | |||
1116 | default: OSL_FAIL( "XclChPropSetHelper::GetLineHelper - unknown property mode" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "1116" ": "), "%s", "XclChPropSetHelper::GetLineHelper - unknown property mode" ); } } while (false); | |||
1117 | } | |||
1118 | return maLineHlpCommon; | |||
1119 | } | |||
1120 | ||||
1121 | ScfPropSetHelper& XclChPropSetHelper::GetAreaHelper( XclChPropertyMode ePropMode ) | |||
1122 | { | |||
1123 | switch( ePropMode ) | |||
1124 | { | |||
1125 | case EXC_CHPROPMODE_COMMON: return maAreaHlpCommon; | |||
1126 | case EXC_CHPROPMODE_FILLEDSERIES: return maAreaHlpFilled; | |||
1127 | default: OSL_FAIL( "XclChPropSetHelper::GetAreaHelper - unknown property mode" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "1127" ": "), "%s", "XclChPropSetHelper::GetAreaHelper - unknown property mode" ); } } while (false); | |||
1128 | } | |||
1129 | return maAreaHlpCommon; | |||
1130 | } | |||
1131 | ||||
1132 | ScfPropSetHelper& XclChPropSetHelper::GetGradientHelper( XclChPropertyMode ePropMode ) | |||
1133 | { | |||
1134 | switch( ePropMode ) | |||
1135 | { | |||
1136 | case EXC_CHPROPMODE_COMMON: return maGradHlpCommon; | |||
1137 | case EXC_CHPROPMODE_FILLEDSERIES: return maGradHlpFilled; | |||
1138 | default: OSL_FAIL( "XclChPropSetHelper::GetGradientHelper - unknown property mode" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "1138" ": "), "%s", "XclChPropSetHelper::GetGradientHelper - unknown property mode" ); } } while (false); | |||
1139 | } | |||
1140 | return maGradHlpCommon; | |||
1141 | } | |||
1142 | ||||
1143 | ScfPropSetHelper& XclChPropSetHelper::GetHatchHelper( XclChPropertyMode ePropMode ) | |||
1144 | { | |||
1145 | switch( ePropMode ) | |||
1146 | { | |||
1147 | case EXC_CHPROPMODE_COMMON: return maHatchHlpCommon; | |||
1148 | case EXC_CHPROPMODE_FILLEDSERIES: return maHatchHlpFilled; | |||
1149 | default: OSL_FAIL( "XclChPropSetHelper::GetHatchHelper - unknown property mode" )do { if (true && (((sal_Bool)1))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "1149" ": "), "%s", "XclChPropSetHelper::GetHatchHelper - unknown property mode" ); } } while (false); | |||
1150 | } | |||
1151 | return maHatchHlpCommon; | |||
1152 | } | |||
1153 | ||||
1154 | namespace { | |||
1155 | ||||
1156 | /* The following local functions implement getting the XShape interface of all | |||
1157 | supported title objects (chart and axes). This needs some effort due to the | |||
1158 | design of the old Chart1 API used to access these objects. */ | |||
1159 | ||||
1160 | /** Returns the drawing shape of the main title, if existing. */ | |||
1161 | uno::Reference<drawing::XShape> lclGetMainTitleShape(const uno::Reference<chart::XChartDocument> & rxChart1Doc) | |||
1162 | { | |||
1163 | ScfPropertySet aPropSet(rxChart1Doc); | |||
1164 | if (rxChart1Doc.is() && aPropSet.GetBoolProperty("HasMainTitle")) | |||
1165 | return rxChart1Doc->getTitle(); | |||
1166 | return uno::Reference<drawing::XShape>(); | |||
1167 | } | |||
1168 | ||||
1169 | uno::Reference<drawing::XShape> lclGetXAxisTitleShape(const uno::Reference<chart::XChartDocument> & rxChart1Doc) | |||
1170 | { | |||
1171 | uno::Reference<chart::XAxisXSupplier> xAxisSupp(rxChart1Doc->getDiagram(), uno::UNO_QUERY); | |||
1172 | ScfPropertySet aPropSet(xAxisSupp); | |||
1173 | if (xAxisSupp.is() && aPropSet.GetBoolProperty("HasXAxisTitle")) | |||
1174 | return xAxisSupp->getXAxisTitle(); | |||
1175 | return uno::Reference<drawing::XShape>(); | |||
1176 | } | |||
1177 | ||||
1178 | uno::Reference<drawing::XShape> lclGetYAxisTitleShape(const uno::Reference<chart::XChartDocument> & rxChart1Doc ) | |||
1179 | { | |||
1180 | uno::Reference<chart::XAxisYSupplier> xAxisSupp(rxChart1Doc->getDiagram(), uno::UNO_QUERY); | |||
1181 | ScfPropertySet aPropSet(xAxisSupp); | |||
1182 | if (xAxisSupp.is() && aPropSet.GetBoolProperty("HasYAxisTitle")) | |||
1183 | return xAxisSupp->getYAxisTitle(); | |||
1184 | return uno::Reference<drawing::XShape>(); | |||
1185 | } | |||
1186 | ||||
1187 | uno::Reference<drawing::XShape> lclGetZAxisTitleShape(const uno::Reference<chart::XChartDocument> & rxChart1Doc ) | |||
1188 | { | |||
1189 | uno::Reference<chart::XAxisZSupplier> xAxisSupp(rxChart1Doc->getDiagram(), uno::UNO_QUERY); | |||
1190 | ScfPropertySet aPropSet(xAxisSupp); | |||
1191 | if (xAxisSupp.is() && aPropSet.GetBoolProperty("HasZAxisTitle")) | |||
1192 | return xAxisSupp->getZAxisTitle(); | |||
1193 | return uno::Reference<drawing::XShape>(); | |||
1194 | } | |||
1195 | ||||
1196 | uno::Reference<drawing::XShape> lclGetSecXAxisTitleShape(const uno::Reference<chart::XChartDocument> & rxChart1Doc) | |||
1197 | { | |||
1198 | uno::Reference<chart::XSecondAxisTitleSupplier> xAxisSupp(rxChart1Doc->getDiagram(), uno::UNO_QUERY); | |||
1199 | ScfPropertySet aPropSet(xAxisSupp); | |||
1200 | if (xAxisSupp.is() && aPropSet.GetBoolProperty("HasSecondaryXAxisTitle")) | |||
1201 | return xAxisSupp->getSecondXAxisTitle(); | |||
1202 | return uno::Reference<drawing::XShape>(); | |||
1203 | } | |||
1204 | ||||
1205 | uno::Reference<drawing::XShape> lclGetSecYAxisTitleShape(const uno::Reference<chart::XChartDocument> & rxChart1Doc) | |||
1206 | { | |||
1207 | uno::Reference<chart::XSecondAxisTitleSupplier> xAxisSupp(rxChart1Doc->getDiagram(), uno::UNO_QUERY); | |||
1208 | ScfPropertySet aPropSet(xAxisSupp); | |||
1209 | if (xAxisSupp.is() && aPropSet.GetBoolProperty("HasSecondaryYAxisTitle")) | |||
1210 | return xAxisSupp->getSecondYAxisTitle(); | |||
1211 | return uno::Reference<drawing::XShape>(); | |||
1212 | } | |||
1213 | ||||
1214 | } // namespace | |||
1215 | ||||
1216 | XclChRootData::XclChRootData() | |||
1217 | : mxTypeInfoProv(std::make_shared<XclChTypeInfoProvider>()) | |||
1218 | , mxFmtInfoProv(std::make_shared<XclChFormatInfoProvider>()) | |||
1219 | , mnBorderGapX(0) | |||
1220 | , mnBorderGapY(0) | |||
1221 | , mfUnitSizeX(0.0) | |||
1222 | , mfUnitSizeY(0.0) | |||
1223 | { | |||
1224 | // remember some title shape getter functions | |||
1225 | maGetShapeFuncs[ XclChTextKey( EXC_CHTEXTTYPE_TITLE ) ] = lclGetMainTitleShape; | |||
1226 | maGetShapeFuncs[ XclChTextKey( EXC_CHTEXTTYPE_AXISTITLE, EXC_CHAXESSET_PRIMARY, EXC_CHAXIS_X ) ] = lclGetXAxisTitleShape; | |||
1227 | maGetShapeFuncs[ XclChTextKey( EXC_CHTEXTTYPE_AXISTITLE, EXC_CHAXESSET_PRIMARY, EXC_CHAXIS_Y ) ] = lclGetYAxisTitleShape; | |||
1228 | maGetShapeFuncs[ XclChTextKey( EXC_CHTEXTTYPE_AXISTITLE, EXC_CHAXESSET_PRIMARY, EXC_CHAXIS_Z ) ] = lclGetZAxisTitleShape; | |||
1229 | maGetShapeFuncs[ XclChTextKey( EXC_CHTEXTTYPE_AXISTITLE, EXC_CHAXESSET_SECONDARY, EXC_CHAXIS_X ) ] = lclGetSecXAxisTitleShape; | |||
1230 | maGetShapeFuncs[ XclChTextKey( EXC_CHTEXTTYPE_AXISTITLE, EXC_CHAXESSET_SECONDARY, EXC_CHAXIS_Y ) ] = lclGetSecYAxisTitleShape; | |||
1231 | } | |||
1232 | ||||
1233 | XclChRootData::~XclChRootData() | |||
1234 | { | |||
1235 | } | |||
1236 | ||||
1237 | void XclChRootData::InitConversion(const XclRoot& rRoot, const uno::Reference<chart2::XChartDocument> & rxChartDoc, const tools::Rectangle& rChartRect) | |||
1238 | { | |||
1239 | // remember chart document reference and chart shape position/size | |||
1240 | OSL_ENSURE( rxChartDoc.is(), "XclChRootData::InitConversion - missing chart document" )do { if (true && (!(rxChartDoc.is()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "1240" ": "), "%s", "XclChRootData::InitConversion - missing chart document" ); } } while (false); | |||
1241 | mxChartDoc = rxChartDoc; | |||
1242 | maChartRect = rChartRect; | |||
1243 | ||||
1244 | // Excel excludes a border of 5 pixels in each direction from chart area | |||
1245 | mnBorderGapX = rRoot.GetHmmFromPixelX( 5.0 ); | |||
1246 | mnBorderGapY = rRoot.GetHmmFromPixelY( 5.0 ); | |||
1247 | ||||
1248 | // size of a chart unit in 1/100 mm | |||
1249 | mfUnitSizeX = std::max<double>( maChartRect.GetWidth() - 2 * mnBorderGapX, mnBorderGapX ) / EXC_CHART_TOTALUNITS; | |||
1250 | mfUnitSizeY = std::max<double>( maChartRect.GetHeight() - 2 * mnBorderGapY, mnBorderGapY ) / EXC_CHART_TOTALUNITS; | |||
1251 | ||||
1252 | // create object tables | |||
1253 | uno::Reference<lang::XMultiServiceFactory> xFactory(mxChartDoc, uno::UNO_QUERY); | |||
1254 | mxLineDashTable = std::make_shared<XclChObjectTable>(xFactory, SERVICE_DRAWING_DASHTABLE"com.sun.star.drawing.DashTable", "Excel line dash "); | |||
1255 | mxGradientTable = std::make_shared<XclChObjectTable>(xFactory, SERVICE_DRAWING_GRADIENTTABLE"com.sun.star.drawing.GradientTable", "Excel gradient "); | |||
1256 | mxHatchTable = std::make_shared<XclChObjectTable>(xFactory, SERVICE_DRAWING_HATCHTABLE"com.sun.star.drawing.HatchTable", "Excel hatch "); | |||
1257 | mxBitmapTable = std::make_shared<XclChObjectTable>(xFactory, SERVICE_DRAWING_BITMAPTABLE"com.sun.star.drawing.BitmapTable", "Excel bitmap "); | |||
1258 | } | |||
1259 | ||||
1260 | void XclChRootData::FinishConversion() | |||
1261 | { | |||
1262 | // forget formatting object tables | |||
1263 | mxBitmapTable.reset(); | |||
1264 | mxHatchTable.reset(); | |||
1265 | mxGradientTable.reset(); | |||
1266 | mxLineDashTable.reset(); | |||
1267 | // forget chart document reference | |||
1268 | mxChartDoc.clear(); | |||
1269 | } | |||
1270 | ||||
1271 | uno::Reference<drawing::XShape> XclChRootData::GetTitleShape(const XclChTextKey& rTitleKey) const | |||
1272 | { | |||
1273 | XclChGetShapeFuncMap::const_iterator aIt = maGetShapeFuncs.find( rTitleKey ); | |||
1274 | OSL_ENSURE( aIt != maGetShapeFuncs.end(), "XclChRootData::GetTitleShape - invalid title key" )do { if (true && (!(aIt != maGetShapeFuncs.end()))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/home/maarten/src/libreoffice/core/sc/source/filter/excel/xlchart.cxx" ":" "1274" ": "), "%s", "XclChRootData::GetTitleShape - invalid title key" ); } } while (false); | |||
1275 | uno::Reference<chart::XChartDocument> xChart1Doc( mxChartDoc, uno::UNO_QUERY ); | |||
1276 | uno::Reference<drawing::XShape> xTitleShape; | |||
1277 | if (xChart1Doc.is() && (aIt != maGetShapeFuncs.end())) | |||
1278 | xTitleShape = (aIt->second)(xChart1Doc); | |||
1279 | return xTitleShape; | |||
1280 | } | |||
1281 | ||||
1282 | /* 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_SC_SOURCE_FILTER_INC_FAPIHELPER_HXX |
21 | #define INCLUDED_SC_SOURCE_FILTER_INC_FAPIHELPER_HXX |
22 | |
23 | #include <com/sun/star/uno/Any.hxx> |
24 | #include <com/sun/star/uno/Reference.hxx> |
25 | #include <com/sun/star/uno/Sequence.hxx> |
26 | #include <osl/diagnose.h> |
27 | #include <tools/color.hxx> |
28 | #include "ftools.hxx" |
29 | |
30 | namespace com::sun::star { |
31 | namespace lang { class XMultiServiceFactory; } |
32 | } |
33 | |
34 | namespace com::sun::star::beans { struct NamedValue; } |
35 | namespace com::sun::star::beans { class XPropertySet; } |
36 | namespace com::sun::star::beans { class XMultiPropertySet; } |
37 | |
38 | namespace comphelper { class IDocPasswordVerifier; } |
39 | |
40 | // Static helper functions ==================================================== |
41 | |
42 | class SfxMedium; |
43 | class SfxObjectShell; |
44 | |
45 | /** Static API helper functions. */ |
46 | class ScfApiHelper |
47 | { |
48 | public: |
49 | /** Converts a non-empty vector into a UNO sequence containing elements of the same type. */ |
50 | template< typename Type > |
51 | static css::uno::Sequence< Type > |
52 | VectorToSequence( const ::std::vector< Type >& rVector ); |
53 | |
54 | /** Returns the service name provided via the XServiceName interface, or an empty string on error. */ |
55 | static OUString GetServiceName( const css::uno::Reference< css::uno::XInterface >& xInt ); |
56 | |
57 | /** Returns the multi service factory from a document shell. */ |
58 | static css::uno::Reference< css::lang::XMultiServiceFactory > GetServiceFactory( const SfxObjectShell* pShell ); |
59 | |
60 | /** Creates an instance from the passed service name, using the passed service factory. */ |
61 | static css::uno::Reference< css::uno::XInterface > CreateInstance( |
62 | const css::uno::Reference< css::lang::XMultiServiceFactory >& xFactory, |
63 | const OUString& rServiceName ); |
64 | |
65 | /** Creates an instance from the passed service name, using the service factory of the passed object. */ |
66 | static css::uno::Reference< css::uno::XInterface > CreateInstance( |
67 | const SfxObjectShell* pShell, |
68 | const OUString& rServiceName ); |
69 | |
70 | /** Creates an instance from the passed service name, using the process service factory. */ |
71 | static css::uno::Reference< css::uno::XInterface > CreateInstance( const OUString& rServiceName ); |
72 | |
73 | /** Opens a password dialog and returns the encryption data. |
74 | @return The encryption data or an empty sequence on 'Cancel' or any error. */ |
75 | static css::uno::Sequence< css::beans::NamedValue > QueryEncryptionDataForMedium( SfxMedium& rMedium, |
76 | ::comphelper::IDocPasswordVerifier& rVerifier, |
77 | const ::std::vector< OUString >* pDefaultPasswords ); |
78 | }; |
79 | |
80 | template< typename Type > |
81 | css::uno::Sequence< Type > ScfApiHelper::VectorToSequence( const ::std::vector< Type >& rVector ) |
82 | { |
83 | OSL_ENSURE( !rVector.empty(), "ScfApiHelper::VectorToSequence - vector is empty" )do { if (true && (!(!rVector.empty()))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/home/maarten/src/libreoffice/core/sc/source/filter/inc/fapihelper.hxx" ":" "83" ": "), "%s", "ScfApiHelper::VectorToSequence - vector is empty" ); } } while (false); |
84 | return css::uno::Sequence<Type>(rVector.data(), static_cast< sal_Int32 >(rVector.size())); |
85 | } |
86 | |
87 | // Property sets ============================================================== |
88 | |
89 | /** A wrapper for a UNO property set. |
90 | |
91 | This class provides functions to silently get and set properties (without |
92 | exceptions, without the need to check validity of the UNO property set). |
93 | |
94 | An instance is constructed with the reference to a UNO property set or any |
95 | other interface (the constructor will query for the XPropertySet interface |
96 | then). The reference to the property set will be kept as long as the |
97 | instance of this class is alive. |
98 | |
99 | The functions GetProperties() and SetProperties() try to handle all passed |
100 | values at once, using the XMultiPropertySet interface. If the |
101 | implementation does not support the XMultiPropertySet interface, all |
102 | properties are handled separately in a loop. |
103 | */ |
104 | class ScfPropertySet |
105 | { |
106 | public: |
107 | explicit ScfPropertySet() {} |
108 | /** Constructs a property set wrapper with the passed UNO property set. */ |
109 | explicit ScfPropertySet( const css::uno::Reference< css::beans::XPropertySet > & xPropSet ) { Set( xPropSet ); } |
110 | /** Constructs a property set wrapper after querying the XPropertySet interface. */ |
111 | template< typename InterfaceType > |
112 | explicit ScfPropertySet( const css::uno::Reference< InterfaceType >& xInterface ) { Set( xInterface ); } |
113 | |
114 | ~ScfPropertySet(); |
115 | //TODO: |
116 | ScfPropertySet(ScfPropertySet const &) = default; |
117 | ScfPropertySet(ScfPropertySet &&) = default; |
118 | ScfPropertySet & operator =(ScfPropertySet const &) = default; |
119 | ScfPropertySet & operator =(ScfPropertySet &&) = default; |
120 | |
121 | /** Sets the passed UNO property set and releases the old UNO property set. */ |
122 | void Set( css::uno::Reference< css::beans::XPropertySet > const & xPropSet ); |
123 | /** Queries the passed interface for an XPropertySet and releases the old UNO property set. */ |
124 | template< typename InterfaceType > |
125 | void Set( css::uno::Reference< InterfaceType > xInterface ) |
126 | { Set( css::uno::Reference< css::beans::XPropertySet >( xInterface, css::uno::UNO_QUERY ) ); } |
127 | |
128 | /** Returns true, if the contained XPropertySet interface is valid. */ |
129 | bool Is() const { return mxPropSet.is(); } |
130 | |
131 | /** Returns the contained XPropertySet interface. */ |
132 | const css::uno::Reference< css::beans::XPropertySet >& GetApiPropertySet() const { return mxPropSet; } |
133 | |
134 | /** Returns the service name provided via the XServiceName interface, or an empty string on error. */ |
135 | OUString GetServiceName() const; |
136 | |
137 | // Get properties --------------------------------------------------------- |
138 | |
139 | /** Returns true, if the property set contains the specified property. */ |
140 | bool HasProperty( const OUString& rPropName ) const; |
141 | |
142 | /** Gets the specified property from the property set. |
143 | @return true, if the Any could be filled with the property value. */ |
144 | bool GetAnyProperty( css::uno::Any& rValue, const OUString& rPropName ) const; |
145 | |
146 | /** Gets the specified property from the property set. |
147 | @return true, if the passed variable could be filled with the property value. */ |
148 | template< typename Type > |
149 | bool GetProperty( Type& rValue, const OUString& rPropName ) const |
150 | { css::uno::Any aAny; return GetAnyProperty( aAny, rPropName ) && (aAny >>= rValue); } |
151 | |
152 | /** Gets the specified Boolean property from the property set. |
153 | @return true = property contains true; false = property contains false or error occurred. */ |
154 | bool GetBoolProperty( const OUString& rPropName ) const; |
155 | |
156 | /** Gets the specified Boolean property from the property set. */ |
157 | OUString GetStringProperty( const OUString& rPropName ) const; |
158 | |
159 | /** Gets the specified color property from the property set. |
160 | @return true, if the passed color variable could be filled with the property value. */ |
161 | bool GetColorProperty( Color& rColor, const OUString& rPropName ) const; |
162 | |
163 | /** Gets the specified properties from the property set. Tries to use the XMultiPropertySet interface. |
164 | @param rPropNames The property names. MUST be ordered alphabetically. |
165 | @param rValues The related property values. */ |
166 | void GetProperties( css::uno::Sequence< css::uno::Any >& rValues, const css::uno::Sequence< OUString >& rPropNames ) const; |
167 | |
168 | // Set properties --------------------------------------------------------- |
169 | |
170 | /** Puts the passed Any into the property set. */ |
171 | void SetAnyProperty( const OUString& rPropName, const css::uno::Any& rValue ); |
172 | |
173 | /** Puts the passed value into the property set. */ |
174 | template< typename Type > |
175 | void SetProperty( const OUString& rPropName, const Type& rValue ) |
176 | { SetAnyProperty( rPropName, css::uno::makeAny( rValue ) ); } |
177 | |
178 | /** Puts the passed Boolean value into the property set. */ |
179 | void SetBoolProperty( const OUString& rPropName, bool bValue ) |
180 | { SetAnyProperty( rPropName, css::uno::Any( bValue ) ); } |
181 | |
182 | /** Puts the passed string into the property set. */ |
183 | void SetStringProperty( const OUString& rPropName, const OUString& rValue ) |
184 | { SetProperty( rPropName, rValue ); } |
185 | |
186 | /** Puts the passed color into the property set. */ |
187 | void SetColorProperty( const OUString& rPropName, const Color& rColor ) |
188 | { SetProperty( rPropName, sal_Int32( rColor ) ); } |
189 | |
190 | /** Puts the passed properties into the property set. Tries to use the XMultiPropertySet interface. |
191 | @param rPropNames The property names. MUST be ordered alphabetically. |
192 | @param rValues The related property values. */ |
193 | void SetProperties( const css::uno::Sequence< OUString > & rPropNames, const css::uno::Sequence< css::uno::Any >& rValues ); |
194 | |
195 | private: |
196 | css::uno::Reference< css::beans::XPropertySet > mxPropSet; /// The mandatory property set interface. |
197 | css::uno::Reference< css::beans::XMultiPropertySet > mxMultiPropSet; /// The optional multi property set interface. |
198 | }; |
199 | |
200 | /** Generic helper class for reading from and writing to property sets. |
201 | |
202 | Usage: |
203 | 1) Call the constructor with a null-terminated array of ASCII strings. |
204 | 2a) Read properties from a property set: Call the ReadFromPropertySet() |
205 | function, then get the properties with the ReadValue() functions or the |
206 | operator>> stream operator. The properties are returned in order of the |
207 | array of property names passed in the constructor. |
208 | 2b) Write properties to a property set: Call InitializeWrite() to start a |
209 | new cycle. Set the values with the WriteValue() functions or the |
210 | operator<< stream operator. The order of the properties is equal to the |
211 | array of property names passed in the constructor. Finally, call the |
212 | WriteToPropertySet() function. |
213 | */ |
214 | class ScfPropSetHelper |
215 | { |
216 | public: |
217 | /** @param ppPropNames A null-terminated array of ASCII property names. */ |
218 | explicit ScfPropSetHelper( const char* const* ppcPropNames ); |
219 | |
220 | // read properties -------------------------------------------------------- |
221 | |
222 | /** Reads all values from the passed property set. */ |
223 | void ReadFromPropertySet( const ScfPropertySet& rPropSet ); |
224 | |
225 | /** Reads the next value from the value sequence. */ |
226 | template< typename Type > |
227 | void ReadValue( Type& rValue ); |
228 | /** Reads an Any from the value sequence. */ |
229 | void ReadValue( css::uno::Any& rAny ); |
230 | /** Reads a color value from the value sequence. */ |
231 | void ReadValue( Color& rColor ); |
232 | /** Reads a C++ boolean value from the value sequence. */ |
233 | void ReadValue( bool& rbValue ); |
234 | |
235 | // write properties ------------------------------------------------------- |
236 | |
237 | /** Must be called before reading or storing property values in the helper. */ |
238 | void InitializeWrite(); |
239 | |
240 | /** Writes the next value to the value sequence. */ |
241 | template< typename Type > |
242 | void WriteValue( const Type& rValue ); |
243 | /** Writes an Any to the value sequence. */ |
244 | void WriteValue( const css::uno::Any& rAny ); |
245 | /** Writes a color value to the value sequence. */ |
246 | void WriteValue( const Color& rColor ) |
247 | { WriteValue( sal_Int32( rColor ) ); } |
248 | /** Writes a C++ boolean value to the value sequence. */ |
249 | void WriteValue( bool rbValue ); |
250 | |
251 | /** Writes all values to the passed property set. */ |
252 | void WriteToPropertySet( ScfPropertySet& rPropSet ) const; |
253 | |
254 | private: |
255 | /** Returns a pointer to the next Any to be written to. */ |
256 | css::uno::Any* GetNextAny(); |
257 | |
258 | private: |
259 | css::uno::Sequence< OUString > maNameSeq; /// Sequence of property names. |
260 | css::uno::Sequence< css::uno::Any > maValueSeq; /// Sequence of property values. |
261 | ScfInt32Vec maNameOrder; /// Maps initial order to alphabetical order. |
262 | size_t mnNextIdx; /// Counter for next Any to be processed. |
263 | }; |
264 | |
265 | template< typename Type > |
266 | void ScfPropSetHelper::ReadValue( Type& rValue ) |
267 | { |
268 | css::uno::Any* pAny = GetNextAny(); |
269 | if (pAny) |
270 | *pAny >>= rValue; |
271 | } |
272 | |
273 | template< typename Type > |
274 | void ScfPropSetHelper::WriteValue( const Type& rValue ) |
275 | { |
276 | css::uno::Any* pAny = GetNextAny(); |
277 | if( pAny ) |
278 | *pAny <<= rValue; |
279 | } |
280 | |
281 | template< typename Type > |
282 | ScfPropSetHelper& operator>>( ScfPropSetHelper& rPropSetHelper, Type& rValue ) |
283 | { |
284 | rPropSetHelper.ReadValue( rValue ); |
285 | return rPropSetHelper; |
286 | } |
287 | |
288 | template< typename Type > |
289 | ScfPropSetHelper& operator<<( ScfPropSetHelper& rPropSetHelper, const Type& rValue ) |
290 | { |
291 | rPropSetHelper.WriteValue( rValue ); |
292 | return rPropSetHelper; |
293 | } |
294 | |
295 | #endif |
296 | |
297 | /* 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_ANY_HXX |
20 | #define INCLUDED_COM_SUN_STAR_UNO_ANY_HXX |
21 | |
22 | #include "sal/config.h" |
23 | |
24 | #include <algorithm> |
25 | #include <cassert> |
26 | #include <cstddef> |
27 | #include <iomanip> |
28 | #include <ostream> |
29 | #include <utility> |
30 | |
31 | #include "com/sun/star/uno/Any.h" |
32 | #include "uno/data.h" |
33 | #include "uno/sequence2.h" |
34 | #include "com/sun/star/uno/Type.hxx" |
35 | #include "com/sun/star/uno/Reference.h" |
36 | #include "com/sun/star/uno/genfunc.hxx" |
37 | #include "com/sun/star/uno/RuntimeException.hpp" |
38 | #include "cppu/cppudllapi.h" |
39 | #include "cppu/unotype.hxx" |
40 | |
41 | extern "C" CPPU_DLLPUBLIC__attribute__ ((visibility("default"))) rtl_uString * SAL_CALL cppu_Any_extraction_failure_msg( |
42 | uno_Any const * pAny, typelib_TypeDescriptionReference * pType ) |
43 | SAL_THROW_EXTERN_C()throw (); |
44 | |
45 | namespace com |
46 | { |
47 | namespace sun |
48 | { |
49 | namespace star |
50 | { |
51 | namespace uno |
52 | { |
53 | |
54 | |
55 | inline Any::Any() |
56 | { |
57 | ::uno_any_construct( this, NULL__null, NULL__null, cpp_acquire ); |
58 | } |
59 | |
60 | |
61 | template <typename T> |
62 | inline Any::Any( T const & value ) |
63 | { |
64 | ::uno_type_any_construct( |
65 | this, const_cast<T *>(&value), |
66 | ::cppu::getTypeFavourUnsigned(&value).getTypeLibType(), |
67 | cpp_acquire ); |
68 | } |
69 | |
70 | inline Any::Any( bool value ) |
71 | { |
72 | sal_Bool b = value; |
73 | ::uno_type_any_construct( |
74 | this, &b, cppu::UnoType<bool>::get().getTypeLibType(), |
75 | cpp_acquire ); |
76 | } |
77 | |
78 | #if defined LIBO_INTERNAL_ONLY1 |
79 | template<typename T1, typename T2> |
80 | Any::Any(rtl::OUStringConcat<T1, T2> && value): |
81 | Any(rtl::OUString(std::move(value))) |
82 | {} |
83 | #endif |
84 | |
85 | inline Any::Any( const Any & rAny ) |
86 | { |
87 | ::uno_type_any_construct( this, rAny.pData, rAny.pType, cpp_acquire ); |
88 | } |
89 | |
90 | inline Any::Any( const void * pData_, const Type & rType ) |
91 | { |
92 | ::uno_type_any_construct( |
93 | this, const_cast< void * >( pData_ ), rType.getTypeLibType(), |
94 | cpp_acquire ); |
95 | } |
96 | |
97 | inline Any::Any( const void * pData_, typelib_TypeDescription * pTypeDescr ) |
98 | { |
99 | ::uno_any_construct( |
100 | this, const_cast< void * >( pData_ ), pTypeDescr, cpp_acquire ); |
101 | } |
102 | |
103 | inline Any::Any( const void * pData_, typelib_TypeDescriptionReference * pType_ ) |
104 | { |
105 | ::uno_type_any_construct( |
106 | this, const_cast< void * >( pData_ ), pType_, cpp_acquire ); |
107 | } |
108 | |
109 | inline Any::~Any() |
110 | { |
111 | ::uno_any_destruct( |
112 | this, cpp_release ); |
113 | } |
114 | |
115 | inline Any & Any::operator = ( const Any & rAny ) |
116 | { |
117 | if (this != &rAny) |
118 | { |
119 | ::uno_type_any_assign( |
120 | this, rAny.pData, rAny.pType, |
121 | cpp_acquire, cpp_release ); |
122 | } |
123 | return *this; |
124 | } |
125 | |
126 | #if defined LIBO_INTERNAL_ONLY1 |
127 | |
128 | namespace detail { |
129 | |
130 | inline void moveAnyInternals(Any & from, Any & to) noexcept { |
131 | uno_any_construct(&to, nullptr, nullptr, &cpp_acquire); |
132 | std::swap(from.pType, to.pType); |
133 | std::swap(from.pData, to.pData); |
134 | std::swap(from.pReserved, to.pReserved); |
135 | if (to.pData == &from.pReserved) { |
136 | to.pData = &to.pReserved; |
137 | } |
138 | // This leaves from.pData (where "from" is now VOID) dangling to somewhere (cf. |
139 | // CONSTRUCT_EMPTY_ANY, cppu/source/uno/prim.hxx), but what's relevant is |
140 | // only that it isn't a nullptr (as e.g. >>= -> uno_type_assignData -> |
141 | // _assignData takes a null pSource to mean "construct a default value"). |
142 | } |
143 | |
144 | } |
145 | |
146 | Any::Any(Any && other) noexcept { |
147 | detail::moveAnyInternals(other, *this); |
148 | } |
149 | |
150 | Any & Any::operator =(Any && other) noexcept { |
151 | uno_any_destruct(this, &cpp_release); |
152 | detail::moveAnyInternals(other, *this); |
153 | return *this; |
154 | } |
155 | |
156 | #endif |
157 | |
158 | inline ::rtl::OUString Any::getValueTypeName() const |
159 | { |
160 | return ::rtl::OUString( pType->pTypeName ); |
161 | } |
162 | |
163 | inline void Any::setValue( const void * pData_, const Type & rType ) |
164 | { |
165 | ::uno_type_any_assign( |
166 | this, const_cast< void * >( pData_ ), rType.getTypeLibType(), |
167 | cpp_acquire, cpp_release ); |
168 | } |
169 | |
170 | inline void Any::setValue( const void * pData_, typelib_TypeDescriptionReference * pType_ ) |
171 | { |
172 | ::uno_type_any_assign( |
173 | this, const_cast< void * >( pData_ ), pType_, |
174 | cpp_acquire, cpp_release ); |
175 | } |
176 | |
177 | inline void Any::setValue( const void * pData_, typelib_TypeDescription * pTypeDescr ) |
178 | { |
179 | ::uno_any_assign( |
180 | this, const_cast< void * >( pData_ ), pTypeDescr, |
181 | cpp_acquire, cpp_release ); |
182 | } |
183 | |
184 | inline void Any::clear() |
185 | { |
186 | ::uno_any_clear( |
187 | this, cpp_release ); |
188 | } |
189 | |
190 | inline bool Any::isExtractableTo( const Type & rType ) const |
191 | { |
192 | return ::uno_type_isAssignableFromData( |
193 | rType.getTypeLibType(), pData, pType, |
194 | cpp_queryInterface, cpp_release ); |
195 | } |
196 | |
197 | |
198 | template <typename T> |
199 | inline bool Any::has() const |
200 | { |
201 | Type const & rType = ::cppu::getTypeFavourUnsigned(static_cast< T * >(0)); |
202 | return ::uno_type_isAssignableFromData( |
203 | rType.getTypeLibType(), pData, pType, |
204 | cpp_queryInterface, |
205 | cpp_release ); |
206 | } |
207 | |
208 | #if defined LIBO_INTERNAL_ONLY1 |
209 | template<> bool Any::has<Any>() const = delete; |
210 | #endif |
211 | |
212 | inline bool Any::operator == ( const Any & rAny ) const |
213 | { |
214 | return ::uno_type_equalData( |
215 | pData, pType, rAny.pData, rAny.pType, |
216 | cpp_queryInterface, cpp_release ); |
217 | } |
218 | |
219 | inline bool Any::operator != ( const Any & rAny ) const |
220 | { |
221 | return (! ::uno_type_equalData( |
222 | pData, pType, rAny.pData, rAny.pType, |
223 | cpp_queryInterface, cpp_release )); |
224 | } |
225 | |
226 | |
227 | template< class C > |
228 | inline Any SAL_CALL makeAny( const C & value ) |
229 | { |
230 | return Any(value); |
231 | } |
232 | |
233 | #if !defined LIBO_INTERNAL_ONLY1 |
234 | template<> Any makeAny(sal_uInt16 const & value) |
235 | { return Any(&value, cppu::UnoType<cppu::UnoUnsignedShortType>::get()); } |
236 | #endif |
237 | |
238 | template<typename T> Any toAny(T const & value) { return makeAny(value); } |
239 | |
240 | template<> Any toAny(Any const & value) { return value; } |
241 | |
242 | #if defined LIBO_INTERNAL_ONLY1 |
243 | |
244 | template<typename T1, typename T2> |
245 | Any makeAny(rtl::OUStringConcat<T1, T2> && value) |
246 | { return Any(std::move(value)); } |
247 | |
248 | template<typename T1, typename T2> |
249 | Any toAny(rtl::OUStringConcat<T1, T2> && value) |
250 | { return makeAny(std::move(value)); } |
251 | |
252 | template<typename T> |
253 | Any makeAny(rtl::OUStringNumber<T> && value) |
254 | { return Any(OUString(std::move(value))); } |
255 | |
256 | template<typename T> |
257 | Any toAny(rtl::OUStringNumber<T> && value) |
258 | { return makeAny(std::move(value)); } |
259 | |
260 | template<typename T> bool fromAny(Any const & any, T * value) { |
261 | assert(value != nullptr)(static_cast <bool> (value != nullptr) ? void (0) : __assert_fail ("value != nullptr", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Any.hxx" , 261, __extension__ __PRETTY_FUNCTION__)); |
262 | return any >>= *value; |
263 | } |
264 | |
265 | template<> bool fromAny(Any const & any, Any * value) { |
266 | assert(value != nullptr)(static_cast <bool> (value != nullptr) ? void (0) : __assert_fail ("value != nullptr", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Any.hxx" , 266, __extension__ __PRETTY_FUNCTION__)); |
267 | *value = any; |
268 | return true; |
269 | } |
270 | |
271 | #endif |
272 | |
273 | template< class C > |
274 | inline void SAL_CALL operator <<= ( Any & rAny, const C & value ) |
275 | { |
276 | const Type & rType = ::cppu::getTypeFavourUnsigned(&value); |
277 | ::uno_type_any_assign( |
278 | &rAny, const_cast< C * >( &value ), rType.getTypeLibType(), |
279 | cpp_acquire, cpp_release ); |
280 | } |
281 | |
282 | // additionally for C++ bool: |
283 | |
284 | template<> |
285 | inline void SAL_CALL operator <<= ( Any & rAny, bool const & value ) |
286 | { |
287 | sal_Bool b = value; |
288 | ::uno_type_any_assign( |
289 | &rAny, &b, cppu::UnoType<bool>::get().getTypeLibType(), |
290 | cpp_acquire, cpp_release ); |
291 | } |
292 | |
293 | |
294 | #ifdef LIBO_INTERNAL_ONLY1 // "RTL_FAST_STRING" |
295 | template< class C1, class C2 > |
296 | inline void SAL_CALL operator <<= ( Any & rAny, rtl::OUStringConcat< C1, C2 >&& value ) |
297 | { |
298 | const rtl::OUString str( std::move(value) ); |
299 | const Type & rType = ::cppu::getTypeFavourUnsigned(&str); |
300 | ::uno_type_any_assign( |
301 | &rAny, const_cast< rtl::OUString * >( &str ), rType.getTypeLibType(), |
302 | cpp_acquire, cpp_release ); |
303 | } |
304 | template<typename T1, typename T2> |
305 | void operator <<=(Any &, rtl::OUStringConcat<T1, T2> const &) = delete; |
306 | template< class C > |
307 | inline void SAL_CALL operator <<= ( Any & rAny, rtl::OUStringNumber< C >&& value ) |
308 | { |
309 | const rtl::OUString str( std::move(value) ); |
310 | const Type & rType = ::cppu::getTypeFavourUnsigned(&str); |
311 | ::uno_type_any_assign( |
312 | &rAny, const_cast< rtl::OUString * >( &str ), rType.getTypeLibType(), |
313 | cpp_acquire, cpp_release ); |
314 | } |
315 | template<typename T> |
316 | void operator <<=(Any &, rtl::OUStringNumber<T> const &) = delete; |
317 | #endif |
318 | |
319 | #if defined LIBO_INTERNAL_ONLY1 |
320 | template<> void SAL_CALL operator <<=(Any &, Any const &) = delete; |
321 | #endif |
322 | |
323 | template< class C > |
324 | inline bool SAL_CALL operator >>= ( const Any & rAny, C & value ) |
325 | { |
326 | const Type & rType = ::cppu::getTypeFavourUnsigned(&value); |
327 | return ::uno_type_assignData( |
328 | &value, rType.getTypeLibType(), |
329 | rAny.pData, rAny.pType, |
330 | cpp_queryInterface, |
331 | cpp_acquire, cpp_release ); |
332 | } |
333 | |
334 | // bool |
335 | |
336 | template<> |
337 | inline bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Bool & value ) |
338 | { |
339 | if (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass) |
340 | { |
341 | value = bool(* static_cast< const sal_Bool * >( rAny.pData )); |
342 | return true; |
343 | } |
344 | return false; |
345 | } |
346 | |
347 | template<> |
348 | inline bool SAL_CALL operator == ( const Any & rAny, const sal_Bool & value ) |
349 | { |
350 | return (typelib_TypeClass_BOOLEAN == rAny.pType->eTypeClass && |
351 | bool(value) == bool(* static_cast< const sal_Bool * >( rAny.pData ))); |
352 | } |
353 | |
354 | |
355 | template<> |
356 | inline bool SAL_CALL operator >>= ( Any const & rAny, bool & value ) |
357 | { |
358 | if (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN) |
359 | { |
360 | value = *static_cast< sal_Bool const * >( rAny.pData ); |
361 | return true; |
362 | } |
363 | return false; |
364 | } |
365 | |
366 | |
367 | template<> |
368 | inline bool SAL_CALL operator == ( Any const & rAny, bool const & value ) |
369 | { |
370 | return (rAny.pType->eTypeClass == typelib_TypeClass_BOOLEAN && |
371 | (value == |
372 | bool(*static_cast< sal_Bool const * >( rAny.pData )))); |
373 | } |
374 | |
375 | // byte |
376 | |
377 | template<> |
378 | inline bool SAL_CALL operator >>= ( const ::com::sun::star::uno::Any & rAny, sal_Int8 & value ) |
379 | { |
380 | if (typelib_TypeClass_BYTE == rAny.pType->eTypeClass) |
381 | { |
382 | value = * static_cast< const sal_Int8 * >( rAny.pData ); |
383 | return true; |
384 | } |
385 | return false; |
386 | } |
387 | // short |
388 | |
389 | template<> |
390 | inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int16 & value ) |
391 | { |
392 | switch (rAny.pType->eTypeClass) |
393 | { |
394 | case typelib_TypeClass_BYTE: |
395 | value = * static_cast< const sal_Int8 * >( rAny.pData ); |
396 | return true; |
397 | case typelib_TypeClass_SHORT: |
398 | case typelib_TypeClass_UNSIGNED_SHORT: |
399 | value = * static_cast< const sal_Int16 * >( rAny.pData ); |
400 | return true; |
401 | default: |
402 | return false; |
403 | } |
404 | } |
405 | |
406 | template<> |
407 | inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt16 & value ) |
408 | { |
409 | switch (rAny.pType->eTypeClass) |
410 | { |
411 | case typelib_TypeClass_BYTE: |
412 | value = static_cast<sal_uInt16>( * static_cast< const sal_Int8 * >( rAny.pData ) ); |
413 | return true; |
414 | case typelib_TypeClass_SHORT: |
415 | case typelib_TypeClass_UNSIGNED_SHORT: |
416 | value = * static_cast< const sal_uInt16 * >( rAny.pData ); |
417 | return true; |
418 | default: |
419 | return false; |
420 | } |
421 | } |
422 | // long |
423 | |
424 | template<> |
425 | inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int32 & value ) |
426 | { |
427 | switch (rAny.pType->eTypeClass) |
428 | { |
429 | case typelib_TypeClass_BYTE: |
430 | value = * static_cast< const sal_Int8 * >( rAny.pData ); |
431 | return true; |
432 | case typelib_TypeClass_SHORT: |
433 | value = * static_cast< const sal_Int16 * >( rAny.pData ); |
434 | return true; |
435 | case typelib_TypeClass_UNSIGNED_SHORT: |
436 | value = * static_cast< const sal_uInt16 * >( rAny.pData ); |
437 | return true; |
438 | case typelib_TypeClass_LONG: |
439 | case typelib_TypeClass_UNSIGNED_LONG: |
440 | value = * static_cast< const sal_Int32 * >( rAny.pData ); |
441 | return true; |
442 | default: |
443 | return false; |
444 | } |
445 | } |
446 | |
447 | template<> |
448 | inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt32 & value ) |
449 | { |
450 | switch (rAny.pType->eTypeClass) |
451 | { |
452 | case typelib_TypeClass_BYTE: |
453 | value = static_cast<sal_uInt32>( * static_cast< const sal_Int8 * >( rAny.pData ) ); |
454 | return true; |
455 | case typelib_TypeClass_SHORT: |
456 | value = static_cast<sal_uInt32>( * static_cast< const sal_Int16 * >( rAny.pData ) ); |
457 | return true; |
458 | case typelib_TypeClass_UNSIGNED_SHORT: |
459 | value = * static_cast< const sal_uInt16 * >( rAny.pData ); |
460 | return true; |
461 | case typelib_TypeClass_LONG: |
462 | case typelib_TypeClass_UNSIGNED_LONG: |
463 | value = * static_cast< const sal_uInt32 * >( rAny.pData ); |
464 | return true; |
465 | default: |
466 | return false; |
467 | } |
468 | } |
469 | // hyper |
470 | |
471 | template<> |
472 | inline bool SAL_CALL operator >>= ( const Any & rAny, sal_Int64 & value ) |
473 | { |
474 | switch (rAny.pType->eTypeClass) |
475 | { |
476 | case typelib_TypeClass_BYTE: |
477 | value = * static_cast< const sal_Int8 * >( rAny.pData ); |
478 | return true; |
479 | case typelib_TypeClass_SHORT: |
480 | value = * static_cast< const sal_Int16 * >( rAny.pData ); |
481 | return true; |
482 | case typelib_TypeClass_UNSIGNED_SHORT: |
483 | value = * static_cast< const sal_uInt16 * >( rAny.pData ); |
484 | return true; |
485 | case typelib_TypeClass_LONG: |
486 | value = * static_cast< const sal_Int32 * >( rAny.pData ); |
487 | return true; |
488 | case typelib_TypeClass_UNSIGNED_LONG: |
489 | value = * static_cast< const sal_uInt32 * >( rAny.pData ); |
490 | return true; |
491 | case typelib_TypeClass_HYPER: |
492 | case typelib_TypeClass_UNSIGNED_HYPER: |
493 | value = * static_cast< const sal_Int64 * >( rAny.pData ); |
494 | return true; |
495 | default: |
496 | return false; |
497 | } |
498 | } |
499 | |
500 | template<> |
501 | inline bool SAL_CALL operator >>= ( const Any & rAny, sal_uInt64 & value ) |
502 | { |
503 | switch (rAny.pType->eTypeClass) |
504 | { |
505 | case typelib_TypeClass_BYTE: |
506 | value = static_cast<sal_uInt64>( * static_cast< const sal_Int8 * >( rAny.pData ) ); |
507 | return true; |
508 | case typelib_TypeClass_SHORT: |
509 | value = static_cast<sal_uInt64>( * static_cast< const sal_Int16 * >( rAny.pData ) ); |
510 | return true; |
511 | case typelib_TypeClass_UNSIGNED_SHORT: |
512 | value = * static_cast< const sal_uInt16 * >( rAny.pData ); |
513 | return true; |
514 | case typelib_TypeClass_LONG: |
515 | value = static_cast<sal_uInt64>( * static_cast< const sal_Int32 * >( rAny.pData ) ); |
516 | return true; |
517 | case typelib_TypeClass_UNSIGNED_LONG: |
518 | value = * static_cast< const sal_uInt32 * >( rAny.pData ); |
519 | return true; |
520 | case typelib_TypeClass_HYPER: |
521 | case typelib_TypeClass_UNSIGNED_HYPER: |
522 | value = * static_cast< const sal_uInt64 * >( rAny.pData ); |
523 | return true; |
524 | default: |
525 | return false; |
526 | } |
527 | } |
528 | // float |
529 | |
530 | template<> |
531 | inline bool SAL_CALL operator >>= ( const Any & rAny, float & value ) |
532 | { |
533 | switch (rAny.pType->eTypeClass) |
534 | { |
535 | case typelib_TypeClass_BYTE: |
536 | value = * static_cast< const sal_Int8 * >( rAny.pData ); |
537 | return true; |
538 | case typelib_TypeClass_SHORT: |
539 | value = * static_cast< const sal_Int16 * >( rAny.pData ); |
540 | return true; |
541 | case typelib_TypeClass_UNSIGNED_SHORT: |
542 | value = * static_cast< const sal_uInt16 * >( rAny.pData ); |
543 | return true; |
544 | case typelib_TypeClass_FLOAT: |
545 | value = * static_cast< const float * >( rAny.pData ); |
546 | return true; |
547 | default: |
548 | return false; |
549 | } |
550 | } |
551 | // double |
552 | |
553 | template<> |
554 | inline bool SAL_CALL operator >>= ( const Any & rAny, double & value ) |
555 | { |
556 | switch (rAny.pType->eTypeClass) |
557 | { |
558 | case typelib_TypeClass_BYTE: |
559 | value = * static_cast< const sal_Int8 * >( rAny.pData ); |
560 | return true; |
561 | case typelib_TypeClass_SHORT: |
562 | value = * static_cast< const sal_Int16 * >( rAny.pData ); |
563 | return true; |
564 | case typelib_TypeClass_UNSIGNED_SHORT: |
565 | value = * static_cast< const sal_uInt16 * >( rAny.pData ); |
566 | return true; |
567 | case typelib_TypeClass_LONG: |
568 | value = * static_cast< const sal_Int32 * >( rAny.pData ); |
569 | return true; |
570 | case typelib_TypeClass_UNSIGNED_LONG: |
571 | value = * static_cast< const sal_uInt32 * >( rAny.pData ); |
572 | return true; |
573 | case typelib_TypeClass_FLOAT: |
574 | value = * static_cast< const float * >( rAny.pData ); |
575 | return true; |
576 | case typelib_TypeClass_DOUBLE: |
577 | value = * static_cast< const double * >( rAny.pData ); |
578 | return true; |
579 | default: |
580 | return false; |
581 | } |
582 | } |
583 | // string |
584 | |
585 | template<> |
586 | inline bool SAL_CALL operator >>= ( const Any & rAny, ::rtl::OUString & value ) |
587 | { |
588 | if (typelib_TypeClass_STRING == rAny.pType->eTypeClass) |
589 | { |
590 | value = * static_cast< const ::rtl::OUString * >( rAny.pData ); |
591 | return true; |
592 | } |
593 | return false; |
594 | } |
595 | |
596 | template<> |
597 | inline bool SAL_CALL operator == ( const Any & rAny, const ::rtl::OUString & value ) |
598 | { |
599 | return (typelib_TypeClass_STRING == rAny.pType->eTypeClass && |
600 | value == * static_cast< const ::rtl::OUString * >( rAny.pData ) ); |
601 | } |
602 | // type |
603 | |
604 | template<> |
605 | inline bool SAL_CALL operator >>= ( const Any & rAny, Type & value ) |
606 | { |
607 | if (typelib_TypeClass_TYPE == rAny.pType->eTypeClass) |
608 | { |
609 | value = * static_cast< const Type * >( rAny.pData ); |
610 | return true; |
611 | } |
612 | return false; |
613 | } |
614 | |
615 | template<> |
616 | inline bool SAL_CALL operator == ( const Any & rAny, const Type & value ) |
617 | { |
618 | return (typelib_TypeClass_TYPE == rAny.pType->eTypeClass && |
619 | value.equals( * static_cast< const Type * >( rAny.pData ) )); |
620 | } |
621 | // any |
622 | |
623 | #if defined LIBO_INTERNAL_ONLY1 |
624 | template<> bool SAL_CALL operator >>=(Any const &, Any &) = delete; |
625 | #else |
626 | template<> |
627 | inline bool SAL_CALL operator >>= ( const Any & rAny, Any & value ) |
628 | { |
629 | if (&rAny != &value) |
630 | { |
631 | ::uno_type_any_assign( |
632 | &value, rAny.pData, rAny.pType, |
633 | cpp_acquire, cpp_release ); |
634 | } |
635 | return true; |
636 | } |
637 | #endif |
638 | // interface |
639 | |
640 | template<> |
641 | inline bool SAL_CALL operator == ( const Any & rAny, const BaseReference & value ) |
642 | { |
643 | if (typelib_TypeClass_INTERFACE == rAny.pType->eTypeClass) |
644 | { |
645 | return static_cast< const BaseReference * >( rAny.pData )->operator == ( value ); |
646 | } |
647 | return false; |
648 | } |
649 | |
650 | // operator to compare to an any. |
651 | |
652 | template< class C > |
653 | inline bool SAL_CALL operator == ( const Any & rAny, const C & value ) |
654 | { |
655 | const Type & rType = ::cppu::getTypeFavourUnsigned(&value); |
656 | return ::uno_type_equalData( |
657 | rAny.pData, rAny.pType, |
658 | const_cast< C * >( &value ), rType.getTypeLibType(), |
659 | cpp_queryInterface, cpp_release ); |
660 | } |
661 | // operator to compare to an any. may use specialized operators ==. |
662 | |
663 | template< class C > |
664 | inline bool SAL_CALL operator != ( const Any & rAny, const C & value ) |
665 | { |
666 | return (! operator == ( rAny, value )); |
667 | } |
668 | |
669 | template <typename T> |
670 | T Any::get() const |
671 | { |
672 | T value = T(); |
673 | if (! (*this >>= value)) { |
674 | throw RuntimeException( |
675 | ::rtl::OUString( |
676 | cppu_Any_extraction_failure_msg( |
677 | this, |
678 | ::cppu::getTypeFavourUnsigned(&value).getTypeLibType() ), |
679 | SAL_NO_ACQUIRE ) ); |
680 | } |
681 | return value; |
682 | } |
683 | |
684 | #if defined LIBO_INTERNAL_ONLY1 |
685 | template<> Any Any::get() const = delete; |
686 | #endif |
687 | |
688 | /** |
689 | Support for Any in std::ostream (and thus in CPPUNIT_ASSERT or SAL_INFO |
690 | macros, for example). |
691 | |
692 | @since LibreOffice 4.2 |
693 | */ |
694 | template<typename charT, typename traits> |
695 | inline std::basic_ostream<charT, traits> &operator<<(std::basic_ostream<charT, traits> &o, Any const &any) { |
696 | o << "<Any: (" << any.getValueTypeName() << ')'; |
697 | switch(any.pType->eTypeClass) { |
698 | case typelib_TypeClass_VOID: |
699 | break; |
700 | case typelib_TypeClass_BOOLEAN: |
701 | o << ' ' << any.get<bool>(); |
702 | break; |
703 | case typelib_TypeClass_BYTE: |
704 | case typelib_TypeClass_SHORT: |
705 | case typelib_TypeClass_LONG: |
706 | case typelib_TypeClass_HYPER: |
707 | o << ' ' << any.get<sal_Int64>(); |
708 | break; |
709 | case typelib_TypeClass_UNSIGNED_SHORT: |
710 | case typelib_TypeClass_UNSIGNED_LONG: |
711 | case typelib_TypeClass_UNSIGNED_HYPER: |
712 | o << ' ' << any.get<sal_uInt64>(); |
713 | break; |
714 | case typelib_TypeClass_FLOAT: |
715 | case typelib_TypeClass_DOUBLE: |
716 | o << ' ' << any.get<double>(); |
717 | break; |
718 | case typelib_TypeClass_CHAR: { |
719 | std::ios_base::fmtflags flgs = o.setf( |
720 | std::ios_base::hex, std::ios_base::basefield); |
721 | charT fill = o.fill('0'); |
722 | o << " U+" << std::setw(4) |
723 | << unsigned(*static_cast<sal_Unicode const *>(any.getValue())); |
724 | o.setf(flgs); |
725 | o.fill(fill); |
726 | break; |
727 | } |
728 | case typelib_TypeClass_STRING: |
729 | o << ' ' << any.get<rtl::OUString>(); |
730 | break; |
731 | case typelib_TypeClass_TYPE: |
732 | o << ' ' << any.get<css::uno::Type>().getTypeName(); |
733 | break; |
734 | case typelib_TypeClass_SEQUENCE: |
735 | o << " len " |
736 | << ((*static_cast<uno_Sequence * const *>(any.getValue()))-> |
737 | nElements); |
738 | break; |
739 | case typelib_TypeClass_ENUM: |
740 | o << ' ' << *static_cast<sal_Int32 const *>(any.getValue()); |
741 | break; |
742 | case typelib_TypeClass_STRUCT: |
743 | case typelib_TypeClass_EXCEPTION: |
744 | o << ' ' << any.getValue(); |
745 | break; |
746 | case typelib_TypeClass_INTERFACE: |
747 | o << ' ' << *static_cast<void * const *>(any.getValue()); |
748 | break; |
749 | default: |
750 | assert(false)(static_cast <bool> (false) ? void (0) : __assert_fail ( "false", "/home/maarten/src/libreoffice/core/include/com/sun/star/uno/Any.hxx" , 750, __extension__ __PRETTY_FUNCTION__)); // this cannot happen |
751 | break; |
752 | } |
753 | o << '>'; |
754 | return o; |
755 | } |
756 | |
757 | } |
758 | } |
759 | } |
760 | } |
761 | |
762 | #endif |
763 | |
764 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |