LCOV - code coverage report
Current view: top level - chart2/source/model/main - Legend.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 89 102 87.3 %
Date: 2012-08-25 Functions: 23 32 71.9 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 83 198 41.9 %

           Branch data     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 "Legend.hxx"
      21                 :            : #include "macros.hxx"
      22                 :            : #include "LineProperties.hxx"
      23                 :            : #include "FillProperties.hxx"
      24                 :            : #include "CharacterProperties.hxx"
      25                 :            : #include "UserDefinedProperties.hxx"
      26                 :            : #include "LegendHelper.hxx"
      27                 :            : #include "ContainerHelper.hxx"
      28                 :            : #include "CloneHelper.hxx"
      29                 :            : #include "PropertyHelper.hxx"
      30                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      31                 :            : #include <com/sun/star/awt/Size.hpp>
      32                 :            : #include <com/sun/star/chart2/LegendPosition.hpp>
      33                 :            : #include <com/sun/star/chart/ChartLegendExpansion.hpp>
      34                 :            : #include <com/sun/star/chart2/RelativePosition.hpp>
      35                 :            : #include <com/sun/star/chart2/RelativeSize.hpp>
      36                 :            : 
      37                 :            : #include <algorithm>
      38                 :            : 
      39                 :            : using namespace ::com::sun::star;
      40                 :            : using namespace ::com::sun::star::beans::PropertyAttribute;
      41                 :            : 
      42                 :            : using ::rtl::OUString;
      43                 :            : using ::com::sun::star::uno::Sequence;
      44                 :            : using ::com::sun::star::uno::Reference;
      45                 :            : using ::com::sun::star::uno::Any;
      46                 :            : using ::com::sun::star::beans::Property;
      47                 :            : 
      48                 :            : namespace
      49                 :            : {
      50                 :            : 
      51                 :         16 : static const OUString lcl_aServiceName(
      52                 :            :     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.Legend" ));
      53                 :            : 
      54                 :            : enum
      55                 :            : {
      56                 :            :     PROP_LEGEND_ANCHOR_POSITION,
      57                 :            :     PROP_LEGEND_EXPANSION,
      58                 :            :     PROP_LEGEND_SHOW,
      59                 :            :     PROP_LEGEND_REF_PAGE_SIZE,
      60                 :            :     PROP_LEGEND_REL_POS,
      61                 :            :     PROP_LEGEND_REL_SIZE
      62                 :            : };
      63                 :            : 
      64                 :         14 : void lcl_AddPropertiesToVector(
      65                 :            :     ::std::vector< Property > & rOutProperties )
      66                 :            : {
      67                 :            :     rOutProperties.push_back(
      68                 :            :         Property( C2U( "AnchorPosition" ),
      69                 :            :                   PROP_LEGEND_ANCHOR_POSITION,
      70         [ +  - ]:         14 :                   ::getCppuType( reinterpret_cast< const chart2::LegendPosition * >(0)),
      71                 :            :                   beans::PropertyAttribute::BOUND
      72 [ +  - ][ +  - ]:         14 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      73                 :            : 
      74                 :            :     rOutProperties.push_back(
      75                 :            :         Property( C2U( "Expansion" ),
      76                 :            :                   PROP_LEGEND_EXPANSION,
      77         [ +  - ]:         14 :                   ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartLegendExpansion * >(0)),
      78                 :            :                   beans::PropertyAttribute::BOUND
      79 [ +  - ][ +  - ]:         14 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      80                 :            : 
      81                 :            :     rOutProperties.push_back(
      82                 :            :         Property( C2U( "Show" ),
      83                 :            :                   PROP_LEGEND_SHOW,
      84         [ +  - ]:         14 :                   ::getBooleanCppuType(),
      85                 :            :                   beans::PropertyAttribute::BOUND
      86 [ +  - ][ +  - ]:         14 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      87                 :            :     rOutProperties.push_back(
      88                 :            :         Property( C2U( "ReferencePageSize" ),
      89                 :            :                   PROP_LEGEND_REF_PAGE_SIZE,
      90         [ +  - ]:         14 :                   ::getCppuType( reinterpret_cast< const awt::Size * >(0)),
      91                 :            :                   beans::PropertyAttribute::BOUND
      92 [ +  - ][ +  - ]:         14 :                   | beans::PropertyAttribute::MAYBEVOID ));
      93                 :            : 
      94                 :            :     rOutProperties.push_back(
      95                 :            :         Property( C2U( "RelativePosition" ),
      96                 :            :                   PROP_LEGEND_REL_POS,
      97         [ +  - ]:         14 :                   ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)),
      98                 :            :                   beans::PropertyAttribute::BOUND
      99 [ +  - ][ +  - ]:         14 :                   | beans::PropertyAttribute::MAYBEVOID ));
     100                 :            : 
     101                 :            :     rOutProperties.push_back(
     102                 :            :         Property( C2U( "RelativeSize" ),
     103                 :            :                   PROP_LEGEND_REL_SIZE,
     104         [ +  - ]:         14 :                   ::getCppuType( reinterpret_cast< const chart2::RelativeSize * >(0)),
     105                 :            :                   beans::PropertyAttribute::BOUND
     106 [ +  - ][ +  - ]:         14 :                   | beans::PropertyAttribute::MAYBEVOID ));
     107                 :            : 
     108                 :         14 : }
     109                 :            : 
     110                 :            : struct StaticLegendDefaults_Initializer
     111                 :            : {
     112                 :         14 :     ::chart::tPropertyValueMap* operator()()
     113                 :            :     {
     114 [ +  - ][ +  - ]:         14 :         static ::chart::tPropertyValueMap aStaticDefaults;
         [ +  - ][ #  # ]
     115                 :         14 :         lcl_AddDefaultsToMap( aStaticDefaults );
     116                 :         14 :         return &aStaticDefaults;
     117                 :            :     }
     118                 :            : private:
     119                 :         14 :     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
     120                 :            :     {
     121         [ +  - ]:         14 :         ::chart::LineProperties::AddDefaultsToMap( rOutMap );
     122         [ +  - ]:         14 :         ::chart::FillProperties::AddDefaultsToMap( rOutMap );
     123         [ +  - ]:         14 :         ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
     124                 :            : 
     125         [ +  - ]:         14 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_ANCHOR_POSITION, chart2::LegendPosition_LINE_END );
     126         [ +  - ]:         14 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_EXPANSION, ::com::sun::star::chart::ChartLegendExpansion_HIGH );
     127         [ +  - ]:         14 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_SHOW, true );
     128                 :            : 
     129                 :         14 :         float fDefaultCharHeight = 10.0;
     130         [ +  - ]:         14 :         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
     131         [ +  - ]:         14 :         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
     132         [ +  - ]:         14 :         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
     133                 :         14 :     }
     134                 :            : };
     135                 :            : 
     136                 :            : struct StaticLegendDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticLegendDefaults_Initializer >
     137                 :            : {
     138                 :            : };
     139                 :            : 
     140                 :            : struct StaticLegendInfoHelper_Initializer
     141                 :            : {
     142                 :         14 :     ::cppu::OPropertyArrayHelper* operator()()
     143                 :            :     {
     144 [ +  - ][ +  - ]:         14 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
         [ +  - ][ +  - ]
         [ +  - ][ #  # ]
     145                 :         14 :         return &aPropHelper;
     146                 :            :     }
     147                 :            : 
     148                 :            : private:
     149                 :         14 :     Sequence< Property > lcl_GetPropertySequence()
     150                 :            :     {
     151         [ +  - ]:         14 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
     152         [ +  - ]:         14 :         lcl_AddPropertiesToVector( aProperties );
     153         [ +  - ]:         14 :         ::chart::LineProperties::AddPropertiesToVector( aProperties );
     154         [ +  - ]:         14 :         ::chart::FillProperties::AddPropertiesToVector( aProperties );
     155         [ +  - ]:         14 :         ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
     156         [ +  - ]:         14 :         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
     157                 :            : 
     158                 :            :         ::std::sort( aProperties.begin(), aProperties.end(),
     159         [ +  - ]:         14 :                      ::chart::PropertyNameLess() );
     160                 :            : 
     161         [ +  - ]:         14 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
     162                 :            :     }
     163                 :            : };
     164                 :            : 
     165                 :            : struct StaticLegendInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticLegendInfoHelper_Initializer >
     166                 :            : {
     167                 :            : };
     168                 :            : 
     169                 :            : struct StaticLegendInfo_Initializer
     170                 :            : {
     171                 :         12 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     172                 :            :     {
     173                 :            :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     174 [ +  - ][ +  - ]:         12 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticLegendInfoHelper::get() ) );
         [ +  - ][ +  - ]
                 [ #  # ]
     175                 :         12 :         return &xPropertySetInfo;
     176                 :            :     }
     177                 :            : };
     178                 :            : 
     179                 :            : struct StaticLegendInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticLegendInfo_Initializer >
     180                 :            : {
     181                 :            : };
     182                 :            : 
     183                 :            : } // anonymous namespace
     184                 :            : 
     185                 :            : namespace chart
     186                 :            : {
     187                 :            : 
     188                 :         62 : Legend::Legend( Reference< uno::XComponentContext > const & /* xContext */ ) :
     189                 :            :         ::property::OPropertySet( m_aMutex ),
     190 [ +  - ][ +  - ]:         62 :         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
                 [ +  - ]
     191                 :            : {
     192                 :         62 : }
     193                 :            : 
     194                 :          0 : Legend::Legend( const Legend & rOther ) :
     195                 :            :         MutexContainer(),
     196                 :            :         impl::Legend_Base(),
     197                 :            :         ::property::OPropertySet( rOther, m_aMutex ),
     198 [ #  # ][ #  # ]:          0 :     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
                 [ #  # ]
     199                 :            : {
     200                 :          0 : }
     201                 :            : 
     202 [ +  - ][ +  - ]:         62 : Legend::~Legend()
     203                 :            : {
     204         [ -  + ]:        124 : }
     205                 :            : 
     206                 :            : // ____ XCloneable ____
     207                 :          0 : Reference< util::XCloneable > SAL_CALL Legend::createClone()
     208                 :            :     throw (uno::RuntimeException)
     209                 :            : {
     210 [ #  # ][ #  # ]:          0 :     return Reference< util::XCloneable >( new Legend( *this ));
     211                 :            : }
     212                 :            : 
     213                 :            : // ____ XModifyBroadcaster ____
     214                 :         62 : void SAL_CALL Legend::addModifyListener( const Reference< util::XModifyListener >& aListener )
     215                 :            :     throw (uno::RuntimeException)
     216                 :            : {
     217                 :            :     try
     218                 :            :     {
     219         [ +  - ]:         62 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     220 [ +  - ][ +  - ]:         62 :         xBroadcaster->addModifyListener( aListener );
                 [ #  # ]
     221                 :            :     }
     222                 :          0 :     catch( const uno::Exception & ex )
     223                 :            :     {
     224                 :            :         ASSERT_EXCEPTION( ex );
     225                 :            :     }
     226                 :         62 : }
     227                 :            : 
     228                 :         62 : void SAL_CALL Legend::removeModifyListener( const Reference< util::XModifyListener >& aListener )
     229                 :            :     throw (uno::RuntimeException)
     230                 :            : {
     231                 :            :     try
     232                 :            :     {
     233         [ +  - ]:         62 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     234 [ +  - ][ +  - ]:         62 :         xBroadcaster->removeModifyListener( aListener );
                 [ #  # ]
     235                 :            :     }
     236                 :          0 :     catch( const uno::Exception & ex )
     237                 :            :     {
     238                 :            :         ASSERT_EXCEPTION( ex );
     239                 :            :     }
     240                 :         62 : }
     241                 :            : 
     242                 :            : // ____ XModifyListener ____
     243                 :          0 : void SAL_CALL Legend::modified( const lang::EventObject& aEvent )
     244                 :            :     throw (uno::RuntimeException)
     245                 :            : {
     246                 :          0 :     m_xModifyEventForwarder->modified( aEvent );
     247                 :          0 : }
     248                 :            : 
     249                 :            : // ____ XEventListener (base of XModifyListener) ____
     250                 :          0 : void SAL_CALL Legend::disposing( const lang::EventObject& /* Source */ )
     251                 :            :     throw (uno::RuntimeException)
     252                 :            : {
     253                 :            :     // nothing
     254                 :          0 : }
     255                 :            : 
     256                 :            : // ____ OPropertySet ____
     257                 :        497 : void Legend::firePropertyChangeEvent()
     258                 :            : {
     259                 :        497 :     fireModifyEvent();
     260                 :        497 : }
     261                 :            : 
     262                 :        497 : void Legend::fireModifyEvent()
     263                 :            : {
     264 [ +  - ][ +  - ]:        497 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
                 [ +  - ]
     265                 :        497 : }
     266                 :            : 
     267                 :            : // ================================================================================
     268                 :            : 
     269                 :         14 : Sequence< OUString > Legend::getSupportedServiceNames_Static()
     270                 :            : {
     271                 :         14 :     const sal_Int32 nNumServices( 6 );
     272                 :         14 :     sal_Int32 nI = 0;
     273                 :         14 :     Sequence< OUString > aServices( nNumServices );
     274 [ +  - ][ +  - ]:         14 :     aServices[ nI++ ] = C2U( "com.sun.star.chart2.Legend" );
     275 [ +  - ][ +  - ]:         14 :     aServices[ nI++ ] = C2U( "com.sun.star.beans.PropertySet" );
     276 [ +  - ][ +  - ]:         14 :     aServices[ nI++ ] = C2U( "com.sun.star.drawing.FillProperties" );
     277 [ +  - ][ +  - ]:         14 :     aServices[ nI++ ] = C2U( "com.sun.star.drawing.LineProperties" );
     278 [ +  - ][ +  - ]:         14 :     aServices[ nI++ ] = C2U( "com.sun.star.style.CharacterProperties" );
     279 [ +  - ][ +  - ]:         14 :     aServices[ nI++ ] = C2U( "com.sun.star.layout.LayoutElement" );
     280                 :            :     OSL_ASSERT( nNumServices == nI );
     281                 :         14 :     return aServices;
     282                 :            : }
     283                 :            : 
     284                 :            : // ____ OPropertySet ____
     285                 :     210639 : Any Legend::GetDefaultValue( sal_Int32 nHandle ) const
     286                 :            :     throw(beans::UnknownPropertyException)
     287                 :            : {
     288         [ +  - ]:     210639 :     const tPropertyValueMap& rStaticDefaults = *StaticLegendDefaults::get();
     289         [ +  - ]:     210639 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     290         [ +  + ]:     210639 :     if( aFound == rStaticDefaults.end() )
     291                 :      15782 :         return uno::Any();
     292                 :     210639 :     return (*aFound).second;
     293                 :            : }
     294                 :            : 
     295                 :     450862 : ::cppu::IPropertyArrayHelper & SAL_CALL Legend::getInfoHelper()
     296                 :            : {
     297                 :     450862 :     return *StaticLegendInfoHelper::get();
     298                 :            : }
     299                 :            : 
     300                 :            : // ____ XPropertySet ____
     301                 :       3205 : Reference< beans::XPropertySetInfo > SAL_CALL Legend::getPropertySetInfo()
     302                 :            :     throw (uno::RuntimeException)
     303                 :            : {
     304                 :       3205 :     return *StaticLegendInfo::get();
     305                 :            : }
     306                 :            : 
     307                 :            : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     308 [ #  # ][ #  # ]:        173 : APPHELPER_XSERVICEINFO_IMPL( Legend, lcl_aServiceName );
         [ #  # ][ #  # ]
                 [ #  # ]
     309                 :            : 
     310                 :            : // needed by MSC compiler
     311                 :            : using impl::Legend_Base;
     312                 :            : 
     313 [ +  + ][ +  - ]:     101546 : IMPLEMENT_FORWARD_XINTERFACE2( Legend, Legend_Base, ::property::OPropertySet )
     314 [ #  # ][ #  # ]:          0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( Legend, Legend_Base, ::property::OPropertySet )
                 [ #  # ]
     315                 :            : 
     316 [ +  - ][ +  - ]:         48 : } //  namespace chart
     317                 :            : 
     318                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10