[Libreoffice-commits] core.git: vcl/qt5

Jan-Marek Glogowski (via logerrit) logerrit at kemper.freedesktop.org
Wed May 15 21:22:26 UTC 2019


 vcl/qt5/Qt5Widget.cxx |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

New commits:
commit 7dc35d13e375cac1371ea491ee3bc46ef5ebf8a6
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Sat May 4 01:04:35 2019 +0000
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Wed May 15 23:21:06 2019 +0200

    Qt5 IM handle surrounding text requests
    
    This is almost a C'n'P from gtk / gtk3. That code is from 2006
    (see i#68048 / commit 28c5cdcc53ae068b0c763c660d61a8291dd96726).
    The original patch was described by the author (caolan) as
    hilarious. No change from my side, except using QString.
    
    Completely untested, in theory correct.
    
    Change-Id: I8373ca7ac9eda6e377da985532fd2b7cd595bf48
    Reviewed-on: https://gerrit.libreoffice.org/71786
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx
index 88ce1b18f0e7..8db1e05e6cf2 100644
--- a/vcl/qt5/Qt5Widget.cxx
+++ b/vcl/qt5/Qt5Widget.cxx
@@ -46,6 +46,12 @@
 #include <headless/svpgdi.hxx>
 #include <vcl/commandevent.hxx>
 #include <vcl/event.hxx>
+#include <window.h>
+
+#include <com/sun/star/accessibility/XAccessibleContext.hpp>
+#include <com/sun/star/accessibility/XAccessibleEditableText.hpp>
+
+using namespace com::sun::star;
 
 void Qt5Widget::paintEvent(QPaintEvent* pEvent)
 {
@@ -553,10 +559,55 @@ void Qt5Widget::inputMethodEvent(QInputMethodEvent* pEvent)
     pEvent->accept();
 }
 
+static bool lcl_retrieveSurrounding(sal_Int32& rPosition, QString* pText)
+{
+    vcl::Window* pFocusWin = Application::GetFocusWindow();
+    if (!pFocusWin)
+        return false;
+
+    uno::Reference<accessibility::XAccessibleEditableText> xText;
+    try
+    {
+        uno::Reference<accessibility::XAccessible> xAccessible(pFocusWin->GetAccessible());
+        if (xAccessible.is())
+            xText = FindFocusedEditableText(xAccessible->getAccessibleContext());
+    }
+    catch (const uno::Exception& e)
+    {
+        SAL_WARN("vcl.qt5", "Exception in getting input method surrounding text: " << e);
+    }
+    if (xText.is())
+    {
+        rPosition = xText->getCaretPosition();
+        if (rPosition != -1 && pText)
+        {
+            *pText = toQString(xText->getText());
+            return true;
+        }
+    }
+
+    return false;
+}
+
 QVariant Qt5Widget::inputMethodQuery(Qt::InputMethodQuery property) const
 {
     switch (property)
     {
+        case Qt::ImSurroundingText:
+        {
+            QString aText;
+            sal_Int32 nCursorPos;
+            if (lcl_retrieveSurrounding(nCursorPos, &aText))
+                return QVariant(aText);
+            [[fallthrough]];
+        }
+        case Qt::ImCursorPosition:
+        {
+            sal_Int32 nCursorPos;
+            if (lcl_retrieveSurrounding(nCursorPos, nullptr))
+                return QVariant(nCursorPos);
+            [[fallthrough]];
+        }
         case Qt::ImCursorRectangle:
         {
             SalExtTextInputPosEvent aPosEvent;
@@ -567,6 +618,8 @@ QVariant Qt5Widget::inputMethodQuery(Qt::InputMethodQuery property) const
         default:
             return QWidget::inputMethodQuery(property);
     }
+
+    return QVariant();
 }
 
 void Qt5Widget::endExtTextInput()


More information about the Libreoffice-commits mailing list