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

Generated by: LCOV version 1.10