1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "DataPoint.hxx"
21 #include "DataPointProperties.hxx"
22 #include "CharacterProperties.hxx"
23 #include "UserDefinedProperties.hxx"
24 #include "PropertyHelper.hxx"
26 #include "ContainerHelper.hxx"
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
28 #include <com/sun/star/style/XStyle.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <cppuhelper/supportsservice.hxx>
35 using namespace ::com::sun::star
;
37 using ::com::sun::star::uno::Reference
;
38 using ::com::sun::star::uno::Sequence
;
39 using ::com::sun::star::beans::Property
;
40 using ::osl::MutexGuard
;
45 struct StaticDataPointInfoHelper_Initializer
47 ::cppu::OPropertyArrayHelper
* operator()()
49 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
54 static Sequence
< Property
> lcl_GetPropertySequence()
56 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
57 ::chart::DataPointProperties::AddPropertiesToVector( aProperties
);
58 ::chart::CharacterProperties::AddPropertiesToVector( aProperties
);
59 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
61 ::std::sort( aProperties
.begin(), aProperties
.end(),
62 ::chart::PropertyNameLess() );
64 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
68 struct StaticDataPointInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticDataPointInfoHelper_Initializer
>
72 struct StaticDataPointInfo_Initializer
74 uno::Reference
< beans::XPropertySetInfo
>* operator()()
76 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
77 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticDataPointInfoHelper::get() ) );
78 return &xPropertySetInfo
;
82 struct StaticDataPointInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticDataPointInfo_Initializer
>
86 } // anonymous namespace
91 DataPoint::DataPoint( const uno::Reference
< beans::XPropertySet
> & rParentProperties
) :
92 ::property::OPropertySet( m_aMutex
),
93 m_xParentProperties( rParentProperties
),
94 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
95 m_bNoParentPropAllowed( false )
97 SetNewValuesExplicitlyEvenIfTheyEqualDefault();
100 DataPoint::DataPoint( const DataPoint
& rOther
) :
102 impl::DataPoint_Base(),
103 ::property::OPropertySet( rOther
, m_aMutex
),
104 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
105 m_bNoParentPropAllowed( true )
107 SetNewValuesExplicitlyEvenIfTheyEqualDefault();
109 // m_xParentProperties has to be set from outside, like in the method
110 // DataSeries::createClone
112 // add as listener to XPropertySet properties
113 Reference
< beans::XPropertySet
> xPropertySet
;
116 getFastPropertyValue( aValue
, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X
);
117 if( ( aValue
>>= xPropertySet
)
118 && xPropertySet
.is())
119 ModifyListenerHelper::addListener( xPropertySet
, m_xModifyEventForwarder
);
121 getFastPropertyValue( aValue
, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y
);
122 if( ( aValue
>>= xPropertySet
)
123 && xPropertySet
.is())
124 ModifyListenerHelper::addListener( xPropertySet
, m_xModifyEventForwarder
);
126 m_bNoParentPropAllowed
= false;
129 DataPoint::~DataPoint()
133 // remove listener from XPropertySet properties
134 Reference
< beans::XPropertySet
> xPropertySet
;
137 getFastPropertyValue( aValue
, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X
);
138 if( ( aValue
>>= xPropertySet
)
139 && xPropertySet
.is())
140 ModifyListenerHelper::removeListener( xPropertySet
, m_xModifyEventForwarder
);
142 getFastPropertyValue( aValue
, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y
);
143 if( ( aValue
>>= xPropertySet
)
144 && xPropertySet
.is())
145 ModifyListenerHelper::removeListener( xPropertySet
, m_xModifyEventForwarder
);
147 catch( const uno::Exception
& ex
)
149 ASSERT_EXCEPTION( ex
);
153 // ____ XCloneable ____
154 uno::Reference
< util::XCloneable
> SAL_CALL
DataPoint::createClone()
155 throw (uno::RuntimeException
, std::exception
)
157 return uno::Reference
< util::XCloneable
>( new DataPoint( *this ));
161 Reference
< uno::XInterface
> SAL_CALL
DataPoint::getParent()
162 throw (uno::RuntimeException
, std::exception
)
164 return Reference
< uno::XInterface
>( m_xParentProperties
.get(), uno::UNO_QUERY
);
167 void SAL_CALL
DataPoint::setParent(
168 const Reference
< uno::XInterface
>& Parent
)
169 throw (lang::NoSupportException
,
170 uno::RuntimeException
, std::exception
)
172 m_xParentProperties
= Reference
< beans::XPropertySet
>( Parent
, uno::UNO_QUERY
);
175 // ____ OPropertySet ____
176 uno::Any
DataPoint::GetDefaultValue( sal_Int32 nHandle
) const
177 throw(beans::UnknownPropertyException
)
179 // the value set at the data series is the default
180 uno::Reference
< beans::XFastPropertySet
> xFast( m_xParentProperties
.get(), uno::UNO_QUERY
);
183 OSL_ENSURE( m_bNoParentPropAllowed
, "data point needs a parent property set to provide values correctly" );
187 return xFast
->getFastPropertyValue( nHandle
);
190 void SAL_CALL
DataPoint::setFastPropertyValue_NoBroadcast(
191 sal_Int32 nHandle
, const uno::Any
& rValue
)
192 throw (uno::Exception
, std::exception
)
194 if( nHandle
== DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y
195 || nHandle
== DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X
)
198 Reference
< util::XModifyBroadcaster
> xBroadcaster
;
199 this->getFastPropertyValue( aOldValue
, nHandle
);
200 if( aOldValue
.hasValue() &&
201 (aOldValue
>>= xBroadcaster
) &&
204 ModifyListenerHelper::removeListener( xBroadcaster
, m_xModifyEventForwarder
);
207 OSL_ASSERT( rValue
.getValueType().getTypeClass() == uno::TypeClass_INTERFACE
);
208 if( rValue
.hasValue() &&
209 (rValue
>>= xBroadcaster
) &&
212 ModifyListenerHelper::addListener( xBroadcaster
, m_xModifyEventForwarder
);
216 ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle
, rValue
);
219 ::cppu::IPropertyArrayHelper
& SAL_CALL
DataPoint::getInfoHelper()
221 return *StaticDataPointInfoHelper::get();
224 // ____ XPropertySet ____
225 Reference
< beans::XPropertySetInfo
> SAL_CALL
DataPoint::getPropertySetInfo()
226 throw (uno::RuntimeException
, std::exception
)
228 return *StaticDataPointInfo::get();
231 // ____ XModifyBroadcaster ____
232 void SAL_CALL
DataPoint::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
233 throw (uno::RuntimeException
, std::exception
)
237 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
238 xBroadcaster
->addModifyListener( aListener
);
240 catch( const uno::Exception
& ex
)
242 ASSERT_EXCEPTION( ex
);
246 void SAL_CALL
DataPoint::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
247 throw (uno::RuntimeException
, std::exception
)
251 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
252 xBroadcaster
->removeModifyListener( aListener
);
254 catch( const uno::Exception
& ex
)
256 ASSERT_EXCEPTION( ex
);
260 // ____ XModifyListener ____
261 void SAL_CALL
DataPoint::modified( const lang::EventObject
& aEvent
)
262 throw (uno::RuntimeException
, std::exception
)
264 m_xModifyEventForwarder
->modified( aEvent
);
267 // ____ XEventListener (base of XModifyListener) ____
268 void SAL_CALL
DataPoint::disposing( const lang::EventObject
& )
269 throw (uno::RuntimeException
, std::exception
)
274 // ____ OPropertySet ____
275 void DataPoint::firePropertyChangeEvent()
280 void DataPoint::fireModifyEvent()
282 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
285 Sequence
< OUString
> DataPoint::getSupportedServiceNames_Static()
287 Sequence
< OUString
> aServices( 3 );
288 aServices
[ 0 ] = "com.sun.star.chart2.DataPoint";
289 aServices
[ 1 ] = "com.sun.star.chart2.DataPointProperties";
290 aServices
[ 2 ] = "com.sun.star.beans.PropertySet";
294 // needed by MSC compiler
295 using impl::DataPoint_Base
;
297 IMPLEMENT_FORWARD_XINTERFACE2( DataPoint
, DataPoint_Base
, ::property::OPropertySet
)
299 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
300 OUString SAL_CALL
DataPoint::getImplementationName()
301 throw( css::uno::RuntimeException
, std::exception
)
303 return getImplementationName_Static();
306 OUString
DataPoint::getImplementationName_Static()
308 return OUString("com.sun.star.comp.chart.DataPoint") ;
311 sal_Bool SAL_CALL
DataPoint::supportsService( const OUString
& rServiceName
)
312 throw( css::uno::RuntimeException
, std::exception
)
314 return cppu::supportsService(this, rServiceName
);
317 css::uno::Sequence
< OUString
> SAL_CALL
DataPoint::getSupportedServiceNames()
318 throw( css::uno::RuntimeException
, std::exception
)
320 return getSupportedServiceNames_Static();
325 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */