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 "BaseCoordinateSystem.hxx"
22 #include "PropertyHelper.hxx"
23 #include "UserDefinedProperties.hxx"
24 #include "ContainerHelper.hxx"
25 #include "CloneHelper.hxx"
27 #include "AxisHelper.hxx"
28 #include <com/sun/star/chart2/AxisType.hpp>
33 #if OSL_DEBUG_LEVEL > 1
34 #include <rtl/math.hxx>
36 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 using namespace ::com::sun::star
;
39 using ::com::sun::star::uno::Reference
;
40 using ::com::sun::star::uno::Sequence
;
41 using ::com::sun::star::beans::Property
;
47 PROP_COORDINATESYSTEM_SWAPXANDYAXIS
50 void lcl_AddPropertiesToVector(
51 ::std::vector
< Property
> & rOutProperties
)
53 rOutProperties
.push_back(
54 Property( "SwapXAndYAxis",
55 PROP_COORDINATESYSTEM_SWAPXANDYAXIS
,
56 cppu::UnoType
<bool>::get(),
57 beans::PropertyAttribute::BOUND
58 | beans::PropertyAttribute::MAYBEVOID
));
61 struct StaticCooSysDefaults_Initializer
63 ::chart::tPropertyValueMap
* operator()()
65 static ::chart::tPropertyValueMap aStaticDefaults
;
66 lcl_AddDefaultsToMap( aStaticDefaults
);
67 return &aStaticDefaults
;
70 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
72 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_COORDINATESYSTEM_SWAPXANDYAXIS
, false );
76 struct StaticCooSysDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticCooSysDefaults_Initializer
>
80 struct StaticCooSysInfoHelper_Initializer
82 ::cppu::OPropertyArrayHelper
* operator()()
84 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
89 static Sequence
< Property
> lcl_GetPropertySequence()
91 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
92 lcl_AddPropertiesToVector( aProperties
);
93 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
95 ::std::sort( aProperties
.begin(), aProperties
.end(),
96 ::chart::PropertyNameLess() );
98 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
102 struct StaticCooSysInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticCooSysInfoHelper_Initializer
>
106 struct StaticCooSysInfo_Initializer
108 uno::Reference
< beans::XPropertySetInfo
>* operator()()
110 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
111 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticCooSysInfoHelper::get() ) );
112 return &xPropertySetInfo
;
116 struct StaticCooSysInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticCooSysInfo_Initializer
>
120 } // anonymous namespace
125 BaseCoordinateSystem::BaseCoordinateSystem(
126 const Reference
< uno::XComponentContext
> & xContext
,
127 sal_Int32 nDimensionCount
/* = 2 */,
128 bool bSwapXAndYAxis
/* = sal_False */ ) :
129 ::property::OPropertySet( m_aMutex
),
130 m_xContext( xContext
),
131 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
132 m_nDimensionCount( nDimensionCount
)
134 m_aAllAxis
.resize( m_nDimensionCount
);
135 for( sal_Int32 nN
=0; nN
<m_nDimensionCount
; nN
++ )
137 m_aAllAxis
[nN
].resize( 1 );
138 Reference
< chart2::XAxis
> xAxis( new Axis(m_xContext
) );
139 m_aAllAxis
[nN
][0] = xAxis
;
141 ModifyListenerHelper::addListenerToAllElements( m_aAllAxis
[nN
], m_xModifyEventForwarder
);
142 chart2::ScaleData
aScaleData( xAxis
->getScaleData() );
145 aScaleData
.AxisType
= chart2::AxisType::CATEGORY
;
149 aScaleData
.AxisType
= chart2::AxisType::REALNUMBER
;
153 aScaleData
.AxisType
= chart2::AxisType::SERIES
;
155 xAxis
->setScaleData( aScaleData
);
158 m_aOrigin
.realloc( m_nDimensionCount
);
159 for( sal_Int32 i
= 0; i
< m_nDimensionCount
; ++i
)
160 m_aOrigin
[ i
] = uno::makeAny( double( 0.0 ) );
162 setFastPropertyValue_NoBroadcast( PROP_COORDINATESYSTEM_SWAPXANDYAXIS
, uno::makeAny( bSwapXAndYAxis
));
166 BaseCoordinateSystem::BaseCoordinateSystem(
167 const BaseCoordinateSystem
& rSource
) :
168 impl::BaseCoordinateSystem_Base(),
170 ::property::OPropertySet( rSource
, m_aMutex
),
171 m_xContext( rSource
.m_xContext
),
172 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
173 m_nDimensionCount( rSource
.m_nDimensionCount
),
174 m_aOrigin( rSource
.m_aOrigin
)
176 m_aAllAxis
.resize(rSource
.m_aAllAxis
.size());
177 tAxisVecVecType::size_type nN
=0;
178 for( nN
=0; nN
<m_aAllAxis
.size(); nN
++ )
179 CloneHelper::CloneRefVector
< Reference
< chart2::XAxis
> >( rSource
.m_aAllAxis
[nN
], m_aAllAxis
[nN
] );
180 CloneHelper::CloneRefVector
< Reference
< chart2::XChartType
> >( rSource
.m_aChartTypes
, m_aChartTypes
);
182 for( nN
=0; nN
<m_aAllAxis
.size(); nN
++ )
183 ModifyListenerHelper::addListenerToAllElements( m_aAllAxis
[nN
], m_xModifyEventForwarder
);
184 ModifyListenerHelper::addListenerToAllElements( m_aChartTypes
, m_xModifyEventForwarder
);
187 BaseCoordinateSystem::~BaseCoordinateSystem()
191 for( tAxisVecVecType::size_type nN
=0; nN
<m_aAllAxis
.size(); nN
++ )
192 ModifyListenerHelper::removeListenerFromAllElements( m_aAllAxis
[nN
], m_xModifyEventForwarder
);
193 ModifyListenerHelper::removeListenerFromAllElements( m_aChartTypes
, m_xModifyEventForwarder
);
195 catch( const uno::Exception
& ex
)
197 ASSERT_EXCEPTION( ex
);
201 // ____ XCoordinateSystem ____
202 sal_Int32 SAL_CALL
BaseCoordinateSystem::getDimension()
203 throw (uno::RuntimeException
, std::exception
)
205 return m_nDimensionCount
;
208 void SAL_CALL
BaseCoordinateSystem::setAxisByDimension(
209 sal_Int32 nDimensionIndex
,
210 const Reference
< chart2::XAxis
>& xAxis
,
212 throw (lang::IndexOutOfBoundsException
,
213 uno::RuntimeException
, std::exception
)
215 if( nDimensionIndex
< 0 || nDimensionIndex
>= getDimension() )
216 throw lang::IndexOutOfBoundsException();
219 throw lang::IndexOutOfBoundsException();
221 if( m_aAllAxis
[ nDimensionIndex
].size() < static_cast< tAxisVecVecType::size_type
>( nIndex
+1 ))
223 m_aAllAxis
[ nDimensionIndex
].resize( nIndex
+1 );
224 m_aAllAxis
[ nDimensionIndex
][nIndex
] = 0;
227 Reference
< chart2::XAxis
> xOldAxis( m_aAllAxis
[ nDimensionIndex
][nIndex
] );
229 ModifyListenerHelper::removeListener( xOldAxis
, m_xModifyEventForwarder
);
230 m_aAllAxis
[ nDimensionIndex
][nIndex
] = xAxis
;
232 ModifyListenerHelper::addListener( xAxis
, m_xModifyEventForwarder
);
236 Reference
< chart2::XAxis
> SAL_CALL
BaseCoordinateSystem::getAxisByDimension(
237 sal_Int32 nDimensionIndex
, sal_Int32 nAxisIndex
)
238 throw (lang::IndexOutOfBoundsException
,
239 uno::RuntimeException
, std::exception
)
241 if( nDimensionIndex
< 0 || nDimensionIndex
>= getDimension() )
242 throw lang::IndexOutOfBoundsException();
244 OSL_ASSERT( m_aAllAxis
.size() == static_cast< size_t >( getDimension()));
246 if( nAxisIndex
< 0 || nAxisIndex
> this->getMaximumAxisIndexByDimension(nDimensionIndex
) )
247 throw lang::IndexOutOfBoundsException();
249 return m_aAllAxis
[ nDimensionIndex
][nAxisIndex
];
252 sal_Int32 SAL_CALL
BaseCoordinateSystem::getMaximumAxisIndexByDimension( sal_Int32 nDimensionIndex
)
253 throw (lang::IndexOutOfBoundsException
,
254 uno::RuntimeException
, std::exception
)
256 if( nDimensionIndex
< 0 || nDimensionIndex
>= getDimension() )
257 throw lang::IndexOutOfBoundsException();
259 OSL_ASSERT( m_aAllAxis
.size() == static_cast< size_t >( getDimension()));
261 sal_Int32 nRet
= m_aAllAxis
[ nDimensionIndex
].size();
268 // ____ XChartTypeContainer ____
269 void SAL_CALL
BaseCoordinateSystem::addChartType( const Reference
< chart2::XChartType
>& aChartType
)
270 throw (lang::IllegalArgumentException
,
271 uno::RuntimeException
, std::exception
)
273 if( ::std::find( m_aChartTypes
.begin(), m_aChartTypes
.end(), aChartType
)
274 != m_aChartTypes
.end())
275 throw lang::IllegalArgumentException();
277 m_aChartTypes
.push_back( aChartType
);
278 ModifyListenerHelper::addListener( aChartType
, m_xModifyEventForwarder
);
282 void SAL_CALL
BaseCoordinateSystem::removeChartType( const Reference
< chart2::XChartType
>& aChartType
)
283 throw (container::NoSuchElementException
,
284 uno::RuntimeException
, std::exception
)
286 ::std::vector
< uno::Reference
< chart2::XChartType
> >::iterator
287 aIt( ::std::find( m_aChartTypes
.begin(), m_aChartTypes
.end(), aChartType
));
288 if( aIt
== m_aChartTypes
.end())
289 throw container::NoSuchElementException(
290 "The given chart type is no element of the container",
291 static_cast< uno::XWeak
* >( this ));
293 m_aChartTypes
.erase( aIt
);
294 ModifyListenerHelper::removeListener( aChartType
, m_xModifyEventForwarder
);
298 Sequence
< Reference
< chart2::XChartType
> > SAL_CALL
BaseCoordinateSystem::getChartTypes()
299 throw (uno::RuntimeException
, std::exception
)
301 return ContainerHelper::ContainerToSequence( m_aChartTypes
);
304 void SAL_CALL
BaseCoordinateSystem::setChartTypes( const Sequence
< Reference
< chart2::XChartType
> >& aChartTypes
)
305 throw (lang::IllegalArgumentException
,
306 uno::RuntimeException
, std::exception
)
308 ModifyListenerHelper::removeListenerFromAllElements( m_aChartTypes
, m_xModifyEventForwarder
);
309 m_aChartTypes
= ContainerHelper::SequenceToVector( aChartTypes
);
310 ModifyListenerHelper::addListenerToAllElements( m_aChartTypes
, m_xModifyEventForwarder
);
314 // ____ XModifyBroadcaster ____
315 void SAL_CALL
BaseCoordinateSystem::addModifyListener( const Reference
< util::XModifyListener
>& aListener
)
316 throw (uno::RuntimeException
, std::exception
)
320 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
321 xBroadcaster
->addModifyListener( aListener
);
323 catch( const uno::Exception
& ex
)
325 ASSERT_EXCEPTION( ex
);
329 void SAL_CALL
BaseCoordinateSystem::removeModifyListener( const Reference
< util::XModifyListener
>& aListener
)
330 throw (uno::RuntimeException
, std::exception
)
334 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
335 xBroadcaster
->removeModifyListener( aListener
);
337 catch( const uno::Exception
& ex
)
339 ASSERT_EXCEPTION( ex
);
343 // ____ XModifyListener ____
344 void SAL_CALL
BaseCoordinateSystem::modified( const lang::EventObject
& aEvent
)
345 throw (uno::RuntimeException
, std::exception
)
347 m_xModifyEventForwarder
->modified( aEvent
);
350 // ____ XEventListener (base of XModifyListener) ____
351 void SAL_CALL
BaseCoordinateSystem::disposing( const lang::EventObject
& /* Source */ )
352 throw (uno::RuntimeException
, std::exception
)
357 // ____ OPropertySet ____
358 void BaseCoordinateSystem::firePropertyChangeEvent()
363 void BaseCoordinateSystem::fireModifyEvent()
365 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
368 // ____ OPropertySet ____
369 uno::Any
BaseCoordinateSystem::GetDefaultValue( sal_Int32 nHandle
) const
370 throw(beans::UnknownPropertyException
)
372 const tPropertyValueMap
& rStaticDefaults
= *StaticCooSysDefaults::get();
373 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
374 if( aFound
== rStaticDefaults
.end() )
376 return (*aFound
).second
;
379 // ____ OPropertySet ____
380 ::cppu::IPropertyArrayHelper
& SAL_CALL
BaseCoordinateSystem::getInfoHelper()
382 return *StaticCooSysInfoHelper::get();
385 // ____ XPropertySet ____
386 Reference
< beans::XPropertySetInfo
> SAL_CALL
BaseCoordinateSystem::getPropertySetInfo()
387 throw (uno::RuntimeException
, std::exception
)
389 return *StaticCooSysInfo::get();
392 using impl::BaseCoordinateSystem_Base
;
394 IMPLEMENT_FORWARD_XINTERFACE2( BaseCoordinateSystem
, BaseCoordinateSystem_Base
, ::property::OPropertySet
)
395 IMPLEMENT_FORWARD_XTYPEPROVIDER2( BaseCoordinateSystem
, BaseCoordinateSystem_Base
, ::property::OPropertySet
)
399 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */