1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "BaseCoordinateSystem.hxx"
33 #include "PropertyHelper.hxx"
34 #include "UserDefinedProperties.hxx"
35 #include "ContainerHelper.hxx"
36 #include "CloneHelper.hxx"
38 #include "AxisHelper.hxx"
39 #include <com/sun/star/chart2/AxisType.hpp>
43 #if OSL_DEBUG_LEVEL > 1
44 #include <rtl/math.hxx>
46 #include <com/sun/star/beans/PropertyAttribute.hpp>
48 using namespace ::com::sun::star
;
49 using ::com::sun::star::uno::Reference
;
50 using ::com::sun::star::uno::Sequence
;
51 using ::rtl::OUString
;
52 using ::com::sun::star::beans::Property
;
58 PROP_COORDINATESYSTEM_SWAPXANDYAXIS
61 void lcl_AddPropertiesToVector(
62 ::std::vector
< Property
> & rOutProperties
)
64 rOutProperties
.push_back(
65 Property( C2U( "SwapXAndYAxis" ),
66 PROP_COORDINATESYSTEM_SWAPXANDYAXIS
,
67 ::getBooleanCppuType(),
68 beans::PropertyAttribute::BOUND
69 | beans::PropertyAttribute::MAYBEVOID
));
72 void lcl_AddDefaultsToMap(
73 ::chart::tPropertyValueMap
& rOutMap
)
75 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_COORDINATESYSTEM_SWAPXANDYAXIS
, false );
78 const Sequence
< Property
> & lcl_GetPropertySequence()
80 static Sequence
< Property
> aPropSeq
;
83 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
84 if( 0 == aPropSeq
.getLength() )
87 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
88 lcl_AddPropertiesToVector( aProperties
);
89 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
91 // and sort them for access via bsearch
92 ::std::sort( aProperties
.begin(), aProperties
.end(),
93 ::chart::PropertyNameLess() );
95 // transfer result to static Sequence
96 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
102 } // anonymous namespace
107 BaseCoordinateSystem::BaseCoordinateSystem(
108 const Reference
< uno::XComponentContext
> & xContext
,
109 sal_Int32 nDimensionCount
/* = 2 */,
110 sal_Bool bSwapXAndYAxis
/* = sal_False */ ) :
111 ::property::OPropertySet( m_aMutex
),
112 m_xContext( xContext
),
113 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
114 m_nDimensionCount( nDimensionCount
)
116 m_aAllAxis
.resize( m_nDimensionCount
);
117 for( sal_Int32 nN
=0; nN
<m_nDimensionCount
; nN
++ )
119 m_aAllAxis
[nN
].resize( 1 );
120 Reference
< chart2::XAxis
> xAxis( new Axis(m_xContext
) );
121 m_aAllAxis
[nN
][0] = xAxis
;
123 ModifyListenerHelper::addListenerToAllElements( m_aAllAxis
[nN
], m_xModifyEventForwarder
);
124 chart2::ScaleData
aScaleData( xAxis
->getScaleData() );
127 aScaleData
.AxisType
= chart2::AxisType::CATEGORY
;
131 aScaleData
.AxisType
= chart2::AxisType::REALNUMBER
;
135 aScaleData
.AxisType
= chart2::AxisType::SERIES
;
137 xAxis
->setScaleData( aScaleData
);
140 m_aOrigin
.realloc( m_nDimensionCount
);
141 for( sal_Int32 i
= 0; i
< m_nDimensionCount
; ++i
)
142 m_aOrigin
[ i
] = uno::makeAny( double( 0.0 ) );
144 setFastPropertyValue_NoBroadcast( PROP_COORDINATESYSTEM_SWAPXANDYAXIS
, uno::makeAny( sal_Bool( bSwapXAndYAxis
)));
148 BaseCoordinateSystem::BaseCoordinateSystem(
149 const BaseCoordinateSystem
& rSource
) :
150 impl::BaseCoordinateSystem_Base(),
152 ::property::OPropertySet( rSource
, m_aMutex
),
153 m_xContext( rSource
.m_xContext
),
154 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
155 m_nDimensionCount( rSource
.m_nDimensionCount
),
156 m_aOrigin( rSource
.m_aOrigin
)
158 m_aAllAxis
.resize(rSource
.m_aAllAxis
.size());
159 tAxisVecVecType::size_type nN
=0;
160 for( nN
=0; nN
<m_aAllAxis
.size(); nN
++ )
161 CloneHelper::CloneRefVector
< Reference
< chart2::XAxis
> >( rSource
.m_aAllAxis
[nN
], m_aAllAxis
[nN
] );
162 CloneHelper::CloneRefVector
< Reference
< chart2::XChartType
> >( rSource
.m_aChartTypes
, m_aChartTypes
);
164 for( nN
=0; nN
<m_aAllAxis
.size(); nN
++ )
165 ModifyListenerHelper::addListenerToAllElements( m_aAllAxis
[nN
], m_xModifyEventForwarder
);
166 ModifyListenerHelper::addListenerToAllElements( m_aChartTypes
, m_xModifyEventForwarder
);
169 BaseCoordinateSystem::~BaseCoordinateSystem()
173 for( tAxisVecVecType::size_type nN
=0; nN
<m_aAllAxis
.size(); nN
++ )
174 ModifyListenerHelper::removeListenerFromAllElements( m_aAllAxis
[nN
], m_xModifyEventForwarder
);
175 ModifyListenerHelper::removeListenerFromAllElements( m_aChartTypes
, m_xModifyEventForwarder
);
177 catch( const uno::Exception
& ex
)
179 ASSERT_EXCEPTION( ex
);
183 // ____ XCoordinateSystem ____
184 sal_Int32 SAL_CALL
BaseCoordinateSystem::getDimension()
185 throw (uno::RuntimeException
)
187 return m_nDimensionCount
;
190 void SAL_CALL
BaseCoordinateSystem::setAxisByDimension(
191 sal_Int32 nDimensionIndex
,
192 const Reference
< chart2::XAxis
>& xAxis
,
194 throw (lang::IndexOutOfBoundsException
,
195 uno::RuntimeException
)
197 if( nDimensionIndex
< 0 || nDimensionIndex
>= getDimension() )
198 throw lang::IndexOutOfBoundsException();
201 throw lang::IndexOutOfBoundsException();
203 if( m_aAllAxis
[ nDimensionIndex
].size() < static_cast< tAxisVecVecType::size_type
>( nIndex
+1 ))
205 m_aAllAxis
[ nDimensionIndex
].resize( nIndex
+1 );
206 m_aAllAxis
[ nDimensionIndex
][nIndex
] = 0;
209 Reference
< chart2::XAxis
> xOldAxis( m_aAllAxis
[ nDimensionIndex
][nIndex
] );
211 ModifyListenerHelper::removeListener( xOldAxis
, m_xModifyEventForwarder
);
212 m_aAllAxis
[ nDimensionIndex
][nIndex
] = xAxis
;
214 ModifyListenerHelper::addListener( xAxis
, m_xModifyEventForwarder
);
218 Reference
< chart2::XAxis
> SAL_CALL
BaseCoordinateSystem::getAxisByDimension(
219 sal_Int32 nDimensionIndex
, sal_Int32 nAxisIndex
)
220 throw (lang::IndexOutOfBoundsException
,
221 uno::RuntimeException
)
223 if( nDimensionIndex
< 0 || nDimensionIndex
>= getDimension() )
224 throw lang::IndexOutOfBoundsException();
226 OSL_ASSERT( m_aAllAxis
.size() == static_cast< size_t >( getDimension()));
228 if( nAxisIndex
< 0 || nAxisIndex
> this->getMaximumAxisIndexByDimension(nDimensionIndex
) )
229 throw lang::IndexOutOfBoundsException();
231 return m_aAllAxis
[ nDimensionIndex
][nAxisIndex
];
234 sal_Int32 SAL_CALL
BaseCoordinateSystem::getMaximumAxisIndexByDimension( sal_Int32 nDimensionIndex
)
235 throw (lang::IndexOutOfBoundsException
,
236 uno::RuntimeException
)
238 if( nDimensionIndex
< 0 || nDimensionIndex
>= getDimension() )
239 throw lang::IndexOutOfBoundsException();
241 OSL_ASSERT( m_aAllAxis
.size() == static_cast< size_t >( getDimension()));
243 sal_Int32 nRet
= m_aAllAxis
[ nDimensionIndex
].size();
250 // ____ XChartTypeContainer ____
251 void SAL_CALL
BaseCoordinateSystem::addChartType( const Reference
< chart2::XChartType
>& aChartType
)
252 throw (lang::IllegalArgumentException
,
253 uno::RuntimeException
)
255 if( ::std::find( m_aChartTypes
.begin(), m_aChartTypes
.end(), aChartType
)
256 != m_aChartTypes
.end())
257 throw lang::IllegalArgumentException();
259 m_aChartTypes
.push_back( aChartType
);
260 ModifyListenerHelper::addListener( aChartType
, m_xModifyEventForwarder
);
264 void SAL_CALL
BaseCoordinateSystem::removeChartType( const Reference
< chart2::XChartType
>& aChartType
)
265 throw (container::NoSuchElementException
,
266 uno::RuntimeException
)
268 ::std::vector
< uno::Reference
< chart2::XChartType
> >::iterator
269 aIt( ::std::find( m_aChartTypes
.begin(), m_aChartTypes
.end(), aChartType
));
270 if( aIt
== m_aChartTypes
.end())
271 throw container::NoSuchElementException(
272 C2U( "The given chart type is no element of the container" ),
273 static_cast< uno::XWeak
* >( this ));
275 m_aChartTypes
.erase( aIt
);
276 ModifyListenerHelper::removeListener( aChartType
, m_xModifyEventForwarder
);
280 Sequence
< Reference
< chart2::XChartType
> > SAL_CALL
BaseCoordinateSystem::getChartTypes()
281 throw (uno::RuntimeException
)
283 return ContainerHelper::ContainerToSequence( m_aChartTypes
);
286 void SAL_CALL
BaseCoordinateSystem::setChartTypes( const Sequence
< Reference
< chart2::XChartType
> >& aChartTypes
)
287 throw (lang::IllegalArgumentException
,
288 uno::RuntimeException
)
290 ModifyListenerHelper::removeListenerFromAllElements( m_aChartTypes
, m_xModifyEventForwarder
);
291 m_aChartTypes
= ContainerHelper::SequenceToVector( aChartTypes
);
292 ModifyListenerHelper::addListenerToAllElements( m_aChartTypes
, m_xModifyEventForwarder
);
296 // ____ XModifyBroadcaster ____
297 void SAL_CALL
BaseCoordinateSystem::addModifyListener( const Reference
< util::XModifyListener
>& aListener
)
298 throw (uno::RuntimeException
)
302 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
303 xBroadcaster
->addModifyListener( aListener
);
305 catch( const uno::Exception
& ex
)
307 ASSERT_EXCEPTION( ex
);
311 void SAL_CALL
BaseCoordinateSystem::removeModifyListener( const Reference
< util::XModifyListener
>& aListener
)
312 throw (uno::RuntimeException
)
316 Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
317 xBroadcaster
->removeModifyListener( aListener
);
319 catch( const uno::Exception
& ex
)
321 ASSERT_EXCEPTION( ex
);
325 // ____ XModifyListener ____
326 void SAL_CALL
BaseCoordinateSystem::modified( const lang::EventObject
& aEvent
)
327 throw (uno::RuntimeException
)
329 m_xModifyEventForwarder
->modified( aEvent
);
332 // ____ XEventListener (base of XModifyListener) ____
333 void SAL_CALL
BaseCoordinateSystem::disposing( const lang::EventObject
& /* Source */ )
334 throw (uno::RuntimeException
)
339 // ____ OPropertySet ____
340 void BaseCoordinateSystem::firePropertyChangeEvent()
345 void BaseCoordinateSystem::fireModifyEvent()
347 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
351 // ____ OPropertySet ____
352 uno::Any
BaseCoordinateSystem::GetDefaultValue( sal_Int32 nHandle
) const
353 throw(beans::UnknownPropertyException
)
355 static tPropertyValueMap aStaticDefaults
;
358 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
359 if( 0 == aStaticDefaults
.size() )
361 // initialize defaults
362 lcl_AddDefaultsToMap( aStaticDefaults
);
365 tPropertyValueMap::const_iterator
aFound(
366 aStaticDefaults
.find( nHandle
));
368 if( aFound
== aStaticDefaults
.end())
371 return (*aFound
).second
;
375 // ____ OPropertySet ____
376 ::cppu::IPropertyArrayHelper
& SAL_CALL
BaseCoordinateSystem::getInfoHelper()
378 static ::cppu::OPropertyArrayHelper
aArrayHelper( lcl_GetPropertySequence(),
379 /* bSorted = */ sal_True
);
385 // ____ XPropertySet ____
386 Reference
< beans::XPropertySetInfo
> SAL_CALL
387 BaseCoordinateSystem::getPropertySetInfo()
388 throw (uno::RuntimeException
)
390 static Reference
< beans::XPropertySetInfo
> xInfo
;
393 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
396 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
404 using impl::BaseCoordinateSystem_Base
;
406 IMPLEMENT_FORWARD_XINTERFACE2( BaseCoordinateSystem
, BaseCoordinateSystem_Base
, ::property::OPropertySet
)
407 IMPLEMENT_FORWARD_XTYPEPROVIDER2( BaseCoordinateSystem
, BaseCoordinateSystem_Base
, ::property::OPropertySet
)