home *** CD-ROM | disk | FTP | other *** search
/ BUG 11 / BUGCD1998_02.ISO / email / sime / simdemo.z / xvt.tcl < prev   
Text File  |  1997-12-09  |  22KB  |  743 lines

  1. #############################################################################
  2.  
  3. proc calc_window_rect {parent left top right bottom} {
  4.     global windows
  5.     set parentrect [get_client_rect $parent]
  6.     set parent_width [expr [lindex $parentrect 2]-[lindex $parentrect 0]]
  7.     set parent_height [expr [lindex $parentrect 3]-[lindex $parentrect 1]]
  8.  
  9.     set newleft [expr {[regsub -all {\$x} $left $parent_width blat] ? {$blat} : $left}]
  10.     set newright [expr {[regsub -all {\$x} $right $parent_width blat] ? {$blat} : $right}]
  11.     set newtop [expr {[regsub -all {\$y} $top $parent_height blat] ? {$blat} : $top}]
  12.     set newbottom [expr {[regsub -all {\$y} $bottom $parent_height blat] ? {$blat} : $bottom}]
  13.     return [list [expr $newleft] [expr $newtop] [expr $newright] [expr $newbottom]]
  14. }
  15.  
  16.  
  17. #############################################################################
  18.  
  19. proc winmapped win {
  20.     global windows
  21.     keylset windows($win) mapped 1
  22. }
  23.  
  24.  
  25. #############################################################################
  26.  
  27. proc windestroyed win {
  28.     global windows
  29.     if {[info exists windows($win)]} {
  30.  
  31. #the following line was added by Leo Pelland, April 12, 1995
  32. #      _xvt_close_win [keylget windows($win) windowptr]
  33.         unset windows($win)                    
  34.     }
  35. }
  36.  
  37.  
  38. #############################################################################
  39. proc xvt_create_window {type rect title parent flags appdata} {
  40.     global windows
  41.     if {[info exists windows($title)]} {
  42.         return
  43.     }
  44.     # if parent is mapped, create it, otherwise just add to parent's kid
  45.     # list (which we do anyway) and have the parent event handler deal with it
  46.     set kids [keylget windows($parent) kidlist]
  47.     lappend kids $appdata
  48.     keylset windows($parent) kidlist $kids
  49.     _xvt_create_window $type $rect $title $parent $flags $appdata
  50. }
  51.  
  52.  
  53. #############################################################################
  54. set ctl_id_ctr 200
  55. proc next_control_id {} {global ctl_id_ctr; incr ctl_id_ctr; return $ctl_id_ctr;}
  56.  
  57. proc xvt_create_control {type rect title parent flags appdata} {
  58.     global windows
  59.     # if parent is mapped, create it, otherwise just add to parent's kid
  60.     # list (which we do anyway) and have the parent event handler deal with it
  61.     set kids [keylget windows($parent) kidlist]
  62.     lappend kids $appdata
  63.     keylset windows($parent) kidlist $kids
  64.     set ctl_id [next_control_id]
  65.     keylset windows($appdata) ctlid $ctl_id
  66.     _xvt_create_control $type $rect $title $parent $flags \
  67.         $appdata $ctl_id
  68. }
  69.  
  70.  
  71. #############################################################################
  72.  
  73. proc activate_control {win ctl} {
  74.     global windows
  75.     foreach i [keylget windows($win) kidlist] {
  76.         set itsid -1; catch { set itsid [keylget windows($i) ctlid] }
  77.         if {$itsid == $ctl} {
  78.             set cmd ""; catch { set cmd [keylget windows($i) command] }
  79.             if {$cmd != ""} {
  80.                 eval $cmd
  81.             }
  82.         }
  83.     }
  84. }
  85.  
  86.  
  87. proc get_ctl_title ctl {
  88.     global windows
  89.     if {[keylget windows($ctl) type]=="listbutton"} {
  90.         return [listitem $ctl [listselected $ctl]]
  91.     }
  92.     return [_xvt_get_ctl_title [keylget windows([keylget windows($ctl) parent]) windowptr] \
  93.             [keylget windows($ctl) ctlid]]
  94. }
  95.  
  96. proc set_ctl_title {ctl title} {
  97.     global windows
  98.     _xvt_set_ctl_title [keylget windows([keylget windows($ctl) parent]) windowptr] \
  99.             [keylget windows($ctl) ctlid] $title
  100. }
  101.  
  102. proc raise win {
  103.     global windows
  104.     _xvt_raise [keylget windows($win) windowptr]
  105. }
  106. # HISTORY
  107. # Created Dec 28, 1995 by ll:
  108. # END HISTORY 
  109.  
  110. proc select win {
  111.     global windows
  112.     _xvt_select_text [keylget windows($win) windowptr]
  113. }
  114.  
  115.  
  116. proc focus ctl {
  117.       global windows
  118.       set type  [keylget windows($ctl) type]
  119.       if {($type == "txedit") || ($type == "txeditline")} {      
  120.           _xvt_focus [keylget windows($ctl) windowptr]
  121.       } else {
  122.           _xvt_focus [keylget windows([keylget windows($ctl) parent]) windowptr] \
  123.           [keylget windows($ctl) ctlid]
  124.      }
  125. }
  126.  
  127. #############################################################################
  128. proc show_win win {
  129.     global windows
  130.     _xvt_show_win [keylget windows($win) windowptr] 1
  131. }
  132.  
  133. proc hide_win win {
  134.     global windows
  135.     _xvt_show_win [keylget windows($win) windowptr] 0
  136. }
  137.  
  138. proc close_win win {
  139.     global windows
  140.     _xvt_close_win [keylget windows($win) windowptr]
  141. }
  142. proc get_client_rect win {
  143.     global windows
  144.     return [_xvt_get_client_rect [keylget windows($win) windowptr]]
  145. }
  146.  
  147. proc enable_win win {
  148.     global windows
  149.     _xvt_enable_win [keylget windows($win) windowptr] 1
  150. }
  151.  
  152. proc disable_win win {
  153.     global windows
  154.     _xvt_enable_win [keylget windows($win) windowptr] 0
  155. }
  156.  
  157. proc enable_control ctl {
  158.     global windows
  159.     _xvt_enable_ctl [keylget windows([keylget windows($ctl) parent]) windowptr] \
  160.         [keylget windows($ctl) ctlid] 1
  161. }
  162.  
  163. proc disable_control ctl {
  164.     global windows
  165.     _xvt_enable_ctl [keylget windows([keylget windows($ctl) parent]) windowptr] \
  166.         [keylget windows($ctl) ctlid] 0
  167. }
  168.  
  169.  
  170. #############################################################################
  171. defargs toplevel_opts {
  172.     {-title text "Untitled"}
  173.     {-left text 100 }
  174.     {-top text 100}
  175.     {-right text 400}
  176.     {-bottom text 400}
  177.     {-hasresize boolean false}
  178.     {-hasclose boolean true}
  179.     {-entercommand text ""}
  180. }
  181.  
  182. proc toplevel {winname args} {
  183.     global windows
  184.     optargs $args toplevel_opts
  185.     set rect [calc_window_rect TASK_WIN $left $top $right $bottom]
  186.     set options 0
  187.     if {$hasresize=="true"} {incr options}
  188.     if {$hasclose=="true"} {incr options; incr options}
  189.     keylset windows($winname) winname $winname parent TASK_WIN left $left \
  190.         top $top right $right bottom $bottom title $title options $options \
  191.         mapped 0 kidlist {} type toplevel entercommand $entercommand
  192.     xvt_create_window W_DOC $rect $title TASK_WIN $options $winname
  193. }
  194.  
  195.  
  196.  
  197. #############################################################################
  198. defargs frame_opts {
  199.     {-parent text}
  200.     {-left text 0}
  201.     {-top text 0}
  202.     {-right text 0}
  203.     {-bottom text 0}
  204.     {-entercommand text ""}
  205. }
  206.  
  207. proc frame {winname args} {
  208.     global windows
  209.     optargs $args frame_opts
  210.     set rect [calc_window_rect $parent $left $top $right $bottom]
  211.     keylset windows($winname) winname $winname parent $parent left $left \
  212.         top $top right $right bottom $bottom options 0 \
  213.         mapped 0 kidlist {} type frame entercommand $entercommand
  214.     xvt_create_window W_PLAIN $rect "" $parent 0 $winname
  215. }
  216.  
  217.  
  218.  
  219. #############################################################################
  220. defargs label_opts {
  221.     {-parent text}
  222.     {-title text ""}
  223.     {-left text}
  224.     {-top text}
  225.     {-right text}
  226.     {-bottom text}
  227. }
  228.  
  229. proc label {winname args} {
  230.     global windows
  231.     optargs $args label_opts
  232.     set bottom [expr $top+[ideal_height label]]
  233.     set rect [calc_window_rect $parent $left $top $right $bottom]
  234.     keylset windows($winname) winname $winname parent $parent left $left \
  235.         top $top right $right bottom $bottom title $title options 0 \
  236.         mapped 0 kidlist {} type label
  237.     xvt_create_control WC_TEXT $rect $title $parent 0 $winname 
  238. }
  239.  
  240.  
  241.  
  242. #############################################################################
  243. defargs button_opts {
  244.     {-parent text}
  245.     {-title text "Untitled"}
  246.     {-left text}
  247.     {-top text}
  248.     {-right text}
  249.     {-bottom text}
  250.     {-command text}
  251. }
  252.  
  253. proc button {winname args} {
  254.     global windows
  255.     optargs $args button_opts
  256.     set bottom [expr $top+[ideal_height button]]
  257.     set rect [calc_window_rect $parent $left $top $right $bottom]
  258.     keylset windows($winname) winname $winname parent $parent left $left \
  259.         top $top right $right bottom $bottom title $title options 0 \
  260.         mapped 0 kidlist {} type button command $command
  261.     xvt_create_control WC_PUSHBUTTON $rect $title $parent 0 $winname
  262. }
  263.  
  264.  
  265. #############################################################################
  266. defargs edit_opts {
  267.     {-parent text}
  268.     {-title text ""}
  269.     {-left text}
  270.     {-top text}
  271.     {-right text}
  272.     {-bottom text}
  273.     {-command text ""}
  274. }
  275.  
  276. proc edit {winname args} {
  277.     global windows
  278.     optargs $args edit_opts
  279.     set bottom [expr $top+[ideal_height edit]]
  280.     set rect [calc_window_rect $parent $left $top $right $bottom]
  281.     keylset windows($winname) winname $winname parent $parent left $left \
  282.         top $top right $right bottom $bottom title $title options 0 \
  283.         mapped 0 kidlist {} type edit command $command
  284.     xvt_create_control WC_EDIT $rect $title $parent 0 $winname 
  285. }
  286.  
  287.  
  288. #############################################################################
  289. defargs checkbox_opts {
  290.     {-parent text}
  291.     {-title text "Check"}
  292.     {-left text}
  293.     {-top text}
  294.     {-right text}
  295.     {-bottom text}
  296.     {-variable text ""}
  297.     {-command text ""}
  298. }
  299.  
  300. proc checkbox {winname args} {
  301.     global windows
  302.     optargs $args checkbox_opts
  303.     set bottom [expr $top+[ideal_height checkbox]]
  304.     set rect [calc_window_rect $parent $left $top $right $bottom]
  305.     keylset windows($winname) winname $winname parent $parent left $left \
  306.         top $top right $right bottom $bottom title $title options 0 \
  307.         mapped 0 kidlist {} type checkbox command "docheck $winname" \
  308.         usercmd $command variable $variable
  309.     xvt_create_control WC_CHECKBOX $rect $title $parent 0 $winname 
  310. }
  311.  
  312.  
  313. proc docheck ctl {
  314.     global windows
  315.     set vbl [keylget windows($ctl) variable]
  316.     set val [_xvt_checkbox FLIP [keylget windows([keylget windows($ctl) parent]) windowptr] \
  317.                 [keylget windows($ctl) ctlid]]
  318.     if {$vbl != ""} {
  319.         global $vbl
  320.         set $vbl $val
  321.     } 
  322.     if {[keylget windows($ctl) usercmd] != ""} {
  323.         eval [keylget windows($ctl) usercmd]
  324.     }
  325. }
  326.  
  327. proc check {ctl check} {
  328.     global windows
  329.     set vbl [keylget windows($ctl) variable]
  330.     set val [_xvt_checkbox SET [keylget windows([keylget windows($ctl) parent]) windowptr] \
  331.                 [keylget windows($ctl) ctlid] $check]
  332.     if {$vbl != ""} {
  333.         global $vbl
  334.         set $vbl $val
  335.     } 
  336. }
  337.  
  338. proc checked ctl {
  339.     global windows
  340.     return [_xvt_checkbox GET [keylget windows([keylget windows($ctl) parent]) windowptr] \
  341.                 [keylget windows($ctl) ctlid]]
  342. }
  343.  
  344. #############################################################################
  345.  
  346. defargs tree_opts {
  347.     {-parent text}
  348.     {-left text}
  349.     {-top text}
  350.     {-right text}
  351.     {-bottom text}
  352. }
  353.  
  354. proc tree {winname args} {
  355.     global windows
  356.     optargs $args label_opts
  357.     set rect [calc_window_rect $parent $left $top $right $bottom]
  358.     keylset windows($winname) winname $winname parent $parent left $left \
  359.         top $top right $right bottom $bottom  \
  360.         mapped 0 kidlist {} type tree
  361.     xvt_create_control $rect $parent $winname 
  362. }
  363.  
  364. proc xvt_create_tree {rect parent winname} {
  365.     global windows
  366.     # if parent is mapped, create it, otherwise just add to parent's kid
  367.     # list (which we do anyway) and have the parent event handler deal with it
  368.     set kids [keylget windows($parent) kidlist]
  369.     lappend kids $appdata
  370.     keylset windows($parent) kidlist $kids
  371.     _xvt_create_tree $rect $parent $winname
  372. }
  373.  
  374.  
  375.  
  376. #############################################################################
  377. defargs radiobutton_opts {
  378.     {-parent text}
  379.     {-title text "Radio"}
  380.     {-left text}
  381.     {-top text}
  382.     {-right text}
  383.     {-bottom text}
  384.     {-variable text ""}
  385.     {-value text ""}
  386.     {-command text ""}
  387. }
  388.  
  389. proc radiobutton {winname args} {
  390.     global windows radiovars
  391.     optargs $args radiobutton_opts
  392.     set bottom [expr $top+[ideal_height radiobutton]]
  393.     set rect [calc_window_rect $parent $left $top $right $bottom]
  394.     keylset windows($winname) winname $winname parent $parent left $left \
  395.         top $top right $right bottom $bottom title $title options 0 \
  396.         mapped 0 kidlist {} type radiobutton command "dochoose $winname" \
  397.         usercmd $command variable $variable value $value
  398.     if {[info exists radiovars($variable)]==0} {
  399.         set radiovars($variable) $winname
  400.     } else {
  401.         lappend radiovars($variable) $winname
  402.     }       
  403.     xvt_create_control WC_RADIOBUTTON $rect $title $parent 0 $winname 
  404. }
  405.  
  406.  
  407. proc dochoose ctl {
  408.     global windows radiovars
  409.     set vbl [keylget windows($ctl) variable]
  410.     set val [keylget windows($ctl) value]
  411.     set tmp ""; set cnt 0;
  412.     foreach i $radiovars($vbl) {
  413.         lappend tmp [keylget windows([keylget windows($i) parent]) windowptr]
  414.         lappend tmp [keylget windows($i) ctlid]
  415.         incr cnt
  416.     }
  417.     eval _xvt_radiobutton SET [keylget windows([keylget windows($ctl) parent]) windowptr] \
  418.                 [keylget windows($ctl) ctlid] $cnt $tmp
  419.     if {$vbl != ""} {
  420.         global $vbl
  421.         set $vbl $val
  422.     } 
  423.     if {[keylget windows($ctl) usercmd] != ""} {
  424.         eval [keylget windows($ctl) usercmd]
  425.     }
  426. }
  427.  
  428. proc choose {ctl} {
  429.     dochoose $ctl
  430. }
  431.  
  432. proc chosen ctl {
  433.     global windows
  434.     return [_xvt_radiobutton GET [keylget windows([keylget windows($ctl) parent]) windowptr] \
  435.                 [keylget windows($ctl) ctlid]]
  436. }
  437.  
  438.  
  439. #############################################################################
  440. defargs txedit_opts {
  441.     {-parent text}
  442.     {-left text}
  443.     {-top text}
  444.     {-right text}
  445.     {-bottom text}
  446.     {-command text ""}
  447. }
  448.  
  449. proc txedit {winname args} {
  450.     global windows
  451.     optargs $args txedit_opts
  452.     set rect [calc_window_rect $parent $left $top $right $bottom]
  453.     keylset windows($winname) winname $winname parent $parent left $left \
  454.         top $top right $right bottom $bottom options 0 \
  455.         mapped 0 kidlist {} type txedit command $command
  456.     xvt_create_control TXEDIT $rect "" $parent 0 $winname 
  457. }
  458.  
  459.  
  460. #############################################################################
  461. defargs txeditline_opts {
  462.     {-parent text}
  463.     {-left text}
  464.     {-top text}
  465.     {-right text}
  466.     {-bottom text}
  467.     {-command text ""}
  468. }
  469.  
  470. proc txeditline {winname args} {
  471.     global windows
  472.     optargs $args txeditline_opts
  473.     set rect [calc_window_rect $parent $left $top $right $bottom]
  474.     keylset windows($winname) winname $winname parent $parent left $left \
  475.         top $top right $right bottom $bottom options 0 \
  476.         mapped 0 kidlist {} type txeditline command $command
  477.     xvt_create_control TXEDITLINE $rect "" $parent 0 $winname 
  478. }
  479.  
  480. #############################################################################
  481. defargs groupbox_opts {
  482.     {-parent text}
  483.     {-title text ""}
  484.     {-left text}
  485.     {-top text}
  486.     {-right text}
  487.     {-bottom text}
  488. }
  489.  
  490. proc groupbox {winname args} {
  491.     global windows
  492.     optargs $args groupbox_opts
  493.     set rect [calc_window_rect $parent $left $top $right $bottom]
  494.     keylset windows($winname) winname $winname parent $parent left $left \
  495.         top $top right $right bottom $bottom title $title options 0 \
  496.         mapped 0 kidlist {} type groupbox
  497.     xvt_create_control WC_GROUPBOX $rect $title $parent 0 $winname 
  498. }
  499.  
  500.  
  501. #############################################################################
  502. defargs listbox_opts {
  503.     {-parent text}
  504.     {-left text}
  505.     {-top text}
  506.     {-right text}
  507.     {-bottom text}
  508.     {-command text ""}
  509. }
  510.  
  511. proc listbox {winname args} {
  512.     global windows
  513.     optargs $args listbox_opts
  514.     set rect [calc_window_rect $parent $left $top $right $bottom]
  515.     keylset windows($winname) winname $winname parent $parent left $left \
  516.         top $top right $right bottom $bottom title "" options 0 \
  517.         mapped 0 kidlist {} type listbox command $command
  518.     xvt_create_control WC_LBOX $rect "" $parent 0 $winname 
  519. }
  520.  
  521. #############################################################################
  522. defargs listbutton_opts {
  523.     {-parent text}
  524.     {-left text}
  525.     {-top text}
  526.     {-right text}
  527.     {-bottom text}
  528.     {-command text ""}
  529. }
  530.  
  531. proc listbutton {winname args} {
  532.     global windows
  533.     optargs $args listbutton_opts
  534.     set rect [calc_window_rect $parent $left $top $right $bottom]
  535.     keylset windows($winname) winname $winname parent $parent left $left \
  536.         top $top right $right bottom $bottom title "" options 0 \
  537.         mapped 0 kidlist {} type listbutton command $command
  538.     xvt_create_control WC_LISTBUTTON $rect "" $parent 0 $winname 
  539. }
  540.  
  541. #############################################################################
  542. defargs listedit_opts {
  543.     {-parent text}
  544.     {-left text}
  545.     {-top text}
  546.     {-right text}
  547.     {-bottom text}
  548.     {-command text ""}
  549. }
  550.  
  551. proc listedit {winname args} {
  552.     global windows
  553.     optargs $args listedit_opts
  554.     set rect [calc_window_rect $parent $left $top $right $bottom]
  555.     keylset windows($winname) winname $winname parent $parent left $left \
  556.         top $top right $right bottom $bottom title "" options 0 \
  557.         mapped 0 kidlist {} type listedit command $command
  558.     xvt_create_control WC_LISTEDIT $rect "" $parent 0 $winname 
  559. }
  560.  
  561.  
  562. #############################################################################
  563.  
  564. proc listadd {list index args} { global windows
  565.     eval _xvt_list add [keylget windows([keylget windows($list) parent]) windowptr] \
  566.                 [keylget windows($list) ctlid] $index $args
  567. }
  568.  
  569. proc listclear list { global windows
  570.     _xvt_list clear [keylget windows([keylget windows($list) parent]) windowptr] \
  571.                 [keylget windows($list) ctlid] 
  572. }
  573.  
  574. proc listcount list { global windows
  575.     return [_xvt_list count [keylget windows([keylget windows($list) parent]) windowptr] \
  576.                 [keylget windows($list) ctlid]]
  577. }
  578.  
  579. proc listdel {list index} { global windows
  580.     _xvt_list delete [keylget windows([keylget windows($list) parent]) windowptr] \
  581.                 [keylget windows($list) ctlid] $index
  582. }
  583.  
  584. proc listitem {list index} { global windows
  585.     return [_xvt_list item [keylget windows([keylget windows($list) parent]) windowptr] \
  586.                 [keylget windows($list) ctlid] $index]
  587. }
  588.  
  589. proc listselected {list} { global windows
  590.     return [_xvt_list selected [keylget windows([keylget windows($list) parent]) windowptr] \
  591.                 [keylget windows($list) ctlid]]
  592. }
  593.  
  594. proc listselect {list index} { global windows
  595.     _xvt_list select [keylget windows([keylget windows($list) parent]) windowptr] \
  596.                 [keylget windows($list) ctlid] $index 1
  597. }
  598.  
  599. proc listunselect {list index} { global windows
  600.     _xvt_list select [keylget windows([keylget windows($list) parent]) windowptr] \
  601.                 [keylget windows($list) ctlid] $index 0
  602. }
  603.  
  604. proc listsuspend {list} { global windows
  605.     _xvt_list suspend [keylget windows([keylget windows($list) parent]) windowptr] \
  606.                 [keylget windows($list) ctlid]
  607. }
  608.  
  609. proc listresume {list} { global windows
  610.     _xvt_list resume [keylget windows([keylget windows($list) parent]) windowptr] \
  611.                 [keylget windows($list) ctlid]
  612. }
  613.  
  614. #############################################################################
  615.  
  616. keylset windows(TASK_WIN) winname TASK_WIN parent NULL left 0 \
  617.         top 0 right 640 bottom 400 mapped 1 kidlist {} type task
  618.  
  619. # by Leo Pelland in November 1994
  620. proc focus_next_kid {win ctl} {
  621.     global windows
  622. #note "in focus_next_kid in xvt.tcl: beginning, win = $win, ctl = $ctl"
  623. #  // set "last" to 0 to indicate that we have not yet found the control that
  624. #  // has the focus
  625.     set last 0
  626. #  // get the list of subwindows
  627.     set kidpresent [keylget windows($win) kidlist {}]
  628. #  // continue if we have subwindows
  629.     if {$kidpresent == 1} {
  630. #     // if no control has the focus, give the focus to the first valid control
  631.       set topwin [keylget windows($win) windowptr]
  632. #note "topwin = $topwin, ctl = $ctl"      
  633.         if { $topwin == $ctl} {set last 1}
  634. #note "break 3"
  635. #     // loop through the windows to find the one who has the focus, then set
  636. #     // the focus to the next valid control
  637. #note "break 4"
  638.         foreach i [keylget windows($win) kidlist] {
  639. #note "focus next kid: begin of for loop, i = $i"
  640.             if {$last == 1} {
  641. #note "last = 1"            
  642.                 set a [keylget windows($i) type]
  643. #           // if we are on a valid control window, give it the focus and exit
  644.                 if {($a == "edit") || ($a == "txedit") || ($a == "txeditline")} {
  645. #note "in focus_next_kid in xvt.tcl: focus now = $a"
  646.                     focus $i
  647.                     break
  648.                 } 
  649.             } else {
  650.                 set b [keylget windows($i) windowptr]
  651. #note "keep track of prev window, b = $b, ctl = $ctl"            
  652. #           // set "last" to 1 if we are on the window which has the focus
  653.                 if {$b == $ctl} {
  654. #note "we are on the window who has the focus"
  655.                     set last 1
  656.                 }
  657.             }
  658.         }
  659.  
  660.     }
  661. }
  662.  
  663.  
  664. # by Leo Pelland on March 22, 1995
  665. proc focus_prev_kid {win ctl} {
  666.     global windows
  667. #  // set "first" to 1 to indicate that we don't have a valid previous control
  668.     set first 1
  669. #  // get the list of sub windows
  670.     set kidpresent [keylget windows($win) kidlist {}]
  671. #  // if we have some windows, continue
  672.     if {$kidpresent == 1} {
  673. #     // if no control has the focus, simply return
  674.         if {[keylget windows($win) windowptr] == $ctl} {break}
  675. #     // loop through the windows, find the one who has the focus and
  676. #     // then, give the focus the the previous control window
  677.         foreach i [keylget windows($win) kidlist] {
  678.             set current_control [keylget windows($i) windowptr]
  679.             if {$current_control == $ctl} {
  680. #           // if the first control has the focus or there is no valid previous
  681. #           // control, simply give control to the container who will decide what to do 
  682.                 if {$first == 1} {
  683.                     go_to_container [keylget windows($win) windowptr]
  684.                     break
  685.                 }
  686. #           // give the focus to the previous valid control
  687.                 focus $prev_control
  688.                 break
  689.             } else {
  690. #           // get the control's type and if it's a valid control, assign it to
  691. #           // "prev_control" and set "first" to 0 to indicate that we have a 
  692. #           // valid previous control
  693.                 set a [keylget windows($i) type]
  694.                 if {($a == "edit") || ($a == "txedit") || ($a == "txeditline")} {
  695.                     set prev_control $i
  696.                     set first 0
  697.                 }
  698.             }
  699.         }
  700.     }
  701. }
  702.  
  703. # by Leo Pelland on June 17, 1995
  704. proc focus_last_kid {win} {
  705.     global windows
  706.     set focus_window "invalid"
  707. #   // get the list of subwindows
  708.     set kidpresent [keylget windows($win) kidlist {}]
  709. #   // continue if we have subwindows
  710.     if {$kidpresent == 1} {
  711. #     // loop through the windows to find the one who has the focus, then set
  712. #     // the focus to the next valid control
  713.         foreach i [keylget windows($win) kidlist] {
  714.             set a [keylget windows($i) type]
  715. #           // if we are on a valid control window, set it as the focus window
  716.             if {($a == "edit") || ($a == "txedit") || ($a == "txeditline")} {
  717.                 set focus_window $i
  718.             } 
  719.         }
  720.     }
  721. #   // if we have found a valid object, give it the focus 
  722.     if {$focus_window != "invalid"} {focus $focus_window}
  723. }
  724.  
  725. # by Leo Pelland on June 17, 1995
  726. proc focus_first_kid {win} {
  727.     global windows
  728. #   // get the list of subwindows
  729.     set kidpresent [keylget windows($win) kidlist {}]
  730. #   // continue if we have subwindows
  731.     if {$kidpresent == 1} {
  732.         foreach i [keylget windows($win) kidlist] {
  733.             set a [keylget windows($i) type]
  734. #           // if we are on a valid control window, give it the focus and exit
  735.             if {($a == "edit") || ($a == "txedit") || ($a == "txeditline")} {
  736.                 focus $i
  737.                 break
  738.             }
  739.         }
  740.     }
  741. }
  742.  
  743.