1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_chart2.hxx" 30*cdf0e10cSrcweir #include "TitleItemConverter.hxx" 31*cdf0e10cSrcweir #include "SchWhichPairs.hxx" 32*cdf0e10cSrcweir #include "macros.hxx" 33*cdf0e10cSrcweir #include "ItemPropertyMap.hxx" 34*cdf0e10cSrcweir #include "GraphicPropertyItemConverter.hxx" 35*cdf0e10cSrcweir #include "CharacterPropertyItemConverter.hxx" 36*cdf0e10cSrcweir #include "MultipleItemConverter.hxx" 37*cdf0e10cSrcweir #include <svl/intitem.hxx> 38*cdf0e10cSrcweir #include <rtl/math.hxx> 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #include <com/sun/star/chart2/XTitled.hpp> 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir #include <functional> 43*cdf0e10cSrcweir #include <algorithm> 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir using namespace ::com::sun::star; 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir namespace 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir ::comphelper::ItemPropertyMapType & lcl_GetTitlePropertyMap() 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir static ::comphelper::ItemPropertyMapType aTitlePropertyMap( 52*cdf0e10cSrcweir ::comphelper::MakeItemPropertyMap 53*cdf0e10cSrcweir IPM_MAP_ENTRY( SCHATTR_TEXT_STACKED, "StackCharacters", 0 ) 54*cdf0e10cSrcweir ); 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir return aTitlePropertyMap; 57*cdf0e10cSrcweir }; 58*cdf0e10cSrcweir } // anonymous namespace 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir namespace chart 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir namespace wrapper 63*cdf0e10cSrcweir { 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir // ======================================== 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir class FormattedStringsConverter : public ::comphelper::MultipleItemConverter 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir public: 70*cdf0e10cSrcweir FormattedStringsConverter( 71*cdf0e10cSrcweir const uno::Sequence< uno::Reference< chart2::XFormattedString > > & aStrings, 72*cdf0e10cSrcweir SfxItemPool & rItemPool, 73*cdf0e10cSrcweir ::std::auto_ptr< awt::Size > pRefSize, 74*cdf0e10cSrcweir const uno::Reference< beans::XPropertySet > & xParentProp ); 75*cdf0e10cSrcweir virtual ~FormattedStringsConverter(); 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir protected: 78*cdf0e10cSrcweir virtual const sal_uInt16 * GetWhichPairs() const; 79*cdf0e10cSrcweir }; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir // ---------------------------------------- 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir FormattedStringsConverter::FormattedStringsConverter( 84*cdf0e10cSrcweir const uno::Sequence< uno::Reference< chart2::XFormattedString > > & aStrings, 85*cdf0e10cSrcweir SfxItemPool & rItemPool, 86*cdf0e10cSrcweir ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize, 87*cdf0e10cSrcweir const uno::Reference< beans::XPropertySet > & xParentProp ) : 88*cdf0e10cSrcweir MultipleItemConverter( rItemPool ) 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir bool bHasRefSize = (pRefSize.get() && xParentProp.is()); 91*cdf0e10cSrcweir for( sal_Int32 i = 0; i < aStrings.getLength(); ++i ) 92*cdf0e10cSrcweir { 93*cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( aStrings[ i ], uno::UNO_QUERY ); 94*cdf0e10cSrcweir if( xProp.is()) 95*cdf0e10cSrcweir { 96*cdf0e10cSrcweir if( bHasRefSize ) 97*cdf0e10cSrcweir m_aConverters.push_back( new CharacterPropertyItemConverter( 98*cdf0e10cSrcweir xProp, rItemPool, 99*cdf0e10cSrcweir ::std::auto_ptr< awt::Size >( new awt::Size( *pRefSize )), 100*cdf0e10cSrcweir C2U( "ReferencePageSize" ), 101*cdf0e10cSrcweir xParentProp )); 102*cdf0e10cSrcweir else 103*cdf0e10cSrcweir m_aConverters.push_back( new CharacterPropertyItemConverter( xProp, rItemPool )); 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir FormattedStringsConverter::~FormattedStringsConverter() 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir } 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir const sal_uInt16 * FormattedStringsConverter::GetWhichPairs() const 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir return nCharacterPropertyWhichPairs; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir // ======================================== 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir TitleItemConverter::TitleItemConverter( 120*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 121*cdf0e10cSrcweir ::com::sun::star::beans::XPropertySet > & rPropertySet, 122*cdf0e10cSrcweir SfxItemPool& rItemPool, 123*cdf0e10cSrcweir SdrModel& rDrawModel, 124*cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory, 125*cdf0e10cSrcweir ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize ) : 126*cdf0e10cSrcweir ItemConverter( rPropertySet, rItemPool ) 127*cdf0e10cSrcweir { 128*cdf0e10cSrcweir m_aConverters.push_back( new GraphicPropertyItemConverter( 129*cdf0e10cSrcweir rPropertySet, rItemPool, rDrawModel, 130*cdf0e10cSrcweir xNamedPropertyContainerFactory, 131*cdf0e10cSrcweir GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES )); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir // CharacterProperties are not at the title but at its contained XFormattedString objects 134*cdf0e10cSrcweir // take the first formatted string in the sequence 135*cdf0e10cSrcweir uno::Reference< chart2::XTitle > xTitle( rPropertySet, uno::UNO_QUERY ); 136*cdf0e10cSrcweir if( xTitle.is()) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::XFormattedString > > aStringSeq( xTitle->getText()); 139*cdf0e10cSrcweir if( aStringSeq.getLength() > 0 ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir m_aConverters.push_back( 142*cdf0e10cSrcweir new FormattedStringsConverter( aStringSeq, rItemPool, pRefSize, rPropertySet )); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir TitleItemConverter::~TitleItemConverter() 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir ::std::for_each( m_aConverters.begin(), m_aConverters.end(), 150*cdf0e10cSrcweir ::comphelper::DeleteItemConverterPtr() ); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir void TitleItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir ::std::for_each( m_aConverters.begin(), m_aConverters.end(), 156*cdf0e10cSrcweir ::comphelper::FillItemSetFunc( rOutItemSet )); 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir // own items 159*cdf0e10cSrcweir ItemConverter::FillItemSet( rOutItemSet ); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir bool TitleItemConverter::ApplyItemSet( const SfxItemSet & rItemSet ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir bool bResult = false; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir ::std::for_each( m_aConverters.begin(), m_aConverters.end(), 167*cdf0e10cSrcweir ::comphelper::ApplyItemSetFunc( rItemSet, bResult )); 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir // own items 170*cdf0e10cSrcweir return ItemConverter::ApplyItemSet( rItemSet ) || bResult; 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir const sal_uInt16 * TitleItemConverter::GetWhichPairs() const 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir // must span all used items! 176*cdf0e10cSrcweir return nTitleWhichPairs; 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir bool TitleItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir ::comphelper::ItemPropertyMapType & rMap( lcl_GetTitlePropertyMap()); 182*cdf0e10cSrcweir ::comphelper::ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId )); 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir if( aIt == rMap.end()) 185*cdf0e10cSrcweir return false; 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir rOutProperty =(*aIt).second; 188*cdf0e10cSrcweir return true; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir bool TitleItemConverter::ApplySpecialItem( 193*cdf0e10cSrcweir sal_uInt16 nWhichId, const SfxItemSet & rItemSet ) 194*cdf0e10cSrcweir throw( uno::Exception ) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir bool bChanged = false; 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir switch( nWhichId ) 199*cdf0e10cSrcweir { 200*cdf0e10cSrcweir case SCHATTR_TEXT_DEGREES: 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir // convert int to double (divided by 100) 203*cdf0e10cSrcweir double fVal = static_cast< double >( 204*cdf0e10cSrcweir static_cast< const SfxInt32Item & >( 205*cdf0e10cSrcweir rItemSet.Get( nWhichId )).GetValue()) / 100.0; 206*cdf0e10cSrcweir double fOldVal = 0.0; 207*cdf0e10cSrcweir bool bPropExisted = 208*cdf0e10cSrcweir ( GetPropertySet()->getPropertyValue( C2U( "TextRotation" )) >>= fOldVal ); 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir if( ! bPropExisted || 211*cdf0e10cSrcweir ( bPropExisted && fOldVal != fVal )) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir GetPropertySet()->setPropertyValue( C2U( "TextRotation" ), uno::makeAny( fVal )); 214*cdf0e10cSrcweir bChanged = true; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir break; 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir return bChanged; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir void TitleItemConverter::FillSpecialItem( 224*cdf0e10cSrcweir sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const 225*cdf0e10cSrcweir throw( uno::Exception ) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir switch( nWhichId ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir case SCHATTR_TEXT_DEGREES: 230*cdf0e10cSrcweir { 231*cdf0e10cSrcweir // convert double to int (times 100) 232*cdf0e10cSrcweir double fVal = 0; 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir if( GetPropertySet()->getPropertyValue( C2U( "TextRotation" )) >>= fVal ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast< sal_Int32 >( 237*cdf0e10cSrcweir ::rtl::math::round( fVal * 100.0 ) ) )); 238*cdf0e10cSrcweir } 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir break; 241*cdf0e10cSrcweir } 242*cdf0e10cSrcweir } 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir } // namespace wrapper 245*cdf0e10cSrcweir } // namespace chart 246