diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx index 89fc12546165..e4980991795a 100644 --- a/oox/source/drawingml/diagram/diagramlayoutatoms.cxx +++ b/oox/source/drawingml/diagram/diagramlayoutatoms.cxx @@ -1146,6 +1146,28 @@ void AlgAtom::layoutShape(const ShapePtr& rShape, const std::vector& if (aCurrShape->getSubType() == XML_conn) aCurrShape->setRotation(nConnectorAngle * PER_DEGREE); } + + // Newer shapes are behind older ones by default. Reverse this if requested. + sal_Int32 nChildOrder = XML_b; + const LayoutNode* pParentLayoutNode = nullptr; + for (LayoutAtomPtr pAtom = getParent(); pAtom; pAtom = pAtom->getParent()) + { + auto pLayoutNode = dynamic_cast(pAtom.get()); + if (pLayoutNode) + { + pParentLayoutNode = pLayoutNode; + break; + } + } + if (pParentLayoutNode) + { + nChildOrder = pParentLayoutNode->getChildOrder(); + } + if (nChildOrder == XML_t) + { + std::reverse(rShape->getChildren().begin(), rShape->getChildren().end()); + } + break; } diff --git a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx index cb34f7a005f1..f36224f0f882 100644 --- a/oox/source/drawingml/diagram/diagramlayoutatoms.hxx +++ b/oox/source/drawingml/diagram/diagramlayoutatoms.hxx @@ -271,6 +271,7 @@ public: { msStyleLabel = sLabel; } void setChildOrder( sal_Int32 nOrder ) { mnChildOrder = nOrder; } + sal_Int32 getChildOrder() const { return mnChildOrder; } void setExistingShape( const ShapePtr& pShape ) { mpExistingShape = pShape; } const ShapePtr& getExistingShape() const diff --git a/oox/source/drawingml/diagram/layoutnodecontext.cxx b/oox/source/drawingml/diagram/layoutnodecontext.cxx index 80ae1d5bb6a9..93f927531cf6 100644 --- a/oox/source/drawingml/diagram/layoutnodecontext.cxx +++ b/oox/source/drawingml/diagram/layoutnodecontext.cxx @@ -198,7 +198,24 @@ LayoutNodeContext::onCreateContext( ::sal_Int32 aElement, { LayoutNodePtr pNode = std::make_shared(mpNode->getLayoutNode().getDiagram()); LayoutAtom::connect(mpNode, pNode); - pNode->setChildOrder( rAttribs.getToken( XML_chOrder, XML_b ) ); + + if (rAttribs.hasAttribute(XML_chOrder)) + { + pNode->setChildOrder(rAttribs.getToken(XML_chOrder, XML_b)); + } + else + { + for (LayoutAtomPtr pAtom = mpNode; pAtom; pAtom = pAtom->getParent()) + { + auto pLayoutNode = dynamic_cast(pAtom.get()); + if (pLayoutNode) + { + pNode->setChildOrder(pLayoutNode->getChildOrder()); + break; + } + } + } + pNode->setMoveWith( rAttribs.getString( XML_moveWith ).get() ); pNode->setStyleLabel( rAttribs.getString( XML_styleLbl ).get() ); return new LayoutNodeContext( *this, rAttribs, pNode ); diff --git a/sd/qa/unit/import-tests-smartart.cxx b/sd/qa/unit/import-tests-smartart.cxx index 6fc195ccd101..bdf320ce831f 100644 --- a/sd/qa/unit/import-tests-smartart.cxx +++ b/sd/qa/unit/import-tests-smartart.cxx @@ -1532,8 +1532,9 @@ void SdImportTestSmartArt::testLinearRule() sd::DrawDocShellRef xDocShRef = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/smartart-linear-rule.pptx"), PPTX); uno::Reference xGroup(getShapeFromPage(0, 0, xDocShRef), uno::UNO_QUERY); - // Last child, then again last child. - uno::Reference xShape = getChildShape(getChildShape(xGroup, 1), 3); + // Last child, then first child inside that. + // It is first as backgroundArrow is last, but chOrder="t" is set to reverse the order. + uno::Reference xShape = getChildShape(getChildShape(xGroup, 1), 0); // Without the accompanying fix in place, this test would have failed with: // - Expected greater than: 17500 (19867)