/src/libreoffice/chart2/source/model/main/Axis.cxx
Line | Count | Source |
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 <Axis.hxx> |
21 | | #include <GridProperties.hxx> |
22 | | #include <CharacterProperties.hxx> |
23 | | #include <LinePropertiesHelper.hxx> |
24 | | #include <UserDefinedProperties.hxx> |
25 | | #include <PropertyHelper.hxx> |
26 | | #include <AxisHelper.hxx> |
27 | | #include <EventListenerHelper.hxx> |
28 | | #include <ModifyListenerHelper.hxx> |
29 | | #include <Title.hxx> |
30 | | #include <unonames.hxx> |
31 | | |
32 | | #include <com/sun/star/chart/ChartAxisArrangeOrderType.hpp> |
33 | | #include <com/sun/star/chart/ChartAxisLabelPosition.hpp> |
34 | | #include <com/sun/star/chart/ChartAxisMarkPosition.hpp> |
35 | | #include <com/sun/star/chart/ChartAxisPosition.hpp> |
36 | | #include <com/sun/star/beans/PropertyAttribute.hpp> |
37 | | #include <com/sun/star/awt/Size.hpp> |
38 | | #include <cppuhelper/supportsservice.hxx> |
39 | | #include <comphelper/diagnose_ex.hxx> |
40 | | #include <rtl/ref.hxx> |
41 | | |
42 | | #include <vector> |
43 | | #include <algorithm> |
44 | | |
45 | | using namespace ::com::sun::star; |
46 | | using namespace ::com::sun::star::beans::PropertyAttribute; |
47 | | |
48 | | using ::com::sun::star::uno::Sequence; |
49 | | using ::com::sun::star::uno::Reference; |
50 | | using ::com::sun::star::beans::Property; |
51 | | using ::osl::MutexGuard; |
52 | | |
53 | | namespace |
54 | | { |
55 | | |
56 | | enum |
57 | | { |
58 | | PROP_AXIS_SHOW, |
59 | | PROP_AXIS_CROSSOVER_POSITION, |
60 | | PROP_AXIS_CROSSOVER_VALUE, |
61 | | PROP_AXIS_DISPLAY_LABELS, |
62 | | PROP_AXIS_NUMBERFORMAT, |
63 | | PROP_AXIS_LINK_NUMBERFORMAT_TO_SOURCE, |
64 | | PROP_AXIS_LABEL_POSITION, |
65 | | PROP_AXIS_TEXT_ROTATION, |
66 | | PROP_AXIS_TEXT_BREAK, |
67 | | PROP_AXIS_TEXT_OVERLAP, |
68 | | PROP_AXIS_TEXT_STACKED, |
69 | | PROP_AXIS_TEXT_ARRANGE_ORDER, |
70 | | PROP_AXIS_REFERENCE_DIAGRAM_SIZE, |
71 | | |
72 | | PROP_AXIS_MAJOR_TICKMARKS, |
73 | | PROP_AXIS_MINOR_TICKMARKS, |
74 | | PROP_AXIS_MARK_POSITION, |
75 | | |
76 | | PROP_AXIS_DISPLAY_UNITS, |
77 | | PROP_AXIS_BUILTINUNIT, |
78 | | |
79 | | PROP_AXIS_TRY_STAGGERING_FIRST, |
80 | | PROP_AXIS_MAJOR_ORIGIN, |
81 | | PROP_AXIS_HAS_EXPLICIT_SPPR, |
82 | | PROP_AXIS_HAS_EXPLICIT_TXPR, |
83 | | PROP_AXIS_ID, |
84 | | PROP_AXIS_CAT_NOT_VAL, |
85 | | PROP_AXIS_CHARTEX_VAL_MIN, |
86 | | PROP_AXIS_CHARTEX_VAL_MAX, |
87 | | PROP_AXIS_CHARTEX_MAJOR_UNIT, |
88 | | PROP_AXIS_CHARTEX_MINOR_UNIT, |
89 | | PROP_AXIS_CHARTEX_UNIT |
90 | | }; |
91 | | |
92 | | void lcl_AddPropertiesToVector( |
93 | | std::vector< Property > & rOutProperties ) |
94 | 0 | { |
95 | 0 | rOutProperties.emplace_back( "Show", |
96 | 0 | PROP_AXIS_SHOW, |
97 | 0 | cppu::UnoType<bool>::get(), |
98 | 0 | beans::PropertyAttribute::BOUND |
99 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
100 | |
|
101 | 0 | rOutProperties.emplace_back( "CrossoverPosition", |
102 | 0 | PROP_AXIS_CROSSOVER_POSITION, |
103 | 0 | cppu::UnoType<css::chart::ChartAxisPosition>::get(), |
104 | 0 | beans::PropertyAttribute::MAYBEDEFAULT ); |
105 | |
|
106 | 0 | rOutProperties.emplace_back( "CrossoverValue", |
107 | 0 | PROP_AXIS_CROSSOVER_VALUE, |
108 | 0 | cppu::UnoType<double>::get(), |
109 | 0 | beans::PropertyAttribute::MAYBEVOID ); |
110 | |
|
111 | 0 | rOutProperties.emplace_back( "DisplayLabels", |
112 | 0 | PROP_AXIS_DISPLAY_LABELS, |
113 | 0 | cppu::UnoType<bool>::get(), |
114 | 0 | beans::PropertyAttribute::BOUND |
115 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
116 | |
|
117 | 0 | rOutProperties.emplace_back( CHART_UNONAME_NUMFMT, |
118 | 0 | PROP_AXIS_NUMBERFORMAT, |
119 | 0 | cppu::UnoType<sal_Int32>::get(), |
120 | 0 | beans::PropertyAttribute::BOUND |
121 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
122 | |
|
123 | 0 | rOutProperties.emplace_back( CHART_UNONAME_LINK_TO_SRC_NUMFMT, |
124 | 0 | PROP_AXIS_LINK_NUMBERFORMAT_TO_SOURCE, |
125 | 0 | cppu::UnoType<bool>::get(), |
126 | 0 | beans::PropertyAttribute::BOUND |
127 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
128 | |
|
129 | 0 | rOutProperties.emplace_back( "LabelPosition", |
130 | 0 | PROP_AXIS_LABEL_POSITION, |
131 | 0 | cppu::UnoType<css::chart::ChartAxisLabelPosition>::get(), |
132 | 0 | beans::PropertyAttribute::MAYBEDEFAULT ); |
133 | |
|
134 | 0 | rOutProperties.emplace_back( "TextRotation", |
135 | 0 | PROP_AXIS_TEXT_ROTATION, |
136 | 0 | cppu::UnoType<double>::get(), |
137 | 0 | beans::PropertyAttribute::BOUND |
138 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
139 | |
|
140 | 0 | rOutProperties.emplace_back( "TextBreak", |
141 | 0 | PROP_AXIS_TEXT_BREAK, |
142 | 0 | cppu::UnoType<bool>::get(), |
143 | 0 | beans::PropertyAttribute::BOUND |
144 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
145 | |
|
146 | 0 | rOutProperties.emplace_back( "TextOverlap", |
147 | 0 | PROP_AXIS_TEXT_OVERLAP, |
148 | 0 | cppu::UnoType<bool>::get(), |
149 | 0 | beans::PropertyAttribute::BOUND |
150 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
151 | |
|
152 | 0 | rOutProperties.emplace_back( "StackCharacters", |
153 | 0 | PROP_AXIS_TEXT_STACKED, |
154 | 0 | cppu::UnoType<bool>::get(), |
155 | 0 | beans::PropertyAttribute::BOUND |
156 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
157 | |
|
158 | 0 | rOutProperties.emplace_back( "ArrangeOrder", |
159 | 0 | PROP_AXIS_TEXT_ARRANGE_ORDER, |
160 | 0 | cppu::UnoType<css::chart::ChartAxisArrangeOrderType>::get(), |
161 | 0 | beans::PropertyAttribute::BOUND |
162 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
163 | |
|
164 | 0 | rOutProperties.emplace_back( "ReferencePageSize", |
165 | 0 | PROP_AXIS_REFERENCE_DIAGRAM_SIZE, |
166 | 0 | cppu::UnoType<awt::Size>::get(), |
167 | 0 | beans::PropertyAttribute::BOUND |
168 | 0 | | beans::PropertyAttribute::MAYBEVOID ); |
169 | |
|
170 | 0 | rOutProperties.emplace_back( "MajorTickmarks", |
171 | 0 | PROP_AXIS_MAJOR_TICKMARKS, |
172 | 0 | cppu::UnoType<sal_Int32>::get(), |
173 | 0 | beans::PropertyAttribute::BOUND |
174 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
175 | |
|
176 | 0 | rOutProperties.emplace_back( "MinorTickmarks", |
177 | 0 | PROP_AXIS_MINOR_TICKMARKS, |
178 | 0 | cppu::UnoType<sal_Int32>::get(), |
179 | 0 | beans::PropertyAttribute::BOUND |
180 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
181 | |
|
182 | 0 | rOutProperties.emplace_back( "MarkPosition", |
183 | 0 | PROP_AXIS_MARK_POSITION, |
184 | 0 | cppu::UnoType<css::chart::ChartAxisMarkPosition>::get(), |
185 | 0 | beans::PropertyAttribute::MAYBEDEFAULT ); |
186 | | |
187 | | //Properties for display units: |
188 | 0 | rOutProperties.emplace_back( "DisplayUnits", |
189 | 0 | PROP_AXIS_DISPLAY_UNITS, |
190 | 0 | cppu::UnoType<bool>::get(), |
191 | 0 | beans::PropertyAttribute::BOUND |
192 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
193 | | |
194 | | //Properties for labels: |
195 | 0 | rOutProperties.emplace_back( "BuiltInUnit", |
196 | 0 | PROP_AXIS_BUILTINUNIT, |
197 | 0 | cppu::UnoType<OUString>::get(), |
198 | 0 | beans::PropertyAttribute::BOUND |
199 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
200 | | |
201 | | // Compatibility option: starting from LibreOffice 5.1 the rotated |
202 | | // layout is preferred to staggering for axis labels. |
203 | 0 | rOutProperties.emplace_back( "TryStaggeringFirst", |
204 | 0 | PROP_AXIS_TRY_STAGGERING_FIRST, |
205 | 0 | cppu::UnoType<bool>::get(), |
206 | 0 | beans::PropertyAttribute::BOUND |
207 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
208 | |
|
209 | 0 | rOutProperties.emplace_back( "MajorOrigin", |
210 | 0 | PROP_AXIS_MAJOR_ORIGIN, |
211 | 0 | cppu::UnoType<double>::get(), |
212 | 0 | beans::PropertyAttribute::BOUND |
213 | 0 | | beans::PropertyAttribute::MAYBEVOID ); |
214 | |
|
215 | 0 | rOutProperties.emplace_back( "HasExplicitSpPr", |
216 | 0 | PROP_AXIS_HAS_EXPLICIT_SPPR, |
217 | 0 | cppu::UnoType<bool>::get(), |
218 | 0 | beans::PropertyAttribute::BOUND |
219 | 0 | | beans::PropertyAttribute::MAYBEVOID ); |
220 | |
|
221 | 0 | rOutProperties.emplace_back( "HasExplicitTxPr", |
222 | 0 | PROP_AXIS_HAS_EXPLICIT_TXPR, |
223 | 0 | cppu::UnoType<bool>::get(), |
224 | 0 | beans::PropertyAttribute::BOUND |
225 | 0 | | beans::PropertyAttribute::MAYBEVOID ); |
226 | | |
227 | | // Chartex only: the cx:axis id attribute value from import, preserved |
228 | | // so export can reuse the same id and so series-to-axis links survive |
229 | | // round-trip. |
230 | 0 | rOutProperties.emplace_back( "AxisId", |
231 | 0 | PROP_AXIS_ID, |
232 | 0 | cppu::UnoType<sal_Int32>::get(), |
233 | 0 | beans::PropertyAttribute::BOUND |
234 | 0 | | beans::PropertyAttribute::MAYBEVOID ); |
235 | 0 | rOutProperties.emplace_back( "CatNotVal", |
236 | 0 | PROP_AXIS_CAT_NOT_VAL, |
237 | 0 | cppu::UnoType<bool>::get(), |
238 | 0 | beans::PropertyAttribute::BOUND |
239 | 0 | | beans::PropertyAttribute::MAYBEVOID ); |
240 | | |
241 | | // Chartex round-trip: cx:valScaling attributes preserved verbatim, so |
242 | | // export does not have to rebuild them from the chart2 ScaleData (where |
243 | | // Auto* flags and explicit calc-style defaults can mask the original |
244 | | // intent). |
245 | 0 | rOutProperties.emplace_back( "ChartexValMin", |
246 | 0 | PROP_AXIS_CHARTEX_VAL_MIN, |
247 | 0 | cppu::UnoType<double>::get(), |
248 | 0 | beans::PropertyAttribute::BOUND |
249 | 0 | | beans::PropertyAttribute::MAYBEVOID ); |
250 | 0 | rOutProperties.emplace_back( "ChartexValMax", |
251 | 0 | PROP_AXIS_CHARTEX_VAL_MAX, |
252 | 0 | cppu::UnoType<double>::get(), |
253 | 0 | beans::PropertyAttribute::BOUND |
254 | 0 | | beans::PropertyAttribute::MAYBEVOID ); |
255 | 0 | rOutProperties.emplace_back( "ChartexMajorUnit", |
256 | 0 | PROP_AXIS_CHARTEX_MAJOR_UNIT, |
257 | 0 | cppu::UnoType<double>::get(), |
258 | 0 | beans::PropertyAttribute::BOUND |
259 | 0 | | beans::PropertyAttribute::MAYBEVOID ); |
260 | 0 | rOutProperties.emplace_back( "ChartexMinorUnit", |
261 | 0 | PROP_AXIS_CHARTEX_MINOR_UNIT, |
262 | 0 | cppu::UnoType<double>::get(), |
263 | 0 | beans::PropertyAttribute::BOUND |
264 | 0 | | beans::PropertyAttribute::MAYBEVOID ); |
265 | | |
266 | | // Chartex round-trip: cx:units/@unit value. Stored alongside the |
267 | | // existing BuiltInUnit/DisplayUnits properties because the chartex |
268 | | // flat form only uses this single string and we want the same string |
269 | | // to come back on export. |
270 | 0 | rOutProperties.emplace_back( "ChartexUnit", |
271 | 0 | PROP_AXIS_CHARTEX_UNIT, |
272 | 0 | cppu::UnoType<OUString>::get(), |
273 | 0 | beans::PropertyAttribute::BOUND |
274 | 0 | | beans::PropertyAttribute::MAYBEVOID ); |
275 | 0 | } |
276 | | } // namespace |
277 | | |
278 | | namespace chart |
279 | | { |
280 | | const ::chart::tPropertyValueMap & StaticAxisDefaults() |
281 | 0 | { |
282 | 0 | static ::chart::tPropertyValueMap aStaticDefaults = []() |
283 | 0 | { |
284 | 0 | ::chart::tPropertyValueMap aMap; |
285 | 0 | ::chart::CharacterProperties::AddDefaultsToMap( aMap ); |
286 | 0 | ::chart::LinePropertiesHelper::AddDefaultsToMap( aMap ); |
287 | |
|
288 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_AXIS_SHOW, true ); |
289 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_AXIS_CROSSOVER_POSITION, css::chart::ChartAxisPosition_ZERO ); |
290 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_AXIS_DISPLAY_LABELS, true ); |
291 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_AXIS_LINK_NUMBERFORMAT_TO_SOURCE, true ); |
292 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_AXIS_LABEL_POSITION, css::chart::ChartAxisLabelPosition_NEAR_AXIS ); |
293 | 0 | ::chart::PropertyHelper::setPropertyValueDefault< double >( aMap, PROP_AXIS_TEXT_ROTATION, 0.0 ); |
294 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_AXIS_TEXT_BREAK, false ); |
295 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_AXIS_TEXT_OVERLAP, false ); |
296 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_AXIS_TEXT_STACKED, false ); |
297 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_AXIS_TEXT_ARRANGE_ORDER, css::chart::ChartAxisArrangeOrderType_AUTO ); |
298 | |
|
299 | 0 | float fDefaultCharHeight = 10.0; |
300 | 0 | ::chart::PropertyHelper::setPropertyValue( aMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight ); |
301 | 0 | ::chart::PropertyHelper::setPropertyValue( aMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight ); |
302 | 0 | ::chart::PropertyHelper::setPropertyValue( aMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight ); |
303 | |
|
304 | 0 | ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aMap, PROP_AXIS_MAJOR_TICKMARKS, 2 /* CHAXIS_MARK_OUTER */ ); |
305 | 0 | ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aMap, PROP_AXIS_MINOR_TICKMARKS, 0 /* CHAXIS_MARK_NONE */ ); |
306 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_AXIS_MARK_POSITION, css::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS ); |
307 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_AXIS_DISPLAY_UNITS, false ); |
308 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aMap, PROP_AXIS_TRY_STAGGERING_FIRST, false ); |
309 | 0 | return aMap; |
310 | 0 | }(); |
311 | 0 | return aStaticDefaults; |
312 | 0 | } |
313 | | } // namespace chart |
314 | | |
315 | | namespace |
316 | | { |
317 | | ::cppu::OPropertyArrayHelper& StaticAxisInfoHelper() |
318 | 0 | { |
319 | 0 | static ::cppu::OPropertyArrayHelper aPropHelper = []() |
320 | 0 | { |
321 | 0 | std::vector< css::beans::Property > aProperties; |
322 | 0 | lcl_AddPropertiesToVector( aProperties ); |
323 | 0 | ::chart::CharacterProperties::AddPropertiesToVector( aProperties ); |
324 | 0 | ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties ); |
325 | 0 | ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties ); |
326 | |
|
327 | 0 | std::sort( aProperties.begin(), aProperties.end(), |
328 | 0 | ::chart::PropertyNameLess() ); |
329 | |
|
330 | 0 | return comphelper::containerToSequence( aProperties ); |
331 | 0 | }(); |
332 | 0 | return aPropHelper; |
333 | 0 | } |
334 | | |
335 | | std::vector< rtl::Reference< ::chart::GridProperties > > lcl_CloneSubGrids( |
336 | | const std::vector< rtl::Reference< ::chart::GridProperties > > & rSource ) |
337 | 0 | { |
338 | 0 | std::vector< rtl::Reference< ::chart::GridProperties > > aDestination; |
339 | 0 | aDestination.reserve( rSource.size()); |
340 | 0 | for( rtl::Reference< ::chart::GridProperties > const & i : rSource ) |
341 | 0 | { |
342 | 0 | aDestination.push_back(new ::chart::GridProperties(*i)); |
343 | 0 | } |
344 | 0 | return aDestination; |
345 | 0 | } |
346 | | |
347 | | } // anonymous namespace |
348 | | |
349 | | namespace chart |
350 | | { |
351 | | |
352 | | Axis::Axis() : |
353 | 0 | m_xModifyEventForwarder( new ModifyEventForwarder() ), |
354 | 0 | m_aScaleData( AxisHelper::createDefaultScale() ), |
355 | 0 | m_xGrid( new GridProperties() ) |
356 | 0 | { |
357 | 0 | osl_atomic_increment(&m_refCount); |
358 | 0 | setFastPropertyValue_NoBroadcast( |
359 | 0 | ::chart::LinePropertiesHelper::PROP_LINE_COLOR, uno::Any( static_cast< sal_Int32 >( 0xb3b3b3 ) ) ); // gray30 |
360 | |
|
361 | 0 | if( m_xGrid.is()) |
362 | 0 | ModifyListenerHelper::addListener( m_xGrid, m_xModifyEventForwarder ); |
363 | 0 | if( m_aScaleData.Categories.is()) |
364 | 0 | ModifyListenerHelper::addListener( m_aScaleData.Categories, m_xModifyEventForwarder ); |
365 | |
|
366 | 0 | AllocateSubGrids(); |
367 | 0 | osl_atomic_decrement(&m_refCount); |
368 | 0 | } |
369 | | |
370 | | Axis::Axis( const Axis & rOther ) : |
371 | 0 | impl::Axis_Base(rOther), |
372 | 0 | ::property::OPropertySet( rOther ), |
373 | 0 | m_xModifyEventForwarder( new ModifyEventForwarder() ), |
374 | 0 | m_aScaleData( rOther.m_aScaleData ) |
375 | 0 | { |
376 | 0 | if (rOther.m_xGrid) |
377 | 0 | m_xGrid = new ::chart::GridProperties(*rOther.m_xGrid); |
378 | 0 | if( m_xGrid.is()) |
379 | 0 | ModifyListenerHelper::addListener( m_xGrid, m_xModifyEventForwarder ); |
380 | |
|
381 | 0 | if( m_aScaleData.Categories.is()) |
382 | 0 | ModifyListenerHelper::addListener( m_aScaleData.Categories, m_xModifyEventForwarder ); |
383 | |
|
384 | 0 | if( !rOther.m_aSubGridProperties.empty() ) |
385 | 0 | m_aSubGridProperties = lcl_CloneSubGrids( rOther.m_aSubGridProperties ); |
386 | 0 | ModifyListenerHelper::addListenerToAllElements( m_aSubGridProperties, m_xModifyEventForwarder ); |
387 | |
|
388 | 0 | if ( rOther.m_xTitle ) |
389 | 0 | m_xTitle = new Title( *rOther.m_xTitle ); |
390 | 0 | if( m_xTitle.is()) |
391 | 0 | ModifyListenerHelper::addListener( m_xTitle, m_xModifyEventForwarder ); |
392 | 0 | } |
393 | | |
394 | | // late initialization to call after copy-constructing |
395 | | void Axis::Init() |
396 | 0 | { |
397 | 0 | if( m_aScaleData.Categories.is()) |
398 | 0 | EventListenerHelper::addListener( m_aScaleData.Categories, this ); |
399 | 0 | } |
400 | | |
401 | | Axis::~Axis() |
402 | 0 | { |
403 | 0 | try |
404 | 0 | { |
405 | 0 | ModifyListenerHelper::removeListener( m_xGrid, m_xModifyEventForwarder ); |
406 | 0 | ModifyListenerHelper::removeListenerFromAllElements( m_aSubGridProperties, m_xModifyEventForwarder ); |
407 | 0 | ModifyListenerHelper::removeListener( m_xTitle, m_xModifyEventForwarder ); |
408 | 0 | if( m_aScaleData.Categories.is()) |
409 | 0 | { |
410 | 0 | ModifyListenerHelper::removeListener( m_aScaleData.Categories, m_xModifyEventForwarder ); |
411 | 0 | m_aScaleData.Categories.clear(); |
412 | 0 | } |
413 | 0 | } |
414 | 0 | catch( const uno::Exception & ) |
415 | 0 | { |
416 | 0 | DBG_UNHANDLED_EXCEPTION("chart2"); |
417 | 0 | } |
418 | |
|
419 | 0 | m_aSubGridProperties.clear(); |
420 | 0 | m_xGrid = nullptr; |
421 | 0 | m_xTitle = nullptr; |
422 | 0 | } |
423 | | |
424 | | void Axis::AllocateSubGrids() |
425 | 0 | { |
426 | 0 | rtl::Reference< ModifyEventForwarder > xModifyEventForwarder; |
427 | 0 | Reference< lang::XEventListener > xEventListener; |
428 | 0 | std::vector< rtl::Reference< GridProperties > > aOldBroadcasters; |
429 | 0 | std::vector< rtl::Reference< GridProperties > > aNewBroadcasters; |
430 | 0 | { |
431 | 0 | MutexGuard aGuard( m_aMutex ); |
432 | 0 | xModifyEventForwarder = m_xModifyEventForwarder; |
433 | 0 | xEventListener = this; |
434 | |
|
435 | 0 | sal_Int32 nNewSubIncCount = m_aScaleData.IncrementData.SubIncrements.getLength(); |
436 | 0 | sal_Int32 nOldSubIncCount = m_aSubGridProperties.size(); |
437 | |
|
438 | 0 | if( nOldSubIncCount > nNewSubIncCount ) |
439 | 0 | { |
440 | | // remove superfluous entries |
441 | 0 | aOldBroadcasters.assign( |
442 | 0 | m_aSubGridProperties.begin() + nNewSubIncCount, |
443 | 0 | m_aSubGridProperties.end()); |
444 | |
|
445 | 0 | m_aSubGridProperties.resize( nNewSubIncCount ); |
446 | 0 | } |
447 | 0 | else if( nOldSubIncCount < nNewSubIncCount ) |
448 | 0 | { |
449 | 0 | m_aSubGridProperties.resize( nNewSubIncCount ); |
450 | | |
451 | | // allocate new entries |
452 | 0 | for( sal_Int32 i = nOldSubIncCount; i < nNewSubIncCount; ++i ) |
453 | 0 | { |
454 | 0 | m_aSubGridProperties[ i ] = new GridProperties(); |
455 | 0 | LinePropertiesHelper::SetLineInvisible( m_aSubGridProperties[ i ] ); |
456 | 0 | LinePropertiesHelper::SetLineColor( m_aSubGridProperties[ i ], static_cast<sal_Int32>(0xdddddd) ); //gray2 |
457 | 0 | aNewBroadcasters.push_back( m_aSubGridProperties[ i ] ); |
458 | 0 | } |
459 | 0 | } |
460 | 0 | } |
461 | | //don't keep the mutex locked while calling out |
462 | 0 | for (auto const& oldBroadcaster : aOldBroadcasters) |
463 | 0 | ModifyListenerHelper::removeListener(oldBroadcaster, xModifyEventForwarder ); |
464 | 0 | for (auto const& newBroadcaster : aNewBroadcasters) |
465 | 0 | ModifyListenerHelper::addListener( newBroadcaster, xModifyEventForwarder ); |
466 | 0 | } |
467 | | |
468 | | // ____ XAxis ____ |
469 | | void SAL_CALL Axis::setScaleData( const chart2::ScaleData& rScaleData ) |
470 | 0 | { |
471 | 0 | rtl::Reference< ModifyEventForwarder > xModifyEventForwarder; |
472 | 0 | Reference< lang::XEventListener > xEventListener; |
473 | 0 | Reference< chart2::data::XLabeledDataSequence > xOldCategories; |
474 | 0 | Reference< chart2::data::XLabeledDataSequence > xNewCategories = rScaleData.Categories; |
475 | 0 | { |
476 | 0 | MutexGuard aGuard( m_aMutex ); |
477 | 0 | xModifyEventForwarder = m_xModifyEventForwarder; |
478 | 0 | xEventListener = this; |
479 | 0 | xOldCategories = m_aScaleData.Categories; |
480 | 0 | m_aScaleData = rScaleData; |
481 | 0 | } |
482 | 0 | AllocateSubGrids(); |
483 | | |
484 | | //don't keep the mutex locked while calling out |
485 | 0 | if( xOldCategories.is() && xOldCategories != xNewCategories ) |
486 | 0 | { |
487 | 0 | ModifyListenerHelper::removeListener( xOldCategories, xModifyEventForwarder ); |
488 | 0 | EventListenerHelper::removeListener( xOldCategories, xEventListener ); |
489 | 0 | } |
490 | 0 | if( xNewCategories.is() && xOldCategories != xNewCategories ) |
491 | 0 | { |
492 | 0 | ModifyListenerHelper::addListener( xNewCategories, m_xModifyEventForwarder ); |
493 | 0 | EventListenerHelper::addListener( xNewCategories, xEventListener ); |
494 | 0 | } |
495 | 0 | fireModifyEvent(); |
496 | 0 | } |
497 | | |
498 | | chart2::ScaleData SAL_CALL Axis::getScaleData() |
499 | 0 | { |
500 | 0 | MutexGuard aGuard( m_aMutex ); |
501 | 0 | return m_aScaleData; |
502 | 0 | } |
503 | | |
504 | | Reference< beans::XPropertySet > SAL_CALL Axis::getGridProperties() |
505 | 0 | { |
506 | 0 | MutexGuard aGuard( m_aMutex ); |
507 | 0 | return m_xGrid; |
508 | 0 | } |
509 | | rtl::Reference< ::chart::GridProperties > Axis::getGridProperties2() |
510 | 0 | { |
511 | 0 | MutexGuard aGuard( m_aMutex ); |
512 | 0 | return m_xGrid; |
513 | 0 | } |
514 | | Sequence< Reference< beans::XPropertySet > > SAL_CALL Axis::getSubGridProperties() |
515 | 0 | { |
516 | 0 | MutexGuard aGuard( m_aMutex ); |
517 | 0 | return comphelper::containerToSequence<Reference< beans::XPropertySet >>(m_aSubGridProperties); |
518 | 0 | } |
519 | | |
520 | | std::vector< rtl::Reference< GridProperties > > Axis::getSubGridProperties2() |
521 | 0 | { |
522 | 0 | MutexGuard aGuard( m_aMutex ); |
523 | 0 | return m_aSubGridProperties; |
524 | 0 | } |
525 | | |
526 | | Sequence< Reference< beans::XPropertySet > > SAL_CALL Axis::getSubTickProperties() |
527 | 0 | { |
528 | 0 | OSL_FAIL( "Not implemented yet" ); |
529 | 0 | return Sequence< Reference< beans::XPropertySet > >(); |
530 | 0 | } |
531 | | |
532 | | // ____ XTitled ____ |
533 | | Reference< chart2::XTitle > SAL_CALL Axis::getTitleObject() |
534 | 0 | { |
535 | 0 | MutexGuard aGuard( m_aMutex ); |
536 | 0 | return m_xTitle; |
537 | 0 | } |
538 | | |
539 | | rtl::Reference< Title > Axis::getTitleObject2() const |
540 | 0 | { |
541 | 0 | MutexGuard aGuard( m_aMutex ); |
542 | 0 | return m_xTitle; |
543 | 0 | } |
544 | | |
545 | | void SAL_CALL Axis::setTitleObject( const Reference< chart2::XTitle >& xNewTitle ) |
546 | 0 | { |
547 | 0 | rtl::Reference<Title> xTitle = dynamic_cast<Title*>(xNewTitle.get()); |
548 | 0 | assert(!xNewTitle || xTitle); |
549 | 0 | setTitleObject(xTitle); |
550 | 0 | } |
551 | | |
552 | | void Axis::setTitleObject( const rtl::Reference< Title >& xNewTitle ) |
553 | 0 | { |
554 | 0 | rtl::Reference< ModifyEventForwarder > xModifyEventForwarder; |
555 | 0 | rtl::Reference< Title > xOldTitle; |
556 | 0 | { |
557 | 0 | MutexGuard aGuard( m_aMutex ); |
558 | 0 | xOldTitle = m_xTitle; |
559 | 0 | xModifyEventForwarder = m_xModifyEventForwarder; |
560 | 0 | m_xTitle = xNewTitle; |
561 | 0 | } |
562 | | |
563 | | //don't keep the mutex locked while calling out |
564 | 0 | if( xOldTitle.is() && xOldTitle != xNewTitle ) |
565 | 0 | ModifyListenerHelper::removeListener( xOldTitle, xModifyEventForwarder ); |
566 | 0 | if( xNewTitle.is() && xOldTitle != xNewTitle ) |
567 | 0 | ModifyListenerHelper::addListener( xNewTitle, xModifyEventForwarder ); |
568 | 0 | fireModifyEvent(); |
569 | 0 | } |
570 | | |
571 | | // ____ XCloneable ____ |
572 | | Reference< util::XCloneable > SAL_CALL Axis::createClone() |
573 | 0 | { |
574 | 0 | rtl::Reference<Axis> pNewAxis( new Axis( *this )); |
575 | | // do initialization that uses uno references to the clone |
576 | 0 | pNewAxis->Init(); |
577 | 0 | return pNewAxis; |
578 | 0 | } |
579 | | |
580 | | // ____ XModifyBroadcaster ____ |
581 | | void SAL_CALL Axis::addModifyListener( const Reference< util::XModifyListener >& aListener ) |
582 | 0 | { |
583 | 0 | m_xModifyEventForwarder->addModifyListener( aListener ); |
584 | 0 | } |
585 | | |
586 | | void SAL_CALL Axis::removeModifyListener( const Reference< util::XModifyListener >& aListener ) |
587 | 0 | { |
588 | 0 | m_xModifyEventForwarder->removeModifyListener( aListener ); |
589 | 0 | } |
590 | | |
591 | | // ____ XModifyListener ____ |
592 | | void SAL_CALL Axis::modified( const lang::EventObject& aEvent ) |
593 | 0 | { |
594 | 0 | m_xModifyEventForwarder->modified( aEvent ); |
595 | 0 | } |
596 | | |
597 | | // ____ XEventListener (base of XModifyListener) ____ |
598 | | void SAL_CALL Axis::disposing( const lang::EventObject& Source ) |
599 | 0 | { |
600 | 0 | if( Source.Source == m_aScaleData.Categories ) |
601 | 0 | m_aScaleData.Categories = nullptr; |
602 | 0 | } |
603 | | |
604 | | // ____ OPropertySet ____ |
605 | | void Axis::firePropertyChangeEvent() |
606 | 0 | { |
607 | 0 | fireModifyEvent(); |
608 | 0 | } |
609 | | |
610 | | void Axis::fireModifyEvent() |
611 | 0 | { |
612 | 0 | m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); |
613 | 0 | } |
614 | | |
615 | | // ____ OPropertySet ____ |
616 | | void Axis::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const |
617 | 0 | { |
618 | 0 | const tPropertyValueMap& rStaticDefaults = StaticAxisDefaults(); |
619 | 0 | tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) ); |
620 | 0 | if( aFound == rStaticDefaults.end() ) |
621 | 0 | rAny.clear(); |
622 | 0 | else |
623 | 0 | rAny = (*aFound).second; |
624 | 0 | } |
625 | | |
626 | | ::cppu::IPropertyArrayHelper & SAL_CALL Axis::getInfoHelper() |
627 | 0 | { |
628 | 0 | return StaticAxisInfoHelper(); |
629 | 0 | } |
630 | | |
631 | | // ____ XPropertySet ____ |
632 | | Reference< beans::XPropertySetInfo > SAL_CALL Axis::getPropertySetInfo() |
633 | 0 | { |
634 | 0 | static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo( |
635 | 0 | ::cppu::OPropertySetHelper::createPropertySetInfo(StaticAxisInfoHelper() ) ); |
636 | 0 | return xPropertySetInfo; |
637 | 0 | } |
638 | | |
639 | | using impl::Axis_Base; |
640 | | |
641 | | IMPLEMENT_FORWARD_XINTERFACE2( Axis, Axis_Base, ::property::OPropertySet ) |
642 | | IMPLEMENT_FORWARD_XTYPEPROVIDER2( Axis, Axis_Base, ::property::OPropertySet ) |
643 | | |
644 | | // implement XServiceInfo methods basing upon getSupportedServiceNames_Static |
645 | | OUString SAL_CALL Axis::getImplementationName() |
646 | 0 | { |
647 | 0 | return u"com.sun.star.comp.chart2.Axis"_ustr; |
648 | 0 | } |
649 | | |
650 | | sal_Bool SAL_CALL Axis::supportsService( const OUString& rServiceName ) |
651 | 0 | { |
652 | 0 | return cppu::supportsService(this, rServiceName); |
653 | 0 | } |
654 | | |
655 | | css::uno::Sequence< OUString > SAL_CALL Axis::getSupportedServiceNames() |
656 | 0 | { |
657 | 0 | return { |
658 | 0 | u"com.sun.star.chart2.Axis"_ustr, |
659 | 0 | u"com.sun.star.beans.PropertySet"_ustr }; |
660 | 0 | } |
661 | | |
662 | | } // namespace chart |
663 | | |
664 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * |
665 | | com_sun_star_comp_chart2_Axis_get_implementation(css::uno::XComponentContext *, |
666 | | css::uno::Sequence<css::uno::Any> const &) |
667 | 0 | { |
668 | 0 | return cppu::acquire(new ::chart::Axis); |
669 | 0 | } |
670 | | |
671 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |