LibreOffice Module editeng (master) 1
urlfieldhelper.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
9
11
12#include <editeng/flditem.hxx>
13#include <editeng/editview.hxx>
14#include <editeng/editeng.hxx>
15
17{
18 pEditView.SelectFieldAtCursor();
19 const SvxFieldData* pField = pEditView.GetFieldAtCursor();
20 if (auto pUrlField = dynamic_cast<const SvxURLField*>(pField))
21 {
22 ESelection aSel = pEditView.GetSelection();
23 pEditView.GetEditEngine()->QuickInsertText(pUrlField->GetRepresentation(), aSel);
24 pEditView.Invalidate();
25 }
26}
27
29{
30 // tdf#128666 Make sure only URL field (or nothing) is selected
31 ESelection aSel = pEditView.GetSelection();
32 auto nSelectedParas = aSel.nEndPara - aSel.nStartPara;
33 auto nSelectedChars = aSel.nEndPos - aSel.nStartPos;
34 bool bIsValidSelection
35 = nSelectedParas == 0
36 && (nSelectedChars == 0 || nSelectedChars == 1 || nSelectedChars == -1);
37 if (!bIsValidSelection)
38 return false;
39
40 const SvxFieldData* pField = pEditView.GetFieldAtCursor();
41 if (dynamic_cast<const SvxURLField*>(pField))
42 return true;
43
44 return false;
45}
46
47/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
void QuickInsertText(const OUString &rText, const ESelection &rSel)
Definition: editeng.cxx:2084
ESelection GetSelection() const
Definition: editview.cxx:301
void SelectFieldAtCursor()
Definition: editview.cxx:1364
const SvxFieldData * GetFieldAtCursor() const
Select and return the field at the current cursor position.
Definition: editview.cxx:1389
EditEngine * GetEditEngine() const
Definition: editview.cxx:178
void Invalidate()
Definition: editview.cxx:239
static void RemoveURLField(EditView &pEditView)
static bool IsCursorAtURLField(const EditView &pEditView)
sal_Int32 nStartPara
Definition: editdata.hxx:113
sal_Int32 nEndPos
Definition: editdata.hxx:116
sal_Int32 nStartPos
Definition: editdata.hxx:114
sal_Int32 nEndPara
Definition: editdata.hxx:115