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

Generated by: LCOV version 1.10