Grid.tcl 21 KB

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