123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175 |
- proc ::tk_dialog {w title text bitmap default args} {
- variable ::tk::Priv
- if {[string is integer -strict $default]} {
- if {$default >= [llength $args]} {
- return -code error -errorcode {TK DIALOG BAD_DEFAULT} \
- "default button index greater than number of buttons\
- specified for tk_dialog"
- }
- } elseif {"" eq $default} {
- set default -1
- } else {
- set default [lsearch -exact $args $default]
- }
- set windowingsystem [tk windowingsystem]
- destroy $w
- toplevel $w -class Dialog
- wm title $w $title
- wm iconname $w Dialog
- wm protocol $w WM_DELETE_WINDOW { }
- if {[winfo viewable [winfo toplevel [winfo parent $w]]] } {
- wm transient $w [winfo toplevel [winfo parent $w]]
- }
- if {$windowingsystem eq "aqua"} {
- ::tk::unsupported::MacWindowStyle style $w moveableModal {}
- } elseif {$windowingsystem eq "x11"} {
- wm attributes $w -type dialog
- }
- frame $w.bot
- frame $w.top
- if {$windowingsystem eq "x11"} {
- $w.bot configure -relief raised -bd 1
- $w.top configure -relief raised -bd 1
- }
- pack $w.bot -side bottom -fill both
- pack $w.top -side top -fill both -expand 1
- grid anchor $w.bot center
- option add *Dialog.msg.wrapLength 3i widgetDefault
- option add *Dialog.msg.font TkCaptionFont widgetDefault
- label $w.msg -justify left -text $text
- pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 3m -pady 3m
- if {$bitmap ne ""} {
- if {$windowingsystem eq "aqua" && $bitmap eq "error"} {
- set bitmap "stop"
- }
- label $w.bitmap -bitmap $bitmap
- pack $w.bitmap -in $w.top -side left -padx 3m -pady 3m
- }
- set i 0
- foreach but $args {
- button $w.button$i -text $but -command [list set ::tk::Priv(button) $i]
- if {$i == $default} {
- $w.button$i configure -default active
- } else {
- $w.button$i configure -default normal
- }
- grid $w.button$i -in $w.bot -column $i -row 0 -sticky ew \
- -padx 10 -pady 4
- grid columnconfigure $w.bot $i
- if {$windowingsystem eq "aqua"} {
- set tmp [string tolower $but]
- if {$tmp eq "ok" || $tmp eq "cancel"} {
- grid columnconfigure $w.bot $i -minsize 90
- }
- grid configure $w.button$i -pady 7
- }
- incr i
- }
- if {$default >= 0} {
- bind $w <Return> [list $w.button$default invoke]
- }
- bind $w <<PrevWindow>> [list bind $w <Return> {[tk_focusPrev %W] invoke}]
- bind $w <<NextWindow>> [list bind $w <Return> {[tk_focusNext %W] invoke}]
- bind $w <Destroy> {set ::tk::Priv(button) -1}
- ::tk::PlaceWindow $w
- tkwait visibility $w
- if {$default >= 0} {
- set focus $w.button$default
- } else {
- set focus $w
- }
- tk::SetFocusGrab $w $focus
- vwait ::tk::Priv(button)
- catch {
- bind $w <Destroy> {}
- }
- tk::RestoreFocusGrab $w $focus
- return $Priv(button)
- }
|