From 015569f5e32a526b412f62ca595a3b5e51e6a012 Mon Sep 17 00:00:00 2001 From: Casey Yelland Date: Tue, 11 Nov 2014 11:11:00 -0800 Subject: [PATCH] Fix bug QTBUG-40691. Win IME's should honor the enabled flag. - IME's were properly being set to disabled but nothing in the windows impl was checking the QPlatformInputContextPrivate::s_inputMethodAccepted flag to see if the IME should be enabled. The result was that IME's were 'always on'. - Fix: On focus change if the input context is disabled we 'turn off' the IME via ImmAssociateContext. ImmAssociateContext code was taken from Qt4. ImmAssociateContext requires a hwnd which is why we need to get the current focus window handle. Change-Id: Iafe0d11996189edd5440e556208ad0f19ad14743 --- .../platforms/windows/qwindowsinputcontext.cpp | 21 +++++++++++++++++++++ .../platforms/windows/qwindowsinputcontext.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/src/plugins/platforms/windows/qwindowsinputcontext.cpp b/src/plugins/platforms/windows/qwindowsinputcontext.cpp index 2429e8a..96c3c4c 100644 --- a/src/plugins/platforms/windows/qwindowsinputcontext.cpp +++ b/src/plugins/platforms/windows/qwindowsinputcontext.cpp @@ -269,6 +269,27 @@ void QWindowsInputContext::invokeAction(QInputMethod::Action action, int cursorP ImmReleaseContext(m_compositionContext.hwnd, himc); } +static HIMC defaultContext = 0; + +void QWindowsInputContext::setFocusObject(QObject *object) +{ + QWindow *window = qApp->focusWindow(); + if (object && window) { + HWND hwnd = reinterpret_cast(window->winId()); + if (inputMethodAccepted()) { + // enable ime + if (defaultContext) + ImmAssociateContext(hwnd, defaultContext); + } + else { + // disable ime + HIMC oldimc = ImmAssociateContext(hwnd, 0); + if (!defaultContext) + defaultContext = oldimc; + } + } +} + QWindowsInputContext *QWindowsInputContext::instance() { return static_cast(QWindowsIntegration::instance()->inputContext()); diff --git a/src/plugins/platforms/windows/qwindowsinputcontext.h b/src/plugins/platforms/windows/qwindowsinputcontext.h index 31a076c..03b792a 100644 --- a/src/plugins/platforms/windows/qwindowsinputcontext.h +++ b/src/plugins/platforms/windows/qwindowsinputcontext.h @@ -72,6 +72,8 @@ public: virtual void update(Qt::InputMethodQueries); virtual void invokeAction(QInputMethod::Action, int cursorPosition); + virtual void setFocusObject(QObject *object); + static QWindowsInputContext *instance(); bool startComposition(HWND hwnd); -- 1.7.11.msysgit.1