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

Generated by: LCOV version 1.10