diff options
author | Release Engineering <releng@openoffice.org> | 2011-02-18 11:14:19 +0100 |
---|---|---|
committer | Release Engineering <releng@openoffice.org> | 2011-02-18 11:14:19 +0100 |
commit | 818496deb94e1582e355437644ef26ad75116c83 (patch) | |
tree | eade73d93ffe46e0204423dde5e8401095043b74 /xmloff | |
parent | cd0d6a5a6775f197fdb7e78b54c8133074a7a236 (diff) | |
parent | 74cc209439d9f239f929fed3f5ebbab1ef81439d (diff) |
merged DEV300
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/Library_xo.mk | 2 | ||||
-rw-r--r-- | xmloff/inc/SchXMLImport.hxx | 8 | ||||
-rw-r--r-- | xmloff/inc/xmloff/SchXMLImportHelper.hxx | 2 | ||||
-rw-r--r-- | xmloff/inc/xmloff/xmltoken.hxx | 6 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLChartContext.cxx | 128 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLChartContext.hxx | 15 | ||||
-rwxr-xr-x | xmloff/source/chart/SchXMLEnumConverter.cxx | 104 | ||||
-rwxr-xr-x | xmloff/source/chart/SchXMLEnumConverter.hxx | 39 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLExport.cxx | 89 | ||||
-rw-r--r-- | xmloff/source/chart/SchXMLImport.cxx | 22 | ||||
-rwxr-xr-x | xmloff/source/chart/SchXMLLegendContext.cxx | 229 | ||||
-rwxr-xr-x | xmloff/source/chart/SchXMLLegendContext.hxx | 46 | ||||
-rw-r--r-- | xmloff/source/chart/makefile.mk | 2 | ||||
-rw-r--r-- | xmloff/source/core/xmltoken.cxx | 6 |
14 files changed, 481 insertions, 217 deletions
diff --git a/xmloff/Library_xo.mk b/xmloff/Library_xo.mk index 9576341f0ffb..0544171dbfbd 100644 --- a/xmloff/Library_xo.mk +++ b/xmloff/Library_xo.mk @@ -69,8 +69,10 @@ $(eval $(call gb_Library_add_exception_objects,xo,\ xmloff/source/chart/SchXMLAxisContext \ xmloff/source/chart/SchXMLCalculationSettingsContext \ xmloff/source/chart/SchXMLChartContext \ + xmloff/source/chart/SchXMLEnumConverter \ xmloff/source/chart/SchXMLExport \ xmloff/source/chart/SchXMLImport \ + xmloff/source/chart/SchXMLLegendContext \ xmloff/source/chart/SchXMLParagraphContext \ xmloff/source/chart/SchXMLPlotAreaContext \ xmloff/source/chart/SchXMLSeries2Context \ diff --git a/xmloff/inc/SchXMLImport.hxx b/xmloff/inc/SchXMLImport.hxx index 936217fb8dc5..6b11e885f72e 100644 --- a/xmloff/inc/SchXMLImport.hxx +++ b/xmloff/inc/SchXMLImport.hxx @@ -127,14 +127,6 @@ enum SchXMLPlotAreaAttrTokenMap XML_TOK_PA_LIGHTING_MODE }; -enum SchXMLLegendAttrMap -{ - XML_TOK_LEGEND_POSITION, - XML_TOK_LEGEND_X, - XML_TOK_LEGEND_Y, - XML_TOK_LEGEND_STYLE_NAME -}; - enum SchXMLAutoStyleAttrMap { XML_TOK_AS_FAMILY, diff --git a/xmloff/inc/xmloff/SchXMLImportHelper.hxx b/xmloff/inc/xmloff/SchXMLImportHelper.hxx index a618d363137f..afc637aead74 100644 --- a/xmloff/inc/xmloff/SchXMLImportHelper.hxx +++ b/xmloff/inc/xmloff/SchXMLImportHelper.hxx @@ -83,7 +83,6 @@ private: SvXMLTokenMap* mpChartAttrTokenMap; SvXMLTokenMap* mpPlotAreaAttrTokenMap; - SvXMLTokenMap* mpLegendAttrTokenMap; SvXMLTokenMap* mpAutoStyleAttrTokenMap; SvXMLTokenMap* mpCellAttrTokenMap; SvXMLTokenMap* mpSeriesAttrTokenMap; @@ -124,7 +123,6 @@ public: const SvXMLTokenMap& GetChartAttrTokenMap(); const SvXMLTokenMap& GetPlotAreaAttrTokenMap(); - const SvXMLTokenMap& GetLegendAttrTokenMap(); const SvXMLTokenMap& GetAutoStyleAttrTokenMap(); const SvXMLTokenMap& GetCellAttrTokenMap(); const SvXMLTokenMap& GetSeriesAttrTokenMap(); diff --git a/xmloff/inc/xmloff/xmltoken.hxx b/xmloff/inc/xmloff/xmltoken.hxx index ecadbbdc196f..ca321245fdb2 100644 --- a/xmloff/inc/xmloff/xmltoken.hxx +++ b/xmloff/inc/xmloff/xmltoken.hxx @@ -3113,6 +3113,12 @@ namespace xmloff { namespace token { XML_OUTSIDE_MINIMUM,//#i114142# XML_OUTSIDE_MAXIMUM,//#i114142# + XML_LEGEND_EXPANSION, //#i28760# + XML_LEGEND_EXPANSION_ASPECT_RATIO, //#i28760# + XML_BALANCED, //#i28760# + XML_HIGH, //#i28760# + XML_WIDE, //#i28760# + XML_AXIS_TYPE, //#i25706# XML_DATE_SCALE, XML_BASE_TIME_UNIT, diff --git a/xmloff/source/chart/SchXMLChartContext.cxx b/xmloff/source/chart/SchXMLChartContext.cxx index 6b42b2e629df..9f9d1cf2bb1d 100644 --- a/xmloff/source/chart/SchXMLChartContext.cxx +++ b/xmloff/source/chart/SchXMLChartContext.cxx @@ -30,6 +30,7 @@ #include "SchXMLChartContext.hxx" #include "SchXMLImport.hxx" +#include "SchXMLLegendContext.hxx" #include "SchXMLPlotAreaContext.hxx" #include "SchXMLParagraphContext.hxx" #include "SchXMLTableContext.hxx" @@ -52,7 +53,6 @@ #include <com/sun/star/chart/XChartDocument.hpp> #include <com/sun/star/chart/XDiagram.hpp> #include <com/sun/star/xml/sax/XAttributeList.hpp> -#include <com/sun/star/chart/ChartLegendPosition.hpp> #include <com/sun/star/util/XStringMapping.hpp> #include <com/sun/star/drawing/XDrawPageSupplier.hpp> #include <com/sun/star/drawing/XDrawPage.hpp> @@ -60,7 +60,6 @@ #include <com/sun/star/awt/PosSize.hpp> #include <com/sun/star/embed/Aspects.hpp> #include <com/sun/star/embed/XVisualObject.hpp> -#include <com/sun/star/drawing/FillStyle.hpp> #include <com/sun/star/chart2/XChartDocument.hpp> #include <com/sun/star/chart2/data/XDataSink.hpp> @@ -234,19 +233,6 @@ uno::Sequence< sal_Int32 > lcl_getNumberSequenceFromString( const ::rtl::OUStrin } // anonymous namespace -static __FAR_DATA SvXMLEnumMapEntry aXMLLegendAlignmentMap[] = -{ -// { XML_LEFT, chart::ChartLegendPosition_LEFT }, - // #i35421# - { XML_START, chart::ChartLegendPosition_LEFT }, - { XML_TOP, chart::ChartLegendPosition_TOP }, -// { XML_RIGHT, chart::ChartLegendPosition_RIGHT }, - // #i35421# - { XML_END, chart::ChartLegendPosition_RIGHT }, - { XML_BOTTOM, chart::ChartLegendPosition_BOTTOM }, - { XML_TOKEN_INVALID, 0 } -}; - // ---------------------------------------- SchXMLChartContext::SchXMLChartContext( SchXMLImportHelper& rImpHelper, @@ -1273,115 +1259,3 @@ SvXMLImportContext* SchXMLTitleContext::CreateChildContext( } // ---------------------------------------- - -SchXMLLegendContext::SchXMLLegendContext( SchXMLImportHelper& rImpHelper, - SvXMLImport& rImport, const rtl::OUString& rLocalName ) : - SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ), - mrImportHelper( rImpHelper ) -{ -} - -void SchXMLLegendContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList ) -{ - uno::Reference< chart::XChartDocument > xDoc = mrImportHelper.GetChartDocument(); - if( ! xDoc.is()) - return; - - // turn on legend - uno::Reference< beans::XPropertySet > xDocProp( xDoc, uno::UNO_QUERY ); - if( xDocProp.is()) - { - uno::Any aTrueBool; - aTrueBool <<= (sal_Bool)(sal_True); - try - { - xDocProp->setPropertyValue( rtl::OUString::createFromAscii( "HasLegend" ), aTrueBool ); - } - catch( beans::UnknownPropertyException ) - { - DBG_ERROR( "Property HasLegend not found" ); - } - } - - // parse attributes - sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; - const SvXMLTokenMap& rAttrTokenMap = mrImportHelper.GetLegendAttrTokenMap(); - - awt::Point aLegendPos; - bool bHasXPosition=false; - bool bHasYPosition=false; - - rtl::OUString sAutoStyleName; - - for( sal_Int16 i = 0; i < nAttrCount; i++ ) - { - rtl::OUString sAttrName = xAttrList->getNameByIndex( i ); - rtl::OUString aLocalName; - rtl::OUString aValue = xAttrList->getValueByIndex( i ); - sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); - - switch( rAttrTokenMap.Get( nPrefix, aLocalName )) - { - case XML_TOK_LEGEND_POSITION: - { - // set anchor position - uno::Reference< beans::XPropertySet > xProp( xDoc->getLegend(), uno::UNO_QUERY ); - if( xProp.is()) - { - try - { - sal_uInt16 nEnumVal; - if( GetImport().GetMM100UnitConverter().convertEnum( nEnumVal, aValue, aXMLLegendAlignmentMap )) - { - uno::Any aAny; - aAny <<= (chart::ChartLegendPosition)(nEnumVal); - xProp->setPropertyValue( rtl::OUString::createFromAscii( "Alignment" ), aAny ); - } - } - catch( beans::UnknownPropertyException ) - { - DBG_ERROR( "Property Alignment (legend) not found" ); - } - } - } - break; - - case XML_TOK_LEGEND_X: - GetImport().GetMM100UnitConverter().convertMeasure( aLegendPos.X, aValue ); - bHasXPosition = true; - break; - case XML_TOK_LEGEND_Y: - GetImport().GetMM100UnitConverter().convertMeasure( aLegendPos.Y, aValue ); - bHasYPosition = true; - break; - case XML_TOK_LEGEND_STYLE_NAME: - sAutoStyleName = aValue; - } - } - - uno::Reference< drawing::XShape > xLegendShape( xDoc->getLegend(), uno::UNO_QUERY ); - if( xLegendShape.is() && bHasXPosition && bHasYPosition ) - xLegendShape->setPosition( aLegendPos ); - - // set auto-styles for Legend - uno::Reference< beans::XPropertySet > xProp( xLegendShape, uno::UNO_QUERY ); - if( xProp.is()) - { - // the fill style has the default "none" in XML, but "solid" in the model. - xProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FillStyle" )), - uno::makeAny( drawing::FillStyle_NONE )); - const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext(); - if( pStylesCtxt ) - { - const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext( - mrImportHelper.GetChartFamilyID(), sAutoStyleName ); - - if( pStyle && pStyle->ISA( XMLPropStyleContext )) - (( XMLPropStyleContext* )pStyle )->FillPropertySet( xProp ); - } - } -} - -SchXMLLegendContext::~SchXMLLegendContext() -{ -} diff --git a/xmloff/source/chart/SchXMLChartContext.hxx b/xmloff/source/chart/SchXMLChartContext.hxx index 41f84f783a67..e34b50c4f62d 100644 --- a/xmloff/source/chart/SchXMLChartContext.hxx +++ b/xmloff/source/chart/SchXMLChartContext.hxx @@ -171,19 +171,4 @@ public: const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList ); }; -// ---------------------------------------- - -class SchXMLLegendContext : public SvXMLImportContext -{ -private: - SchXMLImportHelper& mrImportHelper; - -public: - SchXMLLegendContext( SchXMLImportHelper& rImpHelper, - SvXMLImport& rImport, const rtl::OUString& rLocalName ); - virtual ~SchXMLLegendContext(); - - virtual void StartElement( const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList ); -}; - #endif // _SCH_XMLCHARTCONTEXT_HXX_ diff --git a/xmloff/source/chart/SchXMLEnumConverter.cxx b/xmloff/source/chart/SchXMLEnumConverter.cxx new file mode 100755 index 000000000000..fd4d7914a2fe --- /dev/null +++ b/xmloff/source/chart/SchXMLEnumConverter.cxx @@ -0,0 +1,104 @@ +/************************************************************************* + * + * 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_xmloff.hxx" +#include "SchXMLEnumConverter.hxx" + +#include <com/sun/star/chart/ChartLegendPosition.hpp> +#include <com/sun/star/chart/ChartLegendExpansion.hpp> +#include <com/sun/star/uno/Any.hxx> + +// header for rtl::Static +#include <rtl/instance.hxx> + +using ::rtl::OUString; +using namespace ::xmloff::token; +using namespace ::com::sun::star; + +namespace +{ +//----------------------------------------------------------------------- + +SvXMLEnumMapEntry aXMLLegendPositionEnumMap[] = +{ + { XML_START, chart::ChartLegendPosition_LEFT }, + { XML_TOP, chart::ChartLegendPosition_TOP }, + { XML_END, chart::ChartLegendPosition_RIGHT }, + { XML_BOTTOM, chart::ChartLegendPosition_BOTTOM }, + { XML_TOKEN_INVALID, 0 } +}; + +class XMLLegendPositionPropertyHdl : public XMLEnumPropertyHdl +{ +public: + XMLLegendPositionPropertyHdl() + : XMLEnumPropertyHdl( aXMLLegendPositionEnumMap, ::getCppuType((const chart::ChartLegendPosition*)0) ) {} + virtual ~XMLLegendPositionPropertyHdl() {}; +}; + +struct TheLegendPositionPropertyHdl : public rtl::Static< XMLLegendPositionPropertyHdl, TheLegendPositionPropertyHdl > +{ +}; + +//----------------------------------------------------------------------- + +SvXMLEnumMapEntry aXMLLegendExpansionEnumMap[] = +{ + { XML_WIDE, chart::ChartLegendExpansion_WIDE }, + { XML_HIGH, chart::ChartLegendExpansion_HIGH }, + { XML_BALANCED, chart::ChartLegendExpansion_BALANCED }, + { XML_CUSTOM, chart::ChartLegendExpansion_CUSTOM }, + { XML_TOKEN_INVALID, 0 } +}; + +class XMLLegendExpansionPropertyHdl : public XMLEnumPropertyHdl +{ +public: + XMLLegendExpansionPropertyHdl() + : XMLEnumPropertyHdl( aXMLLegendExpansionEnumMap, ::getCppuType((const chart::ChartLegendExpansion*)0) ) {} + virtual ~XMLLegendExpansionPropertyHdl() {}; +}; + +struct TheLegendExpansionPropertyHdl : public rtl::Static< XMLLegendExpansionPropertyHdl, TheLegendExpansionPropertyHdl > +{ +}; + +//----------------------------------------------------------------------- + +}//end anonymous namespace + +//----------------------------------------------------------------------- + +XMLEnumPropertyHdl& SchXMLEnumConverter::getLegendPositionConverter() +{ + return TheLegendPositionPropertyHdl::get(); +} +XMLEnumPropertyHdl& SchXMLEnumConverter::getLegendExpansionConverter() +{ + return TheLegendExpansionPropertyHdl::get(); +} diff --git a/xmloff/source/chart/SchXMLEnumConverter.hxx b/xmloff/source/chart/SchXMLEnumConverter.hxx new file mode 100755 index 000000000000..63a9fb7ffb95 --- /dev/null +++ b/xmloff/source/chart/SchXMLEnumConverter.hxx @@ -0,0 +1,39 @@ +/************************************************************************* + * + * 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 _XML_CHART_ENUM_CONVERTER_HXX_ +#define _XML_CHART_ENUM_CONVERTER_HXX_ + +#include <xmloff/EnumPropertyHdl.hxx> + +class SchXMLEnumConverter +{ +public: + static XMLEnumPropertyHdl& getLegendPositionConverter();//returns a singleton + static XMLEnumPropertyHdl& getLegendExpansionConverter();//returns a singleton +}; + +#endif // _XML_CHART_ENUM_CONVERTER_HXX_ diff --git a/xmloff/source/chart/SchXMLExport.cxx b/xmloff/source/chart/SchXMLExport.cxx index cc13eb2de733..c74abe953d2f 100644 --- a/xmloff/source/chart/SchXMLExport.cxx +++ b/xmloff/source/chart/SchXMLExport.cxx @@ -35,6 +35,8 @@ #include "SchXMLSeriesHelper.hxx" #include "ColorPropertySet.hxx" #include "SchXMLTools.hxx" +#include "SchXMLEnumConverter.hxx" + #include <tools/debug.hxx> #include <rtl/logfile.hxx> #include <comphelper/processfactory.hxx> @@ -68,6 +70,7 @@ #include <com/sun/star/chart/XAxisSupplier.hpp> #include <com/sun/star/chart/XChartDocument.hpp> #include <com/sun/star/chart/ChartLegendPosition.hpp> +#include <com/sun/star/chart/ChartLegendExpansion.hpp> #include <com/sun/star/chart/ChartDataRowSource.hpp> #include <com/sun/star/chart/ChartAxisAssign.hpp> #include <com/sun/star/chart/ChartAxisType.hpp> @@ -245,8 +248,8 @@ public: void addPosition( const ::com::sun::star::awt::Point & rPosition ); void addPosition( com::sun::star::uno::Reference< com::sun::star::drawing::XShape > xShape ); /// add svg size as attribute for current element - void addSize( const ::com::sun::star::awt::Size & rSize ); - void addSize( com::sun::star::uno::Reference< com::sun::star::drawing::XShape > xShape ); + void addSize( const ::com::sun::star::awt::Size & rSize, bool bIsOOoNamespace = false ); + void addSize( com::sun::star::uno::Reference< com::sun::star::drawing::XShape > xShape, bool bIsOOoNamespace = false ); /// fills the member msString with the appropriate String (i.e. "A3") void getCellAddress( sal_Int32 nCol, sal_Int32 nRow ); /// exports a string as a paragraph element @@ -1427,51 +1430,50 @@ void SchXMLExportHelper_Impl::parseDocument( Reference< chart::XChartDocument >& Reference< beans::XPropertySet > xProp( rChartDoc->getLegend(), uno::UNO_QUERY ); if( xProp.is()) { - chart::ChartLegendPosition aLegendPos = chart::ChartLegendPosition_NONE; + // export legend anchor position try { - Any aAny( xProp->getPropertyValue( - OUString( RTL_CONSTASCII_USTRINGPARAM( "Alignment" )))); - aAny >>= aLegendPos; + Any aAny( xProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Alignment" )))); + if( SchXMLEnumConverter::getLegendPositionConverter().exportXML( msString, aAny, mrExport.GetMM100UnitConverter() ) ) + mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_LEGEND_POSITION, msString ); } catch( beans::UnknownPropertyException & ) { DBG_WARNING( "Property Align not found in ChartLegend" ); } - switch( aLegendPos ) + // export absolute legend position + Reference< drawing::XShape > xLegendShape( xProp, uno::UNO_QUERY ); + addPosition( xLegendShape ); + + // export legend size + const SvtSaveOptions::ODFDefaultVersion nCurrentODFVersion( SvtSaveOptions().GetODFDefaultVersion() ); + if( xLegendShape.is() && nCurrentODFVersion >= SvtSaveOptions::ODFVER_012 && nCurrentODFVersion == SvtSaveOptions::ODFVER_LATEST )//do not export legend-expansion to ODF 1.0 and export size only if extensions are enabled //#i28670# todo: change this dependent on fileformat evolution { - case chart::ChartLegendPosition_LEFT: -// msString = GetXMLToken(XML_LEFT); - // #i35421# change left->start (not clear why this was done) - msString = GetXMLToken(XML_START); - break; - case chart::ChartLegendPosition_RIGHT: -// msString = GetXMLToken(XML_RIGHT); - // #i35421# change right->end (not clear why this was done) - msString = GetXMLToken(XML_END); - break; - case chart::ChartLegendPosition_TOP: - msString = GetXMLToken(XML_TOP); - break; - case chart::ChartLegendPosition_BOTTOM: - msString = GetXMLToken(XML_BOTTOM); - break; - case chart::ChartLegendPosition_NONE: - case chart::ChartLegendPosition_MAKE_FIXED_SIZE: - // nothing - break; + try + { + chart::ChartLegendExpansion nLegendExpansion = chart::ChartLegendExpansion_HIGH; + OUString aExpansionString; + Any aAny( xProp->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "Expansion" )))); + bool bHasExpansion = (aAny >>= nLegendExpansion); + if( bHasExpansion && SchXMLEnumConverter::getLegendExpansionConverter().exportXML( aExpansionString, aAny, mrExport.GetMM100UnitConverter() ) ) + { + mrExport.AddAttribute( XML_NAMESPACE_STYLE, XML_LEGEND_EXPANSION, aExpansionString ); + if( nLegendExpansion == chart::ChartLegendExpansion_CUSTOM) + { + awt::Size aSize( xLegendShape->getSize() ); + addSize( aSize, true ); + rtl::OUStringBuffer aAspectRatioString; + SvXMLUnitConverter::convertDouble(aAspectRatioString, double(aSize.Width)/double(aSize.Height)); + mrExport.AddAttribute( XML_NAMESPACE_STYLE, XML_LEGEND_EXPANSION_ASPECT_RATIO, aAspectRatioString.makeStringAndClear() ); + } + } + } + catch( beans::UnknownPropertyException & ) + { + DBG_WARNING( "Property Expansion not found in ChartLegend" ); + } } - - // export anchor position - if( msString.getLength()) - mrExport.AddAttribute( XML_NAMESPACE_CHART, XML_LEGEND_POSITION, msString ); - - // export absolute position - msString = OUString(); - Reference< drawing::XShape > xShape( xProp, uno::UNO_QUERY ); - if( xShape.is()) - addPosition( xShape ); } // write style name @@ -3535,21 +3537,22 @@ void SchXMLExportHelper_Impl::addPosition( Reference< drawing::XShape > xShape ) addPosition( xShape->getPosition()); } -void SchXMLExportHelper_Impl::addSize( const awt::Size & rSize ) +void SchXMLExportHelper_Impl::addSize( const awt::Size & rSize, bool bIsOOoNamespace) { mrExport.GetMM100UnitConverter().convertMeasure( msStringBuffer, rSize.Width ); msString = msStringBuffer.makeStringAndClear(); - mrExport.AddAttribute( XML_NAMESPACE_SVG, XML_WIDTH, msString ); + mrExport.AddAttribute( bIsOOoNamespace ? XML_NAMESPACE_CHART_EXT : XML_NAMESPACE_SVG , XML_WIDTH, msString ); + - mrExport.GetMM100UnitConverter().convertMeasure( msStringBuffer, rSize.Height ); + mrExport.GetMM100UnitConverter().convertMeasure( msStringBuffer, rSize.Height); msString = msStringBuffer.makeStringAndClear(); - mrExport.AddAttribute( XML_NAMESPACE_SVG, XML_HEIGHT, msString ); + mrExport.AddAttribute( bIsOOoNamespace ? XML_NAMESPACE_CHART_EXT : XML_NAMESPACE_SVG, XML_HEIGHT, msString ); } -void SchXMLExportHelper_Impl::addSize( Reference< drawing::XShape > xShape ) +void SchXMLExportHelper_Impl::addSize( Reference< drawing::XShape > xShape, bool bIsOOoNamespace ) { if( xShape.is()) - addSize( xShape->getSize() ); + addSize( xShape->getSize(), bIsOOoNamespace ); } awt::Size SchXMLExportHelper_Impl::getPageSize( const Reference< chart2::XChartDocument > & xChartDoc ) const diff --git a/xmloff/source/chart/SchXMLImport.cxx b/xmloff/source/chart/SchXMLImport.cxx index a033dcb60e7d..12bea7e50e1b 100644 --- a/xmloff/source/chart/SchXMLImport.cxx +++ b/xmloff/source/chart/SchXMLImport.cxx @@ -146,7 +146,6 @@ SchXMLImportHelper::SchXMLImportHelper() : mpChartAttrTokenMap( 0 ), mpPlotAreaAttrTokenMap( 0 ), - mpLegendAttrTokenMap( 0 ), mpAutoStyleAttrTokenMap( 0 ), mpCellAttrTokenMap( 0 ), mpSeriesAttrTokenMap( 0 ), @@ -172,8 +171,6 @@ SchXMLImportHelper::~SchXMLImportHelper() delete mpChartAttrTokenMap; if( mpPlotAreaAttrTokenMap ) delete mpPlotAreaAttrTokenMap; - if( mpLegendAttrTokenMap ) - delete mpLegendAttrTokenMap; if( mpAutoStyleAttrTokenMap ) delete mpAutoStyleAttrTokenMap; if( mpCellAttrTokenMap ) @@ -371,25 +368,6 @@ const SvXMLTokenMap& SchXMLImportHelper::GetPlotAreaAttrTokenMap() return *mpPlotAreaAttrTokenMap; } -const SvXMLTokenMap& SchXMLImportHelper::GetLegendAttrTokenMap() -{ - if( ! mpLegendAttrTokenMap ) - { - static __FAR_DATA SvXMLTokenMapEntry aLegendAttrTokenMap[] = -{ - { XML_NAMESPACE_CHART, XML_LEGEND_POSITION, XML_TOK_LEGEND_POSITION }, - { XML_NAMESPACE_SVG, XML_X, XML_TOK_LEGEND_X }, - { XML_NAMESPACE_SVG, XML_Y, XML_TOK_LEGEND_Y }, - { XML_NAMESPACE_CHART, XML_STYLE_NAME, XML_TOK_LEGEND_STYLE_NAME }, - XML_TOKEN_MAP_END -}; - - mpLegendAttrTokenMap = new SvXMLTokenMap( aLegendAttrTokenMap ); - } // if( ! mpLegendAttrTokenMap ) - - return *mpLegendAttrTokenMap; -} - const SvXMLTokenMap& SchXMLImportHelper::GetAutoStyleAttrTokenMap() { if( ! mpAutoStyleAttrTokenMap ) diff --git a/xmloff/source/chart/SchXMLLegendContext.cxx b/xmloff/source/chart/SchXMLLegendContext.cxx new file mode 100755 index 000000000000..6220fdfca46a --- /dev/null +++ b/xmloff/source/chart/SchXMLLegendContext.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_xmloff.hxx" +#include "SchXMLLegendContext.hxx" +#include "SchXMLEnumConverter.hxx" + +#include <xmloff/xmlnmspe.hxx> +#include <xmloff/xmlement.hxx> +#include <xmloff/prstylei.hxx> +#include <xmloff/nmspmap.hxx> +#include <xmloff/xmluconv.hxx> + +#include <tools/debug.hxx> + +#include <com/sun/star/chart/ChartLegendPosition.hpp> +#include <com/sun/star/chart/ChartLegendExpansion.hpp> +#include <com/sun/star/drawing/FillStyle.hpp> + +using namespace ::xmloff::token; +using namespace com::sun::star; + +using rtl::OUString; +using com::sun::star::uno::Reference; + +//---------------------------------------- + +namespace +{ + +enum LegendAttributeTokens +{ + XML_TOK_LEGEND_POSITION, + XML_TOK_LEGEND_X, + XML_TOK_LEGEND_Y, + XML_TOK_LEGEND_STYLE_NAME, + XML_TOK_LEGEND_EXPANSION, + XML_TOK_LEGEND_EXPANSION_ASPECT_RATIO, + XML_TOK_LEGEND_WIDTH, + XML_TOK_LEGEND_WIDTH_EXT, + XML_TOK_LEGEND_HEIGHT, + XML_TOK_LEGEND_HEIGHT_EXT +}; + +SvXMLTokenMapEntry aLegendAttributeTokenMap[] = +{ + { XML_NAMESPACE_CHART, XML_LEGEND_POSITION, XML_TOK_LEGEND_POSITION }, + { XML_NAMESPACE_SVG, XML_X, XML_TOK_LEGEND_X }, + { XML_NAMESPACE_SVG, XML_Y, XML_TOK_LEGEND_Y }, + { XML_NAMESPACE_CHART, XML_STYLE_NAME, XML_TOK_LEGEND_STYLE_NAME }, + { XML_NAMESPACE_STYLE, XML_LEGEND_EXPANSION, XML_TOK_LEGEND_EXPANSION }, + { XML_NAMESPACE_STYLE, XML_LEGEND_EXPANSION_ASPECT_RATIO, XML_TOK_LEGEND_EXPANSION_ASPECT_RATIO }, + { XML_NAMESPACE_SVG, XML_WIDTH, XML_TOK_LEGEND_WIDTH }, + { XML_NAMESPACE_CHART_EXT, XML_WIDTH, XML_TOK_LEGEND_WIDTH_EXT }, + { XML_NAMESPACE_SVG, XML_HEIGHT, XML_TOK_LEGEND_HEIGHT }, + { XML_NAMESPACE_CHART_EXT, XML_HEIGHT, XML_TOK_LEGEND_HEIGHT_EXT }, + XML_TOKEN_MAP_END +}; + +class LegendAttributeTokenMap : public SvXMLTokenMap +{ +public: + LegendAttributeTokenMap(): SvXMLTokenMap( aLegendAttributeTokenMap ) {} + virtual ~LegendAttributeTokenMap() {} +}; + +//a LegendAttributeTokenMap Singleton +struct theLegendAttributeTokenMap : public rtl::Static< LegendAttributeTokenMap, theLegendAttributeTokenMap > {}; + +}//end anonymous namespace + +//---------------------------------------- + +SchXMLLegendContext::SchXMLLegendContext( SchXMLImportHelper& rImpHelper, SvXMLImport& rImport, const rtl::OUString& rLocalName ) : + SvXMLImportContext( rImport, XML_NAMESPACE_CHART, rLocalName ), + mrImportHelper( rImpHelper ) +{ +} + +void SchXMLLegendContext::StartElement( const uno::Reference< xml::sax::XAttributeList >& xAttrList ) +{ + uno::Reference< chart::XChartDocument > xDoc = mrImportHelper.GetChartDocument(); + if( !xDoc.is() ) + return; + + // turn on legend + uno::Reference< beans::XPropertySet > xDocProp( xDoc, uno::UNO_QUERY ); + if( xDocProp.is() ) + { + try + { + xDocProp->setPropertyValue( rtl::OUString::createFromAscii( "HasLegend" ), uno::makeAny( sal_True ) ); + } + catch( beans::UnknownPropertyException ) + { + DBG_ERROR( "Property HasLegend not found" ); + } + } + + uno::Reference< drawing::XShape > xLegendShape( xDoc->getLegend(), uno::UNO_QUERY ); + uno::Reference< beans::XPropertySet > xLegendProps( xLegendShape, uno::UNO_QUERY ); + if( !xLegendShape.is() || !xLegendProps.is() ) + { + DBG_ERROR( "legend could not be created" ); + return; + } + + // parse attributes + sal_Int16 nAttrCount = xAttrList.is()? xAttrList->getLength(): 0; + const SvXMLTokenMap& rAttrTokenMap = theLegendAttributeTokenMap::get(); + + awt::Point aLegendPos; + bool bHasXPosition=false; + bool bHasYPosition=false; + awt::Size aLegendSize; + bool bHasWidth=false; + bool bHasHeight=false; + chart::ChartLegendExpansion nLegendExpansion = chart::ChartLegendExpansion_HIGH; + bool bHasExpansion=false; + + rtl::OUString sAutoStyleName; + uno::Any aAny; + + for( sal_Int16 i = 0; i < nAttrCount; i++ ) + { + rtl::OUString sAttrName = xAttrList->getNameByIndex( i ); + rtl::OUString aLocalName; + rtl::OUString aValue = xAttrList->getValueByIndex( i ); + sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); + + switch( rAttrTokenMap.Get( nPrefix, aLocalName )) + { + case XML_TOK_LEGEND_POSITION: + { + try + { + if( SchXMLEnumConverter::getLegendPositionConverter().importXML( aValue, aAny, GetImport().GetMM100UnitConverter() ) ) + xLegendProps->setPropertyValue( rtl::OUString::createFromAscii( "Alignment" ), aAny ); + } + catch( beans::UnknownPropertyException ) + { + DBG_ERROR( "Property Alignment (legend) not found" ); + } + } + break; + + case XML_TOK_LEGEND_X: + GetImport().GetMM100UnitConverter().convertMeasure( aLegendPos.X, aValue ); + bHasXPosition = true; + break; + case XML_TOK_LEGEND_Y: + GetImport().GetMM100UnitConverter().convertMeasure( aLegendPos.Y, aValue ); + bHasYPosition = true; + break; + case XML_TOK_LEGEND_STYLE_NAME: + sAutoStyleName = aValue; + break; + case XML_TOK_LEGEND_EXPANSION: + SchXMLEnumConverter::getLegendPositionConverter().importXML( aValue, aAny, GetImport().GetMM100UnitConverter() ); + bHasExpansion = (aAny>>=nLegendExpansion); + break; + case XML_TOK_LEGEND_EXPANSION_ASPECT_RATIO: + break; + case XML_TOK_LEGEND_WIDTH: + case XML_TOK_LEGEND_WIDTH_EXT: + GetImport().GetMM100UnitConverter().convertMeasure( aLegendSize.Width, aValue ); + bHasWidth = true; + break; + case XML_TOK_LEGEND_HEIGHT: + case XML_TOK_LEGEND_HEIGHT_EXT: + GetImport().GetMM100UnitConverter().convertMeasure( aLegendSize.Height, aValue ); + bHasHeight = true; + break; + default: + break; + } + } + + if( bHasXPosition && bHasYPosition ) + xLegendShape->setPosition( aLegendPos ); + + if( bHasExpansion && nLegendExpansion!= chart::ChartLegendExpansion_CUSTOM ) + xLegendProps->setPropertyValue( rtl::OUString::createFromAscii( "Expansion" ), uno::makeAny(nLegendExpansion) ); + else if( bHasHeight && bHasWidth ) + xLegendShape->setSize( aLegendSize ); + + // the fill style has the default "none" in XML, but "solid" in the model. + xLegendProps->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FillStyle" )), uno::makeAny( drawing::FillStyle_NONE )); + + // set auto-styles for Legend + const SvXMLStylesContext* pStylesCtxt = mrImportHelper.GetAutoStylesContext(); + if( pStylesCtxt ) + { + const SvXMLStyleContext* pStyle = pStylesCtxt->FindStyleChildContext( + mrImportHelper.GetChartFamilyID(), sAutoStyleName ); + + if( pStyle && pStyle->ISA( XMLPropStyleContext )) + (( XMLPropStyleContext* )pStyle )->FillPropertySet( xLegendProps ); + } +} + +SchXMLLegendContext::~SchXMLLegendContext() +{ +} diff --git a/xmloff/source/chart/SchXMLLegendContext.hxx b/xmloff/source/chart/SchXMLLegendContext.hxx new file mode 100755 index 000000000000..1841b0cef24b --- /dev/null +++ b/xmloff/source/chart/SchXMLLegendContext.hxx @@ -0,0 +1,46 @@ +/************************************************************************* + * + * 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 _SCH_XMLLEGENDCONTEXT_HXX_ +#define _SCH_XMLLEGENDCONTEXT_HXX_ + +#include "SchXMLImport.hxx" + +// ---------------------------------------- + +class SchXMLLegendContext : public SvXMLImportContext +{ +public: + SchXMLLegendContext( SchXMLImportHelper& rImpHelper, SvXMLImport& rImport, const rtl::OUString& rLocalName ); + virtual ~SchXMLLegendContext(); + + virtual void StartElement( const com::sun::star::uno::Reference< com::sun::star::xml::sax::XAttributeList >& xAttrList ); + +private: + SchXMLImportHelper& mrImportHelper; +}; + +#endif // _SCH_XMLLEGENDCONTEXT_HXX_ diff --git a/xmloff/source/chart/makefile.mk b/xmloff/source/chart/makefile.mk index 2f61a3d6f0e5..3151d633d13f 100644 --- a/xmloff/source/chart/makefile.mk +++ b/xmloff/source/chart/makefile.mk @@ -45,12 +45,14 @@ SLOFILES = $(SLO)$/ColorPropertySet.obj \ $(SLO)$/contexts.obj \ $(SLO)$/SchXMLTableContext.obj \ $(SLO)$/SchXMLChartContext.obj \ + $(SLO)$/SchXMLLegendContext.obj \ $(SLO)$/SchXMLPlotAreaContext.obj \ $(SLO)$/SchXMLAxisContext.obj \ $(SLO)$/SchXMLParagraphContext.obj \ $(SLO)$/SchXMLTextListContext.obj \ $(SLO)$/SchXMLSeriesHelper.obj \ $(SLO)$/SchXMLSeries2Context.obj \ + $(SLO)$/SchXMLEnumConverter.obj \ $(SLO)$/PropertyMaps.obj \ $(SLO)$/XMLChartStyleContext.obj \ $(SLO)$/XMLErrorIndicatorPropertyHdl.obj \ diff --git a/xmloff/source/core/xmltoken.cxx b/xmloff/source/core/xmltoken.cxx index 824d28a51a5c..bc1e40114c5f 100644 --- a/xmloff/source/core/xmltoken.cxx +++ b/xmloff/source/core/xmltoken.cxx @@ -3113,6 +3113,12 @@ namespace xmloff { namespace token { TOKEN( "outside-minimum", XML_OUTSIDE_MINIMUM ), TOKEN( "outside-maximum", XML_OUTSIDE_MAXIMUM ), + TOKEN( "legend-expansion", XML_LEGEND_EXPANSION), + TOKEN( "legend-expansion-aspect-ratio", XML_LEGEND_EXPANSION_ASPECT_RATIO), + TOKEN( "balanced", XML_BALANCED), + TOKEN( "high", XML_HIGH), + TOKEN( "wide", XML_WIDE), + TOKEN( "axis-type", XML_AXIS_TYPE ), //#i25706# TOKEN( "date-scale", XML_DATE_SCALE ), TOKEN( "base-time-unit", XML_BASE_TIME_UNIT ), |