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 : #include "ChartType.hxx"
21 : #include "PropertyHelper.hxx"
22 : #include "CommonFunctors.hxx"
23 : #include "macros.hxx"
24 : #include "CartesianCoordinateSystem.hxx"
25 : #include "AxisHelper.hxx"
26 : #include "CloneHelper.hxx"
27 : #include "AxisIndexDefines.hxx"
28 : #include "ContainerHelper.hxx"
29 : #include <com/sun/star/chart2/AxisType.hpp>
30 : #include <com/sun/star/beans/PropertyAttribute.hpp>
31 :
32 : using namespace ::com::sun::star;
33 :
34 : using ::rtl::OUString;
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;
40 :
41 : namespace chart
42 : {
43 :
44 327 : ChartType::ChartType(
45 : const Reference< uno::XComponentContext > & xContext ) :
46 : ::property::OPropertySet( m_aMutex ),
47 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
48 : m_xContext( xContext ),
49 327 : m_bNotifyChanges( true )
50 327 : {}
51 :
52 0 : ChartType::ChartType( const ChartType & rOther ) :
53 : MutexContainer(),
54 : impl::ChartType_Base(),
55 : ::property::OPropertySet( rOther, m_aMutex ),
56 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()),
57 : m_xContext( rOther.m_xContext ),
58 0 : m_bNotifyChanges( true )
59 : {
60 0 : CloneHelper::CloneRefVector< Reference< chart2::XDataSeries > >( rOther.m_aDataSeries, m_aDataSeries );
61 0 : ModifyListenerHelper::addListenerToAllElements( m_aDataSeries, m_xModifyEventForwarder );
62 0 : }
63 :
64 654 : ChartType::~ChartType()
65 : {
66 327 : ModifyListenerHelper::removeListenerFromAllElements( m_aDataSeries, m_xModifyEventForwarder );
67 327 : m_aDataSeries.clear();
68 327 : }
69 :
70 41 : Reference< uno::XComponentContext > ChartType::GetComponentContext() const
71 : {
72 41 : return m_xContext;
73 : }
74 :
75 : // ____ XChartType ____
76 : Reference< chart2::XCoordinateSystem > SAL_CALL
77 41 : ChartType::createCoordinateSystem( ::sal_Int32 DimensionCount )
78 : throw (lang::IllegalArgumentException,
79 : uno::RuntimeException)
80 : {
81 : Reference< chart2::XCoordinateSystem > xResult(
82 : new CartesianCoordinateSystem(
83 41 : GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ sal_False ));
84 :
85 123 : for( sal_Int32 i=0; i<DimensionCount; ++i )
86 : {
87 82 : Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) );
88 82 : if( !xAxis.is() )
89 : {
90 : OSL_FAIL("a created coordinate system should have an axis for each dimension");
91 0 : continue;
92 : }
93 :
94 82 : chart2::ScaleData aScaleData = xAxis->getScaleData();
95 82 : aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
96 82 : aScaleData.Scaling = AxisHelper::createLinearScaling();
97 :
98 82 : switch( i )
99 : {
100 41 : case 0: aScaleData.AxisType = chart2::AxisType::CATEGORY; break;
101 0 : case 2: aScaleData.AxisType = chart2::AxisType::SERIES; break;
102 41 : default: aScaleData.AxisType = chart2::AxisType::REALNUMBER; break;
103 : }
104 :
105 82 : xAxis->setScaleData( aScaleData );
106 82 : }
107 :
108 41 : return xResult;
109 : }
110 :
111 0 : Sequence< OUString > SAL_CALL ChartType::getSupportedMandatoryRoles()
112 : throw (uno::RuntimeException)
113 : {
114 0 : Sequence< OUString > aDefaultSeq(2);
115 0 : aDefaultSeq[0] = C2U( "label" );
116 0 : aDefaultSeq[1] = C2U( "values-y" );
117 0 : return aDefaultSeq;
118 : }
119 :
120 0 : Sequence< OUString > SAL_CALL ChartType::getSupportedOptionalRoles()
121 : throw (uno::RuntimeException)
122 : {
123 0 : return Sequence< OUString >();
124 : }
125 :
126 123 : OUString SAL_CALL ChartType::getRoleOfSequenceForSeriesLabel()
127 : throw (uno::RuntimeException)
128 : {
129 123 : return C2U( "values-y" );
130 : }
131 :
132 163 : void ChartType::impl_addDataSeriesWithoutNotification(
133 : const Reference< chart2::XDataSeries >& xDataSeries )
134 : {
135 489 : if( ::std::find( m_aDataSeries.begin(), m_aDataSeries.end(), xDataSeries )
136 489 : != m_aDataSeries.end())
137 0 : throw lang::IllegalArgumentException();
138 :
139 163 : m_aDataSeries.push_back( xDataSeries );
140 163 : ModifyListenerHelper::addListener( xDataSeries, m_xModifyEventForwarder );
141 163 : }
142 :
143 : // ____ XDataSeriesContainer ____
144 40 : void SAL_CALL ChartType::addDataSeries( const Reference< chart2::XDataSeries >& xDataSeries )
145 : throw (lang::IllegalArgumentException,
146 : uno::RuntimeException)
147 : {
148 40 : impl_addDataSeriesWithoutNotification( xDataSeries );
149 40 : fireModifyEvent();
150 40 : }
151 :
152 0 : void SAL_CALL ChartType::removeDataSeries( const Reference< chart2::XDataSeries >& xDataSeries )
153 : throw (container::NoSuchElementException,
154 : uno::RuntimeException)
155 : {
156 0 : if( !xDataSeries.is())
157 0 : throw container::NoSuchElementException();
158 :
159 : tDataSeriesContainerType::iterator aIt(
160 0 : ::std::find( m_aDataSeries.begin(), m_aDataSeries.end(), xDataSeries ) );
161 :
162 0 : if( aIt == m_aDataSeries.end())
163 : throw container::NoSuchElementException(
164 : C2U( "The given series is no element of this charttype" ),
165 0 : static_cast< uno::XWeak * >( this ));
166 :
167 0 : ModifyListenerHelper::removeListener( xDataSeries, m_xModifyEventForwarder );
168 0 : m_aDataSeries.erase( aIt );
169 0 : fireModifyEvent();
170 0 : }
171 :
172 450 : Sequence< Reference< chart2::XDataSeries > > SAL_CALL ChartType::getDataSeries()
173 : throw (uno::RuntimeException)
174 : {
175 450 : return ContainerHelper::ContainerToSequence( m_aDataSeries );
176 : }
177 :
178 41 : void SAL_CALL ChartType::setDataSeries( const Sequence< Reference< chart2::XDataSeries > >& aDataSeries )
179 : throw (lang::IllegalArgumentException,
180 : uno::RuntimeException)
181 : {
182 41 : m_bNotifyChanges = false;
183 : try
184 : {
185 41 : Sequence< Reference< chart2::XDataSeries > > aOldSeries( this->getDataSeries() );
186 41 : for( sal_Int32 nN=0; nN<aOldSeries.getLength(); ++nN )
187 0 : ModifyListenerHelper::removeListener( aOldSeries[nN], m_xModifyEventForwarder );
188 41 : m_aDataSeries.clear();
189 :
190 164 : for( sal_Int32 i=0; i<aDataSeries.getLength(); ++i )
191 164 : impl_addDataSeriesWithoutNotification( aDataSeries[i] );
192 : }
193 0 : catch( ... )
194 : {
195 0 : m_bNotifyChanges = true;
196 0 : throw;
197 : }
198 41 : m_bNotifyChanges = true;
199 41 : fireModifyEvent();
200 41 : }
201 :
202 : // ____ OPropertySet ____
203 0 : uno::Any ChartType::GetDefaultValue( sal_Int32 /* nHandle */ ) const
204 : throw(beans::UnknownPropertyException)
205 : {
206 0 : return uno::Any();
207 : }
208 :
209 : namespace
210 : {
211 :
212 : struct StaticChartTypeInfoHelper_Initializer
213 : {
214 0 : ::cppu::OPropertyArrayHelper* operator()()
215 : {
216 : // using assignment for broken gcc 3.3
217 : static ::cppu::OPropertyArrayHelper aPropHelper = ::cppu::OPropertyArrayHelper(
218 0 : Sequence< beans::Property >() );
219 0 : return &aPropHelper;
220 : }
221 : };
222 :
223 : struct StaticChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticChartTypeInfoHelper_Initializer >
224 : {
225 : };
226 :
227 : struct StaticChartTypeInfo_Initializer
228 : {
229 0 : uno::Reference< beans::XPropertySetInfo >* operator()()
230 : {
231 : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
232 0 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticChartTypeInfoHelper::get() ) );
233 0 : return &xPropertySetInfo;
234 : }
235 : };
236 :
237 : struct StaticChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticChartTypeInfo_Initializer >
238 : {
239 : };
240 :
241 : }
242 :
243 : // ____ OPropertySet ____
244 0 : ::cppu::IPropertyArrayHelper & SAL_CALL ChartType::getInfoHelper()
245 : {
246 0 : return *StaticChartTypeInfoHelper::get();
247 : }
248 :
249 : // ____ XPropertySet ____
250 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL ChartType::getPropertySetInfo()
251 : throw (uno::RuntimeException)
252 : {
253 0 : return *StaticChartTypeInfo::get();
254 : }
255 :
256 : // ____ XModifyBroadcaster ____
257 81 : void SAL_CALL ChartType::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
258 : throw (uno::RuntimeException)
259 : {
260 : try
261 : {
262 81 : uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
263 81 : xBroadcaster->addModifyListener( aListener );
264 : }
265 0 : catch( const uno::Exception & ex )
266 : {
267 : ASSERT_EXCEPTION( ex );
268 : }
269 81 : }
270 :
271 81 : void SAL_CALL ChartType::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
272 : throw (uno::RuntimeException)
273 : {
274 : try
275 : {
276 81 : uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
277 81 : xBroadcaster->removeModifyListener( aListener );
278 : }
279 0 : catch( const uno::Exception & ex )
280 : {
281 : ASSERT_EXCEPTION( ex );
282 : }
283 81 : }
284 :
285 : // ____ XModifyListener ____
286 0 : void SAL_CALL ChartType::modified( const lang::EventObject& aEvent )
287 : throw (uno::RuntimeException)
288 : {
289 0 : m_xModifyEventForwarder->modified( aEvent );
290 0 : }
291 :
292 : // ____ XEventListener (base of XModifyListener) ____
293 0 : void SAL_CALL ChartType::disposing( const lang::EventObject& /* Source */ )
294 : throw (uno::RuntimeException)
295 : {
296 : // nothing
297 0 : }
298 :
299 : // ____ OPropertySet ____
300 41 : void ChartType::firePropertyChangeEvent()
301 : {
302 41 : fireModifyEvent();
303 41 : }
304 :
305 122 : void ChartType::fireModifyEvent()
306 : {
307 122 : if( m_bNotifyChanges )
308 122 : m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
309 122 : }
310 :
311 : // ================================================================================
312 :
313 : using impl::ChartType_Base;
314 :
315 10193 : IMPLEMENT_FORWARD_XINTERFACE2( ChartType, ChartType_Base, ::property::OPropertySet )
316 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( ChartType, ChartType_Base, ::property::OPropertySet )
317 :
318 : } // namespace chart
319 :
320 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|