Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #include "BaseCoordinateSystem.hxx"
22 : : #include "macros.hxx"
23 : : #include "PropertyHelper.hxx"
24 : : #include "UserDefinedProperties.hxx"
25 : : #include "ContainerHelper.hxx"
26 : : #include "CloneHelper.hxx"
27 : : #include "Axis.hxx"
28 : : #include "AxisHelper.hxx"
29 : : #include <com/sun/star/chart2/AxisType.hpp>
30 : :
31 : : #include <algorithm>
32 : :
33 : : #if OSL_DEBUG_LEVEL > 1
34 : : #include <rtl/math.hxx>
35 : : #endif
36 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
37 : :
38 : : using namespace ::com::sun::star;
39 : : using ::com::sun::star::uno::Reference;
40 : : using ::com::sun::star::uno::Sequence;
41 : : using ::rtl::OUString;
42 : : using ::com::sun::star::beans::Property;
43 : :
44 : : namespace
45 : : {
46 : : enum
47 : : {
48 : : PROP_COORDINATESYSTEM_SWAPXANDYAXIS
49 : : };
50 : :
51 : 14 : void lcl_AddPropertiesToVector(
52 : : ::std::vector< Property > & rOutProperties )
53 : : {
54 : : rOutProperties.push_back(
55 : : Property( C2U( "SwapXAndYAxis" ),
56 : : PROP_COORDINATESYSTEM_SWAPXANDYAXIS,
57 [ + - ]: 14 : ::getBooleanCppuType(),
58 : : beans::PropertyAttribute::BOUND
59 [ + - ][ + - ]: 14 : | beans::PropertyAttribute::MAYBEVOID ));
60 : 14 : }
61 : :
62 : : struct StaticCooSysDefaults_Initializer
63 : : {
64 : 14 : ::chart::tPropertyValueMap* operator()()
65 : : {
66 [ + - ][ + - ]: 14 : static ::chart::tPropertyValueMap aStaticDefaults;
[ + - ][ # # ]
67 : 14 : lcl_AddDefaultsToMap( aStaticDefaults );
68 : 14 : return &aStaticDefaults;
69 : : }
70 : : private:
71 : 14 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
72 : : {
73 [ + - ]: 14 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_COORDINATESYSTEM_SWAPXANDYAXIS, false );
74 : 14 : }
75 : : };
76 : :
77 : : struct StaticCooSysDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticCooSysDefaults_Initializer >
78 : : {
79 : : };
80 : :
81 : : struct StaticCooSysInfoHelper_Initializer
82 : : {
83 : 14 : ::cppu::OPropertyArrayHelper* operator()()
84 : : {
85 [ + - ][ + - ]: 14 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
[ + - ][ + - ]
[ + - ][ # # ]
86 : 14 : return &aPropHelper;
87 : : }
88 : :
89 : : private:
90 : 14 : Sequence< Property > lcl_GetPropertySequence()
91 : : {
92 [ + - ]: 14 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
93 [ + - ]: 14 : lcl_AddPropertiesToVector( aProperties );
94 [ + - ]: 14 : ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
95 : :
96 : : ::std::sort( aProperties.begin(), aProperties.end(),
97 [ + - ]: 14 : ::chart::PropertyNameLess() );
98 : :
99 [ + - ]: 14 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
100 : : }
101 : : };
102 : :
103 : : struct StaticCooSysInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticCooSysInfoHelper_Initializer >
104 : : {
105 : : };
106 : :
107 : : struct StaticCooSysInfo_Initializer
108 : : {
109 : 0 : uno::Reference< beans::XPropertySetInfo >* operator()()
110 : : {
111 : : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
112 [ # # ][ # # ]: 0 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticCooSysInfoHelper::get() ) );
[ # # ][ # # ]
[ # # ]
113 : 0 : return &xPropertySetInfo;
114 : : }
115 : : };
116 : :
117 : : struct StaticCooSysInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticCooSysInfo_Initializer >
118 : : {
119 : : };
120 : :
121 : : } // anonymous namespace
122 : :
123 : : namespace chart
124 : : {
125 : :
126 : 100 : BaseCoordinateSystem::BaseCoordinateSystem(
127 : : const Reference< uno::XComponentContext > & xContext,
128 : : sal_Int32 nDimensionCount /* = 2 */,
129 : : sal_Bool bSwapXAndYAxis /* = sal_False */ ) :
130 : : ::property::OPropertySet( m_aMutex ),
131 : : m_xContext( xContext ),
132 : : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
133 [ + - ][ + - ]: 100 : m_nDimensionCount( nDimensionCount )
[ + - ][ + - ]
[ + - ][ + - ]
134 : : {
135 [ + - ]: 100 : m_aAllAxis.resize( m_nDimensionCount );
136 [ + + ]: 306 : for( sal_Int32 nN=0; nN<m_nDimensionCount; nN++ )
137 : : {
138 [ + - ]: 206 : m_aAllAxis[nN].resize( 1 );
139 [ + - ][ + - ]: 206 : Reference< chart2::XAxis > xAxis( new Axis(m_xContext) );
[ + - ]
140 [ + - ]: 206 : m_aAllAxis[nN][0] = xAxis;
141 : :
142 [ + - ]: 206 : ModifyListenerHelper::addListenerToAllElements( m_aAllAxis[nN], m_xModifyEventForwarder );
143 [ + - ][ + - ]: 206 : chart2::ScaleData aScaleData( xAxis->getScaleData() );
144 [ + + ]: 206 : if(nN==0)
145 : : {
146 : 100 : aScaleData.AxisType = chart2::AxisType::CATEGORY;
147 : : }
148 [ + + ]: 106 : else if( nN==1)
149 : : {
150 : 100 : aScaleData.AxisType = chart2::AxisType::REALNUMBER;
151 : : }
152 [ + - ]: 6 : else if( nN==2)
153 : : {
154 : 6 : aScaleData.AxisType = chart2::AxisType::SERIES;
155 : : }
156 [ + - ][ + - ]: 206 : xAxis->setScaleData( aScaleData );
157 [ + - ]: 206 : }
158 : :
159 [ + - ]: 100 : m_aOrigin.realloc( m_nDimensionCount );
160 [ + + ]: 306 : for( sal_Int32 i = 0; i < m_nDimensionCount; ++i )
161 [ + - ][ + - ]: 206 : m_aOrigin[ i ] = uno::makeAny( double( 0.0 ) );
162 : :
163 [ + - ][ + - ]: 100 : setFastPropertyValue_NoBroadcast( PROP_COORDINATESYSTEM_SWAPXANDYAXIS, uno::makeAny( sal_Bool( bSwapXAndYAxis )));
164 : 100 : }
165 : :
166 : : // explicit
167 : 0 : BaseCoordinateSystem::BaseCoordinateSystem(
168 : : const BaseCoordinateSystem & rSource ) :
169 : : impl::BaseCoordinateSystem_Base(),
170 : : MutexContainer(),
171 : : ::property::OPropertySet( rSource, m_aMutex ),
172 : : m_xContext( rSource.m_xContext ),
173 : : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
174 : : m_nDimensionCount( rSource.m_nDimensionCount ),
175 [ # # ][ # # ]: 0 : m_aOrigin( rSource.m_aOrigin )
[ # # ][ # # ]
[ # # ][ # # ]
176 : : {
177 [ # # ]: 0 : m_aAllAxis.resize(rSource.m_aAllAxis.size());
178 : 0 : tAxisVecVecType::size_type nN=0;
179 [ # # ]: 0 : for( nN=0; nN<m_aAllAxis.size(); nN++ )
180 [ # # ]: 0 : CloneHelper::CloneRefVector< Reference< chart2::XAxis > >( rSource.m_aAllAxis[nN], m_aAllAxis[nN] );
181 [ # # ]: 0 : CloneHelper::CloneRefVector< Reference< chart2::XChartType > >( rSource.m_aChartTypes, m_aChartTypes );
182 : :
183 [ # # ]: 0 : for( nN=0; nN<m_aAllAxis.size(); nN++ )
184 [ # # ]: 0 : ModifyListenerHelper::addListenerToAllElements( m_aAllAxis[nN], m_xModifyEventForwarder );
185 [ # # ]: 0 : ModifyListenerHelper::addListenerToAllElements( m_aChartTypes, m_xModifyEventForwarder );
186 : 0 : }
187 : :
188 [ + - ][ + - ]: 100 : BaseCoordinateSystem::~BaseCoordinateSystem()
[ + - ]
189 : : {
190 : : try
191 : : {
192 [ + + ]: 306 : for( tAxisVecVecType::size_type nN=0; nN<m_aAllAxis.size(); nN++ )
193 [ + - ]: 206 : ModifyListenerHelper::removeListenerFromAllElements( m_aAllAxis[nN], m_xModifyEventForwarder );
194 [ + - ]: 100 : ModifyListenerHelper::removeListenerFromAllElements( m_aChartTypes, m_xModifyEventForwarder );
195 : : }
196 [ # # ]: 0 : catch( const uno::Exception & ex )
197 : : {
198 : : ASSERT_EXCEPTION( ex );
199 : : }
200 [ - + ][ # # ]: 100 : }
201 : :
202 : : // ____ XCoordinateSystem ____
203 : 407462 : sal_Int32 SAL_CALL BaseCoordinateSystem::getDimension()
204 : : throw (uno::RuntimeException)
205 : : {
206 : 407462 : return m_nDimensionCount;
207 : : }
208 : :
209 : 24 : void SAL_CALL BaseCoordinateSystem::setAxisByDimension(
210 : : sal_Int32 nDimensionIndex,
211 : : const Reference< chart2::XAxis >& xAxis,
212 : : sal_Int32 nIndex )
213 : : throw (lang::IndexOutOfBoundsException,
214 : : uno::RuntimeException)
215 : : {
216 [ + - ][ + - ]: 24 : if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() )
[ - + ][ - + ]
217 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
218 : :
219 [ - + ]: 24 : if( nIndex < 0 )
220 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
221 : :
222 [ + + ]: 24 : if( m_aAllAxis[ nDimensionIndex ].size() < static_cast< tAxisVecVecType::size_type >( nIndex+1 ))
223 : : {
224 [ + - ]: 4 : m_aAllAxis[ nDimensionIndex ].resize( nIndex+1 );
225 [ + - ]: 4 : m_aAllAxis[ nDimensionIndex ][nIndex] = 0;
226 : : }
227 : :
228 : 24 : Reference< chart2::XAxis > xOldAxis( m_aAllAxis[ nDimensionIndex ][nIndex] );
229 [ + + ]: 24 : if( xOldAxis.is())
230 [ + - ]: 20 : ModifyListenerHelper::removeListener( xOldAxis, m_xModifyEventForwarder );
231 [ + - ]: 24 : m_aAllAxis[ nDimensionIndex ][nIndex] = xAxis;
232 [ + - ]: 24 : if( xAxis.is())
233 [ + - ]: 24 : ModifyListenerHelper::addListener( xAxis, m_xModifyEventForwarder );
234 [ + - ]: 24 : fireModifyEvent();
235 : 24 : }
236 : :
237 : 133289 : Reference< chart2::XAxis > SAL_CALL BaseCoordinateSystem::getAxisByDimension(
238 : : sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
239 : : throw (lang::IndexOutOfBoundsException,
240 : : uno::RuntimeException)
241 : : {
242 [ + - ][ + + ]: 133289 : if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() )
[ + + ]
243 [ + - ]: 7118 : throw lang::IndexOutOfBoundsException();
244 : :
245 : : OSL_ASSERT( m_aAllAxis.size() == static_cast< size_t >( getDimension()));
246 : :
247 [ + - ][ + + ]: 126171 : if( nAxisIndex < 0 || nAxisIndex > this->getMaximumAxisIndexByDimension(nDimensionIndex) )
[ + + ]
248 [ + - ]: 8178 : throw lang::IndexOutOfBoundsException();
249 : :
250 : 117993 : return m_aAllAxis[ nDimensionIndex ][nAxisIndex];
251 : : }
252 : :
253 : 201223 : sal_Int32 SAL_CALL BaseCoordinateSystem::getMaximumAxisIndexByDimension( sal_Int32 nDimensionIndex )
254 : : throw (lang::IndexOutOfBoundsException,
255 : : uno::RuntimeException)
256 : : {
257 [ + - ][ - + ]: 201223 : if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() )
[ - + ]
258 [ # # ]: 0 : throw lang::IndexOutOfBoundsException();
259 : :
260 : : OSL_ASSERT( m_aAllAxis.size() == static_cast< size_t >( getDimension()));
261 : :
262 : 201223 : sal_Int32 nRet = m_aAllAxis[ nDimensionIndex ].size();
263 [ + - ]: 201223 : if(nRet)
264 : 201223 : nRet-=1;
265 : :
266 : 201223 : return nRet;
267 : : }
268 : :
269 : : // ____ XChartTypeContainer ____
270 : 74 : void SAL_CALL BaseCoordinateSystem::addChartType( const Reference< chart2::XChartType >& aChartType )
271 : : throw (lang::IllegalArgumentException,
272 : : uno::RuntimeException)
273 : : {
274 [ + - ][ - + ]: 148 : if( ::std::find( m_aChartTypes.begin(), m_aChartTypes.end(), aChartType )
275 [ + - ]: 148 : != m_aChartTypes.end())
276 [ # # ]: 0 : throw lang::IllegalArgumentException();
277 : :
278 : 74 : m_aChartTypes.push_back( aChartType );
279 : 74 : ModifyListenerHelper::addListener( aChartType, m_xModifyEventForwarder );
280 : 74 : fireModifyEvent();
281 : 74 : }
282 : :
283 : 0 : void SAL_CALL BaseCoordinateSystem::removeChartType( const Reference< chart2::XChartType >& aChartType )
284 : : throw (container::NoSuchElementException,
285 : : uno::RuntimeException)
286 : : {
287 : : ::std::vector< uno::Reference< chart2::XChartType > >::iterator
288 [ # # ]: 0 : aIt( ::std::find( m_aChartTypes.begin(), m_aChartTypes.end(), aChartType ));
289 [ # # ][ # # ]: 0 : if( aIt == m_aChartTypes.end())
290 : : throw container::NoSuchElementException(
291 : : C2U( "The given chart type is no element of the container" ),
292 [ # # ][ # # ]: 0 : static_cast< uno::XWeak * >( this ));
[ # # ]
293 : :
294 [ # # ]: 0 : m_aChartTypes.erase( aIt );
295 [ # # ]: 0 : ModifyListenerHelper::removeListener( aChartType, m_xModifyEventForwarder );
296 [ # # ]: 0 : fireModifyEvent();
297 : 0 : }
298 : :
299 : 52342 : Sequence< Reference< chart2::XChartType > > SAL_CALL BaseCoordinateSystem::getChartTypes()
300 : : throw (uno::RuntimeException)
301 : : {
302 : 52342 : return ContainerHelper::ContainerToSequence( m_aChartTypes );
303 : : }
304 : :
305 : 52 : void SAL_CALL BaseCoordinateSystem::setChartTypes( const Sequence< Reference< chart2::XChartType > >& aChartTypes )
306 : : throw (lang::IllegalArgumentException,
307 : : uno::RuntimeException)
308 : : {
309 : 52 : ModifyListenerHelper::removeListenerFromAllElements( m_aChartTypes, m_xModifyEventForwarder );
310 : 52 : m_aChartTypes = ContainerHelper::SequenceToVector( aChartTypes );
311 : 52 : ModifyListenerHelper::addListenerToAllElements( m_aChartTypes, m_xModifyEventForwarder );
312 : 52 : fireModifyEvent();
313 : 52 : }
314 : :
315 : : // ____ XModifyBroadcaster ____
316 : 78 : void SAL_CALL BaseCoordinateSystem::addModifyListener( const Reference< util::XModifyListener >& aListener )
317 : : throw (uno::RuntimeException)
318 : : {
319 : : try
320 : : {
321 [ + - ]: 78 : Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
322 [ + - ][ + - ]: 78 : xBroadcaster->addModifyListener( aListener );
[ # # ]
323 : : }
324 : 0 : catch( const uno::Exception & ex )
325 : : {
326 : : ASSERT_EXCEPTION( ex );
327 : : }
328 : 78 : }
329 : :
330 : 78 : void SAL_CALL BaseCoordinateSystem::removeModifyListener( const Reference< util::XModifyListener >& aListener )
331 : : throw (uno::RuntimeException)
332 : : {
333 : : try
334 : : {
335 [ + - ]: 78 : Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
336 [ + - ][ + - ]: 78 : xBroadcaster->removeModifyListener( aListener );
[ # # ]
337 : : }
338 : 0 : catch( const uno::Exception & ex )
339 : : {
340 : : ASSERT_EXCEPTION( ex );
341 : : }
342 : 78 : }
343 : :
344 : : // ____ XModifyListener ____
345 : 0 : void SAL_CALL BaseCoordinateSystem::modified( const lang::EventObject& aEvent )
346 : : throw (uno::RuntimeException)
347 : : {
348 : 0 : m_xModifyEventForwarder->modified( aEvent );
349 : 0 : }
350 : :
351 : : // ____ XEventListener (base of XModifyListener) ____
352 : 0 : void SAL_CALL BaseCoordinateSystem::disposing( const lang::EventObject& /* Source */ )
353 : : throw (uno::RuntimeException)
354 : : {
355 : : // nothing
356 : 0 : }
357 : :
358 : : // ____ OPropertySet ____
359 : 2 : void BaseCoordinateSystem::firePropertyChangeEvent()
360 : : {
361 : 2 : fireModifyEvent();
362 : 2 : }
363 : :
364 : 152 : void BaseCoordinateSystem::fireModifyEvent()
365 : : {
366 [ + - ][ + - ]: 152 : m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
[ + - ]
367 : 152 : }
368 : :
369 : :
370 : : // ____ OPropertySet ____
371 : 10225 : uno::Any BaseCoordinateSystem::GetDefaultValue( sal_Int32 nHandle ) const
372 : : throw(beans::UnknownPropertyException)
373 : : {
374 [ + - ]: 10225 : const tPropertyValueMap& rStaticDefaults = *StaticCooSysDefaults::get();
375 [ + - ]: 10225 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
376 [ - + ]: 10225 : if( aFound == rStaticDefaults.end() )
377 : 0 : return uno::Any();
378 : 10225 : return (*aFound).second;
379 : : }
380 : :
381 : : // ____ OPropertySet ____
382 : 20340 : ::cppu::IPropertyArrayHelper & SAL_CALL BaseCoordinateSystem::getInfoHelper()
383 : : {
384 : 20340 : return *StaticCooSysInfoHelper::get();
385 : : }
386 : :
387 : :
388 : : // ____ XPropertySet ____
389 : 0 : Reference< beans::XPropertySetInfo > SAL_CALL BaseCoordinateSystem::getPropertySetInfo()
390 : : throw (uno::RuntimeException)
391 : : {
392 : 0 : return *StaticCooSysInfo::get();
393 : : }
394 : :
395 : : using impl::BaseCoordinateSystem_Base;
396 : :
397 [ + + ][ + - ]: 726692 : IMPLEMENT_FORWARD_XINTERFACE2( BaseCoordinateSystem, BaseCoordinateSystem_Base, ::property::OPropertySet )
398 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( BaseCoordinateSystem, BaseCoordinateSystem_Base, ::property::OPropertySet )
[ # # ]
399 : :
400 : : } // namespace chart
401 : :
402 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|