From 5b17775ceec76475fc09958fe95ea3463bf0d4a0 Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Mon, 1 Jan 2024 23:37:20 +0000 Subject: Keep menu.tcl/tearoff.tcl more in sync with 8.7 --- library/menu.tcl | 33 +++++++++++++++++++-------------- library/tearoff.tcl | 12 ++++++------ 2 files changed, 25 insertions(+), 20 deletions(-) diff --git a/library/menu.tcl b/library/menu.tcl index c334fd9..1fb6e78 100644 --- a/library/menu.tcl +++ b/library/menu.tcl @@ -488,6 +488,7 @@ proc ::tk::MenuMotion {menu x y state} { set index [$menu index @$x,$y] if {[info exists Priv(menuActivated)] \ && $index ne "none" \ + && $index >= 0 \ && $index ne $activeindex} { set mode [option get $menu clickToFocus ClickToFocus] if {[string is false $mode]} { @@ -529,7 +530,8 @@ proc ::tk::MenuButtonDown menu { if {![winfo viewable $menu]} { return } - if {[$menu index active] eq "none"} { + set activeindex [$menu index active] + if {($activeindex eq "none") || ($activeindex < 0)} { if {[$menu cget -type] ne "menubar" } { set Priv(window) {} } @@ -587,7 +589,8 @@ proc ::tk::MenuButtonDown menu { proc ::tk::MenuLeave {menu rootx rooty state} { variable ::tk::Priv set Priv(window) {} - if {[$menu index active] eq "none"} { + set activeindex [$menu index active] + if {($activeindex eq "none") || ($activeindex < 0)} { return } if {[$menu type active] eq "cascade" \ @@ -632,8 +635,8 @@ proc ::tk::MenuInvoke {w buttonRelease} { MenuUnpost $w } elseif {[$w cget -type] eq "menubar"} { $w postcascade none - set active [$w index active] - set isCascade [string equal [$w type $active] "cascade"] + set activeindex [$w index active] + set isCascade [string equal [$w type $activeindex] "cascade"] # Only de-activate the active item if it's a cascade; this prevents # the annoying "activation flicker" you otherwise get with @@ -651,11 +654,11 @@ proc ::tk::MenuInvoke {w buttonRelease} { # but not recommended) if { !$isCascade } { - uplevel #0 [list $w invoke $active] + uplevel #0 [list $w invoke $activeindex] } } else { - set active [$w index active] - if {$Priv(popup) eq "" || $active ne "none"} { + set activeindex [$w index active] + if {$Priv(popup) eq "" || (($activeindex ne "none") && ($activeindex >= 0)} { MenuUnpost $w } uplevel #0 [list $w invoke active] @@ -799,7 +802,8 @@ proc ::tk::MenuNextMenu {menu direction} { if {[winfo class $mb] eq "Menubutton" \ && [$mb cget -state] ne "disabled" \ && [$mb cget -menu] ne "" \ - && [[$mb cget -menu] index last] ne "none"} { + && [[$mb cget -menu] index last] ne "none" \ + && [[$mb cget -menu] index last] >= 0} { break } if {$mb eq $w} { @@ -822,16 +826,16 @@ proc ::tk::MenuNextMenu {menu direction} { proc ::tk::MenuNextEntry {menu count} { set last [$menu index last] - if {$last eq "none"} { + if {($last eq "none") || ($last < 0)} { return } set length [expr {$last+1}] set quitAfter $length - set active [$menu index active] - if {$active eq "none"} { + set activeindex [$menu index active] + if {($activeindex eq "none") || ($activeindex < 0)} { set i 0 } else { - set i [expr {$active + $count}] + set i [expr {$activeindex + $count}] } while {1} { if {$quitAfter <= 0} { @@ -853,7 +857,7 @@ proc ::tk::MenuNextEntry {menu count} { break } } - if {$i == $active} { + if {$i == $activeindex} { return } incr i $count @@ -1070,7 +1074,8 @@ proc ::tk::MenuFirstEntry menu { return } tk_menuSetFocus $menu - if {[$menu index active] ne "none"} { + set activeindex [$menu index active] + if {($activeindex ne "none") && ($activeindex >= 0)} { return } set last [$menu index last] diff --git a/library/tearoff.tcl b/library/tearoff.tcl index 1dbe858..3a63b17 100644 --- a/library/tearoff.tcl +++ b/library/tearoff.tcl @@ -31,10 +31,10 @@ proc ::tk::TearOffMenu {w {x 0} {y 0}} { # away when the toplevel goes away. if {$x == 0} { - set x [winfo rootx $w] + set x [winfo rootx $w] } if {$y == 0} { - set y [winfo rooty $w] + set y [winfo rooty $w] if {[tk windowingsystem] eq "aqua"} { # Shift by height of tearoff entry minus height of window titlebar catch {incr y [expr {[$w yposition 1] - 16}]} @@ -66,14 +66,14 @@ proc ::tk::TearOffMenu {w {x 0} {y 0}} { set parent [winfo parent $w] if {[$menu cget -title] ne ""} { - wm title $menu [$menu cget -title] + wm title $menu [$menu cget -title] } else { - switch -- [winfo class $parent] { + switch -- [winfo class $parent] { Menubutton { - wm title $menu [$parent cget -text] + wm title $menu [$parent cget -text] } Menu { - wm title $menu [$parent entrycget active -label] + wm title $menu [$parent entrycget active -label] } } } -- cgit v0.12