[Libreoffice-commits] core.git: Branch 'libreoffice-6-3' - vcl/inc vcl/qt5

Jan-Marek Glogowski (via logerrit) logerrit at kemper.freedesktop.org
Thu Jun 6 21:35:57 UTC 2019


 vcl/inc/qt5/Qt5Widget.hxx |    1 
 vcl/qt5/Qt5Widget.cxx     |   50 ++++++++++++++++++++++++++++------------------
 2 files changed, 32 insertions(+), 19 deletions(-)

New commits:
commit 47caedee74fd5a66f89a062fa0997be473bd56e2
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Sat Jun 1 19:46:16 2019 +0000
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Thu Jun 6 23:35:07 2019 +0200

    tdf#124118 Qt5 post non-code keys via ExtTextInput
    
    Originally I tried to implement the gtk3 way by shoving all key
    input in some way through the QInputMethod. But that turned out
    to be impossible, because all the nice input event filtering is
    privately hidden in the platform abstraction. And it took me
    much longer to realize that gtk3 is doing this.
    
    Still the delivered code point in the KeyEvent is correct, so
    this simply uses ExtTextInput events for non-code key events,
    if LO has enabled input method support for a frame.
    
    Change-Id: Ia9bb6baf013cf790deecb9675f8309e32294e982
    Reviewed-on: https://gerrit.libreoffice.org/73322
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>
    (cherry picked from commit 7140da917bbe80ad39610fdac28f03859f089461)
    Reviewed-on: https://gerrit.libreoffice.org/73620

diff --git a/vcl/inc/qt5/Qt5Widget.hxx b/vcl/inc/qt5/Qt5Widget.hxx
index af48dbe5e4f5..6398fa7db55c 100644
--- a/vcl/inc/qt5/Qt5Widget.hxx
+++ b/vcl/inc/qt5/Qt5Widget.hxx
@@ -48,6 +48,7 @@ class Qt5Widget : public QWidget
 
     bool handleKeyEvent(QKeyEvent*, bool);
     void handleMouseButtonEvent(QMouseEvent*, bool);
+    void commitText(const QString& aText) const;
 
     virtual bool event(QEvent*) override;
 
diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx
index a6b3d29e69a8..63eb68577da1 100644
--- a/vcl/qt5/Qt5Widget.cxx
+++ b/vcl/qt5/Qt5Widget.cxx
@@ -394,13 +394,35 @@ static sal_uInt16 GetKeyCode(int keyval, Qt::KeyboardModifiers modifiers)
     return nCode;
 }
 
+void Qt5Widget::commitText(const QString& aText) const
+{
+    SalExtTextInputEvent aInputEvent;
+    aInputEvent.mpTextAttr = nullptr;
+    aInputEvent.mnCursorFlags = 0;
+    aInputEvent.maText = toOUString(aText);
+    aInputEvent.mnCursorPos = aInputEvent.maText.getLength();
+
+    SolarMutexGuard aGuard;
+    vcl::DeletionListener aDel(&m_rFrame);
+    m_rFrame.CallCallback(SalEvent::ExtTextInput, &aInputEvent);
+    if (!aDel.isDeleted())
+        m_rFrame.CallCallback(SalEvent::EndExtTextInput, nullptr);
+}
+
 bool Qt5Widget::handleKeyEvent(QKeyEvent* pEvent, bool bDown)
 {
-    SalKeyEvent aEvent;
+    sal_uInt16 nCode = GetKeyCode(pEvent->key(), pEvent->modifiers());
+    if (bDown && nCode == 0 && !pEvent->text().isEmpty()
+        && testAttribute(Qt::WA_InputMethodEnabled))
+    {
+        commitText(pEvent->text());
+        return true;
+    }
 
+    SalKeyEvent aEvent;
     aEvent.mnCharCode = (pEvent->text().isEmpty() ? 0 : pEvent->text().at(0).unicode());
     aEvent.mnRepeat = 0;
-    aEvent.mnCode = GetKeyCode(pEvent->key(), pEvent->modifiers());
+    aEvent.mnCode = nCode;
     aEvent.mnCode |= GetKeyModCode(pEvent->modifiers());
 
     QGuiApplication::inputMethod()->update(Qt::ImCursorRectangle);
@@ -483,24 +505,13 @@ static ExtTextInputAttr lcl_MapUndrelineStyle(QTextCharFormat::UnderlineStyle us
 
 void Qt5Widget::inputMethodEvent(QInputMethodEvent* pEvent)
 {
-    SolarMutexGuard aGuard;
-    SalExtTextInputEvent aInputEvent;
-    aInputEvent.mpTextAttr = nullptr;
-    aInputEvent.mnCursorFlags = 0;
-
-    vcl::DeletionListener aDel(&m_rFrame);
-
     if (!pEvent->commitString().isEmpty())
-    {
-        aInputEvent.maText = toOUString(pEvent->commitString());
-        aInputEvent.mnCursorPos = aInputEvent.maText.getLength();
-        if (!aDel.isDeleted())
-            m_rFrame.CallCallback(SalEvent::ExtTextInput, &aInputEvent);
-        if (!aDel.isDeleted())
-            m_rFrame.CallCallback(SalEvent::EndExtTextInput, nullptr);
-    }
+        commitText(pEvent->commitString());
     else
     {
+        SalExtTextInputEvent aInputEvent;
+        aInputEvent.mpTextAttr = nullptr;
+        aInputEvent.mnCursorFlags = 0;
         aInputEvent.maText = toOUString(pEvent->preeditString());
         aInputEvent.mnCursorPos = 0;
 
@@ -549,8 +560,9 @@ void Qt5Widget::inputMethodEvent(QInputMethodEvent* pEvent)
         const bool bIsEmpty = aInputEvent.maText.isEmpty();
         if (m_bNonEmptyIMPreeditSeen || !bIsEmpty)
         {
-            if (!aDel.isDeleted())
-                m_rFrame.CallCallback(SalEvent::ExtTextInput, &aInputEvent);
+            SolarMutexGuard aGuard;
+            vcl::DeletionListener aDel(&m_rFrame);
+            m_rFrame.CallCallback(SalEvent::ExtTextInput, &aInputEvent);
             if (!aDel.isDeleted() && bIsEmpty)
                 m_rFrame.CallCallback(SalEvent::EndExtTextInput, nullptr);
             m_bNonEmptyIMPreeditSeen = !bIsEmpty;


More information about the Libreoffice-commits mailing list