LCOV - code coverage report
Current view: top level - chart2/source/model/main - GridProperties.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 59 80 73.8 %
Date: 2014-11-03 Functions: 22 33 66.7 %
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 "GridProperties.hxx"
      21             : #include "LinePropertiesHelper.hxx"
      22             : #include "UserDefinedProperties.hxx"
      23             : #include "PropertyHelper.hxx"
      24             : #include "macros.hxx"
      25             : #include "ContainerHelper.hxx"
      26             : #include <com/sun/star/style/XStyle.hpp>
      27             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      28             : #include <com/sun/star/beans/XPropertySet.hpp>
      29             : #include <com/sun/star/uno/Sequence.hxx>
      30             : 
      31             : using namespace ::com::sun::star;
      32             : 
      33             : using ::com::sun::star::uno::Reference;
      34             : using ::com::sun::star::uno::Sequence;
      35             : using ::com::sun::star::beans::Property;
      36             : using ::osl::MutexGuard;
      37             : 
      38             : namespace
      39             : {
      40             : 
      41          36 : static const OUString lcl_aServiceName( "com.sun.star.comp.chart2.GridProperties" );
      42             : 
      43             : enum
      44             : {
      45             :     PROP_GRID_SHOW
      46             : };
      47             : 
      48          30 : void lcl_AddPropertiesToVector(
      49             :     ::std::vector< Property > & rOutProperties )
      50             : {
      51             :     rOutProperties.push_back(
      52             :         Property( "Show",
      53             :                   PROP_GRID_SHOW,
      54          30 :                   ::getBooleanCppuType(),
      55             :                   beans::PropertyAttribute::BOUND
      56          60 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      57          30 : }
      58             : 
      59             : struct StaticGridDefaults_Initializer
      60             : {
      61          30 :     ::chart::tPropertyValueMap* operator()()
      62             :     {
      63          30 :         static ::chart::tPropertyValueMap aStaticDefaults;
      64          30 :         lcl_AddDefaultsToMap( aStaticDefaults );
      65          30 :         return &aStaticDefaults;
      66             :     }
      67             : private:
      68          30 :     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
      69             :     {
      70          30 :         ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap );
      71             : 
      72          30 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_GRID_SHOW, false );
      73             : 
      74             :         // override other defaults
      75             :         ::chart::PropertyHelper::setPropertyValue< sal_Int32 >(
      76          30 :             rOutMap, ::chart::LinePropertiesHelper::PROP_LINE_COLOR, 0xb3b3b3 );  // gray30
      77          30 :     }
      78             : };
      79             : 
      80             : struct StaticGridDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticGridDefaults_Initializer >
      81             : {
      82             : };
      83             : 
      84             : struct StaticGridInfoHelper_Initializer
      85             : {
      86          30 :     ::cppu::OPropertyArrayHelper* operator()()
      87             :     {
      88          30 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
      89          30 :         return &aPropHelper;
      90             :     }
      91             : 
      92             : private:
      93          30 :     Sequence< Property > lcl_GetPropertySequence()
      94             :     {
      95          30 :         ::std::vector< Property > aProperties;
      96          30 :         lcl_AddPropertiesToVector( aProperties );
      97          30 :         ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
      98          30 :         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
      99             : 
     100             :         ::std::sort( aProperties.begin(), aProperties.end(),
     101          30 :                      ::chart::PropertyNameLess() );
     102             : 
     103          30 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
     104             :     }
     105             : 
     106             : };
     107             : 
     108             : struct StaticGridInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticGridInfoHelper_Initializer >
     109             : {
     110             : };
     111             : 
     112             : struct StaticGridInfo_Initializer
     113             : {
     114          12 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     115             :     {
     116             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     117          12 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticGridInfoHelper::get() ) );
     118          12 :         return &xPropertySetInfo;
     119             :     }
     120             : };
     121             : 
     122             : struct StaticGridInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticGridInfo_Initializer >
     123             : {
     124             : };
     125             : 
     126             : } // anonymous namespace
     127             : 
     128             : namespace chart
     129             : {
     130             : 
     131           0 : GridProperties::GridProperties( Reference< uno::XComponentContext > const & /* xContext */ ) :
     132             :         ::property::OPropertySet( m_aMutex ),
     133           0 :     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     134             : {
     135           0 : }
     136             : 
     137        4504 : GridProperties::GridProperties() :
     138             :         ::property::OPropertySet( m_aMutex ),
     139        4504 :     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     140        4504 : {}
     141             : 
     142           0 : GridProperties::GridProperties( const GridProperties & rOther ) :
     143             :         MutexContainer(),
     144             :         impl::GridProperties_Base(),
     145             :         ::property::OPropertySet( rOther, m_aMutex ),
     146           0 :     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     147             : {
     148           0 : }
     149             : 
     150        8800 : GridProperties::~GridProperties()
     151        8800 : {}
     152             : 
     153             : // ____ OPropertySet ____
     154       41199 : uno::Any GridProperties::GetDefaultValue( sal_Int32 nHandle ) const
     155             :     throw(beans::UnknownPropertyException)
     156             : {
     157       41199 :     const tPropertyValueMap& rStaticDefaults = *StaticGridDefaults::get();
     158       41199 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     159       41199 :     if( aFound == rStaticDefaults.end() )
     160         501 :         return uno::Any();
     161       40698 :     return (*aFound).second;
     162             : }
     163             : 
     164      102634 : ::cppu::IPropertyArrayHelper & SAL_CALL GridProperties::getInfoHelper()
     165             : {
     166      102634 :     return *StaticGridInfoHelper::get();
     167             : }
     168             : 
     169             : // ____ XPropertySet ____
     170         952 : Reference< beans::XPropertySetInfo > SAL_CALL GridProperties::getPropertySetInfo()
     171             :     throw (uno::RuntimeException, std::exception)
     172             : {
     173         952 :     return *StaticGridInfo::get();
     174             : }
     175             : 
     176             : // ____ XCloneable ____
     177           0 : uno::Reference< util::XCloneable > SAL_CALL GridProperties::createClone()
     178             :     throw (uno::RuntimeException, std::exception)
     179             : {
     180           0 :     return uno::Reference< util::XCloneable >( new GridProperties( *this ));
     181             : }
     182             : 
     183             : // ____ XModifyBroadcaster ____
     184        4504 : void SAL_CALL GridProperties::addModifyListener( const Reference< util::XModifyListener >& aListener )
     185             :     throw (uno::RuntimeException, std::exception)
     186             : {
     187             :     try
     188             :     {
     189        4504 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     190        4504 :         xBroadcaster->addModifyListener( aListener );
     191             :     }
     192           0 :     catch( const uno::Exception & ex )
     193             :     {
     194             :         ASSERT_EXCEPTION( ex );
     195             :     }
     196        4504 : }
     197             : 
     198        4400 : void SAL_CALL GridProperties::removeModifyListener( const Reference< util::XModifyListener >& aListener )
     199             :     throw (uno::RuntimeException, std::exception)
     200             : {
     201             :     try
     202             :     {
     203        4400 :         Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     204        4400 :         xBroadcaster->removeModifyListener( aListener );
     205             :     }
     206           0 :     catch( const uno::Exception & ex )
     207             :     {
     208             :         ASSERT_EXCEPTION( ex );
     209             :     }
     210        4400 : }
     211             : 
     212             : // ____ XModifyListener ____
     213           0 : void SAL_CALL GridProperties::modified( const lang::EventObject& aEvent )
     214             :     throw (uno::RuntimeException, std::exception)
     215             : {
     216           0 :     m_xModifyEventForwarder->modified( aEvent );
     217           0 : }
     218             : 
     219             : // ____ XEventListener (base of XModifyListener) ____
     220           0 : void SAL_CALL GridProperties::disposing( const lang::EventObject& /* Source */ )
     221             :     throw (uno::RuntimeException, std::exception)
     222             : {
     223             :     // nothing
     224           0 : }
     225             : 
     226             : // ____ OPropertySet ____
     227        5348 : void GridProperties::firePropertyChangeEvent()
     228             : {
     229        5348 :     fireModifyEvent();
     230        5348 : }
     231             : 
     232        5348 : void GridProperties::fireModifyEvent()
     233             : {
     234        5348 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
     235        5348 : }
     236             : 
     237           0 : Sequence< OUString > GridProperties::getSupportedServiceNames_Static()
     238             : {
     239           0 :     Sequence< OUString > aServices( 2 );
     240           0 :     aServices[ 0 ] = "com.sun.star.chart2.GridProperties";
     241           0 :     aServices[ 1 ] = "com.sun.star.beans.PropertySet";
     242           0 :     return aServices;
     243             : }
     244             : 
     245             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     246         486 : APPHELPER_XSERVICEINFO_IMPL( GridProperties, lcl_aServiceName );
     247             : 
     248             : // needed by MSC compiler
     249             : using impl::GridProperties_Base;
     250             : 
     251      294896 : IMPLEMENT_FORWARD_XINTERFACE2( GridProperties, GridProperties_Base, ::property::OPropertySet )
     252           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( GridProperties, GridProperties_Base, ::property::OPropertySet )
     253             : 
     254         108 : } //  namespace chart
     255             : 
     256             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10