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