From dcf70bb4188e019154d6201936bf1ee2e16149a3 Mon Sep 17 00:00:00 2001 From: Tamás Zolnai Date: Fri, 4 Jan 2019 03:12:46 +0100 Subject: Unfloat: Implement unfloating of a floating table MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Triggered by the unfloat button. Change-Id: I863f0ec481480343c184b0b5fa94b9ba1aa9276c Reviewed-on: https://gerrit.libreoffice.org/65821 Tested-by: Jenkins Reviewed-by: Tamás Zolnai --- sw/source/uibase/docvw/FloatingTableButton.cxx | 49 +++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/sw/source/uibase/docvw/FloatingTableButton.cxx b/sw/source/uibase/docvw/FloatingTableButton.cxx index 8f124f46f652..eccdef644227 100644 --- a/sw/source/uibase/docvw/FloatingTableButton.cxx +++ b/sw/source/uibase/docvw/FloatingTableButton.cxx @@ -14,6 +14,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -21,6 +27,7 @@ #include #include #include +#include #define TEXT_PADDING 3 #define BOX_DISTANCE 3 @@ -58,7 +65,47 @@ void FloatingTableButton::SetOffset(Point aBottomRightPixel) void FloatingTableButton::MouseButtonDown(const MouseEvent& /*rMEvt*/) { - // Move the table outside of the frame + assert(GetFrame()->IsFlyFrame()); + // const_cast is needed because of bad design of ISwFrameControl and derived classes + SwFlyFrame* pFlyFrame = const_cast(static_cast(GetFrame())); + + // Find the table inside the text frame + SwTabFrame* pTableFrame = nullptr; + SwFrame* pLower = pFlyFrame->GetLower(); + while (pLower) + { + if (pLower->IsTabFrame()) + { + pTableFrame = static_cast(pLower); + break; + } + pLower = pLower->GetNext(); + } + + if (pTableFrame == nullptr) + return; + + // Insert the table at the position of the text node which has the frame anchored to + SwFrame* pAnchoreFrame = pFlyFrame->AnchorFrame(); + if (pAnchoreFrame == nullptr || !pAnchoreFrame->IsTextFrame()) + return; + + SwTextFrame* pTextFrame = static_cast(pAnchoreFrame); + if (pTextFrame->GetTextNodeFirst() == nullptr) + return; + + SwNodeIndex aInsertPos((*pTextFrame->GetTextNodeFirst())); + + SwTableNode* pTableNode = pTableFrame->GetTable()->GetTableNode(); + if (pTableNode == nullptr) + return; + + SwNodeRange aRange(*pTableNode, 0, *pTableNode->EndOfSectionNode(), 1); + pTableNode->getIDocumentContentOperations().MoveNodeRange(aRange, aInsertPos, + SwMoveFlags::DEFAULT); + + // Remove the floating table's frame + SwFrame::DestroyFrame(pFlyFrame); } void FloatingTableButton::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) -- cgit v1.2.3