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