1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "CandleStickChartType.hxx"
21 #include "PropertyHelper.hxx"
23 #include "StockBar.hxx"
24 #include "servicenames_charttypes.hxx"
25 #include "ContainerHelper.hxx"
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <cppuhelper/supportsservice.hxx>
29 using namespace ::com::sun::star
;
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
;
42 PROP_CANDLESTICKCHARTTYPE_JAPANESE
,
43 PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
,
44 PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
,
46 PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
,
47 PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
50 void lcl_AddPropertiesToVector(
51 ::std::vector
< Property
> & rOutProperties
)
53 rOutProperties
.push_back(
55 PROP_CANDLESTICKCHARTTYPE_JAPANESE
,
56 cppu::UnoType
<bool>::get(),
57 beans::PropertyAttribute::BOUND
58 | beans::PropertyAttribute::MAYBEDEFAULT
));
60 rOutProperties
.push_back(
62 PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
,
63 cppu::UnoType
<beans::XPropertySet
>::get(),
64 beans::PropertyAttribute::BOUND
65 | beans::PropertyAttribute::MAYBEVOID
));
66 rOutProperties
.push_back(
68 PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
,
69 cppu::UnoType
<beans::XPropertySet
>::get(),
70 beans::PropertyAttribute::BOUND
71 | beans::PropertyAttribute::MAYBEVOID
));
73 rOutProperties
.push_back(
74 Property( "ShowFirst",
75 PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
,
76 cppu::UnoType
<bool>::get(),
77 beans::PropertyAttribute::BOUND
78 | beans::PropertyAttribute::MAYBEDEFAULT
));
79 rOutProperties
.push_back(
80 Property( "ShowHighLow",
81 PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
,
82 cppu::UnoType
<bool>::get(),
83 beans::PropertyAttribute::BOUND
84 | beans::PropertyAttribute::MAYBEDEFAULT
));
87 struct StaticCandleStickChartTypeDefaults_Initializer
89 ::chart::tPropertyValueMap
* operator()()
91 static ::chart::tPropertyValueMap aStaticDefaults
;
92 lcl_AddDefaultsToMap( aStaticDefaults
);
93 return &aStaticDefaults
;
96 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
98 // must match default in CTOR!
99 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_CANDLESTICKCHARTTYPE_JAPANESE
, false );
100 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
, false );
101 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
, true );
105 struct StaticCandleStickChartTypeDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticCandleStickChartTypeDefaults_Initializer
>
109 struct StaticCandleStickChartTypeInfoHelper_Initializer
111 ::cppu::OPropertyArrayHelper
* operator()()
113 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
118 static Sequence
< Property
> lcl_GetPropertySequence()
120 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
121 lcl_AddPropertiesToVector( aProperties
);
123 ::std::sort( aProperties
.begin(), aProperties
.end(),
124 ::chart::PropertyNameLess() );
126 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
131 struct StaticCandleStickChartTypeInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticCandleStickChartTypeInfoHelper_Initializer
>
135 struct StaticCandleStickChartTypeInfo_Initializer
137 uno::Reference
< beans::XPropertySetInfo
>* operator()()
139 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
140 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticCandleStickChartTypeInfoHelper::get() ) );
141 return &xPropertySetInfo
;
145 struct StaticCandleStickChartTypeInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticCandleStickChartTypeInfo_Initializer
>
149 } // anonymous namespace
154 CandleStickChartType::CandleStickChartType(
155 const uno::Reference
< uno::XComponentContext
> & xContext
) :
156 ChartType( xContext
)
158 Reference
< beans::XPropertySet
> xWhiteDayProps( new ::chart::StockBar( true ));
159 Reference
< beans::XPropertySet
> xBlackDayProps( new ::chart::StockBar( false ));
161 ModifyListenerHelper::addListener( xWhiteDayProps
, m_xModifyEventForwarder
);
162 ModifyListenerHelper::addListener( xBlackDayProps
, m_xModifyEventForwarder
);
164 setFastPropertyValue_NoBroadcast(
165 PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
, uno::makeAny( xWhiteDayProps
));
166 setFastPropertyValue_NoBroadcast(
167 PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
, uno::makeAny( xBlackDayProps
));
170 CandleStickChartType::CandleStickChartType( const CandleStickChartType
& rOther
) :
173 Reference
< beans::XPropertySet
> xPropertySet
;
176 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
);
177 if( ( aValue
>>= xPropertySet
)
178 && xPropertySet
.is())
179 ModifyListenerHelper::addListener( xPropertySet
, m_xModifyEventForwarder
);
181 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
);
182 if( ( aValue
>>= xPropertySet
)
183 && xPropertySet
.is())
184 ModifyListenerHelper::addListener( xPropertySet
, m_xModifyEventForwarder
);
187 CandleStickChartType::~CandleStickChartType()
191 Reference
< beans::XPropertySet
> xPropertySet
;
194 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
);
195 if( ( aValue
>>= xPropertySet
)
196 && xPropertySet
.is())
197 ModifyListenerHelper::removeListener( xPropertySet
, m_xModifyEventForwarder
);
199 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
);
200 if( ( aValue
>>= xPropertySet
)
201 && xPropertySet
.is())
202 ModifyListenerHelper::removeListener( xPropertySet
, m_xModifyEventForwarder
);
204 catch( const uno::Exception
& ex
)
206 ASSERT_EXCEPTION( ex
);
210 // ____ XCloneable ____
211 uno::Reference
< util::XCloneable
> SAL_CALL
CandleStickChartType::createClone()
212 throw (uno::RuntimeException
, std::exception
)
214 return uno::Reference
< util::XCloneable
>( new CandleStickChartType( *this ));
217 // ____ XChartType ____
218 OUString SAL_CALL
CandleStickChartType::getChartType()
219 throw (uno::RuntimeException
, std::exception
)
221 return OUString(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
);
224 uno::Sequence
< OUString
> SAL_CALL
CandleStickChartType::getSupportedMandatoryRoles()
225 throw (uno::RuntimeException
, std::exception
)
227 bool bShowFirst
= true;
228 bool bShowHiLow
= false;
229 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
) >>= bShowFirst
;
230 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
) >>= bShowHiLow
;
232 ::std::vector
< OUString
> aMandRoles
;
234 aMandRoles
.push_back( "label");
236 aMandRoles
.push_back( "values-first");
240 aMandRoles
.push_back( "values-min");
241 aMandRoles
.push_back( "values-max");
244 aMandRoles
.push_back( "values-last");
246 return ContainerHelper::ContainerToSequence( aMandRoles
);
249 Sequence
< OUString
> SAL_CALL
CandleStickChartType::getSupportedOptionalRoles()
250 throw (uno::RuntimeException
, std::exception
)
252 bool bShowFirst
= true;
253 bool bShowHiLow
= false;
254 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
) >>= bShowFirst
;
255 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
) >>= bShowHiLow
;
257 ::std::vector
< OUString
> aOptRoles
;
260 aOptRoles
.push_back( "values-first");
264 aOptRoles
.push_back( "values-min");
265 aOptRoles
.push_back( "values-max");
268 return ContainerHelper::ContainerToSequence( aOptRoles
);
271 OUString SAL_CALL
CandleStickChartType::getRoleOfSequenceForSeriesLabel()
272 throw (uno::RuntimeException
, std::exception
)
274 return OUString("values-last");
277 // ____ OPropertySet ____
278 uno::Any
CandleStickChartType::GetDefaultValue( sal_Int32 nHandle
) const
279 throw(beans::UnknownPropertyException
)
281 const tPropertyValueMap
& rStaticDefaults
= *StaticCandleStickChartTypeDefaults::get();
282 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
283 if( aFound
== rStaticDefaults
.end() )
285 return (*aFound
).second
;
288 // ____ OPropertySet ____
289 ::cppu::IPropertyArrayHelper
& SAL_CALL
CandleStickChartType::getInfoHelper()
291 return *StaticCandleStickChartTypeInfoHelper::get();
294 // ____ XPropertySet ____
295 Reference
< beans::XPropertySetInfo
> SAL_CALL
CandleStickChartType::getPropertySetInfo()
296 throw (uno::RuntimeException
, std::exception
)
298 return *StaticCandleStickChartTypeInfo::get();
301 void SAL_CALL
CandleStickChartType::setFastPropertyValue_NoBroadcast(
302 sal_Int32 nHandle
, const uno::Any
& rValue
)
303 throw (uno::Exception
, std::exception
)
305 if( nHandle
== PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
306 || nHandle
== PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
)
309 Reference
< util::XModifyBroadcaster
> xBroadcaster
;
310 this->getFastPropertyValue( aOldValue
, nHandle
);
311 if( aOldValue
.hasValue() &&
312 (aOldValue
>>= xBroadcaster
) &&
315 ModifyListenerHelper::removeListener( xBroadcaster
, m_xModifyEventForwarder
);
318 OSL_ASSERT( rValue
.getValueType().getTypeClass() == uno::TypeClass_INTERFACE
);
319 if( rValue
.hasValue() &&
320 (rValue
>>= xBroadcaster
) &&
323 ModifyListenerHelper::addListener( xBroadcaster
, m_xModifyEventForwarder
);
327 ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle
, rValue
);
330 uno::Sequence
< OUString
> CandleStickChartType::getSupportedServiceNames_Static()
332 uno::Sequence
< OUString
> aServices( 3 );
333 aServices
[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
;
334 aServices
[ 1 ] = "com.sun.star.chart2.ChartType";
335 aServices
[ 2 ] = "com.sun.star.beans.PropertySet";
339 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
340 OUString SAL_CALL
CandleStickChartType::getImplementationName()
341 throw( css::uno::RuntimeException
, std::exception
)
343 return getImplementationName_Static();
346 OUString
CandleStickChartType::getImplementationName_Static()
348 return OUString("com.sun.star.comp.chart.CandleStickChartType") ;
351 sal_Bool SAL_CALL
CandleStickChartType::supportsService( const OUString
& rServiceName
)
352 throw( css::uno::RuntimeException
, std::exception
)
354 return cppu::supportsService(this, rServiceName
);
357 css::uno::Sequence
< OUString
> SAL_CALL
CandleStickChartType::getSupportedServiceNames()
358 throw( css::uno::RuntimeException
, std::exception
)
360 return getSupportedServiceNames_Static();
365 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
366 com_sun_star_comp_chart_CandleStickChartType_get_implementation(css::uno::XComponentContext
*context
,
367 css::uno::Sequence
<css::uno::Any
> const &)
369 return cppu::acquire(new ::chart::CandleStickChartType(context
));
372 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */