1# This file is a Tcl script to test out the *NEW* "grid" command
2# of Tk.  It is (almost) organized in the standard fashion for Tcl tests.
3#
4# Copyright (c) 1996 Sun Microsystems, Inc.
5# Copyright (c) 1998-1999 by Scriptics Corporation.
6# All rights reserved.
7#
8# RCS: @(#) $Id: grid.test,v 1.17.2.4 2006/04/12 22:31:01 pspjuth Exp $
9
10package require tcltest 2.1
11namespace import -force tcltest::configure
12namespace import -force tcltest::testsDirectory
13configure -testdir [file join [pwd] [file dirname [info script]]]
14configure -loadfile [file join [testsDirectory] constraints.tcl]
15tcltest::loadTestedCommands
16
17# helper routine to return "." to a sane state after a test
18# The variable GRID_VERBOSE can be used to "look" at the result
19# of one or all of the tests
20
21proc grid_reset {{test ?} {top .}} {
22    global GRID_VERBOSE
23    if {[info exists GRID_VERBOSE]} {
24	if {$GRID_VERBOSE=="" || $GRID_VERBOSE==$test} {
25	    puts -nonewline "grid test $test: "
26	    flush stdout
27	    gets stdin
28	}
29    }
30    eval destroy [winfo children $top]
31    update
32    foreach {cols rows} [grid size .] {}
33    for {set i 0} {$i <= $cols} {incr i} {
34    	grid columnconfigure . $i -weight 0 -minsize 0 -pad 0 -uniform ""
35    }
36    for {set i 0} {$i <= $rows} {incr i} {
37    	grid rowconfigure . $i -weight 0 -minsize 0 -pad 0 -uniform ""
38    }
39    grid propagate . 1
40    update
41}
42
43grid_reset 0.0
44wm geometry . {}
45
46test grid-1.1 {basic argument checking} {
47	list [catch grid msg] $msg
48} {1 {wrong # args: should be "grid option arg ?arg ...?"}}
49
50test grid-1.2 {basic argument checking} {
51	list [catch {grid foo bar} msg] $msg
52} {1 {bad option "foo": must be bbox, columnconfigure, configure, forget, info, location, propagate, remove, rowconfigure, size, or slaves}}
53
54test grid-1.3 {basic argument checking} {
55	button .b
56	list [catch {grid .b -row 0 -column} msg] $msg
57} {1 {extra option or option with no value}}
58grid_reset 1.3
59
60test grid-1.4 {basic argument checking} {
61	button .b
62	list [catch {grid configure .b - foo} msg] $msg
63} {1 {unexpected parameter, "foo", in configure list. Should be window name or option}}
64grid_reset 1.4
65
66test grid-1.5 {basic argument checking} {
67	list [catch {grid .} msg] $msg
68} {1 {can't manage ".": it's a top-level window}}
69
70test grid-1.6 {basic argument checking} {
71	list [catch {grid x} msg] $msg
72} {1 {can't determine master window}}
73
74test grid-1.7 {basic argument checking} {
75	list [catch {grid configure x} msg] $msg
76} {1 {can't determine master window}}
77
78test grid-1.8 {basic argument checking} {
79	button .b
80	list [catch {grid x .b} msg] $msg
81} {0 {}}
82grid_reset 1.8
83
84test grid-1.9 {basic argument checking} {
85	button .b
86	list [catch {grid configure x .b} msg] $msg
87} {0 {}}
88grid_reset 1.9
89
90test grid-2.1 {bbox} {
91	list [catch {grid bbox .} msg] $msg
92} {0 {0 0 0 0}}
93
94test grid-2.2 {bbox} {
95	button .b
96	grid .b
97	destroy .b
98	update
99	list [catch {grid bbox .} msg] $msg
100} {0 {0 0 0 0}}
101
102test grid-2.3 {bbox: argument checking} {
103	list [catch {grid bbox . 0 0 5} msg] $msg
104} {1 {wrong # args: should be "grid bbox master ?column row ?column row??"}}
105
106test grid-2.4 {bbox} {
107	list [catch {grid bbox .bad 0 0} msg] $msg
108} {1 {bad window path name ".bad"}}
109
110test grid-2.5 {bbox} {
111	list [catch {grid bbox . x 0} msg] $msg
112} {1 {expected integer but got "x"}}
113
114test grid-2.6 {bbox} {
115	list [catch {grid bbox . 0 x} msg] $msg
116} {1 {expected integer but got "x"}}
117
118test grid-2.7 {bbox} {
119	list [catch {grid bbox . 0 0 x 0} msg] $msg
120} {1 {expected integer but got "x"}}
121
122test grid-2.8 {bbox} {
123	list [catch {grid bbox . 0 0 0 x} msg] $msg
124} {1 {expected integer but got "x"}}
125
126test grid-2.9 {bbox} {
127    frame .1 -width 75 -height 75 -bg red
128    frame .2 -width 90 -height 90 -bg red
129    grid .1 -row 0 -column 0
130    grid .2 -row 1 -column 1
131    update
132    set a ""
133    lappend a [grid bbox .]
134    lappend a [grid bbox . 0 0]
135    lappend a [grid bbox . 0 0 1 1]
136    lappend a [grid bbox . 1 1]
137    set a
138} {{0 0 165 165} {0 0 75 75} {0 0 165 165} {75 75 90 90}}
139grid_reset 2.9
140
141test grid-2.10 {bbox} {
142    frame .1 -width 75 -height 75 -bg red
143    frame .2 -width 90 -height 90 -bg red
144    grid .1 -row 0 -column 0
145    grid .2 -row 1 -column 1
146    update
147    set a ""
148    lappend a [grid bbox . 10 10 0 0]
149    lappend a [grid bbox . -2 -2 -1 -1]
150    lappend a [grid bbox . 10 10 12 12]
151    set a
152} {{0 0 165 165} {0 0 0 0} {165 165 0 0}}
153grid_reset 2.10
154
155test grid-3.1 {configure: basic argument checking} {
156    list [catch {grid configure foo} msg] $msg
157} {1 {bad argument "foo": must be name of window}}
158
159test grid-3.2 {configure: basic argument checking} {
160    button .b
161    grid configure .b
162    grid slaves .
163} {.b}
164grid_reset 3.2
165
166test grid-3.3 {configure: basic argument checking} {
167    button .b
168    list [catch {grid .b -row -1} msg] $msg
169} {1 {bad grid value "-1": must be a non-negative integer}}
170grid_reset 3.3
171
172test grid-3.4 {configure: basic argument checking} {
173    button .b
174    list [catch {grid .b -column -1} msg] $msg
175} {1 {bad column value "-1": must be a non-negative integer}}
176grid_reset 3.4
177
178test grid-3.5 {configure: basic argument checking} {
179    button .b
180    list [catch {grid .b -rowspan 0} msg] $msg
181} {1 {bad rowspan value "0": must be a positive integer}}
182grid_reset 3.5
183
184test grid-3.6 {configure: basic argument checking} {
185    button .b
186    list [catch {grid .b -columnspan 0} msg] $msg
187} {1 {bad columnspan value "0": must be a positive integer}}
188grid_reset 3.6
189
190test grid-3.7 {configure: basic argument checking} {
191    frame .f
192    button .f.b
193    list [catch {grid .f .f.b} msg] $msg
194} {1 {can't put .f.b inside .}}
195grid_reset 3.7
196
197test grid-3.8 {configure: basic argument checking} {
198    button .b
199    grid configure x .b
200    grid slaves .
201} {.b}
202grid_reset 3.8
203
204test grid-3.9 {configure: basic argument checking} {
205    button .b
206    list [catch {grid configure y .b} msg] $msg
207} {1 {invalid window shortcut, "y" should be '-', 'x', or '^'}}
208grid_reset 3.9
209
210test grid-4.1 {forget: basic argument checking} {
211    list [catch {grid forget foo} msg] $msg
212} {1 {bad window path name "foo"}}
213
214test grid-4.2 {forget} {
215    button .c
216    grid [button .b]
217    set a [grid slaves .]
218    grid forget .b .c
219    lappend a [grid slaves .]
220    set a
221} {.b {}}
222grid_reset 4.2
223
224test grid-4.3 {forget} {
225    button .c
226    grid .c -row 2 -column 2 -rowspan 2 -columnspan 2 -padx 3 -pady 4 -sticky ns
227    grid forget .c
228    grid .c -row 0 -column 0
229    grid info .c
230} {-in . -column 0 -row 0 -columnspan 1 -rowspan 1 -ipadx 0 -ipady 0 -padx 0 -pady 0 -sticky {}}
231grid_reset 4.3
232
233test grid-4.3.1 {forget} {
234    button .c
235    grid .c -row 2 -column 2 -rowspan 2 -columnspan 2 -padx {3 5} -pady {4 7} -sticky ns
236    grid forget .c
237    grid .c -row 0 -column 0
238    grid info .c
239} {-in . -column 0 -row 0 -columnspan 1 -rowspan 1 -ipadx 0 -ipady 0 -padx 0 -pady 0 -sticky {}}
240grid_reset 4.3.1
241
242test grid-4.4 {forget, calling Tk_UnmaintainGeometry} {
243    frame .f -bd 2 -relief raised
244    place .f -x 10 -y 20 -width 200 -height 100
245    frame .f2 -width 50 -height 30 -bg red
246    grid .f2 -in .f
247    update
248    set x [winfo ismapped .f2]
249    grid forget .f2
250    place .f -x 30
251    update
252    lappend x [winfo ismapped .f2]
253} {1 0}
254grid_reset 4.4
255
256test grid-5.1 {info: basic argument checking} {
257	list [catch {grid info a b} msg] $msg
258} {1 {wrong # args: should be "grid info window"}}
259
260test grid-5.2 {info} {
261    frame .1 -width 75 -height 75 -bg red
262    grid .1 -row 0 -column 0
263    update
264    list [catch {grid info .x} msg] $msg
265} {1 {bad window path name ".x"}}
266grid_reset 5.2
267
268test grid-5.3 {info} {
269    frame .1 -width 75 -height 75 -bg red
270    grid .1 -row 0 -column 0
271    update
272    list [catch {grid info .1} msg] $msg
273} {0 {-in . -column 0 -row 0 -columnspan 1 -rowspan 1 -ipadx 0 -ipady 0 -padx 0 -pady 0 -sticky {}}}
274grid_reset 5.3
275
276test grid-5.4 {info} {
277    frame .1 -width 75 -height 75 -bg red
278    update
279    list [catch {grid info .1} msg] $msg
280} {0 {}}
281grid_reset 5.4
282
283test grid-6.1 {location: basic argument checking} {
284	list [catch "grid location ." msg] $msg
285} {1 {wrong # args: should be "grid location master x y"}}
286
287test grid-6.2 {location: basic argument checking} {
288	list [catch "grid location .bad 0 0" msg] $msg
289} {1 {bad window path name ".bad"}}
290
291test grid-6.3 {location: basic argument checking} {
292	list [catch "grid location . x y" msg] $msg
293} {1 {bad screen distance "x"}}
294
295test grid-6.4 {location: basic argument checking} {
296	list [catch "grid location . 1c y" msg] $msg
297} {1 {bad screen distance "y"}}
298
299test grid-6.5 {location: basic argument checking} {
300	frame .f
301	grid location .f 10 10
302} {-1 -1}
303grid_reset 6.5
304
305test grid-6.6 {location (x)} {
306    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
307    grid .f
308    update
309    set got ""
310    set result ""
311    for {set x -10} { $x < 220} { incr x} {
312	set a [grid location . $x 0]
313	if {$a != $got} {
314	    lappend result $x->$a
315	    set got $a
316	}
317    }
318    set result
319} {{-10->-1 0} {0->0 0} {201->1 0}}
320grid_reset 6.6
321
322test grid-6.7 {location (y)} {
323    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
324    grid .f
325    update
326    set got ""
327    set result ""
328    for {set y -10} { $y < 110} { incr y} {
329	set a [grid location . 0 $y]
330	if {$a != $got} {
331	    lappend result $y->$a
332	    set got $a
333	}
334    }
335    set result
336} {{-10->0 -1} {0->0 0} {101->0 1}}
337grid_reset 6.7
338
339test grid-6.8 {location (weights)} {
340    frame .f -width 300 -height 100 -highlightthickness 0 -bg red
341    frame .a
342    grid .a
343    grid .f -in .a
344    grid rowconfigure .f 0 -weight 1
345    grid columnconfigure .f 0 -weight 1
346    grid propagate .a 0
347    .a configure -width 200 -height 15
348    update
349    set got ""
350    set result ""
351    for {set y -10} { $y < 210} { incr y} {
352	set a [grid location . $y $y]
353	if {$a != $got} {
354	    lappend result $y->$a
355	    set got $a
356	}
357    }
358    set result
359} {{-10->-1 -1} {0->0 0} {16->0 1} {201->1 1}}
360grid_reset 6.8
361
362test grid-6.9 {location: check updates pending} {nonPortable} {
363	set a ""
364	foreach i {0 1 2} {
365	    frame .$i -width 120 -height 75 -bg red
366	    lappend a [grid location . 150 90]
367	    grid .$i -row $i -column $i
368	}
369	set a
370} {{0 0} {1 1} {1 1}}
371grid_reset 6.9
372
373test grid-7.1 {propagate} {
374    list [catch {grid propagate . 1 xxx} msg] $msg
375} {1 {wrong # args: should be "grid propagate window ?boolean?"}}
376grid_reset 7.1
377
378test grid-7.2 {propagate} {
379    list [catch {grid propagate .} msg] $msg
380} {0 1}
381grid_reset 7.2
382
383test grid-7.3 {propagate} {
384    list [catch {grid propagate . 0;grid propagate .} msg] $msg
385} {0 0}
386grid_reset 7.3
387
388test grid-7.4 {propagate} {
389    list [catch {grid propagate .x} msg] $msg
390} {1 {bad window path name ".x"}}
391grid_reset 7.4
392
393test grid-7.5 {propagate} {
394    list [catch {grid propagate . x} msg] $msg
395} {1 {expected boolean value but got "x"}}
396grid_reset 7.5
397
398test grid-7.6 {propagate} {
399    frame .f -width 100 -height 100 -bg red
400    grid .f -row 0 -column 0
401    update
402    set a [winfo width .f]x[winfo height .f]
403    grid propagate .f 0
404    frame .g -width 75 -height 85 -bg green
405    grid .g -in .f -row 0 -column 0
406    update
407    lappend a [winfo width .f]x[winfo height .f]
408    grid propagate .f 1
409    update
410    lappend a [winfo width .f]x[winfo height .f]
411    set a
412} {100x100 100x100 75x85}
413grid_reset 7.6
414test grid-7.7 {propagate} {
415    grid propagate . 1
416    set res [list [grid propagate .]]
417    grid propagate . 0
418    lappend res [grid propagate .]
419    grid propagate . 0
420    lappend res [grid propagate .]
421    set res
422} [list 1 0 0]
423grid_reset 7.7
424
425test grid-8.1 {size} {
426    list [catch {grid size . foo} msg] $msg
427} {1 {wrong # args: should be "grid size window"}}
428grid_reset 8.1
429
430test grid-8.2 {size} {
431    list [catch {grid size .x} msg] $msg
432} {1 {bad window path name ".x"}}
433grid_reset 8.2
434
435test grid-8.3 {size} {
436    frame .f
437    list [catch {grid size .f} msg] $msg
438} {0 {0 0}}
439grid_reset 8.3
440
441test grid-8.4 {size} {
442    catch {unset a}
443    scale .f
444    grid .f -row 0 -column 0
445    update
446    lappend a [grid size .]
447    grid .f -row 4 -column 5
448    update
449    lappend a [grid size .]
450    grid .f -row 947 -column 663
451    update
452    lappend a [grid size .]
453    grid .f -row 0 -column 0
454    update
455    lappend a [grid size .]
456    set a
457} {{1 1} {6 5} {664 948} {1 1}}
458grid_reset 8.4
459
460test grid-8.5 {size} {
461    catch {unset a}
462    scale .f
463    grid .f -row 0 -column 0
464    update
465    lappend a [grid size .]
466    grid rowconfigure . 17 -weight 1
467    update
468    lappend a [grid size .]
469    grid columnconfigure . 63 -weight 1
470    update
471    lappend a [grid size .]
472    grid columnconfigure . 63 -weight 0
473    grid rowconfigure . 17 -weight 0
474    update
475    lappend a [grid size .]
476    set a
477} {{1 1} {1 18} {64 18} {1 1}}
478grid_reset 8.5
479
480test grid-8.6 {size} {
481    catch {unset a}
482    scale .f
483    grid .f -row 10 -column 50
484    update
485    lappend a [grid size .]
486    grid columnconfigure . 15 -weight 1
487    grid columnconfigure . 30 -weight 1
488    update
489    lappend a [grid size .]
490    grid .f -row 10 -column 20
491    update
492    lappend a [grid size .]
493    grid columnconfigure . 30 -weight 0
494    update
495    lappend a [grid size .]
496    grid .f -row 0 -column 0
497    update
498    lappend a [grid size .]
499    grid columnconfigure . 15 -weight 0
500    update
501    lappend a [grid size .]
502    set a
503} {{51 11} {51 11} {31 11} {21 11} {16 1} {1 1}}
504grid_reset 8.6
505
506test grid-9.1 {slaves} {
507	list [catch {grid slaves .} msg] $msg
508} {0 {}}
509
510test grid-9.2 {slaves} {
511	list [catch {grid slaves .foo} msg] $msg
512} {1 {bad window path name ".foo"}}
513
514test grid-9.3 {slaves} {
515	list [catch {grid slaves a b} msg] $msg
516} {1 {wrong # args: should be "grid slaves window ?-option value...?"}}
517
518test grid-9.4 {slaves} {
519	list [catch {grid slaves . a b} msg] $msg
520} {1 {bad option "a": must be -column or -row}}
521
522test grid-9.5 {slaves} {
523	list [catch {grid slaves . -column x} msg] $msg
524} {1 {expected integer but got "x"}}
525
526test grid-9.6 {slaves} {
527	list [catch {grid slaves . -row -3} msg] $msg
528} {1 {-row is an invalid value: should NOT be < 0}}
529
530test grid-9.7 {slaves} {
531	list [catch {grid slaves . -foo 3} msg] $msg
532} {1 {bad option "-foo": must be -column or -row}}
533
534test grid-9.8 {slaves} {
535	list [catch {grid slaves .x -row 3} msg] $msg
536} {1 {bad window path name ".x"}}
537
538test grid-9.9 {slaves} {
539	list [catch {grid slaves . -row 3} msg] $msg
540} {0 {}}
541
542test grid-9.10 {slaves} {
543	foreach i {0 1 2} {
544	    label .$i -text $i
545	    grid .$i -row $i -column $i
546	}
547	list [catch {grid slaves .} msg] $msg
548} {0 {.2 .1 .0}}
549grid_reset 9.10
550
551test grid-9.11 {slaves} {
552    catch {unset a}
553    foreach i {0 1 2} {
554	label .$i -text $i
555	label .$i-x -text $i-x
556	grid .$i -row $i -column $i
557	grid .$i-x -row $i -column [incr i]
558    }
559    foreach row {0 1 2 3} {
560	lappend a $row{[grid slaves . -row $row]}
561    }
562    foreach col {0 1 2 3} {
563	lappend a $col{[grid slaves . -column $col]}
564    }
565    set a
566} {{0{.0-x .0}} {1{.1-x .1}} {2{.2-x .2}} 3{} 0{.0} {1{.1 .0-x}} {2{.2 .1-x}} 3{.2-x}} 
567grid_reset 9.11
568
569# column/row configure
570
571test grid-10.1 {column/row configure} {
572	list [catch {grid columnconfigure .} msg] $msg
573} {1 {wrong # args: should be "grid columnconfigure master index ?-option value...?"}}
574grid_reset 10.1
575
576test grid-10.2 {column/row configure} {
577	list [catch {grid columnconfigure . 0 -weight 0 -pad} msg] $msg
578} {1 {wrong # args: should be "grid columnconfigure master index ?-option value...?"}}
579grid_reset 10.2
580
581test grid-10.3 {column/row configure} {
582	list [catch {grid columnconfigure .f 0 -weight} msg] $msg
583} {1 {bad window path name ".f"}}
584grid_reset 10.3
585
586test grid-10.4 {column/row configure} {
587	list [catch {grid columnconfigure . nine -weight} msg] $msg
588} {1 {expected integer but got "nine"}}
589grid_reset 10.4
590
591test grid-10.5 {column/row configure} {
592	list [catch {grid columnconfigure . 265 -weight} msg] $msg
593} {0 0}
594grid_reset 10.5
595
596test grid-10.6 {column/row configure} {
597	list [catch {grid columnconfigure . 0} msg] $msg
598} {0 {-minsize 0 -pad 0 -uniform {} -weight 0}}
599grid_reset 10.6
600
601test grid-10.7 {column/row configure} {
602	list [catch {grid columnconfigure . 0 -foo} msg] $msg
603} {1 {bad option "-foo": must be -minsize, -pad, -uniform, or -weight}}
604grid_reset 10.7
605
606test grid-10.8 {column/row configure} {
607	list [catch {grid columnconfigure . 0 -minsize foo} msg] $msg
608} {1 {bad screen distance "foo"}}
609grid_reset 10.8
610
611test grid-10.9 {column/row configure} {
612	list [catch {grid columnconfigure . 0 -minsize foo} msg] $msg
613} {1 {bad screen distance "foo"}}
614grid_reset 10.9
615
616test grid-10.10 {column/row configure} {
617	grid columnconfigure . 0 -minsize 10
618	grid columnconfigure . 0 -minsize
619} {10}
620grid_reset 10.10
621
622test grid-10.11 {column/row configure} {
623	list [catch {grid columnconfigure . 0 -weight bad} msg] $msg
624} {1 {expected integer but got "bad"}}
625grid_reset 10.11
626
627test grid-10.12 {column/row configure} {
628	list [catch {grid columnconfigure . 0 -weight -3} msg] $msg
629} {1 {invalid arg "-weight": should be non-negative}}
630grid_reset 10.12
631
632test grid-10.13 {column/row configure} {
633	grid columnconfigure . 0 -weight 3
634	grid columnconfigure . 0 -weight
635} {3}
636grid_reset 10.13
637
638test grid-10.14 {column/row configure} {
639	list [catch {grid columnconfigure . 0 -pad foo} msg] $msg
640} {1 {bad screen distance "foo"}}
641grid_reset 10.14
642
643test grid-10.15 {column/row configure} {
644	list [catch {grid columnconfigure . 0 -pad -3} msg] $msg
645} {1 {invalid arg "-pad": should be non-negative}}
646grid_reset 10.15
647
648test grid-10.16 {column/row configure} {
649	grid columnconfigure . 0 -pad 3
650	grid columnconfigure . 0 -pad
651} {3}
652grid_reset 10.16
653
654test grid-10.17 {column/row configure} {
655	frame .f
656	set a ""
657	grid columnconfigure .f 0 -weight 0
658	lappend a [grid columnconfigure .f 0 -weight]
659	grid columnconfigure .f 0 -weight 1
660	lappend a [grid columnconfigure .f 0 -weight]
661	grid rowconfigure .f 0 -weight 0
662	lappend a [grid rowconfigure .f 0 -weight]
663	grid rowconfigure .f 0 -weight 1
664	lappend a [grid columnconfigure .f 0 -weight]
665	grid columnconfigure .f 0 -weight 0
666	set a
667} {0 1 0 1}
668grid_reset 10.17
669
670test grid-10.18 {column/row configure} {
671	frame .f
672	grid columnconfigure .f {0 2} -minsize 10 -weight 1
673	list [grid columnconfigure .f 0 -minsize] \
674		[grid columnconfigure .f 1 -minsize] \
675		[grid columnconfigure .f 2 -minsize] \
676		[grid columnconfigure .f 0 -weight] \
677		[grid columnconfigure .f 1 -weight] \
678		[grid columnconfigure .f 2 -weight]
679}  {10 0 10 1 0 1}
680grid_reset 10.18
681
682test grid-10.19 {column/row configure} {
683	list [catch {grid columnconfigure . {0 -1 2} -weight 1} msg] $msg
684} {1 {grid columnconfigure: "-1" is out of range}}
685grid_reset 10.19
686
687test grid-10.20 {column/row configure} {
688	grid columnconfigure . 0 -uniform foo
689	grid columnconfigure . 0 -uniform
690} {foo}
691grid_reset 10.20
692
693test grid-10.30 {column/row configure - no indices} {
694    # Bug 1422430
695    set t [toplevel .test]
696    set res [list [catch {grid columnconfigure $t "" -weight 1} msg] $msg]
697    destroy $t
698    set res
699} {1 {no column indices specified}}
700
701test grid-10.31 {column/row configure - no indices} {
702    set t [toplevel .test]
703    set res [list [catch {grid rowconfigure $t "" -weight 1} msg] $msg]
704    destroy $t
705    set res
706} {1 {no row indices specified}}
707
708test grid-10.32 {column/row configure - invalid indices} {
709    list [catch {grid columnconfigure . {0 1 2} -weight} msg] $msg
710} {1 {grid columnconfigure: must specify a single element on retrieval}}
711
712test grid-10.33 {column/row configure - invalid indices} {
713    list [catch {grid rowconfigure . {0 1 2} -weight} msg] $msg
714} {1 {grid rowconfigure: must specify a single element on retrieval}}
715
716test grid-10.37 {column/row configure} {
717    list [catch {grid columnconfigure . 100000} msg] $msg
718} {0 {-minsize 0 -pad 0 -uniform {} -weight 0}}
719grid_reset 10.37
720
721test grid-10.38 {column/row configure} -body {
722    # This is a test for bug 1423666 where a column >= 10000 caused
723    # a crash in layout.  The update is needed to reach the layout stage.
724    # Test different combinations of row/column overflow
725    frame .f
726    set res {}
727    grid .f -column 0 -columnspan 1 -row 0 -rowspan 1
728    lappend res [catch {grid .f -row 10 -column 9999} msg] $msg ; update
729    lappend res [catch {grid .f -row 9999 -column 10} msg] $msg ; update
730    lappend res [catch {grid .f -columnspan 2 -column 9998} msg] $msg ; update
731    lappend res [catch {grid .f -rowspan 2 -row 9998} msg] $msg ; update
732    grid .f -column 0 -columnspan 1 -row 0 -rowspan 1
733    lappend res [catch {grid .f -column 9998 -columnspan 2} msg] $msg ; update
734    grid .f -column 0 -columnspan 1 -row 0 -rowspan 1
735    lappend res [catch {grid .f -row 9998 -rowspan 2} msg] $msg ; update
736    set res
737} -cleanup {destroy .f} -result [lrange {
738    1 {Column out of bounds}
739    1 {Row out of bounds}
740    1 {Column out of bounds}
741    1 {Row out of bounds}
742    1 {Column out of bounds}
743    1 {Row out of bounds}
744} 0 end]
745grid_reset 10.38
746
747test grid-10.39 {column/row configure} -body {
748    # Additional tests for row/column overflow
749    frame .f
750    frame .g
751    set res {}
752    grid .f -row 9998 -column 0
753    lappend res [catch {grid ^ .g} msg] $msg  ; update
754    grid forget .g
755    lappend res [catch {grid .g} msg] $msg  ; update
756    grid forget .f .g
757    lappend res [catch {grid .f - -column 9998} msg] $msg ; update
758    grid forget .f .g
759    lappend res [catch {eval grid [string repeat " x " 9999] .f} msg] $msg
760    update
761    set res
762} -cleanup {destroy .f .g} -result [lrange {
763    1 {Row out of bounds}
764    1 {Row out of bounds}
765    1 {Column out of bounds}
766    1 {Column out of bounds}
767} 0 end]
768grid_reset 10.39
769
770# auto-placement tests
771
772test grid-11.1 {default widget placement} {
773	list [catch {grid ^} msg] $msg
774} {1 {can't use '^', cant find master}}
775grid_reset 11.1
776
777test grid-11.2 {default widget placement} {
778	button .b
779	list [catch {grid .b ^} msg] $msg
780} {1 {can't find slave to extend with "^".}}
781grid_reset 11.2
782
783test grid-11.3 {default widget placement} {
784	button .b
785	list [catch {grid .b - - .c} msg] $msg
786} {1 {bad window path name ".c"}}
787grid_reset 11.3
788
789test grid-11.4 {default widget placement} {
790	button .b
791	list [catch {grid .b - - = -} msg] $msg
792} {1 {invalid window shortcut, "=" should be '-', 'x', or '^'}}
793grid_reset 11.4
794
795test grid-11.5 {default widget placement} {
796	button .b
797	list [catch {grid .b - x -} msg] $msg
798} {1 {Must specify window before shortcut '-'.}}
799grid_reset 11.5
800
801test grid-11.6 {default widget placement} {
802    foreach i {1 2 3 4 5 6} {
803	frame .f$i -width 50 -height 50 -highlightthickness 0 -bg red
804    }
805    grid .f1 .f2 .f3 .f4
806    grid .f5   -  x  .f6 -sticky nsew
807    update
808    set a ""
809    foreach i {5 6} {
810	lappend a "[winfo x .f$i],[winfo y .f$i] \
811		[winfo width .f$i],[winfo height .f$i]"
812    }
813    set a
814} {{0,50  100,50} {150,50  50,50}}
815grid_reset 11.6
816
817test grid-11.7 {default widget placement} {
818    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
819    grid .f -row 5 -column 5
820    list [catch "grid .f x -" msg] $msg
821} {1 {Must specify window before shortcut '-'.}}
822grid_reset 11.7
823
824test grid-11.8 {default widget placement} {
825    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
826    grid .f -row 5 -column 5
827    list [catch "grid .f ^ -" msg] $msg
828} {1 {Must specify window before shortcut '-'.}}
829grid_reset 11.8
830
831test grid-11.9 {default widget placement} {
832    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
833    grid .f -row 5 -column 5
834    list [catch "grid .f x ^" msg] $msg
835} {1 {can't find slave to extend with "^".}}
836grid_reset 11.9
837
838test grid-11.10 {default widget placement} {
839    foreach i {1 2 3} {
840		frame .f$i -width 100 -height 50 -highlightthickness 0 -bg red
841    }
842    grid .f1 .f2  -sticky nsew
843    grid .f3   ^  -sticky nsew
844    update
845    set a ""
846    foreach i {1 2 3} {
847	lappend a "[winfo x .f$i],[winfo y .f$i] \
848		[winfo width .f$i],[winfo height .f$i]"
849    }
850    set a
851} {{0,0  100,50} {100,0  100,100} {0,50  100,50}}
852grid_reset 11.10
853
854test grid-11.11 {default widget placement} {
855    foreach i {1 2 3 4 5 6 7 8 9 10 11 12} {
856		frame .f$i -width 50 -height 50 -highlightthickness 1 -highlightbackground black
857    }
858    grid .f1  .f2  .f3 .f4 -sticky nsew
859    grid .f5  .f6   -  .f7  -sticky nsew
860    grid .f8    ^   ^  .f9  -sticky nsew
861    grid .f10   ^   ^  .f11  -sticky nsew
862	grid .f12   -   -   - -sticky nsew
863    update
864    set a ""
865    foreach i {5 6 7 8 9 10 11 12 } {
866	lappend a "[winfo x .f$i],[winfo y .f$i] \
867		[winfo width .f$i],[winfo height .f$i]"
868    }
869    set a
870} {{0,50  50,50} {50,50  100,150} {150,50  50,50} {0,100  50,50} {150,100  50,50} {0,150  50,50} {150,150  50,50} {0,200  200,50}}
871grid_reset 11.11
872
873test grid-11.12 {default widget placement} {
874    foreach i {1 2 3 4} {
875		frame .f$i -width 75 -height 50 -highlightthickness 1 -highlightbackground black
876    }
877    grid .f1  .f2   .f3     -sticky nsew
878    grid .f4    ^           -sticky nsew
879    update
880    set a ""
881    foreach i {1 2 3 4} {
882		lappend a "[winfo x .f$i],[winfo y .f$i] \
883			[winfo width .f$i],[winfo height .f$i]"
884    }
885    grid .f4    ^   -column 1
886    update
887    foreach i {1 2 3 4} {
888		lappend a "[winfo x .f$i],[winfo y .f$i] \
889			[winfo width .f$i],[winfo height .f$i]"
890	}
891	set a
892} {{0,0  75,50} {75,0  75,100} {150,0  75,50} {0,50  75,50} {0,0  75,50} {75,0  75,100} {150,0  75,100} {75,50  75,50}}
893grid_reset 11.12
894
895test grid-11.13 {default widget placement} {
896    foreach i {1 2 3 4 5 6 7} {
897		frame .f$i -width 40 -height 50 -highlightthickness 1 -highlightbackground black
898    }
899    grid .f1  .f2  .f3 .f4 .f5 -sticky nsew
900    grid .f6    -  .f7         -sticky nsew -columnspan 2
901    update
902    set a ""
903    foreach i {6 7} {
904	lappend a "[winfo x .f$i],[winfo y .f$i] \
905		[winfo width .f$i],[winfo height .f$i]"
906    }
907    set a
908} {{0,50  120,50} {120,50  80,50}}
909grid_reset 11.13
910
911test grid-11.14 {default widget placement} {
912    foreach i {1 2 3} {
913	frame .f$i -width 60 -height 60 -highlightthickness 0 -bg red
914    }
915    grid .f1 .f2
916    grid  ^  .f3
917    update
918    set a ""
919    foreach i {1 2 3} {
920	lappend a "[winfo x .f$i],[winfo y .f$i] \
921		[winfo width .f$i],[winfo height .f$i]"
922    }
923    set a
924} {{0,30  60,60} {60,0  60,60} {60,60  60,60}}
925grid_reset 11.14
926
927test grid-11.15 {^ ^ test with multiple windows} {
928    foreach i {1 2 3 4} {
929	frame .f$i -width 50 -height 50 -bd 1 -relief solid
930    }
931    grid .f1 .f2 .f3 -sticky ns
932    grid .f4 ^ ^
933    update
934    set a ""
935    foreach i {1 2 3 4} {
936	lappend a "[winfo x .f$i],[winfo y .f$i]\
937		[winfo width .f$i],[winfo height .f$i]"
938    }
939    set a
940} {{0,0 50,50} {50,0 50,100} {100,0 50,100} {0,50 50,50}}
941grid_reset 11.15
942
943test grid-11.16 {default widget placement} {
944    foreach l {a b c d e} {
945        frame .$l -width 50 -height 50
946    }
947    grid .a .b .c .d -sticky news 
948    grid  x  ^  x .e -sticky news
949    update
950    set res ""
951    lappend res [winfo height .a]
952    lappend res [winfo height .b]
953    lappend res [winfo height .c]
954} {50 100 50}
955grid_reset 11.16
956
957test grid-11.17 {default widget placement} {
958    foreach l {a b c d e} {
959        frame .$l -width 50 -height 50
960    }
961    grid .a .b .c .d -sticky news
962    grid  ^  x  ^ .e -sticky news
963    update
964    set res ""
965    lappend res [winfo height .a]
966    lappend res [winfo height .b]
967    lappend res [winfo height .c]
968} {100 50 100}
969grid_reset 11.17
970
971test grid-12.1 {-sticky} {
972    catch {unset data}
973    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
974    set a ""
975    grid .f
976    grid rowconfigure . 0 -weight 1
977    grid columnconfigure . 0 -weight 1
978    grid propagate . 0
979    . configure -width 250 -height 150
980    foreach i { {} n s e w ns ew nw ne se sw nse nsw sew new nsew} {
981	grid .f -sticky $i
982	update
983	array set data [grid info .f]
984	append a "($data(-sticky)) [winfo x .f] [winfo y .f] [winfo width .f] [winfo height .f]\n"
985    }
986    set a
987} {() 25 25 200 100
988(n) 25 0 200 100
989(s) 25 50 200 100
990(e) 50 25 200 100
991(w) 0 25 200 100
992(ns) 25 0 200 150
993(ew) 0 25 250 100
994(nw) 0 0 200 100
995(ne) 50 0 200 100
996(es) 50 50 200 100
997(sw) 0 50 200 100
998(nes) 50 0 200 150
999(nsw) 0 0 200 150
1000(esw) 0 50 250 100
1001(new) 0 0 250 100
1002(nesw) 0 0 250 150
1003}
1004grid_reset 12.1
1005   
1006test grid-12.2 {-sticky} {
1007    frame .f -bg red
1008    list [catch "grid .f -sticky glue" msg] $msg
1009} {1 {bad stickyness value "glue": must be a string containing n, e, s, and/or w}}
1010grid_reset 12.2
1011   
1012test grid-12.3 {-sticky} {
1013    frame .f -bg red
1014    grid .f -sticky {n,s,e,w}
1015    array set A [grid info .f]
1016    set A(-sticky)
1017} {nesw}
1018grid_reset 12.3
1019
1020test grid-13.1 {-in} {
1021    frame .f -bg red
1022    list [catch "grid .f -in .f" msg] $msg
1023} {1 {Window can't be managed in itself}}
1024grid_reset 13.1
1025
1026test grid-13.2 {-in} {
1027    frame .f -bg red
1028    list [catch "grid .f -in .bad" msg] $msg
1029} {1 {bad window path name ".bad"}}
1030grid_reset 13.2
1031
1032test grid-13.3 {-in} {
1033    frame .f -bg red
1034    toplevel .top
1035    list [catch "grid .f -in .top" msg] $msg
1036} {1 {can't put .f inside .top}}
1037destroy .top
1038grid_reset 13.3
1039
1040test grid-13.4 {-ipadx} {
1041    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
1042    list [catch "grid .f -ipadx x" msg] $msg
1043} {1 {bad ipadx value "x": must be positive screen distance}}
1044grid_reset 13.4
1045
1046test grid-13.4.1 {-ipadx} {
1047    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
1048    list [catch "grid .f -ipadx {5 5}" msg] $msg
1049} {1 {bad ipadx value "5 5": must be positive screen distance}}
1050grid_reset 13.4.1
1051
1052test grid-13.5 {-ipadx} {
1053    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
1054    grid .f
1055    update
1056    set a [winfo width .f]
1057    grid .f -ipadx 1
1058    update
1059    list $a [winfo width .f]
1060} {200 202}
1061grid_reset 13.5
1062
1063test grid-13.6 {-ipady} {
1064    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
1065    list [catch "grid .f -ipady x" msg] $msg
1066} {1 {bad ipady value "x": must be positive screen distance}}
1067grid_reset 13.6
1068
1069test grid-13.6.1 {-ipady} {
1070    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
1071    list [catch "grid .f -ipady {5 5}" msg] $msg
1072} {1 {bad ipady value "5 5": must be positive screen distance}}
1073grid_reset 13.6.1
1074
1075test grid-13.7 {-ipady} {
1076    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
1077    grid .f
1078    update
1079    set a [winfo height .f]
1080    grid .f -ipady 1
1081    update
1082    list $a [winfo height .f]
1083} {100 102}
1084grid_reset 13.7
1085
1086test grid-13.8 {-padx} {
1087    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
1088    list [catch "grid .f -padx x" msg] $msg
1089} {1 {bad pad value "x": must be positive screen distance}}
1090grid_reset 13.8
1091
1092test grid-13.8.1 {-padx} {
1093    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
1094    list [catch "grid .f -padx {10 x}" msg] $msg
1095} {1 {bad 2nd pad value "x": must be positive screen distance}}
1096grid_reset 13.8.1
1097
1098test grid-13.9 {-padx} {
1099    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
1100    grid .f
1101    update
1102    set a "[winfo width .f] [winfo width .]"
1103    grid .f -padx 1
1104    update
1105    list $a "[winfo width .f] [winfo width .] [winfo x .f]"
1106} {{200 200} {200 202 1}}
1107grid_reset 13.9
1108
1109test grid-13.9.1 {-padx} {
1110    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
1111    grid .f
1112    update
1113    set a "[winfo width .f] [winfo width .]"
1114    grid .f -padx {10 5}
1115    update
1116    list $a "[winfo width .f] [winfo width .] [winfo x .f]"
1117} {{200 200} {200 215 10}}
1118grid_reset 13.9.1
1119
1120test grid-13.10 {-pady} {
1121    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
1122    list [catch "grid .f -pady x" msg] $msg
1123} {1 {bad pad value "x": must be positive screen distance}}
1124grid_reset 13.10
1125
1126test grid-13.10.1 {-pady} {
1127    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
1128    list [catch "grid .f -pady {10 x}" msg] $msg
1129} {1 {bad 2nd pad value "x": must be positive screen distance}}
1130grid_reset 13.10.1
1131
1132test grid-13.11 {-pady} {
1133    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
1134    grid .f
1135    update
1136    set a "[winfo height .f] [winfo height .]"
1137    grid .f -pady 1
1138    update
1139    list $a "[winfo height .f] [winfo height .] [winfo y .f]"
1140} {{100 100} {100 102 1}}
1141grid_reset 13.11
1142
1143test grid-13.11.1 {-pady} {
1144    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
1145    grid .f
1146    update
1147    set a "[winfo height .f] [winfo height .]"
1148    grid .f -pady {4 16}
1149    update
1150    list $a "[winfo height .f] [winfo height .] [winfo y .f]"
1151} {{100 100} {100 120 4}}
1152grid_reset 13.11.1
1153
1154test grid-13.12 {-ipad x and y} {
1155    frame .f -width 20 -height 20 -highlightthickness 0 -bg red
1156    grid columnconfigure . 0 -minsize 150
1157    grid rowconfigure . 0 -minsize 100
1158    set a ""
1159    foreach x {0 5} {
1160    	foreach y {0 5} {
1161	    grid .f -ipadx $x -ipady $y
1162	    update
1163	    append a " $x,$y:"
1164	    foreach prop {x y width height} {
1165	    	append a ,[winfo $prop .f]
1166	    }
1167	}
1168    }
1169    set a
1170} { 0,0:,65,40,20,20 0,5:,65,35,20,30 5,0:,60,40,30,20 5,5:,60,35,30,30}
1171grid_reset 13.12
1172
1173test grid-13.13 {reparenting} {
1174    frame .1
1175    frame .2
1176    button .b
1177    grid .1 .2
1178    grid .b -in .1
1179    set a ""
1180    catch {unset info}; array set info [grid info .b]
1181    lappend a [grid slaves .1],[grid slaves .2],$info(-in)
1182    grid .b -in .2
1183    catch {unset info}; array set info [grid info .b]
1184    lappend a [grid slaves .1],[grid slaves .2],$info(-in)
1185    unset info
1186    set a
1187} {.b,,.1 ,.b,.2}
1188grid_reset 13.13
1189
1190test grid-14.1 {structure notify} {
1191    frame .f -width 200 -height 100 -highlightthickness 0 -bg red
1192    frame .g -width 200 -height 100 -highlightthickness 0 -bg red
1193    grid .f 
1194    grid .g -in .f    
1195    update
1196    set a ""
1197    lappend a "[winfo x .g],[winfo y .g] \
1198        [winfo width .g],[winfo height .g]"
1199    .f configure -bd 5 -relief raised
1200    update
1201    lappend a "[winfo x .g],[winfo y .g] \
1202        [winfo width .g],[winfo height .g]"
1203    set a
1204} {{0,0  200,100} {5,5  200,100}}
1205grid_reset 14.1
1206
1207test grid-14.2 {structure notify} {
1208    frame .f -width 200 -height 100 
1209    frame .f.g -width 200 -height 100 
1210    grid .f 
1211    grid .f.g
1212    update
1213    set a ""
1214    lappend a [grid bbox .],[grid bbox .f]
1215    .f config -bd 20
1216    update
1217    lappend a [grid bbox .],[grid bbox .f]
1218} {{0 0 200 100,0 0 200 100} {0 0 240 140,20 20 200 100}}
1219grid_reset 14.2
1220
1221test grid-14.3 {map notify: bug 1648} {nonPortable} {
1222    # This test is nonPortable because the number of times
1223    # A(.) will be incremented is unspecified--the behavior
1224    # is different accross window managers.
1225    global A
1226    catch {unset A}
1227    bind . <Configure> {incr A(%W)}
1228    set A(.) 0
1229    foreach i {0 1 2} {
1230	frame .$i -width 100 -height 75
1231	set A(.$i) 0
1232    }
1233    grid .0 .1 .2
1234    update
1235    bind <Configure> .1 {destroy .0}
1236    .2 configure -bd 10
1237    update
1238    bind . <Configure> {}
1239    array get A
1240} {.2 2 .0 1 . 2 .1 1}
1241grid_reset 14.3
1242
1243test grid-15.1 {lost slave} {
1244    button .b
1245    grid .b
1246    set a [grid slaves .]
1247    pack .b
1248    lappend a [grid slaves .]
1249    grid .b
1250    lappend a [grid slaves .]
1251} {.b {} .b}
1252grid_reset 15.1
1253
1254test grid-15.2 {lost slave} {
1255    frame .f
1256    grid .f
1257    button .b
1258    grid .b -in .f
1259    set a [grid slaves .f]
1260    pack .b
1261    lappend a [grid slaves .f]
1262    grid .b -in .f
1263    lappend a [grid slaves .f]
1264} {.b {} .b}
1265grid_reset 15.2
1266
1267test grid-16.1 {layout centering} {
1268    foreach i {0 1 2} {
1269    	frame .$i -bg gray  -width 75 -height 50 -bd 2 -relief ridge
1270    	grid .$i -row $i -column $i -sticky nswe
1271    }
1272    grid propagate . 0
1273    . configure -width 300 -height 250
1274    update
1275    grid bbox .
1276} {37 50 225 150}
1277grid_reset 16.1
1278
1279test grid-16.2 {layout weights (expanding)} {
1280    foreach i {0 1 2} {
1281    	frame .$i -bg gray  -width 75 -height 50 -bd 2 -relief ridge
1282    	grid .$i -row $i -column $i -sticky nswe
1283    	grid rowconfigure . $i -weight [expr $i + 1]
1284    	grid columnconfigure . $i -weight [expr $i + 1]
1285    }
1286    grid propagate . 0
1287    . configure -width 500 -height 300
1288    set a ""
1289    update
1290    foreach i {0 1 2} {
1291	lappend a [winfo width .$i]-[winfo height .$i]
1292    }
1293    set a
1294} {120-75 167-100 213-125}
1295grid_reset 16.2
1296
1297test grid-16.3 {layout weights (shrinking)} {
1298    foreach i {0 1 2} {
1299    	frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
1300    	grid .$i -row $i -column $i -sticky nswe
1301    	grid rowconfigure . $i -weight [expr $i + 1]
1302    	grid columnconfigure . $i -weight [expr $i + 1]
1303    }
1304    grid propagate . 0
1305    . configure -width 200 -height 150
1306    set a ""
1307    update
1308    foreach i {0 1 2} {
1309	lappend a [winfo width .$i]-[winfo height .$i]
1310    }
1311    set a
1312} {84-63 66-50 50-37}
1313grid_reset 16.3
1314
1315test grid-16.4 {layout weights (shrinking with minsize)} {
1316    foreach i {0 1 2} {
1317    	frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
1318    	grid .$i -row $i -column $i -sticky nswe
1319    	grid rowconfigure . $i -weight [expr $i + 1] -minsize 45
1320    	grid columnconfigure . $i -weight [expr $i + 1] -minsize 65
1321    }
1322    grid propagate . 0
1323    . configure -width 200 -height 150
1324    set a ""
1325    update
1326    foreach i {0 1 2} {
1327	lappend a [winfo width .$i]-[winfo height .$i]
1328    }
1329    set a
1330} {70-60 65-45 65-45}
1331grid_reset 16.4
1332
1333test grid-16.5 {layout weights (shrinking at minsize)} {
1334    foreach i {0 1 2} {
1335    	frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
1336    	grid .$i -row $i -column $i -sticky nswe
1337    	grid rowconfigure . $i -weight 0 -minsize 70
1338    	grid columnconfigure . $i -weight 0 -minsize 90
1339    }
1340    grid propagate . 0
1341    . configure -width 100 -height 75
1342    set a ""
1343    update
1344    foreach i {0 1 2} {
1345	lappend a [winfo width .$i]-[winfo height .$i]
1346    }
1347    set a
1348} {100-75 100-75 100-75}
1349grid_reset 16.5
1350
1351
1352test grid-16.6 {layout weights (shrinking at minsize)} {
1353    foreach i {0 1 2} {
1354    	frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
1355    	grid .$i -row $i -column $i -sticky nswe
1356    	grid rowconfigure . $i -weight [expr $i + 1] -minsize 52
1357    	grid columnconfigure . $i -weight [expr $i + 1] -minsize 69
1358    }
1359    grid propagate . 0
1360    . configure -width 200 -height 150
1361    set a ""
1362    update
1363    foreach i {0 1 2} {
1364	lappend a [winfo width .$i]-[winfo height .$i]
1365    }
1366    set a
1367} {69-52 69-52 69-52}
1368grid_reset 16.6
1369
1370test grid-16.7 {layout weights (shrinking at minsize)} {
1371    foreach i {0 1 2} {
1372    	frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
1373    	grid .$i -row $i -column $i -sticky nswe
1374    }
1375    grid propagate . 0
1376    grid columnconfigure . 1 -weight 1 -minsize 0
1377    grid rowconfigure . 1 -weight 1 -minsize 0
1378    . configure -width 100 -height 75
1379    set a ""
1380    update
1381    foreach i {0 1 2} {
1382	lappend a [winfo width .$i]-[winfo height .$i]-[winfo ismapped .$i]
1383    }
1384    set a
1385} {100-75-1 1-1-0 100-75-1}
1386grid_reset 16.7
1387
1388test grid-16.8 {layout internal constraints} {
1389    foreach i {0 1 2 3 4} {
1390    	frame .$i -bg gray  -width 30 -height 25 -bd 2 -relief ridge
1391    	grid .$i -row $i -column $i -sticky nswe
1392    }
1393    frame .f -bg red -width 250 -height 200
1394    frame .g -bg green -width 200 -height 180
1395    lower .f
1396    raise .g .f
1397    grid .f -row 1 -column 1 -rowspan 3 -columnspan 3 -sticky nswe
1398    grid .g -row 1 -column 1 -rowspan 2 -columnspan 2 -sticky nswe
1399    update
1400    set a ""
1401    foreach i {0 1 2 3 4} {
1402    	append a "[winfo x .$i] "
1403    }
1404    append a ", "
1405    grid remove .f
1406    update
1407    foreach i {0 1 2 3 4} {
1408    	append a "[winfo x .$i] "
1409    }
1410    append a ", "
1411    grid remove .g
1412    grid .f
1413    update
1414    foreach i {0 1 2 3 4} {
1415    	append a "[winfo x .$i] "
1416    }
1417    append a ", "
1418    grid remove .f
1419    update
1420    foreach i {0 1 2 3 4} {
1421    	append a "[winfo x .$i] "
1422    }
1423    set a
1424} {0 30 70 250 280 , 0 30 130 230 260 , 0 30 113 197 280 , 0 30 60 90 120 }
1425grid_reset 16.8
1426
1427test grid-16.9 {layout uniform} {
1428    frame .f1 -width 75 -height 50
1429    frame .f2 -width 60 -height 25
1430    frame .f3 -width 95 -height 75
1431    frame .f4 -width 135 -height 100
1432    frame .f5 -width 80 -height 40
1433    for {set t 1} {$t <= 5} {incr t} {
1434        grid .f$t
1435    }
1436    grid rowconfigure . {0 2} -uniform a
1437    grid rowconfigure . {1 3} -uniform b
1438    update
1439    list [grid bbox . 0 0] [grid bbox . 0 1] [grid bbox . 0 2] \
1440            [grid bbox . 0 3] [grid bbox . 0 4]
1441} {{0 0 135 75} {0 75 135 100} {0 175 135 75} {0 250 135 100} {0 350 135 40}}
1442grid_reset 16.9
1443
1444test grid-16.10 {layout uniform} {
1445    grid [frame .f1 -width  75 -height  50] -row 0 -column 0
1446    grid [frame .f2 -width  60 -height  30] -row 1 -column 2
1447    grid [frame .f3 -width  95 -height  90] -row 2 -column 1
1448    grid [frame .f4 -width  60 -height 100] -row 3 -column 4
1449    grid [frame .f5 -width  60 -height  40] -row 4 -column 3
1450
1451    grid rowconfigure . {0 1} -uniform a
1452    grid rowconfigure . {2 4} -uniform b
1453    grid rowconfigure . {0 2} -weight 2
1454    grid columnconfigure . {0 2} -uniform a
1455    grid columnconfigure . {3 4} -uniform b
1456    grid columnconfigure . {2 4} -weight 2
1457    grid columnconfigure . 3 -minsize 70
1458    grid columnconfigure . 4 -minsize 130
1459    update
1460    list [grid bbox . 0 0] [grid bbox . 2 1] [grid bbox . 1 2] \
1461            [grid bbox . 4 3] [grid bbox . 3 4]
1462} {{0 0 75 60} {170 60 150 30} {75 90 95 90} {390 180 140 100} {320 280 70 45}}
1463grid_reset 16.10
1464
1465test grid-16.11 {layout uniform (shrink)} {
1466    frame .f1 -width 75 -height 50
1467    frame .f2 -width 100 -height 95
1468    grid .f1 .f2 -sticky news
1469    grid columnconfigure . {0 1} -uniform a
1470    grid columnconfigure . 0 -weight 1
1471    update
1472    set res {}
1473    lappend res [grid bbox . 0 0] [grid bbox . 1 0]
1474    grid propagate . 0
1475    . configure -width 150 -height 95
1476    update
1477    lappend res [grid bbox . 0 0] [grid bbox . 1 0]
1478} {{0 0 100 95} {100 0 100 95} {0 0 50 95} {50 0 100 95}}
1479grid_reset 16.11
1480
1481test grid-16.12 {layout uniform (grow)} {
1482    frame .f1 -width 40 -height 50
1483    frame .f2 -width 50 -height 95
1484    frame .f3 -width 60 -height 50
1485    frame .f4 -width 70 -height 95
1486    grid .f1 .f2 .f3 .f4 -sticky news
1487    grid columnconfigure . {0 1 2} -uniform a
1488    # Put weight 2 on the biggest in the group to see that the groups
1489    # adapts to one of the smaller.
1490    grid columnconfigure . 2 -weight 2
1491    grid columnconfigure . {0 3} -weight 1
1492    update
1493    set res {}
1494    lappend res [grid bbox . 0 0] [grid bbox . 1 0]
1495    lappend res [grid bbox . 2 0] [grid bbox . 3 0]
1496
1497    grid propagate . 0
1498    . configure -width 350 -height 95
1499    update
1500    lappend res [grid bbox . 0 0] [grid bbox . 1 0]
1501    lappend res [grid bbox . 2 0] [grid bbox . 3 0]
1502} [list {0 0 50 95} {50 0 50 95} {100 0 100 95} {200 0 70 95} \
1503        {0 0 70 95} {70 0 50 95} {120 0 140 95} {260 0 90 95}]
1504grid_reset 16.12
1505
1506test grid-16.13 {layout weights (shrinking at minsize)} {
1507    foreach i {0 1 2 3} {
1508    	frame .$i -bg gray  -width 100 -height 75 -bd 2 -relief ridge
1509    	grid .$i -row $i -column $i -sticky nswe
1510    }
1511    grid propagate . 0
1512    grid columnconfigure . {0 1} -weight 1 -minsize 0
1513    grid rowconfigure . {0 1} -weight 1 -minsize 0
1514    set a ""
1515    . configure -width 250 -height 200
1516    update
1517    foreach i {0 1 2 3} {
1518	lappend a [winfo width .$i]-[winfo height .$i]-[winfo ismapped .$i]
1519    }
1520    . configure -width 150 -height 100
1521    update
1522    foreach i {0 1 2 3} {
1523	lappend a [winfo width .$i]-[winfo height .$i]-[winfo ismapped .$i]
1524    }
1525    set a
1526} {25-25-1 25-25-1 100-75-1 100-75-1 25-25-0 25-25-0 100-75-1 100-75-1}
1527grid_reset 16.13
1528
1529
1530test grid-17.1 {forget and pending idle handlers} {
1531    # This test is intended to detect a crash caused by a failure to remove
1532    # pending idle handlers when grid forget is invoked.
1533
1534    toplevel .t
1535    wm geometry .t +0+0
1536    frame .t.f
1537    label .t.f.l -text foobar
1538    grid .t.f.l
1539    grid .t.f
1540    update
1541    grid forget .t.f.l
1542    grid forget .t.f
1543    destroy .t
1544
1545    toplevel .t
1546    frame .t.f
1547    label .t.f.l -text foobar
1548    grid .t.f.l
1549    destroy .t
1550    set result ok
1551} ok
1552
1553test grid-18.1 {test respect for internalborder} {
1554    toplevel .pack
1555    wm geometry .pack 200x200
1556    frame .pack.l -width 15 -height 10
1557    labelframe .pack.lf -labelwidget .pack.l
1558    pack .pack.lf -fill both -expand 1
1559    frame .pack.lf.f
1560    grid .pack.lf.f -sticky news
1561    grid columnconfigure .pack.lf 0 -weight 1
1562    grid rowconfigure .pack.lf 0 -weight 1
1563    update
1564    set res [list [winfo geometry .pack.lf.f]]
1565    .pack.lf configure -labelanchor e -padx 3 -pady 5
1566    update
1567    lappend res [winfo geometry .pack.lf.f]
1568    destroy .pack
1569    set res
1570} {196x188+2+10 177x186+5+7}
1571test grid-18.2 {test support for minreqsize} {
1572    toplevel .pack
1573    wm geometry .pack {}
1574    frame .pack.l -width 150 -height 100
1575    labelframe .pack.lf -labelwidget .pack.l
1576    pack .pack.lf -fill both -expand 1
1577    frame .pack.lf.f -width 20 -height 25
1578    grid .pack.lf.f
1579    update
1580    set res [list [winfo geometry .pack.lf]]
1581    .pack.lf configure -labelanchor ws
1582    update
1583    lappend res [winfo geometry .pack.lf]
1584    destroy .pack
1585    set res
1586} {162x127+0+0 172x112+0+0}
1587
1588test grid-19.1 {uniform realloc} {
1589    # Use a lot of uniform groups to test the reallocation mechanism
1590    for {set t 0} {$t < 100} {incr t 2} {
1591        frame .fa$t -width 5 -height 20
1592        frame .fb$t -width 6 -height 20
1593        grid .fa$t .fb$t -row 0 -column $t -sticky news
1594        grid columnconfigure . [list $t [expr {$t + 1}]] -uniform a$t
1595    }
1596    update
1597    grid bbox .
1598} {0 0 600 20}
1599grid_reset 19.1
1600
1601test grid-20.1 {recalculate size after removal (destroy)} {
1602    label .l1 -text l1
1603    grid .l1 -row 2 -column 2
1604    destroy .l1
1605    label .l2 -text l2
1606    grid .l2
1607    grid size .
1608} {1 1}
1609grid_reset 20.1
1610
1611test grid-20.2 {recalculate size after removal (forget)} {
1612    label .l1 -text l1
1613    grid .l1 -row 2 -column 2
1614    grid forget .l1
1615    label .l2 -text l2
1616    grid .l2
1617    grid size .
1618} {1 1}
1619grid_reset 20.2
1620
1621# cleanup
1622::tcltest::cleanupTests
1623return
1624