3 # This file defines the default bindings for Tk scale widgets and provides
4 # procedures that help in implementing the bindings.
6 # RCS: @(#) $Id: scale.tcl,v 1.9.2.5 2006/03/17 10:50:11 patthoyts Exp $
8 # Copyright (c) 1994 The Regents of the University of California.
9 # Copyright (c) 1994-1995 Sun Microsystems, Inc.
11 # See the file "license.terms" for information on usage and redistribution
12 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 #-------------------------------------------------------------------------
16 # The code below creates the default class bindings for entries.
17 #-------------------------------------------------------------------------
19 # Standard Motif bindings:
22 if {$tk_strictMotif} {
23 set tk::Priv(activeBg
) [%W cget
-activebackground]
24 %W configure
-activebackground [%W cget
-background]
26 tk::ScaleActivate %W
%x
%y
29 tk::ScaleActivate %W
%x
%y
32 if {$tk_strictMotif} {
33 %W configure
-activebackground $tk::Priv(activeBg
)
35 if {[%W cget
-state] eq
"active"} {
36 %W configure
-state normal
40 tk::ScaleButtonDown %W
%x
%y
42 bind Scale
<B1-Motion
> {
43 tk::ScaleDrag %W
%x
%y
45 bind Scale
<B1-Leave
> { }
46 bind Scale
<B1-Enter
> { }
47 bind Scale
<ButtonRelease-1
> {
50 tk::ScaleActivate %W
%x
%y
53 tk::ScaleButton2Down %W
%x
%y
55 bind Scale
<B2-Motion
> {
56 tk::ScaleDrag %W
%x
%y
58 bind Scale
<B2-Leave
> { }
59 bind Scale
<B2-Enter
> { }
60 bind Scale
<ButtonRelease-2
> {
63 tk::ScaleActivate %W
%x
%y
65 if {$tcl_platform(platform
) eq
"windows"} {
66 # On Windows do the same with button 3, as that is the right mouse button
67 bind Scale
<3> [bind Scale
<2>]
68 bind Scale
<B3-Motion
> [bind Scale
<B2-Motion
>]
69 bind Scale
<B3-Leave
> [bind Scale
<B2-Leave
>]
70 bind Scale
<B3-Enter
> [bind Scale
<B2-Enter
>]
71 bind Scale
<ButtonRelease-3
> [bind Scale
<ButtonRelease-2
>]
73 bind Scale
<Control-1
> {
74 tk::ScaleControlPress %W
%x
%y
77 tk::ScaleIncrement %W up little noRepeat
80 tk::ScaleIncrement %W down little noRepeat
83 tk::ScaleIncrement %W up little noRepeat
86 tk::ScaleIncrement %W down little noRepeat
88 bind Scale
<Control-Up
> {
89 tk::ScaleIncrement %W up big noRepeat
91 bind Scale
<Control-Down
> {
92 tk::ScaleIncrement %W down big noRepeat
94 bind Scale
<Control-Left
> {
95 tk::ScaleIncrement %W up big noRepeat
97 bind Scale
<Control-Right
> {
98 tk::ScaleIncrement %W down big noRepeat
101 %W
set [%W cget
-from]
107 # ::tk::ScaleActivate --
108 # This procedure is invoked to check a given x-y position in the
109 # scale and activate the slider if the x-y position falls within
113 # w - The scale widget.
114 # x, y - Mouse coordinates.
116 proc ::tk::ScaleActivate {w x y
} {
117 if {[$w cget
-state] eq
"disabled"} {
120 if {[$w identify
$x $y] eq
"slider"} {
125 if {[$w cget
-state] ne
$state} {
126 $w configure
-state $state
130 # ::tk::ScaleButtonDown --
131 # This procedure is invoked when a button is pressed in a scale. It
132 # takes different actions depending on where the button was pressed.
135 # w - The scale widget.
136 # x, y - Mouse coordinates of button press.
138 proc ::tk::ScaleButtonDown {w x y
} {
141 set el
[$w identify
$x $y]
144 set Priv
($w,relief
) [$w cget
-sliderrelief]
146 if {$el eq
"trough1"} {
147 ScaleIncrement
$w up little initial
148 } elseif
{$el eq
"trough2"} {
149 ScaleIncrement
$w down little initial
150 } elseif
{$el eq
"slider"} {
152 set Priv
(initValue
) [$w get
]
153 set coords
[$w coords
]
154 set Priv
(deltaX
) [expr {$x - [lindex $coords 0]}]
155 set Priv
(deltaY
) [expr {$y - [lindex $coords 1]}]
156 switch -exact -- $Priv($w,relief
) {
157 "raised" { $w configure
-sliderrelief sunken
}
158 "ridge" { $w configure
-sliderrelief groove
}
164 # This procedure is called when the mouse is dragged with
165 # mouse button 1 down. If the drag started inside the slider
166 # (i.e. the scale is active) then the scale's value is adjusted
167 # to reflect the mouse's position.
170 # w - The scale widget.
171 # x, y - Mouse coordinates.
173 proc ::tk::ScaleDrag {w x y
} {
175 if {!$Priv(dragging
)} {
178 $w set [$w get
[expr {$x-$Priv(deltaX
)}] [expr {$y-$Priv(deltaY
)}]]
181 # ::tk::ScaleEndDrag --
182 # This procedure is called to end an interactive drag of the
183 # slider. It just marks the drag as over.
186 # w - The scale widget.
188 proc ::tk::ScaleEndDrag {w
} {
191 if {[info exists Priv
($w,relief
)]} {
192 $w configure
-sliderrelief $Priv($w,relief
)
193 unset Priv
($w,relief
)
197 # ::tk::ScaleIncrement --
198 # This procedure is invoked to increment the value of a scale and
199 # to set up auto-repeating of the action if that is desired. The
200 # way the value is incremented depends on the "dir" and "big"
204 # w - The scale widget.
205 # dir - "up" means move value towards -from, "down" means
207 # big - Size of increments: "big" or "little".
208 # repeat - Whether and how to auto-repeat the action: "noRepeat"
209 # means don't auto-repeat, "initial" means this is the
210 # first action in an auto-repeat sequence, and "again"
211 # means this is the second repetition or later.
213 proc ::tk::ScaleIncrement {w dir big repeat
} {
215 if {![winfo exists
$w]} return
217 set inc
[$w cget
-bigincrement]
219 set inc
[expr {abs
([$w cget
-to] - [$w cget
-from])/10.0}]
221 if {$inc < [$w cget
-resolution]} {
222 set inc
[$w cget
-resolution]
225 set inc
[$w cget
-resolution]
227 if {([$w cget
-from] > [$w cget
-to]) ^
($dir eq
"up")} {
228 set inc
[expr {-$inc}]
230 $w set [expr {[$w get
] + $inc}]
232 if {$repeat eq
"again"} {
233 set Priv
(afterId
) [after [$w cget
-repeatinterval] \
234 [list tk::ScaleIncrement $w $dir $big again
]]
235 } elseif
{$repeat eq
"initial"} {
236 set delay
[$w cget
-repeatdelay]
238 set Priv
(afterId
) [after $delay \
239 [list tk::ScaleIncrement $w $dir $big again
]]
244 # ::tk::ScaleControlPress --
245 # This procedure handles button presses that are made with the Control
246 # key down. Depending on the mouse position, it adjusts the scale
247 # value to one end of the range or the other.
250 # w - The scale widget.
251 # x, y - Mouse coordinates where the button was pressed.
253 proc ::tk::ScaleControlPress {w x y
} {
254 set el
[$w identify
$x $y]
255 if {$el eq
"trough1"} {
256 $w set [$w cget
-from]
257 } elseif
{$el eq
"trough2"} {
262 # ::tk::ScaleButton2Down
263 # This procedure is invoked when button 2 is pressed over a scale.
264 # It sets the value to correspond to the mouse position and starts
268 # w - The scrollbar widget.
269 # x, y - Mouse coordinates within the widget.
271 proc ::tk::ScaleButton2Down {w x y
} {
274 if {[$w cget
-state] eq
"disabled"} {
277 $w configure
-state active
278 $w set [$w get
$x $y]
280 set Priv
(initValue
) [$w get
]
281 set Priv
($w,relief
) [$w cget
-sliderrelief]