Next: Controlling the Layout Up: TixHList - The Previous: Creating a Hierarchical


Creating Entries in a HList Widget 

Each entry in an HList widget has a unique name, called its entry-path, which determines each entry's position in the HList widget. The entry-paths of the HList entries are very similar to the pathnames of Unix files. Each entry-path is a list of string names separated by a separator character. By default, the separator character is the period character (.), but it can be configured using the -separator option of the HList widget.

In program 4-3, we add several new entries foo,, foo.bor,, .. etc, into the HList widget using the add method. The relationship between the entries is signified by their names, in a way similar to how Unix denotes directories and subdirectories. For example, foo is the parent of and foo.bor; is the parent of, and so on. As far as the terminology goes, we also say that a child of foo; foo is an ancestor of and is a descendant of foo.

The output of program 4-2 is shown in figure 4-3. As we can see, the entries are displayed under their parents with the amount of indentation control by the -indent option of the HList widget: and are display under, which is in turn displayed under foo.

Entries with no parents, for example, foo and dor in program 4-2, are called top-level entries. Top-level entries are usually entries with no immediate superiors in a hierarchical. For example, the owner of a company, the principle of a school or the root directory of a Unix file system. Toplevel entries are displayed with no indentation.

As evident from program 4-2, all entries who entry-path does not contain a separator character are top-level entries. The only exception is the separator character itself is also a toplevel entry. This makes it easy to display Unix file and directory names inside the HList widget, as shown in program 4-4.

set folder [tix getimage folder]
tixScrolledHList .sh -options {
hlist.separator /
hlist.itemType imagetext
hlist.drawBranch true
hlist.indent 14
hlist.wideSelection false
pack .sh -expand yes -fill both
set hlist [.sh subwidget hlist]

foreach directory {/ /usr /usr/bin /usr/local /etc /etc/rc.d} {
$hlist add $directory -image $folder -text $directory

(Figure 4-4) Displaying Directories in a HList Widget 

Each entry is associated with a display item (see section 3.2 about display items). We can use the -itemtype option of the HList widget to specify the default type of display item to be created by the the add method, as shown in program 4-2 and 4-4. Alternatively, we can also specify the type of display item using the -itemtype option for the add method.