msgbox.tcl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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 tcl_platform 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 {[lsearch -exact {info warning error question} $data(-icon)] == -1} {
  150. error "bad -icon value \"$data(-icon)\": must be error, info, question, or warning"
  151. }
  152. set windowingsystem [tk windowingsystem]
  153. if {$windowingsystem eq "aqua"} {
  154. switch -- $data(-icon) {
  155. "error" {set data(-icon) "stop"}
  156. "warning" {set data(-icon) "caution"}
  157. "info" {set data(-icon) "note"}
  158. }
  159. option add *Dialog*background systemDialogBackgroundActive widgetDefault
  160. option add *Dialog*Button.highlightBackground \
  161. systemDialogBackgroundActive widgetDefault
  162. }
  163. if {![winfo exists $data(-parent)]} {
  164. error "bad window path name \"$data(-parent)\""
  165. }
  166. switch -- $data(-type) {
  167. abortretryignore {
  168. set names [list abort retry ignore]
  169. set labels [list &Abort &Retry &Ignore]
  170. set cancel abort
  171. }
  172. ok {
  173. set names [list ok]
  174. set labels {&OK}
  175. set cancel ok
  176. }
  177. okcancel {
  178. set names [list ok cancel]
  179. set labels [list &OK &Cancel]
  180. set cancel cancel
  181. }
  182. retrycancel {
  183. set names [list retry cancel]
  184. set labels [list &Retry &Cancel]
  185. set cancel cancel
  186. }
  187. yesno {
  188. set names [list yes no]
  189. set labels [list &Yes &No]
  190. set cancel no
  191. }
  192. yesnocancel {
  193. set names [list yes no cancel]
  194. set labels [list &Yes &No &Cancel]
  195. set cancel cancel
  196. }
  197. default {
  198. error "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. error "invalid default button \"$data(-default)\""
  221. }
  222. # 2. Set the dialog to be a child window of $parent
  223. #
  224. #
  225. if {$data(-parent) ne "."} {
  226. set w $data(-parent).__tk__messagebox
  227. } else {
  228. set w .__tk__messagebox
  229. }
  230. # There is only one background colour for the whole dialog
  231. set bg [ttk::style lookup . -background]
  232. # 3. Create the top-level window and divide it into top
  233. # and bottom parts.
  234. catch {destroy $w}
  235. toplevel $w -class Dialog -bg $bg
  236. wm title $w $data(-title)
  237. wm iconname $w Dialog
  238. wm protocol $w WM_DELETE_WINDOW [list $w.$cancel invoke]
  239. # Message boxes should be transient with respect to their parent so that
  240. # they always stay on top of the parent window. But some window managers
  241. # will simply create the child window as withdrawn if the parent is not
  242. # viewable (because it is withdrawn or iconified). This is not good for
  243. # "grab"bed windows. So only make the message box transient if the parent
  244. # is viewable.
  245. #
  246. if {[winfo viewable [winfo toplevel $data(-parent)]] } {
  247. wm transient $w $data(-parent)
  248. }
  249. if {$windowingsystem eq "aqua"} {
  250. ::tk::unsupported::MacWindowStyle style $w moveableModal {}
  251. } elseif {$windowingsystem eq "x11"} {
  252. wm attributes $w -type dialog
  253. }
  254. ttk::frame $w.bot;# -background $bg
  255. grid anchor $w.bot center
  256. pack $w.bot -side bottom -fill both
  257. ttk::frame $w.top;# -background $bg
  258. pack $w.top -side top -fill both -expand 1
  259. if {$windowingsystem ne "aqua"} {
  260. #$w.bot configure -relief raised -bd 1
  261. #$w.top configure -relief raised -bd 1
  262. }
  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. #-background $bg
  272. if {$data(-detail) ne ""} {
  273. ttk::label $w.dtl -anchor nw -justify left -text $data(-detail)
  274. #-background $bg
  275. }
  276. if {$data(-icon) ne ""} {
  277. if {$windowingsystem eq "aqua"
  278. || ([winfo depth $w] < 4) || $tk_strictMotif} {
  279. # ttk::label has no -bitmap option
  280. label $w.bitmap -bitmap $data(-icon);# -background $bg
  281. } else {
  282. canvas $w.bitmap -width 32 -height 32 -highlightthickness 0 \
  283. -background $bg
  284. switch $data(-icon) {
  285. error {
  286. $w.bitmap create oval 0 0 31 31 -fill red -outline black
  287. $w.bitmap create line 9 9 23 23 -fill white -width 4
  288. $w.bitmap create line 9 23 23 9 -fill white -width 4
  289. }
  290. info {
  291. $w.bitmap create image 0 0 -anchor nw \
  292. -image ::tk::dialog::b1
  293. $w.bitmap create image 0 0 -anchor nw \
  294. -image ::tk::dialog::b2
  295. $w.bitmap create image 0 0 -anchor nw \
  296. -image ::tk::dialog::i
  297. }
  298. question {
  299. $w.bitmap create image 0 0 -anchor nw \
  300. -image ::tk::dialog::b1
  301. $w.bitmap create image 0 0 -anchor nw \
  302. -image ::tk::dialog::b2
  303. $w.bitmap create image 0 0 -anchor nw \
  304. -image ::tk::dialog::q
  305. }
  306. default {
  307. $w.bitmap create image 0 0 -anchor nw \
  308. -image ::tk::dialog::w1
  309. $w.bitmap create image 0 0 -anchor nw \
  310. -image ::tk::dialog::w2
  311. $w.bitmap create image 0 0 -anchor nw \
  312. -image ::tk::dialog::w3
  313. }
  314. }
  315. }
  316. }
  317. grid $w.bitmap $w.msg -in $w.top -sticky news -padx 2m -pady 2m
  318. grid columnconfigure $w.top 1 -weight 1
  319. if {$data(-detail) ne ""} {
  320. grid ^ $w.dtl -in $w.top -sticky news -padx 2m -pady {0 2m}
  321. grid rowconfigure $w.top 1 -weight 1
  322. } else {
  323. grid rowconfigure $w.top 0 -weight 1
  324. }
  325. # 5. Create a row of buttons at the bottom of the dialog.
  326. set i 0
  327. foreach but $buttons {
  328. set name [lindex $but 0]
  329. set opts [lrange $but 1 end]
  330. if {![llength $opts]} {
  331. # Capitalize the first letter of $name
  332. set capName [string toupper $name 0]
  333. set opts [list -text $capName]
  334. }
  335. eval [list tk::AmpWidget ttk::button $w.$name] $opts \
  336. [list -command [list set tk::Priv(button) $name]]
  337. # -padx 3m
  338. if {$name eq $data(-default)} {
  339. $w.$name configure -default active
  340. } else {
  341. $w.$name configure -default normal
  342. }
  343. grid $w.$name -in $w.bot -row 0 -column $i -padx 3m -pady 2m -sticky ew
  344. grid columnconfigure $w.bot $i -uniform buttons
  345. # We boost the size of some Mac buttons for l&f
  346. if {$windowingsystem eq "aqua"} {
  347. set tmp [string tolower $name]
  348. if {$tmp eq "ok" || $tmp eq "cancel" || $tmp eq "yes" ||
  349. $tmp eq "no" || $tmp eq "abort" || $tmp eq "retry" ||
  350. $tmp eq "ignore"} {
  351. grid columnconfigure $w.bot $i -minsize 90
  352. }
  353. grid configure $w.$name -pady 7
  354. }
  355. incr i
  356. # create the binding for the key accelerator, based on the underline
  357. #
  358. # set underIdx [$w.$name cget -under]
  359. # if {$underIdx >= 0} {
  360. # set key [string index [$w.$name cget -text] $underIdx]
  361. # bind $w <Alt-[string tolower $key]> [list $w.$name invoke]
  362. # bind $w <Alt-[string toupper $key]> [list $w.$name invoke]
  363. # }
  364. }
  365. bind $w <Alt-Key> [list ::tk::AltKeyInDialog $w %A]
  366. if {$data(-default) ne ""} {
  367. bind $w <FocusIn> {
  368. if {[winfo class %W] in "Button TButton"} {
  369. %W configure -default active
  370. }
  371. }
  372. bind $w <FocusOut> {
  373. if {[winfo class %W] in "Button TButton"} {
  374. %W configure -default normal
  375. }
  376. }
  377. }
  378. # 6. Create bindings for <Return>, <Escape> and <Destroy> on the dialog
  379. bind $w <Return> {
  380. if {[winfo class %W] in "Button TButton"} {
  381. %W invoke
  382. }
  383. }
  384. # Invoke the designated cancelling operation
  385. bind $w <Escape> [list $w.$cancel invoke]
  386. # At <Destroy> the buttons have vanished, so must do this directly.
  387. bind $w.msg <Destroy> [list set tk::Priv(button) $cancel]
  388. # 7. Withdraw the window, then update all the geometry information
  389. # so we know how big it wants to be, then center the window in the
  390. # display (Motif style) and de-iconify it.
  391. ::tk::PlaceWindow $w widget $data(-parent)
  392. # 8. Set a grab and claim the focus too.
  393. if {$data(-default) ne ""} {
  394. set focus $w.$data(-default)
  395. } else {
  396. set focus $w
  397. }
  398. ::tk::SetFocusGrab $w $focus
  399. # 9. Wait for the user to respond, then restore the focus and
  400. # return the index of the selected button. Restore the focus
  401. # before deleting the window, since otherwise the window manager
  402. # may take the focus away so we can't redirect it. Finally,
  403. # restore any grab that was in effect.
  404. vwait ::tk::Priv(button)
  405. # Copy the result now so any <Destroy> that happens won't cause
  406. # trouble
  407. set result $Priv(button)
  408. ::tk::RestoreFocusGrab $w $focus
  409. return $result
  410. }