1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chartcontroller.hxx"
26
27 #include "UpDownBarWrapper.hxx"
28 #include "macros.hxx"
29 #include "Chart2ModelContact.hxx"
30 #include "DiagramHelper.hxx"
31 #include "servicenames_charttypes.hxx"
32 #include "ContainerHelper.hxx"
33 #include <com/sun/star/chart2/XChartType.hpp>
34 #include <com/sun/star/chart2/XDataSeriesContainer.hpp>
35
36 #include "LineProperties.hxx"
37 #include "FillProperties.hxx"
38 // #include "NamedProperties.hxx"
39 #include "UserDefinedProperties.hxx"
40
41 using namespace ::com::sun::star;
42 using namespace ::com::sun::star::chart2;
43
44 using ::com::sun::star::beans::Property;
45 using ::osl::MutexGuard;
46 using ::com::sun::star::uno::Reference;
47 using ::com::sun::star::uno::Sequence;
48 using ::com::sun::star::uno::Any;
49 using ::rtl::OUString;
50
51 namespace
52 {
53 static const OUString lcl_aServiceName(
54 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.ChartArea" ));
55
56 struct StaticUpDownBarWrapperPropertyArray_Initializer
57 {
operator ()__anonc1b286ec0111::StaticUpDownBarWrapperPropertyArray_Initializer58 Sequence< Property >* operator()()
59 {
60 static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
61 return &aPropSeq;
62 }
63
64 private:
lcl_GetPropertySequence__anonc1b286ec0111::StaticUpDownBarWrapperPropertyArray_Initializer65 Sequence< Property > lcl_GetPropertySequence()
66 {
67 ::std::vector< ::com::sun::star::beans::Property > aProperties;
68
69 ::chart::LineProperties::AddPropertiesToVector( aProperties );
70 ::chart::FillProperties::AddPropertiesToVector( aProperties );
71 //::chart::NamedProperties::AddPropertiesToVector( aProperties );
72 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
73
74 ::std::sort( aProperties.begin(), aProperties.end(),
75 ::chart::PropertyNameLess() );
76
77 return ::chart::ContainerHelper::ContainerToSequence( aProperties );
78 }
79 };
80
81 struct StaticUpDownBarWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticUpDownBarWrapperPropertyArray_Initializer >
82 {
83 };
84
85 struct StaticUpDownBarWrapperInfoHelper_Initializer
86 {
operator ()__anonc1b286ec0111::StaticUpDownBarWrapperInfoHelper_Initializer87 ::cppu::OPropertyArrayHelper* operator()()
88 {
89 static ::cppu::OPropertyArrayHelper aPropHelper( *StaticUpDownBarWrapperPropertyArray::get() );
90 return &aPropHelper;
91 }
92 };
93
94 struct StaticUpDownBarWrapperInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticUpDownBarWrapperInfoHelper_Initializer >
95 {
96 };
97
98 struct StaticUpDownBarWrapperInfo_Initializer
99 {
operator ()__anonc1b286ec0111::StaticUpDownBarWrapperInfo_Initializer100 uno::Reference< beans::XPropertySetInfo >* operator()()
101 {
102 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
103 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticUpDownBarWrapperInfoHelper::get() ) );
104 return &xPropertySetInfo;
105 }
106 };
107
108 struct StaticUpDownBarWrapperInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticUpDownBarWrapperInfo_Initializer >
109 {
110 };
111
112 struct StaticUpDownBarWrapperDefaults_Initializer
113 {
operator ()__anonc1b286ec0111::StaticUpDownBarWrapperDefaults_Initializer114 ::chart::tPropertyValueMap* operator()()
115 {
116 static ::chart::tPropertyValueMap aStaticDefaults;
117 lcl_AddDefaultsToMap( aStaticDefaults );
118 return &aStaticDefaults;
119 }
120 private:
lcl_AddDefaultsToMap__anonc1b286ec0111::StaticUpDownBarWrapperDefaults_Initializer121 void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
122 {
123 ::chart::LineProperties::AddDefaultsToMap( rOutMap );
124 ::chart::FillProperties::AddDefaultsToMap( rOutMap );
125 }
126 };
127
128 struct StaticUpDownBarWrapperDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticUpDownBarWrapperDefaults_Initializer >
129 {
130 };
131
132 } // anonymous namespace
133
134 // --------------------------------------------------------------------------------
135
136 namespace chart
137 {
138 namespace wrapper
139 {
140
UpDownBarWrapper(bool bUp,::boost::shared_ptr<Chart2ModelContact> spChart2ModelContact)141 UpDownBarWrapper::UpDownBarWrapper(
142 bool bUp, ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
143 : m_spChart2ModelContact( spChart2ModelContact )
144 , m_aEventListenerContainer( m_aMutex )
145 , m_aPropertySetName( bUp ? C2U("WhiteDay") : C2U("BlackDay") )
146 {
147 }
148
~UpDownBarWrapper()149 UpDownBarWrapper::~UpDownBarWrapper()
150 {
151 }
152
153 // ____ XComponent ____
dispose()154 void SAL_CALL UpDownBarWrapper::dispose()
155 {
156 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
157 m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
158 }
159
addEventListener(const Reference<lang::XEventListener> & xListener)160 void SAL_CALL UpDownBarWrapper::addEventListener(
161 const Reference< lang::XEventListener >& xListener )
162 {
163 m_aEventListenerContainer.addInterface( xListener );
164 }
165
removeEventListener(const Reference<lang::XEventListener> & aListener)166 void SAL_CALL UpDownBarWrapper::removeEventListener(
167 const Reference< lang::XEventListener >& aListener )
168 {
169 m_aEventListenerContainer.removeInterface( aListener );
170 }
171
getInfoHelper()172 ::cppu::IPropertyArrayHelper& UpDownBarWrapper::getInfoHelper()
173 {
174 return *StaticUpDownBarWrapperInfoHelper::get();
175 }
176
177 //XPropertySet
getPropertySetInfo()178 uno::Reference< beans::XPropertySetInfo > SAL_CALL UpDownBarWrapper::getPropertySetInfo()
179 {
180 return *StaticUpDownBarWrapperInfo::get();
181 }
setPropertyValue(const::rtl::OUString & rPropertyName,const uno::Any & rValue)182 void SAL_CALL UpDownBarWrapper::setPropertyValue( const ::rtl::OUString& rPropertyName, const uno::Any& rValue )
183 {
184 Reference< beans::XPropertySet > xPropSet(0);
185
186 Sequence< Reference< chart2::XChartType > > aTypes(
187 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
188 for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
189 {
190 Reference< chart2::XChartType > xType( aTypes[nN] );
191 if( xType->getChartType().equals(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
192 {
193 Reference< beans::XPropertySet > xTypeProps( aTypes[nN], uno::UNO_QUERY );
194 if(xTypeProps.is())
195 {
196 xTypeProps->getPropertyValue( m_aPropertySetName ) >>= xPropSet;
197 }
198 }
199 }
200 if(xPropSet.is())
201 xPropSet->setPropertyValue( rPropertyName, rValue );
202 }
getPropertyValue(const::rtl::OUString & rPropertyName)203 uno::Any SAL_CALL UpDownBarWrapper::getPropertyValue( const ::rtl::OUString& rPropertyName )
204 {
205 Any aRet;
206
207 Reference< beans::XPropertySet > xPropSet(0);
208
209 Sequence< Reference< chart2::XChartType > > aTypes(
210 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact->getChart2Diagram() ) );
211 for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
212 {
213 Reference< chart2::XChartType > xType( aTypes[nN] );
214 if( xType->getChartType().equals(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
215 {
216 Reference< beans::XPropertySet > xTypeProps( aTypes[nN], uno::UNO_QUERY );
217 if(xTypeProps.is())
218 {
219 xTypeProps->getPropertyValue( m_aPropertySetName ) >>= xPropSet;
220 }
221 }
222 }
223 if(xPropSet.is())
224 aRet = xPropSet->getPropertyValue( rPropertyName );
225 return aRet;
226 }
227
addPropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)228 void SAL_CALL UpDownBarWrapper::addPropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
229 {
230 OSL_ENSURE(false,"not implemented");
231 }
removePropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)232 void SAL_CALL UpDownBarWrapper::removePropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
233 {
234 OSL_ENSURE(false,"not implemented");
235 }
addVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)236 void SAL_CALL UpDownBarWrapper::addVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
237 {
238 OSL_ENSURE(false,"not implemented");
239 }
removeVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)240 void SAL_CALL UpDownBarWrapper::removeVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
241 {
242 OSL_ENSURE(false,"not implemented");
243 }
244
245 //XMultiPropertySet
246 //getPropertySetInfo() already declared in XPropertySet
setPropertyValues(const uno::Sequence<::rtl::OUString> & rNameSeq,const uno::Sequence<uno::Any> & rValueSeq)247 void SAL_CALL UpDownBarWrapper::setPropertyValues( const uno::Sequence< ::rtl::OUString >& rNameSeq, const uno::Sequence< uno::Any >& rValueSeq )
248 {
249 bool bUnknownProperty = false;
250 sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() );
251 for(sal_Int32 nN=0; nN<nMinCount; nN++)
252 {
253 ::rtl::OUString aPropertyName( rNameSeq[nN] );
254 try
255 {
256 this->setPropertyValue( aPropertyName, rValueSeq[nN] );
257 }
258 catch( beans::UnknownPropertyException& ex )
259 {
260 ASSERT_EXCEPTION( ex );
261 bUnknownProperty = true;
262 }
263 }
264 //todo: store unknown properties elsewhere
265 // if( bUnknownProperty )
266 // throw beans::UnknownPropertyException();
267 }
getPropertyValues(const uno::Sequence<::rtl::OUString> & rNameSeq)268 uno::Sequence< uno::Any > SAL_CALL UpDownBarWrapper::getPropertyValues( const uno::Sequence< ::rtl::OUString >& rNameSeq )
269 {
270 Sequence< Any > aRetSeq;
271 if( rNameSeq.getLength() )
272 {
273 aRetSeq.realloc( rNameSeq.getLength() );
274 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
275 {
276 ::rtl::OUString aPropertyName( rNameSeq[nN] );
277 aRetSeq[nN] = this->getPropertyValue( aPropertyName );
278 }
279 }
280 return aRetSeq;
281 }
addPropertiesChangeListener(const uno::Sequence<::rtl::OUString> &,const uno::Reference<beans::XPropertiesChangeListener> &)282 void SAL_CALL UpDownBarWrapper::addPropertiesChangeListener( const uno::Sequence< ::rtl::OUString >& /* aPropertyNames */, const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
283 {
284 OSL_ENSURE(false,"not implemented");
285 }
removePropertiesChangeListener(const uno::Reference<beans::XPropertiesChangeListener> &)286 void SAL_CALL UpDownBarWrapper::removePropertiesChangeListener( const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
287 {
288 OSL_ENSURE(false,"not implemented");
289 }
firePropertiesChangeEvent(const uno::Sequence<::rtl::OUString> &,const uno::Reference<beans::XPropertiesChangeListener> &)290 void SAL_CALL UpDownBarWrapper::firePropertiesChangeEvent( const uno::Sequence< ::rtl::OUString >& /* aPropertyNames */, const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
291 {
292 OSL_ENSURE(false,"not implemented");
293 }
294
295 //XPropertyState
getPropertyState(const::rtl::OUString & rPropertyName)296 beans::PropertyState SAL_CALL UpDownBarWrapper::getPropertyState( const ::rtl::OUString& rPropertyName )
297 {
298 uno::Any aDefault( this->getPropertyDefault( rPropertyName ) );
299 uno::Any aValue( this->getPropertyValue( rPropertyName ) );
300
301 if( aDefault == aValue )
302 return beans::PropertyState_DEFAULT_VALUE;
303
304 return beans::PropertyState_DIRECT_VALUE;
305 }
getPropertyStates(const uno::Sequence<::rtl::OUString> & rNameSeq)306 uno::Sequence< beans::PropertyState > SAL_CALL UpDownBarWrapper::getPropertyStates( const uno::Sequence< ::rtl::OUString >& rNameSeq )
307 {
308 Sequence< beans::PropertyState > aRetSeq;
309 if( rNameSeq.getLength() )
310 {
311 aRetSeq.realloc( rNameSeq.getLength() );
312 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
313 {
314 ::rtl::OUString aPropertyName( rNameSeq[nN] );
315 aRetSeq[nN] = this->getPropertyState( aPropertyName );
316 }
317 }
318 return aRetSeq;
319 }
setPropertyToDefault(const::rtl::OUString & rPropertyName)320 void SAL_CALL UpDownBarWrapper::setPropertyToDefault( const ::rtl::OUString& rPropertyName )
321 {
322 this->setPropertyValue( rPropertyName, this->getPropertyDefault(rPropertyName) );
323 }
324
getPropertyDefault(const::rtl::OUString & rPropertyName)325 uno::Any SAL_CALL UpDownBarWrapper::getPropertyDefault( const ::rtl::OUString& rPropertyName )
326 {
327 const tPropertyValueMap& rStaticDefaults = *StaticUpDownBarWrapperDefaults::get();
328 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( getInfoHelper().getHandleByName( rPropertyName ) ) );
329 if( aFound == rStaticDefaults.end() )
330 return uno::Any();
331 return (*aFound).second;
332 }
333
334 //XMultiPropertyStates
335 //getPropertyStates() already declared in XPropertyState
setAllPropertiesToDefault()336 void SAL_CALL UpDownBarWrapper::setAllPropertiesToDefault( )
337 {
338 const Sequence< beans::Property >& rPropSeq = *StaticUpDownBarWrapperPropertyArray::get();
339 for(sal_Int32 nN=0; nN<rPropSeq.getLength(); nN++)
340 {
341 ::rtl::OUString aPropertyName( rPropSeq[nN].Name );
342 this->setPropertyToDefault( aPropertyName );
343 }
344 }
setPropertiesToDefault(const uno::Sequence<::rtl::OUString> & rNameSeq)345 void SAL_CALL UpDownBarWrapper::setPropertiesToDefault( const uno::Sequence< ::rtl::OUString >& rNameSeq )
346 {
347 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
348 {
349 ::rtl::OUString aPropertyName( rNameSeq[nN] );
350 this->setPropertyToDefault( aPropertyName );
351 }
352 }
getPropertyDefaults(const uno::Sequence<::rtl::OUString> & rNameSeq)353 uno::Sequence< uno::Any > SAL_CALL UpDownBarWrapper::getPropertyDefaults( const uno::Sequence< ::rtl::OUString >& rNameSeq )
354 {
355 Sequence< Any > aRetSeq;
356 if( rNameSeq.getLength() )
357 {
358 aRetSeq.realloc( rNameSeq.getLength() );
359 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
360 {
361 ::rtl::OUString aPropertyName( rNameSeq[nN] );
362 aRetSeq[nN] = this->getPropertyDefault( aPropertyName );
363 }
364 }
365 return aRetSeq;
366 }
367
368
369 // ================================================================================
370
getSupportedServiceNames_Static()371 Sequence< OUString > UpDownBarWrapper::getSupportedServiceNames_Static()
372 {
373 Sequence< OUString > aServices( 4 );
374 aServices[ 0 ] = ::rtl::OUString::createFromAscii( "com.sun.star.chart.ChartArea" );
375 aServices[ 1 ] = ::rtl::OUString::createFromAscii( "com.sun.star.drawing.LineProperties" );
376 aServices[ 2 ] = ::rtl::OUString::createFromAscii( "com.sun.star.drawing.FillProperties" );
377 aServices[ 3 ] = ::rtl::OUString::createFromAscii( "com.sun.star.xml.UserDefinedAttributeSupplier" );
378
379 return aServices;
380 }
381
382 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
383 APPHELPER_XSERVICEINFO_IMPL( UpDownBarWrapper, lcl_aServiceName );
384
385 } // namespace wrapper
386 } // namespace chart
387