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 "DataPoint.hxx"
27 #include "DataPointProperties.hxx"
28 #include "CharacterProperties.hxx"
29 #include "UserDefinedProperties.hxx"
30 #include "PropertyHelper.hxx"
31 #include "macros.hxx"
32 #include "ContainerHelper.hxx"
33 #include <com/sun/star/beans/PropertyAttribute.hpp>
34 #include <com/sun/star/style/XStyle.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/uno/Sequence.hxx>
37
38 #include <algorithm>
39
40 using namespace ::com::sun::star;
41
42 using ::com::sun::star::uno::Reference;
43 using ::com::sun::star::uno::Sequence;
44 using ::com::sun::star::beans::Property;
45 using ::osl::MutexGuard;
46 using ::rtl::OUString;
47
48 // ____________________________________________________________
49
50 namespace
51 {
52
53 struct StaticDataPointInfoHelper_Initializer
54 {
operator ()__anon6ba96beb0111::StaticDataPointInfoHelper_Initializer55 ::cppu::OPropertyArrayHelper* operator()()
56 {
57 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
58 return &aPropHelper;
59 }
60
61 private:
lcl_GetPropertySequence__anon6ba96beb0111::StaticDataPointInfoHelper_Initializer62 Sequence< Property > lcl_GetPropertySequence()
63 {
64 ::std::vector< ::com::sun::star::beans::Property > aProperties;
65 ::chart::DataPointProperties::AddPropertiesToVector( aProperties );
66 ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
67 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
68
69 ::std::sort( aProperties.begin(), aProperties.end(),
70 ::chart::PropertyNameLess() );
71
72 return ::chart::ContainerHelper::ContainerToSequence( aProperties );
73 }
74 };
75
76 struct StaticDataPointInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticDataPointInfoHelper_Initializer >
77 {
78 };
79
80 struct StaticDataPointInfo_Initializer
81 {
operator ()__anon6ba96beb0111::StaticDataPointInfo_Initializer82 uno::Reference< beans::XPropertySetInfo >* operator()()
83 {
84 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
85 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticDataPointInfoHelper::get() ) );
86 return &xPropertySetInfo;
87 }
88 };
89
90 struct StaticDataPointInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticDataPointInfo_Initializer >
91 {
92 };
93
94 } // anonymous namespace
95
96 // ____________________________________________________________
97
98 namespace chart
99 {
100
DataPoint(const uno::Reference<beans::XPropertySet> & rParentProperties)101 DataPoint::DataPoint( const uno::Reference< beans::XPropertySet > & rParentProperties ) :
102 ::property::OPropertySet( m_aMutex ),
103 m_xParentProperties( rParentProperties ),
104 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
105 m_bNoParentPropAllowed( false )
106 {
107 SetNewValuesExplicitlyEvenIfTheyEqualDefault();
108 }
109
DataPoint(const DataPoint & rOther)110 DataPoint::DataPoint( const DataPoint & rOther ) :
111 MutexContainer(),
112 impl::DataPoint_Base(),
113 ::property::OPropertySet( rOther, m_aMutex ),
114 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
115 m_bNoParentPropAllowed( true )
116 {
117 SetNewValuesExplicitlyEvenIfTheyEqualDefault();
118
119 // m_xParentProperties has to be set from outside, like in the method
120 // DataSeries::createClone
121
122 // add as listener to XPropertySet properties
123 Reference< beans::XPropertySet > xPropertySet;
124 uno::Any aValue;
125
126 getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X );
127 if( ( aValue >>= xPropertySet )
128 && xPropertySet.is())
129 ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder );
130
131 getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y );
132 if( ( aValue >>= xPropertySet )
133 && xPropertySet.is())
134 ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder );
135
136 m_bNoParentPropAllowed = false;
137 }
138
~DataPoint()139 DataPoint::~DataPoint()
140 {
141 try
142 {
143 // remove listener from XPropertySet properties
144 Reference< beans::XPropertySet > xPropertySet;
145 uno::Any aValue;
146
147 getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X );
148 if( ( aValue >>= xPropertySet )
149 && xPropertySet.is())
150 ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder );
151
152 getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y );
153 if( ( aValue >>= xPropertySet )
154 && xPropertySet.is())
155 ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder );
156 }
157 catch( const uno::Exception & ex )
158 {
159 ASSERT_EXCEPTION( ex );
160 }
161 }
162
163 // ____ XCloneable ____
createClone()164 uno::Reference< util::XCloneable > SAL_CALL DataPoint::createClone()
165 throw (uno::RuntimeException)
166 {
167 return uno::Reference< util::XCloneable >( new DataPoint( *this ));
168 }
169
170 // ____ XChild ____
getParent()171 Reference< uno::XInterface > SAL_CALL DataPoint::getParent()
172 throw (uno::RuntimeException)
173 {
174 return Reference< uno::XInterface >( m_xParentProperties.get(), uno::UNO_QUERY );
175 }
176
setParent(const Reference<uno::XInterface> & Parent)177 void SAL_CALL DataPoint::setParent(
178 const Reference< uno::XInterface >& Parent )
179 throw (lang::NoSupportException,
180 uno::RuntimeException)
181 {
182 m_xParentProperties = Reference< beans::XPropertySet >( Parent, uno::UNO_QUERY );
183 }
184
185 // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const186 uno::Any DataPoint::GetDefaultValue( sal_Int32 nHandle ) const
187 throw(beans::UnknownPropertyException)
188 {
189 // the value set at the data series is the default
190 uno::Reference< beans::XFastPropertySet > xFast( m_xParentProperties.get(), uno::UNO_QUERY );
191 if( !xFast.is())
192 {
193 OSL_ENSURE( m_bNoParentPropAllowed, "data point needs a parent property set to provide values correctly" );
194 return uno::Any();
195 }
196
197 return xFast->getFastPropertyValue( nHandle );
198 }
199
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const uno::Any & rValue)200 void SAL_CALL DataPoint::setFastPropertyValue_NoBroadcast(
201 sal_Int32 nHandle, const uno::Any& rValue )
202 throw (uno::Exception)
203 {
204 if( nHandle == DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y
205 || nHandle == DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X )
206 {
207 uno::Any aOldValue;
208 Reference< util::XModifyBroadcaster > xBroadcaster;
209 this->getFastPropertyValue( aOldValue, nHandle );
210 if( aOldValue.hasValue() &&
211 (aOldValue >>= xBroadcaster) &&
212 xBroadcaster.is())
213 {
214 ModifyListenerHelper::removeListener( xBroadcaster, m_xModifyEventForwarder );
215 }
216
217 OSL_ASSERT( rValue.getValueType().getTypeClass() == uno::TypeClass_INTERFACE );
218 if( rValue.hasValue() &&
219 (rValue >>= xBroadcaster) &&
220 xBroadcaster.is())
221 {
222 ModifyListenerHelper::addListener( xBroadcaster, m_xModifyEventForwarder );
223 }
224 }
225
226 ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle, rValue );
227 }
228
getInfoHelper()229 ::cppu::IPropertyArrayHelper & SAL_CALL DataPoint::getInfoHelper()
230 {
231 return *StaticDataPointInfoHelper::get();
232 }
233
234 // ____ XPropertySet ____
getPropertySetInfo()235 Reference< beans::XPropertySetInfo > SAL_CALL DataPoint::getPropertySetInfo()
236 throw (uno::RuntimeException)
237 {
238 return *StaticDataPointInfo::get();
239 }
240
241 // ____ XModifyBroadcaster ____
addModifyListener(const uno::Reference<util::XModifyListener> & aListener)242 void SAL_CALL DataPoint::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
243 throw (uno::RuntimeException)
244 {
245 try
246 {
247 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
248 xBroadcaster->addModifyListener( aListener );
249 }
250 catch( const uno::Exception & ex )
251 {
252 ASSERT_EXCEPTION( ex );
253 }
254 }
255
removeModifyListener(const uno::Reference<util::XModifyListener> & aListener)256 void SAL_CALL DataPoint::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
257 throw (uno::RuntimeException)
258 {
259 try
260 {
261 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
262 xBroadcaster->removeModifyListener( aListener );
263 }
264 catch( const uno::Exception & ex )
265 {
266 ASSERT_EXCEPTION( ex );
267 }
268 }
269
270 // ____ XModifyListener ____
modified(const lang::EventObject & aEvent)271 void SAL_CALL DataPoint::modified( const lang::EventObject& aEvent )
272 throw (uno::RuntimeException)
273 {
274 m_xModifyEventForwarder->modified( aEvent );
275 }
276
277 // ____ XEventListener (base of XModifyListener) ____
disposing(const lang::EventObject &)278 void SAL_CALL DataPoint::disposing( const lang::EventObject& )
279 throw (uno::RuntimeException)
280 {
281 // nothing
282 }
283
284 // ____ OPropertySet ____
firePropertyChangeEvent()285 void DataPoint::firePropertyChangeEvent()
286 {
287 fireModifyEvent();
288 }
289
fireModifyEvent()290 void DataPoint::fireModifyEvent()
291 {
292 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
293 }
294
getSupportedServiceNames_Static()295 Sequence< OUString > DataPoint::getSupportedServiceNames_Static()
296 {
297 Sequence< OUString > aServices( 3 );
298 aServices[ 0 ] = C2U( "com.sun.star.chart2.DataPoint" );
299 aServices[ 1 ] = C2U( "com.sun.star.chart2.DataPointProperties" );
300 aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
301 return aServices;
302 }
303
304 // needed by MSC compiler
305 using impl::DataPoint_Base;
306
307 IMPLEMENT_FORWARD_XINTERFACE2( DataPoint, DataPoint_Base, ::property::OPropertySet )
308
309 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
310 APPHELPER_XSERVICEINFO_IMPL( DataPoint, C2U( "com.sun.star.comp.chart.DataPoint" ));
311
312 } // namespace chart
313