Avoid potential negative array index access to cached text.
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / DataSeriesPointWrapper.cxx
blobac9a53ce331f3accfde6f87a746cbdfeb3ba5e1b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "DataSeriesPointWrapper.hxx"
21 #include "Chart2ModelContact.hxx"
22 #include <ChartType.hxx>
23 #include <ChartTypeHelper.hxx>
24 #include <DiagramHelper.hxx>
25 #include <DataSeries.hxx>
26 #include <DataSeriesProperties.hxx>
27 #include <LinePropertiesHelper.hxx>
28 #include <FillProperties.hxx>
29 #include <CharacterProperties.hxx>
30 #include <UserDefinedProperties.hxx>
31 #include "WrappedCharacterHeightProperty.hxx"
32 #include <WrappedProperty.hxx>
33 #include <WrappedIgnoreProperty.hxx>
34 #include "WrappedStatisticProperties.hxx"
35 #include "WrappedSymbolProperties.hxx"
36 #include "WrappedDataCaptionProperties.hxx"
37 #include "WrappedSeriesAreaOrLineProperty.hxx"
38 #include "WrappedScaleTextProperties.hxx"
39 #include "WrappedNumberFormatProperty.hxx"
40 #include "WrappedTextRotationProperty.hxx"
41 #include <unonames.hxx>
43 #include <o3tl/safeint.hxx>
44 #include <rtl/math.hxx>
46 #include <algorithm>
47 #include <cppuhelper/supportsservice.hxx>
48 #include <com/sun/star/beans/PropertyAttribute.hpp>
49 #include <com/sun/star/chart/ChartAxisAssign.hpp>
50 #include <com/sun/star/chart/ChartErrorCategory.hpp>
51 #include <com/sun/star/chart/ChartSymbolType.hpp>
52 #include <com/sun/star/chart2/XDataSeries.hpp>
53 #include <com/sun/star/drawing/LineJoint.hpp>
54 #include <com/sun/star/drawing/LineStyle.hpp>
55 #include <com/sun/star/drawing/FillStyle.hpp>
56 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
57 #include <comphelper/sequence.hxx>
58 #include <cppuhelper/exc_hlp.hxx>
59 #include <cppuhelper/propshlp.hxx>
61 using namespace ::com::sun::star;
62 using namespace ::chart::wrapper;
63 using namespace ::chart::DataSeriesProperties;
65 using ::com::sun::star::uno::Reference;
66 using ::com::sun::star::uno::Sequence;
67 using ::com::sun::star::beans::Property;
68 using ::com::sun::star::uno::Any;
70 namespace
73 enum
75 //data point properties
76 PROP_SERIES_DATAPOINT_SOLIDTYPE,
77 PROP_SERIES_DATAPOINT_SEGMENT_OFFSET,
78 PROP_SERIES_DATAPOINT_PERCENT_DIAGONAL,
79 PROP_SERIES_DATAPOINT_LABEL_SEPARATOR,
80 PROP_SERIES_NUMBERFORMAT,
81 PROP_SERIES_LINK_NUMBERFORMAT_TO_SOURCE,
82 PROP_SERIES_PERCENTAGE_NUMBERFORMAT,
83 PROP_SERIES_DATAPOINT_TEXT_WORD_WRAP,
84 PROP_SERIES_DATAPOINT_LABEL_PLACEMENT,
85 //other series properties
86 PROP_SERIES_ATTACHED_AXIS,
87 PROP_SERIES_SHOW_CUSTOM_LEADERLINES,
88 PROP_SERIES_DATAPOINT_TEXT_ROTATION,
89 PROP_SERIES_DATAPOINT_LABEL_BORDER_STYLE,
90 PROP_SERIES_DATAPOINT_LABEL_BORDER_WIDTH,
91 PROP_SERIES_DATAPOINT_LABEL_BORDER_COLOR,
92 PROP_SERIES_DATAPOINT_LABEL_BORDER_TRANS,
93 PROP_SERIES_DATAPOINT_LABEL_FILL_STYLE,
94 PROP_SERIES_DATAPOINT_LABEL_FILL_COLOR,
95 PROP_SERIES_DATAPOINT_LABEL_FILL_BACKGROUND,
96 PROP_SERIES_DATAPOINT_LABEL_FILL_HATCH_NAME
99 void lcl_AddPropertiesToVector_PointProperties(
100 std::vector< Property > & rOutProperties )
102 //service chart::Chart3DBarProperties
103 rOutProperties.emplace_back( "SolidType",
104 PROP_SERIES_DATAPOINT_SOLIDTYPE,
105 cppu::UnoType<sal_Int32>::get(),
106 beans::PropertyAttribute::BOUND
107 | beans::PropertyAttribute::MAYBEDEFAULT );
109 rOutProperties.emplace_back( "SegmentOffset",
110 PROP_SERIES_DATAPOINT_SEGMENT_OFFSET,
111 cppu::UnoType<sal_Int32>::get(),
112 beans::PropertyAttribute::BOUND
113 | beans::PropertyAttribute::MAYBEDEFAULT );
115 rOutProperties.emplace_back( "D3DPercentDiagonal",
116 PROP_SERIES_DATAPOINT_PERCENT_DIAGONAL,
117 cppu::UnoType<sal_Int16>::get(),
118 beans::PropertyAttribute::BOUND
119 | beans::PropertyAttribute::MAYBEVOID );
121 rOutProperties.emplace_back( "LabelSeparator",
122 PROP_SERIES_DATAPOINT_LABEL_SEPARATOR,
123 cppu::UnoType<OUString>::get(),
124 beans::PropertyAttribute::BOUND
125 | beans::PropertyAttribute::MAYBEDEFAULT );
127 rOutProperties.emplace_back( CHART_UNONAME_NUMFMT,
128 PROP_SERIES_NUMBERFORMAT,
129 cppu::UnoType<sal_Int32>::get(),
130 beans::PropertyAttribute::BOUND
131 | beans::PropertyAttribute::MAYBEVOID );
133 rOutProperties.emplace_back( CHART_UNONAME_LINK_TO_SRC_NUMFMT,
134 PROP_SERIES_LINK_NUMBERFORMAT_TO_SOURCE,
135 cppu::UnoType<bool>::get(),
136 beans::PropertyAttribute::BOUND
137 | beans::PropertyAttribute::MAYBEDEFAULT );
139 rOutProperties.emplace_back( "PercentageNumberFormat",
140 PROP_SERIES_PERCENTAGE_NUMBERFORMAT,
141 cppu::UnoType<sal_Int32>::get(),
142 beans::PropertyAttribute::BOUND
143 | beans::PropertyAttribute::MAYBEVOID );
145 rOutProperties.emplace_back( "TextWordWrap",
146 PROP_SERIES_DATAPOINT_TEXT_WORD_WRAP,
147 cppu::UnoType<bool>::get(),
148 beans::PropertyAttribute::BOUND
149 | beans::PropertyAttribute::MAYBEVOID );
151 rOutProperties.emplace_back( "LabelPlacement",
152 PROP_SERIES_DATAPOINT_LABEL_PLACEMENT,
153 cppu::UnoType<sal_Int32>::get(),
154 beans::PropertyAttribute::BOUND
155 | beans::PropertyAttribute::MAYBEVOID );
157 rOutProperties.emplace_back( "TextRotation",
158 PROP_SERIES_DATAPOINT_TEXT_ROTATION,
159 cppu::UnoType<sal_Int32>::get(),
160 beans::PropertyAttribute::BOUND
161 | beans::PropertyAttribute::MAYBEDEFAULT );
163 rOutProperties.emplace_back( CHART_UNONAME_LABEL_BORDER_STYLE,
164 PROP_SERIES_DATAPOINT_LABEL_BORDER_STYLE,
165 cppu::UnoType<drawing::LineStyle>::get(),
166 beans::PropertyAttribute::BOUND
167 | beans::PropertyAttribute::MAYBEDEFAULT );
169 rOutProperties.emplace_back( CHART_UNONAME_LABEL_FILL_STYLE,
170 PROP_SERIES_DATAPOINT_LABEL_FILL_STYLE,
171 cppu::UnoType<drawing::FillStyle>::get(),
172 beans::PropertyAttribute::BOUND
173 | beans::PropertyAttribute::MAYBEDEFAULT );
175 rOutProperties.emplace_back( CHART_UNONAME_LABEL_FILL_COLOR,
176 PROP_SERIES_DATAPOINT_LABEL_FILL_COLOR,
177 cppu::UnoType<sal_Int32>::get(),
178 beans::PropertyAttribute::BOUND
179 | beans::PropertyAttribute::MAYBEVOID
180 | beans::PropertyAttribute::MAYBEDEFAULT );
182 rOutProperties.emplace_back( CHART_UNONAME_LABEL_FILL_BACKGROUND,
183 PROP_SERIES_DATAPOINT_LABEL_FILL_BACKGROUND,
184 cppu::UnoType<sal_Bool>::get(),
185 beans::PropertyAttribute::BOUND
186 | beans::PropertyAttribute::MAYBEDEFAULT );
187 rOutProperties.emplace_back( CHART_UNONAME_LABEL_FILL_HATCH_NAME,
188 PROP_SERIES_DATAPOINT_LABEL_FILL_HATCH_NAME,
189 cppu::UnoType<OUString>::get(),
190 beans::PropertyAttribute::BOUND
191 | beans::PropertyAttribute::MAYBEDEFAULT );
192 rOutProperties.emplace_back( CHART_UNONAME_LABEL_BORDER_WIDTH,
193 PROP_SERIES_DATAPOINT_LABEL_BORDER_WIDTH,
194 cppu::UnoType<sal_Int32>::get(),
195 beans::PropertyAttribute::BOUND
196 | beans::PropertyAttribute::MAYBEDEFAULT );
198 rOutProperties.emplace_back( CHART_UNONAME_LABEL_BORDER_COLOR,
199 PROP_SERIES_DATAPOINT_LABEL_BORDER_COLOR,
200 cppu::UnoType<sal_Int32>::get(),
201 beans::PropertyAttribute::BOUND
202 | beans::PropertyAttribute::MAYBEVOID // "maybe auto"
203 | beans::PropertyAttribute::MAYBEDEFAULT );
205 rOutProperties.emplace_back( CHART_UNONAME_LABEL_BORDER_TRANS,
206 PROP_SERIES_DATAPOINT_LABEL_BORDER_TRANS,
207 cppu::UnoType<sal_Int16>::get(),
208 beans::PropertyAttribute::BOUND
209 | beans::PropertyAttribute::MAYBEDEFAULT );
212 void lcl_AddPropertiesToVector_SeriesOnly(
213 std::vector< Property > & rOutProperties )
215 rOutProperties.emplace_back( "Axis",
216 PROP_SERIES_ATTACHED_AXIS,
217 cppu::UnoType<sal_Int32>::get(),
218 beans::PropertyAttribute::BOUND
219 | beans::PropertyAttribute::MAYBEDEFAULT );
221 rOutProperties.emplace_back( "ShowCustomLeaderLines",
222 PROP_SERIES_SHOW_CUSTOM_LEADERLINES,
223 cppu::UnoType<sal_Bool>::get(),
224 beans::PropertyAttribute::BOUND
225 | beans::PropertyAttribute::MAYBEDEFAULT );
228 uno::Sequence< Property > lcl_GetPropertySequence( DataSeriesPointWrapper::eType _eType )
230 std::vector< css::beans::Property > aProperties;
232 lcl_AddPropertiesToVector_PointProperties( aProperties );
233 if( _eType == DataSeriesPointWrapper::DATA_SERIES )
235 lcl_AddPropertiesToVector_SeriesOnly( aProperties );
236 WrappedStatisticProperties::addProperties( aProperties );
238 WrappedSymbolProperties::addProperties( aProperties ); //for series and points
239 WrappedDataCaptionProperties::addProperties( aProperties ); //for series and points
241 ::chart::FillProperties::AddPropertiesToVector( aProperties );
242 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
243 ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
244 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
245 ::chart::wrapper::WrappedScaleTextProperties::addProperties( aProperties );
247 std::sort( aProperties.begin(), aProperties.end(), ::chart::PropertyNameLess() );
249 return comphelper::containerToSequence( aProperties );
252 const Sequence< Property >& StaticSeriesWrapperPropertyArray()
254 static Sequence< Property > aPropSeq( lcl_GetPropertySequence( DataSeriesPointWrapper::DATA_SERIES ) );
255 return aPropSeq;
258 const Sequence< Property >& StaticPointWrapperPropertyArray()
260 static Sequence< Property > aPropSeq( lcl_GetPropertySequence( DataSeriesPointWrapper::DATA_POINT ) );
261 return aPropSeq;
264 //PROP_SERIES_ATTACHED_AXIS
265 class WrappedAttachedAxisProperty : public ::chart::WrappedProperty
267 public:
268 explicit WrappedAttachedAxisProperty(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact);
270 virtual void setPropertyValue( const Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
272 virtual Any getPropertyValue( const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
274 virtual Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
276 protected:
277 std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact;
280 WrappedAttachedAxisProperty::WrappedAttachedAxisProperty(
281 const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact )
282 : WrappedProperty("Axis",OUString())
283 , m_spChart2ModelContact( spChart2ModelContact )
287 Any WrappedAttachedAxisProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
289 Any aRet;
290 aRet <<= css::chart::ChartAxisAssign::PRIMARY_Y;
291 return aRet;
294 Any WrappedAttachedAxisProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
296 Any aRet;
298 rtl::Reference< ::chart::DataSeries > xDataSeries( dynamic_cast<::chart::DataSeries*>(xInnerPropertySet.get()) );
299 bool bAttachedToMainAxis = ::chart::DiagramHelper::isSeriesAttachedToMainAxis( xDataSeries );
300 if( bAttachedToMainAxis )
301 aRet <<= css::chart::ChartAxisAssign::PRIMARY_Y;
302 else
303 aRet <<= css::chart::ChartAxisAssign::SECONDARY_Y;
304 return aRet;
307 void WrappedAttachedAxisProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
309 rtl::Reference< ::chart::DataSeries > xDataSeries( dynamic_cast<::chart::DataSeries*>(xInnerPropertySet.get()) );
311 sal_Int32 nChartAxisAssign = css::chart::ChartAxisAssign::PRIMARY_Y;
312 if( ! (rOuterValue >>= nChartAxisAssign) )
313 throw lang::IllegalArgumentException("Property Axis requires value of type sal_Int32", nullptr, 0 );
315 bool bNewAttachedToMainAxis = nChartAxisAssign == css::chart::ChartAxisAssign::PRIMARY_Y;
316 bool bOldAttachedToMainAxis = ::chart::DiagramHelper::isSeriesAttachedToMainAxis( xDataSeries );
318 if( bNewAttachedToMainAxis != bOldAttachedToMainAxis)
320 rtl::Reference< ::chart::Diagram > xDiagram( m_spChart2ModelContact->getDiagram() );
321 if( xDiagram.is() )
322 xDiagram->attachSeriesToAxis( bNewAttachedToMainAxis, xDataSeries, m_spChart2ModelContact->m_xContext, false );
326 class WrappedSegmentOffsetProperty : public ::chart::WrappedProperty
328 public:
329 WrappedSegmentOffsetProperty();
331 protected:
332 virtual Any convertInnerToOuterValue( const Any& rInnerValue ) const override;
333 virtual Any convertOuterToInnerValue( const Any& rOuterValue ) const override;
336 WrappedSegmentOffsetProperty::WrappedSegmentOffsetProperty() :
337 WrappedProperty("SegmentOffset","Offset")
340 Any WrappedSegmentOffsetProperty::convertInnerToOuterValue( const Any& rInnerValue ) const
342 // convert new double offset to former integer segment-offset
343 double fOffset = 0;
344 Any aResult( rInnerValue );
346 if( rInnerValue >>= fOffset )
347 aResult <<= static_cast< sal_Int32 >( ::rtl::math::round( fOffset * 100.0 ));
349 return aResult;
352 Any WrappedSegmentOffsetProperty::convertOuterToInnerValue( const Any& rOuterValue ) const
354 // convert former integer segment-offset to new double offset
355 sal_Int32 nOffset = 0;
356 Any aResult( rOuterValue );
358 if( rOuterValue >>= nOffset )
359 aResult <<= static_cast< double >( nOffset ) / 100.0;
361 return aResult;
364 class WrappedLineColorProperty : public WrappedSeriesAreaOrLineProperty
366 public:
367 explicit WrappedLineColorProperty( DataSeriesPointWrapper* pDataSeriesPointWrapper );
369 virtual void setPropertyValue( const Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
371 virtual void setPropertyToDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
373 virtual css::uno::Any getPropertyDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
375 protected:
376 DataSeriesPointWrapper* m_pDataSeriesPointWrapper;
377 mutable Any m_aDefaultValue;
380 WrappedLineColorProperty::WrappedLineColorProperty(
381 DataSeriesPointWrapper* pDataSeriesPointWrapper )
382 : WrappedSeriesAreaOrLineProperty("LineColor","BorderColor","Color", pDataSeriesPointWrapper )
383 , m_pDataSeriesPointWrapper( pDataSeriesPointWrapper )
384 , m_aDefaultValue(uno::Any(sal_Int32( 0x0099ccff ))) // blue 8
388 void WrappedLineColorProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
390 if( !m_pDataSeriesPointWrapper || !m_pDataSeriesPointWrapper->isLinesForbidden() )
391 WrappedSeriesAreaOrLineProperty::setPropertyValue( rOuterValue, xInnerPropertySet );
394 void WrappedLineColorProperty::setPropertyToDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
396 if( !m_pDataSeriesPointWrapper || !m_pDataSeriesPointWrapper->isLinesForbidden() )
397 WrappedSeriesAreaOrLineProperty::setPropertyToDefault( xInnerPropertyState );
400 Any WrappedLineColorProperty::getPropertyDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
402 if( m_pDataSeriesPointWrapper && !m_pDataSeriesPointWrapper->isSupportingAreaProperties() )
403 return m_aDefaultValue;
404 else
405 return WrappedSeriesAreaOrLineProperty::getPropertyDefault( xInnerPropertyState );
408 class WrappedLineStyleProperty : public WrappedSeriesAreaOrLineProperty
410 public:
411 explicit WrappedLineStyleProperty( DataSeriesPointWrapper* pDataSeriesPointWrapper );
413 virtual void setPropertyValue( const Any& rOuterValue, const css::uno::Reference< css::beans::XPropertySet >& xInnerPropertySet ) const override;
415 virtual void setPropertyToDefault( const css::uno::Reference< css::beans::XPropertyState >& xInnerPropertyState ) const override;
417 protected:
418 DataSeriesPointWrapper* m_pDataSeriesPointWrapper;
421 WrappedLineStyleProperty::WrappedLineStyleProperty(
422 DataSeriesPointWrapper* pDataSeriesPointWrapper )
423 : WrappedSeriesAreaOrLineProperty("LineStyle","BorderStyle", "LineStyle", pDataSeriesPointWrapper )
424 , m_pDataSeriesPointWrapper( pDataSeriesPointWrapper )
428 void WrappedLineStyleProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
430 Any aNewValue(rOuterValue);
431 if( m_pDataSeriesPointWrapper && m_pDataSeriesPointWrapper->isLinesForbidden() )
433 aNewValue <<= drawing::LineStyle_NONE;
435 WrappedSeriesAreaOrLineProperty::setPropertyValue( aNewValue, xInnerPropertySet );
438 void WrappedLineStyleProperty::setPropertyToDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const
440 if( !m_pDataSeriesPointWrapper || !m_pDataSeriesPointWrapper->isLinesForbidden() )
441 WrappedSeriesAreaOrLineProperty::setPropertyToDefault( xInnerPropertyState );
444 } // anonymous namespace
446 namespace chart::wrapper
449 DataSeriesPointWrapper::DataSeriesPointWrapper( std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
450 : m_spChart2ModelContact( std::move(spChart2ModelContact) )
451 , m_eType( DATA_SERIES )
452 , m_nSeriesIndexInNewAPI( -1 )
453 , m_nPointIndex( -1 )
454 , m_bLinesAllowed(true)
456 //need initialize call afterwards
459 void SAL_CALL DataSeriesPointWrapper::initialize( const uno::Sequence< uno::Any >& aArguments )
461 OSL_PRECOND(aArguments.hasElements(),"need at least 1 argument to initialize the DataSeriesPointWrapper: series reference + optional datapoint index");
463 m_nSeriesIndexInNewAPI = -1;//ignored in this case
464 m_nPointIndex = -1;
465 if( aArguments.hasElements() )
467 uno::Reference<chart2::XDataSeries> xTmp;
468 aArguments[0] >>= xTmp;
469 auto p = dynamic_cast<DataSeries*>(xTmp.get());
470 assert(p);
471 m_xDataSeries = p;
472 if( aArguments.getLength() >= 2 )
473 aArguments[1] >>= m_nPointIndex;
476 if( !m_xDataSeries.is() )
477 throw uno::Exception(
478 "DataSeries index invalid", static_cast< ::cppu::OWeakObject * >( this ));
480 //todo: check upper border of point index
482 if( m_nPointIndex >= 0 )
483 m_eType = DATA_POINT;
484 else
485 m_eType = DATA_SERIES;
488 DataSeriesPointWrapper::DataSeriesPointWrapper(eType _eType,
489 sal_Int32 nSeriesIndexInNewAPI ,
490 sal_Int32 nPointIndex, //ignored for series
491 std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
492 : m_spChart2ModelContact( std::move(spChart2ModelContact) )
493 , m_eType( _eType )
494 , m_nSeriesIndexInNewAPI( nSeriesIndexInNewAPI )
495 , m_nPointIndex( (_eType == DATA_POINT) ? nPointIndex : -1 )
496 , m_bLinesAllowed( false )
500 DataSeriesPointWrapper::~DataSeriesPointWrapper()
504 // ____ XComponent ____
505 void SAL_CALL DataSeriesPointWrapper::dispose()
507 std::unique_lock g(m_aMutex);
508 uno::Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
509 m_aEventListenerContainer.disposeAndClear( g, lang::EventObject( xSource ) );
511 m_xDataSeries.clear();
512 clearWrappedPropertySet();
515 void SAL_CALL DataSeriesPointWrapper::addEventListener(
516 const uno::Reference< lang::XEventListener >& xListener )
518 std::unique_lock g(m_aMutex);
519 m_aEventListenerContainer.addInterface( g, xListener );
522 void SAL_CALL DataSeriesPointWrapper::removeEventListener(
523 const uno::Reference< lang::XEventListener >& aListener )
525 std::unique_lock g(m_aMutex);
526 m_aEventListenerContainer.removeInterface( g, aListener );
529 // ____ XEventListener ____
530 void SAL_CALL DataSeriesPointWrapper::disposing( const lang::EventObject& /*Source*/ )
534 bool DataSeriesPointWrapper::isSupportingAreaProperties()
536 rtl::Reference< DataSeries > xSeries( getDataSeries() );
537 rtl::Reference< ::chart::Diagram > xDiagram( m_spChart2ModelContact->getDiagram() );
538 rtl::Reference< ::chart::ChartType > xChartType( xDiagram->getChartTypeOfSeries( xSeries ) );
539 sal_Int32 nDimensionCount = xDiagram->getDimension();
541 return ChartTypeHelper::isSupportingAreaProperties( xChartType, nDimensionCount );
544 rtl::Reference< DataSeries > DataSeriesPointWrapper::getDataSeries()
546 rtl::Reference< DataSeries > xSeries = m_xDataSeries;
547 if( !xSeries.is() )
549 rtl::Reference< ::chart::Diagram > xDiagram( m_spChart2ModelContact->getDiagram() );
550 std::vector< rtl::Reference< DataSeries > > aSeriesList =
551 xDiagram->getDataSeries();
553 if( m_nSeriesIndexInNewAPI >= 0 && o3tl::make_unsigned(m_nSeriesIndexInNewAPI) < aSeriesList.size() )
554 xSeries = aSeriesList[m_nSeriesIndexInNewAPI];
557 return xSeries;
560 Reference< beans::XPropertySet > DataSeriesPointWrapper::getDataPointProperties()
562 Reference< beans::XPropertySet > xPointProp;
564 rtl::Reference< DataSeries > xSeries( getDataSeries() );
566 // may throw an IllegalArgumentException
567 if( xSeries.is() )
568 xPointProp = xSeries->getDataPointByIndex( m_nPointIndex );
570 return xPointProp;
573 //ReferenceSizePropertyProvider
574 void DataSeriesPointWrapper::updateReferenceSize()
576 Reference< beans::XPropertySet > xProp = getInnerPropertySet();
577 if( xProp.is() )
579 if( xProp->getPropertyValue("ReferencePageSize").hasValue() )
580 xProp->setPropertyValue("ReferencePageSize", uno::Any(
581 m_spChart2ModelContact->GetPageSize() ));
584 Any DataSeriesPointWrapper::getReferenceSize()
586 Any aRet;
587 Reference< beans::XPropertySet > xProp = getInnerPropertySet();
588 if( xProp.is() )
589 aRet = xProp->getPropertyValue("ReferencePageSize");
590 return aRet;
592 awt::Size DataSeriesPointWrapper::getCurrentSizeForReference()
594 return m_spChart2ModelContact->GetPageSize();
597 // WrappedPropertySet
599 //XPropertyState
600 beans::PropertyState SAL_CALL DataSeriesPointWrapper::getPropertyState( const OUString& rPropertyName )
602 beans::PropertyState aState( beans::PropertyState_DIRECT_VALUE );
605 if (rPropertyName == "SymbolBitmap" || rPropertyName == "SymbolBitmapURL")
607 uno::Any aAny = WrappedPropertySet::getPropertyValue("SymbolType");
608 sal_Int32 nVal = css::chart::ChartSymbolType::NONE;
609 if (aAny >>= nVal)
611 if (nVal != css::chart::ChartSymbolType::BITMAPURL)
612 return beans::PropertyState::PropertyState_DEFAULT_VALUE;
616 if( m_eType == DATA_SERIES )
617 aState = WrappedPropertySet::getPropertyState( rPropertyName );
618 else
620 if( rPropertyName == "FillColor")
622 rtl::Reference< DataSeries > xSeries = getDataSeries();
623 bool bVaryColorsByPoint = false;
624 // "VaryColorsByPoint"
625 if( xSeries.is() && (xSeries->getFastPropertyValue(PROP_DATASERIES_VARY_COLORS_BY_POINT) >>= bVaryColorsByPoint)
626 && bVaryColorsByPoint )
627 return beans::PropertyState_DIRECT_VALUE;
629 else if( rPropertyName == "Lines"
630 || rPropertyName == "SymbolType"
631 || rPropertyName == "SymbolSize" )
632 return WrappedPropertySet::getPropertyState( rPropertyName );
634 uno::Any aDefault( getPropertyDefault( rPropertyName ) );
635 uno::Any aValue( getPropertyValue( rPropertyName ) );
636 if( aDefault==aValue )
637 aState = beans::PropertyState_DEFAULT_VALUE;
640 catch( const beans::UnknownPropertyException& )
642 throw;
644 catch( const uno::RuntimeException& )
646 throw;
648 catch( const lang::WrappedTargetException& e )
650 css::uno::Any a(e.TargetException);
651 throw css::lang::WrappedTargetRuntimeException(
652 "wrapped Exception " + e.Message,
653 css::uno::Reference<css::uno::XInterface>(), a);
655 catch( const uno::Exception& e )
657 css::uno::Any a(cppu::getCaughtException());
658 throw css::lang::WrappedTargetRuntimeException(
659 "wrapped Exception " + e.Message,
660 css::uno::Reference<css::uno::XInterface>(), a);
662 return aState;
665 void SAL_CALL DataSeriesPointWrapper::setPropertyToDefault( const OUString& rPropertyName )
667 if( m_eType == DATA_SERIES )
668 WrappedPropertySet::setPropertyToDefault( rPropertyName );
669 else
671 //for data points the default is given by the series
672 setPropertyValue( rPropertyName, getPropertyDefault( rPropertyName ) );
675 Any SAL_CALL DataSeriesPointWrapper::getPropertyDefault( const OUString& rPropertyName )
677 Any aRet;
680 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
681 if( nHandle > 0 )
683 //always take the series current value as default for points
684 rtl::Reference< DataSeries > xInnerPropertySet = getDataSeries();
685 if( xInnerPropertySet.is() )
687 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
688 if( pWrappedProperty )
689 aRet = pWrappedProperty->getPropertyValue(xInnerPropertySet);
690 else
691 aRet = xInnerPropertySet->getPropertyValue( rPropertyName );
695 catch( const beans::UnknownPropertyException& )
697 aRet = WrappedPropertySet::getPropertyDefault( rPropertyName );
699 return aRet;
702 Reference< beans::XPropertySet > DataSeriesPointWrapper::getInnerPropertySet()
704 if( m_eType == DATA_SERIES )
705 return getDataSeries();
706 return getDataPointProperties();
709 const Sequence< beans::Property >& DataSeriesPointWrapper::getPropertySequence()
711 if( m_eType == DATA_SERIES )
712 return StaticSeriesWrapperPropertyArray();
713 else
714 return StaticPointWrapperPropertyArray();
717 std::vector< std::unique_ptr<WrappedProperty> > DataSeriesPointWrapper::createWrappedProperties()
719 std::vector< std::unique_ptr<WrappedProperty> > aWrappedProperties;
721 WrappedCharacterHeightProperty::addWrappedProperties( aWrappedProperties, this );
723 if( m_eType == DATA_SERIES )
725 WrappedStatisticProperties::addWrappedPropertiesForSeries( aWrappedProperties, m_spChart2ModelContact );
726 aWrappedProperties.emplace_back( new WrappedAttachedAxisProperty( m_spChart2ModelContact ) );
728 aWrappedProperties.emplace_back( new WrappedNumberFormatProperty(m_spChart2ModelContact) );
729 aWrappedProperties.emplace_back( new WrappedLinkNumberFormatProperty );
732 WrappedSymbolProperties::addWrappedPropertiesForSeries( aWrappedProperties, m_spChart2ModelContact );
733 WrappedDataCaptionProperties::addWrappedPropertiesForSeries( aWrappedProperties, m_spChart2ModelContact );
734 WrappedScaleTextProperties::addWrappedProperties( aWrappedProperties, m_spChart2ModelContact );
736 //add unnamed line properties (different inner names here)
738 aWrappedProperties.emplace_back( new WrappedProperty("FillColor","Color") );
739 aWrappedProperties.emplace_back( new WrappedLineStyleProperty( this ) );
740 aWrappedProperties.emplace_back( new WrappedLineColorProperty( this ) );
741 aWrappedProperties.emplace_back( new WrappedSeriesAreaOrLineProperty("LineDashName","BorderDashName","LineDashName", this ) );
742 aWrappedProperties.emplace_back( new WrappedSeriesAreaOrLineProperty("LineTransparence","BorderTransparency","Transparency", this ) );
743 aWrappedProperties.emplace_back( new WrappedSeriesAreaOrLineProperty("LineWidth","BorderWidth","LineWidth", this ) );
744 aWrappedProperties.emplace_back( new WrappedSeriesAreaOrLineProperty("LineCap","LineCap","LineCap", this ) );
745 aWrappedProperties.emplace_back( new WrappedProperty("FillStyle","FillStyle" ) );
746 aWrappedProperties.emplace_back( new WrappedProperty("FillTransparence","Transparency") );
748 aWrappedProperties.emplace_back( new WrappedIgnoreProperty("LineJoint", uno::Any( drawing::LineJoint_ROUND ) ) );
749 aWrappedProperties.emplace_back( new WrappedProperty("FillTransparenceGradientName","TransparencyGradientName") );
750 aWrappedProperties.emplace_back( new WrappedProperty("FillGradientName","GradientName") );
751 aWrappedProperties.emplace_back( new WrappedProperty("FillGradientStepCount","GradientStepCount") );
752 aWrappedProperties.emplace_back( new WrappedProperty("FillHatchName","HatchName") );
753 aWrappedProperties.emplace_back( new WrappedProperty("FillBitmapName","FillBitmapName") );
754 aWrappedProperties.emplace_back( new WrappedProperty("FillBackground","FillBackground") );
756 //bitmap properties
757 aWrappedProperties.emplace_back( new WrappedProperty("FillBitmapMode","FillBitmapMode") );
758 aWrappedProperties.emplace_back( new WrappedProperty("FillBitmapSizeX","FillBitmapSizeX") );
759 aWrappedProperties.emplace_back( new WrappedProperty("FillBitmapSizeY","FillBitmapSizeY") );
760 aWrappedProperties.emplace_back( new WrappedProperty("FillBitmapLogicalSize","FillBitmapLogicalSize") );
761 aWrappedProperties.emplace_back( new WrappedProperty("FillBitmapOffsetX","FillBitmapOffsetX") );
762 aWrappedProperties.emplace_back( new WrappedProperty("FillBitmapOffsetY","FillBitmapOffsetY") );
763 aWrappedProperties.emplace_back( new WrappedProperty("FillBitmapRectanglePoint","FillBitmapRectanglePoint") );
764 aWrappedProperties.emplace_back( new WrappedProperty("FillBitmapPositionOffsetX","FillBitmapPositionOffsetX") );
765 aWrappedProperties.emplace_back( new WrappedProperty("FillBitmapPositionOffsetY","FillBitmapPositionOffsetY") );
767 aWrappedProperties.emplace_back( new WrappedProperty("SolidType","Geometry3D") );
768 aWrappedProperties.emplace_back( new WrappedSegmentOffsetProperty() );
769 aWrappedProperties.emplace_back( new WrappedProperty("D3DPercentDiagonal","PercentDiagonal") );
771 aWrappedProperties.emplace_back( new WrappedTextRotationProperty() );
773 return aWrappedProperties;
776 void SAL_CALL DataSeriesPointWrapper::setPropertyValue( const OUString& rPropertyName, const Any& rValue )
778 if(rPropertyName == "Lines")
780 if( ! (rValue >>= m_bLinesAllowed) )
781 throw lang::IllegalArgumentException("Property Lines requires value of type sal_Bool", nullptr, 0 );
784 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
785 static const sal_Int32 nErrorCategoryHandle = getInfoHelper().getHandleByName("ErrorCategory");
786 if( nErrorCategoryHandle == nHandle )
788 css::chart::ChartErrorCategory aNewValue = css::chart::ChartErrorCategory_NONE;
789 rValue >>= aNewValue;
790 Any aLow, aHigh;
791 bool bSetHighAndLowValues = false;
792 switch(aNewValue)
794 case css::chart::ChartErrorCategory_CONSTANT_VALUE:
795 aHigh = getPropertyValue("ConstantErrorHigh");
796 aLow = getPropertyValue("ConstantErrorLow");
797 bSetHighAndLowValues = true;
798 break;
799 case css::chart::ChartErrorCategory_PERCENT:
800 aHigh = aLow = getPropertyValue("PercentageError");
801 bSetHighAndLowValues = true;
802 break;
803 case css::chart::ChartErrorCategory_ERROR_MARGIN:
804 aHigh = aLow = getPropertyValue("ErrorMargin");
805 bSetHighAndLowValues = true;
806 break;
807 default:
808 break;
811 WrappedPropertySet::setPropertyValue( rPropertyName, rValue );
813 if(bSetHighAndLowValues)
815 switch(aNewValue)
817 case css::chart::ChartErrorCategory_CONSTANT_VALUE:
818 setPropertyValue("ConstantErrorHigh",aHigh);
819 setPropertyValue("ConstantErrorLow",aLow);
820 break;
821 case css::chart::ChartErrorCategory_PERCENT:
822 setPropertyValue("PercentageError",aHigh);
823 break;
824 case css::chart::ChartErrorCategory_ERROR_MARGIN:
825 setPropertyValue("ErrorMargin",aHigh);
826 break;
827 default:
828 break;
832 else
833 WrappedPropertySet::setPropertyValue( rPropertyName, rValue );
836 Any SAL_CALL DataSeriesPointWrapper::getPropertyValue( const OUString& rPropertyName )
838 if( m_eType == DATA_POINT )
840 if( rPropertyName == "FillColor" )
842 rtl::Reference< DataSeries > xSeries = getDataSeries();
843 bool bVaryColorsByPoint = false;
844 // "VaryColorsByPoint"
845 if( xSeries.is() && (xSeries->getFastPropertyValue(PROP_DATASERIES_VARY_COLORS_BY_POINT) >>= bVaryColorsByPoint)
846 && bVaryColorsByPoint )
848 uno::Reference< beans::XPropertyState > xPointState( DataSeriesPointWrapper::getDataPointProperties(), uno::UNO_QUERY );
849 if( xPointState.is() && xPointState->getPropertyState("Color") == beans::PropertyState_DEFAULT_VALUE )
851 rtl::Reference< ::chart::Diagram > xDiagram( m_spChart2ModelContact->getDiagram() );
852 if( xDiagram.is() )
854 Reference< chart2::XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme() );
855 if( xColorScheme.is() )
856 return uno::Any( xColorScheme->getColorByIndex( m_nPointIndex ) );
862 return WrappedPropertySet::getPropertyValue( rPropertyName );
865 OUString SAL_CALL DataSeriesPointWrapper::getImplementationName()
867 return "com.sun.star.comp.chart.DataSeries";
870 sal_Bool SAL_CALL DataSeriesPointWrapper::supportsService( const OUString& rServiceName )
872 return cppu::supportsService(this, rServiceName);
875 css::uno::Sequence< OUString > SAL_CALL DataSeriesPointWrapper::getSupportedServiceNames()
877 return {
878 "com.sun.star.chart.ChartDataRowProperties",
879 "com.sun.star.chart.ChartDataPointProperties",
880 "com.sun.star.xml.UserDefinedAttributesSupplier",
881 "com.sun.star.beans.PropertySet",
882 "com.sun.star.drawing.FillProperties",
883 "com.sun.star.drawing.LineProperties",
884 "com.sun.star.style.CharacterProperties"
888 } // namespace chart
890 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */