nss: upgrade to release 3.73
[LibreOffice.git] / editeng / source / misc / urlfieldhelper.cxx
blob564bc54e781e2b715e45e2442c294ac3d19d081b
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.
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 */
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
35 = nSelectedParas == 0
36 && (nSelectedChars == 0 || nSelectedChars == 1 || nSelectedChars == -1);
37 if (!bIsValidSelection)
38 return false;
40 const SvxFieldData* pField = pEditView.GetFieldAtCursor();
41 if (dynamic_cast<const SvxURLField*>(pField))
42 return true;
44 return false;
47 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */