1# This file is a Tcl script to test out the features of the script
2# file focus.tcl, which includes the procedures tk_focusNext and
3# tk_focusPrev, among other things.  This file is organized in the
4# standard fashion for Tcl tests.
5#
6# Copyright (c) 1995 Sun Microsystems, Inc.
7# Copyright (c) 1998-1999 by Scriptics Corporation.
8# All rights reserved.
9#
10# RCS: @(#) $Id: focusTcl.test,v 1.5.2.1 2003/10/29 01:08:19 hobbs Exp $
11
12package require tcltest 2.1
13namespace import -force tcltest::configure
14namespace import -force tcltest::testsDirectory
15configure -testdir [file join [pwd] [file dirname [info script]]]
16configure -loadfile [file join [testsDirectory] constraints.tcl]
17tcltest::loadTestedCommands
18
19proc setup1 w {
20    if {$w == "."} {
21	set w ""
22    }
23    foreach i {a b c d} {
24	frame  $w.$i -width 200 -height 50 -bd 2 -relief raised
25	pack $w.$i
26    }
27    .b configure -width 0 -height 0
28    foreach i {x y z} {
29	button $w.b.$i -text "Button $w.b.$i"
30	pack $w.b.$i -side left
31    }
32    if {![winfo ismapped $w.b.z]} {
33	tkwait visibility $w.b.z
34    }
35}
36
37option add *takeFocus 1
38option add *highlightThickness 2
39. configure -takefocus 1 -highlightthickness 2
40test focusTcl-1.1 {tk_focusNext procedure, no children} {
41    tk_focusNext .
42} {.}
43setup1 .
44test focusTcl-1.2 {tk_focusNext procedure, basic tree traversal} {
45    tk_focusNext .
46} {.a}
47test focusTcl-1.3 {tk_focusNext procedure, basic tree traversal} {
48    tk_focusNext .a
49} {.b}
50test focusTcl-1.4 {tk_focusNext procedure, basic tree traversal} {
51    tk_focusNext .b
52} {.b.x}
53test focusTcl-1.5 {tk_focusNext procedure, basic tree traversal} {
54    tk_focusNext .b.x
55} {.b.y}
56test focusTcl-1.6 {tk_focusNext procedure, basic tree traversal} {
57    tk_focusNext .b.y
58} {.b.z}
59test focusTcl-1.7 {tk_focusNext procedure, basic tree traversal} {
60    tk_focusNext .b.z
61} {.c}
62test focusTcl-1.8 {tk_focusNext procedure, basic tree traversal} {
63    tk_focusNext .c
64} {.d}
65test focusTcl-1.9 {tk_focusNext procedure, basic tree traversal} {
66    tk_focusNext .d
67} {.}
68foreach w {.b .b.x .b.y .c .d} {
69    $w configure -takefocus 0
70}
71test focusTcl-1.10 {tk_focusNext procedure, basic tree traversal} {
72    tk_focusNext .a
73} {.b.z}
74test focusTcl-1.11 {tk_focusNext procedure, basic tree traversal} {
75    tk_focusNext .b.z
76} {.}
77test focusTcl-1.12 {tk_focusNext procedure, basic tree traversal} {
78    deleteWindows
79    setup1 .
80    update
81    . configure -takefocus 0
82    tk_focusNext .d
83} {.a}
84. configure -takefocus 1
85
86deleteWindows
87setup1 .
88toplevel .t
89wm geom .t +0+0
90toplevel .t2
91wm geom .t2 -0+0
92raise .t .a
93test focusTcl-2.1 {tk_focusNext procedure, toplevels} {
94    tk_focusNext .a
95} {.b}
96test focusTcl-2.2 {tk_focusNext procedure, toplevels} {
97    tk_focusNext .d
98} {.}
99test focusTcl-2.3 {tk_focusNext procedure, toplevels} {
100    tk_focusNext .t
101} {.t}
102setup1 .t
103raise .t.b
104test focusTcl-2.4 {tk_focusNext procedure, toplevels} {
105    tk_focusNext .t
106} {.t.a}
107test focusTcl-2.5 {tk_focusNext procedure, toplevels} {
108    tk_focusNext .t.b.z
109} {.t}
110
111deleteWindows
112test focusTcl-3.1 {tk_focusPrev procedure, no children} {
113    tk_focusPrev .
114} {.}
115setup1 .
116test focusTcl-3.2 {tk_focusPrev procedure, basic tree traversal} {
117    tk_focusPrev .
118} {.d}
119test focusTcl-3.3 {tk_focusPrev procedure, basic tree traversal} {
120    tk_focusPrev .d
121} {.c}
122test focusTcl-3.4 {tk_focusPrev procedure, basic tree traversal} {
123    tk_focusPrev .c
124} {.b.z}
125test focusTcl-3.5 {tk_focusPrev procedure, basic tree traversal} {
126    tk_focusPrev .b.z
127} {.b.y}
128test focusTcl-3.6 {tk_focusPrev procedure, basic tree traversal} {
129    tk_focusPrev .b.y
130} {.b.x}
131test focusTcl-3.7 {tk_focusPrev procedure, basic tree traversal} {
132    tk_focusPrev .b.x
133} {.b}
134test focusTcl-3.8 {tk_focusPrev procedure, basic tree traversal} {
135    tk_focusPrev .b
136} {.a}
137test focusTcl-3.9 {tk_focusPrev procedure, basic tree traversal} {
138    tk_focusPrev .a
139} {.}
140
141deleteWindows
142setup1 .
143toplevel .t
144wm geom .t +0+0
145toplevel .t2
146wm geom .t2 -0+0
147raise .t .a
148test focusTcl-4.1 {tk_focusPrev procedure, toplevels} {
149    tk_focusPrev .
150} {.d}
151test focusTcl-4.2 {tk_focusPrev procedure, toplevels} {
152    tk_focusPrev .b
153} {.a}
154test focusTcl-4.3 {tk_focusPrev procedure, toplevels} {
155    tk_focusPrev .t
156} {.t}
157setup1 .t
158update
159.t configure -takefocus 0
160raise .t.b
161test focusTcl-4.4 {tk_focusPrev procedure, toplevels} {
162    tk_focusPrev .t
163} {.t.b.z}
164test focusTcl-4.5 {tk_focusPrev procedure, toplevels} {
165    tk_focusPrev .t.a
166} {.t.b.z}
167
168deleteWindows
169test focusTcl-5.1 {tkFocusOK procedure, -takefocus 0} {
170    deleteWindows
171    setup1 .
172    .b.x configure -takefocus 0
173    tk_focusNext .b
174} {.b.y}
175test focusTcl-5.2 {tkFocusOK procedure, -takefocus 1} {
176    deleteWindows
177    setup1 .
178    pack forget .b
179    update
180    .b configure -takefocus ""
181    .b.y configure -takefocus ""
182    .b.z configure -takefocus ""
183    list [tk_focusNext .a] [tk_focusNext .b.x]
184} {.c .c}
185test focusTcl-5.3 {tkFocusOK procedure, -takefocus procedure} {
186    proc t w {
187	if {$w == ".b.x"} {
188	    return 1
189	} elseif {$w == ".b.y"} {
190	    return ""
191	}
192	return 0
193    }
194    deleteWindows
195    setup1 .
196    pack forget .b.y
197    update
198    .b configure -takefocus ""
199    foreach w {.b.x .b.y .b.z .c} {
200	$w configure -takefocus t
201    }
202    list [tk_focusNext .a] [tk_focusNext .b.x]
203} {.b.x .d}
204test focusTcl-5.4 {tkFocusOK procedure, -takefocus ""} {
205    deleteWindows
206    setup1 .
207    .b.x configure -takefocus ""
208    update
209    tk_focusNext .b
210} {.b.x}
211test focusTcl-5.5 {tkFocusOK procedure, -takefocus "", not mapped} {
212    deleteWindows
213    setup1 .
214    .b.x configure -takefocus ""
215    pack unpack .b.x
216    update
217    tk_focusNext .b
218} {.b.y}
219test focusTcl-5.6 {tkFocusOK procedure, -takefocus "", not mapped} {
220    deleteWindows
221    setup1 .
222    foreach w {.b.x .b.y .b.z} {
223	$w configure -takefocus ""
224    }
225    pack unpack .b
226    update
227    tk_focusNext .b
228} {.c}
229test focusTcl-5.7 {tkFocusOK procedure, -takefocus "", not mapped} {
230    deleteWindows
231    setup1 .
232    .b.y configure -takefocus 1
233    pack unpack .b.y
234    update
235    tk_focusNext .b.x
236} {.b.z}
237test focusTcl-5.8 {tkFocusOK procedure, -takefocus "", not mapped} {
238    proc always args {return 1}
239    deleteWindows
240    setup1 .
241    .b.y configure -takefocus always
242    pack unpack .b.y
243    update
244    tk_focusNext .b.x
245} {.b.y}
246test focusTcl-5.9 {tkFocusOK procedure, -takefocus "", window disabled} {
247    deleteWindows
248    setup1 .
249    foreach w {.b.x .b.y .b.z} {
250	$w configure -takefocus ""
251    }
252    update
253    .b.x configure -state disabled
254    tk_focusNext .b
255} {.b.y}
256test focusTcl-5.10 {tkFocusOK procedure, -takefocus "", check for bindings} {
257    deleteWindows
258    setup1 .
259    foreach w {.a .b .c .d} {
260	$w configure -takefocus ""
261    }
262    update
263    bind .a <Key> {foo}
264    list [tk_focusNext .] [tk_focusNext .a]
265} {.a .b.x}
266test focusTcl-5.11 {tkFocusOK procedure, -takefocus "", check for bindings} {
267    deleteWindows
268    setup1 .
269    foreach w {.a .b .c .d} {
270	$w configure -takefocus ""
271    }
272    update
273    bind Frame <Key> {foo}
274    list [tk_focusNext .] [tk_focusNext .a]
275} {.a .b}
276
277bind Frame <Key> {}
278. configure -takefocus 0 -highlightthickness 0
279option clear
280
281# cleanup
282::tcltest::cleanupTests
283return
284
285
286
287
288
289
290
291
292
293
294
295
296
297