Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / UpDownBarWrapper.cxx
blob0343c29530a871a81adb74cc9f3ac4eafc069c58
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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"
21 #include "Chart2ModelContact.hxx"
22 #include <DiagramHelper.hxx>
23 #include <servicenames_charttypes.hxx>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <cppuhelper/propshlp.hxx>
26 #include <com/sun/star/chart2/XChartType.hpp>
27 #include <comphelper/sequence.hxx>
29 #include <LinePropertiesHelper.hxx>
30 #include <FillProperties.hxx>
31 #include <UserDefinedProperties.hxx>
32 #include <tools/diagnose_ex.h>
34 using namespace ::com::sun::star;
35 using namespace ::com::sun::star::chart2;
37 using ::com::sun::star::beans::Property;
38 using ::com::sun::star::uno::Reference;
39 using ::com::sun::star::uno::Sequence;
40 using ::com::sun::star::uno::Any;
42 namespace
45 struct StaticUpDownBarWrapperPropertyArray_Initializer
47 Sequence< Property >* operator()()
49 static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
50 return &aPropSeq;
53 private:
54 static Sequence< Property > lcl_GetPropertySequence()
56 std::vector< css::beans::Property > aProperties;
58 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
59 ::chart::FillProperties::AddPropertiesToVector( aProperties );
60 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
62 std::sort( aProperties.begin(), aProperties.end(),
63 ::chart::PropertyNameLess() );
65 return comphelper::containerToSequence( aProperties );
69 struct StaticUpDownBarWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticUpDownBarWrapperPropertyArray_Initializer >
73 struct StaticUpDownBarWrapperInfoHelper_Initializer
75 ::cppu::OPropertyArrayHelper* operator()()
77 static ::cppu::OPropertyArrayHelper aPropHelper( *StaticUpDownBarWrapperPropertyArray::get() );
78 return &aPropHelper;
82 struct StaticUpDownBarWrapperInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticUpDownBarWrapperInfoHelper_Initializer >
86 struct StaticUpDownBarWrapperInfo_Initializer
88 uno::Reference< beans::XPropertySetInfo >* operator()()
90 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
91 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticUpDownBarWrapperInfoHelper::get() ) );
92 return &xPropertySetInfo;
96 struct StaticUpDownBarWrapperInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticUpDownBarWrapperInfo_Initializer >
100 struct StaticUpDownBarWrapperDefaults_Initializer
102 ::chart::tPropertyValueMap* operator()()
104 static ::chart::tPropertyValueMap aStaticDefaults;
105 lcl_AddDefaultsToMap( aStaticDefaults );
106 return &aStaticDefaults;
108 private:
109 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
111 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap );
112 ::chart::FillProperties::AddDefaultsToMap( rOutMap );
116 struct StaticUpDownBarWrapperDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticUpDownBarWrapperDefaults_Initializer >
120 } // anonymous namespace
122 namespace chart
124 namespace wrapper
127 UpDownBarWrapper::UpDownBarWrapper(
128 bool bUp, const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact)
129 : m_spChart2ModelContact( spChart2ModelContact )
130 , m_aEventListenerContainer( m_aMutex )
131 , m_aPropertySetName( bUp ? OUString( "WhiteDay" ) : OUString( "BlackDay" ))
135 UpDownBarWrapper::~UpDownBarWrapper()
139 // ____ XComponent ____
140 void SAL_CALL UpDownBarWrapper::dispose()
142 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
143 m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
146 void SAL_CALL UpDownBarWrapper::addEventListener(
147 const Reference< lang::XEventListener >& xListener )
149 m_aEventListenerContainer.addInterface( xListener );
152 void SAL_CALL UpDownBarWrapper::removeEventListener(
153 const Reference< lang::XEventListener >& aListener )
155 m_aEventListenerContainer.removeInterface( aListener );
158 //XPropertySet
159 uno::Reference< beans::XPropertySetInfo > SAL_CALL UpDownBarWrapper::getPropertySetInfo()
161 return *StaticUpDownBarWrapperInfo::get();
163 void SAL_CALL UpDownBarWrapper::setPropertyValue( const OUString& rPropertyName, const uno::Any& rValue )
165 Reference< beans::XPropertySet > xPropSet;
167 Sequence< Reference< chart2::XChartType > > aTypes(
168 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
169 for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
171 Reference< chart2::XChartType > xType( aTypes[nN] );
172 if( xType->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK )
174 Reference< beans::XPropertySet > xTypeProps( aTypes[nN], uno::UNO_QUERY );
175 if(xTypeProps.is())
177 xTypeProps->getPropertyValue( m_aPropertySetName ) >>= xPropSet;
181 if(xPropSet.is())
182 xPropSet->setPropertyValue( rPropertyName, rValue );
184 uno::Any SAL_CALL UpDownBarWrapper::getPropertyValue( const OUString& rPropertyName )
186 Any aRet;
188 Reference< beans::XPropertySet > xPropSet;
190 Sequence< Reference< chart2::XChartType > > aTypes(
191 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
192 for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
194 Reference< chart2::XChartType > xType( aTypes[nN] );
195 if( xType->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK )
197 Reference< beans::XPropertySet > xTypeProps( aTypes[nN], uno::UNO_QUERY );
198 if(xTypeProps.is())
200 xTypeProps->getPropertyValue( m_aPropertySetName ) >>= xPropSet;
204 if(xPropSet.is())
205 aRet = xPropSet->getPropertyValue( rPropertyName );
206 return aRet;
209 void SAL_CALL UpDownBarWrapper::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
211 OSL_FAIL("not implemented");
213 void SAL_CALL UpDownBarWrapper::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
215 OSL_FAIL("not implemented");
217 void SAL_CALL UpDownBarWrapper::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
219 OSL_FAIL("not implemented");
221 void SAL_CALL UpDownBarWrapper::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
223 OSL_FAIL("not implemented");
226 //XMultiPropertySet
227 //getPropertySetInfo() already declared in XPropertySet
228 void SAL_CALL UpDownBarWrapper::setPropertyValues( const uno::Sequence< OUString >& rNameSeq, const uno::Sequence< uno::Any >& rValueSeq )
230 sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() );
231 for(sal_Int32 nN=0; nN<nMinCount; nN++)
233 OUString aPropertyName( rNameSeq[nN] );
236 setPropertyValue( aPropertyName, rValueSeq[nN] );
238 catch( const beans::UnknownPropertyException& )
240 DBG_UNHANDLED_EXCEPTION("chart2");
243 //todo: store unknown properties elsewhere
245 uno::Sequence< uno::Any > SAL_CALL UpDownBarWrapper::getPropertyValues( const uno::Sequence< OUString >& rNameSeq )
247 Sequence< Any > aRetSeq;
248 if( rNameSeq.hasElements() )
250 aRetSeq.realloc( rNameSeq.getLength() );
251 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
253 OUString aPropertyName( rNameSeq[nN] );
254 aRetSeq[nN] = getPropertyValue( aPropertyName );
257 return aRetSeq;
259 void SAL_CALL UpDownBarWrapper::addPropertiesChangeListener( const uno::Sequence< OUString >& /* aPropertyNames */, const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
261 OSL_FAIL("not implemented");
263 void SAL_CALL UpDownBarWrapper::removePropertiesChangeListener( const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
265 OSL_FAIL("not implemented");
267 void SAL_CALL UpDownBarWrapper::firePropertiesChangeEvent( const uno::Sequence< OUString >& /* aPropertyNames */, const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
269 OSL_FAIL("not implemented");
272 //XPropertyState
273 beans::PropertyState SAL_CALL UpDownBarWrapper::getPropertyState( const OUString& rPropertyName )
275 uno::Any aDefault( getPropertyDefault( rPropertyName ) );
276 uno::Any aValue( getPropertyValue( rPropertyName ) );
278 if( aDefault == aValue )
279 return beans::PropertyState_DEFAULT_VALUE;
281 return beans::PropertyState_DIRECT_VALUE;
283 uno::Sequence< beans::PropertyState > SAL_CALL UpDownBarWrapper::getPropertyStates( const uno::Sequence< OUString >& rNameSeq )
285 Sequence< beans::PropertyState > aRetSeq;
286 if( rNameSeq.hasElements() )
288 aRetSeq.realloc( rNameSeq.getLength() );
289 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
291 OUString aPropertyName( rNameSeq[nN] );
292 aRetSeq[nN] = getPropertyState( aPropertyName );
295 return aRetSeq;
297 void SAL_CALL UpDownBarWrapper::setPropertyToDefault( const OUString& rPropertyName )
299 setPropertyValue( rPropertyName, getPropertyDefault(rPropertyName) );
302 uno::Any SAL_CALL UpDownBarWrapper::getPropertyDefault( const OUString& rPropertyName )
304 const tPropertyValueMap& rStaticDefaults = *StaticUpDownBarWrapperDefaults::get();
305 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( StaticUpDownBarWrapperInfoHelper::get()->getHandleByName( rPropertyName ) ) );
306 if( aFound == rStaticDefaults.end() )
307 return uno::Any();
308 return (*aFound).second;
311 //XMultiPropertyStates
312 //getPropertyStates() already declared in XPropertyState
313 void SAL_CALL UpDownBarWrapper::setAllPropertiesToDefault( )
315 const Sequence< beans::Property >& rPropSeq = *StaticUpDownBarWrapperPropertyArray::get();
316 for(sal_Int32 nN=0; nN<rPropSeq.getLength(); nN++)
318 OUString aPropertyName( rPropSeq[nN].Name );
319 setPropertyToDefault( aPropertyName );
322 void SAL_CALL UpDownBarWrapper::setPropertiesToDefault( const uno::Sequence< OUString >& rNameSeq )
324 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
326 OUString aPropertyName( rNameSeq[nN] );
327 setPropertyToDefault( aPropertyName );
330 uno::Sequence< uno::Any > SAL_CALL UpDownBarWrapper::getPropertyDefaults( const uno::Sequence< OUString >& rNameSeq )
332 Sequence< Any > aRetSeq;
333 if( rNameSeq.hasElements() )
335 aRetSeq.realloc( rNameSeq.getLength() );
336 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
338 OUString aPropertyName( rNameSeq[nN] );
339 aRetSeq[nN] = getPropertyDefault( aPropertyName );
342 return aRetSeq;
345 OUString SAL_CALL UpDownBarWrapper::getImplementationName()
347 return "com.sun.star.comp.chart.ChartArea";
350 sal_Bool SAL_CALL UpDownBarWrapper::supportsService( const OUString& rServiceName )
352 return cppu::supportsService(this, rServiceName);
355 css::uno::Sequence< OUString > SAL_CALL UpDownBarWrapper::getSupportedServiceNames()
357 return {
358 "com.sun.star.chart.ChartArea",
359 "com.sun.star.drawing.LineProperties",
360 "com.sun.star.drawing.FillProperties",
361 "com.sun.star.xml.UserDefinedAttributesSupplier"
365 } // namespace wrapper
366 } // namespace chart
368 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */