msgbox.tcl 16 KB

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