[Libreoffice-commits] core.git: sw/qa sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Jan 29 20:01:24 UTC 2019


 sw/qa/extras/uiwriter/uiwriter2.cxx           |  101 +++++++++++++++-----------
 sw/source/uibase/docvw/UnfloatTableButton.cxx |   23 +++++
 2 files changed, 83 insertions(+), 41 deletions(-)

New commits:
commit 70c29e50af8e16b864d1e5e5a74c30a1de8250de
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Tue Jan 29 19:05:56 2019 +0100
Commit:     Tamás Zolnai <tamas.zolnai at collabora.com>
CommitDate: Tue Jan 29 21:01:00 2019 +0100

    Unfloat: Fix some issues with unfloat operation
    
    - Use the correct method to remove the frame, so DOC
    export will work correctly.
    - Remove pagedesc attribute of the first text node if
    the table is moved before it to avoid to generate a page
    break.
    
    Change-Id: I02802c4d25c947ec140b846c594848117815f1ce
    Reviewed-on: https://gerrit.libreoffice.org/67093
    Tested-by: Jenkins
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>

diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx
index 93334ddc5027..6f56022e92ae 100644
--- a/sw/qa/extras/uiwriter/uiwriter2.cxx
+++ b/sw/qa/extras/uiwriter/uiwriter2.cxx
@@ -648,49 +648,70 @@ void SwUiWriterTest2::testUnfloatButtonReadOnlyMode()
 
 void SwUiWriterTest2::testUnfloating()
 {
-    // Test what happens when pushing the unfloat button
-    load(FLOATING_TABLE_DATA_DIRECTORY, "unfloatable_floating_table.odt");
-    SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
-    CPPUNIT_ASSERT(pTextDoc);
-    SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
-    CPPUNIT_ASSERT(pWrtShell);
-
-    SwFlyFrame* pFlyFrame;
+    // Test unfloating with tables imported from different file formats
+    const std::vector<OUString> aTestFiles = {
+        "unfloatable_floating_table.odt",
+        "unfloatable_floating_table.docx",
+        "unfloatable_floating_table.doc",
+    };
 
-    // Before unfloating we have only one page with a fly frame
+    for (const OUString& aTestFile : aTestFiles)
     {
-        CPPUNIT_ASSERT_EQUAL(SwFrameType::Page, pWrtShell->GetLayout()->GetLower()->GetType());
-        CPPUNIT_ASSERT(!pWrtShell->GetLayout()->GetLower()->GetNext());
-        CPPUNIT_ASSERT_EQUAL(SwFrameType::Txt,
-                             pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetType());
-        const SwSortedObjs* pAnchored
-            = pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs();
-        CPPUNIT_ASSERT(pAnchored);
-        CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pAnchored->size());
-        SwAnchoredObject* pAnchoredObj = (*pAnchored)[0];
-        pFlyFrame = dynamic_cast<SwFlyFrame*>(pAnchoredObj);
-        CPPUNIT_ASSERT(pFlyFrame);
-    }
+        OString sTestFileName = OUStringToOString(aTestFile, RTL_TEXTENCODING_UTF8);
+        OString sFailureMessage = OString("Failure in the test file: ") + sTestFileName;
 
-    // Select the floating table
-    SdrObject* pObj = pFlyFrame->GetFormat()->FindRealSdrObject();
-    CPPUNIT_ASSERT(pObj);
-    pWrtShell->SelectObj(Point(), 0, pObj);
-    CPPUNIT_ASSERT(pFlyFrame->IsShowUnfloatButton(pWrtShell));
-
-    // Push the unfloat button
-    pFlyFrame->ActiveUnfloatButton(pWrtShell);
-
-    // After unfloating we have two pages with one table frame on each page
-    CPPUNIT_ASSERT(pWrtShell->GetLayout()->GetLower()->GetNext());
-    CPPUNIT_ASSERT_EQUAL(SwFrameType::Page,
-                         pWrtShell->GetLayout()->GetLower()->GetNext()->GetType());
-    CPPUNIT_ASSERT(!pWrtShell->GetLayout()->GetLower()->GetNext()->GetNext());
-    CPPUNIT_ASSERT_EQUAL(SwFrameType::Tab,
-                         pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetType());
-    CPPUNIT_ASSERT_EQUAL(
-        SwFrameType::Tab,
-        pWrtShell->GetLayout()->GetLower()->GetNext()->GetLower()->GetLower()->GetType());
+        // Test what happens when pushing the unfloat button
+        load(FLOATING_TABLE_DATA_DIRECTORY, "unfloatable_floating_table.docx");
+        SwXTextDocument* pTextDoc = dynamic_cast<SwXTextDocument*>(mxComponent.get());
+        CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pTextDoc);
+        SwWrtShell* pWrtShell = pTextDoc->GetDocShell()->GetWrtShell();
+        CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pWrtShell);
+
+        SwFlyFrame* pFlyFrame;
+
+        // Before unfloating we have only one page with a fly frame
+        {
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailureMessage.getStr(), SwFrameType::Page,
+                                         pWrtShell->GetLayout()->GetLower()->GetType());
+            CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(),
+                                   !pWrtShell->GetLayout()->GetLower()->GetNext());
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(
+                sFailureMessage.getStr(), SwFrameType::Txt,
+                pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetType());
+            const SwSortedObjs* pAnchored
+                = pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetDrawObjs();
+            CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pAnchored);
+            CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailureMessage.getStr(), static_cast<size_t>(1),
+                                         pAnchored->size());
+            SwAnchoredObject* pAnchoredObj = (*pAnchored)[0];
+            pFlyFrame = dynamic_cast<SwFlyFrame*>(pAnchoredObj);
+            CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pFlyFrame);
+        }
+
+        // Select the floating table
+        SdrObject* pObj = pFlyFrame->GetFormat()->FindRealSdrObject();
+        CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pObj);
+        pWrtShell->SelectObj(Point(), 0, pObj);
+        CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(), pFlyFrame->IsShowUnfloatButton(pWrtShell));
+
+        // Push the unfloat button
+        pFlyFrame->ActiveUnfloatButton(pWrtShell);
+        Scheduler::ProcessEventsToIdle();
+
+        // After unfloating we have two pages with one table frame on each page
+        CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(),
+                               pWrtShell->GetLayout()->GetLower()->GetNext());
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailureMessage.getStr(), SwFrameType::Page,
+                                     pWrtShell->GetLayout()->GetLower()->GetNext()->GetType());
+        CPPUNIT_ASSERT_MESSAGE(sFailureMessage.getStr(),
+                               !pWrtShell->GetLayout()->GetLower()->GetNext()->GetNext());
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(
+            sFailureMessage.getStr(), SwFrameType::Tab,
+            pWrtShell->GetLayout()->GetLower()->GetLower()->GetLower()->GetType());
+        CPPUNIT_ASSERT_EQUAL_MESSAGE(
+            sFailureMessage.getStr(), SwFrameType::Tab,
+            pWrtShell->GetLayout()->GetLower()->GetNext()->GetLower()->GetLower()->GetType());
+    }
 }
 
 void SwUiWriterTest2::testTdf122893()
diff --git a/sw/source/uibase/docvw/UnfloatTableButton.cxx b/sw/source/uibase/docvw/UnfloatTableButton.cxx
index 4fd025ad8ba1..3c564b95024a 100644
--- a/sw/source/uibase/docvw/UnfloatTableButton.cxx
+++ b/sw/source/uibase/docvw/UnfloatTableButton.cxx
@@ -11,7 +11,10 @@
 #include <HeaderFooterWin.hxx>
 
 #include <edtwin.hxx>
+#include <view.hxx>
+#include <wrtsh.hxx>
 #include <strings.hrc>
+#include <fmtpdsc.hxx>
 #include <vcl/metric.hxx>
 #include <vcl/settings.hxx>
 #include <viewopt.hxx>
@@ -19,10 +22,12 @@
 #include <flyfrm.hxx>
 #include <tabfrm.hxx>
 #include <txtfrm.hxx>
+#include <pagefrm.hxx>
 #include <ndindex.hxx>
 #include <swtable.hxx>
 #include <IDocumentState.hxx>
 #include <IDocumentUndoRedo.hxx>
+#include <IDocumentLayoutAccess.hxx>
 #include <drawinglayer/primitive2d/textprimitive2d.hxx>
 #include <drawinglayer/processor2d/baseprocessor2d.hxx>
 #include <drawinglayer/attribute/fontattribute.hxx>
@@ -105,12 +110,28 @@ void UnfloatTableButton::MouseButtonDown(const MouseEvent& /*rMEvt*/)
 
     SwDoc& rDoc = pTextFrame->GetDoc();
 
+    // When we move the table before the first text node, we need to clear RES_PAGEDESC attribute
+    // of the text node otherwise LO will create a page break after the table
+    if (pTextFrame->GetTextNodeFirst())
+    {
+        SfxItemSet aSet(GetEditWin()->GetView().GetWrtShell().GetAttrPool(),
+                        svl::Items<RES_PAGEDESC, RES_PAGEDESC>{});
+        aSet.Put(SwFormatPageDesc(nullptr));
+        SwPaM aPaM(*pTextFrame->GetTextNodeFirst());
+        rDoc.getIDocumentContentOperations().InsertItemSet(aPaM, aSet, SetAttrMode::DEFAULT,
+                                                           GetPageFrame()->getRootFrame());
+    }
+
     // Move the table outside of the text frame
     SwNodeRange aRange(*pTableNode, 0, *pTableNode->EndOfSectionNode(), 1);
     rDoc.getIDocumentContentOperations().MoveNodeRange(aRange, aInsertPos, SwMoveFlags::DEFAULT);
 
     // Remove the floating table's frame
-    SwFrame::DestroyFrame(pFlyFrame);
+    SwFlyFrameFormat* pFrameFormat = pFlyFrame->GetFormat();
+    if (pFrameFormat)
+    {
+        rDoc.getIDocumentLayoutAccess().DelLayoutFormat(pFrameFormat);
+    }
 
     rDoc.getIDocumentState().SetModified();
 


More information about the Libreoffice-commits mailing list