office-gobmx/chart2/source/tools/ErrorBar.cxx
Sebastian Spaeth 63bb42ab7d Add vim/emacs modelines to all source files
Fixes #fdo30794
Based on bin/add-modelines script (originally posted in mail
1286706307.1871.1399280959@webmail.messagingengine.com)

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
2010-10-13 10:57:18 +02:00

366 lines
12 KiB
C++

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_chart2.hxx"
#include "ErrorBar.hxx"
#include "macros.hxx"
#include "LineProperties.hxx"
#include "ContainerHelper.hxx"
#include "EventListenerHelper.hxx"
#include "PropertyHelper.hxx"
#include "CloneHelper.hxx"
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <com/sun/star/chart/ErrorBarStyle.hpp>
#include <rtl/math.hxx>
#include <rtl/ustrbuf.hxx>
using namespace ::com::sun::star;
using ::rtl::OUString;
using ::rtl::OUStringBuffer;
using ::com::sun::star::beans::Property;
using ::osl::MutexGuard;
namespace
{
static const OUString lcl_aServiceName(
RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.ErrorBar" ));
enum
{
PROP_ERROR_BAR_STYLE,
PROP_ERROR_BAR_POS_ERROR,
PROP_ERROR_BAR_NEG_ERROR,
PROP_ERROR_BAR_WEIGHT,
PROP_ERROR_BAR_SHOW_POS_ERROR,
PROP_ERROR_BAR_SHOW_NEG_ERROR
};
void lcl_AddPropertiesToVector(
::std::vector< Property > & rOutProperties )
{
rOutProperties.push_back(
Property( C2U( "ErrorBarStyle" ),
PROP_ERROR_BAR_STYLE,
::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::MAYBEDEFAULT ));
rOutProperties.push_back(
Property( C2U( "PositiveError" ),
PROP_ERROR_BAR_POS_ERROR,
::getCppuType( reinterpret_cast< const double * >(0)),
beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::MAYBEDEFAULT ));
rOutProperties.push_back(
Property( C2U( "NegativeError" ),
PROP_ERROR_BAR_NEG_ERROR,
::getCppuType( reinterpret_cast< const double * >(0)),
beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::MAYBEDEFAULT ));
rOutProperties.push_back(
Property( C2U( "Weight" ),
PROP_ERROR_BAR_WEIGHT,
::getCppuType( reinterpret_cast< const double * >(0)),
beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::MAYBEDEFAULT ));
rOutProperties.push_back(
Property( C2U( "ShowPositiveError" ),
PROP_ERROR_BAR_SHOW_POS_ERROR,
::getBooleanCppuType(),
beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::MAYBEDEFAULT ));
rOutProperties.push_back(
Property( C2U( "ShowNegativeError" ),
PROP_ERROR_BAR_SHOW_NEG_ERROR,
::getBooleanCppuType(),
beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::MAYBEDEFAULT ));
}
void lcl_AddDefaultsToMap(
::chart::tPropertyValueMap & rOutMap )
{
::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_ERROR_BAR_STYLE, ::com::sun::star::chart::ErrorBarStyle::NONE );
::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_ERROR_BAR_POS_ERROR, 0.0 );
::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_ERROR_BAR_NEG_ERROR, 0.0 );
::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_ERROR_BAR_WEIGHT, 1.0 );
::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_ERROR_BAR_SHOW_POS_ERROR, true );
::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_ERROR_BAR_SHOW_NEG_ERROR, true );
}
const uno::Sequence< Property > & lcl_GetPropertySequence()
{
static uno::Sequence< Property > aPropSeq;
// /--
MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
if( 0 == aPropSeq.getLength() )
{
// get properties
::std::vector< ::com::sun::star::beans::Property > aProperties;
lcl_AddPropertiesToVector( aProperties );
::chart::LineProperties::AddPropertiesToVector( aProperties );
// and sort them for access via bsearch
::std::sort( aProperties.begin(), aProperties.end(),
::chart::PropertyNameLess() );
// transfer result to static Sequence
aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
}
return aPropSeq;
}
::cppu::IPropertyArrayHelper & lcl_getInfoHelper()
{
static ::cppu::OPropertyArrayHelper aArrayHelper(
lcl_GetPropertySequence(),
/* bSorted = */ sal_True );
return aArrayHelper;
}
bool lcl_isInternalData( const uno::Reference< chart2::data::XLabeledDataSequence > & xLSeq )
{
uno::Reference< lang::XServiceInfo > xServiceInfo( xLSeq, uno::UNO_QUERY );
return ( xServiceInfo.is() && xServiceInfo->getImplementationName().equalsAsciiL(
RTL_CONSTASCII_STRINGPARAM("com.sun.star.comp.chart2.LabeledDataSequence")));
}
} // anonymous namespace
namespace chart
{
uno::Reference< beans::XPropertySet > createErrorBar( const uno::Reference< uno::XComponentContext > & xContext )
{
return new ErrorBar( xContext );
}
ErrorBar::ErrorBar(
uno::Reference< uno::XComponentContext > const & xContext ) :
::property::OPropertySet( m_aMutex ),
m_xContext( xContext ),
m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
{}
ErrorBar::ErrorBar( const ErrorBar & rOther ) :
MutexContainer(),
impl::ErrorBar_Base(),
::property::OPropertySet( rOther, m_aMutex ),
m_xContext( rOther.m_xContext ),
m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
{
if( ! rOther.m_aDataSequences.empty())
{
if( lcl_isInternalData( rOther.m_aDataSequences.front()))
CloneHelper::CloneRefVector< tDataSequenceContainer::value_type >(
rOther.m_aDataSequences, m_aDataSequences );
else
m_aDataSequences = rOther.m_aDataSequences;
ModifyListenerHelper::addListenerToAllElements( m_aDataSequences, m_xModifyEventForwarder );
}
}
ErrorBar::~ErrorBar()
{}
uno::Reference< util::XCloneable > SAL_CALL ErrorBar::createClone()
throw (uno::RuntimeException)
{
return uno::Reference< util::XCloneable >( new ErrorBar( *this ));
}
// ================================================================================
// ____ OPropertySet ____
uno::Any ErrorBar::GetDefaultValue( sal_Int32 nHandle ) const
throw(beans::UnknownPropertyException)
{
static tPropertyValueMap aStaticDefaults;
// /--
::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
if( 0 == aStaticDefaults.size() )
{
// initialize defaults
lcl_AddDefaultsToMap( aStaticDefaults );
LineProperties::AddDefaultsToMap( aStaticDefaults );
}
tPropertyValueMap::const_iterator aFound(
aStaticDefaults.find( nHandle ));
if( aFound == aStaticDefaults.end())
return uno::Any();
return (*aFound).second;
// \--
}
::cppu::IPropertyArrayHelper & SAL_CALL ErrorBar::getInfoHelper()
{
return lcl_getInfoHelper();
}
// ____ XPropertySet ____
uno::Reference< beans::XPropertySetInfo > SAL_CALL
ErrorBar::getPropertySetInfo()
throw (uno::RuntimeException)
{
static uno::Reference< beans::XPropertySetInfo > xInfo;
// /--
MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
if( !xInfo.is())
{
xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
getInfoHelper());
}
return xInfo;
// \--
}
// ____ XModifyBroadcaster ____
void SAL_CALL ErrorBar::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
throw (uno::RuntimeException)
{
try
{
uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
xBroadcaster->addModifyListener( aListener );
}
catch( const uno::Exception & ex )
{
ASSERT_EXCEPTION( ex );
}
}
void SAL_CALL ErrorBar::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
throw (uno::RuntimeException)
{
try
{
uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
xBroadcaster->removeModifyListener( aListener );
}
catch( const uno::Exception & ex )
{
ASSERT_EXCEPTION( ex );
}
}
// ____ XModifyListener ____
void SAL_CALL ErrorBar::modified( const lang::EventObject& aEvent )
throw (uno::RuntimeException)
{
m_xModifyEventForwarder->modified( aEvent );
}
// ____ XEventListener (base of XModifyListener) ____
void SAL_CALL ErrorBar::disposing( const lang::EventObject& /* Source */ )
throw (uno::RuntimeException)
{
// nothing
}
// ____ XDataSink ____
void SAL_CALL ErrorBar::setData( const uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > >& aData )
throw (uno::RuntimeException)
{
ModifyListenerHelper::removeListenerFromAllElements( m_aDataSequences, m_xModifyEventForwarder );
EventListenerHelper::removeListenerFromAllElements( m_aDataSequences, this );
m_aDataSequences = ContainerHelper::SequenceToVector( aData );
EventListenerHelper::addListenerToAllElements( m_aDataSequences, this );
ModifyListenerHelper::addListenerToAllElements( m_aDataSequences, m_xModifyEventForwarder );
}
// ____ XDataSource ____
uno::Sequence< uno::Reference< chart2::data::XLabeledDataSequence > > SAL_CALL ErrorBar::getDataSequences()
throw (uno::RuntimeException)
{
return ContainerHelper::ContainerToSequence( m_aDataSequences );
}
// ____ XChild ____
uno::Reference< uno::XInterface > SAL_CALL ErrorBar::getParent()
throw (uno::RuntimeException)
{
return m_xParent;
}
void SAL_CALL ErrorBar::setParent(
const uno::Reference< uno::XInterface >& Parent )
throw (lang::NoSupportException,
uno::RuntimeException)
{
m_xParent.set( Parent );
}
// ____ OPropertySet ____
void ErrorBar::firePropertyChangeEvent()
{
fireModifyEvent();
}
void ErrorBar::fireModifyEvent()
{
m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
}
// ================================================================================
uno::Sequence< ::rtl::OUString > ErrorBar::getSupportedServiceNames_Static()
{
uno::Sequence< ::rtl::OUString > aServices( 2 );
aServices[ 0 ] = lcl_aServiceName;
aServices[ 1 ] = C2U( "com.sun.star.chart2.ErrorBar" );
return aServices;
}
// implement XServiceInfo methods basing upon getSupportedServiceNames_Static
APPHELPER_XSERVICEINFO_IMPL( ErrorBar, lcl_aServiceName );
// needed by MSC compiler
using impl::ErrorBar_Base;
IMPLEMENT_FORWARD_XINTERFACE2( ErrorBar, ErrorBar_Base, OPropertySet )
IMPLEMENT_FORWARD_XTYPEPROVIDER2( ErrorBar, ErrorBar_Base, OPropertySet )
} // namespace chart
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */