summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/windows/qwindowsinputcontext.cpp
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-10-19 17:18:19 +0200
committerFriedemann Kleint <Friedemann.Kleint@theqtcompany.com>2015-10-22 08:45:16 +0000
commit9388bbe4bdc366760c0ee5953d5f2157c51a8e68 (patch)
tree37a6257846a1d2efacd61c4272c24c96f73ee276 /src/plugins/platforms/windows/qwindowsinputcontext.cpp
parente137676354dbc6f1d63e9d1ee1163a86623c948a (diff)
Windows: Implement QPlatformInputContext::locale().
Initialize locale from current keyboard value and listen to WM_INPUTLANGCHANGE. Task-number: QTBUG-48772 Change-Id: I53b6ef4e2cf538bb81b41ea497ed0cb66991b104 Reviewed-by: Liang Qi <liang.qi@theqtcompany.com> Reviewed-by: Oliver Wolff <oliver.wolff@theqtcompany.com>
Diffstat (limited to 'src/plugins/platforms/windows/qwindowsinputcontext.cpp')
-rw-r--r--src/plugins/platforms/windows/qwindowsinputcontext.cpp33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/plugins/platforms/windows/qwindowsinputcontext.cpp b/src/plugins/platforms/windows/qwindowsinputcontext.cpp
index e016b84bba..7e1cc563cb 100644
--- a/src/plugins/platforms/windows/qwindowsinputcontext.cpp
+++ b/src/plugins/platforms/windows/qwindowsinputcontext.cpp
@@ -84,6 +84,18 @@ static inline void imeNotifyCancelComposition(HWND hwnd)
ImmReleaseContext(hwnd, himc);
}
+static inline LCID languageIdFromLocaleId(LCID localeId)
+{
+ return localeId & 0xFFFF;
+}
+
+static inline LCID currentInputLanguageId()
+{
+ return languageIdFromLocaleId(reinterpret_cast<quintptr>(GetKeyboardLayout(0)));
+}
+
+Q_CORE_EXPORT QLocale qt_localeFromLCID(LCID id); // from qlocale_win.cpp
+
/*!
\class QWindowsInputContext
\brief Windows Input context implementation
@@ -153,7 +165,9 @@ QWindowsInputContext::CompositionContext::CompositionContext() :
QWindowsInputContext::QWindowsInputContext() :
m_WM_MSIME_MOUSE(RegisterWindowMessage(L"MSIMEMouseOperation")),
- m_endCompositionRecursionGuard(false)
+ m_endCompositionRecursionGuard(false),
+ m_languageId(currentInputLanguageId()),
+ m_locale(qt_localeFromLCID(m_languageId))
{
connect(QGuiApplication::inputMethod(), &QInputMethod::cursorRectangleChanged,
this, &QWindowsInputContext::cursorRectChanged);
@@ -371,7 +385,7 @@ bool QWindowsInputContext::startComposition(HWND hwnd)
QWindow *window = QGuiApplication::focusWindow();
if (!window)
return false;
- qCDebug(lcQpaInputMethods) << __FUNCTION__ << fo << window;
+ qCDebug(lcQpaInputMethods) << __FUNCTION__ << fo << window << "language=" << m_languageId;
if (!fo || QWindowsWindow::handleOf(window) != hwnd)
return false;
initContext(hwnd, fo);
@@ -555,6 +569,21 @@ bool QWindowsInputContext::handleIME_Request(WPARAM wParam,
return false;
}
+void QWindowsInputContext::handleInputLanguageChanged(WPARAM wparam, LPARAM lparam)
+{
+ const LCID newLanguageId = languageIdFromLocaleId(lparam);
+ if (newLanguageId == m_languageId)
+ return;
+ const LCID oldLanguageId = m_languageId;
+ m_languageId = newLanguageId;
+ m_locale = qt_localeFromLCID(m_languageId);
+ emitLocaleChanged();
+
+ qCDebug(lcQpaInputMethods) << __FUNCTION__ << hex << showbase
+ << oldLanguageId << "->" << newLanguageId << "Character set:"
+ << DWORD(wparam) << dec << noshowbase << m_locale;
+}
+
/*!
\brief Determines the string for reconversion with selection.