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_chart2.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 ()__anonce4454840111::StaticMinMaxLineWrapperDefaults_Initializer57     ::chart::tPropertyValueMap* operator()()
58     {
59         static ::chart::tPropertyValueMap aStaticDefaults;
60         lcl_AddDefaultsToMap( aStaticDefaults );
61         return &aStaticDefaults;
62     }
63 private:
lcl_AddDefaultsToMap__anonce4454840111::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 ()__anonce4454840111::StaticMinMaxLineWrapperPropertyArray_Initializer76     Sequence< Property >* operator()()
77     {
78         static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
79         return &aPropSeq;
80     }
81 
82 private:
lcl_GetPropertySequence__anonce4454840111::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 ()__anonce4454840111::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 ()__anonce4454840111::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     throw (uno::RuntimeException)
152 {
153     Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
154     m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
155 }
156 
addEventListener(const Reference<lang::XEventListener> & xListener)157 void SAL_CALL MinMaxLineWrapper::addEventListener(
158     const Reference< lang::XEventListener >& xListener )
159     throw (uno::RuntimeException)
160 {
161 	m_aEventListenerContainer.addInterface( xListener );
162 }
163 
removeEventListener(const Reference<lang::XEventListener> & aListener)164 void SAL_CALL MinMaxLineWrapper::removeEventListener(
165     const Reference< lang::XEventListener >& aListener )
166     throw (uno::RuntimeException)
167 {
168 	m_aEventListenerContainer.removeInterface( aListener );
169 }
170 
getInfoHelper()171 ::cppu::IPropertyArrayHelper& MinMaxLineWrapper::getInfoHelper()
172 {
173     return *StaticMinMaxLineWrapperInfoHelper::get();
174 }
175 
176 //XPropertySet
getPropertySetInfo()177 uno::Reference< beans::XPropertySetInfo > SAL_CALL MinMaxLineWrapper::getPropertySetInfo()
178                     throw (uno::RuntimeException)
179 {
180     return *StaticMinMaxLineWrapperInfo::get();
181 }
182 
setPropertyValue(const::rtl::OUString & rPropertyName,const uno::Any & rValue)183 void SAL_CALL MinMaxLineWrapper::setPropertyValue( const ::rtl::OUString& rPropertyName, const uno::Any& rValue )
184                     throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
185 {
186     Reference< beans::XPropertySet > xPropSet(0);
187 
188     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
189     Sequence< Reference< chart2::XChartType > > aTypes(
190             ::chart::DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
191     for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
192     {
193         Reference< chart2::XChartType > xType( aTypes[nN] );
194         if( xType->getChartType().equals(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
195         {
196             Reference< chart2::XDataSeriesContainer > xSeriesContainer(xType,uno::UNO_QUERY);
197             if( xSeriesContainer.is() )
198             {
199                 Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesContainer->getDataSeries() );
200                 if(aSeriesSeq.getLength())
201                 {
202                     xPropSet = Reference< beans::XPropertySet >(aSeriesSeq[0],uno::UNO_QUERY);
203                     if(xPropSet.is())
204                     {
205                         if( rPropertyName.equals( C2U("LineColor")) )
206                             xPropSet->setPropertyValue( C2U("Color"), rValue );
207                         else if( rPropertyName.equals( C2U("LineTransparence")) )
208                             xPropSet->setPropertyValue( C2U("Transparency"), rValue );
209                         else if( rPropertyName.equals( m_aWrappedLineJointProperty.getOuterName() ) )
210                             m_aWrappedLineJointProperty.setPropertyValue( rValue, xPropSet );
211                         else
212                             xPropSet->setPropertyValue( rPropertyName, rValue );
213                         return;
214                     }
215                 }
216             }
217         }
218     }
219 }
getPropertyValue(const::rtl::OUString & rPropertyName)220 uno::Any SAL_CALL MinMaxLineWrapper::getPropertyValue( const ::rtl::OUString& rPropertyName )
221                     throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
222 {
223     Any aRet;
224 
225     Reference< beans::XPropertySet > xPropSet(0);
226 
227     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
228     Sequence< Reference< chart2::XChartType > > aTypes(
229             ::chart::DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
230     for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
231     {
232         Reference< chart2::XChartType > xType( aTypes[nN] );
233         if( xType->getChartType().equals(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
234         {
235             Reference< chart2::XDataSeriesContainer > xSeriesContainer(xType,uno::UNO_QUERY);
236             if( xSeriesContainer.is() )
237             {
238                 Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesContainer->getDataSeries() );
239                 if(aSeriesSeq.getLength())
240                 {
241                     xPropSet = Reference< beans::XPropertySet >(aSeriesSeq[0],uno::UNO_QUERY);
242                     break;
243                 }
244             }
245         }
246     }
247     if(xPropSet.is())
248     {
249         if( rPropertyName.equals( C2U("LineColor")) )
250             aRet = xPropSet->getPropertyValue( C2U("Color") );
251         else if( rPropertyName.equals( C2U("LineTransparence")) )
252             aRet = xPropSet->getPropertyValue( C2U("Transparency") );
253         else if( rPropertyName.equals( m_aWrappedLineJointProperty.getOuterName() ) )
254             aRet = m_aWrappedLineJointProperty.getPropertyValue( xPropSet );
255         else
256             aRet = xPropSet->getPropertyValue( rPropertyName );
257 
258     }
259     return aRet;
260 }
261 
addPropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)262 void SAL_CALL MinMaxLineWrapper::addPropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
263                     throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
264 {
265     OSL_ENSURE(false,"not implemented");
266 }
removePropertyChangeListener(const::rtl::OUString &,const uno::Reference<beans::XPropertyChangeListener> &)267 void SAL_CALL MinMaxLineWrapper::removePropertyChangeListener( const ::rtl::OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
268                     throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
269 {
270     OSL_ENSURE(false,"not implemented");
271 }
addVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)272 void SAL_CALL MinMaxLineWrapper::addVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
273                     throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
274 {
275     OSL_ENSURE(false,"not implemented");
276 }
removeVetoableChangeListener(const::rtl::OUString &,const uno::Reference<beans::XVetoableChangeListener> &)277 void SAL_CALL MinMaxLineWrapper::removeVetoableChangeListener( const ::rtl::OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
278                     throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
279 {
280     OSL_ENSURE(false,"not implemented");
281 }
282 
283 //XMultiPropertySet
284 //getPropertySetInfo() already declared in XPropertySet
setPropertyValues(const uno::Sequence<::rtl::OUString> & rNameSeq,const uno::Sequence<uno::Any> & rValueSeq)285 void SAL_CALL MinMaxLineWrapper::setPropertyValues( const uno::Sequence< ::rtl::OUString >& rNameSeq, const uno::Sequence< uno::Any >& rValueSeq )
286                     throw (beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException)
287 {
288     bool bUnknownProperty = false;
289     sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() );
290     for(sal_Int32 nN=0; nN<nMinCount; nN++)
291     {
292         ::rtl::OUString aPropertyName( rNameSeq[nN] );
293         try
294         {
295             this->setPropertyValue( aPropertyName, rValueSeq[nN] );
296         }
297         catch( beans::UnknownPropertyException& ex )
298         {
299             ASSERT_EXCEPTION( ex );
300             bUnknownProperty = true;
301         }
302     }
303     //todo: store unknown properties elsewhere
304 //    if( bUnknownProperty )
305 //        throw beans::UnknownPropertyException();
306 }
getPropertyValues(const uno::Sequence<::rtl::OUString> & rNameSeq)307 uno::Sequence< uno::Any > SAL_CALL MinMaxLineWrapper::getPropertyValues( const uno::Sequence< ::rtl::OUString >& rNameSeq )
308                     throw (uno::RuntimeException)
309 {
310     Sequence< Any > aRetSeq;
311     if( rNameSeq.getLength() )
312     {
313         aRetSeq.realloc( rNameSeq.getLength() );
314         for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
315         {
316             ::rtl::OUString aPropertyName( rNameSeq[nN] );
317             aRetSeq[nN] = this->getPropertyValue( aPropertyName );
318         }
319     }
320     return aRetSeq;
321 }
addPropertiesChangeListener(const uno::Sequence<::rtl::OUString> &,const uno::Reference<beans::XPropertiesChangeListener> &)322 void SAL_CALL MinMaxLineWrapper::addPropertiesChangeListener(
323     const uno::Sequence< ::rtl::OUString >& /* aPropertyNames */,
324     const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
325                     throw (uno::RuntimeException)
326 {
327     OSL_ENSURE(false,"not implemented");
328 }
removePropertiesChangeListener(const uno::Reference<beans::XPropertiesChangeListener> &)329 void SAL_CALL MinMaxLineWrapper::removePropertiesChangeListener(
330     const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
331                     throw (uno::RuntimeException)
332 {
333     OSL_ENSURE(false,"not implemented");
334 }
firePropertiesChangeEvent(const uno::Sequence<::rtl::OUString> &,const uno::Reference<beans::XPropertiesChangeListener> &)335 void SAL_CALL MinMaxLineWrapper::firePropertiesChangeEvent(
336     const uno::Sequence< ::rtl::OUString >& /* aPropertyNames */,
337     const uno::Reference< beans::XPropertiesChangeListener >& /* xListener */ )
338                     throw (uno::RuntimeException)
339 {
340     OSL_ENSURE(false,"not implemented");
341 }
342 
343 //XPropertyState
getPropertyState(const::rtl::OUString & rPropertyName)344 beans::PropertyState SAL_CALL MinMaxLineWrapper::getPropertyState( const ::rtl::OUString& rPropertyName )
345                     throw (beans::UnknownPropertyException, uno::RuntimeException)
346 {
347     if( rPropertyName.equals( m_aWrappedLineJointProperty.getOuterName() ) )
348         return beans::PropertyState_DEFAULT_VALUE;
349 
350     uno::Any aDefault( this->getPropertyDefault( rPropertyName ) );
351     uno::Any aValue( this->getPropertyValue( rPropertyName ) );
352 
353     if( aDefault == aValue )
354         return beans::PropertyState_DEFAULT_VALUE;
355 
356     return beans::PropertyState_DIRECT_VALUE;
357 }
getPropertyStates(const uno::Sequence<::rtl::OUString> & rNameSeq)358 uno::Sequence< beans::PropertyState > SAL_CALL MinMaxLineWrapper::getPropertyStates( const uno::Sequence< ::rtl::OUString >& rNameSeq )
359                     throw (beans::UnknownPropertyException, uno::RuntimeException)
360 {
361     Sequence< beans::PropertyState > aRetSeq;
362     if( rNameSeq.getLength() )
363     {
364         aRetSeq.realloc( rNameSeq.getLength() );
365         for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
366         {
367             ::rtl::OUString aPropertyName( rNameSeq[nN] );
368             aRetSeq[nN] = this->getPropertyState( aPropertyName );
369         }
370     }
371     return aRetSeq;
372 }
setPropertyToDefault(const::rtl::OUString & rPropertyName)373 void SAL_CALL MinMaxLineWrapper::setPropertyToDefault( const ::rtl::OUString& rPropertyName )
374                     throw (beans::UnknownPropertyException, uno::RuntimeException)
375 {
376     this->setPropertyValue( rPropertyName, this->getPropertyDefault(rPropertyName) );
377 }
378 
getPropertyDefault(const::rtl::OUString & rPropertyName)379 uno::Any SAL_CALL MinMaxLineWrapper::getPropertyDefault( const ::rtl::OUString& rPropertyName )
380                     throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
381 {
382     const tPropertyValueMap& rStaticDefaults = *StaticMinMaxLineWrapperDefaults::get();
383     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( getInfoHelper().getHandleByName( rPropertyName ) ) );
384     if( aFound == rStaticDefaults.end() )
385         return uno::Any();
386     return (*aFound).second;
387 }
388 
389 //XMultiPropertyStates
390 //getPropertyStates() already declared in XPropertyState
setAllPropertiesToDefault()391 void SAL_CALL MinMaxLineWrapper::setAllPropertiesToDefault(  )
392                     throw (uno::RuntimeException)
393 {
394     const Sequence< beans::Property >& rPropSeq = *StaticMinMaxLineWrapperPropertyArray::get();
395     for(sal_Int32 nN=0; nN<rPropSeq.getLength(); nN++)
396     {
397         ::rtl::OUString aPropertyName( rPropSeq[nN].Name );
398         this->setPropertyToDefault( aPropertyName );
399     }
400 }
setPropertiesToDefault(const uno::Sequence<::rtl::OUString> & rNameSeq)401 void SAL_CALL MinMaxLineWrapper::setPropertiesToDefault( const uno::Sequence< ::rtl::OUString >& rNameSeq )
402                     throw (beans::UnknownPropertyException, uno::RuntimeException)
403 {
404     for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
405     {
406         ::rtl::OUString aPropertyName( rNameSeq[nN] );
407         this->setPropertyToDefault( aPropertyName );
408     }
409 }
getPropertyDefaults(const uno::Sequence<::rtl::OUString> & rNameSeq)410 uno::Sequence< uno::Any > SAL_CALL MinMaxLineWrapper::getPropertyDefaults( const uno::Sequence< ::rtl::OUString >& rNameSeq )
411                     throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
412 {
413     Sequence< Any > aRetSeq;
414     if( rNameSeq.getLength() )
415     {
416         aRetSeq.realloc( rNameSeq.getLength() );
417         for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
418         {
419             ::rtl::OUString aPropertyName( rNameSeq[nN] );
420             aRetSeq[nN] = this->getPropertyDefault( aPropertyName );
421         }
422     }
423     return aRetSeq;
424 }
425 
426 
427 // ================================================================================
428 
getSupportedServiceNames_Static()429 Sequence< OUString > MinMaxLineWrapper::getSupportedServiceNames_Static()
430 {
431     Sequence< OUString > aServices( 3 );
432     aServices[ 0 ] = C2U( "com.sun.star.chart.ChartLine" );
433     aServices[ 1 ] = C2U( "com.sun.star.xml.UserDefinedAttributeSupplier" );
434     aServices[ 2 ] = C2U( "com.sun.star.drawing.LineProperties" );
435 
436     return aServices;
437 }
438 
439 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
440 APPHELPER_XSERVICEINFO_IMPL( MinMaxLineWrapper, lcl_aServiceName );
441 
442 } //  namespace wrapper
443 } //  namespace chart
444