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 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969
|
/*
* bltTable.c --
*
* This module implements a table-based geometry manager
* for the BLT toolkit.
*
* Copyright 1993-1998 Lucent Technologies, Inc.
*
* Permission to use, copy, modify, and distribute this software and
* its documentation for any purpose and without fee is hereby
* granted, provided that the above copyright notice appear in all
* copies and that both that the copyright notice and warranty
* disclaimer appear in supporting documentation, and that the names
* of Lucent Technologies any of their entities not be used in
* advertising or publicity pertaining to distribution of the software
* without specific, written prior permission.
*
* Lucent Technologies disclaims all warranties with regard to this
* software, including all implied warranties of merchantability and
* fitness. In no event shall Lucent Technologies be liable for any
* special, indirect or consequential damages or any damages
* whatsoever resulting from loss of use, data or profits, whether in
* an action of contract, negligence or other tortuous action, arising
* out of or in connection with the use or performance of this
* software.
*
* The "table" geometry manager was created by George Howlett.
*/
/*
* To do:
*
* 3) No way to detect if widget is already a container of another
* geometry manager. This one is especially bad with toplevel
* widgets, causing the window manager to lock-up trying to handle the
* myriads of resize requests.
*
* Note: This problem continues in Tk 8.x. It's possible for a widget
* to be a container for two different geometry managers. Each manager
* will set its own requested geometry for the container widget. The
* winner sets the geometry last (sometimes ad infinitum).
*
* 7) Relative sizing of partitions?
*
*/
#include "bltInt.h"
#include "bltTable.h"
#define TABLE_THREAD_KEY "BLT Table Data"
#define TABLE_DEF_PAD 0
/*
* Default values for widget attributes.
*/
#define DEF_TABLE_ANCHOR "center"
#define DEF_TABLE_COLUMNS "0"
#define DEF_TABLE_FILL "none"
#define DEF_TABLE_PAD "0"
#define DEF_TABLE_PROPAGATE "1"
#define DEF_TABLE_RESIZE "both"
#define DEF_TABLE_ROWS "0"
#define DEF_TABLE_SPAN "1"
#define DEF_TABLE_CONTROL "normal"
#define DEF_TABLE_WEIGHT "1.0"
#define ENTRY_DEF_PAD 0
#define ENTRY_DEF_ANCHOR TK_ANCHOR_CENTER
#define ENTRY_DEF_FILL FILL_NONE
#define ENTRY_DEF_SPAN 1
#define ENTRY_DEF_CONTROL CONTROL_NORMAL
#define ENTRY_DEF_IPAD 0
#define ROWCOL_DEF_RESIZE (RESIZE_BOTH | RESIZE_VIRGIN)
#define ROWCOL_DEF_PAD 0
#define ROWCOL_DEF_WEIGHT 1.0
static Blt_Uid rowUid, columnUid;
static void WidgetGeometryProc _ANSI_ARGS_((ClientData clientData,
Tk_Window tkwin));
static void WidgetCustodyProc _ANSI_ARGS_((ClientData clientData,
Tk_Window tkwin));
static Tk_GeomMgr tableMgrInfo =
{
"table", /* Name of geometry manager used by winfo */
WidgetGeometryProc, /* Procedure to for new geometry requests */
WidgetCustodyProc, /* Procedure when widget is taken away */
};
static int StringToLimits _ANSI_ARGS_((ClientData clientData,
Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
int offset));
static char *LimitsToString _ANSI_ARGS_((ClientData clientData,
Tk_Window tkwin, char *widgRec, int offset,
Tcl_FreeProc **freeProcPtr));
static Tk_CustomOption limitsOption =
{
StringToLimits, LimitsToString, (ClientData)0
};
static int StringToResize _ANSI_ARGS_((ClientData clientData,
Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
int offset));
static char *ResizeToString _ANSI_ARGS_((ClientData clientData,
Tk_Window tkwin, char *widgRec, int offset,
Tcl_FreeProc **freeProcPtr));
static Tk_CustomOption resizeOption =
{
StringToResize, ResizeToString, (ClientData)0
};
static int StringToControl _ANSI_ARGS_((ClientData clientData,
Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
int offset));
static char *ControlToString _ANSI_ARGS_((ClientData clientData,
Tk_Window tkwin, char *widgRec, int offset,
Tcl_FreeProc **freeProcPtr));
static Tk_CustomOption controlOption =
{
StringToControl, ControlToString, (ClientData)0
};
extern Tk_CustomOption bltPadOption;
extern Tk_CustomOption bltFillOption;
extern Tk_CustomOption bltDistanceOption;
static Tk_ConfigSpec rowConfigSpecs[] =
{
{TK_CONFIG_CUSTOM, "-height", (char *)NULL, (char *)NULL,
(char *)NULL, Tk_Offset(RowColumn, reqSize), TK_CONFIG_NULL_OK,
&limitsOption},
{TK_CONFIG_CUSTOM, "-pady", (char *)NULL, (char *)NULL,
DEF_TABLE_PAD, Tk_Offset(RowColumn, pad),
TK_CONFIG_DONT_SET_DEFAULT, &bltPadOption},
{TK_CONFIG_CUSTOM, "-resize", (char *)NULL, (char *)NULL,
DEF_TABLE_RESIZE, Tk_Offset(RowColumn, resize),
TK_CONFIG_DONT_SET_DEFAULT, &resizeOption},
{TK_CONFIG_DOUBLE, "-weight", (char *)NULL, (char *)NULL,
DEF_TABLE_WEIGHT, Tk_Offset(RowColumn, weight),
TK_CONFIG_NULL_OK | TK_CONFIG_DONT_SET_DEFAULT, &limitsOption},
{TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
};
static Tk_ConfigSpec columnConfigSpecs[] =
{
{TK_CONFIG_CUSTOM, "-padx", (char *)NULL, (char *)NULL,
DEF_TABLE_PAD, Tk_Offset(RowColumn, pad),
TK_CONFIG_DONT_SET_DEFAULT, &bltPadOption},
{TK_CONFIG_CUSTOM, "-resize", (char *)NULL, (char *)NULL,
DEF_TABLE_RESIZE, Tk_Offset(RowColumn, resize),
TK_CONFIG_DONT_SET_DEFAULT, &resizeOption},
{TK_CONFIG_DOUBLE, "-weight", (char *)NULL, (char *)NULL,
DEF_TABLE_WEIGHT, Tk_Offset(RowColumn, weight),
TK_CONFIG_NULL_OK | TK_CONFIG_DONT_SET_DEFAULT, &limitsOption},
{TK_CONFIG_CUSTOM, "-width", (char *)NULL, (char *)NULL,
(char *)NULL, Tk_Offset(RowColumn, reqSize), TK_CONFIG_NULL_OK,
&limitsOption},
{TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
};
static Tk_ConfigSpec entryConfigSpecs[] =
{
{TK_CONFIG_ANCHOR, "-anchor", (char *)NULL, (char *)NULL,
DEF_TABLE_ANCHOR, Tk_Offset(Entry, anchor),
TK_CONFIG_DONT_SET_DEFAULT},
{TK_CONFIG_INT, "-columnspan", "columnSpan", (char *)NULL,
DEF_TABLE_SPAN, Tk_Offset(Entry, column.span),
TK_CONFIG_DONT_SET_DEFAULT},
{TK_CONFIG_CUSTOM, "-columncontrol", "columnControl", (char *)NULL,
DEF_TABLE_CONTROL, Tk_Offset(Entry, column.control),
TK_CONFIG_DONT_SET_DEFAULT, &controlOption},
{TK_CONFIG_SYNONYM, "-cspan", "columnSpan", (char *)NULL,
(char *)NULL, Tk_Offset(Entry, column.span), 0},
{TK_CONFIG_SYNONYM, "-ccontrol", "columnControl", (char *)NULL,
(char *)NULL, Tk_Offset(Entry, column.control), 0},
{TK_CONFIG_CUSTOM, "-fill", (char *)NULL, (char *)NULL,
DEF_TABLE_FILL, Tk_Offset(Entry, fill),
TK_CONFIG_DONT_SET_DEFAULT, &bltFillOption},
{TK_CONFIG_SYNONYM, "-height", "reqHeight", (char *)NULL,
(char *)NULL, Tk_Offset(Entry, reqHeight), 0},
{TK_CONFIG_CUSTOM, "-padx", (char *)NULL, (char *)NULL,
(char *)NULL, Tk_Offset(Entry, padX), 0, &bltPadOption},
{TK_CONFIG_CUSTOM, "-pady", (char *)NULL, (char *)NULL,
(char *)NULL, Tk_Offset(Entry, padY), 0, &bltPadOption},
{TK_CONFIG_CUSTOM, "-ipadx", (char *)NULL, (char *)NULL,
(char *)NULL, Tk_Offset(Entry, ipadX), 0, &bltDistanceOption},
{TK_CONFIG_CUSTOM, "-ipady", (char *)NULL, (char *)NULL,
(char *)NULL, Tk_Offset(Entry, ipadY), 0, &bltDistanceOption},
{TK_CONFIG_CUSTOM, "-reqheight", "reqHeight", (char *)NULL,
(char *)NULL, Tk_Offset(Entry, reqHeight), TK_CONFIG_NULL_OK,
&limitsOption},
{TK_CONFIG_CUSTOM, "-reqwidth", "reqWidth", (char *)NULL,
(char *)NULL, Tk_Offset(Entry, reqWidth), TK_CONFIG_NULL_OK,
&limitsOption},
{TK_CONFIG_INT, "-rowspan", "rowSpan", (char *)NULL,
DEF_TABLE_SPAN, Tk_Offset(Entry, row.span),
TK_CONFIG_DONT_SET_DEFAULT},
{TK_CONFIG_CUSTOM, "-rowcontrol", "rowControl", (char *)NULL,
DEF_TABLE_CONTROL, Tk_Offset(Entry, row.control),
TK_CONFIG_DONT_SET_DEFAULT, &controlOption},
{TK_CONFIG_SYNONYM, "-rspan", "rowSpan", (char *)NULL,
(char *)NULL, Tk_Offset(Entry, row.span), 0},
{TK_CONFIG_SYNONYM, "-rcontrol", "rowControl", (char *)NULL,
(char *)NULL, Tk_Offset(Entry, row.control), 0},
{TK_CONFIG_SYNONYM, "-width", "reqWidth", (char *)NULL,
(char *)NULL, Tk_Offset(Entry, reqWidth), 0},
{TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
};
static Tk_ConfigSpec tableConfigSpecs[] =
{
{TK_CONFIG_CUSTOM, "-padx", (char *)NULL, (char *)NULL,
DEF_TABLE_PAD, Tk_Offset(Table, padX),
TK_CONFIG_DONT_SET_DEFAULT, &bltPadOption},
{TK_CONFIG_CUSTOM, "-pady", (char *)NULL, (char *)NULL,
DEF_TABLE_PAD, Tk_Offset(Table, padY),
TK_CONFIG_DONT_SET_DEFAULT, &bltPadOption},
{TK_CONFIG_BOOLEAN, "-propagate", (char *)NULL, (char *)NULL,
DEF_TABLE_PROPAGATE, Tk_Offset(Table, propagate),
TK_CONFIG_DONT_SET_DEFAULT},
{TK_CONFIG_CUSTOM, "-reqheight", (char *)NULL, (char *)NULL,
(char *)NULL, Tk_Offset(Table, reqHeight), TK_CONFIG_NULL_OK,
&limitsOption},
{TK_CONFIG_CUSTOM, "-reqwidth", (char *)NULL, (char *)NULL,
(char *)NULL, Tk_Offset(Table, reqWidth), TK_CONFIG_NULL_OK,
&limitsOption},
{TK_CONFIG_END, NULL, NULL, NULL, NULL, 0, 0}
};
/*
* Forward declarations
*/
static void ArrangeTable _ANSI_ARGS_((ClientData clientData));
static void DestroyTable _ANSI_ARGS_((DestroyData dataPtr));
static void DestroyEntry _ANSI_ARGS_((Entry * entryPtr));
static void TableEventProc _ANSI_ARGS_((ClientData clientData,
XEvent *eventPtr));
static void BinEntry _ANSI_ARGS_((Table *tablePtr, Entry * entryPtr));
static RowColumn *InitSpan _ANSI_ARGS_((PartitionInfo * infoPtr, int start,
int span));
static EntrySearchProc FindEntry;
static Tcl_CmdProc TableCmd;
static Tcl_InterpDeleteProc TableInterpDeleteProc;
static Tk_EventProc WidgetEventProc;
/*
* ----------------------------------------------------------------------------
*
* StringToLimits --
*
* Converts the list of elements into zero or more pixel values which
* determine the range of pixel values possible. An element can be in
* any form accepted by Tk_GetPixels. The list has a different meaning
* based upon the number of elements.
*
* # of elements:
*
* 0 - the limits are reset to the defaults.
* 1 - the minimum and maximum values are set to this
* value, freezing the range at a single value.
* 2 - first element is the minimum, the second is the
* maximum.
* 3 - first element is the minimum, the second is the
* maximum, and the third is the nominal value.
*
* Any element may be the empty string which indicates the default.
*
* Results:
* The return value is a standard Tcl result. The min and max fields
* of the range are set.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
StringToLimits(clientData, interp, tkwin, string, widgRec, offset)
ClientData clientData; /* Not used. */
Tcl_Interp *interp; /* Interpreter to send results back to */
Tk_Window tkwin; /* Widget of table */
char *string; /* New width list */
char *widgRec; /* Widget record */
int offset; /* Offset of limits */
{
Limits *limitsPtr = (Limits *)(widgRec + offset);
char **elemArr;
int nElem;
int limArr[3];
Tk_Window winArr[3];
int flags;
elemArr = NULL;
nElem = 0;
/* Initialize limits to default values */
limArr[2] = LIMITS_NOM;
limArr[1] = LIMITS_MAX;
limArr[0] = LIMITS_MIN;
winArr[0] = winArr[1] = winArr[2] = NULL;
flags = 0;
if (string != NULL) {
int size;
int i;
if (Tcl_SplitList(interp, string, &nElem, &elemArr) != TCL_OK) {
return TCL_ERROR;
}
if (nElem > 3) {
Tcl_AppendResult(interp, "wrong # limits \"", string, "\"",
(char *)NULL);
goto error;
}
for (i = 0; i < nElem; i++) {
if (elemArr[i][0] == '\0') {
continue; /* Empty string: use default value */
}
flags |= (LIMITS_SET_BIT << i);
if ((elemArr[i][0] == '.') &&
((elemArr[i][1] == '\0') || isalpha(UCHAR(elemArr[i][1])))) {
Tk_Window tkwin2;
/* Widget specified: save pointer to widget */
tkwin2 = Tk_NameToWindow(interp, elemArr[i], tkwin);
if (tkwin2 == NULL) {
goto error;
}
winArr[i] = tkwin2;
} else {
if (Tk_GetPixels(interp, tkwin, elemArr[i], &size) != TCL_OK) {
goto error;
}
if ((size < LIMITS_MIN) || (size > LIMITS_MAX)) {
Tcl_AppendResult(interp, "bad limits \"", string, "\"",
(char *)NULL);
goto error;
}
limArr[i] = size;
}
}
Blt_Free(elemArr);
}
/*
* Check the limits specified. We can't check the requested
* size of widgets.
*/
switch (nElem) {
case 1:
flags |= (LIMITS_SET_MIN | LIMITS_SET_MAX);
if (winArr[0] == NULL) {
limArr[1] = limArr[0]; /* Set minimum and maximum to value */
} else {
winArr[1] = winArr[0];
}
break;
case 2:
if ((winArr[0] == NULL) && (winArr[1] == NULL) &&
(limArr[1] < limArr[0])) {
Tcl_AppendResult(interp, "bad range \"", string,
"\": min > max", (char *)NULL);
return TCL_ERROR; /* Minimum is greater than maximum */
}
break;
case 3:
if ((winArr[0] == NULL) && (winArr[1] == NULL)) {
if (limArr[1] < limArr[0]) {
Tcl_AppendResult(interp, "bad range \"", string,
"\": min > max", (char *)NULL);
return TCL_ERROR; /* Minimum is greater than maximum */
}
if ((winArr[2] == NULL) &&
((limArr[2] < limArr[0]) || (limArr[2] > limArr[1]))) {
Tcl_AppendResult(interp, "nominal value \"", string,
"\" out of range", (char *)NULL);
return TCL_ERROR; /* Nominal is outside of range defined
* by minimum and maximum */
}
}
break;
}
limitsPtr->min = limArr[0];
limitsPtr->max = limArr[1];
limitsPtr->nom = limArr[2];
limitsPtr->wMin = winArr[0];
limitsPtr->wMax = winArr[1];
limitsPtr->wNom = winArr[2];
limitsPtr->flags = flags;
return TCL_OK;
error:
Blt_Free(elemArr);
return TCL_ERROR;
}
/*
* ----------------------------------------------------------------------------
*
* ResetLimits --
*
* Resets the limits to their default values.
*
* Results:
* None.
*
* ----------------------------------------------------------------------------
*/
INLINE static void
ResetLimits(limitsPtr)
Limits *limitsPtr; /* Limits to be imposed on the value */
{
limitsPtr->flags = 0;
limitsPtr->min = LIMITS_MIN;
limitsPtr->max = LIMITS_MAX;
limitsPtr->nom = LIMITS_NOM;
limitsPtr->wNom = limitsPtr->wMax = limitsPtr->wMin = NULL;
}
/*
* ----------------------------------------------------------------------------
*
* GetBoundedWidth --
*
* Bounds a given width value to the limits described in the limit
* structure. The initial starting value may be overridden by the
* nominal value in the limits.
*
* Results:
* Returns the constrained value.
*
* ----------------------------------------------------------------------------
*/
static int
GetBoundedWidth(width, limitsPtr)
int width; /* Initial value to be constrained */
Limits *limitsPtr; /* Limits to be imposed on the value */
{
/*
* Check widgets for requested width values;
*/
if (limitsPtr->wMin != NULL) {
limitsPtr->min = Tk_ReqWidth(limitsPtr->wMin);
}
if (limitsPtr->wMax != NULL) {
limitsPtr->max = Tk_ReqWidth(limitsPtr->wMax);
}
if (limitsPtr->wNom != NULL) {
limitsPtr->nom = Tk_ReqWidth(limitsPtr->wNom);
}
if (limitsPtr->flags & LIMITS_SET_NOM) {
width = limitsPtr->nom; /* Override initial value */
}
if (width < limitsPtr->min) {
width = limitsPtr->min; /* Bounded by minimum value */
} else if (width > limitsPtr->max) {
width = limitsPtr->max; /* Bounded by maximum value */
}
return width;
}
/*
* ----------------------------------------------------------------------------
*
* GetBoundedHeight --
*
* Bounds a given value to the limits described in the limit
* structure. The initial starting value may be overridden by the
* nominal value in the limits.
*
* Results:
* Returns the constrained value.
*
* ----------------------------------------------------------------------------
*/
static int
GetBoundedHeight(height, limitsPtr)
int height; /* Initial value to be constrained */
Limits *limitsPtr; /* Limits to be imposed on the value */
{
/*
* Check widgets for requested height values;
*/
if (limitsPtr->wMin != NULL) {
limitsPtr->min = Tk_ReqHeight(limitsPtr->wMin);
}
if (limitsPtr->wMax != NULL) {
limitsPtr->max = Tk_ReqHeight(limitsPtr->wMax);
}
if (limitsPtr->wNom != NULL) {
limitsPtr->nom = Tk_ReqHeight(limitsPtr->wNom);
}
if (limitsPtr->flags & LIMITS_SET_NOM) {
height = limitsPtr->nom;/* Override initial value */
}
if (height < limitsPtr->min) {
height = limitsPtr->min;/* Bounded by minimum value */
} else if (height > limitsPtr->max) {
height = limitsPtr->max;/* Bounded by maximum value */
}
return height;
}
/*
* ----------------------------------------------------------------------------
*
* NameOfLimits --
*
* Convert the values into a list representing the limits.
*
* Results:
* The static string representation of the limits is returned.
*
* ----------------------------------------------------------------------------
*/
static char *
NameOfLimits(limitsPtr)
Limits *limitsPtr;
{
Tcl_DString buffer;
#define STRING_SPACE 200
static char string[STRING_SPACE + 1];
Tcl_DStringInit(&buffer);
if (limitsPtr->wMin != NULL) {
Tcl_DStringAppendElement(&buffer, Tk_PathName(limitsPtr->wMin));
} else if (limitsPtr->flags & LIMITS_SET_MIN) {
Tcl_DStringAppendElement(&buffer, Blt_Itoa(limitsPtr->min));
} else {
Tcl_DStringAppendElement(&buffer, "");
}
if (limitsPtr->wMax != NULL) {
Tcl_DStringAppendElement(&buffer, Tk_PathName(limitsPtr->wMax));
} else if (limitsPtr->flags & LIMITS_SET_MAX) {
Tcl_DStringAppendElement(&buffer, Blt_Itoa(limitsPtr->max));
} else {
Tcl_DStringAppendElement(&buffer, "");
}
if (limitsPtr->wNom != NULL) {
Tcl_DStringAppendElement(&buffer, Tk_PathName(limitsPtr->wNom));
} else if (limitsPtr->flags & LIMITS_SET_NOM) {
Tcl_DStringAppendElement(&buffer, Blt_Itoa(limitsPtr->nom));
} else {
Tcl_DStringAppendElement(&buffer, "");
}
strncpy(string, Tcl_DStringValue(&buffer), STRING_SPACE);
string[STRING_SPACE] = '\0';
return string;
}
/*
* ----------------------------------------------------------------------------
*
* LimitsToString --
*
* Convert the limits of the pixel values allowed into a list.
*
* Results:
* The string representation of the limits is returned.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static char *
LimitsToString(clientData, tkwin, widgRec, offset, freeProcPtr)
ClientData clientData; /* Not used. */
Tk_Window tkwin; /* Not used. */
char *widgRec; /* Row/column structure record */
int offset; /* Offset of widget RowColumn record */
Tcl_FreeProc **freeProcPtr; /* Memory deallocation routine */
{
Limits *limitsPtr = (Limits *)(widgRec + offset);
return NameOfLimits(limitsPtr);
}
/*
* ----------------------------------------------------------------------------
*
* StringToResize --
*
* Converts the resize mode into its numeric representation. Valid
* mode strings are "none", "expand", "shrink", or "both".
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
StringToResize(clientData, interp, tkwin, string, widgRec, offset)
ClientData clientData; /* Not used. */
Tcl_Interp *interp; /* Interpreter to send results back to */
Tk_Window tkwin; /* Not used. */
char *string; /* Resize style string */
char *widgRec; /* Entry structure record */
int offset; /* Offset of style in record */
{
int *resizePtr = (int *)(widgRec + offset);
unsigned int length;
char c;
c = string[0];
length = strlen(string);
if ((c == 'n') && (strncmp(string, "none", length) == 0)) {
*resizePtr = RESIZE_NONE;
} else if ((c == 'b') && (strncmp(string, "both", length) == 0)) {
*resizePtr = RESIZE_BOTH;
} else if ((c == 'e') && (strncmp(string, "expand", length) == 0)) {
*resizePtr = RESIZE_EXPAND;
} else if ((c == 's') && (strncmp(string, "shrink", length) == 0)) {
*resizePtr = RESIZE_SHRINK;
} else {
Tcl_AppendResult(interp, "bad resize argument \"", string,
"\": should be \"none\", \"expand\", \"shrink\", or \"both\"",
(char *)NULL);
return TCL_ERROR;
}
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* NameOfResize --
*
* Converts the resize value into its string representation.
*
* Results:
* Returns a pointer to the static name string.
*
* ----------------------------------------------------------------------------
*/
static char *
NameOfResize(resize)
int resize;
{
switch (resize & RESIZE_BOTH) {
case RESIZE_NONE:
return "none";
case RESIZE_EXPAND:
return "expand";
case RESIZE_SHRINK:
return "shrink";
case RESIZE_BOTH:
return "both";
default:
return "unknown resize value";
}
}
/*
* ----------------------------------------------------------------------------
*
* ResizeToString --
*
* Returns resize mode string based upon the resize flags.
*
* Results:
* The resize mode string is returned.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static char *
ResizeToString(clientData, tkwin, widgRec, offset, freeProcPtr)
ClientData clientData; /* Not used. */
Tk_Window tkwin; /* Not used. */
char *widgRec; /* Row/column structure record */
int offset; /* Offset of resize in RowColumn record */
Tcl_FreeProc **freeProcPtr; /* Not used. */
{
int resize = *(int *)(widgRec + offset);
return NameOfResize(resize);
}
/*
* ----------------------------------------------------------------------------
*
* StringToControl --
*
* Converts the control string into its numeric representation.
* Valid control strings are "none", "normal", and "full".
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
StringToControl(clientData, interp, tkwin, string, widgRec, offset)
ClientData clientData; /* Not used. */
Tcl_Interp *interp; /* Interpreter to send results back to */
Tk_Window tkwin; /* Not used. */
char *string; /* Control style string */
char *widgRec; /* Entry structure record */
int offset; /* Offset of style in record */
{
double *controlPtr = (double *)(widgRec + offset);
unsigned int length;
int bool;
char c;
c = string[0];
length = strlen(string);
if (Tcl_GetBoolean(NULL, string, &bool) == TCL_OK) {
*controlPtr = bool;
return TCL_OK;
}
if ((c == 'n') && (length > 1) &&
(strncmp(string, "normal", length) == 0)) {
*controlPtr = CONTROL_NORMAL;
} else if ((c == 'n') && (length > 1) &&
(strncmp(string, "none", length) == 0)) {
*controlPtr = CONTROL_NONE;
} else if ((c == 'f') && (strncmp(string, "full", length) == 0)) {
*controlPtr = CONTROL_FULL;
} else {
double control;
if ((Tcl_GetDouble(interp, string, &control) != TCL_OK) ||
(control < 0.0)) {
Tcl_AppendResult(interp, "bad control argument \"", string,
"\": should be \"normal\", \"none\", or \"full\"",
(char *)NULL);
return TCL_ERROR;
}
*controlPtr = control;
}
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* NameOfControl --
*
* Converts the control value into its string representation.
*
* Results:
* Returns a pointer to the static name string.
*
* ----------------------------------------------------------------------------
*/
static char *
NameOfControl(control)
double control;
{
if (control == CONTROL_NORMAL) {
return "normal";
} else if (control == CONTROL_NONE) {
return "none";
} else if (control == CONTROL_FULL) {
return "full";
} else {
static char string[TCL_DOUBLE_SPACE + 1];
sprintf(string, "%g", control);
return string;
}
}
/*
* ----------------------------------------------------------------------------
*
* ControlToString --
*
* Returns control mode string based upon the control flags.
*
* Results:
* The control mode string is returned.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static char *
ControlToString(clientData, tkwin, widgRec, offset, freeProcPtr)
ClientData clientData; /* Not used. */
Tk_Window tkwin; /* Not used. */
char *widgRec; /* Row/column structure record */
int offset; /* Offset of control in RowColumn record */
Tcl_FreeProc **freeProcPtr; /* Not used. */
{
double control = *(double *)(widgRec + offset);
return NameOfControl(control);
}
static void
EventuallyArrangeTable(tablePtr)
Table *tablePtr;
{
if (!(tablePtr->flags & ARRANGE_PENDING)) {
tablePtr->flags |= ARRANGE_PENDING;
Tcl_DoWhenIdle(ArrangeTable, tablePtr);
}
}
/*
* ----------------------------------------------------------------------------
*
* TableEventProc --
*
* This procedure is invoked by the Tk event handler when the
* container widget is reconfigured or destroyed.
*
* The table will be rearranged at the next idle point if the
* container widget has been resized or moved. There's a
* distinction made between parent and non-parent container
* arrangements. If the container is moved and it's the parent
* of the widgets, they're are moved automatically. If it's
* not the parent, those widgets need to be moved manually.
* This can be a performance hit in rare cases where we're
* scrolling the container (by moving the window) and there
* are lots of non-child widgets arranged insided.
*
* Results:
* None.
*
* Side effects:
* Arranges for the table associated with tkwin to have its
* layout re-computed and drawn at the next idle point.
*
* ----------------------------------------------------------------------------
*/
static void
TableEventProc(clientData, eventPtr)
ClientData clientData; /* Information about widget */
XEvent *eventPtr; /* Information about event */
{
register Table *tablePtr = clientData;
if (eventPtr->type == ConfigureNotify) {
if ((tablePtr->container.width != Tk_Width(tablePtr->tkwin)) ||
(tablePtr->container.height != Tk_Height(tablePtr->tkwin))
|| (tablePtr->flags & NON_PARENT)) {
EventuallyArrangeTable(tablePtr);
}
} else if (eventPtr->type == DestroyNotify) {
if (tablePtr->flags & ARRANGE_PENDING) {
Tcl_CancelIdleCall(ArrangeTable, tablePtr);
}
tablePtr->tkwin = NULL;
Tcl_EventuallyFree(tablePtr, DestroyTable);
}
}
/*
* ----------------------------------------------------------------------------
*
* WidgetEventProc --
*
* This procedure is invoked by the Tk event handler when
* StructureNotify events occur in a widget managed by the table.
* For example, when a managed widget is destroyed, it frees the
* corresponding entry structure and arranges for the table
* layout to be re-computed at the next idle point.
*
* Results:
* None.
*
* Side effects:
* If the managed widget was deleted, the Entry structure gets
* cleaned up and the table is rearranged.
*
* ----------------------------------------------------------------------------
*/
static void
WidgetEventProc(clientData, eventPtr)
ClientData clientData; /* Pointer to Entry structure for widget
* referred to by eventPtr. */
XEvent *eventPtr; /* Describes what just happened. */
{
Entry *entryPtr = (Entry *) clientData;
Table *tablePtr = entryPtr->tablePtr;
if (eventPtr->type == ConfigureNotify) {
int borderWidth;
tablePtr->flags |= REQUEST_LAYOUT;
borderWidth = Tk_Changes(entryPtr->tkwin)->border_width;
if (entryPtr->borderWidth != borderWidth) {
entryPtr->borderWidth = borderWidth;
EventuallyArrangeTable(tablePtr);
}
} else if (eventPtr->type == DestroyNotify) {
entryPtr->tkwin = NULL;
DestroyEntry(entryPtr);
tablePtr->flags |= REQUEST_LAYOUT;
EventuallyArrangeTable(tablePtr);
}
}
/*
* ----------------------------------------------------------------------------
*
* WidgetCustodyProc --
*
* This procedure is invoked when a widget has been stolen by
* another geometry manager. The information and memory
* associated with the widget is released.
*
* Results:
* None.
*
* Side effects:
* Arranges for the table to have its layout re-arranged at the
* next idle point.
*
* ----------------------------------------------------------------------------
*/
/* ARGSUSED */
static void
WidgetCustodyProc(clientData, tkwin)
ClientData clientData; /* Information about the widget */
Tk_Window tkwin; /* Not used. */
{
Entry *entryPtr = (Entry *) clientData;
Table *tablePtr = entryPtr->tablePtr;
if (Tk_IsMapped(entryPtr->tkwin)) {
Tk_UnmapWindow(entryPtr->tkwin);
}
Tk_UnmaintainGeometry(entryPtr->tkwin, tablePtr->tkwin);
entryPtr->tkwin = NULL;
DestroyEntry(entryPtr);
tablePtr->flags |= REQUEST_LAYOUT;
EventuallyArrangeTable(tablePtr);
}
/*
* ----------------------------------------------------------------------------
*
* WidgetGeometryProc --
*
* This procedure is invoked by Tk_GeometryRequest for widgets
* managed by the table geometry manager.
*
* Results:
* None.
*
* Side effects:
* Arranges for the table to have its layout re-computed and
* re-arranged at the next idle point.
*
* ---------------------------------------------------------------------------- */
/* ARGSUSED */
static void
WidgetGeometryProc(clientData, tkwin)
ClientData clientData; /* Information about widget that got new
* preferred geometry. */
Tk_Window tkwin; /* Other Tk-related information about the
* widget. */
{
Entry *entryPtr = (Entry *) clientData;
entryPtr->tablePtr->flags |= REQUEST_LAYOUT;
EventuallyArrangeTable(entryPtr->tablePtr);
}
/*
* ----------------------------------------------------------------------------
*
* FindEntry --
*
* Searches for the table entry corresponding to the given
* widget.
*
* Results:
* If a structure associated with the widget exists, a pointer to
* that structure is returned. Otherwise NULL.
*
* ----------------------------------------------------------------------------
*/
static Entry *
FindEntry(tablePtr, tkwin)
Table *tablePtr;
Tk_Window tkwin; /* Widget associated with table entry */
{
Blt_HashEntry *hPtr;
hPtr = Blt_FindHashEntry(&(tablePtr->entryTable), (char *)tkwin);
if (hPtr == NULL) {
return NULL;
}
return (Entry *) Blt_GetHashValue(hPtr);
}
static int
GetEntry(interp, tablePtr, string, entryPtrPtr)
Tcl_Interp *interp;
Table *tablePtr;
char *string;
Entry **entryPtrPtr;
{
Tk_Window tkwin;
Entry *entryPtr;
tkwin = Tk_NameToWindow(interp, string, tablePtr->tkwin);
if (tkwin == NULL) {
return TCL_ERROR;
}
entryPtr = FindEntry(tablePtr, tkwin);
if (entryPtr == NULL) {
Tcl_AppendResult(interp, "\"", Tk_PathName(tkwin),
"\" is not managed by any table", (char *)NULL);
return TCL_ERROR;
}
*entryPtrPtr = entryPtr;
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* CreateEntry --
*
* This procedure creates and initializes a new Entry structure
* to hold a widget. A valid widget has a parent widget that is
* either a) the container widget itself or b) a mutual ancestor
* of the container widget.
*
* Results:
* Returns a pointer to the new structure describing the new
* widget entry. If an error occurred, then the return
* value is NULL and an error message is left in interp->result.
*
* Side effects:
* Memory is allocated and initialized for the Entry structure.
*
* ---------------------------------------------------------------------------- */
static Entry *
CreateEntry(tablePtr, tkwin)
Table *tablePtr;
Tk_Window tkwin;
{
register Entry *entryPtr;
int dummy;
Tk_Window parent, ancestor;
/*
* Check that this widget can be managed by this table. A valid
* widget has a parent widget that either
*
* 1) is the container widget, or
* 2) is a mutual ancestor of the container widget.
*/
ancestor = Tk_Parent(tkwin);
for (parent = tablePtr->tkwin; (parent != ancestor) &&
(!Tk_IsTopLevel(parent)); parent = Tk_Parent(parent)) {
/* empty */
}
if (ancestor != parent) {
Tcl_AppendResult(tablePtr->interp, "can't manage \"",
Tk_PathName(tkwin), "\" in table \"", Tk_PathName(tablePtr->tkwin),
"\"", (char *)NULL);
return NULL;
}
entryPtr = Blt_Calloc(1, sizeof(Entry));
assert(entryPtr);
/* Initialize the entry structure */
entryPtr->tkwin = tkwin;
entryPtr->tablePtr = tablePtr;
entryPtr->borderWidth = Tk_Changes(tkwin)->border_width;
entryPtr->fill = ENTRY_DEF_FILL;
entryPtr->row.control = entryPtr->column.control = ENTRY_DEF_CONTROL;
entryPtr->anchor = ENTRY_DEF_ANCHOR;
entryPtr->row.span = entryPtr->column.span = ENTRY_DEF_SPAN;
ResetLimits(&(entryPtr->reqWidth));
ResetLimits(&(entryPtr->reqHeight));
/*
* Add the entry to the following data structures.
*
* 1) A chain of widgets managed by the table.
* 2) A hash table of widgets managed by the table.
*/
entryPtr->linkPtr = Blt_ChainAppend(tablePtr->chainPtr, entryPtr);
entryPtr->hashPtr = Blt_CreateHashEntry(&(tablePtr->entryTable),
(char *)tkwin, &dummy);
Blt_SetHashValue(entryPtr->hashPtr, entryPtr);
Tk_CreateEventHandler(tkwin, StructureNotifyMask, WidgetEventProc,
entryPtr);
Tk_ManageGeometry(tkwin, &tableMgrInfo, (ClientData)entryPtr);
return entryPtr;
}
/*
* ----------------------------------------------------------------------------
*
* DestroyEntry --
*
* Removes the Entry structure from the hash table and frees
* the memory allocated by it. If the table is still in use
* (i.e. was not called from DestoryTable), remove its entries
* from the lists of row and column sorted partitions.
*
* Results:
* None.
*
* Side effects:
* Everything associated with the entry is freed up.
*
* ----------------------------------------------------------------------------
*/
static void
DestroyEntry(entryPtr)
Entry *entryPtr;
{
Table *tablePtr = entryPtr->tablePtr;
if (entryPtr->row.linkPtr != NULL) {
Blt_ChainDeleteLink(entryPtr->row.chainPtr, entryPtr->row.linkPtr);
}
if (entryPtr->column.linkPtr != NULL) {
Blt_ChainDeleteLink(entryPtr->column.chainPtr,
entryPtr->column.linkPtr);
}
if (entryPtr->linkPtr != NULL) {
Blt_ChainDeleteLink(tablePtr->chainPtr, entryPtr->linkPtr);
}
if (entryPtr->tkwin != NULL) {
Tk_DeleteEventHandler(entryPtr->tkwin, StructureNotifyMask,
WidgetEventProc, (ClientData)entryPtr);
Tk_ManageGeometry(entryPtr->tkwin, (Tk_GeomMgr *)NULL,
(ClientData)entryPtr);
if ((tablePtr->tkwin != NULL) &&
(Tk_Parent(entryPtr->tkwin) != tablePtr->tkwin)) {
Tk_UnmaintainGeometry(entryPtr->tkwin, tablePtr->tkwin);
}
if (Tk_IsMapped(entryPtr->tkwin)) {
Tk_UnmapWindow(entryPtr->tkwin);
}
}
if (entryPtr->hashPtr != NULL) {
Blt_DeleteHashEntry(&(tablePtr->entryTable), entryPtr->hashPtr);
}
Blt_Free(entryPtr);
}
/*
* ----------------------------------------------------------------------------
*
* ConfigureEntry --
*
* This procedure is called to process an argv/argc list, plus
* the Tk option database, in order to configure (or reconfigure)
* one or more entries. Entries hold information about widgets
* managed by the table geometry manager.
*
* Note: You can query only one widget at a time. But several
* can be reconfigured at once.
*
* Results:
* The return value is a standard Tcl result. If TCL_ERROR is
* returned, then interp->result contains an error message.
*
* Side effects:
* The table layout is recomputed and rearranged at the next idle
* point.
*
* ----------------------------------------------------------------------------
*/
static int
ConfigureEntry(tablePtr, interp, entryPtr, argc, argv)
Table *tablePtr;
Tcl_Interp *interp;
Entry *entryPtr;
int argc; /* Option-value arguments */
CONST char **argv;
{
int oldRowSpan, oldColSpan;
if (entryPtr->tablePtr != tablePtr) {
Tcl_AppendResult(interp, "widget \"", Tk_PathName(entryPtr->tkwin),
"\" does not belong to table \"", Tk_PathName(tablePtr->tkwin),
"\"", (char *)NULL);
return TCL_ERROR;
}
if (argc == 0) {
return Tk_ConfigureInfo(interp, entryPtr->tkwin, entryConfigSpecs,
(char *)entryPtr, (char *)NULL, 0);
} else if (argc == 1) {
return Tk_ConfigureInfo(interp, entryPtr->tkwin, entryConfigSpecs,
(char *)entryPtr, argv[0], 0);
}
oldRowSpan = entryPtr->row.span;
oldColSpan = entryPtr->column.span;
if (Blt_ConfigureWidget(interp, entryPtr->tkwin, entryConfigSpecs,
argc, argv, (char *)entryPtr, TK_CONFIG_ARGV_ONLY) != TCL_OK) {
return TCL_ERROR;
}
if ((entryPtr->column.span < 1) || (entryPtr->column.span > USHRT_MAX)) {
Tcl_AppendResult(interp, "bad column span specified for \"",
Tk_PathName(entryPtr->tkwin), "\"", (char *)NULL);
return TCL_ERROR;
}
if ((entryPtr->row.span < 1) || (entryPtr->row.span > USHRT_MAX)) {
Tcl_AppendResult(interp, "bad row span specified for \"",
Tk_PathName(entryPtr->tkwin), "\"", (char *)NULL);
return TCL_ERROR;
}
if ((oldColSpan != entryPtr->column.span) ||
(oldRowSpan != entryPtr->row.span)) {
BinEntry(tablePtr, entryPtr);
}
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* PrintEntry --
*
* Returns the name, position and options of a widget in the table.
*
* Results:
* Returns a standard Tcl result. A list of the widget
* attributes is left in interp->result.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static void
PrintEntry(entryPtr, resultPtr)
Entry *entryPtr;
Tcl_DString *resultPtr;
{
char string[200];
sprintf(string, " %d,%d ", entryPtr->row.rcPtr->index,
entryPtr->column.rcPtr->index);
Tcl_DStringAppend(resultPtr, string, -1);
Tcl_DStringAppend(resultPtr, Tk_PathName(entryPtr->tkwin), -1);
if (entryPtr->ipadX != ENTRY_DEF_PAD) {
Tcl_DStringAppend(resultPtr, " -ipadx ", -1);
Tcl_DStringAppend(resultPtr, Blt_Itoa(entryPtr->ipadX), -1);
}
if (entryPtr->ipadY != ENTRY_DEF_PAD) {
Tcl_DStringAppend(resultPtr, " -ipady ", -1);
Tcl_DStringAppend(resultPtr, Blt_Itoa(entryPtr->ipadY), -1);
}
if (entryPtr->row.span != ENTRY_DEF_SPAN) {
Tcl_DStringAppend(resultPtr, " -rowspan ", -1);
Tcl_DStringAppend(resultPtr, Blt_Itoa(entryPtr->row.span), -1);
}
if (entryPtr->column.span != ENTRY_DEF_SPAN) {
Tcl_DStringAppend(resultPtr, " -columnspan ", -1);
Tcl_DStringAppend(resultPtr, Blt_Itoa(entryPtr->column.span), -1);
}
if (entryPtr->anchor != ENTRY_DEF_ANCHOR) {
Tcl_DStringAppend(resultPtr, " -anchor ", -1);
Tcl_DStringAppend(resultPtr, Tk_NameOfAnchor(entryPtr->anchor), -1);
}
if ((entryPtr->padLeft != ENTRY_DEF_PAD) ||
(entryPtr->padRight != ENTRY_DEF_PAD)) {
Tcl_DStringAppend(resultPtr, " -padx ", -1);
sprintf(string, "{%d %d}", entryPtr->padLeft, entryPtr->padRight);
Tcl_DStringAppend(resultPtr, string, -1);
}
if ((entryPtr->padTop != ENTRY_DEF_PAD) ||
(entryPtr->padBottom != ENTRY_DEF_PAD)) {
Tcl_DStringAppend(resultPtr, " -pady ", -1);
sprintf(string, "{%d %d}", entryPtr->padTop, entryPtr->padBottom);
Tcl_DStringAppend(resultPtr, string, -1);
}
if (entryPtr->fill != ENTRY_DEF_FILL) {
Tcl_DStringAppend(resultPtr, " -fill ", -1);
Tcl_DStringAppend(resultPtr, Blt_NameOfFill(entryPtr->fill), -1);
}
if (entryPtr->column.control != ENTRY_DEF_CONTROL) {
Tcl_DStringAppend(resultPtr, " -columncontrol ", -1);
Tcl_DStringAppend(resultPtr, NameOfControl(entryPtr->column.control), -1);
}
if (entryPtr->row.control != ENTRY_DEF_CONTROL) {
Tcl_DStringAppend(resultPtr, " -rowcontrol ", -1);
Tcl_DStringAppend(resultPtr, NameOfControl(entryPtr->row.control), -1);
}
if ((entryPtr->reqWidth.nom != LIMITS_NOM) ||
(entryPtr->reqWidth.min != LIMITS_MIN) ||
(entryPtr->reqWidth.max != LIMITS_MAX)) {
Tcl_DStringAppend(resultPtr, " -reqwidth {", -1);
Tcl_DStringAppend(resultPtr, NameOfLimits(&(entryPtr->reqWidth)), -1);
Tcl_DStringAppend(resultPtr, "}", -1);
}
if ((entryPtr->reqHeight.nom != LIMITS_NOM) ||
(entryPtr->reqHeight.min != LIMITS_MIN) ||
(entryPtr->reqHeight.max != LIMITS_MAX)) {
Tcl_DStringAppend(resultPtr, " -reqheight {", -1);
Tcl_DStringAppend(resultPtr, NameOfLimits(&(entryPtr->reqHeight)), -1);
Tcl_DStringAppend(resultPtr, "}", -1);
}
}
/*
* ----------------------------------------------------------------------------
*
* InfoEntry --
*
* Returns the name, position and options of a widget in the table.
*
* Results:
* Returns a standard Tcl result. A list of the widget
* attributes is left in interp->result.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
InfoEntry(interp, tablePtr, entryPtr)
Tcl_Interp *interp;
Table *tablePtr;
Entry *entryPtr;
{
Tcl_DString dString;
if (entryPtr->tablePtr != tablePtr) {
Tcl_AppendResult(interp, "widget \"", Tk_PathName(entryPtr->tkwin),
"\" does not belong to table \"", Tk_PathName(tablePtr->tkwin),
"\"", (char *)NULL);
return TCL_ERROR;
}
Tcl_DStringInit(&dString);
PrintEntry(entryPtr, &dString);
Tcl_DStringResult(interp, &dString);
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* CreateRowColumn --
*
* Creates and initializes a structure that manages the size of a
* row or column in the table. There will be one of these
* structures allocated for each row and column in the table,
* regardless if a widget is contained in it or not.
*
* Results:
* Returns a pointer to the newly allocated row or column
* structure.
*
* ----------------------------------------------------------------------------
*/
static RowColumn *
CreateRowColumn()
{
RowColumn *rcPtr;
rcPtr = Blt_Malloc(sizeof(RowColumn));
rcPtr->resize = ROWCOL_DEF_RESIZE;
ResetLimits(&(rcPtr->reqSize));
rcPtr->nomSize = LIMITS_NOM;
rcPtr->pad.side1 = rcPtr->pad.side2 = ROWCOL_DEF_PAD;
rcPtr->size = rcPtr->index = rcPtr->minSpan = 0;
rcPtr->weight = ROWCOL_DEF_WEIGHT;
return rcPtr;
}
static PartitionInfo *
ParseRowColumn2(tablePtr, string, numberPtr)
Table *tablePtr;
char *string;
int *numberPtr;
{
char c;
int n;
PartitionInfo *infoPtr;
c = tolower(string[0]);
if (c == 'c') {
infoPtr = &(tablePtr->columnInfo);
} else if (c == 'r') {
infoPtr = &(tablePtr->rowInfo);
} else {
Tcl_AppendResult(tablePtr->interp, "bad index \"", string,
"\": must start with \"r\" or \"c\"", (char *)NULL);
return NULL;
}
/* Handle row or column configuration queries */
if (Tcl_GetInt(tablePtr->interp, string + 1, &n) != TCL_OK) {
return NULL;
}
*numberPtr = (int)n;
return infoPtr;
}
static PartitionInfo *
ParseRowColumn(tablePtr, string, numberPtr)
Table *tablePtr;
char *string;
int *numberPtr;
{
int n;
PartitionInfo *infoPtr;
infoPtr = ParseRowColumn2(tablePtr, string, &n);
if (infoPtr == NULL) {
return NULL;
}
if ((n < 0) || (n >= Blt_ChainGetLength(infoPtr->chainPtr))) {
Tcl_AppendResult(tablePtr->interp, "bad ", infoPtr->type, " index \"",
string, "\"", (char *)NULL);
return NULL;
}
*numberPtr = (int)n;
return infoPtr;
}
/*
* ----------------------------------------------------------------------------
*
* GetRowColumn --
*
* Gets the designated row or column from the table. If the row
* or column index is greater than the size of the table, new
* rows/columns will be automatically allocated.
*
* Results:
* Returns a pointer to the row or column structure.
*
* ----------------------------------------------------------------------------
*/
static RowColumn *
GetRowColumn(infoPtr, n)
PartitionInfo *infoPtr;
int n;
{
Blt_ChainLink *linkPtr;
RowColumn *rcPtr;
register int i;
for (i = Blt_ChainGetLength(infoPtr->chainPtr); i <= n; i++) {
rcPtr = CreateRowColumn();
rcPtr->index = i;
rcPtr->linkPtr = Blt_ChainAppend(infoPtr->chainPtr, (ClientData)rcPtr);
}
linkPtr = Blt_ChainGetNthLink(infoPtr->chainPtr, n);
if (linkPtr == NULL) {
return NULL;
}
return Blt_ChainGetValue(linkPtr);
}
/*
* ----------------------------------------------------------------------------
*
* DeleteRowColumn --
*
* Deletes a span of rows/columns from the table. The number of
* rows/columns to be deleted is given by span.
*
* Results:
* None.
*
* Side effects:
* The size of the column partition array may be extended and
* initialized.
*
* ----------------------------------------------------------------------------
*/
static void
DeleteRowColumn(tablePtr, infoPtr, rcPtr)
Table *tablePtr;
PartitionInfo *infoPtr;
RowColumn *rcPtr;
{
Blt_ChainLink *linkPtr, *nextPtr;
Entry *entryPtr;
/*
* Remove any entries that start in the row/column to be deleted.
* They point to memory that will be freed.
*/
if (infoPtr->type == rowUid) {
for (linkPtr = Blt_ChainFirstLink(tablePtr->chainPtr); linkPtr != NULL;
linkPtr = nextPtr) {
nextPtr = Blt_ChainNextLink(linkPtr);
entryPtr = Blt_ChainGetValue(linkPtr);
if (entryPtr->row.rcPtr->index == rcPtr->index) {
DestroyEntry(entryPtr);
}
}
} else {
for (linkPtr = Blt_ChainFirstLink(tablePtr->chainPtr); linkPtr != NULL;
linkPtr = nextPtr) {
nextPtr = Blt_ChainNextLink(linkPtr);
entryPtr = Blt_ChainGetValue(linkPtr);
if (entryPtr->column.rcPtr->index == rcPtr->index) {
DestroyEntry(entryPtr);
}
}
}
}
/*
* ----------------------------------------------------------------------------
*
* ConfigureRowColumn --
*
* This procedure is called to process an argv/argc list in order
* to configure a row or column in the table geometry manager.
*
* Results:
* The return value is a standard Tcl result. If TCL_ERROR is
* returned, then interp->result holds an error message.
*
* Side effects:
* Partition configuration options (bounds, resize flags, etc)
* get set. New partitions may be created as necessary. The
* table is recalculated and arranged at the next idle point.
*
* ----------------------------------------------------------------------------
*/
static int
ConfigureRowColumn(tablePtr, infoPtr, pattern, argc, argv)
Table *tablePtr; /* Table to be configured */
PartitionInfo *infoPtr;
char *pattern;
int argc;
CONST char **argv;
{
RowColumn *rcPtr;
register Blt_ChainLink *linkPtr;
char string[200];
int nMatches;
nMatches = 0;
for (linkPtr = Blt_ChainFirstLink(infoPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
sprintf(string, "%c%d", pattern[0], rcPtr->index);
if (Tcl_StringMatch(string, pattern)) {
if (argc == 0) {
return Tk_ConfigureInfo(tablePtr->interp, tablePtr->tkwin,
infoPtr->configSpecs, (char *)rcPtr, NULL, 0);
} else if (argc == 1) {
return Tk_ConfigureInfo(tablePtr->interp, tablePtr->tkwin,
infoPtr->configSpecs, (char *)rcPtr, argv[0], 0);
} else {
if (Blt_ConfigureWidget(tablePtr->interp, tablePtr->tkwin,
infoPtr->configSpecs, argc, argv, (char *)rcPtr,
TK_CONFIG_ARGV_ONLY) != TCL_OK) {
return TCL_ERROR;
}
}
nMatches++;
}
}
if (nMatches == 0) {
int n;
/*
* We found no existing partitions matching this pattern, so
* see if this designates an new partition (one beyond the
* current range).
*/
if ((Tcl_GetInt(NULL, pattern + 1, &n) != TCL_OK) || (n < 0)) {
Tcl_AppendResult(tablePtr->interp, "pattern \"", pattern,
"\" matches no ", infoPtr->type, " in table \"",
Tk_PathName(tablePtr->tkwin), "\"", (char *)NULL);
return TCL_ERROR;
}
rcPtr = GetRowColumn(infoPtr, n);
assert(rcPtr);
if (Blt_ConfigureWidget(tablePtr->interp, tablePtr->tkwin,
infoPtr->configSpecs, argc, argv, (char *)rcPtr,
TK_CONFIG_ARGV_ONLY) != TCL_OK) {
return TCL_ERROR;
}
}
EventuallyArrangeTable(tablePtr);
return TCL_OK;
}
static void
PrintRowColumn(interp, infoPtr, rcPtr, resultPtr)
Tcl_Interp *interp;
PartitionInfo *infoPtr;
RowColumn *rcPtr;
Tcl_DString *resultPtr;
{
char string[200];
char *padFmt, *sizeFmt;
if (infoPtr->type == rowUid) {
padFmt = " -pady {%d %d}";
sizeFmt = " -height {%s}";
} else {
padFmt = " -padx {%d %d}";
sizeFmt = " -width {%s}";
}
if (rcPtr->resize != ROWCOL_DEF_RESIZE) {
Tcl_DStringAppend(resultPtr, " -resize ", -1);
Tcl_DStringAppend(resultPtr, NameOfResize(rcPtr->resize), -1);
}
if ((rcPtr->pad.side1 != ROWCOL_DEF_PAD) ||
(rcPtr->pad.side2 != ROWCOL_DEF_PAD)) {
sprintf(string, padFmt, rcPtr->pad.side1, rcPtr->pad.side2);
Tcl_DStringAppend(resultPtr, string, -1);
}
if (rcPtr->weight != ROWCOL_DEF_WEIGHT) {
Tcl_DStringAppend(resultPtr, " -weight ", -1);
Tcl_DStringAppend(resultPtr, Blt_Dtoa(interp, rcPtr->weight), -1);
}
if ((rcPtr->reqSize.min != LIMITS_MIN) ||
(rcPtr->reqSize.nom != LIMITS_NOM) ||
(rcPtr->reqSize.max != LIMITS_MAX)) {
sprintf(string, sizeFmt, NameOfLimits(&(rcPtr->reqSize)));
Tcl_DStringAppend(resultPtr, string, -1);
}
}
/*
* ----------------------------------------------------------------------------
*
* InfoRowColumn --
*
* Returns the options of a partition in the table.
*
* Results:
* Returns a standard Tcl result. A list of the partition
* attributes is left in interp->result.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
InfoRowColumn(tablePtr, interp, pattern)
Table *tablePtr;
Tcl_Interp *interp;
char *pattern;
{
RowColumn *rcPtr;
char string[200];
PartitionInfo *infoPtr;
char c;
Blt_ChainLink *linkPtr, *lastPtr;
Tcl_DString dString;
c = pattern[0];
if ((c == 'r') || (c == 'R')) {
infoPtr = &(tablePtr->rowInfo);
} else {
infoPtr = &(tablePtr->columnInfo);
}
Tcl_DStringInit(&dString);
lastPtr = Blt_ChainLastLink(infoPtr->chainPtr);
for (linkPtr = Blt_ChainFirstLink(infoPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
sprintf(string, "%c%d", infoPtr->type[0], rcPtr->index);
if (Tcl_StringMatch(string, pattern)) {
Tcl_DStringAppend(&dString, string, -1);
PrintRowColumn(interp, infoPtr, rcPtr, &dString);
if (linkPtr != lastPtr) {
Tcl_DStringAppend(&dString, " \\\n", -1);
} else {
Tcl_DStringAppend(&dString, "\n", -1);
}
}
}
Tcl_DStringResult(interp, &dString);
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* InitSpan --
*
* Checks the size of the column partitions and extends the size
* if a larger array is needed.
*
* Results:
* Returns 1 if the column exists. Otherwise 0 is returned and
* interp->result contains an error message.
*
* Side effects:
* The size of the column partition array may be extended and
* initialized.
*
* ----------------------------------------------------------------------------
*/
static RowColumn *
InitSpan(infoPtr, start, span)
PartitionInfo *infoPtr;
int start, span;
{
int length;
RowColumn *rcPtr;
register int i;
Blt_ChainLink *linkPtr;
length = Blt_ChainGetLength(infoPtr->chainPtr);
for (i = length; i < (start + span); i++) {
rcPtr = CreateRowColumn();
rcPtr->index = i;
rcPtr->linkPtr = Blt_ChainAppend(infoPtr->chainPtr, (ClientData)rcPtr);
}
linkPtr = Blt_ChainGetNthLink(infoPtr->chainPtr, start);
return Blt_ChainGetValue(linkPtr);
}
/*
* ----------------------------------------------------------------------------
*
* Blt_GetTable --
*
* Searches for a table associated by the path name of the widget
* container.
*
* Errors may occur because
* 1) pathName isn't a valid for any Tk widget, or
* 2) there's no table associated with that widget as a container.
*
* Results:
* If a table entry exists, a pointer to the Table structure is
* returned. Otherwise NULL is returned.
*
* ----------------------------------------------------------------------------
*/
/*LINTLIBRARY*/
int
Blt_GetTable(dataPtr, interp, pathName, tablePtrPtr)
TableInterpData *dataPtr; /* Interpreter-specific data. */
Tcl_Interp *interp; /* Interpreter to report errors back to. */
char *pathName; /* Path name of the container widget. */
Table **tablePtrPtr;
{
Blt_HashEntry *hPtr;
Tk_Window tkwin;
tkwin = Tk_NameToWindow(interp, pathName, Tk_MainWindow(interp));
if (tkwin == NULL) {
return TCL_ERROR;
}
hPtr = Blt_FindHashEntry(&(dataPtr->tableTable), (char *)tkwin);
if (hPtr == NULL) {
Tcl_AppendResult(interp, "no table associated with widget \"",
pathName, "\"", (char *)NULL);
return TCL_ERROR;
}
*tablePtrPtr = (Table *)Blt_GetHashValue(hPtr);
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* CreateTable --
*
* This procedure creates and initializes a new Table structure
* with tkwin as its container widget. The internal structures
* associated with the table are initialized.
*
* Results:
* Returns the pointer to the new Table structure describing the
* new table geometry manager. If an error occurred, the return
* value will be NULL and an error message is left in
* interp->result.
*
* Side effects:
* Memory is allocated and initialized, an event handler is set
* up to watch tkwin, etc.
*
* ----------------------------------------------------------------------------
*/
static Table *
CreateTable(dataPtr, interp, pathName)
TableInterpData *dataPtr;
Tcl_Interp *interp; /* Interpreter associated with table. */
char *pathName; /* Path name of the container widget to be
* associated with the new table. */
{
register Table *tablePtr;
Tk_Window tkwin;
int dummy;
Blt_HashEntry *hPtr;
tkwin = Tk_NameToWindow(interp, pathName, Tk_MainWindow(interp));
if (tkwin == NULL) {
return NULL;
}
tablePtr = Blt_Calloc(1, sizeof(Table));
assert(tablePtr);
tablePtr->tkwin = tkwin;
tablePtr->interp = interp;
tablePtr->rowInfo.type = rowUid;
tablePtr->rowInfo.configSpecs = rowConfigSpecs;
tablePtr->rowInfo.chainPtr = Blt_ChainCreate();
tablePtr->columnInfo.type = columnUid;
tablePtr->columnInfo.configSpecs = columnConfigSpecs;
tablePtr->columnInfo.chainPtr = Blt_ChainCreate();
tablePtr->propagate = TRUE;
tablePtr->arrangeProc = ArrangeTable;
Blt_InitHashTable(&(tablePtr->entryTable), BLT_ONE_WORD_KEYS);
tablePtr->findEntryProc = FindEntry;
ResetLimits(&(tablePtr->reqWidth));
ResetLimits(&(tablePtr->reqHeight));
tablePtr->chainPtr = Blt_ChainCreate();
tablePtr->rowInfo.list = Blt_ListCreate(BLT_ONE_WORD_KEYS);
tablePtr->columnInfo.list = Blt_ListCreate(BLT_ONE_WORD_KEYS);
Tk_CreateEventHandler(tablePtr->tkwin, StructureNotifyMask,
TableEventProc, (ClientData)tablePtr);
hPtr = Blt_CreateHashEntry(&(dataPtr->tableTable), (char *)tkwin, &dummy);
tablePtr->hashPtr = hPtr;
tablePtr->tablePtr = &(dataPtr->tableTable);
Blt_SetHashValue(hPtr, (ClientData)tablePtr);
return tablePtr;
}
/*
* ----------------------------------------------------------------------------
*
* ConfigureTable --
*
* This procedure is called to process an argv/argc list in order
* to configure the table geometry manager.
*
* Results:
* The return value is a standard Tcl result. If TCL_ERROR is
* returned, then interp->result contains an error message.
*
* Side effects:
* Table configuration options (-padx, -pady, etc.) get set. The
* table is recalculated and arranged at the next idle point.
*
* ----------------------------------------------------------------------------
*/
static int
ConfigureTable(tablePtr, interp, argc, argv)
Table *tablePtr; /* Table to be configured */
Tcl_Interp *interp; /* Interpreter to report results back to */
int argc;
CONST char **argv; /* Option-value pairs */
{
if (argc == 0) {
return Tk_ConfigureInfo(interp, tablePtr->tkwin, tableConfigSpecs,
(char *)tablePtr, (char *)NULL, 0);
} else if (argc == 1) {
return Tk_ConfigureInfo(interp, tablePtr->tkwin, tableConfigSpecs,
(char *)tablePtr, argv[0], 0);
}
if (Blt_ConfigureWidget(interp, tablePtr->tkwin, tableConfigSpecs,
argc, argv, (char *)tablePtr, TK_CONFIG_ARGV_ONLY) != TCL_OK) {
return TCL_ERROR;
}
/* Arrange for the table layout to be computed at the next idle point. */
tablePtr->flags |= REQUEST_LAYOUT;
EventuallyArrangeTable(tablePtr);
return TCL_OK;
}
static void
PrintTable(tablePtr, resultPtr)
Table *tablePtr;
Tcl_DString *resultPtr;
{
char string[200];
if ((tablePtr->padLeft != TABLE_DEF_PAD) ||
(tablePtr->padRight != TABLE_DEF_PAD)) {
sprintf(string, " -padx {%d %d}", tablePtr->padLeft, tablePtr->padRight);
Tcl_DStringAppend(resultPtr, string, -1);
}
if ((tablePtr->padTop != TABLE_DEF_PAD) ||
(tablePtr->padBottom != TABLE_DEF_PAD)) {
sprintf(string, " -pady {%d %d}", tablePtr->padTop, tablePtr->padBottom);
Tcl_DStringAppend(resultPtr, string, -1);
}
if (!tablePtr->propagate) {
Tcl_DStringAppend(resultPtr, " -propagate no", -1);
}
if ((tablePtr->reqWidth.min != LIMITS_MIN) ||
(tablePtr->reqWidth.nom != LIMITS_NOM) ||
(tablePtr->reqWidth.max != LIMITS_MAX)) {
Tcl_DStringAppend(resultPtr, " -reqwidth {%s}", -1);
Tcl_DStringAppend(resultPtr, NameOfLimits(&(tablePtr->reqWidth)), -1);
}
if ((tablePtr->reqHeight.min != LIMITS_MIN) ||
(tablePtr->reqHeight.nom != LIMITS_NOM) ||
(tablePtr->reqHeight.max != LIMITS_MAX)) {
Tcl_DStringAppend(resultPtr, " -reqheight {%s}", -1);
Tcl_DStringAppend(resultPtr, NameOfLimits(&(tablePtr->reqHeight)), -1);
}
}
/*
* ----------------------------------------------------------------------------
*
* DestroyPartitions --
*
* Clear each of the lists managing the entries. The entries in
* the lists of row and column spans are themselves lists which
* need to be cleared.
*
* ----------------------------------------------------------------------------
*/
static void
DestroyPartitions(infoPtr)
PartitionInfo *infoPtr;
{
if (infoPtr->list != NULL) {
Blt_Chain *chainPtr;
Blt_ListNode node;
for (node = Blt_ListFirstNode(infoPtr->list); node != NULL;
node = Blt_ListNextNode(node)) {
chainPtr = (Blt_Chain *)Blt_ListGetValue(node);
if (chainPtr != NULL) {
Blt_ChainDestroy(chainPtr);
}
}
Blt_ListDestroy(infoPtr->list);
}
if (infoPtr->chainPtr != NULL) {
Blt_ChainLink *linkPtr;
RowColumn *rcPtr;
for (linkPtr = Blt_ChainFirstLink(infoPtr->chainPtr);
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
Blt_Free(rcPtr);
}
Blt_ChainDestroy(infoPtr->chainPtr);
}
}
/*
* ----------------------------------------------------------------------------
*
* DestroyTable --
*
* This procedure is invoked by Tcl_EventuallyFree or Tcl_Release to
* clean up the Table structure at a safe time (when no-one is using
* it anymore).
*
* Results:
* None.
*
* Side effects:
* Everything associated with the table geometry manager is freed up.
*
* ----------------------------------------------------------------------------
*/
static void
DestroyTable(dataPtr)
DestroyData dataPtr; /* Table structure */
{
Blt_ChainLink *linkPtr;
Entry *entryPtr;
Table *tablePtr = (Table *)dataPtr;
/* Release the chain of entries. */
for (linkPtr = Blt_ChainFirstLink(tablePtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
entryPtr = Blt_ChainGetValue(linkPtr);
entryPtr->linkPtr = NULL; /* Don't disrupt this chain of entries */
DestroyEntry(entryPtr);
}
Blt_ChainDestroy(tablePtr->chainPtr);
DestroyPartitions(&(tablePtr->rowInfo));
DestroyPartitions(&(tablePtr->columnInfo));
Blt_DeleteHashTable(&(tablePtr->entryTable));
if (tablePtr->hashPtr != NULL) {
Blt_DeleteHashEntry(tablePtr->tablePtr, tablePtr->hashPtr);
}
Blt_Free(tablePtr);
}
/*
* ----------------------------------------------------------------------------
*
* BinEntry --
*
* Adds the entry to the lists of both row and column spans. The
* layout of the table is done in order of partition spans, from
* shorted to longest. The widgets spanning a particular number of
* partitions are stored in a linked list. Each list is in turn,
* contained within a master list.
*
* Results:
* None.
*
* Side effects:
* The entry is added to both the lists of row and columns spans.
* This will effect the layout of the widgets.
*
* ----------------------------------------------------------------------------
*/
static void
BinEntry(tablePtr, entryPtr)
Table *tablePtr;
Entry *entryPtr;
{
Blt_ListNode node;
Blt_List list;
Blt_Chain *chainPtr;
int key;
/*
* Remove the entry from both row and column lists. It will be
* re-inserted into the table at the new position.
*/
if (entryPtr->column.linkPtr != NULL) {
Blt_ChainUnlinkLink(entryPtr->column.chainPtr,
entryPtr->column.linkPtr);
}
if (entryPtr->row.linkPtr != NULL) {
Blt_ChainUnlinkLink(entryPtr->row.chainPtr, entryPtr->row.linkPtr);
}
list = tablePtr->rowInfo.list;
key = 0; /* Initialize key to bogus span */
for (node = Blt_ListFirstNode(list); node != NULL;
node = Blt_ListNextNode(node)) {
key = (intptr_t)Blt_ListGetKey(node);
if (entryPtr->row.span <= key) {
break;
}
}
if (key != entryPtr->row.span) {
Blt_ListNode newNode;
/*
* Create a new list (bucket) to hold entries of that size
* span and and link it into the list of buckets.
*/
newNode = Blt_ListCreateNode(list, (char *)(intptr_t)entryPtr->row.span);
Blt_ListSetValue(newNode, (char *)Blt_ChainCreate());
Blt_ListLinkBefore(list, newNode, node);
node = newNode;
}
chainPtr = (Blt_Chain *) Blt_ListGetValue(node);
if (entryPtr->row.linkPtr == NULL) {
entryPtr->row.linkPtr = Blt_ChainAppend(chainPtr, entryPtr);
} else {
Blt_ChainLinkBefore(chainPtr, entryPtr->row.linkPtr, NULL);
}
entryPtr->row.chainPtr = chainPtr;
list = tablePtr->columnInfo.list;
key = 0;
for (node = Blt_ListFirstNode(list); node != NULL;
node = Blt_ListNextNode(node)) {
key = (intptr_t)Blt_ListGetKey(node);
if (entryPtr->column.span <= key) {
break;
}
}
if (key != entryPtr->column.span) {
Blt_ListNode newNode;
/*
* Create a new list (bucket) to hold entries of that size
* span and and link it into the list of buckets.
*/
newNode = Blt_ListCreateNode(list, (char *)(intptr_t)entryPtr->column.span);
Blt_ListSetValue(newNode, (char *)Blt_ChainCreate());
Blt_ListLinkBefore(list, newNode, node);
node = newNode;
}
chainPtr = (Blt_Chain *) Blt_ListGetValue(node);
/* Add the new entry to the span bucket */
if (entryPtr->column.linkPtr == NULL) {
entryPtr->column.linkPtr =
Blt_ChainAppend(chainPtr, entryPtr);
} else {
Blt_ChainLinkBefore(chainPtr, entryPtr->column.linkPtr, NULL);
}
entryPtr->column.chainPtr = chainPtr;
}
/*
* ----------------------------------------------------------------------------
*
* ParseIndex --
*
* Parse the entry index string and return the row and column
* numbers in their respective parameters. The format of a table
* entry index is row,column where row is the row number and
* column is the column number. Rows and columns are numbered
* starting from zero.
*
* Results:
* Returns a standard Tcl result. If TCL_OK is returned, the row
* and column numbers are returned via rowPtr and columnPtr
* respectively.
*
* ----------------------------------------------------------------------------
*/
static int
ParseIndex(interp, string, rowPtr, columnPtr)
Tcl_Interp *interp;
char *string;
int *rowPtr, *columnPtr;
{
char *comma;
long row, column;
int result;
comma = strchr(string, ',');
if (comma == NULL) {
Tcl_AppendResult(interp, "bad index \"", string,
"\": should be \"row,column\"", (char *)NULL);
return TCL_ERROR;
}
*comma = '\0';
result = ((Tcl_ExprLong(interp, string, &row) != TCL_OK) ||
(Tcl_ExprLong(interp, comma + 1, &column) != TCL_OK));
*comma = ','; /* Repair the argument */
if (result) {
return TCL_ERROR;
}
if ((row < 0) || (row > (long)USHRT_MAX)) {
Tcl_AppendResult(interp, "bad index \"", string,
"\": row is out of range", (char *)NULL);
return TCL_ERROR;
}
if ((column < 0) || (column > (long)USHRT_MAX)) {
Tcl_AppendResult(interp, "bad index \"", string,
"\": column is out of range", (char *)NULL);
return TCL_ERROR;
}
*rowPtr = (int)row;
*columnPtr = (int)column;
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* ManageEntry --
*
* Inserts the given widget into the table at a given row and
* column position. The widget can already be managed by this or
* another table. The widget will be simply moved to the new
* location in this table.
*
* The new widget is inserted into both a hash table (this is
* used to locate the information associated with the widget) and
* a list (used to indicate relative ordering of widgets).
*
* Results:
* Returns a standard Tcl result. If an error occurred, TCL_ERROR is
* returned and an error message is left in interp->result.
*
* Side Effects:
* The table is re-computed and arranged at the next idle point.
*
* ---------------------------------------------------------------------------- */
static int
ManageEntry(interp, tablePtr, tkwin, row, column, argc, argv)
Tcl_Interp *interp;
Table *tablePtr;
Tk_Window tkwin;
int row, column;
int argc;
CONST char **argv;
{
Entry *entryPtr;
int result = TCL_OK;
entryPtr = FindEntry(tablePtr, tkwin);
if ((entryPtr != NULL) && (entryPtr->tablePtr != tablePtr)) {
/* The entry for the widget already exists. If it's
* managed by another table, delete it. */
DestroyEntry(entryPtr);
entryPtr = NULL;
}
if (entryPtr == NULL) {
entryPtr = CreateEntry(tablePtr, tkwin);
if (entryPtr == NULL) {
return TCL_ERROR;
}
}
if (argc > 0) {
result = Blt_ConfigureWidget(tablePtr->interp, entryPtr->tkwin,
entryConfigSpecs, argc, argv, (char *)entryPtr,
TK_CONFIG_ARGV_ONLY);
}
if ((entryPtr->column.span < 1) || (entryPtr->row.span < 1)) {
Tcl_AppendResult(tablePtr->interp, "bad span specified for \"",
Tk_PathName(tkwin), "\"", (char *)NULL);
DestroyEntry(entryPtr);
return TCL_ERROR;
}
entryPtr->column.rcPtr = InitSpan(&(tablePtr->columnInfo), column,
entryPtr->column.span);
entryPtr->row.rcPtr = InitSpan(&(tablePtr->rowInfo), row,
entryPtr->row.span);
/*
* Insert the entry into both the row and column layout lists
*/
BinEntry(tablePtr, entryPtr);
return result;
}
/*
* ----------------------------------------------------------------------------
*
* BuildTable --
*
* Processes an argv/argc list of table entries to add and
* configure new widgets into the table. A table entry consists
* of the widget path name, table index, and optional
* configuration options. The first argument in the argv list is
* the name of the table. If no table exists for the given
* widget, a new one is created.
*
* Results:
* Returns a standard Tcl result. If an error occurred,
* TCL_ERROR is returned and an error message is left in
* interp->result.
*
* Side Effects:
* Memory is allocated, a new table is possibly created, etc.
* The table is re-computed and arranged at the next idle point.
*
* ----------------------------------------------------------------------------
*/
static int
BuildTable(tablePtr, interp, argc, argv)
Table *tablePtr; /* Table to manage new widgets */
Tcl_Interp *interp; /* Interpreter to report errors back to */
int argc; /* */
char **argv; /* List of widgets, indices, and options */
{
Tk_Window tkwin;
int row, column;
int nextRow, nextColumn;
register int i;
/* Process any options specific to the table */
for (i = 2; i < argc; i += 2) {
if (argv[i][0] != '-') {
break;
}
}
if (i > argc) {
i = argc;
}
if (i > 2) {
if (ConfigureTable(tablePtr, interp, i - 2, argv + 2) != TCL_OK) {
return TCL_ERROR;
}
}
nextRow = tablePtr->nRows;
nextColumn = 0;
argc -= i, argv += i;
while (argc > 0) {
/*
* Allow the name of the widget and row/column index to be
* specified in any order.
*/
if (argv[0][0] == '.') {
tkwin = Tk_NameToWindow(interp, argv[0], tablePtr->tkwin);
if (tkwin == NULL) {
return TCL_ERROR;
}
if ((argc == 1) || (argv[1][0] == '-')) {
/* No row,column index, use defaults instead */
row = nextRow, column = nextColumn;
argc--, argv++;
} else {
if (ParseIndex(interp, argv[1], &row, &column) != TCL_OK) {
return TCL_ERROR; /* Invalid row,column index */
}
/* Skip over the widget pathname and table index. */
argc -= 2, argv += 2;
}
} else {
if (ParseIndex(interp, argv[0], &row, &column) != TCL_OK) {
return TCL_ERROR;
}
if (argc == 1) {
Tcl_AppendResult(interp, "missing widget pathname after \"",
argv[0], "\"", (char *)NULL);
return TCL_ERROR;
}
tkwin = Tk_NameToWindow(interp, argv[1], tablePtr->tkwin);
if (tkwin == NULL) {
return TCL_ERROR;
}
/* Skip over the widget pathname and table index. */
argc -= 2, argv += 2;
}
/* Find the end of the widget's option-value pairs */
for (i = 0; i < argc; i += 2) {
if (argv[i][0] != '-') {
break;
}
}
if (i > argc) {
i = argc;
}
if (ManageEntry(interp, tablePtr, tkwin, row,
column, i, argv) != TCL_OK) {
return TCL_ERROR;
}
nextColumn = column + 1;
argc -= i, argv += i;
}
/* Arrange for the new table layout to be calculated. */
tablePtr->flags |= REQUEST_LAYOUT;
EventuallyArrangeTable(tablePtr);
Tcl_SetResult(interp, Tk_PathName(tablePtr->tkwin), TCL_VOLATILE);
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* ParseItem --
*
* Parses a string representing an item in the table. An item
* may be one of the following:
* Rn - Row index, where n is the index of row
* Cn - Column index, where n is the index of column
* r,c - Cell index, where r is the row index and c
* is the column index.
*
* Results:
* Returns a standard Tcl result. If no error occurred, TCL_OK
* is returned. *RowPtr* will return the row index. *ColumnPtr*
* will return the column index. If the row or column index is
* not applicable, -1 is returned via *rowPtr* or *columnPtr*.
*
* ----------------------------------------------------------------------------
*/
static int
ParseItem(tablePtr, string, rowPtr, columnPtr)
Table *tablePtr;
char *string;
int *rowPtr, *columnPtr;
{
char c;
long partNum;
c = tolower(string[0]);
*rowPtr = *columnPtr = -1;
if (c == 'r') {
if (Tcl_ExprLong(tablePtr->interp, string + 1, &partNum) != TCL_OK) {
return TCL_ERROR;
}
if ((partNum < 0) || (partNum >= tablePtr->nRows)) {
Tcl_AppendResult(tablePtr->interp, "row index \"", string,
"\" is out of range", (char *)NULL);
return TCL_ERROR;
}
*rowPtr = (int)partNum;
} else if (c == 'c') {
if (Tcl_ExprLong(tablePtr->interp, string + 1, &partNum) != TCL_OK) {
return TCL_ERROR;
}
if ((partNum < 0) || (partNum >= tablePtr->nColumns)) {
Tcl_AppendResult(tablePtr->interp, "column index \"", string,
"\" is out of range", (char *)NULL);
return TCL_ERROR;
}
*columnPtr = (int)partNum;
} else {
if (ParseIndex(tablePtr->interp, string,
rowPtr, columnPtr) != TCL_OK) {
return TCL_ERROR; /* Invalid row,column index */
}
if ((*rowPtr < 0) || (*rowPtr >= tablePtr->nRows) ||
(*columnPtr < 0) || (*columnPtr >= tablePtr->nColumns)) {
Tcl_AppendResult(tablePtr->interp, "index \"", string,
"\" is out of range", (char *)NULL);
return TCL_ERROR;
}
}
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* TranslateAnchor --
*
* Translate the coordinates of a given bounding box based upon
* the anchor specified. The anchor indicates where the given xy
* position is in relation to the bounding box.
*
* nw --- n --- ne
* | | x,y ---+
* w center e | |
* | | +-----+
* sw --- s --- se
*
* Results:
* The translated coordinates of the bounding box are returned.
*
* ----------------------------------------------------------------------------
*/
static void
TranslateAnchor(dx, dy, anchor, xPtr, yPtr)
int dx, dy; /* Difference between outer and inner regions
*/
Tk_Anchor anchor; /* Direction of the anchor */
int *xPtr, *yPtr;
{
int x, y;
x = y = 0;
switch (anchor) {
case TK_ANCHOR_NW: /* Upper left corner */
break;
case TK_ANCHOR_W: /* Left center */
y = (dy / 2);
break;
case TK_ANCHOR_SW: /* Lower left corner */
y = dy;
break;
case TK_ANCHOR_N: /* Top center */
x = (dx / 2);
break;
case TK_ANCHOR_CENTER: /* Centered */
x = (dx / 2);
y = (dy / 2);
break;
case TK_ANCHOR_S: /* Bottom center */
x = (dx / 2);
y = dy;
break;
case TK_ANCHOR_NE: /* Upper right corner */
x = dx;
break;
case TK_ANCHOR_E: /* Right center */
x = dx;
y = (dy / 2);
break;
case TK_ANCHOR_SE: /* Lower right corner */
x = dx;
y = dy;
break;
}
*xPtr = (*xPtr) + x;
*yPtr = (*yPtr) + y;
}
/*
* ----------------------------------------------------------------------------
*
* GetReqWidth --
*
* Returns the width requested by the widget starting in the
* given entry. The requested space also includes any internal
* padding which has been designated for this widget.
*
* The requested width of the widget is always bounded by the limits
* set in entryPtr->reqWidth.
*
* Results:
* Returns the requested width of the widget.
*
* ----------------------------------------------------------------------------
*/
static int
GetReqWidth(entryPtr)
Entry *entryPtr;
{
int width;
width = Tk_ReqWidth(entryPtr->tkwin) + (2 * entryPtr->ipadX);
width = GetBoundedWidth(width, &(entryPtr->reqWidth));
return width;
}
/*
* ----------------------------------------------------------------------------
*
* GetReqHeight --
*
* Returns the height requested by the widget starting in the
* given entry. The requested space also includes any internal
* padding which has been designated for this widget.
*
* The requested height of the widget is always bounded by the
* limits set in entryPtr->reqHeight.
*
* Results:
* Returns the requested height of the widget.
*
* ----------------------------------------------------------------------------
*/
static int
GetReqHeight(entryPtr)
Entry *entryPtr;
{
int height;
height = Tk_ReqHeight(entryPtr->tkwin) + (2 * entryPtr->ipadY);
height = GetBoundedHeight(height, &(entryPtr->reqHeight));
return height;
}
/*
* ----------------------------------------------------------------------------
*
* GetTotalSpan --
*
* Sums the row/column space requirements for the entire table.
*
* Results:
* Returns the space currently used in the span of partitions.
*
* ----------------------------------------------------------------------------
*/
static int
GetTotalSpan(infoPtr)
PartitionInfo *infoPtr;
{
register int spaceUsed;
Blt_ChainLink *linkPtr;
RowColumn *rcPtr; /* Start of partitions */
spaceUsed = 0;
for (linkPtr = Blt_ChainFirstLink(infoPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
spaceUsed += rcPtr->size;
}
return spaceUsed;
}
/*
* ----------------------------------------------------------------------------
*
* GetSpan --
*
* Determines the space used by rows/columns for an entry.
*
* Results:
* Returns the space currently used in the span of partitions.
*
* ----------------------------------------------------------------------------
*/
static int
GetSpan(infoPtr, entryPtr)
PartitionInfo *infoPtr;
Entry *entryPtr;
{
RowColumn *startPtr;
register int spaceUsed;
int count;
Blt_ChainLink *linkPtr;
RowColumn *rcPtr; /* Start of partitions */
int span; /* Number of partitions spanned */
if (infoPtr->type == rowUid) {
rcPtr = entryPtr->row.rcPtr;
span = entryPtr->row.span;
} else {
rcPtr = entryPtr->column.rcPtr;
span = entryPtr->column.span;
}
count = spaceUsed = 0;
linkPtr = rcPtr->linkPtr;
startPtr = Blt_ChainGetValue(linkPtr);
for ( /*empty*/ ; (linkPtr != NULL) && (count < span);
linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
spaceUsed += rcPtr->size;
count++;
}
/*
* Subtract off the padding on either side of the span, since the
* widget can't grow into it.
*/
spaceUsed -= (startPtr->pad.side1 + rcPtr->pad.side2 + infoPtr->ePad);
return spaceUsed;
}
/*
* ----------------------------------------------------------------------------
*
* GrowSpan --
*
* Expand the span by the amount of the extra space needed. This
* procedure is used in LayoutPartitions to grow the partitions
* to their minimum nominal size, starting from a zero width and
* height space.
*
* This looks more complicated than it really is. The idea is to
* make the size of the partitions correspond to the smallest
* entry spans. For example, if widget A is in column 1 and
* widget B spans both columns 0 and 1, any extra space needed to
* fit widget B should come from column 0.
*
* On the first pass we try to add space to partitions which have
* not been touched yet (i.e. have no nominal size). Since the
* row and column lists are sorted in ascending order of the
* number of rows or columns spanned, the space is distributed
* amongst the smallest spans first.
*
* The second pass handles the case of widgets which have the
* same span. For example, if A and B, which span the same
* number of partitions are the only widgets to span column 1,
* column 1 would grow to contain the bigger of the two slices of
* space.
*
* If there is still extra space after the first two passes, this
* means that there were no partitions of with no widget spans or
* the same order span that could be expanded. The third pass
* will try to remedy this by parcelling out the left over space
* evenly among the rest of the partitions.
*
* On each pass, we have to keep iterating over the span, evenly
* doling out slices of extra space, because we may hit partition
* limits as space is donated. In addition, if there are left
* over pixels because of round-off, this will distribute them as
* evenly as possible. For the worst case, it will take *span*
* passes to expand the span.
*
* Results:
* None.
*
* Side Effects:
* The partitions in the span may be expanded.
*
* ----------------------------------------------------------------------------
*/
static void
GrowSpan(infoPtr, entryPtr, growth)
PartitionInfo *infoPtr;
Entry *entryPtr;
int growth; /* The amount of extra space needed to
* grow the span. */
{
register RowColumn *rcPtr;
Blt_ChainLink *linkPtr;
int spaceLeft, ration;
int nOpen; /* # of partitions with space available */
register int n;
RowColumn *startPtr; /* Starting (column/row) partition */
int span; /* Number of partitions in the span */
if (infoPtr->type == rowUid) {
startPtr = entryPtr->row.rcPtr;
span = entryPtr->row.span;
} else {
startPtr = entryPtr->column.rcPtr;
span = entryPtr->column.span;
}
/*
* ------------------------------------------------------------------------
*
* Pass 1: First add space to rows/columns that haven't determined
* their nominal sizes yet.
*
* ------------------------------------------------------------------------
*/
nOpen = 0;
/* Find out how many partitions have no size yet */
linkPtr = startPtr->linkPtr;
for (n = 0; n < span; n++) {
rcPtr = Blt_ChainGetValue(linkPtr);
if ((rcPtr->nomSize == LIMITS_NOM) && (rcPtr->maxSize > rcPtr->size)) {
nOpen++;
}
linkPtr = Blt_ChainNextLink(linkPtr);
}
while ((nOpen > 0) && (growth > 0)) {
ration = growth / nOpen;
if (ration == 0) {
ration = 1;
}
linkPtr = startPtr->linkPtr;
for (n = 0; (n < span) && (growth > 0); n++) {
rcPtr = Blt_ChainGetValue(linkPtr);
spaceLeft = rcPtr->maxSize - rcPtr->size;
if ((rcPtr->nomSize == LIMITS_NOM) && (spaceLeft > 0)) {
if (ration < spaceLeft) {
growth -= ration;
rcPtr->size += ration;
} else {
growth -= spaceLeft;
rcPtr->size += spaceLeft;
nOpen--;
}
rcPtr->minSpan = span;
rcPtr->control = entryPtr;
}
linkPtr = Blt_ChainNextLink(linkPtr);
}
}
/*
* ------------------------------------------------------------------------
*
* Pass 2: Add space to partitions which have the same minimum span
*
* ------------------------------------------------------------------------
*/
nOpen = 0;
linkPtr = startPtr->linkPtr;
for (n = 0; n < span; n++) {
rcPtr = Blt_ChainGetValue(linkPtr);
if ((rcPtr->minSpan == span) && (rcPtr->maxSize > rcPtr->size)) {
nOpen++;
}
linkPtr = Blt_ChainNextLink(linkPtr);
}
while ((nOpen > 0) && (growth > 0)) {
ration = growth / nOpen;
if (ration == 0) {
ration = 1;
}
linkPtr = startPtr->linkPtr;
for (n = 0; (n < span) && (growth > 0); n++) {
rcPtr = Blt_ChainGetValue(linkPtr);
spaceLeft = rcPtr->maxSize - rcPtr->size;
if ((rcPtr->minSpan == span) && (spaceLeft > 0)) {
if (ration < spaceLeft) {
growth -= ration;
rcPtr->size += ration;
} else {
growth -= spaceLeft;
rcPtr->size += spaceLeft;
nOpen--;
}
rcPtr->control = entryPtr;
}
linkPtr = Blt_ChainNextLink(linkPtr);
}
}
/*
* ------------------------------------------------------------------------
*
* Pass 3: Try to expand all the partitions with space still available
*
* ------------------------------------------------------------------------
*/
/* Find out how many partitions still have space available */
nOpen = 0;
linkPtr = startPtr->linkPtr;
for (n = 0; n < span; n++) {
rcPtr = Blt_ChainGetValue(linkPtr);
if ((rcPtr->resize & RESIZE_EXPAND) && (rcPtr->maxSize > rcPtr->size)) {
nOpen++;
}
/* Set the nominal size of the row/column. */
rcPtr->nomSize = rcPtr->size;
linkPtr = Blt_ChainNextLink(linkPtr);
}
while ((nOpen > 0) && (growth > 0)) {
ration = growth / nOpen;
if (ration == 0) {
ration = 1;
}
linkPtr = startPtr->linkPtr;
for (n = 0; (n < span) && (growth > 0); n++) {
rcPtr = Blt_ChainGetValue(linkPtr);
linkPtr = Blt_ChainNextLink(linkPtr);
if (!(rcPtr->resize & RESIZE_EXPAND)) {
continue;
}
spaceLeft = rcPtr->maxSize - rcPtr->size;
if (spaceLeft > 0) {
if (ration < spaceLeft) {
growth -= ration;
rcPtr->size += ration;
} else {
growth -= spaceLeft;
rcPtr->size += spaceLeft;
nOpen--;
}
rcPtr->nomSize = rcPtr->size;
rcPtr->control = entryPtr;
}
}
}
}
/*
* ----------------------------------------------------------------------------
*
* AdjustPartitions --
*
* Adjust the span by the amount of the extra space needed. If
* the amount (adjustSpace) is negative, shrink the span,
* otherwise expand it. Size constraints on the partitions may
* prevent any or all of the spacing adjustments.
*
* This is very much like the GrowSpan procedure, but in this
* case we are shrinking or expanding all the (row or column)
* partitions. It uses a two pass approach, first giving space to
* partitions which not are smaller/larger than their nominal
* sizes. This is because constraints on the partitions may cause
* resizing to be non-linear.
*
* If there is still extra space, this means that all partitions
* are at least to their nominal sizes. The second pass will try
* to add/remove the left over space evenly among all the
* partitions which still have space available.
*
* Results:
* None.
*
* Side Effects:
* The size of the partitions in the span may be increased or
* decreased.
*
* ----------------------------------------------------------------------------
*/
static void
AdjustPartitions(infoPtr, adjustment)
PartitionInfo *infoPtr; /* Array of (column/row) partitions */
int adjustment; /* The amount of extra space to grow or shrink
* the span. If negative, it represents the
* amount of space to remove */
{
register RowColumn *rcPtr;
int ration; /* Amount of space to ration to each
* row/column. */
int delta; /* Amount of space needed */
int spaceLeft; /* Amount of space still available */
int size; /* Amount of space requested for a particular
* row/column. */
int nOpen; /* Number of rows/columns that still can
* be adjusted. */
Blt_Chain *chainPtr;
Blt_ChainLink *linkPtr;
double totalWeight;
chainPtr = infoPtr->chainPtr;
/*
* ------------------------------------------------------------------------
*
* Pass 1: First adjust the size of rows/columns that still haven't
* reached their nominal size.
*
* ------------------------------------------------------------------------
*/
delta = adjustment;
nOpen = 0;
totalWeight = 0.0;
for (linkPtr = Blt_ChainFirstLink(chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
if (rcPtr->weight > 0.0) {
if (delta < 0) {
spaceLeft = rcPtr->size - rcPtr->nomSize;
} else {
spaceLeft = rcPtr->nomSize - rcPtr->size;
}
if (spaceLeft > 0) {
nOpen++;
totalWeight += rcPtr->weight;
}
}
}
while ((nOpen > 0) && (totalWeight > 0.0) && (delta != 0)) {
ration = (int)(delta / totalWeight);
if (ration == 0) {
ration = (delta > 0) ? 1 : -1;
}
for (linkPtr = Blt_ChainFirstLink(chainPtr);
(linkPtr != NULL) && (delta != 0);
linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
if (rcPtr->weight > 0.0) {
spaceLeft = rcPtr->nomSize - rcPtr->size;
if (((delta > 0) && (spaceLeft > 0)) ||
((delta < 0) && (spaceLeft < 0))) {
size = (int)(ration * rcPtr->weight);
if (size > delta) {
size = delta;
}
if (ABS(size) < ABS(spaceLeft)) {
delta -= size;
rcPtr->size += size;
} else {
delta -= spaceLeft;
rcPtr->size += spaceLeft;
nOpen--;
totalWeight -= rcPtr->weight;
}
}
}
}
}
/*
* ------------------------------------------------------------------------
*
* Pass 2: Adjust the partitions with space still available
*
* ------------------------------------------------------------------------
*/
nOpen = 0;
totalWeight = 0.0;
for (linkPtr = Blt_ChainFirstLink(chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
if (rcPtr->weight > 0.0) {
if (delta > 0) {
spaceLeft = rcPtr->maxSize - rcPtr->size;
} else {
spaceLeft = rcPtr->size - rcPtr->minSize;
}
if (spaceLeft > 0) {
nOpen++;
totalWeight += rcPtr->weight;
}
}
}
while ((nOpen > 0) && (totalWeight > 0.0) && (delta != 0)) {
ration = (int)(delta / totalWeight);
if (ration == 0) {
ration = (delta > 0) ? 1 : -1;
}
linkPtr = Blt_ChainFirstLink(chainPtr);
for ( /*empty*/ ; (linkPtr != NULL) && (delta != 0);
linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
if (rcPtr->weight > 0.0) {
if (delta > 0) {
spaceLeft = rcPtr->maxSize - rcPtr->size;
} else {
spaceLeft = rcPtr->minSize - rcPtr->size;
}
if (((delta > 0) && (spaceLeft > 0)) ||
((delta < 0) && (spaceLeft < 0))) {
size = (int)(ration * rcPtr->weight);
if (size > delta) {
size = delta;
}
if (ABS(size) < ABS(spaceLeft)) {
delta -= size;
rcPtr->size += size;
} else {
delta -= spaceLeft;
rcPtr->size += spaceLeft;
nOpen--;
totalWeight -= rcPtr->weight;
}
}
}
}
}
}
/*
* ----------------------------------------------------------------------------
*
* ResetPartitions --
*
* Sets/resets the size of each row and column partition to the
* minimum limit of the partition (this is usually zero). This
* routine gets called when new widgets are added, deleted, or
* resized.
*
* Results:
* None.
*
* Side Effects:
* The size of each partition is re-initialized to its minimum
* size.
*
* ----------------------------------------------------------------------------
*/
static void
ResetPartitions(tablePtr, infoPtr, limitsProc)
Table *tablePtr;
PartitionInfo *infoPtr;
LimitsProc *limitsProc;
{
register RowColumn *rcPtr;
register Blt_ChainLink *linkPtr;
int pad, size;
for (linkPtr = Blt_ChainFirstLink(infoPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
/*
* The constraint procedure below also has the desired
* side-effect of setting the minimum, maximum, and nominal
* values to the requested size of its associated widget (if
* one exists).
*/
size = (*limitsProc) (0, &(rcPtr->reqSize));
pad = PADDING(rcPtr->pad) + infoPtr->ePad;
if (rcPtr->reqSize.flags & LIMITS_SET_NOM) {
/*
* This could be done more cleanly. We want to ensure
* that the requested nominal size is not overridden when
* determining the normal sizes. So temporarily fix min
* and max to the nominal size and reset them back later.
*/
rcPtr->minSize = rcPtr->maxSize = rcPtr->size =
rcPtr->nomSize = size + pad;
} else {
/* The range defaults to 0..MAXINT */
rcPtr->minSize = rcPtr->reqSize.min + pad;
rcPtr->maxSize = rcPtr->reqSize.max + pad;
rcPtr->nomSize = LIMITS_NOM;
rcPtr->size = pad;
}
rcPtr->minSpan = 0;
rcPtr->control = NULL;
rcPtr->count = 0;
}
}
/*
* ----------------------------------------------------------------------------
*
* SetNominalSizes
*
* Sets the normal sizes for each partition. The partition size
* is the requested widget size plus an amount of padding. In
* addition, adjust the min/max bounds of the partition depending
* upon the resize flags (whether the partition can be expanded
* or shrunk from its normal size).
*
* Results:
* Returns the total space needed for the all the partitions.
*
* Side Effects:
* The nominal size of each partition is set. This is later used
* to determine how to shrink or grow the table if the container
* can't be resized to accommodate the exact size requirements
* of all the partitions.
*
* ----------------------------------------------------------------------------
*/
static int
SetNominalSizes(tablePtr, infoPtr)
Table *tablePtr;
PartitionInfo *infoPtr;
{
register RowColumn *rcPtr;
Blt_ChainLink *linkPtr;
int pad, size, total;
total = 0;
for (linkPtr = Blt_ChainFirstLink(infoPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
pad = PADDING(rcPtr->pad) + infoPtr->ePad;
/*
* Restore the real bounds after temporarily setting nominal
* size. These values may have been set in ResetPartitions to
* restrict the size of the paritition to the requested range.
*/
rcPtr->minSize = rcPtr->reqSize.min + pad;
rcPtr->maxSize = rcPtr->reqSize.max + pad;
size = rcPtr->size;
if (size > rcPtr->maxSize) {
size = rcPtr->maxSize;
} else if (size < rcPtr->minSize) {
size = rcPtr->minSize;
}
if ((infoPtr->ePad > 0) && (size < tablePtr->editPtr->minSize)) {
size = tablePtr->editPtr->minSize;
}
rcPtr->nomSize = rcPtr->size = size;
/*
* If a partition can't be resized (to either expand or
* shrink), hold its respective limit at its normal size.
*/
if (!(rcPtr->resize & RESIZE_EXPAND)) {
rcPtr->maxSize = rcPtr->nomSize;
}
if (!(rcPtr->resize & RESIZE_SHRINK)) {
rcPtr->minSize = rcPtr->nomSize;
}
if (rcPtr->control == NULL) {
/* If a row/column contains no entries, then its size
* should be locked. */
if (rcPtr->resize & RESIZE_VIRGIN) {
rcPtr->maxSize = rcPtr->minSize = size;
} else {
if (!(rcPtr->resize & RESIZE_EXPAND)) {
rcPtr->maxSize = size;
}
if (!(rcPtr->resize & RESIZE_SHRINK)) {
rcPtr->minSize = size;
}
}
rcPtr->nomSize = size;
}
total += rcPtr->nomSize;
}
return total;
}
/*
* ----------------------------------------------------------------------------
*
* LockPartitions
*
* Sets the maximum size of a row or column, if the partition
* has a widget that controls it.
*
* Results:
* None.
*
* ----------------------------------------------------------------------------
*/
static void
LockPartitions(infoPtr)
PartitionInfo *infoPtr;
{
register RowColumn *rcPtr;
Blt_ChainLink *linkPtr;
for (linkPtr = Blt_ChainFirstLink(infoPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
if (rcPtr->control != NULL) {
/* Partition is controlled by this widget */
rcPtr->maxSize = rcPtr->size;
}
}
}
/*
* ----------------------------------------------------------------------------
*
* LayoutPartitions --
*
* Calculates the normal space requirements for both the row and
* column partitions. Each widget is added in order of the
* number of rows or columns spanned, which defines the space
* needed among in the partitions spanned.
*
* Results:
* None.
*
* Side Effects:
*
* The sum of normal sizes set here will be used as the normal size
* for the container widget.
*
* ----------------------------------------------------------------------------
*/
static void
LayoutPartitions(tablePtr)
Table *tablePtr;
{
register Blt_ListNode node;
Blt_Chain *chainPtr;
Blt_ChainLink *linkPtr;
register Entry *entryPtr;
int needed, used, total;
PartitionInfo *infoPtr;
infoPtr = &(tablePtr->columnInfo);
ResetPartitions(tablePtr, infoPtr, GetBoundedWidth);
for (node = Blt_ListFirstNode(infoPtr->list); node != NULL;
node = Blt_ListNextNode(node)) {
chainPtr = (Blt_Chain *) Blt_ListGetValue(node);
for (linkPtr = Blt_ChainFirstLink(chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
entryPtr = Blt_ChainGetValue(linkPtr);
if (entryPtr->column.control != CONTROL_FULL) {
continue;
}
needed = GetReqWidth(entryPtr) + PADDING(entryPtr->padX) +
2 * (entryPtr->borderWidth + tablePtr->eEntryPad);
if (needed <= 0) {
continue;
}
used = GetSpan(infoPtr, entryPtr);
if (needed > used) {
GrowSpan(infoPtr, entryPtr, needed - used);
}
}
}
LockPartitions(infoPtr);
for (node = Blt_ListFirstNode(infoPtr->list); node != NULL;
node = Blt_ListNextNode(node)) {
chainPtr = (Blt_Chain *) Blt_ListGetValue(node);
for (linkPtr = Blt_ChainFirstLink(chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
entryPtr = Blt_ChainGetValue(linkPtr);
needed = GetReqWidth(entryPtr) + PADDING(entryPtr->padX) +
2 * (entryPtr->borderWidth + tablePtr->eEntryPad);
if (entryPtr->column.control >= 0.0) {
needed = (int)(needed * entryPtr->column.control);
}
if (needed <= 0) {
continue;
}
used = GetSpan(infoPtr, entryPtr);
if (needed > used) {
GrowSpan(infoPtr, entryPtr, needed - used);
}
}
}
total = SetNominalSizes(tablePtr, infoPtr);
tablePtr->normal.width = GetBoundedWidth(total, &(tablePtr->reqWidth)) +
PADDING(tablePtr->padX) +
2 * (tablePtr->eTablePad + Tk_InternalBorderWidth(tablePtr->tkwin));
infoPtr = &(tablePtr->rowInfo);
ResetPartitions(tablePtr, infoPtr, GetBoundedHeight);
for (node = Blt_ListFirstNode(infoPtr->list); node != NULL;
node = Blt_ListNextNode(node)) {
chainPtr = (Blt_Chain *) Blt_ListGetValue(node);
for (linkPtr = Blt_ChainFirstLink(chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
entryPtr = Blt_ChainGetValue(linkPtr);
if (entryPtr->row.control != CONTROL_FULL) {
continue;
}
needed = GetReqHeight(entryPtr) + PADDING(entryPtr->padY) +
2 * (entryPtr->borderWidth + tablePtr->eEntryPad);
if (needed <= 0) {
continue;
}
used = GetSpan(infoPtr, entryPtr);
if (needed > used) {
GrowSpan(infoPtr, entryPtr, needed - used);
}
}
}
LockPartitions(&(tablePtr->rowInfo));
for (node = Blt_ListFirstNode(infoPtr->list); node != NULL;
node = Blt_ListNextNode(node)) {
chainPtr = Blt_ChainGetValue(node);
for (linkPtr = Blt_ChainFirstLink(chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
entryPtr = Blt_ChainGetValue(linkPtr);
needed = GetReqHeight(entryPtr) + PADDING(entryPtr->padY) +
2 * (entryPtr->borderWidth + tablePtr->eEntryPad);
if (entryPtr->row.control >= 0.0) {
needed = (int)(needed * entryPtr->row.control);
}
if (needed <= 0) {
continue;
}
used = GetSpan(infoPtr, entryPtr);
if (needed > used) {
GrowSpan(infoPtr, entryPtr, needed - used);
}
}
}
total = SetNominalSizes(tablePtr, infoPtr);
tablePtr->normal.height = GetBoundedHeight(total, &(tablePtr->reqHeight)) +
PADDING(tablePtr->padY) +
2 * (tablePtr->eTablePad + Tk_InternalBorderWidth(tablePtr->tkwin));
}
/*
* ----------------------------------------------------------------------------
*
* ArrangeEntries
*
* Places each widget at its proper location. First determines
* the size and position of the each widget. It then considers the
* following:
*
* 1. translation of widget position its parent widget.
* 2. fill style
* 3. anchor
* 4. external and internal padding
* 5. widget size must be greater than zero
*
* Results:
* None.
*
* Side Effects:
* The size of each partition is re-initialized its minimum size.
*
* ----------------------------------------------------------------------------
*/
static void
ArrangeEntries(tablePtr)
Table *tablePtr; /* Table widget structure */
{
register Blt_ChainLink *linkPtr;
register Entry *entryPtr;
register int spanWidth, spanHeight;
int x, y;
int winWidth, winHeight;
int dx, dy;
int maxX, maxY;
int extra;
maxX = tablePtr->container.width -
(Tk_InternalBorderWidth(tablePtr->tkwin) + tablePtr->padRight +
tablePtr->eTablePad);
maxY = tablePtr->container.height -
(Tk_InternalBorderWidth(tablePtr->tkwin) + tablePtr->padBottom +
tablePtr->eTablePad);
for (linkPtr = Blt_ChainFirstLink(tablePtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
entryPtr = Blt_ChainGetValue(linkPtr);
x = entryPtr->column.rcPtr->offset +
entryPtr->column.rcPtr->pad.side1 +
entryPtr->padLeft +
Tk_Changes(entryPtr->tkwin)->border_width +
tablePtr->eEntryPad;
y = entryPtr->row.rcPtr->offset +
entryPtr->row.rcPtr->pad.side1 +
entryPtr->padTop +
Tk_Changes(entryPtr->tkwin)->border_width +
tablePtr->eEntryPad;
/*
* Unmap any widgets that start beyond of the right edge of
* the container.
*/
if ((x >= maxX) || (y >= maxY)) {
if (Tk_IsMapped(entryPtr->tkwin)) {
if (Tk_Parent(entryPtr->tkwin) != tablePtr->tkwin) {
Tk_UnmaintainGeometry(entryPtr->tkwin, tablePtr->tkwin);
}
Tk_UnmapWindow(entryPtr->tkwin);
}
continue;
}
extra = 2 * (entryPtr->borderWidth + tablePtr->eEntryPad);
spanWidth = GetSpan(&(tablePtr->columnInfo), entryPtr) -
(extra + PADDING(entryPtr->padX));
spanHeight = GetSpan(&(tablePtr->rowInfo), entryPtr) -
(extra + PADDING(entryPtr->padY));
winWidth = GetReqWidth(entryPtr);
winHeight = GetReqHeight(entryPtr);
/*
*
* Compare the widget's requested size to the size of the span.
*
* 1) If the widget is larger than the span or if the fill flag
* is set, make the widget the size of the span. Check that the
* new size is within the bounds set for the widget.
*
* 2) Otherwise, position the widget in the space according to its
* anchor.
*
*/
if ((spanWidth <= winWidth) || (entryPtr->fill & FILL_X)) {
winWidth = spanWidth;
if (winWidth > entryPtr->reqWidth.max) {
winWidth = entryPtr->reqWidth.max;
}
}
if ((spanHeight <= winHeight) || (entryPtr->fill & FILL_Y)) {
winHeight = spanHeight;
if (winHeight > entryPtr->reqHeight.max) {
winHeight = entryPtr->reqHeight.max;
}
}
dx = dy = 0;
if (spanWidth > winWidth) {
dx = (spanWidth - winWidth);
}
if (spanHeight > winHeight) {
dy = (spanHeight - winHeight);
}
if ((dx > 0) || (dy > 0)) {
TranslateAnchor(dx, dy, entryPtr->anchor, &x, &y);
}
/*
* Clip the widget at the bottom and/or right edge of the
* container.
*/
if (winWidth > (maxX - x)) {
winWidth = (maxX - x);
}
if (winHeight > (maxY - y)) {
winHeight = (maxY - y);
}
/*
* If the widget is too small (i.e. it has only an external
* border) then unmap it.
*/
if ((winWidth < 1) || (winHeight < 1)) {
if (Tk_IsMapped(entryPtr->tkwin)) {
if (tablePtr->tkwin != Tk_Parent(entryPtr->tkwin)) {
Tk_UnmaintainGeometry(entryPtr->tkwin, tablePtr->tkwin);
}
Tk_UnmapWindow(entryPtr->tkwin);
}
continue;
}
/*
* Resize and/or move the widget as necessary.
*/
entryPtr->x = x;
entryPtr->y = y;
if (tablePtr->tkwin != Tk_Parent(entryPtr->tkwin)) {
Tk_MaintainGeometry(entryPtr->tkwin, tablePtr->tkwin, x, y,
winWidth, winHeight);
} else {
if ((x != Tk_X(entryPtr->tkwin)) ||
(y != Tk_Y(entryPtr->tkwin)) ||
(winWidth != Tk_Width(entryPtr->tkwin)) ||
(winHeight != Tk_Height(entryPtr->tkwin))) {
Tk_MoveResizeWindow(entryPtr->tkwin, x, y, winWidth, winHeight);
}
if (!Tk_IsMapped(entryPtr->tkwin)) {
Tk_MapWindow(entryPtr->tkwin);
}
}
}
}
/*
* ----------------------------------------------------------------------------
*
* ArrangeTable --
*
*
* Results:
* None.
*
* Side Effects:
* The widgets in the table are possibly resized and redrawn.
*
* ----------------------------------------------------------------------------
*/
static void
ArrangeTable(clientData)
ClientData clientData;
{
Table *tablePtr = clientData;
int width, height;
int offset;
int padX, padY;
int outerPad;
RowColumn *columnPtr, *rowPtr;
Blt_ChainLink *linkPtr;
#ifdef notdef
fprintf(stderr, "ArrangeTable(%s)\n", Tk_PathName(tablePtr->tkwin));
#endif
Tcl_Preserve(tablePtr);
tablePtr->flags &= ~ARRANGE_PENDING;
tablePtr->rowInfo.ePad = tablePtr->columnInfo.ePad = tablePtr->eTablePad =
tablePtr->eEntryPad = 0;
if (tablePtr->editPtr != NULL) {
tablePtr->rowInfo.ePad = tablePtr->columnInfo.ePad =
tablePtr->editPtr->gridLineWidth;
tablePtr->eTablePad = tablePtr->editPtr->gridLineWidth;
tablePtr->eEntryPad = tablePtr->editPtr->entryPad;
}
/*
* If the table has no children anymore, then don't do anything at
* all: just leave the container widget's size as-is.
*/
if ((Blt_ChainGetLength(tablePtr->chainPtr) == 0) ||
(tablePtr->tkwin == NULL)) {
Tcl_Release(tablePtr);
return;
}
if (tablePtr->flags & REQUEST_LAYOUT) {
tablePtr->flags &= ~REQUEST_LAYOUT;
LayoutPartitions(tablePtr);
}
/*
* Initially, try to fit the partitions exactly into the container
* by resizing the container. If the widget's requested size is
* different, send a request to the container widget's geometry
* manager to resize.
*/
if ((tablePtr->propagate) &&
((tablePtr->normal.width != Tk_ReqWidth(tablePtr->tkwin)) ||
(tablePtr->normal.height != Tk_ReqHeight(tablePtr->tkwin)))) {
Tk_GeometryRequest(tablePtr->tkwin, tablePtr->normal.width,
tablePtr->normal.height);
EventuallyArrangeTable(tablePtr);
Tcl_Release(tablePtr);
return;
}
/*
* Save the width and height of the container so we know when its
* size has changed during ConfigureNotify events.
*/
tablePtr->container.width = Tk_Width(tablePtr->tkwin);
tablePtr->container.height = Tk_Height(tablePtr->tkwin);
outerPad = 2 * (Tk_InternalBorderWidth(tablePtr->tkwin) +
tablePtr->eTablePad);
padX = outerPad + tablePtr->columnInfo.ePad + PADDING(tablePtr->padX);
padY = outerPad + tablePtr->rowInfo.ePad + PADDING(tablePtr->padY);
width = GetTotalSpan(&(tablePtr->columnInfo)) + padX;
height = GetTotalSpan(&(tablePtr->rowInfo)) + padY;
/*
* If the previous geometry request was not fulfilled (i.e. the
* size of the container is different from partitions' space
* requirements), try to adjust size of the partitions to fit the
* widget.
*/
if (tablePtr->container.width != width) {
AdjustPartitions(&(tablePtr->columnInfo),
tablePtr->container.width - width);
width = GetTotalSpan(&(tablePtr->columnInfo)) + padX;
}
if (tablePtr->container.height != height) {
AdjustPartitions(&(tablePtr->rowInfo),
tablePtr->container.height - height);
height = GetTotalSpan(&(tablePtr->rowInfo)) + padY;
}
/*
* If after adjusting the size of the partitions the space
* required does not equal the size of the widget, do one of the
* following:
*
* 1) If it's smaller, center the table in the widget.
* 2) If it's bigger, clip the partitions that extend beyond
* the edge of the container.
*
* Set the row and column offsets (including the container's
* internal border width). To be used later when positioning the
* widgets.
*/
offset = Tk_InternalBorderWidth(tablePtr->tkwin) + tablePtr->padLeft +
tablePtr->eTablePad;
if (width < tablePtr->container.width) {
offset += (tablePtr->container.width - width) / 2;
}
for (linkPtr = Blt_ChainFirstLink(tablePtr->columnInfo.chainPtr);
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
columnPtr = Blt_ChainGetValue(linkPtr);
columnPtr->offset = offset + tablePtr->columnInfo.ePad;
offset += columnPtr->size;
}
offset = Tk_InternalBorderWidth(tablePtr->tkwin) + tablePtr->padTop +
tablePtr->eTablePad;
if (height < tablePtr->container.height) {
offset += (tablePtr->container.height - height) / 2;
}
for (linkPtr = Blt_ChainFirstLink(tablePtr->rowInfo.chainPtr);
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
rowPtr = Blt_ChainGetValue(linkPtr);
rowPtr->offset = offset + tablePtr->rowInfo.ePad;
offset += rowPtr->size;
}
ArrangeEntries(tablePtr);
if (tablePtr->editPtr != NULL) {
/* Redraw the editor */
(*tablePtr->editPtr->drawProc) (tablePtr->editPtr);
}
Tcl_Release(tablePtr);
}
/*
* ----------------------------------------------------------------------------
*
* ArrangeOp --
*
* Forces layout of the table geometry manager. This is useful
* mostly for debugging the geometry manager. You can get the
* geometry manager to calculate the normal (requested) width and
* height of each row and column. Otherwise, you need to first
* withdraw the container widget, invoke "update", and then query
* the geometry manager.
*
* Results:
* Returns a standard Tcl result. If the table is successfully
* rearranged, TCL_OK is returned. Otherwise, TCL_ERROR is returned
* and an error message is left in interp->result.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
ArrangeOp(dataPtr, interp, argc, argv)
TableInterpData *dataPtr; /* Interpreter-specific data. */
Tcl_Interp *interp; /* Interpreter to report errors to */
int argc;
char **argv; /* Path name of container associated with
* the table */
{
Table *tablePtr;
if (Blt_GetTable(dataPtr, interp, argv[2], &tablePtr) != TCL_OK) {
return TCL_ERROR;
}
tablePtr->flags |= REQUEST_LAYOUT;
ArrangeTable(tablePtr);
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* CgetOp --
*
* Returns the name, position and options of a widget in the table.
*
* Results:
* Returns a standard Tcl result. A list of the widget attributes
* is left in interp->result.
*
* --------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
CgetOp(dataPtr, interp, argc, argv)
TableInterpData *dataPtr; /* Interpreter-specific data. */
Tcl_Interp *interp;
int argc;
char **argv;
{
Table *tablePtr;
int length;
char c;
int n;
PartitionInfo *infoPtr;
if (Blt_GetTable(dataPtr, interp, argv[2], &tablePtr) != TCL_OK) {
return TCL_ERROR;
}
if (argc == 4) {
return Tk_ConfigureValue(interp, tablePtr->tkwin, tableConfigSpecs,
(char *)tablePtr, argv[3], 0);
}
c = argv[3][0];
length = strlen(argv[3]);
if (c == '.') { /* Configure widget */
Entry *entryPtr;
if (GetEntry(interp, tablePtr, argv[3], &entryPtr) != TCL_OK) {
return TCL_ERROR;
}
return Tk_ConfigureValue(interp, entryPtr->tkwin, entryConfigSpecs,
(char *)entryPtr, argv[4], 0);
} else if ((c == 'c') && (strncmp(argv[3], "container", length) == 0)) {
return Tk_ConfigureValue(interp, tablePtr->tkwin, tableConfigSpecs,
(char *)tablePtr, argv[4], 0);
}
infoPtr = ParseRowColumn(tablePtr, argv[3], &n);
if (infoPtr == NULL) {
return TCL_ERROR;
}
return Tk_ConfigureValue(interp, tablePtr->tkwin, infoPtr->configSpecs,
(char *)GetRowColumn(infoPtr, n), argv[4], 0);
}
/*
* ----------------------------------------------------------------------------
*
* ConfigureOp --
*
* Returns the name, position and options of a widget in the table.
*
* Results:
* Returns a standard Tcl result. A list of the table configuration
* option information is left in interp->result.
*
* --------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
ConfigureOp(dataPtr, interp, argc, argv)
TableInterpData *dataPtr; /* Interpreter-specific data. */
Tcl_Interp *interp;
int argc;
char **argv;
{
Table *tablePtr;
int length;
char c1, c2;
int count;
int result;
char **items;
register int i;
if (Blt_GetTable(dataPtr, interp, argv[2], &tablePtr) != TCL_OK) {
return TCL_ERROR;
}
/*
* Find the end of the items. Search until we see an option (-).
*/
argc -= 3, argv += 3;
for (count = 0; count < argc; count++) {
if (argv[count][0] == '-') {
break;
}
}
items = argv; /* Save the start of the item list */
argc -= count; /* Move beyond the items to the options */
argv += count;
result = TCL_ERROR; /* Suppress compiler warning */
if (count == 0) {
result = ConfigureTable(tablePtr, interp, argc, argv);
}
for (i = 0; i < count; i++) {
c1 = items[i][0];
c2 = items[i][1];
length = strlen(items[i]);
if (c1 == '.') { /* Configure widget */
Entry *entryPtr;
if (GetEntry(interp, tablePtr, items[i], &entryPtr) != TCL_OK) {
return TCL_ERROR;
}
result = ConfigureEntry(tablePtr, interp, entryPtr, argc, argv);
} else if ((c1 == 'r') || (c1 == 'R')) {
result = ConfigureRowColumn(tablePtr, &(tablePtr->rowInfo),
items[i], argc, argv);
} else if ((c1 == 'c') && (c2 == 'o') &&
(strncmp(argv[3], "container", length) == 0)) {
result = ConfigureTable(tablePtr, interp, argc, argv);
} else if ((c1 == 'c') || (c1 == 'C')) {
result = ConfigureRowColumn(tablePtr, &(tablePtr->columnInfo),
items[i], argc, argv);
} else {
Tcl_AppendResult(interp, "unknown item \"", items[i],
"\": should be widget, row or column index, or \"container\"",
(char *)NULL);
return TCL_ERROR;
}
if (result == TCL_ERROR) {
break;
}
if ((i + 1) < count) {
Tcl_AppendResult(interp, "\n", (char *)NULL);
}
}
tablePtr->flags |= REQUEST_LAYOUT;
EventuallyArrangeTable(tablePtr);
return result;
}
/*
* ----------------------------------------------------------------------------
*
* DeleteOp --
*
* Deletes the specified rows and/or columns from the table.
* Note that the row/column indices can be fixed only after
* all the deletions have occurred.
*
* table delete .f r0 r1 r4 c0
*
* Results:
* Returns a standard Tcl result.
*
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
DeleteOp(dataPtr, interp, argc, argv)
TableInterpData *dataPtr; /* Interpreter-specific data. */
Tcl_Interp *interp;
int argc;
char **argv;
{
Table *tablePtr;
char c;
Blt_ChainLink *linkPtr, *nextPtr;
PartitionInfo *infoPtr;
char string[200];
int matches;
register int i;
RowColumn *rcPtr;
if (Blt_GetTable(dataPtr, interp, argv[2], &tablePtr) != TCL_OK) {
return TCL_ERROR;
}
for (i = 3; i < argc; i++) {
c = tolower(argv[i][0]);
if ((c != 'r') && (c != 'c')) {
Tcl_AppendResult(interp, "bad index \"", argv[i],
"\": must start with \"r\" or \"c\"", (char *)NULL);
return TCL_ERROR;
}
}
matches = 0;
for (i = 3; i < argc; i++) {
c = tolower(argv[i][0]);
infoPtr = (c == 'r') ? &(tablePtr->rowInfo) : &(tablePtr->columnInfo);
for (linkPtr = Blt_ChainFirstLink(infoPtr->chainPtr); linkPtr != NULL;
linkPtr = nextPtr) {
nextPtr = Blt_ChainNextLink(linkPtr);
rcPtr = Blt_ChainGetValue(linkPtr);
sprintf(string, "%c%d", argv[i][0], rcPtr->index);
if (Tcl_StringMatch(string, argv[i])) {
matches++;
DeleteRowColumn(tablePtr, infoPtr, rcPtr);
Blt_ChainDeleteLink(infoPtr->chainPtr, linkPtr);
}
}
}
if (matches > 0) { /* Fix indices */
i = 0;
for (linkPtr = Blt_ChainFirstLink(tablePtr->columnInfo.chainPtr);
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
rcPtr->index = i++;
}
i = 0;
for (linkPtr = Blt_ChainFirstLink(tablePtr->rowInfo.chainPtr);
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
rcPtr->index = i++;
}
tablePtr->flags |= REQUEST_LAYOUT;
EventuallyArrangeTable(tablePtr);
}
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* JoinOp --
*
* Joins the specified span of rows/columns together into a
* partition. The row/column indices can be fixed only after
* all the deletions have occurred.
*
* table join .f r0 r3
* table join .f c2 c4
* Results:
* Returns a standard Tcl result.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
JoinOp(dataPtr, interp, argc, argv)
TableInterpData *dataPtr; /* Interpreter-specific data. */
Tcl_Interp *interp;
int argc;
char **argv;
{
Table *tablePtr;
Blt_ChainLink *linkPtr, *nextPtr, *fromPtr;
PartitionInfo *infoPtr, *info2Ptr;
Entry *entryPtr;
int from, to; /* Indices marking the span of
* partitions to be joined together. */
int start, end; /* Entry indices. */
register int i;
RowColumn *rcPtr;
if (Blt_GetTable(dataPtr, interp, argv[2], &tablePtr) != TCL_OK) {
return TCL_ERROR;
}
infoPtr = ParseRowColumn(tablePtr, argv[3], &from);
if (infoPtr == NULL) {
return TCL_ERROR;
}
info2Ptr = ParseRowColumn(tablePtr, argv[4], &to);
if (info2Ptr == NULL) {
return TCL_ERROR;
}
if (infoPtr != info2Ptr) {
Tcl_AppendResult(interp,
"\"from\" and \"to\" must both be rows or columns",
(char *)NULL);
return TCL_ERROR;
}
if (from >= to) {
return TCL_OK; /* No-op. */
}
fromPtr = Blt_ChainGetNthLink(infoPtr->chainPtr, from);
rcPtr = Blt_ChainGetValue(fromPtr);
/*
* ---------------------------------------------------------------
*
* Reduce the span of all entries that currently cross any of the
* trailing rows/columns. Also, if the entry starts in one of
* these rows/columns, moved it to the designated "joined"
* row/column.
*
* ---------------------------------------------------------------
*/
if (infoPtr->type == rowUid) {
for (linkPtr = Blt_ChainFirstLink(tablePtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
entryPtr = Blt_ChainGetValue(linkPtr);
start = entryPtr->row.rcPtr->index + 1;
end = entryPtr->row.rcPtr->index + entryPtr->row.span - 1;
if ((end < from) || ((start > to))) {
continue;
}
entryPtr->row.span -= to - start + 1;
if (start >= from) {/* Entry starts in a trailing partition. */
entryPtr->row.rcPtr = rcPtr;
}
}
} else {
for (linkPtr = Blt_ChainFirstLink(tablePtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
entryPtr = Blt_ChainGetValue(linkPtr);
start = entryPtr->column.rcPtr->index + 1;
end = entryPtr->column.rcPtr->index + entryPtr->column.span - 1;
if ((end < from) || ((start > to))) {
continue;
}
entryPtr->column.span -= to - start + 1;
if (start >= from) {/* Entry starts in a trailing partition. */
entryPtr->column.rcPtr = rcPtr;
}
}
}
linkPtr = Blt_ChainNextLink(fromPtr);
for (i = from + 1; i <= to; i++) {
nextPtr = Blt_ChainNextLink(linkPtr);
rcPtr = Blt_ChainGetValue(linkPtr);
DeleteRowColumn(tablePtr, infoPtr, rcPtr);
Blt_ChainDeleteLink(infoPtr->chainPtr, linkPtr);
linkPtr = nextPtr;
}
i = 0;
for (linkPtr = Blt_ChainFirstLink(infoPtr->chainPtr);
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
rcPtr->index = i++;
}
tablePtr->flags |= REQUEST_LAYOUT;
EventuallyArrangeTable(tablePtr);
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* ExtentsOp --
*
* Returns a list of all the pathnames of the widgets managed by
* a table. The table is determined from the name of the
* container widget associated with the table.
*
* table extents .frame r0 c0 container
*
* Results:
* Returns a standard Tcl result. If no error occurred, TCL_OK is
* returned and a list of widgets managed by the table is left in
* interp->result.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
ExtentsOp(dataPtr, interp, argc, argv)
TableInterpData *dataPtr; /* Interpreter-specific data. */
Tcl_Interp *interp; /* Interpreter to return results to. */
int argc; /* # of arguments */
char **argv; /* Command line arguments. */
{
Table *tablePtr;
Blt_ChainLink *linkPtr;
RowColumn *rcPtr;
RowColumn *c1Ptr, *r1Ptr, *c2Ptr, *r2Ptr;
PartitionInfo *infoPtr;
int x, y, width, height;
char string[200];
char c;
if (Blt_GetTable(dataPtr, interp, argv[2], &tablePtr) != TCL_OK) {
return TCL_ERROR;
}
c = tolower(argv[3][0]);
if (c == 'r') {
infoPtr = &(tablePtr->rowInfo);
} else if (c == 'c') {
infoPtr = &(tablePtr->columnInfo);
} else {
Tcl_AppendResult(interp, "unknown item \"", argv[3],
"\": should be widget, row, or column", (char *)NULL);
return TCL_ERROR;
}
for (linkPtr = Blt_ChainFirstLink(infoPtr->chainPtr);
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
sprintf(string, "%c%d", argv[3][0], rcPtr->index);
if (Tcl_StringMatch(string, argv[3])) {
if (c == 'r') {
r1Ptr = r2Ptr = rcPtr;
c1Ptr = GetRowColumn(&(tablePtr->columnInfo), 0);
c2Ptr = GetRowColumn(&(tablePtr->columnInfo),
tablePtr->nColumns - 1);
} else {
c1Ptr = c2Ptr = rcPtr;
r1Ptr = GetRowColumn(&(tablePtr->rowInfo), 0);
r2Ptr = GetRowColumn(&(tablePtr->rowInfo),
tablePtr->nRows - 1);
}
x = c1Ptr->offset;
y = r1Ptr->offset;
width = c2Ptr->offset + c2Ptr->size - x;
height = r2Ptr->offset + r2Ptr->size - y;
sprintf(string, "%c%d %d %d %d %d\n", argv[3][0], rcPtr->index,
x, y, width, height);
Tcl_AppendResult(interp, string, (char *)NULL);
}
}
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* ForgetOp --
*
* Processes an argv/argc list of widget names and purges their
* entries from their respective tables. The widgets are unmapped and
* the tables are rearranged at the next idle point. Note that all
* the named widgets do not need to exist in the same table.
*
* Results:
* Returns a standard Tcl result. If an error occurred, TCL_ERROR is
* returned and an error message is left in interp->result.
*
* Side Effects:
* Memory is deallocated (the entry is destroyed), etc. The
* affected tables are is re-computed and arranged at the next idle
* point.
*
* ----------------------------------------------------------------------------
*/
static int
ForgetOp(dataPtr, interp, argc, argv)
TableInterpData *dataPtr; /* Interpreter-specific data. */
Tcl_Interp *interp;
int argc;
char **argv;
{
Entry *entryPtr;
register int i;
Blt_HashEntry *hPtr;
Blt_HashSearch cursor;
Table *tablePtr;
Tk_Window tkwin, mainWindow;
tablePtr = NULL;
mainWindow = Tk_MainWindow(interp);
for (i = 2; i < argc; i++) {
entryPtr = NULL;
tkwin = Tk_NameToWindow(interp, argv[i], mainWindow);
if (tkwin == NULL) {
return TCL_ERROR;
}
for (hPtr = Blt_FirstHashEntry(&(dataPtr->tableTable), &cursor);
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
tablePtr = (Table *)Blt_GetHashValue(hPtr);
if (tablePtr->interp != interp) {
continue;
}
entryPtr = FindEntry(tablePtr, tkwin);
if (entryPtr != NULL) {
break;
}
}
if (entryPtr == NULL) {
Tcl_AppendResult(interp, "\"", argv[i],
"\" is not managed by any table", (char *)NULL);
return TCL_ERROR;
}
if (Tk_IsMapped(entryPtr->tkwin)) {
Tk_UnmapWindow(entryPtr->tkwin);
}
/* Arrange for the call back here in the loop, because the
* widgets may not belong to the same table. */
tablePtr->flags |= REQUEST_LAYOUT;
EventuallyArrangeTable(tablePtr);
DestroyEntry(entryPtr);
}
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* InfoOp --
*
* Returns the options of a widget or partition in the table.
*
* Results:
* Returns a standard Tcl result. A list of the widget attributes
* is left in interp->result.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
InfoOp(dataPtr, interp, argc, argv)
TableInterpData *dataPtr; /* Interpreter-specific data. */
Tcl_Interp *interp;
int argc;
char **argv;
{
Table *tablePtr;
int result;
char c;
register int i;
if (Blt_GetTable(dataPtr, interp, argv[2], &tablePtr) != TCL_OK) {
return TCL_ERROR;
}
for (i = 3; i < argc; i++) {
c = argv[i][0];
if (c == '.') { /* Entry information */
Entry *entryPtr;
if (GetEntry(interp, tablePtr, argv[i], &entryPtr) != TCL_OK) {
return TCL_ERROR;
}
result = InfoEntry(interp, tablePtr, entryPtr);
} else if ((c == 'r') || (c == 'R') || (c == 'c') || (c == 'C')) {
result = InfoRowColumn(tablePtr, interp, argv[i]);
} else {
Tcl_AppendResult(interp, "unknown item \"", argv[i],
"\": should be widget, row, or column", (char *)NULL);
return TCL_ERROR;
}
if (result != TCL_OK) {
return TCL_ERROR;
}
if ((i + 1) < argc) {
Tcl_AppendResult(interp, "\n", (char *)NULL);
}
}
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* InsertOp --
*
* Inserts a span of rows/columns into the table.
*
* table insert .f r0 2
* table insert .f c0 5
*
* Results:
* Returns a standard Tcl result. A list of the widget
* attributes is left in interp->result.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
InsertOp(dataPtr, interp, argc, argv)
TableInterpData *dataPtr; /* Interpreter-specific data. */
Tcl_Interp *interp;
int argc;
char **argv;
{
Table *tablePtr;
long int span;
int before;
PartitionInfo *infoPtr;
RowColumn *rcPtr;
register int i;
Blt_ChainLink *beforePtr, *linkPtr;
int linkBefore;
if (Blt_GetTable(dataPtr, interp, argv[2], &tablePtr) != TCL_OK) {
return TCL_ERROR;
}
linkBefore = TRUE;
if (argv[3][0] == '-') {
if (strcmp(argv[3], "-before") == 0) {
linkBefore = TRUE;
argv++; argc--;
} else if (strcmp(argv[3], "-after") == 0) {
linkBefore = FALSE;
argv++; argc--;
}
}
if (argc == 3) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
"insert ", argv[2], "row|column ?span?", (char *)NULL);
return TCL_ERROR;
}
infoPtr = ParseRowColumn(tablePtr, argv[3], &before);
if (infoPtr == NULL) {
return TCL_ERROR;
}
span = 1;
if ((argc > 4) && (Tcl_ExprLong(interp, argv[4], &span) != TCL_OK)) {
return TCL_ERROR;
}
if (span < 1) {
Tcl_AppendResult(interp, "span value \"", argv[4],
"\" can't be negative", (char *)NULL);
return TCL_ERROR;
}
beforePtr = Blt_ChainGetNthLink(infoPtr->chainPtr, before);
/*
* Insert the new rows/columns from the designated point in the
* chain.
*/
for (i = 0; i < span; i++) {
rcPtr = CreateRowColumn();
linkPtr = Blt_ChainNewLink();
Blt_ChainSetValue(linkPtr, rcPtr);
if (linkBefore) {
Blt_ChainLinkBefore(infoPtr->chainPtr, linkPtr, beforePtr);
} else {
Blt_ChainLinkAfter(infoPtr->chainPtr, linkPtr, beforePtr);
}
rcPtr->linkPtr = linkPtr;
}
i = 0;
for (linkPtr = Blt_ChainFirstLink(infoPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
/* Reset the indices of the trailing rows/columns. */
rcPtr->index = i++;
}
tablePtr->flags |= REQUEST_LAYOUT;
EventuallyArrangeTable(tablePtr);
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* SplitOp --
*
* Splits a single row/column into multiple partitions. Any
* widgets that span this row/column will be automatically
* corrected to include the new rows/columns.
*
* table split .f r0 3
* table split .f c2 2
* Results:
* Returns a standard Tcl result. A list of the widget
* attributes is left in interp->result.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
SplitOp(dataPtr, interp, argc, argv)
TableInterpData *dataPtr; /* Interpreter-specific data. */
Tcl_Interp *interp;
int argc;
char **argv;
{
Table *tablePtr;
int number, split;
int start, end;
PartitionInfo *infoPtr;
RowColumn *rcPtr;
register int i;
Blt_ChainLink *afterPtr, *linkPtr;
Entry *entryPtr;
if (Blt_GetTable(dataPtr, interp, argv[2], &tablePtr) != TCL_OK) {
return TCL_ERROR;
}
infoPtr = ParseRowColumn(tablePtr, argv[3], &number);
if (infoPtr == NULL) {
return TCL_ERROR;
}
split = 2;
if (argc > 4) {
if (Tcl_GetInt(interp, argv[4], &split) != TCL_OK) {
return TCL_ERROR;
}
}
if (split < 2) {
Tcl_AppendResult(interp, "bad split value \"", argv[4],
"\": should be 2 or greater", (char *)NULL);
return TCL_ERROR;
}
afterPtr = Blt_ChainGetNthLink(infoPtr->chainPtr, number);
/*
* Append (split - 1) additional rows/columns starting
* from the current point in the chain.
*/
for (i = 1; i < split; i++) {
rcPtr = CreateRowColumn();
linkPtr = Blt_ChainNewLink();
Blt_ChainSetValue(linkPtr, rcPtr);
Blt_ChainLinkAfter(infoPtr->chainPtr, linkPtr, afterPtr);
rcPtr->linkPtr = linkPtr;
}
/*
* Also increase the span of all entries that span this
* row/column by split - 1.
*/
if (infoPtr->type == rowUid) {
for (linkPtr = Blt_ChainFirstLink(tablePtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
entryPtr = Blt_ChainGetValue(linkPtr);
start = entryPtr->row.rcPtr->index;
end = entryPtr->row.rcPtr->index + entryPtr->row.span;
if ((start <= number) && (number < end)) {
entryPtr->row.span += (split - 1);
}
}
} else {
for (linkPtr = Blt_ChainFirstLink(tablePtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
entryPtr = Blt_ChainGetValue(linkPtr);
start = entryPtr->column.rcPtr->index;
end = entryPtr->column.rcPtr->index + entryPtr->column.span;
if ((start <= number) && (number < end)) {
entryPtr->column.span += (split - 1);
}
}
}
/*
* Be careful to renumber the rows or columns only after
* processing each entry. Otherwise row/column numbering
* will be out of sync with the index.
*/
i = number;
for (linkPtr = afterPtr; linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
rcPtr->index = i++; /* Renumber the trailing indices. */
}
tablePtr->flags |= REQUEST_LAYOUT;
EventuallyArrangeTable(tablePtr);
return TCL_OK;
}
/*
* ----------------------------------------------------------------------
*
* RowColumnSearch --
*
* Searches for the row or column designated by an x or y
* coordinate.
*
* Results:
* Returns a pointer to the row/column containing the given point.
* If no row/column contains the coordinate, NULL is returned.
*
* ----------------------------------------------------------------------
*/
static RowColumn *
RowColumnSearch(infoPtr, x)
PartitionInfo *infoPtr;
int x; /* Search coordinate */
{
Blt_ChainLink *linkPtr;
RowColumn *rcPtr;
for (linkPtr = Blt_ChainFirstLink(infoPtr->chainPtr);
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
if (x > (rcPtr->offset + rcPtr->size)) {
break; /* Too far, can't find row/column. */
}
if (x > rcPtr->offset) {
return rcPtr;
}
}
return NULL;
}
/*
*----------------------------------------------------------------------
*
* LocateOp --
*
*
* Returns the row,column index given a screen coordinate.
*
* Results:
* Returns a standard Tcl result.
*
*----------------------------------------------------------------------
*/
/* ARGSUSED */
static int
LocateOp(dataPtr, interp, argc, argv)
TableInterpData *dataPtr; /* Interpreter-specific data. */
Tcl_Interp *interp;
int argc;
char **argv;
{
int x, y;
RowColumn *rowPtr, *columnPtr;
Table *tablePtr;
if (Blt_GetTable(dataPtr, interp, argv[2], &tablePtr) != TCL_OK) {
return TCL_ERROR;
}
if (Blt_GetPixels(interp, tablePtr->tkwin, argv[3], PIXELS_ANY, &x)
!= TCL_OK) {
return TCL_ERROR;
}
if (Blt_GetPixels(interp, tablePtr->tkwin, argv[4], PIXELS_ANY, &y)
!= TCL_OK) {
return TCL_ERROR;
}
rowPtr = RowColumnSearch(&(tablePtr->rowInfo), y);
if (rowPtr == NULL) {
return TCL_OK;
}
columnPtr = RowColumnSearch(&(tablePtr->columnInfo), x);
if (columnPtr == NULL) {
return TCL_OK;
}
Tcl_AppendElement(interp, Blt_Itoa(rowPtr->index));
Tcl_AppendElement(interp, Blt_Itoa(columnPtr->index));
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* ContainersOp --
*
* Returns a list of tables currently in use. A table is
* associated by the name of its container widget. All tables
* matching a given pattern are included in this list. If no
* pattern is present (argc == 0), all tables are included.
*
* Results:
* Returns a standard Tcl result. If no error occurred, TCL_OK is
* returned and a list of tables is left in interp->result.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
ContainersOp(dataPtr, interp, argc, argv)
TableInterpData *dataPtr; /* Interpreter-specific data. */
Tcl_Interp *interp; /* Interpreter to return list of names to */
int argc;
char **argv; /* Contains 0-1 arguments: search pattern */
{
Blt_HashEntry *hPtr;
Blt_HashSearch cursor;
register Table *tablePtr;
char *pattern;
pattern = NULL;
if (argc > 2) {
if (argv[2][0] == '-') {
unsigned int length;
length = strlen(argv[2]);
if ((length > 1) && (argv[2][1] == 'p') &&
(strncmp(argv[2], "-pattern", length) == 0)) {
pattern = argv[3];
goto search;
} else if ((length > 1) && (argv[2][1] == 's') &&
(strncmp(argv[2], "-slave", length) == 0)) {
Tk_Window tkwin;
if (argc != 4) {
Tcl_AppendResult(interp, "needs widget argument for \"",
argv[2], "\"", (char *)NULL);
return TCL_ERROR;
}
tkwin = Tk_NameToWindow(interp, argv[3],
Tk_MainWindow(interp));
if (tkwin == NULL) {
return TCL_ERROR;
}
for (hPtr = Blt_FirstHashEntry(&(dataPtr->tableTable), &cursor);
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
tablePtr = (Table *)Blt_GetHashValue(hPtr);
if (FindEntry(tablePtr, tkwin) != NULL) {
Tcl_AppendElement(interp, Tk_PathName(tablePtr->tkwin));
}
}
return TCL_OK;
} else {
Tcl_AppendResult(interp, "bad switch \"", argv[2], "\" : \
should be \"-pattern\", or \"-slave\"", (char *)NULL);
return TCL_ERROR;
}
} else {
pattern = argv[2];
}
}
search:
for (hPtr = Blt_FirstHashEntry(&(dataPtr->tableTable), &cursor);
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
tablePtr = (Table *)Blt_GetHashValue(hPtr);
if (tablePtr->interp == interp) {
if ((pattern == NULL) ||
(Tcl_StringMatch(Tk_PathName(tablePtr->tkwin), pattern))) {
Tcl_AppendElement(interp, Tk_PathName(tablePtr->tkwin));
}
}
}
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* SaveOp --
*
* Returns a list of all the commands necessary to rebuild the
* the table. This includes the layout of the widgets and any
* row, column, or table options set.
*
* Results:
* Returns a standard Tcl result. If no error occurred, TCL_OK is
* returned and a list of widget path names is left in interp->result.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
SaveOp(dataPtr, interp, argc, argv)
TableInterpData *dataPtr; /* Interpreter-specific data. */
Tcl_Interp *interp;
int argc;
char **argv;
{
Table *tablePtr;
Blt_ChainLink *linkPtr, *lastPtr;
Entry *entryPtr;
PartitionInfo *infoPtr;
RowColumn *rcPtr;
Tcl_DString dString;
int start, last;
if (Blt_GetTable(dataPtr, interp, argv[2], &tablePtr) != TCL_OK) {
return TCL_ERROR;
}
Tcl_DStringInit(&dString);
Tcl_DStringAppend(&dString, "\n# Table widget layout\n\n", -1);
Tcl_DStringAppend(&dString, argv[0], -1);
Tcl_DStringAppend(&dString, " ", -1);
Tcl_DStringAppend(&dString, Tk_PathName(tablePtr->tkwin), -1);
Tcl_DStringAppend(&dString, " \\\n", -1);
lastPtr = Blt_ChainLastLink(tablePtr->chainPtr);
for (linkPtr = Blt_ChainFirstLink(tablePtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
entryPtr = Blt_ChainGetValue(linkPtr);
PrintEntry(entryPtr, &dString);
if (linkPtr != lastPtr) {
Tcl_DStringAppend(&dString, " \\\n", -1);
}
}
Tcl_DStringAppend(&dString, "\n\n# Row configuration options\n\n", -1);
infoPtr = &(tablePtr->rowInfo);
for (linkPtr = Blt_ChainFirstLink(infoPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
start = Tcl_DStringLength(&dString);
Tcl_DStringAppend(&dString, argv[0], -1);
Tcl_DStringAppend(&dString, " configure ", -1);
Tcl_DStringAppend(&dString, Tk_PathName(tablePtr->tkwin), -1);
Tcl_DStringAppend(&dString, " r", -1);
Tcl_DStringAppend(&dString, Blt_Itoa(rcPtr->index), -1);
last = Tcl_DStringLength(&dString);
PrintRowColumn(interp, infoPtr, rcPtr, &dString);
if (Tcl_DStringLength(&dString) == last) {
Tcl_DStringSetLength(&dString, start);
} else {
Tcl_DStringAppend(&dString, "\n", -1);
}
}
Tcl_DStringAppend(&dString, "\n\n# Column configuration options\n\n", -1);
infoPtr = &(tablePtr->columnInfo);
for (linkPtr = Blt_ChainFirstLink(infoPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
rcPtr = Blt_ChainGetValue(linkPtr);
start = Tcl_DStringLength(&dString);
Tcl_DStringAppend(&dString, argv[0], -1);
Tcl_DStringAppend(&dString, " configure ", -1);
Tcl_DStringAppend(&dString, Tk_PathName(tablePtr->tkwin), -1);
Tcl_DStringAppend(&dString, " c", -1);
Tcl_DStringAppend(&dString, Blt_Itoa(rcPtr->index), -1);
last = Tcl_DStringLength(&dString);
PrintRowColumn(interp, infoPtr, rcPtr, &dString);
if (Tcl_DStringLength(&dString) == last) {
Tcl_DStringSetLength(&dString, start);
} else {
Tcl_DStringAppend(&dString, "\n", -1);
}
}
start = Tcl_DStringLength(&dString);
Tcl_DStringAppend(&dString, "\n\n# Table configuration options\n\n", -1);
Tcl_DStringAppend(&dString, argv[0], -1);
Tcl_DStringAppend(&dString, " configure ", -1);
Tcl_DStringAppend(&dString, Tk_PathName(tablePtr->tkwin), -1);
last = Tcl_DStringLength(&dString);
PrintTable(tablePtr, &dString);
if (Tcl_DStringLength(&dString) == last) {
Tcl_DStringSetLength(&dString, start);
} else {
Tcl_DStringAppend(&dString, "\n", -1);
}
Tcl_DStringResult(interp, &dString);
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* SearchOp --
*
* Returns a list of all the pathnames of the widgets managed by
* a table geometry manager. The table is given by the path name of a
* container widget associated with the table.
*
* Results:
* Returns a standard Tcl result. If no error occurred, TCL_OK is
* returned and a list of widget path names is left in interp->result.
*
* ----------------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
SearchOp(dataPtr, interp, argc, argv)
TableInterpData *dataPtr; /* Interpreter-specific data. */
Tcl_Interp *interp; /* Interpreter to return list of names to */
int argc; /* Number of arguments */
char **argv; /* Contains 1-2 arguments: pathname of container
* widget associated with the table and search
* pattern */
{
Table *tablePtr;
Blt_ChainLink *linkPtr;
Entry *entryPtr;
int rspan, cspan, rstart, cstart;
char *pattern;
char c;
int flags;
register int i;
#define MATCH_PATTERN (1<<0) /* Find widgets whose path names
* match a given pattern */
#define MATCH_INDEX_SPAN (1<<1) /* Find widgets that span index */
#define MATCH_INDEX_START (1<<2) /* Find widgets that start at index */
if (Blt_GetTable(dataPtr, interp, argv[2], &tablePtr) != TCL_OK) {
return TCL_ERROR;
}
flags = 0;
pattern = NULL;
rspan = cspan = rstart = cstart = 0;
/* Parse switches and arguments first */
for (i = 3; i < argc; i += 2) {
if (argv[i][0] == '-') {
unsigned int length;
if ((i + 1) == argc) {
Tcl_AppendResult(interp, "switch \"", argv[i], "\" needs value",
(char *)NULL);
return TCL_ERROR;
}
length = strlen(argv[i]);
c = argv[i][1];
if ((c == 'p') && (length > 1) &&
(strncmp(argv[3], "-pattern", length) == 0)) {
flags |= MATCH_PATTERN;
pattern = argv[4];
} else if ((c == 's') && (length > 2) &&
(strncmp(argv[i], "-start", length) == 0)) {
flags |= MATCH_INDEX_START;
if (ParseItem(tablePtr, argv[i + 1],
&rstart, &cstart) != TCL_OK) {
return TCL_ERROR;
}
} else if ((c == 's') && (length > 2) &&
(strncmp(argv[i], "-span", length) == 0)) {
flags |= MATCH_INDEX_SPAN;
if (ParseItem(tablePtr, argv[4],
&rspan, &cspan) != TCL_OK) {
return TCL_ERROR;
}
} else {
Tcl_AppendResult(interp, "bad switch \"", argv[3], "\" : \
should be \"-pattern\", \"-span\", or \"-start\"", (char *)NULL);
return TCL_ERROR;
}
} else {
if ((i + 1) == argc) {
pattern = argv[i];
flags |= MATCH_PATTERN;
}
}
}
/* Then try to match entries with the search criteria */
for (linkPtr = Blt_ChainFirstLink(tablePtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
entryPtr = Blt_ChainGetValue(linkPtr);
if ((flags & MATCH_PATTERN) && (pattern != NULL)) {
if (Tcl_StringMatch(Tk_PathName(entryPtr->tkwin), pattern)) {
goto match;
}
}
if (flags & MATCH_INDEX_SPAN) {
if ((rspan >= 0) && ((entryPtr->row.rcPtr->index <= rspan) ||
((entryPtr->row.rcPtr->index + entryPtr->row.span) > rspan))) {
goto match;
}
if ((cspan >= 0) && ((entryPtr->column.rcPtr->index <= cspan) ||
((entryPtr->column.rcPtr->index + entryPtr->column.span)
> cspan))) {
goto match;
}
}
if (flags & MATCH_INDEX_START) {
if ((rstart >= 0) && (entryPtr->row.rcPtr->index == rstart)) {
goto match;
}
if ((cstart >= 0) && (entryPtr->column.rcPtr->index == cstart)) {
goto match;
}
}
continue;
match:
Tcl_AppendElement(interp, Tk_PathName(entryPtr->tkwin));
}
return TCL_OK;
}
/*
* ----------------------------------------------------------------------------
*
* Table operations.
*
* The fields for Blt_OpSpec are as follows:
*
* - operation name
* - minimum number of characters required to disambiguate the operation name.
* - function associated with operation.
* - minimum number of arguments required.
* - maximum number of arguments allowed (0 indicates no limit).
* - usage string
*
* ----------------------------------------------------------------------------
*/
static Blt_OpSpec operSpecs[] =
{
{"arrange", 1, (Blt_Op)ArrangeOp, 3, 3, "container",},
{"cget", 2, (Blt_Op)CgetOp, 4, 5,
"container ?row|column|widget? option",},
{"configure", 3, (Blt_Op)ConfigureOp, 3, 0,
"container ?row|column|widget?... ?option value?...",},
{"containers", 3, (Blt_Op)ContainersOp, 2, 4, "?switch? ?arg?",},
{"delete", 1, (Blt_Op)DeleteOp, 3, 0,
"container row|column ?row|column?",},
{"extents", 1, (Blt_Op)ExtentsOp, 4, 4,
"container row|column|widget",},
{"forget", 1, (Blt_Op)ForgetOp, 3, 0, "widget ?widget?...",},
{"info", 3, (Blt_Op)InfoOp, 3, 0,
"container ?row|column|widget?...",},
{"insert", 3, (Blt_Op)InsertOp, 4, 6,
"container ?-before|-after? row|column ?count?",},
{"join", 1, (Blt_Op)JoinOp, 5, 5, "container first last",},
{"locate", 2, (Blt_Op)LocateOp, 5, 5, "container x y",},
{"save", 2, (Blt_Op)SaveOp, 3, 3, "container",},
{"search", 2, (Blt_Op)SearchOp, 3, 0, "container ?switch arg?...",},
{"split", 2, (Blt_Op)SplitOp, 4, 5, "container row|column div",},
};
static int nSpecs = sizeof(operSpecs) / sizeof(Blt_OpSpec);
/*
* ----------------------------------------------------------------------------
*
* TableCmd --
*
* This procedure is invoked to process the Tcl command that
* corresponds to the table geometry manager. See the user
* documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
* ----------------------------------------------------------------------------
*/
static int
TableCmd(clientData, interp, argc, argv)
ClientData clientData; /* Interpreter-specific data. */
Tcl_Interp *interp;
int argc;
char **argv;
{
TableInterpData *dataPtr = clientData;
Blt_Op proc;
int result;
if ((argc > 1) && (argv[1][0] == '.')) {
Table *tablePtr;
if (Blt_GetTable(clientData, interp, argv[1], &tablePtr) != TCL_OK) {
Tcl_ResetResult(interp);
tablePtr = CreateTable(dataPtr, interp, argv[1]);
if (tablePtr == NULL) {
return TCL_ERROR;
}
}
return BuildTable(tablePtr, interp, argc, argv);
}
proc = Blt_GetOp(interp, nSpecs, operSpecs, BLT_OP_ARG1, argc, argv, 0);
if (proc == NULL) {
return TCL_ERROR;
}
result = (*proc) (dataPtr, interp, argc, argv);
return result;
}
/*
* -----------------------------------------------------------------------
*
* TableInterpDeleteProc --
*
* This is called when the interpreter hosting the table command
* is destroyed.
*
* Results:
* None.
*
* Side effects:
* Destroys all the hash table maintaining the names of the table
* geomtry managers.
*
* ------------------------------------------------------------------------
*/
/* ARGSUSED */
static void
TableInterpDeleteProc(clientData, interp)
ClientData clientData; /* Thread-specific data. */
Tcl_Interp *interp;
{
TableInterpData *dataPtr = clientData;
Blt_HashEntry *hPtr;
Blt_HashSearch cursor;
Table *tablePtr;
for (hPtr = Blt_FirstHashEntry(&(dataPtr->tableTable), &cursor);
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
tablePtr = (Table *)Blt_GetHashValue(hPtr);
tablePtr->hashPtr = NULL;
DestroyTable((DestroyData)tablePtr);
}
Blt_DeleteHashTable(&(dataPtr->tableTable));
Tcl_DeleteAssocData(interp, TABLE_THREAD_KEY);
Blt_Free(dataPtr);
}
static TableInterpData *
GetTableInterpData(interp)
Tcl_Interp *interp;
{
TableInterpData *dataPtr;
Tcl_InterpDeleteProc *proc;
dataPtr = (TableInterpData *)
Tcl_GetAssocData(interp, TABLE_THREAD_KEY, &proc);
if (dataPtr == NULL) {
dataPtr = Blt_Malloc(sizeof(TableInterpData));
assert(dataPtr);
Tcl_SetAssocData(interp, TABLE_THREAD_KEY, TableInterpDeleteProc,
dataPtr);
Blt_InitHashTable(&(dataPtr->tableTable), BLT_ONE_WORD_KEYS);
}
return dataPtr;
}
/*
* ----------------------------------------------------------------------------
*
* Blt_TableInit --
*
* This procedure is invoked to initialize the Tcl command that
* corresponds to the table geometry manager.
*
* Results:
* None.
*
* Side effects:
* Creates the new command and adds an entry into a global Tcl
* associative array.
*
* ---------------------------------------------------------------------------
*/
int
Blt_TableInit(interp)
Tcl_Interp *interp;
{
static Blt_CmdSpec cmdSpec = {"table", TableCmd, };
TableInterpData *dataPtr;
dataPtr = GetTableInterpData(interp);
cmdSpec.clientData = dataPtr;
if (Blt_InitCmd(interp, "blt", &cmdSpec) == NULL) {
return TCL_ERROR;
}
rowUid = (Blt_Uid)Tk_GetUid("row");
columnUid = (Blt_Uid)Tk_GetUid("column");
return TCL_OK;
}
|