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 <comphelper/diagnose_ex.hxx>
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 ::cppu::OPropertyArrayHelper
& StaticDataPointInfoHelper()
44 static ::cppu::OPropertyArrayHelper aPropHelper
= []()
46 std::vector
< css::beans::Property
> aProperties
;
47 ::chart::DataPointProperties::AddPropertiesToVector( aProperties
);
48 ::chart::CharacterProperties::AddPropertiesToVector( aProperties
);
49 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
51 std::sort( aProperties
.begin(), aProperties
.end(),
52 ::chart::PropertyNameLess() );
54 return comphelper::containerToSequence( aProperties
);
59 } // anonymous namespace
64 DataPoint::DataPoint( const uno::Reference
< beans::XPropertySet
> & rParentProperties
) :
65 m_xParentProperties( rParentProperties
),
66 m_xModifyEventForwarder( new ModifyEventForwarder() ),
67 m_bNoParentPropAllowed( false )
69 SetNewValuesExplicitlyEvenIfTheyEqualDefault();
72 DataPoint::DataPoint( const DataPoint
& rOther
) :
73 impl::DataPoint_Base(rOther
),
74 ::property::OPropertySet( rOther
),
75 m_xModifyEventForwarder( new ModifyEventForwarder() ),
76 m_bNoParentPropAllowed( true )
78 SetNewValuesExplicitlyEvenIfTheyEqualDefault();
80 // m_xParentProperties has to be set from outside, like in the method
81 // DataSeries::createClone
83 // add as listener to XPropertySet properties
84 Reference
< beans::XPropertySet
> xPropertySet
;
87 getFastPropertyValue( aValue
, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X
);
88 if( ( aValue
>>= xPropertySet
)
90 ModifyListenerHelper::addListener( xPropertySet
, m_xModifyEventForwarder
);
92 getFastPropertyValue( aValue
, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y
);
93 if( ( aValue
>>= xPropertySet
)
95 ModifyListenerHelper::addListener( xPropertySet
, m_xModifyEventForwarder
);
97 m_bNoParentPropAllowed
= false;
100 DataPoint::~DataPoint()
104 // remove listener from XPropertySet properties
105 Reference
< beans::XPropertySet
> xPropertySet
;
108 getFastPropertyValue( aValue
, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X
);
109 if( ( aValue
>>= xPropertySet
)
110 && xPropertySet
.is())
111 ModifyListenerHelper::removeListener( xPropertySet
, m_xModifyEventForwarder
);
113 getFastPropertyValue( aValue
, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y
);
114 if( ( aValue
>>= xPropertySet
)
115 && xPropertySet
.is())
116 ModifyListenerHelper::removeListener( xPropertySet
, m_xModifyEventForwarder
);
118 catch( const uno::Exception
& )
120 DBG_UNHANDLED_EXCEPTION("chart2");
124 // ____ XCloneable ____
125 uno::Reference
< util::XCloneable
> SAL_CALL
DataPoint::createClone()
127 return uno::Reference
< util::XCloneable
>( new DataPoint( *this ));
131 Reference
< uno::XInterface
> SAL_CALL
DataPoint::getParent()
133 return Reference
< uno::XInterface
>( m_xParentProperties
.get(), uno::UNO_QUERY
);
136 void SAL_CALL
DataPoint::setParent(
137 const Reference
< uno::XInterface
>& Parent
)
139 m_xParentProperties
= Reference
< beans::XPropertySet
>( Parent
, uno::UNO_QUERY
);
142 // ____ OPropertySet ____
143 void DataPoint::GetDefaultValue( sal_Int32 nHandle
, uno::Any
& rAny
) const
145 // the value set at the data series is the default
146 uno::Reference
< beans::XFastPropertySet
> xFast( m_xParentProperties
.get(), uno::UNO_QUERY
);
149 OSL_ENSURE( m_bNoParentPropAllowed
, "data point needs a parent property set to provide values correctly" );
154 rAny
= xFast
->getFastPropertyValue( nHandle
);
157 void SAL_CALL
DataPoint::setFastPropertyValue_NoBroadcast(
158 sal_Int32 nHandle
, const uno::Any
& rValue
)
160 if( nHandle
== DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y
161 || nHandle
== DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X
)
164 Reference
< util::XModifyBroadcaster
> xBroadcaster
;
165 getFastPropertyValue( aOldValue
, nHandle
);
166 if( aOldValue
.hasValue() &&
167 (aOldValue
>>= xBroadcaster
) &&
170 ModifyListenerHelper::removeListener( xBroadcaster
, m_xModifyEventForwarder
);
173 OSL_ASSERT( rValue
.getValueTypeClass() == uno::TypeClass_INTERFACE
);
174 if( rValue
.hasValue() &&
175 (rValue
>>= xBroadcaster
) &&
178 ModifyListenerHelper::addListener( xBroadcaster
, m_xModifyEventForwarder
);
182 ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle
, rValue
);
185 ::cppu::IPropertyArrayHelper
& SAL_CALL
DataPoint::getInfoHelper()
187 return StaticDataPointInfoHelper();
190 // ____ XPropertySet ____
191 Reference
< beans::XPropertySetInfo
> SAL_CALL
DataPoint::getPropertySetInfo()
193 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
194 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticDataPointInfoHelper() ) );
195 return xPropertySetInfo
;
198 // ____ XModifyBroadcaster ____
199 void SAL_CALL
DataPoint::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
201 m_xModifyEventForwarder
->addModifyListener( aListener
);
204 void SAL_CALL
DataPoint::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
206 m_xModifyEventForwarder
->removeModifyListener( aListener
);
209 // ____ XModifyListener ____
210 void SAL_CALL
DataPoint::modified( const lang::EventObject
& aEvent
)
212 m_xModifyEventForwarder
->modified( aEvent
);
215 // ____ XEventListener (base of XModifyListener) ____
216 void SAL_CALL
DataPoint::disposing( const lang::EventObject
& )
221 // ____ OPropertySet ____
222 void DataPoint::firePropertyChangeEvent()
224 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
227 // needed by MSC compiler
228 using impl::DataPoint_Base
;
230 IMPLEMENT_FORWARD_XINTERFACE2( DataPoint
, DataPoint_Base
, ::property::OPropertySet
)
232 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
233 OUString SAL_CALL
DataPoint::getImplementationName()
235 return u
"com.sun.star.comp.chart.DataPoint"_ustr
;
238 sal_Bool SAL_CALL
DataPoint::supportsService( const OUString
& rServiceName
)
240 return cppu::supportsService(this, rServiceName
);
243 css::uno::Sequence
< OUString
> SAL_CALL
DataPoint::getSupportedServiceNames()
246 u
"com.sun.star.drawing.FillProperties"_ustr
,
247 u
"com.sun.star.chart2.DataPoint"_ustr
,
248 u
"com.sun.star.chart2.DataPointProperties"_ustr
,
249 u
"com.sun.star.beans.PropertySet"_ustr
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */