Line data Source code
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 :
21 : #include "MinMaxLineWrapper.hxx"
22 : #include "macros.hxx"
23 : #include "Chart2ModelContact.hxx"
24 : #include "DiagramHelper.hxx"
25 : #include "servicenames_charttypes.hxx"
26 : #include "ContainerHelper.hxx"
27 : #include <com/sun/star/chart2/XChartType.hpp>
28 : #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
29 : #include <com/sun/star/drawing/LineJoint.hpp>
30 :
31 : #include "LineProperties.hxx"
32 : #include "UserDefinedProperties.hxx"
33 :
34 : using namespace ::com::sun::star;
35 : using namespace ::com::sun::star::chart2;
36 :
37 : using ::com::sun::star::beans::Property;
38 : using ::osl::MutexGuard;
39 : using ::com::sun::star::uno::Reference;
40 : using ::com::sun::star::uno::Sequence;
41 : using ::com::sun::star::uno::Any;
42 : using ::rtl::OUString;
43 :
44 : namespace
45 : {
46 1 : static const OUString lcl_aServiceName(
47 : RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.ChartLine" ));
48 :
49 : struct StaticMinMaxLineWrapperDefaults_Initializer
50 : {
51 0 : ::chart::tPropertyValueMap* operator()()
52 : {
53 0 : static ::chart::tPropertyValueMap aStaticDefaults;
54 0 : lcl_AddDefaultsToMap( aStaticDefaults );
55 0 : return &aStaticDefaults;
56 : }
57 : private:
58 0 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
59 : {
60 0 : ::chart::LineProperties::AddDefaultsToMap( rOutMap );
61 0 : }
62 : };
63 :
64 : struct StaticMinMaxLineWrapperDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticMinMaxLineWrapperDefaults_Initializer >
65 : {
66 : };
67 :
68 : struct StaticMinMaxLineWrapperPropertyArray_Initializer
69 : {
70 0 : Sequence< Property >* operator()()
71 : {
72 0 : static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
73 0 : return &aPropSeq;
74 : }
75 :
76 : private:
77 0 : Sequence< Property > lcl_GetPropertySequence()
78 : {
79 0 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
80 :
81 0 : ::chart::LineProperties::AddPropertiesToVector( aProperties );
82 0 : ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
83 :
84 : ::std::sort( aProperties.begin(), aProperties.end(),
85 0 : ::chart::PropertyNameLess() );
86 :
87 0 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
88 : }
89 : };
90 :
91 : struct StaticMinMaxLineWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticMinMaxLineWrapperPropertyArray_Initializer >
92 : {
93 : };
94 :
95 : struct StaticMinMaxLineWrapperInfoHelper_Initializer
96 : {
97 0 : ::cppu::OPropertyArrayHelper* operator()()
98 : {
99 0 : static ::cppu::OPropertyArrayHelper aPropHelper( *StaticMinMaxLineWrapperPropertyArray::get() );
100 0 : return &aPropHelper;
101 : }
102 : };
103 :
104 : struct StaticMinMaxLineWrapperInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticMinMaxLineWrapperInfoHelper_Initializer >
105 : {
106 : };
107 :
108 : struct StaticMinMaxLineWrapperInfo_Initializer
109 : {
110 0 : uno::Reference< beans::XPropertySetInfo >* operator()()
111 : {
112 : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
113 0 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticMinMaxLineWrapperInfoHelper::get() ) );
114 0 : return &xPropertySetInfo;
115 : }
116 : };
117 :
118 : struct StaticMinMaxLineWrapperInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticMinMaxLineWrapperInfo_Initializer >
119 : {
120 : };
121 :
122 : } // anonymous namespace
123 :
124 : // --------------------------------------------------------------------------------
125 :
126 : namespace chart
127 : {
128 : namespace wrapper
129 : {
130 :
131 0 : MinMaxLineWrapper::MinMaxLineWrapper( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
132 : : m_spChart2ModelContact( spChart2ModelContact )
133 : , m_aEventListenerContainer( m_aMutex )
134 0 : , m_aWrappedLineJointProperty( "LineJoint", uno::makeAny( drawing::LineJoint_NONE ))
135 : {
136 0 : }
137 :
138 0 : MinMaxLineWrapper::~MinMaxLineWrapper()
139 : {
140 0 : }
141 :
142 : // ____ XComponent ____
143 0 : void SAL_CALL MinMaxLineWrapper::dispose()
144 : throw (uno::RuntimeException)
145 : {
146 0 : Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
147 0 : m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
148 0 : }
149 :
150 0 : void SAL_CALL MinMaxLineWrapper::addEventListener(
151 : const Reference< lang::XEventListener >& xListener )
152 : throw (uno::RuntimeException)
153 : {
154 0 : m_aEventListenerContainer.addInterface( xListener );
155 0 : }
156 :
157 0 : void SAL_CALL MinMaxLineWrapper::removeEventListener(
158 : const Reference< lang::XEventListener >& aListener )
159 : throw (uno::RuntimeException)
160 : {
161 0 : m_aEventListenerContainer.removeInterface( aListener );
162 0 : }
163 :
164 0 : ::cppu::IPropertyArrayHelper& MinMaxLineWrapper::getInfoHelper()
165 : {
166 0 : return *StaticMinMaxLineWrapperInfoHelper::get();
167 : }
168 :
169 : //XPropertySet
170 0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL MinMaxLineWrapper::getPropertySetInfo()
171 : throw (uno::RuntimeException)
172 : {
173 0 : return *StaticMinMaxLineWrapperInfo::get();
174 : }
175 :
176 0 : void SAL_CALL MinMaxLineWrapper::setPropertyValue( const ::rtl::OUString& rPropertyName, const uno::Any& rValue )
177 : throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
178 : {
179 0 : Reference< beans::XPropertySet > xPropSet(0);
180 :
181 0 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
182 : Sequence< Reference< chart2::XChartType > > aTypes(
183 0 : ::chart::DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
184 0 : for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
185 : {
186 0 : Reference< chart2::XChartType > xType( aTypes[nN] );
187 0 : if( xType->getChartType().equals(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
188 : {
189 0 : Reference< chart2::XDataSeriesContainer > xSeriesContainer(xType,uno::UNO_QUERY);
190 0 : if( xSeriesContainer.is() )
191 : {
192 0 : Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesContainer->getDataSeries() );
193 0 : if(aSeriesSeq.getLength())
194 : {
195 0 : xPropSet = Reference< beans::XPropertySet >(aSeriesSeq[0],uno::UNO_QUERY);
196 0 : if(xPropSet.is())
197 : {
198 0 : if( rPropertyName == "LineColor" )
199 0 : xPropSet->setPropertyValue( "Color", rValue );
200 0 : else if( rPropertyName == "LineTransparence" )
201 0 : xPropSet->setPropertyValue( "Transparency", rValue );
202 0 : else if( rPropertyName.equals( m_aWrappedLineJointProperty.getOuterName() ) )
203 0 : m_aWrappedLineJointProperty.setPropertyValue( rValue, xPropSet );
204 : else
205 0 : xPropSet->setPropertyValue( rPropertyName, rValue );
206 0 : return;
207 : }
208 0 : }
209 0 : }
210 : }
211 0 : }
212 : }
213 0 : uno::Any SAL_CALL MinMaxLineWrapper::getPropertyValue( const ::rtl::OUString& rPropertyName )
214 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
215 : {
216 0 : Any aRet;
217 :
218 0 : Reference< beans::XPropertySet > xPropSet(0);
219 :
220 0 : Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
221 : Sequence< Reference< chart2::XChartType > > aTypes(
222 0 : ::chart::DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
223 0 : for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
224 : {
225 0 : Reference< chart2::XChartType > xType( aTypes[nN] );
226 0 : if( xType->getChartType().equals(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
227 : {
228 0 : Reference< chart2::XDataSeriesContainer > xSeriesContainer(xType,uno::UNO_QUERY);
229 0 : if( xSeriesContainer.is() )
230 : {
231 0 : Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesContainer->getDataSeries() );
232 0 : if(aSeriesSeq.getLength())
233 : {
234 0 : xPropSet = Reference< beans::XPropertySet >(aSeriesSeq[0],uno::UNO_QUERY);
235 : break;
236 0 : }
237 0 : }
238 : }
239 0 : }
240 0 : if(xPropSet.is())
241 : {
242 0 : if( rPropertyName == "LineColor" )
243 0 : aRet = xPropSet->getPropertyValue( "Color" );
244 0 : else if( rPropertyName == "LineTransparence" )
245 0 : aRet = xPropSet->getPropertyValue( "Transparency" );
246 0 : else if( rPropertyName.equals( m_aWrappedLineJointProperty.getOuterName() ) )
247 0 : aRet = m_aWrappedLineJointProperty.getPropertyValue( xPropSet );
248 : else
249 0 : aRet = xPropSet->getPropertyValue( rPropertyName );
250 :
251 : }
252 0 : return aRet;
253 : }
254 :
255 0 : void SAL_CALL MinMaxLineWrapper::addPropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
256 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
257 : {
258 : OSL_FAIL("not implemented");
259 0 : }
260 0 : void SAL_CALL MinMaxLineWrapper::removePropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
261 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
262 : {
263 : OSL_FAIL("not implemented");
264 0 : }
265 0 : void SAL_CALL MinMaxLineWrapper::addVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
266 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
267 : {
268 : OSL_FAIL("not implemented");
269 0 : }
270 0 : void SAL_CALL MinMaxLineWrapper::removeVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
271 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
272 : {
273 : OSL_FAIL("not implemented");
274 0 : }
275 :
276 : //XMultiPropertySet
277 : //getPropertySetInfo() already declared in XPropertySet
278 0 : void SAL_CALL MinMaxLineWrapper::setPropertyValues( const uno::Sequence< ::rtl::OUString >& rNameSeq, const uno::Sequence< uno::Any >& rValueSeq )
279 : throw (beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
280 : {
281 0 : sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() );
282 0 : for(sal_Int32 nN=0; nN<nMinCount; nN++)
283 : {
284 0 : ::rtl::OUString aPropertyName( rNameSeq[nN] );
285 : try
286 : {
287 0 : this->setPropertyValue( aPropertyName, rValueSeq[nN] );
288 : }
289 0 : catch( const beans::UnknownPropertyException& ex )
290 : {
291 : ASSERT_EXCEPTION( ex );
292 : }
293 0 : }
294 : //todo: store unknown properties elsewhere
295 0 : }
296 0 : uno::Sequence< uno::Any > SAL_CALL MinMaxLineWrapper::getPropertyValues( const uno::Sequence< ::rtl::OUString >& rNameSeq )
297 : throw (uno::RuntimeException)
298 : {
299 0 : Sequence< Any > aRetSeq;
300 0 : if( rNameSeq.getLength() )
301 : {
302 0 : aRetSeq.realloc( rNameSeq.getLength() );
303 0 : for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
304 : {
305 0 : ::rtl::OUString aPropertyName( rNameSeq[nN] );
306 0 : aRetSeq[nN] = this->getPropertyValue( aPropertyName );
307 0 : }
308 : }
309 0 : return aRetSeq;
310 : }
311 0 : void SAL_CALL MinMaxLineWrapper::addPropertiesChangeListener(
312 : const uno::Sequence< ::rtl::OUString >& /* aPropertyNames */,
313 : const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
314 : throw (uno::RuntimeException)
315 : {
316 : OSL_FAIL("not implemented");
317 0 : }
318 0 : void SAL_CALL MinMaxLineWrapper::removePropertiesChangeListener(
319 : const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
320 : throw (uno::RuntimeException)
321 : {
322 : OSL_FAIL("not implemented");
323 0 : }
324 0 : void SAL_CALL MinMaxLineWrapper::firePropertiesChangeEvent(
325 : const uno::Sequence< ::rtl::OUString >& /* aPropertyNames */,
326 : const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
327 : throw (uno::RuntimeException)
328 : {
329 : OSL_FAIL("not implemented");
330 0 : }
331 :
332 : //XPropertyState
333 0 : beans::PropertyState SAL_CALL MinMaxLineWrapper::getPropertyState( const ::rtl::OUString& rPropertyName )
334 : throw (beans::UnknownPropertyException, uno::RuntimeException)
335 : {
336 0 : if( rPropertyName.equals( m_aWrappedLineJointProperty.getOuterName() ) )
337 0 : return beans::PropertyState_DEFAULT_VALUE;
338 :
339 0 : uno::Any aDefault( this->getPropertyDefault( rPropertyName ) );
340 0 : uno::Any aValue( this->getPropertyValue( rPropertyName ) );
341 :
342 0 : if( aDefault == aValue )
343 0 : return beans::PropertyState_DEFAULT_VALUE;
344 :
345 0 : return beans::PropertyState_DIRECT_VALUE;
346 : }
347 0 : uno::Sequence< beans::PropertyState > SAL_CALL MinMaxLineWrapper::getPropertyStates( const uno::Sequence< ::rtl::OUString >& rNameSeq )
348 : throw (beans::UnknownPropertyException, uno::RuntimeException)
349 : {
350 0 : Sequence< beans::PropertyState > aRetSeq;
351 0 : if( rNameSeq.getLength() )
352 : {
353 0 : aRetSeq.realloc( rNameSeq.getLength() );
354 0 : for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
355 : {
356 0 : ::rtl::OUString aPropertyName( rNameSeq[nN] );
357 0 : aRetSeq[nN] = this->getPropertyState( aPropertyName );
358 0 : }
359 : }
360 0 : return aRetSeq;
361 : }
362 0 : void SAL_CALL MinMaxLineWrapper::setPropertyToDefault( const ::rtl::OUString& rPropertyName )
363 : throw (beans::UnknownPropertyException, uno::RuntimeException)
364 : {
365 0 : this->setPropertyValue( rPropertyName, this->getPropertyDefault(rPropertyName) );
366 0 : }
367 :
368 0 : uno::Any SAL_CALL MinMaxLineWrapper::getPropertyDefault( const ::rtl::OUString& rPropertyName )
369 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
370 : {
371 0 : const tPropertyValueMap& rStaticDefaults = *StaticMinMaxLineWrapperDefaults::get();
372 0 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( getInfoHelper().getHandleByName( rPropertyName ) ) );
373 0 : if( aFound == rStaticDefaults.end() )
374 0 : return uno::Any();
375 0 : return (*aFound).second;
376 : }
377 :
378 : //XMultiPropertyStates
379 : //getPropertyStates() already declared in XPropertyState
380 0 : void SAL_CALL MinMaxLineWrapper::setAllPropertiesToDefault( )
381 : throw (uno::RuntimeException)
382 : {
383 0 : const Sequence< beans::Property >& rPropSeq = *StaticMinMaxLineWrapperPropertyArray::get();
384 0 : for(sal_Int32 nN=0; nN<rPropSeq.getLength(); nN++)
385 : {
386 0 : ::rtl::OUString aPropertyName( rPropSeq[nN].Name );
387 0 : this->setPropertyToDefault( aPropertyName );
388 0 : }
389 0 : }
390 0 : void SAL_CALL MinMaxLineWrapper::setPropertiesToDefault( const uno::Sequence< ::rtl::OUString >& rNameSeq )
391 : throw (beans::UnknownPropertyException, uno::RuntimeException)
392 : {
393 0 : for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
394 : {
395 0 : ::rtl::OUString aPropertyName( rNameSeq[nN] );
396 0 : this->setPropertyToDefault( aPropertyName );
397 0 : }
398 0 : }
399 0 : uno::Sequence< uno::Any > SAL_CALL MinMaxLineWrapper::getPropertyDefaults( const uno::Sequence< ::rtl::OUString >& rNameSeq )
400 : throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
401 : {
402 0 : Sequence< Any > aRetSeq;
403 0 : if( rNameSeq.getLength() )
404 : {
405 0 : aRetSeq.realloc( rNameSeq.getLength() );
406 0 : for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
407 : {
408 0 : ::rtl::OUString aPropertyName( rNameSeq[nN] );
409 0 : aRetSeq[nN] = this->getPropertyDefault( aPropertyName );
410 0 : }
411 : }
412 0 : return aRetSeq;
413 : }
414 :
415 :
416 : // ================================================================================
417 :
418 0 : Sequence< OUString > MinMaxLineWrapper::getSupportedServiceNames_Static()
419 : {
420 0 : Sequence< OUString > aServices( 3 );
421 0 : aServices[ 0 ] = "com.sun.star.chart.ChartLine";
422 0 : aServices[ 1 ] = "com.sun.star.xml.UserDefinedAttributesSupplier";
423 0 : aServices[ 2 ] = "com.sun.star.drawing.LineProperties";
424 :
425 0 : return aServices;
426 : }
427 :
428 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
429 0 : APPHELPER_XSERVICEINFO_IMPL( MinMaxLineWrapper, lcl_aServiceName );
430 :
431 : } // namespace wrapper
432 3 : } // namespace chart
433 :
434 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|