summaryrefslogtreecommitdiffstats
path: root/library/dialog.tcl
diff options
context:
space:
mode:
authorpatthoyts <patthoyts@users.sourceforge.net>2010-01-04 21:22:08 (GMT)
committerpatthoyts <patthoyts@users.sourceforge.net>2010-01-04 21:22:08 (GMT)
commita8ccacbdfade151ad3f55b530a1841cdb78d7f47 (patch)
tree83f909d61e5648d9f1f170aba1afebdeb0946e75 /library/dialog.tcl
parent046353d490342a66945758497b9f7a8b4c93bdf5 (diff)
downloadtk-a8ccacbdfade151ad3f55b530a1841cdb78d7f47.zip
tk-a8ccacbdfade151ad3f55b530a1841cdb78d7f47.tar.gz
tk-a8ccacbdfade151ad3f55b530a1841cdb78d7f47.tar.bz2
Fix the <Return> binding for tk_dialog to invoke the focused button.
The standard for Windows and Gtk+ is that the <Return> binding invokes the button that currently has the keyboard focus. This can be seen in tk_messageBox which implements this. This patch implements this feature and also makes use of the tk grab utility functions to replace the grab handling code.
Diffstat (limited to 'library/dialog.tcl')
-rw-r--r--library/dialog.tcl35
1 files changed, 11 insertions, 24 deletions
diff --git a/library/dialog.tcl b/library/dialog.tcl
index b032b62..5012823 100644
--- a/library/dialog.tcl
+++ b/library/dialog.tcl
@@ -3,7 +3,7 @@
# This file defines the procedure tk_dialog, which creates a dialog
# box containing a bitmap, a message, and one or more buttons.
#
-# RCS: @(#) $Id: dialog.tcl,v 1.24 2007/12/13 15:26:27 dgp Exp $
+# RCS: @(#) $Id: dialog.tcl,v 1.25 2010/01/04 21:22:08 patthoyts Exp $
#
# Copyright (c) 1992-1993 The Regents of the University of California.
# Copyright (c) 1994-1997 Sun Microsystems, Inc.
@@ -129,15 +129,14 @@ proc ::tk_dialog {w title text bitmap default args} {
# 4. Create a binding for <Return> on the dialog if there is a
# default button.
+ # Convention also dictates that if the keyboard focus moves among the
+ # the buttons that the <Return> binding affects the button with the focus.
if {$default >= 0} {
- bind $w <Return> "
- [list $w.button$default] configure -state active -relief sunken
- update idletasks
- after 100
- set ::tk::Priv(button) $default
- "
+ bind $w <Return> [list $w.button$default invoke]
}
+ bind $w <<PrevWindow>> [list bind $w <Return> {[tk_focusPrev %W] invoke}]
+ bind $w <<NextWindow>> [list bind $w <Return> {[tk_focusNext %W] invoke}]
# 5. Create a <Destroy> binding for the window that sets the
# button variable to -1; this is needed in case something happens
@@ -172,17 +171,12 @@ proc ::tk_dialog {w title text bitmap default args} {
# 7. Set a grab and claim the focus too.
- set oldFocus [focus]
- set oldGrab [grab current $w]
- if {$oldGrab ne ""} {
- set grabStatus [grab status $oldGrab]
- }
- grab $w
if {$default >= 0} {
- focus $w.button$default
+ set focus $w.button$default
} else {
- focus $w
+ set focus $w
}
+ tk::SetFocusGrab $w $focus
# 8. Wait for the user to respond, then restore the focus and
# return the index of the selected button. Restore the focus
@@ -191,21 +185,14 @@ proc ::tk_dialog {w title text bitmap default args} {
# restore any grab that was in effect.
vwait ::tk::Priv(button)
- catch {focus $oldFocus}
+
catch {
# It's possible that the window has already been destroyed,
# hence this "catch". Delete the Destroy handler so that
# Priv(button) doesn't get reset by it.
bind $w <Destroy> {}
- destroy $w
- }
- if {$oldGrab ne ""} {
- if {$grabStatus ne "global"} {
- grab $oldGrab
- } else {
- grab -global $oldGrab
- }
}
+ tk::RestoreFocusGrab $w $focus
return $Priv(button)
}