diff options
Diffstat (limited to 'chart2/source/model/template')
55 files changed, 11937 insertions, 0 deletions
diff --git a/chart2/source/model/template/AreaChartType.cxx b/chart2/source/model/template/AreaChartType.cxx new file mode 100644 index 000000000000..5c9c9388ce25 --- /dev/null +++ b/chart2/source/model/template/AreaChartType.cxx @@ -0,0 +1,80 @@ +/* -*- 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 "AreaChartType.hxx" +#include "macros.hxx" +#include "servicenames_charttypes.hxx" + +using namespace ::com::sun::star; + +namespace chart +{ + +AreaChartType::AreaChartType( + const uno::Reference< uno::XComponentContext > & xContext ) : + ChartType( xContext ) +{} + +AreaChartType::AreaChartType( const AreaChartType & rOther ) : + ChartType( rOther ) +{} + +AreaChartType::~AreaChartType() +{} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL AreaChartType::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new AreaChartType( *this )); +} + +// ____ XChartType ____ +::rtl::OUString SAL_CALL AreaChartType::getChartType() + throw (uno::RuntimeException) +{ + return CHART2_SERVICE_NAME_CHARTTYPE_AREA; +} + +uno::Sequence< ::rtl::OUString > AreaChartType::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 2 ); + aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_AREA; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( AreaChartType, + C2U( "com.sun.star.comp.chart.AreaChartType" )); + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/AreaChartType.hxx b/chart2/source/model/template/AreaChartType.hxx new file mode 100644 index 000000000000..420a65855e5c --- /dev/null +++ b/chart2/source/model/template/AreaChartType.hxx @@ -0,0 +1,67 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_AREACHARTTYPE_HXX +#define CHART_AREACHARTTYPE_HXX + +#include "ChartType.hxx" +#include "ServiceMacros.hxx" + +namespace chart +{ + +class AreaChartType : public ChartType +{ +public: + AreaChartType( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~AreaChartType(); + + APPHELPER_XSERVICEINFO_DECL() + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( AreaChartType ) + +protected: + explicit AreaChartType( const AreaChartType & rOther ); + + // ____ XChartType ____ + virtual ::rtl::OUString SAL_CALL getChartType() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XCloneable ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() + throw (::com::sun::star::uno::RuntimeException); +}; + +} // namespace chart + +// CHART_AREACHARTTYPE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/AreaChartTypeTemplate.cxx b/chart2/source/model/template/AreaChartTypeTemplate.cxx new file mode 100644 index 000000000000..599e05f54dff --- /dev/null +++ b/chart2/source/model/template/AreaChartTypeTemplate.cxx @@ -0,0 +1,279 @@ +/* -*- 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 "AreaChartTypeTemplate.hxx" +#include "macros.hxx" +#include "servicenames_charttypes.hxx" +#include "DiagramHelper.hxx" +#include "DataSeriesHelper.hxx" +#include "ContainerHelper.hxx" +#include "PropertyHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> + +#include <algorithm> + +using namespace ::com::sun::star; + +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +namespace +{ + +static const ::rtl::OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.AreaChartTypeTemplate" )); + +enum +{ + PROP_AREA_TEMPLATE_DIMENSION +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "Dimension" ), + PROP_AREA_TEMPLATE_DIMENSION, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_AREA_TEMPLATE_DIMENSION, 2 ); +} + +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 ); + + // 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; +} + +} // anonymous namespace + +namespace chart +{ + +AreaChartTypeTemplate::AreaChartTypeTemplate( + uno::Reference< + uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName, + StackMode eStackMode, + sal_Int32 nDim /* = 2 */ ) : + ChartTypeTemplate( xContext, rServiceName ), + ::property::OPropertySet( m_aMutex ), + m_eStackMode( eStackMode ) +{ + setFastPropertyValue_NoBroadcast( PROP_AREA_TEMPLATE_DIMENSION, uno::makeAny( nDim )); +} + +AreaChartTypeTemplate::~AreaChartTypeTemplate() +{} + +// ____ OPropertySet ____ +uno::Any AreaChartTypeTemplate::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 ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; +} + +::cppu::IPropertyArrayHelper & SAL_CALL AreaChartTypeTemplate::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + AreaChartTypeTemplate::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; +} + +sal_Int32 AreaChartTypeTemplate::getDimension() const +{ + sal_Int32 nDim = 2; + try + { + // note: UNO-methods are never const + const_cast< AreaChartTypeTemplate * >( this )-> + getFastPropertyValue( PROP_AREA_TEMPLATE_DIMENSION ) >>= nDim; + } + catch( beans::UnknownPropertyException & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return nDim; +} + +StackMode AreaChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const +{ + return m_eStackMode; +} + +// ____ XChartTypeTemplate ____ +void SAL_CALL AreaChartTypeTemplate::applyStyle( + const Reference< chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (uno::RuntimeException) +{ + ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount ); + DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) ); +} + +void SAL_CALL AreaChartTypeTemplate::resetStyles( const Reference< chart2::XDiagram >& xDiagram ) + throw (uno::RuntimeException) +{ + ChartTypeTemplate::resetStyles( xDiagram ); + ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec( + DiagramHelper::getDataSeriesFromDiagram( xDiagram )); + uno::Any aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE )); + for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin()); + aIt != aSeriesVec.end(); ++aIt ) + { + Reference< beans::XPropertyState > xState( *aIt, uno::UNO_QUERY ); + Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY ); + if( xState.is() && + xProp.is() && + xProp->getPropertyValue( C2U("BorderStyle")) == aLineStyleAny ) + { + xState->setPropertyToDefault( C2U("BorderStyle")); + } + } +} + +Reference< chart2::XChartType > AreaChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ ) +{ + Reference< chart2::XChartType > xResult; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + xResult.set( xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_AREA ), uno::UNO_QUERY_THROW ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return xResult; +} + +Reference< chart2::XChartType > SAL_CALL AreaChartTypeTemplate::getChartTypeForNewSeries( + const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (uno::RuntimeException) +{ + Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) ); + ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult ); + return xResult; +} + + +// ---------------------------------------- + +uno::Sequence< ::rtl::OUString > AreaChartTypeTemplate::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 2 ); + aServices[ 0 ] = lcl_aServiceName; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( AreaChartTypeTemplate, lcl_aServiceName ); + +IMPLEMENT_FORWARD_XINTERFACE2( AreaChartTypeTemplate, ChartTypeTemplate, OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( AreaChartTypeTemplate, ChartTypeTemplate, OPropertySet ) + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/AreaChartTypeTemplate.hxx b/chart2/source/model/template/AreaChartTypeTemplate.hxx new file mode 100644 index 000000000000..ce9d250679da --- /dev/null +++ b/chart2/source/model/template/AreaChartTypeTemplate.hxx @@ -0,0 +1,106 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_AREACHARTTYPETEMPLATE_HXX +#define CHART_AREACHARTTYPETEMPLATE_HXX + +#include "ChartTypeTemplate.hxx" +#include "StackMode.hxx" + +#include "OPropertySet.hxx" +#include "MutexContainer.hxx" +#include <comphelper/uno3.hxx> + +namespace chart +{ + +class AreaChartTypeTemplate : + public MutexContainer, + public ChartTypeTemplate, + public ::property::OPropertySet +{ +public: + explicit AreaChartTypeTemplate( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName, + StackMode eStackMode, + sal_Int32 nDim = 2 ); + virtual ~AreaChartTypeTemplate(); + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XChartTypeTemplate ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > SAL_CALL + getChartTypeForNewSeries( const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL applyStyle( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeGroupIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL resetStyles( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ ChartTypeTemplate ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > + getChartTypeForIndex( sal_Int32 nChartTypeIndex ); + virtual sal_Int32 getDimension() const; + virtual StackMode getStackMode( sal_Int32 nChartTypeIndex ) const; + +private: + StackMode m_eStackMode; + sal_Int32 m_nDim; +}; + +} // namespace chart + +// CHART_AREACHARTTYPETEMPLATE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/BarChartType.cxx b/chart2/source/model/template/BarChartType.cxx new file mode 100644 index 000000000000..f955d7aac413 --- /dev/null +++ b/chart2/source/model/template/BarChartType.cxx @@ -0,0 +1,81 @@ +/* -*- 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 "BarChartType.hxx" +#include "macros.hxx" +#include "servicenames_charttypes.hxx" + +using namespace ::com::sun::star; + +namespace chart +{ + +BarChartType::BarChartType( + const uno::Reference< uno::XComponentContext > & xContext ) : + ChartType( xContext ) +{} + +BarChartType::BarChartType( const BarChartType & rOther ) : + ChartType( rOther ) +{ +} + +BarChartType::~BarChartType() +{} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL BarChartType::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new BarChartType( *this )); +} + +// ____ XChartType ____ +::rtl::OUString SAL_CALL BarChartType::getChartType() + throw (uno::RuntimeException) +{ + return CHART2_SERVICE_NAME_CHARTTYPE_BAR; +} + +uno::Sequence< ::rtl::OUString > BarChartType::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 2 ); + aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_BAR; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( BarChartType, + C2U( "com.sun.star.comp.chart.BarChartType" )); + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/BarChartType.hxx b/chart2/source/model/template/BarChartType.hxx new file mode 100644 index 000000000000..5a88b1a3c1e0 --- /dev/null +++ b/chart2/source/model/template/BarChartType.hxx @@ -0,0 +1,67 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_BARCHARTTYPE_HXX +#define CHART_BARCHARTTYPE_HXX + +#include "ChartType.hxx" +#include "ServiceMacros.hxx" + +namespace chart +{ + +class BarChartType : public ChartType +{ +public: + BarChartType( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~BarChartType(); + + APPHELPER_XSERVICEINFO_DECL() + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( BarChartType ) + +protected: + explicit BarChartType( const BarChartType & rOther ); + + // ____ XChartType ____ + virtual ::rtl::OUString SAL_CALL getChartType() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XCloneable ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() + throw (::com::sun::star::uno::RuntimeException); +}; + +} // namespace chart + +// CHART_BARCHARTTYPE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/BarChartTypeTemplate.cxx b/chart2/source/model/template/BarChartTypeTemplate.cxx new file mode 100644 index 000000000000..a40bc31d4123 --- /dev/null +++ b/chart2/source/model/template/BarChartTypeTemplate.cxx @@ -0,0 +1,351 @@ +/* -*- 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 "BarChartTypeTemplate.hxx" +#include "macros.hxx" +#include "DiagramHelper.hxx" +#include "servicenames_charttypes.hxx" +#include "ContainerHelper.hxx" +#include "DataSeriesHelper.hxx" +#include "PropertyHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> +#include <com/sun/star/chart2/DataPointGeometry3D.hpp> + +#include <algorithm> + +using namespace ::com::sun::star; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::beans::Property; +using ::osl::MutexGuard; +using ::rtl::OUString; + +namespace +{ + +static const OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.BarChartTypeTemplate" )); + +enum +{ + PROP_BAR_TEMPLATE_DIMENSION, + PROP_BAR_TEMPLATE_GEOMETRY3D +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "Dimension" ), + PROP_BAR_TEMPLATE_DIMENSION, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "Geometry3D" ), + PROP_BAR_TEMPLATE_GEOMETRY3D, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_BAR_TEMPLATE_DIMENSION, 2 ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_BAR_TEMPLATE_GEOMETRY3D, ::chart2::DataPointGeometry3D::CUBOID ); +} + +const Sequence< Property > & lcl_GetPropertySequence() +{ + static 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 ); + + // 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; +} + +} // anonymous namespace + +namespace chart +{ + +BarChartTypeTemplate::BarChartTypeTemplate( + Reference< + uno::XComponentContext > const & xContext, + const OUString & rServiceName, + StackMode eStackMode, + BarDirection eDirection, + sal_Int32 nDim /* = 2 */ ) : + ChartTypeTemplate( xContext, rServiceName ), + ::property::OPropertySet( m_aMutex ), + m_eStackMode( eStackMode ), + m_eBarDirection( eDirection ), + m_nDim( nDim ) +{} + +BarChartTypeTemplate::~BarChartTypeTemplate() +{} + +sal_Int32 BarChartTypeTemplate::getDimension() const +{ + return m_nDim; +} + +StackMode BarChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const +{ + return m_eStackMode; +} + +bool BarChartTypeTemplate::isSwapXAndY() const +{ + return (m_eBarDirection == HORIZONTAL); +} + +// ____ XChartTypeTemplate ____ +sal_Bool SAL_CALL BarChartTypeTemplate::matchesTemplate( + const Reference< chart2::XDiagram >& xDiagram, + sal_Bool bAdaptProperties ) + throw (uno::RuntimeException) +{ + sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties ); + + //check BarDirection + if( bResult ) + { + bool bFound = false; + bool bAmbiguous = false; + bool bVertical = DiagramHelper::getVertical( xDiagram, bFound, bAmbiguous ); + if( m_eBarDirection == HORIZONTAL ) + bResult = sal_Bool( bVertical ); + else if( m_eBarDirection == VERTICAL ) + bResult = sal_Bool( !bVertical ); + } + + // adapt solid-type of template according to values in series + if( bAdaptProperties && + bResult && + getDimension() == 3 ) + { + ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec( + DiagramHelper::getDataSeriesFromDiagram( xDiagram )); + + bool bGeomFound = false, bGeomAmbiguous = false; + sal_Int32 aCommonGeom = DiagramHelper::getGeometry3D( xDiagram, bGeomFound, bGeomAmbiguous ); + + if( !bGeomAmbiguous ) + { + setFastPropertyValue_NoBroadcast( + PROP_BAR_TEMPLATE_GEOMETRY3D, uno::makeAny( aCommonGeom )); + } + } + + return bResult; +} +Reference< chart2::XChartType > BarChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ ) +{ + Reference< chart2::XChartType > xResult; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + xResult.set( xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_COLUMN ), uno::UNO_QUERY_THROW ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return xResult; +} + +Reference< chart2::XChartType > SAL_CALL BarChartTypeTemplate::getChartTypeForNewSeries( + const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (uno::RuntimeException) +{ + Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) ); + ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult ); + return xResult; +} + + +// ____ OPropertySet ____ +uno::Any BarChartTypeTemplate::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 ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; +} + +::cppu::IPropertyArrayHelper & SAL_CALL BarChartTypeTemplate::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + + +// ____ XPropertySet ____ +Reference< beans::XPropertySetInfo > SAL_CALL + BarChartTypeTemplate::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static Reference< beans::XPropertySetInfo > xInfo; + + MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + getInfoHelper()); + } + + return xInfo; +} + +void SAL_CALL BarChartTypeTemplate::applyStyle( + const Reference< chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (uno::RuntimeException) +{ + ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount ); + DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) ); + if( getDimension() == 3 ) + { + try + { + //apply Geometry3D + uno::Any aAGeometry3D; + this->getFastPropertyValue( aAGeometry3D, PROP_BAR_TEMPLATE_GEOMETRY3D ); + DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "Geometry3D" ), aAGeometry3D ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } +} + +void SAL_CALL BarChartTypeTemplate::resetStyles( + const Reference< chart2::XDiagram >& xDiagram ) + throw (uno::RuntimeException) +{ + ChartTypeTemplate::resetStyles( xDiagram ); + ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec( + DiagramHelper::getDataSeriesFromDiagram( xDiagram )); + uno::Any aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE )); + for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin()); + aIt != aSeriesVec.end(); ++aIt ) + { + Reference< beans::XPropertyState > xState( *aIt, uno::UNO_QUERY ); + if( xState.is()) + { + if( getDimension() == 3 ) + xState->setPropertyToDefault( C2U("Geometry3D")); + Reference< beans::XPropertySet > xProp( xState, uno::UNO_QUERY ); + if( xProp.is() && + xProp->getPropertyValue( C2U("BorderStyle")) == aLineStyleAny ) + { + xState->setPropertyToDefault( C2U("BorderStyle")); + } + } + } + + DiagramHelper::setVertical( xDiagram, false ); +} + + +void BarChartTypeTemplate::createCoordinateSystems( + const Reference< chart2::XCoordinateSystemContainer > & xCooSysCnt ) +{ + ChartTypeTemplate::createCoordinateSystems( xCooSysCnt ); + + Reference< chart2::XDiagram > xDiagram( xCooSysCnt, uno::UNO_QUERY ); + DiagramHelper::setVertical( xDiagram, m_eBarDirection == HORIZONTAL ); +} + +// ---------------------------------------- + +Sequence< OUString > BarChartTypeTemplate::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 2 ); + aServices[ 0 ] = lcl_aServiceName; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( BarChartTypeTemplate, lcl_aServiceName ); + +IMPLEMENT_FORWARD_XINTERFACE2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( BarChartTypeTemplate, ChartTypeTemplate, OPropertySet ) + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/BarChartTypeTemplate.hxx b/chart2/source/model/template/BarChartTypeTemplate.hxx new file mode 100644 index 000000000000..5123cd78b664 --- /dev/null +++ b/chart2/source/model/template/BarChartTypeTemplate.hxx @@ -0,0 +1,124 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_BARCHARTTYPETEMPLATE_HXX +#define CHART_BARCHARTTYPETEMPLATE_HXX + +#include "OPropertySet.hxx" +#include "MutexContainer.hxx" +#include <comphelper/uno3.hxx> + +#include "ChartTypeTemplate.hxx" +#include "StackMode.hxx" + +namespace chart +{ + +class BarChartTypeTemplate : + public MutexContainer, + public ChartTypeTemplate, + public ::property::OPropertySet +{ +public: + enum BarDirection + { + HORIZONTAL, + VERTICAL + }; + + explicit BarChartTypeTemplate( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName, + StackMode eStackMode, + BarDirection eDirection, + sal_Int32 nDim = 2 ); + virtual ~BarChartTypeTemplate(); + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XChartTypeTemplate ____ + virtual sal_Bool SAL_CALL matchesTemplate( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDiagram >& xDiagram, + sal_Bool bAdaptProperties ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > SAL_CALL + getChartTypeForNewSeries( const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL applyStyle( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeGroupIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL resetStyles( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ ChartTypeTemplate ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > + getChartTypeForIndex( sal_Int32 nChartTypeIndex ); + virtual sal_Int32 getDimension() const; + virtual StackMode getStackMode( sal_Int32 nChartTypeIndex ) const; + virtual bool isSwapXAndY() const; + + virtual void createCoordinateSystems( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XCoordinateSystemContainer > & xCooSysCnt ); + +private: + StackMode m_eStackMode; + BarDirection m_eBarDirection; + sal_Int32 m_nDim; +}; + +} // namespace chart + +// CHART_BARCHARTTYPETEMPLATE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/BubbleChartType.cxx b/chart2/source/model/template/BubbleChartType.cxx new file mode 100644 index 000000000000..e863bb4d0a53 --- /dev/null +++ b/chart2/source/model/template/BubbleChartType.cxx @@ -0,0 +1,240 @@ +/* -*- 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 "BubbleChartType.hxx" +#include "PropertyHelper.hxx" +#include "macros.hxx" +#include "servicenames_charttypes.hxx" +#include "ContainerHelper.hxx" +#include "CartesianCoordinateSystem.hxx" +#include "AxisHelper.hxx" +#include "AxisIndexDefines.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/chart2/AxisType.hpp> +#include <com/sun/star/chart2/CurveStyle.hpp> + +using namespace ::com::sun::star; + +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +namespace +{ + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & /*rOutProperties*/ ) +{ +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & /*rOutMap*/ ) +{ +} + +const Sequence< Property > & lcl_GetPropertySequence() +{ + static Sequence< Property > aPropSeq; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aPropSeq.getLength() ) + { + // get properties + ::std::vector< ::com::sun::star::beans::Property > aProperties; + lcl_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; +} + +} // anonymous namespace + +namespace chart +{ + +BubbleChartType::BubbleChartType( + const uno::Reference< uno::XComponentContext > & xContext ) + : ChartType( xContext ) +{ +} + +BubbleChartType::BubbleChartType( const BubbleChartType & rOther ) : + ChartType( rOther ) +{ +} + +BubbleChartType::~BubbleChartType() +{} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL BubbleChartType::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new BubbleChartType( *this )); +} + +// ____ XChartType ____ +Reference< chart2::XCoordinateSystem > SAL_CALL + BubbleChartType::createCoordinateSystem( ::sal_Int32 DimensionCount ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + Reference< chart2::XCoordinateSystem > xResult( + new CartesianCoordinateSystem( + GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ sal_False )); + + for( sal_Int32 i=0; i<DimensionCount; ++i ) + { + Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) ); + if( !xAxis.is() ) + { + OSL_ENSURE(false,"a created coordinate system should have an axis for each dimension"); + continue; + } + + chart2::ScaleData aScaleData = xAxis->getScaleData(); + aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL; + aScaleData.Scaling = AxisHelper::createLinearScaling(); + + if( i == 2 ) + aScaleData.AxisType = chart2::AxisType::SERIES; + else + aScaleData.AxisType = chart2::AxisType::REALNUMBER; + + xAxis->setScaleData( aScaleData ); + } + + return xResult; +} + +::rtl::OUString SAL_CALL BubbleChartType::getChartType() + throw (uno::RuntimeException) +{ + return CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE; +} + +uno::Sequence< ::rtl::OUString > SAL_CALL BubbleChartType::getSupportedMandatoryRoles() + throw (uno::RuntimeException) +{ + static uno::Sequence< ::rtl::OUString > aMandRolesSeq; + + if( aMandRolesSeq.getLength() == 0 ) + { + aMandRolesSeq.realloc( 4 ); + aMandRolesSeq[0] = C2U( "label" ); + aMandRolesSeq[1] = C2U( "values-x" ); + aMandRolesSeq[2] = C2U( "values-y" ); + aMandRolesSeq[3] = C2U( "values-size" ); + } + + return aMandRolesSeq; +} + +OUString SAL_CALL BubbleChartType::getRoleOfSequenceForSeriesLabel() + throw (uno::RuntimeException) +{ + return C2U( "values-size" ); +} + +// ____ OPropertySet ____ +uno::Any BubbleChartType::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 ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; +} + +// ____ OPropertySet ____ +::cppu::IPropertyArrayHelper & SAL_CALL BubbleChartType::getInfoHelper() +{ + static ::cppu::OPropertyArrayHelper aArrayHelper( lcl_GetPropertySequence(), + /* bSorted = */ sal_True ); + + return aArrayHelper; +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + BubbleChartType::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + getInfoHelper()); + } + + return xInfo; +} + +uno::Sequence< ::rtl::OUString > BubbleChartType::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 3 ); + aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" ); + aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( BubbleChartType, + C2U( "com.sun.star.comp.chart.BubbleChartType" )); + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/BubbleChartType.hxx b/chart2/source/model/template/BubbleChartType.hxx new file mode 100644 index 000000000000..21d6b85cc45d --- /dev/null +++ b/chart2/source/model/template/BubbleChartType.hxx @@ -0,0 +1,89 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_BUBBLECHARTTYPE_HXX +#define CHART_BUBBLECHARTTYPE_HXX + +#include "ChartType.hxx" +#include "ServiceMacros.hxx" +#include <com/sun/star/chart2/CurveStyle.hpp> + +namespace chart +{ + +class BubbleChartType : public ChartType +{ +public: + BubbleChartType( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~BubbleChartType(); + + APPHELPER_XSERVICEINFO_DECL() + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( BubbleChartType ) + +protected: + explicit BubbleChartType( const BubbleChartType & rOther ); + + // ____ XChartType ____ + virtual ::rtl::OUString SAL_CALL getChartType() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedMandatoryRoles() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XCoordinateSystem > SAL_CALL + createCoordinateSystem( ::sal_Int32 DimensionCount ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getRoleOfSequenceForSeriesLabel() + throw (::com::sun::star::uno::RuntimeException); + + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + + // ____ OPropertySet ____ + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XCloneable ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() + throw (::com::sun::star::uno::RuntimeException); +}; + +} // namespace chart + +// CHART_BUBBLECHARTTYPE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/BubbleChartTypeTemplate.cxx b/chart2/source/model/template/BubbleChartTypeTemplate.cxx new file mode 100644 index 000000000000..6f8b41cbe9b9 --- /dev/null +++ b/chart2/source/model/template/BubbleChartTypeTemplate.cxx @@ -0,0 +1,312 @@ +/* -*- 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 "BubbleChartTypeTemplate.hxx" +#include "macros.hxx" +#include "BubbleDataInterpreter.hxx" +#include "CartesianCoordinateSystem.hxx" +#include "Scaling.hxx" +#include "DiagramHelper.hxx" +#include "servicenames_charttypes.hxx" +#include "ContainerHelper.hxx" +#include "DataSeriesHelper.hxx" +#include <com/sun/star/chart2/SymbolStyle.hpp> +#include <com/sun/star/chart2/Symbol.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> +#include "PropertyHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> + +#include <algorithm> + +using namespace ::com::sun::star; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +namespace +{ + +static const OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.BubbleChartTypeTemplate" )); + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & /*rOutProperties*/ ) +{ +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & /*rOutMap*/ ) +{ +} + +const Sequence< Property > & lcl_GetPropertySequence() +{ + static 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 ); + + // 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; +} + +} // anonymous namespace + +namespace chart +{ + +BubbleChartTypeTemplate::BubbleChartTypeTemplate( + Reference< + uno::XComponentContext > const & xContext, + const OUString & rServiceName ) : + ChartTypeTemplate( xContext, rServiceName ), + ::property::OPropertySet( m_aMutex ) +{ +} + +BubbleChartTypeTemplate::~BubbleChartTypeTemplate() +{} + +// ____ OPropertySet ____ +uno::Any BubbleChartTypeTemplate::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 ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; +} + +::cppu::IPropertyArrayHelper & SAL_CALL BubbleChartTypeTemplate::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + BubbleChartTypeTemplate::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; +} + +sal_Int32 BubbleChartTypeTemplate::getDimension() const +{ + return 2; +} + +StackMode BubbleChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const +{ + return StackMode_NONE; +} + +void SAL_CALL BubbleChartTypeTemplate::applyStyle( + const Reference< chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (uno::RuntimeException) +{ + ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount ); + DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) ); + + try + { + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +// ____ XChartTypeTemplate ____ +sal_Bool SAL_CALL BubbleChartTypeTemplate::supportsCategories() + throw (uno::RuntimeException) +{ + return false; +} + +sal_Bool SAL_CALL BubbleChartTypeTemplate::matchesTemplate( + const Reference< chart2::XDiagram >& xDiagram, + sal_Bool bAdaptProperties ) + throw (uno::RuntimeException) +{ + sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties ); + + if( bResult ) + { + ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec( + DiagramHelper::getDataSeriesFromDiagram( xDiagram )); + + for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt = + aSeriesVec.begin(); aIt != aSeriesVec.end(); ++aIt ) + { + try + { + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + } + + // adapt curve style, spline order and resolution + if( bResult && bAdaptProperties ) + { + try + { + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + return bResult; +} + +Reference< chart2::XChartType > BubbleChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ ) +{ + Reference< chart2::XChartType > xResult; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + xResult.set( xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE ), uno::UNO_QUERY_THROW ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return xResult; +} + +Reference< chart2::XChartType > SAL_CALL BubbleChartTypeTemplate::getChartTypeForNewSeries( + const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (uno::RuntimeException) +{ + Reference< chart2::XChartType > xResult; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + xResult.set( xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_BUBBLE ), uno::UNO_QUERY_THROW ); + + ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return xResult; +} + +Reference< chart2::XDataInterpreter > SAL_CALL BubbleChartTypeTemplate::getDataInterpreter() + throw (uno::RuntimeException) +{ + if( ! m_xDataInterpreter.is()) + m_xDataInterpreter.set( new BubbleDataInterpreter( GetComponentContext()) ); + + return m_xDataInterpreter; +} + +// ---------------------------------------- + +Sequence< OUString > BubbleChartTypeTemplate::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 2 ); + aServices[ 0 ] = lcl_aServiceName; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( BubbleChartTypeTemplate, lcl_aServiceName ); + +IMPLEMENT_FORWARD_XINTERFACE2( BubbleChartTypeTemplate, ChartTypeTemplate, OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( BubbleChartTypeTemplate, ChartTypeTemplate, OPropertySet ) + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/BubbleChartTypeTemplate.hxx b/chart2/source/model/template/BubbleChartTypeTemplate.hxx new file mode 100644 index 000000000000..ebe59de686bd --- /dev/null +++ b/chart2/source/model/template/BubbleChartTypeTemplate.hxx @@ -0,0 +1,104 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_BUBBLECHARTTYPETEMPLATE_HXX +#define CHART_BUBBLECHARTTYPETEMPLATE_HXX + +#include "ChartTypeTemplate.hxx" +#include "OPropertySet.hxx" +#include "MutexContainer.hxx" +#include <comphelper/uno3.hxx> + +namespace chart +{ + +class BubbleChartTypeTemplate : + public MutexContainer, + public ChartTypeTemplate, + public ::property::OPropertySet +{ +public: + explicit BubbleChartTypeTemplate( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName ); + virtual ~BubbleChartTypeTemplate(); + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XChartTypeTemplate ____ + virtual sal_Bool SAL_CALL supportsCategories() + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL matchesTemplate( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDiagram >& xDiagram, + sal_Bool bAdaptProperties ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > SAL_CALL + getChartTypeForNewSeries( const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataInterpreter > SAL_CALL getDataInterpreter() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL applyStyle( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeGroupIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ ChartTypeTemplate ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > + getChartTypeForIndex( sal_Int32 nChartTypeIndex ); + virtual sal_Int32 getDimension() const; + virtual StackMode getStackMode( sal_Int32 nChartTypeIndex ) const; +}; + +} // namespace chart + +// CHART_BUBBLECHARTTYPETEMPLATE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/BubbleDataInterpreter.cxx b/chart2/source/model/template/BubbleDataInterpreter.cxx new file mode 100644 index 000000000000..7741c4488f85 --- /dev/null +++ b/chart2/source/model/template/BubbleDataInterpreter.cxx @@ -0,0 +1,311 @@ +/* -*- 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 "BubbleDataInterpreter.hxx" +#include "DataSeries.hxx" +#include "macros.hxx" +#include "DataSeriesHelper.hxx" +#include "CommonConverters.hxx" +#include "ContainerHelper.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/chart2/data/XDataSink.hpp> +#include <com/sun/star/util/XCloneable.hpp> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; +using namespace ::std; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; + +namespace chart +{ + +BubbleDataInterpreter::BubbleDataInterpreter( + const uno::Reference< uno::XComponentContext > & xContext ) : + DataInterpreter( xContext ) +{ +} + +BubbleDataInterpreter::~BubbleDataInterpreter() +{ +} + +// ____ XDataInterpreter ____ +chart2::InterpretedData SAL_CALL BubbleDataInterpreter::interpretDataSource( + const Reference< chart2::data::XDataSource >& xSource, + const Sequence< beans::PropertyValue >& aArguments, + const Sequence< Reference< XDataSeries > >& aSeriesToReUse ) + throw (uno::RuntimeException) +{ + if( ! xSource.is()) + return InterpretedData(); + + Sequence< Reference< data::XLabeledDataSequence > > aData( xSource->getDataSequences() ); + + Reference< data::XLabeledDataSequence > xValuesX; + vector< Reference< data::XLabeledDataSequence > > aYValuesVector; + vector< Reference< data::XLabeledDataSequence > > aSizeValuesVector; + + Reference< data::XLabeledDataSequence > xCategories; + bool bHasCategories = HasCategories( aArguments, aData ); + + bool bHasXValues = false; + sal_Int32 nDataSeqCount = aData.getLength(); + + bHasXValues = bHasCategories ? ( (nDataSeqCount-1) > 2 && (nDataSeqCount-1) % 2 != 0 ) + :( nDataSeqCount > 2 && nDataSeqCount % 2 != 0 ); + + bool bCategoriesUsed = false; + bool bNextIsYValues = bHasCategories ? nDataSeqCount>2 : nDataSeqCount>1; + for( sal_Int32 nDataIdx = 0; nDataIdx < aData.getLength(); ++nDataIdx ) + { + try + { + if( bHasCategories && !bCategoriesUsed ) + { + xCategories.set( aData[nDataIdx] ); + if( xCategories.is()) + SetRole( xCategories->getValues(), C2U("categories")); + bCategoriesUsed = true; + } + else if( !xValuesX.is() && bHasXValues ) + { + xValuesX.set( aData[nDataIdx] ); + if( xValuesX.is()) + SetRole( xValuesX->getValues(), C2U("values-x")); + } + else if( bNextIsYValues ) + { + aYValuesVector.push_back( aData[nDataIdx] ); + if( aData[nDataIdx].is()) + SetRole( aData[nDataIdx]->getValues(), C2U("values-y")); + bNextIsYValues = false; + } + else if( !bNextIsYValues ) + { + aSizeValuesVector.push_back( aData[nDataIdx] ); + if( aData[nDataIdx].is()) + SetRole( aData[nDataIdx]->getValues(), C2U("values-size")); + bNextIsYValues = true; + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + // create DataSeries + sal_Int32 nSeriesIndex = 0; + vector< Reference< XDataSeries > > aSeriesVec; + aSeriesVec.reserve( aSizeValuesVector.size()); + + Reference< data::XLabeledDataSequence > xClonedXValues = xValuesX; + Reference< util::XCloneable > xCloneableX( xValuesX, uno::UNO_QUERY ); + + for( size_t nCount = 0; nCount < aSizeValuesVector.size(); ++nCount, ++nSeriesIndex ) + { + sal_Int32 nDataSequenceCount = 2; + if( xValuesX.is() ) + nDataSequenceCount = 3; + else if( aYValuesVector.empty() ) + nDataSequenceCount = 1; + + Sequence< Reference< data::XLabeledDataSequence > > aNewData( nDataSequenceCount ); + sal_Int32 nDataIndex = 0; + if( xValuesX.is() ) + { + if( nCount > 0 && xCloneableX.is() ) + xClonedXValues.set( xCloneableX->createClone(), uno::UNO_QUERY ); + aNewData[nDataIndex++] = xClonedXValues; + } + if( aYValuesVector.size() > nCount ) + aNewData[nDataIndex++] = aYValuesVector[nCount]; + if( aSizeValuesVector.size() > nCount ) + aNewData[nDataIndex++] = aSizeValuesVector[nCount]; + + Reference< XDataSeries > xSeries; + if( nSeriesIndex < aSeriesToReUse.getLength()) + xSeries.set( aSeriesToReUse[nSeriesIndex] ); + else + xSeries.set( new DataSeries( GetComponentContext() ) ); + OSL_ASSERT( xSeries.is() ); + Reference< data::XDataSink > xSink( xSeries, uno::UNO_QUERY ); + OSL_ASSERT( xSink.is() ); + xSink->setData( aNewData ); + + aSeriesVec.push_back( xSeries ); + } + + Sequence< Sequence< Reference< XDataSeries > > > aSeries(1); + aSeries[0] = ContainerHelper::ContainerToSequence( aSeriesVec ); + return InterpretedData( aSeries, xCategories ); +} + +chart2::InterpretedData SAL_CALL BubbleDataInterpreter::reinterpretDataSeries( + const chart2::InterpretedData& aInterpretedData ) + throw (uno::RuntimeException) +{ + InterpretedData aResult( aInterpretedData ); + + sal_Int32 i=0; + Sequence< Reference< XDataSeries > > aSeries( FlattenSequence( aInterpretedData.Series )); + const sal_Int32 nCount = aSeries.getLength(); + for( ; i<nCount; ++i ) + { + try + { + Reference< data::XDataSource > xSeriesSource( aSeries[i], uno::UNO_QUERY_THROW ); + Sequence< Reference< data::XLabeledDataSequence > > aNewSequences; + + Reference< data::XLabeledDataSequence > xValuesSize( + DataSeriesHelper::getDataSequenceByRole( xSeriesSource, C2U("values-size"), false )); + Reference< data::XLabeledDataSequence > xValuesY( + DataSeriesHelper::getDataSequenceByRole( xSeriesSource, C2U("values-y"), false )); + Reference< data::XLabeledDataSequence > xValuesX( + DataSeriesHelper::getDataSequenceByRole( xSeriesSource, C2U("values-x"), false )); + + if( ! xValuesX.is() || + ! xValuesY.is() || + ! xValuesSize.is() ) + { + vector< Reference< data::XLabeledDataSequence > > aValueSeqVec( + DataSeriesHelper::getAllDataSequencesByRole( + xSeriesSource->getDataSequences(), C2U("values"), true )); + if( xValuesX.is()) + aValueSeqVec.erase( find( aValueSeqVec.begin(), aValueSeqVec.end(), xValuesX )); + if( xValuesY.is()) + aValueSeqVec.erase( find( aValueSeqVec.begin(), aValueSeqVec.end(), xValuesY )); + if( xValuesSize.is()) + aValueSeqVec.erase( find( aValueSeqVec.begin(), aValueSeqVec.end(), xValuesSize )); + + size_t nIndex = 0; + + if( ! xValuesSize.is() && + aValueSeqVec.size() > nIndex ) + { + xValuesSize.set( aValueSeqVec[nIndex++] ); + if( xValuesSize.is()) + SetRole( xValuesSize->getValues(), C2U("values-size")); + } + + if( ! xValuesY.is() && + aValueSeqVec.size() > nIndex ) + { + xValuesY.set( aValueSeqVec[nIndex++] ); + if( xValuesY.is()) + SetRole( xValuesY->getValues(), C2U("values-y")); + } + + if( ! xValuesX.is() && + aValueSeqVec.size() > nIndex ) + { + xValuesX.set( aValueSeqVec[nIndex++] ); + if( xValuesX.is()) + SetRole( xValuesY->getValues(), C2U("values-x")); + } + } + if( xValuesSize.is()) + { + if( xValuesY.is() ) + { + if( xValuesX.is() ) + { + aNewSequences.realloc(3); + aNewSequences[0] = xValuesX; + aNewSequences[1] = xValuesY; + aNewSequences[2] = xValuesSize; + } + else + { + aNewSequences.realloc(2); + aNewSequences[0] = xValuesY; + aNewSequences[1] = xValuesSize; + } + } + else + { + aNewSequences.realloc(1); + aNewSequences[0] = xValuesSize; + } + } + + Sequence< Reference< data::XLabeledDataSequence > > aSeqs( xSeriesSource->getDataSequences()); + if( aSeqs.getLength() != aNewSequences.getLength() ) + { +#if OSL_DEBUG_LEVEL > 1 + sal_Int32 j=0; + for( ; j<aSeqs.getLength(); ++j ) + { + OSL_ENSURE( aSeqs[j] == xValuesY || aSeqs[j] == xValuesX || aSeqs[j] == xValuesSize, "All sequences should be used" ); + } +#endif + Reference< data::XDataSink > xSink( xSeriesSource, uno::UNO_QUERY_THROW ); + xSink->setData( aNewSequences ); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + return aResult; +} + +sal_Bool SAL_CALL BubbleDataInterpreter::isDataCompatible( + const chart2::InterpretedData& aInterpretedData ) + throw (uno::RuntimeException) +{ + Sequence< Reference< XDataSeries > > aSeries( FlattenSequence( aInterpretedData.Series )); + for( sal_Int32 i=0; i<aSeries.getLength(); ++i ) + { + try + { + Reference< data::XDataSource > xSrc( aSeries[i], uno::UNO_QUERY_THROW ); + Sequence< Reference< data::XLabeledDataSequence > > aSeq( xSrc->getDataSequences()); + if( aSeq.getLength() != 3 ) + return sal_False; + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + return sal_True; +} + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/BubbleDataInterpreter.hxx b/chart2/source/model/template/BubbleDataInterpreter.hxx new file mode 100644 index 000000000000..a34f9398cfce --- /dev/null +++ b/chart2/source/model/template/BubbleDataInterpreter.hxx @@ -0,0 +1,64 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_BUBBLEDATAINTERPRETER_HXX +#define CHART_BUBBLEDATAINTERPRETER_HXX + +#include "DataInterpreter.hxx" + +namespace chart +{ + +class BubbleDataInterpreter : public DataInterpreter +{ +public: + explicit BubbleDataInterpreter( + const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext ); + virtual ~BubbleDataInterpreter(); + +protected: + // ____ XDataInterpreter ____ + virtual ::com::sun::star::chart2::InterpretedData SAL_CALL interpretDataSource( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xSource, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments, + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >& aSeriesToReUse ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::chart2::InterpretedData SAL_CALL reinterpretDataSeries( + const ::com::sun::star::chart2::InterpretedData& aInterpretedData ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isDataCompatible( + const ::com::sun::star::chart2::InterpretedData& aInterpretedData ) + throw (::com::sun::star::uno::RuntimeException); +}; + +} // namespace chart + +// CHART_BUBBLEDATAINTERPRETER_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/CandleStickChartType.cxx b/chart2/source/model/template/CandleStickChartType.cxx new file mode 100644 index 000000000000..96ef8e94325e --- /dev/null +++ b/chart2/source/model/template/CandleStickChartType.cxx @@ -0,0 +1,353 @@ +/* -*- 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 "CandleStickChartType.hxx" +#include "PropertyHelper.hxx" +#include "macros.hxx" +#include "StockBar.hxx" +#include "servicenames_charttypes.hxx" +#include "ContainerHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> + +using namespace ::com::sun::star; + +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +namespace +{ + +enum +{ + PROP_CANDLESTICKCHARTTYPE_JAPANESE, + PROP_CANDLESTICKCHARTTYPE_WHITE_DAY, + PROP_CANDLESTICKCHARTTYPE_BLACK_DAY, + + PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST, + PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "Japanese" ), + PROP_CANDLESTICKCHARTTYPE_JAPANESE, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "WhiteDay" ), + PROP_CANDLESTICKCHARTTYPE_WHITE_DAY, + ::getCppuType( reinterpret_cast< Reference< beans::XPropertySet > *>(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + rOutProperties.push_back( + Property( C2U( "BlackDay" ), + PROP_CANDLESTICKCHARTTYPE_BLACK_DAY, + ::getCppuType( reinterpret_cast< Reference< beans::XPropertySet > *>(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "ShowFirst" ), + PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "ShowHighLow" ), + PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap, + ::osl::Mutex & rMutex ) +{ + ::osl::MutexGuard aGuard( rMutex ); + // must match default in CTOR! + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CANDLESTICKCHARTTYPE_JAPANESE, false ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST, false ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW, true ); +} + +const Sequence< Property > & lcl_GetPropertySequence() +{ + static Sequence< Property > aPropSeq; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aPropSeq.getLength() ) + { + // get properties + ::std::vector< ::com::sun::star::beans::Property > aProperties; + lcl_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; +} + +} // anonymous namespace + +namespace chart +{ + +CandleStickChartType::CandleStickChartType( + const uno::Reference< uno::XComponentContext > & xContext ) : + ChartType( xContext ) +{ + Reference< beans::XPropertySet > xWhiteDayProps( new ::chart::StockBar( true )); + Reference< beans::XPropertySet > xBlackDayProps( new ::chart::StockBar( false )); + + ModifyListenerHelper::addListener( xWhiteDayProps, m_xModifyEventForwarder ); + ModifyListenerHelper::addListener( xBlackDayProps, m_xModifyEventForwarder ); + + setFastPropertyValue_NoBroadcast( + PROP_CANDLESTICKCHARTTYPE_WHITE_DAY, uno::makeAny( xWhiteDayProps )); + setFastPropertyValue_NoBroadcast( + PROP_CANDLESTICKCHARTTYPE_BLACK_DAY, uno::makeAny( xBlackDayProps )); +} + +CandleStickChartType::CandleStickChartType( const CandleStickChartType & rOther ) : + ChartType( rOther ) +{ + Reference< beans::XPropertySet > xPropertySet; + uno::Any aValue; + + getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY ); + if( ( aValue >>= xPropertySet ) + && xPropertySet.is()) + ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder ); + + getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY ); + if( ( aValue >>= xPropertySet ) + && xPropertySet.is()) + ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder ); +} + +CandleStickChartType::~CandleStickChartType() +{ + try + { + Reference< beans::XPropertySet > xPropertySet; + uno::Any aValue; + + getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_WHITE_DAY ); + if( ( aValue >>= xPropertySet ) + && xPropertySet.is()) + ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder ); + + getFastPropertyValue( aValue, PROP_CANDLESTICKCHARTTYPE_BLACK_DAY ); + if( ( aValue >>= xPropertySet ) + && xPropertySet.is()) + ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder ); + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL CandleStickChartType::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new CandleStickChartType( *this )); +} + +// ____ XChartType ____ +::rtl::OUString SAL_CALL CandleStickChartType::getChartType() + throw (uno::RuntimeException) +{ + return CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK; +} + +uno::Sequence< ::rtl::OUString > SAL_CALL CandleStickChartType::getSupportedMandatoryRoles() + throw (uno::RuntimeException) +{ + bool bShowFirst = true; + bool bShowHiLow = false; + getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST ) >>= bShowFirst; + getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW ) >>= bShowHiLow; + + ::std::vector< OUString > aMandRoles; + + aMandRoles.push_back( C2U( "label" )); + if( bShowFirst ) + aMandRoles.push_back( C2U( "values-first" )); + + if( bShowHiLow ) + { + aMandRoles.push_back( C2U( "values-min" )); + aMandRoles.push_back( C2U( "values-max" )); + } + + aMandRoles.push_back( C2U( "values-last" )); + + return ContainerHelper::ContainerToSequence( aMandRoles ); +} + +Sequence< OUString > SAL_CALL CandleStickChartType::getSupportedOptionalRoles() + throw (uno::RuntimeException) +{ + bool bShowFirst = true; + bool bShowHiLow = false; + getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_FIRST ) >>= bShowFirst; + getFastPropertyValue( PROP_CANDLESTICKCHARTTYPE_SHOW_HIGH_LOW ) >>= bShowHiLow; + + ::std::vector< OUString > aOptRoles; + + if( ! bShowFirst ) + aOptRoles.push_back( C2U( "values-first" )); + + if( ! bShowHiLow ) + { + aOptRoles.push_back( C2U( "values-min" )); + aOptRoles.push_back( C2U( "values-max" )); + } + + return ContainerHelper::ContainerToSequence( aOptRoles ); +} + +OUString SAL_CALL CandleStickChartType::getRoleOfSequenceForSeriesLabel() + throw (uno::RuntimeException) +{ + return C2U( "values-last" ); +} + +// ____ OPropertySet ____ +uno::Any CandleStickChartType::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, GetMutex() ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; +} + +// ____ OPropertySet ____ +::cppu::IPropertyArrayHelper & SAL_CALL CandleStickChartType::getInfoHelper() +{ + static ::cppu::OPropertyArrayHelper aArrayHelper( lcl_GetPropertySequence(), + /* bSorted = */ sal_True ); + + return aArrayHelper; +} + + +// ____ XPropertySet ____ +Reference< beans::XPropertySetInfo > SAL_CALL + CandleStickChartType::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static Reference< beans::XPropertySetInfo > xInfo; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + getInfoHelper()); + } + + return xInfo; +} + +void SAL_CALL CandleStickChartType::setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, const uno::Any& rValue ) + throw (uno::Exception) +{ + if( nHandle == PROP_CANDLESTICKCHARTTYPE_WHITE_DAY + || nHandle == PROP_CANDLESTICKCHARTTYPE_BLACK_DAY ) + { + uno::Any aOldValue; + Reference< util::XModifyBroadcaster > xBroadcaster; + this->getFastPropertyValue( aOldValue, nHandle ); + if( aOldValue.hasValue() && + (aOldValue >>= xBroadcaster) && + xBroadcaster.is()) + { + ModifyListenerHelper::removeListener( xBroadcaster, m_xModifyEventForwarder ); + } + + OSL_ASSERT( rValue.getValueType().getTypeClass() == uno::TypeClass_INTERFACE ); + if( rValue.hasValue() && + (rValue >>= xBroadcaster) && + xBroadcaster.is()) + { + ModifyListenerHelper::addListener( xBroadcaster, m_xModifyEventForwarder ); + } + } + + ::property::OPropertySet::setFastPropertyValue_NoBroadcast( nHandle, rValue ); +} + +uno::Sequence< ::rtl::OUString > CandleStickChartType::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 3 ); + aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" ); + aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( CandleStickChartType, + C2U( "com.sun.star.comp.chart.CandleStickChartType" )); + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/CandleStickChartType.hxx b/chart2/source/model/template/CandleStickChartType.hxx new file mode 100644 index 000000000000..dd8843e4bbba --- /dev/null +++ b/chart2/source/model/template/CandleStickChartType.hxx @@ -0,0 +1,93 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_CANDLESTICKCHARTTYPE_HXX +#define CHART_CANDLESTICKCHARTTYPE_HXX + +#include "ChartType.hxx" +#include "ServiceMacros.hxx" + +namespace chart +{ + +class CandleStickChartType : public ChartType +{ +public: + CandleStickChartType( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~CandleStickChartType(); + + APPHELPER_XSERVICEINFO_DECL() + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( CandleStickChartType ) + +protected: + explicit CandleStickChartType( const CandleStickChartType & rOther ); + + // ____ XChartType ____ + virtual ::rtl::OUString SAL_CALL getChartType() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedMandatoryRoles() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedOptionalRoles() + throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getRoleOfSequenceForSeriesLabel() + throw (::com::sun::star::uno::RuntimeException); + + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + + // ____ OPropertySet ____ + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ OPropertySet ____ + virtual void SAL_CALL setFastPropertyValue_NoBroadcast + ( sal_Int32 nHandle, + const ::com::sun::star::uno::Any& rValue ) + throw (::com::sun::star::uno::Exception); + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XCloneable ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() + throw (::com::sun::star::uno::RuntimeException); +}; + +} // namespace chart + +// CHART_CANDLESTICKCHARTTYPE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/ChartType.cxx b/chart2/source/model/template/ChartType.cxx new file mode 100644 index 000000000000..547bf3c103f2 --- /dev/null +++ b/chart2/source/model/template/ChartType.cxx @@ -0,0 +1,320 @@ +/* -*- 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 "ChartType.hxx" +#include "PropertyHelper.hxx" +#include "CommonFunctors.hxx" +#include "macros.hxx" +#include "CartesianCoordinateSystem.hxx" +#include "AxisHelper.hxx" +#include "CloneHelper.hxx" +#include "AxisIndexDefines.hxx" +#include "ContainerHelper.hxx" +#include <com/sun/star/chart2/AxisType.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> + +using namespace ::com::sun::star; + +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +namespace chart +{ + +ChartType::ChartType( + const Reference< uno::XComponentContext > & xContext ) : + ::property::OPropertySet( m_aMutex ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()), + m_xContext( xContext ), + m_bNotifyChanges( true ) +{} + +ChartType::ChartType( const ChartType & rOther ) : + MutexContainer(), + impl::ChartType_Base(), + ::property::OPropertySet( rOther, m_aMutex ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()), + m_xContext( rOther.m_xContext ), + m_bNotifyChanges( true ) +{ + CloneHelper::CloneRefVector< Reference< chart2::XDataSeries > >( rOther.m_aDataSeries, m_aDataSeries ); + ModifyListenerHelper::addListenerToAllElements( m_aDataSeries, m_xModifyEventForwarder ); +} + +ChartType::~ChartType() +{ + ModifyListenerHelper::removeListenerFromAllElements( m_aDataSeries, m_xModifyEventForwarder ); + m_aDataSeries.clear(); +} + +Reference< uno::XComponentContext > ChartType::GetComponentContext() const +{ + return m_xContext; +} + +// ____ XChartType ____ +Reference< chart2::XCoordinateSystem > SAL_CALL + ChartType::createCoordinateSystem( ::sal_Int32 DimensionCount ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + Reference< chart2::XCoordinateSystem > xResult( + new CartesianCoordinateSystem( + GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ sal_False )); + + for( sal_Int32 i=0; i<DimensionCount; ++i ) + { + Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) ); + if( !xAxis.is() ) + { + OSL_ENSURE(false,"a created coordinate system should have an axis for each dimension"); + continue; + } + + chart2::ScaleData aScaleData = xAxis->getScaleData(); + aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL; + aScaleData.Scaling = AxisHelper::createLinearScaling(); + + switch( i ) + { + case 0: aScaleData.AxisType = chart2::AxisType::CATEGORY; break; + case 2: aScaleData.AxisType = chart2::AxisType::SERIES; break; + default: aScaleData.AxisType = chart2::AxisType::REALNUMBER; break; + } + + xAxis->setScaleData( aScaleData ); + } + + return xResult; +} + +Sequence< OUString > SAL_CALL ChartType::getSupportedMandatoryRoles() + throw (uno::RuntimeException) +{ + static Sequence< OUString > aDefaultSeq; + + if( aDefaultSeq.getLength() == 0 ) + { + aDefaultSeq.realloc( 2 ); + aDefaultSeq[0] = C2U( "label" ); + aDefaultSeq[1] = C2U( "values-y" ); + } + + return aDefaultSeq; +} + +Sequence< OUString > SAL_CALL ChartType::getSupportedOptionalRoles() + throw (uno::RuntimeException) +{ + static Sequence< OUString > aDefaultOptRolesSeq; + + return aDefaultOptRolesSeq; +} + +OUString SAL_CALL ChartType::getRoleOfSequenceForSeriesLabel() + throw (uno::RuntimeException) +{ + return C2U( "values-y" ); +} + +void ChartType::impl_addDataSeriesWithoutNotification( + const Reference< chart2::XDataSeries >& xDataSeries ) +{ + if( ::std::find( m_aDataSeries.begin(), m_aDataSeries.end(), xDataSeries ) + != m_aDataSeries.end()) + throw lang::IllegalArgumentException(); + + m_aDataSeries.push_back( xDataSeries ); + ModifyListenerHelper::addListener( xDataSeries, m_xModifyEventForwarder ); +} + +// ____ XDataSeriesContainer ____ +void SAL_CALL ChartType::addDataSeries( const Reference< chart2::XDataSeries >& xDataSeries ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + impl_addDataSeriesWithoutNotification( xDataSeries ); + fireModifyEvent(); +} + +void SAL_CALL ChartType::removeDataSeries( const Reference< chart2::XDataSeries >& xDataSeries ) + throw (container::NoSuchElementException, + uno::RuntimeException) +{ + if( !xDataSeries.is()) + throw container::NoSuchElementException(); + + tDataSeriesContainerType::iterator aIt( + ::std::find( m_aDataSeries.begin(), m_aDataSeries.end(), xDataSeries ) ); + + if( aIt == m_aDataSeries.end()) + throw container::NoSuchElementException( + C2U( "The given series is no element of this charttype" ), + static_cast< uno::XWeak * >( this )); + + ModifyListenerHelper::removeListener( xDataSeries, m_xModifyEventForwarder ); + m_aDataSeries.erase( aIt ); + fireModifyEvent(); +} + +Sequence< Reference< chart2::XDataSeries > > SAL_CALL ChartType::getDataSeries() + throw (uno::RuntimeException) +{ + return ContainerHelper::ContainerToSequence( m_aDataSeries ); +} + +void SAL_CALL ChartType::setDataSeries( const Sequence< Reference< chart2::XDataSeries > >& aDataSeries ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + m_bNotifyChanges = false; + try + { + Sequence< Reference< chart2::XDataSeries > > aOldSeries( this->getDataSeries() ); + for( sal_Int32 nN=0; nN<aOldSeries.getLength(); ++nN ) + ModifyListenerHelper::removeListener( aOldSeries[nN], m_xModifyEventForwarder ); + m_aDataSeries.clear(); + + for( sal_Int32 i=0; i<aDataSeries.getLength(); ++i ) + impl_addDataSeriesWithoutNotification( aDataSeries[i] ); + } + catch( ... ) + { + m_bNotifyChanges = true; + throw; + } + m_bNotifyChanges = true; + fireModifyEvent(); +} + +// ____ OPropertySet ____ +uno::Any ChartType::GetDefaultValue( sal_Int32 /* nHandle */ ) const + throw(beans::UnknownPropertyException) +{ + return uno::Any(); +} + +// ____ OPropertySet ____ +::cppu::IPropertyArrayHelper & SAL_CALL ChartType::getInfoHelper() +{ + // using assignment for broken gcc 3.3 + static ::cppu::OPropertyArrayHelper aArrayHelper = ::cppu::OPropertyArrayHelper( + Sequence< beans::Property >(), /* bSorted */ sal_True ); + + return aArrayHelper; +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + ChartType::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + getInfoHelper()); + } + + return xInfo; +} + +// ____ XModifyBroadcaster ____ +void SAL_CALL ChartType::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 ChartType::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 ChartType::modified( const lang::EventObject& aEvent ) + throw (uno::RuntimeException) +{ + m_xModifyEventForwarder->modified( aEvent ); +} + +// ____ XEventListener (base of XModifyListener) ____ +void SAL_CALL ChartType::disposing( const lang::EventObject& /* Source */ ) + throw (uno::RuntimeException) +{ + // nothing +} + +// ____ OPropertySet ____ +void ChartType::firePropertyChangeEvent() +{ + fireModifyEvent(); +} + +void ChartType::fireModifyEvent() +{ + if( m_bNotifyChanges ) + m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); +} + +// ================================================================================ + +using impl::ChartType_Base; + +IMPLEMENT_FORWARD_XINTERFACE2( ChartType, ChartType_Base, ::property::OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( ChartType, ChartType_Base, ::property::OPropertySet ) + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/ChartType.hxx b/chart2/source/model/template/ChartType.hxx new file mode 100644 index 000000000000..a2fd1c75f1b9 --- /dev/null +++ b/chart2/source/model/template/ChartType.hxx @@ -0,0 +1,174 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_CHARTTYPE_HXX +#define CHART_CHARTTYPE_HXX + +#include "MutexContainer.hxx" +#include "OPropertySet.hxx" +#include <cppuhelper/implbase5.hxx> +#include <comphelper/uno3.hxx> +#include "ServiceMacros.hxx" +#include "ModifyListenerHelper.hxx" +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/chart2/XChartType.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/chart2/XDataSeriesContainer.hpp> +#include <com/sun/star/util/XCloneable.hpp> + +#include <vector> + +namespace chart +{ + +namespace impl +{ +typedef ::cppu::WeakImplHelper5< + ::com::sun::star::chart2::XChartType, + ::com::sun::star::chart2::XDataSeriesContainer, + ::com::sun::star::util::XCloneable, + ::com::sun::star::util::XModifyBroadcaster, + ::com::sun::star::util::XModifyListener > + ChartType_Base; +} + +class ChartType : + public MutexContainer, + public impl::ChartType_Base, + public ::property::OPropertySet +{ +public: + explicit ChartType( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~ChartType(); + +protected: + explicit ChartType( const ChartType & rOther ); + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + GetComponentContext() const; + + // ____ XChartType ____ + // still abstract ! implement ! + virtual ::rtl::OUString SAL_CALL getChartType() + throw (::com::sun::star::uno::RuntimeException) = 0; + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XCoordinateSystem > SAL_CALL + createCoordinateSystem( ::sal_Int32 DimensionCount ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedMandatoryRoles() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedOptionalRoles() + throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getRoleOfSequenceForSeriesLabel() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XDataSeriesContainer ____ + virtual void SAL_CALL addDataSeries( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& aDataSeries ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeDataSeries( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& aDataSeries ) + throw (::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > > SAL_CALL getDataSeries() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDataSeries( + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >& aDataSeries ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + + // ____ XModifyBroadcaster ____ + virtual void SAL_CALL addModifyListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeModifyListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener >& aListener ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ XModifyListener ____ + virtual void SAL_CALL modified( + const ::com::sun::star::lang::EventObject& aEvent ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ XEventListener (base of XModifyListener) ____ + virtual void SAL_CALL disposing( + const ::com::sun::star::lang::EventObject& Source ) + throw (::com::sun::star::uno::RuntimeException); + + void fireModifyEvent(); + + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + virtual void firePropertyChangeEvent(); + using OPropertySet::disposing; + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xModifyEventForwarder; + +private: + void impl_addDataSeriesWithoutNotification( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDataSeries >& aDataSeries ); + +private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + m_xContext; + + typedef + ::std::vector< ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDataSeries > > + tDataSeriesContainerType; + + tDataSeriesContainerType m_aDataSeries; + + bool m_bNotifyChanges; +}; + +} // namespace chart + +// CHART_CHARTTYPE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/ChartTypeManager.cxx b/chart2/source/model/template/ChartTypeManager.cxx new file mode 100644 index 000000000000..4a866b2f0fa6 --- /dev/null +++ b/chart2/source/model/template/ChartTypeManager.cxx @@ -0,0 +1,622 @@ +/* -*- 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 "ChartTypeManager.hxx" +#include "macros.hxx" +#include "StackMode.hxx" +#include "ContainerHelper.hxx" + +#include "CartesianCoordinateSystem.hxx" + +#include "LineChartTypeTemplate.hxx" +#include "BarChartTypeTemplate.hxx" +#include "ColumnLineChartTypeTemplate.hxx" +#include "AreaChartTypeTemplate.hxx" +#include "PieChartTypeTemplate.hxx" +#include "ScatterChartTypeTemplate.hxx" +#include "StockChartTypeTemplate.hxx" +#include "NetChartTypeTemplate.hxx" +#include "BubbleChartTypeTemplate.hxx" +#include <cppuhelper/component_context.hxx> +#include <comphelper/InlineContainer.hxx> +#include <com/sun/star/container/XContentEnumerationAccess.hpp> +#include <com/sun/star/lang/XServiceName.hpp> +#include <com/sun/star/chart/ChartSolidType.hpp> +#include <com/sun/star/chart2/CurveStyle.hpp> + +#include <algorithm> +#include <iterator> +#include <functional> + +using namespace ::com::sun::star; + +using ::rtl::OUString; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +// ====================================================================== + +namespace +{ + +enum TemplateId +{ + TEMPLATE_SYMBOL, + TEMPLATE_STACKEDSYMBOL, + TEMPLATE_PERCENTSTACKEDSYMBOL, + TEMPLATE_LINE, + TEMPLATE_STACKEDLINE, + TEMPLATE_PERCENTSTACKEDLINE, + TEMPLATE_LINESYMBOL, + TEMPLATE_STACKEDLINESYMBOL, + TEMPLATE_PERCENTSTACKEDLINESYMBOL, + TEMPLATE_THREEDLINE, + TEMPLATE_STACKEDTHREEDLINE, + TEMPLATE_PERCENTSTACKEDTHREEDLINE, + TEMPLATE_THREEDLINEDEEP, + TEMPLATE_COLUMN, + TEMPLATE_STACKEDCOLUMN, + TEMPLATE_PERCENTSTACKEDCOLUMN, + TEMPLATE_BAR, + TEMPLATE_STACKEDBAR, + TEMPLATE_PERCENTSTACKEDBAR, + TEMPLATE_THREEDCOLUMNDEEP, + TEMPLATE_THREEDCOLUMNFLAT, + TEMPLATE_STACKEDTHREEDCOLUMNFLAT, + TEMPLATE_PERCENTSTACKEDTHREEDCOLUMNFLAT, + TEMPLATE_THREEDBARDEEP, + TEMPLATE_THREEDBARFLAT, + TEMPLATE_STACKEDTHREEDBARFLAT, + TEMPLATE_PERCENTSTACKEDTHREEDBARFLAT, + TEMPLATE_COLUMNWITHLINE, + TEMPLATE_STACKEDCOLUMNWITHLINE, + TEMPLATE_AREA, + TEMPLATE_STACKEDAREA, + TEMPLATE_PERCENTSTACKEDAREA, + TEMPLATE_THREEDAREA, + TEMPLATE_STACKEDTHREEDAREA, + TEMPLATE_PERCENTSTACKEDTHREEDAREA, + TEMPLATE_PIE, + TEMPLATE_PIEALLEXPLODED, + TEMPLATE_DONUT, + TEMPLATE_DONUTALLEXPLODED, + TEMPLATE_THREEDPIE, + TEMPLATE_THREEDPIEALLEXPLODED, + TEMPLATE_THREEDDONUT, + TEMPLATE_THREEDDONUTALLEXPLODED, + TEMPLATE_SCATTERLINESYMBOL, + TEMPLATE_SCATTERLINE, + TEMPLATE_SCATTERSYMBOL, + TEMPLATE_THREEDSCATTER, + TEMPLATE_NET, + TEMPLATE_NETSYMBOL, + TEMPLATE_NETLINE, + TEMPLATE_STACKEDNET, + TEMPLATE_STACKEDNETSYMBOL, + TEMPLATE_STACKEDNETLINE, + TEMPLATE_PERCENTSTACKEDNET, + TEMPLATE_PERCENTSTACKEDNETSYMBOL, + TEMPLATE_PERCENTSTACKEDNETLINE, + TEMPLATE_FILLEDNET, + TEMPLATE_STACKEDFILLEDNET, + TEMPLATE_PERCENTSTACKEDFILLEDNET, + TEMPLATE_STOCKLOWHIGHCLOSE, + TEMPLATE_STOCKOPENLOWHIGHCLOSE, + TEMPLATE_STOCKVOLUMELOWHIGHCLOSE, + TEMPLATE_STOCKVOLUMEOPENLOWHIGHCLOSE, + TEMPLATE_BUBBLE, +// TEMPLATE_SURFACE, +// TEMPLATE_ADDIN, + TEMPLATE_NOT_FOUND = 0xffff +}; + +typedef ::std::map< OUString, TemplateId > tTemplateMapType; + +const tTemplateMapType & lcl_DefaultChartTypeMap() +{ + static const tTemplateMapType aMap = tTemplateMapType( + ::comphelper::MakeMap< tTemplateMapType::key_type, tTemplateMapType::mapped_type > + ( C2U( "com.sun.star.chart2.template.Symbol" ), TEMPLATE_SYMBOL ) + ( C2U( "com.sun.star.chart2.template.StackedSymbol" ), TEMPLATE_STACKEDSYMBOL ) + ( C2U( "com.sun.star.chart2.template.PercentStackedSymbol" ), TEMPLATE_PERCENTSTACKEDSYMBOL ) + ( C2U( "com.sun.star.chart2.template.Line" ), TEMPLATE_LINE ) + ( C2U( "com.sun.star.chart2.template.StackedLine" ), TEMPLATE_STACKEDLINE ) + ( C2U( "com.sun.star.chart2.template.PercentStackedLine" ), TEMPLATE_PERCENTSTACKEDLINE ) + ( C2U( "com.sun.star.chart2.template.LineSymbol" ), TEMPLATE_LINESYMBOL ) + ( C2U( "com.sun.star.chart2.template.StackedLineSymbol" ), TEMPLATE_STACKEDLINESYMBOL ) + ( C2U( "com.sun.star.chart2.template.PercentStackedLineSymbol" ), TEMPLATE_PERCENTSTACKEDLINESYMBOL ) + ( C2U( "com.sun.star.chart2.template.ThreeDLine" ), TEMPLATE_THREEDLINE ) + ( C2U( "com.sun.star.chart2.template.StackedThreeDLine" ), TEMPLATE_STACKEDTHREEDLINE ) + ( C2U( "com.sun.star.chart2.template.PercentStackedThreeDLine" ), TEMPLATE_PERCENTSTACKEDTHREEDLINE ) + ( C2U( "com.sun.star.chart2.template.ThreeDLineDeep" ), TEMPLATE_THREEDLINEDEEP ) + ( C2U( "com.sun.star.chart2.template.Column" ), TEMPLATE_COLUMN ) + ( C2U( "com.sun.star.chart2.template.StackedColumn" ), TEMPLATE_STACKEDCOLUMN ) + ( C2U( "com.sun.star.chart2.template.PercentStackedColumn" ), TEMPLATE_PERCENTSTACKEDCOLUMN ) + ( C2U( "com.sun.star.chart2.template.Bar" ), TEMPLATE_BAR ) + ( C2U( "com.sun.star.chart2.template.StackedBar" ), TEMPLATE_STACKEDBAR ) + ( C2U( "com.sun.star.chart2.template.PercentStackedBar" ), TEMPLATE_PERCENTSTACKEDBAR ) + ( C2U( "com.sun.star.chart2.template.ThreeDColumnDeep" ), TEMPLATE_THREEDCOLUMNDEEP ) + ( C2U( "com.sun.star.chart2.template.ThreeDColumnFlat" ), TEMPLATE_THREEDCOLUMNFLAT ) + ( C2U( "com.sun.star.chart2.template.StackedThreeDColumnFlat" ), TEMPLATE_STACKEDTHREEDCOLUMNFLAT ) + ( C2U( "com.sun.star.chart2.template.PercentStackedThreeDColumnFlat" ), TEMPLATE_PERCENTSTACKEDTHREEDCOLUMNFLAT ) + ( C2U( "com.sun.star.chart2.template.ThreeDBarDeep" ), TEMPLATE_THREEDBARDEEP ) + ( C2U( "com.sun.star.chart2.template.ThreeDBarFlat" ), TEMPLATE_THREEDBARFLAT ) + ( C2U( "com.sun.star.chart2.template.StackedThreeDBarFlat" ), TEMPLATE_STACKEDTHREEDBARFLAT ) + ( C2U( "com.sun.star.chart2.template.PercentStackedThreeDBarFlat" ), TEMPLATE_PERCENTSTACKEDTHREEDBARFLAT ) + ( C2U( "com.sun.star.chart2.template.ColumnWithLine" ), TEMPLATE_COLUMNWITHLINE ) + ( C2U( "com.sun.star.chart2.template.StackedColumnWithLine" ), TEMPLATE_STACKEDCOLUMNWITHLINE ) + ( C2U( "com.sun.star.chart2.template.Area" ), TEMPLATE_AREA ) + ( C2U( "com.sun.star.chart2.template.StackedArea" ), TEMPLATE_STACKEDAREA ) + ( C2U( "com.sun.star.chart2.template.PercentStackedArea" ), TEMPLATE_PERCENTSTACKEDAREA ) + ( C2U( "com.sun.star.chart2.template.ThreeDArea" ), TEMPLATE_THREEDAREA ) + ( C2U( "com.sun.star.chart2.template.StackedThreeDArea" ), TEMPLATE_STACKEDTHREEDAREA ) + ( C2U( "com.sun.star.chart2.template.PercentStackedThreeDArea" ), TEMPLATE_PERCENTSTACKEDTHREEDAREA ) + ( C2U( "com.sun.star.chart2.template.Pie" ), TEMPLATE_PIE ) + ( C2U( "com.sun.star.chart2.template.PieAllExploded" ), TEMPLATE_PIEALLEXPLODED ) + ( C2U( "com.sun.star.chart2.template.Donut" ), TEMPLATE_DONUT ) + ( C2U( "com.sun.star.chart2.template.DonutAllExploded" ), TEMPLATE_DONUTALLEXPLODED ) + ( C2U( "com.sun.star.chart2.template.ThreeDPie" ), TEMPLATE_THREEDPIE ) + ( C2U( "com.sun.star.chart2.template.ThreeDPieAllExploded" ), TEMPLATE_THREEDPIEALLEXPLODED ) + ( C2U( "com.sun.star.chart2.template.ThreeDDonut" ), TEMPLATE_THREEDDONUT ) + ( C2U( "com.sun.star.chart2.template.ThreeDDonutAllExploded" ), TEMPLATE_THREEDDONUTALLEXPLODED ) + ( C2U( "com.sun.star.chart2.template.ScatterLineSymbol" ), TEMPLATE_SCATTERLINESYMBOL ) + ( C2U( "com.sun.star.chart2.template.ScatterLine" ), TEMPLATE_SCATTERLINE ) + ( C2U( "com.sun.star.chart2.template.ScatterSymbol" ), TEMPLATE_SCATTERSYMBOL ) + ( C2U( "com.sun.star.chart2.template.ThreeDScatter" ), TEMPLATE_THREEDSCATTER ) + ( C2U( "com.sun.star.chart2.template.Net" ), TEMPLATE_NET ) + ( C2U( "com.sun.star.chart2.template.NetSymbol" ), TEMPLATE_NETSYMBOL ) + ( C2U( "com.sun.star.chart2.template.NetLine" ), TEMPLATE_NETLINE ) + ( C2U( "com.sun.star.chart2.template.StackedNet" ), TEMPLATE_STACKEDNET ) + ( C2U( "com.sun.star.chart2.template.StackedNetSymbol" ), TEMPLATE_STACKEDNETSYMBOL ) + ( C2U( "com.sun.star.chart2.template.StackedNetLine" ), TEMPLATE_STACKEDNETLINE ) + ( C2U( "com.sun.star.chart2.template.PercentStackedNet" ), TEMPLATE_PERCENTSTACKEDNET ) + ( C2U( "com.sun.star.chart2.template.PercentStackedNetSymbol" ), TEMPLATE_PERCENTSTACKEDNETSYMBOL ) + ( C2U( "com.sun.star.chart2.template.PercentStackedNetLine" ), TEMPLATE_PERCENTSTACKEDNETLINE ) + ( C2U( "com.sun.star.chart2.template.FilledNet" ), TEMPLATE_FILLEDNET ) + ( C2U( "com.sun.star.chart2.template.StackedFilledNet" ), TEMPLATE_STACKEDFILLEDNET ) + ( C2U( "com.sun.star.chart2.template.PercentStackedFilledNet" ), TEMPLATE_PERCENTSTACKEDFILLEDNET ) + ( C2U( "com.sun.star.chart2.template.StockLowHighClose" ), TEMPLATE_STOCKLOWHIGHCLOSE ) + ( C2U( "com.sun.star.chart2.template.StockOpenLowHighClose" ), TEMPLATE_STOCKOPENLOWHIGHCLOSE ) + ( C2U( "com.sun.star.chart2.template.StockVolumeLowHighClose" ), TEMPLATE_STOCKVOLUMELOWHIGHCLOSE ) + ( C2U( "com.sun.star.chart2.template.StockVolumeOpenLowHighClose" ), TEMPLATE_STOCKVOLUMEOPENLOWHIGHCLOSE ) + ( C2U( "com.sun.star.chart2.template.Bubble" ), TEMPLATE_BUBBLE ) +// ( C2U( "com.sun.star.chart2.template.Surface" ), TEMPLATE_SURFACE ) +// ( C2U( "com.sun.star.chart2.template.Addin" ), TEMPLATE_ADDIN ) + ); + + return aMap; +} + +TemplateId lcl_GetTemplateIdForService( const OUString & rServiceName ) +{ + TemplateId eResult = TEMPLATE_NOT_FOUND; + const tTemplateMapType & rMap = lcl_DefaultChartTypeMap(); + tTemplateMapType::const_iterator aIt( rMap.find( rServiceName )); + + if( aIt != rMap.end()) + eResult = (*aIt).second; + + return eResult; +} + +} // anonymous namespace + +namespace chart +{ + +ChartTypeManager::ChartTypeManager( + uno::Reference< + uno::XComponentContext > const & xContext ) : + m_xContext( xContext ) +{} + +ChartTypeManager::~ChartTypeManager() +{} + +// ____ XMultiServiceFactory ____ +uno::Reference< uno::XInterface > SAL_CALL ChartTypeManager::createInstance( + const OUString& aServiceSpecifier ) + throw (uno::Exception, + uno::RuntimeException) +{ + uno::Reference< uno::XInterface > xResult; + TemplateId nId = lcl_GetTemplateIdForService( aServiceSpecifier ); + + if( nId == TEMPLATE_NOT_FOUND ) + { + try + { + xResult = m_xContext->getServiceManager()->createInstanceWithContext( + aServiceSpecifier, m_xContext ); + } +// catch( registry::InvalidValueException & ex ) + catch( uno::Exception & ex ) + { + // couldn't create service via factory + + // As XMultiServiceFactory does not specify, what to do in case + // createInstance is called with an unknown service-name, this + // function will just return an empty XInterface. + ASSERT_EXCEPTION( ex ); + OSL_TRACE( "Couldn't instantiate service \"%s\"", U2C( aServiceSpecifier )); + xResult.set( 0 ); + } + } + else + { + uno::Reference< chart2::XChartTypeTemplate > xTemplate; + switch( nId ) + { + // Point (category x axis) + case TEMPLATE_SYMBOL: + xTemplate.set( new LineChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_NONE, true, false )); + break; + case TEMPLATE_STACKEDSYMBOL: + xTemplate.set( new LineChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED, true, false )); + break; + case TEMPLATE_PERCENTSTACKEDSYMBOL: + xTemplate.set( new LineChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED_PERCENT, true, false )); + break; + // Line (category x axis) + case TEMPLATE_LINE: + xTemplate.set( new LineChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_NONE, false )); + break; + case TEMPLATE_STACKEDLINE: + xTemplate.set( new LineChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED, false )); + break; + case TEMPLATE_PERCENTSTACKEDLINE: + xTemplate.set( new LineChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED_PERCENT, false )); + break; + case TEMPLATE_LINESYMBOL: + xTemplate.set( new LineChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_NONE, true )); + break; + case TEMPLATE_STACKEDLINESYMBOL: + xTemplate.set( new LineChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED, true )); + break; + case TEMPLATE_PERCENTSTACKEDLINESYMBOL: + xTemplate.set( new LineChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED_PERCENT, true )); + break; + case TEMPLATE_THREEDLINE: + xTemplate.set( new LineChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_NONE, false, true, 3 )); + break; + case TEMPLATE_STACKEDTHREEDLINE: + xTemplate.set( new LineChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED, false, true, 3 )); + break; + case TEMPLATE_PERCENTSTACKEDTHREEDLINE: + xTemplate.set( new LineChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED_PERCENT, false, true, 3 )); + break; + case TEMPLATE_THREEDLINEDEEP: + xTemplate.set( new LineChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Z_STACKED, false, true, 3 )); + break; + + // Bar/Column + case TEMPLATE_COLUMN: + xTemplate.set( new BarChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_NONE, BarChartTypeTemplate::VERTICAL )); + break; + case TEMPLATE_STACKEDCOLUMN: + xTemplate.set( new BarChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED, BarChartTypeTemplate::VERTICAL )); + break; + case TEMPLATE_PERCENTSTACKEDCOLUMN: + xTemplate.set( new BarChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED_PERCENT, BarChartTypeTemplate::VERTICAL )); + break; + case TEMPLATE_BAR: + xTemplate.set( new BarChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_NONE, BarChartTypeTemplate::HORIZONTAL )); + break; + case TEMPLATE_STACKEDBAR: + xTemplate.set( new BarChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED, BarChartTypeTemplate::HORIZONTAL )); + break; + case TEMPLATE_PERCENTSTACKEDBAR: + xTemplate.set( new BarChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED_PERCENT, BarChartTypeTemplate::HORIZONTAL )); + break; + case TEMPLATE_THREEDCOLUMNDEEP: + xTemplate.set( new BarChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Z_STACKED, BarChartTypeTemplate::VERTICAL, 3 )); + break; + case TEMPLATE_THREEDCOLUMNFLAT: + xTemplate.set( new BarChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_NONE, BarChartTypeTemplate::VERTICAL, 3 )); + break; + case TEMPLATE_STACKEDTHREEDCOLUMNFLAT: + xTemplate.set( new BarChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED, BarChartTypeTemplate::VERTICAL, 3 )); + break; + case TEMPLATE_PERCENTSTACKEDTHREEDCOLUMNFLAT: + xTemplate.set( new BarChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED_PERCENT, BarChartTypeTemplate::VERTICAL, 3 )); + break; + case TEMPLATE_THREEDBARDEEP: + xTemplate.set( new BarChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Z_STACKED, BarChartTypeTemplate::HORIZONTAL, 3 )); + break; + case TEMPLATE_THREEDBARFLAT: + xTemplate.set( new BarChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_NONE, BarChartTypeTemplate::HORIZONTAL, 3 )); + break; + case TEMPLATE_STACKEDTHREEDBARFLAT: + xTemplate.set( new BarChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED, BarChartTypeTemplate::HORIZONTAL, 3 )); + break; + case TEMPLATE_PERCENTSTACKEDTHREEDBARFLAT: + xTemplate.set( new BarChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED_PERCENT, BarChartTypeTemplate::HORIZONTAL, 3 )); + break; + + // Combi-Chart Line/Column + case TEMPLATE_COLUMNWITHLINE: + case TEMPLATE_STACKEDCOLUMNWITHLINE: + { + StackMode eMode = ( nId == TEMPLATE_COLUMNWITHLINE ) + ? StackMode_NONE + : StackMode_Y_STACKED; + + xTemplate.set( new ColumnLineChartTypeTemplate( m_xContext, aServiceSpecifier, eMode, 1 )); + } + break; + + // Area + case TEMPLATE_AREA: + xTemplate.set( new AreaChartTypeTemplate( m_xContext, aServiceSpecifier, StackMode_NONE )); + break; + case TEMPLATE_STACKEDAREA: + xTemplate.set( new AreaChartTypeTemplate( m_xContext, aServiceSpecifier, StackMode_Y_STACKED )); + break; + case TEMPLATE_PERCENTSTACKEDAREA: + xTemplate.set( new AreaChartTypeTemplate( m_xContext, aServiceSpecifier, StackMode_Y_STACKED_PERCENT )); + break; + case TEMPLATE_THREEDAREA: + xTemplate.set( new AreaChartTypeTemplate( m_xContext, aServiceSpecifier, StackMode_Z_STACKED, 3 )); + break; + case TEMPLATE_STACKEDTHREEDAREA: + xTemplate.set( new AreaChartTypeTemplate( m_xContext, aServiceSpecifier, StackMode_Y_STACKED, 3 )); + break; + case TEMPLATE_PERCENTSTACKEDTHREEDAREA: + xTemplate.set( new AreaChartTypeTemplate( m_xContext, aServiceSpecifier, StackMode_Y_STACKED_PERCENT, 3 )); + break; + + case TEMPLATE_PIE: + xTemplate.set( new PieChartTypeTemplate( m_xContext, aServiceSpecifier, + chart2::PieChartOffsetMode_NONE, false )); + break; + case TEMPLATE_PIEALLEXPLODED: + xTemplate.set( new PieChartTypeTemplate( m_xContext, aServiceSpecifier, + chart2::PieChartOffsetMode_ALL_EXPLODED, false )); + break; + case TEMPLATE_DONUT: + xTemplate.set( new PieChartTypeTemplate( m_xContext, aServiceSpecifier, + chart2::PieChartOffsetMode_NONE, true )); + break; + case TEMPLATE_DONUTALLEXPLODED: + xTemplate.set( new PieChartTypeTemplate( m_xContext, aServiceSpecifier, + chart2::PieChartOffsetMode_ALL_EXPLODED, true )); + break; + case TEMPLATE_THREEDPIE: + xTemplate.set( new PieChartTypeTemplate( m_xContext, aServiceSpecifier, + chart2::PieChartOffsetMode_NONE, false, 3 )); + break; + case TEMPLATE_THREEDPIEALLEXPLODED: + xTemplate.set( new PieChartTypeTemplate( m_xContext, aServiceSpecifier, + chart2::PieChartOffsetMode_ALL_EXPLODED, false, 3 )); + break; + case TEMPLATE_THREEDDONUT: + xTemplate.set( new PieChartTypeTemplate( m_xContext, aServiceSpecifier, + chart2::PieChartOffsetMode_NONE, true, 3 )); + break; + case TEMPLATE_THREEDDONUTALLEXPLODED: + xTemplate.set( new PieChartTypeTemplate( m_xContext, aServiceSpecifier, + chart2::PieChartOffsetMode_ALL_EXPLODED, true, 3 )); + break; + + case TEMPLATE_SCATTERLINESYMBOL: + xTemplate.set( new ScatterChartTypeTemplate( m_xContext, aServiceSpecifier, /* bSymbols */ true )); + break; + case TEMPLATE_SCATTERLINE: + xTemplate.set( new ScatterChartTypeTemplate( m_xContext, aServiceSpecifier, /* bSymbols */ false )); + break; + case TEMPLATE_SCATTERSYMBOL: + xTemplate.set( new ScatterChartTypeTemplate( m_xContext, aServiceSpecifier, /* bSymbols */ true, /* bHasLines */ false )); + break; + case TEMPLATE_THREEDSCATTER: + xTemplate.set( new ScatterChartTypeTemplate( m_xContext, aServiceSpecifier, /* bSymbols */ false, /* bHasLines */ true, 3 )); + break; + + // NetChart + case TEMPLATE_NET: + xTemplate.set( new NetChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_NONE, true )); + break; + case TEMPLATE_NETSYMBOL: + xTemplate.set( new NetChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_NONE, true, false )); + break; + case TEMPLATE_NETLINE: + xTemplate.set( new NetChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_NONE, false )); + break; + + case TEMPLATE_STACKEDNET: + xTemplate.set( new NetChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED, true )); + break; + case TEMPLATE_STACKEDNETSYMBOL: + xTemplate.set( new NetChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED, true, false )); + break; + case TEMPLATE_STACKEDNETLINE: + xTemplate.set( new NetChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED, false, true )); + break; + + case TEMPLATE_PERCENTSTACKEDNET: + xTemplate.set( new NetChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED_PERCENT, true )); + break; + case TEMPLATE_PERCENTSTACKEDNETSYMBOL: + xTemplate.set( new NetChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED_PERCENT, true, false )); + break; + case TEMPLATE_PERCENTSTACKEDNETLINE: + xTemplate.set( new NetChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED_PERCENT, false, true )); + break; + + case TEMPLATE_FILLEDNET: + xTemplate.set( new NetChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_NONE, false, false, true )); + break; + case TEMPLATE_STACKEDFILLEDNET: + xTemplate.set( new NetChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED, false, false, true )); + break; + case TEMPLATE_PERCENTSTACKEDFILLEDNET: + xTemplate.set( new NetChartTypeTemplate( m_xContext, aServiceSpecifier, + StackMode_Y_STACKED_PERCENT, false, false, true )); + break; + + case TEMPLATE_STOCKLOWHIGHCLOSE: + xTemplate.set( new StockChartTypeTemplate( m_xContext, aServiceSpecifier, + StockChartTypeTemplate::LOW_HI_CLOSE, false )); + break; + case TEMPLATE_STOCKOPENLOWHIGHCLOSE: + xTemplate.set( new StockChartTypeTemplate( m_xContext, aServiceSpecifier, + StockChartTypeTemplate::OPEN_LOW_HI_CLOSE, true )); + break; + case TEMPLATE_STOCKVOLUMELOWHIGHCLOSE: + xTemplate.set( new StockChartTypeTemplate( m_xContext, aServiceSpecifier, + StockChartTypeTemplate::VOL_LOW_HI_CLOSE, false )); + break; + case TEMPLATE_STOCKVOLUMEOPENLOWHIGHCLOSE: + xTemplate.set( new StockChartTypeTemplate( m_xContext, aServiceSpecifier, + StockChartTypeTemplate::VOL_OPEN_LOW_HI_CLOSE, true )); + break; + + //BubbleChart + case TEMPLATE_BUBBLE: + xTemplate.set( new BubbleChartTypeTemplate( m_xContext, aServiceSpecifier )); + break; + +// case TEMPLATE_SURFACE: +// case TEMPLATE_ADDIN: +// break; + + case TEMPLATE_NOT_FOUND: + OSL_ASSERT( false ); + break; + } + xResult.set( xTemplate, uno::UNO_QUERY ); + } + + return xResult; +} + +uno::Reference< uno::XInterface > SAL_CALL ChartTypeManager::createInstanceWithArguments( + const OUString& ServiceSpecifier, + const uno::Sequence< uno::Any >& /* Arguments */ ) + throw (uno::Exception, + uno::RuntimeException) +{ + OSL_ENSURE( false, "createInstanceWithArguments: No arguments supported" ); + return createInstance( ServiceSpecifier ); +} + +uno::Sequence< OUString > SAL_CALL ChartTypeManager::getAvailableServiceNames() + throw (uno::RuntimeException) +{ + ::std::vector< OUString > aServices; + const tTemplateMapType & rMap = lcl_DefaultChartTypeMap(); + aServices.reserve( rMap.size()); + + // get own default templates + ::std::transform( rMap.begin(), rMap.end(), ::std::back_inserter( aServices ), + ::std::select1st< tTemplateMapType::value_type >()); + + // add components that were registered in the context's factory + uno::Reference< container::XContentEnumerationAccess > xEnumAcc( + m_xContext->getServiceManager(), uno::UNO_QUERY ); + if( xEnumAcc.is()) + { + uno::Reference< container::XEnumeration > xEnum( + xEnumAcc->createContentEnumeration( C2U( "com.sun.star.chart2.ChartTypeTemplate" ) )); + if( xEnum.is()) + { + uno::Reference< uno::XInterface > xFactIntf; + + while( xEnum->hasMoreElements()) + { + if( xEnum->nextElement() >>= xFactIntf ) + { + uno::Reference< lang::XServiceName > xServiceName( xFactIntf, uno::UNO_QUERY ); + if( xServiceName.is()) + aServices.push_back( xServiceName->getServiceName()); + } + } + } + } + + return ContainerHelper::ContainerToSequence( aServices ); +} + +// ____ XServiceInfo ____ +Sequence< OUString > ChartTypeManager::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 2 ); + aServices[ 0 ] = C2U( "com.sun.star.chart2.ChartTypeManager" ); + aServices[ 1 ] = C2U( "com.sun.star.lang.MultiServiceFactory" ); + return aServices; +} + +// ================================================================================ + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( ChartTypeManager, + C2U( "com.sun.star.comp.chart.ChartTypeManager" )); +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/ChartTypeTemplate.cxx b/chart2/source/model/template/ChartTypeTemplate.cxx new file mode 100644 index 000000000000..98f11ee3257a --- /dev/null +++ b/chart2/source/model/template/ChartTypeTemplate.cxx @@ -0,0 +1,935 @@ +/* -*- 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 "ChartTypeTemplate.hxx" +#include "PropertyHelper.hxx" +#include "macros.hxx" +#include "DataSeriesHelper.hxx" +#include "DataInterpreter.hxx" +#include "CommonConverters.hxx" +#include "ContainerHelper.hxx" +#include "ChartTypeHelper.hxx" + +#include "CartesianCoordinateSystem.hxx" +#include "AxisHelper.hxx" +#include "LegendHelper.hxx" +#include "DiagramHelper.hxx" +#include "ChartDebugTrace.hxx" +#include "AxisIndexDefines.hxx" +#include <cppuhelper/component_context.hxx> +#include <com/sun/star/chart/ChartSolidType.hpp> +#include <com/sun/star/chart2/AxisType.hpp> +#include <com/sun/star/chart2/XDataSeriesContainer.hpp> +#include <com/sun/star/chart2/XChartTypeContainer.hpp> +#include <com/sun/star/chart2/AxisType.hpp> + +#include <algorithm> +#include <iterator> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; + +using ::rtl::OUString; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; + +// ====================================================================== + +namespace +{ + +void lcl_applyDefaultStyle( + const Reference< XDataSeries > & xSeries, + sal_Int32 nIndex, + const Reference< XDiagram > & xDiagram ) +{ + // @deprecated: correct default color should be found by view without + // setting color as hard attribute + if( xSeries.is() && xDiagram.is()) + { + Reference< beans::XPropertySet > xSeriesProp( xSeries, uno::UNO_QUERY ); + Reference< chart2::XColorScheme > xColorScheme( xDiagram->getDefaultColorScheme()); + if( xSeriesProp.is() && xColorScheme.is() ) + xSeriesProp->setPropertyValue( + C2U("Color"), + uno::makeAny( xColorScheme->getColorByIndex( nIndex ))); + } +} + +void lcl_ensureCorrectLabelPlacement( const Reference< beans::XPropertySet >& xProp, const uno::Sequence < sal_Int32 >& rAvailablePlacements ) +{ + sal_Int32 nLabelPlacement=0; + if( xProp.is() && (xProp->getPropertyValue( C2U( "LabelPlacement" ) ) >>= nLabelPlacement) ) + { + bool bValid = false; + for( sal_Int32 nN = 0; nN < rAvailablePlacements.getLength(); nN++ ) + { + if( rAvailablePlacements[nN] == nLabelPlacement ) + { + bValid = true; + break; + } + } + if( !bValid ) + { + uno::Any aNewValue; + //otherwise use the first supported one + if( rAvailablePlacements.getLength() ) + aNewValue <<=rAvailablePlacements[0]; + xProp->setPropertyValue( C2U("LabelPlacement"), aNewValue ); + } + } +} + +void lcl_resetLabelPlacementIfDefault( const Reference< beans::XPropertySet >& xProp, sal_Int32 nDefaultPlacement ) +{ + + sal_Int32 nLabelPlacement=0; + if( xProp.is() && (xProp->getPropertyValue( C2U( "LabelPlacement" ) ) >>= nLabelPlacement) ) + { + if( nDefaultPlacement == nLabelPlacement ) + xProp->setPropertyValue( C2U("LabelPlacement"), uno::Any() ); + } +} + +void lcl_ensureCorrectMissingValueTreatment( const Reference< chart2::XDiagram >& xDiagram, const Reference< XChartType >& xChartType ) +{ + Reference< beans::XPropertySet > xDiaProp( xDiagram, uno::UNO_QUERY ); + if( xDiaProp.is() ) + { + uno::Sequence < sal_Int32 > aAvailableMissingValueTreatment( + ::chart::ChartTypeHelper::getSupportedMissingValueTreatments( xChartType ) ); + + if( aAvailableMissingValueTreatment.getLength() ) + xDiaProp->setPropertyValue( C2U( "MissingValueTreatment" ), uno::makeAny( aAvailableMissingValueTreatment[0] ) ); + else + xDiaProp->setPropertyValue( C2U( "MissingValueTreatment" ), uno::Any() ); + } +} + +} // anonymous namespace + +namespace chart +{ + +ChartTypeTemplate::ChartTypeTemplate( + Reference< uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName ) : + m_xContext( xContext ), + m_aServiceName( rServiceName ) +{ +} + +ChartTypeTemplate::~ChartTypeTemplate() +{} + +// ____ XChartTypeTemplate ____ +uno::Reference< XDiagram > SAL_CALL ChartTypeTemplate::createDiagramByDataSource( + const uno::Reference< data::XDataSource >& xDataSource, + const uno::Sequence< beans::PropertyValue >& aArguments ) + throw (uno::RuntimeException) +{ + Reference< XDiagram > xDia; + + try + { + // create diagram + xDia.set( + GetComponentContext()->getServiceManager()->createInstanceWithContext( + C2U( "com.sun.star.chart2.Diagram" ), + GetComponentContext() ), + uno::UNO_QUERY_THROW ); + + // modify diagram + Reference< chart2::XDataInterpreter > xInterpreter( getDataInterpreter()); + chart2::InterpretedData aData( + xInterpreter->interpretDataSource( + xDataSource, aArguments, Sequence< Reference< XDataSeries > >() )); + + Sequence< Sequence< Reference< XDataSeries > > > aSeries( aData.Series ); + sal_Int32 i, j, nCount = 0; + for( i=0; i<aSeries.getLength(); ++i ) + { + for( j=0; j<aSeries[i].getLength(); ++j, ++nCount ) + lcl_applyDefaultStyle( aSeries[i][j], nCount, xDia ); + } + + Sequence< Reference< XChartType > > aOldChartTypesSeq; + FillDiagram( xDia, aData.Series, aData.Categories, aOldChartTypesSeq, true ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return xDia; +} + +sal_Bool SAL_CALL ChartTypeTemplate::supportsCategories() + throw (uno::RuntimeException) +{ + return sal_True; +} + +void SAL_CALL ChartTypeTemplate::changeDiagram( const uno::Reference< XDiagram >& xDiagram ) + throw (uno::RuntimeException) +{ + if( ! xDiagram.is()) + return; + + try + { + Sequence< Sequence< Reference< XDataSeries > > > aSeriesSeq( + DiagramHelper::getDataSeriesGroups( xDiagram )); + Sequence< Reference< XDataSeries > > aFlatSeriesSeq( FlattenSequence( aSeriesSeq )); + const sal_Int32 nFormerSeriesCount = aFlatSeriesSeq.getLength(); + + // chart-type specific interpretation of existing data series + Reference< chart2::XDataInterpreter > xInterpreter( getDataInterpreter()); + chart2::InterpretedData aData; + aData.Series = aSeriesSeq; + aData.Categories = DiagramHelper::getCategoriesFromDiagram( xDiagram ); + + if( xInterpreter->isDataCompatible( aData ) ) + { + aData = xInterpreter->reinterpretDataSeries( aData ); + } + else + { + Reference< data::XDataSource > xSource( xInterpreter->mergeInterpretedData( aData )); + // todo: get a "range-union" from the data provider by calling + // OUString aRange = getRangeRepresentationByData( xSource ); + // xSource.set( getDataByRangeRepresentation( aRange, aParam )); + // where aParam == ?? + Sequence< beans::PropertyValue > aParam; + if( aData.Categories.is()) + { + aParam.realloc( 1 ); + aParam[0] = beans::PropertyValue( C2U("HasCategories"), -1, uno::makeAny( true ), + beans::PropertyState_DIRECT_VALUE ); + } + aData = xInterpreter->interpretDataSource( xSource, aParam, aFlatSeriesSeq ); + } + aSeriesSeq = aData.Series; + + sal_Int32 i, j, nIndex = 0; + for( i=0; i<aSeriesSeq.getLength(); ++i ) + for( j=0; j<aSeriesSeq[i].getLength(); ++j, ++nIndex ) + { + if( nIndex >= nFormerSeriesCount ) + lcl_applyDefaultStyle( aSeriesSeq[i][j], nIndex, xDiagram ); + } + + // remove charttype groups from all coordinate systems + Sequence< Reference< XChartType > > aOldChartTypesSeq( + DiagramHelper::getChartTypesFromDiagram(xDiagram) ); + + Reference< XCoordinateSystemContainer > xCoordSysCnt( xDiagram, uno::UNO_QUERY ); + OSL_ASSERT( xCoordSysCnt.is()); + if( xCoordSysCnt.is()) + { + Sequence< Reference< XCoordinateSystem > > aCooSysSeq( + xCoordSysCnt->getCoordinateSystems()); + for( sal_Int32 nCooSysIdx = 0; nCooSysIdx < aCooSysSeq.getLength(); ++nCooSysIdx ) + { + Reference< XChartTypeContainer > xContainer( aCooSysSeq[nCooSysIdx], uno::UNO_QUERY ); + if( xContainer.is() ) + xContainer->setChartTypes( Sequence< Reference< XChartType > >() ); + } + } + + FillDiagram( xDiagram, aSeriesSeq, aData.Categories, aOldChartTypesSeq, false ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +void SAL_CALL ChartTypeTemplate::changeDiagramData( + const Reference< chart2::XDiagram >& xDiagram, + const Reference< chart2::data::XDataSource >& xDataSource, + const Sequence< beans::PropertyValue >& aArguments ) + throw (uno::RuntimeException) +{ + if( ! (xDiagram.is() && + xDataSource.is()) ) + return; + + try + { + // interpret new data and re-use existing series + Sequence< Reference< XDataSeries > > aFlatSeriesSeq( + ::chart::ContainerHelper::ContainerToSequence( DiagramHelper::getDataSeriesFromDiagram( xDiagram ))); + const sal_Int32 nFormerSeriesCount = aFlatSeriesSeq.getLength(); + Reference< chart2::XDataInterpreter > xInterpreter( getDataInterpreter()); + chart2::InterpretedData aData = + xInterpreter->interpretDataSource( xDataSource, aArguments, aFlatSeriesSeq ); + + // data series + Sequence< Sequence< Reference< XDataSeries > > > aSeriesSeq( aData.Series ); + + sal_Int32 i, j, nIndex = 0; + for( i=0; i<aSeriesSeq.getLength(); ++i ) + for( j=0; j<aSeriesSeq[i].getLength(); ++j, ++nIndex ) + { + if( nIndex >= nFormerSeriesCount ) + { + lcl_applyDefaultStyle( aSeriesSeq[i][j], nIndex, xDiagram ); + applyStyle( aSeriesSeq[i][j], i, j, aSeriesSeq[i].getLength() ); + } + } + + // categories + DiagramHelper::setCategoriesToDiagram( aData.Categories, xDiagram, true, supportsCategories() ); + + Sequence< Reference< XChartType > > aChartTypes( + DiagramHelper::getChartTypesFromDiagram( xDiagram )); + sal_Int32 nMax = ::std::min( aChartTypes.getLength(), aSeriesSeq.getLength()); + for( i=0; i<nMax; ++i ) + { + Reference< XDataSeriesContainer > xDSCnt( aChartTypes[i], uno::UNO_QUERY_THROW ); + xDSCnt->setDataSeries( aSeriesSeq[i] ); + } +#if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL + OSL_TRACE( "ChartTypeTemplate::changeDiagramData: Showing Diagram structure" ); + OSL_TRACE( "---------------------------------------------------------------" ); + debug::ChartDebugTraceDiagram( xDiagram ); +#endif + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +sal_Bool SAL_CALL ChartTypeTemplate::matchesTemplate( + const Reference< chart2::XDiagram >& xDiagram, + sal_Bool /* bAdaptProperties */ ) + throw (uno::RuntimeException) +{ + sal_Bool bResult = sal_False; + + if( ! xDiagram.is()) + return bResult; + + try + { + Reference< XCoordinateSystemContainer > xCooSysCnt( + xDiagram, uno::UNO_QUERY_THROW ); + Sequence< Reference< XCoordinateSystem > > aCooSysSeq( + xCooSysCnt->getCoordinateSystems()); + + // need to have at least one coordinate system + bResult = (aCooSysSeq.getLength() > 0); + if( bResult ) + { + Sequence< Reference< XChartType > > aFormerlyUsedChartTypes; + const OUString aChartTypeToMatch( getChartTypeForNewSeries(aFormerlyUsedChartTypes)->getChartType()); + const sal_Int32 nDimensionToMatch = getDimension(); + for( sal_Int32 nCooSysIdx=0; bResult && (nCooSysIdx < aCooSysSeq.getLength()); ++nCooSysIdx ) + { + // match dimension + bResult = bResult && (aCooSysSeq[nCooSysIdx]->getDimension() == nDimensionToMatch); + + Reference< XChartTypeContainer > xCTCnt( aCooSysSeq[nCooSysIdx], uno::UNO_QUERY_THROW ); + Sequence< Reference< XChartType > > aChartTypeSeq( xCTCnt->getChartTypes()); + for( sal_Int32 nCTIdx=0; bResult && (nCTIdx < aChartTypeSeq.getLength()); ++nCTIdx ) + { + // match chart type + bResult = bResult && aChartTypeSeq[nCTIdx]->getChartType().equals( aChartTypeToMatch ); + bool bFound=false; + bool bAmbiguous=false; + // match stacking mode + bResult = bResult && + ( DiagramHelper::getStackModeFromChartType( + aChartTypeSeq[nCTIdx], bFound, bAmbiguous, + aCooSysSeq[nCooSysIdx] ) + == getStackMode( nCTIdx ) ); + } + } + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return bResult; +} + +Reference< chart2::XDataInterpreter > SAL_CALL ChartTypeTemplate::getDataInterpreter() + throw (uno::RuntimeException) +{ + if( ! m_xDataInterpreter.is()) + m_xDataInterpreter.set( new DataInterpreter( GetComponentContext() ) ); + + return m_xDataInterpreter; +} + +void SAL_CALL ChartTypeTemplate::applyStyle( + const Reference< chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeIndex, + ::sal_Int32 /* nSeriesIndex */, + ::sal_Int32 /* nSeriesCount */ ) + throw (uno::RuntimeException) +{ + // sset stacking mode + Reference< beans::XPropertySet > xSeriesProp( xSeries, uno::UNO_QUERY ); + if( xSeriesProp.is()) + { + try + { + StackMode eStackMode = getStackMode( nChartTypeIndex ); + const uno::Any aPropValue = uno::makeAny( + ( (eStackMode == StackMode_Y_STACKED) || + (eStackMode == StackMode_Y_STACKED_PERCENT) ) + ? chart2::StackingDirection_Y_STACKING + : (eStackMode == StackMode_Z_STACKED ) + ? chart2::StackingDirection_Z_STACKING + : chart2::StackingDirection_NO_STACKING ); + xSeriesProp->setPropertyValue( C2U("StackingDirection"), aPropValue ); + + //ensure valid label placement + { + uno::Sequence < sal_Int32 > aAvailablePlacements( ChartTypeHelper::getSupportedLabelPlacements( + getChartTypeForIndex( nChartTypeIndex ), getDimension(), isSwapXAndY(), xSeries ) ); + lcl_ensureCorrectLabelPlacement( xSeriesProp, aAvailablePlacements ); + + uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; + if( xSeriesProp->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList ) + for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) + lcl_ensureCorrectLabelPlacement( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]), aAvailablePlacements ); + } + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } +} + +void SAL_CALL ChartTypeTemplate::applyStyles( const Reference< chart2::XDiagram >& xDiagram ) + throw (uno::RuntimeException) +{ + // apply chart-type specific styles, like "symbols on" for example + Sequence< Sequence< Reference< XDataSeries > > > aNewSeriesSeq( + DiagramHelper::getDataSeriesGroups( xDiagram )); + for( sal_Int32 i=0; i<aNewSeriesSeq.getLength(); ++i ) + { + const sal_Int32 nNumSeries = aNewSeriesSeq[i].getLength(); + for( sal_Int32 j=0; j<nNumSeries; ++j ) + applyStyle( aNewSeriesSeq[i][j], i, j, nNumSeries ); + } + + //ensure valid empty cell handling (for first chart type...) + lcl_ensureCorrectMissingValueTreatment( xDiagram, getChartTypeForIndex( 0 ) ); +} + +void SAL_CALL ChartTypeTemplate::resetStyles( const Reference< chart2::XDiagram >& xDiagram ) + throw (uno::RuntimeException) +{ + // reset number format if we had percent stacking on + sal_Bool bPercent = (getStackMode(0) == StackMode_Y_STACKED_PERCENT); + if( bPercent ) + { + Sequence< Reference< chart2::XAxis > > aAxisSeq( AxisHelper::getAllAxesOfDiagram( xDiagram ) ); + for( sal_Int32 i=0; i<aAxisSeq.getLength(); ++i ) + { + if( 1== AxisHelper::getDimensionIndexOfAxis( aAxisSeq[i], xDiagram ) ) + { + Reference< beans::XPropertySet > xAxisProp( aAxisSeq[i], uno::UNO_QUERY ); + if( xAxisProp.is()) + { + // set number format to source format + uno::Any aValue( xAxisProp->getPropertyValue(C2U("NumberFormat"))); + if( aValue.hasValue()) + xAxisProp->setPropertyValue(C2U("NumberFormat"), uno::Any()); + } + } + } + } + + //reset label placement if default + { + uno::Reference< XCoordinateSystemContainer > xCooSysContainer( xDiagram, uno::UNO_QUERY ); + if( xCooSysContainer.is() ) + { + uno::Sequence< uno::Reference< XCoordinateSystem > > aCooSysList( xCooSysContainer->getCoordinateSystems() ); + for( sal_Int32 nCS = 0; nCS < aCooSysList.getLength(); ++nCS ) + { + uno::Reference< XCoordinateSystem > xCooSys( aCooSysList[nCS] ); + + //iterate through all chart types in the current coordinate system + uno::Reference< XChartTypeContainer > xChartTypeContainer( xCooSys, uno::UNO_QUERY ); + OSL_ASSERT( xChartTypeContainer.is()); + if( !xChartTypeContainer.is() ) + continue; + uno::Sequence< uno::Reference< XChartType > > aChartTypeList( xChartTypeContainer->getChartTypes() ); + for( sal_Int32 nT = 0; nT < aChartTypeList.getLength(); ++nT ) + { + uno::Reference< XChartType > xChartType( aChartTypeList[nT] ); + + //iterate through all series in this chart type + uno::Reference< XDataSeriesContainer > xDataSeriesContainer( xChartType, uno::UNO_QUERY ); + OSL_ASSERT( xDataSeriesContainer.is()); + if( !xDataSeriesContainer.is() ) + continue; + + uno::Sequence< uno::Reference< XDataSeries > > aSeriesList( xDataSeriesContainer->getDataSeries() ); + for( sal_Int32 nS = 0; nS < aSeriesList.getLength(); ++nS ) + { + Reference< XDataSeries > xSeries(aSeriesList[nS]); + Reference< beans::XPropertySet > xSeriesProp( xSeries, uno::UNO_QUERY ); + if(!xSeries.is() || !xSeriesProp.is() ) + continue; + + uno::Sequence < sal_Int32 > aAvailablePlacements( ChartTypeHelper::getSupportedLabelPlacements( + xChartType, getDimension(), isSwapXAndY(), xSeries ) ); + if(!aAvailablePlacements.getLength()) + continue; + + sal_Int32 nDefaultPlacement = aAvailablePlacements[0]; + + lcl_resetLabelPlacementIfDefault( xSeriesProp, nDefaultPlacement ); + + uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; + if( xSeriesProp->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList ) + for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) + lcl_resetLabelPlacementIfDefault( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]), nDefaultPlacement ); + } + } + } + } + } + + return; +} + +// ____ XServiceName ____ + ::rtl::OUString SAL_CALL ChartTypeTemplate::getServiceName() + throw (uno::RuntimeException) +{ + return m_aServiceName; +} + +// ________________________________________ + +sal_Int32 ChartTypeTemplate::getDimension() const +{ + return 2; +} + +StackMode ChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const +{ + return StackMode_NONE; +} + +bool ChartTypeTemplate::isSwapXAndY() const +{ + return false; +} + +// ________________________________________ + +void ChartTypeTemplate::createCoordinateSystems( + const Reference< chart2::XCoordinateSystemContainer > & xOutCooSysCnt ) +{ + if( ! xOutCooSysCnt.is()) + return; + Sequence< Reference< XChartType > > aFormerlyUsedChartTypes; + Reference< XChartType > xChartType( getChartTypeForNewSeries(aFormerlyUsedChartTypes)); + if( ! xChartType.is()) + return; + Reference< XCoordinateSystem > xCooSys( xChartType->createCoordinateSystem( getDimension())); + if( ! xCooSys.is()) + { + // chart type wants no coordinate systems + xOutCooSysCnt->setCoordinateSystems( Sequence< Reference< XCoordinateSystem > >()); + return; + } + // #i69680# make grid of first y-axis visible (was in the CooSys CTOR before) + if( xCooSys->getDimension() >= 2 ) + { + Reference< chart2::XAxis > xAxis( xCooSys->getAxisByDimension( 1, 0 )); + if( xAxis.is()) + AxisHelper::makeGridVisible( xAxis->getGridProperties() ); + } + + Sequence< Reference< XCoordinateSystem > > aCoordinateSystems( + xOutCooSysCnt->getCoordinateSystems()); + + if( aCoordinateSystems.getLength()) + { + bool bOk = true; + for( sal_Int32 i=0; bOk && i<aCoordinateSystems.getLength(); ++i ) + bOk = bOk && ( xCooSys->getCoordinateSystemType().equals( aCoordinateSystems[i]->getCoordinateSystemType()) && + (xCooSys->getDimension() == aCoordinateSystems[i]->getDimension()) ); + // coordinate systems are ok + if( bOk ) + return; + // there are coordinate systems but they do not fit. So overwrite them. + } + + //copy as much info from former coordinate system as possible: + if( aCoordinateSystems.getLength() ) + { + Reference< XCoordinateSystem > xOldCooSys( aCoordinateSystems[0] ); + sal_Int32 nMaxDimensionCount = std::min( xCooSys->getDimension(), xOldCooSys->getDimension() ); + + for(sal_Int32 nDimensionIndex=0; nDimensionIndex<nMaxDimensionCount; nDimensionIndex++) + { + const sal_Int32 nMaximumAxisIndex = xOldCooSys->getMaximumAxisIndexByDimension(nDimensionIndex); + for(sal_Int32 nAxisIndex=0; nAxisIndex<=nMaximumAxisIndex; ++nAxisIndex) + { + uno::Reference< XAxis > xAxis( xOldCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex ) ); + if( xAxis.is()) + { + xCooSys->setAxisByDimension( nDimensionIndex, xAxis, nAxisIndex ); + } + } + } + } + + // set new coordinate systems + aCoordinateSystems.realloc( 1 ); + aCoordinateSystems[0] = xCooSys; + + xOutCooSysCnt->setCoordinateSystems( aCoordinateSystems ); +} + +void ChartTypeTemplate::adaptScales( + const Sequence< Reference< chart2::XCoordinateSystem > > & aCooSysSeq, + const Reference< data::XLabeledDataSequence > & xCategories //@todo: in future there may be more than one sequence of categories (e.g. charttype with categories at x and y axis ) + ) +{ + bool bSupportsCategories( supportsCategories() ); + for( sal_Int32 nCooSysIdx=0; nCooSysIdx<aCooSysSeq.getLength(); ++nCooSysIdx ) + { + try + { + Reference< XCoordinateSystem > xCooSys( aCooSysSeq[nCooSysIdx] ); + if( !xCooSys.is() ) + continue; + + // attach categories to first axis + sal_Int32 nDim( xCooSys->getDimension()); + if( nDim > 0 ) + { + const sal_Int32 nMaxIndex = xCooSys->getMaximumAxisIndexByDimension(0); + for(sal_Int32 nI=0; nI<=nMaxIndex; ++nI) + { + Reference< XAxis > xAxis( xCooSys->getAxisByDimension(0,nI) ); + if( xAxis.is()) + { + ScaleData aData( xAxis->getScaleData() ); + aData.Categories = xCategories; + aData.AxisType = bSupportsCategories ? AxisType::CATEGORY : AxisType::REALNUMBER; + if( bSupportsCategories ) + AxisHelper::removeExplicitScaling( aData ); + xAxis->setScaleData( aData ); + } + } + } + // set percent stacking mode at second axis + if( nDim > 1 ) + { + const sal_Int32 nMaxIndex = xCooSys->getMaximumAxisIndexByDimension(1); + for(sal_Int32 nI=0; nI<=nMaxIndex; ++nI) + { + Reference< chart2::XAxis > xAxis( xCooSys->getAxisByDimension( 1,nI )); + if( xAxis.is()) + { + sal_Bool bPercent = (getStackMode(0) == StackMode_Y_STACKED_PERCENT); + chart2::ScaleData aScaleData = xAxis->getScaleData(); + + if( bPercent != (aScaleData.AxisType==AxisType::PERCENT) ) + { + if( bPercent ) + aScaleData.AxisType = AxisType::PERCENT; + else + aScaleData.AxisType = AxisType::REALNUMBER; + xAxis->setScaleData( aScaleData ); + } + } + } + } + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } +} + +void ChartTypeTemplate::adaptDiagram( const Reference< XDiagram > & /* xDiagram */ ) +{ + return; +} + +void ChartTypeTemplate::createAxes( + const Sequence< Reference< XCoordinateSystem > > & rCoordSys ) +{ + //create missing axes + if( rCoordSys.getLength() > 0 ) + { + sal_Int32 nCooSysIdx = 0; + Reference< XCoordinateSystem > xCooSys( rCoordSys[nCooSysIdx] ); + if(!xCooSys.is()) + return; + + //create main axis in first coordinate system + sal_Int32 nDimCount = xCooSys->getDimension(); + sal_Int32 nDim=0; + for( nDim=0; nDim<nDimCount; ++nDim ) + { + sal_Int32 nAxisCount = getAxisCountByDimension( nDim ); + if( nDim == 1 && + nAxisCount < 2 && AxisHelper::isSecondaryYAxisNeeded( xCooSys )) + nAxisCount = 2; + for( sal_Int32 nAxisIndex = 0; nAxisIndex < nAxisCount; ++nAxisIndex ) + { + Reference< XAxis > xAxis = AxisHelper::getAxis( nDim, nAxisIndex, xCooSys ); + if( !xAxis.is()) + { + // create and add axis + xAxis.set( AxisHelper::createAxis( + nDim, nAxisIndex, xCooSys, GetComponentContext() )); + } + } + } + } +} + +void ChartTypeTemplate::adaptAxes( + const Sequence< Reference< XCoordinateSystem > > & rCoordSys ) +{ + //adapt properties of exsisting axes and remove superfluous axes + + if( rCoordSys.getLength() > 0 ) + { + for( sal_Int32 nCooSysIdx=0; nCooSysIdx < rCoordSys.getLength(); ++nCooSysIdx ) + { + Reference< XCoordinateSystem > xCooSys( rCoordSys[nCooSysIdx] ); + if( !xCooSys.is() ) + continue; + sal_Int32 nDimCount = xCooSys->getDimension(); + for( sal_Int32 nDim=0; nDim<nDimCount; ++nDim ) + { + sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension( nDim ); + for( sal_Int32 nAxisIndex=0; nAxisIndex<=nMaxAxisIndex; nAxisIndex++ ) + { + Reference< XAxis > xAxis( AxisHelper::getAxis( nDim, nAxisIndex, xCooSys ) ); + if( !xAxis.is() ) + continue; + + if( nAxisIndex == MAIN_AXIS_INDEX || nAxisIndex == SECONDARY_AXIS_INDEX ) + { + // adapt scales + sal_Bool bPercent = (getStackMode(0) == StackMode_Y_STACKED_PERCENT); + if( bPercent && nDim == 1 ) + { + Reference< beans::XPropertySet > xAxisProp( xAxis, uno::UNO_QUERY ); + if( xAxisProp.is()) + { + // set number format to source format + uno::Any aValue( xAxisProp->getPropertyValue(C2U("NumberFormat"))); + if( aValue.hasValue()) + xAxisProp->setPropertyValue(C2U("NumberFormat"), uno::Any()); + } + } + } + } + } + } + } +} + +sal_Int32 ChartTypeTemplate::getAxisCountByDimension( sal_Int32 nDimension ) +{ + return (nDimension < getDimension()) ? 1 : 0; +} + +void ChartTypeTemplate::FillDiagram( + const Reference< XDiagram >& xDiagram, + const Sequence< Sequence< Reference< XDataSeries > > >& aSeriesSeq, + Reference< data::XLabeledDataSequence > xCategories, + const Sequence< Reference< XChartType > >& aOldChartTypesSeq, + bool /* bCreate */ ) +{ + adaptDiagram( xDiagram ); + + try + { + // create coordinate systems and scales + Reference< XCoordinateSystemContainer > xCoordSysCnt( xDiagram, uno::UNO_QUERY_THROW ); + createCoordinateSystems( xCoordSysCnt ); + Sequence< Reference< XCoordinateSystem > > aCoordinateSystems( xCoordSysCnt->getCoordinateSystems()); + createAxes( aCoordinateSystems ); + adaptAxes( aCoordinateSystems ); + adaptScales( aCoordinateSystems, xCategories ); + + // chart types + createChartTypes( aSeriesSeq, aCoordinateSystems, aOldChartTypesSeq ); + applyStyles( xDiagram ); + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + +#if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL + OSL_TRACE( "ChartTypeTemplate::FillDiagram: Showing Diagram structure" ); + OSL_TRACE( "---------------------------------------------------------" ); + debug::ChartDebugTraceDiagram( xDiagram ); +#endif +} + +void ChartTypeTemplate::createChartTypes( + const Sequence< Sequence< Reference< XDataSeries > > > & aSeriesSeq, + const Sequence< Reference< XCoordinateSystem > > & rCoordSys, + const Sequence< Reference< XChartType > >& aOldChartTypesSeq ) +{ + if( rCoordSys.getLength() == 0 || + ! rCoordSys[0].is() ) + return; + + try + { + sal_Int32 nCooSysIdx=0; + Reference< XChartType > xCT; + if( aSeriesSeq.getLength() == 0 ) + { + // we need a new chart type + xCT.set( getChartTypeForNewSeries( aOldChartTypesSeq )); + Reference< XChartTypeContainer > xCTCnt( rCoordSys[nCooSysIdx], uno::UNO_QUERY_THROW ); + Sequence< Reference< XChartType > > aCTSeq( xCTCnt->getChartTypes()); + aCTSeq.realloc( 1 ); + aCTSeq[0] = xCT; + xCTCnt->setChartTypes( aCTSeq ); + } + else + { + for( sal_Int32 nSeriesIdx=0; nSeriesIdx<aSeriesSeq.getLength(); ++nSeriesIdx ) + { + if( nSeriesIdx == nCooSysIdx ) + { + // we need a new chart type + xCT.set( getChartTypeForNewSeries( aOldChartTypesSeq )); + Reference< XChartTypeContainer > xCTCnt( rCoordSys[nCooSysIdx], uno::UNO_QUERY_THROW ); + Sequence< Reference< XChartType > > aCTSeq( xCTCnt->getChartTypes()); + if( aCTSeq.getLength()) + { + aCTSeq[0] = xCT; + xCTCnt->setChartTypes( aCTSeq ); + } + else + xCTCnt->addChartType( xCT ); + + Reference< chart2::XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW ); + xDSCnt->setDataSeries( aSeriesSeq[nSeriesIdx] ); + } + else + { + // reuse existing chart type + OSL_ASSERT( xCT.is()); + Reference< chart2::XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW ); + Sequence< Reference< XDataSeries > > aNewSeriesSeq( xDSCnt->getDataSeries()); + sal_Int32 nNewStartIndex = aNewSeriesSeq.getLength(); + aNewSeriesSeq.realloc( nNewStartIndex + aSeriesSeq[nSeriesIdx].getLength() ); + ::std::copy( aSeriesSeq[nSeriesIdx].getConstArray(), + aSeriesSeq[nSeriesIdx].getConstArray() + aSeriesSeq[nSeriesIdx].getLength(), + aNewSeriesSeq.getArray() + nNewStartIndex ); + xDSCnt->setDataSeries( aNewSeriesSeq ); + } + + // spread the series over the available coordinate systems + if( rCoordSys.getLength() > (nCooSysIdx + 1) ) + ++nCooSysIdx; + } + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +void ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( + const Sequence< Reference< XChartType > > & rOldChartTypesSeq, + const Reference< XChartType > & xNewChartType ) +{ + Reference< beans::XPropertySet > xDestination( xNewChartType, uno::UNO_QUERY ); + if( !xDestination.is() ) + return; + + OUString aNewChartType( xNewChartType->getChartType() ); + + Reference< beans::XPropertySet > xSource; + sal_Int32 nN=0; + for( nN=0; nN<rOldChartTypesSeq.getLength();++nN) + { + Reference< XChartType > xOldType( rOldChartTypesSeq[nN] ); + if( xOldType.is() && xOldType->getChartType().equals( aNewChartType ) ) + { + xSource.set( Reference< beans::XPropertySet >(xOldType, uno::UNO_QUERY ) ); + if( xSource.is() ) + break; + } + } + if( xSource.is() ) + comphelper::copyProperties( xSource, xDestination ); +} + +// ________ + +Sequence< OUString > ChartTypeTemplate::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 3 ); + aServices[ 0 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" ); + aServices[ 1 ] = C2U( "com.sun.star.layout.LayoutElement" ); + aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +Reference< uno::XComponentContext > ChartTypeTemplate::GetComponentContext() const +{ + return m_xContext; +} + +// ================================================================================ + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( ChartTypeTemplate, + C2U( "com.sun.star.comp.chart.ChartTypeTemplate" )); +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/ChartTypeTemplate.hxx b/chart2/source/model/template/ChartTypeTemplate.hxx new file mode 100644 index 000000000000..931a6357772f --- /dev/null +++ b/chart2/source/model/template/ChartTypeTemplate.hxx @@ -0,0 +1,302 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_CHARTTYPETEMPLATE_HXX +#define CHART_CHARTTYPETEMPLATE_HXX + +#include <cppuhelper/implbase2.hxx> +#include "ServiceMacros.hxx" +#include "DataInterpreter.hxx" +#include "StackMode.hxx" +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/chart2/XChartTypeTemplate.hpp> +#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> +#include <com/sun/star/chart2/XLegend.hpp> +#include <com/sun/star/lang/XServiceName.hpp> +#include <com/sun/star/chart2/XChartType.hpp> +#include <com/sun/star/chart2/XDataSeries.hpp> + +#include <utility> + +namespace chart +{ + +/** For creating diagrams and modifying existing diagrams. A base class that + implements XChartTypeTemplate and offers some tooling for classes that + derive from this class. + + createDiagramByDataSource + ------------------------- + + This does the following steps using some virtual helper-methods, that may be + overloaded by derived classes: + + * creates an XDiagram via service-factory. + + * convert the given XDataSource to a sequence of XDataSeries using the + method createDataSeries(). In this class the DataInterpreter helper class + is used to create a standard interpretation (just y-values). + + * call applyDefaultStyle() for all XDataSeries in order to apply default + styles. In this class the series get the system-wide default colors as + "Color" property. + + * call applyStyle() for applying chart-type specific styles to all series. + The default implementation is empty. + + * call createCoordinateSystems() and apply them to the diagram. As + default one cartesian system with Scales using a linear Scaling is + created. + + * createChartTypes() is called in order to define the structure of the + diagram. For details see comment of this function. As default this + method creates a tree where all series appear in one branch with the chart + type determined by getChartTypeForNewSeries(). The stacking is determined + via the method getStackMode(). + + * create an XLegend via the global service factory, set it at the diagram. + */ +class ChartTypeTemplate : public ::cppu::WeakImplHelper2< + ::com::sun::star::chart2::XChartTypeTemplate, + ::com::sun::star::lang::XServiceName > +{ +public: + explicit ChartTypeTemplate( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName ); + virtual ~ChartTypeTemplate(); + + APPHELPER_XSERVICEINFO_DECL() + /// establish methods for factory instatiation +// APPHELPER_SERVICE_FACTORY_HELPER( ChartTypeTemplate ) + +protected: + // ____ XChartTypeTemplate ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram > SAL_CALL createDiagramByDataSource( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xDataSource, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments ) + throw (::com::sun::star::uno::RuntimeException); + /// denotes if the chart needs categories at the first scale + virtual sal_Bool SAL_CALL supportsCategories() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL changeDiagram( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL changeDiagramData( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram, + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xDataSource, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL matchesTemplate( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDiagram >& xDiagram, + ::sal_Bool bAdaptProperties ) + throw (::com::sun::star::uno::RuntimeException); + // still abstract: getChartTypeForNewSeries() + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataInterpreter > SAL_CALL getDataInterpreter() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL applyStyle( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL resetStyles( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram ) + throw (::com::sun::star::uno::RuntimeException); + + // + virtual void SAL_CALL applyStyles( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ XServiceName ____ + virtual ::rtl::OUString SAL_CALL getServiceName() + throw (::com::sun::star::uno::RuntimeException); + + // Methods to overload for automatic creation + // ------------------------------------------ + + /// returns 2 by default. Supported are 2 and 3 + virtual sal_Int32 getDimension() const; + + /** returns StackMode_NONE by default. This is a global flag used for all + series of a specific chart type. If percent stacking is supported, the + percent stacking mode is retrieved from the first chart type (index 0) + + @param nChartTypeIndex denotes the index of the charttype in means + defined by the template creation order, i.e., 0 means the first + chart type that a template creates. + */ + virtual StackMode getStackMode( sal_Int32 nChartTypeIndex ) const; + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > + getChartTypeForIndex( sal_Int32 nChartTypeIndex ) = 0; + + virtual bool isSwapXAndY() const; + + // Methods for creating the diagram piecewise + // ------------------------------------------ + + /** Allows derived classes to manipulate the diagramas whole, like changing + the wall color. The default implementation is empty. It is called by + FillDiagram which is called by createDiagramByDataSource and + changeDiagram + */ + virtual void adaptDiagram( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDiagram > & xDiagram ); + + /** Creates a 2d or 3d cartesian coordinate system with mathematically + oriented, linear scales with auto-min/max. If the given + CoordinateSystemContainer is not empty, those coordinate system should + be reused. + + <p>The dimension depends on the value returned by getDimension().</p> + */ + virtual void createCoordinateSystems( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XCoordinateSystemContainer > & xOutCooSysCnt ); + + /** Sets categories at the scales of dimension 0 and the percent stacking at + the scales of dimension 1 of all given coordinate systems. + + <p>Called by FillDiagram.</p> + */ + virtual void adaptScales( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XCoordinateSystem > > & aCooSysSeq, + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::data::XLabeledDataSequence > & xCategories ); + + /** create a data series tree, that fits the requirements of the chart type. + + <p>As default, this creates a tree with the following structure:</p> + + <pre> + root + | + +-- chart type (determined by getChartTypeForNewSeries()) + | + +-- category (DiscreteStackableScaleGroup using scale 0) + | + +-- values (ContinuousStackableScaleGroup using scale 1) + | + +-- series 0 + | + +-- series 1 + | + ... + | + +.. series n-1 + </pre> + + <p>If there are less than two scales available the returned tree is + empty.</p> + */ + virtual void createChartTypes( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDataSeries > > > & aSeriesSeq, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > > & aOldChartTypesSeq + ); + + /** create axes and add them to the given container. If there are already + compatible axes in the container these should be maintained. + + <p>As default, this method creates as many axes as there are dimensions + in the given first coordinate system. Each of the axis + represents one of the dimensions of the coordinate systems. If there are series + requesting asecondary axes a secondary y axes is added</p> + */ + virtual void createAxes( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys ); + + /** Give the number of requested axis per dimension here. Default is one + axis for each dimension + */ + virtual sal_Int32 getAxisCountByDimension( sal_Int32 nDimension ); + + /** adapt properties of exsisting axes and remove superfluous axes + */ + virtual void adaptAxes( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys ); + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + GetComponentContext() const; + + static void copyPropertiesFromOldToNewCoordianteSystem( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > > & rOldChartTypesSeq, + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > & xNewChartType ); + +protected: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + m_xContext; + mutable ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDataInterpreter > m_xDataInterpreter; + +private: + const ::rtl::OUString m_aServiceName; + +private: + /** modifies the given diagram + */ + void FillDiagram( const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDiagram > & xDiagram, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDataSeries > > > & aSeriesSeq, + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::data::XLabeledDataSequence > xCategories, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > > & aOldChartTypesSeq, + bool bCreate ); +}; + +} // namespace chart + +// CHART_CHARTTYPETEMPLATE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/ColumnChartType.cxx b/chart2/source/model/template/ColumnChartType.cxx new file mode 100644 index 000000000000..c6080cb8e64b --- /dev/null +++ b/chart2/source/model/template/ColumnChartType.cxx @@ -0,0 +1,199 @@ +/* -*- 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 "ColumnChartType.hxx" +#include "macros.hxx" +#include "servicenames_charttypes.hxx" +#include "PropertyHelper.hxx" +#include "ContainerHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> + +using namespace ::com::sun::star; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::beans::Property; + +//----------------------------------------------------------------------------- + +namespace +{ + +enum +{ + PROP_BARCHARTTYPE_OVERLAP_SEQUENCE, + PROP_BARCHARTTYPE_GAPWIDTH_SEQUENCE +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "OverlapSequence" ), + PROP_BARCHARTTYPE_OVERLAP_SEQUENCE, + ::getCppuType( reinterpret_cast< const Sequence< sal_Int32 > * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "GapwidthSequence" ), + PROP_BARCHARTTYPE_GAPWIDTH_SEQUENCE, + ::getCppuType( reinterpret_cast< const Sequence< sal_Int32 > * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + Sequence< sal_Int32 > aSeq(2); + + aSeq[0] = aSeq[1] = 0; + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_BARCHARTTYPE_OVERLAP_SEQUENCE, aSeq ); + + aSeq[0] = aSeq[1] = 100; + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_BARCHARTTYPE_GAPWIDTH_SEQUENCE, aSeq ); +} + +const Sequence< Property > & lcl_GetPropertySequence() +{ + static Sequence< Property > aPropSeq; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aPropSeq.getLength() ) + { + // get properties + ::std::vector< ::com::sun::star::beans::Property > aProperties; + lcl_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; +} + +} // anonymous namespace + +namespace chart +{ + +ColumnChartType::ColumnChartType( + const uno::Reference< uno::XComponentContext > & xContext ) : + ChartType( xContext ) +{} + +ColumnChartType::ColumnChartType( const ColumnChartType & rOther ) : + ChartType( rOther ) +{ +} + +ColumnChartType::~ColumnChartType() +{} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL ColumnChartType::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new ColumnChartType( *this )); +} + +// ____ XChartType ____ +::rtl::OUString SAL_CALL ColumnChartType::getChartType() + throw (uno::RuntimeException) +{ + return CHART2_SERVICE_NAME_CHARTTYPE_COLUMN; +} + +// ____ OPropertySet ____ +uno::Any ColumnChartType::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 ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; +} + +::cppu::IPropertyArrayHelper & SAL_CALL ColumnChartType::getInfoHelper() +{ + static ::cppu::OPropertyArrayHelper aArrayHelper( lcl_GetPropertySequence(), + /* bSorted = */ sal_True ); + return aArrayHelper; +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + ColumnChartType::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + getInfoHelper()); + } + + return xInfo; +} + + +uno::Sequence< ::rtl::OUString > ColumnChartType::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 2 ); + aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_COLUMN; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( ColumnChartType, + C2U( "com.sun.star.comp.chart.ColumnChartType" )); + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/ColumnChartType.hxx b/chart2/source/model/template/ColumnChartType.hxx new file mode 100644 index 000000000000..5306982c0e8c --- /dev/null +++ b/chart2/source/model/template/ColumnChartType.hxx @@ -0,0 +1,77 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_COLUMNCHARTTYPE_HXX +#define CHART_COLUMNCHARTTYPE_HXX + +#include "ChartType.hxx" +#include "ServiceMacros.hxx" + +namespace chart +{ + +class ColumnChartType : public ChartType +{ +public: + ColumnChartType( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~ColumnChartType(); + + APPHELPER_XSERVICEINFO_DECL() + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( ColumnChartType ) + +protected: + explicit ColumnChartType( const ColumnChartType & rOther ); + + // ____ XChartType ____ + virtual ::rtl::OUString SAL_CALL getChartType() + throw (::com::sun::star::uno::RuntimeException); + + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XCloneable ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() + throw (::com::sun::star::uno::RuntimeException); +}; + +} // namespace chart + +// CHART_COLUMNCHARTTYPE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/ColumnLineChartTypeTemplate.cxx b/chart2/source/model/template/ColumnLineChartTypeTemplate.cxx new file mode 100644 index 000000000000..716fe9dce6c5 --- /dev/null +++ b/chart2/source/model/template/ColumnLineChartTypeTemplate.cxx @@ -0,0 +1,451 @@ +/* -*- 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 "ColumnLineChartTypeTemplate.hxx" +#include "macros.hxx" +#include "CommonConverters.hxx" +#include "DiagramHelper.hxx" +#include "DataSeriesHelper.hxx" +#include "servicenames_charttypes.hxx" +#include "ColumnLineDataInterpreter.hxx" +#include "ContainerHelper.hxx" +#include "PropertyHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/chart2/XChartTypeContainer.hpp> +#include <com/sun/star/chart2/XDataSeriesContainer.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> + +#include <algorithm> + +using namespace ::com::sun::star::chart2; +using namespace ::com::sun::star; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +namespace +{ + +static const ::rtl::OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.ColumnLineChartTypeTemplate" )); + +enum +{ + PROP_COL_LINE_NUMBER_OF_LINES +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "NumberOfLines" ), + PROP_COL_LINE_NUMBER_OF_LINES, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_COL_LINE_NUMBER_OF_LINES, 1 ); +} + +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 ); + + // 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; +} + +} // anonymous namespace + +namespace chart +{ + +ColumnLineChartTypeTemplate::ColumnLineChartTypeTemplate( + Reference< + uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName, + StackMode eStackMode, + sal_Int32 nNumberOfLines ) : + ChartTypeTemplate( xContext, rServiceName ), + ::property::OPropertySet( m_aMutex ), + m_eStackMode( eStackMode ) +{ + setFastPropertyValue_NoBroadcast( PROP_COL_LINE_NUMBER_OF_LINES, uno::makeAny( nNumberOfLines )); +} + +ColumnLineChartTypeTemplate::~ColumnLineChartTypeTemplate() +{} + +// ____ OPropertySet ____ +uno::Any ColumnLineChartTypeTemplate::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 ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; +} + +::cppu::IPropertyArrayHelper & SAL_CALL ColumnLineChartTypeTemplate::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + ColumnLineChartTypeTemplate::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; +} + +void ColumnLineChartTypeTemplate::createChartTypes( + const Sequence< Sequence< Reference< XDataSeries > > > & aSeriesSeq, + const Sequence< Reference< XCoordinateSystem > > & rCoordSys, + const Sequence< Reference< XChartType > >& aOldChartTypesSeq ) +{ + if( rCoordSys.getLength() == 0 || + ! rCoordSys[0].is() ) + return; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + Sequence< Reference< XDataSeries > > aFlatSeriesSeq( FlattenSequence( aSeriesSeq )); + sal_Int32 nNumberOfSeries = aFlatSeriesSeq.getLength(); + sal_Int32 nNumberOfLines = 0; + sal_Int32 nNumberOfColumns = 0; + + getFastPropertyValue( PROP_COL_LINE_NUMBER_OF_LINES ) >>= nNumberOfLines; + OSL_ENSURE( nNumberOfLines>=0, "number of lines should be not negative" ); + if( nNumberOfLines < 0 ) + nNumberOfLines = 0; + + if( nNumberOfLines >= nNumberOfSeries ) + { + if( nNumberOfSeries > 0 ) + { + nNumberOfLines = nNumberOfSeries - 1; + nNumberOfColumns = 1; + } + else + nNumberOfLines = 0; + } + else + nNumberOfColumns = nNumberOfSeries - nNumberOfLines; + + // Columns + // ------- + Reference< XChartType > xCT( + xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_COLUMN ), uno::UNO_QUERY_THROW ); + + ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aOldChartTypesSeq, xCT ); + + Reference< XChartTypeContainer > xCTCnt( rCoordSys[ 0 ], uno::UNO_QUERY_THROW ); + xCTCnt->setChartTypes( Sequence< Reference< chart2::XChartType > >( &xCT, 1 )); + + if( nNumberOfColumns > 0 ) + { + Reference< XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW ); + Sequence< Reference< XDataSeries > > aColumnSeq( nNumberOfColumns ); + ::std::copy( aFlatSeriesSeq.getConstArray(), + aFlatSeriesSeq.getConstArray() + nNumberOfColumns, + aColumnSeq.getArray()); + xDSCnt->setDataSeries( aColumnSeq ); + } + + // Lines + // ----- + xCT.set( xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_LINE ), uno::UNO_QUERY_THROW ); + xCTCnt.set( rCoordSys[ 0 ], uno::UNO_QUERY_THROW ); + xCTCnt->addChartType( xCT ); + + if( nNumberOfLines > 0 ) + { + Reference< XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW ); + Sequence< Reference< XDataSeries > > aLineSeq( nNumberOfLines ); + ::std::copy( aFlatSeriesSeq.getConstArray() + nNumberOfColumns, + aFlatSeriesSeq.getConstArray() + aFlatSeriesSeq.getLength(), + aLineSeq.getArray()); + xDSCnt->setDataSeries( aLineSeq ); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +void SAL_CALL ColumnLineChartTypeTemplate::applyStyle( + const Reference< chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (uno::RuntimeException) +{ + ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount ); + + if( nChartTypeIndex==0 ) // columns + { + DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) ); + } + else if( nChartTypeIndex==1 ) // lines + { + Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY ); + if( xProp.is() ) + { + DataSeriesHelper::switchLinesOnOrOff( xProp, true ); + DataSeriesHelper::switchSymbolsOnOrOff( xProp, false, nSeriesIndex ); + DataSeriesHelper::makeLinesThickOrThin( xProp, true ); + } + } +} + +StackMode ColumnLineChartTypeTemplate::getStackMode( sal_Int32 nChartTypeIndex ) const +{ + if( nChartTypeIndex == 0 ) + return m_eStackMode; + return StackMode_NONE; +} + +// ____ XChartTypeTemplate ____ +sal_Bool SAL_CALL ColumnLineChartTypeTemplate::matchesTemplate( + const uno::Reference< XDiagram >& xDiagram, + sal_Bool bAdaptProperties ) + throw (uno::RuntimeException) +{ + sal_Bool bResult = sal_False; + + if( ! xDiagram.is()) + return bResult; + + try + { + Reference< chart2::XChartType > xColumnChartType; + Reference< XCoordinateSystem > xColumnChartCooSys; + Reference< chart2::XChartType > xLineChartType; + sal_Int32 nNumberOfChartTypes = 0; + + Reference< XCoordinateSystemContainer > xCooSysCnt( + xDiagram, uno::UNO_QUERY_THROW ); + Sequence< Reference< XCoordinateSystem > > aCooSysSeq( + xCooSysCnt->getCoordinateSystems()); + for( sal_Int32 i=0; i<aCooSysSeq.getLength(); ++i ) + { + Reference< XChartTypeContainer > xCTCnt( aCooSysSeq[i], uno::UNO_QUERY_THROW ); + Sequence< Reference< XChartType > > aChartTypeSeq( xCTCnt->getChartTypes()); + for( sal_Int32 j=0; j<aChartTypeSeq.getLength(); ++j ) + { + if( aChartTypeSeq[j].is()) + { + ++nNumberOfChartTypes; + if( nNumberOfChartTypes > 2 ) + break; + OUString aCTService = aChartTypeSeq[j]->getChartType(); + if( aCTService.equals( CHART2_SERVICE_NAME_CHARTTYPE_COLUMN )) + { + xColumnChartType.set( aChartTypeSeq[j] ); + xColumnChartCooSys.set( aCooSysSeq[i] ); + } + else if( aCTService.equals( CHART2_SERVICE_NAME_CHARTTYPE_LINE )) + xLineChartType.set( aChartTypeSeq[j] ); + } + } + if( nNumberOfChartTypes > 2 ) + break; + } + + if( nNumberOfChartTypes == 2 && + xColumnChartType.is() && + xLineChartType.is()) + { + OSL_ASSERT( xColumnChartCooSys.is()); + + // check stackmode of bars + bResult = (xColumnChartCooSys->getDimension() == getDimension()); + if( bResult ) + { + bool bFound=false; + bool bAmbiguous=false; + bResult = ( DiagramHelper::getStackModeFromChartType( + xColumnChartType, bFound, bAmbiguous, + xColumnChartCooSys ) + == getStackMode( 0 ) ); + + if( bResult && bAdaptProperties ) + { + Reference< XDataSeriesContainer > xSeriesContainer( xLineChartType, uno::UNO_QUERY ); + if( xSeriesContainer.is() ) + { + sal_Int32 nNumberOfLines = xSeriesContainer->getDataSeries().getLength(); + setFastPropertyValue_NoBroadcast( PROP_COL_LINE_NUMBER_OF_LINES, uno::makeAny( nNumberOfLines )); + } + } + } + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return bResult; +} + +Reference< chart2::XChartType > ColumnLineChartTypeTemplate::getChartTypeForIndex( sal_Int32 nChartTypeIndex ) +{ + Reference< chart2::XChartType > xCT; + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY ); + if(xFact.is()) + { + if( nChartTypeIndex == 0 ) + xCT.set( xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_COLUMN ), uno::UNO_QUERY ); + else + xCT.set( xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_LINE ), uno::UNO_QUERY ); + } + return xCT; +} + +Reference< XChartType > SAL_CALL ColumnLineChartTypeTemplate::getChartTypeForNewSeries( + const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (uno::RuntimeException) +{ + Reference< chart2::XChartType > xResult; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + xResult.set( xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_LINE ), uno::UNO_QUERY_THROW ); + ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return xResult; +} + +Reference< XDataInterpreter > SAL_CALL ColumnLineChartTypeTemplate::getDataInterpreter() + throw (uno::RuntimeException) +{ + if( ! m_xDataInterpreter.is()) + { + sal_Int32 nNumberOfLines = 1; + getFastPropertyValue( PROP_COL_LINE_NUMBER_OF_LINES ) >>= nNumberOfLines; + m_xDataInterpreter.set( new ColumnLineDataInterpreter( nNumberOfLines, GetComponentContext() ) ); + } + else + { + //todo... + OSL_ENSURE( false, "number of lines may not be valid anymore in the datainterpreter" ); + + } + + return m_xDataInterpreter; +} + +// ---------------------------------------- + +uno::Sequence< ::rtl::OUString > ColumnLineChartTypeTemplate::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 2 ); + aServices[ 0 ] = lcl_aServiceName; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( ColumnLineChartTypeTemplate, lcl_aServiceName ); + +IMPLEMENT_FORWARD_XINTERFACE2( ColumnLineChartTypeTemplate, ChartTypeTemplate, OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( ColumnLineChartTypeTemplate, ChartTypeTemplate, OPropertySet ) + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/ColumnLineChartTypeTemplate.hxx b/chart2/source/model/template/ColumnLineChartTypeTemplate.hxx new file mode 100644 index 000000000000..ad5fc430d1b7 --- /dev/null +++ b/chart2/source/model/template/ColumnLineChartTypeTemplate.hxx @@ -0,0 +1,122 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_COLUMNLINECHARTTYPETEMPLATE_HXX +#define CHART_COLUMNLINECHARTTYPETEMPLATE_HXX + +#include "ChartTypeTemplate.hxx" +#include "StackMode.hxx" + +#include "OPropertySet.hxx" +#include "MutexContainer.hxx" +#include <comphelper/uno3.hxx> + +namespace chart +{ + +class ColumnLineChartTypeTemplate : + public MutexContainer, + public ChartTypeTemplate, + public ::property::OPropertySet +{ +public: + explicit ColumnLineChartTypeTemplate( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName, + StackMode eStackMode, + sal_Int32 nNumberOfLines ); + virtual ~ColumnLineChartTypeTemplate(); + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XChartTypeTemplate ____ + virtual sal_Bool SAL_CALL matchesTemplate( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDiagram >& xDiagram, + sal_Bool bAdaptProperties ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > SAL_CALL + getChartTypeForNewSeries( const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL applyStyle( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeGroupIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataInterpreter > SAL_CALL getDataInterpreter() + throw (::com::sun::star::uno::RuntimeException); + + // ____ ChartTypeTemplate ____ + virtual void createChartTypes( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDataSeries > > > & aSeriesSeq, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > > & aOldChartTypesSeq + ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > + getChartTypeForIndex( sal_Int32 nChartTypeIndex ); + + virtual StackMode getStackMode( sal_Int32 nChartTypeIndex ) const; + +private: + StackMode m_eStackMode; +}; + +} // namespace chart + +// CHART_COLUMNLINECHARTTYPETEMPLATE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/ColumnLineDataInterpreter.cxx b/chart2/source/model/template/ColumnLineDataInterpreter.cxx new file mode 100644 index 000000000000..d98ce6500c42 --- /dev/null +++ b/chart2/source/model/template/ColumnLineDataInterpreter.cxx @@ -0,0 +1,102 @@ +/* -*- 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 "ColumnLineDataInterpreter.hxx" +#include "DataSeries.hxx" +#include "macros.hxx" +#include "DataSeriesHelper.hxx" +#include "CommonConverters.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/chart2/data/XDataSink.hpp> + +#include <vector> +#include <algorithm> +#include <iterator> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; +using namespace ::std; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; + +namespace chart +{ + +// explicit +ColumnLineDataInterpreter::ColumnLineDataInterpreter( + sal_Int32 nNumberOfLines, + const Reference< uno::XComponentContext > & xContext ) : + DataInterpreter( xContext ), + m_nNumberOfLines( nNumberOfLines ) +{} + +ColumnLineDataInterpreter::~ColumnLineDataInterpreter() +{} + +// ____ XDataInterpreter ____ +InterpretedData SAL_CALL ColumnLineDataInterpreter::interpretDataSource( + const Reference< data::XDataSource >& xSource, + const Sequence< beans::PropertyValue >& aArguments, + const Sequence< Reference< XDataSeries > >& aSeriesToReUse ) + throw (uno::RuntimeException) +{ + InterpretedData aResult( DataInterpreter::interpretDataSource( xSource, aArguments, aSeriesToReUse )); + + // the base class should return one group + OSL_ASSERT( aResult.Series.getLength() == 1 ); + if( aResult.Series.getLength() == 1 ) + { + sal_Int32 nNumberOfSeries = aResult.Series[0].getLength(); + + // if we have more than one series put the last nNumOfLines ones into a new group + if( nNumberOfSeries > 1 && m_nNumberOfLines > 0 ) + { + sal_Int32 nNumOfLines = ::std::min( m_nNumberOfLines, nNumberOfSeries - 1 ); + aResult.Series.realloc(2); + + Sequence< Reference< XDataSeries > > & rColumnDataSeries = aResult.Series[0]; + Sequence< Reference< XDataSeries > > & rLineDataSeries = aResult.Series[1]; + rLineDataSeries.realloc( nNumOfLines ); + ::std::copy( rColumnDataSeries.getConstArray() + nNumberOfSeries - nNumOfLines, + rColumnDataSeries.getConstArray() + nNumberOfSeries, + rLineDataSeries.getArray() ); + rColumnDataSeries.realloc( nNumberOfSeries - nNumOfLines ); + } + } + + return aResult; +} + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/ColumnLineDataInterpreter.hxx b/chart2/source/model/template/ColumnLineDataInterpreter.hxx new file mode 100644 index 000000000000..69f79cdaece9 --- /dev/null +++ b/chart2/source/model/template/ColumnLineDataInterpreter.hxx @@ -0,0 +1,62 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_COLUMNLINEDATAINTERPRETER_HXX +#define CHART_COLUMNLINEDATAINTERPRETER_HXX + +#include "DataInterpreter.hxx" + +namespace chart +{ + +class ColumnLineDataInterpreter : public DataInterpreter +{ +public: + explicit ColumnLineDataInterpreter( + sal_Int32 nNumberOfLines, + const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext ); + ~ColumnLineDataInterpreter(); + +protected: + // ____ XDataInterpreter ____ + virtual ::com::sun::star::chart2::InterpretedData SAL_CALL interpretDataSource( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xSource, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments, + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >& aSeriesToReUse ) + throw (::com::sun::star::uno::RuntimeException); + +private: + sal_Int32 m_nNumberOfLines; +}; + +} // namespace chart + +// CHART_COLUMNLINEDATAINTERPRETER_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/DataInterpreter.cxx b/chart2/source/model/template/DataInterpreter.cxx new file mode 100644 index 000000000000..5f23e2bbc670 --- /dev/null +++ b/chart2/source/model/template/DataInterpreter.cxx @@ -0,0 +1,460 @@ +/* -*- 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 "DataInterpreter.hxx" +#include "DataSeries.hxx" +#include "DataSourceHelper.hxx" +#include "DataSeriesHelper.hxx" +#include "macros.hxx" +#include "CommonConverters.hxx" +#include "ContainerHelper.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/chart2/data/XDataSink.hpp> + +#include <vector> +#include <algorithm> +#include <iterator> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; +using namespace ::std; +using namespace ::chart::ContainerHelper; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; + +#if OSL_DEBUG_LEVEL > 1 +namespace +{ +void lcl_ShowDataSource( const Reference< data::XDataSource > & xSource ); +} +#endif + +namespace chart +{ + +DataInterpreter::DataInterpreter( + const Reference< uno::XComponentContext > & xContext ) : + m_xContext( xContext ) +{} + +DataInterpreter::~DataInterpreter() +{} + +Reference< uno::XComponentContext > DataInterpreter::GetComponentContext() const +{ + return m_xContext; +} + +// ____ XDataInterpreter ____ +InterpretedData SAL_CALL DataInterpreter::interpretDataSource( + const Reference< data::XDataSource >& xSource, + const Sequence< beans::PropertyValue >& aArguments, + const Sequence< Reference< XDataSeries > >& aSeriesToReUse ) + throw (uno::RuntimeException) +{ + if( ! xSource.is()) + return InterpretedData(); + +#if OSL_DEBUG_LEVEL > 2 + lcl_ShowDataSource( xSource ); +#endif + + Sequence< Reference< data::XLabeledDataSequence > > aData( xSource->getDataSequences() ); + + Reference< data::XLabeledDataSequence > xCategories; + vector< Reference< data::XLabeledDataSequence > > aSequencesVec; + + // check if we should use categories + + bool bHasCategories( HasCategories( aArguments, aData )); + + // parse data + bool bCategoriesUsed = false; + for( sal_Int32 i=0; i < aData.getLength(); ++i ) + { + try + { + if( bHasCategories && ! bCategoriesUsed ) + { + xCategories.set( aData[i] ); + if( xCategories.is()) + SetRole( xCategories->getValues(), C2U("categories")); + bCategoriesUsed = true; + } + else + { + aSequencesVec.push_back( aData[i] ); + if( aData[i].is()) + SetRole( aData[i]->getValues(), C2U("values-y")); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + // create DataSeries + vector< Reference< data::XLabeledDataSequence > >::const_iterator + aSequencesVecIt = aSequencesVec.begin(); + + sal_Int32 nSeriesIndex = 0; + vector< Reference< XDataSeries > > aSeriesVec; + aSeriesVec.reserve( aSequencesVec.size()); + + for( ;aSequencesVecIt != aSequencesVec.end(); ++aSequencesVecIt, ++nSeriesIndex ) + { + Sequence< Reference< data::XLabeledDataSequence > > aNewData( & (*aSequencesVecIt), 1 ); + Reference< XDataSeries > xSeries; + if( nSeriesIndex < aSeriesToReUse.getLength()) + xSeries.set( aSeriesToReUse[nSeriesIndex] ); + else + xSeries.set( new DataSeries( GetComponentContext() )); + OSL_ASSERT( xSeries.is() ); + Reference< data::XDataSink > xSink( xSeries, uno::UNO_QUERY ); + OSL_ASSERT( xSink.is() ); + xSink->setData( aNewData ); + + aSeriesVec.push_back( xSeries ); + } + + Sequence< Sequence< Reference< XDataSeries > > > aSeries(1); + aSeries[0] = ContainerToSequence( aSeriesVec ); + return InterpretedData( aSeries, xCategories ); +} + +InterpretedData SAL_CALL DataInterpreter::reinterpretDataSeries( + const InterpretedData& aInterpretedData ) + throw (uno::RuntimeException) +{ + InterpretedData aResult( aInterpretedData ); + + sal_Int32 i=0; + Sequence< Reference< XDataSeries > > aSeries( FlattenSequence( aInterpretedData.Series )); + const sal_Int32 nCount = aSeries.getLength(); + for( ; i<nCount; ++i ) + { + try + { + Reference< data::XDataSource > xSeriesSource( aSeries[i], uno::UNO_QUERY_THROW ); + Sequence< Reference< data::XLabeledDataSequence > > aNewSequences; + + // values-y + Reference< data::XLabeledDataSequence > xValuesY( + DataSeriesHelper::getDataSequenceByRole( xSeriesSource, C2U("values-y"), false )); + // re-use values-... as values-y + if( ! xValuesY.is()) + { + xValuesY.set( + DataSeriesHelper::getDataSequenceByRole( xSeriesSource, C2U("values"), true )); + if( xValuesY.is()) + SetRole( xValuesY->getValues(), C2U("values-y")); + } + if( xValuesY.is()) + { + aNewSequences.realloc(1); + aNewSequences[0] = xValuesY; + } + + Sequence< Reference< data::XLabeledDataSequence > > aSeqs( xSeriesSource->getDataSequences()); + if( aSeqs.getLength() != aNewSequences.getLength() ) + { +#if OSL_DEBUG_LEVEL > 1 + sal_Int32 j=0; + for( ; j<aSeqs.getLength(); ++j ) + { + OSL_ENSURE( aSeqs[j] == xValuesY, "All sequences should be used" ); + } +#endif + Reference< data::XDataSink > xSink( xSeriesSource, uno::UNO_QUERY_THROW ); + xSink->setData( aNewSequences ); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + return aResult; +} + +// criterion: all series must have exactly one data::XLabeledDataSequence +sal_Bool SAL_CALL DataInterpreter::isDataCompatible( + const chart2::InterpretedData& aInterpretedData ) + throw (uno::RuntimeException) +{ + Sequence< Reference< XDataSeries > > aSeries( FlattenSequence( aInterpretedData.Series )); + for( sal_Int32 i=0; i<aSeries.getLength(); ++i ) + { + try + { + Reference< data::XDataSource > xSrc( aSeries[i], uno::UNO_QUERY_THROW ); + Sequence< Reference< data::XLabeledDataSequence > > aSeq( xSrc->getDataSequences()); + if( aSeq.getLength() != 1 ) + return sal_False; + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + return sal_True; +} + +namespace +{ + +struct lcl_LabeledSequenceEquals : public std::unary_function< Reference< data::XLabeledDataSequence >, bool > +{ + lcl_LabeledSequenceEquals( const Reference< data::XLabeledDataSequence > & xLSeqToCmp ) : + m_bHasLabels ( false ), + m_bHasValues ( false ) + { + if( xLSeqToCmp.is()) + { + Reference< data::XDataSequence > xSeq( xLSeqToCmp->getValues()); + if( xSeq.is()) + { + m_bHasValues = true; + m_aValuesRangeRep = xSeq->getSourceRangeRepresentation(); + } + + xSeq.set( xLSeqToCmp->getLabel()); + if( xSeq.is()) + { + m_bHasLabels = true; + m_aLabelRangeRep = xSeq->getSourceRangeRepresentation(); + } + } + } + + bool operator() ( const Reference< data::XLabeledDataSequence > & xSeq ) + { + if( ! xSeq.is()) + return false; + + Reference< data::XDataSequence > xSeqValues( xSeq->getValues() ); + Reference< data::XDataSequence > xSeqLabels( xSeq->getLabel() ); + bool bHasValues = xSeqValues.is(); + bool bHasLabels = xSeqLabels.is(); + + return ( ( (m_bHasValues == bHasValues) && + (!bHasValues || m_aValuesRangeRep.equals( xSeqValues->getSourceRangeRepresentation())) ) && + ( (m_bHasLabels == bHasLabels) && + (!bHasLabels || m_aLabelRangeRep.equals( xSeqLabels->getSourceRangeRepresentation())) ) + ); + } + +private: + bool m_bHasLabels; + bool m_bHasValues; + OUString m_aValuesRangeRep; + OUString m_aLabelRangeRep; +}; + +} // anonymous namespace + +Reference< data::XDataSource > SAL_CALL DataInterpreter::mergeInterpretedData( + const InterpretedData& aInterpretedData ) + throw (uno::RuntimeException) +{ + vector< Reference< data::XLabeledDataSequence > > aResultVec; + aResultVec.reserve( aInterpretedData.Series.getLength() + + 1 // categories + ); + + if( aInterpretedData.Categories.is()) + aResultVec.push_back( aInterpretedData.Categories ); + + Sequence< Reference< XDataSeries > > aSeries( FlattenSequence( aInterpretedData.Series )); + for( sal_Int32 nSeriesIdx=0; nSeriesIdx<aSeries.getLength(); ++nSeriesIdx ) + { + try + { + Reference< data::XDataSource > xSrc( aSeries[nSeriesIdx], uno::UNO_QUERY_THROW ); + Sequence< Reference< data::XLabeledDataSequence > > aSeq( xSrc->getDataSequences()); + + // add all sequences of data series + for( sal_Int32 nSeqIdx=0; nSeqIdx<aSeq.getLength(); ++nSeqIdx ) + { + Reference< data::XLabeledDataSequence > xAdd( aSeq[nSeqIdx] ); + + // only add if sequence is not yet in the result + if( find_if( aResultVec.begin(), aResultVec.end(), + lcl_LabeledSequenceEquals( xAdd )) == aResultVec.end()) + { + aResultVec.push_back( xAdd ); + } + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + return Reference< data::XDataSource >( DataSourceHelper::createDataSource( ContainerToSequence( aResultVec ) ) ); +} + +// convenience methods + +OUString DataInterpreter::GetRole( const Reference< data::XDataSequence > & xSeq ) +{ + OUString aResult; + if( ! xSeq.is()) + return aResult; + + try + { + Reference< beans::XPropertySet > xProp( xSeq, uno::UNO_QUERY_THROW ); + xProp->getPropertyValue( C2U("Role")) >>= aResult; + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + return aResult; +} + +void DataInterpreter::SetRole( const Reference< data::XDataSequence > & xSeq, const OUString & rRole ) +{ + if( ! xSeq.is()) + return; + try + { + Reference< beans::XPropertySet > xProp( xSeq, uno::UNO_QUERY_THROW ); + xProp->setPropertyValue( C2U("Role"), uno::makeAny( rRole )); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +uno::Any DataInterpreter::GetProperty( + const Sequence< beans::PropertyValue > & aArguments, + const OUString & rName ) +{ + for( sal_Int32 i=aArguments.getLength(); i--; ) + { + if( aArguments[i].Name.equals( rName )) + return aArguments[i].Value; + } + return uno::Any(); +} + +bool DataInterpreter::HasCategories( + const Sequence< beans::PropertyValue > & rArguments, + const Sequence< Reference< data::XLabeledDataSequence > > & rData ) +{ + bool bHasCategories = false; + + if( rArguments.getLength() > 0 ) + GetProperty( rArguments, C2U(("HasCategories"))) >>= bHasCategories; + + for( sal_Int32 nLSeqIdx=0; ! bHasCategories && nLSeqIdx<rData.getLength(); ++nLSeqIdx ) + bHasCategories = ( rData[nLSeqIdx].is() && + GetRole( rData[nLSeqIdx]->getValues()).equalsAsciiL(RTL_CONSTASCII_STRINGPARAM("categories"))); + + return bHasCategories; +} + +// ------------------------------------------------------------ + +Sequence< OUString > DataInterpreter::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 1 ); + aServices[0] = C2U( "com.sun.star.chart2.DataInterpreter" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( DataInterpreter, C2U("com.sun.star.comp.chart2.DataInterpreter")); + +} // namespace chart + +#if OSL_DEBUG_LEVEL > 1 +namespace +{ + +void lcl_ShowDataSource( const Reference< data::XDataSource > & xSource ) +{ + if( ! xSource.is()) + return; + + OSL_TRACE( "DataSource in DataInterpreter:" ); + Sequence< Reference< data::XLabeledDataSequence > > aSequences( xSource->getDataSequences()); + Reference< beans::XPropertySet > xProp; + OUString aId; + const sal_Int32 nMax = aSequences.getLength(); + for( sal_Int32 k = 0; k < nMax; ++k ) + { + if( aSequences[k].is()) + { + OUString aSourceRepr(C2U("<none>")); + if( aSequences[k]->getValues().is()) + aSourceRepr = aSequences[k]->getValues()->getSourceRangeRepresentation(); + xProp.set( aSequences[k]->getValues(), uno::UNO_QUERY ); + if( xProp.is() && + ( xProp->getPropertyValue( C2U( "Role" )) >>= aId )) + { + OSL_TRACE( " <data sequence %d> Role: %s, Source: %s", k, U2C( aId ), U2C( aSourceRepr )); + } + else + { + OSL_TRACE( " <data sequence %d> unknown Role, Source: %s", k, U2C( aSourceRepr ) ); + } + + aSourceRepr = C2U("<none>"); + if( aSequences[k]->getLabel().is()) + aSourceRepr = OUString( aSequences[k]->getLabel()->getSourceRangeRepresentation()); + xProp.set( aSequences[k]->getLabel(), uno::UNO_QUERY ); + if( xProp.is() && + ( xProp->getPropertyValue( C2U( "Role" )) >>= aId )) + { + OSL_TRACE( " <data sequence label %d> Role: %s, Source: %s", k, U2C( aId ), U2C( aSourceRepr )); + } + else + { + OSL_TRACE( " <data sequence label %d> unknown Role, Source: %s", k, U2C( aSourceRepr ) ); + } + } + } +} + +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/DataInterpreter.hxx b/chart2/source/model/template/DataInterpreter.hxx new file mode 100644 index 000000000000..5133a39de7a8 --- /dev/null +++ b/chart2/source/model/template/DataInterpreter.hxx @@ -0,0 +1,103 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_DATAINTERPRETER_HXX +#define CHART_DATAINTERPRETER_HXX + +#include "ServiceMacros.hxx" +#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/chart2/XDataInterpreter.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +namespace chart +{ + +class DataInterpreter : public ::cppu::WeakImplHelper2< + ::com::sun::star::chart2::XDataInterpreter, + ::com::sun::star::lang::XServiceInfo > +{ +public: + explicit DataInterpreter( const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext ); + virtual ~DataInterpreter(); + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + GetComponentContext() const; + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + // convenience methods + static ::rtl::OUString GetRole( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::data::XDataSequence > & xSeq ); + + static void SetRole( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::data::XDataSequence > & xSeq, + const ::rtl::OUString & rRole ); + + static ::com::sun::star::uno::Any GetProperty( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue > & aArguments, + const ::rtl::OUString & rName ); + + static bool HasCategories( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue > & rArguments, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::data::XLabeledDataSequence > > & rData ); + +protected: + // ____ XDataInterpreter ____ + virtual ::com::sun::star::chart2::InterpretedData SAL_CALL interpretDataSource( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xSource, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments, + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >& aSeriesToReUse ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::chart2::InterpretedData SAL_CALL reinterpretDataSeries( + const ::com::sun::star::chart2::InterpretedData& aInterpretedData ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isDataCompatible( + const ::com::sun::star::chart2::InterpretedData& aInterpretedData ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource > SAL_CALL mergeInterpretedData( + const ::com::sun::star::chart2::InterpretedData& aInterpretedData ) + throw (::com::sun::star::uno::RuntimeException); + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + m_xContext; +}; + +} // namespace chart + +// CHART_DATAINTERPRETER_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/FilledNetChartType.cxx b/chart2/source/model/template/FilledNetChartType.cxx new file mode 100644 index 000000000000..ec9e6d6d945a --- /dev/null +++ b/chart2/source/model/template/FilledNetChartType.cxx @@ -0,0 +1,97 @@ +/* -*- 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 "FilledNetChartType.hxx" +#include "PropertyHelper.hxx" +#include "macros.hxx" +#include "PolarCoordinateSystem.hxx" +#include "Scaling.hxx" +#include "servicenames_charttypes.hxx" +#include "ContainerHelper.hxx" +#include "AxisIndexDefines.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/chart2/AxisType.hpp> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; + +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +namespace chart +{ + +FilledNetChartType::FilledNetChartType( + const uno::Reference< uno::XComponentContext > & xContext ) : + NetChartType_Base( xContext ) +{} + +FilledNetChartType::FilledNetChartType( const FilledNetChartType & rOther ) : + NetChartType_Base( rOther ) +{ +} + +FilledNetChartType::~FilledNetChartType() +{} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL FilledNetChartType::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new FilledNetChartType( *this )); +} + +// ____ XChartType ____ +::rtl::OUString SAL_CALL FilledNetChartType::getChartType() + throw (uno::RuntimeException) +{ + return CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET; +} + +uno::Sequence< ::rtl::OUString > FilledNetChartType::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 3 ); + aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" ); + aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( FilledNetChartType, + C2U( "com.sun.star.comp.chart.FilledNetChartType" )); + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/FilledNetChartType.hxx b/chart2/source/model/template/FilledNetChartType.hxx new file mode 100644 index 000000000000..8faf481dfd5d --- /dev/null +++ b/chart2/source/model/template/FilledNetChartType.hxx @@ -0,0 +1,66 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_FILLEDNETCHARTTYPE_HXX +#define CHART_FILLEDNETCHARTTYPE_HXX + +#include "NetChartType.hxx" +#include "ServiceMacros.hxx" + +namespace chart +{ + +class FilledNetChartType : public NetChartType_Base +{ +public: + FilledNetChartType( ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~FilledNetChartType(); + + APPHELPER_XSERVICEINFO_DECL() + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( FilledNetChartType ) + +protected: + explicit FilledNetChartType( const FilledNetChartType & rOther ); + + // ____ XChartType ____ + virtual ::rtl::OUString SAL_CALL getChartType() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XCloneable ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() + throw (::com::sun::star::uno::RuntimeException); +}; + +} // namespace chart + +// CHART_FILLEDNETCHARTTYPE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/LineChartType.cxx b/chart2/source/model/template/LineChartType.cxx new file mode 100644 index 000000000000..9d1c8eeac7a7 --- /dev/null +++ b/chart2/source/model/template/LineChartType.cxx @@ -0,0 +1,212 @@ +/* -*- 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 "LineChartType.hxx" +#include "PropertyHelper.hxx" +#include "macros.hxx" +#include "servicenames_charttypes.hxx" +#include "ContainerHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/chart2/CurveStyle.hpp> + +using namespace ::com::sun::star; + +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +namespace +{ + +enum +{ + PROP_LINECHARTTYPE_CURVE_STYLE, + PROP_LINECHARTTYPE_CURVE_RESOLUTION, + PROP_LINECHARTTYPE_SPLINE_ORDER +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "CurveStyle" ), + PROP_LINECHARTTYPE_CURVE_STYLE, + ::getCppuType( reinterpret_cast< const chart2::CurveStyle * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "CurveResolution" ), + PROP_LINECHARTTYPE_CURVE_RESOLUTION, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "SplineOrder" ), + PROP_LINECHARTTYPE_SPLINE_ORDER, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LINECHARTTYPE_CURVE_STYLE, ::chart2::CurveStyle_LINES ); + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINECHARTTYPE_CURVE_RESOLUTION, 20 ); + + // todo: check whether order 3 means polygons of order 3 or 2. (see + // http://www.people.nnov.ru/fractal/Splines/Basis.htm ) + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINECHARTTYPE_SPLINE_ORDER, 3 ); +} + +const Sequence< Property > & lcl_GetPropertySequence() +{ + static Sequence< Property > aPropSeq; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aPropSeq.getLength() ) + { + // get properties + ::std::vector< ::com::sun::star::beans::Property > aProperties; + lcl_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; +} + +} // anonymous namespace + +namespace chart +{ + +LineChartType::LineChartType( + const uno::Reference< uno::XComponentContext > & xContext ) : + ChartType( xContext ) +{ +} + +LineChartType::LineChartType( const LineChartType & rOther ) : + ChartType( rOther ) +{ +} + +LineChartType::~LineChartType() +{} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL LineChartType::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new LineChartType( *this )); +} + +// ____ XChartType ____ +::rtl::OUString SAL_CALL LineChartType::getChartType() + throw (uno::RuntimeException) +{ + return CHART2_SERVICE_NAME_CHARTTYPE_LINE; +} + + +// ____ OPropertySet ____ +uno::Any LineChartType::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 ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; +} + +::cppu::IPropertyArrayHelper & SAL_CALL LineChartType::getInfoHelper() +{ + static ::cppu::OPropertyArrayHelper aArrayHelper( lcl_GetPropertySequence(), + /* bSorted = */ sal_True ); + + return aArrayHelper; +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + LineChartType::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + getInfoHelper()); + } + + return xInfo; +} + +uno::Sequence< ::rtl::OUString > LineChartType::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 3 ); + aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_LINE; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" ); + aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( LineChartType, + C2U( "com.sun.star.comp.chart.LineChartType" )); + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/LineChartType.hxx b/chart2/source/model/template/LineChartType.hxx new file mode 100644 index 000000000000..e553538ce324 --- /dev/null +++ b/chart2/source/model/template/LineChartType.hxx @@ -0,0 +1,78 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_LINECHARTTYPE_HXX +#define CHART_LINECHARTTYPE_HXX + +#include "ChartType.hxx" +#include "ServiceMacros.hxx" +#include <com/sun/star/chart2/CurveStyle.hpp> + +namespace chart +{ + +class LineChartType : public ChartType +{ +public: + LineChartType( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~LineChartType(); + + APPHELPER_XSERVICEINFO_DECL() + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( LineChartType ) + +protected: + explicit LineChartType( const LineChartType & rOther ); + + // ____ XChartType ____ + virtual ::rtl::OUString SAL_CALL getChartType() + throw (::com::sun::star::uno::RuntimeException); + + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XCloneable ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() + throw (::com::sun::star::uno::RuntimeException); +}; + +} // namespace chart + +// CHART_LINECHARTTYPE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/LineChartTypeTemplate.cxx b/chart2/source/model/template/LineChartTypeTemplate.cxx new file mode 100644 index 000000000000..a6702ac42b0e --- /dev/null +++ b/chart2/source/model/template/LineChartTypeTemplate.cxx @@ -0,0 +1,410 @@ +/* -*- 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 "LineChartTypeTemplate.hxx" +#include "macros.hxx" +#include "DiagramHelper.hxx" +#include "servicenames_charttypes.hxx" +#include "ContainerHelper.hxx" +#include "DataSeriesHelper.hxx" +#include <com/sun/star/chart2/SymbolStyle.hpp> +#include <com/sun/star/chart2/Symbol.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> +#include "PropertyHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> + +#include <algorithm> + +using namespace ::com::sun::star; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +namespace +{ + +static const OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.LineChartTypeTemplate" )); + +enum +{ + PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE, + PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION, + PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER + +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "CurveStyle" ), + PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE, + ::getCppuType( reinterpret_cast< const chart2::CurveStyle * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "CurveResolution" ), + PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "SplineOrder" ), + PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE, chart2::CurveStyle_LINES ); + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION, 20 ); + + // todo: check whether order 3 means polygons of order 3 or 2. (see + // http://www.people.nnov.ru/fractal/Splines/Basis.htm ) + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER, 3 ); +} + +const Sequence< Property > & lcl_GetPropertySequence() +{ + static 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 ); + + // 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; +} + +} // anonymous namespace + +namespace chart +{ + +LineChartTypeTemplate::LineChartTypeTemplate( + uno::Reference< + uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName, + StackMode eStackMode, + bool bSymbols, + bool bHasLines /* = true */, + sal_Int32 nDim /* = 2 */ ) : + ChartTypeTemplate( xContext, rServiceName ), + ::property::OPropertySet( m_aMutex ), + m_eStackMode( eStackMode ), + m_bHasSymbols( bSymbols ), + m_bHasLines( bHasLines ), + m_nDim( nDim ) +{ + if( nDim == 3 ) + m_bHasSymbols = false; +} + +LineChartTypeTemplate::~LineChartTypeTemplate() +{} +// ____ OPropertySet ____ +uno::Any LineChartTypeTemplate::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 ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; +} + +::cppu::IPropertyArrayHelper & SAL_CALL LineChartTypeTemplate::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + LineChartTypeTemplate::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; +} + +sal_Int32 LineChartTypeTemplate::getDimension() const +{ + return m_nDim; +} + +StackMode LineChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const +{ + return m_eStackMode; +} + +// ____ XChartTypeTemplate ____ +sal_Bool SAL_CALL LineChartTypeTemplate::matchesTemplate( + const uno::Reference< chart2::XDiagram >& xDiagram, + sal_Bool bAdaptProperties ) + throw (uno::RuntimeException) +{ + sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties ); + + // check symbol-style and line-style + // for a template with symbols (or with lines) it is ok, if there is at least one series + // with symbols (or with lines) + if( bResult ) + { + bool bSymbolFound = false; + bool bLineFound = false; + + ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec( + DiagramHelper::getDataSeriesFromDiagram( xDiagram )); + + for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt = + aSeriesVec.begin(); aIt != aSeriesVec.end(); ++aIt ) + { + try + { + chart2::Symbol aSymbProp; + drawing::LineStyle eLineStyle; + Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY_THROW ); + + bool bCurrentHasSymbol = (xProp->getPropertyValue( C2U( "Symbol" )) >>= aSymbProp) && + (aSymbProp.Style != chart2::SymbolStyle_NONE); + + if( bCurrentHasSymbol ) + bSymbolFound = true; + + if( bCurrentHasSymbol && (!m_bHasSymbols) ) + { + bResult = false; + break; + } + + bool bCurrentHasLine = (xProp->getPropertyValue( C2U( "LineStyle" )) >>= eLineStyle) && + ( eLineStyle != drawing::LineStyle_NONE ); + + if( bCurrentHasLine ) + bLineFound = true; + + if( bCurrentHasLine && (!m_bHasLines) ) + { + bResult = false; + break; + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + if(bResult) + { + if( !bLineFound && m_bHasLines && bSymbolFound ) + bResult = false; + else if( !bSymbolFound && m_bHasSymbols && bLineFound ) + bResult = false; + else if( !bLineFound && !bSymbolFound ) + return m_bHasLines && m_bHasSymbols; + } + } + + // adapt curve style, spline order and resolution + if( bResult && bAdaptProperties ) + { + try + { + uno::Reference< beans::XPropertySet > xChartTypeProp( + DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), + uno::UNO_QUERY_THROW ); + setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE, xChartTypeProp->getPropertyValue(C2U("CurveStyle" )) ); + setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION, xChartTypeProp->getPropertyValue(C2U("CurveResolution" )) ); + setFastPropertyValue_NoBroadcast( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER, xChartTypeProp->getPropertyValue(C2U("SplineOrder" )) ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + return bResult; +} + +Reference< chart2::XChartType > LineChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ ) +{ + Reference< chart2::XChartType > xResult; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + xResult.set( xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_LINE ), uno::UNO_QUERY_THROW ); + + Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY ); + if( xCTProp.is()) + { + xCTProp->setPropertyValue( + C2U( "CurveStyle" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE )); + xCTProp->setPropertyValue( + C2U( "CurveResolution" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION )); + xCTProp->setPropertyValue( + C2U( "SplineOrder" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER )); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return xResult; +} + +Reference< chart2::XChartType > SAL_CALL LineChartTypeTemplate::getChartTypeForNewSeries( + const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (uno::RuntimeException) +{ + Reference< chart2::XChartType > xResult; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + xResult.set( xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_LINE ), uno::UNO_QUERY_THROW ); + + ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult ); + + Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY ); + if( xCTProp.is()) + { + xCTProp->setPropertyValue( + C2U( "CurveStyle" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_STYLE )); + xCTProp->setPropertyValue( + C2U( "CurveResolution" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_CURVE_RESOLUTION )); + xCTProp->setPropertyValue( + C2U( "SplineOrder" ), getFastPropertyValue( PROP_LINECHARTTYPE_TEMPLATE_SPLINE_ORDER )); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return xResult; +} + +void SAL_CALL LineChartTypeTemplate::applyStyle( + const Reference< chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (uno::RuntimeException) +{ + ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount ); + + try + { + Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW ); + + DataSeriesHelper::switchSymbolsOnOrOff( xProp, m_bHasSymbols, nSeriesIndex ); + DataSeriesHelper::switchLinesOnOrOff( xProp, m_bHasLines ); + DataSeriesHelper::makeLinesThickOrThin( xProp, m_nDim==2 ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +// ---------------------------------------- + +Sequence< OUString > LineChartTypeTemplate::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 2 ); + aServices[ 0 ] = lcl_aServiceName; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( LineChartTypeTemplate, lcl_aServiceName ); + +IMPLEMENT_FORWARD_XINTERFACE2( LineChartTypeTemplate, ChartTypeTemplate, OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( LineChartTypeTemplate, ChartTypeTemplate, OPropertySet ) + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/LineChartTypeTemplate.hxx b/chart2/source/model/template/LineChartTypeTemplate.hxx new file mode 100644 index 000000000000..496bac77b3e5 --- /dev/null +++ b/chart2/source/model/template/LineChartTypeTemplate.hxx @@ -0,0 +1,112 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_LINECHARTTYPETEMPLATE_HXX +#define CHART_LINECHARTTYPETEMPLATE_HXX + +#include "ChartTypeTemplate.hxx" +#include "OPropertySet.hxx" +#include "MutexContainer.hxx" +#include "StackMode.hxx" +#include <comphelper/uno3.hxx> +#include <com/sun/star/chart2/CurveStyle.hpp> + +namespace chart +{ + +class LineChartTypeTemplate : + public MutexContainer, + public ChartTypeTemplate, + public ::property::OPropertySet +{ +public: + explicit LineChartTypeTemplate( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName, + StackMode eStackMode, + bool bSymbols, + bool bHasLines = true, + sal_Int32 nDim = 2 ); + virtual ~LineChartTypeTemplate(); + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XChartTypeTemplate ____ + virtual sal_Bool SAL_CALL matchesTemplate( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDiagram >& xDiagram, + sal_Bool bAdaptProperties ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > SAL_CALL + getChartTypeForNewSeries( const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL applyStyle( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeGroupIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ ChartTypeTemplate ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > + getChartTypeForIndex( sal_Int32 nChartTypeIndex ); + virtual sal_Int32 getDimension() const; + virtual StackMode getStackMode( sal_Int32 nChartTypeIndex ) const; + +private: + StackMode m_eStackMode; + bool m_bHasSymbols; + bool m_bHasLines; + sal_Int32 m_nDim; +}; + +} // namespace chart + +// CHART_LINECHARTTYPETEMPLATE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/NetChartType.cxx b/chart2/source/model/template/NetChartType.cxx new file mode 100644 index 000000000000..1f1f0f06dfb8 --- /dev/null +++ b/chart2/source/model/template/NetChartType.cxx @@ -0,0 +1,181 @@ +/* -*- 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 "NetChartType.hxx" +#include "PropertyHelper.hxx" +#include "macros.hxx" +#include "PolarCoordinateSystem.hxx" +#include "servicenames_charttypes.hxx" +#include "ContainerHelper.hxx" +#include "AxisIndexDefines.hxx" +#include "AxisHelper.hxx" + +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/chart2/AxisType.hpp> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; + +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +namespace chart +{ + +NetChartType_Base::NetChartType_Base( + const uno::Reference< uno::XComponentContext > & xContext ) : + ChartType( xContext ) +{} + +NetChartType_Base::NetChartType_Base( const NetChartType_Base & rOther ) : + ChartType( rOther ) +{ +} + +NetChartType_Base::~NetChartType_Base() +{} + +Reference< XCoordinateSystem > SAL_CALL + NetChartType_Base::createCoordinateSystem( ::sal_Int32 DimensionCount ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + if( DimensionCount != 2 ) + throw lang::IllegalArgumentException( + C2U( "NetChart must be two-dimensional" ), + static_cast< ::cppu::OWeakObject* >( this ), 0 ); + + Reference< XCoordinateSystem > xResult( + new PolarCoordinateSystem( + GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ sal_False )); + + Reference< XAxis > xAxis( xResult->getAxisByDimension( 0, MAIN_AXIS_INDEX ) ); + if( xAxis.is() ) + { + ScaleData aScaleData = xAxis->getScaleData(); + aScaleData.Scaling = AxisHelper::createLinearScaling(); + aScaleData.AxisType = AxisType::CATEGORY; + aScaleData.Orientation = AxisOrientation_MATHEMATICAL; + xAxis->setScaleData( aScaleData ); + } + + xAxis = xResult->getAxisByDimension( 1, MAIN_AXIS_INDEX ); + if( xAxis.is() ) + { + ScaleData aScaleData = xAxis->getScaleData(); + aScaleData.Orientation = AxisOrientation_MATHEMATICAL; + aScaleData.AxisType = AxisType::REALNUMBER; + xAxis->setScaleData( aScaleData ); + } + + return xResult; +} + +// ____ OPropertySet ____ +uno::Any NetChartType_Base::GetDefaultValue( sal_Int32 /*nHandle*/ ) const + throw(beans::UnknownPropertyException) +{ + return uno::Any(); +} + +// ____ OPropertySet ____ +::cppu::IPropertyArrayHelper & SAL_CALL NetChartType_Base::getInfoHelper() +{ + uno::Sequence< beans::Property > aProps; + static ::cppu::OPropertyArrayHelper aArrayHelper(aProps); + return aArrayHelper; +} + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + NetChartType_Base::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + getInfoHelper()); + } + + return xInfo; +} + +//----------------------------------------------------------------------------- + +NetChartType::NetChartType( + const uno::Reference< uno::XComponentContext > & xContext ) : + NetChartType_Base( xContext ) +{} + +NetChartType::NetChartType( const NetChartType & rOther ) : + NetChartType_Base( rOther ) +{ +} + +NetChartType::~NetChartType() +{} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL NetChartType::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new NetChartType( *this )); +} + +// ____ XChartType ____ +::rtl::OUString SAL_CALL NetChartType::getChartType() + throw (uno::RuntimeException) +{ + return CHART2_SERVICE_NAME_CHARTTYPE_NET; +} + +uno::Sequence< ::rtl::OUString > NetChartType::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 3 ); + aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_NET; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" ); + aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( NetChartType, + C2U( "com.sun.star.comp.chart.NetChartType" )); + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/NetChartType.hxx b/chart2/source/model/template/NetChartType.hxx new file mode 100644 index 000000000000..7a28ebdc9c99 --- /dev/null +++ b/chart2/source/model/template/NetChartType.hxx @@ -0,0 +1,96 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_NETCHARTTYPE_HXX +#define CHART_NETCHARTTYPE_HXX + +#include "ChartType.hxx" +#include "ServiceMacros.hxx" + +namespace chart +{ + +class NetChartType_Base : public ChartType +{ +public: + NetChartType_Base( ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~NetChartType_Base(); + +protected: + explicit NetChartType_Base( const NetChartType_Base & rOther ); + + // ____ XChartType ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XCoordinateSystem > SAL_CALL + createCoordinateSystem( ::sal_Int32 DimensionCount ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); +}; + +//------------------------------------------------------------------------------------- + +class NetChartType : public NetChartType_Base +{ +public: + NetChartType( ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~NetChartType(); + + APPHELPER_XSERVICEINFO_DECL() + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( NetChartType ) + +protected: + explicit NetChartType( const NetChartType & rOther ); + + // ____ XChartType ____ + virtual ::rtl::OUString SAL_CALL getChartType() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XCloneable ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() + throw (::com::sun::star::uno::RuntimeException); +}; + +} // namespace chart + +// CHART_NETCHARTTYPE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/NetChartTypeTemplate.cxx b/chart2/source/model/template/NetChartTypeTemplate.cxx new file mode 100644 index 000000000000..25efd6877a7c --- /dev/null +++ b/chart2/source/model/template/NetChartTypeTemplate.cxx @@ -0,0 +1,232 @@ +/* -*- 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 "NetChartTypeTemplate.hxx" +#include "macros.hxx" +#include "PolarCoordinateSystem.hxx" +#include "DiagramHelper.hxx" +#include "servicenames_charttypes.hxx" +#include "DataSeriesHelper.hxx" +#include <com/sun/star/chart2/SymbolStyle.hpp> +#include <com/sun/star/chart2/Symbol.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> + +using namespace ::com::sun::star; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + + +namespace +{ +static const ::rtl::OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.NetChartTypeTemplate" )); +} // anonymous namespace + +namespace chart +{ + +NetChartTypeTemplate::NetChartTypeTemplate( + Reference< uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName, + StackMode eStackMode, + bool bSymbols, + bool bHasLines , + bool bHasFilledArea ) : + ChartTypeTemplate( xContext, rServiceName ), + m_eStackMode( eStackMode ), + m_bHasSymbols( bSymbols ), + m_bHasLines( bHasLines ), + m_bHasFilledArea( bHasFilledArea ) +{} + +NetChartTypeTemplate::~NetChartTypeTemplate() +{} + +StackMode NetChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const +{ + return m_eStackMode; +} + +void SAL_CALL NetChartTypeTemplate::applyStyle( + const Reference< chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (uno::RuntimeException) +{ + ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount ); + + try + { + Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW ); + + DataSeriesHelper::switchSymbolsOnOrOff( xProp, m_bHasSymbols, nSeriesIndex ); + DataSeriesHelper::switchLinesOnOrOff( xProp, m_bHasLines ); + DataSeriesHelper::makeLinesThickOrThin( xProp, true ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +// ____ XChartTypeTemplate ____ +sal_Bool SAL_CALL NetChartTypeTemplate::matchesTemplate( + const Reference< chart2::XDiagram >& xDiagram, + sal_Bool bAdaptProperties ) + throw (uno::RuntimeException) +{ + sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties ); + + uno::Reference< beans::XPropertySet > xChartTypeProp( + DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), uno::UNO_QUERY_THROW ); + + if( bResult ) + { + //filled net chart?: + if( m_bHasFilledArea ) + return sal_True; + + // check symbol-style + // for a template with symbols it is ok, if there is at least one series + // with symbols, otherwise an unknown template is too easy to achieve + bool bSymbolFound = false; + bool bLineFound = false; + + ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec( + DiagramHelper::getDataSeriesFromDiagram( xDiagram )); + + for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt = + aSeriesVec.begin(); aIt != aSeriesVec.end(); ++aIt ) + { + try + { + chart2::Symbol aSymbProp; + drawing::LineStyle eLineStyle; + Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY_THROW ); + + bool bCurrentHasSymbol = (xProp->getPropertyValue( C2U( "Symbol" )) >>= aSymbProp) && + (aSymbProp.Style != chart2::SymbolStyle_NONE); + + if( bCurrentHasSymbol ) + bSymbolFound = true; + + if( bCurrentHasSymbol && (!m_bHasSymbols) ) + { + bResult = false; + break; + } + + bool bCurrentHasLine = (xProp->getPropertyValue( C2U( "LineStyle" )) >>= eLineStyle) && + ( eLineStyle != drawing::LineStyle_NONE ); + + if( bCurrentHasLine ) + bLineFound = true; + + if( bCurrentHasLine && (!m_bHasLines) ) + { + bResult = false; + break; + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + if(bResult) + { + if( !bLineFound && m_bHasLines && bSymbolFound ) + bResult = false; + else if( !bSymbolFound && m_bHasSymbols && bLineFound ) + bResult = false; + else if( !bLineFound && !bSymbolFound ) + return m_bHasLines && m_bHasSymbols; + } + } + + return bResult; +} + +Reference< chart2::XChartType > NetChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ ) +{ + Reference< chart2::XChartType > xResult; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + + if( m_bHasFilledArea ) + xResult.set( xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_FILLED_NET ), uno::UNO_QUERY_THROW ); + else + xResult.set( xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_NET ), uno::UNO_QUERY_THROW ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return xResult; +} + +Reference< chart2::XChartType > SAL_CALL NetChartTypeTemplate::getChartTypeForNewSeries( + const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (uno::RuntimeException) +{ + Reference< chart2::XChartType > xResult( getChartTypeForIndex( 0 ) ); + ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult ); + return xResult; +} + +// ---------------------------------------- + +Sequence< OUString > NetChartTypeTemplate::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 2 ); + aServices[ 0 ] = lcl_aServiceName; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( NetChartTypeTemplate, lcl_aServiceName ); + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/NetChartTypeTemplate.hxx b/chart2/source/model/template/NetChartTypeTemplate.hxx new file mode 100644 index 000000000000..c3e390d59b66 --- /dev/null +++ b/chart2/source/model/template/NetChartTypeTemplate.hxx @@ -0,0 +1,90 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_NETCHARTTYPETEMPLATE_HXX +#define CHART_NETCHARTTYPETEMPLATE_HXX + +#include "ChartTypeTemplate.hxx" +#include "StackMode.hxx" + +namespace chart +{ + +class NetChartTypeTemplate : public ChartTypeTemplate +{ +public: + explicit NetChartTypeTemplate( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName, + StackMode eStackMode, + bool bSymbols, + bool bHasLines = true, + bool bHasFilledArea = false + ); + virtual ~NetChartTypeTemplate(); + + APPHELPER_XSERVICEINFO_DECL() + +protected: + // ____ XChartTypeTemplate ____ + virtual sal_Bool SAL_CALL matchesTemplate( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDiagram >& xDiagram, + sal_Bool bAdaptProperties ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > SAL_CALL + getChartTypeForNewSeries( const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL applyStyle( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeGroupIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ ChartTypeTemplate ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > + getChartTypeForIndex( sal_Int32 nChartTypeIndex ); + virtual StackMode getStackMode( sal_Int32 nChartTypeIndex ) const; + + +private: + StackMode m_eStackMode; + bool m_bHasSymbols; + bool m_bHasLines; + bool m_bHasFilledArea; +}; + +} // namespace chart + +// CHART_NETCHARTTYPETEMPLATE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/PieChartType.cxx b/chart2/source/model/template/PieChartType.cxx new file mode 100644 index 000000000000..81760c2d3f39 --- /dev/null +++ b/chart2/source/model/template/PieChartType.cxx @@ -0,0 +1,237 @@ +/* -*- 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 "PieChartType.hxx" +#include "PropertyHelper.hxx" +#include "macros.hxx" +#include "PolarCoordinateSystem.hxx" +#include "AxisHelper.hxx" +#include "servicenames_charttypes.hxx" +#include "ContainerHelper.hxx" +#include "AxisIndexDefines.hxx" +#include "AxisHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/chart2/AxisType.hpp> + +using namespace ::com::sun::star; + +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +namespace +{ + +enum +{ + PROP_PIECHARTTYPE_USE_RINGS +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "UseRings" ), + PROP_PIECHARTTYPE_USE_RINGS, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_PIECHARTTYPE_USE_RINGS, false ); +} + +const Sequence< Property > & lcl_GetPropertySequence() +{ + static Sequence< Property > aPropSeq; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aPropSeq.getLength() ) + { + // get properties + ::std::vector< ::com::sun::star::beans::Property > aProperties; + lcl_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; +} + +} // anonymous namespace + +namespace chart +{ + +PieChartType::PieChartType( + const uno::Reference< uno::XComponentContext > & xContext, + sal_Bool bUseRings /* = sal_False */) : + ChartType( xContext ) +{ + if( bUseRings ) + setFastPropertyValue_NoBroadcast( PROP_PIECHARTTYPE_USE_RINGS, uno::makeAny( bUseRings )); +} + +PieChartType::PieChartType( const PieChartType & rOther ) : + ChartType( rOther ) +{ +} + +PieChartType::~PieChartType() +{} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL PieChartType::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new PieChartType( *this )); +} + +// ____ XChartType ____ +::rtl::OUString SAL_CALL PieChartType::getChartType() + throw (uno::RuntimeException) +{ + return CHART2_SERVICE_NAME_CHARTTYPE_PIE; +} + +Reference< chart2::XCoordinateSystem > SAL_CALL + PieChartType::createCoordinateSystem( ::sal_Int32 DimensionCount ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + Reference< chart2::XCoordinateSystem > xResult( + new PolarCoordinateSystem( + GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ sal_False )); + + for( sal_Int32 i=0; i<DimensionCount; ++i ) + { + Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) ); + if( !xAxis.is() ) + { + OSL_ENSURE(false,"a created coordinate system should have an axis for each dimension"); + continue; + } + + //hhhh todo make axis invisible + + chart2::ScaleData aScaleData = xAxis->getScaleData(); + aScaleData.Scaling = AxisHelper::createLinearScaling(); + aScaleData.AxisType = chart2::AxisType::REALNUMBER; + + if( i == 0 ) + aScaleData.Orientation = chart2::AxisOrientation_REVERSE; + else + aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL; + + //remove explicit scalings from all axes + AxisHelper::removeExplicitScaling( aScaleData ); + + xAxis->setScaleData( aScaleData ); + } + + return xResult; +} + +// ____ OPropertySet ____ +uno::Any PieChartType::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 ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; +} + +// ____ OPropertySet ____ +::cppu::IPropertyArrayHelper & SAL_CALL PieChartType::getInfoHelper() +{ + static ::cppu::OPropertyArrayHelper aArrayHelper( lcl_GetPropertySequence(), + /* bSorted = */ sal_True ); + + return aArrayHelper; +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + PieChartType::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + getInfoHelper()); + } + + return xInfo; +} + +uno::Sequence< ::rtl::OUString > PieChartType::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 3 ); + aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_PIE; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" ); + aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( PieChartType, + C2U( "com.sun.star.comp.chart.PieChartType" )); + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/PieChartType.hxx b/chart2/source/model/template/PieChartType.hxx new file mode 100644 index 000000000000..676d51ebb34e --- /dev/null +++ b/chart2/source/model/template/PieChartType.hxx @@ -0,0 +1,84 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_PIECHARTTYPE_HXX +#define CHART_PIECHARTTYPE_HXX + +#include "ChartType.hxx" +#include "ServiceMacros.hxx" + +namespace chart +{ + +class PieChartType : public ChartType +{ +public: + PieChartType( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext, + sal_Bool bUseRings = sal_False ); + virtual ~PieChartType(); + + APPHELPER_XSERVICEINFO_DECL() + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( PieChartType ) + +protected: + explicit PieChartType( const PieChartType & rOther ); + + // ____ XChartType ____ + virtual ::rtl::OUString SAL_CALL getChartType() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XCoordinateSystem > SAL_CALL + createCoordinateSystem( ::sal_Int32 DimensionCount ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + + // ____ OPropertySet ____ + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XCloneable ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() + throw (::com::sun::star::uno::RuntimeException); +}; + +} // namespace chart + +// CHART_PIECHARTTYPE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/PieChartTypeTemplate.cxx b/chart2/source/model/template/PieChartTypeTemplate.cxx new file mode 100644 index 000000000000..1a36079de078 --- /dev/null +++ b/chart2/source/model/template/PieChartTypeTemplate.cxx @@ -0,0 +1,652 @@ +/* -*- 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 "PieChartTypeTemplate.hxx" +#include "macros.hxx" +#include "CommonConverters.hxx" +#include "DiagramHelper.hxx" +#include "servicenames_charttypes.hxx" +#include "DataSeriesHelper.hxx" +#include "ContainerHelper.hxx" +#include "BaseGFXHelper.hxx" +#include "AxisHelper.hxx" +#include "ThreeDHelper.hxx" +#include "PropertyHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> +#include <com/sun/star/drawing/FillStyle.hpp> +#include <com/sun/star/chart2/XChartTypeContainer.hpp> +#include <com/sun/star/chart2/XDataSeriesContainer.hpp> + +#include <rtl/math.hxx> + +#include <algorithm> + +using namespace ::com::sun::star; + +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +namespace +{ + +static const ::rtl::OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.PieChartTypeTemplate" )); + +enum +{ + PROP_PIE_TEMPLATE_DEFAULT_OFFSET, + PROP_PIE_TEMPLATE_OFFSET_MODE, + PROP_PIE_TEMPLATE_DIMENSION, + PROP_PIE_TEMPLATE_USE_RINGS +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "OffsetMode" ), + PROP_PIE_TEMPLATE_OFFSET_MODE, + ::getCppuType( reinterpret_cast< const chart2::PieChartOffsetMode * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "DefaultOffset" ), + PROP_PIE_TEMPLATE_DEFAULT_OFFSET, + ::getCppuType( reinterpret_cast< const double * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "Dimension" ), + PROP_PIE_TEMPLATE_DIMENSION, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "UseRings" ), + PROP_PIE_TEMPLATE_USE_RINGS, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_PIE_TEMPLATE_OFFSET_MODE, chart2::PieChartOffsetMode_NONE ); + ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_PIE_TEMPLATE_DEFAULT_OFFSET, 0.5 ); + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_PIE_TEMPLATE_DIMENSION, 2 ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_PIE_TEMPLATE_USE_RINGS, false ); +} + +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 ); + + // 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; +} + +} // anonymous namespace + +namespace chart +{ + +PieChartTypeTemplate::PieChartTypeTemplate( + uno::Reference< + uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName, + chart2::PieChartOffsetMode eMode, + bool bRings /* = false */, + sal_Int32 nDim /* = 2 */ ) : + ChartTypeTemplate( xContext, rServiceName ), + ::property::OPropertySet( m_aMutex ) +{ + setFastPropertyValue_NoBroadcast( PROP_PIE_TEMPLATE_OFFSET_MODE, uno::makeAny( eMode )); + setFastPropertyValue_NoBroadcast( PROP_PIE_TEMPLATE_DIMENSION, uno::makeAny( nDim )); + setFastPropertyValue_NoBroadcast( PROP_PIE_TEMPLATE_USE_RINGS, uno::makeAny( sal_Bool( bRings ))); +} + +PieChartTypeTemplate::~PieChartTypeTemplate() +{} + +// ____ OPropertySet ____ +uno::Any PieChartTypeTemplate::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 ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; +} + +::cppu::IPropertyArrayHelper & SAL_CALL PieChartTypeTemplate::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + PieChartTypeTemplate::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; +} + + +// ____ ChartTypeTemplate ____ +sal_Int32 PieChartTypeTemplate::getDimension() const +{ + sal_Int32 nDim = 2; + try + { + // note: UNO-methods are never const + const_cast< PieChartTypeTemplate * >( this )-> + getFastPropertyValue( PROP_PIE_TEMPLATE_DIMENSION ) >>= nDim; + } + catch( beans::UnknownPropertyException & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return nDim; +} + +sal_Int32 PieChartTypeTemplate::getAxisCountByDimension( sal_Int32 /*nDimension*/ ) +{ + return 0; +} + +void PieChartTypeTemplate::adaptAxes( + const uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > & /*rCoordSys*/ ) +{ + // hide existing axes + //hhhh todo +} + +void PieChartTypeTemplate::adaptScales( + const Sequence< Reference< chart2::XCoordinateSystem > > & aCooSysSeq, + const Reference< chart2::data::XLabeledDataSequence > & xCategories //@todo: in future there may be more than one sequence of categories (e.g. charttype with categories at x and y axis ) + ) +{ + ChartTypeTemplate::adaptScales( aCooSysSeq, xCategories ); + + //remove explicit scalings from radius axis + //and ensure correct orientation of scales for donuts + + for( sal_Int32 nCooSysIdx=0; nCooSysIdx<aCooSysSeq.getLength(); ++nCooSysIdx ) + { + try + { + Reference< chart2::XAxis > xAxis( AxisHelper::getAxis( 1 /*nDimensionIndex*/,0 /*nAxisIndex*/ + , aCooSysSeq[nCooSysIdx] ) ); + if( xAxis.is() ) + { + chart2::ScaleData aScaleData( xAxis->getScaleData() ); + AxisHelper::removeExplicitScaling( aScaleData ); + aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL; + xAxis->setScaleData( aScaleData ); + } + + xAxis = AxisHelper::getAxis( 0 /*nDimensionIndex*/,0 /*nAxisIndex*/ + , aCooSysSeq[nCooSysIdx] ); + if( xAxis.is() ) + { + chart2::ScaleData aScaleData( xAxis->getScaleData() ); + aScaleData.Orientation = chart2::AxisOrientation_REVERSE; + xAxis->setScaleData( aScaleData ); + } + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } +} + +void PieChartTypeTemplate::createChartTypes( + const Sequence< Sequence< Reference< chart2::XDataSeries > > > & aSeriesSeq, + const Sequence< Reference< chart2::XCoordinateSystem > > & rCoordSys, + const Sequence< Reference< chart2::XChartType > >& /* aOldChartTypesSeq */ ) +{ + if( rCoordSys.getLength() == 0 || + ! rCoordSys[0].is() ) + return; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + + Reference< chart2::XChartType > xCT( + xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_PIE ), uno::UNO_QUERY_THROW ); + Reference< beans::XPropertySet > xCTProp( xCT, uno::UNO_QUERY ); + if( xCTProp.is()) + { + xCTProp->setPropertyValue( + C2U( "UseRings" ), getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS )); + } + Reference< chart2::XChartTypeContainer > xCTCnt( rCoordSys[0], uno::UNO_QUERY_THROW ); + xCTCnt->setChartTypes( Sequence< Reference< chart2::XChartType > >( &xCT, 1 )); + + if( aSeriesSeq.getLength() > 0 ) + { + Reference< chart2::XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW ); + Sequence< Reference< chart2::XDataSeries > > aFlatSeriesSeq( FlattenSequence( aSeriesSeq )); + xDSCnt->setDataSeries( aFlatSeriesSeq ); + + DataSeriesHelper::setStackModeAtSeries( + aFlatSeriesSeq, rCoordSys[0], getStackMode( 0 )); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +// ____ XChartTypeTemplate ____ +sal_Bool SAL_CALL PieChartTypeTemplate::matchesTemplate( + const uno::Reference< chart2::XDiagram >& xDiagram, + sal_Bool bAdaptProperties ) + throw (uno::RuntimeException) +{ + sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties ); + + sal_Bool bTemplateUsesRings = sal_False; + getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ) >>= bTemplateUsesRings; + chart2::PieChartOffsetMode ePieOffsetMode; + getFastPropertyValue( PROP_PIE_TEMPLATE_OFFSET_MODE ) >>= ePieOffsetMode; + + //check offset-mode + if( bResult ) + { + try + { + double fOffset=0.0; + bool bAllOffsetsEqual = true; + + ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec( + DiagramHelper::getDataSeriesFromDiagram( xDiagram )); + + //check offset of outer series + if( aSeriesVec.size() ) + { + sal_Int32 nOuterSeriesIndex = 0; //@todo in future this will depend on Orientation of the radius axis scale + Reference< chart2::XDataSeries > xSeries( aSeriesVec[nOuterSeriesIndex] ); + Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW ); + xProp->getPropertyValue( C2U( "Offset" )) >>= fOffset; + + //get AttributedDataPoints + uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; + if( xProp->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList ) + { + for(sal_Int32 nN=aAttributedDataPointIndexList.getLength();nN--;) + { + uno::Reference< beans::XPropertySet > xPointProp( xSeries->getDataPointByIndex(aAttributedDataPointIndexList[nN]) ); + if(xPointProp.is()) + { + double fPointOffset=0.0; + if( (xProp->getPropertyValue( C2U( "Offset" )) >>= fPointOffset ) ) + { + if( ! ::rtl::math::approxEqual( fPointOffset, fOffset ) ) + { + bAllOffsetsEqual = false; + break; + } + } + } + } + } + } + + chart2::PieChartOffsetMode eOffsetMode = chart2::PieChartOffsetMode_NONE; + if( bAllOffsetsEqual && fOffset > 0.0 ) + { + eOffsetMode = chart2::PieChartOffsetMode_ALL_EXPLODED; + if( bAdaptProperties ) + setFastPropertyValue_NoBroadcast( PROP_PIE_TEMPLATE_DEFAULT_OFFSET, uno::makeAny( fOffset )); + } + + bResult = ( eOffsetMode == ePieOffsetMode ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + bResult = false; + } + } + + //check UseRings + if( bResult ) + { + uno::Reference< beans::XPropertySet > xCTProp( + DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), uno::UNO_QUERY_THROW ); + sal_Bool bUseRings = false; + if( xCTProp->getPropertyValue( C2U( "UseRings" )) >>= bUseRings ) + { + bResult = ( bTemplateUsesRings == bUseRings ); + } + } + + return bResult; +} + +Reference< chart2::XChartType > PieChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ ) +{ + Reference< chart2::XChartType > xResult; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + xResult.set( xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_PIE ), uno::UNO_QUERY_THROW ); + Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY ); + if( xCTProp.is()) + { + xCTProp->setPropertyValue( + C2U( "UseRings" ), getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS )); + } + + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return xResult; +} + +Reference< chart2::XChartType > SAL_CALL PieChartTypeTemplate::getChartTypeForNewSeries( + const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (uno::RuntimeException) +{ + Reference< chart2::XChartType > xResult; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + xResult.set( xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_PIE ), uno::UNO_QUERY_THROW ); + ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult ); + Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY ); + if( xCTProp.is()) + { + xCTProp->setPropertyValue( + C2U( "UseRings" ), getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS )); + } + + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return xResult; +} + +void SAL_CALL PieChartTypeTemplate::applyStyle( + const Reference< chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (uno::RuntimeException) +{ + ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount ); + + try + { + uno::Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW ); + + sal_Bool bTemplateUsesRings = sal_False; + getFastPropertyValue( PROP_PIE_TEMPLATE_USE_RINGS ) >>= bTemplateUsesRings; + sal_Int32 nOuterSeriesIndex = 0; //@todo in future this will depend on Orientation of the radius axis scale + if( nSeriesIndex == nOuterSeriesIndex ) + { + const OUString aOffsetPropName( RTL_CONSTASCII_USTRINGPARAM("Offset")); + // get offset mode + chart2::PieChartOffsetMode ePieOffsetMode; + this->getFastPropertyValue( PROP_PIE_TEMPLATE_OFFSET_MODE ) >>= ePieOffsetMode; + + // get default offset + double fDefaultOffset = 0.5; + this->getFastPropertyValue( PROP_PIE_TEMPLATE_DEFAULT_OFFSET ) >>= fDefaultOffset; + double fOffsetToSet = fDefaultOffset; + + uno::Sequence< sal_Int32 > aAttributedDataPointIndexList; + xProp->getPropertyValue( C2U( "AttributedDataPoints" ) ) >>= aAttributedDataPointIndexList; + + // determine whether to set the new offset + bool bSetOffset = ( ePieOffsetMode == chart2::PieChartOffsetMode_ALL_EXPLODED ); + if( !bSetOffset && + (ePieOffsetMode == chart2::PieChartOffsetMode_NONE) ) + { + // set offset to 0 if the offset was exactly "all exploded" + // before (individual offsets are kept) + double fOffset = 0.0; + if( (xProp->getPropertyValue( aOffsetPropName ) >>= fOffset) && + ::rtl::math::approxEqual( fOffset, fDefaultOffset )) + { + fOffsetToSet = 0.0; + bSetOffset = true; + for( sal_Int32 nPtIdx=0; nPtIdx<aAttributedDataPointIndexList.getLength(); ++nPtIdx ) + { + uno::Reference< beans::XPropertySet > xPointProp( + xSeries->getDataPointByIndex( aAttributedDataPointIndexList[ nPtIdx ] )); + uno::Reference< beans::XPropertyState > xPointState( xPointProp, uno::UNO_QUERY ); + double fPointOffset = 0.0; + if( xPointState.is() && + (xPointState->getPropertyState( aOffsetPropName ) == beans::PropertyState_DIRECT_VALUE) && + xPointProp.is() && + (xPointProp->getPropertyValue( aOffsetPropName ) >>= fPointOffset ) && + ! ::rtl::math::approxEqual( fPointOffset, fDefaultOffset ) ) + { + bSetOffset = false; + break; + } + } + } + } + + if( bSetOffset ) + { + // set the offset to the series and to the attributed data points + xProp->setPropertyValue( aOffsetPropName, uno::makeAny( fOffsetToSet )); + + // remove hard attributes from data points + for( sal_Int32 nPtIdx=0; nPtIdx<aAttributedDataPointIndexList.getLength(); ++nPtIdx ) + { + uno::Reference< beans::XPropertyState > xPointState( + xSeries->getDataPointByIndex( aAttributedDataPointIndexList[ nPtIdx ] ), uno::UNO_QUERY ); + if( xPointState.is()) + xPointState->setPropertyToDefault( aOffsetPropName ); + } + } + } + + // line style + DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) ); + + // vary colors by point + xProp->setPropertyValue( C2U("VaryColorsByPoint"), uno::makeAny( true )); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + + +void SAL_CALL PieChartTypeTemplate::resetStyles( const Reference< chart2::XDiagram >& xDiagram ) + throw (uno::RuntimeException) +{ + // reset axes and grids + Reference< chart2::XCoordinateSystemContainer > xCooSysCnt( xDiagram, uno::UNO_QUERY ); + if( xCooSysCnt.is()) + { + Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems()); + ChartTypeTemplate::createAxes( aCooSysSeq ); + + //reset scale orientation + for( sal_Int32 nCooSysIdx=0; nCooSysIdx<aCooSysSeq.getLength(); ++nCooSysIdx ) + { + try + { + Reference< chart2::XAxis > xAxis( AxisHelper::getAxis( 0 /*nDimensionIndex*/,0 /*nAxisIndex*/ + , aCooSysSeq[nCooSysIdx] ) ); + if( xAxis.is() ) + { + chart2::ScaleData aScaleData( xAxis->getScaleData() ); + aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL; + xAxis->setScaleData( aScaleData ); + } + + xAxis = AxisHelper::getAxis( 1, 0, aCooSysSeq[nCooSysIdx] ); + if( xAxis.is() ) + { + chart2::ScaleData aScaleData( xAxis->getScaleData() ); + aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL; + xAxis->setScaleData( aScaleData ); + } + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + } + + ChartTypeTemplate::resetStyles( xDiagram ); + + // vary colors by point, + // line style + ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec( + DiagramHelper::getDataSeriesFromDiagram( xDiagram )); + uno::Any aLineStyleAny( uno::makeAny( drawing::LineStyle_NONE )); + for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin()); + aIt != aSeriesVec.end(); ++aIt ) + { + Reference< beans::XPropertyState > xState( *aIt, uno::UNO_QUERY ); + if( xState.is()) + { + xState->setPropertyToDefault( C2U("VaryColorsByPoint")); + Reference< beans::XPropertySet > xProp( xState, uno::UNO_QUERY ); + if( xProp.is() && + xProp->getPropertyValue( C2U("BorderStyle")) == aLineStyleAny ) + { + xState->setPropertyToDefault( C2U("BorderStyle")); + } + } + } + + //reset scene properties + ThreeDHelper::setDefaultRotation( uno::Reference< beans::XPropertySet >( xDiagram, uno::UNO_QUERY ), false ); +} + +// ____ XChartTypeTemplate ____ +void PieChartTypeTemplate::adaptDiagram( const uno::Reference< chart2::XDiagram >& xDiagram ) +{ + if( !xDiagram.is() ) + return; + + //different default for scene geometry: + ThreeDHelper::setDefaultRotation( uno::Reference< beans::XPropertySet >( xDiagram, uno::UNO_QUERY ), true ); +} + +// ---------------------------------------- + +uno::Sequence< ::rtl::OUString > PieChartTypeTemplate::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 2 ); + aServices[ 0 ] = lcl_aServiceName; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( PieChartTypeTemplate, lcl_aServiceName ); + +IMPLEMENT_FORWARD_XINTERFACE2( PieChartTypeTemplate, ChartTypeTemplate, OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( PieChartTypeTemplate, ChartTypeTemplate, OPropertySet ) + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/PieChartTypeTemplate.hxx b/chart2/source/model/template/PieChartTypeTemplate.hxx new file mode 100644 index 000000000000..6ae289bbaed7 --- /dev/null +++ b/chart2/source/model/template/PieChartTypeTemplate.hxx @@ -0,0 +1,139 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_PIECHARTTYPETEMPLATE_HXX +#define CHART_PIECHARTTYPETEMPLATE_HXX + +#include "OPropertySet.hxx" +#include "MutexContainer.hxx" +#include <comphelper/uno3.hxx> + +#include "ChartTypeTemplate.hxx" +#include <com/sun/star/chart2/PieChartOffsetMode.hpp> + +namespace chart +{ + +class PieChartTypeTemplate : + public MutexContainer, + public ChartTypeTemplate, + public ::property::OPropertySet +{ +public: + PieChartTypeTemplate( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName, + ::com::sun::star::chart2::PieChartOffsetMode eMode, + bool bRings = false, + sal_Int32 nDim = 2 ); + virtual ~PieChartTypeTemplate(); + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XChartTypeTemplate ____ + virtual sal_Bool SAL_CALL matchesTemplate( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDiagram >& xDiagram, + sal_Bool bAdaptProperties ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > SAL_CALL + getChartTypeForNewSeries( const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL applyStyle( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeGroupIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL resetStyles( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ ChartTypeTemplate ____ + virtual sal_Int32 getDimension() const; + + virtual void adaptDiagram( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDiagram > & xDiagram ); + + virtual sal_Int32 getAxisCountByDimension( sal_Int32 nDimension ); + + virtual void adaptAxes( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys ); + + virtual void adaptScales( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XCoordinateSystem > > & aCooSysSeq, + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::data::XLabeledDataSequence > & xCategories ); + + virtual void createChartTypes( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDataSeries > > >& aSeriesSeq, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > > & aOldChartTypesSeq + ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > + getChartTypeForIndex( sal_Int32 nChartTypeIndex ); +}; + +} // namespace chart + +// CHART_PIECHARTTYPETEMPLATE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/ScatterChartType.cxx b/chart2/source/model/template/ScatterChartType.cxx new file mode 100644 index 000000000000..3d7b0fff5f28 --- /dev/null +++ b/chart2/source/model/template/ScatterChartType.cxx @@ -0,0 +1,286 @@ +/* -*- 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 "ScatterChartType.hxx" +#include "PropertyHelper.hxx" +#include "macros.hxx" +#include "servicenames_charttypes.hxx" +#include "ContainerHelper.hxx" +#include "CartesianCoordinateSystem.hxx" +#include "AxisHelper.hxx" +#include "AxisIndexDefines.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/chart2/AxisType.hpp> +#include <com/sun/star/chart2/CurveStyle.hpp> + +using namespace ::com::sun::star; + +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +namespace +{ + +enum +{ + PROP_SCATTERCHARTTYPE_CURVE_STYLE, + PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION, + PROP_SCATTERCHARTTYPE_SPLINE_ORDER +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "CurveStyle" ), + PROP_SCATTERCHARTTYPE_CURVE_STYLE, + ::getCppuType( reinterpret_cast< const chart2::CurveStyle * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "CurveResolution" ), + PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "SplineOrder" ), + PROP_SCATTERCHARTTYPE_SPLINE_ORDER, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCATTERCHARTTYPE_CURVE_STYLE, chart2::CurveStyle_LINES ); + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION, 20 ); + + // todo: check whether order 3 means polygons of order 3 or 2. (see + // http://www.people.nnov.ru/fractal/Splines/Basis.htm ) + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_SPLINE_ORDER, 3 ); +} + +const Sequence< Property > & lcl_GetPropertySequence() +{ + static Sequence< Property > aPropSeq; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aPropSeq.getLength() ) + { + // get properties + ::std::vector< ::com::sun::star::beans::Property > aProperties; + lcl_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; +} + +} // anonymous namespace + +namespace chart +{ + +ScatterChartType::ScatterChartType( + const uno::Reference< uno::XComponentContext > & xContext, + chart2::CurveStyle eCurveStyle /* chart2::CurveStyle_LINES */ , + sal_Int32 nResolution /* = 20 */, + sal_Int32 nOrder /* = 3 */ ) : + ChartType( xContext ) +{ + if( eCurveStyle != chart2::CurveStyle_LINES ) + setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_CURVE_STYLE, + uno::makeAny( eCurveStyle )); + if( nResolution != 20 ) + setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_CURVE_RESOLUTION, + uno::makeAny( nResolution )); + if( nOrder != 3 ) + setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_SPLINE_ORDER, + uno::makeAny( nOrder )); +} + +ScatterChartType::ScatterChartType( const ScatterChartType & rOther ) : + ChartType( rOther ) +{ +} + +ScatterChartType::~ScatterChartType() +{} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL ScatterChartType::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new ScatterChartType( *this )); +} + +// ____ XChartType ____ +Reference< chart2::XCoordinateSystem > SAL_CALL + ScatterChartType::createCoordinateSystem( ::sal_Int32 DimensionCount ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + Reference< chart2::XCoordinateSystem > xResult( + new CartesianCoordinateSystem( + GetComponentContext(), DimensionCount, /* bSwapXAndYAxis */ sal_False )); + + for( sal_Int32 i=0; i<DimensionCount; ++i ) + { + Reference< chart2::XAxis > xAxis( xResult->getAxisByDimension( i, MAIN_AXIS_INDEX ) ); + if( !xAxis.is() ) + { + OSL_ENSURE(false,"a created coordinate system should have an axis for each dimension"); + continue; + } + + chart2::ScaleData aScaleData = xAxis->getScaleData(); + aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL; + aScaleData.Scaling = AxisHelper::createLinearScaling(); + + if( i == 2 ) + aScaleData.AxisType = chart2::AxisType::SERIES; + else + aScaleData.AxisType = chart2::AxisType::REALNUMBER; + + xAxis->setScaleData( aScaleData ); + } + + return xResult; +} + +::rtl::OUString SAL_CALL ScatterChartType::getChartType() + throw (uno::RuntimeException) +{ + return CHART2_SERVICE_NAME_CHARTTYPE_SCATTER; +} + +uno::Sequence< ::rtl::OUString > SAL_CALL ScatterChartType::getSupportedMandatoryRoles() + throw (uno::RuntimeException) +{ + static uno::Sequence< ::rtl::OUString > aMandRolesSeq; + + if( aMandRolesSeq.getLength() == 0 ) + { + aMandRolesSeq.realloc( 3 ); + aMandRolesSeq[0] = C2U( "label" ); + aMandRolesSeq[1] = C2U( "values-x" ); + aMandRolesSeq[2] = C2U( "values-y" ); + } + + return aMandRolesSeq; +} + +uno::Sequence< ::rtl::OUString > SAL_CALL ScatterChartType::getSupportedOptionalRoles() + throw (uno::RuntimeException) +{ + static uno::Sequence< ::rtl::OUString > aOptRolesSeq; + + return aOptRolesSeq; +} + + +// ____ OPropertySet ____ +uno::Any ScatterChartType::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 ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; +} + +// ____ OPropertySet ____ +::cppu::IPropertyArrayHelper & SAL_CALL ScatterChartType::getInfoHelper() +{ + static ::cppu::OPropertyArrayHelper aArrayHelper( lcl_GetPropertySequence(), + /* bSorted = */ sal_True ); + + return aArrayHelper; +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + ScatterChartType::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo; + + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + getInfoHelper()); + } + + return xInfo; +} + +uno::Sequence< ::rtl::OUString > ScatterChartType::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 3 ); + aServices[ 0 ] = CHART2_SERVICE_NAME_CHARTTYPE_SCATTER; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartType" ); + aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( ScatterChartType, + C2U( "com.sun.star.comp.chart.ScatterChartType" )); + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/ScatterChartType.hxx b/chart2/source/model/template/ScatterChartType.hxx new file mode 100644 index 000000000000..725d92e91351 --- /dev/null +++ b/chart2/source/model/template/ScatterChartType.hxx @@ -0,0 +1,94 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_SCATTERCHARTTYPE_HXX +#define CHART_SCATTERCHARTTYPE_HXX + +#include "ChartType.hxx" +#include "ServiceMacros.hxx" +#include <com/sun/star/chart2/CurveStyle.hpp> + +namespace chart +{ + +class ScatterChartType : public ChartType +{ +public: + ScatterChartType( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext, + ::com::sun::star::chart2::CurveStyle eCurveStyle = + ::com::sun::star::chart2::CurveStyle_LINES, + sal_Int32 nResolution = 20, + sal_Int32 nOrder = 3 ); + virtual ~ScatterChartType(); + + APPHELPER_XSERVICEINFO_DECL() + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( ScatterChartType ) + +protected: + explicit ScatterChartType( const ScatterChartType & rOther ); + + // ____ XChartType ____ + virtual ::rtl::OUString SAL_CALL getChartType() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedMandatoryRoles() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getSupportedOptionalRoles() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XCoordinateSystem > SAL_CALL + createCoordinateSystem( ::sal_Int32 DimensionCount ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + + // ____ OPropertySet ____ + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XCloneable ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() + throw (::com::sun::star::uno::RuntimeException); +}; + +} // namespace chart + +// CHART_SCATTERCHARTTYPE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/ScatterChartTypeTemplate.cxx b/chart2/source/model/template/ScatterChartTypeTemplate.cxx new file mode 100644 index 000000000000..f34ae6a52fe4 --- /dev/null +++ b/chart2/source/model/template/ScatterChartTypeTemplate.cxx @@ -0,0 +1,430 @@ +/* -*- 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 "ScatterChartTypeTemplate.hxx" +#include "macros.hxx" +#include "XYDataInterpreter.hxx" +#include "CartesianCoordinateSystem.hxx" +#include "DiagramHelper.hxx" +#include "servicenames_charttypes.hxx" +#include "ContainerHelper.hxx" +#include "DataSeriesHelper.hxx" +#include <com/sun/star/chart2/SymbolStyle.hpp> +#include <com/sun/star/chart2/Symbol.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> +#include "PropertyHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> + +#include <algorithm> + +using namespace ::com::sun::star; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +namespace +{ + +static const OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.ScatterChartTypeTemplate" )); + +enum +{ + PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE, + PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION, + PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER + +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "CurveStyle" ), + PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE, + ::getCppuType( reinterpret_cast< const chart2::CurveStyle * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "CurveResolution" ), + PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "SplineOrder" ), + PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE, chart2::CurveStyle_LINES ); + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION, 20 ); + + // todo: check whether order 3 means polygons of order 3 or 2. (see + // http://www.people.nnov.ru/fractal/Splines/Basis.htm ) + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER, 3 ); +} + +const Sequence< Property > & lcl_GetPropertySequence() +{ + static 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 ); + + // 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; +} + +} // anonymous namespace + +namespace chart +{ + +ScatterChartTypeTemplate::ScatterChartTypeTemplate( + Reference< + uno::XComponentContext > const & xContext, + const OUString & rServiceName, + bool bSymbols, + bool bHasLines /* = true */, + sal_Int32 nDim /* = 2 */ ) : + ChartTypeTemplate( xContext, rServiceName ), + ::property::OPropertySet( m_aMutex ), + m_bHasSymbols( bSymbols ), + m_bHasLines( bHasLines ), + m_nDim( nDim ) +{ + if( nDim == 3 ) + m_bHasSymbols = false; +} + +ScatterChartTypeTemplate::~ScatterChartTypeTemplate() +{} + +// ____ OPropertySet ____ +uno::Any ScatterChartTypeTemplate::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 ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; +} + +::cppu::IPropertyArrayHelper & SAL_CALL ScatterChartTypeTemplate::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + ScatterChartTypeTemplate::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; +} + +sal_Int32 ScatterChartTypeTemplate::getDimension() const +{ + return m_nDim; +} + +StackMode ScatterChartTypeTemplate::getStackMode( sal_Int32 /* nChartTypeIndex */ ) const +{ + if( m_nDim == 3 ) + return StackMode_Z_STACKED; + return StackMode_NONE; +} + +void SAL_CALL ScatterChartTypeTemplate::applyStyle( + const Reference< chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (uno::RuntimeException) +{ + ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount ); + + try + { + Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY_THROW ); + + DataSeriesHelper::switchSymbolsOnOrOff( xProp, m_bHasSymbols, nSeriesIndex ); + DataSeriesHelper::switchLinesOnOrOff( xProp, m_bHasLines ); + DataSeriesHelper::makeLinesThickOrThin( xProp, m_nDim==2 ); + if( m_nDim==3 ) + DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +// ____ XChartTypeTemplate ____ +sal_Bool SAL_CALL ScatterChartTypeTemplate::supportsCategories() + throw (uno::RuntimeException) +{ + return sal_False; +} + +sal_Bool SAL_CALL ScatterChartTypeTemplate::matchesTemplate( + const Reference< chart2::XDiagram >& xDiagram, + sal_Bool bAdaptProperties ) + throw (uno::RuntimeException) +{ + sal_Bool bResult = ChartTypeTemplate::matchesTemplate( xDiagram, bAdaptProperties ); + + // check symbol-style and line-style + // for a template with symbols (or with lines) it is ok, if there is at least one series + // with symbols (or with lines) + if( bResult ) + { + bool bSymbolFound = false; + bool bLineFound = false; + + ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec( + DiagramHelper::getDataSeriesFromDiagram( xDiagram )); + + for( ::std::vector< Reference< chart2::XDataSeries > >::const_iterator aIt = + aSeriesVec.begin(); aIt != aSeriesVec.end(); ++aIt ) + { + try + { + chart2::Symbol aSymbProp; + drawing::LineStyle eLineStyle; + Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY_THROW ); + + bool bCurrentHasSymbol = (xProp->getPropertyValue( C2U( "Symbol" )) >>= aSymbProp) && + (aSymbProp.Style != chart2::SymbolStyle_NONE); + + if( bCurrentHasSymbol ) + bSymbolFound = true; + + if( bCurrentHasSymbol && (!m_bHasSymbols) ) + { + bResult = false; + break; + } + + bool bCurrentHasLine = (xProp->getPropertyValue( C2U( "LineStyle" )) >>= eLineStyle) && + ( eLineStyle != drawing::LineStyle_NONE ); + + if( bCurrentHasLine ) + bLineFound = true; + + if( bCurrentHasLine && (!m_bHasLines) ) + { + bResult = false; + break; + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + if(bResult) + { + if( !bLineFound && m_bHasLines && bSymbolFound ) + bResult = false; + else if( !bSymbolFound && m_bHasSymbols && bLineFound ) + bResult = false; + else if( !bLineFound && !bSymbolFound ) + return m_bHasLines && m_bHasSymbols; + } + } + + // adapt curve style, spline order and resolution + if( bResult && bAdaptProperties ) + { + try + { + uno::Reference< beans::XPropertySet > xChartTypeProp( + DiagramHelper::getChartTypeByIndex( xDiagram, 0 ), + uno::UNO_QUERY_THROW ); + setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE, xChartTypeProp->getPropertyValue(C2U("CurveStyle" )) ); + setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION, xChartTypeProp->getPropertyValue(C2U("CurveResolution" )) ); + setFastPropertyValue_NoBroadcast( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER, xChartTypeProp->getPropertyValue(C2U("SplineOrder" )) ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + return bResult; +} + +Reference< chart2::XChartType > ScatterChartTypeTemplate::getChartTypeForIndex( sal_Int32 /*nChartTypeIndex*/ ) +{ + Reference< chart2::XChartType > xResult; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + xResult.set( xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_SCATTER ), uno::UNO_QUERY_THROW ); + + Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY ); + if( xCTProp.is()) + { + xCTProp->setPropertyValue( + C2U( "CurveStyle" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE )); + xCTProp->setPropertyValue( + C2U( "CurveResolution" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION )); + xCTProp->setPropertyValue( + C2U( "SplineOrder" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER )); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return xResult; +} + +Reference< chart2::XChartType > SAL_CALL ScatterChartTypeTemplate::getChartTypeForNewSeries( + const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (uno::RuntimeException) +{ + Reference< chart2::XChartType > xResult; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + xResult.set( xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_SCATTER ), uno::UNO_QUERY_THROW ); + + ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult ); + + Reference< beans::XPropertySet > xCTProp( xResult, uno::UNO_QUERY ); + if( xCTProp.is()) + { + xCTProp->setPropertyValue( + C2U( "CurveStyle" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_STYLE )); + xCTProp->setPropertyValue( + C2U( "CurveResolution" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_CURVE_RESOLUTION )); + xCTProp->setPropertyValue( + C2U( "SplineOrder" ), getFastPropertyValue( PROP_SCATTERCHARTTYPE_TEMPLATE_SPLINE_ORDER )); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return xResult; +} + +Reference< chart2::XDataInterpreter > SAL_CALL ScatterChartTypeTemplate::getDataInterpreter() + throw (uno::RuntimeException) +{ + if( ! m_xDataInterpreter.is()) + m_xDataInterpreter.set( new XYDataInterpreter( GetComponentContext()) ); + + return m_xDataInterpreter; +} + +// ---------------------------------------- + +Sequence< OUString > ScatterChartTypeTemplate::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 2 ); + aServices[ 0 ] = lcl_aServiceName; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( ScatterChartTypeTemplate, lcl_aServiceName ); + +IMPLEMENT_FORWARD_XINTERFACE2( ScatterChartTypeTemplate, ChartTypeTemplate, OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( ScatterChartTypeTemplate, ChartTypeTemplate, OPropertySet ) + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/ScatterChartTypeTemplate.hxx b/chart2/source/model/template/ScatterChartTypeTemplate.hxx new file mode 100644 index 000000000000..24ee0c15d1ad --- /dev/null +++ b/chart2/source/model/template/ScatterChartTypeTemplate.hxx @@ -0,0 +1,113 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_SCATTERCHARTTYPETEMPLATE_HXX +#define CHART_SCATTERCHARTTYPETEMPLATE_HXX + +#include "ChartTypeTemplate.hxx" +#include "OPropertySet.hxx" +#include "MutexContainer.hxx" +#include <comphelper/uno3.hxx> +#include <com/sun/star/chart2/CurveStyle.hpp> + +namespace chart +{ + +class ScatterChartTypeTemplate : + public MutexContainer, + public ChartTypeTemplate, + public ::property::OPropertySet +{ +public: + explicit ScatterChartTypeTemplate( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName, + bool bSymbols, + bool bHasLines = true, + sal_Int32 nDim = 2 ); + virtual ~ScatterChartTypeTemplate(); + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XChartTypeTemplate ____ + virtual sal_Bool SAL_CALL supportsCategories() + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL matchesTemplate( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDiagram >& xDiagram, + sal_Bool bAdaptProperties ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > SAL_CALL + getChartTypeForNewSeries( const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataInterpreter > SAL_CALL getDataInterpreter() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL applyStyle( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeGroupIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ ChartTypeTemplate ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > + getChartTypeForIndex( sal_Int32 nChartTypeIndex ); + virtual sal_Int32 getDimension() const; + virtual StackMode getStackMode( sal_Int32 nChartTypeIndex ) const; + +private: + bool m_bHasSymbols; + bool m_bHasLines; + sal_Int32 m_nDim; +}; + +} // namespace chart + +// CHART_SCATTERCHARTTYPETEMPLATE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/StockChartTypeTemplate.cxx b/chart2/source/model/template/StockChartTypeTemplate.cxx new file mode 100644 index 000000000000..d47bb48f2763 --- /dev/null +++ b/chart2/source/model/template/StockChartTypeTemplate.cxx @@ -0,0 +1,558 @@ +/* -*- 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 "StockChartTypeTemplate.hxx" +#include "macros.hxx" +#include "DataSeriesHelper.hxx" +#include "StockDataInterpreter.hxx" +#include "CartesianCoordinateSystem.hxx" +#include "AxisHelper.hxx" +#include "DiagramHelper.hxx" +#include "servicenames_charttypes.hxx" +#include "servicenames_coosystems.hxx" +#include "ContainerHelper.hxx" +#include "AxisIndexDefines.hxx" +#include <com/sun/star/chart2/AxisType.hpp> +#include <com/sun/star/chart2/SymbolStyle.hpp> +#include <com/sun/star/chart2/data/XDataSource.hpp> +#include <com/sun/star/chart2/XChartTypeContainer.hpp> +#include <com/sun/star/chart2/XDataSeriesContainer.hpp> +#include "PropertyHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> + +#include <vector> +#include <algorithm> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Any; +using ::osl::MutexGuard; + +// ---------------------------------------- +namespace +{ + +static const OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.StockChartTypeTemplate" )); + +enum +{ + PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME, + PROP_STOCKCHARTTYPE_TEMPLATE_OPEN, + PROP_STOCKCHARTTYPE_TEMPLATE_LOW_HIGH, + PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "Volume" ), + PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "Open" ), + PROP_STOCKCHARTTYPE_TEMPLATE_OPEN, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "LowHigh" ), + PROP_STOCKCHARTTYPE_TEMPLATE_LOW_HIGH, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "Japanese" ), + PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME, false ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_STOCKCHARTTYPE_TEMPLATE_OPEN, false ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_STOCKCHARTTYPE_TEMPLATE_LOW_HIGH, true ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE, false ); +} + +const Sequence< Property > & lcl_GetPropertySequence() +{ + static 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 ); + + // 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; +} + +} // anonymous namespace +// ---------------------------------------- + +namespace chart +{ + +StockChartTypeTemplate::StockChartTypeTemplate( + uno::Reference< + uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName, + StockVariant eVariant, + bool bJapaneseStyle ) : + ChartTypeTemplate( xContext, rServiceName ), + ::property::OPropertySet( m_aMutex ), + m_eStockVariant( eVariant ) +{ + setFastPropertyValue_NoBroadcast( + PROP_STOCKCHARTTYPE_TEMPLATE_OPEN, + uno::makeAny( ( eVariant == OPEN_LOW_HI_CLOSE || + eVariant == VOL_OPEN_LOW_HI_CLOSE ))); + setFastPropertyValue_NoBroadcast( + PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME, + uno::makeAny( ( eVariant == VOL_LOW_HI_CLOSE || + eVariant == VOL_OPEN_LOW_HI_CLOSE ))); + setFastPropertyValue_NoBroadcast( + PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE, + uno::makeAny( bJapaneseStyle )); +} + +StockChartTypeTemplate::~StockChartTypeTemplate() +{} +// ____ OPropertySet ____ +uno::Any StockChartTypeTemplate::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 ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; +} + +::cppu::IPropertyArrayHelper & SAL_CALL StockChartTypeTemplate::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + StockChartTypeTemplate::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; +} + +sal_Int32 StockChartTypeTemplate::getAxisCountByDimension( sal_Int32 nDimension ) +{ + // one x-axis + if( nDimension <= 0 ) + return 1; + // no further axes + if( nDimension >= 2 ) + return 0; + + // one or two y-axes depending on volume + OSL_ASSERT( nDimension == 1 ); + bool bHasVolume = false; + getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME ) >>= bHasVolume; + return bHasVolume ? 2 : 1; +} + +void SAL_CALL StockChartTypeTemplate::applyStyle( + const Reference< chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (uno::RuntimeException) +{ + ChartTypeTemplate::applyStyle( xSeries, nChartTypeIndex, nSeriesIndex, nSeriesCount ); + try + { + sal_Int32 nNewAxisIndex = 0; + + bool bHasVolume = false; + getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME ) >>= bHasVolume; + if( bHasVolume ) + { + if( nChartTypeIndex != 0 ) + nNewAxisIndex = 1; + } + + Reference< beans::XPropertySet > xProp( xSeries, uno::UNO_QUERY ); + if( xProp.is() ) + xProp->setPropertyValue( C2U("AttachedAxisIndex"), uno::makeAny( nNewAxisIndex ) ); + + if( bHasVolume && nChartTypeIndex==0 ) + { + //switch lines off for volume bars + DataSeriesHelper::setPropertyAlsoToAllAttributedDataPoints( xSeries, C2U( "BorderStyle" ), uno::makeAny( drawing::LineStyle_NONE ) ); + } + else + { + //ensure that lines are on + if( xProp.is() ) + { + drawing::LineStyle eStyle = drawing::LineStyle_NONE; + xProp->getPropertyValue( C2U("LineStyle") ) >>= eStyle; + if( eStyle == drawing::LineStyle_NONE ) + xProp->setPropertyValue( C2U("LineStyle"), uno::makeAny( drawing::LineStyle_SOLID )); + } + } + + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +void SAL_CALL StockChartTypeTemplate::resetStyles( + const Reference< chart2::XDiagram >& xDiagram ) + throw (uno::RuntimeException) +{ + ChartTypeTemplate::resetStyles( xDiagram ); + if( getDimension() == 3 ) + { + ::std::vector< Reference< chart2::XDataSeries > > aSeriesVec( + DiagramHelper::getDataSeriesFromDiagram( xDiagram )); + for( ::std::vector< Reference< chart2::XDataSeries > >::iterator aIt( aSeriesVec.begin()); + aIt != aSeriesVec.end(); ++aIt ) + { + Reference< beans::XPropertySet > xProp( *aIt, uno::UNO_QUERY ); + if( xProp.is() ) + xProp->setPropertyValue( C2U("AttachedAxisIndex"), uno::makeAny( sal_Int32(0) ) ); + } + } + + DiagramHelper::setVertical( xDiagram, false ); +} + +Reference< XChartType > StockChartTypeTemplate::getChartTypeForIndex( sal_Int32 nChartTypeIndex ) +{ + Reference< XChartType > xCT; + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY ); + if(xFact.is()) + { + bool bHasVolume = false; + getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME ) >>= bHasVolume; + if( bHasVolume ) + { + if( nChartTypeIndex == 0 ) + xCT.set( xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_COLUMN ), uno::UNO_QUERY ); + else if( nChartTypeIndex == 1 ) + xCT.set( xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK ), uno::UNO_QUERY ); + else + xCT.set( xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_LINE ), uno::UNO_QUERY ); + } + else + { + if( nChartTypeIndex == 0 ) + xCT.set( xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK ), uno::UNO_QUERY ); + else + xCT.set( xFact->createInstance( CHART2_SERVICE_NAME_CHARTTYPE_LINE ), uno::UNO_QUERY ); + } + } + return xCT; +} + +void StockChartTypeTemplate::createChartTypes( + const Sequence< Sequence< Reference< XDataSeries > > > & aSeriesSeq, + const Sequence< Reference< XCoordinateSystem > > & rCoordSys, + const Sequence< Reference< XChartType > >& /* aOldChartTypesSeq */ ) +{ + if( rCoordSys.getLength() < 1 ) + return; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + bool bHasVolume = false; + bool bShowFirst = false; + bool bJapaneseStyle = false; + bool bShowHighLow = true; + + getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME ) >>= bHasVolume; + getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_OPEN ) >>= bShowFirst; + getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE ) >>= bJapaneseStyle; + getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_LOW_HIGH ) >>= bShowHighLow; + + sal_Int32 nSeriesIndex = 0; + + std::vector< Reference< chart2::XChartType > > aChartTypeVec; + // Bars (Volume) + // ------------- + if( bHasVolume ) + { + // chart type + Reference< XChartType > xCT( + xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_COLUMN ), uno::UNO_QUERY_THROW ); + aChartTypeVec.push_back( xCT ); + + if( aSeriesSeq.getLength() > nSeriesIndex && + aSeriesSeq[nSeriesIndex].getLength() > 0 ) + { + Reference< XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW ); + xDSCnt->setDataSeries( aSeriesSeq[ nSeriesIndex ] ); + } + ++nSeriesIndex; + } + + Reference< XChartType > xCT( + xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK ), uno::UNO_QUERY_THROW ); + aChartTypeVec.push_back( xCT ); + + Reference< beans::XPropertySet > xCTProp( xCT, uno::UNO_QUERY ); + if( xCTProp.is()) + { + xCTProp->setPropertyValue( C2U("Japanese"), uno::makeAny( bJapaneseStyle )); + xCTProp->setPropertyValue( C2U("ShowFirst"), uno::makeAny( bShowFirst )); + xCTProp->setPropertyValue( C2U("ShowHighLow"), uno::makeAny( bShowHighLow )); + } + + if( aSeriesSeq.getLength() > nSeriesIndex && + aSeriesSeq[ nSeriesIndex ].getLength() > 0 ) + { + Reference< XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW ); + xDSCnt->setDataSeries( aSeriesSeq[ nSeriesIndex ] ); + } + ++nSeriesIndex; + + // Lines (remaining series) + // ------------------------ + if( aSeriesSeq.getLength() > nSeriesIndex && + aSeriesSeq[ nSeriesIndex ].getLength() > 0 ) + { + xCT.set( + xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_LINE ), uno::UNO_QUERY_THROW ); + aChartTypeVec.push_back( xCT ); + + Reference< XDataSeriesContainer > xDSCnt( xCT, uno::UNO_QUERY_THROW ); + xDSCnt->setDataSeries( aSeriesSeq[ nSeriesIndex ] ); + } + + Reference< XChartTypeContainer > xCTCnt( rCoordSys[ 0 ], uno::UNO_QUERY_THROW ); + xCTCnt->setChartTypes( ::chart::ContainerHelper::ContainerToSequence(aChartTypeVec) ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +// ____ XChartTypeTemplate ____ +sal_Bool SAL_CALL StockChartTypeTemplate::matchesTemplate( + const uno::Reference< XDiagram >& xDiagram, + sal_Bool /* bAdaptProperties */ ) + throw (uno::RuntimeException) +{ + sal_Bool bResult = sal_False; + + if( ! xDiagram.is()) + return bResult; + + try + { + sal_Bool bHasVolume = false, bHasOpenValue = false, bHasJapaneseStyle = false; + + getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_VOLUME ) >>= bHasVolume; + getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_OPEN ) >>= bHasOpenValue; + getFastPropertyValue( PROP_STOCKCHARTTYPE_TEMPLATE_JAPANESE ) >>= bHasJapaneseStyle; + + Reference< chart2::XChartType > xVolumeChartType; + Reference< chart2::XChartType > xCandleStickChartType; + Reference< chart2::XChartType > xLineChartType; + sal_Int32 nNumberOfChartTypes = 0; + + Reference< XCoordinateSystemContainer > xCooSysCnt( + xDiagram, uno::UNO_QUERY_THROW ); + Sequence< Reference< XCoordinateSystem > > aCooSysSeq( + xCooSysCnt->getCoordinateSystems()); + for( sal_Int32 i=0; i<aCooSysSeq.getLength(); ++i ) + { + Reference< XChartTypeContainer > xCTCnt( aCooSysSeq[i], uno::UNO_QUERY_THROW ); + Sequence< Reference< XChartType > > aChartTypeSeq( xCTCnt->getChartTypes()); + for( sal_Int32 j=0; j<aChartTypeSeq.getLength(); ++j ) + { + if( aChartTypeSeq[j].is()) + { + ++nNumberOfChartTypes; + if( nNumberOfChartTypes > 3 ) + break; + OUString aCTService = aChartTypeSeq[j]->getChartType(); + if( aCTService.equals( CHART2_SERVICE_NAME_CHARTTYPE_COLUMN )) + xVolumeChartType.set( aChartTypeSeq[j] ); + else if( aCTService.equals( CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK )) + xCandleStickChartType.set( aChartTypeSeq[j] ); + else if( aCTService.equals( CHART2_SERVICE_NAME_CHARTTYPE_LINE )) + xLineChartType.set( aChartTypeSeq[j] ); + } + } + if( nNumberOfChartTypes > 3 ) + break; + } + + if( xCandleStickChartType.is() && + ( ( bHasVolume && + xVolumeChartType.is() ) || + ( ! bHasVolume && + ! xVolumeChartType.is() ))) + { + bResult = true; + + // check for japanese style + Reference< beans::XPropertySet > xCTProp( xCandleStickChartType, uno::UNO_QUERY ); + if( xCTProp.is()) + { + sal_Bool bJapaneseProp = sal_False; + xCTProp->getPropertyValue( C2U("Japanese")) >>= bJapaneseProp; + bResult = bResult && ( bHasJapaneseStyle == bJapaneseProp ); + + // in old chart japanese == showFirst + sal_Bool bShowFirstProp = sal_False; + xCTProp->getPropertyValue( C2U("ShowFirst")) >>= bShowFirstProp; + bResult = bResult && ( bHasOpenValue == bShowFirstProp ); + } + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return bResult; +} + +Reference< XChartType > SAL_CALL StockChartTypeTemplate::getChartTypeForNewSeries( + const uno::Sequence< Reference< chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (uno::RuntimeException) +{ + Reference< chart2::XChartType > xResult; + + try + { + Reference< lang::XMultiServiceFactory > xFact( + GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW ); + xResult.set( xFact->createInstance( + CHART2_SERVICE_NAME_CHARTTYPE_LINE ), uno::UNO_QUERY_THROW ); + ChartTypeTemplate::copyPropertiesFromOldToNewCoordianteSystem( aFormerlyUsedChartTypes, xResult ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return xResult; +} + +Reference< XDataInterpreter > SAL_CALL StockChartTypeTemplate::getDataInterpreter() + throw (uno::RuntimeException) +{ + if( ! m_xDataInterpreter.is()) + m_xDataInterpreter.set( new StockDataInterpreter( m_eStockVariant, GetComponentContext() ) ); + + return m_xDataInterpreter; +} + +// ---------------------------------------- + +Sequence< OUString > StockChartTypeTemplate::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 2 ); + aServices[ 0 ] = lcl_aServiceName; + aServices[ 1 ] = C2U( "com.sun.star.chart2.ChartTypeTemplate" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( StockChartTypeTemplate, lcl_aServiceName ); + +IMPLEMENT_FORWARD_XINTERFACE2( StockChartTypeTemplate, ChartTypeTemplate, OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( StockChartTypeTemplate, ChartTypeTemplate, OPropertySet ) + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/StockChartTypeTemplate.hxx b/chart2/source/model/template/StockChartTypeTemplate.hxx new file mode 100644 index 000000000000..65a8424342cb --- /dev/null +++ b/chart2/source/model/template/StockChartTypeTemplate.hxx @@ -0,0 +1,141 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_STOCKCHARTTYPETEMPLATE_HXX +#define CHART_STOCKCHARTTYPETEMPLATE_HXX + +#include "ChartTypeTemplate.hxx" +#include "OPropertySet.hxx" +#include "MutexContainer.hxx" +#include <comphelper/uno3.hxx> + +namespace chart +{ + +class StockChartTypeTemplate : + public MutexContainer, + public ChartTypeTemplate, + public ::property::OPropertySet +{ +public: + enum StockVariant + { + LOW_HI_CLOSE, + OPEN_LOW_HI_CLOSE, + VOL_LOW_HI_CLOSE, + VOL_OPEN_LOW_HI_CLOSE + }; + + /** CTOR + + @param bJapaneseStyle + If true, the candlesticks are drawn as solid white or black boxes + depending on rising or falling stock-values. Otherwise the + open-value will be drawn as a small line at the left side of a + straight vertical line, and the close-value on the right hand side. + */ + explicit StockChartTypeTemplate( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext, + const ::rtl::OUString & rServiceName, + StockVariant eVariant, + bool bJapaneseStyle ); + virtual ~StockChartTypeTemplate(); + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + // ____ OPropertySet ____ + virtual ::com::sun::star::uno::Any GetDefaultValue( sal_Int32 nHandle ) const + throw(::com::sun::star::beans::UnknownPropertyException); + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ XPropertySet ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XChartTypeTemplate ____ + virtual sal_Bool SAL_CALL matchesTemplate( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDiagram >& xDiagram, + sal_Bool bAdaptProperties ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > SAL_CALL + getChartTypeForNewSeries( const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > >& aFormerlyUsedChartTypes ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataInterpreter > SAL_CALL getDataInterpreter() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL applyStyle( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries >& xSeries, + ::sal_Int32 nChartTypeIndex, + ::sal_Int32 nSeriesIndex, + ::sal_Int32 nSeriesCount ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL resetStyles( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram ) + throw (::com::sun::star::uno::RuntimeException); + + // ChartTypeTemplate + virtual sal_Int32 getAxisCountByDimension( sal_Int32 nDimension ); + + // ____ ChartTypeTemplate ____ + virtual void createChartTypes( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDataSeries > > >& aSeriesSeq, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > > & aOldChartTypesSeq + ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > + getChartTypeForIndex( sal_Int32 nChartTypeIndex ); + +private: + // todo: deprecate this variable + StockVariant m_eStockVariant; +}; + +} // namespace chart + +// CHART_STOCKCHARTTYPETEMPLATE_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/StockDataInterpreter.cxx b/chart2/source/model/template/StockDataInterpreter.cxx new file mode 100644 index 000000000000..4842bdb02d81 --- /dev/null +++ b/chart2/source/model/template/StockDataInterpreter.cxx @@ -0,0 +1,345 @@ +/* -*- 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 "StockDataInterpreter.hxx" +#include "DataSeries.hxx" +#include "macros.hxx" +#include "DataSeriesHelper.hxx" +#include "CommonConverters.hxx" +#include "ContainerHelper.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/chart2/data/XDataSink.hpp> + +#include <vector> +#include <algorithm> +#include <iterator> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; +using namespace ::std; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; +using namespace ::chart::ContainerHelper; + +namespace chart +{ + +// explicit +StockDataInterpreter::StockDataInterpreter( + StockChartTypeTemplate::StockVariant eVariant, + const Reference< uno::XComponentContext > & xContext ) : + DataInterpreter( xContext ), + m_eStockVariant( eVariant ) +{} + +StockDataInterpreter::~StockDataInterpreter() +{} + +StockChartTypeTemplate::StockVariant StockDataInterpreter::GetStockVariant() const +{ + return m_eStockVariant; +} + +// ____ XDataInterpreter ____ +InterpretedData SAL_CALL StockDataInterpreter::interpretDataSource( + const Reference< data::XDataSource >& xSource, + const Sequence< beans::PropertyValue >& rArguments, + const Sequence< Reference< XDataSeries > >& rSeriesToReUse ) + throw (uno::RuntimeException) +{ + if( ! xSource.is()) + return InterpretedData(); + + Reference< data::XLabeledDataSequence > xCategories; + Sequence< Reference< data::XLabeledDataSequence > > aData( xSource->getDataSequences() ); + const sal_Int32 nDataCount( aData.getLength()); + + // sub-type properties + const StockChartTypeTemplate::StockVariant eVar( GetStockVariant()); + const bool bHasOpenValues (( eVar == StockChartTypeTemplate::OPEN_LOW_HI_CLOSE ) || + ( eVar == StockChartTypeTemplate::VOL_OPEN_LOW_HI_CLOSE )); + const bool bHasVolume (( eVar == StockChartTypeTemplate::VOL_LOW_HI_CLOSE ) || + ( eVar == StockChartTypeTemplate::VOL_OPEN_LOW_HI_CLOSE )); + const bool bHasCategories( HasCategories( rArguments, aData )); + + // necessary roles for "full series" + // low/high/close + sal_Int32 nNumberOfNecessarySequences( 3 ); + if( bHasOpenValues ) + ++nNumberOfNecessarySequences; + if( bHasVolume ) + ++nNumberOfNecessarySequences; + + // calculate number of full series (nNumOfFullSeries) and the number of remaining + // sequences used for additional "incomplete series" (nRemaining) + sal_Int32 nNumOfFullSeries( 0 ); + sal_Int32 nRemaining( 0 ); + { + sal_Int32 nAvailableSequences( nDataCount ); + if( bHasCategories ) + --nAvailableSequences; + nNumOfFullSeries = nAvailableSequences / nNumberOfNecessarySequences; + nRemaining = nAvailableSequences % nNumberOfNecessarySequences; + } + sal_Int32 nCandleStickSeries = nNumOfFullSeries; + sal_Int32 nVolumeSeries = nNumOfFullSeries; + + sal_Int32 nNumberOfGroups( bHasVolume ? 2 : 1 ); + // sequences of data::XLabeledDataSequence per series per group + Sequence< Sequence< Sequence< Reference< data::XLabeledDataSequence > > > > aSequences( nNumberOfGroups ); + sal_Int32 nBarGroupIndex( 0 ); + sal_Int32 nCandleStickGroupIndex( nNumberOfGroups - 1 ); + + // allocate space for labeled sequences + if( nRemaining > 0 ) + ++nCandleStickSeries; + aSequences[nCandleStickGroupIndex].realloc( nCandleStickSeries ); + if( bHasVolume ) + { + // if there are remaining sequences, the first one is taken for + // additional close values, the second one is taken as volume, if volume + // is used + if( nRemaining > 1 ) + ++nVolumeSeries; + aSequences[nBarGroupIndex].realloc( nVolumeSeries ); + } + + + // create data + sal_Int32 nSourceIndex = 0; // index into aData sequence + + // 1. categories + if( bHasCategories ) + { + xCategories.set( aData[nSourceIndex] ); + ++nSourceIndex; + } + + // 2. create "full" series + for( sal_Int32 nLabeledSeqIdx=0; nLabeledSeqIdx<nNumOfFullSeries; ++nLabeledSeqIdx ) + { + // bar + if( bHasVolume ) + { + aSequences[nBarGroupIndex][nLabeledSeqIdx].realloc( 1 ); + aSequences[nBarGroupIndex][nLabeledSeqIdx][0].set( aData[nSourceIndex] ); + if( aData[nSourceIndex].is()) + SetRole( aData[nSourceIndex]->getValues(), C2U("values-y")); + ++nSourceIndex; + } + + sal_Int32 nSeqIdx = 0; + if( bHasOpenValues ) + { + aSequences[nCandleStickGroupIndex][nLabeledSeqIdx].realloc( 4 ); + aSequences[nCandleStickGroupIndex][nLabeledSeqIdx][nSeqIdx].set( aData[nSourceIndex] ); + if( aData[nSourceIndex].is()) + SetRole( aData[nSourceIndex]->getValues(), C2U("values-first")); + ++nSourceIndex, ++nSeqIdx; + } + else + aSequences[nCandleStickGroupIndex][nLabeledSeqIdx].realloc( 3 ); + + aSequences[nCandleStickGroupIndex][nLabeledSeqIdx][nSeqIdx].set( aData[nSourceIndex] ); + if( aData[nSourceIndex].is()) + SetRole( aData[nSourceIndex]->getValues(), C2U("values-min")); + ++nSourceIndex, ++nSeqIdx; + + aSequences[nCandleStickGroupIndex][nLabeledSeqIdx][nSeqIdx].set( aData[nSourceIndex] ); + if( aData[nSourceIndex].is()) + SetRole( aData[nSourceIndex]->getValues(), C2U("values-max")); + ++nSourceIndex, ++nSeqIdx; + + aSequences[nCandleStickGroupIndex][nLabeledSeqIdx][nSeqIdx].set( aData[nSourceIndex] ); + if( aData[nSourceIndex].is()) + SetRole( aData[nSourceIndex]->getValues(), C2U("values-last")); + ++nSourceIndex, ++nSeqIdx; + } + + // 3. create series with remaining sequences + if( bHasVolume && nRemaining > 1 ) + { + OSL_ASSERT( nVolumeSeries > nNumOfFullSeries ); + aSequences[nBarGroupIndex][nVolumeSeries - 1].realloc( 1 ); + OSL_ASSERT( nDataCount > nSourceIndex ); + if( aData[nSourceIndex].is()) + SetRole( aData[nSourceIndex]->getValues(), C2U("values-y")); + aSequences[nBarGroupIndex][nVolumeSeries - 1][0].set( aData[nSourceIndex] ); + ++nSourceIndex; + --nRemaining; + OSL_ENSURE( nRemaining, "additional bar should only be used if there is at least one more sequence for a candle stick" ); + } + + // candle-stick + if( nRemaining > 0 ) + { + OSL_ASSERT( nCandleStickSeries > nNumOfFullSeries ); + const sal_Int32 nSeriesIndex = nCandleStickSeries - 1; + aSequences[nCandleStickGroupIndex][nSeriesIndex].realloc( nRemaining ); + OSL_ASSERT( nDataCount > nSourceIndex ); + + // 1. low + sal_Int32 nSeqIdx( 0 ); + aSequences[nCandleStickGroupIndex][nSeriesIndex][nSeqIdx].set( aData[nSourceIndex] ); + if( aData[nSourceIndex].is()) + SetRole( aData[nSourceIndex]->getValues(), C2U("values-min")); + ++nSourceIndex, ++nSeqIdx; + + // 2. high + if( nSeqIdx < nRemaining ) + { + aSequences[nCandleStickGroupIndex][nSeriesIndex][nSeqIdx].set( aData[nSourceIndex] ); + if( aData[nSourceIndex].is()) + SetRole( aData[nSourceIndex]->getValues(), C2U("values-max")); + ++nSourceIndex, ++nSeqIdx; + } + + // 3. close + OSL_ENSURE( bHasOpenValues || nSeqIdx >= nRemaining, "could have created full series" ); + if( nSeqIdx < nRemaining ) + { + aSequences[nCandleStickGroupIndex][nSeriesIndex][nSeqIdx].set( aData[nSourceIndex] ); + if( aData[nSourceIndex].is()) + SetRole( aData[nSourceIndex]->getValues(), C2U("values-last")); + ++nSourceIndex, ++nSeqIdx; + } + + // 4. open + OSL_ENSURE( nSeqIdx >= nRemaining, "could have created full series" ); + } + + // create DataSeries + Sequence< Sequence< Reference< XDataSeries > > > aResultSeries( nNumberOfGroups ); + sal_Int32 nGroupIndex, nReUsedSeriesIdx = 0; + for( nGroupIndex=0; nGroupIndex<nNumberOfGroups; ++nGroupIndex ) + { + const sal_Int32 nNumSeriesData = aSequences[nGroupIndex].getLength(); + aResultSeries[nGroupIndex].realloc( nNumSeriesData ); + for( sal_Int32 nSeriesIdx = 0; nSeriesIdx < nNumSeriesData; ++nSeriesIdx, ++nReUsedSeriesIdx ) + { + try + { + Reference< XDataSeries > xSeries; + if( nReUsedSeriesIdx < rSeriesToReUse.getLength()) + xSeries.set( rSeriesToReUse[nReUsedSeriesIdx] ); + else + xSeries.set( new DataSeries( GetComponentContext() ) ); + OSL_ASSERT( xSeries.is() ); + Reference< data::XDataSink > xSink( xSeries, uno::UNO_QUERY_THROW ); + OSL_ASSERT( xSink.is() ); + xSink->setData( aSequences[nGroupIndex][nSeriesIdx] ); + aResultSeries[nGroupIndex][nSeriesIdx].set( xSeries ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + } + + return InterpretedData( aResultSeries, xCategories ); +} + +// criterion: there must be two groups for stock-charts with volume and all +// series must have the correct number of data::XLabeledDataSequences + +// todo: skip first criterion? (to allow easy switch from stock-chart without +// volume to one with volume) +sal_Bool SAL_CALL StockDataInterpreter::isDataCompatible( + const InterpretedData& aInterpretedData ) + throw (uno::RuntimeException) +{ + // high/low/close + sal_Int32 nNumberOfNecessarySequences = 3; + // open + StockChartTypeTemplate::StockVariant eVar( GetStockVariant()); + if( ( eVar == StockChartTypeTemplate::OPEN_LOW_HI_CLOSE ) || + ( eVar == StockChartTypeTemplate::VOL_OPEN_LOW_HI_CLOSE )) + ++nNumberOfNecessarySequences; + // volume + bool bHasVolume = (( eVar == StockChartTypeTemplate::VOL_LOW_HI_CLOSE ) || + ( eVar == StockChartTypeTemplate::VOL_OPEN_LOW_HI_CLOSE )); + + // 1. correct number of sub-types + if( aInterpretedData.Series.getLength() < (bHasVolume ? 2 : 1 )) + return sal_False; + + // 2. a. volume -- use default check + if( bHasVolume ) + { + if( ! DataInterpreter::isDataCompatible( + InterpretedData( Sequence< Sequence< Reference< XDataSeries > > >( + aInterpretedData.Series.getConstArray(), 1 ), + aInterpretedData.Categories ))) + return sal_False; + } + + // 2. b. candlestick + { + OSL_ASSERT( aInterpretedData.Series.getLength() > (bHasVolume ? 1 : 0)); + Sequence< Reference< XDataSeries > > aSeries( aInterpretedData.Series[(bHasVolume ? 1 : 0)] ); + if(!aSeries.getLength()) + return sal_False; + for( sal_Int32 i=0; i<aSeries.getLength(); ++i ) + { + try + { + Reference< data::XDataSource > xSrc( aSeries[i], uno::UNO_QUERY_THROW ); + Sequence< Reference< data::XLabeledDataSequence > > aSeq( xSrc->getDataSequences()); + if( aSeq.getLength() != nNumberOfNecessarySequences ) + return sal_False; + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + } + + // 2. c. additional series + // ignore + + return sal_True; +} + +InterpretedData SAL_CALL StockDataInterpreter::reinterpretDataSeries( + const InterpretedData& aInterpretedData ) + throw (uno::RuntimeException) +{ + // prerequisite: StockDataInterpreter::isDataCompatible() returned true + return aInterpretedData; +} + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/StockDataInterpreter.hxx b/chart2/source/model/template/StockDataInterpreter.hxx new file mode 100644 index 000000000000..d2ad20800f37 --- /dev/null +++ b/chart2/source/model/template/StockDataInterpreter.hxx @@ -0,0 +1,72 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_STOCKDATAINTERPRETER_HXX +#define CHART_STOCKDATAINTERPRETER_HXX + +#include "DataInterpreter.hxx" + +#include "StockChartTypeTemplate.hxx" + +namespace chart +{ + +class StockDataInterpreter : public DataInterpreter +{ +public: + explicit StockDataInterpreter( + StockChartTypeTemplate::StockVariant eVariant, + const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext ); + virtual ~StockDataInterpreter(); + +protected: + // ____ XDataInterpreter ____ + virtual ::com::sun::star::chart2::InterpretedData SAL_CALL interpretDataSource( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xSource, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments, + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >& aSeriesToReUse ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isDataCompatible( + const ::com::sun::star::chart2::InterpretedData& aInterpretedData ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::chart2::InterpretedData SAL_CALL reinterpretDataSeries( + const ::com::sun::star::chart2::InterpretedData& aInterpretedData ) + throw (::com::sun::star::uno::RuntimeException); + +private: + StockChartTypeTemplate::StockVariant m_eStockVariant; + + StockChartTypeTemplate::StockVariant GetStockVariant() const; +}; + +} // namespace chart + +// CHART_STOCKDATAINTERPRETER_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/XYDataInterpreter.cxx b/chart2/source/model/template/XYDataInterpreter.cxx new file mode 100644 index 000000000000..249a6a69c1b2 --- /dev/null +++ b/chart2/source/model/template/XYDataInterpreter.cxx @@ -0,0 +1,276 @@ +/* -*- 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 "XYDataInterpreter.hxx" +#include "DataSeries.hxx" +#include "macros.hxx" +#include "DataSeriesHelper.hxx" +#include "CommonConverters.hxx" +#include "ContainerHelper.hxx" +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/chart2/data/XDataSink.hpp> +#include <com/sun/star/util/XCloneable.hpp> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::chart2; +using namespace ::std; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; + +namespace chart +{ + +XYDataInterpreter::XYDataInterpreter( + const uno::Reference< uno::XComponentContext > & xContext ) : + DataInterpreter( xContext ) +{ +} + +XYDataInterpreter::~XYDataInterpreter() +{ +} + +// ____ XDataInterpreter ____ +chart2::InterpretedData SAL_CALL XYDataInterpreter::interpretDataSource( + const Reference< chart2::data::XDataSource >& xSource, + const Sequence< beans::PropertyValue >& aArguments, + const Sequence< Reference< XDataSeries > >& aSeriesToReUse ) + throw (uno::RuntimeException) +{ + if( ! xSource.is()) + return InterpretedData(); + + Sequence< Reference< data::XLabeledDataSequence > > aData( xSource->getDataSequences() ); + + Reference< data::XLabeledDataSequence > xValuesX; + vector< Reference< data::XLabeledDataSequence > > aSequencesVec; + + Reference< data::XLabeledDataSequence > xCategories; + // check for categories. If true, the the categories bet parked in the axis scale, but not used via setting the Axistype to Not CATEGORY + bool bHasCategories = HasCategories( aArguments, aData ); + + // parse data + bool bCategoriesUsed = false; + for( sal_Int32 nDataIdx= 0; nDataIdx < aData.getLength(); ++nDataIdx ) + { + try + { + if( bHasCategories && ! bCategoriesUsed ) + { + xCategories.set( aData[nDataIdx] ); + if( xCategories.is()) + SetRole( xCategories->getValues(), C2U("categories")); + bCategoriesUsed = true; + } + else if( !xValuesX.is() && (aData.getLength()>(bCategoriesUsed?2:1)) ) + { + xValuesX.set( aData[nDataIdx] ); + if( xValuesX.is()) + SetRole( xValuesX->getValues(), C2U("values-x")); + } + else + { + aSequencesVec.push_back( aData[nDataIdx] ); + if( aData[nDataIdx].is()) + SetRole( aData[nDataIdx]->getValues(), C2U("values-y")); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + // create DataSeries + vector< Reference< data::XLabeledDataSequence > >::const_iterator + aSequencesVecIt = aSequencesVec.begin(); + + sal_Int32 nSeriesIndex = 0; + vector< Reference< XDataSeries > > aSeriesVec; + aSeriesVec.reserve( aSequencesVec.size()); + + Reference< data::XLabeledDataSequence > xClonedXValues = xValuesX; + Reference< util::XCloneable > xCloneable( xValuesX, uno::UNO_QUERY ); + + for( ;aSequencesVecIt != aSequencesVec.end(); ++aSequencesVecIt, ++nSeriesIndex ) + { + Sequence< Reference< data::XLabeledDataSequence > > aNewData(xValuesX.is()?2:1); + if( aSequencesVecIt != aSequencesVec.begin() && + xCloneable.is() ) + { + xClonedXValues.set( xCloneable->createClone(), uno::UNO_QUERY ); + } + + if( xValuesX.is() ) + { + aNewData[0] = xClonedXValues; + aNewData[1] = (*aSequencesVecIt); + } + else + { + aNewData[0] = (*aSequencesVecIt); + } + + Reference< XDataSeries > xSeries; + if( nSeriesIndex < aSeriesToReUse.getLength()) + xSeries.set( aSeriesToReUse[nSeriesIndex] ); + else + xSeries.set( new DataSeries( GetComponentContext() ) ); + OSL_ASSERT( xSeries.is() ); + Reference< data::XDataSink > xSink( xSeries, uno::UNO_QUERY ); + OSL_ASSERT( xSink.is() ); + xSink->setData( aNewData ); + + aSeriesVec.push_back( xSeries ); + } + + Sequence< Sequence< Reference< XDataSeries > > > aSeries(1); + aSeries[0] = ContainerHelper::ContainerToSequence( aSeriesVec ); + return InterpretedData( aSeries, xCategories ); +} + +chart2::InterpretedData SAL_CALL XYDataInterpreter::reinterpretDataSeries( + const chart2::InterpretedData& aInterpretedData ) + throw (uno::RuntimeException) +{ + InterpretedData aResult( aInterpretedData ); + + sal_Int32 i=0; + Sequence< Reference< XDataSeries > > aSeries( FlattenSequence( aInterpretedData.Series )); + const sal_Int32 nCount = aSeries.getLength(); + for( ; i<nCount; ++i ) + { + try + { + Reference< data::XDataSource > xSeriesSource( aSeries[i], uno::UNO_QUERY_THROW ); + Sequence< Reference< data::XLabeledDataSequence > > aNewSequences; + + // values-y + Reference< data::XLabeledDataSequence > xValuesY( + DataSeriesHelper::getDataSequenceByRole( xSeriesSource, C2U("values-y"), false )); + Reference< data::XLabeledDataSequence > xValuesX( + DataSeriesHelper::getDataSequenceByRole( xSeriesSource, C2U("values-x"), false )); + // re-use values-... as values-x/values-y + if( ! xValuesX.is() || + ! xValuesY.is()) + { + vector< Reference< data::XLabeledDataSequence > > aValueSeqVec( + DataSeriesHelper::getAllDataSequencesByRole( + xSeriesSource->getDataSequences(), C2U("values"), true )); + if( xValuesX.is()) + aValueSeqVec.erase( find( aValueSeqVec.begin(), aValueSeqVec.end(), xValuesX )); + if( xValuesY.is()) + aValueSeqVec.erase( find( aValueSeqVec.begin(), aValueSeqVec.end(), xValuesY )); + + size_t nIndex = 0; + if( ! xValuesY.is() && + aValueSeqVec.size() > nIndex ) + { + xValuesY.set( aValueSeqVec[nIndex++] ); + if( xValuesY.is()) + SetRole( xValuesY->getValues(), C2U("values-y")); + } + + if( ! xValuesX.is() && + aValueSeqVec.size() > nIndex ) + { + xValuesX.set( aValueSeqVec[nIndex++] ); + if( xValuesX.is()) + SetRole( xValuesY->getValues(), C2U("values-x")); + } + } + if( xValuesY.is()) + { + if( xValuesX.is()) + { + aNewSequences.realloc(2); + aNewSequences[0] = xValuesX; + aNewSequences[1] = xValuesY; + } + else + { + aNewSequences.realloc(1); + aNewSequences[0] = xValuesY; + } + } + + Sequence< Reference< data::XLabeledDataSequence > > aSeqs( xSeriesSource->getDataSequences()); + if( aSeqs.getLength() != aNewSequences.getLength() ) + { +#if OSL_DEBUG_LEVEL > 1 + sal_Int32 j=0; + for( ; j<aSeqs.getLength(); ++j ) + { + OSL_ENSURE( aSeqs[j] == xValuesY || aSeqs[j] == xValuesX, "All sequences should be used" ); + } +#endif + Reference< data::XDataSink > xSink( xSeriesSource, uno::UNO_QUERY_THROW ); + xSink->setData( aNewSequences ); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + return aResult; +} + +// criterion: all series must have exactly two data::XLabeledDataSequences +sal_Bool SAL_CALL XYDataInterpreter::isDataCompatible( + const chart2::InterpretedData& aInterpretedData ) + throw (uno::RuntimeException) +{ + Sequence< Reference< XDataSeries > > aSeries( FlattenSequence( aInterpretedData.Series )); + for( sal_Int32 i=0; i<aSeries.getLength(); ++i ) + { + try + { + Reference< data::XDataSource > xSrc( aSeries[i], uno::UNO_QUERY_THROW ); + Sequence< Reference< data::XLabeledDataSequence > > aSeq( xSrc->getDataSequences()); + if( aSeq.getLength() != 2 ) + return sal_False; + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + return sal_True; +} + +} // namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/XYDataInterpreter.hxx b/chart2/source/model/template/XYDataInterpreter.hxx new file mode 100644 index 000000000000..74ebb28d0a40 --- /dev/null +++ b/chart2/source/model/template/XYDataInterpreter.hxx @@ -0,0 +1,64 @@ +/* -*- 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. + * + ************************************************************************/ +#ifndef CHART_XYDATAINTERPRETER_HXX +#define CHART_XYDATAINTERPRETER_HXX + +#include "DataInterpreter.hxx" + +namespace chart +{ + +class XYDataInterpreter : public DataInterpreter +{ +public: + explicit XYDataInterpreter( + const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext ); + virtual ~XYDataInterpreter(); + +protected: + // ____ XDataInterpreter ____ + virtual ::com::sun::star::chart2::InterpretedData SAL_CALL interpretDataSource( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource >& xSource, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments, + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeries > >& aSeriesToReUse ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::chart2::InterpretedData SAL_CALL reinterpretDataSeries( + const ::com::sun::star::chart2::InterpretedData& aInterpretedData ) + throw (::com::sun::star::uno::RuntimeException); + virtual sal_Bool SAL_CALL isDataCompatible( + const ::com::sun::star::chart2::InterpretedData& aInterpretedData ) + throw (::com::sun::star::uno::RuntimeException); +}; + +} // namespace chart + +// CHART_XYDATAINTERPRETER_HXX +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/_serviceregistration_charttypes.cxx b/chart2/source/model/template/_serviceregistration_charttypes.cxx new file mode 100644 index 000000000000..5888be8b42c8 --- /dev/null +++ b/chart2/source/model/template/_serviceregistration_charttypes.cxx @@ -0,0 +1,140 @@ +/* -*- 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 "_serviceregistration_charttypes.hxx" + +#include "AreaChartType.hxx" +#include "BarChartType.hxx" +#include "CandleStickChartType.hxx" +#include "ColumnChartType.hxx" +#include "LineChartType.hxx" +#include "NetChartType.hxx" +#include "FilledNetChartType.hxx" +#include "PieChartType.hxx" +#include "ScatterChartType.hxx" +#include "BubbleChartType.hxx" + +namespace +{ +static struct ::cppu::ImplementationEntry g_entries_chart2_charttypes[] = +{ + { + ::chart::AreaChartType::create + , ::chart::AreaChartType::getImplementationName_Static + , ::chart::AreaChartType::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::BarChartType::create + , ::chart::BarChartType::getImplementationName_Static + , ::chart::BarChartType::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::CandleStickChartType::create + , ::chart::CandleStickChartType::getImplementationName_Static + , ::chart::CandleStickChartType::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::ColumnChartType::create + , ::chart::ColumnChartType::getImplementationName_Static + , ::chart::ColumnChartType::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::LineChartType::create + , ::chart::LineChartType::getImplementationName_Static + , ::chart::LineChartType::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::NetChartType::create + , ::chart::NetChartType::getImplementationName_Static + , ::chart::NetChartType::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::FilledNetChartType::create + , ::chart::FilledNetChartType::getImplementationName_Static + , ::chart::FilledNetChartType::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::PieChartType::create + , ::chart::PieChartType::getImplementationName_Static + , ::chart::PieChartType::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::ScatterChartType::create + , ::chart::ScatterChartType::getImplementationName_Static + , ::chart::ScatterChartType::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::BubbleChartType::create + , ::chart::BubbleChartType::getImplementationName_Static + , ::chart::BubbleChartType::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ 0, 0, 0, 0, 0, 0 } +}; + +} // anonymous namespace + +struct ::cppu::ImplementationEntry * + ChartTypeEntriesForServiceRegistration::getImplementationEntries() +{ + return g_entries_chart2_charttypes; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/model/template/makefile.mk b/chart2/source/model/template/makefile.mk new file mode 100644 index 000000000000..5599aed50256 --- /dev/null +++ b/chart2/source/model/template/makefile.mk @@ -0,0 +1,82 @@ +#************************************************************************* +# +# 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. +# +#************************************************************************* + +PRJ= ..$/..$/.. +PRJNAME= chart2 +TARGET= chmodeltemplate + +PRJINC= $(PRJ)$/source + +ENABLE_EXCEPTIONS= TRUE +VISIBILITY_HIDDEN=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE: settings.mk + +# i26518 the gcc-3.0.4 requires to enhance the template-depth +# this seems to be a compiler issue, so we recommend not to use 3.0.x anymore +.IF "$(COM)"=="GCC" + CFLAGS+=-ftemplate-depth-128 +.ENDIF + +# --- export library ------------------------------------------------- + +#Specifies object files to bind into linked libraries. +SLOFILES= \ + $(SLO)$/AreaChartType.obj \ + $(SLO)$/AreaChartTypeTemplate.obj \ + $(SLO)$/BarChartType.obj \ + $(SLO)$/BarChartTypeTemplate.obj \ + $(SLO)$/CandleStickChartType.obj \ + $(SLO)$/ChartType.obj \ + $(SLO)$/ChartTypeManager.obj \ + $(SLO)$/ChartTypeTemplate.obj \ + $(SLO)$/ColumnChartType.obj \ + $(SLO)$/ColumnLineChartTypeTemplate.obj \ + $(SLO)$/DataInterpreter.obj \ + $(SLO)$/FilledNetChartType.obj \ + $(SLO)$/LineChartType.obj \ + $(SLO)$/LineChartTypeTemplate.obj \ + $(SLO)$/NetChartType.obj \ + $(SLO)$/NetChartTypeTemplate.obj \ + $(SLO)$/PieChartType.obj \ + $(SLO)$/PieChartTypeTemplate.obj \ + $(SLO)$/ScatterChartType.obj \ + $(SLO)$/ScatterChartTypeTemplate.obj \ + $(SLO)$/BubbleChartType.obj \ + $(SLO)$/BubbleChartTypeTemplate.obj \ + $(SLO)$/BubbleDataInterpreter.obj \ + $(SLO)$/StockChartTypeTemplate.obj \ + $(SLO)$/StockDataInterpreter.obj \ + $(SLO)$/XYDataInterpreter.obj \ + $(SLO)$/ColumnLineDataInterpreter.obj \ + $(SLO)$/_serviceregistration_charttypes.obj + +# --- Targets ----------------------------------------------------------------- + +.INCLUDE: target.mk |