1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*cde9e8dcSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*cde9e8dcSAndrew Rist * distributed with this work for additional information
6*cde9e8dcSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*cde9e8dcSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*cde9e8dcSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist * KIND, either express or implied. See the License for the
17*cde9e8dcSAndrew Rist * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*cde9e8dcSAndrew Rist *************************************************************/
21*cde9e8dcSAndrew Rist
22*cde9e8dcSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir #include "TitleItemConverter.hxx"
27cdf0e10cSrcweir #include "SchWhichPairs.hxx"
28cdf0e10cSrcweir #include "macros.hxx"
29cdf0e10cSrcweir #include "ItemPropertyMap.hxx"
30cdf0e10cSrcweir #include "GraphicPropertyItemConverter.hxx"
31cdf0e10cSrcweir #include "CharacterPropertyItemConverter.hxx"
32cdf0e10cSrcweir #include "MultipleItemConverter.hxx"
33cdf0e10cSrcweir #include <svl/intitem.hxx>
34cdf0e10cSrcweir #include <rtl/math.hxx>
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include <com/sun/star/chart2/XTitled.hpp>
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include <functional>
39cdf0e10cSrcweir #include <algorithm>
40cdf0e10cSrcweir
41cdf0e10cSrcweir using namespace ::com::sun::star;
42cdf0e10cSrcweir
43cdf0e10cSrcweir namespace
44cdf0e10cSrcweir {
lcl_GetTitlePropertyMap()45cdf0e10cSrcweir ::comphelper::ItemPropertyMapType & lcl_GetTitlePropertyMap()
46cdf0e10cSrcweir {
47cdf0e10cSrcweir static ::comphelper::ItemPropertyMapType aTitlePropertyMap(
48cdf0e10cSrcweir ::comphelper::MakeItemPropertyMap
49cdf0e10cSrcweir IPM_MAP_ENTRY( SCHATTR_TEXT_STACKED, "StackCharacters", 0 )
50cdf0e10cSrcweir );
51cdf0e10cSrcweir
52cdf0e10cSrcweir return aTitlePropertyMap;
53cdf0e10cSrcweir };
54cdf0e10cSrcweir } // anonymous namespace
55cdf0e10cSrcweir
56cdf0e10cSrcweir namespace chart
57cdf0e10cSrcweir {
58cdf0e10cSrcweir namespace wrapper
59cdf0e10cSrcweir {
60cdf0e10cSrcweir
61cdf0e10cSrcweir // ========================================
62cdf0e10cSrcweir
63cdf0e10cSrcweir class FormattedStringsConverter : public ::comphelper::MultipleItemConverter
64cdf0e10cSrcweir {
65cdf0e10cSrcweir public:
66cdf0e10cSrcweir FormattedStringsConverter(
67cdf0e10cSrcweir const uno::Sequence< uno::Reference< chart2::XFormattedString > > & aStrings,
68cdf0e10cSrcweir SfxItemPool & rItemPool,
69cdf0e10cSrcweir ::std::auto_ptr< awt::Size > pRefSize,
70cdf0e10cSrcweir const uno::Reference< beans::XPropertySet > & xParentProp );
71cdf0e10cSrcweir virtual ~FormattedStringsConverter();
72cdf0e10cSrcweir
73cdf0e10cSrcweir protected:
74cdf0e10cSrcweir virtual const sal_uInt16 * GetWhichPairs() const;
75cdf0e10cSrcweir };
76cdf0e10cSrcweir
77cdf0e10cSrcweir // ----------------------------------------
78cdf0e10cSrcweir
FormattedStringsConverter(const uno::Sequence<uno::Reference<chart2::XFormattedString>> & aStrings,SfxItemPool & rItemPool,::std::auto_ptr<::com::sun::star::awt::Size> pRefSize,const uno::Reference<beans::XPropertySet> & xParentProp)79cdf0e10cSrcweir FormattedStringsConverter::FormattedStringsConverter(
80cdf0e10cSrcweir const uno::Sequence< uno::Reference< chart2::XFormattedString > > & aStrings,
81cdf0e10cSrcweir SfxItemPool & rItemPool,
82cdf0e10cSrcweir ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize,
83cdf0e10cSrcweir const uno::Reference< beans::XPropertySet > & xParentProp ) :
84cdf0e10cSrcweir MultipleItemConverter( rItemPool )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir bool bHasRefSize = (pRefSize.get() && xParentProp.is());
87cdf0e10cSrcweir for( sal_Int32 i = 0; i < aStrings.getLength(); ++i )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir uno::Reference< beans::XPropertySet > xProp( aStrings[ i ], uno::UNO_QUERY );
90cdf0e10cSrcweir if( xProp.is())
91cdf0e10cSrcweir {
92cdf0e10cSrcweir if( bHasRefSize )
93cdf0e10cSrcweir m_aConverters.push_back( new CharacterPropertyItemConverter(
94cdf0e10cSrcweir xProp, rItemPool,
95cdf0e10cSrcweir ::std::auto_ptr< awt::Size >( new awt::Size( *pRefSize )),
96cdf0e10cSrcweir C2U( "ReferencePageSize" ),
97cdf0e10cSrcweir xParentProp ));
98cdf0e10cSrcweir else
99cdf0e10cSrcweir m_aConverters.push_back( new CharacterPropertyItemConverter( xProp, rItemPool ));
100cdf0e10cSrcweir }
101cdf0e10cSrcweir }
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
~FormattedStringsConverter()104cdf0e10cSrcweir FormattedStringsConverter::~FormattedStringsConverter()
105cdf0e10cSrcweir {
106cdf0e10cSrcweir }
107cdf0e10cSrcweir
GetWhichPairs() const108cdf0e10cSrcweir const sal_uInt16 * FormattedStringsConverter::GetWhichPairs() const
109cdf0e10cSrcweir {
110cdf0e10cSrcweir return nCharacterPropertyWhichPairs;
111cdf0e10cSrcweir }
112cdf0e10cSrcweir
113cdf0e10cSrcweir // ========================================
114cdf0e10cSrcweir
TitleItemConverter(const::com::sun::star::uno::Reference<::com::sun::star::beans::XPropertySet> & rPropertySet,SfxItemPool & rItemPool,SdrModel & rDrawModel,const uno::Reference<lang::XMultiServiceFactory> & xNamedPropertyContainerFactory,::std::auto_ptr<::com::sun::star::awt::Size> pRefSize)115cdf0e10cSrcweir TitleItemConverter::TitleItemConverter(
116cdf0e10cSrcweir const ::com::sun::star::uno::Reference<
117cdf0e10cSrcweir ::com::sun::star::beans::XPropertySet > & rPropertySet,
118cdf0e10cSrcweir SfxItemPool& rItemPool,
119cdf0e10cSrcweir SdrModel& rDrawModel,
120cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
121cdf0e10cSrcweir ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize ) :
122cdf0e10cSrcweir ItemConverter( rPropertySet, rItemPool )
123cdf0e10cSrcweir {
124cdf0e10cSrcweir m_aConverters.push_back( new GraphicPropertyItemConverter(
125cdf0e10cSrcweir rPropertySet, rItemPool, rDrawModel,
126cdf0e10cSrcweir xNamedPropertyContainerFactory,
127cdf0e10cSrcweir GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES ));
128cdf0e10cSrcweir
129cdf0e10cSrcweir // CharacterProperties are not at the title but at its contained XFormattedString objects
130cdf0e10cSrcweir // take the first formatted string in the sequence
131cdf0e10cSrcweir uno::Reference< chart2::XTitle > xTitle( rPropertySet, uno::UNO_QUERY );
132cdf0e10cSrcweir if( xTitle.is())
133cdf0e10cSrcweir {
134cdf0e10cSrcweir uno::Sequence< uno::Reference< chart2::XFormattedString > > aStringSeq( xTitle->getText());
135cdf0e10cSrcweir if( aStringSeq.getLength() > 0 )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir m_aConverters.push_back(
138cdf0e10cSrcweir new FormattedStringsConverter( aStringSeq, rItemPool, pRefSize, rPropertySet ));
139cdf0e10cSrcweir }
140cdf0e10cSrcweir }
141cdf0e10cSrcweir }
142cdf0e10cSrcweir
~TitleItemConverter()143cdf0e10cSrcweir TitleItemConverter::~TitleItemConverter()
144cdf0e10cSrcweir {
145cdf0e10cSrcweir ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
146cdf0e10cSrcweir ::comphelper::DeleteItemConverterPtr() );
147cdf0e10cSrcweir }
148cdf0e10cSrcweir
FillItemSet(SfxItemSet & rOutItemSet) const149cdf0e10cSrcweir void TitleItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
150cdf0e10cSrcweir {
151cdf0e10cSrcweir ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
152cdf0e10cSrcweir ::comphelper::FillItemSetFunc( rOutItemSet ));
153cdf0e10cSrcweir
154cdf0e10cSrcweir // own items
155cdf0e10cSrcweir ItemConverter::FillItemSet( rOutItemSet );
156cdf0e10cSrcweir }
157cdf0e10cSrcweir
ApplyItemSet(const SfxItemSet & rItemSet)158cdf0e10cSrcweir bool TitleItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir bool bResult = false;
161cdf0e10cSrcweir
162cdf0e10cSrcweir ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
163cdf0e10cSrcweir ::comphelper::ApplyItemSetFunc( rItemSet, bResult ));
164cdf0e10cSrcweir
165cdf0e10cSrcweir // own items
166cdf0e10cSrcweir return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
167cdf0e10cSrcweir }
168cdf0e10cSrcweir
GetWhichPairs() const169cdf0e10cSrcweir const sal_uInt16 * TitleItemConverter::GetWhichPairs() const
170cdf0e10cSrcweir {
171cdf0e10cSrcweir // must span all used items!
172cdf0e10cSrcweir return nTitleWhichPairs;
173cdf0e10cSrcweir }
174cdf0e10cSrcweir
GetItemProperty(tWhichIdType nWhichId,tPropertyNameWithMemberId & rOutProperty) const175cdf0e10cSrcweir bool TitleItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
176cdf0e10cSrcweir {
177cdf0e10cSrcweir ::comphelper::ItemPropertyMapType & rMap( lcl_GetTitlePropertyMap());
178cdf0e10cSrcweir ::comphelper::ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
179cdf0e10cSrcweir
180cdf0e10cSrcweir if( aIt == rMap.end())
181cdf0e10cSrcweir return false;
182cdf0e10cSrcweir
183cdf0e10cSrcweir rOutProperty =(*aIt).second;
184cdf0e10cSrcweir return true;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir
187cdf0e10cSrcweir
ApplySpecialItem(sal_uInt16 nWhichId,const SfxItemSet & rItemSet)188cdf0e10cSrcweir bool TitleItemConverter::ApplySpecialItem(
189cdf0e10cSrcweir sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
190cdf0e10cSrcweir throw( uno::Exception )
191cdf0e10cSrcweir {
192cdf0e10cSrcweir bool bChanged = false;
193cdf0e10cSrcweir
194cdf0e10cSrcweir switch( nWhichId )
195cdf0e10cSrcweir {
196cdf0e10cSrcweir case SCHATTR_TEXT_DEGREES:
197cdf0e10cSrcweir {
198cdf0e10cSrcweir // convert int to double (divided by 100)
199cdf0e10cSrcweir double fVal = static_cast< double >(
200cdf0e10cSrcweir static_cast< const SfxInt32Item & >(
201cdf0e10cSrcweir rItemSet.Get( nWhichId )).GetValue()) / 100.0;
202cdf0e10cSrcweir double fOldVal = 0.0;
203cdf0e10cSrcweir bool bPropExisted =
204cdf0e10cSrcweir ( GetPropertySet()->getPropertyValue( C2U( "TextRotation" )) >>= fOldVal );
205cdf0e10cSrcweir
206cdf0e10cSrcweir if( ! bPropExisted ||
207cdf0e10cSrcweir ( bPropExisted && fOldVal != fVal ))
208cdf0e10cSrcweir {
209cdf0e10cSrcweir GetPropertySet()->setPropertyValue( C2U( "TextRotation" ), uno::makeAny( fVal ));
210cdf0e10cSrcweir bChanged = true;
211cdf0e10cSrcweir }
212cdf0e10cSrcweir }
213cdf0e10cSrcweir break;
214cdf0e10cSrcweir }
215cdf0e10cSrcweir
216cdf0e10cSrcweir return bChanged;
217cdf0e10cSrcweir }
218cdf0e10cSrcweir
FillSpecialItem(sal_uInt16 nWhichId,SfxItemSet & rOutItemSet) const219cdf0e10cSrcweir void TitleItemConverter::FillSpecialItem(
220cdf0e10cSrcweir sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
221cdf0e10cSrcweir throw( uno::Exception )
222cdf0e10cSrcweir {
223cdf0e10cSrcweir switch( nWhichId )
224cdf0e10cSrcweir {
225cdf0e10cSrcweir case SCHATTR_TEXT_DEGREES:
226cdf0e10cSrcweir {
227cdf0e10cSrcweir // convert double to int (times 100)
228cdf0e10cSrcweir double fVal = 0;
229cdf0e10cSrcweir
230cdf0e10cSrcweir if( GetPropertySet()->getPropertyValue( C2U( "TextRotation" )) >>= fVal )
231cdf0e10cSrcweir {
232cdf0e10cSrcweir rOutItemSet.Put( SfxInt32Item( nWhichId, static_cast< sal_Int32 >(
233cdf0e10cSrcweir ::rtl::math::round( fVal * 100.0 ) ) ));
234cdf0e10cSrcweir }
235cdf0e10cSrcweir }
236cdf0e10cSrcweir break;
237cdf0e10cSrcweir }
238cdf0e10cSrcweir }
239cdf0e10cSrcweir
240cdf0e10cSrcweir } // namespace wrapper
241cdf0e10cSrcweir } // namespace chart
242