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 "ChartType.hxx"
21 #include "PropertyHelper.hxx"
22 #include "CommonFunctors.hxx"
24 #include "CartesianCoordinateSystem.hxx"
25 #include "AxisHelper.hxx"
26 #include "CloneHelper.hxx"
27 #include "AxisIndexDefines.hxx"
28 #include "ContainerHelper.hxx"
29 #include <vcl/svapp.hxx>
30 #include <com/sun/star/chart2/AxisType.hpp>
31 #include <com/sun/star/beans/PropertyAttribute.hpp>
33 using namespace ::com::sun::star
;
35 using ::com::sun::star::beans::Property
;
36 using ::com::sun::star::uno::Sequence
;
37 using ::com::sun::star::uno::Reference
;
38 using ::com::sun::star::uno::Any
;
39 using ::osl::MutexGuard
;
45 const Reference
< uno::XComponentContext
> & xContext
) :
46 ::property::OPropertySet( m_aMutex
),
47 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
48 m_xContext( xContext
),
49 m_bNotifyChanges( true )
52 ChartType::ChartType( const ChartType
& rOther
) :
54 impl::ChartType_Base(),
55 ::property::OPropertySet( rOther
, m_aMutex
),
56 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
57 m_xContext( rOther
.m_xContext
),
58 m_bNotifyChanges( true )
61 SolarMutexGuard g
; // access to rOther.m_aDataSeries
62 CloneHelper::CloneRefVector
<Reference
<chart2::XDataSeries
> >(
63 rOther
.m_aDataSeries
, m_aDataSeries
);
65 ModifyListenerHelper::addListenerToAllElements( m_aDataSeries
, m_xModifyEventForwarder
);
68 ChartType::~ChartType()
70 ModifyListenerHelper::removeListenerFromAllElements( m_aDataSeries
, m_xModifyEventForwarder
);
71 m_aDataSeries
.clear();
74 // ____ XChartType ____
75 Reference
< chart2::XCoordinateSystem
> SAL_CALL
76 ChartType::createCoordinateSystem( ::sal_Int32 DimensionCount
)
77 throw (lang::IllegalArgumentException
,
78 uno::RuntimeException
, std::exception
)
80 Reference
< chart2::XCoordinateSystem
> xResult(
81 new CartesianCoordinateSystem(
82 GetComponentContext(), DimensionCount
, /* bSwapXAndYAxis */ false ));
84 for( sal_Int32 i
=0; i
<DimensionCount
; ++i
)
86 Reference
< chart2::XAxis
> xAxis( xResult
->getAxisByDimension( i
, MAIN_AXIS_INDEX
) );
89 OSL_FAIL("a created coordinate system should have an axis for each dimension");
93 chart2::ScaleData aScaleData
= xAxis
->getScaleData();
94 aScaleData
.Orientation
= chart2::AxisOrientation_MATHEMATICAL
;
95 aScaleData
.Scaling
= AxisHelper::createLinearScaling();
99 case 0: aScaleData
.AxisType
= chart2::AxisType::CATEGORY
; break;
100 case 2: aScaleData
.AxisType
= chart2::AxisType::SERIES
; break;
101 default: aScaleData
.AxisType
= chart2::AxisType::REALNUMBER
; break;
104 xAxis
->setScaleData( aScaleData
);
110 Sequence
< OUString
> SAL_CALL
ChartType::getSupportedMandatoryRoles()
111 throw (uno::RuntimeException
, std::exception
)
113 Sequence
< OUString
> aDefaultSeq(2);
114 aDefaultSeq
[0] = "label";
115 aDefaultSeq
[1] = "values-y";
119 Sequence
< OUString
> SAL_CALL
ChartType::getSupportedOptionalRoles()
120 throw (uno::RuntimeException
, std::exception
)
122 return Sequence
< OUString
>();
125 Sequence
< OUString
> SAL_CALL
ChartType::getSupportedPropertyRoles()
126 throw (uno::RuntimeException
, std::exception
)
128 return Sequence
< OUString
>();
131 OUString SAL_CALL
ChartType::getRoleOfSequenceForSeriesLabel()
132 throw (uno::RuntimeException
, std::exception
)
134 return OUString("values-y");
137 void ChartType::impl_addDataSeriesWithoutNotification(
138 const Reference
< chart2::XDataSeries
>& xDataSeries
)
140 if( ::std::find( m_aDataSeries
.begin(), m_aDataSeries
.end(), xDataSeries
)
141 != m_aDataSeries
.end())
142 throw lang::IllegalArgumentException();
144 m_aDataSeries
.push_back( xDataSeries
);
145 ModifyListenerHelper::addListener( xDataSeries
, m_xModifyEventForwarder
);
148 // ____ XDataSeriesContainer ____
149 void SAL_CALL
ChartType::addDataSeries( const Reference
< chart2::XDataSeries
>& xDataSeries
)
150 throw (lang::IllegalArgumentException
,
151 uno::RuntimeException
, std::exception
)
155 impl_addDataSeriesWithoutNotification( xDataSeries
);
159 void SAL_CALL
ChartType::removeDataSeries( const Reference
< chart2::XDataSeries
>& xDataSeries
)
160 throw (container::NoSuchElementException
,
161 uno::RuntimeException
, std::exception
)
163 if( !xDataSeries
.is())
164 throw container::NoSuchElementException();
168 tDataSeriesContainerType::iterator
aIt(
169 ::std::find( m_aDataSeries
.begin(), m_aDataSeries
.end(), xDataSeries
) );
171 if( aIt
== m_aDataSeries
.end())
172 throw container::NoSuchElementException(
173 "The given series is no element of this charttype",
174 static_cast< uno::XWeak
* >( this ));
176 ModifyListenerHelper::removeListener( xDataSeries
, m_xModifyEventForwarder
);
177 m_aDataSeries
.erase( aIt
);
181 Sequence
< Reference
< chart2::XDataSeries
> > SAL_CALL
ChartType::getDataSeries()
182 throw (uno::RuntimeException
, std::exception
)
186 return ContainerHelper::ContainerToSequence( m_aDataSeries
);
189 void SAL_CALL
ChartType::setDataSeries( const Sequence
< Reference
< chart2::XDataSeries
> >& aDataSeries
)
190 throw (lang::IllegalArgumentException
,
191 uno::RuntimeException
, std::exception
)
195 m_bNotifyChanges
= false;
198 Sequence
< Reference
< chart2::XDataSeries
> > aOldSeries( this->getDataSeries() );
199 for( sal_Int32 nN
=0; nN
<aOldSeries
.getLength(); ++nN
)
200 ModifyListenerHelper::removeListener( aOldSeries
[nN
], m_xModifyEventForwarder
);
201 m_aDataSeries
.clear();
203 for( sal_Int32 i
=0; i
<aDataSeries
.getLength(); ++i
)
204 impl_addDataSeriesWithoutNotification( aDataSeries
[i
] );
208 m_bNotifyChanges
= true;
211 m_bNotifyChanges
= true;
215 // ____ OPropertySet ____
216 uno::Any
ChartType::GetDefaultValue( sal_Int32
/* nHandle */ ) const
217 throw(beans::UnknownPropertyException
)
225 struct StaticChartTypeInfoHelper_Initializer
227 ::cppu::OPropertyArrayHelper
* operator()()
229 // using assignment for broken gcc 3.3
230 static ::cppu::OPropertyArrayHelper aPropHelper
= ::cppu::OPropertyArrayHelper(
231 Sequence
< beans::Property
>() );
236 struct StaticChartTypeInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticChartTypeInfoHelper_Initializer
>
240 struct StaticChartTypeInfo_Initializer
242 uno::Reference
< beans::XPropertySetInfo
>* operator()()
244 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
245 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticChartTypeInfoHelper::get() ) );
246 return &xPropertySetInfo
;
250 struct StaticChartTypeInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticChartTypeInfo_Initializer
>
256 // ____ OPropertySet ____
257 ::cppu::IPropertyArrayHelper
& SAL_CALL
ChartType::getInfoHelper()
259 return *StaticChartTypeInfoHelper::get();
262 // ____ XPropertySet ____
263 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
ChartType::getPropertySetInfo()
264 throw (uno::RuntimeException
, std::exception
)
266 return *StaticChartTypeInfo::get();
269 // ____ XModifyBroadcaster ____
270 void SAL_CALL
ChartType::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
271 throw (uno::RuntimeException
, std::exception
)
275 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
276 xBroadcaster
->addModifyListener( aListener
);
278 catch( const uno::Exception
& ex
)
280 ASSERT_EXCEPTION( ex
);
284 void SAL_CALL
ChartType::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
285 throw (uno::RuntimeException
, std::exception
)
289 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
290 xBroadcaster
->removeModifyListener( aListener
);
292 catch( const uno::Exception
& ex
)
294 ASSERT_EXCEPTION( ex
);
298 // ____ XModifyListener ____
299 void SAL_CALL
ChartType::modified( const lang::EventObject
& aEvent
)
300 throw (uno::RuntimeException
, std::exception
)
302 m_xModifyEventForwarder
->modified( aEvent
);
305 // ____ XEventListener (base of XModifyListener) ____
306 void SAL_CALL
ChartType::disposing( const lang::EventObject
& /* Source */ )
307 throw (uno::RuntimeException
, std::exception
)
312 // ____ OPropertySet ____
313 void ChartType::firePropertyChangeEvent()
318 void ChartType::fireModifyEvent()
324 bNotifyChanges
= m_bNotifyChanges
;
328 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
331 using impl::ChartType_Base
;
333 IMPLEMENT_FORWARD_XINTERFACE2( ChartType
, ChartType_Base
, ::property::OPropertySet
)
334 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ChartType
, ChartType_Base
, ::property::OPropertySet
)
338 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */