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 3b0a0e70cb67fc2e1f9999d2e8cbb9cfcd8c670e
Author:     Attila Bakos (NISZ) <bakos.attilakar...@nisz.hu>
AuthorDate: Tue Jan 11 12:09:46 2022 +0100
Commit:     László Németh <nem...@numbertext.org>
CommitDate: Wed Feb 2 14:20:55 2022 +0100

    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>

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 70d39cdbcde8..29996d119812 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport10.cxx
@@ -95,9 +95,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 76b768155677..6feb92b15149 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -8,10 +8,12 @@
  */
 
 #include <com/sun/star/text/XBookmarksSupplier.hpp>
+#include <com/sun/star/drawing/XShapes.hpp>
 
 #include <comphelper/scopeguard.hxx>
 #include <officecfg/Office/Common.hxx>
 
+#include <queue>
 #include <swmodeltestbase.hxx>
 
 constexpr OUStringLiteral DATA_DIRECTORY = u"/sw/qa/extras/ooxmlexport/data/";
@@ -103,6 +105,53 @@ CPPUNIT_TEST_FIXTURE(Test, testDontAddNewStyles)
     assertXPath(pXmlDoc, "/w:styles/w:style[@w:styleId='Caption']", 0);
 }
 
+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 65f6e2e03863..a2ca9175a957 100644
--- a/sw/source/core/doc/textboxhelper.cxx
+++ b/sw/source/core/doc/textboxhelper.cxx
@@ -1473,15 +1473,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 f4f463294087..d8a9ef322924 100644
--- a/sw/source/core/draw/dcontact.cxx
+++ b/sw/source/core/draw/dcontact.cxx
@@ -1368,7 +1368,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