From fa0e9cf0d13b9b426dd9a3636a0866d0fb220c51 Mon Sep 17 00:00:00 2001 From: Radek Doulik Date: Mon, 2 Jul 2012 18:24:04 +0200 Subject: use master's shape position/size for layout shapes when needed (n#760997) Change-Id: I2a9d4f6b134817bda84645df3ab6fa217186e1d2 --- oox/inc/oox/ppt/pptshape.hxx | 6 +++--- oox/source/ppt/pptshape.cxx | 43 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 39 insertions(+), 10 deletions(-) (limited to 'oox') diff --git a/oox/inc/oox/ppt/pptshape.hxx b/oox/inc/oox/ppt/pptshape.hxx index e171f24fd6a8..d0b31a632330 100644 --- a/oox/inc/oox/ppt/pptshape.hxx +++ b/oox/inc/oox/ppt/pptshape.hxx @@ -50,7 +50,7 @@ public: // addShape is creating and inserting the corresponding XShape. void addShape( oox::core::XmlFilterBase& rFilterBase, - const SlidePersist& rPersist, + SlidePersist& rPersist, const oox::drawingml::Theme* pTheme, const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& rxShapes, basegfx::B2DHomMatrix& aTransformation, @@ -65,8 +65,8 @@ public: void setReferenced( sal_Bool bReferenced ){ mbReferenced = bReferenced; }; void setPlaceholder( oox::drawingml::ShapePtr pPlaceholder ) { mpPlaceholder = pPlaceholder; } - static oox::drawingml::ShapePtr findPlaceholder( const sal_Int32 nMasterPlaceholder, std::vector< oox::drawingml::ShapePtr >& rShapes ); - static oox::drawingml::ShapePtr findPlaceholderByIndex( const sal_Int32 nIdx, std::vector< oox::drawingml::ShapePtr >& rShapes ); + static oox::drawingml::ShapePtr findPlaceholder( const sal_Int32 nMasterPlaceholder, std::vector< oox::drawingml::ShapePtr >& rShapes, bool bMasterOnly = false ); + static oox::drawingml::ShapePtr findPlaceholderByIndex( const sal_Int32 nIdx, std::vector< oox::drawingml::ShapePtr >& rShapes, bool bMasterOnly = false ); static oox::drawingml::TextListStylePtr getSubTypeTextListStyle( const SlidePersist& rSlidePersist, sal_Int32 nSubType ); diff --git a/oox/source/ppt/pptshape.cxx b/oox/source/ppt/pptshape.cxx index 2f2e330de539..1456fbb8ab4c 100644 --- a/oox/source/ppt/pptshape.cxx +++ b/oox/source/ppt/pptshape.cxx @@ -119,7 +119,7 @@ oox::drawingml::TextListStylePtr PPTShape::getSubTypeTextListStyle( const SlideP void PPTShape::addShape( oox::core::XmlFilterBase& rFilterBase, - const SlidePersist& rSlidePersist, + SlidePersist& rSlidePersist, const oox::drawingml::Theme* pTheme, const Reference< XShapes >& rxShapes, basegfx::B2DHomMatrix& aTransformation, @@ -261,6 +261,31 @@ void PPTShape::addShape( OSL_TRACE("shape service: %s", rtl::OUStringToOString(sServiceName, RTL_TEXTENCODING_UTF8 ).getStr()); + if( mnSubType && getSubTypeIndex().has() && meShapeLocation == Layout ) { + oox::drawingml::ShapePtr pPlaceholder = PPTShape::findPlaceholderByIndex( getSubTypeIndex().get(), rSlidePersist.getShapes()->getChildren(), true ); + if (!pPlaceholder.get()) + pPlaceholder = PPTShape::findPlaceholder( mnSubType, rSlidePersist.getShapes()->getChildren(), true ); + + if (pPlaceholder.get()) { + if( maSize.Width == 0 || maSize.Height == 0 ) { + awt::Size aSize = maSize; + if( maSize.Width == 0 ) + aSize.Width = pPlaceholder->getSize().Width; + if( maSize.Height == 0 ) + aSize.Height = pPlaceholder->getSize().Height; + setSize( aSize ); + if ( maPosition.X == 0 || maPosition.Y == 0 ) { + awt::Point aPosition = maPosition; + if( maPosition.X == 0 ) + aPosition.X = pPlaceholder->getPosition().X; + if( maPosition.Y == 0 ) + aPosition.Y = pPlaceholder->getPosition().Y; + setPosition( aPosition ); + } + } + } + } + // use placeholder index if possible if( mnSubType && getSubTypeIndex().has() && rSlidePersist.getMasterPersist().get() ) { oox::drawingml::ShapePtr pPlaceholder = PPTShape::findPlaceholderByIndex( getSubTypeIndex().get(), rSlidePersist.getMasterPersist()->getShapes()->getChildren() ); @@ -379,19 +404,21 @@ void PPTShape::applyShapeReference( const oox::drawingml::Shape& rReferencedShap Shape::applyShapeReference( rReferencedShape, bUseText ); } -oox::drawingml::ShapePtr PPTShape::findPlaceholder( const sal_Int32 nMasterPlaceholder, std::vector< oox::drawingml::ShapePtr >& rShapes ) +oox::drawingml::ShapePtr PPTShape::findPlaceholder( const sal_Int32 nMasterPlaceholder, std::vector< oox::drawingml::ShapePtr >& rShapes, bool bMasterOnly ) { oox::drawingml::ShapePtr aShapePtr; std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() ); while( aRevIter != rShapes.rend() ) { - if ( (*aRevIter)->getSubType() == nMasterPlaceholder ) + if ( (*aRevIter)->getSubType() == nMasterPlaceholder && + ( !bMasterOnly || + ( dynamic_cast< PPTShape* >( (*aRevIter).get() ) && dynamic_cast< PPTShape* >( (*aRevIter).get() )->getShapeLocation() == Master ) ) ) { aShapePtr = *aRevIter; break; } std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren(); - aShapePtr = findPlaceholder( nMasterPlaceholder, rChildren ); + aShapePtr = findPlaceholder( nMasterPlaceholder, rChildren, bMasterOnly ); if ( aShapePtr.get() ) break; ++aRevIter; @@ -399,20 +426,22 @@ oox::drawingml::ShapePtr PPTShape::findPlaceholder( const sal_Int32 nMasterPlace return aShapePtr; } -oox::drawingml::ShapePtr PPTShape::findPlaceholderByIndex( const sal_Int32 nIdx, std::vector< oox::drawingml::ShapePtr >& rShapes ) +oox::drawingml::ShapePtr PPTShape::findPlaceholderByIndex( const sal_Int32 nIdx, std::vector< oox::drawingml::ShapePtr >& rShapes, bool bMasterOnly ) { oox::drawingml::ShapePtr aShapePtr; std::vector< oox::drawingml::ShapePtr >::reverse_iterator aRevIter( rShapes.rbegin() ); while( aRevIter != rShapes.rend() ) { - if ( (*aRevIter)->getSubTypeIndex().has() && (*aRevIter)->getSubTypeIndex().get() == nIdx ) + if ( (*aRevIter)->getSubTypeIndex().has() && (*aRevIter)->getSubTypeIndex().get() == nIdx && + ( !bMasterOnly || + ( dynamic_cast< PPTShape* >( (*aRevIter).get() ) && dynamic_cast< PPTShape* >( (*aRevIter).get() )->getShapeLocation() == Master ) ) ) { aShapePtr = *aRevIter; break; } std::vector< oox::drawingml::ShapePtr >& rChildren = (*aRevIter)->getChildren(); - aShapePtr = findPlaceholderByIndex( nIdx, rChildren ); + aShapePtr = findPlaceholderByIndex( nIdx, rChildren, bMasterOnly ); if ( aShapePtr.get() ) break; ++aRevIter; -- cgit