Line data Source code
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 "DataSeriesPointWrapper.hxx"
21 : #include "macros.hxx"
22 : #include "RegressionCurveHelper.hxx"
23 : #include "Chart2ModelContact.hxx"
24 : #include "ChartTypeHelper.hxx"
25 : #include "DiagramHelper.hxx"
26 : #include "ContainerHelper.hxx"
27 : #include "ChartModelHelper.hxx"
28 : #include "LinePropertiesHelper.hxx"
29 : #include "FillProperties.hxx"
30 : #include "CharacterProperties.hxx"
31 : #include "UserDefinedProperties.hxx"
32 : #include "WrappedCharacterHeightProperty.hxx"
33 : #include "WrappedProperty.hxx"
34 : #include "WrappedIgnoreProperty.hxx"
35 : #include "WrappedStatisticProperties.hxx"
36 : #include "WrappedSymbolProperties.hxx"
37 : #include "WrappedDataCaptionProperties.hxx"
38 : #include "WrappedSeriesAreaOrLineProperty.hxx"
39 : #include "WrappedScaleTextProperties.hxx"
40 : #include "WrappedNumberFormatProperty.hxx"
41 : #include "WrappedTextRotationProperty.hxx"
42 : #include <rtl/ustrbuf.hxx>
43 : #include <rtl/math.hxx>
44 :
45 : #include <algorithm>
46 : #include <comphelper/InlineContainer.hxx>
47 : #include <com/sun/star/beans/PropertyAttribute.hpp>
48 : #include <com/sun/star/chart/ChartAxisAssign.hpp>
49 : #include <com/sun/star/chart/ChartErrorCategory.hpp>
50 : #include <com/sun/star/chart/XChartDocument.hpp>
51 : #include <com/sun/star/drawing/FillStyle.hpp>
52 : #include <com/sun/star/drawing/LineJoint.hpp>
53 : #include <com/sun/star/drawing/LineStyle.hpp>
54 :
55 : using namespace ::com::sun::star;
56 : using namespace ::chart::wrapper;
57 :
58 : using ::com::sun::star::uno::Reference;
59 : using ::com::sun::star::uno::Sequence;
60 : using ::com::sun::star::beans::Property;
61 : using ::com::sun::star::uno::Any;
62 : using ::osl::MutexGuard;
63 :
64 : namespace
65 : {
66 0 : static const OUString lcl_aServiceName( "com.sun.star.comp.chart.DataSeries" );
67 :
68 : enum
69 : {
70 : //data point properties
71 : PROP_SERIES_DATAPOINT_SOLIDTYPE,
72 : PROP_SERIES_DATAPOINT_SEGMENT_OFFSET,
73 : PROP_SERIES_DATAPOINT_PERCENT_DIAGONAL,
74 : PROP_SERIES_DATAPOINT_LABEL_SEPARATOR,
75 : PROP_SERIES_NUMBERFORMAT,
76 : PROP_SERIES_LINK_NUMBERFORMAT_TO_SOURCE,
77 : PROP_SERIES_PERCENTAGE_NUMBERFORMAT,
78 : PROP_SERIES_DATAPOINT_LABEL_PLACEMENT,
79 : //other series properties
80 : PROP_SERIES_ATTACHED_AXIS,
81 : PROP_SERIES_DATAPOINT_TEXT_ROTATION
82 : };
83 :
84 0 : void lcl_AddPropertiesToVector_PointProperties(
85 : ::std::vector< Property > & rOutProperties )
86 : {
87 : //service chart::Chart3DBarProperties
88 : rOutProperties.push_back(
89 : Property( "SolidType",
90 : PROP_SERIES_DATAPOINT_SOLIDTYPE,
91 0 : ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
92 : beans::PropertyAttribute::BOUND
93 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
94 :
95 : rOutProperties.push_back(
96 : Property( "SegmentOffset",
97 : PROP_SERIES_DATAPOINT_SEGMENT_OFFSET,
98 0 : ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
99 : beans::PropertyAttribute::BOUND
100 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
101 :
102 : rOutProperties.push_back(
103 : Property( "D3DPercentDiagonal",
104 : PROP_SERIES_DATAPOINT_PERCENT_DIAGONAL,
105 0 : ::getCppuType( reinterpret_cast< sal_Int16 * >(0)),
106 : beans::PropertyAttribute::BOUND
107 0 : | beans::PropertyAttribute::MAYBEVOID ));
108 :
109 : rOutProperties.push_back(
110 : Property( "LabelSeparator",
111 : PROP_SERIES_DATAPOINT_LABEL_SEPARATOR,
112 0 : ::getCppuType( reinterpret_cast< const OUString * >(0)),
113 : beans::PropertyAttribute::BOUND
114 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
115 :
116 : rOutProperties.push_back(
117 : Property( "NumberFormat",
118 : PROP_SERIES_NUMBERFORMAT,
119 0 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
120 : beans::PropertyAttribute::BOUND
121 0 : | beans::PropertyAttribute::MAYBEVOID ));
122 :
123 : rOutProperties.push_back(
124 : Property( "PercentageNumberFormat",
125 : PROP_SERIES_PERCENTAGE_NUMBERFORMAT,
126 0 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
127 : beans::PropertyAttribute::BOUND
128 0 : | beans::PropertyAttribute::MAYBEVOID ));
129 :
130 : rOutProperties.push_back(
131 : Property( "LabelPlacement",
132 : PROP_SERIES_DATAPOINT_LABEL_PLACEMENT,
133 0 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
134 : beans::PropertyAttribute::BOUND
135 0 : | beans::PropertyAttribute::MAYBEVOID ));
136 :
137 : rOutProperties.push_back(
138 : Property( "TextRotation",
139 : PROP_SERIES_DATAPOINT_TEXT_ROTATION,
140 0 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
141 : beans::PropertyAttribute::BOUND
142 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
143 0 : }
144 :
145 0 : void lcl_AddPropertiesToVector_SeriesOnly(
146 : ::std::vector< Property > & rOutProperties )
147 : {
148 : rOutProperties.push_back(
149 : Property( "Axis",
150 : PROP_SERIES_ATTACHED_AXIS,
151 0 : ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
152 : beans::PropertyAttribute::BOUND
153 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
154 :
155 : rOutProperties.push_back(
156 : Property( "LinkNumberFormatToSource",
157 : PROP_SERIES_LINK_NUMBERFORMAT_TO_SOURCE,
158 0 : ::getBooleanCppuType(),
159 : beans::PropertyAttribute::BOUND
160 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
161 0 : }
162 :
163 0 : uno::Sequence< Property > lcl_GetPropertySequence( DataSeriesPointWrapper::eType _eType )
164 : {
165 0 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
166 :
167 0 : lcl_AddPropertiesToVector_PointProperties( aProperties );
168 0 : if( _eType == DataSeriesPointWrapper::DATA_SERIES )
169 : {
170 0 : lcl_AddPropertiesToVector_SeriesOnly( aProperties );
171 0 : WrappedStatisticProperties::addProperties( aProperties );
172 : }
173 0 : WrappedSymbolProperties::addProperties( aProperties ); //for series and points
174 0 : WrappedDataCaptionProperties::addProperties( aProperties ); //for series and points
175 :
176 0 : ::chart::FillProperties::AddPropertiesToVector( aProperties );
177 0 : ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
178 0 : ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
179 0 : ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
180 0 : ::chart::wrapper::WrappedScaleTextProperties::addProperties( aProperties );
181 :
182 0 : ::std::sort( aProperties.begin(), aProperties.end(), ::chart::PropertyNameLess() );
183 :
184 0 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
185 : }
186 :
187 : struct StaticSeriesWrapperPropertyArray_Initializer
188 : {
189 0 : Sequence< Property >* operator()()
190 : {
191 0 : static Sequence< Property > aPropSeq( lcl_GetPropertySequence( DataSeriesPointWrapper::DATA_SERIES ) );
192 0 : return &aPropSeq;
193 : }
194 : };
195 :
196 : struct StaticSeriesWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticSeriesWrapperPropertyArray_Initializer >
197 : {
198 : };
199 :
200 : struct StaticPointWrapperPropertyArray_Initializer
201 : {
202 0 : Sequence< Property >* operator()()
203 : {
204 0 : static Sequence< Property > aPropSeq( lcl_GetPropertySequence( DataSeriesPointWrapper::DATA_POINT ) );
205 0 : return &aPropSeq;
206 : }
207 : };
208 :
209 : struct StaticPointWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticPointWrapperPropertyArray_Initializer >
210 : {
211 : };
212 :
213 : //PROP_SERIES_ATTACHED_AXIS
214 : class WrappedAttachedAxisProperty : public ::chart::WrappedProperty
215 : {
216 : public:
217 : WrappedAttachedAxisProperty( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact );
218 : virtual ~WrappedAttachedAxisProperty();
219 :
220 : virtual void setPropertyValue( const Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
221 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
222 :
223 : virtual Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
224 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
225 :
226 : virtual Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
227 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
228 :
229 : protected:
230 : ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
231 : };
232 :
233 0 : WrappedAttachedAxisProperty::WrappedAttachedAxisProperty(
234 : ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
235 : : WrappedProperty("Axis",OUString())
236 0 : , m_spChart2ModelContact( spChart2ModelContact )
237 : {
238 0 : }
239 :
240 0 : WrappedAttachedAxisProperty::~WrappedAttachedAxisProperty()
241 : {
242 0 : }
243 :
244 0 : Any WrappedAttachedAxisProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
245 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
246 : {
247 0 : Any aRet;
248 0 : aRet <<= ::com::sun::star::chart::ChartAxisAssign::PRIMARY_Y;
249 0 : return aRet;
250 : }
251 :
252 0 : Any WrappedAttachedAxisProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
253 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
254 : {
255 0 : Any aRet;
256 :
257 0 : uno::Reference< chart2::XDataSeries > xDataSeries( xInnerPropertySet, uno::UNO_QUERY );
258 0 : bool bAttachedToMainAxis = ::chart::DiagramHelper::isSeriesAttachedToMainAxis( xDataSeries );
259 0 : if( bAttachedToMainAxis )
260 0 : aRet <<= ::com::sun::star::chart::ChartAxisAssign::PRIMARY_Y;
261 : else
262 0 : aRet <<= ::com::sun::star::chart::ChartAxisAssign::SECONDARY_Y;
263 0 : return aRet;
264 : }
265 :
266 0 : void WrappedAttachedAxisProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
267 : throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
268 : {
269 0 : uno::Reference< chart2::XDataSeries > xDataSeries( xInnerPropertySet, uno::UNO_QUERY );
270 :
271 0 : sal_Int32 nChartAxisAssign = ::com::sun::star::chart::ChartAxisAssign::PRIMARY_Y;
272 0 : if( ! (rOuterValue >>= nChartAxisAssign) )
273 0 : throw lang::IllegalArgumentException("Property Axis requires value of type sal_Int32", 0, 0 );
274 :
275 0 : bool bNewAttachedToMainAxis = nChartAxisAssign == ::com::sun::star::chart::ChartAxisAssign::PRIMARY_Y;
276 0 : bool bOldAttachedToMainAxis = ::chart::DiagramHelper::isSeriesAttachedToMainAxis( xDataSeries );
277 :
278 0 : if( bNewAttachedToMainAxis != bOldAttachedToMainAxis)
279 : {
280 0 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
281 0 : if( xDiagram.is() )
282 0 : ::chart::DiagramHelper::attachSeriesToAxis( bNewAttachedToMainAxis, xDataSeries, xDiagram, m_spChart2ModelContact->m_xContext, false );
283 0 : }
284 0 : }
285 :
286 : class WrappedSegmentOffsetProperty : public ::chart::WrappedProperty
287 : {
288 : public:
289 : WrappedSegmentOffsetProperty();
290 : virtual ~WrappedSegmentOffsetProperty();
291 :
292 : protected:
293 : virtual Any convertInnerToOuterValue( const Any& rInnerValue ) const SAL_OVERRIDE;
294 : virtual Any convertOuterToInnerValue( const Any& rOuterValue ) const SAL_OVERRIDE;
295 : };
296 :
297 0 : WrappedSegmentOffsetProperty::WrappedSegmentOffsetProperty() :
298 0 : WrappedProperty("SegmentOffset","Offset")
299 0 : {}
300 :
301 0 : WrappedSegmentOffsetProperty::~WrappedSegmentOffsetProperty()
302 0 : {}
303 :
304 0 : Any WrappedSegmentOffsetProperty::convertInnerToOuterValue( const Any& rInnerValue ) const
305 : {
306 : // convert new double offset to former integer segment-offset
307 0 : double fOffset = 0;
308 0 : Any aResult( rInnerValue );
309 :
310 0 : if( rInnerValue >>= fOffset )
311 0 : aResult <<= static_cast< sal_Int32 >( ::rtl::math::round( fOffset * 100.0 ));
312 :
313 0 : return aResult;
314 : }
315 :
316 0 : Any WrappedSegmentOffsetProperty::convertOuterToInnerValue( const Any& rOuterValue ) const
317 : {
318 : // convert former integer segment-offset to new double offset
319 0 : sal_Int32 nOffset = 0;
320 0 : Any aResult( rOuterValue );
321 :
322 0 : if( rOuterValue >>= nOffset )
323 0 : aResult <<= (static_cast< double >( nOffset ) / 100.0);
324 :
325 0 : return aResult;
326 : }
327 :
328 : class WrappedLineColorProperty : public WrappedSeriesAreaOrLineProperty
329 : {
330 : public:
331 : WrappedLineColorProperty( DataSeriesPointWrapper* pDataSeriesPointWrapper );
332 : virtual ~WrappedLineColorProperty();
333 :
334 : virtual void setPropertyValue( const Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
335 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
336 :
337 : virtual void setPropertyToDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
338 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
339 :
340 : virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
341 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
342 :
343 : protected:
344 : DataSeriesPointWrapper* m_pDataSeriesPointWrapper;
345 : mutable Any m_aDefaultValue;
346 : mutable Any m_aOuterValue;
347 : };
348 :
349 0 : WrappedLineColorProperty::WrappedLineColorProperty(
350 : DataSeriesPointWrapper* pDataSeriesPointWrapper )
351 : : WrappedSeriesAreaOrLineProperty("LineColor","BorderColor","Color", pDataSeriesPointWrapper )
352 : , m_pDataSeriesPointWrapper( pDataSeriesPointWrapper )
353 : , m_aDefaultValue(uno::makeAny(sal_Int32( 0x0099ccff ))) // blue 8
354 0 : , m_aOuterValue(m_aDefaultValue)
355 : {
356 0 : }
357 :
358 0 : WrappedLineColorProperty::~WrappedLineColorProperty()
359 : {
360 0 : }
361 :
362 0 : void WrappedLineColorProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
363 : throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
364 : {
365 0 : if( m_pDataSeriesPointWrapper && m_pDataSeriesPointWrapper->isLinesForbidden() )
366 0 : m_aOuterValue = rOuterValue;
367 : else
368 0 : WrappedSeriesAreaOrLineProperty::setPropertyValue( rOuterValue, xInnerPropertySet );
369 0 : }
370 :
371 0 : void WrappedLineColorProperty::setPropertyToDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
372 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
373 : {
374 0 : if( m_pDataSeriesPointWrapper && m_pDataSeriesPointWrapper->isLinesForbidden() )
375 0 : m_aOuterValue = m_aDefaultValue;
376 : else
377 0 : WrappedSeriesAreaOrLineProperty::setPropertyToDefault( xInnerPropertyState );
378 0 : }
379 :
380 0 : Any WrappedLineColorProperty::getPropertyDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
381 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
382 : {
383 0 : if( m_pDataSeriesPointWrapper && !m_pDataSeriesPointWrapper->isSupportingAreaProperties() )
384 0 : return m_aDefaultValue;
385 : else
386 0 : return WrappedSeriesAreaOrLineProperty::getPropertyDefault( xInnerPropertyState );
387 : }
388 :
389 : class WrappedLineStyleProperty : public WrappedSeriesAreaOrLineProperty
390 : {
391 : public:
392 : WrappedLineStyleProperty( DataSeriesPointWrapper* pDataSeriesPointWrapper );
393 : virtual ~WrappedLineStyleProperty();
394 :
395 : virtual void setPropertyValue( const Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const
396 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
397 :
398 : virtual void setPropertyToDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const
399 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
400 :
401 : protected:
402 : DataSeriesPointWrapper* m_pDataSeriesPointWrapper;
403 : mutable Any m_aDefaultValue;
404 : mutable Any m_aOuterValue;
405 : };
406 :
407 0 : WrappedLineStyleProperty::WrappedLineStyleProperty(
408 : DataSeriesPointWrapper* pDataSeriesPointWrapper )
409 : : WrappedSeriesAreaOrLineProperty("LineStyle","BorderStyle", "LineStyle", pDataSeriesPointWrapper )
410 : , m_pDataSeriesPointWrapper( pDataSeriesPointWrapper )
411 : , m_aDefaultValue(uno::makeAny(drawing::LineStyle_SOLID))
412 0 : , m_aOuterValue(m_aDefaultValue)
413 : {
414 0 : }
415 :
416 0 : WrappedLineStyleProperty::~WrappedLineStyleProperty()
417 : {
418 0 : }
419 :
420 0 : void WrappedLineStyleProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
421 : throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
422 : {
423 0 : Any aNewValue(rOuterValue);
424 0 : if( m_pDataSeriesPointWrapper && m_pDataSeriesPointWrapper->isLinesForbidden() )
425 : {
426 0 : m_aOuterValue = rOuterValue;
427 0 : aNewValue = uno::makeAny(drawing::LineStyle_NONE);
428 : }
429 0 : WrappedSeriesAreaOrLineProperty::setPropertyValue( aNewValue, xInnerPropertySet );
430 0 : }
431 :
432 0 : void WrappedLineStyleProperty::setPropertyToDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
433 : throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::uno::RuntimeException)
434 : {
435 0 : if( m_pDataSeriesPointWrapper && m_pDataSeriesPointWrapper->isLinesForbidden() )
436 0 : m_aOuterValue = m_aDefaultValue;
437 : else
438 0 : WrappedSeriesAreaOrLineProperty::setPropertyToDefault( xInnerPropertyState );
439 0 : }
440 :
441 : } // anonymous namespace
442 :
443 : namespace chart
444 : {
445 : namespace wrapper
446 : {
447 :
448 0 : DataSeriesPointWrapper::DataSeriesPointWrapper(
449 : ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
450 : : m_spChart2ModelContact( spChart2ModelContact )
451 : , m_aEventListenerContainer( m_aMutex )
452 : , m_eType( DATA_SERIES )
453 : , m_nSeriesIndexInNewAPI( -1 )
454 : , m_nPointIndex( -1 )
455 : , m_bLinesAllowed(sal_True)
456 0 : , m_xDataSeries(0)
457 : {
458 : //need initialize call afterwards
459 0 : }
460 :
461 0 : void SAL_CALL DataSeriesPointWrapper::initialize( const uno::Sequence< uno::Any >& aArguments )
462 : throw ( uno::Exception, uno::RuntimeException, std::exception)
463 : {
464 : OSL_PRECOND(aArguments.getLength() >= 1,"need at least 1 argument to initialize the DataSeriesPointWrapper: series reference + optional datapoint index");
465 :
466 0 : m_nSeriesIndexInNewAPI = -1;//ignored in this case
467 0 : m_nPointIndex = -1;
468 0 : if( aArguments.getLength() >= 1 )
469 : {
470 0 : aArguments[0] >>= m_xDataSeries;
471 0 : if( aArguments.getLength() >= 2 )
472 0 : aArguments[1] >>= m_nPointIndex;
473 : }
474 :
475 0 : if( !m_xDataSeries.is() )
476 : throw uno::Exception(
477 0 : "DataSeries index invalid", static_cast< ::cppu::OWeakObject * >( this ));
478 :
479 : //todo: check upper border of point index
480 :
481 0 : if( m_nPointIndex >= 0 )
482 0 : m_eType = DATA_POINT;
483 : else
484 0 : m_eType = DATA_SERIES;
485 0 : }
486 :
487 0 : DataSeriesPointWrapper::DataSeriesPointWrapper( eType _eType,
488 : sal_Int32 nSeriesIndexInNewAPI ,
489 : sal_Int32 nPointIndex, //ignored for series
490 : ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
491 : : m_spChart2ModelContact( spChart2ModelContact )
492 : , m_aEventListenerContainer( m_aMutex )
493 : , m_eType( _eType )
494 : , m_nSeriesIndexInNewAPI( nSeriesIndexInNewAPI )
495 : , m_nPointIndex( (_eType == DATA_POINT) ? nPointIndex : -1 )
496 : , m_bLinesAllowed( sal_False )
497 0 : , m_xDataSeries(0)
498 : {
499 0 : }
500 :
501 0 : DataSeriesPointWrapper::~DataSeriesPointWrapper()
502 : {
503 0 : }
504 :
505 : // ____ XComponent ____
506 0 : void SAL_CALL DataSeriesPointWrapper::dispose()
507 : throw (uno::RuntimeException, std::exception)
508 : {
509 0 : uno::Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
510 0 : m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
511 :
512 0 : m_xDataSeries.clear();
513 0 : clearWrappedPropertySet();
514 0 : }
515 :
516 0 : void SAL_CALL DataSeriesPointWrapper::addEventListener(
517 : const uno::Reference< lang::XEventListener >& xListener )
518 : throw (uno::RuntimeException, std::exception)
519 : {
520 0 : m_aEventListenerContainer.addInterface( xListener );
521 0 : }
522 :
523 0 : void SAL_CALL DataSeriesPointWrapper::removeEventListener(
524 : const uno::Reference< lang::XEventListener >& aListener )
525 : throw (uno::RuntimeException, std::exception)
526 : {
527 0 : m_aEventListenerContainer.removeInterface( aListener );
528 0 : }
529 :
530 : // ____ XEventListener ____
531 0 : void SAL_CALL DataSeriesPointWrapper::disposing( const lang::EventObject& /*Source*/ )
532 : throw (uno::RuntimeException, std::exception)
533 : {
534 0 : }
535 :
536 0 : bool DataSeriesPointWrapper::isSupportingAreaProperties()
537 : {
538 0 : Reference< chart2::XDataSeries > xSeries( this->getDataSeries() );
539 0 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
540 0 : Reference< chart2::XChartType > xChartType( DiagramHelper::getChartTypeOfSeries( xDiagram, xSeries ) );
541 0 : sal_Int32 nDimensionCount = DiagramHelper::getDimension( xDiagram );
542 :
543 0 : return ChartTypeHelper::isSupportingAreaProperties( xChartType, nDimensionCount );
544 : }
545 :
546 0 : bool DataSeriesPointWrapper::isLinesForbidden()
547 : {
548 0 : return !m_bLinesAllowed;
549 : }
550 :
551 0 : Reference< chart2::XDataSeries > DataSeriesPointWrapper::getDataSeries()
552 : {
553 0 : Reference< chart2::XDataSeries > xSeries( m_xDataSeries );
554 0 : if( !xSeries.is() )
555 : {
556 0 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
557 : ::std::vector< uno::Reference< chart2::XDataSeries > > aSeriesList(
558 0 : ::chart::DiagramHelper::getDataSeriesFromDiagram( xDiagram ) );
559 :
560 0 : if( m_nSeriesIndexInNewAPI >= 0 && m_nSeriesIndexInNewAPI < static_cast<sal_Int32>(aSeriesList.size()) )
561 0 : xSeries = aSeriesList[m_nSeriesIndexInNewAPI];
562 : }
563 :
564 0 : return xSeries;
565 : }
566 :
567 0 : Reference< beans::XPropertySet > DataSeriesPointWrapper::getDataPointProperties()
568 : {
569 0 : Reference< beans::XPropertySet > xPointProp;
570 :
571 0 : Reference< chart2::XDataSeries > xSeries( this->getDataSeries() );
572 :
573 : // may throw an IllegalArgumentException
574 0 : if( xSeries.is() )
575 0 : xPointProp = xSeries->getDataPointByIndex( m_nPointIndex );
576 :
577 0 : return xPointProp;
578 : }
579 :
580 : //ReferenceSizePropertyProvider
581 0 : void DataSeriesPointWrapper::updateReferenceSize()
582 : {
583 0 : Reference< beans::XPropertySet > xProp( this->getInnerPropertySet(), uno::UNO_QUERY );
584 0 : if( xProp.is() )
585 : {
586 0 : if( xProp->getPropertyValue("ReferencePageSize").hasValue() )
587 0 : xProp->setPropertyValue("ReferencePageSize", uno::makeAny(
588 0 : m_spChart2ModelContact->GetPageSize() ));
589 0 : }
590 0 : }
591 0 : Any DataSeriesPointWrapper::getReferenceSize()
592 : {
593 0 : Any aRet;
594 0 : Reference< beans::XPropertySet > xProp( this->getInnerPropertySet(), uno::UNO_QUERY );
595 0 : if( xProp.is() )
596 0 : aRet = xProp->getPropertyValue("ReferencePageSize");
597 0 : return aRet;
598 : }
599 0 : awt::Size DataSeriesPointWrapper::getCurrentSizeForReference()
600 : {
601 0 : return m_spChart2ModelContact->GetPageSize();
602 : }
603 :
604 : // WrappedPropertySet
605 :
606 : //XPropertyState
607 0 : beans::PropertyState SAL_CALL DataSeriesPointWrapper::getPropertyState( const OUString& rPropertyName )
608 : throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
609 : {
610 0 : beans::PropertyState aState( beans::PropertyState_DIRECT_VALUE );
611 :
612 0 : if( m_eType == DATA_SERIES )
613 0 : aState = WrappedPropertySet::getPropertyState( rPropertyName );
614 : else
615 : {
616 0 : if( rPropertyName == "FillColor")
617 : {
618 0 : Reference< beans::XPropertySet > xSeriesProp( getDataSeries(), uno::UNO_QUERY );
619 0 : sal_Bool bVaryColorsByPoint = sal_False;
620 0 : if( xSeriesProp.is() && (xSeriesProp->getPropertyValue("VaryColorsByPoint") >>= bVaryColorsByPoint)
621 0 : && bVaryColorsByPoint )
622 0 : return beans::PropertyState_DIRECT_VALUE;
623 : }
624 0 : else if( rPropertyName == "Lines"
625 0 : || rPropertyName == "SymbolType"
626 0 : || rPropertyName == "SymbolSize" )
627 0 : return WrappedPropertySet::getPropertyState( rPropertyName );
628 :
629 0 : uno::Any aDefault( getPropertyDefault( rPropertyName ) );
630 0 : uno::Any aValue( getPropertyValue( rPropertyName ) );
631 0 : if( aDefault==aValue )
632 0 : aState = beans::PropertyState_DEFAULT_VALUE;
633 : }
634 0 : return aState;
635 : }
636 :
637 0 : void SAL_CALL DataSeriesPointWrapper::setPropertyToDefault( const OUString& rPropertyName )
638 : throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
639 : {
640 0 : if( m_eType == DATA_SERIES )
641 0 : WrappedPropertySet::setPropertyToDefault( rPropertyName );
642 : else
643 : {
644 : //for data points the default is given by the series
645 0 : setPropertyValue( rPropertyName, getPropertyDefault( rPropertyName ) );
646 : }
647 0 : }
648 0 : Any SAL_CALL DataSeriesPointWrapper::getPropertyDefault( const OUString& rPropertyName )
649 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
650 : {
651 0 : Any aRet;
652 : try
653 : {
654 0 : sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
655 0 : if( nHandle > 0 )
656 : {
657 : //always take the series current value as default for points
658 0 : Reference< beans::XPropertySet > xInnerPropertySet( getDataSeries(), uno::UNO_QUERY );
659 0 : if( xInnerPropertySet.is() )
660 : {
661 0 : const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
662 0 : if( pWrappedProperty )
663 0 : aRet = pWrappedProperty->getPropertyValue(xInnerPropertySet);
664 : else
665 0 : aRet = xInnerPropertySet->getPropertyValue( rPropertyName );
666 0 : }
667 : }
668 : }
669 0 : catch( const beans::UnknownPropertyException& )
670 : {
671 0 : aRet = WrappedPropertySet::getPropertyDefault( rPropertyName );
672 : }
673 0 : return aRet;
674 : }
675 :
676 0 : Reference< beans::XPropertySet > DataSeriesPointWrapper::getInnerPropertySet()
677 : {
678 0 : if( m_eType == DATA_SERIES )
679 0 : return Reference< beans::XPropertySet >( getDataSeries(), uno::UNO_QUERY );
680 0 : return getDataPointProperties();
681 : }
682 :
683 0 : const Sequence< beans::Property >& DataSeriesPointWrapper::getPropertySequence()
684 : {
685 0 : if( m_eType == DATA_SERIES )
686 0 : return *StaticSeriesWrapperPropertyArray::get();
687 : else
688 0 : return *StaticPointWrapperPropertyArray::get();
689 : }
690 :
691 0 : const std::vector< WrappedProperty* > DataSeriesPointWrapper::createWrappedProperties()
692 : {
693 0 : ::std::vector< ::chart::WrappedProperty* > aWrappedProperties;
694 :
695 0 : WrappedCharacterHeightProperty::addWrappedProperties( aWrappedProperties, this );
696 :
697 0 : if( m_eType == DATA_SERIES )
698 : {
699 0 : WrappedStatisticProperties::addWrappedPropertiesForSeries( aWrappedProperties, m_spChart2ModelContact );
700 0 : aWrappedProperties.push_back( new WrappedAttachedAxisProperty( m_spChart2ModelContact ) );
701 :
702 0 : WrappedNumberFormatProperty* pWrappedNumberFormatProperty = new WrappedNumberFormatProperty( m_spChart2ModelContact );
703 0 : aWrappedProperties.push_back( pWrappedNumberFormatProperty );
704 0 : aWrappedProperties.push_back( new WrappedLinkNumberFormatProperty(pWrappedNumberFormatProperty) );
705 : }
706 :
707 0 : WrappedSymbolProperties::addWrappedPropertiesForSeries( aWrappedProperties, m_spChart2ModelContact );
708 0 : WrappedDataCaptionProperties::addWrappedPropertiesForSeries( aWrappedProperties, m_spChart2ModelContact );
709 0 : WrappedScaleTextProperties::addWrappedProperties( aWrappedProperties, m_spChart2ModelContact );
710 :
711 : //add unnamed line properties (different inner names here)
712 :
713 0 : aWrappedProperties.push_back( new WrappedProperty("FillColor","Color") );
714 0 : aWrappedProperties.push_back( new WrappedLineStyleProperty( this ) );
715 0 : aWrappedProperties.push_back( new WrappedLineColorProperty( this ) );
716 0 : aWrappedProperties.push_back( new WrappedSeriesAreaOrLineProperty("LineDashName","BorderDashName","LineDashName", this ) );
717 0 : aWrappedProperties.push_back( new WrappedSeriesAreaOrLineProperty("LineTransparence","BorderTransparency","Transparency", this ) );
718 0 : aWrappedProperties.push_back( new WrappedSeriesAreaOrLineProperty("LineWidth","BorderWidth","LineWidth", this ) );
719 0 : aWrappedProperties.push_back( new WrappedProperty("FillStyle","FillStyle" ) );
720 0 : aWrappedProperties.push_back( new WrappedProperty("FillTransparence","Transparency") );
721 :
722 0 : aWrappedProperties.push_back( new WrappedIgnoreProperty("LineJoint", uno::makeAny( drawing::LineJoint_ROUND ) ) );
723 0 : aWrappedProperties.push_back( new WrappedProperty("FillTransparenceGradientName","TransparencyGradientName") );
724 0 : aWrappedProperties.push_back( new WrappedProperty("FillGradientName","GradientName") );
725 0 : aWrappedProperties.push_back( new WrappedProperty("FillGradientStepCount","GradientStepCount") );
726 0 : aWrappedProperties.push_back( new WrappedProperty("FillHatchName","HatchName") );
727 0 : aWrappedProperties.push_back( new WrappedProperty("FillBitmapName","FillBitmapName") );
728 0 : aWrappedProperties.push_back( new WrappedProperty("FillBackground","FillBackground") );
729 :
730 : //bitmap properties
731 0 : aWrappedProperties.push_back( new WrappedProperty("FillBitmapMode","FillBitmapMode") );
732 0 : aWrappedProperties.push_back( new WrappedProperty("FillBitmapSizeX","FillBitmapSizeX") );
733 0 : aWrappedProperties.push_back( new WrappedProperty("FillBitmapSizeY","FillBitmapSizeY") );
734 0 : aWrappedProperties.push_back( new WrappedProperty("FillBitmapLogicalSize","FillBitmapLogicalSize") );
735 0 : aWrappedProperties.push_back( new WrappedProperty("FillBitmapOffsetX","FillBitmapOffsetX") );
736 0 : aWrappedProperties.push_back( new WrappedProperty("FillBitmapOffsetY","FillBitmapOffsetY") );
737 0 : aWrappedProperties.push_back( new WrappedProperty("FillBitmapRectanglePoint","FillBitmapRectanglePoint") );
738 0 : aWrappedProperties.push_back( new WrappedProperty("FillBitmapPositionOffsetX","FillBitmapPositionOffsetX") );
739 0 : aWrappedProperties.push_back( new WrappedProperty("FillBitmapPositionOffsetY","FillBitmapPositionOffsetY") );
740 :
741 0 : aWrappedProperties.push_back( new WrappedProperty("SolidType","Geometry3D") );
742 0 : aWrappedProperties.push_back( new WrappedSegmentOffsetProperty() );
743 0 : aWrappedProperties.push_back( new WrappedProperty("D3DPercentDiagonal","PercentDiagonal") );
744 :
745 0 : aWrappedProperties.push_back( new WrappedTextRotationProperty() );
746 :
747 0 : return aWrappedProperties;
748 : }
749 :
750 0 : void SAL_CALL DataSeriesPointWrapper::setPropertyValue( const OUString& rPropertyName, const Any& rValue )
751 : throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
752 : {
753 0 : if(rPropertyName == "Lines")
754 : {
755 0 : if( ! (rValue >>= m_bLinesAllowed) )
756 0 : throw lang::IllegalArgumentException("Property Lines requires value of type sal_Bool", 0, 0 );
757 : }
758 :
759 0 : sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
760 0 : static const sal_Int32 nErrorCategoryHandle = getInfoHelper().getHandleByName("ErrorCategory");
761 0 : if( nErrorCategoryHandle == nHandle )
762 : {
763 0 : ::com::sun::star::chart::ChartErrorCategory aNewValue = ::com::sun::star::chart::ChartErrorCategory_NONE;
764 0 : rValue >>= aNewValue;
765 0 : Any aLow, aHigh;
766 0 : bool bSetHighAndLowValues = false;
767 0 : switch(aNewValue)
768 : {
769 : case ::com::sun::star::chart::ChartErrorCategory_CONSTANT_VALUE:
770 0 : aHigh = this->getPropertyValue("ConstantErrorHigh");
771 0 : aLow = this->getPropertyValue("ConstantErrorLow");
772 0 : bSetHighAndLowValues = true;
773 0 : break;
774 : case ::com::sun::star::chart::ChartErrorCategory_PERCENT:
775 0 : aHigh = aLow = this->getPropertyValue("PercentageError");
776 0 : bSetHighAndLowValues = true;
777 0 : break;
778 : case ::com::sun::star::chart::ChartErrorCategory_ERROR_MARGIN:
779 0 : aHigh = aLow = this->getPropertyValue("ErrorMargin");
780 0 : bSetHighAndLowValues = true;
781 0 : break;
782 : default:
783 0 : break;
784 : }
785 :
786 0 : WrappedPropertySet::setPropertyValue( rPropertyName, rValue );
787 :
788 0 : if(bSetHighAndLowValues)
789 : {
790 0 : switch(aNewValue)
791 : {
792 : case ::com::sun::star::chart::ChartErrorCategory_CONSTANT_VALUE:
793 0 : this->setPropertyValue("ConstantErrorHigh",aHigh);
794 0 : this->setPropertyValue("ConstantErrorLow",aLow);
795 0 : break;
796 : case ::com::sun::star::chart::ChartErrorCategory_PERCENT:
797 0 : this->setPropertyValue("PercentageError",aHigh);
798 0 : break;
799 : case ::com::sun::star::chart::ChartErrorCategory_ERROR_MARGIN:
800 0 : this->setPropertyValue("ErrorMargin",aHigh);
801 0 : break;
802 : default:
803 0 : break;
804 : }
805 0 : }
806 : }
807 : else
808 0 : WrappedPropertySet::setPropertyValue( rPropertyName, rValue );
809 0 : }
810 :
811 0 : Any SAL_CALL DataSeriesPointWrapper::getPropertyValue( const OUString& rPropertyName )
812 : throw ( beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
813 : {
814 0 : if( m_eType == DATA_POINT )
815 : {
816 0 : if( rPropertyName == "FillColor" )
817 : {
818 0 : Reference< beans::XPropertySet > xSeriesProp( getDataSeries(), uno::UNO_QUERY );
819 0 : sal_Bool bVaryColorsByPoint = sal_False;
820 0 : if( xSeriesProp.is() && (xSeriesProp->getPropertyValue("VaryColorsByPoint") >>= bVaryColorsByPoint)
821 0 : && bVaryColorsByPoint )
822 : {
823 0 : uno::Reference< beans::XPropertyState > xPointState( DataSeriesPointWrapper::getDataPointProperties(), uno::UNO_QUERY );
824 0 : if( xPointState.is() && xPointState->getPropertyState("Color") == beans::PropertyState_DEFAULT_VALUE )
825 : {
826 0 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
827 0 : if( xDiagram.is() )
828 : {
829 0 : Reference< chart2::XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme() );
830 0 : if( xColorScheme.is() )
831 0 : return uno::makeAny( xColorScheme->getColorByIndex( m_nPointIndex ) );
832 0 : }
833 0 : }
834 0 : }
835 : }
836 : }
837 0 : return WrappedPropertySet::getPropertyValue( rPropertyName );
838 : }
839 :
840 0 : uno::Sequence< OUString > DataSeriesPointWrapper::getSupportedServiceNames_Static()
841 : {
842 0 : uno::Sequence< OUString > aServices( 7 );
843 0 : aServices[ 0 ] = "com.sun.star.chart.ChartDataRowProperties";
844 0 : aServices[ 1 ] = "com.sun.star.chart.ChartDataPointProperties";
845 0 : aServices[ 2 ] = "com.sun.star.xml.UserDefinedAttributesSupplier";
846 0 : aServices[ 3 ] = "com.sun.star.beans.PropertySet";
847 0 : aServices[ 4 ] = "com.sun.star.drawing.FillProperties";
848 0 : aServices[ 5 ] = "com.sun.star.drawing.LineProperties";
849 0 : aServices[ 6 ] = "com.sun.star.style.CharacterProperties";
850 :
851 0 : return aServices;
852 : }
853 :
854 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
855 0 : APPHELPER_XSERVICEINFO_IMPL( DataSeriesPointWrapper, lcl_aServiceName );
856 :
857 : } // namespace wrapper
858 0 : } // namespace chart
859 :
860 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|