1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "CandleStickChartType.hxx"
32 #include "PropertyHelper.hxx"
34 #include "StockBar.hxx"
35 #include "servicenames_charttypes.hxx"
36 #include "ContainerHelper.hxx"
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
39 using namespace ::com::sun::star
;
41 using ::rtl::OUString
;
42 using ::com::sun::star::beans::Property
;
43 using ::com::sun::star::uno::Sequence
;
44 using ::com::sun::star::uno::Reference
;
45 using ::com::sun::star::uno::Any
;
46 using ::osl::MutexGuard
;
53 PROP_CANDLESTICKCHARTTYPE_JAPANESE
,
54 PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
,
55 PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
,
57 PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
,
58 PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
61 void lcl_AddPropertiesToVector(
62 ::std::vector
< Property
> & rOutProperties
)
64 rOutProperties
.push_back(
65 Property( C2U( "Japanese" ),
66 PROP_CANDLESTICKCHARTTYPE_JAPANESE
,
67 ::getBooleanCppuType(),
68 beans::PropertyAttribute::BOUND
69 | beans::PropertyAttribute::MAYBEDEFAULT
));
71 rOutProperties
.push_back(
72 Property( C2U( "WhiteDay" ),
73 PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
,
74 ::getCppuType( reinterpret_cast< Reference
< beans::XPropertySet
> *>(0)),
75 beans::PropertyAttribute::BOUND
76 | beans::PropertyAttribute::MAYBEVOID
));
77 rOutProperties
.push_back(
78 Property( C2U( "BlackDay" ),
79 PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
,
80 ::getCppuType( reinterpret_cast< Reference
< beans::XPropertySet
> *>(0)),
81 beans::PropertyAttribute::BOUND
82 | beans::PropertyAttribute::MAYBEVOID
));
84 rOutProperties
.push_back(
85 Property( C2U( "ShowFirst" ),
86 PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
,
87 ::getBooleanCppuType(),
88 beans::PropertyAttribute::BOUND
89 | beans::PropertyAttribute::MAYBEDEFAULT
));
90 rOutProperties
.push_back(
91 Property( C2U( "ShowHighLow" ),
92 PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
,
93 ::getBooleanCppuType(),
94 beans::PropertyAttribute::BOUND
95 | beans::PropertyAttribute::MAYBEDEFAULT
));
98 void lcl_AddDefaultsToMap(
99 ::chart::tPropertyValueMap
& rOutMap
,
100 ::osl::Mutex
& rMutex
)
102 ::osl::MutexGuard
aGuard( rMutex
);
103 // must match default in CTOR!
104 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_CANDLESTICKCHARTTYPE_JAPANESE
, false );
105 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
, false );
106 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
, true );
109 const Sequence
< Property
> & lcl_GetPropertySequence()
111 static Sequence
< Property
> aPropSeq
;
114 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
115 if( 0 == aPropSeq
.getLength() )
118 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
119 lcl_AddPropertiesToVector( aProperties
);
121 // and sort them for access via bsearch
122 ::std::sort( aProperties
.begin(), aProperties
.end(),
123 ::chart::PropertyNameLess() );
125 // transfer result to static Sequence
126 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
132 } // anonymous namespace
137 CandleStickChartType::CandleStickChartType(
138 const uno::Reference
< uno::XComponentContext
> & xContext
) :
139 ChartType( xContext
)
141 Reference
< beans::XPropertySet
> xWhiteDayProps( new ::chart::StockBar( true ));
142 Reference
< beans::XPropertySet
> xBlackDayProps( new ::chart::StockBar( false ));
144 ModifyListenerHelper::addListener( xWhiteDayProps
, m_xModifyEventForwarder
);
145 ModifyListenerHelper::addListener( xBlackDayProps
, m_xModifyEventForwarder
);
147 setFastPropertyValue_NoBroadcast(
148 PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
, uno::makeAny( xWhiteDayProps
));
149 setFastPropertyValue_NoBroadcast(
150 PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
, uno::makeAny( xBlackDayProps
));
153 CandleStickChartType::CandleStickChartType( const CandleStickChartType
& rOther
) :
156 Reference
< beans::XPropertySet
> xPropertySet
;
159 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
);
160 if( ( aValue
>>= xPropertySet
)
161 && xPropertySet
.is())
162 ModifyListenerHelper::addListener( xPropertySet
, m_xModifyEventForwarder
);
164 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
);
165 if( ( aValue
>>= xPropertySet
)
166 && xPropertySet
.is())
167 ModifyListenerHelper::addListener( xPropertySet
, m_xModifyEventForwarder
);
170 CandleStickChartType::~CandleStickChartType()
174 Reference
< beans::XPropertySet
> xPropertySet
;
177 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
);
178 if( ( aValue
>>= xPropertySet
)
179 && xPropertySet
.is())
180 ModifyListenerHelper::removeListener( xPropertySet
, m_xModifyEventForwarder
);
182 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
);
183 if( ( aValue
>>= xPropertySet
)
184 && xPropertySet
.is())
185 ModifyListenerHelper::removeListener( xPropertySet
, m_xModifyEventForwarder
);
187 catch( const uno::Exception
& ex
)
189 ASSERT_EXCEPTION( ex
);
193 // ____ XCloneable ____
194 uno::Reference
< util::XCloneable
> SAL_CALL
CandleStickChartType::createClone()
195 throw (uno::RuntimeException
)
197 return uno::Reference
< util::XCloneable
>( new CandleStickChartType( *this ));
200 // ____ XChartType ____
201 ::rtl::OUString SAL_CALL
CandleStickChartType::getChartType()
202 throw (uno::RuntimeException
)
204 return CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
;
207 uno::Sequence
< ::rtl::OUString
> SAL_CALL
CandleStickChartType::getSupportedMandatoryRoles()
208 throw (uno::RuntimeException
)
210 bool bShowFirst
= true;
211 bool bShowHiLow
= false;
212 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
) >>= bShowFirst
;
213 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
) >>= bShowHiLow
;
215 ::std::vector
< OUString
> aMandRoles
;
217 aMandRoles
.push_back( C2U( "label" ));
219 aMandRoles
.push_back( C2U( "values-first" ));
223 aMandRoles
.push_back( C2U( "values-min" ));
224 aMandRoles
.push_back( C2U( "values-max" ));
227 aMandRoles
.push_back( C2U( "values-last" ));
229 return ContainerHelper::ContainerToSequence( aMandRoles
);
232 Sequence
< OUString
> SAL_CALL
CandleStickChartType::getSupportedOptionalRoles()
233 throw (uno::RuntimeException
)
235 bool bShowFirst
= true;
236 bool bShowHiLow
= false;
237 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
) >>= bShowFirst
;
238 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
) >>= bShowHiLow
;
240 ::std::vector
< OUString
> aOptRoles
;
243 aOptRoles
.push_back( C2U( "values-first" ));
247 aOptRoles
.push_back( C2U( "values-min" ));
248 aOptRoles
.push_back( C2U( "values-max" ));
251 return ContainerHelper::ContainerToSequence( aOptRoles
);
254 OUString SAL_CALL
CandleStickChartType::getRoleOfSequenceForSeriesLabel()
255 throw (uno::RuntimeException
)
257 return C2U( "values-last" );
260 // ____ OPropertySet ____
261 uno::Any
CandleStickChartType::GetDefaultValue( sal_Int32 nHandle
) const
262 throw(beans::UnknownPropertyException
)
264 static tPropertyValueMap aStaticDefaults
;
267 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
268 if( 0 == aStaticDefaults
.size() )
270 // initialize defaults
271 lcl_AddDefaultsToMap( aStaticDefaults
, GetMutex() );
274 tPropertyValueMap::const_iterator
aFound(
275 aStaticDefaults
.find( nHandle
));
277 if( aFound
== aStaticDefaults
.end())
280 return (*aFound
).second
;
284 // ____ OPropertySet ____
285 ::cppu::IPropertyArrayHelper
& SAL_CALL
CandleStickChartType::getInfoHelper()
287 static ::cppu::OPropertyArrayHelper
aArrayHelper( lcl_GetPropertySequence(),
288 /* bSorted = */ sal_True
);
294 // ____ XPropertySet ____
295 Reference
< beans::XPropertySetInfo
> SAL_CALL
296 CandleStickChartType::getPropertySetInfo()
297 throw (uno::RuntimeException
)
299 static Reference
< beans::XPropertySetInfo
> xInfo
;
302 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
305 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
313 void SAL_CALL
CandleStickChartType::setFastPropertyValue_NoBroadcast(
314 sal_Int32 nHandle
, const uno::Any
& rValue
)
315 throw (uno::Exception
)
317 if( nHandle
== PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
318 || nHandle
== PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
)
321 Reference
< util::XModifyBroadcaster
> xBroadcaster
;
322 this->getFastPropertyValue( aOldValue
, nHandle
);
323 if( aOldValue
.hasValue() &&
324 (aOldValue
>>= xBroadcaster
) &&
327 ModifyListenerHelper::removeListener( xBroadcaster
, m_xModifyEventForwarder
);
330 OSL_ASSERT( rValue
.getValueType().getTypeClass() == uno::TypeClass_INTERFACE
);
331 if( rValue
.hasValue() &&
332 (rValue
>>= xBroadcaster
) &&
335 ModifyListenerHelper::addListener( xBroadcaster
, m_xModifyEventForwarder
);
339 ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle
, rValue
);
342 uno::Sequence
< ::rtl::OUString
> CandleStickChartType::getSupportedServiceNames_Static()
344 uno::Sequence
< ::rtl::OUString
> aServices( 3 );
345 aServices
[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
;
346 aServices
[ 1 ] = C2U( "com.sun.star.chart2.ChartType" );
347 aServices
[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
351 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
352 APPHELPER_XSERVICEINFO_IMPL( CandleStickChartType
,
353 C2U( "com.sun.star.comp.chart.CandleStickChartType" ));