1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "TitleItemConverter.hxx"
21 #include "SchWhichPairs.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>
30 #include <com/sun/star/chart2/XTitled.hpp>
35 #include <boost/checked_delete.hpp>
37 using namespace ::com::sun::star
;
39 namespace chart
{ namespace wrapper
{
43 ItemPropertyMapType
& lcl_GetTitlePropertyMap()
45 static ItemPropertyMapType
aTitlePropertyMap(
47 IPM_MAP_ENTRY( SCHATTR_TEXT_STACKED
, "StackCharacters", 0 )
50 return aTitlePropertyMap
;
53 } // anonymous namespace
55 class FormattedStringsConverter
: public MultipleItemConverter
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();
66 virtual const sal_uInt16
* GetWhichPairs() const SAL_OVERRIDE
;
69 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 MultipleItemConverter( rItemPool
)
76 bool bHasRefSize
= (pRefSize
&& xParentProp
.is());
77 for( sal_Int32 i
= 0; i
< aStrings
.getLength(); ++i
)
79 uno::Reference
< beans::XPropertySet
> xProp( aStrings
[ i
], uno::UNO_QUERY
);
83 m_aConverters
.push_back(
84 new CharacterPropertyItemConverter(
85 xProp
, rItemPool
, pRefSize
, "ReferencePageSize", xParentProp
));
87 m_aConverters
.push_back( new CharacterPropertyItemConverter( xProp
, rItemPool
));
92 FormattedStringsConverter::~FormattedStringsConverter()
96 const sal_uInt16
* FormattedStringsConverter::GetWhichPairs() const
98 return nCharacterPropertyWhichPairs
;
101 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 ItemConverter( rPropertySet
, rItemPool
)
109 m_aConverters
.push_back( new GraphicPropertyItemConverter(
110 rPropertySet
, rItemPool
, rDrawModel
,
111 xNamedPropertyContainerFactory
,
112 GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES
));
114 // CharacterProperties are not at the title but at its contained XFormattedString objects
115 // take the first formatted string in the sequence
116 uno::Reference
< chart2::XTitle
> xTitle( rPropertySet
, uno::UNO_QUERY
);
119 uno::Sequence
< uno::Reference
< chart2::XFormattedString
> > aStringSeq( xTitle
->getText());
120 if( aStringSeq
.getLength() > 0 )
122 m_aConverters
.push_back(
123 new FormattedStringsConverter( aStringSeq
, rItemPool
, pRefSize
, rPropertySet
));
128 TitleItemConverter::~TitleItemConverter()
130 ::std::for_each(m_aConverters
.begin(), m_aConverters
.end(), boost::checked_deleter
<ItemConverter
>());
133 void TitleItemConverter::FillItemSet( SfxItemSet
& rOutItemSet
) const
135 ::std::for_each( m_aConverters
.begin(), m_aConverters
.end(),
136 FillItemSetFunc( rOutItemSet
));
139 ItemConverter::FillItemSet( rOutItemSet
);
142 bool TitleItemConverter::ApplyItemSet( const SfxItemSet
& rItemSet
)
144 bool bResult
= false;
146 ::std::for_each( m_aConverters
.begin(), m_aConverters
.end(),
147 ApplyItemSetFunc( rItemSet
, bResult
));
150 return ItemConverter::ApplyItemSet( rItemSet
) || bResult
;
153 const sal_uInt16
* TitleItemConverter::GetWhichPairs() const
155 // must span all used items!
156 return nTitleWhichPairs
;
159 bool TitleItemConverter::GetItemProperty( tWhichIdType nWhichId
, tPropertyNameWithMemberId
& rOutProperty
) const
161 ItemPropertyMapType
& rMap( lcl_GetTitlePropertyMap());
162 ItemPropertyMapType::const_iterator
aIt( rMap
.find( nWhichId
));
164 if( aIt
== rMap
.end())
167 rOutProperty
=(*aIt
).second
;
171 bool TitleItemConverter::ApplySpecialItem(
172 sal_uInt16 nWhichId
, const SfxItemSet
& rItemSet
)
173 throw( uno::Exception
)
175 bool bChanged
= false;
179 case SCHATTR_TEXT_DEGREES
:
181 // convert int to double (divided by 100)
182 double fVal
= static_cast< double >(
183 static_cast< const SfxInt32Item
& >(
184 rItemSet
.Get( nWhichId
)).GetValue()) / 100.0;
185 double fOldVal
= 0.0;
187 ( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fOldVal
);
189 if( ! bPropExisted
||
190 ( bPropExisted
&& fOldVal
!= fVal
))
192 GetPropertySet()->setPropertyValue( "TextRotation" , uno::makeAny( fVal
));
202 void TitleItemConverter::FillSpecialItem(
203 sal_uInt16 nWhichId
, SfxItemSet
& rOutItemSet
) const
204 throw( uno::Exception
)
208 case SCHATTR_TEXT_DEGREES
:
210 // convert double to int (times 100)
213 if( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fVal
)
215 rOutItemSet
.Put( SfxInt32Item( nWhichId
, static_cast< sal_Int32
>(
216 ::rtl::math::round( fVal
* 100.0 ) ) ));
223 } // namespace wrapper
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */