diff options
author | Daniel Rentz <dr@openoffice.org> | 2009-07-21 08:45:37 +0000 |
---|---|---|
committer | Daniel Rentz <dr@openoffice.org> | 2009-07-21 08:45:37 +0000 |
commit | 666ab44fc05a32d5d60783b8986fa3c72bb8bb19 (patch) | |
tree | 3bae923318ab89e382e15710ecab386327759fd5 /oox/source/drawingml/chart | |
parent | e86f49f5885249ea160cdd16f9866d18f92e4401 (diff) |
#i12587# support chart sheets with embedded shapes
Diffstat (limited to 'oox/source/drawingml/chart')
-rw-r--r-- | oox/source/drawingml/chart/chartconverter.cxx | 11 | ||||
-rw-r--r-- | oox/source/drawingml/chart/chartdrawingfragment.cxx | 64 | ||||
-rw-r--r-- | oox/source/drawingml/chart/chartspaceconverter.cxx | 32 | ||||
-rw-r--r-- | oox/source/drawingml/chart/converterbase.cxx | 20 |
4 files changed, 68 insertions, 59 deletions
diff --git a/oox/source/drawingml/chart/chartconverter.cxx b/oox/source/drawingml/chart/chartconverter.cxx index 6358e6b899e6..53c301dab7f8 100644 --- a/oox/source/drawingml/chart/chartconverter.cxx +++ b/oox/source/drawingml/chart/chartconverter.cxx @@ -37,7 +37,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; @@ -58,14 +60,15 @@ ChartConverter::~ChartConverter() } void ChartConverter::convertFromModel( XmlFilterBase& rFilter, - ChartSpaceModel& rModel, const Reference< XChartDocument >& rxChartDoc, const Size& rChartSize ) + 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, rChartSize, 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 index ea034fd9418e..eb584c6aa9d9 100644 --- a/oox/source/drawingml/chart/chartdrawingfragment.cxx +++ b/oox/source/drawingml/chart/chartdrawingfragment.cxx @@ -38,6 +38,7 @@ 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; @@ -51,32 +52,6 @@ namespace chart { // ============================================================================ -AnchorPosModel::AnchorPosModel() : - mfX( -1.0 ), - mfY( -1.0 ) -{ -} - -bool AnchorPosModel::isValid() const -{ - return (0.0 <= mfX) && (mfX <= 1.0) && (0.0 <= mfY) && (mfY <= 1.0); -} - -// ---------------------------------------------------------------------------- - -AnchorSizeModel::AnchorSizeModel() : - mnWidth( -1 ), - mnHeight( -1 ) -{ -} - -bool AnchorSizeModel::isValid() const -{ - return (mnWidth >= 0) && (mnHeight >= 0); -} - -// ============================================================================ - ShapeAnchor::ShapeAnchor( bool bRelSize ) : mbRelSize( bRelSize ) { @@ -85,8 +60,8 @@ ShapeAnchor::ShapeAnchor( bool bRelSize ) : void ShapeAnchor::importExt( const AttributeList& rAttribs ) { OSL_ENSURE( !mbRelSize, "ShapeAnchor::importExt - unexpected 'cdr:ext' element" ); - maSize.mnWidth = rAttribs.getInteger64( XML_cx, 0 ); - maSize.mnHeight = rAttribs.getInteger64( XML_cy, 0 ); + maSize.Width = rAttribs.getInteger64( XML_cx, 0 ); + maSize.Height = rAttribs.getInteger64( XML_cy, 0 ); } void ShapeAnchor::setPos( sal_Int32 nElement, sal_Int32 nParentContext, const OUString& rValue ) @@ -112,7 +87,7 @@ void ShapeAnchor::setPos( sal_Int32 nElement, sal_Int32 nParentContext, const OU } } -Rectangle ShapeAnchor::calcEmuLocation( const AnchorSizeModel& rEmuChartSize ) const +Rectangle ShapeAnchor::calcEmuLocation( const EmuRectangle& rEmuChartRect ) const { Rectangle aLoc( -1, -1, -1, -1 ); @@ -121,19 +96,19 @@ Rectangle ShapeAnchor::calcEmuLocation( const AnchorSizeModel& rEmuChartSize ) c if( maFrom.isValid() && (mbRelSize ? maTo.isValid() : maSize.isValid()) ) { // calculate shape position - aLoc.X = getLimitedValue< sal_Int32, double >( maFrom.mfX * rEmuChartSize.mnWidth, 0, SAL_MAX_INT32 ); - aLoc.Y = getLimitedValue< sal_Int32, double >( maFrom.mfY * rEmuChartSize.mnHeight, 0, SAL_MAX_INT32 ); + 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 * rEmuChartSize.mnWidth, 0, SAL_MAX_INT32 ) - aLoc.X; + 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 * rEmuChartSize.mnHeight, 0, SAL_MAX_INT32 ) - aLoc.Y; + aLoc.Height = getLimitedValue< sal_Int32, double >( maTo.mfY * rEmuChartRect.Height, 0, SAL_MAX_INT32 ) - aLoc.Y; if( aLoc.Height < 0 ) { aLoc.Y += aLoc.Height; @@ -142,8 +117,8 @@ Rectangle ShapeAnchor::calcEmuLocation( const AnchorSizeModel& rEmuChartSize ) c } else { - aLoc.Width = getLimitedValue< sal_Int32, sal_Int64 >( maSize.mnWidth, 0, SAL_MAX_INT32 ); - aLoc.Height = getLimitedValue< sal_Int32, sal_Int64 >( maSize.mnHeight, 0, SAL_MAX_INT32 ); + 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 ); } } @@ -152,12 +127,16 @@ Rectangle ShapeAnchor::calcEmuLocation( const AnchorSizeModel& rEmuChartSize ) c // ============================================================================ ChartDrawingFragment::ChartDrawingFragment( XmlFilterBase& rFilter, - const OUString& rFragmentPath, const Reference< XShapes >& rxDrawPage, const Size& rChartSize ) : + const OUString& rFragmentPath, const Reference< XShapes >& rxDrawPage, + const Size& rChartSize, const Point& rShapesOffset, bool bOleSupport ) : FragmentHandler2( rFilter, rFragmentPath ), - mxDrawPage( rxDrawPage ) + mxDrawPage( rxDrawPage ), + mbOleSupport( bOleSupport ) { - maEmuChartSize.mnWidth = static_cast< sal_Int64 >( rChartSize.Width ) * 360; - maEmuChartSize.mnHeight = static_cast< sal_Int64 >( rChartSize.Height ) * 360; + 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() @@ -198,8 +177,11 @@ ContextHandlerRef ChartDrawingFragment::onCreateContext( sal_Int32 nElement, con 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 ); + return new GraphicalObjectFrameContext( *this, ShapePtr(), mxShape, true ); + break; case CDR_TOKEN( grpSp ): mxShape.reset( new Shape( "com.sun.star.drawing.GroupShape" ) ); return new ShapeGroupContext( *this, ShapePtr(), mxShape ); @@ -240,7 +222,7 @@ void ChartDrawingFragment::onEndElement( const OUString& rChars ) case CDR_TOKEN( relSizeAnchor ): if( mxDrawPage.is() && mxShape.get() && mxAnchor.get() ) { - Rectangle aLoc = mxAnchor->calcEmuLocation( maEmuChartSize ); + 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 ); } diff --git a/oox/source/drawingml/chart/chartspaceconverter.cxx b/oox/source/drawingml/chart/chartspaceconverter.cxx index ccd19a2e73e3..100a503674f1 100644 --- a/oox/source/drawingml/chart/chartspaceconverter.cxx +++ b/oox/source/drawingml/chart/chartspaceconverter.cxx @@ -45,6 +45,7 @@ #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; @@ -71,7 +72,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) */ @@ -163,9 +164,32 @@ void ChartSpaceConverter::convertFromModel() // embedded drawing shapes if( mrModel.maDrawingPath.getLength() > 0 ) try { - Reference< XDrawPageSupplier > xDrawPageSupp( getChartDocument(), UNO_QUERY_THROW ); - Reference< XShapes > xShapes( xDrawPageSupp->getDrawPage(), UNO_QUERY_THROW ); - getFilter().importFragment( new ChartDrawingFragment( getFilter(), mrModel.maDrawingPath, xShapes, getChartSize() ) ); + /* 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& ) { diff --git a/oox/source/drawingml/chart/converterbase.cxx b/oox/source/drawingml/chart/converterbase.cxx index 950c351278ee..82297611fe2b 100644 --- a/oox/source/drawingml/chart/converterbase.cxx +++ b/oox/source/drawingml/chart/converterbase.cxx @@ -56,18 +56,18 @@ namespace chart { struct ConverterData { + ObjectFormatter maFormatter; XmlFilterBase& mrFilter; ChartConverter& mrConverter; Reference< XChartDocument > mxDoc; Size maSize; - ObjectFormatter maFormatter; explicit ConverterData( XmlFilterBase& rFilter, ChartConverter& rChartConverter, + const ChartSpaceModel& rChartModel, const Reference< XChartDocument >& rxChartDoc, - const Size& rChartSize, - const ChartSpaceModel& rChartSpace ); + const Size& rChartSize ); ~ConverterData(); }; @@ -76,14 +76,14 @@ struct ConverterData ConverterData::ConverterData( XmlFilterBase& rFilter, ChartConverter& rChartConverter, + const ChartSpaceModel& rChartModel, const Reference< XChartDocument >& rxChartDoc, - const Size& rChartSize, - const ChartSpaceModel& rChartModel ) : + const Size& rChartSize ) : + maFormatter( rFilter, rxChartDoc, rChartModel ), mrFilter( rFilter ), mrConverter( rChartConverter ), mxDoc( rxChartDoc ), - maSize( rChartSize ), - maFormatter( rFilter, rxChartDoc, rChartModel ) + maSize( rChartSize ) { OSL_ENSURE( mxDoc.is(), "ConverterData::ConverterData - missing chart document" ); // lock the model to suppress internal updates during conversion @@ -115,10 +115,10 @@ ConverterData::~ConverterData() ConverterRoot::ConverterRoot( XmlFilterBase& rFilter, ChartConverter& rChartConverter, + const ChartSpaceModel& rChartModel, const Reference< XChartDocument >& rxChartDoc, - const Size& rChartSize, - const ChartSpaceModel& rChartModel ) : - mxData( new ConverterData( rFilter, rChartConverter, rxChartDoc, rChartSize, rChartModel ) ) + const Size& rChartSize ) : + mxData( new ConverterData( rFilter, rChartConverter, rChartModel, rxChartDoc, rChartSize ) ) { } |