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