summaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authormarc_culler <marc.culler@gmail.com>2023-11-19 19:17:33 (GMT)
committermarc_culler <marc.culler@gmail.com>2023-11-19 19:17:33 (GMT)
commit404383577459f5d77a42386134835beaaa62f164 (patch)
tree26b233cd6d014f0c86313b3bfb0226c185bf0a10 /library
parentf28d954bfec94579d39e5a1f71363e42066b49c4 (diff)
downloadtk-404383577459f5d77a42386134835beaaa62f164.zip
tk-404383577459f5d77a42386134835beaaa62f164.tar.gz
tk-404383577459f5d77a42386134835beaaa62f164.tar.bz2
Add helper functions to avoid multiple occurrences of hard-wired constants.
Diffstat (limited to 'library')
-rw-r--r--library/scrlbar.tcl26
-rw-r--r--library/text.tcl9
-rw-r--r--library/tk.tcl24
3 files changed, 36 insertions, 23 deletions
diff --git a/library/scrlbar.tcl b/library/scrlbar.tcl
index c54e880..0a0c2c6 100644
--- a/library/scrlbar.tcl
+++ b/library/scrlbar.tcl
@@ -129,30 +129,20 @@ bind Scrollbar <<LineEnd>> {
}
}
-set HiresScrollMask 512
-set ShiftMask 1
bind Scrollbar <MouseWheel> {
- if {[expr {%s & $ShiftMask}]} {
- set orientation "h";
+ set direction [tk::ScrollDirection %s]
+ if {[tk::IsHiResScroll %s]} {
+ tk::ScrollByUnits %W $direction %D -10.0
} else {
- set orientation "v";
- }
- if {[expr {%s & $HiresScrollMask}]} {
- tk::ScrollByUnits %W $orientation %D -10.0
- } else {
- tk::ScrollByUnits %W $orientation [tk::ScaleNum %D] -30.0
+ tk::ScrollByUnits %W $direction [tk::ScaleNum %D] -30.0
}
}
bind Scrollbar <Option-MouseWheel> {
- if {[expr {%s & $ShiftMask}]} {
- set orientation "h";
- } else {
- set orientation "v";
- }
- if {[expr {%s & $HiresScrollMask}]} {
- tk::ScrollByUnits %W $orientation %D -1.0
+ set direction [tk::ScrollDirection %s]
+ if {[tk::IsHiResScroll %s]} {
+ tk::ScrollByUnits %W $direction %D -1.0
} else {
- tk::ScrollByUnits %W $orientation [tk::ScaleNum %D] -3.0
+ tk::ScrollByUnits %W $direction [tk::ScaleNum %D] -3.0
}
}
diff --git a/library/text.tcl b/library/text.tcl
index 73ec714..631759d 100644
--- a/library/text.tcl
+++ b/library/text.tcl
@@ -455,30 +455,29 @@ bind Text <B2-Motion> {
}
}
set ::tk::Priv(prevPos) {}
-set HiresScrollMask 512
bind Text <MouseWheel> {
- if {[expr {%s & $HiresScrollMask}]} {
+ if {[tk::IsHiResScroll %s]} {
tk::MouseWheel %W y %D -1.0 pixels
} else {
tk::MouseWheel %W y [tk::ScaleNum %D] -4.0 pixels
}
}
bind Text <Option-MouseWheel> {
- if {[expr {%s & $HiresScrollMask}]} {
+ if {[tk::IsHiResScroll %s]} {
tk::MouseWheel %W y %D -0.3 pixels
} else {
tk::MouseWheel %W y [tk::ScaleNum %D] -1.2 pixels
}
}
bind Text <Shift-MouseWheel> {
- if {[expr {%s & $HiresScrollMask}]} {
+ if {[tk::IsHiResScroll %s]} {
tk::MouseWheel %W x %D -1.0 pixels
} else {
tk::MouseWheel %W x [tk::ScaleNum %D] -4.0 pixels
}
}
bind Text <Shift-Option-MouseWheel> {
- if {[expr {%s & $HiresScrollMask}]} {
+ if {[tk::IsHiResScroll %s]} {
tk::MouseWheel %W x %D -0.3 pixels
} else {
tk::MouseWheel %W x [tk::ScaleNum %D] -1.2 pixels
diff --git a/library/tk.tcl b/library/tk.tcl
index a6dc37c..74942cb 100644
--- a/library/tk.tcl
+++ b/library/tk.tcl
@@ -543,6 +543,30 @@ proc ::tk::CancelRepeat {} {
set Priv(afterId) {}
}
+
+# ::tk::IsHiResScroll $state --
+# Checks whether the HiResScrollMask bit is set in the state.
+
+proc ::tk::IsHiResScroll state {
+ if {[expr {$state & 512}]} {
+ return 1
+ } else {
+ return 0
+ }
+}
+
+# ::tk::ScrollDirection $state --
+# Checks if ShiftMask is set in the MouseWheelEvent state.
+# Returns h for a horizontal scroll, v for a vertical scroll
+
+proc ::tk::ScrollDirection state {
+ if {[expr {$state & 1}]} {
+ return "h"
+ } else {
+ return "v"
+ }
+}
+
## ::tk::MouseWheel $w $dir $amount $factor $units
proc ::tk::MouseWheel {w dir amount {factor -120.0} {units units}} {