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