1 # This file is a Tcl script to test out the "listbox" command
2 # of Tk. It is organized in the standard fashion for Tcl tests.
4 # Copyright (c) 1993-1994 The Regents of the University of California.
5 # Copyright (c) 1994-1997 Sun Microsystems, Inc.
6 # Copyright (c) 1998-1999 by Scriptics Corporation.
9 package require tcltest 2.2
10 eval tcltest::configure $argv
11 tcltest::loadTestedCommands
12 namespace import -force tcltest::test
14 set fixed {Courier -12}
16 proc record {name args} {
18 lappend log [format {%s %.6g %.6g} $name {*}$args]
22 regexp {(^[^+-]*)} [wm geometry $w] foo x
26 proc resetGridInfo {} {
27 # Some window managers, such as mwm, don't reset gridding information
28 # unless the window is withdrawn and re-mapped. If this procedure
29 # isn't invoked, the window manager will stay in gridded mode, which
30 # can cause all sorts of problems. The "wm positionfrom" command is
31 # needed so that the window manager doesn't ask the user to
32 # manually position the window when it is re-mapped.
35 wm positionfrom . user
39 # Procedure that creates a second listbox for checking things related
40 # to partially visible lines.
42 proc mkPartial {{w .partial}} {
46 listbox $w.l -width 30 -height 5
47 pack $w.l -expand 1 -fill both
48 $w.l insert end one two three four five six seven eight nine ten \
49 eleven twelve thirteen fourteen fifteen
51 scan [wm geometry $w] "%dx%d" width height
52 wm geometry $w ${width}x[expr $height-3]
56 # Create entries in the option database to be sure that geometry options
57 # like border width have predictable values.
59 option add *Listbox.borderWidth 2
60 option add *Listbox.selectBorderWidth 1
61 option add *Listbox.highlightThickness 2
62 option add *Listbox.font {Helvetica -12 bold}
64 # Listbox used in 3.* configuration options tests
69 test listbox-1.1 {configuration options} -body {
70 .l configure -activestyle under
71 list [lindex [.l configure -activestyle] 4] [.l cget -activestyle]
73 .l configure -activestyle [lindex [.l configure -activestyle] 3]
74 } -result {underline underline}
75 test listbox-1.2 {configuration options} -body {
76 .l configure -activestyle foo
77 } -returnCodes error -result {bad activestyle "foo": must be dotbox, none, or underline}
78 test listbox-1.3 {configuration options} -body {
79 .l configure -background #ff0000
80 list [lindex [.l configure -background] 4] [.l cget -background]
82 .l configure -background [lindex [.l configure -background] 3]
83 } -result {{#ff0000} #ff0000}
84 test listbox-1.4 {configuration options} -body {
85 .l configure -background non-existent
86 } -returnCodes error -result {unknown color name "non-existent"}
87 test listbox-1.5 {configuration options} -body {
89 list [lindex [.l configure -bd] 4] [.l cget -bd]
91 .l configure -bd [lindex [.l configure -bd] 3]
93 test listbox-1.6 {configuration options} -body {
94 .l configure -bd badValue
95 } -returnCodes error -result {bad screen distance "badValue"}
96 test listbox-1.7 {configuration options} -body {
97 .l configure -bg #ff0000
98 list [lindex [.l configure -bg] 4] [.l cget -bg]
100 .l configure -bg [lindex [.l configure -bg] 3]
101 } -result {{#ff0000} #ff0000}
102 test listbox-1.8 {configuration options} -body {
103 .l configure -bg non-existent
104 } -returnCodes error -result {unknown color name "non-existent"}
105 test listbox-1.9 {configuration options} -body {
106 .l configure -borderwidth 1.3
107 list [lindex [.l configure -borderwidth] 4] [.l cget -borderwidth]
109 .l configure -borderwidth [lindex [.l configure -borderwidth] 3]
111 test listbox-1.10 {configuration options} -body {
112 .l configure -borderwidth badValue
113 } -returnCodes error -result {bad screen distance "badValue"}
114 test listbox-1.11 {configuration options} -body {
115 .l configure -cursor arrow
116 list [lindex [.l configure -cursor] 4] [.l cget -cursor]
118 .l configure -cursor [lindex [.l configure -cursor] 3]
119 } -result {arrow arrow}
120 test listbox-1.12 {configuration options} -body {
121 .l configure -cursor badValue
122 } -returnCodes error -result {bad cursor spec "badValue"}
123 test listbox-1.13 {configuration options} -body {
124 .l configure -disabledforeground #110022
125 list [lindex [.l configure -disabledforeground] 4] [.l cget -disabledforeground]
127 .l configure -disabledforeground [lindex [.l configure -disabledforeground] 3]
128 } -result {{#110022} #110022}
129 test listbox-1.14 {configuration options} -body {
130 .l configure -disabledforeground bogus
131 } -returnCodes error -result {unknown color name "bogus"}
132 test listbox-1.15 {configuration options} -body {
133 .l configure -exportselection yes
134 list [lindex [.l configure -exportselection] 4] [.l cget -exportselection]
136 .l configure -exportselection [lindex [.l configure -exportselection] 3]
138 test listbox-1.16 {configuration options} -body {
139 .l configure -exportselection xyzzy
140 } -returnCodes error -result {expected boolean value but got "xyzzy"}
141 test listbox-1.17 {configuration options} -body {
142 .l configure -fg #110022
143 list [lindex [.l configure -fg] 4] [.l cget -fg]
145 .l configure -fg [lindex [.l configure -fg] 3]
146 } -result {{#110022} #110022}
147 test listbox-1.18 {configuration options} -body {
148 .l configure -fg bogus
149 } -returnCodes error -result {unknown color name "bogus"}
150 test listbox-1.19 {configuration options} -body {
151 .l configure -font {Helvetica 12}
152 list [lindex [.l configure -font] 4] [.l cget -font]
154 .l configure -font [lindex [.l configure -font] 3]
155 } -result {{Helvetica 12} {Helvetica 12}}
156 test listbox-1.21 {configuration options} -body {
157 .l configure -foreground #110022
158 list [lindex [.l configure -foreground] 4] [.l cget -foreground]
160 .l configure -foreground [lindex [.l configure -foreground] 3]
161 } -result {{#110022} #110022}
162 test listbox-1.22 {configuration options} -body {
163 .l configure -foreground bogus
164 } -returnCodes error -result {unknown color name "bogus"}
165 test listbox-1.23 {configuration options} -body {
166 .l configure -height 30
167 list [lindex [.l configure -height] 4] [.l cget -height]
169 .l configure -height [lindex [.l configure -height] 3]
171 test listbox-1.24 {configuration options} -body {
172 .l configure -height 20p
173 } -returnCodes error -result {expected integer but got "20p"}
174 test listbox-1.25 {configuration options} -body {
175 .l configure -highlightbackground #112233
176 list [lindex [.l configure -highlightbackground] 4] [.l cget -highlightbackground]
178 .l configure -highlightbackground [lindex [.l configure -highlightbackground] 3]
179 } -result {{#112233} #112233}
180 test listbox-1.26 {configuration options} -body {
181 .l configure -highlightbackground ugly
182 } -returnCodes error -result {unknown color name "ugly"}
183 test listbox-1.27 {configuration options} -body {
184 .l configure -highlightcolor #123456
185 list [lindex [.l configure -highlightcolor] 4] [.l cget -highlightcolor]
187 .l configure -highlightcolor [lindex [.l configure -highlightcolor] 3]
188 } -result {{#123456} #123456}
189 test listbox-1.28 {configuration options} -body {
190 .l configure -highlightcolor bogus
191 } -returnCodes error -result {unknown color name "bogus"}
192 test listbox-1.29 {configuration options} -body {
193 .l configure -highlightthickness 6
194 list [lindex [.l configure -highlightthickness] 4] [.l cget -highlightthickness]
196 .l configure -highlightthickness [lindex [.l configure -highlightthickness] 3]
198 test listbox-1.30 {configuration options} -body {
199 .l configure -highlightthickness bogus
200 } -returnCodes error -result {bad screen distance "bogus"}
201 test listbox-1.31 {configuration options} -body {
202 .l configure -highlightthickness -2
203 list [lindex [.l configure -highlightthickness] 4] [.l cget -highlightthickness]
205 .l configure -highlightthickness [lindex [.l configure -highlightthickness] 3]
207 test listbox-1.32.1 {configuration options} -setup {
210 .l configure -justify left
211 set res [list [lindex [.l configure -justify] 4] [.l cget -justify]]
212 .l configure -justify center
213 lappend res [lindex [.l configure -justify] 4] [.l cget -justify]
214 .l configure -justify right
215 lappend res [lindex [.l configure -justify] 4] [.l cget -justify]
217 .l configure -justify [lindex [.l configure -justify] 3]
218 } -result {left left center center right right}
219 test listbox-1.32.2 {configuration options} -body {
220 .l configure -justify bogus
221 } -returnCodes error -result {bad justification "bogus": must be left, right, or center}
222 test listbox-1.33 {configuration options} -body {
223 .l configure -relief groove
224 list [lindex [.l configure -relief] 4] [.l cget -relief]
226 .l configure -relief [lindex [.l configure -relief] 3]
227 } -result {groove groove}
228 test listbox-1.34 {configuration options} -body {
229 .l configure -relief 1.5
230 } -returnCodes error -result {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}
231 test listbox-1.35 {configuration options} -body {
232 .l configure -selectbackground #110022
233 list [lindex [.l configure -selectbackground] 4] [.l cget -selectbackground]
235 .l configure -selectbackground [lindex [.l configure -selectbackground] 3]
236 } -result {{#110022} #110022}
237 test listbox-1.36 {configuration options} -body {
238 .l configure -selectbackground bogus
239 } -returnCodes error -result {unknown color name "bogus"}
240 test listbox-1.37 {configuration options} -body {
241 .l configure -selectborderwidth 1.3
242 list [lindex [.l configure -selectborderwidth] 4] [.l cget -selectborderwidth]
244 .l configure -selectborderwidth [lindex [.l configure -selectborderwidth] 3]
246 test listbox-1.38 {configuration options} -body {
247 .l configure -selectborderwidth badValue
248 } -returnCodes error -result {bad screen distance "badValue"}
249 test listbox-1.39 {configuration options} -body {
250 .l configure -selectforeground #654321
251 list [lindex [.l configure -selectforeground] 4] [.l cget -selectforeground]
253 .l configure -selectforeground [lindex [.l configure -selectforeground] 3]
254 } -result {{#654321} #654321}
255 test listbox-1.40 {configuration options} -body {
256 .l configure -selectforeground bogus
257 } -returnCodes error -result {unknown color name "bogus"}
258 test listbox-1.41 {configuration options} -body {
259 .l configure -selectmode string
260 list [lindex [.l configure -selectmode] 4] [.l cget -selectmode]
262 .l configure -selectmode [lindex [.l configure -selectmode] 3]
263 } -result {string string}
264 test listbox-1.43 {configuration options} -body {
265 .l configure -setgrid false
266 list [lindex [.l configure -setgrid] 4] [.l cget -setgrid]
268 .l configure -setgrid [lindex [.l configure -setgrid] 3]
270 test listbox-1.44 {configuration options} -body {
271 .l configure -setgrid lousy
272 } -returnCodes error -result {expected boolean value but got "lousy"}
273 test listbox-1.45 {configuration options} -body {
274 .l configure -state disabled
275 list [lindex [.l configure -state] 4] [.l cget -state]
277 .l configure -state [lindex [.l configure -state] 3]
278 } -result {disabled disabled}
279 test listbox-1.46 {configuration options} -body {
280 .l configure -state foo
281 } -returnCodes error -result {bad state "foo": must be disabled or normal}
282 test listbox-1.47 {configuration options} -body {
283 .l configure -takefocus {any string}
284 list [lindex [.l configure -takefocus] 4] [.l cget -takefocus]
286 .l configure -takefocus [lindex [.l configure -takefocus] 3]
287 } -result {{any string} {any string}}
288 test listbox-1.49 {configuration options} -body {
289 .l configure -width 45
290 list [lindex [.l configure -width] 4] [.l cget -width]
292 .l configure -width [lindex [.l configure -width] 3]
294 test listbox-1.50 {configuration options} -body {
295 .l configure -width 3p
296 } -returnCodes error -result {expected integer but got "3p"}
297 test listbox-1.51 {configuration options} -body {
298 .l configure -xscrollcommand {Some command}
299 list [lindex [.l configure -xscrollcommand] 4] [.l cget -xscrollcommand]
301 .l configure -xscrollcommand [lindex [.l configure -xscrollcommand] 3]
302 } -result {{Some command} {Some command}}
303 test listbox-1.53 {configuration options} -body {
304 .l configure -yscrollcommand {Another command}
305 list [lindex [.l configure -yscrollcommand] 4] [.l cget -yscrollcommand]
307 .l configure -yscrollcommand [lindex [.l configure -yscrollcommand] 3]
308 } -result {{Another command} {Another command}}
309 test listbox-1.55 {configuration options} -body {
310 .l configure -listvar testVariable
311 list [lindex [.l configure -listvar] 4] [.l cget -listvar]
313 .l configure -listvar [lindex [.l configure -listvar] 3]
314 } -result {testVariable testVariable}
317 test listbox-2.1 {Tk_ListboxCmd procedure} -body {
319 } -returnCodes error -result {wrong # args: should be "listbox pathName ?-option value ...?"}
320 test listbox-2.2 {Tk_ListboxCmd procedure} -body {
322 } -returnCodes error -result {bad window path name "gorp"}
323 test listbox-2.3 {Tk_ListboxCmd procedure} -setup {
327 list [winfo exists .l] [winfo class .l] [info commands .l]
328 } -result {1 Listbox .l}
329 test listbox-2.4 {Tk_ListboxCmd procedure} -setup {
335 } -returnCodes error -result {unknown option "-gorp"}
336 test listbox-2.4.1 {Tk_ListboxCmd procedure} -setup {
339 catch {listbox .l -gorp foo}
340 list [winfo exists .l] [info commands .l]
344 test listbox-2.5 {Tk_ListboxCmd procedure} -setup {
353 # Listbox used in 3.1 -3.115 tests
355 listbox .l -width 20 -height 5 -bd 4 -highlightthickness 1 -selectborderwidth 2
357 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11 el12 el13 el14 \
360 test listbox-3.1 {ListboxWidgetCmd procedure} -body {
362 } -returnCodes error -result {wrong # args: should be ".l option ?arg ...?"}
363 test listbox-3.2 {ListboxWidgetCmd procedure, "activate" option} -body {
365 } -returnCodes error -result {wrong # args: should be ".l activate index"}
366 test listbox-3.3 {ListboxWidgetCmd procedure, "activate" option} -body {
368 } -returnCodes error -result {wrong # args: should be ".l activate index"}
369 test listbox-3.4 {ListboxWidgetCmd procedure, "activate" option} -body {
371 } -returnCodes error -result {bad listbox index "fooey": must be active, anchor, end, @x,y, or a number}
372 test listbox-3.5 {ListboxWidgetCmd procedure, "activate" option} -body {
376 test listbox-3.6 {ListboxWidgetCmd procedure, "activate" option} -body {
380 test listbox-3.7 {ListboxWidgetCmd procedure, "activate" option} -body {
384 test listbox-3.8 {ListboxWidgetCmd procedure, "activate" option} -body {
388 test listbox-3.9 {ListboxWidgetCmd procedure, "bbox" option} -body {
390 } -returnCodes error -result {wrong # args: should be ".l bbox index"}
391 test listbox-3.10 {ListboxWidgetCmd procedure, "bbox" option} -body {
393 } -returnCodes error -result {wrong # args: should be ".l bbox index"}
394 test listbox-3.11 {ListboxWidgetCmd procedure, "bbox" option} -body {
396 } -returnCodes error -result {bad listbox index "fooey": must be active, anchor, end, @x,y, or a number}
397 test listbox-3.12 {ListboxWidgetCmd procedure, "bbox" option} -body {
400 list [.l bbox 2] [.l bbox 8]
402 test listbox-3.13 {ListboxWidgetCmd procedure, "bbox" option} -cleanup {
405 # Used to generate a core dump before a bug was fixed (the last
406 # element would be on-screen if it existed, but it doesn't exist).
410 tkwait visibility .l2
417 test listbox-3.14 {ListboxWidgetCmd procedure, "bbox" option} -constraints {
422 list [.l bbox 3] [.l bbox 4]
423 } -result {{7 7 17 14} {7 26 17 14}}
424 test listbox-3.15 {ListboxWidgetCmd procedure, "bbox" option} -constraints {
429 list [.l bbox -1] [.l bbox 0]
430 } -result {{} {7 7 17 14}}
431 test listbox-3.16 {ListboxWidgetCmd procedure, "bbox" option} -constraints {
436 list [.l bbox 17] [.l bbox end] [.l bbox 18]
437 } -result {{7 83 24 14} {7 83 24 14} {}}
438 test listbox-3.17 {ListboxWidgetCmd procedure, "bbox" option} -constraints {
445 listbox .t.l -width 10 -height 5
446 .t.l insert 0 "Short" "Somewhat longer" "Really, quite a whole lot longer than can possibly fit on the screen" "Short"
453 } -result {-72 39 393 14}
454 test listbox-3.18 {ListboxWidgetCmd procedure, "bbox" option, partial last line} -constraints {
458 list [.partial.l bbox 3] [.partial.l bbox 4]
459 } -result {{5 56 24 14} {5 73 23 14}}
460 test listbox-3.18a {ListboxWidgetCmd procedure, "bbox" option, justified} -constraints {
464 unset -nocomplain res
467 listbox .top.l -justify left
468 .top.l insert end Item1 LongerItem2 MuchLongerItem3
471 lappend res [.top.l bbox 0] [.top.l bbox 1] [.top.l bbox 2]
472 .top.l configure -justify center
473 lappend res [.top.l bbox 0] [.top.l bbox 1] [.top.l bbox 2]
474 .top.l configure -justify right
475 lappend res [.top.l bbox 0] [.top.l bbox 1] [.top.l bbox 2]
478 unset -nocomplain res
480 {5 5 34 14} {5 22 74 14} {5 39 106 14} \
481 {58 5 34 14} {38 22 74 14} {22 39 106 14} \
482 {111 5 34 14} {71 22 74 14} {39 39 106 14} \
484 test listbox-3.18b {ListboxWidgetCmd procedure, "bbox" option, justified, non-default borderwidth} -setup {
486 unset -nocomplain lres res
488 # This test checks whether all "x" values from bbox for different size
489 # items with different justification settings are all positive or zero
490 # This checks a bit the calculation of this x value with non-default
491 # borders widths of the listbox
493 listbox .top.l -justify left -borderwidth 17 -highlightthickness 19 -selectborderwidth 22
494 .top.l insert end Item1 LongerItem2 MuchLongerItem3
495 .top.l selection set 1
498 lappend lres [.top.l bbox 0] [.top.l bbox 1] [.top.l bbox 2]
499 .top.l configure -justify center
500 lappend lres [.top.l bbox 0] [.top.l bbox 1] [.top.l bbox 2]
501 .top.l configure -justify right
502 lappend lres [.top.l bbox 0] [.top.l bbox 1] [.top.l bbox 2]
504 for {set i 0} {$i < [llength $lres]} {incr i 4} {
505 set res [expr {$res * [expr {[lindex $lres $i] >= 0}] }]
510 unset -nocomplain lres res
512 test listbox-3.19 {ListboxWidgetCmd procedure, "cget" option} -body {
514 } -returnCodes error -result {wrong # args: should be ".l cget option"}
515 test listbox-3.20 {ListboxWidgetCmd procedure, "cget" option} -body {
517 } -returnCodes error -result {wrong # args: should be ".l cget option"}
518 test listbox-3.21 {ListboxWidgetCmd procedure, "cget" option} -body {
520 } -returnCodes error -result {unknown option "-gorp"}
521 test listbox-3.22 {ListboxWidgetCmd procedure, "cget" option} -body {
524 test listbox-3.23 {ListboxWidgetCmd procedure, "configure" option} -body {
525 llength [.l configure]
527 test listbox-3.24 {ListboxWidgetCmd procedure, "configure" option} -body {
529 } -returnCodes error -result {unknown option "-gorp"}
530 test listbox-3.25 {ListboxWidgetCmd procedure, "configure" option} -body {
531 .l configure -setgrid
532 } -result {-setgrid setGrid SetGrid 0 0}
533 test listbox-3.26 {ListboxWidgetCmd procedure, "configure" option} -body {
534 .l configure -gorp is_messy
535 } -returnCodes error -result {unknown option "-gorp"}
536 test listbox-3.27 {ListboxWidgetCmd procedure, "configure" option} -body {
537 set oldbd [.l cget -bd]
538 set oldht [.l cget -highlightthickness]
539 .l configure -bd 3 -highlightthickness 0
540 set x "[.l cget -bd] [.l cget -highlightthickness]"
541 .l configure -bd $oldbd -highlightthickness $oldht
544 test listbox-3.28 {ListboxWidgetCmd procedure, "curselection" option} -body {
546 } -returnCodes error -result {wrong # args: should be ".l curselection"}
547 test listbox-3.29 {ListboxWidgetCmd procedure, "curselection" option} -body {
548 .l selection clear 0 end
552 } -result {3 4 5 6 9}
553 test listbox-3.30 {ListboxWidgetCmd procedure, "delete" option} -body {
555 } -returnCodes error -result {wrong # args: should be ".l delete firstIndex ?lastIndex?"}
556 test listbox-3.31 {ListboxWidgetCmd procedure, "delete" option} -body {
558 } -returnCodes error -result {wrong # args: should be ".l delete firstIndex ?lastIndex?"}
559 test listbox-3.32 {ListboxWidgetCmd procedure, "delete" option} -body {
561 } -returnCodes error -result {bad listbox index "badIndex": must be active, anchor, end, @x,y, or a number}
562 test listbox-3.33 {ListboxWidgetCmd procedure, "delete" option} -body {
564 } -returnCodes error -result {bad listbox index "123ab": must be active, anchor, end, @x,y, or a number}
565 test listbox-3.34 {ListboxWidgetCmd procedure, "delete" option} -setup {
569 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
571 list [.l2 get 2] [.l2 get 3] [.l2 index end]
574 } -result {el2 el4 7}
575 test listbox-3.35 {ListboxWidgetCmd procedure, "delete" option} -setup {
579 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
581 list [.l2 get 1] [.l2 get 2] [.l2 index end]
584 } -result {el1 el5 5}
585 test listbox-3.36 {ListboxWidgetCmd procedure, "delete" option} -setup {
589 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
594 } -result {el3 el4 el5 el6 el7}
595 test listbox-3.37 {ListboxWidgetCmd procedure, "delete" option} -setup {
599 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
604 } -result {el0 el1 el2 el3 el4 el5 el6 el7}
605 test listbox-3.38 {ListboxWidgetCmd procedure, "delete" option} -setup {
609 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
615 test listbox-3.39 {ListboxWidgetCmd procedure, "delete" option} -setup {
619 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
624 } -result {el0 el1 el2 el3 el4}
625 test listbox-3.40 {ListboxWidgetCmd procedure, "delete" option} -setup {
629 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
634 } -result {el0 el1 el2 el3 el4 el5 el6}
635 test listbox-3.41 {ListboxWidgetCmd procedure, "delete" option} -setup {
639 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
644 } -result {el0 el1 el2 el3 el4 el5 el6 el7}
645 test listbox-3.42 {ListboxWidgetCmd procedure, "get" option} -body {
647 } -returnCodes error -result {wrong # args: should be ".l get firstIndex ?lastIndex?"}
648 test listbox-3.43 {ListboxWidgetCmd procedure, "get" option} -body {
650 } -returnCodes error -result {wrong # args: should be ".l get firstIndex ?lastIndex?"}
651 test listbox-3.44 {ListboxWidgetCmd procedure, "get" option} -body {
653 } -returnCodes error -result {bad listbox index "2.4": must be active, anchor, end, @x,y, or a number}
654 test listbox-3.45 {ListboxWidgetCmd procedure, "get" option} -body {
656 } -returnCodes error -result {bad listbox index "bogus": must be active, anchor, end, @x,y, or a number}
657 test listbox-3.46 {ListboxWidgetCmd procedure, "get" option} -setup {
661 .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
662 list [.l2 get 0] [.l2 get 3] [.l2 get end]
665 } -result {el0 el3 el7}
666 test listbox-3.47 {ListboxWidgetCmd procedure, "get" option} -setup {
670 list [.l2 get 0] [.l2 get end]
674 test listbox-3.48 {ListboxWidgetCmd procedure, "get" option} -setup {
678 .l2 insert 0 el0 el1 el2 "two words" el4 el5 el6 el7
682 } -result {{two words} el4 el5 el6 el7}
683 test listbox-3.49 {ListboxWidgetCmd procedure, "get" option} -body {
686 test listbox-3.50 {ListboxWidgetCmd procedure, "get" option} -body {
689 test listbox-3.51 {ListboxWidgetCmd procedure, "get" option} -body {
691 } -result {el0 el1 el2 el3}
692 test listbox-3.52 {ListboxWidgetCmd procedure, "get" option} -body {
694 } -result {el12 el13 el14 el15 el16 el17}
695 test listbox-3.53 {ListboxWidgetCmd procedure, "get" option} -body {
697 } -result {el12 el13 el14 el15 el16 el17}
698 test listbox-3.54 {ListboxWidgetCmd procedure, "get" option} -body {
701 test listbox-3.55 {ListboxWidgetCmd procedure, "get" option} -body {
704 test listbox-3.56 {ListboxWidgetCmd procedure, "get" option} -body {
707 test listbox-3.57 {ListboxWidgetCmd procedure, "index" option} -body {
709 } -returnCodes error -result {wrong # args: should be ".l index index"}
710 test listbox-3.58 {ListboxWidgetCmd procedure, "index" option} -body {
712 } -returnCodes error -result {wrong # args: should be ".l index index"}
713 test listbox-3.59 {ListboxWidgetCmd procedure, "index" option} -body {
715 } -returnCodes error -result {bad listbox index "@": must be active, anchor, end, @x,y, or a number}
716 test listbox-3.60 {ListboxWidgetCmd procedure, "index" option} -body {
719 test listbox-3.61 {ListboxWidgetCmd procedure, "index" option} -body {
722 test listbox-3.62 {ListboxWidgetCmd procedure, "index" option} -body {
725 test listbox-3.63 {ListboxWidgetCmd procedure, "index" option} -body {
728 test listbox-3.64 {ListboxWidgetCmd procedure, "insert" option} -body {
730 } -returnCodes error -result {wrong # args: should be ".l insert index ?element ...?"}
731 test listbox-3.65 {ListboxWidgetCmd procedure, "insert" option} -body {
733 } -returnCodes error -result {bad listbox index "badIndex": must be active, anchor, end, @x,y, or a number}
734 test listbox-3.66 {ListboxWidgetCmd procedure, "insert" option} -setup {
738 .l2 insert end a b c d e
743 } -result {a b c x y z d e}
744 test listbox-3.67 {ListboxWidgetCmd procedure, "insert" option} -setup {
754 test listbox-3.68 {ListboxWidgetCmd procedure, "insert" option} -setup {
764 test listbox-3.69 {ListboxWidgetCmd procedure, "insert" option} -setup {
774 test listbox-3.70 {ListboxWidgetCmd procedure, "nearest" option} -body {
776 } -returnCodes error -result {wrong # args: should be ".l nearest y"}
777 test listbox-3.71 {ListboxWidgetCmd procedure, "nearest" option} -body {
779 } -returnCodes error -result {wrong # args: should be ".l nearest y"}
780 test listbox-3.72 {ListboxWidgetCmd procedure, "nearest" option} -body {
782 } -returnCodes error -result {expected integer but got "20p"}
783 test listbox-3.73 {ListboxWidgetCmd procedure, "nearest" option} -body {
787 test listbox-3.74 {ListboxWidgetCmd procedure, "scan" option} -body {
789 } -returnCodes error -result {wrong # args: should be ".l scan mark|dragto x y"}
790 test listbox-3.75 {ListboxWidgetCmd procedure, "scan" option} -body {
792 } -returnCodes error -result {wrong # args: should be ".l scan mark|dragto x y"}
793 test listbox-3.76 {ListboxWidgetCmd procedure, "scan" option} -body {
795 } -returnCodes error -result {expected integer but got "bogus"}
796 test listbox-3.77 {ListboxWidgetCmd procedure, "scan" option} -body {
798 } -returnCodes error -result {expected integer but got "2.3"}
799 test listbox-3.78 {ListboxWidgetCmd procedure, "scan" option} -constraints {
806 listbox .t.l -width 10 -height 5
807 .t.l insert 0 "Short" "Somewhat longer" "Really, quite a whole lot longer than can possibly fit on the screen" "Short" a b c d e f g h i j
810 .t.l scan mark 100 140
811 .t.l scan dragto 90 137
813 list [format {%.6g %.6g} {*}[.t.l xview]] [format {%.6g %.6g} {*}[.t.l yview]]
816 } -result {{0.249364 0.427481} {0.0714286 0.428571}}
817 test listbox-3.79 {ListboxWidgetCmd procedure, "scan" option} -body {
819 } -returnCodes error -result {bad option "foo": must be mark or dragto}
820 test listbox-3.80 {ListboxWidgetCmd procedure, "see" option} -body {
822 } -returnCodes error -result {wrong # args: should be ".l see index"}
823 test listbox-3.81 {ListboxWidgetCmd procedure, "see" option} -body {
825 } -returnCodes error -result {wrong # args: should be ".l see index"}
826 test listbox-3.82 {ListboxWidgetCmd procedure, "see" option} -body {
828 } -returnCodes error -result {bad listbox index "gorp": must be active, anchor, end, @x,y, or a number}
829 test listbox-3.83 {ListboxWidgetCmd procedure, "see" option} -body {
834 test listbox-3.84 {ListboxWidgetCmd procedure, "see" option} -body {
839 test listbox-3.85 {ListboxWidgetCmd procedure, "see" option} -body {
844 test listbox-3.86 {ListboxWidgetCmd procedure, "see" option} -body {
849 test listbox-3.87 {ListboxWidgetCmd procedure, "see" option} -body {
854 test listbox-3.88 {ListboxWidgetCmd procedure, "see" option} -body {
859 test listbox-3.89 {ListboxWidgetCmd procedure, "see" option} -body {
864 test listbox-3.90 {ListboxWidgetCmd procedure, "see" option} -body {
869 test listbox-3.91 {ListboxWidgetCmd procedure, "see" option} -body {
874 test listbox-3.92 {ListboxWidgetCmd procedure, "see" option, partial last line} -body {
877 .partial.l index @0,0
879 test listbox-3.93 {ListboxWidgetCmd procedure, "selection" option} -body {
881 } -returnCodes error -result {wrong # args: should be ".l selection option index ?index?"}
882 test listbox-3.94 {ListboxWidgetCmd procedure, "selection" option} -body {
884 } -returnCodes error -result {wrong # args: should be ".l selection option index ?index?"}
885 test listbox-3.95 {ListboxWidgetCmd procedure, "selection" option} -body {
887 } -returnCodes error -result {bad listbox index "bogus": must be active, anchor, end, @x,y, or a number}
888 test listbox-3.96 {ListboxWidgetCmd procedure, "selection" option} -body {
889 .l selection a 0 lousy
890 } -returnCodes error -result {bad listbox index "lousy": must be active, anchor, end, @x,y, or a number}
891 test listbox-3.97 {ListboxWidgetCmd procedure, "selection" option} -body {
892 .l selection anchor 0 0
893 } -returnCodes error -result {wrong # args: should be ".l selection anchor index"}
894 test listbox-3.98 {ListboxWidgetCmd procedure, "selection" option} -body {
895 list [.l selection anchor 5; .l index anchor] \
896 [.l selection anchor 0; .l index anchor]
898 test listbox-3.99 {ListboxWidgetCmd procedure, "selection" option} -body {
899 .l selection anchor -1
902 test listbox-3.100 {ListboxWidgetCmd procedure, "selection" option} -body {
903 .l selection anchor end
906 test listbox-3.101 {ListboxWidgetCmd procedure, "selection" option} -body {
907 .l selection anchor 44
910 test listbox-3.102 {ListboxWidgetCmd procedure, "selection" option} -body {
911 .l selection clear 0 end
913 .l selection clear 3 4
915 } -result {2 5 6 7 8}
916 test listbox-3.103 {ListboxWidgetCmd procedure, "selection" option} -body {
917 .l selection includes 0 0
918 } -returnCodes error -result {wrong # args: should be ".l selection includes index"}
919 test listbox-3.104 {ListboxWidgetCmd procedure, "selection" option} -body {
920 .l selection clear 0 end
923 list [.l selection includes 3] [.l selection includes 4] \
924 [.l selection includes 5]
926 test listbox-3.105 {ListboxWidgetCmd procedure, "selection" option} -body {
927 .l selection set 0 end
928 .l selection includes -1
930 test listbox-3.106 {ListboxWidgetCmd procedure, "selection" option} -body {
931 .l selection clear 0 end
933 .l selection includes end
935 test listbox-3.107 {ListboxWidgetCmd procedure, "selection" option} -body {
936 .l selection set 0 end
937 .l selection includes 44
939 test listbox-3.108 {ListboxWidgetCmd procedure, "selection" option} -setup {
943 .l2 selection includes 0
947 test listbox-3.109 {ListboxWidgetCmd procedure, "selection" option} -body {
948 .l selection clear 0 end
953 test listbox-3.110 {ListboxWidgetCmd procedure, "selection" option} -body {
954 .l selection clear 0 end
960 test listbox-3.111 {ListboxWidgetCmd procedure, "selection" option} -body {
961 .l selection badOption 0 0
962 } -returnCodes error -result {bad option "badOption": must be anchor, clear, includes, or set}
963 test listbox-3.112 {ListboxWidgetCmd procedure, "size" option} -body {
965 } -returnCodes error -result {wrong # args: should be ".l size"}
966 test listbox-3.113 {ListboxWidgetCmd procedure, "size" option} -body {
969 test listbox-3.114 {ListboxWidgetCmd procedure, "xview" option} -setup {
974 format {%.6g %.6g} {*}[.l2 xview]
978 test listbox-3.115 {ListboxWidgetCmd procedure, "xview" option} -setup {
981 listbox .l2 -width 10 -height 5 -font $fixed
982 .l2 insert 0 a b c d e f g h i j k l m n o p q r s t
985 format {%.6g %.6g} {*}[.l2 xview]
990 test listbox-3.116 {ListboxWidgetCmd procedure, "xview" option} -constraints {
994 listbox .l2 -width 10 -height 5 -font $fixed
998 .l2 insert 0 a b c d e f g h i j k l m n o p q r s t
999 .l2 insert 1 "0123456789a123456789b123456789c123456789d123456789"
1001 format {%.6g %.6g} {*}[.l2 xview]
1004 } -result {0.08 0.28}
1005 test listbox-3.117 {ListboxWidgetCmd procedure, "xview" option} -body {
1007 } -returnCodes error -result {expected integer but got "foo"}
1008 test listbox-3.118 {ListboxWidgetCmd procedure, "xview" option} -body {
1010 } -returnCodes error -result {unknown option "zoom": must be moveto or scroll}
1011 test listbox-3.119 {ListboxWidgetCmd procedure, "xview" option} -constraints {
1015 listbox .l2 -width 10 -height 5 -font $fixed
1019 .l2 insert 0 a b c d e f g h i j k l m n o p q r s t
1020 .l2 insert 1 "0123456789a123456789b123456789c123456789d123456789"
1024 format {%.6g %.6g} {*}[.l2 xview]
1028 test listbox-3.120 {ListboxWidgetCmd procedure, "xview" option} -constraints {
1032 listbox .l2 -width 10 -height 5 -font $fixed
1036 .l2 insert 0 a b c d e f g h i j k l m n o p q r s t
1037 .l2 insert 1 "0123456789a123456789b123456789c123456789d123456789"
1039 .l2 xview scroll 2 units
1041 format {%.6g %.6g} {*}[.l2 xview]
1044 } -result {0.04 0.24}
1045 test listbox-3.121 {ListboxWidgetCmd procedure, "xview" option} -constraints {
1049 listbox .l2 -width 10 -height 5 -font $fixed
1053 .l2 insert 0 a b c d e f g h i j k l m n o p q r s t
1054 .l2 insert 1 "0123456789a123456789b123456789c123456789d123456789"
1056 .l2 xview scroll -1 pages
1058 format {%.6g %.6g} {*}[.l2 xview]
1061 } -result {0.44 0.64}
1062 test listbox-3.122 {ListboxWidgetCmd procedure, "xview" option} -constraints {
1066 listbox .l2 -width 10 -height 5 -font $fixed
1070 .l2 insert 0 a b c d e f g h i j k l m n o p q r s t
1071 .l2 insert 1 "0123456789a123456789b123456789c123456789d123456789"
1072 .l2 configure -width 1
1075 .l2 xview scroll -4 pages
1077 format {%.6g %.6g} {*}[.l2 xview]
1080 } -result {0.52 0.54}
1081 test listbox-3.123 {ListboxWidgetCmd procedure, "yview" option} -setup {
1087 format {%.6g %.6g} {*}[.l2 yview]
1091 test listbox-3.124 {ListboxWidgetCmd procedure, "yview" option} -setup {
1098 format {%.6g %.6g} {*}[.l2 yview]
1103 test listbox-3.125 {ListboxWidgetCmd procedure, "yview" option} -setup {
1105 listbox .l2 -width 10 -height 5 -font $fixed
1109 .l2 insert 0 a b c d e f g h i j k l m n o p q r s t
1112 format {%.6g %.6g} {*}[.l2 yview]
1115 } -result {0.2 0.45}
1116 test listbox-3.126 {ListboxWidgetCmd procedure, "yview" option, partial last line} -setup {
1118 listbox .l -width 10 -height 5 -font $fixed
1122 .l insert 0 a b c d e f g h i j k l m n o p q r s t
1124 format {%.6g %.6g} {*}[.partial.l yview]
1127 } -result {0 0.266667}
1129 # Listbox used in 3.127 -3.137 tests
1131 listbox .l -width 20 -height 5 -bd 4 -highlightthickness 1 -selectborderwidth 2
1133 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11 el12 el13 el14 \
1136 test listbox-3.127 {ListboxWidgetCmd procedure, "xview" option} -body {
1138 } -returnCodes error -result {bad listbox index "foo": must be active, anchor, end, @x,y, or a number}
1139 test listbox-3.128 {ListboxWidgetCmd procedure, "xview" option} -body {
1141 } -returnCodes error -result {unknown option "foo": must be moveto or scroll}
1142 test listbox-3.129 {ListboxWidgetCmd procedure, "xview" option} -setup {
1144 listbox .l2 -width 10 -height 5 -font $fixed
1148 .l2 insert 0 a b c d e f g h i j k l m n o p q r s t
1150 .l2 yview moveto .31
1151 format {%.6g %.6g} {*}[.l2 yview]
1154 } -result {0.3 0.55}
1155 test listbox-3.130 {ListboxWidgetCmd procedure, "xview" option} -setup {
1157 listbox .l2 -width 10 -height 5 -font $fixed
1161 .l2 insert 0 a b c d e f g h i j k l m n o p q r s t
1163 .l2 yview scroll 2 pages
1164 format {%.6g %.6g} {*}[.l2 yview]
1167 } -result {0.4 0.65}
1168 test listbox-3.131 {ListboxWidgetCmd procedure, "xview" option} -setup {
1170 listbox .l2 -width 10 -height 5 -font $fixed
1174 .l2 insert 0 a b c d e f g h i j k l m n o p q r s t
1176 .l2 yview scroll -3 units
1177 format {%.6g %.6g} {*}[.l2 yview]
1180 } -result {0.35 0.6}
1181 test listbox-3.132 {ListboxWidgetCmd procedure, "xview" option} -setup {
1183 listbox .l2 -width 10 -height 5 -font $fixed
1187 .l2 insert 0 a b c d e f g h i j k l m n o p q r s t
1188 .l2 configure -height 2
1191 .l2 yview scroll -4 pages
1192 format {%.6g %.6g} {*}[.l2 yview]
1195 } -result {0.55 0.65}
1196 test listbox-3.133 {ListboxWidgetCmd procedure, "xview" option} -body {
1198 } -returnCodes error -result {bad option "whoknows": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}
1199 test listbox-3.134 {ListboxWidgetCmd procedure, "xview" option} -body {
1201 } -returnCodes error -result {ambiguous option "c": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}
1202 test listbox-3.135 {ListboxWidgetCmd procedure, "xview" option} -body {
1204 } -returnCodes error -result {ambiguous option "in": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}
1205 test listbox-3.136 {ListboxWidgetCmd procedure, "xview" option} -body {
1207 } -returnCodes error -result {ambiguous option "s": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}
1208 test listbox-3.137 {ListboxWidgetCmd procedure, "xview" option} -body {
1210 } -returnCodes error -result {ambiguous option "se": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}
1212 # No tests for DestroyListbox: I can't come up with anything to test
1213 # in this procedure.
1216 test listbox-4.1 {ConfigureListbox procedure} -constraints {
1221 listbox .l -setgrid 1 -width 25 -height 15
1227 .l configure -setgrid 0
1232 } -result {25x15 185x263}
1234 test listbox-4.2 {ConfigureListbox procedure} -setup {
1237 listbox .l -setgrid 1 -width 25 -height 15
1241 .l configure -highlightthickness -3
1242 .l cget -highlightthickness
1246 test listbox-4.3 {ConfigureListbox procedure} -setup {
1249 listbox .l -setgrid 1 -width 25 -height 15
1253 .l configure -exportselection 0
1255 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8
1256 .l selection set 3 5
1257 .l configure -exportselection 1
1264 test listbox-4.4 {ConfigureListbox procedure} -setup {
1266 listbox .l -setgrid 1 -width 25 -height 15
1274 .l configure -exportselection 0
1276 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8
1277 .l selection set 3 5
1278 .l selection clear 3 5
1279 .l configure -exportselection 1
1280 list [selection own] [selection get]
1284 test listbox-4.5 {-exportselection option} -setup {
1286 listbox .l -setgrid 1 -width 25 -height 15
1291 .l configure -exportselection 1
1293 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8
1294 .l selection set 1 1
1296 lappend x [catch {selection get} msg] $msg [.l curselection]
1297 .l config -exportselection 0
1298 lappend x [catch {selection get} msg] $msg [.l curselection]
1299 .l selection clear 0 end
1300 lappend x [catch {selection get} msg] $msg [.l curselection]
1301 .l selection set 1 3
1302 lappend x [catch {selection get} msg] $msg [.l curselection]
1303 .l config -exportselection 1
1304 lappend x [catch {selection get} msg] $msg [.l curselection]
1307 } -result {0 el1 1 1 {PRIMARY selection doesn't exist or form "STRING" not defined} 1 1 {PRIMARY selection doesn't exist or form "STRING" not defined} {} 1 {PRIMARY selection doesn't exist or form "STRING" not defined} {1 2 3} 0 {el1
1310 test listbox-4.6 {ConfigureListbox procedure} -constraints {
1316 # The following code (reset geometry, withdraw, etc.) is necessary
1317 # to reset the state of some window managers like olvwm under
1324 listbox .l2 -font $fixed -width 15 -height 20
1329 .l2 configure -setgrid 1
1334 } -result {115x328 15x20}
1335 test listbox-4.7 {ConfigureListbox procedure} -setup {
1339 listbox .l2 -font $fixed -width 30 -height 20 -setgrid 1
1344 set result [getsize .]
1347 lappend result [getsize .]
1348 .l2 configure -setgrid 1
1350 lappend result [getsize .]
1354 } -result {30x20 26x15 26x15}
1357 test listbox-4.8 {ConfigureListbox procedure} -setup {
1360 listbox .l2 -width 15 -height 20 -xscrollcommand "record x" \
1361 -yscrollcommand "record y"
1364 .l2 configure -fg black
1370 } -result {{y 0 1} {x 0 1}}
1371 test listbox-4.9 {ConfigureListbox procedure, -listvar} -setup {
1374 set x [list a b c d]
1375 listbox .l2 -listvar x
1379 } -result [list a b c d]
1380 test listbox-4.10 {ConfigureListbox, no listvar -> existing listvar} -setup {
1383 set x [list a b c d]
1385 .l2 insert end 1 2 3 4
1386 .l2 configure -listvar x
1390 } -result [list a b c d]
1391 test listbox-4.11 {ConfigureListbox procedure, listvar -> no listvar} -setup {
1394 set x [list a b c d]
1395 listbox .l2 -listvar x
1396 .l2 configure -listvar {}
1397 .l2 insert end 1 2 3 4
1398 list $x [.l2 get 0 end]
1401 } -result [list [list a b c d] [list a b c d 1 2 3 4]]
1402 test listbox-4.12 {ConfigureListbox procedure, listvar -> different listvar} -setup {
1405 set x [list a b c d]
1406 set y [list 1 2 3 4]
1408 .l2 configure -listvar x
1409 .l2 configure -listvar y
1410 .l2 insert end 5 6 7 8
1414 } -result [list [list a b c d] [list 1 2 3 4 5 6 7 8]]
1415 test listbox-4.13 {ConfigureListbox, no listvar -> non-existant listvar} -setup {
1420 .l2 insert end a b c d
1421 .l2 configure -listvar x
1425 } -result [list a b c d]
1426 test listbox-4.14 {ConfigureListbox, non-existant listvar} -setup {
1430 listbox .l2 -listvar x
1431 list [info exists x] $x
1434 } -result [list 1 {}]
1435 test listbox-4.15 {ConfigureListbox, listvar -> non-existant listvar} -setup {
1439 set x [list a b c d]
1440 listbox .l2 -listvar x
1441 .l2 configure -listvar y
1442 list [info exists y] $y
1445 } -result [list 1 [list a b c d]]
1446 test listbox-4.16 {ConfigureListbox, listvar -> same listvar} -setup {
1449 set x [list a b c d]
1450 listbox .l2 -listvar x
1451 .l2 configure -listvar x
1455 } -result [list a b c d]
1456 test listbox-4.17 {ConfigureListbox, no listvar -> no listvar} -setup {
1460 .l2 insert end a b c d
1461 .l2 configure -listvar {}
1465 } -result [list a b c d]
1466 test listbox-4.18 {ConfigureListbox, no listvar -> bad listvar} -setup {
1470 .l2 insert end a b c d
1471 set x "this is a \" bad list"
1472 catch {.l2 configure -listvar x} result
1473 list [.l2 get 0 end] [.l2 cget -listvar] $result
1476 } -result [list [list a b c d] {} \
1477 "unmatched open quote in list: invalid -listvariable value"]
1478 test listbox-4.19 {ConfigureListbox, no listvar -> bad non-existent listvar} -setup {
1481 unset -nocomplain ::foo
1482 listbox .l2 -listvar foo
1483 .l2 insert end a b c d
1484 catch {.l2 configure -listvar ::zoo::bar::foo} result
1485 list [.l2 get 0 end] [.l2 cget -listvar] $foo $result
1488 } -result [list [list a b c d] foo [list a b c d] \
1489 {can't set "::zoo::bar::foo": parent namespace doesn't exist}]
1492 # No tests for DisplayListbox: I don't know how to test this procedure.
1494 test listbox-5.1 {ListboxComputeGeometry procedure} -constraints {
1499 listbox .l -font $fixed -width 15 -height 20
1501 list [winfo reqwidth .l] [winfo reqheight .l]
1503 test listbox-5.2 {ListboxComputeGeometry procedure} -constraints {
1508 listbox .l -font $fixed -width 0 -height 10
1511 list [winfo reqwidth .l] [winfo reqheight .l]
1513 test listbox-5.3 {ListboxComputeGeometry procedure} -constraints {
1518 listbox .l -font $fixed -width 0 -height 10 -bd 3
1519 .l insert 0 Short "Really much longer" Longer
1522 list [winfo reqwidth .l] [winfo reqheight .l]
1524 test listbox-5.4 {ListboxComputeGeometry procedure} -constraints {
1529 listbox .l -font $fixed -width 10 -height 0
1532 list [winfo reqwidth .l] [winfo reqheight .l]
1534 test listbox-5.5 {ListboxComputeGeometry procedure} -constraints {
1539 listbox .l -font $fixed -width 10 -height 0 -highlightthickness 0
1540 .l insert 0 Short "Really much longer" Longer
1543 list [winfo reqwidth .l] [winfo reqheight .l]
1545 test listbox-5.6 {ListboxComputeGeometry procedure} -setup {
1548 # If "0" in selected font had 0 width, caused divide-by-zero error.
1550 pack [listbox .l -font {{open look glyph}}]
1557 # Listbox used in 6.*, 7.* tests
1559 listbox .l -height 2 -xscrollcommand "record x" -yscrollcommand "record y"
1562 test listbox-6.1 {InsertEls procedure} -body {
1564 .l insert end a b c d
1569 } -result {q r s a b A c d x y z}
1570 test listbox-6.2 {InsertEls procedure} -body {
1572 .l insert 0 a b c d e f g h i j
1573 .l selection anchor 2
1577 test listbox-6.3 {InsertEls procedure} -body {
1579 .l insert 0 a b c d e f g h i j
1580 .l selection anchor 2
1584 test listbox-6.4 {InsertEls procedure} -body {
1586 .l insert 0 a b c d e f g h i j
1592 test listbox-6.5 {InsertEls procedure} -body {
1594 .l insert 0 a b c d e f g h i j
1600 test listbox-6.6 {InsertEls procedure} -body {
1602 .l insert 0 a b c d e f g h i j
1607 test listbox-6.7 {InsertEls procedure} -body {
1609 .l insert 0 a b c d e f g h i j
1614 test listbox-6.8 {InsertEls procedure} -body {
1619 test listbox-6.9 {InsertEls procedure} -body {
1624 test listbox-6.10 {InsertEls procedure} -body {
1626 .l insert 0 a b "two words" c d e f g h i j
1632 } -result {{y 0 0.166667}}
1633 test listbox-6.11 {InsertEls procedure} -body {
1635 .l insert 0 a b "two words" c d e f g h i j
1638 .l insert 0 "much longer entry"
1641 } -result {{y 0 0.166667} {x 0 1}}
1642 test listbox-6.12 {InsertEls procedure} -constraints {
1647 listbox .l2 -width 0 -height 0
1649 .l2 insert 0 a b "two words" c d
1651 lappend x [winfo reqwidth .l2] [winfo reqheight .l2]
1652 .l2 insert 0 "much longer entry"
1653 lappend x [winfo reqwidth .l2] [winfo reqheight .l2]
1656 } -result {80 93 122 110}
1657 test listbox-6.13 {InsertEls procedure, check -listvar update} -setup {
1660 set x [list a b c d]
1661 listbox .l2 -listvar x
1662 .l2 insert 0 1 2 3 4
1666 } -result [list 1 2 3 4 a b c d]
1667 test listbox-6.14 {InsertEls procedure, check selection update} -setup {
1671 .l2 insert 0 0 1 2 3 4
1672 .l2 selection set 2 4
1677 } -result [list 3 4 5]
1678 test listbox-6.15 {InsertEls procedure, lost namespaced listvar} -body {
1680 namespace eval test { variable foo {a b} }
1681 listbox .l2 -listvar ::test::foo
1682 namespace delete test
1686 catch {set ::test::foo} result
1687 list [.l2 get 0 end] [.l2 cget -listvar] $result
1690 } -result [list [list a b c e f] ::test::foo \
1691 {can't read "::test::foo": no such variable}]
1694 test listbox-7.1 {DeleteEls procedure} -body {
1696 .l insert 0 a b c d e f g h i j
1697 .l selection set 1 6
1699 list [.l size] [selection get]
1706 test listbox-7.2 {DeleteEls procedure} -body {
1708 .l insert 0 a b c d e f g h i j
1709 .l selection set 3 6
1711 list [.l size] [.l get 4] [.l curselection]
1712 } -result {9 f {3 4 5}}
1713 test listbox-7.3 {DeleteEls procedure} -body {
1715 .l insert 0 a b c d e f g h i j
1717 list [.l size] [.l get 0] [.l get 1]
1719 test listbox-7.4 {DeleteEls procedure} -body {
1721 .l insert 0 a b c d e f g h i j
1723 list [.l size] [.l get 7]
1725 test listbox-7.5 {DeleteEls procedure} -body {
1727 .l insert 0 a b c d e f g h i j
1728 .l selection anchor 2
1732 test listbox-7.6 {DeleteEls procedure} -body {
1734 .l insert 0 a b c d e f g h i j
1735 .l selection anchor 2
1739 test listbox-7.7 {DeleteEls procedure} -body {
1741 .l insert 0 a b c d e f g h i j
1742 .l selection anchor 4
1746 test listbox-7.8 {DeleteEls procedure} -body {
1748 .l insert 0 a b c d e f g h i j
1749 .l selection anchor 3
1753 test listbox-7.9 {DeleteEls procedure} -body {
1755 .l insert 0 a b c d e f g h i j
1761 test listbox-7.10 {DeleteEls procedure} -body {
1763 .l insert 0 a b c d e f g h i j
1769 test listbox-7.11 {DeleteEls procedure} -body {
1771 .l insert 0 a b c d e f g h i j
1777 test listbox-7.12 {DeleteEls procedure} -body {
1779 .l insert 0 a b c d e f g h i j
1785 test listbox-7.13 {DeleteEls procedure, updating view with partial last line} -body {
1789 .partial.l delete 10 13
1790 .partial.l index @0,0
1792 test listbox-7.14 {DeleteEls procedure} -body {
1794 .l insert 0 a b c d e f g h i j
1799 test listbox-7.15 {DeleteEls procedure} -body {
1801 .l insert 0 a b c d e f g h i j
1806 test listbox-7.16 {DeleteEls procedure} -body {
1808 .l insert 0 a b c d e f g h i j
1813 test listbox-7.17 {DeleteEls procedure} -body {
1815 .l insert 0 a b c d e f g h i j
1820 test listbox-7.18 {DeleteEls procedure} -body {
1822 .l insert 0 a b c "two words" d e f g h i j
1828 } -result {{y 0 0.25}}
1829 test listbox-7.19 {DeleteEls procedure} -body {
1831 .l insert 0 a b c "two words" d e f g h i j
1837 } -result {{y 0 0.2} {x 0 1}}
1838 test listbox-7.20 {DeleteEls procedure} -constraints {
1843 listbox .l2 -width 0 -height 0
1845 .l2 insert 0 a b "two words" c d e f g
1847 lappend x [winfo reqwidth .l2] [winfo reqheight .l2]
1849 lappend x [winfo reqwidth .l2] [winfo reqheight .l2]
1850 } -result {80 144 17 93}
1851 test listbox-7.21 {DeleteEls procedure, check -listvar update} -setup {
1854 set x [list a b c d]
1855 listbox .l2 -listvar x
1858 } -result [list c d]
1861 test listbox-8.1 {ListboxEventProc procedure} -constraints {
1866 listbox .l -setgrid 1
1871 list $x [getsize .] [winfo exists .l] [info command .l]
1874 } -result {20x10 150x178 0 {}}
1876 test listbox-8.2 {ListboxEventProc procedure} -constraints {
1881 listbox .l -height 5 -width 10
1882 .l insert 0 a b c "A string that is very very long" d e f g h i j k
1885 place .l -width 50 -height 80
1887 list [format {%.6g %.6g} {*}[.l xview]] [format {%.6g %.6g} {*}[.l yview]]
1890 } -result {{0 0.222222} {0 0.333333}}
1891 test listbox-8.3 {ListboxEventProc procedure} -setup {
1894 listbox .l1 -bg #543210
1897 lappend x [winfo children .]
1898 lappend x [.l2 cget -bg]
1900 lappend x [info command .l*] [winfo children .]
1903 } -result {.l1 #543210 {} {}}
1906 test listbox-9.1 {ListboxCmdDeletedProc procedure} -setup {
1911 list [info command .l*] [winfo children .]
1915 test listbox-9.2 {ListboxCmdDeletedProc procedure, disabling -setgrid} -constraints {
1922 listbox .top.l -setgrid 1 -width 20 -height 10
1925 set x [getsize .top]
1928 lappend x [getsize .top]
1931 } -result {20x10 150x178}
1934 # Listbox used in 10.* tests
1936 test listbox-10.1 {GetListboxIndex procedure} -setup {
1940 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
1943 list [.l activate 3; .l index active] [.l activate 6; .l index active]
1947 test listbox-10.2 {GetListboxIndex procedure} -setup {
1951 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
1952 .l selection anchor 2
1958 test listbox-10.3 {GetListboxIndex procedure} -setup {
1962 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
1963 .l insert end A B C D E
1964 .l selection anchor end
1967 list [.l index anchor] [.l index end]
1971 test listbox-10.4 {GetListboxIndex procedure} -setup {
1975 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
1980 } -returnCodes error -result {bad listbox index "a": must be active, anchor, end, @x,y, or a number}
1981 test listbox-10.5 {GetListboxIndex procedure} -setup {
1985 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
1991 test listbox-10.6 {GetListboxIndex procedure} -setup {
1995 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
2001 test listbox-10.7 {GetListboxIndex procedure} -setup {
2005 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
2012 test listbox-10.8 {GetListboxIndex procedure} -setup {
2016 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
2021 } -returnCodes error -result {bad listbox index "@": must be active, anchor, end, @x,y, or a number}
2022 test listbox-10.9 {GetListboxIndex procedure} -setup {
2026 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
2031 } -returnCodes error -result {bad listbox index "@foo": must be active, anchor, end, @x,y, or a number}
2032 test listbox-10.10 {GetListboxIndex procedure} -setup {
2036 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
2041 } -returnCodes error -result {bad listbox index "@1x3": must be active, anchor, end, @x,y, or a number}
2042 test listbox-10.11 {GetListboxIndex procedure} -setup {
2046 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
2051 } -returnCodes error -result {bad listbox index "@1,": must be active, anchor, end, @x,y, or a number}
2052 test listbox-10.12 {GetListboxIndex procedure} -setup {
2056 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
2061 } -returnCodes error -result {bad listbox index "@1,foo": must be active, anchor, end, @x,y, or a number}
2062 test listbox-10.13 {GetListboxIndex procedure} -setup {
2066 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
2071 } -returnCodes error -result {bad listbox index "@1,2x": must be active, anchor, end, @x,y, or a number}
2072 test listbox-10.14 {GetListboxIndex procedure} -constraints {
2078 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
2080 list [.l index @5,57] [.l index @5,58]
2086 test listbox-10.15 {GetListboxIndex procedure} -setup {
2090 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
2095 } -returnCodes error -result {bad listbox index "1xy": must be active, anchor, end, @x,y, or a number}
2096 test listbox-10.16 {GetListboxIndex procedure} -setup {
2100 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
2106 test listbox-10.17 {GetListboxIndex procedure} -setup {
2110 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
2116 test listbox-10.18 {GetListboxIndex procedure} -setup {
2120 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
2126 test listbox-10.19 {GetListboxIndex procedure} -setup {
2130 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
2136 test listbox-10.20 {GetListboxIndex procedure} -setup {
2140 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
2149 test listbox-11.1 {ChangeListboxView procedure, boundary conditions for index} -setup {
2152 listbox .l -height 5
2154 .l insert 0 a b c d e f g h i j
2157 set x [.l index @0,0]
2160 lappend x [.l index @0,0]
2164 test listbox-11.2 {ChangeListboxView procedure, boundary conditions for index} -setup {
2167 listbox .l -height 5
2169 .l insert 0 a b c d e f g h i j
2172 set x [.l index @0,0]
2175 lappend x [.l index @0,0]
2179 test listbox-11.3 {ChangeListboxView procedure} -setup {
2182 listbox .l -height 5 -yscrollcommand "record y"
2184 .l insert 0 a b c d e f g h i j
2189 list [format {%.6g %.6g} {*}[.l yview]] $log
2192 } -result {{0.2 0.7} {{y 0.2 0.7}}}
2193 test listbox-11.4 {ChangeListboxView procedure} -setup {
2196 listbox .l -height 5 -yscrollcommand "record y"
2198 .l insert 0 a b c d e f g h i j
2203 list [format {%.6g %.6g} {*}[.l yview]] $log
2206 } -result {{0.5 1} {{y 0.5 1}}}
2207 test listbox-11.5 {ChangeListboxView procedure} -setup {
2210 listbox .l -height 5 -yscrollcommand "record y"
2213 .l insert 0 a b c d e f g h i j
2219 list [format {%.6g %.6g} {*}[.l yview]] $log
2222 } -result {{0.3 0.8} {}}
2223 test listbox-11.6 {ChangeListboxView procedure, partial last line} -body {
2226 .partial.l index @0,0
2232 # Listbox used in 12.* tests
2234 listbox .l -font $fixed -xscrollcommand "record x" -width 10
2235 .l insert 0 0123456789a123456789b123456789c123456789d123456789e123456789f123456789g123456789h123456789i123456789
2238 test listbox-12.1 {ChangeListboxOffset procedure} -constraints {
2244 list [format {%.6g %.6g} {*}[.l xview]] $log
2245 } -result {{0.9 1} {{x 0.9 1}}}
2246 test listbox-12.2 {ChangeListboxOffset procedure} -constraints {
2251 .l xview moveto -.25
2253 list [format {%.6g %.6g} {*}[.l xview]] $log
2254 } -result {{0 0.1} {{x 0 0.1}}}
2255 test listbox-12.3 {ChangeListboxOffset procedure} -constraints {
2263 list [format {%.6g %.6g} {*}[.l xview]] $log
2264 } -result {{0.1 0.2} {}}
2267 # Listbox used in 13.* tests
2269 listbox .l -font $fixed -width 10 -height 5
2271 .l insert 0 a bb c d e f g h i j k l m n o p q r s
2272 .l insert 0 0123456789a123456789b123456789c123456789d123456789
2274 set width [expr [lindex [.l bbox 2] 2] - [lindex [.l bbox 1] 2]]
2275 set height [expr [lindex [.l bbox 2] 1] - [lindex [.l bbox 1] 1]]
2276 test listbox-13.1 {ListboxScanTo procedure} -constraints {
2282 .l scan dragto [expr 10-$width] [expr 20-$height]
2284 list [format {%.6g %.6g} {*}[.l xview]] [format {%.6g %.6g} {*}[.l yview]]
2285 } -result {{0.2 0.4} {0.5 0.75}}
2286 test listbox-13.2 {ListboxScanTo procedure} -constraints {
2292 .l scan dragto 20 40
2294 set x [list [format {%.6g %.6g} {*}[.l xview]] [format {%.6g %.6g} {*}[.l yview]]]
2295 .l scan dragto [expr 20-$width] [expr 40-$height]
2297 lappend x [format {%.6g %.6g} {*}[.l xview]] [format {%.6g %.6g} {*}[.l yview]]
2298 } -result {{0 0.2} {0 0.25} {0.2 0.4} {0.5 0.75}}
2299 test listbox-13.3 {ListboxScanTo procedure} -constraints {
2307 set x [list [format {%.6g %.6g} {*}[.l xview]] [format {%.6g %.6g} {*}[.l yview]]]
2308 .l scan dragto [expr 5+$width] [expr 10+$height]
2310 lappend x [format {%.6g %.6g} {*}[.l xview]] [format {%.6g %.6g} {*}[.l yview]]
2311 } -result {{0.8 1} {0.75 1} {0.6 0.8} {0.25 0.5}}
2314 test listbox-14.1 {NearestListboxElement procedure, partial last line} -body {
2316 .partial.l nearest [winfo height .partial.l]
2318 # Listbox used in 14.* tests
2320 listbox .l -font $fixed -width 20 -height 10
2321 .l insert 0 a b c d e f g h i j k l m n o p q r s t
2325 test listbox-14.2 {NearestListboxElement procedure} -constraints {
2330 test listbox-14.3 {NearestListboxElement procedure} -constraints {
2333 list [.l index @50,35] [.l index @50,36]
2335 test listbox-14.4 {NearestListboxElement procedure} -constraints {
2342 # Listbox used in 15.* 16.* and 17.* tests
2344 listbox .l -font $fixed -width 20 -height 10
2347 test listbox-15.1 {ListboxSelect procedure} -body {
2349 .l insert 0 a b c d e f g h i j k l m n o p
2354 } -result {2 3 8 9 10 11 12}
2355 test listbox-15.2 {ListboxSelect procedure} -setup {
2359 .l insert 0 a b c d e f g h i j k l m n o p
2361 .e insert 0 "This is some text"
2364 .l selection clear 2 4
2365 set x [selection own]
2367 list $x [selection own] [selection get]
2371 test listbox-15.3 {ListboxSelect procedure} -body {
2373 .l selection clear 0 end
2377 test listbox-15.4 {ListboxSelect procedure, boundary conditions for indices} -body {
2379 .l insert 0 a b c d e f
2380 .l select clear 0 end
2384 test listbox-15.5 {ListboxSelect procedure, boundary conditions for indices} -body {
2386 .l insert 0 a b c d e f
2387 .l select clear 0 end
2391 test listbox-15.6 {ListboxSelect procedure, boundary conditions for indices} -body {
2393 .l insert 0 a b c d e f
2394 .l select clear 0 end
2398 test listbox-15.7 {ListboxSelect procedure, boundary conditions for indices} -body {
2400 .l insert 0 a b c d e f
2401 .l select clear 0 end
2405 test listbox-15.8 {ListboxSelect procedure, boundary conditions for indices} -body {
2407 .l insert 0 a b c d e f
2408 .l select clear 0 end
2412 test listbox-15.9 {ListboxSelect procedure, boundary conditions for indices} -body {
2414 .l insert 0 a b c d e f
2415 .l select clear 0 end
2416 .l select set end 30
2419 test listbox-15.10 {ListboxSelect procedure, boundary conditions for indices} -body {
2421 .l insert 0 a b c d e f
2422 .l select clear 0 end
2428 test listbox-16.1 {ListboxFetchSelection procedure} -body {
2430 .l insert 0 a b c "two words" e f g h i \\ k l m n o p
2431 .l selection set 2 4
2433 .l selection set 11 12
2435 } -result "c\ntwo words\ne\n\\\nl\nm"
2436 test listbox-16.2 {ListboxFetchSelection procedure} -body {
2438 .l insert 0 a b c "two words" e f g h i \\ k l m n o p
2441 } -result "two words"
2442 test listbox-16.3 {ListboxFetchSelection procedure, retrieve in several parts} -body {
2443 set long "This is quite a long string\n"
2444 append long $long $long $long $long
2445 append long $long $long $long $long
2446 append long $long $long
2448 .l insert 0 1$long 2$long 3$long 4$long 5$long
2449 .l selection set 0 end
2450 set sel [selection get]
2451 string compare 1$long\n2$long\n3$long\n4$long\n5$long $sel
2453 catch {unset long sel}
2457 test listbox-17.1 {ListboxLostSelection procedure} -setup {
2461 .l insert 0 a b c d e
2464 .e insert 0 "This is some text"
2471 test listbox-17.2 {ListboxLostSelection procedure} -setup {
2475 .l insert 0 a b c d e
2477 .l configure -exportselection 0
2479 .e insert 0 "This is some text"
2485 } -result {0 1 2 3 4}
2488 # Listbox used in 18.* tests
2490 listbox .l -font $fixed -width 10 -height 5
2493 test listbox-18.1 {ListboxUpdateVScrollbar procedure} -body {
2494 .l configure -yscrollcommand "record y"
2498 .l insert end d e f g h
2503 } -result {{y 0 1} {y 0 0.625} {y 0 1}}
2504 test listbox-18.2 {ListboxUpdateVScrollbar procedure, partial last line} -body {
2506 .partial.l configure -yscrollcommand "record y"
2511 } -result {{y 0.2 0.466667}}
2512 test listbox-18.3 {ListboxUpdateVScrollbar procedure} -body {
2515 set x [list $args $errorInfo]
2517 .l configure -yscrollcommand gorp
2523 } -result {{{invalid command name "gorp"}} {invalid command name "gorp"
2526 (vertical scrolling command executed by listbox)}}
2529 # Listbox used in 19.* tests
2531 listbox .l -font $fixed -width 10 -height 5
2534 test listbox-19.1 {ListboxUpdateVScrollbar procedure} -constraints {
2537 .l configure -xscrollcommand "record x"
2541 .l insert 0 "This is a much longer string..."
2546 } -result {{x 0 1} {x 0 0.322581} {x 0 1}}
2547 test listbox-19.2 {ListboxUpdateVScrollbar procedure} -body {
2550 set x [list $args $errorInfo]
2552 .l configure -xscrollcommand bogus
2556 } -result {{{invalid command name "bogus"}} {invalid command name "bogus"
2559 (horizontal scrolling command executed by listbox)}}
2562 test listbox-20.1 {listbox vs hidden commands} -setup {
2565 set l [interp hidden]
2569 set res1 [list [winfo children .] [interp hidden]]
2570 set res2 [list {} $l]
2571 expr {$res1 eq $res2}
2575 # tests for ListboxListVarProc
2576 test listbox-21.1 {ListboxListVarProc} -setup {
2580 listbox .l -listvar x
2581 set x [list a b c d]
2585 } -result [list a b c d]
2586 test listbox-21.2 {ListboxListVarProc} -setup {
2589 set x [list a b c d]
2590 listbox .l -listvar x
2595 } -result [list a b c d]
2596 test listbox-21.3 {ListboxListVarProc} -setup {
2599 set x [list a b c d]
2600 listbox .l -listvar x
2601 .l configure -listvar {}
2607 test listbox-21.4 {ListboxListVarProc} -setup {
2610 set x [list a b c d]
2611 listbox .l -listvar x
2617 test listbox-21.5 {ListboxListVarProc, test selection after listvar mod} -setup {
2620 set x [list a b c d e f g]
2621 listbox .l -listvar x
2622 .l selection set end
2623 set x [list a b c d]
2624 set x [list 0 1 2 3 4 5 6]
2629 test listbox-21.6 {ListboxListVarProc, test selection after listvar mod} -setup {
2632 set x [list a b c d]
2633 listbox .l -listvar x
2640 test listbox-21.7 {ListboxListVarProc, test selection after listvar mod} -setup {
2643 set x [list a b c d]
2644 listbox .l -listvar x
2646 set x [linsert $x 0 1 2 3 4]
2651 test listbox-21.8 {ListboxListVarProc, test selection after listvar mod} -setup {
2654 set x [list a b c d]
2655 listbox .l -listvar x
2662 test listbox-21.9 {ListboxListVarProc, test hscrollbar after listvar mod} -setup {
2666 listbox .l -font $fixed -width 10 -xscrollcommand "record x" -listvar x
2670 lappend x "0000000000"
2672 lappend x "00000000000000000000"
2677 } -result [list {x 0 1} {x 0 0.5}]
2678 test listbox-21.10 {ListboxListVarProc, test hscrollbar after listvar mod} -setup {
2682 listbox .l -font $fixed -width 10 -xscrollcommand "record x" -listvar x
2686 lappend x "0000000000"
2688 lappend x "00000000000000000000"
2690 set x [list "0000000000"]
2695 } -result [list {x 0 1} {x 0 0.5} {x 0 1}]
2696 test listbox-21.11 {ListboxListVarProc, bad list} -setup {
2700 listbox .l -listvar x
2701 set x [list a b c d]
2702 catch {set x "this is a \" bad list"} result
2706 } -result {can't set "x": invalid listvar value}
2707 test listbox-21.12 {ListboxListVarProc, cleanup item attributes} -setup {
2710 set x [list a b c d e f g]
2711 listbox .l -listvar x
2712 .l itemconfigure end -fg red
2713 set x [list a b c d]
2714 set x [list 0 1 2 3 4 5 6]
2719 test listbox-21.12a {ListboxListVarProc, cleanup item attributes} -setup {
2722 set x [list a b c d e f g]
2723 listbox .l -listvar x
2724 .l itemconfigure end -fg red
2725 set x [list a b c d]
2726 set x [list 0 1 2 3 4 5 6]
2731 test listbox-21.13 {listbox item configurations and listvar based deletions} -setup {
2735 listbox .l -listvar x
2737 .l itemconfigure 1 -fg red
2743 test listbox-21.14 {listbox item configurations and listvar based inserts} -setup {
2747 listbox .l -listvar x
2749 .l itemconfigure 0 -fg red
2750 set x [list 1 2 3 4 a b c]
2755 test listbox-21.15 {ListboxListVarProc, update vertical scrollbar} -setup {
2759 listbox .l -font $fixed -height 3 -yscrollcommand "record y" -listvar x
2763 set timeout [after 500 {lappend log timeout3}]
2766 lappend x a b c d e f
2771 after cancel $timeout
2772 } -result [list {y 0 1} {y 0 0.5}]
2773 test listbox-21.16 {ListboxListVarProc, update vertical scrollbar} -setup {
2777 listbox .l -listvar x -height 3
2779 set x [list 0 1 2 3 4 5]
2780 .l yview scroll 3 units
2783 lappend result [format {%.6g %.6g} {*}[.l yview]]
2784 set x [lreplace $x 3 3]
2785 set x [lreplace $x 3 3]
2786 set x [lreplace $x 3 3]
2788 lappend result [format {%.6g %.6g} {*}[.l yview]]
2792 } -result [list {0.5 1} {0 1}]
2796 test listbox-22.1 {UpdateHScrollbar} -setup {
2799 listbox .l -font $fixed -width 10 -xscrollcommand "record x"
2803 set timeout [after 500 {lappend log timeout4}]
2804 .l insert end "0000000000"
2806 .l insert end "00000000000000000000"
2811 after cancel $timeout
2812 } -result [list {x 0 1} {x 0 0.5}]
2815 # ConfigureListboxItem
2816 test listbox-23.1 {ConfigureListboxItem} -setup {
2820 catch {.l itemconfigure 0} result
2824 } -result {item number "0" out of range}
2825 test listbox-23.2 {ConfigureListboxItem} -setup {
2829 .l insert end a b c d
2833 } -result [list {-background background Background {} {}} \
2836 {-foreground foreground Foreground {} {}} \
2837 {-selectbackground selectBackground Foreground {} {}} \
2838 {-selectforeground selectForeground Background {} {}}]
2839 test listbox-23.3 {ConfigureListboxItem, itemco shortcut} -setup {
2843 .l insert end a b c d
2844 .l itemco 0 -background
2847 } -result {-background background Background {} {}}
2848 test listbox-23.4 {ConfigureListboxItem, wrong num args} -setup {
2853 catch {.l itemco} result
2857 } -result {wrong # args: should be ".l itemconfigure index ?-option? ?value? ?-option value ...?"}
2858 test listbox-23.5 {ConfigureListboxItem, multiple calls} -setup {
2863 foreach color {red orange yellow green blue white violet} {
2864 .l insert end $color
2865 .l itemconfigure $i -bg $color
2870 list [.l itemcget 0 -bg] [.l itemcget 1 -bg] [.l itemcget 2 -bg] \
2871 [.l itemcget 3 -bg] [.l itemcget 4 -bg] [.l itemcget 5 -bg] \
2875 } -result {red orange yellow green blue white violet}
2877 # Listbox used in 23.6 -23.17 tests
2880 .l insert end a b c d
2881 test listbox-23.6 {configuration options} -body {
2882 .l itemconfigure 0 -background #ff0000
2883 list [lindex [.l itemconfigure 0 -background] 4] [.l itemcget 0 -background]
2885 .l configure -background #ffffff
2886 } -result {{#ff0000} #ff0000}
2887 test listbox-23.7 {configuration options} -body {
2888 .l configure -background non-existent
2889 } -returnCodes error -result {unknown color name "non-existent"}
2890 test listbox-23.8 {configuration options} -body {
2891 .l itemconfigure 0 -bg #ff0000
2892 list [lindex [.l itemconfigure 0 -bg] 4] [.l itemcget 0 -bg]
2894 .l configure -bg #ffffff
2895 } -result {{#ff0000} #ff0000}
2896 test listbox-23.9 {configuration options} -body {
2897 .l configure -bg non-existent
2898 } -returnCodes error -result {unknown color name "non-existent"}
2899 test listbox-23.10 {configuration options} -body {
2900 .l itemconfigure 0 -fg #110022
2901 list [lindex [.l itemconfigure 0 -fg] 4] [.l itemcget 0 -fg]
2903 .l configure -fg #000000
2904 } -result {{#110022} #110022}
2905 test listbox-23.11 {configuration options} -body {
2906 .l configure -fg bogus
2907 } -returnCodes error -result {unknown color name "bogus"}
2908 test listbox-23.12 {configuration options} -body {
2909 .l itemconfigure 0 -foreground #110022
2910 list [lindex [.l itemconfigure 0 -foreground] 4] [.l itemcget 0 -foreground]
2912 .l configure -foreground #000000
2913 } -result {{#110022} #110022}
2914 test listbox-23.13 {configuration options} -body {
2915 .l configure -foreground bogus
2916 } -returnCodes error -result {unknown color name "bogus"}
2917 test listbox-23.14 {configuration options} -body {
2918 .l itemconfigure 0 -selectbackground #110022
2919 list [lindex [.l itemconfigure 0 -selectbackground] 4] [.l itemcget 0 -selectbackground]
2921 .l configure -selectbackground #c3c3c3
2922 } -result {{#110022} #110022}
2923 test listbox-23.15 {configuration options} -body {
2924 .l configure -selectbackground bogus
2925 } -returnCodes error -result {unknown color name "bogus"}
2926 test listbox-23.16 {configuration options} -body {
2927 .l itemconfigure 0 -selectforeground #654321
2928 list [lindex [.l itemconfigure 0 -selectforeground] 4] [.l itemcget 0 -selectforeground]
2930 .l configure -selectforeground #000000
2931 } -result {{#654321} #654321}
2932 test listbox-23.17 {configuration options} -body {
2933 .l configure -selectforeground bogus
2934 } -returnCodes error -result {unknown color name "bogus"}
2937 # ListboxWidgetObjCmd, itemcget
2938 test listbox-24.1 {itemcget} -setup {
2942 .l insert end a b c d
2947 test listbox-24.2 {itemcget} -setup {
2951 .l insert end a b c d
2952 .l itemconfigure 0 -fg red
2957 test listbox-24.3 {itemcget} -setup {
2961 .l insert end a b c d
2962 catch {.l itemcget 0} result
2966 } -result {wrong # args: should be ".l itemcget index option"}
2967 test listbox-24.4 {itemcget, itemcg shortcut} -setup {
2971 .l insert end a b c d
2972 catch {.l itemcg 0} result
2976 } -result {wrong # args: should be ".l itemcget index option"}
2979 # General item configuration issues
2980 test listbox-25.1 {listbox item configurations and widget based deletions} -setup {
2985 .l itemconfigure 0 -fg red
2992 test listbox-25.2 {listbox item configurations and widget based inserts} -setup {
2997 .l itemconfigure 0 -fg red
2999 list [.l itemcget 0 -fg] [.l itemcget 4 -fg]
3006 test listbox-26.1 {listbox disabled state disallows inserts} -setup {
3011 .l configure -state disabled
3016 } -result [list a b c]
3017 test listbox-26.2 {listbox disabled state disallows deletions} -setup {
3022 .l configure -state disabled
3027 } -result [list a b c]
3028 test listbox-26.3 {listbox disabled state disallows selection modification} -setup {
3035 .l configure -state disabled
3036 .l selection clear 0 end
3041 } -result [list 0 2]
3042 test listbox-26.4 {listbox disabled state disallows anchor modification} -setup {
3047 .l selection anchor 0
3048 .l configure -state disabled
3049 .l selection anchor 2
3054 test listbox-26.5 {listbox disabled state disallows active modification} -setup {
3060 .l configure -state disabled
3068 test listbox-27.1 {widget deletion while active} -setup {
3073 .l configure -cursor xterm -xscrollcommand { destroy .l }
3081 test listbox-28.1 {listbox -activestyle} -setup {
3084 listbox .l -activ non
3085 .l cget -activestyle
3089 test listbox-28.2 {listbox -activestyle} -constraints {
3095 .l cget -activestyle
3099 test listbox-28.3 {listbox -activestyle} -constraints {
3105 .l cget -activestyle
3109 test listbox-28.4 {listbox -activestyle} -setup {
3112 listbox .l -activestyle und
3113 .l cget -activestyle
3119 test listbox-29.1 {listbox selection behavior, -state disabled} -setup {
3125 set out [.l selection includes 2]
3126 .l configure -state disabled
3127 # still return 1 when disabled, because 'selection get' will work,
3128 # but selection cannot be changed (new behavior since 8.4)
3130 lappend out [.l selection includes 2] [.l curselection]
3135 test listbox-30.1 {Bug 3607326} -setup {
3140 listbox .l -listvariable a
3144 } -result * -match glob -returnCodes error
3146 test listbox-31.1 {<<ListboxSelect>> event} -setup {
3148 unset -nocomplain res
3150 pack [listbox .l -state normal]
3152 bind .l <<ListboxSelect>> {lappend res [%W curselection]}
3155 event generate .l <1> -x 5 -y 5 ; # <<ListboxSelect>> fires
3156 .l configure -state disabled
3158 event generate .l <Control-Home> ; # <<ListboxSelect>> does NOT fire
3159 .l configure -state normal
3161 event generate .l <Control-End> ; # <<ListboxSelect>> fires
3162 .l selection clear 0 end ; # <<ListboxSelect>> does NOT fire
3163 .l selection set 1 1 ; # <<ListboxSelect>> does NOT fire
3164 lappend res [.l curselection]
3167 unset -nocomplain res
3170 test listbox-31.2 {<<ListboxSelect>> event on lost selection} -setup {
3173 pack [listbox .l -exportselection true]
3175 bind .l <<ListboxSelect>> {lappend res [list [selection own] [%W curselection]]}
3178 event generate .l <1> -x 5 -y 5 ; # <<ListboxSelect>> fires
3179 selection clear ; # <<ListboxSelect>> fires again
3184 } -result {{.l 0} {{} {}}}
3186 test listbox-32.1 {Bug [5d991b822e]} {
3187 # Want this not to segfault, or write to variable with empty name
3189 listbox .b -listvariable var
3190 trace add variable var unset {apply {args {
3191 .b configure -listvariable {}
3194 bind .b <Configure> {unset var}
3199 test listbox-32.2 {Bug [5d991b822e]} {
3200 # Want this not to leak traces
3202 listbox .b -listvariable var
3203 trace add variable var unset {apply {args {
3204 .b configure -listvariable new
3207 bind .b <Configure> {unset -nocomplain var}