LCOV - code coverage report
Current view: top level - chart2/source/controller/chartapiwrapper - MinMaxLineWrapper.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 179 0.0 %
Date: 2014-04-14 Functions: 0 39 0.0 %
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           0 : static const OUString lcl_aServiceName( "com.sun.star.comp.chart.ChartLine" );
      45             : 
      46             : struct StaticMinMaxLineWrapperDefaults_Initializer
      47             : {
      48           0 :     ::chart::tPropertyValueMap* operator()()
      49             :     {
      50           0 :         static ::chart::tPropertyValueMap aStaticDefaults;
      51           0 :         lcl_AddDefaultsToMap( aStaticDefaults );
      52           0 :         return &aStaticDefaults;
      53             :     }
      54             : private:
      55           0 :     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
      56             :     {
      57           0 :         ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap );
      58           0 :     }
      59             : };
      60             : 
      61             : struct StaticMinMaxLineWrapperDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticMinMaxLineWrapperDefaults_Initializer >
      62             : {
      63             : };
      64             : 
      65             : struct StaticMinMaxLineWrapperPropertyArray_Initializer
      66             : {
      67           0 :     Sequence< Property >* operator()()
      68             :     {
      69           0 :         static Sequence< Property > aPropSeq( lcl_GetPropertySequence() );
      70           0 :         return &aPropSeq;
      71             :     }
      72             : 
      73             : private:
      74           0 :     Sequence< Property > lcl_GetPropertySequence()
      75             :     {
      76           0 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
      77             : 
      78           0 :         ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
      79           0 :         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
      80             : 
      81             :         ::std::sort( aProperties.begin(), aProperties.end(),
      82           0 :                      ::chart::PropertyNameLess() );
      83             : 
      84           0 :         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           0 :     ::cppu::OPropertyArrayHelper* operator()()
      95             :     {
      96           0 :         static ::cppu::OPropertyArrayHelper aPropHelper( *StaticMinMaxLineWrapperPropertyArray::get() );
      97           0 :         return &aPropHelper;
      98             :     }
      99             : };
     100             : 
     101             : struct StaticMinMaxLineWrapperInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticMinMaxLineWrapperInfoHelper_Initializer >
     102             : {
     103             : };
     104             : 
     105             : struct StaticMinMaxLineWrapperInfo_Initializer
     106             : {
     107           0 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     108             :     {
     109             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     110           0 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticMinMaxLineWrapperInfoHelper::get() ) );
     111           0 :         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           0 : MinMaxLineWrapper::MinMaxLineWrapper( ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact )
     127             :         : m_spChart2ModelContact( spChart2ModelContact )
     128             :         , m_aEventListenerContainer( m_aMutex )
     129           0 :         , m_aWrappedLineJointProperty( "LineJoint", uno::makeAny( drawing::LineJoint_NONE ))
     130             : {
     131           0 : }
     132             : 
     133           0 : MinMaxLineWrapper::~MinMaxLineWrapper()
     134             : {
     135           0 : }
     136             : 
     137             : // ____ XComponent ____
     138           0 : void SAL_CALL MinMaxLineWrapper::dispose()
     139             :     throw (uno::RuntimeException, std::exception)
     140             : {
     141           0 :     Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
     142           0 :     m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) );
     143           0 : }
     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           0 : ::cppu::IPropertyArrayHelper& MinMaxLineWrapper::getInfoHelper()
     160             : {
     161           0 :     return *StaticMinMaxLineWrapperInfoHelper::get();
     162             : }
     163             : 
     164             : //XPropertySet
     165           0 : uno::Reference< beans::XPropertySetInfo > SAL_CALL MinMaxLineWrapper::getPropertySetInfo()
     166             :                     throw (uno::RuntimeException, std::exception)
     167             : {
     168           0 :     return *StaticMinMaxLineWrapperInfo::get();
     169             : }
     170             : 
     171           0 : 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           0 :     Reference< beans::XPropertySet > xPropSet(0);
     175             : 
     176           0 :     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
     177             :     Sequence< Reference< chart2::XChartType > > aTypes(
     178           0 :             ::chart::DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
     179           0 :     for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
     180             :     {
     181           0 :         Reference< chart2::XChartType > xType( aTypes[nN] );
     182           0 :         if( xType->getChartType().equals(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
     183             :         {
     184           0 :             Reference< chart2::XDataSeriesContainer > xSeriesContainer(xType,uno::UNO_QUERY);
     185           0 :             if( xSeriesContainer.is() )
     186             :             {
     187           0 :                 Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesContainer->getDataSeries() );
     188           0 :                 if(aSeriesSeq.getLength())
     189             :                 {
     190           0 :                     xPropSet = Reference< beans::XPropertySet >(aSeriesSeq[0],uno::UNO_QUERY);
     191           0 :                     if(xPropSet.is())
     192             :                     {
     193           0 :                         if( rPropertyName == "LineColor" )
     194           0 :                             xPropSet->setPropertyValue( "Color", rValue );
     195           0 :                         else if( rPropertyName == "LineTransparence" )
     196           0 :                             xPropSet->setPropertyValue( "Transparency", rValue );
     197           0 :                         else if( rPropertyName.equals( m_aWrappedLineJointProperty.getOuterName() ) )
     198           0 :                             m_aWrappedLineJointProperty.setPropertyValue( rValue, xPropSet );
     199             :                         else
     200           0 :                             xPropSet->setPropertyValue( rPropertyName, rValue );
     201           0 :                         return;
     202             :                     }
     203           0 :                 }
     204           0 :             }
     205             :         }
     206           0 :     }
     207             : }
     208           0 : uno::Any SAL_CALL MinMaxLineWrapper::getPropertyValue( const OUString& rPropertyName )
     209             :                     throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     210             : {
     211           0 :     Any aRet;
     212             : 
     213           0 :     Reference< beans::XPropertySet > xPropSet(0);
     214             : 
     215           0 :     Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() );
     216             :     Sequence< Reference< chart2::XChartType > > aTypes(
     217           0 :             ::chart::DiagramHelper::getChartTypesFromDiagram( xDiagram ) );
     218           0 :     for( sal_Int32 nN = 0; nN < aTypes.getLength(); nN++ )
     219             :     {
     220           0 :         Reference< chart2::XChartType > xType( aTypes[nN] );
     221           0 :         if( xType->getChartType().equals(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK) )
     222             :         {
     223           0 :             Reference< chart2::XDataSeriesContainer > xSeriesContainer(xType,uno::UNO_QUERY);
     224           0 :             if( xSeriesContainer.is() )
     225             :             {
     226           0 :                 Sequence< Reference< chart2::XDataSeries > > aSeriesSeq( xSeriesContainer->getDataSeries() );
     227           0 :                 if(aSeriesSeq.getLength())
     228             :                 {
     229           0 :                     xPropSet = Reference< beans::XPropertySet >(aSeriesSeq[0],uno::UNO_QUERY);
     230           0 :                     break;
     231           0 :                 }
     232           0 :             }
     233             :         }
     234           0 :     }
     235           0 :     if(xPropSet.is())
     236             :     {
     237           0 :         if( rPropertyName == "LineColor" )
     238           0 :             aRet = xPropSet->getPropertyValue( "Color" );
     239           0 :         else if( rPropertyName == "LineTransparence" )
     240           0 :             aRet = xPropSet->getPropertyValue( "Transparency" );
     241           0 :         else if( rPropertyName.equals( m_aWrappedLineJointProperty.getOuterName() ) )
     242           0 :             aRet = m_aWrappedLineJointProperty.getPropertyValue( xPropSet );
     243             :         else
     244           0 :             aRet = xPropSet->getPropertyValue( rPropertyName );
     245             : 
     246             :     }
     247           0 :     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           0 : 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           0 :     sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() );
     277           0 :     for(sal_Int32 nN=0; nN<nMinCount; nN++)
     278             :     {
     279           0 :         OUString aPropertyName( rNameSeq[nN] );
     280             :         try
     281             :         {
     282           0 :             this->setPropertyValue( aPropertyName, rValueSeq[nN] );
     283             :         }
     284           0 :         catch( const beans::UnknownPropertyException& ex )
     285             :         {
     286             :             ASSERT_EXCEPTION( ex );
     287             :         }
     288           0 :     }
     289             :     //todo: store unknown properties elsewhere
     290           0 : }
     291           0 : uno::Sequence< uno::Any > SAL_CALL MinMaxLineWrapper::getPropertyValues( const uno::Sequence< OUString >& rNameSeq )
     292             :                     throw (uno::RuntimeException, std::exception)
     293             : {
     294           0 :     Sequence< Any > aRetSeq;
     295           0 :     if( rNameSeq.getLength() )
     296             :     {
     297           0 :         aRetSeq.realloc( rNameSeq.getLength() );
     298           0 :         for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
     299             :         {
     300           0 :             OUString aPropertyName( rNameSeq[nN] );
     301           0 :             aRetSeq[nN] = this->getPropertyValue( aPropertyName );
     302           0 :         }
     303             :     }
     304           0 :     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           0 : beans::PropertyState SAL_CALL MinMaxLineWrapper::getPropertyState( const OUString& rPropertyName )
     329             :                     throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     330             : {
     331           0 :     if( rPropertyName.equals( m_aWrappedLineJointProperty.getOuterName() ) )
     332           0 :         return beans::PropertyState_DEFAULT_VALUE;
     333             : 
     334           0 :     uno::Any aDefault( this->getPropertyDefault( rPropertyName ) );
     335           0 :     uno::Any aValue( this->getPropertyValue( rPropertyName ) );
     336             : 
     337           0 :     if( aDefault == aValue )
     338           0 :         return beans::PropertyState_DEFAULT_VALUE;
     339             : 
     340           0 :     return beans::PropertyState_DIRECT_VALUE;
     341             : }
     342           0 : uno::Sequence< beans::PropertyState > SAL_CALL MinMaxLineWrapper::getPropertyStates( const uno::Sequence< OUString >& rNameSeq )
     343             :                     throw (beans::UnknownPropertyException, uno::RuntimeException, std::exception)
     344             : {
     345           0 :     Sequence< beans::PropertyState > aRetSeq;
     346           0 :     if( rNameSeq.getLength() )
     347             :     {
     348           0 :         aRetSeq.realloc( rNameSeq.getLength() );
     349           0 :         for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
     350             :         {
     351           0 :             OUString aPropertyName( rNameSeq[nN] );
     352           0 :             aRetSeq[nN] = this->getPropertyState( aPropertyName );
     353           0 :         }
     354             :     }
     355           0 :     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           0 : uno::Any SAL_CALL MinMaxLineWrapper::getPropertyDefault( const OUString& rPropertyName )
     364             :                     throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
     365             : {
     366           0 :     const tPropertyValueMap& rStaticDefaults = *StaticMinMaxLineWrapperDefaults::get();
     367           0 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( getInfoHelper().getHandleByName( rPropertyName ) ) );
     368           0 :     if( aFound == rStaticDefaults.end() )
     369           0 :         return uno::Any();
     370           0 :     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           0 : } //  namespace chart
     425             : 
     426             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10