1# This file is a Tcl script to test the procedures in the file
2# tkGeometry.c (generic support for geometry managers).  It is
3# organized in the standard fashion for Tcl tests.
4#
5# Copyright (c) 1994 The Regents of the University of California.
6# Copyright (c) 1994 Sun Microsystems, Inc.
7# Copyright (c) 1998-1999 by Scriptics Corporation.
8# All rights reserved.
9#
10# RCS: @(#) $Id$
11
12package require tcltest 2.1
13eval tcltest::configure $argv
14tcltest::loadTestedCommands
15
16wm geometry . 300x300
17raise .
18update
19
20frame .f -bd 2 -relief raised
21frame .f.f -bd 2 -relief sunken
22frame .f.f.f -bd 2 -relief raised
23button .b1 -text .b1
24button .b2 -text .b2
25button .b3 -text .b3
26button .f.f.b4 -text .b4
27
28test geometry-1.1 {Tk_ManageGeometry procedure} {
29    place .b1 -x 120 -y 80
30    update
31    list [winfo x .b1] [winfo y .b1]
32} {120 80}
33test geometry-1.2 {Tk_ManageGeometry procedure} {
34    foreach w {.f .f.f .f.f.f .b1 .b2 .b3} {
35	place forget $w
36    }
37    place .f -x 20 -y 30 -width 200 -height 200
38    place .b1 -in .f -x 40 -y 30
39    update
40    pack .b1 -side top -anchor w
41    place .f -x 30 -y 40
42    update
43    list [winfo x .b1] [winfo y .b1]
44} {0 0}
45
46test geometry-2.1 {Tk_GeometryRequest procedure} {
47    frame .f2
48    set result [list [winfo reqwidth .f2] [winfo reqheight .f2]]
49    .f2 configure -width 150 -height 300
50    update
51    lappend result [winfo reqwidth .f2] [winfo reqheight .f2] \
52	    [winfo geom .f2]
53    place .f2 -x 10 -y 20
54    update
55    lappend result [winfo geom .f2]
56    .f2 configure -width 100 -height 80
57    update
58    lappend result [winfo geom .f2]
59} {1 1 150 300 1x1+0+0 150x300+10+20 100x80+10+20}
60catch {destroy .f2}
61
62test geometry-3.1 {Tk_SetInternalBorder procedure} {
63    foreach w {.f .f.f .f.f.f .b1 .b2 .b3} {
64	place forget $w
65    }
66    place .f -x 20 -y 30 -width 200 -height 200
67    place .b1 -in .f -x 50 -y 5
68    update
69    set x [list [winfo x .b1] [winfo y .b1]]
70    .f configure -bd 5
71    update
72    lappend x [winfo x .b1] [winfo y .b1]
73} {72 37 75 40}
74.f configure -bd 2
75
76test geometry-4.1 {Tk_MaintainGeometry and Tk_UnmaintainGeometry} {
77    foreach w {.f .f.f .f.f.f .b1 .b2 .b3} {
78	place forget $w
79    }
80    place .f -x 20 -y 30 -width 200 -height 200
81    place .f.f -x 15 -y 5 -width 150 -height 120
82    place .f.f.f -width 100 -height 80
83    place .b1 -in .f.f.f -x 50 -y 5
84    update
85    list [winfo x .b1] [winfo y .b1]
86} {91 46}
87test geometry-4.2 {Tk_MaintainGeometry and Tk_UnmaintainGeometry} {
88    foreach w {.f .f.f .f.f.f .b1 .b2 .b3} {
89	place forget $w
90    }
91    place .f -x 20 -y 30 -width 200 -height 200
92    place .f.f -x 15 -y 5 -width 150 -height 120
93    place .f.f.f -width 100 -height 80
94    place .b1 -in .f.f.f -x 50 -y 5
95    place .b2 -in .f.f.f -x 10 -y 25
96    place .b3 -in .f.f.f -x 50 -y 25
97    update
98    place .f -x 30 -y 25
99    update
100    list [winfo x .b1] [winfo y .b1] [winfo x .b2] [winfo y .b2] \
101	    [winfo x .b3] [winfo y .b3]
102} {101 41 61 61 101 61}
103test geometry-4.3 {Tk_MaintainGeometry and Tk_UnmaintainGeometry} {
104    foreach w {.f .f.f .f.f.f .b1 .b2 .b3} {
105	place forget $w
106    }
107    place .f -x 20 -y 30 -width 200 -height 200
108    place .f.f -x 15 -y 5 -width 150 -height 120
109    place .f.f.f -width 100 -height 80
110    place .b1 -in .f.f.f -x 50 -y 5
111    place .b2 -in .f.f.f -x 10 -y 25
112    place .b3 -in .f.f.f -x 50 -y 25
113    update
114    destroy .b1
115    button .b1 -text .b1
116    place .f.f -x 10 -y 25
117    update
118    list [winfo x .b1] [winfo y .b1] [winfo x .b2] [winfo y .b2] \
119	    [winfo x .b3] [winfo y .b3]
120} {0 0 46 86 86 86}
121test geometry-4.4 {Tk_MaintainGeometry and Tk_UnmaintainGeometry} {
122    foreach w {.f .f.f .f.f.f .b1 .b2 .b3} {
123	place forget $w
124    }
125    place .f -x 20 -y 30 -width 200 -height 200
126    place .f.f -x 15 -y 5 -width 150 -height 120
127    place .f.f.f -width 100 -height 80
128    place .b1 -in .f.f.f -x 50 -y 5
129    place .b2 -in .f.f.f -x 10 -y 25
130    place .b3 -in .f.f.f -x 50 -y 25
131    update
132    destroy .b2
133    button .b2 -text .b2
134    place .f.f.f -x 2 -y 3
135    update
136    list [winfo x .b1] [winfo y .b1] [winfo x .b2] [winfo y .b2] \
137	    [winfo x .b3] [winfo y .b3]
138} {93 49 0 0 93 69}
139test geometry-4.5 {Tk_MaintainGeometry and Tk_UnmaintainGeometry} {
140    foreach w {.f .f.f .f.f.f .b1 .b2 .b3} {
141	place forget $w
142    }
143    place .f -x 20 -y 30 -width 200 -height 200
144    place .f.f -x 15 -y 5 -width 150 -height 120
145    place .f.f.f -width 100 -height 80
146    place .b1 -in .f.f.f -x 50 -y 5
147    place .b2 -in .f.f.f -x 10 -y 25
148    place .b3 -in .f.f.f -x 50 -y 25
149    update
150    destroy .b3
151    button .b3 -text .b3
152    place .f.f.f -x 2 -y 3
153    update
154    list [winfo x .b1] [winfo y .b1] [winfo x .b2] [winfo y .b2] \
155	    [winfo x .b3] [winfo y .b3]
156} {93 49 53 69 0 0}
157test geometry-4.6 {Tk_MaintainGeometry and Tk_UnmaintainGeometry} {
158    foreach w {.f .f.f .f.f.f .b1 .b2 .b3 .f.f.b4} {
159	place forget $w
160    }
161    place .f -x 20 -y 30 -width 200 -height 200
162    place .f.f -x 15 -y 5 -width 150 -height 120
163    place .f.f.f -width 100 -height 80
164    place .f.f.b4 -in .f.f.f -x 50 -y 5
165    place .b2 -in .f.f.f -x 10 -y 25
166    update
167    place .f -x 25 -y 35
168    update
169    list [winfo x .f.f.b4] [winfo y .f.f.b4] [winfo x .b2] [winfo y .b2]
170} {54 9 56 71}
171test geometry-4.7 {Tk_MaintainGeometry and Tk_UnmaintainGeometry} {
172    foreach w {.f .f.f .f.f.f .b1 .b2 .b3 .f.f.b4} {
173	place forget $w
174    }
175    bind .b1 <Configure> {lappend x configure}
176    place .f -x 20 -y 30 -width 200 -height 200
177    place .f.f -x 15 -y 5 -width 150 -height 120
178    place .f.f.f -width 100 -height 80
179    place .f.f.b4 -in .f.f.f -x 50 -y 5
180    place .b1 -in .f.f.f -x 10 -y 25
181    update
182    set x init
183    place .f -x 25 -y 35
184    update
185    lappend x |
186    place .f -x 30 -y 40
187    place .f.f -x 10 -y 0
188    update
189    bind .b1 <Configure> {}
190    set x
191} {init configure |}
192test geometry-4.8 {Tk_MaintainGeometry and Tk_UnmaintainGeometry} {
193    foreach w {.f .f.f .f.f.f .b1 .b2 .b3} {
194	place forget $w
195    }
196    place .f -x 20 -y 30 -width 200 -height 200
197    place .f.f -x 15 -y 5 -width 150 -height 120
198    place .f.f.f -width 100 -height 80
199    place .b1 -in .f.f.f -x 50 -y 5
200    place .b2 -in .f.f.f -x 10 -y 25
201    place .b3 -in .f.f.f -x 50 -y 25
202    update
203    destroy .f.f
204    frame .f.f -bd 2 -relief raised
205    frame .f.f.f -bd 2 -relief raised
206    place .f -x 30 -y 25
207    update
208    list [winfo x .b1] [winfo y .b1] [winfo ismapped .b1] \
209	    [winfo x .b2] [winfo y .b2] [winfo ismapped .b2] \
210	    [winfo x .b3] [winfo y .b3] [winfo ismapped .b3]
211} {91 46 0 51 66 0 91 66 0}
212test geometry-4.9 {Tk_MaintainGeometry and Tk_UnmaintainGeometry} {
213    foreach w {.f .f.f .f.f.f .b1 .b2 .b3} {
214	place forget $w
215    }
216    place .f -x 20 -y 30 -width 200 -height 200
217    place .f.f -x 15 -y 5 -width 150 -height 120
218    place .f.f.f -width 100 -height 80
219    place .b1 -in .f.f.f -x 50 -y 5
220    update
221    set result [winfo ismapped .b1]
222    place forget .f.f
223    update
224    lappend result [winfo ismapped .b1]
225    place .f.f -x 15 -y 5 -width 150 -height 120
226    update
227    lappend result [winfo ismapped .b1]
228} {1 0 1}
229test geometry-4.10 {Tk_MaintainGeometry and Tk_UnmaintainGeometry} {
230    toplevel .t
231    wm geometry .t +0+0
232    tkwait visibility .t
233    update
234    frame .t.f 
235    pack .t.f
236    button .t.quit -text Quit -command exit
237    pack .t.quit -in .t.f
238    wm iconify .t
239    set x 0
240    after 500 {set x 1}
241    tkwait variable x
242    wm deiconify .t
243    update
244    winfo ismapped .t.quit
245} {1}
246
247catch {destroy .t}
248
249# cleanup
250cleanupTests
251return
252