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: MinMaxLineWrapper.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 "MinMaxLineWrapper.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>
42 #include <com/sun/star/drawing/LineJoint.hpp>
44 #include "LineProperties.hxx"
45 #include "UserDefinedProperties.hxx"
47 using namespace ::com::sun::star
;
48 using namespace ::com::sun::star::chart2
;
50 using ::com::sun::star::beans::Property
;
51 using ::osl::MutexGuard
;
52 using ::com::sun::star::uno::Reference
;
53 using ::com::sun::star::uno::Sequence
;
54 using ::com::sun::star::uno::Any
;
55 using ::rtl::OUString
;
59 static const OUString
lcl_aServiceName(
60 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.ChartLine" ));
62 const Sequence
< Property
> & lcl_GetPropertySequence()
64 static Sequence
< Property
> aPropSeq
;
67 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
68 if( 0 == aPropSeq
.getLength() )
71 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
73 ::chart::LineProperties::AddPropertiesToVector( aProperties
);
74 // ::chart::NamedLineProperties::AddPropertiesToVector( aProperties );
75 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
77 // and sort them for access via bsearch
78 ::std::sort( aProperties
.begin(), aProperties
.end(),
79 ::chart::PropertyNameLess() );
81 // transfer result to static Sequence
82 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
88 } // anonymous namespace
90 // --------------------------------------------------------------------------------
97 MinMaxLineWrapper::MinMaxLineWrapper( ::boost::shared_ptr
< Chart2ModelContact
> spChart2ModelContact
)
98 : m_spChart2ModelContact( spChart2ModelContact
)
99 , m_aEventListenerContainer( m_aMutex
)
100 , m_pPropertyArrayHelper()
101 , m_aWrappedLineJointProperty( C2U("LineJoint"), uno::makeAny( drawing::LineJoint_NONE
))
105 MinMaxLineWrapper::~MinMaxLineWrapper()
109 // ____ XComponent ____
110 void SAL_CALL
MinMaxLineWrapper::dispose()
111 throw (uno::RuntimeException
)
113 Reference
< uno::XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
114 m_aEventListenerContainer
.disposeAndClear( lang::EventObject( xSource
) );
117 MutexGuard
aGuard( GetMutex());
122 void SAL_CALL
MinMaxLineWrapper::addEventListener(
123 const Reference
< lang::XEventListener
>& xListener
)
124 throw (uno::RuntimeException
)
126 m_aEventListenerContainer
.addInterface( xListener
);
129 void SAL_CALL
MinMaxLineWrapper::removeEventListener(
130 const Reference
< lang::XEventListener
>& aListener
)
131 throw (uno::RuntimeException
)
133 m_aEventListenerContainer
.removeInterface( aListener
);
136 ::cppu::IPropertyArrayHelper
& MinMaxLineWrapper::getInfoHelper()
138 if(!m_pPropertyArrayHelper
.get())
141 ::osl::MutexGuard
aGuard( GetMutex() );
142 if(!m_pPropertyArrayHelper
.get())
144 sal_Bool bSorted
= sal_True
;
145 m_pPropertyArrayHelper
= ::boost::shared_ptr
< ::cppu::OPropertyArrayHelper
>( new ::cppu::OPropertyArrayHelper( lcl_GetPropertySequence(), bSorted
) );
149 return *m_pPropertyArrayHelper
.get();
153 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
MinMaxLineWrapper::getPropertySetInfo()
154 throw (uno::RuntimeException
)
159 ::osl::MutexGuard
aGuard( GetMutex() );
161 m_xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo( getInfoHelper() );
166 void SAL_CALL
MinMaxLineWrapper::setPropertyValue( const ::rtl::OUString
& rPropertyName
, const uno::Any
& rValue
)
167 throw (beans::UnknownPropertyException
, beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
169 Reference
< beans::XPropertySet
> xPropSet(0);
171 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
172 Sequence
< Reference
< chart2::XChartType
> > aTypes(
173 ::chart::DiagramHelper::getChartTypesFromDiagram( xDiagram
) );
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
< chart2::XDataSeriesContainer
> xSeriesContainer(xType
,uno::UNO_QUERY
);
180 if( xSeriesContainer
.is() )
182 Sequence
< Reference
< chart2::XDataSeries
> > aSeriesSeq( xSeriesContainer
->getDataSeries() );
183 if(aSeriesSeq
.getLength())
185 xPropSet
= Reference
< beans::XPropertySet
>(aSeriesSeq
[0],uno::UNO_QUERY
);
188 if( rPropertyName
.equals( C2U("LineColor")) )
189 xPropSet
->setPropertyValue( C2U("Color"), rValue
);
190 else if( rPropertyName
.equals( C2U("LineTransparence")) )
191 xPropSet
->setPropertyValue( C2U("Transparency"), rValue
);
192 else if( rPropertyName
.equals( m_aWrappedLineJointProperty
.getOuterName() ) )
193 m_aWrappedLineJointProperty
.setPropertyValue( rValue
, xPropSet
);
195 xPropSet
->setPropertyValue( rPropertyName
, rValue
);
203 uno::Any SAL_CALL
MinMaxLineWrapper::getPropertyValue( const ::rtl::OUString
& rPropertyName
)
204 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
208 Reference
< beans::XPropertySet
> xPropSet(0);
210 Reference
< chart2::XDiagram
> xDiagram( m_spChart2ModelContact
->getChart2Diagram() );
211 Sequence
< Reference
< chart2::XChartType
> > aTypes(
212 ::chart::DiagramHelper::getChartTypesFromDiagram( xDiagram
) );
213 for( sal_Int32 nN
= 0; nN
< aTypes
.getLength(); nN
++ )
215 Reference
< chart2::XChartType
> xType( aTypes
[nN
] );
216 if( xType
->getChartType().equals(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
) )
218 Reference
< chart2::XDataSeriesContainer
> xSeriesContainer(xType
,uno::UNO_QUERY
);
219 if( xSeriesContainer
.is() )
221 Sequence
< Reference
< chart2::XDataSeries
> > aSeriesSeq( xSeriesContainer
->getDataSeries() );
222 if(aSeriesSeq
.getLength())
224 xPropSet
= Reference
< beans::XPropertySet
>(aSeriesSeq
[0],uno::UNO_QUERY
);
232 if( rPropertyName
.equals( C2U("LineColor")) )
233 aRet
= xPropSet
->getPropertyValue( C2U("Color") );
234 else if( rPropertyName
.equals( C2U("LineTransparence")) )
235 aRet
= xPropSet
->getPropertyValue( C2U("Transparency") );
236 else if( rPropertyName
.equals( m_aWrappedLineJointProperty
.getOuterName() ) )
237 aRet
= m_aWrappedLineJointProperty
.getPropertyValue( xPropSet
);
239 aRet
= xPropSet
->getPropertyValue( rPropertyName
);
245 void SAL_CALL
MinMaxLineWrapper::addPropertyChangeListener( const ::rtl::OUString
& /*aPropertyName*/, const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
246 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
248 OSL_ENSURE(false,"not implemented");
250 void SAL_CALL
MinMaxLineWrapper::removePropertyChangeListener( const ::rtl::OUString
& /*aPropertyName*/, const uno::Reference
< beans::XPropertyChangeListener
>& /*aListener*/ )
251 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
253 OSL_ENSURE(false,"not implemented");
255 void SAL_CALL
MinMaxLineWrapper::addVetoableChangeListener( const ::rtl::OUString
& /*PropertyName*/, const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
256 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
258 OSL_ENSURE(false,"not implemented");
260 void SAL_CALL
MinMaxLineWrapper::removeVetoableChangeListener( const ::rtl::OUString
& /*PropertyName*/, const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
261 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
263 OSL_ENSURE(false,"not implemented");
267 //getPropertySetInfo() already declared in XPropertySet
268 void SAL_CALL
MinMaxLineWrapper::setPropertyValues( const uno::Sequence
< ::rtl::OUString
>& rNameSeq
, const uno::Sequence
< uno::Any
>& rValueSeq
)
269 throw (beans::PropertyVetoException
, lang::IllegalArgumentException
, lang::WrappedTargetException
, uno::RuntimeException
)
271 bool bUnknownProperty
= false;
272 sal_Int32 nMinCount
= std::min( rValueSeq
.getLength(), rNameSeq
.getLength() );
273 for(sal_Int32 nN
=0; nN
<nMinCount
; nN
++)
275 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
278 this->setPropertyValue( aPropertyName
, rValueSeq
[nN
] );
280 catch( beans::UnknownPropertyException
& ex
)
282 ASSERT_EXCEPTION( ex
);
283 bUnknownProperty
= true;
286 //todo: store unknown properties elsewhere
287 // if( bUnknownProperty )
288 // throw beans::UnknownPropertyException();
290 uno::Sequence
< uno::Any
> SAL_CALL
MinMaxLineWrapper::getPropertyValues( const uno::Sequence
< ::rtl::OUString
>& rNameSeq
)
291 throw (uno::RuntimeException
)
293 Sequence
< Any
> aRetSeq
;
294 if( rNameSeq
.getLength() )
296 aRetSeq
.realloc( rNameSeq
.getLength() );
297 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
299 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
300 aRetSeq
[nN
] = this->getPropertyValue( aPropertyName
);
305 void SAL_CALL
MinMaxLineWrapper::addPropertiesChangeListener(
306 const uno::Sequence
< ::rtl::OUString
>& /* aPropertyNames */,
307 const uno::Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
308 throw (uno::RuntimeException
)
310 OSL_ENSURE(false,"not implemented");
312 void SAL_CALL
MinMaxLineWrapper::removePropertiesChangeListener(
313 const uno::Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
314 throw (uno::RuntimeException
)
316 OSL_ENSURE(false,"not implemented");
318 void SAL_CALL
MinMaxLineWrapper::firePropertiesChangeEvent(
319 const uno::Sequence
< ::rtl::OUString
>& /* aPropertyNames */,
320 const uno::Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
321 throw (uno::RuntimeException
)
323 OSL_ENSURE(false,"not implemented");
327 beans::PropertyState SAL_CALL
MinMaxLineWrapper::getPropertyState( const ::rtl::OUString
& rPropertyName
)
328 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
330 if( rPropertyName
.equals( m_aWrappedLineJointProperty
.getOuterName() ) )
331 return beans::PropertyState_DEFAULT_VALUE
;
333 uno::Any
aDefault( this->getPropertyDefault( rPropertyName
) );
334 uno::Any
aValue( this->getPropertyValue( rPropertyName
) );
336 if( aDefault
== aValue
)
337 return beans::PropertyState_DEFAULT_VALUE
;
339 return beans::PropertyState_DIRECT_VALUE
;
341 uno::Sequence
< beans::PropertyState
> SAL_CALL
MinMaxLineWrapper::getPropertyStates( const uno::Sequence
< ::rtl::OUString
>& rNameSeq
)
342 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
344 Sequence
< beans::PropertyState
> aRetSeq
;
345 if( rNameSeq
.getLength() )
347 aRetSeq
.realloc( rNameSeq
.getLength() );
348 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
350 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
351 aRetSeq
[nN
] = this->getPropertyState( aPropertyName
);
356 void SAL_CALL
MinMaxLineWrapper::setPropertyToDefault( const ::rtl::OUString
& rPropertyName
)
357 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
359 this->setPropertyValue( rPropertyName
, this->getPropertyDefault(rPropertyName
) );
361 uno::Any SAL_CALL
MinMaxLineWrapper::getPropertyDefault( const ::rtl::OUString
& rPropertyName
)
362 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
364 static tPropertyValueMap aStaticDefaults
;
367 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
368 if( 0 == aStaticDefaults
.size() )
370 LineProperties::AddDefaultsToMap( aStaticDefaults
);
373 sal_Int32 nHandle
= getInfoHelper().getHandleByName( rPropertyName
);
375 tPropertyValueMap::const_iterator
aFound(
376 aStaticDefaults
.find( nHandle
));
378 if( aFound
== aStaticDefaults
.end())
381 return (*aFound
).second
;
384 //XMultiPropertyStates
385 //getPropertyStates() already declared in XPropertyState
386 void SAL_CALL
MinMaxLineWrapper::setAllPropertiesToDefault( )
387 throw (uno::RuntimeException
)
389 const Sequence
< beans::Property
>& rPropSeq
= lcl_GetPropertySequence();
390 for(sal_Int32 nN
=0; nN
<rPropSeq
.getLength(); nN
++)
392 ::rtl::OUString
aPropertyName( rPropSeq
[nN
].Name
);
393 this->setPropertyToDefault( aPropertyName
);
396 void SAL_CALL
MinMaxLineWrapper::setPropertiesToDefault( const uno::Sequence
< ::rtl::OUString
>& rNameSeq
)
397 throw (beans::UnknownPropertyException
, uno::RuntimeException
)
399 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
401 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
402 this->setPropertyToDefault( aPropertyName
);
405 uno::Sequence
< uno::Any
> SAL_CALL
MinMaxLineWrapper::getPropertyDefaults( const uno::Sequence
< ::rtl::OUString
>& rNameSeq
)
406 throw (beans::UnknownPropertyException
, lang::WrappedTargetException
, uno::RuntimeException
)
408 Sequence
< Any
> aRetSeq
;
409 if( rNameSeq
.getLength() )
411 aRetSeq
.realloc( rNameSeq
.getLength() );
412 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
414 ::rtl::OUString
aPropertyName( rNameSeq
[nN
] );
415 aRetSeq
[nN
] = this->getPropertyDefault( aPropertyName
);
422 // ================================================================================
424 Sequence
< OUString
> MinMaxLineWrapper::getSupportedServiceNames_Static()
426 Sequence
< OUString
> aServices( 3 );
427 aServices
[ 0 ] = C2U( "com.sun.star.chart.ChartLine" );
428 aServices
[ 1 ] = C2U( "com.sun.star.xml.UserDefinedAttributeSupplier" );
429 aServices
[ 2 ] = C2U( "com.sun.star.drawing.LineProperties" );
434 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
435 APPHELPER_XSERVICEINFO_IMPL( MinMaxLineWrapper
, lcl_aServiceName
);
437 } // namespace wrapper