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