1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
|
# This file is a Tcl script to test the code in tkEvent.c. It is
# organized in the standard fashion for Tcl tests.
#
# Copyright (c) 1994 The Regents of the University of California.
# Copyright (c) 1994-1995 Sun Microsystems, Inc.
# Copyright (c) 1998-1999 by Scriptics Corporation.
# All rights reserved.
package require tcltest 2.2
eval tcltest::configure $argv
tcltest::loadTestedCommands
namespace import -force tcltest::test
# XXX This test file is woefully incomplete. Right now it only tests
# a few of the procedures in tkEvent.c. Please add more tests whenever
# possible.
# Setup table used to query key events.
proc _init_keypress_lookup {} {
global keypress_lookup
scan A %c start
scan Z %c finish
for {set i $start} {$i <= $finish} {incr i} {
set l [format %c $i]
set keypress_lookup($l) $l
}
scan a %c start
scan z %c finish
for {set i $start} {$i <= $finish} {incr i} {
set l [format %c $i]
set keypress_lookup($l) $l
}
scan 0 %c start
scan 9 %c finish
for {set i $start} {$i <= $finish} {incr i} {
set l [format %c $i]
set keypress_lookup($l) $l
}
# Most punctuation
array set keypress_lookup {
! exclam
% percent
& ampersand
( parenleft
) parenright
* asterisk
+ plus
, comma
- minus
. period
/ slash
: colon
< less
= equal
> greater
? question
@ at
^ asciicircum
_ underscore
| bar
~ asciitilde
' apostrophe
}
# Characters with meaning to Tcl...
array set keypress_lookup [list \
\" quotedbl \
\# numbersign \
\$ dollar \
\; semicolon \
\[ bracketleft \
\\ backslash \
\] bracketright \
\{ braceleft \
\} braceright \
" " space \
"\n" Return \
"\t" Tab]
}
# Lookup an event in the keypress table.
# For example:
# Q -> Q
# . -> period
# / -> slash
# Delete -> Delete
# Escape -> Escape
proc _keypress_lookup {char} {
global keypress_lookup
if {! [info exists keypress_lookup]} {
_init_keypress_lookup
}
if {$char == ""} {
error "empty char"
}
if {[info exists keypress_lookup($char)]} {
return $keypress_lookup($char)
} else {
return $char
}
}
# Lookup and generate a pair of KeyPress and KeyRelease events
proc _keypress {win key} {
set keysym [_keypress_lookup $key]
# Force focus to the window before delivering
# each event so that a window manager using
# a focus follows mouse will not steal away
# the focus if the mouse is moved around.
if {[focus] != $win} {
focus -force $win
}
event generate $win <KeyPress-$keysym>
_pause 50
if {[focus] != $win} {
focus -force $win
}
event generate $win <KeyRelease-$keysym>
_pause 50
}
# Call _keypress for each character in the given string
proc _keypress_string {win string} {
foreach letter [split $string ""] {
_keypress $win $letter
}
}
# Delay script execution for a given amount of time
proc _pause {{msecs 1000}} {
global _pause
if {! [info exists _pause(number)]} {
set _pause(number) 0
}
set num [incr _pause(number)]
set _pause($num) 0
after $msecs "set _pause($num) 1"
vwait _pause($num)
unset _pause($num)
}
# Helper proc to convert index to x y position
proc _text_ind_to_x_y {text ind} {
set bbox [$text bbox $ind]
if {[llength $bbox] != 4} {
error "got bbox \{$bbox\} from $text, index $ind"
}
foreach {x1 y1 width height} $bbox break
set middle_y [expr {$y1 + ($height / 2)}]
return [list $x1 $middle_y]
}
# Return selection only if owned by the given widget
proc _get_selection {widget} {
if {[string compare $widget [selection own]] != 0} {
return ""
}
if {[catch {selection get} sel]} {
return ""
}
return $sel
}
# Begining of the actual tests
test event-1.1 {Tk_HandleEvent procedure, filter events for dead windows} -setup {
deleteWindows
set x {}
} -body {
button .b -text Test
pack .b
bindtags .b .b
update
bind .b <Destroy> {
lappend x destroy
event generate .b <1>
event generate .b <ButtonRelease-1>
}
bind .b <1> {
lappend x button
}
destroy .b
return $x
} -cleanup {
deleteWindows
} -result {destroy}
test event-1.2 {event generate <Alt-z>} -setup {
deleteWindows
catch {unset ::event12result}
} -body {
set ::event12result 0
pack [entry .e]
update
bind .e <Alt-z> {set ::event12result "1"}
focus -force .e
event generate .e <Alt-z>
destroy .e
set ::event12result
} -cleanup {
deleteWindows
} -result 1
test event-2.1(keypress) {type into entry widget and hit Return} -setup {
deleteWindows
} -body {
set t [toplevel .t]
set e [entry $t.e]
pack $e
set return_binding 0
bind $e <Return> {set return_binding 1}
tkwait visibility $e
_keypress_string $e HELLO\n
list [$e get] $return_binding
} -cleanup {
deleteWindows
} -result {HELLO 1}
test event-2.2(keypress) {type into entry widget and then delete some text} -setup {
deleteWindows
} -body {
set t [toplevel .t]
set e [entry $t.e]
pack $e
tkwait visibility $e
# Avoid a hang when macOS puts the mouse pointer on the green button
wm geometry .t +200+100
_keypress_string $e MELLO
_keypress $e BackSpace
_keypress $e BackSpace
$e get
} -cleanup {
deleteWindows
} -result {MEL}
test event-2.3(keypress) {type into entry widget, triple click, hit Delete key,
and then type some more} -setup {
deleteWindows
} -body {
set t [toplevel .t]
set e [entry $t.e]
pack $e
tkwait visibility $e
_keypress_string $e JUMP
set result [$e get]
event generate $e <Enter>
for {set i 0} {$i < 3} {incr i} {
_pause 100
event generate $e <ButtonPress-1>
_pause 100
event generate $e <ButtonRelease-1>
}
_keypress $e Delete
_keypress_string $e UP
lappend result [$e get]
} -cleanup {
deleteWindows
} -result {JUMP UP}
test event-2.4(keypress) {type into text widget and hit Return} -setup {
deleteWindows
} -body {
set t [toplevel .t]
set e [text $t.e]
pack $e
set return_binding 0
bind $e <Return> {set return_binding 1}
tkwait visibility $e
_keypress_string $e HELLO\n
list [$e get 1.0 end] $return_binding
} -cleanup {
deleteWindows
} -result [list "HELLO\n\n" 1]
test event-2.5(keypress) {type into text widget and then delete some text} -setup {
deleteWindows
} -body {
set t [toplevel .t]
set e [text $t.e]
pack $e
tkwait visibility $e
_keypress_string $e MELLO
_keypress $e BackSpace
_keypress $e BackSpace
$e get 1.0 1.end
} -cleanup {
deleteWindows
} -result {MEL}
test event-2.6(keypress) {type into text widget, triple click,
hit Delete key, and then type some more} -setup {
deleteWindows
update idletasks
} -body {
set t [toplevel .t]
set e [text $t.e]
pack $e
tkwait visibility $e
_keypress_string $e JUMP
set result [$e get 1.0 1.end]
event generate $e <Enter>
for {set i 0} {$i < 3} {incr i} {
_pause 100
event generate $e <ButtonPress-1>
_pause 100
event generate $e <ButtonRelease-1>
}
_keypress $e Delete
_keypress_string $e UP
lappend result [$e get 1.0 1.end]
} -cleanup {
deleteWindows
} -result {JUMP UP}
test event-3.1(click-drag) {click and drag in a text widget, this tests
tkTextSelectTo in text.tcl} -setup {
deleteWindows
} -body {
set t [toplevel .t]
set e [text $t.e]
pack $e
tkwait visibility $e
_keypress_string $e "A Tcl/Tk selection test!"
set anchor 1.6
set selend 1.18
set result [list]
lappend result [$e get 1.0 1.end]
# Get the x,y coords of the second T in "Tcl/Tk"
foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break
# Click down to set the insert cursor position
event generate $e <Enter>
event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
# Save the position of the insert cursor
lappend result [$e index insert]
# Now drag until selend is highlighted, then click up
set current $anchor
while {[$e compare $current <= $selend]} {
foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
event generate $e <B1-Motion> -x $current_x -y $current_y
set current [$e index [list $current + 1 char]]
_pause 50
}
event generate $e <ButtonRelease-1> -x $current_x -y $current_y
_pause 200
# Save the position of the insert cursor
lappend result [$e index insert]
# Save the highlighted text
lappend result [_get_selection $e]
# Now click and click and drag to the left, over "Tcl/Tk selection"
event generate $e <ButtonPress-1> -x $current_x -y $current_y
while {[$e compare $current >= [list $anchor - 4 char]]} {
foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
event generate $e <B1-Motion> -x $current_x -y $current_y
set current [$e index [list $current - 1 char]]
_pause 50
}
event generate $e <ButtonRelease-1> -x $current_x -y $current_y
_pause 200
# Save the position of the insert cursor
lappend result [$e index insert]
# Save the highlighted text
lappend result [_get_selection $e]
} -cleanup {
deleteWindows
} -result {{A Tcl/Tk selection test!} 1.6 1.18 {Tk selection} 1.2 {Tcl/Tk selection}}
test event-3.2(click-drag) {click and drag in an entry widget, this
tests tkEntryMouseSelect in entry.tcl} -setup {
deleteWindows
} -body {
set t [toplevel .t]
set e [entry $t.e]
pack $e
tkwait visibility $e
_keypress_string $e "A Tcl/Tk selection!"
set anchor 6
set selend 18
set result [list]
lappend result [$e get]
# Get the x,y coords of the second T in "Tcl/Tk"
foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break
# Click down to set the insert cursor position
event generate $e <Enter>
event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
# Save the position of the insert cursor
lappend result [$e index insert]
# Now drag until selend is highlighted, then click up
set current $anchor
while {$current <= $selend} {
foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
event generate $e <B1-Motion> -x $current_x -y $current_y
incr current
_pause 50
}
event generate $e <ButtonRelease-1> -x $current_x -y $current_y
_pause 200
# Save the position of the insert cursor
lappend result [$e index insert]
# Save the highlighted text
lappend result [_get_selection $e]
# Now click and click and drag to the left, over "Tcl/Tk selection"
event generate $e <ButtonPress-1> -x $current_x -y $current_y
while {$current >= ($anchor - 4)} {
foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
event generate $e <B1-Motion> -x $current_x -y $current_y
incr current -1
_pause 50
}
event generate $e <ButtonRelease-1> -x $current_x -y $current_y
_pause 200
# Save the position of the insert cursor
lappend result [$e index insert]
# Save the highlighted text
lappend result [_get_selection $e]
} -cleanup {
deleteWindows
} -result {{A Tcl/Tk selection!} 6 18 {Tk selection} 2 {Tcl/Tk selection}}
test event-4.1(double-click-drag) {click down, click up, click down again,
then drag in a text widget} -setup {
deleteWindows
} -body {
set t [toplevel .t]
set e [text $t.e]
pack $e
tkwait visibility $e
_keypress_string $e "Word select test"
set anchor 1.8
# Get the x,y coords of the second e in "select"
foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break
# Click down, release, then click down again
event generate $e <Enter>
event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
_pause 50
event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
_pause 50
event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
_pause 50
# Save the highlighted text
set result [list]
lappend result [_get_selection $e]
# Insert cursor should be at beginning of "select"
lappend result [$e index insert]
# Move mouse one character to the left
set current [$e index [list $anchor - 1 char]]
foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
event generate $e <B1-Motion> -x $current_x -y $current_y
_pause 50
# Insert cursor should be before the l in "select"
lappend result [$e index insert]
# Selection should still be the word "select"
lappend result [_get_selection $e]
# Move mouse to the space before the word "select"
set current [$e index [list $current - 3 char]]
foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
event generate $e <B1-Motion> -x $current_x -y $current_y
_pause 200
lappend result [$e index insert]
lappend result [_get_selection $e]
# Move mouse to the r in "Word"
set current 1.2
foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
event generate $e <B1-Motion> -x $current_x -y $current_y
_pause 50
# Selection should now be "Word select"
lappend result [_get_selection $e]
# Insert cursor should be before the r in "Word"
lappend result [$e index insert]
return $result
} -cleanup {
deleteWindows
} -result {select 1.5 1.7 select 1.4 { select} {Word select} 1.2}
test event-4.2(double-click-drag) {click down, click up, click down again,
then drag in an entry widget} -setup {
deleteWindows
} -body {
set t [toplevel .t]
set e [entry $t.e]
pack $e
tkwait visibility $e
_keypress_string $e "Word select test"
set anchor 8
# Get the x,y coords of the second e in "select"
foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break
# Click down, release, then click down again
event generate $e <Enter>
event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
_pause 50
event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
_pause 50
event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
_pause 50
set result [list]
lappend result [_get_selection $e]
# Insert cursor should be at the end of "select"
lappend result [$e index insert]
# Move mouse one character to the left
set current [expr {$anchor - 1}]
foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
event generate $e <B1-Motion> -x $current_x -y $current_y
_pause 50
# Insert cursor should be before the l in "select"
lappend result [$e index insert]
# Selection should still be the word "select"
lappend result [_get_selection $e]
# Move mouse to the space before the word "select"
set current [expr {$current - 3}]
foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
event generate $e <B1-Motion> -x $current_x -y $current_y
_pause 50
lappend result [$e index insert]
lappend result [_get_selection $e]
# Move mouse to the r in "Word"
set current [expr {$current - 2}]
foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
event generate $e <B1-Motion> -x $current_x -y $current_y
_pause 50
# Selection should now be "Word select"
lappend result [_get_selection $e]
# Insert cursor should be before the r in "Word"
lappend result [$e index insert]
return $result
} -cleanup {
deleteWindows
} -result {select 11 7 select 4 { select} {Word select} 2}
test event-5.1(triple-click-drag) {Triple click and drag across lines in a
text widget, this should extend the selection to the new line} -setup {
deleteWindows
} -body {
set t [toplevel .t]
set e [text $t.e]
pack $e
tkwait visibility $e
_keypress_string $e "LINE ONE\nLINE TWO\nLINE THREE"
set anchor 3.2
# Triple click one third line leaving mouse down
foreach {anchor_x anchor_y} [_text_ind_to_x_y $e $anchor] break
event generate $e <Enter>
event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
_pause 50
event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
_pause 50
event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
_pause 50
event generate $e <ButtonRelease-1> -x $anchor_x -y $anchor_y
_pause 50
event generate $e <ButtonPress-1> -x $anchor_x -y $anchor_y
_pause 50
set result [list]
lappend result [_get_selection $e]
# Drag up to second line
set current [$e index [list $anchor - 1 line]]
foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
event generate $e <B1-Motion> -x $current_x -y $current_y
_pause 50
lappend result [_get_selection $e]
# Drag up to first line
set current [$e index [list $current - 1 line]]
foreach {current_x current_y} [_text_ind_to_x_y $e $current] break
event generate $e <B1-Motion> -x $current_x -y $current_y
_pause 50
lappend result [_get_selection $e]
return $result
} -cleanup {
deleteWindows
} -result [list "LINE THREE\n" "LINE TWO\nLINE THREE\n" \
"LINE ONE\nLINE TWO\nLINE THREE\n"]
test event-6.1(button-state) {button press in a window that is then
destroyed, when the mouse is moved into another window it
should not generate a <B1-motion> event since the mouse
was not pressed down in that window} -setup {
deleteWindows
} -body {
set t [toplevel .t]
event generate $t <ButtonPress-1>
destroy $t
set t [toplevel .t]
set motion nomotion
bind $t <B1-Motion> {set motion inmotion}
event generate $t <Motion>
return $motion
} -cleanup {
deleteWindows
} -result {nomotion}
test event-7.1(double-click) {A double click on a lone character
in a text widget should select that character} -setup {
deleteWindows
} -body {
set t [toplevel .t]
set e [text $t.e]
pack $e
tkwait visibility $e
focus -force $e
_keypress_string $e "On A letter"
set anchor 1.3
# Get x,y coords just inside the left
# and right hand side of the letter A
foreach {x1 y1 width height} [$e bbox $anchor] break
set middle_y [expr {$y1 + ($height / 2)}]
set left_x [expr {$x1 + 2}]
set left_y $middle_y
set right_x [expr {($x1 + $width) - 2}]
set right_y $middle_y
# Double click near left hand egde of the letter A
event generate $e <Enter>
event generate $e <ButtonPress-1> -x $left_x -y $left_y
_pause 50
event generate $e <ButtonRelease-1> -x $left_x -y $left_y
_pause 50
event generate $e <ButtonPress-1> -x $left_x -y $left_y
_pause 50
event generate $e <ButtonRelease-1> -x $left_x -y $left_y
_pause 50
set result [list]
lappend result [$e index insert]
lappend result [_get_selection $e]
# Clear selection by clicking at 0,0
event generate $e <ButtonPress-1> -x 0 -y 0
_pause 50
event generate $e <ButtonRelease-1> -x 0 -y 0
_pause 50
# Double click near right hand edge of the letter A
event generate $e <ButtonPress-1> -x $right_x -y $right_y
_pause 50
event generate $e <ButtonRelease-1> -x $right_x -y $right_y
_pause 50
event generate $e <ButtonPress-1> -x $right_x -y $right_y
_pause 50
event generate $e <ButtonRelease-1> -x $right_x -y $right_y
_pause 50
lappend result [$e index insert]
lappend result [_get_selection $e]
return $result
} -cleanup {
deleteWindows
unset x1 y1 width height middle_y left_x left_y right_x right_y
} -result {1.3 A 1.3 A}
test event-7.2(double-click) {A double click on a lone character
in an entry widget should select that character} -setup {
deleteWindows
} -body {
set t [toplevel .t]
set e [entry $t.e]
pack $e
tkwait visibility $e
focus -force $e
_keypress_string $e "On A letter"
set anchor 3
# Get x,y coords just inside the left
# and right hand side of the letter A
foreach {x1 y1 width height} [$e bbox $anchor] break
set middle_y [expr {$y1 + ($height / 2)}]
set left_x [expr {$x1 + 2}]
set left_y $middle_y
set right_x [expr {($x1 + $width) - 2}]
set right_y $middle_y
# Double click near left hand egde of the letter A
event generate $e <Enter>
event generate $e <ButtonPress-1> -x $left_x -y $left_y
_pause 50
event generate $e <ButtonRelease-1> -x $left_x -y $left_y
_pause 50
event generate $e <ButtonPress-1> -x $left_x -y $left_y
_pause 50
event generate $e <ButtonRelease-1> -x $left_x -y $left_y
_pause 50
set result [list]
lappend result [$e index insert]
lappend result [_get_selection $e]
# Clear selection by clicking at 0,0
event generate $e <ButtonPress-1> -x 0 -y 0
_pause 50
event generate $e <ButtonRelease-1> -x 0 -y 0
_pause 50
# Double click near right hand edge of the letter A
event generate $e <ButtonPress-1> -x $right_x -y $right_y
_pause 50
event generate $e <ButtonRelease-1> -x $right_x -y $right_y
_pause 50
event generate $e <ButtonPress-1> -x $right_x -y $right_y
_pause 50
event generate $e <ButtonRelease-1> -x $right_x -y $right_y
_pause 50
lappend result [$e index insert]
lappend result [_get_selection $e]
return $result
} -cleanup {
deleteWindows
unset x1 y1 width height middle_y left_x left_y right_x right_y
} -result {4 A 4 A}
test event-8 {event generate with keysyms corresponding to
multi-byte virtual keycodes - bug
e36963bfe8df9f5e528134707a91b9c0051de723} -constraints nonPortable -setup {
deleteWindows
set res [list ]
} -body {
set t [toplevel .t]
set e [entry $t.e]
pack $e
tkwait visibility $e
bind $e <KeyPress> {lappend res keycode: %k keysym: %K}
focus -force $e
update
event generate $e <diaeresis>
# The value now contained in $res depends on the actual
# physical keyboard layout and keycode generated, from
# the hardware on which the test suite happens to run.
# We don't need (and we can't really) check correctness
# of the (system-dependent) keycode received, however
# Tk should be able to associate this keycode to a
# (system-independent) known keysym, unless the system
# running the test does not have a keyboard with a
# diaeresis key.
if {[expr {[lindex $res 3] ne "??"}]} {
# keyboard has a physical diaeresis key and bug is fixed
return "OK"
} else {
return "Test failed, unless the keyboard tied to the system \
on which this test is run does NOT have a diaeresis \
physical key - in this case, test is actually void."
}
} -cleanup {
deleteWindows
} -result {OK}
proc waitForWindowEvent {w event {timeout 1000}} {
# This proc is intended to overcome latency of windowing system
# notifications when toplevel windows are involved. These latencies vary
# considerably with the window manager in use, with the system load,
# with configured scheduling priorities for processes, etc ...
# Waiting for the corresponding window events evades the trouble that is
# associated with the alternative: waiting or halting the Tk process for a
# fixed amount of time (using "after ms"). With the latter strategy it's
# always a gamble how much waiting time is enough on an end user's system.
# It also leads to long fixed waiting times in order to be on the safe side.
variable _windowEvent
# Use counter as a unique ID to prevent subsequent waits
# from interfering with each other.
set counter [incr _windowEvent(counter)]
set _windowEvent($counter) 1
set savedBinding [bind $w $event]
bind $w $event [list +waitForWindowEvent.signal $counter]
set afterID [after $timeout [list set _windowEvent($counter) -1]]
vwait _windowEvent($counter)
set late [expr {$_windowEvent($counter) == -1}]
bind $w $event $savedBinding
unset _windowEvent($counter)
if {$late} {
puts stderr "wait for $event event on $w timed out (> $timeout ms)"
} else {
after cancel $afterID
}
}
proc waitForWindowEvent.signal {counter} {
# Helper proc that records the triggering of a window event.
incr ::_windowEvent($counter)
}
proc create_and_pack_frames {{w {}}} {
frame $w.f1 -bg blue -width 200 -height 200
pack propagate $w.f1 0
frame $w.f1.f2 -bg yellow -width 100 -height 100
pack $w.f1.f2 $w.f1 -side bottom -anchor se
update idletasks
}
proc setup_win_mousepointer {w} {
# Position the window and the mouse pointer as an initial state for some tests.
# The so-called "pointer window" is the $w window that will now contain the mouse pointer.
wm geometry . +700+700; # root window out of our way - must not cover windows from event-9.1*
toplevel $w
pack propagate $w 0
wm geometry $w 300x300+100+100
tkwait visibility $w
update; # service remaining screen drawing events (e.g. <Expose>)
set pointerWin [winfo containing [winfo pointerx $w] [winfo pointery $w]]
event generate $w <Motion> -warp 1 -x 250 -y 250
if {($pointerWin ne $w) && ([tk windowingsystem] ne "aqua")} {
waitForWindowEvent $w <Enter>
} else {
controlPointerWarpTiming
}
}
test event-9.11 {pointer window container = parent} -setup {
setup_win_mousepointer .one
wm withdraw .one
create_and_pack_frames .one
wm deiconify .one
tkwait visibility .one.f1.f2
_pause 200
bind all <Leave> {append result "<Leave> %d %W|"}
bind all <Enter> {append result "<Enter> %d %W|"}
set result "|"
} -body {
destroy .one.f1.f2
_pause 200; # service crossing events
set result
} -cleanup {
bind all <Leave> {}
bind all <Enter> {}
destroy .one
unset result
} -result {|<Enter> NotifyInferior .one.f1|}
test event-9.12 {pointer window container != parent} -setup {
setup_win_mousepointer .one
wm withdraw .one
create_and_pack_frames .one
pack propagate .one.f1.f2 0
pack [frame .one.g -bg orange -width 80 -height 80] -anchor se -side bottom -in .one.f1.f2
wm deiconify .one
tkwait visibility .one.g
event generate .one <Motion> -warp 1 -x 250 -y 250
_pause 200
bind all <Leave> {append result "<Leave> %d %W|"}
bind all <Enter> {append result "<Enter> %d %W|"}
set result "|"
} -body {
destroy .one.g
_pause 200; # service crossing events -- crashes without this
set result
} -cleanup {
bind all <Leave> {}
bind all <Enter> {}
destroy .one
unset result
} -result {|<Enter> NotifyNonlinearVirtual .one.f1|<Enter> NotifyNonlinear .one.f1.f2|}
test event-9.13 {pointer window is a toplevel, toplevel destination} -setup {
setup_win_mousepointer .one
toplevel .two
wm geometry .two 300x300+150+150
wm withdraw .two
wm deiconify .two
waitForWindowEvent .two <Enter>
bind all <Leave> {append result "<Leave> %d %W|"}
bind all <Enter> {append result "<Enter> %d %W|"}
set result |
} -body {
destroy .two
waitForWindowEvent .one <Enter>
# destroying .one here instead of in cleanup makes the test pass
destroy .one
set result
} -cleanup {
bind all <Leave> {}
bind all <Enter> {}
unset result
} -result {|<Enter> NotifyNonlinear .one|}
test event-9.14 {pointer window is a toplevel, tk internal destination} -setup {
setup_win_mousepointer .one
wm withdraw .one
create_and_pack_frames .one
toplevel .two
wm geometry .two 300x300+150+150
wm withdraw .two
wm deiconify .one
wm deiconify .two
waitForWindowEvent .two <Enter>
bind all <Leave> {append result "<Leave> %d %W|"}
bind all <Enter> {append result "<Enter> %d %W|"}
set result "|"
} -body {
destroy .two
waitForWindowEvent .one.f1.f2 <Enter>
bind all <Leave> {}
bind all <Enter> {}
destroy .one
set result
} -cleanup {
unset result
} -result {|<Enter> NotifyNonlinearVirtual .one|<Enter> NotifyNonlinearVirtual .one.f1|<Enter> NotifyNonlinear .one.f1.f2|}
test event-9.15 {pointer window is a toplevel, destination is screen root} -setup {
setup_win_mousepointer .one; # ensure the mouse pointer is where we want it to be (the .one toplevel is not itself used in this test)
toplevel .two
wm geometry .two 300x300+150+150
wm deiconify .two
waitForWindowEvent .two <Enter>
event generate .two <Motion> -warp 1 -x 275 -y 275
controlPointerWarpTiming
bind all <Leave> {append result "<Leave> %d %W|"}
bind all <Enter> {append result "<Enter> %d %W|"}
set result "|"
} -body {
_pause 200; # ensure servicing of all scheduled events (only <Expose> events expected)
destroy .two
set result
} -cleanup {
bind all <Leave> {}
bind all <Enter> {}
destroy .one
unset result
} -result {|}
test event-9.16 {Successive destructions (pointer window + parent), single generation of crossing events} -setup {
# Tests correctness of overwriting the dead window struct in
# TkPointerDeadWindow() and subsequent reading in GenerateEnterLeave().
setup_win_mousepointer .one
wm withdraw .one
create_and_pack_frames .one
wm deiconify .one
tkwait visibility .one.f1.f2
_pause 200
bind all <Leave> {append result "<Leave> %d %W|"}
bind all <Enter> {append result "<Enter> %d %W|"}
set result "|"
} -body {
destroy .one.f1
_pause 200; # service crossing events
set result
} -cleanup {
bind all <Leave> {}
bind all <Enter> {}
destroy .one
unset result
} -result {|<Enter> NotifyInferior .one|}
test event-9.17 {Successive destructions (pointer window + parent), separate crossing events} -setup {
# Tests correctness of overwriting the dead window struct in
# TkPointerDeadWindow() and subsequent reading in GenerateEnterLeave().
setup_win_mousepointer .one
wm withdraw .one
create_and_pack_frames .one
wm deiconify .one
tkwait visibility .one.f1.f2
_pause 200
bind all <Leave> {append result "<Leave> %d %W|"}
bind all <Enter> {append result "<Enter> %d %W|"}
set result "|"
} -body {
destroy .one.f1.f2
_pause 200; # service crossing events
destroy .one.f1
_pause 200; # service crossing events
set result
} -cleanup {
bind all <Leave> {}
bind all <Enter> {}
destroy .one
unset result
} -result {|<Enter> NotifyInferior .one.f1|<Enter> NotifyInferior .one|}
test event-9.18 {Successive destructions (pointer window + ancestors including its toplevel), destination is non-root toplevel} -setup {
setup_win_mousepointer .one
toplevel .two
pack propagate .two 0
wm geometry .two 300x300+100+100
create_and_pack_frames .two
wm deiconify .two
waitForWindowEvent .two.f1.f2 <Enter>
bind all <Leave> {append result "<Leave> %d %W|"}
bind all <Enter> {append result "<Enter> %d %W|"}
set result "|"
} -body {
destroy .two
waitForWindowEvent .one <Enter>
bind all <Leave> {}
bind all <Enter> {}
destroy .one
set result
} -cleanup {
unset result
} -result {|<Enter> NotifyNonlinear .one|}
test event-9.19 {Successive destructions (pointer window + ancestors including its toplevel), destination is internal window, bypass root win} -setup {
setup_win_mousepointer .one; # ensure the mouse pointer is where we want it to be (the .one toplevel is not itself used in this test)
destroy .one
toplevel .two
pack propagate .two 0
wm geometry .two 300x300+100+100
create_and_pack_frames .two
wm deiconify .two
waitForWindowEvent .two.f1.f2 <Enter>
toplevel .three
pack propagate .three 0
wm geometry .three 300x300+110+110
create_and_pack_frames .three
wm deiconify .three
waitForWindowEvent .three.f1.f2 <Enter>
bind all <Leave> {append result "<Leave> %d %W|"}
bind all <Enter> {append result "<Enter> %d %W|"}
set result "|"
} -body {
destroy .three
waitForWindowEvent .two.f1.f2 <Enter>
bind all <Leave> {}
bind all <Enter> {}
destroy .two
set result
} -cleanup {
unset result
} -result {|<Enter> NotifyNonlinearVirtual .two|<Enter> NotifyNonlinearVirtual .two.f1|<Enter> NotifyNonlinear .two.f1.f2|}
test event-9.20 {Successive destructions (pointer window + ancestors including its toplevel), destination is screen root} -setup {
setup_win_mousepointer .one; # ensure the mouse pointer is where we want it to be (the .one toplevel is not itself used in this test)
destroy .one
toplevel .two
pack propagate .two 0
wm geometry .two 300x300+100+100
create_and_pack_frames .two
wm deiconify .two
waitForWindowEvent .two.f1.f2 <Enter>
bind all <Leave> {append result "<Leave> %d %W|"}
bind all <Enter> {append result "<Enter> %d %W|"}
set result "|"
} -body {
destroy .two
_pause 200; # service events (only screen drawing events expected)
set result
} -cleanup {
bind all <Leave> {}
bind all <Enter> {}
unset result
} -result {|}
# cleanup
update
unset -nocomplain keypress_lookup
rename _init_keypress_lookup {}
rename _keypress_lookup {}
rename _keypress {}
rename _pause {}
rename _text_ind_to_x_y {}
rename _get_selection {}
rename create_and_pack_frames {}
rename setup_win_mousepointer {}
cleanupTests
return
|