merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / UpDownBarWrapper.cxx
blob338131c4f973c3125f359285cafad19facaa1bf0
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 "UpDownBarWrapper.hxx"
32 #include "macros.hxx"
33 #include "Chart2ModelContact.hxx"
34 #include "DiagramHelper.hxx"
35 #include "servicenames_charttypes.hxx"
36 #include "ContainerHelper.hxx"
37 #include <com/sun/star/chart2/XChartType.hpp>
38 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
40 #include "LineProperties.hxx"
41 #include "FillProperties.hxx"
42 // #include "NamedProperties.hxx"
43 #include "UserDefinedProperties.hxx"
45 using namespace ::com::sun::star;
46 using namespace ::com::sun::star::chart2;
48 using ::com::sun::star::beans::Property;
49 using ::osl::MutexGuard;
50 using ::com::sun::star::uno::Reference;
51 using ::com::sun::star::uno::Sequence;
52 using ::com::sun::star::uno::Any;
53 using ::rtl::OUString;
55 namespace
57 static const OUString lcl_aServiceName(
58 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.ChartArea" ));
60 const Sequence< Property > & lcl_GetPropertySequence()
62 static Sequence< Property > aPropSeq;
64 // /--
65 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
66 if( 0 == aPropSeq.getLength() )
68 // get properties
69 ::std::vector< ::com::sun::star::beans::Property > aProperties;
71 ::chart::LineProperties::AddPropertiesToVector( aProperties );
72 ::chart::FillProperties::AddPropertiesToVector( aProperties );
73 // ::chart::NamedProperties::AddPropertiesToVector( aProperties );
74 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
76 // and sort them for access via bsearch
77 ::std::sort( aProperties.begin(), aProperties.end(),
78 ::chart::PropertyNameLess() );
80 // transfer result to static Sequence
81 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
84 return aPropSeq;
87 } // anonymous namespace
89 // --------------------------------------------------------------------------------
91 namespace chart
93 namespace wrapper
96 UpDownBarWrapper::UpDownBarWrapper(
97 bool bUp, ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
98 : m_spChart2ModelContact( spChart2ModelContact )
99 , m_aEventListenerContainer( m_aMutex )
100 , m_aPropertySetName( bUp ? C2U("WhiteDay") : C2U("BlackDay") )
101 , m_xInfo(0)
102 , m_pPropertyArrayHelper()
106 UpDownBarWrapper::~UpDownBarWrapper()
110 // ____ XComponent ____
111 void SAL_CALL UpDownBarWrapper::dispose()
112 throw (uno::RuntimeException)
114 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
115 m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
117 // /--
118 MutexGuard aGuard( GetMutex());
119 m_xInfo.clear();
120 // \--
123 void SAL_CALL UpDownBarWrapper::addEventListener(
124 const Reference< lang::XEventListener >& xListener )
125 throw (uno::RuntimeException)
127 m_aEventListenerContainer.addInterface( xListener );
130 void SAL_CALL UpDownBarWrapper::removeEventListener(
131 const Reference< lang::XEventListener >& aListener )
132 throw (uno::RuntimeException)
134 m_aEventListenerContainer.removeInterface( aListener );
137 ::cppu::IPropertyArrayHelper& UpDownBarWrapper::getInfoHelper()
139 if(!m_pPropertyArrayHelper.get())
141 // /--
142 ::osl::MutexGuard aGuard( GetMutex() );
143 if(!m_pPropertyArrayHelper.get())
145 sal_Bool bSorted = sal_True;
146 m_pPropertyArrayHelper = ::boost::shared_ptr< ::cppu::OPropertyArrayHelper >( new ::cppu::OPropertyArrayHelper( lcl_GetPropertySequence(), bSorted ) );
148 // \--
150 return *m_pPropertyArrayHelper.get();
153 //XPropertySet
154 uno::Reference< beans::XPropertySetInfo > SAL_CALL UpDownBarWrapper::getPropertySetInfo()
155 throw (uno::RuntimeException)
157 if( !m_xInfo.is() )
159 // /--
160 ::osl::MutexGuard aGuard( GetMutex() );
161 if( !m_xInfo.is() )
162 m_xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
163 // \--
165 return m_xInfo;
167 void SAL_CALL UpDownBarWrapper::setPropertyValue( const ::rtl::OUString& rPropertyName, const uno::Any& rValue )
168 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
170 Reference< beans::XPropertySet > xPropSet(0);
172 Sequence< Reference< chart2::XChartType > > aTypes(
173 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
174 for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
176 Reference< chart2::XChartType > xType( aTypes[nN] );
177 if( xType->getChartType().equals(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
179 Reference< beans::XPropertySet > xTypeProps( aTypes[nN], uno::UNO_QUERY );
180 if(xTypeProps.is())
182 xTypeProps->getPropertyValue( m_aPropertySetName ) >>= xPropSet;
186 if(xPropSet.is())
187 xPropSet->setPropertyValue( rPropertyName, rValue );
189 uno::Any SAL_CALL UpDownBarWrapper::getPropertyValue( const ::rtl::OUString& rPropertyName )
190 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
192 Any aRet;
194 Reference< beans::XPropertySet > xPropSet(0);
196 Sequence< Reference< chart2::XChartType > > aTypes(
197 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
198 for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
200 Reference< chart2::XChartType > xType( aTypes[nN] );
201 if( xType->getChartType().equals(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
203 Reference< beans::XPropertySet > xTypeProps( aTypes[nN], uno::UNO_QUERY );
204 if(xTypeProps.is())
206 xTypeProps->getPropertyValue( m_aPropertySetName ) >>= xPropSet;
210 if(xPropSet.is())
211 aRet = xPropSet->getPropertyValue( rPropertyName );
212 return aRet;
215 void SAL_CALL UpDownBarWrapper::addPropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
216 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
218 OSL_ENSURE(false,"not implemented");
220 void SAL_CALL UpDownBarWrapper::removePropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
221 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
223 OSL_ENSURE(false,"not implemented");
225 void SAL_CALL UpDownBarWrapper::addVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
226 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
228 OSL_ENSURE(false,"not implemented");
230 void SAL_CALL UpDownBarWrapper::removeVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
231 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
233 OSL_ENSURE(false,"not implemented");
236 //XMultiPropertySet
237 //getPropertySetInfo() already declared in XPropertySet
238 void SAL_CALL UpDownBarWrapper::setPropertyValues( const uno::Sequence< ::rtl::OUString >& rNameSeq, const uno::Sequence< uno::Any >& rValueSeq )
239 throw (beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
241 bool bUnknownProperty = false;
242 sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() );
243 for(sal_Int32 nN=0; nN<nMinCount; nN++)
245 ::rtl::OUString aPropertyName( rNameSeq[nN] );
248 this->setPropertyValue( aPropertyName, rValueSeq[nN] );
250 catch( beans::UnknownPropertyException& ex )
252 ASSERT_EXCEPTION( ex );
253 bUnknownProperty = true;
256 //todo: store unknown properties elsewhere
257 // if( bUnknownProperty )
258 // throw beans::UnknownPropertyException();
260 uno::Sequence< uno::Any > SAL_CALL UpDownBarWrapper::getPropertyValues( const uno::Sequence< ::rtl::OUString >& rNameSeq )
261 throw (uno::RuntimeException)
263 Sequence< Any > aRetSeq;
264 if( rNameSeq.getLength() )
266 aRetSeq.realloc( rNameSeq.getLength() );
267 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
269 ::rtl::OUString aPropertyName( rNameSeq[nN] );
270 aRetSeq[nN] = this->getPropertyValue( aPropertyName );
273 return aRetSeq;
275 void SAL_CALL UpDownBarWrapper::addPropertiesChangeListener( const uno::Sequence< ::rtl::OUString >& /* aPropertyNames */, const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
276 throw (uno::RuntimeException)
278 OSL_ENSURE(false,"not implemented");
280 void SAL_CALL UpDownBarWrapper::removePropertiesChangeListener( const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
281 throw (uno::RuntimeException)
283 OSL_ENSURE(false,"not implemented");
285 void SAL_CALL UpDownBarWrapper::firePropertiesChangeEvent( const uno::Sequence< ::rtl::OUString >& /* aPropertyNames */, const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
286 throw (uno::RuntimeException)
288 OSL_ENSURE(false,"not implemented");
291 //XPropertyState
292 beans::PropertyState SAL_CALL UpDownBarWrapper::getPropertyState( const ::rtl::OUString& rPropertyName )
293 throw (beans::UnknownPropertyException, uno::RuntimeException)
295 uno::Any aDefault( this->getPropertyDefault( rPropertyName ) );
296 uno::Any aValue( this->getPropertyValue( rPropertyName ) );
298 if( aDefault == aValue )
299 return beans::PropertyState_DEFAULT_VALUE;
301 return beans::PropertyState_DIRECT_VALUE;
303 uno::Sequence< beans::PropertyState > SAL_CALL UpDownBarWrapper::getPropertyStates( const uno::Sequence< ::rtl::OUString >& rNameSeq )
304 throw (beans::UnknownPropertyException, uno::RuntimeException)
306 Sequence< beans::PropertyState > aRetSeq;
307 if( rNameSeq.getLength() )
309 aRetSeq.realloc( rNameSeq.getLength() );
310 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
312 ::rtl::OUString aPropertyName( rNameSeq[nN] );
313 aRetSeq[nN] = this->getPropertyState( aPropertyName );
316 return aRetSeq;
318 void SAL_CALL UpDownBarWrapper::setPropertyToDefault( const ::rtl::OUString& rPropertyName )
319 throw (beans::UnknownPropertyException, uno::RuntimeException)
321 this->setPropertyValue( rPropertyName, this->getPropertyDefault(rPropertyName) );
323 uno::Any SAL_CALL UpDownBarWrapper::getPropertyDefault( const ::rtl::OUString& rPropertyName )
324 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
326 static tPropertyValueMap aStaticDefaults;
328 // /--
329 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
330 if( 0 == aStaticDefaults.size() )
332 LineProperties::AddDefaultsToMap( aStaticDefaults );
333 FillProperties::AddDefaultsToMap( aStaticDefaults );
336 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
338 tPropertyValueMap::const_iterator aFound(
339 aStaticDefaults.find( nHandle ));
341 if( aFound == aStaticDefaults.end())
342 return uno::Any();
344 return (*aFound).second;
347 //XMultiPropertyStates
348 //getPropertyStates() already declared in XPropertyState
349 void SAL_CALL UpDownBarWrapper::setAllPropertiesToDefault( )
350 throw (uno::RuntimeException)
352 const Sequence< beans::Property >& rPropSeq = lcl_GetPropertySequence();
353 for(sal_Int32 nN=0; nN<rPropSeq.getLength(); nN++)
355 ::rtl::OUString aPropertyName( rPropSeq[nN].Name );
356 this->setPropertyToDefault( aPropertyName );
359 void SAL_CALL UpDownBarWrapper::setPropertiesToDefault( const uno::Sequence< ::rtl::OUString >& rNameSeq )
360 throw (beans::UnknownPropertyException, uno::RuntimeException)
362 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
364 ::rtl::OUString aPropertyName( rNameSeq[nN] );
365 this->setPropertyToDefault( aPropertyName );
368 uno::Sequence< uno::Any > SAL_CALL UpDownBarWrapper::getPropertyDefaults( const uno::Sequence< ::rtl::OUString >& rNameSeq )
369 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
371 Sequence< Any > aRetSeq;
372 if( rNameSeq.getLength() )
374 aRetSeq.realloc( rNameSeq.getLength() );
375 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
377 ::rtl::OUString aPropertyName( rNameSeq[nN] );
378 aRetSeq[nN] = this->getPropertyDefault( aPropertyName );
381 return aRetSeq;
385 // ================================================================================
387 Sequence< OUString > UpDownBarWrapper::getSupportedServiceNames_Static()
389 Sequence< OUString > aServices( 4 );
390 aServices[ 0 ] = ::rtl::OUString::createFromAscii( "com.sun.star.chart.ChartArea" );
391 aServices[ 1 ] = ::rtl::OUString::createFromAscii( "com.sun.star.drawing.LineProperties" );
392 aServices[ 2 ] = ::rtl::OUString::createFromAscii( "com.sun.star.drawing.FillProperties" );
393 aServices[ 3 ] = ::rtl::OUString::createFromAscii( "com.sun.star.xml.UserDefinedAttributeSupplier" );
395 return aServices;
398 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
399 APPHELPER_XSERVICEINFO_IMPL( UpDownBarWrapper, lcl_aServiceName );
401 } // namespace wrapper
402 } // namespace chart