VTree.tcl 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: VTree.tcl,v 1.6 2004/03/28 02:44:57 hobbs Exp $
  4. #
  5. # VTree.tcl --
  6. #
  7. # Virtual base class for Tree widgets.
  8. #
  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. tixWidgetClass tixVTree {
  18. -virtual true
  19. -classname TixVTree
  20. -superclass tixScrolledHList
  21. -method {
  22. }
  23. -flag {
  24. -ignoreinvoke
  25. }
  26. -configspec {
  27. {-ignoreinvoke ignoreInvoke IgnoreInvoke false tixVerifyBoolean}
  28. }
  29. -default {
  30. }
  31. }
  32. proc tixVTree:InitWidgetRec {w} {
  33. upvar #0 $w data
  34. tixChainMethod $w InitWidgetRec
  35. }
  36. proc tixVTree:ConstructWidget {w} {
  37. upvar #0 $w data
  38. tixChainMethod $w ConstructWidget
  39. set data(indStyle) \
  40. [tixDisplayStyle image -refwindow $data(w:hlist) -padx 0 -pady 0]
  41. }
  42. proc tixVTree:SetBindings {w} {
  43. upvar #0 $w data
  44. tixChainMethod $w SetBindings
  45. $data(w:hlist) config \
  46. -indicatorcmd [list tixVTree:IndicatorCmd $w] \
  47. -browsecmd [list tixVTree:BrowseCmdHook $w] \
  48. -command [list tixVTree:CommandHook $w]
  49. }
  50. proc tixVTree:IndicatorCmd {w args} {
  51. upvar #0 $w data
  52. set event [tixEvent type]
  53. set ent [tixEvent flag V]
  54. set type [tixVTree:GetType $w $ent]
  55. set plus [tix getimage plus]
  56. set plusarm [tix getimage plusarm]
  57. set minus [tix getimage minus]
  58. set minusarm [tix getimage minusarm]
  59. if {![$data(w:hlist) info exists $ent]} {return}
  60. switch -exact -- $event {
  61. <Arm> {
  62. if {![$data(w:hlist) indicator exists $ent]} {return}
  63. $data(w:hlist) indicator config $ent \
  64. -image [expr {$type eq "open" ? $plusarm : $minusarm}]
  65. }
  66. <Disarm> {
  67. if {![$data(w:hlist) indicator exists $ent]} {return}
  68. $data(w:hlist) indicator config $ent \
  69. -image [expr {$type eq "open" ? $plus : $minus}]
  70. }
  71. <Activate> {
  72. upvar bind bind
  73. tixCallMethod $w Activate $ent $type
  74. set bind(%V) $ent
  75. tixVTree:BrowseCmdHook $w
  76. }
  77. }
  78. }
  79. proc tixVTree:GetType {w ent} {
  80. upvar #0 $w data
  81. if {![$data(w:hlist) indicator exists $ent]} {
  82. return none
  83. }
  84. set img [$data(w:hlist) indicator cget $ent -image]
  85. if {$img eq [tix getimage plus] || $img eq [tix getimage plusarm]} {
  86. return open
  87. }
  88. return close
  89. }
  90. proc tixVTree:Activate {w ent type} {
  91. upvar #0 $w data
  92. if {$type eq "open"} {
  93. tixCallMethod $w OpenCmd $ent
  94. $data(w:hlist) indicator config $ent -image [tix getimage minus]
  95. } else {
  96. tixCallMethod $w CloseCmd $ent
  97. $data(w:hlist) indicator config $ent -image [tix getimage plus]
  98. }
  99. }
  100. proc tixVTree:CommandHook {w args} {
  101. upvar #0 $w data
  102. upvar bind bind
  103. tixCallMethod $w Command bind
  104. }
  105. proc tixVTree:BrowseCmdHook {w args} {
  106. upvar #0 $w data
  107. upvar bind bind
  108. tixCallMethod $w BrowseCmd bind
  109. }
  110. proc tixVTree:SetMode {w ent mode} {
  111. upvar #0 $w data
  112. switch -exact -- $mode {
  113. open {
  114. $data(w:hlist) indicator create $ent -itemtype image \
  115. -image [tix getimage plus] -style $data(indStyle)
  116. }
  117. close {
  118. $data(w:hlist) indicator create $ent -itemtype image \
  119. -image [tix getimage minus] -style $data(indStyle)
  120. }
  121. none {
  122. if {[$data(w:hlist) indicator exist $ent]} {
  123. $data(w:hlist) indicator delete $ent
  124. }
  125. }
  126. }
  127. }
  128. #----------------------------------------------------------------------
  129. #
  130. # Virtual Methods
  131. #
  132. #----------------------------------------------------------------------
  133. proc tixVTree:OpenCmd {w ent} {
  134. upvar #0 $w data
  135. # The default action
  136. foreach kid [$data(w:hlist) info children $ent] {
  137. $data(w:hlist) show entry $kid
  138. }
  139. }
  140. proc tixVTree:CloseCmd {w ent} {
  141. upvar #0 $w data
  142. # The default action
  143. foreach kid [$data(w:hlist) info children $ent] {
  144. $data(w:hlist) hide entry $kid
  145. }
  146. }
  147. proc tixVTree:Command {w B} {
  148. upvar #0 $w data
  149. upvar $B bind
  150. if {$data(-ignoreinvoke)} {
  151. return
  152. }
  153. set ent [tixEvent flag V]
  154. if {[$data(w:hlist) indicator exist $ent]} {
  155. tixVTree:Activate $w $ent [tixVTree:GetType $w $ent]
  156. }
  157. }
  158. proc tixVTree:BrowseCmd {w B} {
  159. }
  160. #----------------------------------------------------------------------
  161. #
  162. # Widget commands
  163. #
  164. #----------------------------------------------------------------------