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"
22 #include <ItemPropertyMap.hxx>
23 #include <GraphicPropertyItemConverter.hxx>
24 #include <CharacterPropertyItemConverter.hxx>
25 #include <MultipleItemConverter.hxx>
26 #include <svl/intitem.hxx>
27 #include <rtl/math.hxx>
29 #include <com/sun/star/chart2/XTitled.hpp>
35 using namespace ::com::sun::star
;
37 namespace chart
{ namespace wrapper
{
41 ItemPropertyMapType
& lcl_GetTitlePropertyMap()
43 static ItemPropertyMapType aTitlePropertyMap
{
44 {SCHATTR_TEXT_STACKED
, {"StackCharacters", 0}}};
45 return aTitlePropertyMap
;
48 } // anonymous namespace
50 class FormattedStringsConverter
: public MultipleItemConverter
53 FormattedStringsConverter(
54 const uno::Sequence
< uno::Reference
< chart2::XFormattedString
> > & aStrings
,
55 SfxItemPool
& rItemPool
,
56 const awt::Size
* pRefSize
,
57 const uno::Reference
< beans::XPropertySet
> & xParentProp
);
60 virtual const sal_uInt16
* GetWhichPairs() const override
;
63 FormattedStringsConverter::FormattedStringsConverter(
64 const uno::Sequence
< uno::Reference
< chart2::XFormattedString
> > & aStrings
,
65 SfxItemPool
& rItemPool
,
66 const awt::Size
* pRefSize
,
67 const uno::Reference
< beans::XPropertySet
> & xParentProp
) :
68 MultipleItemConverter( rItemPool
)
70 bool bHasRefSize
= (pRefSize
&& xParentProp
.is());
71 for( sal_Int32 i
= 0; i
< aStrings
.getLength(); ++i
)
73 uno::Reference
< beans::XPropertySet
> xProp( aStrings
[ i
], uno::UNO_QUERY
);
77 m_aConverters
.push_back(
78 new CharacterPropertyItemConverter(
79 xProp
, rItemPool
, pRefSize
, "ReferencePageSize", xParentProp
));
81 m_aConverters
.push_back( new CharacterPropertyItemConverter( xProp
, rItemPool
));
86 const sal_uInt16
* FormattedStringsConverter::GetWhichPairs() const
88 return nCharacterPropertyWhichPairs
;
91 TitleItemConverter::TitleItemConverter(
92 const uno::Reference
<beans::XPropertySet
> & rPropertySet
,
93 SfxItemPool
& rItemPool
,
95 const uno::Reference
< lang::XMultiServiceFactory
> & xNamedPropertyContainerFactory
,
96 const awt::Size
* pRefSize
) :
97 ItemConverter( rPropertySet
, rItemPool
)
99 m_aConverters
.push_back( new GraphicPropertyItemConverter(
100 rPropertySet
, rItemPool
, rDrawModel
,
101 xNamedPropertyContainerFactory
,
102 GraphicObjectType::LineAndFillProperties
));
104 // CharacterProperties are not at the title but at its contained XFormattedString objects
105 // take the first formatted string in the sequence
106 uno::Reference
< chart2::XTitle
> xTitle( rPropertySet
, uno::UNO_QUERY
);
109 uno::Sequence
< uno::Reference
< chart2::XFormattedString
> > aStringSeq( xTitle
->getText());
110 if( aStringSeq
.getLength() > 0 )
112 m_aConverters
.push_back(
113 new FormattedStringsConverter( aStringSeq
, rItemPool
, pRefSize
, rPropertySet
));
118 TitleItemConverter::~TitleItemConverter()
120 std::for_each(m_aConverters
.begin(), m_aConverters
.end(), std::default_delete
<ItemConverter
>());
123 void TitleItemConverter::FillItemSet( SfxItemSet
& rOutItemSet
) const
125 for( const auto& pConv
: m_aConverters
)
126 pConv
->FillItemSet( rOutItemSet
);
129 ItemConverter::FillItemSet( rOutItemSet
);
132 bool TitleItemConverter::ApplyItemSet( const SfxItemSet
& rItemSet
)
134 bool bResult
= false;
136 for( const auto& pConv
: m_aConverters
)
137 bResult
= pConv
->ApplyItemSet( rItemSet
) || bResult
;
140 return ItemConverter::ApplyItemSet( rItemSet
) || bResult
;
143 const sal_uInt16
* TitleItemConverter::GetWhichPairs() const
145 // must span all used items!
146 return nTitleWhichPairs
;
149 bool TitleItemConverter::GetItemProperty( tWhichIdType nWhichId
, tPropertyNameWithMemberId
& rOutProperty
) const
151 ItemPropertyMapType
& rMap( lcl_GetTitlePropertyMap());
152 ItemPropertyMapType::const_iterator
aIt( rMap
.find( nWhichId
));
154 if( aIt
== rMap
.end())
157 rOutProperty
=(*aIt
).second
;
161 bool TitleItemConverter::ApplySpecialItem(
162 sal_uInt16 nWhichId
, const SfxItemSet
& rItemSet
)
164 bool bChanged
= false;
168 case SCHATTR_TEXT_DEGREES
:
170 // convert int to double (divided by 100)
171 double fVal
= static_cast< double >(
172 static_cast< const SfxInt32Item
& >(
173 rItemSet
.Get( nWhichId
)).GetValue()) / 100.0;
174 double fOldVal
= 0.0;
176 ( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fOldVal
);
178 if( ! bPropExisted
|| fOldVal
!= fVal
)
180 GetPropertySet()->setPropertyValue( "TextRotation" , uno::Any( fVal
));
190 void TitleItemConverter::FillSpecialItem(
191 sal_uInt16 nWhichId
, SfxItemSet
& rOutItemSet
) const
195 case SCHATTR_TEXT_DEGREES
:
197 // convert double to int (times 100)
200 if( GetPropertySet()->getPropertyValue( "TextRotation" ) >>= fVal
)
202 rOutItemSet
.Put( SfxInt32Item( nWhichId
, static_cast< sal_Int32
>(
203 ::rtl::math::round( fVal
* 100.0 ) ) ));
210 } // namespace wrapper
213 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */