LCOV - code coverage report
Current view: top level - chart2/source/model/template - CandleStickChartType.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 96 142 67.6 %
Date: 2015-06-13 12:38:46 Functions: 20 25 80.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 "CandleStickChartType.hxx"
      21             : #include "PropertyHelper.hxx"
      22             : #include "macros.hxx"
      23             : #include "StockBar.hxx"
      24             : #include "servicenames_charttypes.hxx"
      25             : #include "ContainerHelper.hxx"
      26             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      27             : #include <cppuhelper/supportsservice.hxx>
      28             : 
      29             : using namespace ::com::sun::star;
      30             : 
      31             : using ::com::sun::star::beans::Property;
      32             : using ::com::sun::star::uno::Sequence;
      33             : using ::com::sun::star::uno::Reference;
      34             : using ::com::sun::star::uno::Any;
      35             : using ::osl::MutexGuard;
      36             : 
      37             : namespace
      38             : {
      39             : 
      40             : enum
      41             : {
      42             :     PROP_CANDLESTICKCHARTTYPE_JAPANESE,
      43             :     PROP_CANDLESTICKCHARTTYPE_WHITE_DAY,
      44             :     PROP_CANDLESTICKCHARTTYPE_BLACK_DAY,
      45             : 
      46             :     PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST,
      47             :     PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW
      48             : };
      49             : 
      50           2 : void lcl_AddPropertiesToVector(
      51             :     ::std::vector< Property > & rOutProperties )
      52             : {
      53             :     rOutProperties.push_back(
      54             :         Property( "Japanese",
      55             :                   PROP_CANDLESTICKCHARTTYPE_JAPANESE,
      56           2 :                   cppu::UnoType<bool>::get(),
      57             :                   beans::PropertyAttribute::BOUND
      58           4 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      59             : 
      60             :     rOutProperties.push_back(
      61             :         Property( "WhiteDay",
      62             :                   PROP_CANDLESTICKCHARTTYPE_WHITE_DAY,
      63           2 :                   cppu::UnoType<beans::XPropertySet>::get(),
      64             :                   beans::PropertyAttribute::BOUND
      65           4 :                   | beans::PropertyAttribute::MAYBEVOID ));
      66             :     rOutProperties.push_back(
      67             :         Property( "BlackDay",
      68             :                   PROP_CANDLESTICKCHARTTYPE_BLACK_DAY,
      69           2 :                   cppu::UnoType<beans::XPropertySet>::get(),
      70             :                   beans::PropertyAttribute::BOUND
      71           4 :                   | beans::PropertyAttribute::MAYBEVOID ));
      72             : 
      73             :     rOutProperties.push_back(
      74             :         Property( "ShowFirst",
      75             :                   PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST,
      76           2 :                   cppu::UnoType<bool>::get(),
      77             :                   beans::PropertyAttribute::BOUND
      78           4 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      79             :     rOutProperties.push_back(
      80             :         Property( "ShowHighLow",
      81             :                   PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW,
      82           2 :                   cppu::UnoType<bool>::get(),
      83             :                   beans::PropertyAttribute::BOUND
      84           4 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      85           2 : }
      86             : 
      87             : struct StaticCandleStickChartTypeDefaults_Initializer
      88             : {
      89           3 :     ::chart::tPropertyValueMap* operator()()
      90             :     {
      91           3 :         static ::chart::tPropertyValueMap aStaticDefaults;
      92           3 :         lcl_AddDefaultsToMap( aStaticDefaults );
      93           3 :         return &aStaticDefaults;
      94             :     }
      95             : private:
      96           3 :     static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
      97             :     {
      98             :         // must match default in CTOR!
      99           3 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CANDLESTICKCHARTTYPE_JAPANESE, false );
     100           3 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST, false );
     101           3 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW, true );
     102           3 :     }
     103             : };
     104             : 
     105             : struct StaticCandleStickChartTypeDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticCandleStickChartTypeDefaults_Initializer >
     106             : {
     107             : };
     108             : 
     109             : struct StaticCandleStickChartTypeInfoHelper_Initializer
     110             : {
     111           2 :     ::cppu::OPropertyArrayHelper* operator()()
     112             :     {
     113           2 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
     114           2 :         return &aPropHelper;
     115             :     }
     116             : 
     117             : private:
     118           2 :     static Sequence< Property > lcl_GetPropertySequence()
     119             :     {
     120           2 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
     121           2 :         lcl_AddPropertiesToVector( aProperties );
     122             : 
     123             :         ::std::sort( aProperties.begin(), aProperties.end(),
     124           2 :                      ::chart::PropertyNameLess() );
     125             : 
     126           2 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
     127             :     }
     128             : 
     129             : };
     130             : 
     131             : struct StaticCandleStickChartTypeInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticCandleStickChartTypeInfoHelper_Initializer >
     132             : {
     133             : };
     134             : 
     135             : struct StaticCandleStickChartTypeInfo_Initializer
     136             : {
     137           1 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     138             :     {
     139             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     140           1 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticCandleStickChartTypeInfoHelper::get() ) );
     141           1 :         return &xPropertySetInfo;
     142             :     }
     143             : };
     144             : 
     145             : struct StaticCandleStickChartTypeInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticCandleStickChartTypeInfo_Initializer >
     146             : {
     147             : };
     148             : 
     149             : } // anonymous namespace
     150             : 
     151             : namespace chart
     152             : {
     153             : 
     154          21 : CandleStickChartType::CandleStickChartType(
     155             :     const uno::Reference< uno::XComponentContext > & xContext ) :
     156          21 :         ChartType( xContext )
     157             : {
     158          21 :     Reference< beans::XPropertySet > xWhiteDayProps( new ::chart::StockBar( true ));
     159          42 :     Reference< beans::XPropertySet > xBlackDayProps( new ::chart::StockBar( false ));
     160             : 
     161          21 :     ModifyListenerHelper::addListener( xWhiteDayProps, m_xModifyEventForwarder );
     162          21 :     ModifyListenerHelper::addListener( xBlackDayProps, m_xModifyEventForwarder );
     163             : 
     164             :     setFastPropertyValue_NoBroadcast(
     165          21 :         PROP_CANDLESTICKCHARTTYPE_WHITE_DAY, uno::makeAny( xWhiteDayProps ));
     166             :     setFastPropertyValue_NoBroadcast(
     167          42 :         PROP_CANDLESTICKCHARTTYPE_BLACK_DAY, uno::makeAny( xBlackDayProps ));
     168          21 : }
     169             : 
     170           0 : CandleStickChartType::CandleStickChartType( const CandleStickChartType & rOther ) :
     171           0 :         ChartType( rOther )
     172             : {
     173           0 :     Reference< beans::XPropertySet > xPropertySet;
     174           0 :     uno::Any aValue;
     175             : 
     176           0 :     getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY );
     177           0 :     if( ( aValue >>= xPropertySet )
     178           0 :         && xPropertySet.is())
     179           0 :         ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder );
     180             : 
     181           0 :     getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY );
     182           0 :     if( ( aValue >>= xPropertySet )
     183           0 :         && xPropertySet.is())
     184           0 :         ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder );
     185           0 : }
     186             : 
     187          63 : CandleStickChartType::~CandleStickChartType()
     188             : {
     189             :     try
     190             :     {
     191          21 :         Reference< beans::XPropertySet > xPropertySet;
     192          42 :         uno::Any aValue;
     193             : 
     194          21 :         getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY );
     195          42 :         if( ( aValue >>= xPropertySet )
     196          21 :             && xPropertySet.is())
     197          21 :             ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder );
     198             : 
     199          21 :         getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY );
     200          42 :         if( ( aValue >>= xPropertySet )
     201          21 :             && xPropertySet.is())
     202          42 :             ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder );
     203             :     }
     204           0 :     catch( const uno::Exception & ex )
     205             :     {
     206             :         ASSERT_EXCEPTION( ex );
     207             :     }
     208          42 : }
     209             : 
     210             : // ____ XCloneable ____
     211           0 : uno::Reference< util::XCloneable > SAL_CALL CandleStickChartType::createClone()
     212             :     throw (uno::RuntimeException, std::exception)
     213             : {
     214           0 :     return uno::Reference< util::XCloneable >( new CandleStickChartType( *this ));
     215             : }
     216             : 
     217             : // ____ XChartType ____
     218        1781 : OUString SAL_CALL CandleStickChartType::getChartType()
     219             :     throw (uno::RuntimeException, std::exception)
     220             : {
     221        1781 :     return OUString(CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK);
     222             : }
     223             : 
     224           0 : uno::Sequence< OUString > SAL_CALL CandleStickChartType::getSupportedMandatoryRoles()
     225             :     throw (uno::RuntimeException, std::exception)
     226             : {
     227           0 :     bool bShowFirst = true;
     228           0 :     bool bShowHiLow = false;
     229           0 :     getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST ) >>= bShowFirst;
     230           0 :     getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW ) >>= bShowHiLow;
     231             : 
     232           0 :     ::std::vector< OUString > aMandRoles;
     233             : 
     234           0 :     aMandRoles.push_back( "label");
     235           0 :     if( bShowFirst )
     236           0 :         aMandRoles.push_back( "values-first");
     237             : 
     238           0 :     if( bShowHiLow )
     239             :     {
     240           0 :         aMandRoles.push_back( "values-min");
     241           0 :         aMandRoles.push_back( "values-max");
     242             :     }
     243             : 
     244           0 :     aMandRoles.push_back( "values-last");
     245             : 
     246           0 :     return ContainerHelper::ContainerToSequence( aMandRoles );
     247             : }
     248             : 
     249           0 : Sequence< OUString > SAL_CALL CandleStickChartType::getSupportedOptionalRoles()
     250             :     throw (uno::RuntimeException, std::exception)
     251             : {
     252           0 :     bool bShowFirst = true;
     253           0 :     bool bShowHiLow = false;
     254           0 :     getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST ) >>= bShowFirst;
     255           0 :     getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW ) >>= bShowHiLow;
     256             : 
     257           0 :     ::std::vector< OUString > aOptRoles;
     258             : 
     259           0 :     if( ! bShowFirst )
     260           0 :         aOptRoles.push_back( "values-first");
     261             : 
     262           0 :     if( ! bShowHiLow )
     263             :     {
     264           0 :         aOptRoles.push_back( "values-min");
     265           0 :         aOptRoles.push_back( "values-max");
     266             :     }
     267             : 
     268           0 :     return ContainerHelper::ContainerToSequence( aOptRoles );
     269             : }
     270             : 
     271          32 : OUString SAL_CALL CandleStickChartType::getRoleOfSequenceForSeriesLabel()
     272             :     throw (uno::RuntimeException, std::exception)
     273             : {
     274          32 :     return OUString("values-last");
     275             : }
     276             : 
     277             : // ____ OPropertySet ____
     278         118 : uno::Any CandleStickChartType::GetDefaultValue( sal_Int32 nHandle ) const
     279             :     throw(beans::UnknownPropertyException)
     280             : {
     281         118 :     const tPropertyValueMap& rStaticDefaults = *StaticCandleStickChartTypeDefaults::get();
     282         118 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     283         118 :     if( aFound == rStaticDefaults.end() )
     284          84 :         return uno::Any();
     285          34 :     return (*aFound).second;
     286             : }
     287             : 
     288             : // ____ OPropertySet ____
     289        2288 : ::cppu::IPropertyArrayHelper & SAL_CALL CandleStickChartType::getInfoHelper()
     290             : {
     291        2288 :     return *StaticCandleStickChartTypeInfoHelper::get();
     292             : }
     293             : 
     294             : // ____ XPropertySet ____
     295           4 : Reference< beans::XPropertySetInfo > SAL_CALL CandleStickChartType::getPropertySetInfo()
     296             :     throw (uno::RuntimeException, std::exception)
     297             : {
     298           4 :     return *StaticCandleStickChartTypeInfo::get();
     299             : }
     300             : 
     301          48 : void SAL_CALL CandleStickChartType::setFastPropertyValue_NoBroadcast(
     302             :     sal_Int32 nHandle, const uno::Any& rValue )
     303             :     throw (uno::Exception, std::exception)
     304             : {
     305          48 :     if(    nHandle == PROP_CANDLESTICKCHARTTYPE_WHITE_DAY
     306          27 :         || nHandle == PROP_CANDLESTICKCHARTTYPE_BLACK_DAY )
     307             :     {
     308          42 :         uno::Any aOldValue;
     309          84 :         Reference< util::XModifyBroadcaster > xBroadcaster;
     310          42 :         this->getFastPropertyValue( aOldValue, nHandle );
     311          84 :         if( aOldValue.hasValue() &&
     312          42 :             (aOldValue >>= xBroadcaster) &&
     313           0 :             xBroadcaster.is())
     314             :         {
     315           0 :             ModifyListenerHelper::removeListener( xBroadcaster, m_xModifyEventForwarder );
     316             :         }
     317             : 
     318             :         OSL_ASSERT( rValue.getValueType().getTypeClass() == uno::TypeClass_INTERFACE );
     319         126 :         if( rValue.hasValue() &&
     320          84 :             (rValue >>= xBroadcaster) &&
     321          42 :             xBroadcaster.is())
     322             :         {
     323          42 :             ModifyListenerHelper::addListener( xBroadcaster, m_xModifyEventForwarder );
     324          42 :         }
     325             :     }
     326             : 
     327          48 :     ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle, rValue );
     328          48 : }
     329             : 
     330           1 : uno::Sequence< OUString > CandleStickChartType::getSupportedServiceNames_Static()
     331             : {
     332           1 :     uno::Sequence< OUString > aServices( 3 );
     333           1 :     aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK;
     334           1 :     aServices[ 1 ] = "com.sun.star.chart2.ChartType";
     335           1 :     aServices[ 2 ] = "com.sun.star.beans.PropertySet";
     336           1 :     return aServices;
     337             : }
     338             : 
     339             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     340           1 : OUString SAL_CALL CandleStickChartType::getImplementationName()
     341             :     throw( css::uno::RuntimeException, std::exception )
     342             : {
     343           1 :     return getImplementationName_Static();
     344             : }
     345             : 
     346           1 : OUString CandleStickChartType::getImplementationName_Static()
     347             : {
     348           1 :     return OUString("com.sun.star.comp.chart.CandleStickChartType") ;
     349             : }
     350             : 
     351           0 : sal_Bool SAL_CALL CandleStickChartType::supportsService( const OUString& rServiceName )
     352             :     throw( css::uno::RuntimeException, std::exception )
     353             : {
     354           0 :     return cppu::supportsService(this, rServiceName);
     355             : }
     356             : 
     357           1 : css::uno::Sequence< OUString > SAL_CALL CandleStickChartType::getSupportedServiceNames()
     358             :     throw( css::uno::RuntimeException, std::exception )
     359             : {
     360           1 :     return getSupportedServiceNames_Static();
     361             : }
     362             : 
     363             : } //  namespace chart
     364             : 
     365             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     366          21 : com_sun_star_comp_chart_CandleStickChartType_get_implementation(css::uno::XComponentContext *context,
     367             :                                                          css::uno::Sequence<css::uno::Any> const &)
     368             : {
     369          21 :     return cppu::acquire(new ::chart::CandleStickChartType(context));
     370             : }
     371             : 
     372             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11