diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-10-24 21:12:52 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-10-25 22:01:58 +0100 |
commit | 41df2d06cc13a1c60a4ea9671535afb8bd55b344 (patch) | |
tree | 96c61b2bed2a746657f1212b9cf53916e01b8bf7 /vcl | |
parent | 8d3a60ce43a36a4568c772afdb331f29e51503c2 (diff) |
Related: tdf#137620 factor out working IMDeleteSurrounding hunk
Change-Id: I7504e8670fb464fe3e76a3d38f1cac39ba2e9208
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104779
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/unx/gtk/gtkframe.hxx | 1 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkframe.cxx | 50 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtk3gtkinst.cxx | 48 |
3 files changed, 54 insertions, 45 deletions
diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx index 820d796bf6e5..ad67070f2b0c 100644 --- a/vcl/inc/unx/gtk/gtkframe.hxx +++ b/vcl/inc/unx/gtk/gtkframe.hxx @@ -528,6 +528,7 @@ public: static gboolean NativeWidgetHelpPressed(GtkAccelGroup*, GObject*, guint, GdkModifierType, gpointer pFrame); static OUString GetPreeditDetails(GtkIMContext* pIMContext, std::vector<ExtTextInputAttr>& rInputFlags, sal_Int32& rCursorPos, sal_uInt8& rCursorFlags); + static Selection CalcDeleteSurroundingSelection(const OUString& rSurroundingText, int nCursorIndex, int nOffset, int nChars); void DisallowCycleFocusOut(); bool IsCycleFocusOutDisallowed() const; diff --git a/vcl/unx/gtk3/gtk3gtkframe.cxx b/vcl/unx/gtk3/gtk3gtkframe.cxx index eb964a790533..7da09d72d375 100644 --- a/vcl/unx/gtk3/gtk3gtkframe.cxx +++ b/vcl/unx/gtk3/gtk3gtkframe.cxx @@ -4400,6 +4400,56 @@ gboolean GtkSalFrame::IMHandler::signalIMRetrieveSurrounding( GtkIMContext* pCon return false; } +Selection GtkSalFrame::CalcDeleteSurroundingSelection(const OUString& rSurroundingText, int nCursorIndex, int nOffset, int nChars) +{ + Selection aInvalid(-1, -1); + + if (nCursorIndex == -1) + return aInvalid; + + // Note that offset and n_chars are in characters not in bytes + // which differs from the usage other places in GtkIMContext + + if (nOffset > 0) + { + while (nOffset && nCursorIndex < rSurroundingText.getLength()) + { + rSurroundingText.iterateCodePoints(&nCursorIndex, 1); + --nOffset; + } + } + else if (nOffset < 0) + { + while (nOffset && nCursorIndex > 0) + { + rSurroundingText.iterateCodePoints(&nCursorIndex, -1); + ++nOffset; + } + } + + if (nOffset) + { + SAL_WARN("vcl.gtk", "IM delete-surrounding, unable to move to offset: " << nOffset); + return aInvalid; + } + + sal_Int32 nCursorEndIndex(nCursorIndex); + sal_Int32 nCount(0); + while (nCount < nChars && nCursorEndIndex < rSurroundingText.getLength()) + { + rSurroundingText.iterateCodePoints(&nCursorEndIndex, 1); + ++nCount; + } + + if (nCount != nChars) + { + SAL_WARN("vcl.gtk", "IM delete-surrounding, unable to select: " << nChars << " characters"); + return aInvalid; + } + + return Selection(nCursorIndex, nCursorEndIndex); +} + gboolean GtkSalFrame::IMHandler::signalIMDeleteSurrounding( GtkIMContext*, gint offset, gint nchars, gpointer /*im_handler*/ ) { diff --git a/vcl/unx/gtk3/gtk3gtkinst.cxx b/vcl/unx/gtk3/gtk3gtkinst.cxx index 46baaf4bc6cf..6ee16f782503 100644 --- a/vcl/unx/gtk3/gtk3gtkinst.cxx +++ b/vcl/unx/gtk3/gtk3gtkinst.cxx @@ -13848,51 +13848,9 @@ public: OUString sSurroundingText; sal_Int32 nCursorIndex = pThis->m_pArea->im_context_get_surrounding(sSurroundingText); - if (nCursorIndex != -1) - { - // Note that offset and n_chars are in characters not in bytes - // which differs from the usage other places in GtkIMContext - - if (nOffset > 0) - { - while (nOffset && nCursorIndex < sSurroundingText.getLength()) - { - sSurroundingText.iterateCodePoints(&nCursorIndex, 1); - --nOffset; - } - } - else if (nOffset < 0) - { - while (nOffset && nCursorIndex > 0) - { - sSurroundingText.iterateCodePoints(&nCursorIndex, -1); - ++nOffset; - } - } - - if (nOffset) - { - SAL_WARN("vcl.gtk", "IM delete-surrounding, unable to move to offset: " << nOffset); - return false; - } - - sal_Int32 nCursorEndIndex(nCursorIndex); - sal_Int32 nCount(0); - while (nCount < nChars && nCursorEndIndex < sSurroundingText.getLength()) - { - sSurroundingText.iterateCodePoints(&nCursorEndIndex, 1); - ++nCount; - } - - if (nCount != nChars) - { - SAL_WARN("vcl.gtk", "IM delete-surrounding, unable to select: " << nChars << " characters"); - return false; - } - - bRet = pThis->m_pArea->im_context_delete_surrounding(Selection(nCursorIndex, nCursorEndIndex)); - } - + Selection aSelection = GtkSalFrame::CalcDeleteSurroundingSelection(sSurroundingText, nCursorIndex, nOffset, nChars); + if (aSelection != Selection(-1, -1)) + bRet = pThis->m_pArea->im_context_delete_surrounding(aSelection); return bRet; } |