summaryrefslogtreecommitdiffstats
path: root/win/tkWinKey.c
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2016-08-30 10:24:09 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2016-08-30 10:24:09 (GMT)
commit8166b9bf7de9b6fa88032ae6539431560b86421d (patch)
tree47d25c98edc0c1c42f9831657c9fc60fa698055c /win/tkWinKey.c
parent4b0295c62375361b1fc27f4f3dbaaf60e4d7643c (diff)
downloadtk-8166b9bf7de9b6fa88032ae6539431560b86421d.zip
tk-8166b9bf7de9b6fa88032ae6539431560b86421d.tar.gz
tk-8166b9bf7de9b6fa88032ae6539431560b86421d.tar.bz2
Enhance TkpGetString() to handle Unicode characters, even when TCL_UTF_MAX==3.
Diffstat (limited to 'win/tkWinKey.c')
-rw-r--r--win/tkWinKey.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/win/tkWinKey.c b/win/tkWinKey.c
index ed546f7..a49898f 100644
--- a/win/tkWinKey.c
+++ b/win/tkWinKey.c
@@ -102,7 +102,7 @@ TkpGetString(
*/
int unichar;
- char buf[TCL_UTF_MAX];
+ char buf[XMaxTransChars];
int len;
unichar = keyEv->trans_chars[1] & 0xff;
@@ -115,10 +115,18 @@ TkpGetString(
} else if (keyEv->send_event == -3) {
/*
* Special case for WM_UNICHAR. xkey.trans_chars[] already contains a
- * UTF-8 char.
+ * UTF-8 char, except when nbytes == 0 (then it didn't fit there).
*/
- Tcl_DStringAppend(dsPtr, keyEv->trans_chars, keyEv->nbytes);
+ if (keyEv->nbytes) {
+ Tcl_DStringAppend(dsPtr, keyEv->trans_chars, keyEv->nbytes);
+ } else if (keyEv->keycode > 0xffff) {
+ char buf[XMaxTransChars];
+ Tcl_UniCharToUtf(((keyEv->keycode - 0x10000) >> 10) | 0xd800, buf);
+ Tcl_DStringAppend(dsPtr, buf, 3);
+ Tcl_UniCharToUtf(((keyEv->keycode - 0x10000) & 0x3ff) | 0xdc00, buf);
+ Tcl_DStringAppend(dsPtr, buf, 3);
+ }
} else {
/*
* This is an event generated from generic code. It has no nchars or
@@ -129,7 +137,7 @@ TkpGetString(
if (((keysym != NoSymbol) && (keysym > 0) && (keysym < 256))
|| (keysym == XK_Return) || (keysym == XK_Tab)) {
- char buf[TCL_UTF_MAX];
+ char buf[XMaxTransChars];
int len;
len = Tcl_UniCharToUtf((Tcl_UniChar) (keysym & 255), buf);