1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "ErrorBar.hxx"
31 #include "LineProperties.hxx"
32 #include "ContainerHelper.hxx"
33 #include "EventListenerHelper.hxx"
34 #include "PropertyHelper.hxx"
35 #include "CloneHelper.hxx"
37 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 #include <com/sun/star/chart/ErrorBarStyle.hpp>
40 #include <rtl/math.hxx>
41 #include <rtl/ustrbuf.hxx>
43 using namespace ::com::sun::star
;
45 using ::rtl::OUString
;
46 using ::rtl::OUStringBuffer
;
47 using ::com::sun::star::beans::Property
;
48 using ::osl::MutexGuard
;
52 static const OUString
lcl_aServiceName(
53 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ErrorBar" ));
58 PROP_ERROR_BAR_POS_ERROR
,
59 PROP_ERROR_BAR_NEG_ERROR
,
60 PROP_ERROR_BAR_WEIGHT
,
61 PROP_ERROR_BAR_SHOW_POS_ERROR
,
62 PROP_ERROR_BAR_SHOW_NEG_ERROR
65 void lcl_AddPropertiesToVector(
66 ::std::vector
< Property
> & rOutProperties
)
68 rOutProperties
.push_back(
69 Property( C2U( "ErrorBarStyle" ),
71 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
72 beans::PropertyAttribute::BOUND
73 | beans::PropertyAttribute::MAYBEDEFAULT
));
75 rOutProperties
.push_back(
76 Property( C2U( "PositiveError" ),
77 PROP_ERROR_BAR_POS_ERROR
,
78 ::getCppuType( reinterpret_cast< const double * >(0)),
79 beans::PropertyAttribute::BOUND
80 | beans::PropertyAttribute::MAYBEDEFAULT
));
81 rOutProperties
.push_back(
82 Property( C2U( "NegativeError" ),
83 PROP_ERROR_BAR_NEG_ERROR
,
84 ::getCppuType( reinterpret_cast< const double * >(0)),
85 beans::PropertyAttribute::BOUND
86 | beans::PropertyAttribute::MAYBEDEFAULT
));
88 rOutProperties
.push_back(
89 Property( C2U( "Weight" ),
90 PROP_ERROR_BAR_WEIGHT
,
91 ::getCppuType( reinterpret_cast< const double * >(0)),
92 beans::PropertyAttribute::BOUND
93 | beans::PropertyAttribute::MAYBEDEFAULT
));
95 rOutProperties
.push_back(
96 Property( C2U( "ShowPositiveError" ),
97 PROP_ERROR_BAR_SHOW_POS_ERROR
,
98 ::getBooleanCppuType(),
99 beans::PropertyAttribute::BOUND
100 | beans::PropertyAttribute::MAYBEDEFAULT
));
101 rOutProperties
.push_back(
102 Property( C2U( "ShowNegativeError" ),
103 PROP_ERROR_BAR_SHOW_NEG_ERROR
,
104 ::getBooleanCppuType(),
105 beans::PropertyAttribute::BOUND
106 | beans::PropertyAttribute::MAYBEDEFAULT
));
109 struct StaticErrorBarDefaults_Initializer
111 ::chart::tPropertyValueMap
* operator()()
113 static ::chart::tPropertyValueMap aStaticDefaults
;
114 lcl_AddDefaultsToMap( aStaticDefaults
);
115 return &aStaticDefaults
;
118 void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
120 ::chart::LineProperties::AddDefaultsToMap( rOutMap
);
122 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_ERROR_BAR_STYLE
, ::com::sun::star::chart::ErrorBarStyle::NONE
);
123 ::chart::PropertyHelper::setPropertyValueDefault
< double >( rOutMap
, PROP_ERROR_BAR_POS_ERROR
, 0.0 );
124 ::chart::PropertyHelper::setPropertyValueDefault
< double >( rOutMap
, PROP_ERROR_BAR_NEG_ERROR
, 0.0 );
125 ::chart::PropertyHelper::setPropertyValueDefault
< double >( rOutMap
, PROP_ERROR_BAR_WEIGHT
, 1.0 );
126 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_ERROR_BAR_SHOW_POS_ERROR
, true );
127 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_ERROR_BAR_SHOW_NEG_ERROR
, true );
131 struct StaticErrorBarDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticErrorBarDefaults_Initializer
>
135 struct StaticErrorBarInfoHelper_Initializer
137 ::cppu::OPropertyArrayHelper
* operator()()
139 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
144 uno::Sequence
< Property
> lcl_GetPropertySequence()
146 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
147 lcl_AddPropertiesToVector( aProperties
);
148 ::chart::LineProperties::AddPropertiesToVector( aProperties
);
150 ::std::sort( aProperties
.begin(), aProperties
.end(),
151 ::chart::PropertyNameLess() );
153 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
158 struct StaticErrorBarInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticErrorBarInfoHelper_Initializer
>
162 struct StaticErrorBarInfo_Initializer
164 uno::Reference
< beans::XPropertySetInfo
>* operator()()
166 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
167 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticErrorBarInfoHelper::get() ) );
168 return &xPropertySetInfo
;
172 struct StaticErrorBarInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticErrorBarInfo_Initializer
>
176 bool lcl_isInternalData( const uno::Reference
< chart2::data::XLabeledDataSequence
> & xLSeq
)
178 uno::Reference
< lang::XServiceInfo
> xServiceInfo( xLSeq
, uno::UNO_QUERY
);
179 return ( xServiceInfo
.is() && xServiceInfo
->getImplementationName() == "com.sun.star.comp.chart2.LabeledDataSequence" );
182 } // anonymous namespace
187 uno::Reference
< beans::XPropertySet
> createErrorBar( const uno::Reference
< uno::XComponentContext
> & xContext
)
189 return new ErrorBar( xContext
);
193 uno::Reference
< uno::XComponentContext
> const & xContext
) :
194 ::property::OPropertySet( m_aMutex
),
195 m_xContext( xContext
),
196 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
199 ErrorBar::ErrorBar( const ErrorBar
& rOther
) :
201 impl::ErrorBar_Base(),
202 ::property::OPropertySet( rOther
, m_aMutex
),
203 m_xContext( rOther
.m_xContext
),
204 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
206 if( ! rOther
.m_aDataSequences
.empty())
208 if( lcl_isInternalData( rOther
.m_aDataSequences
.front()))
209 CloneHelper::CloneRefVector
< tDataSequenceContainer::value_type
>(
210 rOther
.m_aDataSequences
, m_aDataSequences
);
212 m_aDataSequences
= rOther
.m_aDataSequences
;
213 ModifyListenerHelper::addListenerToAllElements( m_aDataSequences
, m_xModifyEventForwarder
);
217 ErrorBar::~ErrorBar()
220 uno::Reference
< util::XCloneable
> SAL_CALL
ErrorBar::createClone()
221 throw (uno::RuntimeException
)
223 return uno::Reference
< util::XCloneable
>( new ErrorBar( *this ));
226 // ================================================================================
228 // ____ OPropertySet ____
229 uno::Any
ErrorBar::GetDefaultValue( sal_Int32 nHandle
) const
230 throw(beans::UnknownPropertyException
)
232 const tPropertyValueMap
& rStaticDefaults
= *StaticErrorBarDefaults::get();
233 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
234 if( aFound
== rStaticDefaults
.end() )
236 return (*aFound
).second
;
239 ::cppu::IPropertyArrayHelper
& SAL_CALL
ErrorBar::getInfoHelper()
241 return *StaticErrorBarInfoHelper::get();
244 // ____ XPropertySet ____
245 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
ErrorBar::getPropertySetInfo()
246 throw (uno::RuntimeException
)
248 return *StaticErrorBarInfo::get();
251 // ____ XModifyBroadcaster ____
252 void SAL_CALL
ErrorBar::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
253 throw (uno::RuntimeException
)
257 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
258 xBroadcaster
->addModifyListener( aListener
);
260 catch( const uno::Exception
& ex
)
262 ASSERT_EXCEPTION( ex
);
266 void SAL_CALL
ErrorBar::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
267 throw (uno::RuntimeException
)
271 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
272 xBroadcaster
->removeModifyListener( aListener
);
274 catch( const uno::Exception
& ex
)
276 ASSERT_EXCEPTION( ex
);
280 // ____ XModifyListener ____
281 void SAL_CALL
ErrorBar::modified( const lang::EventObject
& aEvent
)
282 throw (uno::RuntimeException
)
284 m_xModifyEventForwarder
->modified( aEvent
);
287 // ____ XEventListener (base of XModifyListener) ____
288 void SAL_CALL
ErrorBar::disposing( const lang::EventObject
& /* Source */ )
289 throw (uno::RuntimeException
)
294 // ____ XDataSink ____
295 void SAL_CALL
ErrorBar::setData( const uno::Sequence
< uno::Reference
< chart2::data::XLabeledDataSequence
> >& aData
)
296 throw (uno::RuntimeException
)
298 ModifyListenerHelper::removeListenerFromAllElements( m_aDataSequences
, m_xModifyEventForwarder
);
299 EventListenerHelper::removeListenerFromAllElements( m_aDataSequences
, this );
300 m_aDataSequences
= ContainerHelper::SequenceToVector( aData
);
301 EventListenerHelper::addListenerToAllElements( m_aDataSequences
, this );
302 ModifyListenerHelper::addListenerToAllElements( m_aDataSequences
, m_xModifyEventForwarder
);
305 // ____ XDataSource ____
306 uno::Sequence
< uno::Reference
< chart2::data::XLabeledDataSequence
> > SAL_CALL
ErrorBar::getDataSequences()
307 throw (uno::RuntimeException
)
309 return ContainerHelper::ContainerToSequence( m_aDataSequences
);
313 uno::Reference
< uno::XInterface
> SAL_CALL
ErrorBar::getParent()
314 throw (uno::RuntimeException
)
319 void SAL_CALL
ErrorBar::setParent(
320 const uno::Reference
< uno::XInterface
>& Parent
)
321 throw (lang::NoSupportException
,
322 uno::RuntimeException
)
324 m_xParent
.set( Parent
);
327 // ____ OPropertySet ____
328 void ErrorBar::firePropertyChangeEvent()
333 void ErrorBar::fireModifyEvent()
335 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
338 // ================================================================================
340 uno::Sequence
< ::rtl::OUString
> ErrorBar::getSupportedServiceNames_Static()
342 uno::Sequence
< ::rtl::OUString
> aServices( 2 );
343 aServices
[ 0 ] = lcl_aServiceName
;
344 aServices
[ 1 ] = C2U( "com.sun.star.chart2.ErrorBar" );
348 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
349 APPHELPER_XSERVICEINFO_IMPL( ErrorBar
, lcl_aServiceName
);
351 // needed by MSC compiler
352 using impl::ErrorBar_Base
;
354 IMPLEMENT_FORWARD_XINTERFACE2( ErrorBar
, ErrorBar_Base
, OPropertySet
)
355 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ErrorBar
, ErrorBar_Base
, OPropertySet
)
359 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */