Update ooo320-m1
[ooovba.git] / chart2 / source / controller / itemsetwrapper / TitleItemConverter.cxx
blob6f35ce20d49a7dbe4a3d60011755e74bbf3b294e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TitleItemConverter.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "TitleItemConverter.hxx"
34 #include "SchWhichPairs.hxx"
35 #include "macros.hxx"
36 #include "ItemPropertyMap.hxx"
37 #include "GraphicPropertyItemConverter.hxx"
38 #include "CharacterPropertyItemConverter.hxx"
39 #include "MultipleItemConverter.hxx"
40 #include <svtools/intitem.hxx>
41 #include <rtl/math.hxx>
43 #include <com/sun/star/chart2/XTitled.hpp>
45 #include <functional>
46 #include <algorithm>
48 using namespace ::com::sun::star;
50 namespace
52 ::comphelper::ItemPropertyMapType & lcl_GetTitlePropertyMap()
54 static ::comphelper::ItemPropertyMapType aTitlePropertyMap(
55 ::comphelper::MakeItemPropertyMap
56 IPM_MAP_ENTRY( SCHATTR_TEXT_STACKED, "StackCharacters", 0 )
59 return aTitlePropertyMap;
61 } // anonymous namespace
63 namespace chart
65 namespace wrapper
68 // ========================================
70 class FormattedStringsConverter : public ::comphelper::MultipleItemConverter
72 public:
73 FormattedStringsConverter(
74 const uno::Sequence< uno::Reference< chart2::XFormattedString > > & aStrings,
75 SfxItemPool & rItemPool,
76 ::std::auto_ptr< awt::Size > pRefSize,
77 const uno::Reference< beans::XPropertySet > & xParentProp );
78 virtual ~FormattedStringsConverter();
80 protected:
81 virtual const USHORT * GetWhichPairs() const;
84 // ----------------------------------------
86 FormattedStringsConverter::FormattedStringsConverter(
87 const uno::Sequence< uno::Reference< chart2::XFormattedString > > & aStrings,
88 SfxItemPool & rItemPool,
89 ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize,
90 const uno::Reference< beans::XPropertySet > & xParentProp ) :
91 MultipleItemConverter( rItemPool )
93 bool bHasRefSize = (pRefSize.get() && xParentProp.is());
94 for( sal_Int32 i = 0; i < aStrings.getLength(); ++i )
96 uno::Reference< beans::XPropertySet > xProp( aStrings[ i ], uno::UNO_QUERY );
97 if( xProp.is())
99 if( bHasRefSize )
100 m_aConverters.push_back( new CharacterPropertyItemConverter(
101 xProp, rItemPool,
102 ::std::auto_ptr< awt::Size >( new awt::Size( *pRefSize )),
103 C2U( "ReferencePageSize" ),
104 xParentProp ));
105 else
106 m_aConverters.push_back( new CharacterPropertyItemConverter( xProp, rItemPool ));
111 FormattedStringsConverter::~FormattedStringsConverter()
115 const USHORT * FormattedStringsConverter::GetWhichPairs() const
117 return nCharacterPropertyWhichPairs;
120 // ========================================
122 TitleItemConverter::TitleItemConverter(
123 const ::com::sun::star::uno::Reference<
124 ::com::sun::star::beans::XPropertySet > & rPropertySet,
125 SfxItemPool& rItemPool,
126 SdrModel& rDrawModel,
127 const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
128 ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize ) :
129 ItemConverter( rPropertySet, rItemPool )
131 m_aConverters.push_back( new GraphicPropertyItemConverter(
132 rPropertySet, rItemPool, rDrawModel,
133 xNamedPropertyContainerFactory,
134 GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES ));
136 // CharacterProperties are not at the title but at its contained XFormattedString objects
137 // take the first formatted string in the sequence
138 uno::Reference< chart2::XTitle > xTitle( rPropertySet, uno::UNO_QUERY );
139 if( xTitle.is())
141 uno::Sequence< uno::Reference< chart2::XFormattedString > > aStringSeq( xTitle->getText());
142 if( aStringSeq.getLength() > 0 )
144 m_aConverters.push_back(
145 new FormattedStringsConverter( aStringSeq, rItemPool, pRefSize, rPropertySet ));
150 TitleItemConverter::~TitleItemConverter()
152 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
153 ::comphelper::DeleteItemConverterPtr() );
156 void TitleItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
158 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
159 ::comphelper::FillItemSetFunc( rOutItemSet ));
161 // own items
162 ItemConverter::FillItemSet( rOutItemSet );
165 bool TitleItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
167 bool bResult = false;
169 ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
170 ::comphelper::ApplyItemSetFunc( rItemSet, bResult ));
172 // own items
173 return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
176 const USHORT * TitleItemConverter::GetWhichPairs() const
178 // must span all used items!
179 return nTitleWhichPairs;
182 bool TitleItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
184 ::comphelper::ItemPropertyMapType & rMap( lcl_GetTitlePropertyMap());
185 ::comphelper::ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
187 if( aIt == rMap.end())
188 return false;
190 rOutProperty =(*aIt).second;
191 return true;
195 bool TitleItemConverter::ApplySpecialItem(
196 USHORT nWhichId, const SfxItemSet & rItemSet )
197 throw( uno::Exception )
199 bool bChanged = false;
201 switch( nWhichId )
203 case SCHATTR_TEXT_DEGREES:
205 // convert int to double (divided by 100)
206 double fVal = static_cast< double >(
207 static_cast< const SfxInt32Item & >(
208 rItemSet.Get( nWhichId )).GetValue()) / 100.0;
209 double fOldVal = 0.0;
210 bool bPropExisted =
211 ( GetPropertySet()->getPropertyValue( C2U( "TextRotation" )) >>= fOldVal );
213 if( ! bPropExisted ||
214 ( bPropExisted && fOldVal != fVal ))
216 GetPropertySet()->setPropertyValue( C2U( "TextRotation" ), uno::makeAny( fVal ));
217 bChanged = true;
220 break;
223 return bChanged;
226 void TitleItemConverter::FillSpecialItem(
227 USHORT nWhichId, SfxItemSet & rOutItemSet ) const
228 throw( uno::Exception )
230 switch( nWhichId )
232 case SCHATTR_TEXT_DEGREES:
234 // convert double to int (times 100)
235 double fVal = 0;
237 if( GetPropertySet()->getPropertyValue( C2U( "TextRotation" )) >>= fVal )
239 rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast< sal_Int32 >(
240 ::rtl::math::round( fVal * 100.0 ) ) ));
243 break;
247 } // namespace wrapper
248 } // namespace chart