From b5ce3d504c4cfe46725bfbcb4bfa37c7456a67c9 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 30 Jul 2014 13:32:53 +0200 Subject: Windows plugin: Refactor input context. - Use static invocation of QGuiApplication accessor. - Use QInputMethod::queryFocusObject(). Task-number: QTBUG-40402 Change-Id: Ic1a7f66389df532acca88ddda37d35d6e7049a53 Reviewed-by: Lars Knoll --- .../platforms/windows/qwindowsinputcontext.cpp | 25 ++++++---------------- 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsinputcontext.cpp b/src/plugins/platforms/windows/qwindowsinputcontext.cpp index 2429e8a4fa..bc7ffc9afd 100644 --- a/src/plugins/platforms/windows/qwindowsinputcontext.cpp +++ b/src/plugins/platforms/windows/qwindowsinputcontext.cpp @@ -88,18 +88,6 @@ static inline void imeNotifyCancelComposition(HWND hwnd) ImmReleaseContext(hwnd, himc); } -// Query a QObject for an InputMethod-related value -// by sending a QInputMethodQueryEvent. -template - bool inputMethodQuery(QObject *fo, Qt::InputMethodQuery query, T *result) -{ - QInputMethodQueryEvent queryEvent(query); - if (!QCoreApplication::sendEvent(fo, &queryEvent)) - return false; - *result = qvariant_cast(queryEvent.value(query)); - return true; -} - /*! \class QWindowsInputContext \brief Windows Input context implementation @@ -170,7 +158,7 @@ QWindowsInputContext::QWindowsInputContext() : m_WM_MSIME_MOUSE(RegisterWindowMessage(L"MSIMEMouseOperation")), m_endCompositionRecursionGuard(false) { - connect(qApp->inputMethod(), SIGNAL(cursorRectangleChanged()), + connect(QGuiApplication::inputMethod(), SIGNAL(cursorRectangleChanged()), this, SLOT(cursorRectChanged())); } @@ -215,7 +203,7 @@ void QWindowsInputContext::cursorRectChanged() { if (!m_compositionContext.hwnd) return; - const QInputMethod *inputMethod = qApp->inputMethod(); + const QInputMethod *inputMethod = QGuiApplication::inputMethod(); QRect cursorRectangle = inputMethod->cursorRectangle().toRect(); if (!cursorRectangle.isValid()) return; @@ -536,9 +524,10 @@ int QWindowsInputContext::reconvertString(RECONVERTSTRING *reconv) if (!fo) return false; - QString surroundingText; - if (!inputMethodQuery(fo, Qt::ImSurroundingText, &surroundingText)) + const QVariant surroundingTextV = QInputMethod::queryFocusObject(Qt::ImSurroundingText, QVariant()); + if (!surroundingTextV.isValid()) return -1; + const QString surroundingText = surroundingTextV.toString(); const DWORD memSize = sizeof(RECONVERTSTRING) + (surroundingText.length() + 1) * sizeof(ushort); qCDebug(lcQpaInputMethods) << __FUNCTION__ << " reconv=" << reconv @@ -547,8 +536,8 @@ int QWindowsInputContext::reconvertString(RECONVERTSTRING *reconv) if (!reconv) return surroundingText.isEmpty() ? -1 : int(memSize); - int pos = 0; - inputMethodQuery(fo, Qt::ImCursorPosition, &pos); + const QVariant posV = QInputMethod::queryFocusObject(Qt::ImCursorPosition, QVariant()); + const int pos = posV.isValid() ? posV.toInt() : 0; // Find the word in the surrounding text. QTextBoundaryFinder bounds(QTextBoundaryFinder::Word, surroundingText); bounds.setPosition(pos); -- cgit v1.2.3