SmartArt: reuse existing diagram shape for root shape
it prevents creating unnecessary expanded shape hierarchy and allows
layout algorithm to know parent's size
Change-Id: Ieb991a74bd662e359f5cf479a7480893e0b13d45
Reviewed-on: https://gerrit.libreoffice.org/39410
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Thorsten Behrens <Thorsten.Behrens@CIB.de>
diff --git a/oox/source/drawingml/diagram/diagram.cxx b/oox/source/drawingml/diagram/diagram.cxx
index 467d700..533156b 100644
--- a/oox/source/drawingml/diagram/diagram.cxx
+++ b/oox/source/drawingml/diagram/diagram.cxx
@@ -317,13 +317,19 @@ void Diagram::addTo( const ShapePtr & pParentShape )
// collect data, init maps
build( );
if (pParentShape->getSize().Width == 0 || pParentShape->getSize().Height == 0)
SAL_WARN("oox.drawingml", "Diagram cannot be correctly laid out. Size: "
<< pParentShape->getSize().Width << "x" << pParentShape->getSize().Height);
pParentShape->setChildSize(pParentShape->getSize());
// create Shape hierarchy
ShapeCreationVisitor aCreationVisitor(pParentShape, *this);
if( mpLayout->getNode() )
{
// create Shape hierarchy
ShapeCreationVisitor aCreationVisitor(pParentShape, *this);
mpLayout->getNode()->setExistingShape(pParentShape);
mpLayout->getNode()->accept( aCreationVisitor );
}
pParentShape->setDiagramDoms( getDomsAsPropertyValues() );
}
diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
index 2df1af0..d5b9fcd 100644
--- a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
+++ b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx
@@ -238,10 +238,14 @@ public:
{ msStyleLabel = sLabel; }
void setChildOrder( sal_Int32 nOrder )
{ mnChildOrder = nOrder; }
void setShape( const ShapePtr& pShape )
{ mpShape = pShape; }
const ShapePtr& getShape() const
{ return mpShape; }
void setShapeTemplate( const ShapePtr& pShape )
{ mpShapeTemplate = pShape; }
void setExistingShape( const ShapePtr& pShape )
{ mpExistingShape = pShape; }
const ShapePtr& getShapeTemplate() const
{ return mpShapeTemplate; }
const ShapePtr& getExistingShape() const
{ return mpExistingShape; }
bool setupShape( const ShapePtr& rShape,
const Diagram& rDgm,
@@ -251,7 +255,8 @@ private:
VarMap mVariables;
OUString msMoveWith;
OUString msStyleLabel;
ShapePtr mpShape;
ShapePtr mpShapeTemplate;
ShapePtr mpExistingShape;
sal_Int32 mnChildOrder;
};
diff --git a/oox/source/drawingml/diagram/layoutatomvisitors.cxx b/oox/source/drawingml/diagram/layoutatomvisitors.cxx
index a0c1609..fd6e9d7 100755
--- a/oox/source/drawingml/diagram/layoutatomvisitors.cxx
+++ b/oox/source/drawingml/diagram/layoutatomvisitors.cxx
@@ -94,8 +94,13 @@ void ShapeCreationVisitor::visit(ChooseAtom& rAtom)
void ShapeCreationVisitor::visit(LayoutNode& rAtom)
{
ShapePtr pCurrParent(mpParentShape);
ShapePtr pCurrShape(rAtom.getShape());
if( pCurrShape )
ShapePtr pCurrShape(rAtom.getShapeTemplate());
if (rAtom.getExistingShape())
{
rAtom.setupShape(rAtom.getExistingShape(), mrDgm, mnCurrIdx);
}
else if( pCurrShape )
{
SAL_INFO(
"oox.drawingml",
diff --git a/oox/source/drawingml/diagram/layoutnodecontext.cxx b/oox/source/drawingml/diagram/layoutnodecontext.cxx
index d96a49b0..5d66de1 100644
--- a/oox/source/drawingml/diagram/layoutnodecontext.cxx
+++ b/oox/source/drawingml/diagram/layoutnodecontext.cxx
@@ -263,7 +263,7 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement,
pShape.reset( new Shape("com.sun.star.drawing.GroupShape") );
}
pNode->setShape( pShape );
pNode->setShapeTemplate( pShape );
return new ShapeContext( *this, ShapePtr(), pShape );
}
else