summaryrefslogtreecommitdiffstats
path: root/library/ttk/treeview.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'library/ttk/treeview.tcl')
-rw-r--r--library/ttk/treeview.tcl141
1 files changed, 111 insertions, 30 deletions
diff --git a/library/ttk/treeview.tcl b/library/ttk/treeview.tcl
index 62fc630..e9fc5ad 100644
--- a/library/ttk/treeview.tcl
+++ b/library/ttk/treeview.tcl
@@ -20,6 +20,9 @@ namespace eval ttk::treeview {
# For pressmode == "heading"
set State(heading) {}
+
+ set State(cellAnchor) {}
+ set State(cellAnchorOp) "set"
}
### Widget bindings.
@@ -56,9 +59,20 @@ ttk::copyBindings TtkScrollable Treeview
# @@@ TODO: verify/rewrite up and down code.
#
proc ttk::treeview::Keynav {w dir} {
+ variable State
set focus [$w focus]
if {$focus eq ""} { return }
+ set cells [expr {[$w cget -selecttype] eq "cell"}]
+
+ if {$cells} {
+ lassign $State(cellAnchor) _ colAnchor
+ # Just in case, give it a valid value
+ if {$colAnchor eq ""} {
+ set colAnchor "#1"
+ }
+ }
+
switch -- $dir {
up {
if {[set up [$w prev $focus]] eq ""} {
@@ -82,19 +96,46 @@ proc ttk::treeview::Keynav {w dir} {
}
}
left {
- if {[$w item $focus -open] && [llength [$w children $focus]]} {
- CloseItem $w $focus
+ if {$cells} {
+ # This assumes that colAnchor is of the "#N" format.
+ set colNo [string range $colAnchor 1 end]
+ set firstCol [expr {"tree" ni [$w cget -show]}]
+ if {$colNo > $firstCol} {
+ incr colNo -1
+ set colAnchor "#$colNo"
+ }
+ } elseif {[$w item $focus -open] && [llength [$w children $focus]]} {
+ CloseItem $w $focus
} else {
- set focus [$w parent $focus]
+ set focus [$w parent $focus]
}
}
right {
- OpenItem $w $focus
+ if {$cells} {
+ set colNo [string range $colAnchor 1 end]
+ set dispCol [$w cget -displaycolumns]
+ if {$dispCol eq "#all"} {
+ set lastCol [llength [$w cget -columns]]
+ } else {
+ set lastCol [llength $dispCol]
+ }
+ if {$colNo < ($lastCol - 1)} {
+ incr colNo
+ set colAnchor "#$colNo"
+ }
+ } else {
+ OpenItem $w $focus
+ }
}
}
if {$focus != {}} {
- SelectOp $w $focus choose
+ if {$cells} {
+ set cell [list $focus $colAnchor]
+ SelectOp $w $focus $cell choose
+ } else {
+ SelectOp $w $focus "" choose
+ }
}
}
@@ -145,13 +186,27 @@ proc ttk::treeview::ActivateHeading {w heading} {
}
}
+## IndentifyCell -- Locate the cell at coordinate
+# Only active when -selecttype is "cell", and leaves cell empty otherwise.
+# Down the call chain it is enough to check cell to know the selecttype.
+proc ttk::treeview::IdentifyCell {w x y} {
+ set cell {}
+ if {[$w cget -selecttype] eq "cell"} {
+ # Later handling assumes that the column in the cell ID is of the
+ # format #N, which is always the case from "identify cell"
+ set cell [$w identify cell $x $y]
+ }
+ return $cell
+}
+
## Select $w $x $y $selectop
# Binding procedure for selection operations.
# See "Selection modes", below.
#
proc ttk::treeview::Select {w x y op} {
if {[set item [$w identify row $x $y]] ne "" } {
- SelectOp $w $item $op
+ set cell [IdentifyCell $w $x $y]
+ SelectOp $w $item $cell $op
}
}
@@ -176,7 +231,9 @@ proc ttk::treeview::Press {w x y} {
tree -
cell {
set item [$w identify item $x $y]
- SelectOp $w $item choose
+ set cell [IdentifyCell $w $x $y]
+
+ SelectOp $w $item $cell choose
switch -glob -- [$w identify element $x $y] {
*indicator -
*disclosure { Toggle $w $item }
@@ -238,9 +295,9 @@ proc ttk::treeview::heading.drag {w x y} {
if { [$w identify region $x $y] eq "heading"
&& [$w identify column $x $y] eq $State(heading)
} {
- $w heading $State(heading) state pressed
+ $w heading $State(heading) state pressed
} else {
- $w heading $State(heading) state !pressed
+ $w heading $State(heading) state !pressed
}
}
@@ -259,35 +316,51 @@ proc ttk::treeview::heading.release {w} {
# Dispatch to appropriate selection operation
# depending on current value of -selectmode.
#
-proc ttk::treeview::SelectOp {w item op} {
- select.$op.[$w cget -selectmode] $w $item
+proc ttk::treeview::SelectOp {w item cell op} {
+ select.$op.[$w cget -selectmode] $w $item $cell
}
## -selectmode none:
#
-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.none {w item cell} { $w focus $item; $w see $item }
+proc ttk::treeview::select.toggle.none {w item cell} { $w focus $item; $w see $item }
+proc ttk::treeview::select.extend.none {w item cell} { $w focus $item; $w see $item }
## -selectmode browse:
#
-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.browse {w item cell} { BrowseTo $w $item $cell }
+proc ttk::treeview::select.toggle.browse {w item cell} { BrowseTo $w $item $cell }
+proc ttk::treeview::select.extend.browse {w item cell} { BrowseTo $w $item $cell }
## -selectmode multiple:
#
-proc ttk::treeview::select.choose.extended {w item} {
- BrowseTo $w $item
+proc ttk::treeview::select.choose.extended {w item cell} {
+ BrowseTo $w $item $cell
}
-proc ttk::treeview::select.toggle.extended {w item} {
- $w selection toggle [list $item]
+proc ttk::treeview::select.toggle.extended {w item cell} {
+ variable State
+ if {$cell ne ""} {
+ $w cellselection toggle [list $cell]
+ set State(cellAnchor) $cell
+ set State(cellAnchorOp) add
+ } else {
+ $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]
+proc ttk::treeview::select.extend.extended {w item cell} {
+ variable State
+ if {$cell ne ""} {
+ if {$State(cellAnchor) ne ""} {
+ $w cellselection $State(cellAnchorOp) $State(cellAnchor) $cell
+ } else {
+ BrowseTo $w $item $cell
+ }
} else {
- BrowseTo $w $item
+ if {[set anchor [$w focus]] ne ""} {
+ $w selection set [between $w $anchor $item]
+ } else {
+ BrowseTo $w $item $cell
+ }
}
}
@@ -319,10 +392,10 @@ proc ttk::treeview::ScanBetween {tv item1 item2 item} {
variable selectingBetween
if {$item eq $item1 || $item eq $item2} {
- lappend between $item
+ lappend between $item
set selectingBetween [expr {!$selectingBetween}]
} elseif {$selectingBetween} {
- lappend between $item
+ lappend between $item
}
foreach child [$tv children $item] {
ScanBetween $tv $item1 $item2 $child
@@ -368,16 +441,24 @@ proc ttk::treeview::Toggle {w item} {
proc ttk::treeview::ToggleFocus {w} {
set item [$w focus]
if {$item ne ""} {
- Toggle $w $item
+ Toggle $w $item
}
}
## BrowseTo -- navigate to specified item; set focus and selection
#
-proc ttk::treeview::BrowseTo {w item} {
+proc ttk::treeview::BrowseTo {w item cell} {
+ variable State
+
$w see $item
$w focus $item
- $w selection set [list $item]
+ set State(cellAnchor) $cell
+ set State(cellAnchorOp) set
+ if {$cell ne ""} {
+ $w cellselection set [list $cell]
+ } else {
+ $w selection set [list $item]
+ }
}
#*EOF*