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