diff options
author | Michael Weghorn <m.weghorn@posteo.de> | 2022-05-28 10:44:29 +0200 |
---|---|---|
committer | Michael Weghorn <m.weghorn@posteo.de> | 2022-05-28 16:08:45 +0200 |
commit | 54f6599a4de738dfe3a26e8229e5588d26dd8165 (patch) | |
tree | efe2fa471f274aa77e3c58a58a0dcfc62118f936 | |
parent | 87a932120d5f146933ed3bcc16c0f47dab90fd4b (diff) |
Move GtkSalFrame::CalcDeleteSurroundingSelection to SalFrame
It will be used for qt5/qt6 in a follow-up commit
as well.
Change-Id: Ic6a9351b0506519010b92e11d30962d5b105ec2b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135052
Tested-by: Jenkins
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
-rw-r--r-- | vcl/inc/salframe.hxx | 6 | ||||
-rw-r--r-- | vcl/inc/unx/gtk/gtkframe.hxx | 1 | ||||
-rw-r--r-- | vcl/source/app/salvtables.cxx | 50 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtkframe.cxx | 52 | ||||
-rw-r--r-- | vcl/unx/gtk3/gtkinst.cxx | 2 |
5 files changed, 58 insertions, 53 deletions
diff --git a/vcl/inc/salframe.hxx b/vcl/inc/salframe.hxx index ac8840b437c7..1c5cbbbcd0ee 100644 --- a/vcl/inc/salframe.hxx +++ b/vcl/inc/salframe.hxx @@ -306,6 +306,12 @@ public: // (e.g. input methods, printer update handlers). bool CallCallback( SalEvent nEvent, const void* pEvent ) const { return m_pProc && m_pProc( m_pWindow, nEvent, pEvent ); } + + // Helper method for input method handling: Calculate cursor index in (UTF-16) OUString, + // starting at nCursorIndex, moving number of characters (not UTF-16 codepoints) specified + // in nOffset, nChars. + static Selection CalcDeleteSurroundingSelection(const OUString& rSurroundingText, + sal_Int32 nCursorIndex, int nOffset, int nChars); }; #ifdef _WIN32 diff --git a/vcl/inc/unx/gtk/gtkframe.hxx b/vcl/inc/unx/gtk/gtkframe.hxx index c90afbdee899..91a9470a071e 100644 --- a/vcl/inc/unx/gtk/gtkframe.hxx +++ b/vcl/inc/unx/gtk/gtkframe.hxx @@ -633,7 +633,6 @@ public: GdkModifierType, gpointer pFrame); #endif static OUString GetPreeditDetails(GtkIMContext* pIMContext, std::vector<ExtTextInputAttr>& rInputFlags, sal_Int32& rCursorPos, sal_uInt8& rCursorFlags); - static Selection CalcDeleteSurroundingSelection(const OUString& rSurroundingText, sal_Int32 nCursorIndex, int nOffset, int nChars); const cairo_font_options_t* get_font_options(); diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx index 07a8a649c8ba..fd7739f3c460 100644 --- a/vcl/source/app/salvtables.cxx +++ b/vcl/source/app/salvtables.cxx @@ -7375,4 +7375,54 @@ weld::Window* SalFrame::GetFrameWeld() const return m_xFrameWeld.get(); } +Selection SalFrame::CalcDeleteSurroundingSelection(const OUString& rSurroundingText, + sal_Int32 nCursorIndex, int nOffset, int nChars) +{ + Selection aInvalid(SAL_MAX_UINT32, SAL_MAX_UINT32); + + if (nCursorIndex == -1) + return aInvalid; + + 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", + "SalFrame::CalcDeleteSurroundingSelection, 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", "SalFrame::CalcDeleteSurroundingSelection, unable to select: " + << nChars << " characters"); + return aInvalid; + } + + return Selection(nCursorIndex, nCursorEndIndex); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/unx/gtk3/gtkframe.cxx b/vcl/unx/gtk3/gtkframe.cxx index 80f235d10642..3684dd560593 100644 --- a/vcl/unx/gtk3/gtkframe.cxx +++ b/vcl/unx/gtk3/gtkframe.cxx @@ -5710,56 +5710,6 @@ gboolean GtkSalFrame::IMHandler::signalIMRetrieveSurrounding( GtkIMContext* pCon return true; } -Selection GtkSalFrame::CalcDeleteSurroundingSelection(const OUString& rSurroundingText, sal_Int32 nCursorIndex, int nOffset, int nChars) -{ - Selection aInvalid(SAL_MAX_UINT32, SAL_MAX_UINT32); - - 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 ) { @@ -5774,7 +5724,7 @@ gboolean GtkSalFrame::IMHandler::signalIMDeleteSurrounding( GtkIMContext*, gint pThis->m_pFrame->CallCallback(SalEvent::SurroundingTextRequest, &aSurroundingTextEvt); // Turn offset, nchars into a utf-16 selection - Selection aSelection = GtkSalFrame::CalcDeleteSurroundingSelection(aSurroundingTextEvt.maText, + Selection aSelection = SalFrame::CalcDeleteSurroundingSelection(aSurroundingTextEvt.maText, aSurroundingTextEvt.mnStart, offset, nchars); Selection aInvalid(SAL_MAX_UINT32, SAL_MAX_UINT32); diff --git a/vcl/unx/gtk3/gtkinst.cxx b/vcl/unx/gtk3/gtkinst.cxx index 6e2dc24590d1..c61f6d650261 100644 --- a/vcl/unx/gtk3/gtkinst.cxx +++ b/vcl/unx/gtk3/gtkinst.cxx @@ -18019,7 +18019,7 @@ public: OUString sSurroundingText; sal_Int32 nCursorIndex = pThis->m_pArea->im_context_get_surrounding(sSurroundingText); - Selection aSelection = GtkSalFrame::CalcDeleteSurroundingSelection(sSurroundingText, nCursorIndex, nOffset, nChars); + Selection aSelection = SalFrame::CalcDeleteSurroundingSelection(sSurroundingText, nCursorIndex, nOffset, nChars); if (aSelection != Selection(SAL_MAX_UINT32, SAL_MAX_UINT32)) bRet = pThis->m_pArea->im_context_delete_surrounding(aSelection); return bRet; |