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