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

Generated by: LCOV version 1.10