LCOV - code coverage report
Current view: top level - libreoffice/chart2/source/controller/itemsetwrapper - TitleItemConverter.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 67 0.0 %
Date: 2012-12-27 Functions: 0 14 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 "TitleItemConverter.hxx"
      21             : #include "SchWhichPairs.hxx"
      22             : #include "macros.hxx"
      23             : #include "ItemPropertyMap.hxx"
      24             : #include "GraphicPropertyItemConverter.hxx"
      25             : #include "CharacterPropertyItemConverter.hxx"
      26             : #include "MultipleItemConverter.hxx"
      27             : #include <svl/intitem.hxx>
      28             : #include <rtl/math.hxx>
      29             : 
      30             : #include <com/sun/star/chart2/XTitled.hpp>
      31             : 
      32             : #include <functional>
      33             : #include <algorithm>
      34             : 
      35             : using namespace ::com::sun::star;
      36             : 
      37             : namespace
      38             : {
      39           0 : ::comphelper::ItemPropertyMapType & lcl_GetTitlePropertyMap()
      40             : {
      41             :     static ::comphelper::ItemPropertyMapType aTitlePropertyMap(
      42             :         ::comphelper::MakeItemPropertyMap
      43             :         IPM_MAP_ENTRY( SCHATTR_TEXT_STACKED, "StackCharacters", 0 )
      44           0 :         );
      45             : 
      46           0 :     return aTitlePropertyMap;
      47             : };
      48             : } // anonymous namespace
      49             : 
      50             : namespace chart
      51             : {
      52             : namespace wrapper
      53             : {
      54             : 
      55             : // ========================================
      56             : 
      57             : class FormattedStringsConverter : public ::comphelper::MultipleItemConverter
      58             : {
      59             : public:
      60             :     SAL_WNODEPRECATED_DECLARATIONS_PUSH
      61             :     FormattedStringsConverter(
      62             :         const uno::Sequence< uno::Reference< chart2::XFormattedString > > & aStrings,
      63             :         SfxItemPool & rItemPool,
      64             :         ::std::auto_ptr< awt::Size > pRefSize,
      65             :         const uno::Reference< beans::XPropertySet > & xParentProp );
      66             :     SAL_WNODEPRECATED_DECLARATIONS_POP
      67             :     virtual ~FormattedStringsConverter();
      68             : 
      69             : protected:
      70             :     virtual const sal_uInt16 * GetWhichPairs() const;
      71             : };
      72             : 
      73             : // ----------------------------------------
      74             : 
      75             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
      76           0 : FormattedStringsConverter::FormattedStringsConverter(
      77             :     const uno::Sequence< uno::Reference< chart2::XFormattedString > > & aStrings,
      78             :     SfxItemPool & rItemPool,
      79             :     ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize,
      80             :     const uno::Reference< beans::XPropertySet > & xParentProp ) :
      81           0 :         MultipleItemConverter( rItemPool )
      82             : {
      83           0 :     bool bHasRefSize = (pRefSize.get() && xParentProp.is());
      84           0 :     for( sal_Int32 i = 0; i < aStrings.getLength(); ++i )
      85             :     {
      86           0 :         uno::Reference< beans::XPropertySet > xProp( aStrings[ i ], uno::UNO_QUERY );
      87           0 :         if( xProp.is())
      88             :         {
      89           0 :             if( bHasRefSize )
      90             :                 m_aConverters.push_back( new CharacterPropertyItemConverter(
      91             :                                              xProp, rItemPool,
      92             :                                              ::std::auto_ptr< awt::Size >( new awt::Size( *pRefSize )),
      93             :                                              "ReferencePageSize" ,
      94           0 :                                              xParentProp ));
      95             :             else
      96           0 :                 m_aConverters.push_back( new CharacterPropertyItemConverter( xProp, rItemPool ));
      97             :         }
      98           0 :     }
      99           0 : }
     100             : SAL_WNODEPRECATED_DECLARATIONS_POP
     101             : 
     102           0 : FormattedStringsConverter::~FormattedStringsConverter()
     103             : {
     104           0 : }
     105             : 
     106           0 : const sal_uInt16 * FormattedStringsConverter::GetWhichPairs() const
     107             : {
     108           0 :     return nCharacterPropertyWhichPairs;
     109             : }
     110             : 
     111             : // ========================================
     112             : 
     113             : SAL_WNODEPRECATED_DECLARATIONS_PUSH
     114           0 : TitleItemConverter::TitleItemConverter(
     115             :     const ::com::sun::star::uno::Reference<
     116             :     ::com::sun::star::beans::XPropertySet > & rPropertySet,
     117             :     SfxItemPool& rItemPool,
     118             :     SdrModel& rDrawModel,
     119             :     const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
     120             :     ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize ) :
     121           0 :         ItemConverter( rPropertySet, rItemPool )
     122             : {
     123             :     m_aConverters.push_back( new GraphicPropertyItemConverter(
     124             :                                  rPropertySet, rItemPool, rDrawModel,
     125             :                                  xNamedPropertyContainerFactory,
     126           0 :                                  GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES ));
     127             : 
     128             :     // CharacterProperties are not at the title but at its contained XFormattedString objects
     129             :     // take the first formatted string in the sequence
     130           0 :     uno::Reference< chart2::XTitle > xTitle( rPropertySet, uno::UNO_QUERY );
     131           0 :     if( xTitle.is())
     132             :     {
     133           0 :         uno::Sequence< uno::Reference< chart2::XFormattedString > > aStringSeq( xTitle->getText());
     134           0 :         if( aStringSeq.getLength() > 0 )
     135             :         {
     136             :             m_aConverters.push_back(
     137           0 :                 new FormattedStringsConverter( aStringSeq, rItemPool, pRefSize, rPropertySet ));
     138           0 :         }
     139           0 :     }
     140           0 : }
     141             : SAL_WNODEPRECATED_DECLARATIONS_POP
     142             : 
     143           0 : TitleItemConverter::~TitleItemConverter()
     144             : {
     145             :     ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
     146           0 :                      ::comphelper::DeleteItemConverterPtr() );
     147           0 : }
     148             : 
     149           0 : void TitleItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
     150             : {
     151             :     ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
     152           0 :                      ::comphelper::FillItemSetFunc( rOutItemSet ));
     153             : 
     154             :     // own items
     155           0 :     ItemConverter::FillItemSet( rOutItemSet );
     156           0 : }
     157             : 
     158           0 : bool TitleItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
     159             : {
     160           0 :     bool bResult = false;
     161             : 
     162             :     ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
     163           0 :                      ::comphelper::ApplyItemSetFunc( rItemSet, bResult ));
     164             : 
     165             :     // own items
     166           0 :     return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
     167             : }
     168             : 
     169           0 : const sal_uInt16 * TitleItemConverter::GetWhichPairs() const
     170             : {
     171             :     // must span all used items!
     172           0 :     return nTitleWhichPairs;
     173             : }
     174             : 
     175           0 : bool TitleItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
     176             : {
     177           0 :     ::comphelper::ItemPropertyMapType & rMap( lcl_GetTitlePropertyMap());
     178           0 :     ::comphelper::ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
     179             : 
     180           0 :     if( aIt == rMap.end())
     181           0 :         return false;
     182             : 
     183           0 :     rOutProperty =(*aIt).second;
     184           0 :     return true;
     185             : }
     186             : 
     187             : 
     188           0 : bool TitleItemConverter::ApplySpecialItem(
     189             :     sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
     190             :     throw( uno::Exception )
     191             : {
     192           0 :     bool bChanged = false;
     193             : 
     194           0 :     switch( nWhichId )
     195             :     {
     196             :         case SCHATTR_TEXT_DEGREES:
     197             :         {
     198             :             // convert int to double (divided by 100)
     199             :             double fVal = static_cast< double >(
     200             :                 static_cast< const SfxInt32Item & >(
     201           0 :                     rItemSet.Get( nWhichId )).GetValue()) / 100.0;
     202           0 :             double fOldVal = 0.0;
     203             :             bool bPropExisted =
     204           0 :                 ( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fOldVal );
     205             : 
     206           0 :             if( ! bPropExisted ||
     207             :                 ( bPropExisted && fOldVal != fVal ))
     208             :             {
     209           0 :                 GetPropertySet()->setPropertyValue( "TextRotation" , uno::makeAny( fVal ));
     210           0 :                 bChanged = true;
     211             :             }
     212             :         }
     213           0 :         break;
     214             :     }
     215             : 
     216           0 :     return bChanged;
     217             : }
     218             : 
     219           0 : void TitleItemConverter::FillSpecialItem(
     220             :     sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
     221             :     throw( uno::Exception )
     222             : {
     223           0 :     switch( nWhichId )
     224             :     {
     225             :         case SCHATTR_TEXT_DEGREES:
     226             :         {
     227             :             // convert double to int (times 100)
     228           0 :             double fVal = 0;
     229             : 
     230           0 :             if( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fVal )
     231             :             {
     232             :                 rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast< sal_Int32 >(
     233           0 :                                                    ::rtl::math::round( fVal * 100.0 ) ) ));
     234             :             }
     235             :         }
     236           0 :         break;
     237             :    }
     238           0 : }
     239             : 
     240             : } //  namespace wrapper
     241             : } //  namespace chart
     242             : 
     243             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10