3 # This is the primitive widget. It is just a frame with proper
4 # inheritance wrapping. All new Tix widgets will be derived from
7 # Copyright (c) 1996, Expert Interface Technologies
9 # See the file "license.terms" for information on usage and redistribution
10 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
15 # No superclass, so the superclass switch is not used
18 tixWidgetClass tixPrimitive {
21 -classname TixPrimitive
23 cget configure subwidget subwidgets
26 -background -borderwidth -cursor
27 -height -highlightbackground -highlightcolor -highlightthickness
28 -options -relief -takefocus -width -bd -bg
34 {-background background Background #d9d9d9}
35 {-borderwidth borderWidth BorderWidth 0}
36 {-cursor cursor Cursor ""}
37 {-height height Height 0}
38 {-highlightbackground highlightBackground HighlightBackground #c3c3c3}
39 {-highlightcolor highlightColor HighlightColor black}
40 {-highlightthickness highlightThickness HighlightThickness 0}
41 {-options options Options ""}
42 {-relief relief Relief flat}
43 {-takefocus takeFocus TakeFocus 0 tixVerifyBoolean}
44 {-width width Width 0}
52 #----------------------------------------------------------------------
53 # ClassInitialization:
54 #----------------------------------------------------------------------
60 proc tixPrimitive:Constructor {w args} {
63 upvar #0 $data(className) classRec
65 # Set up some minimal items in the class record.
68 set data(rootCmd) $w:root
70 # We need to create the root widget in order to parse the options
72 tixCallMethod $w CreateRootWidget
74 # Parse the default options from the options database
76 tixPrimitive:ParseDefaultOptions $w
78 # Parse the options supplied by the user
80 tixPrimitive:ParseUserOptions $w $args
82 # Rename the widget command so that it can be use to access
83 # the methods of this class
85 tixPrimitive:MkWidgetCmd $w
87 # Inistalize the Widget Record
89 tixCallMethod $w InitWidgetRec
91 # Construct the compound widget
93 tixCallMethod $w ConstructWidget
97 tixCallMethod $w SetBindings
99 # Call the configuration methods for all "force call" options
101 foreach option $classRec(forceCall) {
102 tixInt_ChangeOptions $w $option $data($option)
107 # Create only the root widget. We need the root widget to query the option
110 # Override: seldom. (unless you want to use a toplevel as root widget)
113 proc tixPrimitive:CreateRootWidget {w args} {
115 upvar #0 $data(className) classRec
117 frame $w -class $data(ClassName)
120 proc tixPrimitive:ParseDefaultOptions {w} {
122 upvar #0 $data(className) classRec
124 # SET UP THE INSTANCE RECORD ACCORDING TO DEFAULT VALUES IN
125 # THE OPTIONS DATABASE
127 foreach option $classRec(options) {
128 set spec [tixInt_GetOptionSpec $data(className) $option]
130 if {[lindex $spec 0] == "="} {
134 set o_name [lindex $spec 1]
135 set o_class [lindex $spec 2]
136 set o_default [lindex $spec 3]
138 if {![catch "option get $w $o_name $o_class" db_default]} {
139 if {$db_default != ""} {
140 set data($option) $db_default
142 set data($option) $o_default
145 set data($option) $o_default
150 proc tixPrimitive:ParseUserOptions {w arglist} {
152 upvar #0 $data(className) classRec
154 # SET UP THE INSTANCE RECORD ACCORDING TO COMMAND ARGUMENTS FROM
155 # THE USER OF THE TIX LIBRARY (i.e. Application programmer:)
157 tixForEach {option arg} $arglist {
158 if {[lsearch $classRec(options) $option] != "-1"} {
159 set spec [tixInt_GetOptionSpec $data(className) $option]
161 if {[lindex $spec 0] != "="} {
162 set data($option) $arg
164 set realOption [lindex $spec 1]
165 set data($realOption) $arg
168 error "unknown option $option. Should be: [tixInt_ListOptions $w]"
173 #----------------------------------------------------------------------
174 # Initialize the widget record
178 # Chain : always, before
179 proc tixPrimitive:InitWidgetRec {w} {
180 # default: do nothing
183 #----------------------------------------------------------------------
187 # Override: sometimes
188 # Chain : sometimes, before
190 bind TixDestroyHandler <Destroy> {
191 [tixGetMethod %W [set %W(className)] Destructor] %W
194 proc tixPrimitive:SetBindings {w} {
197 if {[winfo toplevel $w] == $w} {
198 bindtags $w [concat TixDestroyHandler [bindtags $w]]
200 bind $data(w:root) <Destroy> \
201 "[tixGetMethod $w $data(className) Destructor] $w"
205 #----------------------------------------------------------------------
206 # PrivateMethod: ConstructWidget
208 # Construct and set up the compound widget
210 # Override: sometimes
211 # Chain : sometimes, before
213 proc tixPrimitive:ConstructWidget {w} {
216 $data(rootCmd) config \
217 -background $data(-background) \
218 -borderwidth $data(-borderwidth) \
219 -cursor $data(-cursor) \
220 -relief $data(-relief)
222 if {$data(-width) != 0} {
223 $data(rootCmd) config -width $data(-width)
225 if {$data(-height) != 0} {
226 $data(rootCmd) config -height $data(-height)
229 set rootname *[string range $w 1 end]
231 tixForEach {spec value} $data(-options) {
232 option add $rootname*$spec $value 100
236 #----------------------------------------------------------------------
237 # PrivateMethod: MkWidgetCmd
239 # Construct and set up the compound widget
241 # Override: sometimes
242 # Chain : sometimes, before
244 proc tixPrimitive:MkWidgetCmd {w} {
247 rename $w $data(rootCmd)
248 tixInt_MkInstanceCmd $w
252 #----------------------------------------------------------------------
254 #----------------------------------------------------------------------
256 #----------------------------------------------------------------------
257 # ConfigMethod: config
259 # Configure one option.
264 # Note the hack of [winfo width] in this procedure
266 # The hack is necessary because of the bad interaction between TK's geometry
267 # manager (the packer) and the frame widget. The packer determines the size
268 # of the root widget of the ComboBox (a frame widget) according to the
269 # requirement of the slaves inside the frame widget, NOT the -width
270 # option of the frame widget.
272 # However, everytime the frame widget is
273 # configured, it sends a geometry request to the packer according to its
274 # -width and -height options and the packer will temporarily resize
275 # the frame widget according to the requested size! The packer then realizes
276 # something is wrong and revert to the size determined by the slaves. This
277 # cause a flash on the screen.
279 foreach opt {-height -width -background -borderwidth -cursor
280 -highlightbackground -highlightcolor -relief -takefocus -bd -bg} {
282 set tixPrimOpt($opt) 1
285 proc tixPrimitive:config {w option value} {
289 if [info exists tixPrimOpt($option)] {
290 $data(rootCmd) config $option $value
294 #----------------------------------------------------------------------
296 #----------------------------------------------------------------------
298 #----------------------------------------------------------------------
299 # This method is used to implement the "subwidgets" widget command.
300 # Will be re-written in C. It can't be used as a public method because
301 # of the lame substring comparison routines used in tixClass.c
304 proc tixPrimitive:subwidgets {w type args} {
309 set name [lindex $args 0]
310 set args [lrange $args 1 end]
311 # access subwidgets of a particular class
313 # note: if $name=="Frame", will *not return the root widget as well
316 foreach des [tixDescendants $w] {
317 if {[winfo class $des] == $name} {
322 # Note: if the there is no subwidget of this class, does not
335 set name [lindex $args 0]
336 set args [lrange $args 1 end]
337 # access subwidgets of a particular group
339 if [info exists data(g:$name)] {
342 foreach item $data(g:$name) {
347 foreach item $data(g:$name) {
353 error "no such subwidget group $name"
357 set sub [tixDescendants $w]
369 error "unknown flag $type, should be -all, -class or -group"
374 #----------------------------------------------------------------------
375 # PublicMethod: subwidget
377 # Access a subwidget withe a particular name
382 proc tixPrimitive:subwidget {w name args} {
385 if [info exists data(w:$name)] {
387 return $data(w:$name)
389 return [eval $data(w:$name) $args]
392 error "no such subwidget $name"
397 #----------------------------------------------------------------------
399 #----------------------------------------------------------------------
401 # delete the widget record and remove the command
403 proc tixPrimitive:Destructor {w} {
406 if {![info exists data(w:root)]} {
410 if {[info commands $w] != ""} {
416 if {[info commands $data(rootCmd)] != ""} {
417 # remove the command of the root widget
419 rename $data(rootCmd) ""
422 # delete the widget record