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
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
|
#
# [7Jun2005] TO CHECK: [$tv see {}] -- shouldn't work (at least, shouldn't do
# what it currently does)
#
package require tk
package require tcltest 2.2
namespace import -force tcltest::*
loadTestedCommands
# consistencyCheck --
# Traverse the tree to make sure the item data structures
# are properly linked.
#
# Since [$tv children] follows ->next links and [$tv index]
# follows ->prev links, this should cover all invariants.
#
proc consistencyCheck {tv {item {}}} {
set i 0
foreach child [$tv children $item] {
assert {[$tv parent $child] == $item} "parent $child = $item"
assert {[$tv index $child] == $i} "index $child [$tv index $child]=$i"
incr i
consistencyCheck $tv $child
}
}
proc assert {expr {message ""}} {
if {![uplevel 1 [list expr $expr]]} {
set error "PANIC! PANIC! PANIC: $message ($expr failed)"
puts stderr $error
error $error
}
}
proc tvSetup {} {
destroy .tv
ttk::treeview .tv -columns {a b c}
pack .tv -expand true -fill both
.tv column #0 -width 50
.tv column a -width 50
.tv column b -width 50
.tv column c -width 50
# Make sure everything is created and updated
tkwait visibility .tv
update
after 10
update
}
proc tvSetupWithItems {} {
tvSetup
.tv insert {} end -id nn -text "nn"
.tv insert nn end -id nn.n1 -text "nn.1"
.tv insert nn end -id nn.n2 -text "nn.3"
.tv insert nn end -id nn.n3 -text "nn.3"
for {set t 2} {$t < 100} {incr t} {
.tv insert {} end -id nn$t -text "nn$t"
if {$t % 3 == 0} {
.tv insert nn$t end -id nn$t.n1 -text "nn$t.n1"
.tv insert nn$t end -id nn$t.n2 -text "nn$t.n2"
.tv insert nn$t end -id nn$t.n3 -text "nn$t.n3"
}
}
}
test treeview-1.1 "columns" -body {
tvSetup
.tv configure -columns {a b c}
}
test treeview-1.2 "Bad columns" -body {
#.tv configure -columns {illegal "list"value}
ttk::treeview .badtv -columns {illegal "list"value}
} -returnCodes error -result "list element in quotes followed by*" -match glob
test treeview-1.3 "bad displaycolumns" -body {
.tv configure -displaycolumns {a b d}
} -returnCodes error -result "Invalid column index d"
test treeview-1.4 "more bad displaycolumns" -body {
.tv configure -displaycolumns {1 2 3}
} -returnCodes error -result {Column index "3" out of bounds}
test treeview-1.5 "Don't forget to check negative numbers" -body {
.tv configure -displaycolumns {1 {} 3}
} -returnCodes error -result {Column index "" out of bounds}
# Item creation.
#
test treeview-2.1 "insert -- not enough args" -body {
.tv insert
} -returnCodes error -result "wrong # args: *" -match glob
test treeview-2.3 "insert -- bad integer index" -body {
.tv insert {} badindex
} -returnCodes error -result "expected integer *" -match glob
test treeview-2.4 "insert -- bad parent node" -body {
.tv insert badparent end
} -returnCodes error -result "Item badparent not found" -match glob
test treeview-2.5 "insert -- finaly insert a node" -body {
.tv insert {} end -id newnode -text "New node"
} -result newnode
test treeview-2.6 "insert -- make sure node was inserted" -body {
.tv children {}
} -result [list newnode]
test treeview-2.7 "insert -- prevent duplicate node names" -body {
.tv insert {} end -id newnode
} -returnCodes error -result "Item newnode already exists"
test treeview-2.8 "insert -- new node at end" -body {
.tv insert {} end -id lastnode
consistencyCheck .tv
.tv children {}
} -result [list newnode lastnode]
test treeview-2.9 "insert -- new node at beginning" -body {
.tv insert {} 0 -id firstnode
consistencyCheck .tv
.tv children {}
} -result [list firstnode newnode lastnode]
test treeview-2.10 "insert -- one more node" -body {
.tv insert {} 2 -id onemore
consistencyCheck .tv
.tv children {}
} -result [list firstnode newnode onemore lastnode]
test treeview-2.11 "insert -- and another one" -body {
.tv insert {} 2 -id anotherone
consistencyCheck .tv
.tv children {}
} -result [list firstnode newnode anotherone onemore lastnode]
test treeview-2.12 "insert -- one more at end" -body {
.tv insert {} end -id newlastone
consistencyCheck .tv
.tv children {}
} -result [list firstnode newnode anotherone onemore lastnode newlastone]
test treeview-2.13 "insert -- one more at beginning" -body {
.tv insert {} 0 -id newfirstone
consistencyCheck .tv
.tv children {}
} -result [list newfirstone firstnode newnode anotherone onemore lastnode newlastone]
test treeview-2.14 "insert -- bad options" -body {
.tv insert {} end -badoption foo
} -returnCodes error -result {unknown option "-badoption"}
test treeview-2.15 "insert -- at position 0 w/no children" -body {
.tv insert newnode 0 -id newnode.n2 -text "Foo"
.tv children newnode
} -result newnode.n2 ;# don't crash
test treeview-2.16 "insert -- insert way past end" -body {
.tv insert newnode 99 -id newnode.n3 -text "Foo"
consistencyCheck .tv
.tv children newnode
} -result [list newnode.n2 newnode.n3]
test treeview-2.17 "insert -- insert before beginning" -body {
.tv insert newnode -1 -id newnode.n1 -text "Foo"
consistencyCheck .tv
.tv children newnode
} -result [list newnode.n1 newnode.n2 newnode.n3]
###
#
test treeview-3.1 "parent" -body {
.tv parent newnode.n1
} -result newnode
test treeview-3.2 "parent - top-level node" -body {
.tv parent newnode
} -result {}
test treeview-3.3 "parent - root node" -body {
.tv parent {}
} -result {}
test treeview-3.4 "index" -body {
list [.tv index newnode.n3] [.tv index newnode.n2] [.tv index newnode.n1]
} -result [list 2 1 0]
test treeview-3.5 "index - exhaustive test" -body {
set result [list]
foreach item [.tv children {}] {
lappend result [.tv index $item]
}
set result
} -result [list 0 1 2 3 4 5 6]
test treeview-3.6 "detach" -body {
.tv detach newnode
consistencyCheck .tv
.tv children {}
} -result [list newfirstone firstnode anotherone onemore lastnode newlastone]
# XREF: treeview-2.13
test treeview-3.7 "detach didn't screw up internal links" -body {
consistencyCheck .tv
set result [list]
foreach item [.tv children {}] {
lappend result [.tv index $item]
}
set result
} -result [list 0 1 2 3 4 5]
test treeview-3.8 "detached node has no parent, index 0" -body {
list [.tv parent newnode] [.tv index newnode]
} -result [list {} 0]
# @@@ Can't distinguish detached nodes from first root node
test treeview-3.9 "detached node's children undisturbed" -body {
.tv children newnode
} -result [list newnode.n1 newnode.n2 newnode.n3]
test treeview-3.10 "detach is idempotent" -body {
.tv detach newnode
consistencyCheck .tv
.tv children {}
} -result [list newfirstone firstnode anotherone onemore lastnode newlastone]
test treeview-3.11 "Can't detach root item" -body {
.tv detach [list {}]
} -cleanup {
update
consistencyCheck .tv
} -returnCodes error -result "Cannot detach root item"
test treeview-3.12 "Reattach" -body {
.tv move newnode {} end
consistencyCheck .tv
.tv children {}
} -result [list newfirstone firstnode anotherone onemore lastnode newlastone newnode]
# Bug # ?????
test treeview-3.13 "Re-reattach" -body {
.tv move newnode {} end
consistencyCheck .tv
.tv children {}
} -result [list newfirstone firstnode anotherone onemore lastnode newlastone newnode]
catch {
.tv insert newfirstone end -id x1
.tv insert newfirstone end -id x2
.tv insert newfirstone end -id x3
}
test treeview-3.14 "Duplicated entry in children list" -body {
.tv children newfirstone [list x3 x1 x2 x3]
# ??? Maybe this should raise an error?
consistencyCheck .tv
.tv children newfirstone
} -result [list x3 x1 x2]
test treeview-3.14.1 "Duplicated entry in children list" -body {
.tv children newfirstone [list x1 x2 x3 x3 x2 x1]
consistencyCheck .tv
.tv children newfirstone
} -result [list x1 x2 x3]
test treeview-3.15 "Consecutive duplicate entries in children list" -body {
.tv children newfirstone [list x1 x2 x2 x3]
consistencyCheck .tv
.tv children newfirstone
} -result [list x1 x2 x3]
test treeview-3.16 "Insert child after self" -body {
.tv move x2 newfirstone 1
consistencyCheck .tv
.tv children newfirstone
} -result [list x1 x2 x3]
test treeview-3.17 "Insert last child after self" -body {
.tv move x3 newfirstone 2
consistencyCheck .tv
.tv children newfirstone
} -result [list x1 x2 x3]
test treeview-3.18 "Insert last child after end" -body {
.tv move x3 newfirstone 3
consistencyCheck .tv
.tv children newfirstone
} -result [list x1 x2 x3]
test treeview-4.1 "opened - initial state" -body {
.tv item newnode -open
} -result 0
test treeview-4.2 "opened - open node" -body {
.tv item newnode -open 1
.tv item newnode -open
} -result 1
test treeview-4.3 "opened - closed node" -body {
.tv item newnode -open 0
.tv item newnode -open
} -result 0
test treeview-5.1 "item -- error checks" -body {
.tv item newnode -text "Bad values" -values "{bad}list"
} -returnCodes error -result "list element in braces followed by*" -match glob
test treeview-5.2 "item -- error leaves options unchanged " -body {
.tv item newnode -text
} -result "New node"
test treeview-5.3 "Heading" -body {
.tv heading #0 -text "Heading"
}
test treeview-5.4 "get cell" -body {
set l [list a b c]
.tv item newnode -values $l
.tv set newnode 1
} -result b
test treeview-5.5 "set cell" -body {
.tv set newnode 1 XXX
.tv item newnode -values
} -result [list a XXX c]
test treeview-5.6 "set illegal cell" -body {
.tv set newnode #0 YYY
} -returnCodes error -result "Display column #0 cannot be set"
test treeview-5.7 "set illegal cell" -body {
.tv set newnode 3 YY ;# 3 == current #columns
} -returnCodes error -result {Column index "3" out of bounds}
test treeview-5.8 "set display columns" -body {
.tv configure -displaycolumns [list 2 1 0]
.tv set newnode #1 X
.tv set newnode #2 Y
.tv set newnode #3 Z
.tv item newnode -values
} -result [list Z Y X]
test treeview-5.9 "display columns part 2" -body {
list [.tv column #1 -id] [.tv column #2 -id] [.tv column #3 -id]
} -result [list c b a]
test treeview-5.10 "cannot set column -id" -body {
.tv column #1 -id X
} -returnCodes error -result "Attempt to change read-only option"
test treeview-5.11 "get" -body {
.tv set newnode #1
} -result X
test treeview-5.12 "get dictionary" -body {
.tv set newnode
} -result [list a Z b Y c X]
test treeview-5.13 "get, no value" -body {
set newitem [.tv insert {} end]
set result [.tv set $newitem #1]
.tv delete $newitem
set result
} -result {}
test treeview-5.14 "set illegal height" -body {
# For now, -height can only be integer
.tv item newnode -height 1.5
} -returnCodes 1 -result {expected integer but got "1.5"}
test treeview-5.15 "set illegal height" -body {
.tv item newnode -height 0
} -returnCodes 1 -result "Invalid item height 0"
test treeview-5.16 "no change after illegal attempt" -body {
.tv item newnode -height
} -result 1
test treeview-6.1 "deletion - setup" -body {
.tv insert {} end -id dtest
foreach id [list a b c d e] {
.tv insert dtest end -id $id
}
.tv children dtest
} -result [list a b c d e]
test treeview-6.1.1 "delete" -body {
.tv delete b
consistencyCheck .tv
list [.tv exists b] [.tv children dtest]
} -result [list 0 [list a c d e]]
test treeview-6.2 "delete - duplicate items in list" -body {
.tv delete [list a e a e]
consistencyCheck .tv
.tv children dtest
} -result [list c d]
test treeview-6.3 "delete - descendants removed" -body {
.tv insert c end -id c1
.tv insert c end -id c2
.tv insert c1 end -id c11
consistencyCheck .tv
.tv delete c
consistencyCheck .tv
list [.tv exists c] [.tv exists c1] [.tv exists c2] [.tv exists c11]
} -result [list 0 0 0 0]
test treeview-6.4 "delete - delete parent and descendants" -body {
.tv insert dtest end -id c
.tv insert c end -id c1
.tv insert c end -id c2
.tv insert c1 end -id c11
consistencyCheck .tv
.tv delete [list c c1 c2 c11]
consistencyCheck .tv
list [.tv exists c] [.tv exists c1] [.tv exists c2] [.tv exists c11]
} -result [list 0 0 0 0]
test treeview-6.5 "delete - delete descendants and parent" -body {
.tv insert dtest end -id c
.tv insert c end -id c1
.tv insert c end -id c2
.tv insert c1 end -id c11
consistencyCheck .tv
.tv delete [list c11 c1 c2 c]
consistencyCheck .tv
list [.tv exists c] [.tv exists c1] [.tv exists c2] [.tv exists c11]
} -result [list 0 0 0 0]
test treeview-6.6 "delete - end" -body {
consistencyCheck .tv
.tv children dtest
} -result [list d]
test treeview-7.1 "move" -body {
.tv insert d end -id d1
.tv insert d end -id d2
.tv insert d end -id d3
.tv move d3 d 0
consistencyCheck .tv
.tv children d
} -result [list d3 d1 d2]
test treeview-7.2 "illegal move" -body {
.tv move d d2 end
} -returnCodes error -result "Cannot insert d as descendant of d2"
test treeview-7.3 "illegal move has no effect" -body {
consistencyCheck .tv
.tv children d
} -result [list d3 d1 d2]
test treeview-7.4 "Replace children" -body {
.tv children d [list d3 d2 d1]
consistencyCheck .tv
.tv children d
} -result [list d3 d2 d1]
test treeview-7.5 "replace children - precondition" -body {
# Just check to make sure the test suite so far has left
# us in the state we expect to be in:
list [.tv parent newnode] [.tv children newnode]
} -result [list {} [list newnode.n1 newnode.n2 newnode.n3]]
test treeview-7.6 "Replace children - illegal move" -body {
.tv children newnode.n1 [list newnode.n1 newnode.n2 newnode.n3]
} -cleanup {
consistencyCheck .tv
} -returnCodes error -result "Cannot insert newnode.n1 as descendant of newnode.n1"
test treeview-8.0 "Selection set" -body {
.tv selection set [list newnode.n1 newnode.n3 newnode.n2]
.tv selection
} -result [list newnode.n1 newnode.n2 newnode.n3]
test treeview-8.1 "Selection add" -body {
.tv selection add [list newnode]
.tv selection
} -result [list newnode newnode.n1 newnode.n2 newnode.n3]
test treeview-8.2 "Selection toggle" -body {
.tv selection toggle [list newnode.n2 d3]
.tv selection
} -result [list newnode newnode.n1 newnode.n3 d3]
test treeview-8.3 "Selection remove" -body {
.tv selection remove [list newnode.n2 d3]
.tv selection
} -result [list newnode newnode.n1 newnode.n3]
test treeview-8.4 "Selection - clear" -body {
.tv selection set {}
.tv selection
} -result {}
test treeview-8.5 "Selection - bad operation" -body {
.tv selection badop foo
} -returnCodes error -match glob -result {bad selection operation "badop": must be *}
test treeview-8.7 "<<TreeviewSelect>> when deleting items" -body {
.tv delete [.tv children {}]
.tv insert "" end -id myItem1 -text FirstItem
.tv insert "" end -id myItem2 -text SecondItem
.tv selection add myItem1
update
bind .tv <<TreeviewSelect>> {lappend res $val}
set res {}
set val 1
.tv delete myItem2 ; # no <<TreeviewSelect>> (selection unchanged)
update
set val 2
.tv delete myItem1 ; # <<TreeviewSelect>> triggers
update
set res
} -cleanup {
bind .tv <<TreeviewSelect>> {}
} -result {2}
test treeview-8.8 "<<TreeviewSelect>> when setting the selection" -body {
.tv delete [.tv children {}]
.tv insert "" end -id myItem1 -text FirstItem
.tv insert "" end -id myItem2 -text SecondItem
update
bind .tv <<TreeviewSelect>> {lappend res $val}
set res {}
set val 1
.tv selection set "" ; # no <<TreeviewSelect>> (selection unchanged)
update
set val 2
.tv selection set myItem1 ; # <<TreeviewSelect>> triggers
update
# Current implementation generates an event for this case
set val 3
.tv selection set myItem1 ; # (already selected)
update
set val 4
.tv selection set {myItem1 myItem2} ; # <<TreeviewSelect>> triggers
update
set val 5
.tv selection set {myItem2} ; # <<TreeviewSelect>> triggers
update
set res
} -cleanup {
bind .tv <<TreeviewSelect>> {}
} -result {2 3 4 5}
test treeview-8.9 "<<TreeviewSelect>> when removing items from the selection" -body {
.tv delete [.tv children {}]
.tv insert "" end -id myItem1 -text FirstItem
.tv selection set myItem1
update
bind .tv <<TreeviewSelect>> {lappend res $val}
set res {}
set val 1
.tv selection remove "" ; # no <<TreeviewSelect>> (selection unchanged)
update
set val 2
.tv selection remove myItem1 ; # <<TreeviewSelect>> triggers
update
set val 3
.tv selection remove myItem1 ; # no <<TreeviewSelect>> (selection unchanged)
update
set res
} -cleanup {
bind .tv <<TreeviewSelect>> {}
} -result {2}
test treeview-8.10 "<<TreeviewSelect>> when adding items in the selection" -body {
.tv delete [.tv children {}]
.tv insert "" end -id myItem1 -text FirstItem
.tv insert "" end -id myItem2 -text SecondItem
.tv insert "" end -id myItem3 -text ThirdItem
update
bind .tv <<TreeviewSelect>> {lappend res $val}
set res {}
set val 1
.tv selection add myItem2 ; # <<TreeviewSelect>> triggers
update
set val 2
.tv selection add myItem2 ; # no <<TreeviewSelect>> (selection unchanged)
update
set val 3
.tv selection add myItem3 ; # <<TreeviewSelect>> triggers
update
set res
} -cleanup {
bind .tv <<TreeviewSelect>> {}
} -result {1 3}
test treeview-8.11 "<<TreeviewSelect>> when toggling" -body {
.tv delete [.tv children {}]
.tv insert "" end -id myItem1 -text FirstItem
.tv insert "" end -id myItem2 -text SecondItem
.tv insert "" end -id myItem3 -text ThirdItem
update
bind .tv <<TreeviewSelect>> {lappend res $val}
set res {}
set val 1
.tv selection toggle "" ; # no <<TreeviewSelect>> (selection unchanged)
update
set val 2
.tv selection toggle {myItem1 myItem3} ; # <<TreeviewSelect>> triggers
update
set val 3
.tv selection toggle {myItem3 myItem2} ; # <<TreeviewSelect>> triggers
update
set val 4
.tv selection toggle {myItem3 myItem2} ; # <<TreeviewSelect>> triggers
update
set res
} -cleanup {
bind .tv <<TreeviewSelect>> {}
} -result {2 3 4}
### NEED: more tests for see/yview/scrolling
proc scrollcallback {args} {
set ::scrolldata $args
}
test treeview-9.0 "scroll callback - empty tree" -body {
tvSetup
.tv configure -yscrollcommand scrollcallback
.tv delete [.tv children {}]
update
set ::scrolldata
} -result [list 0.0 1.0]
test treeview-9.1 "scrolling" -setup {
pack [ttk::treeview .tree -show tree] -fill y
for {set i 1} {$i < 100} {incr i} {
.tree insert {} end -text $i
}
} -body {
.tree yview scroll 5 units
# This is sensitive to the exact layout of a tree.
# It assumes that (8,8) should be far enough in to be in the tree,
# while still being in the first item.
.tree identify item 8 8
} -cleanup {
destroy .tree
} -result {I006}
test treeview-9.2 {scrolling on see command - bug [14188104c3]} -setup {
toplevel .top
ttk::treeview .top.tree -show {} -height 10 -columns {label} \
-yscrollcommand [list .top.vs set]
ttk::scrollbar .top.vs -command {.top.tree yview}
grid .top.tree -row 0 -column 0 -sticky ns
grid .top.vs -row 0 -column 1 -sticky ns
update
proc setrows {n} {
.top.tree delete [.top.tree children {}]
for {set i 1} {$i <= $n} {incr i} {
.top.tree insert {} end -id row$i \
-values [list [format "Row %2.2d" $i]]
}
.top.tree see row1
update idletasks
}
} -body {
setrows 10
set res [.top.vs get]
setrows 20
lappend res [expr [lindex [.top.vs get] 1] < 1]
} -cleanup {
destroy .top
} -result {0.0 1.0 1}
test treeview-9.3 {scrolling on see command, requested item is closed} -setup {
toplevel .top
ttk::treeview .top.tree -show tree -height 10 -columns {label} \
-yscrollcommand [list .top.vs set]
ttk::scrollbar .top.vs -command {.top.tree yview}
grid .top.tree -row 0 -column 0 -sticky ns
grid .top.vs -row 0 -column 1 -sticky ns
.top.tree insert {} end -id a -text a
.top.tree insert a end -id b -text b
.top.tree insert b end -id c -text c
.top.tree insert c end -id d -text d
.top.tree insert d end -id e -text e
for {set i 6} {$i <= 15} {incr i} {
.top.tree insert {} end -id row$i \
-values [list [format "Row %2.2d" $i]]
}
update
} -body {
set before [lindex [.top.vs get] 1]
.top.tree see e
update idletasks
set after [lindex [.top.vs get] 1]
expr $after < $before
} -cleanup {
destroy .top
} -result 1
test treeview-10.0 "See command" -setup {
# Setup common for all 10.* tests
ttk::style configure Treeview -rowheight 20
tvSetupWithItems
set ::baseBbY [lindex [.tv bbox nn "#1"] 1]
proc bbY {item} {
set bb [.tv bbox $item "#1"]
set y [lindex $bb 1]
if {$y eq ""} {return "_"}
return [expr {$y - $::baseBbY}]
}
} -body {
set res ""
lappend res [bbY nn99]
.tv see nn99
lappend res [bbY nn99]
set res
} -result {_ 180}
test treeview-10.1 "See command, auto-open" -body {
set res ""
lappend res [bbY nn96]
# Not yet visible
lappend res [bbY nn96.n1]
.tv see nn96.n1
lappend res [bbY nn96.n1]
# Pushed out by the opening, not visible
lappend res [bbY nn99]
set res
} -result {120 _ 140 _}
test treeview-10.2 "See command, height" -setup {
.tv item nn34 -height 4
.tv item nn55 -height 30
.tv item nn76 -height 5
} -body {
set res ""
lappend res [bbY nn34]
.tv see nn34
lappend res [bbY nn34]
.tv see nn33
lappend res [bbY nn34]
lappend res [bbY nn76]
.tv see nn76
lappend res [bbY nn76]
.tv see nn53
lappend res [bbY nn53]
# Partly visible
lappend res [bbY nn55]
.tv see nn55
# Scrolled to top
lappend res [bbY nn55]
set res
} -result {_ 0 20 _ 100 0 40 0}
test treeview-11.0 "Cellselection set rectangle" -setup {
# Setup common for all 11.* tests
tvSetupWithItems
.tv configure -columns {a b c d}
.tv configure -displaycolumns {a b c}
} -body {
.tv cellselection set "nn.n3 #2" "nn.n1 a"
.tv cellselection
} -result [list "nn.n1 a" "nn.n1 b" "nn.n2 a" "nn.n2 b" "nn.n3 a" "nn.n3 b"]
test treeview-11.1 "Cellselection set" -body {
.tv cellselection set [list "nn.n1 a" "nn.n2 a" "nn.n3 #2" "nn.n2 d"]
.tv cellselection
} -result [list "nn.n1 a" "nn.n2 a" "nn.n2 d" "nn.n3 b"]
test treeview-11.2 "Cellselection add" -body {
.tv cellselection add "nn b"
.tv cellselection
} -result [list "nn b" "nn.n1 a" "nn.n2 a" "nn.n2 d" "nn.n3 b"]
test treeview-11.3 "Cellselection toggle" -body {
.tv cellselection toggle [list "nn.n2 a" "nn2 b" "nn2 #0"]
.tv cellselection
} -result [list "nn b" "nn.n1 a" "nn.n2 d" "nn.n3 b" "nn2 b" "nn2 #0"]
test treeview-11.4 "Cellselection remove" -body {
.tv cellselection remove [list "nn.n2 d" "nn b" "nn2 #0"]
.tv cellselection
} -result [list "nn.n1 a" "nn.n3 b" "nn2 b"]
test treeview-11.5 "Cellselection add rectangle" -body {
.tv cellselection add "nn a" "nn.n1 c"
.tv cellselection
} -result [list \
"nn a" "nn b" "nn c" \
"nn.n1 a" "nn.n1 b" "nn.n1 c" \
"nn.n3 b" \
"nn2 b"]
test treeview-11.6 "Cellselection toggle rectangle" -body {
.tv cellselection toggle "nn.n1 b" "nn.n3 c"
.tv cellselection
} -result [list \
"nn a" "nn b" "nn c" \
"nn.n1 a" \
"nn.n2 b" "nn.n2 c" \
"nn.n3 c" \
"nn2 b"]
test treeview-11.7 "Cellselection remove rectangle" -body {
.tv cellselection remove "nn.n1 a" "nn.n3 b"
.tv cellselection
} -result [list \
"nn a" "nn b" "nn c" \
"nn.n2 c" \
"nn.n3 c" \
"nn2 b"]
test treeview-11.8 "Cellselection set rectangle" -body {
# This tests that "set" clears out all old selections
.tv cellselection set "nn b" "nn.n1 c"
.tv cellselection
} -result [list "nn b" "nn c" "nn.n1 b" "nn.n1 c"]
test treeview-11.9 "Cellselection - clear" -body {
.tv cellselection set {}
.tv cellselection
} -result {}
test treeview-11.10 "Cellselection - bad operation" -body {
.tv cellselection badop foo
} -returnCodes 1 -match glob -result {bad cellselection operation "badop": must be *}
test treeview-11.11 "Cellselection - <<TreeviewSelect>> on cellselection add" -body {
.tv cellselection set {}
bind .tv <<TreeviewSelect>> {set res 1}
set res 0
.tv cellselection add {"nn.n1 b"}
update
set res
} -cleanup {
bind .tv <<TreeviewSelect>> {}
} -result 1
test treeview-11.12 "<<TreeviewSelect>> on selected cell deletion" -body {
.tv cellselection set {}
.tv insert "" end -id selectedDoomed -text DeadItem
.tv insert "" end -id doomed -text AlsoDead
.tv cellselection add {"selectedDoomed c"}
.tv cellselection add {"doomed c"}
.tv cellselection remove {"doomed c"}
update
bind .tv <<TreeviewSelect>> {lappend res 1}
set res 0
.tv delete doomed
update
set res [expr {$res == 0}]
.tv delete selectedDoomed
update
set res
} -cleanup {
bind .tv <<TreeviewSelect>> {}
} -result {1 1}
test treeview-11.13 "Cellselection - error" -body {
.tv cellselection set [list "apa a"]
} -returnCodes 1 -match glob -result {Item apa not found}
test treeview-11.14 "Cellselection - error" -body {
.tv cellselection set [list "nn xx "]
} -returnCodes 1 -match glob -result {Invalid column index xx}
test treeview-11.15 "Cellselection - error" -body {
.tv cellselection set "nn c" "nn d"
} -returnCodes 1 -match glob -result {Cell id must be in a visible column}
test treeview-11.16 "Cellselection - non visible" -body {
.tv cellselection set [list "nn d"]
.tv cellselection
} -result {{nn d}}
# Same as 8.8, but for cell selection
test treeview-11.17 "<<TreeviewSelect>> when setting the selection" -body {
.tv delete [.tv children {}]
.tv insert "" end -id myItem1 -text FirstItem
.tv insert "" end -id myItem2 -text SecondItem
update
bind .tv <<TreeviewSelect>> {lappend res $val}
set res {}
set val 1
.tv cellselection set "" ; # no <<TreeviewSelect>> (selection unchanged)
update
set val 2
.tv cellselection set "myItem1 a" ; # <<TreeviewSelect>> triggers
update
# Current implementation generates an event for this case
set val 3
.tv cellselection set "myItem1 a" ; # (already selected)
update
set val 4
.tv cellselection set {{myItem1 a} {myItem2 a}} ; # <<TreeviewSelect>>
update
set val 5
.tv cellselection set {myItem2 a} ; # <<TreeviewSelect>> triggers
update
set res
} -cleanup {
bind .tv <<TreeviewSelect>> {}
} -result {2 3 4 5}
### identify tests:
#
proc identify* {tv comps args} {
foreach {x y} $args {
foreach comp $comps {
lappend result [$tv identify $comp $x $y]
}
}
return $result
}
# get list of column IDs from list of display column ids.
#
proc columnids {tv dcols} {
set result [list]
foreach dcol $dcols {
if {[catch {
lappend result [$tv column $dcol -id]
}]} {
lappend result ERROR
}
}
return $result
}
test treeview-identify-setup "identify series - setup" -body {
destroy .tv
ttk::setTheme default
ttk::style configure Treeview -rowheight 20
ttk::treeview .tv -columns [list A B C]
.tv insert {} end -id branch -text branch -open true
.tv insert branch end -id item1 -text item1 -height 2
.tv insert branch end -id item2 -text item2
.tv insert branch end -id item3 -text item3
.tv insert {} end -id item4 -text item4
.tv column #0 -width 50 ;# 0-50
.tv column A -width 50 ;# 50-100
.tv column B -width 50 ;# 100-150
.tv column C -width 50 ;# 150-200 (plus slop for margins)
wm geometry . {} ; pack .tv ; update
}
test treeview-identify-1 "identify heading" -body {
.tv configure -show {headings tree}
update idletasks
identify* .tv {region column} 10 10
} -result [list heading #0]
test treeview-identify-2 "identify columns" -body {
.tv configure -displaycolumns #all
update idletasks
columnids .tv [identify* .tv column 25 10 75 10 125 10 175 10]
} -result [list \#0 A B C]
test treeview-identify-3 "reordered columns" -body {
.tv configure -displaycolumns {B A C}
update idletasks
columnids .tv [identify* .tv column 25 10 75 10 125 10 175 10]
} -result [list \#0 B A C]
test treeview-identify-4 "no tree column" -body {
.tv configure -displaycolumns #all -show {headings}
update idletasks
identify* .tv {region column} 25 10 75 10 125 10 175 10
} -result [list heading #1 heading #2 heading #3 nothing {}]
# Item height in default theme is 20px
test treeview-identify-5 "vertical scan - no headings" -body {
.tv configure -displaycolumns #all -show {tree}
update idletasks
identify* .tv {region item} 25 10 25 30 25 70 25 90 25 110 25 130
} -result [list tree branch tree item1 tree item2 tree item3 tree item4 nothing {}]
test treeview-identify-6 "vertical scan - with headings" -body {
.tv configure -displaycolumns #all -show {tree headings}
update idletasks
identify* .tv {region item} 25 10 25 30 25 50 25 90 25 110
} -result [list heading {} tree branch tree item1 tree item2 tree item3]
test treeview-identify-7 "vertical scan - headings, no tree" -body {
.tv configure -displaycolumns #all -show {headings}
update idletasks
identify* .tv {region item cell} 25 10 25 30 25 50 75 90 25 110
} -result [list heading {} {} cell branch {branch #1} cell item1 {item1 #1} cell item2 {item2 #2} cell item3 {item3 #1}]
# In default theme, -indent and -itemheight both 20px
# Disclosure element name is "Treeitem.indicator"
set disclosure "*.indicator"
test treeview-identify-8 "identify element" -body {
.tv configure -show {tree}
.tv insert branch 0 -id branch2 -open true
.tv insert branch2 0 -id branch3 -open true
.tv insert branch3 0 -id leaf3
update idletasks;
identify* .tv {item element} 10 10 30 30 50 50
} -match glob -result [list \
branch $disclosure branch2 $disclosure branch3 $disclosure]
test treeview-identify-8.1 "identify element" -body {
.tv configure -show {tree headings}
update
identify* .tv element 1 1 10 10 25 25
# Heading elements are currently not reported
} -result [list {} {} text]
# See #2381555
test treeview-identify-9 "identify works when horizontally scrolled" -setup {
.tv configure -show {tree headings}
foreach column {#0 A B C} {
.tv column $column -stretch 0 -width 50
}
# Scrollable area is 200, visible is 100
place .tv -x 0 -y 0 -width 100
} -body {
set result [list]
foreach xoffs {0 50 100} {
.tv xview $xoffs ; update
lappend result [identify* .tv {region column} 10 10 60 10]
}
set result
} -result [list \
[list heading #0 heading #1] \
[list heading #1 heading #2] \
[list heading #2 heading #3] ]
test treeview-identify-10 "identify works when horizontally scrolled" -setup {
.tv configure -show {tree headings}
.tv configure -titlecolumns 1
foreach column {"#0" A B C} {
.tv column $column -stretch 0 -width 50
}
# Scrollable area is 200, visible is 150
place .tv -x 0 -y 0 -width 150
} -body {
set result [list]
foreach xoffs {0 25 50} {
.tv xview $xoffs
update
lappend result [identify* .tv {region column} 10 10 60 10]
lappend result [identify* .tv {region column} 10 50 60 50]
}
set result
} -result [list \
[list heading #0 heading #1] [list tree #0 cell #1] \
[list heading #0 heading #1] [list tree #0 cell #1] \
[list heading #0 heading #2] [list tree #0 cell #2] ]
# Hijack the setup above to check bbox too
test treeview-identify-10b "bbox works when horizontally scrolled" -body {
# Establish a point of reference
.tv configure -titlecolumns 0
.tv xview 0
update
set base [lindex [.tv bbox branch "#0"] 0]
set result [list]
foreach tc {0 1 2 3} {
.tv configure -titlecolumns $tc
foreach xoffs {0 25 50} {
.tv xview $xoffs
update
# Extract x coordinate for each column
lappend result [expr {[lindex [.tv bbox branch "#0"] 0] - $base}]
lappend result [expr {[lindex [.tv bbox branch A ] 0] - $base}]
lappend result [expr {[lindex [.tv bbox branch B ] 0] - $base}]
lappend result [expr {[lindex [.tv bbox branch C ] 0] - $base}]
}
}
set result
} -result [list 0 50 100 150 -25 25 75 125 -50 0 50 100 \
0 50 100 150 0 25 75 125 0 0 50 100 \
0 50 100 150 0 50 75 125 0 50 50 100 \
0 50 100 150 0 50 100 125 0 50 100 101]
# Followup to trigger crash that happened when title > display
test treeview-identify-10c "title more than display" -body {
.tv configure -titlecolumns 10
.tv xview 0
update
set x1 [.tv xview]
# It shouldn't be possible to scroll
.tv xview 50
update
set x2 [.tv xview]
set result [list $x1 $x2]
} -result {{0.0 1.0} {0.0 1.0}}
test treeview-identify-11 "bbox supporting -height" -body {
.tv configure -titlecolumns 0
.tv xview 0
.tv item branch2 -open false
# Add extra items to make sure it scrolls
.tv insert {} end -id item5 -text item5
.tv insert {} end -id item6 -text item6
# Height needs to be big enough to show the items we measure
# and small enough to make scrolling happen.
.tv configure -height 6
pack .tv -side top
update
set base [lindex [.tv bbox branch A] 1]
set result {}
foreach yv {0 1} {
.tv yview $yv
update
foreach item {item1 item2 item3} {
set bb [.tv bbox $item A]
set y [lindex $bb 1]
if {$y eq ""} {
# This is to get a clearer error if this goes wrong
lappend result {}
} else {
lappend result [expr {$y - $base}]
}
lappend result [lindex $bb 3]
}
}
set result
} -result [list 40 40 80 20 100 20 20 40 60 20 80 20]
test treeview-identify-cleanup "identify - cleanup" -body {
destroy .tv
}
test treeview-rowheight-1 "rowheight - setup" -body {
destroy .tv
ttk::setTheme default
# Test that style rowheight is in control
ttk::style configure Treeview -rowheight 73
tvSetupWithItems
lindex [.tv bbox nn a] 3
} -result 73
test treeview-rowheight-2 "rowheight change" -body {
# Reacts to style changes
ttk::style configure Treeview -rowheight 25
update
lindex [.tv bbox nn a] 3
} -cleanup {
ttk::style configure Treeview -rowheight {}
} -result 25
test treeview-rowheight-3 "rowheight adapts to font" -constraints haveBigFontTwiceLargerThanTextFont -body {
ttk::style configure Treeview -font "Courier 12"
update
set baseline [lindex [.tv bbox nn a] 3]
ttk::style configure Treeview -font "Helvetica 24"
update
set after [lindex [.tv bbox nn a] 3]
set diff [expr {$after - $baseline}]
# We only want to check there is an increase,
# its exact magnitude does not matter
expr {0 < $diff ? "OK" : $diff}
} -result OK
test treeview-rowheight-3b "rowheight adapts to named font" -constraints haveBigFontTwiceLargerThanTextFont -body {
font create __tf -family Courier -size 12
ttk::style configure Treeview -font __tf
update
set baseline [lindex [.tv bbox nn a] 3]
font configure __tf -family Helvetica -size 24
update
set after [lindex [.tv bbox nn a] 3]
set diff [expr {$after - $baseline}]
# We only want to check there is an increase,
# its exact magnitude does not matter
expr {0 < $diff ? "OK" : $diff}
} -result OK
test treeview-rowheight-4 "rowheight adapts to item padding" -body {
# Test that things from Item style is picked up.
ttk::style configure Item -padding "2 2 2 2"
update
set baseline [lindex [.tv bbox nn a] 3]
ttk::style configure Item -padding "2 3 2 5"
update
set after [lindex [.tv bbox nn a] 3]
set diff [expr {$after - $baseline}]
} -cleanup {
ttk::style configure Item -padding {}
} -result [expr {3-2 + 5-2}]
test treeview-rowheight-5 "rowheight adapts to cell padding" -body {
# Test that things from Cell style is picked up.
ttk::style configure Cell -padding "2 5 2 5"
update
set baseline [lindex [.tv bbox nn a] 3]
ttk::style configure Cell -padding "2 8 2 9"
update
set after [lindex [.tv bbox nn a] 3]
set diff [expr {$after - $baseline}]
} -cleanup {
ttk::style configure Cell -padding {}
} -result [expr {8-5 + 9-5}]
### NEED: tests for focus item, selection
### Misc. tests:
destroy .tv
test treeview-1541739 "Root node properly initialized (#1541739)" -setup {
ttk::treeview .tv
.tv insert {} end -id a
.tv see a
} -cleanup {
destroy .tv
}
test treeview-3006842 "Null bindings" -setup {
ttk::treeview .tv -show tree
} -body {
.tv tag bind empty <Button-1> {}
.tv insert {} end -text "Click me" -tags empty
event generate .tv <Button-1> -x 10 -y 10
.tv tag bind empty
} -result {} -cleanup {
destroy .tv
}
test treeview-3085489-1 "tag add, no -tags" -setup {
ttk::treeview .tv
} -body {
set item [.tv insert {} end]
.tv tag add foo $item
.tv item $item -tags
} -cleanup {
destroy .tv
} -result [list foo]
test treeview-3085489-2 "tag remove, no -tags" -setup {
ttk::treeview .tv
} -body {
set item [.tv insert {} end]
.tv tag remove foo $item
.tv item $item -tags
} -cleanup {
destroy .tv
} -result [list]
test treeview-368fa4561e "indicators cannot be clicked on leafs" -setup {
pack [ttk::treeview .tv]
.tv insert {} end -id foo -text "<-- (1) Click the blank space to my left"
update
} -body {
foreach {x y w h} [.tv bbox foo #0] {}
set res [.tv item foo -open]
# using $h even for x computation is intentional here in order to simulate
# a mouse click on the (invisible since we're on a leaf) indicator
event generate .tv <Button-1> \
-x [expr {$x + $h / 2}] \
-y [expr {$y + $h / 2}]
lappend res [.tv item foo -open]
.tv insert foo end -text "sub"
lappend res [.tv item foo -open]
} -cleanup {
destroy .tv
} -result {0 0 0}
test treeview-ce470f20fd-1 "dragging further than the right edge of the treeview is allowed" -setup {
pack [ttk::treeview .tv]
.tv heading #0 -text "Drag my right edge -->"
update
} -body {
set res [.tv column #0 -width]
.tv drag #0 400
lappend res [expr {[.tv column #0 -width] > $res}]
} -cleanup {
destroy .tv
} -result {200 1}
proc nostretch {tv} {
foreach col [$tv cget -columns] {
$tv column $col -stretch 0
}
$tv column #0 -stretch 0
update idletasks ; # redisplay $tv
}
test treeview-ce470f20fd-2 "changing -stretch resizes columns" -setup {
pack [ttk::treeview .tv -columns {bar colA colB colC foo}]
foreach col [.tv cget -columns] {
.tv heading $col -text $col
}
nostretch .tv
.tv column colA -width 50 ; .tv column colB -width 50 ; # slack created
update idletasks ; # redisplay treeview
} -body {
# when no column is stretchable and one of them becomes stretchable
# the stretchable column takes the slack and the widget is redisplayed
# automatically at idle time
set res [.tv column colA -width]
.tv column colA -stretch 1
update idletasks ; # no slack anymore, widget redisplayed
lappend res [expr {[.tv column colA -width] > $res}]
} -cleanup {
destroy .tv
} -result {50 1}
test treeview-ce470f20fd-3 "changing -stretch resizes columns" -setup {
pack [ttk::treeview .tv -columns {bar colA colB colC foo}]
foreach col [.tv cget -columns] {
.tv heading $col -text $col
}
.tv configure -displaycolumns {colB colA colC}
nostretch .tv
.tv column colA -width 50 ; .tv column colB -width 50 ; # slack created
update idletasks ; # redisplay treeview
} -body {
# only some columns are displayed (and in a different order than declared
# in -columns), a displayed column becomes stretchable --> the stretchable
# column expands
set res [.tv column colA -width]
.tv column colA -stretch 1
update idletasks ; # no slack anymore, widget redisplayed
lappend res [expr {[.tv column colA -width] > $res}]
} -cleanup {
destroy .tv
} -result {50 1}
test treeview-ce470f20fd-4 "changing -stretch resizes columns" -setup {
pack [ttk::treeview .tv -columns {bar colA colB colC foo}]
foreach col [.tv cget -columns] {
.tv heading $col -text $col
}
.tv configure -displaycolumns {colB colA colC}
nostretch .tv
.tv column colA -width 50 ; .tv column bar -width 60 ; # slack created
update idletasks ; # redisplay treeview
} -body {
# only some columns are displayed (and in a different order than declared
# in -columns), a non-displayed column becomes stretchable --> nothing
# happens
set origTreeWidth [winfo width .tv]
set res [list [.tv column bar -width] [.tv column colA -width]]
.tv column bar -stretch 1
update idletasks ; # no change, widget redisplayed
lappend res [.tv column bar -width] [.tv column colA -width]
# this column becomes visible --> widget resizes
.tv configure -displaycolumns {bar colC colA colB}
update idletasks ; # no slack anymore because the widget resizes (shrinks)
lappend res [.tv column bar -width] [.tv column colA -width] \
[expr {[winfo width .tv] < $origTreeWidth}]
} -cleanup {
destroy .tv
} -result {60 50 60 50 60 50 1}
test treeview-bc602049ab "treeview with custom background does not change size when switching themes" -setup {
image create photo tvbg -data {
iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAYAAACNiR0NAAAACXBIWXMAAAnXAAAJ1wG
xbhe3AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAACJJREFUOI
1jPLF9+38GKgImaho2auCogaMGjho4auBQMhAAyR0DXUEyypsAAAAASUVORK5CYII=
}
ttk::style theme create foo-bc602049ab -parent clam -settings {
ttk::style element create Treeview.field image tvbg -width 0 -height 0
}
ttk::style theme use foo-bc602049ab
pack [ttk::treeview .tv]
update idletasks
} -body {
set g1 [winfo geometry .tv]
ttk::style theme use foo-bc602049ab
update idletasks
set g2 [winfo geometry .tv]
expr {$g1 eq $g2 ? 1 : "$g1 --> $g2"}
} -cleanup {
destroy .tv
image delete tvbg
} -result {1}
test treeview-6ee162c3d9 "style configure Treeview -rowheight 0" -setup {
tvSetupWithItems
} -body {
ttk::style configure Treeview -rowheight 0 ; # shall not crash
update
} -result {}
test treeview-column0-leak "Test for leak in tree column" -setup {
destroy .ttt
set heading [string range _Hej_ 1 3]
} -body {
for {set t 0} {$t < 3} {incr t} {
ttk::treeview .tapa -columns "hej hopp"
.tapa heading #0 -text $heading
destroy .tapa
}
tcl::unsupported::representation $heading
} -match glob -result {*refcount of 3,*}
test treeview-21.1 "style command" -body {
ttk::treeview .w
list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
destroy .w
} -result {{} Treeview Treeview}
test treeview-21.2 "style command" -body {
ttk::style configure customStyle.Treeview
ttk::treeview .w -style customStyle.Treeview
list [.w cget -style] [.w style] [winfo class .w]
} -cleanup {
destroy .w
} -result {customStyle.Treeview customStyle.Treeview Treeview}
test treeview-22.1 "tag bindings" -setup {
tvSetupWithItems
.tv tag configure t1 -background red
.tv tag configure t2 -background blue
.tv item nn -open 1
# Tags on item and cell to spot the difference
.tv tag add t1 "nn.n1"
.tv tag cell add t2 "nn.n1 a"
.tv tag cell add t2 "nn.n2 c"
update
proc cellEvent {item col} {
# Find midpoint of cell
lassign [.tv bbox $item $col] aX aY aW aH
set aX [expr {$aX + $aW / 2}]
set aY [expr {$aY + $aH / 2}]
event generate .tv <Button-1> -x $aX -y $aY
}
} -body {
.tv tag bind t1 <Button-1> {lappend ::tagtest t1}
.tv tag bind t2 <Button-1> {lappend ::tagtest t2}
# Cell with both binds
set ::tagtest a
cellEvent nn.n1 a
# Cell with just item tag
lappend ::tagtest b
cellEvent nn.n1 b
# Cell with just cell tag
lappend ::tagtest c
cellEvent nn.n2 c
# Same tag on both cell and item should fire once
.tv tag cell add t1 "nn.n1 b"
lappend ::tagtest b
cellEvent nn.n1 b
# Break in first bind
.tv tag bind t1 <Button-1> {lappend ::tagtest t1;break}
lappend ::tagtest a
cellEvent nn.n1 a
set ::tagtest
} -cleanup {
rename cellEvent {}
destroy .tv
} -result {a t1 t2 b t1 c t2 b t1 a t1}
test treeview-12.2 "tag bindings deletion on tag delete" -setup {
tvSetupWithItems
.tv tag bind nn.n1 <Button-1> {puts Triggered}
} -body {
.tv tag delete nn.n1
.tv tag bind nn.n1
} -cleanup {
destroy .tv
} -result {}
test treeview-23.1 "cell padding" -setup {
tvSetupWithItems
} -body {
.tv tag cell add mytag "nn b"
set redcross [image create photo -format gif -data {R0lGODlhBwAHAIABAP8AAP///
yH5BAEKAAEALAAAAAAHAAcAAAIMBIKmsWrIXnLxuDMLADs=}]
.tv tag configure mytag -image $redcross
.tv tag configure mytag -imageanchor nw
.tv tag configure mytag -padding {2 4 6 8}
.tv tag configure mytag -padding
} -cleanup {
destroy .tv
} -result {2 4 6 8}
tcltest::cleanupTests
|