sw/qa/extras/uiwriter/uiwriter2.cxx | 102 +++++++++++++++---------- sw/source/uibase/docvw/FloatingTableButton.cxx | 37 ++++++++- 2 files changed, 97 insertions(+), 42 deletions(-)
New commits: commit 79f84cf94dd26c4fee14a0db4a98df7791df78f2 Author: Tamás Zolnai <tamas.zol...@collabora.com> AuthorDate: Wed Jan 30 16:43:28 2019 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Wed Jan 30 18:51:43 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. Reviewed-on: https://gerrit.libreoffice.org/67093 Tested-by: Jenkins Reviewed-by: Tamás Zolnai <tamas.zol...@collabora.com> (cherry picked from commit 70c29e50af8e16b864d1e5e5a74c30a1de8250de) Unfloat: Need to move the page desc into the table node AttrSet Reviewed-on: https://gerrit.libreoffice.org/67126 Tested-by: Jenkins Reviewed-by: Tamás Zolnai <tamas.zol...@collabora.com> (cherry picked from commit 9d319865f8bf78d25ca2e614d148420054a6461a) Change-Id: I02802c4d25c947ec140b846c594848117815f1ce b9868bb31238905dd178fcf54c79f013079a037b Reviewed-on: https://gerrit.libreoffice.org/67098 Reviewed-by: Miklos Vajna <vmik...@collabora.com> Tested-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 274bec37d0b1..d6d8c989fb2f 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -19,6 +19,7 @@ #include <sortedobjs.hxx> #include <anchoredobject.hxx> #include <swtypes.hxx> +#include <vcl/scheduler.hxx> namespace { @@ -174,49 +175,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 tablre 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()); + } } CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2); diff --git a/sw/source/uibase/docvw/FloatingTableButton.cxx b/sw/source/uibase/docvw/FloatingTableButton.cxx index ba0f0fcfbcc8..ccbd0a8c17d3 100644 --- a/sw/source/uibase/docvw/FloatingTableButton.cxx +++ b/sw/source/uibase/docvw/FloatingTableButton.cxx @@ -11,17 +11,22 @@ #include <HeaderFooterWin.hxx> #include <edtwin.hxx> +#include <view.hxx> +#include <wrtsh.hxx> #include <strings.hrc> +#include <fmtpdsc.hxx> #include <vcl/metric.hxx> #include <viewopt.hxx> #include <frame.hxx> #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> @@ -104,12 +109,40 @@ void FloatingTableButton::MouseButtonDown(const MouseEvent& /*rMEvt*/) SwDoc& rDoc = *pTextFrame->GetTextNode()->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->GetTextNode()) + { + const SwPageDesc* pPageDesc + = pTextFrame->GetAttrSet()->GetPageDesc().GetPageDesc(); // First text node of the page has this + if (pPageDesc) + { + // First set the existing page desc for the table node + SfxItemSet aSet(GetEditWin()->GetView().GetWrtShell().GetAttrPool(), + svl::Items<RES_PAGEDESC, RES_PAGEDESC>{}); + aSet.Put(SwFormatPageDesc(pPageDesc)); + SwPaM aPaMTable(*pTableNode); + rDoc.getIDocumentContentOperations().InsertItemSet( + aPaMTable, aSet, SetAttrMode::DEFAULT); + + // Then remove pagedesc from the attributes of the text node + aSet.Put(SwFormatPageDesc(nullptr)); + SwPaM aPaMTextNode(*pTextFrame->GetTextNode()); + rDoc.getIDocumentContentOperations().InsertItemSet( + aPaMTextNode, aSet, SetAttrMode::DEFAULT); + } + } + // 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(); @@ -174,4 +207,4 @@ bool FloatingTableButton::Contains(const Point& rDocPt) const void FloatingTableButton::SetReadonly(bool bReadonly) { ShowAll(!bReadonly); } -/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ \ No newline at end of file +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits