File size: 4,635 Bytes
ba2f5d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
#
#	$Id: HList1.tcl,v 1.3 2001/12/09 05:31:07 idiscovery Exp $
#
# Tix Demostration Program
#
# This sample program is structured in such a way so that it can be
# executed from the Tix demo program "widget": it must have a
# procedure called "RunSample". It should also have the "if" statment
# at the end of this file so that it can be run as a standalone
# program using tixwish.

# This file demonstrates the use of the tixHList widget -- you can
# use to display data in a tree structure. For example, your family tree
#
#
proc RunSample {w} {

    # Create the tixHList and the tixLabelEntry widgets on the on the top
    # of the dialog box
    #
    # [Hint] We create the tixHList and and the scrollbar by ourself,
    #	     but it is more convenient to use the tixScrolledHlist widget
    #	     which does all the chores for us.
    #
    # [Hint] Use of the -browsecmd and -command options:
    #	     We want to set the tixLabelEntry accordingly whenever the user
    #	     single-clicks on an entry in the HList box. Also, when the user
    #	     double-clicks, we want to print out the selection and close
    #	     the dialog box
    #
    frame $w.top -border 1 -relief raised

    tixHList $w.top.h -yscrollcommand "$w.top.s set" -separator / \
	-browsecmd "hlist1:browse $w.top.h" \
	-command "hlist1:activate $w.top.h"\
	-wideselection false \
	-indent 15
    scrollbar $w.top.s -command "$w.top.h yview" -takefocus 0

    # Some icons for our list entries
    #
    global folder1 folder2
    set img1 [image create bitmap -data $folder1]
    set img2 [image create bitmap -data $folder2]

    # Put our directories into the HList entry
    #
    set h $w.top.h
    set dirs {
	/
	/lib
	/pkg
	/usr
	/usr/lib
	/usr/local
	/usr/local/lib
	/pkg/lib
    }
    foreach d $dirs {
	$h add $d -itemtype imagetext -text $d -image $img2 -data $d

	# We only want the user to select the directories that
	# ends by "lib"
	if {![string match "*lib" $d]} {
	    $h entryconfig $d -state disabled -image $img1
	}
    }
    
    # We use a LabelEntry to hold the installation directory. The user
    # can choose from the DirList widget, or he can type in the directory 
    # manually
    #
    tixLabelEntry $w.top.e -label "Installation Directory:" -labelside top \
	-options {
	    entry.width 25
	    entry.textVariable demo_hlist_dir
	    label.anchor w
	}
    bind [$w.top.e subwidget entry] <Return> "hlist:okcmd $w"

    # Set the default value
    #
    uplevel #0 set demo_hlist_dir /usr/local/lib
    $h anchor set /usr/local/lib
    $h select set /usr/local/lib

    pack $w.top.h -side left -expand yes -fill both -padx 2 -pady 2
    pack $w.top.s -side left -fill y -pady 2
    pack $w.top.e -side left -expand yes -fill x -anchor s -padx 4 -pady 2

    # Use a ButtonBox to hold the buttons.
    #
    tixButtonBox $w.box -orientation horizontal
    $w.box add ok     -text Ok     -underline 0 -command "hlist:okcmd $w" \
	-width 6
    $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
	-width 6

    pack $w.box -side bottom -fill x
    pack $w.top -side top -fill both -expand yes
}

# In an actual program, you may want to tell the user how much space he has
# left in this directory
#
#
proc hlist1:browse {w dir} {
    global demo_hlist_dir

    set demo_hlist_dir [$w entrycget $dir -data]
}

# In an actual program, you will install your favorit application
# in the selected directory
#
proc hlist1:activate {w dir} {
    global demo_hlist_dir

    set demo_hlist_dir [$w entrycget $dir -data]
    tixDemo:Status "You have selected the directory $demo_hlist_dir"

    destroy [winfo toplevel $w]
}

proc hlist:okcmd {w} {
    global demo_hlist_dir

    tixDemo:Status "You have selected the directory $demo_hlist_dir"

    destroy $w
}

set folder1 {
#define foo_width 16
#define foo_height 12
static unsigned char foo_bits[] = {
   0x00, 0x00, 0x00, 0x3e, 0xfe, 0x41, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40,
   0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0x02, 0x40, 0xfe, 0x7f, 0x00, 0x00};}

set folder2 {
#define foo_width 16
#define foo_height 12
static unsigned char foo_bits[] = {
   0x00, 0x00, 0x00, 0x00, 0xfe, 0x7f, 0x02, 0x40, 0x02, 0x44, 0xf2, 0x4f,
   0xf2, 0x5f, 0xf2, 0x4f, 0x02, 0x44, 0x02, 0x40, 0xfe, 0x7f, 0x00, 0x00};
}

# This "if" statement makes it possible to run this script file inside or
# outside of the main demo program "widget".
#
if {![info exists tix_demo_running]} {
    wm withdraw .
    set w .demo
    toplevel $w; wm transient $w ""
    RunSample $w
    bind $w <Destroy> exit
}