home *** CD-ROM | disk | FTP | other *** search
/ Freelog Special Freeware 31 / FreelogHS31.iso / Texte / scribus / scribus-1.3.3.9-win32-install.exe / tcl / tix8.1 / Grid.tcl < prev    next >
Text File  |  2002-01-24  |  23KB  |  1,135 lines

  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. #    $Id: Grid.tcl,v 1.2.2.3 2002/01/24 10:08:58 idiscovery Exp $
  4. #
  5. # Grid.tcl --
  6. #
  7. #     This file defines the default bindings for Tix Grid widgets.
  8. #
  9. # Copyright (c) 1993-1999 Ioi Kim Lam.
  10. # Copyright (c) 2000-2001 Tix Project Group.
  11. #
  12. # See the file "license.terms" for information on usage and redistribution
  13. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  14. #
  15.  
  16.  
  17. global tkPriv
  18. if {![llength [info globals tkPriv]]} {
  19.     tk::unsupported::ExposePrivateVariable tkPriv
  20. }
  21. #--------------------------------------------------------------------------
  22. # tkPriv elements used in this file:
  23. #
  24. # afterId -        Token returned by "after" for autoscanning.
  25. # fakeRelease -        Cancel the ButtonRelease-1 after the user double click
  26. #--------------------------------------------------------------------------
  27. #
  28. foreach fun {tkCancelRepeat} {
  29.     if {![llength [info commands $fun]]} {
  30.     tk::unsupported::ExposePrivateCommand $fun
  31.     }
  32. }
  33. unset fun
  34.  
  35. proc tixGridBind {} {
  36.     tixBind TixGrid <ButtonPress-1> {
  37.     tixGrid:Button-1 %W %x %y
  38.     }
  39.     tixBind TixGrid <Shift-ButtonPress-1> {
  40.     tixGrid:Shift-Button-1 %W %x %y
  41.     }
  42.     tixBind TixGrid <Control-ButtonPress-1> {
  43.     tixGrid:Control-Button-1 %W %x %y
  44.     }
  45.     tixBind TixGrid <ButtonRelease-1> {
  46.     tixGrid:ButtonRelease-1 %W %x %y
  47.     }
  48.     tixBind TixGrid <Double-ButtonPress-1> {
  49.     tixGrid:Double-1 %W  %x %y
  50.     }
  51.     tixBind TixGrid <B1-Motion> {
  52.     set tkPriv(x) %x 
  53.     set tkPriv(y) %y
  54.     set tkPriv(X) %X
  55.     set tkPriv(Y) %Y
  56.  
  57.     tixGrid:B1-Motion %W %x %y
  58.     }
  59.     tixBind TixGrid <Control-B1-Motion> {
  60.     set tkPriv(x) %x 
  61.     set tkPriv(y) %y
  62.     set tkPriv(X) %X
  63.     set tkPriv(Y) %Y
  64.  
  65.     tixGrid:Control-B1-Motion %W %x %y
  66.     }
  67.     tixBind TixGrid <B1-Leave> {
  68.     set tkPriv(x) %x 
  69.     set tkPriv(y) %y
  70.     set tkPriv(X) %X
  71.     set tkPriv(Y) %Y
  72.  
  73.     tixGrid:B1-Leave %W
  74.     }
  75.     tixBind TixGrid <B1-Enter> {
  76.     tixGrid:B1-Enter %W %x %y
  77.     }
  78.     tixBind TixGrid <Control-B1-Leave> {
  79.     set tkPriv(x) %x 
  80.     set tkPriv(y) %y
  81.     set tkPriv(X) %X
  82.     set tkPriv(Y) %Y
  83.  
  84.     tixGrid:Control-B1-Leave %W
  85.     }
  86.     tixBind TixGrid <Control-B1-Enter> {
  87.     tixGrid:Control-B1-Enter %W %x %y
  88.     }
  89.  
  90.     # Keyboard bindings
  91.     #
  92.     tixBind TixGrid <Up> {
  93.     tixGrid:DirKey %W up
  94.     }
  95.     tixBind TixGrid <Down> {
  96.     tixGrid:DirKey %W down
  97.     }
  98.     tixBind TixGrid <Left> {
  99.     tixGrid:DirKey %W left
  100.     }
  101.     tixBind TixGrid <Right> {
  102.     tixGrid:DirKey %W right
  103.     }
  104.     tixBind TixGrid <Prior> {
  105.     %W yview scroll -1 pages
  106.     }
  107.     tixBind TixGrid <Next> {
  108.     %W yview scroll 1 pages
  109.     }
  110.     tixBind TixGrid <Return> {
  111.     tixGrid:Return %W 
  112.     }
  113.     tixBind TixGrid <space> {
  114.     tixGrid:Space %W 
  115.     }
  116.     #
  117.     # Don't use tixBind because %A causes Tk 8.3.2 to crash
  118.     #
  119.     bind TixGrid <MouseWheel> {
  120.         %W yview scroll [expr {- (%D / 120) * 2}] units
  121.     }
  122. }
  123.  
  124. #----------------------------------------------------------------------
  125. #
  126. #
  127. #             Mouse bindings
  128. #
  129. #
  130. #----------------------------------------------------------------------
  131.  
  132. proc tixGrid:Button-1 {w x y} {
  133.     if {[$w cget -state] == "disabled"} {
  134.     return
  135.     }
  136.     tixGrid:SetFocus $w
  137.  
  138.     case [tixGrid:GetState $w] {
  139.     {0} {
  140.         tixGrid:GoState 1 $w $x $y
  141.            }
  142.     }
  143. }
  144.  
  145. proc tixGrid:Shift-Button-1 {w x y} {
  146.     if {[$w cget -state] == "disabled"} {
  147.     return
  148.     }
  149.     tixGrid:SetFocus $w
  150.  
  151.     case [tixGrid:GetState $w] {
  152.     }
  153. }
  154.  
  155. proc tixGrid:Control-Button-1 {w x y} {
  156.     if {[$w cget -state] == "disabled"} {
  157.     return
  158.     }
  159.     tixGrid:SetFocus $w
  160.  
  161.     case [tixGrid:GetState $w] {
  162.     {s0} {
  163.         tixGrid:GoState s1 $w $x $y
  164.            }
  165.     {b0} {
  166.         tixGrid:GoState b1 $w $x $y
  167.            }
  168.     {m0} {
  169.         tixGrid:GoState m1 $w $x $y
  170.            }
  171.     {e0} {
  172.         tixGrid:GoState e10 $w $x $y
  173.            }
  174.     }
  175. }
  176.  
  177. proc tixGrid:ButtonRelease-1 {w x y} {
  178.     case [tixGrid:GetState $w] {
  179.     {2} {
  180.         tixGrid:GoState 5 $w $x $y
  181.     }
  182.     {4} {
  183.         tixGrid:GoState 3 $w $x $y
  184.     }
  185.     }
  186. }
  187.  
  188. proc tixGrid:B1-Motion {w x y} {
  189.     case [tixGrid:GetState $w] {
  190.     {2 4} {
  191.         tixGrid:GoState 4 $w $x $y
  192.     }
  193.     }
  194. }
  195.  
  196. proc tixGrid:Control-B1-Motion {w x y} {
  197.     case [tixGrid:GetState $w] {
  198.     {s2 s4} {
  199.         tixGrid:GoState s4 $w $x $y 
  200.     }
  201.     {b2 b4} {
  202.         tixGrid:GoState b4 $w $x $y 
  203.     }
  204.     {m2 m5} {
  205.         tixGrid:GoState m4 $w $x $y 
  206.     }
  207.     }
  208. }
  209.  
  210. proc tixGrid:Double-1 {w x y} {
  211.     case [tixGrid:GetState $w] {
  212.     {s0} {
  213.         tixGrid:GoState s7 $w $x $y
  214.     }
  215.     {b0} {
  216.         tixGrid:GoState b7 $w $x $y
  217.     }
  218.     }
  219. }
  220.  
  221. proc tixGrid:B1-Leave {w} {
  222.     case [tixGrid:GetState $w] {
  223.     {s2 s4} {
  224.         tixGrid:GoState s5 $w
  225.     }
  226.     {b2 b4} {
  227.         tixGrid:GoState b5 $w
  228.     }
  229.     {m2 m5} {
  230.         tixGrid:GoState m8 $w
  231.     }
  232.     {e2 e5} {
  233.         tixGrid:GoState e8 $w
  234.     }
  235.     }
  236. }
  237.  
  238. proc tixGrid:B1-Enter {w x y} {
  239.     case [tixGrid:GetState $w] {
  240.     {s5 s6} {
  241.         tixGrid:GoState s4 $w $x $y
  242.     }
  243.     {b5 b6} {
  244.         tixGrid:GoState b4 $w $x $y
  245.     }
  246.     {m8 m9} {
  247.         tixGrid:GoState m4 $w $x $y
  248.     }
  249.     {e8 e9} {
  250.         tixGrid:GoState e4 $w $x $y
  251.     }
  252.     }
  253. }
  254.  
  255. proc tixGrid:Control-B1-Leave {w} {
  256.     case [tixGrid:GetState $w] {
  257.     {s2 s4} {
  258.         tixGrid:GoState s5 $w
  259.     }
  260.     {b2 b4} {
  261.         tixGrid:GoState b5 $w
  262.     }
  263.     {m2 m5} {
  264.         tixGrid:GoState m8 $w
  265.     }
  266.     }
  267. }
  268.  
  269. proc tixGrid:Control-B1-Enter {w x y} {
  270.     case [tixGrid:GetState $w] {
  271.     {s5 s6} {
  272.         tixGrid:GoState s4 $w $x $y
  273.     }
  274.     {b5 b6} {
  275.         tixGrid:GoState b4 $w $x $y
  276.     }
  277.     {m8 m9} {
  278.         tixGrid:GoState m4 $w $x $y
  279.     }
  280.     }
  281. }
  282.  
  283. proc tixGrid:AutoScan {w} {
  284.     case [tixGrid:GetState $w] {
  285.     {s5 s6} {
  286.         tixGrid:GoState s6 $w
  287.     }
  288.     {b5 b6} {
  289.         tixGrid:GoState b6 $w
  290.     }
  291.     {m8 m9} {
  292.         tixGrid:GoState m9 $w
  293.     }
  294.     {e8 e9} {
  295.         tixGrid:GoState e9 $w
  296.     }
  297.     }
  298. }
  299.  
  300. #----------------------------------------------------------------------
  301. #
  302. #
  303. #             Key bindings
  304. #
  305. #
  306. #----------------------------------------------------------------------
  307. proc tixGrid:DirKey {w key} {
  308.     if {[$w cget -state] == "disabled"} {
  309.     return
  310.     }
  311.     case [tixGrid:GetState $w] {
  312.     {s0} {
  313.         tixGrid:GoState s8 $w $key
  314.            }
  315.     {b0} {
  316.         tixGrid:GoState b8 $w $key
  317.            }
  318.     }
  319. }
  320.  
  321. proc tixGrid:Return {w} {
  322.     if {[$w cget -state] == "disabled"} {
  323.     return
  324.     }
  325.     case [tixGrid:GetState $w] {
  326.     {s0} {
  327.         tixGrid:GoState s9 $w
  328.            }
  329.     {b0} {
  330.         tixGrid:GoState b9 $w
  331.            }
  332.     }
  333. }
  334.  
  335. proc tixGrid:Space {w} {
  336.     if {[$w cget -state] == "disabled"} {
  337.     return
  338.     }
  339.     case [tixGrid:GetState $w] {
  340.     {s0} {
  341.         tixGrid:GoState s10 $w
  342.            }
  343.      {b0} {
  344.         tixGrid:GoState b10 $w
  345.            }
  346.    }
  347. }
  348.  
  349. #----------------------------------------------------------------------
  350. #
  351. #            STATE MANIPULATION
  352. #
  353. #
  354. #----------------------------------------------------------------------
  355. proc tixGrid:GetState {w} {
  356.     global $w:priv:state
  357.  
  358.     if {![info exists $w:priv:state]} {
  359.     set $w:priv:state 0
  360.     }
  361.     return [set $w:priv:state]
  362. }
  363.  
  364. proc tixGrid:SetState {w n} {
  365.     global $w:priv:state
  366.  
  367.     set $w:priv:state $n
  368. }
  369.  
  370. proc tixGrid:GoState {n w args} {
  371.  
  372. #   puts "going from [tixGrid:GetState $w] --> $n"
  373.  
  374.     tixGrid:SetState $w $n
  375.     eval tixGrid:GoState-$n $w $args
  376. }
  377.  
  378. #----------------------------------------------------------------------
  379. #           SELECTION ROUTINES
  380. #----------------------------------------------------------------------
  381. proc tixGrid:SelectSingle {w ent} {
  382.     $w selection set [lindex $ent 0] [lindex $ent 1]
  383.     tixGrid:CallBrowseCmd $w $ent
  384. }
  385.  
  386. #----------------------------------------------------------------------
  387. #    SINGLE SELECTION
  388. #----------------------------------------------------------------------
  389. proc tixGrid:GoState-0 {w} {
  390.     set list $w:_list
  391.     global $list
  392.  
  393.     if {[info exists $list]} {
  394.     foreach cmd [set $list] {
  395.         uplevel #0 $cmd
  396.     }
  397.     if {[info exists $list]} {
  398.         unset $list
  399.     }
  400.     }
  401. }
  402.  
  403. proc tixGrid:GoState-1 {w x y} {
  404.     set ent [$w nearest $x $y]
  405.     if {$ent != ""} {
  406.     tixGrid:SetAnchor $w $ent
  407.     }
  408.     tixGrid:CheckEdit $w
  409.     $w selection clear 0 0 max max
  410.  
  411.     if {[string compare [$w cget -selectmode] single]} {
  412.     tixGrid:SelectSingle $w $ent
  413.     }
  414.     tixGrid:GoState 2 $w
  415. }
  416.  
  417. proc tixGrid:GoState-2 {w} {
  418. }
  419.  
  420. proc tixGrid:GoState-3 {w x y} {
  421.     set ent [$w nearest $x $y]
  422.  
  423.     if {$ent != ""} {
  424.     tixGrid:SelectSingle $w $ent
  425.     }
  426.     tixGrid:GoState 0 $w
  427. }
  428.  
  429. proc tixGrid:GoState-5 {w x y} {
  430.     set ent [$w nearest $x $y]
  431.  
  432.     if {$ent != ""} {
  433.     tixGrid:SelectSingle $w $ent
  434.     tixGrid:SetEdit $w $ent
  435.     }
  436.     tixGrid:GoState 0 $w
  437. }
  438.  
  439.  
  440. proc tixGrid:GoState-4 {w x y} {
  441.     set ent [$w nearest $x $y]
  442.  
  443.     case [$w cget -selectmode] {
  444.     single {
  445.         tixGrid:SetAnchor $w $ent
  446.     }
  447.     browse {
  448.         tixGrid:SetAnchor $w $ent
  449.         $w selection clear 0 0 max max
  450.         tixGrid:SelectSingle $w $ent
  451.     }
  452.     {multiple extended} {
  453.         set anchor [$w anchor get]
  454.         $w selection adjust [lindex $anchor 0] [lindex $anchor 1] \
  455.         [lindex $ent 0] [lindex $ent 1]
  456.     }
  457.     }
  458. }
  459.  
  460. proc tixGrid:GoState-s5 {w} {
  461.     tixGrid:StartScan $w
  462. }
  463.  
  464. proc tixGrid:GoState-s6 {w} {
  465.     global tkPriv
  466.  
  467.     tixGrid:DoScan $w
  468. }
  469.  
  470. proc tixGrid:GoState-s7 {w x y} {
  471.     set ent [$w nearest $x $y]
  472.  
  473.     if {$ent != ""} {
  474.     $w selection clear
  475.     $w selection set $ent
  476.     tixGrid:CallCommand $w $ent
  477.     }
  478.     tixGrid:GoState s0 $w
  479. }
  480.  
  481. proc tixGrid:GoState-s8 {w key} {
  482.     set anchor [$w info anchor]
  483.  
  484.     if {$anchor == ""} {
  485.     set anchor 0
  486.     } else {
  487.     set anchor [$w info $key $anchor]
  488.     }
  489.  
  490.     $w anchor set $anchor
  491.     $w see $anchor
  492.     tixGrid:GoState s0 $w
  493. }
  494.  
  495. proc tixGrid:GoState-s9 {w} {
  496.     set anchor [$w info anchor]
  497.  
  498.     if {$anchor == ""} {
  499.     set anchor 0
  500.     $w anchor set $anchor
  501.     $w see $anchor
  502.     }
  503.  
  504.     if {[$w info anchor] != ""} {
  505.     # ! may not have any elements
  506.     #
  507.     tixGrid:CallCommand $w [$w info anchor]
  508.     $w selection clear 
  509.     $w selection set $anchor
  510.     }
  511.  
  512.     tixGrid:GoState s0 $w
  513. }
  514.  
  515. proc tixGrid:GoState-s10 {w} {
  516.     set anchor [$w info anchor]
  517.  
  518.     if {$anchor == ""} {
  519.     set anchor 0
  520.     $w anchor set $anchor
  521.     $w see $anchor
  522.     }
  523.  
  524.     if {[$w info anchor] != ""} {
  525.     # ! may not have any elements
  526.     #
  527.     tixGrid:CallBrowseCmd $w [$w info anchor]
  528.     $w selection clear 
  529.     $w selection set $anchor
  530.     }
  531.  
  532.     tixGrid:GoState s0 $w
  533. }
  534.  
  535. #----------------------------------------------------------------------
  536. #    BROWSE SELECTION
  537. #----------------------------------------------------------------------
  538. proc tixGrid:GoState-b0 {w} {
  539. }
  540.  
  541. proc tixGrid:GoState-b1 {w x y} {
  542.     set ent [$w nearest $x $y]
  543.     if {$ent != ""} {
  544.     $w anchor set $ent
  545.     $w selection clear
  546.     $w selection set $ent
  547.     tixGrid:CallBrowseCmd $w $ent
  548.     }
  549.     tixGrid:GoState b2 $w
  550. }
  551.  
  552. proc tixGrid:GoState-b2 {w} {
  553. }
  554.  
  555. proc tixGrid:GoState-b3 {w} {
  556.     set ent [$w info anchor]
  557.     if {$ent != ""} {
  558.     $w selection clear
  559.     $w selection set $ent
  560.     tixGrid:CallBrowseCmd $w $ent
  561.     }
  562.     tixGrid:GoState b0 $w
  563. }
  564.  
  565. proc tixGrid:GoState-b4 {w x y} {
  566.     set ent [$w nearest $x $y]
  567.     if {$ent != ""} {
  568.     $w anchor set $ent
  569.     $w selection clear
  570.     $w selection set $ent
  571.     tixGrid:CallBrowseCmd $w $ent
  572.     }
  573. }
  574.  
  575. proc tixGrid:GoState-b5 {w} {
  576.     tixGrid:StartScan $w
  577. }
  578.  
  579. proc tixGrid:GoState-b6 {w} {
  580.     global tkPriv
  581.  
  582.     tixGrid:DoScan $w
  583. }
  584.  
  585. proc tixGrid:GoState-b7 {w x y} {
  586.     set ent [$w nearest $x $y]
  587.  
  588.     if {$ent != ""} {
  589.     $w selection clear
  590.     $w selection set $ent
  591.     tixGrid:CallCommand $w $ent
  592.     }
  593.     tixGrid:GoState b0 $w
  594. }
  595.  
  596. proc tixGrid:GoState-b8 {w key} {
  597.     set anchor [$w info anchor]
  598.  
  599.     if {$anchor == ""} {
  600.     set anchor 0
  601.     } else {
  602.     set anchor [$w info $key $anchor]
  603.     }
  604.  
  605.     $w anchor set $anchor
  606.     $w selection clear
  607.     $w selection set $anchor
  608.     $w see $anchor
  609.  
  610.     tixGrid:CallBrowseCmd $w $anchor
  611.     tixGrid:GoState b0 $w
  612. }
  613.  
  614. proc tixGrid:GoState-b9 {w} {
  615.     set anchor [$w info anchor]
  616.  
  617.     if {$anchor == ""} {
  618.     set anchor 0
  619.     $w anchor set $anchor
  620.     $w see $anchor
  621.     }
  622.  
  623.     if {[$w info anchor] != ""} {
  624.     # ! may not have any elements
  625.     #
  626.     tixGrid:CallCommand $w [$w info anchor]
  627.     $w selection clear 
  628.     $w selection set $anchor
  629.     }
  630.  
  631.     tixGrid:GoState b0 $w
  632. }
  633.  
  634. proc tixGrid:GoState-b10 {w} {
  635.     set anchor [$w info anchor]
  636.  
  637.     if {$anchor == ""} {
  638.     set anchor 0
  639.     $w anchor set $anchor
  640.     $w see $anchor
  641.     }
  642.  
  643.     if {[$w info anchor] != ""} {
  644.     # ! may not have any elements
  645.     #
  646.     tixGrid:CallBrowseCmd $w [$w info anchor]
  647.     $w selection clear 
  648.     $w selection set $anchor
  649.     }
  650.  
  651.     tixGrid:GoState b0 $w
  652. }
  653.  
  654. #----------------------------------------------------------------------
  655. #    MULTIPLE SELECTION
  656. #----------------------------------------------------------------------
  657. proc tixGrid:GoState-m0 {w} {
  658. }
  659.  
  660. proc tixGrid:GoState-m1 {w x y} {
  661.     set ent [$w nearest $x $y]
  662.     if {$ent != ""} {
  663.     $w anchor set $ent
  664.     $w selection clear
  665.     $w selection set $ent
  666.     tixGrid:CallBrowseCmd $w $ent
  667.     }
  668.     tixGrid:GoState m2 $w
  669. }
  670.  
  671. proc tixGrid:GoState-m2 {w} {
  672. }
  673.  
  674. proc tixGrid:GoState-m3 {w} {
  675.     set ent [$w info anchor]
  676.     if {$ent != ""} {
  677.     tixGrid:CallBrowseCmd $w $ent
  678.     }
  679.     tixGrid:GoState m0 $w
  680. }
  681.  
  682. proc tixGrid:GoState-m4 {w x y} {
  683.     set from [$w info anchor]
  684.     set to   [$w nearest $x $y]
  685.     if {$to != ""} {
  686.     $w selection clear
  687.     $w selection set $from $to
  688.     tixGrid:CallBrowseCmd $w $to
  689.     }
  690.     tixGrid:GoState m5 $w
  691. }
  692.  
  693. proc tixGrid:GoState-m5 {w} {
  694. }
  695.  
  696. proc tixGrid:GoState-m6 {w x y} {
  697.     set ent [$w nearest $x $y]
  698.     if {$ent != ""} {
  699.     tixGrid:CallBrowseCmd $w $ent
  700.     }
  701.     tixGrid:GoState m0 $w  
  702. }
  703.  
  704. proc tixGrid:GoState-m7 {w x y} {
  705.     set from [$w info anchor]
  706.     set to   [$w nearest $x $y]
  707.     if {$from == ""} {
  708.     set from $to
  709.     $w anchor set $from
  710.     }
  711.     if {$to != ""} {
  712.     $w selection clear
  713.     $w selection set $from $to
  714.     tixGrid:CallBrowseCmd $w $to
  715.     }
  716.     tixGrid:GoState m5 $w
  717. }
  718.  
  719.  
  720. proc tixGrid:GoState-m8 {w} {
  721.     tixGrid:StartScan $w
  722. }
  723.  
  724. proc tixGrid:GoState-m9 {w} {
  725.     tixGrid:DoScan $w
  726. }
  727.  
  728. proc tixGrid:GoState-xm7 {w x y} {
  729.     set ent [$w nearest $x $y]
  730.  
  731.     if {$ent != ""} {
  732.     $w selection clear
  733.     $w selection set $ent
  734.     tixGrid:CallCommand $w $ent
  735.     }
  736.     tixGrid:GoState m0 $w
  737. }
  738.  
  739. #----------------------------------------------------------------------
  740. #    EXTENDED SELECTION
  741. #----------------------------------------------------------------------
  742. proc tixGrid:GoState-e0 {w} {
  743. }
  744.  
  745. proc tixGrid:GoState-e1 {w x y} {
  746.     set ent [$w nearest $x $y]
  747.     if {$ent != ""} {
  748.     $w anchor set $ent
  749.     $w selection clear
  750.     $w selection set $ent
  751.     tixGrid:CallBrowseCmd $w $ent
  752.     }
  753.     tixGrid:GoState e2 $w
  754. }
  755.  
  756. proc tixGrid:GoState-e2 {w} {
  757. }
  758.  
  759. proc tixGrid:GoState-e3 {w} {
  760.     set ent [$w info anchor]
  761.     if {$ent != ""} {
  762.     tixGrid:CallBrowseCmd $w $ent
  763.     }
  764.     tixGrid:GoState e0 $w
  765. }
  766.  
  767. proc tixGrid:GoState-e4 {w x y} {
  768.     set from [$w info anchor]
  769.     set to   [$w nearest $x $y]
  770.     if {$to != ""} {
  771.     $w selection clear
  772.     $w selection set $from $to
  773.     tixGrid:CallBrowseCmd $w $to
  774.     }
  775.     tixGrid:GoState e5 $w
  776. }
  777.  
  778. proc tixGrid:GoState-e5 {w} {
  779. }
  780.  
  781. proc tixGrid:GoState-e6 {w x y} {
  782.     set ent [$w nearest $x $y]
  783.     if {$ent != ""} {
  784.     tixGrid:CallBrowseCmd $w $ent
  785.     }
  786.     tixGrid:GoState e0 $w  
  787. }
  788.  
  789. proc tixGrid:GoState-e7 {w x y} {
  790.     set from [$w info anchor]
  791.     set to   [$w nearest $x $y]
  792.     if {$from == ""} {
  793.     set from $to
  794.     $w anchor set $from
  795.     }
  796.     if {$to != ""} {
  797.     $w selection clear
  798.     $w selection set $from $to
  799.     tixGrid:CallBrowseCmd $w $to
  800.     }
  801.     tixGrid:GoState e5 $w
  802. }
  803.  
  804.  
  805. proc tixGrid:GoState-e8 {w} {
  806.     tixGrid:StartScan $w
  807. }
  808.  
  809. proc tixGrid:GoState-e9 {w} {
  810.     tixGrid:DoScan $w
  811. }
  812.  
  813. proc tixGrid:GoState-e10 {w x y} {
  814.     set ent [$w nearest $x $y]
  815.     if {$ent != ""} {
  816.     if {[$w info anchor] == ""} {
  817.         $w anchor set $ent
  818.     }
  819.     if {[$w selection includes $ent]} {
  820.         $w selection clear $ent
  821.     } else {
  822.         $w selection set $ent
  823.     }
  824.     tixGrid:CallBrowseCmd $w $ent
  825.     }
  826.     tixGrid:GoState e2 $w
  827. }
  828.  
  829. proc tixGrid:GoState-xm7 {w x y} {
  830.     set ent [$w nearest $x $y]
  831.  
  832.     if {$ent != ""} {
  833.     $w selection clear
  834.     $w selection set $ent
  835.     tixGrid:CallCommand $w $ent
  836.     }
  837.     tixGrid:GoState e0 $w
  838. }
  839.  
  840. #----------------------------------------------------------------------
  841. #    HODGE PODGE
  842. #----------------------------------------------------------------------
  843.  
  844. proc tixGrid:GoState-12 {w x y} {
  845.     tkCancelRepeat
  846.     tixGrid:GoState 5 $w $x $y 
  847. }
  848.  
  849. proc tixGrid:GoState-13 {w ent oldEnt} {
  850.     global tkPriv
  851.     set tkPriv(tix,indicator) $ent
  852.     set tkPriv(tix,oldEnt)    $oldEnt
  853.     tixGrid:IndicatorCmd $w <Arm> $ent
  854. }
  855.  
  856. proc tixGrid:GoState-14 {w x y} {
  857.     global tkPriv
  858.  
  859.     if {[tixGrid:InsideArmedIndicator $w $x $y]} {
  860.     $w anchor set $tkPriv(tix,indicator)
  861.     $w select clear
  862.     $w select set $tkPriv(tix,indicator)
  863.     tixGrid:IndicatorCmd $w <Activate> $tkPriv(tix,indicator)
  864.     } else {
  865.     tixGrid:IndicatorCmd $w <Disarm>   $tkPriv(tix,indicator)
  866.     }
  867.  
  868.     unset tkPriv(tix,indicator)
  869.     tixGrid:GoState 0 $w
  870. }
  871.  
  872. proc tixGrid:GoState-16 {w ent} {
  873.     if {$ent == ""} {
  874.     return
  875.     }
  876.     if {[$w cget -selectmode] != "single"} {
  877.     tixGrid:Select $w $ent
  878.     tixGrid:Browse $w $ent
  879.     }
  880. }
  881.  
  882. proc tixGrid:GoState-18 {w} {
  883.     global tkPriv
  884.     tkCancelRepeat
  885.     tixGrid:GoState 6 $w $tkPriv(x) $tkPriv(y) 
  886. }
  887.  
  888. proc tixGrid:GoState-20 {w x y} {
  889.     global tkPriv
  890.  
  891.     if {![tixGrid:InsideArmedIndicator $w $x $y]} {
  892.     tixGrid:GoState 21 $w $x $y
  893.     } else {
  894.     tixGrid:IndicatorCmd $w <Arm> $tkPriv(tix,indicator)
  895.     }
  896. }
  897.  
  898. proc tixGrid:GoState-21 {w x y} {
  899.     global tkPriv
  900.  
  901.     if {[tixGrid:InsideArmedIndicator $w $x $y]} {
  902.     tixGrid:GoState 20 $w $x $y
  903.     } else {
  904.     tixGrid:IndicatorCmd $w <Disarm> $tkPriv(tix,indicator)
  905.     }
  906. }
  907.  
  908. proc tixGrid:GoState-22 {w} {
  909.     global tkPriv
  910.  
  911.     if {$tkPriv(tix,oldEnt) != ""} {
  912.     $w anchor set $tkPriv(tix,oldEnt)
  913.     } else {
  914.     $w anchor clear
  915.     }
  916.     tixGrid:GoState 0 $w
  917. }
  918.  
  919.  
  920. #----------------------------------------------------------------------
  921. #            callback actions
  922. #----------------------------------------------------------------------
  923. proc tixGrid:SetAnchor {w ent} {
  924.     if {[string compare $ent ""]} {
  925.     $w anchor set [lindex $ent 0] [lindex $ent 1]
  926. #    $w see $ent
  927.     }
  928. }
  929.  
  930. proc tixGrid:Select {w ent} {
  931.     $w selection clear
  932.     $w select set $ent
  933. }
  934.  
  935. proc tixGrid:StartScan {w} {
  936.     global tkPriv
  937.     set tkPriv(afterId) [after 50 tixGrid:AutoScan $w]
  938. }
  939.  
  940. proc tixGrid:DoScan {w} {
  941.     global tkPriv
  942.     set x $tkPriv(x)
  943.     set y $tkPriv(y)
  944.     set X $tkPriv(X)
  945.     set Y $tkPriv(Y)
  946.  
  947.     set out 0
  948.     if {$y >= [winfo height $w]} {
  949.     $w yview scroll 1 units
  950.     set out 1
  951.     }
  952.     if {$y < 0} {
  953.     $w yview scroll -1 units
  954.     set out 1
  955.     }
  956.     if {$x >= [winfo width $w]} {
  957.     $w xview scroll 2 units
  958.     set out 1
  959.     } 
  960.     if {$x < 0} {
  961.     $w xview scroll -2 units
  962.     set out 1
  963.     }
  964.  
  965.     if {$out} {
  966.     set tkPriv(afterId) [after 50 tixGrid:AutoScan $w]
  967.     }
  968. }
  969.  
  970. proc tixGrid:CallBrowseCmd {w ent} {
  971.     return
  972.  
  973.     set browsecmd [$w cget -browsecmd]
  974.     if {$browsecmd != ""} {
  975.     set bind(specs) {%V}
  976.     set bind(%V)    $ent
  977.  
  978.     tixEvalCmdBinding $w $browsecmd bind $ent
  979.     }
  980. }
  981.  
  982. proc tixGrid:CallCommand {w ent} {
  983.     set command [$w cget -command]
  984.     if {$command != ""} {
  985.     set bind(specs) {%V}
  986.     set bind(%V)    $ent
  987.  
  988.     tixEvalCmdBinding $w $command bind $ent
  989.     }
  990. }
  991.  
  992. # tixGrid:EditCell --
  993. #
  994. #    This command is called when "$w edit set $x $y" is called. It causes
  995. #    an SetEdit call when the grid's state is 0.
  996. #
  997. proc tixGrid:EditCell {w x y} {
  998.     set list $w:_list
  999.     global $list
  1000.  
  1001.     case [tixGrid:GetState $w] {
  1002.     {0} {
  1003.         tixGrid:SetEdit $w [list $x $y]
  1004.            }
  1005.     default {
  1006.         lappend $list [list tixGrid:SetEdit $w [list $x $y]]
  1007.     }
  1008.     }
  1009. }
  1010.  
  1011. # tixGrid:EditApply --
  1012. #
  1013. #    This command is called when "$w edit apply $x $y" is called. It causes
  1014. #    an CheckEdit call when the grid's state is 0.
  1015. #
  1016. proc tixGrid:EditApply {w} {
  1017.     set list $w:_list
  1018.     global $list
  1019.  
  1020.     case [tixGrid:GetState $w] {
  1021.     {0} {
  1022.         tixGrid:CheckEdit $w
  1023.            }
  1024.     default {
  1025.         lappend $list [list tixGrid:CheckEdit $w]
  1026.     }
  1027.     }
  1028. }
  1029.  
  1030. # tixGrid:CheckEdit --
  1031. #
  1032. #    This procedure is called when the user sets the focus on a cell.
  1033. #    If another cell is being edited, apply the changes of that cell.
  1034. #
  1035. proc tixGrid:CheckEdit {w} {
  1036.     set edit $w.tixpriv__edit
  1037.     if {[winfo exists $edit]} {
  1038.     #
  1039.     # If it -command is not empty, it is being used for another cell.
  1040.     # Invoke it so that the other cell can be updated.
  1041.     #
  1042.     if {![tixStrEq [$edit cget -command] ""]} {
  1043.         $edit invoke
  1044.     }
  1045.     }
  1046. }
  1047.  
  1048. # tixGrid:SetEdit --
  1049. #
  1050. #    Puts a floatentry on top of an editable entry.
  1051. #
  1052. proc tixGrid:SetEdit {w ent} {
  1053.     set edit $w.tixpriv__edit
  1054.     tixGrid:CheckEdit $w
  1055.  
  1056.     set editnotifycmd [$w cget -editnotifycmd]
  1057.     if {[tixStrEq $editnotifycmd ""]} {
  1058.     return
  1059.     }
  1060.     set px [lindex $ent 0]
  1061.     set py [lindex $ent 1]
  1062.  
  1063.     if {![uplevel #0 $editnotifycmd $px $py]} {
  1064.     return
  1065.     }
  1066.     if {[$w info exists $px $py]} {
  1067.     if [catch {
  1068.         set oldValue [$w entrycget $px $py -text]
  1069.     }] {
  1070.         # The entry doesn't support -text option. Can't edit it.
  1071.         #
  1072.         # If the application wants to force editing of an entry, it could
  1073.         # delete or replace the entry in the editnotifyCmd procedure.
  1074.         #
  1075.         return
  1076.     }
  1077.     } else {
  1078.     set oldValue ""
  1079.     }
  1080.  
  1081.     set bbox [$w info bbox [lindex $ent 0] [lindex $ent 1]]
  1082.     set x [lindex $bbox 0]
  1083.     set y [lindex $bbox 1]
  1084.     set W [lindex $bbox 2]
  1085.     set H [lindex $bbox 3]
  1086.  
  1087.     if {![winfo exists $edit]} {
  1088.     tixFloatEntry $edit
  1089.     }
  1090.  
  1091.     $edit config -command "tixGrid:DoneEdit $w $ent"
  1092.     $edit post $x $y $W $H
  1093.  
  1094.     $edit config -value $oldValue
  1095. }
  1096.  
  1097. proc tixGrid:DoneEdit {w x y args} {
  1098.     set edit $w.tixpriv__edit
  1099.     $edit config -command ""
  1100.     $edit unpost
  1101.  
  1102.     set value [tixEvent value]
  1103.     if {[$w info exists $x $y]} {
  1104.     if [catch {
  1105.         $w entryconfig $x $y -text $value
  1106.     }] {
  1107.         return
  1108.     }
  1109.     } elseif {![tixStrEq $value ""]} {    
  1110.     if [catch {
  1111.         # This needs to be catch'ed because the default itemtype may
  1112.         # not support the -text option
  1113.         #
  1114.         $w set $x $y -text $value
  1115.     }] {
  1116.         return
  1117.     }
  1118.     } else {
  1119.     return
  1120.     }
  1121.  
  1122.     set editDoneCmd [$w cget -editdonecmd]
  1123.     if {![tixStrEq $editDoneCmd ""]} {
  1124.     uplevel #0 $editDoneCmd $x $y
  1125.     }
  1126. }
  1127.  
  1128. proc tixGrid:SetFocus {w} {
  1129.     if {[$w cget -takefocus]} {
  1130.     if {![string match $w.* [focus -displayof $w]]} {
  1131.         focus $w
  1132.     }
  1133.     }
  1134. }
  1135.