LCOV - code coverage report
Current view: top level - chart2/source/model/main - StockBar.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 55 67 82.1 %
Date: 2014-11-03 Functions: 18 22 81.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 "StockBar.hxx"
      21             : #include "LinePropertiesHelper.hxx"
      22             : #include "FillProperties.hxx"
      23             : #include "UserDefinedProperties.hxx"
      24             : #include "PropertyHelper.hxx"
      25             : #include "macros.hxx"
      26             : #include "ContainerHelper.hxx"
      27             : #include "ModifyListenerHelper.hxx"
      28             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      29             : #include <com/sun/star/style/XStyle.hpp>
      30             : #include <com/sun/star/beans/XPropertySet.hpp>
      31             : #include <com/sun/star/uno/Sequence.hxx>
      32             : 
      33             : #include <algorithm>
      34             : 
      35             : using namespace ::com::sun::star;
      36             : 
      37             : using ::com::sun::star::uno::Reference;
      38             : using ::com::sun::star::beans::Property;
      39             : using ::osl::MutexGuard;
      40             : 
      41             : namespace
      42             : {
      43             : 
      44             : struct StaticStockBarInfoHelper_Initializer
      45             : {
      46           4 :     ::cppu::OPropertyArrayHelper* operator()()
      47             :     {
      48           4 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
      49           4 :         return &aPropHelper;
      50             :     }
      51             : 
      52             : private:
      53           4 :     uno::Sequence< Property > lcl_GetPropertySequence()
      54             :     {
      55           4 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
      56           4 :         ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
      57           4 :         ::chart::FillProperties::AddPropertiesToVector( aProperties );
      58           4 :         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
      59             : 
      60             :         ::std::sort( aProperties.begin(), aProperties.end(),
      61           4 :                      ::chart::PropertyNameLess() );
      62             : 
      63           4 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
      64             :     }
      65             : 
      66             : };
      67             : 
      68             : struct StaticStockBarInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticStockBarInfoHelper_Initializer >
      69             : {
      70             : };
      71             : 
      72             : struct StaticStockBarInfo_Initializer
      73             : {
      74           2 :     uno::Reference< beans::XPropertySetInfo >* operator()()
      75             :     {
      76             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
      77           2 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticStockBarInfoHelper::get() ) );
      78           2 :         return &xPropertySetInfo;
      79             :     }
      80             : };
      81             : 
      82             : struct StaticStockBarInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticStockBarInfo_Initializer >
      83             : {
      84             : };
      85             : 
      86             : struct StaticStockBarDefaults_Initializer
      87             : {
      88           4 :     ::chart::tPropertyValueMap* operator()()
      89             :     {
      90           4 :         static ::chart::tPropertyValueMap aStaticDefaults;
      91           4 :         lcl_AddDefaultsToMap( aStaticDefaults );
      92           4 :         return &aStaticDefaults;
      93             :     }
      94             : private:
      95           4 :     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
      96             :     {
      97           4 :         ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap );
      98           4 :         ::chart::FillProperties::AddDefaultsToMap( rOutMap );
      99             : 
     100             :         // override other defaults
     101           4 :         ::chart::PropertyHelper::setPropertyValue< sal_Int32 >( rOutMap, ::chart::FillProperties::PROP_FILL_COLOR, 0xffffff ); // white
     102           4 :     }
     103             : };
     104             : 
     105             : struct StaticStockBarDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticStockBarDefaults_Initializer >
     106             : {
     107             : };
     108             : 
     109             : } // anonymous namespace
     110             : 
     111             : namespace chart
     112             : {
     113             : 
     114          96 : StockBar::StockBar( bool bRisingCourse ) :
     115             :         ::property::OPropertySet( m_aMutex ),
     116             :     m_bRisingCourse( bRisingCourse ),
     117          96 :     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     118             : {
     119          96 :     if( ! m_bRisingCourse )
     120             :     {
     121             :         setFastPropertyValue_NoBroadcast(
     122             :             ::chart::FillProperties::PROP_FILL_COLOR,
     123          48 :             uno::makeAny( sal_Int32( 0x000000 ))); // black
     124             :         setFastPropertyValue_NoBroadcast(
     125             :             ::chart::LinePropertiesHelper::PROP_LINE_COLOR,
     126          48 :             uno::makeAny( sal_Int32( 0xb3b3b3 ))); // gray30
     127             :     }
     128          96 : }
     129             : 
     130           0 : StockBar::StockBar( const StockBar & rOther ) :
     131             :         MutexContainer(),
     132             :         impl::StockBar_Base(),
     133             :         ::property::OPropertySet( rOther, m_aMutex ),
     134             :     m_bRisingCourse( rOther.m_bRisingCourse ),
     135           0 :     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     136           0 : {}
     137             : 
     138         192 : StockBar::~StockBar()
     139         192 : {}
     140             : 
     141             : // ____ XCloneable ____
     142           0 : uno::Reference< util::XCloneable > SAL_CALL StockBar::createClone()
     143             :     throw (uno::RuntimeException, std::exception)
     144             : {
     145           0 :     return uno::Reference< util::XCloneable >( new StockBar( *this ));
     146             : }
     147             : 
     148             : // ____ OPropertySet ____
     149        1568 : uno::Any StockBar::GetDefaultValue( sal_Int32 nHandle ) const
     150             :     throw(beans::UnknownPropertyException)
     151             : {
     152        1568 :     const tPropertyValueMap& rStaticDefaults = *StaticStockBarDefaults::get();
     153        1568 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     154        1568 :     if( aFound == rStaticDefaults.end() )
     155         444 :         return uno::Any();
     156        1124 :     return (*aFound).second;
     157             : }
     158             : 
     159        3408 : ::cppu::IPropertyArrayHelper & SAL_CALL StockBar::getInfoHelper()
     160             : {
     161        3408 :     return *StaticStockBarInfoHelper::get();
     162             : }
     163             : 
     164             : // ____ XPropertySet ____
     165           8 : Reference< beans::XPropertySetInfo > SAL_CALL StockBar::getPropertySetInfo()
     166             :     throw (uno::RuntimeException, std::exception)
     167             : {
     168           8 :     return *StaticStockBarInfo::get();
     169             : }
     170             : 
     171             : // ____ XModifyBroadcaster ____
     172         192 : void SAL_CALL StockBar::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     173             :     throw (uno::RuntimeException, std::exception)
     174             : {
     175             :     try
     176             :     {
     177         192 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     178         192 :         xBroadcaster->addModifyListener( aListener );
     179             :     }
     180           0 :     catch( const uno::Exception & ex )
     181             :     {
     182             :         ASSERT_EXCEPTION( ex );
     183             :     }
     184         192 : }
     185             : 
     186          96 : void SAL_CALL StockBar::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     187             :     throw (uno::RuntimeException, std::exception)
     188             : {
     189             :     try
     190             :     {
     191          96 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     192          96 :         xBroadcaster->removeModifyListener( aListener );
     193             :     }
     194           0 :     catch( const uno::Exception & ex )
     195             :     {
     196             :         ASSERT_EXCEPTION( ex );
     197             :     }
     198          96 : }
     199             : 
     200             : // ____ XModifyListener ____
     201           0 : void SAL_CALL StockBar::modified( const lang::EventObject& aEvent )
     202             :     throw (uno::RuntimeException, std::exception)
     203             : {
     204           0 :     m_xModifyEventForwarder->modified( aEvent );
     205           0 : }
     206             : 
     207             : // ____ XEventListener (base of XModifyListener) ____
     208           0 : void SAL_CALL StockBar::disposing( const lang::EventObject& /* Source */ )
     209             :     throw (uno::RuntimeException, std::exception)
     210             : {
     211             :     // nothing
     212           0 : }
     213             : 
     214             : // ____ OPropertySet ____
     215          26 : void StockBar::firePropertyChangeEvent()
     216             : {
     217          26 :     fireModifyEvent();
     218          26 : }
     219             : 
     220          26 : void StockBar::fireModifyEvent()
     221             : {
     222          26 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
     223          26 : }
     224             : 
     225             : using impl::StockBar_Base;
     226             : 
     227        8770 : IMPLEMENT_FORWARD_XINTERFACE2( StockBar, StockBar_Base, ::property::OPropertySet )
     228             : 
     229             : } //  namespace chart
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10