2 # Bindings for TScrollbar widget
5 # Still don't have a working ttk::scrollbar under OSX -
6 # Swap in a [tk::scrollbar] on that platform,
7 # unless user specifies -class or -style.
9 if {[tk windowingsystem
] eq
"aqua"} {
10 rename ::ttk::scrollbar ::ttk::_scrollbar
11 proc ttk
::scrollbar {w args
} {
12 set constructor
::tk::scrollbar
13 foreach {option _
} $args {
14 if {$option eq
"-class" ||
$option eq
"-style"} {
15 set constructor
::ttk::_scrollbar
19 return [$constructor $w {*}$args]
23 namespace eval ttk
::scrollbar {
26 # State(yPress) -- initial position of mouse at start of drag.
27 # State(first) -- value of -first at start of drag.
30 bind TScrollbar
<ButtonPress-1
> { ttk
::scrollbar::Press %W
%x
%y
}
31 bind TScrollbar
<B1-Motion
> { ttk
::scrollbar::Drag %W
%x
%y
}
32 bind TScrollbar
<ButtonRelease-1
> { ttk
::scrollbar::Release %W
%x
%y
}
34 bind TScrollbar
<ButtonPress-2
> { ttk
::scrollbar::Jump %W
%x
%y
}
35 bind TScrollbar
<B2-Motion
> { ttk
::scrollbar::Drag %W
%x
%y
}
36 bind TScrollbar
<ButtonRelease-2
> { ttk
::scrollbar::Release %W
%x
%y
}
38 proc ttk
::scrollbar::Scroll {w n units
} {
39 set cmd
[$w cget
-command]
41 uplevel #0 $cmd scroll $n $units
45 proc ttk
::scrollbar::Moveto {w fraction
} {
46 set cmd
[$w cget
-command]
48 uplevel #0 $cmd moveto $fraction
52 proc ttk
::scrollbar::Press {w x y
} {
58 switch -glob -- [$w identify
$x $y] {
61 ttk
::Repeatedly Scroll
$w -1 units
65 ttk
::Repeatedly Scroll
$w 1 units
68 set State
(first
) [lindex [$w get
] 0]
71 set f
[$w fraction
$x $y]
72 if {$f < [lindex [$w get
] 0]} {
73 # Clicked in upper/left trough
74 ttk
::Repeatedly Scroll
$w -1 pages
75 } elseif
{$f > [lindex [$w get
] 1]} {
76 # Clicked in lower/right trough
77 ttk
::Repeatedly Scroll
$w 1 pages
79 # Clicked on thumb (???)
80 set State
(first
) [lindex [$w get
] 0]
86 proc ttk
::scrollbar::Drag {w x y
} {
88 if {![info exists State
(first
)]} {
89 # Initial buttonpress was not on the thumb,
90 # or something screwy has happened. In either case, ignore:
93 set xDelta
[expr {$x - $State(xPress
)}]
94 set yDelta
[expr {$y - $State(yPress
)}]
95 Moveto
$w [expr {$State(first
) + [$w delta
$xDelta $yDelta]}]
98 proc ttk
::scrollbar::Release {w x y
} {
100 unset -nocomplain State
(xPress
) State
(yPress
) State
(first
)
104 # scrollbar::Jump -- ButtonPress-2 binding for scrollbars.
105 # Behaves exactly like scrollbar::Press, except that
106 # clicking in the trough jumps to the the selected position.
108 proc ttk
::scrollbar::Jump {w x y
} {
111 switch -glob -- [$w identify
$x $y] {
114 set State
(first
) [$w fraction
$x $y]
115 Moveto
$w $State(first
)