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 / combobox.tcl < prev    next >
Text File  |  1998-09-19  |  6KB  |  180 lines

  1. # $XConsortium: combobox.tcl /main/1 1996/09/21 14:15:02 kaleb $
  2. #
  3. #
  4. #
  5. #
  6. # $XFree86: xc/programs/Xserver/hw/xfree86/XF86Setup/tcllib/combobox.tcl,v 3.6 1996/12/27 06:54:54 dawes Exp $
  7. #
  8. # Copyright 1996 by Joseph V. Moss <joe@XFree86.Org>
  9. #
  10. # See the file "LICENSE" for information regarding redistribution terms,
  11. # and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13.  
  14. # Implements a simple combobox widget
  15.  
  16. proc combobox {w args} {
  17.     global tcl_library
  18.  
  19.     frame $w
  20.     # putting the # in front does a pretty good job of hiding things
  21.     rename $w #$w.frame
  22.     proc $w {args} "eval [list \\#combobox_proc $w] \$args"
  23.  
  24.     entry $w.entry -relief sunken -bd 1m
  25.     button $w.button -command "\\#combobox_popup [list $w]" \
  26.         -bitmap @$tcl_library/downarrow.xbm
  27.     pack $w.entry $w.button -side left
  28.  
  29.     toplevel $w.popup -cursor top_left_arrow
  30.  
  31.     listbox $w.popup.list -yscroll "$w.popup.sb set" \
  32.         -selectmode browse -relief sunken -bd 1m
  33.     scrollbar $w.popup.sb -command "$w.popup.list yview"
  34.  
  35.     set topwin [winfo toplevel $w]
  36.     wm withdraw $w.popup
  37.     wm transient $w.popup $topwin
  38.     wm overrideredirect $w.popup 1
  39.  
  40.     bind $w.popup.list <ButtonRelease-1> "\\#combobox_buttonrel [list $w]"
  41.  
  42.     if [llength $args] {
  43.         eval "\\#combobox_proc [list $w] econfig $args"
  44.     }
  45. }
  46.  
  47. proc #combobox_proc {w op args} {
  48.  
  49.     set p $w.popup
  50.     switch -- $op {
  51.         activate    {return [eval [list $p.list  activate]  $args]}
  52.         bbox    {return [eval [list $p.list  bbox]      $args]}
  53.         ecget    {return [eval [list $w.entry cget]      $args]}
  54.         lcget    {return [eval [list $p.list  cget]      $args]}
  55.         econfig    {return [eval [list $w.entry configure] $args]}
  56.         lconfig    {return [eval [list $p.list  configure] $args]}
  57.         curselection {return [eval \
  58.                 [list $p.list curselection] $args]}
  59.         edelete    {return [eval [list $w.entry delete]    $args]}
  60.         ldelete    {return [eval [list $p.list  delete]    $args]}
  61.         eget    {return [eval [list $w.entry get]       $args]}
  62.         lget    {return [eval [list $p.list  get]       $args]}
  63.         icursor    {return [eval [list $w.entry icursor]   $args]}
  64.         eindex    {return [eval [list $w.entry index]     $args]}
  65.         lindex    {return [eval [list $p.list  index]     $args]}
  66.         einsert    {return [eval [list $w.entry insert]    $args]}
  67.         linsert    {return [eval [list $p.list  insert]    $args]}
  68.         nearest    {return [eval [list $p.list  nearest]   $args]}
  69.         escan    {return [eval [list $w.entry scan]      $args]}
  70.         lscan    {return [eval [list $p.list  scan]      $args]}
  71.         see        {return [eval [list $p.list  see]       $args]}
  72.         eselection    {return [eval [list $w.entry selection] $args]}
  73.         lselection    {return [eval [list $p.list  selection] $args]}
  74.         size    {return [eval [list $p.list  size]      $args]}
  75.         exview    {return [eval [list $w.entry xview]     $args]}
  76.         lxview    {return [eval [list $p.list  xview]     $args]}
  77.         yview    {return [eval [list $p.list  yview]     $args]}
  78.         default    {error "Unknown option" }
  79.     }
  80. }
  81.  
  82. proc #combobox_popup { w } {
  83.     global tcl_library #combobox_vars
  84.  
  85.     set count [$w.popup.list size]
  86.     if { $count == 0 } return
  87.     pack forget $w.popup.sb $w.popup.list
  88.     set #combobox_vars(focus) [focus]
  89.     if { $count > 10 } {
  90.         set wid [winfo width $w.entry]
  91.         $w.popup.list configure -height 10 -width [$w.entry cget -width]
  92.         #$w.popup.list configure -height 10
  93.         incr wid [expr [winfo width $w.button] +1 ]
  94.         pack $w.popup.list -side left -fill x -expand yes
  95.         pack $w.popup.sb   -side left -fill y -expand yes
  96.     } else {
  97.         set wid [winfo width $w.entry]
  98.         #$w.popup.list configure -height $count -width $wid
  99.         $w.popup.list configure -height $count -width [$w.entry cget -width]
  100.         pack $w.popup.list -side left -fill x -expand yes
  101.     }
  102.     update idletasks
  103.     set ht   [winfo reqheight $w.popup]
  104.     set xpos [winfo rootx $w]
  105.     set ypos [expr [winfo rooty $w]+[winfo reqheight $w]]
  106.     wm geometry $w.popup ${wid}x${ht}+${xpos}+${ypos}
  107.     #$w.popup.list configure -width [winfo width $w.entry]
  108.     #pack $w.popup.sb   -side left -fill y -expand yes
  109.     wm deiconify $w.popup
  110.     raise $w.popup
  111.     #$w.button configure -state disabled
  112.     #grab -global $w.popup
  113.     grab $w.popup
  114.     bind $w.popup <ButtonPress-1> "\\#combobox_checkmsepos [list $w] %X %Y"
  115.     bind $w.popup.list <Return> "\\#combobox_popdown [list $w]"
  116.     #bind $w.popup.list <Escape> "\\#combobox_popdown [list $w]"
  117.     $w.button configure -command "\\#combobox_popdown [list $w]" \
  118.         -bitmap @$tcl_library/uparrow.xbm
  119.     set #combobox_vars($w,x) [winfo rootx $w]
  120.     set #combobox_vars($w,y) [winfo rooty $w]
  121.     bind [winfo toplevel $w] <Configure> "\\#combobox_follow [list $w]"
  122.     if [string length [focus]] {
  123.         focus $w.popup.list
  124.     }
  125. }
  126.  
  127. proc #combobox_follow { w } {
  128.     global #combobox_vars
  129.  
  130.     regexp {([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+)} \
  131.         [wm geometry $w.popup] dummy pw ph px py
  132.     set oldx [set #combobox_vars($w,x)]
  133.     set oldy [set #combobox_vars($w,y)]
  134.     set newx [expr $px+[winfo rootx $w]-$oldx]
  135.     set newy [expr $py+[winfo rooty $w]-$oldy]
  136.     wm geometry $w.popup ${pw}x${ph}+${newx}+${newy}
  137.     set #combobox_vars($w,x) [winfo rootx $w]
  138.     set #combobox_vars($w,y) [winfo rooty $w]
  139. }
  140.  
  141. proc #combobox_popdown { w } {
  142.     global tcl_library #combobox_vars
  143.  
  144.     wm withdraw $w.popup
  145.     #$w.button configure -state normal
  146.     grab release $w.popup
  147.     if { [info exists #combobox_vars(focus)]
  148.         && [string length [set #combobox_vars(focus)]] } {
  149.         focus [set #combobox_vars(focus)]
  150.     }
  151.     set entry ""
  152.     foreach selection [$w.popup.list curselection] {
  153.         set text [$w.popup.list get $selection]
  154.         if {    [string compare $text "<None>"  ] != 0 &&
  155.             [string compare $text "<Probed>"] != 0 } {
  156.         append entry ",$text"
  157.         }
  158.     }
  159.     set oldstate [$w.entry cget -state]
  160.     $w.entry configure -state normal
  161.     $w.entry delete 0 end
  162.     $w.entry insert end [string range $entry 1 end]
  163.     $w.entry configure -state $oldstate
  164.     $w.button configure -command "\\#combobox_popup [list $w]" \
  165.         -bitmap @$tcl_library/downarrow.xbm
  166. }
  167.  
  168. proc #combobox_buttonrel { w } {
  169.     set mode [$w.popup.list cget -selectmode]
  170.     if { "$mode" == "multiple" || "$mode" == "extended" } return
  171.     \#combobox_popdown $w
  172. }
  173.  
  174. proc #combobox_checkmsepos { w xpos ypos } {
  175.     set curwin [winfo containing $xpos $ypos]
  176.     if { "[winfo toplevel $curwin]" == "$w.popup" } return
  177.     \#combobox_popdown $w
  178. }
  179.  
  180.