1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
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/.
10 #include <editeng/urlfieldhelper.hxx>
12 #include <editeng/flditem.hxx>
13 #include <editeng/editview.hxx>
14 #include <editeng/editeng.hxx>
16 void URLFieldHelper::RemoveURLField(EditView
& pEditView
)
18 pEditView
.SelectFieldAtCursor();
19 const SvxFieldData
* pField
= pEditView
.GetFieldAtCursor();
20 if (auto pUrlField
= dynamic_cast<const SvxURLField
*>(pField
))
22 ESelection aSel
= pEditView
.GetSelection();
23 pEditView
.GetEditEngine()->QuickInsertText(pUrlField
->GetRepresentation(), aSel
);
24 pEditView
.Invalidate();
28 bool URLFieldHelper::IsCursorAtURLField(const EditView
& pEditView
)
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
36 && (nSelectedChars
== 0 || nSelectedChars
== 1 || nSelectedChars
== -1);
37 if (!bIsValidSelection
)
40 const SvxFieldData
* pField
= pEditView
.GetFieldAtCursor();
41 if (dynamic_cast<const SvxURLField
*>(pField
))
47 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */