LCOV - code coverage report
Current view: top level - chart2/source/model/main - FormattedString.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 69 84 82.1 %
Date: 2015-06-13 12:38:46 Functions: 25 32 78.1 %
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 "FormattedString.hxx"
      21             : #include "ContainerHelper.hxx"
      22             : 
      23             : #include "CharacterProperties.hxx"
      24             : #include "PropertyHelper.hxx"
      25             : #include "macros.hxx"
      26             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      27             : #include <cppuhelper/supportsservice.hxx>
      28             : 
      29             : using namespace ::com::sun::star;
      30             : 
      31             : using ::com::sun::star::beans::Property;
      32             : using ::com::sun::star::uno::Sequence;
      33             : using ::com::sun::star::uno::Reference;
      34             : using ::com::sun::star::uno::Any;
      35             : using ::osl::MutexGuard;
      36             : 
      37             : namespace
      38             : {
      39             : 
      40             : struct StaticFormattedStringDefaults_Initializer
      41             : {
      42          12 :     ::chart::tPropertyValueMap* operator()()
      43             :     {
      44          12 :         static ::chart::tPropertyValueMap aStaticDefaults;
      45          12 :         lcl_AddDefaultsToMap( aStaticDefaults );
      46          12 :         return &aStaticDefaults;
      47             :     }
      48             : private:
      49          12 :     static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
      50             :     {
      51          12 :         ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
      52          12 :     }
      53             : };
      54             : 
      55             : struct StaticFormattedStringDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticFormattedStringDefaults_Initializer >
      56             : {
      57             : };
      58             : 
      59             : struct StaticFormattedStringInfoHelper_Initializer
      60             : {
      61          12 :     ::cppu::OPropertyArrayHelper* operator()()
      62             :     {
      63          12 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
      64          12 :         return &aPropHelper;
      65             :     }
      66             : 
      67             : private:
      68          12 :     static Sequence< Property > lcl_GetPropertySequence()
      69             :     {
      70          12 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
      71          12 :         ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
      72             : 
      73             :         ::std::sort( aProperties.begin(), aProperties.end(),
      74          12 :                      ::chart::PropertyNameLess() );
      75             : 
      76          12 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
      77             :     }
      78             : 
      79             : };
      80             : 
      81             : struct StaticFormattedStringInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticFormattedStringInfoHelper_Initializer >
      82             : {
      83             : };
      84             : 
      85             : struct StaticFormattedStringInfo_Initializer
      86             : {
      87           8 :     uno::Reference< beans::XPropertySetInfo >* operator()()
      88             :     {
      89             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
      90           8 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticFormattedStringInfoHelper::get() ) );
      91           8 :         return &xPropertySetInfo;
      92             :     }
      93             : };
      94             : 
      95             : struct StaticFormattedStringInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticFormattedStringInfo_Initializer >
      96             : {
      97             : };
      98             : 
      99             : } // anonymous namespace
     100             : 
     101             : namespace chart
     102             : {
     103             : 
     104        2939 : FormattedString::FormattedString(
     105             :         uno::Reference< uno::XComponentContext > const & /* xContext */ ) :
     106             :         ::property::OPropertySet( m_aMutex ),
     107             :     m_aString(),
     108        2939 :     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     109        2939 : {}
     110             : 
     111           0 : FormattedString::FormattedString( const FormattedString & rOther ) :
     112             :         MutexContainer(),
     113             :         impl::FormattedString_Base(),
     114             :         ::property::OPropertySet( rOther, m_aMutex ),
     115             :     m_aString( rOther.m_aString ),
     116           0 :     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     117           0 : {}
     118             : 
     119        5878 : FormattedString::~FormattedString()
     120        5878 : {}
     121             : 
     122             : // ____ XCloneable ____
     123           0 : uno::Reference< util::XCloneable > SAL_CALL FormattedString::createClone()
     124             :     throw (uno::RuntimeException, std::exception)
     125             : {
     126           0 :     return uno::Reference< util::XCloneable >( new FormattedString( *this ));
     127             : }
     128             : 
     129             : // ____ XFormattedString ____
     130        5142 : OUString SAL_CALL FormattedString::getString()
     131             :     throw (uno::RuntimeException, std::exception)
     132             : {
     133        5142 :     MutexGuard aGuard( GetMutex());
     134        5142 :     return m_aString;
     135             : }
     136             : 
     137        2989 : void SAL_CALL FormattedString::setString( const OUString& String )
     138             :     throw (uno::RuntimeException, std::exception)
     139             : {
     140             :     {
     141        2989 :         MutexGuard aGuard( GetMutex());
     142        2989 :         m_aString = String;
     143             :     }
     144             :     //don't keep the mutex locked while calling out
     145        2989 :     fireModifyEvent();
     146             : 
     147        2989 : }
     148             : 
     149             : // ____ XModifyBroadcaster ____
     150         281 : void SAL_CALL FormattedString::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     151             :     throw (uno::RuntimeException, std::exception)
     152             : {
     153             :     try
     154             :     {
     155         281 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     156         281 :         xBroadcaster->addModifyListener( aListener );
     157             :     }
     158           0 :     catch( const uno::Exception & ex )
     159             :     {
     160             :         ASSERT_EXCEPTION( ex );
     161             :     }
     162         281 : }
     163             : 
     164         281 : void SAL_CALL FormattedString::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     165             :     throw (uno::RuntimeException, std::exception)
     166             : {
     167             :     try
     168             :     {
     169         281 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     170         281 :         xBroadcaster->removeModifyListener( aListener );
     171             :     }
     172           0 :     catch( const uno::Exception & ex )
     173             :     {
     174             :         ASSERT_EXCEPTION( ex );
     175             :     }
     176         281 : }
     177             : 
     178             : // ____ XModifyListener ____
     179           0 : void SAL_CALL FormattedString::modified( const lang::EventObject& aEvent )
     180             :     throw (uno::RuntimeException, std::exception)
     181             : {
     182           0 :     m_xModifyEventForwarder->modified( aEvent );
     183           0 : }
     184             : 
     185             : // ____ XEventListener (base of XModifyListener) ____
     186           0 : void SAL_CALL FormattedString::disposing( const lang::EventObject& /* Source */ )
     187             :     throw (uno::RuntimeException, std::exception)
     188             : {
     189             :     // nothing
     190           0 : }
     191             : 
     192             : // ____ OPropertySet ____
     193      125442 : void FormattedString::firePropertyChangeEvent()
     194             : {
     195      125442 :     fireModifyEvent();
     196      125442 : }
     197             : 
     198      128431 : void FormattedString::fireModifyEvent()
     199             : {
     200      128431 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
     201      128431 : }
     202             : 
     203           1 : Sequence< OUString > FormattedString::getSupportedServiceNames_Static()
     204             : {
     205           1 :     Sequence< OUString > aServices( 2 );
     206             : 
     207           1 :     aServices[ 0 ] = "com.sun.star.chart2.FormattedString";
     208           1 :     aServices[ 1 ] = "com.sun.star.beans.PropertySet";
     209           1 :     return aServices;
     210             : }
     211             : 
     212             : // ____ OPropertySet ____
     213      172513 : uno::Any FormattedString::GetDefaultValue( sal_Int32 nHandle ) const
     214             :     throw (beans::UnknownPropertyException, uno::RuntimeException)
     215             : {
     216      172513 :     const tPropertyValueMap& rStaticDefaults = *StaticFormattedStringDefaults::get();
     217      172513 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     218      172513 :     if( aFound == rStaticDefaults.end() )
     219        6858 :         return uno::Any();
     220      165655 :     return (*aFound).second;
     221             : }
     222             : 
     223             : // ____ OPropertySet ____
     224      367848 : ::cppu::IPropertyArrayHelper & SAL_CALL FormattedString::getInfoHelper()
     225             : {
     226      367848 :     return *StaticFormattedStringInfoHelper::get();
     227             : }
     228             : 
     229             : // ____ XPropertySet ____
     230        2831 : uno::Reference< beans::XPropertySetInfo > SAL_CALL FormattedString::getPropertySetInfo()
     231             :     throw (uno::RuntimeException, std::exception)
     232             : {
     233        2831 :     return *StaticFormattedStringInfo::get();
     234             : }
     235             : 
     236             : using impl::FormattedString_Base;
     237             : 
     238      901576 : IMPLEMENT_FORWARD_XINTERFACE2( FormattedString, FormattedString_Base, ::property::OPropertySet )
     239           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( FormattedString, FormattedString_Base, ::property::OPropertySet )
     240             : 
     241             : // do this in derived classes!
     242             : 
     243             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     244           1 : OUString SAL_CALL FormattedString::getImplementationName()
     245             :     throw( css::uno::RuntimeException, std::exception )
     246             : {
     247           1 :     return getImplementationName_Static();
     248             : }
     249             : 
     250           1 : OUString FormattedString::getImplementationName_Static()
     251             : {
     252           1 :     return OUString("com.sun.star.comp.chart.FormattedString");
     253             : }
     254             : 
     255           0 : sal_Bool SAL_CALL FormattedString::supportsService( const OUString& rServiceName )
     256             :     throw( css::uno::RuntimeException, std::exception )
     257             : {
     258           0 :     return cppu::supportsService(this, rServiceName);
     259             : }
     260             : 
     261           1 : css::uno::Sequence< OUString > SAL_CALL FormattedString::getSupportedServiceNames()
     262             :     throw( css::uno::RuntimeException, std::exception )
     263             : {
     264           1 :     return getSupportedServiceNames_Static();
     265             : }
     266             : 
     267             : } //  namespace chart
     268             : 
     269             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     270        2939 : com_sun_star_comp_chart_FormattedString_get_implementation(css::uno::XComponentContext *context,
     271             :         css::uno::Sequence<css::uno::Any> const &)
     272             : {
     273        2939 :     return cppu::acquire(new ::chart::FormattedString(context));
     274             : }
     275             : 
     276             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11