summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfvogel <fvogel@noemail.net>2016-08-23 20:16:55 (GMT)
committerfvogel <fvogel@noemail.net>2016-08-23 20:16:55 (GMT)
commit0c2099c80524554327af2ce990ebfbc51cd003fe (patch)
treeec621613a624a80e4c7a43a2aa81fbfd73520553
parent02f164eaaed552f9f4da043f40f0b340ae940426 (diff)
downloadtk-0c2099c80524554327af2ce990ebfbc51cd003fe.zip
tk-0c2099c80524554327af2ce990ebfbc51cd003fe.tar.gz
tk-0c2099c80524554327af2ce990ebfbc51cd003fe.tar.bz2
Patch [6c0d7aec67] from Christian Werner on upstream Androwish to better handle unicode text input for Windows 8 by dealing with wParam VK_PACKET in WM_KEYDOWN and WM_SYSKEYDOWN events. This was observed on a Windows 8.1 tablet when the on-screen virtual keyboard is used to enter Emojis for example. The changes allow to enter Emojis when Tcl/Tk is built with TCL_UTF_MAX>3.
FossilOrigin-Name: aaa031e1510a942b67ee76613f3747303160b416
-rw-r--r--win/tkWinX.c77
1 files changed, 68 insertions, 9 deletions
diff --git a/win/tkWinX.c b/win/tkWinX.c
index 7e25826..96a8720 100644
--- a/win/tkWinX.c
+++ b/win/tkWinX.c
@@ -911,15 +911,24 @@ Tk_TranslateWinEvent(
Tk_PointerEvent(hwnd, (short) LOWORD(lParam), (short) HIWORD(lParam));
return 1;
+ case WM_SYSKEYDOWN:
+ case WM_KEYDOWN:
+ if (wParam == VK_PACKET) {
+ /*
+ * This will trigger WM_CHAR event(s) with unicode data.
+ */
+ *resultPtr =
+ PostMessageW(hwnd, message, HIWORD(lParam), LOWORD(lParam));
+ return 1;
+ }
+ /* else fall through */
case WM_CLOSE:
case WM_SETFOCUS:
case WM_KILLFOCUS:
case WM_DESTROYCLIPBOARD:
case WM_UNICHAR:
case WM_CHAR:
- case WM_SYSKEYDOWN:
case WM_SYSKEYUP:
- case WM_KEYDOWN:
case WM_KEYUP:
case WM_MOUSEWHEEL:
GenerateXEvent(hwnd, message, wParam, lParam);
@@ -1197,17 +1206,50 @@ GenerateXEvent(
event.type = KeyPress;
event.xany.send_event = -1;
event.xkey.keycode = 0;
- event.xkey.nbytes = 1;
- event.xkey.trans_chars[0] = (char) wParam;
-
- if (IsDBCSLeadByte((BYTE) wParam)) {
+ if ((int)wParam & 0xff00) {
+ int i, ch1 = wParam & 0xffff;
+ char buffer[TCL_UTF_MAX+1];
+#if TCL_UTF_MAX >= 4
MSG msg;
- if ((PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) != 0)
+ if ((((int)wParam & 0xfc00) == 0xd800)
+ && (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) != 0)
&& (msg.message == WM_CHAR)) {
+ MSG msg;
+ int ch2;
+
GetMessage(&msg, NULL, 0, 0);
- event.xkey.nbytes = 2;
- event.xkey.trans_chars[1] = (char) msg.wParam;
+ ch2 = wParam & 0xffff;
+#if TCL_UTF_MAX == 4
+ event.xkey.nbytes = Tcl_UniCharToUtf(ch1, buffer);
+ event.xkey.nbytes += Tcl_UniCharToUtf(ch2, buffer);
+#else
+ ch1 = ((ch1 & 0x3ff) << 10) | (ch2 & 0x3ff);
+ ch1 += 0x10000;
+ event.xkey.nbytes = Tcl_UniCharToUtf(ch1, buffer);
+#endif
+ } else
+#endif
+ {
+ event.xkey.nbytes = Tcl_UniCharToUtf(ch1, buffer);
+ }
+ for (i=0; i<event.xkey.nbytes && i<TCL_UTF_MAX; ++i) {
+ event.xkey.trans_chars[i] = buffer[i];
+ }
+ event.xany.send_event = -3;
+ } else {
+ event.xkey.nbytes = 1;
+ event.xkey.trans_chars[0] = (char) wParam;
+
+ if (IsDBCSLeadByte((BYTE) wParam)) {
+ MSG msg;
+
+ if ((PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE) != 0)
+ && (msg.message == WM_CHAR)) {
+ GetMessage(&msg, NULL, 0, 0);
+ event.xkey.nbytes = 2;
+ event.xkey.trans_chars[1] = (char) msg.wParam;
+ }
}
}
Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL);
@@ -1217,10 +1259,27 @@ GenerateXEvent(
case WM_UNICHAR: {
char buffer[TCL_UTF_MAX+1];
int i;
+
event.type = KeyPress;
event.xany.send_event = -3;
event.xkey.keycode = wParam;
+#if TCL_UTF_MAX < 4
+ event.xkey.nbytes = Tcl_UniCharToUtf(((int)wParam > 0xffff) ?
+ 0xfffd : (int)wParam, buffer);
+#else
+#if TCL_UTF_MAX == 4
+ if ((int)wParam > 0xffff) {
+ Tcl_UniChar uch;
+
+ uch = (((int)wParam - 0x10000) >> 10) & 0x3ff;
+ event.xkey.nbytes = Tcl_UniCharToUtf(uch | 0xd800, buffer);
+ uch = ((int)wParam - 0x10000) & 0x3ff;
+ event.xkey.nbytes += Tcl_UniCharToUtf(uch | 0xdc00,
+ buffer + event.xkey.nbytes);
+ } else
+#endif
event.xkey.nbytes = Tcl_UniCharToUtf((int)wParam, buffer);
+#endif
for (i=0; i<event.xkey.nbytes && i<TCL_UTF_MAX; ++i) {
event.xkey.trans_chars[i] = buffer[i];
}