From 1e91aa73ce7aa59b5950e2a91443fdcdcba6ccaf Mon Sep 17 00:00:00 2001 From: fvogel Date: Tue, 5 Apr 2016 16:08:33 +0000 Subject: Fixed [fd3a4dc111] - <> event is not always sent to peers --- generic/tkText.c | 5 ++++- tests/text.test | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/generic/tkText.c b/generic/tkText.c index 506075d..e6cb96d 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -5215,7 +5215,10 @@ TextEditCmd( */ if ((!oldModified) != (!setModified)) { - GenerateModifiedEvent(textPtr); + for (textPtr = textPtr->sharedTextPtr->peers; textPtr != NULL; + textPtr = textPtr->next) { + GenerateModifiedEvent(textPtr); + } } break; case EDIT_REDO: diff --git a/tests/text.test b/tests/text.test index ff933a8..03b5ae3 100644 --- a/tests/text.test +++ b/tests/text.test @@ -6321,6 +6321,21 @@ test text-27.14 {<> virtual event - delete before Modified} -body { } -cleanup { destroy .t } -result {thing special} +test text-27.14a {<> virtual event - propagation to peers} -body { +# Bug [fd3a4dc111], <> event is not always sent to peers + set ::retval 0 + text .t -undo 1 + .t peer create .tt + pack .t .tt + bind .t <> {incr ::retval} + bind .tt <> {incr ::retval} + .t insert end "This increments ::retval once for each peer, i.e. twice." + .t edit modified 0 ; # shall increment twice as well, not just once + update idletasks + set ::retval +} -cleanup { + destroy .t .tt +} -result {4} test text-27.15 {<> virtual event} -body { set ::retval no_selection pack [text .t -undo 1] -- cgit v0.12 From 00604f72c60af9ed0748c955048a446f7e5f7b9c Mon Sep 17 00:00:00 2001 From: fvogel Date: Thu, 21 Apr 2016 22:03:01 +0000 Subject: Fixed [b362182e45] - Generation of virtual events through Tk_HandleEvent is unsafe --- generic/tkInt.h | 2 +- generic/tkListbox.c | 11 +---------- generic/tkText.c | 26 ++------------------------ generic/tkTextDisp.c | 17 ++++------------- generic/tkUtil.c | 9 +++++++-- macosx/tkMacOSXDialog.c | 8 ++++---- tests/listbox.test | 1 + tests/text.test | 6 +++++- win/tkWinDialog.c | 8 ++++---- 9 files changed, 29 insertions(+), 59 deletions(-) diff --git a/generic/tkInt.h b/generic/tkInt.h index b644c5b..029f0f1 100644 --- a/generic/tkInt.h +++ b/generic/tkInt.h @@ -1208,7 +1208,7 @@ MODULE_SCOPE void TkpCreateBusy(Tk_FakeWin *winPtr, Tk_Window tkRef, MODULE_SCOPE int TkBackgroundEvalObjv(Tcl_Interp *interp, int objc, Tcl_Obj *const *objv, int flags); MODULE_SCOPE void TkSendVirtualEvent(Tk_Window tgtWin, - const char *eventName); + const char *eventName, Tcl_Obj *detail); MODULE_SCOPE Tcl_Command TkMakeEnsemble(Tcl_Interp *interp, const char *nsname, const char *name, ClientData clientData, const TkEnsemble *map); diff --git a/generic/tkListbox.c b/generic/tkListbox.c index c7effdd..b059727 100644 --- a/generic/tkListbox.c +++ b/generic/tkListbox.c @@ -3223,16 +3223,7 @@ static void GenerateListboxSelectEvent( Listbox *listPtr) /* Information about widget. */ { - union {XEvent general; XVirtualEvent virtual;} event; - - memset(&event, 0, sizeof(event)); - event.general.xany.type = VirtualEvent; - event.general.xany.serial = NextRequest(Tk_Display(listPtr->tkwin)); - event.general.xany.send_event = False; - event.general.xany.window = Tk_WindowId(listPtr->tkwin); - event.general.xany.display = Tk_Display(listPtr->tkwin); - event.virtual.name = Tk_GetUid("ListboxSelect"); - Tk_HandleEvent(&event.general); + TkSendVirtualEvent(listPtr->tkwin, "ListboxSelect", NULL); } /* diff --git a/generic/tkText.c b/generic/tkText.c index 506075d..b17a425 100644 --- a/generic/tkText.c +++ b/generic/tkText.c @@ -3554,16 +3554,7 @@ TkTextSelectionEvent( * event generate $textWidget <> */ - union {XEvent general; XVirtualEvent virtual;} event; - - memset(&event, 0, sizeof(event)); - event.general.xany.type = VirtualEvent; - event.general.xany.serial = NextRequest(Tk_Display(textPtr->tkwin)); - event.general.xany.send_event = False; - event.general.xany.window = Tk_WindowId(textPtr->tkwin); - event.general.xany.display = Tk_Display(textPtr->tkwin); - event.virtual.name = Tk_GetUid("Selection"); - Tk_HandleEvent(&event.general); + TkSendVirtualEvent(textPtr->tkwin, "Selection", NULL); } /* @@ -5361,21 +5352,8 @@ static void GenerateModifiedEvent( TkText *textPtr) /* Information about text widget. */ { - union { - XEvent general; - XVirtualEvent virtual; - } event; - Tk_MakeWindowExist(textPtr->tkwin); - - memset(&event, 0, sizeof(event)); - event.general.xany.type = VirtualEvent; - event.general.xany.serial = NextRequest(Tk_Display(textPtr->tkwin)); - event.general.xany.send_event = False; - event.general.xany.window = Tk_WindowId(textPtr->tkwin); - event.general.xany.display = Tk_Display(textPtr->tkwin); - event.virtual.name = Tk_GetUid("Modified"); - Tk_HandleEvent(&event.general); + TkSendVirtualEvent(textPtr->tkwin, "Modified", NULL); } /* diff --git a/generic/tkTextDisp.c b/generic/tkTextDisp.c index 0849307..81bce94 100644 --- a/generic/tkTextDisp.c +++ b/generic/tkTextDisp.c @@ -3104,7 +3104,7 @@ AsyncUpdateLineMetrics( * Send the <> event related to the text widget * line metrics asynchronous update. * This is equivalent to: - * event generate $textWidget <> -detail $s + * event generate $textWidget <> -data $s * where $s is the sync status: true (when the widget view is in * sync with its internal data) or false (when it is not). * @@ -3120,19 +3120,10 @@ AsyncUpdateLineMetrics( static void GenerateWidgetViewSyncEvent( TkText *textPtr, /* Information about text widget. */ - Bool InSync) /* True if in sync, false otherwise */ + Bool InSync) /* true if in sync, false otherwise */ { - union {XEvent general; XVirtualEvent virtual;} event; - - memset(&event, 0, sizeof(event)); - event.general.xany.type = VirtualEvent; - event.general.xany.serial = NextRequest(Tk_Display(textPtr->tkwin)); - event.general.xany.send_event = False; - event.general.xany.window = Tk_WindowId(textPtr->tkwin); - event.general.xany.display = Tk_Display(textPtr->tkwin); - event.virtual.name = Tk_GetUid("WidgetViewSync"); - event.virtual.user_data = Tcl_NewBooleanObj(InSync); - Tk_HandleEvent(&event.general); + TkSendVirtualEvent(textPtr->tkwin, "WidgetViewSync", + Tcl_NewBooleanObj(InSync)); } /* diff --git a/generic/tkUtil.c b/generic/tkUtil.c index 7ff9ecb..6563165 100644 --- a/generic/tkUtil.c +++ b/generic/tkUtil.c @@ -1162,7 +1162,8 @@ TkMakeEnsemble( * TkSendVirtualEvent -- * * Send a virtual event notification to the specified target window. - * Equivalent to "event generate $target <<$eventName>>" + * Equivalent to: + * "event generate $target <<$eventName>> -data $detail" * * Note that we use Tk_QueueWindowEvent, not Tk_HandleEvent, so this * routine does not reenter the interpreter. @@ -1173,7 +1174,8 @@ TkMakeEnsemble( void TkSendVirtualEvent( Tk_Window target, - const char *eventName) + const char *eventName, + Tcl_Obj *detail) { union {XEvent general; XVirtualEvent virtual;} event; @@ -1184,6 +1186,9 @@ TkSendVirtualEvent( event.general.xany.window = Tk_WindowId(target); event.general.xany.display = Tk_Display(target); event.virtual.name = Tk_GetUid(eventName); + if (detail != NULL) { + event.virtual.user_data = detail; + } Tk_QueueWindowEvent(&event.general, TCL_QUEUE_TAIL); } diff --git a/macosx/tkMacOSXDialog.c b/macosx/tkMacOSXDialog.c index f6edb6d..80a7a11 100644 --- a/macosx/tkMacOSXDialog.c +++ b/macosx/tkMacOSXDialog.c @@ -1320,7 +1320,7 @@ FontchooserEvent( switch (kind) { case FontchooserClosed: if (fcdPtr->parent != None) { - TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserVisibility"); + TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserVisibility", NULL); fontchooserInterp = NULL; } break; @@ -1343,7 +1343,7 @@ FontchooserEvent( ckfree(tmpv); } } - TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserFontChanged"); + TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserFontChanged", NULL); } break; } @@ -1553,7 +1553,7 @@ FontchooserConfigureCmd( [fm setSelectedAttributes:fontPanelFontAttributes isMultiple:NO]; if ([fp isVisible]) { - TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserFontChanged"); + TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserFontChanged", NULL); } break; case FontchooserCmd: @@ -1616,7 +1616,7 @@ FontchooserShowCmd( } if (![fp isVisible]) { [fm orderFrontFontPanel:NSApp]; - TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserVisibility"); + TkSendVirtualEvent(fcdPtr->parent, "TkFontchooserVisibility", NULL); } fontchooserInterp = interp; diff --git a/tests/listbox.test b/tests/listbox.test index 76a4349..407420c 100644 --- a/tests/listbox.test +++ b/tests/listbox.test @@ -3170,6 +3170,7 @@ test listbox-31.2 {<> event on lost selection} -setup { focus -force .l event generate .l <1> -x 5 -y 5 ; # <> fires selection clear ; # <> fires again + update set res } -cleanup { destroy .l diff --git a/tests/text.test b/tests/text.test index a778b79..a500daf 100644 --- a/tests/text.test +++ b/tests/text.test @@ -6280,7 +6280,7 @@ test text-27.11 {TextEditCmd procedure, set modified flag repeat} -setup { # Shouldn't require [update idle] to trigger event [Bug 1809538] lappend ::retval [.t edit modified] .t edit modified 1 - update idletasks + update lappend ::retval [.t edit modified] .t edit modified 1 ; # binding should only fire once [Bug 1799782] update idletasks @@ -6295,6 +6295,7 @@ test text-27.12 {<> virtual event} -body { bind .t <> "set ::retval modified" update idletasks .t insert end "nothing special\n" + update return $::retval } -cleanup { destroy .t @@ -6305,6 +6306,7 @@ test text-27.13 {<> virtual event - insert before Modified} -body { bind .t <> { set ::retval [.t get 1.0 end-1c] } update idletasks .t insert end "nothing special" + update return $::retval } -cleanup { destroy .t @@ -6317,6 +6319,7 @@ test text-27.14 {<> virtual event - delete before Modified} -body { .t insert end "nothing special" .t edit modified 0 .t delete 1.0 1.2 + update set ::retval } -cleanup { destroy .t @@ -6328,6 +6331,7 @@ test text-27.15 {<> virtual event} -body { update idletasks .t insert end "nothing special\n" .t tag add sel 1.0 1.1 + update set ::retval } -cleanup { destroy .t diff --git a/win/tkWinDialog.c b/win/tkWinDialog.c index d7f63fb..d58bd52 100644 --- a/win/tkWinDialog.c +++ b/win/tkWinDialog.c @@ -3145,13 +3145,13 @@ HookProc( if (IsWindow(hwndCtrl)) { EnableWindow(hwndCtrl, FALSE); } - TkSendVirtualEvent(phd->parent, "TkFontchooserVisibility"); + TkSendVirtualEvent(phd->parent, "TkFontchooserVisibility", NULL); return 1; /* we handled the message */ } if (WM_DESTROY == msg) { phd->hwnd = NULL; - TkSendVirtualEvent(phd->parent, "TkFontchooserVisibility"); + TkSendVirtualEvent(phd->parent, "TkFontchooserVisibility", NULL); return 0; } @@ -3169,7 +3169,7 @@ HookProc( ApplyLogfont(phd->interp, phd->cmdObj, hdc, &lf); } if (phd && phd->parent) { - TkSendVirtualEvent(phd->parent, "TkFontchooserFontChanged"); + TkSendVirtualEvent(phd->parent, "TkFontchooserFontChanged", NULL); } return 1; } @@ -3481,7 +3481,7 @@ FontchooserShowCmd( ApplyLogfont(hdPtr->interp, hdPtr->cmdObj, hdc, &lf); } if (hdPtr->parent) { - TkSendVirtualEvent(hdPtr->parent, "TkFontchooserFontChanged"); + TkSendVirtualEvent(hdPtr->parent, "TkFontchooserFontChanged", NULL); } } Tcl_SetServiceMode(oldMode); -- cgit v0.12 From d9629dd3f036632bf29ca7792d85a0fd346e8cb9 Mon Sep 17 00:00:00 2001 From: fvogel Date: Fri, 22 Apr 2016 20:15:13 +0000 Subject: Added test text-11a.51 to check the fix of [b362182e45] --- tests/text.test | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/text.test b/tests/text.test index a500daf..4b27c76 100644 --- a/tests/text.test +++ b/tests/text.test @@ -3053,6 +3053,25 @@ test text-11a.41 {"sync" "pendingsync" and <>} -setup { destroy .top.yt .top } -result {Sync:0 Pending:1 Sync:1 Pending:0} +test text-11a.51 {<> calls TkSendVirtualEvent(), + NOT Tk_HandleEvent(). + Bug [b362182e45704dd7bbd6aed91e48122035ea3d16]} -setup { + destroy .top.t .top +} -body { + set res {} + toplevel .top + pack [text .top.t] + for {set i 1} {$i < 10000} {incr i} { + .top.t insert end "Hello world!\n" + } + bind .top.t <> {destroy .top.t} + .top.t tag add mytag 1.5 8000.8 ; # shall not crash + update + set res "Still doing fine!" +} -cleanup { + destroy .top.t .top +} -result {Still doing fine!} + test text-12.1 {TextWidgetCmd procedure, "index" option} -setup { text .t } -body { -- cgit v0.12 From fe445933c38a59e269197da7ad01187157358ab4 Mon Sep 17 00:00:00 2001 From: fvogel Date: Fri, 29 Apr 2016 19:07:53 +0000 Subject: Fixed [011706ec42] - tk::ButtonInvoke safety bug --- library/button.tcl | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/library/button.tcl b/library/button.tcl index b2bafb2..061069a 100644 --- a/library/button.tcl +++ b/library/button.tcl @@ -597,14 +597,16 @@ proc ::tk::ButtonUp w { # w - The name of the widget. proc ::tk::ButtonInvoke w { - if {[$w cget -state] ne "disabled"} { + if {[winfo exists $w] && [$w cget -state] ne "disabled"} { set oldRelief [$w cget -relief] set oldState [$w cget -state] $w configure -state active -relief sunken update idletasks after 100 - $w configure -state $oldState -relief $oldRelief - uplevel #0 [list $w invoke] + if {[winfo exists $w]} { + $w configure -state $oldState -relief $oldRelief + uplevel #0 [list $w invoke] + } } } -- cgit v0.12 From dd7c680bf0627dc809b4b205ad1258100deaa466 Mon Sep 17 00:00:00 2001 From: fvogel Date: Fri, 29 Apr 2016 19:23:56 +0000 Subject: Fixed indentation --- library/button.tcl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/button.tcl b/library/button.tcl index 061069a..16624e7 100644 --- a/library/button.tcl +++ b/library/button.tcl @@ -604,8 +604,8 @@ proc ::tk::ButtonInvoke w { update idletasks after 100 if {[winfo exists $w]} { - $w configure -state $oldState -relief $oldRelief - uplevel #0 [list $w invoke] + $w configure -state $oldState -relief $oldRelief + uplevel #0 [list $w invoke] } } } -- cgit v0.12 From acdaf387562f63cecd2e448c4790aa5e02bd89a9 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sat, 30 Apr 2016 15:50:35 +0000 Subject: Experiment: can it be done without a busy wait as well? Not tested on all platforms yet, feedback appreciated! --- library/button.tcl | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/library/button.tcl b/library/button.tcl index 16624e7..469a9a8 100644 --- a/library/button.tcl +++ b/library/button.tcl @@ -589,6 +589,20 @@ proc ::tk::ButtonUp w { # Shared routines ################## +# ::tk::ButtonInvokeEnd -- +# The procedure below is called after a button is invoked through +# the keyboard. It simulate a release of the button via the mouse. +# +# Arguments: +# w - The name of the widget. + +proc ::tk::ButtonInvokeEnd {w oldState oldRelief} { + if {[winfo exists $w]} { + $w configure -state $oldState -relief $oldRelief + uplevel #0 [list $w invoke] + } +} + # ::tk::ButtonInvoke -- # The procedure below is called when a button is invoked through # the keyboard. It simulate a press of the button via the mouse. @@ -601,12 +615,7 @@ proc ::tk::ButtonInvoke w { set oldRelief [$w cget -relief] set oldState [$w cget -state] $w configure -state active -relief sunken - update idletasks - after 100 - if {[winfo exists $w]} { - $w configure -state $oldState -relief $oldRelief - uplevel #0 [list $w invoke] - } + after 100 [list ::tk::ButtonInvokeEnd $w $oldState $oldRelief] } } -- cgit v0.12 From b1abab58282cc8ff89e73762114369e7a11ce07f Mon Sep 17 00:00:00 2001 From: fvogel Date: Mon, 2 May 2016 20:16:20 +0000 Subject: Fixed Americano-British English (American English selected) --- tests/button.test | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/button.test b/tests/button.test index 984fd43..6d924f6 100644 --- a/tests/button.test +++ b/tests/button.test @@ -3750,7 +3750,7 @@ test button-12.1 {button widget vs hidden commands} -body { destroy .b } -result {1} -test button-13.1 {size behaviouor: label} -setup { +test button-13.1 {size behavior: label} -setup { label .a -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold} label .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold} label .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold} @@ -3769,7 +3769,7 @@ test button-13.1 {size behaviouor: label} -setup { } -cleanup { destroy .a .b .c } -result {1 1 1} -test button-13.2 {size behaviouor: label} -setup { +test button-13.2 {size behavior: label} -setup { label .a -borderwidth 2 -highlightthickness 2 -font {Arial 20} label .b -borderwidth 2 -highlightthickness 2 -font {Arial 20} label .c -borderwidth 2 -highlightthickness 2 -font {Arial 20} @@ -3789,7 +3789,7 @@ test button-13.2 {size behaviouor: label} -setup { destroy .a .b .c } -result {1 1 1} -test button-13.3 {size behaviouor: button} -setup { +test button-13.3 {size behavior: button} -setup { button .a -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold} button .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold} button .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold} @@ -3808,7 +3808,7 @@ test button-13.3 {size behaviouor: button} -setup { } -cleanup { destroy .a .b .c } -result {1 1 1} -test button-13.4 {size behaviouor: button} -setup { +test button-13.4 {size behavior: button} -setup { button .a -borderwidth 2 -highlightthickness 2 -font {Arial 20} button .b -borderwidth 2 -highlightthickness 2 -font {Arial 20} button .c -borderwidth 2 -highlightthickness 2 -font {Arial 20} @@ -3828,7 +3828,7 @@ test button-13.4 {size behaviouor: button} -setup { destroy .a .b .c } -result {1 1 1} -test button-13.5 {size behaviouor: radiobutton} -setup { +test button-13.5 {size behavior: radiobutton} -setup { radiobutton .a -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold} radiobutton .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold} radiobutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold} @@ -3848,7 +3848,7 @@ test button-13.5 {size behaviouor: radiobutton} -setup { destroy .a .b .c } -result {1 1 1} -test button-13.6 {size behaviouor: radiobutton} -setup { +test button-13.6 {size behavior: radiobutton} -setup { radiobutton .a -borderwidth 2 -highlightthickness 2 -font {Arial 20} radiobutton .b -borderwidth 2 -highlightthickness 2 -font {Arial 20} radiobutton .c -borderwidth 2 -highlightthickness 2 -font {Arial 20} @@ -3868,7 +3868,7 @@ test button-13.6 {size behaviouor: radiobutton} -setup { destroy .a .b .c } -result {1 1 1} -test button-13.7 {size behaviouor: checkbutton} -setup { +test button-13.7 {size behavior: checkbutton} -setup { checkbutton .a -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold} checkbutton .b -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold} checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Helvetica -12 bold} @@ -3888,7 +3888,7 @@ test button-13.7 {size behaviouor: checkbutton} -setup { destroy .a .b .c } -result {1 1 1} -test button-13.8 {size behaviouor: checkbutton} -setup { +test button-13.8 {size behavior: checkbutton} -setup { checkbutton .a -borderwidth 2 -highlightthickness 2 -font {Arial 20} checkbutton .b -borderwidth 2 -highlightthickness 2 -font {Arial 20} checkbutton .c -borderwidth 2 -highlightthickness 2 -font {Arial 20} -- cgit v0.12 From 9685eae702c2d72291bb0b47e5ec481b9afa3a80 Mon Sep 17 00:00:00 2001 From: fvogel Date: Mon, 2 May 2016 20:45:41 +0000 Subject: Added test button-14.1 to guard against regressions regarding [011706ec42] --- tests/button.test | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/button.test b/tests/button.test index 6d924f6..05f463c 100644 --- a/tests/button.test +++ b/tests/button.test @@ -3908,6 +3908,25 @@ test button-13.8 {size behavior: checkbutton} -setup { destroy .a .b .c } -result {1 1 1} +test button-14.1 {bug fix: [011706ec42] tk::ButtonInvoke unsafe wrt widget destruction} -body { + proc destroy_button {} { + if {[winfo exists .top.b]} { + destroy .top.b + puts destroyed + } + } + toplevel .top + button .top.b -text Foo -command destroy_button + bind .top.b destroy_button + pack .top.b + focus -force .top.b + update + event generate .top.b + update ; # shall not trigger error invalid command name ".top.b" +} -cleanup { + destroy .top.b .top +} -result {} + imageFinish cleanupTests return -- cgit v0.12 From 7c0c67cd90b2ba56e2758e4859676b35a7c56025 Mon Sep 17 00:00:00 2001 From: fvogel Date: Tue, 10 May 2016 19:09:58 +0000 Subject: Fixed [545f10fcf3] - Poor Xft coloured font performance on X11. Thanks to James Bonfield for the bug report, to Rob Davies for the patch, and to Brian Griffin for the testing --- unix/tkUnixRFont.c | 150 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 106 insertions(+), 44 deletions(-) diff --git a/unix/tkUnixRFont.c b/unix/tkUnixRFont.c index ab2ed4a..36e5462 100644 --- a/unix/tkUnixRFont.c +++ b/unix/tkUnixRFont.c @@ -14,6 +14,8 @@ #include #include +#define MAX_CACHED_COLORS 16 + typedef struct { XftFont *ftFont; XftFont *ft0Font; @@ -23,6 +25,11 @@ typedef struct { } UnixFtFace; typedef struct { + XftColor color; + int next; +} UnixFtColorList; + +typedef struct { TkFont font; /* Stuff used by generic font package. Must be * first in structure. */ UnixFtFace *faces; @@ -33,7 +40,9 @@ typedef struct { Display *display; int screen; XftDraw *ftDraw; - XftColor color; + int ncolors; + int firstColor; + UnixFtColorList colors[MAX_CACHED_COLORS]; } UnixFtFont; /* @@ -289,11 +298,8 @@ InitFont( fontPtr->display = Tk_Display(tkwin); fontPtr->screen = Tk_ScreenNumber(tkwin); fontPtr->ftDraw = 0; - fontPtr->color.color.red = 0; - fontPtr->color.color.green = 0; - fontPtr->color.color.blue = 0; - fontPtr->color.color.alpha = 0xffff; - fontPtr->color.pixel = 0xffffffff; + fontPtr->ncolors = 0; + fontPtr->firstColor = -1; /* * Fill in platform-specific fields of TkFont. @@ -737,6 +743,89 @@ TkpMeasureCharsInContext( maxLength, flags, lengthPtr); } +/* + *---------------------------------------------------------------------- + * + * LookUpColor -- + * + * Convert a pixel value to an XftColor. This can be slow due to the + * need to call XQueryColor, which involves a server round-trip. To + * avoid that, a least-recently-used cache of up to MAX_CACHED_COLORS + * is kept, in the form of a linked list. The returned color is moved + * to the front of the list, so repeatedly asking for the same one + * should be fast. + * + * Results: + * A pointer to the XftColor structure for the requested color is + * returned. + * + * Side effects: + * The converted color is stored in a cache in the UnixFtFont structure. The cache + * can hold at most MAX_CACHED_COLORS colors. If no more slots are available, the least + * recently used color is replaced with the new one. + *---------------------------------------------------------------------- + */ + +static XftColor * +LookUpColor(Display *display, /* Display to lookup colors on */ + UnixFtFont *fontPtr, /* Font to search for cached colors */ + unsigned long pixel) /* Pixel value to translate to XftColor */ +{ + int i, last = -1, last2 = -1; + XColor xcolor; + + for (i = fontPtr->firstColor; + i >= 0; last2 = last, last = i, i = fontPtr->colors[i].next) { + + if (pixel == fontPtr->colors[i].color.pixel) { + /* + * Color found in cache. Move it to the front of the list and return it. + */ + if (last >= 0) { + fontPtr->colors[last].next = fontPtr->colors[i].next; + fontPtr->colors[i].next = fontPtr->firstColor; + fontPtr->firstColor = i; + } + + return &fontPtr->colors[i].color; + } + } + + /* + * Color wasn't found, so it needs to be added to the cache. + * If a spare slot is available, it can be put there. If not, last + * will now point to the least recently used color, so replace that one. + */ + + if (fontPtr->ncolors < MAX_CACHED_COLORS) { + last2 = -1; + last = fontPtr->ncolors++; + } + + /* + * Translate the pixel value to a color. Needs a server round-trip. + */ + xcolor.pixel = pixel; + XQueryColor(display, DefaultColormap(display, fontPtr->screen), &xcolor); + + fontPtr->colors[last].color.color.red = xcolor.red; + fontPtr->colors[last].color.color.green = xcolor.green; + fontPtr->colors[last].color.color.blue = xcolor.blue; + fontPtr->colors[last].color.color.alpha = 0xffff; + fontPtr->colors[last].color.pixel = pixel; + + /* + * Put at the front of the list. + */ + if (last2 >= 0) { + fontPtr->colors[last2].next = fontPtr->colors[last].next; + } + fontPtr->colors[last].next = fontPtr->firstColor; + fontPtr->firstColor = last; + + return &fontPtr->colors[last].color; +} + #define NUM_SPEC 1024 void @@ -760,7 +849,7 @@ Tk_DrawChars( const int maxCoord = 0x7FFF;/* Xft coordinates are 16 bit values */ UnixFtFont *fontPtr = (UnixFtFont *) tkfont; XGCValues values; - XColor xcolor; + XftColor *xftcolor; int clen, nspec, xStart = x; XftGlyphFontSpec specs[NUM_SPEC]; XGlyphInfo metrics; @@ -782,16 +871,7 @@ Tk_DrawChars( Tk_DeleteErrorHandler(handler); } XGetGCValues(display, gc, GCForeground, &values); - if (values.foreground != fontPtr->color.pixel) { - xcolor.pixel = values.foreground; - XQueryColor(display, DefaultColormap(display, fontPtr->screen), - &xcolor); - fontPtr->color.color.red = xcolor.red; - fontPtr->color.color.green = xcolor.green; - fontPtr->color.color.blue = xcolor.blue; - fontPtr->color.color.alpha = 0xffff; - fontPtr->color.pixel = values.foreground; - } + xftcolor = LookUpColor(display, fontPtr, values.foreground); if (tsdPtr->clipRegion != None) { XftDrawSetClip(fontPtr->ftDraw, tsdPtr->clipRegion); } @@ -823,14 +903,14 @@ Tk_DrawChars( y += metrics.yOff; nspec++; if (nspec == NUM_SPEC) { - XftDrawGlyphFontSpec(fontPtr->ftDraw, &fontPtr->color, + XftDrawGlyphFontSpec(fontPtr->ftDraw, xftcolor, specs, nspec); nspec = 0; } } } if (nspec) { - XftDrawGlyphFontSpec(fontPtr->ftDraw, &fontPtr->color, specs, nspec); + XftDrawGlyphFontSpec(fontPtr->ftDraw, xftcolor, specs, nspec); } doUnderlineStrikeout: @@ -892,7 +972,7 @@ TkDrawAngledChars( const int minCoord = -1000; /* Should be good enough... */ UnixFtFont *fontPtr = (UnixFtFont *) tkfont; XGCValues values; - XColor xcolor; + XftColor *xftcolor; int xStart = x, yStart = y; ThreadSpecificData *tsdPtr = (ThreadSpecificData *) Tcl_GetThreadData(&dataKey, sizeof(ThreadSpecificData)); @@ -919,16 +999,7 @@ TkDrawAngledChars( } XGetGCValues(display, gc, GCForeground, &values); - if (values.foreground != fontPtr->color.pixel) { - xcolor.pixel = values.foreground; - XQueryColor(display, DefaultColormap(display, fontPtr->screen), - &xcolor); - fontPtr->color.color.red = xcolor.red; - fontPtr->color.color.green = xcolor.green; - fontPtr->color.color.blue = xcolor.blue; - fontPtr->color.color.alpha = 0xffff; - fontPtr->color.pixel = values.foreground; - } + xftcolor = LookUpColor(display, fontPtr, values.foreground); if (tsdPtr->clipRegion != None) { XftDrawSetClip(fontPtr->ftDraw, tsdPtr->clipRegion); } @@ -967,7 +1038,7 @@ TkDrawAngledChars( * this information... but we'll be ready when it does! */ - XftDrawGlyphs(fontPtr->ftDraw, &fontPtr->color, currentFtFont, + XftDrawGlyphs(fontPtr->ftDraw, xftcolor, currentFtFont, originX, originY, glyphs, nglyph); } originX = ROUND16(x); @@ -984,7 +1055,7 @@ TkDrawAngledChars( glyphs[nglyph++] = XftCharIndex(fontPtr->display, ftFont, c); } if (nglyph) { - XftDrawGlyphs(fontPtr->ftDraw, &fontPtr->color, currentFtFont, + XftDrawGlyphs(fontPtr->ftDraw, xftcolor, currentFtFont, originX, originY, glyphs, nglyph); } #else /* !XFT_HAS_FIXED_ROTATED_PLACEMENT */ @@ -1008,16 +1079,7 @@ TkDrawAngledChars( Tk_DeleteErrorHandler(handler); } XGetGCValues(display, gc, GCForeground, &values); - if (values.foreground != fontPtr->color.pixel) { - xcolor.pixel = values.foreground; - XQueryColor(display, DefaultColormap(display, fontPtr->screen), - &xcolor); - fontPtr->color.color.red = xcolor.red; - fontPtr->color.color.green = xcolor.green; - fontPtr->color.color.blue = xcolor.blue; - fontPtr->color.color.alpha = 0xffff; - fontPtr->color.pixel = values.foreground; - } + xftcolor = LookUpColor(display, fontPtr, values.foreground); if (tsdPtr->clipRegion != None) { XftDrawSetClip(fontPtr->ftDraw, tsdPtr->clipRegion); } @@ -1051,14 +1113,14 @@ TkDrawAngledChars( y += metrics.yOff*cosA - metrics.xOff*sinA; nspec++; if (nspec == NUM_SPEC) { - XftDrawGlyphFontSpec(fontPtr->ftDraw, &fontPtr->color, + XftDrawGlyphFontSpec(fontPtr->ftDraw, xftcolor, specs, nspec); nspec = 0; } } } if (nspec) { - XftDrawGlyphFontSpec(fontPtr->ftDraw, &fontPtr->color, specs, nspec); + XftDrawGlyphFontSpec(fontPtr->ftDraw, xftcolor, specs, nspec); } #endif /* XFT_HAS_FIXED_ROTATED_PLACEMENT */ -- cgit v0.12 From fbfb7ab3f964d449a7dd80957998c23fe8c49117 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Thu, 12 May 2016 09:46:57 +0000 Subject: (cherry-pick): Bug [64261b50]. Spurious mouse events sent to underlying window when file dialog is closed. --- win/tkWinDialog.c | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/win/tkWinDialog.c b/win/tkWinDialog.c index d58bd52..a7d8c7d 100644 --- a/win/tkWinDialog.c +++ b/win/tkWinDialog.c @@ -674,19 +674,25 @@ static void LoadShellProcs() * processing functions are used to cope with keyboard navigation of * controls.) * - * Here is one solution. After returning, we poll the message queue for - * 1/4s looking for WM_LBUTTON up messages. If we see one it's consumed. - * If we get a WM_LBUTTONDOWN message, then we exit early, since the user - * must be doing something new. This fix only works for the current - * application, so the problem will still occur if the open dialog - * happens to be over another applications button. However this is a - * fairly rare occurrance. + * Here is one solution. After returning, we flush all mouse events + * for 1/4 second. In 8.6.5 and earlier, the code used to + * poll the message queue consuming WM_LBUTTONUP messages. + * On seeing a WM_LBUTTONDOWN message, it would exit early, since the user + * must be doing something new. However this early exit does not work + * on Vista and later because the Windows sends both BUTTONDOWN and + * BUTTONUP after the DBLCLICK instead of just BUTTONUP as on XP. + * Rather than try and figure out version specific sequences, we + * ignore all mouse events in that interval. + * + * This fix only works for the current application, so the problem will + * still occur if the open dialog happens to be over another applications + * button. However this is a fairly rare occurrance. * * Results: * None. * * Side effects: - * Consumes an unwanted BUTTON messages. + * Consumes unwanted mouse related messages. * *------------------------------------------------------------------------- */ @@ -698,10 +704,7 @@ EatSpuriousMessageBugFix(void) DWORD nTime = GetTickCount() + 250; while (GetTickCount() < nTime) { - if (PeekMessageA(&msg, 0, WM_LBUTTONDOWN, WM_LBUTTONDOWN, PM_NOREMOVE)){ - break; - } - PeekMessageA(&msg, 0, WM_LBUTTONUP, WM_LBUTTONUP, PM_REMOVE); + PeekMessage(&msg, 0, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE); } } @@ -1113,7 +1116,7 @@ ParseOFNOptions( if (strcmp(Tcl_GetString(objv[i]), "-xpstyle")) goto error_return; if (i + 1 == objc) { - Tcl_SetResult(interp, "value for \"-xpstyle\" missing", TCL_STATIC); + Tcl_SetObjResult(interp, Tcl_NewStringObj("value for \"-xpstyle\" missing", -1)); Tcl_SetErrorCode(interp, "TK", "FILEDIALOG", "VALUE", NULL); goto error_return; } @@ -1281,9 +1284,8 @@ static int GetFileNameVista(Tcl_Interp *interp, OFNOpts *optsPtr, int oldMode; if (tsdPtr->newFileDialogsState != FDLG_STATE_USE_NEW) { - /* XXX - should be an assert but Tcl does not seem to have one? */ - Tcl_SetResult(interp, "Internal error: GetFileNameVista: IFileDialog API not available", TCL_STATIC); - return TCL_ERROR; + Tcl_Panic("Internal error: GetFileNameVista: IFileDialog API not available"); + return TCL_ERROR; } /* @@ -1425,6 +1427,7 @@ static int GetFileNameVista(Tcl_Interp *interp, OFNOpts *optsPtr, oldMode = Tcl_SetServiceMode(TCL_SERVICE_ALL); hr = fdlgIf->lpVtbl->Show(fdlgIf, hWnd); Tcl_SetServiceMode(oldMode); + EatSpuriousMessageBugFix(); /* * Ensure that hWnd is enabled, because it can happen that we have updated -- cgit v0.12 From ac52dfb290b2def674a44dcdd9d2a5744f435ba8 Mon Sep 17 00:00:00 2001 From: fvogel Date: Tue, 17 May 2016 20:36:00 +0000 Subject: Added (currently failing) test case scrollbar-11.1 - Note that it will only fail on x11 and on aqua, not on Win because on Windows there is no binding of <2> for the Scrollbar class --- tests/scrollbar.test | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/scrollbar.test b/tests/scrollbar.test index 3b16821..8f967ea 100644 --- a/tests/scrollbar.test +++ b/tests/scrollbar.test @@ -662,6 +662,24 @@ test scrollbar-10.2 { event on scrollbar} -constraints {win|unix} -s destroy .t .s } -result {1.4} +test scrollbar-11.1 {bug fix: [011706ec42] Scrollbar unsafe wrt widget destruction} -body { + proc destroy_scrollbar {} { + if {[winfo exists .top.s]} { + destroy .top.s + } + } + toplevel .top + scrollbar .top.s -command destroy_scrollbar + bind .top.s <2> destroy_scrollbar + pack .top.s + focus -force .top.s + update + event generate .top.s <2> + update ; # shall not trigger error invalid command name ".top.s" +} -cleanup { + destroy .top.s .top +} -result {} + catch {destroy .s} catch {destroy .t} -- cgit v0.12 From 51c67e374ef37b064bf13cda750744eb7b0d41fc Mon Sep 17 00:00:00 2001 From: Kevin Walzer Date: Wed, 18 May 2016 02:26:41 +0000 Subject: Tweak to allow Tk to build on 10.5; thanks to Marc Culler for patch --- macosx/tkMacOSXNotify.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/macosx/tkMacOSXNotify.c b/macosx/tkMacOSXNotify.c index 1455688..f14e1b8 100644 --- a/macosx/tkMacOSXNotify.c +++ b/macosx/tkMacOSXNotify.c @@ -270,10 +270,15 @@ TkMacOSXEventsCheckProc( inMode:GetRunLoopMode(modalSession) dequeue:NO]; /* We must not steal any events during LiveResize. */ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060 if (testEvent && [[testEvent window] inLiveResize]) { break; } - +#else + if (testEvent && [[[testEvent window] contentView] inLiveResize]) { + break; + } +#endif currentEvent = [NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[NSDate distantPast] inMode:GetRunLoopMode(modalSession) -- cgit v0.12 From 1c0858ce27408d641e6b3bb8f66e9b59cf630014 Mon Sep 17 00:00:00 2001 From: fvogel Date: Wed, 18 May 2016 10:14:33 +0000 Subject: Fixed [011706ec42] for the scrollbar case. --- library/scrlbar.tcl | 11 ++++++++--- tests/scrollbar.test | 23 +++++++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/library/scrlbar.tcl b/library/scrlbar.tcl index b7be014..6f1caa2 100644 --- a/library/scrlbar.tcl +++ b/library/scrlbar.tcl @@ -430,6 +430,9 @@ proc ::tk::ScrollTopBottom {w x y} { proc ::tk::ScrollButton2Down {w x y} { variable ::tk::Priv + if {![winfo exists $w]} { + return + } set element [$w identify $x $y] if {[string match {arrow[12]} $element]} { ScrollButtonDown $w $x $y @@ -443,7 +446,9 @@ proc ::tk::ScrollButton2Down {w x y} { # slider drag. update idletasks - $w configure -activerelief sunken - $w activate slider - ScrollStartDrag $w $x $y + if {[winfo exists $w]} { + $w configure -activerelief sunken + $w activate slider + ScrollStartDrag $w $x $y + } } diff --git a/tests/scrollbar.test b/tests/scrollbar.test index 8f967ea..bd14067 100644 --- a/tests/scrollbar.test +++ b/tests/scrollbar.test @@ -669,8 +669,8 @@ test scrollbar-11.1 {bug fix: [011706ec42] Scrollbar unsafe wrt widget destructi } } toplevel .top - scrollbar .top.s -command destroy_scrollbar - bind .top.s <2> destroy_scrollbar + scrollbar .top.s + bind .top.s <2> {destroy_scrollbar} pack .top.s focus -force .top.s update @@ -679,6 +679,25 @@ test scrollbar-11.1 {bug fix: [011706ec42] Scrollbar unsafe wrt widget destructi } -cleanup { destroy .top.s .top } -result {} +test scrollbar-11.2 {bug fix: [011706ec42] Scrollbar unsafe wrt widget destruction} -body { + proc destroy_scrollbar {{y 0}} { + if {[winfo exists .top.s]} { + destroy .top.s + } + } + toplevel .top + wm minsize .top 50 400 + update + scrollbar .top.s + bind .top.s <2> {after idle destroy_scrollbar} + pack .top.s -expand true -fill y + focus -force .top.s + update + event generate .top.s <2> -x 2 -y [expr {[winfo height .top.s] / 2}] + update ; # shall not trigger error invalid command name ".top.s" +} -cleanup { + destroy .top.s .top +} -result {} catch {destroy .s} catch {destroy .t} -- cgit v0.12