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 | |
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!
-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]; |