1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "DataPoint.hxx"
31 #include "DataPointProperties.hxx"
32 #include "CharacterProperties.hxx"
33 #include "UserDefinedProperties.hxx"
34 #include "PropertyHelper.hxx"
36 #include "ContainerHelper.hxx"
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 #include <com/sun/star/style/XStyle.hpp>
39 #include <com/sun/star/beans/XPropertySet.hpp>
40 #include <com/sun/star/uno/Sequence.hxx>
44 using namespace ::com::sun::star
;
46 using ::com::sun::star::uno::Reference
;
47 using ::com::sun::star::uno::Sequence
;
48 using ::com::sun::star::beans::Property
;
49 using ::osl::MutexGuard
;
50 using ::rtl::OUString
;
52 // ____________________________________________________________
56 const Sequence
< Property
> & lcl_GetPropertySequence()
58 static Sequence
< Property
> aPropSeq
;
61 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
62 if( 0 == aPropSeq
.getLength() )
65 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
66 ::chart::DataPointProperties::AddPropertiesToVector( aProperties
);
67 ::chart::CharacterProperties::AddPropertiesToVector( aProperties
);
68 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
70 // and sort them for access via bsearch
71 ::std::sort( aProperties
.begin(), aProperties
.end(),
72 ::chart::PropertyNameLess() );
74 // transfer result to static Sequence
75 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
80 } // anonymous namespace
82 // ____________________________________________________________
87 DataPoint::DataPoint( const uno::Reference
< beans::XPropertySet
> & rParentProperties
) :
88 ::property::OPropertySet( m_aMutex
),
89 m_xParentProperties( rParentProperties
),
90 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
91 m_bNoParentPropAllowed( false )
93 SetNewValuesExplicitlyEvenIfTheyEqualDefault();
96 DataPoint::DataPoint( const DataPoint
& rOther
) :
98 impl::DataPoint_Base(),
99 ::property::OPropertySet( rOther
, m_aMutex
),
100 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
101 m_bNoParentPropAllowed( true )
103 SetNewValuesExplicitlyEvenIfTheyEqualDefault();
105 // m_xParentProperties has to be set from outside, like in the method
106 // DataSeries::createClone
108 // add as listener to XPropertySet properties
109 Reference
< beans::XPropertySet
> xPropertySet
;
112 getFastPropertyValue( aValue
, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X
);
113 if( ( aValue
>>= xPropertySet
)
114 && xPropertySet
.is())
115 ModifyListenerHelper::addListener( xPropertySet
, m_xModifyEventForwarder
);
117 getFastPropertyValue( aValue
, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y
);
118 if( ( aValue
>>= xPropertySet
)
119 && xPropertySet
.is())
120 ModifyListenerHelper::addListener( xPropertySet
, m_xModifyEventForwarder
);
122 m_bNoParentPropAllowed
= false;
125 DataPoint::~DataPoint()
129 // remove listener from XPropertySet properties
130 Reference
< beans::XPropertySet
> xPropertySet
;
133 getFastPropertyValue( aValue
, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X
);
134 if( ( aValue
>>= xPropertySet
)
135 && xPropertySet
.is())
136 ModifyListenerHelper::removeListener( xPropertySet
, m_xModifyEventForwarder
);
138 getFastPropertyValue( aValue
, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y
);
139 if( ( aValue
>>= xPropertySet
)
140 && xPropertySet
.is())
141 ModifyListenerHelper::removeListener( xPropertySet
, m_xModifyEventForwarder
);
143 catch( const uno::Exception
& ex
)
145 ASSERT_EXCEPTION( ex
);
149 // ____ XCloneable ____
150 uno::Reference
< util::XCloneable
> SAL_CALL
DataPoint::createClone()
151 throw (uno::RuntimeException
)
153 return uno::Reference
< util::XCloneable
>( new DataPoint( *this ));
157 Reference
< uno::XInterface
> SAL_CALL
DataPoint::getParent()
158 throw (uno::RuntimeException
)
160 return Reference
< uno::XInterface
>( m_xParentProperties
, uno::UNO_QUERY
);
163 void SAL_CALL
DataPoint::setParent(
164 const Reference
< uno::XInterface
>& Parent
)
165 throw (lang::NoSupportException
,
166 uno::RuntimeException
)
168 m_xParentProperties
.set( Parent
, uno::UNO_QUERY
);
171 // ____ OPropertySet ____
172 uno::Any
DataPoint::GetDefaultValue( sal_Int32 nHandle
) const
173 throw(beans::UnknownPropertyException
)
175 // the value set at the data series is the default
176 uno::Reference
< beans::XFastPropertySet
> xFast( m_xParentProperties
, uno::UNO_QUERY
);
179 OSL_ENSURE( m_bNoParentPropAllowed
, "data point needs a parent property set to provide values correctly" );
183 return xFast
->getFastPropertyValue( nHandle
);
186 void SAL_CALL
DataPoint::setFastPropertyValue_NoBroadcast(
187 sal_Int32 nHandle
, const uno::Any
& rValue
)
188 throw (uno::Exception
)
190 if( nHandle
== DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y
191 || nHandle
== DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X
)
194 Reference
< util::XModifyBroadcaster
> xBroadcaster
;
195 this->getFastPropertyValue( aOldValue
, nHandle
);
196 if( aOldValue
.hasValue() &&
197 (aOldValue
>>= xBroadcaster
) &&
200 ModifyListenerHelper::removeListener( xBroadcaster
, m_xModifyEventForwarder
);
203 OSL_ASSERT( rValue
.getValueType().getTypeClass() == uno::TypeClass_INTERFACE
);
204 if( rValue
.hasValue() &&
205 (rValue
>>= xBroadcaster
) &&
208 ModifyListenerHelper::addListener( xBroadcaster
, m_xModifyEventForwarder
);
212 ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle
, rValue
);
215 ::cppu::IPropertyArrayHelper
& SAL_CALL
DataPoint::getInfoHelper()
217 return getInfoHelperConst();
220 ::cppu::IPropertyArrayHelper
& SAL_CALL
DataPoint::getInfoHelperConst() const
222 static ::cppu::OPropertyArrayHelper
aArrayHelper(
223 lcl_GetPropertySequence(),
224 /* bSorted = */ sal_True
);
229 // ____ XPropertySet ____
230 Reference
< beans::XPropertySetInfo
> SAL_CALL
231 DataPoint::getPropertySetInfo()
232 throw (uno::RuntimeException
)
234 static Reference
< beans::XPropertySetInfo
> xInfo
;
237 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
240 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
248 // ____ XModifyBroadcaster ____
249 void SAL_CALL
DataPoint::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
250 throw (uno::RuntimeException
)
254 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
255 xBroadcaster
->addModifyListener( aListener
);
257 catch( const uno::Exception
& ex
)
259 ASSERT_EXCEPTION( ex
);
263 void SAL_CALL
DataPoint::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
264 throw (uno::RuntimeException
)
268 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
269 xBroadcaster
->removeModifyListener( aListener
);
271 catch( const uno::Exception
& ex
)
273 ASSERT_EXCEPTION( ex
);
277 // ____ XModifyListener ____
278 void SAL_CALL
DataPoint::modified( const lang::EventObject
& aEvent
)
279 throw (uno::RuntimeException
)
281 m_xModifyEventForwarder
->modified( aEvent
);
284 // ____ XEventListener (base of XModifyListener) ____
285 void SAL_CALL
DataPoint::disposing( const lang::EventObject
& )
286 throw (uno::RuntimeException
)
291 // ____ OPropertySet ____
292 void DataPoint::firePropertyChangeEvent()
297 void DataPoint::fireModifyEvent()
299 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
302 Sequence
< OUString
> DataPoint::getSupportedServiceNames_Static()
304 Sequence
< OUString
> aServices( 3 );
305 aServices
[ 0 ] = C2U( "com.sun.star.chart2.DataPoint" );
306 aServices
[ 1 ] = C2U( "com.sun.star.chart2.DataPointProperties" );
307 aServices
[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
311 // needed by MSC compiler
312 using impl::DataPoint_Base
;
314 IMPLEMENT_FORWARD_XINTERFACE2( DataPoint
, DataPoint_Base
, ::property::OPropertySet
)
316 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
317 APPHELPER_XSERVICEINFO_IMPL( DataPoint
, C2U( "com.sun.star.comp.chart.DataPoint" ));