# This file defines the default bindings for Tk label, button,
# checkbutton, and radiobutton widgets and provides procedures
# that help in implementing those bindings.
# RCS: @(#) $Id: button.tcl,v 1.17 2002/09/04 02:05:52 hobbs Exp $
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
# Copyright (c) 2002 ActiveState Corporation.
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
#-------------------------------------------------------------------------
# The code below creates the default class bindings for buttons.
#-------------------------------------------------------------------------
if {[string equal
[tk windowingsystem
] "classic"]
||
[string equal
[tk windowingsystem
] "aqua"]} {
bind Radiobutton
<Enter
> {
bind Radiobutton
<ButtonRelease-1
> {
bind Checkbutton
<Enter
> {
bind Checkbutton
<ButtonRelease-1
> {
if {[string equal
"windows" $tcl_platform(platform
)]} {
bind Checkbutton
<equal
> {
tk::CheckRadioInvoke %W select
bind Checkbutton
<plus
> {
tk::CheckRadioInvoke %W select
bind Checkbutton
<minus
> {
tk::CheckRadioInvoke %W deselect
bind Checkbutton
<ButtonRelease-1
> {
bind Checkbutton
<Enter
> {
bind Radiobutton
<ButtonRelease-1
> {
bind Radiobutton
<Enter
> {
if {[string equal
"x11" [tk windowingsystem
]]} {
bind Checkbutton
<Return
> {
bind Radiobutton
<Return
> {
bind Checkbutton
<Enter
> {
bind Radiobutton
<Enter
> {
bind Checkbutton
<space
> {
bind Radiobutton
<space
> {
bind Button
<ButtonRelease-1
> {
bind Checkbutton
<FocusIn
> {}
bind Checkbutton
<Leave
> {
bind Radiobutton
<FocusIn
> {}
bind Radiobutton
<Leave
> {
if {[string equal
"windows" $tcl_platform(platform
)]} {
#########################
#########################
# The procedure below is invoked when the mouse pointer enters a
# button widget. It records the button we're in and changes the
# state of the button to active unless the button is disabled.
# w - The name of the widget.
proc ::tk::ButtonEnter w
{
if {[$w cget
-state] ne
"disabled"} {
# If the mouse button is down, set the relief to sunken on entry.
# Overwise, if there's an -overrelief value, set the relief to that.
set Priv
($w,relief
) [$w cget
-relief]
if {$Priv(buttonWindow
) eq
$w} {
$w configure
-relief sunken
-state active
set Priv
($w,prelief
) sunken
} elseif
{[set over
[$w cget
-overrelief]] ne
""} {
$w configure
-relief $over
set Priv
($w,prelief
) $over
# The procedure below is invoked when the mouse pointer leaves a
# button widget. It changes the state of the button back to inactive.
# Restore any modified relief too.
# w - The name of the widget.
proc ::tk::ButtonLeave w
{
if {[$w cget
-state] ne
"disabled"} {
$w configure
-state normal
# Restore the original button relief if it was changed by Tk.
# That is signaled by the existence of Priv($w,prelief).
if {[info exists Priv
($w,relief
)]} {
if {[info exists Priv
($w,prelief
)] && \
$Priv($w,prelief
) eq
[$w cget
-relief]} {
$w configure
-relief $Priv($w,relief
)
unset -nocomplain Priv
($w,relief
) Priv
($w,prelief
)
# The procedure below is invoked when the mouse button is pressed in
# a button widget. It records the fact that the mouse is in the button,
# saves the button's relief so it can be restored later, and changes
# w - The name of the widget.
proc ::tk::ButtonDown w
{
# Only save the button's relief if it does not yet exist. If there
# is an overrelief setting, Priv($w,relief) will already have been set,
# and the current value of the -relief option will be incorrect.
if {![info exists Priv
($w,relief
)]} {
set Priv
($w,relief
) [$w cget
-relief]
if {[$w cget
-state] ne
"disabled"} {
set Priv
(buttonWindow
) $w
$w configure
-relief sunken
-state active
set Priv
($w,prelief
) sunken
# If this button has a repeatdelay set up, get it going with an after
after cancel
$Priv(afterId
)
set delay
[$w cget
-repeatdelay]
set Priv
(afterId
) [after $delay [list tk::ButtonAutoInvoke $w]]
# The procedure below is invoked when the mouse button is released
# in a button widget. It restores the button's relief and invokes
# the command as long as the mouse hasn't left the button.
# w - The name of the widget.
if {$Priv(buttonWindow
) eq
$w} {
set Priv
(buttonWindow
) ""
# Restore the button's relief if it was cached.
if {[info exists Priv
($w,relief
)]} {
if {[info exists Priv
($w,prelief
)] && \
$Priv($w,prelief
) eq
[$w cget
-relief]} {
$w configure
-relief $Priv($w,relief
)
unset -nocomplain Priv
($w,relief
) Priv
($w,prelief
)
# Clean up the after event from the auto-repeater
after cancel
$Priv(afterId
)
if {$Priv(window
) eq
$w && [$w cget
-state] ne
"disabled"} {
$w configure
-state normal
# Only invoke the command if it wasn't already invoked by the
# auto-repeater functionality
if { $Priv(repeated
) == 0 } {
uplevel #0 [list $w invoke]
# ::tk::CheckRadioEnter --
# The procedure below is invoked when the mouse pointer enters a
# checkbutton or radiobutton widget. It records the button we're in
# and changes the state of the button to active unless the button is
# w - The name of the widget.
proc ::tk::CheckRadioEnter w
{
if {[$w cget
-state] ne
"disabled"} {
if {$Priv(buttonWindow
) eq
$w} {
$w configure
-state active
if {[set over
[$w cget
-overrelief]] ne
""} {
set Priv
($w,relief
) [$w cget
-relief]
set Priv
($w,prelief
) $over
$w configure
-relief $over
# ::tk::CheckRadioDown --
# The procedure below is invoked when the mouse button is pressed in
# a button widget. It records the fact that the mouse is in the button,
# saves the button's relief so it can be restored later, and changes
# w - The name of the widget.
proc ::tk::CheckRadioDown w
{
if {![info exists Priv
($w,relief
)]} {
set Priv
($w,relief
) [$w cget
-relief]
if {[$w cget
-state] ne
"disabled"} {
set Priv
(buttonWindow
) $w
$w configure
-state active
if {[string equal
"x11" [tk windowingsystem
]]} {
# The procedure below is invoked when the mouse pointer enters a
# button widget. It records the button we're in and changes the
# state of the button to active unless the button is disabled.
# w - The name of the widget.
proc ::tk::ButtonEnter {w
} {
if {[$w cget
-state] ne
"disabled"} {
# On unix the state is active just with mouse-over
$w configure
-state active
# If the mouse button is down, set the relief to sunken on entry.
# Overwise, if there's an -overrelief value, set the relief to that.
set Priv
($w,relief
) [$w cget
-relief]
if {$Priv(buttonWindow
) eq
$w} {
$w configure
-relief sunken
set Priv
($w,prelief
) sunken
} elseif
{[set over
[$w cget
-overrelief]] ne
""} {
$w configure
-relief $over
set Priv
($w,prelief
) $over
# The procedure below is invoked when the mouse pointer leaves a
# button widget. It changes the state of the button back to inactive.
# Restore any modified relief too.
# w - The name of the widget.
proc ::tk::ButtonLeave w
{
if {[$w cget
-state] ne
"disabled"} {
$w configure
-state normal
# Restore the original button relief if it was changed by Tk.
# That is signaled by the existence of Priv($w,prelief).
if {[info exists Priv
($w,relief
)]} {
if {[info exists Priv
($w,prelief
)] && \
$Priv($w,prelief
) eq
[$w cget
-relief]} {
$w configure
-relief $Priv($w,relief
)
unset -nocomplain Priv
($w,relief
) Priv
($w,prelief
)
# The procedure below is invoked when the mouse button is pressed in
# a button widget. It records the fact that the mouse is in the button,
# saves the button's relief so it can be restored later, and changes
# w - The name of the widget.
proc ::tk::ButtonDown w
{
# Only save the button's relief if it does not yet exist. If there
# is an overrelief setting, Priv($w,relief) will already have been set,
# and the current value of the -relief option will be incorrect.
if {![info exists Priv
($w,relief
)]} {
set Priv
($w,relief
) [$w cget
-relief]
if {[$w cget
-state] ne
"disabled"} {
set Priv
(buttonWindow
) $w
$w configure
-relief sunken
set Priv
($w,prelief
) sunken
# If this button has a repeatdelay set up, get it going with an after
after cancel
$Priv(afterId
)
set delay
[$w cget
-repeatdelay]
set Priv
(afterId
) [after $delay [list tk::ButtonAutoInvoke $w]]
# The procedure below is invoked when the mouse button is released
# in a button widget. It restores the button's relief and invokes
# the command as long as the mouse hasn't left the button.
# w - The name of the widget.
if {[string equal
$w $Priv(buttonWindow
)]} {
set Priv
(buttonWindow
) ""
# Restore the button's relief if it was cached.
if {[info exists Priv
($w,relief
)]} {
if {[info exists Priv
($w,prelief
)] && \
$Priv($w,prelief
) eq
[$w cget
-relief]} {
$w configure
-relief $Priv($w,relief
)
unset -nocomplain Priv
($w,relief
) Priv
($w,prelief
)
# Clean up the after event from the auto-repeater
after cancel
$Priv(afterId
)
if {$Priv(window
) eq
$w && [$w cget
-state] ne
"disabled"} {
# Only invoke the command if it wasn't already invoked by the
# auto-repeater functionality
if { $Priv(repeated
) == 0 } {
uplevel #0 [list $w invoke]
if {[string equal
[tk windowingsystem
] "classic"]
||
[string equal
[tk windowingsystem
] "aqua"]} {
# The procedure below is invoked when the mouse pointer enters a
# button widget. It records the button we're in and changes the
# state of the button to active unless the button is disabled.
# w - The name of the widget.
proc ::tk::ButtonEnter {w
} {
if {[$w cget
-state] ne
"disabled"} {
# If there's an -overrelief value, set the relief to that.
if {$Priv(buttonWindow
) eq
$w} {
$w configure
-state active
} elseif
{[set over
[$w cget
-overrelief]] ne
""} {
set Priv
($w,relief
) [$w cget
-relief]
set Priv
($w,prelief
) $over
$w configure
-relief $over
# The procedure below is invoked when the mouse pointer leaves a
# button widget. It changes the state of the button back to
# inactive. If we're leaving the button window with a mouse button
# pressed (Priv(buttonWindow) == $w), restore the relief of the
# w - The name of the widget.
proc ::tk::ButtonLeave w
{
if {$w eq
$Priv(buttonWindow
)} {
$w configure
-state normal
# Restore the original button relief if it was changed by Tk.
# That is signaled by the existence of Priv($w,prelief).
if {[info exists Priv
($w,relief
)]} {
if {[info exists Priv
($w,prelief
)] && \
$Priv($w,prelief
) eq
[$w cget
-relief]} {
$w configure
-relief $Priv($w,relief
)
unset -nocomplain Priv
($w,relief
) Priv
($w,prelief
)
# The procedure below is invoked when the mouse button is pressed in
# a button widget. It records the fact that the mouse is in the button,
# saves the button's relief so it can be restored later, and changes
# w - The name of the widget.
proc ::tk::ButtonDown w
{
if {[$w cget
-state] ne
"disabled"} {
set Priv
(buttonWindow
) $w
$w configure
-state active
# If this button has a repeatdelay set up, get it going with an after
after cancel
$Priv(afterId
)
if { ![catch {$w cget
-repeatdelay} delay
] } {
set Priv
(afterId
) [after $delay [list tk::ButtonAutoInvoke $w]]
# The procedure below is invoked when the mouse button is released
# in a button widget. It restores the button's relief and invokes
# the command as long as the mouse hasn't left the button.
# w - The name of the widget.
if {$Priv(buttonWindow
) eq
$w} {
set Priv
(buttonWindow
) ""
$w configure
-state normal
# Restore the button's relief if it was cached.
if {[info exists Priv
($w,relief
)]} {
if {[info exists Priv
($w,prelief
)] && \
$Priv($w,prelief
) eq
[$w cget
-relief]} {
$w configure
-relief $Priv($w,relief
)
unset -nocomplain Priv
($w,relief
) Priv
($w,prelief
)
# Clean up the after event from the auto-repeater
after cancel
$Priv(afterId
)
if {$Priv(window
) eq
$w && [$w cget
-state] ne
"disabled"} {
# Only invoke the command if it wasn't already invoked by the
# auto-repeater functionality
if { $Priv(repeated
) == 0 } {
uplevel #0 [list $w invoke]
# The procedure below is called when a button is invoked through
# the keyboard. It simulate a press of the button via the mouse.
# w - The name of the widget.
proc ::tk::ButtonInvoke w
{
if {[$w cget
-state] ne
"disabled"} {
set oldRelief
[$w cget
-relief]
set oldState
[$w cget
-state]
$w configure
-state active
-relief sunken
$w configure
-state $oldState -relief $oldRelief
uplevel #0 [list $w invoke]
# ::tk::ButtonAutoInvoke --
# Invoke an auto-repeating button, and set it up to continue to repeat.
# May create an after event to call ::tk::ButtonAutoInvoke.
proc ::tk::ButtonAutoInvoke {w
} {
after cancel
$Priv(afterId
)
set delay
[$w cget
-repeatinterval]
if {$Priv(window
) eq
$w} {
uplevel #0 [list $w invoke]
set Priv
(afterId
) [after $delay [list tk::ButtonAutoInvoke $w]]
# ::tk::CheckRadioInvoke --
# The procedure below is invoked when the mouse button is pressed in
# a checkbutton or radiobutton widget, or when the widget is invoked
# through the keyboard. It invokes the widget if it
# w - The name of the widget.
# cmd - The subcommand to invoke (one of invoke, select, or deselect).
proc ::tk::CheckRadioInvoke {w
{cmd invoke
}} {
if {[$w cget
-state] ne
"disabled"} {
uplevel #0 [list $w $cmd]