summaryrefslogtreecommitdiffstats
path: root/library/ttk
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2020-10-13 13:05:57 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2020-10-13 13:05:57 (GMT)
commitad0d8ceeb439f7151ce2378527b87cf81e17d1bd (patch)
tree4b1ab4bdae549da7663b1f30f78c2bd65263d1c2 /library/ttk
parent9a1a8cdddc762590ba680992219159244f63d945 (diff)
downloadtk-ad0d8ceeb439f7151ce2378527b87cf81e17d1bd.zip
tk-ad0d8ceeb439f7151ce2378527b87cf81e17d1bd.tar.gz
tk-ad0d8ceeb439f7151ce2378527b87cf81e17d1bd.tar.bz2
Protect ttk::spinbox::Spin against empty lsearch result. Discovered when running against Tcl's "empty-not-found" branch. Some formatting
Diffstat (limited to 'library/ttk')
-rw-r--r--library/ttk/spinbox.tcl43
1 files changed, 22 insertions, 21 deletions
diff --git a/library/ttk/spinbox.tcl b/library/ttk/spinbox.tcl
index 33936d9..8aba5e1 100644
--- a/library/ttk/spinbox.tcl
+++ b/library/ttk/spinbox.tcl
@@ -32,7 +32,7 @@ proc ttk::spinbox::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}]
+ && [$w instate {!readonly !disabled}]
} {
ttk::setCursor $w text
} else {
@@ -46,16 +46,16 @@ proc ttk::spinbox::Press {w x y} {
if {[$w instate disabled]} { return }
focus $w
switch -glob -- [$w identify $x $y] {
- *textarea { ttk::entry::Press $w $x }
+ *textarea { ttk::entry::Press $w $x }
*rightarrow -
- *uparrow { ttk::Repeatedly event generate $w <<Increment>> }
+ *uparrow { ttk::Repeatedly event generate $w <<Increment>> }
*leftarrow -
- *downarrow { ttk::Repeatedly event generate $w <<Decrement>> }
+ *downarrow { ttk::Repeatedly event generate $w <<Decrement>> }
*spinbutton {
if {$y * 2 >= [winfo height $w]} {
- set event <<Decrement>>
+ set event <<Decrement>>
} else {
- set event <<Increment>>
+ set event <<Increment>>
}
ttk::Repeatedly event generate $w $event
}
@@ -69,7 +69,7 @@ proc ttk::spinbox::DoubleClick {w x y} {
if {[$w instate disabled]} { return }
switch -glob -- [$w identify $x $y] {
- *textarea { SelectAll $w }
+ *textarea { SelectAll $w }
* { Press $w $x $y }
}
}
@@ -140,25 +140,26 @@ proc ttk::spinbox::Spin {w dir} {
if {[$w instate disabled]} { return }
if {![info exists State($w,values.length)]} {
- set State($w,values.index) -1
- set State($w,values.last) {}
+ set State($w,values.index) -1
+ set State($w,values.last) {}
}
set State($w,values) [$w cget -values]
set State($w,values.length) [llength $State($w,values)]
if {$State($w,values.length) > 0} {
- set value [$w get]
- set current $State($w,values.index)
- if {$value ne $State($w,values.last)} {
- set current [lsearch -exact $State($w,values) $value]
- }
- set State($w,values.index) [Adjust $w [expr {$current + $dir}] 0 \
- [expr {$State($w,values.length) - 1}]]
- set State($w,values.last) [lindex $State($w,values) $State($w,values.index)]
- $w set $State($w,values.last)
+ set value [$w get]
+ set current $State($w,values.index)
+ if {$value ne $State($w,values.last)} {
+ set current [lsearch -exact $State($w,values) $value]
+ if {$current < 0} {set current -1}
+ }
+ set State($w,values.index) [Adjust $w [expr {$current + $dir}] 0 \
+ [expr {$State($w,values.length) - 1}]]
+ set State($w,values.last) [lindex $State($w,values) $State($w,values.index)]
+ $w set $State($w,values.last)
} else {
- if {[catch {
- set v [expr {[scan [$w get] %f] + $dir * [$w cget -increment]}]
+ if {[catch {
+ set v [expr {[scan [$w get] %f] + $dir * [$w cget -increment]}]
}]} {
set v [$w cget -from]
}
@@ -176,7 +177,7 @@ proc ttk::spinbox::FormatValue {w val} {
if {$fmt eq ""} {
# Try to guess a suitable -format based on -increment.
set delta [expr {abs([$w cget -increment])}]
- if {0 < $delta && $delta < 1} {
+ if {0 < $delta && $delta < 1} {
# NB: This guesses wrong if -increment has more than 1
# significant digit itself, e.g., -increment 0.25
set nsd [expr {int(ceil(-log10($delta)))}]