home *** CD-ROM | disk | FTP | other *** search
/ Freesoft 1999 February / Freesoft_1999-02_cd.bin / Recenz / Utility / DisplayDoctorLinux / scitech-display-doctor-1.0beta-3.i386.rpm / scitech-display-doctor-1.0beta.3.cpio.gz / scitech-display-doctor-1.0beta.3.cpio / usr / lib / nucleus / XF86Setup / tcllib / dialog.tcl < prev    next >
Text File  |  1998-09-19  |  4KB  |  131 lines

  1. # $XConsortium: dialog.tcl /main/1 1996/09/21 14:15:10 kaleb $
  2. #
  3. #
  4. #
  5. #
  6. # $XFree86: xc/programs/Xserver/hw/xfree86/XF86Setup/tcllib/dialog.tcl,v 3.1 1996/12/27 06:54:55 dawes Exp $
  7. #
  8. # dialog.tcl --
  9. #
  10. # This file defines the procedure tk_dialog, which creates a dialog
  11. # box containing a bitmap, a message, and one or more buttons.
  12. #
  13. # @(#) dialog.tcl 1.18 95/11/24 15:03:04
  14. #
  15. # Copyright (c) 1992-1993 The Regents of the University of California.
  16. # Copyright (c) 1994-1995 Sun Microsystems, Inc.
  17. #
  18. # See the file "license.terms" for information on usage and redistribution
  19. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  20. #
  21.  
  22. #
  23. # tk_dialog:
  24. #
  25. # This procedure displays a dialog box, waits for a button in the dialog
  26. # to be invoked, then returns the index of the selected button.
  27. #
  28. # Arguments:
  29. # w -        Window to use for dialog top-level.
  30. # title -    Title to display in dialog's decorative frame.
  31. # text -    Message to display in dialog.
  32. # bitmap -    Bitmap to display in dialog (empty string means none).
  33. # default -    Index of button that is to display the default ring
  34. #        (-1 means none).
  35. # args -    One or more strings to display in buttons across the
  36. #        bottom of the dialog box.
  37.  
  38. proc tk_dialog {w title text bitmap default args} {
  39.     global tkPriv
  40.  
  41.     # 1. Create the top-level window and divide it into top
  42.     # and bottom parts.
  43.  
  44.     catch {destroy $w}
  45.     toplevel $w -class Dialog
  46.     wm title $w $title
  47.     wm iconname $w Dialog
  48.     wm protocol $w WM_DELETE_WINDOW { }
  49.     wm transient $w [winfo toplevel [winfo parent $w]]
  50.     frame $w.top -relief raised -bd 1
  51.     pack $w.top -side top -fill both
  52.     frame $w.bot -relief raised -bd 1
  53.     pack $w.bot -side bottom -fill both
  54.  
  55.     # 2. Fill the top part with bitmap and message (use the option
  56.     # database for -wraplength so that it can be overridden by
  57.     # the caller).
  58.  
  59.     option add *Dialog.msg.wrapLength 3i widgetDefault
  60.     label $w.msg -justify left -text $text \
  61.         -font -Adobe-Times-Medium-R-Normal--*-180-*-*-*-*-*-*
  62.     pack $w.msg -in $w.top -side right -expand 1 -fill both -padx 3m -pady 3m
  63.     if {$bitmap != ""} {
  64.     label $w.bitmap -bitmap $bitmap
  65.     pack $w.bitmap -in $w.top -side left -padx 3m -pady 3m
  66.     }
  67.  
  68.     # 3. Create a row of buttons at the bottom of the dialog.
  69.  
  70.     set i 0
  71.     foreach but $args {
  72.     button $w.button$i -text $but -command "set tkPriv(button) $i"
  73.     if {$i == $default} {
  74.         frame $w.default -relief sunken -bd 1
  75.         raise $w.button$i $w.default
  76.         pack $w.default -in $w.bot -side left -expand 1 -padx 3m -pady 2m
  77.         pack $w.button$i -in $w.default -padx 2m -pady 2m
  78.     } else {
  79.         pack $w.button$i -in $w.bot -side left -expand 1 \
  80.             -padx 3m -pady 2m
  81.     }
  82.     incr i
  83.     }
  84.  
  85.     # 4. Withdraw the window, then update all the geometry information
  86.     # so we know how big it wants to be, then center the window in the
  87.     # display and de-iconify it.
  88.  
  89.     wm withdraw $w
  90.     update idletasks
  91.     set x [expr [winfo screenwidth $w]/2 - [winfo reqwidth $w]/2 \
  92.         - [winfo vrootx [winfo parent $w]]]
  93.     set y [expr [winfo screenheight $w]/2 - [winfo reqheight $w]/2 \
  94.         - [winfo vrooty [winfo parent $w]]]
  95.     wm geom $w +$x+$y
  96.     wm deiconify $w
  97.  
  98.     # 5. Set a grab and claim the focus too.
  99.  
  100.     set oldFocus [focus]
  101.     set oldGrab [grab current $w]
  102.     if {$oldGrab != ""} {
  103.     set grabStatus [grab status $oldGrab]
  104.     }
  105.     grab $w
  106.     tkwait visibility $w
  107.     if {$default >= 0} {
  108.     focus $w.button$default
  109.     } else {
  110.     focus $w
  111.     }
  112.  
  113.     # 6. Wait for the user to respond, then restore the focus and
  114.     # return the index of the selected button.  Restore the focus
  115.     # before deleting the window, since otherwise the window manager
  116.     # may take the focus away so we can't redirect it.  Finally,
  117.     # restore any grab that was in effect.
  118.  
  119.     tkwait variable tkPriv(button)
  120.     catch {focus $oldFocus}
  121.     destroy $w
  122.     if {$oldGrab != ""} {
  123.     if {$grabStatus == "global"} {
  124.         grab -global $oldGrab
  125.     } else {
  126.         grab $oldGrab
  127.     }
  128.     }
  129.     return $tkPriv(button)
  130. }
  131.