diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-06-25 14:20:29 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-06-25 18:13:24 +0200 |
commit | 7b726e587ec7bbe8926fd00a50c0192ad32b3858 (patch) | |
tree | 929c1bc813522bc9e6b0ef182923d97c1e8010a1 /editeng | |
parent | 44250864a8252d29c87801a4530e3fe3efd01ba7 (diff) |
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@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/Library_editeng.mk | 1 | ||||
-rw-r--r-- | editeng/source/misc/weldeditview.cxx | 147 |
2 files changed, 148 insertions, 0 deletions
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: */ |