1 # This file is a Tcl script to test drawing of menus in Tk. It is
2 # organized in the standard fashion for Tcl tests.
4 # Copyright (c) 1996-1997 Sun Microsystems, Inc.
5 # Copyright (c) 1998-1999 by Scriptics Corporation.
10 if {[lsearch [namespace children] ::tcltest] == -1} {
11 source [file join [pwd] [file dirname [info script]] defs.tcl]
14 if {[lsearch [image types] test] < 0} {
15 puts "This application hasn't been compiled with the \"test\" image"
16 puts "type, so I can't run this test. Are you sure you're using"
17 puts "tktest instead of wish?"
18 ::tcltest::cleanupTests
22 proc deleteWindows {} {
23 foreach i [winfo children .] {
32 test menuDraw-1.1 {TkMenuInitializeDrawingFields} {
34 list [menu .m1] [destroy .m1]
37 test menuDraw-2.1 {TkIntializeMenuEntryDrawingFields} {
40 list [.m1 add command] [destroy .m1]
43 test menuDraw-3.1 {TkMenuFreeDrawOptions} {
49 test menuDraw-4.1 {TkMenuEntryFreeDrawOptions} {
52 .m1 add command -label "This is a test"
55 test menuDraw-4.2 {TkMenuEntryFreeDrawOptions} {
58 .m1 add checkbutton -label "This is a test." -font "Courier 12" -activeforeground red -background green -selectcolor purple
62 test menuDraw-5.1 {TkMenuConfigureDrawOptions - new menu} {
64 list [menu .m1] [destroy .m1]
66 test menuDraw-5.2 {TkMenuConfigureDrawOptions - old menu} {
69 list [.m1 configure -fg red] [destroy .m1]
71 test menuDraw-5.3 {TkMenuConfigureDrawOptions - no disabledFg} {
73 list [menu .m1 -disabledforeground ""] [destroy .m1]
76 test menuDraw-6.1 {TkMenuConfigureEntryDrawOptions - no tkfont specified} {
79 list [.m1 add command -label "foo"] [destroy .m1]
81 test menuDraw-6.2 {TkMenuConfigureEntryDrawOptions - tkfont specified} {
84 list [.m1 add command -label "foo" -font "Courier 12"] [destroy .m1]
86 test menuDraw-6.3 {TkMenuConfigureEntryDrawOptions - active state - wrong entry} {
89 .m1 add command -label "foo"
90 list [.m1 entryconfigure 1 -state active] [destroy .m1]
92 test menuDraw-6.4 {TkMenuConfigureEntryDrawOptions - active state - correct entry} {
95 .m1 add command -label "foo"
97 list [.m1 entryconfigure 1 -state active] [destroy .m1]
99 test menuDraw-6.5 {TkMenuConfigureEntryDrawOptions - deactivate entry} {
102 .m1 add command -label "foo"
104 list [.m1 entryconfigure 1 -state normal] [destroy .m1]
106 test menuDraw-6.6 {TkMenuConfigureEntryDrawOptions - bad state} {
109 .m1 add command -label "foo"
110 list [catch {.m1 entryconfigure 1 -state foo} msg] $msg [destroy .m1]
111 } {1 {bad state "foo": must be active, normal, or disabled} {}}
112 test menuDraw-6.7 {TkMenuConfigureEntryDrawOptions - tkfont specified} {
115 list [.m1 add command -label "foo" -font "Courier 12"] [destroy .m1]
117 test menuDraw-6.8 {TkMenuConfigureEntryDrawOptions - border specified} {
120 list [.m1 add command -label "foo" -background "red"] [destroy .m1]
122 test menuDraw-6.9 {TkMenuConfigureEntryDrawOptions - foreground specified} {
125 list [.m1 add command -label "foo" -foreground "red"] [destroy .m1]
127 test menuDraw-6.10 {TkMenuConfigureEntryDrawOptions - activeBorder specified} {
130 list [.m1 add command -label "foo" -activebackground "red"] [destroy .m1]
132 test menuDraw-6.11 {TkMenuConfigureEntryDrawOptions - activeforeground specified} {
135 list [.m1 add command -label "foo" -activeforeground "red"] [destroy .m1]
137 test menuDraw-6.12 {TkMenuConfigureEntryDrawOptions - selectcolor specified} {
140 list [.m1 add radiobutton -label "foo" -selectcolor "red"] [destroy .m1]
142 test menuDraw-6.13 {TkMenuConfigureEntryDrawOptions - textGC disposal} {
145 .m1 add command -label "foo" -font "Helvetica 12"
146 list [.m1 entryconfigure 1 -font "Courier 12"] [destroy .m1]
148 test menuDraw-6.14 {TkMenuConfigureEntryDrawOptions - activeGC disposal} {
151 .m1 add command -label "foo" -activeforeground "red"
152 list [.m1 entryconfigure 1 -activeforeground "green"] [destroy .m1]
154 test menuDraw-6.15 {TkMenuConfigureEntryDrawOptions - disabledGC disposal} {
156 menu .m1 -disabledforeground "red"
157 .m1 add command -label "foo"
158 list [.m1 configure -disabledforeground "green"] [destroy .m1]
160 test menuDraw-6.16 {TkMenuConfigureEntryDrawOptions - indicatorGC disposal} {
163 .m1 add radiobutton -label "foo" -selectcolor "red"
164 list [.m1 entryconfigure 1 -selectcolor "green"] [destroy .m1]
167 test menuDraw-7.1 {TkEventuallyRecomputeMenu} {
170 .m1 add command -label "This is a long label"
171 set tearoff [tkTearOffMenu .m1]
173 list [.m1 entryconfigure 1 -label "foo"] [destroy .m1]
175 test menuDraw-7.2 {TkEventuallyRecomputeMenu - update pending} {
178 .m1 add command -label "This is a long label"
179 set tearoff [tkTearOffMenu .m1]
180 list [.m1 entryconfigure 1 -label "foo"] [destroy .m1]
184 test menuDraw-8.1 {TkRecomputeMenu} {pcOnly userInteraction} {
187 .m1 configure -postcommand [.m1 add command -label foo]
188 .m1 add command -label "Hit ESCAPE to make this menu go away."
189 list [.m1 post 0 0] [destroy .m1]
193 test menuDraw-9.1 {TkEventuallyRedrawMenu - entry test} {
198 .m1 add radiobutton -variable foo -label test
201 list [set foo test] [destroy .m1] [unset foo]
203 test menuDraw-9.2 {TkEventuallyRedrawMenu - whole menu} {
206 list [catch {tkTearOffMenu .m1}] [destroy .m1]
209 # Don't know how to test when window has been deleted and ComputeMenuGeometry
211 test menuDraw-10.1 {ComputeMenuGeometry - menubar} {
214 .m1 add command -label test
215 . configure -menu .m1
216 list [update idletasks] [. configure -menu ""] [destroy .m1]
218 test menuDraw-10.2 {ComputeMenuGeometry - non-menubar} {
221 .m1 add command -label test
222 list [update idletasks] [destroy .m1]
224 test menuDraw-10.3 {ComputeMenuGeometry - Resize necessary} {
227 .m1 add command -label test
228 list [update idletasks] [destroy .m1]
230 test menuDraw-10.4 {ComputeMenuGeometry - resize not necessary} {
233 .m1 add command -label test
235 .m1 entryconfigure 1 -label test
236 list [update idletasks] [destroy .m1]
239 test menuDraw-11.1 {TkMenuSelectImageProc - entry selected; redraw not pending} {
241 catch {eval image delete [image names]}
242 image create test image1
243 image create test image2
245 .m1 add checkbutton -image image1 -selectimage image2
247 set tearoff [tkTearOffMenu .m1 40 40]
249 list [image delete image2] [destroy .m1] [eval image delete [image names]]
251 test menuDraw-11.2 {TkMenuSelectImageProc - entry selected; redraw pending} {
253 catch {eval image delete [image names]}
254 image create test image1
255 image create test image2
257 .m1 add checkbutton -image image1 -selectimage image2
259 set tearoff [tkTearOffMenu .m1 40 40]
260 list [image delete image2] [destroy .m1] [eval image delete [image names]]
262 test menuDraw-11.3 {TkMenuSelectImageProc - entry not selected} {
264 catch {eval image delete [image names]}
265 image create test image1
266 image create test image2
268 .m1 add checkbutton -image image1 -selectimage image2
269 set tearoff [tkTearOffMenu .m1 40 40]
271 list [image delete image2] [destroy .m1] [eval image delete [image names]]
274 #Don't know how to test missing tkwin in DisplayMenu
275 test menuDraw-12.1 {DisplayMenu - menubar background} {unixOnly} {
278 .m1 add cascade -label foo -menu .m2
279 . configure -menu .m1
280 list [update] [. configure -menu ""] [destroy .m1]
282 test menuDraw-12.2 {Display menu - no entries} {
285 set tearoff [tkTearOffMenu .m1 40 40]
286 list [update] [destroy .m1]
288 test menuDraw-12.3 {DisplayMenu - one entry} {
291 .m1 add command -label foo
292 set tearoff [tkTearOffMenu .m1 40 40]
293 list [update] [destroy .m1]
295 test menuDraw-12.4 {DisplayMenu - two entries} {
298 .m1 add command -label "one"
299 .m1 add command -label "two"
300 set tearoff [tkTearOffMenu .m1 40 40]
301 list [update] [destroy .m1]
303 test menuDraw.12.5 {DisplayMenu - two columns - first bigger} {
306 .m1 add command -label "one"
307 .m1 add command -label "two"
308 .m1 add command -label "three" -columnbreak 1
309 set tearoff [tkTearOffMenu .m1 40 40]
310 list [update] [destroy .m1]
312 test menuDraw-12.5 {DisplayMenu - two column - second bigger} {
315 .m1 add command -label "one"
316 .m1 add command -label "two" -columnbreak 1
317 .m1 add command -label "three"
318 set tearoff [tkTearOffMenu .m1 40 40]
319 list [update] [destroy .m1]
321 test menuDraw.12.7 {DisplayMenu - three columns} {
324 .m1 add command -label "one"
325 .m1 add command -label "two" -columnbreak 1
326 .m1 add command -label "three"
327 .m1 add command -label "four"
328 .m1 add command -label "five"
329 .m1 add command -label "six"
330 set tearoff [tkTearOffMenu .m1 40 40]
331 list [update] [destroy .m1]
333 test menuDraw-12.6 {Display menu - testing for extra space and menubars} {unixOnly} {
336 .m1 add cascade -label foo
337 . configure -menu .m1
338 list [update] [. configure -menu ""] [destroy .m1]
340 test menuDraw-12.7 {Display menu - extra space at end of menu} {
343 .m1 add cascade -label foo
344 set tearoff [tkTearOffMenu .m1 40 40]
345 wm geometry $tearoff 200x100
346 list [update] [destroy .m1]
349 test menuDraw-13.1 {TkMenuEventProc - Expose} {
353 .m1 add command -label "one"
355 .m2 add command -label "two"
356 set tearoff1 [tkTearOffMenu .m1 40 40]
357 set tearoff2 [tkTearOffMenu .m2 40 40]
358 list [raise $tearoff2] [update] [destroy .m1] [destroy .m2]
360 test menuDraw-13.2 {TkMenuEventProc - ConfigureNotify} {
363 .m1 add command -label "foo"
364 set tearoff [tkTearOffMenu .m1 40 40]
365 list [wm geometry $tearoff 200x100] [update] [destroy .m1]
367 test menuDraw-13.3 {TkMenuEventProc - ActivateNotify} {macOnly} {
369 toplevel .t2 -menu .t2.m1
371 .t2.m1 add command -label foo
372 tkTearOffMenu .t2.m1 40 40
373 list [catch {update} msg] $msg [destroy .t2]
375 # Testing deletes is hard, and I am going to do my best. Don't know how
376 # to test the case where we have already cleared the tkwin field in the
378 test menuDraw-13.4 {TkMenuEventProc - simple delete} {
383 test menuDraw-13.5 {TkMenuEventProc - nothing pending} {
386 .m1 add command -label foo
391 test menuDraw-14.1 {TkMenuImageProc} {
393 catch {image delete image1}
395 image create test image1
396 .m1 add command -image image1
398 list [image delete image1] [destroy .m1]
400 test menuDraw-14.2 {TkMenuImageProc} {
402 catch {image delete image1}
404 image create test image1
405 .m1 add command -image image1
406 list [image delete image1] [destroy .m1]
409 test menuDraw-15.1 {TkPostTearoffMenu - Basic posting} {
412 .m1 add command -label "foo"
413 list [catch {tkTearOffMenu .m1 40 40}] [destroy .m1]
415 test menuDraw-15.2 {TkPostTearoffMenu - Deactivation} {
418 .m1 add command -label "foo" -state active
419 set tearoff [tkTearOffMenu .m1 40 40]
420 list [$tearoff index active] [destroy .m1]
422 test menuDraw-15.3 {TkPostTearoffMenu - post command} {
425 menu .m1 -postcommand "set foo .m1"
426 .m1 add command -label "foo"
427 list [catch {tkTearOffMenu .m1 40 40}] [set foo] [unset foo] [destroy .m1]
429 test menuDraw-15.4 {TkPostTearoffMenu - post command deleting the menu} {
431 menu .m1 -postcommand "destroy .m1"
432 .m1 add command -label "foo"
433 list [catch {tkTearOffMenu .m1 40 40} msg] $msg [winfo exists .m1]
435 test menuDraw-15.5 {TkPostTearoffMenu - tearoff at edge of screen} {
438 .m1 add command -label "foo"
439 set height [winfo screenheight .m1]
440 list [catch {tkTearOffMenu .m1 40 $height}] [destroy .m1]
442 test menuDraw-15.6 {TkPostTearoffMenu - tearoff off right} {
445 .m1 add command -label "foo"
446 set width [winfo screenwidth .m1]
447 list [catch {tkTearOffMenu .m1 $width 40}] [destroy .m1]
451 test menuDraw-16.1 {TkPostSubmenu} {unixOnly} {
455 .m1 add cascade -label test -menu .m2
457 .m2 add command -label "Hit ESCAPE to make this menu go away."
458 set tearoff [tkTearOffMenu .m1 40 40]
459 $tearoff postcascade 0
460 list [$tearoff postcascade 0] [destroy .m1] [destroy .m2]
462 test menuDraw-16.2 {TkPostSubMenu} {unixOnly} {
467 .m1 add cascade -label "two" -menu .m2
468 .m1 add cascade -label "three" -menu .m3
470 .m2 add command -label "two"
472 .m3 add command -label "three"
473 set tearoff [tkTearOffMenu .m1 40 40]
474 $tearoff postcascade 0
475 list [$tearoff postcascade 1] [destroy .m1] [destroy .m2] [destroy .m3]
477 test menuDraw-16.3 {TkPostSubMenu} {
480 .m1 add cascade -label test -menu .m2
481 list [.m1 postcascade 1] [destroy .m1]
483 test menuDraw-16.4 {TkPostSubMenu} {
486 .m1 add cascade -label test
487 set tearoff [tkTearOffMenu .m1 40 40]
488 list [$tearoff postcascade 0] [destroy .m1]
490 test menuDraw-16.5 {TkPostSubMenu} {unixOnly} {
494 .m1 add cascade -label test -menu .m2
495 menu .m2 -postcommand "glorp"
496 set tearoff [tkTearOffMenu .m1 40 40]
497 list [catch {$tearoff postcascade test} msg] $msg [destroy .m1] [destroy .m2]
498 } {1 {invalid command name "glorp"} {} {}}
499 test menuDraw-16.6 {TkPostSubMenu} {pcOnly userInteraction} {
503 .m1 add cascade -label test -menu .m2
505 .m2 add command -label "Hit ESCAPE to get rid of this menu"
506 set tearoff [tkTearOffMenu .m1 40 40]
507 list [$tearoff postcascade 0] [destroy .m1] [destroy .m2]
510 test menuDraw-17.1 {AdjustMenuCoords - menubar} {unixOnly} {
514 .m1 add cascade -label test -menu .m2
516 .m2 add command -label foo
517 . configure -menu .m1
518 foreach w [winfo children .] {
519 if {[$w cget -type] == "menubar"} {
523 list [$w postcascade 0] [. configure -menu ""] [destroy .m1] [destroy .m2]
525 test menuDraw-17.2 {AdjustMenuCoords - menu} {pcOnly userInteraction} {
529 .m1 add cascade -label test -menu .m2
531 .m2 add command -label "Hit ESCAPE to make this menu go away"
532 set tearoff [tkTearOffMenu .m1 40 40]
533 list [$tearoff postcascade 0] [destroy .m1] [destroy .m2]
538 ::tcltest::cleanupTests