merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / tools / RegressionEquation.cxx
blobea16e5b7702a00cda3dc4b8500b08d93a8bab2a8
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
31 #include "RegressionEquation.hxx"
32 #include "LineProperties.hxx"
33 #include "FillProperties.hxx"
34 #include "UserDefinedProperties.hxx"
35 #include "CharacterProperties.hxx"
36 #include "PropertyHelper.hxx"
37 #include "macros.hxx"
38 #include "ContainerHelper.hxx"
40 #include <com/sun/star/uno/Sequence.hxx>
41 #include <com/sun/star/drawing/FillStyle.hpp>
42 #include <com/sun/star/drawing/LineStyle.hpp>
43 #include <com/sun/star/beans/PropertyAttribute.hpp>
44 #include <com/sun/star/chart2/RelativePosition.hpp>
45 #include <com/sun/star/awt/Size.hpp>
47 #include <algorithm>
49 using namespace ::com::sun::star;
51 using ::com::sun::star::uno::Reference;
52 using ::com::sun::star::beans::Property;
53 using ::osl::MutexGuard;
55 // ____________________________________________________________
57 namespace
60 static const ::rtl::OUString lcl_aImplementationName(
61 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.RegressionEquation" ));
62 static const ::rtl::OUString lcl_aServiceName(
63 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.RegressionEquation" ));
65 enum
67 PROP_EQUATION_SHOW,
68 PROP_EQUATION_SHOW_CORRELATION_COEFF,
69 // PROP_EQUATION_SEPARATOR,
70 PROP_EQUATION_REF_PAGE_SIZE,
71 PROP_EQUATION_REL_POS,
72 PROP_EQUATION_NUMBER_FORMAT
75 void lcl_AddPropertiesToVector(
76 ::std::vector< Property > & rOutProperties )
78 rOutProperties.push_back(
79 Property( C2U( "ShowEquation" ),
80 PROP_EQUATION_SHOW,
81 ::getBooleanCppuType(),
82 beans::PropertyAttribute::BOUND
83 | beans::PropertyAttribute::MAYBEDEFAULT ));
85 rOutProperties.push_back(
86 Property( C2U( "ShowCorrelationCoefficient" ),
87 PROP_EQUATION_SHOW_CORRELATION_COEFF,
88 ::getBooleanCppuType(),
89 beans::PropertyAttribute::BOUND
90 | beans::PropertyAttribute::MAYBEDEFAULT ));
92 // rOutProperties.push_back(
93 // Property( C2U( "Separator" ),
94 // PROP_EQUATION_SEPARATOR,
95 // ::getCppuType( reinterpret_cast< ::rtl::OUString * >(0)),
96 // beans::PropertyAttribute::BOUND
97 // | beans::PropertyAttribute::MAYBEDEFAULT ));
99 rOutProperties.push_back(
100 Property( C2U( "ReferencePageSize" ),
101 PROP_EQUATION_REF_PAGE_SIZE,
102 ::getCppuType( reinterpret_cast< const awt::Size * >(0)),
103 beans::PropertyAttribute::BOUND
104 | beans::PropertyAttribute::MAYBEVOID ));
106 rOutProperties.push_back(
107 Property( C2U( "RelativePosition" ),
108 PROP_EQUATION_REL_POS,
109 ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)),
110 beans::PropertyAttribute::BOUND
111 | beans::PropertyAttribute::MAYBEVOID ));
113 rOutProperties.push_back(
114 Property( C2U( "NumberFormat" ),
115 PROP_EQUATION_NUMBER_FORMAT,
116 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
117 beans::PropertyAttribute::BOUND
118 | beans::PropertyAttribute::MAYBEVOID ));
121 void lcl_AddDefaultsToMap(
122 ::chart::tPropertyValueMap & rOutMap )
124 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW, false );
125 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW_CORRELATION_COEFF, false );
126 // ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SEPARATOR, ::rtl::OUString( sal_Unicode( '\n' )));
128 // override other defaults
129 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE );
130 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LineProperties::PROP_LINE_STYLE, drawing::LineStyle_NONE );
132 float fDefaultCharHeight = 10.0;
133 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
134 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
135 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
138 const uno::Sequence< Property > & lcl_GetPropertySequence()
140 static uno::Sequence< Property > aPropSeq;
142 // /--
143 MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
144 if( 0 == aPropSeq.getLength() )
146 // get properties
147 ::std::vector< ::com::sun::star::beans::Property > aProperties;
148 lcl_AddPropertiesToVector( aProperties );
149 ::chart::LineProperties::AddPropertiesToVector( aProperties );
150 ::chart::FillProperties::AddPropertiesToVector( aProperties );
151 ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
152 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
154 // and sort them for access via bsearch
155 ::std::sort( aProperties.begin(), aProperties.end(),
156 ::chart::PropertyNameLess() );
158 // transfer result to static Sequence
159 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
162 return aPropSeq;
165 ::cppu::IPropertyArrayHelper & lcl_getInfoHelper()
167 static ::cppu::OPropertyArrayHelper aArrayHelper(
168 lcl_GetPropertySequence(),
169 /* bSorted = */ sal_True );
171 return aArrayHelper;
174 } // anonymous namespace
176 // ____________________________________________________________
178 namespace chart
181 RegressionEquation::RegressionEquation( const Reference< uno::XComponentContext > & xContext ) :
182 ::property::OPropertySet( m_aMutex ),
183 m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder()),
184 m_xContext( xContext )
187 RegressionEquation::RegressionEquation( const RegressionEquation & rOther ) :
188 MutexContainer(),
189 impl::RegressionEquation_Base(),
190 ::property::OPropertySet( rOther, m_aMutex ),
191 m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder())
194 RegressionEquation::~RegressionEquation()
198 // ____ XCloneable ____
199 uno::Reference< util::XCloneable > SAL_CALL RegressionEquation::createClone()
200 throw (uno::RuntimeException)
202 return uno::Reference< util::XCloneable >( new RegressionEquation( *this ));
205 // ____ OPropertySet ____
206 uno::Any RegressionEquation::GetDefaultValue( sal_Int32 nHandle ) const
207 throw(beans::UnknownPropertyException)
209 static tPropertyValueMap aStaticDefaults;
211 // /--
212 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
213 if( 0 == aStaticDefaults.size() )
215 // initialize defaults
216 LineProperties::AddDefaultsToMap( aStaticDefaults );
217 FillProperties::AddDefaultsToMap( aStaticDefaults );
218 CharacterProperties::AddDefaultsToMap( aStaticDefaults );
220 // overrides a line property
221 lcl_AddDefaultsToMap( aStaticDefaults );
224 tPropertyValueMap::const_iterator aFound(
225 aStaticDefaults.find( nHandle ));
227 if( aFound == aStaticDefaults.end())
228 return uno::Any();
230 return (*aFound).second;
231 // \--
234 ::cppu::IPropertyArrayHelper & SAL_CALL RegressionEquation::getInfoHelper()
236 return lcl_getInfoHelper();
239 // ____ XPropertySet ____
240 Reference< beans::XPropertySetInfo > SAL_CALL
241 RegressionEquation::getPropertySetInfo()
242 throw (uno::RuntimeException)
244 static Reference< beans::XPropertySetInfo > xInfo;
246 // /--
247 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
248 if( !xInfo.is())
250 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
251 lcl_getInfoHelper());
254 return xInfo;
255 // \--
259 // ____ XModifyBroadcaster ____
260 void SAL_CALL RegressionEquation::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
261 throw (uno::RuntimeException)
265 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
266 xBroadcaster->addModifyListener( aListener );
268 catch( const uno::Exception & ex )
270 ASSERT_EXCEPTION( ex );
274 void SAL_CALL RegressionEquation::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
275 throw (uno::RuntimeException)
279 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
280 xBroadcaster->removeModifyListener( aListener );
282 catch( const uno::Exception & ex )
284 ASSERT_EXCEPTION( ex );
288 // ____ XModifyListener ____
289 void SAL_CALL RegressionEquation::modified( const lang::EventObject& aEvent )
290 throw (uno::RuntimeException)
292 m_xModifyEventForwarder->modified( aEvent );
295 // ____ XEventListener (base of XModifyListener) ____
296 void SAL_CALL RegressionEquation::disposing( const lang::EventObject& /* Source */ )
297 throw (uno::RuntimeException)
299 // nothing
302 // ____ OPropertySet ____
303 void RegressionEquation::firePropertyChangeEvent()
305 fireModifyEvent();
308 void RegressionEquation::fireModifyEvent()
310 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
313 // --------------------------------------------------------------------------------
315 // ____ XTitle ____
316 uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL RegressionEquation::getText()
317 throw (uno::RuntimeException)
319 // /--
320 MutexGuard aGuard( GetMutex() );
321 return m_aStrings;
322 // \--
325 void SAL_CALL RegressionEquation::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& Strings )
326 throw (uno::RuntimeException)
328 // /--
329 MutexGuard aGuard( GetMutex() );
330 ModifyListenerHelper::removeListenerFromAllElements(
331 ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
332 m_aStrings = Strings;
333 ModifyListenerHelper::addListenerToAllElements(
334 ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
335 fireModifyEvent();
336 // \--
339 // ================================================================================
341 uno::Sequence< ::rtl::OUString > RegressionEquation::getSupportedServiceNames_Static()
343 const sal_Int32 nNumServices( 5 );
344 sal_Int32 nI = 0;
345 uno::Sequence< ::rtl::OUString > aServices( nNumServices );
346 aServices[ nI++ ] = lcl_aServiceName;
347 aServices[ nI++ ] = C2U( "com.sun.star.beans.PropertySet" );
348 aServices[ nI++ ] = C2U( "com.sun.star.drawing.FillProperties" );
349 aServices[ nI++ ] = C2U( "com.sun.star.drawing.LineProperties" );
350 aServices[ nI++ ] = C2U( "com.sun.star.style.CharacterProperties" );
351 OSL_ASSERT( nNumServices == nI );
352 return aServices;
355 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
356 APPHELPER_XSERVICEINFO_IMPL( RegressionEquation, lcl_aImplementationName );
358 using impl::RegressionEquation_Base;
360 IMPLEMENT_FORWARD_XINTERFACE2( RegressionEquation, RegressionEquation_Base, ::property::OPropertySet )
362 } // namespace chart