|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace eval ttk::combobox { |
|
variable Values |
|
variable State |
|
set State(entryPress) 0 |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
ttk::copyBindings TEntry TCombobox |
|
|
|
bind TCombobox <Down> { ttk::combobox::Post %W } |
|
bind TCombobox <Escape> { ttk::combobox::Unpost %W } |
|
|
|
bind TCombobox <Button-1> { ttk::combobox::Press "" %W %x %y } |
|
bind TCombobox <Shift-Button-1> { ttk::combobox::Press "s" %W %x %y } |
|
bind TCombobox <Double-Button-1> { ttk::combobox::Press "2" %W %x %y } |
|
bind TCombobox <Triple-Button-1> { ttk::combobox::Press "3" %W %x %y } |
|
bind TCombobox <B1-Motion> { ttk::combobox::Drag %W %x } |
|
bind TCombobox <Motion> { ttk::combobox::Motion %W %x %y } |
|
|
|
ttk::bindMouseWheel TCombobox [list ttk::combobox::Scroll %W] |
|
|
|
bind TCombobox <<TraverseIn>> { ttk::combobox::TraverseIn %W } |
|
|
|
|
|
|
|
bind ComboboxListbox <ButtonRelease-1> { ttk::combobox::LBSelected %W } |
|
bind ComboboxListbox <Return> { ttk::combobox::LBSelected %W } |
|
bind ComboboxListbox <Escape> { ttk::combobox::LBCancel %W } |
|
bind ComboboxListbox <Tab> { ttk::combobox::LBTab %W next } |
|
bind ComboboxListbox <<PrevWindow>> { ttk::combobox::LBTab %W prev } |
|
bind ComboboxListbox <Destroy> { ttk::combobox::LBCleanup %W } |
|
bind ComboboxListbox <Motion> { ttk::combobox::LBHover %W %x %y } |
|
bind ComboboxListbox <Map> { focus -force %W } |
|
|
|
switch -- [tk windowingsystem] { |
|
win32 { |
|
|
|
|
|
bind ComboboxListbox <FocusOut> { ttk::combobox::LBCancel %W } |
|
} |
|
} |
|
|
|
|
|
|
|
bind ComboboxPopdown <Map> { ttk::combobox::MapPopdown %W } |
|
bind ComboboxPopdown <Unmap> { ttk::combobox::UnmapPopdown %W } |
|
bind ComboboxPopdown <Button> \ |
|
{ ttk::combobox::Unpost [winfo parent %W] } |
|
|
|
|
|
|
|
|
|
option add *TCombobox*Listbox.font TkTextFont widgetDefault |
|
option add *TCombobox*Listbox.relief flat widgetDefault |
|
option add *TCombobox*Listbox.highlightThickness 0 widgetDefault |
|
|
|
|
|
|
|
switch -- [tk windowingsystem] { |
|
x11 { |
|
option add *TCombobox*Listbox.background white widgetDefault |
|
} |
|
aqua { |
|
option add *TCombobox*Listbox.borderWidth 0 widgetDefault |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::combobox::Press {mode w x y} { |
|
variable State |
|
|
|
$w instate disabled { return } |
|
|
|
set State(entryPress) [expr { |
|
[$w instate !readonly] |
|
&& [string match *textarea [$w identify element $x $y]] |
|
}] |
|
|
|
focus $w |
|
if {$State(entryPress)} { |
|
switch -- $mode { |
|
s { ttk::entry::Shift-Press $w $x |
|
2 { ttk::entry::Select $w $x word |
|
3 { ttk::entry::Select $w $x line |
|
"" - |
|
default { ttk::entry::Press $w $x } |
|
} |
|
} else { |
|
Post $w |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
proc ttk::combobox::Drag {w x} { |
|
variable State |
|
if {$State(entryPress)} { |
|
ttk::entry::Drag $w $x |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::combobox::Motion {w x y} { |
|
variable State |
|
ttk::saveCursor $w State(userConfCursor) [ttk::cursor text] |
|
if { [$w identify $x $y] eq "textarea" |
|
&& [$w instate {!readonly !disabled}] |
|
} { |
|
ttk::setCursor $w text |
|
} else { |
|
ttk::setCursor $w $State(userConfCursor) |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::combobox::TraverseIn {w} { |
|
$w instate {!readonly !disabled} { |
|
$w selection range 0 end |
|
$w icursor end |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::combobox::SelectEntry {cb index} { |
|
$cb current $index |
|
$cb selection range 0 end |
|
$cb icursor end |
|
event generate $cb <<ComboboxSelected>> -when mark |
|
} |
|
|
|
|
|
|
|
proc ttk::combobox::Scroll {cb dir} { |
|
$cb instate disabled { return } |
|
set max [llength [$cb cget -values]] |
|
set current [$cb current] |
|
incr current $dir |
|
if {$max != 0 && $current == $current % $max} { |
|
SelectEntry $cb $current |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
proc ttk::combobox::LBSelected {lb} { |
|
set cb [LBMaster $lb] |
|
LBSelect $lb |
|
Unpost $cb |
|
focus $cb |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::combobox::LBCancel {lb} { |
|
Unpost [LBMaster $lb] |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::combobox::LBTab {lb dir} { |
|
set cb [LBMaster $lb] |
|
switch -- $dir { |
|
next { set newFocus [tk_focusNext $cb] } |
|
prev { set newFocus [tk_focusPrev $cb] } |
|
} |
|
|
|
if {$newFocus ne ""} { |
|
LBSelect $lb |
|
Unpost $cb |
|
|
|
|
|
|
|
after 0 [list ttk::traverseTo $newFocus] |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::combobox::LBHover {w x y} { |
|
$w selection clear 0 end |
|
$w activate @$x,$y |
|
$w selection set @$x,$y |
|
} |
|
|
|
|
|
|
|
proc ttk::combobox::MapPopdown {w} { |
|
[winfo parent $w] state pressed |
|
ttk::globalGrab $w |
|
} |
|
|
|
|
|
|
|
proc ttk::combobox::UnmapPopdown {w} { |
|
[winfo parent $w] state !pressed |
|
ttk::releaseGrab $w |
|
} |
|
|
|
|
|
|
|
|
|
|
|
proc ttk::combobox::PopdownWindow {cb} { |
|
if {![winfo exists $cb.popdown]} { |
|
set poplevel [PopdownToplevel $cb.popdown] |
|
set popdown [ttk::frame $poplevel.f -style ComboboxPopdownFrame] |
|
|
|
ttk::scrollbar $popdown.sb \ |
|
-orient vertical -command [list $popdown.l yview] |
|
listbox $popdown.l \ |
|
-listvariable ttk::combobox::Values($cb) \ |
|
-yscrollcommand [list $popdown.sb set] \ |
|
-exportselection false \ |
|
-selectmode browse \ |
|
-activestyle none \ |
|
; |
|
|
|
bindtags $popdown.l \ |
|
[list $popdown.l ComboboxListbox Listbox $popdown all] |
|
|
|
grid $popdown.l -row 0 -column 0 -padx {1 0} -pady 1 -sticky nsew |
|
grid $popdown.sb -row 0 -column 1 -padx {0 1} -pady 1 -sticky ns |
|
grid columnconfigure $popdown 0 -weight 1 |
|
grid rowconfigure $popdown 0 -weight 1 |
|
|
|
grid $popdown -sticky news -padx 0 -pady 0 |
|
grid rowconfigure $poplevel 0 -weight 1 |
|
grid columnconfigure $poplevel 0 -weight 1 |
|
} |
|
return $cb.popdown |
|
} |
|
|
|
|
|
|
|
|
|
|
|
proc ttk::combobox::PopdownToplevel {w} { |
|
toplevel $w -class ComboboxPopdown |
|
wm withdraw $w |
|
switch -- [tk windowingsystem] { |
|
default - |
|
x11 { |
|
$w configure -relief flat -borderwidth 0 |
|
wm attributes $w -type combo |
|
wm overrideredirect $w true |
|
} |
|
win32 { |
|
$w configure -relief flat -borderwidth 0 |
|
wm overrideredirect $w true |
|
wm attributes $w -topmost 1 |
|
} |
|
aqua { |
|
$w configure -relief solid -borderwidth 0 |
|
tk::unsupported::MacWindowStyle style $w \ |
|
help {noActivates hideOnSuspend} |
|
wm resizable $w 0 0 |
|
} |
|
} |
|
return $w |
|
} |
|
|
|
|
|
|
|
|
|
|
|
proc ttk::combobox::ConfigureListbox {cb} { |
|
variable Values |
|
|
|
set popdown [PopdownWindow $cb].f |
|
set values [$cb cget -values] |
|
set current [$cb current] |
|
if {$current < 0} { |
|
set current 0 |
|
} |
|
set Values($cb) $values |
|
$popdown.l selection clear 0 end |
|
$popdown.l selection set $current |
|
$popdown.l activate $current |
|
$popdown.l see $current |
|
set height [llength $values] |
|
if {$height > [$cb cget -height]} { |
|
set height [$cb cget -height] |
|
grid $popdown.sb |
|
grid configure $popdown.l -padx {1 0} |
|
} else { |
|
grid remove $popdown.sb |
|
grid configure $popdown.l -padx 1 |
|
} |
|
$popdown.l configure -height $height |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::combobox::PlacePopdown {cb popdown} { |
|
set x [winfo rootx $cb] |
|
set y [winfo rooty $cb] |
|
set w [winfo width $cb] |
|
set h [winfo height $cb] |
|
set style [$cb cget -style] |
|
if { $style eq {} } { |
|
set style TCombobox |
|
} |
|
set postoffset [ttk::style lookup $style -postoffset {} {0 0 0 0}] |
|
foreach var {x y w h} delta $postoffset { |
|
incr $var $delta |
|
} |
|
|
|
set H [winfo reqheight $popdown] |
|
if {$y + $h + $H > [winfo screenheight $popdown]} { |
|
set Y [expr {$y - $H}] |
|
} else { |
|
set Y [expr {$y + $h}] |
|
} |
|
wm geometry $popdown ${w}x${H}+${x}+${Y} |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::combobox::Post {cb} { |
|
|
|
|
|
$cb instate disabled { return } |
|
|
|
|
|
|
|
|
|
|
|
uplevel #0 [$cb cget -postcommand] |
|
|
|
set popdown [PopdownWindow $cb] |
|
ConfigureListbox $cb |
|
update idletasks |
|
PlacePopdown $cb $popdown |
|
|
|
switch -- [tk windowingsystem] { |
|
x11 - win32 { wm transient $popdown [winfo toplevel $cb] } |
|
} |
|
|
|
|
|
|
|
wm attribute $popdown -topmost 1 |
|
wm deiconify $popdown |
|
raise $popdown |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::combobox::Unpost {cb} { |
|
if {[winfo exists $cb.popdown]} { |
|
wm withdraw $cb.popdown |
|
} |
|
grab release $cb.popdown |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::combobox::LBMaster {lb} { |
|
winfo parent [winfo parent [winfo parent $lb]] |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::combobox::LBSelect {lb} { |
|
set cb [LBMaster $lb] |
|
set selection [$lb curselection] |
|
if {[llength $selection] == 1} { |
|
SelectEntry $cb [lindex $selection 0] |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::combobox::LBCleanup {lb} { |
|
variable Values |
|
unset Values([LBMaster $lb]) |
|
} |
|
|
|
|
|
|