1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <ChartType.hxx>
23 #include <servicenames_charttypes.hxx>
24 #include <cppuhelper/propshlp.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <com/sun/star/drawing/LineJoint.hpp>
27 #include <comphelper/sequence.hxx>
28 #include <DataSeries.hxx>
29 #include <LinePropertiesHelper.hxx>
30 #include <UserDefinedProperties.hxx>
32 #include <comphelper/diagnose_ex.hxx>
34 using namespace ::com::sun::star
;
36 using ::com::sun::star::beans::Property
;
37 using ::com::sun::star::uno::Reference
;
38 using ::com::sun::star::uno::Sequence
;
39 using ::com::sun::star::uno::Any
;
44 Sequence
< Property
>& StaticMinMaxLineWrapperPropertyArray()
46 static Sequence
< Property
> aPropSeq
= []()
48 std::vector
< css::beans::Property
> aProperties
;
50 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
51 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
53 std::sort( aProperties
.begin(), aProperties
.end(),
54 ::chart::PropertyNameLess() );
56 return comphelper::containerToSequence( aProperties
);
61 ::cppu::OPropertyArrayHelper
& StaticMinMaxLineWrapperInfoHelper()
63 static ::cppu::OPropertyArrayHelper
aPropHelper( StaticMinMaxLineWrapperPropertyArray() );
67 uno::Reference
< beans::XPropertySetInfo
>& StaticMinMaxLineWrapperInfo()
69 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
70 ::cppu::OPropertySetHelper::createPropertySetInfo( StaticMinMaxLineWrapperInfoHelper() ) );
71 return xPropertySetInfo
;
74 } // anonymous namespace
76 namespace chart::wrapper
79 MinMaxLineWrapper::MinMaxLineWrapper(std::shared_ptr
<Chart2ModelContact
> spChart2ModelContact
)
80 : m_spChart2ModelContact(std::move( spChart2ModelContact
))
81 , m_aWrappedLineJointProperty( u
"LineJoint"_ustr
, uno::Any( drawing::LineJoint_NONE
))
85 MinMaxLineWrapper::~MinMaxLineWrapper()
89 // ____ XComponent ____
90 void SAL_CALL
MinMaxLineWrapper::dispose()
92 std::unique_lock
g(m_aMutex
);
93 Reference
< uno::XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
94 m_aEventListenerContainer
.disposeAndClear( g
, lang::EventObject( xSource
) );
97 void SAL_CALL
MinMaxLineWrapper::addEventListener(
98 const Reference
< lang::XEventListener
>& xListener
)
100 std::unique_lock
g(m_aMutex
);
101 m_aEventListenerContainer
.addInterface( g
, xListener
);
104 void SAL_CALL
MinMaxLineWrapper::removeEventListener(
105 const Reference
< lang::XEventListener
>& aListener
)
107 std::unique_lock
g(m_aMutex
);
108 m_aEventListenerContainer
.removeInterface( g
, aListener
);
112 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
MinMaxLineWrapper::getPropertySetInfo()
114 return StaticMinMaxLineWrapperInfo();
117 void SAL_CALL
MinMaxLineWrapper::setPropertyValue( const OUString
& rPropertyName
, const uno::Any
& rValue
)
119 rtl::Reference
< ::chart::Diagram
> xDiagram( m_spChart2ModelContact
->getDiagram() );
120 const std::vector
< rtl::Reference
< ChartType
> > aTypes
= xDiagram
->getChartTypes();
121 for( rtl::Reference
< ChartType
> const & xType
: aTypes
)
123 if( xType
->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
)
125 const std::vector
< rtl::Reference
< DataSeries
> > & aSeriesSeq( xType
->getDataSeries2() );
126 if(!aSeriesSeq
.empty())
128 if(aSeriesSeq
[0].is())
130 if( rPropertyName
== "LineColor" )
131 aSeriesSeq
[0]->setPropertyValue( u
"Color"_ustr
, rValue
);
132 else if( rPropertyName
== "LineTransparence" )
133 aSeriesSeq
[0]->setPropertyValue( u
"Transparency"_ustr
, rValue
);
134 else if( rPropertyName
== m_aWrappedLineJointProperty
.getOuterName() )
135 m_aWrappedLineJointProperty
.setPropertyValue( rValue
, aSeriesSeq
[0] );
137 aSeriesSeq
[0]->setPropertyValue( rPropertyName
, rValue
);
144 uno::Any SAL_CALL
MinMaxLineWrapper::getPropertyValue( const OUString
& rPropertyName
)
148 rtl::Reference
< DataSeries
> xPropSet
;
150 rtl::Reference
< ::chart::Diagram
> xDiagram( m_spChart2ModelContact
->getDiagram() );
151 const std::vector
< rtl::Reference
< ChartType
> > aTypes
= xDiagram
->getChartTypes();
152 for( rtl::Reference
< ChartType
> const & xType
: aTypes
)
154 if( xType
->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
)
156 const std::vector
< rtl::Reference
< DataSeries
> > & aSeriesSeq( xType
->getDataSeries2() );
157 if(!aSeriesSeq
.empty())
159 xPropSet
= aSeriesSeq
[0];
166 if( rPropertyName
== "LineColor" )
167 aRet
= xPropSet
->getPropertyValue( u
"Color"_ustr
);
168 else if( rPropertyName
== "LineTransparence" )
169 aRet
= xPropSet
->getPropertyValue( u
"Transparency"_ustr
);
170 else if( rPropertyName
== m_aWrappedLineJointProperty
.getOuterName() )
171 aRet
= m_aWrappedLineJointProperty
.getPropertyValue( xPropSet
);
173 aRet
= xPropSet
->getPropertyValue( rPropertyName
);
179 void SAL_CALL
MinMaxLineWrapper::addPropertyChangeListener( const OUString
& /*aPropertyName*/, const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
181 OSL_FAIL("not implemented");
183 void SAL_CALL
MinMaxLineWrapper::removePropertyChangeListener( const OUString
& /*aPropertyName*/, const uno::Reference
< beans::XPropertyChangeListener
>& /*aListener*/ )
185 OSL_FAIL("not implemented");
187 void SAL_CALL
MinMaxLineWrapper::addVetoableChangeListener( const OUString
& /*PropertyName*/, const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
189 OSL_FAIL("not implemented");
191 void SAL_CALL
MinMaxLineWrapper::removeVetoableChangeListener( const OUString
& /*PropertyName*/, const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
193 OSL_FAIL("not implemented");
197 //getPropertySetInfo() already declared in XPropertySet
198 void SAL_CALL
MinMaxLineWrapper::setPropertyValues( const uno::Sequence
< OUString
>& rNameSeq
, const uno::Sequence
< uno::Any
>& rValueSeq
)
200 sal_Int32 nMinCount
= std::min( rValueSeq
.getLength(), rNameSeq
.getLength() );
201 for(sal_Int32 nN
=0; nN
<nMinCount
; nN
++)
203 const OUString
& aPropertyName( rNameSeq
[nN
] );
206 setPropertyValue( aPropertyName
, rValueSeq
[nN
] );
208 catch( const beans::UnknownPropertyException
& )
210 DBG_UNHANDLED_EXCEPTION("chart2");
213 //todo: store unknown properties elsewhere
215 uno::Sequence
< uno::Any
> SAL_CALL
MinMaxLineWrapper::getPropertyValues( const uno::Sequence
< OUString
>& rNameSeq
)
217 Sequence
< Any
> aRetSeq
;
218 if( rNameSeq
.hasElements() )
220 aRetSeq
.realloc( rNameSeq
.getLength() );
221 auto pRetSeq
= aRetSeq
.getArray();
222 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
224 const OUString
& aPropertyName( rNameSeq
[nN
] );
225 pRetSeq
[nN
] = getPropertyValue( aPropertyName
);
230 void SAL_CALL
MinMaxLineWrapper::addPropertiesChangeListener(
231 const uno::Sequence
< OUString
>& /* aPropertyNames */,
232 const uno::Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
234 OSL_FAIL("not implemented");
236 void SAL_CALL
MinMaxLineWrapper::removePropertiesChangeListener(
237 const uno::Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
239 OSL_FAIL("not implemented");
241 void SAL_CALL
MinMaxLineWrapper::firePropertiesChangeEvent(
242 const uno::Sequence
< OUString
>& /* aPropertyNames */,
243 const uno::Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
245 OSL_FAIL("not implemented");
249 beans::PropertyState SAL_CALL
MinMaxLineWrapper::getPropertyState( const OUString
& rPropertyName
)
251 if( rPropertyName
== m_aWrappedLineJointProperty
.getOuterName() )
252 return beans::PropertyState_DEFAULT_VALUE
;
254 uno::Any
aDefault( getPropertyDefault( rPropertyName
) );
255 uno::Any
aValue( getPropertyValue( rPropertyName
) );
257 if( aDefault
== aValue
)
258 return beans::PropertyState_DEFAULT_VALUE
;
260 return beans::PropertyState_DIRECT_VALUE
;
262 uno::Sequence
< beans::PropertyState
> SAL_CALL
MinMaxLineWrapper::getPropertyStates( const uno::Sequence
< OUString
>& rNameSeq
)
264 Sequence
< beans::PropertyState
> aRetSeq
;
265 if( rNameSeq
.hasElements() )
267 aRetSeq
.realloc( rNameSeq
.getLength() );
268 auto pRetSeq
= aRetSeq
.getArray();
269 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
271 const OUString
& aPropertyName( rNameSeq
[nN
] );
272 pRetSeq
[nN
] = getPropertyState( aPropertyName
);
277 void SAL_CALL
MinMaxLineWrapper::setPropertyToDefault( const OUString
& rPropertyName
)
279 setPropertyValue( rPropertyName
, getPropertyDefault(rPropertyName
) );
282 uno::Any SAL_CALL
MinMaxLineWrapper::getPropertyDefault( const OUString
& rPropertyName
)
284 static const ::chart::tPropertyValueMap aStaticDefaults
= []
286 ::chart::tPropertyValueMap aTmp
;
287 ::chart::LinePropertiesHelper::AddDefaultsToMap( aTmp
);
290 tPropertyValueMap::const_iterator
aFound( aStaticDefaults
.find( StaticMinMaxLineWrapperInfoHelper().getHandleByName( rPropertyName
) ) );
291 if( aFound
== aStaticDefaults
.end() )
293 return (*aFound
).second
;
296 //XMultiPropertyStates
297 //getPropertyStates() already declared in XPropertyState
298 void SAL_CALL
MinMaxLineWrapper::setAllPropertiesToDefault( )
300 const Sequence
< beans::Property
>& rPropSeq
= StaticMinMaxLineWrapperPropertyArray();
301 for(beans::Property
const & prop
: rPropSeq
)
303 setPropertyToDefault( prop
.Name
);
306 void SAL_CALL
MinMaxLineWrapper::setPropertiesToDefault( const uno::Sequence
< OUString
>& rNameSeq
)
308 for(OUString
const & s
: rNameSeq
)
310 setPropertyToDefault( s
);
313 uno::Sequence
< uno::Any
> SAL_CALL
MinMaxLineWrapper::getPropertyDefaults( const uno::Sequence
< OUString
>& rNameSeq
)
315 Sequence
< Any
> aRetSeq
;
316 if( rNameSeq
.hasElements() )
318 aRetSeq
.realloc( rNameSeq
.getLength() );
319 auto pRetSeq
= aRetSeq
.getArray();
320 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
322 const OUString
& aPropertyName( rNameSeq
[nN
] );
323 pRetSeq
[nN
] = getPropertyDefault( aPropertyName
);
329 OUString SAL_CALL
MinMaxLineWrapper::getImplementationName()
331 return u
"com.sun.star.comp.chart.ChartLine"_ustr
;
334 sal_Bool SAL_CALL
MinMaxLineWrapper::supportsService( const OUString
& rServiceName
)
336 return cppu::supportsService(this, rServiceName
);
339 css::uno::Sequence
< OUString
> SAL_CALL
MinMaxLineWrapper::getSupportedServiceNames()
342 u
"com.sun.star.chart.ChartLine"_ustr
,
343 u
"com.sun.star.xml.UserDefinedAttributesSupplier"_ustr
,
344 u
"com.sun.star.drawing.LineProperties"_ustr
348 } // namespace chart::wrapper
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */