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 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816
|
#==============================================================================
# Contains the implementation of the tablelist widget.
#
# Structure of the module:
# - Namespace initialization
# - Private procedure creating the default bindings
# - Public procedure creating a new tablelist widget
# - Private procedures implementing the tablelist widget command
# - Private callback procedures
#
# Copyright (c) 2000-2008 Csaba Nemethi (E-mail: csaba.nemethi@t-online.de)
#==============================================================================
#
# Namespace initialization
# ========================
#
namespace eval tablelist {
#
# Get the current windowing system ("x11", "win32", "classic", or "aqua")
#
variable winSys
if {[catch {tk windowingsystem} winSys] != 0} {
switch $::tcl_platform(platform) {
unix { set winSys x11 }
windows { set winSys win32 }
macintosh { set winSys classic }
}
}
#
# Create aliases for a few tile commands if not yet present
#
proc createTileAliases {} {
if {[string compare [interp alias {} ::tablelist::style] ""] != 0} {
return ""
}
if {[string compare [info commands ::ttk::style] ""] == 0} {
interp alias {} ::tablelist::style {} ::style
if {[string compare $::tile::version "0.7"] >= 0} {
interp alias {} ::tablelist::styleConfig {} ::style configure
} else {
interp alias {} ::tablelist::styleConfig {} ::style default
}
interp alias {} ::tablelist::getThemes {} ::tile::availableThemes
interp alias {} ::tablelist::setTheme {} ::tile::setTheme
interp alias {} ::tablelist::tileqt_currentThemeName \
{} ::tile::theme::tileqt::currentThemeName
interp alias {} ::tablelist::tileqt_currentThemeColour \
{} ::tile::theme::tileqt::currentThemeColour
} else {
interp alias {} ::tablelist::style {} ::ttk::style
interp alias {} ::tablelist::styleConfig {} ::ttk::style configure
interp alias {} ::tablelist::getThemes {} ::ttk::themes
interp alias {} ::tablelist::setTheme {} ::ttk::setTheme
interp alias {} ::tablelist::tileqt_currentThemeName \
{} ::ttk::theme::tileqt::currentThemeName
interp alias {} ::tablelist::tileqt_currentThemeColour \
{} ::ttk::theme::tileqt::currentThemeColour
}
}
if {$usingTile} {
createTileAliases
}
#
# The array configSpecs is used to handle configuration options. The
# names of its elements are the configuration options for the Tablelist
# class. The value of an array element is either an alias name or a list
# containing the database name and class as well as an indicator specifying
# the widget(s) to which the option applies: c stands for all children
# (text widgets and labels), b for the body text widget, l for the labels,
# f for the frame, and w for the widget itself.
#
# Command-Line Name {Database Name Database Class W}
# ------------------------------------------------------------------------
#
variable configSpecs
array set configSpecs {
-activestyle {activeStyle ActiveStyle w}
-arrowcolor {arrowColor ArrowColor w}
-arrowstyle {arrowStyle ArrowStyle w}
-arrowdisabledcolor {arrowDisabledColor ArrowDisabledColor w}
-background {background Background b}
-bg -background
-borderwidth {borderWidth BorderWidth f}
-bd -borderwidth
-columns {columns Columns w}
-cursor {cursor Cursor c}
-disabledforeground {disabledForeground DisabledForeground w}
-editendcommand {editEndCommand EditEndCommand w}
-editstartcommand {editStartCommand EditStartCommand w}
-exportselection {exportSelection ExportSelection w}
-font {font Font b}
-forceeditendcommand {forceEditEndCommand ForceEditEndCommand w}
-foreground {foreground Foreground b}
-fg -foreground
-height {height Height w}
-highlightbackground {highlightBackground HighlightBackground f}
-highlightcolor {highlightColor HighlightColor f}
-highlightthickness {highlightThickness HighlightThickness f}
-incrarrowtype {incrArrowType IncrArrowType w}
-labelactivebackground {labelActiveBackground Foreground l}
-labelactiveforeground {labelActiveForeground Background l}
-labelbackground {labelBackground Background l}
-labelbg -labelbackground
-labelborderwidth {labelBorderWidth BorderWidth l}
-labelbd -labelborderwidth
-labelcommand {labelCommand LabelCommand w}
-labelcommand2 {labelCommand2 LabelCommand2 w}
-labeldisabledforeground {labelDisabledForeground DisabledForeground l}
-labelfont {labelFont Font l}
-labelforeground {labelForeground Foreground l}
-labelfg -labelforeground
-labelheight {labelHeight Height l}
-labelpady {labelPadY Pad l}
-labelrelief {labelRelief Relief l}
-listvariable {listVariable Variable w}
-movablecolumns {movableColumns MovableColumns w}
-movablerows {movableRows MovableRows w}
-movecolumncursor {moveColumnCursor MoveColumnCursor w}
-movecursor {moveCursor MoveCursor w}
-protecttitlecolumns {protectTitleColumns ProtectTitleColumns w}
-relief {relief Relief f}
-resizablecolumns {resizableColumns ResizableColumns w}
-resizecursor {resizeCursor ResizeCursor w}
-selectbackground {selectBackground Foreground w}
-selectborderwidth {selectBorderWidth BorderWidth w}
-selectforeground {selectForeground Background w}
-selectmode {selectMode SelectMode w}
-selecttype {selectType SelectType w}
-setfocus {setFocus SetFocus w}
-setgrid {setGrid SetGrid w}
-showarrow {showArrow ShowArrow w}
-showlabels {showLabels ShowLabels w}
-showseparators {showSeparators ShowSeparators w}
-snipstring {snipString SnipString w}
-sortcommand {sortCommand SortCommand w}
-spacing {spacing Spacing w}
-state {state State w}
-stretch {stretch Stretch w}
-stripebackground {stripeBackground Background w}
-stripebg -stripebackground
-stripeforeground {stripeForeground Foreground w}
-stripefg -stripeforeground
-stripeheight {stripeHeight StripeHeight w}
-takefocus {takeFocus TakeFocus f}
-targetcolor {targetColor TargetColor w}
-titlecolumns {titleColumns TitleColumns w}
-tooltipaddcommand {tooltipAddCommand TooltipAddCommand w}
-tooltipdelcommand {tooltipDelCommand TooltipDelCommand w}
-width {width Width w}
-xscrollcommand {xScrollCommand ScrollCommand w}
-yscrollcommand {yScrollCommand ScrollCommand w}
}
#
# Extend the elements of the array configSpecs
#
extendConfigSpecs
variable configOpts [lsort [array names configSpecs]]
#
# The array colConfigSpecs is used to handle column configuration options.
# The names of its elements are the column configuration options for the
# Tablelist widget class. The value of an array element is either an alias
# name or a list containing the database name and class.
#
# Command-Line Name {Database Name Database Class }
# -----------------------------------------------------------------
#
variable colConfigSpecs
array set colConfigSpecs {
-align {align Align }
-background {background Background }
-bg -background
-changesnipside {changeSnipSide ChangeSnipSide }
-editable {editable Editable }
-editwindow {editWindow EditWindow }
-font {font Font }
-foreground {foreground Foreground }
-fg -foreground
-formatcommand {formatCommand FormatCommand }
-hide {hide Hide }
-labelalign {labelAlign Align }
-labelbackground {labelBackground Background }
-labelbg -labelbackground
-labelborderwidth {labelBorderWidth BorderWidth }
-labelbd -labelborderwidth
-labelcommand {labelCommand LabelCommand }
-labelcommand2 {labelCommand2 LabelCommand2 }
-labelfont {labelFont Font }
-labelforeground {labelForeground Foreground }
-labelfg -labelforeground
-labelheight {labelHeight Height }
-labelimage {labelImage Image }
-labelpady {labelPadY Pad }
-labelrelief {labelRelief Relief }
-maxwidth {maxWidth MaxWidth }
-name {name Name }
-resizable {resizable Resizable }
-selectbackground {selectBackground Foreground }
-selectforeground {selectForeground Background }
-showarrow {showArrow ShowArrow }
-showlinenumbers {showLineNumbers ShowLineNumbers }
-sortcommand {sortCommand SortCommand }
-sortmode {sortMode SortMode }
-stretchable {stretchable Stretchable }
-text {text Text }
-title {title Title }
-width {width Width }
-wrap {wrap Wrap }
}
#
# Extend some elements of the array colConfigSpecs
#
lappend colConfigSpecs(-align) - left
lappend colConfigSpecs(-changesnipside) - 0
lappend colConfigSpecs(-editable) - 0
lappend colConfigSpecs(-editwindow) - entry
lappend colConfigSpecs(-hide) - 0
lappend colConfigSpecs(-maxwidth) - 0
lappend colConfigSpecs(-resizable) - 1
lappend colConfigSpecs(-showarrow) - 1
lappend colConfigSpecs(-showlinenumbers) - 0
lappend colConfigSpecs(-sortmode) - ascii
lappend colConfigSpecs(-stretchable) - 0
lappend colConfigSpecs(-width) - 0
lappend colConfigSpecs(-wrap) - 0
if {$usingTile} {
unset colConfigSpecs(-labelheight)
}
#
# The array rowConfigSpecs is used to handle row configuration options.
# The names of its elements are the row configuration options for the
# Tablelist widget class. The value of an array element is either an alias
# name or a list containing the database name and class.
#
# Command-Line Name {Database Name Database Class }
# -----------------------------------------------------------------
#
variable rowConfigSpecs
array set rowConfigSpecs {
-background {background Background }
-bg -background
-font {font Font }
-foreground {foreground Foreground }
-fg -foreground
-hide {hide Hide }
-name {name Name }
-selectable {selectable Selectable }
-selectbackground {selectBackground Foreground }
-selectforeground {selectForeground Background }
-text {text Text }
}
#
# Check whether the -elide text widget tag option is available
#
variable canElide
variable elide
if {$::tk_version >= 8.3} {
set canElide 1
set elide -elide
} else {
set canElide 0
set elide --
}
#
# Extend some elements of the array rowConfigSpecs
#
if {$canElide} {
lappend rowConfigSpecs(-hide) - 0
} else {
unset rowConfigSpecs(-hide)
}
lappend rowConfigSpecs(-selectable) - 1
#
# The array cellConfigSpecs is used to handle cell configuration options.
# The names of its elements are the cell configuration options for the
# Tablelist widget class. The value of an array element is either an alias
# name or a list containing the database name and class.
#
# Command-Line Name {Database Name Database Class }
# -----------------------------------------------------------------
#
variable cellConfigSpecs
array set cellConfigSpecs {
-background {background Background }
-bg -background
-editable {editable Editable }
-editwindow {editWindow EditWindow }
-font {font Font }
-foreground {foreground Foreground }
-fg -foreground
-image {image Image }
-selectbackground {selectBackground Foreground }
-selectforeground {selectForeground Background }
-stretchwindow {stretchWindow StretchWindow }
-text {text Text }
-window {window Window }
-windowdestroy {windowDestroy WindowDestroy }
}
#
# Extend some elements of the array cellConfigSpecs
#
lappend cellConfigSpecs(-editable) - 0
lappend cellConfigSpecs(-editwindow) - entry
lappend cellConfigSpecs(-stretchwindow) - 0
#
# Use a list to facilitate the handling of the command options
#
variable cmdOpts [list \
activate activatecell attrib bbox bodypath bodytag cancelediting \
cellattrib cellcget cellconfigure cellindex cellselection cget \
columnattrib columncget columnconfigure columncount columnindex \
columnwidth config configcelllist configcells configcolumnlist \
configcolumns configrowlist configrows configure containing \
containingcell containingcolumn curcellselection curselection delete \
deletecolumns editcell editwintag editwinpath entrypath fillcolumn \
finishediting formatinfo get getcells getcolumns getkeys hasattrib \
hascellattrib hascolumnattrib hasrowattrib imagelabelpath index \
insert insertcolumnlist insertcolumns insertlist iselemsnipped \
istitlesnipped itemlistvar labelpath labels move movecolumn nearest \
nearestcell nearestcolumn rejectinput resetsortinfo rowattrib rowcget \
rowconfigure scan see seecell seecolumn selection separatorpath \
separators size sort sortbycolumn sortbycolumnlist sortcolumn \
sortcolumnlist sortorder sortorderlist togglecolumnhide togglerowhide \
unsetattrib unsetcellattrib unsetcolumnattrib unsetrowattrib \
windowpath xview yview]
if {!$canElide} {
set idx [lsearch -exact $cmdOpts togglerowhide]
set cmdOpts [lreplace $cmdOpts $idx $idx]
}
#
# Use lists to facilitate the handling of miscellaneous options
#
variable activeStyles [list frame none underline]
variable alignments [list left right center]
variable arrowStyles [list flat7x4 flat7x5 flat7x7 flat8x5 flat9x5 \
sunken8x7 sunken10x9 sunken12x11]
variable arrowTypes [list up down]
variable colWidthOpts [list -requested -stretched -total]
variable states [list disabled normal]
variable selectTypes [list row cell]
variable sortModes [list ascii command dictionary integer real]
variable sortOrders [list increasing decreasing]
variable _sortOrders [list -increasing -decreasing]
variable scanCmdOpts [list mark dragto]
variable selCmdOpts [list anchor clear includes set]
#
# Define the procedure strToDispStr, which returns the string
# obtained by replacing all \t characters in its argument with
# \\t, as well as the procedure strMap, needed because the
# "string map" command is not available in Tcl 8.0 and 8.1.0.
#
if {[catch {string map {} ""}] == 0} {
proc strToDispStr str {
if {[string match "*\t*" $str]} {
return [string map {"\t" "\\t"} $str]
} else {
return $str
}
}
interp alias {} ::tablelist::strMap {} string map
} else {
proc strToDispStr str {
if {[string match "*\t*" $str]} {
regsub -all "\t" $str "\\t" str
}
return $str
}
proc strMap {charMap str} {
foreach {key val} $charMap {
#
# We will only need this for noncritical key and str values
#
regsub -all $key $str $val str
}
return $str
}
}
}
#
# Private procedure creating the default bindings
# ===============================================
#
#------------------------------------------------------------------------------
# tablelist::createBindings
#
# Creates the default bindings for the binding tags Tablelist, TablelistWindow,
# TablelistKeyNav, TablelistBody, TablelistLabel, TablelistSubLabel,
# TablelistArrow, and TablelistEdit.
#------------------------------------------------------------------------------
proc tablelist::createBindings {} {
#
# Define some Tablelist class bindings
#
bind Tablelist <KeyPress> continue
bind Tablelist <FocusIn> {
if {![info exists tablelist::ns%W::data(dispId)]} {
tablelist::addActiveTag %W
}
if {[string compare [focus -lastfor %W] %W] == 0} {
if {[winfo exists [%W editwinpath]]} {
focus [set tablelist::ns%W::data(editFocus)]
} else {
focus [%W bodypath]
}
}
}
bind Tablelist <FocusOut> { tablelist::removeActiveTag %W }
bind Tablelist <<TablelistSelect>> { event generate %W <<ListboxSelect>> }
bind Tablelist <Destroy> { tablelist::cleanup %W }
variable usingTile
if {$usingTile} {
bind Tablelist <<ThemeChanged>> {
after idle [list tablelist::updateConfigSpecs %W]
}
}
#
# Define some TablelistWindow class bindings
#
bind TablelistWindow <Destroy> { tablelist::cleanupWindow %W }
#
# Define the binding tags TablelistKeyNav and TablelistBody
#
mwutil::defineKeyNav Tablelist
defineTablelistBody
#
# Define the virtual events <<Button3>> and <<ShiftButton3>>
#
event add <<Button3>> <Button-3>
event add <<ShiftButton3>> <Shift-Button-3>
variable winSys
if {[string compare $winSys "classic"] == 0 ||
[string compare $winSys "aqua"] == 0} {
event add <<Button3>> <Control-Button-1>
event add <<ShiftButton3>> <Shift-Control-Button-1>
}
#
# Define some mouse bindings for the binding tag TablelistLabel
#
bind TablelistLabel <Enter> { tablelist::labelEnter %W %X %Y %x }
bind TablelistLabel <Motion> { tablelist::labelEnter %W %X %Y %x }
bind TablelistLabel <Leave> { tablelist::labelLeave %W %X %x %y }
bind TablelistLabel <Button-1> { tablelist::labelB1Down %W %x 0 }
bind TablelistLabel <Shift-Button-1> { tablelist::labelB1Down %W %x 1 }
bind TablelistLabel <B1-Motion> { tablelist::labelB1Motion %W %X %x %y }
bind TablelistLabel <B1-Enter> { tablelist::labelB1Enter %W }
bind TablelistLabel <B1-Leave> { tablelist::labelB1Leave %W %x %y }
bind TablelistLabel <ButtonRelease-1> { tablelist::labelB1Up %W %X}
bind TablelistLabel <<Button3>> { tablelist::labelB3Down %W 0 }
bind TablelistLabel <<ShiftButton3>> { tablelist::labelB3Down %W 1 }
#
# Define the binding tags TablelistSubLabel and TablelistArrow
#
defineTablelistSubLabel
defineTablelistArrow
#
# Define the binding tag TablelistEdit if the file tablelistEdit.tcl exists
#
catch {defineTablelistEdit}
}
#
# Public procedure creating a new tablelist widget
# ================================================
#
#------------------------------------------------------------------------------
# tablelist::tablelist
#
# Creates a new tablelist widget whose name is specified as the first command-
# line argument, and configures it according to the options and their values
# given on the command line. Returns the name of the newly created widget.
#------------------------------------------------------------------------------
proc tablelist::tablelist args {
variable usingTile
variable configSpecs
variable configOpts
variable canElide
if {[llength $args] == 0} {
mwutil::wrongNumArgs "tablelist pathName ?options?"
}
#
# Create a frame of the class Tablelist
#
set win [lindex $args 0]
if {[catch {
if {$usingTile} {
ttk::frame $win -style Frame$win.TFrame -class Tablelist \
-height 0 -width 0 -padding 0
} else {
tk::frame $win -class Tablelist -container 0 -height 0 -width 0
catch {$win configure -padx 0 -pady 0}
}
} result] != 0} {
return -code error $result
}
#
# Create a namespace within the current one to hold the data of the widget
#
namespace eval ns$win {
#
# The folowing array holds various data for this widget
#
variable data
array set data {
arrowWidth 9
hasListVar 0
isDisabled 0
ownsFocus 0
charWidth 1
hdrPixels 0
activeRow 0
activeCol 0
anchorRow 0
anchorCol 0
seqNum -1
freeKeyList {}
itemList {}
itemCount 0
lastRow -1
colList {}
colCount 0
lastCol -1
rowTagRefCount 0
cellTagRefCount 0
imgCount 0
winCount 0
afterId ""
labelClicked 0
arrowColList {}
sortColList {}
sortOrder ""
editRow -1
editCol -1
fmtKey ""
fmtRow -1
fmtCol -1
prevCell ""
prevCol -1
forceAdjust 0
fmtCmdFlagList {}
hasFmtCmds 0
scrlColOffset 0
cellsToReconfig {}
hiddenRowCount 0
nonHiddenRowList {-1}
hiddenColCount 0
}
#
# The following array is used to hold arbitrary
# attributes and their values for this widget
#
variable attribs
}
#
# Initialize some further components of data
#
upvar ::tablelist::ns${win}::data data
foreach opt $configOpts {
set data($opt) [lindex $configSpecs($opt) 3]
}
if {$usingTile} {
setThemeDefaults
variable themeDefaults
set data(currentTheme) [getCurrentTheme]
set data(themeDefaults) [array get themeDefaults]
if {[string compare $data(currentTheme) "tileqt"] == 0} {
set data(widgetStyle) [tileqt_currentThemeName]
set data(colorScheme) [getKdeConfigVal "KDE" "colorScheme"]
} else {
set data(widgetStyle) ""
set data(colorScheme) ""
}
}
set data(-titlecolumns) 0 ;# for Tk versions < 8.3
set data(colFontList) [list $data(-font)]
set data(listVarTraceCmd) [list tablelist::listVarTrace $win]
set data(bodyTag) body$win
set data(editwinTag) editwin$win
set data(body) $win.body
set data(bodyFr) $data(body).f
set data(bodyFrEd) $data(bodyFr).e
set data(rowGap) $data(body).g
set data(hdr) $win.hdr
set data(hdrTxt) $data(hdr).t
set data(hdrTxtFr) $data(hdrTxt).f
set data(hdrTxtFrCanv) $data(hdrTxtFr).c
set data(hdrTxtFrLbl) $data(hdrTxtFr).l
set data(hdrLbl) $data(hdr).l
set data(colGap) $data(hdr).g
set data(lb) $win.lb
set data(sep) $win.sep
#
# Create a child hierarchy used to hold the column labels. The
# labels will be created as children of the frame data(hdrTxtFr),
# which is embedded into the text widget data(hdrTxt) (in order
# to make it scrollable), which in turn fills the frame data(hdr)
# (whose width and height can be set arbitrarily in pixels).
#
set w $data(hdr) ;# header frame
tk::frame $w -borderwidth 0 -container 0 -height 0 -highlightthickness 0 \
-relief flat -takefocus 0 -width 0
catch {$w configure -padx 0 -pady 0}
bind $w <Configure> {
set tablelist::W [winfo parent %W]
tablelist::stretchColumnsWhenIdle $tablelist::W
tablelist::updateScrlColOffsetWhenIdle $tablelist::W
tablelist::updateHScrlbarWhenIdle $tablelist::W
}
pack $w -fill x
set w $data(hdrTxt) ;# text widget within the header frame
text $w -borderwidth 0 -highlightthickness 0 -insertwidth 0 \
-padx 0 -pady 0 -state normal -takefocus 0 -wrap none
place $w -relheight 1.0 -relwidth 1.0
bindtags $w [lreplace [bindtags $w] 1 1]
tk::frame $data(hdrTxtFr) -borderwidth 0 -container 0 -height 0 \
-highlightthickness 0 -relief flat \
-takefocus 0 -width 0
catch {$data(hdrTxtFr) configure -padx 0 -pady 0}
$w window create 1.0 -window $data(hdrTxtFr)
set w $data(hdrLbl) ;# filler label within the header frame
if {$usingTile} {
ttk::label $data(hdrTxtFrLbl)0 -style TablelistHeader.TLabel
ttk::label $w -style TablelistHeader.TLabel -image "" \
-padding {1 1 1 1} -takefocus 0 -text "" \
-textvariable "" -underline -1 -wraplength 0
} else {
tk::label $data(hdrTxtFrLbl)0
tk::label $w -bitmap "" -highlightthickness 0 -image "" \
-takefocus 0 -text "" -textvariable "" -underline -1 \
-wraplength 0
}
place $w -relheight 1.0 -relwidth 1.0
#
# Create the body text widget within the main frame
#
set w $data(body)
text $w -borderwidth 0 -exportselection 0 -highlightthickness 0 \
-insertwidth 0 -padx 0 -pady 0 -state normal -takefocus 0 -wrap none
bind $w <Configure> {
set tablelist::W [winfo parent %W]
tablelist::makeColFontAndTagLists $tablelist::W
tablelist::adjustElidedTextWhenIdle $tablelist::W
tablelist::updateColorsWhenIdle $tablelist::W
tablelist::adjustSepsWhenIdle $tablelist::W
tablelist::updateVScrlbarWhenIdle $tablelist::W
}
pack $w -expand 1 -fill both
#
# Modify the list of binding tags of the body text widget
#
bindtags $w [list $w $data(bodyTag) TablelistBody [winfo toplevel $w] \
TablelistKeyNav all]
#
# Create the "stripe", "select", "active", "disabled", "hiddenRow",
# "hiddenCol", and "elidedCol" tags in the body text widget. 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. DO NOT CHANGE the order of creation of these tags!
#
$w tag configure stripe -background "" -foreground "" ;# will be changed
$w tag configure select -relief raised
$w tag configure active -borderwidth "" ;# will be changed
$w tag configure disabled -foreground "" ;# will be changed
if {$canElide} {
$w tag configure hiddenRow -elide 1
$w tag configure hiddenCol -elide 1
$w tag configure elidedCol -elide 1
}
#
# Create two frames used to display a gap between two consecutive
# rows/columns when moving a row/column interactively
#
tk::frame $data(rowGap) -borderwidth 1 -container 0 -highlightthickness 0 \
-relief sunken -takefocus 0 -height 4
tk::frame $data(colGap) -borderwidth 1 -container 0 -highlightthickness 0 \
-relief sunken -takefocus 0 -width 4
#
# Create an unmanaged listbox child, used to handle the -setgrid option
#
listbox $data(lb)
#
# Create the bitmaps needed to display the sort ranks
#
createSortRankImgs $win
#
# Configure the widget according to the command-line
# arguments and to the available database options
#
if {[catch {
mwutil::configureWidget $win configSpecs tablelist::doConfig \
tablelist::doCget [lrange $args 1 end] 1
} result] != 0} {
destroy $win
return -code error $result
}
#
# Move the original widget command into the current namespace and
# create an alias of the original name for a new widget procedure
#
rename ::$win $win
interp alias {} ::$win {} tablelist::tablelistWidgetCmd $win
#
# Register a callback to be invoked whenever the PRIMARY
# selection is owned by the window win and someone
# attempts to retrieve it as a UTF8_STRING or STRING
#
selection handle -type UTF8_STRING $win \
[list ::tablelist::fetchSelection $win]
selection handle -type STRING $win \
[list ::tablelist::fetchSelection $win]
#
# Set a trace on the array elements data(activeRow),
# data(avtiveCol), and data(-selecttype)
#
foreach name {activeRow activeCol -selecttype} {
trace variable data($name) w [list tablelist::activeTrace $win]
}
return $win
}
#
# Private procedures implementing the tablelist widget command
# ============================================================
#
#------------------------------------------------------------------------------
# tablelist::tablelistWidgetCmd
#
# Processes the Tcl command corresponding to a tablelist widget.
#------------------------------------------------------------------------------
proc tablelist::tablelistWidgetCmd {win args} {
if {[llength $args] == 0} {
mwutil::wrongNumArgs "$win option ?arg arg ...?"
}
variable cmdOpts
set cmd [mwutil::fullOpt "option" [lindex $args 0] $cmdOpts]
return [${cmd}SubCmd $win [lrange $args 1 end]]
}
#------------------------------------------------------------------------------
# tablelist::activateSubCmd
#------------------------------------------------------------------------------
proc tablelist::activateSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win activate index"
}
upvar ::tablelist::ns${win}::data data
if {$data(isDisabled)} {
return ""
}
synchronize $win
displayItems $win
set index [rowIndex $win [lindex $argList 0] 0]
#
# Adjust the index to fit within the existing non-hidden items
#
adjustRowIndex $win index 1
set data(activeRow) $index
return ""
}
#------------------------------------------------------------------------------
# tablelist::activatecellSubCmd
#------------------------------------------------------------------------------
proc tablelist::activatecellSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win activatecell cellIndex"
}
upvar ::tablelist::ns${win}::data data
if {$data(isDisabled)} {
return ""
}
synchronize $win
displayItems $win
foreach {row col} [cellIndex $win [lindex $argList 0] 0] {}
#
# Adjust the row and column indices to fit
# within the existing non-hidden elements
#
adjustRowIndex $win row 1
adjustColIndex $win col 1
set data(activeRow) $row
set data(activeCol) $col
return ""
}
#------------------------------------------------------------------------------
# tablelist::attribSubCmd
#------------------------------------------------------------------------------
proc tablelist::attribSubCmd {win argList} {
return [mwutil::attribSubCmd $win "widget" $argList]
}
#------------------------------------------------------------------------------
# tablelist::bboxSubCmd
#------------------------------------------------------------------------------
proc tablelist::bboxSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win bbox index"
}
synchronize $win
displayItems $win
set index [rowIndex $win [lindex $argList 0] 0]
upvar ::tablelist::ns${win}::data data
set w $data(body)
set dlineinfo [$w dlineinfo [expr {double($index + 1)}]]
if {$data(itemCount) == 0 || [string compare $dlineinfo ""] == 0} {
return {}
}
set spacing1 [$w cget -spacing1]
set spacing3 [$w cget -spacing3]
foreach {x y width height baselinePos} $dlineinfo {}
lappend bbox [expr {$x + [winfo x $w]}] \
[expr {$y + [winfo y $w] + $spacing1}] \
$width [expr {$height - $spacing1 - $spacing3}]
return $bbox
}
#------------------------------------------------------------------------------
# tablelist::bodypathSubCmd
#------------------------------------------------------------------------------
proc tablelist::bodypathSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win bodypath"
}
upvar ::tablelist::ns${win}::data data
return $data(body)
}
#------------------------------------------------------------------------------
# tablelist::bodytagSubCmd
#------------------------------------------------------------------------------
proc tablelist::bodytagSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win bodytag"
}
upvar ::tablelist::ns${win}::data data
return $data(bodyTag)
}
#------------------------------------------------------------------------------
# tablelist::canceleditingSubCmd
#------------------------------------------------------------------------------
proc tablelist::canceleditingSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win cancelediting"
}
synchronize $win
displayItems $win
return [doCancelEditing $win]
}
#------------------------------------------------------------------------------
# tablelist::cellattribSubCmd
#------------------------------------------------------------------------------
proc tablelist::cellattribSubCmd {win argList} {
if {[llength $argList] < 1} {
mwutil::wrongNumArgs "$win cellattrib cellIndex ?name? ?value\
name value ...?"
}
synchronize $win
foreach {row col} [cellIndex $win [lindex $argList 0] 1] {}
upvar ::tablelist::ns${win}::data data
set key [lindex [lindex $data(itemList) $row] end]
return [mwutil::attribSubCmd $win $key,$col [lrange $argList 1 end]]
}
#------------------------------------------------------------------------------
# tablelist::cellcgetSubCmd
#------------------------------------------------------------------------------
proc tablelist::cellcgetSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win cellcget cellIndex option"
}
synchronize $win
foreach {row col} [cellIndex $win [lindex $argList 0] 1] {}
variable cellConfigSpecs
set opt [mwutil::fullConfigOpt [lindex $argList 1] cellConfigSpecs]
return [doCellCget $row $col $win $opt]
}
#------------------------------------------------------------------------------
# tablelist::cellconfigureSubCmd
#------------------------------------------------------------------------------
proc tablelist::cellconfigureSubCmd {win argList} {
if {[llength $argList] < 1} {
mwutil::wrongNumArgs "$win cellconfigure cellIndex ?option? ?value\
option value ...?"
}
synchronize $win
displayItems $win
variable cellConfigSpecs
foreach {row col} [cellIndex $win [lindex $argList 0] 1] {}
return [mwutil::configureSubCmd $win cellConfigSpecs \
"tablelist::doCellConfig $row $col" \
"tablelist::doCellCget $row $col" [lrange $argList 1 end]]
}
#------------------------------------------------------------------------------
# tablelist::cellindexSubCmd
#------------------------------------------------------------------------------
proc tablelist::cellindexSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win cellindex cellIndex"
}
synchronize $win
return [join [cellIndex $win [lindex $argList 0] 0] ","]
}
#------------------------------------------------------------------------------
# tablelist::cellselectionSubCmd
#------------------------------------------------------------------------------
proc tablelist::cellselectionSubCmd {win argList} {
set argCount [llength $argList]
if {$argCount < 2 || $argCount > 3} {
mwutil::wrongNumArgs \
"$win cellselection option firstCellIndex lastCellIndex" \
"$win cellselection option cellIndexList"
}
synchronize $win
displayItems $win
variable selCmdOpts
set opt [mwutil::fullOpt "option" [lindex $argList 0] $selCmdOpts]
set first [lindex $argList 1]
switch $opt {
anchor -
includes {
if {$argCount != 2} {
mwutil::wrongNumArgs "$win cellselection $opt cellIndex"
}
foreach {row col} [cellIndex $win $first 0] {}
return [cellSelection $win $opt $row $col $row $col]
}
clear -
set {
if {$argCount == 2} {
foreach elem $first {
foreach {row col} [cellIndex $win $elem 0] {}
cellSelection $win $opt $row $col $row $col
}
return ""
} else {
foreach {firstRow firstCol} [cellIndex $win $first 0] {}
foreach {lastRow lastCol} \
[cellIndex $win [lindex $argList 2] 0] {}
return [cellSelection $win $opt \
$firstRow $firstCol $lastRow $lastCol]
}
}
}
}
#------------------------------------------------------------------------------
# tablelist::cgetSubCmd
#------------------------------------------------------------------------------
proc tablelist::cgetSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win cget option"
}
#
# Return the value of the specified configuration option
#
variable configSpecs
set opt [mwutil::fullConfigOpt [lindex $argList 0] configSpecs]
upvar ::tablelist::ns${win}::data data
return $data($opt)
}
#------------------------------------------------------------------------------
# tablelist::columnattribSubCmd
#------------------------------------------------------------------------------
proc tablelist::columnattribSubCmd {win argList} {
if {[llength $argList] < 1} {
mwutil::wrongNumArgs "$win columnattrib columnIndex ?name? ?value\
name value ...?"
}
synchronize $win
set col [colIndex $win [lindex $argList 0] 1]
return [mwutil::attribSubCmd $win $col [lrange $argList 1 end]]
}
#------------------------------------------------------------------------------
# tablelist::columncgetSubCmd
#------------------------------------------------------------------------------
proc tablelist::columncgetSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win columncget columnIndex option"
}
synchronize $win
set col [colIndex $win [lindex $argList 0] 1]
variable colConfigSpecs
set opt [mwutil::fullConfigOpt [lindex $argList 1] colConfigSpecs]
return [doColCget $col $win $opt]
}
#------------------------------------------------------------------------------
# tablelist::columnconfigureSubCmd
#------------------------------------------------------------------------------
proc tablelist::columnconfigureSubCmd {win argList} {
if {[llength $argList] < 1} {
mwutil::wrongNumArgs "$win columnconfigure columnIndex ?option? ?value\
option value ...?"
}
synchronize $win
displayItems $win
variable colConfigSpecs
set col [colIndex $win [lindex $argList 0] 1]
return [mwutil::configureSubCmd $win colConfigSpecs \
"tablelist::doColConfig $col" "tablelist::doColCget $col" \
[lrange $argList 1 end]]
}
#------------------------------------------------------------------------------
# tablelist::columncountSubCmd
#------------------------------------------------------------------------------
proc tablelist::columncountSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win columncount"
}
upvar ::tablelist::ns${win}::data data
return $data(colCount)
}
#------------------------------------------------------------------------------
# tablelist::columnindexSubCmd
#------------------------------------------------------------------------------
proc tablelist::columnindexSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win columnindex columnIndex"
}
return [colIndex $win [lindex $argList 0] 0]
}
#------------------------------------------------------------------------------
# tablelist::columnwidthSubCmd
#------------------------------------------------------------------------------
proc tablelist::columnwidthSubCmd {win argList} {
set argCount [llength $argList]
if {$argCount < 1 || $argCount > 2} {
mwutil::wrongNumArgs "$win columnwidth columnIndex\
?-requested|-stretched|-total?"
}
synchronize $win
displayItems $win
set col [colIndex $win [lindex $argList 0] 1]
if {$argCount == 1} {
set opt -requested
} else {
variable colWidthOpts
set opt [mwutil::fullOpt "option" [lindex $argList 1] $colWidthOpts]
}
return [colWidth $win $col $opt]
}
#------------------------------------------------------------------------------
# tablelist::configSubCmd
#------------------------------------------------------------------------------
proc tablelist::configSubCmd {win argList} {
return [configureSubCmd $win $argList]
}
#------------------------------------------------------------------------------
# tablelist::configcelllistSubCmd
#------------------------------------------------------------------------------
proc tablelist::configcelllistSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win configcelllist cellConfigSpecList"
}
return [configcellsSubCmd $win [lindex $argList 0]]
}
#------------------------------------------------------------------------------
# tablelist::configcellsSubCmd
#------------------------------------------------------------------------------
proc tablelist::configcellsSubCmd {win argList} {
synchronize $win
displayItems $win
variable cellConfigSpecs
set argCount [llength $argList]
foreach {cell opt val} $argList {
if {$argCount == 1} {
return -code error "option and value for \"$cell\" missing"
} elseif {$argCount == 2} {
return -code error "value for \"$opt\" missing"
}
foreach {row col} [cellIndex $win $cell 1] {}
mwutil::configureWidget $win cellConfigSpecs \
"tablelist::doCellConfig $row $col" \
"tablelist::doCellCget $row $col" [list $opt $val] 0
incr argCount -3
}
return ""
}
#------------------------------------------------------------------------------
# tablelist::configcolumnlistSubCmd
#------------------------------------------------------------------------------
proc tablelist::configcolumnlistSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win configcolumnlist columnConfigSpecList"
}
return [configcolumnsSubCmd $win [lindex $argList 0]]
}
#------------------------------------------------------------------------------
# tablelist::configcolumnsSubCmd
#------------------------------------------------------------------------------
proc tablelist::configcolumnsSubCmd {win argList} {
synchronize $win
displayItems $win
variable colConfigSpecs
set argCount [llength $argList]
foreach {col opt val} $argList {
if {$argCount == 1} {
return -code error "option and value for \"$col\" missing"
} elseif {$argCount == 2} {
return -code error "value for \"$opt\" missing"
}
set col [colIndex $win $col 1]
mwutil::configureWidget $win colConfigSpecs \
"tablelist::doColConfig $col" "tablelist::doColCget $col" \
[list $opt $val] 0
incr argCount -3
}
return ""
}
#------------------------------------------------------------------------------
# tablelist::configrowlistSubCmd
#------------------------------------------------------------------------------
proc tablelist::configrowlistSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win configrowlist rowConfigSpecList"
}
return [configrowsSubCmd $win [lindex $argList 0]]
}
#------------------------------------------------------------------------------
# tablelist::configrowsSubCmd
#------------------------------------------------------------------------------
proc tablelist::configrowsSubCmd {win argList} {
synchronize $win
displayItems $win
variable rowConfigSpecs
upvar ::tablelist::ns${win}::data data
set argCount [llength $argList]
foreach {rowSpec opt val} $argList {
if {$argCount == 1} {
return -code error "option and value for \"$rowSpec\" missing"
} elseif {$argCount == 2} {
return -code error "value for \"$opt\" missing"
}
set row [rowIndex $win $rowSpec 0]
if {$row < 0 || $row > $data(lastRow)} {
return -code error "row index \"$rowSpec\" out of range"
}
mwutil::configureWidget $win rowConfigSpecs \
"tablelist::doRowConfig $row" "tablelist::doRowCget $row" \
[list $opt $val] 0
incr argCount -3
}
return ""
}
#------------------------------------------------------------------------------
# tablelist::configureSubCmd
#------------------------------------------------------------------------------
proc tablelist::configureSubCmd {win argList} {
synchronize $win
displayItems $win
variable configSpecs
return [mwutil::configureSubCmd $win configSpecs tablelist::doConfig \
tablelist::doCget $argList]
}
#------------------------------------------------------------------------------
# tablelist::containingSubCmd
#------------------------------------------------------------------------------
proc tablelist::containingSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win containing y"
}
set y [format "%d" [lindex $argList 0]]
synchronize $win
displayItems $win
return [containingRow $win $y]
}
#------------------------------------------------------------------------------
# tablelist::containingcellSubCmd
#------------------------------------------------------------------------------
proc tablelist::containingcellSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win containingcell x y"
}
set x [format "%d" [lindex $argList 0]]
set y [format "%d" [lindex $argList 1]]
synchronize $win
displayItems $win
return [containingRow $win $y],[containingCol $win $x]
}
#------------------------------------------------------------------------------
# tablelist::containingcolumnSubCmd
#------------------------------------------------------------------------------
proc tablelist::containingcolumnSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win containingcolumn x"
}
set x [format "%d" [lindex $argList 0]]
synchronize $win
displayItems $win
return [containingCol $win $x]
}
#------------------------------------------------------------------------------
# tablelist::curcellselectionSubCmd
#------------------------------------------------------------------------------
proc tablelist::curcellselectionSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win curcellselection"
}
synchronize $win
displayItems $win
return [curCellSelection $win]
}
#------------------------------------------------------------------------------
# tablelist::curselectionSubCmd
#------------------------------------------------------------------------------
proc tablelist::curselectionSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win curselection"
}
synchronize $win
displayItems $win
return [curSelection $win]
}
#------------------------------------------------------------------------------
# tablelist::deleteSubCmd
#------------------------------------------------------------------------------
proc tablelist::deleteSubCmd {win argList} {
set argCount [llength $argList]
if {$argCount < 1 || $argCount > 2} {
mwutil::wrongNumArgs "$win delete firstIndex lastIndex" \
"$win delete indexList"
}
upvar ::tablelist::ns${win}::data data
if {$data(isDisabled)} {
return ""
}
synchronize $win
displayItems $win
set first [lindex $argList 0]
if {$argCount == 1} {
if {[llength $first] == 1} { ;# just to save time
set index [rowIndex $win [lindex $first 0] 0]
return [deleteRows $win $index $index $data(hasListVar)]
} elseif {$data(itemCount) == 0} { ;# no items present
return ""
} else { ;# a bit more work
#
# Sort the numerical equivalents of the
# specified indices in decreasing order
#
set indexList {}
foreach elem $first {
set index [rowIndex $win $elem 0]
if {$index < 0} {
set index 0
} elseif {$index > $data(lastRow)} {
set index $data(lastRow)
}
lappend indexList $index
}
set indexList [lsort -integer -decreasing $indexList]
#
# Traverse the sorted index list and ignore any duplicates
#
set prevIndex -1
foreach index $indexList {
if {$index != $prevIndex} {
deleteRows $win $index $index $data(hasListVar)
set prevIndex $index
}
}
return ""
}
} else {
set first [rowIndex $win $first 0]
set last [rowIndex $win [lindex $argList 1] 0]
return [deleteRows $win $first $last $data(hasListVar)]
}
}
#------------------------------------------------------------------------------
# tablelist::deletecolumnsSubCmd
#------------------------------------------------------------------------------
proc tablelist::deletecolumnsSubCmd {win argList} {
set argCount [llength $argList]
if {$argCount < 1 || $argCount > 2} {
mwutil::wrongNumArgs \
"$win deletecolumns firstColumnIndex lastColumnIndex" \
"$win deletecolumns columnIndexList"
}
upvar ::tablelist::ns${win}::data data
if {$data(isDisabled)} {
return ""
}
synchronize $win
displayItems $win
set first [lindex $argList 0]
if {$argCount == 1} {
if {[llength $first] == 1} { ;# just to save time
set col [colIndex $win [lindex $first 0] 1]
set selCells [curCellSelection $win]
deleteCols $win $col $col selCells
redisplay $win 0 $selCells
} elseif {$data(colCount) == 0} { ;# no columns present
return ""
} else { ;# a bit more work
#
# Sort the numerical equivalents of the
# specified column indices in decreasing order
#
set colList {}
foreach elem $first {
lappend colList [colIndex $win $elem 1]
}
set colList [lsort -integer -decreasing $colList]
#
# Traverse the sorted column index list and ignore any duplicates
#
set selCells [curCellSelection $win]
set deleted 0
set prevCol -1
foreach col $colList {
if {$col != $prevCol} {
deleteCols $win $col $col selCells
set deleted 1
set prevCol $col
}
}
if {$deleted} {
redisplay $win 0 $selCells
}
}
} else {
set first [colIndex $win $first 1]
set last [colIndex $win [lindex $argList 1] 1]
if {$first <= $last} {
set selCells [curCellSelection $win]
deleteCols $win $first $last selCells
redisplay $win 0 $selCells
}
}
return ""
}
#------------------------------------------------------------------------------
# tablelist::editcellSubCmd
#------------------------------------------------------------------------------
proc tablelist::editcellSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win editcell cellIndex"
}
synchronize $win
displayItems $win
foreach {row col} [cellIndex $win [lindex $argList 0] 1] {}
return [doEditCell $win $row $col 0]
}
#------------------------------------------------------------------------------
# tablelist::editwintagSubCmd
#------------------------------------------------------------------------------
proc tablelist::editwintagSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win editwintag"
}
upvar ::tablelist::ns${win}::data data
return $data(editwinTag)
}
#------------------------------------------------------------------------------
# tablelist::editwinpathSubCmd
#------------------------------------------------------------------------------
proc tablelist::editwinpathSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win editwinpath"
}
upvar ::tablelist::ns${win}::data data
if {[winfo exists $data(bodyFrEd)]} {
return $data(bodyFrEd)
} else {
return ""
}
}
#------------------------------------------------------------------------------
# tablelist::entrypathSubCmd
#------------------------------------------------------------------------------
proc tablelist::entrypathSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win entrypath"
}
upvar ::tablelist::ns${win}::data data
if {[winfo exists $data(bodyFrEd)]} {
set class [winfo class $data(bodyFrEd)]
if {[regexp {^(Mentry|T?Checkbutton)$} $class]} {
return ""
} else {
return $data(editFocus)
}
} else {
return ""
}
}
#------------------------------------------------------------------------------
# tablelist::fillcolumnSubCmd
#------------------------------------------------------------------------------
proc tablelist::fillcolumnSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win fillcolumn columnIndex text"
}
upvar ::tablelist::ns${win}::data data
if {$data(isDisabled)} {
return ""
}
synchronize $win
displayItems $win
set colIdx [colIndex $win [lindex $argList 0] 1]
set text [lindex $argList 1]
#
# Update the item list
#
set newItemList {}
foreach item $data(itemList) {
set item [lreplace $item $colIdx $colIdx $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 $colIdx 1
redisplayColWhenIdle $win $colIdx
return ""
}
#------------------------------------------------------------------------------
# tablelist::finisheditingSubCmd
#------------------------------------------------------------------------------
proc tablelist::finisheditingSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win finishediting"
}
synchronize $win
displayItems $win
return [doFinishEditing $win]
}
#------------------------------------------------------------------------------
# tablelist::formatinfoSubCmd
#------------------------------------------------------------------------------
proc tablelist::formatinfoSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win formatinfo"
}
upvar ::tablelist::ns${win}::data data
return [list $data(fmtKey) $data(fmtRow) $data(fmtCol)]
}
#------------------------------------------------------------------------------
# tablelist::getSubCmd
#------------------------------------------------------------------------------
proc tablelist::getSubCmd {win argList} {
set argCount [llength $argList]
if {$argCount < 1 || $argCount > 2} {
mwutil::wrongNumArgs "$win get firstIndex lastIndex" \
"$win get indexList"
}
synchronize $win
set first [lindex $argList 0]
#
# Get the specified items from the internal list
#
upvar ::tablelist::ns${win}::data data
set result {}
if {$argCount == 1} {
foreach elem $first {
set index [rowIndex $win $elem 0]
if {$index >= 0 && $index < $data(itemCount)} {
set item [lindex $data(itemList) $index]
lappend result [lrange $item 0 $data(lastCol)]
}
}
if {[llength $first] == 1} {
return [lindex $result 0]
} else {
return $result
}
} else {
set first [rowIndex $win $first 0]
set last [rowIndex $win [lindex $argList 1] 0]
#
# Adjust the range to fit within the existing items
#
if {$first > $data(lastRow)} {
return {}
}
if {$first < 0} {
set first 0
}
if {$last > $data(lastRow)} {
set last $data(lastRow)
}
foreach item [lrange $data(itemList) $first $last] {
lappend result [lrange $item 0 $data(lastCol)]
}
return $result
}
}
#------------------------------------------------------------------------------
# tablelist::getcellsSubCmd
#------------------------------------------------------------------------------
proc tablelist::getcellsSubCmd {win argList} {
set argCount [llength $argList]
if {$argCount < 1 || $argCount > 2} {
mwutil::wrongNumArgs \
"$win getcells firstCellIndex lastCellIndex" \
"$win getcells cellIndexList"
}
synchronize $win
set first [lindex $argList 0]
#
# Get the specified elements from the internal list
#
upvar ::tablelist::ns${win}::data data
set result {}
if {$argCount == 1} {
foreach elem $first {
foreach {row col} [cellIndex $win $elem 1] {}
lappend result [lindex [lindex $data(itemList) $row] $col]
}
if {[llength $first] == 1} {
return [lindex $result 0]
} else {
return $result
}
} else {
foreach {firstRow firstCol} [cellIndex $win $first 1] {}
foreach {lastRow lastCol} [cellIndex $win [lindex $argList 1] 1] {}
foreach item [lrange $data(itemList) $firstRow $lastRow] {
foreach elem [lrange $item $firstCol $lastCol] {
lappend result $elem
}
}
return $result
}
}
#------------------------------------------------------------------------------
# tablelist::getcolumnsSubCmd
#------------------------------------------------------------------------------
proc tablelist::getcolumnsSubCmd {win argList} {
set argCount [llength $argList]
if {$argCount < 1 || $argCount > 2} {
mwutil::wrongNumArgs \
"$win getcolumns firstColumnIndex lastColumnIndex" \
"$win getcolumns columnIndexList"
}
synchronize $win
set first [lindex $argList 0]
#
# Get the specified columns from the internal list
#
upvar ::tablelist::ns${win}::data data
set result {}
if {$argCount == 1} {
foreach elem $first {
set col [colIndex $win $elem 1]
set colResult {}
foreach item $data(itemList) {
lappend colResult [lindex $item $col]
}
lappend result $colResult
}
if {[llength $first] == 1} {
return [lindex $result 0]
} else {
return $result
}
} else {
set first [colIndex $win $first 1]
set last [colIndex $win [lindex $argList 1] 1]
for {set col $first} {$col <= $last} {incr col} {
set colResult {}
foreach item $data(itemList) {
lappend colResult [lindex $item $col]
}
lappend result $colResult
}
return $result
}
}
#------------------------------------------------------------------------------
# tablelist::getkeysSubCmd
#------------------------------------------------------------------------------
proc tablelist::getkeysSubCmd {win argList} {
set argCount [llength $argList]
if {$argCount < 1 || $argCount > 2} {
mwutil::wrongNumArgs "$win getkeys firstIndex lastIndex" \
"$win getkeys indexList"
}
synchronize $win
set first [lindex $argList 0]
#
# Get the specified keys from the internal list
#
upvar ::tablelist::ns${win}::data data
set result {}
if {$argCount == 1} {
foreach elem $first {
set index [rowIndex $win $elem 0]
if {$index >= 0 && $index < $data(itemCount)} {
set item [lindex $data(itemList) $index]
lappend result [string range [lindex $item end] 1 end]
}
}
if {[llength $first] == 1} {
return [lindex $result 0]
} else {
return $result
}
} else {
set first [rowIndex $win $first 0]
set last [rowIndex $win [lindex $argList 1] 0]
#
# Adjust the range to fit within the existing items
#
if {$first > $data(lastRow)} {
return {}
}
if {$first < 0} {
set first 0
}
if {$last > $data(lastRow)} {
set last $data(lastRow)
}
foreach item [lrange $data(itemList) $first $last] {
lappend result [string range [lindex $item end] 1 end]
}
return $result
}
}
#------------------------------------------------------------------------------
# tablelist::hasattribSubCmd
#------------------------------------------------------------------------------
proc tablelist::hasattribSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win hasattrib name"
}
return [mwutil::hasattribSubCmd $win "widget" [lindex $argList 0]]
}
#------------------------------------------------------------------------------
# tablelist::hascellattribSubCmd
#------------------------------------------------------------------------------
proc tablelist::hascellattribSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win hascellattrib cellIndex name"
}
synchronize $win
foreach {row col} [cellIndex $win [lindex $argList 0] 1] {}
upvar ::tablelist::ns${win}::data data
set key [lindex [lindex $data(itemList) $row] end]
return [mwutil::hasattribSubCmd $win $key,$col [lindex $argList 1]]
}
#------------------------------------------------------------------------------
# tablelist::hascolumnattribSubCmd
#------------------------------------------------------------------------------
proc tablelist::hascolumnattribSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win hascolumnattrib columnIndex name"
}
synchronize $win
set col [colIndex $win [lindex $argList 0] 1]
return [mwutil::hasattribSubCmd $win $col [lindex $argList 1]]
}
#------------------------------------------------------------------------------
# tablelist::hasrowattribSubCmd
#------------------------------------------------------------------------------
proc tablelist::hasrowattribSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win hasrowattrib index name"
}
synchronize $win
set rowSpec [lindex $argList 0]
set row [rowIndex $win $rowSpec 0]
upvar ::tablelist::ns${win}::data data
if {$row < 0 || $row > $data(lastRow)} {
return -code error "row index \"$rowSpec\" out of range"
}
set key [lindex [lindex $data(itemList) $row] end]
return [mwutil::hasattribSubCmd $win $key [lindex $argList 1]]
}
#------------------------------------------------------------------------------
# tablelist::imagelabelpathSubCmd
#------------------------------------------------------------------------------
proc tablelist::imagelabelpathSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win imagelabelpath cellIndex"
}
synchronize $win
foreach {row col} [cellIndex $win [lindex $argList 0] 1] {}
upvar ::tablelist::ns${win}::data data
set key [lindex [lindex $data(itemList) $row] end]
set w $data(body).l$key,$col
if {[winfo exists $w]} {
return $w
} else {
return ""
}
}
#------------------------------------------------------------------------------
# tablelist::indexSubCmd
#------------------------------------------------------------------------------
proc tablelist::indexSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win index index"
}
synchronize $win
return [rowIndex $win [lindex $argList 0] 1]
}
#------------------------------------------------------------------------------
# tablelist::insertSubCmd
#------------------------------------------------------------------------------
proc tablelist::insertSubCmd {win argList} {
if {[llength $argList] < 1} {
mwutil::wrongNumArgs "$win insert index ?item item ...?"
}
synchronize $win
set index [rowIndex $win [lindex $argList 0] 1]
upvar ::tablelist::ns${win}::data data
return [insertRows $win $index [lrange $argList 1 end] $data(hasListVar)]
}
#------------------------------------------------------------------------------
# tablelist::insertcolumnlistSubCmd
#------------------------------------------------------------------------------
proc tablelist::insertcolumnlistSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win insertcolumnlist columnIndex columnList"
}
synchronize $win
displayItems $win
set arg0 [lindex $argList 0]
upvar ::tablelist::ns${win}::data data
if {[string first $arg0 "end"] == 0 || $arg0 == $data(colCount)} {
set col $data(colCount)
} else {
set col [colIndex $win $arg0 1]
}
return [insertCols $win $col [lindex $argList 1]]
}
#------------------------------------------------------------------------------
# tablelist::insertcolumnsSubCmd
#------------------------------------------------------------------------------
proc tablelist::insertcolumnsSubCmd {win argList} {
if {[llength $argList] < 1} {
mwutil::wrongNumArgs "$win insertcolumns columnIndex\
?width title ?alignment? width title ?alignment? ...?"
}
synchronize $win
displayItems $win
set arg0 [lindex $argList 0]
upvar ::tablelist::ns${win}::data data
if {[string first $arg0 "end"] == 0 || $arg0 == $data(colCount)} {
set col $data(colCount)
} else {
set col [colIndex $win $arg0 1]
}
return [insertCols $win $col [lrange $argList 1 end]]
}
#------------------------------------------------------------------------------
# tablelist::insertlistSubCmd
#------------------------------------------------------------------------------
proc tablelist::insertlistSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win insertlist index list"
}
synchronize $win
set index [rowIndex $win [lindex $argList 0] 1]
upvar ::tablelist::ns${win}::data data
return [insertRows $win $index [lindex $argList 1] $data(hasListVar)]
}
#------------------------------------------------------------------------------
# tablelist::iselemsnippedSubCmd
#------------------------------------------------------------------------------
proc tablelist::iselemsnippedSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win iselemsnipped cellIndex fullTextName"
}
synchronize $win
displayItems $win
foreach {row col} [cellIndex $win [lindex $argList 0] 1] {}
set fullTextName [lindex $argList 1]
upvar 2 $fullTextName fullText
upvar ::tablelist::ns${win}::data data
set item [lindex $data(itemList) $row]
set key [lindex $item end]
set fullText [lindex $item $col]
if {[lindex $data(fmtCmdFlagList) $col]} {
set fullText [formatElem $win $key $row $col $fullText]
}
set fullText [strToDispStr $fullText]
set pixels [lindex $data(colList) [expr {2*$col}]]
if {$pixels == 0} { ;# convention: dynamic width
if {$data($col-maxPixels) > 0 &&
$data($col-reqPixels) > $data($col-maxPixels)} {
set pixels $data($col-maxPixels)
}
}
if {$pixels == 0 || $data($col-wrap)} {
return 0
}
set text $fullText
getAuxData $win $key $col auxType auxWidth $pixels
set cellFont [getCellFont $win $key $col]
incr pixels $data($col-delta)
if {[string match "*\n*" $text]} {
set list [split $text "\n"]
adjustMlElem $win list auxWidth $cellFont $pixels "r" ""
set text [join $list "\n"]
} else {
adjustElem $win text auxWidth $cellFont $pixels "r" ""
}
return [expr {[string compare $text $fullText] != 0}]
}
#------------------------------------------------------------------------------
# tablelist::istitlesnippedSubCmd
#------------------------------------------------------------------------------
proc tablelist::istitlesnippedSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win istitlesnipped columnIndex fullTextName"
}
set col [colIndex $win [lindex $argList 0] 1]
set fullTextName [lindex $argList 1]
upvar 2 $fullTextName fullText
upvar ::tablelist::ns${win}::data data
set fullText [lindex $data(-columns) [expr {3*$col + 1}]]
return $data($col-isSnipped)
}
#------------------------------------------------------------------------------
# tablelist::itemlistvarSubCmd
#------------------------------------------------------------------------------
proc tablelist::itemlistvarSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win itemlistvar"
}
return ::tablelist::ns${win}::data(itemList)
}
#------------------------------------------------------------------------------
# tablelist::labelpathSubCmd
#------------------------------------------------------------------------------
proc tablelist::labelpathSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win labelpath columnIndex"
}
set col [colIndex $win [lindex $argList 0] 1]
upvar ::tablelist::ns${win}::data data
return $data(hdrTxtFrLbl)$col
}
#------------------------------------------------------------------------------
# tablelist::labelsSubCmd
#------------------------------------------------------------------------------
proc tablelist::labelsSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win labels"
}
upvar ::tablelist::ns${win}::data data
set labelList {}
for {set col 0} {$col < $data(colCount)} {incr col} {
lappend labelList $data(hdrTxtFrLbl)$col
}
return $labelList
}
#------------------------------------------------------------------------------
# tablelist::moveSubCmd
#------------------------------------------------------------------------------
proc tablelist::moveSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win move sourceIndex targetIndex"
}
synchronize $win
displayItems $win
set source [rowIndex $win [lindex $argList 0] 0]
set target [rowIndex $win [lindex $argList 1] 1]
return [moveRow $win $source $target]
}
#------------------------------------------------------------------------------
# tablelist::movecolumnSubCmd
#------------------------------------------------------------------------------
proc tablelist::movecolumnSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win movecolumn sourceColumnIndex\
targetColumnIndex"
}
synchronize $win
displayItems $win
set arg0 [lindex $argList 0]
set source [colIndex $win $arg0 1]
set arg1 [lindex $argList 1]
upvar ::tablelist::ns${win}::data data
if {[string first $arg1 "end"] == 0 || $arg1 == $data(colCount)} {
set target $data(colCount)
} else {
set target [colIndex $win $arg1 1]
}
return [moveCol $win $source $target]
}
#------------------------------------------------------------------------------
# tablelist::nearestSubCmd
#------------------------------------------------------------------------------
proc tablelist::nearestSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win nearest y"
}
set y [format "%d" [lindex $argList 0]]
synchronize $win
displayItems $win
return [rowIndex $win @0,$y 0]
}
#------------------------------------------------------------------------------
# tablelist::nearestcellSubCmd
#------------------------------------------------------------------------------
proc tablelist::nearestcellSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win nearestcell x y"
}
set x [format "%d" [lindex $argList 0]]
set y [format "%d" [lindex $argList 1]]
synchronize $win
displayItems $win
return [join [cellIndex $win @$x,$y 0] ","]
}
#------------------------------------------------------------------------------
# tablelist::nearestcolumnSubCmd
#------------------------------------------------------------------------------
proc tablelist::nearestcolumnSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win nearestcolumn x"
}
set x [format "%d" [lindex $argList 0]]
synchronize $win
displayItems $win
return [colIndex $win @$x,0 0]
}
#------------------------------------------------------------------------------
# tablelist::rejectinputSubCmd
#------------------------------------------------------------------------------
proc tablelist::rejectinputSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win rejectinput"
}
upvar ::tablelist::ns${win}::data data
set data(rejected) 1
}
#------------------------------------------------------------------------------
# tablelist::resetsortinfoSubCmd
#------------------------------------------------------------------------------
proc tablelist::resetsortinfoSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win resetsortinfo"
}
upvar ::tablelist::ns${win}::data data
foreach col $data(sortColList) {
set data($col-sortRank) 0
set data($col-sortOrder) ""
}
set whichWidths {}
foreach col $data(arrowColList) {
lappend whichWidths l$col
}
set data(sortColList) {}
set data(arrowColList) {}
set data(sortOrder) {}
if {[llength $whichWidths] > 0} {
synchronize $win
displayItems $win
adjustColumns $win $whichWidths 1
}
return ""
}
#------------------------------------------------------------------------------
# tablelist::rowattribSubCmd
#------------------------------------------------------------------------------
proc tablelist::rowattribSubCmd {win argList} {
if {[llength $argList] < 1} {
mwutil::wrongNumArgs "$win rowattrib index ?name? ?value\
name value ...?"
}
synchronize $win
set rowSpec [lindex $argList 0]
set row [rowIndex $win $rowSpec 0]
upvar ::tablelist::ns${win}::data data
if {$row < 0 || $row > $data(lastRow)} {
return -code error "row index \"$rowSpec\" out of range"
}
set key [lindex [lindex $data(itemList) $row] end]
return [mwutil::attribSubCmd $win $key [lrange $argList 1 end]]
}
#------------------------------------------------------------------------------
# tablelist::rowcgetSubCmd
#------------------------------------------------------------------------------
proc tablelist::rowcgetSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win rowcget index option"
}
synchronize $win
set rowArg [lindex $argList 0]
set row [rowIndex $win $rowArg 0]
upvar ::tablelist::ns${win}::data data
if {$row < 0 || $row > $data(lastRow)} {
return -code error "row index \"$rowArg\" out of range"
}
variable rowConfigSpecs
set opt [mwutil::fullConfigOpt [lindex $argList 1] rowConfigSpecs]
return [doRowCget $row $win $opt]
}
#------------------------------------------------------------------------------
# tablelist::rowconfigureSubCmd
#------------------------------------------------------------------------------
proc tablelist::rowconfigureSubCmd {win argList} {
if {[llength $argList] < 1} {
mwutil::wrongNumArgs "$win rowconfigure index ?option? ?value\
option value ...?"
}
synchronize $win
displayItems $win
variable rowConfigSpecs
set rowSpec [lindex $argList 0]
set row [rowIndex $win $rowSpec 0]
upvar ::tablelist::ns${win}::data data
if {$row < 0 || $row > $data(lastRow)} {
return -code error "row index \"$rowSpec\" out of range"
}
return [mwutil::configureSubCmd $win rowConfigSpecs \
"tablelist::doRowConfig $row" "tablelist::doRowCget $row" \
[lrange $argList 1 end]]
}
#------------------------------------------------------------------------------
# tablelist::scanSubCmd
#------------------------------------------------------------------------------
proc tablelist::scanSubCmd {win argList} {
if {[llength $argList] != 3} {
mwutil::wrongNumArgs "$win scan mark|dragto x y"
}
set x [format "%d" [lindex $argList 1]]
set y [format "%d" [lindex $argList 2]]
variable scanCmdOpts
set opt [mwutil::fullOpt "option" [lindex $argList 0] $scanCmdOpts]
synchronize $win
displayItems $win
return [doScan $win $opt $x $y]
}
#------------------------------------------------------------------------------
# tablelist::seeSubCmd
#------------------------------------------------------------------------------
proc tablelist::seeSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win see index"
}
synchronize $win
displayItems $win
set index [rowIndex $win [lindex $argList 0] 0]
return [seeRow $win $index]
}
#------------------------------------------------------------------------------
# tablelist::seecellSubCmd
#------------------------------------------------------------------------------
proc tablelist::seecellSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win seecell cellIndex"
}
synchronize $win
displayItems $win
foreach {row col} [cellIndex $win [lindex $argList 0] 0] {}
if {[winfo viewable $win]} {
return [seeCell $win $row $col]
} else {
after idle [list tablelist::seeCell $win $row $col]
return ""
}
}
#------------------------------------------------------------------------------
# tablelist::seecolumnSubCmd
#------------------------------------------------------------------------------
proc tablelist::seecolumnSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win seecolumn columnIndex"
}
synchronize $win
displayItems $win
set col [colIndex $win [lindex $argList 0] 0]
if {[winfo viewable $win]} {
return [seeCell $win [rowIndex $win @0,0 0] $col]
} else {
after idle [list tablelist::seeCell $win [rowIndex $win @0,0 0] $col]
return ""
}
}
#------------------------------------------------------------------------------
# tablelist::selectionSubCmd
#------------------------------------------------------------------------------
proc tablelist::selectionSubCmd {win argList} {
set argCount [llength $argList]
if {$argCount < 2 || $argCount > 3} {
mwutil::wrongNumArgs "$win selection option firstIndex lastIndex" \
"$win selection option indexList"
}
synchronize $win
displayItems $win
variable selCmdOpts
set opt [mwutil::fullOpt "option" [lindex $argList 0] $selCmdOpts]
set first [lindex $argList 1]
switch $opt {
anchor -
includes {
if {$argCount != 2} {
mwutil::wrongNumArgs "$win selection $opt index"
}
set index [rowIndex $win $first 0]
return [rowSelection $win $opt $index $index]
}
clear -
set {
if {$argCount == 2} {
foreach elem $first {
set index [rowIndex $win $elem 0]
rowSelection $win $opt $index $index
}
return ""
} else {
set first [rowIndex $win $first 0]
set last [rowIndex $win [lindex $argList 2] 0]
return [rowSelection $win $opt $first $last]
}
}
}
}
#------------------------------------------------------------------------------
# tablelist::separatorpathSubCmd
#------------------------------------------------------------------------------
proc tablelist::separatorpathSubCmd {win argList} {
set argCount [llength $argList]
if {$argCount > 1} {
mwutil::wrongNumArgs "$win separatorpath ?columnIndex?"
}
upvar ::tablelist::ns${win}::data data
if {$argCount == 0} {
if {[winfo exists $data(sep)]} {
return $data(sep)
} else {
return ""
}
} else {
set col [colIndex $win [lindex $argList 0] 1]
if {$data(-showseparators)} {
return $data(sep)$col
} else {
return ""
}
}
}
#------------------------------------------------------------------------------
# tablelist::separatorsSubCmd
#------------------------------------------------------------------------------
proc tablelist::separatorsSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win separators"
}
set sepList {}
foreach w [winfo children $win] {
if {[regexp {^sep([0-9]+)?$} [winfo name $w]]} {
lappend sepList $w
}
}
return [lsort -dictionary $sepList]
}
#------------------------------------------------------------------------------
# tablelist::sizeSubCmd
#------------------------------------------------------------------------------
proc tablelist::sizeSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win size"
}
synchronize $win
upvar ::tablelist::ns${win}::data data
return $data(itemCount)
}
#------------------------------------------------------------------------------
# tablelist::sortSubCmd
#------------------------------------------------------------------------------
proc tablelist::sortSubCmd {win argList} {
set argCount [llength $argList]
if {$argCount > 1} {
mwutil::wrongNumArgs "$win sort ?-increasing|-decreasing?"
}
if {$argCount == 0} {
set order -increasing
} else {
variable _sortOrders
set order [mwutil::fullOpt "option" [lindex $argList 0] $_sortOrders]
}
synchronize $win
displayItems $win
return [sortItems $win -1 [string range $order 1 end]]
}
#------------------------------------------------------------------------------
# tablelist::sortbycolumnSubCmd
#------------------------------------------------------------------------------
proc tablelist::sortbycolumnSubCmd {win argList} {
set argCount [llength $argList]
if {$argCount < 1 || $argCount > 2} {
mwutil::wrongNumArgs "$win sortbycolumn columnIndex\
?-increasing|-decreasing?"
}
synchronize $win
displayItems $win
set col [colIndex $win [lindex $argList 0] 1]
if {$argCount == 1} {
set order -increasing
} else {
variable _sortOrders
set order [mwutil::fullOpt "option" [lindex $argList 1] $_sortOrders]
}
return [sortItems $win $col [string range $order 1 end]]
}
#------------------------------------------------------------------------------
# tablelist::sortbycolumnlistSubCmd
#------------------------------------------------------------------------------
proc tablelist::sortbycolumnlistSubCmd {win argList} {
set argCount [llength $argList]
if {$argCount < 1 || $argCount > 2} {
mwutil::wrongNumArgs "$win sortbycolumnlist columnIndexList\
?sortOrderList?"
}
synchronize $win
displayItems $win
set sortColList {}
foreach elem [lindex $argList 0] {
set col [colIndex $win $elem 1]
if {[lsearch -exact $sortColList $col] >= 0} {
return -code error "duplicate column index \"$elem\""
}
lappend sortColList $col
}
set sortOrderList {}
if {$argCount == 2} {
variable sortOrders
foreach elem [lindex $argList 1] {
lappend sortOrderList [mwutil::fullOpt "option" $elem $sortOrders]
}
}
return [sortItems $win $sortColList $sortOrderList]
}
#------------------------------------------------------------------------------
# tablelist::sortcolumnSubCmd
#------------------------------------------------------------------------------
proc tablelist::sortcolumnSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win sortcolumn"
}
upvar ::tablelist::ns${win}::data data
if {[llength $data(sortColList)] == 0} {
return -1
} else {
return [lindex $data(sortColList) 0]
}
}
#------------------------------------------------------------------------------
# tablelist::sortcolumnlistSubCmd
#------------------------------------------------------------------------------
proc tablelist::sortcolumnlistSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win sortcolumnlist"
}
upvar ::tablelist::ns${win}::data data
return $data(sortColList)
}
#------------------------------------------------------------------------------
# tablelist::sortorderSubCmd
#------------------------------------------------------------------------------
proc tablelist::sortorderSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win sortorder"
}
upvar ::tablelist::ns${win}::data data
if {[llength $data(sortColList)] == 0} {
return $data(sortOrder)
} else {
set col [lindex $data(sortColList) 0]
return $data($col-sortOrder)
}
}
#------------------------------------------------------------------------------
# tablelist::sortorderlistSubCmd
#------------------------------------------------------------------------------
proc tablelist::sortorderlistSubCmd {win argList} {
if {[llength $argList] != 0} {
mwutil::wrongNumArgs "$win sortorderlist"
}
upvar ::tablelist::ns${win}::data data
set sortOrderList {}
foreach col $data(sortColList) {
lappend sortOrderList $data($col-sortOrder)
}
return $sortOrderList
}
#------------------------------------------------------------------------------
# tablelist::togglecolumnhideSubCmd
#------------------------------------------------------------------------------
proc tablelist::togglecolumnhideSubCmd {win argList} {
set argCount [llength $argList]
if {$argCount < 1 || $argCount > 2} {
mwutil::wrongNumArgs \
"$win togglecolumnhide firstColumnIndex lastColumnIndex" \
"$win togglecolumnhide columnIndexList"
}
synchronize $win
displayItems $win
set first [lindex $argList 0]
#
# Toggle the value of the -hide option of the specified columns
#
variable canElide
if {!$canElide} {
set selCells [curCellSelection $win]
}
upvar ::tablelist::ns${win}::data data
set colIdxList {}
if {$argCount == 1} {
foreach elem $first {
set col [colIndex $win $elem 1]
if {$canElide && !$data($col-hide)} {
cellSelection $win clear 0 $col $data(lastRow) $col
}
set data($col-hide) [expr {!$data($col-hide)}]
if {$data($col-hide)} {
incr data(hiddenColCount)
if {$col == $data(editCol)} {
doCancelEditing $win
}
} else {
incr data(hiddenColCount) -1
}
lappend colIdxList $col
}
} else {
set first [colIndex $win $first 1]
set last [colIndex $win [lindex $argList 1] 1]
for {set col $first} {$col <= $last} {incr col} {
if {$canElide && !$data($col-hide)} {
cellSelection $win clear 0 $col $data(lastRow) $col
}
set data($col-hide) [expr {!$data($col-hide)}]
if {$data($col-hide)} {
incr data(hiddenColCount)
if {$col == $data(editCol)} {
doCancelEditing $win
}
} else {
incr data(hiddenColCount) -1
}
lappend colIdxList $col
}
}
if {[llength $colIdxList] == 0} {
return ""
}
#
# Adjust the columns and redisplay the items
#
makeColFontAndTagLists $win
adjustColumns $win $colIdxList 1
adjustColIndex $win data(anchorCol) 1
adjustColIndex $win data(activeCol) 1
if {$canElide} {
adjustElidedTextWhenIdle $win
} else {
redisplay $win 0 $selCells
}
if {[string compare $data(-selecttype) "row"] == 0} {
foreach row [curSelection $win] {
rowSelection $win set $row $row
}
}
return ""
}
#------------------------------------------------------------------------------
# tablelist::togglerowhideSubCmd
#------------------------------------------------------------------------------
proc tablelist::togglerowhideSubCmd {win argList} {
set argCount [llength $argList]
if {$argCount < 1 || $argCount > 2} {
mwutil::wrongNumArgs "$win togglerowhide firstIndex lastIndex" \
"$win togglerowhide indexList"
}
synchronize $win
displayItems $win
set first [lindex $argList 0]
#
# Toggle the value of the -hide option of the specified rows
#
upvar ::tablelist::ns${win}::data data
if {$argCount == 1} {
foreach elem $first {
set row [rowIndex $win $elem 0]
if {$row < 0 || $row > $data(lastRow)} {
return -code error "row index \"$elem\" out of range"
}
doRowConfig $row $win -hide [expr {![doRowCget $row $win -hide]}]
}
} else {
set firstRow [rowIndex $win $first 0]
if {$firstRow < 0 || $firstRow > $data(lastRow)} {
return -code error "row index \"$first\" out of range"
}
set lastRow [rowIndex $win [lindex $argList 1] 0]
if {$lastRow < 0 || $lastRow > $data(lastRow)} {
return -code error "row index \"$last\" out of range"
}
for {set row $firstRow} {$row <= $lastRow} {incr row} {
doRowConfig $row $win -hide [expr {![doRowCget $row $win -hide]}]
}
}
}
#------------------------------------------------------------------------------
# tablelist::unsetattribSubCmd
#------------------------------------------------------------------------------
proc tablelist::unsetattribSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win unsetattrib name"
}
return [mwutil::unsetattribSubCmd $win "widget" [lindex $argList 0]]
}
#------------------------------------------------------------------------------
# tablelist::unsetcellattribSubCmd
#------------------------------------------------------------------------------
proc tablelist::unsetcellattribSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win unsetcellattrib cellIndex name"
}
synchronize $win
foreach {row col} [cellIndex $win [lindex $argList 0] 1] {}
upvar ::tablelist::ns${win}::data data
set key [lindex [lindex $data(itemList) $row] end]
return [mwutil::unsetattribSubCmd $win $key,$col [lindex $argList 1]]
}
#------------------------------------------------------------------------------
# tablelist::unsetcolumnattribSubCmd
#------------------------------------------------------------------------------
proc tablelist::unsetcolumnattribSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win unsetcolumnattrib columnIndex name"
}
synchronize $win
set col [colIndex $win [lindex $argList 0] 1]
return [mwutil::unsetattribSubCmd $win $col [lindex $argList 1]]
}
#------------------------------------------------------------------------------
# tablelist::unsetrowattribSubCmd
#------------------------------------------------------------------------------
proc tablelist::unsetrowattribSubCmd {win argList} {
if {[llength $argList] != 2} {
mwutil::wrongNumArgs "$win unsetrowattrib index name"
}
synchronize $win
set rowSpec [lindex $argList 0]
set row [rowIndex $win $rowSpec 0]
upvar ::tablelist::ns${win}::data data
if {$row < 0 || $row > $data(lastRow)} {
return -code error "row index \"$rowSpec\" out of range"
}
set key [lindex [lindex $data(itemList) $row] end]
return [mwutil::unsetattribSubCmd $win $key [lindex $argList 1]]
}
#------------------------------------------------------------------------------
# tablelist::windowpathSubCmd
#------------------------------------------------------------------------------
proc tablelist::windowpathSubCmd {win argList} {
if {[llength $argList] != 1} {
mwutil::wrongNumArgs "$win windowpath cellIndex"
}
synchronize $win
foreach {row col} [cellIndex $win [lindex $argList 0] 1] {}
upvar ::tablelist::ns${win}::data data
set key [lindex [lindex $data(itemList) $row] end]
set w $data(body).f$key,$col.w
if {[winfo exists $w]} {
return $w
} else {
return ""
}
}
#------------------------------------------------------------------------------
# tablelist::xviewSubCmd
#------------------------------------------------------------------------------
proc tablelist::xviewSubCmd {win argList} {
synchronize $win
displayItems $win
upvar ::tablelist::ns${win}::data data
switch [llength $argList] {
0 {
#
# Command: $win xview
#
if {$data(-titlecolumns) == 0} {
return [$data(hdrTxt) xview]
} else {
set scrlWindowWidth [getScrlWindowWidth $win]
if {$scrlWindowWidth <= 0} {
return [list 0 0]
}
set scrlContentWidth [getScrlContentWidth $win 0 $data(lastCol)]
if {$scrlContentWidth == 0} {
return [list 0 1]
}
set scrlXOffset \
[scrlColOffsetToXOffset $win $data(scrlColOffset)]
set fraction1 [expr {$scrlXOffset/double($scrlContentWidth)}]
set fraction2 [expr {($scrlXOffset + $scrlWindowWidth)/
double($scrlContentWidth)}]
if {$fraction2 > 1.0} {
set fraction2 1.0
}
return [list [format "%g" $fraction1] [format "%g" $fraction2]]
}
}
1 {
#
# Command: $win xview <units>
#
set units [format "%d" [lindex $argList 0]]
if {$data(-titlecolumns) == 0} {
foreach w [list $data(hdrTxt) $data(body)] {
$w xview moveto 0
$w xview scroll $units units
}
} else {
changeScrlColOffset $win $units
updateColorsWhenIdle $win
}
return ""
}
default {
#
# Command: $win xview moveto <fraction>
# $win xview scroll <number> units|pages
#
set argList [mwutil::getScrollInfo $argList]
if {$data(-titlecolumns) == 0} {
foreach w [list $data(hdrTxt) $data(body)] {
eval [list $w xview] $argList
}
} else {
if {[string compare [lindex $argList 0] "moveto"] == 0} {
#
# Compute the new scrolled column offset
#
set fraction [lindex $argList 1]
set scrlContentWidth \
[getScrlContentWidth $win 0 $data(lastCol)]
set pixels [expr {int($fraction*$scrlContentWidth + 0.5)}]
set scrlColOffset [scrlXOffsetToColOffset $win $pixels]
#
# Increase the new scrolled column offset if necessary
#
if {$pixels + [getScrlWindowWidth $win] >=
$scrlContentWidth} {
incr scrlColOffset
}
changeScrlColOffset $win $scrlColOffset
} else {
set number [lindex $argList 1]
if {[string compare [lindex $argList 2] "units"] == 0} {
changeScrlColOffset $win \
[expr {$data(scrlColOffset) + $number}]
} else {
#
# Compute the new scrolled column offset
#
set scrlXOffset \
[scrlColOffsetToXOffset $win $data(scrlColOffset)]
set scrlWindowWidth [getScrlWindowWidth $win]
set deltaPixels [expr {$number*$scrlWindowWidth}]
set pixels [expr {$scrlXOffset + $deltaPixels}]
set scrlColOffset [scrlXOffsetToColOffset $win $pixels]
#
# Adjust the new scrolled column offset if necessary
#
if {$number < 0 &&
[getScrlContentWidth $win $scrlColOffset \
$data(lastCol)] -
[getScrlContentWidth $win $data(scrlColOffset) \
$data(lastCol)] > -$deltaPixels} {
incr scrlColOffset
}
if {$scrlColOffset == $data(scrlColOffset)} {
if {$number < 0} {
incr scrlColOffset -1
} elseif {$number > 0} {
incr scrlColOffset
}
}
changeScrlColOffset $win $scrlColOffset
}
}
updateColorsWhenIdle $win
}
variable winSys
if {[string compare $winSys "aqua"] == 0 && [winfo viewable $win]} {
#
# Work around some Tk bugs on Mac OS X Aqua
#
if {[winfo exists $data(bodyFr)]} {
lower $data(bodyFr)
raise $data(bodyFr)
}
update
}
return ""
}
}
}
#------------------------------------------------------------------------------
# tablelist::yviewSubCmd
#------------------------------------------------------------------------------
proc tablelist::yviewSubCmd {win argList} {
synchronize $win
displayItems $win
upvar ::tablelist::ns${win}::data data
set w $data(body)
switch [llength $argList] {
0 {
#
# Command: $win yview
#
set totalNonHiddenCount \
[expr {$data(itemCount) - $data(hiddenRowCount)}]
if {$totalNonHiddenCount == 0} {
return [list 0 1]
}
set btmY [expr {[winfo height $w] - 1}]
set topTextIdx [$w index @0,0]
set btmTextIdx [$w index @0,$btmY]
set topRow [expr {int($topTextIdx) - 1}]
set btmRow [expr {int($btmTextIdx) - 1}]
foreach {x y width height baselinePos} [$w dlineinfo $topTextIdx] {}
if {$y < 0} {
incr topRow ;# top row incomplete in vertical direction
}
foreach {x y width height baselinePos} [$w dlineinfo $btmTextIdx] {}
set y2 [expr {$y + $height}]
if {[string compare [$w index @0,$y] [$w index @0,$y2]] == 0} {
incr btmRow -1 ;# btm row incomplete in vertical direction
}
set upperNonHiddenCount \
[getNonHiddenRowCount $win 0 [expr {$topRow - 1}]]
set winNonHiddenCount [getNonHiddenRowCount $win $topRow $btmRow]
set fraction1 [expr {$upperNonHiddenCount/
double($totalNonHiddenCount)}]
set fraction2 [expr {($upperNonHiddenCount + $winNonHiddenCount)/
double($totalNonHiddenCount)}]
return [list [format "%g" $fraction1] [format "%g" $fraction2]]
}
1 {
#
# Command: $win yview <units>
#
set units [format "%d" [lindex $argList 0]]
$w yview [nonHiddenRowOffsetToRowIndex $win $units]
adjustElidedText $win
updateColorsWhenIdle $win
adjustSepsWhenIdle $win
updateVScrlbarWhenIdle $win
return ""
}
default {
#
# Command: $win yview moveto <fraction>
# $win yview scroll <number> units|pages
#
set argList [mwutil::getScrollInfo $argList]
if {[string compare [lindex $argList 0] "moveto"] == 0} {
set fraction [lindex $argList 1]
set totalNonHiddenCount \
[expr {$data(itemCount) - $data(hiddenRowCount)}]
set offset [expr {int($fraction*$totalNonHiddenCount + 0.5)}]
$w yview [nonHiddenRowOffsetToRowIndex $win $offset]
} else {
set number [lindex $argList 1]
if {[string compare [lindex $argList 2] "units"] == 0} {
set topRow [expr {int([$w index @0,0]) - 1}]
set upperNonHiddenCount \
[getNonHiddenRowCount $win 0 [expr {$topRow - 1}]]
set offset [expr {$upperNonHiddenCount + $number}]
$w yview [nonHiddenRowOffsetToRowIndex $win $offset]
} else {
set absNumber [expr {abs($number)}]
set btmY [expr {[winfo height $w] - 1}]
for {set n 0} {$n < $absNumber} {incr n} {
set topRow [expr {int([$w index @0,0]) - 1}]
set btmRow [expr {int([$w index @0,$btmY]) - 1}]
set upperNonHiddenCount \
[getNonHiddenRowCount $win 0 [expr {$topRow - 1}]]
set winNonHiddenCount \
[getNonHiddenRowCount $win $topRow $btmRow]
set delta [expr {$winNonHiddenCount - 2}]
if {$number < 0} {
set delta [expr {(-1)*$delta}]
}
set offset [expr {$upperNonHiddenCount + $delta}]
$w yview [nonHiddenRowOffsetToRowIndex $win $offset]
}
}
}
adjustElidedText $win
updateColorsWhenIdle $win
adjustSepsWhenIdle $win
updateVScrlbarWhenIdle $win
variable winSys
if {[string compare $winSys "aqua"] == 0 && [winfo viewable $win]} {
#
# Work around some Tk bugs on Mac OS X Aqua
#
if {[winfo exists $data(bodyFr)]} {
lower $data(bodyFr)
raise $data(bodyFr)
}
update
}
return ""
}
}
}
#------------------------------------------------------------------------------
# tablelist::cellSelection
#
# Processes the tablelist cellselection subcommand.
#------------------------------------------------------------------------------
proc tablelist::cellSelection {win opt firstRow firstCol lastRow lastCol} {
upvar ::tablelist::ns${win}::data data
if {$data(isDisabled) && [string compare $opt "includes"] != 0} {
return ""
}
switch $opt {
anchor {
#
# Adjust the row and column indices to fit
# within the existing non-hidden elements
#
adjustRowIndex $win firstRow 1
adjustColIndex $win firstCol 1
set data(anchorRow) $firstRow
set data(anchorCol) $firstCol
return ""
}
clear {
#
# Adjust the row and column indices
# to fit within the existing elements
#
if {$data(itemCount) == 0 || $data(colCount) == 0} {
return ""
}
adjustRowIndex $win firstRow
adjustColIndex $win firstCol
adjustRowIndex $win lastRow
adjustColIndex $win lastCol
#
# Swap the indices if necessary
#
if {$lastRow < $firstRow} {
set tmp $firstRow
set firstRow $lastRow
set lastRow $tmp
}
if {$lastCol < $firstCol} {
set tmp $firstCol
set firstCol $lastCol
set lastCol $tmp
}
#
# Shrink the column range to be delimited by non-hidden columns
#
while {$firstCol <= $lastCol && $data($firstCol-hide)} {
incr firstCol
}
if {$firstCol > $lastCol} {
return ""
}
while {$lastCol >= $firstCol && $data($lastCol-hide)} {
incr lastCol -1
}
set firstTextIdx [expr {$firstRow + 1}].0
set lastTextIdx [expr {$lastRow + 1}].end
#
# Find the (partly) selected lines of the body text
# widget in the text range specified by the two indices
#
set w $data(body)
variable canElide
variable elide
set selRange [$w tag nextrange select $firstTextIdx $lastTextIdx]
while {[llength $selRange] != 0} {
set selStart [lindex $selRange 0]
set line [expr {int($selStart)}]
set row [expr {$line - 1}]
set key [lindex [lindex $data(itemList) $row] end]
#
# Deselect the relevant elements of the row and handle
# the -(select)background and -(select)foreground
# cell and column configuration options for them
#
findTabs $win $line $firstCol $lastCol firstTabIdx lastTabIdx
set textIdx1 $firstTabIdx
for {set col $firstCol} {$col <= $lastCol} {incr col} {
if {$data($col-hide) && !$canElide} {
continue
}
set textIdx2 \
[$w search $elide "\t" $textIdx1+1c $lastTabIdx+1c]+1c
$w tag remove select $textIdx1 $textIdx2
foreach optTail {background foreground} {
set opt -select$optTail
foreach name [list $col$opt $key$opt $key,$col$opt] \
level [list col row cell] {
if {[info exists data($name)]} {
$w tag remove $level$opt-$data($name) \
$textIdx1 $textIdx2
}
}
foreach name [list $col-$optTail $key-$optTail \
$key,$col-$optTail] \
level [list col row cell] {
if {[info exists data($name)]} {
$w tag add $level-$optTail-$data($name) \
$textIdx1 $textIdx2
}
}
}
set textIdx1 $textIdx2
}
set selRange \
[$w tag nextrange select "$selStart lineend" $lastTextIdx]
}
updateColorsWhenIdle $win
return ""
}
includes {
variable canElide
if {$firstRow < 0 || $firstRow > $data(lastRow) || \
$firstCol < 0 || $firstCol > $data(lastCol) ||
($data($firstCol-hide) && !$canElide)} {
return 0
}
findTabs $win [expr {$firstRow + 1}] $firstCol $firstCol \
tabIdx1 tabIdx2
if {[lsearch -exact [$data(body) tag names $tabIdx1] select] < 0} {
return 0
} else {
return 1
}
}
set {
#
# Adjust the row and column indices
# to fit within the existing elements
#
if {$data(itemCount) == 0 || $data(colCount) == 0} {
return ""
}
adjustRowIndex $win firstRow
adjustColIndex $win firstCol
adjustRowIndex $win lastRow
adjustColIndex $win lastCol
#
# Swap the indices if necessary
#
if {$lastRow < $firstRow} {
set tmp $firstRow
set firstRow $lastRow
set lastRow $tmp
}
if {$lastCol < $firstCol} {
set tmp $firstCol
set firstCol $lastCol
set lastCol $tmp
}
#
# Shrink the column range to be delimited by non-hidden columns
#
while {$firstCol <= $lastCol && $data($firstCol-hide)} {
incr firstCol
}
if {$firstCol > $lastCol} {
return ""
}
while {$lastCol >= $firstCol && $data($lastCol-hide)} {
incr lastCol -1
}
set w $data(body)
variable canElide
variable elide
for {set row $firstRow; set line [expr {$firstRow + 1}]} \
{$row <= $lastRow} {set row $line; incr line} {
#
# Check whether the row is selectable and non-hidden
#
set key [lindex [lindex $data(itemList) $row] end]
if {[info exists data($key-selectable)] ||
[info exists data($key-hide)]} {
continue
}
#
# Select the relevant non-hidden elements of the row and
# handle the -(select)background and -(select)foreground
# cell and column configuration options for them
#
findTabs $win $line $firstCol $lastCol firstTabIdx lastTabIdx
set textIdx1 $firstTabIdx
for {set col $firstCol} {$col <= $lastCol} {incr col} {
if {$data($col-hide) && !$canElide} {
continue
}
set textIdx2 \
[$w search $elide "\t" $textIdx1+1c $lastTabIdx+1c]+1c
if {$data($col-hide)} {
set textIdx1 $textIdx2
continue
}
$w tag add select $textIdx1 $textIdx2
foreach optTail {background foreground} {
set opt -select$optTail
foreach name [list $col$opt $key$opt $key,$col$opt] \
level [list col row cell] {
if {[info exists data($name)]} {
$w tag add $level$opt-$data($name) \
$textIdx1 $textIdx2
}
}
foreach name [list $col-$optTail $key-$optTail \
$key,$col-$optTail] \
level [list col row cell] {
if {[info exists data($name)]} {
set tag $level-$optTail-$data($name)
$w tag remove $level-$optTail-$data($name) \
$textIdx1 $textIdx2
}
}
}
set textIdx1 $textIdx2
}
}
#
# If the selection is exported and there are any selected
# cells 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
#
if {$data(-exportselection) &&
[llength [$w tag nextrange select 1.0]] != 0} {
selection own -command \
[list ::tablelist::lostSelection $win] $win
}
updateColorsWhenIdle $win
return ""
}
}
}
#------------------------------------------------------------------------------
# tablelist::colWidth
#
# Processes the tablelist columnwidth subcommand.
#------------------------------------------------------------------------------
proc tablelist::colWidth {win col opt} {
upvar ::tablelist::ns${win}::data data
set pixels [lindex $data(colList) [expr {2*$col}]]
if {$pixels == 0} { ;# convention: dynamic width
set pixels $data($col-reqPixels)
if {$data($col-maxPixels) > 0} {
if {$pixels > $data($col-maxPixels)} {
set pixels $data($col-maxPixels)
}
}
}
switch -- $opt {
-requested { return $pixels }
-stretched { return [expr {$pixels + $data($col-delta)}] }
-total {
return [expr {$pixels + $data($col-delta) + 2*$data(charWidth)}]
}
}
}
#------------------------------------------------------------------------------
# tablelist::containingRow
#
# Processes the tablelist containing subcommand.
#------------------------------------------------------------------------------
proc tablelist::containingRow {win y} {
upvar ::tablelist::ns${win}::data data
if {$data(itemCount) == 0} {
return -1
}
set row [rowIndex $win @0,$y 0]
set w $data(body)
incr y -[winfo y $w]
if {$y < 0} {
return -1
}
set dlineinfo [$w dlineinfo [expr {double($row + 1)}]]
if {$y < [lindex $dlineinfo 1] + [lindex $dlineinfo 3]} {
return $row
} else {
return -1
}
}
#------------------------------------------------------------------------------
# tablelist::containingCol
#
# Processes the tablelist containingcolumn subcommand.
#------------------------------------------------------------------------------
proc tablelist::containingCol {win x} {
upvar ::tablelist::ns${win}::data data
if {$x < [winfo x $data(body)]} {
return -1
}
set col [colIndex $win @$x,0 0]
if {$col < 0} {
return -1
}
set lbl $data(hdrTxtFrLbl)$col
if {$x + [winfo rootx $win] < [winfo width $lbl] + [winfo rootx $lbl]} {
return $col
} else {
return -1
}
}
#------------------------------------------------------------------------------
# tablelist::curCellSelection
#
# Processes the tablelist curcellselection subcommand.
#------------------------------------------------------------------------------
proc tablelist::curCellSelection {win {getKeys 0}} {
variable canElide
variable elide
upvar ::tablelist::ns${win}::data data
#
# Find the (partly) selected lines of the body text widget
#
set result {}
set w $data(body)
set selRange [$w tag nextrange select 1.0]
while {[llength $selRange] != 0} {
foreach {selStart selEnd} $selRange {}
set line [expr {int($selStart)}]
set row [expr {$line - 1}]
#
# Get the index of the column starting at the text position selStart
#
set textIdx $line.0
for {set col 0} {$col < $data(colCount)} {incr col} {
if {!$data($col-hide) || $canElide} {
if {[$w compare $textIdx == $selStart]} {
set firstCol $col
break
} else {
set textIdx [$w search $elide "\t" $textIdx+1c $selEnd]+1c
}
}
}
#
# Process the columns, starting at the found one
# and ending just before the text position selEnd
#
if {$getKeys} {
set key [lindex [lindex $data(itemList) $row] end]
}
set textIdx [$w search $elide "\t" $textIdx+1c $selEnd]+1c
for {set col $firstCol} {$col < $data(colCount)} {incr col} {
if {!$data($col-hide) || $canElide} {
if {$getKeys} {
lappend result $key $col
} else {
lappend result $row,$col
}
if {[$w compare $textIdx == $selEnd]} {
break
} else {
set textIdx [$w search $elide "\t" $textIdx+1c $selEnd]+1c
}
}
}
set selRange [$w tag nextrange select $selEnd]
}
return $result
}
#------------------------------------------------------------------------------
# tablelist::curSelection
#
# Processes the tablelist curselection subcommand.
#------------------------------------------------------------------------------
proc tablelist::curSelection win {
#
# Find the (partly) selected lines of the body text widget
#
set result {}
upvar ::tablelist::ns${win}::data data
set w $data(body)
set selRange [$w tag nextrange select 1.0]
while {[llength $selRange] != 0} {
set selStart [lindex $selRange 0]
lappend result [expr {int($selStart) - 1}]
set selRange [$w tag nextrange select "$selStart lineend"]
}
return $result
}
#------------------------------------------------------------------------------
# tablelist::deleteRows
#
# Processes the tablelist delete subcommand.
#------------------------------------------------------------------------------
proc tablelist::deleteRows {win first last updateListVar} {
#
# Adjust the range to fit within the existing items
#
if {$first < 0} {
set first 0
}
upvar ::tablelist::ns${win}::data data \
::tablelist::ns${win}::attribs attribs
if {$last > $data(lastRow)} {
set last $data(lastRow)
}
set count [expr {$last - $first + 1}]
if {$count <= 0} {
return ""
}
#
# Check whether the width of any dynamic-width
# column might be affected by the deletion
#
set w $data(body)
set itemListRange [lrange $data(itemList) $first $last]
if {$count == $data(itemCount)} {
set colWidthsChanged 1 ;# just to save time
set data(seqNum) -1
set data(freeKeyList) {}
} else {
variable canElide
set colWidthsChanged 0
set snipStr $data(-snipstring)
set row 0
foreach item $itemListRange {
#
# Format the item
#
set key [lindex $item end]
set dispItem [lrange $item 0 $data(lastCol)]
if {$data(hasFmtCmds)} {
set dispItem [formatItem $win $key $row $dispItem]
}
set col 0
foreach text [strToDispStr $dispItem] \
{pixels alignment} $data(colList) {
if {($data($col-hide) && !$canElide) || $pixels != 0} {
incr col
continue
}
getAuxData $win $key $col auxType auxWidth
set cellFont [getCellFont $win $key $col]
set elemWidth [getElemWidth $win $text $auxWidth $cellFont]
if {$elemWidth == $data($col-elemWidth) &&
[incr data($col-widestCount) -1] == 0} {
set colWidthsChanged 1
break
}
incr col
}
if {$colWidthsChanged} {
break
}
incr row
}
}
#
# Delete the given items from the body text widget. Interestingly,
# for a large number of items it is much more efficient to delete
# each line individually than to invoke a global delete command.
#
set textIdx1 [expr {double($first + 1)}]
set textIdx2 [expr {double($first + 2)}]
foreach item $itemListRange {
$w delete $textIdx1 $textIdx2
set key [lindex $item end]
if {$count != $data(itemCount)} {
lappend data(freeKeyList) $key
}
foreach opt {-background -foreground -font} {
if {[info exists data($key$opt)]} {
unset data($key$opt)
incr data(rowTagRefCount) -1
}
}
if {[info exists data($key-hide)]} {
unset data($key-hide)
incr data(hiddenRowCount) -1
}
foreach opt {-name -selectable -selectbackground -selectforeground} {
if {[info exists data($key$opt)]} {
unset data($key$opt)
}
}
foreach name [array names attribs $key-*] {
unset attribs($name)
}
for {set col 0} {$col < $data(colCount)} {incr col} {
foreach opt {-background -foreground -font} {
if {[info exists data($key,$col$opt)]} {
unset data($key,$col$opt)
incr data(cellTagRefCount) -1
}
}
foreach opt {-editable -editwindow -selectbackground
-selectforeground -windowdestroy} {
if {[info exists data($key,$col$opt)]} {
unset data($key,$col$opt)
}
}
if {[info exists data($key,$col-image)]} {
unset data($key,$col-image)
incr data(imgCount) -1
}
if {[info exists data($key,$col-window)]} {
unset data($key,$col-window)
unset data($key,$col-reqWidth)
unset data($key,$col-reqHeight)
incr data(winCount) -1
}
}
foreach name [array names attribs $key,*-*] {
unset attribs($name)
}
}
#
# Delete the given items from the internal list
#
set data(itemList) [lreplace $data(itemList) $first $last]
incr data(itemCount) -$count
incr data(lastRow) -$count
#
# Delete the given items from the list variable if needed
#
if {$updateListVar} {
upvar #0 $data(-listvariable) var
trace vdelete var wu $data(listVarTraceCmd)
set var [lreplace $var $first $last]
trace variable var wu $data(listVarTraceCmd)
}
#
# Update the indices anchorRow and activeRow
#
if {$first <= $data(anchorRow)} {
incr data(anchorRow) -$count
if {$data(anchorRow) < $first} {
set data(anchorRow) $first
}
adjustRowIndex $win data(anchorRow) 1
}
if {$last < $data(activeRow)} {
incr data(activeRow) -$count
adjustRowIndex $win data(activeRow) 1
} elseif {$first <= $data(activeRow)} {
set data(activeRow) $first
adjustRowIndex $win data(activeRow) 1
}
#
# Update data(editRow) if the edit window is present
#
if {$data(editRow) >= 0} {
set data(editRow) [lsearch $data(itemList) "* $data(editKey)"]
}
#
# Adjust the heights of the body text widget
# and of the listbox child, if necessary
#
if {$data(-height) <= 0} {
set nonHiddenRowCount [expr {$data(itemCount) - $data(hiddenRowCount)}]
$w configure -height $nonHiddenRowCount
$data(lb) configure -height $nonHiddenRowCount
}
#
# Invalidate the list of the row indices indicating the
# non-hidden rows, adjust the columns if necessary, and
# schedule some operations for execution at idle time
#
set data(nonHiddenRowList) {-1}
if {$colWidthsChanged} {
adjustColumns $win allCols 1
}
adjustElidedTextWhenIdle $win
makeStripesWhenIdle $win
adjustSepsWhenIdle $win
updateVScrlbarWhenIdle $win
showLineNumbersWhenIdle $win
return ""
}
#------------------------------------------------------------------------------
# tablelist::deleteCols
#
# Processes the tablelist deletecolumns subcommand.
#------------------------------------------------------------------------------
proc tablelist::deleteCols {win first last selCellsName} {
upvar ::tablelist::ns${win}::data data \
::tablelist::ns${win}::attribs attribs $selCellsName selCells
#
# Delete the data and attributes corresponding to the given range
#
for {set col $first} {$col <= $last} {incr col} {
if {$data($col-hide)} {
incr data(hiddenColCount) -1
}
deleteColData $win $col
deleteColAttribs $win $col
set selCells [deleteColFromCellList $selCells $col]
}
#
# Shift the elements of data and attribs corresponding to the
# column indices > last to the left by last - first + 1 positions
#
for {set oldCol [expr {$last + 1}]; set newCol $first} \
{$oldCol < $data(colCount)} {incr oldCol; incr newCol} {
moveColData data data imgs $oldCol $newCol
moveColAttribs attribs attribs $oldCol $newCol
set selCells [replaceColInCellList $selCells $oldCol $newCol]
}
#
# Update the item list
#
set newItemList {}
foreach item $data(itemList) {
set item [lreplace $item $first $last]
lappend newItemList $item
}
set data(itemList) $newItemList
#
# Update the list variable if present
#
condUpdateListVar $win
#
# Set up and adjust the columns, and rebuild some columns-related lists
#
setupColumns $win \
[lreplace $data(-columns) [expr {3*$first}] [expr {3*$last + 2}]] 1
makeColFontAndTagLists $win
makeSortAndArrowColLists $win
adjustColumns $win {} 1
#
# Reconfigure the relevant column labels
#
for {set col $first} {$col < $data(colCount)} {incr col} {
reconfigColLabels $win imgs $col
}
#
# Update the indices anchorCol and activeCol
#
set count [expr {$last - $first + 1}]
if {$first <= $data(anchorCol)} {
incr data(anchorCol) -$count
if {$data(anchorCol) < $first} {
set data(anchorCol) $first
}
adjustColIndex $win data(anchorCol) 1
}
if {$last < $data(activeCol)} {
incr data(activeCol) -$count
adjustColIndex $win data(activeCol) 1
} elseif {$first <= $data(activeCol)} {
set data(activeCol) $first
adjustColIndex $win data(activeCol) 1
}
}
#------------------------------------------------------------------------------
# tablelist::insertRows
#
# Processes the tablelist insert and insertlist subcommands.
#------------------------------------------------------------------------------
proc tablelist::insertRows {win index argList updateListVar} {
set argCount [llength $argList]
upvar ::tablelist::ns${win}::data data
if {$argCount == 0 || $data(isDisabled)} {
return ""
}
if {$index < $data(itemCount)} {
displayItems $win
}
if {$index < 0} {
set index 0
} elseif {$index > $data(itemCount)} {
set index $data(itemCount)
}
#
# Insert the items into the internal list
#
set appending [expr {$index == $data(itemCount)}]
set row $index
foreach item $argList {
#
# Adjust the item
#
set item [adjustItem $item $data(colCount)]
#
# Get a free key for the new item
#
if {[llength $data(freeKeyList)] == 0} {
set key k[incr data(seqNum)]
} else {
set key [lindex $data(freeKeyList) 0]
set data(freeKeyList) [lrange $data(freeKeyList) 1 end]
}
#
# Insert the item into the list variable if needed
#
if {$updateListVar} {
upvar #0 $data(-listvariable) var
trace vdelete var wu $data(listVarTraceCmd)
if {$appending} {
lappend var $item ;# this works much faster
} else {
set var [linsert $var $row $item]
}
trace variable var wu $data(listVarTraceCmd)
}
#
# Insert the item into the internal list
#
lappend item $key
if {$appending} {
lappend data(itemList) $item ;# this works much faster
} else {
set data(itemList) [linsert $data(itemList) $row $item]
}
lappend data(rowsToDisplay) $row
incr row
}
incr data(itemCount) $argCount
set data(lastRow) [expr {$data(itemCount) - 1}]
if {![info exists data(dispId)]} {
#
# Arrange for the inserted items to be displayed at idle time
#
set data(dispId) [after idle [list tablelist::displayItems $win]]
}
#
# Update the indices anchorRow and activeRow
#
if {$index <= $data(anchorRow)} {
incr data(anchorRow) $argCount
adjustRowIndex $win data(anchorRow) 1
}
if {$index <= $data(activeRow)} {
incr data(activeRow) $argCount
adjustRowIndex $win data(activeRow) 1
}
#
# Update data(editRow) if the edit window is present
#
if {$data(editRow) >= 0} {
set data(editRow) [lsearch $data(itemList) "* $data(editKey)"]
}
return ""
}
#------------------------------------------------------------------------------
# tablelist::displayItems
#
# This procedure is invoked either as an idle callback after inserting some
# items into the internal list of the tablelist widget win, or directly, upon
# execution of some widget commands. It displays the inserted items.
#------------------------------------------------------------------------------
proc tablelist::displayItems win {
#
# Nothing to do if there are no items to display
#
upvar ::tablelist::ns${win}::data data
if {![info exists data(dispId)]} {
return ""
}
#
# Here we are in the case that the procedure was scheduled for
# execution at idle time. However, it might have been invoked
# directly, before the idle time occured; in this case we should
# cancel the execution of the previously scheduled idle callback.
#
after cancel $data(dispId) ;# no harm if data(dispId) is no longer valid
unset data(dispId)
#
# Insert the items into the body text widget and into the internal list
#
variable canElide
variable snipSides
set w $data(body)
set widgetFont $data(-font)
set snipStr $data(-snipstring)
set padY [expr {[$w cget -spacing1] == 0}]
set wasEmpty [expr {[llength $data(rowsToDisplay)] == $data(itemCount)}]
set isEmpty $wasEmpty
set colWidthsChanged 0
foreach row $data(rowsToDisplay) {
set line [expr {$row + 1}]
set item [lindex $data(itemList) $row]
set key [lindex $item end]
#
# Format the item
#
set dispItem [lrange $item 0 $data(lastCol)]
if {$data(hasFmtCmds)} {
set dispItem [formatItem $win $key $row $dispItem]
}
if {$isEmpty} {
set isEmpty 0
} else {
$w insert $line.0 "\n"
}
if {$data(hiddenRowCount) != 0} {
$w tag remove hiddenRow $line.0
}
set multilineData {}
set col 0
if {$data(hasColTags)} {
set insertArgs {}
foreach text [strToDispStr $dispItem] \
colFont $data(colFontList) \
colTags $data(colTagsList) \
{pixels alignment} $data(colList) {
if {$data($col-hide) && !$canElide} {
incr col
continue
}
#
# Update the column width or clip the element if necessary
#
set multiline [string match "*\n*" $text]
if {$pixels == 0} { ;# convention: dynamic width
if {$multiline} {
set list [split $text "\n"]
set textWidth [getListWidth $win $list $colFont]
} else {
set textWidth \
[font measure $colFont -displayof $win $text]
}
if {$data($col-maxPixels) > 0} {
if {$textWidth > $data($col-maxPixels)} {
set pixels $data($col-maxPixels)
}
}
if {$textWidth == $data($col-elemWidth)} {
incr data($col-widestCount)
} elseif {$textWidth > $data($col-elemWidth)} {
set data($col-elemWidth) $textWidth
set data($col-widestCount) 1
if {$textWidth > $data($col-reqPixels)} {
set data($col-reqPixels) $textWidth
set colWidthsChanged 1
}
}
}
if {$pixels != 0} {
incr pixels $data($col-delta)
if {$data($col-wrap) && !$multiline} {
if {[font measure $colFont -displayof $win $text] >
$pixels} {
set multiline 1
}
}
set snipSide \
$snipSides($alignment,$data($col-changesnipside))
if {$multiline} {
if {$data($col-wrap)} {
set snipSide ""
}
set list [split $text "\n"]
set text [joinList $win $list $colFont \
$pixels $snipSide $snipStr]
} else {
set text [strRange $win $text $colFont \
$pixels $snipSide $snipStr]
}
}
if {$multiline} {
lappend insertArgs "\t\t" $colTags
lappend multilineData $col $text $colFont $pixels $alignment
} else {
lappend insertArgs "\t$text\t" $colTags
}
incr col
}
#
# Insert the item into the body text widget
#
if {[llength $insertArgs] != 0} {
eval [list $w insert $line.0] $insertArgs
}
} else {
set insertStr ""
foreach text [strToDispStr $dispItem] \
{pixels alignment} $data(colList) {
if {$data($col-hide) && !$canElide} {
incr col
continue
}
#
# Update the column width or clip the element if necessary
#
set multiline [string match "*\n*" $text]
if {$pixels == 0} { ;# convention: dynamic width
if {$multiline} {
set list [split $text "\n"]
set textWidth [getListWidth $win $list $widgetFont]
} else {
set textWidth \
[font measure $widgetFont -displayof $win $text]
}
if {$data($col-maxPixels) > 0} {
if {$textWidth > $data($col-maxPixels)} {
set pixels $data($col-maxPixels)
}
}
if {$textWidth == $data($col-elemWidth)} {
incr data($col-widestCount)
} elseif {$textWidth > $data($col-elemWidth)} {
set data($col-elemWidth) $textWidth
set data($col-widestCount) 1
if {$textWidth > $data($col-reqPixels)} {
set data($col-reqPixels) $textWidth
set colWidthsChanged 1
}
}
}
if {$pixels != 0} {
incr pixels $data($col-delta)
if {$data($col-wrap) && !$multiline} {
if {[font measure $widgetFont -displayof $win $text] >
$pixels} {
set multiline 1
}
}
set snipSide \
$snipSides($alignment,$data($col-changesnipside))
if {$multiline} {
if {$data($col-wrap)} {
set snipSide ""
}
set list [split $text "\n"]
set text [joinList $win $list $widgetFont \
$pixels $snipSide $snipStr]
} else {
set text [strRange $win $text $widgetFont \
$pixels $snipSide $snipStr]
}
}
if {$multiline} {
append insertStr "\t\t"
lappend multilineData $col $text $widgetFont \
$pixels $alignment
} else {
append insertStr "\t$text\t"
}
incr col
}
#
# Insert the item into the body text widget
#
$w insert $line.0 $insertStr
}
#
# Embed the message widgets displaying multiline elements
#
foreach {col text font pixels alignment} $multilineData {
findTabs $win $line $col $col tabIdx1 tabIdx2
set msgScript [list ::tablelist::displayText $win $key \
$col $text $font $pixels $alignment]
$w window create $tabIdx2 -pady $padY -create $msgScript
}
}
unset data(rowsToDisplay)
#
# Adjust the heights of the body text widget
# and of the listbox child, if necessary
#
if {$data(-height) <= 0} {
set nonHiddenRowCount [expr {$data(itemCount) - $data(hiddenRowCount)}]
$w configure -height $nonHiddenRowCount
$data(lb) configure -height $nonHiddenRowCount
}
#
# Invalidate the list of the row indices indicating the
# non-hidden rows, adjust the columns if necessary, and
# schedule some operations for execution at idle time
#
set data(nonHiddenRowList) {-1}
if {$colWidthsChanged} {
adjustColumns $win {} 1
}
adjustElidedTextWhenIdle $win
makeStripesWhenIdle $win
adjustSepsWhenIdle $win
updateVScrlbarWhenIdle $win
showLineNumbersWhenIdle $win
activeTrace $win data activeRow w
if {$wasEmpty} {
$w xview moveto [lindex [$data(hdrTxt) xview] 0]
}
}
#------------------------------------------------------------------------------
# tablelist::insertCols
#
# Processes the tablelist insertcolumns and insertcolumnlist subcommands.
#------------------------------------------------------------------------------
proc tablelist::insertCols {win colIdx argList} {
set argCount [llength $argList]
upvar ::tablelist::ns${win}::data data \
::tablelist::ns${win}::attribs attribs
if {$argCount == 0 || $data(isDisabled)} {
return ""
}
#
# Check the syntax of argList and get the number of columns to be inserted
#
variable alignments
set count 0
for {set n 0} {$n < $argCount} {incr n} {
#
# Check the column width
#
format "%d" [lindex $argList $n] ;# integer check with error message
#
# Check whether the column title is present
#
if {[incr n] == $argCount} {
return -code error "column title missing"
}
#
# Check the column alignment
#
set alignment left
if {[incr n] < $argCount} {
set next [lindex $argList $n]
if {[catch {format "%d" $next}] == 0} { ;# integer check
incr n -1
} else {
mwutil::fullOpt "alignment" $next $alignments
}
}
incr count
}
#
# Shift the elements of data and attribs corresponding to the
# column indices >= colIdx to the right by count positions
#
set selCells [curCellSelection $win]
for {set oldCol $data(lastCol); set newCol [expr {$oldCol + $count}]} \
{$oldCol >= $colIdx} {incr oldCol -1; incr newCol -1} {
moveColData data data imgs $oldCol $newCol
moveColAttribs attribs attribs $oldCol $newCol
set selCells [replaceColInCellList $selCells $oldCol $newCol]
}
#
# Update the item list
#
set emptyStrs {}
for {set n 0} {$n < $count} {incr n} {
lappend emptyStrs ""
}
set newItemList {}
foreach item $data(itemList) {
set item [eval [list linsert $item $colIdx] $emptyStrs]
lappend newItemList $item
}
set data(itemList) $newItemList
#
# Update the list variable if present
#
condUpdateListVar $win
#
# Set up and adjust the columns, and rebuild some columns-related lists
#
setupColumns $win \
[eval [list linsert $data(-columns) [expr {3*$colIdx}]] $argList] 1
makeColFontAndTagLists $win
makeSortAndArrowColLists $win
set limit [expr {$colIdx + $count}]
set colIdxList {}
for {set col $colIdx} {$col < $limit} {incr col} {
lappend colIdxList $col
}
adjustColumns $win $colIdxList 1
#
# Reconfigure the relevant column labels
#
for {set col $limit} {$col < $data(colCount)} {incr col} {
reconfigColLabels $win imgs $col
}
#
# Redisplay the items
#
redisplay $win 0 $selCells
#
# Update the indices anchorCol and activeCol
#
if {$colIdx <= $data(anchorCol)} {
incr data(anchorCol) $argCount
adjustColIndex $win data(anchorCol) 1
}
if {$colIdx <= $data(activeCol)} {
incr data(activeCol) $argCount
adjustColIndex $win data(activeCol) 1
}
return ""
}
#------------------------------------------------------------------------------
# tablelist::doScan
#
# Processes the tablelist scan subcommand.
#------------------------------------------------------------------------------
proc tablelist::doScan {win opt x y} {
upvar ::tablelist::ns${win}::data data
set w $data(body)
incr x -[winfo x $w]
incr y -[winfo y $w]
if {$data(-titlecolumns) == 0} {
$w scan $opt $x $y
$data(hdrTxt) scan $opt $x 0
if {[string compare $opt "dragto"] == 0} {
adjustElidedText $win
updateColorsWhenIdle $win
adjustSepsWhenIdle $win
updateVScrlbarWhenIdle $win
}
} elseif {[string compare $opt "mark"] == 0} {
$w scan mark 0 $y
set data(scanMarkX) $x
set data(scanMarkXOffset) \
[scrlColOffsetToXOffset $win $data(scrlColOffset)]
} else {
$w scan dragto 0 $y
#
# Compute the new scrolled x offset by amplifying the
# difference between the current horizontal position and
# the place where the scan started (the "mark" position)
#
set scrlXOffset \
[expr {$data(scanMarkXOffset) - 10*($x - $data(scanMarkX))}]
set maxScrlXOffset [scrlColOffsetToXOffset $win \
[getMaxScrlColOffset $win]]
if {$scrlXOffset > $maxScrlXOffset} {
set scrlXOffset $maxScrlXOffset
set data(scanMarkX) $x
set data(scanMarkXOffset) $maxScrlXOffset
} elseif {$scrlXOffset < 0} {
set scrlXOffset 0
set data(scanMarkX) $x
set data(scanMarkXOffset) 0
}
#
# Change the scrolled column offset and adjust the elided text
#
changeScrlColOffset $win [scrlXOffsetToColOffset $win $scrlXOffset]
adjustElidedText $win
updateColorsWhenIdle $win
adjustSepsWhenIdle $win
updateVScrlbarWhenIdle $win
}
return ""
}
#------------------------------------------------------------------------------
# tablelist::seeRow
#
# Processes the tablelist see subcommand.
#------------------------------------------------------------------------------
proc tablelist::seeRow {win index} {
#
# Adjust the index to fit within the existing items
#
adjustRowIndex $win index
upvar ::tablelist::ns${win}::data data
set key [lindex [lindex $data(itemList) $index] end]
if {$data(itemCount) == 0 || [info exists data($key-hide)]} {
return ""
}
#
# Bring the given row into the window and restore
# the horizontal view in the body text widget
#
$data(body) see [expr {double($index + 1)}]
$data(body) xview moveto [lindex [$data(hdrTxt) xview] 0]
adjustElidedText $win
updateColorsWhenIdle $win
adjustSepsWhenIdle $win
updateVScrlbarWhenIdle $win
return ""
}
#------------------------------------------------------------------------------
# tablelist::seeCell
#
# Processes the tablelist seecell subcommand.
#------------------------------------------------------------------------------
proc tablelist::seeCell {win row col} {
#
# This might be an "after idle" callback; check whether the window exists
#
if {![winfo exists $win]} {
return ""
}
upvar ::tablelist::ns${win}::data data
set h $data(hdrTxt)
set b $data(body)
#
# Adjust the row and column indices to fit within the existing elements
#
adjustRowIndex $win row
adjustColIndex $win col
set key [lindex [lindex $data(itemList) $row] end]
if {[info exists data($key-hide)]} {
return ""
}
if {$data(colCount) == 0} {
$b see [expr {double($row + 1)}]
return ""
} elseif {$data($col-hide)} {
return ""
}
#
# Force any geometry manager calculations to be completed first
#
update idletasks
if {![winfo exists $win]} { ;# because of update idletasks
return ""
}
#
# If the tablelist is empty then insert a temporary row
#
if {$data(itemCount) == 0} {
variable canElide
for {set n 0} {$n < $data(colCount)} {incr n} {
if {!$data($n-hide) || $canElide} {
$b insert end "\t\t"
}
}
$b xview moveto [lindex [$h xview] 0]
}
if {$data(-titlecolumns) == 0} {
findTabs $win [expr {$row + 1}] $col $col tabIdx1 tabIdx2
set nextIdx [$b index $tabIdx2+1c]
set alignment [lindex $data(colList) [expr {2*$col + 1}]]
set lX [winfo x $data(hdrTxtFrLbl)$col]
set rX [expr {$lX + [winfo width $data(hdrTxtFrLbl)$col] - 1}]
switch $alignment {
left {
#
# Bring the cell's left edge into view
#
$b see $tabIdx1
$h xview moveto [lindex [$b xview] 0]
#
# Shift the view in the header text widget until the right
# edge of the cell becomes visible but finish the scrolling
# before the cell's left edge would become invisible
#
while {![isHdrTxtFrXPosVisible $win $rX]} {
$h xview scroll 1 units
if {![isHdrTxtFrXPosVisible $win $lX]} {
$h xview scroll -1 units
break
}
}
}
center {
#
# Bring the cell's left edge into view
#
$b see $tabIdx1
set winWidth [winfo width $h]
if {[winfo width $data(hdrTxtFrLbl)$col] > $winWidth} {
#
# The cell doesn't fit into the window: Bring its
# center into the window's middle horizontal position
#
$h xview moveto \
[expr {double($lX + $rX - $winWidth)/2/$data(hdrPixels)}]
} else {
#
# Shift the view in the header text widget until
# the right edge of the cell becomes visible
#
$h xview moveto [lindex [$b xview] 0]
while {![isHdrTxtFrXPosVisible $win $rX]} {
$h xview scroll 1 units
}
}
}
right {
#
# Bring the cell's right edge into view
#
$b see $nextIdx
$h xview moveto [lindex [$b xview] 0]
#
# Shift the view in the header text widget until the left
# edge of the cell becomes visible but finish the scrolling
# before the cell's right edge would become invisible
#
while {![isHdrTxtFrXPosVisible $win $lX]} {
$h xview scroll -1 units
if {![isHdrTxtFrXPosVisible $win $rX]} {
$h xview scroll 1 units
break
}
}
}
}
$b xview moveto [lindex [$h xview] 0]
} else {
#
# Bring the cell's row into view
#
$b see [expr {double($row + 1)}]
set scrlWindowWidth [getScrlWindowWidth $win]
if {($col < $data(-titlecolumns)) ||
(!$data($col-elide) &&
[getScrlContentWidth $win $data(scrlColOffset) $col] <=
$scrlWindowWidth)} {
#
# The given column index specifies either a title column or
# one that is fully visible; restore the horizontal view
#
$b xview moveto [lindex [$h xview] 0]
adjustElidedText $win
} elseif {$data($col-elide) ||
[winfo width $data(hdrTxtFrLbl)$col] > $scrlWindowWidth} {
#
# The given column index specifies either an elided column or one
# that doesn't fit into the window; shift the horizontal view to
# make the column the first visible one among all scrollable columns
#
set scrlColOffset 0
for {incr col -1} {$col >= $data(-titlecolumns)} {incr col -1} {
if {!$data($col-hide)} {
incr scrlColOffset
}
}
changeScrlColOffset $win $scrlColOffset
} else {
#
# The given column index specifies a non-elided
# scrollable column; shift the horizontal view
# repeatedly until the column becomes visible
#
set scrlColOffset [expr {$data(scrlColOffset) + 1}]
while {[getScrlContentWidth $win $scrlColOffset $col] >
$scrlWindowWidth} {
incr scrlColOffset
}
changeScrlColOffset $win $scrlColOffset
}
}
#
# Delete the temporary row if any
#
if {$data(itemCount) == 0} {
$b delete 1.0 end
}
updateColorsWhenIdle $win
adjustSepsWhenIdle $win
updateVScrlbarWhenIdle $win
return ""
}
#------------------------------------------------------------------------------
# tablelist::rowSelection
#
# Processes the tablelist selection subcommand.
#------------------------------------------------------------------------------
proc tablelist::rowSelection {win opt first last} {
upvar ::tablelist::ns${win}::data data
if {$data(isDisabled) && [string compare $opt "includes"] != 0} {
return ""
}
switch $opt {
anchor {
#
# Adjust the index to fit within the existing non-hidden items
#
adjustRowIndex $win first 1
set data(anchorRow) $first
return ""
}
clear {
#
# Swap the indices if necessary
#
if {$last < $first} {
set tmp $first
set first $last
set last $tmp
}
set firstTextIdx [expr {$first + 1}].0
set lastTextIdx [expr {$last + 1}].end
#
# Find the (partly) selected lines of the body text
# widget in the text range specified by the two indices
#
set w $data(body)
variable canElide
variable elide
set selRange [$w tag nextrange select $firstTextIdx $lastTextIdx]
while {[llength $selRange] != 0} {
set selStart [lindex $selRange 0]
$w tag remove select $selStart "$selStart lineend"
#
# Handle the -(select)background and -(select)foreground cell
# and column configuration options for each element of the row
#
set row [expr {int($selStart) - 1}]
set key [lindex [lindex $data(itemList) $row] end]
set textIdx1 "$selStart linestart"
for {set col 0} {$col < $data(colCount)} {incr col} {
if {$data($col-hide) && !$canElide} {
continue
}
set textIdx2 [$w search $elide "\t" \
$textIdx1+1c "$selStart lineend"]+1c
foreach optTail {background foreground} {
set opt -select$optTail
foreach name [list $col$opt $key$opt $key,$col$opt] \
level [list col row cell] {
if {[info exists data($name)]} {
$w tag remove $level$opt-$data($name) \
$textIdx1 $textIdx2
}
}
foreach name [list $col-$optTail $key-$optTail \
$key,$col-$optTail] \
level [list col row cell] {
if {[info exists data($name)]} {
$w tag add $level-$optTail-$data($name) \
$textIdx1 $textIdx2
}
}
}
set textIdx1 $textIdx2
}
set selRange \
[$w tag nextrange select "$selStart lineend" $lastTextIdx]
}
updateColorsWhenIdle $win
return ""
}
includes {
set w $data(body)
set textIdx [expr {double($first + 1)}]
set selRange [$w tag nextrange select $textIdx "$textIdx lineend"]
if {[llength $selRange] > 0} {
return 1
} else {
return 0
}
}
set {
#
# Swap the indices if necessary and adjust
# the range to fit within the existing items
#
if {$last < $first} {
set tmp $first
set first $last
set last $tmp
}
if {$first < 0} {
set first 0
}
if {$last > $data(lastRow)} {
set last $data(lastRow)
}
set w $data(body)
variable canElide
variable elide
for {set row $first; set line [expr {$first + 1}]} \
{$row <= $last} {set row $line; incr line} {
#
# Check whether the row is selectable and non-hidden
#
set key [lindex [lindex $data(itemList) $row] end]
if {[info exists data($key-selectable)] ||
[info exists data($key-hide)]} {
continue
}
#
# Select the non-hidden elements of the row and handle
# the -(select)background and -(select)foreground
# cell and column configuration options for them
#
set textIdx1 $line.0
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 {$data($col-hide)} {
set textIdx1 $textIdx2
continue
}
$w tag add select $textIdx1 $textIdx2
foreach optTail {background foreground} {
set opt -select$optTail
foreach name [list $col$opt $key$opt $key,$col$opt] \
level [list col row cell] {
if {[info exists data($name)]} {
$w tag add $level$opt-$data($name) \
$textIdx1 $textIdx2
}
}
foreach name [list $col-$optTail $key-$optTail \
$key,$col-$optTail] \
level [list col row cell] {
if {[info exists data($name)]} {
$w tag remove $level-$optTail-$data($name) \
$textIdx1 $textIdx2
}
}
}
set textIdx1 $textIdx2
}
}
#
# If the selection is exported and there are any selected
# cells 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
#
if {$data(-exportselection) &&
[llength [$w tag nextrange select 1.0]] != 0} {
selection own -command \
[list ::tablelist::lostSelection $win] $win
}
updateColorsWhenIdle $win
return ""
}
}
}
#
# Private callback procedures
# ===========================
#
#------------------------------------------------------------------------------
# tablelist::fetchSelection
#
# This procedure is invoked when the PRIMARY selection is owned by the
# tablelist widget win and someone attempts to retrieve it as a STRING. It
# returns part or all of the selection, as given by offset and maxChars. The
# string which is to be (partially) returned is built by joining all of the
# selected elements of the (partly) selected rows together with tabs and the
# rows themselves with newlines.
#------------------------------------------------------------------------------
proc tablelist::fetchSelection {win offset maxChars} {
upvar ::tablelist::ns${win}::data data
if {!$data(-exportselection)} {
return ""
}
set selection ""
set prevRow -1
foreach cellIdx [curCellSelection $win] {
scan $cellIdx "%d,%d" row col
if {$row != $prevRow} {
if {$prevRow != -1} {
append selection "\n"
}
set prevRow $row
set item [lindex $data(itemList) $row]
set isFirstCol 1
}
set key [lindex $item end]
set text [lindex $item $col]
if {[lindex $data(fmtCmdFlagList) $col]} {
set text [formatElem $win $key $row $col $text]
}
if {!$isFirstCol} {
append selection "\t"
}
append selection $text
set isFirstCol 0
}
return [string range $selection $offset [expr {$offset + $maxChars - 1}]]
}
#------------------------------------------------------------------------------
# tablelist::lostSelection
#
# This procedure is invoked when the tablelist widget win loses ownership of
# the PRIMARY selection. It deselects all items of the widget with the aid of
# the rowSelection procedure if the selection is exported.
#------------------------------------------------------------------------------
proc tablelist::lostSelection win {
upvar ::tablelist::ns${win}::data data
if {$data(-exportselection)} {
rowSelection $win clear 0 $data(lastRow)
event generate $win <<TablelistSelectionLost>>
}
}
#------------------------------------------------------------------------------
# tablelist::activeTrace
#
# This procedure is executed whenever the array element data(activeRow),
# data(activeCol), or data(-selecttype) is written. It moves the "active" tag
# to the line or cell that displays the active item or element of the widget in
# its body text child if the latter has the keyboard focus.
#------------------------------------------------------------------------------
proc tablelist::activeTrace {win varName index op} {
upvar ::tablelist::ns${win}::data data
set w $data(body)
if {$data(ownsFocus) && ![info exists data(dispId)]} {
$w tag remove active 1.0 end
set line [expr {$data(activeRow) + 1}]
set col $data(activeCol)
if {[string compare $data(-selecttype) "row"] == 0} {
$w tag add active $line.0 $line.end
} elseif {$data(itemCount) > 0 && $data(colCount) > 0 &&
$line > 0 && !$data($col-hide)} {
findTabs $win $line $data(activeCol) $data(activeCol) \
tabIdx1 tabIdx2
$w tag add active $tabIdx1 $tabIdx2+1c
}
}
}
#------------------------------------------------------------------------------
# tablelist::listVarTrace
#
# This procedure is executed whenever the global variable specified by varName
# is written or unset. It makes sure that the contents of the widget will be
# synchronized with the value of the variable at idle time, and that the
# variable is recreated if it was unset.
#------------------------------------------------------------------------------
proc tablelist::listVarTrace {win varName index op} {
upvar ::tablelist::ns${win}::data data
switch $op {
w {
if {![info exists data(syncId)]} {
#
# Arrange for the contents of the widget to be synchronized
# with the value of the variable ::$varName at idle time
#
set data(syncId) [after idle [list tablelist::synchronize $win]]
}
}
u {
#
# Recreate the variable ::$varName by setting it according to
# the value of data(itemList), and set the trace on it again
#
if {[string compare $index ""] != 0} {
set varName ${varName}($index)
}
set ::$varName {}
foreach item $data(itemList) {
lappend ::$varName [lrange $item 0 $data(lastCol)]
}
trace variable ::$varName wu $data(listVarTraceCmd)
}
}
}
|