1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "ErrorBar.hxx"
32 #include "LineProperties.hxx"
33 #include "ContainerHelper.hxx"
34 #include "EventListenerHelper.hxx"
35 #include "PropertyHelper.hxx"
36 #include "CloneHelper.hxx"
38 #include <com/sun/star/beans/PropertyAttribute.hpp>
39 #include <com/sun/star/chart/ErrorBarStyle.hpp>
41 #include <rtl/math.hxx>
42 #include <rtl/ustrbuf.hxx>
44 using namespace ::com::sun::star
;
46 using ::rtl::OUString
;
47 using ::rtl::OUStringBuffer
;
48 using ::com::sun::star::beans::Property
;
49 using ::osl::MutexGuard
;
53 static const OUString
lcl_aServiceName(
54 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ErrorBar" ));
59 PROP_ERROR_BAR_POS_ERROR
,
60 PROP_ERROR_BAR_NEG_ERROR
,
61 PROP_ERROR_BAR_WEIGHT
,
62 PROP_ERROR_BAR_SHOW_POS_ERROR
,
63 PROP_ERROR_BAR_SHOW_NEG_ERROR
66 void lcl_AddPropertiesToVector(
67 ::std::vector
< Property
> & rOutProperties
)
69 rOutProperties
.push_back(
70 Property( C2U( "ErrorBarStyle" ),
72 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
73 beans::PropertyAttribute::BOUND
74 | beans::PropertyAttribute::MAYBEDEFAULT
));
76 rOutProperties
.push_back(
77 Property( C2U( "PositiveError" ),
78 PROP_ERROR_BAR_POS_ERROR
,
79 ::getCppuType( reinterpret_cast< const double * >(0)),
80 beans::PropertyAttribute::BOUND
81 | beans::PropertyAttribute::MAYBEDEFAULT
));
82 rOutProperties
.push_back(
83 Property( C2U( "NegativeError" ),
84 PROP_ERROR_BAR_NEG_ERROR
,
85 ::getCppuType( reinterpret_cast< const double * >(0)),
86 beans::PropertyAttribute::BOUND
87 | beans::PropertyAttribute::MAYBEDEFAULT
));
89 rOutProperties
.push_back(
90 Property( C2U( "Weight" ),
91 PROP_ERROR_BAR_WEIGHT
,
92 ::getCppuType( reinterpret_cast< const double * >(0)),
93 beans::PropertyAttribute::BOUND
94 | beans::PropertyAttribute::MAYBEDEFAULT
));
96 rOutProperties
.push_back(
97 Property( C2U( "ShowPositiveError" ),
98 PROP_ERROR_BAR_SHOW_POS_ERROR
,
99 ::getBooleanCppuType(),
100 beans::PropertyAttribute::BOUND
101 | beans::PropertyAttribute::MAYBEDEFAULT
));
102 rOutProperties
.push_back(
103 Property( C2U( "ShowNegativeError" ),
104 PROP_ERROR_BAR_SHOW_NEG_ERROR
,
105 ::getBooleanCppuType(),
106 beans::PropertyAttribute::BOUND
107 | beans::PropertyAttribute::MAYBEDEFAULT
));
110 void lcl_AddDefaultsToMap(
111 ::chart::tPropertyValueMap
& rOutMap
)
113 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_ERROR_BAR_STYLE
, ::com::sun::star::chart::ErrorBarStyle::NONE
);
114 ::chart::PropertyHelper::setPropertyValueDefault
< double >( rOutMap
, PROP_ERROR_BAR_POS_ERROR
, 0.0 );
115 ::chart::PropertyHelper::setPropertyValueDefault
< double >( rOutMap
, PROP_ERROR_BAR_NEG_ERROR
, 0.0 );
116 ::chart::PropertyHelper::setPropertyValueDefault
< double >( rOutMap
, PROP_ERROR_BAR_WEIGHT
, 1.0 );
117 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_ERROR_BAR_SHOW_POS_ERROR
, true );
118 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_ERROR_BAR_SHOW_NEG_ERROR
, true );
121 const uno::Sequence
< Property
> & lcl_GetPropertySequence()
123 static uno::Sequence
< Property
> aPropSeq
;
126 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
127 if( 0 == aPropSeq
.getLength() )
130 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
131 lcl_AddPropertiesToVector( aProperties
);
132 ::chart::LineProperties::AddPropertiesToVector( aProperties
);
134 // and sort them for access via bsearch
135 ::std::sort( aProperties
.begin(), aProperties
.end(),
136 ::chart::PropertyNameLess() );
138 // transfer result to static Sequence
139 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
145 ::cppu::IPropertyArrayHelper
& lcl_getInfoHelper()
147 static ::cppu::OPropertyArrayHelper
aArrayHelper(
148 lcl_GetPropertySequence(),
149 /* bSorted = */ sal_True
);
154 bool lcl_isInternalData( const uno::Reference
< chart2::data::XLabeledDataSequence
> & xLSeq
)
156 uno::Reference
< lang::XServiceInfo
> xServiceInfo( xLSeq
, uno::UNO_QUERY
);
157 return ( xServiceInfo
.is() && xServiceInfo
->getImplementationName().equalsAsciiL(
158 RTL_CONSTASCII_STRINGPARAM("com.sun.star.comp.chart2.LabeledDataSequence")));
161 } // anonymous namespace
166 uno::Reference
< beans::XPropertySet
> createErrorBar( const uno::Reference
< uno::XComponentContext
> & xContext
)
168 return new ErrorBar( xContext
);
172 uno::Reference
< uno::XComponentContext
> const & xContext
) :
173 ::property::OPropertySet( m_aMutex
),
174 m_xContext( xContext
),
175 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
178 ErrorBar::ErrorBar( const ErrorBar
& rOther
) :
180 impl::ErrorBar_Base(),
181 ::property::OPropertySet( rOther
, m_aMutex
),
182 m_xContext( rOther
.m_xContext
),
183 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
185 if( ! rOther
.m_aDataSequences
.empty())
187 if( lcl_isInternalData( rOther
.m_aDataSequences
.front()))
188 CloneHelper::CloneRefVector
< tDataSequenceContainer::value_type
>(
189 rOther
.m_aDataSequences
, m_aDataSequences
);
191 m_aDataSequences
= rOther
.m_aDataSequences
;
192 ModifyListenerHelper::addListenerToAllElements( m_aDataSequences
, m_xModifyEventForwarder
);
196 ErrorBar::~ErrorBar()
199 uno::Reference
< util::XCloneable
> SAL_CALL
ErrorBar::createClone()
200 throw (uno::RuntimeException
)
202 return uno::Reference
< util::XCloneable
>( new ErrorBar( *this ));
205 // ================================================================================
207 // ____ OPropertySet ____
208 uno::Any
ErrorBar::GetDefaultValue( sal_Int32 nHandle
) const
209 throw(beans::UnknownPropertyException
)
211 static tPropertyValueMap aStaticDefaults
;
214 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
215 if( 0 == aStaticDefaults
.size() )
217 // initialize defaults
218 lcl_AddDefaultsToMap( aStaticDefaults
);
219 LineProperties::AddDefaultsToMap( aStaticDefaults
);
222 tPropertyValueMap::const_iterator
aFound(
223 aStaticDefaults
.find( nHandle
));
225 if( aFound
== aStaticDefaults
.end())
228 return (*aFound
).second
;
232 ::cppu::IPropertyArrayHelper
& SAL_CALL
ErrorBar::getInfoHelper()
234 return lcl_getInfoHelper();
238 // ____ XPropertySet ____
239 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
240 ErrorBar::getPropertySetInfo()
241 throw (uno::RuntimeException
)
243 static uno::Reference
< beans::XPropertySetInfo
> xInfo
;
246 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
249 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
257 // ____ XModifyBroadcaster ____
258 void SAL_CALL
ErrorBar::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
259 throw (uno::RuntimeException
)
263 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
264 xBroadcaster
->addModifyListener( aListener
);
266 catch( const uno::Exception
& ex
)
268 ASSERT_EXCEPTION( ex
);
272 void SAL_CALL
ErrorBar::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
273 throw (uno::RuntimeException
)
277 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
278 xBroadcaster
->removeModifyListener( aListener
);
280 catch( const uno::Exception
& ex
)
282 ASSERT_EXCEPTION( ex
);
286 // ____ XModifyListener ____
287 void SAL_CALL
ErrorBar::modified( const lang::EventObject
& aEvent
)
288 throw (uno::RuntimeException
)
290 m_xModifyEventForwarder
->modified( aEvent
);
293 // ____ XEventListener (base of XModifyListener) ____
294 void SAL_CALL
ErrorBar::disposing( const lang::EventObject
& /* Source */ )
295 throw (uno::RuntimeException
)
300 // ____ XDataSink ____
301 void SAL_CALL
ErrorBar::setData( const uno::Sequence
< uno::Reference
< chart2::data::XLabeledDataSequence
> >& aData
)
302 throw (uno::RuntimeException
)
304 ModifyListenerHelper::removeListenerFromAllElements( m_aDataSequences
, m_xModifyEventForwarder
);
305 EventListenerHelper::removeListenerFromAllElements( m_aDataSequences
, this );
306 m_aDataSequences
= ContainerHelper::SequenceToVector( aData
);
307 EventListenerHelper::addListenerToAllElements( m_aDataSequences
, this );
308 ModifyListenerHelper::addListenerToAllElements( m_aDataSequences
, m_xModifyEventForwarder
);
311 // ____ XDataSource ____
312 uno::Sequence
< uno::Reference
< chart2::data::XLabeledDataSequence
> > SAL_CALL
ErrorBar::getDataSequences()
313 throw (uno::RuntimeException
)
315 return ContainerHelper::ContainerToSequence( m_aDataSequences
);
319 uno::Reference
< uno::XInterface
> SAL_CALL
ErrorBar::getParent()
320 throw (uno::RuntimeException
)
325 void SAL_CALL
ErrorBar::setParent(
326 const uno::Reference
< uno::XInterface
>& Parent
)
327 throw (lang::NoSupportException
,
328 uno::RuntimeException
)
330 m_xParent
.set( Parent
);
333 // ____ OPropertySet ____
334 void ErrorBar::firePropertyChangeEvent()
339 void ErrorBar::fireModifyEvent()
341 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
344 // ================================================================================
346 uno::Sequence
< ::rtl::OUString
> ErrorBar::getSupportedServiceNames_Static()
348 uno::Sequence
< ::rtl::OUString
> aServices( 2 );
349 aServices
[ 0 ] = lcl_aServiceName
;
350 aServices
[ 1 ] = C2U( "com.sun.star.chart2.ErrorBar" );
354 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
355 APPHELPER_XSERVICEINFO_IMPL( ErrorBar
, lcl_aServiceName
);
357 // needed by MSC compiler
358 using impl::ErrorBar_Base
;
360 IMPLEMENT_FORWARD_XINTERFACE2( ErrorBar
, ErrorBar_Base
, OPropertySet
)
361 IMPLEMENT_FORWARD_XTYPEPROVIDER2( ErrorBar
, ErrorBar_Base
, OPropertySet
)