summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamás Zolnai <tamas.zolnai@collabora.com>2019-01-04 03:12:46 +0100
committerTamás Zolnai <tamas.zolnai@collabora.com>2019-01-04 04:09:17 +0100
commitdcf70bb4188e019154d6201936bf1ee2e16149a3 (patch)
treebcfdfaa36420ecc448e5afe88e820161c7388b88
parent9c4a374baa4d18dec4066e547d76a40501b20d45 (diff)
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.zolnai@collabora.com>
-rw-r--r--sw/source/uibase/docvw/FloatingTableButton.cxx49
1 files changed, 48 insertions, 1 deletions
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&)