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

Generated by: LCOV version 1.10