summaryrefslogtreecommitdiffstats
path: root/library/button.tcl
diff options
context:
space:
mode:
Diffstat (limited to 'library/button.tcl')
-rw-r--r--library/button.tcl73
1 files changed, 69 insertions, 4 deletions
diff --git a/library/button.tcl b/library/button.tcl
index 8feeba8..0184648 100644
--- a/library/button.tcl
+++ b/library/button.tcl
@@ -4,7 +4,7 @@
# checkbutton, and radiobutton widgets and provides procedures
# that help in implementing those bindings.
#
-# RCS: @(#) $Id: button.tcl,v 1.6 1999/09/02 17:02:52 hobbs Exp $
+# RCS: @(#) $Id: button.tcl,v 1.7 2000/05/13 00:39:08 ericm Exp $
#
# Copyright (c) 1992-1994 The Regents of the University of California.
# Copyright (c) 1994-1996 Sun Microsystems, Inc.
@@ -203,6 +203,14 @@ proc tkButtonDown w {
if {[string compare [$w cget -state] "disabled"]} {
set tkPriv(buttonWindow) $w
$w configure -relief sunken -state active
+
+ # If this button has a repeatdelay set up, get it going with an after
+ after cancel $tkPriv(afterId)
+ set delay [$w cget -repeatdelay]
+ set tkPriv(repeated) 0
+ if {$delay > 0} {
+ set tkPriv(afterId) [after $delay [list tkButtonAutoInvoke $w]]
+ }
}
}
@@ -240,7 +248,12 @@ proc tkButtonUp w {
if {[string equal $tkPriv(window) $w]
&& [string compare [$w cget -state] "disabled"]} {
$w configure -state normal
- uplevel #0 [list $w invoke]
+
+ # Only invoke the command if it wasn't already invoked by the
+ # auto-repeater functionality
+ if { $tkPriv(repeated) == 0 } {
+ uplevel #0 [list $w invoke]
+ }
}
}
}
@@ -308,6 +321,14 @@ proc tkButtonDown w {
if {[string compare [$w cget -state] "disabled"]} {
set tkPriv(buttonWindow) $w
$w configure -relief sunken
+
+ # If this button has a repeatdelay set up, get it going with an after
+ after cancel $tkPriv(afterId)
+ set delay [$w cget -repeatdelay]
+ set tkPriv(repeated) 0
+ if {$delay > 0} {
+ set tkPriv(afterId) [after $delay [list tkButtonAutoInvoke $w]]
+ }
}
}
@@ -324,9 +345,15 @@ proc tkButtonUp w {
if {[string equal $w $tkPriv(buttonWindow)]} {
set tkPriv(buttonWindow) ""
$w configure -relief $tkPriv(relief)
+ after cancel $tkPriv(afterId)
if {[string equal $w $tkPriv(window)] \
&& [string compare [$w cget -state] "disabled"]} {
- uplevel #0 [list $w invoke]
+
+ # Only invoke the command if it wasn't already invoked by the
+ # auto-repeater functionality
+ if { $tkPriv(repeated) == 0 } {
+ uplevel #0 [list $w invoke]
+ }
}
}
}
@@ -389,6 +416,14 @@ proc tkButtonDown w {
if {[string compare [$w cget -state] "disabled"]} {
set tkPriv(buttonWindow) $w
$w configure -state active
+
+ # If this button has a repeatdelay set up, get it going with an after
+ after cancel $tkPriv(afterId)
+ set delay [$w cget -repeatdelay]
+ set tkPriv(repeated) 0
+ if {$delay > 0} {
+ set tkPriv(afterId) [after $delay [list tkButtonAutoInvoke $w]]
+ }
}
}
@@ -407,7 +442,11 @@ proc tkButtonUp w {
set tkPriv(buttonWindow) ""
if {[string equal $w $tkPriv(window)]
&& [string compare [$w cget -state] "disabled"]} {
- uplevel #0 [list $w invoke]
+ # Only invoke the command if it wasn't already invoked by the
+ # auto-repeater functionality
+ if { $tkPriv(repeated) == 0 } {
+ uplevel #0 [list $w invoke]
+ }
}
}
}
@@ -437,6 +476,32 @@ proc tkButtonInvoke w {
}
}
+# tkButtonAutoInvoke --
+#
+# Invoke an auto-repeating button, and set it up to continue to repeat.
+#
+# Arguments:
+# w button to invoke.
+#
+# Results:
+# None.
+#
+# Side effects:
+# May create an after event to call tkButtonAutoInvoke.
+
+proc tkButtonAutoInvoke {w} {
+ global tkPriv
+ after cancel $tkPriv(afterId)
+ set delay [$w cget -repeatinterval]
+ if { [string equal $tkPriv(window) $w] } {
+ incr tkPriv(repeated)
+ uplevel #0 [list $w invoke]
+ }
+ if {$delay > 0} {
+ set tkPriv(afterId) [after $delay [list tkButtonAutoInvoke $w]]
+ }
+}
+
# tkCheckRadioInvoke --
# The procedure below is invoked when the mouse button is pressed in
# a checkbutton or radiobutton widget, or when the widget is invoked