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