diff options
author | nijtmans@users.sourceforge.net <jan.nijtmans> | 2016-08-31 09:49:27 (GMT) |
---|---|---|
committer | nijtmans@users.sourceforge.net <jan.nijtmans> | 2016-08-31 09:49:27 (GMT) |
commit | 783fa49262686e95a08babb596e530d5adcc1a7f (patch) | |
tree | 4545818b5ad8d03416d816ac2fc90c15e0f46320 | |
parent | 95b2756be7d3c937cbc5e19ff1456ae374f5a75e (diff) | |
parent | 649734741310284cd216cab6a64f2d1e22a3c115 (diff) | |
download | tk-783fa49262686e95a08babb596e530d5adcc1a7f.zip tk-783fa49262686e95a08babb596e530d5adcc1a7f.tar.gz tk-783fa49262686e95a08babb596e530d5adcc1a7f.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!
-rw-r--r-- | generic/tkEntry.c | 3 | ||||
-rw-r--r-- | generic/tkText.c | 2 | ||||
-rw-r--r-- | generic/ttk/ttkEntry.c | 3 | ||||
-rw-r--r-- | tests/text.test | 44 | ||||
-rw-r--r-- | win/tkWinX.c | 58 |
5 files changed, 98 insertions, 12 deletions
diff --git a/generic/tkEntry.c b/generic/tkEntry.c index ea8d7f1..c0ce47b 100644 --- a/generic/tkEntry.c +++ b/generic/tkEntry.c @@ -1943,7 +1943,8 @@ EntryComputeGeometry( entryPtr->displayString = p; for (i = entryPtr->numChars; --i >= 0; ) { - p += Tcl_UniCharToUtf(ch, p); + memcpy(p, buf, size); + p += size; } *p = '\0'; } diff --git a/generic/tkText.c b/generic/tkText.c index 5ad527a..ab77d99 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -547,7 +547,7 @@ CreateWidget( Tcl_InitHashTable(&sharedPtr->windowTable, TCL_STRING_KEYS); Tcl_InitHashTable(&sharedPtr->imageTable, TCL_STRING_KEYS); sharedPtr->undoStack = TkUndoInitStack(interp,0); - sharedPtr->undo = 1; + sharedPtr->undo = 0; sharedPtr->isDirty = 0; sharedPtr->dirtyMode = TK_TEXT_DIRTY_NORMAL; sharedPtr->autoSeparators = 1; diff --git a/generic/ttk/ttkEntry.c b/generic/ttk/ttkEntry.c index f395649..533637d 100644 --- a/generic/ttk/ttkEntry.c +++ b/generic/ttk/ttkEntry.c @@ -290,7 +290,8 @@ static char *EntryDisplayString(const char *showChar, int numChars) p = displayString = ckalloc(numChars * size + 1); while (numChars--) { - p += Tcl_UniCharToUtf(ch, p); + memcpy(p, buf, size); + p += size; } *p = '\0'; diff --git a/tests/text.test b/tests/text.test index 720afbe..f640817 100644 --- a/tests/text.test +++ b/tests/text.test @@ -29,6 +29,15 @@ test text-1.1 {configuration option: "autoseparators"} -setup { } -cleanup { destroy .t } -result {1} +test text-1.1b {configuration option: "autoseparators", default} -setup { + text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold} + pack .t + update +} -body { + .t cget -autoseparators +} -cleanup { + destroy .t +} -result {1} test text-1.2 {configuration option: "autoseparators"} -setup { text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold} pack .t @@ -428,6 +437,15 @@ test text-1.43 {configuration option: "maxundo"} -setup { } -cleanup { destroy .t } -result {5} +test text-1.43b {configuration option: "maxundo", default} -setup { + text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold} + pack .t + update +} -body { + .t cget -maxundo +} -cleanup { + destroy .t +} -result {0} test text-1.44 {configuration option: "maxundo"} -setup { text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold} pack .t @@ -732,6 +750,15 @@ test text-1.75 {configuration option: "undo"} -setup { } -cleanup { destroy .t } -result {1} +test text-1.75b {configuration option: "undo", default} -setup { + text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold} + pack .t + update +} -body { + .t cget -undo +} -cleanup { + destroy .t +} -result {0} test text-1.76 {configuration option: "undo"} -setup { text .t -borderwidth 2 -highlightthickness 2 -font {Courier -12 bold} pack .t @@ -6396,8 +6423,23 @@ test text-27.16a {undo configuration options with peers} -body { lappend res [.t edit canundo] lappend res [.tt edit canundo] } -cleanup { - destroy .t + destroy .t .tt } -result {1 1 0 0 100 100 1 1} +test text-27.16b {undo configuration options with peers, defaults} -body { + text .t + .t peer create .tt + set res [.t cget -undo] + lappend res [.tt cget -undo] + lappend res [.t cget -autoseparators] + lappend res [.tt cget -autoseparators] + lappend res [.t cget -maxundo] + lappend res [.tt cget -maxundo] + .t insert end "The undo stack is common between peers" + lappend res [.t edit canundo] + lappend res [.tt edit canundo] +} -cleanup { + destroy .t .tt +} -result {0 0 1 1 0 0 0 0} test text-27.17 {bug fix 1536735 - undo with empty text} -body { text .t -undo 1 set r [.t edit modified] 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]; |