|
|
|
|
|
|
|
|
|
namespace eval ttk::treeview { |
|
variable State |
|
|
|
|
|
|
|
set State(activeWidget) {} |
|
set State(activeHeading) {} |
|
|
|
|
|
|
|
set State(pressMode) none |
|
set State(pressX) 0 |
|
|
|
|
|
set State(resizeColumn) #0 |
|
|
|
|
|
set State(heading) {} |
|
} |
|
|
|
|
|
|
|
|
|
bind Treeview <Motion> { ttk::treeview::Motion %W %x %y } |
|
bind Treeview <B1-Leave> { #nothing } |
|
bind Treeview <Leave> { ttk::treeview::ActivateHeading {} {}} |
|
bind Treeview <Button-1> { ttk::treeview::Press %W %x %y } |
|
bind Treeview <Double-Button-1> { ttk::treeview::DoubleClick %W %x %y } |
|
bind Treeview <ButtonRelease-1> { ttk::treeview::Release %W %x %y } |
|
bind Treeview <B1-Motion> { ttk::treeview::Drag %W %x %y } |
|
bind Treeview <Up> { ttk::treeview::Keynav %W up } |
|
bind Treeview <Down> { ttk::treeview::Keynav %W down } |
|
bind Treeview <Right> { ttk::treeview::Keynav %W right } |
|
bind Treeview <Left> { ttk::treeview::Keynav %W left } |
|
bind Treeview <Prior> { %W yview scroll -1 pages } |
|
bind Treeview <Next> { %W yview scroll 1 pages } |
|
bind Treeview <Return> { ttk::treeview::ToggleFocus %W } |
|
bind Treeview <space> { ttk::treeview::ToggleFocus %W } |
|
|
|
bind Treeview <Shift-Button-1> \ |
|
{ ttk::treeview::Select %W %x %y extend } |
|
bind Treeview <<ToggleSelection>> \ |
|
{ ttk::treeview::Select %W %x %y toggle } |
|
|
|
ttk::copyBindings TtkScrollable Treeview |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::treeview::Keynav {w dir} { |
|
set focus [$w focus] |
|
if {$focus eq ""} { return } |
|
|
|
switch -- $dir { |
|
up { |
|
if {[set up [$w prev $focus]] eq ""} { |
|
set focus [$w parent $focus] |
|
} else { |
|
while {[$w item $up -open] && [llength [$w children $up]]} { |
|
set up [lindex [$w children $up] end] |
|
} |
|
set focus $up |
|
} |
|
} |
|
down { |
|
if {[$w item $focus -open] && [llength [$w children $focus]]} { |
|
set focus [lindex [$w children $focus] 0] |
|
} else { |
|
set up $focus |
|
while {$up ne "" && [set down [$w next $up]] eq ""} { |
|
set up [$w parent $up] |
|
} |
|
set focus $down |
|
} |
|
} |
|
left { |
|
if {[$w item $focus -open] && [llength [$w children $focus]]} { |
|
CloseItem $w $focus |
|
} else { |
|
set focus [$w parent $focus] |
|
} |
|
} |
|
right { |
|
OpenItem $w $focus |
|
} |
|
} |
|
|
|
if {$focus != {}} { |
|
SelectOp $w $focus choose |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::treeview::Motion {w x y} { |
|
variable State |
|
|
|
ttk::saveCursor $w State(userConfCursor) [ttk::cursor hresize] |
|
|
|
set cursor $State(userConfCursor) |
|
set activeHeading {} |
|
|
|
switch -- [$w identify region $x $y] { |
|
separator { set cursor hresize } |
|
heading { set activeHeading [$w identify column $x $y] } |
|
} |
|
|
|
ttk::setCursor $w $cursor |
|
ActivateHeading $w $activeHeading |
|
} |
|
|
|
|
|
|
|
proc ttk::treeview::ActivateHeading {w heading} { |
|
variable State |
|
|
|
if {$w != $State(activeWidget) || $heading != $State(activeHeading)} { |
|
if {[winfo exists $State(activeWidget)] && $State(activeHeading) != {}} { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
catch {$State(activeWidget) heading $State(activeHeading) state !active} |
|
} |
|
if {$heading != {}} { |
|
$w heading $heading state active |
|
} |
|
set State(activeHeading) $heading |
|
set State(activeWidget) $w |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
proc ttk::treeview::Select {w x y op} { |
|
if {[set item [$w identify row $x $y]] ne "" } { |
|
SelectOp $w $item $op |
|
} |
|
} |
|
|
|
|
|
|
|
proc ttk::treeview::DoubleClick {w x y} { |
|
if {[set row [$w identify row $x $y]] ne ""} { |
|
Toggle $w $row |
|
} else { |
|
Press $w $x $y |
|
} |
|
} |
|
|
|
|
|
|
|
proc ttk::treeview::Press {w x y} { |
|
focus $w |
|
switch -- [$w identify region $x $y] { |
|
nothing { } |
|
heading { heading.press $w $x $y } |
|
separator { resize.press $w $x $y } |
|
tree - |
|
cell { |
|
set item [$w identify item $x $y] |
|
SelectOp $w $item choose |
|
switch -glob -- [$w identify element $x $y] { |
|
*indicator - |
|
*disclosure { Toggle $w $item } |
|
} |
|
} |
|
} |
|
} |
|
|
|
|
|
|
|
proc ttk::treeview::Drag {w x y} { |
|
variable State |
|
switch $State(pressMode) { |
|
resize { resize.drag $w $x } |
|
heading { heading.drag $w $x $y } |
|
} |
|
} |
|
|
|
proc ttk::treeview::Release {w x y} { |
|
variable State |
|
switch $State(pressMode) { |
|
resize { resize.release $w $x } |
|
heading { heading.release $w } |
|
} |
|
set State(pressMode) none |
|
Motion $w $x $y |
|
} |
|
|
|
|
|
|
|
proc ttk::treeview::resize.press {w x y} { |
|
variable State |
|
set State(pressMode) "resize" |
|
set State(resizeColumn) [$w identify column $x $y] |
|
} |
|
|
|
proc ttk::treeview::resize.drag {w x} { |
|
variable State |
|
$w drag $State(resizeColumn) $x |
|
} |
|
|
|
proc ttk::treeview::resize.release {w x} { |
|
$w drop |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::treeview::heading.press {w x y} { |
|
variable State |
|
set column [$w identify column $x $y] |
|
set State(pressMode) "heading" |
|
set State(heading) $column |
|
$w heading $column state pressed |
|
} |
|
|
|
proc ttk::treeview::heading.drag {w x y} { |
|
variable State |
|
if { [$w identify region $x $y] eq "heading" |
|
&& [$w identify column $x $y] eq $State(heading) |
|
} { |
|
$w heading $State(heading) state pressed |
|
} else { |
|
$w heading $State(heading) state !pressed |
|
} |
|
} |
|
|
|
proc ttk::treeview::heading.release {w} { |
|
variable State |
|
if {[lsearch -exact [$w heading $State(heading) state] pressed] >= 0} { |
|
after 0 [$w heading $State(heading) -command] |
|
} |
|
$w heading $State(heading) state !pressed |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::treeview::SelectOp {w item op} { |
|
select.$op.[$w cget -selectmode] $w $item |
|
} |
|
|
|
|
|
|
|
proc ttk::treeview::select.choose.none {w item} { $w focus $item; $w see $item } |
|
proc ttk::treeview::select.toggle.none {w item} { $w focus $item; $w see $item } |
|
proc ttk::treeview::select.extend.none {w item} { $w focus $item; $w see $item } |
|
|
|
|
|
|
|
proc ttk::treeview::select.choose.browse {w item} { BrowseTo $w $item } |
|
proc ttk::treeview::select.toggle.browse {w item} { BrowseTo $w $item } |
|
proc ttk::treeview::select.extend.browse {w item} { BrowseTo $w $item } |
|
|
|
|
|
|
|
proc ttk::treeview::select.choose.extended {w item} { |
|
BrowseTo $w $item |
|
} |
|
proc ttk::treeview::select.toggle.extended {w item} { |
|
$w selection toggle [list $item] |
|
} |
|
proc ttk::treeview::select.extend.extended {w item} { |
|
if {[set anchor [$w focus]] ne ""} { |
|
$w selection set [between $w $anchor $item] |
|
} else { |
|
BrowseTo $w $item |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::treeview::between {tv item1 item2} { |
|
variable between [list] |
|
variable selectingBetween 0 |
|
ScanBetween $tv $item1 $item2 {} |
|
return $between |
|
} |
|
|
|
|
|
|
|
|
|
proc ttk::treeview::ScanBetween {tv item1 item2 item} { |
|
variable between |
|
variable selectingBetween |
|
|
|
if {$item eq $item1 || $item eq $item2} { |
|
lappend between $item |
|
set selectingBetween [expr {!$selectingBetween}] |
|
} elseif {$selectingBetween} { |
|
lappend between $item |
|
} |
|
foreach child [$tv children $item] { |
|
ScanBetween $tv $item1 $item2 $child |
|
} |
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
proc ttk::treeview::OpenItem {w item} { |
|
$w focus $item |
|
event generate $w <<TreeviewOpen>> |
|
$w item $item -open true |
|
} |
|
|
|
proc ttk::treeview::CloseItem {w item} { |
|
$w item $item -open false |
|
$w focus $item |
|
event generate $w <<TreeviewClose>> |
|
} |
|
|
|
|
|
|
|
proc ttk::treeview::Toggle {w item} { |
|
|
|
|
|
if {[$w children $item] == {}} { |
|
return |
|
} |
|
|
|
if {[$w item $item -open]} { |
|
CloseItem $w $item |
|
} else { |
|
OpenItem $w $item |
|
} |
|
} |
|
|
|
|
|
|
|
proc ttk::treeview::ToggleFocus {w} { |
|
set item [$w focus] |
|
if {$item ne ""} { |
|
Toggle $w $item |
|
} |
|
} |
|
|
|
|
|
|
|
proc ttk::treeview::BrowseTo {w item} { |
|
$w see $item |
|
$w focus $item |
|
$w selection set [list $item] |
|
} |
|
|
|
|
|
|