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 : :
21 : : #include "CandleStickChartType.hxx"
22 : : #include "PropertyHelper.hxx"
23 : : #include "macros.hxx"
24 : : #include "StockBar.hxx"
25 : : #include "servicenames_charttypes.hxx"
26 : : #include "ContainerHelper.hxx"
27 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
28 : :
29 : : using namespace ::com::sun::star;
30 : :
31 : : using ::rtl::OUString;
32 : : using ::com::sun::star::beans::Property;
33 : : using ::com::sun::star::uno::Sequence;
34 : : using ::com::sun::star::uno::Reference;
35 : : using ::com::sun::star::uno::Any;
36 : : using ::osl::MutexGuard;
37 : :
38 : : namespace
39 : : {
40 : :
41 : : enum
42 : : {
43 : : PROP_CANDLESTICKCHARTTYPE_JAPANESE,
44 : : PROP_CANDLESTICKCHARTTYPE_WHITE_DAY,
45 : : PROP_CANDLESTICKCHARTTYPE_BLACK_DAY,
46 : :
47 : : PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST,
48 : : PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
49 : : };
50 : :
51 : 2 : void lcl_AddPropertiesToVector(
52 : : ::std::vector< Property > & rOutProperties )
53 : : {
54 : : rOutProperties.push_back(
55 : : Property( C2U( "Japanese" ),
56 : : PROP_CANDLESTICKCHARTTYPE_JAPANESE,
57 [ + - ]: 2 : ::getBooleanCppuType(),
58 : : beans::PropertyAttribute::BOUND
59 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
60 : :
61 : : rOutProperties.push_back(
62 : : Property( C2U( "WhiteDay" ),
63 : : PROP_CANDLESTICKCHARTTYPE_WHITE_DAY,
64 [ + - ]: 2 : ::getCppuType( reinterpret_cast< Reference< beans::XPropertySet > *>(0)),
65 : : beans::PropertyAttribute::BOUND
66 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEVOID ));
67 : : rOutProperties.push_back(
68 : : Property( C2U( "BlackDay" ),
69 : : PROP_CANDLESTICKCHARTTYPE_BLACK_DAY,
70 [ + - ]: 2 : ::getCppuType( reinterpret_cast< Reference< beans::XPropertySet > *>(0)),
71 : : beans::PropertyAttribute::BOUND
72 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEVOID ));
73 : :
74 : : rOutProperties.push_back(
75 : : Property( C2U( "ShowFirst" ),
76 : : PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST,
77 [ + - ]: 2 : ::getBooleanCppuType(),
78 : : beans::PropertyAttribute::BOUND
79 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
80 : : rOutProperties.push_back(
81 : : Property( C2U( "ShowHighLow" ),
82 : : PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW,
83 [ + - ]: 2 : ::getBooleanCppuType(),
84 : : beans::PropertyAttribute::BOUND
85 [ + - ][ + - ]: 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
86 : 2 : }
87 : :
88 : : struct StaticCandleStickChartTypeDefaults_Initializer
89 : : {
90 : 2 : ::chart::tPropertyValueMap* operator()()
91 : : {
92 [ + - ][ + - ]: 2 : static ::chart::tPropertyValueMap aStaticDefaults;
[ + - ][ # # ]
93 : 2 : lcl_AddDefaultsToMap( aStaticDefaults );
94 : 2 : return &aStaticDefaults;
95 : : }
96 : : private:
97 : 2 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
98 : : {
99 : : // must match default in CTOR!
100 [ + - ]: 2 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CANDLESTICKCHARTTYPE_JAPANESE, false );
101 [ + - ]: 2 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST, false );
102 [ + - ]: 2 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW, true );
103 : 2 : }
104 : : };
105 : :
106 : : struct StaticCandleStickChartTypeDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticCandleStickChartTypeDefaults_Initializer >
107 : : {
108 : : };
109 : :
110 : : struct StaticCandleStickChartTypeInfoHelper_Initializer
111 : : {
112 : 2 : ::cppu::OPropertyArrayHelper* operator()()
113 : : {
114 [ + - ][ + - ]: 2 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
[ + - ][ + - ]
[ + - ][ # # ]
115 : 2 : return &aPropHelper;
116 : : }
117 : :
118 : : private:
119 : 2 : Sequence< Property > lcl_GetPropertySequence()
120 : : {
121 [ + - ]: 2 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
122 [ + - ]: 2 : lcl_AddPropertiesToVector( aProperties );
123 : :
124 : : ::std::sort( aProperties.begin(), aProperties.end(),
125 [ + - ]: 2 : ::chart::PropertyNameLess() );
126 : :
127 [ + - ]: 2 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
128 : : }
129 : :
130 : : };
131 : :
132 : : struct StaticCandleStickChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticCandleStickChartTypeInfoHelper_Initializer >
133 : : {
134 : : };
135 : :
136 : : struct StaticCandleStickChartTypeInfo_Initializer
137 : : {
138 : 0 : uno::Reference< beans::XPropertySetInfo >* operator()()
139 : : {
140 : : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
141 [ # # ][ # # ]: 0 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticCandleStickChartTypeInfoHelper::get() ) );
[ # # ][ # # ]
[ # # ]
142 : 0 : return &xPropertySetInfo;
143 : : }
144 : : };
145 : :
146 : : struct StaticCandleStickChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticCandleStickChartTypeInfo_Initializer >
147 : : {
148 : : };
149 : :
150 : : } // anonymous namespace
151 : :
152 : : namespace chart
153 : : {
154 : :
155 : 28 : CandleStickChartType::CandleStickChartType(
156 : : const uno::Reference< uno::XComponentContext > & xContext ) :
157 : 28 : ChartType( xContext )
158 : : {
159 [ + - ][ + - ]: 28 : Reference< beans::XPropertySet > xWhiteDayProps( new ::chart::StockBar( true ));
[ + - ]
160 [ + - ][ + - ]: 28 : Reference< beans::XPropertySet > xBlackDayProps( new ::chart::StockBar( false ));
[ + - ]
161 : :
162 [ + - ]: 28 : ModifyListenerHelper::addListener( xWhiteDayProps, m_xModifyEventForwarder );
163 [ + - ]: 28 : ModifyListenerHelper::addListener( xBlackDayProps, m_xModifyEventForwarder );
164 : :
165 : : setFastPropertyValue_NoBroadcast(
166 [ + - ][ + - ]: 28 : PROP_CANDLESTICKCHARTTYPE_WHITE_DAY, uno::makeAny( xWhiteDayProps ));
167 : : setFastPropertyValue_NoBroadcast(
168 [ + - ][ + - ]: 28 : PROP_CANDLESTICKCHARTTYPE_BLACK_DAY, uno::makeAny( xBlackDayProps ));
169 : 28 : }
170 : :
171 : 0 : CandleStickChartType::CandleStickChartType( const CandleStickChartType & rOther ) :
172 : 0 : ChartType( rOther )
173 : : {
174 : 0 : Reference< beans::XPropertySet > xPropertySet;
175 : 0 : uno::Any aValue;
176 : :
177 [ # # ]: 0 : getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY );
178 [ # # ]: 0 : if( ( aValue >>= xPropertySet )
[ # # # # ]
[ # # ]
179 : 0 : && xPropertySet.is())
180 [ # # ]: 0 : ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder );
181 : :
182 [ # # ]: 0 : getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY );
183 [ # # ]: 0 : if( ( aValue >>= xPropertySet )
[ # # # # ]
[ # # ]
184 : 0 : && xPropertySet.is())
185 [ # # ]: 0 : ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder );
186 : 0 : }
187 : :
188 : 28 : CandleStickChartType::~CandleStickChartType()
189 : : {
190 : : try
191 : : {
192 : 28 : Reference< beans::XPropertySet > xPropertySet;
193 : 28 : uno::Any aValue;
194 : :
195 [ + - ]: 28 : getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY );
196 [ + - ]: 56 : if( ( aValue >>= xPropertySet )
[ + - + - ]
[ + - ]
197 : 28 : && xPropertySet.is())
198 [ + - ]: 28 : ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder );
199 : :
200 [ + - ]: 28 : getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY );
201 [ + - ]: 56 : if( ( aValue >>= xPropertySet )
[ + - + - ]
[ + - ]
202 : 28 : && xPropertySet.is())
203 [ + - ][ # # ]: 28 : ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder );
204 : : }
205 [ # # ]: 0 : catch( const uno::Exception & ex )
206 : : {
207 : : ASSERT_EXCEPTION( ex );
208 : : }
209 [ - + ]: 56 : }
210 : :
211 : : // ____ XCloneable ____
212 : 0 : uno::Reference< util::XCloneable > SAL_CALL CandleStickChartType::createClone()
213 : : throw (uno::RuntimeException)
214 : : {
215 [ # # ][ # # ]: 0 : return uno::Reference< util::XCloneable >( new CandleStickChartType( *this ));
216 : : }
217 : :
218 : : // ____ XChartType ____
219 : 392 : ::rtl::OUString SAL_CALL CandleStickChartType::getChartType()
220 : : throw (uno::RuntimeException)
221 : : {
222 : 392 : return CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK;
223 : : }
224 : :
225 : 0 : uno::Sequence< ::rtl::OUString > SAL_CALL CandleStickChartType::getSupportedMandatoryRoles()
226 : : throw (uno::RuntimeException)
227 : : {
228 : 0 : bool bShowFirst = true;
229 : 0 : bool bShowHiLow = false;
230 [ # # ]: 0 : getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST ) >>= bShowFirst;
231 [ # # ]: 0 : getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW ) >>= bShowHiLow;
232 : :
233 [ # # ]: 0 : ::std::vector< OUString > aMandRoles;
234 : :
235 [ # # ][ # # ]: 0 : aMandRoles.push_back( C2U( "label" ));
236 [ # # ]: 0 : if( bShowFirst )
237 [ # # ][ # # ]: 0 : aMandRoles.push_back( C2U( "values-first" ));
238 : :
239 [ # # ]: 0 : if( bShowHiLow )
240 : : {
241 [ # # ][ # # ]: 0 : aMandRoles.push_back( C2U( "values-min" ));
242 [ # # ][ # # ]: 0 : aMandRoles.push_back( C2U( "values-max" ));
243 : : }
244 : :
245 [ # # ][ # # ]: 0 : aMandRoles.push_back( C2U( "values-last" ));
246 : :
247 [ # # ]: 0 : return ContainerHelper::ContainerToSequence( aMandRoles );
248 : : }
249 : :
250 : 0 : Sequence< OUString > SAL_CALL CandleStickChartType::getSupportedOptionalRoles()
251 : : throw (uno::RuntimeException)
252 : : {
253 : 0 : bool bShowFirst = true;
254 : 0 : bool bShowHiLow = false;
255 [ # # ]: 0 : getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST ) >>= bShowFirst;
256 [ # # ]: 0 : getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW ) >>= bShowHiLow;
257 : :
258 [ # # ]: 0 : ::std::vector< OUString > aOptRoles;
259 : :
260 [ # # ]: 0 : if( ! bShowFirst )
261 [ # # ][ # # ]: 0 : aOptRoles.push_back( C2U( "values-first" ));
262 : :
263 [ # # ]: 0 : if( ! bShowHiLow )
264 : : {
265 [ # # ][ # # ]: 0 : aOptRoles.push_back( C2U( "values-min" ));
266 [ # # ][ # # ]: 0 : aOptRoles.push_back( C2U( "values-max" ));
267 : : }
268 : :
269 [ # # ]: 0 : return ContainerHelper::ContainerToSequence( aOptRoles );
270 : : }
271 : :
272 : 44 : OUString SAL_CALL CandleStickChartType::getRoleOfSequenceForSeriesLabel()
273 : : throw (uno::RuntimeException)
274 : : {
275 : 44 : return C2U( "values-last" );
276 : : }
277 : :
278 : : // ____ OPropertySet ____
279 : 140 : uno::Any CandleStickChartType::GetDefaultValue( sal_Int32 nHandle ) const
280 : : throw(beans::UnknownPropertyException)
281 : : {
282 [ + - ]: 140 : const tPropertyValueMap& rStaticDefaults = *StaticCandleStickChartTypeDefaults::get();
283 [ + - ]: 140 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
284 [ + + ]: 140 : if( aFound == rStaticDefaults.end() )
285 : 112 : return uno::Any();
286 : 140 : return (*aFound).second;
287 : : }
288 : :
289 : : // ____ OPropertySet ____
290 : 72 : ::cppu::IPropertyArrayHelper & SAL_CALL CandleStickChartType::getInfoHelper()
291 : : {
292 : 72 : return *StaticCandleStickChartTypeInfoHelper::get();
293 : : }
294 : :
295 : : // ____ XPropertySet ____
296 : 0 : Reference< beans::XPropertySetInfo > SAL_CALL CandleStickChartType::getPropertySetInfo()
297 : : throw (uno::RuntimeException)
298 : : {
299 : 0 : return *StaticCandleStickChartTypeInfo::get();
300 : : }
301 : :
302 : 56 : void SAL_CALL CandleStickChartType::setFastPropertyValue_NoBroadcast(
303 : : sal_Int32 nHandle, const uno::Any& rValue )
304 : : throw (uno::Exception)
305 : : {
306 [ + + ][ + - ]: 56 : if( nHandle == PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
307 : : || nHandle == PROP_CANDLESTICKCHARTTYPE_BLACK_DAY )
308 : : {
309 : 56 : uno::Any aOldValue;
310 : 56 : Reference< util::XModifyBroadcaster > xBroadcaster;
311 [ + - ]: 56 : this->getFastPropertyValue( aOldValue, nHandle );
312 [ - + ]: 56 : if( aOldValue.hasValue() &&
[ # # # # ]
[ - + ]
313 [ # # ]: 0 : (aOldValue >>= xBroadcaster) &&
314 : 0 : xBroadcaster.is())
315 : : {
316 [ # # ]: 0 : ModifyListenerHelper::removeListener( xBroadcaster, m_xModifyEventForwarder );
317 : : }
318 : :
319 : : OSL_ASSERT( rValue.getValueType().getTypeClass() == uno::TypeClass_INTERFACE );
320 [ + - ]: 168 : if( rValue.hasValue() &&
[ + - + - ]
[ + - ]
321 [ + - ]: 56 : (rValue >>= xBroadcaster) &&
322 : 56 : xBroadcaster.is())
323 : : {
324 [ + - ]: 56 : ModifyListenerHelper::addListener( xBroadcaster, m_xModifyEventForwarder );
325 : 56 : }
326 : : }
327 : :
328 : 56 : ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle, rValue );
329 : 56 : }
330 : :
331 : 2 : uno::Sequence< ::rtl::OUString > CandleStickChartType::getSupportedServiceNames_Static()
332 : : {
333 : 2 : uno::Sequence< ::rtl::OUString > aServices( 3 );
334 [ + - ][ + - ]: 2 : aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK;
335 [ + - ][ + - ]: 2 : aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" );
336 [ + - ][ + - ]: 2 : aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
337 : 2 : return aServices;
338 : : }
339 : :
340 : : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
341 [ # # ][ # # ]: 77 : APPHELPER_XSERVICEINFO_IMPL( CandleStickChartType,
[ # # ][ # # ]
[ # # ]
342 : : C2U( "com.sun.star.comp.chart.CandleStickChartType" ));
343 : :
344 : : } // namespace chart
345 : :
346 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|