File size: 5,308 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
#
#	$Id: ChkList.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 program demonstrates the use of the tixCheckList widget.
#

proc RunSample {w} {
    set top [frame $w.f -bd 1 -relief raised]
    set box [tixButtonBox $w.b -bd 1 -relief raised]

    pack $box -side bottom -fill both
    pack $top -side top -fill both -expand yes

    #------------------------------------------------------------
    # Create the 1st CheckList (Multiple Selection)
    #
    set f [frame $top.f1]
    pack $f -side left -expand yes -fill both -padx 4

    set l [label $f.l -text "Choose languages: "]
    pack $l -side top -fill x -padx 4 -pady 4

    set c1 [tixCheckList $f.c -scrollbar auto]
    pack $c1 -expand yes -fill both -padx 4 -pady 4

    set b1 [button $f.btn -text "Results >>" -command "ChkList_Result $c1"]
    pack $b1 -anchor c
    #------------------------------------------------------------
    # Create the 2nd CheckList (Single Selection, using the -radio option)
    #
    set f [frame $top.f2]
    pack $f -side left -expand yes -fill both -padx 4

    set l [label $f.l -text "Choose one language: "]
    pack $l -side top -fill x -padx 4 -pady 4

    set c2 [tixCheckList $f.c -scrollbar auto -radio true]
    pack $c2 -expand yes -fill both -padx 4 -pady 4

    # Fill up the two checklists with languages
    #
    set names(1) "Ada"
    set names(2) "BCPL"
    set names(3) "C"
    set names(4) "Dylan"
    set names(5) "Eiffel"
    set names(6) "Fortran"
    set names(7) "Incr Tcl"
    set names(8) "Python"
    set names(9) "Scheme"
    set names(0) "TCL"

    set h1 [$c1 subwidget hlist]
    set h2 [$c2 subwidget hlist]

    foreach ent {1 2 3 4 5 6 7 8 9 0} {
	$h1 add $ent -itemtype imagetext -text $names($ent)
    }

    foreach ent {1 2 3 4 5 6 7 8 9 0} {
	$h2 add $ent -itemtype imagetext -text $names($ent)
	$c2 setstatus $ent off
    }

    $c1 setstatus 1 on
    $c1 setstatus 2 on
    $c1 setstatus 3 default
    $c1 setstatus 4 off
    $c1 setstatus 5 off
    $c1 setstatus 6 on
    $c1 setstatus 7 off
    $c1 setstatus 8 on
    $c1 setstatus 9 on
    $c1 setstatus 0 default


    #------------------------------------------------------------
    # Create the 3nd CheckList (a tree). Also, we disable some
    # sub-selections if the top-level selections are not selected.
    # i.e., if the user doesn't like any functional languages,
    # make sure he doesn't select Lisp.
    #
    set f [frame $top.f3]
    pack $f -side left -expand yes -fill both -padx 4

    set l [label $f.l -text "Choose languages: "]
    pack $l -side top -fill x -padx 4 -pady 4

    set c3 [tixCheckList $f.c -scrollbar auto -options {
	hlist.indicator 1
	hlist.indent    20
    }]
    pack $c3 -expand yes -fill both -padx 4 -pady 4

    set h3 [$c3 subwidget hlist]

    $h3 add 0 -itemtype imagetext -text "Functional Languages"
    $h3 add 1 -itemtype imagetext -text "Imperative Languages"

    $h3 add 0.0 -itemtype imagetext -text Lisp
    $h3 add 0.1 -itemtype imagetext -text Scheme
    $h3 add 1.0 -itemtype imagetext -text C
    $h3 add 1.1 -itemtype imagetext -text Python

    $c3 setstatus 0   on
    $c3 setstatus 1   on
    $c3 setstatus 0.0 off
    $c3 setstatus 0.1 off
    $c3 setstatus 1.0 on
    $c3 setstatus 1.1 off

    $c3 config -browsecmd "ChkList:Monitor $c3"
    $c3 config -command   "ChkList:Monitor $c3"

    $c3 autosetmode

    global chklist tixOption
    set chklist(disabled) [tixDisplayStyle imagetext -fg $tixOption(disabled_fg) \
	-refwindow [$c3 subwidget hlist]]
    set chklist(normal)   [tixDisplayStyle imagetext -fg black \
	-refwindow [$c3 subwidget hlist]]

    # Create the buttons
    #
    $box add ok     -text Ok     -command "destroy $w" -width 6
    $box add cancel -text Cancel -command "destroy $w" -width 6
}

proc ChkList_Result {clist} {
    tixDemo:Status "Selected items: [$clist getselection on]"
    tixDemo:Status "Unselected items: [$clist getselection off]"
    tixDemo:Status "Default items: [$clist getselection default]"
}

# This function monitors if any of the two "general groups"
# (functional and imperative languages) are de-selected. If so, it
# sets all the sub-selections to non-selectable by setting their -state
# to disabled.
#
proc ChkList:Monitor {c3 ent} {
    global chklist

    set h [$c3 subwidget hlist]

    if {[$c3 getstatus 0] == "on"} {
	set state normal
    } else {
	set state disabled
    }

    $h entryconfig 0.0 -state $state -style $chklist($state)
    $h entryconfig 0.1 -state $state -style $chklist($state)

    if {[$c3 getstatus 1] == "on"} {
	set state normal
    } else {
	set state disabled
    }

    $h entryconfig 1.0 -state $state -style $chklist($state)
    $h entryconfig 1.1 -state $state -style $chklist($state)
}

if {![info exists tix_demo_running]} {
    wm withdraw .
    set w .demo
    toplevel $w; wm transient $w ""
    RunSample $w
    bind $w <Destroy> exit
}