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

Generated by: LCOV version 1.11