For example, a hierarchical listbox widget (HList) can display items of images, plain text and subwindows in the form of a hierarchy. Another widget, the tabular listbox, (TList, currently planned and will be released in Tix 4.1) also display items of the same types, although it arranges the items in a tabular form. Yet another widget, the spreadsheet widget, also displays similar types items, but in yet another format.
In these examples, the display items in different widgets are only different in how they are arranged by the host widget. In Tix, display items are clearly separated from the host widgets. The advantage is two-fold: first, the creation and configuration of display items become uniform across different host widgets. Second, new display item types can be added without the need to modify the existing host widgets.
In a way, Tix display items are similar to the items inside Tk the canvas widget. However, unlike the Tix display items, the canvas items are not independent of the canvas widget; this makes it impossible to use the canvas items inside other types of TK widgets.
The appearance of a display item is controlled by a set of attributes. It is observed that each the attributes usually fall into one of two categroies: "individual" or "collective". For example, the text items inside a HList widget may all display a different text string; however, in most cases, the text items share the same color, font and spacing. Instead of keeping a duplicated version of the same attributes inside each display item, it will be advantageous to put the collective attributes in a special object called a display style. First, there is the space concern: a host widget may have many thousands of items; keeping dupilcated attributes will be very wasteful. Second, when it becomes necessary to change a collective attribute, such as changing all the change only the display style object than to modify all the text items one by one.
The attributes of the a display item are thus stored in two places: it has a set of item options to store its individual attributes. Each display item is also associated with a display style, which specifies the collective attributes of all items associated with itself.
The division between the individual and collective attributes are fixed and cannot be changed. Thus, when it becomes necessary for some items to differ in their collective attributes, two or more display styles can be used. For example, suppose you want to display two columns of text items inside an HList widget, one column in red and the other in blue. You can create a TextStyle object called "red", which defines a red foreground, and another called "blue", which defines a blue foreground. You can then associate all text items of the first column to "red" and the second column to "blue".
ITEM OPTIONS
Name: bitmap
Class: Bitmap
Switch: -bitmap
Name: image
Class: Image
Switch: -image
Name: imageTextStyle
Class: ImageTextStyle
Switch: -style
Name: showImage
Class: ShowImage
Switch: -showimage
Name: showText
Class: ShowText
Switch: -showtext
Name: text
Class: Text
Switch: -text
Name: underline
Class: Underline
Switch: -underline
STYLE OPTIONS
The style information of imagetext items are stored in the imagetext display style. The following options are supported:
STANDARD OPTIONS
\fC
activeBackground activeForeground
anchor background
disabledBackground disabledForeground
foreground font
justify padX
padY selectBackground
selectForeground wrapLength
See the options(n) manual entry for details on the standard options.
STYLE-SPECIFIC OPTIONS
Name: gap
Class: Gap
Switch: -gap
ITEM OPTIONS
Name: textStyle
Class: TextStyle
Switch: -style
Name: text
Class: Text
Switch: -text
Name: underline
Class: Underline
Switch: -underline
STANDARD OPTIONS
\fC
activeBackground activeForeground
anchor background
disabledBackground disabledForeground
foreground font
justify padX
padY selectBackground
selectForeground wrapLength
See the options(n) manual entry for details on the standard options.
ITEM OPTIONS
Name: windowStyle
Class: WindowStyle
Switch: -style
Name: window
Class: Window
Switch: -window
Alias: -widget
\fC
anchor
padX padY
See the options(n) manual entry for details on the standard
options.
\fC
tixHList .h -columns 3
.h add foo
.h item create foo 2 -itemtype imagetext -text Hello -image image1
The item create command of the HList widget accepts a variable number of arguments. The special argument -itemtype specifies which type of display item to create. Options that are valid for this type of display items can then be specified by one or more option-value pairs.
After the display item is created, they can then be configured or destroyed using the commands provided by the host widget. For example, the HList widget has the command item configure, item cget and item delete for accessing the display items.
itemType must be one of the existing display items types such as text, imagetext, window or any new types added by the user. Additional arguments can be given in one or more option-value pairs. option can be any of the valid option for this display style or any of the following:
option add *table.list*disabledForeground blue
option add *table.list*disabledBackground darkgray
tixDisplayStyle text -refwindow .table.list -fg red
By using the option database to set the options of the display styles,
we can advoid hard-coding the option values and give the user more
flexibility in customization. See option(n) for a detailed description
of the option database.
The tixDisplayStyle command creates a new Tcl command whose name is the same as the name of the newly created display style. This command may be used to invoke various operations on the display style. It has the following general form:
styleName option ?arg arg ...?styleName is the name of the command. Option and the args determine the exact behavior of the command. The following commands are possible:
\fC
set courier -*-courier-medium-r-*-*-14-*-*-*-*-*-*-*
tixHList .h -columns 2; pack .h
set red [tixDisplayStyle text -fg #800000]
set blue [tixDisplayStyle text -fg #000080 -anchor e -font $courier]
foreach n {{Joe $10,000} {Peter $20,000} {Raj $90,000} {Zinh $0}} {
set entry [.h addchild {}]
.h item create $entry 0 -itemtype text \\
-text [lindex $n 0] -style $red
.h item create $entry 1 -itemtype text \\
-text [lindex $n 1] -style $blue
}