LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/model/main - Legend.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 89 102 87.3 %
Date: 2012-12-27 Functions: 23 32 71.9 %
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 "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           1 : 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           1 : void lcl_AddPropertiesToVector(
      65             :     ::std::vector< Property > & rOutProperties )
      66             : {
      67             :     rOutProperties.push_back(
      68             :         Property( C2U( "AnchorPosition" ),
      69             :                   PROP_LEGEND_ANCHOR_POSITION,
      70           1 :                   ::getCppuType( reinterpret_cast< const chart2::LegendPosition * >(0)),
      71             :                   beans::PropertyAttribute::BOUND
      72           2 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      73             : 
      74             :     rOutProperties.push_back(
      75             :         Property( C2U( "Expansion" ),
      76             :                   PROP_LEGEND_EXPANSION,
      77           1 :                   ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartLegendExpansion * >(0)),
      78             :                   beans::PropertyAttribute::BOUND
      79           2 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      80             : 
      81             :     rOutProperties.push_back(
      82             :         Property( C2U( "Show" ),
      83             :                   PROP_LEGEND_SHOW,
      84           1 :                   ::getBooleanCppuType(),
      85             :                   beans::PropertyAttribute::BOUND
      86           2 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      87             :     rOutProperties.push_back(
      88             :         Property( C2U( "ReferencePageSize" ),
      89             :                   PROP_LEGEND_REF_PAGE_SIZE,
      90           1 :                   ::getCppuType( reinterpret_cast< const awt::Size * >(0)),
      91             :                   beans::PropertyAttribute::BOUND
      92           2 :                   | beans::PropertyAttribute::MAYBEVOID ));
      93             : 
      94             :     rOutProperties.push_back(
      95             :         Property( C2U( "RelativePosition" ),
      96             :                   PROP_LEGEND_REL_POS,
      97           1 :                   ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)),
      98             :                   beans::PropertyAttribute::BOUND
      99           2 :                   | beans::PropertyAttribute::MAYBEVOID ));
     100             : 
     101             :     rOutProperties.push_back(
     102             :         Property( C2U( "RelativeSize" ),
     103             :                   PROP_LEGEND_REL_SIZE,
     104           1 :                   ::getCppuType( reinterpret_cast< const chart2::RelativeSize * >(0)),
     105             :                   beans::PropertyAttribute::BOUND
     106           2 :                   | beans::PropertyAttribute::MAYBEVOID ));
     107             : 
     108           1 : }
     109             : 
     110             : struct StaticLegendDefaults_Initializer
     111             : {
     112           1 :     ::chart::tPropertyValueMap* operator()()
     113             :     {
     114           1 :         static ::chart::tPropertyValueMap aStaticDefaults;
     115           1 :         lcl_AddDefaultsToMap( aStaticDefaults );
     116           1 :         return &aStaticDefaults;
     117             :     }
     118             : private:
     119           1 :     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
     120             :     {
     121           1 :         ::chart::LineProperties::AddDefaultsToMap( rOutMap );
     122           1 :         ::chart::FillProperties::AddDefaultsToMap( rOutMap );
     123           1 :         ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
     124             : 
     125           1 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_ANCHOR_POSITION, chart2::LegendPosition_LINE_END );
     126           1 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_EXPANSION, ::com::sun::star::chart::ChartLegendExpansion_HIGH );
     127           1 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_SHOW, true );
     128             : 
     129           1 :         float fDefaultCharHeight = 10.0;
     130           1 :         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
     131           1 :         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
     132           1 :         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
     133           1 :     }
     134             : };
     135             : 
     136             : struct StaticLegendDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticLegendDefaults_Initializer >
     137             : {
     138             : };
     139             : 
     140             : struct StaticLegendInfoHelper_Initializer
     141             : {
     142           1 :     ::cppu::OPropertyArrayHelper* operator()()
     143             :     {
     144           1 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
     145           1 :         return &aPropHelper;
     146             :     }
     147             : 
     148             : private:
     149           1 :     Sequence< Property > lcl_GetPropertySequence()
     150             :     {
     151           1 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
     152           1 :         lcl_AddPropertiesToVector( aProperties );
     153           1 :         ::chart::LineProperties::AddPropertiesToVector( aProperties );
     154           1 :         ::chart::FillProperties::AddPropertiesToVector( aProperties );
     155           1 :         ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
     156           1 :         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
     157             : 
     158             :         ::std::sort( aProperties.begin(), aProperties.end(),
     159           1 :                      ::chart::PropertyNameLess() );
     160             : 
     161           1 :         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           1 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     172             :     {
     173             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     174           1 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticLegendInfoHelper::get() ) );
     175           1 :         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         124 : 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         392 : void Legend::firePropertyChangeEvent()
     258             : {
     259         392 :     fireModifyEvent();
     260         392 : }
     261             : 
     262         392 : void Legend::fireModifyEvent()
     263             : {
     264         392 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
     265         392 : }
     266             : 
     267             : // ================================================================================
     268             : 
     269           1 : Sequence< OUString > Legend::getSupportedServiceNames_Static()
     270             : {
     271           1 :     const sal_Int32 nNumServices( 6 );
     272           1 :     sal_Int32 nI = 0;
     273           1 :     Sequence< OUString > aServices( nNumServices );
     274           1 :     aServices[ nI++ ] = C2U( "com.sun.star.chart2.Legend" );
     275           1 :     aServices[ nI++ ] = C2U( "com.sun.star.beans.PropertySet" );
     276           1 :     aServices[ nI++ ] = C2U( "com.sun.star.drawing.FillProperties" );
     277           1 :     aServices[ nI++ ] = C2U( "com.sun.star.drawing.LineProperties" );
     278           1 :     aServices[ nI++ ] = C2U( "com.sun.star.style.CharacterProperties" );
     279           1 :     aServices[ nI++ ] = C2U( "com.sun.star.layout.LayoutElement" );
     280             :     OSL_ASSERT( nNumServices == nI );
     281           1 :     return aServices;
     282             : }
     283             : 
     284             : // ____ OPropertySet ____
     285        9705 : Any Legend::GetDefaultValue( sal_Int32 nHandle ) const
     286             :     throw(beans::UnknownPropertyException)
     287             : {
     288        9705 :     const tPropertyValueMap& rStaticDefaults = *StaticLegendDefaults::get();
     289        9705 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     290        9705 :     if( aFound == rStaticDefaults.end() )
     291         714 :         return uno::Any();
     292        8991 :     return (*aFound).second;
     293             : }
     294             : 
     295       18744 : ::cppu::IPropertyArrayHelper & SAL_CALL Legend::getInfoHelper()
     296             : {
     297       18744 :     return *StaticLegendInfoHelper::get();
     298             : }
     299             : 
     300             : // ____ XPropertySet ____
     301         123 : Reference< beans::XPropertySetInfo > SAL_CALL Legend::getPropertySetInfo()
     302             :     throw (uno::RuntimeException)
     303             : {
     304         123 :     return *StaticLegendInfo::get();
     305             : }
     306             : 
     307             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     308          16 : APPHELPER_XSERVICEINFO_IMPL( Legend, lcl_aServiceName );
     309             : 
     310             : // needed by MSC compiler
     311             : using impl::Legend_Base;
     312             : 
     313        6138 : IMPLEMENT_FORWARD_XINTERFACE2( Legend, Legend_Base, ::property::OPropertySet )
     314           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( Legend, Legend_Base, ::property::OPropertySet )
     315             : 
     316           3 : } //  namespace chart
     317             : 
     318             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10