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