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 "RegressionEquation.hxx"
28 #include "LineProperties.hxx"
29 #include "FillProperties.hxx"
30 #include "UserDefinedProperties.hxx"
31 #include "CharacterProperties.hxx"
32 #include "PropertyHelper.hxx"
33 #include "macros.hxx"
34 #include "ContainerHelper.hxx"
35 
36 #include <com/sun/star/uno/Sequence.hxx>
37 #include <com/sun/star/drawing/FillStyle.hpp>
38 #include <com/sun/star/drawing/LineStyle.hpp>
39 #include <com/sun/star/beans/PropertyAttribute.hpp>
40 #include <com/sun/star/chart2/RelativePosition.hpp>
41 #include <com/sun/star/awt/Size.hpp>
42 
43 #include <algorithm>
44 
45 using namespace ::com::sun::star;
46 
47 using ::com::sun::star::uno::Reference;
48 using ::com::sun::star::beans::Property;
49 using ::osl::MutexGuard;
50 
51 // ____________________________________________________________
52 
53 namespace
54 {
55 
56 static const ::rtl::OUString lcl_aImplementationName(
57     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.RegressionEquation" ));
58 static const ::rtl::OUString lcl_aServiceName(
59     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.RegressionEquation" ));
60 
61 enum
62 {
63     PROP_EQUATION_SHOW,
64     PROP_EQUATION_SHOW_CORRELATION_COEFF,
65 //     PROP_EQUATION_SEPARATOR,
66     PROP_EQUATION_REF_PAGE_SIZE,
67     PROP_EQUATION_REL_POS,
68     PROP_EQUATION_NUMBER_FORMAT
69 };
70 
lcl_AddPropertiesToVector(::std::vector<Property> & rOutProperties)71 void lcl_AddPropertiesToVector(
72     ::std::vector< Property > & rOutProperties )
73 {
74     rOutProperties.push_back(
75         Property( C2U( "ShowEquation" ),
76                   PROP_EQUATION_SHOW,
77                   ::getBooleanCppuType(),
78                   beans::PropertyAttribute::BOUND
79                   | beans::PropertyAttribute::MAYBEDEFAULT ));
80 
81     rOutProperties.push_back(
82         Property( C2U( "ShowCorrelationCoefficient" ),
83                   PROP_EQUATION_SHOW_CORRELATION_COEFF,
84                   ::getBooleanCppuType(),
85                   beans::PropertyAttribute::BOUND
86                   | beans::PropertyAttribute::MAYBEDEFAULT ));
87 
88 //     rOutProperties.push_back(
89 //         Property( C2U( "Separator" ),
90 //                   PROP_EQUATION_SEPARATOR,
91 //                   ::getCppuType( reinterpret_cast< ::rtl::OUString * >(0)),
92 //                   beans::PropertyAttribute::BOUND
93 //                   | beans::PropertyAttribute::MAYBEDEFAULT ));
94 
95     rOutProperties.push_back(
96         Property( C2U( "ReferencePageSize" ),
97                   PROP_EQUATION_REF_PAGE_SIZE,
98                   ::getCppuType( reinterpret_cast< const awt::Size * >(0)),
99                   beans::PropertyAttribute::BOUND
100                   | beans::PropertyAttribute::MAYBEVOID ));
101 
102     rOutProperties.push_back(
103         Property( C2U( "RelativePosition" ),
104                   PROP_EQUATION_REL_POS,
105                   ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)),
106                   beans::PropertyAttribute::BOUND
107                   | beans::PropertyAttribute::MAYBEVOID ));
108 
109     rOutProperties.push_back(
110         Property( C2U( "NumberFormat" ),
111                   PROP_EQUATION_NUMBER_FORMAT,
112                   ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
113                   beans::PropertyAttribute::BOUND
114                   | beans::PropertyAttribute::MAYBEVOID ));
115 }
116 
117 struct StaticRegressionEquationDefaults_Initializer
118 {
operator ()__anone2308f090111::StaticRegressionEquationDefaults_Initializer119     ::chart::tPropertyValueMap* operator()()
120     {
121         static ::chart::tPropertyValueMap aStaticDefaults;
122         lcl_AddDefaultsToMap( aStaticDefaults );
123         return &aStaticDefaults;
124     }
125 private:
lcl_AddDefaultsToMap__anone2308f090111::StaticRegressionEquationDefaults_Initializer126     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
127     {
128         ::chart::LineProperties::AddDefaultsToMap( rOutMap );
129         ::chart::FillProperties::AddDefaultsToMap( rOutMap );
130         ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
131 
132         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW, false );
133         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW_CORRELATION_COEFF, false );
134         //::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SEPARATOR, ::rtl::OUString( sal_Unicode( '\n' )));
135 
136         // override other defaults
137         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE );
138         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LineProperties::PROP_LINE_STYLE, drawing::LineStyle_NONE );
139 
140         float fDefaultCharHeight = 10.0;
141         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
142         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
143         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
144     }
145 };
146 
147 struct StaticRegressionEquationDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticRegressionEquationDefaults_Initializer >
148 {
149 };
150 
151 struct StaticRegressionEquationInfoHelper_Initializer
152 {
operator ()__anone2308f090111::StaticRegressionEquationInfoHelper_Initializer153     ::cppu::OPropertyArrayHelper* operator()()
154     {
155         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
156         return &aPropHelper;
157     }
158 
159 private:
lcl_GetPropertySequence__anone2308f090111::StaticRegressionEquationInfoHelper_Initializer160     uno::Sequence< Property > lcl_GetPropertySequence()
161     {
162         ::std::vector< ::com::sun::star::beans::Property > aProperties;
163         lcl_AddPropertiesToVector( aProperties );
164         ::chart::LineProperties::AddPropertiesToVector( aProperties );
165         ::chart::FillProperties::AddPropertiesToVector( aProperties );
166         ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
167         ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
168 
169         ::std::sort( aProperties.begin(), aProperties.end(),
170                      ::chart::PropertyNameLess() );
171 
172         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
173     }
174 
175 };
176 
177 struct StaticRegressionEquationInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticRegressionEquationInfoHelper_Initializer >
178 {
179 };
180 
181 struct StaticRegressionEquationInfo_Initializer
182 {
operator ()__anone2308f090111::StaticRegressionEquationInfo_Initializer183     uno::Reference< beans::XPropertySetInfo >* operator()()
184     {
185         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
186             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticRegressionEquationInfoHelper::get() ) );
187         return &xPropertySetInfo;
188     }
189 };
190 
191 struct StaticRegressionEquationInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticRegressionEquationInfo_Initializer >
192 {
193 };
194 
195 } // anonymous namespace
196 
197 // ____________________________________________________________
198 
199 namespace chart
200 {
201 
RegressionEquation(const Reference<uno::XComponentContext> & xContext)202 RegressionEquation::RegressionEquation( const Reference< uno::XComponentContext > & xContext ) :
203         ::property::OPropertySet( m_aMutex ),
204         m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder()),
205         m_xContext( xContext )
206 {}
207 
RegressionEquation(const RegressionEquation & rOther)208 RegressionEquation::RegressionEquation( const RegressionEquation & rOther ) :
209         MutexContainer(),
210         impl::RegressionEquation_Base(),
211         ::property::OPropertySet( rOther, m_aMutex ),
212     m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder())
213 {}
214 
~RegressionEquation()215 RegressionEquation::~RegressionEquation()
216 {}
217 
218 
219 // ____ XCloneable ____
createClone()220 uno::Reference< util::XCloneable > SAL_CALL RegressionEquation::createClone()
221     throw (uno::RuntimeException)
222 {
223     return uno::Reference< util::XCloneable >( new RegressionEquation( *this ));
224 }
225 
226 // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const227 uno::Any RegressionEquation::GetDefaultValue( sal_Int32 nHandle ) const
228     throw(beans::UnknownPropertyException)
229 {
230     const tPropertyValueMap& rStaticDefaults = *StaticRegressionEquationDefaults::get();
231     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
232     if( aFound == rStaticDefaults.end() )
233         return uno::Any();
234     return (*aFound).second;
235 }
236 
getInfoHelper()237 ::cppu::IPropertyArrayHelper & SAL_CALL RegressionEquation::getInfoHelper()
238 {
239     return *StaticRegressionEquationInfoHelper::get();
240 }
241 
242 // ____ XPropertySet ____
getPropertySetInfo()243 Reference< beans::XPropertySetInfo > SAL_CALL RegressionEquation::getPropertySetInfo()
244     throw (uno::RuntimeException)
245 {
246     return *StaticRegressionEquationInfo::get();
247 }
248 
249 // ____ XModifyBroadcaster ____
addModifyListener(const uno::Reference<util::XModifyListener> & aListener)250 void SAL_CALL RegressionEquation::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
251     throw (uno::RuntimeException)
252 {
253     try
254     {
255         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
256         xBroadcaster->addModifyListener( aListener );
257     }
258     catch( const uno::Exception & ex )
259     {
260         ASSERT_EXCEPTION( ex );
261     }
262 }
263 
removeModifyListener(const uno::Reference<util::XModifyListener> & aListener)264 void SAL_CALL RegressionEquation::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
265     throw (uno::RuntimeException)
266 {
267     try
268     {
269         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
270         xBroadcaster->removeModifyListener( aListener );
271     }
272     catch( const uno::Exception & ex )
273     {
274         ASSERT_EXCEPTION( ex );
275     }
276 }
277 
278 // ____ XModifyListener ____
modified(const lang::EventObject & aEvent)279 void SAL_CALL RegressionEquation::modified( const lang::EventObject& aEvent )
280     throw (uno::RuntimeException)
281 {
282     m_xModifyEventForwarder->modified( aEvent );
283 }
284 
285 // ____ XEventListener (base of XModifyListener) ____
disposing(const lang::EventObject &)286 void SAL_CALL RegressionEquation::disposing( const lang::EventObject& /* Source */ )
287     throw (uno::RuntimeException)
288 {
289     // nothing
290 }
291 
292 // ____ OPropertySet ____
firePropertyChangeEvent()293 void RegressionEquation::firePropertyChangeEvent()
294 {
295     fireModifyEvent();
296 }
297 
fireModifyEvent()298 void RegressionEquation::fireModifyEvent()
299 {
300     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
301 }
302 
303 // --------------------------------------------------------------------------------
304 
305 // ____ XTitle ____
getText()306 uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL RegressionEquation::getText()
307     throw (uno::RuntimeException)
308 {
309     // /--
310     MutexGuard aGuard( GetMutex() );
311     return m_aStrings;
312     // \--
313 }
314 
setText(const uno::Sequence<uno::Reference<chart2::XFormattedString>> & Strings)315 void SAL_CALL RegressionEquation::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& Strings )
316     throw (uno::RuntimeException)
317 {
318     // /--
319     MutexGuard aGuard( GetMutex() );
320     ModifyListenerHelper::removeListenerFromAllElements(
321         ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
322     m_aStrings = Strings;
323     ModifyListenerHelper::addListenerToAllElements(
324         ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
325     fireModifyEvent();
326     // \--
327 }
328 
329 // ================================================================================
330 
getSupportedServiceNames_Static()331 uno::Sequence< ::rtl::OUString > RegressionEquation::getSupportedServiceNames_Static()
332 {
333     const sal_Int32 nNumServices( 5 );
334     sal_Int32 nI = 0;
335     uno::Sequence< ::rtl::OUString > aServices( nNumServices );
336     aServices[ nI++ ] = lcl_aServiceName;
337     aServices[ nI++ ] = C2U( "com.sun.star.beans.PropertySet" );
338     aServices[ nI++ ] = C2U( "com.sun.star.drawing.FillProperties" );
339     aServices[ nI++ ] = C2U( "com.sun.star.drawing.LineProperties" );
340     aServices[ nI++ ] = C2U( "com.sun.star.style.CharacterProperties" );
341     OSL_ASSERT( nNumServices == nI );
342     return aServices;
343 }
344 
345 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
346 APPHELPER_XSERVICEINFO_IMPL( RegressionEquation, lcl_aImplementationName );
347 
348 using impl::RegressionEquation_Base;
349 
350 IMPLEMENT_FORWARD_XINTERFACE2( RegressionEquation, RegressionEquation_Base, ::property::OPropertySet )
351 
352 } //  namespace chart
353