sw/source/uibase/docvw/FloatingTableButton.cxx | 49 ++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-)
New commits: commit dcf70bb4188e019154d6201936bf1ee2e16149a3 Author: Tamás Zolnai <tamas.zol...@collabora.com> AuthorDate: Fri Jan 4 03:12:46 2019 +0100 Commit: Tamás Zolnai <tamas.zol...@collabora.com> CommitDate: Fri Jan 4 04:09:17 2019 +0100 Unfloat: Implement unfloating of a floating table Triggered by the unfloat button. Change-Id: I863f0ec481480343c184b0b5fa94b9ba1aa9276c Reviewed-on: https://gerrit.libreoffice.org/65821 Tested-by: Jenkins Reviewed-by: Tamás Zolnai <tamas.zol...@collabora.com> 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 <strings.hrc> #include <vcl/metric.hxx> #include <viewopt.hxx> +#include <frame.hxx> +#include <flyfrm.hxx> +#include <tabfrm.hxx> +#include <txtfrm.hxx> +#include <ndindex.hxx> +#include <swtable.hxx> #include <drawinglayer/primitive2d/textprimitive2d.hxx> #include <drawinglayer/processor2d/baseprocessor2d.hxx> #include <drawinglayer/attribute/fontattribute.hxx> @@ -21,6 +27,7 @@ #include <basegfx/matrix/b2dhommatrixtools.hxx> #include <drawinglayer/processor2d/processorfromoutputdevice.hxx> #include <basegfx/vector/b2dvector.hxx> +#include <DocumentContentOperationsManager.hxx> #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<SwFlyFrame*>(static_cast<const SwFlyFrame*>(GetFrame())); + + // Find the table inside the text frame + SwTabFrame* pTableFrame = nullptr; + SwFrame* pLower = pFlyFrame->GetLower(); + while (pLower) + { + if (pLower->IsTabFrame()) + { + pTableFrame = static_cast<SwTabFrame*>(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<SwTextFrame*>(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&) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits