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 <lars.knoll@digia.com>
This commit is contained in:
Friedemann Kleint 2014-07-30 13:32:53 +02:00
parent 2eea6034bc
commit b5ce3d504c

View File

@ -88,18 +88,6 @@ static inline void imeNotifyCancelComposition(HWND hwnd)
ImmReleaseContext(hwnd, himc); ImmReleaseContext(hwnd, himc);
} }
// Query a QObject for an InputMethod-related value
// by sending a QInputMethodQueryEvent.
template <class T>
bool inputMethodQuery(QObject *fo, Qt::InputMethodQuery query, T *result)
{
QInputMethodQueryEvent queryEvent(query);
if (!QCoreApplication::sendEvent(fo, &queryEvent))
return false;
*result = qvariant_cast<T>(queryEvent.value(query));
return true;
}
/*! /*!
\class QWindowsInputContext \class QWindowsInputContext
\brief Windows Input context implementation \brief Windows Input context implementation
@ -170,7 +158,7 @@ QWindowsInputContext::QWindowsInputContext() :
m_WM_MSIME_MOUSE(RegisterWindowMessage(L"MSIMEMouseOperation")), m_WM_MSIME_MOUSE(RegisterWindowMessage(L"MSIMEMouseOperation")),
m_endCompositionRecursionGuard(false) m_endCompositionRecursionGuard(false)
{ {
connect(qApp->inputMethod(), SIGNAL(cursorRectangleChanged()), connect(QGuiApplication::inputMethod(), SIGNAL(cursorRectangleChanged()),
this, SLOT(cursorRectChanged())); this, SLOT(cursorRectChanged()));
} }
@ -215,7 +203,7 @@ void QWindowsInputContext::cursorRectChanged()
{ {
if (!m_compositionContext.hwnd) if (!m_compositionContext.hwnd)
return; return;
const QInputMethod *inputMethod = qApp->inputMethod(); const QInputMethod *inputMethod = QGuiApplication::inputMethod();
QRect cursorRectangle = inputMethod->cursorRectangle().toRect(); QRect cursorRectangle = inputMethod->cursorRectangle().toRect();
if (!cursorRectangle.isValid()) if (!cursorRectangle.isValid())
return; return;
@ -536,9 +524,10 @@ int QWindowsInputContext::reconvertString(RECONVERTSTRING *reconv)
if (!fo) if (!fo)
return false; return false;
QString surroundingText; const QVariant surroundingTextV = QInputMethod::queryFocusObject(Qt::ImSurroundingText, QVariant());
if (!inputMethodQuery(fo, Qt::ImSurroundingText, &surroundingText)) if (!surroundingTextV.isValid())
return -1; return -1;
const QString surroundingText = surroundingTextV.toString();
const DWORD memSize = sizeof(RECONVERTSTRING) const DWORD memSize = sizeof(RECONVERTSTRING)
+ (surroundingText.length() + 1) * sizeof(ushort); + (surroundingText.length() + 1) * sizeof(ushort);
qCDebug(lcQpaInputMethods) << __FUNCTION__ << " reconv=" << reconv qCDebug(lcQpaInputMethods) << __FUNCTION__ << " reconv=" << reconv
@ -547,8 +536,8 @@ int QWindowsInputContext::reconvertString(RECONVERTSTRING *reconv)
if (!reconv) if (!reconv)
return surroundingText.isEmpty() ? -1 : int(memSize); return surroundingText.isEmpty() ? -1 : int(memSize);
int pos = 0; const QVariant posV = QInputMethod::queryFocusObject(Qt::ImCursorPosition, QVariant());
inputMethodQuery(fo, Qt::ImCursorPosition, &pos); const int pos = posV.isValid() ? posV.toInt() : 0;
// Find the word in the surrounding text. // Find the word in the surrounding text.
QTextBoundaryFinder bounds(QTextBoundaryFinder::Word, surroundingText); QTextBoundaryFinder bounds(QTextBoundaryFinder::Word, surroundingText);
bounds.setPosition(pos); bounds.setPosition(pos);