msgbox.tcl 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. # msgbox.tcl --
  2. #
  3. # Implements messageboxes for platforms that do not have native
  4. # messagebox support.
  5. #
  6. # Copyright © 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. # Uses ::tk::Priv.${disp}(button) instead of ::tk::Priv(button) to
  124. # avoid adverse effects of [::tk::ScreenChanged]. Bug [e2cec2fa41].
  125. #
  126. # This procedure is a private procedure shouldn't be called
  127. # directly. Call tk_messageBox instead.
  128. #
  129. # See the user documentation for details on what tk_messageBox does.
  130. #
  131. proc ::tk::MessageBox {args} {
  132. global tk_strictMotif
  133. variable ::tk::Priv
  134. set w ::tk::PrivMsgBox
  135. upvar $w data
  136. #
  137. # The default value of the title is space (" ") not the empty string
  138. # because for some window managers, a
  139. # wm title .foo ""
  140. # causes the window title to be "foo" instead of the empty string.
  141. #
  142. set specs {
  143. {-default "" "" ""}
  144. {-detail "" "" ""}
  145. {-icon "" "" "info"}
  146. {-message "" "" ""}
  147. {-parent "" "" .}
  148. {-title "" "" " "}
  149. {-type "" "" "ok"}
  150. }
  151. tclParseConfigSpec $w $specs "" $args
  152. if {$data(-icon) ni {info warning error question}} {
  153. return -code error -errorcode [list TK LOOKUP ICON $data(-icon)] \
  154. "bad -icon value \"$data(-icon)\": must be error, info, question, or warning"
  155. }
  156. set windowingsystem [tk windowingsystem]
  157. if {$windowingsystem eq "aqua"} {
  158. switch -- $data(-icon) {
  159. "error" {set data(-icon) "stop"}
  160. "warning" {set data(-icon) "caution"}
  161. "info" {set data(-icon) "note"}
  162. }
  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. # Select the vwait variable carefully.
  169. set oldScreen $Priv(screen)
  170. set screen [winfo screen $data(-parent)]
  171. # Extract the display name (cf. ScreenChanged, including [Bug 2912473] fix).
  172. set disp [string range $screen 0 [string last . $screen]-1]
  173. # Ensure that namespace separators never occur in the display name (as
  174. # they cause problems in variable names). Double-colons exist in some VNC
  175. # display names. [Bug 2912473]
  176. set disp [string map {:: _doublecolon_} $disp]
  177. if {![info exists ::tk::Priv.${disp}]} {
  178. # Use ScreenChanged to create ::tk::Priv.${disp}, then change back to old
  179. # screen to avoid interfering with Tk expectations for bindings.
  180. ScreenChanged $screen
  181. ScreenChanged $oldScreen
  182. }
  183. variable ::tk::Priv.${disp}
  184. # Now in place of ::tk::Priv(button), use ::tk::Priv.${disp}(button) which
  185. # is the intended target variable of upvar and will not be redefined when
  186. # ::tk::ScreenChanged is called.
  187. switch -- $data(-type) {
  188. abortretryignore {
  189. set names [list abort retry ignore]
  190. set labels [list &Abort &Retry &Ignore]
  191. set cancel abort
  192. }
  193. ok {
  194. set names [list ok]
  195. set labels {&OK}
  196. set cancel ok
  197. }
  198. okcancel {
  199. set names [list ok cancel]
  200. set labels [list &OK &Cancel]
  201. set cancel cancel
  202. }
  203. retrycancel {
  204. set names [list retry cancel]
  205. set labels [list &Retry &Cancel]
  206. set cancel cancel
  207. }
  208. yesno {
  209. set names [list yes no]
  210. set labels [list &Yes &No]
  211. set cancel no
  212. }
  213. yesnocancel {
  214. set names [list yes no cancel]
  215. set labels [list &Yes &No &Cancel]
  216. set cancel cancel
  217. }
  218. default {
  219. return -code error -errorcode [list TK LOOKUP DLG_TYPE $data(-type)] \
  220. "bad -type value \"$data(-type)\": must be\
  221. abortretryignore, ok, okcancel, retrycancel,\
  222. yesno, or yesnocancel"
  223. }
  224. }
  225. set buttons {}
  226. foreach name $names lab $labels {
  227. lappend buttons [list $name -text [mc $lab]]
  228. }
  229. # If no default button was specified, the default default is the
  230. # first button (Bug: 2218).
  231. if {$data(-default) eq ""} {
  232. set data(-default) [lindex [lindex $buttons 0] 0]
  233. }
  234. set valid 0
  235. foreach btn $buttons {
  236. if {[lindex $btn 0] eq $data(-default)} {
  237. set valid 1
  238. break
  239. }
  240. }
  241. if {!$valid} {
  242. return -code error -errorcode {TK MSGBOX DEFAULT} \
  243. "bad -default value \"$data(-default)\": must be\
  244. abort, retry, ignore, ok, cancel, no, or yes"
  245. }
  246. # 2. Set the dialog to be a child window of $parent
  247. #
  248. #
  249. if {$data(-parent) ne "."} {
  250. set w $data(-parent).__tk__messagebox
  251. } else {
  252. set w .__tk__messagebox
  253. }
  254. # There is only one background colour for the whole dialog
  255. set bg [ttk::style lookup . -background]
  256. # 3. Create the top-level window and divide it into top
  257. # and bottom parts.
  258. catch {destroy $w}
  259. toplevel $w -class Dialog -bg $bg
  260. wm title $w $data(-title)
  261. wm iconname $w Dialog
  262. wm protocol $w WM_DELETE_WINDOW [list $w.$cancel invoke]
  263. # Message boxes should be transient with respect to their parent so that
  264. # they always stay on top of the parent window. But some window managers
  265. # will simply create the child window as withdrawn if the parent is not
  266. # viewable (because it is withdrawn or iconified). This is not good for
  267. # "grab"bed windows. So only make the message box transient if the parent
  268. # is viewable.
  269. #
  270. if {[winfo viewable [winfo toplevel $data(-parent)]] } {
  271. wm transient $w $data(-parent)
  272. }
  273. if {$windowingsystem eq "aqua"} {
  274. ::tk::unsupported::MacWindowStyle style $w moveableModal {}
  275. } elseif {$windowingsystem eq "x11"} {
  276. wm attributes $w -type dialog
  277. }
  278. ttk::frame $w.bot
  279. grid anchor $w.bot center
  280. pack $w.bot -side bottom -fill both
  281. ttk::frame $w.top
  282. pack $w.top -side top -fill both -expand 1
  283. # 4. Fill the top part with bitmap, message and detail (use the
  284. # option database for -wraplength and -font so that they can be
  285. # overridden by the caller).
  286. option add *Dialog.msg.wrapLength 3i widgetDefault
  287. option add *Dialog.dtl.wrapLength 3i widgetDefault
  288. option add *Dialog.msg.font TkCaptionFont widgetDefault
  289. option add *Dialog.dtl.font TkDefaultFont widgetDefault
  290. ttk::label $w.msg -anchor nw -justify left -text $data(-message)
  291. if {$data(-detail) ne ""} {
  292. ttk::label $w.dtl -anchor nw -justify left -text $data(-detail)
  293. }
  294. if {$data(-icon) ne ""} {
  295. if {([winfo depth $w] < 4) || $tk_strictMotif} {
  296. # ttk::label has no -bitmap option
  297. label $w.bitmap -bitmap $data(-icon) -background $bg
  298. } else {
  299. switch $data(-icon) {
  300. error {
  301. ttk::label $w.bitmap -image ::tk::icons::error
  302. }
  303. info {
  304. ttk::label $w.bitmap -image ::tk::icons::information
  305. }
  306. question {
  307. ttk::label $w.bitmap -image ::tk::icons::question
  308. }
  309. default {
  310. ttk::label $w.bitmap -image ::tk::icons::warning
  311. }
  312. }
  313. }
  314. }
  315. grid $w.bitmap $w.msg -in $w.top -sticky news -padx 2m -pady 2m
  316. grid configure $w.bitmap -sticky nw
  317. grid columnconfigure $w.top 1 -weight 1
  318. if {$data(-detail) ne ""} {
  319. grid ^ $w.dtl -in $w.top -sticky news -padx 2m -pady {0 2m}
  320. grid rowconfigure $w.top 1 -weight 1
  321. } else {
  322. grid rowconfigure $w.top 0 -weight 1
  323. }
  324. # 5. Create a row of buttons at the bottom of the dialog.
  325. set i 0
  326. foreach but $buttons {
  327. set name [lindex $but 0]
  328. set opts [lrange $but 1 end]
  329. if {![llength $opts]} {
  330. # Capitalize the first letter of $name
  331. set capName [string toupper $name 0]
  332. set opts [list -text $capName]
  333. }
  334. eval [list tk::AmpWidget ttk::button $w.$name] $opts \
  335. [list -command [list set tk::Priv.${disp}(button) $name]]
  336. if {$name eq $data(-default)} {
  337. $w.$name configure -default active
  338. } else {
  339. $w.$name configure -default normal
  340. }
  341. grid $w.$name -in $w.bot -row 0 -column $i -padx 3m -pady 2m -sticky ew
  342. grid columnconfigure $w.bot $i -uniform buttons
  343. # We boost the size of some Mac buttons for l&f
  344. if {$windowingsystem eq "aqua"} {
  345. set tmp [string tolower $name]
  346. if {$tmp eq "ok" || $tmp eq "cancel" || $tmp eq "yes" ||
  347. $tmp eq "no" || $tmp eq "abort" || $tmp eq "retry" ||
  348. $tmp eq "ignore"} {
  349. grid columnconfigure $w.bot $i -minsize 90
  350. }
  351. grid configure $w.$name -pady 7
  352. }
  353. incr i
  354. # create the binding for the key accelerator, based on the underline
  355. #
  356. # set underIdx [$w.$name cget -under]
  357. # if {$underIdx >= 0} {
  358. # set key [string index [$w.$name cget -text] $underIdx]
  359. # bind $w <Alt-[string tolower $key]> [list $w.$name invoke]
  360. # bind $w <Alt-[string toupper $key]> [list $w.$name invoke]
  361. # }
  362. }
  363. bind $w <Alt-Key> [list ::tk::AltKeyInDialog $w %A]
  364. if {$data(-default) ne ""} {
  365. bind $w <FocusIn> {
  366. if {[winfo class %W] in "Button TButton"} {
  367. %W configure -default active
  368. }
  369. }
  370. bind $w <FocusOut> {
  371. if {[winfo class %W] in "Button TButton"} {
  372. %W configure -default normal
  373. }
  374. }
  375. }
  376. # 6. Create bindings for <Return>, <Escape> and <Destroy> on the dialog
  377. bind $w <Return> {
  378. if {[winfo class %W] in "Button TButton"} {
  379. %W invoke
  380. }
  381. }
  382. # Invoke the designated cancelling operation
  383. bind $w <Escape> [list $w.$cancel invoke]
  384. # At <Destroy> the buttons have vanished, so must do this directly.
  385. bind $w.msg <Destroy> [list set tk::Priv.${disp}(button) $cancel]
  386. # 7. Withdraw the window, then update all the geometry information
  387. # so we know how big it wants to be, then center the window in the
  388. # display (Motif style) and de-iconify it.
  389. ::tk::PlaceWindow $w widget $data(-parent)
  390. # 8. Set a grab and claim the focus too.
  391. if {$data(-default) ne ""} {
  392. set focus $w.$data(-default)
  393. } else {
  394. set focus $w
  395. }
  396. ::tk::SetFocusGrab $w $focus
  397. # 9. Wait for the user to respond, then restore the focus and
  398. # return the index of the selected button. Restore the focus
  399. # before deleting the window, since otherwise the window manager
  400. # may take the focus away so we can't redirect it. Finally,
  401. # restore any grab that was in effect.
  402. vwait ::tk::Priv.${disp}(button)
  403. # Copy the result now so any <Destroy> that happens won't cause
  404. # trouble
  405. set result [set Priv.${disp}(button)]
  406. ::tk::RestoreFocusGrab $w $focus
  407. return $result
  408. }