LibreOffice Module chart2 (master) 1
CandleStickChartType.cxx
Go to the documentation of this file.
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
21#include <PropertyHelper.hxx>
22#include <StockBar.hxx>
25#include <com/sun/star/beans/PropertyAttribute.hpp>
28
29namespace com::sun::star::uno { class XComponentContext; }
30
31using namespace ::com::sun::star;
32
33using ::com::sun::star::beans::Property;
34using ::com::sun::star::uno::Sequence;
35using ::com::sun::star::uno::Reference;
36
37namespace
38{
39
40enum
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
50void lcl_AddPropertiesToVector(
51 std::vector< Property > & rOutProperties )
52{
53 rOutProperties.emplace_back( "Japanese",
54 PROP_CANDLESTICKCHARTTYPE_JAPANESE,
56 beans::PropertyAttribute::BOUND
57 | beans::PropertyAttribute::MAYBEDEFAULT );
58
59 rOutProperties.emplace_back( "WhiteDay",
60 PROP_CANDLESTICKCHARTTYPE_WHITE_DAY,
62 beans::PropertyAttribute::BOUND
63 | beans::PropertyAttribute::MAYBEVOID );
64 rOutProperties.emplace_back( "BlackDay",
65 PROP_CANDLESTICKCHARTTYPE_BLACK_DAY,
67 beans::PropertyAttribute::BOUND
68 | beans::PropertyAttribute::MAYBEVOID );
69
70 rOutProperties.emplace_back( "ShowFirst",
71 PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST,
73 beans::PropertyAttribute::BOUND
74 | beans::PropertyAttribute::MAYBEDEFAULT );
75 rOutProperties.emplace_back( "ShowHighLow",
76 PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW,
78 beans::PropertyAttribute::BOUND
79 | beans::PropertyAttribute::MAYBEDEFAULT );
80}
81
82::cppu::OPropertyArrayHelper& StaticCandleStickChartTypeInfoHelper()
83{
84 static ::cppu::OPropertyArrayHelper aPropHelper = []()
85 {
86 std::vector< css::beans::Property > aProperties;
87 lcl_AddPropertiesToVector( aProperties );
88 std::sort( aProperties.begin(), aProperties.end(),
90 return comphelper::containerToSequence( aProperties );
91 }();
92 return aPropHelper;
93};
94
95} // anonymous namespace
96
97namespace chart
98{
99
101{
102 Reference< beans::XPropertySet > xWhiteDayProps( new ::chart::StockBar( true ));
103 Reference< beans::XPropertySet > xBlackDayProps( new ::chart::StockBar( false ));
104
107
109 PROP_CANDLESTICKCHARTTYPE_WHITE_DAY, uno::Any( xWhiteDayProps ));
111 PROP_CANDLESTICKCHARTTYPE_BLACK_DAY, uno::Any( xBlackDayProps ));
112}
113
115 ChartType( rOther )
116{
118 uno::Any aValue;
119
120 getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY );
121 if( ( aValue >>= xPropertySet )
122 && xPropertySet.is())
124
125 getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY );
126 if( ( aValue >>= xPropertySet )
127 && xPropertySet.is())
129}
130
132{
133 try
134 {
136 uno::Any aValue;
137
138 getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY );
139 if( ( aValue >>= xPropertySet )
140 && xPropertySet.is())
142
143 getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY );
144 if( ( aValue >>= xPropertySet )
145 && xPropertySet.is())
147 }
148 catch( const uno::Exception & )
149 {
150 DBG_UNHANDLED_EXCEPTION("chart2");
151 }
152}
153
154// ____ XCloneable ____
156{
158}
159
161{
162 return new CandleStickChartType( *this );
163}
164
165// ____ XChartType ____
167{
169}
170
172{
173 bool bShowFirst = true;
174 bool bShowHiLow = false;
175 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST ) >>= bShowFirst;
176 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW ) >>= bShowHiLow;
177
178 std::vector< OUString > aMandRoles;
179
180 aMandRoles.emplace_back("label");
181 if( bShowFirst )
182 aMandRoles.emplace_back("values-first");
183
184 if( bShowHiLow )
185 {
186 aMandRoles.emplace_back("values-min");
187 aMandRoles.emplace_back("values-max");
188 }
189
190 aMandRoles.emplace_back("values-last");
191
192 return comphelper::containerToSequence( aMandRoles );
193}
194
196{
197 bool bShowFirst = true;
198 bool bShowHiLow = false;
199 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST ) >>= bShowFirst;
200 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW ) >>= bShowHiLow;
201
202 std::vector< OUString > aOptRoles;
203
204 if( ! bShowFirst )
205 aOptRoles.emplace_back("values-first");
206
207 if( ! bShowHiLow )
208 {
209 aOptRoles.emplace_back("values-min");
210 aOptRoles.emplace_back("values-max");
211 }
212
213 return comphelper::containerToSequence( aOptRoles );
214}
215
217{
218 return "values-last";
219}
220
221// ____ OPropertySet ____
222void CandleStickChartType::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
223{
224 static const ::chart::tPropertyValueMap aStaticDefaults = []()
225 {
226 // must match default in CTOR!
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 );
231 return aTmp;
232 }();
233 tPropertyValueMap::const_iterator aFound( aStaticDefaults.find( nHandle ) );
234 if( aFound == aStaticDefaults.end() )
235 rAny.clear();
236 else
237 rAny = (*aFound).second;
238}
239
240// ____ OPropertySet ____
242{
243 return StaticCandleStickChartTypeInfoHelper();
244}
245
246// ____ XPropertySet ____
248{
249 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
250 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticCandleStickChartTypeInfoHelper() ) );
251 return xPropertySetInfo;
252}
253
255 sal_Int32 nHandle, const uno::Any& rValue )
256{
257 if( nHandle == PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
258 || nHandle == PROP_CANDLESTICKCHARTTYPE_BLACK_DAY )
259 {
260 uno::Any aOldValue;
262 getFastPropertyValue( aOldValue, nHandle );
263 if( aOldValue.hasValue() &&
264 (aOldValue >>= xBroadcaster) &&
265 xBroadcaster.is())
266 {
268 }
269
270 OSL_ASSERT( rValue.getValueType().getTypeClass() == uno::TypeClass_INTERFACE );
271 if( rValue.hasValue() &&
272 (rValue >>= xBroadcaster) &&
273 xBroadcaster.is())
274 {
276 }
277 }
278
280}
281
283{
284 return "com.sun.star.comp.chart.CandleStickChartType" ;
285}
286
287sal_Bool SAL_CALL CandleStickChartType::supportsService( const OUString& rServiceName )
288{
289 return cppu::supportsService(this, rServiceName);
290}
291
292css::uno::Sequence< OUString > SAL_CALL CandleStickChartType::getSupportedServiceNames()
293{
294 return {
296 "com.sun.star.chart2.ChartType",
297 "com.sun.star.beans.PropertySet" };
298}
299
300} // namespace chart
301
302extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
304 css::uno::Sequence<css::uno::Any> const &)
305{
306 return cppu::acquire(new ::chart::CandleStickChartType);
307}
308
309/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart_CandleStickChartType_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
PropertiesInfo aProperties
virtual ~CandleStickChartType() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
The InfoHelper table contains all property names and types of this object.
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
The same as setFastPropertyValue; nHandle is always valid.
virtual OUString SAL_CALL getChartType() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedMandatoryRoles() override
virtual OUString SAL_CALL getImplementationName() override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void GetDefaultValue(sal_Int32 nHandle, css::uno::Any &rAny) const override
implement this method to provide default values for all properties supporting defaults.
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedOptionalRoles() override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual rtl::Reference< ChartType > cloneChartType() const override
virtual OUString SAL_CALL getRoleOfSequenceForSeriesLabel() override
rtl::Reference< ModifyEventForwarder > m_xModifyEventForwarder
merge XTypeProvider implementations
Definition: ChartType.hxx:142
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
virtual void SAL_CALL getFastPropertyValue(css::uno::Any &rValue, sal_Int32 nHandle) const override
The same as getFastPropertyValue, but return the value through rValue and nHandle is always valid.
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
The same as setFastPropertyValue; nHandle is always valid.
#define DBG_UNHANDLED_EXCEPTION(...)
void removeListener(const InterfaceRef &xObject, const css::uno::Reference< css::util::XModifyListener > &xListener)
void addListener(const InterfaceRef &xObject, const css::uno::Reference< css::util::XModifyListener > &xListener)
void setPropertyValueDefault(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Calls setPropertyValue() but asserts that the given property hasn't been set before.
std::unordered_map< tPropertyValueMapKey, css::uno::Any > tPropertyValueMap
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
sal_Int32 nHandle
constexpr OUStringLiteral CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
bool hasValue()
unsigned char sal_Bool