diff options
author | Tamás Zolnai <tamas.zolnai@collabora.com> | 2019-01-04 11:23:59 +0100 |
---|---|---|
committer | Tamás Zolnai <tamas.zolnai@collabora.com> | 2019-01-04 13:08:55 +0100 |
commit | dd0b559d6aac5bf09566af735bd00b28c00fb2e4 (patch) | |
tree | aeb56b0bdbb77f5f145b8b94c006bc31d36140d1 | |
parent | ba60204055823bce27a51078d7170e0ff9836636 (diff) |
Unfloat: Test layout change of unfloat operation
Change-Id: I75298a392de6a10861ac96e1bc58a30173cd2dd2
Reviewed-on: https://gerrit.libreoffice.org/65823
Tested-by: Jenkins
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
-rw-r--r-- | sw/qa/extras/uiwriter/uiwriter2.cxx | 52 | ||||
-rw-r--r-- | sw/source/core/inc/flyfrm.hxx | 3 | ||||
-rw-r--r-- | sw/source/core/layout/fly.cxx | 11 |
3 files changed, 64 insertions, 2 deletions
diff --git a/sw/qa/extras/uiwriter/uiwriter2.cxx b/sw/qa/extras/uiwriter/uiwriter2.cxx index 3f49e4c591f8..74a8a7593a82 100644 --- a/sw/qa/extras/uiwriter/uiwriter2.cxx +++ b/sw/qa/extras/uiwriter/uiwriter2.cxx @@ -27,8 +27,7 @@ #include <view.hxx> #include <sortedobjs.hxx> #include <anchoredobject.hxx> -#include <FrameControlsManager.hxx> -#include <FloatingTableButton.hxx> +#include <swtypes.hxx> namespace { @@ -54,6 +53,7 @@ public: void testUnfloatButtonSmallTable(); void testUnfloatButton(); void testUnfloatButtonReadOnlyMode(); + void testUnfloating(); CPPUNIT_TEST_SUITE(SwUiWriterTest2); CPPUNIT_TEST(testRedlineMoveInsertInDelete); @@ -70,6 +70,7 @@ public: CPPUNIT_TEST(testUnfloatButtonSmallTable); CPPUNIT_TEST(testUnfloatButton); CPPUNIT_TEST(testUnfloatButtonReadOnlyMode); + CPPUNIT_TEST(testUnfloating); CPPUNIT_TEST_SUITE_END(); private: @@ -635,6 +636,53 @@ void SwUiWriterTest2::testUnfloatButtonReadOnlyMode() CPPUNIT_ASSERT(!pFlyFrame->IsShowUnfloatButton(pWrtShell)); } +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; + + // Before unfloating we have only one page with a fly frame + { + 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); + } + + // 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()); +} + CPPUNIT_TEST_SUITE_REGISTRATION(SwUiWriterTest2); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/inc/flyfrm.hxx b/sw/source/core/inc/flyfrm.hxx index 5ee5eb152b9b..218fbe4a98ec 100644 --- a/sw/source/core/inc/flyfrm.hxx +++ b/sw/source/core/inc/flyfrm.hxx @@ -274,6 +274,9 @@ public: void SelectionHasChanged(SwFEShell* pShell); bool IsShowUnfloatButton(SwWrtShell* pWrtSh) const; + // For testing only (see uiwriter) + void ActiveUnfloatButton(SwWrtShell* pWrtSh); + private: void UpdateUnfloatButton(SwWrtShell* pWrtSh, bool bShow) const; void PaintDecorators() const; diff --git a/sw/source/core/layout/fly.cxx b/sw/source/core/layout/fly.cxx index 5cf16541ee9b..edb35f91a049 100644 --- a/sw/source/core/layout/fly.cxx +++ b/sw/source/core/layout/fly.cxx @@ -1849,6 +1849,17 @@ bool SwFlyFrame::IsShowUnfloatButton(SwWrtShell* pWrtSh) const return nBodyHeight < nTableHeight + nFrameOffset; } +void SwFlyFrame::ActiveUnfloatButton(SwWrtShell* pWrtSh) +{ + SwEditWin& rEditWin = pWrtSh->GetView().GetEditWin(); + SwFrameControlsManager& rMngr = rEditWin.GetFrameControlsManager(); + SwFrameControlPtr pControl = rMngr.GetControl(FloatingTable, this); + if (pControl.get() || pControl->GetWindow()) + { + pControl->GetWindow()->MouseButtonDown(MouseEvent()); + } +} + void SwFlyFrame::UpdateUnfloatButton(SwWrtShell* pWrtSh, bool bShow) const { if (pWrtSh == nullptr) |