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