From 70c29e50af8e16b864d1e5e5a74c30a1de8250de Mon Sep 17 00:00:00 2001 From: Tamás Zolnai Date: Tue, 29 Jan 2019 19:05:56 +0100 Subject: Unfloat: Fix some issues with unfloat operation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- sw/qa/extras/uiwriter/uiwriter2.cxx | 101 ++++++++++++++++---------- sw/source/uibase/docvw/UnfloatTableButton.cxx | 23 +++++- 2 files changed, 83 insertions(+), 41 deletions(-) (limited to 'sw') 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(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 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(1), pAnchored->size()); - SwAnchoredObject* pAnchoredObj = (*pAnchored)[0]; - pFlyFrame = dynamic_cast(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(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(1), + pAnchored->size()); + SwAnchoredObject* pAnchoredObj = (*pAnchored)[0]; + pFlyFrame = dynamic_cast(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 #include +#include +#include #include +#include #include #include #include @@ -19,10 +22,12 @@ #include #include #include +#include #include #include #include #include +#include #include #include #include @@ -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{}); + 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(); -- cgit