summaryrefslogtreecommitdiff
path: root/src/video
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2013-08-05 20:37:06 +0000
committermichi_cc <michi_cc@openttd.org>2013-08-05 20:37:06 +0000
commit7422120014b51f0057bb41b3e9b6405957a01b63 (patch)
tree2a56e09275b9e9e75f8be57f4ca1c0b7d39ee3c3 /src/video
parent13873d2534208ddc4596a9354d23d1e4940339ac (diff)
downloadopenttd-7422120014b51f0057bb41b3e9b6405957a01b63.tar.xz
(svn r25679) -Codechange: [Win32] Get the result string of an IME input directly without a trip through the window messaging system.
Diffstat (limited to 'src/video')
-rw-r--r--src/video/win32_v.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp
index 8d50d812a..c497feb7e 100644
--- a/src/video/win32_v.cpp
+++ b/src/video/win32_v.cpp
@@ -24,6 +24,7 @@
#include "../window_func.h"
#include "win32_v.h"
#include <windows.h>
+#include <imm.h>
/* Missing define in MinGW headers. */
#ifndef MAPVK_VK_TO_CHAR
@@ -498,6 +499,33 @@ static LRESULT HandleCharMsg(uint keycode, WChar charcode)
return 0;
}
+#if !defined(WINCE) || _WIN32_WCE >= 0x400
+/** Handle WM_IME_COMPOSITION messages. */
+static LRESULT HandleIMEComposition(HWND hwnd, WPARAM wParam, LPARAM lParam)
+{
+ HIMC hIMC = ImmGetContext(hwnd);
+
+ if (hIMC != NULL) {
+ if (lParam & GCS_RESULTSTR) {
+ /* Read result string from the IME. */
+ LONG len = ImmGetCompositionString(hIMC, GCS_RESULTSTR, NULL, 0); // Length is always in bytes, even in UNICODE build.
+ TCHAR *str = (TCHAR *)_alloca(len + sizeof(TCHAR));
+ len = ImmGetCompositionString(hIMC, GCS_RESULTSTR, str, len);
+ str[len / sizeof(TCHAR)] = '\0';
+
+ /* Transmit text to windowing system. */
+ if (len > 0) HandleTextInput(FS2OTTD(str));
+
+ /* Don't pass the result string on to the default window proc. */
+ lParam &= ~(GCS_RESULTSTR | GCS_RESULTCLAUSE | GCS_RESULTREADCLAUSE | GCS_RESULTREADSTR);
+ }
+ }
+ ImmReleaseContext(hwnd, hIMC);
+
+ return lParam != 0 ? DefWindowProc(hwnd, WM_IME_COMPOSITION, wParam, lParam) : 0;
+}
+#endif
+
static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static uint32 keycode = 0;
@@ -633,6 +661,9 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
}
#if !defined(WINCE) || _WIN32_WCE >= 0x400
+ case WM_IME_COMPOSITION:
+ return HandleIMEComposition(hwnd, wParam, lParam);
+
#if !defined(UNICODE)
case WM_IME_CHAR:
if (GB(wParam, 8, 8) != 0) {