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

Generated by: LCOV version 1.10