sw/qa/extras/ooxmlexport/data/testWPGZOrder.docx |binary
 sw/qa/extras/ooxmlexport/ooxmlexport10.cxx       |    4 -
 sw/qa/extras/ooxmlexport/ooxmlexport17.cxx       |   49 +++++++++++++++++++++++
 sw/source/core/doc/textboxhelper.cxx             |   15 ++++---
 sw/source/core/draw/dcontact.cxx                 |    8 +++
 5 files changed, 68 insertions(+), 8 deletions(-)

New commits:
commit 0cb370d02bebf6a9d65b5852815e2c617b33a89a
Author:     Attila Bakos (NISZ) <bakos.attilakar...@nisz.hu>
AuthorDate: Tue Jan 11 12:09:46 2022 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Jan 17 09:26:33 2023 +0000

    Related tdf#66039 DOCX import: fix Z-order of group shapes
    
    A missing function resulted covered textboxes which weren't
    visible in group shapes.
    
    Follow-up to 121cbc250b36290f0f8c7265fea57256dad69553
    "tdf#66039 DOCX: import textboxes (with tables, images etc.)
    in group shapes".
    
    Change-Id: I08eb1c1cf4a4f4769af8812500b9cf9778b01e9c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128279
    Tested-by: László Németh <nem...@numbertext.org>
    Reviewed-by: László Németh <nem...@numbertext.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/143372
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/ooxmlexport/data/testWPGZOrder.docx 
b/sw/qa/extras/ooxmlexport/data/testWPGZOrder.docx
new file mode 100644
index 000000000000..664f47a0b623
Binary files /dev/null and b/sw/qa/extras/ooxmlexport/data/testWPGZOrder.docx 
differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
index e23a42bf4983..3dafae143432 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -116,9 +116,9 @@ protected:
 
 DECLARE_OOXMLEXPORT_TEST(testWPGtextboxes, "testWPGtextboxes.docx")
 {
-    CPPUNIT_ASSERT_EQUAL(1, getShapes());
+    CPPUNIT_ASSERT_EQUAL(2, getShapes());
 
-    auto MyShape = getShape(1);
+    auto MyShape = getShape(2);
     CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.drawing.GroupShape"), 
MyShape->getShapeType());
 
     uno::Reference<drawing::XShapes> xGroup(MyShape, uno::UNO_QUERY_THROW);
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 395f0dbf03fc..42b7a0891877 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -20,6 +20,7 @@
 #include <com/sun/star/frame/XStorable.hpp>
 #include <com/sun/star/awt/FontSlant.hpp>
 #include <com/sun/star/awt/FontWeight.hpp>
+#include <com/sun/star/drawing/XShapes.hpp>
 
 
 #include <comphelper/configuration.hxx>
@@ -28,6 +29,7 @@
 #include <officecfg/Office/Common.hxx>
 #include <comphelper/propertyvalue.hxx>
 
+#include <queue>
 #include <swmodeltestbase.hxx>
 #include <unotxdoc.hxx>
 
@@ -390,6 +392,53 @@ DECLARE_OOXMLEXPORT_TEST(testTdf126287, "tdf126287.docx")
     CPPUNIT_ASSERT_EQUAL(2, getPages());
 }
 
+DECLARE_OOXMLEXPORT_TEST(TestWPGZOrder, "testWPGZOrder.docx")
+{
+    // Check if the load failed.
+    CPPUNIT_ASSERT(mxComponent);
+
+    // Get the WPG
+    uno::Reference<drawing::XShapes> xGroup(getShape(1), uno::UNO_QUERY_THROW);
+    uno::Reference<beans::XPropertySet> xGroupProperties(xGroup, 
uno::UNO_QUERY_THROW);
+
+    // Initialize a queue for subgroups
+    std::queue<uno::Reference<drawing::XShapes>> xGroupList;
+    xGroupList.push(xGroup);
+
+    // Every textbox shall be visible.
+    while (xGroupList.size())
+    {
+        // Get the first group
+        xGroup = xGroupList.front();
+        xGroupList.pop();
+        for (sal_Int32 i = 0; i < xGroup->getCount(); ++i)
+        {
+            // Get the child shape
+            uno::Reference<beans::XPropertySet> 
xChildShapeProperties(xGroup->getByIndex(i),
+                uno::UNO_QUERY_THROW);
+            // Check for textbox
+            if 
(!xChildShapeProperties->getPropertyValue("TextBox").get<bool>())
+            {
+                // Is this a Group Shape? Put it into the queue.
+                uno::Reference<drawing::XShapes> 
xInnerGroup(xGroup->getByIndex(i), uno::UNO_QUERY);
+                if (xInnerGroup)
+                    xGroupList.push(xInnerGroup);
+                continue;
+            }
+
+            // Get the textbox properties
+            uno::Reference<beans::XPropertySet> xTextBoxFrameProperties(
+                xChildShapeProperties->getPropertyValue("TextBoxContent"), 
uno::UNO_QUERY_THROW);
+
+            // Assert that the textbox ZOrder greater than the groupshape
+            
CPPUNIT_ASSERT_GREATER(xGroupProperties->getPropertyValue("ZOrder").get<long>(),
+                
xTextBoxFrameProperties->getPropertyValue("ZOrder").get<long>());
+            // Before the fix, this failed because that was less, and the 
textboxes were covered.
+        }
+
+    }
+}
+
 DECLARE_OOXMLEXPORT_TEST(testTdf123642_BookmarkAtDocEnd, "tdf123642.docx")
 {
     // get bookmark interface
diff --git a/sw/source/core/doc/textboxhelper.cxx 
b/sw/source/core/doc/textboxhelper.cxx
index bcdf25002305..bb1d6f331dbc 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -1432,15 +1432,20 @@ bool 
SwTextBoxHelper::DoTextBoxZOrderCorrection(SwFrameFormat* pShape, const Sdr
 {
     // TODO: do this with group shape textboxes.
     SdrObject* pShpObj = nullptr;
-    //if (pObj)
-    //    pShpObj = pObj;
-    //else
+
     pShpObj = pShape->FindRealSdrObject();
 
     if (pShpObj)
     {
-        if (SdrObject* pFrmObj
-            = getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT, 
pObj)->FindRealSdrObject())
+        auto pTextBox = getOtherTextBoxFormat(pShape, RES_DRAWFRMFMT, pObj);
+        SdrObject* pFrmObj = pTextBox->FindRealSdrObject();
+        if (!pFrmObj)
+        {
+            // During doc-loading there is no ready SdrObj for z-ordering, so 
create one here and cache it.
+            pFrmObj
+                = 
SwXTextFrame::GetOrCreateSdrObject(*dynamic_cast<SwFlyFrameFormat*>(pTextBox));
+        }
+        if (pFrmObj)
         {
             // Get the draw model from the doc
             SwDrawModel* pDrawModel
diff --git a/sw/source/core/draw/dcontact.cxx b/sw/source/core/draw/dcontact.cxx
index 35085e42740f..63011f0171a8 100644
--- a/sw/source/core/draw/dcontact.cxx
+++ b/sw/source/core/draw/dcontact.cxx
@@ -1369,7 +1369,13 @@ void SwDrawContact::Changed_( const SdrObject& rObj,
                     aSet.Put(aSyncSet);
                     aSet.Put(pSdrObj->GetMergedItem(RES_FRM_SIZE));
                     SwTextBoxHelper::syncFlyFrameAttr(*GetFormat(), aSet, 
pSdrObj);
-                    SwTextBoxHelper::changeAnchor(GetFormat(), pSdrObj);
+
+                    SwTextBoxHelper::synchronizeGroupTextBoxProperty(
+                        &SwTextBoxHelper::changeAnchor, GetFormat(),
+                        GetFormat()->FindRealSdrObject());
+                    SwTextBoxHelper::synchronizeGroupTextBoxProperty(
+                        &SwTextBoxHelper::syncTextBoxSize, GetFormat(),
+                        GetFormat()->FindRealSdrObject());
                 }
                 else
                     SwTextBoxHelper::syncFlyFrameAttr(*GetFormat(), aSyncSet, 
GetFormat()->FindRealSdrObject());

Reply via email to