/src/libreoffice/chart2/source/controller/chartapiwrapper/UpDownBarWrapper.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
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> |
27 | | |
28 | | #include <LinePropertiesHelper.hxx> |
29 | | #include <FillProperties.hxx> |
30 | | #include <UserDefinedProperties.hxx> |
31 | | #include <utility> |
32 | | #include <comphelper/diagnose_ex.hxx> |
33 | | |
34 | | using namespace ::com::sun::star; |
35 | | |
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; |
40 | | |
41 | | namespace |
42 | | { |
43 | | |
44 | | const Sequence< Property > & StaticUpDownBarWrapperPropertyArray() |
45 | 0 | { |
46 | 0 | static Sequence< Property > aPropSeq = []() |
47 | 0 | { |
48 | 0 | std::vector< css::beans::Property > aProperties; |
49 | |
|
50 | 0 | ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties ); |
51 | 0 | ::chart::FillProperties::AddPropertiesToVector( aProperties ); |
52 | 0 | ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties ); |
53 | |
|
54 | 0 | std::sort( aProperties.begin(), aProperties.end(), |
55 | 0 | ::chart::PropertyNameLess() ); |
56 | |
|
57 | 0 | return comphelper::containerToSequence( aProperties ); |
58 | 0 | }(); |
59 | 0 | return aPropSeq; |
60 | 0 | }; |
61 | | |
62 | | ::cppu::OPropertyArrayHelper& StaticUpDownBarWrapperInfoHelper() |
63 | 0 | { |
64 | 0 | static ::cppu::OPropertyArrayHelper aPropHelper( StaticUpDownBarWrapperPropertyArray() ); |
65 | 0 | return aPropHelper; |
66 | 0 | }; |
67 | | |
68 | | } // anonymous namespace |
69 | | |
70 | | namespace chart::wrapper |
71 | | { |
72 | | |
73 | | UpDownBarWrapper::UpDownBarWrapper( |
74 | | bool bUp, std::shared_ptr<Chart2ModelContact> spChart2ModelContact) |
75 | 0 | : m_spChart2ModelContact(std::move( spChart2ModelContact )) |
76 | 0 | , m_aPropertySetName( bUp ? u"WhiteDay"_ustr : u"BlackDay"_ustr) |
77 | 0 | { |
78 | 0 | } |
79 | | |
80 | | UpDownBarWrapper::~UpDownBarWrapper() |
81 | 0 | { |
82 | 0 | } |
83 | | |
84 | | // ____ XComponent ____ |
85 | | void SAL_CALL UpDownBarWrapper::dispose() |
86 | 0 | { |
87 | 0 | std::unique_lock g(m_aMutex); |
88 | 0 | Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); |
89 | 0 | m_aEventListenerContainer.disposeAndClear( g, lang::EventObject( xSource ) ); |
90 | 0 | } |
91 | | |
92 | | void SAL_CALL UpDownBarWrapper::addEventListener( |
93 | | const Reference< lang::XEventListener >& xListener ) |
94 | 0 | { |
95 | 0 | std::unique_lock g(m_aMutex); |
96 | 0 | m_aEventListenerContainer.addInterface( g, xListener ); |
97 | 0 | } |
98 | | |
99 | | void SAL_CALL UpDownBarWrapper::removeEventListener( |
100 | | const Reference< lang::XEventListener >& aListener ) |
101 | 0 | { |
102 | 0 | std::unique_lock g(m_aMutex); |
103 | 0 | m_aEventListenerContainer.removeInterface( g, aListener ); |
104 | 0 | } |
105 | | |
106 | | //XPropertySet |
107 | | uno::Reference< beans::XPropertySetInfo > SAL_CALL UpDownBarWrapper::getPropertySetInfo() |
108 | 0 | { |
109 | 0 | static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo( |
110 | 0 | ::cppu::OPropertySetHelper::createPropertySetInfo(StaticUpDownBarWrapperInfoHelper() ) ); |
111 | 0 | return xPropertySetInfo; |
112 | 0 | } |
113 | | |
114 | | void SAL_CALL UpDownBarWrapper::setPropertyValue( const OUString& rPropertyName, const uno::Any& rValue ) |
115 | 0 | { |
116 | 0 | Reference< beans::XPropertySet > xPropSet; |
117 | |
|
118 | 0 | const std::vector< rtl::Reference< ChartType > > aTypes = |
119 | 0 | m_spChart2ModelContact->getDiagram()->getChartTypes(); |
120 | 0 | for( rtl::Reference< ChartType > const & xType : aTypes ) |
121 | 0 | { |
122 | 0 | if( xType->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK ) |
123 | 0 | { |
124 | 0 | xType->getPropertyValue( m_aPropertySetName ) >>= xPropSet; |
125 | 0 | } |
126 | 0 | } |
127 | 0 | if(xPropSet.is()) |
128 | 0 | xPropSet->setPropertyValue( rPropertyName, rValue ); |
129 | 0 | } |
130 | | uno::Any SAL_CALL UpDownBarWrapper::getPropertyValue( const OUString& rPropertyName ) |
131 | 0 | { |
132 | 0 | Any aRet; |
133 | |
|
134 | 0 | Reference< beans::XPropertySet > xPropSet; |
135 | |
|
136 | 0 | const std::vector< rtl::Reference< ChartType > > aTypes = |
137 | 0 | m_spChart2ModelContact->getDiagram()->getChartTypes(); |
138 | 0 | for( rtl::Reference<ChartType > const & xType : aTypes ) |
139 | 0 | { |
140 | 0 | if( xType->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK ) |
141 | 0 | { |
142 | 0 | xType->getPropertyValue( m_aPropertySetName ) >>= xPropSet; |
143 | 0 | } |
144 | 0 | } |
145 | 0 | if(xPropSet.is()) |
146 | 0 | aRet = xPropSet->getPropertyValue( rPropertyName ); |
147 | 0 | return aRet; |
148 | 0 | } |
149 | | |
150 | | void SAL_CALL UpDownBarWrapper::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ ) |
151 | 0 | { |
152 | 0 | OSL_FAIL("not implemented"); |
153 | 0 | } |
154 | | void SAL_CALL UpDownBarWrapper::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ ) |
155 | 0 | { |
156 | 0 | OSL_FAIL("not implemented"); |
157 | 0 | } |
158 | | void SAL_CALL UpDownBarWrapper::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) |
159 | 0 | { |
160 | 0 | OSL_FAIL("not implemented"); |
161 | 0 | } |
162 | | void SAL_CALL UpDownBarWrapper::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ ) |
163 | 0 | { |
164 | 0 | OSL_FAIL("not implemented"); |
165 | 0 | } |
166 | | |
167 | | //XMultiPropertySet |
168 | | //getPropertySetInfo() already declared in XPropertySet |
169 | | void SAL_CALL UpDownBarWrapper::setPropertyValues( const uno::Sequence< OUString >& rNameSeq, const uno::Sequence< uno::Any >& rValueSeq ) |
170 | 0 | { |
171 | 0 | sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() ); |
172 | 0 | for(sal_Int32 nN=0; nN<nMinCount; nN++) |
173 | 0 | { |
174 | 0 | const OUString& aPropertyName( rNameSeq[nN] ); |
175 | 0 | try |
176 | 0 | { |
177 | 0 | setPropertyValue( aPropertyName, rValueSeq[nN] ); |
178 | 0 | } |
179 | 0 | catch( const beans::UnknownPropertyException& ) |
180 | 0 | { |
181 | 0 | DBG_UNHANDLED_EXCEPTION("chart2"); |
182 | 0 | } |
183 | 0 | } |
184 | | //todo: store unknown properties elsewhere |
185 | 0 | } |
186 | | uno::Sequence< uno::Any > SAL_CALL UpDownBarWrapper::getPropertyValues( const uno::Sequence< OUString >& rNameSeq ) |
187 | 0 | { |
188 | 0 | Sequence< Any > aRetSeq; |
189 | 0 | if( rNameSeq.hasElements() ) |
190 | 0 | { |
191 | 0 | aRetSeq.realloc( rNameSeq.getLength() ); |
192 | 0 | auto pRetSeq = aRetSeq.getArray(); |
193 | 0 | for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++) |
194 | 0 | { |
195 | 0 | const OUString& aPropertyName( rNameSeq[nN] ); |
196 | 0 | pRetSeq[nN] = getPropertyValue( aPropertyName ); |
197 | 0 | } |
198 | 0 | } |
199 | 0 | return aRetSeq; |
200 | 0 | } |
201 | | void SAL_CALL UpDownBarWrapper::addPropertiesChangeListener( const uno::Sequence< OUString >& /* aPropertyNames */, const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ ) |
202 | 0 | { |
203 | 0 | OSL_FAIL("not implemented"); |
204 | 0 | } |
205 | | void SAL_CALL UpDownBarWrapper::removePropertiesChangeListener( const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ ) |
206 | 0 | { |
207 | 0 | OSL_FAIL("not implemented"); |
208 | 0 | } |
209 | | void SAL_CALL UpDownBarWrapper::firePropertiesChangeEvent( const uno::Sequence< OUString >& /* aPropertyNames */, const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ ) |
210 | 0 | { |
211 | 0 | OSL_FAIL("not implemented"); |
212 | 0 | } |
213 | | |
214 | | //XPropertyState |
215 | | beans::PropertyState SAL_CALL UpDownBarWrapper::getPropertyState( const OUString& rPropertyName ) |
216 | 0 | { |
217 | 0 | uno::Any aDefault( getPropertyDefault( rPropertyName ) ); |
218 | 0 | uno::Any aValue( getPropertyValue( rPropertyName ) ); |
219 | |
|
220 | 0 | if( aDefault == aValue ) |
221 | 0 | return beans::PropertyState_DEFAULT_VALUE; |
222 | | |
223 | 0 | return beans::PropertyState_DIRECT_VALUE; |
224 | 0 | } |
225 | | uno::Sequence< beans::PropertyState > SAL_CALL UpDownBarWrapper::getPropertyStates( const uno::Sequence< OUString >& rNameSeq ) |
226 | 0 | { |
227 | 0 | Sequence< beans::PropertyState > aRetSeq; |
228 | 0 | if( rNameSeq.hasElements() ) |
229 | 0 | { |
230 | 0 | aRetSeq.realloc( rNameSeq.getLength() ); |
231 | 0 | auto pRetSeq = aRetSeq.getArray(); |
232 | 0 | for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++) |
233 | 0 | { |
234 | 0 | const OUString& aPropertyName( rNameSeq[nN] ); |
235 | 0 | pRetSeq[nN] = getPropertyState( aPropertyName ); |
236 | 0 | } |
237 | 0 | } |
238 | 0 | return aRetSeq; |
239 | 0 | } |
240 | | void SAL_CALL UpDownBarWrapper::setPropertyToDefault( const OUString& rPropertyName ) |
241 | 0 | { |
242 | 0 | setPropertyValue( rPropertyName, getPropertyDefault(rPropertyName) ); |
243 | 0 | } |
244 | | |
245 | | uno::Any SAL_CALL UpDownBarWrapper::getPropertyDefault( const OUString& rPropertyName ) |
246 | 0 | { |
247 | 0 | static const ::chart::tPropertyValueMap aStaticDefaults = []() |
248 | 0 | { |
249 | 0 | ::chart::tPropertyValueMap aTmp; |
250 | 0 | ::chart::LinePropertiesHelper::AddDefaultsToMap( aTmp ); |
251 | 0 | ::chart::FillProperties::AddDefaultsToMap( aTmp ); |
252 | 0 | return aTmp; |
253 | 0 | }(); |
254 | 0 | tPropertyValueMap::const_iterator aFound( aStaticDefaults.find( StaticUpDownBarWrapperInfoHelper().getHandleByName( rPropertyName ) ) ); |
255 | 0 | if( aFound == aStaticDefaults.end() ) |
256 | 0 | return uno::Any(); |
257 | 0 | return (*aFound).second; |
258 | 0 | } |
259 | | |
260 | | //XMultiPropertyStates |
261 | | //getPropertyStates() already declared in XPropertyState |
262 | | void SAL_CALL UpDownBarWrapper::setAllPropertiesToDefault( ) |
263 | 0 | { |
264 | 0 | const Sequence< beans::Property >& rPropSeq = StaticUpDownBarWrapperPropertyArray(); |
265 | 0 | for(beans::Property const & prop : rPropSeq) |
266 | 0 | { |
267 | 0 | setPropertyToDefault( prop.Name ); |
268 | 0 | } |
269 | 0 | } |
270 | | void SAL_CALL UpDownBarWrapper::setPropertiesToDefault( const uno::Sequence< OUString >& rNameSeq ) |
271 | 0 | { |
272 | 0 | for(OUString const & s : rNameSeq) |
273 | 0 | { |
274 | 0 | setPropertyToDefault( s ); |
275 | 0 | } |
276 | 0 | } |
277 | | uno::Sequence< uno::Any > SAL_CALL UpDownBarWrapper::getPropertyDefaults( const uno::Sequence< OUString >& rNameSeq ) |
278 | 0 | { |
279 | 0 | Sequence< Any > aRetSeq; |
280 | 0 | if( rNameSeq.hasElements() ) |
281 | 0 | { |
282 | 0 | aRetSeq.realloc( rNameSeq.getLength() ); |
283 | 0 | auto pRetSeq = aRetSeq.getArray(); |
284 | 0 | for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++) |
285 | 0 | { |
286 | 0 | const OUString& aPropertyName( rNameSeq[nN] ); |
287 | 0 | pRetSeq[nN] = getPropertyDefault( aPropertyName ); |
288 | 0 | } |
289 | 0 | } |
290 | 0 | return aRetSeq; |
291 | 0 | } |
292 | | |
293 | | OUString SAL_CALL UpDownBarWrapper::getImplementationName() |
294 | 0 | { |
295 | 0 | return u"com.sun.star.comp.chart.ChartArea"_ustr; |
296 | 0 | } |
297 | | |
298 | | sal_Bool SAL_CALL UpDownBarWrapper::supportsService( const OUString& rServiceName ) |
299 | 0 | { |
300 | 0 | return cppu::supportsService(this, rServiceName); |
301 | 0 | } |
302 | | |
303 | | css::uno::Sequence< OUString > SAL_CALL UpDownBarWrapper::getSupportedServiceNames() |
304 | 0 | { |
305 | 0 | return { |
306 | 0 | u"com.sun.star.chart.ChartArea"_ustr, |
307 | 0 | u"com.sun.star.drawing.LineProperties"_ustr, |
308 | 0 | u"com.sun.star.drawing.FillProperties"_ustr, |
309 | 0 | u"com.sun.star.xml.UserDefinedAttributesSupplier"_ustr |
310 | 0 | }; |
311 | 0 | } |
312 | | |
313 | | } // namespace chart::wrapper |
314 | | |
315 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |