LabWidg.tcl 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. # -*- mode: TCL; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: LabWidg.tcl,v 1.3 2001/12/09 05:04:02 idiscovery Exp $
  4. #
  5. # LabWidg.tcl --
  6. #
  7. # TixLabelWidget: Virtual base class. Do not instantiate
  8. #
  9. # This widget class is the base class for all widgets that has a
  10. # label. Most Tix compound widgets will have a label so that
  11. # the app programmer doesn't need to add labels themselvel.
  12. #
  13. #
  14. # Copyright (c) 1993-1999 Ioi Kim Lam.
  15. # Copyright (c) 2000-2001 Tix Project Group.
  16. #
  17. # See the file "license.terms" for information on usage and redistribution
  18. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  19. #
  20. # LabelSide : top, left, right, bottom, none, acrosstop
  21. #
  22. # public widgets:
  23. # frame, label
  24. #
  25. tixWidgetClass tixLabelWidget {
  26. -superclass tixPrimitive
  27. -classname TixLabelWidget
  28. -flag {
  29. -label -labelside -padx -pady
  30. }
  31. -static {-labelside}
  32. -configspec {
  33. {-label label Label ""}
  34. {-labelside labelSide LabelSide left}
  35. {-padx padX Pad 0}
  36. {-pady padY Pad 0}
  37. }
  38. }
  39. proc tixLabelWidget:ConstructWidget {w} {
  40. upvar #0 $w data
  41. tixChainMethod $w ConstructWidget
  42. if {$data(-labelside) != "acrosstop"} {
  43. set data(w:frame) [frame $w.frame]
  44. } else {
  45. set data(pw:border) [frame $w.border]
  46. set data(pw:pad) [frame $w.border.pad]
  47. set data(w:frame) [frame $w.border.frame]
  48. }
  49. if {$data(-labelside) != "none"} {
  50. set data(w:label) [label $w.label -text $data(-label)]
  51. }
  52. tixLabelWidget:Pack $w
  53. tixCallMethod $w ConstructFramedWidget $data(w:frame)
  54. }
  55. proc tixLabelWidget:ConstructFramedWidget {w frame} {
  56. # Do nothing
  57. }
  58. proc tixLabelWidget:Pack {w} {
  59. upvar #0 $w data
  60. if {[catch {tixLabelWidget:Pack-$data(-labelside) $w}]} {
  61. error "unknown -labelside option \"$data(-labelside)\""
  62. }
  63. }
  64. proc tixLabelWidget:Pack-acrosstop {w} {
  65. upvar #0 $w data
  66. set labHalfHeight [expr [winfo reqheight $data(w:label)] / 2]
  67. set padHeight [expr $labHalfHeight - [$data(pw:border) cget -bd]]
  68. if {$padHeight < 0} {
  69. set padHeight 0
  70. }
  71. tixForm $data(w:label) -top 0 -left 4\
  72. -padx [expr $data(-padx) +4] -pady $data(-pady)
  73. tixForm $data(pw:border) -top $labHalfHeight -bottom -1 \
  74. -left 0 -right -1 -padx $data(-padx) -pady $data(-pady)
  75. tixForm $data(pw:pad) -left 0 -right -1 \
  76. -top 0 -bottom $padHeight
  77. tixForm $data(w:frame) -top $data(pw:pad) -bottom -1 \
  78. -left 0 -right -1
  79. }
  80. proc tixLabelWidget:Pack-top {w} {
  81. upvar #0 $w data
  82. pack $data(w:label) -side top \
  83. -padx $data(-padx) -pady $data(-pady) \
  84. -fill x
  85. pack $data(w:frame) -side top \
  86. -padx $data(-padx) -pady $data(-pady) \
  87. -expand yes -fill both
  88. }
  89. proc tixLabelWidget:Pack-bottom {w} {
  90. upvar #0 $w data
  91. pack $data(w:label) -side bottom \
  92. -padx $data(-padx) -pady $data(-pady) \
  93. -fill x
  94. pack $data(w:frame) -side bottom \
  95. -padx $data(-padx) -pady $data(-pady) \
  96. -expand yes -fill both
  97. }
  98. proc tixLabelWidget:Pack-left {w} {
  99. upvar #0 $w data
  100. pack $data(w:label) -side left \
  101. -padx $data(-padx) -pady $data(-pady) \
  102. -fill y
  103. pack $data(w:frame) -side left \
  104. -padx $data(-padx) -pady $data(-pady) \
  105. -expand yes -fill both
  106. }
  107. proc tixLabelWidget:Pack-right {w} {
  108. upvar #0 $w data
  109. pack $data(w:label) -side right \
  110. -padx $data(-padx) -pady $data(-pady) \
  111. -fill x
  112. pack $data(w:frame) -side right \
  113. -padx $data(-padx) -pady $data(-pady) \
  114. -expand yes -fill both
  115. }
  116. proc tixLabelWidget:Pack-none {w} {
  117. upvar #0 $w data
  118. pack $data(w:frame)\
  119. -padx $data(-padx) -pady $data(-pady) \
  120. -expand yes -fill both
  121. }
  122. #----------------------------------------------------------------------
  123. # CONFIG OPTIONS
  124. #----------------------------------------------------------------------
  125. proc tixLabelWidget:config-label {w value} {
  126. upvar #0 $w data
  127. $data(w:label) config -text $value
  128. if {$data(-labelside) == "acrosstop"} {
  129. tixLabelWidget:Pack-acrosstop $w
  130. }
  131. }