diff options
Diffstat (limited to 'library/dialog.tcl')
-rw-r--r-- | library/dialog.tcl | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/library/dialog.tcl b/library/dialog.tcl index 504bc9e..26ec7e0 100644 --- a/library/dialog.tcl +++ b/library/dialog.tcl @@ -37,7 +37,6 @@ proc ::tk_dialog {w title text bitmap default args} { return -code error "default button index greater than number of\ buttons specified for tk_dialog" } - # Never call if -strict option is omitted in previous test ! } elseif {"" eq $default} { set default -1 } else { @@ -85,17 +84,14 @@ proc ::tk_dialog {w title text bitmap default args} { } pack $w.bot -side bottom -fill both pack $w.top -side top -fill both -expand 1 + grid anchor $w.bot center # 2. Fill the top part with bitmap and message (use the option # database for -wraplength and -font so that they can be # overridden by the caller). option add *Dialog.msg.wrapLength 3i widgetDefault - if {$windowingsystem eq "aqua"} { - option add *Dialog.msg.font system widgetDefault - } else { - option add *Dialog.msg.font {Times 12} widgetDefault - } + option add *Dialog.msg.font TkCaptionFont widgetDefault label $w.msg -justify left -text $text pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 3m -pady 3m @@ -133,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 <Tab> [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 @@ -158,17 +153,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 @@ -177,21 +167,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) } |