LCOV - code coverage report
Current view: top level - chart2/source/model/main - Title.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 113 130 86.9 %
Date: 2015-06-13 12:38:46 Functions: 26 33 78.8 %
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 "Title.hxx"
      21             : #include "macros.hxx"
      22             : #include "FormattedString.hxx"
      23             : #include "LinePropertiesHelper.hxx"
      24             : #include "FillProperties.hxx"
      25             : #include "ContainerHelper.hxx"
      26             : #include "CloneHelper.hxx"
      27             : #include "PropertyHelper.hxx"
      28             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      29             : #include <com/sun/star/style/ParagraphAdjust.hpp>
      30             : #include <com/sun/star/drawing/FillStyle.hpp>
      31             : #include <com/sun/star/drawing/LineStyle.hpp>
      32             : #include <com/sun/star/chart2/RelativePosition.hpp>
      33             : #include <com/sun/star/awt/Size.hpp>
      34             : #include <rtl/uuid.h>
      35             : #include <cppuhelper/queryinterface.hxx>
      36             : #include <cppuhelper/supportsservice.hxx>
      37             : 
      38             : #include <vector>
      39             : #include <algorithm>
      40             : 
      41             : using namespace ::com::sun::star;
      42             : using namespace ::com::sun::star::beans::PropertyAttribute;
      43             : 
      44             : using ::com::sun::star::beans::Property;
      45             : using ::osl::MutexGuard;
      46             : 
      47             : namespace
      48             : {
      49             : 
      50             : static const char lcl_aServiceName[] = "com.sun.star.comp.chart2.Title";
      51             : 
      52             : enum
      53             : {
      54             :     PROP_TITLE_PARA_ADJUST,
      55             :     PROP_TITLE_PARA_LAST_LINE_ADJUST,
      56             :     PROP_TITLE_PARA_LEFT_MARGIN,
      57             :     PROP_TITLE_PARA_RIGHT_MARGIN,
      58             :     PROP_TITLE_PARA_TOP_MARGIN,
      59             :     PROP_TITLE_PARA_BOTTOM_MARGIN,
      60             :     PROP_TITLE_PARA_IS_HYPHENATION,
      61             : 
      62             :     PROP_TITLE_TEXT_ROTATION,
      63             :     PROP_TITLE_TEXT_STACKED,
      64             :     PROP_TITLE_REL_POS,
      65             : 
      66             :     PROP_TITLE_REF_PAGE_SIZE
      67             : };
      68             : 
      69           8 : void lcl_AddPropertiesToVector(
      70             :     ::std::vector< Property > & rOutProperties )
      71             : {
      72             :     rOutProperties.push_back(
      73             :         Property( "ParaAdjust",
      74             :                   PROP_TITLE_PARA_ADJUST,
      75           8 :                   cppu::UnoType<com::sun::star::style::ParagraphAdjust>::get(),
      76             :                   beans::PropertyAttribute::BOUND
      77          16 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      78             : 
      79             :     rOutProperties.push_back(
      80             :         Property( "ParaLastLineAdjust",
      81             :                   PROP_TITLE_PARA_LAST_LINE_ADJUST,
      82           8 :                   cppu::UnoType<sal_Int16>::get(),
      83             :                   beans::PropertyAttribute::BOUND
      84          16 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      85             : 
      86             :     rOutProperties.push_back(
      87             :         Property( "ParaLeftMargin",
      88             :                   PROP_TITLE_PARA_LEFT_MARGIN,
      89           8 :                   cppu::UnoType<sal_Int32>::get(),
      90             :                   beans::PropertyAttribute::BOUND
      91          16 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      92             : 
      93             :     rOutProperties.push_back(
      94             :         Property( "ParaRightMargin",
      95             :                   PROP_TITLE_PARA_RIGHT_MARGIN,
      96           8 :                   cppu::UnoType<sal_Int32>::get(),
      97             :                   beans::PropertyAttribute::BOUND
      98          16 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
      99             : 
     100             :     rOutProperties.push_back(
     101             :         Property( "ParaTopMargin",
     102             :                   PROP_TITLE_PARA_TOP_MARGIN,
     103           8 :                   cppu::UnoType<sal_Int32>::get(),
     104             :                   beans::PropertyAttribute::BOUND
     105          16 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     106             : 
     107             :     rOutProperties.push_back(
     108             :         Property( "ParaBottomMargin",
     109             :                   PROP_TITLE_PARA_BOTTOM_MARGIN,
     110           8 :                   cppu::UnoType<sal_Int32>::get(),
     111             :                   beans::PropertyAttribute::BOUND
     112          16 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     113             : 
     114             :     rOutProperties.push_back(
     115             :         Property( "ParaIsHyphenation",
     116             :                   PROP_TITLE_PARA_IS_HYPHENATION,
     117           8 :                   cppu::UnoType<bool>::get(),
     118             :                   beans::PropertyAttribute::BOUND
     119          16 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     120             : 
     121             :     rOutProperties.push_back(
     122             :         Property( "TextRotation",
     123             :                   PROP_TITLE_TEXT_ROTATION,
     124           8 :                   cppu::UnoType<double>::get(),
     125             :                   beans::PropertyAttribute::BOUND
     126          16 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     127             :     rOutProperties.push_back(
     128             :         Property( "StackCharacters",
     129             :                   PROP_TITLE_TEXT_STACKED,
     130           8 :                   cppu::UnoType<bool>::get(),
     131             :                   beans::PropertyAttribute::BOUND
     132          16 :                   | beans::PropertyAttribute::MAYBEDEFAULT ));
     133             : 
     134             :     rOutProperties.push_back(
     135             :         Property( "RelativePosition",
     136             :                   PROP_TITLE_REL_POS,
     137           8 :                   cppu::UnoType<chart2::RelativePosition>::get(),
     138             :                   beans::PropertyAttribute::BOUND
     139          16 :                   | beans::PropertyAttribute::MAYBEVOID ));
     140             : 
     141             :     rOutProperties.push_back(
     142             :         Property( "ReferencePageSize",
     143             :                   PROP_TITLE_REF_PAGE_SIZE,
     144           8 :                   cppu::UnoType<awt::Size>::get(),
     145             :                   beans::PropertyAttribute::BOUND
     146          16 :                   | beans::PropertyAttribute::MAYBEVOID ));
     147           8 : }
     148             : 
     149             : struct StaticTitleDefaults_Initializer
     150             : {
     151           8 :     ::chart::tPropertyValueMap* operator()()
     152             :     {
     153           8 :         static ::chart::tPropertyValueMap aStaticDefaults;
     154           8 :         lcl_AddDefaultsToMap( aStaticDefaults );
     155           8 :         return &aStaticDefaults;
     156             :     }
     157             : private:
     158           8 :     static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
     159             :     {
     160           8 :         ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap );
     161           8 :         ::chart::FillProperties::AddDefaultsToMap( rOutMap );
     162             : 
     163             :         // ParagraphProperties
     164             :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_PARA_ADJUST,
     165           8 :                                                           ::com::sun::star::style::ParagraphAdjust_CENTER );
     166             :         // PROP_TITLE_PARA_LAST_LINE_ADJUST
     167             : 
     168           8 :         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_LEFT_MARGIN, 0 );
     169           8 :         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_RIGHT_MARGIN, 0 );
     170           8 :         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_TOP_MARGIN, 0 );
     171           8 :         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_BOTTOM_MARGIN, 0 );
     172           8 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_PARA_IS_HYPHENATION, true );
     173             : 
     174             :         // own properties
     175           8 :         ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_TITLE_TEXT_ROTATION, 0.0 );
     176           8 :         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_TEXT_STACKED, false );
     177             : 
     178             :         // override other defaults
     179           8 :         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE );
     180           8 :         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LinePropertiesHelper::PROP_LINE_STYLE, drawing::LineStyle_NONE );
     181           8 :     }
     182             : };
     183             : 
     184             : struct StaticTitleDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticTitleDefaults_Initializer >
     185             : {
     186             : };
     187             : 
     188             : struct StaticTitleInfoHelper_Initializer
     189             : {
     190           8 :     ::cppu::OPropertyArrayHelper* operator()()
     191             :     {
     192           8 :         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
     193           8 :         return &aPropHelper;
     194             :     }
     195             : 
     196             : private:
     197           8 :     static uno::Sequence< Property > lcl_GetPropertySequence()
     198             :     {
     199           8 :         ::std::vector< ::com::sun::star::beans::Property > aProperties;
     200           8 :         lcl_AddPropertiesToVector( aProperties );
     201           8 :         ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
     202           8 :         ::chart::FillProperties::AddPropertiesToVector( aProperties );
     203             : 
     204             :         ::std::sort( aProperties.begin(), aProperties.end(),
     205           8 :                      ::chart::PropertyNameLess() );
     206             : 
     207           8 :         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
     208             :     }
     209             : 
     210             : };
     211             : 
     212             : struct StaticTitleInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticTitleInfoHelper_Initializer >
     213             : {
     214             : };
     215             : 
     216             : struct StaticTitleInfo_Initializer
     217             : {
     218           3 :     uno::Reference< beans::XPropertySetInfo >* operator()()
     219             :     {
     220             :         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
     221           3 :             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticTitleInfoHelper::get() ) );
     222           3 :         return &xPropertySetInfo;
     223             :     }
     224             : };
     225             : 
     226             : struct StaticTitleInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticTitleInfo_Initializer >
     227             : {
     228             : };
     229             : 
     230             : } // anonymous namespace
     231             : 
     232             : namespace chart
     233             : {
     234             : 
     235         215 : Title::Title( uno::Reference< uno::XComponentContext > const & /* xContext */ ) :
     236             :         ::property::OPropertySet( m_aMutex ),
     237         215 :         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     238         215 : {}
     239             : 
     240           0 : Title::Title( const Title & rOther ) :
     241             :         MutexContainer(),
     242             :         impl::Title_Base(),
     243             :         ::property::OPropertySet( rOther, m_aMutex ),
     244           0 :         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
     245             : {
     246             :     CloneHelper::CloneRefSequence< uno::Reference< chart2::XFormattedString > >(
     247           0 :         rOther.m_aStrings, m_aStrings );
     248             :     ModifyListenerHelper::addListenerToAllElements(
     249           0 :         ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
     250           0 : }
     251             : 
     252         645 : Title::~Title()
     253             : {
     254             :     ModifyListenerHelper::removeListenerFromAllElements(
     255         215 :         ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
     256         430 : }
     257             : 
     258             : // ____ XCloneable ____
     259           0 : uno::Reference< util::XCloneable > SAL_CALL Title::createClone()
     260             :     throw (uno::RuntimeException, std::exception)
     261             : {
     262           0 :     return uno::Reference< util::XCloneable >( new Title( *this ));
     263             : }
     264             : 
     265             : // ____ XTitle ____
     266       24886 : uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL Title::getText()
     267             :     throw (uno::RuntimeException, std::exception)
     268             : {
     269       24886 :     MutexGuard aGuard( GetMutex() );
     270       24886 :     return m_aStrings;
     271             : }
     272             : 
     273         265 : void SAL_CALL Title::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& rNewStrings )
     274             :     throw (uno::RuntimeException, std::exception)
     275             : {
     276         265 :     uno::Sequence< uno::Reference< chart2::XFormattedString > > aOldStrings;
     277             :     {
     278         265 :         MutexGuard aGuard( GetMutex() );
     279         265 :         std::swap( m_aStrings, aOldStrings );
     280         265 :         m_aStrings = rNewStrings;
     281             :     }
     282             :     //don't keep the mutex locked while calling out
     283             :     ModifyListenerHelper::removeListenerFromAllElements(
     284         265 :         ContainerHelper::SequenceToVector( aOldStrings ), m_xModifyEventForwarder );
     285             :     ModifyListenerHelper::addListenerToAllElements(
     286         265 :         ContainerHelper::SequenceToVector( rNewStrings ), m_xModifyEventForwarder );
     287         265 :     fireModifyEvent();
     288         265 : }
     289             : 
     290             : // ____ OPropertySet ____
     291       34272 : uno::Any Title::GetDefaultValue( sal_Int32 nHandle ) const
     292             :     throw(beans::UnknownPropertyException)
     293             : {
     294       34272 :     const tPropertyValueMap& rStaticDefaults = *StaticTitleDefaults::get();
     295       34272 :     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
     296       34272 :     if( aFound == rStaticDefaults.end() )
     297       10611 :         return uno::Any();
     298       23661 :     return (*aFound).second;
     299             : }
     300             : 
     301       82127 : ::cppu::IPropertyArrayHelper & SAL_CALL Title::getInfoHelper()
     302             : {
     303       82127 :     return *StaticTitleInfoHelper::get();
     304             : }
     305             : 
     306             : // ____ XPropertySet ____
     307         214 : uno::Reference< beans::XPropertySetInfo > SAL_CALL Title::getPropertySetInfo()
     308             :     throw (uno::RuntimeException, std::exception)
     309             : {
     310         214 :     return *StaticTitleInfo::get();
     311             : }
     312             : 
     313             : // ____ XModifyBroadcaster ____
     314         214 : void SAL_CALL Title::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     315             :     throw (uno::RuntimeException, std::exception)
     316             : {
     317             :     try
     318             :     {
     319         214 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     320         214 :         xBroadcaster->addModifyListener( aListener );
     321             :     }
     322           0 :     catch( const uno::Exception & ex )
     323             :     {
     324             :         ASSERT_EXCEPTION( ex );
     325             :     }
     326         214 : }
     327             : 
     328          80 : void SAL_CALL Title::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
     329             :     throw (uno::RuntimeException, std::exception)
     330             : {
     331             :     try
     332             :     {
     333          80 :         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
     334          80 :         xBroadcaster->removeModifyListener( aListener );
     335             :     }
     336           0 :     catch( const uno::Exception & ex )
     337             :     {
     338             :         ASSERT_EXCEPTION( ex );
     339             :     }
     340          80 : }
     341             : 
     342             : // ____ XModifyListener ____
     343           0 : void SAL_CALL Title::modified( const lang::EventObject& aEvent )
     344             :     throw (uno::RuntimeException, std::exception)
     345             : {
     346           0 :     m_xModifyEventForwarder->modified( aEvent );
     347           0 : }
     348             : 
     349             : // ____ XEventListener (base of XModifyListener) ____
     350           0 : void SAL_CALL Title::disposing( const lang::EventObject& /* Source */ )
     351             :     throw (uno::RuntimeException, std::exception)
     352             : {
     353             :     // nothing
     354           0 : }
     355             : 
     356             : // ____ OPropertySet ____
     357         499 : void Title::firePropertyChangeEvent()
     358             : {
     359         499 :     fireModifyEvent();
     360         499 : }
     361             : 
     362         764 : void Title::fireModifyEvent()
     363             : {
     364         764 :     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
     365         764 : }
     366             : 
     367           1 : uno::Sequence< OUString > Title::getSupportedServiceNames_Static()
     368             : {
     369           1 :     uno::Sequence< OUString > aServices( 4 );
     370           1 :     aServices[ 0 ] = "com.sun.star.chart2.Title";
     371           1 :     aServices[ 1 ] = "com.sun.star.style.ParagraphProperties";
     372           1 :     aServices[ 2 ] = "com.sun.star.beans.PropertySet";
     373           1 :     aServices[ 3 ] = "com.sun.star.layout.LayoutElement";
     374           1 :     return aServices;
     375             : }
     376             : 
     377             : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
     378           1 : OUString SAL_CALL Title::getImplementationName()
     379             :     throw( css::uno::RuntimeException, std::exception )
     380             : {
     381           1 :     return getImplementationName_Static();
     382             : }
     383             : 
     384           1 : OUString Title::getImplementationName_Static()
     385             : {
     386           1 :     return OUString(lcl_aServiceName);
     387             : }
     388             : 
     389           0 : sal_Bool SAL_CALL Title::supportsService( const OUString& rServiceName )
     390             :     throw( css::uno::RuntimeException, std::exception )
     391             : {
     392           0 :     return cppu::supportsService(this, rServiceName);
     393             : }
     394             : 
     395           1 : css::uno::Sequence< OUString > SAL_CALL Title::getSupportedServiceNames()
     396             :     throw( css::uno::RuntimeException, std::exception )
     397             : {
     398           1 :     return getSupportedServiceNames_Static();
     399             : }
     400             : 
     401             : // needed by MSC compiler
     402             : using impl::Title_Base;
     403             : 
     404      276582 : IMPLEMENT_FORWARD_XINTERFACE2( Title, Title_Base, ::property::OPropertySet )
     405           0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( Title, Title_Base, ::property::OPropertySet )
     406             : 
     407             : } //  namespace chart
     408             : 
     409             : extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
     410         215 : com_sun_star_comp_chart2_Title_get_implementation(css::uno::XComponentContext *context,
     411             :         css::uno::Sequence<css::uno::Any> const &)
     412             : {
     413         215 :     return cppu::acquire(new ::chart::Title(context));
     414             : }
     415             : 
     416             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11