diff options
Diffstat (limited to 'chart2/source/model')
102 files changed, 24817 insertions, 0 deletions
diff --git a/chart2/source/model/chartmodel.component b/chart2/source/model/chartmodel.component new file mode 100644 index 000000000000..fa26e51ac401 --- /dev/null +++ b/chart2/source/model/chartmodel.component @@ -0,0 +1,150 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!--********************************************************************** +* +* 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. +* +**********************************************************************--> + +<component loader="com.sun.star.loader.SharedLibrary" + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.chart.AreaChartType"> + <service name="com.sun.star.chart2.AreaChartType"/> + <service name="com.sun.star.chart2.ChartType"/> + </implementation> + <implementation name="com.sun.star.comp.chart.BarChartType"> + <service name="com.sun.star.chart2.BarChartType"/> + <service name="com.sun.star.chart2.ChartType"/> + </implementation> + <implementation name="com.sun.star.comp.chart.BubbleChartType"> + <service name="com.sun.star.beans.PropertySet"/> + <service name="com.sun.star.chart2.BubbleChartType"/> + <service name="com.sun.star.chart2.ChartType"/> + </implementation> + <implementation name="com.sun.star.comp.chart.CandleStickChartType"> + <service name="com.sun.star.beans.PropertySet"/> + <service name="com.sun.star.chart2.CandleStickChartType"/> + <service name="com.sun.star.chart2.ChartType"/> + </implementation> + <implementation name="com.sun.star.comp.chart.ChartTypeManager"> + <service name="com.sun.star.chart2.ChartTypeManager"/> + </implementation> + <implementation name="com.sun.star.comp.chart.ColumnChartType"> + <service name="com.sun.star.chart2.ChartType"/> + <service name="com.sun.star.chart2.ColumnChartType"/> + </implementation> + <implementation name="com.sun.star.comp.chart.DataSeries"> + <service name="com.sun.star.beans.PropertySet"/> + <service name="com.sun.star.chart2.DataPointProperties"/> + <service name="com.sun.star.chart2.DataSeries"/> + </implementation> + <implementation name="com.sun.star.comp.chart.FilledNetChartType"> + <service name="com.sun.star.beans.PropertySet"/> + <service name="com.sun.star.chart2.ChartType"/> + <service name="com.sun.star.chart2.FilledNetChartType"/> + </implementation> + <implementation name="com.sun.star.comp.chart.FormattedString"> + <service name="com.sun.star.beans.PropertySet"/> + <service name="com.sun.star.chart2.FormattedString"/> + </implementation> + <implementation name="com.sun.star.comp.chart.LineChartType"> + <service name="com.sun.star.beans.PropertySet"/> + <service name="com.sun.star.chart2.ChartType"/> + <service name="com.sun.star.chart2.LineChartType"/> + </implementation> + <implementation name="com.sun.star.comp.chart.NetChartType"> + <service name="com.sun.star.beans.PropertySet"/> + <service name="com.sun.star.chart2.ChartType"/> + <service name="com.sun.star.chart2.NetChartType"/> + </implementation> + <implementation name="com.sun.star.comp.chart.PieChartType"> + <service name="com.sun.star.beans.PropertySet"/> + <service name="com.sun.star.chart2.ChartType"/> + <service name="com.sun.star.chart2.PieChartType"/> + </implementation> + <implementation name="com.sun.star.comp.chart.ScatterChartType"> + <service name="com.sun.star.beans.PropertySet"/> + <service name="com.sun.star.chart2.ChartType"/> + <service name="com.sun.star.chart2.ScatterChartType"/> + </implementation> + <implementation name="com.sun.star.comp.chart2.Axis"> + <service name="com.sun.star.beans.PropertySet"/> + <service name="com.sun.star.chart2.Axis"/> + </implementation> + <implementation name="com.sun.star.comp.chart2.CartesianCoordinateSystem2d"> + <service name="com.sun.star.chart2.CartesianCoordinateSystem2d"/> + <service name="com.sun.star.chart2.CoordinateSystems.Cartesian"/> + </implementation> + <implementation name="com.sun.star.comp.chart2.CartesianCoordinateSystem3d"> + <service name="com.sun.star.chart2.CartesianCoordinateSystem3d"/> + <service name="com.sun.star.chart2.CoordinateSystems.Cartesian"/> + </implementation> + <implementation name="com.sun.star.comp.chart2.ChartModel"> + <service name="com.sun.star.chart.ChartDocument"/> + <service name="com.sun.star.chart2.ChartDocument"/> + <service name="com.sun.star.document.OfficeDocument"/> + </implementation> + <implementation name="com.sun.star.comp.chart2.Diagram"> + <service name="com.sun.star.beans.PropertySet"/> + <service name="com.sun.star.chart2.Diagram"/> + <service name="com.sun.star.layout.LayoutElement"/> + </implementation> + <implementation name="com.sun.star.comp.chart2.GridProperties"> + <service name="com.sun.star.beans.PropertySet"/> + <service name="com.sun.star.chart2.GridProperties"/> + </implementation> + <implementation name="com.sun.star.comp.chart2.Legend"> + <service name="com.sun.star.beans.PropertySet"/> + <service name="com.sun.star.chart2.Legend"/> + <service name="com.sun.star.drawing.FillProperties"/> + <service name="com.sun.star.drawing.LineProperties"/> + <service name="com.sun.star.layout.LayoutElement"/> + <service name="com.sun.star.style.CharacterProperties"/> + </implementation> + <implementation name="com.sun.star.comp.chart2.PageBackground"> + <service name="com.sun.star.beans.PropertySet"/> + <service name="com.sun.star.chart2.PageBackground"/> + </implementation> + <implementation name="com.sun.star.comp.chart2.PolarCoordinateSystem2d"> + <service name="com.sun.star.chart2.CoordinateSystems.Polar"/> + <service name="com.sun.star.chart2.PolarCoordinateSystem2d"/> + </implementation> + <implementation name="com.sun.star.comp.chart2.PolarCoordinateSystem3d"> + <service name="com.sun.star.chart2.CoordinateSystems.Polar"/> + <service name="com.sun.star.chart2.PolarCoordinateSystem3d"/> + </implementation> + <implementation name="com.sun.star.comp.chart2.Title"> + <service name="com.sun.star.beans.PropertySet"/> + <service name="com.sun.star.chart2.Title"/> + <service name="com.sun.star.layout.LayoutElement"/> + <service name="com.sun.star.style.ParagraphProperties"/> + </implementation> + <implementation name="com.sun.star.comp.chart2.XMLFilter"> + <service name="com.sun.star.document.ExportFilter"/> + <service name="com.sun.star.document.ImportFilter"/> + </implementation> + <implementation name="com.sun.star.comp.chart2.report.XMLFilter"> + <service name="com.sun.star.document.ExportFilter"/> + <service name="com.sun.star.document.ImportFilter"/> + </implementation> +</component> diff --git a/chart2/source/model/filter/XMLFilter.cxx b/chart2/source/model/filter/XMLFilter.cxx new file mode 100644 index 000000000000..b66c4bc46102 --- /dev/null +++ b/chart2/source/model/filter/XMLFilter.cxx @@ -0,0 +1,873 @@ +/************************************************************************* + * + * 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 "XMLFilter.hxx" +#include "macros.hxx" +#include "MediaDescriptorHelper.hxx" +#include "ContainerHelper.hxx" +#include <comphelper/mediadescriptor.hxx> + +// for ERRCODE_SFX_GENERAL etc. +// header contains only macros +#include <svtools/sfxecode.hxx> +// header for class SvtSaveOptions +#include <unotools/saveopt.hxx> +#include <comphelper/genericpropertyset.hxx> +// header for struct PropertyMapEntry +#include <comphelper/propertysetinfo.hxx> +#include <comphelper/documentconstants.hxx> + +// header for class SotStorage +#include <sot/storage.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/xml/sax/InputSource.hpp> +#include <com/sun/star/lang/XMultiComponentFactory.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/embed/XTransactedObject.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/xml/sax/XDocumentHandler.hpp> +#include <com/sun/star/xml/sax/XParser.hpp> +#include <com/sun/star/xml/sax/SAXParseException.hpp> +#include <com/sun/star/packages/zip/ZipIOException.hpp> +#include <com/sun/star/document/XGraphicObjectResolver.hpp> +#include <com/sun/star/container/XNameAccess.hpp> + +using namespace ::com::sun::star; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; +using ::osl::MutexGuard; + +// ---------------------------------------- +namespace +{ +#define LOCAL_CONST_STR(i, x) sal_Char __READONLY_DATA i[sizeof(x)] = x +#define MAP_LEN(x) x, sizeof(x) - 1 + +LOCAL_CONST_STR( sXML_metaStreamName, "meta.xml"); +LOCAL_CONST_STR( sXML_styleStreamName, "styles.xml" ); +LOCAL_CONST_STR( sXML_contentStreamName, "content.xml" ); +LOCAL_CONST_STR( sXML_oldContentStreamName, "Content.xml" ); + +// soffice 6/7 +// LOCAL_CONST_STR( sXML_export_chart_meta_service, "com.sun.star.comp.Chart.XMLMetaExporter" ); +LOCAL_CONST_STR( sXML_export_chart_styles_service, "com.sun.star.comp.Chart.XMLStylesExporter" ); +LOCAL_CONST_STR( sXML_export_chart_content_service, "com.sun.star.comp.Chart.XMLContentExporter" ); + +// LOCAL_CONST_STR( sXML_import_chart_meta_service, "com.sun.star.comp.Chart.XMLMetaImporter" ); +LOCAL_CONST_STR( sXML_import_chart_styles_service, "com.sun.star.comp.Chart.XMLStylesImporter" ); +LOCAL_CONST_STR( sXML_import_chart_content_service, "com.sun.star.comp.Chart.XMLContentImporter" ); +LOCAL_CONST_STR( sXML_import_chart_old_content_service, "com.sun.star.office.sax.importer.Chart" ); + +// Oasis +LOCAL_CONST_STR( sXML_export_chart_oasis_styles_service, "com.sun.star.comp.Chart.XMLOasisStylesExporter" ); +LOCAL_CONST_STR( sXML_export_chart_oasis_content_service, "com.sun.star.comp.Chart.XMLOasisContentExporter" ); +LOCAL_CONST_STR( sXML_export_chart_oasis_meta_service, "com.sun.star.comp.Chart.XMLOasisMetaExporter" ); + +LOCAL_CONST_STR( sXML_import_chart_oasis_styles_service, "com.sun.star.comp.Chart.XMLOasisStylesImporter" ); +LOCAL_CONST_STR( sXML_import_chart_oasis_content_service, "com.sun.star.comp.Chart.XMLOasisContentImporter" ); +LOCAL_CONST_STR( sXML_import_chart_oasis_meta_service, "com.sun.star.comp.Chart.XMLOasisMetaImporter" ); + +uno::Reference< embed::XStorage > lcl_getWriteStorage( + const Sequence< beans::PropertyValue >& rMediaDescriptor, + const uno::Reference< uno::XComponentContext >& xContext,const ::rtl::OUString& _sMediaType) +{ + uno::Reference< embed::XStorage > xStorage; + try + { + apphelper::MediaDescriptorHelper aMDHelper( rMediaDescriptor ); + if( aMDHelper.ISSET_Storage ) + { + xStorage = aMDHelper.Storage; + } + else + { + Reference< lang::XSingleServiceFactory > xStorageFact( + xContext->getServiceManager()->createInstanceWithContext( + C2U("com.sun.star.embed.StorageFactory"), + xContext ), uno::UNO_QUERY_THROW ); + + ::std::vector< beans::PropertyValue > aPropertiesForStorage; + + for( sal_Int32 i=rMediaDescriptor.getLength(); i--; ) + { + // properties understood by storage factory + // (see package/source/xstor/xfactory.cxx for details) + if ( rMediaDescriptor[i].Name.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM( "InteractionHandler" )) + || rMediaDescriptor[i].Name.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM( "Password" )) + || rMediaDescriptor[i].Name.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM( "RepairPackage" )) + // || rMediaDescriptor[i].Name.equalsAsciiL( + // RTL_CONSTASCII_STRINGPARAM( "StatusIndicator" )) + // || rMediaDescriptor[i].Name.equalsAsciiL( + // RTL_CONSTASCII_STRINGPARAM( "Unpacked" )) + ) + { + aPropertiesForStorage.push_back( rMediaDescriptor[i] ); + } + } + + if( aMDHelper.ISSET_Storage ) + xStorage.set( aMDHelper.Storage ); + else + { + Sequence< uno::Any > aStorageArgs( 3 ); + if( aMDHelper.ISSET_OutputStream ) + aStorageArgs[0] <<= aMDHelper.OutputStream; + else + aStorageArgs[0] <<= aMDHelper.URL; + aStorageArgs[1] <<= (embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE); + aStorageArgs[2] <<= ::chart::ContainerHelper::ContainerToSequence( aPropertiesForStorage ); + + xStorage.set( + xStorageFact->createInstanceWithArguments( aStorageArgs ), + uno::UNO_QUERY_THROW ); + } + } + + // set correct media type at storage + uno::Reference<beans::XPropertySet> xProp(xStorage,uno::UNO_QUERY); + OUString aMediaType; + if ( ! xProp.is() || + ! ( xProp->getPropertyValue( C2U("MediaType")) >>= aMediaType ) || + ( aMediaType.getLength() == 0 )) + { + xProp->setPropertyValue( C2U("MediaType"), uno::makeAny( _sMediaType )); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + return xStorage; +} + +uno::Reference< embed::XStorage > lcl_getReadStorage( + const Sequence< beans::PropertyValue >& rMediaDescriptor, + const uno::Reference< uno::XComponentContext >& xContext) +{ + uno::Reference< embed::XStorage > xStorage; + + try + { + apphelper::MediaDescriptorHelper aMDHelper( rMediaDescriptor ); + if( aMDHelper.ISSET_Storage ) + { + xStorage = aMDHelper.Storage; + } + else + { + // get XStream from MediaDescriptor + uno::Reference< io::XInputStream > xStream; + ::std::vector< beans::PropertyValue > aPropertiesForStorage; + for( sal_Int32 i=rMediaDescriptor.getLength(); i--; ) + { + if( rMediaDescriptor[i].Name.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM( "InputStream" ))) + xStream.set( rMediaDescriptor[i].Value, uno::UNO_QUERY ); + + // properties understood by storage factory + // (see package/source/xstor/xfactory.cxx for details) + if ( rMediaDescriptor[i].Name.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM( "InteractionHandler" )) + || rMediaDescriptor[i].Name.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM( "Password" )) + || rMediaDescriptor[i].Name.equalsAsciiL( + RTL_CONSTASCII_STRINGPARAM( "RepairPackage" )) +// || rMediaDescriptor[i].Name.equalsAsciiL( +// RTL_CONSTASCII_STRINGPARAM( "StatusIndicator" )) +// || rMediaDescriptor[i].Name.equalsAsciiL( +// RTL_CONSTASCII_STRINGPARAM( "Unpacked" )) + ) + { + aPropertiesForStorage.push_back( rMediaDescriptor[i] ); + } + } + OSL_ENSURE( xStream.is(), "No Stream" ); + if( ! xStream.is()) + return xStorage; + + // convert XInputStream to XStorage via the storage factory + Reference< lang::XSingleServiceFactory > xStorageFact( + xContext->getServiceManager()->createInstanceWithContext( + C2U("com.sun.star.embed.StorageFactory"), + xContext ), + uno::UNO_QUERY_THROW ); + Sequence< uno::Any > aStorageArgs( 3 ); + aStorageArgs[0] <<= xStream; + aStorageArgs[1] <<= (embed::ElementModes::READ | embed::ElementModes::NOCREATE); + aStorageArgs[2] <<= ::chart::ContainerHelper::ContainerToSequence( aPropertiesForStorage ); + xStorage.set( + xStorageFact->createInstanceWithArguments( aStorageArgs ), uno::UNO_QUERY_THROW ); + } + + OSL_ENSURE( xStorage.is(), "No Storage" ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return xStorage; +} + + +} // anonymous namespace + +// ---------------------------------------- + +namespace chart +{ + +XMLFilter::XMLFilter( Reference< uno::XComponentContext > const & xContext ) : + m_xContext( xContext ), + m_bCancelOperation( false ) +{} + +XMLFilter::~XMLFilter() +{} + +// ____ XFilter ____ +sal_Bool SAL_CALL XMLFilter::filter( + const Sequence< beans::PropertyValue >& aDescriptor ) + throw (uno::RuntimeException) +{ + bool bResult = false; + + MutexGuard aGuard( m_aMutex ); + + // ignore cancel flag at start of function + // note: is currently ignored during import/export + if( m_bCancelOperation ) + m_bCancelOperation = false; + + if( m_xSourceDoc.is()) + { + OSL_ENSURE( ! m_xTargetDoc.is(), "source doc is set -> target document should not be set" ); + if( impl_Export( m_xSourceDoc, + aDescriptor ) == 0 ) + { + m_xSourceDoc = NULL; + bResult = true; + } + } + else if( m_xTargetDoc.is()) + { + if( impl_Import( m_xTargetDoc, + aDescriptor ) == 0 ) + { + m_xTargetDoc = NULL; + bResult = true; + } + } + else + { + OSL_ENSURE( false, "filter() called with no document set" ); + } + + return bResult; +} + +void SAL_CALL XMLFilter::cancel() + throw (uno::RuntimeException) +{ + // if mutex is locked set "cancel state" + // note: is currently ignored in filter-method + if( ! m_aMutex.tryToAcquire()) + { + m_bCancelOperation = true; + } +} + +// ____ XImporter ____ +void SAL_CALL XMLFilter::setTargetDocument( + const Reference< lang::XComponent >& Document ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + MutexGuard aGuard( m_aMutex ); + OSL_ENSURE( ! m_xSourceDoc.is(), "Setting target doc while source doc is set" ); + + m_xTargetDoc = Document; +} + + +// ____ XExporter ____ +void SAL_CALL XMLFilter::setSourceDocument( + const Reference< lang::XComponent >& Document ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + MutexGuard aGuard( m_aMutex ); + OSL_ENSURE( ! m_xTargetDoc.is(), "Setting source doc while target doc is set" ); + + m_xSourceDoc = Document; +} + + +sal_Int32 XMLFilter::impl_Import( + const Reference< lang::XComponent > & xDocumentComp, + const Sequence< beans::PropertyValue > & rMediaDescriptor ) +{ + sal_Int32 nWarning = 0; + + OSL_ENSURE( xDocumentComp.is(), "Import: No Model" ); + OSL_ENSURE( m_xContext.is(), "Import: No ComponentContext" ); + + if( ! (xDocumentComp.is() && + m_xContext.is())) + return nWarning; + + try + { + Reference< lang::XServiceInfo > xServInfo( xDocumentComp, uno::UNO_QUERY_THROW ); + if( ! xServInfo->supportsService( C2U( "com.sun.star.chart2.ChartDocument" ))) + { + OSL_ENSURE( false, "Import: No ChartDocument" ); + return ERRCODE_SFX_GENERAL; + } + + Reference< lang::XMultiComponentFactory > xFactory( m_xContext->getServiceManager()); + OSL_ENSURE( xFactory.is(), "Import: No Factory" ); + if( ! xFactory.is()) + return ERRCODE_SFX_GENERAL; + + // create a sax parser + Reference< xml::sax::XParser > xSaxParser( + xFactory->createInstanceWithContext( C2U( "com.sun.star.xml.sax.Parser" ), m_xContext ), + uno::UNO_QUERY_THROW ); + + bool bOasis = true; + isOasisFormat( rMediaDescriptor, bOasis ); + Reference< embed::XStorage > xStorage( lcl_getReadStorage( rMediaDescriptor, m_xContext)); + if( ! xStorage.is()) + return ERRCODE_SFX_GENERAL; + +// bool bOasis = (SotStorage::GetVersion( xStorage ) > SOFFICE_FILEFORMAT_60); + + Reference< document::XGraphicObjectResolver > xGraphicObjectResolver; + uno::Reference< lang::XMultiServiceFactory > xServiceFactory( xFactory, uno::UNO_QUERY); + if( xServiceFactory.is()) + { + uno::Sequence< uno::Any > aArgs(1); + aArgs[0] <<= xStorage; + xGraphicObjectResolver.set( + xServiceFactory->createInstanceWithArguments( + C2U("com.sun.star.comp.Svx.GraphicImportHelper"), aArgs ), uno::UNO_QUERY ); + } + + // create XPropertySet with extra informatio for the filter + /** property map for import info set */ + comphelper::PropertyMapEntry aImportInfoMap[] = + { + // #80365# necessary properties for XML progress bar at load time + { MAP_LEN( "ProgressRange" ), 0, &::getCppuType((const sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0}, + { MAP_LEN( "ProgressMax" ), 0, &::getCppuType((const sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0}, + { MAP_LEN( "ProgressCurrent" ), 0, &::getCppuType((const sal_Int32*)0), ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0}, + { MAP_LEN( "PrivateData" ), 0, + &::getCppuType( (Reference<XInterface> *)0 ), + ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 }, + { MAP_LEN( "BaseURI" ), 0, + &::getCppuType( (OUString *)0 ), + ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 }, + { MAP_LEN( "StreamRelPath" ), 0, + &::getCppuType( (OUString *)0 ), + ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 }, + { MAP_LEN( "StreamName" ), 0, + &::getCppuType( (OUString *)0 ), + ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 }, + { MAP_LEN( "BuildId" ), 0, + &::getCppuType( (OUString *)0 ), + ::com::sun::star::beans::PropertyAttribute::MAYBEVOID, 0 }, + { NULL, 0, 0, NULL, 0, 0 } + }; + uno::Reference< beans::XPropertySet > xImportInfo( + comphelper::GenericPropertySet_CreateInstance( + new comphelper::PropertySetInfo( aImportInfoMap ) ) ); + + // Set base URI and Hierarchical Name + OUString aHierarchName, aBaseUri; + uno::Reference< frame::XModel > xModel( m_xSourceDoc, uno::UNO_QUERY ); + if( xModel.is() ) + { + uno::Sequence< beans::PropertyValue > aModProps = xModel->getArgs(); + for( sal_Int32 nInd = 0; nInd < aModProps.getLength(); nInd++ ) + { + if( aModProps[nInd].Name.equals( C2U( "HierarchicalDocumentName" ) ) ) + { + // Actually this argument only has meaning for embedded documents + aModProps[nInd].Value >>= aHierarchName; + } + else if( aModProps[nInd].Name.equals( C2U( "DocumentBaseURL" ) ) ) + { + aModProps[nInd].Value >>= aBaseUri; + } + } + } + + if( aBaseUri.getLength() ) + xImportInfo->setPropertyValue( C2U("BaseURI"), uno::makeAny( aBaseUri ) ); + + if( aHierarchName.getLength() ) + xImportInfo->setPropertyValue( C2U("StreamRelPath"), uno::makeAny( aHierarchName ) ); + + // import meta information + if( bOasis ) + nWarning |= impl_ImportStream( + C2U( sXML_metaStreamName ), + C2U( sXML_import_chart_oasis_meta_service ), + xStorage, xSaxParser, xFactory, xGraphicObjectResolver, xImportInfo ); + + // import styles + nWarning |= impl_ImportStream( + C2U( sXML_styleStreamName ), + bOasis + ? C2U( sXML_import_chart_oasis_styles_service ) + : C2U( sXML_import_chart_styles_service ), + xStorage, xSaxParser, xFactory, xGraphicObjectResolver, xImportInfo ); + + // import content + sal_Int32 nContentWarning = impl_ImportStream( + C2U( sXML_contentStreamName ), + bOasis + ? C2U( sXML_import_chart_oasis_content_service ) + : C2U( sXML_import_chart_content_service ), + xStorage, xSaxParser, xFactory, xGraphicObjectResolver, xImportInfo ); + nWarning |= nContentWarning; + + // import of "content.xml" didn't work - try old "Content.xml" stream + if( nContentWarning != 0 ) + { + nWarning = impl_ImportStream( + C2U( sXML_oldContentStreamName ), + C2U( sXML_import_chart_old_content_service ), + xStorage, xSaxParser, xFactory, xGraphicObjectResolver, xImportInfo ); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + + // something went awry + nWarning = ERRCODE_SFX_GENERAL; + } + + return nWarning; +} + +sal_Int32 XMLFilter::impl_ImportStream( + const OUString & rStreamName, + const OUString & rServiceName, + const Reference< embed::XStorage > & xStorage, + const Reference< xml::sax::XParser > & xParser, + const Reference< lang::XMultiComponentFactory > & xFactory, + const Reference< document::XGraphicObjectResolver > & xGraphicObjectResolver, + uno::Reference< beans::XPropertySet >& xImportInfo ) +{ + sal_Int32 nWarning = ERRCODE_SFX_GENERAL; + + Reference< container::XNameAccess > xNameAcc( xStorage, uno::UNO_QUERY ); + if( ! (xNameAcc.is() && + xNameAcc->hasByName( rStreamName ))) + return 0; + + if( xImportInfo.is() ) + xImportInfo->setPropertyValue( C2U("StreamName"), uno::makeAny( rStreamName ) ); + + if( xStorage.is() && + xStorage->isStreamElement( rStreamName ) ) + { + try + { + xml::sax::InputSource aParserInput; + aParserInput.aInputStream.set( + xStorage->openStreamElement( + rStreamName, + embed::ElementModes::READ | embed::ElementModes::NOCREATE ), + uno::UNO_QUERY ); + + // todo: encryption + + if( aParserInput.aInputStream.is()) + { + sal_Int32 nArgs = 0; + //if( m_xStatusIndicator.is()) + // nArgs++; + if( xGraphicObjectResolver.is()) + nArgs++; + if( xImportInfo.is()) + nArgs++; + + uno::Sequence< uno::Any > aFilterCompArgs( nArgs ); + + nArgs = 0; + //if( m_xStatusIndicator.is()) + // aFilterCompArgs[ nArgs++ ] <<= m_xStatusIndicator; + if( xGraphicObjectResolver.is()) + aFilterCompArgs[nArgs++] <<= xGraphicObjectResolver; + if( xImportInfo.is()) + aFilterCompArgs[ nArgs++ ] <<= xImportInfo; + + Reference< xml::sax::XDocumentHandler > xDocHandler( + xFactory->createInstanceWithArgumentsAndContext( rServiceName, aFilterCompArgs, m_xContext ), + uno::UNO_QUERY_THROW ); + + + Reference< document::XImporter > xImporter( xDocHandler, uno::UNO_QUERY_THROW ); + xImporter->setTargetDocument( Reference< lang::XComponent >( m_xTargetDoc, uno::UNO_QUERY_THROW )); + + if ( m_sDocumentHandler.getLength() ) + { + try + { + uno::Sequence< uno::Any > aArgs(2); + beans::NamedValue aValue; + aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DocumentHandler")); + aValue.Value <<= xDocHandler; + aArgs[0] <<= aValue; + aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Model")); + aValue.Value <<= m_xTargetDoc; + aArgs[1] <<= aValue; + + xDocHandler.set(xFactory->createInstanceWithArgumentsAndContext(m_sDocumentHandler,aArgs,m_xContext), uno::UNO_QUERY ); + xImporter.set(xDocHandler,uno::UNO_QUERY); + } + catch(uno::Exception&) + { + OSL_ENSURE(0,"Exception caught!"); + } + } + xParser->setDocumentHandler( xDocHandler ); + xParser->parseStream( aParserInput ); + } + + // load was successful + nWarning = 0; + } + catch( xml::sax::SAXParseException ) + { + // todo: if encrypted: ERRCODE_SFX_WRONGPASSWORD + } + catch( xml::sax::SAXException ) + { + // todo: if encrypted: ERRCODE_SFX_WRONGPASSWORD + } + catch( packages::zip::ZipIOException ) + { + nWarning = ERRCODE_IO_BROKENPACKAGE; + } + catch( io::IOException ) + { + } + catch( uno::Exception& aEx ) + { + ASSERT_EXCEPTION( aEx ); + } + } + + return nWarning; +} + +sal_Int32 XMLFilter::impl_Export( + const Reference< lang::XComponent > & xDocumentComp, + const Sequence< beans::PropertyValue > & rMediaDescriptor ) +{ + //save + + sal_Int32 nWarning = 0; + + OSL_ENSURE( xDocumentComp.is(), "Export: No Model" ); + OSL_ENSURE( m_xContext.is(), "Export: No ComponentContext" ); + + if( !xDocumentComp.is() || !m_xContext.is() ) + return nWarning; + + try + { + Reference< lang::XServiceInfo > xServInfo( xDocumentComp, uno::UNO_QUERY_THROW ); + if( ! xServInfo->supportsService( C2U( "com.sun.star.chart2.ChartDocument" ))) + { + OSL_ENSURE( false, "Export: No ChartDocument" ); + return ERRCODE_SFX_GENERAL; + } + + Reference< lang::XMultiComponentFactory > xFactory( m_xContext->getServiceManager()); + OSL_ENSURE( xFactory.is(), "Export: No Factory" ); + if( ! xFactory.is()) + return ERRCODE_SFX_GENERAL; + uno::Reference< lang::XMultiServiceFactory > xServiceFactory( m_xContext->getServiceManager(), uno::UNO_QUERY); + if( ! xServiceFactory.is()) + return ERRCODE_SFX_GENERAL; + + uno::Reference< io::XActiveDataSource > xSaxWriter( xServiceFactory->createInstance( + C2U("com.sun.star.xml.sax.Writer")), uno::UNO_QUERY ); + if ( !xSaxWriter.is() ) + return ERRCODE_SFX_GENERAL; + + bool bOasis = true; + isOasisFormat( rMediaDescriptor, bOasis ); + + uno::Reference< embed::XStorage > xStorage( lcl_getWriteStorage( rMediaDescriptor, m_xContext, getMediaType(bOasis) ) ); + OSL_ENSURE( xStorage.is(), "No Storage" ); + if( ! xStorage.is()) + return ERRCODE_SFX_GENERAL; + + uno::Reference< xml::sax::XDocumentHandler> xDocHandler( xSaxWriter, uno::UNO_QUERY ); + + if ( m_sDocumentHandler.getLength() ) + { + try + { + uno::Sequence< uno::Any > aArgs(2); + beans::NamedValue aValue; + aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DocumentHandler")); + aValue.Value <<= xDocHandler; + aArgs[0] <<= aValue; + aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Model")); + aValue.Value <<= xDocumentComp; + aArgs[1] <<= aValue; + + xDocHandler.set(xServiceFactory->createInstanceWithArguments(m_sDocumentHandler,aArgs), uno::UNO_QUERY ); + xSaxWriter.set(xDocHandler,uno::UNO_QUERY); + } + catch(uno::Exception&) + { + OSL_ENSURE(0,"Exception caught!"); + } + } + + uno::Sequence< uno::Any > aGraphicResolverArgs(1); + aGraphicResolverArgs[0] <<= xStorage; + Reference< document::XGraphicObjectResolver > xGraphicObjectResolver( + xServiceFactory->createInstanceWithArguments( + C2U("com.sun.star.comp.Svx.GraphicExportHelper"), aGraphicResolverArgs ), uno::UNO_QUERY ); + + uno::Reference< beans::XPropertySet > xInfoSet; + { + // property map for export info set + comphelper::PropertyMapEntry aExportInfoMap[] = + { + { MAP_LEN("UsePrettyPrinting"), 0, &::getBooleanCppuType(), beans::PropertyAttribute::MAYBEVOID, 0}, + { MAP_LEN("BaseURI"), 0, &::getCppuType( (OUString *)0 ), beans::PropertyAttribute::MAYBEVOID, 0 }, + { MAP_LEN("StreamRelPath"), 0, &::getCppuType( (OUString *)0 ), beans::PropertyAttribute::MAYBEVOID, 0 }, + { MAP_LEN("StreamName"), 0, &::getCppuType( (OUString *)0 ), beans::PropertyAttribute::MAYBEVOID, 0 }, + { MAP_LEN("ExportTableNumberList"), 0, &::getBooleanCppuType(), beans::PropertyAttribute::MAYBEVOID, 0 }, + { NULL, 0, 0, NULL, 0, 0 } + }; + + xInfoSet = comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aExportInfoMap ) ); + + SvtSaveOptions aSaveOpt; + OUString sUsePrettyPrinting(RTL_CONSTASCII_USTRINGPARAM("UsePrettyPrinting")); + sal_Bool bUsePrettyPrinting( aSaveOpt.IsPrettyPrinting() ); + xInfoSet->setPropertyValue( sUsePrettyPrinting, uno::makeAny( bUsePrettyPrinting ) ); + if( ! bOasis ) + xInfoSet->setPropertyValue( C2U("ExportTableNumberList"), uno::makeAny( true )); + } + + sal_Int32 nArgs = 2; + if( xGraphicObjectResolver.is()) + nArgs++; + + uno::Sequence< uno::Any > aFilterProperties( nArgs ); + { + nArgs = 0; + aFilterProperties[ nArgs++ ] <<= xInfoSet; + aFilterProperties[ nArgs++ ] <<= xDocHandler; + if( xGraphicObjectResolver.is()) + aFilterProperties[ nArgs++ ] <<= xGraphicObjectResolver; + } + +// bool bOasis = (SotStorage::GetVersion( xStorage ) > SOFFICE_FILEFORMAT_60); + + // export meta information + if( bOasis ) + nWarning |= impl_ExportStream( + C2U( sXML_metaStreamName ), + C2U( sXML_export_chart_oasis_meta_service ), + xStorage, xSaxWriter, xServiceFactory, aFilterProperties ); + + // export styles + nWarning |= impl_ExportStream( + C2U( sXML_styleStreamName ), + bOasis + ? C2U( sXML_export_chart_oasis_styles_service ) + : C2U( sXML_export_chart_styles_service ), + xStorage, xSaxWriter, xServiceFactory, aFilterProperties ); + + // export content + sal_Int32 nContentWarning = impl_ExportStream( + C2U( sXML_contentStreamName ), + bOasis + ? C2U( sXML_export_chart_oasis_content_service ) + : C2U( sXML_export_chart_content_service ), + xStorage, xSaxWriter, xServiceFactory, aFilterProperties ); + nWarning |= nContentWarning; + + Reference< lang::XComponent > xComp( xGraphicObjectResolver, uno::UNO_QUERY ); + if( xComp.is()) + xComp->dispose(); + + uno::Reference<embed::XTransactedObject> xTransact( xStorage ,uno::UNO_QUERY); + if ( xTransact.is() ) + xTransact->commit(); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + + // something went awry + nWarning = ERRCODE_SFX_GENERAL; + } + + return nWarning; +} + +sal_Int32 XMLFilter::impl_ExportStream( + const OUString & rStreamName, + const OUString & rServiceName, + const Reference< embed::XStorage > & xStorage, + const uno::Reference< io::XActiveDataSource >& xActiveDataSource, + const Reference< lang::XMultiServiceFactory >& xServiceFactory, + const Sequence< uno::Any > & rFilterProperties ) +{ + sal_Int32 nWarning = 0; + + try + { + if( !xServiceFactory.is() ) + return ERRCODE_SFX_GENERAL; + if( !xStorage.is() ) + return ERRCODE_SFX_GENERAL; + if ( !xActiveDataSource.is() ) + return ERRCODE_SFX_GENERAL; + + uno::Reference< io::XStream > xStream( xStorage->openStreamElement( + rStreamName, embed::ElementModes::READWRITE | embed::ElementModes::TRUNCATE ) ); + if ( !xStream.is() ) + return ERRCODE_SFX_GENERAL; + uno::Reference< io::XOutputStream > xOutputStream( xStream->getOutputStream() ); + if ( !xOutputStream.is() ) + return ERRCODE_SFX_GENERAL; + + uno::Reference< beans::XPropertySet > xStreamProp( xOutputStream, uno::UNO_QUERY ); + if(xStreamProp.is()) try + { + xStreamProp->setPropertyValue( C2U("MediaType"), uno::makeAny( C2U("text/xml") ) ); + xStreamProp->setPropertyValue( C2U("Compressed"), uno::makeAny( sal_True ) );//@todo? + xStreamProp->setPropertyValue( C2U("UseCommonStoragePasswordEncryption"), uno::makeAny( sal_True ) ); + } + catch( uno::Exception& rEx ) + { + ASSERT_EXCEPTION( rEx ); + } + + xActiveDataSource->setOutputStream(xOutputStream); + + // set Base URL + { + uno::Reference< beans::XPropertySet > xInfoSet; + if( rFilterProperties.getLength() > 0 ) + rFilterProperties.getConstArray()[0] >>= xInfoSet; + OSL_ENSURE( xInfoSet.is(), "missing infoset for export" ); + if( xInfoSet.is() ) + xInfoSet->setPropertyValue( C2U("StreamName"), uno::makeAny( rStreamName ) ); + } + + Reference< XExporter > xExporter( xServiceFactory->createInstanceWithArguments( + rServiceName, rFilterProperties ), uno::UNO_QUERY); + if ( !xExporter.is() ) + return ERRCODE_SFX_GENERAL; + + xExporter->setSourceDocument( m_xSourceDoc ); + + uno::Reference< document::XFilter > xFilter( xExporter, uno::UNO_QUERY ); + if ( !xFilter.is() ) + return ERRCODE_SFX_GENERAL; + + uno::Sequence < beans::PropertyValue > aMediaDesc(0); + //@todo? filter properties? ... url? ... + xFilter->filter( aMediaDesc ); + } + catch( uno::Exception& rEx ) + { + ASSERT_EXCEPTION( rEx ); + } + return nWarning; +} + +// -------------------------------------------------------------------------------- + +Sequence< OUString > XMLFilter::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 2 ); + aServices[ 0 ] = C2U( "com.sun.star.document.ImportFilter" ); + aServices[ 1 ] = C2U( "com.sun.star.document.ExportFilter" ); + + // todo: services are incomplete. Missing: + // XInitialization, XNamed + return aServices; +} +// ----------------------------------------------------------------------------- + +void XMLFilter::isOasisFormat(const Sequence< beans::PropertyValue >& _rMediaDescriptor, bool & rOutOASIS ) +{ + apphelper::MediaDescriptorHelper aMDHelper( _rMediaDescriptor ); + if( aMDHelper.ISSET_FilterName ) + rOutOASIS = aMDHelper.FilterName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("chart8")); +} +// ----------------------------------------------------------------------------- +::rtl::OUString XMLFilter::getMediaType(bool _bOasis) +{ + return _bOasis ? MIMETYPE_OASIS_OPENDOCUMENT_CHART : MIMETYPE_VND_SUN_XML_CHART; +} +// ----------------------------------------------------------------------------- + +APPHELPER_XSERVICEINFO_IMPL( XMLFilter, C2U( "com.sun.star.comp.chart2.XMLFilter" ) ); +// ----------------------------------------------------------------------------- + +void XMLReportFilterHelper::isOasisFormat(const Sequence< beans::PropertyValue >& _rMediaDescriptor, bool & rOutOASIS ) +{ + apphelper::MediaDescriptorHelper aMDHelper( _rMediaDescriptor ); + if( aMDHelper.ISSET_FilterName ) + rOutOASIS = aMDHelper.FilterName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("StarOffice XML (Base) Report Chart")); +} +// ----------------------------------------------------------------------------- +::rtl::OUString XMLReportFilterHelper::getMediaType(bool ) +{ + return MIMETYPE_OASIS_OPENDOCUMENT_REPORT_CHART; +} + +} // namespace chart diff --git a/chart2/source/model/filter/makefile.mk b/chart2/source/model/filter/makefile.mk new file mode 100644 index 000000000000..fc9f7ebb9973 --- /dev/null +++ b/chart2/source/model/filter/makefile.mk @@ -0,0 +1,49 @@ +#************************************************************************* +# +# 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= chmodelfilter + +PRJINC= $(PRJ)$/source + +ENABLE_EXCEPTIONS= TRUE +VISIBILITY_HIDDEN=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE: settings.mk + +# --- export library ------------------------------------------------- + +#Specifies object files to bind into linked libraries. +SLOFILES= \ + $(SLO)$/XMLFilter.obj + +# --- Targets ----------------------------------------------------------------- + +.INCLUDE: target.mk diff --git a/chart2/source/model/inc/BaseCoordinateSystem.hxx b/chart2/source/model/inc/BaseCoordinateSystem.hxx new file mode 100644 index 000000000000..22346e917453 --- /dev/null +++ b/chart2/source/model/inc/BaseCoordinateSystem.hxx @@ -0,0 +1,190 @@ +/************************************************************************* + * + * 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_COORDINATESYSTEM_HXX +#define CHART_COORDINATESYSTEM_HXX + +#include "ServiceMacros.hxx" +#include "OPropertySet.hxx" +#include "MutexContainer.hxx" +#include <cppuhelper/implbase6.hxx> +#include <comphelper/uno3.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/chart2/XCoordinateSystem.hpp> +#include <com/sun/star/chart2/XChartTypeContainer.hpp> +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/util/XModifyBroadcaster.hpp> +#include <com/sun/star/util/XModifyListener.hpp> + +#include <vector> + +namespace chart +{ + +namespace impl +{ +typedef ::cppu::WeakImplHelper6 + < ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::chart2::XCoordinateSystem, + ::com::sun::star::chart2::XChartTypeContainer, + ::com::sun::star::util::XCloneable, + ::com::sun::star::util::XModifyBroadcaster, + ::com::sun::star::util::XModifyListener > + BaseCoordinateSystem_Base; +} + +class BaseCoordinateSystem : + public impl::BaseCoordinateSystem_Base, + public MutexContainer, + public ::property::OPropertySet +{ +public: + BaseCoordinateSystem( + const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext, + sal_Int32 nDimensionCount = 2, + sal_Bool bSwapXAndYAxis = sal_False ); + explicit BaseCoordinateSystem( const BaseCoordinateSystem & rSource ); + virtual ~BaseCoordinateSystem(); + + // ____ 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); + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + // ____ XCoordinateSystem ____ + virtual ::sal_Int32 SAL_CALL getDimension() + throw (::com::sun::star::uno::RuntimeException); + // not implemented +// virtual ::rtl::OUString SAL_CALL getCoordinateSystemType() +// throw (::com::sun::star::uno::RuntimeException); + // not implemented +// virtual ::rtl::OUString SAL_CALL getViewServiceName() +// throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setAxisByDimension( + ::sal_Int32 nDimension, + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XAxis >& xAxis, + ::sal_Int32 nIndex ) + throw (::com::sun::star::lang::IndexOutOfBoundsException, + ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XAxis > SAL_CALL getAxisByDimension( + ::sal_Int32 nDimension, ::sal_Int32 nIndex ) + throw (::com::sun::star::lang::IndexOutOfBoundsException, + ::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getMaximumAxisIndexByDimension( ::sal_Int32 nDimension ) + throw (::com::sun::star::lang::IndexOutOfBoundsException, + ::com::sun::star::uno::RuntimeException); + + // ____ XChartTypeContainer ____ + virtual void SAL_CALL addChartType( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& aChartType ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeChartType( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType >& aChartType ) + 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::XChartType > > SAL_CALL getChartTypes() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setChartTypes( + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartType > >& aChartTypes ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + + // ____ XCloneable ____ + // not implemented +// virtual ::com::sun::star::uno::Reference< +// ::com::sun::star::util::XCloneable > SAL_CALL createClone() +// throw (::com::sun::star::uno::RuntimeException); + + // ____ XServiceInfo ____ + // not implemented +// virtual ::rtl::OUString SAL_CALL getImplementationName() +// throw (::com::sun::star::uno::RuntimeException); +// virtual ::sal_Bool SAL_CALL supportsService( +// const ::rtl::OUString& ServiceName ) +// throw (::com::sun::star::uno::RuntimeException); +// virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() +// throw (::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); + + // ____ OPropertySet ____ + virtual void firePropertyChangeEvent(); + using OPropertySet::disposing; + + void fireModifyEvent(); + +protected: + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > m_xContext; + + ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xModifyEventForwarder; + +private: + sal_Int32 m_nDimensionCount; + typedef ::std::vector< ::std::vector< ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XAxis > > > tAxisVecVecType; + tAxisVecVecType m_aAllAxis; //outer sequence is the dimension; inner sequence is the axis index that indicates main or secondary axis + ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Any > m_aOrigin; + ::std::vector< ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartType > > m_aChartTypes; +}; + +} // namespace chart + +// CHART_COORDINATESYSTEM_HXX +#endif diff --git a/chart2/source/model/inc/CartesianCoordinateSystem.hxx b/chart2/source/model/inc/CartesianCoordinateSystem.hxx new file mode 100644 index 000000000000..7c9fd075d787 --- /dev/null +++ b/chart2/source/model/inc/CartesianCoordinateSystem.hxx @@ -0,0 +1,93 @@ +/************************************************************************* + * + * 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_CARTESIANCOORDINATESYSTEM_HXX +#define _CHART_CARTESIANCOORDINATESYSTEM_HXX + +#include "ServiceMacros.hxx" +#include "BaseCoordinateSystem.hxx" + +namespace chart +{ + +class CartesianCoordinateSystem : public BaseCoordinateSystem +{ +public: + explicit CartesianCoordinateSystem( + const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext, + sal_Int32 nDimensionCount = 2, + sal_Bool bSwapXAndYAxis = sal_False ); + explicit CartesianCoordinateSystem( const CartesianCoordinateSystem & rSource ); + virtual ~CartesianCoordinateSystem(); + + // ____ XCoordinateSystem ____ + virtual ::rtl::OUString SAL_CALL getCoordinateSystemType() + throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getViewServiceName() + 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); + + // ____ XServiceInfo ____ + APPHELPER_XSERVICEINFO_DECL() +}; + +class CartesianCoordinateSystem2d : public CartesianCoordinateSystem +{ +public: + explicit CartesianCoordinateSystem2d( + const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext ); + virtual ~CartesianCoordinateSystem2d(); + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( CartesianCoordinateSystem2d ) + // ____ XServiceInfo ____ + APPHELPER_XSERVICEINFO_DECL() +}; + +class CartesianCoordinateSystem3d : public CartesianCoordinateSystem +{ +public: + explicit CartesianCoordinateSystem3d( + const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext ); + virtual ~CartesianCoordinateSystem3d(); + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( CartesianCoordinateSystem3d ) + // ____ XServiceInfo ____ + APPHELPER_XSERVICEINFO_DECL() +}; + +} // namespace chart + +// _CHART_CARTESIANCOORDINATESYSTEM_HXX +#endif diff --git a/chart2/source/model/inc/ChartTypeManager.hxx b/chart2/source/model/inc/ChartTypeManager.hxx new file mode 100644 index 000000000000..de721be48142 --- /dev/null +++ b/chart2/source/model/inc/ChartTypeManager.hxx @@ -0,0 +1,92 @@ +/************************************************************************* + * + * 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_CHARTTYPEMANAGER_HXX +#define CHART_CHARTTYPEMANAGER_HXX + +#include "OPropertySet.hxx" +#include "MutexContainer.hxx" +#include <cppuhelper/implbase2.hxx> +#include <comphelper/uno3.hxx> +#include "ServiceMacros.hxx" +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +// #ifndef _COM_SUN_STAR_LANG_XMULTICOMPONENTFACTORY_HPP_ +// #include <com/sun/star/lang/XMultiComponentFactory.hpp> +// #endif + +#include <com/sun/star/chart2/XChartTypeManager.hpp> + +// #include <map> + +namespace chart +{ + +class ChartTypeManager : + public ::cppu::WeakImplHelper2< + ::com::sun::star::lang::XMultiServiceFactory, +// ::com::sun::star::lang::XMultiComponentFactory, + ::com::sun::star::chart2::XChartTypeManager > +{ +public: + explicit ChartTypeManager( + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~ChartTypeManager(); + + APPHELPER_XSERVICEINFO_DECL() + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( ChartTypeManager ) + +protected: + // ____ XMultiServiceFactory ____ + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XInterface > SAL_CALL createInstance( const ::rtl::OUString& aServiceSpecifier ) + throw (::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XInterface > SAL_CALL createInstanceWithArguments( + const ::rtl::OUString& ServiceSpecifier, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Any >& Arguments ) + throw (::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< + ::rtl::OUString > SAL_CALL getAvailableServiceNames() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XChartTypeManager ____ + // currently empty + +private: + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + m_xContext; +}; + +} // namespace chart + +// CHART_CHARTTYPEMANAGER_HXX +#endif diff --git a/chart2/source/model/inc/DataSeries.hxx b/chart2/source/model/inc/DataSeries.hxx new file mode 100644 index 000000000000..e05bac782b86 --- /dev/null +++ b/chart2/source/model/inc/DataSeries.hxx @@ -0,0 +1,230 @@ +/************************************************************************* + * + * 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_DATASERIES_HXX +#define _CHART_DATASERIES_HXX + +// UNO types +#include <com/sun/star/chart2/XDataSeries.hpp> +#include <com/sun/star/chart2/data/XDataSink.hpp> +#include <com/sun/star/chart2/data/XDataSource.hpp> +#include <com/sun/star/chart2/XRegressionCurveContainer.hpp> +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/util/XModifyBroadcaster.hpp> +#include <com/sun/star/util/XModifyListener.hpp> +#include <com/sun/star/container/XIndexContainer.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +// helper classes +#include "ServiceMacros.hxx" +#include <cppuhelper/implbase8.hxx> +#include <comphelper/uno3.hxx> +#include <osl/mutex.hxx> + +// STL +#include <vector> +#include <map> + +#include "MutexContainer.hxx" +#include "OPropertySet.hxx" + +namespace com { namespace sun { namespace star { namespace style { + class XStyle; +}}}} + +namespace chart +{ + +namespace impl +{ +typedef ::cppu::WeakImplHelper8< + ::com::sun::star::chart2::XDataSeries, + ::com::sun::star::chart2::data::XDataSink, + ::com::sun::star::chart2::data::XDataSource, + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::chart2::XRegressionCurveContainer, + ::com::sun::star::util::XCloneable, + ::com::sun::star::util::XModifyBroadcaster, + ::com::sun::star::util::XModifyListener > + DataSeries_Base; +} + +class DataSeries : + public MutexContainer, + public impl::DataSeries_Base, + public ::property::OPropertySet +{ +public: + explicit DataSeries( + const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext ); + virtual ~DataSeries(); + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( DataSeries ) + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + explicit DataSeries( const DataSeries & rOther ); + + // late initialization to call after copy-constructing + void Init( const DataSeries & rOther ); + + // ____ XDataSeries ____ + // _____________________ + /// @see ::com::sun::star::chart2::XDataSeries + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > + SAL_CALL getDataPointByIndex( sal_Int32 nIndex ) + throw (::com::sun::star::lang::IndexOutOfBoundsException, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL resetDataPoint( sal_Int32 nIndex ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL resetAllDataPoints() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XDataSink ____ + // ___________________ + /// @see ::com::sun::star::chart2::data::XDataSink + virtual void SAL_CALL setData( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XLabeledDataSequence > >& aData ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ XDataSource ____ + // _____________________ + /// @see ::com::sun::star::chart2::data::XDataSource + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XLabeledDataSequence > > SAL_CALL getDataSequences() + 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 void SAL_CALL getFastPropertyValue( ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const; + virtual void SAL_CALL setFastPropertyValue_NoBroadcast + ( sal_Int32 nHandle, + const ::com::sun::star::uno::Any& rValue ) + throw (::com::sun::star::uno::Exception); + + virtual ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelper(); + + // ____ XPropertySet ____ + // ______________________ + /// @see ::com::sun::star::beans::XPropertySet + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL + getPropertySetInfo() + throw (::com::sun::star::uno::RuntimeException); + + /// make original interface function visible again + using ::com::sun::star::beans::XFastPropertySet::getFastPropertyValue; + + // ____ XRegressionCurveContainer ____ + // ___________________________________ + /// @see ::com::sun::star::chart2::XRegressionCurveContainer + virtual void SAL_CALL addRegressionCurve( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XRegressionCurve >& aRegressionCurve ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeRegressionCurve( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XRegressionCurve >& aRegressionCurve ) + 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::XRegressionCurve > > SAL_CALL getRegressionCurves() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setRegressionCurves( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XRegressionCurve > >& aRegressionCurves ) + 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); + + // ____ 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); + + // ____ OPropertySet ____ + virtual void firePropertyChangeEvent(); + using OPropertySet::disposing; + + void fireModifyEvent(); + + /** const variant of getInfoHelper() + */ + ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelperConst() const; + +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::data::XLabeledDataSequence > > tDataSequenceContainer; + tDataSequenceContainer m_aDataSequences; + + typedef ::std::map< sal_Int32, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > > tDataPointAttributeContainer; + tDataPointAttributeContainer m_aAttributedDataPoints; + + typedef + ::std::vector< ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XRegressionCurve > > + tRegressionCurveContainerType; + tRegressionCurveContainerType m_aRegressionCurves; + + ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xModifyEventForwarder; +}; + +} // namespace chart + +// _CHART_DATASERIES_HXX +#endif diff --git a/chart2/source/model/inc/DataSeriesTree.hxx b/chart2/source/model/inc/DataSeriesTree.hxx new file mode 100644 index 000000000000..5c6734dde845 --- /dev/null +++ b/chart2/source/model/inc/DataSeriesTree.hxx @@ -0,0 +1,91 @@ +/************************************************************************* + * + * 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_DATASERIESTREE_HXX +#define CHART_DATASERIESTREE_HXX + +#include <cppuhelper/implbase2.hxx> + +#include "ServiceMacros.hxx" +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/chart2/XDataSeriesTreeParent.hpp> + +#include <vector> + +namespace chart +{ + +class DataSeriesTree : public + ::cppu::WeakImplHelper2< + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::chart2::XDataSeriesTreeParent > +{ +public: + DataSeriesTree( const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext ); + virtual ~DataSeriesTree(); + + /// declare XServiceInfo methods + APPHELPER_XSERVICEINFO_DECL() + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( DataSeriesTree ) + +protected: + + // ____ XDataSeriesTreeParent ____ + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeriesTreeNode > > + SAL_CALL getChildren() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setChildren( + const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeriesTreeNode > >& aNewChildren ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addChild( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeriesTreeNode >& aNode ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeChild( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDataSeriesTreeNode >& aNode ) + throw (::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException); + + // ____ XDataSeriesTreeNode ____ + +private: + typedef ::std::vector< ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDataSeriesTreeNode > > + m_tChildType; + + m_tChildType m_aChildren; + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > + m_xContext; +}; + +} // namespace chart + +// CHART_DATASERIESTREE_HXX +#endif diff --git a/chart2/source/model/inc/Diagram.hxx b/chart2/source/model/inc/Diagram.hxx new file mode 100644 index 000000000000..fc672e29b24c --- /dev/null +++ b/chart2/source/model/inc/Diagram.hxx @@ -0,0 +1,241 @@ +/************************************************************************* + * + * 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_DIAGRAM_HXX +#define CHART_DIAGRAM_HXX + +#include "OPropertySet.hxx" +#include "MutexContainer.hxx" +#include <cppuhelper/implbase8.hxx> +#include <comphelper/uno3.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/chart2/XDiagram.hpp> +#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp> +#include <com/sun/star/chart2/XTitled.hpp> +#include <com/sun/star/chart/X3DDefaultSetter.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/util/XModifyBroadcaster.hpp> +#include <com/sun/star/util/XModifyListener.hpp> + +#include "ServiceMacros.hxx" + +#include <map> +#include <vector> + +namespace chart +{ + +namespace impl +{ +typedef ::cppu::WeakImplHelper8< + ::com::sun::star::chart2::XDiagram, + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::chart2::XCoordinateSystemContainer, + ::com::sun::star::chart2::XTitled, + ::com::sun::star::chart::X3DDefaultSetter, + ::com::sun::star::util::XModifyBroadcaster, + ::com::sun::star::util::XModifyListener, + ::com::sun::star::util::XCloneable > + Diagram_Base; +} + +class Diagram : + public MutexContainer, + public impl::Diagram_Base, + public ::property::OPropertySet +{ +public: + Diagram( ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~Diagram(); + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( Diagram ) + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + explicit Diagram( const Diagram & rOther ); + + // ____ 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); + + // ____ XFastPropertySet ____ + virtual void SAL_CALL setFastPropertyValue( sal_Int32 nHandle, const ::com::sun::star::uno::Any& rValue ) + throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); + + /// make original interface function visible again + using ::com::sun::star::beans::XFastPropertySet::getFastPropertyValue; + + virtual void SAL_CALL getFastPropertyValue( + ::com::sun::star::uno::Any& rValue, sal_Int32 nHandle ) const; + +// virtual sal_Bool SAL_CALL convertFastPropertyValue +// ( ::com::sun::star::uno::Any & rConvertedValue, +// ::com::sun::star::uno::Any & rOldValue, +// sal_Int32 nHandle, +// const ::com::sun::star::uno::Any& rValue ) +// throw (::com::sun::star::lang::IllegalArgumentException); + + // ____ XDiagram ____ +// virtual ::rtl::OUString SAL_CALL getChartTypeTemplateServiceName() +// throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > SAL_CALL getWall() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > SAL_CALL getFloor() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XLegend > SAL_CALL getLegend() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setLegend( const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XLegend >& xLegend ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XColorScheme > SAL_CALL getDefaultColorScheme() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDefaultColorScheme( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XColorScheme >& xColorScheme ) + throw (::com::sun::star::uno::RuntimeException); + + + // ____ XCoordinateSystemContainer ____ + virtual void SAL_CALL addCoordinateSystem( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XCoordinateSystem >& aCoordSys ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeCoordinateSystem( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XCoordinateSystem >& aCoordSys ) + 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::XCoordinateSystem > > SAL_CALL getCoordinateSystems() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setCoordinateSystems( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XCoordinateSystem > >& aCoordinateSystems ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + + // ____ XTitled ____ + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XTitle > SAL_CALL getTitleObject() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setTitleObject( const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XTitle >& Title ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ X3DDefaultSetter ____ + virtual void SAL_CALL set3DSettingsToDefault() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDefaultRotation() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setDefaultIllumination() 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); + + // ____ 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); + + // ____ OPropertySet ____ + virtual void firePropertyChangeEvent(); + using OPropertySet::disposing; + + void fireModifyEvent(); + +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::XCoordinateSystem > > + tCoordinateSystemContainerType; + + tCoordinateSystemContainerType m_aCoordSystems; + + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > + m_xWall; + + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > + m_xFloor; + + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XTitle > + m_xTitle; + + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XLegend > + m_xLegend; + + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XColorScheme > + m_xColorScheme; + + ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xModifyEventForwarder; +}; + +} // namespace chart + +// CHART_DIAGRAM_HXX +#endif diff --git a/chart2/source/model/inc/PolarCoordinateSystem.hxx b/chart2/source/model/inc/PolarCoordinateSystem.hxx new file mode 100644 index 000000000000..cf82e1cb0871 --- /dev/null +++ b/chart2/source/model/inc/PolarCoordinateSystem.hxx @@ -0,0 +1,93 @@ +/************************************************************************* + * + * 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_POLARCOORDINATESYSTEM_HXX +#define _CHART_POLARCOORDINATESYSTEM_HXX + +#include "ServiceMacros.hxx" +#include "BaseCoordinateSystem.hxx" + +namespace chart +{ + +class PolarCoordinateSystem : public BaseCoordinateSystem +{ +public: + explicit PolarCoordinateSystem( + const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext, + sal_Int32 nDimensionCount = 2, + sal_Bool bSwapXAndYAxis = sal_False ); + explicit PolarCoordinateSystem( const PolarCoordinateSystem & rSource ); + virtual ~PolarCoordinateSystem(); + + // ____ XCoordinateSystem ____ + virtual ::rtl::OUString SAL_CALL getCoordinateSystemType() + throw (::com::sun::star::uno::RuntimeException); + virtual ::rtl::OUString SAL_CALL getViewServiceName() + 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); + + // ____ XServiceInfo ____ + APPHELPER_XSERVICEINFO_DECL() +}; + +class PolarCoordinateSystem2d : public PolarCoordinateSystem +{ +public: + explicit PolarCoordinateSystem2d( + const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext ); + virtual ~PolarCoordinateSystem2d(); + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( PolarCoordinateSystem2d ) + // ____ XServiceInfo ____ + APPHELPER_XSERVICEINFO_DECL() +}; + +class PolarCoordinateSystem3d : public PolarCoordinateSystem +{ +public: + explicit PolarCoordinateSystem3d( + const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext ); + virtual ~PolarCoordinateSystem3d(); + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( PolarCoordinateSystem3d ) + // ____ XServiceInfo ____ + APPHELPER_XSERVICEINFO_DECL() +}; + +} // namespace chart + +// _CHART_POLARCOORDINATESYSTEM_HXX +#endif diff --git a/chart2/source/model/inc/StockBar.hxx b/chart2/source/model/inc/StockBar.hxx new file mode 100644 index 000000000000..7fa98b79964b --- /dev/null +++ b/chart2/source/model/inc/StockBar.hxx @@ -0,0 +1,119 @@ +/************************************************************************* + * + * 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_STOCKBAR_HXX +#define CHART_STOCKBAR_HXX + +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/util/XModifyBroadcaster.hpp> +#include <com/sun/star/util/XModifyListener.hpp> +#include "MutexContainer.hxx" +#include "OPropertySet.hxx" + +#include "ServiceMacros.hxx" +#include <cppuhelper/implbase3.hxx> +#include <comphelper/uno3.hxx> + +namespace chart +{ + +namespace impl +{ +typedef ::cppu::WeakImplHelper3< + ::com::sun::star::util::XCloneable, + ::com::sun::star::util::XModifyBroadcaster, + ::com::sun::star::util::XModifyListener > + StockBar_Base; +} + +class StockBar : + public MutexContainer, + public impl::StockBar_Base, + public ::property::OPropertySet +{ +public: + explicit StockBar( bool bRisingCourse ); + virtual ~StockBar(); + + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + +protected: + explicit StockBar( const StockBar & rOther ); + + // ____ 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); + + // ____ 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); + + // ____ OPropertySet ____ + virtual void firePropertyChangeEvent(); + using OPropertySet::disposing; + + void fireModifyEvent(); + +private: + const bool m_bRisingCourse; + ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xModifyEventForwarder; +}; + +} // namespace chart + +// CHART_STOCKBAR_HXX +#endif diff --git a/chart2/source/model/inc/XMLFilter.hxx b/chart2/source/model/inc/XMLFilter.hxx new file mode 100644 index 000000000000..69b008bbcb75 --- /dev/null +++ b/chart2/source/model/inc/XMLFilter.hxx @@ -0,0 +1,223 @@ +/************************************************************************* + * + * 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 CHART2_XMLFILTER_HXX +#define CHART2_XMLFILTER_HXX + +#include <cppuhelper/implbase4.hxx> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/document/XImporter.hpp> +#include <com/sun/star/document/XExporter.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/io/XActiveDataSource.hpp> +#include <osl/mutex.hxx> + +// for APPHELPER_... macros +#include "ServiceMacros.hxx" + +namespace com { namespace sun { namespace star { +namespace embed +{ + class XStorage; +} +namespace xml { namespace sax +{ + class XParser; +}} +namespace document +{ + class XGraphicObjectResolver; +} +}}} + +namespace chart +{ + +class XMLFilter : public + ::cppu::WeakImplHelper4< + ::com::sun::star::document::XFilter, + ::com::sun::star::document::XExporter, + ::com::sun::star::document::XImporter, + ::com::sun::star::lang::XServiceInfo > +{ +public: + explicit XMLFilter( ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~XMLFilter(); + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( XMLFilter ) + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + +protected: + // ____ XFilter ____ + virtual sal_Bool SAL_CALL filter( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue >& aDescriptor ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL cancel() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XImporter ____ + virtual void SAL_CALL setTargetDocument( + const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XComponent >& Document ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + + // ____ XExporter ____ + virtual void SAL_CALL setSourceDocument( + const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XComponent >& Document ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + + inline ::rtl::OUString getDocumentHandler() const { return m_sDocumentHandler; } + inline void setDocumentHandler(const ::rtl::OUString& _sDocumentHandler) { m_sDocumentHandler = _sDocumentHandler; } + + virtual ::rtl::OUString getMediaType(bool _bOasis); + + /** fills the oasis flag only when a filtername was set + * + * \param _rMediaDescriptor + * \param _rOutOASIS + */ + virtual void isOasisFormat(const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue >& _rMediaDescriptor, bool & _rOutOASIS ); + +private: + // methods + + /// @return a warning code, or 0 for successful operation + sal_Int32 impl_Import( const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XComponent > & xDocumentComp, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue > & aMediaDescriptor ); + /// @return a warning code, or 0 for successful operation + sal_Int32 impl_ImportStream( + const ::rtl::OUString & rStreamName, + const ::rtl::OUString & rServiceName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::embed::XStorage > & xStorage, + const ::com::sun::star::uno::Reference< + ::com::sun::star::xml::sax::XParser > & xParser, + const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiComponentFactory > & xFactory, + const ::com::sun::star::uno::Reference< + ::com::sun::star::document::XGraphicObjectResolver > & xGraphicObjectResolver, + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet >& xPropSet ); + + /// @return a warning code, or 0 for successful operation + sal_Int32 impl_Export( const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XComponent > & xDocumentComp, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue > & aMediaDescriptor ); + /// @return a warning code, or 0 for successful operation + sal_Int32 impl_ExportStream( + const ::rtl::OUString & rStreamName, + const ::rtl::OUString & rServiceName, + const ::com::sun::star::uno::Reference< + ::com::sun::star::embed::XStorage > & xStorage, + const ::com::sun::star::uno::Reference< + ::com::sun::star::io::XActiveDataSource >& xActiveDataSource, + const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XMultiServiceFactory > & xFactory, + const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Any > & rFilterProperties ); + + // members + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > m_xContext; + ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XComponent > m_xTargetDoc; + ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XComponent > m_xSourceDoc; + ::rtl::OUString m_sDocumentHandler; // when set it will be set as doc handler + + volatile bool m_bCancelOperation; + ::osl::Mutex m_aMutex; +}; + +// ============================================================================= +class XMLReportFilterHelper : public XMLFilter +{ + virtual void isOasisFormat(const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue >& _rMediaDescriptor, bool & _rOutOASIS ); +public: + explicit XMLReportFilterHelper( ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & _xContext ) + :XMLFilter(_xContext) + {} + /// establish methods for factory instatiation + static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL create( + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > const & xContext) throw(::com::sun::star::uno::Exception) + { + return (::cppu::OWeakObject *)new XMLReportFilterHelper( xContext ); + } + static ::rtl::OUString getImplementationName_Static() + { + return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.chart2.report.XMLFilter" )); + } +protected: + virtual ::rtl::OUString SAL_CALL + getImplementationName() + throw( ::com::sun::star::uno::RuntimeException ) + { + return getImplementationName_Static(); + } + // ____ XImporter ____ + virtual void SAL_CALL setTargetDocument( + const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XComponent >& Document ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException) + { + setDocumentHandler(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.ImportDocumentHandler"))); + XMLFilter::setTargetDocument(Document); + } + + // ____ XExporter ____ + virtual void SAL_CALL setSourceDocument( + const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XComponent >& Document ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException) + { + setDocumentHandler(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.report.ExportDocumentHandler"))); + XMLFilter::setSourceDocument(Document); + } + + virtual ::rtl::OUString getMediaType(bool _bOasis); +}; + +} // namespace chart + +// CHART2_XMLFILTER_HXX +#endif diff --git a/chart2/source/model/inc/_serviceregistration_charttypes.hxx b/chart2/source/model/inc/_serviceregistration_charttypes.hxx new file mode 100644 index 000000000000..481a7064f311 --- /dev/null +++ b/chart2/source/model/inc/_serviceregistration_charttypes.hxx @@ -0,0 +1,40 @@ +/************************************************************************* + * + * 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 CHART2__SERVICEREGISTRATION_CHARTTYPES_HXX +#define CHART2__SERVICEREGISTRATION_CHARTTYPES_HXX + +#include <cppuhelper/implementationentry.hxx> + +class ChartTypeEntriesForServiceRegistration +{ +public: + static struct ::cppu::ImplementationEntry* + getImplementationEntries(); +}; + +// CHART2__SERVICEREGISTRATION_CHARTTYPES_HXX +#endif diff --git a/chart2/source/model/main/Axis.cxx b/chart2/source/model/main/Axis.cxx new file mode 100644 index 000000000000..fd1d78ebe071 --- /dev/null +++ b/chart2/source/model/main/Axis.cxx @@ -0,0 +1,646 @@ +/************************************************************************* + * + * 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 "Axis.hxx" +#include "GridProperties.hxx" +#include "macros.hxx" +#include "CharacterProperties.hxx" +#include "LineProperties.hxx" +#include "UserDefinedProperties.hxx" +#include "PropertyHelper.hxx" +#include "ContainerHelper.hxx" +#include "CloneHelper.hxx" +#include "AxisHelper.hxx" +#include "EventListenerHelper.hxx" +#include <com/sun/star/chart/ChartAxisArrangeOrderType.hpp> +#include <com/sun/star/chart/ChartAxisLabelPosition.hpp> +#include <com/sun/star/chart/ChartAxisMarkPosition.hpp> +#include <com/sun/star/chart/ChartAxisPosition.hpp> +#include <com/sun/star/chart2/AxisType.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/lang/Locale.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> +#include <com/sun/star/drawing/LineDash.hpp> +#include <com/sun/star/drawing/LineJoint.hpp> +#include <com/sun/star/awt/Size.hpp> +#include <rtl/uuid.h> +#include <cppuhelper/queryinterface.hxx> + +#include <vector> +#include <algorithm> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::beans::PropertyAttribute; + +using ::rtl::OUString; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::com::sun::star::beans::Property; +using ::osl::MutexGuard; + +namespace +{ + +static const OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.Axis" )); + +enum +{ + PROP_AXIS_SHOW, + PROP_AXIS_CROSSOVER_POSITION, + PROP_AXIS_CROSSOVER_VALUE, + PROP_AXIS_DISPLAY_LABELS, + PROP_AXIS_NUMBER_FORMAT, + PROP_AXIS_LABEL_POSITION, + PROP_AXIS_TEXT_ROTATION, + PROP_AXIS_TEXT_BREAK, + PROP_AXIS_TEXT_OVERLAP, + PROP_AXIS_TEXT_STACKED, + PROP_AXIS_TEXT_ARRANGE_ORDER, + PROP_AXIS_REFERENCE_DIAGRAM_SIZE, + + PROP_AXIS_MAJOR_TICKMARKS, + PROP_AXIS_MINOR_TICKMARKS, + PROP_AXIS_MARK_POSITION +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "Show" ), + PROP_AXIS_SHOW, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "CrossoverPosition" ), + PROP_AXIS_CROSSOVER_POSITION, + ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartAxisPosition * >(0)), + beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "CrossoverValue" ), + PROP_AXIS_CROSSOVER_VALUE, + ::getCppuType( reinterpret_cast< const double * >(0)), + beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "DisplayLabels" ), + PROP_AXIS_DISPLAY_LABELS, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "NumberFormat" ), + PROP_AXIS_NUMBER_FORMAT, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "LabelPosition" ), + PROP_AXIS_LABEL_POSITION, + ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartAxisLabelPosition * >(0)), + beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "TextRotation" ), + PROP_AXIS_TEXT_ROTATION, + ::getCppuType( reinterpret_cast< const double * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "TextBreak" ), + PROP_AXIS_TEXT_BREAK, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "TextOverlap" ), + PROP_AXIS_TEXT_OVERLAP, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "StackCharacters" ), + PROP_AXIS_TEXT_STACKED, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "ArrangeOrder" ), + PROP_AXIS_TEXT_ARRANGE_ORDER, + ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartAxisArrangeOrderType * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "ReferencePageSize" ), + PROP_AXIS_REFERENCE_DIAGRAM_SIZE, + ::getCppuType( reinterpret_cast< const awt::Size * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "MajorTickmarks" ), + PROP_AXIS_MAJOR_TICKMARKS, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "MinorTickmarks" ), + PROP_AXIS_MINOR_TICKMARKS, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "MarkPosition" ), + PROP_AXIS_MARK_POSITION, + ::getCppuType( reinterpret_cast< const ::com::sun::star::chart::ChartAxisMarkPosition * >(0)), + beans::PropertyAttribute::MAYBEDEFAULT )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_SHOW, true ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_CROSSOVER_POSITION, ::com::sun::star::chart::ChartAxisPosition_ZERO ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_DISPLAY_LABELS, true ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_LABEL_POSITION, ::com::sun::star::chart::ChartAxisLabelPosition_NEAR_AXIS ); + ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_AXIS_TEXT_ROTATION, 0.0 ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_TEXT_BREAK, false ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_TEXT_OVERLAP, false ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_TEXT_STACKED, false ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_TEXT_ARRANGE_ORDER, ::com::sun::star::chart::ChartAxisArrangeOrderType_AUTO ); + + float fDefaultCharHeight = 10.0; + ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight ); + ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight ); + ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight ); + + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_AXIS_MAJOR_TICKMARKS, 2 /* CHAXIS_MARK_OUTER */ ); + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_AXIS_MINOR_TICKMARKS, 0 /* CHAXIS_MARK_NONE */ ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_AXIS_MARK_POSITION, ::com::sun::star::chart::ChartAxisMarkPosition_AT_LABELS_AND_AXIS ); +} + +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 ); + ::chart::CharacterProperties::AddPropertiesToVector( aProperties ); + ::chart::LineProperties::AddPropertiesToVector( aProperties ); + ::chart::UserDefinedProperties::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; +} + +typedef uno::Reference< beans::XPropertySet > lcl_tSubGridType; +typedef uno::Sequence< lcl_tSubGridType > lcl_tSubGridSeq; + +void lcl_CloneSubGrids( + const lcl_tSubGridSeq & rSource, lcl_tSubGridSeq & rDestination ) +{ + const lcl_tSubGridType * pBegin = rSource.getConstArray(); + const lcl_tSubGridType * pEnd = pBegin + rSource.getLength(); + + rDestination.realloc( rSource.getLength()); + lcl_tSubGridType * pDestBegin = rDestination.getArray(); + lcl_tSubGridType * pDestEnd = pDestBegin + rDestination.getLength(); + lcl_tSubGridType * pDestIt = pDestBegin; + + for( const lcl_tSubGridType * pIt = pBegin; pIt != pEnd; ++pIt ) + { + Reference< beans::XPropertySet > xSubGrid( *pIt ); + if( xSubGrid.is()) + { + Reference< util::XCloneable > xCloneable( xSubGrid, uno::UNO_QUERY ); + if( xCloneable.is()) + xSubGrid.set( xCloneable->createClone(), uno::UNO_QUERY ); + } + + (*pDestIt) = xSubGrid; + OSL_ASSERT( pDestIt != pDestEnd ); + ++pDestIt; + } + OSL_ASSERT( pDestIt == pDestEnd ); + (void)(pDestEnd); // avoid warning +} + +} // anonymous namespace + +// ================================================================================ + +namespace chart +{ + +Axis::Axis( Reference< uno::XComponentContext > const & /* xContext */ ) : + ::property::OPropertySet( m_aMutex ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()), + m_aScaleData( AxisHelper::createDefaultScale() ), + m_xGrid( new GridProperties() ), + m_aSubGridProperties(), + m_xTitle() +{ + osl_incrementInterlockedCount(&m_refCount); + setFastPropertyValue_NoBroadcast( + ::chart::LineProperties::PROP_LINE_COLOR, uno::makeAny( static_cast< sal_Int32 >( 0xb3b3b3 ) ) ); // gray30 + + if( m_xGrid.is()) + ModifyListenerHelper::addListener( m_xGrid, m_xModifyEventForwarder ); + if( m_aScaleData.Categories.is()) + ModifyListenerHelper::addListener( m_aScaleData.Categories, m_xModifyEventForwarder ); + + AllocateSubGrids(); + osl_decrementInterlockedCount(&m_refCount); +} + +Axis::Axis( const Axis & rOther ) : + MutexContainer(), + impl::Axis_Base(), + ::property::OPropertySet( rOther, m_aMutex ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()), + m_aScaleData( rOther.m_aScaleData ) +{ + m_xGrid.set( CloneHelper::CreateRefClone< Reference< beans::XPropertySet > >()( rOther.m_xGrid )); + if( m_xGrid.is()) + ModifyListenerHelper::addListener( m_xGrid, m_xModifyEventForwarder ); + + if( m_aScaleData.Categories.is()) + ModifyListenerHelper::addListener( m_aScaleData.Categories, m_xModifyEventForwarder ); + + if( rOther.m_aSubGridProperties.getLength() != 0 ) + lcl_CloneSubGrids( rOther.m_aSubGridProperties, m_aSubGridProperties ); + ModifyListenerHelper::addListenerToAllSequenceElements( m_aSubGridProperties, m_xModifyEventForwarder ); + + m_xTitle.set( CloneHelper::CreateRefClone< Reference< chart2::XTitle > >()( rOther.m_xTitle )); + if( m_xTitle.is()) + ModifyListenerHelper::addListener( m_xTitle, m_xModifyEventForwarder ); +} + +// late initialization to call after copy-constructing +void Axis::Init( const Axis & /* rOther */ ) +{ + if( m_aScaleData.Categories.is()) + EventListenerHelper::addListener( m_aScaleData.Categories, this ); +} + +Axis::~Axis() +{ + try + { + ModifyListenerHelper::removeListener( m_xGrid, m_xModifyEventForwarder ); + ModifyListenerHelper::removeListenerFromAllSequenceElements( m_aSubGridProperties, m_xModifyEventForwarder ); + ModifyListenerHelper::removeListener( m_xTitle, m_xModifyEventForwarder ); + if( m_aScaleData.Categories.is()) + { + ModifyListenerHelper::removeListener( m_aScaleData.Categories, m_xModifyEventForwarder ); + m_aScaleData.Categories.set(0); + } + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + m_aSubGridProperties.realloc(0); + m_xGrid = 0; + m_xTitle = 0; +} + +void Axis::AllocateSubGrids() +{ + Reference< util::XModifyListener > xModifyEventForwarder; + Reference< lang::XEventListener > xEventListener; + std::vector< Reference< beans::XPropertySet > > aOldBroadcasters; + std::vector< Reference< beans::XPropertySet > > aNewBroadcasters; + { + MutexGuard aGuard( m_aMutex ); + xModifyEventForwarder = m_xModifyEventForwarder; + xEventListener = this; + + sal_Int32 nNewSubIncCount = m_aScaleData.IncrementData.SubIncrements.getLength(); + sal_Int32 nOldSubIncCount = m_aSubGridProperties.getLength(); + + if( nOldSubIncCount > nNewSubIncCount ) + { + // remove superfluous entries + for( sal_Int32 i = nNewSubIncCount; i < nOldSubIncCount; ++i ) + aOldBroadcasters.push_back( m_aSubGridProperties[ i ] ); + m_aSubGridProperties.realloc( nNewSubIncCount ); + } + else if( nOldSubIncCount < nNewSubIncCount ) + { + m_aSubGridProperties.realloc( nNewSubIncCount ); + + // allocate new entries + for( sal_Int32 i = nOldSubIncCount; i < nNewSubIncCount; ++i ) + { + m_aSubGridProperties[ i ] = new GridProperties(); + LineProperties::SetLineInvisible( m_aSubGridProperties[ i ] ); + aNewBroadcasters.push_back( m_aSubGridProperties[ i ] ); + } + } + } + //don't keep the mutex locked while calling out + std::vector< Reference< beans::XPropertySet > >::iterator aBroadcaster = aOldBroadcasters.begin(); + for( ;aBroadcaster != aOldBroadcasters.end(); ++aBroadcaster ) + ModifyListenerHelper::removeListener( *aBroadcaster, xModifyEventForwarder ); + for( aBroadcaster = aNewBroadcasters.begin(); aBroadcaster != aNewBroadcasters.end(); ++aBroadcaster ) + ModifyListenerHelper::addListener( *aBroadcaster, xModifyEventForwarder ); +} + +// -------------------------------------------------------------------------------- + +// ____ XAxis ____ +void SAL_CALL Axis::setScaleData( const chart2::ScaleData& rScaleData ) + throw (uno::RuntimeException) +{ + Reference< util::XModifyListener > xModifyEventForwarder; + Reference< lang::XEventListener > xEventListener; + Reference< chart2::data::XLabeledDataSequence > xOldCategories; + Reference< chart2::data::XLabeledDataSequence > xNewCategories = rScaleData.Categories; + { + MutexGuard aGuard( m_aMutex ); + xModifyEventForwarder = m_xModifyEventForwarder; + xEventListener = this; + xOldCategories = m_aScaleData.Categories; + m_aScaleData = rScaleData; + } + AllocateSubGrids(); + + //don't keep the mutex locked while calling out + if( xOldCategories.is() && xOldCategories != xNewCategories ) + { + ModifyListenerHelper::removeListener( xOldCategories, xModifyEventForwarder ); + EventListenerHelper::removeListener( xOldCategories, xEventListener ); + } + if( xNewCategories.is() && xOldCategories != xNewCategories ) + { + ModifyListenerHelper::addListener( xNewCategories, m_xModifyEventForwarder ); + EventListenerHelper::addListener( xNewCategories, xEventListener ); + } + fireModifyEvent(); +} + +chart2::ScaleData SAL_CALL Axis::getScaleData() + throw (uno::RuntimeException) +{ + // /-- + MutexGuard aGuard( m_aMutex ); + return m_aScaleData; + // \-- +} + +Reference< beans::XPropertySet > SAL_CALL Axis::getGridProperties() + throw (uno::RuntimeException) +{ + // /-- + MutexGuard aGuard( m_aMutex ); + return m_xGrid; + // \-- +} +Sequence< Reference< beans::XPropertySet > > SAL_CALL Axis::getSubGridProperties() + throw (uno::RuntimeException) +{ + // /-- + MutexGuard aGuard( m_aMutex ); + return m_aSubGridProperties; + // \-- +} + +Sequence< Reference< beans::XPropertySet > > SAL_CALL Axis::getSubTickProperties() + throw (uno::RuntimeException) +{ + OSL_ENSURE( false, "Not implemented yet" ); + return Sequence< Reference< beans::XPropertySet > >(); +} + + +// ____ XTitled ____ +Reference< chart2::XTitle > SAL_CALL Axis::getTitleObject() + throw (uno::RuntimeException) +{ + // /-- + MutexGuard aGuard( GetMutex() ); + return m_xTitle; + // \-- +} + +void SAL_CALL Axis::setTitleObject( const Reference< chart2::XTitle >& xNewTitle ) + throw (uno::RuntimeException) +{ + Reference< util::XModifyListener > xModifyEventForwarder; + Reference< chart2::XTitle > xOldTitle; + { + MutexGuard aGuard( GetMutex() ); + xOldTitle = m_xTitle; + xModifyEventForwarder = m_xModifyEventForwarder; + m_xTitle = xNewTitle; + } + + //don't keep the mutex locked while calling out + if( xOldTitle.is() && xOldTitle != xNewTitle ) + ModifyListenerHelper::removeListener( xOldTitle, xModifyEventForwarder ); + if( xNewTitle.is() && xOldTitle != xNewTitle ) + ModifyListenerHelper::addListener( xNewTitle, xModifyEventForwarder ); + fireModifyEvent(); +} + +// ____ XCloneable ____ +Reference< util::XCloneable > SAL_CALL Axis::createClone() + throw (uno::RuntimeException) +{ + Axis * pNewAxis( new Axis( *this )); + // hold a reference to the clone + Reference< util::XCloneable > xResult( pNewAxis ); + // do initialization that uses uno references to the clone + pNewAxis->Init( *this ); + return xResult; +} + +// ____ XModifyBroadcaster ____ +void SAL_CALL Axis::addModifyListener( const Reference< util::XModifyListener >& aListener ) + throw (uno::RuntimeException) +{ + try + { + Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW ); + xBroadcaster->addModifyListener( aListener ); + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +void SAL_CALL Axis::removeModifyListener( const Reference< util::XModifyListener >& aListener ) + throw (uno::RuntimeException) +{ + try + { + 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 Axis::modified( const lang::EventObject& aEvent ) + throw (uno::RuntimeException) +{ + m_xModifyEventForwarder->modified( aEvent ); +} + +// ____ XEventListener (base of XModifyListener) ____ +void SAL_CALL Axis::disposing( const lang::EventObject& Source ) + throw (uno::RuntimeException) +{ + if( Source.Source == m_aScaleData.Categories ) + m_aScaleData.Categories = 0; +} + +// ____ OPropertySet ____ +void Axis::firePropertyChangeEvent() +{ + fireModifyEvent(); +} + +void Axis::fireModifyEvent() +{ + m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); +} + +// ================================================================================ + +// ____ OPropertySet ____ +uno::Any Axis::GetDefaultValue( sal_Int32 nHandle ) const + throw(beans::UnknownPropertyException) +{ + static tPropertyValueMap aStaticDefaults; + + // /-- + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aStaticDefaults.size() ) + { + CharacterProperties::AddDefaultsToMap( aStaticDefaults ); + LineProperties::AddDefaultsToMap( aStaticDefaults ); + + // 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 Axis::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + + +// ____ XPropertySet ____ +Reference< beans::XPropertySetInfo > SAL_CALL + Axis::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static Reference< beans::XPropertySetInfo > xInfo; + + // /-- + MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + getInfoHelper()); + } + + return xInfo; + // \-- +} + +// ================================================================================ + +Sequence< OUString > Axis::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 2 ); + aServices[ 0 ] = C2U( "com.sun.star.chart2.Axis" ); + aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +using impl::Axis_Base; + +IMPLEMENT_FORWARD_XINTERFACE2( Axis, Axis_Base, ::property::OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( Axis, Axis_Base, ::property::OPropertySet ) + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( Axis, lcl_aServiceName ); + +} // namespace chart diff --git a/chart2/source/model/main/Axis.hxx b/chart2/source/model/main/Axis.hxx new file mode 100644 index 000000000000..7f72e08b8b69 --- /dev/null +++ b/chart2/source/model/main/Axis.hxx @@ -0,0 +1,184 @@ +/************************************************************************* + * + * 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_AXIS_HXX +#define CHART_AXIS_HXX + +#include <com/sun/star/uno/XComponentContext.hpp> +#include "MutexContainer.hxx" +#include "OPropertySet.hxx" +#include <cppuhelper/implbase6.hxx> +#include <comphelper/uno3.hxx> + +#include "ServiceMacros.hxx" +#include "ModifyListenerHelper.hxx" +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/chart2/XAxis.hpp> +#include <com/sun/star/chart2/XTitled.hpp> +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/util/XModifyBroadcaster.hpp> +#include <com/sun/star/util/XModifyListener.hpp> + +namespace chart +{ + +namespace impl +{ +typedef ::cppu::WeakImplHelper6< + ::com::sun::star::chart2::XAxis, + ::com::sun::star::chart2::XTitled, + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::util::XCloneable, + ::com::sun::star::util::XModifyBroadcaster, + ::com::sun::star::util::XModifyListener > + Axis_Base; +} + +class Axis : + public MutexContainer, + public impl::Axis_Base, + public ::property::OPropertySet +{ +public: + Axis( ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~Axis(); + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( Axis ) + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + explicit Axis( const Axis & rOther ); + + // late initialization to call after copy-constructing + void Init( const Axis & rOther ); + + // ____ 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); + +// virtual sal_Bool SAL_CALL convertFastPropertyValue +// ( ::com::sun::star::uno::Any & rConvertedValue, +// ::com::sun::star::uno::Any & rOldValue, +// sal_Int32 nHandle, +// const ::com::sun::star::uno::Any& rValue ) +// throw (::com::sun::star::lang::IllegalArgumentException); + + // ____ XAxis ____ + virtual void SAL_CALL setScaleData( const ::com::sun::star::chart2::ScaleData& rScaleData ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::chart2::ScaleData SAL_CALL getScaleData() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > SAL_CALL getGridProperties() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > > SAL_CALL getSubGridProperties() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > > SAL_CALL getSubTickProperties() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XTitled ____ + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XTitle > SAL_CALL getTitleObject() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setTitleObject( + const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XTitle >& Title ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ XCloneable ____ + // Note: the coordinate systems are not cloned! + virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() + throw (::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); + + // ____ OPropertySet ____ + virtual void firePropertyChangeEvent(); + using OPropertySet::disposing; + + void fireModifyEvent(); + +private: //methods + void AllocateSubGrids(); + +private: //member + + ::com::sun::star::uno::Reference< + ::com::sun::star::util::XModifyListener > m_xModifyEventForwarder; + + ::com::sun::star::chart2::ScaleData m_aScaleData; + + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > m_xGrid; + + ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > > m_aSubGridProperties; + + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XTitle > m_xTitle; +}; + +} // namespace chart + +// CHART_AXIS_HXX +#endif diff --git a/chart2/source/model/main/BaseCoordinateSystem.cxx b/chart2/source/model/main/BaseCoordinateSystem.cxx new file mode 100644 index 000000000000..4fa58cff5039 --- /dev/null +++ b/chart2/source/model/main/BaseCoordinateSystem.cxx @@ -0,0 +1,409 @@ +/************************************************************************* + * + * 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 "BaseCoordinateSystem.hxx" +#include "macros.hxx" +#include "PropertyHelper.hxx" +#include "UserDefinedProperties.hxx" +#include "ContainerHelper.hxx" +#include "CloneHelper.hxx" +#include "Axis.hxx" +#include "AxisHelper.hxx" +#include <com/sun/star/chart2/AxisType.hpp> + +#include <algorithm> + +#if OSL_DEBUG_LEVEL > 1 +#include <rtl/math.hxx> +#endif +#include <com/sun/star/beans/PropertyAttribute.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::beans::Property; + +namespace +{ +enum +{ + PROP_COORDINATESYSTEM_SWAPXANDYAXIS +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "SwapXAndYAxis" ), + PROP_COORDINATESYSTEM_SWAPXANDYAXIS, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_COORDINATESYSTEM_SWAPXANDYAXIS, 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 ); + ::chart::UserDefinedProperties::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 +{ + +BaseCoordinateSystem::BaseCoordinateSystem( + const Reference< uno::XComponentContext > & xContext, + sal_Int32 nDimensionCount /* = 2 */, + sal_Bool bSwapXAndYAxis /* = sal_False */ ) : + ::property::OPropertySet( m_aMutex ), + m_xContext( xContext ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()), + m_nDimensionCount( nDimensionCount ) + { + m_aAllAxis.resize( m_nDimensionCount ); + for( sal_Int32 nN=0; nN<m_nDimensionCount; nN++ ) + { + m_aAllAxis[nN].resize( 1 ); + Reference< chart2::XAxis > xAxis( new Axis(m_xContext) ); + m_aAllAxis[nN][0] = xAxis; + + ModifyListenerHelper::addListenerToAllElements( m_aAllAxis[nN], m_xModifyEventForwarder ); + chart2::ScaleData aScaleData( xAxis->getScaleData() ); + if(nN==0) + { + aScaleData.AxisType = chart2::AxisType::CATEGORY; + } + else if( nN==1) + { + aScaleData.AxisType = chart2::AxisType::REALNUMBER; + } + else if( nN==2) + { + aScaleData.AxisType = chart2::AxisType::SERIES; + } + xAxis->setScaleData( aScaleData ); + } + + m_aOrigin.realloc( m_nDimensionCount ); + for( sal_Int32 i = 0; i < m_nDimensionCount; ++i ) + m_aOrigin[ i ] = uno::makeAny( double( 0.0 ) ); + + setFastPropertyValue_NoBroadcast( PROP_COORDINATESYSTEM_SWAPXANDYAXIS, uno::makeAny( sal_Bool( bSwapXAndYAxis ))); +} + +// explicit +BaseCoordinateSystem::BaseCoordinateSystem( + const BaseCoordinateSystem & rSource ) : + impl::BaseCoordinateSystem_Base(), + MutexContainer(), + ::property::OPropertySet( rSource, m_aMutex ), + m_xContext( rSource.m_xContext ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()), + m_nDimensionCount( rSource.m_nDimensionCount ), + m_aOrigin( rSource.m_aOrigin ) +{ + m_aAllAxis.resize(rSource.m_aAllAxis.size()); + tAxisVecVecType::size_type nN=0; + for( nN=0; nN<m_aAllAxis.size(); nN++ ) + CloneHelper::CloneRefVector< Reference< chart2::XAxis > >( rSource.m_aAllAxis[nN], m_aAllAxis[nN] ); + CloneHelper::CloneRefVector< Reference< chart2::XChartType > >( rSource.m_aChartTypes, m_aChartTypes ); + + for( nN=0; nN<m_aAllAxis.size(); nN++ ) + ModifyListenerHelper::addListenerToAllElements( m_aAllAxis[nN], m_xModifyEventForwarder ); + ModifyListenerHelper::addListenerToAllElements( m_aChartTypes, m_xModifyEventForwarder ); +} + +BaseCoordinateSystem::~BaseCoordinateSystem() +{ + try + { + for( tAxisVecVecType::size_type nN=0; nN<m_aAllAxis.size(); nN++ ) + ModifyListenerHelper::removeListenerFromAllElements( m_aAllAxis[nN], m_xModifyEventForwarder ); + ModifyListenerHelper::removeListenerFromAllElements( m_aChartTypes, m_xModifyEventForwarder ); + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +// ____ XCoordinateSystem ____ +sal_Int32 SAL_CALL BaseCoordinateSystem::getDimension() + throw (uno::RuntimeException) +{ + return m_nDimensionCount; +} + +void SAL_CALL BaseCoordinateSystem::setAxisByDimension( + sal_Int32 nDimensionIndex, + const Reference< chart2::XAxis >& xAxis, + sal_Int32 nIndex ) + throw (lang::IndexOutOfBoundsException, + uno::RuntimeException) +{ + if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() ) + throw lang::IndexOutOfBoundsException(); + + if( nIndex < 0 ) + throw lang::IndexOutOfBoundsException(); + + if( m_aAllAxis[ nDimensionIndex ].size() < static_cast< tAxisVecVecType::size_type >( nIndex+1 )) + { + m_aAllAxis[ nDimensionIndex ].resize( nIndex+1 ); + m_aAllAxis[ nDimensionIndex ][nIndex] = 0; + } + + Reference< chart2::XAxis > xOldAxis( m_aAllAxis[ nDimensionIndex ][nIndex] ); + if( xOldAxis.is()) + ModifyListenerHelper::removeListener( xOldAxis, m_xModifyEventForwarder ); + m_aAllAxis[ nDimensionIndex ][nIndex] = xAxis; + if( xAxis.is()) + ModifyListenerHelper::addListener( xAxis, m_xModifyEventForwarder ); + fireModifyEvent(); +} + +Reference< chart2::XAxis > SAL_CALL BaseCoordinateSystem::getAxisByDimension( + sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex ) + throw (lang::IndexOutOfBoundsException, + uno::RuntimeException) +{ + if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() ) + throw lang::IndexOutOfBoundsException(); + + OSL_ASSERT( m_aAllAxis.size() == static_cast< size_t >( getDimension())); + + if( nAxisIndex < 0 || nAxisIndex > this->getMaximumAxisIndexByDimension(nDimensionIndex) ) + throw lang::IndexOutOfBoundsException(); + + return m_aAllAxis[ nDimensionIndex ][nAxisIndex]; +} + +sal_Int32 SAL_CALL BaseCoordinateSystem::getMaximumAxisIndexByDimension( sal_Int32 nDimensionIndex ) + throw (lang::IndexOutOfBoundsException, + uno::RuntimeException) +{ + if( nDimensionIndex < 0 || nDimensionIndex >= getDimension() ) + throw lang::IndexOutOfBoundsException(); + + OSL_ASSERT( m_aAllAxis.size() == static_cast< size_t >( getDimension())); + + sal_Int32 nRet = m_aAllAxis[ nDimensionIndex ].size(); + if(nRet) + nRet-=1; + + return nRet; +} + +// ____ XChartTypeContainer ____ +void SAL_CALL BaseCoordinateSystem::addChartType( const Reference< chart2::XChartType >& aChartType ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + if( ::std::find( m_aChartTypes.begin(), m_aChartTypes.end(), aChartType ) + != m_aChartTypes.end()) + throw lang::IllegalArgumentException(); + + m_aChartTypes.push_back( aChartType ); + ModifyListenerHelper::addListener( aChartType, m_xModifyEventForwarder ); + fireModifyEvent(); +} + +void SAL_CALL BaseCoordinateSystem::removeChartType( const Reference< chart2::XChartType >& aChartType ) + throw (container::NoSuchElementException, + uno::RuntimeException) +{ + ::std::vector< uno::Reference< chart2::XChartType > >::iterator + aIt( ::std::find( m_aChartTypes.begin(), m_aChartTypes.end(), aChartType )); + if( aIt == m_aChartTypes.end()) + throw container::NoSuchElementException( + C2U( "The given chart type is no element of the container" ), + static_cast< uno::XWeak * >( this )); + + m_aChartTypes.erase( aIt ); + ModifyListenerHelper::removeListener( aChartType, m_xModifyEventForwarder ); + fireModifyEvent(); +} + +Sequence< Reference< chart2::XChartType > > SAL_CALL BaseCoordinateSystem::getChartTypes() + throw (uno::RuntimeException) +{ + return ContainerHelper::ContainerToSequence( m_aChartTypes ); +} + +void SAL_CALL BaseCoordinateSystem::setChartTypes( const Sequence< Reference< chart2::XChartType > >& aChartTypes ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + ModifyListenerHelper::removeListenerFromAllElements( m_aChartTypes, m_xModifyEventForwarder ); + m_aChartTypes = ContainerHelper::SequenceToVector( aChartTypes ); + ModifyListenerHelper::addListenerToAllElements( m_aChartTypes, m_xModifyEventForwarder ); + fireModifyEvent(); +} + +// ____ XModifyBroadcaster ____ +void SAL_CALL BaseCoordinateSystem::addModifyListener( const Reference< util::XModifyListener >& aListener ) + throw (uno::RuntimeException) +{ + try + { + Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW ); + xBroadcaster->addModifyListener( aListener ); + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +void SAL_CALL BaseCoordinateSystem::removeModifyListener( const Reference< util::XModifyListener >& aListener ) + throw (uno::RuntimeException) +{ + try + { + 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 BaseCoordinateSystem::modified( const lang::EventObject& aEvent ) + throw (uno::RuntimeException) +{ + m_xModifyEventForwarder->modified( aEvent ); +} + +// ____ XEventListener (base of XModifyListener) ____ +void SAL_CALL BaseCoordinateSystem::disposing( const lang::EventObject& /* Source */ ) + throw (uno::RuntimeException) +{ + // nothing +} + +// ____ OPropertySet ____ +void BaseCoordinateSystem::firePropertyChangeEvent() +{ + fireModifyEvent(); +} + +void BaseCoordinateSystem::fireModifyEvent() +{ + m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); +} + + +// ____ OPropertySet ____ +uno::Any BaseCoordinateSystem::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 BaseCoordinateSystem::getInfoHelper() +{ + static ::cppu::OPropertyArrayHelper aArrayHelper( lcl_GetPropertySequence(), + /* bSorted = */ sal_True ); + + return aArrayHelper; +} + + +// ____ XPropertySet ____ +Reference< beans::XPropertySetInfo > SAL_CALL + BaseCoordinateSystem::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; + // \-- +} + +using impl::BaseCoordinateSystem_Base; + +IMPLEMENT_FORWARD_XINTERFACE2( BaseCoordinateSystem, BaseCoordinateSystem_Base, ::property::OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( BaseCoordinateSystem, BaseCoordinateSystem_Base, ::property::OPropertySet ) + +} // namespace chart diff --git a/chart2/source/model/main/CartesianCoordinateSystem.cxx b/chart2/source/model/main/CartesianCoordinateSystem.cxx new file mode 100644 index 000000000000..fdaa333b1cb8 --- /dev/null +++ b/chart2/source/model/main/CartesianCoordinateSystem.cxx @@ -0,0 +1,155 @@ +/************************************************************************* + * + * 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 "CartesianCoordinateSystem.hxx" +#include "macros.hxx" +#include "servicenames_coosystems.hxx" + +using namespace ::com::sun::star; + +using ::com::sun::star::uno::RuntimeException; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; + +namespace +{ + +static const ::rtl::OUString lcl_aServiceNameCartesian2d( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.CartesianCoordinateSystem2d" )); +static const ::rtl::OUString lcl_aServiceNameCartesian3d( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.CartesianCoordinateSystem3d" )); + +static const ::rtl::OUString lcl_aImplementationNameCartesian2d( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.CartesianCoordinateSystem2d" )); +static const ::rtl::OUString lcl_aImplementationNameCartesian3d( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.CartesianCoordinateSystem3d" )); +} + +namespace chart +{ + +// explicit +CartesianCoordinateSystem::CartesianCoordinateSystem( + const uno::Reference< uno::XComponentContext > & xContext, + sal_Int32 nDimensionCount /* = 2 */, + sal_Bool bSwapXAndYAxis /* = sal_False */ ) : + BaseCoordinateSystem( xContext, nDimensionCount, bSwapXAndYAxis ) +{} + +CartesianCoordinateSystem::CartesianCoordinateSystem( + const CartesianCoordinateSystem & rSource ) : + BaseCoordinateSystem( rSource ) +{} + +CartesianCoordinateSystem::~CartesianCoordinateSystem() +{} + +// ____ XCoordinateSystem ____ +::rtl::OUString SAL_CALL CartesianCoordinateSystem::getCoordinateSystemType() + throw (RuntimeException) +{ + return CHART2_COOSYSTEM_CARTESIAN_SERVICE_NAME; +} + +::rtl::OUString SAL_CALL CartesianCoordinateSystem::getViewServiceName() + throw (RuntimeException) +{ + return CHART2_COOSYSTEM_CARTESIAN_VIEW_SERVICE_NAME; +} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL CartesianCoordinateSystem::createClone() + throw (RuntimeException) +{ + return Reference< util::XCloneable >( new CartesianCoordinateSystem( *this )); +} + +// ____ XServiceInfo ____ +Sequence< OUString > CartesianCoordinateSystem::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 1 ); + aServices[ 0 ] = CHART2_COOSYSTEM_CARTESIAN_SERVICE_NAME; + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( CartesianCoordinateSystem, + C2U( "com.sun.star.comp.chart.CartesianCoordinateSystem" )) + + +// ================================= +// ==== CartesianCoordinateSystem2d ==== +// ================================= + +CartesianCoordinateSystem2d::CartesianCoordinateSystem2d( + const uno::Reference< uno::XComponentContext > & xContext ) : + CartesianCoordinateSystem( xContext, 2, sal_False ) +{} + +CartesianCoordinateSystem2d::~CartesianCoordinateSystem2d() +{} + +// ____ XServiceInfo ____ +Sequence< OUString > CartesianCoordinateSystem2d::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 2 ); + aServices[ 0 ] = CHART2_COOSYSTEM_CARTESIAN_SERVICE_NAME; + aServices[ 1 ] = lcl_aServiceNameCartesian2d; + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( CartesianCoordinateSystem2d, lcl_aImplementationNameCartesian2d ) + +// ================================= +// ==== CartesianCoordinateSystem3d ==== +// ================================= + +CartesianCoordinateSystem3d::CartesianCoordinateSystem3d( + const uno::Reference< uno::XComponentContext > & xContext ) : + CartesianCoordinateSystem( xContext, 3, sal_False ) +{} + +CartesianCoordinateSystem3d::~CartesianCoordinateSystem3d() +{} + +// ____ XServiceInfo ____ +Sequence< OUString > CartesianCoordinateSystem3d::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 2 ); + aServices[ 0 ] = CHART2_COOSYSTEM_CARTESIAN_SERVICE_NAME; + aServices[ 1 ] = lcl_aServiceNameCartesian3d; + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( CartesianCoordinateSystem3d, lcl_aImplementationNameCartesian3d ) + +} // namespace chart diff --git a/chart2/source/model/main/ChartModel.cxx b/chart2/source/model/main/ChartModel.cxx new file mode 100755 index 000000000000..5a30d97118c5 --- /dev/null +++ b/chart2/source/model/main/ChartModel.cxx @@ -0,0 +1,1379 @@ +/************************************************************************* + * + * 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 "ChartModel.hxx" +#include "servicenames.hxx" +#include "MediaDescriptorHelper.hxx" +#include "macros.hxx" +#include "servicenames.hxx" +#include "NoWarningThisInCTOR.hxx" +#include "DataSourceHelper.hxx" +#include "ChartModelHelper.hxx" +#include "DiagramHelper.hxx" +#include "DisposeHelper.hxx" +#include "ControllerLockGuard.hxx" +#include "ObjectIdentifier.hxx" +#include "PageBackground.hxx" +#include "CloneHelper.hxx" +#include "NameContainer.hxx" + +#include <com/sun/star/chart/ChartDataRowSource.hpp> + +#include <comphelper/InlineContainer.hxx> +#include <comphelper/processfactory.hxx> + +// header for class SvNumberFormatsSupplierObj +#include <svl/numuno.hxx> +#include <com/sun/star/lang/DisposedException.hpp> +#include <com/sun/star/lang/XInitialization.hpp> +#include <com/sun/star/view/XSelectionSupplier.hpp> +#include <com/sun/star/embed/XEmbedObjectCreator.hpp> +#include <com/sun/star/embed/XEmbedPersist.hpp> +#include <com/sun/star/embed/EmbedStates.hpp> +#include <com/sun/star/embed/XComponentSupplier.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/embed/EmbedMapUnits.hpp> +#include <com/sun/star/embed/Aspects.hpp> +#include <com/sun/star/awt/Gradient.hpp> +#include <com/sun/star/awt/XWindow.hpp> +#include <com/sun/star/awt/PosSize.hpp> +#include <com/sun/star/datatransfer/XTransferable.hpp> +#include <com/sun/star/drawing/Hatch.hpp> +#include <com/sun/star/drawing/LineDash.hpp> +#include <com/sun/star/drawing/XShapes.hpp> + +// header for class SvNumberFormatter +#include <svl/zforlist.hxx> + +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::rtl::OUString; +using ::osl::MutexGuard; + +using namespace ::com::sun::star; +using namespace ::apphelper; +using namespace ::chart::CloneHelper; + +namespace +{ +const OUString lcl_aGDIMetaFileMIMEType( + RTL_CONSTASCII_USTRINGPARAM("application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"")); +const OUString lcl_aGDIMetaFileMIMETypeHighContrast( + RTL_CONSTASCII_USTRINGPARAM("application/x-openoffice-highcontrast-gdimetafile;windows_formatname=\"GDIMetaFile\"")); + +} // anonymous namespace + +//----------------------------------------------------------------- +// ChartModel Constructor and Destructor +//----------------------------------------------------------------- + +namespace chart +{ + +ChartModel::ChartModel(uno::Reference<uno::XComponentContext > const & xContext) + : m_aLifeTimeManager( this, this ) + , m_bReadOnly( sal_False ) + , m_bModified( sal_False ) + , m_nInLoad(0) + , m_bUpdateNotificationsPending(false) + , m_aControllers( m_aModelMutex ) + , m_nControllerLockCount(0) + , m_xContext( xContext ) + , m_aVisualAreaSize( ChartModelHelper::getDefaultPageSize() ) + , m_xDataProvider( 0 ) + , m_xInternalDataProvider( 0 ) + , m_xPageBackground( new PageBackground( m_xContext ) ) + , m_xXMLNamespaceMap( createNameContainer( ::getCppuType( (const OUString*) 0 ), + C2U( "com.sun.star.xml.NamespaceMap" ), C2U( "com.sun.star.comp.chart.XMLNameSpaceMap" ) ), uno::UNO_QUERY) +{ + OSL_TRACE( "ChartModel: CTOR called" ); + osl_incrementInterlockedCount(&m_refCount); + + ModifyListenerHelper::addListener( m_xPageBackground, this ); + m_xChartTypeManager.set( xContext->getServiceManager()->createInstanceWithContext( + C2U( "com.sun.star.chart2.ChartTypeManager" ), m_xContext ), uno::UNO_QUERY ); + m_xUndoManager = Reference< chart2::XUndoManager >( + this->createInstance( CHART_UNDOMANAGER_SERVICE_NAME ), uno::UNO_QUERY ); + + osl_decrementInterlockedCount(&m_refCount); +} + +ChartModel::ChartModel( const ChartModel & rOther ) + : impl::ChartModel_Base() + , m_aLifeTimeManager( this, this ) + , m_bReadOnly( rOther.m_bReadOnly ) + , m_bModified( rOther.m_bModified ) + , m_nInLoad(0) + , m_bUpdateNotificationsPending(false) + , m_aResource( rOther.m_aResource ) + , m_aMediaDescriptor( rOther.m_aMediaDescriptor ) + , m_aControllers( m_aModelMutex ) + , m_nControllerLockCount(0) + , m_xContext( rOther.m_xContext ) + // @note: the old model aggregate must not be shared with other models if it + // is, you get mutex deadlocks + , m_xOldModelAgg( 0 ) //rOther.m_xOldModelAgg ) + , m_xStorage( 0 ) //rOther.m_xStorage ) + , m_aVisualAreaSize( rOther.m_aVisualAreaSize ) + , m_aGraphicObjectVector( rOther.m_aGraphicObjectVector ) + , m_xDataProvider( rOther.m_xDataProvider ) + , m_xInternalDataProvider( rOther.m_xInternalDataProvider ) + , m_xUndoManager( rOther.m_xUndoManager ) +{ + OSL_TRACE( "ChartModel: Copy-CTOR called" ); + osl_incrementInterlockedCount(&m_refCount); + + Reference< util::XModifyListener > xListener; + Reference< chart2::XTitle > xNewTitle = CreateRefClone< Reference< chart2::XTitle > >()( rOther.m_xTitle ); + Reference< chart2::XDiagram > xNewDiagram = CreateRefClone< Reference< chart2::XDiagram > >()( rOther.m_xDiagram ); + Reference< beans::XPropertySet > xNewPageBackground = CreateRefClone< Reference< beans::XPropertySet > >()( rOther.m_xPageBackground ); + Reference< chart2::XChartTypeManager > xChartTypeManager = CreateRefClone< Reference< chart2::XChartTypeManager > >()( rOther.m_xChartTypeManager ); + Reference< container::XNameAccess > xXMLNamespaceMap = CreateRefClone< Reference< container::XNameAccess > >()( rOther.m_xXMLNamespaceMap ); + + { + MutexGuard aGuard( m_aModelMutex ); + xListener = this; + m_xTitle = xNewTitle; + m_xDiagram = xNewDiagram; + m_xPageBackground = xNewPageBackground; + m_xChartTypeManager = xChartTypeManager; + m_xXMLNamespaceMap = xXMLNamespaceMap; + } + + ModifyListenerHelper::addListener( xNewTitle, xListener ); + ModifyListenerHelper::addListener( xNewDiagram, xListener ); + ModifyListenerHelper::addListener( xNewPageBackground, xListener ); + xListener.clear(); + + osl_decrementInterlockedCount(&m_refCount); +} + +ChartModel::~ChartModel() +{ + OSL_TRACE( "ChartModel: DTOR called" ); + if( m_xOldModelAgg.is()) + m_xOldModelAgg->setDelegator( 0 ); +} + + +//----------------------------------------------------------------- +// private methods +//----------------------------------------------------------------- + +::rtl::OUString ChartModel::impl_g_getLocation() +{ + + LifeTimeGuard aGuard(m_aLifeTimeManager); + if(!aGuard.startApiCall()) + return ::rtl::OUString(); //behave passive if already disposed or closed or throw exception @todo? + //mutex is acquired + return m_aResource; +} + +sal_Bool ChartModel::impl_isControllerConnected( const uno::Reference< frame::XController >& xController ) +{ + try + { + uno::Sequence< uno::Reference<uno::XInterface> > aSeq = m_aControllers.getElements(); + for( sal_Int32 nN = aSeq.getLength(); nN--; ) + { + if( aSeq[nN] == xController ) + return sal_True; + } + } + catch( uno::Exception ) + { + } + return sal_False; +} + +uno::Reference< frame::XController > ChartModel::impl_getCurrentController() throw(uno::RuntimeException) +{ + //@todo? hold only weak references to controllers + + // get the last active controller of this model + if( m_xCurrentController.is() ) + return m_xCurrentController; + + // get the first controller of this model + if( m_aControllers.getLength() ) + { + uno::Reference<uno::XInterface> xI = m_aControllers.getElements()[0]; + return uno::Reference<frame::XController>( xI, uno::UNO_QUERY ); + } + + //return nothing if no controllers are connected at all + return uno::Reference< frame::XController > (); +} + +void SAL_CALL ChartModel::impl_notifyCloseListeners() + throw( uno::RuntimeException) +{ + ::cppu::OInterfaceContainerHelper* pIC = m_aLifeTimeManager.m_aListenerContainer + .getContainer( ::getCppuType((const uno::Reference< util::XCloseListener >*)0) ); + if( pIC ) + { + lang::EventObject aEvent( static_cast< lang::XComponent*>(this) ); + ::cppu::OInterfaceIteratorHelper aIt( *pIC ); + while( aIt.hasMoreElements() ) + { + uno::Reference< util::XCloseListener > xListener( aIt.next(), uno::UNO_QUERY ); + if( xListener.is() ) + xListener->notifyClosing( aEvent ); + } + } +} + +void ChartModel::impl_adjustAdditionalShapesPositionAndSize( const awt::Size& aVisualAreaSize ) +{ + uno::Reference< beans::XPropertySet > xProperties( static_cast< ::cppu::OWeakObject* >( this ), uno::UNO_QUERY ); + if ( xProperties.is() ) + { + uno::Reference< drawing::XShapes > xShapes; + xProperties->getPropertyValue( C2U( "AdditionalShapes" ) ) >>= xShapes; + if ( xShapes.is() ) + { + sal_Int32 nCount = xShapes->getCount(); + for ( sal_Int32 i = 0; i < nCount; ++i ) + { + Reference< drawing::XShape > xShape; + if ( xShapes->getByIndex( i ) >>= xShape ) + { + if ( xShape.is() ) + { + awt::Point aPos( xShape->getPosition() ); + awt::Size aSize( xShape->getSize() ); + + double fWidth = static_cast< double >( aVisualAreaSize.Width ) / m_aVisualAreaSize.Width; + double fHeight = static_cast< double >( aVisualAreaSize.Height ) / m_aVisualAreaSize.Height; + + aPos.X = static_cast< long >( aPos.X * fWidth ); + aPos.Y = static_cast< long >( aPos.Y * fHeight ); + aSize.Width = static_cast< long >( aSize.Width * fWidth ); + aSize.Height = static_cast< long >( aSize.Height * fHeight ); + + xShape->setPosition( aPos ); + xShape->setSize( aSize ); + } + } + } + } + } +} + +//----------------------------------------------------------------- +// lang::XServiceInfo +//----------------------------------------------------------------- + +APPHELPER_XSERVICEINFO_IMPL(ChartModel,CHART_MODEL_SERVICE_IMPLEMENTATION_NAME) + +uno::Sequence< rtl::OUString > ChartModel::getSupportedServiceNames_Static() +{ + uno::Sequence< rtl::OUString > aSNS( 3 ); + aSNS[0] = CHART_MODEL_SERVICE_NAME; + aSNS[1] = C2U( "com.sun.star.document.OfficeDocument" ); + aSNS[2] = C2U( "com.sun.star.chart.ChartDocument" ); + //// @todo : add additional services if you support any further + return aSNS; +} + +//----------------------------------------------------------------- +// frame::XModel (required interface) +//----------------------------------------------------------------- + +sal_Bool SAL_CALL ChartModel::attachResource( const ::rtl::OUString& rURL + , const uno::Sequence< beans::PropertyValue >& rMediaDescriptor ) + throw(uno::RuntimeException) +{ + /* + The method attachResource() is used by the frame loader implementations + to inform the model about its URL and MediaDescriptor. + */ + + LifeTimeGuard aGuard(m_aLifeTimeManager); + if(!aGuard.startApiCall()) + return sal_False; //behave passive if already disposed or closed or throw exception @todo? + //mutex is acquired + + if(m_aResource.getLength()!=0)//we have a resource already //@todo? or is setting a new resource allowed? + return sal_False; + m_aResource = rURL; + m_aMediaDescriptor = rMediaDescriptor; + + //@todo ? check rURL ?? + //@todo ? evaluate m_aMediaDescriptor; + //@todo ? ... ??? --> nothing, this method is only for setting informations + + return sal_True; +} + +::rtl::OUString SAL_CALL ChartModel::getURL() throw(uno::RuntimeException) +{ + return impl_g_getLocation(); +} + +uno::Sequence< beans::PropertyValue > SAL_CALL ChartModel::getArgs() throw(uno::RuntimeException) +{ + /* + The method getArgs() returns a sequence of property values + that report the resource description according to com.sun.star.document.MediaDescriptor, + specified on loading or saving with storeAsURL. + */ + + LifeTimeGuard aGuard(m_aLifeTimeManager); + if(!aGuard.startApiCall()) + return uno::Sequence< beans::PropertyValue >(); //behave passive if already disposed or closed or throw exception @todo? + //mutex is acquired + + return m_aMediaDescriptor; +} + +void SAL_CALL ChartModel::connectController( const uno::Reference< frame::XController >& xController ) + throw(uno::RuntimeException) +{ + //@todo? this method is declared as oneway -> ...? + + LifeTimeGuard aGuard(m_aLifeTimeManager); + if(!aGuard.startApiCall()) + return ; //behave passive if already disposed or closed + //mutex is acquired + + //--add controller + m_aControllers.addInterface(xController); +} + +void SAL_CALL ChartModel::disconnectController( const uno::Reference< frame::XController >& xController ) + throw(uno::RuntimeException) +{ + //@todo? this method is declared as oneway -> ...? + + LifeTimeGuard aGuard(m_aLifeTimeManager); + if(!aGuard.startApiCall()) + return; //behave passive if already disposed or closed + + //--remove controller + m_aControllers.removeInterface(xController); + + //case: current controller is disconnected: + if( m_xCurrentController == xController ) + m_xCurrentController.clear(); + + DisposeHelper::DisposeAndClear( m_xRangeHighlighter ); +} + +void SAL_CALL ChartModel::lockControllers() throw(uno::RuntimeException) +{ + /* + suspends some notifications to the controllers which are used for display updates. + + The calls to lockControllers() and unlockControllers() may be nested + and even overlapping, but they must be in pairs. While there is at least one lock + remaining, some notifications for display updates are not broadcasted. + */ + + //@todo? this method is declared as oneway -> ...? + + LifeTimeGuard aGuard(m_aLifeTimeManager); + if(!aGuard.startApiCall()) + return; //behave passive if already disposed or closed or throw exception @todo? + ++m_nControllerLockCount; +} + +void SAL_CALL ChartModel::unlockControllers() throw(uno::RuntimeException) +{ + /* + resumes the notifications which were suspended by lockControllers() . + + The calls to lockControllers() and unlockControllers() may be nested + and even overlapping, but they must be in pairs. While there is at least one lock + remaining, some notifications for display updates are not broadcasted. + */ + + //@todo? this method is declared as oneway -> ...? + + LifeTimeGuard aGuard(m_aLifeTimeManager); + if(!aGuard.startApiCall()) + return; //behave passive if already disposed or closed or throw exception @todo? + if( m_nControllerLockCount == 0 ) + { + OSL_TRACE( "ChartModel: unlockControllers called with m_nControllerLockCount == 0" ); + return; + } + --m_nControllerLockCount; + if( m_nControllerLockCount == 0 && m_bUpdateNotificationsPending ) + { + aGuard.clear(); + impl_notifyModifiedListeners(); + } +} + +sal_Bool SAL_CALL ChartModel::hasControllersLocked() throw(uno::RuntimeException) +{ + LifeTimeGuard aGuard(m_aLifeTimeManager); + if(!aGuard.startApiCall()) + return sal_False; //behave passive if already disposed or closed or throw exception @todo? + return ( m_nControllerLockCount != 0 ) ; +} + +uno::Reference< frame::XController > SAL_CALL ChartModel::getCurrentController() throw(uno::RuntimeException) +{ + LifeTimeGuard aGuard(m_aLifeTimeManager); + if(!aGuard.startApiCall()) + throw lang::DisposedException(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "getCurrentController was called on an already disposed or closed model" ) ) + , static_cast< ::cppu::OWeakObject* >(this)); + + return impl_getCurrentController(); +} + +void SAL_CALL ChartModel::setCurrentController( const uno::Reference< frame::XController >& xController ) + throw(container::NoSuchElementException, uno::RuntimeException) +{ + LifeTimeGuard aGuard(m_aLifeTimeManager); + if(!aGuard.startApiCall()) + throw lang::DisposedException(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "setCurrentController was called on an already disposed or closed model" ) ) + , static_cast< ::cppu::OWeakObject* >(this)); + + //OSL_ENSURE( impl_isControllerConnected(xController), "setCurrentController is called with a Controller which is not connected" ); + if(!impl_isControllerConnected(xController)) + throw container::NoSuchElementException(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "setCurrentController is called with a Controller which is not connected" ) ) + , static_cast< ::cppu::OWeakObject* >(this)); + + m_xCurrentController = xController; + + DisposeHelper::DisposeAndClear( m_xRangeHighlighter ); +} + +uno::Reference< uno::XInterface > SAL_CALL ChartModel::getCurrentSelection() throw(uno::RuntimeException) +{ + LifeTimeGuard aGuard(m_aLifeTimeManager); + if(!aGuard.startApiCall()) + throw lang::DisposedException(::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "getCurrentSelection was called on an already disposed or closed model" ) ) + , static_cast< ::cppu::OWeakObject* >(this)); + + + uno::Reference< uno::XInterface > xReturn; + uno::Reference< frame::XController > xController = impl_getCurrentController(); + + aGuard.clear(); + if( xController.is() ) + { + uno::Reference< view::XSelectionSupplier > xSelectionSupl( xController, uno::UNO_QUERY ); + if ( xSelectionSupl.is() ) + { + uno::Any aSel = xSelectionSupl->getSelection(); + rtl::OUString aObjectCID; + if( aSel >>= aObjectCID ) + { + xReturn.set( ObjectIdentifier::getObjectPropertySet( aObjectCID, Reference< XChartDocument >(this))); + } + } + } + return xReturn; +} + + +//----------------------------------------------------------------- +// lang::XComponent (base of XModel) +//----------------------------------------------------------------- +void SAL_CALL ChartModel::dispose() throw(uno::RuntimeException) +{ + //This object should release all resources and references in the + //easiest possible manner + //This object must notify all registered listeners using the method + //<member>XEventListener::disposing</member> + + //hold no mutex + if( !m_aLifeTimeManager.dispose() ) + return; + + //--release all resources and references + //// @todo + + m_xDataProvider.clear(); + m_xInternalDataProvider.clear(); + m_xNumberFormatsSupplier.clear(); + DisposeHelper::DisposeAndClear( m_xOwnNumberFormatsSupplier ); + DisposeHelper::DisposeAndClear( m_xChartTypeManager ); + DisposeHelper::DisposeAndClear( m_xDiagram ); + DisposeHelper::DisposeAndClear( m_xTitle ); + DisposeHelper::DisposeAndClear( m_xPageBackground ); + DisposeHelper::DisposeAndClear( m_xXMLNamespaceMap ); + + // not owner of storage +// if( m_xStorage.is()) +// { +// Reference< lang::XComponent > xComp( m_xStorage, uno::UNO_QUERY ); +// if( xComp.is()) +// xComp->dispose(); +// } + m_xStorage.clear(); + + if( m_xOldModelAgg.is()) + { + m_xOldModelAgg->setDelegator( 0 ); + m_xOldModelAgg.clear(); + } + + m_aControllers.disposeAndClear( lang::EventObject( static_cast< cppu::OWeakObject * >( this ))); + m_xCurrentController.clear(); + + m_xStorage.clear(); + m_xParent.clear(); + DisposeHelper::DisposeAndClear( m_xRangeHighlighter ); + OSL_TRACE( "ChartModel: dispose() called" ); +} + +void SAL_CALL ChartModel::addEventListener( const uno::Reference< lang::XEventListener > & xListener ) + throw(uno::RuntimeException) +{ + if( m_aLifeTimeManager.impl_isDisposedOrClosed() ) + return; //behave passive if already disposed or closed + + m_aLifeTimeManager.m_aListenerContainer.addInterface( ::getCppuType((const uno::Reference< lang::XEventListener >*)0), xListener ); +} + +void SAL_CALL ChartModel::removeEventListener( const uno::Reference< lang::XEventListener > & xListener ) + throw(uno::RuntimeException) +{ + if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) ) + return; //behave passive if already disposed or closed + + m_aLifeTimeManager.m_aListenerContainer.removeInterface( ::getCppuType((const uno::Reference< lang::XEventListener >*)0), xListener ); + return; +} + +//----------------------------------------------------------------- +// util::XCloseBroadcaster (base of XCloseable) +//----------------------------------------------------------------- +void SAL_CALL ChartModel::addCloseListener( const uno::Reference< util::XCloseListener > & xListener ) + throw(uno::RuntimeException) +{ + m_aLifeTimeManager.g_addCloseListener( xListener ); +} + +void SAL_CALL ChartModel::removeCloseListener( const uno::Reference< util::XCloseListener > & xListener ) + throw(uno::RuntimeException) +{ + if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) ) + return; //behave passive if already disposed or closed + + m_aLifeTimeManager.m_aListenerContainer.removeInterface( ::getCppuType((const uno::Reference< util::XCloseListener >*)0), xListener ); + return; +} + +//----------------------------------------------------------------- +// util::XCloseable +//----------------------------------------------------------------- +void SAL_CALL ChartModel::close( sal_Bool bDeliverOwnership ) + throw( util::CloseVetoException, + uno::RuntimeException ) +{ + //hold no mutex + + if( !m_aLifeTimeManager.g_close_startTryClose( bDeliverOwnership ) ) + return; + //no mutex is acquired + + // At the end of this method may we must dispose ourself ... + // and may nobody from outside hold a reference to us ... + // then it's a good idea to do that by ourself. + uno::Reference< uno::XInterface > xSelfHold( static_cast< ::cppu::OWeakObject* >(this) ); + + //the listeners have had no veto + //check wether we self can close + { + util::CloseVetoException aVetoException = util::CloseVetoException( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( + "the model itself could not be closed" ) ) + , static_cast< ::cppu::OWeakObject* >(this)); + + if( m_aLifeTimeManager.g_close_isNeedToCancelLongLastingCalls( bDeliverOwnership, aVetoException ) ) + { + ////you can empty this block, if you never start longlasting calls or + ////if your longlasting calls are per default not cancelable (check how you have constructed your LifeTimeManager) + + sal_Bool bLongLastingCallsAreCanceled = sal_False; + try + { + //try to cancel running longlasting calls + //// @todo + } + catch( uno::Exception ) + { + //// @todo + //do not throw anything here!! (without endTryClose) + } + //if not successful canceled + if(!bLongLastingCallsAreCanceled) + { + m_aLifeTimeManager.g_close_endTryClose( bDeliverOwnership, sal_True ); + throw aVetoException; + } + } + + } + m_aLifeTimeManager.g_close_endTryClose_doClose(); + + // BM @todo: is it ok to call the listeners here? + impl_notifyCloseListeners(); +} + +//----------------------------------------------------------------- +// lang::XTypeProvider +//----------------------------------------------------------------- +uno::Sequence< uno::Type > SAL_CALL ChartModel::getTypes() + throw (uno::RuntimeException) +{ + uno::Reference< lang::XTypeProvider > xAggTypeProvider; + if( (m_xOldModelAgg->queryAggregation( ::getCppuType( & xAggTypeProvider )) >>= xAggTypeProvider) + && xAggTypeProvider.is()) + { + uno::Sequence< uno::Type > aOwnTypes( impl::ChartModel_Base::getTypes()); + uno::Sequence< uno::Type > aAggTypes( xAggTypeProvider->getTypes()); + uno::Sequence< uno::Type > aResult( aOwnTypes.getLength() + aAggTypes.getLength()); + sal_Int32 i=0; + for( ;i<aOwnTypes.getLength(); ++i ) + aResult[i] = aOwnTypes[i]; + for( sal_Int32 j=0; i<aResult.getLength(); ++j, ++i) + aResult[i] = aAggTypes[j]; + return aResult; + } + + return impl::ChartModel_Base::getTypes(); +} + +//----------------------------------------------------------------- +// document::XDocumentPropertiesSupplier +//----------------------------------------------------------------- +uno::Reference< document::XDocumentProperties > SAL_CALL + ChartModel::getDocumentProperties() throw (uno::RuntimeException) +{ + if ( !m_xDocumentProperties.is() ) + { + uno::Reference< document::XDocumentProperties > xDocProps( + ::comphelper::getProcessServiceFactory()->createInstance( + C2U("com.sun.star.document.DocumentProperties") ), uno::UNO_QUERY ); + m_xDocumentProperties.set(xDocProps); + } + return m_xDocumentProperties; +} + +//----------------------------------------------------------------- +// chart2::XChartDocument +//----------------------------------------------------------------- + +uno::Reference< chart2::XDiagram > SAL_CALL ChartModel::getFirstDiagram() + throw (uno::RuntimeException) +{ + MutexGuard aGuard( m_aModelMutex ); + return m_xDiagram; +} + +void SAL_CALL ChartModel::setFirstDiagram( const uno::Reference< chart2::XDiagram >& xDiagram ) + throw (uno::RuntimeException) +{ + Reference< chart2::XDiagram > xOldDiagram; + Reference< util::XModifyListener > xListener; + { + MutexGuard aGuard( m_aModelMutex ); + if( xDiagram == m_xDiagram ) + return; + xOldDiagram = m_xDiagram; + m_xDiagram = xDiagram; + xListener = this; + } + //don't keep the mutex locked while calling out + ModifyListenerHelper::removeListener( xOldDiagram, xListener ); + ModifyListenerHelper::addListener( xDiagram, xListener ); + setModified( sal_True ); +} + +Reference< chart2::data::XDataSource > ChartModel::impl_createDefaultData() +{ + Reference< chart2::data::XDataSource > xDataSource; + if( hasInternalDataProvider() ) + { + uno::Reference< lang::XInitialization > xIni(m_xInternalDataProvider,uno::UNO_QUERY); + if( xIni.is() ) + { + //init internal dataprovider + { + uno::Sequence< uno::Any > aArgs(1); + beans::NamedValue aParam(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CreateDefaultData")),uno::makeAny(sal_True)); + aArgs[0] <<= aParam; + xIni->initialize(aArgs); + } + //create data + uno::Sequence< beans::PropertyValue > aArgs( 4 ); + aArgs[0] = beans::PropertyValue( + ::rtl::OUString::createFromAscii("CellRangeRepresentation"), -1, + uno::makeAny( C2U("all") ), beans::PropertyState_DIRECT_VALUE ); + aArgs[1] = beans::PropertyValue( + ::rtl::OUString::createFromAscii("HasCategories"), -1, + uno::makeAny( true ), beans::PropertyState_DIRECT_VALUE ); + aArgs[2] = beans::PropertyValue( + ::rtl::OUString::createFromAscii("FirstCellAsLabel"), -1, + uno::makeAny( true ), beans::PropertyState_DIRECT_VALUE ); + aArgs[3] = beans::PropertyValue( + ::rtl::OUString::createFromAscii("DataRowSource"), -1, + uno::makeAny( ::com::sun::star::chart::ChartDataRowSource_COLUMNS ), beans::PropertyState_DIRECT_VALUE ); + xDataSource = m_xInternalDataProvider->createDataSource( aArgs ); + } + } + return xDataSource; +} + +void SAL_CALL ChartModel::createInternalDataProvider( sal_Bool bCloneExistingData ) + throw (util::CloseVetoException, uno::RuntimeException) +{ + // don't lock the mutex, because this call calls out to code that tries to + // lock the solar mutex. On the other hand, a paint locks the solar mutex + // and calls to the model lock the model's mutex => deadlock + // @todo: lock a separate mutex in the InternalData class + if( !hasInternalDataProvider() ) + { + if( bCloneExistingData ) + m_xInternalDataProvider = ChartModelHelper::createInternalDataProvider( this, true ); + else + m_xInternalDataProvider = ChartModelHelper::createInternalDataProvider( Reference<XChartDocument>(), true ); + m_xDataProvider.set( m_xInternalDataProvider ); + } + setModified( sal_True ); +} + +sal_Bool SAL_CALL ChartModel::hasInternalDataProvider() + throw (uno::RuntimeException) +{ + return m_xDataProvider.is() && m_xInternalDataProvider.is(); +} + +uno::Reference< chart2::data::XDataProvider > SAL_CALL ChartModel::getDataProvider() + throw (uno::RuntimeException) +{ + // /-- + MutexGuard aGuard( m_aModelMutex ); + return m_xDataProvider; + // \-- +} + +// ____ XDataReceiver ____ + +void SAL_CALL ChartModel::attachDataProvider( const uno::Reference< chart2::data::XDataProvider >& xDataProvider ) + throw (uno::RuntimeException) +{ + { + // /-- + MutexGuard aGuard( m_aModelMutex ); + uno::Reference< beans::XPropertySet > xProp( xDataProvider, uno::UNO_QUERY ); + if( xProp.is() ) + { + try + { + sal_Bool bIncludeHiddenCells = ChartModelHelper::isIncludeHiddenCells( Reference< frame::XModel >(this) ); + xProp->setPropertyValue(C2U("IncludeHiddenCells"), uno::makeAny(bIncludeHiddenCells)); + } + catch( const beans::UnknownPropertyException& ) + { + } + } + + m_xDataProvider.set( xDataProvider ); + m_xInternalDataProvider.clear(); + + //the numberformatter is kept independent of the data provider! + // \-- + } + setModified( sal_True ); +} + +void SAL_CALL ChartModel::attachNumberFormatsSupplier( const uno::Reference< util::XNumberFormatsSupplier >& xNewSupplier ) + throw (uno::RuntimeException) +{ + { + // /-- + MutexGuard aGuard( m_aModelMutex ); + if( xNewSupplier==m_xNumberFormatsSupplier ) + return; + if( xNewSupplier==m_xOwnNumberFormatsSupplier ) + return; + if( m_xOwnNumberFormatsSupplier.is() && xNewSupplier.is() ) + { + //@todo + //merge missing numberformats from own to new formatter + } + else if( !xNewSupplier.is() ) + { + if( m_xNumberFormatsSupplier.is() ) + { + //@todo + //merge missing numberformats from old numberformatter to own numberformatter + //create own numberformatter if necessary + } + } + + m_xNumberFormatsSupplier.set( xNewSupplier ); + m_xOwnNumberFormatsSupplier.clear(); + // \-- + } + setModified( sal_True ); +} + +void SAL_CALL ChartModel::setArguments( const Sequence< beans::PropertyValue >& aArguments ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + { + // /-- + MutexGuard aGuard( m_aModelMutex ); + if( !m_xDataProvider.is() ) + return; + lockControllers(); + + try + { + Reference< chart2::data::XDataSource > xDataSource( m_xDataProvider->createDataSource( aArguments ) ); + if( xDataSource.is() ) + { + // set new data + Reference< chart2::XChartTypeTemplate > xTemplate; + Reference< chart2::XDiagram > xDia( getFirstDiagram() ); + if( xDia.is()) + { + // apply new data + DiagramHelper::tTemplateWithServiceName aTemplateAndService = + DiagramHelper::getTemplateForDiagram( + xDia, Reference< lang::XMultiServiceFactory >( m_xChartTypeManager, uno::UNO_QUERY )); + xTemplate.set( aTemplateAndService.first ); + } + + if( !xTemplate.is()) + xTemplate.set( impl_createDefaultChartTypeTemplate() ); + + if( xTemplate.is()) + { + if( xDia.is()) + xTemplate->changeDiagramData( xDia, xDataSource, aArguments ); + else + setFirstDiagram( xTemplate->createDiagramByDataSource( xDataSource, aArguments ) ); + } + } + } + catch( lang::IllegalArgumentException & ) + { + throw; + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + unlockControllers(); + // \-- + } + setModified( sal_True ); +} + +Sequence< OUString > SAL_CALL ChartModel::getUsedRangeRepresentations() + throw (uno::RuntimeException) +{ + return DataSourceHelper::getUsedDataRanges( Reference< frame::XModel >(this)); +} + +Reference< chart2::data::XDataSource > SAL_CALL ChartModel::getUsedData() + throw (uno::RuntimeException) +{ + return DataSourceHelper::getUsedData( Reference< chart2::XChartDocument >(this)); +} + +Reference< chart2::data::XRangeHighlighter > SAL_CALL ChartModel::getRangeHighlighter() + throw (uno::RuntimeException) +{ + if( ! m_xRangeHighlighter.is()) + { + uno::Reference< view::XSelectionSupplier > xSelSupp( this->getCurrentController(), uno::UNO_QUERY ); + if( xSelSupp.is() ) + m_xRangeHighlighter.set( ChartModelHelper::createRangeHighlighter( xSelSupp )); + } + return m_xRangeHighlighter; +} + +Reference< chart2::XChartTypeTemplate > ChartModel::impl_createDefaultChartTypeTemplate() +{ + Reference< chart2::XChartTypeTemplate > xTemplate; + Reference< lang::XMultiServiceFactory > xFact( m_xChartTypeManager, uno::UNO_QUERY ); + if( xFact.is() ) + xTemplate.set( xFact->createInstance( C2U( "com.sun.star.chart2.template.Column" ) ), uno::UNO_QUERY ); + return xTemplate; +} + +void SAL_CALL ChartModel::setChartTypeManager( const uno::Reference< chart2::XChartTypeManager >& xNewManager ) + throw (uno::RuntimeException) +{ + { + // /-- + MutexGuard aGuard( m_aModelMutex ); + m_xChartTypeManager = xNewManager; + // \-- + } + setModified( sal_True ); +} + +uno::Reference< chart2::XChartTypeManager > SAL_CALL ChartModel::getChartTypeManager() + throw (uno::RuntimeException) +{ + // /-- + MutexGuard aGuard( m_aModelMutex ); + return m_xChartTypeManager; + // \-- +} + +uno::Reference< beans::XPropertySet > SAL_CALL ChartModel::getPageBackground() + throw (uno::RuntimeException) +{ + // /-- + MutexGuard aGuard( m_aModelMutex ); + return m_xPageBackground; + // \-- +} + +// ____ XTitled ____ +uno::Reference< chart2::XTitle > SAL_CALL ChartModel::getTitleObject() + throw (uno::RuntimeException) +{ + // /-- + MutexGuard aGuard( m_aModelMutex ); + return m_xTitle; + // \-- +} + +void SAL_CALL ChartModel::setTitleObject( const uno::Reference< chart2::XTitle >& xTitle ) + throw (uno::RuntimeException) +{ + { + // /-- + MutexGuard aGuard( m_aModelMutex ); + if( m_xTitle.is() ) + ModifyListenerHelper::removeListener( m_xTitle, this ); + m_xTitle = xTitle; + ModifyListenerHelper::addListener( m_xTitle, this ); + // \-- + } + setModified( sal_True ); +} + +void ChartModel::impl_createOldModelAgg() +{ + if( ! m_xOldModelAgg.is()) + { + m_xOldModelAgg.set( + m_xContext->getServiceManager()->createInstanceWithContext( + CHART_CHARTAPIWRAPPER_SERVICE_NAME, + m_xContext ), uno::UNO_QUERY_THROW ); + m_xOldModelAgg->setDelegator( static_cast< ::cppu::OWeakObject* >( this )); + } +} + +// ____ XInterface (for old API wrapper) ____ +uno::Any SAL_CALL ChartModel::queryInterface( const uno::Type& aType ) + throw (uno::RuntimeException) +{ + uno::Any aResult( impl::ChartModel_Base::queryInterface( aType )); + + if( ! aResult.hasValue()) + { + // try old API wrapper + try + { + impl_createOldModelAgg(); + if( m_xOldModelAgg.is()) + aResult = m_xOldModelAgg->queryAggregation( aType ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + + return aResult; +} + +// ____ XCloneable ____ +Reference< util::XCloneable > SAL_CALL ChartModel::createClone() + throw (uno::RuntimeException) +{ + return Reference< util::XCloneable >( new ChartModel( *this )); +} + +// ____ XVisualObject ____ +void SAL_CALL ChartModel::setVisualAreaSize( ::sal_Int64 nAspect, const awt::Size& aSize ) + throw (lang::IllegalArgumentException, + embed::WrongStateException, + uno::Exception, + uno::RuntimeException) +{ + if( nAspect == embed::Aspects::MSOLE_CONTENT ) + { + ControllerLockGuard aLockGuard( this ); + bool bChanged = + (m_aVisualAreaSize.Width != aSize.Width || + m_aVisualAreaSize.Height != aSize.Height); + + // #i12587# support for shapes in chart + if ( bChanged ) + { + impl_adjustAdditionalShapesPositionAndSize( aSize ); + } + + m_aVisualAreaSize = aSize; + if( bChanged ) + setModified( sal_True ); + } + else + { + OSL_ENSURE( false, "setVisualAreaSize: Aspect not implemented yet."); + } +} + +awt::Size SAL_CALL ChartModel::getVisualAreaSize( ::sal_Int64 nAspect ) + throw (lang::IllegalArgumentException, + embed::WrongStateException, + uno::Exception, + uno::RuntimeException) +{ + OSL_ENSURE( nAspect == embed::Aspects::MSOLE_CONTENT, + "No aspects other than content are supported" ); + (void)(nAspect); // avoid warning in non-debug builds + // other possible aspects are MSOLE_THUMBNAIL, MSOLE_ICON and MSOLE_DOCPRINT + + return m_aVisualAreaSize; +} + +embed::VisualRepresentation SAL_CALL ChartModel::getPreferredVisualRepresentation( ::sal_Int64 nAspect ) + throw (lang::IllegalArgumentException, + embed::WrongStateException, + uno::Exception, + uno::RuntimeException) +{ + OSL_ENSURE( nAspect == embed::Aspects::MSOLE_CONTENT, + "No aspects other than content are supported" ); + (void)(nAspect); // avoid warning in non-debug builds + + embed::VisualRepresentation aResult; + + try + { + Sequence< sal_Int8 > aMetafile; + + //get view from old api wrapper + Reference< datatransfer::XTransferable > xTransferable( + this->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY ); + if( xTransferable.is() ) + { + datatransfer::DataFlavor aDataFlavor( lcl_aGDIMetaFileMIMEType, + C2U( "GDIMetaFile" ), + ::getCppuType( (const uno::Sequence< sal_Int8 >*) 0 ) ); + + uno::Any aData( xTransferable->getTransferData( aDataFlavor ) ); + aData >>= aMetafile; + } + + aResult.Flavor.MimeType = lcl_aGDIMetaFileMIMEType; + aResult.Flavor.DataType = getCppuType( &aMetafile ); + + aResult.Data <<= aMetafile; + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + return aResult; +} + +::sal_Int32 SAL_CALL ChartModel::getMapUnit( ::sal_Int64 nAspect ) + throw (uno::Exception, + uno::RuntimeException) +{ + OSL_ENSURE( nAspect == embed::Aspects::MSOLE_CONTENT, + "No aspects other than content are supported" ); + (void)(nAspect); // avoid warning in non-debug builds + return embed::EmbedMapUnits::ONE_100TH_MM; +} + +// ____ datatransfer::XTransferable ____ +uno::Any SAL_CALL ChartModel::getTransferData( const datatransfer::DataFlavor& aFlavor ) + throw (datatransfer::UnsupportedFlavorException, + io::IOException, + uno::RuntimeException) +{ + uno::Any aResult; + if( this->isDataFlavorSupported( aFlavor )) + { + try + { + //get view from old api wrapper + Reference< datatransfer::XTransferable > xTransferable( + this->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY ); + if( xTransferable.is() && + xTransferable->isDataFlavorSupported( aFlavor )) + { + aResult = xTransferable->getTransferData( aFlavor ); + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + else + { + throw datatransfer::UnsupportedFlavorException( + aFlavor.MimeType, static_cast< ::cppu::OWeakObject* >( this )); + } + + return aResult; +} + +Sequence< datatransfer::DataFlavor > SAL_CALL ChartModel::getTransferDataFlavors() + throw (uno::RuntimeException) +{ + uno::Sequence< datatransfer::DataFlavor > aRet(1); + +// aRet[0] = datatransfer::DataFlavor( lcl_aGDIMetaFileMIMEType, +// C2U( "GDIMetaFile" ), +// ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) ); + aRet[0] = datatransfer::DataFlavor( lcl_aGDIMetaFileMIMETypeHighContrast, + C2U( "GDIMetaFile" ), + ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) ); + + return aRet; +} + +::sal_Bool SAL_CALL ChartModel::isDataFlavorSupported( const datatransfer::DataFlavor& aFlavor ) + throw (uno::RuntimeException) +{ +// return ( aFlavor.MimeType.equals(lcl_aGDIMetaFileMIMEType) || +// aFlavor.MimeType.equals(lcl_aGDIMetaFileMIMETypeHighContrast) ); + return aFlavor.MimeType.equals(lcl_aGDIMetaFileMIMETypeHighContrast); +} + + + +namespace +{ +enum eServiceType +{ + SERVICE_DASH_TABLE, + SERVICE_GARDIENT_TABLE, + SERVICE_HATCH_TABLE, + SERVICE_BITMAP_TABLE, + SERVICE_TRANSP_GRADIENT_TABLE, + SERVICE_MARKER_TABLE, + SERVICE_NAMESPACE_MAP +}; + +typedef ::std::map< ::rtl::OUString, enum eServiceType > tServiceNameMap; +typedef ::comphelper::MakeMap< ::rtl::OUString, enum eServiceType > tMakeServiceNameMap; + +tServiceNameMap & lcl_getStaticServiceNameMap() +{ + static tServiceNameMap aServiceNameMap( + tMakeServiceNameMap + ( C2U( "com.sun.star.drawing.DashTable" ), SERVICE_DASH_TABLE ) + ( C2U( "com.sun.star.drawing.GradientTable" ), SERVICE_GARDIENT_TABLE ) + ( C2U( "com.sun.star.drawing.HatchTable" ), SERVICE_HATCH_TABLE ) + ( C2U( "com.sun.star.drawing.BitmapTable" ), SERVICE_BITMAP_TABLE ) + ( C2U( "com.sun.star.drawing.TransparencyGradientTable" ), SERVICE_TRANSP_GRADIENT_TABLE ) + ( C2U( "com.sun.star.drawing.MarkerTable" ), SERVICE_MARKER_TABLE ) + ( C2U( "com.sun.star.xml.NamespaceMap" ), SERVICE_NAMESPACE_MAP ) + ); + return aServiceNameMap; +} +} +// ____ XMultiServiceFactory ____ +Reference< uno::XInterface > SAL_CALL ChartModel::createInstance( const OUString& rServiceSpecifier ) + throw( uno::Exception, uno::RuntimeException ) +{ + uno::Reference< uno::XInterface > xResult; + tServiceNameMap & rMap = lcl_getStaticServiceNameMap(); + + tServiceNameMap::const_iterator aIt( rMap.find( rServiceSpecifier )); + if( aIt != rMap.end()) + { + switch( (*aIt).second ) + { + case SERVICE_DASH_TABLE: + case SERVICE_GARDIENT_TABLE: + case SERVICE_HATCH_TABLE: + case SERVICE_BITMAP_TABLE: + case SERVICE_TRANSP_GRADIENT_TABLE: + case SERVICE_MARKER_TABLE: + { + uno::Reference< lang::XMultiServiceFactory > xFact( + this->createInstance( CHART_VIEW_SERVICE_NAME ), uno::UNO_QUERY ); + if ( xFact.is() ) + { + return xFact->createInstance( rServiceSpecifier ); + } + } + break; + case SERVICE_NAMESPACE_MAP: + return Reference< uno::XInterface >( m_xXMLNamespaceMap ); + } + } + else + { + impl_createOldModelAgg(); + if( m_xOldModelAgg.is() ) + { + Any aAny = m_xOldModelAgg->queryAggregation( ::getCppuType((const uno::Reference< lang::XMultiServiceFactory >*)0) ); + uno::Reference< lang::XMultiServiceFactory > xOldModelFactory; + if( (aAny >>= xOldModelFactory) && xOldModelFactory.is() ) + { + return xOldModelFactory->createInstance( rServiceSpecifier ); + } + } + } + return 0; +} + +Reference< uno::XInterface > SAL_CALL ChartModel::createInstanceWithArguments( + const OUString& rServiceSpecifier , const Sequence< Any >& Arguments ) + throw( uno::Exception, uno::RuntimeException ) +{ + OSL_ENSURE( Arguments.getLength(), "createInstanceWithArguments: Warning: Arguments are ignored" ); + (void)(Arguments); // avoid warning in non-debug builds + return createInstance( rServiceSpecifier ); +} + +Sequence< OUString > SAL_CALL ChartModel::getAvailableServiceNames() + throw( uno::RuntimeException ) +{ + uno::Sequence< ::rtl::OUString > aResult; + + impl_createOldModelAgg(); + if( m_xOldModelAgg.is()) + { + Any aAny = m_xOldModelAgg->queryAggregation( ::getCppuType((const uno::Reference< lang::XMultiServiceFactory >*)0) ); + uno::Reference< lang::XMultiServiceFactory > xOldModelFactory; + if( (aAny >>= xOldModelFactory) && xOldModelFactory.is() ) + { + return xOldModelFactory->getAvailableServiceNames(); + } + } + return aResult; +} + +Reference< util::XNumberFormatsSupplier > ChartModel::impl_getNumberFormatsSupplier() +{ + if( !m_xNumberFormatsSupplier.is() ) + { + if( !m_xOwnNumberFormatsSupplier.is() ) + { + Reference< lang::XMultiServiceFactory > xFactory( m_xContext->getServiceManager(), uno::UNO_QUERY ); + m_xOwnNumberFormatsSupplier = new SvNumberFormatsSupplierObj( new SvNumberFormatter( xFactory, LANGUAGE_SYSTEM ) ); + //pOwnNumberFormatter->ChangeStandardPrec( 15 ); todo? + } + m_xNumberFormatsSupplier = m_xOwnNumberFormatsSupplier; + } + return m_xNumberFormatsSupplier; +} + +// ____ XUnoTunnel ___ +::sal_Int64 SAL_CALL ChartModel::getSomething( const Sequence< ::sal_Int8 >& aIdentifier ) + throw( uno::RuntimeException) +{ + if( aIdentifier.getLength() == 16 && 0 == rtl_compareMemory( SvNumberFormatsSupplierObj::getUnoTunnelId().getConstArray(), + aIdentifier.getConstArray(), 16 ) ) + { + Reference< lang::XUnoTunnel > xTunnel( impl_getNumberFormatsSupplier(), uno::UNO_QUERY ); + if( xTunnel.is() ) + return xTunnel->getSomething( aIdentifier ); + } + return 0; +} + +// ____ XNumberFormatsSupplier ____ +uno::Reference< beans::XPropertySet > SAL_CALL ChartModel::getNumberFormatSettings() + throw (uno::RuntimeException) +{ + Reference< util::XNumberFormatsSupplier > xSupplier( impl_getNumberFormatsSupplier() ); + if( xSupplier.is() ) + return xSupplier->getNumberFormatSettings(); + return uno::Reference< beans::XPropertySet >(); +} + +uno::Reference< util::XNumberFormats > SAL_CALL ChartModel::getNumberFormats() + throw (uno::RuntimeException) +{ + Reference< util::XNumberFormatsSupplier > xSupplier( impl_getNumberFormatsSupplier() ); + if( xSupplier.is() ) + return xSupplier->getNumberFormats(); + return uno::Reference< util::XNumberFormats >(); +} + +// ____ XChild ____ +Reference< uno::XInterface > SAL_CALL ChartModel::getParent() + throw (uno::RuntimeException) +{ + return Reference< uno::XInterface >(m_xParent,uno::UNO_QUERY); +} + +void SAL_CALL ChartModel::setParent( const Reference< uno::XInterface >& Parent ) + throw (lang::NoSupportException, + uno::RuntimeException) +{ + if( Parent != m_xParent ) + m_xParent.set( Parent, uno::UNO_QUERY ); +} + +// ____ XUndoManager ____ +Reference< chart2::XUndoManager > SAL_CALL ChartModel::getUndoManager() + throw (uno::RuntimeException) +{ + return m_xUndoManager; +} + +// ____ XDataSource ____ +uno::Sequence< Reference< chart2::data::XLabeledDataSequence > > SAL_CALL ChartModel::getDataSequences() + throw (uno::RuntimeException) +{ + Reference< chart2::data::XDataSource > xSource( + DataSourceHelper::getUsedData( uno::Reference< frame::XModel >(this) ) ); + if( xSource.is()) + return xSource->getDataSequences(); + + return uno::Sequence< Reference< chart2::data::XLabeledDataSequence > >(); +} + +} // namespace chart diff --git a/chart2/source/model/main/ChartModel.hxx b/chart2/source/model/main/ChartModel.hxx new file mode 100644 index 000000000000..23da02f3f83a --- /dev/null +++ b/chart2/source/model/main/ChartModel.hxx @@ -0,0 +1,609 @@ +/************************************************************************* + * + * 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_MODEL_HXX +#define _CHART_MODEL_HXX + +#include "LifeTime.hxx" +#include "ServiceMacros.hxx" + +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/frame/XStorable2.hpp> +#include <com/sun/star/util/XModifiable.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> +#include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/embed/XVisualObject.hpp> +#include <com/sun/star/document/XStorageBasedDocument.hpp> +#include <com/sun/star/lang/XUnoTunnel.hpp> +#include <com/sun/star/util/XNumberFormatsSupplier.hpp> +#include <com/sun/star/container/XChild.hpp> +#include <com/sun/star/chart2/XUndoSupplier.hpp> +#include <com/sun/star/chart2/data/XDataSource.hpp> +#include <com/sun/star/chart2/XChartTypeTemplate.hpp> +#include <com/sun/star/container/XNameContainer.hpp> + +// public API +#include <com/sun/star/chart2/data/XDataProvider.hpp> +#include <com/sun/star/chart2/data/XDataReceiver.hpp> + +#include <com/sun/star/chart2/XChartDocument.hpp> +#include <com/sun/star/chart2/XTitled.hpp> + +#include <com/sun/star/frame/XLoadable.hpp> +#include <com/sun/star/embed/XEmbeddedObject.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/datatransfer/XTransferable.hpp> + +#if ! defined(INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_20) +#define INCLUDED_COMPHELPER_IMPLBASE_VAR_HXX_20 +#define COMPHELPER_IMPLBASE_INTERFACE_NUMBER 20 +#include "comphelper/implbase_var.hxx" +#endif +#include <osl/mutex.hxx> +#include <cppuhelper/interfacecontainer.hxx> +#include <svtools/grfmgr.hxx> + +// for auto_ptr +#include <memory> + +//============================================================================= +/** this is an example implementation for the service ::com::sun::star::document::OfficeDocument +*/ + +namespace chart +{ + +namespace impl +{ + +// Note: needed for queryInterface (if it calls the base-class implementation) +typedef ::comphelper::WeakImplHelper20< +// ::com::sun::star::frame::XModel //comprehends XComponent (required interface), base of XChartDocument + ::com::sun::star::util::XCloseable //comprehends XCloseBroadcaster + ,::com::sun::star::frame::XStorable2 //(extension of XStorable) +// ,::com::sun::star::frame::XStorable //(required interface) base of XStorable2 + ,::com::sun::star::util::XModifiable //comprehends XModifyBroadcaster (required interface) + // ,::com::sun::star::uno::XWeak // implemented by WeakImplHelper(optional interface) + // ,::com::sun::star::uno::XInterface // implemented by WeakImplHelper(optional interface) + // ,::com::sun::star::lang::XTypeProvider // implemented by WeakImplHelper + ,::com::sun::star::lang::XServiceInfo + ,::com::sun::star::chart2::XChartDocument // derived from XModel + ,::com::sun::star::chart2::data::XDataReceiver // public API + ,::com::sun::star::chart2::XTitled + ,::com::sun::star::frame::XLoadable + ,::com::sun::star::util::XCloneable + ,::com::sun::star::embed::XVisualObject + ,::com::sun::star::lang::XMultiServiceFactory + ,::com::sun::star::document::XStorageBasedDocument + ,::com::sun::star::lang::XUnoTunnel + ,::com::sun::star::util::XNumberFormatsSupplier + ,::com::sun::star::container::XChild + ,::com::sun::star::util::XModifyListener + ,::com::sun::star::datatransfer::XTransferable + ,::com::sun::star::chart2::XUndoSupplier + ,::com::sun::star::document::XDocumentPropertiesSupplier + ,::com::sun::star::chart2::data::XDataSource + > + ChartModel_Base; +} + +class ChartModel : public impl::ChartModel_Base +{ + +private: + mutable ::apphelper::CloseableLifeTimeManager m_aLifeTimeManager; + + mutable ::osl::Mutex m_aModelMutex; + sal_Bool volatile m_bReadOnly; + sal_Bool volatile m_bModified; + sal_Int32 m_nInLoad; + sal_Bool volatile m_bUpdateNotificationsPending; + + ::rtl::OUString m_aResource; + ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aMediaDescriptor; + ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties > m_xDocumentProperties; + + ::cppu::OInterfaceContainerHelper m_aControllers; + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > m_xCurrentController; + sal_uInt16 m_nControllerLockCount; + +// ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > m_aPrinterOptions; + + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext; + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation > m_xOldModelAgg; + + ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > m_xStorage; + //the content of this should be always synchronized with the current m_xViewWindow size. The variable is necessary to hold the information as long as no view window exists. + ::com::sun::star::awt::Size m_aVisualAreaSize; + ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModel > m_xParent; + ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XRangeHighlighter > m_xRangeHighlighter; + ::std::vector< GraphicObject > m_aGraphicObjectVector; + + ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataProvider > m_xDataProvider; + /** is only valid if m_xDataProvider is set. If m_xDataProvider is set to an + external data provider this reference must be set to 0 + */ + ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataProvider > m_xInternalDataProvider; + + ::com::sun::star::uno::Reference< com::sun::star::util::XNumberFormatsSupplier > + m_xOwnNumberFormatsSupplier; + ::com::sun::star::uno::Reference< com::sun::star::util::XNumberFormatsSupplier > + m_xNumberFormatsSupplier; + + ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartTypeManager > + m_xChartTypeManager; + + // Diagram Access + ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram > + m_xDiagram; + + ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XTitle > + m_xTitle; + + bool m_bIsDisposed; + ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > + m_xPageBackground; + ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XUndoManager > + m_xUndoManager; + + ::com::sun::star::uno::Reference< ::com::sun::star::container::XNameAccess> m_xXMLNamespaceMap; + + ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xModifyListener; + +private: + //private methods + + ::rtl::OUString impl_g_getLocation(); + + sal_Bool + impl_isControllerConnected( const com::sun::star::uno::Reference< + com::sun::star::frame::XController >& xController ); + + com::sun::star::uno::Reference< com::sun::star::frame::XController > + impl_getCurrentController() + throw( com::sun::star::uno::RuntimeException); + + void SAL_CALL + impl_notifyModifiedListeners() + throw( com::sun::star::uno::RuntimeException); + void SAL_CALL + impl_notifyCloseListeners() + throw( com::sun::star::uno::RuntimeException); + void SAL_CALL + impl_notifyStorageChangeListeners() + throw(::com::sun::star::uno::RuntimeException); + + void impl_killInternalData() throw( com::sun::star::util::CloseVetoException ); + + void impl_createOldModelAgg(); + void impl_store( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue >& rMediaDescriptor, + const ::com::sun::star::uno::Reference< + ::com::sun::star::embed::XStorage > & xStorage ); + void impl_load( + const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue >& rMediaDescriptor, + const ::com::sun::star::uno::Reference< + ::com::sun::star::embed::XStorage >& xStorage ); + void impl_loadGraphics( + const ::com::sun::star::uno::Reference< + ::com::sun::star::embed::XStorage >& xStorage ); + ::com::sun::star::uno::Reference< + ::com::sun::star::document::XFilter > + impl_createFilter( const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue > & rMediaDescriptor ); + + ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartTypeTemplate > impl_createDefaultChartTypeTemplate(); + ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource > impl_createDefaultData(); + + void impl_adjustAdditionalShapesPositionAndSize( + const ::com::sun::star::awt::Size& aVisualAreaSize ); + + ::com::sun::star::uno::Reference< ::com::sun::star::util::XNumberFormatsSupplier > + impl_getNumberFormatsSupplier(); + +public: + //no default constructor + ChartModel(::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext); + explicit ChartModel( const ChartModel & rOther ); + virtual ~ChartModel(); + + //----------------------------------------------------------------- + // ::com::sun::star::lang::XServiceInfo + //----------------------------------------------------------------- + + APPHELPER_XSERVICEINFO_DECL() + APPHELPER_SERVICE_FACTORY_HELPER(ChartModel) + + //----------------------------------------------------------------- + // ::com::sun::star::frame::XModel (required interface) + //----------------------------------------------------------------- + + virtual sal_Bool SAL_CALL + attachResource( const ::rtl::OUString& rURL + , const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue >& rMediaDescriptor ) + throw (::com::sun::star::uno::RuntimeException); + + virtual ::rtl::OUString SAL_CALL + getURL() throw (::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue > SAL_CALL + getArgs() throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + connectController( const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XController >& xController ) + throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + disconnectController( const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XController >& xController ) + throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + lockControllers() throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + unlockControllers() throw (::com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + hasControllersLocked() + throw (::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::frame::XController > SAL_CALL + getCurrentController() + throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + setCurrentController( const ::com::sun::star::uno::Reference< + ::com::sun::star::frame::XController >& xController ) + throw (::com::sun::star::container::NoSuchElementException + , ::com::sun::star::uno::RuntimeException); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL + getCurrentSelection() + throw (::com::sun::star::uno::RuntimeException); + + + //----------------------------------------------------------------- + // ::com::sun::star::lang::XComponent (base of XModel) + //----------------------------------------------------------------- + virtual void SAL_CALL + dispose() throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + addEventListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XEventListener > & xListener ) + throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + removeEventListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::lang::XEventListener > & xListener ) + throw (::com::sun::star::uno::RuntimeException); + + //----------------------------------------------------------------- + // ::com::sun::star::util::XCloseable + //----------------------------------------------------------------- + virtual void SAL_CALL + close( sal_Bool bDeliverOwnership ) + throw(::com::sun::star::util::CloseVetoException, + ::com::sun::star::uno::RuntimeException); + + //----------------------------------------------------------------- + // ::com::sun::star::util::XCloseBroadcaster (base of XCloseable) + //----------------------------------------------------------------- + virtual void SAL_CALL + addCloseListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XCloseListener > & xListener ) + throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + removeCloseListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XCloseListener > & xListener ) + throw (::com::sun::star::uno::RuntimeException); + + //----------------------------------------------------------------- + // ::com::sun::star::frame::XStorable2 (extension of XStorable) + //----------------------------------------------------------------- + virtual void SAL_CALL storeSelf( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rMediaDescriptor ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::RuntimeException); + + //----------------------------------------------------------------- + // ::com::sun::star::frame::XStorable (required interface) + //----------------------------------------------------------------- + virtual sal_Bool SAL_CALL + hasLocation() throw (::com::sun::star::uno::RuntimeException); + + virtual ::rtl::OUString SAL_CALL + getLocation() throw (::com::sun::star::uno::RuntimeException); + + virtual sal_Bool SAL_CALL + isReadonly() throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + store() throw (::com::sun::star::io::IOException + , ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + storeAsURL( const ::rtl::OUString& rURL + , const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue >& rMediaDescriptor ) + throw (::com::sun::star::io::IOException + , ::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + storeToURL( const ::rtl::OUString& rURL + , const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue >& rMediaDescriptor ) + throw (::com::sun::star::io::IOException + , ::com::sun::star::uno::RuntimeException); + + //----------------------------------------------------------------- + // ::com::sun::star::util::XModifiable (required interface) + //----------------------------------------------------------------- + virtual sal_Bool SAL_CALL + isModified() throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + setModified( sal_Bool bModified ) + throw (::com::sun::star::beans::PropertyVetoException + , ::com::sun::star::uno::RuntimeException); + + //----------------------------------------------------------------- + // ::com::sun::star::util::XModifyBroadcaster (base of XModifiable) + //----------------------------------------------------------------- + virtual void SAL_CALL + addModifyListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XModifyListener >& xListener ) + throw (::com::sun::star::uno::RuntimeException); + + virtual void SAL_CALL + removeModifyListener( const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XModifyListener >& xListener ) + 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); + + // ____ datatransferable::XTransferable ____ + virtual ::com::sun::star::uno::Any SAL_CALL getTransferData( + const ::com::sun::star::datatransfer::DataFlavor& aFlavor ) + throw (::com::sun::star::datatransfer::UnsupportedFlavorException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor > SAL_CALL getTransferDataFlavors() + throw (::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL isDataFlavorSupported( + const ::com::sun::star::datatransfer::DataFlavor& aFlavor ) + throw (::com::sun::star::uno::RuntimeException); + + //----------------------------------------------------------------- + // lang::XTypeProvider (overloaded method of WeakImplHelper) + //----------------------------------------------------------------- + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL + getTypes() throw (::com::sun::star::uno::RuntimeException); + + // ____ document::XDocumentPropertiesSupplier ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::document::XDocumentProperties > SAL_CALL + getDocumentProperties( ) throw (::com::sun::star::uno::RuntimeException); + + //----------------------------------------------------------------- + // ::com::sun::star::chart2::XChartDocument + //----------------------------------------------------------------- + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XDiagram > SAL_CALL + getFirstDiagram() throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setFirstDiagram( + const ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XDiagram >& xDiagram ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL + createInternalDataProvider( sal_Bool bCloneExistingData ) + throw (::com::sun::star::util::CloseVetoException, + ::com::sun::star::uno::RuntimeException); + virtual ::sal_Bool SAL_CALL hasInternalDataProvider() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataProvider > SAL_CALL + getDataProvider() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL + setChartTypeManager( const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XChartTypeManager >& xNewManager ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XChartTypeManager > SAL_CALL + getChartTypeManager() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > SAL_CALL + getPageBackground() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XDataReceiver (public API) ____ + virtual void SAL_CALL + attachDataProvider( const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::data::XDataProvider >& xProvider ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setArguments( + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArguments ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL getUsedRangeRepresentations() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XDataSource > SAL_CALL getUsedData() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL attachNumberFormatsSupplier( const ::com::sun::star::uno::Reference< + ::com::sun::star::util::XNumberFormatsSupplier >& xSupplier ) + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XRangeHighlighter > SAL_CALL getRangeHighlighter() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XTitled ____ + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XTitle > SAL_CALL getTitleObject() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setTitleObject( const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XTitle >& Title ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ XInterface (for old API wrapper) ____ + virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& aType ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ XLoadable ____ + virtual void SAL_CALL initNew() + throw (::com::sun::star::frame::DoubleInitializationException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL load( const ::com::sun::star::uno::Sequence< + ::com::sun::star::beans::PropertyValue >& rMediaDescriptor ) + throw (::com::sun::star::frame::DoubleInitializationException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::Exception, + ::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); + + // ____ XVisualObject ____ + virtual void SAL_CALL setVisualAreaSize( + ::sal_Int64 nAspect, + const ::com::sun::star::awt::Size& aSize ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::awt::Size SAL_CALL getVisualAreaSize( + ::sal_Int64 nAspect ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::embed::VisualRepresentation SAL_CALL getPreferredVisualRepresentation( + ::sal_Int64 nAspect ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::embed::WrongStateException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + virtual ::sal_Int32 SAL_CALL getMapUnit( + ::sal_Int64 nAspect ) + throw (::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + + // ____ XMultiServiceFactory ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL + createInstance( const ::rtl::OUString& aServiceSpecifier ) + throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL + createInstanceWithArguments( const ::rtl::OUString& ServiceSpecifier + , const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& Arguments ) + throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL + getAvailableServiceNames() throw (::com::sun::star::uno::RuntimeException); + + // ____ XStorageBasedDocument ____ + virtual void SAL_CALL loadFromStorage( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rMediaDescriptor ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::frame::DoubleInitializationException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL storeToStorage( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage, + const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& rMediaDescriptor ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL switchToStorage( + const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::io::IOException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage > SAL_CALL getDocumentStorage() + throw (::com::sun::star::io::IOException, + ::com::sun::star::uno::Exception, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addStorageChangeListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XStorageChangeListener >& xListener ) + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeStorageChangeListener( + const ::com::sun::star::uno::Reference< ::com::sun::star::document::XStorageChangeListener >& xListener ) + throw (::com::sun::star::uno::RuntimeException); + + // for SvNumberFormatsSupplierObj + // ____ XUnoTunnel ___ + virtual ::sal_Int64 SAL_CALL getSomething( const ::com::sun::star::uno::Sequence< ::sal_Int8 >& aIdentifier ) + throw (::com::sun::star::uno::RuntimeException); + + // ____ XNumberFormatsSupplier ____ + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > SAL_CALL getNumberFormatSettings() + throw (::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Reference< + ::com::sun::star::util::XNumberFormats > SAL_CALL getNumberFormats() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XChild ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setParent( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Parent ) + throw (::com::sun::star::lang::NoSupportException, + ::com::sun::star::uno::RuntimeException); + + // ____ XUndoSupplier ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::chart2::XUndoManager > SAL_CALL getUndoManager() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XDataSource ____ allows access to the curently used data and data ranges + virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< ::com::sun::star::chart2::data::XLabeledDataSequence > > SAL_CALL getDataSequences() + throw (::com::sun::star::uno::RuntimeException); +}; + +} // namespace chart + +#endif diff --git a/chart2/source/model/main/ChartModel_Persistence.cxx b/chart2/source/model/main/ChartModel_Persistence.cxx new file mode 100644 index 000000000000..1868c38e094f --- /dev/null +++ b/chart2/source/model/main/ChartModel_Persistence.cxx @@ -0,0 +1,860 @@ +/************************************************************************* + * + * 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 "ChartModel.hxx" +#include "MediaDescriptorHelper.hxx" +#include "ChartDebugTrace.hxx" +#include "macros.hxx" +#include "ChartViewHelper.hxx" +#include "ChartModelHelper.hxx" +#include "AxisHelper.hxx" +#include "ThreeDHelper.hxx" + +#include <com/sun/star/chart2/LegendPosition.hpp> +#include <com/sun/star/container/XNameAccess.hpp> +#include <com/sun/star/document/XExporter.hpp> +#include <com/sun/star/document/XImporter.hpp> +#include <com/sun/star/document/XFilter.hpp> +#include <com/sun/star/drawing/FillStyle.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> +#include <com/sun/star/drawing/ProjectionMode.hpp> +#include <com/sun/star/embed/ElementModes.hpp> +#include <com/sun/star/embed/XStorage.hpp> +#include <com/sun/star/lang/XSingleServiceFactory.hpp> +#include <com/sun/star/sheet/XSpreadsheetDocument.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/io/XSeekable.hpp> + +#include <ucbhelper/content.hxx> +#ifndef _UNOTOOLS_UCBSTREAMHELPER_HXX +#include <unotools/ucbstreamhelper.hxx> +#endif +#include <vcl/cvtgrf.hxx> +#include <comphelper/storagehelper.hxx> +#include <vcl/svapp.hxx> + +#include <algorithm> +#include <functional> + +using namespace ::com::sun::star; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; +using ::osl::MutexGuard; + +namespace +{ +struct lcl_PropNameEquals : public ::std::unary_function< beans::PropertyValue, bool > +{ + lcl_PropNameEquals( const OUString & rStrToCompareWith ) : + m_aStr( rStrToCompareWith ) + {} + bool operator() ( const beans::PropertyValue & rProp ) + { + return rProp.Name.equals( m_aStr ); + } +private: + OUString m_aStr; +}; + +template< typename T > +T lcl_getProperty( + const Sequence< beans::PropertyValue > & rMediaDescriptor, + const OUString & rPropName ) +{ + T aResult; + if( rMediaDescriptor.getLength()) + { + OUString aPropName( rPropName ); + const beans::PropertyValue * pIt = rMediaDescriptor.getConstArray(); + const beans::PropertyValue * pEndIt = pIt + + rMediaDescriptor.getLength(); + pIt = ::std::find_if( pIt, pEndIt, lcl_PropNameEquals( aPropName )); + if( pIt != pEndIt ) + (*pIt).Value >>= aResult; + } + return aResult; +} + +void lcl_addStorageToMediaDescriptor( + Sequence< beans::PropertyValue > & rOutMD, + const Reference< embed::XStorage > & xStorage ) +{ + rOutMD.realloc( rOutMD.getLength() + 1 ); + rOutMD[rOutMD.getLength() - 1] = beans::PropertyValue( + C2U("Storage"), -1, uno::makeAny( xStorage ), beans::PropertyState_DIRECT_VALUE ); +} + +Reference< embed::XStorage > lcl_createStorage( + const OUString & rURL, + const Reference< uno::XComponentContext > & xContext, + const Sequence< beans::PropertyValue > & rMediaDescriptor ) +{ + // create new storage + Reference< embed::XStorage > xStorage; + if( !xContext.is()) + return xStorage; + + try + { + Reference< io::XStream > xStream( + ::ucbhelper::Content( rURL, Reference< ::com::sun::star::ucb::XCommandEnvironment >()).openStream(), + uno::UNO_QUERY ); + + Reference< lang::XSingleServiceFactory > xStorageFact( + xContext->getServiceManager()->createInstanceWithContext( + C2U("com.sun.star.embed.StorageFactory"), + xContext ), + uno::UNO_QUERY_THROW ); + Sequence< uno::Any > aStorageArgs( 3 ); + aStorageArgs[0] <<= xStream; + aStorageArgs[1] <<= embed::ElementModes::READWRITE; + aStorageArgs[2] <<= rMediaDescriptor; + xStorage.set( + xStorageFact->createInstanceWithArguments( aStorageArgs ), uno::UNO_QUERY_THROW ); + OSL_ENSURE( xStorage.is(), "No Storage" ); + } + catch( ::com::sun::star::ucb::ContentCreationException & rEx ) + { + ASSERT_EXCEPTION( rEx ); + } + + return xStorage; +} + +} // anonymous namespace + +namespace chart +{ + +Reference< document::XFilter > ChartModel::impl_createFilter( + const Sequence< beans::PropertyValue > & rMediaDescriptor ) +{ + Reference< document::XFilter > xFilter; + + // find FilterName in MediaDescriptor + OUString aFilterName( + lcl_getProperty< OUString >( rMediaDescriptor, OUString::createFromAscii("FilterName"))); + + // if FilterName was found, get Filter from factory + if( aFilterName.getLength() > 0 ) + { + try + { + Reference< container::XNameAccess > xFilterFact( + m_xContext->getServiceManager()->createInstanceWithContext( + C2U( "com.sun.star.document.FilterFactory" ), m_xContext ), + uno::UNO_QUERY_THROW ); + uno::Any aFilterProps( xFilterFact->getByName( aFilterName )); + Sequence< beans::PropertyValue > aProps; + + if( aFilterProps.hasValue() && + (aFilterProps >>= aProps)) + { + OUString aFilterServiceName( + lcl_getProperty< OUString >( aProps, OUString::createFromAscii("FilterService"))); + + if( aFilterServiceName.getLength()) + { + xFilter.set( + m_xContext->getServiceManager()->createInstanceWithContext( + aFilterServiceName, m_xContext ), uno::UNO_QUERY_THROW ); + OSL_TRACE( "Filter found for service %s", U2C( aFilterServiceName )); + } + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + OSL_ENSURE( xFilter.is(), "Filter not found via factory" ); + } + + // fall-back: create XML-Filter + if( ! xFilter.is()) + { + OSL_TRACE( "No FilterName passed in MediaDescriptor" ); + xFilter.set( + m_xContext->getServiceManager()->createInstanceWithContext( + C2U("com.sun.star.comp.chart2.XMLFilter"), m_xContext ), + uno::UNO_QUERY_THROW ); + } + + return xFilter; +} + +//----------------------------------------------------------------- +// frame::XStorable2 +//----------------------------------------------------------------- + +void SAL_CALL ChartModel::storeSelf( const Sequence< beans::PropertyValue >& rMediaDescriptor ) + throw (lang::IllegalArgumentException, + io::IOException, + uno::RuntimeException) +{ + // only some parameters are allowed (see also SfxBaseModel) + // "VersionComment", "Author", "InteractionHandler", "StatusIndicator" + // However, they are ignored here. They would become interesting when + // charts support a standalone format again. + impl_store( rMediaDescriptor, m_xStorage ); +} + +//----------------------------------------------------------------- +// frame::XStorable (base of XStorable2) +//----------------------------------------------------------------- +sal_Bool SAL_CALL ChartModel::hasLocation() + throw(uno::RuntimeException) +{ + //@todo guard + return m_aResource.getLength()!=0; +} + +::rtl::OUString SAL_CALL ChartModel::getLocation() + throw(uno::RuntimeException) +{ + return impl_g_getLocation(); +} + +sal_Bool SAL_CALL ChartModel::isReadonly() + throw(uno::RuntimeException) +{ + //@todo guard + return m_bReadOnly; +} + +void SAL_CALL ChartModel::store() + throw(io::IOException, + uno::RuntimeException) +{ + apphelper::LifeTimeGuard aGuard(m_aLifeTimeManager); + if(!aGuard.startApiCall(sal_True)) //start LongLastingCall + return; //behave passive if already disposed or closed or throw exception @todo? + + ::rtl::OUString aLocation = m_aResource; + + if( aLocation.getLength() == 0 ) + throw io::IOException( C2U( "no location specified" ), static_cast< ::cppu::OWeakObject* >(this)); + //@todo check wether aLocation is something like private:factory... + if( m_bReadOnly ) + throw io::IOException( C2U( "document is read only" ), static_cast< ::cppu::OWeakObject* >(this)); + + aGuard.clear(); + + // store + impl_store( m_aMediaDescriptor, m_xStorage ); +} + +void SAL_CALL ChartModel::storeAsURL( + const ::rtl::OUString& rURL, + const uno::Sequence< beans::PropertyValue >& rMediaDescriptor ) + throw(io::IOException, uno::RuntimeException) +{ + apphelper::LifeTimeGuard aGuard(m_aLifeTimeManager); + if(!aGuard.startApiCall(sal_True)) //start LongLastingCall + return; //behave passive if already disposed or closed or throw exception @todo? + + apphelper::MediaDescriptorHelper aMediaDescriptorHelper(rMediaDescriptor); + uno::Sequence< beans::PropertyValue > aReducedMediaDescriptor( + aMediaDescriptorHelper.getReducedForModel() ); + + m_bReadOnly = sal_False; + aGuard.clear(); + + // create new storage + Reference< embed::XStorage > xStorage( lcl_createStorage( rURL, m_xContext, aReducedMediaDescriptor )); + + if( xStorage.is()) + { + impl_store( aReducedMediaDescriptor, xStorage ); + attachResource( rURL, aReducedMediaDescriptor ); + } +} + +void SAL_CALL ChartModel::storeToURL( + const ::rtl::OUString& rURL, + const uno::Sequence< beans::PropertyValue >& rMediaDescriptor ) + throw(io::IOException, + uno::RuntimeException) +{ + apphelper::LifeTimeGuard aGuard(m_aLifeTimeManager); + if(!aGuard.startApiCall(sal_True)) //start LongLastingCall + return; //behave passive if already disposed or closed or throw exception @todo? + //do not change the internal state of the document here + //... + + aGuard.clear(); + + apphelper::MediaDescriptorHelper aMediaDescriptorHelper(rMediaDescriptor); + uno::Sequence< beans::PropertyValue > aReducedMediaDescriptor( + aMediaDescriptorHelper.getReducedForModel() ); + + if( rURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("private:stream"))) + { + try + { + if( m_xContext.is() && aMediaDescriptorHelper.ISSET_OutputStream ) + { + Reference< lang::XMultiServiceFactory > xFact( m_xContext->getServiceManager(), uno::UNO_QUERY_THROW ); + Reference< io::XStream > xStream( + xFact->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM("com.sun.star.io.TempFile"))), uno::UNO_QUERY_THROW ); + Reference< io::XInputStream > xInputStream( xStream->getInputStream()); + + Reference< embed::XStorage > xStorage( + ::comphelper::OStorageHelper::GetStorageFromStream( xStream, embed::ElementModes::READWRITE, xFact )); + if( xStorage.is()) + { + impl_store( aReducedMediaDescriptor, xStorage ); + + Reference< io::XSeekable > xSeekable( xStream, uno::UNO_QUERY_THROW ); + xSeekable->seek( 0 ); + ::comphelper::OStorageHelper::CopyInputToOutput( xInputStream, aMediaDescriptorHelper.OutputStream ); + } + } + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + else + { + // create new storage + Reference< embed::XStorage > xStorage( lcl_createStorage( rURL, m_xContext, aReducedMediaDescriptor )); + + if( xStorage.is()) + impl_store( aReducedMediaDescriptor, xStorage ); + } +} + +void ChartModel::impl_store( + const Sequence< beans::PropertyValue >& rMediaDescriptor, + const Reference< embed::XStorage > & xStorage ) +{ + Reference< document::XFilter > xFilter( impl_createFilter( rMediaDescriptor)); + if( xFilter.is() && xStorage.is()) + { + Sequence< beans::PropertyValue > aMD( rMediaDescriptor ); + lcl_addStorageToMediaDescriptor( aMD, xStorage ); + try + { + Reference< document::XExporter > xExporter( xFilter, uno::UNO_QUERY_THROW ); + xExporter->setSourceDocument( Reference< lang::XComponent >( this )); + xFilter->filter( aMD ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + else + { + OSL_ENSURE( false, "No filter" ); + } + + setModified( sal_False ); + + //#i66865# + //for data change notification during chart is not loaded: + //notify parent data provider after saving thus the parent document can store + //the ranges for which a load and update of the chart will be necessary + Reference< beans::XPropertySet > xPropSet( m_xParent, uno::UNO_QUERY ); + if ( !hasInternalDataProvider() && xPropSet.is() ) + { + apphelper::MediaDescriptorHelper aMDHelper(rMediaDescriptor); + try + { + xPropSet->setPropertyValue( OUString::createFromAscii("SavedObject"), + uno::makeAny( aMDHelper.HierarchicalDocumentName ) ); + } + catch ( uno::Exception& ) + { + } + } +} + +//----------------------------------------------------------------- +// frame::XLoadable +//----------------------------------------------------------------- +void SAL_CALL ChartModel::initNew() + throw (frame::DoubleInitializationException, + io::IOException, + uno::Exception, + uno::RuntimeException) +{ + lockControllers(); + createInternalDataProvider( sal_False ); + try + { + // create default chart + Reference< chart2::XChartTypeTemplate > xTemplate( impl_createDefaultChartTypeTemplate() ); + if( xTemplate.is()) + { + try + { + Reference< chart2::data::XDataSource > xDataSource( impl_createDefaultData() ); + Sequence< beans::PropertyValue > aParam; + + bool bSupportsCategories = xTemplate->supportsCategories(); + if( bSupportsCategories ) + { + aParam.realloc( 1 ); + aParam[0] = beans::PropertyValue( C2U("HasCategories"), -1, uno::makeAny( true ), + beans::PropertyState_DIRECT_VALUE ); + } + + Reference< chart2::XDiagram > xDiagram( xTemplate->createDiagramByDataSource( xDataSource, aParam ) ); + + setFirstDiagram( xDiagram ); + + bool bIsRTL = Application::GetSettings().GetLayoutRTL(); + //reverse x axis for rtl charts + if( bIsRTL ) + AxisHelper::setRTLAxisLayout( AxisHelper::getCoordinateSystemByIndex( xDiagram, 0 ) ); + + // create and attach legend + Reference< chart2::XLegend > xLegend( + m_xContext->getServiceManager()->createInstanceWithContext( + C2U( "com.sun.star.chart2.Legend" ), m_xContext ), uno::UNO_QUERY_THROW ); + Reference< beans::XPropertySet > xLegendProperties( xLegend, uno::UNO_QUERY ); + if( xLegendProperties.is() ) + { + xLegendProperties->setPropertyValue( C2U( "FillStyle" ), uno::makeAny( drawing::FillStyle_NONE )); + xLegendProperties->setPropertyValue( C2U( "LineStyle" ), uno::makeAny( drawing::LineStyle_NONE )); + xLegendProperties->setPropertyValue( C2U( "LineColor" ), uno::makeAny( static_cast< sal_Int32 >( 0xb3b3b3 ) )); // gray30 + xLegendProperties->setPropertyValue( C2U( "FillColor" ), uno::makeAny( static_cast< sal_Int32 >( 0xe6e6e6 ) ) ); // gray10 + + if( bIsRTL ) + xLegendProperties->setPropertyValue( C2U( "AnchorPosition" ), uno::makeAny( chart2::LegendPosition_LINE_START )); + } + if(xDiagram.is()) + xDiagram->setLegend( xLegend ); + + // set simple 3D look + Reference< beans::XPropertySet > xDiagramProperties( xDiagram, uno::UNO_QUERY ); + if( xDiagramProperties.is() ) + { + xDiagramProperties->setPropertyValue( C2U("RightAngledAxes"), uno::makeAny( sal_True )); + xDiagramProperties->setPropertyValue( C2U("D3DScenePerspective"), uno::makeAny( drawing::ProjectionMode_PARALLEL )); + ThreeDHelper::setScheme( xDiagram, ThreeDLookScheme_Realistic ); + } + + //set some new 'defaults' for wall and floor + if( xDiagram.is() ) + { + Reference< beans::XPropertySet > xWall( xDiagram->getWall() ); + if( xWall.is() ) + { + xWall->setPropertyValue( C2U( "LineStyle" ), uno::makeAny( drawing::LineStyle_SOLID ) ); + xWall->setPropertyValue( C2U( "FillStyle" ), uno::makeAny( drawing::FillStyle_NONE ) ); + xWall->setPropertyValue( C2U( "LineColor" ), uno::makeAny( static_cast< sal_Int32 >( 0xb3b3b3 ) ) ); // gray30 + xWall->setPropertyValue( C2U( "FillColor" ), uno::makeAny( static_cast< sal_Int32 >( 0xe6e6e6 ) ) ); // gray10 + } + Reference< beans::XPropertySet > xFloor( xDiagram->getFloor() ); + if( xFloor.is() ) + { + xFloor->setPropertyValue( C2U( "LineStyle" ), uno::makeAny( drawing::LineStyle_NONE ) ); + xFloor->setPropertyValue( C2U( "FillStyle" ), uno::makeAny( drawing::FillStyle_SOLID ) ); + xFloor->setPropertyValue( C2U( "LineColor" ), uno::makeAny( static_cast< sal_Int32 >( 0xb3b3b3 ) ) ); // gray30 + xFloor->setPropertyValue( C2U( "FillColor" ), uno::makeAny( static_cast< sal_Int32 >( 0xcccccc ) ) ); // gray20 + } + + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + } + ChartModelHelper::setIncludeHiddenCells( false, this ); + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + setModified( sal_False ); + unlockControllers(); + +#if OSL_DEBUG_LEVEL >= CHART_TRACE_OSL_DEBUG_LEVEL + OSL_TRACE( "ChartModel::initNew: Showing ChartDocument structure" ); + OSL_TRACE( "----------------------------------------------------" ); + debug::ChartDebugTraceDocument( Reference< chart2::XChartDocument >( this )); +#endif +} + +void SAL_CALL ChartModel::load( + const Sequence< beans::PropertyValue >& rMediaDescriptor ) + throw (frame::DoubleInitializationException, + io::IOException, + uno::Exception, + uno::RuntimeException) +{ + Reference< embed::XStorage > xStorage; + OUString aURL; + try + { + apphelper::MediaDescriptorHelper aMDHelper( rMediaDescriptor ); + if( aMDHelper.ISSET_Storage ) + { + xStorage = aMDHelper.Storage; + } + else if( aMDHelper.ISSET_Stream || + aMDHelper.ISSET_InputStream ) + { + if( aMDHelper.ISSET_FilterName && + (aMDHelper.FilterName.equals( C2U("StarChart 5.0")) || + aMDHelper.FilterName.equals( C2U("StarChart 4.0")) || + aMDHelper.FilterName.equals( C2U("StarChart 3.0")) )) + { + attachResource( aMDHelper.URL, rMediaDescriptor ); + impl_load( rMediaDescriptor, 0 ); // cannot create a storage from binary streams, but I do not need the storage here anyhow + m_bReadOnly = sal_True; + return; + } + + Reference< lang::XSingleServiceFactory > xStorageFact( + m_xContext->getServiceManager()->createInstanceWithContext( + C2U("com.sun.star.embed.StorageFactory"), + m_xContext ), + uno::UNO_QUERY_THROW ); + + if( aMDHelper.ISSET_Stream ) + { + // convert XStream to XStorage via the storage factory + Sequence< uno::Any > aStorageArgs( 2 ); + aStorageArgs[0] <<= aMDHelper.Stream; + // todo: check if stream is read-only + aStorageArgs[1] <<= (embed::ElementModes::READ); //WRITE | embed::ElementModes::NOCREATE); + + xStorage.set( xStorageFact->createInstanceWithArguments( aStorageArgs ), + uno::UNO_QUERY_THROW ); + } + else + { + OSL_ASSERT( aMDHelper.ISSET_InputStream ); + // convert XInputStream to XStorage via the storage factory + Sequence< uno::Any > aStorageArgs( 2 ); + aStorageArgs[0] <<= aMDHelper.InputStream; + aStorageArgs[1] <<= (embed::ElementModes::READ); + + xStorage.set( xStorageFact->createInstanceWithArguments( aStorageArgs ), + uno::UNO_QUERY_THROW ); + } + } + + if( aMDHelper.ISSET_URL ) + aURL = aMDHelper.URL; + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } + + if( xStorage.is()) + { + attachResource( aURL, rMediaDescriptor ); + impl_load( rMediaDescriptor, xStorage ); + } +} + +void ChartModel::impl_load( + const Sequence< beans::PropertyValue >& rMediaDescriptor, + const Reference< embed::XStorage >& xStorage ) +{ + { + MutexGuard aGuard( m_aModelMutex ); + m_nInLoad++; + } + + Reference< document::XFilter > xFilter( impl_createFilter( rMediaDescriptor )); + + if( xFilter.is()) + { + Reference< document::XImporter > xImporter( xFilter, uno::UNO_QUERY_THROW ); + xImporter->setTargetDocument( this ); + Sequence< beans::PropertyValue > aMD( rMediaDescriptor ); + lcl_addStorageToMediaDescriptor( aMD, xStorage ); + + xFilter->filter( aMD ); + xFilter.clear(); + } + else + { + OSL_ENSURE( false, "loadFromStorage cannot create filter" ); + } + + if( xStorage.is() ) + impl_loadGraphics( xStorage ); + + setModified( sal_False ); + + // switchToStorage without notifying listeners (which shouldn't exist at + // this time, anyway) + m_xStorage = xStorage; + + { + MutexGuard aGuard( m_aModelMutex ); + m_nInLoad--; + } +} + +void ChartModel::impl_loadGraphics( + const Reference< embed::XStorage >& xStorage ) +{ + try + { + const Reference< embed::XStorage >& xGraphicsStorage( + xStorage->openStorageElement( C2U( "Pictures" ), + embed::ElementModes::READ ) ); + + if( xGraphicsStorage.is() ) + { + const uno::Sequence< ::rtl::OUString > aElementNames( + xGraphicsStorage->getElementNames() ); + + for( int i = 0; i < aElementNames.getLength(); ++i ) + { + if( xGraphicsStorage->isStreamElement( aElementNames[ i ] ) ) + { + uno::Reference< io::XStream > xElementStream( + xGraphicsStorage->openStreamElement( + aElementNames[ i ], + embed::ElementModes::READ ) ); + + if( xElementStream.is() ) + { + std::auto_ptr< SvStream > apIStm( + ::utl::UcbStreamHelper::CreateStream( + xElementStream, true ) ); + + if( apIStm.get() ) + { + Graphic aGraphic; + + if( !GraphicConverter::Import( + *apIStm.get(), + aGraphic ) ) + { + m_aGraphicObjectVector.push_back( aGraphic ); + } + } + } + } + } + } + } + catch ( uno::Exception& ) + { + } +} + +//----------------------------------------------------------------- +// util::XModifiable +//----------------------------------------------------------------- +void SAL_CALL ChartModel::impl_notifyModifiedListeners() + throw( uno::RuntimeException) +{ + { + MutexGuard aGuard( m_aModelMutex ); + m_bUpdateNotificationsPending = false; + } + + //always notify the view first! + ChartViewHelper::setViewToDirtyState( this ); + + ::cppu::OInterfaceContainerHelper* pIC = m_aLifeTimeManager.m_aListenerContainer + .getContainer( ::getCppuType((const uno::Reference< util::XModifyListener >*)0) ); + if( pIC ) + { + lang::EventObject aEvent( static_cast< lang::XComponent*>(this) ); + ::cppu::OInterfaceIteratorHelper aIt( *pIC ); + while( aIt.hasMoreElements() ) + { + uno::Reference< util::XModifyListener > xListener( aIt.next(), uno::UNO_QUERY ); + if( xListener.is() ) + xListener->modified( aEvent ); + } + } +} + +sal_Bool SAL_CALL ChartModel::isModified() + throw(uno::RuntimeException) +{ + //@todo guard + return m_bModified; +} + +void SAL_CALL ChartModel::setModified( sal_Bool bModified ) + throw(beans::PropertyVetoException, + uno::RuntimeException) +{ + apphelper::LifeTimeGuard aGuard(m_aLifeTimeManager); + if(!aGuard.startApiCall())//@todo ? is this a long lasting call?? + return; //behave passive if already disposed or closed or throw exception @todo? + m_bModified = bModified; + + if( m_nControllerLockCount > 0 ) + { + m_bUpdateNotificationsPending = true; + return;//don't call listeners if controllers are locked + } + aGuard.clear(); + + if(bModified) + impl_notifyModifiedListeners(); +} + +//----------------------------------------------------------------- +// util::XModifyBroadcaster (base of XModifiable) +//----------------------------------------------------------------- +void SAL_CALL ChartModel::addModifyListener( + const uno::Reference< util::XModifyListener >& xListener ) + throw(uno::RuntimeException) +{ + if( m_aLifeTimeManager.impl_isDisposedOrClosed() ) + return; //behave passive if already disposed or closed + + m_aLifeTimeManager.m_aListenerContainer.addInterface( + ::getCppuType((const uno::Reference< util::XModifyListener >*)0), xListener ); +} + +void SAL_CALL ChartModel::removeModifyListener( + const uno::Reference< util::XModifyListener >& xListener ) + throw(uno::RuntimeException) +{ + if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) ) + return; //behave passive if already disposed or closed + + m_aLifeTimeManager.m_aListenerContainer.removeInterface( + ::getCppuType((const uno::Reference< util::XModifyListener >*)0), xListener ); +} + +//----------------------------------------------------------------- +// util::XModifyListener +//----------------------------------------------------------------- +void SAL_CALL ChartModel::modified( const lang::EventObject& ) + throw (uno::RuntimeException) +{ + if( m_nInLoad == 0 ) + setModified( sal_True ); +} + +//----------------------------------------------------------------- +// lang::XEventListener (base of util::XModifyListener) +//----------------------------------------------------------------- +void SAL_CALL ChartModel::disposing( const lang::EventObject& ) + throw (uno::RuntimeException) +{ + // child was disposed -- should not happen from outside +} + + +//----------------------------------------------------------------- +// document::XStorageBasedDocument +//----------------------------------------------------------------- +void SAL_CALL ChartModel::loadFromStorage( + const Reference< embed::XStorage >& xStorage, + const Sequence< beans::PropertyValue >& rMediaDescriptor ) + throw (lang::IllegalArgumentException, + frame::DoubleInitializationException, + io::IOException, + uno::Exception, + uno::RuntimeException) +{ + attachResource( OUString(), rMediaDescriptor ); + impl_load( rMediaDescriptor, xStorage ); +} + +void SAL_CALL ChartModel::storeToStorage( + const Reference< embed::XStorage >& xStorage, + const Sequence< beans::PropertyValue >& rMediaDescriptor ) + throw (lang::IllegalArgumentException, + io::IOException, + uno::Exception, + uno::RuntimeException) +{ + impl_store( rMediaDescriptor, xStorage ); +} + +void SAL_CALL ChartModel::switchToStorage( const Reference< embed::XStorage >& xStorage ) + throw (lang::IllegalArgumentException, + io::IOException, + uno::Exception, + uno::RuntimeException) +{ + m_xStorage = xStorage; + impl_notifyStorageChangeListeners(); +} + +Reference< embed::XStorage > SAL_CALL ChartModel::getDocumentStorage() + throw (io::IOException, + uno::Exception, + uno::RuntimeException) +{ + return m_xStorage; +} + +void SAL_CALL ChartModel::impl_notifyStorageChangeListeners() + throw( uno::RuntimeException) +{ + ::cppu::OInterfaceContainerHelper* pIC = m_aLifeTimeManager.m_aListenerContainer + .getContainer( ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0) ); + if( pIC ) + { + ::cppu::OInterfaceIteratorHelper aIt( *pIC ); + while( aIt.hasMoreElements() ) + { + uno::Reference< document::XStorageChangeListener > xListener( aIt.next(), uno::UNO_QUERY ); + if( xListener.is() ) + xListener->notifyStorageChange( static_cast< ::cppu::OWeakObject* >( this ), m_xStorage ); + } + } +} + +void SAL_CALL ChartModel::addStorageChangeListener( const Reference< document::XStorageChangeListener >& xListener ) + throw (uno::RuntimeException) +{ + if( m_aLifeTimeManager.impl_isDisposedOrClosed() ) + return; //behave passive if already disposed or closed + + m_aLifeTimeManager.m_aListenerContainer.addInterface( + ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener ); +} + +void SAL_CALL ChartModel::removeStorageChangeListener( const Reference< document::XStorageChangeListener >& xListener ) + throw (uno::RuntimeException) +{ + if( m_aLifeTimeManager.impl_isDisposedOrClosed(false) ) + return; //behave passive if already disposed or closed + + m_aLifeTimeManager.m_aListenerContainer.removeInterface( + ::getCppuType((const uno::Reference< document::XStorageChangeListener >*)0), xListener ); +} + +} // namespace chart diff --git a/chart2/source/model/main/DataPoint.cxx b/chart2/source/model/main/DataPoint.cxx new file mode 100644 index 000000000000..1f3d92e4d94b --- /dev/null +++ b/chart2/source/model/main/DataPoint.cxx @@ -0,0 +1,319 @@ +/************************************************************************* + * + * 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 "DataPoint.hxx" +#include "DataPointProperties.hxx" +#include "CharacterProperties.hxx" +#include "UserDefinedProperties.hxx" +#include "PropertyHelper.hxx" +#include "macros.hxx" +#include "ContainerHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uno/Sequence.hxx> + +#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 +{ +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; + ::chart::DataPointProperties::AddPropertiesToVector( aProperties ); + ::chart::CharacterProperties::AddPropertiesToVector( aProperties ); + ::chart::UserDefinedProperties::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 +{ + +DataPoint::DataPoint( const uno::Reference< beans::XPropertySet > & rParentProperties ) : + ::property::OPropertySet( m_aMutex ), + m_xParentProperties( rParentProperties ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()), + m_bNoParentPropAllowed( false ) +{ + SetNewValuesExplicitlyEvenIfTheyEqualDefault(); +} + +DataPoint::DataPoint( const DataPoint & rOther ) : + MutexContainer(), + impl::DataPoint_Base(), + ::property::OPropertySet( rOther, m_aMutex ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()), + m_bNoParentPropAllowed( true ) +{ + SetNewValuesExplicitlyEvenIfTheyEqualDefault(); + + // m_xParentProperties has to be set from outside, like in the method + // DataSeries::createClone + + // add as listener to XPropertySet properties + Reference< beans::XPropertySet > xPropertySet; + uno::Any aValue; + + getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X ); + if( ( aValue >>= xPropertySet ) + && xPropertySet.is()) + ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder ); + + getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y ); + if( ( aValue >>= xPropertySet ) + && xPropertySet.is()) + ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder ); + + m_bNoParentPropAllowed = false; +} + +DataPoint::~DataPoint() +{ + try + { + // remove listener from XPropertySet properties + Reference< beans::XPropertySet > xPropertySet; + uno::Any aValue; + + getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X ); + if( ( aValue >>= xPropertySet ) + && xPropertySet.is()) + ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder ); + + getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y ); + 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 DataPoint::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new DataPoint( *this )); +} + +// ____ XChild ____ +Reference< uno::XInterface > SAL_CALL DataPoint::getParent() + throw (uno::RuntimeException) +{ + return Reference< uno::XInterface >( m_xParentProperties, uno::UNO_QUERY ); +} + +void SAL_CALL DataPoint::setParent( + const Reference< uno::XInterface >& Parent ) + throw (lang::NoSupportException, + uno::RuntimeException) +{ + m_xParentProperties.set( Parent, uno::UNO_QUERY ); +} + +// ____ OPropertySet ____ +uno::Any DataPoint::GetDefaultValue( sal_Int32 nHandle ) const + throw(beans::UnknownPropertyException) +{ + // the value set at the data series is the default + uno::Reference< beans::XFastPropertySet > xFast( m_xParentProperties, uno::UNO_QUERY ); + if( !xFast.is()) + { + OSL_ENSURE( m_bNoParentPropAllowed, "data point needs a parent property set to provide values correctly" ); + return uno::Any(); + } + + return xFast->getFastPropertyValue( nHandle ); +} + +void SAL_CALL DataPoint::setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, const uno::Any& rValue ) + throw (uno::Exception) +{ + if( nHandle == DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y + || nHandle == DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X ) + { + 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 ); +} + +::cppu::IPropertyArrayHelper & SAL_CALL DataPoint::getInfoHelper() +{ + return getInfoHelperConst(); +} + +::cppu::IPropertyArrayHelper & SAL_CALL DataPoint::getInfoHelperConst() const +{ + static ::cppu::OPropertyArrayHelper aArrayHelper( + lcl_GetPropertySequence(), + /* bSorted = */ sal_True ); + + return aArrayHelper; +} + +// ____ XPropertySet ____ +Reference< beans::XPropertySetInfo > SAL_CALL + DataPoint::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; + // \-- +} + +// ____ XModifyBroadcaster ____ +void SAL_CALL DataPoint::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 DataPoint::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 DataPoint::modified( const lang::EventObject& aEvent ) + throw (uno::RuntimeException) +{ + m_xModifyEventForwarder->modified( aEvent ); +} + +// ____ XEventListener (base of XModifyListener) ____ +void SAL_CALL DataPoint::disposing( const lang::EventObject& ) + throw (uno::RuntimeException) +{ + // nothing +} + +// ____ OPropertySet ____ +void DataPoint::firePropertyChangeEvent() +{ + fireModifyEvent(); +} + +void DataPoint::fireModifyEvent() +{ + m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); +} + +Sequence< OUString > DataPoint::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 3 ); + aServices[ 0 ] = C2U( "com.sun.star.chart2.DataPoint" ); + aServices[ 1 ] = C2U( "com.sun.star.chart2.DataPointProperties" ); + aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +// needed by MSC compiler +using impl::DataPoint_Base; + +IMPLEMENT_FORWARD_XINTERFACE2( DataPoint, DataPoint_Base, ::property::OPropertySet ) + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( DataPoint, C2U( "com.sun.star.comp.chart.DataPoint" )); + +} // namespace chart diff --git a/chart2/source/model/main/DataPoint.hxx b/chart2/source/model/main/DataPoint.hxx new file mode 100644 index 000000000000..1498b8345963 --- /dev/null +++ b/chart2/source/model/main/DataPoint.hxx @@ -0,0 +1,143 @@ +/************************************************************************* + * + * 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_DATAPOINT_HXX +#define CHART_DATAPOINT_HXX + +#include <osl/mutex.hxx> +#include <cppuhelper/implbase5.hxx> +#include <comphelper/uno3.hxx> +#include <com/sun/star/container/XChild.hpp> +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> + +#include "OPropertySet.hxx" +#include "MutexContainer.hxx" +#include "ModifyListenerHelper.hxx" +#include "ServiceMacros.hxx" + +//for auto_ptr +#include <memory> + +namespace chart +{ + +namespace impl +{ +typedef ::cppu::WeakImplHelper5< + ::com::sun::star::container::XChild, + ::com::sun::star::util::XCloneable, + ::com::sun::star::util::XModifyBroadcaster, + ::com::sun::star::util::XModifyListener, + ::com::sun::star::lang::XServiceInfo > + DataPoint_Base; +} + +class DataPoint : + public MutexContainer, + public impl::DataPoint_Base, + public ::property::OPropertySet +{ +public: + DataPoint( const ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > & rParentProperties ); + virtual ~DataPoint(); + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + +protected: + explicit DataPoint( const DataPoint & rOther ); + + // ____ 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 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 ____ + // Note: m_xParentProperties are not cloned! + virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() + throw (::com::sun::star::uno::RuntimeException); + + // ____ XChild ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL getParent() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setParent( + const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& Parent ) + throw (::com::sun::star::lang::NoSupportException, + ::com::sun::star::uno::RuntimeException); + + /** const variant of getInfoHelper() + */ + ::cppu::IPropertyArrayHelper & SAL_CALL getInfoHelperConst() const; + + // ____ 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); + + // ____ OPropertySet ____ + virtual void firePropertyChangeEvent(); + using OPropertySet::disposing; + + void fireModifyEvent(); + +private: + ::com::sun::star::uno::Reference< + ::com::sun::star::beans::XPropertySet > m_xParentProperties; + + ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xModifyEventForwarder; + bool m_bNoParentPropAllowed; +}; + +} // namespace chart + +// CHART_DATAPOINT_HXX +#endif diff --git a/chart2/source/model/main/DataPointProperties.cxx b/chart2/source/model/main/DataPointProperties.cxx new file mode 100644 index 000000000000..964f61b128ed --- /dev/null +++ b/chart2/source/model/main/DataPointProperties.cxx @@ -0,0 +1,438 @@ +/************************************************************************* + * + * 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 "DataPointProperties.hxx" +#include "macros.hxx" +#include "LineProperties.hxx" +#include "FillProperties.hxx" + +// #ifndef _COM_SUN_STAR_AWT_GRADIENT_HPP_ +// #include <com/sun/star/awt/Gradient.hpp> +// #endif +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/drawing/FillStyle.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> +#include <com/sun/star/drawing/LineDash.hpp> +#include <com/sun/star/drawing/PolyPolygonBezierCoords.hpp> +// #ifndef _COM_SUN_STAR_DRAWING_HATCH_HPP_ +// #include <com/sun/star/drawing/Hatch.hpp> +// #endif +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/drawing/BitmapMode.hpp> +#include <com/sun/star/drawing/RectanglePoint.hpp> + +// #ifndef _COM_SUN_STAR_CHART2_FILLBITMAP_HPP_ +// #include <com/sun/star/chart2/FillBitmap.hpp> +// #endif +#include <com/sun/star/chart2/DataPointGeometry3D.hpp> +#include <com/sun/star/chart2/DataPointLabel.hpp> +#include <com/sun/star/chart2/Symbol.hpp> + +using namespace ::com::sun::star; + +using ::com::sun::star::beans::Property; + +namespace chart +{ + +void DataPointProperties::AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + // DataPointProperties + // =================== + + // Common + // ------ + rOutProperties.push_back( + Property( C2U( "Color" ), + PROP_DATAPOINT_COLOR, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID // "maybe auto" + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "Transparency" ), + PROP_DATAPOINT_TRANSPARENCY, + ::getCppuType( reinterpret_cast< const sal_Int16 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + // Fill Properties + // --------------- + rOutProperties.push_back( + Property( C2U( "FillStyle" ), + PROP_DATAPOINT_FILL_STYLE, + ::getCppuType( reinterpret_cast< const drawing::FillStyle * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "TransparencyGradientName" ), + PROP_DATAPOINT_TRANSPARENCY_GRADIENT_NAME, + ::getCppuType( reinterpret_cast< const ::rtl::OUString * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT + | beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "GradientName" ), + PROP_DATAPOINT_GRADIENT_NAME, + ::getCppuType( reinterpret_cast< const ::rtl::OUString * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT + | beans::PropertyAttribute::MAYBEVOID )); + + + rOutProperties.push_back( + beans::Property( C2U( "GradientStepCount" ), + PROP_DATAPOINT_GRADIENT_STEPCOUNT, + ::getCppuType( reinterpret_cast< const sal_Int16 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "HatchName" ), + PROP_DATAPOINT_HATCH_NAME, + ::getCppuType( reinterpret_cast< const ::rtl::OUString * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT + | beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "FillBitmapName" ), + PROP_DATAPOINT_FILL_BITMAP_NAME, + ::getCppuType( reinterpret_cast< const ::rtl::OUString * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT + | beans::PropertyAttribute::MAYBEVOID )); + rOutProperties.push_back( + Property( C2U( "FillBackground" ), + PROP_DATAPOINT_FILL_BACKGROUND, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT + | beans::PropertyAttribute::MAYBEVOID )); + + // border for filled objects + rOutProperties.push_back( + Property( C2U( "BorderColor" ), + PROP_DATAPOINT_BORDER_COLOR, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID // "maybe auto" + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "BorderStyle" ), + PROP_DATAPOINT_BORDER_STYLE, + ::getCppuType( reinterpret_cast< const drawing::LineStyle * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "BorderWidth" ), + PROP_DATAPOINT_BORDER_WIDTH, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "BorderDashName" ), + PROP_DATAPOINT_BORDER_DASH_NAME, + ::getCppuType( reinterpret_cast< const ::rtl::OUString * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + rOutProperties.push_back( + Property( C2U( "BorderTransparency" ), + PROP_DATAPOINT_BORDER_TRANSPARENCY, + ::getCppuType( reinterpret_cast< const sal_Int16 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + + // Line Properties + // --------------- + rOutProperties.push_back( + Property( C2U( "LineStyle" ), + LineProperties::PROP_LINE_STYLE, + ::getCppuType( reinterpret_cast< const drawing::LineStyle * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "LineWidth" ), + LineProperties::PROP_LINE_WIDTH, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "LineDash" ), + LineProperties::PROP_LINE_DASH, + ::getCppuType( reinterpret_cast< const drawing::LineDash * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + rOutProperties.push_back( + Property( C2U( "LineDashName" ), + LineProperties::PROP_LINE_DASH_NAME, + ::getCppuType( reinterpret_cast< const ::rtl::OUString * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + + // FillProperties + // bitmap properties + rOutProperties.push_back( + Property( C2U( "FillBitmapOffsetX" ), + FillProperties::PROP_FILL_BITMAP_OFFSETX, + ::getCppuType( reinterpret_cast< const sal_Int16 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "FillBitmapOffsetY" ), + FillProperties::PROP_FILL_BITMAP_OFFSETY, + ::getCppuType( reinterpret_cast< const sal_Int16 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "FillBitmapPositionOffsetX" ), + FillProperties::PROP_FILL_BITMAP_POSITION_OFFSETX, + ::getCppuType( reinterpret_cast< const sal_Int16 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "FillBitmapPositionOffsetY" ), + FillProperties::PROP_FILL_BITMAP_POSITION_OFFSETY, + ::getCppuType( reinterpret_cast< const sal_Int16 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + + rOutProperties.push_back( + Property( C2U( "FillBitmapRectanglePoint" ), + FillProperties::PROP_FILL_BITMAP_RECTANGLEPOINT, + ::getCppuType( reinterpret_cast< const drawing::RectanglePoint * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "FillBitmapLogicalSize" ), + FillProperties::PROP_FILL_BITMAP_LOGICALSIZE, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "FillBitmapSizeX" ), + FillProperties::PROP_FILL_BITMAP_SIZEX, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "FillBitmapSizeY" ), + FillProperties::PROP_FILL_BITMAP_SIZEY, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "FillBitmapMode" ), + FillProperties::PROP_FILL_BITMAP_MODE, + ::getCppuType( reinterpret_cast< const drawing::BitmapMode * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + // others + rOutProperties.push_back( + Property( C2U( "Symbol" ), + PROP_DATAPOINT_SYMBOL_PROP, + ::getCppuType( reinterpret_cast< const chart2::Symbol * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "Offset" ), + PROP_DATAPOINT_OFFSET, + ::getCppuType( reinterpret_cast< const double * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "Geometry3D" ), + PROP_DATAPOINT_GEOMETRY3D, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "Label" ), + PROP_DATAPOINT_LABEL, + ::getCppuType( reinterpret_cast< const chart2::DataPointLabel * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "LabelSeparator" ), + PROP_DATAPOINT_LABEL_SEPARATOR, + ::getCppuType( reinterpret_cast< const ::rtl::OUString * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "NumberFormat" ), + PROP_DATAPOINT_NUMBER_FORMAT, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + + //additional 'PercentageNumberFormat' + rOutProperties.push_back( + Property( C2U( "PercentageNumberFormat" ), + PROP_DATAPOINT_PERCENTAGE_NUMBER_FORMAT, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "LabelPlacement" ), + PROP_DATAPOINT_LABEL_PLACEMENT, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "ReferencePageSize" ), + PROP_DATAPOINT_REFERENCE_DIAGRAM_SIZE, + ::getCppuType( reinterpret_cast< const awt::Size * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "TextRotation" ), + PROP_DATAPOINT_TEXT_ROTATION, + ::getCppuType( reinterpret_cast< const double * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + // statistics + rOutProperties.push_back( + Property( C2U( "ErrorBarX" ), + PROP_DATAPOINT_ERROR_BAR_X, + // XPropertySet supporting service ErrorBar + ::getCppuType( reinterpret_cast< const uno::Reference< beans::XPropertySet > * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + rOutProperties.push_back( + Property( C2U( "ErrorBarY" ), + PROP_DATAPOINT_ERROR_BAR_Y, + // XPropertySet supporting service ErrorBar + ::getCppuType( reinterpret_cast< const uno::Reference< beans::XPropertySet > * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + rOutProperties.push_back( + Property( C2U( "ShowErrorBox" ), + PROP_DATAPOINT_SHOW_ERROR_BOX, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + rOutProperties.push_back( + Property( C2U( "PercentDiagonal" ), + PROP_DATAPOINT_PERCENT_DIAGONAL, + ::getCppuType( reinterpret_cast< const sal_Int16 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); +} + +void DataPointProperties::AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_DATAPOINT_COLOR, 0x0099ccff ); // blue 8 + PropertyHelper::setPropertyValueDefault< sal_Int16 >( rOutMap, PROP_DATAPOINT_TRANSPARENCY, 0 ); + + //fill + PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DATAPOINT_FILL_STYLE, drawing::FillStyle_SOLID ); + PropertyHelper::setEmptyPropertyValueDefault( rOutMap, PROP_DATAPOINT_TRANSPARENCY_GRADIENT_NAME ); + PropertyHelper::setEmptyPropertyValueDefault( rOutMap, PROP_DATAPOINT_GRADIENT_NAME ); + PropertyHelper::setEmptyPropertyValueDefault( rOutMap, PROP_DATAPOINT_HATCH_NAME ); + PropertyHelper::setEmptyPropertyValueDefault( rOutMap, PROP_DATAPOINT_FILL_BITMAP_NAME ); + PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DATAPOINT_FILL_BACKGROUND, false ); + + //border + PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_DATAPOINT_BORDER_COLOR, 0x000000 ); // black + PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DATAPOINT_BORDER_STYLE, drawing::LineStyle_SOLID ); // drawing::LineStyle_NONE + PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_DATAPOINT_BORDER_WIDTH, 0 ); + PropertyHelper::setEmptyPropertyValueDefault( rOutMap, PROP_DATAPOINT_BORDER_DASH_NAME ); + PropertyHelper::setPropertyValueDefault< sal_Int16 >( rOutMap, PROP_DATAPOINT_BORDER_TRANSPARENCY, 0 ); + + //line + PropertyHelper::setPropertyValueDefault( rOutMap, LineProperties::PROP_LINE_STYLE, drawing::LineStyle_SOLID ); + PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, LineProperties::PROP_LINE_WIDTH, 0 ); + PropertyHelper::setPropertyValueDefault( rOutMap, LineProperties::PROP_LINE_DASH, drawing::LineDash()); + PropertyHelper::setEmptyPropertyValueDefault( rOutMap, LineProperties::PROP_LINE_DASH_NAME ); + + //fill bitmap + PropertyHelper::setPropertyValueDefault< sal_Int16 >( rOutMap, FillProperties::PROP_FILL_BITMAP_OFFSETX, 0 ); + PropertyHelper::setPropertyValueDefault< sal_Int16 >( rOutMap, FillProperties::PROP_FILL_BITMAP_OFFSETY, 0 ); + PropertyHelper::setPropertyValueDefault< sal_Int16 >( rOutMap, FillProperties::PROP_FILL_BITMAP_POSITION_OFFSETX, 0 ); + PropertyHelper::setPropertyValueDefault< sal_Int16 >( rOutMap, FillProperties::PROP_FILL_BITMAP_POSITION_OFFSETY, 0 ); + PropertyHelper::setPropertyValueDefault( rOutMap, FillProperties::PROP_FILL_BITMAP_RECTANGLEPOINT, drawing::RectanglePoint_MIDDLE_MIDDLE ); + PropertyHelper::setPropertyValueDefault( rOutMap, FillProperties::PROP_FILL_BITMAP_LOGICALSIZE, true ); + + PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, FillProperties::PROP_FILL_BITMAP_SIZEX, 0 ); + PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, FillProperties::PROP_FILL_BITMAP_SIZEY, 0 ); + PropertyHelper::setPropertyValueDefault( rOutMap, FillProperties::PROP_FILL_BITMAP_MODE, drawing::BitmapMode_REPEAT ); + + //others + chart2::Symbol aSymbProp; + aSymbProp.Style = chart2::SymbolStyle_NONE; + aSymbProp.StandardSymbol = 0; + aSymbProp.Size = awt::Size( 250, 250 ); // ca. 7pt x 7pt (7pt=246.94) + aSymbProp.BorderColor = 0x000000; // Black + aSymbProp.FillColor = 0xee4000; // OrangeRed2 + PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DATAPOINT_SYMBOL_PROP, aSymbProp ); + + PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_DATAPOINT_OFFSET, 0.0 ); + PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DATAPOINT_GEOMETRY3D, chart2::DataPointGeometry3D::CUBOID ); + + PropertyHelper::setPropertyValueDefault( + rOutMap, PROP_DATAPOINT_LABEL, + chart2::DataPointLabel( + sal_False, // ShowNumber + sal_False, // ShowNumberInPercent + sal_False, // ShowCategoryName + sal_False // ShowLegendSymbol + )); + + PropertyHelper::setPropertyValueDefault< rtl::OUString >( rOutMap, PROP_DATAPOINT_LABEL_SEPARATOR, C2U(" ") ); + + //@todo maybe choose a different one here -> should be dynamically that of the attached axis + PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DATAPOINT_ERROR_BAR_X, uno::Reference< beans::XPropertySet >()); + PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DATAPOINT_ERROR_BAR_Y, uno::Reference< beans::XPropertySet >()); + PropertyHelper::setPropertyValueDefault< sal_Int16 >( rOutMap, PROP_DATAPOINT_PERCENT_DIAGONAL, 0 ); + + PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_DATAPOINT_TEXT_ROTATION, 0.0 ); +} + +} // namespace chart diff --git a/chart2/source/model/main/DataPointProperties.hxx b/chart2/source/model/main/DataPointProperties.hxx new file mode 100644 index 000000000000..5d4d02af36ef --- /dev/null +++ b/chart2/source/model/main/DataPointProperties.hxx @@ -0,0 +1,101 @@ +/************************************************************************* + * + * 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_DATAPOINTPROPERTIES_HXX +#define CHART_DATAPOINTPROPERTIES_HXX + +#include "PropertyHelper.hxx" +#include "FastPropertyIdRanges.hxx" +#include <com/sun/star/beans/Property.hpp> + +#include <vector> + +namespace chart +{ + +// implements service DataPointProperties +class DataPointProperties +{ +public: + // FastProperty Ids for properties + enum + { + // common + PROP_DATAPOINT_COLOR = FAST_PROPERTY_ID_START_DATA_POINT, + PROP_DATAPOINT_TRANSPARENCY, + + // fill + PROP_DATAPOINT_FILL_STYLE, +// PROP_DATAPOINT_TRANSPARENCY_STYLE, + PROP_DATAPOINT_TRANSPARENCY_GRADIENT_NAME, + PROP_DATAPOINT_GRADIENT_NAME, + PROP_DATAPOINT_GRADIENT_STEPCOUNT, + PROP_DATAPOINT_HATCH_NAME, + PROP_DATAPOINT_FILL_BITMAP_NAME, + PROP_DATAPOINT_FILL_BACKGROUND, + + // border (of filled objects) + PROP_DATAPOINT_BORDER_COLOR, + PROP_DATAPOINT_BORDER_STYLE, + PROP_DATAPOINT_BORDER_WIDTH, + PROP_DATAPOINT_BORDER_DASH_NAME, + PROP_DATAPOINT_BORDER_TRANSPARENCY, + + // others + PROP_DATAPOINT_SYMBOL_PROP, + PROP_DATAPOINT_OFFSET, + PROP_DATAPOINT_GEOMETRY3D, + PROP_DATAPOINT_LABEL, + PROP_DATAPOINT_LABEL_SEPARATOR, + PROP_DATAPOINT_NUMBER_FORMAT, + PROP_DATAPOINT_PERCENTAGE_NUMBER_FORMAT, + PROP_DATAPOINT_LABEL_PLACEMENT, + PROP_DATAPOINT_REFERENCE_DIAGRAM_SIZE, + PROP_DATAPOINT_TEXT_ROTATION, + + // statistics + PROP_DATAPOINT_ERROR_BAR_X, + PROP_DATAPOINT_ERROR_BAR_Y, + PROP_DATAPOINT_SHOW_ERROR_BOX, + PROP_DATAPOINT_PERCENT_DIAGONAL + + // additionally some properites from ::chart::LineProperties + }; + + static void AddPropertiesToVector( + ::std::vector< ::com::sun::star::beans::Property > & rOutProperties ); + + static void AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap ); + +private: + // not implemented + DataPointProperties(); +}; + +} // namespace chart + +// CHART_DATAPOINTPROPERTIES_HXX +#endif diff --git a/chart2/source/model/main/DataSeries.cxx b/chart2/source/model/main/DataSeries.cxx new file mode 100644 index 000000000000..89197aa5ba3f --- /dev/null +++ b/chart2/source/model/main/DataSeries.cxx @@ -0,0 +1,624 @@ +/************************************************************************* + * + * 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 "DataSeries.hxx" +#include "DataSeriesProperties.hxx" +#include "DataPointProperties.hxx" +#include "CharacterProperties.hxx" +#include "UserDefinedProperties.hxx" +#include "DataPoint.hxx" +#include "macros.hxx" +#include "DataSeriesHelper.hxx" +#include "ContainerHelper.hxx" +#include "CloneHelper.hxx" +#include "ModifyListenerHelper.hxx" +#include "EventListenerHelper.hxx" + +#include <algorithm> + +using namespace ::com::sun::star; + +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 ::rtl::OUString; +using ::osl::MutexGuard; + +// ---------------------------------------- + +namespace +{ +const uno::Sequence< Property > & lcl_GetPropertySequence() +{ + static uno::Sequence< Property > aPropSeq; + + // /-- + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aPropSeq.getLength() ) + { + // get properties + ::std::vector< ::com::sun::star::beans::Property > aProperties; + ::chart::DataSeriesProperties::AddPropertiesToVector( aProperties ); + ::chart::CharacterProperties::AddPropertiesToVector( aProperties ); + ::chart::UserDefinedProperties::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; +} + +void lcl_SetParent( + const uno::Reference< uno::XInterface > & xChildInterface, + const uno::Reference< uno::XInterface > & xParentInterface ) +{ + uno::Reference< container::XChild > xChild( xChildInterface, uno::UNO_QUERY ); + if( xChild.is()) + xChild->setParent( xParentInterface ); +} + +typedef ::std::map< sal_Int32, ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > > + lcl_tDataPointMap; + +void lcl_CloneAttributedDataPoints( + const lcl_tDataPointMap & rSource, lcl_tDataPointMap & rDestination, + const uno::Reference< uno::XInterface > & xSeries ) +{ + for( lcl_tDataPointMap::const_iterator aIt( rSource.begin()); + aIt != rSource.end(); ++aIt ) + { + Reference< beans::XPropertySet > xPoint( (*aIt).second ); + if( xPoint.is()) + { + Reference< util::XCloneable > xCloneable( xPoint, uno::UNO_QUERY ); + if( xCloneable.is()) + { + xPoint.set( xCloneable->createClone(), uno::UNO_QUERY ); + if( xPoint.is()) + { + lcl_SetParent( xPoint, xSeries ); + rDestination.insert( lcl_tDataPointMap::value_type( (*aIt).first, xPoint )); + } + } + } + } +} + +} // anonymous namespace + +// ---------------------------------------- + +namespace chart +{ + +DataSeries::DataSeries( const uno::Reference< uno::XComponentContext > & xContext ) : + ::property::OPropertySet( m_aMutex ), + m_xContext( xContext ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{ +} + +DataSeries::DataSeries( const DataSeries & rOther ) : + MutexContainer(), + impl::DataSeries_Base(), + ::property::OPropertySet( rOther, m_aMutex ), + m_xContext( rOther.m_xContext ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{ + if( ! rOther.m_aDataSequences.empty()) + { + CloneHelper::CloneRefVector< tDataSequenceContainer::value_type >( + rOther.m_aDataSequences, m_aDataSequences ); + ModifyListenerHelper::addListenerToAllElements( m_aDataSequences, m_xModifyEventForwarder ); + } + + CloneHelper::CloneRefVector< Reference< chart2::XRegressionCurve > >( rOther.m_aRegressionCurves, m_aRegressionCurves ); + ModifyListenerHelper::addListenerToAllElements( m_aRegressionCurves, m_xModifyEventForwarder ); + + // add as listener to XPropertySet properties + Reference< beans::XPropertySet > xPropertySet; + uno::Any aValue; + + getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X ); + if( ( aValue >>= xPropertySet ) + && xPropertySet.is()) + ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder ); + + getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y ); + if( ( aValue >>= xPropertySet ) + && xPropertySet.is()) + ModifyListenerHelper::addListener( xPropertySet, m_xModifyEventForwarder ); +} + +// late initialization to call after copy-constructing +void DataSeries::Init( const DataSeries & rOther ) +{ + if( ! rOther.m_aDataSequences.empty()) + EventListenerHelper::addListenerToAllElements( m_aDataSequences, this ); + + Reference< uno::XInterface > xThisInterface( static_cast< ::cppu::OWeakObject * >( this )); + if( ! rOther.m_aAttributedDataPoints.empty()) + { + lcl_CloneAttributedDataPoints( + rOther.m_aAttributedDataPoints, m_aAttributedDataPoints, xThisInterface ); + ModifyListenerHelper::addListenerToAllMapElements( m_aAttributedDataPoints, m_xModifyEventForwarder ); + } + + // add as parent to error bars + Reference< beans::XPropertySet > xPropertySet; + uno::Any aValue; + + getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X ); + if( ( aValue >>= xPropertySet ) + && xPropertySet.is()) + lcl_SetParent( xPropertySet, xThisInterface ); + + getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y ); + if( ( aValue >>= xPropertySet ) + && xPropertySet.is()) + lcl_SetParent( xPropertySet, xThisInterface ); +} + +DataSeries::~DataSeries() +{ + try + { + ModifyListenerHelper::removeListenerFromAllMapElements( m_aAttributedDataPoints, m_xModifyEventForwarder ); + ModifyListenerHelper::removeListenerFromAllElements( m_aRegressionCurves, m_xModifyEventForwarder ); + ModifyListenerHelper::removeListenerFromAllElements( m_aDataSequences, m_xModifyEventForwarder ); + + // remove listener from XPropertySet properties + Reference< beans::XPropertySet > xPropertySet; + uno::Any aValue; + + getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X ); + if( ( aValue >>= xPropertySet ) + && xPropertySet.is()) + ModifyListenerHelper::removeListener( xPropertySet, m_xModifyEventForwarder ); + + getFastPropertyValue( aValue, DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y ); + 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 DataSeries::createClone() + throw (uno::RuntimeException) +{ + DataSeries * pNewSeries( new DataSeries( *this )); + // hold a reference to the clone + uno::Reference< util::XCloneable > xResult( pNewSeries ); + // do initialization that uses uno references to the clone + pNewSeries->Init( *this ); + + return xResult; +} + +Sequence< OUString > DataSeries::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 3 ); + aServices[ 0 ] = C2U( "com.sun.star.chart2.DataSeries" ); + aServices[ 1 ] = C2U( "com.sun.star.chart2.DataPointProperties" ); + aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +// ____ OPropertySet ____ +uno::Any DataSeries::GetDefaultValue( sal_Int32 nHandle ) const + throw(beans::UnknownPropertyException) +{ + static tPropertyValueMap aStaticDefaults; + + // /-- + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aStaticDefaults.size() ) + { + // initialize defaults + DataSeriesProperties::AddDefaultsToMap( aStaticDefaults ); + CharacterProperties::AddDefaultsToMap( aStaticDefaults ); + + float fDefaultCharHeight = 10.0; + ::chart::PropertyHelper::setPropertyValue( aStaticDefaults, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight ); + ::chart::PropertyHelper::setPropertyValue( aStaticDefaults, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight ); + ::chart::PropertyHelper::setPropertyValue( aStaticDefaults, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + throw beans::UnknownPropertyException(); + + return (*aFound).second; + // \-- +} + +// ____ OPropertySet ____ +::cppu::IPropertyArrayHelper & SAL_CALL DataSeries::getInfoHelper() +{ + static ::cppu::OPropertyArrayHelper aArrayHelper( + lcl_GetPropertySequence(), + /* bSorted = */ sal_True ); + + return aArrayHelper; +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + DataSeries::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; + // \-- +} + +void SAL_CALL DataSeries::getFastPropertyValue + ( uno::Any& rValue, + sal_Int32 nHandle ) const +{ + // special handling for get. set is not possible for this property + if( nHandle == DataSeriesProperties::PROP_DATASERIES_ATTRIBUTED_DATA_POINTS ) + { + // ToDo: only add those property sets that are really modified + uno::Sequence< sal_Int32 > aSeq( m_aAttributedDataPoints.size()); + sal_Int32 * pIndexArray = aSeq.getArray(); + sal_Int32 i = 0; + + for( tDataPointAttributeContainer::const_iterator aIt( m_aAttributedDataPoints.begin()); + aIt != m_aAttributedDataPoints.end(); ++aIt ) + { + pIndexArray[ i ] = (*aIt).first; + ++i; + } + + rValue <<= aSeq; + } + else + OPropertySet::getFastPropertyValue( rValue, nHandle ); +} + +void SAL_CALL DataSeries::setFastPropertyValue_NoBroadcast( + sal_Int32 nHandle, const uno::Any& rValue ) + throw (uno::Exception) +{ + if( nHandle == DataPointProperties::PROP_DATAPOINT_ERROR_BAR_Y + || nHandle == DataPointProperties::PROP_DATAPOINT_ERROR_BAR_X ) + { + 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 ); +} + +Reference< beans::XPropertySet > + SAL_CALL DataSeries::getDataPointByIndex( sal_Int32 nIndex ) + throw (lang::IndexOutOfBoundsException, + uno::RuntimeException) +{ + Reference< beans::XPropertySet > xResult; + + Sequence< Reference< chart2::data::XLabeledDataSequence > > aSequences; + { + MutexGuard aGuard( GetMutex() ); + aSequences = ContainerHelper::ContainerToSequence( m_aDataSequences ); + } + + ::std::vector< Reference< chart2::data::XLabeledDataSequence > > aValuesSeries( + DataSeriesHelper::getAllDataSequencesByRole( aSequences , C2U("values"), true ) ); + if( !aValuesSeries.empty() ) + { + Reference< chart2::data::XDataSequence > xSeq( aValuesSeries.front()->getValues() ); + if( 0 <= nIndex && nIndex < xSeq->getData().getLength() ) + { + { + MutexGuard aGuard( GetMutex() ); + tDataPointAttributeContainer::iterator aIt( m_aAttributedDataPoints.find( nIndex ) ); + if( aIt != m_aAttributedDataPoints.end() ) + xResult = (*aIt).second; + } + if( !xResult.is() ) + { + Reference< beans::XPropertySet > xParentProperties; + Reference< util::XModifyListener > xModifyEventForwarder; + { + MutexGuard aGuard( GetMutex() ); + xParentProperties = this; + xModifyEventForwarder = m_xModifyEventForwarder; + } + + // create a new XPropertySet for this data point + xResult.set( new DataPoint( xParentProperties ) ); + { + MutexGuard aGuard( GetMutex() ); + m_aAttributedDataPoints[ nIndex ] = xResult; + } + ModifyListenerHelper::addListener( xResult, xModifyEventForwarder ); + } + } + } + else + { + throw lang::IndexOutOfBoundsException(); + } + + return xResult; +} + +void SAL_CALL DataSeries::resetDataPoint( sal_Int32 nIndex ) + throw (uno::RuntimeException) +{ + Reference< beans::XPropertySet > xDataPointProp; + Reference< util::XModifyListener > xModifyEventForwarder; + { + MutexGuard aGuard( GetMutex() ); + xModifyEventForwarder = m_xModifyEventForwarder; + tDataPointAttributeContainer::iterator aIt( m_aAttributedDataPoints.find( nIndex )); + if( aIt != m_aAttributedDataPoints.end()) + { + xDataPointProp = (*aIt).second; + m_aAttributedDataPoints.erase(aIt); + } + + } + if( xDataPointProp.is() ) + { + Reference< util::XModifyBroadcaster > xBroadcaster( xDataPointProp, uno::UNO_QUERY ); + if( xBroadcaster.is() && xModifyEventForwarder.is()) + xBroadcaster->removeModifyListener( xModifyEventForwarder ); + fireModifyEvent(); + } +} + +void SAL_CALL DataSeries::resetAllDataPoints() + throw (uno::RuntimeException) +{ + tDataPointAttributeContainer aOldAttributedDataPoints; + Reference< util::XModifyListener > xModifyEventForwarder; + { + MutexGuard aGuard( GetMutex() ); + xModifyEventForwarder = m_xModifyEventForwarder; + std::swap( aOldAttributedDataPoints, m_aAttributedDataPoints ); + } + ModifyListenerHelper::removeListenerFromAllMapElements( aOldAttributedDataPoints, xModifyEventForwarder ); + aOldAttributedDataPoints.clear(); + fireModifyEvent(); +} + +// ____ XDataSink ____ +void SAL_CALL DataSeries::setData( const uno::Sequence< Reference< chart2::data::XLabeledDataSequence > >& aData ) + throw (uno::RuntimeException) +{ + tDataSequenceContainer aOldDataSequences; + tDataSequenceContainer aNewDataSequences; + Reference< util::XModifyListener > xModifyEventForwarder; + Reference< lang::XEventListener > xListener; + { + MutexGuard aGuard( GetMutex() ); + xModifyEventForwarder = m_xModifyEventForwarder; + xListener = this; + std::swap( aOldDataSequences, m_aDataSequences ); + aNewDataSequences = ContainerHelper::SequenceToVector( aData ); + m_aDataSequences = aNewDataSequences; + } + ModifyListenerHelper::removeListenerFromAllElements( aOldDataSequences, xModifyEventForwarder ); + EventListenerHelper::removeListenerFromAllElements( aOldDataSequences, xListener ); + EventListenerHelper::addListenerToAllElements( aNewDataSequences, xListener ); + ModifyListenerHelper::addListenerToAllElements( aNewDataSequences, xModifyEventForwarder ); + fireModifyEvent(); +} + +// ____ XDataSource ____ +Sequence< Reference< chart2::data::XLabeledDataSequence > > SAL_CALL DataSeries::getDataSequences() + throw (uno::RuntimeException) +{ + MutexGuard aGuard( GetMutex() ); + return ContainerHelper::ContainerToSequence( m_aDataSequences ); +} + + +// ____ XRegressionCurveContainer ____ +void SAL_CALL DataSeries::addRegressionCurve( + const uno::Reference< chart2::XRegressionCurve >& xRegressionCurve ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + Reference< util::XModifyListener > xModifyEventForwarder; + { + MutexGuard aGuard( GetMutex() ); + xModifyEventForwarder = m_xModifyEventForwarder; + if( ::std::find( m_aRegressionCurves.begin(), m_aRegressionCurves.end(), xRegressionCurve ) + != m_aRegressionCurves.end()) + throw lang::IllegalArgumentException(); + m_aRegressionCurves.push_back( xRegressionCurve ); + } + ModifyListenerHelper::addListener( xRegressionCurve, xModifyEventForwarder ); + fireModifyEvent(); +} + +void SAL_CALL DataSeries::removeRegressionCurve( + const uno::Reference< chart2::XRegressionCurve >& xRegressionCurve ) + throw (container::NoSuchElementException, + uno::RuntimeException) +{ + if( !xRegressionCurve.is() ) + throw container::NoSuchElementException(); + + Reference< util::XModifyListener > xModifyEventForwarder; + { + MutexGuard aGuard( GetMutex() ); + xModifyEventForwarder = m_xModifyEventForwarder; + tRegressionCurveContainerType::iterator aIt( + ::std::find( m_aRegressionCurves.begin(), m_aRegressionCurves.end(), xRegressionCurve ) ); + if( aIt == m_aRegressionCurves.end()) + throw container::NoSuchElementException( + C2U( "The given regression curve is no element of this series" ), + static_cast< uno::XWeak * >( this )); + m_aRegressionCurves.erase( aIt ); + } + + ModifyListenerHelper::removeListener( xRegressionCurve, xModifyEventForwarder ); + fireModifyEvent(); +} + +uno::Sequence< uno::Reference< chart2::XRegressionCurve > > SAL_CALL DataSeries::getRegressionCurves() + throw (uno::RuntimeException) +{ + MutexGuard aGuard( GetMutex() ); + return ContainerHelper::ContainerToSequence( m_aRegressionCurves ); +} + +void SAL_CALL DataSeries::setRegressionCurves( + const Sequence< Reference< chart2::XRegressionCurve > >& aRegressionCurves ) + throw (uno::RuntimeException) +{ + tRegressionCurveContainerType aOldCurves; + tRegressionCurveContainerType aNewCurves( ContainerHelper::SequenceToVector( aRegressionCurves ) ); + Reference< util::XModifyListener > xModifyEventForwarder; + { + MutexGuard aGuard( GetMutex() ); + xModifyEventForwarder = m_xModifyEventForwarder; + std::swap( aOldCurves, m_aRegressionCurves ); + m_aRegressionCurves = aNewCurves; + } + ModifyListenerHelper::removeListenerFromAllElements( aOldCurves, xModifyEventForwarder ); + ModifyListenerHelper::addListenerToAllElements( aNewCurves, xModifyEventForwarder ); + fireModifyEvent(); +} + +// ____ XModifyBroadcaster ____ +void SAL_CALL DataSeries::addModifyListener( const Reference< util::XModifyListener >& aListener ) + throw (uno::RuntimeException) +{ + try + { + Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW ); + xBroadcaster->addModifyListener( aListener ); + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +void SAL_CALL DataSeries::removeModifyListener( const Reference< util::XModifyListener >& aListener ) + throw (uno::RuntimeException) +{ + try + { + 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 DataSeries::modified( const lang::EventObject& aEvent ) + throw (uno::RuntimeException) +{ + m_xModifyEventForwarder->modified( aEvent ); +} + +// ____ XEventListener (base of XModifyListener) ____ +void SAL_CALL DataSeries::disposing( const lang::EventObject& rEventObject ) + throw (uno::RuntimeException) +{ + // forget disposed data sequences + tDataSequenceContainer::iterator aIt( + ::std::find( m_aDataSequences.begin(), m_aDataSequences.end(), rEventObject.Source )); + if( aIt != m_aDataSequences.end()) + m_aDataSequences.erase( aIt ); +} + +// ____ OPropertySet ____ +void DataSeries::firePropertyChangeEvent() +{ + fireModifyEvent(); +} + +void DataSeries::fireModifyEvent() +{ + m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); +} + + +// ================================================================================ + +using impl::DataSeries_Base; +using ::property::OPropertySet; + +IMPLEMENT_FORWARD_XINTERFACE2( DataSeries, DataSeries_Base, OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( DataSeries, DataSeries_Base, OPropertySet ) + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( DataSeries, + C2U( "com.sun.star.comp.chart.DataSeries" )); + +} // namespace chart diff --git a/chart2/source/model/main/DataSeriesProperties.cxx b/chart2/source/model/main/DataSeriesProperties.cxx new file mode 100644 index 000000000000..29a41bd38e14 --- /dev/null +++ b/chart2/source/model/main/DataSeriesProperties.cxx @@ -0,0 +1,98 @@ +/************************************************************************* + * + * 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 "DataSeriesProperties.hxx" +#include "DataPointProperties.hxx" +#include "DataPoint.hxx" +#include "macros.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/chart2/StackingDirection.hpp> + +#include <algorithm> + +using namespace ::com::sun::star; + +using ::rtl::OUString; +using ::com::sun::star::beans::Property; +using ::com::sun::star::uno::Reference; + +namespace chart +{ + +void DataSeriesProperties::AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "AttributedDataPoints" ), + PROP_DATASERIES_ATTRIBUTED_DATA_POINTS, + ::getCppuType( reinterpret_cast< const uno::Sequence< sal_Int32 > * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "StackingDirection" ), + PROP_DATASERIES_STACKING_DIRECTION, + ::getCppuType( reinterpret_cast< const chart2::StackingDirection * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "VaryColorsByPoint" ), + PROP_DATASERIES_VARY_COLORS_BY_POINT, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "AttachedAxisIndex" ), + PROP_DATASERIES_ATTACHED_AXIS_INDEX, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID + | beans::PropertyAttribute::MAYBEDEFAULT )); + + // add properties of service DataPointProperties + DataPointProperties::AddPropertiesToVector( rOutProperties ); +} + +void DataSeriesProperties::AddDefaultsToMap( + tPropertyValueMap & rOutMap ) +{ + PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DATASERIES_STACKING_DIRECTION, chart2::StackingDirection_NO_STACKING ); + PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DATASERIES_VARY_COLORS_BY_POINT, false ); + PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_DATASERIES_ATTACHED_AXIS_INDEX, 0 ); + + // PROP_DATASERIES_ATTRIBUTED_DATA_POINTS has no default + + // add properties of service DataPointProperties + DataPointProperties::AddDefaultsToMap( rOutMap ); +} + +} // namespace chart diff --git a/chart2/source/model/main/DataSeriesProperties.hxx b/chart2/source/model/main/DataSeriesProperties.hxx new file mode 100644 index 000000000000..6805b80c975b --- /dev/null +++ b/chart2/source/model/main/DataSeriesProperties.hxx @@ -0,0 +1,63 @@ +/************************************************************************* + * + * 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_DATASERIESPROPERTIES_HXX +#define CHART_DATASERIESPROPERTIES_HXX + +#include "PropertyHelper.hxx" +#include "FastPropertyIdRanges.hxx" +#include <com/sun/star/beans/Property.hpp> + +#include <vector> + +namespace chart +{ + +class DataSeriesProperties +{ +public: + enum + { + PROP_DATASERIES_ATTRIBUTED_DATA_POINTS = FAST_PROPERTY_ID_START_DATA_SERIES, + PROP_DATASERIES_STACKING_DIRECTION, + PROP_DATASERIES_VARY_COLORS_BY_POINT, + PROP_DATASERIES_ATTACHED_AXIS_INDEX + }; + + static void AddPropertiesToVector( + ::std::vector< ::com::sun::star::beans::Property > & rOutProperties ); + + static void AddDefaultsToMap( tPropertyValueMap & rOutMap ); + +private: + // not implemented + DataSeriesProperties(); +}; + +} // namespace chart + +// CHART_DATASERIESPROPERTIES_HXX +#endif diff --git a/chart2/source/model/main/Diagram.cxx b/chart2/source/model/main/Diagram.cxx new file mode 100644 index 000000000000..ff8a0c4030bc --- /dev/null +++ b/chart2/source/model/main/Diagram.cxx @@ -0,0 +1,713 @@ +/************************************************************************* + * + * 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 "Diagram.hxx" +#include "macros.hxx" +#include "PropertyHelper.hxx" +#include "Wall.hxx" +#include "UserDefinedProperties.hxx" +#include "ConfigColorScheme.hxx" +#include "ContainerHelper.hxx" +#include "ThreeDHelper.hxx" +#include "CloneHelper.hxx" +#include "AxisHelper.hxx" +#include "SceneProperties.hxx" +#include "DisposeHelper.hxx" +#include "BaseGFXHelper.hxx" +#include <basegfx/numeric/ftools.hxx> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/chart2/RelativePosition.hpp> +#include <com/sun/star/chart2/RelativeSize.hpp> +#include <com/sun/star/drawing/CameraGeometry.hpp> + +#include <com/sun/star/drawing/HomogenMatrix.hpp> + +#include <algorithm> +#include <iterator> +#include <functional> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::beans::PropertyAttribute; + +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_DIAGRAM_REL_POS, + PROP_DIAGRAM_REL_SIZE, + PROP_DIAGRAM_POSSIZE_EXCLUDE_LABELS, + PROP_DIAGRAM_SORT_BY_X_VALUES, + PROP_DIAGRAM_CONNECT_BARS, + PROP_DIAGRAM_GROUP_BARS_PER_AXIS, + PROP_DIAGRAM_INCLUDE_HIDDEN_CELLS, + PROP_DIAGRAM_STARTING_ANGLE, + PROP_DIAGRAM_RIGHT_ANGLED_AXES, + PROP_DIAGRAM_PERSPECTIVE, + PROP_DIAGRAM_ROTATION_HORIZONTAL, + PROP_DIAGRAM_ROTATION_VERTICAL, + PROP_DIAGRAM_MISSING_VALUE_TREATMENT +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "RelativePosition" ), + PROP_DIAGRAM_REL_POS, + ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "RelativeSize" ), + PROP_DIAGRAM_REL_SIZE, + ::getCppuType( reinterpret_cast< const chart2::RelativeSize * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "PosSizeExcludeAxes" ), + PROP_DIAGRAM_POSSIZE_EXCLUDE_LABELS, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "SortByXValues" ), + PROP_DIAGRAM_SORT_BY_X_VALUES, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U("ConnectBars"), + PROP_DIAGRAM_CONNECT_BARS, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U("GroupBarsPerAxis"), + PROP_DIAGRAM_GROUP_BARS_PER_AXIS, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U("IncludeHiddenCells"), + PROP_DIAGRAM_INCLUDE_HIDDEN_CELLS, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "StartingAngle" ), + PROP_DIAGRAM_STARTING_ANGLE, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0) ), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U("RightAngledAxes"), + PROP_DIAGRAM_RIGHT_ANGLED_AXES, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U("Perspective"), + PROP_DIAGRAM_PERSPECTIVE, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U("RotationHorizontal"), + PROP_DIAGRAM_ROTATION_HORIZONTAL, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U("RotationVertical"), + PROP_DIAGRAM_ROTATION_VERTICAL, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "MissingValueTreatment" ), + PROP_DIAGRAM_MISSING_VALUE_TREATMENT, + ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_POSSIZE_EXCLUDE_LABELS, true ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_SORT_BY_X_VALUES, false ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_CONNECT_BARS, false ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_GROUP_BARS_PER_AXIS, true ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_INCLUDE_HIDDEN_CELLS, true ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_DIAGRAM_RIGHT_ANGLED_AXES, false ); + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_DIAGRAM_STARTING_ANGLE, 90 ); +} + +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 ); + ::chart::SceneProperties::AddPropertiesToVector( aProperties ); + ::chart::UserDefinedProperties::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; +} + +/// clones a UNO-sequence of UNO-References +typedef Reference< chart2::XCoordinateSystem > lcl_tCooSysRef; +typedef ::std::map< lcl_tCooSysRef, lcl_tCooSysRef > lcl_tCooSysMapping; +typedef ::std::vector< lcl_tCooSysRef > lcl_tCooSysVector; + +lcl_tCooSysMapping lcl_CloneCoordinateSystems( + const lcl_tCooSysVector & rSource, + lcl_tCooSysVector & rDestination ) +{ + lcl_tCooSysMapping aResult; + + for( lcl_tCooSysVector::const_iterator aIt( rSource.begin()); + aIt != rSource.end(); ++aIt ) + { + lcl_tCooSysRef xClone; + ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > + xCloneable( *aIt, ::com::sun::star::uno::UNO_QUERY ); + if( xCloneable.is()) + xClone.set( xCloneable->createClone(), ::com::sun::star::uno::UNO_QUERY ); + + if( xClone.is()) + { + rDestination.push_back( xClone ); + aResult.insert( lcl_tCooSysMapping::value_type( *aIt, xClone )); + } + else + rDestination.push_back( *aIt ); + } + + return aResult; +} + +} // anonymous namespace + +// ====================================================================== + +namespace chart +{ + +Diagram::Diagram( uno::Reference< uno::XComponentContext > const & xContext ) : + ::property::OPropertySet( m_aMutex ), + m_xContext( xContext ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{ + // Set camera position to a default position (that should be set hard, so + // that it will be exported. The property default is a camera looking + // straight ono the scene). These defaults have been acquired from the old + // chart implemetation. + setFastPropertyValue_NoBroadcast( + SceneProperties::PROP_SCENE_CAMERA_GEOMETRY, uno::makeAny( + ThreeDHelper::getDefaultCameraGeometry())); +} + +Diagram::Diagram( const Diagram & rOther ) : + MutexContainer(), + impl::Diagram_Base(), + ::property::OPropertySet( rOther, m_aMutex ), + m_xContext( rOther.m_xContext ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{ + lcl_tCooSysMapping aCooSysMapping = + lcl_CloneCoordinateSystems( rOther.m_aCoordSystems, m_aCoordSystems ); + ModifyListenerHelper::addListenerToAllElements( m_aCoordSystems, m_xModifyEventForwarder ); + + m_xWall.set( CloneHelper::CreateRefClone< Reference< beans::XPropertySet > >()( rOther.m_xWall )); + m_xFloor.set( CloneHelper::CreateRefClone< Reference< beans::XPropertySet > >()( rOther.m_xFloor )); + m_xTitle.set( CloneHelper::CreateRefClone< Reference< chart2::XTitle > >()( rOther.m_xTitle )); + m_xLegend.set( CloneHelper::CreateRefClone< Reference< chart2::XLegend > >()( rOther.m_xLegend )); + + ModifyListenerHelper::addListener( m_xWall, m_xModifyEventForwarder ); + ModifyListenerHelper::addListener( m_xFloor, m_xModifyEventForwarder ); + ModifyListenerHelper::addListener( m_xTitle, m_xModifyEventForwarder ); + ModifyListenerHelper::addListener( m_xLegend, m_xModifyEventForwarder ); +} + +Diagram::~Diagram() +{ + try + { + ModifyListenerHelper::removeListenerFromAllElements( m_aCoordSystems, m_xModifyEventForwarder ); + + ModifyListenerHelper::removeListener( m_xWall, m_xModifyEventForwarder ); + ModifyListenerHelper::removeListener( m_xFloor, m_xModifyEventForwarder ); + ModifyListenerHelper::removeListener( m_xTitle, m_xModifyEventForwarder ); + ModifyListenerHelper::removeListener( m_xLegend, m_xModifyEventForwarder ); + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +// ____ XDiagram ____ +uno::Reference< beans::XPropertySet > SAL_CALL Diagram::getWall() + throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xRet; + bool bAddListener = false; + { + MutexGuard aGuard( GetMutex() ); + if( !m_xWall.is() ) + { + m_xWall.set( new Wall() ); + bAddListener = true; + } + xRet = m_xWall; + } + if(bAddListener) + ModifyListenerHelper::addListener( xRet, m_xModifyEventForwarder ); + return xRet; +} + +uno::Reference< beans::XPropertySet > SAL_CALL Diagram::getFloor() + throw (uno::RuntimeException) +{ + uno::Reference< beans::XPropertySet > xRet; + bool bAddListener = false; + { + MutexGuard aGuard( GetMutex() ); + if( !m_xFloor.is() ) + { + m_xFloor.set( new Wall() ); + bAddListener = true; + } + xRet = m_xFloor; + } + if(bAddListener) + ModifyListenerHelper::addListener( xRet, m_xModifyEventForwarder ); + return xRet; +} + +uno::Reference< chart2::XLegend > SAL_CALL Diagram::getLegend() + throw (uno::RuntimeException) +{ + MutexGuard aGuard( GetMutex() ); + return m_xLegend; +} + +void SAL_CALL Diagram::setLegend( const uno::Reference< chart2::XLegend >& xNewLegend ) + throw (uno::RuntimeException) +{ + Reference< chart2::XLegend > xOldLegend; + { + MutexGuard aGuard( GetMutex() ); + if( m_xLegend == xNewLegend ) + return; + xOldLegend = m_xLegend; + m_xLegend = xNewLegend; + } + if( xOldLegend.is()) + ModifyListenerHelper::removeListener( xOldLegend, m_xModifyEventForwarder ); + if( xNewLegend.is()) + ModifyListenerHelper::addListener( xNewLegend, m_xModifyEventForwarder ); + fireModifyEvent(); +} + +Reference< chart2::XColorScheme > SAL_CALL Diagram::getDefaultColorScheme() + throw (uno::RuntimeException) +{ + Reference< chart2::XColorScheme > xRet; + { + MutexGuard aGuard( GetMutex() ); + xRet = m_xColorScheme; + } + + if( !xRet.is()) + { + xRet.set( createConfigColorScheme( m_xContext )); + MutexGuard aGuard( GetMutex() ); + m_xColorScheme = xRet; + } + return xRet; +} + +void SAL_CALL Diagram::setDefaultColorScheme( const Reference< chart2::XColorScheme >& xColorScheme ) + throw (uno::RuntimeException) +{ + { + MutexGuard aGuard( GetMutex() ); + m_xColorScheme.set( xColorScheme ); + } + fireModifyEvent(); +} + +// ____ XTitled ____ +uno::Reference< chart2::XTitle > SAL_CALL Diagram::getTitleObject() + throw (uno::RuntimeException) +{ + MutexGuard aGuard( GetMutex() ); + return m_xTitle; +} + +void SAL_CALL Diagram::setTitleObject( const uno::Reference< chart2::XTitle >& xNewTitle ) + throw (uno::RuntimeException) +{ + Reference< chart2::XTitle > xOldTitle; + { + MutexGuard aGuard( GetMutex() ); + if( m_xTitle == xNewTitle ) + return; + xOldTitle = m_xTitle; + m_xTitle = xNewTitle; + } + if( xOldTitle.is()) + ModifyListenerHelper::removeListener( xOldTitle, m_xModifyEventForwarder ); + if( xNewTitle.is()) + ModifyListenerHelper::addListener( xNewTitle, m_xModifyEventForwarder ); + fireModifyEvent(); +} + +// ____ X3DDefaultSetter ____ +void SAL_CALL Diagram::set3DSettingsToDefault() + throw (uno::RuntimeException) +{ + ThreeDHelper::set3DSettingsToDefault( this ); +} + +void SAL_CALL Diagram::setDefaultRotation() + throw (uno::RuntimeException) +{ + ThreeDHelper::setDefaultRotation( this ); +} + +void SAL_CALL Diagram::setDefaultIllumination() + throw (uno::RuntimeException) +{ + ThreeDHelper::setDefaultIllumination( this ); +} + +// ____ XCoordinateSystemContainer ____ +void SAL_CALL Diagram::addCoordinateSystem( + const uno::Reference< chart2::XCoordinateSystem >& aCoordSys ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + { + MutexGuard aGuard( GetMutex() ); + if( ::std::find( m_aCoordSystems.begin(), m_aCoordSystems.end(), aCoordSys ) + != m_aCoordSystems.end()) + throw lang::IllegalArgumentException(); + + if( m_aCoordSystems.size()>=1 ) + { + OSL_ENSURE( false, "more than one coordinatesystem is not supported yet by the fileformat" ); + return; + } + m_aCoordSystems.push_back( aCoordSys ); + } + ModifyListenerHelper::addListener( aCoordSys, m_xModifyEventForwarder ); + fireModifyEvent(); +} + +void SAL_CALL Diagram::removeCoordinateSystem( + const uno::Reference< chart2::XCoordinateSystem >& aCoordSys ) + throw (container::NoSuchElementException, + uno::RuntimeException) +{ + { + MutexGuard aGuard( GetMutex() ); + ::std::vector< uno::Reference< chart2::XCoordinateSystem > >::iterator + aIt( ::std::find( m_aCoordSystems.begin(), m_aCoordSystems.end(), aCoordSys )); + if( aIt == m_aCoordSystems.end()) + throw container::NoSuchElementException( + C2U( "The given coordinate-system is no element of the container" ), + static_cast< uno::XWeak * >( this )); + m_aCoordSystems.erase( aIt ); + } + ModifyListenerHelper::removeListener( aCoordSys, m_xModifyEventForwarder ); + fireModifyEvent(); +} + +uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > SAL_CALL Diagram::getCoordinateSystems() + throw (uno::RuntimeException) +{ + MutexGuard aGuard( GetMutex() ); + return ContainerHelper::ContainerToSequence( m_aCoordSystems ); +} + +void SAL_CALL Diagram::setCoordinateSystems( + const Sequence< Reference< chart2::XCoordinateSystem > >& aCoordinateSystems ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + tCoordinateSystemContainerType aNew; + tCoordinateSystemContainerType aOld; + if( aCoordinateSystems.getLength()>0 ) + { + OSL_ENSURE( aCoordinateSystems.getLength()<=1, "more than one coordinatesystem is not supported yet by the fileformat" ); + aNew.push_back( aCoordinateSystems[0] ); + } + { + MutexGuard aGuard( GetMutex() ); + std::swap( aOld, m_aCoordSystems ); + m_aCoordSystems = aNew; + } + ModifyListenerHelper::removeListenerFromAllElements( aOld, m_xModifyEventForwarder ); + ModifyListenerHelper::addListenerToAllElements( aNew, m_xModifyEventForwarder ); + fireModifyEvent(); +} + +// ____ XCloneable ____ +Reference< util::XCloneable > SAL_CALL Diagram::createClone() + throw (uno::RuntimeException) +{ + MutexGuard aGuard( GetMutex() ); + return Reference< util::XCloneable >( new Diagram( *this )); +} + +// ____ XModifyBroadcaster ____ +void SAL_CALL Diagram::addModifyListener( const Reference< util::XModifyListener >& aListener ) + throw (uno::RuntimeException) +{ + try + { + Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW ); + xBroadcaster->addModifyListener( aListener ); + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +void SAL_CALL Diagram::removeModifyListener( const Reference< util::XModifyListener >& aListener ) + throw (uno::RuntimeException) +{ + try + { + 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 Diagram::modified( const lang::EventObject& aEvent ) + throw (uno::RuntimeException) +{ + m_xModifyEventForwarder->modified( aEvent ); +} + +// ____ XEventListener (base of XModifyListener) ____ +void SAL_CALL Diagram::disposing( const lang::EventObject& /* Source */ ) + throw (uno::RuntimeException) +{ + // nothing +} + +// ____ OPropertySet ____ +void Diagram::firePropertyChangeEvent() +{ + fireModifyEvent(); +} + +void Diagram::fireModifyEvent() +{ + m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); +} + +// ============================================================ + +Sequence< OUString > Diagram::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 3 ); + + aServices[ 0 ] = C2U( "com.sun.star.chart2.Diagram" ); + aServices[ 1 ] = C2U( "com.sun.star.layout.LayoutElement" ); + aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +// ____ OPropertySet ____ +uno::Any Diagram::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 ); + ::chart::SceneProperties::AddDefaultsToMap( aStaticDefaults ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; + // \-- +} + +// ____ OPropertySet ____ +::cppu::IPropertyArrayHelper & SAL_CALL Diagram::getInfoHelper() +{ + static ::cppu::OPropertyArrayHelper aArrayHelper( lcl_GetPropertySequence(), + /* bSorted = */ sal_True ); + + return aArrayHelper; +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + Diagram::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; + // \-- +} + +// ____ XFastPropertySet ____ +void SAL_CALL Diagram::setFastPropertyValue( sal_Int32 nHandle, const Any& rValue ) + throw(beans::UnknownPropertyException, + beans::PropertyVetoException, + lang::IllegalArgumentException, + lang::WrappedTargetException, uno::RuntimeException) +{ + //special treatment for some 3D properties + if( PROP_DIAGRAM_PERSPECTIVE == nHandle ) + { + sal_Int32 fPerspective = 20; + if( rValue >>=fPerspective ) + ThreeDHelper::setCameraDistance( this, ThreeDHelper::PerspectiveToCameraDistance( fPerspective ) ); + } + else if( PROP_DIAGRAM_ROTATION_HORIZONTAL == nHandle + || PROP_DIAGRAM_ROTATION_VERTICAL == nHandle ) + { + sal_Int32 nNewAngleDegree = 0; + if( rValue >>=nNewAngleDegree ) + { + sal_Int32 nHorizontal, nVertical; + ThreeDHelper::getRotationFromDiagram( const_cast< Diagram* >( this ), nHorizontal, nVertical ); + if( PROP_DIAGRAM_ROTATION_HORIZONTAL == nHandle ) + nHorizontal = nNewAngleDegree; + else + nVertical = nNewAngleDegree; + ThreeDHelper::setRotationToDiagram( this, nHorizontal, nVertical ); + } + } + else + ::property::OPropertySet::setFastPropertyValue( nHandle, rValue ); +} + +void SAL_CALL Diagram::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const +{ + //special treatment for some 3D properties + if( nHandle == PROP_DIAGRAM_PERSPECTIVE ) + { + sal_Int32 nPerspective = ::basegfx::fround( ThreeDHelper::CameraDistanceToPerspective( + ThreeDHelper::getCameraDistance( const_cast< Diagram* >( this ) ) ) ); + rValue = uno::makeAny(nPerspective); + } + else if( PROP_DIAGRAM_ROTATION_HORIZONTAL == nHandle + || PROP_DIAGRAM_ROTATION_VERTICAL == nHandle ) + { + sal_Int32 nHorizontal, nVertical; + ThreeDHelper::getRotationFromDiagram( const_cast< Diagram* >( this ), nHorizontal, nVertical ); + sal_Int32 nAngleDegree = 0; + if( PROP_DIAGRAM_ROTATION_HORIZONTAL == nHandle ) + nAngleDegree = nHorizontal; + else + nAngleDegree = nVertical; + rValue = uno::makeAny(nAngleDegree); + } + else + ::property::OPropertySet::getFastPropertyValue( rValue,nHandle ); +} + +// ================================================================================ + +using impl::Diagram_Base; + +IMPLEMENT_FORWARD_XINTERFACE2( Diagram, Diagram_Base, ::property::OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( Diagram, Diagram_Base, ::property::OPropertySet ) + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( Diagram, + C2U( "com.sun.star.comp.chart2.Diagram" )); + +} // namespace chart diff --git a/chart2/source/model/main/FormattedString.cxx b/chart2/source/model/main/FormattedString.cxx new file mode 100644 index 000000000000..9d38fafd3cf7 --- /dev/null +++ b/chart2/source/model/main/FormattedString.cxx @@ -0,0 +1,263 @@ +/************************************************************************* + * + * 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 "FormattedString.hxx" +#include "ContainerHelper.hxx" + +#include "CharacterProperties.hxx" +#include "PropertyHelper.hxx" +#include "macros.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 +{ + +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; + ::chart::CharacterProperties::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 +{ + +FormattedString::FormattedString( + uno::Reference< uno::XComponentContext > const & /* xContext */ ) : + ::property::OPropertySet( m_aMutex ), + m_aString(), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{} + +FormattedString::FormattedString( const FormattedString & rOther ) : + MutexContainer(), + impl::FormattedString_Base(), + ::property::OPropertySet( rOther, m_aMutex ), + m_aString( rOther.m_aString ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{} + +FormattedString::~FormattedString() +{} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL FormattedString::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new FormattedString( *this )); +} + +// ____ XFormattedString ____ +::rtl::OUString SAL_CALL FormattedString::getString() + throw (uno::RuntimeException) +{ + // /-- + MutexGuard aGuard( GetMutex()); + return m_aString; + // \-- +} + +void SAL_CALL FormattedString::setString( const ::rtl::OUString& String ) + throw (uno::RuntimeException) +{ + { + MutexGuard aGuard( GetMutex()); + m_aString = String; + } + //don't keep the mutex locked while calling out + fireModifyEvent(); + +} + +// ____ XModifyBroadcaster ____ +void SAL_CALL FormattedString::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 FormattedString::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 FormattedString::modified( const lang::EventObject& aEvent ) + throw (uno::RuntimeException) +{ + m_xModifyEventForwarder->modified( aEvent ); +} + +// ____ XEventListener (base of XModifyListener) ____ +void SAL_CALL FormattedString::disposing( const lang::EventObject& /* Source */ ) + throw (uno::RuntimeException) +{ + // nothing +} + +// ____ OPropertySet ____ +void FormattedString::firePropertyChangeEvent() +{ + fireModifyEvent(); +} + +void FormattedString::fireModifyEvent() +{ + m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); +} + + +// ---------------------------------------- + +Sequence< OUString > FormattedString::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 2 ); + + aServices[ 0 ] = C2U( "com.sun.star.chart2.FormattedString" ); + aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +// ____ OPropertySet ____ +uno::Any FormattedString::GetDefaultValue( sal_Int32 nHandle ) const + throw(beans::UnknownPropertyException) +{ + static tPropertyValueMap aStaticDefaults; + + // /-- + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aStaticDefaults.size() ) + { + // initialize defaults + CharacterProperties::AddDefaultsToMap( aStaticDefaults ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + throw beans::UnknownPropertyException(); + + return (*aFound).second; + // \-- +} + +// ____ OPropertySet ____ +::cppu::IPropertyArrayHelper & SAL_CALL FormattedString::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + FormattedString::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; + // \-- +} + +// ================================================================================ + +using impl::FormattedString_Base; + +IMPLEMENT_FORWARD_XINTERFACE2( FormattedString, FormattedString_Base, ::property::OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( FormattedString, FormattedString_Base, ::property::OPropertySet ) + +// do this in derived classes! + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( FormattedString, + C2U( "com.sun.star.comp.chart.FormattedString" )); + +} // namespace chart diff --git a/chart2/source/model/main/FormattedString.hxx b/chart2/source/model/main/FormattedString.hxx new file mode 100644 index 000000000000..9293d73afa5b --- /dev/null +++ b/chart2/source/model/main/FormattedString.hxx @@ -0,0 +1,140 @@ +/************************************************************************* + * + * 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_FORMATTEDSTRING_HXX +#define CHART_FORMATTEDSTRING_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/XFormattedString.hpp> +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> + +namespace chart +{ + +namespace impl +{ +typedef ::cppu::WeakImplHelper5< + ::com::sun::star::chart2::XFormattedString, + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::util::XCloneable, + ::com::sun::star::util::XModifyBroadcaster, + ::com::sun::star::util::XModifyListener > + FormattedString_Base; +} + +class FormattedString : + public MutexContainer, + public impl::FormattedString_Base, + public ::property::OPropertySet +{ +public: + FormattedString( ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~FormattedString(); + + /// declare XServiceInfo methods + APPHELPER_XSERVICEINFO_DECL() + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( FormattedString ) + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + explicit FormattedString( const FormattedString & rOther ); + + // ____ XFormattedString ____ + virtual ::rtl::OUString SAL_CALL getString() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setString( const ::rtl::OUString& String ) + 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); + +// virtual sal_Bool SAL_CALL convertFastPropertyValue +// ( ::com::sun::star::uno::Any & rConvertedValue, +// ::com::sun::star::uno::Any & rOldValue, +// sal_Int32 nHandle, +// const ::com::sun::star::uno::Any& rValue ) +// throw (::com::sun::star::lang::IllegalArgumentException); + + // ____ XCloneable ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() + throw (::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); + + // ____ OPropertySet ____ + virtual void firePropertyChangeEvent(); + using OPropertySet::disposing; + + void fireModifyEvent(); + +private: + ::rtl::OUString m_aString; + + ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xModifyEventForwarder; +}; + +} // namespace chart + +// CHART_FORMATTEDSTRING_HXX +#endif diff --git a/chart2/source/model/main/GridProperties.cxx b/chart2/source/model/main/GridProperties.cxx new file mode 100644 index 000000000000..a8d5be5d1453 --- /dev/null +++ b/chart2/source/model/main/GridProperties.cxx @@ -0,0 +1,273 @@ +/************************************************************************* + * + * 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 "GridProperties.hxx" +#include "LineProperties.hxx" +#include "UserDefinedProperties.hxx" +#include "PropertyHelper.hxx" +#include "macros.hxx" +#include "ContainerHelper.hxx" +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uno/Sequence.hxx> + +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 ::rtl::OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.GridProperties" )); + +enum +{ + PROP_GRID_SHOW +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "Show" ), + PROP_GRID_SHOW, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); +} + +void lcl_addDefaultsToMap( ::chart::tPropertyValueMap & rOutMap ) +{ + ::chart::LineProperties::AddDefaultsToMap( rOutMap ); + + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_GRID_SHOW, false ); + + // override other defaults + ::chart::PropertyHelper::setPropertyValue< sal_Int32 >( + rOutMap, ::chart::LineProperties::PROP_LINE_COLOR, 0xb3b3b3 ); // gray30 +} + +const Sequence< Property > & lcl_getPropertySequence() +{ + static Sequence< Property > aPropSeq; + + // /-- + MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aPropSeq.getLength() ) + { + // get properties + ::std::vector< Property > aProperties; + lcl_AddPropertiesToVector( aProperties ); + ::chart::LineProperties::AddPropertiesToVector( aProperties ); + ::chart::UserDefinedProperties::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 +{ + +GridProperties::GridProperties( Reference< uno::XComponentContext > const & /* xContext */ ) : + ::property::OPropertySet( m_aMutex ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{ +} + +GridProperties::GridProperties() : + ::property::OPropertySet( m_aMutex ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{} + +GridProperties::GridProperties( const GridProperties & rOther ) : + MutexContainer(), + impl::GridProperties_Base(), + ::property::OPropertySet( rOther, m_aMutex ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{ +} + +GridProperties::~GridProperties() +{} + +// ____ OPropertySet ____ +uno::Any GridProperties::GetDefaultValue( sal_Int32 nHandle ) const + throw(beans::UnknownPropertyException) +{ + static tPropertyValueMap aStaticDefaults; + + // /-- + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aStaticDefaults.size() ) + lcl_addDefaultsToMap( aStaticDefaults ); + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; + // \-- +} + +::cppu::IPropertyArrayHelper & SAL_CALL GridProperties::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + +// ____ XPropertySet ____ +Reference< beans::XPropertySetInfo > SAL_CALL + GridProperties::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static Reference< beans::XPropertySetInfo > xInfo; + + // /-- + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + lcl_getInfoHelper()); + } + + return xInfo; + // \-- +} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL GridProperties::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new GridProperties( *this )); +} + +// ____ XModifyBroadcaster ____ +void SAL_CALL GridProperties::addModifyListener( const Reference< util::XModifyListener >& aListener ) + throw (uno::RuntimeException) +{ + try + { + Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW ); + xBroadcaster->addModifyListener( aListener ); + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +void SAL_CALL GridProperties::removeModifyListener( const Reference< util::XModifyListener >& aListener ) + throw (uno::RuntimeException) +{ + try + { + 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 GridProperties::modified( const lang::EventObject& aEvent ) + throw (uno::RuntimeException) +{ + m_xModifyEventForwarder->modified( aEvent ); +} + +// ____ XEventListener (base of XModifyListener) ____ +void SAL_CALL GridProperties::disposing( const lang::EventObject& /* Source */ ) + throw (uno::RuntimeException) +{ + // nothing +} + +// ____ OPropertySet ____ +void GridProperties::firePropertyChangeEvent() +{ + fireModifyEvent(); +} + +void GridProperties::fireModifyEvent() +{ + m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); +} + +// ================================================================================ + +Sequence< OUString > GridProperties::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 2 ); + aServices[ 0 ] = C2U( "com.sun.star.chart2.GridProperties" ); + aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( GridProperties, lcl_aServiceName ); + +// needed by MSC compiler +using impl::GridProperties_Base; + +IMPLEMENT_FORWARD_XINTERFACE2( GridProperties, GridProperties_Base, ::property::OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( GridProperties, GridProperties_Base, ::property::OPropertySet ) + +} // namespace chart diff --git a/chart2/source/model/main/GridProperties.hxx b/chart2/source/model/main/GridProperties.hxx new file mode 100644 index 000000000000..1c0ae0ed849a --- /dev/null +++ b/chart2/source/model/main/GridProperties.hxx @@ -0,0 +1,128 @@ +/************************************************************************* + * + * 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_GRIDPROPERTIES_HXX +#define CHART_GRIDPROPERTIES_HXX + +#include "ServiceMacros.hxx" +#include <osl/mutex.hxx> +#include <cppuhelper/implbase4.hxx> +#include <comphelper/uno3.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/util/XModifyBroadcaster.hpp> +#include <com/sun/star/util/XModifyListener.hpp> + +#include "OPropertySet.hxx" +#include "MutexContainer.hxx" +#include "ModifyListenerHelper.hxx" + +namespace chart +{ + +namespace impl +{ +typedef ::cppu::WeakImplHelper4< + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::util::XCloneable, + ::com::sun::star::util::XModifyBroadcaster, + ::com::sun::star::util::XModifyListener > + GridProperties_Base; +} + +class GridProperties : + public MutexContainer, + public impl::GridProperties_Base, + public ::property::OPropertySet +{ +public: + GridProperties( ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + explicit GridProperties(); + virtual ~GridProperties(); + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( GridProperties ) + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + explicit GridProperties( const GridProperties & rOther ); + + // ____ 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); + + // ____ 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); + + // ____ OPropertySet ____ + virtual void firePropertyChangeEvent(); + using OPropertySet::disposing; + + void fireModifyEvent(); + +private: + ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xModifyEventForwarder; +}; + +} // namespace chart + +// CHART_GRIDPROPERTIES_HXX +#endif diff --git a/chart2/source/model/main/LayoutContainer.cxx b/chart2/source/model/main/LayoutContainer.cxx new file mode 100644 index 000000000000..d962113f78c7 --- /dev/null +++ b/chart2/source/model/main/LayoutContainer.cxx @@ -0,0 +1,138 @@ +/************************************************************************* + * + * 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 "LayoutContainer.hxx" +#include "macros.hxx" +#include "ContainerHelper.hxx" + +#include <algorithm> + +using namespace ::com::sun::star; + +namespace +{ + +static const ::rtl::OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.layout.LayoutContainer" )); +} // anonymous namespace + +namespace chart +{ + +LayoutContainer::LayoutContainer() +{} + +LayoutContainer::~LayoutContainer() +{} + +// ____ XLayoutContainer ____ +void SAL_CALL LayoutContainer::addConstrainedElementByIdentifier( + const ::rtl::OUString& aIdentifier, + const layout::Constraint& Constraint ) + throw (layout::IllegalConstraintException, + lang::IllegalArgumentException, + uno::RuntimeException) +{ + addElementByIdentifier( aIdentifier ); + m_aConstraints[ aIdentifier ] = Constraint; +} + +void SAL_CALL LayoutContainer::addElementByIdentifier( const ::rtl::OUString& aIdentifier ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + if( ::std::find( m_aLayoutElements.begin(), + m_aLayoutElements.end(), + aIdentifier ) != m_aLayoutElements.end()) + throw lang::IllegalArgumentException(); + + m_aLayoutElements.push_back( aIdentifier ); +} + +void SAL_CALL LayoutContainer::removeElementByIdentifier( const ::rtl::OUString& aIdentifier ) + throw (container::NoSuchElementException, + uno::RuntimeException) +{ + tLayoutElements::iterator aIt( + ::std::find( m_aLayoutElements.begin(), + m_aLayoutElements.end(), + aIdentifier )); + + if( aIt == m_aLayoutElements.end()) + throw container::NoSuchElementException(); + + m_aLayoutElements.erase( aIt ); + m_aConstraints.erase( aIdentifier ); +} + +void SAL_CALL LayoutContainer::setConstraintByIdentifier( + const ::rtl::OUString& aIdentifier, + const layout::Constraint& Constraint ) + throw (container::NoSuchElementException, + uno::RuntimeException) +{ + if( ::std::find( m_aLayoutElements.begin(), + m_aLayoutElements.end(), + aIdentifier ) == m_aLayoutElements.end()) + throw container::NoSuchElementException(); + + m_aConstraints[ aIdentifier ] = Constraint; +} + +layout::Constraint SAL_CALL LayoutContainer::getConstraintByIdentifier( const ::rtl::OUString& aIdentifier ) + throw (container::NoSuchElementException, + uno::RuntimeException) +{ + tConstraintsMap::const_iterator aIt( m_aConstraints.find( aIdentifier )); + if( aIt == m_aConstraints.end()) + throw container::NoSuchElementException(); + + return (*aIt).second; +} + +uno::Sequence< ::rtl::OUString > SAL_CALL LayoutContainer::getElementIdentifiers() + throw (uno::RuntimeException) +{ + return ContainerHelper::ContainerToSequence( m_aLayoutElements ); +} + +uno::Sequence< ::rtl::OUString > LayoutContainer::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 1 ); + + aServices[ 0 ] = C2U( "com.sun.star.layout.LayoutContainer" ); + return aServices; +} + +// -------------------------------------------------------------------------------- + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( LayoutContainer, lcl_aServiceName ); + +} // namespace chart diff --git a/chart2/source/model/main/LayoutContainer.hxx b/chart2/source/model/main/LayoutContainer.hxx new file mode 100644 index 000000000000..ea645dcff536 --- /dev/null +++ b/chart2/source/model/main/LayoutContainer.hxx @@ -0,0 +1,90 @@ +/************************************************************************* + * + * 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_LAYOUTCONTAINER_HXX +#define CHART_LAYOUTCONTAINER_HXX + +#include <cppuhelper/implbase2.hxx> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/layout/XLayoutContainer.hpp> + +#include "ServiceMacros.hxx" + +#include <vector> +#include <map> + +namespace chart +{ + +class LayoutContainer : public + ::cppu::WeakImplHelper2< + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::layout::XLayoutContainer > +{ +public: + LayoutContainer(); + virtual ~LayoutContainer(); + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + +protected: + // ____ XLayoutContainer ____ + virtual void SAL_CALL addConstrainedElementByIdentifier( const ::rtl::OUString& aIdentifier, const ::com::sun::star::layout::Constraint& Constraint ) + throw (::com::sun::star::layout::IllegalConstraintException, + ::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL addElementByIdentifier( const ::rtl::OUString& aIdentifier ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL removeElementByIdentifier( const ::rtl::OUString& aIdentifier ) + throw (::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setConstraintByIdentifier( const ::rtl::OUString& aIdentifier, const ::com::sun::star::layout::Constraint& Constraint ) + throw (::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::layout::Constraint SAL_CALL getConstraintByIdentifier( const ::rtl::OUString& aIdentifier ) + throw (::com::sun::star::container::NoSuchElementException, + ::com::sun::star::uno::RuntimeException); + virtual ::com::sun::star::uno::Sequence< + ::rtl::OUString > SAL_CALL getElementIdentifiers() + throw (::com::sun::star::uno::RuntimeException); + +private: + typedef ::std::vector< ::rtl::OUString > tLayoutElements; + + typedef ::std::map< + ::rtl::OUString, + ::com::sun::star::layout::Constraint > tConstraintsMap; + + tLayoutElements m_aLayoutElements; + tConstraintsMap m_aConstraints; +}; + +} // namespace chart + +// CHART_LAYOUTCONTAINER_HXX +#endif diff --git a/chart2/source/model/main/Legend.cxx b/chart2/source/model/main/Legend.cxx new file mode 100644 index 000000000000..c1143ecdf77a --- /dev/null +++ b/chart2/source/model/main/Legend.cxx @@ -0,0 +1,369 @@ +/************************************************************************* + * + * 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 "Legend.hxx" +#include "macros.hxx" +#include "LineProperties.hxx" +#include "FillProperties.hxx" +#include "CharacterProperties.hxx" +#include "UserDefinedProperties.hxx" +#include "LegendHelper.hxx" +#include "ContainerHelper.hxx" +#include "CloneHelper.hxx" +#include "PropertyHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/chart2/LegendPosition.hpp> +#include <com/sun/star/chart2/LegendExpansion.hpp> +#include <com/sun/star/chart2/RelativePosition.hpp> + +#include <algorithm> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::beans::PropertyAttribute; + +using ::rtl::OUString; +using ::com::sun::star::uno::Sequence; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Any; +using ::com::sun::star::beans::Property; + +namespace +{ + +static const OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.Legend" )); + +enum +{ + PROP_LEGEND_ANCHOR_POSITION, + PROP_LEGEND_PREFERRED_EXPANSION, + PROP_LEGEND_SHOW, + PROP_LEGEND_REF_PAGE_SIZE, + PROP_LEGEND_REL_POS +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "AnchorPosition" ), + PROP_LEGEND_ANCHOR_POSITION, + ::getCppuType( reinterpret_cast< const chart2::LegendPosition * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "Expansion" ), + PROP_LEGEND_PREFERRED_EXPANSION, + ::getCppuType( reinterpret_cast< const chart2::LegendExpansion * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "Show" ), + PROP_LEGEND_SHOW, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "ReferencePageSize" ), + PROP_LEGEND_REF_PAGE_SIZE, + ::getCppuType( reinterpret_cast< const awt::Size * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "RelativePosition" ), + PROP_LEGEND_REL_POS, + ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_ANCHOR_POSITION, chart2::LegendPosition_LINE_END ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_PREFERRED_EXPANSION, chart2::LegendExpansion_HIGH ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_LEGEND_SHOW, true ); + + float fDefaultCharHeight = 10.0; + ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_CHAR_HEIGHT, fDefaultCharHeight ); + ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_ASIAN_CHAR_HEIGHT, fDefaultCharHeight ); + ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::CharacterProperties::PROP_CHAR_COMPLEX_CHAR_HEIGHT, fDefaultCharHeight ); +} + +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 ); + ::chart::LineProperties::AddPropertiesToVector( aProperties ); + ::chart::FillProperties::AddPropertiesToVector( aProperties ); + ::chart::CharacterProperties::AddPropertiesToVector( aProperties ); + ::chart::UserDefinedProperties::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 +{ + +Legend::Legend( Reference< uno::XComponentContext > const & /* xContext */ ) : + ::property::OPropertySet( m_aMutex ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{ +} + +Legend::Legend( const Legend & rOther ) : + MutexContainer(), + impl::Legend_Base(), + ::property::OPropertySet( rOther, m_aMutex ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{ + CloneHelper::CloneRefVector< Reference< chart2::XLegendEntry > >( rOther.m_aLegendEntries, m_aLegendEntries ); + ModifyListenerHelper::addListenerToAllElements( m_aLegendEntries, m_xModifyEventForwarder ); +} + +Legend::~Legend() +{ + try + { + ModifyListenerHelper::removeListenerFromAllElements( m_aLegendEntries, m_xModifyEventForwarder ); + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +// ____ XLegend ____ +void SAL_CALL Legend::registerEntry( const Reference< chart2::XLegendEntry >& xEntry ) + throw (lang::IllegalArgumentException, + uno::RuntimeException) +{ + if( ::std::find( m_aLegendEntries.begin(), + m_aLegendEntries.end(), + xEntry ) != m_aLegendEntries.end()) + throw lang::IllegalArgumentException(); + + m_aLegendEntries.push_back( xEntry ); + ModifyListenerHelper::addListener( xEntry, m_xModifyEventForwarder ); + fireModifyEvent(); +} + +void SAL_CALL Legend::revokeEntry( const Reference< chart2::XLegendEntry >& xEntry ) + throw (container::NoSuchElementException, + uno::RuntimeException) +{ + tLegendEntries::iterator aIt( + ::std::find( m_aLegendEntries.begin(), + m_aLegendEntries.end(), + xEntry )); + + if( aIt == m_aLegendEntries.end()) + throw container::NoSuchElementException(); + + m_aLegendEntries.erase( aIt ); + ModifyListenerHelper::removeListener( xEntry, m_xModifyEventForwarder ); + fireModifyEvent(); +} + +Sequence< Reference< chart2::XLegendEntry > > SAL_CALL Legend::getEntries() + throw (uno::RuntimeException) +{ + return ContainerHelper::ContainerToSequence( m_aLegendEntries ); +} + +// ____ XCloneable ____ +Reference< util::XCloneable > SAL_CALL Legend::createClone() + throw (uno::RuntimeException) +{ + return Reference< util::XCloneable >( new Legend( *this )); +} + +// ____ XModifyBroadcaster ____ +void SAL_CALL Legend::addModifyListener( const Reference< util::XModifyListener >& aListener ) + throw (uno::RuntimeException) +{ + try + { + Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW ); + xBroadcaster->addModifyListener( aListener ); + } + catch( const uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); + } +} + +void SAL_CALL Legend::removeModifyListener( const Reference< util::XModifyListener >& aListener ) + throw (uno::RuntimeException) +{ + try + { + 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 Legend::modified( const lang::EventObject& aEvent ) + throw (uno::RuntimeException) +{ + m_xModifyEventForwarder->modified( aEvent ); +} + +// ____ XEventListener (base of XModifyListener) ____ +void SAL_CALL Legend::disposing( const lang::EventObject& /* Source */ ) + throw (uno::RuntimeException) +{ + // nothing +} + +// ____ OPropertySet ____ +void Legend::firePropertyChangeEvent() +{ + fireModifyEvent(); +} + +void Legend::fireModifyEvent() +{ + m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); +} + +// ================================================================================ + +Sequence< OUString > Legend::getSupportedServiceNames_Static() +{ + const sal_Int32 nNumServices( 6 ); + sal_Int32 nI = 0; + Sequence< OUString > aServices( nNumServices ); + aServices[ nI++ ] = C2U( "com.sun.star.chart2.Legend" ); + aServices[ nI++ ] = C2U( "com.sun.star.beans.PropertySet" ); + aServices[ nI++ ] = C2U( "com.sun.star.drawing.FillProperties" ); + aServices[ nI++ ] = C2U( "com.sun.star.drawing.LineProperties" ); + aServices[ nI++ ] = C2U( "com.sun.star.style.CharacterProperties" ); + aServices[ nI++ ] = C2U( "com.sun.star.layout.LayoutElement" ); + OSL_ASSERT( nNumServices == nI ); + return aServices; +} + +// ____ OPropertySet ____ +Any Legend::GetDefaultValue( sal_Int32 nHandle ) const + throw(beans::UnknownPropertyException) +{ + static tPropertyValueMap aStaticDefaults; + + // /-- + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aStaticDefaults.size() ) + { + LineProperties::AddDefaultsToMap( aStaticDefaults ); + FillProperties::AddDefaultsToMap( aStaticDefaults ); + CharacterProperties::AddDefaultsToMap( aStaticDefaults ); + // call last to overwrite some character property defaults + lcl_AddDefaultsToMap( aStaticDefaults ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return Any(); + + return (*aFound).second; + // \-- +} + +::cppu::IPropertyArrayHelper & SAL_CALL Legend::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + + +// ____ XPropertySet ____ +Reference< beans::XPropertySetInfo > SAL_CALL + Legend::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; + // \-- +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( Legend, lcl_aServiceName ); + +// needed by MSC compiler +using impl::Legend_Base; + +IMPLEMENT_FORWARD_XINTERFACE2( Legend, Legend_Base, ::property::OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( Legend, Legend_Base, ::property::OPropertySet ) + +} // namespace chart diff --git a/chart2/source/model/main/Legend.hxx b/chart2/source/model/main/Legend.hxx new file mode 100644 index 000000000000..6b645828f4c1 --- /dev/null +++ b/chart2/source/model/main/Legend.hxx @@ -0,0 +1,154 @@ +/************************************************************************* + * + * 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_LEGEND_HXX +#define CHART_LEGEND_HXX + +#include "ServiceMacros.hxx" +#include "ModifyListenerHelper.hxx" +#include "OPropertySet.hxx" +#include "MutexContainer.hxx" +#include <cppuhelper/implbase5.hxx> +#include <comphelper/uno3.hxx> +#include <com/sun/star/chart2/XLegend.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/util/XModifyBroadcaster.hpp> +#include <com/sun/star/util/XModifyListener.hpp> + +namespace chart +{ + +namespace impl +{ +typedef ::cppu::WeakImplHelper5< + ::com::sun::star::chart2::XLegend, + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::util::XCloneable, + ::com::sun::star::util::XModifyBroadcaster, + ::com::sun::star::util::XModifyListener > + Legend_Base; +} + +class Legend : + public MutexContainer, + public impl::Legend_Base, + public ::property::OPropertySet +{ +public: + Legend( ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~Legend(); + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( Legend ) + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + explicit Legend( const Legend & rOther ); + + // ____ 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); + +// virtual sal_Bool SAL_CALL convertFastPropertyValue +// ( ::com::sun::star::uno::Any & rConvertedValue, +// ::com::sun::star::uno::Any & rOldValue, +// sal_Int32 nHandle, +// const ::com::sun::star::uno::Any& rValue ) +// throw (::com::sun::star::lang::IllegalArgumentException); + + // ____ XLegend ____ + virtual void SAL_CALL registerEntry( const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XLegendEntry >& xEntry ) + throw (::com::sun::star::lang::IllegalArgumentException, + ::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL revokeEntry( const ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XLegendEntry >& xEntry ) + 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::XLegendEntry > > SAL_CALL getEntries() + 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); + + // ____ 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); + + // ____ OPropertySet ____ + virtual void firePropertyChangeEvent(); + using OPropertySet::disposing; + + void fireModifyEvent(); + +private: + typedef ::std::vector< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XLegendEntry > > tLegendEntries; + + tLegendEntries m_aLegendEntries; + ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xModifyEventForwarder; +}; + +} // namespace chart + +// CHART_LEGEND_HXX +#endif diff --git a/chart2/source/model/main/PageBackground.cxx b/chart2/source/model/main/PageBackground.cxx new file mode 100644 index 000000000000..0dbe1d82fcf3 --- /dev/null +++ b/chart2/source/model/main/PageBackground.cxx @@ -0,0 +1,255 @@ +/************************************************************************* + * + * 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 "PageBackground.hxx" +#include "macros.hxx" +#include "LineProperties.hxx" +#include "FillProperties.hxx" +#include "UserDefinedProperties.hxx" +#include "ContainerHelper.hxx" +#include "PropertyHelper.hxx" + +#include <com/sun/star/drawing/LineStyle.hpp> +#include <rtl/uuid.h> +#include <cppuhelper/queryinterface.hxx> + +#include <vector> +#include <algorithm> + +using namespace ::com::sun::star; + +using ::com::sun::star::beans::Property; +using ::osl::MutexGuard; + +namespace +{ + +static const ::rtl::OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.PageBackground" )); + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + // override other defaults + ::chart::PropertyHelper::setPropertyValue< sal_Int32 >( rOutMap, ::chart::FillProperties::PROP_FILL_COLOR, 0xffffff ); + ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LineProperties::PROP_LINE_STYLE, drawing::LineStyle_NONE ); +} + +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; + ::chart::LineProperties::AddPropertiesToVector( aProperties ); + ::chart::FillProperties::AddPropertiesToVector( aProperties ); + ::chart::UserDefinedProperties::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 +{ + +PageBackground::PageBackground( const uno::Reference< uno::XComponentContext > & xContext ) : + ::property::OPropertySet( m_aMutex ), + m_xContext( xContext ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{} + +PageBackground::PageBackground( const PageBackground & rOther ) : + MutexContainer(), + impl::PageBackground_Base(), + ::property::OPropertySet( rOther, m_aMutex ), + m_xContext( rOther.m_xContext ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{} + +PageBackground::~PageBackground() +{} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL PageBackground::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new PageBackground( *this )); +} + +// ================================================================================ + +// ____ OPropertySet ____ +uno::Any PageBackground::GetDefaultValue( sal_Int32 nHandle ) const + throw(beans::UnknownPropertyException) +{ + static tPropertyValueMap aStaticDefaults; + + // /-- + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aStaticDefaults.size() ) + { + // initialize defaults + LineProperties::AddDefaultsToMap( aStaticDefaults ); + FillProperties::AddDefaultsToMap( aStaticDefaults ); + // overrides defaults of FillProperties + lcl_AddDefaultsToMap( aStaticDefaults ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; + // \-- +} + +::cppu::IPropertyArrayHelper & SAL_CALL PageBackground::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + PageBackground::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo; + + // /-- + MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + getInfoHelper()); + } + + return xInfo; + // \-- +} + + +// ____ XModifyBroadcaster ____ +void SAL_CALL PageBackground::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 PageBackground::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 PageBackground::modified( const lang::EventObject& aEvent ) + throw (uno::RuntimeException) +{ + m_xModifyEventForwarder->modified( aEvent ); +} + +// ____ XEventListener (base of XModifyListener) ____ +void SAL_CALL PageBackground::disposing( const lang::EventObject& /* Source */ ) + throw (uno::RuntimeException) +{ + // nothing +} + +// ____ OPropertySet ____ +void PageBackground::firePropertyChangeEvent() +{ + fireModifyEvent(); +} + +void PageBackground::fireModifyEvent() +{ + m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); +} + +// ================================================================================ + +uno::Sequence< ::rtl::OUString > PageBackground::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 2 ); + aServices[ 0 ] = C2U( "com.sun.star.chart2.PageBackground" ); + aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( PageBackground, lcl_aServiceName ); + +using impl::PageBackground_Base; + +IMPLEMENT_FORWARD_XINTERFACE2( PageBackground, PageBackground_Base, ::property::OPropertySet ) + +} // namespace chart diff --git a/chart2/source/model/main/PageBackground.hxx b/chart2/source/model/main/PageBackground.hxx new file mode 100644 index 000000000000..9875a76eae2b --- /dev/null +++ b/chart2/source/model/main/PageBackground.hxx @@ -0,0 +1,132 @@ +/************************************************************************* + * + * 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_PAGEBACKGROUND_HXX +#define CHART_PAGEBACKGROUND_HXX + +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/util/XCloneable.hpp> +#include "MutexContainer.hxx" +#include "OPropertySet.hxx" +#include <cppuhelper/implbase3.hxx> + +#include "ServiceMacros.hxx" +#include "ModifyListenerHelper.hxx" +#include <comphelper/uno3.hxx> + +namespace chart +{ + +namespace impl +{ +typedef ::cppu::WeakImplHelper3< + ::com::sun::star::util::XCloneable, + ::com::sun::star::util::XModifyBroadcaster, + ::com::sun::star::util::XModifyListener > + PageBackground_Base; +} + +class PageBackground : + public MutexContainer, + public impl::PageBackground_Base, + public ::property::OPropertySet +{ +public: + PageBackground( const ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > & xContext ); + virtual ~PageBackground(); + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( PageBackground ) + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + +protected: + explicit PageBackground( const PageBackground & rOther ); + + // ____ 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); + +// virtual sal_Bool SAL_CALL convertFastPropertyValue +// ( ::com::sun::star::uno::Any & rConvertedValue, +// ::com::sun::star::uno::Any & rOldValue, +// sal_Int32 nHandle, +// const ::com::sun::star::uno::Any& rValue ) +// throw (::com::sun::star::lang::IllegalArgumentException); + + // ____ XCloneable ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() + throw (::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); + + // ____ OPropertySet ____ + virtual void firePropertyChangeEvent(); + using OPropertySet::disposing; + + void fireModifyEvent(); + +private: + ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > + m_xContext; + + ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xModifyEventForwarder; +}; + +} // namespace chart + +// CHART_PAGEBACKGROUND_HXX +#endif diff --git a/chart2/source/model/main/PolarCoordinateSystem.cxx b/chart2/source/model/main/PolarCoordinateSystem.cxx new file mode 100644 index 000000000000..9022a5e17901 --- /dev/null +++ b/chart2/source/model/main/PolarCoordinateSystem.cxx @@ -0,0 +1,155 @@ +/************************************************************************* + * + * 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 "PolarCoordinateSystem.hxx" +#include "macros.hxx" +#include "servicenames_coosystems.hxx" + +using namespace ::com::sun::star; + +using ::com::sun::star::uno::RuntimeException; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::uno::Sequence; +using ::rtl::OUString; + +namespace +{ + +static const ::rtl::OUString lcl_aServiceNamePolar2d( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.PolarCoordinateSystem2d" )); +static const ::rtl::OUString lcl_aServiceNamePolar3d( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.chart2.PolarCoordinateSystem3d" )); + +static const ::rtl::OUString lcl_aImplementationNamePolar2d( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.PolarCoordinateSystem2d" )); +static const ::rtl::OUString lcl_aImplementationNamePolar3d( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.PolarCoordinateSystem3d" )); +} + +namespace chart +{ + +// explicit +PolarCoordinateSystem::PolarCoordinateSystem( + const uno::Reference< uno::XComponentContext > & xContext, + sal_Int32 nDimensionCount /* = 2 */, + sal_Bool bSwapXAndYAxis /* = sal_False */ ) : + BaseCoordinateSystem( xContext, nDimensionCount, bSwapXAndYAxis ) +{} + +PolarCoordinateSystem::PolarCoordinateSystem( + const PolarCoordinateSystem & rSource ) : + BaseCoordinateSystem( rSource ) +{} + +PolarCoordinateSystem::~PolarCoordinateSystem() +{} + +// ____ XCoordinateSystem ____ +::rtl::OUString SAL_CALL PolarCoordinateSystem::getCoordinateSystemType() + throw (RuntimeException) +{ + return CHART2_COOSYSTEM_POLAR_SERVICE_NAME; +} + +::rtl::OUString SAL_CALL PolarCoordinateSystem::getViewServiceName() + throw (RuntimeException) +{ + return CHART2_COOSYSTEM_POLAR_VIEW_SERVICE_NAME; +} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL PolarCoordinateSystem::createClone() + throw (RuntimeException) +{ + return Reference< util::XCloneable >( new PolarCoordinateSystem( *this )); +} + +// ____ XServiceInfo ____ +Sequence< OUString > PolarCoordinateSystem::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 1 ); + aServices[ 0 ] = CHART2_COOSYSTEM_POLAR_SERVICE_NAME; + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( PolarCoordinateSystem, + C2U( "com.sun.star.comp.chart.PolarCoordinateSystem" )) + + +// ================================= +// ==== PolarCoordinateSystem2d ==== +// ================================= + +PolarCoordinateSystem2d::PolarCoordinateSystem2d( + const uno::Reference< uno::XComponentContext > & xContext ) : + PolarCoordinateSystem( xContext, 2, sal_False ) +{} + +PolarCoordinateSystem2d::~PolarCoordinateSystem2d() +{} + +// ____ XServiceInfo ____ +Sequence< OUString > PolarCoordinateSystem2d::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 2 ); + aServices[ 0 ] = CHART2_COOSYSTEM_POLAR_SERVICE_NAME; + aServices[ 1 ] = lcl_aServiceNamePolar2d; + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( PolarCoordinateSystem2d, lcl_aImplementationNamePolar2d ) + +// ================================= +// ==== PolarCoordinateSystem3d ==== +// ================================= + +PolarCoordinateSystem3d::PolarCoordinateSystem3d( + const uno::Reference< uno::XComponentContext > & xContext ) : + PolarCoordinateSystem( xContext, 3, sal_False ) +{} + +PolarCoordinateSystem3d::~PolarCoordinateSystem3d() +{} + +// ____ XServiceInfo ____ +Sequence< OUString > PolarCoordinateSystem3d::getSupportedServiceNames_Static() +{ + Sequence< OUString > aServices( 2 ); + aServices[ 0 ] = CHART2_COOSYSTEM_POLAR_SERVICE_NAME; + aServices[ 1 ] = lcl_aServiceNamePolar3d; + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( PolarCoordinateSystem3d, lcl_aImplementationNamePolar3d ) + +} // namespace chart diff --git a/chart2/source/model/main/StockBar.cxx b/chart2/source/model/main/StockBar.cxx new file mode 100644 index 000000000000..9a3c7f8ab623 --- /dev/null +++ b/chart2/source/model/main/StockBar.cxx @@ -0,0 +1,267 @@ +/************************************************************************* + * + * 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 "StockBar.hxx" +#include "LineProperties.hxx" +#include "FillProperties.hxx" +#include "UserDefinedProperties.hxx" +#include "PropertyHelper.hxx" +#include "macros.hxx" +#include "ContainerHelper.hxx" +#include "ModifyListenerHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/style/XStyle.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/uno/Sequence.hxx> + +#include <algorithm> + +using namespace ::com::sun::star; + +using ::com::sun::star::uno::Reference; +using ::com::sun::star::beans::Property; +using ::osl::MutexGuard; + +// ____________________________________________________________ + +namespace +{ + +static const ::rtl::OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.StockBar" )); + +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; + ::chart::LineProperties::AddPropertiesToVector( aProperties ); + ::chart::FillProperties::AddPropertiesToVector( aProperties ); + ::chart::UserDefinedProperties::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; +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + // override other defaults + ::chart::PropertyHelper::setPropertyValue< sal_Int32 >( rOutMap, ::chart::FillProperties::PROP_FILL_COLOR, 0xffffff ); // white +} + +::cppu::IPropertyArrayHelper & lcl_getInfoHelper() +{ + static ::cppu::OPropertyArrayHelper aArrayHelper( + lcl_GetPropertySequence(), + /* bSorted = */ sal_True ); + + return aArrayHelper; +} + +} // anonymous namespace + +// ____________________________________________________________ + +namespace chart +{ + +StockBar::StockBar( bool bRisingCourse ) : + ::property::OPropertySet( m_aMutex ), + m_bRisingCourse( bRisingCourse ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{ + if( ! m_bRisingCourse ) + { + setFastPropertyValue_NoBroadcast( + ::chart::FillProperties::PROP_FILL_COLOR, + uno::makeAny( sal_Int32( 0x000000 ))); // black + setFastPropertyValue_NoBroadcast( + ::chart::LineProperties::PROP_LINE_COLOR, + uno::makeAny( sal_Int32( 0xb3b3b3 ))); // gray30 + } +} + +StockBar::StockBar( const StockBar & rOther ) : + MutexContainer(), + impl::StockBar_Base(), + ::property::OPropertySet( rOther, m_aMutex ), + m_bRisingCourse( rOther.m_bRisingCourse ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{} + +StockBar::~StockBar() +{} + + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL StockBar::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new StockBar( *this )); +} + +// ____ OPropertySet ____ +uno::Any StockBar::GetDefaultValue( sal_Int32 nHandle ) const + throw(beans::UnknownPropertyException) +{ + static tPropertyValueMap aStaticDefaults; + + // /-- + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aStaticDefaults.size() ) + { + // initialize defaults + LineProperties::AddDefaultsToMap( aStaticDefaults ); + FillProperties::AddDefaultsToMap( aStaticDefaults ); + + // overrides a line property + lcl_AddDefaultsToMap( aStaticDefaults ); + } + + tPropertyValueMap::const_iterator aFound( + aStaticDefaults.find( nHandle )); + + if( aFound == aStaticDefaults.end()) + return uno::Any(); + + return (*aFound).second; + // \-- +} + +::cppu::IPropertyArrayHelper & SAL_CALL StockBar::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + +// ____ XPropertySet ____ +Reference< beans::XPropertySetInfo > SAL_CALL + StockBar::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static Reference< beans::XPropertySetInfo > xInfo; + + // /-- + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + lcl_getInfoHelper()); + } + + return xInfo; + // \-- +} + + +// ____ XModifyBroadcaster ____ +void SAL_CALL StockBar::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 StockBar::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 StockBar::modified( const lang::EventObject& aEvent ) + throw (uno::RuntimeException) +{ + m_xModifyEventForwarder->modified( aEvent ); +} + +// ____ XEventListener (base of XModifyListener) ____ +void SAL_CALL StockBar::disposing( const lang::EventObject& /* Source */ ) + throw (uno::RuntimeException) +{ + // nothing +} + +// ____ OPropertySet ____ +void StockBar::firePropertyChangeEvent() +{ + fireModifyEvent(); +} + +void StockBar::fireModifyEvent() +{ + m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); +} + +// ================================================================================ + +uno::Sequence< ::rtl::OUString > StockBar::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 2 ); + aServices[ 0 ] = C2U( "com.sun.star.chart2.StockBar" ); + aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( StockBar, lcl_aServiceName ); + +using impl::StockBar_Base; + +IMPLEMENT_FORWARD_XINTERFACE2( StockBar, StockBar_Base, ::property::OPropertySet ) + +} // namespace chart diff --git a/chart2/source/model/main/Title.cxx b/chart2/source/model/main/Title.cxx new file mode 100644 index 000000000000..d7c5691d160d --- /dev/null +++ b/chart2/source/model/main/Title.cxx @@ -0,0 +1,412 @@ +/************************************************************************* + * + * 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 "Title.hxx" +#include "macros.hxx" +#include "FormattedString.hxx" +#include "LineProperties.hxx" +#include "FillProperties.hxx" +#include "ContainerHelper.hxx" +#include "CloneHelper.hxx" +#include "PropertyHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/style/ParagraphAdjust.hpp> +#include <com/sun/star/drawing/FillStyle.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> +#include <com/sun/star/chart2/RelativePosition.hpp> +#include <com/sun/star/awt/Size.hpp> +#include <rtl/uuid.h> +#include <cppuhelper/queryinterface.hxx> + +#include <vector> +#include <algorithm> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::beans::PropertyAttribute; + +using ::com::sun::star::beans::Property; +using ::osl::MutexGuard; + +namespace +{ + +static const ::rtl::OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.Title" )); + +enum +{ + PROP_TITLE_PARA_ADJUST, + PROP_TITLE_PARA_LAST_LINE_ADJUST, + PROP_TITLE_PARA_LEFT_MARGIN, + PROP_TITLE_PARA_RIGHT_MARGIN, + PROP_TITLE_PARA_TOP_MARGIN, + PROP_TITLE_PARA_BOTTOM_MARGIN, + PROP_TITLE_PARA_IS_HYPHENATION, + + PROP_TITLE_TEXT_ROTATION, + PROP_TITLE_TEXT_STACKED, + PROP_TITLE_REL_POS, + + PROP_TITLE_REF_PAGE_SIZE +}; + +void lcl_AddPropertiesToVector( + ::std::vector< Property > & rOutProperties ) +{ + rOutProperties.push_back( + Property( C2U( "ParaAdjust" ), + PROP_TITLE_PARA_ADJUST, + ::getCppuType( reinterpret_cast< ::com::sun::star::style::ParagraphAdjust * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "ParaLastLineAdjust" ), + PROP_TITLE_PARA_LAST_LINE_ADJUST, + ::getCppuType( reinterpret_cast< sal_Int16 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "ParaLeftMargin" ), + PROP_TITLE_PARA_LEFT_MARGIN, + ::getCppuType( reinterpret_cast< sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "ParaRightMargin" ), + PROP_TITLE_PARA_RIGHT_MARGIN, + ::getCppuType( reinterpret_cast< sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "ParaTopMargin" ), + PROP_TITLE_PARA_TOP_MARGIN, + ::getCppuType( reinterpret_cast< sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "ParaBottomMargin" ), + PROP_TITLE_PARA_BOTTOM_MARGIN, + ::getCppuType( reinterpret_cast< sal_Int32 * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "ParaIsHyphenation" ), + PROP_TITLE_PARA_IS_HYPHENATION, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "TextRotation" ), + PROP_TITLE_TEXT_ROTATION, + ::getCppuType( reinterpret_cast< const double * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "StackCharacters" ), + PROP_TITLE_TEXT_STACKED, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "RelativePosition" ), + PROP_TITLE_REL_POS, + ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); + + rOutProperties.push_back( + Property( C2U( "ReferencePageSize" ), + PROP_TITLE_REF_PAGE_SIZE, + ::getCppuType( reinterpret_cast< const awt::Size * >(0)), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEVOID )); +} + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + // ParagraphProperties + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_PARA_ADJUST, + ::com::sun::star::style::ParagraphAdjust_CENTER ); + // PROP_TITLE_PARA_LAST_LINE_ADJUST + + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_LEFT_MARGIN, 0 ); + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_RIGHT_MARGIN, 0 ); + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_TOP_MARGIN, 0 ); + ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_BOTTOM_MARGIN, 0 ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_PARA_IS_HYPHENATION, true ); + + // own properties + ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_TITLE_TEXT_ROTATION, 0.0 ); + ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_TEXT_STACKED, false ); + + // override other defaults + ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE ); + ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LineProperties::PROP_LINE_STYLE, drawing::LineStyle_NONE ); +} + +const uno::Sequence< Property > & lcl_GetPropertySequence() +{ + static uno::Sequence< Property > aPropSeq; + + // /-- + MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aPropSeq.getLength() ) + { + // get properties + ::std::vector< ::com::sun::star::beans::Property > aProperties; + lcl_AddPropertiesToVector( aProperties ); + ::chart::LineProperties::AddPropertiesToVector( aProperties ); + ::chart::FillProperties::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 +{ + +Title::Title( uno::Reference< uno::XComponentContext > const & /* xContext */ ) : + ::property::OPropertySet( m_aMutex ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{} + +Title::Title( const Title & rOther ) : + MutexContainer(), + impl::Title_Base(), + ::property::OPropertySet( rOther, m_aMutex ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{ + CloneHelper::CloneRefSequence< uno::Reference< chart2::XFormattedString > >( + rOther.m_aStrings, m_aStrings ); + ModifyListenerHelper::addListenerToAllElements( + ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder ); +} + +Title::~Title() +{ + ModifyListenerHelper::removeListenerFromAllElements( + ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder ); +} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL Title::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new Title( *this )); +} + +// -------------------------------------------------------------------------------- + +// ____ XTitle ____ +uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL Title::getText() + throw (uno::RuntimeException) +{ + MutexGuard aGuard( GetMutex() ); + return m_aStrings; +} + +void SAL_CALL Title::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& rNewStrings ) + throw (uno::RuntimeException) +{ + uno::Sequence< uno::Reference< chart2::XFormattedString > > aOldStrings; + { + MutexGuard aGuard( GetMutex() ); + std::swap( m_aStrings, aOldStrings ); + m_aStrings = rNewStrings; + } + //don't keep the mutex locked while calling out + ModifyListenerHelper::removeListenerFromAllElements( + ContainerHelper::SequenceToVector( aOldStrings ), m_xModifyEventForwarder ); + ModifyListenerHelper::addListenerToAllElements( + ContainerHelper::SequenceToVector( rNewStrings ), m_xModifyEventForwarder ); + fireModifyEvent(); +} + +// ================================================================================ + +// ____ OPropertySet ____ +uno::Any Title::GetDefaultValue( sal_Int32 nHandle ) const + throw(beans::UnknownPropertyException) +{ + static tPropertyValueMap aStaticDefaults; + + // /-- + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aStaticDefaults.size() ) + { + LineProperties::AddDefaultsToMap( aStaticDefaults ); + FillProperties::AddDefaultsToMap( aStaticDefaults ); + + // initialize defaults + // Note: this should be last to override defaults of the previously + // added 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 Title::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + Title::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo; + + // /-- + MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + getInfoHelper()); + } + + return xInfo; + // \-- +} + +// ____ XModifyBroadcaster ____ +void SAL_CALL Title::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 Title::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 Title::modified( const lang::EventObject& aEvent ) + throw (uno::RuntimeException) +{ + m_xModifyEventForwarder->modified( aEvent ); +} + +// ____ XEventListener (base of XModifyListener) ____ +void SAL_CALL Title::disposing( const lang::EventObject& /* Source */ ) + throw (uno::RuntimeException) +{ + // nothing +} + +// ____ OPropertySet ____ +void Title::firePropertyChangeEvent() +{ + fireModifyEvent(); +} + +void Title::fireModifyEvent() +{ + m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); +} + + +// ================================================================================ + +uno::Sequence< ::rtl::OUString > Title::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 4 ); + aServices[ 0 ] = C2U( "com.sun.star.chart2.Title" ); + aServices[ 1 ] = C2U( "com.sun.star.style.ParagraphProperties" ); + aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" ); + aServices[ 3 ] = C2U( "com.sun.star.layout.LayoutElement" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( Title, lcl_aServiceName ); + +// needed by MSC compiler +using impl::Title_Base; + +IMPLEMENT_FORWARD_XINTERFACE2( Title, Title_Base, ::property::OPropertySet ) +IMPLEMENT_FORWARD_XTYPEPROVIDER2( Title, Title_Base, ::property::OPropertySet ) + +} // namespace chart diff --git a/chart2/source/model/main/Title.hxx b/chart2/source/model/main/Title.hxx new file mode 100644 index 000000000000..5889910018b7 --- /dev/null +++ b/chart2/source/model/main/Title.hxx @@ -0,0 +1,147 @@ +/************************************************************************* + * + * 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_TITLE_HXX +#define CHART_TITLE_HXX + +#include "ServiceMacros.hxx" +#include "ModifyListenerHelper.hxx" +#include "OPropertySet.hxx" +#include "MutexContainer.hxx" +#include <cppuhelper/implbase5.hxx> +#include <comphelper/uno3.hxx> +#include <com/sun/star/chart2/XTitle.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> +#include <com/sun/star/util/XCloneable.hpp> + +namespace chart +{ + +namespace impl +{ +typedef ::cppu::WeakImplHelper5< + ::com::sun::star::chart2::XTitle, + ::com::sun::star::lang::XServiceInfo, + ::com::sun::star::util::XCloneable, + ::com::sun::star::util::XModifyBroadcaster, + ::com::sun::star::util::XModifyListener > + Title_Base; +} + +class Title : + public MutexContainer, + public impl::Title_Base, + public ::property::OPropertySet +{ +public: + Title( ::com::sun::star::uno::Reference< + ::com::sun::star::uno::XComponentContext > const & xContext ); + virtual ~Title(); + + /// establish methods for factory instatiation + APPHELPER_SERVICE_FACTORY_HELPER( Title ) + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + +protected: + explicit Title( const Title & rOther ); + + // ____ 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); + +// virtual sal_Bool SAL_CALL convertFastPropertyValue +// ( ::com::sun::star::uno::Any & rConvertedValue, +// ::com::sun::star::uno::Any & rOldValue, +// sal_Int32 nHandle, +// const ::com::sun::star::uno::Any& rValue ) +// throw (::com::sun::star::lang::IllegalArgumentException); + + // ____ XTitle ____ + virtual ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XFormattedString > > SAL_CALL getText() + throw (::com::sun::star::uno::RuntimeException); + virtual void SAL_CALL setText( const ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XFormattedString > >& Strings ) + 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); + + // ____ 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); + + // ____ OPropertySet ____ + virtual void firePropertyChangeEvent(); + using OPropertySet::disposing; + + void fireModifyEvent(); + +private: + ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XFormattedString > > m_aStrings; + + ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xModifyEventForwarder; +}; + +} // namespace chart + +// CHART_TITLE_HXX +#endif diff --git a/chart2/source/model/main/Wall.cxx b/chart2/source/model/main/Wall.cxx new file mode 100644 index 000000000000..2ad00a4c90ae --- /dev/null +++ b/chart2/source/model/main/Wall.cxx @@ -0,0 +1,260 @@ +/************************************************************************* + * + * 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 "Wall.hxx" +#include "macros.hxx" +#include "LineProperties.hxx" +#include "FillProperties.hxx" +#include "UserDefinedProperties.hxx" +#include "ContainerHelper.hxx" +#include "PropertyHelper.hxx" +#include <com/sun/star/beans/PropertyAttribute.hpp> +#include <com/sun/star/drawing/FillStyle.hpp> +#include <com/sun/star/awt/Gradient.hpp> +#include <com/sun/star/drawing/Hatch.hpp> +#include <com/sun/star/drawing/LineStyle.hpp> +#include <com/sun/star/drawing/LineDash.hpp> +#include <com/sun/star/drawing/LineJoint.hpp> +#include <rtl/uuid.h> +#include <cppuhelper/queryinterface.hxx> + +#include <vector> +#include <algorithm> + +using namespace ::com::sun::star; +using namespace ::com::sun::star::beans::PropertyAttribute; + +using ::com::sun::star::beans::Property; +using ::osl::MutexGuard; + +namespace +{ + +static const ::rtl::OUString lcl_aServiceName( + RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.Wall" )); + +void lcl_AddDefaultsToMap( + ::chart::tPropertyValueMap & rOutMap ) +{ + // override other defaults + ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LineProperties::PROP_LINE_STYLE, drawing::LineStyle_NONE ); +} + +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; + ::chart::LineProperties::AddPropertiesToVector( aProperties ); + ::chart::FillProperties::AddPropertiesToVector( aProperties ); + ::chart::UserDefinedProperties::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 +{ + +Wall::Wall() : + ::property::OPropertySet( m_aMutex ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{} + +Wall::Wall( const Wall & rOther ) : + MutexContainer(), + impl::Wall_Base(), + ::property::OPropertySet( rOther, m_aMutex ), + m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder()) +{} + +Wall::~Wall() +{} + +// ____ XCloneable ____ +uno::Reference< util::XCloneable > SAL_CALL Wall::createClone() + throw (uno::RuntimeException) +{ + return uno::Reference< util::XCloneable >( new Wall( *this )); +} + +// ================================================================================ + +// ____ OPropertySet ____ +uno::Any Wall::GetDefaultValue( sal_Int32 nHandle ) const + throw(beans::UnknownPropertyException) +{ + static tPropertyValueMap aStaticDefaults; + + // /-- + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( 0 == aStaticDefaults.size() ) + { + // initialize defaults + LineProperties::AddDefaultsToMap( aStaticDefaults ); + FillProperties::AddDefaultsToMap( aStaticDefaults ); + + // initialize defaults + // Note: this should be last to override defaults of the previously + // added 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 Wall::getInfoHelper() +{ + return lcl_getInfoHelper(); +} + + +// ____ XPropertySet ____ +uno::Reference< beans::XPropertySetInfo > SAL_CALL + Wall::getPropertySetInfo() + throw (uno::RuntimeException) +{ + static uno::Reference< beans::XPropertySetInfo > xInfo; + + // /-- + MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if( !xInfo.is()) + { + xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo( + getInfoHelper()); + } + + return xInfo; + // \-- +} + +// ____ XModifyBroadcaster ____ +void SAL_CALL Wall::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 Wall::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 Wall::modified( const lang::EventObject& aEvent ) + throw (uno::RuntimeException) +{ + m_xModifyEventForwarder->modified( aEvent ); +} + +// ____ XEventListener (base of XModifyListener) ____ +void SAL_CALL Wall::disposing( const lang::EventObject& /* Source */ ) + throw (uno::RuntimeException) +{ + // nothing +} + +// ____ OPropertySet ____ +void Wall::firePropertyChangeEvent() +{ + fireModifyEvent(); +} + +void Wall::fireModifyEvent() +{ + m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); +} + +// ================================================================================ + +uno::Sequence< ::rtl::OUString > Wall::getSupportedServiceNames_Static() +{ + uno::Sequence< ::rtl::OUString > aServices( 2 ); + aServices[ 0 ] = C2U( "com.sun.star.chart2.Wall" ); + aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" ); + return aServices; +} + +// implement XServiceInfo methods basing upon getSupportedServiceNames_Static +APPHELPER_XSERVICEINFO_IMPL( Wall, lcl_aServiceName ); + +using impl::Wall_Base; + +IMPLEMENT_FORWARD_XINTERFACE2( Wall, Wall_Base, ::property::OPropertySet ) + +} // namespace chart diff --git a/chart2/source/model/main/Wall.hxx b/chart2/source/model/main/Wall.hxx new file mode 100644 index 000000000000..8c796b4da432 --- /dev/null +++ b/chart2/source/model/main/Wall.hxx @@ -0,0 +1,127 @@ +/************************************************************************* + * + * 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_WALL_HXX +#define CHART_WALL_HXX + +#include <com/sun/star/util/XCloneable.hpp> +#include <com/sun/star/util/XModifyBroadcaster.hpp> +#include <com/sun/star/util/XModifyListener.hpp> +#include "MutexContainer.hxx" +#include "OPropertySet.hxx" +#include <cppuhelper/weak.hxx> + +#include "ServiceMacros.hxx" +#include "ModifyListenerHelper.hxx" +#include <cppuhelper/implbase3.hxx> +#include <comphelper/uno3.hxx> + +namespace chart +{ + +namespace impl +{ +typedef ::cppu::WeakImplHelper3< + ::com::sun::star::util::XCloneable, + ::com::sun::star::util::XModifyBroadcaster, + ::com::sun::star::util::XModifyListener > + Wall_Base; +} + +class Wall : + public MutexContainer, + public impl::Wall_Base, + public ::property::OPropertySet +{ +public: + Wall(); + virtual ~Wall(); + + /// XServiceInfo declarations + APPHELPER_XSERVICEINFO_DECL() + + /// merge XInterface implementations + DECLARE_XINTERFACE() + +protected: + explicit Wall( const Wall & rOther ); + + // ____ 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); + +// virtual sal_Bool SAL_CALL convertFastPropertyValue +// ( ::com::sun::star::uno::Any & rConvertedValue, +// ::com::sun::star::uno::Any & rOldValue, +// sal_Int32 nHandle, +// const ::com::sun::star::uno::Any& rValue ) +// throw (::com::sun::star::lang::IllegalArgumentException); + + // ____ XCloneable ____ + virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() + throw (::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); + + // ____ OPropertySet ____ + virtual void firePropertyChangeEvent(); + using OPropertySet::disposing; + + void fireModifyEvent(); + +private: + + ::com::sun::star::uno::Reference< ::com::sun::star::util::XModifyListener > m_xModifyEventForwarder; +}; + +} // namespace chart + +// CHART_WALL_HXX +#endif diff --git a/chart2/source/model/main/_serviceregistration_model.cxx b/chart2/source/model/main/_serviceregistration_model.cxx new file mode 100644 index 000000000000..a8b214aaf124 --- /dev/null +++ b/chart2/source/model/main/_serviceregistration_model.cxx @@ -0,0 +1,210 @@ +/************************************************************************* + * + * 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 <cppuhelper/implementationentry.hxx> +#ifndef _CHARTMODEL_HXX +#include "ChartModel.hxx" +#endif + +#include "Diagram.hxx" +#include "Legend.hxx" +#include "Axis.hxx" +#include "GridProperties.hxx" +#include "Title.hxx" +#include "FormattedString.hxx" +#include "PageBackground.hxx" +#include "DataSeries.hxx" +#include "PolarCoordinateSystem.hxx" +#include "CartesianCoordinateSystem.hxx" + +#include "ChartTypeManager.hxx" +#include "XMLFilter.hxx" + +#include "_serviceregistration_charttypes.hxx" + +static struct ::cppu::ImplementationEntry g_entries_chart2_model[] = +{ + { + ::chart::ChartModel::create + , ::chart::ChartModel::getImplementationName_Static + , ::chart::ChartModel::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::Diagram::create + , ::chart::Diagram::getImplementationName_Static + , ::chart::Diagram::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::Legend::create + , ::chart::Legend::getImplementationName_Static + , ::chart::Legend::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::Axis::create + , ::chart::Axis::getImplementationName_Static + , ::chart::Axis::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::GridProperties::create + , ::chart::GridProperties::getImplementationName_Static + , ::chart::GridProperties::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::Title::create + , ::chart::Title::getImplementationName_Static + , ::chart::Title::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + + ,{ + ::chart::FormattedString::create + , ::chart::FormattedString::getImplementationName_Static + , ::chart::FormattedString::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + + ,{ + ::chart::ChartTypeManager::create + , ::chart::ChartTypeManager::getImplementationName_Static + , ::chart::ChartTypeManager::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::PageBackground::create + , ::chart::PageBackground::getImplementationName_Static + , ::chart::PageBackground::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::DataSeries::create + , ::chart::DataSeries::getImplementationName_Static + , ::chart::DataSeries::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::XMLFilter::create + , ::chart::XMLFilter::getImplementationName_Static + , ::chart::XMLFilter::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::XMLReportFilterHelper::create + , ::chart::XMLReportFilterHelper::getImplementationName_Static + , ::chart::XMLFilter::getSupportedServiceNames_Static // we support the same, because we are derived from + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::PolarCoordinateSystem2d::create + , ::chart::PolarCoordinateSystem2d::getImplementationName_Static + , ::chart::PolarCoordinateSystem2d::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::PolarCoordinateSystem3d::create + , ::chart::PolarCoordinateSystem3d::getImplementationName_Static + , ::chart::PolarCoordinateSystem3d::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::CartesianCoordinateSystem2d::create + , ::chart::CartesianCoordinateSystem2d::getImplementationName_Static + , ::chart::CartesianCoordinateSystem2d::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ + ::chart::CartesianCoordinateSystem3d::create + , ::chart::CartesianCoordinateSystem3d::getImplementationName_Static + , ::chart::CartesianCoordinateSystem3d::getSupportedServiceNames_Static + , ::cppu::createSingleComponentFactory + , 0 + , 0 + } + ,{ 0, 0, 0, 0, 0, 0 } +}; + +// component exports +extern "C" +{ +//================================================================================================== +SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment( + const sal_Char ** ppEnvTypeName, uno_Environment ** /* ppEnv */ ) +{ + *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; +} +//================================================================================================== +SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory( + const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey ) +{ + void * pResult = ::cppu::component_getFactoryHelper( + pImplName, pServiceManager, pRegistryKey, g_entries_chart2_model ); + + if( ! pResult ) + pResult = ::cppu::component_getFactoryHelper( + pImplName, pServiceManager, pRegistryKey, + ChartTypeEntriesForServiceRegistration::getImplementationEntries() ); + + return pResult; +} +} +//========================================================================= diff --git a/chart2/source/model/main/makefile.mk b/chart2/source/model/main/makefile.mk new file mode 100644 index 000000000000..8e963dfa0f5c --- /dev/null +++ b/chart2/source/model/main/makefile.mk @@ -0,0 +1,67 @@ +#************************************************************************* +# +# 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= chmodelmain + +PRJINC= $(PRJ)$/source + +ENABLE_EXCEPTIONS= TRUE +VISIBILITY_HIDDEN=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE: settings.mk + +# --- export library ------------------------------------------------- + +#Specifies object files to bind into linked libraries. +SLOFILES= \ + $(SLO)$/Axis.obj \ + $(SLO)$/GridProperties.obj \ + $(SLO)$/BaseCoordinateSystem.obj \ + $(SLO)$/CartesianCoordinateSystem.obj \ + $(SLO)$/ChartModel.obj \ + $(SLO)$/ChartModel_Persistence.obj \ + $(SLO)$/DataPoint.obj \ + $(SLO)$/DataPointProperties.obj \ + $(SLO)$/DataSeries.obj \ + $(SLO)$/Diagram.obj \ + $(SLO)$/DataSeriesProperties.obj \ + $(SLO)$/FormattedString.obj \ + $(SLO)$/Legend.obj \ + $(SLO)$/PageBackground.obj \ + $(SLO)$/PolarCoordinateSystem.obj \ + $(SLO)$/StockBar.obj \ + $(SLO)$/Title.obj \ + $(SLO)$/Wall.obj \ + $(SLO)$/_serviceregistration_model.obj + +# --- Targets ----------------------------------------------------------------- + +.INCLUDE: target.mk diff --git a/chart2/source/model/makefile.mk b/chart2/source/model/makefile.mk new file mode 100644 index 000000000000..52cc85c10904 --- /dev/null +++ b/chart2/source/model/makefile.mk @@ -0,0 +1,108 @@ +#************************************************************************* +# +# 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= chartmodel + +USE_DEFFILE= TRUE +ENABLE_EXCEPTIONS= TRUE +VISIBILITY_HIDDEN=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE: $(PRJ)$/util$/makefile.pmk + +# --- export library ------------------------------------------------- + +#You can use several library macros of this form to build libraries that +#do not consist of all object files in a directory or to merge different libraries. +LIB1TARGET= $(SLB)$/_$(TARGET).lib + +LIB1FILES= \ + $(SLB)$/chmodelmain.lib \ + $(SLB)$/chmodeltemplate.lib \ + $(SLB)$/chmodelfilter.lib + +#-------- + +#Indicates the filename of the shared library. +SHL1TARGET= $(TARGET)$(DLLPOSTFIX) + +#indicates dependencies: +.IF "$(COM)" == "MSC" +SHL1DEPN = \ + $(LB)$/icharttools.lib +.ELSE +SHL1DEPN = +.ENDIF + +#Specifies an import library to create. For Win32 only. +SHL1IMPLIB= i$(TARGET) + +#Specifies libraries from the same module to put into the shared library. +#was created above +SHL1LIBS= $(LIB1TARGET) + +#Links import libraries. + +SHL1STDLIBS= $(CHARTTOOLS) \ + $(CPPULIB) \ + $(CPPUHELPERLIB) \ + $(COMPHELPERLIB) \ + $(UNOTOOLSLIB) \ + $(VCLLIB) \ + $(SVLLIB) \ + $(SVTOOLLIB) \ + $(SALLIB) \ + $(UCBHELPERLIB) + +#--------exports + +#specifies the exported symbols for Windows only: +SHL1DEF= $(MISC)$/$(SHL1TARGET).def + +SHL1VERSIONMAP = $(SOLARENV)/src/component.map + +#--------definition file + +#name of the definition file: +DEF1NAME= $(SHL1TARGET) + +# --- Resources --------------------------------------------------------------- + +# --- Targets ----------------------------------------------------------------- + +.INCLUDE: target.mk + +ALLTAR : $(MISC)/chartmodel.component + +$(MISC)/chartmodel.component .ERRREMOVE : $(SOLARENV)/bin/createcomponent.xslt \ + chartmodel.component + $(XSLTPROC) --nonet --stringparam uri \ + '$(COMPONENTPREFIX_BASIS_NATIVE)$(SHL1TARGETN:f)' -o $@ \ + $(SOLARENV)/bin/createcomponent.xslt chartmodel.component diff --git a/chart2/source/model/template/AreaChartType.cxx b/chart2/source/model/template/AreaChartType.cxx new file mode 100644 index 000000000000..003220c87dfb --- /dev/null +++ b/chart2/source/model/template/AreaChartType.cxx @@ -0,0 +1,77 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/AreaChartType.hxx b/chart2/source/model/template/AreaChartType.hxx new file mode 100644 index 000000000000..9955d5eb537e --- /dev/null +++ b/chart2/source/model/template/AreaChartType.hxx @@ -0,0 +1,64 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/AreaChartTypeTemplate.cxx b/chart2/source/model/template/AreaChartTypeTemplate.cxx new file mode 100644 index 000000000000..5fe21cfb25e0 --- /dev/null +++ b/chart2/source/model/template/AreaChartTypeTemplate.cxx @@ -0,0 +1,281 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/AreaChartTypeTemplate.hxx b/chart2/source/model/template/AreaChartTypeTemplate.hxx new file mode 100644 index 000000000000..a84a4b645c2a --- /dev/null +++ b/chart2/source/model/template/AreaChartTypeTemplate.hxx @@ -0,0 +1,103 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/BarChartType.cxx b/chart2/source/model/template/BarChartType.cxx new file mode 100644 index 000000000000..e877a34007de --- /dev/null +++ b/chart2/source/model/template/BarChartType.cxx @@ -0,0 +1,78 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/BarChartType.hxx b/chart2/source/model/template/BarChartType.hxx new file mode 100644 index 000000000000..884a52e3a228 --- /dev/null +++ b/chart2/source/model/template/BarChartType.hxx @@ -0,0 +1,64 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/BarChartTypeTemplate.cxx b/chart2/source/model/template/BarChartTypeTemplate.cxx new file mode 100644 index 000000000000..01dc4c253d2b --- /dev/null +++ b/chart2/source/model/template/BarChartTypeTemplate.cxx @@ -0,0 +1,353 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/BarChartTypeTemplate.hxx b/chart2/source/model/template/BarChartTypeTemplate.hxx new file mode 100644 index 000000000000..fabf7a59826c --- /dev/null +++ b/chart2/source/model/template/BarChartTypeTemplate.hxx @@ -0,0 +1,121 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/BubbleChartType.cxx b/chart2/source/model/template/BubbleChartType.cxx new file mode 100644 index 000000000000..9922ed4df5fb --- /dev/null +++ b/chart2/source/model/template/BubbleChartType.cxx @@ -0,0 +1,242 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/BubbleChartType.hxx b/chart2/source/model/template/BubbleChartType.hxx new file mode 100644 index 000000000000..eea8a0e7a6ee --- /dev/null +++ b/chart2/source/model/template/BubbleChartType.hxx @@ -0,0 +1,86 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/BubbleChartTypeTemplate.cxx b/chart2/source/model/template/BubbleChartTypeTemplate.cxx new file mode 100644 index 000000000000..59b552cc8995 --- /dev/null +++ b/chart2/source/model/template/BubbleChartTypeTemplate.cxx @@ -0,0 +1,314 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/BubbleChartTypeTemplate.hxx b/chart2/source/model/template/BubbleChartTypeTemplate.hxx new file mode 100644 index 000000000000..24d35c6acbb7 --- /dev/null +++ b/chart2/source/model/template/BubbleChartTypeTemplate.hxx @@ -0,0 +1,101 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/BubbleDataInterpreter.cxx b/chart2/source/model/template/BubbleDataInterpreter.cxx new file mode 100644 index 000000000000..1f26fff907e4 --- /dev/null +++ b/chart2/source/model/template/BubbleDataInterpreter.cxx @@ -0,0 +1,308 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/BubbleDataInterpreter.hxx b/chart2/source/model/template/BubbleDataInterpreter.hxx new file mode 100644 index 000000000000..3eb6ebaedbf0 --- /dev/null +++ b/chart2/source/model/template/BubbleDataInterpreter.hxx @@ -0,0 +1,61 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/CandleStickChartType.cxx b/chart2/source/model/template/CandleStickChartType.cxx new file mode 100644 index 000000000000..22c8e058ea53 --- /dev/null +++ b/chart2/source/model/template/CandleStickChartType.cxx @@ -0,0 +1,355 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/CandleStickChartType.hxx b/chart2/source/model/template/CandleStickChartType.hxx new file mode 100644 index 000000000000..d32c4c455d74 --- /dev/null +++ b/chart2/source/model/template/CandleStickChartType.hxx @@ -0,0 +1,90 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/ChartType.cxx b/chart2/source/model/template/ChartType.cxx new file mode 100644 index 000000000000..22a744769fc6 --- /dev/null +++ b/chart2/source/model/template/ChartType.cxx @@ -0,0 +1,325 @@ +/************************************************************************* + * + * 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; + +// if( aDefaultOptRolesSeq.getLength() == 0 ) +// { +// aDefaultOptRolesSeq.realloc( 1 ); +// aDefaultOptRolesSeq[0] = C2U( "error-bars-y" ); +// } + + 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 diff --git a/chart2/source/model/template/ChartType.hxx b/chart2/source/model/template/ChartType.hxx new file mode 100644 index 000000000000..07e72ea2890b --- /dev/null +++ b/chart2/source/model/template/ChartType.hxx @@ -0,0 +1,183 @@ +/************************************************************************* + * + * 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); + +// virtual sal_Bool SAL_CALL convertFastPropertyValue +// ( ::com::sun::star::uno::Any & rConvertedValue, +// ::com::sun::star::uno::Any & rOldValue, +// sal_Int32 nHandle, +// const ::com::sun::star::uno::Any& rValue ) +// throw (::com::sun::star::lang::IllegalArgumentException); + + /// merge XInterface implementations + DECLARE_XINTERFACE() + /// merge XTypeProvider implementations + DECLARE_XTYPEPROVIDER() + + // not implemented +// ____ XCloneable ____ +// virtual ::com::sun::star::uno::Reference< ::com::sun::star::util::XCloneable > SAL_CALL createClone() +// throw (::com::sun::star::uno::RuntimeException); + +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 diff --git a/chart2/source/model/template/ChartTypeManager.cxx b/chart2/source/model/template/ChartTypeManager.cxx new file mode 100644 index 000000000000..d34617ffce1f --- /dev/null +++ b/chart2/source/model/template/ChartTypeManager.cxx @@ -0,0 +1,619 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/ChartTypeTemplate.cxx b/chart2/source/model/template/ChartTypeTemplate.cxx new file mode 100644 index 000000000000..e3943e9eb45f --- /dev/null +++ b/chart2/source/model/template/ChartTypeTemplate.cxx @@ -0,0 +1,933 @@ +/************************************************************************* + * + * 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 ); + } +} + +//static +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 diff --git a/chart2/source/model/template/ChartTypeTemplate.hxx b/chart2/source/model/template/ChartTypeTemplate.hxx new file mode 100644 index 000000000000..3f43e0ca6038 --- /dev/null +++ b/chart2/source/model/template/ChartTypeTemplate.hxx @@ -0,0 +1,299 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/ColumnChartType.cxx b/chart2/source/model/template/ColumnChartType.cxx new file mode 100644 index 000000000000..aa11d77e8995 --- /dev/null +++ b/chart2/source/model/template/ColumnChartType.cxx @@ -0,0 +1,202 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/ColumnChartType.hxx b/chart2/source/model/template/ColumnChartType.hxx new file mode 100644 index 000000000000..3386b6a1cd40 --- /dev/null +++ b/chart2/source/model/template/ColumnChartType.hxx @@ -0,0 +1,74 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/ColumnLineChartTypeTemplate.cxx b/chart2/source/model/template/ColumnLineChartTypeTemplate.cxx new file mode 100644 index 000000000000..663cad4c2fe4 --- /dev/null +++ b/chart2/source/model/template/ColumnLineChartTypeTemplate.cxx @@ -0,0 +1,453 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/ColumnLineChartTypeTemplate.hxx b/chart2/source/model/template/ColumnLineChartTypeTemplate.hxx new file mode 100644 index 000000000000..ce86188e2bb6 --- /dev/null +++ b/chart2/source/model/template/ColumnLineChartTypeTemplate.hxx @@ -0,0 +1,119 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/ColumnLineDataInterpreter.cxx b/chart2/source/model/template/ColumnLineDataInterpreter.cxx new file mode 100644 index 000000000000..18e22f78e86e --- /dev/null +++ b/chart2/source/model/template/ColumnLineDataInterpreter.cxx @@ -0,0 +1,101 @@ +/************************************************************************* + * + * 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 <deque> + +#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 diff --git a/chart2/source/model/template/ColumnLineDataInterpreter.hxx b/chart2/source/model/template/ColumnLineDataInterpreter.hxx new file mode 100644 index 000000000000..b9b8a62a4097 --- /dev/null +++ b/chart2/source/model/template/ColumnLineDataInterpreter.hxx @@ -0,0 +1,59 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/DataInterpreter.cxx b/chart2/source/model/template/DataInterpreter.cxx new file mode 100644 index 000000000000..b619553ee959 --- /dev/null +++ b/chart2/source/model/template/DataInterpreter.cxx @@ -0,0 +1,461 @@ +/************************************************************************* + * + * 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 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 + +// static +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; +} + +// static +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 ); + } +} + +// static +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(); +} + +// static +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 diff --git a/chart2/source/model/template/DataInterpreter.hxx b/chart2/source/model/template/DataInterpreter.hxx new file mode 100644 index 000000000000..a2d6201fc023 --- /dev/null +++ b/chart2/source/model/template/DataInterpreter.hxx @@ -0,0 +1,100 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/FilledNetChartType.cxx b/chart2/source/model/template/FilledNetChartType.cxx new file mode 100644 index 000000000000..d90dc8b9f7c7 --- /dev/null +++ b/chart2/source/model/template/FilledNetChartType.cxx @@ -0,0 +1,94 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/FilledNetChartType.hxx b/chart2/source/model/template/FilledNetChartType.hxx new file mode 100644 index 000000000000..14beee021b34 --- /dev/null +++ b/chart2/source/model/template/FilledNetChartType.hxx @@ -0,0 +1,63 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/LineChartType.cxx b/chart2/source/model/template/LineChartType.cxx new file mode 100644 index 000000000000..f96d7ed1297d --- /dev/null +++ b/chart2/source/model/template/LineChartType.cxx @@ -0,0 +1,214 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/LineChartType.hxx b/chart2/source/model/template/LineChartType.hxx new file mode 100644 index 000000000000..1821333a4cdc --- /dev/null +++ b/chart2/source/model/template/LineChartType.hxx @@ -0,0 +1,75 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/LineChartTypeTemplate.cxx b/chart2/source/model/template/LineChartTypeTemplate.cxx new file mode 100644 index 000000000000..8d582178a128 --- /dev/null +++ b/chart2/source/model/template/LineChartTypeTemplate.cxx @@ -0,0 +1,412 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/LineChartTypeTemplate.hxx b/chart2/source/model/template/LineChartTypeTemplate.hxx new file mode 100644 index 000000000000..faee9715720a --- /dev/null +++ b/chart2/source/model/template/LineChartTypeTemplate.hxx @@ -0,0 +1,109 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/NetChartType.cxx b/chart2/source/model/template/NetChartType.cxx new file mode 100644 index 000000000000..ddf001b2a6e4 --- /dev/null +++ b/chart2/source/model/template/NetChartType.cxx @@ -0,0 +1,180 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/NetChartType.hxx b/chart2/source/model/template/NetChartType.hxx new file mode 100644 index 000000000000..ba5dc48b6881 --- /dev/null +++ b/chart2/source/model/template/NetChartType.hxx @@ -0,0 +1,93 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/NetChartTypeTemplate.cxx b/chart2/source/model/template/NetChartTypeTemplate.cxx new file mode 100644 index 000000000000..b67817e73997 --- /dev/null +++ b/chart2/source/model/template/NetChartTypeTemplate.cxx @@ -0,0 +1,229 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/NetChartTypeTemplate.hxx b/chart2/source/model/template/NetChartTypeTemplate.hxx new file mode 100644 index 000000000000..f66355a3576e --- /dev/null +++ b/chart2/source/model/template/NetChartTypeTemplate.hxx @@ -0,0 +1,87 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/PieChartType.cxx b/chart2/source/model/template/PieChartType.cxx new file mode 100644 index 000000000000..9c199bb23d70 --- /dev/null +++ b/chart2/source/model/template/PieChartType.cxx @@ -0,0 +1,239 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/PieChartType.hxx b/chart2/source/model/template/PieChartType.hxx new file mode 100644 index 000000000000..fccd4e9ee25c --- /dev/null +++ b/chart2/source/model/template/PieChartType.hxx @@ -0,0 +1,81 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/PieChartTypeTemplate.cxx b/chart2/source/model/template/PieChartTypeTemplate.cxx new file mode 100644 index 000000000000..c16682846d53 --- /dev/null +++ b/chart2/source/model/template/PieChartTypeTemplate.cxx @@ -0,0 +1,661 @@ +/************************************************************************* + * + * 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::createAxes( +// const Sequence< Reference< chart2::XCoordinateSystem > > & rCoordSys ) +// { +// } + +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 diff --git a/chart2/source/model/template/PieChartTypeTemplate.hxx b/chart2/source/model/template/PieChartTypeTemplate.hxx new file mode 100644 index 000000000000..1634e643611f --- /dev/null +++ b/chart2/source/model/template/PieChartTypeTemplate.hxx @@ -0,0 +1,140 @@ +/************************************************************************* + * + * 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 createAxes( +// const ::com::sun::star::uno::Sequence< +// ::com::sun::star::uno::Reference< +// ::com::sun::star::chart2::XCoordinateSystem > > & rCoordSys ); + + 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 diff --git a/chart2/source/model/template/ScatterChartType.cxx b/chart2/source/model/template/ScatterChartType.cxx new file mode 100644 index 000000000000..8c4ab0d18415 --- /dev/null +++ b/chart2/source/model/template/ScatterChartType.cxx @@ -0,0 +1,296 @@ +/************************************************************************* + * + * 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 ____ +// ____ 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; + +// if( aOptRolesSeq.getLength() == 0 ) +// { +// aOptRolesSeq.realloc( 2 ); +// aOptRolesSeq[0] = C2U( "error-bars-x" ); +// aOptRolesSeq[1] = C2U( "error-bars-y" ); +// } + + 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 diff --git a/chart2/source/model/template/ScatterChartType.hxx b/chart2/source/model/template/ScatterChartType.hxx new file mode 100644 index 000000000000..aed0cce2a97f --- /dev/null +++ b/chart2/source/model/template/ScatterChartType.hxx @@ -0,0 +1,91 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/ScatterChartTypeTemplate.cxx b/chart2/source/model/template/ScatterChartTypeTemplate.cxx new file mode 100644 index 000000000000..a83d9a8a4ea3 --- /dev/null +++ b/chart2/source/model/template/ScatterChartTypeTemplate.cxx @@ -0,0 +1,432 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/ScatterChartTypeTemplate.hxx b/chart2/source/model/template/ScatterChartTypeTemplate.hxx new file mode 100644 index 000000000000..048cca73a92c --- /dev/null +++ b/chart2/source/model/template/ScatterChartTypeTemplate.hxx @@ -0,0 +1,110 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/StockChartTypeTemplate.cxx b/chart2/source/model/template/StockChartTypeTemplate.cxx new file mode 100644 index 000000000000..00ace6c330ad --- /dev/null +++ b/chart2/source/model/template/StockChartTypeTemplate.cxx @@ -0,0 +1,560 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/StockChartTypeTemplate.hxx b/chart2/source/model/template/StockChartTypeTemplate.hxx new file mode 100644 index 000000000000..c9347ff4e070 --- /dev/null +++ b/chart2/source/model/template/StockChartTypeTemplate.hxx @@ -0,0 +1,138 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/StockDataInterpreter.cxx b/chart2/source/model/template/StockDataInterpreter.cxx new file mode 100644 index 000000000000..0d134516a1bb --- /dev/null +++ b/chart2/source/model/template/StockDataInterpreter.cxx @@ -0,0 +1,344 @@ +/************************************************************************* + * + * 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 <deque> + +#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 diff --git a/chart2/source/model/template/StockDataInterpreter.hxx b/chart2/source/model/template/StockDataInterpreter.hxx new file mode 100644 index 000000000000..bb9edf48c169 --- /dev/null +++ b/chart2/source/model/template/StockDataInterpreter.hxx @@ -0,0 +1,69 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/XYDataInterpreter.cxx b/chart2/source/model/template/XYDataInterpreter.cxx new file mode 100644 index 000000000000..839c0cbac510 --- /dev/null +++ b/chart2/source/model/template/XYDataInterpreter.cxx @@ -0,0 +1,273 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/XYDataInterpreter.hxx b/chart2/source/model/template/XYDataInterpreter.hxx new file mode 100644 index 000000000000..c8ecb4d17778 --- /dev/null +++ b/chart2/source/model/template/XYDataInterpreter.hxx @@ -0,0 +1,61 @@ +/************************************************************************* + * + * 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 diff --git a/chart2/source/model/template/_serviceregistration_charttypes.cxx b/chart2/source/model/template/_serviceregistration_charttypes.cxx new file mode 100644 index 000000000000..c0ffb8f4825f --- /dev/null +++ b/chart2/source/model/template/_serviceregistration_charttypes.cxx @@ -0,0 +1,138 @@ +/************************************************************************* + * + * 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 + +// static +struct ::cppu::ImplementationEntry * + ChartTypeEntriesForServiceRegistration::getImplementationEntries() +{ + return g_entries_chart2_charttypes; +} 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 |