diff options
author | jan.nijtmans <nijtmans@users.sourceforge.net> | 2016-08-31 09:49:27 (GMT) |
---|---|---|
committer | jan.nijtmans <nijtmans@users.sourceforge.net> | 2016-08-31 09:49:27 (GMT) |
commit | 52fcc0939f7809c3234212ef5fdff0359767d4f7 (patch) | |
tree | 4545818b5ad8d03416d816ac2fc90c15e0f46320 /win | |
parent | 8166b9bf7de9b6fa88032ae6539431560b86421d (diff) | |
parent | ea6b35b21034a7ccfb568ab20f1c850b5619b8a7 (diff) | |
download | tk-52fcc0939f7809c3234212ef5fdff0359767d4f7.zip tk-52fcc0939f7809c3234212ef5fdff0359767d4f7.tar.gz tk-52fcc0939f7809c3234212ef5fdff0359767d4f7.tar.bz2 |
Implement USE_EXTRA_EVENTS=1, which generates additional events for surrogate pairs when TCL_USF_MAX==3. Since the information in trans_chars is redundant (same as keycode), I don't believe this is better. Test-cases to prove otherwise welcome!
Diffstat (limited to 'win')
-rw-r--r-- | win/tkWinX.c | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/win/tkWinX.c b/win/tkWinX.c index 6b8bdff..f4908e0 100644 --- a/win/tkWinX.c +++ b/win/tkWinX.c @@ -29,6 +29,8 @@ # pragma comment (lib, "advapi32.lib") #endif +#define USE_EXTRA_EVENTS 0 /* Set this to 1 if you want to generate + additional events for surrogates */ /* * The zmouse.h file includes the definition for WM_MOUSEWHEEL. */ @@ -914,7 +916,7 @@ Tk_TranslateWinEvent( case WM_SYSKEYDOWN: case WM_KEYDOWN: - if (wParam == VK_PACKET) { + if (wParam == VK_PACKET) { /* * This will trigger WM_CHAR event(s) with unicode data. */ @@ -1217,15 +1219,35 @@ GenerateXEvent( } if ((ch1 & 0xfc00) == 0xdc00) { ch1 = ((tsdPtr->surrogateBuffer & 0x3ff) << 10) | - (ch1 & 0x3ff); - ch1 += 0x10000; + (ch1 & 0x3ff) | 0x10000; tsdPtr->surrogateBuffer = 0; } + event.xany.send_event = -3; event.xkey.nbytes = Tcl_UniCharToUtf(ch1, buffer); - for (i=0; i<event.xkey.nbytes && i<XMaxTransChars; ++i) { - event.xkey.trans_chars[i] = buffer[i]; + if ((ch1 <= 0xffff) || (event.xkey.nbytes == XMaxTransChars)) { + for (i=0; i<event.xkey.nbytes && i<XMaxTransChars; ++i) { + event.xkey.trans_chars[i] = buffer[i]; + } + } else { +#ifdef USE_EXTRA_EVENTS + event.xkey.keycode = ((int)(ch1 - 0x10000)>>10) | 0xd800; + event.xkey.nbytes = Tcl_UniCharToUtf(event.xkey.keycode, buffer); + for (i=0; i<event.xkey.nbytes && i<XMaxTransChars; ++i) { + event.xkey.trans_chars[i] = buffer[i]; + } + Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); + event.type = KeyRelease; + Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); + event.type = KeyPress; + event.xkey.keycode = ((int)(ch1 - 0x10000)&0x3ff) | 0xdc00; + event.xkey.nbytes = Tcl_UniCharToUtf(event.xkey.keycode, buffer); + for (i=0; i<event.xkey.nbytes && i<XMaxTransChars; ++i) { + event.xkey.trans_chars[i] = buffer[i]; + } +#else + event.xkey.nbytes = 0; +#endif } - event.xany.send_event = -3; } else { event.xkey.nbytes = 1; event.xkey.trans_chars[0] = (char) wParam; @@ -1252,10 +1274,30 @@ GenerateXEvent( event.xany.send_event = -3; event.xkey.keycode = wParam; event.xkey.nbytes = Tcl_UniCharToUtf((int)wParam, buffer); - if(((int)wParam > 0xffff) && (event.xkey.nbytes < 4)) { + if(((int)wParam > 0xffff) && (event.xkey.nbytes < XMaxTransChars)) { +#if USE_EXTRA_EVENTS /* trans_chars buffer is not big enough to hold 2 surrogate - characters, so don't store anything */ + characters, so split it in two separate events */ + + event.xkey.keycode = ((int)(wParam - 0x10000)>>10) | 0xd800; + event.xkey.nbytes = Tcl_UniCharToUtf(event.xkey.keycode, buffer); + for (i=0; i<event.xkey.nbytes && i<XMaxTransChars; ++i) { + event.xkey.trans_chars[i] = buffer[i]; + } + Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); + event.type = KeyRelease; + Tk_QueueWindowEvent(&event, TCL_QUEUE_TAIL); + event.type = KeyPress; + event.xkey.keycode = ((int)(wParam - 0x10000)&0x3ff) | 0xdc00; + event.xkey.nbytes = Tcl_UniCharToUtf(event.xkey.keycode, buffer); + for (i=0; i<event.xkey.nbytes && i<XMaxTransChars; ++i) { + event.xkey.trans_chars[i] = buffer[i]; + } +#else + /* trans_chars buffer is not big enough to hold 2 surrogate + characters, so don't store anything redundant anyway. */ event.xkey.nbytes = 0; +#endif } else { for (i=0; i<event.xkey.nbytes && i<XMaxTransChars; ++i) { event.xkey.trans_chars[i] = buffer[i]; |