summaryrefslogtreecommitdiffstats
path: root/library/ttk/spinbox.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'library/ttk/spinbox.tcl')
-rw-r--r--library/ttk/spinbox.tcl28
1 files changed, 20 insertions, 8 deletions
diff --git a/library/ttk/spinbox.tcl b/library/ttk/spinbox.tcl
index 8aba5e1..56629bb 100644
--- a/library/ttk/spinbox.tcl
+++ b/library/ttk/spinbox.tcl
@@ -23,7 +23,17 @@ bind TSpinbox <Down> { event generate %W <<Decrement>> }
bind TSpinbox <<Increment>> { ttk::spinbox::Spin %W +1 }
bind TSpinbox <<Decrement>> { ttk::spinbox::Spin %W -1 }
-ttk::bindMouseWheel TSpinbox [list ttk::spinbox::MouseWheel %W]
+ttk::bindMouseWheel TSpinbox { ttk::spinbox::Spin %W }
+bind TSpinbox <Shift-MouseWheel> {
+ # Ignore the event
+}
+bind TSpinbox <TouchpadScroll> {
+ lassign [tk::PreciseScrollDeltas %D] tk::Priv(deltaX) tk::Priv(deltaY)
+ # TouchpadScroll events fire about 60 times per second.
+ if {$tk::Priv(deltaY) != 0 && %# %% 12 == 0} {
+ ttk::spinbox::Spin %W [expr {$tk::Priv(deltaY) > 0 ? -1 : 1}]
+ }
+}
## Motion --
# Sets cursor.
@@ -80,13 +90,13 @@ proc ttk::spinbox::Release {w} {
## MouseWheel --
# Mousewheel callback. Turn these into <<Increment>> (-1, up)
-# or <<Decrement> (+1, down) events.
+# or <<Decrement> (+1, down) events. Not used any more.
#
-proc ttk::spinbox::MouseWheel {w dir} {
+proc ttk::spinbox::MouseWheel {w dir {factor 1.0}} {
if {[$w instate disabled]} { return }
- if {$dir < 0} {
+ if {($dir < 0) ^ ($factor < 0)} {
event generate $w <<Increment>>
- } else {
+ } elseif {$dir != 0} {
event generate $w <<Decrement>>
}
}
@@ -134,7 +144,7 @@ proc ttk::spinbox::Adjust {w v min max} {
# Otherwise cycle through numeric range based on
# -from, -to, and -increment.
#
-proc ttk::spinbox::Spin {w dir} {
+proc ttk::spinbox::Spin {w dir {factor -1.0}} {
variable State
if {[$w instate disabled]} { return }
@@ -146,6 +156,8 @@ proc ttk::spinbox::Spin {w dir} {
set State($w,values) [$w cget -values]
set State($w,values.length) [llength $State($w,values)]
+ set d [expr {-($dir/$factor)}]
+ set d [expr {int($d > 0 ? ceil($d) : floor($d))}]
if {$State($w,values.length) > 0} {
set value [$w get]
set current $State($w,values.index)
@@ -153,13 +165,13 @@ proc ttk::spinbox::Spin {w dir} {
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 \
+ set State($w,values.index) [Adjust $w [expr {$current + $d}] 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]}]
+ set v [expr {[scan [$w get] %f] + $d * [$w cget -increment]}]
}]} {
set v [$w cget -from]
}