merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / model / main / DataPoint.cxx
blob124f8b32e7327096cc6aa3afca88e33b3b3ed084
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: DataPoint.cxx,v $
10 * $Revision: 1.9.44.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "DataPoint.hxx"
34 #include "DataPointProperties.hxx"
35 #include "CharacterProperties.hxx"
36 #include "UserDefinedProperties.hxx"
37 #include "PropertyHelper.hxx"
38 #include "macros.hxx"
39 #include "ContainerHelper.hxx"
40 #include <com/sun/star/beans/PropertyAttribute.hpp>
41 #include <com/sun/star/style/XStyle.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/uno/Sequence.hxx>
45 #include <algorithm>
47 using namespace ::com::sun::star;
49 using ::com::sun::star::uno::Reference;
50 using ::com::sun::star::uno::Sequence;
51 using ::com::sun::star::beans::Property;
52 using ::osl::MutexGuard;
53 using ::rtl::OUString;
55 // ____________________________________________________________
57 namespace
59 const Sequence< Property > & lcl_GetPropertySequence()
61 static Sequence< Property > aPropSeq;
63 // /--
64 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
65 if( 0 == aPropSeq.getLength() )
67 // get properties
68 ::std::vector< ::com::sun::star::beans::Property > aProperties;
69 ::chart::DataPointProperties::AddPropertiesToVector( aProperties );
70 ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
71 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
73 // and sort them for access via bsearch
74 ::std::sort( aProperties.begin(), aProperties.end(),
75 ::chart::PropertyNameLess() );
77 // transfer result to static Sequence
78 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
81 return aPropSeq;
83 } // anonymous namespace
85 // ____________________________________________________________
87 namespace chart
90 DataPoint::DataPoint( const uno::Reference< beans::XPropertySet > & rParentProperties ) :
91 ::property::OPropertySet( m_aMutex ),
92 m_xParentProperties( rParentProperties ),
93 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
94 m_bNoParentPropAllowed( false )
96 SetNewValuesExplicitlyEvenIfTheyEqualDefault();
99 DataPoint::DataPoint( const DataPoint & rOther ) :
100 MutexContainer(),
101 impl::DataPoint_Base(),
102 ::property::OPropertySet( rOther, m_aMutex ),
103 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
104 m_bNoParentPropAllowed( true )
106 SetNewValuesExplicitlyEvenIfTheyEqualDefault();
108 // m_xParentProperties has to be set from outside, like in the method
109 // DataSeries::createClone
111 // add as listener to XPropertySet properties
112 Reference< beans::XPropertySet > xPropertySet;
113 uno::Any aValue;
115 getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X );
116 if( ( aValue >>= xPropertySet )
117 && xPropertySet.is())
118 ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder );
120 getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y );
121 if( ( aValue >>= xPropertySet )
122 && xPropertySet.is())
123 ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder );
125 m_bNoParentPropAllowed = false;
128 DataPoint::~DataPoint()
132 // remove listener from XPropertySet properties
133 Reference< beans::XPropertySet > xPropertySet;
134 uno::Any aValue;
136 getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X );
137 if( ( aValue >>= xPropertySet )
138 && xPropertySet.is())
139 ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder );
141 getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y );
142 if( ( aValue >>= xPropertySet )
143 && xPropertySet.is())
144 ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder );
146 catch( const uno::Exception & ex )
148 ASSERT_EXCEPTION( ex );
152 // ____ XCloneable ____
153 uno::Reference< util::XCloneable > SAL_CALL DataPoint::createClone()
154 throw (uno::RuntimeException)
156 return uno::Reference< util::XCloneable >( new DataPoint( *this ));
159 // ____ XChild ____
160 Reference< uno::XInterface > SAL_CALL DataPoint::getParent()
161 throw (uno::RuntimeException)
163 return Reference< uno::XInterface >( m_xParentProperties, uno::UNO_QUERY );
166 void SAL_CALL DataPoint::setParent(
167 const Reference< uno::XInterface >& Parent )
168 throw (lang::NoSupportException,
169 uno::RuntimeException)
171 m_xParentProperties.set( Parent, uno::UNO_QUERY );
174 // ____ OPropertySet ____
175 uno::Any DataPoint::GetDefaultValue( sal_Int32 nHandle ) const
176 throw(beans::UnknownPropertyException)
178 // the value set at the data series is the default
179 uno::Reference< beans::XFastPropertySet > xFast( m_xParentProperties, uno::UNO_QUERY );
180 if( !xFast.is())
182 OSL_ENSURE( m_bNoParentPropAllowed, "data point needs a parent property set to provide values correctly" );
183 return uno::Any();
186 return xFast->getFastPropertyValue( nHandle );
189 void SAL_CALL DataPoint::setFastPropertyValue_NoBroadcast(
190 sal_Int32 nHandle, const uno::Any& rValue )
191 throw (uno::Exception)
193 if( nHandle == DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y
194 || nHandle == DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X )
196 uno::Any aOldValue;
197 Reference< util::XModifyBroadcaster > xBroadcaster;
198 this->getFastPropertyValue( aOldValue, nHandle );
199 if( aOldValue.hasValue() &&
200 (aOldValue >>= xBroadcaster) &&
201 xBroadcaster.is())
203 ModifyListenerHelper::removeListener( xBroadcaster, m_xModifyEventForwarder );
206 OSL_ASSERT( rValue.getValueType().getTypeClass() == uno::TypeClass_INTERFACE );
207 if( rValue.hasValue() &&
208 (rValue >>= xBroadcaster) &&
209 xBroadcaster.is())
211 ModifyListenerHelper::addListener( xBroadcaster, m_xModifyEventForwarder );
215 ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle, rValue );
218 ::cppu::IPropertyArrayHelper & SAL_CALL DataPoint::getInfoHelper()
220 return getInfoHelperConst();
223 ::cppu::IPropertyArrayHelper & SAL_CALL DataPoint::getInfoHelperConst() const
225 static ::cppu::OPropertyArrayHelper aArrayHelper(
226 lcl_GetPropertySequence(),
227 /* bSorted = */ sal_True );
229 return aArrayHelper;
232 // ____ XPropertySet ____
233 Reference< beans::XPropertySetInfo > SAL_CALL
234 DataPoint::getPropertySetInfo()
235 throw (uno::RuntimeException)
237 static Reference< beans::XPropertySetInfo > xInfo;
239 // /--
240 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
241 if( !xInfo.is())
243 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
244 getInfoHelper());
247 return xInfo;
248 // \--
251 // ____ XModifyBroadcaster ____
252 void SAL_CALL DataPoint::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
253 throw (uno::RuntimeException)
257 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
258 xBroadcaster->addModifyListener( aListener );
260 catch( const uno::Exception & ex )
262 ASSERT_EXCEPTION( ex );
266 void SAL_CALL DataPoint::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
267 throw (uno::RuntimeException)
271 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
272 xBroadcaster->removeModifyListener( aListener );
274 catch( const uno::Exception & ex )
276 ASSERT_EXCEPTION( ex );
280 // ____ XModifyListener ____
281 void SAL_CALL DataPoint::modified( const lang::EventObject& aEvent )
282 throw (uno::RuntimeException)
284 m_xModifyEventForwarder->modified( aEvent );
287 // ____ XEventListener (base of XModifyListener) ____
288 void SAL_CALL DataPoint::disposing( const lang::EventObject& )
289 throw (uno::RuntimeException)
291 // nothing
294 // ____ OPropertySet ____
295 void DataPoint::firePropertyChangeEvent()
297 fireModifyEvent();
300 void DataPoint::fireModifyEvent()
302 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
305 Sequence< OUString > DataPoint::getSupportedServiceNames_Static()
307 Sequence< OUString > aServices( 3 );
308 aServices[ 0 ] = C2U( "com.sun.star.chart2.DataPoint" );
309 aServices[ 1 ] = C2U( "com.sun.star.chart2.DataPointProperties" );
310 aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
311 return aServices;
314 // needed by MSC compiler
315 using impl::DataPoint_Base;
317 IMPLEMENT_FORWARD_XINTERFACE2( DataPoint, DataPoint_Base, ::property::OPropertySet )
319 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
320 APPHELPER_XSERVICEINFO_IMPL( DataPoint, C2U( "com.sun.star.comp.chart.DataPoint" ));
322 } // namespace chart