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