From 9945c2458d75947b94e9cdb45b7aca7ed6336c12 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Fri, 12 Jul 2019 08:53:35 +0200 Subject: Move remove url code to editeng so that the code can be reused by sc and sw Change-Id: I0d3c778c7bb7847fcf690d0e76994afdd0645285 Reviewed-on: https://gerrit.libreoffice.org/75477 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt --- editeng/Library_editeng.mk | 1 + editeng/source/misc/urlfieldhelper.cxx | 27 +++++++++++++++++++++++++++ editeng/source/outliner/outlvw.cxx | 28 ++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 editeng/source/misc/urlfieldhelper.cxx (limited to 'editeng') diff --git a/editeng/Library_editeng.mk b/editeng/Library_editeng.mk index fc47842b650f..57717ed839f8 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/urlfieldhelper \ editeng/source/misc/weldeditview \ editeng/source/outliner/outleeng \ editeng/source/outliner/outlin2 \ diff --git a/editeng/source/misc/urlfieldhelper.cxx b/editeng/source/misc/urlfieldhelper.cxx new file mode 100644 index 000000000000..961a946ca142 --- /dev/null +++ b/editeng/source/misc/urlfieldhelper.cxx @@ -0,0 +1,27 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * 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 + +#include + +void URLFieldHelper::RemoveURLField(Outliner* pOutl, OutlinerView* pOLV) +{ + if (!pOutl || !pOLV) + return; + + const SvxFieldData* pField = pOLV->GetFieldAtCursor(); + if (auto pUrlField = dynamic_cast(pField)) + { + ESelection aSel = pOLV->GetSelection(); + pOutl->QuickInsertText(pUrlField->GetRepresentation(), aSel); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/editeng/source/outliner/outlvw.cxx b/editeng/source/outliner/outlvw.cxx index 124f43122a99..43efbbb1615c 100644 --- a/editeng/source/outliner/outlvw.cxx +++ b/editeng/source/outliner/outlvw.cxx @@ -1317,6 +1317,34 @@ const SvxFieldItem* OutlinerView::GetFieldAtSelection() const return pEditView->GetFieldAtSelection(); } +const SvxFieldData* OutlinerView::GetFieldAtCursor() +{ + const SvxFieldItem* pFieldItem = GetFieldAtSelection(); + if (pFieldItem) + { + // Make sure the whole field is selected + ESelection aSel = GetSelection(); + if (aSel.nStartPos == aSel.nEndPos) + { + aSel.nEndPos++; + SetSelection(aSel); + } + } + if (!pFieldItem) + { + // Cursor probably behind the field - extend selection to select the field + ESelection aSel = GetSelection(); + if (aSel.nStartPos == aSel.nEndPos) + { + aSel.nStartPos--; + SetSelection(aSel); + pFieldItem = GetFieldAtSelection(); + } + } + + return pFieldItem ? pFieldItem->GetField() : nullptr; +} + void OutlinerView::SetInvalidateMore( sal_uInt16 nPixel ) { pEditView->SetInvalidateMore( nPixel ); -- cgit v1.2.3