diff options
Diffstat (limited to 'oox/source/drawingml')
-rw-r--r-- | oox/source/drawingml/chart/chartconverter.cxx | 12 | ||||
-rw-r--r-- | oox/source/drawingml/chart/chartdrawingfragment.cxx | 239 | ||||
-rw-r--r-- | oox/source/drawingml/chart/chartspaceconverter.cxx | 63 | ||||
-rw-r--r-- | oox/source/drawingml/chart/chartspacefragment.cxx | 3 | ||||
-rw-r--r-- | oox/source/drawingml/chart/converterbase.cxx | 23 | ||||
-rw-r--r-- | oox/source/drawingml/chart/makefile.mk | 1 | ||||
-rw-r--r-- | oox/source/drawingml/graphicshapecontext.cxx | 33 | ||||
-rw-r--r-- | oox/source/drawingml/shape.cxx | 28 | ||||
-rw-r--r-- | oox/source/drawingml/shapegroupcontext.cxx | 2 |
9 files changed, 355 insertions, 49 deletions
diff --git a/oox/source/drawingml/chart/chartconverter.cxx b/oox/source/drawingml/chart/chartconverter.cxx index f1b592631f2d..efd8e6d021e1 100644 --- a/oox/source/drawingml/chart/chartconverter.cxx +++ b/oox/source/drawingml/chart/chartconverter.cxx @@ -33,6 +33,9 @@ using ::rtl::OUString; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Exception; +using ::com::sun::star::awt::Point; +using ::com::sun::star::awt::Size; +using ::com::sun::star::drawing::XShapes; using ::com::sun::star::chart2::XChartDocument; using ::com::sun::star::chart2::data::XDataProvider; using ::com::sun::star::chart2::data::XDataSequence; @@ -53,14 +56,15 @@ ChartConverter::~ChartConverter() } void ChartConverter::convertFromModel( XmlFilterBase& rFilter, - ChartSpaceModel& rModel, const Reference< XChartDocument >& rxChartDoc ) + ChartSpaceModel& rChartModel, const Reference< XChartDocument >& rxChartDoc, + const Reference< XShapes >& rxExternalPage, const Point& rChartPos, const Size& rChartSize ) { OSL_ENSURE( rxChartDoc.is(), "ChartConverter::convertFromModel - missing chart document" ); if( rxChartDoc.is() ) { - ConverterRoot aConvBase( rFilter, *this, rxChartDoc, rModel ); - ChartSpaceConverter aSpaceConv( aConvBase, rModel ); - aSpaceConv.convertFromModel(); + ConverterRoot aConvBase( rFilter, *this, rChartModel, rxChartDoc, rChartSize ); + ChartSpaceConverter aSpaceConv( aConvBase, rChartModel ); + aSpaceConv.convertFromModel( rxExternalPage, rChartPos ); } } diff --git a/oox/source/drawingml/chart/chartdrawingfragment.cxx b/oox/source/drawingml/chart/chartdrawingfragment.cxx new file mode 100644 index 000000000000..9df064125457 --- /dev/null +++ b/oox/source/drawingml/chart/chartdrawingfragment.cxx @@ -0,0 +1,239 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: chartdrawingfragment.cxx,v $ + * + * $Revision: 1.1 $ + * + * 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. + * + ************************************************************************/ + +#include "oox/drawingml/chart/chartdrawingfragment.hxx" +#include "oox/core/xmlfilterbase.hxx" +#include "oox/drawingml/connectorshapecontext.hxx" +#include "oox/drawingml/graphicshapecontext.hxx" +#include "oox/drawingml/shapecontext.hxx" +#include "oox/drawingml/shapegroupcontext.hxx" + +using ::rtl::OUString; +using ::com::sun::star::uno::Reference; +using ::com::sun::star::awt::Point; +using ::com::sun::star::awt::Rectangle; +using ::com::sun::star::awt::Size; +using ::com::sun::star::drawing::XShapes; +using ::oox::core::ContextHandlerRef; +using ::oox::core::FragmentHandler2; +using ::oox::core::XmlFilterBase; + +namespace oox { +namespace drawingml { +namespace chart { + +// ============================================================================ + +ShapeAnchor::ShapeAnchor( bool bRelSize ) : + mbRelSize( bRelSize ) +{ +} + +void ShapeAnchor::importExt( const AttributeList& rAttribs ) +{ + OSL_ENSURE( !mbRelSize, "ShapeAnchor::importExt - unexpected 'cdr:ext' element" ); + maSize.Width = rAttribs.getHyper( XML_cx, 0 ); + maSize.Height = rAttribs.getHyper( XML_cy, 0 ); +} + +void ShapeAnchor::setPos( sal_Int32 nElement, sal_Int32 nParentContext, const OUString& rValue ) +{ + AnchorPosModel* pAnchorPos = 0; + switch( nParentContext ) + { + case CDR_TOKEN( from ): + pAnchorPos = &maFrom; + break; + case CDR_TOKEN( to ): + OSL_ENSURE( mbRelSize, "ShapeAnchor::setPos - unexpected 'cdr:to' element" ); + pAnchorPos = &maTo; + break; + default: + OSL_ENSURE( false, "ShapeAnchor::setPos - unexpected parent element" ); + } + if( pAnchorPos ) switch( nElement ) + { + case CDR_TOKEN( x ): pAnchorPos->mfX = rValue.toDouble(); break; + case CDR_TOKEN( y ): pAnchorPos->mfY = rValue.toDouble(); break; + default: OSL_ENSURE( false, "ShapeAnchor::setPos - unexpected element" ); + } +} + +Rectangle ShapeAnchor::calcEmuLocation( const EmuRectangle& rEmuChartRect ) const +{ + Rectangle aLoc( -1, -1, -1, -1 ); + + OSL_ENSURE( maFrom.isValid(), "ShapeAnchor::calcEmuLocation - invalid from position" ); + OSL_ENSURE( mbRelSize ? maTo.isValid() : maSize.isValid(), "ShapeAnchor::calcEmuLocation - invalid to/size" ); + if( maFrom.isValid() && (mbRelSize ? maTo.isValid() : maSize.isValid()) ) + { + // calculate shape position + aLoc.X = getLimitedValue< sal_Int32, double >( maFrom.mfX * rEmuChartRect.Width, 0, SAL_MAX_INT32 ); + aLoc.Y = getLimitedValue< sal_Int32, double >( maFrom.mfY * rEmuChartRect.Height, 0, SAL_MAX_INT32 ); + + // calculate shape size + if( mbRelSize ) + { + aLoc.Width = getLimitedValue< sal_Int32, double >( maTo.mfX * rEmuChartRect.Width, 0, SAL_MAX_INT32 ) - aLoc.X; + if( aLoc.Width < 0 ) + { + aLoc.X += aLoc.Width; + aLoc.Width *= -1; + } + aLoc.Height = getLimitedValue< sal_Int32, double >( maTo.mfY * rEmuChartRect.Height, 0, SAL_MAX_INT32 ) - aLoc.Y; + if( aLoc.Height < 0 ) + { + aLoc.Y += aLoc.Height; + aLoc.Height *= -1; + } + } + else + { + aLoc.Width = getLimitedValue< sal_Int32, sal_Int64 >( maSize.Width, 0, SAL_MAX_INT32 ); + aLoc.Height = getLimitedValue< sal_Int32, sal_Int64 >( maSize.Height, 0, SAL_MAX_INT32 ); + } + } + + return aLoc; +} +// ============================================================================ + +ChartDrawingFragment::ChartDrawingFragment( XmlFilterBase& rFilter, + const OUString& rFragmentPath, const Reference< XShapes >& rxDrawPage, + const Size& rChartSize, const Point& rShapesOffset, bool bOleSupport ) : + FragmentHandler2( rFilter, rFragmentPath ), + mxDrawPage( rxDrawPage ), + mbOleSupport( bOleSupport ) +{ + maEmuChartRect.X = static_cast< sal_Int64 >( rShapesOffset.X ) * 360; + maEmuChartRect.Y = static_cast< sal_Int64 >( rShapesOffset.Y ) * 360; + maEmuChartRect.Width = static_cast< sal_Int64 >( rChartSize.Width ) * 360; + maEmuChartRect.Height = static_cast< sal_Int64 >( rChartSize.Height ) * 360; +} + +ChartDrawingFragment::~ChartDrawingFragment() +{ +} + +ContextHandlerRef ChartDrawingFragment::onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) +{ + switch( getCurrentElement() ) + { + case XML_ROOT_CONTEXT: + if( nElement == C_TOKEN( userShapes ) ) return this; + break; + + case C_TOKEN( userShapes ): + switch( nElement ) + { + case CDR_TOKEN( absSizeAnchor ): + mxAnchor.reset( new ShapeAnchor( false ) ); + return this; + case CDR_TOKEN( relSizeAnchor ): + mxAnchor.reset( new ShapeAnchor( true ) ); + return this; + } + break; + + case CDR_TOKEN( absSizeAnchor ): + case CDR_TOKEN( relSizeAnchor ): + switch( nElement ) + { + case CDR_TOKEN( sp ): + mxShape.reset( new Shape( "com.sun.star.drawing.CustomShape" ) ); + return new ShapeContext( *this, ShapePtr(), mxShape ); + case CDR_TOKEN( cxnSp ): + mxShape.reset( new Shape( "com.sun.star.drawing.ConnectorShape" ) ); + return new ConnectorShapeContext( *this, ShapePtr(), mxShape ); + case CDR_TOKEN( pic ): + mxShape.reset( new Shape( "com.sun.star.drawing.GraphicObjectShape" ) ); + return new GraphicShapeContext( *this, ShapePtr(), mxShape ); + case CDR_TOKEN( graphicFrame ): + if( !mbOleSupport ) + return 0; + mxShape.reset( new Shape( "com.sun.star.drawing.OLE2Shape" ) ); + return new GraphicalObjectFrameContext( *this, ShapePtr(), mxShape, true ); + case CDR_TOKEN( grpSp ): + mxShape.reset( new Shape( "com.sun.star.drawing.GroupShape" ) ); + return new ShapeGroupContext( *this, ShapePtr(), mxShape ); + + case CDR_TOKEN( from ): + case CDR_TOKEN( to ): + return this; + + case CDR_TOKEN( ext ): + if( mxAnchor.get() ) mxAnchor->importExt( rAttribs ); + return 0; + } + break; + + case CDR_TOKEN( from ): + case CDR_TOKEN( to ): + switch( nElement ) + { + case CDR_TOKEN( x ): + case CDR_TOKEN( y ): + return this; // collect value in onEndElement() + } + break; + } + return 0; +} + +void ChartDrawingFragment::onEndElement( const OUString& rChars ) +{ + switch( getCurrentElement() ) + { + case CDR_TOKEN( x ): + case CDR_TOKEN( y ): + if( mxAnchor.get() ) mxAnchor->setPos( getCurrentElement(), getPreviousElement(), rChars ); + break; + + case CDR_TOKEN( absSizeAnchor ): + case CDR_TOKEN( relSizeAnchor ): + if( mxDrawPage.is() && mxShape.get() && mxAnchor.get() ) + { + Rectangle aLoc = mxAnchor->calcEmuLocation( maEmuChartRect ); + if( (aLoc.X >= 0) && (aLoc.Y >= 0) && (aLoc.Width >= 0) && (aLoc.Height >= 0) ) + mxShape->addShape( getFilter(), getFilter().getCurrentTheme(), mxDrawPage, &aLoc ); + } + mxShape.reset(); + mxAnchor.reset(); + break; + } +} + +// ============================================================================ + +} // namespace chart +} // namespace drawingml +} // namespace oox + diff --git a/oox/source/drawingml/chart/chartspaceconverter.cxx b/oox/source/drawingml/chart/chartspaceconverter.cxx index 390f7ccfe7b9..6460e94a4f3b 100644 --- a/oox/source/drawingml/chart/chartspaceconverter.cxx +++ b/oox/source/drawingml/chart/chartspaceconverter.cxx @@ -26,24 +26,29 @@ ************************************************************************/ #include "oox/drawingml/chart/chartspaceconverter.hxx" +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/chart/MissingValueTreatment.hpp> #include <com/sun/star/chart/XChartDocument.hpp> #include <com/sun/star/chart2/XChartDocument.hpp> #include <com/sun/star/chart2/XTitled.hpp> #include <com/sun/star/chart2/data/XDataReceiver.hpp> -#include <com/sun/star/chart/MissingValueTreatment.hpp> #include "oox/core/xmlfilterbase.hxx" #include "oox/drawingml/chart/chartconverter.hxx" +#include "oox/drawingml/chart/chartdrawingfragment.hxx" #include "oox/drawingml/chart/chartspacemodel.hxx" #include "oox/drawingml/chart/plotareaconverter.hxx" #include "oox/drawingml/chart/titleconverter.hxx" #include "properties.hxx" using ::rtl::OUString; +using ::com::sun::star::awt::Point; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Exception; using ::com::sun::star::uno::UNO_QUERY; using ::com::sun::star::uno::UNO_QUERY_THROW; using ::com::sun::star::util::XNumberFormatsSupplier; +using ::com::sun::star::drawing::XDrawPageSupplier; +using ::com::sun::star::drawing::XShapes; using ::com::sun::star::chart2::XDiagram; using ::com::sun::star::chart2::XTitled; using ::com::sun::star::chart2::data::XDataReceiver; @@ -63,7 +68,7 @@ ChartSpaceConverter::~ChartSpaceConverter() { } -void ChartSpaceConverter::convertFromModel() +void ChartSpaceConverter::convertFromModel( const Reference< XShapes >& rxExternalPage, const Point& rChartPos ) { /* create data provider (virtual function in the ChartConverter class, derived converters may create an external data provider) */ @@ -81,8 +86,8 @@ void ChartSpaceConverter::convertFromModel() } // formatting of the chart background - PropertySet aPropSet( getChartDocument()->getPageBackground() ); - getFormatter().convertFrameFormatting( aPropSet, mrModel.mxShapeProp, OBJECTTYPE_CHARTSPACE ); + PropertySet aBackPropSet( getChartDocument()->getPageBackground() ); + getFormatter().convertFrameFormatting( aBackPropSet, mrModel.mxShapeProp, OBJECTTYPE_CHARTSPACE ); // convert plot area (container of all chart type groups) PlotAreaConverter aPlotAreaConv( *this, mrModel.mxPlotArea.getOrCreate() ); @@ -121,10 +126,10 @@ void ChartSpaceConverter::convertFromModel() } // legend - if( mrModel.mxLegend.is() ) + if( xDiagram.is() && mrModel.mxLegend.is() ) { LegendConverter aLegendConv( *this, *mrModel.mxLegend ); - aLegendConv.convertFromModel( getChartDocument()->getFirstDiagram() ); + aLegendConv.convertFromModel( xDiagram ); } // treatment of missing values @@ -142,12 +147,48 @@ void ChartSpaceConverter::convertFromModel() aDiaProp.setProperty( PROP_MissingValueTreatment, nMissingValues ); } - // set the IncludeHiddenCells property via the old API as only this ensures that the data provider and al created sequences get this flag correctly - Reference< com::sun::star::chart::XChartDocument > xStandardApiChartDoc( getChartDocument(), UNO_QUERY ); - if( xStandardApiChartDoc.is() ) + Reference< com::sun::star::chart::XChartDocument > xOldChartDoc( getChartDocument(), UNO_QUERY ); + if( xOldChartDoc.is() ) + { + /* Set the IncludeHiddenCells property via the old API as only this + ensures that the data provider and all created sequences get this + flag correctly. */ + PropertySet aOldDiaProp( xOldChartDoc->getDiagram() ); + aOldDiaProp.setProperty( PROP_IncludeHiddenCells, !mrModel.mbPlotVisOnly ); + } + + // embedded drawing shapes + if( mrModel.maDrawingPath.getLength() > 0 ) try + { + /* Get the internal draw page of the chart document, if no external + drawing page has been passed. */ + Reference< XShapes > xShapes; + Point aShapesOffset( 0, 0 ); + if( rxExternalPage.is() ) + { + xShapes = rxExternalPage; + // offset for embedded shapes to move them inside the chart area + aShapesOffset = rChartPos; + } + else + { + Reference< XDrawPageSupplier > xDrawPageSupp( getChartDocument(), UNO_QUERY_THROW ); + xShapes.set( xDrawPageSupp->getDrawPage(), UNO_QUERY_THROW ); + } + + /* If an external drawing page is passed, all embedded shapes will be + inserted there (used e.g. with 'chart sheets' in spreadsheet + documents). In this case, all types of shapes including OLE objects + are supported. If the shapes are inserted into the internal chart + drawing page instead, it is not possible to embed OLE objects. */ + bool bOleSupport = rxExternalPage.is(); + + // now, xShapes is not null anymore + getFilter().importFragment( new ChartDrawingFragment( + getFilter(), mrModel.maDrawingPath, xShapes, getChartSize(), aShapesOffset, bOleSupport ) ); + } + catch( Exception& ) { - PropertySet aStandardApiDiagramProp( xStandardApiChartDoc->getDiagram() ); - aStandardApiDiagramProp.setProperty( PROP_IncludeHiddenCells, !mrModel.mbPlotVisOnly ); } } diff --git a/oox/source/drawingml/chart/chartspacefragment.cxx b/oox/source/drawingml/chart/chartspacefragment.cxx index d041997636a9..75df94e95de7 100644 --- a/oox/source/drawingml/chart/chartspacefragment.cxx +++ b/oox/source/drawingml/chart/chartspacefragment.cxx @@ -75,6 +75,9 @@ ContextHandlerRef ChartSpaceFragment::onCreateContext( sal_Int32 nElement, const return 0; case C_TOKEN( txPr ): return new TextBodyContext( *this, mrModel.mxTextProp.create() ); + case C_TOKEN( userShapes ): + mrModel.maDrawingPath = getFragmentPathFromRelId( rAttribs.getString( R_TOKEN( id ), OUString() ) ); + return 0; } break; diff --git a/oox/source/drawingml/chart/converterbase.cxx b/oox/source/drawingml/chart/converterbase.cxx index 596efcf8b30f..534ce48e0278 100644 --- a/oox/source/drawingml/chart/converterbase.cxx +++ b/oox/source/drawingml/chart/converterbase.cxx @@ -40,6 +40,7 @@ using ::com::sun::star::uno::Exception; using ::com::sun::star::uno::UNO_QUERY_THROW; using ::com::sun::star::lang::XMultiServiceFactory; using ::com::sun::star::frame::XModel; +using ::com::sun::star::awt::Size; using ::com::sun::star::chart2::XChartDocument; using ::oox::core::XmlFilterBase; @@ -51,16 +52,18 @@ namespace chart { struct ConverterData { + ObjectFormatter maFormatter; XmlFilterBase& mrFilter; ChartConverter& mrConverter; Reference< XChartDocument > mxDoc; - ObjectFormatter maFormatter; + Size maSize; explicit ConverterData( XmlFilterBase& rFilter, ChartConverter& rChartConverter, + const ChartSpaceModel& rChartModel, const Reference< XChartDocument >& rxChartDoc, - const ChartSpaceModel& rChartSpace ); + const Size& rChartSize ); ~ConverterData(); }; @@ -69,12 +72,14 @@ struct ConverterData ConverterData::ConverterData( XmlFilterBase& rFilter, ChartConverter& rChartConverter, + const ChartSpaceModel& rChartModel, const Reference< XChartDocument >& rxChartDoc, - const ChartSpaceModel& rChartSpace ) : + const Size& rChartSize ) : + maFormatter( rFilter, rxChartDoc, rChartModel ), mrFilter( rFilter ), mrConverter( rChartConverter ), mxDoc( rxChartDoc ), - maFormatter( rFilter, rxChartDoc, rChartSpace ) + maSize( rChartSize ) { OSL_ENSURE( mxDoc.is(), "ConverterData::ConverterData - missing chart document" ); // lock the model to suppress internal updates during conversion @@ -106,9 +111,10 @@ ConverterData::~ConverterData() ConverterRoot::ConverterRoot( XmlFilterBase& rFilter, ChartConverter& rChartConverter, + const ChartSpaceModel& rChartModel, const Reference< XChartDocument >& rxChartDoc, - const ChartSpaceModel& rChartSpace ) : - mxData( new ConverterData( rFilter, rChartConverter, rxChartDoc, rChartSpace ) ) + const Size& rChartSize ) : + mxData( new ConverterData( rFilter, rChartConverter, rChartModel, rxChartDoc, rChartSize ) ) { } @@ -151,6 +157,11 @@ Reference< XChartDocument > ConverterRoot::getChartDocument() const return mxData->mxDoc; } +const Size& ConverterRoot::getChartSize() const +{ + return mxData->maSize; +} + ObjectFormatter& ConverterRoot::getFormatter() const { return mxData->maFormatter; diff --git a/oox/source/drawingml/chart/makefile.mk b/oox/source/drawingml/chart/makefile.mk index 3ba22a30f9e6..84762e6a2540 100644 --- a/oox/source/drawingml/chart/makefile.mk +++ b/oox/source/drawingml/chart/makefile.mk @@ -46,6 +46,7 @@ SLOFILES = \ $(SLO)$/axismodel.obj \ $(SLO)$/chartcontextbase.obj \ $(SLO)$/chartconverter.obj \ + $(SLO)$/chartdrawingfragment.obj \ $(SLO)$/chartspaceconverter.obj \ $(SLO)$/chartspacefragment.obj \ $(SLO)$/chartspacemodel.obj \ diff --git a/oox/source/drawingml/graphicshapecontext.cxx b/oox/source/drawingml/graphicshapecontext.cxx index bcb562c0118f..a0335fe68ee2 100644 --- a/oox/source/drawingml/graphicshapecontext.cxx +++ b/oox/source/drawingml/graphicshapecontext.cxx @@ -106,8 +106,9 @@ Reference< XFastContextHandler > GraphicShapeContext::createFastChildContext( sa // ============================================================================ // CT_GraphicalObjectFrameContext -GraphicalObjectFrameContext::GraphicalObjectFrameContext( ContextHandler& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr ) -: ShapeContext( rParent, pMasterShapePtr, pShapePtr ) +GraphicalObjectFrameContext::GraphicalObjectFrameContext( ContextHandler& rParent, ShapePtr pMasterShapePtr, ShapePtr pShapePtr, bool bEmbedShapesInChart ) : + ShapeContext( rParent, pMasterShapePtr, pShapePtr ), + mbEmbedShapesInChart( bEmbedShapesInChart ) { } @@ -135,7 +136,7 @@ Reference< XFastContextHandler > GraphicalObjectFrameContext::createFastChildCon else if ( sUri.equalsAscii( "http://schemas.openxmlformats.org/drawingml/2006/diagram" ) ) xRet.set( new DiagramGraphicDataContext( *this, mpShapePtr ) ); else if ( sUri.equalsAscii( "http://schemas.openxmlformats.org/drawingml/2006/chart" ) ) - xRet.set( new ChartGraphicDataContext( *this, mpShapePtr ) ); + xRet.set( new ChartGraphicDataContext( *this, mpShapePtr, mbEmbedShapesInChart ) ); else if ( sUri.compareToAscii( "http://schemas.openxmlformats.org/drawingml/2006/table" ) == 0 ) xRet.set( new table::TableContext( *this, mpShapePtr ) ); else @@ -349,22 +350,24 @@ Reference< XFastContextHandler > DiagramGraphicDataContext::createFastChildConte class CreateChartCallback : public CreateShapeCallback { public: - explicit CreateChartCallback( XmlFilterBase& rFilter, const OUString& rFragmentPath ); - virtual void onXShapeCreated( const Reference< drawing::XShape >& rxShape ) const; + explicit CreateChartCallback( XmlFilterBase& rFilter, const OUString& rFragmentPath, bool bEmbedShapes ); + virtual void onXShapeCreated( const Reference< drawing::XShape >& rxShape, const Reference< drawing::XShapes >& rxShapes ) const; private: OUString maFragmentPath; + bool mbEmbedShapes; }; // ---------------------------------------------------------------------------- -CreateChartCallback::CreateChartCallback( XmlFilterBase& rFilter, const OUString& rFragmentPath ) : +CreateChartCallback::CreateChartCallback( XmlFilterBase& rFilter, const OUString& rFragmentPath, bool bEmbedShapes ) : CreateShapeCallback( rFilter ), - maFragmentPath( rFragmentPath ) + maFragmentPath( rFragmentPath ), + mbEmbedShapes( bEmbedShapes ) { } -void CreateChartCallback::onXShapeCreated( const Reference< drawing::XShape >& rxShape ) const +void CreateChartCallback::onXShapeCreated( const Reference< drawing::XShape >& rxShape, const Reference< drawing::XShapes >& rxShapes ) const { OSL_ENSURE( maFragmentPath.getLength() > 0, "CreateChartCallback::onXShapeCreated - missing chart fragment" ); if( maFragmentPath.getLength() > 0 ) try @@ -376,14 +379,17 @@ void CreateChartCallback::onXShapeCreated( const Reference< drawing::XShape >& r // get the XModel interface of the embedded object from the OLE shape Reference< frame::XModel > xDocModel; aShapeProp.getProperty( xDocModel, PROP_Model ); + Reference< chart2::XChartDocument > xChartDoc( xDocModel, UNO_QUERY_THROW ); // load the chart data from the XML fragment chart::ChartSpaceModel aModel; mrFilter.importFragment( new chart::ChartSpaceFragment( mrFilter, maFragmentPath, aModel ) ); // convert imported chart model to chart document - Reference< chart2::XChartDocument > xChartDoc( xDocModel, UNO_QUERY_THROW ); - mrFilter.getChartConverter().convertFromModel( mrFilter, aModel, xChartDoc ); + Reference< drawing::XShapes > xExternalPage; + if( !mbEmbedShapes ) + xExternalPage = rxShapes; + mrFilter.getChartConverter().convertFromModel( mrFilter, aModel, xChartDoc, xExternalPage, rxShape->getPosition(), rxShape->getSize() ); } catch( Exception& ) { @@ -392,8 +398,9 @@ void CreateChartCallback::onXShapeCreated( const Reference< drawing::XShape >& r // ============================================================================ -ChartGraphicDataContext::ChartGraphicDataContext( ContextHandler& rParent, const ShapePtr& rxShape ) : - ShapeContext( rParent, ShapePtr(), rxShape ) +ChartGraphicDataContext::ChartGraphicDataContext( ContextHandler& rParent, const ShapePtr& rxShape, bool bEmbedShapes ) : + ShapeContext( rParent, ShapePtr(), rxShape ), + mbEmbedShapes( bEmbedShapes ) { rxShape->setServiceName( "com.sun.star.drawing.OLE2Shape" ); } @@ -405,7 +412,7 @@ Reference< XFastContextHandler > ChartGraphicDataContext::createFastChildContext { AttributeList aAttribs( rxAttribs ); OUString aFragmentPath = getFragmentPathFromRelId( aAttribs.getString( R_TOKEN( id ), OUString() ) ); - CreateShapeCallbackRef xCallback( new CreateChartCallback( getFilter(), aFragmentPath ) ); + CreateShapeCallbackRef xCallback( new CreateChartCallback( getFilter(), aFragmentPath, mbEmbedShapes ) ); mpShapePtr->setCreateShapeCallback( xCallback ); } return 0; diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index 8bbfc820fca1..cab64f11c166 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -76,7 +76,7 @@ OUString CreateShapeCallback::onCreateXShape( const OUString& rServiceName, cons return rServiceName; } -void CreateShapeCallback::onXShapeCreated( const Reference< XShape >& ) const +void CreateShapeCallback::onXShapeCreated( const Reference< XShape >&, const Reference< XShapes >& ) const { } @@ -135,7 +135,7 @@ const ShapeStyleRef* Shape::getShapeStyleRef( sal_Int32 nRefType ) const void Shape::addShape( const ::oox::core::XmlFilterBase& rFilterBase, - const ThemePtr& rxTheme, + const Theme* pTheme, const Reference< XShapes >& rxShapes, const awt::Rectangle* pShapeRect, ShapeIdMap* pShapeMap ) @@ -145,7 +145,7 @@ void Shape::addShape( rtl::OUString sServiceName( msServiceName ); if( sServiceName.getLength() ) { - Reference< XShape > xShape( createAndInsert( rFilterBase, sServiceName, rxTheme, rxShapes, pShapeRect, sal_False ) ); + Reference< XShape > xShape( createAndInsert( rFilterBase, sServiceName, pTheme, rxShapes, pShapeRect, sal_False ) ); if( pShapeMap && msId.getLength() ) { @@ -155,7 +155,7 @@ void Shape::addShape( // if this is a group shape, we have to add also each child shape Reference< XShapes > xShapes( xShape, UNO_QUERY ); if ( xShapes.is() ) - addChildren( rFilterBase, *this, rxTheme, xShapes, pShapeRect ? *pShapeRect : awt::Rectangle( maPosition.X, maPosition.Y, maSize.Width, maSize.Height ), pShapeMap ); + addChildren( rFilterBase, *this, pTheme, xShapes, pShapeRect ? *pShapeRect : awt::Rectangle( maPosition.X, maPosition.Y, maSize.Width, maSize.Height ), pShapeMap ); } } catch( const Exception& ) @@ -184,7 +184,7 @@ void Shape::applyShapeReference( const Shape& rReferencedShape ) void Shape::addChildren( const ::oox::core::XmlFilterBase& rFilterBase, Shape& rMaster, - const ThemePtr& rxTheme, + const Theme* pTheme, const Reference< XShapes >& rxShapes, const awt::Rectangle& rClientRect, ShapeIdMap* pShapeMap ) @@ -235,14 +235,14 @@ void Shape::addChildren( pShapeRect = &aShapeRect; } } - (*aIter++)->addShape( rFilterBase, rxTheme, rxShapes, pShapeRect, pShapeMap ); + (*aIter++)->addShape( rFilterBase, pTheme, rxShapes, pShapeRect, pShapeMap ); } } Reference< XShape > Shape::createAndInsert( const ::oox::core::XmlFilterBase& rFilterBase, const rtl::OUString& rServiceName, - const ThemePtr& rxTheme, + const Theme* pTheme, const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, const awt::Rectangle* pShapeRect, sal_Bool bClearText ) @@ -383,23 +383,23 @@ Reference< XShape > Shape::createAndInsert( aFillProperties.moFillType = XML_noFill; sal_Int32 nFillPhClr = -1; - if( rxTheme.get() ) + if( pTheme ) { if( const ShapeStyleRef* pLineRef = getShapeStyleRef( XML_lnRef ) ) { - if( const LineProperties* pLineProps = rxTheme->getLineStyle( pLineRef->mnThemedIdx ) ) + if( const LineProperties* pLineProps = pTheme->getLineStyle( pLineRef->mnThemedIdx ) ) aLineProperties.assignUsed( *pLineProps ); nLinePhClr = pLineRef->maPhClr.getColor( rFilterBase ); } if( const ShapeStyleRef* pFillRef = getShapeStyleRef( XML_fillRef ) ) { - if( const FillProperties* pFillProps = rxTheme->getFillStyle( pFillRef->mnThemedIdx ) ) + if( const FillProperties* pFillProps = pTheme->getFillStyle( pFillRef->mnThemedIdx ) ) aFillProperties.assignUsed( *pFillProps ); nFillPhClr = pFillRef->maPhClr.getColor( rFilterBase ); } // if( const ShapeStyleRef* pEffectRef = getShapeStyleRef( XML_fillRef ) ) // { -// if( const EffectProperties* pEffectProps = rxTheme->getEffectStyle( pEffectRef->mnThemedIdx ) ) +// if( const EffectProperties* pEffectProps = pTheme->getEffectStyle( pEffectRef->mnThemedIdx ) ) // aEffectProperties.assignUsed( *pEffectProps ); // nEffectPhClr = pEffectRef->maPhClr.getColor( rFilterBase ); // } @@ -451,8 +451,8 @@ Reference< XShape > Shape::createAndInsert( TextCharacterProperties aCharStyleProperties; if( const ShapeStyleRef* pFontRef = getShapeStyleRef( XML_fontRef ) ) { - if( rxTheme.get() ) - if( const TextCharacterProperties* pCharProps = rxTheme->getFontStyle( pFontRef->mnThemedIdx ) ) + if( pTheme ) + if( const TextCharacterProperties* pCharProps = pTheme->getFontStyle( pFontRef->mnThemedIdx ) ) aCharStyleProperties.assignUsed( *pCharProps ); aCharStyleProperties.maCharColor.assignIfUsed( pFontRef->maPhClr ); } @@ -465,7 +465,7 @@ Reference< XShape > Shape::createAndInsert( // use a callback for further processing on the XShape (e.g. charts) if( mxShape.is() && mxCreateCallback.get() ) - mxCreateCallback->onXShapeCreated( mxShape ); + mxCreateCallback->onXShapeCreated( mxShape, rxShapes ); return mxShape; } diff --git a/oox/source/drawingml/shapegroupcontext.cxx b/oox/source/drawingml/shapegroupcontext.cxx index 3d93d5866886..1b90be3952ab 100644 --- a/oox/source/drawingml/shapegroupcontext.cxx +++ b/oox/source/drawingml/shapegroupcontext.cxx @@ -103,7 +103,7 @@ Reference< XFastContextHandler > ShapeGroupContext::createFastChildContext( sal_ xRet.set( new GraphicShapeContext( *this, mpGroupShapePtr, ShapePtr( new Shape( "com.sun.star.drawing.GraphicObjectShape" ) ) ) ); break; case XML_graphicFrame: // CT_GraphicalObjectFrame - xRet.set( new GraphicalObjectFrameContext( *this, mpGroupShapePtr, ShapePtr( new Shape( "com.sun.star.drawing.OLE2Shape" ) ) ) ); + xRet.set( new GraphicalObjectFrameContext( *this, mpGroupShapePtr, ShapePtr( new Shape( "com.sun.star.drawing.OLE2Shape" ) ), true ) ); break; } if( !xRet.is() ) |