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 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757
|
/*
* bltTabnotebook.c --
*
* This module implements a tab notebook widget for the BLT toolkit.
*
* Copyright 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 or 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.
*
* Tabnotebook widget created by George A. Howlett (gah@bell-labs.com)
*
*/
#include "bltInt.h"
#ifndef NO_TABNOTEBOOK
#include "bltBind.h"
#include "bltChain.h"
#include "bltHash.h"
#include "bltTile.h"
#if (TK_MAJOR_VERSION == 4)
#define TK_REPARENTED 0x2000
#endif
#define INVALID_FAIL 0
#define INVALID_OK 1
/*
* The macro below is used to modify a "char" value (e.g. by casting
* it to an unsigned character) so that it can be used safely with
* macros such as isspace.
*/
#define CLAMP(val,low,hi) \
(((val) < (low)) ? (low) : ((val) > (hi)) ? (hi) : (val))
#define GAP 3
#define SELECT_PADX 4
#define SELECT_PADY 2
#define OUTER_PAD 2
#define LABEL_PAD 1
#define LABEL_PADX 2
#define LABEL_PADY 2
#define IMAGE_PAD 1
#define CORNER_OFFSET 3
#define TAB_SCROLL_OFFSET 10
#define SLANT_NONE 0
#define SLANT_LEFT 1
#define SLANT_RIGHT 2
#define SLANT_BOTH (SLANT_LEFT | SLANT_RIGHT)
#define END (-1)
#define ODD(x) ((x) | 0x01)
#define TABWIDTH(s, t) \
((s)->side & SIDE_VERTICAL) ? (t)->height : (t)->width)
#define TABHEIGHT(s, t) \
((s)->side & SIDE_VERTICAL) ? (t)->height : (t)->width)
#define VPORTWIDTH(s) \
(((s)->side & SIDE_HORIZONTAL) ? (Tk_Width((s)->tkwin) - 2 * (s)->inset) : \
(Tk_Height((s)->tkwin) - 2 * (s)->inset))
#define VPORTHEIGHT(s) \
(((s)->side & SIDE_VERTICAL) ? (Tk_Width((s)->tkwin) - 2 * (s)->inset) : \
(Tk_Height((s)->tkwin) - 2 * (s)->inset))
#define GETATTR(t,attr) \
(((t)->attr != NULL) ? (t)->attr : (t)->nbPtr->defTabStyle.attr)
/*
* ----------------------------------------------------------------------------
*
* Internal widget flags:
*
* TNB_LAYOUT The layout of the widget needs to be
* recomputed.
*
* TNB_REDRAW A redraw request is pending for the widget.
*
* TNB_SCROLL A scroll request is pending.
*
* TNB_FOCUS The widget is receiving keyboard events.
* Draw the focus highlight border around the
* widget.
*
* TNB_MULTIPLE_TIER Notebook is using multiple tiers.
*
* TNB_STATIC Notebook does not scroll.
*
* ---------------------------------------------------------------------------
*/
#define TNB_LAYOUT (1<<0)
#define TNB_REDRAW (1<<1)
#define TNB_SCROLL (1<<2)
#define TNB_FOCUS (1<<4)
#define TNB_STATIC (1<<8)
#define TNB_MULTIPLE_TIER (1<<9)
#define PERFORATION_ACTIVE (1<<10)
#define SIDE_TOP (1<<0)
#define SIDE_RIGHT (1<<1)
#define SIDE_LEFT (1<<2)
#define SIDE_BOTTOM (1<<3)
#define SIDE_VERTICAL (SIDE_LEFT | SIDE_RIGHT)
#define SIDE_HORIZONTAL (SIDE_TOP | SIDE_BOTTOM)
#define TAB_LABEL (ClientData)0
#define TAB_PERFORATION (ClientData)1
#define DEF_TNB_ACTIVE_BACKGROUND RGB_GREY90
#define DEF_TNB_ACTIVE_BG_MONO STD_ACTIVE_BG_MONO
#define DEF_TNB_ACTIVE_FOREGROUND STD_ACTIVE_FOREGROUND
#define DEF_TNB_ACTIVE_FG_MONO STD_ACTIVE_FG_MONO
#define DEF_TNB_BG_MONO STD_NORMAL_BG_MONO
#define DEF_TNB_BACKGROUND STD_NORMAL_BACKGROUND
#define DEF_TNB_BORDERWIDTH "1"
#define DEF_TNB_COMMAND (char *)NULL
#define DEF_TNB_CURSOR (char *)NULL
#define DEF_TNB_DASHES "1"
#define DEF_TNB_FOREGROUND STD_NORMAL_FOREGROUND
#define DEF_TNB_FG_MONO STD_NORMAL_FG_MONO
#define DEF_TNB_FONT STD_FONT
#define DEF_TNB_GAP "3"
#define DEF_TNB_HEIGHT "0"
#define DEF_TNB_HIGHLIGHT_BACKGROUND STD_NORMAL_BACKGROUND
#define DEF_TNB_HIGHLIGHT_BG_MONO STD_NORMAL_BG_MONO
#define DEF_TNB_HIGHLIGHT_COLOR RGB_BLACK
#define DEF_TNB_HIGHLIGHT_WIDTH "2"
#define DEF_TNB_NORMAL_BACKGROUND STD_NORMAL_BACKGROUND
#define DEF_TNB_NORMAL_FG_MONO STD_ACTIVE_FG_MONO
#define DEF_TNB_OUTER_PAD "3"
#define DEF_TNB_RELIEF "sunken"
#define DEF_TNB_ROTATE "0.0"
#define DEF_TNB_SCROLL_INCREMENT "0"
#define DEF_TNB_SELECT_BACKGROUND STD_NORMAL_BACKGROUND
#define DEF_TNB_SELECT_BG_MONO STD_SELECT_BG_MONO
#define DEF_TNB_SELECT_BORDERWIDTH "1"
#define DEF_TNB_SELECT_CMD (char *)NULL
#define DEF_TNB_SELECT_FOREGROUND STD_SELECT_FOREGROUND
#define DEF_TNB_SELECT_FG_MONO STD_SELECT_FG_MONO
#define DEF_TNB_SELECT_MODE "multiple"
#define DEF_TNB_SELECT_RELIEF "raised"
#define DEF_TNB_SELECT_PAD "5"
#define DEF_TNB_SHADOW_COLOR RGB_BLACK
#define DEF_TNB_SIDE "top"
#define DEF_TNB_SLANT "none"
#define DEF_TNB_TAB_BACKGROUND RGB_GREY82
#define DEF_TNB_TAB_BG_MONO STD_SELECT_BG_MONO
#define DEF_TNB_TAB_RELIEF "raised"
#define DEF_TNB_TAKE_FOCUS "1"
#define DEF_TNB_TEXT_COLOR STD_NORMAL_FOREGROUND
#define DEF_TNB_TEXT_MONO STD_NORMAL_FG_MONO
#define DEF_TNB_TEXT_SIDE "left"
#define DEF_TNB_TIERS "1"
#define DEF_TNB_TILE (char *)NULL
#define DEF_TNB_WIDTH "0"
#define DEF_TNB_SAME_WIDTH "yes"
#define DEF_TNB_TEAROFF "yes"
#define DEF_TNB_PAGE_WIDTH "0"
#define DEF_TNB_PAGE_HEIGHT "0"
#define DEF_TAB_ACTIVE_BG (char *)NULL
#define DEF_TAB_ACTIVE_FG (char *)NULL
#define DEF_TAB_ANCHOR "center"
#define DEF_TAB_BG (char *)NULL
#define DEF_TAB_COMMAND (char *)NULL
#define DEF_TAB_DATA (char *)NULL
#define DEF_TAB_FG (char *)NULL
#define DEF_TAB_FILL "none"
#define DEF_TAB_FONT (char *)NULL
#define DEF_TAB_HEIGHT "0"
#define DEF_TAB_IMAGE (char *)NULL
#define DEF_TAB_IPAD "0"
#define DEF_TAB_PAD "3"
#define DEF_TAB_PERF_COMMAND (char *)NULL
#define DEF_TAB_SELECT_BG (char *)NULL
#define DEF_TAB_SELECT_BORDERWIDTH "1"
#define DEF_TAB_SELECT_CMD (char *)NULL
#define DEF_TAB_SELECT_FG (char *)NULL
#define DEF_TAB_SHADOW (char *)NULL
#define DEF_TAB_STATE "normal"
#define DEF_TAB_STIPPLE "BLT"
#define DEF_TAB_BIND_TAGS "all"
#define DEF_TAB_TEXT (char *)NULL
#define DEF_TAB_VISUAL (char *)NULL
#define DEF_TAB_WIDTH "0"
#define DEF_TAB_WINDOW (char *)NULL
typedef struct NotebookStruct Notebook;
static void EmbeddedWidgetGeometryProc _ANSI_ARGS_((ClientData, Tk_Window));
static void EmbeddedWidgetCustodyProc _ANSI_ARGS_((ClientData, Tk_Window));
static Tk_GeomMgr tabMgrInfo =
{
"notebook", /* Name of geometry manager used by winfo */
EmbeddedWidgetGeometryProc, /* Procedure to for new geometry requests */
EmbeddedWidgetCustodyProc, /* Procedure when window is taken away */
};
extern Tk_CustomOption bltDashesOption;
extern Tk_CustomOption bltFillOption;
extern Tk_CustomOption bltDistanceOption;
extern Tk_CustomOption bltPositiveDistanceOption;
extern Tk_CustomOption bltPositiveCountOption;
extern Tk_CustomOption bltListOption;
extern Tk_CustomOption bltPadOption;
extern Tk_CustomOption bltShadowOption;
extern Tk_CustomOption bltStateOption;
extern Tk_CustomOption bltTileOption;
extern Tk_CustomOption bltUidOption;
static int StringToImage _ANSI_ARGS_((ClientData clientData,
Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
int offset));
static char *ImageToString _ANSI_ARGS_((ClientData clientData,
Tk_Window tkwin, char *widgRec, int offset,
Tcl_FreeProc **freeProcPtrPtr));
static int StringToWindow _ANSI_ARGS_((ClientData clientData,
Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
int offset));
static char *WindowToString _ANSI_ARGS_((ClientData clientData,
Tk_Window tkwin, char *widgRec, int offset,
Tcl_FreeProc **freeProcPtrPtr));
static int StringToSide _ANSI_ARGS_((ClientData clientData,
Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
int offset));
static char *SideToString _ANSI_ARGS_((ClientData clientData,
Tk_Window tkwin, char *widgRec, int offset,
Tcl_FreeProc **freeProcPtrPtr));
static int StringToSlant _ANSI_ARGS_((ClientData clientData,
Tcl_Interp *interp, Tk_Window tkwin, char *string, char *widgRec,
int offset));
static char *SlantToString _ANSI_ARGS_((ClientData clientData,
Tk_Window tkwin, char *widgRec, int offset,
Tcl_FreeProc **freeProcPtrPtr));
/*
* Contains a pointer to the widget that's currently being configured.
* This is used in the custom configuration parse routine for images.
*/
static Notebook *lastNotebookInstance;
static Tk_CustomOption imageOption =
{
StringToImage, ImageToString, (ClientData)&lastNotebookInstance,
};
static Tk_CustomOption sideOption =
{
StringToSide, SideToString, (ClientData)0,
};
static Tk_CustomOption windowOption =
{
StringToWindow, WindowToString, (ClientData)0,
};
static Tk_CustomOption slantOption =
{
StringToSlant, SlantToString, (ClientData)0,
};
/*
* TabImage --
*
* When multiple instances of an image are displayed in the
* same widget, this can be inefficient in terms of both memory
* and time. We only need one instance of each image, regardless
* of number of times we use it. And searching/deleting instances
* can be very slow as the list gets large.
*
* The workaround, employed below, is to maintain a hash table of
* images that maintains a reference count for each image.
*/
typedef struct TabImageStruct {
int refCount; /* Reference counter for this image. */
Tk_Image tkImage; /* The Tk image being cached. */
int width, height; /* Dimensions of the cached image. */
Blt_HashEntry *hashPtr; /* Hash table pointer to the image. */
} *TabImage;
#define ImageHeight(image) ((image)->height)
#define ImageWidth(image) ((image)->width)
#define ImageBits(image) ((image)->tkImage)
#define TAB_VISIBLE (1<<0)
#define TAB_REDRAW (1<<2)
typedef struct {
char *name; /* Identifier for tab entry */
int state; /* State of the tab: Disabled, active, or
* normal. */
unsigned int flags;
int tier; /* Index of tier [1..numTiers] containing
* this tab. */
int worldX, worldY; /* Position of the tab in world coordinates. */
int worldWidth, worldHeight;/* Dimensions of the tab, corrected for
* orientation (-side). It includes the
* border, padding, label, etc. */
int screenX, screenY;
short int screenWidth, screenHeight; /* */
Notebook *nbPtr; /* Notebook that includes this
* tab. Needed for callbacks can pass
* only a tab pointer. */
Blt_Uid tags;
/*
* Tab label:
*/
Blt_Uid text; /* String displayed as the tab's label. */
TabImage image; /* Image displayed as the label. */
short int textWidth, textHeight;
short int labelWidth, labelHeight;
Blt_Pad iPadX, iPadY; /* Internal padding around the text */
Tk_Font font;
/*
* Normal:
*/
XColor *textColor; /* Text color */
Tk_3DBorder border; /* Background color and border for tab.*/
/*
* Selected: Tab is currently selected.
*/
XColor *selColor; /* Selected text color */
Tk_3DBorder selBorder; /* 3D border of selected folder. */
/*
* Active: Mouse passes over the tab.
*/
Tk_3DBorder activeBorder; /* Active background color. */
XColor *activeFgColor; /* Active text color */
Shadow shadow;
Pixmap stipple; /* Stipple for outline of embedded window
* when torn off. */
/*
* Embedded widget information:
*/
Tk_Window tkwin; /* Widget to be mapped when the tab is
* selected. If NULL, don't make
* space for the page. */
int reqWidth, reqHeight; /* If non-zero, overrides the
* requested dimensions of the
* embedded widget. */
Tk_Window container; /* The window containing the embedded
* widget. Does not necessarily have
* to be the parent. */
Tk_Anchor anchor; /* Anchor: indicates how the embedded
* widget is positioned within the
* extra space on the page. */
Blt_Pad padX, padY; /* Padding around embedded widget */
int fill; /* Indicates how the window should
* fill the page. */
/*
* Auxillary information:
*/
Blt_Uid command; /* Command (malloc-ed) invoked when the tab
* is selected */
Blt_Uid data; /* This value isn't used in C code.
* It may be used by clients in Tcl bindings
* to associate extra data (other than the
* label or name) with the tab. */
Blt_ChainLink *linkPtr; /* Pointer to where the tab resides in the
* list of tabs. */
Blt_Uid perfCommand; /* Command (malloc-ed) invoked when the tab
* is selected */
GC textGC;
GC backGC;
Blt_Tile tile;
} Tab;
static Tk_ConfigSpec tabConfigSpecs[] =
{
{TK_CONFIG_BORDER, "-activebackground", "activeBackground",
"ActiveBackground", DEF_TAB_ACTIVE_BG,
Tk_Offset(Tab, activeBorder), TK_CONFIG_NULL_OK},
{TK_CONFIG_COLOR, "-activeforeground", "activeForeground",
"ActiveForeground", DEF_TAB_ACTIVE_FG,
Tk_Offset(Tab, activeFgColor), TK_CONFIG_NULL_OK},
{TK_CONFIG_ANCHOR, "-anchor", "anchor", "Anchor",
DEF_TAB_ANCHOR, Tk_Offset(Tab, anchor), TK_CONFIG_DONT_SET_DEFAULT},
{TK_CONFIG_BORDER, "-background", "background", "Background",
DEF_TAB_BG, Tk_Offset(Tab, border), TK_CONFIG_NULL_OK},
{TK_CONFIG_SYNONYM, "-bg", "background", (char *)NULL, (char *)NULL, 0, 0},
{TK_CONFIG_CUSTOM, "-bindtags", "bindTags", "BindTags",
DEF_TAB_BIND_TAGS, Tk_Offset(Tab, tags),
TK_CONFIG_NULL_OK, &bltUidOption},
{TK_CONFIG_CUSTOM, "-command", "command", "Command",
DEF_TAB_COMMAND, Tk_Offset(Tab, command),
TK_CONFIG_NULL_OK, &bltUidOption},
{TK_CONFIG_CUSTOM, "-data", "data", "data",
DEF_TAB_DATA, Tk_Offset(Tab, data),
TK_CONFIG_NULL_OK, &bltUidOption},
{TK_CONFIG_SYNONYM, "-fg", "foreground", (char *)NULL, (char *)NULL, 0, 0},
{TK_CONFIG_CUSTOM, "-fill", "fill", "Fill",
DEF_TAB_FILL, Tk_Offset(Tab, fill),
TK_CONFIG_DONT_SET_DEFAULT, &bltFillOption},
{TK_CONFIG_COLOR, "-foreground", "foreground", "Foreground",
DEF_TAB_FG, Tk_Offset(Tab, textColor), TK_CONFIG_NULL_OK},
{TK_CONFIG_FONT, "-font", "font", "Font",
DEF_TAB_FONT, Tk_Offset(Tab, font), 0},
{TK_CONFIG_CUSTOM, "-image", "image", "image",
DEF_TAB_IMAGE, Tk_Offset(Tab, image),
TK_CONFIG_NULL_OK, &imageOption},
{TK_CONFIG_CUSTOM, "-ipadx", "iPadX", "PadX",
DEF_TAB_IPAD, Tk_Offset(Tab, iPadX),
TK_CONFIG_DONT_SET_DEFAULT, &bltPadOption},
{TK_CONFIG_CUSTOM, "-ipady", "iPadY", "PadY",
DEF_TAB_IPAD, Tk_Offset(Tab, iPadY),
TK_CONFIG_DONT_SET_DEFAULT, &bltPadOption},
{TK_CONFIG_CUSTOM, "-padx", "padX", "PadX",
DEF_TAB_PAD, Tk_Offset(Tab, padX), 0, &bltPadOption},
{TK_CONFIG_CUSTOM, "-pady", "padY", "PadY",
DEF_TAB_PAD, Tk_Offset(Tab, padY), 0, &bltPadOption},
{TK_CONFIG_CUSTOM, "-perforationcommand", "perforationcommand",
"PerforationCommand",
DEF_TAB_PERF_COMMAND, Tk_Offset(Tab, perfCommand),
TK_CONFIG_NULL_OK, &bltUidOption},
{TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Background",
DEF_TAB_SELECT_BG, Tk_Offset(Tab, selBorder), TK_CONFIG_NULL_OK},
{TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Foreground",
DEF_TAB_SELECT_FG, Tk_Offset(Tab, selColor), TK_CONFIG_NULL_OK},
{TK_CONFIG_CUSTOM, "-shadow", "shadow", "Shadow",
DEF_TAB_SHADOW, Tk_Offset(Tab, shadow),
TK_CONFIG_NULL_OK, &bltShadowOption},
{TK_CONFIG_CUSTOM, "-state", "state", "State",
DEF_TAB_STATE, Tk_Offset(Tab, state),
TK_CONFIG_DONT_SET_DEFAULT, &bltStateOption},
{TK_CONFIG_BITMAP, "-stipple", "stipple", "Stipple",
DEF_TAB_STIPPLE, Tk_Offset(Tab, stipple), 0},
{TK_CONFIG_CUSTOM, "-tile", "tile", "Tile",
(char *)NULL, Tk_Offset(Tab, tile), TK_CONFIG_NULL_OK,
&bltTileOption},
{TK_CONFIG_CUSTOM, "-text", "Text", "Text",
DEF_TAB_TEXT, Tk_Offset(Tab, text),
TK_CONFIG_NULL_OK, &bltUidOption},
{TK_CONFIG_CUSTOM, "-window", "window", "Window",
DEF_TAB_WINDOW, Tk_Offset(Tab, tkwin),
TK_CONFIG_NULL_OK, &windowOption},
{TK_CONFIG_CUSTOM, "-windowheight", "windowHeight", "WindowHeight",
DEF_TAB_HEIGHT, Tk_Offset(Tab, reqHeight),
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
{TK_CONFIG_CUSTOM, "-windowwidth", "windowWidth", "WindowWidth",
DEF_TAB_WIDTH, Tk_Offset(Tab, reqWidth),
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
{TK_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL,
(char *)NULL, 0, 0}
};
/*
* TabAttributes --
*/
typedef struct {
Tk_Window tkwin; /* Default window to map pages. */
int reqWidth, reqHeight; /* Requested tab size. */
int constWidth;
int borderWidth; /* Width of 3D border around the tab's
* label. */
int pad; /* Extra padding of a tab entry */
XColor *activeFgColor; /* Active foreground. */
Tk_3DBorder activeBorder; /* Active background. */
XColor *selColor; /* Selected foreground. */
Tk_Font font;
XColor *textColor;
Tk_3DBorder border; /* Normal background. */
Tk_3DBorder selBorder; /* Selected background. */
Blt_Dashes dashes;
GC normalGC, activeGC;
int relief;
char *command;
char *perfCommand; /* Command (malloc-ed) invoked when the tab
* is selected */
double rotate;
int textSide;
} TabAttributes;
struct NotebookStruct {
Tk_Window tkwin; /* Window that embodies the widget.
* NULL means that the window has been
* destroyed but the data structures
* haven't yet been cleaned up.*/
Display *display; /* Display containing widget; needed,
* among other things, to release
* resources after tkwin has already
* gone away. */
Tcl_Interp *interp; /* Interpreter associated with widget. */
Tcl_Command cmdToken; /* Token for widget's command. */
unsigned int flags; /* For bitfield definitions, see below */
int inset; /* Total width of all borders, including
* traversal highlight and 3-D border.
* Indicates how much interior stuff must
* be offset from outside edges to leave
* room for borders. */
int inset2; /* Total width of 3-D folder border + corner,
* Indicates how much interior stuff must
* be offset from outside edges of folder.*/
int yPad; /* Extra offset for selected tab. Only
* for single tiers. */
int pageTop; /* Offset from top of notebook to the
* start of the page. */
Tk_Cursor cursor; /* X Cursor */
Tk_3DBorder border; /* 3D border surrounding the window. */
int borderWidth; /* Width of 3D border. */
int relief; /* 3D border relief. */
XColor *shadowColor; /* Shadow color around folder. */
/*
* Focus highlight ring
*/
int highlightWidth; /* Width in pixels of highlight to draw
* around widget when it has the focus.
* <= 0 means don't draw a highlight. */
XColor *highlightBgColor; /* Color for drawing traversal highlight
* area when highlight is off. */
XColor *highlightColor; /* Color for drawing traversal highlight. */
GC highlightGC; /* GC for focus highlight. */
char *takeFocus; /* Says whether to select this widget during
* tab traveral operations. This value isn't
* used in C code, but for the widget's Tcl
* bindings. */
int side; /* Orientation of the notebook: either
* SIDE_LEFT, SIDE_RIGHT, SIDE_TOP, or
* SIDE_BOTTOM. */
int slant;
int overlap;
int gap;
int tabWidth, tabHeight;
int xSelectPad, ySelectPad; /* Padding around label of the selected tab. */
int outerPad; /* Padding around the exterior of the notebook
* and folder. */
TabAttributes defTabStyle; /* Global attribute information specific to
* tabs. */
Blt_Tile tile;
int reqWidth, reqHeight; /* Requested dimensions of the notebook
* window. */
int pageWidth, pageHeight; /* Dimensions of a page in the folder. */
int reqPageWidth, reqPageHeight; /* Requested dimensions of a page. */
int lastX, lastY;
/*
* Scrolling information:
*/
int worldWidth;
int scrollOffset; /* Offset of viewport in world coordinates. */
char *scrollCmdPrefix; /* Command strings to control scrollbar.*/
int scrollUnits; /* Smallest unit of scrolling for tabs. */
/*
* Scanning information:
*/
int scanAnchor; /* Scan anchor in screen coordinates. */
int scanOffset; /* Offset of the start of the scan in world
* coordinates.*/
int corner; /* Number of pixels to offset next point
* when drawing corners of the folder. */
int reqTiers; /* Requested number of tiers. Zero means to
* dynamically scroll if there are too many
* tabs to be display on a single tier. */
int nTiers; /* Actual number of tiers. */
Blt_HashTable imageTable;
Tab *selectPtr; /* The currently selected tab.
* (i.e. its page is displayed). */
Tab *activePtr; /* Tab last located under the pointer.
* It is displayed with its active
* foreground/background colors. */
Tab *focusPtr; /* Tab currently receiving focus. */
Tab *startPtr; /* The first tab on the first tier. */
Blt_Chain *chainPtr; /* List of tab entries. Used to
* arrange placement of tabs. */
Blt_HashTable tabTable; /* Hash table of tab entries. Used for
* lookups of tabs by name. */
int nextId;
int nVisible; /* Number of tabs that are currently visible
* in the view port. */
Blt_BindTable bindTable; /* Tab binding information */
Blt_HashTable tagTable; /* Table of bind tags. */
int tearoff;
};
static Tk_ConfigSpec configSpecs[] =
{
{TK_CONFIG_BORDER, "-activebackground", "activeBackground",
"activeBackground",
DEF_TNB_ACTIVE_BACKGROUND, Tk_Offset(Notebook, defTabStyle.activeBorder),
TK_CONFIG_COLOR_ONLY},
{TK_CONFIG_BORDER, "-activebackground", "activeBackground",
"activeBackground",
DEF_TNB_ACTIVE_BG_MONO, Tk_Offset(Notebook, defTabStyle.activeBorder),
TK_CONFIG_MONO_ONLY},
{TK_CONFIG_COLOR, "-activeforeground", "activeForeground",
"activeForeground", DEF_TNB_ACTIVE_FOREGROUND,
Tk_Offset(Notebook, defTabStyle.activeFgColor), TK_CONFIG_COLOR_ONLY},
{TK_CONFIG_COLOR, "-activeforeground", "activeForeground",
"activeForeground", DEF_TNB_ACTIVE_FG_MONO,
Tk_Offset(Notebook, defTabStyle.activeFgColor), TK_CONFIG_MONO_ONLY},
{TK_CONFIG_BORDER, "-background", "background", "Background",
DEF_TNB_BG_MONO, Tk_Offset(Notebook, border), TK_CONFIG_MONO_ONLY},
{TK_CONFIG_BORDER, "-background", "background", "Background",
DEF_TNB_BACKGROUND, Tk_Offset(Notebook, border), TK_CONFIG_COLOR_ONLY},
{TK_CONFIG_SYNONYM, "-bd", "borderWidth", (char *)NULL, (char *)NULL, 0, 0},
{TK_CONFIG_SYNONYM, "-bg", "background", (char *)NULL, (char *)NULL, 0, 0},
{TK_CONFIG_ACTIVE_CURSOR, "-cursor", "cursor", "Cursor",
DEF_TNB_CURSOR, Tk_Offset(Notebook, cursor), TK_CONFIG_NULL_OK},
{TK_CONFIG_CUSTOM, "-borderwidth", "borderWidth", "BorderWidth",
DEF_TNB_BORDERWIDTH, Tk_Offset(Notebook, borderWidth),
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
{TK_CONFIG_CUSTOM, "-dashes", "dashes", "Dashes",
DEF_TNB_DASHES, Tk_Offset(Notebook, defTabStyle.dashes),
TK_CONFIG_NULL_OK, &bltDashesOption},
{TK_CONFIG_SYNONYM, "-fg", "tabForeground", (char *)NULL,
(char *)NULL, 0, 0},
{TK_CONFIG_FONT, "-font", "font", "Font",
DEF_TNB_FONT, Tk_Offset(Notebook, defTabStyle.font), 0},
{TK_CONFIG_SYNONYM, "-foreground", "tabForeground", (char *)NULL,
(char *)NULL, 0, 0},
{TK_CONFIG_PIXELS, "-gap", "gap", "Gap",
DEF_TNB_GAP, Tk_Offset(Notebook, gap),
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
{TK_CONFIG_CUSTOM, "-height", "height", "Height",
DEF_TNB_HEIGHT, Tk_Offset(Notebook, reqHeight),
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
{TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground",
"HighlightBackground",
DEF_TNB_HIGHLIGHT_BACKGROUND, Tk_Offset(Notebook, highlightBgColor),
TK_CONFIG_COLOR_ONLY},
{TK_CONFIG_COLOR, "-highlightbackground", "highlightBackground",
"HighlightBackground",
DEF_TNB_HIGHLIGHT_BG_MONO, Tk_Offset(Notebook, highlightBgColor),
TK_CONFIG_MONO_ONLY},
{TK_CONFIG_COLOR, "-highlightcolor", "highlightColor", "HighlightColor",
DEF_TNB_HIGHLIGHT_COLOR, Tk_Offset(Notebook, highlightColor), 0},
{TK_CONFIG_PIXELS, "-highlightthickness", "highlightThickness",
"HighlightThickness",
DEF_TNB_HIGHLIGHT_WIDTH, Tk_Offset(Notebook, highlightWidth),
TK_CONFIG_DONT_SET_DEFAULT},
{TK_CONFIG_CUSTOM, "-outerpad", "outerPad", "OuterPad",
DEF_TNB_OUTER_PAD, Tk_Offset(Notebook, outerPad),
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
{TK_CONFIG_CUSTOM, "-pageheight", "pageHeight", "PageHeight",
DEF_TNB_PAGE_HEIGHT, Tk_Offset(Notebook, reqPageHeight),
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
{TK_CONFIG_CUSTOM, "-pagewidth", "pageWidth", "PageWidth",
DEF_TNB_PAGE_WIDTH, Tk_Offset(Notebook, reqPageWidth),
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
{TK_CONFIG_STRING, "-perforationcommand", "perforationcommand",
"PerforationCommand",
DEF_TAB_PERF_COMMAND, Tk_Offset(Notebook, defTabStyle.perfCommand),
TK_CONFIG_NULL_OK, &bltUidOption},
{TK_CONFIG_RELIEF, "-relief", "relief", "Relief",
DEF_TNB_RELIEF, Tk_Offset(Notebook, relief), 0},
{TK_CONFIG_DOUBLE, "-rotate", "rotate", "Rotate",
DEF_TNB_ROTATE, Tk_Offset(Notebook, defTabStyle.rotate),
TK_CONFIG_DONT_SET_DEFAULT},
{TK_CONFIG_BOOLEAN, "-samewidth", "sameWidth", "SameWidth",
DEF_TNB_SAME_WIDTH, Tk_Offset(Notebook, defTabStyle.constWidth),
TK_CONFIG_DONT_SET_DEFAULT},
{TK_CONFIG_STRING, "-scrollcommand", "scrollCommand", "ScrollCommand",
(char *)NULL, Tk_Offset(Notebook, scrollCmdPrefix), TK_CONFIG_NULL_OK},
{TK_CONFIG_CUSTOM, "-scrollincrement", "scrollIncrement",
"ScrollIncrement",
DEF_TNB_SCROLL_INCREMENT, Tk_Offset(Notebook, scrollUnits),
TK_CONFIG_DONT_SET_DEFAULT, &bltPositiveDistanceOption},
{TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground",
DEF_TNB_SELECT_BG_MONO, Tk_Offset(Notebook, defTabStyle.selBorder),
TK_CONFIG_MONO_ONLY},
{TK_CONFIG_BORDER, "-selectbackground", "selectBackground", "Foreground",
DEF_TNB_SELECT_BACKGROUND, Tk_Offset(Notebook, defTabStyle.selBorder),
TK_CONFIG_COLOR_ONLY},
{TK_CONFIG_STRING, "-selectcommand", "selectCommand", "SelectCommand",
DEF_TNB_SELECT_CMD, Tk_Offset(Notebook, defTabStyle.command),
TK_CONFIG_NULL_OK},
{TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Background",
DEF_TNB_SELECT_FG_MONO, Tk_Offset(Notebook, defTabStyle.selColor),
TK_CONFIG_MONO_ONLY},
{TK_CONFIG_COLOR, "-selectforeground", "selectForeground", "Background",
DEF_TNB_SELECT_FOREGROUND, Tk_Offset(Notebook, defTabStyle.selColor),
TK_CONFIG_COLOR_ONLY},
{TK_CONFIG_CUSTOM, "-selectpad", "selectPad", "SelectPad",
DEF_TNB_SELECT_PAD, Tk_Offset(Notebook, xSelectPad),
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
{TK_CONFIG_COLOR, "-shadowcolor", "shadowColor", "ShadowColor",
DEF_TNB_SHADOW_COLOR, Tk_Offset(Notebook, shadowColor), 0},
{TK_CONFIG_CUSTOM, "-side", "side", "side",
DEF_TNB_SIDE, Tk_Offset(Notebook, side),
TK_CONFIG_DONT_SET_DEFAULT, &sideOption},
{TK_CONFIG_CUSTOM, "-slant", "slant", "Slant",
DEF_TNB_SLANT, Tk_Offset(Notebook, slant),
TK_CONFIG_DONT_SET_DEFAULT, &slantOption},
{TK_CONFIG_BORDER, "-tabbackground", "tabBackground", "Background",
DEF_TNB_TAB_BG_MONO, Tk_Offset(Notebook, defTabStyle.border),
TK_CONFIG_MONO_ONLY},
{TK_CONFIG_BORDER, "-tabbackground", "tabBackground", "Background",
DEF_TNB_TAB_BACKGROUND, Tk_Offset(Notebook, defTabStyle.border),
TK_CONFIG_COLOR_ONLY},
{TK_CONFIG_CUSTOM, "-tabborderwidth", "tabBorderWidth", "BorderWidth",
DEF_TNB_BORDERWIDTH, Tk_Offset(Notebook, defTabStyle.borderWidth),
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
{TK_CONFIG_COLOR, "-tabforeground", "tabForeground", "Foreground",
DEF_TNB_TEXT_COLOR, Tk_Offset(Notebook, defTabStyle.textColor),
TK_CONFIG_COLOR_ONLY},
{TK_CONFIG_COLOR, "-tabforeground", "tabForeground", "Foreground",
DEF_TNB_TEXT_MONO, Tk_Offset(Notebook, defTabStyle.textColor),
TK_CONFIG_MONO_ONLY},
{TK_CONFIG_RELIEF, "-tabrelief", "tabRelief", "TabRelief",
DEF_TNB_TAB_RELIEF, Tk_Offset(Notebook, defTabStyle.relief), 0},
{TK_CONFIG_STRING, "-takefocus", "takeFocus", "TakeFocus",
DEF_TNB_TAKE_FOCUS, Tk_Offset(Notebook, takeFocus), TK_CONFIG_NULL_OK},
{TK_CONFIG_BOOLEAN, "-tearoff", "tearoff", "Tearoff",
DEF_TNB_TEAROFF, Tk_Offset(Notebook, tearoff),
TK_CONFIG_DONT_SET_DEFAULT},
{TK_CONFIG_CUSTOM, "-textside", "textSide", "TextSide",
DEF_TNB_TEXT_SIDE, Tk_Offset(Notebook, defTabStyle.textSide),
TK_CONFIG_DONT_SET_DEFAULT, &sideOption},
{TK_CONFIG_CUSTOM, "-tiers", "tiers", "Tiers",
DEF_TNB_TIERS, Tk_Offset(Notebook, reqTiers),
TK_CONFIG_DONT_SET_DEFAULT, &bltPositiveCountOption},
{TK_CONFIG_CUSTOM, "-tile", "tile", "Tile",
(char *)NULL, Tk_Offset(Notebook, tile), TK_CONFIG_NULL_OK,
&bltTileOption},
{TK_CONFIG_CUSTOM, "-width", "width", "Width",
DEF_TNB_WIDTH, Tk_Offset(Notebook, reqWidth),
TK_CONFIG_DONT_SET_DEFAULT, &bltDistanceOption},
{TK_CONFIG_END, (char *)NULL, (char *)NULL, (char *)NULL,
(char *)NULL, 0, 0}
};
/* Forward Declarations */
static void DestroyNotebook _ANSI_ARGS_((DestroyData dataPtr));
static void DestroyTearoff _ANSI_ARGS_((DestroyData dataPtr));
static void EmbeddedWidgetEventProc _ANSI_ARGS_((ClientData clientdata,
XEvent *eventPtr));
static void TearoffEventProc _ANSI_ARGS_((ClientData clientdata,
XEvent *eventPtr));
static void NotebookEventProc _ANSI_ARGS_((ClientData clientdata,
XEvent *eventPtr));
static void DrawLabel _ANSI_ARGS_((Notebook *nbPtr, Tab *tabPtr,
Drawable drawable));
static void DrawFolder _ANSI_ARGS_((Notebook *nbPtr, Tab *tabPtr,
Drawable drawable));
static void DisplayNotebook _ANSI_ARGS_((ClientData clientData));
static void DisplayTearoff _ANSI_ARGS_((ClientData clientData));
static void NotebookInstDeletedCmd _ANSI_ARGS_((ClientData clientdata));
static int NotebookInstCmd _ANSI_ARGS_((ClientData clientdata,
Tcl_Interp *interp, int argc, char **argv));
static void GetWindowRectangle _ANSI_ARGS_((Tab *tabPtr, Tk_Window parent,
int tearOff, XRectangle *rectPtr));
static void ArrangeWindow _ANSI_ARGS_((Tk_Window tkwin, XRectangle *rectPtr,
int force));
static void EventuallyRedraw _ANSI_ARGS_((Notebook *nbPtr));
static void EventuallyRedrawTearoff _ANSI_ARGS_((Tab *tabPtr));
static void ComputeLayout _ANSI_ARGS_((Notebook *nbPtr));
static void DrawOuterBorders _ANSI_ARGS_((Notebook *nbPtr,
Drawable drawable));
static Tk_ImageChangedProc ImageChangedProc;
static Blt_TileChangedProc TileChangedProc;
static Blt_BindTagProc GetTags;
static Blt_BindPickProc PickTab;
static Tcl_IdleProc AdoptWindow;
static Tcl_CmdProc NotebookCmd;
static ClientData
MakeTag(nbPtr, tagName)
Notebook *nbPtr;
char *tagName;
{
Blt_HashEntry *hPtr;
int isNew;
hPtr = Blt_CreateHashEntry(&(nbPtr->tagTable), tagName, &isNew);
assert(hPtr);
return Blt_GetHashKey(&(nbPtr->tagTable), hPtr);
}
/*
*----------------------------------------------------------------------
*
* WorldToScreen --
*
* Converts world coordinates to screen coordinates. Note that
* the world view is always tabs up.
*
* Results:
* The screen coordinates are returned via *xScreenPtr and *yScreenPtr.
*
*----------------------------------------------------------------------
*/
static void
WorldToScreen(nbPtr, x, y, xScreenPtr, yScreenPtr)
Notebook *nbPtr;
int x, y;
int *xScreenPtr, *yScreenPtr;
{
int sx, sy;
sx = sy = 0; /* Suppress compiler warning. */
/* Translate world X-Y to screen coordinates */
/*
* Note that the world X-coordinate is translated by the selected label's
* X padding. This is done only to keep the scroll range is between
* 0.0 and 1.0, rather adding/subtracting the pad in various locations.
* It may be changed back in the future.
*/
x += (nbPtr->inset +
nbPtr->xSelectPad -
nbPtr->scrollOffset);
y += nbPtr->inset + nbPtr->yPad;
switch (nbPtr->side) {
case SIDE_TOP:
sx = x, sy = y; /* Do nothing */
break;
case SIDE_RIGHT:
sx = Tk_Width(nbPtr->tkwin) - y;
sy = x;
break;
case SIDE_LEFT:
sx = y, sy = x; /* Flip coordinates */
break;
case SIDE_BOTTOM:
sx = x;
sy = Tk_Height(nbPtr->tkwin) - y;
break;
}
*xScreenPtr = sx;
*yScreenPtr = sy;
}
/*
*----------------------------------------------------------------------
*
* EventuallyRedraw --
*
* Queues a request to redraw the widget at the next idle point.
*
* Results:
* None.
*
* Side effects:
* Information gets redisplayed. Right now we don't do selective
* redisplays: the whole window will be redrawn.
*
*----------------------------------------------------------------------
*/
static void
EventuallyRedraw(nbPtr)
Notebook *nbPtr;
{
if ((nbPtr->tkwin != NULL) && !(nbPtr->flags & TNB_REDRAW)) {
nbPtr->flags |= TNB_REDRAW;
Tcl_DoWhenIdle(DisplayNotebook, nbPtr);
}
}
/*
*----------------------------------------------------------------------
*
* EventuallyRedrawTearoff --
*
* Queues a request to redraw the tearoff at the next idle point.
*
* Results:
* None.
*
* Side effects:
* Information gets redisplayed. Right now we don't do selective
* redisplays: the whole window will be redrawn.
*
*----------------------------------------------------------------------
*/
static void
EventuallyRedrawTearoff(tabPtr)
Tab *tabPtr;
{
if ((tabPtr->tkwin != NULL) && !(tabPtr->flags & TAB_REDRAW)) {
tabPtr->flags |= TAB_REDRAW;
Tcl_DoWhenIdle(DisplayTearoff, tabPtr);
}
}
/*
*----------------------------------------------------------------------
*
* ImageChangedProc
*
* This routine is called whenever an image displayed in a tab
* changes. In this case, we assume that everything will change
* and queue a request to re-layout and redraw the entire notebook.
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
/* ARGSUSED */
static void
ImageChangedProc(clientData, x, y, width, height, imageWidth, imageHeight)
ClientData clientData;
int x, y, width, height; /* Not used. */
int imageWidth, imageHeight;/* Not used. */
{
Notebook *nbPtr = clientData;
nbPtr->flags |= (TNB_LAYOUT | TNB_SCROLL);
EventuallyRedraw(nbPtr);
}
/*
*----------------------------------------------------------------------
*
* GetImage --
*
* This is a wrapper procedure for Tk_GetImage. The problem is
* that if the same image is used repeatedly in the same widget,
* the separate instances are saved in a linked list. This makes
* it especially slow to destroy the widget. As a workaround,
* this routine hashes the image and maintains a reference count
* for it.
*
* Results:
* Returns a pointer to the new image.
*
*----------------------------------------------------------------------
*/
static TabImage
GetImage(nbPtr, interp, tkwin, name)
Notebook *nbPtr;
Tcl_Interp *interp;
Tk_Window tkwin;
char *name;
{
struct TabImageStruct *imagePtr;
int isNew;
Blt_HashEntry *hPtr;
hPtr = Blt_CreateHashEntry(&(nbPtr->imageTable), name, &isNew);
if (isNew) {
Tk_Image tkImage;
int width, height;
tkImage = Tk_GetImage(interp, tkwin, name, ImageChangedProc, nbPtr);
if (tkImage == NULL) {
Blt_DeleteHashEntry(&(nbPtr->imageTable), hPtr);
return NULL;
}
Tk_SizeOfImage(tkImage, &width, &height);
imagePtr = Blt_Malloc(sizeof(struct TabImageStruct));
imagePtr->tkImage = tkImage;
imagePtr->hashPtr = hPtr;
imagePtr->refCount = 1;
imagePtr->width = width;
imagePtr->height = height;
Blt_SetHashValue(hPtr, imagePtr);
} else {
imagePtr = (struct TabImageStruct *)Blt_GetHashValue(hPtr);
imagePtr->refCount++;
}
return imagePtr;
}
/*
*----------------------------------------------------------------------
*
* FreeImage --
*
* Releases the image if it's not being used anymore by this
* widget. Note there may be several uses of the same image
* by many tabs.
*
* Results:
* None.
*
* Side Effects:
* The reference count is decremented and the image is freed
* is it's not being used anymore.
*
*----------------------------------------------------------------------
*/
static void
FreeImage(nbPtr, imagePtr)
Notebook *nbPtr;
struct TabImageStruct *imagePtr;
{
imagePtr->refCount--;
if (imagePtr->refCount == 0) {
Blt_DeleteHashEntry(&(nbPtr->imageTable), imagePtr->hashPtr);
Tk_FreeImage(imagePtr->tkImage);
Blt_Free(imagePtr);
}
}
/*
*----------------------------------------------------------------------
*
* StringToImage --
*
* Converts an image name into a Tk image token.
*
* Results:
* If the string is successfully converted, TCL_OK is returned.
* Otherwise, TCL_ERROR is returned and an error message is left
* in interpreter's result field.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
StringToImage(clientData, interp, tkwin, string, widgRec, offset)
ClientData clientData; /* Contains a pointer to the notebook containing
* this image. */
Tcl_Interp *interp; /* Interpreter to send results back to */
Tk_Window tkwin; /* Window associated with the notebook. */
char *string; /* String representation */
char *widgRec; /* Widget record */
int offset; /* Offset to field in structure */
{
Notebook *nbPtr = *(Notebook **)clientData;
TabImage *imagePtr = (TabImage *) (widgRec + offset);
TabImage image;
image = NULL;
if ((string != NULL) && (*string != '\0')) {
image = GetImage(nbPtr, interp, tkwin, string);
if (image == NULL) {
return TCL_ERROR;
}
}
if (*imagePtr != NULL) {
FreeImage(nbPtr, *imagePtr);
}
*imagePtr = image;
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* ImageToString --
*
* Converts the Tk image back to its string representation (i.e.
* its name).
*
* Results:
* The name of the image is returned.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static char *
ImageToString(clientData, tkwin, widgRec, offset, freeProcPtr)
ClientData clientData; /* Pointer to notebook containing image. */
Tk_Window tkwin; /* Not used. */
char *widgRec; /* Widget record */
int offset; /* Offset of field in record */
Tcl_FreeProc **freeProcPtr; /* Memory deallocation scheme to use */
{
Notebook *nbPtr = *(Notebook **)clientData;
TabImage *imagePtr = (TabImage *) (widgRec + offset);
if (*imagePtr == NULL) {
return "";
}
return Blt_GetHashKey(&(nbPtr->imageTable), (*imagePtr)->hashPtr);
}
/*
*----------------------------------------------------------------------
*
* StringToWindow --
*
* Converts a window name into Tk window.
*
* Results:
* If the string is successfully converted, TCL_OK is returned.
* Otherwise, TCL_ERROR is returned and an error message is left
* in interpreter's result field.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
StringToWindow(clientData, interp, parent, string, widgRec, offset)
ClientData clientData; /* Not used. */
Tcl_Interp *interp; /* Interpreter to send results back to */
Tk_Window parent; /* Parent window */
char *string; /* String representation. */
char *widgRec; /* Widget record */
int offset; /* Offset to field in structure */
{
Tab *tabPtr = (Tab *)widgRec;
Tk_Window *tkwinPtr = (Tk_Window *)(widgRec + offset);
Tk_Window old, tkwin;
Notebook *nbPtr;
old = *tkwinPtr;
tkwin = NULL;
nbPtr = tabPtr->nbPtr;
if ((string != NULL) && (*string != '\0')) {
tkwin = Tk_NameToWindow(interp, string, parent);
if (tkwin == NULL) {
return TCL_ERROR;
}
if (tkwin == old) {
return TCL_OK;
}
/*
* Allow only widgets that are children of the notebook to be
* embedded into the page. This way we can make assumptions about
* the window based upon its parent; either it's the notebook window
* or it has been torn off.
*/
parent = Tk_Parent(tkwin);
if (parent != nbPtr->tkwin) {
Tcl_AppendResult(interp, "can't manage \"", Tk_PathName(tkwin),
"\" in notebook \"", Tk_PathName(nbPtr->tkwin), "\"",
(char *)NULL);
return TCL_ERROR;
}
Tk_ManageGeometry(tkwin, &tabMgrInfo, tabPtr);
Tk_CreateEventHandler(tkwin, StructureNotifyMask,
EmbeddedWidgetEventProc, tabPtr);
/*
* We need to make the window to exist immediately. If the
* window is torn off (placed into another container window),
* the timing between the container and the its new child
* (this window) gets tricky. This should work for Tk 4.2.
*/
Tk_MakeWindowExist(tkwin);
}
if (old != NULL) {
if (tabPtr->container != NULL) {
Tcl_EventuallyFree(tabPtr, DestroyTearoff);
}
Tk_DeleteEventHandler(old, StructureNotifyMask,
EmbeddedWidgetEventProc, tabPtr);
Tk_ManageGeometry(old, (Tk_GeomMgr *) NULL, tabPtr);
Tk_UnmapWindow(old);
}
*tkwinPtr = tkwin;
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* WindowToString --
*
* Converts the Tk window back to its string representation (i.e.
* its name).
*
* Results:
* The name of the window is returned.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static char *
WindowToString(clientData, parent, widgRec, offset, freeProcPtr)
ClientData clientData; /* Not used. */
Tk_Window parent; /* Not used. */
char *widgRec; /* Widget record */
int offset; /* Offset of field in record */
Tcl_FreeProc **freeProcPtr; /* Memory deallocation scheme to use */
{
Tk_Window tkwin = *(Tk_Window *)(widgRec + offset);
if (tkwin == NULL) {
return "";
}
return Tk_PathName(tkwin);
}
/*
*----------------------------------------------------------------------
*
* StringToSide --
*
* Converts "left", "right", "top", "bottom", into a numeric token
* designating the side of the notebook which to display tabs.
*
* Results:
* If the string is successfully converted, TCL_OK is returned.
* Otherwise, TCL_ERROR is returned and an error message is left
* in interpreter's result field.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED */
static int
StringToSide(clientData, interp, parent, string, widgRec, offset)
ClientData clientData; /* Not used. */
Tcl_Interp *interp; /* Interpreter to send results back to */
Tk_Window parent; /* Parent window */
char *string; /* Option value string */
char *widgRec; /* Widget record */
int offset; /* offset to field in structure */
{
int *sidePtr = (int *)(widgRec + offset);
char c;
unsigned int length;
c = string[0];
length = strlen(string);
if ((c == 'l') && (strncmp(string, "left", length) == 0)) {
*sidePtr = SIDE_LEFT;
} else if ((c == 'r') && (strncmp(string, "right", length) == 0)) {
*sidePtr = SIDE_RIGHT;
} else if ((c == 't') && (strncmp(string, "top", length) == 0)) {
*sidePtr = SIDE_TOP;
} else if ((c == 'b') && (strncmp(string, "bottom", length) == 0)) {
*sidePtr = SIDE_BOTTOM;
} else {
Tcl_AppendResult(interp, "bad side \"", string,
"\": should be left, right, top, or bottom", (char *)NULL);
return TCL_ERROR;
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* SideToString --
*
* Converts the window into its string representation (its name).
*
* Results:
* The name of the window is returned.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static char *
SideToString(clientData, parent, widgRec, offset, freeProcPtr)
ClientData clientData; /* Not used. */
Tk_Window parent; /* Not used. */
char *widgRec; /* Widget record */
int offset; /* offset of windows array in record */
Tcl_FreeProc **freeProcPtr; /* Memory deallocation scheme to use */
{
int side = *(int *)(widgRec + offset);
switch (side) {
case SIDE_LEFT:
return "left";
case SIDE_RIGHT:
return "right";
case SIDE_BOTTOM:
return "bottom";
case SIDE_TOP:
return "top";
}
return "unknown side value";
}
/*
*----------------------------------------------------------------------
*
* StringToSlant --
*
* Converts the slant style string into its numeric representation.
*
* Valid style strings are:
*
* "none" Both sides are straight.
* "left" Left side is slanted.
* "right" Right side is slanted.
* "both" Both sides are slanted.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
StringToSlant(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; /* String representation of attribute. */
char *widgRec; /* Widget record */
int offset; /* Offset of field in widget record. */
{
int *slantPtr = (int *)(widgRec + offset);
unsigned int length;
char c;
c = string[0];
length = strlen(string);
if ((c == 'n') && (strncmp(string, "none", length) == 0)) {
*slantPtr = SLANT_NONE;
} else if ((c == 'l') && (strncmp(string, "left", length) == 0)) {
*slantPtr = SLANT_LEFT;
} else if ((c == 'r') && (strncmp(string, "right", length) == 0)) {
*slantPtr = SLANT_RIGHT;
} else if ((c == 'b') && (strncmp(string, "both", length) == 0)) {
*slantPtr = SLANT_BOTH;
} else {
Tcl_AppendResult(interp, "bad argument \"", string,
"\": should be \"none\", \"left\", \"right\", or \"both\"",
(char *)NULL);
return TCL_ERROR;
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* SlantToString --
*
* Returns the slant style string based upon the slant flags.
*
* Results:
* The slant style string is returned.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static char *
SlantToString(clientData, tkwin, widgRec, offset, freeProcPtr)
ClientData clientData; /* Not used. */
Tk_Window tkwin; /* Not used. */
char *widgRec; /* Widget structure record. */
int offset; /* Offset of field in widget record. */
Tcl_FreeProc **freeProcPtr; /* Not used. */
{
int slant = *(int *)(widgRec + offset);
switch (slant) {
case SLANT_LEFT:
return "left";
case SLANT_RIGHT:
return "right";
case SLANT_NONE:
return "none";
case SLANT_BOTH:
return "both";
default:
return "unknown value";
}
}
static int
WorldY(tabPtr)
Tab *tabPtr;
{
int tier;
tier = tabPtr->nbPtr->nTiers - tabPtr->tier;
return tier * tabPtr->nbPtr->tabHeight;
}
static int
TabIndex(nbPtr, tabPtr)
Notebook *nbPtr;
Tab *tabPtr;
{
Tab *t2Ptr;
int count;
Blt_ChainLink *linkPtr;
count = 0;
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
t2Ptr = Blt_ChainGetValue(linkPtr);
if (t2Ptr == tabPtr) {
return count;
}
count++;
}
return -1;
}
/*
* ----------------------------------------------------------------------
*
* RenumberTiers --
*
* In multi-tier mode, we need to find the start of the tier
* containing the newly selected tab.
*
* Tiers are draw from the last tier to the first, so that
* the the lower-tiered tabs will partially cover the bottoms
* of tab directly above it. This simplifies the drawing of
* tabs because we don't worry how tabs are clipped by their
* neighbors.
*
* In addition, tabs are re-marked with the correct tier number.
*
* Results:
* None.
*
* Side Effects:
* Renumbering the tab's tier will change the vertical placement
* of the tab (i.e. shift tiers).
*
* ----------------------------------------------------------------------
*/
static void
RenumberTiers(nbPtr, tabPtr)
Notebook *nbPtr;
Tab *tabPtr;
{
int tier;
Tab *prevPtr;
Blt_ChainLink *linkPtr, *lastPtr;
nbPtr->focusPtr = nbPtr->selectPtr = tabPtr;
Blt_SetFocusItem(nbPtr->bindTable, nbPtr->focusPtr, NULL);
tier = tabPtr->tier;
for (linkPtr = Blt_ChainPrevLink(tabPtr->linkPtr); linkPtr != NULL;
linkPtr = lastPtr) {
lastPtr = Blt_ChainPrevLink(linkPtr);
prevPtr = Blt_ChainGetValue(linkPtr);
if ((prevPtr == NULL) || (prevPtr->tier != tier)) {
break;
}
tabPtr = prevPtr;
}
nbPtr->startPtr = tabPtr;
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
tabPtr->tier = (tabPtr->tier - tier + 1);
if (tabPtr->tier < 1) {
tabPtr->tier += nbPtr->nTiers;
}
tabPtr->worldY = WorldY(tabPtr);
}
}
/*
*----------------------------------------------------------------------
*
* PickTab --
*
* Searches the tab located within the given screen X-Y coordinates
* in the viewport. Note that tabs overlap slightly, so that its
* important to search from the innermost tier out.
*
* Results:
* Returns the pointer to the tab. If the pointer isn't contained
* by any tab, NULL is returned.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static ClientData
PickTab(clientData, x, y, contextPtr)
ClientData clientData;
int x, y; /* Screen coordinates to test. */
ClientData *contextPtr;
{
Notebook *nbPtr = clientData;
Tab *tabPtr;
Blt_ChainLink *linkPtr;
if (contextPtr != NULL) {
*contextPtr = NULL;
}
tabPtr = nbPtr->selectPtr;
if ((nbPtr->tearoff) && (tabPtr != NULL) &&
(tabPtr->container == NULL) && (tabPtr->tkwin != NULL)) {
int top, bottom, left, right;
int sx, sy;
/* Check first for perforation on the selected tab. */
WorldToScreen(nbPtr, tabPtr->worldX + 2,
tabPtr->worldY + tabPtr->worldHeight + 4, &sx, &sy);
if (nbPtr->side & SIDE_HORIZONTAL) {
left = sx - 2;
right = left + tabPtr->screenWidth;
top = sy - 4;
bottom = sy + 4;
} else {
left = sx - 4;
right = sx + 4;
top = sy - 2;
bottom = top + tabPtr->screenHeight;
}
if ((x >= left) && (y >= top) && (x < right) && (y < bottom)) {
if (contextPtr != NULL) {
*contextPtr = TAB_PERFORATION;
}
return nbPtr->selectPtr;
}
}
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
if (!(tabPtr->flags & TAB_VISIBLE)) {
continue;
}
if ((x >= tabPtr->screenX) && (y >= tabPtr->screenY) &&
(x <= (tabPtr->screenX + tabPtr->screenWidth)) &&
(y < (tabPtr->screenY + tabPtr->screenHeight))) {
if (contextPtr != NULL) {
*contextPtr = TAB_LABEL;
}
return tabPtr;
}
}
return NULL;
}
static Tab *
TabLeft(tabPtr)
Tab *tabPtr;
{
Blt_ChainLink *linkPtr;
linkPtr = Blt_ChainPrevLink(tabPtr->linkPtr);
if (linkPtr != NULL) {
Tab *newPtr;
newPtr = Blt_ChainGetValue(linkPtr);
/* Move only if the next tab is on another tier. */
if (newPtr->tier == tabPtr->tier) {
tabPtr = newPtr;
}
}
return tabPtr;
}
static Tab *
TabRight(tabPtr)
Tab *tabPtr;
{
Blt_ChainLink *linkPtr;
linkPtr = Blt_ChainNextLink(tabPtr->linkPtr);
if (linkPtr != NULL) {
Tab *newPtr;
newPtr = Blt_ChainGetValue(linkPtr);
/* Move only if the next tab is on another tier. */
if (newPtr->tier == tabPtr->tier) {
tabPtr = newPtr;
}
}
return tabPtr;
}
static Tab *
TabUp(tabPtr)
Tab *tabPtr;
{
if (tabPtr != NULL) {
Notebook *nbPtr;
int x, y;
int worldX, worldY;
nbPtr = tabPtr->nbPtr;
worldX = tabPtr->worldX + (tabPtr->worldWidth / 2);
worldY = tabPtr->worldY - (nbPtr->tabHeight / 2);
WorldToScreen(nbPtr, worldX, worldY, &x, &y);
tabPtr = (Tab *)PickTab(nbPtr, x, y, NULL);
if (tabPtr == NULL) {
/*
* We might have inadvertly picked the gap between two tabs,
* so if the first pick fails, try again a little to the left.
*/
WorldToScreen(nbPtr, worldX + nbPtr->gap, worldY, &x, &y);
tabPtr = (Tab *)PickTab(nbPtr, x, y, NULL);
}
if ((tabPtr == NULL) &&
(nbPtr->focusPtr->tier < (nbPtr->nTiers - 1))) {
worldY -= nbPtr->tabHeight;
WorldToScreen(nbPtr, worldX, worldY, &x, &y);
tabPtr = (Tab *)PickTab(nbPtr, x, y, NULL);
}
if (tabPtr == NULL) {
tabPtr = nbPtr->focusPtr;
}
}
return tabPtr;
}
static Tab *
TabDown(tabPtr)
Tab *tabPtr;
{
if (tabPtr != NULL) {
Notebook *nbPtr;
int x, y;
int worldX, worldY;
nbPtr = tabPtr->nbPtr;
worldX = tabPtr->worldX + (tabPtr->worldWidth / 2);
worldY = tabPtr->worldY + (3 * nbPtr->tabHeight) / 2;
WorldToScreen(nbPtr, worldX, worldY, &x, &y);
tabPtr = (Tab *)PickTab(nbPtr, x, y, NULL);
if (tabPtr == NULL) {
/*
* We might have inadvertly picked the gap between two tabs,
* so if the first pick fails, try again a little to the left.
*/
WorldToScreen(nbPtr, worldX - nbPtr->gap, worldY, &x, &y);
tabPtr = (Tab *)PickTab(nbPtr, x, y, NULL);
}
if ((tabPtr == NULL) && (nbPtr->focusPtr->tier > 2)) {
worldY += nbPtr->tabHeight;
WorldToScreen(nbPtr, worldX, worldY, &x, &y);
tabPtr = (Tab *)PickTab(nbPtr, x, y, NULL);
}
if (tabPtr == NULL) {
tabPtr = nbPtr->focusPtr;
}
}
return tabPtr;
}
/*
*----------------------------------------------------------------------
*
* GetTab --
*
* Converts a string representing a tab index into a tab pointer.
* The index may be in one of the following forms:
*
* number Tab at position in the list of tabs.
* @x,y Tab closest to the specified X-Y screen coordinates.
* "active" Tab mouse is located over.
* "focus" Tab is the widget's focus.
* "select" Currently selected tab.
* "right" Next tab from the focus tab.
* "left" Previous tab from the focus tab.
* "up" Next tab from the focus tab.
* "down" Previous tab from the focus tab.
* "end" Last tab in list.
*
* Results:
* If the string is successfully converted, TCL_OK is returned.
* The pointer to the node is returned via tabPtrPtr.
* Otherwise, TCL_ERROR is returned and an error message is left
* in interpreter's result field.
*
*----------------------------------------------------------------------
*/
static int
GetTab(nbPtr, string, tabPtrPtr, allowNull)
Notebook *nbPtr;
char *string;
Tab **tabPtrPtr;
int allowNull; /* Allow NULL tabPtr */
{
Tab *tabPtr;
Blt_ChainLink *linkPtr;
int position;
char c;
c = string[0];
tabPtr = NULL;
if (nbPtr->focusPtr == NULL) {
nbPtr->focusPtr = nbPtr->selectPtr;
Blt_SetFocusItem(nbPtr->bindTable, nbPtr->focusPtr, NULL);
}
if ((isdigit(UCHAR(c))) &&
(Tcl_GetInt(nbPtr->interp, string, &position) == TCL_OK)) {
linkPtr = Blt_ChainGetNthLink(nbPtr->chainPtr, position);
if (linkPtr == NULL) {
Tcl_AppendResult(nbPtr->interp, "can't find tab \"", string,
"\" in \"", Tk_PathName(nbPtr->tkwin),
"\": no such index", (char *)NULL);
return TCL_ERROR;
}
tabPtr = Blt_ChainGetValue(linkPtr);
} else if ((c == 'a') && (strcmp(string, "active") == 0)) {
tabPtr = nbPtr->activePtr;
} else if ((c == 'c') && (strcmp(string, "current") == 0)) {
tabPtr = (Tab *)Blt_GetCurrentItem(nbPtr->bindTable);
} else if ((c == 's') && (strcmp(string, "select") == 0)) {
tabPtr = nbPtr->selectPtr;
} else if ((c == 'f') && (strcmp(string, "focus") == 0)) {
tabPtr = nbPtr->focusPtr;
} else if ((c == 'u') && (strcmp(string, "up") == 0)) {
switch (nbPtr->side) {
case SIDE_LEFT:
case SIDE_RIGHT:
tabPtr = TabLeft(nbPtr->focusPtr);
break;
case SIDE_BOTTOM:
tabPtr = TabDown(nbPtr->focusPtr);
break;
case SIDE_TOP:
tabPtr = TabUp(nbPtr->focusPtr);
break;
}
} else if ((c == 'd') && (strcmp(string, "down") == 0)) {
switch (nbPtr->side) {
case SIDE_LEFT:
case SIDE_RIGHT:
tabPtr = TabRight(nbPtr->focusPtr);
break;
case SIDE_BOTTOM:
tabPtr = TabUp(nbPtr->focusPtr);
break;
case SIDE_TOP:
tabPtr = TabDown(nbPtr->focusPtr);
break;
}
} else if ((c == 'l') && (strcmp(string, "left") == 0)) {
switch (nbPtr->side) {
case SIDE_LEFT:
tabPtr = TabUp(nbPtr->focusPtr);
break;
case SIDE_RIGHT:
tabPtr = TabDown(nbPtr->focusPtr);
break;
case SIDE_BOTTOM:
case SIDE_TOP:
tabPtr = TabLeft(nbPtr->focusPtr);
break;
}
} else if ((c == 'r') && (strcmp(string, "right") == 0)) {
switch (nbPtr->side) {
case SIDE_LEFT:
tabPtr = TabDown(nbPtr->focusPtr);
break;
case SIDE_RIGHT:
tabPtr = TabUp(nbPtr->focusPtr);
break;
case SIDE_BOTTOM:
case SIDE_TOP:
tabPtr = TabRight(nbPtr->focusPtr);
break;
}
} else if ((c == 'e') && (strcmp(string, "end") == 0)) {
linkPtr = Blt_ChainLastLink(nbPtr->chainPtr);
if (linkPtr != NULL) {
tabPtr = Blt_ChainGetValue(linkPtr);
}
} else if (c == '@') {
int x, y;
if (Blt_GetXY(nbPtr->interp, nbPtr->tkwin, string, &x, &y)
!= TCL_OK) {
return TCL_ERROR;
}
tabPtr = (Tab *)PickTab(nbPtr, x, y, NULL);
} else {
Blt_HashEntry *hPtr;
hPtr = Blt_FindHashEntry(&(nbPtr->tabTable), string);
if (hPtr != NULL) {
tabPtr = (Tab *)Blt_GetHashValue(hPtr);
}
}
*tabPtrPtr = tabPtr;
Tcl_ResetResult(nbPtr->interp);
if ((!allowNull) && (tabPtr == NULL)) {
Tcl_AppendResult(nbPtr->interp, "can't find tab \"", string,
"\" in \"", Tk_PathName(nbPtr->tkwin), "\"", (char *)NULL);
return TCL_ERROR;
}
return TCL_OK;
}
static Tab *
NextOrLastTab(tabPtr)
Tab *tabPtr;
{
if (tabPtr->linkPtr != NULL) {
Blt_ChainLink *linkPtr;
linkPtr = Blt_ChainNextLink(tabPtr->linkPtr);
if (linkPtr == NULL) {
linkPtr = Blt_ChainPrevLink(tabPtr->linkPtr);
}
if (linkPtr != NULL) {
return Blt_ChainGetValue(linkPtr);
}
}
return NULL;
}
/*
* --------------------------------------------------------------
*
* EmbeddedWidgetEventProc --
*
* This procedure is invoked by the Tk dispatcher for various
* events on embedded widgets contained in the notebook.
*
* Results:
* None.
*
* Side effects:
* When an embedded widget gets deleted, internal structures get
* cleaned up. When it gets resized, the notebook is redisplayed.
*
* --------------------------------------------------------------
*/
static void
EmbeddedWidgetEventProc(clientData, eventPtr)
ClientData clientData; /* Information about the tab window. */
XEvent *eventPtr; /* Information about event. */
{
Tab *tabPtr = clientData;
if ((tabPtr == NULL) || (tabPtr->tkwin == NULL)) {
return;
}
switch (eventPtr->type) {
case ConfigureNotify:
/*
* If the window's requested size changes, redraw the window.
* But only if it's currently the selected page.
*/
if ((tabPtr->container == NULL) && (Tk_IsMapped(tabPtr->tkwin)) &&
(tabPtr->nbPtr->selectPtr == tabPtr)) {
EventuallyRedraw(tabPtr->nbPtr);
}
break;
case DestroyNotify:
/*
* Mark the tab as deleted by dereferencing the Tk window
* pointer. Redraw the window only if the tab is currently
* visible.
*/
if ((Tk_IsMapped(tabPtr->tkwin)) &&
(tabPtr->nbPtr->selectPtr == tabPtr)) {
EventuallyRedraw(tabPtr->nbPtr);
}
Tk_DeleteEventHandler(tabPtr->tkwin, StructureNotifyMask,
EmbeddedWidgetEventProc, tabPtr);
tabPtr->tkwin = NULL;
break;
}
}
/*
* ----------------------------------------------------------------------
*
* EmbeddedWidgetCustodyProc --
*
* This procedure is invoked when a tab window has been
* stolen by another geometry manager. The information and
* memory associated with the tab window is released.
*
* Results:
* None.
*
* Side effects:
* Arranges for the widget formerly associated with the tab
* window to have its layout re-computed and arranged at the
* next idle point.
*
* ---------------------------------------------------------------------
*/
/* ARGSUSED */
static void
EmbeddedWidgetCustodyProc(clientData, tkwin)
ClientData clientData; /* Information about the former tab window. */
Tk_Window tkwin; /* Not used. */
{
Tab *tabPtr = clientData;
Notebook *nbPtr;
if ((tabPtr == NULL) || (tabPtr->tkwin == NULL)) {
return;
}
nbPtr = tabPtr->nbPtr;
if (tabPtr->container != NULL) {
Tcl_EventuallyFree(tabPtr, DestroyTearoff);
}
/*
* Mark the tab as deleted by dereferencing the Tk window
* pointer. Redraw the window only if the tab is currently
* visible.
*/
if (tabPtr->tkwin != NULL) {
if (Tk_IsMapped(tabPtr->tkwin) && (nbPtr->selectPtr == tabPtr)) {
nbPtr->flags |= (TNB_LAYOUT | TNB_SCROLL);
EventuallyRedraw(nbPtr);
}
Tk_DeleteEventHandler(tabPtr->tkwin, StructureNotifyMask,
EmbeddedWidgetEventProc, tabPtr);
tabPtr->tkwin = NULL;
}
}
/*
* -------------------------------------------------------------------------
*
* EmbeddedWidgetGeometryProc --
*
* This procedure is invoked by Tk_GeometryRequest for tab
* windows managed by the widget.
*
* Results:
* None.
*
* Side effects:
* Arranges for tkwin, and all its managed siblings, to be
* repacked and drawn at the next idle point.
*
* ------------------------------------------------------------------------
*/
/* ARGSUSED */
static void
EmbeddedWidgetGeometryProc(clientData, tkwin)
ClientData clientData; /* Information about window that got new
* preferred geometry. */
Tk_Window tkwin; /* Other Tk-related information about the
* window. */
{
Tab *tabPtr = clientData;
if ((tabPtr == NULL) || (tabPtr->tkwin == NULL)) {
fprintf(stderr, "%s: line %d \"tkwin is null\"", __FILE__, __LINE__);
return;
}
tabPtr->nbPtr->flags |= (TNB_LAYOUT | TNB_SCROLL);
EventuallyRedraw(tabPtr->nbPtr);
}
/*
* ----------------------------------------------------------------------
*
* DestroyTab --
*
* ----------------------------------------------------------------------
*/
static void
DestroyTab(nbPtr, tabPtr)
Notebook *nbPtr;
Tab *tabPtr;
{
Blt_HashEntry *hPtr;
if (tabPtr->flags & TAB_REDRAW) {
Tcl_CancelIdleCall(DisplayTearoff, tabPtr);
}
if (tabPtr->container != NULL) {
Tk_DestroyWindow(tabPtr->container);
}
if (tabPtr->tkwin != NULL) {
Tk_ManageGeometry(tabPtr->tkwin, (Tk_GeomMgr *)NULL, tabPtr);
Tk_DeleteEventHandler(tabPtr->tkwin, StructureNotifyMask,
EmbeddedWidgetEventProc, tabPtr);
if (Tk_IsMapped(tabPtr->tkwin)) {
Tk_UnmapWindow(tabPtr->tkwin);
}
}
if (tabPtr == nbPtr->activePtr) {
nbPtr->activePtr = NULL;
}
if (tabPtr == nbPtr->selectPtr) {
nbPtr->selectPtr = NextOrLastTab(tabPtr);
}
if (tabPtr == nbPtr->focusPtr) {
nbPtr->focusPtr = nbPtr->selectPtr;
Blt_SetFocusItem(nbPtr->bindTable, nbPtr->focusPtr, NULL);
}
if (tabPtr == nbPtr->startPtr) {
nbPtr->startPtr = NULL;
}
Tk_FreeOptions(tabConfigSpecs, (char *)tabPtr, nbPtr->display, 0);
if (tabPtr->text != NULL) {
Blt_FreeUid(tabPtr->text);
}
hPtr = Blt_FindHashEntry(&(nbPtr->tabTable), tabPtr->name);
assert(hPtr);
Blt_DeleteHashEntry(&(nbPtr->tabTable), hPtr);
if (tabPtr->image != NULL) {
FreeImage(nbPtr, tabPtr->image);
}
if (tabPtr->name != NULL) {
Blt_Free(tabPtr->name);
}
if (tabPtr->textGC != NULL) {
Tk_FreeGC(nbPtr->display, tabPtr->textGC);
}
if (tabPtr->backGC != NULL) {
Tk_FreeGC(nbPtr->display, tabPtr->backGC);
}
if (tabPtr->command != NULL) {
Blt_FreeUid(tabPtr->command);
}
if (tabPtr->linkPtr != NULL) {
Blt_ChainDeleteLink(nbPtr->chainPtr, tabPtr->linkPtr);
}
if (tabPtr->tags != NULL) {
Blt_FreeUid(tabPtr->tags);
}
Blt_DeleteBindings(nbPtr->bindTable, tabPtr);
Blt_Free(tabPtr);
}
/*
* ----------------------------------------------------------------------
*
* CreateTab --
*
* Creates a new tab structure. A tab contains information about
* the state of the tab and its embedded window.
*
* Results:
* Returns a pointer to the new tab structure.
*
* ----------------------------------------------------------------------
*/
static Tab *
CreateTab(nbPtr)
Notebook *nbPtr;
{
Tab *tabPtr;
Blt_HashEntry *hPtr;
int isNew;
char string[200];
tabPtr = Blt_Calloc(1, sizeof(Tab));
assert(tabPtr);
tabPtr->nbPtr = nbPtr;
sprintf(string, "tab%d", nbPtr->nextId++);
tabPtr->name = Blt_Strdup(string);
tabPtr->text = Blt_GetUid(string);
tabPtr->fill = FILL_NONE;
tabPtr->anchor = TK_ANCHOR_CENTER;
tabPtr->container = NULL;
tabPtr->state = STATE_NORMAL;
hPtr = Blt_CreateHashEntry(&(nbPtr->tabTable), string, &isNew);
Blt_SetHashValue(hPtr, tabPtr);
return tabPtr;
}
/*
*----------------------------------------------------------------------
*
* TileChangedProc
*
* Stub for image change notifications. Since we immediately draw
* the image into a pixmap, we don't really care about image changes.
*
* It would be better if Tk checked for NULL proc pointers.
*
* Results:
* None.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static void
TileChangedProc(clientData, tile)
ClientData clientData;
Blt_Tile tile; /* Not used. */
{
Notebook *nbPtr = clientData;
if (nbPtr->tkwin != NULL) {
EventuallyRedraw(nbPtr);
}
}
static int
ConfigureTab(nbPtr, tabPtr)
Notebook *nbPtr;
Tab *tabPtr;
{
GC newGC;
XGCValues gcValues;
unsigned long gcMask;
int labelWidth, labelHeight;
Tk_Font font;
Tk_3DBorder border;
font = GETATTR(tabPtr, font);
labelWidth = labelHeight = 0;
if (tabPtr->text != NULL) {
TextStyle ts;
double rotWidth, rotHeight;
Blt_InitTextStyle(&ts);
ts.font = font;
ts.shadow.offset = tabPtr->shadow.offset;
ts.padX.side1 = ts.padX.side2 = 2;
Blt_GetTextExtents(&ts, tabPtr->text, &labelWidth, &labelHeight);
Blt_GetBoundingBox(labelWidth, labelHeight, nbPtr->defTabStyle.rotate,
&rotWidth, &rotHeight, (Point2D *)NULL);
labelWidth = ROUND(rotWidth);
labelHeight = ROUND(rotHeight);
}
tabPtr->textWidth = (short int)labelWidth;
tabPtr->textHeight = (short int)labelHeight;
if (tabPtr->image != NULL) {
int width, height;
width = ImageWidth(tabPtr->image) + 2 * IMAGE_PAD;
height = ImageHeight(tabPtr->image) + 2 * IMAGE_PAD;
if (nbPtr->defTabStyle.textSide & SIDE_VERTICAL) {
labelWidth += width;
labelHeight = MAX(labelHeight, height);
} else {
labelHeight += height;
labelWidth = MAX(labelWidth, width);
}
}
labelWidth += PADDING(tabPtr->iPadX);
labelHeight += PADDING(tabPtr->iPadY);
tabPtr->labelWidth = ODD(labelWidth);
tabPtr->labelHeight = ODD(labelHeight);
newGC = NULL;
if (tabPtr->text != NULL) {
XColor *colorPtr;
gcMask = GCForeground | GCFont;
colorPtr = GETATTR(tabPtr, textColor);
gcValues.foreground = colorPtr->pixel;
gcValues.font = Tk_FontId(font);
newGC = Tk_GetGC(nbPtr->tkwin, gcMask, &gcValues);
}
if (tabPtr->textGC != NULL) {
Tk_FreeGC(nbPtr->display, tabPtr->textGC);
}
tabPtr->textGC = newGC;
gcMask = GCForeground | GCStipple | GCFillStyle;
gcValues.fill_style = FillStippled;
border = GETATTR(tabPtr, border);
gcValues.foreground = Tk_3DBorderColor(border)->pixel;
gcValues.stipple = tabPtr->stipple;
newGC = Tk_GetGC(nbPtr->tkwin, gcMask, &gcValues);
if (tabPtr->backGC != NULL) {
Tk_FreeGC(nbPtr->display, tabPtr->backGC);
}
tabPtr->backGC = newGC;
/*
* GC for tiled background.
*/
if (tabPtr->tile != NULL) {
Blt_SetTileChangedProc(tabPtr->tile, TileChangedProc, nbPtr);
}
if (tabPtr->flags & TAB_VISIBLE) {
EventuallyRedraw(nbPtr);
}
return TCL_OK;
}
/*
* --------------------------------------------------------------
*
* TearoffEventProc --
*
* This procedure is invoked by the Tk dispatcher for various
* events on the tearoff widget.
*
* Results:
* None.
*
* Side effects:
* When the tearoff gets deleted, internal structures get
* cleaned up. When it gets resized or exposed, it's redisplayed.
*
* --------------------------------------------------------------
*/
static void
TearoffEventProc(clientData, eventPtr)
ClientData clientData; /* Information about the tab window. */
XEvent *eventPtr; /* Information about event. */
{
Tab *tabPtr = clientData;
if ((tabPtr == NULL) || (tabPtr->tkwin == NULL) ||
(tabPtr->container == NULL)) {
return;
}
switch (eventPtr->type) {
case Expose:
if (eventPtr->xexpose.count == 0) {
EventuallyRedrawTearoff(tabPtr);
}
break;
case ConfigureNotify:
EventuallyRedrawTearoff(tabPtr);
break;
case DestroyNotify:
if (tabPtr->flags & TAB_REDRAW) {
tabPtr->flags &= ~TAB_REDRAW;
Tcl_CancelIdleCall(DisplayTearoff, clientData);
}
Tk_DestroyWindow(tabPtr->container);
tabPtr->container = NULL;
break;
}
}
/*
* ----------------------------------------------------------------------------
*
* GetReqWidth --
*
* Returns the width requested by the embedded tab window and
* any requested padding around it. This represents the requested
* width of the page.
*
* Results:
* Returns the requested width of the page.
*
* ----------------------------------------------------------------------------
*/
static int
GetReqWidth(tabPtr)
Tab *tabPtr;
{
int width;
if (tabPtr->reqWidth > 0) {
width = tabPtr->reqWidth;
} else {
width = Tk_ReqWidth(tabPtr->tkwin);
}
width += PADDING(tabPtr->padX) +
2 * Tk_Changes(tabPtr->tkwin)->border_width;
if (width < 1) {
width = 1;
}
return width;
}
/*
* ----------------------------------------------------------------------------
*
* GetReqHeight --
*
* Returns the height requested by the window and padding around
* the window. This represents the requested height of the page.
*
* Results:
* Returns the requested height of the page.
*
* ----------------------------------------------------------------------------
*/
static int
GetReqHeight(tabPtr)
Tab *tabPtr;
{
int height;
if (tabPtr->reqHeight > 0) {
height = tabPtr->reqHeight;
} else {
height = Tk_ReqHeight(tabPtr->tkwin);
}
height += PADDING(tabPtr->padY) +
2 * Tk_Changes(tabPtr->tkwin)->border_width;
if (height < 1) {
height = 1;
}
return height;
}
/*
* ----------------------------------------------------------------------------
*
* 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;
}
static void
GetWindowRectangle(tabPtr, parent, tearoff, rectPtr)
Tab *tabPtr;
Tk_Window parent;
int tearoff;
XRectangle *rectPtr;
{
int pad;
Notebook *nbPtr;
int cavityWidth, cavityHeight;
int width, height;
int dx, dy;
int x = 0, y = 0;
nbPtr = tabPtr->nbPtr;
pad = nbPtr->inset + nbPtr->inset2;
if (!tearoff) {
switch (nbPtr->side) {
case SIDE_RIGHT:
case SIDE_BOTTOM:
x = nbPtr->inset + nbPtr->inset2;
y = nbPtr->inset + nbPtr->inset2;
break;
case SIDE_LEFT:
x = nbPtr->pageTop;
y = nbPtr->inset + nbPtr->inset2;
break;
case SIDE_TOP:
x = nbPtr->inset + nbPtr->inset2;
y = nbPtr->pageTop;
break;
}
if (nbPtr->side & SIDE_VERTICAL) {
cavityWidth = Tk_Width(nbPtr->tkwin) - (nbPtr->pageTop + pad);
cavityHeight = Tk_Height(nbPtr->tkwin) - (2 * pad);
} else {
cavityWidth = Tk_Width(nbPtr->tkwin) - (2 * pad);
cavityHeight = Tk_Height(nbPtr->tkwin) - (nbPtr->pageTop + pad);
}
} else {
x = nbPtr->inset + nbPtr->inset2;
#define TEAR_OFF_TAB_SIZE 5
y = nbPtr->inset + nbPtr->inset2 + nbPtr->yPad + nbPtr->outerPad +
TEAR_OFF_TAB_SIZE;
cavityWidth = Tk_Width(parent) - (2 * pad);
cavityHeight = Tk_Height(parent) - (y + pad);
}
cavityWidth -= PADDING(tabPtr->padX);
cavityHeight -= PADDING(tabPtr->padY);
if (cavityWidth < 1) {
cavityWidth = 1;
}
if (cavityHeight < 1) {
cavityHeight = 1;
}
width = GetReqWidth(tabPtr);
height = GetReqHeight(tabPtr);
/*
* Resize the embedded window is of the following is true:
*
* 1) It's been torn off.
* 2) The -fill option (horizontal or vertical) is set.
* 3) the window is bigger than the cavity.
*/
if ((tearoff) || (cavityWidth < width) || (tabPtr->fill & FILL_X)) {
width = cavityWidth;
}
if ((tearoff) || (cavityHeight < height) || (tabPtr->fill & FILL_Y)) {
height = cavityHeight;
}
dx = (cavityWidth - width);
dy = (cavityHeight - height);
if ((dx > 0) || (dy > 0)) {
TranslateAnchor(dx, dy, tabPtr->anchor, &x, &y);
}
/* Remember that X11 windows must be at least 1 pixel. */
if (width < 1) {
width = 1;
}
if (height < 1) {
height = 1;
}
rectPtr->x = (short)(x + tabPtr->padLeft);
rectPtr->y = (short)(y + tabPtr->padTop);
rectPtr->width = (short)width;
rectPtr->height = (short)height;
}
static void
ArrangeWindow(tkwin, rectPtr, force)
Tk_Window tkwin;
XRectangle *rectPtr;
int force;
{
if ((force) ||
(rectPtr->x != Tk_X(tkwin)) ||
(rectPtr->y != Tk_Y(tkwin)) ||
(rectPtr->width != Tk_Width(tkwin)) ||
(rectPtr->height != Tk_Height(tkwin))) {
Tk_MoveResizeWindow(tkwin, rectPtr->x, rectPtr->y,
rectPtr->width, rectPtr->height);
}
if (!Tk_IsMapped(tkwin)) {
Tk_MapWindow(tkwin);
}
}
/*ARGSUSED*/
static void
GetTags(table, object, context, list)
Blt_BindTable table;
ClientData object;
ClientData context;
Blt_List list;
{
Tab *tabPtr = (Tab *)object;
Notebook *nbPtr;
nbPtr = (Notebook *)table->clientData;
if (context == TAB_PERFORATION) {
Blt_ListAppend(list, MakeTag(nbPtr, "Perforation"), 0);
} else if (context == TAB_LABEL) {
Blt_ListAppend(list, MakeTag(nbPtr, tabPtr->name), 0);
if (tabPtr->tags != NULL) {
int nNames;
char **names;
register char **p;
/*
* This is a space/time trade-off in favor of space. The tags
* are stored as character strings in a hash table. That way,
* tabs can share the strings. It's likely that they will. The
* down side is that the same string is split over and over again.
*/
if (Tcl_SplitList((Tcl_Interp *)NULL, tabPtr->tags, &nNames,
&names) == TCL_OK) {
for (p = names; *p != NULL; p++) {
Blt_ListAppend(list, MakeTag(nbPtr, *p), 0);
}
Blt_Free(names);
}
}
}
}
/*
* --------------------------------------------------------------
*
* NotebookEventProc --
*
* This procedure is invoked by the Tk dispatcher for various
* events on notebook widgets.
*
* Results:
* None.
*
* Side Effects:
* When the window gets deleted, internal structures get
* cleaned up. When it gets exposed, it is redisplayed.
*
* --------------------------------------------------------------
*/
static void
NotebookEventProc(clientData, eventPtr)
ClientData clientData; /* Information about window. */
XEvent *eventPtr; /* Information about event. */
{
Notebook *nbPtr = clientData;
switch (eventPtr->type) {
case Expose:
if (eventPtr->xexpose.count == 0) {
EventuallyRedraw(nbPtr);
}
break;
case ConfigureNotify:
nbPtr->flags |= (TNB_LAYOUT | TNB_SCROLL);
EventuallyRedraw(nbPtr);
break;
case FocusIn:
case FocusOut:
if (eventPtr->xfocus.detail != NotifyInferior) {
if (eventPtr->type == FocusIn) {
nbPtr->flags |= TNB_FOCUS;
} else {
nbPtr->flags &= ~TNB_FOCUS;
}
EventuallyRedraw(nbPtr);
}
break;
case DestroyNotify:
if (nbPtr->tkwin != NULL) {
nbPtr->tkwin = NULL;
Tcl_DeleteCommandFromToken(nbPtr->interp, nbPtr->cmdToken);
}
if (nbPtr->flags & TNB_REDRAW) {
Tcl_CancelIdleCall(DisplayNotebook, nbPtr);
}
Tcl_EventuallyFree(nbPtr, DestroyNotebook);
break;
}
}
/*
* ----------------------------------------------------------------------
*
* DestroyNotebook --
*
* This procedure is invoked by Tcl_EventuallyFree or Tcl_Release
* to clean up the internal structure of the widget at a safe
* time (when no-one is using it anymore).
*
* Results:
* None.
*
* Side Effects:
* Everything associated with the widget is freed up.
*
* ----------------------------------------------------------------------
*/
static void
DestroyNotebook(dataPtr)
DestroyData dataPtr; /* Pointer to the widget record. */
{
Notebook *nbPtr = (Notebook *)dataPtr;
Tab *tabPtr;
Blt_ChainLink *linkPtr;
if (nbPtr->highlightGC != NULL) {
Tk_FreeGC(nbPtr->display, nbPtr->highlightGC);
}
if (nbPtr->tile != NULL) {
Blt_FreeTile(nbPtr->tile);
}
if (nbPtr->defTabStyle.activeGC != NULL) {
Blt_FreePrivateGC(nbPtr->display, nbPtr->defTabStyle.activeGC);
}
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
tabPtr->linkPtr = NULL;
DestroyTab(nbPtr, tabPtr);
}
Blt_ChainDestroy(nbPtr->chainPtr);
Blt_DestroyBindingTable(nbPtr->bindTable);
Blt_DeleteHashTable(&(nbPtr->tabTable));
Blt_DeleteHashTable(&(nbPtr->tagTable));
Tk_FreeOptions(configSpecs, (char *)nbPtr, nbPtr->display, 0);
Blt_Free(nbPtr);
}
/*
* ----------------------------------------------------------------------
*
* CreateNotebook --
*
* ----------------------------------------------------------------------
*/
static Notebook *
CreateNotebook(interp, tkwin)
Tcl_Interp *interp;
Tk_Window tkwin;
{
Notebook *nbPtr;
nbPtr = Blt_Calloc(1, sizeof(Notebook));
assert(nbPtr);
Tk_SetClass(tkwin, "Tabnotebook");
nbPtr->tkwin = tkwin;
nbPtr->display = Tk_Display(tkwin);
nbPtr->interp = interp;
nbPtr->flags |= (TNB_LAYOUT | TNB_SCROLL);
nbPtr->side = SIDE_TOP;
nbPtr->borderWidth = nbPtr->highlightWidth = 2;
nbPtr->ySelectPad = SELECT_PADY;
nbPtr->xSelectPad = SELECT_PADX;
nbPtr->relief = TK_RELIEF_SUNKEN;
nbPtr->defTabStyle.relief = TK_RELIEF_RAISED;
nbPtr->defTabStyle.borderWidth = 1;
nbPtr->defTabStyle.constWidth = TRUE;
nbPtr->defTabStyle.textSide = SIDE_LEFT;
nbPtr->scrollUnits = 2;
nbPtr->corner = CORNER_OFFSET;
nbPtr->gap = GAP;
nbPtr->outerPad = OUTER_PAD;
nbPtr->slant = SLANT_NONE;
nbPtr->overlap = 0;
nbPtr->tearoff = TRUE;
nbPtr->bindTable = Blt_CreateBindingTable(interp, tkwin, nbPtr, PickTab,
GetTags);
nbPtr->chainPtr = Blt_ChainCreate();
Blt_InitHashTable(&(nbPtr->tabTable), BLT_STRING_KEYS);
Blt_InitHashTable(&(nbPtr->imageTable), BLT_STRING_KEYS);
Blt_InitHashTable(&(nbPtr->tagTable), BLT_STRING_KEYS);
#if (TK_MAJOR_VERSION > 4)
Blt_SetWindowInstanceData(tkwin, nbPtr);
#endif
return nbPtr;
}
/*
* ----------------------------------------------------------------------
*
* ConfigureNotebook --
*
* This procedure is called to process an argv/argc list, plus
* the Tk option database, in order to configure (or reconfigure)
* the widget.
*
* Results:
* The return value is a standard Tcl result. If TCL_ERROR is
* returned, then interp->result contains an error message.
*
* Side Effects:
* Configuration information, such as text string, colors, font,
* etc. get set for nbPtr; old resources get freed, if there
* were any. The widget is redisplayed.
*
* ----------------------------------------------------------------------
*/
static int
ConfigureNotebook(interp, nbPtr, argc, argv, flags)
Tcl_Interp *interp; /* Interpreter to report errors. */
Notebook *nbPtr; /* Information about widget; may or
* may not already have values for
* some fields. */
int argc;
CONST char **argv;
int flags;
{
XGCValues gcValues;
unsigned long gcMask;
GC newGC;
lastNotebookInstance = nbPtr;
if (Blt_ConfigureWidget(interp, nbPtr->tkwin, configSpecs, argc, argv,
(char *)nbPtr, flags) != TCL_OK) {
return TCL_ERROR;
}
if (Blt_ConfigModified(configSpecs, interp, "-width", "-height", "-side", "-gap",
"-slant", (char *)NULL)) {
nbPtr->flags |= (TNB_LAYOUT | TNB_SCROLL);
}
if ((nbPtr->reqHeight > 0) && (nbPtr->reqWidth > 0)) {
Tk_GeometryRequest(nbPtr->tkwin, nbPtr->reqWidth,
nbPtr->reqHeight);
}
/*
* GC for focus highlight.
*/
gcMask = GCForeground;
gcValues.foreground = nbPtr->highlightColor->pixel;
newGC = Tk_GetGC(nbPtr->tkwin, gcMask, &gcValues);
if (nbPtr->highlightGC != NULL) {
Tk_FreeGC(nbPtr->display, nbPtr->highlightGC);
}
nbPtr->highlightGC = newGC;
/*
* GC for tiled background.
*/
if (nbPtr->tile != NULL) {
Blt_SetTileChangedProc(nbPtr->tile, TileChangedProc, nbPtr);
}
/*
* GC for active line.
*/
gcMask = GCForeground | GCLineWidth | GCLineStyle | GCCapStyle;
gcValues.foreground = nbPtr->defTabStyle.activeFgColor->pixel;
gcValues.line_width = 0;
gcValues.cap_style = CapProjecting;
gcValues.line_style = (LineIsDashed(nbPtr->defTabStyle.dashes))
? LineOnOffDash : LineSolid;
newGC = Blt_GetPrivateGC(nbPtr->tkwin, gcMask, &gcValues);
if (LineIsDashed(nbPtr->defTabStyle.dashes)) {
nbPtr->defTabStyle.dashes.offset = 2;
Blt_SetDashes(nbPtr->display, newGC, &(nbPtr->defTabStyle.dashes));
}
if (nbPtr->defTabStyle.activeGC != NULL) {
Blt_FreePrivateGC(nbPtr->display,
nbPtr->defTabStyle.activeGC);
}
nbPtr->defTabStyle.activeGC = newGC;
nbPtr->defTabStyle.rotate = FMOD(nbPtr->defTabStyle.rotate, 360.0);
if (nbPtr->defTabStyle.rotate < 0.0) {
nbPtr->defTabStyle.rotate += 360.0;
}
nbPtr->inset = nbPtr->highlightWidth + nbPtr->borderWidth + nbPtr->outerPad;
if (Blt_ConfigModified(configSpecs, interp, "-font", "-*foreground", "-rotate",
"-*background", "-side", (char *)NULL)) {
Blt_ChainLink *linkPtr;
Tab *tabPtr;
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr);
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
ConfigureTab(nbPtr, tabPtr);
}
nbPtr->flags |= (TNB_LAYOUT | TNB_SCROLL);
}
nbPtr->inset2 = nbPtr->defTabStyle.borderWidth + nbPtr->corner;
EventuallyRedraw(nbPtr);
return TCL_OK;
}
/*
* --------------------------------------------------------------
*
* Notebook operations
*
* --------------------------------------------------------------
*/
/*
*----------------------------------------------------------------------
*
* ActivateOp --
*
* Selects the tab to appear active.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
ActivateOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc; /* Not used. */
char **argv;
{
Tab *tabPtr;
if (argv[2][0] == '\0') {
tabPtr = NULL;
} else if (GetTab(nbPtr, argv[2], &tabPtr, INVALID_OK) != TCL_OK) {
return TCL_ERROR;
}
if ((tabPtr != NULL) && (tabPtr->state == STATE_DISABLED)) {
tabPtr = NULL;
}
if (tabPtr != nbPtr->activePtr) {
nbPtr->activePtr = tabPtr;
EventuallyRedraw(nbPtr);
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* BindOp --
*
* .t bind index sequence command
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
BindOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc; /* Not used. */
char **argv;
{
if (argc == 2) {
Blt_HashEntry *hPtr;
Blt_HashSearch cursor;
char *tagName;
for (hPtr = Blt_FirstHashEntry(&(nbPtr->tagTable), &cursor);
hPtr != NULL; hPtr = Blt_NextHashEntry(&cursor)) {
tagName = Blt_GetHashKey(&(nbPtr->tagTable), hPtr);
Tcl_AppendElement(interp, tagName);
}
return TCL_OK;
}
return Blt_ConfigureBindings(interp, nbPtr->bindTable,
MakeTag(nbPtr, argv[2]), argc - 3, argv + 3);
}
/*
*----------------------------------------------------------------------
*
* CgetOp --
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
CgetOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc; /* Not used. */
char **argv;
{
lastNotebookInstance = nbPtr;
return Tk_ConfigureValue(interp, nbPtr->tkwin, configSpecs,
(char *)nbPtr, argv[2], 0);
}
/*
*----------------------------------------------------------------------
*
* ConfigureOp --
*
* This procedure is called to process an argv/argc list, plus
* the Tk option database, in order to configure (or reconfigure)
* the widget.
*
* Results:
* A standard Tcl result. If TCL_ERROR is returned, then
* interp->result contains an error message.
*
* Side Effects:
* Configuration information, such as text string, colors, font,
* etc. get set for nbPtr; old resources get freed, if there
* were any. The widget is redisplayed.
*
*----------------------------------------------------------------------
*/
static int
ConfigureOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc;
char **argv;
{
lastNotebookInstance = nbPtr;
if (argc == 2) {
return Tk_ConfigureInfo(interp, nbPtr->tkwin, configSpecs,
(char *)nbPtr, (char *)NULL, 0);
} else if (argc == 3) {
return Tk_ConfigureInfo(interp, nbPtr->tkwin, configSpecs,
(char *)nbPtr, argv[2], 0);
}
if (ConfigureNotebook(interp, nbPtr, argc - 2, argv + 2,
TK_CONFIG_ARGV_ONLY) != TCL_OK) {
return TCL_ERROR;
}
EventuallyRedraw(nbPtr);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* DeleteOp --
*
* Deletes tab from the set. Deletes either a range of
* tabs or a single node.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
DeleteOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc; /* Not used. */
char **argv;
{
Tab *firstPtr, *lastPtr;
lastPtr = NULL;
if (GetTab(nbPtr, argv[2], &firstPtr, INVALID_FAIL) != TCL_OK) {
return TCL_ERROR;
}
if ((argc == 4) &&
(GetTab(nbPtr, argv[3], &lastPtr, INVALID_FAIL) != TCL_OK)) {
return TCL_ERROR;
}
if (lastPtr == NULL) {
DestroyTab(nbPtr, firstPtr);
} else {
Tab *tabPtr;
Blt_ChainLink *linkPtr, *nextLinkPtr;
tabPtr = NULL; /* Suppress compiler warning. */
/* Make sure that the first tab is before the last. */
for (linkPtr = firstPtr->linkPtr; linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
if (tabPtr == lastPtr) {
break;
}
}
if (tabPtr != lastPtr) {
return TCL_OK;
}
linkPtr = firstPtr->linkPtr;
while (linkPtr != NULL) {
nextLinkPtr = Blt_ChainNextLink(linkPtr);
tabPtr = Blt_ChainGetValue(linkPtr);
DestroyTab(nbPtr, tabPtr);
linkPtr = nextLinkPtr;
if (tabPtr == lastPtr) {
break;
}
}
}
nbPtr->flags |= (TNB_LAYOUT | TNB_SCROLL);
EventuallyRedraw(nbPtr);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* FocusOp --
*
* Selects the tab to get focus.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
FocusOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc; /* Not used. */
char **argv;
{
Tab *tabPtr;
if (GetTab(nbPtr, argv[2], &tabPtr, INVALID_FAIL) != TCL_OK) {
return TCL_ERROR;
}
if (tabPtr != NULL) {
nbPtr->focusPtr = tabPtr;
Blt_SetFocusItem(nbPtr->bindTable, nbPtr->focusPtr, NULL);
EventuallyRedraw(nbPtr);
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* IndexOp --
*
* Converts a string representing a tab index.
*
* Results:
* A standard Tcl result. Interp->result will contain the
* identifier of each index found. If an index could not be found,
* then the serial identifier will be the empty string.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
IndexOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc;
char **argv;
{
Tab *tabPtr;
if (GetTab(nbPtr, argv[2], &tabPtr, INVALID_OK) != TCL_OK) {
return TCL_ERROR;
}
if (tabPtr != NULL) {
Tcl_SetResult(interp, Blt_Itoa(TabIndex(nbPtr, tabPtr)),
TCL_VOLATILE);
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* IdOp --
*
* Converts a tab index into the tab identifier.
*
* Results:
* A standard Tcl result. Interp->result will contain the
* identifier of each index found. If an index could not be found,
* then the serial identifier will be the empty string.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
IdOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc; /* Not used. */
char **argv;
{
Tab *tabPtr;
if (GetTab(nbPtr, argv[2], &tabPtr, INVALID_OK) != TCL_OK) {
return TCL_ERROR;
}
if (tabPtr == NULL) {
Tcl_SetResult(interp, "", TCL_STATIC);
} else {
Tcl_SetResult(interp, tabPtr->name, TCL_VOLATILE);
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* InsertOp --
*
* Add new entries into a tab set.
*
* .t insert end label option-value label option-value...
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
InsertOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc; /* Not used. */
CONST char **argv;
{
Tab *tabPtr;
Blt_ChainLink *linkPtr, *beforeLinkPtr;
char c;
c = argv[2][0];
if ((c == 'e') && (strcmp(argv[2], "end") == 0)) {
beforeLinkPtr = NULL;
} else if (isdigit(UCHAR(c))) {
int position;
if (Tcl_GetInt(interp, argv[2], &position) != TCL_OK) {
return TCL_ERROR;
}
if (position < 0) {
beforeLinkPtr = Blt_ChainFirstLink(nbPtr->chainPtr);
} else if (position > Blt_ChainGetLength(nbPtr->chainPtr)) {
beforeLinkPtr = NULL;
} else {
beforeLinkPtr = Blt_ChainGetNthLink(nbPtr->chainPtr, position);
}
} else {
Tab *beforePtr;
if (GetTab(nbPtr, argv[2], &beforePtr, INVALID_FAIL) != TCL_OK) {
return TCL_ERROR;
}
beforeLinkPtr = beforePtr->linkPtr;
}
nbPtr->flags |= (TNB_LAYOUT | TNB_SCROLL);
EventuallyRedraw(nbPtr);
tabPtr = CreateTab(nbPtr);
if (tabPtr == NULL) {
return TCL_ERROR;
}
lastNotebookInstance = nbPtr;
if (Blt_ConfigureWidgetComponent(interp, nbPtr->tkwin, tabPtr->name,
"Tab", tabConfigSpecs, argc - 3, (char **)argv + 3, (char *)tabPtr, 0)
!= TCL_OK) {
DestroyTab(nbPtr, tabPtr);
return TCL_ERROR;
}
if (ConfigureTab(nbPtr, tabPtr) != TCL_OK) {
DestroyTab(nbPtr, tabPtr);
return TCL_ERROR;
}
linkPtr = Blt_ChainNewLink();
if (beforeLinkPtr == NULL) {
Blt_ChainAppendLink(nbPtr->chainPtr, linkPtr);
} else {
Blt_ChainLinkBefore(nbPtr->chainPtr, linkPtr, beforeLinkPtr);
}
tabPtr->linkPtr = linkPtr;
Blt_ChainSetValue(linkPtr, tabPtr);
Tcl_SetResult(interp, tabPtr->name, TCL_VOLATILE);
return TCL_OK;
}
/*
* Preprocess the command string for percent substitution.
*/
static void
PercentSubst(nbPtr, tabPtr, command, resultPtr)
Notebook *nbPtr;
Tab *tabPtr;
char *command;
Tcl_DString *resultPtr;
{
register char *last, *p;
/*
* Get the full path name of the node, in case we need to
* substitute for it.
*/
Tcl_DStringInit(resultPtr);
for (last = p = command; *p != '\0'; p++) {
if (*p == '%') {
char *string;
char buf[3];
if (p > last) {
*p = '\0';
Tcl_DStringAppend(resultPtr, last, -1);
*p = '%';
}
switch (*(p + 1)) {
case '%': /* Percent sign */
string = "%";
break;
case 'W': /* Widget name */
string = Tk_PathName(nbPtr->tkwin);
break;
case 'i': /* Tab Index */
string = Blt_Itoa(TabIndex(nbPtr, tabPtr));
break;
case 'n': /* Tab name */
string = tabPtr->name;
break;
default:
if (*(p + 1) == '\0') {
p--;
}
buf[0] = *p, buf[1] = *(p + 1), buf[2] = '\0';
string = buf;
break;
}
Tcl_DStringAppend(resultPtr, string, -1);
p++;
last = p + 1;
}
}
if (p > last) {
*p = '\0';
Tcl_DStringAppend(resultPtr, last, -1);
}
}
/*
*----------------------------------------------------------------------
*
* InvokeOp --
*
* This procedure is called to invoke a selection command.
*
* .h invoke index
*
* Results:
* A standard Tcl result. If TCL_ERROR is returned, then
* interp->result contains an error message.
*
* Side Effects:
* Configuration information, such as text string, colors, font,
* etc. get set; old resources get freed, if there were any.
* The widget is redisplayed if needed.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
InvokeOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp; /* Not used. */
int argc;
char **argv;
{
Tab *tabPtr;
char *command;
if (GetTab(nbPtr, argv[2], &tabPtr, INVALID_OK) != TCL_OK) {
return TCL_ERROR;
}
if ((tabPtr == NULL) || (tabPtr->state == STATE_DISABLED)) {
return TCL_OK;
}
Tcl_Preserve(tabPtr);
command = GETATTR(tabPtr, command);
if (command != NULL) {
Tcl_DString dString;
int result;
PercentSubst(nbPtr, tabPtr, command, &dString);
result = Tcl_GlobalEval(nbPtr->interp,
Tcl_DStringValue(&dString));
Tcl_DStringFree(&dString);
if (result != TCL_OK) {
return TCL_ERROR;
}
}
Tcl_Release(tabPtr);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* MoveOp --
*
* Moves a tab to a new location.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
MoveOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc; /* Not used. */
char **argv;
{
Tab *tabPtr, *linkPtr;
int before;
if (GetTab(nbPtr, argv[2], &tabPtr, INVALID_OK) != TCL_OK) {
return TCL_ERROR;
}
if ((tabPtr == NULL) || (tabPtr->state == STATE_DISABLED)) {
return TCL_OK;
}
if ((argv[3][0] == 'b') && (strcmp(argv[3], "before") == 0)) {
before = 1;
} else if ((argv[3][0] == 'a') && (strcmp(argv[3], "after") == 0)) {
before = 0;
} else {
Tcl_AppendResult(interp, "bad key word \"", argv[3],
"\": should be \"after\" or \"before\"", (char *)NULL);
return TCL_ERROR;
}
if (GetTab(nbPtr, argv[4], &linkPtr, INVALID_FAIL) != TCL_OK) {
return TCL_ERROR;
}
if (tabPtr == linkPtr) {
return TCL_OK;
}
Blt_ChainUnlinkLink(nbPtr->chainPtr, tabPtr->linkPtr);
if (before) {
Blt_ChainLinkBefore(nbPtr->chainPtr, tabPtr->linkPtr,
linkPtr->linkPtr);
} else {
Blt_ChainLinkAfter(nbPtr->chainPtr, tabPtr->linkPtr,
linkPtr->linkPtr);
}
nbPtr->flags |= (TNB_LAYOUT | TNB_SCROLL);
EventuallyRedraw(nbPtr);
return TCL_OK;
}
/*ARGSUSED*/
static int
NearestOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc; /* Not used. */
char **argv;
{
int x, y; /* Screen coordinates of the test point. */
Tab *tabPtr;
if ((Tk_GetPixels(interp, nbPtr->tkwin, argv[2], &x) != TCL_OK) ||
(Tk_GetPixels(interp, nbPtr->tkwin, argv[3], &y) != TCL_OK)) {
return TCL_ERROR;
}
if (nbPtr->nVisible > 0) {
tabPtr = (Tab *)PickTab(nbPtr, x, y, NULL);
if (tabPtr != NULL) {
Tcl_SetResult(interp, tabPtr->name, TCL_VOLATILE);
}
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* SelectOp --
*
* This procedure is called to selecta tab.
*
* .h select index
*
* Results:
* A standard Tcl result. If TCL_ERROR is returned, then
* interp->result contains an error message.
*
* Side Effects:
* Configuration information, such as text string, colors, font,
* etc. get set; old resources get freed, if there were any.
* The widget is redisplayed if needed.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
SelectOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp; /* Not used. */
int argc;
char **argv;
{
Tab *tabPtr;
if (GetTab(nbPtr, argv[2], &tabPtr, INVALID_OK) != TCL_OK) {
return TCL_ERROR;
}
if ((tabPtr == NULL) || (tabPtr->state == STATE_DISABLED)) {
return TCL_OK;
}
if ((nbPtr->selectPtr != NULL) && (nbPtr->selectPtr != tabPtr) &&
(nbPtr->selectPtr->tkwin != NULL)) {
if (nbPtr->selectPtr->container == NULL) {
if (Tk_IsMapped(nbPtr->selectPtr->tkwin)) {
Tk_UnmapWindow(nbPtr->selectPtr->tkwin);
}
} else {
/* Redraw now unselected container. */
EventuallyRedrawTearoff(nbPtr->selectPtr);
}
}
nbPtr->selectPtr = tabPtr;
if ((nbPtr->nTiers > 1) && (tabPtr->tier != nbPtr->startPtr->tier)) {
RenumberTiers(nbPtr, tabPtr);
Blt_PickCurrentItem(nbPtr->bindTable);
}
nbPtr->flags |= (TNB_SCROLL);
if (tabPtr->container != NULL) {
EventuallyRedrawTearoff(tabPtr);
}
EventuallyRedraw(nbPtr);
return TCL_OK;
}
static int
ViewOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc;
char **argv;
{
int width;
width = VPORTWIDTH(nbPtr);
if (argc == 2) {
double fract;
/*
* Note: we are bounding the fractions between 0.0 and 1.0 to
* support the "canvas"-style of scrolling.
*/
fract = (double)nbPtr->scrollOffset / nbPtr->worldWidth;
Tcl_AppendElement(interp, Blt_Dtoa(interp, CLAMP(fract, 0.0, 1.0)));
fract = (double)(nbPtr->scrollOffset + width) / nbPtr->worldWidth;
Tcl_AppendElement(interp, Blt_Dtoa(interp, CLAMP(fract, 0.0, 1.0)));
return TCL_OK;
}
if (Blt_GetScrollInfo(interp, argc - 2, argv + 2, &(nbPtr->scrollOffset),
nbPtr->worldWidth, width, nbPtr->scrollUnits,
BLT_SCROLL_MODE_CANVAS) != TCL_OK) {
return TCL_ERROR;
}
nbPtr->flags |= TNB_SCROLL;
EventuallyRedraw(nbPtr);
return TCL_OK;
}
static void
AdoptWindow(clientData)
ClientData clientData;
{
Tab *tabPtr = clientData;
int x, y;
Notebook *nbPtr = tabPtr->nbPtr;
x = nbPtr->inset + nbPtr->inset2 + tabPtr->padLeft;
#define TEAR_OFF_TAB_SIZE 5
y = nbPtr->inset + nbPtr->inset2 + nbPtr->yPad +
nbPtr->outerPad + TEAR_OFF_TAB_SIZE + tabPtr->padTop;
Blt_RelinkWindow(tabPtr->tkwin, tabPtr->container, x, y);
Tk_MapWindow(tabPtr->tkwin);
}
static void
DestroyTearoff(dataPtr)
DestroyData dataPtr;
{
Tab *tabPtr = (Tab *)dataPtr;
if (tabPtr->container != NULL) {
Notebook *nbPtr;
Tk_Window tkwin;
nbPtr = tabPtr->nbPtr;
tkwin = tabPtr->container;
if (tabPtr->flags & TAB_REDRAW) {
Tcl_CancelIdleCall(DisplayTearoff, tabPtr);
}
Tk_DeleteEventHandler(tkwin, StructureNotifyMask, TearoffEventProc,
tabPtr);
if (tabPtr->tkwin != NULL) {
XRectangle rect;
GetWindowRectangle(tabPtr, nbPtr->tkwin, FALSE, &rect);
Blt_RelinkWindow(tabPtr->tkwin, nbPtr->tkwin, rect.x, rect.y);
if (tabPtr == nbPtr->selectPtr) {
ArrangeWindow(tabPtr->tkwin, &rect, TRUE);
} else {
Tk_UnmapWindow(tabPtr->tkwin);
}
}
Tk_DestroyWindow(tkwin);
tabPtr->container = NULL;
}
}
static int
CreateTearoff(nbPtr, name, tabPtr)
Notebook *nbPtr;
char *name;
Tab *tabPtr;
{
Tk_Window tkwin;
int width, height;
tkwin = Tk_CreateWindowFromPath(nbPtr->interp, nbPtr->tkwin, name,
(char *)NULL);
if (tkwin == NULL) {
return TCL_ERROR;
}
tabPtr->container = tkwin;
if (Tk_WindowId(tkwin) == None) {
Tk_MakeWindowExist(tkwin);
}
Tk_SetClass(tkwin, "Tearoff");
Tk_CreateEventHandler(tkwin, (ExposureMask | StructureNotifyMask),
TearoffEventProc, tabPtr);
if (Tk_WindowId(tabPtr->tkwin) == None) {
Tk_MakeWindowExist(tabPtr->tkwin);
}
width = Tk_Width(tabPtr->tkwin);
if (width < 2) {
width = (tabPtr->reqWidth > 0)
? tabPtr->reqWidth : Tk_ReqWidth(tabPtr->tkwin);
}
width += PADDING(tabPtr->padX) + 2 *
Tk_Changes(tabPtr->tkwin)->border_width;
width += 2 * (nbPtr->inset2 + nbPtr->inset);
#define TEAR_OFF_TAB_SIZE 5
height = Tk_Height(tabPtr->tkwin);
if (height < 2) {
height = (tabPtr->reqHeight > 0)
? tabPtr->reqHeight : Tk_ReqHeight(tabPtr->tkwin);
}
height += PADDING(tabPtr->padY) +
2 * Tk_Changes(tabPtr->tkwin)->border_width;
height += nbPtr->inset + nbPtr->inset2 + nbPtr->yPad +
TEAR_OFF_TAB_SIZE + nbPtr->outerPad;
Tk_GeometryRequest(tkwin, width, height);
Tk_UnmapWindow(tabPtr->tkwin);
/* Tk_MoveWindow(tabPtr->tkwin, 0, 0); */
Tcl_SetResult(nbPtr->interp, Tk_PathName(tkwin), TCL_VOLATILE);
#ifdef WIN32
AdoptWindow(tabPtr);
#else
Tcl_DoWhenIdle(AdoptWindow, tabPtr);
#endif
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* TabCgetOp --
*
* .h tab cget index option
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
TabCgetOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc; /* Not used. */
char **argv;
{
Tab *tabPtr;
if (GetTab(nbPtr, argv[3], &tabPtr, INVALID_FAIL) != TCL_OK) {
return TCL_ERROR;
}
lastNotebookInstance = nbPtr;
return Tk_ConfigureValue(interp, nbPtr->tkwin, tabConfigSpecs,
(char *)tabPtr, argv[4], 0);
}
/*
*----------------------------------------------------------------------
*
* TabConfigureOp --
*
* This procedure is called to process a list of configuration
* options database, in order to reconfigure the options for
* one or more tabs in the widget.
*
* .h tab configure index ?index...? ?option value?...
*
* Results:
* A standard Tcl result. If TCL_ERROR is returned, then
* interp->result contains an error message.
*
* Side Effects:
* Configuration information, such as text string, colors, font,
* etc. get set; old resources get freed, if there were any.
* The widget is redisplayed if needed.
*
*----------------------------------------------------------------------
*/
static int
TabConfigureOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc;
CONST char **argv;
{
int nTabs, nOpts, result;
CONST char **options;
register int i;
Tab *tabPtr;
/* Figure out where the option value pairs begin */
argc -= 3;
argv += 3;
for (i = 0; i < argc; i++) {
if (argv[i][0] == '-') {
break;
}
if (GetTab(nbPtr, argv[i], &tabPtr, INVALID_FAIL) != TCL_OK) {
return TCL_ERROR; /* Can't find node. */
}
}
nTabs = i; /* Number of tab indices specified */
nOpts = argc - i; /* Number of options specified */
options = argv + i; /* Start of options in argv */
for (i = 0; i < nTabs; i++) {
GetTab(nbPtr, argv[i], &tabPtr, INVALID_FAIL);
if (argc == 1) {
return Tk_ConfigureInfo(interp, nbPtr->tkwin, tabConfigSpecs,
(char *)tabPtr, (char *)NULL, 0);
} else if (argc == 2) {
return Tk_ConfigureInfo(interp, nbPtr->tkwin, tabConfigSpecs,
(char *)tabPtr, argv[2], 0);
}
Tcl_Preserve(tabPtr);
lastNotebookInstance = nbPtr;
result = Blt_ConfigureWidget(interp, nbPtr->tkwin, tabConfigSpecs,
nOpts, options, (char *)tabPtr, TK_CONFIG_ARGV_ONLY);
if (result == TCL_OK) {
result = ConfigureTab(nbPtr, tabPtr);
}
Tcl_Release(tabPtr);
if (result == TCL_ERROR) {
return TCL_ERROR;
}
if (tabPtr->flags & TAB_VISIBLE) {
nbPtr->flags |= (TNB_LAYOUT | TNB_SCROLL);
EventuallyRedraw(nbPtr);
}
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* TabDockallOp --
*
* .h tab dockall
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
TabDockallOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc; /* Not used. */
char **argv; /* Not used. */
{
Tab *tabPtr;
Blt_ChainLink *linkPtr;
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
if (tabPtr->container != NULL) {
Tcl_EventuallyFree(tabPtr, DestroyTearoff);
}
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* TabNamesOp --
*
* .h tab names pattern
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
TabNamesOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc; /* Not used. */
char **argv; /* Not used. */
{
Tab *tabPtr;
Blt_ChainLink *linkPtr;
if (argc == 3) {
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
Tcl_AppendElement(interp, tabPtr->name);
}
} else {
register int i;
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
for (i = 3; i < argc; i++) {
if (Tcl_StringMatch(tabPtr->name, argv[i])) {
Tcl_AppendElement(interp, tabPtr->name);
break;
}
}
}
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* TabTearoffOp --
*
* .h tab tearoff index ?title?
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
TabTearoffOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc; /* Not used. */
char **argv;
{
Tab *tabPtr;
int result;
Tk_Window tkwin;
if (GetTab(nbPtr, argv[3], &tabPtr, INVALID_OK) != TCL_OK) {
return TCL_ERROR;
}
if ((tabPtr == NULL) || (tabPtr->tkwin == NULL) ||
(tabPtr->state == STATE_DISABLED)) {
return TCL_OK; /* No-op */
}
if (argc == 4) {
Tk_Window parent;
parent = (tabPtr->container == NULL)
? nbPtr->tkwin : tabPtr->container;
Tcl_SetResult(nbPtr->interp, Tk_PathName(parent), TCL_VOLATILE);
return TCL_OK;
}
Tcl_Preserve(tabPtr);
result = TCL_OK;
tkwin = Tk_NameToWindow(interp, argv[4], nbPtr->tkwin);
Tcl_ResetResult(interp);
if (tabPtr->container != NULL) {
Tcl_EventuallyFree(tabPtr, DestroyTearoff);
}
if ((tkwin != nbPtr->tkwin) && (tabPtr->container == NULL)) {
result = CreateTearoff(nbPtr, argv[4], tabPtr);
}
Tcl_Release(tabPtr);
EventuallyRedraw(nbPtr);
return result;
}
/*
*----------------------------------------------------------------------
*
* TabOp --
*
* This procedure handles tab operations.
*
* Results:
* A standard Tcl result.
*
*----------------------------------------------------------------------
*/
static Blt_OpSpec tabOps[] =
{
{"cget", 2, (Blt_Op)TabCgetOp, 5, 5, "nameOrIndex option",},
{"configure", 2, (Blt_Op)TabConfigureOp, 4, 0,
"nameOrIndex ?option value?...",},
{"dockall", 1, (Blt_Op)TabDockallOp, 3, 3, "" },
{"names", 1, (Blt_Op)TabNamesOp, 3, 0, "?pattern...?",},
{"tearoff", 1, (Blt_Op)TabTearoffOp, 4, 5, "index ?parent?",},
};
static int nTabOps = sizeof(tabOps) / sizeof(Blt_OpSpec);
static int
TabOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc;
char **argv;
{
Blt_Op proc;
int result;
proc = Blt_GetOp(interp, nTabOps, tabOps, BLT_OP_ARG2, argc, argv, 0);
if (proc == NULL) {
return TCL_ERROR;
}
result = (*proc) (nbPtr, interp, argc, argv);
return result;
}
/*
*----------------------------------------------------------------------
*
* PerforationActivateOp --
*
* This procedure is called to highlight the perforation.
*
* .h perforation highlight boolean
*
* Results:
* A standard Tcl result. If TCL_ERROR is returned, then
* interp->result contains an error message.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
PerforationActivateOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp; /* Not used. */
int argc;
char **argv;
{
int bool;
if (Tcl_GetBoolean(interp, argv[3], &bool) != TCL_OK) {
return TCL_ERROR;
}
if (bool) {
nbPtr->flags |= PERFORATION_ACTIVE;
} else {
nbPtr->flags &= ~PERFORATION_ACTIVE;
}
EventuallyRedraw(nbPtr);
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* PerforationInvokeOp --
*
* This procedure is called to invoke a perforation command.
*
* .t perforation invoke
*
* Results:
* A standard Tcl result. If TCL_ERROR is returned, then
* interp->result contains an error message.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
PerforationInvokeOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp; /* Not used. */
int argc;
char **argv;
{
if (nbPtr->selectPtr != NULL) {
char *cmd;
cmd = GETATTR(nbPtr->selectPtr, perfCommand);
if (cmd != NULL) {
Tcl_DString dString;
int result;
PercentSubst(nbPtr, nbPtr->selectPtr, cmd, &dString);
Tcl_Preserve(nbPtr);
result = Tcl_GlobalEval(interp, Tcl_DStringValue(&dString));
Tcl_Release(nbPtr);
Tcl_DStringFree(&dString);
if (result != TCL_OK) {
return TCL_ERROR;
}
}
}
return TCL_OK;
}
/*
*----------------------------------------------------------------------
*
* PerforationOp --
*
* This procedure handles tab operations.
*
* Results:
* A standard Tcl result.
*
*----------------------------------------------------------------------
*/
static Blt_OpSpec perforationOps[] =
{
{"activate", 1, (Blt_Op)PerforationActivateOp, 4, 4, "boolean" },
{"invoke", 1, (Blt_Op)PerforationInvokeOp, 3, 3, "",},
};
static int nPerforationOps = sizeof(perforationOps) / sizeof(Blt_OpSpec);
static int
PerforationOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc;
char **argv;
{
Blt_Op proc;
int result;
proc = Blt_GetOp(interp, nPerforationOps, perforationOps, BLT_OP_ARG2,
argc, argv, 0);
if (proc == NULL) {
return TCL_ERROR;
}
result = (*proc) (nbPtr, interp, argc, argv);
return result;
}
/*
*----------------------------------------------------------------------
*
* ScanOp --
*
* Implements the quick scan.
*
*----------------------------------------------------------------------
*/
/*ARGSUSED*/
static int
ScanOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc; /* Not used. */
char **argv;
{
int x, y;
char c;
unsigned int length;
int oper;
#define SCAN_MARK 1
#define SCAN_DRAGTO 2
c = argv[2][0];
length = strlen(argv[2]);
if ((c == 'm') && (strncmp(argv[2], "mark", length) == 0)) {
oper = SCAN_MARK;
} else if ((c == 'd') && (strncmp(argv[2], "dragto", length) == 0)) {
oper = SCAN_DRAGTO;
} else {
Tcl_AppendResult(interp, "bad scan operation \"", argv[2],
"\": should be either \"mark\" or \"dragto\"", (char *)NULL);
return TCL_ERROR;
}
if ((Tk_GetPixels(interp, nbPtr->tkwin, argv[3], &x) != TCL_OK) ||
(Tk_GetPixels(interp, nbPtr->tkwin, argv[4], &y) != TCL_OK)) {
return TCL_ERROR;
}
if (oper == SCAN_MARK) {
if (nbPtr->side & SIDE_VERTICAL) {
nbPtr->scanAnchor = y;
} else {
nbPtr->scanAnchor = x;
}
nbPtr->scanOffset = nbPtr->scrollOffset;
} else {
int offset, delta;
if (nbPtr->side & SIDE_VERTICAL) {
delta = nbPtr->scanAnchor - y;
} else {
delta = nbPtr->scanAnchor - x;
}
offset = nbPtr->scanOffset + (10 * delta);
offset = Blt_AdjustViewport(offset, nbPtr->worldWidth,
VPORTWIDTH(nbPtr), nbPtr->scrollUnits, BLT_SCROLL_MODE_CANVAS);
nbPtr->scrollOffset = offset;
nbPtr->flags |= TNB_SCROLL;
EventuallyRedraw(nbPtr);
}
return TCL_OK;
}
/*ARGSUSED*/
static int
SeeOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp; /* Not used. */
int argc;
char **argv;
{
Tab *tabPtr;
if (GetTab(nbPtr, argv[2], &tabPtr, INVALID_OK) != TCL_OK) {
return TCL_ERROR;
}
if (tabPtr != NULL) {
int left, right, width;
width = VPORTWIDTH(nbPtr);
left = nbPtr->scrollOffset + nbPtr->xSelectPad;
right = nbPtr->scrollOffset + width - nbPtr->xSelectPad;
/* If the tab is partially obscured, scroll so that it's
* entirely in view. */
if (tabPtr->worldX < left) {
nbPtr->scrollOffset = tabPtr->worldX;
if (TabIndex(nbPtr, tabPtr) > 0) {
nbPtr->scrollOffset -= TAB_SCROLL_OFFSET;
}
} else if ((tabPtr->worldX + tabPtr->worldWidth) >= right) {
Blt_ChainLink *linkPtr;
nbPtr->scrollOffset = tabPtr->worldX + tabPtr->worldWidth -
(width - 2 * nbPtr->xSelectPad);
linkPtr = Blt_ChainNextLink(tabPtr->linkPtr);
if (linkPtr != NULL) {
Tab *nextPtr;
nextPtr = Blt_ChainGetValue(linkPtr);
if (nextPtr->tier == tabPtr->tier) {
nbPtr->scrollOffset += TAB_SCROLL_OFFSET;
}
}
}
nbPtr->flags |= TNB_SCROLL;
EventuallyRedraw(nbPtr);
}
return TCL_OK;
}
/*ARGSUSED*/
static int
SizeOp(nbPtr, interp, argc, argv)
Notebook *nbPtr;
Tcl_Interp *interp;
int argc; /* Not used. */
char **argv; /* Not used. */
{
Tcl_SetResult(interp, Blt_Itoa(Blt_ChainGetLength(nbPtr->chainPtr)),
TCL_VOLATILE);
return TCL_OK;
}
static int
CountTabs(nbPtr)
Notebook *nbPtr;
{
int count;
int width, height;
Blt_ChainLink *linkPtr;
register Tab *tabPtr;
register int pageWidth, pageHeight;
int labelWidth, labelHeight;
int tabWidth, tabHeight;
pageWidth = pageHeight = 0;
count = 0;
labelWidth = labelHeight = 0;
/*
* Pass 1: Figure out the maximum area needed for a label and a
* page. Both the label and page dimensions are adjusted
* for orientation. In addition, reset the visibility
* flags and reorder the tabs.
*/
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
/* Reset visibility flag and order of tabs. */
tabPtr->flags &= ~TAB_VISIBLE;
count++;
if (tabPtr->tkwin != NULL) {
width = GetReqWidth(tabPtr);
if (pageWidth < width) {
pageWidth = width;
}
height = GetReqHeight(tabPtr);
if (pageHeight < height) {
pageHeight = height;
}
}
if (labelWidth < tabPtr->labelWidth) {
labelWidth = tabPtr->labelWidth;
}
if (labelHeight < tabPtr->labelHeight) {
labelHeight = tabPtr->labelHeight;
}
}
nbPtr->overlap = 0;
/*
* Pass 2: Set the individual sizes of each tab. This is different
* for constant and variable width tabs. Add the extra space
* needed for slanted tabs, now that we know maximum tab
* height.
*/
if (nbPtr->defTabStyle.constWidth) {
int slant;
tabWidth = 2 * nbPtr->inset2;
tabHeight = nbPtr->inset2 /* + 4 */;
if (nbPtr->side & SIDE_VERTICAL) {
tabWidth += labelHeight;
tabHeight += labelWidth;
slant = labelWidth;
} else {
tabWidth += labelWidth;
tabHeight += labelHeight;
slant = labelHeight;
}
if (nbPtr->slant & SLANT_LEFT) {
tabWidth += slant;
nbPtr->overlap += tabHeight / 2;
}
if (nbPtr->slant & SLANT_RIGHT) {
tabWidth += slant;
nbPtr->overlap += tabHeight / 2;
}
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
tabPtr->worldWidth = tabWidth;
tabPtr->worldHeight = tabHeight;
}
} else {
int slant;
tabWidth = tabHeight = 0;
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
width = 2 * nbPtr->inset2;
height = nbPtr->inset2 /* + 4 */;
if (nbPtr->side & SIDE_VERTICAL) {
width += tabPtr->labelHeight;
height += labelWidth;
slant = labelWidth;
} else {
width += tabPtr->labelWidth;
height += labelHeight;
slant = labelHeight;
}
width += (nbPtr->slant & SLANT_LEFT) ? slant : nbPtr->corner;
width += (nbPtr->slant & SLANT_RIGHT) ? slant : nbPtr->corner;
tabPtr->worldWidth = width; /* + 2 * (nbPtr->corner + nbPtr->xSelectPad) */ ;
tabPtr->worldHeight = height;
if (tabWidth < width) {
tabWidth = width;
}
if (tabHeight < height) {
tabHeight = height;
}
}
if (nbPtr->slant & SLANT_LEFT) {
nbPtr->overlap += tabHeight / 2;
}
if (nbPtr->slant & SLANT_RIGHT) {
nbPtr->overlap += tabHeight / 2;
}
}
nbPtr->tabWidth = tabWidth;
nbPtr->tabHeight = tabHeight;
/*
* Let the user override any page dimension.
*/
nbPtr->pageWidth = pageWidth;
nbPtr->pageHeight = pageHeight;
if (nbPtr->reqPageWidth > 0) {
nbPtr->pageWidth = nbPtr->reqPageWidth;
}
if (nbPtr->reqPageHeight > 0) {
nbPtr->pageHeight = nbPtr->reqPageHeight;
}
return count;
}
static void
WidenTabs(nbPtr, startPtr, nTabs, adjustment)
Notebook *nbPtr;
Tab *startPtr;
int nTabs;
int adjustment;
{
register Tab *tabPtr;
register int i;
int ration;
Blt_ChainLink *linkPtr;
int x;
x = startPtr->tier;
while (adjustment > 0) {
ration = adjustment / nTabs;
if (ration == 0) {
ration = 1;
}
linkPtr = startPtr->linkPtr;
for (i = 0; (linkPtr != NULL) && (i < nTabs) && (adjustment > 0); i++) {
tabPtr = Blt_ChainGetValue(linkPtr);
adjustment -= ration;
tabPtr->worldWidth += ration;
assert(x == tabPtr->tier);
linkPtr = Blt_ChainNextLink(linkPtr);
}
}
/*
* Go back and reset the world X-coordinates of the tabs,
* now that their widths have changed.
*/
x = 0;
linkPtr = startPtr->linkPtr;
for (i = 0; (i < nTabs) && (linkPtr != NULL); i++) {
tabPtr = Blt_ChainGetValue(linkPtr);
tabPtr->worldX = x;
x += tabPtr->worldWidth + nbPtr->gap - nbPtr->overlap;
linkPtr = Blt_ChainNextLink(linkPtr);
}
}
static void
AdjustTabSizes(nbPtr, nTabs)
Notebook *nbPtr;
int nTabs;
{
int tabsPerTier;
int total, count, extra;
Tab *startPtr, *nextPtr;
Blt_ChainLink *linkPtr;
register Tab *tabPtr;
int x, maxWidth;
tabsPerTier = (nTabs + (nbPtr->nTiers - 1)) / nbPtr->nTiers;
x = 0;
maxWidth = 0;
if (nbPtr->defTabStyle.constWidth) {
register int i;
linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr);
count = 1;
while (linkPtr != NULL) {
for (i = 0; i < tabsPerTier; i++) {
tabPtr = Blt_ChainGetValue(linkPtr);
tabPtr->tier = count;
tabPtr->worldX = x;
x += tabPtr->worldWidth + nbPtr->gap - nbPtr->overlap;
linkPtr = Blt_ChainNextLink(linkPtr);
if (x > maxWidth) {
maxWidth = x;
}
if (linkPtr == NULL) {
goto done;
}
}
count++;
x = 0;
}
}
done:
/* Add to tab widths to fill out row. */
if (((nTabs % tabsPerTier) != 0) && (nbPtr->defTabStyle.constWidth)) {
return;
}
startPtr = NULL;
count = total = 0;
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
/*empty*/ ) {
tabPtr = Blt_ChainGetValue(linkPtr);
if (startPtr == NULL) {
startPtr = tabPtr;
}
count++;
total += tabPtr->worldWidth + nbPtr->gap - nbPtr->overlap;
linkPtr = Blt_ChainNextLink(linkPtr);
if (linkPtr != NULL) {
nextPtr = Blt_ChainGetValue(linkPtr);
if (tabPtr->tier == nextPtr->tier) {
continue;
}
}
total += nbPtr->overlap;
extra = nbPtr->worldWidth - total;
assert(count > 0);
if (extra > 0) {
WidenTabs(nbPtr, startPtr, count, extra);
}
count = total = 0;
startPtr = NULL;
}
}
/*
*
* tabWidth = textWidth + gap + (2 * (pad + outerBW));
*
* tabHeight = textHeight + 2 * (pad + outerBW) + topMargin;
*
*/
static void
ComputeLayout(nbPtr)
Notebook *nbPtr;
{
int width;
Blt_ChainLink *linkPtr;
Tab *tabPtr;
int x, extra;
int nTiers, nTabs;
nbPtr->nTiers = 0;
nbPtr->pageTop = 0;
nbPtr->worldWidth = 1;
nbPtr->yPad = 0;
nTabs = CountTabs(nbPtr);
if (nTabs == 0) {
return;
}
/* Reset the pointers to the selected and starting tab. */
if (nbPtr->selectPtr == NULL) {
linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr);
if (linkPtr != NULL) {
nbPtr->selectPtr = Blt_ChainGetValue(linkPtr);
}
}
if (nbPtr->startPtr == NULL) {
nbPtr->startPtr = nbPtr->selectPtr;
}
if (nbPtr->focusPtr == NULL) {
nbPtr->focusPtr = nbPtr->selectPtr;
Blt_SetFocusItem(nbPtr->bindTable, nbPtr->focusPtr, NULL);
}
if (nbPtr->side & SIDE_VERTICAL) {
width = Tk_Height(nbPtr->tkwin) - 2 *
(nbPtr->corner + nbPtr->xSelectPad);
} else {
width = Tk_Width(nbPtr->tkwin) - (2 * nbPtr->inset) -
nbPtr->xSelectPad - nbPtr->corner;
}
nbPtr->flags |= TNB_STATIC;
if (nbPtr->reqTiers > 1) {
int total, maxWidth;
/* Static multiple tier mode. */
/* Sum tab widths and determine the number of tiers needed. */
nTiers = 1;
total = x = 0;
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
if ((x + tabPtr->worldWidth) > width) {
nTiers++;
x = 0;
}
tabPtr->worldX = x;
tabPtr->tier = nTiers;
extra = tabPtr->worldWidth + nbPtr->gap - nbPtr->overlap;
total += extra, x += extra;
}
maxWidth = width;
if (nTiers > nbPtr->reqTiers) {
/*
* The tabs do not fit into the requested number of tiers.
* Go into scrolling mode.
*/
width = ((total + nbPtr->tabWidth) / nbPtr->reqTiers);
x = 0;
nTiers = 1;
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr);
linkPtr != NULL; linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
tabPtr->tier = nTiers;
/*
* Keep adding tabs to a tier until we overfill it.
*/
tabPtr->worldX = x;
x += tabPtr->worldWidth + nbPtr->gap - nbPtr->overlap;
if (x > width) {
nTiers++;
if (x > maxWidth) {
maxWidth = x;
}
x = 0;
}
}
nbPtr->flags &= ~TNB_STATIC;
}
nbPtr->worldWidth = maxWidth;
nbPtr->nTiers = nTiers;
if (nTiers > 1) {
AdjustTabSizes(nbPtr, nTabs);
}
if (nbPtr->flags & TNB_STATIC) {
nbPtr->worldWidth = VPORTWIDTH(nbPtr);
} else {
/* Do you add an offset ? */
nbPtr->worldWidth += (nbPtr->xSelectPad + nbPtr->corner);
}
nbPtr->worldWidth += nbPtr->overlap;
if (nbPtr->selectPtr != NULL) {
RenumberTiers(nbPtr, nbPtr->selectPtr);
}
} else {
/*
* Scrollable single tier mode.
*/
nTiers = 1;
x = 0;
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
tabPtr->tier = nTiers;
tabPtr->worldX = x;
tabPtr->worldY = 0;
x += tabPtr->worldWidth + nbPtr->gap - nbPtr->overlap;
}
nbPtr->worldWidth = x + nbPtr->corner - nbPtr->gap +
nbPtr->xSelectPad + nbPtr->overlap;
nbPtr->flags &= ~TNB_STATIC;
}
if (nTiers == 1) {
nbPtr->yPad = nbPtr->ySelectPad;
}
nbPtr->nTiers = nTiers;
nbPtr->pageTop = nbPtr->inset + nbPtr->yPad /* + 4 */ +
(nbPtr->nTiers * nbPtr->tabHeight) + nbPtr->inset2;
if (nbPtr->side & SIDE_VERTICAL) {
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
tabPtr->screenWidth = (short int)nbPtr->tabHeight;
tabPtr->screenHeight = (short int)tabPtr->worldWidth;
}
} else {
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
tabPtr->screenWidth = (short int)tabPtr->worldWidth;
tabPtr->screenHeight = (short int)nbPtr->tabHeight;
}
}
}
static void
ComputeVisibleTabs(nbPtr)
Notebook *nbPtr;
{
int nVisibleTabs;
register Tab *tabPtr;
Blt_ChainLink *linkPtr;
nbPtr->nVisible = 0;
if (Blt_ChainGetLength(nbPtr->chainPtr) == 0) {
return;
}
nVisibleTabs = 0;
if (nbPtr->flags & TNB_STATIC) {
/* Static multiple tier mode. */
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
tabPtr->flags |= TAB_VISIBLE;
nVisibleTabs++;
}
} else {
int width, offset;
/*
* Scrollable (single or multiple) tier mode.
*/
offset = nbPtr->scrollOffset - (nbPtr->outerPad + nbPtr->xSelectPad);
width = VPORTWIDTH(nbPtr) + nbPtr->scrollOffset +
2 * nbPtr->outerPad;
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
if ((tabPtr->worldX >= width) ||
((tabPtr->worldX + tabPtr->worldWidth) < offset)) {
tabPtr->flags &= ~TAB_VISIBLE;
} else {
tabPtr->flags |= TAB_VISIBLE;
nVisibleTabs++;
}
}
}
for (linkPtr = Blt_ChainFirstLink(nbPtr->chainPtr); linkPtr != NULL;
linkPtr = Blt_ChainNextLink(linkPtr)) {
tabPtr = Blt_ChainGetValue(linkPtr);
tabPtr->screenX = tabPtr->screenY = -1000;
if (tabPtr->flags & TAB_VISIBLE) {
WorldToScreen(nbPtr, tabPtr->worldX, tabPtr->worldY,
&(tabPtr->screenX), &(tabPtr->screenY));
switch (nbPtr->side) {
case SIDE_RIGHT:
tabPtr->screenX -= nbPtr->tabHeight;
break;
case SIDE_BOTTOM:
tabPtr->screenY -= nbPtr->tabHeight;
break;
}
}
}
nbPtr->nVisible = nVisibleTabs;
Blt_PickCurrentItem(nbPtr->bindTable);
}
static void
Draw3DFolder(nbPtr, tabPtr, drawable, side, pointArr, nPoints)
Notebook *nbPtr;
Tab *tabPtr;
Drawable drawable;
int side;
XPoint pointArr[];
int nPoints;
{
GC gc;
int relief, borderWidth;
Tk_3DBorder border;
if (tabPtr == nbPtr->selectPtr) {
border = GETATTR(tabPtr, selBorder);
} else if (tabPtr->border != NULL) {
border = tabPtr->border;
} else {
border = nbPtr->defTabStyle.border;
}
relief = nbPtr->defTabStyle.relief;
if ((side == SIDE_RIGHT) || (side == SIDE_TOP)) {
borderWidth = -nbPtr->defTabStyle.borderWidth;
if (relief == TK_RELIEF_SUNKEN) {
relief = TK_RELIEF_RAISED;
} else if (relief == TK_RELIEF_RAISED) {
relief = TK_RELIEF_SUNKEN;
}
} else {
borderWidth = nbPtr->defTabStyle.borderWidth;
}
{
int i;
#ifndef notdef
int dx, dy;
int oldType, newType;
int start;
dx = pointArr[0].x - pointArr[1].x;
dy = pointArr[0].y - pointArr[1].y;
oldType = ((dy < 0) || (dx > 0));
start = 0;
for (i = 1; i < nPoints; i++) {
dx = pointArr[i - 1].x - pointArr[i].x;
dy = pointArr[i - 1].y - pointArr[i].y;
newType = ((dy < 0) || (dx > 0));
if (newType != oldType) {
if (oldType) {
gc = Tk_GCForColor(nbPtr->shadowColor, drawable);
} else {
gc = Tk_3DBorderGC(nbPtr->tkwin, border, TK_3D_FLAT_GC);
}
XDrawLines(nbPtr->display, drawable, gc, pointArr + start,
i - start, CoordModeOrigin);
start = i - 1;
oldType = newType;
}
}
if (start != i) {
if (oldType) {
gc = Tk_GCForColor(nbPtr->shadowColor, drawable);
} else {
gc = Tk_3DBorderGC(nbPtr->tkwin, border, TK_3D_FLAT_GC);
}
XDrawLines(nbPtr->display, drawable, gc, pointArr + start,
i - start, CoordModeOrigin);
}
#else
/* Draw the outline of the folder. */
gc = Tk_GCForColor(nbPtr->shadowColor, drawable);
XDrawLines(nbPtr->display, drawable, gc, pointArr, nPoints,
CoordModeOrigin);
#endif
}
/* And the folder itself. */
if (tabPtr->tile != NULL) {
#ifdef notdef
Tk_Fill3DPolygon(nbPtr->tkwin, drawable, border, pointArr, nPoints,
borderWidth, relief);
#endif
Blt_TilePolygon(nbPtr->tkwin, drawable, tabPtr->tile, pointArr,
nPoints);
#ifdef notdef
Tk_Draw3DPolygon(nbPtr->tkwin, drawable, border, pointArr, nPoints,
borderWidth, relief);
#endif
} else {
Tk_Fill3DPolygon(nbPtr->tkwin, drawable, border, pointArr, nPoints,
borderWidth, relief);
}
}
/*
* x,y
* |1|2|3| 4 |3|2|1|
*
* 1. tab border width
* 2. corner offset
* 3. label pad
* 4. label width
*
*
*/
static void
DrawLabel(nbPtr, tabPtr, drawable)
Notebook *nbPtr;
Tab *tabPtr;
Drawable drawable;
{
int x, y, dx, dy;
int tx, ty, ix, iy;
int imgWidth, imgHeight;
int active, selected;
XColor *fgColor, *bgColor;
Tk_3DBorder border;
GC gc;
if (!(tabPtr->flags & TAB_VISIBLE)) {
return;
}
x = tabPtr->screenX;
y = tabPtr->screenY;
active = (nbPtr->activePtr == tabPtr);
selected = (nbPtr->selectPtr == tabPtr);
fgColor = GETATTR(tabPtr, textColor);
border = GETATTR(tabPtr, border);
if (selected) {
border = GETATTR(tabPtr, selBorder);
}
bgColor = Tk_3DBorderColor(border);
if (active) {
Tk_3DBorder activeBorder;
activeBorder = GETATTR(tabPtr, activeBorder);
bgColor = Tk_3DBorderColor(activeBorder);
}
dx = (tabPtr->screenWidth - tabPtr->labelWidth) / 2;
dy = (tabPtr->screenHeight - tabPtr->labelHeight) / 2;
/*
* The label position is computed with screen coordinates. This
* is because both text and image components are oriented in
* screen space, and not according to the orientation of the tabs
* themselves. That's why we have to consider the side when
* correcting for left/right slants.
*/
switch (nbPtr->side) {
case SIDE_TOP:
case SIDE_BOTTOM:
if (nbPtr->slant == SLANT_LEFT) {
x += nbPtr->overlap;
} else if (nbPtr->slant == SLANT_RIGHT) {
x -= nbPtr->overlap;
}
break;
case SIDE_LEFT:
case SIDE_RIGHT:
if (nbPtr->slant == SLANT_LEFT) {
y += nbPtr->overlap;
} else if (nbPtr->slant == SLANT_RIGHT) {
y -= nbPtr->overlap;
}
break;
}
/*
* Draw the active or normal background color over the entire
* label area. This includes both the tab's text and image.
* The rectangle should be 2 pixels wider/taller than this
* area. So if the label consists of just an image, we get an
* halo around the image when the tab is active.
*/
gc = Tk_GCForColor(bgColor, drawable);
XFillRectangle(nbPtr->display, drawable, gc, x + dx, y + dy,
tabPtr->labelWidth, tabPtr->labelHeight);
if ((nbPtr->flags & TNB_FOCUS) && (nbPtr->focusPtr == tabPtr)) {
XDrawRectangle(nbPtr->display, drawable, nbPtr->defTabStyle.activeGC,
x + dx, y + dy, tabPtr->labelWidth - 1, tabPtr->labelHeight - 1);
}
tx = ty = ix = iy = 0; /* Suppress compiler warning. */
imgWidth = imgHeight = 0;
if (tabPtr->image != NULL) {
imgWidth = ImageWidth(tabPtr->image);
imgHeight = ImageHeight(tabPtr->image);
}
switch (nbPtr->defTabStyle.textSide) {
case SIDE_LEFT:
tx = x + dx + tabPtr->iPadX.side1;
ty = y + (tabPtr->screenHeight - tabPtr->textHeight) / 2;
ix = tx + tabPtr->textWidth + IMAGE_PAD;
iy = y + (tabPtr->screenHeight - imgHeight) / 2;
break;
case SIDE_RIGHT:
ix = x + dx + tabPtr->iPadX.side1 + IMAGE_PAD;
iy = y + (tabPtr->screenHeight - imgHeight) / 2;
tx = ix + imgWidth;
ty = y + (tabPtr->screenHeight - tabPtr->textHeight) / 2;
break;
case SIDE_BOTTOM:
iy = y + dy + tabPtr->iPadY.side1 + IMAGE_PAD;
ix = x + (tabPtr->screenWidth - imgWidth) / 2;
ty = iy + imgHeight;
tx = x + (tabPtr->screenWidth - tabPtr->textWidth) / 2;
break;
case SIDE_TOP:
tx = x + (tabPtr->screenWidth - tabPtr->textWidth) / 2;
ty = y + dy + tabPtr->iPadY.side1 + IMAGE_PAD;
ix = x + (tabPtr->screenWidth - imgWidth) / 2;
iy = ty + tabPtr->textHeight;
break;
}
if (tabPtr->image != NULL) {
Tk_RedrawImage(ImageBits(tabPtr->image), 0, 0, imgWidth, imgHeight,
drawable, ix, iy);
}
if (tabPtr->text != NULL) {
TextStyle ts;
XColor *activeColor;
activeColor = fgColor;
if (selected) {
activeColor = GETATTR(tabPtr, selColor);
} else if (active) {
activeColor = GETATTR(tabPtr, activeFgColor);
}
Blt_SetDrawTextStyle(&ts, GETATTR(tabPtr, font), tabPtr->textGC,
fgColor, activeColor, tabPtr->shadow.color,
nbPtr->defTabStyle.rotate, TK_ANCHOR_NW, TK_JUSTIFY_LEFT,
0, tabPtr->shadow.offset);
ts.state = tabPtr->state;
ts.border = border;
ts.padX.side1 = ts.padX.side2 = 2;
if (selected || active) {
ts.state |= STATE_ACTIVE;
}
Blt_DrawText(nbPtr->tkwin, drawable, tabPtr->text, &ts, tx, ty);
}
}
static void
DrawPerforation(nbPtr, tabPtr, drawable)
Notebook *nbPtr;
Tab *tabPtr;
Drawable drawable;
{
XPoint pointArr[2];
int x, y;
int segmentWidth, max;
Tk_3DBorder border, perfBorder;
if ((tabPtr->container != NULL) || (tabPtr->tkwin == NULL)) {
return;
}
WorldToScreen(nbPtr, tabPtr->worldX + 2,
tabPtr->worldY + tabPtr->worldHeight + 2, &x, &y);
border = GETATTR(tabPtr, selBorder);
segmentWidth = 3;
if (nbPtr->flags & PERFORATION_ACTIVE) {
perfBorder = GETATTR(tabPtr, activeBorder);
} else {
perfBorder = GETATTR(tabPtr, selBorder);
}
if (nbPtr->side & SIDE_HORIZONTAL) {
pointArr[0].x = x;
pointArr[0].y = pointArr[1].y = y;
max = tabPtr->screenX + tabPtr->screenWidth - 2;
Blt_Fill3DRectangle(nbPtr->tkwin, drawable, perfBorder,
x - 2, y - 4, tabPtr->screenWidth, 8, 0, TK_RELIEF_FLAT);
while (pointArr[0].x < max) {
pointArr[1].x = pointArr[0].x + segmentWidth;
if (pointArr[1].x > max) {
pointArr[1].x = max;
}
Tk_Draw3DPolygon(nbPtr->tkwin, drawable, border, pointArr, 2, 1,
TK_RELIEF_RAISED);
pointArr[0].x += 2 * segmentWidth;
}
} else {
pointArr[0].x = pointArr[1].x = x;
pointArr[0].y = y;
max = tabPtr->screenY + tabPtr->screenHeight - 2;
Blt_Fill3DRectangle(nbPtr->tkwin, drawable, perfBorder,
x - 4, y - 2, 8, tabPtr->screenHeight, 0, TK_RELIEF_FLAT);
while (pointArr[0].y < max) {
pointArr[1].y = pointArr[0].y + segmentWidth;
if (pointArr[1].y > max) {
pointArr[1].y = max;
}
Tk_Draw3DPolygon(nbPtr->tkwin, drawable, border, pointArr, 2, 1,
TK_RELIEF_RAISED);
pointArr[0].y += 2 * segmentWidth;
}
}
}
#define NextPoint(px, py) \
pointPtr->x = (px), pointPtr->y = (py), pointPtr++, nPoints++
#define EndPoint(px, py) \
pointPtr->x = (px), pointPtr->y = (py), nPoints++
#define BottomLeft(px, py) \
NextPoint((px) + nbPtr->corner, (py)), \
NextPoint((px), (py) - nbPtr->corner)
#define TopLeft(px, py) \
NextPoint((px), (py) + nbPtr->corner), \
NextPoint((px) + nbPtr->corner, (py))
#define TopRight(px, py) \
NextPoint((px) - nbPtr->corner, (py)), \
NextPoint((px), (py) + nbPtr->corner)
#define BottomRight(px, py) \
NextPoint((px), (py) - nbPtr->corner), \
NextPoint((px) - nbPtr->corner, (py))
/*
* From the left edge:
*
* |a|b|c|d|e| f |d|e|g|h| i |h|g|e|d|f| j |e|d|c|b|a|
*
* a. highlight ring
* b. notebook 3D border
* c. outer gap
* d. page border
* e. page corner
* f. gap + select pad
* g. label pad x (worldX)
* h. internal pad x
* i. label width
* j. rest of page width
*
* worldX, worldY
* |
* |
* * 4+ . . +5
* 3+ +6
* . .
* . .
* 1+. . .2+ +7 . . . .+8
* 0+ +9
* . .
* . .
*13+ +10
* 12+-------------------------+11
*
*/
static void
DrawFolder(nbPtr, tabPtr, drawable)
Notebook *nbPtr;
Tab *tabPtr;
Drawable drawable;
{
XPoint pointArr[16];
XPoint *pointPtr;
int width, height;
int left, bottom, right, top, yBot, yTop;
int x, y;
register int i;
int nPoints;
width = VPORTWIDTH(nbPtr);
height = VPORTHEIGHT(nbPtr);
x = tabPtr->worldX;
y = tabPtr->worldY;
nPoints = 0;
pointPtr = pointArr;
/* Remember these are all world coordinates. */
/*
* x Left side of tab.
* y Top of tab.
* yTop Top of folder.
* yBot Bottom of the tab.
* left Left side of the folder.
* right Right side of the folder.
* top Top of folder.
* bottom Bottom of folder.
*/
left = nbPtr->scrollOffset - nbPtr->xSelectPad;
right = left + width;
yTop = y + tabPtr->worldHeight;
yBot = nbPtr->pageTop - (nbPtr->inset + nbPtr->yPad);
top = yBot - nbPtr->inset2 /* - 4 */;
if (nbPtr->pageHeight == 0) {
bottom = yBot + 2 * nbPtr->corner;
} else {
bottom = height - nbPtr->yPad - 1;
}
if (tabPtr != nbPtr->selectPtr) {
/*
* Case 1: Unselected tab
*
* * 3+ . . +4
* 2+ +5
* . .
* 1+ +6
* 0+ . . +7
*
*/
if (nbPtr->slant & SLANT_LEFT) {
NextPoint(x, yBot);
NextPoint(x, yTop);
NextPoint(x + nbPtr->tabHeight, y);
} else {
BottomLeft(x, yBot);
TopLeft(x, y);
}
x += tabPtr->worldWidth;
if (nbPtr->slant & SLANT_RIGHT) {
NextPoint(x - nbPtr->tabHeight, y);
NextPoint(x, yTop);
NextPoint(x, yBot);
} else {
TopRight(x, y);
BottomRight(x, yBot);
}
} else if (!(tabPtr->flags & TAB_VISIBLE)) {
/*
* Case 2: Selected tab not visible in viewport. Draw folder only.
*
* * 3+ . . +4
* 2+ +5
* . .
* 1+ +6
* 0+------+7
*
*/
TopLeft(left, top);
TopRight(right, top);
BottomRight(right, bottom);
BottomLeft(left, bottom);
} else {
int flags;
int tabWidth;
x -= nbPtr->xSelectPad;
y -= nbPtr->yPad;
tabWidth = tabPtr->worldWidth + 2 * nbPtr->xSelectPad;
#define CLIP_NONE 0
#define CLIP_LEFT (1<<0)
#define CLIP_RIGHT (1<<1)
flags = 0;
if (x < left) {
flags |= CLIP_LEFT;
}
if ((x + tabWidth) > right) {
flags |= CLIP_RIGHT;
}
switch (flags) {
case CLIP_NONE:
/*
* worldX, worldY
* |
* * 4+ . . +5
* 3+ +6
* . .
* . .
* 1+. . .2+---------+7 . . . .+8
* 0+ +9
* . .
* . .
*13+ +10
* 12+ . . . . . . . . . . . . +11
*/
if (x < (left + nbPtr->corner)) {
NextPoint(left, top);
} else {
TopLeft(left, top);
}
if (nbPtr->slant & SLANT_LEFT) {
NextPoint(x, yTop);
NextPoint(x + nbPtr->tabHeight + nbPtr->yPad, y);
} else {
NextPoint(x, top);
TopLeft(x, y);
}
x += tabWidth;
if (nbPtr->slant & SLANT_RIGHT) {
NextPoint(x - nbPtr->tabHeight - nbPtr->yPad, y);
NextPoint(x, yTop);
} else {
TopRight(x, y);
NextPoint(x, top);
}
if (x > (right - nbPtr->corner)) {
NextPoint(right, top + nbPtr->corner);
} else {
TopRight(right, top);
}
BottomRight(right, bottom);
BottomLeft(left, bottom);
break;
case CLIP_LEFT:
/*
* worldX, worldY
* |
* * 4+ . . +5
* 3+ +6
* . .
* . .
* 2+--------+7 . . . .+8
* 1+ . . . +0 +9
* . .
* . .
* 13+ +10
* 12+ . . . .+11
*/
NextPoint(left, yBot);
if (nbPtr->slant & SLANT_LEFT) {
NextPoint(x, yBot);
NextPoint(x, yTop);
NextPoint(x + nbPtr->tabHeight + nbPtr->yPad, y);
} else {
BottomLeft(x, yBot);
TopLeft(x, y);
}
x += tabWidth;
if (nbPtr->slant & SLANT_RIGHT) {
NextPoint(x - nbPtr->tabHeight - nbPtr->yPad, y);
NextPoint(x, yTop);
NextPoint(x, top);
} else {
TopRight(x, y);
NextPoint(x, top);
}
if (x > (right - nbPtr->corner)) {
NextPoint(right, top + nbPtr->corner);
} else {
TopRight(right, top);
}
BottomRight(right, bottom);
BottomLeft(left, bottom);
break;
case CLIP_RIGHT:
/*
* worldX, worldY
* |
* * 9+ . . +10
* 8+ +11
* . .
* . .
* 6+ . . . .7+---------+12
* 5+ 0+ . . . +13
* . .
* . .
* 4+ +1
* 3+ . . . +2
*/
NextPoint(right, yBot);
BottomRight(right, bottom);
BottomLeft(left, bottom);
if (x < (left + nbPtr->corner)) {
NextPoint(left, top);
} else {
TopLeft(left, top);
}
NextPoint(x, top);
if (nbPtr->slant & SLANT_LEFT) {
NextPoint(x, yTop);
NextPoint(x + nbPtr->tabHeight + nbPtr->yPad, y);
} else {
TopLeft(x, y);
}
x += tabWidth;
if (nbPtr->slant & SLANT_RIGHT) {
NextPoint(x - nbPtr->tabHeight - nbPtr->yPad, y);
NextPoint(x, yTop);
NextPoint(x, yBot);
} else {
TopRight(x, y);
BottomRight(x, yBot);
}
break;
case (CLIP_LEFT | CLIP_RIGHT):
/*
* worldX, worldY
* |
* * 4+ . . . . . . . . +5
* 3+ +6
* . .
* . .
* 1+---------------------+7
* 2+ 0+ +9 .+8
* . .
* . .
* 13+ +10
* 12+ . . . +11
*/
NextPoint(left, yBot);
if (nbPtr->slant & SLANT_LEFT) {
NextPoint(x, yBot);
NextPoint(x, yTop);
NextPoint(x + nbPtr->tabHeight + nbPtr->yPad, y);
} else {
BottomLeft(x, yBot);
TopLeft(x, y);
}
x += tabPtr->worldWidth;
if (nbPtr->slant & SLANT_RIGHT) {
NextPoint(x - nbPtr->tabHeight - nbPtr->yPad, y);
NextPoint(x, yTop);
NextPoint(x, yBot);
} else {
TopRight(x, y);
BottomRight(x, yBot);
}
NextPoint(right, yBot);
BottomRight(right, bottom);
BottomLeft(left, bottom);
break;
}
}
EndPoint(pointArr[0].x, pointArr[0].y);
for (i = 0; i < nPoints; i++) {
WorldToScreen(nbPtr, pointArr[i].x, pointArr[i].y, &x, &y);
pointArr[i].x = x;
pointArr[i].y = y;
}
Draw3DFolder(nbPtr, tabPtr, drawable, nbPtr->side, pointArr, nPoints);
DrawLabel(nbPtr, tabPtr, drawable);
if (tabPtr->container != NULL) {
XRectangle rect;
/* Draw a rectangle covering the spot representing the window */
GetWindowRectangle(tabPtr, nbPtr->tkwin, FALSE, &rect);
XFillRectangles(nbPtr->display, drawable, tabPtr->backGC,
&rect, 1);
}
}
static void
DrawOuterBorders(nbPtr, drawable)
Notebook *nbPtr;
Drawable drawable;
{
/*
* Draw 3D border just inside of the focus highlight ring. We
* draw the border even if the relief is flat so that any tabs
* that hang over the edge will be clipped.
*/
if (nbPtr->borderWidth > 0) {
Blt_Draw3DRectangle(nbPtr->tkwin, drawable, nbPtr->border,
nbPtr->highlightWidth, nbPtr->highlightWidth,
Tk_Width(nbPtr->tkwin) - 2 * nbPtr->highlightWidth,
Tk_Height(nbPtr->tkwin) - 2 * nbPtr->highlightWidth,
nbPtr->borderWidth, nbPtr->relief);
}
/* Draw focus highlight ring. */
if (nbPtr->highlightWidth > 0) {
XColor *color;
GC gc;
color = (nbPtr->flags & TNB_FOCUS)
? nbPtr->highlightColor : nbPtr->highlightBgColor;
gc = Tk_GCForColor(color, drawable);
Tk_DrawFocusHighlight(nbPtr->tkwin, gc, nbPtr->highlightWidth,
drawable);
}
}
/*
* ----------------------------------------------------------------------
*
* DisplayNotebook --
*
* This procedure is invoked to display the widget.
*
* Recomputes the layout of the widget if necessary. This is
* necessary if the world coordinate system has changed.
* Sets the vertical and horizontal scrollbars. This is done
* here since the window width and height are needed for the
* scrollbar calculations.
*
* Results:
* None.
*
* Side effects:
* The widget is redisplayed.
*
* ----------------------------------------------------------------------
*/
static void
DisplayNotebook(clientData)
ClientData clientData; /* Information about widget. */
{
Notebook *nbPtr = clientData;
Pixmap drawable;
int width, height;
nbPtr->flags &= ~TNB_REDRAW;
if (nbPtr->tkwin == NULL) {
return; /* Window has been destroyed. */
}
if (nbPtr->flags & TNB_LAYOUT) {
ComputeLayout(nbPtr);
nbPtr->flags &= ~TNB_LAYOUT;
}
if ((nbPtr->reqHeight == 0) || (nbPtr->reqWidth == 0)) {
width = height = 0;
if (nbPtr->side & SIDE_VERTICAL) {
height = nbPtr->worldWidth;
} else {
width = nbPtr->worldWidth;
}
if (nbPtr->reqWidth > 0) {
width = nbPtr->reqWidth;
} else if (nbPtr->pageWidth > 0) {
width = nbPtr->pageWidth;
}
if (nbPtr->reqHeight > 0) {
height = nbPtr->reqHeight;
} else if (nbPtr->pageHeight > 0) {
height = nbPtr->pageHeight;
}
if (nbPtr->side & SIDE_VERTICAL) {
width += nbPtr->pageTop + nbPtr->inset + nbPtr->inset2;
height += nbPtr->inset + nbPtr->inset2;
} else {
height += nbPtr->pageTop + nbPtr->inset + nbPtr->inset2;
width += nbPtr->inset + nbPtr->inset2;
}
if ((Tk_ReqWidth(nbPtr->tkwin) != width) ||
(Tk_ReqHeight(nbPtr->tkwin) != height)) {
Tk_GeometryRequest(nbPtr->tkwin, width, height);
}
}
if (nbPtr->flags & TNB_SCROLL) {
width = VPORTWIDTH(nbPtr);
nbPtr->scrollOffset = Blt_AdjustViewport(nbPtr->scrollOffset,
nbPtr->worldWidth, width, nbPtr->scrollUnits,
BLT_SCROLL_MODE_CANVAS);
if (nbPtr->scrollCmdPrefix != NULL) {
Blt_UpdateScrollbar(nbPtr->interp, nbPtr->scrollCmdPrefix,
(double)nbPtr->scrollOffset / nbPtr->worldWidth,
(double)(nbPtr->scrollOffset + width) / nbPtr->worldWidth);
}
ComputeVisibleTabs(nbPtr);
nbPtr->flags &= ~TNB_SCROLL;
}
if (!Tk_IsMapped(nbPtr->tkwin)) {
return;
}
height = Tk_Height(nbPtr->tkwin);
drawable = Tk_GetPixmap(nbPtr->display, Tk_WindowId(nbPtr->tkwin),
Tk_Width(nbPtr->tkwin), Tk_Height(nbPtr->tkwin),
Tk_Depth(nbPtr->tkwin));
/*
* Clear the background either by tiling a pixmap or filling with
* a solid color. Tiling takes precedence.
*/
if (nbPtr->tile != NULL) {
Blt_SetTileOrigin(nbPtr->tkwin, nbPtr->tile, 0, 0);
Blt_TileRectangle(nbPtr->tkwin, drawable, nbPtr->tile, 0, 0,
Tk_Width(nbPtr->tkwin), height);
} else {
Blt_Fill3DRectangle(nbPtr->tkwin, drawable, nbPtr->border, 0, 0,
Tk_Width(nbPtr->tkwin), height, 0, TK_RELIEF_FLAT);
}
if (nbPtr->nVisible > 0) {
register int i;
register Tab *tabPtr;
Blt_ChainLink *linkPtr;
linkPtr = nbPtr->startPtr->linkPtr;
for (i = 0; i < Blt_ChainGetLength(nbPtr->chainPtr); i++) {
linkPtr = Blt_ChainPrevLink(linkPtr);
if (linkPtr == NULL) {
linkPtr = Blt_ChainLastLink(nbPtr->chainPtr);
}
tabPtr = Blt_ChainGetValue(linkPtr);
if ((tabPtr != nbPtr->selectPtr) &&
(tabPtr->flags & TAB_VISIBLE)) {
DrawFolder(nbPtr, tabPtr, drawable);
}
}
DrawFolder(nbPtr, nbPtr->selectPtr, drawable);
if (nbPtr->tearoff) {
DrawPerforation(nbPtr, nbPtr->selectPtr, drawable);
}
if ((nbPtr->selectPtr->tkwin != NULL) &&
(nbPtr->selectPtr->container == NULL)) {
XRectangle rect;
GetWindowRectangle(nbPtr->selectPtr, nbPtr->tkwin, FALSE, &rect);
ArrangeWindow(nbPtr->selectPtr->tkwin, &rect, 0);
}
}
DrawOuterBorders(nbPtr, drawable);
XCopyArea(nbPtr->display, drawable, Tk_WindowId(nbPtr->tkwin),
nbPtr->highlightGC, 0, 0, Tk_Width(nbPtr->tkwin), height, 0, 0);
Tk_FreePixmap(nbPtr->display, drawable);
}
/*
* From the left edge:
*
* |a|b|c|d|e| f |d|e|g|h| i |h|g|e|d|f| j |e|d|c|b|a|
*
* a. highlight ring
* b. notebook 3D border
* c. outer gap
* d. page border
* e. page corner
* f. gap + select pad
* g. label pad x (worldX)
* h. internal pad x
* i. label width
* j. rest of page width
*
* worldX, worldY
* |
* |
* * 4+ . . +5
* 3+ +6
* . .
* . .
* 1+. . .2+ +7 . . . .+8
* 0+ +9
* . .
* . .
*13+ +10
* 12+-------------------------+11
*
*/
static void
DisplayTearoff(clientData)
ClientData clientData;
{
Notebook *nbPtr;
Tab *tabPtr;
Drawable drawable;
XPoint pointArr[16];
XPoint *pointPtr;
int width, height;
int left, bottom, right, top;
int x, y;
int nPoints;
Tk_Window tkwin;
Tk_Window parent;
XRectangle rect;
tabPtr = clientData;
if (tabPtr == NULL) {
return;
}
tabPtr->flags &= ~TAB_REDRAW;
nbPtr = tabPtr->nbPtr;
if (nbPtr->tkwin == NULL) {
return;
}
tkwin = tabPtr->container;
drawable = Tk_WindowId(tkwin);
/*
* Clear the background either by tiling a pixmap or filling with
* a solid color. Tiling takes precedence.
*/
if (nbPtr->tile != NULL) {
Blt_SetTileOrigin(tkwin, nbPtr->tile, 0, 0);
Blt_TileRectangle(tkwin, drawable, nbPtr->tile, 0, 0, Tk_Width(tkwin),
Tk_Height(tkwin));
} else {
Blt_Fill3DRectangle(tkwin, drawable, nbPtr->border, 0, 0,
Tk_Width(tkwin), Tk_Height(tkwin), 0, TK_RELIEF_FLAT);
}
width = Tk_Width(tkwin) - 2 * nbPtr->inset;
height = Tk_Height(tkwin) - 2 * nbPtr->inset;
x = nbPtr->inset + nbPtr->gap + nbPtr->corner;
y = nbPtr->inset;
left = nbPtr->inset;
right = nbPtr->inset + width;
top = nbPtr->inset + nbPtr->corner + nbPtr->xSelectPad;
bottom = nbPtr->inset + height;
/*
* worldX, worldY
* |
* * 4+ . . +5
* 3+ +6
* . .
* . .
* 1+. . .2+ +7 . . . .+8
* 0+ +9
* . .
* . .
*13+ +10
* 12+-------------------------+11
*/
nPoints = 0;
pointPtr = pointArr;
TopLeft(left, top);
NextPoint(x, top);
TopLeft(x, y);
x += tabPtr->worldWidth;
TopRight(x, y);
NextPoint(x, top);
TopRight(right, top);
BottomRight(right, bottom);
BottomLeft(left, bottom);
EndPoint(pointArr[0].x, pointArr[0].y);
Draw3DFolder(nbPtr, tabPtr, drawable, SIDE_TOP, pointArr, nPoints);
parent = (tabPtr->container == NULL) ? nbPtr->tkwin : tabPtr->container;
GetWindowRectangle(tabPtr, parent, TRUE, &rect);
ArrangeWindow(tabPtr->tkwin, &rect, TRUE);
/* Draw 3D border. */
if ((nbPtr->borderWidth > 0) && (nbPtr->relief != TK_RELIEF_FLAT)) {
Blt_Draw3DRectangle(tkwin, drawable, nbPtr->border, 0, 0,
Tk_Width(tkwin), Tk_Height(tkwin), nbPtr->borderWidth,
nbPtr->relief);
}
}
/*
* --------------------------------------------------------------
*
* NotebookCmd --
*
* This procedure is invoked to process the "notebook" command.
* See the user documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side effects:
* See the user documentation.
*
* --------------------------------------------------------------
*/
static Blt_OpSpec notebookOps[] =
{
{"activate", 1, (Blt_Op)ActivateOp, 3, 3, "index",},
{"bind", 1, (Blt_Op)BindOp, 2, 5, "index ?sequence command?",},
{"cget", 2, (Blt_Op)CgetOp, 3, 3, "option",},
{"configure", 2, (Blt_Op)ConfigureOp, 2, 0, "?option value?...",},
{"delete", 1, (Blt_Op)DeleteOp, 2, 0, "first ?last?",},
{"focus", 1, (Blt_Op)FocusOp, 3, 3, "index",},
{"highlight", 1, (Blt_Op)ActivateOp, 3, 3, "index",},
{"id", 2, (Blt_Op)IdOp, 3, 3, "index",},
{"index", 3, (Blt_Op)IndexOp, 3, 5, "string",},
{"insert", 3, (Blt_Op)InsertOp, 3, 0, "index ?option value?",},
{"invoke", 3, (Blt_Op)InvokeOp, 3, 3, "index",},
{"move", 1, (Blt_Op)MoveOp, 5, 5, "name after|before index",},
{"nearest", 1, (Blt_Op)NearestOp, 4, 4, "x y",},
{"perforation", 1, (Blt_Op)PerforationOp, 2, 0, "args",},
{"scan", 2, (Blt_Op)ScanOp, 5, 5, "dragto|mark x y",},
{"see", 3, (Blt_Op)SeeOp, 3, 3, "index",},
{"select", 3, (Blt_Op)SelectOp, 3, 3, "index",},
{"size", 2, (Blt_Op)SizeOp, 2, 2, "",},
{"tab", 1, (Blt_Op)TabOp, 2, 0, "oper args",},
{"view", 1, (Blt_Op)ViewOp, 2, 5,
"?moveto fract? ?scroll number what?",},
};
static int nNotebookOps = sizeof(notebookOps) / sizeof(Blt_OpSpec);
static int
NotebookInstCmd(clientData, interp, argc, argv)
ClientData clientData; /* Information about the widget. */
Tcl_Interp *interp; /* Interpreter to report errors back to. */
int argc; /* Number of arguments. */
char **argv; /* Vector of argument strings. */
{
Blt_Op proc;
Notebook *nbPtr = clientData;
int result;
proc = Blt_GetOp(interp, nNotebookOps, notebookOps, BLT_OP_ARG1, argc,
argv, 0);
if (proc == NULL) {
return TCL_ERROR;
}
Tcl_Preserve(nbPtr);
result = (*proc) (nbPtr, interp, argc, argv);
Tcl_Release(nbPtr);
return result;
}
/*
*----------------------------------------------------------------------
*
* NotebookInstDeletedCmd --
*
* This procedure can be called if the window was destroyed
* (tkwin will be NULL) and the command was deleted
* automatically. In this case, we need to do nothing.
*
* Otherwise this routine was called because the command was
* deleted. Then we need to clean-up and destroy the widget.
*
* Results:
* None.
*
* Side Effects:
* The widget is destroyed.
*
*----------------------------------------------------------------------
*/
static void
NotebookInstDeletedCmd(clientData)
ClientData clientData; /* Pointer to widget record for widget. */
{
Notebook *nbPtr = clientData;
if (nbPtr->tkwin != NULL) {
Tk_Window tkwin;
tkwin = nbPtr->tkwin;
nbPtr->tkwin = NULL;
Tk_DestroyWindow(tkwin);
#ifdef ITCL_NAMESPACES
Itk_SetWidgetCommand(tkwin, (Tcl_Command) NULL);
#endif /* ITCL_NAMESPACES */
}
}
/*
* ------------------------------------------------------------------------
*
* NotebookCmd --
*
* This procedure is invoked to process the Tcl command that
* corresponds to a widget managed by this module. See the user
* documentation for details on what it does.
*
* Results:
* A standard Tcl result.
*
* Side Effects:
* See the user documentation.
*
* -----------------------------------------------------------------------
*/
/* ARGSUSED */
static int
NotebookCmd(clientData, interp, argc, argv)
ClientData clientData; /* Main window associated with interpreter. */
Tcl_Interp *interp; /* Current interpreter. */
int argc; /* Number of arguments. */
char **argv; /* Argument strings. */
{
Notebook *nbPtr;
Tk_Window tkwin;
unsigned int mask;
Tcl_CmdInfo cmdInfo;
if (argc < 2) {
Tcl_AppendResult(interp, "wrong # args: should be \"", argv[0],
" pathName ?option value?...\"", (char *)NULL);
return TCL_ERROR;
}
tkwin = Tk_CreateWindowFromPath(interp, Tk_MainWindow(interp), argv[1],
(char *)NULL);
if (tkwin == NULL) {
return TCL_ERROR;
}
nbPtr = CreateNotebook(interp, tkwin);
if (ConfigureNotebook(interp, nbPtr, argc - 2, argv + 2, 0) != TCL_OK) {
Tk_DestroyWindow(nbPtr->tkwin);
return TCL_ERROR;
}
mask = (ExposureMask | StructureNotifyMask | FocusChangeMask);
Tk_CreateEventHandler(tkwin, mask, NotebookEventProc, nbPtr);
nbPtr->cmdToken = Tcl_CreateCommand(interp, argv[1], NotebookInstCmd,
nbPtr, NotebookInstDeletedCmd);
#ifdef ITCL_NAMESPACES
Itk_SetWidgetCommand(nbPtr->tkwin, nbPtr->cmdToken);
#endif
/*
* Try to invoke a procedure to initialize various bindings on
* tabs. Source the file containing the procedure now if the
* procedure isn't currently defined. We deferred this to now so
* that the user could set the variable "blt_library" within the
* script.
*/
if (!Tcl_GetCommandInfo(interp, "blt::TabnotebookInit", &cmdInfo)) {
static char initCmd[] =
"source [file join $blt_library tabnotebook.tcl]";
if (Tcl_GlobalEval(interp, initCmd) != TCL_OK) {
char info[200];
sprintf(info, "\n (while loading bindings for %s)", argv[0]);
Tcl_AddErrorInfo(interp, info);
Tk_DestroyWindow(nbPtr->tkwin);
return TCL_ERROR;
}
}
if (Tcl_VarEval(interp, "blt::TabnotebookInit ", argv[1], (char *)NULL)
!= TCL_OK) {
Tk_DestroyWindow(nbPtr->tkwin);
return TCL_ERROR;
}
Tcl_SetResult(interp, Tk_PathName(nbPtr->tkwin), TCL_VOLATILE);
return TCL_OK;
}
int
Blt_TabnotebookInit(interp)
Tcl_Interp *interp;
{
static Blt_CmdSpec cmdSpec =
{
"tabnotebook", NotebookCmd,
};
if (Blt_InitCmd(interp, "blt", &cmdSpec) == NULL) {
return TCL_ERROR;
}
return TCL_OK;
}
#endif /* NO_TABNOTEBOOK */
|