|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace eval ttk { |
|
namespace eval menubutton { |
|
variable State |
|
array set State { |
|
pulldown 0 |
|
oldcursor {} |
|
} |
|
} |
|
} |
|
|
|
bind TMenubutton <Enter> { %W instate !disabled {%W state active } } |
|
bind TMenubutton <Leave> { %W state !active } |
|
bind TMenubutton <Key-space> { ttk::menubutton::Popdown %W } |
|
bind TMenubutton <<Invoke>> { ttk::menubutton::Popdown %W } |
|
|
|
if {[tk windowingsystem] eq "x11"} { |
|
bind TMenubutton <ButtonPress-1> { ttk::menubutton::Pulldown %W } |
|
bind TMenubutton <ButtonRelease-1> { ttk::menubutton::TransferGrab %W } |
|
bind TMenubutton <B1-Leave> { ttk::menubutton::TransferGrab %W } |
|
} else { |
|
bind TMenubutton <ButtonPress-1> \ |
|
{ %W state pressed ; ttk::menubutton::Popdown %W } |
|
bind TMenubutton <ButtonRelease-1> \ |
|
{ if {[winfo exists %W]} { %W state !pressed } } |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::menubutton::PostPosition {mb menu} { |
|
set x [winfo rootx $mb] |
|
set y [winfo rooty $mb] |
|
set dir [$mb cget -direction] |
|
|
|
set bw [winfo width $mb] |
|
set bh [winfo height $mb] |
|
set mw [winfo reqwidth $menu] |
|
set mh [winfo reqheight $menu] |
|
set sw [expr {[winfo screenwidth $menu] - $bw - $mw}] |
|
set sh [expr {[winfo screenheight $menu] - $bh - $mh}] |
|
|
|
switch -- $dir { |
|
above { if {$y >= $mh} { incr y -$mh } { incr y $bh } } |
|
below { if {$y <= $sh} { incr y $bh } { incr y -$mh } } |
|
left { if {$x >= $mw} { incr x -$mw } { incr x $bw } } |
|
right { if {$x <= $sw} { incr x $bw } { incr x -$mw } } |
|
flush { |
|
|
|
|
|
|
|
|
|
set index [FindMenuEntry $menu [$mb cget -text]] |
|
if {$index ne ""} { |
|
incr y -[$menu yposition $index] |
|
} |
|
} |
|
} |
|
|
|
return [list $x $y] |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::menubutton::Popdown {mb} { |
|
if {[$mb instate disabled] || [set menu [$mb cget -menu]] eq ""} { |
|
return |
|
} |
|
foreach {x y} [PostPosition $mb $menu] { break } |
|
tk_popup $menu $x $y |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::menubutton::Pulldown {mb} { |
|
variable State |
|
if {[$mb instate disabled] || [set menu [$mb cget -menu]] eq ""} { |
|
return |
|
} |
|
foreach {x y} [PostPosition $mb $menu] { break } |
|
set State(pulldown) 1 |
|
set State(oldcursor) [$mb cget -cursor] |
|
|
|
$mb state pressed |
|
$mb configure -cursor [$menu cget -cursor] |
|
$menu post $x $y |
|
tk_menuSetFocus $menu |
|
} |
|
|
|
|
|
|
|
|
|
|
|
proc ttk::menubutton::TransferGrab {mb} { |
|
variable State |
|
if {$State(pulldown)} { |
|
$mb configure -cursor $State(oldcursor) |
|
$mb state {!pressed !active} |
|
set State(pulldown) 0 |
|
|
|
set menu [$mb cget -menu] |
|
tk_popup $menu [winfo rootx $menu] [winfo rooty $menu] |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::menubutton::FindMenuEntry {menu s} { |
|
set last [$menu index last] |
|
if {$last eq "none"} { |
|
return "" |
|
} |
|
for {set i 0} {$i <= $last} {incr i} { |
|
if {![catch {$menu entrycget $i -label} label] |
|
&& ($label eq $s)} { |
|
return $i |
|
} |
|
} |
|
return "" |
|
} |
|
|
|
|
|
|