[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Jan 7 09:23:27 UTC 2019


 sw/source/uibase/docvw/FloatingTableButton.cxx |   49 ++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)

New commits:
commit d2f6818130cef0926c8e3ead6dc6f03fd005fefc
Author:     Tamás Zolnai <tamas.zolnai at collabora.com>
AuthorDate: Fri Jan 4 21:10:27 2019 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Mon Jan 7 10:23:07 2019 +0100

    Unfloat: Implement unfloating of a floating table
    
    Triggered by the unfloat button.
    
    Reviewed-on: https://gerrit.libreoffice.org/65821
    Tested-by: Jenkins
    Reviewed-by: Tamás Zolnai <tamas.zolnai at collabora.com>
    (cherry picked from commit dcf70bb4188e019154d6201936bf1ee2e16149a3)
    
    Change-Id: I863f0ec481480343c184b0b5fa94b9ba1aa9276c
    Reviewed-on: https://gerrit.libreoffice.org/65872
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/sw/source/uibase/docvw/FloatingTableButton.cxx b/sw/source/uibase/docvw/FloatingTableButton.cxx
index 8f124f46f652..982af73c0367 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->GetTextNode() == nullptr)
+        return;
+
+    SwNodeIndex aInsertPos((*pTextFrame->GetTextNode()));
+
+    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&)


More information about the Libreoffice-commits mailing list