3
# This file defines the default bindings for Tk label, button,
4
# checkbutton, and radiobutton widgets and provides procedures
5
# that help in implementing those bindings.
7
# @(#) button.tcl 1.17 95/05/05 16:56:01
9
# Copyright (c) 1992-1994 The Regents of the University of California.
10
# Copyright (c) 1994 Sun Microsystems, Inc.
12
# See the file "license.terms" for information on usage and redistribution
13
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
16
#-------------------------------------------------------------------------
17
# The code below creates the default class bindings for buttons.
18
#-------------------------------------------------------------------------
20
bind Button <FocusIn> {}
30
bind Button <ButtonRelease-1> {
36
bind Button <Return> {
42
bind Checkbutton <FocusIn> {}
43
bind Checkbutton <Enter> {
46
bind Checkbutton <Leave> {
49
bind Checkbutton <1> {
52
bind Checkbutton <space> {
55
bind Checkbutton <Return> {
61
bind Radiobutton <FocusIn> {}
62
bind Radiobutton <Enter> {
65
bind Radiobutton <Leave> {
68
bind Radiobutton <1> {
71
bind Radiobutton <space> {
74
bind Radiobutton <Return> {
81
# The procedure below is invoked when the mouse pointer enters a
82
# button widget. It records the button we're in and changes the
83
# state of the button to active unless the button is disabled.
86
# w - The name of the widget.
88
proc tkButtonEnter {w} {
90
if {[$w cget -state] != "disabled"} {
91
$w config -state active
92
if {$tkPriv(buttonWindow) == $w} {
93
$w configure -state active -relief sunken
100
# The procedure below is invoked when the mouse pointer leaves a
101
# button widget. It changes the state of the button back to
102
# inactive. If we're leaving the button window with a mouse button
103
# pressed (tkPriv(buttonWindow) == $w), restore the relief of the
107
# w - The name of the widget.
109
proc tkButtonLeave w {
111
if {[$w cget -state] != "disabled"} {
112
$w config -state normal
114
if {$w == $tkPriv(buttonWindow)} {
115
$w configure -relief $tkPriv(relief)
117
set tkPriv(window) ""
121
# The procedure below is invoked when the mouse button is pressed in
122
# a button widget. It records the fact that the mouse is in the button,
123
# saves the button's relief so it can be restored later, and changes
124
# the relief to sunken.
127
# w - The name of the widget.
129
proc tkButtonDown w {
131
set tkPriv(relief) [lindex [$w config -relief] 4]
132
if {[$w cget -state] != "disabled"} {
133
set tkPriv(buttonWindow) $w
134
$w config -relief sunken
139
# The procedure below is invoked when the mouse button is released
140
# in a button widget. It restores the button's relief and invokes
141
# the command as long as the mouse hasn't left the button.
144
# w - The name of the widget.
148
if {$w == $tkPriv(buttonWindow)} {
149
set tkPriv(buttonWindow) ""
150
$w config -relief $tkPriv(relief)
151
if {($w == $tkPriv(window))
152
&& ([$w cget -state] != "disabled")} {
153
uplevel #0 [list $w invoke]
159
# The procedure below is called when a button is invoked through
160
# the keyboard. It simulate a press of the button via the mouse.
163
# w - The name of the widget.
165
proc tkButtonInvoke w {
166
if {[$w cget -state] != "disabled"} {
167
set oldRelief [$w cget -relief]
168
set oldState [$w cget -state]
169
$w configure -state active -relief sunken
172
$w configure -state $oldState -relief $oldRelief
173
uplevel #0 [list $w invoke]
177
# tkCheckRadioInvoke --
178
# The procedure below is invoked when the mouse button is pressed in
179
# a checkbutton or radiobutton widget, or when the widget is invoked
180
# through the keyboard. It invokes the widget if it
184
# w - The name of the widget.
186
proc tkCheckRadioInvoke w {
187
if {[$w cget -state] != "disabled"} {
188
uplevel #0 [list $w invoke]