[Libreoffice-commits] core.git: Branch 'libreoffice-6-3' - editeng/Library_editeng.mk editeng/source include/editeng

Caolán McNamara (via logerrit) logerrit at kemper.freedesktop.org
Fri Sep 13 08:46:19 UTC 2019


 editeng/Library_editeng.mk           |    1 
 editeng/source/misc/weldeditview.cxx |  147 +++++++++++++++++++++++++++++++++++
 include/editeng/weldeditview.hxx     |   62 ++++++++++++++
 3 files changed, 210 insertions(+)

New commits:
commit ed7c96738298a19d375937f38642be08e65fcf46
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Tue Jun 25 14:20:29 2019 +0100
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Sep 13 10:45:46 2019 +0200

    factor out to a common WeldEditView
    
    Change-Id: Ife7b6f57c80d310bd11a8ed89e36fdc99742d158
    Reviewed-on: https://gerrit.libreoffice.org/74698
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>
    (cherry picked from commit 7b726e587ec7bbe8926fd00a50c0192ad32b3858)
    Reviewed-on: https://gerrit.libreoffice.org/78543
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/editeng/Library_editeng.mk b/editeng/Library_editeng.mk
index 9354071b3a70..fc47842b650f 100644
--- a/editeng/Library_editeng.mk
+++ b/editeng/Library_editeng.mk
@@ -98,6 +98,7 @@ $(eval $(call gb_Library_add_exception_objects,editeng,\
     editeng/source/misc/swafopt \
     editeng/source/misc/txtrange \
     editeng/source/misc/unolingu \
+    editeng/source/misc/weldeditview \
     editeng/source/outliner/outleeng \
     editeng/source/outliner/outlin2 \
     editeng/source/outliner/outliner \
diff --git a/editeng/source/misc/weldeditview.cxx b/editeng/source/misc/weldeditview.cxx
new file mode 100644
index 000000000000..dab3796f9b17
--- /dev/null
+++ b/editeng/source/misc/weldeditview.cxx
@@ -0,0 +1,147 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#include <editeng/weldeditview.hxx>
+#include <vcl/cursor.hxx>
+#include <vcl/event.hxx>
+#include <vcl/ptrstyle.hxx>
+#include <vcl/settings.hxx>
+#include <vcl/svapp.hxx>
+
+Size WeldEditView::GetPreferredSize() const { return Size(500, 100); }
+
+void WeldEditView::SetDrawingArea(weld::DrawingArea* pDrawingArea)
+{
+    Size aSize(GetPreferredSize());
+    pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
+    SetOutputSizePixel(aSize);
+
+    weld::CustomWidgetController::SetDrawingArea(pDrawingArea);
+
+    EnableRTL(false);
+
+    const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
+    Color aBgColor = rStyleSettings.GetWindowColor();
+
+    OutputDevice& rDevice = pDrawingArea->get_ref_device();
+
+    rDevice.SetMapMode(MapMode(MapUnit::MapTwip));
+    rDevice.SetBackground(aBgColor);
+
+    Size aOutputSize(rDevice.PixelToLogic(aSize));
+    aSize = aOutputSize;
+    aSize.setHeight(aSize.Height());
+
+    m_xEdEngine.reset(new EditEngine(EditEngine::CreatePool()));
+    m_xEdEngine->SetPaperSize(aSize);
+    m_xEdEngine->SetRefDevice(&rDevice);
+
+    m_xEdEngine->SetControlWord(m_xEdEngine->GetControlWord() | EEControlBits::MARKFIELDS);
+
+    m_xEdView.reset(new EditView(m_xEdEngine.get(), nullptr));
+    m_xEdView->setEditViewCallbacks(this);
+    m_xEdView->SetOutputArea(tools::Rectangle(Point(0, 0), aOutputSize));
+
+    m_xEdView->SetBackgroundColor(aBgColor);
+    m_xEdEngine->InsertView(m_xEdView.get());
+
+    pDrawingArea->set_cursor(PointerStyle::Text);
+}
+
+WeldEditView::~WeldEditView() {}
+
+void WeldEditView::Resize()
+{
+    OutputDevice& rDevice = GetDrawingArea()->get_ref_device();
+    Size aOutputSize(rDevice.PixelToLogic(GetOutputSizePixel()));
+    Size aSize(aOutputSize);
+    m_xEdEngine->SetPaperSize(aSize);
+    m_xEdView->SetOutputArea(tools::Rectangle(Point(0, 0), aOutputSize));
+    weld::CustomWidgetController::Resize();
+}
+
+void WeldEditView::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect)
+{
+    //note: ScEditWindow::Paint is similar
+
+    rRenderContext.Push(PushFlags::ALL);
+    rRenderContext.SetClipRegion();
+
+    const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
+    Color aBgColor = rStyleSettings.GetWindowColor();
+
+    m_xEdView->SetBackgroundColor(aBgColor);
+
+    rRenderContext.SetBackground(aBgColor);
+
+    tools::Rectangle aLogicRect(rRenderContext.PixelToLogic(rRect));
+    m_xEdView->Paint(aLogicRect, &rRenderContext);
+
+    if (HasFocus())
+    {
+        m_xEdView->ShowCursor();
+        vcl::Cursor* pCursor = m_xEdView->GetCursor();
+        pCursor->DrawToDevice(rRenderContext);
+    }
+
+    std::vector<tools::Rectangle> aLogicRects;
+
+    // get logic selection
+    m_xEdView->GetSelectionRectangles(aLogicRects);
+
+    rRenderContext.SetLineColor();
+    rRenderContext.SetFillColor(COL_BLACK);
+    rRenderContext.SetRasterOp(RasterOp::Invert);
+
+    for (const auto& rSelectionRect : aLogicRects)
+        rRenderContext.DrawRect(rSelectionRect);
+
+    rRenderContext.Pop();
+}
+
+bool WeldEditView::MouseMove(const MouseEvent& rMEvt) { return m_xEdView->MouseMove(rMEvt); }
+
+bool WeldEditView::MouseButtonDown(const MouseEvent& rMEvt)
+{
+    if (!HasFocus())
+        GrabFocus();
+
+    return m_xEdView->MouseButtonDown(rMEvt);
+}
+
+bool WeldEditView::MouseButtonUp(const MouseEvent& rMEvt)
+{
+    return m_xEdView->MouseButtonUp(rMEvt);
+}
+
+bool WeldEditView::KeyInput(const KeyEvent& rKEvt)
+{
+    sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
+
+    if (nKey == KEY_TAB)
+    {
+        return false;
+    }
+    else if (!m_xEdView->PostKeyEvent(rKEvt))
+    {
+        return false;
+    }
+
+    return true;
+}
+
+void WeldEditView::GetFocus()
+{
+    m_xEdView->ShowCursor();
+
+    weld::CustomWidgetController::GetFocus();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/include/editeng/weldeditview.hxx b/include/editeng/weldeditview.hxx
new file mode 100644
index 000000000000..3d31f589d14f
--- /dev/null
+++ b/include/editeng/weldeditview.hxx
@@ -0,0 +1,62 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ */
+
+#ifndef INCLUDED_EDITENG_WELDEDITVIEW_HXX
+#define INCLUDED_EDITENG_WELDEDITVIEW_HXX
+
+#include <sal/config.h>
+#include <editeng/editengdllapi.h>
+#include <editeng/editeng.hxx>
+#include <editeng/editview.hxx>
+#include <vcl/customweld.hxx>
+#include <vcl/outdev.hxx>
+
+class EDITENG_DLLPUBLIC WeldEditView : public weld::CustomWidgetController, public EditViewCallbacks
+{
+public:
+    WeldEditView();
+    virtual void SetDrawingArea(weld::DrawingArea* pDrawingArea) override;
+    virtual ~WeldEditView() override;
+
+    std::unique_ptr<EditEngine> m_xEdEngine;
+    std::unique_ptr<EditView> m_xEdView;
+
+protected:
+    virtual Size GetPreferredSize() const;
+    virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override;
+    virtual bool MouseMove(const MouseEvent& rMEvt) override;
+    virtual bool MouseButtonDown(const MouseEvent& rMEvt) override;
+    virtual bool MouseButtonUp(const MouseEvent& rMEvt) override;
+    virtual bool KeyInput(const KeyEvent& rKEvt) override;
+    virtual void GetFocus() override;
+    virtual void Resize() override;
+
+    virtual void EditViewInvalidate(const tools::Rectangle& rRect) const override
+    {
+        weld::DrawingArea* pDrawingArea = GetDrawingArea();
+        pDrawingArea->queue_draw_area(rRect.Left(), rRect.Top(), rRect.GetWidth(),
+                                      rRect.GetHeight());
+    }
+
+    virtual void EditViewSelectionChange() const override
+    {
+        weld::DrawingArea* pDrawingArea = GetDrawingArea();
+        pDrawingArea->queue_draw();
+    }
+
+    virtual OutputDevice& EditViewOutputDevice() const override
+    {
+        return GetDrawingArea()->get_ref_device();
+    }
+};
+
+#endif // INCLUDED_EDITENG_WELDEDITVIEW_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list