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: UpDownBarWrapper.cxx,v $
10 * $Revision: 1.4.44.1 $
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 "UpDownBarWrapper.hxx"
36 #include "Chart2ModelContact.hxx"
37 #include "DiagramHelper.hxx"
38 #include "servicenames_charttypes.hxx"
39 #include "ContainerHelper.hxx"
40 #include <com/sun/star/chart2/XChartType.hpp>
41 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
43 #include "LineProperties.hxx"
44 #include "FillProperties.hxx"
45 // #include "NamedProperties.hxx"
46 #include "UserDefinedProperties.hxx"
48 using namespace ::com::sun::star
;
49 using namespace ::com::sun::star::chart2
;
51 using ::com::sun::star::beans::Property
;
52 using ::osl::MutexGuard
;
53 using ::com::sun::star::uno::Reference
;
54 using ::com::sun::star::uno::Sequence
;
55 using ::com::sun::star::uno::Any
;
56 using ::rtl::OUString
;
60 static const OUString
lcl_aServiceName(
61 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.ChartArea" ));
63 const Sequence
< Property
> & lcl_GetPropertySequence()
65 static Sequence
< Property
> aPropSeq
;
68 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
69 if( 0 == aPropSeq
.getLength() )
72 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
74 ::chart::LineProperties::AddPropertiesToVector( aProperties
);
75 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
76 // ::chart::NamedProperties::AddPropertiesToVector( aProperties );
77 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
79 // and sort them for access via bsearch
80 ::std::sort( aProperties
.begin(), aProperties
.end(),
81 ::chart::PropertyNameLess() );
83 // transfer result to static Sequence
84 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
90 } // anonymous namespace
92 // --------------------------------------------------------------------------------
99 UpDownBarWrapper::UpDownBarWrapper(
100 bool bUp
, ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
101 : m_spChart2ModelContact( spChart2ModelContact
)
102 , m_aEventListenerContainer( m_aMutex
)
103 , m_aPropertySetName( bUp
? C2U("WhiteDay") : C2U("BlackDay") )
105 , m_pPropertyArrayHelper()
109 UpDownBarWrapper::~UpDownBarWrapper()
113 // ____ XComponent ____
114 void SAL_CALL
UpDownBarWrapper::dispose()
115 throw (uno::RuntimeException
)
117 Reference
< uno::XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
118 m_aEventListenerContainer
.disposeAndClear( lang::EventObject( xSource
) );
121 MutexGuard
aGuard( GetMutex());
126 void SAL_CALL
UpDownBarWrapper::addEventListener(
127 const Reference
< lang::XEventListener
>& xListener
)
128 throw (uno::RuntimeException
)
130 m_aEventListenerContainer
.addInterface( xListener
);
133 void SAL_CALL
UpDownBarWrapper::removeEventListener(
134 const Reference
< lang::XEventListener
>& aListener
)
135 throw (uno::RuntimeException
)
137 m_aEventListenerContainer
.removeInterface( aListener
);
140 ::cppu::IPropertyArrayHelper
& UpDownBarWrapper::getInfoHelper()
142 if(!m_pPropertyArrayHelper
.get())
145 ::osl::MutexGuard
aGuard( GetMutex() );
146 if(!m_pPropertyArrayHelper
.get())
148 sal_Bool bSorted
= sal_True
;
149 m_pPropertyArrayHelper
= ::boost::shared_ptr
< ::cppu::OPropertyArrayHelper
>( new ::cppu::OPropertyArrayHelper( lcl_GetPropertySequence(), bSorted
) );
153 return *m_pPropertyArrayHelper
.get();
157 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
UpDownBarWrapper::getPropertySetInfo()
158 throw (uno::RuntimeException
)
163 ::osl::MutexGuard
aGuard( GetMutex() );
165 m_xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
170 void SAL_CALL
UpDownBarWrapper::setPropertyValue( const ::rtl::OUString
& rPropertyName
, const uno::Any
& rValue
)
171 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
173 Reference
< beans::XPropertySet
> xPropSet(0);
175 Sequence
< Reference
< chart2::XChartType
> > aTypes(
176 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact
->getChart2Diagram() ) );
177 for( sal_Int32 nN
= 0; nN
< aTypes
.getLength(); nN
++ )
179 Reference
< chart2::XChartType
> xType( aTypes
[nN
] );
180 if( xType
->getChartType().equals(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
) )
182 Reference
< beans::XPropertySet
> xTypeProps( aTypes
[nN
], uno::UNO_QUERY
);
185 xTypeProps
->getPropertyValue( m_aPropertySetName
) >>= xPropSet
;
190 xPropSet
->setPropertyValue( rPropertyName
, rValue
);
192 uno::Any SAL_CALL
UpDownBarWrapper::getPropertyValue( const ::rtl::OUString
& rPropertyName
)
193 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
197 Reference
< beans::XPropertySet
> xPropSet(0);
199 Sequence
< Reference
< chart2::XChartType
> > aTypes(
200 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact
->getChart2Diagram() ) );
201 for( sal_Int32 nN
= 0; nN
< aTypes
.getLength(); nN
++ )
203 Reference
< chart2::XChartType
> xType( aTypes
[nN
] );
204 if( xType
->getChartType().equals(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
) )
206 Reference
< beans::XPropertySet
> xTypeProps( aTypes
[nN
], uno::UNO_QUERY
);
209 xTypeProps
->getPropertyValue( m_aPropertySetName
) >>= xPropSet
;
214 aRet
= xPropSet
->getPropertyValue( rPropertyName
);
218 void SAL_CALL
UpDownBarWrapper::addPropertyChangeListener( const ::rtl::OUString
& /*aPropertyName*/, const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
219 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
221 OSL_ENSURE(false,"not implemented");
223 void SAL_CALL
UpDownBarWrapper::removePropertyChangeListener( const ::rtl::OUString
& /*aPropertyName*/, const uno::Reference
< beans::XPropertyChangeListener
>& /*aListener*/ )
224 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
226 OSL_ENSURE(false,"not implemented");
228 void SAL_CALL
UpDownBarWrapper::addVetoableChangeListener( const ::rtl::OUString
& /*PropertyName*/, const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
229 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
231 OSL_ENSURE(false,"not implemented");
233 void SAL_CALL
UpDownBarWrapper::removeVetoableChangeListener( const ::rtl::OUString
& /*PropertyName*/, const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
234 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
236 OSL_ENSURE(false,"not implemented");
240 //getPropertySetInfo() already declared in XPropertySet
241 void SAL_CALL
UpDownBarWrapper::setPropertyValues( const uno::Sequence
< ::rtl::OUString
>& rNameSeq
, const uno::Sequence
< uno::Any
>& rValueSeq
)
242 throw (beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
244 bool bUnknownProperty
= false;
245 sal_Int32 nMinCount
= std::min( rValueSeq
.getLength(), rNameSeq
.getLength() );
246 for(sal_Int32 nN
=0; nN
<nMinCount
; nN
++)
248 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
251 this->setPropertyValue( aPropertyName
, rValueSeq
[nN
] );
253 catch( beans::UnknownPropertyException
& ex
)
255 ASSERT_EXCEPTION( ex
);
256 bUnknownProperty
= true;
259 //todo: store unknown properties elsewhere
260 // if( bUnknownProperty )
261 // throw beans::UnknownPropertyException();
263 uno::Sequence
< uno::Any
> SAL_CALL
UpDownBarWrapper::getPropertyValues( const uno::Sequence
< ::rtl::OUString
>& rNameSeq
)
264 throw (uno::RuntimeException
)
266 Sequence
< Any
> aRetSeq
;
267 if( rNameSeq
.getLength() )
269 aRetSeq
.realloc( rNameSeq
.getLength() );
270 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
272 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
273 aRetSeq
[nN
] = this->getPropertyValue( aPropertyName
);
278 void SAL_CALL
UpDownBarWrapper::addPropertiesChangeListener( const uno::Sequence
< ::rtl::OUString
>& /* aPropertyNames */, const uno::Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
279 throw (uno::RuntimeException
)
281 OSL_ENSURE(false,"not implemented");
283 void SAL_CALL
UpDownBarWrapper::removePropertiesChangeListener( const uno::Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
284 throw (uno::RuntimeException
)
286 OSL_ENSURE(false,"not implemented");
288 void SAL_CALL
UpDownBarWrapper::firePropertiesChangeEvent( const uno::Sequence
< ::rtl::OUString
>& /* aPropertyNames */, const uno::Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
289 throw (uno::RuntimeException
)
291 OSL_ENSURE(false,"not implemented");
295 beans::PropertyState SAL_CALL
UpDownBarWrapper::getPropertyState( const ::rtl::OUString
& rPropertyName
)
296 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
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
< ::rtl::OUString
>& rNameSeq
)
307 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
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 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
316 aRetSeq
[nN
] = this->getPropertyState( aPropertyName
);
321 void SAL_CALL
UpDownBarWrapper::setPropertyToDefault( const ::rtl::OUString
& rPropertyName
)
322 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
324 this->setPropertyValue( rPropertyName
, this->getPropertyDefault(rPropertyName
) );
326 uno::Any SAL_CALL
UpDownBarWrapper::getPropertyDefault( const ::rtl::OUString
& rPropertyName
)
327 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
329 static tPropertyValueMap aStaticDefaults
;
332 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
333 if( 0 == aStaticDefaults
.size() )
335 LineProperties::AddDefaultsToMap( aStaticDefaults
);
336 FillProperties::AddDefaultsToMap( aStaticDefaults
);
339 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
341 tPropertyValueMap::const_iterator
aFound(
342 aStaticDefaults
.find( nHandle
));
344 if( aFound
== aStaticDefaults
.end())
347 return (*aFound
).second
;
350 //XMultiPropertyStates
351 //getPropertyStates() already declared in XPropertyState
352 void SAL_CALL
UpDownBarWrapper::setAllPropertiesToDefault( )
353 throw (uno::RuntimeException
)
355 const Sequence
< beans::Property
>& rPropSeq
= lcl_GetPropertySequence();
356 for(sal_Int32 nN
=0; nN
<rPropSeq
.getLength(); nN
++)
358 ::rtl::OUString
aPropertyName( rPropSeq
[nN
].Name
);
359 this->setPropertyToDefault( aPropertyName
);
362 void SAL_CALL
UpDownBarWrapper::setPropertiesToDefault( const uno::Sequence
< ::rtl::OUString
>& rNameSeq
)
363 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
365 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
367 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
368 this->setPropertyToDefault( aPropertyName
);
371 uno::Sequence
< uno::Any
> SAL_CALL
UpDownBarWrapper::getPropertyDefaults( const uno::Sequence
< ::rtl::OUString
>& rNameSeq
)
372 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
374 Sequence
< Any
> aRetSeq
;
375 if( rNameSeq
.getLength() )
377 aRetSeq
.realloc( rNameSeq
.getLength() );
378 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
380 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
381 aRetSeq
[nN
] = this->getPropertyDefault( aPropertyName
);
388 // ================================================================================
390 Sequence
< OUString
> UpDownBarWrapper::getSupportedServiceNames_Static()
392 Sequence
< OUString
> aServices( 4 );
393 aServices
[ 0 ] = ::rtl::OUString::createFromAscii( "com.sun.star.chart.ChartArea" );
394 aServices
[ 1 ] = ::rtl::OUString::createFromAscii( "com.sun.star.drawing.LineProperties" );
395 aServices
[ 2 ] = ::rtl::OUString::createFromAscii( "com.sun.star.drawing.FillProperties" );
396 aServices
[ 3 ] = ::rtl::OUString::createFromAscii( "com.sun.star.xml.UserDefinedAttributeSupplier" );
401 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
402 APPHELPER_XSERVICEINFO_IMPL( UpDownBarWrapper
, lcl_aServiceName
);
404 } // namespace wrapper