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