diff options
-rw-r--r-- | library/scrlbar.tcl | 33 | ||||
-rw-r--r-- | library/text.tcl | 18 | ||||
-rw-r--r-- | library/ttk/combobox.tcl | 2 | ||||
-rw-r--r-- | library/ttk/notebook.tcl | 46 | ||||
-rw-r--r-- | library/ttk/scrollbar.tcl | 14 | ||||
-rw-r--r-- | library/ttk/spinbox.tcl | 3 | ||||
-rw-r--r-- | tests/scrollbar.test | 3 |
7 files changed, 89 insertions, 30 deletions
diff --git a/library/scrlbar.tcl b/library/scrlbar.tcl index 5c4ba72..3d3f204 100644 --- a/library/scrlbar.tcl +++ b/library/scrlbar.tcl @@ -129,14 +129,21 @@ bind Scrollbar <<LineEnd>> { } } -bind Scrollbar <Option-MouseWheel> { - tk::ScrollByUnits %W hv %D -12.0 +bind Scrollbar <Enter> {+ + set tk::Priv(xEvents) 0; set tk::Priv(yEvents) 0 } - bind Scrollbar <MouseWheel> { + tk::ScrollByUnits %W vh %D -40.0 +} +bind Scrollbar <Option-MouseWheel> { + tk::ScrollByUnits %W vh %D -12.0 +} +bind Scrollbar <Shift-MouseWheel> { tk::ScrollByUnits %W hv %D -40.0 } - +bind Scrollbar <Shift-Option-MouseWheel> { + tk::ScrollByUnits %W hv %D -12.0 +} bind Scrollbar <TouchpadScroll> { lassign [tk::PreciseScrollDeltas %D] deltaX deltaY if {$deltaX != 0 && [%W cget -orient] eq "horizontal"} { @@ -147,7 +154,6 @@ bind Scrollbar <TouchpadScroll> { } } - # tk::ScrollButtonDown -- # This procedure is invoked when a button is pressed in a scrollbar. # It changes the way the scrollbar is displayed and takes actions @@ -358,7 +364,7 @@ proc ::tk::ScrollbarScrollByPixels {w orient amount} { # Arguments: # w - The scrollbar widget. # orient - Which kinds of scrollbars this applies to: "h" for -# horizontal, "v" for vertical, "hv" for both. +# horizontal, "v" for vertical, "hv" or "vh" for both. # amount - How many units to scroll: typically 1 or -1. proc ::tk::ScrollByUnits {w orient amount {factor 1.0}} { @@ -367,6 +373,21 @@ proc ::tk::ScrollByUnits {w orient amount {factor 1.0}} { [string index [$w cget -orient] 0] $orient] < 0)} { return } + + if {[string length $orient] == 2 && $factor != 1.0} { + # Count both the <MouseWheel> and <Shift-MouseWheel> + # events, and ignore the non-dominant ones + + variable ::tk::Priv + set axis [expr {[string index $orient 0] eq "h" ? "x" : "y"}] + incr Priv(${axis}Events) + if {($Priv(xEvents) + $Priv(yEvents) > 10) && + ($axis eq "x" && $Priv(xEvents) < $Priv(yEvents) || + $axis eq "y" && $Priv(yEvents) < $Priv(xEvents))} { + return + } + } + set info [$w get] if {[llength $info] == 2} { uplevel #0 $cmd scroll [expr {$amount/$factor}] units diff --git a/library/text.tcl b/library/text.tcl index f2ef83a..caa2844 100644 --- a/library/text.tcl +++ b/library/text.tcl @@ -456,15 +456,6 @@ bind Text <B2-Motion> { } set ::tk::Priv(prevPos) {} -bind Text <TouchpadScroll> { - lassign [tk::PreciseScrollDeltas %D] deltaX deltaY - if {$deltaX != 0} { - %W xview scroll [expr {-$deltaX}] pixels - } - if {$deltaY != 0} { - %W yview scroll [expr {-$deltaY}] pixels - } -} bind Text <MouseWheel> { tk::MouseWheel %W y [tk::ScaleNum %D] -4.0 pixels } @@ -477,6 +468,15 @@ bind Text <Shift-MouseWheel> { bind Text <Shift-Option-MouseWheel> { tk::MouseWheel %W x [tk::ScaleNum %D] -1.2 pixels } +bind Text <TouchpadScroll> { + lassign [tk::PreciseScrollDeltas %D] deltaX deltaY + if {$deltaX != 0} { + %W xview scroll [tk::ScaleNum [expr {-$deltaX}]] pixels + } + if {$deltaY != 0} { + %W yview scroll [tk::ScaleNum [expr {-$deltaY}]] pixels + } +} # ::tk::TextClosestGap -- # Given x and y coordinates, this procedure finds the closest boundary diff --git a/library/ttk/combobox.tcl b/library/ttk/combobox.tcl index 449d0a2..c253eb0 100644 --- a/library/ttk/combobox.tcl +++ b/library/ttk/combobox.tcl @@ -52,7 +52,7 @@ 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] +ttk::bindMouseWheel TCombobox { ttk::combobox::Scroll %W } bind TCombobox <Shift-MouseWheel> { # Ignore the event } diff --git a/library/ttk/notebook.tcl b/library/ttk/notebook.tcl index b3acf3f..7fb0ad5 100644 --- a/library/ttk/notebook.tcl +++ b/library/ttk/notebook.tcl @@ -16,14 +16,25 @@ bind TNotebook <Control-ISO_Left_Tab> { ttk::notebook::CycleTab %W -1; break } } bind TNotebook <Destroy> { ttk::notebook::Cleanup %W } -ttk::bindMouseWheel TNotebook [list ttk::notebook::CycleTab %W] +bind TNotebook <Enter> { + set tk::Priv(xEvents) 0; set tk::Priv(yEvents) 0 +} +bind TNotebook <MouseWheel> { + ttk::notebook::CondCycleTab1 %W y %D -120.0 +} +bind TNotebook <Option-MouseWheel> { + ttk::notebook::CondCycleTab1 %W y %D -12.0 +} bind TNotebook <Shift-MouseWheel> { - # Ignore the event + ttk::notebook::CondCycleTab1 %W x %D -120.0 +} +bind TNotebook <Shift-Option-MouseWheel> { + ttk::notebook::CondCycleTab1 %W x %D -12.0 } bind TNotebook <TouchpadScroll> { # TouchpadScroll events fire about 60 times per second. if {[expr {%# %% 30}] == 0} { - ttk::notebook::CondCycleTab %W %D + ttk::notebook::CondCycleTab2 %W %D } } @@ -84,10 +95,28 @@ proc ttk::notebook::CycleTab {w dir {factor 1.0}} { } } -# CondCycleTab -- +# CondCycleTab1 -- +# Conditionally invoke the ttk::notebook::CycleTab proc. +# +proc ttk::notebook::CondCycleTab1 {w axis dir {factor 1.0}} { + # Count both the <MouseWheel> and <Shift-MouseWheel> + # events, and ignore the non-dominant ones + + variable ::tk::Priv + incr Priv(${axis}Events) + if {($Priv(xEvents) + $Priv(yEvents) > 10) && + ($axis eq "x" && $Priv(xEvents) < $Priv(yEvents) || + $axis eq "y" && $Priv(yEvents) < $Priv(xEvents))} { + return + } + + CycleTab $w $dir $factor +} + +# CondCycleTab2 -- # Conditionally invoke the ttk::notebook::CycleTab proc. # -proc ttk::notebook::CondCycleTab {w dxdy} { +proc ttk::notebook::CondCycleTab2 {w dxdy} { if {[set style [$w cget -style]] eq ""} { set style TNotebook } @@ -95,10 +124,9 @@ proc ttk::notebook::CondCycleTab {w dxdy} { lassign [tk::PreciseScrollDeltas $dxdy] deltaX deltaY if {$tabSide in {n s} && $deltaX != 0} { - CycleTab $w [expr {$deltaX > 0 ? -1 : 1}] - } - if {$tabSide in {w e} && $deltaY != 0} { - CycleTab $w [expr {$deltaY > 0 ? -1 : 1}] + CycleTab $w [expr {$deltaX < 0 ? -1 : 1}] + } elseif {$tabSide in {w e} && $deltaY != 0} { + CycleTab $w [expr {$deltaY < 0 ? -1 : 1}] } } diff --git a/library/ttk/scrollbar.tcl b/library/ttk/scrollbar.tcl index 28c6a84..7c31511 100644 --- a/library/ttk/scrollbar.tcl +++ b/library/ttk/scrollbar.tcl @@ -17,11 +17,17 @@ bind TScrollbar <Button-2> { ttk::scrollbar::Jump %W %x %y } bind TScrollbar <B2-Motion> { ttk::scrollbar::Drag %W %x %y } bind TScrollbar <ButtonRelease-2> { ttk::scrollbar::Release %W %x %y } -# Redirect scrollwheel bindings to the scrollbar widget +# Copy the mouse wheel event bindings from Scrollbar to TScrollbar # -bind TScrollbar <MouseWheel> [bind Scrollbar <MouseWheel>] -bind TScrollbar <Option-MouseWheel> [bind Scrollbar <Option-MouseWheel>] -bind TScrollbar <TouchpadScroll> [bind Scrollbar <TouchpadScroll>] +bind TScrollbar <Enter> { + set tk::Priv(xEvents) 0; set tk::Priv(yEvents) 0 +} +foreach event {<MouseWheel> <Option-MouseWheel> + <Shift-MouseWheel> <Shift-Option-MouseWheel> + <TouchpadScroll>} { + bind TScrollbar $event [bind Scrollbar $event] +} +unset event proc ttk::scrollbar::Scroll {w n units} { set cmd [$w cget -command] diff --git a/library/ttk/spinbox.tcl b/library/ttk/spinbox.tcl index 252521a..0160d35 100644 --- a/library/ttk/spinbox.tcl +++ b/library/ttk/spinbox.tcl @@ -23,12 +23,13 @@ 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::Spin %W] +ttk::bindMouseWheel TSpinbox { ttk::spinbox::Spin %W } bind TSpinbox <Shift-MouseWheel> { # Ignore the event } bind TSpinbox <TouchpadScroll> { lassign [tk::PreciseScrollDeltas %D] deltaX deltaY + # TouchpadScroll events fire about 60 times per second. if {$deltaY != 0 && [expr {%# %% 12}] == 0} { ttk::spinbox::Spin %W [expr {$deltaY > 0 ? -1 : 1}] } diff --git a/tests/scrollbar.test b/tests/scrollbar.test index edf263c..aac01e5 100644 --- a/tests/scrollbar.test +++ b/tests/scrollbar.test @@ -705,6 +705,7 @@ test scrollbar-10.1 {<MouseWheel> event on scrollbar} -setup { pack [scrollbar .s -command {.t yview}] -fill y -expand 1 -side left update focus -force .s + event generate .s <Enter> event generate .s <MouseWheel> -delta -120 after 200 {set eventprocessed 1} ; vwait eventprocessed .t index @0,0 @@ -720,6 +721,7 @@ test scrollbar-10.2 {<MouseWheel> event on scrollbar} -setup { pack [scrollbar .s -command {.t xview} -orient horizontal] -fill x -expand 1 -side top update focus -force .s + event generate .s <Enter> event generate .s <Shift-MouseWheel> -delta -120 after 200 {set eventprocessed 1} ; vwait eventprocessed .t index @0,0 @@ -734,6 +736,7 @@ test scrollbar-10.3 {<MouseWheel> event on horizontal scrollbar} -setup { pack [scrollbar .s -command {.t xview} -orient horizontal] -fill x -expand 1 -side top update focus -force .s + event generate .s <Enter> event generate .s <MouseWheel> -delta -120 after 200 {set eventprocessed 1} ; vwait eventprocessed .t index @0,0 |