File: tixTList.c

package info (click to toggle)
tix 8.4.3-10
  • links: PTS
  • area: main
  • in suites: bookworm, buster, sid
  • size: 9,080 kB
  • ctags: 7,129
  • sloc: ansic: 28,082; tcl: 22,774; python: 7,577; makefile: 331; cs: 253; sh: 210; perl: 128
file content (2493 lines) | stat: -rw-r--r-- 66,831 bytes parent folder | download | duplicates (5)
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
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
/* 
 * tixTList.c --
 *
 *	This module implements "TList" widgets.
 *
 * Copyright (c) 1993-1999 Ioi Kim Lam.
 * Copyright (c) 2000      Tix Project Group.
 *
 * See the file "license.terms" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * $Id: tixTList.c,v 1.6 2008/02/28 04:05:29 hobbs Exp $
 */

#include <tixPort.h>
#include <tixInt.h>
#include <tixDef.h>
#include <tixTList.h>

#define TIX_UP		1
#define TIX_DOWN	2
#define TIX_LEFT	3
#define TIX_RIGHT 	4

/*
 * Information used for argv parsing.
 */
static Tk_ConfigSpec configSpecs[] = {
    {TK_CONFIG_COLOR, "-background", "background", "Background",
       DEF_TLIST_BG_COLOR, Tk_Offset(WidgetRecord, normalBg),
       TK_CONFIG_COLOR_ONLY},

    {TK_CONFIG_COLOR, "-background", "background", "Background",
       DEF_TLIST_BG_MONO, Tk_Offset(WidgetRecord, normalBg),
       TK_CONFIG_MONO_ONLY},

    {TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *) NULL,
       (char *) NULL, 0, 0},

    {TK_CONFIG_SYNONYM, "-bg", "background", (char *) NULL,
       (char *) NULL, 0, 0},

    {TK_CONFIG_BORDER, "-highlightbackground", "highlightBackground",
       "HighlightBackground",
       DEF_TLIST_BG_COLOR, Tk_Offset(WidgetRecord, border),
       TK_CONFIG_COLOR_ONLY},

    {TK_CONFIG_BORDER, "-highlightbackground", "highlightBackground",
       "HighlightBackground",
       DEF_TLIST_BG_MONO, Tk_Offset(WidgetRecord, border),
       TK_CONFIG_MONO_ONLY},

    {TK_CONFIG_PIXELS, "-borderwidth", "borderWidth", "BorderWidth",
       DEF_TLIST_BORDER_WIDTH, Tk_Offset(WidgetRecord, borderWidth), 0},

    {TK_CONFIG_STRING, "-browsecmd", "browseCmd", "BrowseCmd",
	DEF_TLIST_BROWSE_COMMAND, Tk_Offset(WidgetRecord, browseCmd),
	TK_CONFIG_NULL_OK},

    {TK_CONFIG_STRING, "-command", "command", "Command",
       DEF_TLIST_COMMAND, Tk_Offset(WidgetRecord, command),
       TK_CONFIG_NULL_OK},

    {TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",
       DEF_TLIST_CURSOR, Tk_Offset(WidgetRecord, cursor),
       TK_CONFIG_NULL_OK},

    {TK_CONFIG_SYNONYM, "-fg", "foreground", (char *) NULL,
       (char *) NULL, 0, 0},

    {TK_CONFIG_FONT, "-font", "font", "Font",
       DEF_TLIST_FONT, Tk_Offset(WidgetRecord, font), 0},

    {TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground",
       DEF_TLIST_FG_COLOR, Tk_Offset(WidgetRecord, normalFg),
       TK_CONFIG_COLOR_ONLY},

    {TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground",
       DEF_TLIST_FG_MONO, Tk_Offset(WidgetRecord, normalFg),
       TK_CONFIG_MONO_ONLY},

    {TK_CONFIG_INT, "-height", "height", "Height",
       DEF_TLIST_HEIGHT, Tk_Offset(WidgetRecord, height), 0},

    {TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
       DEF_TLIST_HIGHLIGHT_COLOR, Tk_Offset(WidgetRecord, highlightColorPtr),
       TK_CONFIG_COLOR_ONLY},

    {TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
       DEF_TLIST_HIGHLIGHT_MONO, Tk_Offset(WidgetRecord, highlightColorPtr),
       TK_CONFIG_MONO_ONLY},

    {TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness",
       "HighlightThickness",
       DEF_TLIST_HIGHLIGHT_WIDTH, Tk_Offset(WidgetRecord, highlightWidth), 0},

    {TK_CONFIG_CUSTOM, "-itemtype", "itemType", "ItemType",
       DEF_TLIST_ITEM_TYPE, Tk_Offset(WidgetRecord, diTypePtr),
       0, &tixConfigItemType},

    {TK_CONFIG_UID, "-orient", "orient", "Orient",
	DEF_TLIST_ORIENT, Tk_Offset(WidgetRecord, orientUid), 0},

    {TK_CONFIG_PIXELS, "-padx", "padX", "Pad",
	DEF_TLIST_PADX, Tk_Offset(WidgetRecord, padX), 0},

    {TK_CONFIG_PIXELS, "-pady", "padY", "Pad",
	DEF_TLIST_PADY, Tk_Offset(WidgetRecord, padY), 0},

    {TK_CONFIG_RELIEF, "-relief", "relief", "Relief",
       DEF_TLIST_RELIEF, Tk_Offset(WidgetRecord, relief), 0},

    {TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground",
	DEF_TLIST_SELECT_BG_COLOR, Tk_Offset(WidgetRecord, selectBorder),
	TK_CONFIG_COLOR_ONLY},

    {TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground",
	DEF_TLIST_SELECT_BG_MONO, Tk_Offset(WidgetRecord, selectBorder),
	TK_CONFIG_MONO_ONLY},

    {TK_CONFIG_PIXELS, "-selectborderwidth", "selectBorderWidth","BorderWidth",
       DEF_TLIST_SELECT_BORDERWIDTH,Tk_Offset(WidgetRecord, selBorderWidth),0},

    {TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Background",
       DEF_TLIST_SELECT_FG_COLOR, Tk_Offset(WidgetRecord, selectFg),
       TK_CONFIG_COLOR_ONLY},

    {TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Background",
       DEF_TLIST_SELECT_FG_MONO, Tk_Offset(WidgetRecord, selectFg),
       TK_CONFIG_MONO_ONLY},

    {TK_CONFIG_UID, "-selectmode", "selectMode", "SelectMode",
	DEF_TLIST_SELECT_MODE, Tk_Offset(WidgetRecord, selectMode), 0},

    {TK_CONFIG_UID, "-state", (char*)NULL, (char*)NULL,
       DEF_TLIST_STATE, Tk_Offset(WidgetRecord, state), 0},

    {TK_CONFIG_STRING, "-sizecmd", "sizeCmd", "SizeCmd",
       DEF_TLIST_SIZE_COMMAND, Tk_Offset(WidgetRecord, sizeCmd),
       TK_CONFIG_NULL_OK},
 
    {TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",
	DEF_TLIST_TAKE_FOCUS, Tk_Offset(WidgetRecord, takeFocus),
	TK_CONFIG_NULL_OK},

    {TK_CONFIG_INT, "-width", "width", "Width",
	DEF_TLIST_WIDTH, Tk_Offset(WidgetRecord, width), 0},

    {TK_CONFIG_STRING, "-xscrollcommand", "xScrollCommand", "ScrollCommand",
       DEF_TLIST_X_SCROLL_COMMAND,
       Tk_Offset(WidgetRecord, scrollInfo[0].command),
       TK_CONFIG_NULL_OK},

    {TK_CONFIG_STRING, "-yscrollcommand", "yScrollCommand", "ScrollCommand",
       DEF_TLIST_Y_SCROLL_COMMAND,
       Tk_Offset(WidgetRecord, scrollInfo[1].command),
       TK_CONFIG_NULL_OK},

    {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
       (char *) NULL, 0, 0}
};	

#define DEF_TLISTENTRY_STATE	 "normal"

static Tk_ConfigSpec entryConfigSpecs[] = {

    {TK_CONFIG_UID, "-state", (char*)NULL, (char*)NULL,
       DEF_TLISTENTRY_STATE, Tk_Offset(ListEntry, state), 0},

    {TK_CONFIG_END, (char *) NULL, (char *) NULL, (char *) NULL,
       (char *) NULL, 0, 0}
};

static Tix_ListInfo entListInfo = {
    Tk_Offset(ListEntry, next),
    TIX_UNDEFINED,
};


/*
 * Forward declarations for procedures defined later in this file:
 */

	/* These are standard procedures for TK widgets
	 * implemeted in C
	 */

static void		WidgetCmdDeletedProc _ANSI_ARGS_((
			    ClientData clientData));
static int		WidgetConfigure _ANSI_ARGS_((Tcl_Interp *interp,
			    WidgetPtr wPtr, int argc, CONST84 char **argv,
			    int flags));
static void		WidgetDestroy _ANSI_ARGS_((ClientData clientData));
static void		WidgetEventProc _ANSI_ARGS_((ClientData clientData,
			    XEvent *eventPtr));
static int		WidgetCommand _ANSI_ARGS_((ClientData clientData,
			    Tcl_Interp *, int argc, CONST84 char **argv));
static void		WidgetDisplay _ANSI_ARGS_((ClientData clientData));
static void		WidgetComputeGeometry _ANSI_ARGS_((
			    ClientData clientData));

	/* Extra procedures for this widget
	 */
static void		CancelRedrawWhenIdle _ANSI_ARGS_((WidgetPtr wPtr));
static void		CancelResizeWhenIdle _ANSI_ARGS_((WidgetPtr wPtr));
static int		ConfigElement _ANSI_ARGS_((WidgetPtr wPtr,
			    ListEntry *chPtr, int argc, CONST84 char ** argv,
			    int flags, int forced));
static void 		RedrawRows _ANSI_ARGS_((
			    WidgetPtr wPtr, Drawable pixmap));
static void		RedrawWhenIdle _ANSI_ARGS_((WidgetPtr wPtr));
static void 		ResizeRows _ANSI_ARGS_((
			    WidgetPtr wPtr, int winW, int winH));
static void		ResizeWhenIdle _ANSI_ARGS_((WidgetPtr wPtr));
static void		ResizeNow _ANSI_ARGS_((WidgetPtr wPtr));
static void		UpdateScrollBars _ANSI_ARGS_((WidgetPtr wPtr,
			    int sizeChanged));
static int		Tix_TLGetFromTo _ANSI_ARGS_((
			    Tcl_Interp *interp, WidgetPtr wPtr,
			    int argc, CONST84 char **argv,
			    ListEntry ** fromPtr_ret, ListEntry ** toPtr_ret));
static void		Tix_TLDItemSizeChanged _ANSI_ARGS_((
			    Tix_DItem *iPtr));
static void		MakeGeomRequest _ANSI_ARGS_((
			    WidgetPtr wPtr));
static int		Tix_TLGetNearest _ANSI_ARGS_((
   			    WidgetPtr wPtr, int posn[2]));
static int		Tix_TLGetAt _ANSI_ARGS_((WidgetPtr wPtr,
			    Tcl_Interp *interp, CONST84 char * spec, int *at));
static int		Tix_TLGetNeighbor _ANSI_ARGS_((
			    WidgetPtr wPtr, Tcl_Interp *interp,
			    int type, int argc, CONST84 char **argv));
static int		Tix_TranslateIndex _ANSI_ARGS_((
			    WidgetPtr wPtr, Tcl_Interp *interp, CONST84 char * string,
			    int * index, int isInsert));
static int		Tix_TLDeleteRange _ANSI_ARGS_((
			    WidgetPtr wPtr, ListEntry * fromPtr,
			    ListEntry *toPtr));
static ListEntry *	AllocEntry _ANSI_ARGS_((WidgetPtr wPtr));
static int		AddElement _ANSI_ARGS_((WidgetPtr wPtr,
			    ListEntry * chPtr, int at));
static void		FreeEntry _ANSI_ARGS_((WidgetPtr wPtr,
			    ListEntry * chPtr));
static int 		Tix_TLSpecialEntryInfo _ANSI_ARGS_((
			    WidgetPtr wPtr, Tcl_Interp *interp,
			    ListEntry * chPtr));
static void		Realloc _ANSI_ARGS_((WidgetPtr wPtr,int new_size));

static TIX_DECLARE_SUBCMD(Tix_TLInsert);
static TIX_DECLARE_SUBCMD(Tix_TLCGet);
static TIX_DECLARE_SUBCMD(Tix_TLConfig);
static TIX_DECLARE_SUBCMD(Tix_TLDelete);
static TIX_DECLARE_SUBCMD(Tix_TLEntryCget);
static TIX_DECLARE_SUBCMD(Tix_TLEntryConfig);
static TIX_DECLARE_SUBCMD(Tix_TLGeometryInfo);
static TIX_DECLARE_SUBCMD(Tix_TLIndex);
static TIX_DECLARE_SUBCMD(Tix_TLInfo);
static TIX_DECLARE_SUBCMD(Tix_TLNearest);
static TIX_DECLARE_SUBCMD(Tix_TLSee);
static TIX_DECLARE_SUBCMD(Tix_TLSelection);
static TIX_DECLARE_SUBCMD(Tix_TLSetSite);
static TIX_DECLARE_SUBCMD(Tix_TLView);

/*
 *--------------------------------------------------------------
 *
 * Tix_TListCmd --
 *
 *	This procedure is invoked to process the "tixTList" Tcl
 *	command.  It creates a new "TixTList" widget.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	A new widget is created and configured.
 *
 *--------------------------------------------------------------
 */
int
Tix_TListCmd(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    Tk_Window mainwin = (Tk_Window) clientData;
    WidgetPtr wPtr;
    Tk_Window tkwin;

    if (argc < 2) {
	Tcl_AppendResult(interp, "wrong # args:  should be \"",
		argv[0], " pathName ?options?\"", (char *) NULL);
	return TCL_ERROR;
    }

    tkwin = Tk_CreateWindowFromPath(interp, mainwin, argv[1], (char *) NULL);
    if (tkwin == NULL) {
	return TCL_ERROR;
    }

    Tk_SetClass(tkwin, "TixTList");

    /*
     * Allocate and initialize the widget record.
     */
    wPtr = (WidgetPtr) ckalloc(sizeof(WidgetRecord));
    memset(wPtr, 0, sizeof(WidgetRecord));

    wPtr->dispData.tkwin 	= tkwin;
    wPtr->dispData.display 	= Tk_Display(tkwin);
    wPtr->dispData.interp 	= interp;
    wPtr->dispData.sizeChangedProc = Tix_TLDItemSizeChanged;
    wPtr->backgroundGC		= None;
    wPtr->selectGC		= None;
    wPtr->anchorGC		= None;
    wPtr->anchorGC2		= None;
    wPtr->highlightGC		= None;
    wPtr->relief 		= TK_RELIEF_FLAT;
    wPtr->cursor 		= None;
    wPtr->state			= tixNormalUid;
    wPtr->rows			= (ListRow*)ckalloc(sizeof(ListRow) *1);
    wPtr->numRow		= 1;
    wPtr->numRowAllocd		= 1;

    Tix_LinkListInit(&wPtr->entList);
    Tix_InitScrollInfo((Tix_ScrollInfo*)&wPtr->scrollInfo[0], TIX_SCROLL_INT);
    Tix_InitScrollInfo((Tix_ScrollInfo*)&wPtr->scrollInfo[1], TIX_SCROLL_INT);

    Tk_CreateEventHandler(wPtr->dispData.tkwin,
	ExposureMask|StructureNotifyMask|FocusChangeMask,
	WidgetEventProc, (ClientData) wPtr);
    wPtr->widgetCmd = Tcl_CreateCommand(interp,
	Tk_PathName(wPtr->dispData.tkwin), WidgetCommand, (ClientData) wPtr,
	WidgetCmdDeletedProc);

    if (WidgetConfigure(interp, wPtr, argc-2, argv+2, 0) != TCL_OK) {
	Tk_DestroyWindow(wPtr->dispData.tkwin);
	return TCL_ERROR;
    }

    Tcl_SetResult(interp, Tk_PathName(wPtr->dispData.tkwin), TCL_STATIC);
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------
 *
 * WidgetConfigure --
 *
 *	This procedure is called to process an argv/argc list in
 *	conjunction with the Tk option database to configure (or
 *	reconfigure) a List widget.
 *
 * Results:
 *	The return value is a standard Tcl result.  If TCL_ERROR is
 *	returned, then interp's result contains an error message.
 *
 * Side effects:
 *	Configuration information, such as colors, border width,
 *	etc. get set for wPtr;  old resources get freed,
 *	if there were any.
 *
 *----------------------------------------------------------------------
 */
static int
WidgetConfigure(interp, wPtr, argc, argv, flags)
    Tcl_Interp *interp;			/* Used for error reporting. */
    WidgetPtr wPtr;			/* Information about widget. */
    int argc;				/* Number of valid entries in argv. */
    CONST84 char **argv;		/* Arguments. */
    int flags;				/* Flags to pass to
					 * Tk_ConfigureWidget. */
{
    XGCValues gcValues;
    GC newGC;
    TixFont oldfont;
    size_t length;
    Tix_StyleTemplate stTmpl;

    oldfont = wPtr->font;

    if (Tk_ConfigureWidget(interp, wPtr->dispData.tkwin, configSpecs,
	    argc, argv, (char *) wPtr, flags) != TCL_OK) {
	return TCL_ERROR;
    }

    length = strlen(wPtr->orientUid);
    if (strncmp(wPtr->orientUid, "vertical", length) == 0) {
	wPtr->isVertical = 1;
    } else if (strncmp(wPtr->orientUid, "horizontal", length) == 0) {
	wPtr->isVertical = 0;
    } else {
	Tcl_AppendResult(interp, "bad orientation \"", wPtr->orientUid,
	    "\": must be vertical or horizontal", (char *) NULL);
	wPtr->orientUid = Tk_GetUid("vertical");
	wPtr->isVertical = 1;
	return TCL_ERROR;
    }

    if ((wPtr->state != tixNormalUid) && (wPtr->state != tixDisabledUid)) {
	Tcl_AppendResult(interp, "bad state value \"", wPtr->state,
	    "\":  must be normal or disabled", (char *) NULL);
	wPtr->state = tixNormalUid;
	return TCL_ERROR;
    }


    if (oldfont != wPtr->font) {
	/* Font has been changed (initialized) */
	TixComputeTextGeometry(wPtr->font, "0", 1,
	    0, &wPtr->scrollInfo[0].unit, &wPtr->scrollInfo[1].unit);
    }

    /*
     * A few options need special processing, such as setting the
     * background from a 3-D border, or filling in complicated
     * defaults that couldn't be specified to Tk_ConfigureWidget.
     */

    Tk_SetBackgroundFromBorder(wPtr->dispData.tkwin, wPtr->border);

    /*
     * Note: GraphicsExpose events are disabled in normalGC because it's
     * used to copy stuff from an off-screen pixmap onto the screen (we know
     * that there's no problem with obscured areas).
     */

    /* The background GC */
    gcValues.foreground 	= wPtr->normalBg->pixel;
    gcValues.graphics_exposures = False;

    newGC = Tk_GetGC(wPtr->dispData.tkwin,
	GCForeground|GCGraphicsExposures, &gcValues);
    if (wPtr->backgroundGC != None) {
	Tk_FreeGC(wPtr->dispData.display, wPtr->backgroundGC);
    }
    wPtr->backgroundGC = newGC;

    /* The selected text GC */
    gcValues.font 		= TixFontId(wPtr->font);
    gcValues.foreground 	= wPtr->selectFg->pixel;
    gcValues.background 	= Tk_3DBorderColor(wPtr->selectBorder)->pixel;
    gcValues.graphics_exposures = False;

    newGC = Tk_GetGC(wPtr->dispData.tkwin,
	GCForeground|GCBackground|GCFont|GCGraphicsExposures, &gcValues);
    if (wPtr->selectGC != None) {
	Tk_FreeGC(wPtr->dispData.display, wPtr->selectGC);
    }
    wPtr->selectGC = newGC;

    /* The dotted anchor lines (for selected item) */
    newGC = Tix_GetAnchorGC(wPtr->dispData.tkwin,
            Tk_3DBorderColor(wPtr->selectBorder));
    if (wPtr->anchorGC != None) {
	Tk_FreeGC(wPtr->dispData.display, wPtr->anchorGC);
    }
    wPtr->anchorGC = newGC;

    /* The dotted anchor lines (for unselected item)  */
    newGC = Tix_GetAnchorGC(wPtr->dispData.tkwin, wPtr->normalBg);
    if (wPtr->anchorGC2 != None) {
	Tk_FreeGC(wPtr->dispData.display, wPtr->anchorGC2);
    }
    wPtr->anchorGC2 = newGC;

    /* The highlight border */
    gcValues.background 	= wPtr->selectFg->pixel;
    gcValues.foreground 	= wPtr->highlightColorPtr->pixel;
    gcValues.graphics_exposures = False;

    newGC = Tk_GetGC(wPtr->dispData.tkwin,
	GCForeground|GCBackground|GCGraphicsExposures, &gcValues);
    if (wPtr->highlightGC != None) {
	Tk_FreeGC(wPtr->dispData.display, wPtr->highlightGC);
    }
    wPtr->highlightGC = newGC;

    /* We must set the options of the default styles so that
     * -- the default styles will change according to what is in
     *    stTmpl
     */
    stTmpl.font 			= wPtr->font;
    stTmpl.pad[0]  			= wPtr->padX;
    stTmpl.pad[1]  			= wPtr->padY;
    stTmpl.colors[TIX_DITEM_NORMAL].fg  = wPtr->normalFg;
    stTmpl.colors[TIX_DITEM_NORMAL].bg  = wPtr->normalBg;
    stTmpl.colors[TIX_DITEM_SELECTED].fg= wPtr->selectFg;
    stTmpl.colors[TIX_DITEM_SELECTED].bg= Tk_3DBorderColor(wPtr->selectBorder);
    stTmpl.flags = TIX_DITEM_FONT|TIX_DITEM_NORMAL_BG|
	TIX_DITEM_SELECTED_BG|TIX_DITEM_NORMAL_FG|TIX_DITEM_SELECTED_FG |
	TIX_DITEM_PADX|TIX_DITEM_PADY;

    Tix_SetDefaultStyleTemplate(wPtr->dispData.tkwin, &stTmpl);

    /*
     * Probably the -font or -width or -height options have changed. Let's
     * make geometry request
     */
    MakeGeomRequest(wPtr);

    ResizeWhenIdle(wPtr);

    return TCL_OK;
}

/*
 *--------------------------------------------------------------
 *
 * WidgetCommand --
 *
 *	This procedure is invoked to process the Tcl command
 *	that corresponds to a widget managed by this module.
 *	See the user documentation for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	See the user documentation.
 *
 *--------------------------------------------------------------
 */

static int
WidgetCommand(clientData, interp, argc, argv)
    ClientData clientData;		/* Information about the widget. */
    Tcl_Interp *interp;			/* Current interpreter. */
    int argc;				/* Number of arguments. */
    CONST84 char **argv;		/* Argument strings. */
{
    int code;

    static Tix_SubCmdInfo subCmdInfo[] = {
	{TIX_DEFAULT_LEN, "active", 1, 2, Tix_TLSetSite,
	   "option ?index?"},
	{TIX_DEFAULT_LEN, "anchor", 1, 2, Tix_TLSetSite,
	   "option ?index?"},
	{TIX_DEFAULT_LEN, "cget", 1, 1, Tix_TLCGet,
	   "option"},
	{TIX_DEFAULT_LEN, "configure", 0, TIX_VAR_ARGS, Tix_TLConfig,
	   "?option? ?value? ?option value ... ?"},
	{TIX_DEFAULT_LEN, "delete", 1, 2, Tix_TLDelete,
	   "from ?to?"},
	{TIX_DEFAULT_LEN, "dragsite", 1, 2, Tix_TLSetSite,
	   "option ?entryPath?"},
	{TIX_DEFAULT_LEN, "dropsite", 1, 2, Tix_TLSetSite,
	   "option ?entryPath?"},
	{TIX_DEFAULT_LEN, "entrycget", 2, 2, Tix_TLEntryCget,
	   "entryPath option"},
	{TIX_DEFAULT_LEN, "entryconfigure", 1, TIX_VAR_ARGS, Tix_TLEntryConfig,
	   "index ?option? ?value? ?option value ... ?"},
	{TIX_DEFAULT_LEN, "geometryinfo", 0, 2, Tix_TLGeometryInfo,
	   "?width height?"},
	{TIX_DEFAULT_LEN, "index", 1, 1, Tix_TLIndex,
	   "index"},
	{TIX_DEFAULT_LEN, "info", 1, TIX_VAR_ARGS, Tix_TLInfo,
	   "option ?args ...?"},
	{TIX_DEFAULT_LEN, "insert", 1, TIX_VAR_ARGS, Tix_TLInsert,
	   "where ?option value ..."},
	{TIX_DEFAULT_LEN, "nearest", 2, 2, Tix_TLNearest,
	   "x y"},
	{TIX_DEFAULT_LEN, "see", 1, 1, Tix_TLSee,
	   "entryPath"},
	{TIX_DEFAULT_LEN, "selection", 1, 3, Tix_TLSelection,
	   "option arg ?arg ...?"},
	{TIX_DEFAULT_LEN, "xview", 0, 3, Tix_TLView,
	   "args"},
	{TIX_DEFAULT_LEN, "yview", 0, 3, Tix_TLView,
	   "args"},
    };

    static Tix_CmdInfo cmdInfo = {
	Tix_ArraySize(subCmdInfo), 1, TIX_VAR_ARGS, "?option? arg ?arg ...?",
    };

    Tk_Preserve(clientData);
    code = Tix_HandleSubCmds(&cmdInfo, subCmdInfo, clientData,
	interp, argc, argv);
    Tk_Release(clientData);

    return code;
}

/*
 *--------------------------------------------------------------
 *
 * WidgetEventProc --
 *
 *	This procedure is invoked by the Tk dispatcher for various
 *	events on Lists.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	When the window gets deleted, internal structures get
 *	cleaned up.  When it gets exposed, it is redisplayed.
 *
 *--------------------------------------------------------------
 */
static void
WidgetEventProc(clientData, eventPtr)
    ClientData clientData;	/* Information about window. */
    XEvent *eventPtr;		/* Information about event. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;

    switch (eventPtr->type) {
      case DestroyNotify:
	if (wPtr->dispData.tkwin != NULL) {
	    wPtr->dispData.tkwin = NULL;
	    Tcl_DeleteCommand(wPtr->dispData.interp, 
	        Tcl_GetCommandName(wPtr->dispData.interp, wPtr->widgetCmd));
	}
	CancelResizeWhenIdle(wPtr);
	CancelRedrawWhenIdle(wPtr);
	Tk_EventuallyFree((ClientData) wPtr, (Tix_FreeProc*)WidgetDestroy);
	break;

      case ConfigureNotify:
	ResizeWhenIdle(wPtr);
	break;

      case Expose:
	RedrawWhenIdle(wPtr);
	break;

      case FocusIn:
	wPtr->hasFocus = 1;
	RedrawWhenIdle(wPtr);
	break;

      case FocusOut:
	wPtr->hasFocus = 0;
	RedrawWhenIdle(wPtr);
	break;
    }
}

/*
 *----------------------------------------------------------------------
 *
 * WidgetDestroy --
 *
 *	This procedure is invoked by Tk_EventuallyFree or Tk_Release
 *	to clean up the internal structure of a List at a safe time
 *	(when no-one is using it anymore).
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	Everything associated with the List is freed up.
 *
 *----------------------------------------------------------------------
 */

static void
WidgetDestroy(clientData)
    ClientData clientData;	/* Info about my widget. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;


    if (wPtr->backgroundGC != None) {
	Tk_FreeGC(wPtr->dispData.display, wPtr->backgroundGC);
    }
    if (wPtr->selectGC != None) {
	Tk_FreeGC(wPtr->dispData.display, wPtr->selectGC);
    }
    if (wPtr->anchorGC != None) {
	Tk_FreeGC(wPtr->dispData.display, wPtr->anchorGC);
    }
    if (wPtr->anchorGC2 != None) {
	Tk_FreeGC(wPtr->dispData.display, wPtr->anchorGC2);
    }
    if (wPtr->highlightGC != None) {
	Tk_FreeGC(wPtr->dispData.display, wPtr->highlightGC);
    }

    if (wPtr->entList.numItems > 0) {
	ListEntry * fromPtr=NULL, *toPtr=NULL;
	CONST84 char * argv[2];
	argv[0] = "0";
	argv[1] = "end";

	Tix_TLGetFromTo(wPtr->dispData.interp, wPtr, 2, argv, &fromPtr,&toPtr);
	Tcl_ResetResult(wPtr->dispData.interp);

	if (fromPtr && toPtr) {
	    Tix_TLDeleteRange(wPtr, fromPtr, toPtr);
	}
    }

    if (wPtr->rows) {
	ckfree((char*)wPtr->rows);
    }

    Tk_FreeOptions(configSpecs, (char *) wPtr, wPtr->dispData.display, 0);
    ckfree((char *) wPtr);
}

/*
 *----------------------------------------------------------------------
 *
 * WidgetCmdDeletedProc --
 *
 *	This procedure is invoked when a widget command is deleted.  If
 *	the widget isn't already in the process of being destroyed,
 *	this command destroys it.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *	The widget is destroyed.
 *
 *----------------------------------------------------------------------
 */
static void
WidgetCmdDeletedProc(clientData)
    ClientData clientData;	/* Pointer to widget record for widget. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;

    /*
     * This procedure could be invoked either because the window was
     * destroyed and the command was then deleted (in which case tkwin
     * is NULL) or because the command was deleted, and then this procedure
     * destroys the widget.
     */
    if (wPtr->dispData.tkwin != NULL) {
	Tk_Window tkwin = wPtr->dispData.tkwin;
	wPtr->dispData.tkwin = NULL;
	Tk_DestroyWindow(tkwin);
    }
}

/*
 *--------------------------------------------------------------
 *
 * WidgetComputeGeometry --
 *
 *	This procedure is invoked to process the Tcl command
 *	that corresponds to a widget managed by this module.
 *	See the user documentation for details on what it does.
 *
 * Results:
 *	A standard Tcl result.
 *
 * Side effects:
 *	none
 *
 *--------------------------------------------------------------
 */
static void
WidgetComputeGeometry(clientData)
    ClientData clientData;
{
    WidgetPtr wPtr = (WidgetPtr)clientData;
    int winW, winH;
    Tk_Window tkwin = wPtr->dispData.tkwin;

    wPtr->resizing = 0;

    winW = Tk_Width(tkwin)  - 2*wPtr->highlightWidth - 2*wPtr->borderWidth;
    winH = Tk_Height(tkwin) - 2*wPtr->highlightWidth - 2*wPtr->borderWidth;

    ResizeRows(wPtr, winW, winH);
    /* Update scrollbars */
    UpdateScrollBars(wPtr, 1);

    RedrawWhenIdle(wPtr);
}

static void
MakeGeomRequest(wPtr)
    WidgetPtr wPtr;
{
    int reqW, reqH;
    
    reqW = wPtr->width  * wPtr->scrollInfo[0].unit;
    reqH = wPtr->height * wPtr->scrollInfo[1].unit;

    Tk_GeometryRequest(wPtr->dispData.tkwin, reqW, reqH);
}



/*----------------------------------------------------------------------
 * DItemSizeChanged --
 *
 *	This is called whenever the size of one of the HList's items
 *	changes its size.
 *----------------------------------------------------------------------
 */
static void
Tix_TLDItemSizeChanged(iPtr)
    Tix_DItem *iPtr;
{
    WidgetPtr wPtr = (WidgetPtr)iPtr->base.clientData;

    if (wPtr) {
	/* double-check: perhaps we haven't set the clientData yet! */
	ResizeWhenIdle(wPtr);
    }
}

/*
 *----------------------------------------------------------------------
 * ResizeWhenIdle --
 *----------------------------------------------------------------------
 */
static void
ResizeWhenIdle(wPtr)
    WidgetPtr wPtr;
{
    if (wPtr->redrawing) {
	CancelRedrawWhenIdle(wPtr);
    }
    if (!wPtr->resizing) {
	wPtr->resizing = 1;
	Tk_DoWhenIdle(WidgetComputeGeometry, (ClientData)wPtr);
    }
}

/*
 *----------------------------------------------------------------------
 * ResizeWhenIdle --
 *----------------------------------------------------------------------
 */
static void
ResizeNow(wPtr)
    WidgetPtr wPtr;
{
    if (wPtr->resizing) {
	Tk_CancelIdleCall(WidgetComputeGeometry, (ClientData)wPtr);

	WidgetComputeGeometry((ClientData)wPtr);
	wPtr->resizing = 0;
    }
}

/*
 *----------------------------------------------------------------------
 * CancelResizeWhenIdle --
 *----------------------------------------------------------------------
 */
static void
CancelResizeWhenIdle(wPtr)
    WidgetPtr wPtr;
{
    if (wPtr->resizing) {
	wPtr->resizing = 0;
	Tk_CancelIdleCall(WidgetComputeGeometry, (ClientData)wPtr);
    }
}

/*
 *----------------------------------------------------------------------
 * RedrawWhenIdle --
 *----------------------------------------------------------------------
 */
static void
RedrawWhenIdle(wPtr)
    WidgetPtr wPtr;
{
    if (wPtr->resizing) {
	/*
	 * Resize will eventually call redraw.
	 */
	return;
    }
    if (!wPtr->redrawing && Tk_IsMapped(wPtr->dispData.tkwin)) {
	wPtr->redrawing = 1;
	Tk_DoWhenIdle(WidgetDisplay, (ClientData)wPtr);
    }
}

/*
 *----------------------------------------------------------------------
 * CancelRedrawWhenIdle --
 *----------------------------------------------------------------------
 */
static void
CancelRedrawWhenIdle(wPtr)
    WidgetPtr wPtr;
{
    if (wPtr->redrawing) {
	wPtr->redrawing = 0;
	Tk_CancelIdleCall(WidgetDisplay, (ClientData)wPtr);
    }
}

/*
 *----------------------------------------------------------------------
 *
 * WidgetDisplay --
 *
 *	Draw the widget to the screen.
 *
 * Results:
 *	None.
 *
 * Side effects:
 *
 *----------------------------------------------------------------------
 */
static void
WidgetDisplay(clientData)
    ClientData clientData;	/* Info about my widget. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;
    Pixmap pixmap;
    Tk_Window tkwin = wPtr->dispData.tkwin;
    int winH, winW;
    int hl = wPtr->highlightWidth;
    int bd = wPtr->borderWidth;

    wPtr->redrawing = 0;		/* clear the redraw flag */
    wPtr->serial ++;

    pixmap = Tk_GetPixmap(wPtr->dispData.display, Tk_WindowId(tkwin),
	Tk_Width(tkwin), Tk_Height(tkwin), Tk_Depth(tkwin));

    /* Fill the background */
    XFillRectangle(wPtr->dispData.display, pixmap, wPtr->backgroundGC,
	0, 0, (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin));

    winW = Tk_Width(tkwin)  - 2*hl - 2*bd;
    winH = Tk_Height(tkwin) - 2*hl - 2*bd;

    if (winW > 0 && winH > 0) {
	RedrawRows(wPtr, pixmap);
    }

    /* Draw the border */
    Tk_Draw3DRectangle(wPtr->dispData.tkwin, pixmap, wPtr->border,
	    hl, hl, Tk_Width(tkwin)  - 2*hl, Tk_Height(tkwin) - 2*hl, bd,
	    wPtr->relief);
  
    /* Draw the highlight */
    if (hl > 0) {
	GC gc;

	if (wPtr->hasFocus) {
	    gc = wPtr->highlightGC;
	} else {
	    gc = Tk_3DBorderGC(wPtr->dispData.tkwin, wPtr->border, 
		TK_3D_FLAT_GC);
	}
	Tk_DrawFocusHighlight(tkwin, gc, hl, pixmap);
    }

    /*
     * Copy the information from the off-screen pixmap onto the screen,
     * then delete the pixmap.
     */
    XCopyArea(wPtr->dispData.display, pixmap, Tk_WindowId(tkwin),
	    wPtr->backgroundGC, 0, 0,
	    (unsigned) Tk_Width(tkwin), (unsigned) Tk_Height(tkwin), 0, 0);
    Tk_FreePixmap(wPtr->dispData.display, pixmap);

}

/*----------------------------------------------------------------------
 *  AddElement  --
 *
 *	Add the element at the position indicated by "at".
 *----------------------------------------------------------------------
 */
static int
AddElement(wPtr, chPtr, at)
    WidgetPtr wPtr;
    ListEntry * chPtr;
    int at;
{
    if (at >= wPtr->entList.numItems) {
	/* The "end" position */
	Tix_LinkListAppend(&entListInfo, &wPtr->entList, (char*)chPtr, 0);
    }
    else {
	Tix_ListIterator li;
	Tix_LinkListIteratorInit(&li);

	for (Tix_LinkListStart(&entListInfo, &wPtr->entList, &li);
	     !Tix_LinkListDone(&li);
	     Tix_LinkListNext (&entListInfo, &wPtr->entList, &li)) {

	    if (at == 0) {
		Tix_LinkListInsert(&entListInfo, &wPtr->entList,
		    (char*)chPtr, &li);
		break;
	    } else {
		-- at;
	    }
	}
    }

    return TCL_OK;
}

/*----------------------------------------------------------------------
 *  AllocEntry  --
 *
 *	Allocates memory for a new entry and initializes it to a
 *	proper state.
 *----------------------------------------------------------------------
 */
static ListEntry *
AllocEntry(wPtr)
    WidgetPtr wPtr;
{
    ListEntry * chPtr;

    chPtr = (ListEntry *)ckalloc(sizeof(ListEntry));
    chPtr->state	= NULL;
    chPtr->selected	= 0;
    chPtr->iPtr		= NULL;

    return chPtr;
}

/*----------------------------------------------------------------------
 *  FreeEntry  --
 *
 *	Free the entry and all resources allocated to this entry.
 *	This entry must already be deleted from the list.
 *----------------------------------------------------------------------
 */
static void
FreeEntry(wPtr, chPtr)
    WidgetPtr wPtr;
    ListEntry * chPtr;
{

    if (wPtr->seeElemPtr == chPtr) {
	/*
	 * This is the element that should be visible the next time
	 * we draw the window. Adjust the "to see element" to an element
	 * that is close to it.
	 */
	if (chPtr->next != NULL) {
	    wPtr->seeElemPtr = chPtr->next;
	} else {
	    ListEntry *p;

	    wPtr->seeElemPtr = NULL;
	    for (p=(ListEntry*)wPtr->entList.head; p; p=p->next) {
		if (p->next == chPtr) {
		    wPtr->seeElemPtr = p;
		    break;
		}
	    }
	}
    }

    if (wPtr->anchor == chPtr) {
	wPtr->anchor = NULL;
    }
    if (wPtr->active == chPtr) {
	wPtr->active = NULL;
    }
    if (wPtr->dragSite == chPtr) {
	wPtr->dragSite = NULL;
    }
    if (wPtr->dropSite == chPtr) {
	wPtr->dropSite = NULL;
    }

    if (chPtr->iPtr != NULL) {
	if (Tix_DItemType(chPtr->iPtr) == TIX_DITEM_WINDOW) {
#if 0
	    Tix_WindowItemListRemove(&wPtr->mappedWindows,
		chPtr->iPtr);
#endif
	}
	Tix_DItemFree(chPtr->iPtr);
    }

    Tk_FreeOptions(entryConfigSpecs, (char *)chPtr,wPtr->dispData.display, 0);
    ckfree((char*)chPtr);
}

/*----------------------------------------------------------------------
 * "insert" sub command -- 
 *
 *	Insert a new item into the list
 *----------------------------------------------------------------------
 */
static int
Tix_TLInsert(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;
    ListEntry * chPtr = NULL;
    char buff[40];
    CONST84 char * ditemType;
    int at;
    int added = 0;
    int code = TCL_OK;

    /*------------------------------------------------------------
     * (1) We need to determine the options:
     *     -itemtype and -at.
     *------------------------------------------------------------
     */

    /* (1.1) Find out where */
    if (Tix_TranslateIndex(wPtr, interp, argv[0], &at, 1) != TCL_OK) {
	code = TCL_ERROR; goto done;
    }

    /* (1.2) Find out the -itemtype, if specified */
    ditemType = wPtr->diTypePtr->name;   		 /* default value */
    if (argc > 1) {
	size_t len;
	int i;
	if (argc %2 != 1) {
	    Tcl_AppendResult(interp, "value for \"", argv[argc-1],
		"\" missing", NULL);
	    code = TCL_ERROR; goto done;
	}
	for (i=1; i<argc; i+=2) {
	    len = strlen(argv[i]);
	    if (strncmp(argv[i], "-itemtype", len) == 0) {
		ditemType = argv[i+1];
	    }
	}
    }

    if (Tix_GetDItemType(interp, ditemType) == NULL) {
	code = TCL_ERROR; goto done;
    }

    /*
     * (2) Allocate a new entry
     */
    chPtr = AllocEntry(wPtr);

    /* (2.1) The Display item data */
    if ((chPtr->iPtr = Tix_DItemCreate(&wPtr->dispData, ditemType)) == NULL) {
	code = TCL_ERROR; goto done;
    }
    chPtr->iPtr->base.clientData = (ClientData)wPtr;
    chPtr->size[0] = chPtr->iPtr->base.size[0];
    chPtr->size[1] = chPtr->iPtr->base.size[1];

    /*
     * (3) Add the entry into the list
     */
    if (AddElement(wPtr, chPtr, at) != TCL_OK) {
	code = TCL_ERROR; goto done;
    } else {
	added = 1;
    }

    if (ConfigElement(wPtr, chPtr, argc-1, argv+1, 0, 1) != TCL_OK) {
	code = TCL_ERROR; goto done;
    }

    ResizeWhenIdle(wPtr);

  done:
    if (code == TCL_ERROR) {
	if (chPtr != NULL) {
	    if (added) {
		Tix_LinkListFindAndDelete(&entListInfo, &wPtr->entList, 
		    (char*)chPtr, NULL);
	    }
	    FreeEntry(wPtr, chPtr);
	}
    } else {
	sprintf(buff, "%d", at);
	Tcl_AppendResult(interp, buff, NULL);	
    }

    return code;
}

static int 
Tix_TLSpecialEntryInfo(wPtr, interp, chPtr)
    WidgetPtr wPtr;
    Tcl_Interp *interp;
    ListEntry * chPtr;
{
    char buff[100];

    if (chPtr) {
	int i;
	Tix_ListIterator li;

	Tix_LinkListIteratorInit(&li);

	for (i=0,Tix_LinkListStart(&entListInfo, &wPtr->entList, &li);
	     !Tix_LinkListDone(&li);
	     Tix_LinkListNext(&entListInfo, &wPtr->entList, &li),i++) {
	    if (li.curr == (char*)chPtr) {
		break;
	    }
	}
	if (li.curr != NULL) {
	    sprintf(buff, "%d", i);
	    Tcl_AppendResult(interp, buff, NULL);
	} else {
	    panic("TList list entry is invalid");
	}
    } else {
	Tcl_ResetResult(interp);
    }
    return TCL_OK;
}

/*----------------------------------------------------------------------
 * "index" sub command
 *----------------------------------------------------------------------
 */
static int
Tix_TLIndex(clientData, interp, argc, argv)
    ClientData clientData;	/* TList widget record. */
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;
    int index;
    char buff[100];

    if (Tix_TranslateIndex(wPtr, interp, argv[0], &index, 0) != TCL_OK) {
	return TCL_ERROR;
    }

    sprintf(buff, "%d", index);
    Tcl_AppendResult(interp, buff, NULL);
    return TCL_OK;
}

/*----------------------------------------------------------------------
 * "info" sub command
 *----------------------------------------------------------------------
 */
static int
Tix_TLInfo(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;
    size_t len = strlen(argv[0]);

    if (strncmp(argv[0], "anchor", len)==0) {
	return Tix_TLSpecialEntryInfo(wPtr, interp, wPtr->anchor);
    }
    else if (strncmp(argv[0], "active", len)==0) {
	return Tix_TLSpecialEntryInfo(wPtr, interp, wPtr->active);
    }
    else if (strncmp(argv[0], "down", len)==0) {
	return Tix_TLGetNeighbor(wPtr, interp, TIX_DOWN,  argc-1, argv+1);
    }
    else if (strncmp(argv[0], "left", len)==0) {
	return Tix_TLGetNeighbor(wPtr, interp, TIX_LEFT,  argc-1, argv+1);
    }
    else if (strncmp(argv[0], "right", len)==0) {
	return Tix_TLGetNeighbor(wPtr, interp, TIX_RIGHT, argc-1, argv+1);
    }
    else if (strncmp(argv[0], "selection", len)==0) {
	ListEntry *chPtr;
	int i;
	char buffer[32];

	for (chPtr=(ListEntry*)wPtr->entList.head, i=0;
	     chPtr;
	     chPtr=chPtr->next, i++) {
	    
	    if (chPtr->selected) {
		if (i) {
		    Tcl_AppendResult(interp, " ", (char *) NULL);
		}
		sprintf(buffer, "%d", i);
		Tcl_AppendResult(interp, buffer, (char *) NULL);
	    }
	}
	return TCL_OK;
    }
    else if (strncmp(argv[0], "size", len)==0) {
	char buff[100];

	sprintf(buff, "%d", wPtr->entList.numItems);
	Tcl_AppendResult(interp, buff, NULL);

	return TCL_OK;
    }
    else if (strncmp(argv[0], "up", len)==0) {
	return Tix_TLGetNeighbor(wPtr, interp, TIX_UP,    argc-1, argv+1);
    }
    else {
	Tcl_AppendResult(interp, "unknown option \"", argv[0], 
	    "\": must be anchor or selection",
	    NULL);
	return TCL_ERROR;
    }
}

static int
Tix_TranslateIndex(wPtr, interp, string, index, isInsert)
    WidgetPtr wPtr;		/* TList widget record. */
    Tcl_Interp *interp;		/* Current interpreter. */
    CONST84 char * string;	/* String representation of the index. */
    int * index;		/* Returns the index value(0 = 1st element).*/
    int isInsert;		/* Is this function called by an "insert"
				 * operation? */
{
    if (strcmp(string, "end") == 0) {
	*index = wPtr->entList.numItems;
    }
    else if (Tix_TLGetAt(wPtr, interp, string, index) != TCL_OK) {
	if (Tcl_GetInt(interp, string, index) != TCL_OK) {
	    return TCL_ERROR;
	}
	else if (*index < 0) {
	    Tcl_AppendResult(interp,"expected non-negative integer but got \"",
	    	string, "\"", NULL);
	    return TCL_ERROR;
	}
    }


    /*
     * The meaning of "end" means:
     *     isInsert:wPtr->entList.numItems
     *    !isInsert:wPtr->entList.numItems-1;
     */

    if (isInsert) {
	if (*index > wPtr->entList.numItems) {
	    /*
	     * By default add it to the end, just to follow what TK
	     * does for the Listbox widget
	     */
	    *index = wPtr->entList.numItems;
	}
    } else {
	if (*index >= wPtr->entList.numItems) {
	    /*
	     * By default add it to the end, just to follow what TK
	     * does for the Listbox widget
	     */
	    *index = wPtr->entList.numItems - 1;
	}
    }

    if (*index < 0) {
	*index = 0;
    }

    return TCL_OK;
}

static int Tix_TLGetNeighbor(wPtr, interp, type, argc, argv)
    WidgetPtr wPtr;
    Tcl_Interp *interp;		/* Current interpreter. */
    int type;
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    int index;
    int dst = 0; /* lint */
    int xStep, yStep;
    int numPerRow;
    char buff[100];

    if (argc != 1) {
	Tix_ArgcError(interp, argc+3, argv-3, 3, "index");
    }

    if (Tix_TranslateIndex(wPtr, interp, argv[0], &index, 0) != TCL_OK) {
	return TCL_ERROR;
    }

    if (wPtr->entList.numItems == 0) {
	Tcl_ResetResult(interp);
	return TCL_OK;
    }

    numPerRow = wPtr->rows[0].numEnt;

    if (wPtr->isVertical) {
	xStep = numPerRow;
	yStep = 1;
    } else {
	xStep = 1;
	yStep = numPerRow;
    }

    switch (type) {
      case TIX_UP:
	dst = index - yStep;
	break;
      case TIX_DOWN:
	dst = index + yStep;
	break;
      case TIX_LEFT:
	dst = index - xStep;
	break;
      case TIX_RIGHT:
	dst = index + xStep;
	break;
    }

    if (dst < 0) {
	dst = index;
    } else if (dst >= wPtr->entList.numItems) {
	dst = index;
    }

    sprintf(buff, "%d", dst);
    Tcl_AppendResult(interp, buff, NULL);	

    return TCL_OK;
}



/*----------------------------------------------------------------------
 * "cget" sub command --
 *----------------------------------------------------------------------
 */
static int
Tix_TLCGet(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;

    return Tk_ConfigureValue(interp, wPtr->dispData.tkwin, configSpecs,
	(char *)wPtr, argv[0], 0);
}

/*----------------------------------------------------------------------
 * "configure" sub command
 *----------------------------------------------------------------------
 */
static int
Tix_TLConfig(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;

    if (argc == 0) {
	return Tk_ConfigureInfo(interp, wPtr->dispData.tkwin, configSpecs,
	    (char *) wPtr, (char *) NULL, 0);
    } else if (argc == 1) {
	return Tk_ConfigureInfo(interp, wPtr->dispData.tkwin, configSpecs,
	    (char *) wPtr, argv[0], 0);
    } else {
	return WidgetConfigure(interp, wPtr, argc, argv,
	    TK_CONFIG_ARGV_ONLY);
    }
}

/*----------------------------------------------------------------------
 * "geometryinfo" sub command
 *----------------------------------------------------------------------
 */
static int
Tix_TLGeometryInfo(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;
    int qSize[2];
    double first[2], last[2];
    char string[40];
    int i;

    if (argc == 2) {
	if (Tcl_GetInt(interp, argv[0], &qSize[0]) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (Tcl_GetInt(interp, argv[1], &qSize[1]) != TCL_OK) {
	    return TCL_ERROR;
	}
    } else {
	qSize[0] = Tk_Width (wPtr->dispData.tkwin);
	qSize[1] = Tk_Height(wPtr->dispData.tkwin);
    }
    qSize[0] -= 2*wPtr->borderWidth + 2*wPtr->highlightWidth;
    qSize[1] -= 2*wPtr->borderWidth + 2*wPtr->highlightWidth;

    for (i=0; i<2; i++) {
	qSize[i] -= 2*wPtr->borderWidth + 2*wPtr->highlightWidth;
	Tix_GetScrollFractions((Tix_ScrollInfo*)&wPtr->scrollInfo[i],
	    &first[i], &last[i]);
    }

    sprintf(string, "{%f %f} {%f %f}", first[0], last[0], first[1], last[1]);
    Tcl_AppendResult(interp, string, NULL);

    return TCL_OK;
}

/*----------------------------------------------------------------------
 * "delete" sub command
 *----------------------------------------------------------------------
 */
static int
Tix_TLDelete(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;
    ListEntry * fromPtr, *toPtr;
    int code = TCL_OK;

    if (argc < 1 || argc > 2) {
	Tix_ArgcError(interp, argc+2, argv-2, 2, "from ?to?");
	code = TCL_ERROR;
	goto done;
    }

    if (Tix_TLGetFromTo(interp, wPtr, argc, argv, &fromPtr, &toPtr)!= TCL_OK) {
	code = TCL_ERROR;
	goto done;
    }
    if (fromPtr == NULL) {
	goto done;
    }

    if (Tix_TLDeleteRange(wPtr, fromPtr, toPtr)) {
	ResizeWhenIdle(wPtr);
    }

  done:
    return code;
}

/* returns true if some element has been deleted */
static int Tix_TLDeleteRange(wPtr, fromPtr, toPtr)
    WidgetPtr wPtr;
    ListEntry * fromPtr;
    ListEntry *toPtr;
{
    int started;
    Tix_ListIterator li;

    Tix_LinkListIteratorInit(&li);
    started = 0;
    for (Tix_LinkListStart(&entListInfo, &wPtr->entList, &li);
	 !Tix_LinkListDone(&li);
	 Tix_LinkListNext (&entListInfo, &wPtr->entList, &li)) {

	ListEntry * curr = (ListEntry *)li.curr;
	if (curr == fromPtr) {
	    started = 1;
	}
	if (started) {
	    Tix_LinkListDelete(&entListInfo, &wPtr->entList, &li);
	    FreeEntry(wPtr, curr);
	}
	if (curr == toPtr) {
	    break;
	}
    }

    return started;
}


/*----------------------------------------------------------------------
 * "entrycget" sub command
 *----------------------------------------------------------------------
 */
static int
Tix_TLEntryCget(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;
    ListEntry * chPtr, * dummy;

    if (Tix_TLGetFromTo(interp, wPtr, 1, argv, &chPtr, &dummy)
	!= TCL_OK) {
	return TCL_ERROR;
    }

    if (chPtr == NULL) {
	Tcl_AppendResult(interp, "list entry \"", argv[0],
	    "\" does not exist", NULL);
	return TCL_ERROR;
    }

    return Tix_ConfigureValue2(interp, wPtr->dispData.tkwin, (char *)chPtr,
	entryConfigSpecs, chPtr->iPtr, argv[1], 0);
}

/*----------------------------------------------------------------------
 * "entryconfigure" sub command
 *----------------------------------------------------------------------
 */
static int
Tix_TLEntryConfig(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;
    ListEntry * chPtr, * dummy;

    if (Tix_TLGetFromTo(interp, wPtr, 1, argv, &chPtr, &dummy)
	!= TCL_OK) {
	return TCL_ERROR;
    }

    if (chPtr == NULL) {
	Tcl_AppendResult(interp, "list entry \"", argv[0],
	    "\" does not exist", NULL);
	return TCL_ERROR;
    }

    if (argc == 1) {
	return Tix_ConfigureInfo2(interp, wPtr->dispData.tkwin,
	    (char*)chPtr, entryConfigSpecs, chPtr->iPtr, (char *) NULL, 0);
    } else if (argc == 2) {
	return Tix_ConfigureInfo2(interp, wPtr->dispData.tkwin,
	    (char*)chPtr, entryConfigSpecs, chPtr->iPtr, (char *) argv[1], 0);
    } else {
	return ConfigElement(wPtr, chPtr, argc-1, argv+1,
	    TK_CONFIG_ARGV_ONLY, 0);
    }
}

/*----------------------------------------------------------------------
 * "nearest" sub command
 *----------------------------------------------------------------------
 */
static int
Tix_TLNearest(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;
    int posn[2];
    int index;
    char buff[100];

    if (Tcl_GetInt(interp, argv[0], &posn[0]) != TCL_OK) {
	return TCL_ERROR;
    }
    if (Tcl_GetInt(interp, argv[1], &posn[1]) != TCL_OK) {
	return TCL_ERROR;
    }

    index = Tix_TLGetNearest(wPtr, posn);
    Tcl_ResetResult(interp);

    if (index != -1) {
	sprintf(buff, "%d", index);
	Tcl_AppendResult(interp, buff, NULL);
    }
    return TCL_OK;
}

static int Tix_TLGetAt(wPtr, interp, spec, at)
    WidgetPtr wPtr;
    Tcl_Interp *interp;
    CONST84 char * spec;
    int *at;
{
    int posn[2];
    char *p, *end;

    if (spec[0] != '@') {
	return TCL_ERROR;
    }

    p = (char *) spec+1;
    posn[0] = strtol(p, &end, 0);
    if ((end == p) || (*end != ',')) {
	return TCL_ERROR;
    }
    p = end+1;
    posn[1] = strtol(p, &end, 0);
    if ((end == p) || (*end != 0)) {
	return TCL_ERROR;
    }

    *at = Tix_TLGetNearest(wPtr, posn);
    return TCL_OK;
}

static int Tix_TLGetNearest(wPtr, posn)
    WidgetPtr wPtr;
    int posn[2];
{
    int i, j, index;
    int maxX, maxY;
    int r, c;

    if (wPtr->resizing) {
	ResizeNow(wPtr);
    }

    if (wPtr->entList.numItems == 0) {
	return -1;
    }

    /* clip off the position with the border of the window */

    posn[0] -= wPtr->borderWidth + wPtr->highlightWidth;
    posn[1] -= wPtr->borderWidth + wPtr->highlightWidth;

    maxX = Tk_Width (wPtr->dispData.tkwin);
    maxY = Tk_Height(wPtr->dispData.tkwin);

    maxX -= 2*(wPtr->borderWidth + wPtr->highlightWidth);
    maxY -= 2*(wPtr->borderWidth + wPtr->highlightWidth);

    if (posn[0] >= maxX) {
	posn[0] =  maxX -1;
    }
    if (posn[1] >= maxY) {
	posn[1] =  maxY -1;
    }
    if (posn[0] < 0) {
	posn[0] = 0;
    }
    if (posn[1] < 0) {
	posn[1] = 0;
    }

    i = (wPtr->isVertical == 0);
    j = (wPtr->isVertical == 1);

    posn[0] += wPtr->scrollInfo[0].offset;
    posn[1] += wPtr->scrollInfo[1].offset;

    r = posn[i] / wPtr->maxSize[i];
    c = posn[j] / wPtr->maxSize[j];

    index = (r * wPtr->rows[0].numEnt) + c;

    if (index >= wPtr->entList.numItems) {
	index = wPtr->entList.numItems - 1;
    }

    return index;
}

/*----------------------------------------------------------------------
 * "selection" sub command
 * 	Modify the selection in this HList box
 *----------------------------------------------------------------------
 */
static int
Tix_TLGetFromTo(interp, wPtr, argc, argv, fromPtr_ret, toPtr_ret)
    Tcl_Interp *interp;
    WidgetPtr wPtr;
    int argc;
    CONST84 char **argv;
    ListEntry ** fromPtr_ret;
    ListEntry ** toPtr_ret;
{
    /*
     * ToDo: make it more efficient by saving the previous from and to
     * pointers and make the list of childrens a doubly-linked list
     */
    ListEntry * fromPtr;
    ListEntry * toPtr;
    int from, to, tmp;

    if (Tix_TranslateIndex(wPtr, interp, argv[0], &from, 0) != TCL_OK) {
	return TCL_ERROR;
    }
    if (argc == 2) {
	if (Tix_TranslateIndex(wPtr, interp, argv[1], &to, 0) != TCL_OK) {
	    return TCL_ERROR;
	}
    } else {
	to = from;
    }

    if (from > to) {
	/* swap from and to */
	tmp = to; to = from; from = tmp;
    }

    fromPtr = NULL;
    toPtr   = NULL;

    if (from >= wPtr->entList.numItems) {
	fromPtr = (ListEntry *)wPtr->entList.tail;
	toPtr   = (ListEntry *)wPtr->entList.tail;
    }
    if (to >= wPtr->entList.numItems) {
	toPtr   = (ListEntry *)wPtr->entList.tail;
    }

    if (fromPtr == NULL) {
	for (fromPtr = (ListEntry*)wPtr->entList.head;
	     from > 0;
	     fromPtr=fromPtr->next) {

	    -- from;
	    -- to;
	}
    }
    if (toPtr == NULL) {
	for (toPtr = fromPtr; to > 0; toPtr=toPtr->next) {
	    -- to;
	}
    }

    * fromPtr_ret = fromPtr;
    if (toPtr_ret) {
	* toPtr_ret = toPtr;
    }
    return TCL_OK;
}

static int
Tix_TLSelection(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;
    size_t len = strlen(argv[0]);
    int code = TCL_OK;
    int changed = 0;
    ListEntry * chPtr, * fromPtr, * toPtr;

    if (strncmp(argv[0], "clear", len)==0) {
	if (argc == 1) {
	    /*
	     * Clear all entries
	     */
	    for (chPtr=(ListEntry*)wPtr->entList.head;
		 chPtr;
		 chPtr=chPtr->next) {

		chPtr->selected = 0;
	    }
	    changed = 1;
	}
	else {
	    if (Tix_TLGetFromTo(interp, wPtr, argc-1, argv+1, &fromPtr, &toPtr)
		    != TCL_OK) {
		code = TCL_ERROR;
		goto done;
	    }
	    if (fromPtr == NULL) {
		goto done;
	    }
	    else {
		while (1) {
		    fromPtr->selected = 0;
		    if (fromPtr == toPtr) {
			break;
		    } else {
			fromPtr=fromPtr->next;
		    }
		}
		changed = 1;
		goto done;
	    }
	}
    }
    else if (strncmp(argv[0], "includes", len)==0) {
	if (argc != 2) {
	    Tix_ArgcError(interp, argc+2, argv-2, 3, "index");
	    code = TCL_ERROR;
	    goto done;
	}
	if (Tix_TLGetFromTo(interp, wPtr, argc-1, argv+1, &fromPtr, &toPtr)
		!= TCL_OK) {
	    code = TCL_ERROR;
	    goto done;
	}
	if (fromPtr->selected) {
	    Tcl_AppendResult(interp, "1", NULL);
	} else {
	    Tcl_AppendResult(interp, "0", NULL);
	}
    }
    else if (strncmp(argv[0], "set", len)==0) {
	if (argc < 2 || argc > 3) {
	    Tix_ArgcError(interp, argc+2, argv-2, 3, "from ?to?");
	    code = TCL_ERROR;
	    goto done;
	}

	if (Tix_TLGetFromTo(interp, wPtr, argc-1, argv+1, &fromPtr, &toPtr)
		!= TCL_OK) {
	    code = TCL_ERROR;
	    goto done;
	}
	if (fromPtr == NULL) {
	    goto done;
	}
	else {
	    while (1) {
		fromPtr->selected = 1;
		if (fromPtr == toPtr) {
		    break;
		} else {
		    fromPtr=fromPtr->next;
		}
	    }
	    changed = 1;
	    goto done;
	}
    }
    else {
	Tcl_AppendResult(interp, "unknown option \"", argv[0], 
	    "\": must be anchor, clear, includes or set", NULL);
	code = TCL_ERROR;
    }

  done:
    if (changed) {
	RedrawWhenIdle(wPtr);
    }

    return code;
}

/*
 *----------------------------------------------------------------------
 *
 * Tix_TLSee --
 *
 *      Implements the "see" widget subcommand -- make sure that the
 *      given entry is visible as much as possible.
 *
 *      We don't scroll the widget immediately in this function.
 *      Instead, we set the wPtr->seeElemPtr and the scrolling will be
 *      set when the widget is redrawn. This make sure that the "see"
 *      command works even before the widget's contents has been laid
 *      out.
 *
 * Results:
 *      A standard Tcl result.
 *
 * Side effects:
 *      Widget is scheduled to be redrawn.
 *
 *----------------------------------------------------------------------
 */

static int
Tix_TLSee(clientData, interp, argc, argv)
    ClientData clientData;      /* The widget data struct */
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;
    ListEntry * chPtr, * dummy;

    if (argc == 1) {
	if (Tix_TLGetFromTo(interp, wPtr, 1, argv, &chPtr, &dummy) != TCL_OK) {
	    return TCL_ERROR;
	}
	if (chPtr != NULL) {
	    wPtr->seeElemPtr = chPtr;
	    RedrawWhenIdle(wPtr);
	}
    } else {
	Tcl_AppendResult(interp, "wrong # of arguments, must be: ",
		Tk_PathName(wPtr->dispData.tkwin), " ", argv[-1],
		" index", NULL);
    }

    return TCL_OK;
}

/*----------------------------------------------------------------------
 * "anchor", "dragsite" and "dropsite" sub commands --
 *
 *	Set/remove the anchor element
 *----------------------------------------------------------------------
 */
static int
Tix_TLSetSite(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    int changed = 0;
    WidgetPtr wPtr = (WidgetPtr) clientData;
    ListEntry * fromPtr;
    ListEntry * toPtr;			/* unused */
    ListEntry ** changePtr;
    size_t len;

    /* Determine which site should be changed (the last else clause
     * doesn't need to check the string because HandleSubCommand
     * already ensures that only the valid options can be specified.
     **/
    len = strlen(argv[-1]);
    if (strncmp(argv[-1], "anchor", len)==0) {
	changePtr = &wPtr->anchor;
    }
    else if (strncmp(argv[-1], "active", len)==0) {
	changePtr = &wPtr->active;
    }
    else if (strncmp(argv[-1], "dragsite", len)==0) {
	changePtr = &wPtr->dragSite;
    }
    else {
	changePtr = &wPtr->dropSite;
    }

    len = strlen(argv[0]);
    if (strncmp(argv[0], "set", len)==0) {
	if (argc == 2) {
	    if (Tix_TLGetFromTo(interp,wPtr, argc-1, argv+1, &fromPtr, &toPtr)
		    != TCL_OK) {
		return TCL_ERROR;
	    }
	    if (*changePtr != fromPtr) {
		*changePtr = fromPtr;
		changed = 1;
	    }
	} else {
	    Tcl_AppendResult(interp, "wrong # of arguments, must be: ",
		Tk_PathName(wPtr->dispData.tkwin), " ", argv[-1],
		" set index", NULL);
	    return TCL_ERROR;
	}
    }
    else if (strncmp(argv[0], "clear", len)==0) {
	if (*changePtr != NULL) {
	    *changePtr = NULL;
	    changed = 1;
	}
    }
    else {
	Tcl_AppendResult(interp, "wrong option \"", argv[0], "\", ",
	    "must be clear or set", NULL);
	return TCL_ERROR;
    }

    if (changed) {
	RedrawWhenIdle(wPtr);
    }

    return TCL_OK;
}

/*----------------------------------------------------------------------
 * "xview" and "yview" sub command
 *----------------------------------------------------------------------
 */
static int
Tix_TLView(clientData, interp, argc, argv)
    ClientData clientData;
    Tcl_Interp *interp;		/* Current interpreter. */
    int argc;			/* Number of arguments. */
    CONST84 char **argv;	/* Argument strings. */
{
    WidgetPtr wPtr = (WidgetPtr) clientData;
    int axis;

    if (argv[-1][0] == 'x') {
	axis = 0;
    } else {
	axis = 1;
    }

    if (argc == 0) {
	char string[80];
	double first, last;

	Tix_GetScrollFractions((Tix_ScrollInfo*)&wPtr->scrollInfo[axis],
	    &first, &last);

	sprintf(string, "{%f %f}", first, last);
	Tcl_AppendResult(interp, string, NULL);
	return TCL_OK;
    }
    else if (Tix_SetScrollBarView(interp, 
	(Tix_ScrollInfo*)&wPtr->scrollInfo[axis], argc, argv, 0) != TCL_OK) {

	return TCL_ERROR;
    }

    UpdateScrollBars(wPtr, 0);
    RedrawWhenIdle(wPtr);
    return TCL_OK;
}
/*----------------------------------------------------------------------
 *
 *
 * 			Memory Management Section
 *
 *
 *----------------------------------------------------------------------
 */
static int
ConfigElement(wPtr, chPtr, argc, argv, flags, forced)
    WidgetPtr wPtr;
    ListEntry *chPtr;
    int argc;
    CONST84 char ** argv;
    int flags;
    int forced;
{
    int sizeChanged;

    if (Tix_WidgetConfigure2(wPtr->dispData.interp, wPtr->dispData.tkwin,
	(char*)chPtr, entryConfigSpecs, chPtr->iPtr, argc, argv, flags,
	forced, &sizeChanged) != TCL_OK) {
	return TCL_ERROR;
    }

    if (sizeChanged) {
	chPtr->size[0] = chPtr->iPtr->base.size[0];
	chPtr->size[1] = chPtr->iPtr->base.size[1];
	ResizeWhenIdle(wPtr);
    } else {
	RedrawWhenIdle(wPtr);
    }
    return TCL_OK;
}

static void
Realloc(wPtr, new_size)
    WidgetPtr wPtr;
    int new_size;
{
    if (new_size < 1) {
	new_size = 1;
    }
    if (new_size == wPtr->numRowAllocd) {
	return;
    }
    wPtr->rows = (ListRow*)ckrealloc( (char *)wPtr->rows,
                                      sizeof(ListRow)*new_size);
    wPtr->numRowAllocd = new_size;
}

static void ResizeRows(wPtr, winW, winH)
    WidgetPtr wPtr;
    int winW;			/* -1 == current width */
    int winH;			/* -1 == current height */
{
    ListEntry * chPtr;
    ListEntry * rowHead;
    int n, c, r;
    int maxI;			/* max of width in the current column */
    int maxJ;			/* max of height among all elements */
    int curRow;
    int i, j;
    int sizeJ;
    int winSize[2];

    if (wPtr->isVertical) {
	i = 0;		/* Column major, 0,0 -> 0,1 -> 0,2 ... -> 1,0 */
	j = 1;
    } else {
	i = 1;		/* Row major, 0,0 -> 1,0 -> 2,0 ... -> 0,1 */
	j = 0;
    }

    if (winW == -1) {
	winW = Tk_Width (wPtr->dispData.tkwin);
    }
    if (winH == -1) {
	winH = Tk_Height(wPtr->dispData.tkwin);
    }

    winSize[0] = winW;
    winSize[1] = winH;
    
    if (wPtr->entList.numItems == 0) {
	wPtr->rows[0].chPtr = NULL;
	wPtr->rows[0].size[0] = 1;
	wPtr->rows[0].size[1] = 1;
	wPtr->rows[0].numEnt = 0;

	wPtr->numRow = 1;
	goto done;
    }

    /* 	    --  The following verbal description follows the "Column Major"
     *     	model. Row major are similar, just the i,j incides are swapped
     *
     * (1) (a) Search for the tallest element, use it as the height of all
     *         the elements;
     *     (b) Search for the widest element, use it as the width of all
     *         the elements;
     */
    for (maxJ=1, maxI=1, chPtr = (ListEntry*)wPtr->entList.head;
	 chPtr;
	 chPtr=chPtr->next) {

	if (maxJ < chPtr->iPtr->base.size[j]) {
	    maxJ = chPtr->iPtr->base.size[j];
	}
	if (maxI < chPtr->iPtr->base.size[i]) {
	    maxI = chPtr->iPtr->base.size[i];
	}
    }
    wPtr->maxSize[i] = maxI;
    wPtr->maxSize[j] = maxJ;

    /* (2) Calculate how many elements can be in each column
     *
     */
    n = winSize[j] / maxJ;
    if (n <=0) {
	n = 1;
    }

    wPtr->numRow = 0;
    curRow = 0;
    c = 0;
    sizeJ = 0;
    rowHead = (ListEntry*)wPtr->entList.head;
    for(chPtr = (ListEntry*)wPtr->entList.head; chPtr; chPtr=chPtr->next) {
	sizeJ += chPtr->iPtr->base.size[j];
	++ c;
	if (c == n || chPtr->next == NULL) {
	    if (curRow >= wPtr->numRowAllocd) {
		Realloc(wPtr, curRow*2);
	    }
	    wPtr->rows[curRow].chPtr   = rowHead;
	    wPtr->rows[curRow].size[i] = maxI;
	    wPtr->rows[curRow].size[j] = sizeJ;
	    wPtr->rows[curRow].numEnt  = c;
	    ++ curRow;
	    ++ wPtr->numRow;
	    c = 0;
	    rowHead = chPtr->next;
	    sizeJ = 0;
	}
    }

  done:
    /* calculate the size of the total and visible area */
    wPtr->scrollInfo[i].total = 0;
    wPtr->scrollInfo[j].total = 0;

    for (r=0; r<wPtr->numRow; r++) {
	wPtr->scrollInfo[i].total += wPtr->rows[r].size[i];
	if (wPtr->scrollInfo[j].total < wPtr->rows[r].size[j]) {
	    wPtr->scrollInfo[j].total = wPtr->rows[r].size[j];
	}
    }

    wPtr->scrollInfo[i].window = winSize[i];
    wPtr->scrollInfo[j].window = winSize[j];

    if (wPtr->scrollInfo[i].total < 1) {
	wPtr->scrollInfo[i].total = 1;
    }
    if (wPtr->scrollInfo[j].total < 1) {
	wPtr->scrollInfo[j].total = 1;
    }
    if (wPtr->scrollInfo[i].window < 1) {
	wPtr->scrollInfo[i].window = 1;
    }
    if (wPtr->scrollInfo[j].window < 1) {
	wPtr->scrollInfo[j].window = 1;
    }

    /* If we have much fewer rows now, adjust the size of the rows list */
    if (wPtr->numRowAllocd > (2*wPtr->numRow)) {
	Realloc(wPtr, 2*wPtr->numRow);
    }

    /* Update the scrollbars */

    UpdateScrollBars(wPtr, 1);
}
/*----------------------------------------------------------------------
 * RedrawRows --
 *
 *	Redraw the rows, according to the "offset" in both directions
 *----------------------------------------------------------------------
 */

static void
RedrawRows(wPtr, pixmap)
    WidgetPtr wPtr;
    Drawable pixmap;
{
    int r, n;
    int p[2];
    ListEntry * chPtr;
    int i, j;
    int total;
    int windowSize;

    if (wPtr->entList.numItems == 0) {
	return;
    }

    if (wPtr->isVertical) {
	i = 0;		/* Column major, 0,0 -> 0,1 -> 0,2 ... -> 1,0 */
	j = 1;
	windowSize = Tk_Width(wPtr->dispData.tkwin);
    } else {
	i = 1;		/* Row major, 0,0 -> 1,0 -> 2,0 ... -> 0,1 */
	j = 0;
	windowSize = Tk_Height(wPtr->dispData.tkwin);
    }

    p[i] = wPtr->highlightWidth + wPtr->borderWidth;
    windowSize -= 2*p[i];

    if (windowSize < 1) {
	windowSize = 1;
    }

    if (wPtr->seeElemPtr != NULL) {
	/*
	 * Adjust the scrolling so that the given the entry is visible in
         * its entirty (as much as allowed by the height of the TList)
	 */

	int start = 0;		/* y1 position of the element to see. */
	int size = 0;		/* height of the element to see. */
	int old = wPtr->scrollInfo[i].offset;

	for (r=0, n=0, chPtr=(ListEntry*)wPtr->entList.head; chPtr;
		chPtr=chPtr->next) {
	    if (chPtr == wPtr->seeElemPtr) {
		size = chPtr->size[i];
		break;
	    }
            n++;
	    if (n == wPtr->rows[r].numEnt) {
		n=0;
		r++;
		start += wPtr->rows[r].size[i];
	    }
	}

	if (wPtr->scrollInfo[i].offset + windowSize < start + size) {
            /*
             * Bottom of the entry is beneath the bottom edge
             */
	    wPtr->scrollInfo[i].offset = start + size - windowSize;
	}
	if (wPtr->scrollInfo[i].offset > start) {
            /*
             * Top of the entry is above the top edge
             */
	    wPtr->scrollInfo[i].offset = start;
	}
	if (wPtr->scrollInfo[i].offset != old) {
	    UpdateScrollBars(wPtr, 0);
	}
	wPtr->seeElemPtr = NULL;
    }

    /*
     * Search for the first row from the top (or first column from the left)
     * that is (possibly partially) visible
     */
    total=0; r=0;
    if (wPtr->scrollInfo[i].offset != 0) {
	for (; r<wPtr->numRow; r++) {
	    total += wPtr->rows[r].size[i];

	    if (total > wPtr->scrollInfo[i].offset) {
		p[i] -= wPtr->scrollInfo[i].offset - 
		        (total - wPtr->rows[r].size[i]);
		break;
	    }
	    if (total == wPtr->scrollInfo[i].offset) {
		r++;
		break;
	    }
	}
    }

    /* Redraw all the visible rows */
    for (; r<wPtr->numRow; r++) {

	p[j] = wPtr->highlightWidth + wPtr->borderWidth;

	total=0; n=0; chPtr=wPtr->rows[r].chPtr;
	if (wPtr->scrollInfo[j].offset > 0)  {
	    /* Search for a column that is (possibly partially) visible*/
	    for (;
		 n<wPtr->rows[r].numEnt;
		 n++, chPtr = chPtr->next) {

		total += chPtr->iPtr->base.size[j];
		if (total > wPtr->scrollInfo[j].offset) {
		    /* Adjust for the shift due to partially visible elements*/
		    p[j] -= wPtr->scrollInfo[j].offset - 
		      (total - chPtr->iPtr->base.size[j]);
		    break;
		}
		if (total == wPtr->scrollInfo[j].offset) {
		    n++; chPtr = chPtr->next;
		    break;
		}
	    }
	}

	/* Redraw all the visible columns in this row */
	for (; n<wPtr->rows[r].numEnt; n++, chPtr = chPtr->next) {
	    int flags = TIX_DITEM_NORMAL_FG | TIX_DITEM_NORMAL_BG;
	    int W, H;

	    if (chPtr->selected) {
		flags |= TIX_DITEM_SELECTED_FG;
		flags |= TIX_DITEM_SELECTED_BG;
	    }

	    if (wPtr->isVertical) {
		W = wPtr->rows[r].size[0];
		H = chPtr->iPtr->base.size[1];
	    } else {
		H = wPtr->rows[r].size[1];
		W = chPtr->iPtr->base.size[0];
	    }

            if (chPtr == wPtr->anchor && wPtr->hasFocus) {
                flags |= TIX_DITEM_ANCHOR;
            }

	    Tix_DItemDisplay(pixmap, chPtr->iPtr, p[0], p[1], W, H,
		0, 0, flags);

#if 0
	    if (chPtr == wPtr->anchor && wPtr->hasFocus) {
                GC ancGC;
                if (chPtr->selected) {
                    ancGC = wPtr->anchorGC;
                } else {
                    ancGC = wPtr->anchorGC2;
                }
		Tix_DrawAnchorLines(Tk_Display(wPtr->dispData.tkwin), pixmap,
	                ancGC, p[0], p[1], W, H);
	    }
#endif
	    p[j] += wPtr->maxSize[j];
	}

	/* advance to the next row */
	p[i]+= wPtr->rows[r].size[i];
    }
}

/*----------------------------------------------------------------------
 *  UpdateScrollBars
 *----------------------------------------------------------------------
 */
static void UpdateScrollBars(wPtr, sizeChanged)
    WidgetPtr wPtr;
    int sizeChanged;
{
    Tix_UpdateScrollBar(wPtr->dispData.interp,
	(Tix_ScrollInfo*)&wPtr->scrollInfo[0]);
    Tix_UpdateScrollBar(wPtr->dispData.interp,
	(Tix_ScrollInfo*)&wPtr->scrollInfo[1]);

    if (wPtr->sizeCmd && sizeChanged) {
	if (Tcl_Eval(wPtr->dispData.interp, wPtr->sizeCmd) != TCL_OK) {
	    Tcl_AddErrorInfo(wPtr->dispData.interp,
		"\n    (size command executed by tixTList)");
	    Tk_BackgroundError(wPtr->dispData.interp);
	}
    }
}