1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: CandleStickChartType.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "CandleStickChartType.hxx"
35 #include "PropertyHelper.hxx"
37 #include "StockBar.hxx"
38 #include "servicenames_charttypes.hxx"
39 #include "ContainerHelper.hxx"
40 #include <com/sun/star/beans/PropertyAttribute.hpp>
42 using namespace ::com::sun::star
;
44 using ::rtl::OUString
;
45 using ::com::sun::star::beans::Property
;
46 using ::com::sun::star::uno::Sequence
;
47 using ::com::sun::star::uno::Reference
;
48 using ::com::sun::star::uno::Any
;
49 using ::osl::MutexGuard
;
56 PROP_CANDLESTICKCHARTTYPE_JAPANESE
,
57 PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
,
58 PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
,
60 PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
,
61 PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
64 void lcl_AddPropertiesToVector(
65 ::std::vector
< Property
> & rOutProperties
)
67 rOutProperties
.push_back(
68 Property( C2U( "Japanese" ),
69 PROP_CANDLESTICKCHARTTYPE_JAPANESE
,
70 ::getBooleanCppuType(),
71 beans::PropertyAttribute::BOUND
72 | beans::PropertyAttribute::MAYBEDEFAULT
));
74 rOutProperties
.push_back(
75 Property( C2U( "WhiteDay" ),
76 PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
,
77 ::getCppuType( reinterpret_cast< Reference
< beans::XPropertySet
> *>(0)),
78 beans::PropertyAttribute::BOUND
79 | beans::PropertyAttribute::MAYBEVOID
));
80 rOutProperties
.push_back(
81 Property( C2U( "BlackDay" ),
82 PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
,
83 ::getCppuType( reinterpret_cast< Reference
< beans::XPropertySet
> *>(0)),
84 beans::PropertyAttribute::BOUND
85 | beans::PropertyAttribute::MAYBEVOID
));
87 rOutProperties
.push_back(
88 Property( C2U( "ShowFirst" ),
89 PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
,
90 ::getBooleanCppuType(),
91 beans::PropertyAttribute::BOUND
92 | beans::PropertyAttribute::MAYBEDEFAULT
));
93 rOutProperties
.push_back(
94 Property( C2U( "ShowHighLow" ),
95 PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
,
96 ::getBooleanCppuType(),
97 beans::PropertyAttribute::BOUND
98 | beans::PropertyAttribute::MAYBEDEFAULT
));
101 void lcl_AddDefaultsToMap(
102 ::chart::tPropertyValueMap
& rOutMap
,
103 ::osl::Mutex
& rMutex
)
105 ::osl::MutexGuard
aGuard( rMutex
);
106 // must match default in CTOR!
107 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_CANDLESTICKCHARTTYPE_JAPANESE
, false );
108 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
, false );
109 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
, true );
112 const Sequence
< Property
> & lcl_GetPropertySequence()
114 static Sequence
< Property
> aPropSeq
;
117 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
118 if( 0 == aPropSeq
.getLength() )
121 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
122 lcl_AddPropertiesToVector( aProperties
);
124 // and sort them for access via bsearch
125 ::std::sort( aProperties
.begin(), aProperties
.end(),
126 ::chart::PropertyNameLess() );
128 // transfer result to static Sequence
129 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
135 } // anonymous namespace
140 CandleStickChartType::CandleStickChartType(
141 const uno::Reference
< uno::XComponentContext
> & xContext
) :
142 ChartType( xContext
)
144 Reference
< beans::XPropertySet
> xWhiteDayProps( new ::chart::StockBar( true ));
145 Reference
< beans::XPropertySet
> xBlackDayProps( new ::chart::StockBar( false ));
147 ModifyListenerHelper::addListener( xWhiteDayProps
, m_xModifyEventForwarder
);
148 ModifyListenerHelper::addListener( xBlackDayProps
, m_xModifyEventForwarder
);
150 setFastPropertyValue_NoBroadcast(
151 PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
, uno::makeAny( xWhiteDayProps
));
152 setFastPropertyValue_NoBroadcast(
153 PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
, uno::makeAny( xBlackDayProps
));
156 CandleStickChartType::CandleStickChartType( const CandleStickChartType
& rOther
) :
159 Reference
< beans::XPropertySet
> xPropertySet
;
162 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
);
163 if( ( aValue
>>= xPropertySet
)
164 && xPropertySet
.is())
165 ModifyListenerHelper::addListener( xPropertySet
, m_xModifyEventForwarder
);
167 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
);
168 if( ( aValue
>>= xPropertySet
)
169 && xPropertySet
.is())
170 ModifyListenerHelper::addListener( xPropertySet
, m_xModifyEventForwarder
);
173 CandleStickChartType::~CandleStickChartType()
177 Reference
< beans::XPropertySet
> xPropertySet
;
180 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
);
181 if( ( aValue
>>= xPropertySet
)
182 && xPropertySet
.is())
183 ModifyListenerHelper::removeListener( xPropertySet
, m_xModifyEventForwarder
);
185 getFastPropertyValue( aValue
, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
);
186 if( ( aValue
>>= xPropertySet
)
187 && xPropertySet
.is())
188 ModifyListenerHelper::removeListener( xPropertySet
, m_xModifyEventForwarder
);
190 catch( const uno::Exception
& ex
)
192 ASSERT_EXCEPTION( ex
);
196 // ____ XCloneable ____
197 uno::Reference
< util::XCloneable
> SAL_CALL
CandleStickChartType::createClone()
198 throw (uno::RuntimeException
)
200 return uno::Reference
< util::XCloneable
>( new CandleStickChartType( *this ));
203 // ____ XChartType ____
204 ::rtl::OUString SAL_CALL
CandleStickChartType::getChartType()
205 throw (uno::RuntimeException
)
207 return CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
;
210 uno::Sequence
< ::rtl::OUString
> SAL_CALL
CandleStickChartType::getSupportedMandatoryRoles()
211 throw (uno::RuntimeException
)
213 bool bShowFirst
= true;
214 bool bShowHiLow
= false;
215 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
) >>= bShowFirst
;
216 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
) >>= bShowHiLow
;
218 ::std::vector
< OUString
> aMandRoles
;
220 aMandRoles
.push_back( C2U( "label" ));
222 aMandRoles
.push_back( C2U( "values-first" ));
226 aMandRoles
.push_back( C2U( "values-min" ));
227 aMandRoles
.push_back( C2U( "values-max" ));
230 aMandRoles
.push_back( C2U( "values-last" ));
232 return ContainerHelper::ContainerToSequence( aMandRoles
);
235 Sequence
< OUString
> SAL_CALL
CandleStickChartType::getSupportedOptionalRoles()
236 throw (uno::RuntimeException
)
238 bool bShowFirst
= true;
239 bool bShowHiLow
= false;
240 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST
) >>= bShowFirst
;
241 getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
) >>= bShowHiLow
;
243 ::std::vector
< OUString
> aOptRoles
;
246 aOptRoles
.push_back( C2U( "values-first" ));
250 aOptRoles
.push_back( C2U( "values-min" ));
251 aOptRoles
.push_back( C2U( "values-max" ));
254 return ContainerHelper::ContainerToSequence( aOptRoles
);
257 OUString SAL_CALL
CandleStickChartType::getRoleOfSequenceForSeriesLabel()
258 throw (uno::RuntimeException
)
260 return C2U( "values-last" );
263 // ____ OPropertySet ____
264 uno::Any
CandleStickChartType::GetDefaultValue( sal_Int32 nHandle
) const
265 throw(beans::UnknownPropertyException
)
267 static tPropertyValueMap aStaticDefaults
;
270 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
271 if( 0 == aStaticDefaults
.size() )
273 // initialize defaults
274 lcl_AddDefaultsToMap( aStaticDefaults
, GetMutex() );
277 tPropertyValueMap::const_iterator
aFound(
278 aStaticDefaults
.find( nHandle
));
280 if( aFound
== aStaticDefaults
.end())
283 return (*aFound
).second
;
287 // ____ OPropertySet ____
288 ::cppu::IPropertyArrayHelper
& SAL_CALL
CandleStickChartType::getInfoHelper()
290 static ::cppu::OPropertyArrayHelper
aArrayHelper( lcl_GetPropertySequence(),
291 /* bSorted = */ sal_True
);
297 // ____ XPropertySet ____
298 Reference
< beans::XPropertySetInfo
> SAL_CALL
299 CandleStickChartType::getPropertySetInfo()
300 throw (uno::RuntimeException
)
302 static Reference
< beans::XPropertySetInfo
> xInfo
;
305 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
308 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
316 void SAL_CALL
CandleStickChartType::setFastPropertyValue_NoBroadcast(
317 sal_Int32 nHandle
, const uno::Any
& rValue
)
318 throw (uno::Exception
)
320 if( nHandle
== PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
321 || nHandle
== PROP_CANDLESTICKCHARTTYPE_BLACK_DAY
)
324 Reference
< util::XModifyBroadcaster
> xBroadcaster
;
325 this->getFastPropertyValue( aOldValue
, nHandle
);
326 if( aOldValue
.hasValue() &&
327 (aOldValue
>>= xBroadcaster
) &&
330 ModifyListenerHelper::removeListener( xBroadcaster
, m_xModifyEventForwarder
);
333 OSL_ASSERT( rValue
.getValueType().getTypeClass() == uno::TypeClass_INTERFACE
);
334 if( rValue
.hasValue() &&
335 (rValue
>>= xBroadcaster
) &&
338 ModifyListenerHelper::addListener( xBroadcaster
, m_xModifyEventForwarder
);
342 ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle
, rValue
);
345 uno::Sequence
< ::rtl::OUString
> CandleStickChartType::getSupportedServiceNames_Static()
347 uno::Sequence
< ::rtl::OUString
> aServices( 3 );
348 aServices
[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
;
349 aServices
[ 1 ] = C2U( "com.sun.star.chart2.ChartType" );
350 aServices
[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
354 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
355 APPHELPER_XSERVICEINFO_IMPL( CandleStickChartType
,
356 C2U( "com.sun.star.comp.chart.CandleStickChartType" ));