From 7de0edbbb725a1ffbfebb1f41a85853cd402db36 Mon Sep 17 00:00:00 2001 From: fvogel Date: Sun, 25 Sep 2016 20:13:53 +0000 Subject: New attempt to fix [720879afe9] - WM_CHAR message handling. Patch from Christian Werner backported from http://www.androwish.org/index.html/info/a0da5845594cec28 --- win/tkWinX.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/win/tkWinX.c b/win/tkWinX.c index bb60a2d..e13bb4f 100644 --- a/win/tkWinX.c +++ b/win/tkWinX.c @@ -92,7 +92,7 @@ static Tcl_ThreadDataKey dataKey; static void GenerateXEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); static unsigned int GetState(UINT message, WPARAM wParam, LPARAM lParam); -static void GetTranslatedKey(XKeyEvent *xkey); +static void GetTranslatedKey(XKeyEvent *xkey, UINT type); static void UpdateInputLanguage(int charset); static int HandleIMEComposition(HWND hwnd, LPARAM lParam); @@ -1157,7 +1157,8 @@ GenerateXEvent( event.type = KeyPress; event.xany.send_event = -1; event.xkey.keycode = wParam; - GetTranslatedKey(&event.xkey); + GetTranslatedKey(&event.xkey, (message == WM_KEYDOWN) ? WM_CHAR : + WM_SYSCHAR); break; case WM_SYSKEYUP: @@ -1229,9 +1230,10 @@ GenerateXEvent( if (IsDBCSLeadByte((BYTE) wParam)) { MSG msg; - if ((PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) != 0) + if ((PeekMessage(&msg, NULL, WM_CHAR, WM_CHAR, + PM_NOREMOVE) != 0) && (msg.message == WM_CHAR)) { - GetMessage(&msg, NULL, 0, 0); + GetMessage(&msg, NULL, WM_CHAR, WM_CHAR); event.xkey.nbytes = 2; event.xkey.trans_chars[1] = (char) msg.wParam; } @@ -1370,19 +1372,20 @@ GetState( static void GetTranslatedKey( - XKeyEvent *xkey) + XKeyEvent *xkey, + UINT type) { MSG msg; xkey->nbytes = 0; while ((xkey->nbytes < XMaxTransChars) - && PeekMessageA(&msg, NULL, 0, 0, PM_NOREMOVE)) { - if ((msg.message != WM_CHAR) && (msg.message != WM_SYSCHAR)) { + && (PeekMessageA(&msg, NULL, type, type, PM_NOREMOVE) != 0)) { + if (msg.message != type) { break; } - GetMessageA(&msg, NULL, 0, 0); + GetMessageA(&msg, NULL, type, type); /* * If this is a normal character message, we may need to strip off the -- cgit v0.12 From 6864f7029a8095dec62bdc53e31f4e3c30c31b0b Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 27 Sep 2016 09:58:34 +0000 Subject: Fix [720879afe9] - WM_CHAR message handling. Patch from Christian Werner backported from http://www.androwish.org/index.html/info/a0da5845594cec28 --- win/tkWinX.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/win/tkWinX.c b/win/tkWinX.c index cbd6032..af28e41 100644 --- a/win/tkWinX.c +++ b/win/tkWinX.c @@ -137,7 +137,7 @@ static Tcl_ThreadDataKey dataKey; static void GenerateXEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); static unsigned int GetState(UINT message, WPARAM wParam, LPARAM lParam); -static void GetTranslatedKey(XKeyEvent *xkey); +static void GetTranslatedKey(XKeyEvent *xkey, UINT type); static void UpdateInputLanguage(int charset); static int HandleIMEComposition(HWND hwnd, LPARAM lParam); @@ -1187,7 +1187,8 @@ GenerateXEvent( event.type = KeyPress; event.xany.send_event = -1; event.xkey.keycode = wParam; - GetTranslatedKey(&event.xkey); + GetTranslatedKey(&event.xkey, (message == WM_KEYDOWN) ? WM_CHAR : + WM_SYSCHAR); break; case WM_SYSKEYUP: @@ -1243,9 +1244,10 @@ GenerateXEvent( if (IsDBCSLeadByte((BYTE) wParam)) { MSG msg; - if ((PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) != 0) + if ((PeekMessage(&msg, NULL, WM_CHAR, WM_CHAR, + PM_NOREMOVE) != 0) && (msg.message == WM_CHAR)) { - GetMessage(&msg, NULL, 0, 0); + GetMessage(&msg, NULL, WM_CHAR, WM_CHAR); event.xkey.nbytes = 2; event.xkey.trans_chars[1] = (char) msg.wParam; } @@ -1392,19 +1394,20 @@ GetState( static void GetTranslatedKey( - XKeyEvent *xkey) + XKeyEvent *xkey, + UINT type) { MSG msg; xkey->nbytes = 0; while ((xkey->nbytes < XMaxTransChars) - && PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { - if ((msg.message != WM_CHAR) && (msg.message != WM_SYSCHAR)) { + && PeekMessage(&msg, NULL, type, type, PM_NOREMOVE)) { + if (msg.message != type) { break; } - GetMessage(&msg, NULL, 0, 0); + GetMessage(&msg, NULL, type, type); /* * If this is a normal character message, we may need to strip off the -- cgit v0.12 From 506ee2fc81bb27e237860565c11a1494ab8c7b38 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Tue, 27 Sep 2016 14:41:50 +0000 Subject: Internal code simplification: Store Unicode character in keycode field in stead of trans_chars. No behavior change, just use a different internal event type. --- win/tkWinKey.c | 15 --------------- win/tkWinX.c | 15 ++++++--------- 2 files changed, 6 insertions(+), 24 deletions(-) diff --git a/win/tkWinKey.c b/win/tkWinKey.c index a567653..89b5d29 100644 --- a/win/tkWinKey.c +++ b/win/tkWinKey.c @@ -97,21 +97,6 @@ TkpGetString( Tcl_ExternalToUtfDString(TkWinGetKeyInputEncoding(), keyEv->trans_chars, keyEv->nbytes, dsPtr); } - } else if (keyEv->send_event == -2) { - /* - * Special case for win2000 multi-lingal IME input. xkey.trans_chars[] - * already contains a UNICODE char. - */ - - int unichar; - - unichar = keyEv->trans_chars[1] & 0xff; - unichar <<= 8; - unichar |= keyEv->trans_chars[0] & 0xff; - - len = Tcl_UniCharToUtf((Tcl_UniChar) unichar, buf); - - Tcl_DStringAppend(dsPtr, buf, len); } else if (keyEv->send_event == -3) { /* diff --git a/win/tkWinX.c b/win/tkWinX.c index e13bb4f..5771a29 100644 --- a/win/tkWinX.c +++ b/win/tkWinX.c @@ -1573,18 +1573,18 @@ HandleIMEComposition( n = ImmGetCompositionString(hIMC, GCS_RESULTSTR, NULL, 0); if (n > 0) { - char *buff = ckalloc(n); + WCHAR *buff = (WCHAR *) ckalloc(n); TkWindow *winPtr; XEvent event; int i; - n = ImmGetCompositionString(hIMC, GCS_RESULTSTR, buff, (unsigned) n); + n = ImmGetCompositionString(hIMC, GCS_RESULTSTR, buff, (unsigned) n) / 2; /* * Set up the fields pertinent to key event. * - * We set send_event to the special value of -2, so that TkpGetString - * in tkWinKey.c knows that trans_chars[] already contains a UNICODE + * We set send_event to the special value of -3, so that TkpGetString + * in tkWinKey.c knows that keycode already contains a UNICODE * char and there's no need to do encoding conversion. * * Note that the event *must* be zeroed out first; Tk plays cunning @@ -1595,7 +1595,7 @@ HandleIMEComposition( memset(&event, 0, sizeof(XEvent)); event.xkey.serial = winPtr->display->request++; - event.xkey.send_event = -2; + event.xkey.send_event = -3; event.xkey.display = winPtr->display; event.xkey.window = winPtr->window; event.xkey.root = RootWindow(winPtr->display, winPtr->screenNum); @@ -1603,8 +1603,6 @@ HandleIMEComposition( event.xkey.state = TkWinGetModifierState(); event.xkey.time = TkpGetMS(); event.xkey.same_screen = True; - event.xkey.keycode = 0; - event.xkey.nbytes = 2; for (i=0; i