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 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930
|
#==============================================================================
# Contains private configuration procedures for tablelist widgets.
#
# Copyright (c) 2000-2011 Csaba Nemethi (E-mail: csaba.nemethi@t-online.de)
#==============================================================================
#------------------------------------------------------------------------------
# tablelist::extendConfigSpecs
#
# Extends the elements of the array configSpecs.
#------------------------------------------------------------------------------
proc tablelist::extendConfigSpecs {} {
variable usingTile
variable helpLabel
variable configSpecs
variable winSys
#
# Extend some elements of the array configSpecs
#
lappend configSpecs(-acceptchildcommand) {}
lappend configSpecs(-activestyle) frame
lappend configSpecs(-autoscan) 1
lappend configSpecs(-collapsecommand) {}
lappend configSpecs(-columns) {}
lappend configSpecs(-columntitles) {}
lappend configSpecs(-editendcommand) {}
lappend configSpecs(-editselectedonly) 0
lappend configSpecs(-editstartcommand) {}
lappend configSpecs(-expandcommand) {}
lappend configSpecs(-forceeditendcommand) 0
lappend configSpecs(-fullseparators) 0
lappend configSpecs(-incrarrowtype) up
lappend configSpecs(-labelcommand) {}
lappend configSpecs(-labelcommand2) {}
lappend configSpecs(-labelrelief) raised
lappend configSpecs(-listvariable) {}
lappend configSpecs(-movablecolumns) 0
lappend configSpecs(-movablerows) 0
lappend configSpecs(-populatecommand) {}
lappend configSpecs(-protecttitlecolumns) 0
lappend configSpecs(-resizablecolumns) 1
lappend configSpecs(-selecttype) row
lappend configSpecs(-setfocus) 1
lappend configSpecs(-showarrow) 1
lappend configSpecs(-showlabels) 1
lappend configSpecs(-showseparators) 0
lappend configSpecs(-snipstring) ...
lappend configSpecs(-sortcommand) {}
lappend configSpecs(-spacing) 0
lappend configSpecs(-stretch) {}
lappend configSpecs(-stripebackground) {}
lappend configSpecs(-stripeforeground) {}
lappend configSpecs(-stripeheight) 1
lappend configSpecs(-targetcolor) black
lappend configSpecs(-titlecolumns) 0
lappend configSpecs(-tooltipaddcommand) {}
lappend configSpecs(-tooltipdelcommand) {}
lappend configSpecs(-treecolumn) 0
#
# Append the default values of the configuration options
# of a temporary, invisible listbox widget to the values
# of the corresponding elements of the array configSpecs
#
set helpListbox .__helpListbox
for {set n 2} {[winfo exists $helpListbox]} {incr n} {
set helpListbox .__helpListbox$n
}
listbox $helpListbox
foreach configSet [$helpListbox configure] {
if {[llength $configSet] != 2} {
set opt [lindex $configSet 0]
if {[info exists configSpecs($opt)]} {
lappend configSpecs($opt) [lindex $configSet 3]
}
}
}
destroy $helpListbox
set helpLabel .__helpLabel
for {set n 0} {[winfo exists $helpLabel]} {incr n} {
set helpLabel .__helpLabel$n
}
if {$usingTile} {
foreach opt {-highlightbackground -highlightcolor -highlightthickness
-labelactivebackground -labelactiveforeground
-labelbackground -labelbg -labeldisabledforeground
-labelheight} {
unset configSpecs($opt)
}
#
# Append theme-specific values to some elements of the
# array configSpecs and initialize some tree resources
#
setThemeDefaults
variable themeDefaults
set treeStyle $themeDefaults(-treestyle)
${treeStyle}TreeImgs
variable maxIndentDepths
set maxIndentDepths($treeStyle) 0
ttk::label $helpLabel -takefocus 0
#
# Define the header label layout
#
style theme settings "default" {
style layout TablelistHeader.TLabel {
Treeheading.cell
Treeheading.border -children {
Label.padding -children {
Label.label
}
}
}
}
if {[string compare [package provide ttk::theme::aqua] ""] != 0 ||
[string compare [package provide tile::theme::aqua] ""] != 0} {
style theme settings "aqua" {
if {[info exists tile::patchlevel] &&
[string compare $tile::patchlevel "0.6.4"] < 0} {
style layout TablelistHeader.TLabel {
Treeheading.cell
Label.padding -children {
Label.label -side top
Separator.hseparator -side bottom
}
}
} else {
style layout TablelistHeader.TLabel {
Treeheading.cell
Label.padding -children {
Label.label -side top
}
}
}
style map TablelistHeader.TLabel -foreground [list \
{disabled background} #a3a3a3 disabled #a3a3a3 \
background black]
}
}
} else {
if {$::tk_version < 8.3} {
unset configSpecs(-acceptchildcommand)
unset configSpecs(-collapsecommand)
unset configSpecs(-expandcommand)
unset configSpecs(-populatecommand)
unset configSpecs(-titlecolumns)
unset configSpecs(-treecolumn)
unset configSpecs(-treestyle)
}
#
# Append the default values of some configuration options
# of an invisible label widget to the values of the
# corresponding -label* elements of the array configSpecs
#
tk::label $helpLabel -takefocus 0
foreach optTail {font height} {
set configSet [$helpLabel configure -$optTail]
lappend configSpecs(-label$optTail) [lindex $configSet 3]
}
if {[catch {$helpLabel configure -activebackground} configSet1] == 0 &&
[catch {$helpLabel configure -activeforeground} configSet2] == 0} {
lappend configSpecs(-labelactivebackground) [lindex $configSet1 3]
lappend configSpecs(-labelactiveforeground) [lindex $configSet2 3]
} else {
unset configSpecs(-labelactivebackground)
unset configSpecs(-labelactiveforeground)
}
if {[catch {$helpLabel configure -disabledforeground} configSet] == 0} {
lappend configSpecs(-labeldisabledforeground) [lindex $configSet 3]
} else {
unset configSpecs(-labeldisabledforeground)
}
if {[string compare $winSys "win32"] == 0 &&
$::tcl_platform(osVersion) < 5.1} {
lappend configSpecs(-labelpady) 0
} else {
set configSet [$helpLabel configure -pady]
lappend configSpecs(-labelpady) [lindex $configSet 3]
}
#
# Steal the default values of some configuration
# options from a temporary, invisible button widget
#
set helpButton .__helpButton
for {set n 0} {[winfo exists $helpButton]} {incr n} {
set helpButton .__helpButton$n
}
button $helpButton
foreach opt {-disabledforeground -state} {
if {[llength $configSpecs($opt)] == 3} {
set configSet [$helpButton configure $opt]
lappend configSpecs($opt) [lindex $configSet 3]
}
}
foreach optTail {background foreground} {
set configSet [$helpButton configure -$optTail]
lappend configSpecs(-label$optTail) [lindex $configSet 3]
}
if {[string compare $winSys "classic"] == 0 ||
[string compare $winSys "aqua"] == 0} {
lappend configSpecs(-labelborderwidth) 1
} else {
set configSet [$helpButton configure -borderwidth]
lappend configSpecs(-labelborderwidth) [lindex $configSet 3]
}
destroy $helpButton
#
# Set the default values of the -arrowcolor,
# -arrowdisabledcolor, -arrowstyle, and -treestyle options
#
switch $winSys {
x11 {
set arrowColor {}
set arrowDisabledColor {}
set arrowStyle sunken10x9
set treeStyle gtk
}
win32 {
if {$::tcl_platform(osVersion) < 5.1} { ;# Win native
set arrowColor {}
set arrowDisabledColor {}
set arrowStyle sunken8x7
set treeStyle winnative
} elseif {$::tcl_platform(osVersion) == 5.1} { ;# Win XP
switch [winfo rgb . SystemHighlight] {
"12593 27242 50629" { ;# Win XP Blue
set arrowColor #aca899
set arrowStyle flat9x5
set treeStyle winxpBlue
}
"37779 41120 28784" { ;# Win XP Olive
set arrowColor #aca899
set arrowStyle flat9x5
set treeStyle winxpOlive
}
"45746 46260 49087" { ;# Win XP Silver
set arrowColor #aca899
set arrowStyle flat9x5
set treeStyle winxpSilver
}
default { ;# Win Classic
set arrowColor SystemButtonShadow
set arrowStyle flat7x4
set treeStyle winnative
}
}
set arrowDisabledColor SystemDisabledText
} elseif {$::tcl_platform(osVersion) == 6.0} { ;# Win Vista
switch [winfo rgb . SystemHighlight] {
"13107 39321 65535" { ;# Vista Aero
set arrowColor #569bc0
set arrowStyle flat7x4
set treeStyle vistaAero
}
default { ;# Win Classic
set arrowColor SystemButtonShadow
set arrowStyle flat7x4
set treeStyle vistaClassic
}
}
set arrowDisabledColor SystemDisabledText
} else { ;# Win 7
switch [winfo rgb . SystemHighlight] {
"13107 39321 65535" { ;# Win 7 Aero
set arrowColor #569bc0
set arrowStyle flat7x4
set treeStyle win7Aero
}
default { ;# Win Classic
set arrowColor SystemButtonShadow
set arrowStyle flat7x4
set treeStyle win7Classic
}
}
set arrowDisabledColor SystemDisabledText
}
}
classic -
aqua {
set arrowColor #717171
set arrowDisabledColor #a3a3a3
set arrowStyle flat7x7
set treeStyle aqua
}
}
lappend configSpecs(-arrowcolor) $arrowColor
lappend configSpecs(-arrowdisabledcolor) $arrowDisabledColor
lappend configSpecs(-arrowstyle) $arrowStyle
if {$::tk_version >= 8.3} {
lappend configSpecs(-treestyle) $treeStyle
${treeStyle}TreeImgs
variable maxIndentDepths
set maxIndentDepths($treeStyle) 0
}
}
#
# Set the default values of the -movecolumncursor,
# -movecursor, and -resizecursor options
#
switch $winSys {
x11 -
win32 {
set movecolumnCursor icon
set moveCursor hand2
set resizeCursor sb_h_double_arrow
}
classic -
aqua {
set movecolumnCursor closedhand
set moveCursor pointinghand
if {[catch {$helpLabel configure -cursor resizeleftright}] == 0} {
set resizeCursor resizeleftright
} else {
set resizeCursor sb_h_double_arrow
}
}
}
lappend configSpecs(-movecolumncursor) $movecolumnCursor
lappend configSpecs(-movecursor) $moveCursor
lappend configSpecs(-resizecursor) $resizeCursor
}
#------------------------------------------------------------------------------
# tablelist::doConfig
#
# Applies the value val of the configuration option opt to the tablelist widget
# win.
#------------------------------------------------------------------------------
proc tablelist::doConfig {win opt val} {
variable usingTile
variable helpLabel
variable configSpecs
upvar ::tablelist::ns${win}::data data
#
# Apply the value to the widget(s) corresponding to the given option
#
switch [lindex $configSpecs($opt) 2] {
c {
#
# Apply the value to all children and save the
# properly formatted value of val in data($opt)
#
foreach w [winfo children $win] {
if {[regexp {^(body|hdr|sep([0-9]+)?)$} [winfo name $w]]} {
$w configure $opt $val
}
}
$data(hdrTxt) configure $opt $val
$data(hdrFrLbl) configure $opt $val
$data(cornerLbl) configure $opt $val
foreach w [winfo children $data(hdrTxtFr)] {
$w configure $opt $val
}
set data($opt) [$data(hdrFrLbl) cget $opt]
}
b {
#
# Apply the value to the body text widget and save
# the properly formatted value of val in data($opt)
#
set w $data(body)
$w configure $opt $val
set data($opt) [$w cget $opt]
switch -- $opt {
-background {
#
# Apply the value to the frame (because of
# the shadow colors of its 3-D border), to
# the separators, and to the "disabled" tag
#
if {$usingTile} {
styleConfig Frame$win.TFrame $opt $val
styleConfig Seps$win.TSeparator $opt $val
} else {
$win configure $opt $val
foreach c [winfo children $win] {
if {[regexp {^sep[0-9]+$} [winfo name $c]]} {
$c configure $opt $val
}
}
}
$w tag configure disabled $opt $val
updateColorsWhenIdle $win
}
-font {
#
# Apply the value to the listbox child, rebuild the lists
# of the column fonts and tag names, configure the edit
# window if present, set up and adjust the columns, and
# make sure the items will be redisplayed at idle time
#
$data(lb) configure $opt $val
set data(charWidth) [font measure $val -displayof $win 0]
makeColFontAndTagLists $win
if {$data(editRow) >= 0} {
setEditWinFont $win
}
for {set col 0} {$col < $data(colCount)} {incr col} {
if {$data($col-maxwidth) > 0} {
set data($col-maxPixels) \
[charsToPixels $win $val $data($col-maxwidth)]
}
}
setupColumns $win $data(-columns) 0
adjustColumns $win allCols 1
redisplayWhenIdle $win
updateViewWhenIdle $win
}
-foreground {
#
# Set the background color of the main separator
# frame (if any) to the specified value, and apply
# this value to the "disabled" tag if needed
#
if {$usingTile} {
styleConfig Sep$win.TSeparator -background $val
} else {
if {[winfo exists $data(sep)]} {
$data(sep) configure -background $val
}
}
if {[string compare $data(-disabledforeground) ""] == 0} {
$w tag configure disabled $opt $val
}
updateColorsWhenIdle $win
}
}
}
l {
#
# Apply the value to all not individually configured labels
# and save the properly formatted value of val in data($opt)
#
set optTail [string range $opt 6 end] ;# remove the -label
configLabel $data(hdrFrLbl) -$optTail $val
configLabel $data(cornerLbl) -$optTail $val
for {set col 0} {$col < $data(colCount)} {incr col} {
set w $data(hdrTxtFrLbl)$col
if {![info exists data($col$opt)]} {
configLabel $w -$optTail $val
}
}
if {$usingTile && [string compare $opt "-labelpady"] == 0} {
set data($opt) $val
} else {
set data($opt) [$data(hdrFrLbl) cget -$optTail]
}
switch -- $opt {
-labelbackground -
-labelforeground {
#
# Apply the value to $data(hdrTxt) and conditionally
# to the canvases displaying up- or down-arrows
#
$helpLabel configure -$optTail $val
set data($opt) [$helpLabel cget -$optTail]
$data(hdrTxt) configure -$optTail $data($opt)
foreach col $data(arrowColList) {
if {![info exists data($col$opt)]} {
configCanvas $win $col
}
}
}
-labelborderwidth {
#
# Adjust the columns (including
# the height of the header frame)
#
adjustColumns $win allLabels 1
set borderWidth [winfo pixels $win $data($opt)]
if {$borderWidth < 0} {
set borderWidth 0
}
place configure $data(cornerLbl) -x -$borderWidth \
-width [expr {2*$borderWidth}]
}
-labeldisabledforeground {
#
# Conditionally apply the value to the
# canvases displaying up- or down-arrows
#
foreach col $data(arrowColList) {
if {![info exists data($col$opt)]} {
configCanvas $win $col
}
}
}
-labelfont {
#
# Apply the value to $data(hdrTxt) and adjust the
# columns (including the height of the header frame)
#
$data(hdrTxt) configure -$optTail $data($opt)
adjustColumns $win allLabels 1
}
-labelheight -
-labelpady {
#
# Adjust the height of the header frame
#
adjustHeaderHeight $win
}
}
}
f {
#
# Apply the value to the frame and save the
# properly formatted value of val in data($opt)
#
$win configure $opt $val
set data($opt) [$win cget $opt]
}
w {
switch -- $opt {
-acceptchildcommand -
-collapsecommand -
-editendcommand -
-editstartcommand -
-expandcommand -
-labelcommand -
-labelcommand2 -
-populatecommand -
-selectmode -
-sortcommand -
-tooltipaddcommand -
-tooltipdelcommand -
-yscrollcommand {
set data($opt) $val
}
-activestyle {
#
# Configure the "active" tag and save the
# properly formatted value of val in data($opt)
#
variable activeStyles
set val [mwutil::fullOpt "active style" $val $activeStyles]
set w $data(body)
switch $val {
frame {
$w tag configure active \
-borderwidth 1 -relief solid -underline ""
}
none {
$w tag configure active \
-borderwidth "" -relief "" -underline ""
}
underline {
$w tag configure active \
-borderwidth "" -relief "" -underline 1
}
}
set data($opt) $val
}
-arrowcolor -
-arrowdisabledcolor {
#
# Save the properly formatted value of val in data($opt)
# and set the color of the normal or disabled arrows
#
if {[string compare $val ""] == 0} {
set data($opt) ""
} else {
$helpLabel configure -foreground $val
set data($opt) [$helpLabel cget -foreground]
}
if {([string compare $opt "-arrowcolor"] == 0 &&
!$data(isDisabled)) ||
([string compare $opt "-arrowdisabledcolor"] == 0 &&
$data(isDisabled))} {
foreach w [info commands $data(hdrTxtFrCanv)*] {
fillArrows $w $val $data(-arrowstyle)
}
}
}
-arrowstyle {
#
# Save the properly formatted value of val in data($opt)
# and draw the corresponding arrows in the canvas widgets
#
variable arrowStyles
set data($opt) \
[mwutil::fullOpt "arrow style" $val $arrowStyles]
regexp {^(flat|sunken|photo)([0-9]+)x([0-9]+)$} \
$data($opt) dummy relief width height
set data(arrowWidth) $width
set data(arrowHeight) $height
foreach w [info commands $data(hdrTxtFrCanv)*] {
createArrows $w $width $height $relief
if {$data(isDisabled)} {
fillArrows $w $data(-arrowdisabledcolor) $data($opt)
} else {
fillArrows $w $data(-arrowcolor) $data($opt)
}
}
if {[llength $data(arrowColList)] > 0} {
foreach col $data(arrowColList) {
raiseArrow $win $col
lappend whichWidths l$col
}
adjustColumns $win $whichWidths 1
}
}
-autoscan -
-editselectedonly -
-forceeditendcommand -
-movablecolumns -
-movablerows -
-protecttitlecolumns -
-resizablecolumns -
-setfocus {
#
# Save the boolean value specified by val in data($opt)
#
set data($opt) [expr {$val ? 1 : 0}]
}
-columns {
#
# Set up and adjust the columns, rebuild
# the lists of the column fonts and tag
# names, and redisplay the items
#
set selCells [curCellSelection $win]
setupColumns $win $val 1
adjustColumns $win allCols 1
adjustColIndex $win data(anchorCol) 1
adjustColIndex $win data(activeCol) 1
makeColFontAndTagLists $win
redisplay $win 0 $selCells
updateViewWhenIdle $win
}
-columntitles {
set titleCount [llength $val]
set colCount $data(colCount)
if {$titleCount <= $colCount} {
#
# Update the first titleCount column
# titles and adjust the columns
#
set whichWidths {}
for {set col 0} {$col < $titleCount} {incr col} {
set idx [expr {3*$col + 1}]
set data(-columns) [lreplace $data(-columns) \
$idx $idx [lindex $val $col]]
lappend whichWidths l$col
}
adjustColumns $win $whichWidths 1
} else {
#
# Update the titles of the current columns,
# extend the column list, and do nearly the
# same as in the case of the -columns option
#
set columns {}
set col 0
foreach {width title alignment} $data(-columns) {
lappend columns $width [lindex $val $col] $alignment
incr col
}
for {} {$col < $titleCount} {incr col} {
lappend columns 0 [lindex $val $col] left
}
set selCells [curCellSelection $win]
setupColumns $win $columns 1
adjustColumns $win allCols 1
makeColFontAndTagLists $win
redisplay $win 0 $selCells
updateViewWhenIdle $win
#
# If this option is being set at widget creation time
# then append "-columns" to the list of command line
# options processed by the caller proc, to make sure
# that the columns-related information produced by the
# setupColumns call above won't be overridden by the
# default -columns {} option that would otherwise
# be processed as a non-explicitly specified option
#
set callerProc [lindex [info level -1] 0]
if {[string compare $callerProc \
"mwutil::configureWidget"] == 0} {
uplevel 1 lappend cmdLineOpts "-columns"
}
}
}
-disabledforeground {
#
# Configure the "disabled" tag in the body text widget and
# save the properly formatted value of val in data($opt)
#
set w $data(body)
if {[string compare $val ""] == 0} {
$w tag configure disabled -fgstipple gray50 \
-foreground $data(-foreground)
set data($opt) ""
} else {
$w tag configure disabled -fgstipple "" \
-foreground $val
set data($opt) [$w tag cget disabled -foreground]
}
if {$data(isDisabled)} {
updateColorsWhenIdle $win
}
}
-exportselection {
#
# Save the boolean value specified by val in
# data($opt). In addition, if the selection is
# exported and there are any selected rows in the
# widget then make win the new owner of the PRIMARY
# selection and register a callback to be invoked
# when it loses ownership of the PRIMARY selection
#
set data($opt) [expr {$val ? 1 : 0}]
if {$val &&
[llength [$data(body) tag nextrange select 1.0]] != 0} {
selection own -command \
[list ::tablelist::lostSelection $win] $win
}
}
-fullseparators {
#
# Save the boolean value specified by val
# in data($opt) and adjust the separators
#
set data($opt) [expr {$val ? 1 : 0}]
adjustSepsWhenIdle $win
}
-height {
#
# Adjust the heights of the body text widget
# and of the listbox child, and save the
# properly formatted value of val in data($opt)
#
set val [format "%d" $val] ;# integer check with error msg
if {$val <= 0} {
set viewableRowCount [expr \
{$data(itemCount) - $data(nonViewableRowCount)}]
$data(body) configure $opt $viewableRowCount
$data(lb) configure $opt $viewableRowCount
} else {
$data(body) configure $opt $val
$data(lb) configure $opt $val
}
set data($opt) $val
}
-incrarrowtype {
#
# Save the properly formatted value of val in
# data($opt) and raise the corresponding arrows
# if the currently mapped canvas widgets
#
variable arrowTypes
set data($opt) \
[mwutil::fullOpt "arrow type" $val $arrowTypes]
foreach col $data(arrowColList) {
raiseArrow $win $col
}
}
-listvariable {
#
# Associate val as list variable with the
# given widget and save it in data($opt)
#
makeListVar $win $val
set data($opt) $val
if {[string compare $val ""] == 0} {
set data(hasListVar) 0
} else {
set data(hasListVar) 1
}
}
-movecolumncursor -
-movecursor -
-resizecursor {
#
# Save the properly formatted value of val in data($opt)
#
$helpLabel configure -cursor $val
set data($opt) [$helpLabel cget -cursor]
}
-selectbackground -
-selectforeground {
#
# Configure the "select" tag in the body text widget
# and save the properly formatted value of val in
# data($opt). Don't use the built-in "sel" tag
# because on Windows the selection in a text widget only
# becomes visible when the window gets the input focus.
#
set w $data(body)
set optTail [string range $opt 7 end] ;# remove the -select
$w tag configure select -$optTail $val
set data($opt) [$w tag cget select -$optTail]
if {!$data(isDisabled)} {
updateColorsWhenIdle $win
}
}
-selecttype {
#
# Save the properly formatted value of val in data($opt)
#
variable selectTypes
set val [mwutil::fullOpt "selection type" $val $selectTypes]
set data($opt) $val
}
-selectborderwidth {
#
# Configure the "select" tag in the body text widget
# and save the properly formatted value of val in
# data($opt). Don't use the built-in "sel" tag
# because on Windows the selection in a text widget only
# becomes visible when the window gets the input focus.
# In addition, adjust the line spacing accordingly and
# apply the value to the listbox child, too.
#
set w $data(body)
set optTail [string range $opt 7 end] ;# remove the -select
$w tag configure select -$optTail $val
set data($opt) [$w tag cget select -$optTail]
set pixVal [winfo pixels $w $val]
if {$pixVal < 0} {
set pixVal 0
}
set spacing [winfo pixels $w $data(-spacing)]
if {$spacing < 0} {
set spacing 0
}
$w configure -spacing1 [expr {$spacing + $pixVal}] \
-spacing3 [expr {$spacing + $pixVal + 1}]
$data(lb) configure $opt $val
redisplayWhenIdle $win
updateViewWhenIdle $win
}
-setgrid {
#
# Apply the value to the listbox child and save
# the properly formatted value of val in data($opt)
#
$data(lb) configure $opt $val
set data($opt) [$data(lb) cget $opt]
}
-showarrow {
#
# Save the boolean value specified by val in
# data($opt) and manage or unmanage the
# canvases displaying up- or down-arrows
#
set data($opt) [expr {$val ? 1 : 0}]
makeSortAndArrowColLists $win
adjustColumns $win allLabels 1
}
-showlabels {
#
# Save the boolean value specified by val in data($opt)
# and adjust the height of the header frame
#
set data($opt) [expr {$val ? 1 : 0}]
adjustHeaderHeight $win
}
-showseparators {
#
# Save the boolean value specified by val in data($opt),
# and create or destroy the separators if needed
#
set oldVal $data($opt)
set data($opt) [expr {$val ? 1 : 0}]
if {!$oldVal && $data($opt)} {
createSeps $win
} elseif {$oldVal && !$data($opt)} {
foreach w [winfo children $win] {
if {[regexp {^sep[0-9]+$} [winfo name $w]]} {
destroy $w
}
}
}
}
-snipstring {
#
# Save val in data($opt), adjust the columns, and make
# sure the items will be redisplayed at idle time
#
set data($opt) $val
adjustColumns $win {} 0
redisplayWhenIdle $win
updateViewWhenIdle $win
}
-spacing {
#
# Adjust the line spacing and save val in data($opt)
#
set w $data(body)
set pixVal [winfo pixels $w $val]
if {$pixVal < 0} {
set pixVal 0
}
set selectBd [winfo pixels $w $data(-selectborderwidth)]
if {$selectBd < 0} {
set selectBd 0
}
$w configure -spacing1 [expr {$pixVal + $selectBd}] \
-spacing3 [expr {$pixVal + $selectBd + 1}]
set data($opt) $val
redisplayWhenIdle $win
updateViewWhenIdle $win
}
-state {
#
# Apply the value to all labels and their sublabels
# (if any), as well as to the edit window (if present),
# add/remove the "disabled" tag to/from the contents
# of the body text widget, configure the borderwidth
# of the "active" and "select" tags, save the
# properly formatted value of val in data($opt),
# and raise the corresponding arrow in the canvas
#
variable states
set val [mwutil::fullOpt "state" $val $states]
catch {
configLabel $data(hdrFrLbl) $opt $val
configLabel $data(cornerLbl) $opt $val
for {set col 0} {$col < $data(colCount)} {incr col} {
configLabel $data(hdrTxtFrLbl)$col $opt $val
}
}
if {$data(editRow) >= 0} {
catch {$data(bodyFrEd) configure $opt $val}
}
set w $data(body)
switch $val {
disabled {
$w tag add disabled 1.0 end
$w tag configure select -relief flat
set data(isDisabled) 1
}
normal {
$w tag remove disabled 1.0 end
$w tag configure select -relief raised
set data(isDisabled) 0
}
}
set data($opt) $val
foreach col $data(arrowColList) {
configCanvas $win $col
raiseArrow $win $col
}
updateColorsWhenIdle $win
}
-stretch {
#
# Save the properly formatted value of val in
# data($opt) and stretch the stretchable columns
#
if {[string first $val "all"] == 0} {
set data($opt) all
} else {
set data($opt) $val
sortStretchableColList $win
}
set data(forceAdjust) 1
stretchColumnsWhenIdle $win
}
-stripebackground -
-stripeforeground {
#
# Configure the "stripe" tag in the body text
# widget, save the properly formatted value of val
# in data($opt), and draw the stripes if necessary
#
set w $data(body)
set optTail [string range $opt 7 end] ;# remove the -stripe
$w tag configure stripe -$optTail $val
set data($opt) [$w tag cget stripe -$optTail]
makeStripesWhenIdle $win
}
-stripeheight {
#
# Save the properly formatted value of val in
# data($opt) and draw the stripes if necessary
#
set val [format "%d" $val] ;# integer check with error msg
set data($opt) $val
makeStripesWhenIdle $win
}
-targetcolor {
#
# Set the color of the row and column gaps, and save
# the properly formatted value of val in data($opt)
#
$data(rowGap) configure -background $val
$data(colGap) configure -background $val
set data($opt) [$data(rowGap) cget -background]
}
-titlecolumns {
#
# Update the value of the -xscrollcommand option, save
# the properly formatted value of val in data($opt),
# and create or destroy the main separator if needed
#
set oldVal $data($opt)
set val [format "%d" $val] ;# integer check with error msg
if {$val < 0} {
set val 0
}
xviewSubCmd $win 0
set w $data(sep)
if {$val == 0} {
$data(hdrTxt) configure -xscrollcommand \
$data(-xscrollcommand)
if {$oldVal > 0} {
destroy $w
}
} else {
$data(hdrTxt) configure -xscrollcommand ""
if {$oldVal == 0} {
if {$usingTile} {
ttk::separator $w -style Sep$win.TSeparator \
-cursor $data(-cursor) \
-orient vertical -takefocus 0
} else {
tk::frame $w -background $data(-foreground) \
-borderwidth 1 -container 0 \
-cursor $data(-cursor) \
-highlightthickness 0 \
-relief sunken -takefocus 0 \
-width 2
}
bindtags $w [lreplace [bindtags $w] 1 1 \
$data(bodyTag) TablelistBody]
}
adjustSepsWhenIdle $win
}
set data($opt) $val
xviewSubCmd $win 0
updateHScrlbarWhenIdle $win
}
-treecolumn {
#
# Save the properly formatted value of val in
# data($opt), its adjusted value in data(treeCol),
# and move the tree images into the new tree column
#
set oldTreeCol $data(treeCol)
set newTreeCol [colIndex $win $val 0]
set data($opt) $newTreeCol
adjustColIndex $win newTreeCol
set data(treeCol) $newTreeCol
if {$data(colCount) != 0} {
set data($opt) $newTreeCol
}
if {$newTreeCol != $oldTreeCol} {
for {set row 0} {$row < $data(itemCount)} {incr row} {
doCellConfig $row $newTreeCol $win -indent \
[doCellCget $row $oldTreeCol $win -indent]
doCellConfig $row $oldTreeCol $win -indent ""
}
}
}
-treestyle {
#
# Update the tree images and save the properly
# formatted value of val in data($opt)
#
variable treeStyles
set newStyle [mwutil::fullOpt "tree style" $val $treeStyles]
set oldStyle $data($opt)
set treeCol $data(treeCol)
if {[string compare $newStyle $oldStyle] != 0} {
${newStyle}TreeImgs
variable maxIndentDepths
if {![info exists maxIndentDepths($newStyle)]} {
set maxIndentDepths($newStyle) 0
}
if {$data(colCount) != 0} {
for {set row 0} {$row < $data(itemCount)} \
{incr row} {
set oldImg \
[doCellCget $row $treeCol $win -indent]
set newImg [strMap \
[list $oldStyle $newStyle "Sel" ""] $oldImg]
if {[regexp {^.+Img([0-9]+)$} $newImg \
dummy depth]} {
if {$depth > $maxIndentDepths($newStyle)} {
createTreeImgs $newStyle $depth
set maxIndentDepths($newStyle) $depth
}
doCellConfig $row $treeCol $win \
-indent $newImg
}
}
}
}
set data($opt) $newStyle
set data(protectIndents) [expr {![regexp \
{^(a.+|dust.*|gtk|newWave|plastique|radiance|win7.+)$} \
$newStyle]}]
set selCells [curCellSelection $win 1]
foreach {key col} $selCells {
set row [keyToRow $win $key]
cellSelection $win set $row $col $row $col
}
if {$data(ownsFocus) && ![info exists data(dispId)]} {
addActiveTag $win
}
}
-width {
#
# Adjust the widths of the body text widget,
# header frame, and listbox child, and save the
# properly formatted value of val in data($opt)
#
set val [format "%d" $val] ;# integer check with error msg
$data(body) configure $opt $val
if {$val <= 0} {
$data(hdr) configure $opt $data(hdrPixels)
$data(lb) configure $opt \
[expr {$data(hdrPixels) / $data(charWidth)}]
} else {
$data(hdr) configure $opt 0
$data(lb) configure $opt $val
}
set data($opt) $val
}
-xscrollcommand {
#
# Save val in data($opt), and apply it to the header text
# widget if (and only if) no title columns are being used
#
set data($opt) $val
if {$data(-titlecolumns) == 0} {
$data(hdrTxt) configure $opt $val
} else {
$data(hdrTxt) configure $opt ""
}
}
}
}
}
}
#------------------------------------------------------------------------------
# tablelist::doCget
#
# Returns the value of the configuration option opt for the tablelist widget
# win.
#------------------------------------------------------------------------------
proc tablelist::doCget {win opt} {
upvar ::tablelist::ns${win}::data data
if {[string compare $opt "-columntitles"] == 0} {
set colTitles {}
foreach {width title alignment} $data(-columns) {
lappend colTitles $title
}
return $colTitles
} else {
return $data($opt)
}
}
#------------------------------------------------------------------------------
# tablelist::doColConfig
#
# Applies the value val of the column configuration option opt to the col'th
# column of the tablelist widget win.
#------------------------------------------------------------------------------
proc tablelist::doColConfig {col win opt val} {
variable canElide
upvar ::tablelist::ns${win}::data data
switch -- $opt {
-align {
#
# Set up and adjust the columns, and make sure the
# given column will be redisplayed at idle time
#
set idx [expr {3*$col + 2}]
setupColumns $win [lreplace $data(-columns) $idx $idx $val] 0
adjustColumns $win {} 0
redisplayColWhenIdle $win $col
}
-background -
-foreground {
set w $data(body)
set name $col$opt
if {[info exists data($name)] &&
(!$data($col-hide) || $canElide)} {
#
# Remove the tag col$opt-$data($name)
# from the elements of the given column
#
set tag col$opt-$data($name)
for {set line 1} {$line <= $data(itemCount)} {incr line} {
findTabs $win $line $col $col tabIdx1 tabIdx2
$w tag remove $tag $tabIdx1 $tabIdx2+1c
}
}
if {[string compare $val ""] == 0} {
if {[info exists data($name)]} {
unset data($name)
}
} else {
#
# Configure the tag col$opt-$val in the body text widget
#
set tag col$opt-$val
$w tag configure $tag $opt $val
$w tag lower $tag
if {!$data($col-hide) || $canElide} {
#
# Apply the tag to the elements of the given column
#
for {set line 1} {$line <= $data(itemCount)} {incr line} {
findTabs $win $line $col $col tabIdx1 tabIdx2
if {[lsearch -exact [$w tag names $tabIdx1] select]
< 0} {
$w tag add $tag $tabIdx1 $tabIdx2+1c
}
}
}
#
# Save val in data($name)
#
set data($name) $val
}
if {!$data(isDisabled)} {
updateColorsWhenIdle $win
}
#
# Rebuild the lists of the column fonts and tag names
#
makeColFontAndTagLists $win
}
-changesnipside -
-wrap {
#
# Save the boolean value specified by val in data($col$opt) and
# make sure the given column will be redisplayed at idle time
#
set data($col$opt) [expr {$val ? 1 : 0}]
if {[lindex $data(-columns) [expr {3*$col}]] != 0} {
redisplayColWhenIdle $win $col
updateViewWhenIdle $win
}
}
-editable -
-resizable {
#
# Save the boolean value specified by val in data($col$opt)
#
set data($col$opt) [expr {$val ? 1 : 0}]
}
-editwindow {
variable editWin
if {[info exists editWin($val-creationCmd)]} {
set data($col$opt) $val
} else {
return -code error "name \"$val\" is not registered\
for interactive cell editing"
}
}
-font {
set w $data(body)
set name $col$opt
if {[info exists data($name)] &&
(!$data($col-hide) || $canElide)} {
#
# Remove the tag col$opt-$data($name)
# from the elements of the given column
#
set tag col$opt-$data($name)
for {set line 1} {$line <= $data(itemCount)} {incr line} {
findTabs $win $line $col $col tabIdx1 tabIdx2
$w tag remove $tag $tabIdx1 $tabIdx2+1c
}
}
if {[string compare $val ""] == 0} {
if {[info exists data($name)]} {
unset data($name)
}
} else {
#
# Configure the tag col$opt-$val in the body text widget
#
set tag col$opt-$val
$w tag configure $tag $opt $val
$w tag lower $tag
if {!$data($col-hide) || $canElide} {
#
# Apply the tag to the elements of the given column
#
for {set line 1} {$line <= $data(itemCount)} {incr line} {
findTabs $win $line $col $col tabIdx1 tabIdx2
$w tag add $tag $tabIdx1 $tabIdx2+1c
}
}
#
# Save val in data($name)
#
set data($name) $val
}
#
# Rebuild the lists of the column fonts and tag names
#
makeColFontAndTagLists $win
#
# Adjust the columns, and make sure the specified
# column will be redisplayed at idle time
#
adjustColumns $win $col 1
redisplayColWhenIdle $win $col
updateViewWhenIdle $win
if {$col == $data(editCol)} {
#
# Configure the edit window
#
setEditWinFont $win
}
}
-formatcommand {
if {[string compare $val ""] == 0} {
if {[info exists data($col$opt)]} {
unset data($col$opt)
}
set fmtCmdFlag 0
} else {
set data($col$opt) $val
set fmtCmdFlag 1
}
#
# Update the corresponding element of the list data(fmtCmdFlagList)
#
set data(fmtCmdFlagList) \
[lreplace $data(fmtCmdFlagList) $col $col $fmtCmdFlag]
set data(hasFmtCmds) \
[expr {[lsearch -exact $data(fmtCmdFlagList) 1] >= 0}]
#
# Adjust the columns and make sure the specified
# column will be redisplayed at idle time
#
adjustColumns $win $col 1
redisplayColWhenIdle $win $col
updateViewWhenIdle $win
}
-hide {
#
# Save the boolean value specified by val in data($col$opt),
# adjust the columns, and redisplay the items
#
set oldVal $data($col$opt)
set newVal [expr {$val ? 1 : 0}]
if {$newVal != $oldVal} {
if {!$canElide} {
set selCells [curCellSelection $win]
}
set data($col$opt) $newVal
if {$newVal} { ;# hiding the column
incr data(hiddenColCount)
adjustColIndex $win data(anchorCol) 1
adjustColIndex $win data(activeCol) 1
if {$col == $data(editCol)} {
doCancelEditing $win
}
} else {
incr data(hiddenColCount) -1
}
makeColFontAndTagLists $win
adjustColumns $win $col 1
if {!$canElide} {
redisplay $win 0 $selCells
if {!$newVal &&
[string compare $data(-selecttype) "row"] == 0} {
foreach row [curSelection $win] {
rowSelection $win set $row $row
}
}
}
updateViewWhenIdle $win
event generate $win <<TablelistColHiddenStateChanged>>
}
}
-labelalign {
if {[string compare $val ""] == 0} {
#
# Unset data($col$opt)
#
set alignment [lindex $data(colList) [expr {2*$col + 1}]]
if {[info exists data($col$opt)]} {
unset data($col$opt)
}
} else {
#
# Save the properly formatted value of val in data($col$opt)
#
variable alignments
set val [mwutil::fullOpt "label alignment" $val $alignments]
set alignment $val
set data($col$opt) $val
}
#
# Adjust the col'th label
#
set pixels [lindex $data(colList) [expr {2*$col}]]
if {$pixels == 0} { ;# convention: dynamic width
if {$data($col-maxPixels) > 0} {
if {$data($col-reqPixels) > $data($col-maxPixels)} {
set pixels $data($col-maxPixels)
}
}
}
if {$pixels != 0} {
incr pixels $data($col-delta)
}
adjustLabel $win $col $pixels $alignment
}
-labelbackground -
-labelforeground {
set w $data(hdrTxtFrLbl)$col
set optTail [string range $opt 6 end] ;# remove the -label
if {[string compare $val ""] == 0} {
#
# Apply the value of the corresponding widget
# configuration option to the col'th label and
# its sublabels (if any), and unset data($col$opt)
#
configLabel $w -$optTail $data($opt)
if {[info exists data($col$opt)]} {
unset data($col$opt)
}
} else {
#
# Apply the given value to the col'th label and
# its sublabels (if any), and save the properly
# formatted value of val in data($col$opt)
#
configLabel $w -$optTail $val
variable helpLabel
$helpLabel configure -$optTail $val
set data($col$opt) [$helpLabel cget -$optTail]
}
if {[lsearch -exact $data(arrowColList) $col] >= 0} {
configCanvas $win $col
}
}
-labelborderwidth {
set w $data(hdrTxtFrLbl)$col
set optTail [string range $opt 6 end] ;# remove the -label
if {[string compare $val ""] == 0} {
#
# Apply the value of the corresponding widget configuration
# option to the col'th label and unset data($col$opt)
#
configLabel $w -$optTail $data($opt)
if {[info exists data($col$opt)]} {
unset data($col$opt)
}
} else {
#
# Apply the given value to the col'th label and save the
# properly formatted value of val in data($col$opt)
#
configLabel $w -$optTail $val
set data($col$opt) [$w cget -$optTail]
}
#
# Adjust the columns (including the height of the header frame)
#
adjustColumns $win l$col 1
}
-labelcommand -
-labelcommand2 -
-name -
-sortcommand {
if {[string compare $val ""] == 0} {
if {[info exists data($col$opt)]} {
unset data($col$opt)
}
} else {
set data($col$opt) $val
}
}
-labelfont {
set w $data(hdrTxtFrLbl)$col
set optTail [string range $opt 6 end] ;# remove the -label
if {[string compare $val ""] == 0} {
#
# Apply the value of the corresponding widget
# configuration option to the col'th label and
# its sublabels (if any), and unset data($col$opt)
#
configLabel $w -$optTail $data($opt)
if {[info exists data($col$opt)]} {
unset data($col$opt)
}
} else {
#
# Apply the given value to the col'th label and
# its sublabels (if any), and save the properly
# formatted value of val in data($col$opt)
#
configLabel $w -$optTail $val
set data($col$opt) [$w cget -$optTail]
}
#
# Adjust the columns (including the height of the header frame)
#
adjustColumns $win l$col 1
}
-labelheight -
-labelpady {
set w $data(hdrTxtFrLbl)$col
set optTail [string range $opt 6 end] ;# remove the -label
if {[string compare $val ""] == 0} {
#
# Apply the value of the corresponding widget configuration
# option to the col'th label and unset data($col$opt)
#
configLabel $w -$optTail $data($opt)
if {[info exists data($col$opt)]} {
unset data($col$opt)
}
} else {
#
# Apply the given value to the col'th label and save the
# properly formatted value of val in data($col$opt)
#
configLabel $w -$optTail $val
variable usingTile
if {$usingTile} {
set data($col$opt) $val
} else {
set data($col$opt) [$w cget -$optTail]
}
}
#
# Adjust the height of the header frame
#
adjustHeaderHeight $win
}
-labelimage {
set w $data(hdrTxtFrLbl)$col
if {[string compare $val ""] == 0} {
foreach l [getSublabels $w] {
destroy $l
}
if {[info exists data($col$opt)]} {
unset data($col$opt)
}
} else {
if {![winfo exists $w-il]} {
variable configSpecs
variable configOpts
foreach l [list $w-il $w-tl] { ;# image and text labels
#
# Create the label $l
#
tk::label $l -borderwidth 0 -height 0 \
-highlightthickness 0 -padx 0 \
-pady 0 -takefocus 0 -width 0
#
# Apply to it the current configuration options
#
foreach opt2 $configOpts {
if {[string compare \
[lindex $configSpecs($opt2) 2] "c"] == 0} {
$l configure $opt2 $data($opt2)
}
}
if {[string compare [winfo class $w] "TLabel"] == 0} {
variable themeDefaults
$l configure -background \
$themeDefaults(-labelbackground)
} else {
$l configure -background [$w cget -background]
$l configure -foreground [$w cget -foreground]
$l configure -font [$w cget -font]
}
foreach opt2 {-activebackground -activeforeground
-disabledforeground -state} {
catch {$l configure $opt2 [$w cget $opt2]}
}
#
# Replace the binding tag Label with $w,
# $data(labelTag), and TablelistSubLabel in
# the list of binding tags of the label $l
#
bindtags $l [lreplace [bindtags $l] 1 1 \
$w $data(labelTag) TablelistSubLabel]
}
}
#
# Display the specified image in the label
# $w-il and save val in data($col$opt)
#
$w-il configure -image $val
set data($col$opt) $val
}
#
# Adjust the columns (including the height of the header frame)
#
adjustColumns $win l$col 1
}
-labelrelief {
set w $data(hdrTxtFrLbl)$col
set optTail [string range $opt 6 end] ;# remove the -label
if {[string compare $val ""] == 0} {
#
# Apply the value of the corresponding widget configuration
# option to the col'th label and unset data($col$opt)
#
configLabel $w -$optTail $data($opt)
if {[info exists data($col$opt)]} {
unset data($col$opt)
}
} else {
#
# Apply the given value to the col'th label and save the
# properly formatted value of val in data($col$opt)
#
configLabel $w -$optTail $val
set data($col$opt) [$w cget -$optTail]
}
}
-maxwidth {
#
# Save the properly formatted value of val in
# data($col$opt), adjust the columns, and make sure
# the specified column will be redisplayed at idle time
#
set val [format "%d" $val] ;# integer check with error message
set data($col$opt) $val
if {$val > 0} { ;# convention: max. width in characters
set pixels [charsToPixels $win $data(-font) $val]
} elseif {$val < 0} { ;# convention: max. width in pixels
set pixels [expr {(-1)*$val}]
} else { ;# convention: no max. width
set pixels 0
}
set data($col-maxPixels) $pixels
adjustColumns $win $col 1
redisplayColWhenIdle $win $col
updateViewWhenIdle $win
}
-selectbackground -
-selectforeground {
set w $data(body)
set name $col$opt
if {[info exists data($name)] &&
(!$data($col-hide) || $canElide)} {
#
# Remove the tag col$opt-$data($name)
# from the elements of the given column
#
set tag col$opt-$data($name)
for {set line 1} {$line <= $data(itemCount)} {incr line} {
findTabs $win $line $col $col tabIdx1 tabIdx2
$w tag remove $tag $tabIdx1 $tabIdx2+1c
}
}
if {[string compare $val ""] == 0} {
if {[info exists data($name)]} {
unset data($name)
}
} else {
#
# Configure the tag col$opt-$val in the body text widget
#
set tag col$opt-$val
set optTail [string range $opt 7 end] ;# remove the -select
$w tag configure $tag -$optTail $val
$w tag raise $tag select
if {!$data($col-hide) || $canElide} {
#
# Apply the tag to the selected elements of the given column
#
set selRange [$w tag nextrange select 1.0]
while {[llength $selRange] != 0} {
set selStart [lindex $selRange 0]
set line [expr {int($selStart)}]
findTabs $win $line $col $col tabIdx1 tabIdx2
if {[lsearch -exact [$w tag names $tabIdx1] select]
>= 0} {
$w tag add $tag $tabIdx1 $tabIdx2+1c
}
set selRange \
[$w tag nextrange select "$selStart lineend"]
}
}
#
# Save val in data($name)
#
set data($name) $val
}
if {!$data(isDisabled)} {
updateColorsWhenIdle $win
}
}
-showarrow {
#
# Save the boolean value specified by val in data($col$opt) and
# manage or unmanage the canvas displaying an up- or down-arrow
#
set data($col$opt) [expr {$val ? 1 : 0}]
makeSortAndArrowColLists $win
adjustColumns $win l$col 1
}
-showlinenumbers {
#
# Save the boolean value specified by val in
# data($col$opt), and make sure the line numbers
# will be redisplayed at idle time if needed
#
set val [expr {$val ? 1 : 0}]
if {!$data($col$opt) && $val} {
showLineNumbersWhenIdle $win
}
set data($col$opt) $val
}
-sortmode {
#
# Save the properly formatted value of val in data($col$opt)
#
variable sortModes
set data($col$opt) [mwutil::fullOpt "sort mode" $val $sortModes]
}
-stretchable {
set flag [expr {$val ? 1 : 0}]
if {$flag} {
if {[string compare $data(-stretch) "all"] != 0 &&
[lsearch -exact $data(-stretch) $col] < 0} {
#
# col was not found in data(-stretch): add it to the list
#
lappend data(-stretch) $col
sortStretchableColList $win
set data(forceAdjust) 1
stretchColumnsWhenIdle $win
}
} elseif {[string compare $data(-stretch) "all"] == 0} {
#
# Replace the value "all" of data(-stretch) with
# the list of all column indices different from col
#
set data(-stretch) {}
for {set n 0} {$n < $data(colCount)} {incr n} {
if {$n != $col} {
lappend data(-stretch) $n
}
}
set data(forceAdjust) 1
stretchColumnsWhenIdle $win
} else {
#
# If col is contained in data(-stretch)
# then remove it from the list
#
if {[set n [lsearch -exact $data(-stretch) $col]] >= 0} {
set data(-stretch) [lreplace $data(-stretch) $n $n]
set data(forceAdjust) 1
stretchColumnsWhenIdle $win
}
#
# If col indicates the last column and data(-stretch)
# contains "end" then remove "end" from the list
#
if {$col == $data(lastCol) &&
[string compare [lindex $data(-stretch) end] "end"] == 0} {
set data(-stretch) [lreplace $data(-stretch) end end]
set data(forceAdjust) 1
stretchColumnsWhenIdle $win
}
}
}
-text {
if {$data(isDisabled)} {
return ""
}
#
# Replace the column's contents in the internal list
#
set newItemList {}
set row 0
foreach item $data(itemList) text [lrange $val 0 $data(lastRow)] {
set item [lreplace $item $col $col $text]
lappend newItemList $item
}
set data(itemList) $newItemList
#
# Update the list variable if present
#
condUpdateListVar $win
#
# Adjust the columns and make sure the specified
# column will be redisplayed at idle time
#
adjustColumns $win $col 1
redisplayColWhenIdle $win $col
updateViewWhenIdle $win
}
-title {
#
# Save the given value in the corresponding
# element of data(-columns) and adjust the columns
#
set idx [expr {3*$col + 1}]
set data(-columns) [lreplace $data(-columns) $idx $idx $val]
adjustColumns $win l$col 1
}
-width {
#
# Set up and adjust the columns, and make sure the
# given column will be redisplayed at idle time
#
set idx [expr {3*$col}]
if {$val != [lindex $data(-columns) $idx]} {
setupColumns $win [lreplace $data(-columns) $idx $idx $val] 0
redisplayColWhenIdle $win $col ;# here before adjustColumns!
adjustColumns $win $col 1
updateViewWhenIdle $win
}
}
}
}
#------------------------------------------------------------------------------
# tablelist::doColCget
#
# Returns the value of the column configuration option opt for the col'th
# column of the tablelist widget win.
#------------------------------------------------------------------------------
proc tablelist::doColCget {col win opt} {
upvar ::tablelist::ns${win}::data data
switch -- $opt {
-align {
return [lindex $data(-columns) [expr {3*$col + 2}]]
}
-stretchable {
return [expr {
[string compare $data(-stretch) "all"] == 0 ||
[lsearch -exact $data(-stretch) $col] >= 0 ||
($col == $data(lastCol) && \
[string compare [lindex $data(-stretch) end] "end"] == 0)
}]
}
-text {
set result {}
foreach item $data(itemList) {
lappend result [lindex $item $col]
}
return $result
}
-title {
return [lindex $data(-columns) [expr {3*$col + 1}]]
}
-width {
return [lindex $data(-columns) [expr {3*$col}]]
}
default {
if {[info exists data($col$opt)]} {
return $data($col$opt)
} else {
return ""
}
}
}
}
#------------------------------------------------------------------------------
# tablelist::doRowConfig
#
# Applies the value val of the row configuration option opt to the row'th row
# of the tablelist widget win.
#------------------------------------------------------------------------------
proc tablelist::doRowConfig {row win opt val} {
variable canElide
variable elide
variable snipSides
upvar ::tablelist::ns${win}::data data
set w $data(body)
switch -- $opt {
-background -
-foreground {
set key [lindex $data(keyList) $row]
set name $key$opt
if {[info exists data($name)]} {
#
# Remove the tag row$opt-$data($name) from the given row
#
set line [expr {$row + 1}]
$w tag remove row$opt-$data($name) $line.0 $line.end
}
if {[string compare $val ""] == 0} {
if {[info exists data($name)]} {
unset data($name)
incr data(rowTagRefCount) -1
}
} else {
#
# Configure the tag row$opt-$val in the body text widget and
# apply it to the non-selected elements of the given row
#
set tag row$opt-$val
$w tag configure $tag $opt $val
$w tag lower $tag active
set line [expr {$row + 1}]
if {[llength [$w tag nextrange select $line.0 $line.end]]
== 0} {
$w tag add $tag $line.0 $line.end
} else {
set textIdx1 [expr {double($line)}]
for {set col 0} {$col < $data(colCount)} {incr col} {
if {$data($col-hide) && !$canElide} {
continue
}
set textIdx2 \
[$w search $elide "\t" $textIdx1+1c $line.end]+1c
if {[lsearch -exact [$w tag names $textIdx1] select]
< 0} {
$w tag add $tag $textIdx1 $textIdx2
}
set textIdx1 $textIdx2
}
}
#
# Save val in data($name)
#
if {![info exists data($name)]} {
incr data(rowTagRefCount)
}
set data($name) $val
}
if {!$data(isDisabled)} {
updateColorsWhenIdle $win
}
}
-elide {
set val [expr {$val ? 1 : 0}]
set item [lindex $data(itemList) $row]
set key [lindex $item end]
set name $key$opt
set line [expr {$row + 1}]
set viewChanged 0
if {$val} { ;# eliding the row
if {![info exists data($name)]} {
set data($name) 1
$w tag add elidedRow $line.0 $line.end+1c
if {![info exists data($key-hide)]} {
incr data(nonViewableRowCount)
set viewChanged 1
if {$row == $data(editRow)} {
doCancelEditing $win
}
}
}
} else { ;# uneliding the row
if {[info exists data($name)]} {
unset data($name)
$w tag remove elidedRow $line.0 $line.end+1c
if {![info exists data($key-hide)]} {
incr data(nonViewableRowCount) -1
set viewChanged 1
}
}
}
if {$viewChanged} {
#
# Adjust the heights of the body text widget
# and of the listbox child, if necessary
#
if {$data(-height) <= 0} {
set viewableRowCount \
[expr {$data(itemCount) - $data(nonViewableRowCount)}]
$w configure -height $viewableRowCount
$data(lb) configure -height $viewableRowCount
}
#
# Build the list of those dynamic-width columns
# whose widths are affected by (un)eliding the row
#
set colWidthsChanged 0
set colIdxList {}
set displayedItem [lrange $item 0 $data(lastCol)]
if {$data(hasFmtCmds)} {
set displayedItem [formatItem $win $key $row $displayedItem]
}
set col 0
foreach text [strToDispStr $displayedItem] \
{pixels alignment} $data(colList) {
if {($data($col-hide) && !$canElide) || $pixels != 0} {
incr col
continue
}
getAuxData $win $key $col auxType auxWidth
getIndentData $win $key $col indentWidth
set cellFont [getCellFont $win $key $col]
set elemWidth [getElemWidth $win $text $auxWidth \
$indentWidth $cellFont]
if {$val} { ;# eliding the row
if {$elemWidth == $data($col-elemWidth) &&
[incr data($col-widestCount) -1] == 0} {
set colWidthsChanged 1
lappend colIdxList $col
}
} else { ;# uneliding the row
if {$elemWidth == $data($col-elemWidth)} {
incr data($col-widestCount)
} elseif {$elemWidth > $data($col-elemWidth)} {
set data($col-elemWidth) $elemWidth
set data($col-widestCount) 1
if {$elemWidth > $data($col-reqPixels)} {
set data($col-reqPixels) $elemWidth
set colWidthsChanged 1
}
}
}
incr col
}
#
# Invalidate the list of row indices indicating the
# viewable rows and adjust the columns if necessary
#
set data(viewableRowList) {-1}
if {$colWidthsChanged} {
adjustColumns $win $colIdxList 1
}
}
}
-font {
#
# Save the current cell fonts in a temporary array
#
set item [lindex $data(itemList) $row]
set key [lindex $item end]
for {set col 0} {$col < $data(colCount)} {incr col} {
set oldCellFonts($col) [getCellFont $win $key $col]
}
set name $key$opt
if {[info exists data($name)]} {
#
# Remove the tag row$opt-$data($name) from the given row
#
set line [expr {$row + 1}]
$w tag remove row$opt-$data($name) $line.0 $line.end
}
if {[string compare $val ""] == 0} {
if {[info exists data($name)]} {
unset data($name)
incr data(rowTagRefCount) -1
}
} else {
#
# Configure the tag row$opt-$val in the body
# text widget and apply it to the given row
#
set tag row$opt-$val
$w tag configure $tag $opt $val
$w tag lower $tag active
set line [expr {$row + 1}]
$w tag add $tag $line.0 $line.end
#
# Save val in data($name)
#
if {![info exists data($name)]} {
incr data(rowTagRefCount)
}
set data($name) $val
}
set displayedItem [lrange $item 0 $data(lastCol)]
if {$data(hasFmtCmds)} {
set displayedItem [formatItem $win $key $row $displayedItem]
}
set colWidthsChanged 0
set colIdxList {}
set line [expr {$row + 1}]
set textIdx1 $line.1
set col 0
foreach text [strToDispStr $displayedItem] \
{pixels alignment} $data(colList) {
if {$data($col-hide) && !$canElide} {
incr col
continue
}
#
# Adjust the cell text and the image or window width
#
set multiline [string match "*\n*" $text]
set cellFont [getCellFont $win $key $col]
set workPixels $pixels
if {$pixels == 0} { ;# convention: dynamic width
set textSav $text
getAuxData $win $key $col auxType auxWidthSav
getIndentData $win $key $col indentWidthSav
if {$data($col-maxPixels) > 0} {
if {$data($col-reqPixels) > $data($col-maxPixels)} {
set workPixels $data($col-maxPixels)
}
}
}
set aux [getAuxData $win $key $col auxType auxWidth $workPixels]
set indent [getIndentData $win $key $col indentWidth]
set maxTextWidth $workPixels
if {$workPixels != 0} {
incr workPixels $data($col-delta)
set maxTextWidth \
[getMaxTextWidth $workPixels $auxWidth $indentWidth]
if {$data($col-wrap) && !$multiline} {
if {[font measure $cellFont -displayof $win $text] >
$maxTextWidth} {
set multiline 1
}
}
}
set snipSide $snipSides($alignment,$data($col-changesnipside))
if {$multiline} {
set list [split $text "\n"]
if {$data($col-wrap)} {
set snipSide ""
}
adjustMlElem $win list auxWidth indentWidth $cellFont \
$workPixels $snipSide $data(-snipstring)
set msgScript [list ::tablelist::displayText $win $key \
$col [join $list "\n"] $cellFont \
$maxTextWidth $alignment]
} else {
adjustElem $win text auxWidth indentWidth $cellFont \
$workPixels $snipSide $data(-snipstring)
}
if {$row == $data(editRow) && $col == $data(editCol)} {
#
# Configure the edit window
#
setEditWinFont $win
} else {
#
# Update the text widget's contents between the two tabs
#
set textIdx2 [$w search $elide "\t" $textIdx1 $line.end]
if {$multiline} {
updateMlCell $w $textIdx1 $textIdx2 $msgScript \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
} else {
updateCell $w $textIdx1 $textIdx2 $text \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
}
}
if {$pixels == 0 && ![info exists data($key-elide)] &&
![info exists data($key-hide)]} {
#
# Check whether the width of the current column has changed
#
set text $textSav
set auxWidth $auxWidthSav
set indentWidth $indentWidthSav
set newElemWidth [getElemWidth $win $text $auxWidth \
$indentWidth $cellFont]
if {$newElemWidth > $data($col-elemWidth)} {
set data($col-elemWidth) $newElemWidth
set data($col-widestCount) 1
if {$newElemWidth > $data($col-reqPixels)} {
set data($col-reqPixels) $newElemWidth
set colWidthsChanged 1
}
} else {
set oldElemWidth [getElemWidth $win $text $auxWidth \
$indentWidth $oldCellFonts($col)]
if {$oldElemWidth < $data($col-elemWidth) &&
$newElemWidth == $data($col-elemWidth)} {
incr data($col-widestCount)
} elseif {$oldElemWidth == $data($col-elemWidth) &&
$newElemWidth < $oldElemWidth &&
[incr data($col-widestCount) -1] == 0} {
set colWidthsChanged 1
lappend colIdxList $col
}
}
}
set textIdx1 [$w search $elide "\t" $textIdx1 $line.end]+2c
incr col
}
#
# Adjust the columns if necessary and schedule
# some operations for execution at idle time
#
if {$colWidthsChanged} {
adjustColumns $win $colIdxList 1
}
updateViewWhenIdle $win
}
-hide {
set val [expr {$val ? 1 : 0}]
set item [lindex $data(itemList) $row]
set key [lindex $item end]
set name $key$opt
set line [expr {$row + 1}]
set viewChanged 0
set callerProc [lindex [info level -1] 0]
if {$val} { ;# hiding the row
if {![info exists data($name)]} {
set data($name) 1
$w tag add hiddenRow $line.0 $line.end+1c
if {![info exists data($key-elide)]} {
incr data(nonViewableRowCount)
set viewChanged 1
#
# Elide the descendants of this item
#
set fromRow [expr {$row + 1}]
set toRow [nodeRow $win $key end]
for {set _row $fromRow} {$_row < $toRow} {incr _row} {
doRowConfig $_row $win -elide 1
}
if {[string match "*configureWidget" $callerProc]} {
adjustRowIndex $win data(anchorRow) 1
set activeRow $data(activeRow)
adjustRowIndex $win activeRow 1
set data(activeRow) $activeRow
}
if {$row == $data(editRow)} {
doCancelEditing $win
}
}
}
} else { ;# unhiding the row
if {[info exists data($name)]} {
unset data($name)
$w tag remove hiddenRow $line.0 $line.end+1c
if {![info exists data($key-elide)]} {
incr data(nonViewableRowCount) -1
set viewChanged 1
if {[info exists data($key,$data(treeCol)-indent)] &&
[string match "*expanded*" \
$data($key,$data(treeCol)-indent)]} {
expandSubCmd $win [list $row -partly]
}
}
}
}
if {$viewChanged} {
#
# Adjust the heights of the body text widget
# and of the listbox child, if necessary
#
if {$data(-height) <= 0} {
set viewableRowCount \
[expr {$data(itemCount) - $data(nonViewableRowCount)}]
$w configure -height $viewableRowCount
$data(lb) configure -height $viewableRowCount
}
#
# Build the list of those dynamic-width columns
# whose widths are affected by (un)hiding the row
#
set colWidthsChanged 0
set colIdxList {}
set displayedItem [lrange $item 0 $data(lastCol)]
if {$data(hasFmtCmds)} {
set displayedItem [formatItem $win $key $row $displayedItem]
}
set col 0
foreach text [strToDispStr $displayedItem] \
{pixels alignment} $data(colList) {
if {($data($col-hide) && !$canElide) || $pixels != 0} {
incr col
continue
}
getAuxData $win $key $col auxType auxWidth
getIndentData $win $key $col indentWidth
set cellFont [getCellFont $win $key $col]
set elemWidth [getElemWidth $win $text $auxWidth \
$indentWidth $cellFont]
if {$val} { ;# hiding the row
if {$elemWidth == $data($col-elemWidth) &&
[incr data($col-widestCount) -1] == 0} {
set colWidthsChanged 1
lappend colIdxList $col
}
} else { ;# unhiding the row
if {$elemWidth == $data($col-elemWidth)} {
incr data($col-widestCount)
} elseif {$elemWidth > $data($col-elemWidth)} {
set data($col-elemWidth) $elemWidth
set data($col-widestCount) 1
if {$elemWidth > $data($col-reqPixels)} {
set data($col-reqPixels) $elemWidth
set colWidthsChanged 1
}
}
}
incr col
}
#
# Invalidate the list of row indices indicating the
# viewable rows and adjust the columns if necessary
#
set data(viewableRowList) {-1}
if {$colWidthsChanged} {
adjustColumns $win $colIdxList 1
}
#
# Schedule some operations for execution at idle time
# and generate a virtual event only if the caller proc
# is configureWidget, in order to make sure that only
# one event per caller proc invocation will be generated
#
if {[string match "*configureWidget" $callerProc]} {
makeStripesWhenIdle $win
showLineNumbersWhenIdle $win
updateViewWhenIdle $win
event generate $win <<TablelistRowHiddenStateChanged>>
}
}
}
-name {
set key [lindex $data(keyList) $row]
if {[string compare $val ""] == 0} {
if {[info exists data($key$opt)]} {
unset data($key$opt)
}
} else {
set data($key$opt) $val
}
}
-selectable {
set val [expr {$val ? 1 : 0}]
set key [lindex $data(keyList) $row]
if {$val} {
if {[info exists data($key$opt)]} {
unset data($key$opt)
}
} else {
#
# Set data($key$opt) to 0 and deselect the row
#
set data($key$opt) 0
rowSelection $win clear $row $row
}
}
-selectbackground -
-selectforeground {
set key [lindex $data(keyList) $row]
set name $key$opt
if {[info exists data($name)]} {
#
# Remove the tag row$opt-$data($name) from the given row
#
set line [expr {$row + 1}]
$w tag remove row$opt-$data($name) $line.0 $line.end
}
if {[string compare $val ""] == 0} {
if {[info exists data($name)]} {
unset data($name)
}
} else {
#
# Configure the tag row$opt-$val in the body text widget
# and apply it to the selected elements of the given row
#
set tag row$opt-$val
set optTail [string range $opt 7 end] ;# remove the -select
$w tag configure $tag -$optTail $val
$w tag lower $tag active
set line [expr {$row + 1}]
set selRange [$w tag nextrange select $line.0 $line.end]
while {[llength $selRange] != 0} {
foreach {selStart selEnd} $selRange {}
$w tag add $tag $selStart $selEnd
set selRange [$w tag nextrange select $selEnd $line.end]
}
#
# Save val in data($name)
#
set data($name) [$w tag cget $tag -$optTail]
}
if {!$data(isDisabled)} {
updateColorsWhenIdle $win
}
}
-text {
if {$data(isDisabled)} {
return ""
}
set colWidthsChanged 0
set colIdxList {}
set oldItem [lindex $data(itemList) $row]
set key [lindex $oldItem end]
set newItem [adjustItem $val $data(colCount)]
if {$data(hasFmtCmds)} {
set displayedItem [formatItem $win $key $row $newItem]
} else {
set displayedItem $newItem
}
set line [expr {$row + 1}]
set textIdx1 $line.1
set col 0
foreach text [strToDispStr $displayedItem] \
{pixels alignment} $data(colList) {
if {$data($col-hide) && !$canElide} {
incr col
continue
}
#
# Adjust the cell text and the image or window width
#
set multiline [string match "*\n*" $text]
set cellFont [getCellFont $win $key $col]
set workPixels $pixels
if {$pixels == 0} { ;# convention: dynamic width
set textSav $text
getAuxData $win $key $col auxType auxWidthSav
getIndentData $win $key $col indentWidthSav
if {$data($col-maxPixels) > 0} {
if {$data($col-reqPixels) > $data($col-maxPixels)} {
set workPixels $data($col-maxPixels)
}
}
}
set aux [getAuxData $win $key $col auxType auxWidth $workPixels]
set indent [getIndentData $win $key $col indentWidth]
set maxTextWidth $workPixels
if {$workPixels != 0} {
incr workPixels $data($col-delta)
set maxTextWidth \
[getMaxTextWidth $workPixels $auxWidth $indentWidth]
if {$data($col-wrap) && !$multiline} {
if {[font measure $cellFont -displayof $win $text] >
$maxTextWidth} {
set multiline 1
}
}
}
set snipSide $snipSides($alignment,$data($col-changesnipside))
if {$multiline} {
set list [split $text "\n"]
if {$data($col-wrap)} {
set snipSide ""
}
adjustMlElem $win list auxWidth indentWidth $cellFont \
$workPixels $snipSide $data(-snipstring)
set msgScript [list ::tablelist::displayText $win $key \
$col [join $list "\n"] $cellFont \
$maxTextWidth $alignment]
} else {
adjustElem $win text auxWidth indentWidth $cellFont \
$workPixels $snipSide $data(-snipstring)
}
if {$row != $data(editRow) || $col != $data(editCol)} {
#
# Update the text widget's contents between the two tabs
#
set textIdx2 [$w search $elide "\t" $textIdx1 $line.end]
if {$multiline} {
updateMlCell $w $textIdx1 $textIdx2 $msgScript \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
} else {
updateCell $w $textIdx1 $textIdx2 $text \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
}
}
if {$pixels == 0 && ![info exists data($key-elide)] &&
![info exists data($key-hide)]} {
#
# Check whether the width of the current column has changed
#
set text $textSav
set auxWidth $auxWidthSav
set indentWidth $indentWidthSav
set newElemWidth [getElemWidth $win $text $auxWidth \
$indentWidth $cellFont]
if {$newElemWidth > $data($col-elemWidth)} {
set data($col-elemWidth) $newElemWidth
set data($col-widestCount) 1
if {$newElemWidth > $data($col-reqPixels)} {
set data($col-reqPixels) $newElemWidth
set colWidthsChanged 1
}
} else {
set oldText [lindex $oldItem $col]
if {[lindex $data(fmtCmdFlagList) $col]} {
set oldText \
[formatElem $win $key $row $col $oldText]
}
set oldText [strToDispStr $oldText]
set oldElemWidth [getElemWidth $win $oldText $auxWidth \
$indentWidth $cellFont]
if {$oldElemWidth < $data($col-elemWidth) &&
$newElemWidth == $data($col-elemWidth)} {
incr data($col-widestCount)
} elseif {$oldElemWidth == $data($col-elemWidth) &&
$newElemWidth < $oldElemWidth &&
[incr data($col-widestCount) -1] == 0} {
set colWidthsChanged 1
lappend colIdxList $col
}
}
}
set textIdx1 [$w search $elide "\t" $textIdx1 $line.end]+2c
incr col
}
#
# Replace the row contents in the list variable if present
#
if {$data(hasListVar)} {
upvar #0 $data(-listvariable) var
trace vdelete var wu $data(listVarTraceCmd)
set var [lreplace $var $row $row $newItem]
trace variable var wu $data(listVarTraceCmd)
}
#
# Replace the row contents in the internal list
#
lappend newItem $key
set data(itemList) [lreplace $data(itemList) $row $row $newItem]
#
# Adjust the columns if necessary and schedule
# some operations for execution at idle time
#
if {$colWidthsChanged} {
adjustColumns $win $colIdxList 1
}
showLineNumbersWhenIdle $win
updateViewWhenIdle $win
}
}
}
#------------------------------------------------------------------------------
# tablelist::doRowCget
#
# Returns the value of the row configuration option opt for the row'th row of
# the tablelist widget win.
#------------------------------------------------------------------------------
proc tablelist::doRowCget {row win opt} {
upvar ::tablelist::ns${win}::data data
#
# Return the value of the specified row configuration option
#
set item [lindex $data(itemList) $row]
switch -- $opt {
-text {
return [lrange $item 0 $data(lastCol)]
}
-elide -
-hide {
set key [lindex $item end]
if {[info exists data($key$opt)]} {
return $data($key$opt)
} else {
return 0
}
}
-selectable {
set key [lindex $item end]
if {[info exists data($key$opt)]} {
return $data($key$opt)
} else {
return 1
}
}
default {
set key [lindex $item end]
if {[info exists data($key$opt)]} {
return $data($key$opt)
} else {
return ""
}
}
}
}
#------------------------------------------------------------------------------
# tablelist::doCellConfig
#
# Applies the value val of the cell configuration option opt to the cell
# row,col of the tablelist widget win.
#------------------------------------------------------------------------------
proc tablelist::doCellConfig {row col win opt val} {
variable canElide
variable snipSides
upvar ::tablelist::ns${win}::data data
set w $data(body)
switch -- $opt {
-background -
-foreground {
set key [lindex $data(keyList) $row]
set name $key,$col$opt
if {[info exists data($name)] &&
(!$data($col-hide) || $canElide)} {
#
# Remove the tag cell$opt-$data($name) from the given cell
#
findTabs $win [expr {$row + 1}] $col $col tabIdx1 tabIdx2
$w tag remove cell$opt-$data($name) $tabIdx1 $tabIdx2+1c
}
if {[string compare $val ""] == 0} {
if {[info exists data($name)]} {
unset data($name)
incr data(cellTagRefCount) -1
}
} else {
#
# Configure the tag cell$opt-$val in the body text widget
#
set tag cell$opt-$val
$w tag configure $tag $opt $val
$w tag lower $tag disabled
if {!$data($col-hide) || $canElide} {
#
# Apply the tag to the given cell if it is not selected
#
findTabs $win [expr {$row + 1}] $col $col tabIdx1 tabIdx2
if {[lsearch -exact [$w tag names $tabIdx1] select] < 0} {
$w tag add $tag $tabIdx1 $tabIdx2+1c
}
}
#
# Save val in data($name)
#
if {![info exists data($name)]} {
incr data(cellTagRefCount)
}
set data($name) $val
}
if {!$data(isDisabled)} {
updateColorsWhenIdle $win
}
}
-editable {
#
# Save the boolean value specified by val in data($key,$col$opt)
#
set key [lindex $data(keyList) $row]
set data($key,$col$opt) [expr {$val ? 1 : 0}]
}
-editwindow {
variable editWin
if {[info exists editWin($val-creationCmd)]} {
set key [lindex $data(keyList) $row]
set data($key,$col$opt) $val
} else {
return -code error "name \"$val\" is not registered\
for interactive cell editing"
}
}
-font {
#
# Save the current cell font
#
set item [lindex $data(itemList) $row]
set key [lindex $item end]
set name $key,$col$opt
set oldCellFont [getCellFont $win $key $col]
if {[info exists data($name)] &&
(!$data($col-hide) || $canElide)} {
#
# Remove the tag cell$opt-$data($name) from the given cell
#
findTabs $win [expr {$row + 1}] $col $col tabIdx1 tabIdx2
$w tag remove cell$opt-$data($name) $tabIdx1 $tabIdx2+1c
}
if {[string compare $val ""] == 0} {
if {[info exists data($name)]} {
unset data($name)
incr data(cellTagRefCount) -1
}
} else {
#
# Configure the tag cell$opt-$val in the body text widget
#
set tag cell$opt-$val
$w tag configure $tag $opt $val
$w tag lower $tag disabled
if {!$data($col-hide) || $canElide} {
#
# Apply the tag to the given cell
#
findTabs $win [expr {$row + 1}] $col $col tabIdx1 tabIdx2
$w tag add $tag $tabIdx1 $tabIdx2+1c
}
#
# Save val in data($name)
#
if {![info exists data($name)]} {
incr data(cellTagRefCount)
}
set data($name) $val
}
#
# Adjust the cell text and the image or window width
#
set text [lindex $item $col]
if {[lindex $data(fmtCmdFlagList) $col]} {
set text [formatElem $win $key $row $col $text]
}
set text [strToDispStr $text]
set multiline [string match "*\n*" $text]
set cellFont [getCellFont $win $key $col]
set pixels [lindex $data(colList) [expr {2*$col}]]
set workPixels $pixels
if {$pixels == 0} { ;# convention: dynamic width
set textSav $text
getAuxData $win $key $col auxType auxWidthSav
getIndentData $win $key $col indentWidthSav
if {$data($col-maxPixels) > 0} {
if {$data($col-reqPixels) > $data($col-maxPixels)} {
set workPixels $data($col-maxPixels)
}
}
}
set aux [getAuxData $win $key $col auxType auxWidth $workPixels]
set indent [getIndentData $win $key $col indentWidth]
set maxTextWidth $workPixels
if {$workPixels != 0} {
incr workPixels $data($col-delta)
set maxTextWidth \
[getMaxTextWidth $workPixels $auxWidth $indentWidth]
if {$data($col-wrap) && !$multiline} {
if {[font measure $cellFont -displayof $win $text] >
$maxTextWidth} {
set multiline 1
}
}
}
set alignment [lindex $data(colList) [expr {2*$col + 1}]]
set snipSide $snipSides($alignment,$data($col-changesnipside))
if {$multiline} {
set list [split $text "\n"]
if {$data($col-wrap)} {
set snipSide ""
}
adjustMlElem $win list auxWidth indentWidth $cellFont \
$workPixels $snipSide $data(-snipstring)
set msgScript [list ::tablelist::displayText $win $key \
$col [join $list "\n"] $cellFont \
$maxTextWidth $alignment]
} else {
adjustElem $win text auxWidth indentWidth $cellFont \
$workPixels $snipSide $data(-snipstring)
}
if {!$data($col-hide)} {
if {$row == $data(editRow) && $col == $data(editCol)} {
#
# Configure the edit window
#
setEditWinFont $win
} else {
#
# Update the text widget's contents between the two tabs
#
findTabs $win [expr {$row + 1}] $col $col tabIdx1 tabIdx2
if {$multiline} {
updateMlCell $w $tabIdx1+1c $tabIdx2 $msgScript \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
} else {
updateCell $w $tabIdx1+1c $tabIdx2 $text \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
}
}
}
#
# Adjust the columns if necessary
#
if {$pixels == 0 && ![info exists data($key-elide)] &&
![info exists data($key-hide)]} {
set text $textSav
set auxWidth $auxWidthSav
set indentWidth $indentWidthSav
set newElemWidth [getElemWidth $win $text $auxWidth \
$indentWidth $cellFont]
if {$newElemWidth > $data($col-elemWidth)} {
set data($col-elemWidth) $newElemWidth
set data($col-widestCount) 1
if {$newElemWidth > $data($col-reqPixels)} {
set data($col-reqPixels) $newElemWidth
adjustColumns $win {} 1
}
} else {
set oldElemWidth [getElemWidth $win $text $auxWidth \
$indentWidth $oldCellFont]
if {$oldElemWidth < $data($col-elemWidth) &&
$newElemWidth == $data($col-elemWidth)} {
incr data($col-widestCount)
} elseif {$oldElemWidth == $data($col-elemWidth) &&
$newElemWidth < $oldElemWidth &&
[incr data($col-widestCount) -1] == 0} {
adjustColumns $win $col 1
}
}
}
updateViewWhenIdle $win
}
-image {
if {$data(isDisabled)} {
return ""
}
#
# Save the old image or window width
#
set item [lindex $data(itemList) $row]
set key [lindex $item end]
set name $key,$col$opt
getAuxData $win $key $col oldAuxType oldAuxWidth
#
# Delete data($name) or save the specified value in it
#
if {[string compare $val ""] == 0} {
if {[info exists data($name)]} {
unset data($name)
incr data(imgCount) -1
}
} else {
if {![info exists data($name)]} {
incr data(imgCount)
}
set imgLabel $w.img_$key,$col
if {[winfo exists $imgLabel] &&
[string compare $val $data($name)] != 0} {
destroy $imgLabel
}
set data($name) $val
}
#
# Adjust the cell text and the image or window width
#
set pixels [lindex $data(colList) [expr {2*$col}]]
set workPixels $pixels
set text [lindex $item $col]
if {[lindex $data(fmtCmdFlagList) $col]} {
set text [formatElem $win $key $row $col $text]
}
set text [strToDispStr $text]
set oldText $text
set multiline [string match "*\n*" $text]
set cellFont [getCellFont $win $key $col]
if {$pixels == 0} { ;# convention: dynamic width
set textSav $text
getAuxData $win $key $col auxType auxWidthSav
getIndentData $win $key $col indentWidthSav
if {$data($col-maxPixels) > 0} {
if {$data($col-reqPixels) > $data($col-maxPixels)} {
set workPixels $data($col-maxPixels)
}
}
}
set aux [getAuxData $win $key $col auxType auxWidth $workPixels]
set indent [getIndentData $win $key $col indentWidth]
set maxTextWidth $workPixels
if {$workPixels != 0} {
incr workPixels $data($col-delta)
set maxTextWidth \
[getMaxTextWidth $workPixels $auxWidth $indentWidth]
if {$data($col-wrap) && !$multiline} {
if {[font measure $cellFont -displayof $win $text] >
$maxTextWidth} {
set multiline 1
}
}
}
set alignment [lindex $data(colList) [expr {2*$col + 1}]]
set snipSide $snipSides($alignment,$data($col-changesnipside))
if {$multiline} {
set list [split $text "\n"]
if {$data($col-wrap)} {
set snipSide ""
}
adjustMlElem $win list auxWidth indentWidth $cellFont \
$workPixels $snipSide $data(-snipstring)
set msgScript [list ::tablelist::displayText $win $key \
$col [join $list "\n"] $cellFont \
$maxTextWidth $alignment]
} else {
adjustElem $win text auxWidth indentWidth $cellFont \
$workPixels $snipSide $data(-snipstring)
}
if {(!$data($col-hide) || $canElide) &&
!($row == $data(editRow) && $col == $data(editCol))} {
#
# Delete the old cell contents between the two tabs,
# and insert the text and the auxiliary object
#
findTabs $win [expr {$row + 1}] $col $col tabIdx1 tabIdx2
if {$multiline} {
updateMlCell $w $tabIdx1+1c $tabIdx2 $msgScript \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
} else {
updateCell $w $tabIdx1+1c $tabIdx2 $text \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
}
}
#
# Adjust the columns if necessary
#
if {$pixels == 0 && ![info exists data($key-elide)] &&
![info exists data($key-hide)]} {
set text $textSav
set auxWidth $auxWidthSav
set indentWidth $indentWidthSav
set newElemWidth [getElemWidth $win $text $auxWidth \
$indentWidth $cellFont]
if {$newElemWidth > $data($col-elemWidth)} {
set data($col-elemWidth) $newElemWidth
set data($col-widestCount) 1
if {$newElemWidth > $data($col-reqPixels)} {
set data($col-reqPixels) $newElemWidth
adjustColumns $win {} 1
}
} else {
set oldElemWidth [getElemWidth $win $oldText $oldAuxWidth \
$indentWidth $cellFont]
if {$oldElemWidth < $data($col-elemWidth) &&
$newElemWidth == $data($col-elemWidth)} {
incr data($col-widestCount)
} elseif {$oldElemWidth == $data($col-elemWidth) &&
$newElemWidth < $oldElemWidth &&
[incr data($col-widestCount) -1] == 0} {
adjustColumns $win $col 1
}
}
}
updateViewWhenIdle $win
}
-indent {
if {$data(isDisabled)} {
return ""
}
#
# Save the old indentation width
#
set item [lindex $data(itemList) $row]
set key [lindex $item end]
set name $key,$col$opt
getIndentData $win $key $col oldIndentWidth
#
# Delete data($name) or save the specified value in it
#
if {[string compare $val ""] == 0} {
if {[info exists data($name)]} {
unset data($name)
incr data(indentCount) -1
}
} else {
if {![info exists data($name)]} {
incr data(indentCount)
}
set indentLabel $w.ind_$key,$col
if {[winfo exists $indentLabel] &&
[string compare $val $data($name)] != 0} {
destroy $indentLabel
}
set data($name) $val
}
#
# Adjust the cell text and the image or window width
#
set pixels [lindex $data(colList) [expr {2*$col}]]
set workPixels $pixels
set text [lindex $item $col]
if {[lindex $data(fmtCmdFlagList) $col]} {
set text [formatElem $win $key $row $col $text]
}
set text [strToDispStr $text]
set oldText $text
set multiline [string match "*\n*" $text]
set cellFont [getCellFont $win $key $col]
if {$pixels == 0} { ;# convention: dynamic width
set textSav $text
getAuxData $win $key $col auxType auxWidthSav
getIndentData $win $key $col indentWidthSav
if {$data($col-maxPixels) > 0} {
if {$data($col-reqPixels) > $data($col-maxPixels)} {
set workPixels $data($col-maxPixels)
}
}
}
set aux [getAuxData $win $key $col auxType auxWidth $workPixels]
set indent [getIndentData $win $key $col indentWidth]
set maxTextWidth $workPixels
if {$workPixels != 0} {
incr workPixels $data($col-delta)
set maxTextWidth \
[getMaxTextWidth $workPixels $auxWidth $indentWidth]
if {$data($col-wrap) && !$multiline} {
if {[font measure $cellFont -displayof $win $text] >
$maxTextWidth} {
set multiline 1
}
}
}
set alignment [lindex $data(colList) [expr {2*$col + 1}]]
set snipSide $snipSides($alignment,$data($col-changesnipside))
if {$multiline} {
set list [split $text "\n"]
if {$data($col-wrap)} {
set snipSide ""
}
adjustMlElem $win list auxWidth indentWidth $cellFont \
$workPixels $snipSide $data(-snipstring)
set msgScript [list ::tablelist::displayText $win $key \
$col [join $list "\n"] $cellFont \
$maxTextWidth $alignment]
} else {
adjustElem $win text auxWidth indentWidth $cellFont \
$workPixels $snipSide $data(-snipstring)
}
if {(!$data($col-hide) || $canElide) &&
!($row == $data(editRow) && $col == $data(editCol))} {
#
# Delete the old cell contents between the two tabs,
# and insert the text and the auxiliary object
#
findTabs $win [expr {$row + 1}] $col $col tabIdx1 tabIdx2
if {$multiline} {
updateMlCell $w $tabIdx1+1c $tabIdx2 $msgScript \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
} else {
updateCell $w $tabIdx1+1c $tabIdx2 $text \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
}
}
#
# Adjust the columns if necessary
#
if {$pixels == 0 && ![info exists data($key-elide)] &&
![info exists data($key-hide)]} {
set text $textSav
set auxWidth $auxWidthSav
set indentWidth $indentWidthSav
set newElemWidth [getElemWidth $win $text $auxWidth \
$indentWidth $cellFont]
if {$newElemWidth > $data($col-elemWidth)} {
set data($col-elemWidth) $newElemWidth
set data($col-widestCount) 1
if {$newElemWidth > $data($col-reqPixels)} {
set data($col-reqPixels) $newElemWidth
adjustColumns $win {} 1
}
} else {
set oldElemWidth [getElemWidth $win $oldText $auxWidth \
$oldIndentWidth $cellFont]
if {$oldElemWidth < $data($col-elemWidth) &&
$newElemWidth == $data($col-elemWidth)} {
incr data($col-widestCount)
} elseif {$oldElemWidth == $data($col-elemWidth) &&
$newElemWidth < $oldElemWidth &&
[incr data($col-widestCount) -1] == 0} {
adjustColumns $win $col 1
}
}
}
updateViewWhenIdle $win
}
-selectbackground -
-selectforeground {
set key [lindex $data(keyList) $row]
set name $key,$col$opt
if {[info exists data($name)] &&
(!$data($col-hide) || $canElide)} {
#
# Remove the tag cell$opt-$data($name) from the given cell
#
findTabs $win [expr {$row + 1}] $col $col tabIdx1 tabIdx2
$w tag remove cell$opt-$data($name) $tabIdx1 $tabIdx2+1c
}
if {[string compare $val ""] == 0} {
if {[info exists data($name)]} {
unset data($name)
}
} else {
#
# Configure the tag cell$opt-$val in the body text widget
#
set tag cell$opt-$val
set optTail [string range $opt 7 end] ;# remove the -select
$w tag configure $tag -$optTail $val
$w tag lower $tag disabled
if {!$data($col-hide) || $canElide} {
#
# Apply the tag to the given cell if it is selected
#
findTabs $win [expr {$row + 1}] $col $col tabIdx1 tabIdx2
if {[lsearch -exact [$w tag names $tabIdx1] select] >= 0} {
$w tag add $tag $tabIdx1 $tabIdx2+1c
}
}
#
# Save val in data($name)
#
set data($name) $val
}
if {!$data(isDisabled)} {
updateColorsWhenIdle $win
}
}
-stretchwindow {
#
# Save the boolean value specified by val in data($key,$col$opt)
#
set item [lindex $data(itemList) $row]
set key [lindex $item end]
set name $key,$col$opt
if {$val} {
set data($name) 1
} elseif {[info exists data($name)]} {
unset data($name)
}
if {($data($col-hide) && !$canElide) ||
($row == $data(editRow) && $col == $data(editCol))} {
return ""
}
set pixels [lindex $data(colList) [expr {2*$col}]]
set text [lindex $item $col]
if {[lindex $data(fmtCmdFlagList) $col]} {
set text [formatElem $win $key $row $col $text]
}
set text [strToDispStr $text]
set multiline [string match "*\n*" $text]
set cellFont [getCellFont $win $key $col]
if {$pixels == 0} { ;# convention: dynamic width
if {$data($col-maxPixels) > 0} {
if {$data($col-reqPixels) > $data($col-maxPixels)} {
set pixels $data($col-maxPixels)
}
}
}
set aux [getAuxData $win $key $col auxType auxWidth $pixels]
set indent [getIndentData $win $key $col indentWidth]
set maxTextWidth $pixels
if {$pixels != 0} {
incr pixels $data($col-delta)
set maxTextWidth \
[getMaxTextWidth $pixels $auxWidth $indentWidth]
if {$data($col-wrap) && !$multiline} {
if {[font measure $cellFont -displayof $win $text] >
$maxTextWidth} {
set multiline 1
}
}
}
if {$auxType < 2} { ;# no window
return ""
}
#
# Adjust the cell text and the window width
#
set alignment [lindex $data(colList) [expr {2*$col + 1}]]
set snipSide $snipSides($alignment,$data($col-changesnipside))
if {$multiline} {
set list [split $text "\n"]
if {$data($col-wrap)} {
set snipSide ""
}
adjustMlElem $win list auxWidth indentWidth $cellFont \
$pixels $snipSide $data(-snipstring)
set msgScript [list ::tablelist::displayText $win $key $row \
[join $list "\n"] $cellFont \
$maxTextWidth $alignment]
} else {
adjustElem $win text auxWidth indentWidth $cellFont \
$pixels $snipSide $data(-snipstring)
}
#
# Update the text widget's contents between the two tabs
#
findTabs $win [expr {$row + 1}] $col $col tabIdx1 tabIdx2
if {$multiline} {
updateMlCell $w $tabIdx1+1c $tabIdx2 $msgScript \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
} else {
updateCell $w $tabIdx1+1c $tabIdx2 $text \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
}
}
-text {
if {$data(isDisabled)} {
return ""
}
set pixels [lindex $data(colList) [expr {2*$col}]]
set workPixels $pixels
set text $val
set oldItem [lindex $data(itemList) $row]
set key [lindex $oldItem end]
set fmtCmdFlag [lindex $data(fmtCmdFlagList) $col]
if {$fmtCmdFlag} {
set text [formatElem $win $key $row $col $text]
}
set text [strToDispStr $text]
set textSav $text
set multiline [string match "*\n*" $text]
set cellFont [getCellFont $win $key $col]
if {$pixels == 0} { ;# convention: dynamic width
getAuxData $win $key $col auxType auxWidthSav
getIndentData $win $key $col indentWidthSav
if {$data($col-maxPixels) > 0} {
if {$data($col-reqPixels) > $data($col-maxPixels)} {
set workPixels $data($col-maxPixels)
}
}
}
set aux [getAuxData $win $key $col auxType auxWidth $workPixels]
set indent [getIndentData $win $key $col indentWidth]
set maxTextWidth $workPixels
if {$workPixels != 0} {
incr workPixels $data($col-delta)
set maxTextWidth \
[getMaxTextWidth $workPixels $auxWidth $indentWidth]
if {$data($col-wrap) && !$multiline} {
if {[font measure $cellFont -displayof $win $text] >
$maxTextWidth} {
set multiline 1
}
}
}
set alignment [lindex $data(colList) [expr {2*$col + 1}]]
#
# Adjust the cell text and the image or window width
#
set snipSide $snipSides($alignment,$data($col-changesnipside))
if {$multiline} {
set list [split $text "\n"]
if {$data($col-wrap)} {
set snipSide ""
}
adjustMlElem $win list auxWidth indentWidth $cellFont \
$workPixels $snipSide $data(-snipstring)
set msgScript [list ::tablelist::displayText $win $key \
$col [join $list "\n"] $cellFont \
$maxTextWidth $alignment]
} else {
adjustElem $win text auxWidth indentWidth $cellFont \
$workPixels $snipSide $data(-snipstring)
}
if {(!$data($col-hide) || $canElide) &&
!($row == $data(editRow) && $col == $data(editCol))} {
#
# Update the text widget's contents between the two tabs
#
findTabs $win [expr {$row + 1}] $col $col tabIdx1 tabIdx2
if {$multiline} {
updateMlCell $w $tabIdx1+1c $tabIdx2 $msgScript \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
} else {
updateCell $w $tabIdx1+1c $tabIdx2 $text \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
}
}
#
# Replace the cell contents in the internal list
#
set newItem [lreplace $oldItem $col $col $val]
set data(itemList) [lreplace $data(itemList) $row $row $newItem]
#
# Replace the cell contents in the list variable if present
#
if {$data(hasListVar)} {
upvar #0 $data(-listvariable) var
trace vdelete var wu $data(listVarTraceCmd)
set var [lreplace $var $row $row \
[lrange $newItem 0 $data(lastCol)]]
trace variable var wu $data(listVarTraceCmd)
}
#
# Adjust the columns if necessary
#
if {$pixels == 0 && ![info exists data($key-elide)] &&
![info exists data($key-hide)]} {
set text $textSav
set auxWidth $auxWidthSav
set indentWidth $indentWidthSav
set newElemWidth [getElemWidth $win $text $auxWidth \
$indentWidth $cellFont]
if {$newElemWidth > $data($col-elemWidth)} {
set data($col-elemWidth) $newElemWidth
set data($col-widestCount) 1
if {$newElemWidth > $data($col-reqPixels)} {
set data($col-reqPixels) $newElemWidth
adjustColumns $win {} 1
}
} else {
set oldText [lindex $oldItem $col]
if {$fmtCmdFlag} {
set oldText [formatElem $win $key $row $col $oldText]
}
set oldText [strToDispStr $oldText]
set oldElemWidth [getElemWidth $win $oldText $auxWidth \
$indentWidth $cellFont]
if {$oldElemWidth < $data($col-elemWidth) &&
$newElemWidth == $data($col-elemWidth)} {
incr data($col-widestCount)
} elseif {$oldElemWidth == $data($col-elemWidth) &&
$newElemWidth < $oldElemWidth &&
[incr data($col-widestCount) -1] == 0} {
adjustColumns $win $col 1
}
}
}
showLineNumbersWhenIdle $win
updateViewWhenIdle $win
}
-window {
if {$data(isDisabled)} {
return ""
}
#
# Save the old image or window width
#
set item [lindex $data(itemList) $row]
set key [lindex $item end]
set name $key,$col$opt
getAuxData $win $key $col oldAuxType oldAuxWidth
getIndentData $win $key $col oldIndentWidth
#
# Delete data($name) or save the specified value in it
#
if {[string compare $val ""] == 0} {
if {[info exists data($name)]} {
unset data($name)
unset data($key,$col-reqWidth)
unset data($key,$col-reqHeight)
#
# If the cell index is contained in the list
# data(cellsToReconfig) then remove it from the list
#
set n [lsearch -exact $data(cellsToReconfig) $row,$col]
if {$n >= 0} {
set data(cellsToReconfig) \
[lreplace $data(cellsToReconfig) $n $n]
}
incr data(winCount) -1
}
} else {
if {![info exists data($name)]} {
incr data(winCount)
}
set aux $w.frm_$key,$col
set existsAux [winfo exists $aux]
if {[info exists data($name)] &&
[string compare $val $data($name)] != 0} {
destroy $aux
}
if {![winfo exists $aux]} {
#
# Create the frame and evaluate the specified script
# that creates a child widget within the frame
#
tk::frame $aux -borderwidth 0 -class TablelistWindow \
-container 0 -highlightthickness 0 \
-relief flat -takefocus 0
catch {$aux configure -padx 0 -pady 0}
bindtags $aux [linsert [bindtags $aux] 1 \
$data(bodyTag) TablelistBody]
uplevel #0 $val [list $win $row $col $aux.w]
}
set data($name) $val
set data($key,$col-reqWidth) [winfo reqwidth $aux.w]
set data($key,$col-reqHeight) [winfo reqheight $aux.w]
$aux configure -height $data($key,$col-reqHeight)
#
# Add the cell index to the list data(cellsToReconfig) if
# the window's requested width or height is not yet known
#
if {($data($key,$col-reqWidth) == 1 ||
$data($key,$col-reqHeight) == 1) &&
[lsearch -exact $data(cellsToReconfig) $row,$col] < 0} {
lappend data(cellsToReconfig) $row,$col
if {![info exists data(reconfigId)]} {
set data(reconfigId) \
[after idle [list tablelist::reconfigWindows $win]]
}
}
}
#
# Adjust the cell text and the image or window width
#
set pixels [lindex $data(colList) [expr {2*$col}]]
set workPixels $pixels
set text [lindex $item $col]
if {[lindex $data(fmtCmdFlagList) $col]} {
set text [formatElem $win $key $row $col $text]
}
set text [strToDispStr $text]
set oldText $text
set multiline [string match "*\n*" $text]
set cellFont [getCellFont $win $key $col]
if {$pixels == 0} { ;# convention: dynamic width
set textSav $text
getAuxData $win $key $col auxType auxWidthSav
getIndentData $win $key $col indentWidthSav
if {$data($col-maxPixels) > 0} {
if {$data($col-reqPixels) > $data($col-maxPixels)} {
set workPixels $data($col-maxPixels)
}
}
}
set aux [getAuxData $win $key $col auxType auxWidth $workPixels]
set indent [getIndentData $win $key $col indentWidth]
set maxTextWidth $workPixels
if {$workPixels != 0} {
incr workPixels $data($col-delta)
set maxTextWidth \
[getMaxTextWidth $workPixels $auxWidth $indentWidth]
if {$data($col-wrap) && !$multiline} {
if {[font measure $cellFont -displayof $win $text] >
$maxTextWidth} {
set multiline 1
}
}
}
set alignment [lindex $data(colList) [expr {2*$col + 1}]]
set snipSide $snipSides($alignment,$data($col-changesnipside))
if {$multiline} {
set list [split $text "\n"]
if {$data($col-wrap)} {
set snipSide ""
}
adjustMlElem $win list auxWidth indentWidth $cellFont \
$workPixels $snipSide $data(-snipstring)
set msgScript [list ::tablelist::displayText $win $key \
$col [join $list "\n"] $cellFont \
$maxTextWidth $alignment]
} else {
adjustElem $win text auxWidth indentWidth $cellFont \
$workPixels $snipSide $data(-snipstring)
}
if {(!$data($col-hide) || $canElide) &&
!($row == $data(editRow) && $col == $data(editCol))} {
#
# Delete the old cell contents between the two tabs,
# and insert the text and the auxiliary object
#
findTabs $win [expr {$row + 1}] $col $col tabIdx1 tabIdx2
if {$multiline} {
updateMlCell $w $tabIdx1+1c $tabIdx2 $msgScript \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
} else {
updateCell $w $tabIdx1+1c $tabIdx2 $text \
$aux $auxType $auxWidth \
$indent $indentWidth $alignment
}
}
#
# Adjust the columns if necessary
#
if {$pixels == 0 && ![info exists data($key-elide)] &&
![info exists data($key-hide)]} {
set text $textSav
set auxWidth $auxWidthSav
set indentWidth $indentWidthSav
set newElemWidth [getElemWidth $win $text $auxWidth \
$indentWidth $cellFont]
if {$newElemWidth > $data($col-elemWidth)} {
set data($col-elemWidth) $newElemWidth
set data($col-widestCount) 1
if {$newElemWidth > $data($col-reqPixels)} {
set data($col-reqPixels) $newElemWidth
adjustColumns $win {} 1
}
} else {
set oldElemWidth [getElemWidth $win $oldText $oldAuxWidth \
$oldIndentWidth $cellFont]
if {$oldElemWidth < $data($col-elemWidth) &&
$newElemWidth == $data($col-elemWidth)} {
incr data($col-widestCount)
} elseif {$oldElemWidth == $data($col-elemWidth) &&
$newElemWidth < $oldElemWidth &&
[incr data($col-widestCount) -1] == 0} {
adjustColumns $win $col 1
}
}
}
updateViewWhenIdle $win
}
-windowdestroy {
set key [lindex $data(keyList) $row]
set name $key,$col$opt
#
# Delete data($name) or save the specified value in it
#
if {[string compare $val ""] == 0} {
if {[info exists data($name)]} {
unset data($name)
}
} else {
set data($name) $val
}
}
}
}
#------------------------------------------------------------------------------
# tablelist::doCellCget
#
# Returns the value of the cell configuration option opt for the cell row,col
# of the tablelist widget win.
#------------------------------------------------------------------------------
proc tablelist::doCellCget {row col win opt} {
upvar ::tablelist::ns${win}::data data
#
# Return the value of the specified cell configuration option
#
switch -- $opt {
-editable {
return [isCellEditable $win $row $col]
}
-editwindow {
return [getEditWindow $win $row $col]
}
-stretchwindow {
set key [lindex $data(keyList) $row]
if {[info exists data($key,$col$opt)]} {
return $data($key,$col$opt)
} else {
return 0
}
}
-text {
return [lindex [lindex $data(itemList) $row] $col]
}
default {
set key [lindex $data(keyList) $row]
if {[info exists data($key,$col$opt)]} {
return $data($key,$col$opt)
} else {
return ""
}
}
}
}
#------------------------------------------------------------------------------
# tablelist::makeListVar
#
# Arranges for the global variable specified by varName to become the list
# variable associated with the tablelist widget win.
#------------------------------------------------------------------------------
proc tablelist::makeListVar {win varName} {
upvar ::tablelist::ns${win}::data data
if {[string compare $varName ""] == 0} {
#
# If there is an old list variable associated with the
# widget then remove the trace set on this variable
#
if {$data(hasListVar)} {
synchronize $win
upvar #0 $data(-listvariable) var
trace vdelete var wu $data(listVarTraceCmd)
}
return ""
}
#
# The list variable may be an array element but must not be an array
#
if {![regexp {^(.*)\((.*)\)$} $varName dummy name1 name2]} {
if {[array exists $varName]} {
return -code error "variable \"$varName\" is array"
}
set name1 $varName
set name2 ""
}
#
# If there is an old list variable associated with the
# widget then remove the trace set on this variable
#
if {$data(hasListVar)} {
synchronize $win
upvar #0 $data(-listvariable) var
trace vdelete var wu $data(listVarTraceCmd)
}
upvar #0 $varName var
if {[info exists var]} {
#
# Invoke the trace procedure associated with the new list variable
#
listVarTrace $win $name1 $name2 w
} else {
#
# Set $varName according to the value of data(itemList)
#
set var {}
foreach item $data(itemList) {
lappend var [lrange $item 0 $data(lastCol)]
}
}
#
# Set a trace on the new list variable
#
trace variable var wu $data(listVarTraceCmd)
}
#------------------------------------------------------------------------------
# tablelist::isRowViewable
#
# Checks whether the given row of the tablelist widget win is viewable.
#------------------------------------------------------------------------------
proc tablelist::isRowViewable {win row} {
upvar ::tablelist::ns${win}::data data
set key [lindex $data(keyList) $row]
return [expr {![info exists data($key-elide)] &&
![info exists data($key-hide)]}]
}
#------------------------------------------------------------------------------
# tablelist::getCellFont
#
# Returns the font to be used in the tablelist cell specified by win, key, and
# col.
#------------------------------------------------------------------------------
proc tablelist::getCellFont {win key col} {
upvar ::tablelist::ns${win}::data data
if {[info exists data($key,$col-font)]} {
return $data($key,$col-font)
} elseif {[info exists data($key-font)]} {
return $data($key-font)
} else {
return [lindex $data(colFontList) $col]
}
}
#------------------------------------------------------------------------------
# tablelist::reconfigWindows
#
# Invoked as an after idle callback, this procedure forces any geometry manager
# calculations to be completed and then applies the -window option a second
# time to those cells whose embedded windows' requested widths or heights were
# still unknown.
#------------------------------------------------------------------------------
proc tablelist::reconfigWindows win {
#
# Force any geometry manager calculations to be completed first
#
update idletasks
if {![winfo exists $win]} { ;# because of update idletasks
return ""
}
#
# Reconfigure the cells specified in the list data(cellsToReconfig)
#
upvar ::tablelist::ns${win}::data data
foreach cellIdx $data(cellsToReconfig) {
foreach {row col} [split $cellIdx ","] {}
set key [lindex $data(keyList) $row]
if {[info exists data($key,$col-window)]} {
doCellConfig $row $col $win -window $data($key,$col-window)
}
}
unset data(reconfigId)
set data(cellsToReconfig) {}
}
#------------------------------------------------------------------------------
# tablelist::isCellEditable
#
# Checks whether the given cell of the tablelist widget win is editable.
#------------------------------------------------------------------------------
proc tablelist::isCellEditable {win row col} {
upvar ::tablelist::ns${win}::data data
set key [lindex $data(keyList) $row]
if {[info exists data($key,$col-editable)]} {
return $data($key,$col-editable)
} else {
return $data($col-editable)
}
}
#------------------------------------------------------------------------------
# tablelist::getEditWindow
#
# Returns the value of the -editwindow option at cell or column level for the
# given cell of the tablelist widget win.
#------------------------------------------------------------------------------
proc tablelist::getEditWindow {win row col} {
upvar ::tablelist::ns${win}::data data
set key [lindex $data(keyList) $row]
if {[info exists data($key,$col-editwindow)]} {
return $data($key,$col-editwindow)
} elseif {[info exists data($col-editwindow)]} {
return $data($col-editwindow)
} else {
return "entry"
}
}
|