fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / controller / chartapiwrapper / MinMaxLineWrapper.cxx
blob023eed13ed1593d3de0b5faa95c69a2b649347fe
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 "macros.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>
29 #include <com/sun/star/drawing/LineJoint.hpp>
31 #include "LinePropertiesHelper.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;
43 namespace
45 static const char lcl_aServiceName[] = "com.sun.star.comp.chart.ChartLine";
47 struct StaticMinMaxLineWrapperDefaults_Initializer
49 ::chart::tPropertyValueMap* operator()()
51 static ::chart::tPropertyValueMap aStaticDefaults;
52 lcl_AddDefaultsToMap( aStaticDefaults );
53 return &aStaticDefaults;
55 private:
56 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
58 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap );
62 struct StaticMinMaxLineWrapperDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticMinMaxLineWrapperDefaults_Initializer >
66 struct StaticMinMaxLineWrapperPropertyArray_Initializer
68 Sequence< Property >* operator()()
70 static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
71 return &aPropSeq;
74 private:
75 static Sequence< Property > lcl_GetPropertySequence()
77 ::std::vector< ::com::sun::star::beans::Property > aProperties;
79 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
80 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
82 ::std::sort( aProperties.begin(), aProperties.end(),
83 ::chart::PropertyNameLess() );
85 return ::chart::ContainerHelper::ContainerToSequence( aProperties );
89 struct StaticMinMaxLineWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticMinMaxLineWrapperPropertyArray_Initializer >
93 struct StaticMinMaxLineWrapperInfoHelper_Initializer
95 ::cppu::OPropertyArrayHelper* operator()()
97 static ::cppu::OPropertyArrayHelper aPropHelper( *StaticMinMaxLineWrapperPropertyArray::get() );
98 return &aPropHelper;
102 struct StaticMinMaxLineWrapperInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticMinMaxLineWrapperInfoHelper_Initializer >
106 struct StaticMinMaxLineWrapperInfo_Initializer
108 uno::Reference< beans::XPropertySetInfo >* operator()()
110 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
111 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticMinMaxLineWrapperInfoHelper::get() ) );
112 return &xPropertySetInfo;
116 struct StaticMinMaxLineWrapperInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticMinMaxLineWrapperInfo_Initializer >
120 } // anonymous namespace
122 namespace chart
124 namespace wrapper
127 MinMaxLineWrapper::MinMaxLineWrapper( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
128 : m_spChart2ModelContact( spChart2ModelContact )
129 , m_aEventListenerContainer( m_aMutex )
130 , m_aWrappedLineJointProperty( "LineJoint", uno::makeAny( drawing::LineJoint_NONE ))
134 MinMaxLineWrapper::~MinMaxLineWrapper()
138 // ____ XComponent ____
139 void SAL_CALL MinMaxLineWrapper::dispose()
140 throw (uno::RuntimeException, std::exception)
142 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
143 m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
146 void SAL_CALL MinMaxLineWrapper::addEventListener(
147 const Reference< lang::XEventListener >& xListener )
148 throw (uno::RuntimeException, std::exception)
150 m_aEventListenerContainer.addInterface( xListener );
153 void SAL_CALL MinMaxLineWrapper::removeEventListener(
154 const Reference< lang::XEventListener >& aListener )
155 throw (uno::RuntimeException, std::exception)
157 m_aEventListenerContainer.removeInterface( aListener );
160 ::cppu::IPropertyArrayHelper& MinMaxLineWrapper::getInfoHelper()
162 return *StaticMinMaxLineWrapperInfoHelper::get();
165 //XPropertySet
166 uno::Reference< beans::XPropertySetInfo > SAL_CALL MinMaxLineWrapper::getPropertySetInfo()
167 throw (uno::RuntimeException, std::exception)
169 return *StaticMinMaxLineWrapperInfo::get();
172 void SAL_CALL MinMaxLineWrapper::setPropertyValue( const OUString& rPropertyName, const uno::Any& rValue )
173 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
175 Reference< beans::XPropertySet > xPropSet(0);
177 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
178 Sequence< Reference< chart2::XChartType > > aTypes(
179 ::chart::DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
180 for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
182 Reference< chart2::XChartType > xType( aTypes[nN] );
183 if( xType->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK )
185 Reference< chart2::XDataSeriesContainer > xSeriesContainer(xType,uno::UNO_QUERY);
186 if( xSeriesContainer.is() )
188 Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesContainer->getDataSeries() );
189 if(aSeriesSeq.getLength())
191 xPropSet = Reference< beans::XPropertySet >(aSeriesSeq[0],uno::UNO_QUERY);
192 if(xPropSet.is())
194 if( rPropertyName == "LineColor" )
195 xPropSet->setPropertyValue( "Color", rValue );
196 else if( rPropertyName == "LineTransparence" )
197 xPropSet->setPropertyValue( "Transparency", rValue );
198 else if( rPropertyName.equals( m_aWrappedLineJointProperty.getOuterName() ) )
199 m_aWrappedLineJointProperty.setPropertyValue( rValue, xPropSet );
200 else
201 xPropSet->setPropertyValue( rPropertyName, rValue );
202 return;
209 uno::Any SAL_CALL MinMaxLineWrapper::getPropertyValue( const OUString& rPropertyName )
210 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
212 Any aRet;
214 Reference< beans::XPropertySet > xPropSet(0);
216 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
217 Sequence< Reference< chart2::XChartType > > aTypes(
218 ::chart::DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
219 for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
221 Reference< chart2::XChartType > xType( aTypes[nN] );
222 if( xType->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK )
224 Reference< chart2::XDataSeriesContainer > xSeriesContainer(xType,uno::UNO_QUERY);
225 if( xSeriesContainer.is() )
227 Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesContainer->getDataSeries() );
228 if(aSeriesSeq.getLength())
230 xPropSet = Reference< beans::XPropertySet >(aSeriesSeq[0],uno::UNO_QUERY);
231 break;
236 if(xPropSet.is())
238 if( rPropertyName == "LineColor" )
239 aRet = xPropSet->getPropertyValue( "Color" );
240 else if( rPropertyName == "LineTransparence" )
241 aRet = xPropSet->getPropertyValue( "Transparency" );
242 else if( rPropertyName.equals( m_aWrappedLineJointProperty.getOuterName() ) )
243 aRet = m_aWrappedLineJointProperty.getPropertyValue( xPropSet );
244 else
245 aRet = xPropSet->getPropertyValue( rPropertyName );
248 return aRet;
251 void SAL_CALL MinMaxLineWrapper::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
252 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
254 OSL_FAIL("not implemented");
256 void SAL_CALL MinMaxLineWrapper::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
257 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
259 OSL_FAIL("not implemented");
261 void SAL_CALL MinMaxLineWrapper::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
262 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
264 OSL_FAIL("not implemented");
266 void SAL_CALL MinMaxLineWrapper::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
267 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
269 OSL_FAIL("not implemented");
272 //XMultiPropertySet
273 //getPropertySetInfo() already declared in XPropertySet
274 void SAL_CALL MinMaxLineWrapper::setPropertyValues( const uno::Sequence< OUString >& rNameSeq, const uno::Sequence< uno::Any >& rValueSeq )
275 throw (beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
277 sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() );
278 for(sal_Int32 nN=0; nN<nMinCount; nN++)
280 OUString aPropertyName( rNameSeq[nN] );
283 this->setPropertyValue( aPropertyName, rValueSeq[nN] );
285 catch( const beans::UnknownPropertyException& ex )
287 ASSERT_EXCEPTION( ex );
290 //todo: store unknown properties elsewhere
292 uno::Sequence< uno::Any > SAL_CALL MinMaxLineWrapper::getPropertyValues( const uno::Sequence< OUString >& rNameSeq )
293 throw (uno::RuntimeException, std::exception)
295 Sequence< Any > aRetSeq;
296 if( rNameSeq.getLength() )
298 aRetSeq.realloc( rNameSeq.getLength() );
299 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
301 OUString aPropertyName( rNameSeq[nN] );
302 aRetSeq[nN] = this->getPropertyValue( aPropertyName );
305 return aRetSeq;
307 void SAL_CALL MinMaxLineWrapper::addPropertiesChangeListener(
308 const uno::Sequence< OUString >& /* aPropertyNames */,
309 const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
310 throw (uno::RuntimeException, std::exception)
312 OSL_FAIL("not implemented");
314 void SAL_CALL MinMaxLineWrapper::removePropertiesChangeListener(
315 const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
316 throw (uno::RuntimeException, std::exception)
318 OSL_FAIL("not implemented");
320 void SAL_CALL MinMaxLineWrapper::firePropertiesChangeEvent(
321 const uno::Sequence< OUString >& /* aPropertyNames */,
322 const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
323 throw (uno::RuntimeException, std::exception)
325 OSL_FAIL("not implemented");
328 //XPropertyState
329 beans::PropertyState SAL_CALL MinMaxLineWrapper::getPropertyState( const OUString& rPropertyName )
330 throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
332 if( rPropertyName.equals( m_aWrappedLineJointProperty.getOuterName() ) )
333 return beans::PropertyState_DEFAULT_VALUE;
335 uno::Any aDefault( this->getPropertyDefault( rPropertyName ) );
336 uno::Any aValue( this->getPropertyValue( rPropertyName ) );
338 if( aDefault == aValue )
339 return beans::PropertyState_DEFAULT_VALUE;
341 return beans::PropertyState_DIRECT_VALUE;
343 uno::Sequence< beans::PropertyState > SAL_CALL MinMaxLineWrapper::getPropertyStates( const uno::Sequence< OUString >& rNameSeq )
344 throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
346 Sequence< beans::PropertyState > aRetSeq;
347 if( rNameSeq.getLength() )
349 aRetSeq.realloc( rNameSeq.getLength() );
350 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
352 OUString aPropertyName( rNameSeq[nN] );
353 aRetSeq[nN] = this->getPropertyState( aPropertyName );
356 return aRetSeq;
358 void SAL_CALL MinMaxLineWrapper::setPropertyToDefault( const OUString& rPropertyName )
359 throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
361 this->setPropertyValue( rPropertyName, this->getPropertyDefault(rPropertyName) );
364 uno::Any SAL_CALL MinMaxLineWrapper::getPropertyDefault( const OUString& rPropertyName )
365 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
367 const tPropertyValueMap& rStaticDefaults = *StaticMinMaxLineWrapperDefaults::get();
368 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( getInfoHelper().getHandleByName( rPropertyName ) ) );
369 if( aFound == rStaticDefaults.end() )
370 return uno::Any();
371 return (*aFound).second;
374 //XMultiPropertyStates
375 //getPropertyStates() already declared in XPropertyState
376 void SAL_CALL MinMaxLineWrapper::setAllPropertiesToDefault( )
377 throw (uno::RuntimeException, std::exception)
379 const Sequence< beans::Property >& rPropSeq = *StaticMinMaxLineWrapperPropertyArray::get();
380 for(sal_Int32 nN=0; nN<rPropSeq.getLength(); nN++)
382 OUString aPropertyName( rPropSeq[nN].Name );
383 this->setPropertyToDefault( aPropertyName );
386 void SAL_CALL MinMaxLineWrapper::setPropertiesToDefault( const uno::Sequence< OUString >& rNameSeq )
387 throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
389 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
391 OUString aPropertyName( rNameSeq[nN] );
392 this->setPropertyToDefault( aPropertyName );
395 uno::Sequence< uno::Any > SAL_CALL MinMaxLineWrapper::getPropertyDefaults( const uno::Sequence< OUString >& rNameSeq )
396 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
398 Sequence< Any > aRetSeq;
399 if( rNameSeq.getLength() )
401 aRetSeq.realloc( rNameSeq.getLength() );
402 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
404 OUString aPropertyName( rNameSeq[nN] );
405 aRetSeq[nN] = this->getPropertyDefault( aPropertyName );
408 return aRetSeq;
411 Sequence< OUString > MinMaxLineWrapper::getSupportedServiceNames_Static()
413 Sequence< OUString > aServices( 3 );
414 aServices[ 0 ] = "com.sun.star.chart.ChartLine";
415 aServices[ 1 ] = "com.sun.star.xml.UserDefinedAttributesSupplier";
416 aServices[ 2 ] = "com.sun.star.drawing.LineProperties";
418 return aServices;
421 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
422 OUString SAL_CALL MinMaxLineWrapper::getImplementationName()
423 throw( css::uno::RuntimeException, std::exception )
425 return getImplementationName_Static();
428 OUString MinMaxLineWrapper::getImplementationName_Static()
430 return OUString(lcl_aServiceName);
433 sal_Bool SAL_CALL MinMaxLineWrapper::supportsService( const OUString& rServiceName )
434 throw( css::uno::RuntimeException, std::exception )
436 return cppu::supportsService(this, rServiceName);
439 css::uno::Sequence< OUString > SAL_CALL MinMaxLineWrapper::getSupportedServiceNames()
440 throw( css::uno::RuntimeException, std::exception )
442 return getSupportedServiceNames_Static();
445 } // namespace wrapper
446 } // namespace chart
448 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */