File: display.test

package info (click to toggle)
tktreectrl 2.4.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 7,124 kB
  • sloc: ansic: 50,925; tcl: 9,975; sh: 234; makefile: 96
file content (646 lines) | stat: -rw-r--r-- 18,217 bytes parent folder | download | duplicates (2)
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
# Commands covered:  display code
#
# This file contains a collection of tests for the style widget command of
# the tktreectrl extension.  Sourcing this file into Tcl runs the tests and
# generates output for errors.  No output means no errors were found.
#
# Copyright (c) 2000 by Scriptics Corporation.
# Copyright (c) 2002 by Christian Krone.
#
# See the file "license.terms" for information on usage and redistribution
# of this file, and for a DISCLAIMER OF ALL WARRANTIES.

if {[lsearch [namespace children] ::tcltest] == -1} {
    package require tcltest 2
    namespace import ::tcltest::*
}

package require Tk
package require treectrl

test display-0.1 {some needed preparations} -body {

    # The size of the window is important.
    pack [treectrl .t -width 500 -height 400]

    .t element create e1 text -text "Hello,"
    .t element create e2 window -destroy yes
    .t element create e3 text -text " world!"

    .t style create S1
    .t style elements S1 {e1 e2 e3}
    .t style layout S1 e2 -iexpand x -squeeze x

    .t column create -text "Column 0" -tags C0 -itemstyle S1
    .t column create -text "Column 1" -tags C1 -itemstyle S1
    .t column create -text "Column 2" -tags C2 -itemstyle S1
    .t column create -text "Column 3" -tags C3 -itemstyle S1

    foreach I [.t item create -count 10 -parent root] {
	foreach C [.t column list] {
	    .t item element configure $I $C e2 -window [entry .t.w${I}C$C]
	}
    }

    update ; # make sure it is visible
} -result {}

test display-1.1 {<ItemVisibility>: hide some items} -body {
    .t notify bind .t <ItemVisibility> {
	puts -nonewline "%P visible=[list [lsort -integer %v]] hidden=[list [lsort -integer %h]]"
    }
    .t item configure {list {2 5 9}} -visible no
    update idletasks
} -output {<ItemVisibility> visible={} hidden={2 5 9}}

test display-1.2 {<ItemVisibility>: show some items} -body {
    .t item configure {list {9 2}} -visible yes
    update idletasks
} -output {<ItemVisibility> visible={2 9} hidden={}}

test display-1.3 {<ItemVisibility>: hide & show some items} -body {
    .t item configure {list {5}} -visible yes
    .t item configure {list {6 7}} -visible no
    update idletasks
} -output {<ItemVisibility> visible=5 hidden={6 7}}

test display-1.4 {<ItemVisibility>: delete an item when it becomes visible} -body {
    .t notify bind .t <ItemVisibility> {
	%T item delete {list %v}
    }
    .t notify bind .t <ItemDelete> {
	puts -nonewline "%P [list [lsort -integer %i]]"
    }
    .t item configure 6 -visible yes
    # Deleting an item that is being displayed should not segfault.
    update idletasks
} -output {<ItemDelete> 6}

test display-2.1 {<Configure>: resizing a column resizes a window element} -body {
    set w [.t item element cget 2 C1 e2 -window]
    bind $w <Configure> {
	puts -nonewline "<Configure> %W"
    }
    .t column configure C1 -width 100
    update idletasks
} -output {<Configure> .t.w2C1}

test display-2.2 {<Configure>: delete a column when a window in a previous column is resized during a display update} -body {
    set w [.t item element cget 2 C1 e2 -window]
    bind $w <Configure> {+
	.t column delete C2
    }
    .t column configure C1 -width 150
    # Deleting a column while displaying an item should not segfault.
    update idletasks
} -output {<Configure> .t.w2C1}

test display-2.3 {<Configure>: delete a column when a window in a previous column is resized during a display update} -body {
    set w [.t item element cget 2 C1 e2 -window]
    bind $w <Configure> {
	.t item delete 2
    }
    .t column configure C1 -width 100
    # Deleting an item while displaying it should not segfault.
    update idletasks
} -output {<ItemDelete> 2}

test display-3.1 {<Scroll>} -body {
    .t configure -width 200
    update idletasks
    .t notify bind .t <Scroll-x> {
	puts -nonewline "%P"
    }
    .t xview moveto 1.0
    update idletasks
} -output {<Scroll-x>}

test display-3.2 {<Scroll>: delete an item while scrolling} -body {
    .t notify bind .t <Scroll-x> {
	.t item delete 8
	.t notify unbind .t <Scroll-x>
    }
    .t xview moveto 0.0
    # Causing a display update while scrolling (during a display update) should
    # restart the display update and not operate on deleted items.
    update idletasks
} -output {<ItemDelete> 8}

test display-3.3 {delete the tree during a display update} -body {
    .t notify bind .t <ItemVisibility> {
	destroy .t
    }
    .t item configure 4 -visible no
    update idletasks
    winfo exists .t
} -result {0}

# Create a 40x40 item
# Check bounds via [item bbox], [marquee identify] and [item id "nearest x y"]
# Configure -canvaspadx and -canvaspady with positive values
# Check item bounds
# Create another 40x40 item to right of the first (horizontal layout)
# Check item bounds
# Configure -itemgapx with positive value
# Check item bounds

test display-4.1 {item layout} -setup {
    catch {destroy .t}
    pack [treectrl .t -width 500 -height 500]
    .t configure -showroot 0 -showheader 0 -highlightthickness 0 \
	-borderwidth 0 -orient horizontal
    .t column create -tags C1
    .t element create E1 rect -width 40 -height 40
    .t style create S1
    .t style elements S1 [list E1]
    .t item create -parent root -tags I1
    .t item style set I1 C1 S1
    update ; # make sure it is visible
} -body {
    .t item bbox I1
} -result {0 0 40 40}

test display-4.2 {item layout} -setup {
    .t configure -canvaspadx 10
} -body {
    .t item bbox I1
} -result {10 0 50 40}

test display-4.3 {item layout} -setup {
    .t configure -canvaspadx 0 -canvaspady 10
} -body {
    .t item bbox I1
} -result {0 10 40 50}

test display-4.4 {item layout} -setup {
    .t configure -canvaspadx 10 -canvaspady 10
} -body {
    .t item bbox I1
} -result {10 10 50 50}

test display-4.5 {item layout} -body {
    .t identify 0 0
} -result {}

test display-4.6 {item layout} -body {
    .t identify 9 9
} -result {}

test display-4.7 {item layout} -body {
    .t identify 50 50
} -result {}

test display-4.8 {item layout} -body {
    .t identify 50 10
} -result {}

test display-4.9 {item layout} -body {
    .t identify 10 50
} -result {}

test display-4.10 {item layout} -body {
    .t identify 10 10
} -result {item 1 column 0 elem E1}

test display-4.11 {item layout} -body {
    .t identify 49 10
} -result {item 1 column 0 elem E1}

test display-4.12 {item layout} -body {
    .t identify 10 49
} -result {item 1 column 0 elem E1}

test display-4.13 {item layout} -setup {
    .t item create -parent root -tags I2
    .t item style set I2 C1 S1
} -body {
    .t item bbox I2
} -result {50 10 90 50}

test display-4.14 {item layout} -body {
    .t identify 50 10
} -result {item 2 column 0 elem E1}

test display-4.15 {item layout} -body {
    .t identify 90 10
} -result {}

test display-4.16 {item layout} -body {
    .t item id "nearest 0 0"
} -result {1}

test display-4.17 {item layout} -body {
    .t item id "nearest 10 10"
} -result {1}

test display-4.18 {item layout} -body {
    .t item id "nearest 100 100"
} -result {2}

test display-4.19 {item layout} -body {
    .t marquee coords 0 0 100 10
    .t marquee identify
} -result {}

test display-4.20 {item layout} -body {
    .t marquee coords 0 50 100 60
    .t marquee identify
} -result {}

test display-4.21 {item layout} -body {
    .t marquee coords 90 0 100 100
    .t marquee identify
} -result {}

test display-4.22 {item layout} -body {
    .t marquee coords 10 10 11 11
    .t marquee identify
} -result {{1 {0 E1}}}

test display-4.23 {item layout} -body {
    .t marquee coords 50 10 51 11
    .t marquee identify
} -result {{2 {0 E1}}}

test display-4.24 {item layout} -body {
    .t marquee coords 49 10 61 11
    .t marquee identify
} -result {{1 {0 E1}} {2 {0 E1}}}

test display-4.25 {item layout} -setup {
    .t configure -itemgapx 10
} -body {
    .t item bbox I1
} -result {10 10 50 50}

test display-4.26 {item layout} -body {
    .t item bbox I2
} -result {60 10 100 50}

test display-4.27 {item layout} -body {
    .t identify 50 10
} -result {}

test display-4.28 {item layout} -body {
    .t identify 59 10
} -result {}

test display-4.29 {item layout} -body {
    .t identify 60 10
} -result {item 2 column 0 elem E1}

test display-4.30 {item layout} -body {
    .t marquee coords 50 0 60 100
    .t marquee identify
} -result {}

test display-4.31 {item layout} -body {
    .t marquee coords 100 0 110 100
    .t marquee identify
} -result {}

test display-4.32 {item layout} -body {
    .t marquee coords 10 10 60 20
    .t marquee identify
} -result {{1 {0 E1}}}

test display-4.33 {item layout} -body {
    .t marquee coords 10 10 61 20
    .t marquee identify
} -result {{1 {0 E1}} {2 {0 E1}}}

test display-4.34 {item layout} -body {
    .t item id "nearest 50 10"
} -result {1}

test display-4.35 {item layout: < half-way between} -body {
    .t item id "nearest 54 10"
} -result {1}

test display-4.36 {item layout: >= half-way between} -body {
    .t item id "nearest 55 10"
} -result {2}

test display-5.1 {item layout} -setup {
    catch {destroy .t}
    pack [treectrl .t -width 500 -height 500]
    .t configure -showroot 0 -showheader 0 -highlightthickness 0 \
	-borderwidth 0 -orient vertical -indent 20
    .t column create -tags C1
    .t configure -treecolumn C1
    .t element create E1 rect -width 100 -height 20
    .t style create S1
    .t style elements S1 [list E1]
    .t item create -button yes -parent root -tags I1
    .t item style set I1 C1 S1
    update ; # make sure it is visible
} -body {
    .t item bbox I1
} -result {0 0 120 20}

test display-5.2 {button hit-testing} -setup {
} -body {
    .t identify 0 0
} -result {item 1 button}

test display-5.3 {button hit-testing} -setup {
    .t configure -canvaspadx 20
} -body {
    .t identify 20 0
} -result {item 1 button}

test display-6.1 {no unlocked columns: no canvaspadx/y} -setup {
    destroy .t
    pack [treectrl .t]
    .t configure -showheader no -borderwidth 5 -highlightthickness 5
    .t column create -tags C0 -lock left -width 100
    .t item configure root -height 20
    if 0 {
        .t style create s
        .t style elements s [.t element create e rect -fill blue]
        .t style layout s e -iexpand xy
        .t item style set root C0 s
    }
    update
} -body {
    .t item bbox root C0
} -result {10 10 110 30}

test display-6.2 {no unlocked columns: -canvaspadx ignored, -canvaspady used} -setup {
    .t configure -canvaspadx 10 -canvaspady 10
} -body {
    .t item bbox root C0
} -result {10 20 110 40}

test display-6.3 {no unlocked columns: -canvaspadx ignored, -canvaspady used} -body {
    .t identify 10 10
} -result {}

test display-6.4 {no unlocked columns: -canvaspadx ignored, -canvaspady used} -body {
    .t identify 10 19
} -result {}

test display-6.5 {no unlocked columns: -canvaspadx ignored, -canvaspady used} -body {
    .t identify 10 20
} -result {item 0 column 0}

proc colWid {args} {
    foreach c $args {
        lappend result [.t column width $c]
    }
    return $result
}

test display-7.0 {column spanning: span=1} -setup {
    destroy .t
    pack [treectrl .t]
    .t configure -showheader no -borderwidth 0 -highlightthickness 0
    .t column create -tags C0
    .t element create e1 rect -width 100 -height 20
    .t style create s1 -orient horizontal
    .t style elements s1 e1
    .t item style set root C0 s1
} -body {
    colWid C0
} -result {100}

test display-7.1 {column spanning: span=2} -setup {
    .t column create -tags C1
    .t item span root C0 2
} -body {
    colWid C0 C1
} -result {50 50}

test display-7.2 {column spanning: span=3} -setup {
    .t column create -tags C2
    .t item span root C0 3
} -body {
    colWid C0 C1 C2
} -result {34 33 33}

test display-7.3 {column spanning: span=4} -setup {
    .t column create -tags C3
    .t item span root C0 4
} -body {
    colWid C0 C1 C2 C3
} -result {25 25 25 25}

test display-7.4 {column spanning: span=5} -setup {
    .t column create -tags C4
    .t item span root C0 5
} -body {
    colWid C0 C1 C2 C3 C4
} -result {20 20 20 20 20}

test display-7.5 {column spanning: minwidth > 0} -setup {
    .t column configure all -minwidth 10
} -body {
    colWid C0 C1 C2 C3 C4
} -result {20 20 20 20 20}

test display-7.6 {column spanning: minwidth > 0} -setup {
    .t column configure C0 -minwidth 30
} -body {
    colWid C0 C1 C2 C3 C4
} -result {30 18 18 17 17}

test display-7.7 {column spanning: minwidth > 0} -setup {
    .t column configure C2 -minwidth 30
} -body {
    colWid C0 C1 C2 C3 C4
} -result {30 14 30 13 13}

test display-7.8 {column spanning: minwidth > 0} -setup {
    .t column configure all -minwidth 30
} -body {
    colWid C0 C1 C2 C3 C4
} -result {30 30 30 30 30}

test display-7.20 {column spanning: maxwidth > 0} -setup {
    .t column configure all -minwidth ""
    .t column configure C1 -maxwidth 15
} -body {
    colWid C0 C1 C2 C3 C4
} -result {22 15 21 21 21}

test display-7.21 {column spanning: maxwidth > 0} -setup {
    .t column configure C0 -maxwidth 15
} -body {
    colWid C0 C1 C2 C3 C4
} -result {15 15 24 23 23}

test display-7.30 {column spanning: width > 0} -setup {
    .t column configure all -maxwidth ""
    .t column configure C3 -width 50
} -body {
    colWid C0 C1 C2 C3 C4
} -result {13 13 12 50 12}

test display-7.31 {column spanning: width > 0} -setup {
    .t column configure C0 -width 20
} -body {
    colWid C0 C1 C2 C3 C4
} -result {20 10 10 50 10}

test display-7.40 {column spanning: hidden columns} -setup {
    .t column configure all -width ""
    .t column configure C2 -visible no
} -body {
    colWid C0 C1 C2 C3 C4
} -result {25 25 0 25 25}

test display-7.41 {column spanning: hidden columns} -setup {
    .t column configure C4 -visible no
} -body {
    colWid C0 C1 C2 C3 C4
} -result {34 33 0 33 0}

test display-7.42 {column spanning: hidden columns} -setup {
    .t column configure all -visible no
} -body {
    colWid C0 C1 C2 C3 C4
} -result {0 0 0 0 0}

test display-7.50 {column spanning: trim the fat} -setup {
    .t column configure all -visible yes
    .t item span root all 1
    .t item style set root C1 s1
    .t item element configure root C0 e1 -width 75
    .t item element configure root C1 e1 -width 25

    .t item create -tags item1
    .t item style set item1 C0 s1
    .t item element configure item1 C0 e1 -width 100
    .t item span item1 C0 2
} -body {
    colWid C0 C1 C2 C3 C4
} -result {75 25 0 0 0}

proc itemWid {args} {
    foreach i $args {
        scan [.t item bbox $i] "%d %d %d %d" x1 y1 x2 y2
        lappend result [expr {$x2 - $x1}]
    }
    return $result
}

test display-8.1 {item width} -setup {
    destroy .t
    pack [treectrl .t]
    .t column create -tags C0
    .t element create e rect -width 55 -height 20
    .t style create s
    .t style elements s e
    .t item style set root C0 s
} -body {
    itemWid root
} -result {55}

test display-8.2 {-itemwidth ignored without wrapping} -body {
    .t configure -itemwidth 100
    itemWid root
} -result {55}

test display-8.3 {-itemwidth plus -wrap} -body {
    .t configure -itemwidth 100 -wrap {1 items}
    itemWid root
} -result {100}

test display-8.4 {-itemwidth overrides -itemwidthmultiple} -body {
    .t configure -itemwidth 100 -itemwidthmultiple 55
    itemWid root
} -result {100}

test display-8.5 {-itemwidthmultiple} -body {
    .t configure -itemwidth "" -itemwidthmultiple 55
    itemWid root
} -result {55}

test display-8.6 {-itemwidthmultiple} -body {
    .t configure -itemwidth "" -itemwidthmultiple 60
    itemWid root
} -result {60}

test display-8.7 {-itemwidthmultiple} -body {
    .t configure -itemwidth "" -itemwidthmultiple 50
    itemWid root
} -result {100}

test display-8.20 {item width} -setup {
    .t item create -tags item1 -parent root
    .t item style set item1 C0 s
    .t item element configure item1 C0 e -width 40
    .t configure -itemwidth "" -itemwidthmultiple ""
} -body {
    itemWid root item1
} -result {55 40}

test display-8.21 {-itemwidthmultiple} -body {
    .t configure -itemwidth "" -itemwidthmultiple 55
    itemWid root item1
} -result {55 55}

test display-8.22 {-itemwidthmultiple} -body {
    .t configure -itemwidth "" -itemwidthmultiple 40
    itemWid root item1
} -result {80 40}

test display-8.23 {-itemwidth} -body {
    .t configure -itemwidth 100 -itemwidthmultiple 40
    itemWid root item1
} -result {100 100}

test display-8.24 {-itemwidthequal} -body {
    .t configure -itemwidth "" -itemwidthmultiple "" -itemwidthequal yes
    itemWid root item1
} -result {55 55}

test display-8.25 {-itemwidthequal with -itemwidthmultiple} -body {
    .t configure -itemwidth "" -itemwidthmultiple 40 -itemwidthequal yes
    itemWid root item1
} -result {80 80}

test display-8.30 {column width} -body {
    colWid C0
} -result {55}

test display-8.31 {column -width overrides -itemwidth} -body {
    .t column configure C0 -width 123
    itemWid root item1
} -result {123 123}

test display-8.32 {header width doesn't affect item width with -wrap} -setup {
    image create photo headerImage -width 175 -height 20
} -body {
    .t column configure C0 -width "" -image headerImage -imagepadx 0
    .t configure -itemwidth "" -itemwidthmultiple "" -itemwidthequal no
    concat [colWid C0] [itemWid root item1]
} -result {175 55 40}

test display-8.33 {header width doesn't affect item width with -wrap} -body {
    .t configure -itemwidth "" -itemwidthmultiple "" -itemwidthequal yes
    concat [colWid C0] [itemWid root item1]
} -result {175 55 55}

test display-8.34 {header width does affect item width without -wrap} -body {
    .t configure -itemwidth "" -itemwidthmultiple "" -itemwidthequal yes -wrap {}
    concat [colWid C0] [itemWid root item1]
} -result {175 175 175}

test display-8.35 {horizontal layout, item width unaffected by -wrap} -body {
    .t configure -orient horizontal
    concat [colWid C0] [itemWid root item1]
} -result {175 55 55}

test display-8.36 {horizontal layout, item width unaffected by -wrap} -body {
    .t configure -itemwidthequal no
    concat [colWid C0] [itemWid root item1]
} -result {175 55 40}

test style-99.1 {some needed cleanup} -body {
    destroy .t
} -result {}

# cleanup
::tcltest::cleanupTests
return