1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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 <ModifyListenerHelper.hxx>
27 #include <unonames.hxx>
28 #include <cppuhelper/supportsservice.hxx>
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 #include <tools/diagnose_ex.h>
40 namespace com
{ namespace sun
{ namespace star
{ namespace uno
{ class XComponentContext
; } } } }
42 using namespace ::com::sun::star
;
44 using ::com::sun::star::uno::Reference
;
45 using ::com::sun::star::beans::Property
;
46 using ::osl::MutexGuard
;
56 PROP_EQUATION_SHOW_CORRELATION_COEFF
,
57 PROP_EQUATION_REF_PAGE_SIZE
,
58 PROP_EQUATION_REL_POS
,
59 PROP_EQUATION_NUMBER_FORMAT
62 void lcl_AddPropertiesToVector(
63 std::vector
< Property
> & rOutProperties
)
65 rOutProperties
.emplace_back( "ShowEquation",
67 cppu::UnoType
<bool>::get(),
68 beans::PropertyAttribute::BOUND
69 | beans::PropertyAttribute::MAYBEDEFAULT
);
71 rOutProperties
.emplace_back( "XName",
73 cppu::UnoType
<OUString
>::get(),
74 beans::PropertyAttribute::BOUND
75 | beans::PropertyAttribute::MAYBEDEFAULT
);
77 rOutProperties
.emplace_back( "YName",
79 cppu::UnoType
<OUString
>::get(),
80 beans::PropertyAttribute::BOUND
81 | beans::PropertyAttribute::MAYBEDEFAULT
);
83 rOutProperties
.emplace_back( "ShowCorrelationCoefficient",
84 PROP_EQUATION_SHOW_CORRELATION_COEFF
,
85 cppu::UnoType
<bool>::get(),
86 beans::PropertyAttribute::BOUND
87 | beans::PropertyAttribute::MAYBEDEFAULT
);
89 rOutProperties
.emplace_back( "ReferencePageSize",
90 PROP_EQUATION_REF_PAGE_SIZE
,
91 cppu::UnoType
<awt::Size
>::get(),
92 beans::PropertyAttribute::BOUND
93 | beans::PropertyAttribute::MAYBEVOID
);
95 rOutProperties
.emplace_back( "RelativePosition",
96 PROP_EQUATION_REL_POS
,
97 cppu::UnoType
<chart2::RelativePosition
>::get(),
98 beans::PropertyAttribute::BOUND
99 | beans::PropertyAttribute::MAYBEVOID
);
101 rOutProperties
.emplace_back( CHART_UNONAME_NUMFMT
,
102 PROP_EQUATION_NUMBER_FORMAT
,
103 cppu::UnoType
<sal_Int32
>::get(),
104 beans::PropertyAttribute::BOUND
105 | beans::PropertyAttribute::MAYBEVOID
);
108 struct StaticRegressionEquationDefaults_Initializer
110 ::chart::tPropertyValueMap
* operator()()
112 static ::chart::tPropertyValueMap aStaticDefaults
;
113 lcl_AddDefaultsToMap( aStaticDefaults
);
114 return &aStaticDefaults
;
117 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
119 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap
);
120 ::chart::FillProperties::AddDefaultsToMap( rOutMap
);
121 ::chart::CharacterProperties::AddDefaultsToMap( rOutMap
);
123 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_EQUATION_SHOW
, false );
124 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_EQUATION_XNAME
, OUString("x") );
125 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_EQUATION_YNAME
, OUString("f(x)") );
126 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_EQUATION_SHOW_CORRELATION_COEFF
, false );
127 //::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_EQUATION_SEPARATOR, OUString( '\n' ));
129 // override other defaults
130 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::FillProperties::PROP_FILL_STYLE
, drawing::FillStyle_NONE
);
131 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::LinePropertiesHelper::PROP_LINE_STYLE
, drawing::LineStyle_NONE
);
133 float fDefaultCharHeight
= 10.0;
134 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT
, fDefaultCharHeight
);
135 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT
, fDefaultCharHeight
);
136 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT
, fDefaultCharHeight
);
140 struct StaticRegressionEquationDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticRegressionEquationDefaults_Initializer
>
144 struct StaticRegressionEquationInfoHelper_Initializer
146 ::cppu::OPropertyArrayHelper
* operator()()
148 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
153 static uno::Sequence
< Property
> lcl_GetPropertySequence()
155 std::vector
< css::beans::Property
> aProperties
;
156 lcl_AddPropertiesToVector( aProperties
);
157 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
158 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
159 ::chart::CharacterProperties::AddPropertiesToVector( aProperties
);
160 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties
);
162 std::sort( aProperties
.begin(), aProperties
.end(),
163 ::chart::PropertyNameLess() );
165 return comphelper::containerToSequence( aProperties
);
170 struct StaticRegressionEquationInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticRegressionEquationInfoHelper_Initializer
>
174 struct StaticRegressionEquationInfo_Initializer
176 uno::Reference
< beans::XPropertySetInfo
>* operator()()
178 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
179 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticRegressionEquationInfoHelper::get() ) );
180 return &xPropertySetInfo
;
184 struct StaticRegressionEquationInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticRegressionEquationInfo_Initializer
>
188 } // anonymous namespace
193 RegressionEquation::RegressionEquation() :
194 ::property::OPropertySet( m_aMutex
),
195 m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder())
198 RegressionEquation::RegressionEquation( const RegressionEquation
& rOther
) :
199 impl::RegressionEquation_Base(rOther
),
200 ::property::OPropertySet( rOther
, m_aMutex
),
201 m_xModifyEventForwarder( new ModifyListenerHelper::ModifyEventForwarder())
204 RegressionEquation::~RegressionEquation()
207 // ____ XCloneable ____
208 uno::Reference
< util::XCloneable
> SAL_CALL
RegressionEquation::createClone()
210 return uno::Reference
< util::XCloneable
>( new RegressionEquation( *this ));
213 // ____ OPropertySet ____
214 uno::Any
RegressionEquation::GetDefaultValue( sal_Int32 nHandle
) const
216 const tPropertyValueMap
& rStaticDefaults
= *StaticRegressionEquationDefaults::get();
217 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
218 if( aFound
== rStaticDefaults
.end() )
220 return (*aFound
).second
;
223 ::cppu::IPropertyArrayHelper
& SAL_CALL
RegressionEquation::getInfoHelper()
225 return *StaticRegressionEquationInfoHelper::get();
228 // ____ XPropertySet ____
229 Reference
< beans::XPropertySetInfo
> SAL_CALL
RegressionEquation::getPropertySetInfo()
231 return *StaticRegressionEquationInfo::get();
234 // ____ XModifyBroadcaster ____
235 void SAL_CALL
RegressionEquation::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
239 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
240 xBroadcaster
->addModifyListener( aListener
);
242 catch( const uno::Exception
& )
244 DBG_UNHANDLED_EXCEPTION("chart2");
248 void SAL_CALL
RegressionEquation::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
252 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
253 xBroadcaster
->removeModifyListener( aListener
);
255 catch( const uno::Exception
& )
257 DBG_UNHANDLED_EXCEPTION("chart2");
261 // ____ XModifyListener ____
262 void SAL_CALL
RegressionEquation::modified( const lang::EventObject
& aEvent
)
264 m_xModifyEventForwarder
->modified( aEvent
);
267 // ____ XEventListener (base of XModifyListener) ____
268 void SAL_CALL
RegressionEquation::disposing( const lang::EventObject
& /* Source */ )
273 // ____ OPropertySet ____
274 void RegressionEquation::firePropertyChangeEvent()
279 void RegressionEquation::fireModifyEvent()
281 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
285 uno::Sequence
< uno::Reference
< chart2::XFormattedString
> > SAL_CALL
RegressionEquation::getText()
287 MutexGuard
aGuard( m_aMutex
);
291 void SAL_CALL
RegressionEquation::setText( const uno::Sequence
< uno::Reference
< chart2::XFormattedString
> >& Strings
)
293 MutexGuard
aGuard( m_aMutex
);
294 ModifyListenerHelper::removeListenerFromAllElements(
295 comphelper::sequenceToContainer
<std::vector
<uno::Reference
< chart2::XFormattedString
> > >( m_aStrings
),
296 m_xModifyEventForwarder
);
297 m_aStrings
= Strings
;
298 ModifyListenerHelper::addListenerToAllElements(
299 comphelper::sequenceToContainer
<std::vector
<uno::Reference
< chart2::XFormattedString
> > >( m_aStrings
),
300 m_xModifyEventForwarder
);
304 OUString SAL_CALL
RegressionEquation::getImplementationName()
306 return "com.sun.star.comp.chart2.RegressionEquation";
309 sal_Bool SAL_CALL
RegressionEquation::supportsService( const OUString
& rServiceName
)
311 return cppu::supportsService(this, rServiceName
);
314 css::uno::Sequence
< OUString
> SAL_CALL
RegressionEquation::getSupportedServiceNames()
316 return { "com.sun.star.chart2.RegressionEquation",
317 "com.sun.star.beans.PropertySet",
318 "com.sun.star.drawing.FillProperties",
319 "com.sun.star.drawing.LineProperties",
320 "com.sun.star.style.CharacterProperties" };
323 using impl::RegressionEquation_Base
;
325 IMPLEMENT_FORWARD_XINTERFACE2( RegressionEquation
, RegressionEquation_Base
, ::property::OPropertySet
)
329 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
330 com_sun_star_comp_chart2_RegressionEquation_get_implementation(css::uno::XComponentContext
*,
331 css::uno::Sequence
<css::uno::Any
> const &)
333 return cppu::acquire(new ::chart::RegressionEquation
);
336 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */