HList.tcl 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917
  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: HList.tcl,v 1.6 2004/03/28 02:44:57 hobbs Exp $
  4. #
  5. # HList.tcl --
  6. #
  7. # This file defines the default bindings for Tix Hierarchical Listbox
  8. # widgets.
  9. #
  10. # Copyright (c) 1993-1999 Ioi Kim Lam.
  11. # Copyright (c) 2000-2001 Tix Project Group.
  12. # Copyright (c) 2004 ActiveState
  13. #
  14. # See the file "license.terms" for information on usage and redistribution
  15. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  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. proc tixHListBind {} {
  35. tixBind TixHList <ButtonPress-1> {
  36. tixHList:Button-1 %W %x %y ""
  37. }
  38. tixBind TixHList <Shift-ButtonPress-1> {
  39. tixHList:Button-1 %W %x %y s
  40. }
  41. tixBind TixHList <Control-ButtonPress-1> {
  42. tixHList:Button-1 %W %x %y c
  43. }
  44. tixBind TixHList <ButtonRelease-1> {
  45. tixHList:ButtonRelease-1 %W %x %y
  46. }
  47. tixBind TixHList <Double-ButtonPress-1> {
  48. tixHList:Double-1 %W %x %y
  49. }
  50. tixBind TixHList <B1-Motion> {
  51. set tkPriv(x) %x
  52. set tkPriv(y) %y
  53. set tkPriv(X) %X
  54. set tkPriv(Y) %Y
  55. tixHList:B1-Motion %W %x %y
  56. }
  57. tixBind TixHList <B1-Leave> {
  58. set tkPriv(x) %x
  59. set tkPriv(y) %y
  60. set tkPriv(X) %X
  61. set tkPriv(Y) %Y
  62. tixHList:B1-Leave %W
  63. }
  64. tixBind TixHList <B1-Enter> {
  65. tixHList:B1-Enter %W %x %y
  66. }
  67. # Keyboard bindings
  68. #
  69. tixBind TixHList <Up> {
  70. tixHList:UpDown %W prev ""
  71. }
  72. tixBind TixHList <Down> {
  73. tixHList:UpDown %W next ""
  74. }
  75. tixBind TixHList <Shift-Up> {
  76. tixHList:UpDown %W prev s
  77. }
  78. tixBind TixHList <Shift-Down> {
  79. tixHList:UpDown %W next s
  80. }
  81. tixBind TixHList <Left> {
  82. tixHList:LeftRight %W left
  83. }
  84. tixBind TixHList <Right> {
  85. tixHList:LeftRight %W right
  86. }
  87. tixBind TixHList <Prior> {
  88. %W yview scroll -1 pages
  89. }
  90. tixBind TixHList <Next> {
  91. %W yview scroll 1 pages
  92. }
  93. tixBind TixHList <Return> {
  94. tixHList:Keyboard-Activate %W
  95. }
  96. tixBind TixHList <space> {
  97. tixHList:Keyboard-Browse %W
  98. }
  99. # Under Windows <Home> moves up, clears the sel and sets the selection
  100. # Under Windows <Control-Home> moves up, leaves the selection, and sets the anchor
  101. tixBind TixHList <Home> {
  102. set w %W
  103. $w yview moveto 0; # $w xview moveto 0
  104. set sel [lindex [$w info children] 0]
  105. # should be first not disabled
  106. $w anchor set $sel
  107. tixHList:Keyboard-Browse $w
  108. }
  109. tixBind TixHList <End> {
  110. set w %W
  111. $w yview moveto 1; # $w xview moveto 0
  112. $w select clear
  113. # should be last not disabled
  114. set sel [lindex [$w info children .] end]
  115. while {[set next [$w info next $sel]] ne "" && \
  116. ![$w info hidden $next] && \
  117. [llength [set kids [$w info child $sel]]]} {
  118. set sel [lindex $kids end]
  119. }
  120. $w anchor set $sel
  121. tixHList:Keyboard-Browse $w
  122. }
  123. tixBind TixHList <Control-Home> {
  124. set w %W
  125. $w yview moveto 0; # $w xview moveto 0
  126. set sel [lindex [$w info children] 0]
  127. # should be first not disabled
  128. $w anchor set $sel
  129. }
  130. tixBind TixHList <Control-End> {
  131. set w %W
  132. $w yview moveto 1; # $w xview moveto 0
  133. # should be last not disabled
  134. set sel [lindex [$w info children .] end]
  135. while {[set next [$w info next $sel]] ne "" && \
  136. ![$w info hidden $next] && \
  137. [llength [set kids [$w info child $sel]]]} {
  138. set sel [lindex $kids end]
  139. }
  140. $w anchor set $sel
  141. }
  142. #
  143. # Don't use tixBind because %A causes Tk 8.3.2 to crash
  144. #
  145. bind TixHList <MouseWheel> {
  146. %W yview scroll [expr {- (%D / 120) * 2}] units
  147. }
  148. }
  149. #----------------------------------------------------------------------
  150. #
  151. #
  152. # Key bindings
  153. #
  154. #
  155. #----------------------------------------------------------------------
  156. proc tixHList:Keyboard-Activate {w} {
  157. if {[tixHList:GetState $w] != 0} {
  158. return
  159. }
  160. set ent [$w info anchor]
  161. if {$ent eq ""} {
  162. return
  163. }
  164. if {[$w cget -selectmode] eq "single"} {
  165. $w select clear
  166. }
  167. $w select set $ent
  168. set command [$w cget -command]
  169. if {$command ne ""} {
  170. set bind(specs) {%V}
  171. set bind(%V) $ent
  172. tixEvalCmdBinding $w $command bind $ent
  173. }
  174. }
  175. proc tixHList:Keyboard-Browse {w} {
  176. if {[tixHList:GetState $w] != 0} {
  177. return
  178. }
  179. set ent [$w info anchor]
  180. if {$ent eq ""} {
  181. return
  182. }
  183. if {[$w cget -selectmode] eq "single"} {
  184. $w select clear
  185. }
  186. $w select set $ent
  187. tixHList:Browse $w $ent
  188. }
  189. proc tixHList:LeftRight {w spec} {
  190. catch {
  191. uplevel #0 unset $w:priv:shiftanchor
  192. }
  193. if {[tixHList:GetState $w] != 0} {
  194. return
  195. }
  196. set anchor [$w info anchor]
  197. if {$anchor eq ""} {
  198. set anchor [lindex [$w info children] 0]
  199. }
  200. if {$anchor eq ""} {
  201. return
  202. }
  203. set ent $anchor
  204. while {1} {
  205. set e $ent
  206. if {$spec eq "left"} {
  207. set ent [$w info parent $e]
  208. if {$ent eq "" || [$w entrycget $ent -state] eq "disabled"} {
  209. set ent [$w info prev $e]
  210. }
  211. } else {
  212. set ent [lindex [$w info children $e] 0]
  213. if {$ent eq "" || [$w entrycget $ent -state] eq "disabled"} {
  214. set ent [$w info next $e]
  215. }
  216. }
  217. if {$ent eq ""} {
  218. break
  219. }
  220. if {[$w entrycget $ent -state] eq "disabled"} {
  221. continue
  222. }
  223. if {[$w info hidden $ent]} {
  224. continue
  225. }
  226. break
  227. }
  228. if {$ent eq ""} {
  229. return
  230. }
  231. $w anchor set $ent
  232. $w see $ent
  233. if {[$w cget -selectmode] ne "single"} {
  234. $w select clear
  235. $w selection set $ent
  236. tixHList:Browse $w $ent
  237. }
  238. }
  239. proc tixHList:UpDown {w spec mod} {
  240. if {[tixHList:GetState $w] ne 0} {
  241. return
  242. }
  243. set anchor [$w info anchor]
  244. set done 0
  245. if {$anchor eq ""} {
  246. set anchor [lindex [$w info children] 0]
  247. if {$anchor eq ""} {
  248. return
  249. }
  250. if {[$w entrycget $anchor -state] ne "disabled"} {
  251. # That's a good anchor
  252. set done 1
  253. } else {
  254. # We search for the first non-disabled entry (downward)
  255. set spec next
  256. }
  257. }
  258. set ent $anchor
  259. # mike - bulletproofing
  260. if {![$w info exists $ent]} {return}
  261. # Find the prev/next non-disabled entry
  262. #
  263. while {!$done} {
  264. set ent [$w info $spec $ent]
  265. if {$ent eq ""} {
  266. break
  267. }
  268. if {[$w entrycget $ent -state] eq "disabled"} {
  269. continue
  270. }
  271. if {[$w info hidden $ent]} {
  272. continue
  273. }
  274. break
  275. }
  276. if {$ent eq ""} {
  277. return
  278. } else {
  279. $w see $ent
  280. $w anchor set $ent
  281. set selMode [$w cget -selectmode]
  282. if {$mod eq "s" && ($selMode eq "extended" || $selMode eq "multiple")} {
  283. global $w:priv:shiftanchor
  284. if {![info exists $w:priv:shiftanchor]} {
  285. set $w:priv:shiftanchor $anchor
  286. }
  287. $w selection clear
  288. # mike - bulletproofing
  289. if {![catch {$w selection set $ent [set $w:priv:shiftanchor]}]} {
  290. tixHList:Browse $w $ent
  291. }
  292. } else {
  293. catch {
  294. uplevel #0 unset $w:priv:shiftanchor
  295. }
  296. if {[$w cget -selectmode] ne "single"} {
  297. $w select clear
  298. $w selection set $ent
  299. tixHList:Browse $w $ent
  300. }
  301. }
  302. }
  303. }
  304. #----------------------------------------------------------------------
  305. #
  306. #
  307. # Mouse bindings
  308. #
  309. #
  310. #----------------------------------------------------------------------
  311. proc tixHList:Button-1 {w x y mod} {
  312. # if {[$w cget -state] eq "disabled"} {
  313. # return
  314. # }
  315. if {[$w cget -takefocus]} {
  316. focus $w
  317. }
  318. set selMode [$w cget -selectmode]
  319. case [tixHList:GetState $w] {
  320. {0} {
  321. if {$mod eq "s" && $selMode eq "multiple"} {
  322. tixHList:GoState 28 $w $x $y
  323. return
  324. }
  325. if {$mod eq "s" && $selMode eq "extended"} {
  326. tixHList:GoState 28 $w $x $y
  327. return
  328. }
  329. if {$mod eq "c" && $selMode eq "extended"} {
  330. tixHList:GoState 33 $w $x $y
  331. return
  332. }
  333. tixHList:GoState 1 $w $x $y
  334. }
  335. }
  336. }
  337. proc tixHList:ButtonRelease-1 {w x y} {
  338. case [tixHList:GetState $w] {
  339. {5 16} {
  340. tixHList:GoState 6 $w $x $y
  341. }
  342. {15} {
  343. tixHList:GoState 17 $w $x $y
  344. }
  345. {10 11} {
  346. tixHList:GoState 18 $w
  347. }
  348. {13 20} {
  349. tixHList:GoState 14 $w $x $y
  350. }
  351. {21} {
  352. tixHList:GoState 22 $w
  353. }
  354. {24} {
  355. tixHList:GoState 25 $w
  356. }
  357. {26 28 33} {
  358. tixHList:GoState 27 $w
  359. }
  360. {30} {
  361. tixHList:GoState 32 $w
  362. }
  363. }
  364. }
  365. proc tixHList:Double-1 {w x y} {
  366. case [tixHList:GetState $w] {
  367. {0} {
  368. tixHList:GoState 23 $w $x $y
  369. }
  370. }
  371. }
  372. proc tixHList:B1-Motion {w x y} {
  373. case [tixHList:GetState $w] {
  374. {1} {
  375. tixHList:GoState 5 $w $x $y
  376. }
  377. {5 16} {
  378. tixHList:GoState 5 $w $x $y
  379. }
  380. {13 20 21} {
  381. tixHList:GoState 20 $w $x $y
  382. }
  383. {24 26 28} {
  384. tixHList:GoState 26 $w $x $y
  385. }
  386. }
  387. }
  388. proc tixHList:B1-Leave {w} {
  389. case [tixHList:GetState $w] {
  390. {5} {
  391. tixHList:GoState 10 $w
  392. }
  393. {26} {
  394. tixHList:GoState 29 $w
  395. }
  396. }
  397. }
  398. proc tixHList:B1-Enter {w x y} {
  399. case [tixHList:GetState $w] {
  400. {10 11} {
  401. tixHList:GoState 12 $w $x $y
  402. }
  403. {29 30} {
  404. tixHList:GoState 31 $w $x $y
  405. }
  406. }
  407. }
  408. proc tixHList:AutoScan {w} {
  409. case [tixHList:GetState $w] {
  410. {29 30} {
  411. tixHList:GoState 30 $w
  412. }
  413. }
  414. }
  415. #----------------------------------------------------------------------
  416. #
  417. # STATE MANIPULATION
  418. #
  419. #
  420. #----------------------------------------------------------------------
  421. proc tixHList:GetState {w} {
  422. global $w:priv:state
  423. if {![info exists $w:priv:state]} {
  424. set $w:priv:state 0
  425. }
  426. return [set $w:priv:state]
  427. }
  428. proc tixHList:SetState {w n} {
  429. global $w:priv:state
  430. set $w:priv:state $n
  431. }
  432. proc tixHList:GoState {n w args} {
  433. # puts "going from [tixHList:GetState $w] --> $n"
  434. tixHList:SetState $w $n
  435. eval tixHList:GoState-$n $w $args
  436. }
  437. #----------------------------------------------------------------------
  438. # States
  439. #----------------------------------------------------------------------
  440. proc tixHList:GoState-0 {w} {
  441. }
  442. proc tixHList:GoState-1 {w x y} {
  443. set oldEnt [$w info anchor]
  444. set ent [tixHList:SetAnchor $w $x $y 1]
  445. if {$ent eq ""} {
  446. tixHList:GoState 0 $w
  447. return
  448. }
  449. set info [$w info item $x $y]
  450. if {[lindex $info 1] eq "indicator"} {
  451. tixHList:GoState 13 $w $ent $oldEnt
  452. } else {
  453. if {[$w entrycget $ent -state] eq "disabled"} {
  454. tixHList:GoState 0 $w
  455. } else {
  456. case [$w cget -selectmode] {
  457. {single browse} {
  458. tixHList:GoState 16 $w $ent
  459. }
  460. default {
  461. tixHList:GoState 24 $w $ent
  462. }
  463. }
  464. }
  465. }
  466. }
  467. proc tixHList:GoState-5 {w x y} {
  468. set oldEnt [$w info anchor]
  469. set ent [tixHList:SetAnchor $w $x $y]
  470. if {$ent eq "" || $oldEnt eq $ent} {
  471. return
  472. }
  473. if {[$w cget -selectmode] ne "single"} {
  474. tixHList:Select $w $ent
  475. tixHList:Browse $w $ent
  476. }
  477. }
  478. proc tixHList:GoState-6 {w x y} {
  479. set ent [tixHList:SetAnchor $w $x $y]
  480. if {$ent eq ""} {
  481. tixHList:GoState 0 $w
  482. return
  483. }
  484. tixHList:Select $w $ent
  485. tixHList:Browse $w $ent
  486. tixHList:GoState 0 $w
  487. }
  488. proc tixHList:GoState-10 {w} {
  489. tixHList:StartScan $w
  490. }
  491. proc tixHList:GoState-11 {w} {
  492. global tkPriv
  493. tixHList:DoScan $w
  494. set oldEnt [$w info anchor]
  495. set ent [tixHList:SetAnchor $w $tkPriv(x) $tkPriv(y)]
  496. if {$ent eq "" || $oldEnt eq $ent} {
  497. return
  498. }
  499. if {[$w cget -selectmode] ne "single"} {
  500. tixHList:Select $w $ent
  501. tixHList:Browse $w $ent
  502. }
  503. }
  504. proc tixHList:GoState-12 {w x y} {
  505. tkCancelRepeat
  506. tixHList:GoState 5 $w $x $y
  507. }
  508. proc tixHList:GoState-13 {w ent oldEnt} {
  509. global tkPriv
  510. set tkPriv(tix,indicator) $ent
  511. set tkPriv(tix,oldEnt) $oldEnt
  512. tixHList:CallIndicatorCmd $w <Arm> $ent
  513. }
  514. proc tixHList:GoState-14 {w x y} {
  515. global tkPriv
  516. if {[tixHList:InsideArmedIndicator $w $x $y]} {
  517. $w anchor set $tkPriv(tix,indicator)
  518. $w select clear
  519. $w select set $tkPriv(tix,indicator)
  520. tixHList:CallIndicatorCmd $w <Activate> $tkPriv(tix,indicator)
  521. } else {
  522. tixHList:CallIndicatorCmd $w <Disarm> $tkPriv(tix,indicator)
  523. }
  524. unset tkPriv(tix,indicator)
  525. tixHList:GoState 0 $w
  526. }
  527. proc tixHList:GoState-16 {w ent} {
  528. if {$ent ne "" && [$w cget -selectmode] ne "single"} {
  529. tixHList:Select $w $ent
  530. tixHList:Browse $w $ent
  531. }
  532. }
  533. proc tixHList:GoState-18 {w} {
  534. global tkPriv
  535. tkCancelRepeat
  536. tixHList:GoState 6 $w $tkPriv(x) $tkPriv(y)
  537. }
  538. proc tixHList:GoState-20 {w x y} {
  539. global tkPriv
  540. if {![tixHList:InsideArmedIndicator $w $x $y]} {
  541. tixHList:GoState 21 $w $x $y
  542. } else {
  543. tixHList:CallIndicatorCmd $w <Arm> $tkPriv(tix,indicator)
  544. }
  545. }
  546. proc tixHList:GoState-21 {w x y} {
  547. global tkPriv
  548. if {[tixHList:InsideArmedIndicator $w $x $y]} {
  549. tixHList:GoState 20 $w $x $y
  550. } else {
  551. tixHList:CallIndicatorCmd $w <Disarm> $tkPriv(tix,indicator)
  552. }
  553. }
  554. proc tixHList:GoState-22 {w} {
  555. global tkPriv
  556. if {$tkPriv(tix,oldEnt) ne ""} {
  557. $w anchor set $tkPriv(tix,oldEnt)
  558. } else {
  559. $w anchor clear
  560. }
  561. tixHList:GoState 0 $w
  562. }
  563. proc tixHList:GoState-23 {w x y} {
  564. set ent [tixHList:GetNearest $w $y]
  565. if {$ent ne ""} {
  566. set info [$w info item $x $y]
  567. if {[lindex $info 1] eq "indicator"} {
  568. tixHList:CallIndicatorCmd $w <Activate> $ent
  569. } else {
  570. $w select set $ent
  571. set command [$w cget -command]
  572. if {$command ne ""} {
  573. set bind(specs) {%V}
  574. set bind(%V) $ent
  575. tixEvalCmdBinding $w $command bind $ent
  576. }
  577. }
  578. }
  579. tixHList:GoState 0 $w
  580. }
  581. proc tixHList:GoState-24 {w ent} {
  582. if {$ent ne ""} {
  583. tixHList:Select $w $ent
  584. tixHList:Browse $w $ent
  585. }
  586. }
  587. proc tixHList:GoState-25 {w} {
  588. set ent [$w info anchor]
  589. if {$ent ne ""} {
  590. tixHList:Select $w $ent
  591. tixHList:Browse $w $ent
  592. }
  593. tixHList:GoState 0 $w
  594. }
  595. proc tixHList:GoState-26 {w x y} {
  596. set anchor [$w info anchor]
  597. if {$anchor eq ""} {
  598. set first [lindex [$w info children ""] 0]
  599. if {$first ne ""} {
  600. $w anchor set $first
  601. set anchor $first
  602. } else {
  603. return
  604. }
  605. }
  606. set ent [tixHList:GetNearest $w $y 1]
  607. if {$ent ne ""} {
  608. $w selection clear
  609. $w selection set $anchor $ent
  610. tixHList:Browse $w $ent
  611. }
  612. }
  613. proc tixHList:GoState-27 {w} {
  614. set ent [$w info anchor]
  615. if {$ent ne ""} {
  616. tixHList:Browse $w $ent
  617. }
  618. tixHList:GoState 0 $w
  619. }
  620. proc tixHList:GoState-28 {w x y} {
  621. set anchor [$w info anchor]
  622. if {$anchor eq ""} {
  623. set first [lindex [$w info children ""] 0]
  624. if {$first ne ""} {
  625. $w anchor set $first
  626. set anchor $first
  627. } else {
  628. return
  629. }
  630. }
  631. set ent [tixHList:GetNearest $w $y 1]
  632. if {$ent ne ""} {
  633. $w selection clear
  634. $w selection set $anchor $ent
  635. tixHList:Browse $w $ent
  636. }
  637. }
  638. proc tixHList:GoState-29 {w} {
  639. tixHList:StartScan $w
  640. }
  641. proc tixHList:GoState-30 {w} {
  642. global tkPriv
  643. tixHList:DoScan $w
  644. set anchor [$w info anchor]
  645. if {$anchor eq ""} {
  646. set first [lindex [$w info children ""] 0]
  647. if {$first ne ""} {
  648. $w anchor set $first
  649. set anchor $first
  650. } else {
  651. return
  652. }
  653. }
  654. set ent [tixHList:GetNearest $w $tkPriv(y) 1]
  655. if {$ent ne ""} {
  656. $w selection clear
  657. $w selection set $anchor $ent
  658. tixHList:Browse $w $ent
  659. }
  660. }
  661. proc tixHList:GoState-31 {w x y} {
  662. tkCancelRepeat
  663. tixHList:GoState 26 $w $x $y
  664. }
  665. proc tixHList:GoState-32 {w} {
  666. tkCancelRepeat
  667. tixHList:GoState 0 $w
  668. }
  669. proc tixHList:GoState-33 {w x y} {
  670. set ent [tixHList:GetNearest $w $y]
  671. if {$ent ne ""} {
  672. $w anchor set $ent
  673. if {[lsearch [$w selection get] $ent] > -1} {
  674. # This was missing - mike
  675. $w selection clear $ent
  676. } else {
  677. $w selection set $ent
  678. }
  679. tixHList:Browse $w $ent
  680. }
  681. }
  682. #----------------------------------------------------------------------
  683. #
  684. # Common actions
  685. #
  686. #----------------------------------------------------------------------
  687. proc tixHList:GetNearest {w y {disableOK 0}} {
  688. set ent [$w nearest $y]
  689. if {$ent ne ""} {
  690. if {!$disableOK && [$w entrycget $ent -state] eq "disabled"} {
  691. return ""
  692. }
  693. }
  694. return $ent
  695. }
  696. proc tixHList:SetAnchor {w x y {disableOK 0}} {
  697. set ent [tixHList:GetNearest $w $y $disableOK]
  698. if {$ent ne ""} {
  699. if {[$w entrycget $ent -state] ne "disabled"} {
  700. $w anchor set $ent
  701. # mike This is non-standard and has a wierd effect: too much motion
  702. # $w see $ent
  703. return $ent
  704. } elseif $disableOK {
  705. return $ent
  706. }
  707. }
  708. return ""
  709. }
  710. proc tixHList:Select {w ent} {
  711. if {[$w info selection] ne $ent} {
  712. $w selection clear
  713. $w select set $ent
  714. }
  715. }
  716. #----------------------------------------------------------------------
  717. #
  718. # Auto scan
  719. #
  720. #----------------------------------------------------------------------
  721. proc tixHList:StartScan {w} {
  722. global tkPriv
  723. set tkPriv(afterId) [after 50 tixHList:AutoScan $w]
  724. }
  725. proc tixHList:DoScan {w} {
  726. global tkPriv
  727. set x $tkPriv(x)
  728. set y $tkPriv(y)
  729. set X $tkPriv(X)
  730. set Y $tkPriv(Y)
  731. if {$y >= [winfo height $w]} {
  732. $w yview scroll 1 units
  733. } elseif {$y < 0} {
  734. $w yview scroll -1 units
  735. } elseif {$x >= [winfo width $w]} {
  736. $w xview scroll 2 units
  737. } elseif {$x < 0} {
  738. $w xview scroll -2 units
  739. } else {
  740. return
  741. }
  742. set tkPriv(afterId) [after 50 tixHList:AutoScan $w]
  743. }
  744. #----------------------------------------------------------------------
  745. #
  746. # Indicator handling
  747. #
  748. #----------------------------------------------------------------------
  749. proc tixHList:CallIndicatorCmd {w event ent} {
  750. set cmd [$w cget -indicatorcmd]
  751. if {$cmd ne ""} {
  752. set bind(type) $event
  753. set bind(specs) {%V}
  754. set bind(%V) $ent
  755. tixEvalCmdBinding $w $cmd bind $ent
  756. }
  757. }
  758. proc tixHList:InsideArmedIndicator {w x y} {
  759. global tkPriv
  760. set ent [tixHList:GetNearest $w $y 1]
  761. if {$ent eq "" || $ent ne $tkPriv(tix,indicator)} {
  762. return 0
  763. }
  764. set info [$w info item $x $y]
  765. if {[lindex $info 1] eq "indicator"} {
  766. return 1
  767. } else {
  768. return 0
  769. }
  770. }
  771. proc tixHList:Browse {w ent} {
  772. set browsecmd [$w cget -browsecmd]
  773. if {$browsecmd ne ""} {
  774. set bind(specs) {%V}
  775. set bind(%V) $ent
  776. tixEvalCmdBinding $w $browsecmd bind $ent
  777. }
  778. }