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 "UpDownBarWrapper.hxx"
22 #include "Chart2ModelContact.hxx"
23 #include "DiagramHelper.hxx"
24 #include "servicenames_charttypes.hxx"
25 #include "ContainerHelper.hxx"
26 #include <cppuhelper/supportsservice.hxx>
27 #include <com/sun/star/chart2/XChartType.hpp>
28 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
30 #include "LinePropertiesHelper.hxx"
31 #include "FillProperties.hxx"
32 #include "UserDefinedProperties.hxx"
34 using namespace ::com::sun::star
;
35 using namespace ::com::sun::star::chart2
;
37 using ::com::sun::star::beans::Property
;
38 using ::osl::MutexGuard
;
39 using ::com::sun::star::uno::Reference
;
40 using ::com::sun::star::uno::Sequence
;
41 using ::com::sun::star::uno::Any
;
45 static const char lcl_aServiceName
[] = "com.sun.star.comp.chart.ChartArea";
47 struct StaticUpDownBarWrapperPropertyArray_Initializer
49 Sequence
< Property
>* operator()()
51 static Sequence
< Property
> aPropSeq( lcl_GetPropertySequence() );
56 static Sequence
< Property
> lcl_GetPropertySequence()
58 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
60 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
61 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
62 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
64 ::std::sort( aProperties
.begin(), aProperties
.end(),
65 ::chart::PropertyNameLess() );
67 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
71 struct StaticUpDownBarWrapperPropertyArray
: public rtl::StaticAggregate
< Sequence
< Property
>, StaticUpDownBarWrapperPropertyArray_Initializer
>
75 struct StaticUpDownBarWrapperInfoHelper_Initializer
77 ::cppu::OPropertyArrayHelper
* operator()()
79 static ::cppu::OPropertyArrayHelper
aPropHelper( *StaticUpDownBarWrapperPropertyArray::get() );
84 struct StaticUpDownBarWrapperInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticUpDownBarWrapperInfoHelper_Initializer
>
88 struct StaticUpDownBarWrapperInfo_Initializer
90 uno::Reference
< beans::XPropertySetInfo
>* operator()()
92 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
93 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticUpDownBarWrapperInfoHelper::get() ) );
94 return &xPropertySetInfo
;
98 struct StaticUpDownBarWrapperInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticUpDownBarWrapperInfo_Initializer
>
102 struct StaticUpDownBarWrapperDefaults_Initializer
104 ::chart::tPropertyValueMap
* operator()()
106 static ::chart::tPropertyValueMap aStaticDefaults
;
107 lcl_AddDefaultsToMap( aStaticDefaults
);
108 return &aStaticDefaults
;
111 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
113 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap
);
114 ::chart::FillProperties::AddDefaultsToMap( rOutMap
);
118 struct StaticUpDownBarWrapperDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticUpDownBarWrapperDefaults_Initializer
>
122 } // anonymous namespace
129 UpDownBarWrapper::UpDownBarWrapper(
130 bool bUp
, ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
131 : m_spChart2ModelContact( spChart2ModelContact
)
132 , m_aEventListenerContainer( m_aMutex
)
133 , m_aPropertySetName( bUp
? OUString( "WhiteDay" ) : OUString( "BlackDay" ))
137 UpDownBarWrapper::~UpDownBarWrapper()
141 // ____ XComponent ____
142 void SAL_CALL
UpDownBarWrapper::dispose()
143 throw (uno::RuntimeException
, std::exception
)
145 Reference
< uno::XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
146 m_aEventListenerContainer
.disposeAndClear( lang::EventObject( xSource
) );
149 void SAL_CALL
UpDownBarWrapper::addEventListener(
150 const Reference
< lang::XEventListener
>& xListener
)
151 throw (uno::RuntimeException
, std::exception
)
153 m_aEventListenerContainer
.addInterface( xListener
);
156 void SAL_CALL
UpDownBarWrapper::removeEventListener(
157 const Reference
< lang::XEventListener
>& aListener
)
158 throw (uno::RuntimeException
, std::exception
)
160 m_aEventListenerContainer
.removeInterface( aListener
);
163 ::cppu::IPropertyArrayHelper
& UpDownBarWrapper::getInfoHelper()
165 return *StaticUpDownBarWrapperInfoHelper::get();
169 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
UpDownBarWrapper::getPropertySetInfo()
170 throw (uno::RuntimeException
, std::exception
)
172 return *StaticUpDownBarWrapperInfo::get();
174 void SAL_CALL
UpDownBarWrapper::setPropertyValue( const OUString
& rPropertyName
, const uno::Any
& rValue
)
175 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
177 Reference
< beans::XPropertySet
> xPropSet(0);
179 Sequence
< Reference
< chart2::XChartType
> > aTypes(
180 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact
->getChart2Diagram() ) );
181 for( sal_Int32 nN
= 0; nN
< aTypes
.getLength(); nN
++ )
183 Reference
< chart2::XChartType
> xType( aTypes
[nN
] );
184 if( xType
->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
)
186 Reference
< beans::XPropertySet
> xTypeProps( aTypes
[nN
], uno::UNO_QUERY
);
189 xTypeProps
->getPropertyValue( m_aPropertySetName
) >>= xPropSet
;
194 xPropSet
->setPropertyValue( rPropertyName
, rValue
);
196 uno::Any SAL_CALL
UpDownBarWrapper::getPropertyValue( const OUString
& rPropertyName
)
197 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
201 Reference
< beans::XPropertySet
> xPropSet(0);
203 Sequence
< Reference
< chart2::XChartType
> > aTypes(
204 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact
->getChart2Diagram() ) );
205 for( sal_Int32 nN
= 0; nN
< aTypes
.getLength(); nN
++ )
207 Reference
< chart2::XChartType
> xType( aTypes
[nN
] );
208 if( xType
->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
)
210 Reference
< beans::XPropertySet
> xTypeProps( aTypes
[nN
], uno::UNO_QUERY
);
213 xTypeProps
->getPropertyValue( m_aPropertySetName
) >>= xPropSet
;
218 aRet
= xPropSet
->getPropertyValue( rPropertyName
);
222 void SAL_CALL
UpDownBarWrapper::addPropertyChangeListener( const OUString
& /*aPropertyName*/, const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
223 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
225 OSL_FAIL("not implemented");
227 void SAL_CALL
UpDownBarWrapper::removePropertyChangeListener( const OUString
& /*aPropertyName*/, const uno::Reference
< beans::XPropertyChangeListener
>& /*aListener*/ )
228 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
230 OSL_FAIL("not implemented");
232 void SAL_CALL
UpDownBarWrapper::addVetoableChangeListener( const OUString
& /*PropertyName*/, const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
233 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
235 OSL_FAIL("not implemented");
237 void SAL_CALL
UpDownBarWrapper::removeVetoableChangeListener( const OUString
& /*PropertyName*/, const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
238 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
240 OSL_FAIL("not implemented");
244 //getPropertySetInfo() already declared in XPropertySet
245 void SAL_CALL
UpDownBarWrapper::setPropertyValues( const uno::Sequence
< OUString
>& rNameSeq
, const uno::Sequence
< uno::Any
>& rValueSeq
)
246 throw (beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
248 sal_Int32 nMinCount
= std::min( rValueSeq
.getLength(), rNameSeq
.getLength() );
249 for(sal_Int32 nN
=0; nN
<nMinCount
; nN
++)
251 OUString
aPropertyName( rNameSeq
[nN
] );
254 this->setPropertyValue( aPropertyName
, rValueSeq
[nN
] );
256 catch( const beans::UnknownPropertyException
& ex
)
258 ASSERT_EXCEPTION( ex
);
261 //todo: store unknown properties elsewhere
263 uno::Sequence
< uno::Any
> SAL_CALL
UpDownBarWrapper::getPropertyValues( const uno::Sequence
< OUString
>& rNameSeq
)
264 throw (uno::RuntimeException
, std::exception
)
266 Sequence
< Any
> aRetSeq
;
267 if( rNameSeq
.getLength() )
269 aRetSeq
.realloc( rNameSeq
.getLength() );
270 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
272 OUString
aPropertyName( rNameSeq
[nN
] );
273 aRetSeq
[nN
] = this->getPropertyValue( aPropertyName
);
278 void SAL_CALL
UpDownBarWrapper::addPropertiesChangeListener( const uno::Sequence
< OUString
>& /* aPropertyNames */, const uno::Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
279 throw (uno::RuntimeException
, std::exception
)
281 OSL_FAIL("not implemented");
283 void SAL_CALL
UpDownBarWrapper::removePropertiesChangeListener( const uno::Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
284 throw (uno::RuntimeException
, std::exception
)
286 OSL_FAIL("not implemented");
288 void SAL_CALL
UpDownBarWrapper::firePropertiesChangeEvent( const uno::Sequence
< OUString
>& /* aPropertyNames */, const uno::Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
289 throw (uno::RuntimeException
, std::exception
)
291 OSL_FAIL("not implemented");
295 beans::PropertyState SAL_CALL
UpDownBarWrapper::getPropertyState( const OUString
& rPropertyName
)
296 throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
298 uno::Any
aDefault( this->getPropertyDefault( rPropertyName
) );
299 uno::Any
aValue( this->getPropertyValue( rPropertyName
) );
301 if( aDefault
== aValue
)
302 return beans::PropertyState_DEFAULT_VALUE
;
304 return beans::PropertyState_DIRECT_VALUE
;
306 uno::Sequence
< beans::PropertyState
> SAL_CALL
UpDownBarWrapper::getPropertyStates( const uno::Sequence
< OUString
>& rNameSeq
)
307 throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
309 Sequence
< beans::PropertyState
> aRetSeq
;
310 if( rNameSeq
.getLength() )
312 aRetSeq
.realloc( rNameSeq
.getLength() );
313 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
315 OUString
aPropertyName( rNameSeq
[nN
] );
316 aRetSeq
[nN
] = this->getPropertyState( aPropertyName
);
321 void SAL_CALL
UpDownBarWrapper::setPropertyToDefault( const OUString
& rPropertyName
)
322 throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
324 this->setPropertyValue( rPropertyName
, this->getPropertyDefault(rPropertyName
) );
327 uno::Any SAL_CALL
UpDownBarWrapper::getPropertyDefault( const OUString
& rPropertyName
)
328 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
330 const tPropertyValueMap
& rStaticDefaults
= *StaticUpDownBarWrapperDefaults::get();
331 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( getInfoHelper().getHandleByName( rPropertyName
) ) );
332 if( aFound
== rStaticDefaults
.end() )
334 return (*aFound
).second
;
337 //XMultiPropertyStates
338 //getPropertyStates() already declared in XPropertyState
339 void SAL_CALL
UpDownBarWrapper::setAllPropertiesToDefault( )
340 throw (uno::RuntimeException
, std::exception
)
342 const Sequence
< beans::Property
>& rPropSeq
= *StaticUpDownBarWrapperPropertyArray::get();
343 for(sal_Int32 nN
=0; nN
<rPropSeq
.getLength(); nN
++)
345 OUString
aPropertyName( rPropSeq
[nN
].Name
);
346 this->setPropertyToDefault( aPropertyName
);
349 void SAL_CALL
UpDownBarWrapper::setPropertiesToDefault( const uno::Sequence
< OUString
>& rNameSeq
)
350 throw (beans::UnknownPropertyException
, uno::RuntimeException
, std::exception
)
352 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
354 OUString
aPropertyName( rNameSeq
[nN
] );
355 this->setPropertyToDefault( aPropertyName
);
358 uno::Sequence
< uno::Any
> SAL_CALL
UpDownBarWrapper::getPropertyDefaults( const uno::Sequence
< OUString
>& rNameSeq
)
359 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
, std::exception
)
361 Sequence
< Any
> aRetSeq
;
362 if( rNameSeq
.getLength() )
364 aRetSeq
.realloc( rNameSeq
.getLength() );
365 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
367 OUString
aPropertyName( rNameSeq
[nN
] );
368 aRetSeq
[nN
] = this->getPropertyDefault( aPropertyName
);
374 Sequence
< OUString
> UpDownBarWrapper::getSupportedServiceNames_Static()
376 Sequence
< OUString
> aServices( 4 );
377 aServices
[ 0 ] = "com.sun.star.chart.ChartArea";
378 aServices
[ 1 ] = "com.sun.star.drawing.LineProperties";
379 aServices
[ 2 ] = "com.sun.star.drawing.FillProperties";
380 aServices
[ 3 ] = "com.sun.star.xml.UserDefinedAttributesSupplier";
385 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
386 OUString SAL_CALL
UpDownBarWrapper::getImplementationName()
387 throw( css::uno::RuntimeException
, std::exception
)
389 return getImplementationName_Static();
392 OUString
UpDownBarWrapper::getImplementationName_Static()
394 return OUString(lcl_aServiceName
);
397 sal_Bool SAL_CALL
UpDownBarWrapper::supportsService( const OUString
& rServiceName
)
398 throw( css::uno::RuntimeException
, std::exception
)
400 return cppu::supportsService(this, rServiceName
);
403 css::uno::Sequence
< OUString
> SAL_CALL
UpDownBarWrapper::getSupportedServiceNames()
404 throw( css::uno::RuntimeException
, std::exception
)
406 return getSupportedServiceNames_Static();
409 } // namespace wrapper
412 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */