msgbox.tcl 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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. }
  161. if {![winfo exists $data(-parent)]} {
  162. return -code error -errorcode [list TK LOOKUP WINDOW $data(-parent)] \
  163. "bad window path name \"$data(-parent)\""
  164. }
  165. switch -- $data(-type) {
  166. abortretryignore {
  167. set names [list abort retry ignore]
  168. set labels [list &Abort &Retry &Ignore]
  169. set cancel abort
  170. }
  171. ok {
  172. set names [list ok]
  173. set labels {&OK}
  174. set cancel ok
  175. }
  176. okcancel {
  177. set names [list ok cancel]
  178. set labels [list &OK &Cancel]
  179. set cancel cancel
  180. }
  181. retrycancel {
  182. set names [list retry cancel]
  183. set labels [list &Retry &Cancel]
  184. set cancel cancel
  185. }
  186. yesno {
  187. set names [list yes no]
  188. set labels [list &Yes &No]
  189. set cancel no
  190. }
  191. yesnocancel {
  192. set names [list yes no cancel]
  193. set labels [list &Yes &No &Cancel]
  194. set cancel cancel
  195. }
  196. default {
  197. return -code error -errorcode [list TK LOOKUP DLG_TYPE $data(-type)] \
  198. "bad -type value \"$data(-type)\": must be\
  199. abortretryignore, ok, okcancel, retrycancel,\
  200. yesno, or yesnocancel"
  201. }
  202. }
  203. set buttons {}
  204. foreach name $names lab $labels {
  205. lappend buttons [list $name -text [mc $lab]]
  206. }
  207. # If no default button was specified, the default default is the
  208. # first button (Bug: 2218).
  209. if {$data(-default) eq ""} {
  210. set data(-default) [lindex [lindex $buttons 0] 0]
  211. }
  212. set valid 0
  213. foreach btn $buttons {
  214. if {[lindex $btn 0] eq $data(-default)} {
  215. set valid 1
  216. break
  217. }
  218. }
  219. if {!$valid} {
  220. return -code error -errorcode {TK MSGBOX DEFAULT} \
  221. "bad -default value \"$data(-default)\": must be\
  222. abort, retry, ignore, ok, cancel, no, or yes"
  223. }
  224. # 2. Set the dialog to be a child window of $parent
  225. #
  226. #
  227. if {$data(-parent) ne "."} {
  228. set w $data(-parent).__tk__messagebox
  229. } else {
  230. set w .__tk__messagebox
  231. }
  232. # There is only one background colour for the whole dialog
  233. set bg [ttk::style lookup . -background]
  234. # 3. Create the top-level window and divide it into top
  235. # and bottom parts.
  236. catch {destroy $w}
  237. toplevel $w -class Dialog -bg $bg
  238. wm title $w $data(-title)
  239. wm iconname $w Dialog
  240. wm protocol $w WM_DELETE_WINDOW [list $w.$cancel invoke]
  241. # Message boxes should be transient with respect to their parent so that
  242. # they always stay on top of the parent window. But some window managers
  243. # will simply create the child window as withdrawn if the parent is not
  244. # viewable (because it is withdrawn or iconified). This is not good for
  245. # "grab"bed windows. So only make the message box transient if the parent
  246. # is viewable.
  247. #
  248. if {[winfo viewable [winfo toplevel $data(-parent)]] } {
  249. wm transient $w $data(-parent)
  250. }
  251. if {$windowingsystem eq "aqua"} {
  252. ::tk::unsupported::MacWindowStyle style $w moveableModal {}
  253. } elseif {$windowingsystem eq "x11"} {
  254. wm attributes $w -type dialog
  255. }
  256. ttk::frame $w.bot
  257. grid anchor $w.bot center
  258. pack $w.bot -side bottom -fill both
  259. ttk::frame $w.top
  260. pack $w.top -side top -fill both -expand 1
  261. # 4. Fill the top part with bitmap, message and detail (use the
  262. # option database for -wraplength and -font so that they can be
  263. # overridden by the caller).
  264. option add *Dialog.msg.wrapLength 3i widgetDefault
  265. option add *Dialog.dtl.wrapLength 3i widgetDefault
  266. option add *Dialog.msg.font TkCaptionFont widgetDefault
  267. option add *Dialog.dtl.font TkDefaultFont widgetDefault
  268. ttk::label $w.msg -anchor nw -justify left -text $data(-message)
  269. if {$data(-detail) ne ""} {
  270. ttk::label $w.dtl -anchor nw -justify left -text $data(-detail)
  271. }
  272. if {$data(-icon) ne ""} {
  273. if {([winfo depth $w] < 4) || $tk_strictMotif} {
  274. # ttk::label has no -bitmap option
  275. label $w.bitmap -bitmap $data(-icon) -background $bg
  276. } else {
  277. switch $data(-icon) {
  278. error {
  279. ttk::label $w.bitmap -image ::tk::icons::error
  280. }
  281. info {
  282. ttk::label $w.bitmap -image ::tk::icons::information
  283. }
  284. question {
  285. ttk::label $w.bitmap -image ::tk::icons::question
  286. }
  287. default {
  288. ttk::label $w.bitmap -image ::tk::icons::warning
  289. }
  290. }
  291. }
  292. }
  293. grid $w.bitmap $w.msg -in $w.top -sticky news -padx 2m -pady 2m
  294. grid configure $w.bitmap -sticky nw
  295. grid columnconfigure $w.top 1 -weight 1
  296. if {$data(-detail) ne ""} {
  297. grid ^ $w.dtl -in $w.top -sticky news -padx 2m -pady {0 2m}
  298. grid rowconfigure $w.top 1 -weight 1
  299. } else {
  300. grid rowconfigure $w.top 0 -weight 1
  301. }
  302. # 5. Create a row of buttons at the bottom of the dialog.
  303. set i 0
  304. foreach but $buttons {
  305. set name [lindex $but 0]
  306. set opts [lrange $but 1 end]
  307. if {![llength $opts]} {
  308. # Capitalize the first letter of $name
  309. set capName [string toupper $name 0]
  310. set opts [list -text $capName]
  311. }
  312. eval [list tk::AmpWidget ttk::button $w.$name] $opts \
  313. [list -command [list set tk::Priv(button) $name]]
  314. if {$name eq $data(-default)} {
  315. $w.$name configure -default active
  316. } else {
  317. $w.$name configure -default normal
  318. }
  319. grid $w.$name -in $w.bot -row 0 -column $i -padx 3m -pady 2m -sticky ew
  320. grid columnconfigure $w.bot $i -uniform buttons
  321. # We boost the size of some Mac buttons for l&f
  322. if {$windowingsystem eq "aqua"} {
  323. set tmp [string tolower $name]
  324. if {$tmp eq "ok" || $tmp eq "cancel" || $tmp eq "yes" ||
  325. $tmp eq "no" || $tmp eq "abort" || $tmp eq "retry" ||
  326. $tmp eq "ignore"} {
  327. grid columnconfigure $w.bot $i -minsize 90
  328. }
  329. grid configure $w.$name -pady 7
  330. }
  331. incr i
  332. # create the binding for the key accelerator, based on the underline
  333. #
  334. # set underIdx [$w.$name cget -under]
  335. # if {$underIdx >= 0} {
  336. # set key [string index [$w.$name cget -text] $underIdx]
  337. # bind $w <Alt-[string tolower $key]> [list $w.$name invoke]
  338. # bind $w <Alt-[string toupper $key]> [list $w.$name invoke]
  339. # }
  340. }
  341. bind $w <Alt-Key> [list ::tk::AltKeyInDialog $w %A]
  342. if {$data(-default) ne ""} {
  343. bind $w <FocusIn> {
  344. if {[winfo class %W] in "Button TButton"} {
  345. %W configure -default active
  346. }
  347. }
  348. bind $w <FocusOut> {
  349. if {[winfo class %W] in "Button TButton"} {
  350. %W configure -default normal
  351. }
  352. }
  353. }
  354. # 6. Create bindings for <Return>, <Escape> and <Destroy> on the dialog
  355. bind $w <Return> {
  356. if {[winfo class %W] in "Button TButton"} {
  357. %W invoke
  358. }
  359. }
  360. # Invoke the designated cancelling operation
  361. bind $w <Escape> [list $w.$cancel invoke]
  362. # At <Destroy> the buttons have vanished, so must do this directly.
  363. bind $w.msg <Destroy> [list set tk::Priv(button) $cancel]
  364. # 7. Withdraw the window, then update all the geometry information
  365. # so we know how big it wants to be, then center the window in the
  366. # display (Motif style) and de-iconify it.
  367. ::tk::PlaceWindow $w widget $data(-parent)
  368. # 8. Set a grab and claim the focus too.
  369. if {$data(-default) ne ""} {
  370. set focus $w.$data(-default)
  371. } else {
  372. set focus $w
  373. }
  374. ::tk::SetFocusGrab $w $focus
  375. # 9. Wait for the user to respond, then restore the focus and
  376. # return the index of the selected button. Restore the focus
  377. # before deleting the window, since otherwise the window manager
  378. # may take the focus away so we can't redirect it. Finally,
  379. # restore any grab that was in effect.
  380. vwait ::tk::Priv(button)
  381. # Copy the result now so any <Destroy> that happens won't cause
  382. # trouble
  383. set result $Priv(button)
  384. ::tk::RestoreFocusGrab $w $focus
  385. return $result
  386. }