Debian Codegraph @

chart2/source/controller/chartapiwrapper/MinMaxLineWrapper.cxx

raw
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 "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>
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 Sequence< Property >& StaticMinMaxLineWrapperPropertyArray()
45 {
46 static Sequence< Property > aPropSeq = []()
47 {
48 std::vector< css::beans::Property > aProperties;
49
50 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
51 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
52
53 std::sort( aProperties.begin(), aProperties.end(),
54 ::chart::PropertyNameLess() );
55
56 return comphelper::containerToSequence( aProperties );
57 }();
58 return aPropSeq;
59 };
60
61 ::cppu::OPropertyArrayHelper& StaticMinMaxLineWrapperInfoHelper()
62 {
63 static ::cppu::OPropertyArrayHelper aPropHelper( StaticMinMaxLineWrapperPropertyArray() );
64 return aPropHelper;
65 };
66
67 uno::Reference< beans::XPropertySetInfo >& StaticMinMaxLineWrapperInfo()
68 {
69 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
70 ::cppu::OPropertySetHelper::createPropertySetInfo( StaticMinMaxLineWrapperInfoHelper() ) );
71 return xPropertySetInfo;
72 };
73
74 } // anonymous namespace
75
76 namespace chart::wrapper
77 {
78
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 ))
82 {
83 }
84
85 MinMaxLineWrapper::~MinMaxLineWrapper()
86 {
87 }
88
89 // ____ XComponent ____
90 void SAL_CALL MinMaxLineWrapper::dispose()
91 {
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 ) );
95 }
96
97 void SAL_CALL MinMaxLineWrapper::addEventListener(
98 const Reference< lang::XEventListener >& xListener )
99 {
100 std::unique_lock g(m_aMutex);
101 m_aEventListenerContainer.addInterface( g, xListener );
102 }
103
104 void SAL_CALL MinMaxLineWrapper::removeEventListener(
105 const Reference< lang::XEventListener >& aListener )
106 {
107 std::unique_lock g(m_aMutex);
108 m_aEventListenerContainer.removeInterface( g, aListener );
109 }
110
111 //XPropertySet
112 uno::Reference< beans::XPropertySetInfo > SAL_CALL MinMaxLineWrapper::getPropertySetInfo()
113 {
114 return StaticMinMaxLineWrapperInfo();
115 }
116
117 void SAL_CALL MinMaxLineWrapper::setPropertyValue( const OUString& rPropertyName, const uno::Any& rValue )
118 {
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 )
122 {
123 if( xType->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK )
124 {
125 const std::vector< rtl::Reference< DataSeries > > & aSeriesSeq( xType->getDataSeries2() );
126 if(!aSeriesSeq.empty())
127 {
128 if(aSeriesSeq[0].is())
129 {
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] );
136 else
137 aSeriesSeq[0]->setPropertyValue( rPropertyName, rValue );
138 return;
139 }
140 }
141 }
142 }
143 }
144 uno::Any SAL_CALL MinMaxLineWrapper::getPropertyValue( const OUString& rPropertyName )
145 {
146 Any aRet;
147
148 rtl::Reference< DataSeries > xPropSet;
149
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 )
153 {
154 if( xType->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK )
155 {
156 const std::vector< rtl::Reference< DataSeries > > & aSeriesSeq( xType->getDataSeries2() );
157 if(!aSeriesSeq.empty())
158 {
159 xPropSet = aSeriesSeq[0];
160 break;
161 }
162 }
163 }
164 if(xPropSet.is())
165 {
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 );
172 else
173 aRet = xPropSet->getPropertyValue( rPropertyName );
174
175 }
176 return aRet;
177 }
178
179 void SAL_CALL MinMaxLineWrapper::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
180 {
181 OSL_FAIL("not implemented");
182 }
183 void SAL_CALL MinMaxLineWrapper::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
184 {
185 OSL_FAIL("not implemented");
186 }
187 void SAL_CALL MinMaxLineWrapper::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
188 {
189 OSL_FAIL("not implemented");
190 }
191 void SAL_CALL MinMaxLineWrapper::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
192 {
193 OSL_FAIL("not implemented");
194 }
195
196 //XMultiPropertySet
197 //getPropertySetInfo() already declared in XPropertySet
198 void SAL_CALL MinMaxLineWrapper::setPropertyValues( const uno::Sequence< OUString >& rNameSeq, const uno::Sequence< uno::Any >& rValueSeq )
199 {
200 sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() );
201 for(sal_Int32 nN=0; nN<nMinCount; nN++)
202 {
203 const OUString& aPropertyName( rNameSeq[nN] );
204 try
205 {
206 setPropertyValue( aPropertyName, rValueSeq[nN] );
207 }
208 catch( const beans::UnknownPropertyException& )
209 {
210 DBG_UNHANDLED_EXCEPTION("chart2");
211 }
212 }
213 //todo: store unknown properties elsewhere
214 }
215 uno::Sequence< uno::Any > SAL_CALL MinMaxLineWrapper::getPropertyValues( const uno::Sequence< OUString >& rNameSeq )
216 {
217 Sequence< Any > aRetSeq;
218 if( rNameSeq.hasElements() )
219 {
220 aRetSeq.realloc( rNameSeq.getLength() );
221 auto pRetSeq = aRetSeq.getArray();
222 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
223 {
224 const OUString& aPropertyName( rNameSeq[nN] );
225 pRetSeq[nN] = getPropertyValue( aPropertyName );
226 }
227 }
228 return aRetSeq;
229 }
230 void SAL_CALL MinMaxLineWrapper::addPropertiesChangeListener(
231 const uno::Sequence< OUString >& /* aPropertyNames */,
232 const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
233 {
234 OSL_FAIL("not implemented");
235 }
236 void SAL_CALL MinMaxLineWrapper::removePropertiesChangeListener(
237 const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
238 {
239 OSL_FAIL("not implemented");
240 }
241 void SAL_CALL MinMaxLineWrapper::firePropertiesChangeEvent(
242 const uno::Sequence< OUString >& /* aPropertyNames */,
243 const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
244 {
245 OSL_FAIL("not implemented");
246 }
247
248 //XPropertyState
249 beans::PropertyState SAL_CALL MinMaxLineWrapper::getPropertyState( const OUString& rPropertyName )
250 {
251 if( rPropertyName == m_aWrappedLineJointProperty.getOuterName() )
252 return beans::PropertyState_DEFAULT_VALUE;
253
254 uno::Any aDefault( getPropertyDefault( rPropertyName ) );
255 uno::Any aValue( getPropertyValue( rPropertyName ) );
256
257 if( aDefault == aValue )
258 return beans::PropertyState_DEFAULT_VALUE;
259
260 return beans::PropertyState_DIRECT_VALUE;
261 }
262 uno::Sequence< beans::PropertyState > SAL_CALL MinMaxLineWrapper::getPropertyStates( const uno::Sequence< OUString >& rNameSeq )
263 {
264 Sequence< beans::PropertyState > aRetSeq;
265 if( rNameSeq.hasElements() )
266 {
267 aRetSeq.realloc( rNameSeq.getLength() );
268 auto pRetSeq = aRetSeq.getArray();
269 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
270 {
271 const OUString& aPropertyName( rNameSeq[nN] );
272 pRetSeq[nN] = getPropertyState( aPropertyName );
273 }
274 }
275 return aRetSeq;
276 }
277 void SAL_CALL MinMaxLineWrapper::setPropertyToDefault( const OUString& rPropertyName )
278 {
279 setPropertyValue( rPropertyName, getPropertyDefault(rPropertyName) );
280 }
281
282 uno::Any SAL_CALL MinMaxLineWrapper::getPropertyDefault( const OUString& rPropertyName )
283 {
284 static const ::chart::tPropertyValueMap aStaticDefaults = []
285 {
286 ::chart::tPropertyValueMap aTmp;
287 ::chart::LinePropertiesHelper::AddDefaultsToMap( aTmp );
288 return aTmp;
289 }();
290 tPropertyValueMap::const_iterator aFound( aStaticDefaults.find( StaticMinMaxLineWrapperInfoHelper().getHandleByName( rPropertyName ) ) );
291 if( aFound == aStaticDefaults.end() )
292 return uno::Any();
293 return (*aFound).second;
294 }
295
296 //XMultiPropertyStates
297 //getPropertyStates() already declared in XPropertyState
298 void SAL_CALL MinMaxLineWrapper::setAllPropertiesToDefault( )
299 {
300 const Sequence< beans::Property >& rPropSeq = StaticMinMaxLineWrapperPropertyArray();
301 for(beans::Property const & prop : rPropSeq)
302 {
303 setPropertyToDefault( prop.Name );
304 }
305 }
306 void SAL_CALL MinMaxLineWrapper::setPropertiesToDefault( const uno::Sequence< OUString >& rNameSeq )
307 {
308 for(OUString const & s : rNameSeq)
309 {
310 setPropertyToDefault( s );
311 }
312 }
313 uno::Sequence< uno::Any > SAL_CALL MinMaxLineWrapper::getPropertyDefaults( const uno::Sequence< OUString >& rNameSeq )
314 {
315 Sequence< Any > aRetSeq;
316 if( rNameSeq.hasElements() )
317 {
318 aRetSeq.realloc( rNameSeq.getLength() );
319 auto pRetSeq = aRetSeq.getArray();
320 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
321 {
322 const OUString& aPropertyName( rNameSeq[nN] );
323 pRetSeq[nN] = getPropertyDefault( aPropertyName );
324 }
325 }
326 return aRetSeq;
327 }
328
329 OUString SAL_CALL MinMaxLineWrapper::getImplementationName()
330 {
331 return u"com.sun.star.comp.chart.ChartLine"_ustr;
332 }
333
334 sal_Bool SAL_CALL MinMaxLineWrapper::supportsService( const OUString& rServiceName )
335 {
336 return cppu::supportsService(this, rServiceName);
337 }
338
339 css::uno::Sequence< OUString > SAL_CALL MinMaxLineWrapper::getSupportedServiceNames()
340 {
341 return {
342 u"com.sun.star.chart.ChartLine"_ustr,
343 u"com.sun.star.xml.UserDefinedAttributesSupplier"_ustr,
344 u"com.sun.star.drawing.LineProperties"_ustr
345 };
346 }
347
348 } // namespace chart::wrapper
349
350 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */