OSDN Git Service

touched all tk files to ease next import
[pf3gnuchains/pf3gnuchains4x.git] / tk / tests / listbox.test
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.
3 #
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.
7 # All rights reserved.
8 #
9 # RCS: @(#) $Id$
10
11 if {[lsearch [namespace children] ::tcltest] == -1} {
12     source [file join [pwd] [file dirname [info script]] defs.tcl]
13 }
14
15 foreach i [winfo children .] {
16     destroy $i
17 }
18 wm geometry . {}
19 raise .
20 set fixed {Courier -12}
21
22 proc record args {
23     global log
24     lappend log $args
25 }
26
27 proc getsize w {
28     regexp {(^[^+-]*)} [wm geometry $w] foo x
29     return $x
30 }
31
32 proc resetGridInfo {} {
33     # Some window managers, such as mwm, don't reset gridding information
34     # unless the window is withdrawn and re-mapped.  If this procedure
35     # isn't invoked, the window manager will stay in gridded mode, which
36     # can cause all sorts of problems.  The "wm positionfrom" command is
37     # needed so that the window manager doesn't ask the user to
38     # manually position the window when it is re-mapped.
39
40     wm withdraw .
41     wm positionfrom . user
42     wm deiconify .
43 }
44
45 # Procedure that creates a second listbox for checking things related
46 # to partially visible lines.
47
48 proc mkPartial {{w .partial}} {
49     catch {destroy $w}
50     toplevel $w
51     wm geometry $w +0+0
52     listbox $w.l -width 30 -height 5
53     pack $w.l -expand 1 -fill both
54     $w.l insert end one two three four five six seven eight nine ten \
55             eleven twelve thirteen fourteen fifteen
56     update
57     scan [wm geometry $w] "%dx%d" width height
58     wm geometry $w ${width}x[expr $height-3]
59     update
60 }
61
62 # Create entries in the option database to be sure that geometry options
63 # like border width have predictable values.
64
65 option add *Listbox.borderWidth 2
66 option add *Listbox.highlightThickness 2
67 option add *Listbox.font {Helvetica -12 bold}
68
69 listbox .l
70 pack .l
71 update
72 resetGridInfo
73 set i 1
74
75 foreach test {
76     {-background #ff0000 #ff0000 non-existent
77             {unknown color name "non-existent"}}
78     {-bd 4 4 badValue {bad screen distance "badValue"}}
79     {-bg #ff0000 #ff0000 non-existent {unknown color name "non-existent"}}
80     {-borderwidth 1.3 1 badValue {bad screen distance "badValue"}}
81     {-cursor arrow arrow badValue {bad cursor spec "badValue"}}
82     {-exportselection yes 1 xyzzy {expected boolean value but got "xyzzy"}}
83     {-fg #110022 #110022 bogus {unknown color name "bogus"}}
84     {-font {Helvetica 12} {Helvetica 12} {} {font "" doesn't exist}}
85     {-foreground #110022 #110022 bogus {unknown color name "bogus"}}
86     {-height 30 30 20p {expected integer but got "20p"}}
87     {-highlightbackground #112233 #112233 ugly {unknown color name "ugly"}}
88     {-highlightcolor #123456 #123456 bogus {unknown color name "bogus"}}
89     {-highlightthickness 6 6 bogus {bad screen distance "bogus"}}
90     {-highlightthickness -2 0 {} {}}
91     {-relief groove groove 1.5 {bad relief "1.5": must be flat, groove, raised, ridge, solid, or sunken}}
92     {-selectbackground #110022 #110022 bogus {unknown color name "bogus"}}
93     {-selectborderwidth 1.3 1 badValue {bad screen distance "badValue"}}
94     {-selectforeground #654321 #654321 bogus {unknown color name "bogus"}}
95     {-selectmode string string {} {}}
96     {-setgrid false 0 lousy {expected boolean value but got "lousy"}}
97     {-takefocus "any string" "any string" {} {}}
98     {-width 45 45 3p {expected integer but got "3p"}}
99     {-xscrollcommand {Some command} {Some command} {} {}}
100     {-yscrollcommand {Another command} {Another command} {} {}}
101     {-listvar testVariable testVariable {} {}}
102 } {
103     set name [lindex $test 0]
104     test listbox-1.$i {configuration options} {
105         .l configure $name [lindex $test 1]
106         list [lindex [.l configure $name] 4] [.l cget $name]
107     } [list [lindex $test 2] [lindex $test 2]]
108     incr i
109     if {[lindex $test 3] != ""} {
110         test listbox-1.$i {configuration options} {
111             list [catch {.l configure $name [lindex $test 3]} msg] $msg
112         } [list 1 [lindex $test 4]]
113     }
114     .l configure $name [lindex [.l configure $name] 3]
115     incr i
116 }
117
118 test listbox-2.1 {Tk_ListboxCmd procedure} {
119     list [catch {listbox} msg] $msg
120 } {1 {wrong # args: should be "listbox pathName ?options?"}}
121 test listbox-2.2 {Tk_ListboxCmd procedure} {
122     list [catch {listbox gorp} msg] $msg
123 } {1 {bad window path name "gorp"}}
124 test listbox-2.3 {Tk_ListboxCmd procedure} {
125     catch {destroy .l}
126     listbox .l
127     list [winfo exists .l] [winfo class .l] [info commands .l]
128 } {1 Listbox .l}
129 test listbox-2.4 {Tk_ListboxCmd procedure} {
130     catch {destroy .l}
131     list [catch {listbox .l -gorp foo} msg] $msg [winfo exists .l] \
132             [info commands .l]
133 } {1 {unknown option "-gorp"} 0 {}}
134 test listbox-2.5 {Tk_ListboxCmd procedure} {
135     catch {destroy .l}
136     listbox .l
137 } {.l}
138
139 catch {destroy .l}
140 listbox .l -width 20 -height 5 -bd 4 -highlightthickness 1 -selectborderwidth 2
141 pack .l
142 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11 el12 el13 el14 \
143         el15 el16 el17
144 update
145 test listbox-3.1 {ListboxWidgetCmd procedure} {
146     list [catch .l msg] $msg
147 } {1 {wrong # args: should be ".l option ?arg arg ...?"}}
148 test listbox-3.2 {ListboxWidgetCmd procedure, "activate" option} {
149     list [catch {.l activate} msg] $msg
150 } {1 {wrong # args: should be ".l activate index"}}
151 test listbox-3.3 {ListboxWidgetCmd procedure, "activate" option} {
152     list [catch {.l activate a b} msg] $msg
153 } {1 {wrong # args: should be ".l activate index"}}
154 test listbox-3.4 {ListboxWidgetCmd procedure, "activate" option} {
155     list [catch {.l activate fooey} msg] $msg
156 } {1 {bad listbox index "fooey": must be active, anchor, end, @x,y, or a number}}
157 test listbox-3.5 {ListboxWidgetCmd procedure, "activate" option} {
158     .l activate 3
159     .l index active
160 } 3
161 test listbox-3.6 {ListboxWidgetCmd procedure, "activate" option} {
162     .l activate -1
163     .l index active
164 } {0}
165 test listbox-3.7 {ListboxWidgetCmd procedure, "activate" option} {
166     .l activate 30
167     .l index active
168 } {17}
169 test listbox-3.8 {ListboxWidgetCmd procedure, "activate" option} {
170     .l activate end
171     .l index active
172 } {17}
173 test listbox-3.9 {ListboxWidgetCmd procedure, "bbox" option} {
174     list [catch {.l bbox} msg] $msg
175 } {1 {wrong # args: should be ".l bbox index"}}
176 test listbox-3.10 {ListboxWidgetCmd procedure, "bbox" option} {
177     list [catch {.l bbox a b} msg] $msg
178 } {1 {wrong # args: should be ".l bbox index"}}
179 test listbox-3.11 {ListboxWidgetCmd procedure, "bbox" option} {
180     list [catch {.l bbox fooey} msg] $msg
181 } {1 {bad listbox index "fooey": must be active, anchor, end, @x,y, or a number}}
182 test listbox-3.12 {ListboxWidgetCmd procedure, "bbox" option} {
183     .l yview 3
184     update
185     list [.l bbox 2] [.l bbox 8]
186 } {{} {}}
187 test listbox-3.13 {ListboxWidgetCmd procedure, "bbox" option} {
188     # Used to generate a core dump before a bug was fixed (the last
189     # element would be on-screen if it existed, but it doesn't exist).
190
191     listbox .l2
192     pack .l2 -side top
193     tkwait visibility .l2
194     set x [.l2 bbox 0]
195     destroy .l2
196     set x
197 } {}
198 test listbox-3.14 {ListboxWidgetCmd procedure, "bbox" option} {fonts} {
199     .l yview 3
200     update
201     list [.l bbox 3] [.l bbox 4]
202 } {{7 7 17 14} {7 26 17 14}}
203 test listbox-3.15 {ListboxWidgetCmd procedure, "bbox" option} {fonts} {
204     .l yview 0
205     update
206     list [.l bbox -1] [.l bbox 0]
207 } {{} {7 7 17 14}}
208 test listbox-3.16 {ListboxWidgetCmd procedure, "bbox" option} {fonts} {
209     .l yview end
210     update
211     list [.l bbox 17] [.l bbox end] [.l bbox 18]
212 } {{7 83 24 14} {7 83 24 14} {}}
213 test listbox-3.17 {ListboxWidgetCmd procedure, "bbox" option} {fonts} {
214     catch {destroy .t}
215     toplevel .t
216     wm geom .t +0+0
217     listbox .t.l -width 10 -height 5
218     .t.l insert 0 "Short" "Somewhat longer" "Really, quite a whole lot longer than can possibly fit on the screen" "Short"
219     pack .t.l
220     update
221     .t.l xview moveto .2
222     .t.l bbox 2
223 } {-72 39 393 14}
224 test listbox-3.18 {ListboxWidgetCmd procedure, "bbox" option, partial last line} {fonts} {
225     mkPartial
226     list [.partial.l bbox 3] [.partial.l bbox 4]
227 } {{5 56 24 14} {5 73 23 14}}
228 test listbox-3.19 {ListboxWidgetCmd procedure, "cget" option} {
229     list [catch {.l cget} msg] $msg
230 } {1 {wrong # args: should be ".l cget option"}}
231 test listbox-3.20 {ListboxWidgetCmd procedure, "cget" option} {
232     list [catch {.l cget a b} msg] $msg
233 } {1 {wrong # args: should be ".l cget option"}}
234 test listbox-3.21 {ListboxWidgetCmd procedure, "cget" option} {
235     list [catch {.l cget -gorp} msg] $msg
236 } {1 {unknown option "-gorp"}}
237 test listbox-3.22 {ListboxWidgetCmd procedure, "cget" option} {
238     .l cget -setgrid
239 } {0}
240 test listbox-3.23 {ListboxWidgetCmd procedure, "configure" option} {
241     llength [.l configure]
242 } {24}
243 test listbox-3.24 {ListboxWidgetCmd procedure, "configure" option} {
244     list [catch {.l configure -gorp} msg] $msg
245 } {1 {unknown option "-gorp"}}
246 test listbox-3.25 {ListboxWidgetCmd procedure, "configure" option} {
247     .l configure -setgrid
248 } {-setgrid setGrid SetGrid 0 0}
249 test listbox-3.26 {ListboxWidgetCmd procedure, "configure" option} {
250     list [catch {.l configure -gorp is_messy} msg] $msg
251 } {1 {unknown option "-gorp"}}
252 test listbox-3.27 {ListboxWidgetCmd procedure, "configure" option} {
253     set oldbd [.l cget -bd]
254     set oldht [.l cget -highlightthickness]
255     .l configure -bd 3 -highlightthickness 0
256     set x "[.l cget -bd] [.l cget -highlightthickness]"
257     .l configure -bd $oldbd -highlightthickness $oldht
258     set x
259 } {3 0}
260 test listbox-3.28 {ListboxWidgetCmd procedure, "curselection" option} {
261     list [catch {.l curselection a} msg] $msg
262 } {1 {wrong # args: should be ".l curselection"}}
263 test listbox-3.29 {ListboxWidgetCmd procedure, "curselection" option} {
264     .l selection clear 0 end
265     .l selection set 3 6
266     .l selection set 9
267     .l curselection
268 } {3 4 5 6 9}
269 test listbox-3.30 {ListboxWidgetCmd procedure, "delete" option} {
270     list [catch {.l delete} msg] $msg
271 } {1 {wrong # args: should be ".l delete firstIndex ?lastIndex?"}}
272 test listbox-3.31 {ListboxWidgetCmd procedure, "delete" option} {
273     list [catch {.l delete a b c} msg] $msg
274 } {1 {wrong # args: should be ".l delete firstIndex ?lastIndex?"}}
275 test listbox-3.32 {ListboxWidgetCmd procedure, "delete" option} {
276     list [catch {.l delete badIndex} msg] $msg
277 } {1 {bad listbox index "badIndex": must be active, anchor, end, @x,y, or a number}}
278 test listbox-3.33 {ListboxWidgetCmd procedure, "delete" option} {
279     list [catch {.l delete 2 123ab} msg] $msg
280 } {1 {bad listbox index "123ab": must be active, anchor, end, @x,y, or a number}}
281 test listbox-3.34 {ListboxWidgetCmd procedure, "delete" option} {
282     catch {destroy .l2}
283     listbox .l2
284     .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
285     .l2 delete 3
286     list [.l2 get 2] [.l2 get 3] [.l2 index end]
287 } {el2 el4 7}
288 test listbox-3.35 {ListboxWidgetCmd procedure, "delete" option} {
289     catch {destroy .l2}
290     listbox .l2
291     .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
292     .l2 delete 2 4
293     list [.l2 get 1] [.l2 get 2] [.l2 index end]
294 } {el1 el5 5}
295 test listbox-3.36 {ListboxWidgetCmd procedure, "delete" option} {
296     catch {destroy .l2}
297     listbox .l2
298     .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
299     .l2 delete -3 2
300     .l2 get 0 end
301 } {el3 el4 el5 el6 el7}
302 test listbox-3.37 {ListboxWidgetCmd procedure, "delete" option} {
303     catch {destroy .l2}
304     listbox .l2
305     .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
306     .l2 delete -3 -1
307     .l2 get 0 end
308 } {el0 el1 el2 el3 el4 el5 el6 el7}
309 test listbox-3.38 {ListboxWidgetCmd procedure, "delete" option} {
310     catch {destroy .l2}
311     listbox .l2
312     .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
313     .l2 delete 2 end
314     .l2 get 0 end
315 } {el0 el1}
316 test listbox-3.39 {ListboxWidgetCmd procedure, "delete" option} {
317     catch {destroy .l2}
318     listbox .l2
319     .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
320     .l2 delete 5 20
321     .l2 get 0 end
322 } {el0 el1 el2 el3 el4}
323 test listbox-3.40 {ListboxWidgetCmd procedure, "delete" option} {
324     catch {destroy .l2}
325     listbox .l2
326     .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
327     .l2 delete end 20
328     .l2 get 0 end
329 } {el0 el1 el2 el3 el4 el5 el6}
330 test listbox-3.41 {ListboxWidgetCmd procedure, "delete" option} {
331     catch {destroy .l2}
332     listbox .l2
333     .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
334     .l2 delete 8 20
335     .l2 get 0 end
336 } {el0 el1 el2 el3 el4 el5 el6 el7}
337 test listbox-3.42 {ListboxWidgetCmd procedure, "get" option} {
338     list [catch {.l get} msg] $msg
339 } {1 {wrong # args: should be ".l get firstIndex ?lastIndex?"}}
340 test listbox-3.43 {ListboxWidgetCmd procedure, "get" option} {
341     list [catch {.l get a b c} msg] $msg
342 } {1 {wrong # args: should be ".l get firstIndex ?lastIndex?"}}
343 test listbox-3.44 {ListboxWidgetCmd procedure, "get" option} {
344     list [catch {.l get 2.4} msg] $msg
345 } {1 {bad listbox index "2.4": must be active, anchor, end, @x,y, or a number}}
346 test listbox-3.45 {ListboxWidgetCmd procedure, "get" option} {
347     list [catch {.l get end bogus} msg] $msg
348 } {1 {bad listbox index "bogus": must be active, anchor, end, @x,y, or a number}}
349 test listbox-3.46 {ListboxWidgetCmd procedure, "get" option} {
350     catch {destroy .l2}
351     listbox .l2
352     .l2 insert 0 el0 el1 el2 el3 el4 el5 el6 el7
353     list [.l2 get 0] [.l2 get 3] [.l2 get end]
354 } {el0 el3 el7}
355 test listbox-3.47 {ListboxWidgetCmd procedure, "get" option} {
356     catch {destroy .l2}
357     listbox .l2
358     list [.l2 get 0] [.l2 get end]
359 } {{} {}}
360 test listbox-3.48 {ListboxWidgetCmd procedure, "get" option} {
361     catch {destroy .l2}
362     listbox .l2
363     .l2 insert 0 el0 el1 el2 "two words" el4 el5 el6 el7
364     .l2 get 3 end
365 } {{two words} el4 el5 el6 el7}
366 test listbox-3.49 {ListboxWidgetCmd procedure, "get" option} {
367     .l get -1
368 } {}
369 test listbox-3.50 {ListboxWidgetCmd procedure, "get" option} {
370     .l get -2 -1
371 } {}
372 test listbox-3.51 {ListboxWidgetCmd procedure, "get" option} {
373     .l get -2 3
374 } {el0 el1 el2 el3}
375 test listbox-3.52 {ListboxWidgetCmd procedure, "get" option} {
376     .l get 12 end
377 } {el12 el13 el14 el15 el16 el17}
378 test listbox-3.53 {ListboxWidgetCmd procedure, "get" option} {
379     .l get 12 20
380 } {el12 el13 el14 el15 el16 el17}
381 test listbox-3.54 {ListboxWidgetCmd procedure, "get" option} {
382     .l get end
383 } {el17}
384 test listbox-3.55 {ListboxWidgetCmd procedure, "get" option} {
385     .l get 30
386 } {}
387 test listbox-3.56 {ListboxWidgetCmd procedure, "get" option} {
388     .l get 30 35
389 } {}
390 test listbox-3.57 {ListboxWidgetCmd procedure, "index" option} {
391     list [catch {.l index} msg] $msg
392 } {1 {wrong # args: should be ".l index index"}}
393 test listbox-3.58 {ListboxWidgetCmd procedure, "index" option} {
394     list [catch {.l index a b} msg] $msg
395 } {1 {wrong # args: should be ".l index index"}}
396 test listbox-3.59 {ListboxWidgetCmd procedure, "index" option} {
397     list [catch {.l index @} msg] $msg
398 } {1 {bad listbox index "@": must be active, anchor, end, @x,y, or a number}}
399 test listbox-3.60 {ListboxWidgetCmd procedure, "index" option} {
400     .l index 2
401 } 2
402 test listbox-3.61 {ListboxWidgetCmd procedure, "index" option} {
403     .l index -1
404 } -1
405 test listbox-3.62 {ListboxWidgetCmd procedure, "index" option} {
406     .l index end
407 } 18
408 test listbox-3.63 {ListboxWidgetCmd procedure, "index" option} {
409     .l index 34
410 } 34
411 test listbox-3.64 {ListboxWidgetCmd procedure, "insert" option} {
412     list [catch {.l insert} msg] $msg
413 } {1 {wrong # args: should be ".l insert index ?element element ...?"}}
414 test listbox-3.65 {ListboxWidgetCmd procedure, "insert" option} {
415     list [catch {.l insert badIndex} msg] $msg
416 } {1 {bad listbox index "badIndex": must be active, anchor, end, @x,y, or a number}}
417 test listbox-3.66 {ListboxWidgetCmd procedure, "insert" option} {
418     catch {destroy .l2}
419     listbox .l2
420     .l2 insert end a b c d e
421     .l2 insert 3 x y z
422     .l2 get 0 end
423 } {a b c x y z d e}
424 test listbox-3.67 {ListboxWidgetCmd procedure, "insert" option} {
425     catch {destroy .l2}
426     listbox .l2
427     .l2 insert end a b c
428     .l2 insert -1 x
429     .l2 get 0 end
430 } {x a b c}
431 test listbox-3.68 {ListboxWidgetCmd procedure, "insert" option} {
432     catch {destroy .l2}
433     listbox .l2
434     .l2 insert end a b c
435     .l2 insert end x
436     .l2 get 0 end
437 } {a b c x}
438 test listbox-3.69 {ListboxWidgetCmd procedure, "insert" option} {
439     catch {destroy .l2}
440     listbox .l2
441     .l2 insert end a b c
442     .l2 insert 43 x
443     .l2 get 0 end
444 } {a b c x}
445 test listbox-3.70 {ListboxWidgetCmd procedure, "nearest" option} {
446     list [catch {.l nearest} msg] $msg
447 } {1 {wrong # args: should be ".l nearest y"}}
448 test listbox-3.71 {ListboxWidgetCmd procedure, "nearest" option} {
449     list [catch {.l nearest a b} msg] $msg
450 } {1 {wrong # args: should be ".l nearest y"}}
451 test listbox-3.72 {ListboxWidgetCmd procedure, "nearest" option} {
452     list [catch {.l nearest 20p} msg] $msg
453 } {1 {expected integer but got "20p"}}
454 test listbox-3.73 {ListboxWidgetCmd procedure, "nearest" option} {
455     .l yview 3
456     .l nearest 1000
457 } {7}
458 test listbox-3.74 {ListboxWidgetCmd procedure, "scan" option} {
459     list [catch {.l scan a b} msg] $msg
460 } {1 {wrong # args: should be ".l scan mark|dragto x y"}}
461 test listbox-3.75 {ListboxWidgetCmd procedure, "scan" option} {
462     list [catch {.l scan a b c d} msg] $msg
463 } {1 {wrong # args: should be ".l scan mark|dragto x y"}}
464 test listbox-3.76 {ListboxWidgetCmd procedure, "scan" option} {
465     list [catch {.l scan foo bogus 2} msg] $msg
466 } {1 {expected integer but got "bogus"}}
467 test listbox-3.77 {ListboxWidgetCmd procedure, "scan" option} {
468     list [catch {.l scan foo 2 2.3} msg] $msg
469 } {1 {expected integer but got "2.3"}}
470 test listbox-3.78 {ListboxWidgetCmd procedure, "scan" option} {fonts} {
471     catch {destroy .t}
472     toplevel .t
473     wm geom .t +0+0
474     listbox .t.l -width 10 -height 5
475     .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
476     pack .t.l
477     update
478     .t.l scan mark 100 140
479     .t.l scan dragto 90 137
480     update
481     list [.t.l xview] [.t.l yview]
482 } {{0.249364 0.427481} {0.0714286 0.428571}}
483 test listbox-3.79 {ListboxWidgetCmd procedure, "scan" option} {
484     list [catch {.l scan foo 2 4} msg] $msg
485 } {1 {bad option "foo": must be mark or dragto}}
486 test listbox-3.80 {ListboxWidgetCmd procedure, "see" option} {
487     list [catch {.l see} msg] $msg
488 } {1 {wrong # args: should be ".l see index"}}
489 test listbox-3.81 {ListboxWidgetCmd procedure, "see" option} {
490     list [catch {.l see a b} msg] $msg
491 } {1 {wrong # args: should be ".l see index"}}
492 test listbox-3.82 {ListboxWidgetCmd procedure, "see" option} {
493     list [catch {.l see gorp} msg] $msg
494 } {1 {bad listbox index "gorp": must be active, anchor, end, @x,y, or a number}}
495 test listbox-3.83 {ListboxWidgetCmd procedure, "see" option} {
496     .l yview 7
497     .l see 7
498     .l index @0,0
499 } {7}
500 test listbox-3.84 {ListboxWidgetCmd procedure, "see" option} {
501     .l yview 7
502     .l see 11
503     .l index @0,0
504 } {7}
505 test listbox-3.85 {ListboxWidgetCmd procedure, "see" option} {
506     .l yview 7
507     .l see 6
508     .l index @0,0
509 } {6}
510 test listbox-3.86 {ListboxWidgetCmd procedure, "see" option} {
511     .l yview 7
512     .l see 5
513     .l index @0,0
514 } {3}
515 test listbox-3.87 {ListboxWidgetCmd procedure, "see" option} {
516     .l yview 7
517     .l see 12
518     .l index @0,0
519 } {8}
520 test listbox-3.88 {ListboxWidgetCmd procedure, "see" option} {
521     .l yview 7
522     .l see 13
523     .l index @0,0
524 } {11}
525 test listbox-3.89 {ListboxWidgetCmd procedure, "see" option} {
526     .l yview 7
527     .l see -1
528     .l index @0,0
529 } {0}
530 test listbox-3.90 {ListboxWidgetCmd procedure, "see" option} {
531     .l yview 7
532     .l see end
533     .l index @0,0
534 } {13}
535 test listbox-3.91 {ListboxWidgetCmd procedure, "see" option} {
536     .l yview 7
537     .l see 322
538     .l index @0,0
539 } {13}
540 test listbox-3.92 {ListboxWidgetCmd procedure, "see" option, partial last line} {
541     mkPartial
542     .partial.l see 4
543     .partial.l index @0,0
544 } {1}
545 test listbox-3.93 {ListboxWidgetCmd procedure, "selection" option} {
546     list [catch {.l select a} msg] $msg
547 } {1 {wrong # args: should be ".l selection option index ?index?"}}
548 test listbox-3.94 {ListboxWidgetCmd procedure, "selection" option} {
549     list [catch {.l select a b c d} msg] $msg
550 } {1 {wrong # args: should be ".l selection option index ?index?"}}
551 test listbox-3.95 {ListboxWidgetCmd procedure, "selection" option} {
552     list [catch {.l selection a bogus} msg] $msg
553 } {1 {bad listbox index "bogus": must be active, anchor, end, @x,y, or a number}}
554 test listbox-3.96 {ListboxWidgetCmd procedure, "selection" option} {
555     list [catch {.l selection a 0 lousy} msg] $msg
556 } {1 {bad listbox index "lousy": must be active, anchor, end, @x,y, or a number}}
557 test listbox-3.97 {ListboxWidgetCmd procedure, "selection" option} {
558     list [catch {.l selection anchor 0 0} msg] $msg
559 } {1 {wrong # args: should be ".l selection anchor index"}}
560 test listbox-3.98 {ListboxWidgetCmd procedure, "selection" option} {
561     list [.l selection anchor 5; .l index anchor] \
562             [.l selection anchor 0; .l index anchor]
563 } {5 0}
564 test listbox-3.99 {ListboxWidgetCmd procedure, "selection" option} {
565     .l selection anchor -1
566     .l index anchor
567 } {0}
568 test listbox-3.100 {ListboxWidgetCmd procedure, "selection" option} {
569     .l selection anchor end
570     .l index anchor
571 } {17}
572 test listbox-3.101 {ListboxWidgetCmd procedure, "selection" option} {
573     .l selection anchor 44
574     .l index anchor
575 } {17}
576 test listbox-3.102 {ListboxWidgetCmd procedure, "selection" option} {
577     .l selection clear 0 end
578     .l selection set 2 8
579     .l selection clear 3 4
580     .l curselection
581 } {2 5 6 7 8}
582 test listbox-3.103 {ListboxWidgetCmd procedure, "selection" option} {
583     list [catch {.l selection includes 0 0} msg] $msg
584 } {1 {wrong # args: should be ".l selection includes index"}}
585 test listbox-3.104 {ListboxWidgetCmd procedure, "selection" option} {
586     .l selection clear 0 end
587     .l selection set 2 8
588     .l selection clear 4
589     list [.l selection includes 3] [.l selection includes 4] \
590             [.l selection includes 5]
591 } {1 0 1}
592 test listbox-3.105 {ListboxWidgetCmd procedure, "selection" option} {
593     .l selection set 0 end
594     .l selection includes -1
595 } {0}
596 test listbox-3.106 {ListboxWidgetCmd procedure, "selection" option} {
597     .l selection clear 0 end
598     .l selection set end
599     .l selection includes end
600 } {1}
601 test listbox-3.107 {ListboxWidgetCmd procedure, "selection" option} {
602     .l selection set 0 end
603     .l selection includes 44
604 } {0}
605 test listbox-3.108 {ListboxWidgetCmd procedure, "selection" option} {
606     catch {destroy .l2}
607     listbox .l2
608     .l2 selection includes 0
609 } {0}
610 test listbox-3.109 {ListboxWidgetCmd procedure, "selection" option} {
611     .l selection clear 0 end
612     .l selection set 2
613     .l selection set 5 7
614     .l curselection
615 } {2 5 6 7}
616 test listbox-3.110 {ListboxWidgetCmd procedure, "selection" option} {
617     .l selection set 5 7
618     .l curselection
619 } {2 5 6 7}
620 test listbox-3.111 {ListboxWidgetCmd procedure, "selection" option} {
621     list [catch {.l selection badOption 0 0} msg] $msg
622 } {1 {bad option "badOption": must be anchor, clear, includes, or set}}
623 test listbox-3.112 {ListboxWidgetCmd procedure, "size" option} {
624     list [catch {.l size a} msg] $msg
625 } {1 {wrong # args: should be ".l size"}}
626 test listbox-3.113 {ListboxWidgetCmd procedure, "size" option} {
627     .l size
628 } {18}
629 test listbox-3.114 {ListboxWidgetCmd procedure, "xview" option} {
630     catch {destroy .l2}
631     listbox .l2
632     update
633     .l2 xview
634 } {0 1}
635 test listbox-3.115 {ListboxWidgetCmd procedure, "xview" option} {
636     catch {destroy .l}
637     listbox .l -width 10 -height 5 -font $fixed
638     .l insert 0 a b c d e f g h i j k l m n o p q r s t
639     pack .l
640     update
641     .l xview
642 } {0 1}
643 catch {destroy .l}
644 listbox .l -width 10 -height 5 -font $fixed
645 .l insert 0 a b c d e f g h i j k l m n o p q r s t
646 .l insert 1 "0123456789a123456789b123456789c123456789d123456789"
647 pack .l
648 update
649 test listbox-3.116 {ListboxWidgetCmd procedure, "xview" option} {fonts} {
650     .l xview 4
651     .l xview
652 } {0.08 0.28}
653 test listbox-3.117 {ListboxWidgetCmd procedure, "xview" option} {
654     list [catch {.l xview foo} msg] $msg
655 } {1 {expected integer but got "foo"}}
656 test listbox-3.118 {ListboxWidgetCmd procedure, "xview" option} {
657     list [catch {.l xview zoom a b} msg] $msg
658 } {1 {unknown option "zoom": must be moveto or scroll}}
659 test listbox-3.119 {ListboxWidgetCmd procedure, "xview" option} {fonts} {
660     .l xview 0
661     .l xview moveto .4
662     update
663     .l xview
664 } {0.4 0.6}
665 test listbox-3.120 {ListboxWidgetCmd procedure, "xview" option} {fonts} {
666     .l xview 0
667     .l xview scroll 2 units
668     update
669     .l xview
670 } {0.04 0.24}
671 test listbox-3.121 {ListboxWidgetCmd procedure, "xview" option} {fonts} {
672     .l xview 30
673     .l xview scroll -1 pages
674     update
675     .l xview
676 } {0.44 0.64}
677 test listbox-3.122 {ListboxWidgetCmd procedure, "xview" option} {fonts} {
678     .l configure -width 1
679     update
680     .l xview 30
681     .l xview scroll -4 pages
682     update
683     .l xview
684 } {0.52 0.54}
685 test listbox-3.123 {ListboxWidgetCmd procedure, "yview" option} {
686     catch {destroy .l}
687     listbox .l
688     pack  .l
689     update
690     .l yview
691 } {0 1}
692 test listbox-3.124 {ListboxWidgetCmd procedure, "yview" option} {
693     catch {destroy .l}
694     listbox .l
695     .l insert 0 el1
696     pack  .l
697     update
698     .l yview
699 } {0 1}
700 catch {destroy .l}
701 listbox .l -width 10 -height 5 -font $fixed
702 .l insert 0 a b c d e f g h i j k l m n o p q r s t
703 pack .l
704 update
705 test listbox-3.125 {ListboxWidgetCmd procedure, "yview" option} {
706     .l yview 4
707     update
708     .l yview
709 } {0.2 0.45}
710 test listbox-3.126 {ListboxWidgetCmd procedure, "yview" option, partial last line} {
711     mkPartial
712     .partial.l yview
713 } {0 0.266667}
714 test listbox-3.127 {ListboxWidgetCmd procedure, "xview" option} {
715     list [catch {.l yview foo} msg] $msg
716 } {1 {bad listbox index "foo": must be active, anchor, end, @x,y, or a number}}
717 test listbox-3.128 {ListboxWidgetCmd procedure, "xview" option} {
718     list [catch {.l yview foo a b} msg] $msg
719 } {1 {unknown option "foo": must be moveto or scroll}}
720 test listbox-3.129 {ListboxWidgetCmd procedure, "xview" option} {
721     .l yview 0
722     .l yview moveto .31
723     .l yview
724 } {0.3 0.55}
725 test listbox-3.130 {ListboxWidgetCmd procedure, "xview" option} {
726     .l yview 2
727     .l yview scroll 2 pages
728     .l yview
729 } {0.4 0.65}
730 test listbox-3.131 {ListboxWidgetCmd procedure, "xview" option} {
731     .l yview 10
732     .l yview scroll -3 units
733     .l yview
734 } {0.35 0.6}
735 test listbox-3.132 {ListboxWidgetCmd procedure, "xview" option} {
736     .l configure -height 2
737     update
738     .l yview 15
739     .l yview scroll -4 pages
740     .l yview
741 } {0.55 0.65}
742 test listbox-3.133 {ListboxWidgetCmd procedure, "xview" option} {
743     list [catch {.l whoknows} msg] $msg
744 } {1 {bad option "whoknows": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}}
745 test listbox-3.134 {ListboxWidgetCmd procedure, "xview" option} {
746     list [catch {.l c} msg] $msg
747 } {1 {ambiguous option "c": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}}
748 test listbox-3.135 {ListboxWidgetCmd procedure, "xview" option} {
749     list [catch {.l in} msg] $msg
750 } {1 {ambiguous option "in": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}}
751 test listbox-3.136 {ListboxWidgetCmd procedure, "xview" option} {
752     list [catch {.l s} msg] $msg
753 } {1 {ambiguous option "s": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}}
754 test listbox-3.137 {ListboxWidgetCmd procedure, "xview" option} {
755     list [catch {.l se} msg] $msg
756 } {1 {ambiguous option "se": must be activate, bbox, cget, configure, curselection, delete, get, index, insert, itemcget, itemconfigure, nearest, scan, see, selection, size, xview, or yview}}
757
758 # No tests for DestroyListbox:  I can't come up with anything to test
759 # in this procedure.
760
761 test listbox-4.1 {ConfigureListbox procedure} {fonts} {
762     catch {destroy .l}
763     listbox .l -setgrid 1 -width 25 -height 15
764     pack .l
765     update
766     set x [getsize .]
767     .l configure -setgrid 0
768     update
769     list $x [getsize .]
770 } {25x15 185x263}
771 resetGridInfo
772 test listbox-4.2 {ConfigureListbox procedure} {
773     .l configure -highlightthickness -3
774     .l cget -highlightthickness
775 } {0}
776 test listbox-4.3 {ConfigureListbox procedure} {
777     .l configure -exportselection 0
778     .l delete 0 end
779     .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8
780     .l selection set 3 5
781     .l configure -exportselection 1
782     selection get
783 } {el3
784 el4
785 el5}
786 test listbox-4.4 {ConfigureListbox procedure} {
787     catch {destroy .e}
788     entry .e
789     .e insert 0 abc
790     .e select from 0
791     .e select to 2
792     .l configure -exportselection 0
793     .l delete 0 end
794     .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8
795     .l selection set 3 5
796     .l selection clear 3 5
797     .l configure -exportselection 1
798     list [selection own] [selection get]
799 } {.e ab}
800 test listbox-4.5 {-exportselection option} {
801     selection clear .
802     .l configure -exportselection 1
803     .l delete 0 end
804     .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8
805     .l selection set 1 1
806     set x {}
807     lappend x [catch {selection get} msg] $msg [.l curselection]
808     .l config -exportselection 0
809     lappend x [catch {selection get} msg] $msg [.l curselection]
810     .l selection clear 0 end
811     lappend x [catch {selection get} msg] $msg [.l curselection]
812     .l selection set 1 3
813     lappend x [catch {selection get} msg] $msg [.l curselection]
814     .l config -exportselection 1
815     lappend x [catch {selection get} msg] $msg [.l curselection]
816 } {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
817 el2
818 el3} {1 2 3}}
819 test listbox-4.6 {ConfigureListbox procedure} {fonts} {
820     catch {destroy .l}
821
822     # The following code (reset geometry, withdraw, etc.) is necessary
823     # to reset the state of some window managers like olvwm under
824     # SunOS 4.1.3.
825
826     wm geom . 300x300
827     update
828     wm geom . {}
829     wm withdraw .
830     listbox .l -font $fixed -width 15 -height 20
831     pack .l
832     update
833     wm deiconify .
834     set x [getsize .]
835     .l configure -setgrid 1
836     update
837     list $x [getsize .]
838 } {115x328 15x20}
839 test listbox-4.7 {ConfigureListbox procedure} {
840     catch {destroy .l}
841     wm withdraw .
842     listbox .l -font $fixed -width 30 -height 20 -setgrid 1
843     wm geom . +0+0
844     pack .l
845     update
846     wm deiconify .
847     set result [getsize .]
848     wm geom . 26x15
849     update
850     lappend result [getsize .]
851     .l configure -setgrid 1
852     update
853     lappend result [getsize .]
854 } {30x20 26x15 26x15}
855 wm geom . {}
856 catch {destroy .l}
857 resetGridInfo
858 test listbox-4.8 {ConfigureListbox procedure} {
859     catch {destroy .l}
860     listbox .l -width 15 -height 20 -xscrollcommand "record x" \
861             -yscrollcommand "record y"
862     pack .l
863     update
864     .l configure -fg black
865     set log {}
866     update
867     set log
868 } {{y 0 1} {x 0 1}}
869 test listbox-4.9 {ConfigureListbox procedure, -listvar} {
870     catch {destroy .l}
871     set x [list a b c d]
872     listbox .l -listvar x
873     .l get 0 end
874 } [list a b c d]
875 test listbox-4.10 {ConfigureListbox, no listvar -> existing listvar} {
876     catch {destroy .l}
877     set x [list a b c d]
878     listbox .l
879     .l insert end 1 2 3 4
880     .l configure -listvar x
881     .l get 0 end
882 } [list a b c d]
883 test listbox-4.11 {ConfigureListbox procedure, listvar -> no listvar} {
884     catch {destroy .l}
885     set x [list a b c d]
886     listbox .l -listvar x
887     .l configure -listvar {}
888     .l insert end 1 2 3 4
889     list $x [.l get 0 end]
890 } [list [list a b c d] [list a b c d 1 2 3 4]]
891 test listbox-4.12 {ConfigureListbox procedure, listvar -> different listvar} {
892     catch {destroy .l}
893     set x [list a b c d]
894     set y [list 1 2 3 4]
895     listbox .l 
896     .l configure -listvar x
897     .l configure -listvar y
898     .l insert end 5 6 7 8
899     list $x $y
900 } [list [list a b c d] [list 1 2 3 4 5 6 7 8]]
901 test listbox-4.13 {ConfigureListbox, no listvar -> non-existant listvar} {
902     catch {destroy .l}
903     catch {unset x}
904     listbox .l
905     .l insert end a b c d
906     .l configure -listvar x
907     set x
908 } [list a b c d]
909 test listbox-4.14 {ConfigureListbox, non-existant listvar} {
910     catch {destroy .l}
911     catch {unset x}
912     listbox .l -listvar x
913     list [info exists x] $x
914 } [list 1 {}]
915 test listbox-4.15 {ConfigureListbox, listvar -> non-existant listvar} {
916     catch {destroy .l}
917     catch {unset y}
918     set x [list a b c d]
919     listbox .l -listvar x
920     .l configure -listvar y
921     list [info exists y] $y
922 } [list 1 [list a b c d]]
923 test listbox-4.16 {ConfigureListbox, listvar -> same listvar} {
924     catch {destroy .l}
925     set x [list a b c d]
926     listbox .l -listvar x
927     .l configure -listvar x
928     set x
929 } [list a b c d]
930 test listbox-4.17 {ConfigureListbox, no listvar -> no listvar} {
931     catch {destroy .l}
932     listbox .l
933     .l insert end a b c d
934     .l configure -listvar {}
935     .l get 0 end
936 } [list a b c d]
937 test listbox-4.18 {ConfigureListbox, no listvar -> bad listvar} {
938     catch {destroy .l}
939     listbox .l
940     .l insert end a b c d
941     set x {this is a " bad list}
942     catch {.l configure -listvar x} result
943     list [.l get 0 end] [.l cget -listvar] $result
944 } [list [list a b c d] {} \
945         "unmatched open quote in list: invalid listvar value"]
946
947 # No tests for DisplayListbox:  I don't know how to test this procedure.
948
949 test listbox-5.1 {ListboxComputeGeometry procedure} {fonts} {
950     catch {destroy .l}
951     listbox .l -font $fixed -width 15 -height 20
952     pack .l
953     list [winfo reqwidth .l] [winfo reqheight .l]
954 } {115 328}
955 test listbox-5.2 {ListboxComputeGeometry procedure} {fonts} {
956     catch {destroy .l}
957     listbox .l -font $fixed -width 0 -height 10
958     pack .l
959     update
960     list [winfo reqwidth .l] [winfo reqheight .l]
961 } {17 168}
962 test listbox-5.3 {ListboxComputeGeometry procedure} {fonts} {
963     catch {destroy .l}
964     listbox .l -font $fixed -width 0 -height 10 -bd 3
965     .l insert 0 Short "Really much longer" Longer
966     pack .l
967     update
968     list [winfo reqwidth .l] [winfo reqheight .l]
969 } {138 170}
970 test listbox-5.4 {ListboxComputeGeometry procedure} {fonts} {
971     catch {destroy .l}
972     listbox .l -font $fixed -width 10 -height 0
973     pack .l
974     update
975     list [winfo reqwidth .l] [winfo reqheight .l]
976 } {80 24}
977 test listbox-5.5 {ListboxComputeGeometry procedure} {fonts} {
978     catch {destroy .l}
979     listbox .l -font $fixed -width 10 -height 0 -highlightthickness 0
980     .l insert 0 Short "Really much longer" Longer
981     pack .l
982     update
983     list [winfo reqwidth .l] [winfo reqheight .l]
984 } {76 52}
985 test listbox-5.6 {ListboxComputeGeometry procedure} {
986     # If "0" in selected font had 0 width, caused divide-by-zero error.
987
988     catch {destroy .l}
989     pack [listbox .l -font {{open look glyph}}]
990     update
991 } {}
992     
993
994 catch {destroy .l}
995 listbox .l -height 2 -xscrollcommand "record x" -yscrollcommand "record y"
996 pack .l
997 update
998 test listbox-6.1 {InsertEls procedure} {
999     .l delete 0 end
1000     .l insert end a b c d
1001     .l insert 5 x y z
1002     .l insert 2 A
1003     .l insert 0 q r s
1004     .l get 0 end
1005 } {q r s a b A c d x y z}
1006 test listbox-6.2 {InsertEls procedure} {
1007     .l delete 0 end
1008     .l insert 0 a b c d e f g h i j
1009     .l selection anchor 2
1010     .l insert 2 A B
1011     .l index anchor
1012 } {4}
1013 test listbox-6.3 {InsertEls procedure} {
1014     .l delete 0 end
1015     .l insert 0 a b c d e f g h i j
1016     .l selection anchor 2
1017     .l insert 3 A B
1018     .l index anchor
1019 } {2}
1020 test listbox-6.4 {InsertEls procedure} {
1021     .l delete 0 end
1022     .l insert 0 a b c d e f g h i j
1023     .l yview 3
1024     update
1025     .l insert 2 A B
1026     .l index @0,0
1027 } {5}
1028 test listbox-6.5 {InsertEls procedure} {
1029     .l delete 0 end
1030     .l insert 0 a b c d e f g h i j
1031     .l yview 3
1032     update
1033     .l insert 3 A B
1034     .l index @0,0
1035 } {3}
1036 test listbox-6.6 {InsertEls procedure} {
1037     .l delete 0 end
1038     .l insert 0 a b c d e f g h i j
1039     .l activate 5
1040     .l insert 5 A B
1041     .l index active
1042 } {7}
1043 test listbox-6.7 {InsertEls procedure} {
1044     .l delete 0 end
1045     .l insert 0 a b c d e f g h i j
1046     .l activate 5
1047     .l insert 6 A B
1048     .l index active
1049 } {5}
1050 test listbox-6.8 {InsertEls procedure} {
1051     .l delete 0 end
1052     .l insert 0 a b c
1053     .l index active
1054 } {2}
1055 test listbox-6.9 {InsertEls procedure} {
1056     .l delete 0 end
1057     .l insert 0
1058     .l index active
1059 } {0}
1060 test listbox-6.10 {InsertEls procedure} {
1061     .l delete 0 end
1062     .l insert 0 a b "two words"  c d e f g h i j
1063     update
1064     set log {}
1065     .l insert 0 word
1066     update
1067     set log
1068 } {{y 0 0.166667}}
1069 test listbox-6.11 {InsertEls procedure} {
1070     .l delete 0 end
1071     .l insert 0 a b "two words"  c d e f g h i j
1072     update
1073     set log {}
1074     .l insert 0 "much longer entry"
1075     update
1076     set log
1077 } {{y 0 0.166667} {x 0 1}}
1078 test listbox-6.12 {InsertEls procedure} {fonts} {
1079     catch {destroy .l2}
1080     listbox .l2 -width 0 -height 0
1081     pack .l2 -side top
1082     .l2 insert 0 a b "two words"  c d
1083     set x {}
1084     lappend x [winfo reqwidth .l2] [winfo reqheight .l2]
1085     .l2 insert 0 "much longer entry"
1086     lappend x [winfo reqwidth .l2] [winfo reqheight .l2]
1087 } {80 93 122 110}
1088 test listbox-6.13 {InsertEls procedure, check -listvar update} {
1089     catch {destroy .l2}
1090     set x [list a b c d]
1091     listbox .l2 -listvar x
1092     .l2 insert 0 1 2 3 4
1093     set x
1094 } [list 1 2 3 4 a b c d]
1095 test listbox-6.14 {InsertEls procedure, check selection update} {
1096     catch {destroy .l2}
1097     listbox .l2
1098     .l2 insert 0 0 1 2 3 4
1099     .l2 selection set 2 4
1100     .l2 insert 0 a
1101     .l2 curselection
1102 } [list 3 4 5]
1103
1104
1105 test listbox-7.1 {DeleteEls procedure} {
1106     .l delete 0 end
1107     .l insert 0 a b c d e f g h i j
1108     .l selection set 1 6
1109     .l delete 4 3
1110     list [.l size] [selection get]
1111 } {10 {b
1112 c
1113 d
1114 e
1115 f
1116 g}}
1117 test listbox-7.2 {DeleteEls procedure} {
1118     .l delete 0 end
1119     .l insert 0 a b c d e f g h i j
1120     .l selection set 3 6
1121     .l delete 4 4
1122     list [.l size] [.l get 4] [.l curselection]
1123 } {9 f {3 4 5}}
1124 test listbox-7.3 {DeleteEls procedure} {
1125     .l delete 0 end
1126     .l insert 0 a b c d e f g h i j
1127     .l delete 0 3
1128     list [.l size] [.l get 0] [.l get 1]
1129 } {6 e f}
1130 test listbox-7.4 {DeleteEls procedure} {
1131     .l delete 0 end
1132     .l insert 0 a b c d e f g h i j
1133     .l delete 8 1000
1134     list [.l size] [.l get 7]
1135 } {8 h}
1136 test listbox-7.5 {DeleteEls procedure} {
1137     .l delete 0 end
1138     .l insert 0 a b c d e f g h i j
1139     .l selection anchor 2
1140     .l delete 0 1
1141     .l index anchor
1142 } {0}
1143 test listbox-7.6 {DeleteEls procedure} {
1144     .l delete 0 end
1145     .l insert 0 a b c d e f g h i j
1146     .l selection anchor 2
1147     .l delete 2
1148     .l index anchor
1149 } {2}
1150 test listbox-7.7 {DeleteEls procedure} {
1151     .l delete 0 end
1152     .l insert 0 a b c d e f g h i j
1153     .l selection anchor 4
1154     .l delete 2 5
1155     .l index anchor
1156 } {2}
1157 test listbox-7.8 {DeleteEls procedure} {
1158     .l delete 0 end
1159     .l insert 0 a b c d e f g h i j
1160     .l selection anchor 3
1161     .l delete 4 5
1162     .l index anchor
1163 } {3}
1164 test listbox-7.9 {DeleteEls procedure} {
1165     .l delete 0 end
1166     .l insert 0 a b c d e f g h i j
1167     .l yview 3
1168     update
1169     .l delete 1 2
1170     .l index @0,0
1171 } {1}
1172 test listbox-7.10 {DeleteEls procedure} {
1173     .l delete 0 end
1174     .l insert 0 a b c d e f g h i j
1175     .l yview 3
1176     update
1177     .l delete 3 4
1178     .l index @0,0
1179 } {3}
1180 test listbox-7.11 {DeleteEls procedure} {
1181     .l delete 0 end
1182     .l insert 0 a b c d e f g h i j
1183     .l yview 3
1184     update
1185     .l delete 4 6
1186     .l index @0,0
1187 } {3}
1188 test listbox-7.12 {DeleteEls procedure} {
1189     .l delete 0 end
1190     .l insert 0 a b c d e f g h i j
1191     .l yview 3
1192     update
1193     .l delete 3 end
1194     .l index @0,0
1195 } {1}
1196 test listbox-7.13 {DeleteEls procedure, updating view with partial last line} {
1197     mkPartial
1198     .partial.l yview 8
1199     update
1200     .partial.l delete 10 13
1201     .partial.l index @0,0
1202 } {7}
1203 test listbox-7.14 {DeleteEls procedure} {
1204     .l delete 0 end
1205     .l insert 0 a b c d e f g h i j
1206     .l activate 6
1207     .l delete 3 4
1208     .l index active
1209 } {4}
1210 test listbox-7.15 {DeleteEls procedure} {
1211     .l delete 0 end
1212     .l insert 0 a b c d e f g h i j
1213     .l activate 6
1214     .l delete 5 7
1215     .l index active
1216 } {5}
1217 test listbox-7.16 {DeleteEls procedure} {
1218     .l delete 0 end
1219     .l insert 0 a b c d e f g h i j
1220     .l activate 6
1221     .l delete 5 end
1222     .l index active
1223 } {4}
1224 test listbox-7.17 {DeleteEls procedure} {
1225     .l delete 0 end
1226     .l insert 0 a b c d e f g h i j
1227     .l activate 6
1228     .l delete 0 end
1229     .l index active
1230 } {0}
1231 test listbox-7.18 {DeleteEls procedure} {
1232     .l delete 0 end
1233     .l insert 0 a b c "two words" d e f g h i j
1234     update
1235     set log {}
1236     .l delete 4 6
1237     update
1238     set log
1239 } {{y 0 0.25}}
1240 test listbox-7.19 {DeleteEls procedure} {
1241     .l delete 0 end
1242     .l insert 0 a b c "two words" d e f g h i j
1243     update
1244     set log {}
1245     .l delete 3
1246     update
1247     set log
1248 } {{y 0 0.2} {x 0 1}}
1249 test listbox-7.20 {DeleteEls procedure} {fonts} {
1250     catch {destroy .l2}
1251     listbox .l2 -width 0 -height 0
1252     pack .l2 -side top
1253     .l2 insert 0 a b "two words" c d e f g
1254     set x {}
1255     lappend x [winfo reqwidth .l2] [winfo reqheight .l2]
1256     .l2 delete 2 4
1257     lappend x [winfo reqwidth .l2] [winfo reqheight .l2]
1258 } {80 144 17 93}
1259 catch {destroy .l2}
1260 test listbox-7.21 {DeleteEls procedure, check -listvar update} {
1261     catch {destroy .l2}
1262     set x [list a b c d]
1263     listbox .l2 -listvar x
1264     .l2 delete 0 1
1265     set x
1266 } [list c d]
1267
1268 test listbox-8.1 {ListboxEventProc procedure} {fonts} {
1269     catch {destroy .l}
1270     listbox .l -setgrid 1
1271     pack .l
1272     update
1273     set x [getsize .]
1274     destroy .l
1275     list $x [getsize .] [winfo exists .l] [info command .l]
1276 } {20x10 150x178 0 {}}
1277 resetGridInfo
1278 test listbox-8.2 {ListboxEventProc procedure} {fonts} {
1279     catch {destroy .l}
1280     listbox .l -height 5 -width 10
1281     .l insert 0 a b c "A string that is very very long" d e f g h i j k
1282     pack .l
1283     update
1284     place .l -width 50 -height 80
1285     update
1286     list [.l xview] [.l yview]
1287 } {{0 0.222222} {0 0.333333}}
1288 test listbox-8.3 {ListboxEventProc procedure} {
1289     eval destroy [winfo children .]
1290     listbox .l1 -bg #543210
1291     rename .l1 .l2
1292     set x {}
1293     lappend x [winfo children .]
1294     lappend x [.l2 cget -bg]
1295     destroy .l1
1296     lappend x [info command .l*] [winfo children .]
1297 } {.l1 #543210 {} {}}
1298
1299 test listbox-9.1 {ListboxCmdDeletedProc procedure} {
1300     eval destroy [winfo children .]
1301     listbox .l1
1302     rename .l1 {}
1303     list [info command .l*] [winfo children .]
1304 } {{} {}}
1305 test listbox-9.2 {ListboxCmdDeletedProc procedure, disabling -setgrid} fonts {
1306     catch {destroy .top}
1307     toplevel .top
1308     wm geom .top +0+0
1309     listbox .top.l -setgrid 1 -width 20 -height 10
1310     pack .top.l
1311     update
1312     set x [wm geometry .top]
1313     rename .top.l {}
1314     update
1315     lappend x [wm geometry .top]
1316     destroy .top
1317     set x
1318 } {20x10+0+0 150x178+0+0}
1319
1320 catch {destroy .l}
1321 listbox .l
1322 pack .l
1323 .l delete 0 end
1324 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
1325 test listbox-10.1 {GetListboxIndex procedure} {
1326     .l activate 3
1327     list [.l activate 3; .l index active] [.l activate 6; .l index active]
1328 } {3 6}
1329 test listbox-10.2 {GetListboxIndex procedure} {
1330     .l selection anchor 2
1331     .l index anchor
1332 } 2
1333 test listbox-10.3 {GetListboxIndex procedure} {
1334     .l insert end A B C D E
1335     .l selection anchor end
1336     .l delete 12 end
1337     list [.l index anchor] [.l index end]
1338 } {12 12}
1339 test listbox-10.4 {GetListboxIndex procedure} {
1340     list [catch {.l index a} msg] $msg
1341 } {1 {bad listbox index "a": must be active, anchor, end, @x,y, or a number}}
1342 test listbox-10.5 {GetListboxIndex procedure} {
1343     .l index end
1344 } {12}
1345 test listbox-10.6 {GetListboxIndex procedure} {
1346     .l get end
1347 } {el11}
1348 test listbox-10.7 {GetListboxIndex procedure} {
1349     .l delete 0 end
1350     .l index end
1351 } 0
1352 .l delete 0 end
1353 .l insert 0 el0 el1 el2 el3 el4 el5 el6 el7 el8 el9 el10 el11
1354 update
1355 test listbox-10.8 {GetListboxIndex procedure} {
1356     list [catch {.l index @} msg] $msg
1357 } {1 {bad listbox index "@": must be active, anchor, end, @x,y, or a number}}
1358 test listbox-10.9 {GetListboxIndex procedure} {
1359     list [catch {.l index @foo} msg] $msg
1360 } {1 {bad listbox index "@foo": must be active, anchor, end, @x,y, or a number}}
1361 test listbox-10.10 {GetListboxIndex procedure} {
1362     list [catch {.l index @1x3} msg] $msg
1363 } {1 {bad listbox index "@1x3": must be active, anchor, end, @x,y, or a number}}
1364 test listbox-10.11 {GetListboxIndex procedure} {
1365     list [catch {.l index @1,} msg] $msg
1366 } {1 {bad listbox index "@1,": must be active, anchor, end, @x,y, or a number}}
1367 test listbox-10.12 {GetListboxIndex procedure} {
1368     list [catch {.l index @1,foo} msg] $msg
1369 } {1 {bad listbox index "@1,foo": must be active, anchor, end, @x,y, or a number}}
1370 test listbox-10.13 {GetListboxIndex procedure} {
1371     list [catch {.l index @1,2x} msg] $msg
1372 } {1 {bad listbox index "@1,2x": must be active, anchor, end, @x,y, or a number}}
1373 test listbox-10.14 {GetListboxIndex procedure} {fonts} {
1374     list [.l index @5,57] [.l index @5,58]
1375 } {3 3}
1376 test listbox-10.15 {GetListboxIndex procedure} {
1377     list [catch {.l index 1xy} msg] $msg
1378 } {1 {bad listbox index "1xy": must be active, anchor, end, @x,y, or a number}}
1379 test listbox-10.16 {GetListboxIndex procedure} {
1380     .l index 3
1381 } {3}
1382 test listbox-10.17 {GetListboxIndex procedure} {
1383     .l index 20
1384 } {20}
1385 test listbox-10.18 {GetListboxIndex procedure} {
1386     .l get 20
1387 } {}
1388 test listbox-10.19 {GetListboxIndex procedure} {
1389     .l index -2
1390 } -2
1391 test listbox-10.20 {GetListboxIndex procedure} {
1392     .l delete 0 end
1393     .l index 1
1394 } 1
1395
1396 test listbox-11.1 {ChangeListboxView procedure, boundary conditions for index} {
1397     catch {destroy .l}
1398     listbox .l -height 5
1399     pack .l
1400     .l insert 0 a b c d e f g h i j
1401     .l yview 3
1402     update
1403     set x [.l index @0,0]
1404     .l yview -1
1405     update
1406     lappend x [.l index @0,0]
1407 } {3 0}
1408 test listbox-11.2 {ChangeListboxView procedure, boundary conditions for index} {
1409     catch {destroy .l}
1410     listbox .l -height 5
1411     pack .l
1412     .l insert 0 a b c d e f g h i j
1413     .l yview 3
1414     update
1415     set x [.l index @0,0]
1416     .l yview 20
1417     update
1418     lappend x [.l index @0,0]
1419 } {3 5}
1420 test listbox-11.3 {ChangeListboxView procedure} {
1421     catch {destroy .l}
1422     listbox .l -height 5 -yscrollcommand "record y"
1423     pack .l
1424     .l insert 0 a b c d e f g h i j
1425     update
1426     set log {}
1427     .l yview 2
1428     update
1429     list [.l yview] $log
1430 }  {{0.2 0.7} {{y 0.2 0.7}}}
1431 test listbox-11.4 {ChangeListboxView procedure} {
1432     catch {destroy .l}
1433     listbox .l -height 5 -yscrollcommand "record y"
1434     pack .l
1435     .l insert 0 a b c d e f g h i j
1436     update
1437     set log {}
1438     .l yview 8
1439     update
1440     list [.l yview] $log
1441 }  {{0.5 1} {{y 0.5 1}}}
1442 test listbox-11.5 {ChangeListboxView procedure} {
1443     catch {destroy .l}
1444     listbox .l -height 5 -yscrollcommand "record y"
1445     pack .l
1446     .l insert 0 a b c d e f g h i j
1447     .l yview 3
1448     update
1449     set log {}
1450     .l yview 3
1451     update
1452     list [.l yview] $log
1453 }  {{0.3 0.8} {}}
1454 test listbox-11.6 {ChangeListboxView procedure, partial last line} {
1455     mkPartial
1456     .partial.l yview 13
1457     .partial.l index @0,0
1458 } {11}
1459
1460 catch {destroy .l}
1461 listbox .l -font $fixed -xscrollcommand "record x" -width 10
1462 .l insert 0 0123456789a123456789b123456789c123456789d123456789e123456789f123456789g123456789h123456789i123456789
1463 pack .l
1464 update
1465 test listbox-12.1 {ChangeListboxOffset procedure} {fonts} {
1466     set log {}
1467     .l xview 99
1468     update
1469     list [.l xview] $log
1470 } {{0.9 1} {{x 0.9 1}}}
1471 test listbox-12.2 {ChangeListboxOffset procedure} {fonts} {
1472     set log {}
1473     .l xview moveto -.25
1474     update
1475     list [.l xview] $log
1476 } {{0 0.1} {{x 0 0.1}}}
1477 test listbox-12.3 {ChangeListboxOffset procedure} {fonts} {
1478     .l xview 10
1479     update
1480     set log {}
1481     .l xview 10
1482     update
1483     list [.l xview] $log
1484 } {{0.1 0.2} {}}
1485
1486 catch {destroy .l}
1487 listbox .l -font $fixed -width 10 -height 5
1488 pack .l
1489 .l insert 0 a bb c d e f g h i j k l m n o p q r s
1490 .l insert 0 0123456789a123456789b123456789c123456789d123456789
1491 update
1492 set width [expr [lindex [.l bbox 2] 2] - [lindex [.l bbox 1] 2]]
1493 set height [expr [lindex [.l bbox 2] 1] - [lindex [.l bbox 1] 1]]
1494 test listbox-13.1 {ListboxScanTo procedure} {fonts} {
1495     .l yview 0
1496     .l xview 0
1497     .l scan mark 10 20
1498     .l scan dragto [expr 10-$width] [expr 20-$height]
1499     update
1500     list [.l xview] [.l yview]
1501 } {{0.2 0.4} {0.5 0.75}}
1502 test listbox-13.2 {ListboxScanTo procedure} {fonts} {
1503     .l yview 5
1504     .l xview 10
1505     .l scan mark 10 20
1506     .l scan dragto 20 40
1507     update
1508     set x [list [.l xview] [.l yview]]
1509     .l scan dragto [expr 20-$width] [expr 40-$height]
1510     update
1511     lappend x [.l xview] [.l yview]
1512 } {{0 0.2} {0 0.25} {0.2 0.4} {0.5 0.75}}
1513 test listbox-13.3 {ListboxScanTo procedure} {fonts} {
1514     .l yview moveto 1.0
1515     .l xview moveto 1.0
1516     .l scan mark 10 20
1517     .l scan dragto 5 10
1518     update
1519     set x [list [.l xview] [.l yview]]
1520     .l scan dragto [expr 5+$width] [expr 10+$height]
1521     update
1522     lappend x [.l xview] [.l yview]
1523 } {{0.8 1} {0.75 1} {0.62 0.82} {0.25 0.5}}
1524
1525 test listbox-14.1 {NearestListboxElement procedure, partial last line} {
1526     mkPartial
1527     .partial.l nearest [winfo height .partial.l]
1528 } {4}
1529 catch {destroy .l}
1530 listbox .l -font $fixed -width 20 -height 10
1531 .l insert 0 a b c d e f g h i j k l m n o p q r s t
1532 .l yview 4
1533 pack .l
1534 update
1535 test listbox-14.2 {NearestListboxElement procedure} {fonts} {
1536     .l index @50,0
1537 } {4}
1538 test listbox-14.3 {NearestListboxElement procedure} {fonts} {
1539     list [.l index @50,35] [.l index @50,36]
1540 } {5 6}
1541 test listbox-14.4 {NearestListboxElement procedure} {fonts} {
1542     .l index @50,200
1543 } {13}
1544
1545 test listbox-15.1 {ListboxSelect procedure} {
1546     .l delete 0 end
1547     .l insert 0 a b c d e f g h i j k l m n o p
1548     .l select set 2 4
1549     .l select set 7 12
1550     .l select clear 4 7
1551     .l curselection
1552 } {2 3 8 9 10 11 12}
1553 test listbox-15.2 {ListboxSelect procedure} {
1554     .l delete 0 end
1555     .l insert 0 a b c d e f g h i j k l m n o p
1556     catch {destroy .e}
1557     entry .e
1558     .e insert 0 "This is some text"
1559     .e select from 0
1560     .e select to 7
1561     .l selection clear 2 4
1562     set x [selection own]
1563     .l selection set 3
1564     list $x [selection own] [selection get]
1565 } {.e .l d}
1566 test listbox-15.3 {ListboxSelect procedure} {
1567     .l delete 0 end
1568     .l selection clear 0 end
1569     .l select set 0 end
1570     .l curselection
1571 } {}
1572 test listbox-15.4 {ListboxSelect procedure, boundary conditions for indices} {
1573     .l delete 0 end
1574     .l insert 0 a b c d e f
1575     .l select clear 0 end
1576     .l select set -2 -1
1577     .l curselection
1578 } {}
1579 test listbox-15.5 {ListboxSelect procedure, boundary conditions for indices} {
1580     .l delete 0 end
1581     .l insert 0 a b c d e f
1582     .l select clear 0 end
1583     .l select set -1 3
1584     .l curselection
1585 } {0 1 2 3}
1586 test listbox-15.6 {ListboxSelect procedure, boundary conditions for indices} {
1587     .l delete 0 end
1588     .l insert 0 a b c d e f
1589     .l select clear 0 end
1590     .l select set 2 4
1591     .l curselection
1592 } {2 3 4}
1593 test listbox-15.7 {ListboxSelect procedure, boundary conditions for indices} {
1594     .l delete 0 end
1595     .l insert 0 a b c d e f
1596     .l select clear 0 end
1597     .l select set 4 end
1598     .l curselection
1599 } {4 5}
1600 test listbox-15.8 {ListboxSelect procedure, boundary conditions for indices} {
1601     .l delete 0 end
1602     .l insert 0 a b c d e f
1603     .l select clear 0 end
1604     .l select set 4 30
1605     .l curselection
1606 } {4 5}
1607 test listbox-15.9 {ListboxSelect procedure, boundary conditions for indices} {
1608     .l delete 0 end
1609     .l insert 0 a b c d e f
1610     .l select clear 0 end
1611     .l select set end 30
1612     .l curselection
1613 } {5}
1614 test listbox-15.10 {ListboxSelect procedure, boundary conditions for indices} {
1615     .l delete 0 end
1616     .l insert 0 a b c d e f
1617     .l select clear 0 end
1618     .l select set 20 25
1619     .l curselection
1620 } {}
1621
1622 test listbox-16.1 {ListboxFetchSelection procedure} {
1623     .l delete 0 end
1624     .l insert 0 a b c "two words" e f g h i \\ k l m n o p
1625     .l selection set 2 4
1626     .l selection set 9
1627     .l selection set 11 12
1628     selection get
1629 } "c\ntwo words\ne\n\\\nl\nm"
1630 test listbox-16.2 {ListboxFetchSelection procedure} {
1631     .l delete 0 end
1632     .l insert 0 a b c "two words" e f g h i \\ k l m n o p
1633     .l selection set 3
1634     selection get
1635 } "two words"
1636 test listbox-16.3 {ListboxFetchSelection procedure, retrieve in several parts} {
1637     set long "This is quite a long string\n"
1638     append long $long $long $long $long
1639     append long $long $long $long $long
1640     append long $long $long
1641     .l delete 0 end
1642     .l insert 0 1$long 2$long 3$long 4$long 5$long
1643     .l selection set 0 end
1644     set sel [selection get]
1645     string compare 1$long\n2$long\n3$long\n4$long\n5$long $sel
1646 } {0}
1647 catch {unset long sel}
1648
1649 test listbox-17.1 {ListboxLostSelection procedure} {
1650     .l delete 0 end
1651     .l insert 0 a b c d e
1652     .l select set 0 end
1653     catch {destroy .e}
1654     entry .e
1655     .e insert 0 "This is some text"
1656     .e select from 0
1657     .e select to 5
1658     .l curselection
1659 } {}
1660 test listbox-17.2 {ListboxLostSelection procedure} {
1661     .l delete 0 end
1662     .l insert 0 a b c d e
1663     .l select set 0 end
1664     .l configure -exportselection 0
1665     catch {destroy .e}
1666     entry .e
1667     .e insert 0 "This is some text"
1668     .e select from 0
1669     .e select to 5
1670     .l curselection
1671 } {0 1 2 3 4}
1672
1673 catch {destroy .l}
1674 listbox .l -font $fixed -width 10 -height 5
1675 pack .l
1676 update
1677 test listbox-18.1 {ListboxUpdateVScrollbar procedure} {
1678     .l configure -yscrollcommand "record y"
1679     set log {}
1680     .l insert 0 a b c
1681     update
1682     .l insert end d e f g h
1683     update
1684     .l delete 0 end
1685     update
1686     set log
1687 } {{y 0 1} {y 0 0.625} {y 0 1}}
1688 test listbox-18.2 {ListboxUpdateVScrollbar procedure, partial last line} {
1689     mkPartial
1690     .partial.l configure -yscrollcommand "record y"
1691     set log {}
1692     .partial.l yview 3
1693     update
1694     set log
1695 } {{y 0.2 0.466667}}
1696 test listbox-18.3 {ListboxUpdateVScrollbar procedure} {
1697     proc bgerror args {
1698         global x errorInfo
1699         set x [list $args $errorInfo]
1700     }
1701     .l configure -yscrollcommand gorp
1702     .l insert 0 foo
1703     update
1704     set x
1705 } {{{invalid command name "gorp"}} {invalid command name "gorp"
1706     while executing
1707 "gorp 0 1"
1708     (vertical scrolling command executed by listbox)}}
1709 if {[info exists bgerror]} {
1710     rename bgerror {}
1711 }
1712
1713 catch {destroy .l}
1714 listbox .l -font $fixed -width 10 -height 5
1715 pack .l
1716 update
1717 test listbox-19.1 {ListboxUpdateVScrollbar procedure} {fonts} {
1718     .l configure -xscrollcommand "record x"
1719     set log {}
1720     .l insert 0 abc
1721     update
1722     .l insert 0 "This is a much longer string..."
1723     update
1724     .l delete 0 end
1725     update
1726     set log
1727 } {{x 0 1} {x 0 0.322581} {x 0 1}}
1728 test listbox-19.2 {ListboxUpdateVScrollbar procedure} {
1729     proc bgerror args {
1730         global x errorInfo
1731         set x [list $args $errorInfo]
1732     }
1733     .l configure -xscrollcommand bogus
1734     .l insert 0 foo
1735     update
1736     set x
1737 } {{{invalid command name "bogus"}} {invalid command name "bogus"
1738     while executing
1739 "bogus 0 1"
1740     (horizontal scrolling command executed by listbox)}}
1741
1742 set l [interp hidden]
1743 eval destroy [winfo children .]
1744
1745 test listbox-20.1 {listbox vs hidden commands} {
1746     catch {destroy .l}
1747     listbox .l
1748     interp hide {} .l
1749     destroy .l
1750     list [winfo children .] [interp hidden]
1751 } [list {} $l]
1752
1753 # tests for ListboxListVarProc
1754 test listbox-21.1 {ListboxListVarProc} {
1755     catch {destroy .l}
1756     catch {unset x}
1757     listbox .l -listvar x
1758     set x [list a b c d]
1759     .l get 0 end
1760 } [list a b c d]
1761 test listbox-21.2 {ListboxListVarProc} {
1762     catch {destroy .l}
1763     set x [list a b c d]
1764     listbox .l -listvar x
1765     unset x
1766     set x
1767 } [list a b c d]
1768 test listbox-21.3 {ListboxListVarProc} {
1769     catch {destroy .l}
1770     set x [list a b c d]
1771     listbox .l -listvar x
1772     .l configure -listvar {}
1773     unset x
1774     info exists x
1775 } 0
1776 test listbox-21.4 {ListboxListVarProc} {
1777     catch {destroy .l}
1778     set x [list a b c d]
1779     listbox .l -listvar x
1780     lappend x e f g
1781     .l size
1782 } 7
1783 test listbox-21.5 {ListboxListVarProc, test selection after listvar mod} {
1784     catch {destroy .l}
1785     set x [list a b c d e f g]
1786     listbox .l -listvar x
1787     .l selection set end
1788     set x [list a b c d]
1789     set x [list 0 1 2 3 4 5 6]
1790     .l curselection
1791 } {}
1792 test listbox-21.6 {ListboxListVarProc, test selection after listvar mod} {
1793     catch {destroy .l}
1794     set x [list a b c d]
1795     listbox .l -listvar x
1796     .l selection set 3
1797     lappend x e f g
1798     .l curselection
1799 } 3
1800 test listbox-21.7 {ListboxListVarProc, test selection after listvar mod} {
1801     catch {destroy .l}
1802     set x [list a b c d]
1803     listbox .l -listvar x
1804     .l selection set 0
1805     set x [linsert $x 0 1 2 3 4]
1806     .l curselection
1807 } 0
1808 test listbox-21.8 {ListboxListVarProc, test selection after listvar mod} {
1809     catch {destroy .l}
1810     set x [list a b c d]
1811     listbox .l -listvar x
1812     .l selection set 2
1813     set x [list a b c]
1814     .l curselection
1815 } 2
1816 test listbox-21.9 {ListboxListVarProc, test hscrollbar after listvar mod} {
1817     catch {destroy .l}
1818     catch {unset x}
1819     set log {}
1820     listbox .l -font $fixed -width 10 -xscrollcommand "record x" -listvar x
1821     pack .l
1822     update
1823     lappend x "0000000000"
1824     update
1825     lappend x "00000000000000000000"
1826     update
1827     set log
1828 } [list {x 0 1} {x 0 1} {x 0 0.5}]
1829 test listbox-21.10 {ListboxListVarProc, test hscrollbar after listvar mod} {
1830     catch {destroy .l}
1831     catch {unset x}
1832     set log {}
1833     listbox .l -font $fixed -width 10 -xscrollcommand "record x" -listvar x
1834     pack .l
1835     update
1836     lappend x "0000000000"
1837     update
1838     lappend x "00000000000000000000"
1839     update
1840     set x [list "0000000000"]
1841     update
1842     set log
1843 } [list {x 0 1} {x 0 1} {x 0 0.5} {x 0 1}]
1844 test listbox-21.11 {ListboxListVarProc, bad list} {
1845     catch {destroy .l}
1846     catch {unset x}
1847     listbox .l -listvar x
1848     set x [list a b c d]
1849     catch {set x {this is a " bad list}} result
1850     set result
1851 } {can't set "x": invalid listvar value}
1852 test listbox-21.12 {ListboxListVarProc, cleanup item attributes} {
1853     catch {destroy .l}
1854     set x [list a b c d e f g]
1855     listbox .l -listvar x
1856     .l itemconfigure end -fg red
1857     set x [list a b c d]
1858     set x [list 0 1 2 3 4 5 6]
1859     .l itemcget end -fg
1860 } {}
1861 test listbox-21.12 {ListboxListVarProc, cleanup item attributes} {
1862     catch {destroy .l}
1863     set x [list a b c d e f g]
1864     listbox .l -listvar x
1865     .l itemconfigure end -fg red
1866     set x [list a b c d]
1867     set x [list 0 1 2 3 4 5 6]
1868     .l itemcget end -fg
1869 } {}
1870 test listbox-21.13 {listbox item configurations and listvar based deletions} {
1871     catch {destroy .l}
1872     catch {unset x}
1873     listbox .l -listvar x
1874     .l insert end a b c
1875     .l itemconfigure 1 -fg red
1876     set x [list b c]
1877     .l itemcget 1 -fg
1878 } red
1879 test listbox-21.14 {listbox item configurations and listvar based inserts} {
1880     catch {destroy .l}
1881     catch {unset x}
1882     listbox .l -listvar x
1883     .l insert end a b c
1884     .l itemconfigure 0 -fg red
1885     set x [list 1 2 3 4 a b c]
1886     .l itemcget 0 -fg
1887 } red
1888 test listbox-21.15 {ListboxListVarProc, update vertical scrollbar} {
1889     catch {destroy .l}
1890     catch {unset x}
1891     set log {}
1892     listbox .l -listvar x -yscrollcommand "record y" -font fixed -height 3
1893     pack .l
1894     update
1895     lappend x a b c d e f
1896     update
1897     set log
1898 } [list {y 0 1} {y 0 0.5}]
1899 test listbox-21.16 {ListboxListVarProc, update vertical scrollbar} {
1900     catch {destroy .l}
1901     catch {unset x}
1902     listbox .l -listvar x -height 3
1903     pack .l
1904     update
1905     set x [list 0 1 2 3 4 5]
1906     .l yview scroll 3 units
1907     update
1908     set result {}
1909     lappend result [.l yview]
1910     set x [lreplace $x 3 3]
1911     set x [lreplace $x 3 3]
1912     set x [lreplace $x 3 3]
1913     update
1914     lappend result [.l yview]
1915     set result
1916 } [list {0.5 1} {0 1}]
1917
1918 # UpdateHScrollbar
1919 test listbox-22.1 {UpdateHScrollbar} {
1920     catch {destroy .l}
1921     set log {}
1922     listbox .l -font $fixed -width 10 -xscrollcommand "record x"
1923     pack .l
1924     update
1925     .l insert end "0000000000"
1926     update
1927     .l insert end "00000000000000000000"
1928     update
1929     set log
1930 } [list {x 0 1} {x 0 1} {x 0 0.5}]
1931
1932 # ConfigureListboxItem
1933 test listbox-23.1 {ConfigureListboxItem} {
1934     catch {destroy .l}
1935     listbox .l
1936     catch {.l itemconfigure 0} result
1937     set result
1938 } {item number "0" out of range}
1939 test listbox-23.2 {ConfigureListboxItem} {
1940     catch {destroy .l}
1941     listbox .l
1942     .l insert end a b c d
1943     .l itemconfigure 0
1944 } [list {-background background Background {} {}} \
1945         {-bg -background} \
1946         {-fg -foreground} \
1947         {-foreground foreground Foreground {} {}} \
1948         {-selectbackground selectBackground Foreground {} {}} \
1949         {-selectforeground selectForeground Background {} {}}]
1950 test listbox-23.3 {ConfigureListboxItem, itemco shortcut} {
1951     catch {destroy .l}
1952     listbox .l
1953     .l insert end a b c d
1954     .l itemco 0 -background
1955 } {-background background Background {} {}}
1956 test listbox-23.4 {ConfigureListboxItem, wrong num args} {
1957     catch {destroy .l}
1958     listbox .l
1959     .l insert end a
1960     catch {.l itemco} result
1961     set result
1962 } {wrong # args: should be ".l itemconfigure index ?option? ?value? ?option value ...?"}
1963 test listbox-23.5 {ConfigureListboxItem, multiple calls} {
1964     catch {destroy .l}
1965     listbox .l
1966     set i 0
1967     foreach color {red orange yellow green blue darkblue violet} {
1968         .l insert end $color
1969         .l itemconfigure $i -bg $color
1970         incr i
1971     }
1972     pack .l
1973     update
1974     list [.l itemcget 0 -bg] [.l itemcget 1 -bg] [.l itemcget 2 -bg] \
1975             [.l itemcget 3 -bg] [.l itemcget 4 -bg] [.l itemcget 5 -bg] \
1976             [.l itemcget 6 -bg]
1977 } {red orange yellow green blue darkblue violet}
1978 catch {destroy .l}
1979 listbox .l
1980 .l insert end a b c d
1981 set i 6
1982 foreach test {
1983     {-background #ff0000 #ff0000 non-existent
1984             {unknown color name "non-existent"}}
1985     {-bg #ff0000 #ff0000 non-existent {unknown color name "non-existent"}}
1986     {-fg #110022 #110022 bogus {unknown color name "bogus"}}
1987     {-foreground #110022 #110022 bogus {unknown color name "bogus"}}
1988     {-selectbackground #110022 #110022 bogus {unknown color name "bogus"}}
1989     {-selectforeground #654321 #654321 bogus {unknown color name "bogus"}}
1990 } {
1991     set name [lindex $test 0]
1992     test listbox-23.$i {configuration options} {
1993         .l itemconfigure 0 $name [lindex $test 1]
1994         list [lindex [.l itemconfigure 0 $name] 4] [.l itemcget 0 $name]
1995     } [list [lindex $test 2] [lindex $test 2]]
1996     incr i
1997     if {[lindex $test 3] != ""} {
1998         test listbox-1.$i {configuration options} {
1999             list [catch {.l configure $name [lindex $test 3]} msg] $msg
2000         } [list 1 [lindex $test 4]]
2001     }
2002     .l configure $name [lindex [.l configure $name] 3]
2003     incr i
2004 }
2005
2006 # ListboxWidgetObjCmd, itemcget
2007 test listbox-24.1 {itemcget} {
2008     catch {destroy .l}
2009     listbox .l
2010     .l insert end a b c d
2011     .l itemcget 0 -fg
2012 } {}
2013 test listbox-24.2 {itemcget} {
2014     catch {destroy .l}
2015     listbox .l
2016     .l insert end a b c d
2017     .l itemconfigure 0 -fg red
2018     .l itemcget 0 -fg
2019 } red
2020 test listbox-24.3 {itemcget} {
2021     catch {destroy .l}
2022     listbox .l
2023     .l insert end a b c d
2024     catch {.l itemcget 0} result
2025     set result
2026 } {wrong # args: should be ".l itemcget index option"}
2027 test listbox-24.3 {itemcget, itemcg shortcut} {
2028     catch {destroy .l}
2029     listbox .l
2030     .l insert end a b c d
2031     catch {.l itemcg 0} result
2032     set result
2033 } {wrong # args: should be ".l itemcget index option"}
2034
2035 # General item configuration issues
2036 test listbox-25.1 {listbox item configurations and widget based deletions} {
2037     catch {destroy .l}
2038     listbox .l
2039     .l insert end a
2040     .l itemconfigure 0 -fg red
2041     .l delete 0 end
2042     .l insert end a
2043     .l itemcget 0 -fg
2044 } {}
2045 test listbox-25.2 {listbox item configurations and widget based inserts} {
2046     catch {destroy .l}
2047     listbox .l
2048     .l insert end a b c
2049     .l itemconfigure 0 -fg red
2050     .l insert 0 1 2 3 4
2051     list [.l itemcget 0 -fg] [.l itemcget 4 -fg]
2052 } [list {} red]
2053     
2054
2055
2056 resetGridInfo
2057 catch {destroy .l2}
2058 catch {destroy .t}
2059 catch {destroy .e}
2060 catch {destroy .partial}
2061 option clear
2062
2063 # cleanup
2064 ::tcltest::cleanupTests
2065 return