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 "UpDownBarWrapper.hxx"
21 #include "Chart2ModelContact.hxx"
22 #include <ChartType.hxx>
23 #include <servicenames_charttypes.hxx>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <cppuhelper/propshlp.hxx>
26 #include <comphelper/sequence.hxx>
28 #include <LinePropertiesHelper.hxx>
29 #include <FillProperties.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 const Sequence
< Property
> & StaticUpDownBarWrapperPropertyArray()
46 static Sequence
< Property
> aPropSeq
= []()
48 std::vector
< css::beans::Property
> aProperties
;
50 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
51 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
52 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
54 std::sort( aProperties
.begin(), aProperties
.end(),
55 ::chart::PropertyNameLess() );
57 return comphelper::containerToSequence( aProperties
);
62 ::cppu::OPropertyArrayHelper
& StaticUpDownBarWrapperInfoHelper()
64 static ::cppu::OPropertyArrayHelper
aPropHelper( StaticUpDownBarWrapperPropertyArray() );
68 } // anonymous namespace
70 namespace chart::wrapper
73 UpDownBarWrapper::UpDownBarWrapper(
74 bool bUp
, std::shared_ptr
<Chart2ModelContact
> spChart2ModelContact
)
75 : m_spChart2ModelContact(std::move( spChart2ModelContact
))
76 , m_aPropertySetName( bUp
? u
"WhiteDay"_ustr
: u
"BlackDay"_ustr
)
80 UpDownBarWrapper::~UpDownBarWrapper()
84 // ____ XComponent ____
85 void SAL_CALL
UpDownBarWrapper::dispose()
87 std::unique_lock
g(m_aMutex
);
88 Reference
< uno::XInterface
> xSource( static_cast< ::cppu::OWeakObject
* >( this ) );
89 m_aEventListenerContainer
.disposeAndClear( g
, lang::EventObject( xSource
) );
92 void SAL_CALL
UpDownBarWrapper::addEventListener(
93 const Reference
< lang::XEventListener
>& xListener
)
95 std::unique_lock
g(m_aMutex
);
96 m_aEventListenerContainer
.addInterface( g
, xListener
);
99 void SAL_CALL
UpDownBarWrapper::removeEventListener(
100 const Reference
< lang::XEventListener
>& aListener
)
102 std::unique_lock
g(m_aMutex
);
103 m_aEventListenerContainer
.removeInterface( g
, aListener
);
107 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
UpDownBarWrapper::getPropertySetInfo()
109 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
110 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticUpDownBarWrapperInfoHelper() ) );
111 return xPropertySetInfo
;
114 void SAL_CALL
UpDownBarWrapper::setPropertyValue( const OUString
& rPropertyName
, const uno::Any
& rValue
)
116 Reference
< beans::XPropertySet
> xPropSet
;
118 const std::vector
< rtl::Reference
< ChartType
> > aTypes
=
119 m_spChart2ModelContact
->getDiagram()->getChartTypes();
120 for( rtl::Reference
< ChartType
> const & xType
: aTypes
)
122 if( xType
->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
)
124 xType
->getPropertyValue( m_aPropertySetName
) >>= xPropSet
;
128 xPropSet
->setPropertyValue( rPropertyName
, rValue
);
130 uno::Any SAL_CALL
UpDownBarWrapper::getPropertyValue( const OUString
& rPropertyName
)
134 Reference
< beans::XPropertySet
> xPropSet
;
136 const std::vector
< rtl::Reference
< ChartType
> > aTypes
=
137 m_spChart2ModelContact
->getDiagram()->getChartTypes();
138 for( rtl::Reference
<ChartType
> const & xType
: aTypes
)
140 if( xType
->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
)
142 xType
->getPropertyValue( m_aPropertySetName
) >>= xPropSet
;
146 aRet
= xPropSet
->getPropertyValue( rPropertyName
);
150 void SAL_CALL
UpDownBarWrapper::addPropertyChangeListener( const OUString
& /*aPropertyName*/, const uno::Reference
< beans::XPropertyChangeListener
>& /*xListener*/ )
152 OSL_FAIL("not implemented");
154 void SAL_CALL
UpDownBarWrapper::removePropertyChangeListener( const OUString
& /*aPropertyName*/, const uno::Reference
< beans::XPropertyChangeListener
>& /*aListener*/ )
156 OSL_FAIL("not implemented");
158 void SAL_CALL
UpDownBarWrapper::addVetoableChangeListener( const OUString
& /*PropertyName*/, const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
160 OSL_FAIL("not implemented");
162 void SAL_CALL
UpDownBarWrapper::removeVetoableChangeListener( const OUString
& /*PropertyName*/, const uno::Reference
< beans::XVetoableChangeListener
>& /*aListener*/ )
164 OSL_FAIL("not implemented");
168 //getPropertySetInfo() already declared in XPropertySet
169 void SAL_CALL
UpDownBarWrapper::setPropertyValues( const uno::Sequence
< OUString
>& rNameSeq
, const uno::Sequence
< uno::Any
>& rValueSeq
)
171 sal_Int32 nMinCount
= std::min( rValueSeq
.getLength(), rNameSeq
.getLength() );
172 for(sal_Int32 nN
=0; nN
<nMinCount
; nN
++)
174 const OUString
& aPropertyName( rNameSeq
[nN
] );
177 setPropertyValue( aPropertyName
, rValueSeq
[nN
] );
179 catch( const beans::UnknownPropertyException
& )
181 DBG_UNHANDLED_EXCEPTION("chart2");
184 //todo: store unknown properties elsewhere
186 uno::Sequence
< uno::Any
> SAL_CALL
UpDownBarWrapper::getPropertyValues( const uno::Sequence
< OUString
>& rNameSeq
)
188 Sequence
< Any
> aRetSeq
;
189 if( rNameSeq
.hasElements() )
191 aRetSeq
.realloc( rNameSeq
.getLength() );
192 auto pRetSeq
= aRetSeq
.getArray();
193 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
195 const OUString
& aPropertyName( rNameSeq
[nN
] );
196 pRetSeq
[nN
] = getPropertyValue( aPropertyName
);
201 void SAL_CALL
UpDownBarWrapper::addPropertiesChangeListener( const uno::Sequence
< OUString
>& /* aPropertyNames */, const uno::Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
203 OSL_FAIL("not implemented");
205 void SAL_CALL
UpDownBarWrapper::removePropertiesChangeListener( const uno::Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
207 OSL_FAIL("not implemented");
209 void SAL_CALL
UpDownBarWrapper::firePropertiesChangeEvent( const uno::Sequence
< OUString
>& /* aPropertyNames */, const uno::Reference
< beans::XPropertiesChangeListener
>& /* xListener */ )
211 OSL_FAIL("not implemented");
215 beans::PropertyState SAL_CALL
UpDownBarWrapper::getPropertyState( const OUString
& rPropertyName
)
217 uno::Any
aDefault( getPropertyDefault( rPropertyName
) );
218 uno::Any
aValue( getPropertyValue( rPropertyName
) );
220 if( aDefault
== aValue
)
221 return beans::PropertyState_DEFAULT_VALUE
;
223 return beans::PropertyState_DIRECT_VALUE
;
225 uno::Sequence
< beans::PropertyState
> SAL_CALL
UpDownBarWrapper::getPropertyStates( const uno::Sequence
< OUString
>& rNameSeq
)
227 Sequence
< beans::PropertyState
> aRetSeq
;
228 if( rNameSeq
.hasElements() )
230 aRetSeq
.realloc( rNameSeq
.getLength() );
231 auto pRetSeq
= aRetSeq
.getArray();
232 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
234 const OUString
& aPropertyName( rNameSeq
[nN
] );
235 pRetSeq
[nN
] = getPropertyState( aPropertyName
);
240 void SAL_CALL
UpDownBarWrapper::setPropertyToDefault( const OUString
& rPropertyName
)
242 setPropertyValue( rPropertyName
, getPropertyDefault(rPropertyName
) );
245 uno::Any SAL_CALL
UpDownBarWrapper::getPropertyDefault( const OUString
& rPropertyName
)
247 static const ::chart::tPropertyValueMap aStaticDefaults
= []()
249 ::chart::tPropertyValueMap aTmp
;
250 ::chart::LinePropertiesHelper::AddDefaultsToMap( aTmp
);
251 ::chart::FillProperties::AddDefaultsToMap( aTmp
);
254 tPropertyValueMap::const_iterator
aFound( aStaticDefaults
.find( StaticUpDownBarWrapperInfoHelper().getHandleByName( rPropertyName
) ) );
255 if( aFound
== aStaticDefaults
.end() )
257 return (*aFound
).second
;
260 //XMultiPropertyStates
261 //getPropertyStates() already declared in XPropertyState
262 void SAL_CALL
UpDownBarWrapper::setAllPropertiesToDefault( )
264 const Sequence
< beans::Property
>& rPropSeq
= StaticUpDownBarWrapperPropertyArray();
265 for(beans::Property
const & prop
: rPropSeq
)
267 setPropertyToDefault( prop
.Name
);
270 void SAL_CALL
UpDownBarWrapper::setPropertiesToDefault( const uno::Sequence
< OUString
>& rNameSeq
)
272 for(OUString
const & s
: rNameSeq
)
274 setPropertyToDefault( s
);
277 uno::Sequence
< uno::Any
> SAL_CALL
UpDownBarWrapper::getPropertyDefaults( const uno::Sequence
< OUString
>& rNameSeq
)
279 Sequence
< Any
> aRetSeq
;
280 if( rNameSeq
.hasElements() )
282 aRetSeq
.realloc( rNameSeq
.getLength() );
283 auto pRetSeq
= aRetSeq
.getArray();
284 for(sal_Int32 nN
=0; nN
<rNameSeq
.getLength(); nN
++)
286 const OUString
& aPropertyName( rNameSeq
[nN
] );
287 pRetSeq
[nN
] = getPropertyDefault( aPropertyName
);
293 OUString SAL_CALL
UpDownBarWrapper::getImplementationName()
295 return u
"com.sun.star.comp.chart.ChartArea"_ustr
;
298 sal_Bool SAL_CALL
UpDownBarWrapper::supportsService( const OUString
& rServiceName
)
300 return cppu::supportsService(this, rServiceName
);
303 css::uno::Sequence
< OUString
> SAL_CALL
UpDownBarWrapper::getSupportedServiceNames()
306 u
"com.sun.star.chart.ChartArea"_ustr
,
307 u
"com.sun.star.drawing.LineProperties"_ustr
,
308 u
"com.sun.star.drawing.FillProperties"_ustr
,
309 u
"com.sun.star.xml.UserDefinedAttributesSupplier"_ustr
313 } // namespace chart::wrapper
315 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */