MkChoose.tcl 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: MkChoose.tcl,v 1.4 2004/03/28 02:44:56 hobbs Exp $
  4. #
  5. # MkChoose.tcl --
  6. #
  7. # This file implements the "Choosers" page in the widget demo
  8. #
  9. # This file has not been properly documented. It is NOT intended
  10. # to be used as an introductory demo program about Tix
  11. # programming. For such demos, please see the files in the
  12. # demos/samples directory or go to the "Samples" page in the
  13. # "widget demo"
  14. #
  15. #
  16. # Copyright (c) 1996, Expert Interface Technologies
  17. #
  18. # See the file "license.terms" for information on usage and redistribution
  19. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  20. #
  21. proc MkChoosers {nb page} {
  22. set w [$nb subwidget $page]
  23. set name [tixOptionName $w]
  24. option add *$name*TixLabelFrame*label.padX 4
  25. tixLabelFrame $w.til -label "Chooser Widgets"
  26. tixLabelFrame $w.cbx -label "tixComboBox"
  27. tixLabelFrame $w.ctl -label "tixControl"
  28. tixLabelFrame $w.sel -label "tixSelect"
  29. tixLabelFrame $w.opt -label "tixOptionMenu"
  30. tixLabelFrame $w.fil -label "tixFileEntry"
  31. tixLabelFrame $w.fbx -label "tixFileSelectBox"
  32. tixLabelFrame $w.tbr -label "Tool Bar"
  33. MkTitle [$w.til subwidget frame]
  34. MkCombo [$w.cbx subwidget frame]
  35. MkControl [$w.ctl subwidget frame]
  36. MkSelect [$w.sel subwidget frame]
  37. MkOptMenu [$w.opt subwidget frame]
  38. MkFileBox [$w.fbx subwidget frame]
  39. MkFileEnt [$w.fil subwidget frame]
  40. MkToolBar [$w.tbr subwidget frame]
  41. #
  42. # First column: comBox and selector
  43. tixForm $w.cbx -top 0 -left 0 -right %33
  44. tixForm $w.sel -left 0 -right &$w.cbx -top $w.cbx
  45. tixForm $w.opt -left 0 -right &$w.cbx -top $w.sel -bottom -1
  46. #
  47. # Second column: title .. etc
  48. tixForm $w.til -left $w.cbx -right %66 -top 0
  49. tixForm $w.ctl -left $w.cbx -right &$w.til -top $w.til
  50. tixForm $w.fil -left $w.cbx -right &$w.til -top $w.ctl
  51. tixForm $w.tbr -left $w.cbx -right &$w.til -top $w.fil -bottom -1
  52. #
  53. # Third column: file selection
  54. tixForm $w.fbx -left %66 -right -1 -top 0
  55. }
  56. #----------------------------------------------------------------------
  57. # ComboBox
  58. #----------------------------------------------------------------------
  59. proc MkCombo {w} {
  60. set name [tixOptionName $w]
  61. option add *$name*TixComboBox*label.width 10
  62. option add *$name*TixComboBox*label.anchor e
  63. option add *$name*TixComboBox*entry.width 14
  64. tixComboBox $w.static -label "Static" \
  65. -editable false
  66. tixComboBox $w.editable -label "Editable" \
  67. -editable true
  68. tixComboBox $w.history -label "History" \
  69. -editable true -history true -anchor e
  70. $w.static insert end January
  71. $w.static insert end February
  72. $w.static insert end March
  73. $w.static insert end April
  74. $w.static insert end May
  75. $w.static insert end June
  76. $w.static insert end July
  77. $w.static insert end August
  78. $w.static insert end September
  79. $w.static insert end October
  80. $w.static insert end November
  81. $w.static insert end December
  82. $w.editable insert end "America"
  83. $w.editable insert end "Britain"
  84. $w.editable insert end "China"
  85. $w.editable insert end "Denmark"
  86. $w.editable insert end "Egypt"
  87. $w.history insert end "/usr/bin/mail"
  88. $w.history insert end "/etc/profile"
  89. $w.history insert end "/home/d/doe/Mail/letter"
  90. pack $w.static $w.editable $w.history -side top -padx 5 -pady 3
  91. }
  92. #----------------------------------------------------------------------
  93. # The Control widgets
  94. #----------------------------------------------------------------------
  95. set states {Alabama "New York" Pennsylvania Washington}
  96. proc stCmd {w by value} {
  97. global states
  98. set index [lsearch $states $value]
  99. set len [llength $states]
  100. set index [expr {$index + $by}]
  101. if {$index < 0} {
  102. set index [expr {$len -1}]
  103. }
  104. if {$index >= $len} {
  105. set index 0
  106. }
  107. return [lindex $states $index]
  108. }
  109. proc stValidate {w value} {
  110. global states
  111. if {[lsearch $states $value] == -1} {
  112. return [lindex $states 0]
  113. } else {
  114. return $value
  115. }
  116. }
  117. proc MkControl {w} {
  118. set name [tixOptionName $w]
  119. option add *$name*TixControl*label.width 10
  120. option add *$name*TixControl*label.anchor e
  121. option add *$name*TixControl*entry.width 13
  122. tixControl $w.simple -label Numbers
  123. tixControl $w.spintext -label States \
  124. -incrcmd [list stCmd $w.spintext 1] \
  125. -decrcmd [list stCmd $w.spintext -1] \
  126. -validatecmd [list stValidate .d] \
  127. -value "Alabama"
  128. pack $w.simple $w.spintext -side top -padx 5 -pady 3
  129. }
  130. #----------------------------------------------------------------------
  131. # The Select Widgets
  132. #----------------------------------------------------------------------
  133. proc MkSelect {w} {
  134. set name [tixOptionName $w]
  135. option add *$name*TixSelect*label.anchor c
  136. option add *$name*TixSelect*orientation vertical
  137. option add *$name*TixSelect*labelSide top
  138. tixSelect $w.sel1 -label "Mere Mortals" -allowzero true -radio true
  139. tixSelect $w.sel2 -label "Geeks" -allowzero true -radio false
  140. $w.sel1 add eat -text Eat
  141. $w.sel1 add work -text Work
  142. $w.sel1 add play -text Play
  143. $w.sel1 add party -text Party
  144. $w.sel1 add sleep -text Sleep
  145. $w.sel2 add eat -text Eat
  146. $w.sel2 add prog1 -text Program
  147. $w.sel2 add prog2 -text Program
  148. $w.sel2 add prog3 -text Program
  149. $w.sel2 add sleep -text Sleep
  150. pack $w.sel1 $w.sel2 -side left -padx 5 -pady 3 -fill x
  151. }
  152. #----------------------------------------------------------------------
  153. # The OptMenu Widget
  154. #----------------------------------------------------------------------
  155. proc MkOptMenu {w} {
  156. set name [tixOptionName $w]
  157. option add *$name*TixOptionMenu*label.anchor e
  158. tixOptionMenu $w.menu -label "File Format : " \
  159. -options {
  160. menubutton.width 15
  161. }
  162. $w.menu add command text -label "Plain Text"
  163. $w.menu add command post -label "PostScript"
  164. $w.menu add command format -label "Formatted Text"
  165. $w.menu add command html -label "HTML"
  166. $w.menu add separator sep
  167. $w.menu add command tex -label "LaTeX"
  168. $w.menu add command rtf -label "Rich Text Format"
  169. pack $w.menu -padx 5 -pady 3 -fill x
  170. }
  171. #----------------------------------------------------------------------
  172. # FileEntry
  173. #----------------------------------------------------------------------
  174. proc MkFileEnt {w} {
  175. set name [tixOptionName $w]
  176. message $w.msg \
  177. -relief flat -width 240 -anchor n\
  178. -text {Press the "open file" icon button and a\
  179. TixFileSelectDialog will popup.}
  180. tixFileEntry $w.ent -label "Select a file : "
  181. pack $w.msg -side top -expand yes -fill both -padx 3 -pady 3
  182. pack $w.ent -side top -fill x -padx 3 -pady 3
  183. }
  184. proc MkFileBox {w} {
  185. set name [tixOptionName $w]
  186. message $w.msg \
  187. -relief flat -width 240 -anchor n\
  188. -text {The TixFileSelectBox is Motif-style file selection\
  189. box with various enhancements. For example, you can adjust the\
  190. size of the two listboxes and your past selections are recorded.}
  191. tixFileSelectBox $w.box
  192. pack $w.msg -side top -expand yes -fill both -padx 3 -pady 3
  193. pack $w.box -side top -fill x -padx 3 -pady 3
  194. }
  195. #----------------------------------------------------------------------
  196. # Tool Bar
  197. #----------------------------------------------------------------------
  198. proc MkToolBar {w} {
  199. set name [tixOptionName $w]
  200. option add $name*TixSelect*frame.borderWidth 1
  201. message $w.msg -relief flat -width 240 -anchor n\
  202. -text {The Select widget is also good for arranging buttons\
  203. in a tool bar.}
  204. frame $w.bar -bd 2 -relief raised
  205. tixSelect $w.font -allowzero true -radio false -label {}
  206. tixSelect $w.para -allowzero false -radio true -label {}
  207. $w.font add bold -bitmap [tix getbitmap bold]
  208. $w.font add italic -bitmap [tix getbitmap italic]
  209. $w.font add underline -bitmap [tix getbitmap underlin]
  210. $w.font add capital -bitmap [tix getbitmap capital]
  211. $w.para add left -bitmap [tix getbitmap leftj]
  212. $w.para add right -bitmap [tix getbitmap rightj]
  213. $w.para add center -bitmap [tix getbitmap centerj]
  214. $w.para add justify -bitmap [tix getbitmap justify]
  215. pack $w.msg -side top -expand yes -fill both -padx 3 -pady 3
  216. pack $w.bar -side top -fill x -padx 3 -pady 3
  217. pack $w.para $w.font -in $w.bar -side left -padx 4 -pady 3
  218. }
  219. #----------------------------------------------------------------------
  220. # Title
  221. #----------------------------------------------------------------------
  222. proc MkTitle {w} {
  223. set name [tixOptionName $w]
  224. option add $name*TixSelect*frame.borderWidth 1
  225. message $w.msg \
  226. -relief flat -width 240 -anchor n\
  227. -text {There are many types of "choose" widgets that allow\
  228. the user to input different type of information.}
  229. pack $w.msg -side top -expand yes -fill both -padx 3 -pady 3
  230. }