MultView.tcl 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: MultView.tcl,v 1.3 2001/12/09 05:04:02 idiscovery Exp $
  4. #
  5. # MultView.tcl --
  6. #
  7. # Implements the multi-view 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 tixMultiView {
  16. -classname TixMultiView
  17. -superclass tixPrimitive
  18. -method {
  19. add
  20. }
  21. -flag {
  22. -browsecmd -command -view
  23. }
  24. -forcecall {
  25. -view
  26. }
  27. -configspec {
  28. {-browsecmd browseCmd BrowseCmd ""}
  29. {-command command Command ""}
  30. {-view view View icon tixMultiView:VerifyView}
  31. }
  32. -alias {
  33. }
  34. -default {
  35. }
  36. }
  37. proc tixMultiView:InitWidgetRec {w} {
  38. upvar #0 $w data
  39. global env
  40. tixChainMethod $w InitWidgetRec
  41. }
  42. #----------------------------------------------------------------------
  43. # Construct widget
  44. #----------------------------------------------------------------------
  45. proc tixMultiView:ConstructWidget {w} {
  46. upvar #0 $w data
  47. tixChainMethod $w ConstructWidget
  48. set data(w:stlist) [tixScrolledTList $w.stlist]
  49. set data(w:sgrid) [tixScrolledGrid $w.sgrid]
  50. set data(w:icon) [tixIconView $w.icon]
  51. set data(w:tlist) [$data(w:stlist) subwidget tlist]
  52. set data(w:grid) [$data(w:sgrid) subwidget grid]
  53. $data(w:grid) config -formatcmd [list tixMultiView:GridFormat $w] \
  54. -leftmargin 0 -topmargin 1
  55. }
  56. proc tixMultiView:SetBindings {w} {
  57. upvar #0 $w data
  58. tixChainMethod $w SetBindings
  59. }
  60. proc tixMultiView:GetWid {w which} {
  61. upvar #0 $w data
  62. case $which {
  63. list {
  64. return $data(w:stlist)
  65. }
  66. icon {
  67. return $data(w:icon)
  68. }
  69. detail {
  70. return $data(w:sgrid)
  71. }
  72. }
  73. }
  74. #----------------------------------------------------------------------
  75. # Configuration
  76. #----------------------------------------------------------------------
  77. proc tixMultiView:config-view {w value} {
  78. upvar #0 $w data
  79. if {$data(-view) != ""} {
  80. pack forget [tixMultiView:GetWid $w $data(-view)]
  81. }
  82. pack [tixMultiView:GetWid $w $value] -expand yes -fill both
  83. }
  84. #----------------------------------------------------------------------
  85. # Private methods
  86. #----------------------------------------------------------------------
  87. proc tixMultiView:GridFormat {w area x1 y1 x2 y2} {
  88. upvar #0 $w data
  89. case $area {
  90. main {
  91. }
  92. {x-margin y-margin s-margin} {
  93. # cborder specifies consecutive 3d borders
  94. #
  95. $data(w:grid) format cborder $x1 $y1 $x2 $y2 \
  96. -fill 1 -relief raised -bd 2 -bg gray60 \
  97. -selectbackground gray80
  98. }
  99. }
  100. }
  101. #----------------------------------------------------------------------
  102. # Public methods
  103. #----------------------------------------------------------------------
  104. # Return value is the index of "$name" in the grid subwidget
  105. #
  106. #
  107. proc tixMultiView:add {w name args} {
  108. upvar #0 $w data
  109. set validOptions {-image -text}
  110. set opt(-image) ""
  111. set opt(-text) ""
  112. tixHandleOptions -nounknown opt $validOptions $args
  113. $data(w:icon) add $name $opt(-image) $opt(-text)
  114. $data(w:tlist) insert end -itemtype imagetext \
  115. -image $opt(-image) -text $opt(-text)
  116. $data(w:grid) set 0 end -itemtype imagetext \
  117. -image $opt(-image) -text $opt(-text)
  118. return max
  119. }
  120. #----------------------------------------------------------------------
  121. # checker
  122. #----------------------------------------------------------------------
  123. proc tixMultiView:VerifyView {value} {
  124. case $value {
  125. {icon list detail} {
  126. return $value
  127. }
  128. }
  129. error "bad view \"$value\", must be detail, icon or list"
  130. }