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

Generated by: LCOV version 1.10