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
10*cde9e8dcSAndrew Rist *
11*cde9e8dcSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist *
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.
19*cde9e8dcSAndrew Rist *
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
27cdf0e10cSrcweir #include "RegressionEquationItemConverter.hxx"
28cdf0e10cSrcweir #include "SchWhichPairs.hxx"
29cdf0e10cSrcweir #include "macros.hxx"
30cdf0e10cSrcweir #include "ItemPropertyMap.hxx"
31cdf0e10cSrcweir #include "GraphicPropertyItemConverter.hxx"
32cdf0e10cSrcweir #include "CharacterPropertyItemConverter.hxx"
33cdf0e10cSrcweir #include "MultipleItemConverter.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include <svl/intitem.hxx>
36cdf0e10cSrcweir #include <rtl/math.hxx>
37cdf0e10cSrcweir
38cdf0e10cSrcweir #include <functional>
39cdf0e10cSrcweir #include <algorithm>
40cdf0e10cSrcweir
41cdf0e10cSrcweir using namespace ::com::sun::star;
42cdf0e10cSrcweir
43cdf0e10cSrcweir namespace
44cdf0e10cSrcweir {
lcl_GetEquationPropertyMap()45cdf0e10cSrcweir ::comphelper::ItemPropertyMapType & lcl_GetEquationPropertyMap()
46cdf0e10cSrcweir {
47cdf0e10cSrcweir static ::comphelper::ItemPropertyMapType aEquationPropertyMap;
48cdf0e10cSrcweir
49cdf0e10cSrcweir return aEquationPropertyMap;
50cdf0e10cSrcweir };
51cdf0e10cSrcweir } // anonymous namespace
52cdf0e10cSrcweir
53cdf0e10cSrcweir namespace chart
54cdf0e10cSrcweir {
55cdf0e10cSrcweir namespace wrapper
56cdf0e10cSrcweir {
57cdf0e10cSrcweir
RegressionEquationItemConverter(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)58cdf0e10cSrcweir RegressionEquationItemConverter::RegressionEquationItemConverter(
59cdf0e10cSrcweir const ::com::sun::star::uno::Reference<
60cdf0e10cSrcweir ::com::sun::star::beans::XPropertySet > & rPropertySet,
61cdf0e10cSrcweir SfxItemPool& rItemPool,
62cdf0e10cSrcweir SdrModel& rDrawModel,
63cdf0e10cSrcweir const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
64cdf0e10cSrcweir ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize ) :
65cdf0e10cSrcweir ItemConverter( rPropertySet, rItemPool )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir m_aConverters.push_back( new GraphicPropertyItemConverter(
68cdf0e10cSrcweir rPropertySet, rItemPool, rDrawModel,
69cdf0e10cSrcweir xNamedPropertyContainerFactory,
70cdf0e10cSrcweir GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES ));
71cdf0e10cSrcweir
72cdf0e10cSrcweir m_aConverters.push_back( new CharacterPropertyItemConverter(
73cdf0e10cSrcweir rPropertySet, rItemPool, pRefSize, C2U("ReferencePageSize")));
74cdf0e10cSrcweir
75cdf0e10cSrcweir // // CharacterProperties are not at the title but at its contained XFormattedString objects
76cdf0e10cSrcweir // // take the first formatted string in the sequence
77cdf0e10cSrcweir // uno::Reference< chart2::XTitle > xTitle( rPropertySet, uno::UNO_QUERY );
78cdf0e10cSrcweir // if( xTitle.is())
79cdf0e10cSrcweir // {
80cdf0e10cSrcweir // uno::Sequence< uno::Reference< chart2::XFormattedString > > aStringSeq( xTitle->getText());
81cdf0e10cSrcweir // if( aStringSeq.getLength() > 0 )
82cdf0e10cSrcweir // {
83cdf0e10cSrcweir // m_aConverters.push_back(
84cdf0e10cSrcweir // new FormattedStringsConverter( aStringSeq, rItemPool, pRefSize, rPropertySet ));
85cdf0e10cSrcweir // }
86cdf0e10cSrcweir // }
87cdf0e10cSrcweir }
88cdf0e10cSrcweir
~RegressionEquationItemConverter()89cdf0e10cSrcweir RegressionEquationItemConverter::~RegressionEquationItemConverter()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
92cdf0e10cSrcweir ::comphelper::DeleteItemConverterPtr() );
93cdf0e10cSrcweir }
94cdf0e10cSrcweir
FillItemSet(SfxItemSet & rOutItemSet) const95cdf0e10cSrcweir void RegressionEquationItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
96cdf0e10cSrcweir {
97cdf0e10cSrcweir ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
98cdf0e10cSrcweir ::comphelper::FillItemSetFunc( rOutItemSet ));
99cdf0e10cSrcweir
100cdf0e10cSrcweir // own items
101cdf0e10cSrcweir ItemConverter::FillItemSet( rOutItemSet );
102cdf0e10cSrcweir }
103cdf0e10cSrcweir
ApplyItemSet(const SfxItemSet & rItemSet)104cdf0e10cSrcweir bool RegressionEquationItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
105cdf0e10cSrcweir {
106cdf0e10cSrcweir bool bResult = false;
107cdf0e10cSrcweir
108cdf0e10cSrcweir ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
109cdf0e10cSrcweir ::comphelper::ApplyItemSetFunc( rItemSet, bResult ));
110cdf0e10cSrcweir
111cdf0e10cSrcweir // own items
112cdf0e10cSrcweir return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
113cdf0e10cSrcweir }
114cdf0e10cSrcweir
GetWhichPairs() const115cdf0e10cSrcweir const sal_uInt16 * RegressionEquationItemConverter::GetWhichPairs() const
116cdf0e10cSrcweir {
117cdf0e10cSrcweir // must span all used items!
118cdf0e10cSrcweir return nRegEquationWhichPairs;
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
GetItemProperty(tWhichIdType nWhichId,tPropertyNameWithMemberId & rOutProperty) const121cdf0e10cSrcweir bool RegressionEquationItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
122cdf0e10cSrcweir {
123cdf0e10cSrcweir ::comphelper::ItemPropertyMapType & rMap( lcl_GetEquationPropertyMap());
124cdf0e10cSrcweir ::comphelper::ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
125cdf0e10cSrcweir
126cdf0e10cSrcweir if( aIt == rMap.end())
127cdf0e10cSrcweir return false;
128cdf0e10cSrcweir
129cdf0e10cSrcweir rOutProperty =(*aIt).second;
130cdf0e10cSrcweir return true;
131cdf0e10cSrcweir }
132cdf0e10cSrcweir
ApplySpecialItem(sal_uInt16 nWhichId,const SfxItemSet & rItemSet)133cdf0e10cSrcweir bool RegressionEquationItemConverter::ApplySpecialItem(
134cdf0e10cSrcweir sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
135cdf0e10cSrcweir throw( uno::Exception )
136cdf0e10cSrcweir {
137cdf0e10cSrcweir bool bChanged = false;
138cdf0e10cSrcweir
139cdf0e10cSrcweir switch( nWhichId )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir case SID_ATTR_NUMBERFORMAT_VALUE:
142cdf0e10cSrcweir {
143cdf0e10cSrcweir // bool bUseSourceFormat =
144cdf0e10cSrcweir // (static_cast< const SfxBoolItem & >(
145cdf0e10cSrcweir // rItemSet.Get( SID_ATTR_NUMBERFORMAT_SOURCE )).GetValue() );
146cdf0e10cSrcweir
147cdf0e10cSrcweir // if( ! bUseSourceFormat )
148cdf0e10cSrcweir // {
149cdf0e10cSrcweir uno::Any aValue( static_cast< sal_Int32 >(
150cdf0e10cSrcweir static_cast< const SfxUInt32Item & >(
151cdf0e10cSrcweir rItemSet.Get( nWhichId )).GetValue()));
152cdf0e10cSrcweir if( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )) != aValue )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir GetPropertySet()->setPropertyValue( C2U( "NumberFormat" ), aValue );
155cdf0e10cSrcweir bChanged = true;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir }
158cdf0e10cSrcweir break;
159cdf0e10cSrcweir }
160cdf0e10cSrcweir
161cdf0e10cSrcweir return bChanged;
162cdf0e10cSrcweir }
163cdf0e10cSrcweir
FillSpecialItem(sal_uInt16 nWhichId,SfxItemSet & rOutItemSet) const164cdf0e10cSrcweir void RegressionEquationItemConverter::FillSpecialItem(
165cdf0e10cSrcweir sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
166cdf0e10cSrcweir throw( uno::Exception )
167cdf0e10cSrcweir {
168cdf0e10cSrcweir switch( nWhichId )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir case SID_ATTR_NUMBERFORMAT_VALUE:
171cdf0e10cSrcweir {
172cdf0e10cSrcweir sal_Int32 nFormatKey = 0;
173cdf0e10cSrcweir if( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )) >>= nFormatKey )
174cdf0e10cSrcweir {
175cdf0e10cSrcweir rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
176cdf0e10cSrcweir }
177cdf0e10cSrcweir }
178cdf0e10cSrcweir break;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir }
181cdf0e10cSrcweir
182cdf0e10cSrcweir } // namespace wrapper
183cdf0e10cSrcweir } // namespace chart
184