Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "RegressionEquation.hxx"
21 : #include "LinePropertiesHelper.hxx"
22 : #include "FillProperties.hxx"
23 : #include "UserDefinedProperties.hxx"
24 : #include "CharacterProperties.hxx"
25 : #include "PropertyHelper.hxx"
26 : #include "macros.hxx"
27 : #include "ContainerHelper.hxx"
28 :
29 : #include <com/sun/star/uno/Sequence.hxx>
30 : #include <com/sun/star/drawing/FillStyle.hpp>
31 : #include <com/sun/star/drawing/LineStyle.hpp>
32 : #include <com/sun/star/beans/PropertyAttribute.hpp>
33 : #include <com/sun/star/chart2/RelativePosition.hpp>
34 : #include <com/sun/star/awt/Size.hpp>
35 :
36 : #include <algorithm>
37 :
38 : using namespace ::com::sun::star;
39 :
40 : using ::com::sun::star::uno::Reference;
41 : using ::com::sun::star::beans::Property;
42 : using ::osl::MutexGuard;
43 :
44 : namespace
45 : {
46 :
47 0 : static const OUString lcl_aImplementationName( "com.sun.star.comp.chart2.RegressionEquation" );
48 0 : static const OUString lcl_aServiceName( "com.sun.star.chart2.RegressionEquation" );
49 :
50 : enum
51 : {
52 : PROP_EQUATION_SHOW,
53 : PROP_EQUATION_SHOW_CORRELATION_COEFF,
54 : PROP_EQUATION_REF_PAGE_SIZE,
55 : PROP_EQUATION_REL_POS,
56 : PROP_EQUATION_NUMBER_FORMAT
57 : };
58 :
59 0 : void lcl_AddPropertiesToVector(
60 : ::std::vector< Property > & rOutProperties )
61 : {
62 : rOutProperties.push_back(
63 : Property( "ShowEquation",
64 : PROP_EQUATION_SHOW,
65 0 : ::getBooleanCppuType(),
66 : beans::PropertyAttribute::BOUND
67 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
68 :
69 : rOutProperties.push_back(
70 : Property( "ShowCorrelationCoefficient",
71 : PROP_EQUATION_SHOW_CORRELATION_COEFF,
72 0 : ::getBooleanCppuType(),
73 : beans::PropertyAttribute::BOUND
74 0 : | beans::PropertyAttribute::MAYBEDEFAULT ));
75 :
76 : rOutProperties.push_back(
77 : Property( "ReferencePageSize",
78 : PROP_EQUATION_REF_PAGE_SIZE,
79 0 : ::getCppuType( reinterpret_cast< const awt::Size * >(0)),
80 : beans::PropertyAttribute::BOUND
81 0 : | beans::PropertyAttribute::MAYBEVOID ));
82 :
83 : rOutProperties.push_back(
84 : Property( "RelativePosition",
85 : PROP_EQUATION_REL_POS,
86 0 : ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)),
87 : beans::PropertyAttribute::BOUND
88 0 : | beans::PropertyAttribute::MAYBEVOID ));
89 :
90 : rOutProperties.push_back(
91 : Property( "NumberFormat",
92 : PROP_EQUATION_NUMBER_FORMAT,
93 0 : ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)),
94 : beans::PropertyAttribute::BOUND
95 0 : | beans::PropertyAttribute::MAYBEVOID ));
96 0 : }
97 :
98 : struct StaticRegressionEquationDefaults_Initializer
99 : {
100 0 : ::chart::tPropertyValueMap* operator()()
101 : {
102 0 : static ::chart::tPropertyValueMap aStaticDefaults;
103 0 : lcl_AddDefaultsToMap( aStaticDefaults );
104 0 : return &aStaticDefaults;
105 : }
106 : private:
107 0 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
108 : {
109 0 : ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap );
110 0 : ::chart::FillProperties::AddDefaultsToMap( rOutMap );
111 0 : ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
112 :
113 0 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW, false );
114 0 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SHOW_CORRELATION_COEFF, false );
115 : //::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SEPARATOR, OUString( '\n' ));
116 :
117 : // override other defaults
118 0 : ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE );
119 0 : ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LinePropertiesHelper::PROP_LINE_STYLE, drawing::LineStyle_NONE );
120 :
121 0 : float fDefaultCharHeight = 10.0;
122 0 : ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight );
123 0 : ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight );
124 0 : ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight );
125 0 : }
126 : };
127 :
128 : struct StaticRegressionEquationDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticRegressionEquationDefaults_Initializer >
129 : {
130 : };
131 :
132 : struct StaticRegressionEquationInfoHelper_Initializer
133 : {
134 0 : ::cppu::OPropertyArrayHelper* operator()()
135 : {
136 0 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
137 0 : return &aPropHelper;
138 : }
139 :
140 : private:
141 0 : uno::Sequence< Property > lcl_GetPropertySequence()
142 : {
143 0 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
144 0 : lcl_AddPropertiesToVector( aProperties );
145 0 : ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
146 0 : ::chart::FillProperties::AddPropertiesToVector( aProperties );
147 0 : ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
148 0 : ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties );
149 :
150 : ::std::sort( aProperties.begin(), aProperties.end(),
151 0 : ::chart::PropertyNameLess() );
152 :
153 0 : return ::chart::ContainerHelper::ContainerToSequence( aProperties );
154 : }
155 :
156 : };
157 :
158 : struct StaticRegressionEquationInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticRegressionEquationInfoHelper_Initializer >
159 : {
160 : };
161 :
162 : struct StaticRegressionEquationInfo_Initializer
163 : {
164 0 : uno::Reference< beans::XPropertySetInfo >* operator()()
165 : {
166 : static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
167 0 : ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticRegressionEquationInfoHelper::get() ) );
168 0 : return &xPropertySetInfo;
169 : }
170 : };
171 :
172 : struct StaticRegressionEquationInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticRegressionEquationInfo_Initializer >
173 : {
174 : };
175 :
176 : } // anonymous namespace
177 :
178 : namespace chart
179 : {
180 :
181 0 : RegressionEquation::RegressionEquation( const Reference< uno::XComponentContext > & xContext ) :
182 : ::property::OPropertySet( m_aMutex ),
183 0 : m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder()),
184 0 : m_xContext( xContext )
185 0 : {}
186 :
187 0 : RegressionEquation::RegressionEquation( const RegressionEquation & rOther ) :
188 : MutexContainer(),
189 : impl::RegressionEquation_Base(),
190 : ::property::OPropertySet( rOther, m_aMutex ),
191 0 : m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder()),
192 0 : m_xContext( NULL )
193 0 : {}
194 :
195 0 : RegressionEquation::~RegressionEquation()
196 0 : {}
197 :
198 : // ____ XCloneable ____
199 0 : uno::Reference< util::XCloneable > SAL_CALL RegressionEquation::createClone()
200 : throw (uno::RuntimeException, std::exception)
201 : {
202 0 : return uno::Reference< util::XCloneable >( new RegressionEquation( *this ));
203 : }
204 :
205 : // ____ OPropertySet ____
206 0 : uno::Any RegressionEquation::GetDefaultValue( sal_Int32 nHandle ) const
207 : throw(beans::UnknownPropertyException)
208 : {
209 0 : const tPropertyValueMap& rStaticDefaults = *StaticRegressionEquationDefaults::get();
210 0 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
211 0 : if( aFound == rStaticDefaults.end() )
212 0 : return uno::Any();
213 0 : return (*aFound).second;
214 : }
215 :
216 0 : ::cppu::IPropertyArrayHelper & SAL_CALL RegressionEquation::getInfoHelper()
217 : {
218 0 : return *StaticRegressionEquationInfoHelper::get();
219 : }
220 :
221 : // ____ XPropertySet ____
222 0 : Reference< beans::XPropertySetInfo > SAL_CALL RegressionEquation::getPropertySetInfo()
223 : throw (uno::RuntimeException, std::exception)
224 : {
225 0 : return *StaticRegressionEquationInfo::get();
226 : }
227 :
228 : // ____ XModifyBroadcaster ____
229 0 : void SAL_CALL RegressionEquation::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
230 : throw (uno::RuntimeException, std::exception)
231 : {
232 : try
233 : {
234 0 : uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
235 0 : xBroadcaster->addModifyListener( aListener );
236 : }
237 0 : catch( const uno::Exception & ex )
238 : {
239 : ASSERT_EXCEPTION( ex );
240 : }
241 0 : }
242 :
243 0 : void SAL_CALL RegressionEquation::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
244 : throw (uno::RuntimeException, std::exception)
245 : {
246 : try
247 : {
248 0 : uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
249 0 : xBroadcaster->removeModifyListener( aListener );
250 : }
251 0 : catch( const uno::Exception & ex )
252 : {
253 : ASSERT_EXCEPTION( ex );
254 : }
255 0 : }
256 :
257 : // ____ XModifyListener ____
258 0 : void SAL_CALL RegressionEquation::modified( const lang::EventObject& aEvent )
259 : throw (uno::RuntimeException, std::exception)
260 : {
261 0 : m_xModifyEventForwarder->modified( aEvent );
262 0 : }
263 :
264 : // ____ XEventListener (base of XModifyListener) ____
265 0 : void SAL_CALL RegressionEquation::disposing( const lang::EventObject& /* Source */ )
266 : throw (uno::RuntimeException, std::exception)
267 : {
268 : // nothing
269 0 : }
270 :
271 : // ____ OPropertySet ____
272 0 : void RegressionEquation::firePropertyChangeEvent()
273 : {
274 0 : fireModifyEvent();
275 0 : }
276 :
277 0 : void RegressionEquation::fireModifyEvent()
278 : {
279 0 : m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
280 0 : }
281 :
282 : // ____ XTitle ____
283 0 : uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL RegressionEquation::getText()
284 : throw (uno::RuntimeException, std::exception)
285 : {
286 0 : MutexGuard aGuard( GetMutex() );
287 0 : return m_aStrings;
288 : }
289 :
290 0 : void SAL_CALL RegressionEquation::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& Strings )
291 : throw (uno::RuntimeException, std::exception)
292 : {
293 0 : MutexGuard aGuard( GetMutex() );
294 : ModifyListenerHelper::removeListenerFromAllElements(
295 0 : ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
296 0 : m_aStrings = Strings;
297 : ModifyListenerHelper::addListenerToAllElements(
298 0 : ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
299 0 : fireModifyEvent();
300 0 : }
301 :
302 0 : uno::Sequence< OUString > RegressionEquation::getSupportedServiceNames_Static()
303 : {
304 0 : const sal_Int32 nNumServices( 5 );
305 0 : sal_Int32 nI = 0;
306 0 : uno::Sequence< OUString > aServices( nNumServices );
307 0 : aServices[ nI++ ] = lcl_aServiceName;
308 0 : aServices[ nI++ ] = "com.sun.star.beans.PropertySet";
309 0 : aServices[ nI++ ] = "com.sun.star.drawing.FillProperties";
310 0 : aServices[ nI++ ] = "com.sun.star.drawing.LineProperties";
311 0 : aServices[ nI++ ] = "com.sun.star.style.CharacterProperties";
312 : OSL_ASSERT( nNumServices == nI );
313 0 : return aServices;
314 : }
315 :
316 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
317 0 : APPHELPER_XSERVICEINFO_IMPL( RegressionEquation, lcl_aImplementationName );
318 :
319 : using impl::RegressionEquation_Base;
320 :
321 0 : IMPLEMENT_FORWARD_XINTERFACE2( RegressionEquation, RegressionEquation_Base, ::property::OPropertySet )
322 :
323 0 : } // namespace chart
324 :
325 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|