ChkList.tcl 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: ChkList.tcl,v 1.6 2004/03/28 02:44:57 hobbs Exp $
  4. #
  5. # ChkList.tcl --
  6. #
  7. # This file implements the TixCheckList widget.
  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. tixWidgetClass tixCheckList {
  17. -classname TixCheckList
  18. -superclass tixTree
  19. -method {
  20. getselection getstatus setstatus
  21. }
  22. -flag {
  23. -radio
  24. }
  25. -configspec {
  26. {-radio radio Radio false tixVerifyBoolean}
  27. {-ignoreinvoke ignoreInvoke IgnoreInvoke true tixVerifyBoolean}
  28. }
  29. -static {
  30. -radio
  31. }
  32. -default {
  33. {.scrollbar auto}
  34. {.doubleClick false}
  35. {*Scrollbar.takeFocus 0}
  36. {*borderWidth 1}
  37. {*hlist.background #c3c3c3}
  38. {*hlist.drawBranch 1}
  39. {*hlist.height 10}
  40. {*hlist.highlightBackground #d9d9d9}
  41. {*hlist.indicator 1}
  42. {*hlist.indent 20}
  43. {*hlist.itemType imagetext}
  44. {*hlist.padX 3}
  45. {*hlist.padY 0}
  46. {*hlist.relief sunken}
  47. {*hlist.takeFocus 1}
  48. {*hlist.wideSelection 0}
  49. {*hlist.width 20}
  50. }
  51. }
  52. proc tixCheckList:InitWidgetRec {w} {
  53. upvar #0 $w data
  54. tixChainMethod $w InitWidgetRec
  55. if {$data(-radio)} {
  56. set data(selected) ""
  57. }
  58. }
  59. #----------------------------------------------------------------------
  60. #
  61. # Widget commands
  62. #
  63. #----------------------------------------------------------------------
  64. # Helper function for getselection
  65. #
  66. proc tixCheckList:GetSel {w var ent mode} {
  67. upvar #0 $w data
  68. upvar $var img
  69. set ents ""
  70. catch {
  71. if {[$data(w:hlist) entrycget $ent -bitmap] eq $img($mode)} {
  72. lappend ents $ent
  73. }
  74. }
  75. foreach child [$data(w:hlist) info children $ent] {
  76. set ents [concat $ents [tixCheckList:GetSel $w img $child $mode]]
  77. }
  78. return $ents
  79. }
  80. # Mode can be on, off, default
  81. #
  82. proc tixCheckList:getselection {w {mode on}} {
  83. upvar #0 $w data
  84. set img(on) [tix getbitmap ck_on]
  85. set img(off) [tix getbitmap ck_off]
  86. set img(default) [tix getbitmap ck_def]
  87. set ents ""
  88. foreach child [$data(w:hlist) info children] {
  89. set ents [concat $ents [tixCheckList:GetSel $w img $child $mode]]
  90. }
  91. return $ents
  92. }
  93. proc tixCheckList:getstatus {w ent} {
  94. upvar #0 $w data
  95. if {[$data(w:hlist) entrycget $ent -itemtype] eq "imagetext"} {
  96. set img(on) [tix getbitmap ck_on]
  97. set img(off) [tix getbitmap ck_off]
  98. set img(default) [tix getbitmap ck_def]
  99. set bitmap [$data(w:hlist) entrycget $ent -bitmap]
  100. if {$bitmap eq $img(on)} {
  101. set status on
  102. }
  103. if {$bitmap eq $img(off)} {
  104. set status off
  105. }
  106. if {$bitmap eq $img(default)} {
  107. set status default
  108. }
  109. }
  110. if {[info exists status]} {
  111. return $status
  112. } else {
  113. return "none"
  114. }
  115. }
  116. proc tixCheckList:setstatus {w ent {mode on}} {
  117. upvar #0 $w data
  118. if {$data(-radio)} {
  119. set status [tixCheckList:getstatus $w $ent]
  120. if {$status eq $mode} {
  121. return
  122. }
  123. if {$mode eq "on"} {
  124. if {$data(selected) != ""} {
  125. tixCheckList:Select $w $data(selected) off
  126. }
  127. set data(selected) $ent
  128. tixCheckList:Select $w $ent $mode
  129. } elseif {$mode eq "off"} {
  130. if {$data(selected) eq $ent} {
  131. return
  132. }
  133. tixCheckList:Select $w $ent $mode
  134. } else {
  135. tixCheckList:Select $w $ent $mode
  136. }
  137. } else {
  138. tixCheckList:Select $w $ent $mode
  139. }
  140. }
  141. proc tixCheckList:Select {w ent mode} {
  142. upvar #0 $w data
  143. if {[$data(w:hlist) entrycget $ent -itemtype] eq "imagetext"} {
  144. set img(on) ck_on
  145. set img(off) ck_off
  146. set img(default) ck_def
  147. if [catch {
  148. set bitmap [tix getbitmap $img($mode)]
  149. $data(w:hlist) entryconfig $ent -bitmap $bitmap
  150. }] {
  151. # must be the "none" mode
  152. #
  153. catch {
  154. $data(w:hlist) entryconfig $ent -bitmap ""
  155. }
  156. }
  157. }
  158. return $mode
  159. }
  160. proc tixCheckList:HandleCheck {w ent} {
  161. upvar #0 $w data
  162. if {[$data(w:hlist) entrycget $ent -itemtype] eq "imagetext"} {
  163. set img(on) [tix getbitmap ck_on]
  164. set img(off) [tix getbitmap ck_off]
  165. set img(default) [tix getbitmap ck_def]
  166. set curMode [tixCheckList:getstatus $w $ent]
  167. case $curMode {
  168. on {
  169. tixCheckList:setstatus $w $ent off
  170. }
  171. off {
  172. tixCheckList:setstatus $w $ent on
  173. }
  174. none {
  175. return
  176. }
  177. default {
  178. tixCheckList:setstatus $w $ent on
  179. }
  180. }
  181. }
  182. }
  183. proc tixCheckList:Command {w B} {
  184. upvar #0 $w data
  185. upvar $B bind
  186. set ent [tixEvent flag V]
  187. tixCheckList:HandleCheck $w $ent
  188. tixChainMethod $w Command $B
  189. }
  190. proc tixCheckList:BrowseCmd {w B} {
  191. upvar #0 $w data
  192. upvar $B bind
  193. set ent [tixEvent flag V]
  194. case [tixEvent type] {
  195. {<ButtonPress-1> <space>} {
  196. tixCheckList:HandleCheck $w $ent
  197. }
  198. }
  199. tixChainMethod $w BrowseCmd $B
  200. }