Branch data 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 "StockChartTypeTemplate.hxx"
21 : : #include "macros.hxx"
22 : : #include "DataSeriesHelper.hxx"
23 : : #include "StockDataInterpreter.hxx"
24 : : #include "CartesianCoordinateSystem.hxx"
25 : : #include "AxisHelper.hxx"
26 : : #include "DiagramHelper.hxx"
27 : : #include "servicenames_charttypes.hxx"
28 : : #include "servicenames_coosystems.hxx"
29 : : #include "ContainerHelper.hxx"
30 : : #include "AxisIndexDefines.hxx"
31 : : #include <com/sun/star/chart2/AxisType.hpp>
32 : : #include <com/sun/star/chart2/data/XDataSource.hpp>
33 : : #include <com/sun/star/chart2/XChartTypeContainer.hpp>
34 : : #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
35 : : #include "PropertyHelper.hxx"
36 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
37 : : #include <com/sun/star/drawing/LineStyle.hpp>
38 : :
39 : : #include <vector>
40 : : #include <algorithm>
41 : :
42 : : using namespace ::com::sun::star;
43 : : using namespace ::com::sun::star::chart2;
44 : :
45 : : using ::com::sun::star::uno::Reference;
46 : : using ::com::sun::star::uno::Sequence;
47 : : using ::rtl::OUString;
48 : : using ::com::sun::star::beans::Property;
49 : : using ::com::sun::star::uno::Any;
50 : : using ::osl::MutexGuard;
51 : :
52 : : // ----------------------------------------
53 : : namespace
54 : : {
55 : :
56 : 16 : static const OUString lcl_aServiceName(
57 : : RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.StockChartTypeTemplate" ));
58 : :
59 : : enum
60 : : {
61 : : PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME,
62 : : PROP_STOCKCHARTTYPE_TEMPLATE_OPEN,
63 : : PROP_STOCKCHARTTYPE_TEMPLATE_LOW_HIGH,
64 : : PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE
65 : : };
66 : :
67 : 2 : void lcl_AddPropertiesToVector(
68 : : ::std::vector< Property > & rOutProperties )
69 : : {
70 : : rOutProperties.push_back(
71 : : Property( C2U( "Volume" ),
72 : : PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME,
73 [ + - ]: 2 : ::getBooleanCppuType(),
74 : : beans::PropertyAttribute::BOUND
75 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
76 : : rOutProperties.push_back(
77 : : Property( C2U( "Open" ),
78 : : PROP_STOCKCHARTTYPE_TEMPLATE_OPEN,
79 [ + - ]: 2 : ::getBooleanCppuType(),
80 : : beans::PropertyAttribute::BOUND
81 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
82 : : rOutProperties.push_back(
83 : : Property( C2U( "LowHigh" ),
84 : : PROP_STOCKCHARTTYPE_TEMPLATE_LOW_HIGH,
85 [ + - ]: 2 : ::getBooleanCppuType(),
86 : : beans::PropertyAttribute::BOUND
87 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
88 : : rOutProperties.push_back(
89 : : Property( C2U( "Japanese" ),
90 : : PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE,
91 [ + - ]: 2 : ::getBooleanCppuType(),
92 : : beans::PropertyAttribute::BOUND
93 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
94 : 2 : }
95 : :
96 : : struct StaticStockChartTypeTemplateDefaults_Initializer
97 : : {
98 : 2 : ::chart::tPropertyValueMap* operator()()
99 : : {
100 [ + - ][ + - ]: 2 : static ::chart::tPropertyValueMap aStaticDefaults;
[ + - ][ # # ]
101 : 2 : lcl_AddDefaultsToMap( aStaticDefaults );
102 : 2 : return &aStaticDefaults;
103 : : }
104 : : private:
105 : 2 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
106 : : {
107 [ + - ]: 2 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME, false );
108 [ + - ]: 2 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_STOCKCHARTTYPE_TEMPLATE_OPEN, false );
109 [ + - ]: 2 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_STOCKCHARTTYPE_TEMPLATE_LOW_HIGH, true );
110 [ + - ]: 2 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE, false );
111 : 2 : }
112 : : };
113 : :
114 : : struct StaticStockChartTypeTemplateDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticStockChartTypeTemplateDefaults_Initializer >
115 : : {
116 : : };
117 : :
118 : : struct StaticStockChartTypeTemplateInfoHelper_Initializer
119 : : {
120 : 2 : ::cppu::OPropertyArrayHelper* operator()()
121 : : {
122 [ + - ][ + - ]: 2 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
[ + - ][ + - ]
[ + - ][ # # ]
123 : 2 : return &aPropHelper;
124 : : }
125 : :
126 : : private:
127 : 2 : Sequence< Property > lcl_GetPropertySequence()
128 : : {
129 [ + - ]: 2 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
130 [ + - ]: 2 : lcl_AddPropertiesToVector( aProperties );
131 : :
132 : : ::std::sort( aProperties.begin(), aProperties.end(),
133 [ + - ]: 2 : ::chart::PropertyNameLess() );
134 : :
135 [ + - ]: 2 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
136 : : }
137 : : };
138 : :
139 : : struct StaticStockChartTypeTemplateInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticStockChartTypeTemplateInfoHelper_Initializer >
140 : : {
141 : : };
142 : :
143 : : struct StaticStockChartTypeTemplateInfo_Initializer
144 : : {
145 : 0 : uno::Reference< beans::XPropertySetInfo >* operator()()
146 : : {
147 : : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
148 [ # # ][ # # ]: 0 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticStockChartTypeTemplateInfoHelper::get() ) );
[ # # ][ # # ]
[ # # ]
149 : 0 : return &xPropertySetInfo;
150 : : }
151 : : };
152 : :
153 : : struct StaticStockChartTypeTemplateInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticStockChartTypeTemplateInfo_Initializer >
154 : : {
155 : : };
156 : :
157 : : } // anonymous namespace
158 : : // ----------------------------------------
159 : :
160 : : namespace chart
161 : : {
162 : :
163 : 8 : StockChartTypeTemplate::StockChartTypeTemplate(
164 : : uno::Reference<
165 : : uno::XComponentContext > const & xContext,
166 : : const ::rtl::OUString & rServiceName,
167 : : StockVariant eVariant,
168 : : bool bJapaneseStyle ) :
169 : : ChartTypeTemplate( xContext, rServiceName ),
170 : : ::property::OPropertySet( m_aMutex ),
171 [ + - ][ + - ]: 8 : m_eStockVariant( eVariant )
172 : : {
173 : : setFastPropertyValue_NoBroadcast(
174 : : PROP_STOCKCHARTTYPE_TEMPLATE_OPEN,
175 : : uno::makeAny( ( eVariant == OPEN_LOW_HI_CLOSE ||
176 [ + - ][ - + ]: 8 : eVariant == VOL_OPEN_LOW_HI_CLOSE )));
[ + - ][ + - ]
177 : : setFastPropertyValue_NoBroadcast(
178 : : PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME,
179 : : uno::makeAny( ( eVariant == VOL_LOW_HI_CLOSE ||
180 [ - + ][ + - ]: 8 : eVariant == VOL_OPEN_LOW_HI_CLOSE )));
[ + - ][ + - ]
181 : : setFastPropertyValue_NoBroadcast(
182 : : PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE,
183 [ + - ][ + - ]: 8 : uno::makeAny( bJapaneseStyle ));
184 : 8 : }
185 : :
186 [ + - ][ + - ]: 8 : StockChartTypeTemplate::~StockChartTypeTemplate()
187 [ - + ]: 16 : {}
188 : : // ____ OPropertySet ____
189 : 100 : uno::Any StockChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle ) const
190 : : throw(beans::UnknownPropertyException)
191 : : {
192 [ + - ]: 100 : const tPropertyValueMap& rStaticDefaults = *StaticStockChartTypeTemplateDefaults::get();
193 [ + - ]: 100 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
194 [ - + ]: 100 : if( aFound == rStaticDefaults.end() )
195 : 0 : return uno::Any();
196 : 100 : return (*aFound).second;
197 : : }
198 : :
199 : 76 : ::cppu::IPropertyArrayHelper & SAL_CALL StockChartTypeTemplate::getInfoHelper()
200 : : {
201 : 76 : return *StaticStockChartTypeTemplateInfoHelper::get();
202 : : }
203 : :
204 : : // ____ XPropertySet ____
205 : 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL StockChartTypeTemplate::getPropertySetInfo()
206 : : throw (uno::RuntimeException)
207 : : {
208 : 0 : return *StaticStockChartTypeTemplateInfo::get();
209 : : }
210 : :
211 : 8 : sal_Int32 StockChartTypeTemplate::getAxisCountByDimension( sal_Int32 nDimension )
212 : : {
213 : : // one x-axis
214 [ + + ]: 8 : if( nDimension <= 0 )
215 : 4 : return 1;
216 : : // no further axes
217 [ - + ]: 4 : if( nDimension >= 2 )
218 : 0 : return 0;
219 : :
220 : : // one or two y-axes depending on volume
221 : : OSL_ASSERT( nDimension == 1 );
222 : 4 : bool bHasVolume = false;
223 [ + - ]: 4 : getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME ) >>= bHasVolume;
224 [ - + ]: 8 : return bHasVolume ? 2 : 1;
225 : : }
226 : :
227 : 20 : void SAL_CALL StockChartTypeTemplate::applyStyle(
228 : : const Reference< chart2::XDataSeries >& xSeries,
229 : : ::sal_Int32 nChartTypeIndex,
230 : : ::sal_Int32 nSeriesIndex,
231 : : ::sal_Int32 nSeriesCount )
232 : : throw (uno::RuntimeException)
233 : : {
234 : 20 : ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount );
235 : : try
236 : : {
237 : 20 : sal_Int32 nNewAxisIndex = 0;
238 : :
239 : 20 : bool bHasVolume = false;
240 [ + - ]: 20 : getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME ) >>= bHasVolume;
241 [ - + ]: 20 : if( bHasVolume )
242 : : {
243 [ # # ]: 0 : if( nChartTypeIndex != 0 )
244 : 0 : nNewAxisIndex = 1;
245 : : }
246 : :
247 [ + - ]: 20 : Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY );
248 [ + - ]: 20 : if( xProp.is() )
249 [ + - ][ + - ]: 20 : xProp->setPropertyValue( C2U("AttachedAxisIndex"), uno::makeAny( nNewAxisIndex ) );
[ + - ][ + - ]
250 : :
251 [ - + ][ # # ]: 20 : if( bHasVolume && nChartTypeIndex==0 )
252 : : {
253 : : //switch lines off for volume bars
254 [ # # ][ # # ]: 0 : DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) );
[ # # ]
255 : : }
256 : : else
257 : : {
258 : : //ensure that lines are on
259 [ + - ]: 20 : if( xProp.is() )
260 : : {
261 : 20 : drawing::LineStyle eStyle = drawing::LineStyle_NONE;
262 [ + - ][ + - ]: 20 : xProp->getPropertyValue( C2U("LineStyle") ) >>= eStyle;
[ + - ][ + - ]
263 [ - + ]: 20 : if( eStyle == drawing::LineStyle_NONE )
264 [ # # ][ # # ]: 20 : xProp->setPropertyValue( C2U("LineStyle"), uno::makeAny( drawing::LineStyle_SOLID ));
[ # # ][ # # ]
265 : : }
266 [ # # ]: 20 : }
267 : :
268 : : }
269 : 0 : catch( const uno::Exception & ex )
270 : : {
271 : : ASSERT_EXCEPTION( ex );
272 : : }
273 : 20 : }
274 : :
275 : 4 : void SAL_CALL StockChartTypeTemplate::resetStyles(
276 : : const Reference< chart2::XDiagram >& xDiagram )
277 : : throw (uno::RuntimeException)
278 : : {
279 : 4 : ChartTypeTemplate::resetStyles( xDiagram );
280 [ - + ]: 4 : if( getDimension() == 3 )
281 : : {
282 : : ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec(
283 [ # # ]: 0 : DiagramHelper::getDataSeriesFromDiagram( xDiagram ));
284 [ # # ][ # # ]: 0 : for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin());
285 : 0 : aIt != aSeriesVec.end(); ++aIt )
286 : : {
287 [ # # ]: 0 : Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY );
288 [ # # ]: 0 : if( xProp.is() )
289 [ # # ][ # # ]: 0 : xProp->setPropertyValue( C2U("AttachedAxisIndex"), uno::makeAny( sal_Int32(0) ) );
[ # # ][ # # ]
290 : 0 : }
291 : : }
292 : :
293 : 4 : DiagramHelper::setVertical( xDiagram, false );
294 : 4 : }
295 : :
296 : 24 : Reference< XChartType > StockChartTypeTemplate::getChartTypeForIndex( sal_Int32 nChartTypeIndex )
297 : : {
298 : 24 : Reference< XChartType > xCT;
299 : : Reference< lang::XMultiServiceFactory > xFact(
300 [ + - ][ + - ]: 24 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY );
[ + - ][ + - ]
301 [ + - ]: 24 : if(xFact.is())
302 : : {
303 : 24 : bool bHasVolume = false;
304 [ + - ]: 24 : getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME ) >>= bHasVolume;
305 [ - + ]: 24 : if( bHasVolume )
306 : : {
307 [ # # ]: 0 : if( nChartTypeIndex == 0 )
308 [ # # ][ # # ]: 0 : xCT.set( xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_COLUMN ), uno::UNO_QUERY );
[ # # ][ # # ]
309 [ # # ]: 0 : else if( nChartTypeIndex == 1 )
310 [ # # ][ # # ]: 0 : xCT.set( xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK ), uno::UNO_QUERY );
[ # # ][ # # ]
311 : : else
312 [ # # ][ # # ]: 0 : xCT.set( xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_LINE ), uno::UNO_QUERY );
[ # # ][ # # ]
313 : : }
314 : : else
315 : : {
316 [ + - ]: 24 : if( nChartTypeIndex == 0 )
317 [ + - ][ + - ]: 24 : xCT.set( xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK ), uno::UNO_QUERY );
[ + - ][ + - ]
318 : : else
319 [ # # ][ # # ]: 24 : xCT.set( xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_LINE ), uno::UNO_QUERY );
[ # # ][ # # ]
320 : : }
321 : : }
322 : 24 : return xCT;
323 : : }
324 : :
325 : 4 : void StockChartTypeTemplate::createChartTypes(
326 : : const Sequence< Sequence< Reference< XDataSeries > > > & aSeriesSeq,
327 : : const Sequence< Reference< XCoordinateSystem > > & rCoordSys,
328 : : const Sequence< Reference< XChartType > >& /* aOldChartTypesSeq */ )
329 : : {
330 [ - + ]: 4 : if( rCoordSys.getLength() < 1 )
331 : 4 : return;
332 : :
333 : : try
334 : : {
335 : : Reference< lang::XMultiServiceFactory > xFact(
336 [ + - ][ + - ]: 4 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
[ + - ][ + - ]
337 : 4 : bool bHasVolume = false;
338 : 4 : bool bShowFirst = false;
339 : 4 : bool bJapaneseStyle = false;
340 : 4 : bool bShowHighLow = true;
341 : :
342 [ + - ]: 4 : getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME ) >>= bHasVolume;
343 [ + - ]: 4 : getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_OPEN ) >>= bShowFirst;
344 [ + - ]: 4 : getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE ) >>= bJapaneseStyle;
345 [ + - ]: 4 : getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_LOW_HIGH ) >>= bShowHighLow;
346 : :
347 : 4 : sal_Int32 nSeriesIndex = 0;
348 : :
349 [ + - ]: 4 : std::vector< Reference< chart2::XChartType > > aChartTypeVec;
350 : : // Bars (Volume)
351 : : // -------------
352 [ - + ]: 4 : if( bHasVolume )
353 : : {
354 : : // chart type
355 : : Reference< XChartType > xCT(
356 [ # # ]: 0 : xFact->createInstance(
357 [ # # ][ # # ]: 0 : CHART2_SERVICE_NAME_CHARTTYPE_COLUMN ), uno::UNO_QUERY_THROW );
[ # # ]
358 [ # # ]: 0 : aChartTypeVec.push_back( xCT );
359 : :
360 [ # # # # ]: 0 : if( aSeriesSeq.getLength() > nSeriesIndex &&
[ # # ]
361 : 0 : aSeriesSeq[nSeriesIndex].getLength() > 0 )
362 : : {
363 [ # # ]: 0 : Reference< XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW );
364 [ # # ][ # # ]: 0 : xDSCnt->setDataSeries( aSeriesSeq[ nSeriesIndex ] );
365 : : }
366 : 0 : ++nSeriesIndex;
367 : : }
368 : :
369 : : Reference< XChartType > xCT(
370 [ + - ]: 4 : xFact->createInstance(
371 [ + - ][ + - ]: 4 : CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK ), uno::UNO_QUERY_THROW );
[ + - ]
372 [ + - ]: 4 : aChartTypeVec.push_back( xCT );
373 : :
374 [ + - ]: 4 : Reference< beans::XPropertySet > xCTProp( xCT, uno::UNO_QUERY );
375 [ + - ]: 4 : if( xCTProp.is())
376 : : {
377 [ + - ][ + - ]: 4 : xCTProp->setPropertyValue( C2U("Japanese"), uno::makeAny( bJapaneseStyle ));
[ + - ][ + - ]
378 [ + - ][ + - ]: 4 : xCTProp->setPropertyValue( C2U("ShowFirst"), uno::makeAny( bShowFirst ));
[ + - ][ + - ]
379 [ + - ][ + - ]: 4 : xCTProp->setPropertyValue( C2U("ShowHighLow"), uno::makeAny( bShowHighLow ));
[ + - ][ + - ]
380 : : }
381 : :
382 [ + - + - ]: 8 : if( aSeriesSeq.getLength() > nSeriesIndex &&
[ + - ]
383 : 4 : aSeriesSeq[ nSeriesIndex ].getLength() > 0 )
384 : : {
385 [ + - ]: 4 : Reference< XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW );
386 [ + - ][ + - ]: 4 : xDSCnt->setDataSeries( aSeriesSeq[ nSeriesIndex ] );
387 : : }
388 : 4 : ++nSeriesIndex;
389 : :
390 : : // Lines (remaining series)
391 : : // ------------------------
392 [ - + # # ]: 4 : if( aSeriesSeq.getLength() > nSeriesIndex &&
[ - + ]
393 : 0 : aSeriesSeq[ nSeriesIndex ].getLength() > 0 )
394 : : {
395 : : xCT.set(
396 [ # # ]: 0 : xFact->createInstance(
397 [ # # ][ # # ]: 0 : CHART2_SERVICE_NAME_CHARTTYPE_LINE ), uno::UNO_QUERY_THROW );
[ # # ]
398 [ # # ]: 0 : aChartTypeVec.push_back( xCT );
399 : :
400 [ # # ]: 0 : Reference< XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW );
401 [ # # ][ # # ]: 0 : xDSCnt->setDataSeries( aSeriesSeq[ nSeriesIndex ] );
402 : : }
403 : :
404 [ + - ]: 4 : Reference< XChartTypeContainer > xCTCnt( rCoordSys[ 0 ], uno::UNO_QUERY_THROW );
405 [ + - ][ + - ]: 4 : xCTCnt->setChartTypes( ::chart::ContainerHelper::ContainerToSequence(aChartTypeVec) );
[ + - ][ + - ]
[ # # ]
406 : : }
407 : 0 : catch( const uno::Exception & ex )
408 : : {
409 : : ASSERT_EXCEPTION( ex );
410 : : }
411 : : }
412 : :
413 : : // ____ XChartTypeTemplate ____
414 : 4 : sal_Bool SAL_CALL StockChartTypeTemplate::matchesTemplate(
415 : : const uno::Reference< XDiagram >& xDiagram,
416 : : sal_Bool /* bAdaptProperties */ )
417 : : throw (uno::RuntimeException)
418 : : {
419 : 4 : sal_Bool bResult = sal_False;
420 : :
421 [ - + ]: 4 : if( ! xDiagram.is())
422 : 0 : return bResult;
423 : :
424 : : try
425 : : {
426 : 4 : sal_Bool bHasVolume = false, bHasOpenValue = false, bHasJapaneseStyle = false;
427 : :
428 [ + - ]: 4 : getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME ) >>= bHasVolume;
429 [ + - ]: 4 : getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_OPEN ) >>= bHasOpenValue;
430 [ + - ]: 4 : getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE ) >>= bHasJapaneseStyle;
431 : :
432 : 4 : Reference< chart2::XChartType > xVolumeChartType;
433 : 4 : Reference< chart2::XChartType > xCandleStickChartType;
434 : 4 : Reference< chart2::XChartType > xLineChartType;
435 : 4 : sal_Int32 nNumberOfChartTypes = 0;
436 : :
437 : : Reference< XCoordinateSystemContainer > xCooSysCnt(
438 [ + - ]: 4 : xDiagram, uno::UNO_QUERY_THROW );
439 : : Sequence< Reference< XCoordinateSystem > > aCooSysSeq(
440 [ + - ][ + - ]: 4 : xCooSysCnt->getCoordinateSystems());
441 [ + + ]: 8 : for( sal_Int32 i=0; i<aCooSysSeq.getLength(); ++i )
442 : : {
443 [ + - ][ + - ]: 4 : Reference< XChartTypeContainer > xCTCnt( aCooSysSeq[i], uno::UNO_QUERY_THROW );
444 [ + - ][ + - ]: 4 : Sequence< Reference< XChartType > > aChartTypeSeq( xCTCnt->getChartTypes());
445 [ + + ]: 8 : for( sal_Int32 j=0; j<aChartTypeSeq.getLength(); ++j )
446 : : {
447 [ + - ][ + - ]: 4 : if( aChartTypeSeq[j].is())
448 : : {
449 : 4 : ++nNumberOfChartTypes;
450 [ + - ]: 4 : if( nNumberOfChartTypes > 3 )
451 : : break;
452 [ + - ][ + - ]: 4 : OUString aCTService = aChartTypeSeq[j]->getChartType();
[ + - ]
453 [ + - ][ - + ]: 4 : if( aCTService.equals( CHART2_SERVICE_NAME_CHARTTYPE_COLUMN ))
454 [ # # ][ # # ]: 0 : xVolumeChartType.set( aChartTypeSeq[j] );
455 [ + - ][ + - ]: 4 : else if( aCTService.equals( CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK ))
456 [ + - ][ + - ]: 4 : xCandleStickChartType.set( aChartTypeSeq[j] );
457 [ # # ][ # # ]: 0 : else if( aCTService.equals( CHART2_SERVICE_NAME_CHARTTYPE_LINE ))
458 [ # # ][ # # ]: 4 : xLineChartType.set( aChartTypeSeq[j] );
459 : : }
460 : : }
461 [ - + ]: 4 : if( nNumberOfChartTypes > 3 )
462 : : break;
463 [ + - ][ - + ]: 4 : }
[ + - ]
464 : :
465 [ + - ]: 8 : if( xCandleStickChartType.is() &&
[ - + # # ]
[ + - + - ]
[ + - ]
466 : : ( ( bHasVolume &&
467 : 0 : xVolumeChartType.is() ) ||
468 : 4 : ( ! bHasVolume &&
469 : 4 : ! xVolumeChartType.is() )))
470 : : {
471 : 4 : bResult = true;
472 : :
473 : : // check for japanese style
474 [ + - ]: 4 : Reference< beans::XPropertySet > xCTProp( xCandleStickChartType, uno::UNO_QUERY );
475 [ + - ]: 4 : if( xCTProp.is())
476 : : {
477 : 4 : sal_Bool bJapaneseProp = sal_False;
478 [ + - ][ + - ]: 4 : xCTProp->getPropertyValue( C2U("Japanese")) >>= bJapaneseProp;
[ + - ]
479 [ + - ][ + - ]: 4 : bResult = bResult && ( bHasJapaneseStyle == bJapaneseProp );
480 : :
481 : : // in old chart japanese == showFirst
482 : 4 : sal_Bool bShowFirstProp = sal_False;
483 [ + - ][ + - ]: 4 : xCTProp->getPropertyValue( C2U("ShowFirst")) >>= bShowFirstProp;
[ + - ]
484 [ + - ][ + - ]: 4 : bResult = bResult && ( bHasOpenValue == bShowFirstProp );
485 : 4 : }
486 [ + - ][ # # ]: 4 : }
487 : : }
488 : 0 : catch( const uno::Exception & ex )
489 : : {
490 : : ASSERT_EXCEPTION( ex );
491 : : }
492 : :
493 : 4 : return bResult;
494 : : }
495 : :
496 : 8 : Reference< XChartType > SAL_CALL StockChartTypeTemplate::getChartTypeForNewSeries(
497 : : const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes )
498 : : throw (uno::RuntimeException)
499 : : {
500 : 8 : Reference< chart2::XChartType > xResult;
501 : :
502 : : try
503 : : {
504 : : Reference< lang::XMultiServiceFactory > xFact(
505 [ + - ][ + - ]: 8 : GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW );
[ + - ][ + - ]
506 [ + - ]: 8 : xResult.set( xFact->createInstance(
507 [ + - ][ + - ]: 8 : CHART2_SERVICE_NAME_CHARTTYPE_LINE ), uno::UNO_QUERY_THROW );
[ + - ]
508 [ # # ][ + - ]: 8 : ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult );
509 : : }
510 [ # # ]: 0 : catch( const uno::Exception & ex )
511 : : {
512 : : ASSERT_EXCEPTION( ex );
513 : : }
514 : :
515 : 8 : return xResult;
516 : : }
517 : :
518 : 4 : Reference< XDataInterpreter > SAL_CALL StockChartTypeTemplate::getDataInterpreter()
519 : : throw (uno::RuntimeException)
520 : : {
521 [ + - ]: 4 : if( ! m_xDataInterpreter.is())
522 [ + - ][ + - ]: 4 : m_xDataInterpreter.set( new StockDataInterpreter( m_eStockVariant, GetComponentContext() ) );
[ + - ]
523 : :
524 : 4 : return m_xDataInterpreter;
525 : : }
526 : :
527 : : // ----------------------------------------
528 : :
529 : 0 : Sequence< OUString > StockChartTypeTemplate::getSupportedServiceNames_Static()
530 : : {
531 : 0 : Sequence< OUString > aServices( 2 );
532 [ # # ]: 0 : aServices[ 0 ] = lcl_aServiceName;
533 [ # # ][ # # ]: 0 : aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" );
534 : 0 : return aServices;
535 : : }
536 : :
537 : : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
538 [ # # ][ # # ]: 0 : APPHELPER_XSERVICEINFO_IMPL( StockChartTypeTemplate, lcl_aServiceName );
[ # # ][ # # ]
[ # # ]
539 : :
540 [ - + ][ # # ]: 72 : IMPLEMENT_FORWARD_XINTERFACE2( StockChartTypeTemplate, ChartTypeTemplate, OPropertySet )
541 [ # # ][ # # ]: 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( StockChartTypeTemplate, ChartTypeTemplate, OPropertySet )
[ # # ]
542 : :
543 [ + - ][ + - ]: 48 : } // namespace chart
544 : :
545 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|