1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ChartType.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "ChartType.hxx"
34 #include "PropertyHelper.hxx"
35 #include "CommonFunctors.hxx"
37 #include "CartesianCoordinateSystem.hxx"
38 #include "AxisHelper.hxx"
39 #include "CloneHelper.hxx"
40 #include "AxisIndexDefines.hxx"
41 #include "ContainerHelper.hxx"
42 #include <com/sun/star/chart2/AxisType.hpp>
43 #include <com/sun/star/beans/PropertyAttribute.hpp>
45 using namespace ::com::sun::star
;
47 using ::rtl::OUString
;
48 using ::com::sun::star::beans::Property
;
49 using ::com::sun::star::uno::Sequence
;
50 using ::com::sun::star::uno::Reference
;
51 using ::com::sun::star::uno::Any
;
52 using ::osl::MutexGuard
;
58 const Reference
< uno::XComponentContext
> & xContext
) :
59 ::property::OPropertySet( m_aMutex
),
60 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
61 m_xContext( xContext
),
62 m_bNotifyChanges( true )
65 ChartType::ChartType( const ChartType
& rOther
) :
67 impl::ChartType_Base(),
68 ::property::OPropertySet( rOther
, m_aMutex
),
69 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
70 m_xContext( rOther
.m_xContext
),
71 m_bNotifyChanges( true )
73 CloneHelper::CloneRefVector
< Reference
< chart2::XDataSeries
> >( rOther
.m_aDataSeries
, m_aDataSeries
);
74 ModifyListenerHelper::addListenerToAllElements( m_aDataSeries
, m_xModifyEventForwarder
);
77 ChartType::~ChartType()
79 ModifyListenerHelper::removeListenerFromAllElements( m_aDataSeries
, m_xModifyEventForwarder
);
80 m_aDataSeries
.clear();
83 Reference
< uno::XComponentContext
> ChartType::GetComponentContext() const
88 // ____ XChartType ____
89 Reference
< chart2::XCoordinateSystem
> SAL_CALL
90 ChartType::createCoordinateSystem( ::sal_Int32 DimensionCount
)
91 throw (lang::IllegalArgumentException
,
92 uno::RuntimeException
)
94 Reference
< chart2::XCoordinateSystem
> xResult(
95 new CartesianCoordinateSystem(
96 GetComponentContext(), DimensionCount
, /* bSwapXAndYAxis */ sal_False
));
98 for( sal_Int32 i
=0; i
<DimensionCount
; ++i
)
100 Reference
< chart2::XAxis
> xAxis( xResult
->getAxisByDimension( i
, MAIN_AXIS_INDEX
) );
103 OSL_ENSURE(false,"a created coordinate system should have an axis for each dimension");
107 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
108 aScaleData
.Orientation
= chart2::AxisOrientation_MATHEMATICAL
;
109 aScaleData
.Scaling
= AxisHelper::createLinearScaling();
113 case 0: aScaleData
.AxisType
= chart2::AxisType::CATEGORY
; break;
114 case 2: aScaleData
.AxisType
= chart2::AxisType::SERIES
; break;
115 default: aScaleData
.AxisType
= chart2::AxisType::REALNUMBER
; break;
118 xAxis
->setScaleData( aScaleData
);
124 Sequence
< OUString
> SAL_CALL
ChartType::getSupportedMandatoryRoles()
125 throw (uno::RuntimeException
)
127 static Sequence
< OUString
> aDefaultSeq
;
129 if( aDefaultSeq
.getLength() == 0 )
131 aDefaultSeq
.realloc( 2 );
132 aDefaultSeq
[0] = C2U( "label" );
133 aDefaultSeq
[1] = C2U( "values-y" );
139 Sequence
< OUString
> SAL_CALL
ChartType::getSupportedOptionalRoles()
140 throw (uno::RuntimeException
)
142 static Sequence
< OUString
> aDefaultOptRolesSeq
;
144 // if( aDefaultOptRolesSeq.getLength() == 0 )
146 // aDefaultOptRolesSeq.realloc( 1 );
147 // aDefaultOptRolesSeq[0] = C2U( "error-bars-y" );
150 return aDefaultOptRolesSeq
;
153 OUString SAL_CALL
ChartType::getRoleOfSequenceForSeriesLabel()
154 throw (uno::RuntimeException
)
156 return C2U( "values-y" );
159 void ChartType::impl_addDataSeriesWithoutNotification(
160 const Reference
< chart2::XDataSeries
>& xDataSeries
)
162 if( ::std::find( m_aDataSeries
.begin(), m_aDataSeries
.end(), xDataSeries
)
163 != m_aDataSeries
.end())
164 throw lang::IllegalArgumentException();
166 m_aDataSeries
.push_back( xDataSeries
);
167 ModifyListenerHelper::addListener( xDataSeries
, m_xModifyEventForwarder
);
170 // ____ XDataSeriesContainer ____
171 void SAL_CALL
ChartType::addDataSeries( const Reference
< chart2::XDataSeries
>& xDataSeries
)
172 throw (lang::IllegalArgumentException
,
173 uno::RuntimeException
)
175 impl_addDataSeriesWithoutNotification( xDataSeries
);
179 void SAL_CALL
ChartType::removeDataSeries( const Reference
< chart2::XDataSeries
>& xDataSeries
)
180 throw (container::NoSuchElementException
,
181 uno::RuntimeException
)
183 if( !xDataSeries
.is())
184 throw container::NoSuchElementException();
186 tDataSeriesContainerType::iterator
aIt(
187 ::std::find( m_aDataSeries
.begin(), m_aDataSeries
.end(), xDataSeries
) );
189 if( aIt
== m_aDataSeries
.end())
190 throw container::NoSuchElementException(
191 C2U( "The given series is no element of this charttype" ),
192 static_cast< uno::XWeak
* >( this ));
194 ModifyListenerHelper::removeListener( xDataSeries
, m_xModifyEventForwarder
);
195 m_aDataSeries
.erase( aIt
);
199 Sequence
< Reference
< chart2::XDataSeries
> > SAL_CALL
ChartType::getDataSeries()
200 throw (uno::RuntimeException
)
202 return ContainerHelper::ContainerToSequence( m_aDataSeries
);
205 void SAL_CALL
ChartType::setDataSeries( const Sequence
< Reference
< chart2::XDataSeries
> >& aDataSeries
)
206 throw (lang::IllegalArgumentException
,
207 uno::RuntimeException
)
209 m_bNotifyChanges
= false;
212 Sequence
< Reference
< chart2::XDataSeries
> > aOldSeries( this->getDataSeries() );
213 for( sal_Int32 nN
=0; nN
<aOldSeries
.getLength(); ++nN
)
214 ModifyListenerHelper::removeListener( aOldSeries
[nN
], m_xModifyEventForwarder
);
215 m_aDataSeries
.clear();
217 for( sal_Int32 i
=0; i
<aDataSeries
.getLength(); ++i
)
218 impl_addDataSeriesWithoutNotification( aDataSeries
[i
] );
222 m_bNotifyChanges
= true;
225 m_bNotifyChanges
= true;
229 // ____ OPropertySet ____
230 uno::Any
ChartType::GetDefaultValue( sal_Int32
/* nHandle */ ) const
231 throw(beans::UnknownPropertyException
)
236 // ____ OPropertySet ____
237 ::cppu::IPropertyArrayHelper
& SAL_CALL
ChartType::getInfoHelper()
239 // using assignment for broken gcc 3.3
240 static ::cppu::OPropertyArrayHelper aArrayHelper
= ::cppu::OPropertyArrayHelper(
241 Sequence
< beans::Property
>(), /* bSorted */ sal_True
);
247 // ____ XPropertySet ____
248 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
249 ChartType::getPropertySetInfo()
250 throw (uno::RuntimeException
)
252 static uno::Reference
< beans::XPropertySetInfo
> xInfo
;
255 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
258 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
266 // ____ XModifyBroadcaster ____
267 void SAL_CALL
ChartType::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
268 throw (uno::RuntimeException
)
272 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
273 xBroadcaster
->addModifyListener( aListener
);
275 catch( const uno::Exception
& ex
)
277 ASSERT_EXCEPTION( ex
);
281 void SAL_CALL
ChartType::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
282 throw (uno::RuntimeException
)
286 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
287 xBroadcaster
->removeModifyListener( aListener
);
289 catch( const uno::Exception
& ex
)
291 ASSERT_EXCEPTION( ex
);
295 // ____ XModifyListener ____
296 void SAL_CALL
ChartType::modified( const lang::EventObject
& aEvent
)
297 throw (uno::RuntimeException
)
299 m_xModifyEventForwarder
->modified( aEvent
);
302 // ____ XEventListener (base of XModifyListener) ____
303 void SAL_CALL
ChartType::disposing( const lang::EventObject
& /* Source */ )
304 throw (uno::RuntimeException
)
309 // ____ OPropertySet ____
310 void ChartType::firePropertyChangeEvent()
315 void ChartType::fireModifyEvent()
317 if( m_bNotifyChanges
)
318 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
321 // ================================================================================
323 using impl::ChartType_Base
;
325 IMPLEMENT_FORWARD_XINTERFACE2( ChartType
, ChartType_Base
, ::property::OPropertySet
)
326 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ChartType
, ChartType_Base
, ::property::OPropertySet
)