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>
25 #include <ModifyListenerHelper.hxx>
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <cppuhelper/supportsservice.hxx>
29 #include <tools/diagnose_ex.h>
33 using namespace ::com::sun::star
;
35 using ::com::sun::star::uno::Reference
;
36 using ::com::sun::star::uno::Sequence
;
37 using ::com::sun::star::beans::Property
;
42 struct StaticDataPointInfoHelper_Initializer
44 ::cppu::OPropertyArrayHelper
* operator()()
46 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
51 static Sequence
< Property
> lcl_GetPropertySequence()
53 std::vector
< css::beans::Property
> aProperties
;
54 ::chart::DataPointProperties::AddPropertiesToVector( aProperties
);
55 ::chart::CharacterProperties::AddPropertiesToVector( aProperties
);
56 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
58 std::sort( aProperties
.begin(), aProperties
.end(),
59 ::chart::PropertyNameLess() );
61 return comphelper::containerToSequence( aProperties
);
65 struct StaticDataPointInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticDataPointInfoHelper_Initializer
>
69 struct StaticDataPointInfo_Initializer
71 uno::Reference
< beans::XPropertySetInfo
>* operator()()
73 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
74 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticDataPointInfoHelper::get() ) );
75 return &xPropertySetInfo
;
79 struct StaticDataPointInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticDataPointInfo_Initializer
>
83 } // anonymous namespace
88 DataPoint::DataPoint( const uno::Reference
< beans::XPropertySet
> & rParentProperties
) :
89 ::property::OPropertySet( m_aMutex
),
90 m_xParentProperties( rParentProperties
),
91 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
92 m_bNoParentPropAllowed( false )
94 SetNewValuesExplicitlyEvenIfTheyEqualDefault();
97 DataPoint::DataPoint( const DataPoint
& rOther
) :
98 impl::DataPoint_Base(rOther
),
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
& )
145 DBG_UNHANDLED_EXCEPTION("chart2");
149 // ____ XCloneable ____
150 uno::Reference
< util::XCloneable
> SAL_CALL
DataPoint::createClone()
152 return uno::Reference
< util::XCloneable
>( new DataPoint( *this ));
156 Reference
< uno::XInterface
> SAL_CALL
DataPoint::getParent()
158 return Reference
< uno::XInterface
>( m_xParentProperties
.get(), uno::UNO_QUERY
);
161 void SAL_CALL
DataPoint::setParent(
162 const Reference
< uno::XInterface
>& Parent
)
164 m_xParentProperties
= Reference
< beans::XPropertySet
>( Parent
, uno::UNO_QUERY
);
167 // ____ OPropertySet ____
168 uno::Any
DataPoint::GetDefaultValue( sal_Int32 nHandle
) const
170 // the value set at the data series is the default
171 uno::Reference
< beans::XFastPropertySet
> xFast( m_xParentProperties
.get(), uno::UNO_QUERY
);
174 OSL_ENSURE( m_bNoParentPropAllowed
, "data point needs a parent property set to provide values correctly" );
178 return xFast
->getFastPropertyValue( nHandle
);
181 void SAL_CALL
DataPoint::setFastPropertyValue_NoBroadcast(
182 sal_Int32 nHandle
, const uno::Any
& rValue
)
184 if( nHandle
== DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y
185 || nHandle
== DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X
)
188 Reference
< util::XModifyBroadcaster
> xBroadcaster
;
189 getFastPropertyValue( aOldValue
, nHandle
);
190 if( aOldValue
.hasValue() &&
191 (aOldValue
>>= xBroadcaster
) &&
194 ModifyListenerHelper::removeListener( xBroadcaster
, m_xModifyEventForwarder
);
197 OSL_ASSERT( rValue
.getValueType().getTypeClass() == uno::TypeClass_INTERFACE
);
198 if( rValue
.hasValue() &&
199 (rValue
>>= xBroadcaster
) &&
202 ModifyListenerHelper::addListener( xBroadcaster
, m_xModifyEventForwarder
);
206 ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle
, rValue
);
209 ::cppu::IPropertyArrayHelper
& SAL_CALL
DataPoint::getInfoHelper()
211 return *StaticDataPointInfoHelper::get();
214 // ____ XPropertySet ____
215 Reference
< beans::XPropertySetInfo
> SAL_CALL
DataPoint::getPropertySetInfo()
217 return *StaticDataPointInfo::get();
220 // ____ XModifyBroadcaster ____
221 void SAL_CALL
DataPoint::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
225 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
226 xBroadcaster
->addModifyListener( aListener
);
228 catch( const uno::Exception
& )
230 DBG_UNHANDLED_EXCEPTION("chart2");
234 void SAL_CALL
DataPoint::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
238 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
239 xBroadcaster
->removeModifyListener( aListener
);
241 catch( const uno::Exception
& )
243 DBG_UNHANDLED_EXCEPTION("chart2");
247 // ____ XModifyListener ____
248 void SAL_CALL
DataPoint::modified( const lang::EventObject
& aEvent
)
250 m_xModifyEventForwarder
->modified( aEvent
);
253 // ____ XEventListener (base of XModifyListener) ____
254 void SAL_CALL
DataPoint::disposing( const lang::EventObject
& )
259 // ____ OPropertySet ____
260 void DataPoint::firePropertyChangeEvent()
262 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
265 // needed by MSC compiler
266 using impl::DataPoint_Base
;
268 IMPLEMENT_FORWARD_XINTERFACE2( DataPoint
, DataPoint_Base
, ::property::OPropertySet
)
270 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
271 OUString SAL_CALL
DataPoint::getImplementationName()
273 return "com.sun.star.comp.chart.DataPoint" ;
276 sal_Bool SAL_CALL
DataPoint::supportsService( const OUString
& rServiceName
)
278 return cppu::supportsService(this, rServiceName
);
281 css::uno::Sequence
< OUString
> SAL_CALL
DataPoint::getSupportedServiceNames()
284 "com.sun.star.drawing.FillProperties",
285 "com.sun.star.chart2.DataPoint",
286 "com.sun.star.chart2.DataPointProperties",
287 "com.sun.star.beans.PropertySet"
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */