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