LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/chartapiwrapper - UpDownBarWrapper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 159 1.3 %
Date: 2012-12-27 Functions: 2 39 5.1 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10