Tree.tcl 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: Tree.tcl,v 1.7 2004/04/09 21:39:12 hobbs Exp $
  4. #
  5. # Tree.tcl --
  6. #
  7. # This file implements the TixTree widget.
  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. tixWidgetClass tixTree {
  16. -classname TixTree
  17. -superclass tixVTree
  18. -method {
  19. autosetmode close getmode open setmode
  20. addchild anchor column delete entrycget
  21. entryconfigure header hide indicator info
  22. item nearest see selection show
  23. }
  24. -flag {
  25. -browsecmd -command -opencmd -closecmd
  26. }
  27. -configspec {
  28. {-browsecmd browseCmd BrowseCmd ""}
  29. {-command command Command ""}
  30. {-closecmd closeCmd CloseCmd ""}
  31. {-opencmd openCmd OpenCmd ""}
  32. }
  33. -default {
  34. {.scrollbar auto}
  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 2}
  45. {*hlist.padY 2}
  46. {*hlist.relief sunken}
  47. {*hlist.takeFocus 1}
  48. {*hlist.wideSelection 0}
  49. {*hlist.width 20}
  50. }
  51. }
  52. proc tixTree:InitWidgetRec {w} {
  53. upvar #0 $w data
  54. tixChainMethod $w InitWidgetRec
  55. }
  56. proc tixTree:ConstructWidget {w} {
  57. upvar #0 $w data
  58. tixChainMethod $w ConstructWidget
  59. }
  60. proc tixTree:SetBindings {w} {
  61. upvar #0 $w data
  62. tixChainMethod $w SetBindings
  63. }
  64. #----------------------------------------------------------------------
  65. #
  66. # Widget commands
  67. #
  68. #----------------------------------------------------------------------
  69. proc tixTree:autosetmode {w} {
  70. tixTree:SetModes $w ""
  71. }
  72. proc tixTree:close {w ent} {
  73. upvar #0 $w data
  74. set type [tixVTree:GetType $w $ent]
  75. if {$type == "close"} {
  76. tixCallMethod $w Activate $ent $type
  77. }
  78. }
  79. proc tixTree:open {w ent} {
  80. upvar #0 $w data
  81. set type [tixVTree:GetType $w $ent]
  82. if {$type == "open"} {
  83. tixCallMethod $w Activate $ent $type
  84. }
  85. }
  86. proc tixTree:getmode {w ent} {
  87. tixVTree:GetType $w $ent
  88. }
  89. proc tixTree:setmode {w ent mode} {
  90. tixVTree:SetMode $w $ent $mode
  91. }
  92. foreach cmd {
  93. addchild anchor column delete entrycget
  94. entryconfigure header hide indicator info
  95. item nearest see selection show
  96. } {
  97. proc tixTree:$cmd {w args} {
  98. # These are hlist passthrough methods to work around
  99. # Tix' ignorant inheritance model.
  100. upvar #0 $w data
  101. set cmd [lindex [split [lindex [info level 0] 0] :] end]
  102. uplevel 1 [linsert $args 0 $data(w:hlist) $cmd]
  103. }
  104. }
  105. unset cmd
  106. #----------------------------------------------------------------------
  107. #
  108. # Private Methods
  109. #
  110. #----------------------------------------------------------------------
  111. proc tixTree:SetModes {w ent} {
  112. upvar #0 $w data
  113. set mode none
  114. if {$ent == ""} {
  115. set children [$data(w:hlist) info children]
  116. } else {
  117. set children [$data(w:hlist) info children $ent]
  118. }
  119. if {$children != ""} {
  120. set mode close
  121. foreach c $children {
  122. if {[$data(w:hlist) info hidden $c]} {
  123. set mode open
  124. }
  125. tixTree:SetModes $w $c
  126. }
  127. }
  128. if {$ent != ""} {
  129. tixVTree:SetMode $w $ent $mode
  130. }
  131. }
  132. #----------------------------------------------------------------------
  133. #
  134. # Virtual Methods
  135. #
  136. #----------------------------------------------------------------------
  137. proc tixTree:OpenCmd {w ent} {
  138. upvar #0 $w data
  139. if {$data(-opencmd) != ""} {
  140. tixTree:CallSwitchCmd $w $data(-opencmd) $ent
  141. } else {
  142. tixChainMethod $w OpenCmd $ent
  143. }
  144. }
  145. proc tixTree:CloseCmd {w ent} {
  146. upvar #0 $w data
  147. if {$data(-closecmd) != ""} {
  148. tixTree:CallSwitchCmd $w $data(-closecmd) $ent
  149. } else {
  150. tixChainMethod $w CloseCmd $ent
  151. }
  152. }
  153. # Call the opencmd or closecmd, depending on the mode ($cmd argument)
  154. #
  155. proc tixTree:CallSwitchCmd {w cmd ent} {
  156. upvar #0 $w data
  157. set bind(specs) {%V}
  158. set bind(%V) $ent
  159. tixEvalCmdBinding $w $cmd bind $ent
  160. }
  161. proc tixTree:Command {w B} {
  162. upvar #0 $w data
  163. upvar $B bind
  164. tixChainMethod $w Command $B
  165. set ent [tixEvent flag V]
  166. if {$data(-command) != ""} {
  167. tixEvalCmdBinding $w $data(-command) bind $ent
  168. }
  169. }
  170. proc tixTree:BrowseCmd {w B} {
  171. upvar #0 $w data
  172. set ent [tixEvent flag V]
  173. if {$data(-browsecmd) != ""} {
  174. tixEvalCmdBinding $w $data(-browsecmd) "" $ent
  175. }
  176. }