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

Generated by: LCOV version 1.10