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"
30 #include "ChartType.hxx"
31 #include "PropertyHelper.hxx"
32 #include "CommonFunctors.hxx"
34 #include "CartesianCoordinateSystem.hxx"
35 #include "AxisHelper.hxx"
36 #include "CloneHelper.hxx"
37 #include "AxisIndexDefines.hxx"
38 #include "ContainerHelper.hxx"
39 #include <com/sun/star/chart2/AxisType.hpp>
40 #include <com/sun/star/beans/PropertyAttribute.hpp>
42 using namespace ::com::sun::star
;
44 using ::rtl::OUString
;
45 using ::com::sun::star::beans::Property
;
46 using ::com::sun::star::uno::Sequence
;
47 using ::com::sun::star::uno::Reference
;
48 using ::com::sun::star::uno::Any
;
49 using ::osl::MutexGuard
;
55 const Reference
< uno::XComponentContext
> & xContext
) :
56 ::property::OPropertySet( m_aMutex
),
57 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
58 m_xContext( xContext
),
59 m_bNotifyChanges( true )
62 ChartType::ChartType( const ChartType
& rOther
) :
64 impl::ChartType_Base(),
65 ::property::OPropertySet( rOther
, m_aMutex
),
66 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
67 m_xContext( rOther
.m_xContext
),
68 m_bNotifyChanges( true )
70 CloneHelper::CloneRefVector
< Reference
< chart2::XDataSeries
> >( rOther
.m_aDataSeries
, m_aDataSeries
);
71 ModifyListenerHelper::addListenerToAllElements( m_aDataSeries
, m_xModifyEventForwarder
);
74 ChartType::~ChartType()
76 ModifyListenerHelper::removeListenerFromAllElements( m_aDataSeries
, m_xModifyEventForwarder
);
77 m_aDataSeries
.clear();
80 Reference
< uno::XComponentContext
> ChartType::GetComponentContext() const
85 // ____ XChartType ____
86 Reference
< chart2::XCoordinateSystem
> SAL_CALL
87 ChartType::createCoordinateSystem( ::sal_Int32 DimensionCount
)
88 throw (lang::IllegalArgumentException
,
89 uno::RuntimeException
)
91 Reference
< chart2::XCoordinateSystem
> xResult(
92 new CartesianCoordinateSystem(
93 GetComponentContext(), DimensionCount
, /* bSwapXAndYAxis */ sal_False
));
95 for( sal_Int32 i
=0; i
<DimensionCount
; ++i
)
97 Reference
< chart2::XAxis
> xAxis( xResult
->getAxisByDimension( i
, MAIN_AXIS_INDEX
) );
100 OSL_ENSURE(false,"a created coordinate system should have an axis for each dimension");
104 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
105 aScaleData
.Orientation
= chart2::AxisOrientation_MATHEMATICAL
;
106 aScaleData
.Scaling
= AxisHelper::createLinearScaling();
110 case 0: aScaleData
.AxisType
= chart2::AxisType::CATEGORY
; break;
111 case 2: aScaleData
.AxisType
= chart2::AxisType::SERIES
; break;
112 default: aScaleData
.AxisType
= chart2::AxisType::REALNUMBER
; break;
115 xAxis
->setScaleData( aScaleData
);
121 Sequence
< OUString
> SAL_CALL
ChartType::getSupportedMandatoryRoles()
122 throw (uno::RuntimeException
)
124 static Sequence
< OUString
> aDefaultSeq
;
126 if( aDefaultSeq
.getLength() == 0 )
128 aDefaultSeq
.realloc( 2 );
129 aDefaultSeq
[0] = C2U( "label" );
130 aDefaultSeq
[1] = C2U( "values-y" );
136 Sequence
< OUString
> SAL_CALL
ChartType::getSupportedOptionalRoles()
137 throw (uno::RuntimeException
)
139 static Sequence
< OUString
> aDefaultOptRolesSeq
;
141 // if( aDefaultOptRolesSeq.getLength() == 0 )
143 // aDefaultOptRolesSeq.realloc( 1 );
144 // aDefaultOptRolesSeq[0] = C2U( "error-bars-y" );
147 return aDefaultOptRolesSeq
;
150 OUString SAL_CALL
ChartType::getRoleOfSequenceForSeriesLabel()
151 throw (uno::RuntimeException
)
153 return C2U( "values-y" );
156 void ChartType::impl_addDataSeriesWithoutNotification(
157 const Reference
< chart2::XDataSeries
>& xDataSeries
)
159 if( ::std::find( m_aDataSeries
.begin(), m_aDataSeries
.end(), xDataSeries
)
160 != m_aDataSeries
.end())
161 throw lang::IllegalArgumentException();
163 m_aDataSeries
.push_back( xDataSeries
);
164 ModifyListenerHelper::addListener( xDataSeries
, m_xModifyEventForwarder
);
167 // ____ XDataSeriesContainer ____
168 void SAL_CALL
ChartType::addDataSeries( const Reference
< chart2::XDataSeries
>& xDataSeries
)
169 throw (lang::IllegalArgumentException
,
170 uno::RuntimeException
)
172 impl_addDataSeriesWithoutNotification( xDataSeries
);
176 void SAL_CALL
ChartType::removeDataSeries( const Reference
< chart2::XDataSeries
>& xDataSeries
)
177 throw (container::NoSuchElementException
,
178 uno::RuntimeException
)
180 if( !xDataSeries
.is())
181 throw container::NoSuchElementException();
183 tDataSeriesContainerType::iterator
aIt(
184 ::std::find( m_aDataSeries
.begin(), m_aDataSeries
.end(), xDataSeries
) );
186 if( aIt
== m_aDataSeries
.end())
187 throw container::NoSuchElementException(
188 C2U( "The given series is no element of this charttype" ),
189 static_cast< uno::XWeak
* >( this ));
191 ModifyListenerHelper::removeListener( xDataSeries
, m_xModifyEventForwarder
);
192 m_aDataSeries
.erase( aIt
);
196 Sequence
< Reference
< chart2::XDataSeries
> > SAL_CALL
ChartType::getDataSeries()
197 throw (uno::RuntimeException
)
199 return ContainerHelper::ContainerToSequence( m_aDataSeries
);
202 void SAL_CALL
ChartType::setDataSeries( const Sequence
< Reference
< chart2::XDataSeries
> >& aDataSeries
)
203 throw (lang::IllegalArgumentException
,
204 uno::RuntimeException
)
206 m_bNotifyChanges
= false;
209 Sequence
< Reference
< chart2::XDataSeries
> > aOldSeries( this->getDataSeries() );
210 for( sal_Int32 nN
=0; nN
<aOldSeries
.getLength(); ++nN
)
211 ModifyListenerHelper::removeListener( aOldSeries
[nN
], m_xModifyEventForwarder
);
212 m_aDataSeries
.clear();
214 for( sal_Int32 i
=0; i
<aDataSeries
.getLength(); ++i
)
215 impl_addDataSeriesWithoutNotification( aDataSeries
[i
] );
219 m_bNotifyChanges
= true;
222 m_bNotifyChanges
= true;
226 // ____ OPropertySet ____
227 uno::Any
ChartType::GetDefaultValue( sal_Int32
/* nHandle */ ) const
228 throw(beans::UnknownPropertyException
)
233 // ____ OPropertySet ____
234 ::cppu::IPropertyArrayHelper
& SAL_CALL
ChartType::getInfoHelper()
236 // using assignment for broken gcc 3.3
237 static ::cppu::OPropertyArrayHelper aArrayHelper
= ::cppu::OPropertyArrayHelper(
238 Sequence
< beans::Property
>(), /* bSorted */ sal_True
);
244 // ____ XPropertySet ____
245 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
246 ChartType::getPropertySetInfo()
247 throw (uno::RuntimeException
)
249 static uno::Reference
< beans::XPropertySetInfo
> xInfo
;
252 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
255 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
263 // ____ XModifyBroadcaster ____
264 void SAL_CALL
ChartType::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
265 throw (uno::RuntimeException
)
269 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
270 xBroadcaster
->addModifyListener( aListener
);
272 catch( const uno::Exception
& ex
)
274 ASSERT_EXCEPTION( ex
);
278 void SAL_CALL
ChartType::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
279 throw (uno::RuntimeException
)
283 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
284 xBroadcaster
->removeModifyListener( aListener
);
286 catch( const uno::Exception
& ex
)
288 ASSERT_EXCEPTION( ex
);
292 // ____ XModifyListener ____
293 void SAL_CALL
ChartType::modified( const lang::EventObject
& aEvent
)
294 throw (uno::RuntimeException
)
296 m_xModifyEventForwarder
->modified( aEvent
);
299 // ____ XEventListener (base of XModifyListener) ____
300 void SAL_CALL
ChartType::disposing( const lang::EventObject
& /* Source */ )
301 throw (uno::RuntimeException
)
306 // ____ OPropertySet ____
307 void ChartType::firePropertyChangeEvent()
312 void ChartType::fireModifyEvent()
314 if( m_bNotifyChanges
)
315 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
318 // ================================================================================
320 using impl::ChartType_Base
;
322 IMPLEMENT_FORWARD_XINTERFACE2( ChartType
, ChartType_Base
, ::property::OPropertySet
)
323 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ChartType
, ChartType_Base
, ::property::OPropertySet
)