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