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 | 7d1b9612ad04e7e35d6443d6e9b0e4053b801427 (patch) | |
tree | 4545818b5ad8d03416d816ac2fc90c15e0f46320 /win/tkWinX.c | |
parent | d257de6d2ca3b8c1b8494276d2bdfd5ef137e7ba (diff) | |
parent | 34d8945d9d1dbbb3f599cabcad75ec0305f7615d (diff) | |
download | tk-7d1b9612ad04e7e35d6443d6e9b0e4053b801427.zip tk-7d1b9612ad04e7e35d6443d6e9b0e4053b801427.tar.gz tk-7d1b9612ad04e7e35d6443d6e9b0e4053b801427.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/tkWinX.c')
-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]; |