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 / focus.tcl < prev    next >
Text File  |  1998-09-19  |  5KB  |  188 lines

  1. # $XConsortium: focus.tcl /main/1 1996/09/21 14:15:25 kaleb $
  2. #
  3. #
  4. #
  5. #
  6. # $XFree86: xc/programs/Xserver/hw/xfree86/XF86Setup/tcllib/focus.tcl,v 3.1 1996/12/27 06:54:57 dawes Exp $
  7. #
  8. # focus.tcl --
  9. #
  10. # This file defines several procedures for managing the input
  11. # focus.
  12. #
  13. # @(#) focus.tcl 1.15 95/10/30 08:08:27
  14. #
  15. # Copyright (c) 1994-1995 Sun Microsystems, Inc.
  16. #
  17. # See the file "license.terms" for information on usage and redistribution
  18. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  19. #
  20.  
  21. # tk_focusNext --
  22. # This procedure returns the name of the next window after "w" in
  23. # "focus order" (the window that should receive the focus next if
  24. # Tab is typed in w).  "Next" is defined by a pre-order search
  25. # of a top-level and its non-top-level descendants, with the stacking
  26. # order determining the order of siblings.  The "-takefocus" options
  27. # on windows determine whether or not they should be skipped.
  28. #
  29. # Arguments:
  30. # w -        Name of a window.
  31.  
  32. proc tk_focusNext w {
  33.     set cur $w
  34.     while 1 {
  35.  
  36.     # Descend to just before the first child of the current widget.
  37.  
  38.     set parent $cur
  39.     set children [winfo children $cur]
  40.     set i -1
  41.  
  42.     # Look for the next sibling that isn't a top-level.
  43.  
  44.     while 1 {
  45.         incr i
  46.         if {$i < [llength $children]} {
  47.         set cur [lindex $children $i]
  48.         if {[winfo toplevel $cur] == $cur} {
  49.             continue
  50.         } else {
  51.             break
  52.         }
  53.         }
  54.  
  55.         # No more siblings, so go to the current widget's parent.
  56.         # If it's a top-level, break out of the loop, otherwise
  57.         # look for its next sibling.
  58.  
  59.         set cur $parent
  60.         if {[winfo toplevel $cur] == $cur} {
  61.         break
  62.         }
  63.         set parent [winfo parent $parent]
  64.         set children [winfo children $parent]
  65.         set i [lsearch -exact $children $cur]
  66.     }
  67.     if {($cur == $w) || [tkFocusOK $cur]} {
  68.         return $cur
  69.     }
  70.     }
  71. }
  72.  
  73. # tk_focusPrev --
  74. # This procedure returns the name of the previous window before "w" in
  75. # "focus order" (the window that should receive the focus next if
  76. # Shift-Tab is typed in w).  "Next" is defined by a pre-order search
  77. # of a top-level and its non-top-level descendants, with the stacking
  78. # order determining the order of siblings.  The "-takefocus" options
  79. # on windows determine whether or not they should be skipped.
  80. #
  81. # Arguments:
  82. # w -        Name of a window.
  83.  
  84. proc tk_focusPrev w {
  85.     set cur $w
  86.     while 1 {
  87.  
  88.     # Collect information about the current window's position
  89.     # among its siblings.  Also, if the window is a top-level,
  90.     # then reposition to just after the last child of the window.
  91.     
  92.     if {[winfo toplevel $cur] == $cur}  {
  93.         set parent $cur
  94.         set children [winfo children $cur]
  95.         set i [llength $children]
  96.     } else {
  97.         set parent [winfo parent $cur]
  98.         set children [winfo children $parent]
  99.         set i [lsearch -exact $children $cur]
  100.     }
  101.  
  102.     # Go to the previous sibling, then descend to its last descendant
  103.     # (highest in stacking order.  While doing this, ignore top-levels
  104.     # and their descendants.  When we run out of descendants, go up
  105.     # one level to the parent.
  106.  
  107.     while {$i > 0} {
  108.         incr i -1
  109.         set cur [lindex $children $i]
  110.         if {[winfo toplevel $cur] == $cur} {
  111.         continue
  112.         }
  113.         set parent $cur
  114.         set children [winfo children $parent]
  115.         set i [llength $children]
  116.     }
  117.     set cur $parent
  118.     if {($cur == $w) || [tkFocusOK $cur]} {
  119.         return $cur
  120.     }
  121.     }
  122. }
  123.  
  124. # tkFocusOK --
  125. #
  126. # This procedure is invoked to decide whether or not to focus on
  127. # a given window.  It returns 1 if it's OK to focus on the window,
  128. # 0 if it's not OK.  The code first checks whether the window is
  129. # viewable.  If not, then it never focuses on the window.  Then it
  130. # checks the -takefocus option for the window and uses it if it's
  131. # set.  If there's no -takefocus option, the procedure checks to
  132. # see if (a) the widget isn't disabled, and (b) it has some key
  133. # bindings.  If all of these are true, then 1 is returned.
  134. #
  135. # Arguments:
  136. # w -        Name of a window.
  137.  
  138. proc tkFocusOK w {
  139.     if {![winfo viewable $w]} {
  140.     return 0
  141.     }
  142.     set code [catch {$w cget -takefocus} value]
  143.     if {($code == 0) && ($value != "")} {
  144.     if {$value == 0} {
  145.         return 0
  146.     } elseif {$value == 1} {
  147.         return 1
  148.     } else {
  149.         set value [uplevel #0 $value $w]
  150.         if {$value != ""} {
  151.         return $value
  152.         }
  153.     }
  154.     }
  155.     set code [catch {$w cget -state} value]
  156.     if {($code == 0) && ($value == "disabled")} {
  157.     return 0
  158.     }
  159.     regexp Key|Focus "[bind $w] [bind [winfo class $w]]"
  160. }
  161.  
  162. # tk_focusFollowsMouse --
  163. #
  164. # If this procedure is invoked, Tk will enter "focus-follows-mouse"
  165. # mode, where the focus is always on whatever window contains the
  166. # mouse.  If this procedure isn't invoked, then the user typically
  167. # has to click on a window to give it the focus.
  168. #
  169. # Arguments:
  170. # None.
  171.  
  172. proc tk_focusFollowsMouse {} {
  173.     set old [bind all <Enter>]
  174.     set script {
  175.     if {("%d" == "NotifyAncestor") || ("%d" == "NotifyNonlinear")
  176.         || ("%d" == "NotifyInferior")} {
  177.         if [tkFocusOK %W] {
  178.         focus %W
  179.         }
  180.     }
  181.     }
  182.     if {$old != ""} {
  183.     bind all <Enter> "$old; $script"
  184.     } else {
  185.     bind all <Enter> $script
  186.     }
  187. }
  188.