1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ErrorBar.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "ErrorBar.hxx"
35 #include "LineProperties.hxx"
36 #include "ContainerHelper.hxx"
37 #include "EventListenerHelper.hxx"
38 #include "PropertyHelper.hxx"
39 #include "CloneHelper.hxx"
41 #include <com/sun/star/beans/PropertyAttribute.hpp>
42 #include <com/sun/star/chart/ErrorBarStyle.hpp>
44 #include <rtl/math.hxx>
45 #include <rtl/ustrbuf.hxx>
47 using namespace ::com::sun::star
;
49 using ::rtl::OUString
;
50 using ::rtl::OUStringBuffer
;
51 using ::com::sun::star::beans::Property
;
52 using ::osl::MutexGuard
;
56 static const OUString
lcl_aServiceName(
57 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ErrorBar" ));
62 PROP_ERROR_BAR_POS_ERROR
,
63 PROP_ERROR_BAR_NEG_ERROR
,
64 PROP_ERROR_BAR_WEIGHT
,
65 PROP_ERROR_BAR_SHOW_POS_ERROR
,
66 PROP_ERROR_BAR_SHOW_NEG_ERROR
69 void lcl_AddPropertiesToVector(
70 ::std::vector
< Property
> & rOutProperties
)
72 rOutProperties
.push_back(
73 Property( C2U( "ErrorBarStyle" ),
75 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
76 beans::PropertyAttribute::BOUND
77 | beans::PropertyAttribute::MAYBEDEFAULT
));
79 rOutProperties
.push_back(
80 Property( C2U( "PositiveError" ),
81 PROP_ERROR_BAR_POS_ERROR
,
82 ::getCppuType( reinterpret_cast< const double * >(0)),
83 beans::PropertyAttribute::BOUND
84 | beans::PropertyAttribute::MAYBEDEFAULT
));
85 rOutProperties
.push_back(
86 Property( C2U( "NegativeError" ),
87 PROP_ERROR_BAR_NEG_ERROR
,
88 ::getCppuType( reinterpret_cast< const double * >(0)),
89 beans::PropertyAttribute::BOUND
90 | beans::PropertyAttribute::MAYBEDEFAULT
));
92 rOutProperties
.push_back(
93 Property( C2U( "Weight" ),
94 PROP_ERROR_BAR_WEIGHT
,
95 ::getCppuType( reinterpret_cast< const double * >(0)),
96 beans::PropertyAttribute::BOUND
97 | beans::PropertyAttribute::MAYBEDEFAULT
));
99 rOutProperties
.push_back(
100 Property( C2U( "ShowPositiveError" ),
101 PROP_ERROR_BAR_SHOW_POS_ERROR
,
102 ::getBooleanCppuType(),
103 beans::PropertyAttribute::BOUND
104 | beans::PropertyAttribute::MAYBEDEFAULT
));
105 rOutProperties
.push_back(
106 Property( C2U( "ShowNegativeError" ),
107 PROP_ERROR_BAR_SHOW_NEG_ERROR
,
108 ::getBooleanCppuType(),
109 beans::PropertyAttribute::BOUND
110 | beans::PropertyAttribute::MAYBEDEFAULT
));
113 void lcl_AddDefaultsToMap(
114 ::chart::tPropertyValueMap
& rOutMap
)
116 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_ERROR_BAR_STYLE
, ::com::sun::star::chart::ErrorBarStyle::NONE
);
117 ::chart::PropertyHelper::setPropertyValueDefault
< double >( rOutMap
, PROP_ERROR_BAR_POS_ERROR
, 0.0 );
118 ::chart::PropertyHelper::setPropertyValueDefault
< double >( rOutMap
, PROP_ERROR_BAR_NEG_ERROR
, 0.0 );
119 ::chart::PropertyHelper::setPropertyValueDefault
< double >( rOutMap
, PROP_ERROR_BAR_WEIGHT
, 1.0 );
120 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_ERROR_BAR_SHOW_POS_ERROR
, true );
121 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_ERROR_BAR_SHOW_NEG_ERROR
, true );
124 const uno::Sequence
< Property
> & lcl_GetPropertySequence()
126 static uno::Sequence
< Property
> aPropSeq
;
129 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
130 if( 0 == aPropSeq
.getLength() )
133 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
134 lcl_AddPropertiesToVector( aProperties
);
135 ::chart::LineProperties::AddPropertiesToVector( aProperties
);
137 // and sort them for access via bsearch
138 ::std::sort( aProperties
.begin(), aProperties
.end(),
139 ::chart::PropertyNameLess() );
141 // transfer result to static Sequence
142 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
148 ::cppu::IPropertyArrayHelper
& lcl_getInfoHelper()
150 static ::cppu::OPropertyArrayHelper
aArrayHelper(
151 lcl_GetPropertySequence(),
152 /* bSorted = */ sal_True
);
157 bool lcl_isInternalData( const uno::Reference
< chart2::data::XLabeledDataSequence
> & xLSeq
)
159 uno::Reference
< lang::XServiceInfo
> xServiceInfo( xLSeq
, uno::UNO_QUERY
);
160 return ( xServiceInfo
.is() && xServiceInfo
->getImplementationName().equalsAsciiL(
161 RTL_CONSTASCII_STRINGPARAM("com.sun.star.comp.chart2.LabeledDataSequence")));
164 } // anonymous namespace
169 uno::Reference
< beans::XPropertySet
> createErrorBar( const uno::Reference
< uno::XComponentContext
> & xContext
)
171 return new ErrorBar( xContext
);
175 uno::Reference
< uno::XComponentContext
> const & xContext
) :
176 ::property::OPropertySet( m_aMutex
),
177 m_xContext( xContext
),
178 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
181 ErrorBar::ErrorBar( const ErrorBar
& rOther
) :
183 impl::ErrorBar_Base(),
184 ::property::OPropertySet( rOther
, m_aMutex
),
185 m_xContext( rOther
.m_xContext
),
186 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
188 if( ! rOther
.m_aDataSequences
.empty())
190 if( lcl_isInternalData( rOther
.m_aDataSequences
.front()))
191 CloneHelper::CloneRefVector
< tDataSequenceContainer::value_type
>(
192 rOther
.m_aDataSequences
, m_aDataSequences
);
194 m_aDataSequences
= rOther
.m_aDataSequences
;
195 ModifyListenerHelper::addListenerToAllElements( m_aDataSequences
, m_xModifyEventForwarder
);
199 ErrorBar::~ErrorBar()
202 uno::Reference
< util::XCloneable
> SAL_CALL
ErrorBar::createClone()
203 throw (uno::RuntimeException
)
205 return uno::Reference
< util::XCloneable
>( new ErrorBar( *this ));
208 // ================================================================================
210 // ____ OPropertySet ____
211 uno::Any
ErrorBar::GetDefaultValue( sal_Int32 nHandle
) const
212 throw(beans::UnknownPropertyException
)
214 static tPropertyValueMap aStaticDefaults
;
217 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
218 if( 0 == aStaticDefaults
.size() )
220 // initialize defaults
221 lcl_AddDefaultsToMap( aStaticDefaults
);
222 LineProperties::AddDefaultsToMap( aStaticDefaults
);
225 tPropertyValueMap::const_iterator
aFound(
226 aStaticDefaults
.find( nHandle
));
228 if( aFound
== aStaticDefaults
.end())
231 return (*aFound
).second
;
235 ::cppu::IPropertyArrayHelper
& SAL_CALL
ErrorBar::getInfoHelper()
237 return lcl_getInfoHelper();
241 // ____ XPropertySet ____
242 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
243 ErrorBar::getPropertySetInfo()
244 throw (uno::RuntimeException
)
246 static uno::Reference
< beans::XPropertySetInfo
> xInfo
;
249 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
252 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
260 // ____ XModifyBroadcaster ____
261 void SAL_CALL
ErrorBar::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
262 throw (uno::RuntimeException
)
266 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
267 xBroadcaster
->addModifyListener( aListener
);
269 catch( const uno::Exception
& ex
)
271 ASSERT_EXCEPTION( ex
);
275 void SAL_CALL
ErrorBar::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
276 throw (uno::RuntimeException
)
280 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
281 xBroadcaster
->removeModifyListener( aListener
);
283 catch( const uno::Exception
& ex
)
285 ASSERT_EXCEPTION( ex
);
289 // ____ XModifyListener ____
290 void SAL_CALL
ErrorBar::modified( const lang::EventObject
& aEvent
)
291 throw (uno::RuntimeException
)
293 m_xModifyEventForwarder
->modified( aEvent
);
296 // ____ XEventListener (base of XModifyListener) ____
297 void SAL_CALL
ErrorBar::disposing( const lang::EventObject
& /* Source */ )
298 throw (uno::RuntimeException
)
303 // ____ XDataSink ____
304 void SAL_CALL
ErrorBar::setData( const uno::Sequence
< uno::Reference
< chart2::data::XLabeledDataSequence
> >& aData
)
305 throw (uno::RuntimeException
)
307 ModifyListenerHelper::removeListenerFromAllElements( m_aDataSequences
, m_xModifyEventForwarder
);
308 EventListenerHelper::removeListenerFromAllElements( m_aDataSequences
, this );
309 m_aDataSequences
= ContainerHelper::SequenceToVector( aData
);
310 EventListenerHelper::addListenerToAllElements( m_aDataSequences
, this );
311 ModifyListenerHelper::addListenerToAllElements( m_aDataSequences
, m_xModifyEventForwarder
);
314 // ____ XDataSource ____
315 uno::Sequence
< uno::Reference
< chart2::data::XLabeledDataSequence
> > SAL_CALL
ErrorBar::getDataSequences()
316 throw (uno::RuntimeException
)
318 return ContainerHelper::ContainerToSequence( m_aDataSequences
);
322 uno::Reference
< uno::XInterface
> SAL_CALL
ErrorBar::getParent()
323 throw (uno::RuntimeException
)
328 void SAL_CALL
ErrorBar::setParent(
329 const uno::Reference
< uno::XInterface
>& Parent
)
330 throw (lang::NoSupportException
,
331 uno::RuntimeException
)
333 m_xParent
.set( Parent
);
336 // ____ OPropertySet ____
337 void ErrorBar::firePropertyChangeEvent()
342 void ErrorBar::fireModifyEvent()
344 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
347 // ================================================================================
349 uno::Sequence
< ::rtl::OUString
> ErrorBar::getSupportedServiceNames_Static()
351 uno::Sequence
< ::rtl::OUString
> aServices( 2 );
352 aServices
[ 0 ] = lcl_aServiceName
;
353 aServices
[ 1 ] = C2U( "com.sun.star.chart2.ErrorBar" );
357 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
358 APPHELPER_XSERVICEINFO_IMPL( ErrorBar
, lcl_aServiceName
);
360 // needed by MSC compiler
361 using impl::ErrorBar_Base
;
363 IMPLEMENT_FORWARD_XINTERFACE2( ErrorBar
, ErrorBar_Base
, OPropertySet
)
364 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ErrorBar
, ErrorBar_Base
, OPropertySet
)