Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / MinMaxLineWrapper.cxx
blobf38ff93c9bef7315b91c421316feddf495c88980
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 "MinMaxLineWrapper.hxx"
21 #include "Chart2ModelContact.hxx"
22 #include <DiagramHelper.hxx>
23 #include <servicenames_charttypes.hxx>
24 #include <cppuhelper/propshlp.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <com/sun/star/chart2/XChartType.hpp>
27 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
28 #include <com/sun/star/drawing/LineJoint.hpp>
29 #include <comphelper/sequence.hxx>
31 #include <LinePropertiesHelper.hxx>
32 #include <UserDefinedProperties.hxx>
33 #include <tools/diagnose_ex.h>
35 using namespace ::com::sun::star;
36 using namespace ::com::sun::star::chart2;
38 using ::com::sun::star::beans::Property;
39 using ::com::sun::star::uno::Reference;
40 using ::com::sun::star::uno::Sequence;
41 using ::com::sun::star::uno::Any;
43 namespace
46 struct StaticMinMaxLineWrapperDefaults_Initializer
48 ::chart::tPropertyValueMap* operator()()
50 static ::chart::tPropertyValueMap aStaticDefaults;
51 ::chart::LinePropertiesHelper::AddDefaultsToMap( aStaticDefaults );
52 return &aStaticDefaults;
56 struct StaticMinMaxLineWrapperDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticMinMaxLineWrapperDefaults_Initializer >
60 struct StaticMinMaxLineWrapperPropertyArray_Initializer
62 Sequence< Property >* operator()()
64 static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
65 return &aPropSeq;
68 private:
69 static Sequence< Property > lcl_GetPropertySequence()
71 std::vector< css::beans::Property > aProperties;
73 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
74 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
76 std::sort( aProperties.begin(), aProperties.end(),
77 ::chart::PropertyNameLess() );
79 return comphelper::containerToSequence( aProperties );
83 struct StaticMinMaxLineWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticMinMaxLineWrapperPropertyArray_Initializer >
87 struct StaticMinMaxLineWrapperInfoHelper_Initializer
89 ::cppu::OPropertyArrayHelper* operator()()
91 static ::cppu::OPropertyArrayHelper aPropHelper( *StaticMinMaxLineWrapperPropertyArray::get() );
92 return &aPropHelper;
96 struct StaticMinMaxLineWrapperInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticMinMaxLineWrapperInfoHelper_Initializer >
100 struct StaticMinMaxLineWrapperInfo_Initializer
102 uno::Reference< beans::XPropertySetInfo >* operator()()
104 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
105 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticMinMaxLineWrapperInfoHelper::get() ) );
106 return &xPropertySetInfo;
110 struct StaticMinMaxLineWrapperInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticMinMaxLineWrapperInfo_Initializer >
114 } // anonymous namespace
116 namespace chart
118 namespace wrapper
121 MinMaxLineWrapper::MinMaxLineWrapper(const std::shared_ptr<Chart2ModelContact>& spChart2ModelContact)
122 : m_spChart2ModelContact( spChart2ModelContact )
123 , m_aEventListenerContainer( m_aMutex )
124 , m_aWrappedLineJointProperty( "LineJoint", uno::Any( drawing::LineJoint_NONE ))
128 MinMaxLineWrapper::~MinMaxLineWrapper()
132 // ____ XComponent ____
133 void SAL_CALL MinMaxLineWrapper::dispose()
135 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
136 m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
139 void SAL_CALL MinMaxLineWrapper::addEventListener(
140 const Reference< lang::XEventListener >& xListener )
142 m_aEventListenerContainer.addInterface( xListener );
145 void SAL_CALL MinMaxLineWrapper::removeEventListener(
146 const Reference< lang::XEventListener >& aListener )
148 m_aEventListenerContainer.removeInterface( aListener );
151 //XPropertySet
152 uno::Reference< beans::XPropertySetInfo > SAL_CALL MinMaxLineWrapper::getPropertySetInfo()
154 return *StaticMinMaxLineWrapperInfo::get();
157 void SAL_CALL MinMaxLineWrapper::setPropertyValue( const OUString& rPropertyName, const uno::Any& rValue )
159 Reference< beans::XPropertySet > xPropSet;
161 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
162 Sequence< Reference< chart2::XChartType > > aTypes(
163 ::chart::DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
164 for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
166 Reference< chart2::XChartType > xType( aTypes[nN] );
167 if( xType->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK )
169 Reference< chart2::XDataSeriesContainer > xSeriesContainer(xType,uno::UNO_QUERY);
170 if( xSeriesContainer.is() )
172 Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesContainer->getDataSeries() );
173 if(aSeriesSeq.hasElements())
175 xPropSet.set(aSeriesSeq[0],uno::UNO_QUERY);
176 if(xPropSet.is())
178 if( rPropertyName == "LineColor" )
179 xPropSet->setPropertyValue( "Color", rValue );
180 else if( rPropertyName == "LineTransparence" )
181 xPropSet->setPropertyValue( "Transparency", rValue );
182 else if( rPropertyName == m_aWrappedLineJointProperty.getOuterName() )
183 m_aWrappedLineJointProperty.setPropertyValue( rValue, xPropSet );
184 else
185 xPropSet->setPropertyValue( rPropertyName, rValue );
186 return;
193 uno::Any SAL_CALL MinMaxLineWrapper::getPropertyValue( const OUString& rPropertyName )
195 Any aRet;
197 Reference< beans::XPropertySet > xPropSet;
199 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
200 Sequence< Reference< chart2::XChartType > > aTypes(
201 ::chart::DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
202 for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
204 Reference< chart2::XChartType > xType( aTypes[nN] );
205 if( xType->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK )
207 Reference< chart2::XDataSeriesContainer > xSeriesContainer(xType,uno::UNO_QUERY);
208 if( xSeriesContainer.is() )
210 Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesContainer->getDataSeries() );
211 if(aSeriesSeq.hasElements())
213 xPropSet.set(aSeriesSeq[0],uno::UNO_QUERY);
214 break;
219 if(xPropSet.is())
221 if( rPropertyName == "LineColor" )
222 aRet = xPropSet->getPropertyValue( "Color" );
223 else if( rPropertyName == "LineTransparence" )
224 aRet = xPropSet->getPropertyValue( "Transparency" );
225 else if( rPropertyName == m_aWrappedLineJointProperty.getOuterName() )
226 aRet = m_aWrappedLineJointProperty.getPropertyValue( xPropSet );
227 else
228 aRet = xPropSet->getPropertyValue( rPropertyName );
231 return aRet;
234 void SAL_CALL MinMaxLineWrapper::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
236 OSL_FAIL("not implemented");
238 void SAL_CALL MinMaxLineWrapper::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
240 OSL_FAIL("not implemented");
242 void SAL_CALL MinMaxLineWrapper::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
244 OSL_FAIL("not implemented");
246 void SAL_CALL MinMaxLineWrapper::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
248 OSL_FAIL("not implemented");
251 //XMultiPropertySet
252 //getPropertySetInfo() already declared in XPropertySet
253 void SAL_CALL MinMaxLineWrapper::setPropertyValues( const uno::Sequence< OUString >& rNameSeq, const uno::Sequence< uno::Any >& rValueSeq )
255 sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() );
256 for(sal_Int32 nN=0; nN<nMinCount; nN++)
258 OUString aPropertyName( rNameSeq[nN] );
261 setPropertyValue( aPropertyName, rValueSeq[nN] );
263 catch( const beans::UnknownPropertyException& )
265 DBG_UNHANDLED_EXCEPTION("chart2");
268 //todo: store unknown properties elsewhere
270 uno::Sequence< uno::Any > SAL_CALL MinMaxLineWrapper::getPropertyValues( const uno::Sequence< OUString >& rNameSeq )
272 Sequence< Any > aRetSeq;
273 if( rNameSeq.hasElements() )
275 aRetSeq.realloc( rNameSeq.getLength() );
276 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
278 OUString aPropertyName( rNameSeq[nN] );
279 aRetSeq[nN] = getPropertyValue( aPropertyName );
282 return aRetSeq;
284 void SAL_CALL MinMaxLineWrapper::addPropertiesChangeListener(
285 const uno::Sequence< OUString >& /* aPropertyNames */,
286 const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
288 OSL_FAIL("not implemented");
290 void SAL_CALL MinMaxLineWrapper::removePropertiesChangeListener(
291 const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
293 OSL_FAIL("not implemented");
295 void SAL_CALL MinMaxLineWrapper::firePropertiesChangeEvent(
296 const uno::Sequence< OUString >& /* aPropertyNames */,
297 const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
299 OSL_FAIL("not implemented");
302 //XPropertyState
303 beans::PropertyState SAL_CALL MinMaxLineWrapper::getPropertyState( const OUString& rPropertyName )
305 if( rPropertyName == m_aWrappedLineJointProperty.getOuterName() )
306 return beans::PropertyState_DEFAULT_VALUE;
308 uno::Any aDefault( getPropertyDefault( rPropertyName ) );
309 uno::Any aValue( getPropertyValue( rPropertyName ) );
311 if( aDefault == aValue )
312 return beans::PropertyState_DEFAULT_VALUE;
314 return beans::PropertyState_DIRECT_VALUE;
316 uno::Sequence< beans::PropertyState > SAL_CALL MinMaxLineWrapper::getPropertyStates( const uno::Sequence< OUString >& rNameSeq )
318 Sequence< beans::PropertyState > aRetSeq;
319 if( rNameSeq.hasElements() )
321 aRetSeq.realloc( rNameSeq.getLength() );
322 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
324 OUString aPropertyName( rNameSeq[nN] );
325 aRetSeq[nN] = getPropertyState( aPropertyName );
328 return aRetSeq;
330 void SAL_CALL MinMaxLineWrapper::setPropertyToDefault( const OUString& rPropertyName )
332 setPropertyValue( rPropertyName, getPropertyDefault(rPropertyName) );
335 uno::Any SAL_CALL MinMaxLineWrapper::getPropertyDefault( const OUString& rPropertyName )
337 const tPropertyValueMap& rStaticDefaults = *StaticMinMaxLineWrapperDefaults::get();
338 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( StaticMinMaxLineWrapperInfoHelper::get()->getHandleByName( rPropertyName ) ) );
339 if( aFound == rStaticDefaults.end() )
340 return uno::Any();
341 return (*aFound).second;
344 //XMultiPropertyStates
345 //getPropertyStates() already declared in XPropertyState
346 void SAL_CALL MinMaxLineWrapper::setAllPropertiesToDefault( )
348 const Sequence< beans::Property >& rPropSeq = *StaticMinMaxLineWrapperPropertyArray::get();
349 for(sal_Int32 nN=0; nN<rPropSeq.getLength(); nN++)
351 OUString aPropertyName( rPropSeq[nN].Name );
352 setPropertyToDefault( aPropertyName );
355 void SAL_CALL MinMaxLineWrapper::setPropertiesToDefault( const uno::Sequence< OUString >& rNameSeq )
357 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
359 OUString aPropertyName( rNameSeq[nN] );
360 setPropertyToDefault( aPropertyName );
363 uno::Sequence< uno::Any > SAL_CALL MinMaxLineWrapper::getPropertyDefaults( const uno::Sequence< OUString >& rNameSeq )
365 Sequence< Any > aRetSeq;
366 if( rNameSeq.hasElements() )
368 aRetSeq.realloc( rNameSeq.getLength() );
369 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
371 OUString aPropertyName( rNameSeq[nN] );
372 aRetSeq[nN] = getPropertyDefault( aPropertyName );
375 return aRetSeq;
378 OUString SAL_CALL MinMaxLineWrapper::getImplementationName()
380 return "com.sun.star.comp.chart.ChartLine";
383 sal_Bool SAL_CALL MinMaxLineWrapper::supportsService( const OUString& rServiceName )
385 return cppu::supportsService(this, rServiceName);
388 css::uno::Sequence< OUString > SAL_CALL MinMaxLineWrapper::getSupportedServiceNames()
390 return {
391 "com.sun.star.chart.ChartLine",
392 "com.sun.star.xml.UserDefinedAttributesSupplier",
393 "com.sun.star.drawing.LineProperties"
397 } // namespace wrapper
398 } // namespace chart
400 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */