1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_chart2.hxx"
26 
27 #include "RegressionEquationItemConverter.hxx"
28 #include "SchWhichPairs.hxx"
29 #include "macros.hxx"
30 #include "ItemPropertyMap.hxx"
31 #include "GraphicPropertyItemConverter.hxx"
32 #include "CharacterPropertyItemConverter.hxx"
33 #include "MultipleItemConverter.hxx"
34 
35 #include <svl/intitem.hxx>
36 #include <rtl/math.hxx>
37 
38 #include <functional>
39 #include <algorithm>
40 
41 using namespace ::com::sun::star;
42 
43 namespace
44 {
lcl_GetEquationPropertyMap()45 ::comphelper::ItemPropertyMapType & lcl_GetEquationPropertyMap()
46 {
47     static ::comphelper::ItemPropertyMapType aEquationPropertyMap;
48 
49     return aEquationPropertyMap;
50 };
51 } // anonymous namespace
52 
53 namespace chart
54 {
55 namespace wrapper
56 {
57 
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)58 RegressionEquationItemConverter::RegressionEquationItemConverter(
59     const ::com::sun::star::uno::Reference<
60     ::com::sun::star::beans::XPropertySet > & rPropertySet,
61     SfxItemPool& rItemPool,
62     SdrModel& rDrawModel,
63     const uno::Reference< lang::XMultiServiceFactory > & xNamedPropertyContainerFactory,
64     ::std::auto_ptr< ::com::sun::star::awt::Size > pRefSize ) :
65         ItemConverter( rPropertySet, rItemPool )
66 {
67     m_aConverters.push_back( new GraphicPropertyItemConverter(
68                                  rPropertySet, rItemPool, rDrawModel,
69                                  xNamedPropertyContainerFactory,
70                                  GraphicPropertyItemConverter::LINE_AND_FILL_PROPERTIES ));
71 
72     m_aConverters.push_back( new CharacterPropertyItemConverter(
73                                  rPropertySet, rItemPool, pRefSize, C2U("ReferencePageSize")));
74 
75 //     // CharacterProperties are not at the title but at its contained XFormattedString objects
76 //     // take the first formatted string in the sequence
77 //     uno::Reference< chart2::XTitle > xTitle( rPropertySet, uno::UNO_QUERY );
78 //     if( xTitle.is())
79 //     {
80 //         uno::Sequence< uno::Reference< chart2::XFormattedString > > aStringSeq( xTitle->getText());
81 //         if( aStringSeq.getLength() > 0 )
82 //         {
83 //             m_aConverters.push_back(
84 //                 new FormattedStringsConverter( aStringSeq, rItemPool, pRefSize, rPropertySet ));
85 //         }
86 //     }
87 }
88 
~RegressionEquationItemConverter()89 RegressionEquationItemConverter::~RegressionEquationItemConverter()
90 {
91     ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
92                      ::comphelper::DeleteItemConverterPtr() );
93 }
94 
FillItemSet(SfxItemSet & rOutItemSet) const95 void RegressionEquationItemConverter::FillItemSet( SfxItemSet & rOutItemSet ) const
96 {
97     ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
98                      ::comphelper::FillItemSetFunc( rOutItemSet ));
99 
100     // own items
101     ItemConverter::FillItemSet( rOutItemSet );
102 }
103 
ApplyItemSet(const SfxItemSet & rItemSet)104 bool RegressionEquationItemConverter::ApplyItemSet( const SfxItemSet & rItemSet )
105 {
106     bool bResult = false;
107 
108     ::std::for_each( m_aConverters.begin(), m_aConverters.end(),
109                      ::comphelper::ApplyItemSetFunc( rItemSet, bResult ));
110 
111     // own items
112     return ItemConverter::ApplyItemSet( rItemSet ) || bResult;
113 }
114 
GetWhichPairs() const115 const sal_uInt16 * RegressionEquationItemConverter::GetWhichPairs() const
116 {
117     // must span all used items!
118     return nRegEquationWhichPairs;
119 }
120 
GetItemProperty(tWhichIdType nWhichId,tPropertyNameWithMemberId & rOutProperty) const121 bool RegressionEquationItemConverter::GetItemProperty( tWhichIdType nWhichId, tPropertyNameWithMemberId & rOutProperty ) const
122 {
123     ::comphelper::ItemPropertyMapType & rMap( lcl_GetEquationPropertyMap());
124     ::comphelper::ItemPropertyMapType::const_iterator aIt( rMap.find( nWhichId ));
125 
126     if( aIt == rMap.end())
127         return false;
128 
129     rOutProperty =(*aIt).second;
130     return true;
131 }
132 
ApplySpecialItem(sal_uInt16 nWhichId,const SfxItemSet & rItemSet)133 bool RegressionEquationItemConverter::ApplySpecialItem(
134     sal_uInt16 nWhichId, const SfxItemSet & rItemSet )
135     throw( uno::Exception )
136 {
137     bool bChanged = false;
138 
139     switch( nWhichId )
140     {
141         case SID_ATTR_NUMBERFORMAT_VALUE:
142         {
143 //             bool bUseSourceFormat =
144 //                 (static_cast< const SfxBoolItem & >(
145 //                     rItemSet.Get( SID_ATTR_NUMBERFORMAT_SOURCE )).GetValue() );
146 
147 //             if( ! bUseSourceFormat )
148 //             {
149             uno::Any aValue( static_cast< sal_Int32 >(
150                 static_cast< const SfxUInt32Item & >(
151                     rItemSet.Get( nWhichId )).GetValue()));
152             if( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )) != aValue )
153             {
154                 GetPropertySet()->setPropertyValue( C2U( "NumberFormat" ), aValue );
155                 bChanged = true;
156             }
157         }
158         break;
159     }
160 
161     return bChanged;
162 }
163 
FillSpecialItem(sal_uInt16 nWhichId,SfxItemSet & rOutItemSet) const164 void RegressionEquationItemConverter::FillSpecialItem(
165     sal_uInt16 nWhichId, SfxItemSet & rOutItemSet ) const
166     throw( uno::Exception )
167 {
168     switch( nWhichId )
169     {
170         case SID_ATTR_NUMBERFORMAT_VALUE:
171         {
172             sal_Int32 nFormatKey = 0;
173             if( GetPropertySet()->getPropertyValue( C2U( "NumberFormat" )) >>= nFormatKey )
174             {
175                 rOutItemSet.Put( SfxUInt32Item( nWhichId, nFormatKey ));
176             }
177         }
178         break;
179    }
180 }
181 
182 } //  namespace wrapper
183 } //  namespace chart
184