home *** CD-ROM | disk | FTP | other *** search
/ PCNET 2006 September - Disc 1 / PCNET_CD_2006_09.iso / linux / puppy-barebones-2.01r2.iso / pup_201.sfs / usr / lib / tk8.5 / msgbox.tcl < prev    next >
Encoding:
Text File  |  2006-06-17  |  16.1 KB  |  441 lines

  1. # msgbox.tcl --
  2. #
  3. #    Implements messageboxes for platforms that do not have native
  4. #    messagebox support.
  5. #
  6. # RCS: @(#) $Id: msgbox.tcl,v 1.30 2006/01/25 18:22:04 dgp Exp $
  7. #
  8. # Copyright (c) 1994-1997 Sun Microsystems, Inc.
  9. #
  10. # See the file "license.terms" for information on usage and redistribution
  11. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13.  
  14. # Ensure existence of ::tk::dialog namespace
  15. #
  16. namespace eval ::tk::dialog {}
  17.  
  18. image create bitmap ::tk::dialog::b1 -foreground black \
  19. -data "#define b1_width 32\n#define b1_height 32
  20. static unsigned char q1_bits[] = {
  21.    0x00, 0xf8, 0x1f, 0x00, 0x00, 0x07, 0xe0, 0x00, 0xc0, 0x00, 0x00, 0x03,
  22.    0x20, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x10,
  23.    0x04, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40,
  24.    0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80,
  25.    0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80,
  26.    0x01, 0x00, 0x00, 0x80, 0x02, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x40,
  27.    0x04, 0x00, 0x00, 0x20, 0x08, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x08,
  28.    0x60, 0x00, 0x00, 0x04, 0x80, 0x03, 0x80, 0x03, 0x00, 0x0c, 0x78, 0x00,
  29.    0x00, 0x30, 0x04, 0x00, 0x00, 0x40, 0x04, 0x00, 0x00, 0x40, 0x04, 0x00,
  30.    0x00, 0x80, 0x04, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x06, 0x00,
  31.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};"
  32. image create bitmap ::tk::dialog::b2 -foreground white \
  33. -data "#define b2_width 32\n#define b2_height 32
  34. static unsigned char b2_bits[] = {
  35.    0x00, 0x00, 0x00, 0x00, 0x00, 0xf8, 0x1f, 0x00, 0x00, 0xff, 0xff, 0x00,
  36.    0xc0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0x0f,
  37.    0xf8, 0xff, 0xff, 0x1f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f,
  38.    0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f,
  39.    0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f, 0xfe, 0xff, 0xff, 0x7f,
  40.    0xfe, 0xff, 0xff, 0x7f, 0xfc, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x3f,
  41.    0xf8, 0xff, 0xff, 0x1f, 0xf0, 0xff, 0xff, 0x0f, 0xe0, 0xff, 0xff, 0x07,
  42.    0x80, 0xff, 0xff, 0x03, 0x00, 0xfc, 0x7f, 0x00, 0x00, 0xf0, 0x07, 0x00,
  43.    0x00, 0xc0, 0x03, 0x00, 0x00, 0x80, 0x03, 0x00, 0x00, 0x80, 0x03, 0x00,
  44.    0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
  45.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};"
  46. image create bitmap ::tk::dialog::q -foreground blue \
  47. -data "#define q_width 32\n#define q_height 32
  48. static unsigned char q_bits[] = {
  49.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  50.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0x07, 0x00,
  51.    0x00, 0x10, 0x0f, 0x00, 0x00, 0x18, 0x1e, 0x00, 0x00, 0x38, 0x1e, 0x00,
  52.    0x00, 0x38, 0x1e, 0x00, 0x00, 0x10, 0x0f, 0x00, 0x00, 0x80, 0x07, 0x00,
  53.    0x00, 0xc0, 0x01, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00,
  54.    0x00, 0x00, 0x00, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0xe0, 0x01, 0x00,
  55.    0x00, 0xe0, 0x01, 0x00, 0x00, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  56.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  57.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  58.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  59.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};"
  60. image create bitmap ::tk::dialog::i -foreground blue \
  61. -data "#define i_width 32\n#define i_height 32
  62. static unsigned char i_bits[] = {
  63.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  64.    0x00, 0xe0, 0x01, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0xf0, 0x03, 0x00,
  65.    0x00, 0xe0, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  66.    0x00, 0xf8, 0x03, 0x00, 0x00, 0xf0, 0x03, 0x00, 0x00, 0xe0, 0x03, 0x00,
  67.    0x00, 0xe0, 0x03, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xe0, 0x03, 0x00,
  68.    0x00, 0xe0, 0x03, 0x00, 0x00, 0xe0, 0x03, 0x00, 0x00, 0xf0, 0x07, 0x00,
  69.    0x00, 0xf8, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  70.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  71.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  72.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  73.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};"
  74. image create bitmap ::tk::dialog::w1 -foreground black \
  75. -data "#define w1_width 32\n#define w1_height 32
  76. static unsigned char w1_bits[] = {
  77.    0x00, 0x80, 0x01, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x20, 0x04, 0x00,
  78.    0x00, 0x10, 0x04, 0x00, 0x00, 0x10, 0x08, 0x00, 0x00, 0x08, 0x08, 0x00,
  79.    0x00, 0x08, 0x10, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x04, 0x20, 0x00,
  80.    0x00, 0x02, 0x20, 0x00, 0x00, 0x02, 0x40, 0x00, 0x00, 0x01, 0x40, 0x00,
  81.    0x00, 0x01, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x80, 0x00, 0x00, 0x01,
  82.    0x40, 0x00, 0x00, 0x01, 0x40, 0x00, 0x00, 0x02, 0x20, 0x00, 0x00, 0x02,
  83.    0x20, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x08,
  84.    0x08, 0x00, 0x00, 0x08, 0x08, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00, 0x10,
  85.    0x04, 0x00, 0x00, 0x20, 0x02, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x40,
  86.    0x01, 0x00, 0x00, 0x40, 0x01, 0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x20,
  87.    0xfc, 0xff, 0xff, 0x1f, 0x00, 0x00, 0x00, 0x00};"
  88. image create bitmap ::tk::dialog::w2 -foreground yellow \
  89. -data "#define w2_width 32\n#define w2_height 32
  90. static unsigned char w2_bits[] = {
  91.    0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0xc0, 0x03, 0x00,
  92.    0x00, 0xe0, 0x03, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xf0, 0x07, 0x00,
  93.    0x00, 0xf0, 0x0f, 0x00, 0x00, 0xf8, 0x0f, 0x00, 0x00, 0xf8, 0x1f, 0x00,
  94.    0x00, 0xfc, 0x1f, 0x00, 0x00, 0xfc, 0x3f, 0x00, 0x00, 0xfe, 0x3f, 0x00,
  95.    0x00, 0xfe, 0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0xff, 0x00,
  96.    0x80, 0xff, 0xff, 0x00, 0x80, 0xff, 0xff, 0x01, 0xc0, 0xff, 0xff, 0x01,
  97.    0xc0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x03, 0xe0, 0xff, 0xff, 0x07,
  98.    0xf0, 0xff, 0xff, 0x07, 0xf0, 0xff, 0xff, 0x0f, 0xf8, 0xff, 0xff, 0x0f,
  99.    0xf8, 0xff, 0xff, 0x1f, 0xfc, 0xff, 0xff, 0x1f, 0xfe, 0xff, 0xff, 0x3f,
  100.    0xfe, 0xff, 0xff, 0x3f, 0xfe, 0xff, 0xff, 0x3f, 0xfc, 0xff, 0xff, 0x1f,
  101.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};"
  102. image create bitmap ::tk::dialog::w3 -foreground black \
  103. -data "#define w3_width 32\n#define w3_height 32
  104. static unsigned char w3_bits[] = {
  105.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  106.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  107.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  108.    0x00, 0xc0, 0x03, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
  109.    0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00, 0x00, 0xe0, 0x07, 0x00,
  110.    0x00, 0xc0, 0x03, 0x00, 0x00, 0xc0, 0x03, 0x00, 0x00, 0xc0, 0x03, 0x00,
  111.    0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00,
  112.    0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0xc0, 0x03, 0x00,
  113.    0x00, 0xc0, 0x03, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
  114.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  115.    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};"
  116.  
  117. # ::tk::MessageBox --
  118. #
  119. #    Pops up a messagebox with an application-supplied message with
  120. #    an icon and a list of buttons. This procedure will be called
  121. #    by tk_messageBox if the platform does not have native
  122. #    messagebox support, or if the particular type of messagebox is
  123. #    not supported natively.
  124. #
  125. #    Color icons are used on Unix displays that have a color
  126. #    depth of 4 or more and $tk_strictMotif is not on.
  127. #
  128. #    This procedure is a private procedure shouldn't be called
  129. #    directly. Call tk_messageBox instead.
  130. #
  131. #    See the user documentation for details on what tk_messageBox does.
  132. #
  133. proc ::tk::MessageBox {args} {
  134.     global tcl_platform tk_strictMotif
  135.     variable ::tk::Priv
  136.  
  137.     set w ::tk::PrivMsgBox
  138.     upvar $w data
  139.  
  140.     #
  141.     # The default value of the title is space (" ") not the empty string
  142.     # because for some window managers, a 
  143.     #        wm title .foo ""
  144.     # causes the window title to be "foo" instead of the empty string.
  145.     #
  146.     set specs {
  147.     {-default "" "" ""}
  148.     {-detail "" "" ""}
  149.         {-icon "" "" "info"}
  150.         {-message "" "" ""}
  151.         {-parent "" "" .}
  152.         {-title "" "" " "}
  153.         {-type "" "" "ok"}
  154.     }
  155.  
  156.     tclParseConfigSpec $w $specs "" $args
  157.  
  158.     if {[lsearch -exact {info warning error question} $data(-icon)] == -1} {
  159.     error "bad -icon value \"$data(-icon)\": must be error, info, question, or warning"
  160.     }
  161.     set windowingsystem [tk windowingsystem]
  162.     if {$windowingsystem eq "aqua"} {
  163.     switch -- $data(-icon) {
  164.         "error"     {set data(-icon) "stop"}
  165.         "warning"   {set data(-icon) "caution"}
  166.         "info"      {set data(-icon) "note"}
  167.     }
  168.     }
  169.  
  170.     if {![winfo exists $data(-parent)]} {
  171.     error "bad window path name \"$data(-parent)\""
  172.     }
  173.  
  174.     switch -- $data(-type) {
  175.     abortretryignore { 
  176.         set names [list abort retry ignore]
  177.         set labels [list &Abort &Retry &Ignore]
  178.         set cancel abort
  179.     }
  180.     ok {
  181.         set names [list ok]
  182.         set labels {&OK}
  183.         set cancel ok
  184.     }
  185.     okcancel {
  186.         set names [list ok cancel]
  187.         set labels [list &OK &Cancel]
  188.         set cancel cancel
  189.     }
  190.     retrycancel {
  191.         set names [list retry cancel]
  192.         set labels [list &Retry &Cancel]
  193.         set cancel cancel
  194.     }
  195.     yesno {
  196.         set names [list yes no]
  197.         set labels [list &Yes &No]
  198.         set cancel no
  199.     }
  200.     yesnocancel {
  201.         set names [list yes no cancel]
  202.         set labels [list &Yes &No &Cancel]
  203.         set cancel cancel
  204.     }
  205.     default {
  206.         error "bad -type value \"$data(-type)\": must be\
  207.             abortretryignore, ok, okcancel, retrycancel,\
  208.             yesno, or yesnocancel"
  209.     }
  210.     }
  211.  
  212.     set buttons {}
  213.     foreach name $names lab $labels {
  214.     lappend buttons [list $name -text [mc $lab]]
  215.     }
  216.  
  217.     # If no default button was specified, the default default is the 
  218.     # first button (Bug: 2218).
  219.  
  220.     if {$data(-default) eq ""} {
  221.     set data(-default) [lindex [lindex $buttons 0] 0]
  222.     }
  223.  
  224.     set valid 0
  225.     foreach btn $buttons {
  226.     if {[lindex $btn 0] eq $data(-default)} {
  227.         set valid 1
  228.         break
  229.     }
  230.     }
  231.     if {!$valid} {
  232.     error "invalid default button \"$data(-default)\""
  233.     }
  234.  
  235.     # 2. Set the dialog to be a child window of $parent
  236.     #
  237.     #
  238.     if {$data(-parent) ne "."} {
  239.     set w $data(-parent).__tk__messagebox
  240.     } else {
  241.     set w .__tk__messagebox
  242.     }
  243.  
  244.     # 3. Create the top-level window and divide it into top
  245.     # and bottom parts.
  246.  
  247.     catch {destroy $w}
  248.     toplevel $w -class Dialog
  249.     wm title $w $data(-title)
  250.     wm iconname $w Dialog
  251.     wm protocol $w WM_DELETE_WINDOW { }
  252.     # There is only one background colour for the whole dialog
  253.     set bg [$w cget -background]
  254.  
  255.     # Message boxes should be transient with respect to their parent so that
  256.     # they always stay on top of the parent window.  But some window managers
  257.     # will simply create the child window as withdrawn if the parent is not
  258.     # viewable (because it is withdrawn or iconified).  This is not good for
  259.     # "grab"bed windows.  So only make the message box transient if the parent
  260.     # is viewable.
  261.     #
  262.     if {[winfo viewable [winfo toplevel $data(-parent)]] } {
  263.     wm transient $w $data(-parent)
  264.     }    
  265.  
  266.     if {$windowingsystem eq "aqua"} {
  267.     unsupported::MacWindowStyle style $w dBoxProc
  268.     }
  269.  
  270.     frame $w.bot -background $bg
  271.     grid anchor $w.bot center
  272.     pack $w.bot -side bottom -fill both
  273.     frame $w.top -background $bg
  274.     pack $w.top -side top -fill both -expand 1
  275.     if {$windowingsystem ne "aqua"} {
  276.     $w.bot configure -relief raised -bd 1
  277.     $w.top configure -relief raised -bd 1
  278.     }
  279.  
  280.     # 4. Fill the top part with bitmap, message and detail (use the
  281.     # option database for -wraplength and -font so that they can be
  282.     # overridden by the caller).
  283.  
  284.     option add *Dialog.msg.wrapLength 3i widgetDefault
  285.     option add *Dialog.dtl.wrapLength 3i widgetDefault
  286.     if {$windowingsystem eq "aqua"} {
  287.     option add *Dialog.msg.font system widgetDefault
  288.     option add *Dialog.dtl.font system widgetDefault
  289.     } else {
  290.     option add *Dialog.msg.font {Times 14} widgetDefault
  291.     option add *Dialog.dtl.font {Times 10} widgetDefault
  292.     }
  293.  
  294.     label $w.msg -anchor nw -justify left -text $data(-message) \
  295.         -background $bg
  296.     if {$data(-detail) ne ""} {
  297.     label $w.dtl -anchor nw -justify left -text $data(-detail) \
  298.         -background $bg
  299.     }
  300.     if {$data(-icon) ne ""} {
  301.     if {$windowingsystem eq "aqua"
  302.         || ([winfo depth $w] < 4) || $tk_strictMotif} {
  303.         label $w.bitmap -bitmap $data(-icon) -background $bg
  304.     } else {
  305.         canvas $w.bitmap -width 32 -height 32 -highlightthickness 0 \
  306.             -background $bg
  307.         switch $data(-icon) {
  308.         error {
  309.             $w.bitmap create oval 0 0 31 31 -fill red -outline black
  310.             $w.bitmap create line 9 9 23 23 -fill white -width 4
  311.             $w.bitmap create line 9 23 23 9 -fill white -width 4
  312.         }
  313.         info {
  314.             $w.bitmap create image 0 0 -anchor nw \
  315.                 -image ::tk::dialog::b1
  316.             $w.bitmap create image 0 0 -anchor nw \
  317.                 -image ::tk::dialog::b2
  318.             $w.bitmap create image 0 0 -anchor nw \
  319.                 -image ::tk::dialog::i
  320.         }
  321.         question {
  322.             $w.bitmap create image 0 0 -anchor nw \
  323.                 -image ::tk::dialog::b1
  324.             $w.bitmap create image 0 0 -anchor nw \
  325.                 -image ::tk::dialog::b2
  326.             $w.bitmap create image 0 0 -anchor nw \
  327.                 -image ::tk::dialog::q
  328.         }
  329.         default {
  330.             $w.bitmap create image 0 0 -anchor nw \
  331.                 -image ::tk::dialog::w1
  332.             $w.bitmap create image 0 0 -anchor nw \
  333.                 -image ::tk::dialog::w2
  334.             $w.bitmap create image 0 0 -anchor nw \
  335.                 -image ::tk::dialog::w3
  336.         }
  337.         }
  338.     }
  339.     }
  340.     grid $w.bitmap $w.msg -in $w.top -sticky news -padx 2m -pady 2m
  341.     grid columnconfigure $w.top 1 -weight 1
  342.     if {$data(-detail) ne ""} {
  343.     grid ^ $w.dtl -in $w.top -sticky news -padx 2m -pady {0 2m}
  344.     grid rowconfigure $w.top 1 -weight 1
  345.     } else {
  346.     grid rowconfigure $w.top 0 -weight 1
  347.     }
  348.  
  349.     # 5. Create a row of buttons at the bottom of the dialog.
  350.  
  351.     set i 0
  352.     foreach but $buttons {
  353.     set name [lindex $but 0]
  354.     set opts [lrange $but 1 end]
  355.     if {![llength $opts]} {
  356.         # Capitalize the first letter of $name
  357.         set capName [string toupper $name 0]
  358.         set opts [list -text $capName]
  359.     }
  360.  
  361.     eval [list tk::AmpWidget button $w.$name -padx 3m] $opts \
  362.         [list -command [list set tk::Priv(button) $name]]
  363.  
  364.     if {$name eq $data(-default)} {
  365.         $w.$name configure -default active
  366.     } else {
  367.         $w.$name configure -default normal
  368.     }
  369.     grid $w.$name -in $w.bot -row 0 -column $i -padx 3m -pady 2m -sticky ew
  370.     grid columnconfigure $w.bot $i -uniform buttons
  371.         incr i
  372.  
  373.     # create the binding for the key accelerator, based on the underline
  374.     #
  375.         # set underIdx [$w.$name cget -under]
  376.         # if {$underIdx >= 0} {
  377.         #     set key [string index [$w.$name cget -text] $underIdx]
  378.         #     bind $w <Alt-[string tolower $key]>  [list $w.$name invoke]
  379.         #     bind $w <Alt-[string toupper $key]>  [list $w.$name invoke]
  380.         # }
  381.     }
  382.     bind $w <Alt-Key> [list ::tk::AltKeyInDialog $w %A]
  383.  
  384.     if {$data(-default) ne ""} {
  385.     bind $w <FocusIn> {
  386.         if {[winfo class %W] eq "Button"} {
  387.         %W configure -default active
  388.         }
  389.     }
  390.     bind $w <FocusOut> {
  391.         if {[winfo class %W] eq "Button"} {
  392.         %W configure -default normal
  393.         }
  394.     }
  395.     }
  396.  
  397.     # 6. Create bindings for <Return>, <Escape> and <Destroy> on the dialog
  398.  
  399.     bind $w <Return> {
  400.     if {[winfo class %W] eq "Button"} {
  401.         tk::ButtonInvoke %W
  402.     }
  403.     }
  404.  
  405.     # Invoke the designated cancelling operation
  406.     bind $w <Escape> [list tk::ButtonInvoke $w.$cancel]
  407.  
  408.     # At <Destroy> the buttons have vanished, so must do this directly.
  409.     bind $w.msg <Destroy> [list set tk::Priv(button) $cancel]
  410.  
  411.     # 7. Withdraw the window, then update all the geometry information
  412.     # so we know how big it wants to be, then center the window in the
  413.     # display and de-iconify it.
  414.  
  415.     ::tk::PlaceWindow $w widget $data(-parent)
  416.  
  417.     # 8. Set a grab and claim the focus too.
  418.  
  419.     if {$data(-default) ne ""} {
  420.     set focus $w.$data(-default)
  421.     } else {
  422.     set focus $w
  423.     }
  424.     ::tk::SetFocusGrab $w $focus
  425.  
  426.     # 9. Wait for the user to respond, then restore the focus and
  427.     # return the index of the selected button.  Restore the focus
  428.     # before deleting the window, since otherwise the window manager
  429.     # may take the focus away so we can't redirect it.  Finally,
  430.     # restore any grab that was in effect.
  431.  
  432.     vwait ::tk::Priv(button)
  433.     # Copy the result now so any <Destroy> that happens won't cause
  434.     # trouble
  435.     set result $Priv(button)
  436.  
  437.     ::tk::RestoreFocusGrab $w $focus
  438.  
  439.     return $result
  440. }
  441.