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>
22 #include <StockBar.hxx>
23 #include <ModifyListenerHelper.hxx>
24 #include <servicenames_charttypes.hxx>
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <comphelper/diagnose_ex.hxx>
29 namespace com::sun::star::uno
{ class XComponentContext
; }
31 using namespace ::com::sun::star
;
33 using ::com::sun::star::beans::Property
;
34 using ::com::sun::star::uno::Sequence
;
35 using ::com::sun::star::uno::Reference
;
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
.emplace_back( "Japanese",
54 PROP_CANDLESTICKCHARTTYPE_JAPANESE
,
55 cppu::UnoType
<bool>::get(),
56 beans::PropertyAttribute::BOUND
57 | beans::PropertyAttribute::MAYBEDEFAULT
);
59 rOutProperties
.emplace_back( "WhiteDay",
60 PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
,
61 cppu::UnoType
<beans::XPropertySet
>::get(),
62 beans::PropertyAttribute::BOUND
63 | beans::PropertyAttribute::MAYBEVOID
);
64 rOutProperties
.emplace_back( "BlackDay",
65 PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
,
66 cppu::UnoType
<beans::XPropertySet
>::get(),
67 beans::PropertyAttribute::BOUND
68 | beans::PropertyAttribute::MAYBEVOID
);
70 rOutProperties
.emplace_back( "ShowFirst",
71 PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
,
72 cppu::UnoType
<bool>::get(),
73 beans::PropertyAttribute::BOUND
74 | beans::PropertyAttribute::MAYBEDEFAULT
);
75 rOutProperties
.emplace_back( "ShowHighLow",
76 PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
,
77 cppu::UnoType
<bool>::get(),
78 beans::PropertyAttribute::BOUND
79 | beans::PropertyAttribute::MAYBEDEFAULT
);
82 ::cppu::OPropertyArrayHelper
& StaticCandleStickChartTypeInfoHelper()
84 static ::cppu::OPropertyArrayHelper aPropHelper
= []()
86 std::vector
< css::beans::Property
> aProperties
;
87 lcl_AddPropertiesToVector( aProperties
);
88 std::sort( aProperties
.begin(), aProperties
.end(),
89 ::chart::PropertyNameLess() );
90 return comphelper::containerToSequence( aProperties
);
95 } // anonymous namespace
100 CandleStickChartType::CandleStickChartType()
102 Reference
< beans::XPropertySet
> xWhiteDayProps( new ::chart::StockBar( true ));
103 Reference
< beans::XPropertySet
> xBlackDayProps( new ::chart::StockBar( false ));
105 ModifyListenerHelper::addListener( xWhiteDayProps
, m_xModifyEventForwarder
);
106 ModifyListenerHelper::addListener( xBlackDayProps
, m_xModifyEventForwarder
);
108 setFastPropertyValue_NoBroadcast(
109 PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
, uno::Any( xWhiteDayProps
));
110 setFastPropertyValue_NoBroadcast(
111 PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
, uno::Any( xBlackDayProps
));
114 CandleStickChartType::CandleStickChartType( const CandleStickChartType
& rOther
) :
117 Reference
< beans::XPropertySet
> xPropertySet
;
120 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
);
121 if( ( aValue
>>= xPropertySet
)
122 && xPropertySet
.is())
123 ModifyListenerHelper::addListener( xPropertySet
, m_xModifyEventForwarder
);
125 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
);
126 if( ( aValue
>>= xPropertySet
)
127 && xPropertySet
.is())
128 ModifyListenerHelper::addListener( xPropertySet
, m_xModifyEventForwarder
);
131 CandleStickChartType::~CandleStickChartType()
135 Reference
< beans::XPropertySet
> xPropertySet
;
138 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
);
139 if( ( aValue
>>= xPropertySet
)
140 && xPropertySet
.is())
141 ModifyListenerHelper::removeListener( xPropertySet
, m_xModifyEventForwarder
);
143 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
);
144 if( ( aValue
>>= xPropertySet
)
145 && xPropertySet
.is())
146 ModifyListenerHelper::removeListener( xPropertySet
, m_xModifyEventForwarder
);
148 catch( const uno::Exception
& )
150 DBG_UNHANDLED_EXCEPTION("chart2");
154 // ____ XCloneable ____
155 uno::Reference
< util::XCloneable
> SAL_CALL
CandleStickChartType::createClone()
157 return uno::Reference
< util::XCloneable
>( new CandleStickChartType( *this ));
160 rtl::Reference
< ChartType
> CandleStickChartType::cloneChartType() const
162 return new CandleStickChartType( *this );
165 // ____ XChartType ____
166 OUString SAL_CALL
CandleStickChartType::getChartType()
168 return CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
;
171 uno::Sequence
< OUString
> SAL_CALL
CandleStickChartType::getSupportedMandatoryRoles()
173 bool bShowFirst
= true;
174 bool bShowHiLow
= false;
175 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
) >>= bShowFirst
;
176 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
) >>= bShowHiLow
;
178 std::vector
< OUString
> aMandRoles
;
180 aMandRoles
.emplace_back("label");
182 aMandRoles
.emplace_back("values-first");
186 aMandRoles
.emplace_back("values-min");
187 aMandRoles
.emplace_back("values-max");
190 aMandRoles
.emplace_back("values-last");
192 return comphelper::containerToSequence( aMandRoles
);
195 Sequence
< OUString
> SAL_CALL
CandleStickChartType::getSupportedOptionalRoles()
197 bool bShowFirst
= true;
198 bool bShowHiLow
= false;
199 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
) >>= bShowFirst
;
200 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
) >>= bShowHiLow
;
202 std::vector
< OUString
> aOptRoles
;
205 aOptRoles
.emplace_back("values-first");
209 aOptRoles
.emplace_back("values-min");
210 aOptRoles
.emplace_back("values-max");
213 return comphelper::containerToSequence( aOptRoles
);
216 OUString SAL_CALL
CandleStickChartType::getRoleOfSequenceForSeriesLabel()
218 return u
"values-last"_ustr
;
221 // ____ OPropertySet ____
222 void CandleStickChartType::GetDefaultValue( sal_Int32 nHandle
, uno::Any
& rAny
) const
224 static const ::chart::tPropertyValueMap aStaticDefaults
= []()
226 // must match default in CTOR!
227 ::chart::tPropertyValueMap aTmp
;
228 ::chart::PropertyHelper::setPropertyValueDefault( aTmp
, PROP_CANDLESTICKCHARTTYPE_JAPANESE
, false );
229 ::chart::PropertyHelper::setPropertyValueDefault( aTmp
, PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
, false );
230 ::chart::PropertyHelper::setPropertyValueDefault( aTmp
, PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
, true );
233 tPropertyValueMap::const_iterator
aFound( aStaticDefaults
.find( nHandle
) );
234 if( aFound
== aStaticDefaults
.end() )
237 rAny
= (*aFound
).second
;
240 // ____ OPropertySet ____
241 ::cppu::IPropertyArrayHelper
& SAL_CALL
CandleStickChartType::getInfoHelper()
243 return StaticCandleStickChartTypeInfoHelper();
246 // ____ XPropertySet ____
247 Reference
< beans::XPropertySetInfo
> SAL_CALL
CandleStickChartType::getPropertySetInfo()
249 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
250 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticCandleStickChartTypeInfoHelper() ) );
251 return xPropertySetInfo
;
254 void SAL_CALL
CandleStickChartType::setFastPropertyValue_NoBroadcast(
255 sal_Int32 nHandle
, const uno::Any
& rValue
)
257 if( nHandle
== PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
258 || nHandle
== PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
)
261 Reference
< util::XModifyBroadcaster
> xBroadcaster
;
262 getFastPropertyValue( aOldValue
, nHandle
);
263 if( aOldValue
.hasValue() &&
264 (aOldValue
>>= xBroadcaster
) &&
267 ModifyListenerHelper::removeListener( xBroadcaster
, m_xModifyEventForwarder
);
270 OSL_ASSERT( rValue
.getValueTypeClass() == uno::TypeClass_INTERFACE
);
271 if( rValue
.hasValue() &&
272 (rValue
>>= xBroadcaster
) &&
275 ModifyListenerHelper::addListener( xBroadcaster
, m_xModifyEventForwarder
);
279 ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle
, rValue
);
282 OUString SAL_CALL
CandleStickChartType::getImplementationName()
284 return u
"com.sun.star.comp.chart.CandleStickChartType"_ustr
;
287 sal_Bool SAL_CALL
CandleStickChartType::supportsService( const OUString
& rServiceName
)
289 return cppu::supportsService(this, rServiceName
);
292 css::uno::Sequence
< OUString
> SAL_CALL
CandleStickChartType::getSupportedServiceNames()
295 CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
,
296 u
"com.sun.star.chart2.ChartType"_ustr
,
297 u
"com.sun.star.beans.PropertySet"_ustr
};
302 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
303 com_sun_star_comp_chart_CandleStickChartType_get_implementation(css::uno::XComponentContext
* /*context*/,
304 css::uno::Sequence
<css::uno::Any
> const &)
306 return cppu::acquire(new ::chart::CandleStickChartType
);
309 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */