1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RegressionEquation.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
34 #include "RegressionEquation.hxx"
35 #include "LineProperties.hxx"
36 #include "FillProperties.hxx"
37 #include "UserDefinedProperties.hxx"
38 #include "CharacterProperties.hxx"
39 #include "PropertyHelper.hxx"
41 #include "ContainerHelper.hxx"
43 #include <com/sun/star/uno/Sequence.hxx>
44 #include <com/sun/star/drawing/FillStyle.hpp>
45 #include <com/sun/star/drawing/LineStyle.hpp>
46 #include <com/sun/star/beans/PropertyAttribute.hpp>
47 #include <com/sun/star/chart2/RelativePosition.hpp>
48 #include <com/sun/star/awt/Size.hpp>
52 using namespace ::com::sun::star
;
54 using ::com::sun::star::uno::Reference
;
55 using ::com::sun::star::beans::Property
;
56 using ::osl::MutexGuard
;
58 // ____________________________________________________________
63 static const ::rtl::OUString
lcl_aImplementationName(
64 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.RegressionEquation" ));
65 static const ::rtl::OUString
lcl_aServiceName(
66 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.RegressionEquation" ));
71 PROP_EQUATION_SHOW_CORRELATION_COEFF
,
72 // PROP_EQUATION_SEPARATOR,
73 PROP_EQUATION_REF_PAGE_SIZE
,
74 PROP_EQUATION_REL_POS
,
75 PROP_EQUATION_NUMBER_FORMAT
78 void lcl_AddPropertiesToVector(
79 ::std::vector
< Property
> & rOutProperties
)
81 rOutProperties
.push_back(
82 Property( C2U( "ShowEquation" ),
84 ::getBooleanCppuType(),
85 beans::PropertyAttribute::BOUND
86 | beans::PropertyAttribute::MAYBEDEFAULT
));
88 rOutProperties
.push_back(
89 Property( C2U( "ShowCorrelationCoefficient" ),
90 PROP_EQUATION_SHOW_CORRELATION_COEFF
,
91 ::getBooleanCppuType(),
92 beans::PropertyAttribute::BOUND
93 | beans::PropertyAttribute::MAYBEDEFAULT
));
95 // rOutProperties.push_back(
96 // Property( C2U( "Separator" ),
97 // PROP_EQUATION_SEPARATOR,
98 // ::getCppuType( reinterpret_cast< ::rtl::OUString * >(0)),
99 // beans::PropertyAttribute::BOUND
100 // | beans::PropertyAttribute::MAYBEDEFAULT ));
102 rOutProperties
.push_back(
103 Property( C2U( "ReferencePageSize" ),
104 PROP_EQUATION_REF_PAGE_SIZE
,
105 ::getCppuType( reinterpret_cast< const awt::Size
* >(0)),
106 beans::PropertyAttribute::BOUND
107 | beans::PropertyAttribute::MAYBEVOID
));
109 rOutProperties
.push_back(
110 Property( C2U( "RelativePosition" ),
111 PROP_EQUATION_REL_POS
,
112 ::getCppuType( reinterpret_cast< const chart2::RelativePosition
* >(0)),
113 beans::PropertyAttribute::BOUND
114 | beans::PropertyAttribute::MAYBEVOID
));
116 rOutProperties
.push_back(
117 Property( C2U( "NumberFormat" ),
118 PROP_EQUATION_NUMBER_FORMAT
,
119 ::getCppuType( reinterpret_cast< const sal_Int32
* >(0)),
120 beans::PropertyAttribute::BOUND
121 | beans::PropertyAttribute::MAYBEVOID
));
124 void lcl_AddDefaultsToMap(
125 ::chart::tPropertyValueMap
& rOutMap
)
127 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_EQUATION_SHOW
, false );
128 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_EQUATION_SHOW_CORRELATION_COEFF
, false );
129 // ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SEPARATOR, ::rtl::OUString( sal_Unicode( '\n' )));
131 // override other defaults
132 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::FillProperties::PROP_FILL_STYLE
, drawing::FillStyle_NONE
);
133 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::LineProperties::PROP_LINE_STYLE
, drawing::LineStyle_NONE
);
135 float fDefaultCharHeight
= 10.0;
136 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT
, fDefaultCharHeight
);
137 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT
, fDefaultCharHeight
);
138 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT
, fDefaultCharHeight
);
141 const uno::Sequence
< Property
> & lcl_GetPropertySequence()
143 static uno::Sequence
< Property
> aPropSeq
;
146 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
147 if( 0 == aPropSeq
.getLength() )
150 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
151 lcl_AddPropertiesToVector( aProperties
);
152 ::chart::LineProperties::AddPropertiesToVector( aProperties
);
153 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
154 ::chart::CharacterProperties::AddPropertiesToVector( aProperties
);
155 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
157 // and sort them for access via bsearch
158 ::std::sort( aProperties
.begin(), aProperties
.end(),
159 ::chart::PropertyNameLess() );
161 // transfer result to static Sequence
162 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
168 ::cppu::IPropertyArrayHelper
& lcl_getInfoHelper()
170 static ::cppu::OPropertyArrayHelper
aArrayHelper(
171 lcl_GetPropertySequence(),
172 /* bSorted = */ sal_True
);
177 } // anonymous namespace
179 // ____________________________________________________________
184 RegressionEquation::RegressionEquation( const Reference
< uno::XComponentContext
> & xContext
) :
185 ::property::OPropertySet( m_aMutex
),
186 m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder()),
187 m_xContext( xContext
)
190 RegressionEquation::RegressionEquation( const RegressionEquation
& rOther
) :
192 impl::RegressionEquation_Base(),
193 ::property::OPropertySet( rOther
, m_aMutex
),
194 m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder())
197 RegressionEquation::~RegressionEquation()
201 // ____ XCloneable ____
202 uno::Reference
< util::XCloneable
> SAL_CALL
RegressionEquation::createClone()
203 throw (uno::RuntimeException
)
205 return uno::Reference
< util::XCloneable
>( new RegressionEquation( *this ));
208 // ____ OPropertySet ____
209 uno::Any
RegressionEquation::GetDefaultValue( sal_Int32 nHandle
) const
210 throw(beans::UnknownPropertyException
)
212 static tPropertyValueMap aStaticDefaults
;
215 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
216 if( 0 == aStaticDefaults
.size() )
218 // initialize defaults
219 LineProperties::AddDefaultsToMap( aStaticDefaults
);
220 FillProperties::AddDefaultsToMap( aStaticDefaults
);
221 CharacterProperties::AddDefaultsToMap( aStaticDefaults
);
223 // overrides a line property
224 lcl_AddDefaultsToMap( aStaticDefaults
);
227 tPropertyValueMap::const_iterator
aFound(
228 aStaticDefaults
.find( nHandle
));
230 if( aFound
== aStaticDefaults
.end())
233 return (*aFound
).second
;
237 ::cppu::IPropertyArrayHelper
& SAL_CALL
RegressionEquation::getInfoHelper()
239 return lcl_getInfoHelper();
242 // ____ XPropertySet ____
243 Reference
< beans::XPropertySetInfo
> SAL_CALL
244 RegressionEquation::getPropertySetInfo()
245 throw (uno::RuntimeException
)
247 static Reference
< beans::XPropertySetInfo
> xInfo
;
250 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
253 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
254 lcl_getInfoHelper());
262 // ____ XModifyBroadcaster ____
263 void SAL_CALL
RegressionEquation::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
264 throw (uno::RuntimeException
)
268 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
269 xBroadcaster
->addModifyListener( aListener
);
271 catch( const uno::Exception
& ex
)
273 ASSERT_EXCEPTION( ex
);
277 void SAL_CALL
RegressionEquation::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
278 throw (uno::RuntimeException
)
282 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
283 xBroadcaster
->removeModifyListener( aListener
);
285 catch( const uno::Exception
& ex
)
287 ASSERT_EXCEPTION( ex
);
291 // ____ XModifyListener ____
292 void SAL_CALL
RegressionEquation::modified( const lang::EventObject
& aEvent
)
293 throw (uno::RuntimeException
)
295 m_xModifyEventForwarder
->modified( aEvent
);
298 // ____ XEventListener (base of XModifyListener) ____
299 void SAL_CALL
RegressionEquation::disposing( const lang::EventObject
& /* Source */ )
300 throw (uno::RuntimeException
)
305 // ____ OPropertySet ____
306 void RegressionEquation::firePropertyChangeEvent()
311 void RegressionEquation::fireModifyEvent()
313 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
316 // --------------------------------------------------------------------------------
319 uno::Sequence
< uno::Reference
< chart2::XFormattedString
> > SAL_CALL
RegressionEquation::getText()
320 throw (uno::RuntimeException
)
323 MutexGuard
aGuard( GetMutex() );
328 void SAL_CALL
RegressionEquation::setText( const uno::Sequence
< uno::Reference
< chart2::XFormattedString
> >& Strings
)
329 throw (uno::RuntimeException
)
332 MutexGuard
aGuard( GetMutex() );
333 ModifyListenerHelper::removeListenerFromAllElements(
334 ContainerHelper::SequenceToVector( m_aStrings
), m_xModifyEventForwarder
);
335 m_aStrings
= Strings
;
336 ModifyListenerHelper::addListenerToAllElements(
337 ContainerHelper::SequenceToVector( m_aStrings
), m_xModifyEventForwarder
);
342 // ================================================================================
344 uno::Sequence
< ::rtl::OUString
> RegressionEquation::getSupportedServiceNames_Static()
346 const sal_Int32
nNumServices( 5 );
348 uno::Sequence
< ::rtl::OUString
> aServices( nNumServices
);
349 aServices
[ nI
++ ] = lcl_aServiceName
;
350 aServices
[ nI
++ ] = C2U( "com.sun.star.beans.PropertySet" );
351 aServices
[ nI
++ ] = C2U( "com.sun.star.drawing.FillProperties" );
352 aServices
[ nI
++ ] = C2U( "com.sun.star.drawing.LineProperties" );
353 aServices
[ nI
++ ] = C2U( "com.sun.star.style.CharacterProperties" );
354 OSL_ASSERT( nNumServices
== nI
);
358 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
359 APPHELPER_XSERVICEINFO_IMPL( RegressionEquation
, lcl_aImplementationName
);
361 using impl::RegressionEquation_Base
;
363 IMPLEMENT_FORWARD_XINTERFACE2( RegressionEquation
, RegressionEquation_Base
, ::property::OPropertySet
)