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
|
/*****
* XmHTML.c : XmHTML main routines, Xt/Motif version
*
* This file Version $Revision: 1.19 $
*
* Creation date: Thu Nov 21 05:02:44 GMT+0100 1996
* Last modification: $Date: 1998/04/27 06:56:21 $
* By: $Author: newt $
* Current State: $State: Exp $
*
* Author: newt
* (C)Copyright 1995-1996 Ripley Software Development
* All Rights Reserved
*
* This file is part of the XmHTML Widget Library.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*****/
/*****
* ChangeLog
* $Log: XmHTML.c,v $
* Revision 1.19 1998/04/27 06:56:21 newt
* tka: extracted all toolkit independent functions to private.c and public.c
*
* Revision 1.18 1998/04/04 06:27:51 newt
* XmHTML Beta 1.1.3
*
* Revision 1.17 1997/10/26 23:49:18 newt
* Bugfixes 10/22/97-01, 10/26/97-01
*
* Revision 1.16 1997/08/31 17:32:33 newt
* Again some fixes in _XmHTMLMoveToPos
*
* Revision 1.15 1997/08/30 00:38:58 newt
* Anchor Highlighting, form component traversal action routines, alpha
* channel support, loads of fixes in _XmHTMLMoveToPos, DrawRedisplay and
* SetValues.
*
* Revision 1.14 1997/08/01 12:54:48 newt
* Progressive image loading changes.
*
* Revision 1.13 1997/05/28 01:38:30 newt
* Added a check on the value of the XmNmaxImageColors resource. Added a check
* on the scrollbar dimensions. Modified the SetValues method to properly deal
* with the XmNbodyImage resource. Modified XmHTMLImageFreeImageInfo to call
* _XmHTMLFreeImageInfo.
*
* Revision 1.12 1997/04/29 14:22:14 newt
* A lot of changes in SetValues, Layout, XmHTMLTextSetString.
* Added XmHTMLXYToInfo.
*
* Revision 1.11 1997/04/03 05:31:02 newt
* Modified XmHTMLImageReplace and XmHTMLImageUpdate to immediatly render an
* image whenever possible. Added the XmHTMLFrameGetChild convenience function.
*
* Revision 1.10 1997/03/28 07:05:28 newt
* Frame interface added.
* Horizontal scrolling bugfix.
* Added all remaining action routines and adjusted translation table.
*
* Revision 1.9 1997/03/20 08:04:38 newt
* XmHTMLImageFreeImageInfo, XmNrepeatDelay, changes in public image functions
*
* Revision 1.8 1997/03/11 19:49:53 newt
* Fix 03/11/97-01, SetValues.
* Added XmHTMLImageGetType, updated XmHTMLImageReplace and XmHTMLImageUpdate
*
* Revision 1.7 1997/03/04 18:45:15 newt
* ?
*
* Revision 1.6 1997/03/04 00:55:54 newt
* Delayed Image Loading changes: XmHTMLReplaceImage, XmHTMLUpdateImage
* and XmHTMLRedisplay added
*
* Revision 1.5 1997/03/02 23:06:35 newt
* Added image/imagemap support; changed expose method; added background
* image painting
*
* Revision 1.4 1997/02/11 02:05:44 newt
* Changes related to autosizing, exposure and scrolling
*
* Revision 1.3 1997/01/09 06:54:53 newt
* expanded copyright marker
*
* Revision 1.2 1997/01/09 06:42:40 newt
* XmNresizeWidth and XmNresizeHeight updates
*
* Revision 1.1 1996/12/19 02:17:03 newt
* Initial Revision
*
*****/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <X11/IntrinsicP.h> /* Fast macros */
#include <X11/keysym.h> /* for keycodes in HTMLProcessInput */
#include <X11/Xmu/StdSel.h>
#include <X11/Xlib.h>
#ifdef HAVE_XFT
#include <X11/Xft/Xft.h>
#endif
#include <Xm/XmP.h> /* XmField, XmPartOffset and private motif funcs. */
#include <Xm/DrawP.h>
#include <Xm/XmStrDefs.h> /* For motif XmN macros */
/*****
* Test if these macros are present. They are required for conversion of the
* enumeration resource values. I don't know if they are present in Motif 1.2.X.
* If not here, spit out an error message.
* If you can't compile this because this error occurs, please contact us
* at the address given below and state what version of Motif you are using.
* Note: these are explicit syntax errors...
*****/
#ifndef XmPartOffset
XmPartOffset macro undefined. Please contact ripley@xs4all.nl
#endif
#ifndef XmField
XmField macro undefined. Please contact ripley@xs4all.nl
#endif
#include <Xm/DrawingA.h>
#include <Xm/ScrollBar.h>
#include <Xm/ScrolledW.h>
#include <Xm/RepType.h>
/* Our private header files */
#include "toolkit.h"
#include XmHTMLPrivateHeader
/* This is the anchor cursor */
#include "bitmaps/fingers.xbm"
#include "bitmaps/fingers_m.xbm"
/*** External Function Prototype Declarations ***/
/*
* undocumented motif functions used: (declared in XmP.h):
* _XmRedisplayGadgets (Widget, XEvent*, Region);
*/
/*** Public Variable Declarations ***/
/*** Private Datatype Declarations ****/
/* Static resources */
#include "resources.h"
/*** Private Function Prototype Declarations ****/
/***
* Private functions
***/
static void CreateAnchorCursor(XmHTMLWidget html);
static void CreateHTMLWidget(XmHTMLWidget html);
static void CheckAnchorUnderlining(XmHTMLWidget html, XmHTMLWidget req);
static void CheckAlignment(XmHTMLWidget html, XmHTMLWidget req);
static void ScrollCB(Widget w, XtPointer arg1, XtPointer arg2);
/* manage scrollbars if necessary */
#define SetScrollBars(HTML) { \
if(ATTR_HTML(HTML, needs_hsb) && \
!(ATTR_HTML(HTML,tka)->IsManaged(ATTR_HTML(HTML,hsb)))) \
ATTR_HTML(HTML,tka)->ManageChild(ATTR_HTML(HTML, hsb)); \
if(ATTR_HTML(HTML, needs_vsb) && \
!(ATTR_HTML(HTML,tka)->IsManaged(ATTR_HTML(HTML,vsb)))) \
ATTR_HTML(HTML,tka)->ManageChild(ATTR_HTML(HTML, vsb)); \
}
/***
* Class methods
***/
/* Primary ClassInitialize method */
static void ClassInitialize(void);
/* ClassPartInitialize method */
static void ClassPartInitialize(WidgetClass wc);
/* class initialize method */
static void Initialize(Widget request, Widget init, ArgList args,
Cardinal *num_args);
/* class expose method */
static void Redisplay(Widget w, XEvent *event, Region region);
/* Expose event handler for the work area */
void _XmHTMLDrawRedisplay(Widget w, XmHTMLWidget html, XEvent *event);
/* VisibilityNotify event handler for the work area */
static void VisibilityHandler(Widget w, XmHTMLWidget html, XEvent *event);
/* MapNotify action routine for the work area */
static void Mapped(Widget w, XmHTMLWidget html, XEvent *event);
/* class set_values method */
static Boolean SetValues(Widget current, Widget request, Widget set,
ArgList args, Cardinal *num_args);
/* class get_values_hook method */
static void GetValues(Widget w, ArgList args, Cardinal *num_args);
/* class geometry_manager method */
static XtGeometryResult GeometryManager(Widget w, XtWidgetGeometry *request,
XtWidgetGeometry *geometry_return);
/* class destroy method */
static void Destroy(Widget w);
/* Action routines */
static void ExtendStart(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void ExtendAdjust(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void ExtendEnd(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void TrackMotion(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void TrackFocus(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void HTMLProcessInput(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void HTMLPageUpOrLeft(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void HTMLPageDownOrRight(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void HTMLIncrementUpOrLeft(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void HTMLIncrementDownOrRight(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void HTMLTopOrBottom(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void HTMLTraverseCurrent(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void HTMLTraverseNext(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void HTMLTraversePrev(Widget w, XEvent *event, String *params,
Cardinal *num_params);
static void HTMLTraverseNextOrPrev(Widget w, XEvent *event, String *params,
Cardinal *num_params);
/*** Private Variable Declarations ***/
static XmRepTypeId underline_repid, sb_policy_repid;
static XmRepTypeId sb_placement_repid, string_repid, icon_repid;
static XmRepTypeId enable_repid, conv_repid, load_repid;
/*****
* default translations
* Order of key translations is important: placing c <Key>osfPageUp after
* <key>osfPageUp will mask of the Ctrl key.
* XmHTML explicitly masks off all key modifiers it does not need for a
* certain action. This allows application programmers to use the same keys
* with modifiers for their own purposes and prevents that these key sequences
* are handled by these specific XmHTML action routines.
* This looks ugly, since it's a static block of text it doesn't take up that
* much data space.
*****/
static char translations[] =
"Ctrl <Key>osfPageUp: page-up-or-left(1)\n\
Ctrl <Key>osfPageDown: page-down-or-right(1)\n\
Ctrl <Key>osfBeginLine: top-or-bottom(0)\n\
Ctrl <Key>osfEndLine: top-or-bottom(1)\n\
~Shift ~Meta ~Alt <Btn1Down>: extend-start() ManagerGadgetArm()\n\
~Shift ~Meta ~Alt <Btn1Motion>: extend-adjust() ManagerGadgetButtonMotion()\n\
~Shift ~Meta ~Alt <Btn1Up>: extend-end(PRIMARY, CUT_BUFFER0) ManagerGadgetActivate() traverse-current()\n\
~Shift ~Meta ~Alt <Btn2Down>:extend-start()\n\
~Shift ~Meta ~Alt <Btn2Motion>: extend-adjust()\n\
~Shift ~Meta ~Alt <Btn2Up>: extend-end(PRIMARY, CUT_BUFFER0)\n\
~Shift ~Meta ~Alt <Key>osfPageUp: page-up-or-left(0)\n\
~Shift ~Meta ~Alt <Key>osfPageDown: page-down-or-right(0)\n\
~Shift ~Meta ~Alt <Key>osfUp: increment-up-or-left(0)\n\
~Shift ~Meta ~Alt <Key>osfLeft: increment-up-or-left(1)\n\
~Shift ~Meta ~Alt <Key>osfDown: increment-down-or-right(0)\n\
~Shift ~Meta ~Alt <Key>osfRight: increment-down-or-right(1)\n\
<Key>osfHelp: ManagerGadgetHelp()\n\
Shift Ctrl <Key>Tab: ManagerGadgetPrevTabGroup()\n\
Ctrl <Key>Tab: ManagerGadgetNextTabGroup()\n\
<Key>Tab: traverse-next()\n\
<Motion>: track-motion()\n\
<Leave>: track-focus()\n\
<FocusIn>: track-focus()\n\
<FocusOut>: track-focus()\n\
<KeyDown>: process-html-input()\n\
<KeyUp>: process-html-input()";
/* Action routines provided by XmHTML */
static XtActionsRec actions[] =
{
{"extend-start", (XtActionProc)ExtendStart},
{"extend-adjust", (XtActionProc)ExtendAdjust},
{"extend-end", (XtActionProc)ExtendEnd},
{"page-up-or-left", (XtActionProc)HTMLPageUpOrLeft},
{"page-down-or-right", (XtActionProc)HTMLPageDownOrRight},
{"increment-up-or-left", (XtActionProc)HTMLIncrementUpOrLeft},
{"increment-down-or-right", (XtActionProc)HTMLIncrementDownOrRight},
{"top-or-bottom", (XtActionProc)HTMLTopOrBottom},
{"track-motion", (XtActionProc)TrackMotion},
{"track-focus", (XtActionProc)TrackFocus},
{"process-html-input", (XtActionProc)HTMLProcessInput},
{"traverse-current", (XtActionProc)HTMLTraverseCurrent},
{"traverse-next", (XtActionProc)HTMLTraverseNext},
{"traverse-prev", (XtActionProc)HTMLTraversePrev},
{"traverse-next-or-prev", (XtActionProc)HTMLTraverseNextOrPrev}
};
/*
* copy of original list. Motif destroys the original list and therefore
* XmHTML crashes when we try to use the above list again.
*/
static XtActionsRec spareActions[] =
{
{"extend-start", (XtActionProc)ExtendStart},
{"extend-adjust", (XtActionProc)ExtendAdjust},
{"extend-end", (XtActionProc)ExtendEnd},
{"page-up-or-left", (XtActionProc)HTMLPageUpOrLeft},
{"page-down-or-right", (XtActionProc)HTMLPageDownOrRight},
{"increment-up-or-left", (XtActionProc)HTMLIncrementUpOrLeft},
{"increment-down-or-right", (XtActionProc)HTMLIncrementDownOrRight},
{"top-or-bottom", (XtActionProc)HTMLTopOrBottom},
{"track-motion", (XtActionProc)TrackMotion},
{"track-focus", (XtActionProc)TrackFocus},
{"process-html-input", (XtActionProc)HTMLProcessInput},
{"traverse-current", (XtActionProc)HTMLTraverseCurrent},
{"traverse-next", (XtActionProc)HTMLTraverseNext},
{"traverse-prev", (XtActionProc)HTMLTraversePrev},
{"traverse-next-or-prev", (XtActionProc)HTMLTraverseNextOrPrev}
};
/****
* Define the CompositeClassExtension record so we can accept objects.
****/
static CompositeClassExtensionRec htmlCompositeExtension = {
NULL, /* next_extension */
NULLQUARK, /* record_type */
XtCompositeExtensionVersion, /* version */
sizeof(CompositeClassExtensionRec), /* record_size */
True /* accept_objects */
#if XtSpecificationRelease >= 6
, False /* allows_change_managed_set */
#endif
};
/****
* Define the widget class record.
****/
XmHTMLClassRec xmHTMLClassRec = {
/* core class fields */
{
#ifdef MOTIF_IN_DLL
/*****
* If Motif is in a DLL on Windows (VC++ 5.0), attempting to initialize
* this with &xmManagerClassRec gives a compiler error telling us that
* it's not a constant (there's some indirection going on there). In
* that case, we have to initialize this to NULL and set it in
* XmCreateHTML before calling XtCreateWidget. This means that
* XmCreateHTML will be the only valid way to create an XmHTML widget,
* but that's a small price to pay
* -- DCW, 6 Jul 98
*****/
(WidgetClass) NULL, /* superclass */
#else
(WidgetClass) &xmManagerClassRec, /* superclass */
#endif
"XmHTML", /* class_name */
sizeof(XmHTMLRec), /* widget_size */
ClassInitialize, /* class_initialize */
ClassPartInitialize, /* class_part_init */
FALSE, /* class_inited */
(XtInitProc)Initialize, /* initialize */
NULL, /* initialize_hook */
XtInheritRealize, /* realize */
actions, /* actions */
XtNumber(actions), /* num_actions */
resources, /* resources */
XtNumber(resources), /* num_resources */
NULLQUARK, /* xrm_class */
TRUE, /* compress_motion */
XtExposeCompressMaximal, /* compress_exposure */
TRUE, /* compress_enterleave */
FALSE, /* visible_interest */
Destroy, /* destroy */
(XtWidgetProc)_XmHTMLResize, /* resize */
(XtExposeProc)Redisplay, /* expose */
(XtSetValuesFunc)SetValues, /* set_values */
NULL, /* set_values_hook */
XtInheritSetValuesAlmost, /* set_values_almost */
GetValues, /* get_values_hook */
XtInheritAcceptFocus, /* accept_focus */
XtVersion, /* version */
NULL, /* callback_private */
translations, /* tm_table */
XtInheritQueryGeometry, /* query_geometry */
XtInheritDisplayAccelerator, /* display_accelerator */
NULL /* extension */
},
/* composite_class fields */
{
GeometryManager, /* geometry_manager */
NULL, /* change_managed */
XtInheritInsertChild, /* insert_child */
XtInheritDeleteChild, /* delete_child */
NULL, /* set by ClassPartInit */
},
/* constraint_class fields */
{
NULL, /* resource list */
0, /* num resources */
0, /* constraint size */
NULL, /* init proc */
NULL, /* destroy proc */
NULL, /* set values proc */
NULL /* extension */
},
/* manager_class fields */
{
XtInheritTranslations, /* translations */
NULL, /* syn_resources */
0, /* num_syn_resources */
NULL, /* syn_cont_resources */
0, /* num_syn_cont_resources*/
XmInheritParentProcess, /* parent_process */
NULL /* extension */
},
/* html_class fields */
{
0 /* none */
}
};
/* Establish the widget class name as an externally accessible symbol. */
WidgetClass xmHTMLWidgetClass = (WidgetClass) &xmHTMLClassRec;
static void
TestRepId(XmRepTypeId id, String name)
{
if(id == XmREP_TYPE_INVALID)
_XmHTMLWarning(__WFUNC__(NULL, "TestRepId"), XMHTML_MSG_8, name);
}
/*****
* Name: ClassInitialize
* Return Type: void
* Description: Called by Intrinsics the first time a widget of this class
* is instantiated
* In:
* nothing
* Returns:
* nothing
*****/
static void
ClassInitialize(void)
{
static char *enable_models[] = {"automatic", "always", "never"};
static char *conv_models[] = {"quick", "best", "fast", "slow", "disabled"};
static char *line_styles[] = {"no_line", "single_line", "double_line",
"single_dashed_line", "double_dashed_line"};
static char *load_types[] = {"normal", "load_normal",
"progressive", "load_progressive",
"incremental", "load_incremental",
"suspend", "load_suspend",
"abort", "load_abort"};
static Byte load_values[] = {XmLOAD_NORMAL, XmLOAD_NORMAL,
XmLOAD_PROGRESSIVE, XmLOAD_PROGRESSIVE,
XmLOAD_INCREMENTAL, XmLOAD_INCREMENTAL,
XmLOAD_SUSPEND, XmLOAD_SUSPEND,
XmLOAD_ABORT, XmLOAD_ABORT};
/* Usefull sanity: check compile version against current header version */
if(XmHTMLVersion != VERSION)
{
_XmHTMLWarning(__WFUNC__(NULL, "ClassInitialize"),
"Version number mismatch: this library was compiled as\n"
" version %i using XmHTML.h version %i.",
VERSION, XmHTMLVersion);
}
/* Get appropriate representation type convertor id's */
/* ScrollBar converters. */
sb_policy_repid = XmRepTypeGetId(XmCScrollBarDisplayPolicy);
TestRepId(sb_policy_repid, XmCScrollBarDisplayPolicy);
sb_placement_repid = XmRepTypeGetId(XmCScrollBarPlacement);
TestRepId(sb_placement_repid, XmCScrollBarPlacement);
/* string direction converter */
string_repid = XmRepTypeGetId(XmCAlignment);
TestRepId(string_repid, XmCAlignment);
/* vertical icon alignment */
icon_repid = XmRepTypeGetId(XmCVerticalAlignment);
TestRepId(icon_repid, XmCVerticalAlignment);
/* XmCEnableMode resource class converter */
XmRepTypeRegister(XmCEnableMode, enable_models, NULL, 3);
enable_repid = XmRepTypeGetId(XmCEnableMode);
TestRepId(enable_repid, XmCEnableMode);
/* XmCConversionMode resource class converter */
XmRepTypeRegister(XmCConversionMode, conv_models, NULL, 5);
conv_repid = XmRepTypeGetId(XmCConversionMode);
TestRepId(conv_repid, XmCConversionMode);
/* XmCAnchorUnderlineType resource class converter */
XmRepTypeRegister(XmCAnchorUnderlineType, line_styles, NULL, 5);
underline_repid = XmRepTypeGetId(XmCAnchorUnderlineType);
TestRepId(underline_repid, XmCAnchorUnderlineType);
/* XmCLoadType resource class converter */
XmRepTypeRegister(XmCLoadType, load_types, load_values, 10);
load_repid = XmRepTypeGetId(XmCLoadType);
TestRepId(load_repid, XmCLoadType);
/* Register the XmNenableBadHTMLWarnings converter */
XtSetTypeConverter(XmRString, XmRHTMLWarningMode,
(XtTypeConverter)_XmHTMLCvtStringToWarning, NULL, 0, XtCacheAll, NULL);
}
/*****
* Name: ClassPartInitialize
* Return Type: void
* Description: object class method to initialize class part structure fields.
* In:
* subclass: pointer to a widget class structure.
* Returns:
* nothing.
* Note:
* This routine initializes the Composite extension. XmHTML *must* be a
* subclass of composite if we want to have it accept any type of Object
* (including real Objects, Gadgets and Widgets).
* Kindly donated by Youssef Ouaghli <Youssef.Ouaghli@elec.rma.ac.be>
*****/
static void
ClassPartInitialize(WidgetClass wc)
{
XmHTMLWidgetClass html_wc = (XmHTMLWidgetClass)wc;
htmlCompositeExtension.next_extension = html_wc->composite_class.extension;
htmlCompositeExtension.accepts_objects = True;
html_wc->composite_class.extension = (XtPointer)&htmlCompositeExtension;
}
/*****
* Name: Initialize
* Return Type: void
* Description: Called when the widget is instantiated
* In:
* request: widget with resource values set as requested by the argument
* list, resource database and widget defaults
* init: same widget with values as modified by superclass initialize()
* methods
* args: argument list passed to XtCreateWidget
* num_args: number of entries in the argument list
* Returns:
* nothing, but init is updated with checked/updated resource values.
*****/
static void
Initialize(Widget request, Widget init, ArgList args, Cardinal *num_args)
{
XmHTMLWidget html = (XmHTMLWidget)init;
XmHTMLWidget req = (XmHTMLWidget)request;
/* Initialize the global HTMLpart */
/* select debug levels */
_XmHTMLSelectDebugLevels(req->html.debug_levels);
_XmHTMLSetFullDebug(req->html.debug_full_output);
#ifdef DEBUG
if(req->html.debug_disable_warnings)
debug_disable_warnings = True;
else
debug_disable_warnings = False;
#endif
_XmHTMLDebug(1, ("XmHTML.c: Initialize Start\n"));
/* private widget resources */
/* Initialize ToolkitAbstraction */
HTML_ATTR(tka) = XmHTMLTkaCreate();
/* Store display */
XmHTMLTkaSetDisplay(HTML_ATTR(tka), (Widget)html);
HTML_ATTR(needs_vsb) = False;
HTML_ATTR(needs_hsb) = False;
HTML_ATTR(scroll_x) = 0;
HTML_ATTR(scroll_y) = 0;
CheckAnchorUnderlining(html, html);
/* ScrollBarDisplayPolicy */
if(!XmRepTypeValidValue(sb_policy_repid, HTML_ATTR(sb_policy),
(Widget)html))
HTML_ATTR(sb_policy) = XmAS_NEEDED;
else if(HTML_ATTR(sb_policy) == XmSTATIC)
HTML_ATTR(needs_vsb) = True;
/* ScrollBarPlacement */
if(!XmRepTypeValidValue(sb_placement_repid, HTML_ATTR(sb_placement),
(Widget)html))
HTML_ATTR(sb_placement) = XmBOTTOM_RIGHT;
/* perfectColors */
if(!XmRepTypeValidValue(enable_repid, HTML_ATTR(perfect_colors),
(Widget)html))
HTML_ATTR(perfect_colors) = XmAUTOMATIC;
/* AlphaChannelProcessing */
if(!XmRepTypeValidValue(enable_repid, HTML_ATTR(alpha_processing),
(Widget)html))
HTML_ATTR(alpha_processing) = XmALWAYS;
/* ImageRGBConversion */
if(!XmRepTypeValidValue(conv_repid, HTML_ATTR(rgb_conv_mode),
(Widget)html) || HTML_ATTR(rgb_conv_mode) == XmDISABLED)
HTML_ATTR(rgb_conv_mode) = XmBEST;
/* ImageMapToPalette */
if(!XmRepTypeValidValue(conv_repid, HTML_ATTR(map_to_palette),
(Widget)html))
HTML_ATTR(map_to_palette) = XmDISABLED;
/* LoadType */
if(!XmRepTypeValidValue(load_repid, HTML_ATTR(load_type),
(Widget)html))
HTML_ATTR(load_type) = XmLOAD_NORMAL;
/* Vertical icon alignment */
if(!XmRepTypeValidValue(icon_repid, HTML_ATTR(icon_valign),
(Widget)html))
HTML_ATTR(icon_valign) = XmALIGNMENT_CENTER;
/* repeat delay. Must be positive */
if(HTML_ATTR(repeat_delay) < 1)
{
_XmHTMLWarning(__WFUNC__(init, "Initialize"), XMHTML_MSG_9,
"XmNrepeatDelay", HTML_ATTR(repeat_delay),
XmHTML_DEFAULT_REPEAT_DELAY);
HTML_ATTR(repeat_delay) = XmHTML_DEFAULT_REPEAT_DELAY;
}
/* tabwidth, must be a positive, non-zero number */
if(HTML_ATTR(tabwidth) < 1)
{
_XmHTMLWarning(__WFUNC__(init, "Initialize"), XMHTML_MSG_9,
"XmNtabWidth", HTML_ATTR(tabwidth),
XmHTML_DEFAULT_TABWIDTH);
HTML_ATTR(tabwidth) = XmHTML_DEFAULT_TABWIDTH;
}
/* Set default text alignment */
CheckAlignment(html, html);
/* source input is always complete */
HTML_ATTR(input_complete) = True;
/****
* Initialize private resources.
****/
/* Formatted document resources */
HTML_ATTR(formatted_width) = 1;
HTML_ATTR(formatted_height) = 1;
HTML_ATTR(elements) = (XmHTMLObject*)NULL;
HTML_ATTR(last_element) = (XmHTMLObject*)NULL;
HTML_ATTR(formatted) = (XmHTMLObjectTable*)NULL;
HTML_ATTR(last_formatted) = (XmHTMLObjectTable*)NULL;
HTML_ATTR(paint_start) = (XmHTMLObjectTable*)NULL;
HTML_ATTR(paint_end) = (XmHTMLObjectTable*)NULL;
HTML_ATTR(nlines) = 0;
HTML_ATTR(line_table) = (XmHTMLLineTable*)NULL;
/* body image */
HTML_ATTR(body_image) = (XmHTMLImage*)NULL;
HTML_ATTR(body_image_url) = (String)NULL;
/* layout & paint engine resources */
HTML_ATTR(in_layout) = False;
HTML_ATTR(paint_x) = 0;
HTML_ATTR(paint_y) = 0;
HTML_ATTR(paint_width) = 0;
HTML_ATTR(paint_height) = 0;
HTML_ATTR(body_fg) = MGR_ATTR(foreground);
HTML_ATTR(body_bg) = CORE_ATTR(background_pixel);
HTML_ATTR(images) = (XmHTMLImage*)NULL;
HTML_ATTR(image_maps) = (XmHTMLImageMap*)NULL;
HTML_ATTR(xcc) = (XCC)NULL;
HTML_ATTR(bg_gc) = (GC)NULL;
HTML_ATTR(form_data) = (XmHTMLFormData*)NULL;
HTML_ATTR(delayed_creation) = False; /* no delayed image creation */
HTML_ATTR(embedded) = (XmHTMLExtObj*)NULL;
/*****
* Original colors must be stored. They can be altered by the
* <BODY> element, so if we get a body without any or some of these
* colors specified, we can use the proper default values for the
* unspecified elements.
*****/
HTML_ATTR(body_fg_save) = HTML_ATTR(body_fg);
HTML_ATTR(body_bg_save) = HTML_ATTR(body_bg);
HTML_ATTR(anchor_fg_save) = HTML_ATTR(anchor_fg);
HTML_ATTR(anchor_target_fg_save) = HTML_ATTR(anchor_target_fg);
HTML_ATTR(anchor_visited_fg_save) = HTML_ATTR(anchor_visited_fg);
HTML_ATTR(anchor_activated_fg_save) = HTML_ATTR(anchor_activated_fg);
HTML_ATTR(anchor_activated_bg_save) = HTML_ATTR(anchor_activated_bg);
/* anchor resources */
HTML_ATTR(anchor_position_x) = 0;
HTML_ATTR(anchor_position_y) = 0;
HTML_ATTR(anchor_current_cursor_element) = (XmHTMLAnchor*)NULL;
HTML_ATTR(armed_anchor) = (XmHTMLObjectTable*)NULL;
HTML_ATTR(current_anchor) = (XmHTMLObjectTable*)NULL;
HTML_ATTR(num_named_anchors) = 0;
HTML_ATTR(anchors) = (XmHTMLWord*)NULL;
HTML_ATTR(anchor_words) = 0;
HTML_ATTR(named_anchors) = (XmHTMLObjectTable*)NULL;
HTML_ATTR(anchor_data) = (XmHTMLAnchor*)NULL;
HTML_ATTR(press_x) = 0;
HTML_ATTR(press_y) = 0;
HTML_ATTR(pressed_time) = 0;
HTML_ATTR(selected_time) = 0;
HTML_ATTR(selected) = (XmHTMLAnchor*)NULL;
/* Text selection resources */
HTML_ATTR(selection) = (XmHTMLObjectTable*)NULL;
HTML_ATTR(select_start) = 0;
HTML_ATTR(select_end) = 0;
/* HTML Frame resources */
HTML_ATTR(nframes) = 0;
HTML_ATTR(frames) = NULL;
HTML_ATTR(is_frame) = False;
/* PLC resources */
HTML_ATTR(plc_buffer) = (PLCPtr)NULL;
HTML_ATTR(num_plcs) = 0;
HTML_ATTR(plc_proc_id) = None;
HTML_ATTR(plc_suspended) = True;
HTML_ATTR(plc_gc) = (GC)NULL;
/* Table resources */
HTML_ATTR(tables) = (XmHTMLTable*)NULL;
/* HTML4.0 Event database */
HTML_ATTR(events) = (HTEvent**)NULL;
HTML_ATTR(nevents) = 0;
HTML_ATTR(body_events) = (AllEvents*)NULL;
HTML_ATTR(event_mask) = 0L;
/* initial mimetype */
if(!(strcasecmp(HTML_ATTR(mime_type), "text/html")))
HTML_ATTR(mime_id) = XmPLC_DOCUMENT;
else if(!(strcasecmp(HTML_ATTR(mime_type), "text/html-perfect")))
HTML_ATTR(mime_id) = XmPLC_DOCUMENT;
else if(!(strcasecmp(HTML_ATTR(mime_type), "text/plain")))
HTML_ATTR(mime_id) = XmHTML_NONE;
else if(!(strncasecmp(HTML_ATTR(mime_type), "image/", 6)))
HTML_ATTR(mime_id) = XmPLC_IMAGE;
/* alpha channel stuff */
HTML_ATTR(alpha_buffer) = (AlphaPtr)NULL;
if(!HTML_ATTR(anchor_track_callback) && !HTML_ATTR(anchor_cursor) &&
!HTML_ATTR(highlight_on_enter) && !HTML_ATTR(motion_track_callback) &&
!HTML_ATTR(focus_callback) && !HTML_ATTR(losing_focus_callback))
HTML_ATTR(need_tracking) = False;
else
HTML_ATTR(need_tracking) = True;
/* verify plc timing intervals */
_XmHTMLPLCCheckIntervals(html);
/* Misc. resources */
HTML_ATTR(gc) = (GC)NULL;
/* set maximum amount of colors for this display (also creates the XCC) */
_XmHTMLCheckMaxColorSetting(html);
/* Create the anchor cursor (if any) */
if(HTML_ATTR(anchor_display_cursor) && !(HTML_ATTR(anchor_cursor)))
CreateAnchorCursor(html);
/* set cursor to None if we don't have to use or have a cursor */
if(!HTML_ATTR(anchor_display_cursor) || !HTML_ATTR(anchor_cursor))
HTML_ATTR(anchor_cursor) = None;
/* Select & initialize appropriate font cache */
HTML_ATTR(default_font) = _XmHTMLSelectFontCache(html, True);
/*****
* if no width or height was specified, default to the width of 20 em
* (TeX measure for average character width) in the default font and the
* height of a single line. We need to do this check since the Core
* initialize() method doesn't do it.
*****/
if(CORE_ATTR(width) <= 0)
{
unsigned long value = 0;
if(!(XGetFontProperty(HTML_ATTR(default_font)->xfont, XA_QUAD_WIDTH,
&value)))
{
value = XTextWidth(HTML_ATTR(default_font)->xfont, "m", 1);
/* sanity for non-ISO fonts */
if(value == 0)
value = 16;
}
CORE_ATTR(width) = (Dimension)(20*(Dimension)value +
2*HTML_ATTR(margin_width));
}
if(CORE_ATTR(height) <= 0)
CORE_ATTR(height) = HTML_ATTR(default_font)->lineheight +
2*HTML_ATTR(margin_height);
/*****
* Now create all private widgets: drawing area and scrollbars.
* We couldn't do this until we knew for sure the widget dimensions were
* set; creation of the work_area uses them.
*****/
CreateHTMLWidget(html);
/* Parse the raw HTML text */
if(ATTR_HTML(req, value))
{
HTML_ATTR(source) = strdup(ATTR_HTML(req, value));
HTML_ATTR(elements) = _XmHTMLparseHTML(req, NULL, ATTR_HTML(req, value),
html);
/* check for frames */
HTML_ATTR(nframes) = _XmHTMLCheckForFrames(html, HTML_ATTR(elements));
/* and create them */
if(!_XmHTMLCreateFrames(NULL, html))
{
HTML_ATTR(frames) = NULL;
HTML_ATTR(nframes) = 0;
}
/* Trigger link callback */
if(HTML_ATTR(link_callback))
_XmHTMLLinkCallback(html);
/* do initial document markup */
_XmHTMLformatObjects(html, html);
/* check for possible delayed external imagemaps */
_XmHTMLCheckImagemaps(html);
}
else
{
HTML_ATTR(source) = (String)NULL;
HTML_ATTR(elements) = (XmHTMLObject*)NULL;
HTML_ATTR(nframes) = 0;
HTML_ATTR(formatted) = (XmHTMLObjectTable*)NULL;
}
/* reset scrollbars (this will also resize the work_area) */
_XmHTMLCheckScrollBars(html);
/* Final step: add a palette if we must dither */
if(HTML_ATTR(map_to_palette) != XmDISABLED)
_XmHTMLAddPalette(html);
_XmHTMLDebug(1, ("XmHTML.c: Initialize End.\n"));
}
/*****
* Name: CreateAnchorCursor
* Return Type: void
* Description: creates the built-in anchor cursor
* In:
* html: XmHTMLWidget for which to create a cursor
* Returns:
* nothing.
*****/
static void
CreateAnchorCursor(XmHTMLWidget html)
{
_XmHTMLDebug(1, ("XmHTML.c: CreateAnchorCursor Start\n"));
if(HTML_ATTR(anchor_cursor) == None)
{
Pixmap shape, mask;
XColor white_def, black_def;
Window window = XtWindow((Widget)html);
Display *display = XtDisplay((Widget)html);
Screen *screen = XtScreen((Widget)html);
if(!window)
window = RootWindowOfScreen(screen);
shape = XCreatePixmapFromBitmapData(display, window,
(char*)fingers_bits, fingers_width, fingers_height, 1, 0, 1);
mask = XCreatePixmapFromBitmapData(display, window,
(char*)fingers_m_bits, fingers_m_width, fingers_m_height, 1, 0, 1);
(void)XParseColor(display, TkaGetColormap(html), "white", &white_def);
(void)XParseColor(display, TkaGetColormap(html), "black", &black_def);
HTML_ATTR(anchor_cursor) = XCreatePixmapCursor(display, shape, mask,
&white_def, &black_def, fingers_x_hot, fingers_y_hot);
}
_XmHTMLDebug(1, ("XmHTML.c: CreateAnchorCursor End\n"));
}
/*
static void
LowerFormWidgets(XmHTMLWidget html)
{
XmHTMLFormData *form;
XmHTMLForm *entry;
XmHTMLExtObj *uentry;
for(form = HTML_ATTR(form_data); form != NULL; form = form->next)
{
for(entry = form->components; entry != NULL; entry = entry->next)
if(entry->w && entry->mapped)
XtUnmapWidget(entry->w);
}
for(uentry = HTML_ATTR(embedded); uentry != NULL; uentry = uentry->next)
{
if(uentry->w && uentry->mapped)
XtUnmapWidget(uentry->w);
}
}
*/
void
_XmHTMLRaiseFormWidgets(XmHTMLWidget html)
{
XmHTMLFormData *form;
XmHTMLForm *entry;
XmHTMLExtObj *uentry;
for(form = HTML_ATTR(form_data); form != NULL; form = form->next)
{
for(entry = form->components; entry != NULL; entry = entry->next)
if(entry->w && entry->mapped)
XtMapWidget(entry->w);
}
for(uentry = HTML_ATTR(embedded); uentry != NULL; uentry = uentry->next)
{
if(uentry->w && uentry->mapped)
XtMapWidget(uentry->w);
}
}
/*****
* Name: OverrideExposure
* Return Type: void
* Description: expose event filter when HTML form widgets are being scrolled.
* In:
* w: unused;
* client_..: unused;
* event: XEvent info;
* continu..: flag to tell X whether or not to propagate this event;
* Returns:
* nothing.
* Note:
* this routine is only activated when XmHTML is moving widgets on it's own
* display area. It filters out any Exposure events that are generated by
* moving these widgets around.
*****/
static void
OverrideExposure(Widget w, XtPointer client_data, XEvent *event,
Boolean *continue_to_dispatch)
{
if(event->xany.type == Expose || event->xany.type == GraphicsExpose)
{
XEvent expose;
#ifdef DEBUG
_XmHTMLDebug(1, ("XmHTML.c: OverrideExposure, ignoring %s event\n"
"\t(x = %i, y = %i, width = %i, height = %i)\n",
(event->xany.type == Expose ? "Expose" : "GraphicsExpose"),
event->xexpose.x, event->xexpose.y,
event->xexpose.width, event->xexpose.height));
if(event->xany.type == GraphicsExpose &&
NULL != XtWindowToWidget(XtDisplay(w),
event->xgraphicsexpose.drawable))
_XmHTMLDebug(1, ("XmHTML.c: OverrideExposure, event was destined "
"for %s (%i events still pending)\n",
XtName(XtWindowToWidget(XtDisplay(w),
event->xgraphicsexpose.drawable)),
event->xgraphicsexpose.count));
#endif
/*****
* A GraphicsExpose event is generated for the entire area covered
* by the form widgets when scrolling: the CopyArea call in
* _XmHTMLMoveToPos fails 'cause the source is overlapped by
* the form widgets. Therefore we must allow this event or text
* will disappear.
*****/
if(event->xany.type == GraphicsExpose &&
event->xgraphicsexpose.count == 0)
return;
/* Gather all other pending events and disallow continuation */
while((XCheckWindowEvent(XtDisplay(w), XtWindow(w), ExposureMask,
&expose)) == True)
;
*continue_to_dispatch = False;
}
#ifdef DEBUG
else
_XmHTMLDebug(1, ("XmHTML.c: OverrideExposure, wrong event %i\n",
(int)(event->xany.type)));
#endif
}
/*****
* Name: _XmHTMLScrollForm
* Return Type: void
* Description: scrolls all widgets of all forms in the current document.
* In:
* html: XmHTML widget id
* Returns:
* nothing.
*****/
void
_XmHTMLScrollForm(XmHTMLWidget html)
{
int xs, ys;
Boolean did_anything = False;
ToolkitAbstraction *tka = HTML_ATTR(tka);
#ifndef UNMAP_FORMS
Widget *forms;
Cardinal nforms;
_XmHTMLDebug(1, ("XmHTML.c: _XmHTMLScrollForm, Start\n"));
XtVaGetValues(HTML_ATTR(work_area),
XmNchildren, &forms,
XmNnumChildren, &nforms,
NULL);
while(nforms--)
{
/* compute new widget position */
xs = ATTR_CORE(forms[nforms],x) - HTML_ATTR(scroll_x);
ys = ATTR_CORE(forms[nforms],y) - HTML_ATTR(scroll_y);
tka->MoveWidget(forms[nforms],
ATTR_CORE(forms[nforms],x) + xs,
ATTR_CORE(forms[nforms],y) + ys);
}
#else
XmHTMLFormData *form;
XmHTMLForm *entry;
/*****
* To prevent the X exposure handling from going haywire, we simply
* override *any* exposure events generated by moving the widgets
* around.
*****/
XtInsertEventHandler(HTML_ATTR(work_area), ExposureMask, True,
(XtEventHandler)OverrideExposure, NULL, XtListHead);
for(form = HTML_ATTR(form_data); form != NULL; form = form->next)
{
for(entry = form->components; entry != NULL; entry = entry->next)
{
if(entry->w)
{
/* compute new widget position */
xs = entry->data->x - HTML_ATTR(scroll_x);
ys = entry->data->y - HTML_ATTR(scroll_y);
/* check if we need to show this widget */
if(xs + entry->width > 0 && xs < HTML_ATTR(work_width) &&
ys + entry->height > 0 && ys < HTML_ATTR(work_height))
{
_XmHTMLDebug(1, ("XmHTML.c: _XmHTMLScrollForm, moving "
"widget %s from %ix%i to %ix%i (wxh = %ix%i)\n",
entry->name, entry->x, entry->y, xs, ys,
entry->width, entry->height));
/* save new widget position */
entry->x = xs;
entry->y = ys;
/* and move to it */
tka->MoveWidget(entry->w, xs, ys);
/* show it */
if(!entry->mapped)
{
tka->SetMappedWhenManaged(entry->w, True);
entry->mapped = True;
}
/****
* FIXME!!
* This code is terribly slow for pages with a great deal of form widgets
* in them.
****/
#ifdef UNMAP_FORMS_AND_REFRESH
/* restore background at previously obscured position */
_XmHTMLRefresh(html, x, y, entry->width, entry->height);
#endif
did_anything = True;
}
else
{
/* hide by unmapping it */
if(entry->mapped)
{
_XmHTMLDebug(1, ("XmHTML.c: _XmHTMLScrollForm, hiding "
"widget %s\n", entry->name));
tka->SetMappedWhenManaged(entry->w, False);
entry->mapped = False;
/****
* FIXME!!
* This code is terribly slow for pages with a great deal of form widgets
* in them.
****/
#ifdef UNMAP_FORMS_AND_REFRESH
/* restore background at previously obscured position */
_XmHTMLRefresh(html, x, y, entry->width, entry->height);
#endif
did_anything = True;
}
}
}
}
}
XtRemoveEventHandler(HTML_ATTR(work_area), ExposureMask, True,
(XtEventHandler)OverrideExposure, NULL);
#endif
/* only do this if we actually did something */
if(did_anything)
{
tka->Sync(tka->dpy, False);
XmUpdateDisplay((Widget)html);
}
_XmHTMLDebug(1, ("XmHTML.c: _XmHTMLScrollForm, End\n"));
}
/*****
* Name: _XmHTMLScrollObjects
* Return Type: void
* Description: scrolls all external objects forms in the current document.
* In:
* html: XmHTML widget id
* Returns:
* nothing.
*****/
void
_XmHTMLScrollObjects(XmHTMLWidget html)
{
int xs, ys;
Boolean did_anything = False;
ToolkitAbstraction *tka = HTML_ATTR(tka);
#ifndef UNMAP_FORMS
Widget *forms;
Cardinal nforms;
_XmHTMLDebug(1, ("XmHTML.c: _XmHTMLScrollObjects, Start\n"));
XtVaGetValues(HTML_ATTR(work_area),
XmNchildren, &forms,
XmNnumChildren, &nforms,
NULL);
while(nforms--)
{
/* compute new widget position */
xs = ATTR_CORE(forms[nforms],x) - HTML_ATTR(scroll_x);
ys = ATTR_CORE(forms[nforms],y) - HTML_ATTR(scroll_y);
tka->MoveWidget(forms[nforms],
ATTR_CORE(forms[nforms],x) + xs,
ATTR_CORE(forms[nforms],y) + ys);
}
#else
XmHTMLExtObj *entry;
/*****
* To prevent the X exposure handling from going haywire, we simply
* override *any* exposure events generated by moving the widgets
* around.
*****/
XtInsertEventHandler(HTML_ATTR(work_area), ExposureMask, True,
(XtEventHandler)OverrideExposure, NULL, XtListHead);
for(entry = HTML_ATTR(embedded); entry != NULL; entry = entry->next)
{
if(entry->w)
{
/* compute new widget position */
xs = entry->data->x - HTML_ATTR(scroll_x);
ys = entry->data->y - HTML_ATTR(scroll_y);
/* check if we need to show this widget */
if(xs + entry->width > 0 && xs < HTML_ATTR(work_width) &&
ys + entry->height > 0 && ys < HTML_ATTR(work_height))
{
_XmHTMLDebug(1, ("XmHTML.c: _XmHTMLScrollForm, moving "
"widget %s from %ix%i to %ix%i (wxh = %ix%i)\n",
entry->name, entry->x, entry->y, xs, ys,
entry->width, entry->height));
/* save new widget position */
entry->x = xs;
entry->y = ys;
/* and move to it */
tka->MoveWidget(entry->w, xs, ys);
/* show it */
if(!entry->mapped)
{
tka->SetMappedWhenManaged(entry->w, True);
entry->mapped = True;
}
/****
* FIXME!!
* This code is terribly slow for pages with a great deal of form widgets
* in them.
****/
#ifdef UNMAP_FORMS_AND_REFRESH
/* restore background at previously obscured position */
_XmHTMLRefresh(html, x, y, entry->width, entry->height);
#endif
did_anything = True;
}
else
{
/* hide by unmapping it */
if(entry->mapped)
{
_XmHTMLDebug(1, ("XmHTML.c: _XmHTMLScrollForm, hiding "
"widget %s\n", entry->name));
tka->SetMappedWhenManaged(entry->w, False);
entry->mapped = False;
/****
* FIXME!!
* This code is terribly slow for pages with a great deal of form widgets
* in them.
****/
#ifdef UNMAP_FORMS_AND_REFRESH
/* restore background at previously obscured position */
_XmHTMLRefresh(html, x, y, entry->width, entry->height);
#endif
did_anything = True;
}
}
}
}
XtRemoveEventHandler(HTML_ATTR(work_area), ExposureMask, True,
(XtEventHandler)OverrideExposure, NULL);
#endif
/* only do this if we actually did something */
if(did_anything)
{
tka->Sync(tka->dpy, False);
XmUpdateDisplay((Widget)html);
}
_XmHTMLDebug(1, ("XmHTML.c: _XmHTMLScrollForm, End\n"));
}
/*****
* Name: ScrollCB
* Return Type: void
* Description: callback procedure for scrollbar movement
* In:
* w: originator
* arg1: client_data, in this case a XmHTMLWidget
* arg2: event specific callback structure.
* Returns:
* nothing
*****/
static void
ScrollCB(Widget w, XtPointer arg1, XtPointer arg2)
{
XmScrollBarCallbackStruct *cbs = (XmScrollBarCallbackStruct *)arg2;
XEvent *event = cbs->event;
XmHTMLWidget html = (XmHTMLWidget)arg1;
/* Fix 05/27/98-01, eb */
if(event && event->type == MotionNotify && !HTML_ATTR(smooth_scroll))
{
/****
* Try to collapse motion events.
* In case there are some other motion events in the queue,
* so ignore this one and let the latter one do the job.
*****/
XEvent next_event ;
Display *dpy = HTML_ATTR(tka)->dpy ;
/****
* Look for a would-be MotionNotify event in the queue.
* Use XCheckTypedWindowEvent() instead of XWindowEvent(), as
* XWindowEvent() blocks if there is no event in the queue.
* The only drawback is that the event is withdrawn from the queue,
* and thus we have to put it back.
*****/
if(XCheckTypedWindowEvent(dpy, XtWindow(w), event->type, &next_event))
{
/* if found, put the event back in the queue and return */
XPutBackEvent(dpy, &next_event);
_XmHTMLDebug(1, ("XmHTML.c: ScrollCB, pushed back an outstanding "
"MotionNotify event.\n"));
return ;
}
}
_XmHTMLDebug(1, ("XmHTML.c: ScrollCB, calling _XmHTMLMoveToPos\n"));
_XmHTMLMoveToPos(w, (XmHTMLWidget)arg1, cbs->value);
}
/*****
* Name: CreateHTMLWidget
* Return Type: void
* Description: creates the HTML widget
* The actual area we use to draw into is a drawingAreaWidget.
* In:
* html: widget to be created.
* Returns:
* nothing
*****/
static void
CreateHTMLWidget(XmHTMLWidget html)
{
Arg args[15];
Dimension argc = 0;
int vsb_width, hsb_height;
static XtTranslations trans = NULL;
_XmHTMLDebug(1, ("XmHTML.c: CreateHTMLWidget Start\n"));
/* Check if user provided a work area */
if(HTML_ATTR(work_area) == NULL)
{
HTML_ATTR(work_area) = XtVaCreateWidget("workWindow",
xmDrawingAreaWidgetClass, (Widget)html,
XmNwidth, CORE_ATTR(width),
XmNheight, CORE_ATTR(height),
NULL);
}
/* catch all exposure events on the render window */
XtAddEventHandler((Widget)HTML_ATTR(work_area), ExposureMask, True,
(XtEventHandler)_XmHTMLDrawRedisplay, (XtPointer)html);
/* we want to know when to handle GraphicsExpose events */
XtAddEventHandler((Widget)HTML_ATTR(work_area), VisibilityChangeMask, True,
(XtEventHandler)VisibilityHandler, (XtPointer)html);
XtAddEventHandler((Widget)html, SubstructureNotifyMask,
True, (XtEventHandler)Mapped, (XtPointer)html);
/*
* For some reason, Motif fucks up the original action list, so we
* need to use a fallback copy instead.
* Crash happens in XrmStringToQuark().
*/
XtAppAddActions(XtWidgetToApplicationContext(HTML_ATTR(work_area)),
spareActions, XtNumber(spareActions));
/* add translations for the actions */
if(trans == NULL)
trans = XtParseTranslationTable(translations);
XtSetArg(args[0], XtNtranslations, trans);
XtSetValues(HTML_ATTR(work_area), args, 1);
argc = 0;
XtManageChild(HTML_ATTR(work_area));
if(HTML_ATTR(vsb) == NULL)
{
argc = 0;
XtSetArg(args[argc], XmNorientation, XmVERTICAL); argc++;
XtSetArg(args[argc], XmNrepeatDelay, HTML_ATTR(repeat_delay)); argc++;
/* make them a little bit more responsive */
XtSetArg(args[argc], XmNinitialDelay, 100); argc++;
HTML_ATTR(vsb) = XtCreateWidget("verticalScrollBar",
xmScrollBarWidgetClass, (Widget)html, args, argc);
}
XtManageChild(HTML_ATTR(vsb));
/* Catch vertical scrollbar movement */
XtAddCallback(HTML_ATTR(vsb), XmNvalueChangedCallback,
(XtCallbackProc)ScrollCB, (XtPointer)html);
XtAddCallback(HTML_ATTR(vsb), XmNdragCallback,
(XtCallbackProc)ScrollCB, (XtPointer)html);
if(HTML_ATTR(hsb) == NULL)
{
argc = 0;
XtSetArg(args[argc], XmNorientation, XmHORIZONTAL); argc++;
XtSetArg(args[argc], XmNrepeatDelay, HTML_ATTR(repeat_delay)); argc++;
/* make them a little bit more responsive */
XtSetArg(args[argc], XmNinitialDelay, 100); argc++;
HTML_ATTR(hsb) = XtCreateWidget("horizontalScrollBar",
xmScrollBarWidgetClass, (Widget)html, args, argc);
}
XtManageChild(HTML_ATTR(hsb));
/* Catch horizontal scrollbar movement */
XtAddCallback(HTML_ATTR(hsb), XmNvalueChangedCallback,
(XtCallbackProc)ScrollCB, (XtPointer)html);
XtAddCallback(HTML_ATTR(hsb), XmNdragCallback,
(XtCallbackProc)ScrollCB, (XtPointer)html);
/*
* subtract margin_width once to minimize number of calcs in
* the paint routines: every thing rendered starts at an x position
* of margin_width.
*/
_XmHTMLGetScrollDim(html, &hsb_height, &vsb_width);
HTML_ATTR(work_width) = CORE_ATTR(width) - HTML_ATTR(margin_width) -
vsb_width;
HTML_ATTR(work_height)= CORE_ATTR(height);
/* store window of *drawingarea* in the toolkit abstraction */
XmHTMLTkaSetDrawable(HTML_ATTR(tka),
XtWindow(HTML_ATTR(work_area)));
/* set some other data of the tka */
/* font_type */
HTML_ATTR(tka)->font_type = HTML_ATTR(font_type);
/* charset */
HTML_ATTR(tka)->charset = HTML_ATTR(charset);
_XmHTMLDebug(1, ("XmHTML.c: CreateHTMLWidget End\n"));
return;
}
/*****
* Name: _XmHTMLGetScrollDim
* Return Type: void
* Description: retrieves width & height of the scrollbars
* In:
* html: XmHTMLWidget for which to retrieve these values
* hsb_height: thickness of horizontal scrollbar, filled upon return
* vsb_width: thickness of vertical scrollbar, filled upon return
* Returns:
* nothing
* Note:
* I had a nicely working caching version of this routine under Linux &
* Motif 2.0.1, but under HPUX with 1.2.0 this never worked. This does.
*****/
void
_XmHTMLGetScrollDim(XmHTMLWidget html, int *hsb_height, int *vsb_width)
{
Arg args[1];
Dimension height = 0, width = 0;
if(HTML_ATTR(hsb))
{
#ifdef NO_XLIB_ILLEGAL_ACCESS
XtSetArg(args[0], XmNheight, &height);
XtGetValues(HTML_ATTR(hsb), args, 1);
#else
height = ATTR_CORE(HTML_ATTR(hsb), height);
#endif
/*
* Sanity check if the scrollbar dimensions exceed the widget dimensions
* Not doing this would lead to X Protocol errors whenever text is set
* into the widget: the size of the workArea will be less than or equal
* to zero when scrollbars are required.
* We always need to do this check since it's possible that some
* user has been playing with the dimensions of the scrollbars.
*/
if(height >= CORE_ATTR(height))
{
_XmHTMLWarning(__WFUNC__(HTML_ATTR(hsb), "_XmHTMLGetScrollDim"),
XMHTML_MSG_11, "Height", "horizontal", height, "height",
CORE_ATTR(height), 15);
height = 15;
XtSetArg(args[0], XmNheight, height);
XtSetValues(HTML_ATTR(hsb), args, 1);
}
}
if(HTML_ATTR(vsb))
{
#ifdef NO_XLIB_ILLEGAL_ACCESS
XtSetArg(args[0], XmNwidth, &width);
XtGetValues(HTML_ATTR(vsb), args, 1);
#else
width = ATTR_CORE(HTML_ATTR(vsb), width);
#endif
if(width >= CORE_ATTR(width))
{
_XmHTMLWarning(__WFUNC__(HTML_ATTR(vsb), "_XmHTMLGetScrollDim"),
XMHTML_MSG_11, "Width", "vertical", width, "width",
CORE_ATTR(width), 15);
width = 15;
XtSetArg(args[0], XmNwidth, width);
XtSetValues(HTML_ATTR(vsb), args, 1);
}
}
_XmHTMLDebug(1, ("XmHTML.c: _XmHTMLGetScrollDim; height = %i, width = %i\n",
height, width));
*hsb_height = height;
*vsb_width = width;
}
/*****
* Name: _XmHTMLCheckScrollBars
* Return Type: void
* Description: (re)configures scrollbars
* In:
* html: HTML widget to configure
* Returns:
* nothing.
*****/
void
_XmHTMLCheckScrollBars(XmHTMLWidget html)
{
int dx, dy, hsb_height, vsb_width, st;
Boolean hsb_on_top, vsb_on_left;
/* forced display of scrollbars: XmSTATIC or frames with scrolling = yes */
Boolean force_vsb = False, force_hsb = False;
Arg args[10];
Dimension argc = 0;
ToolkitAbstraction *tka = HTML_ATTR(tka);
_XmHTMLDebug(1, ("XmHTML.c: _XmHTMLCheckScrollBars, start\n"));
/* don't do a thing if we aren't managed yet */
if(!(tka->IsManaged((Widget)html)))
return;
/* Initial work area offset */
st = dx = dy = MGR_ATTR(shadow_thickness);
_XmHTMLGetScrollDim(html, &hsb_height, &vsb_width);
/* check if we need a vertical scrollbar */
if(HTML_ATTR(formatted_height) < CORE_ATTR(height))
{
HTML_ATTR(needs_vsb) = False;
/* don't forget! */
HTML_ATTR(scroll_y) = 0;
tka->UnmanageChild(HTML_ATTR(vsb));
}
else
HTML_ATTR(needs_vsb) = True;
/* add a scrollbar if we must and it isn't already here */
if(!HTML_ATTR(needs_vsb) && HTML_ATTR(sb_policy) == XmSTATIC)
{
HTML_ATTR(needs_vsb) = True;
force_vsb = True;
}
/*
* check if we need a horizontal scrollbar. If we have a vertical
* scrollbar, we must add it's width or text might be lost.
*/
if(HTML_ATTR(formatted_width) < CORE_ATTR(width) -
(HTML_ATTR(needs_vsb) ? vsb_width : 0)) /* fix 04/27/97-01, kdh */
{
HTML_ATTR(needs_hsb) = False;
/* don't forget! */
HTML_ATTR(scroll_x) = 0;
tka->UnmanageChild(HTML_ATTR(hsb));
}
else
HTML_ATTR(needs_hsb) = True;
/* add a scrollbar if we must and it isn't already here */
if(!HTML_ATTR(needs_hsb) && HTML_ATTR(sb_policy) == XmSTATIC)
{
HTML_ATTR(needs_hsb) = True;
force_hsb = True;
}
/* if this is a frame, check what type of scrolling is requested */
if(HTML_ATTR(is_frame))
{
if(HTML_ATTR(scroll_type) == FRAME_SCROLL_NONE)
{
HTML_ATTR(needs_hsb) = False;
HTML_ATTR(needs_vsb) = False;
HTML_ATTR(scroll_x) = 0;
HTML_ATTR(scroll_y) = 0;
tka->UnmanageChild(HTML_ATTR(hsb));
tka->UnmanageChild(HTML_ATTR(vsb));
}
else if(HTML_ATTR(scroll_type) == FRAME_SCROLL_YES)
{
HTML_ATTR(needs_vsb) = True;
HTML_ATTR(needs_hsb) = True;
force_vsb = True;
force_hsb = True;
}
/* else scrolling is auto, just proceed */
}
/* return if we don't need any scrollbars */
if(!HTML_ATTR(needs_hsb) && !HTML_ATTR(needs_vsb))
{
_XmHTMLDebug(1, ("XmHTML.c: _XmHTMLCheckScrollBars, end, no bars "
"needed.\n"));
/* move work_area to it's correct position */
tka->ConfigureWidget(HTML_ATTR(work_area), dx, dy, CORE_ATTR(width),
CORE_ATTR(height), ATTR_CORE(HTML_ATTR(work_area), border_width));
return;
}
/* see if we have to put hsb on top */
hsb_on_top = (HTML_ATTR(sb_placement) == XmTOP_LEFT ||
HTML_ATTR(sb_placement) == XmTOP_RIGHT);
/* see if we have top put vsb on left */
vsb_on_left = (HTML_ATTR(sb_placement) == XmTOP_LEFT ||
HTML_ATTR(sb_placement) == XmBOTTOM_LEFT);
/* horizontal sb on top */
if(HTML_ATTR(needs_hsb) && hsb_on_top)
dy += hsb_height;
/* vertical sb on left */
if(HTML_ATTR(needs_vsb) && vsb_on_left)
dx += vsb_width;
/* move work_area to it's correct position */
tka->MoveWidget(HTML_ATTR(work_area), dx, dy);
/* See what space we have to reserve for the scrollbars */
if(HTML_ATTR(needs_hsb) && hsb_on_top == False)
dy += hsb_height;
if(HTML_ATTR(needs_vsb) && vsb_on_left == False)
dx += vsb_width;
tka->ResizeWidget(HTML_ATTR(work_area),
CORE_ATTR(width) - dx, CORE_ATTR(height) - dy,
ATTR_CORE(HTML_ATTR(work_area), border_width));
if(HTML_ATTR(needs_hsb) == True)
{
int pinc;
_XmHTMLDebug(1, ("XmHTML.c: _XmHTMLCheckScrollBars, setting hsb\n"));
/* Set hsb size; adjust x-position if we have a vsb */
dx = (HTML_ATTR(needs_vsb) ? vsb_width : 0);
tka->ResizeWidget(HTML_ATTR(hsb),
CORE_ATTR(width) - dx - 2*st,
ATTR_CORE(HTML_ATTR(hsb), height),
ATTR_CORE(HTML_ATTR(hsb), border_width));
/* pageIncrement == sliderSize */
pinc = HTML_ATTR(work_width) - 2*(HTML_ATTR(default_font) ?
HTML_ATTR(default_font)->m_width :
XmHTML_HORIZONTAL_SCROLL_INCREMENT);
/* sanity check */
if(pinc < 1)
pinc = XmHTML_HORIZONTAL_SCROLL_INCREMENT;
/* adjust horizontal scroll if necessary */
if(HTML_ATTR(scroll_x) > HTML_ATTR(formatted_width) - pinc)
HTML_ATTR(scroll_x) = HTML_ATTR(formatted_width) - pinc;
/* fix 01/23/97-02, kdh */
/*
* Adjust if a horizontal scrollbar has been forced
* (can only happen for frames with scrolling = yes)
*/
if(force_hsb && pinc > HTML_ATTR(formatted_width))
{
pinc = HTML_ATTR(formatted_width);
HTML_ATTR(scroll_x) = 0;
}
argc = 0;
XtSetArg(args[argc], XmNminimum, 0); argc++;
XtSetArg(args[argc], XmNmaximum, HTML_ATTR(formatted_width)); argc++;
XtSetArg(args[argc], XmNvalue, HTML_ATTR(scroll_x)); argc++;
XtSetArg(args[argc], XmNsliderSize, pinc); argc++;
XtSetArg(args[argc], XmNincrement, (HTML_ATTR(default_font) ?
HTML_ATTR(default_font)->m_width :
XmHTML_HORIZONTAL_SCROLL_INCREMENT));
argc++;
XtSetArg(args[argc], XmNpageIncrement, pinc); argc++;
XtSetValues(HTML_ATTR(hsb), args, argc);
/* adjust x-position if vsb is on left */
dx = (HTML_ATTR(needs_vsb) && vsb_on_left ? vsb_width : 0);
/* place it */
if(hsb_on_top)
tka->MoveWidget(HTML_ATTR(hsb), dx, 0);
else
tka->MoveWidget(HTML_ATTR(hsb), dx,
(CORE_ATTR(height) - hsb_height));
}
if(HTML_ATTR(needs_vsb) == True)
{
int pinc;
_XmHTMLDebug(1, ("XmHTML.c: _XmHTMLCheckScrollBars, setting vsb\n"));
/* Set vsb size; adjust y-position if we have a hsb */
dy = (HTML_ATTR(needs_hsb) ? hsb_height : 0);
tka->ResizeWidget(HTML_ATTR(vsb),
ATTR_CORE(HTML_ATTR(vsb), width),
CORE_ATTR(height) - dy - 2*st,
ATTR_CORE(HTML_ATTR(vsb), border_width));
/* pageIncrement == sliderSize */
pinc = HTML_ATTR(work_height) - 2*(HTML_ATTR(default_font) ?
HTML_ATTR(default_font)->height : XmHTML_VERTICAL_SCROLL_INCREMENT);
/* sanity check */
if(pinc < 1)
pinc = XmHTML_VERTICAL_SCROLL_INCREMENT;
/* adjust vertical scroll if necessary */
if(HTML_ATTR(scroll_y) > HTML_ATTR(formatted_height) - pinc)
HTML_ATTR(scroll_y) = HTML_ATTR(formatted_height) - pinc;
/*
* Adjust if a vertical scrollbar has been forced
* (can only happen if scrollBarDisplayPolicy == XmSTATIC)
*/
if(force_vsb && pinc > HTML_ATTR(formatted_height))
{
pinc = HTML_ATTR(formatted_height);
HTML_ATTR(scroll_y) = 0;
}
argc = 0;
XtSetArg(args[argc], XmNminimum, 0); argc++;
XtSetArg(args[argc], XmNmaximum, HTML_ATTR(formatted_height)); argc++;
XtSetArg(args[argc], XmNvalue, HTML_ATTR(scroll_y)); argc++;
XtSetArg(args[argc], XmNsliderSize, pinc); argc++;
XtSetArg(args[argc], XmNincrement, (HTML_ATTR(default_font) ?
HTML_ATTR(default_font)->height :
XmHTML_VERTICAL_SCROLL_INCREMENT)); argc++;
XtSetArg(args[argc], XmNpageIncrement, pinc); argc++;
XtSetValues(HTML_ATTR(vsb), args, argc);
/* adjust y-position if hsb is on top */
dy = (HTML_ATTR(needs_hsb) && hsb_on_top ? hsb_height : 0);
/* place it */
if(vsb_on_left)
tka->MoveWidget(HTML_ATTR(vsb), 0, dy);
else
tka->MoveWidget(HTML_ATTR(vsb), (CORE_ATTR(width)- vsb_width), dy);
}
_XmHTMLDebug(1, ("XmHTML.c: _XmHTMLCheckScrollBars, end\n"));
}
/*****
* Name: Mapped
* Return Type: void
* Description: event handler for CreateNotify events.
* In:
* w: owner of this eventhandler
* html: client data, XmHTMLWidget to which w belongs
* event: CreateNotify event data
* Returns:
* nothing
* Note:
* We want to be notified when the window gets created. Motif seems to block
* the CreateNotify event, so we work with the MapNotify event. This is
* required to get the text rendered correctly when it has been
* set inside the Xt[Va]Create[Managed]Widget and before XtRealizeWidget
* has been called: we do not have a window yet and thus no valid gc. Bad
* things happen otherwise.
*****/
/*ARGSUSED*/
static void
Mapped(Widget w, XmHTMLWidget html, XEvent *event)
{
/* wrong event, just return */
if(event->type != MapNotify)
return;
_XmHTMLDebug(1, ("XmHTML.c: Mapped start\n"));
_XmHTMLDebug(1, ("XmHTML.c: Mapped, work area dimensions: %ix%i\n",
HTML_ATTR(work_width), HTML_ATTR(work_height)));
/* store window of *drawingarea* in the toolkit abstraction */
XmHTMLTkaSetDrawable(HTML_ATTR(tka), XtWindow(HTML_ATTR(work_area)));
/* create a gc */
_XmHTMLCheckGC(html);
/* save new height */
HTML_ATTR(work_height) = CORE_ATTR(height);
/* and width as well, fix 10/26/97-01, kdh */
HTML_ATTR(work_width) = CORE_ATTR(width) - HTML_ATTR(margin_width) -
ATTR_CORE(HTML_ATTR(vsb), width);
_XmHTMLDebug(1, ("XmHTML.c: Mapped, new work area dimensions: %ix%i\n",
HTML_ATTR(work_width), HTML_ATTR(work_height)));
/* configure the scrollbars, will also resize work_area */
_XmHTMLCheckScrollBars(html);
_XmHTMLLayout(html);
/* no longer needed now, so remove it */
XtRemoveEventHandler(w, SubstructureNotifyMask, True,
(XtEventHandler)Mapped, (XtPointer)html);
/*****
* IRIX seems to have problems with this. Trigger a Redisplay by
* clearing the entire area.
*****/
#ifdef __sgi
_XmHTMLClearArea(html, 0, 0, CORE_ATTR(width), CORE_ATTR(height));
#endif
_XmHTMLDebug(1, ("XmHTML.c: Mapped end.\n"));
}
/*****
* Name: VisibilityHandler
* Return Type: void
* Description: VisibilityChangeMask event handler. Used to store the
* visibility state of the work_area so we know when to
* serve or ignore GraphicsExpose requests: if we're partially
* obscured we need to respond to them, in all other cases we
* can ignore them.
* In:
* w: owner of this eventhandler
* html: client data, XmHTMLWidget to which w belongs
* event: VisibilityNotify event data
* Returns:
* nothing, but sets the visibility field in the widget's instance structure.
*****/
/*ARGSUSED*/
static void
VisibilityHandler(Widget w, XmHTMLWidget html, XEvent *event)
{
if(event->type != VisibilityNotify)
return;
_XmHTMLDebug(1, ("XmHTML.c: VisibilityHandler start\n"));
HTML_ATTR(visibility) = event->xvisibility.state;
_XmHTMLDebug(1, ("XmHTML.c: VisibilityHandler end\n"));
}
/*****
* Name: _XmHTMLAutoSizeWidget
* Return Type: void
* Description: computes XmHTML's widget dimensions if we have to autosize
* in either direction.
* In:
* html: XmHTMLWidget id
* Returns:
* nothing.
* Note:
* This routine is fairly complicated due to the fact that the dimensions
* of the work area are partly determined by the presence of possible
* scrollbars.
*****/
void
_XmHTMLAutoSizeWidget(XmHTMLWidget html)
{
int max_w, max_h, width, height, core_w, core_h;
int hsb_height = 0, vsb_width = 0, h_reserved, w_reserved;
Boolean done = False, granted = False, has_vsb = False, has_hsb = False;
Dimension new_h, new_w, width_return, height_return;
ToolkitAbstraction *tka = HTML_ATTR(tka);
/* get dimensions of the scrollbars */
_XmHTMLGetScrollDim(html, &hsb_height, &vsb_width);
/* maximum allowable widget height: 80% of screen height */
max_h = (int)(0.8*tka->height);
/* make a guess at the initial widget width */
max_w = _XmHTMLGetMaxLineLength(html) + 2*HTML_ATTR(margin_width);
/* save original widget dimensions in case our resize request is denied */
core_w = CORE_ATTR(width);
core_h = CORE_ATTR(height);
/* set initial dimensions */
height = (core_h > max_h ? max_h : core_h);
width = max_w;
/*
* Since we are making geometry requests, we need to compute the total
* width and height required to make all text visible.
* If we succeed, we don't require any scrollbars to be present.
* This does complicate things considerably.
* The dimensions of the work area are given by the widget dimensions
* minus possible margins and possible scrollbars.
*/
h_reserved = HTML_ATTR(margin_height) + hsb_height;
w_reserved = 2*HTML_ATTR(margin_width) + vsb_width;
do
{
/* work_width *always* includes room for a vertical scrollbar */
HTML_ATTR(work_width) = width - w_reserved;
/* Check if we need to add a vertical scrollbar. */
if(height - h_reserved > max_h)
has_vsb = True;
else /* no vertical scrollbar needed */
has_vsb = False;
_XmHTMLDebug(1, ("XmHTML.c: autoSizeWidget, initial dimension: "
"%ix%i. has_vsb: %s\n", width, height,
has_vsb ? "yes" : "no"));
/* Compute new screen layout. */
_XmHTMLComputeLayout(html);
/*
* We have made a pass on the document, so we know now the formatted
* dimensions. If the formatted width exceeds the maximum allowable
* width, we need to add a horizontal scrollbar, and if the formatted
* height exceeds the maximum allowable height we need to add a
* vertical scrollbar. Order of these checks is important: if a vertical
* scrollbar is present, the width of the vertical scrollbar must be
* added as well.
* formatted_height includes the vertical margin twice.
* formatted_width includes the horizontal margin once.
*/
/* higher than available height, need a vertical scrollbar */
if(HTML_ATTR(formatted_height) > max_h)
{
has_vsb = True;
height = max_h;
}
else
{
has_vsb = False;
height = HTML_ATTR(formatted_height);
}
/* wider than available width, need a horizontal scrollbar */
if(HTML_ATTR(formatted_width) + HTML_ATTR(margin_width) > max_w)
{
has_hsb = True;
width = max_w;
}
else
{
has_hsb = False;
width = HTML_ATTR(formatted_width) + HTML_ATTR(margin_width);
}
/* add width of vertical scrollbar if we are to have one */
if(has_vsb)
width += vsb_width;
/*
* With the above checks we *know* width and height are positive
* integers smaller than 2^16 (max value of an unsigned short), so we
* don't have to check for a possible wraparound of the new dimensions.
*/
new_h = (Dimension)height;
new_w = (Dimension)width;
width_return = 0;
height_return = 0;
_XmHTMLDebug(1, ("XmHTML.c: autoSizeWidget, geometry request with "
"dimensions: %hix%hi. has_vsb = %s, has_hsb = %s\n", new_w, new_h,
has_vsb ? "yes" : "no", has_hsb ? "yes" : "no"));
/* make the resize request and check return value */
switch(XtMakeResizeRequest((Widget)html, new_w, new_h,
&width_return, &height_return))
{
case XtGeometryAlmost:
/*
* partially granted. Set the returned width and height
* as the new widget dimensions and recompute the
* widget layout. The next time the resizeRequest is made
* it *will* be granted.
*/
width = (int)width_return;
height= (int)height_return;
break;
case XtGeometryNo:
/* revert to original widget dimensions */
new_h = core_h;
new_w = core_w;
granted = False;
done = True;
break;
case XtGeometryYes:
/* Resize request was granted. */
granted = True;
done = True;
break;
default: /* not reached, XtGeometryDone is never returned */
done = True;
break;
}
}
while(!done);
CORE_ATTR(width) = new_w;
CORE_ATTR(height) = HTML_ATTR(work_height) = new_h;
/* work_width *always* includes room for a vertical scrollbar */
HTML_ATTR(work_width) = new_w - w_reserved;
/* Make sure scrollbars don't appear when they are not needed. */
if(!has_hsb && granted)
HTML_ATTR(formatted_height) = new_h - HTML_ATTR(margin_height) -
hsb_height - 1;
if(!has_vsb && granted)
HTML_ATTR(formatted_width) = new_w - 1;
/*
* If a vertical scrollbar is present, CheckScrollBars will add a horizontal
* scrollbar if the formatted_width + vsb_width exceeds the widget width.
* To make sure a horizontal scrollbar does not appear when one is not
* needed, we need to adjust the formatted width accordingly.
*/
if(has_vsb && granted)
HTML_ATTR(formatted_width) -= vsb_width;
/*
* If our resize request was denied we need to recompute the text
* layout using the original widget dimensions. The previous layout is
* invalid since it used guessed widget dimensions instead of the previous
* dimensions and thus it will look bad if we don't recompute it.
*/
if(!granted)
_XmHTMLComputeLayout(html);
_XmHTMLDebug(1, ("XmHTML.c: autoSizeWidget, results:\n"
"\tRequest granted: %s\n"
"\tcore height = %i, core width = %i, work_width = %i\n"
"\tformatted_width = %i, formatted_height = %i.\n"
"\thas_vsb = %s, has_hsb = %s\n",
granted ? "yes" : "no",
CORE_ATTR(height), CORE_ATTR(width), HTML_ATTR(work_width),
HTML_ATTR(formatted_width), HTML_ATTR(formatted_height),
has_vsb ? "yes" : "no", has_hsb ? "yes" : "no"));
}
/*****
* Name: DrawRedisplay
* Return Type: void
* Description: Eventhandler for exposure events on the work_area
* In:
* w: owner of this eventhandler
* html: client data, XmHTMLWidget to which w belongs
* event: expose event data.
* Returns:
* nothing
* Note:
* This routine makes a rough guess on which ObjectTable elements
* should be used as vertical start and end points for the paint engine.
* Finetuning is done by the DrawText routine in paint.c, which uses
* the paint_x, paint_y, paint_width and paint_height fields in the
* htmlRec to determine what should be painted exactly.
*****/
void
_XmHTMLDrawRedisplay(Widget w, XmHTMLWidget html, XEvent *event)
{
/*
* must use int for y-positions. The Position and Dimension typedefs
* are shorts, which may produce bad results if the scrolled position
* exceeds the size of a short
*/
int y1, y2, height, x1, x2, width;
XEvent expose;
_XmHTMLDebug(1, ("XmHTML.c: DrawRedisplay Start\n"));
/*****
* No needless exposures. Kick out graphics exposures, I don't know
* who invented these, sure as hell don't know what to do with them...
*
* Update August 26: I do know now what to do with these suckers:
* they are generated whenever a XCopyArea or XCopyPlane request couldn't
* be completed 'cause the destination area is (partially) obscured.
* This happens when some other window is placed over our display area.
* So when we get a GraphicsExpose event, we check our visibility state
* and only draw something when we are partially obscured: when we are
* fully visibile we won't get any GraphicsExpose events, and when we
* are fully obscured we won't even get Expose Events.
* The reason behind all of this are the images & anchor drawing: sometimes
* they overlap an already painted area, and drawing will then generate
* a GraphicsExpose, which in turn will trigger a redisplay of these anchors
* and then it starts all over again. Ergo: bad screen flickering. And we
* DO NOT want this.
*****/
if(((event->xany.type != Expose) && (event->xany.type != GraphicsExpose))
|| HTML_ATTR(formatted) == NULL || HTML_ATTR(nframes))
{
/* display scrollbars if we are in a frame */
if(HTML_ATTR(is_frame))
_XmHTMLSetScrollBars(html);
_XmHTMLDebug(1, ("XmHTML.c: DrawRedisplay End: wrong event "
"(%i).\n", event->xany.type));
return;
}
if(event->xany.type == GraphicsExpose &&
HTML_ATTR(visibility) != VisibilityPartiallyObscured &&
!HTML_ATTR(form_data))
{
_XmHTMLDebug(1, ("XmHTML.c: DrawRedisplay End: bad GraphicsExpose, "
"window not partially obscured.\n"));
return;
}
x1 = event->xexpose.x;
y1 = event->xexpose.y;
width = event->xexpose.width;
height = event->xexpose.height;
x2 = x1 + width;
_XmHTMLDebug(1, ("XmHTML.c: DrawRedisplay, y-position of region: %i, "
"height of region: %i\n", y1, height));
_XmHTMLDebug(1, ("XmHTML.c: DrawRedisplay, event type: %s\n",
event->xany.type == Expose ? "Expose" : "GraphicsExpose"));
_XmHTMLDebug(1, ("XmHTML.c: DrawRedisplay %i Expose events waiting.\n",
event->xexpose.count));
/*
* coalesce multiple expose events into one.
*/
while((XCheckWindowEvent(XtDisplay(w), XtWindow(w), ExposureMask,
&expose)) == True)
{
int dx, dy, dh, dw;
/*****
* GraphicsExpose events are only honored when we are partially
* obscured.
*****/
if(expose.xany.type == NoExpose ||
(event->xany.type == GraphicsExpose &&
HTML_ATTR(visibility) != VisibilityPartiallyObscured))
continue;
dx = expose.xexpose.x;
dy = expose.xexpose.y;
dw = expose.xexpose.width;
dh = expose.xexpose.height;
_XmHTMLDebug(1, ("XmHTML.c: DrawRedisplay, next event, geometry of "
"exposed region: %ix%i:%i,%i\n", dx, dy, dw, dh));
/* right side of region */
x2 = x1 + width;
/* leftmost x-position of exposure region */
if(x1 > dx)
x1 = dx;
/* rightmost x-position of exposure region */
if(x2 < (dx + dw))
x2 = dx + dw;
/* width of exposure region */
width = x2 - x1;
/* bottom of region */
y2 = y1 + height;
/* topmost y-position of exposure region */
if(y1 > dy)
y1 = dy;
/* bottommost y-position of exposure region */
if(y2 < (dy + dh))
y2 = dy + dh;
/* height of exposure region */
height = y2 - y1;
}
_XmHTMLDebug(1, ("XmHTML.c: DrawRedisplay, total region geometry: "
"%ix%i:%i,%i.\n", x1, y1, width, height));
_XmHTMLRefresh(html, x1, y1, width, height);
_XmHTMLDebug(1, ("XmHTML.c: DrawRedisplay End\n"));
}
/*****
* Name: Redisplay
* Return Type: void
* Description: xmHTMLWidgetClass expose method.
* In:
* w: widget to expose
* event: description of event that triggered an expose
* region: region to display.
* Returns:
* nothing
*****/
static void
Redisplay(Widget w, XEvent *event, Region region)
{
_XmHTMLDebug(1, ("XmHTML.c: Redisplay Start\n"));
/* Pass exposure events down to the children */
_XmRedisplayGadgets(w, (XEvent*)event, region);
_XmHTMLDebug(1, ("XmHTML.c: Redisplay End\n"));
return;
}
/*****
* Name: SetValues
* Return Type: Boolean
* Description: xmHTMLWidgetClass SetValues method.
* In:
* current: copy of widget before any set_values methods are called
* request: copy of widget after resources have changed but before any
* set_values methods are called
* set: widget with resources set and as modified by any superclass
* methods that have called XtSetValues()
* args: argument list passed to XtSetValues, done by programmer
* num_args: no of args
* Returns:
* True if a changed resource requires a redisplay, False otherwise.
*****/
static Boolean
SetValues(Widget current, Widget request, Widget set,
ArgList args, Cardinal *num_args)
{
XmHTMLWidget w_curr = (XmHTMLWidget)current;
XmHTMLWidget w_req = (XmHTMLWidget)request;
XmHTMLWidget w_new = (XmHTMLWidget)set;
Boolean redraw = False, parse = False;
Boolean need_reformat = False;
Boolean need_layout = False;
Boolean free_images = False;
unsigned long event_to_check = 0L;
/* fix 06/17/97-01, aj */
int i;
int valueReq = False;
_XmHTMLDebug(1, ("XmHTML.c: SetValues Start\n"));
/*****
* Note on processing of the onLoad/onUnload events.
* For the onLoad event, the spec states the following:
* ``The onload event occurs when the user agent finished loading a
* window or all frames within a frameset''.
* Therefore the onLoad event will be the last action to be carried
* out when a new source has been supplied.
*
* For the onUnload event: the spec doesn't state when this event
* should be executed. We take the easy way out and execute this event
* right before the document is unloaded.
*****/
#ifdef DEBUG
if(ATTR_HTML(w_req, debug_levels) != ATTR_HTML(w_curr, debug_levels))
{
_XmHTMLSelectDebugLevels(ATTR_HTML(w_req, debug_levels));
ATTR_HTML(w_new, debug_levels) = ATTR_HTML(w_req, debug_levels);
}
_XmHTMLSetFullDebug(ATTR_HTML(w_req, debug_full_output));
if(ATTR_HTML(w_req, debug_disable_warnings))
debug_disable_warnings = True;
else
debug_disable_warnings = False;
#endif
/*****
* We always use a copy of the HTML source text that is set into
* the widget to prevent a crash when the user has freed it before we
* had a chance of parsing it, and we ensure new text will get set
* properly.
*
* fix 06/17/97-01, aj
* Patch to fix clearing if doing setvalues without XmNvalue
* Determine if we have a set value request and only check new source
* if it has been supplied explicitly.
*
* Addition 10/10/97, kdh: changing the palette at run-time is *never*
* allowed.
*****/
for(i = 0; i < *num_args; i++)
{
if(!strcmp(XmNvalue, args[i].name))
valueReq = True;
/* Check for read-only resources */
if(!strcmp(XmNimagePalette, args[i].name) ||
!strcmp(XmNhorizontalScrollBar, args[i].name) ||
!strcmp(XmNverticalScrollBar, args[i].name) ||
!strcmp(XmNworkWindow, args[i].name))
{
_XmHTMLWarning(__WFUNC__(w_curr, "SetValues"), XMHTML_MSG_12,
args[i].name);
return(False);
}
}
/* we have a new source request */
if(valueReq)
{
/* we had a previous source */
if(ATTR_HTML(w_curr, source))
{
/* new text has been supplied */
if(ATTR_HTML(w_req, value))
{
/* see if it differs */
if(strcmp(ATTR_HTML(w_req, value), ATTR_HTML(w_curr, source)))
{
parse = True; /* it does */
/* free previous source text */
free(ATTR_HTML(w_curr, source));
/* copy new source text */
ATTR_HTML(w_new, source) = strdup(ATTR_HTML(w_req, value));
/* Required to do both onLoad and onUnload events */
event_to_check = EVENT_LOAD | EVENT_UNLOAD;
}
else
parse = False; /* it doesn't */
}
else /* have to clear current text */
{
parse = True;
/* free previous source text */
free(ATTR_HTML(w_curr, source));
/* reset to NULL */
ATTR_HTML(w_new, source) = NULL;
/* Required to check onUnLoad event */
event_to_check = EVENT_UNLOAD;
}
}
else /* we didn't have any source */
{
if(ATTR_HTML(w_req, value))
{
/* new text */
parse = True;
/* copy new source text */
ATTR_HTML(w_new, source) = strdup(ATTR_HTML(w_req, value));
/* Required to check onLoad event */
event_to_check = EVENT_LOAD;
}
else
parse = False; /* still empty */
}
/* input is always complete */
ATTR_HTML(w_new, input_complete) = True;
}
/*****
* Whoa!! String direction changed!!! All text will be reversed
* and default alignment changes to the other margin as well.
* Needs full reformat as this changes things profoundly...
* This requires a full reparsing of the document data as string reversal
* is done at the lowest possible level: in the parser.
*****/
if(ATTR_HTML(w_req,string_direction) != ATTR_HTML(w_curr,string_direction))
{
parse = True;
/* check for alignment */
CheckAlignment(w_new, w_req);
}
/*****
* Enabling/disabling icon entity support requires a complete reparsing
* of the input as the icons are translated at parse-time.
*****/
if(ATTR_HTML(w_req, icon_entities_enabled) !=
ATTR_HTML(w_curr, icon_entities_enabled))
{
parse = True;
}
/*****
* Check if vertical icon alignment has changed. Same note as with
* enabling/disabling icon entities applies here as well.
*****/
if(ATTR_HTML(w_req, icon_valign) != ATTR_HTML(w_curr, icon_valign))
{
/* verify new value */
if(!XmRepTypeValidValue(icon_repid, ATTR_HTML(w_req, icon_valign),
(Widget)w_req))
ATTR_HTML(w_new, icon_valign) = ATTR_HTML(w_curr, icon_valign);
else
/*****
* Reparsing only required if support for icon entities is
* enabled.
*****/
parse = ATTR_HTML(w_req, icon_entities_enabled);
}
if(parse)
{
_XmHTMLDebug(1, ("XmHTML.c: SetValues, parsing new text\n"));
/* Check if we have to execute the onUnload event */
if((event_to_check & EVENT_UNLOAD) &&
ATTR_HTML(w_curr, event_mask) & EVENT_UNLOAD)
{
/*****
* Event processing of the onUnload event can *never*
* modify the document content. EventProcess explicitly
* *exits* if it does happen.
*****/
_XmHTMLEventProcess(w_curr, NULL,
ATTR_HTML(w_curr, body_events)->onUnload);
}
/* clear the unload bit */
event_to_check &= ~EVENT_UNLOAD;
/* new text has been set, kill of any existing PLC's */
_XmHTMLKillPLCCycler(w_curr);
/* release event database */
_XmHTMLEventFreeDatabase(w_curr, w_new);
/* destroy any form data */
_XmHTMLFreeForm(w_curr, ATTR_HTML(w_curr, form_data));
ATTR_HTML(w_curr, form_data) = (XmHTMLFormData*)NULL;
ATTR_HTML(w_new, form_data) = (XmHTMLFormData*)NULL;
/*****
* Destroy any external object data inside frames before new
* ones are created.
*****/
#ifdef HAVE_EXTERNAL_OBJECTS
_XmHTMLFrameDestroyExternalObjects(w_curr);
_XmHTMLDestroyExternalObjects(w_curr);
#endif
/* Parse the raw HTML text */
ATTR_HTML(w_new, elements) = _XmHTMLparseHTML(w_req,
ATTR_HTML(w_curr, elements), ATTR_HTML(w_req, value), w_new);
/* reset topline */
ATTR_HTML(w_new, top_line) = 0;
/* keep current frame setting and check if new frames are allowed */
ATTR_HTML(w_new, is_frame) = ATTR_HTML(w_curr, is_frame);
ATTR_HTML(w_new, nframes) = _XmHTMLCheckForFrames(w_new,
ATTR_HTML(w_new, elements));
/* Trigger link callback */
if(ATTR_HTML(w_new, link_callback))
_XmHTMLLinkCallback(w_new);
/* needs layout, a redraw and current images must be freed */
need_reformat = True;
redraw = True;
free_images = True;
_XmHTMLDebug(1, ("XmHTML.c: SetValues, done parsing\n"));
}
if((ATTR_HTML(w_req, enable_outlining)
!= ATTR_HTML(w_curr, enable_outlining)) ||
(ATTR_HTML(w_req, alignment) != ATTR_HTML(w_curr, alignment)))
{
/* Needs full reformat, default alignment is a text property */
CheckAlignment(w_new, w_req);
need_reformat = True;
}
/*****
* Check if tabwidth has been changed. Always needs a recomputation
* of the layout since we don't know if the current text contains
* preformatted text or not.
*****/
if(ATTR_HTML(w_req, tabwidth) != ATTR_HTML(w_curr, tabwidth))
{
/*****
* tabwidth must be a positive, non-zero number.
* If not, issue a warning and keep the current tabwidth.
*****/
if(ATTR_HTML(w_req, tabwidth) < 1)
{
_XmHTMLWarning(__WFUNC__(w_req, "SetValues"), XMHTML_MSG_9,
"XmNtabWidth", ATTR_HTML(w_req, tabwidth),
ATTR_HTML(w_curr, tabwidth));
ATTR_HTML(w_new, tabwidth) = ATTR_HTML(w_curr, tabwidth);
}
else
need_reformat = True;
}
/*****
* see if fonts have changed. The bloody problem with resources of type
* String is that it's very well possible that a user is using some
* static space to store these things. In these cases, the simple
* comparisons are bound to be True every time, even though the content
* might have changed (which we won't see cause it's all in static user
* space!!), so to catch changes to this type of resources, we *MUST*
* scan the array of provided args to check if it's specified. Sigh.
*****/
valueReq = False;
for(i = 0; i < *num_args; i++)
{
if(!strcmp(XmNcharset, args[i].name) ||
!strcmp(XmNfontFamily, args[i].name) ||
!strcmp(XmNfontFamilyFixed, args[i].name) ||
!strcmp(XmNfontSizeFixedList, args[i].name) ||
!strcmp(XmNfontSizeList, args[i].name))
valueReq = True;
}
if(valueReq ||
ATTR_HTML(w_req, font_sizes) != ATTR_HTML(w_curr, font_sizes) ||
ATTR_HTML(w_req, font_family) != ATTR_HTML(w_curr, font_family) ||
ATTR_HTML(w_req, font_sizes_fixed) != ATTR_HTML(w_curr, font_sizes_fixed) ||
ATTR_HTML(w_req, font_family_fixed)!= ATTR_HTML(w_curr, font_family_fixed)||
ATTR_HTML(w_req, charset) != ATTR_HTML(w_curr, charset))
{
/* reset font cache */
ATTR_HTML(w_new, default_font) = _XmHTMLSelectFontCache(w_new, True);
need_reformat = True;
}
/*
* Body colors. Original body colors are restored when body colors are
* disabled.
*/
if(ATTR_HTML(w_req, body_colors_enabled)
!= ATTR_HTML(w_curr, body_colors_enabled))
{
/* restore original body colors */
if(!ATTR_HTML(w_req, body_colors_enabled))
{
ATTR_HTML(w_new, body_fg) = ATTR_HTML(w_req, body_fg_save);
ATTR_HTML(w_new, body_bg) = ATTR_HTML(w_req, body_bg_save);
ATTR_HTML(w_new, anchor_fg) = ATTR_HTML(w_req, anchor_fg_save);
ATTR_HTML(w_new, anchor_visited_fg) =
ATTR_HTML(w_req, anchor_visited_fg_save);
ATTR_HTML(w_new, anchor_activated_fg) =
ATTR_HTML(w_req, anchor_activated_fg_save);
/* recompute top, bottom & highlight colors */
XmHTMLTkaRecomputeColors(w_new, ATTR_HTML(w_new, body_bg));
}
need_reformat = True;
}
/*
* Colors. For now we redo the layout since all colors are stored
* in the ObjectTable data.
* Not that effective, perhaps use multiple GC's, but thats a lot of
* resource consuming going on then...
*/
if((ATTR_MGR(w_req,foreground) !=
ATTR_MGR(w_curr, foreground)) ||
(ATTR_CORE(w_req, background_pixel) !=
ATTR_CORE(w_curr, background_pixel)) ||
(ATTR_HTML(w_req, anchor_fg) !=
ATTR_HTML(w_curr, anchor_fg)) ||
(ATTR_HTML(w_req, anchor_target_fg) !=
ATTR_HTML(w_curr, anchor_target_fg)) ||
(ATTR_HTML(w_req, anchor_visited_fg) !=
ATTR_HTML(w_curr, anchor_visited_fg)) ||
(ATTR_HTML(w_req, anchor_activated_fg) !=
ATTR_HTML(w_curr, anchor_activated_fg)) ||
(ATTR_HTML(w_req, anchor_activated_bg) !=
ATTR_HTML(w_curr, anchor_activated_bg)))
{
/* back and foreground pixels */
ATTR_MGR(w_new, foreground) =
ATTR_MGR(w_req, foreground);
ATTR_CORE(w_new, background_pixel) =
ATTR_CORE(w_req, background_pixel);
ATTR_HTML(w_new, body_fg) =
ATTR_MGR(w_new, foreground);
ATTR_HTML(w_new, body_bg) =
ATTR_CORE(w_new, background_pixel);
ATTR_HTML(w_new, anchor_fg) =
ATTR_HTML(w_req, anchor_fg);
ATTR_HTML(w_new, anchor_target_fg) =
ATTR_HTML(w_req, anchor_target_fg);
ATTR_HTML(w_new, anchor_visited_fg) =
ATTR_HTML(w_req, anchor_visited_fg);
ATTR_HTML(w_new, anchor_activated_fg) =
ATTR_HTML(w_req, anchor_activated_fg);
ATTR_HTML(w_new, anchor_activated_bg) =
ATTR_HTML(w_req, anchor_activated_bg);
/* save as new default colors */
ATTR_HTML(w_new, body_fg_save) =
ATTR_HTML(w_new, body_fg);
ATTR_HTML(w_new, body_bg_save) =
ATTR_HTML(w_new, body_bg);
ATTR_HTML(w_new, anchor_fg_save) =
ATTR_HTML(w_new, anchor_fg);
ATTR_HTML(w_new, anchor_target_fg_save) =
ATTR_HTML(w_new, anchor_target_fg);
ATTR_HTML(w_new, anchor_visited_fg_save) =
ATTR_HTML(w_new, anchor_visited_fg);
ATTR_HTML(w_new, anchor_activated_fg_save) =
ATTR_HTML(w_new, anchor_activated_fg);
ATTR_HTML(w_new, anchor_activated_bg_save) =
ATTR_HTML(w_new, anchor_activated_bg);
/* get new values for top, bottom & highlight colors */
XmHTMLTkaRecomputeColors(w_new, ATTR_HTML(w_new, body_bg));
need_reformat = True;
}
/*
* anchor highlighting, must invalidate any current selection
* No need to do a redraw if the highlightcolor changes: since the
* SetValues method is chained, Manager's SetValues takes care of that.
*/
if(ATTR_HTML(w_req, highlight_on_enter) !=
ATTR_HTML(w_curr, highlight_on_enter))
ATTR_HTML(w_new, armed_anchor) = (XmHTMLObjectTable*)NULL;
/*
* anchor underlining. Also needs a full layout computation as
* underlining data is stored in the ObjectTable data
*/
if( (ATTR_HTML(w_req, anchor_underline_type) !=
ATTR_HTML(w_curr, anchor_underline_type)) ||
(ATTR_HTML(w_req, anchor_visited_underline_type) !=
ATTR_HTML(w_curr, anchor_visited_underline_type)) ||
(ATTR_HTML(w_req, anchor_target_underline_type) !=
ATTR_HTML(w_curr, anchor_target_underline_type)))
{
CheckAnchorUnderlining(w_new, w_req);
need_reformat = True;
}
else
{
/*
* Support for color & font attributes. Needs a redo of the layout
* if changed. We only need to check for this if the above test
* failed as that will also trigger a redo of the layout.
*/
if(ATTR_HTML(w_req, allow_color_switching) !=
ATTR_HTML(w_curr, allow_color_switching) ||
ATTR_HTML(w_req, allow_font_switching) !=
ATTR_HTML(w_curr, allow_font_switching))
need_reformat = True;
}
/*
* on-the-fly enable/disable of dithering.
*/
if(ATTR_HTML(w_req, map_to_palette) != ATTR_HTML(w_curr, map_to_palette))
{
/* from on to off or off to on */
if(ATTR_HTML(w_curr, map_to_palette) == XmDISABLED ||
ATTR_HTML(w_req, map_to_palette) == XmDISABLED)
{
/* free current stuff */
XCCFree(ATTR_HTML(w_curr, xcc));
/* and create a new one */
ATTR_HTML(w_new, xcc) = NULL;
_XmHTMLCheckXCC(w_new);
/* add palette if necessary */
if(ATTR_HTML(w_req, map_to_palette) != XmDISABLED)
_XmHTMLAddPalette(w_new);
}
else
{
/* fast & best methods require precomputed error matrices */
if(ATTR_HTML(w_req, map_to_palette) == XmBEST ||
ATTR_HTML(w_req, map_to_palette) == XmFAST)
{
XCCInitDither(ATTR_HTML(w_new, xcc));
}
else
XCCFreeDither(ATTR_HTML(w_new, xcc));
}
/* and in *all* cases we need a full reformat */
need_reformat = True;
}
/*
* maximum amount of allowable image colors. Needs a full redo
* of the layout if the current doc has got images with more colors
* than allowed or it has images which have been dithered to fit
* the previous setting.
*/
if((ATTR_HTML(w_req, max_image_colors) !=
ATTR_HTML(w_curr, max_image_colors)))
{
_XmHTMLCheckMaxColorSetting(w_new);
/*
* check if we have any images with more colors than allowed or
* we had images that were dithered. If so we need to redo the layout
*/
if(!need_reformat)
{
XmHTMLImage *image;
int prev_max = ATTR_HTML(w_curr, max_image_colors);
int new_max = ATTR_HTML(w_req, max_image_colors);
for(image = ATTR_HTML(w_new, images); image != NULL && !free_images;
image = image->next)
{
/* ImageInfo is still available. Compare against it */
if(!ImageInfoFreed(image))
{
/*
* redo image composition if any of the following
* conditions is True:
* - current image has more colors than allowed;
* - current image has less colors than allowed but the
* original image had more colors than allowed previously.
*/
if(image->html_image->ncolors > new_max ||
(image->html_image->scolors < new_max &&
image->html_image->scolors > prev_max))
free_images = True;
}
/* info no longer available. Check against allocated colors */
else
if(image->npixels > new_max)
free_images = True;
}
/* need to redo the layout if we are to redo the images */
need_reformat = free_images;
}
}
/* Are images enabled? */
if(ATTR_HTML(w_req, images_enabled) != ATTR_HTML(w_curr, images_enabled))
{
/*****
* we always need to free the images if this changes. A full
* layout recomputation will load all images.
*****/
free_images = True;
need_reformat = True;
}
/* PLC timing intervals */
if(ATTR_HTML(w_req, plc_min_delay) != ATTR_HTML(w_curr, plc_min_delay) ||
ATTR_HTML(w_req, plc_max_delay) != ATTR_HTML(w_curr, plc_max_delay) ||
ATTR_HTML(w_req, plc_delay) != ATTR_HTML(w_curr, plc_def_delay))
_XmHTMLPLCCheckIntervals(w_new);
/*****
* Now format the list of parsed objects.
* Don't do a bloody thing if we are already in layout as this will
* cause unnecessary reloading and screen flickering.
*****/
if(need_reformat && !ATTR_HTML(w_curr, in_layout))
{
_XmHTMLDebug(1, ("XmHTML.c: SetValues, need layout\n"));
/*****
* It the current document makes heavy use of images we first need
* to clear it. Not doing this would cause a shift in the colors of
* the current document (as they are being released) which does not
* look nice. Therefore first clear the entire display* area *before*
* freeing anything at all.
*****/
if(ATTR_HTML(w_new, gc) != NULL)
{
ATTR_HTML(w_curr, tka)->ClearArea(ATTR_HTML(w_new, tka)->dpy,
ATTR_HTML(w_new, tka)->win, 0, 0,
ATTR_CORE(w_new, width), ATTR_CORE(w_new, height), False);
}
/* destroy any form data */
_XmHTMLFreeForm(w_curr, ATTR_HTML(w_curr, form_data));
ATTR_HTML(w_new, form_data) = (XmHTMLFormData*)NULL;
/*****
* Destroy any external object data inside frames before new
* ones are created.
*****/
#ifdef HAVE_EXTERNAL_OBJECTS
_XmHTMLFrameDestroyExternalObjects(w_curr);
_XmHTMLDestroyExternalObjects(w_curr);
#endif
/* Free all non-persistent resources */
_XmHTMLFreeExpendableResources(w_curr, free_images);
/* reset some important vars */
_XmHTMLReset(w_new, free_images);
/* check for an xcc, it might have been destroyed by now */
if(free_images)
_XmHTMLCheckXCC(w_new);
/* get new values for top, bottom & highlight */
XmHTMLTkaRecomputeColors(w_new, ATTR_HTML(w_new, body_bg));
/* go and format the parsed HTML data */
if(!_XmHTMLCreateFrames(w_curr, w_new))
{
ATTR_HTML(w_new, frames) = NULL;
ATTR_HTML(w_new, nframes) = 0;
/* keep current frame setting */
ATTR_HTML(w_new, is_frame) = ATTR_HTML(w_curr, is_frame);
}
_XmHTMLformatObjects(w_curr, w_new);
/* Check for the onload event */
if(ATTR_HTML(w_new, event_mask) & EVENT_LOAD)
{
/*****
* Check event return value. If it returns True the document
* has changed from under us!
*****/
if(_XmHTMLEventProcess(w_new, NULL,
ATTR_HTML(w_new, body_events)->onLoad))
return(False);
}
/* and check for possible external imagemaps */
_XmHTMLCheckImagemaps(w_new);
_XmHTMLDebug(1, ("XmHTML.c: SetValues, computing new layout.\n"));
/* compute new screen layout */
_XmHTMLLayout(w_new);
_XmHTMLDebug(1, ("XmHTML.c: SetValues, done with layout.\n"));
/* if new text has been set, fire up the PLCCycler */
if(parse)
{
ATTR_HTML(w_new, plc_suspended) = False;
_XmHTMLPLCCycler((XtPointer)w_new , NULL);
}
free_images = False;
redraw = True;
need_layout = False;
}
/*****
* Default background image changed. We don't need to do this when a
* layout recomputation was required as it will have been taken care
* of already.
*****/
else if
(ATTR_HTML(w_req, body_images_enabled) !=
ATTR_HTML(w_curr, body_images_enabled) ||
ATTR_HTML(w_req, def_body_image_url) !=
ATTR_HTML(w_curr, def_body_image_url))
{
/* check if body images display status is changed */
if(ATTR_HTML(w_req, body_images_enabled) !=
ATTR_HTML(w_curr, body_images_enabled))
{
if(!free_images && ATTR_HTML(w_curr, body_image))
ATTR_HTML(w_curr, body_image)->options |= IMG_ORPHANED;
ATTR_HTML(w_new, body_image) = NULL;
}
/* a new body image has been specified, check it */
if(ATTR_HTML(w_req, def_body_image_url) !=
ATTR_HTML(w_curr, def_body_image_url))
{
/* do we have a new image? */
if(ATTR_HTML(w_req, def_body_image_url))
{
/* yes we do */
ATTR_HTML(w_new, def_body_image_url) =
strdup(ATTR_HTML(w_req, def_body_image_url));
}
else /* no we don't */
ATTR_HTML(w_new, def_body_image_url) = NULL;
/* did we have a previous image? */
if(ATTR_HTML(w_curr, def_body_image_url))
{
/* we did, free it */
free(ATTR_HTML(w_curr, def_body_image_url));
/* make it an orphan */
if(!free_images && ATTR_HTML(w_curr, body_image))
ATTR_HTML(w_curr, body_image)->options |= IMG_ORPHANED;
}
}
/*
* only load background image if image support is enabled and if
* we are instructed to show a background image.
*/
if(ATTR_HTML(w_req, images_enabled) &&
ATTR_HTML(w_req, body_images_enabled))
{
/* current document has a background image of it's own. */
if(ATTR_HTML(w_new, body_image_url))
_XmHTMLLoadBodyImage(w_new, ATTR_HTML(w_new, body_image_url));
/*
* Only load the default background image if the doc didn't have
* it's colors changed.
*/
else if(ATTR_HTML(w_new, def_body_image_url) &&
ATTR_HTML(w_new, body_fg) ==
ATTR_HTML(w_new, body_fg_save) &&
ATTR_HTML(w_new, body_bg) ==
ATTR_HTML(w_new, body_bg_save) &&
ATTR_HTML(w_new, anchor_fg) ==
ATTR_HTML(w_new, anchor_fg_save) &&
ATTR_HTML(w_new, anchor_visited_fg) ==
ATTR_HTML(w_new, anchor_visited_fg_save) &&
ATTR_HTML(w_new, anchor_activated_fg) ==
ATTR_HTML(w_new, anchor_activated_fg_save))
_XmHTMLLoadBodyImage(w_new,
ATTR_HTML(w_new, def_body_image_url));
}
/*****
* When a body image is present it is very likely that a highlight
* color based upon the current background actually makes an anchor
* invisible when highlighting is selected. Therefore we base the
* highlight color on the activated anchor background when we have a
* body image, and on the document background when no body image is
* present.
*****/
if(ATTR_HTML(w_new, body_image))
XmHTMLTkaRecomputeHighlightColor(w_new,
ATTR_HTML(w_new, anchor_activated_fg));
else
XmHTMLTkaRecomputeHighlightColor(w_new, ATTR_HTML(w_new, body_bg));
/* only redraw if the new body image differs from the old one */
if(ATTR_HTML(w_new, body_image) != ATTR_HTML(w_curr, body_image))
{
/* set alpha channel processing if not yet done */
free_images = !parse && !need_reformat;
redraw = True;
}
}
/* anchor button state */
if((ATTR_HTML(w_req, anchor_buttons) != ATTR_HTML(w_curr, anchor_buttons)))
redraw = True;
/*****
* cursor state changes. Note that we always free the current cursor,
* even if it's created by the user.
*****/
if((ATTR_HTML(w_req, anchor_cursor) != ATTR_HTML(w_curr, anchor_cursor)) ||
(ATTR_HTML(w_req, anchor_display_cursor) !=
ATTR_HTML(w_curr, anchor_display_cursor)))
{
/* set cursor to None if we don't have to use or have a cursor */
if(!ATTR_HTML(w_new, anchor_display_cursor) ||
!ATTR_HTML(w_new, anchor_cursor))
{
if(ATTR_HTML(w_curr, anchor_cursor) != None)
XFreeCursor(XtDisplay((Widget)w_curr),
ATTR_HTML(w_curr, anchor_cursor));
ATTR_HTML(w_new, anchor_cursor) = None;
}
/* no redraw required */
}
/*
* Scroll to the requested line or restore previous line if it has been
* messed up as the result of a resource change requiring a recompuation
* of the layout.
*/
if(ATTR_HTML(w_req, top_line) != ATTR_HTML(w_curr, top_line))
{
_XmHTMLScrollToLine(w_new, ATTR_HTML(w_req, top_line));
redraw = True;
}
else if(need_reformat && !parse &&
ATTR_HTML(w_new, top_line) != ATTR_HTML(w_curr, top_line))
{
_XmHTMLScrollToLine(w_new, ATTR_HTML(w_curr, top_line));
redraw = True;
}
/* check and set scrolling delay */
if(ATTR_HTML(w_req, repeat_delay) != ATTR_HTML(w_curr, repeat_delay))
{
if(ATTR_HTML(w_new, vsb) && XtIsManaged(ATTR_HTML(w_new, vsb)))
XtVaSetValues(ATTR_HTML(w_new, vsb),
XmNrepeatDelay, ATTR_HTML(w_new, repeat_delay), NULL);
if(ATTR_HTML(w_new, hsb) && XtIsManaged(ATTR_HTML(w_new, hsb)))
XtVaSetValues(ATTR_HTML(w_new, hsb),
XmNrepeatDelay, ATTR_HTML(w_new, repeat_delay), NULL);
}
/* see if we have to restart the animations if they were frozen */
if(!ATTR_HTML(w_req, freeze_animations) &&
ATTR_HTML(w_curr, freeze_animations))
_XmHTMLRestartAnimations(w_new);
/* do we still need pointer tracking? */
if(!ATTR_HTML(w_new, anchor_track_callback) &&
!ATTR_HTML(w_new, anchor_cursor) &&
!ATTR_HTML(w_new, highlight_on_enter) &&
!ATTR_HTML(w_new, motion_track_callback) &&
!ATTR_HTML(w_new, focus_callback) &&
!ATTR_HTML(w_new, losing_focus_callback))
ATTR_HTML(w_new, need_tracking) = False;
else
ATTR_HTML(w_new, need_tracking) = True;
/* only recompute new layout if we haven't done so already */
if(need_layout && !ATTR_HTML(w_curr, in_layout) && !need_reformat)
{
_XmHTMLLayout(w_new);
redraw = True;
}
if(redraw)
{
/*
* If free_images is still set when we get here, check if some
* images need their delayed_creation bit set.
*/
if(free_images)
{
XmHTMLImage *img;
for(img = ATTR_HTML(w_new, images); img != NULL; img = img->next)
{
if(!ImageInfoFreed(img) &&
ImageInfoDelayedCreation(img->html_image))
{
img->options |= IMG_DELAYED_CREATION;
ATTR_HTML(w_new, delayed_creation) = True;
}
}
if(ATTR_HTML(w_new, delayed_creation))
_XmHTMLImageCheckDelayedCreation(w_new);
}
_XmHTMLDebug(1, ("XmHTML.c: SetValues, calling _XmHTMLClearArea.\n"));
/*****
* To make sure the new text is displayed, we need to clear
* the current contents and generate an expose event to render
* the new text.
* We can only do this when we have been realized. If we don't have
* a gc, it means we haven't been realized yet. (fix 01/26/97-01, kdh)
*****/
if(ATTR_HTML(w_new, gc) != NULL)
_XmHTMLClearArea(w_new, 0, 0, ATTR_CORE(w_new, width),
ATTR_CORE(w_new, height));
}
/* Check for the onload event */
if((event_to_check & EVENT_LOAD) &&
ATTR_HTML(w_new, event_mask) & EVENT_LOAD)
{
/*****
* Don't bother to check return value. It's forbidden to modify
* the document content during processing of the onLoad event.
* (EventProcess exits if it does happen)
*****/
_XmHTMLEventProcess(w_new, NULL,
ATTR_HTML(w_new, body_events)->onLoad);
}
_XmHTMLDebug(1, ("XmHTML.c: SetValues End\n"));
return(redraw);
}
/*****
* Name: GetValues
* Return Type: void
* Description: XmHTMLWidgetClass get_values_hook method.
* In:
*
* Returns:
* nothing
*****/
static void
GetValues(Widget w, ArgList args, Cardinal *num_args)
{
register int i;
_XmHTMLDebug(1, ("XmHTML.c: GetValues Start\n"));
/*****
* Note on args filling:
* the value field (which is of type long int) represents a pointer to
* another pointer. Thus, updating a value requires updating the
* location the second pointer points to. That's why a double pointer
* cast is required.
*****/
for(i = 0; i < *num_args; i++)
{
_XmHTMLDebug(1, ("XmHTML.c: GetValues, requested for %s.\n",
args[i].name));
/*
* We return a pointer to the source text instead of letting X do it
* since the user might have freed the original text by now.
*/
if(!(strcmp(args[i].name, XmNvalue)))
{
*((char**)args[i].value) = XmHTMLTextGetSource(w);
}
else if(!(strcmp(args[i].name, XmNtopLine)))
{
XmHTMLObjectTableElement tmp;
XmHTMLWidget html = (XmHTMLWidget)w;
/* get current linenumber */
tmp = _XmHTMLGetLineObject(html, HTML_ATTR(scroll_y));
if(tmp != NULL)
*((int*)args[i].value) = tmp->line;
else
*((int*)args[i].value) = 0;
}
}
_XmHTMLDebug(1, ("XmHTML.c: GetValues End\n"));
return;
}
/*****
* Name: GeometryManager
* Return Type: XtGeometryResult
* Description: XmHTMLWidgetClass geometry_manager method
* In:
*
* Returns:
* Don't care. Just pass everything on.
*****/
static XtGeometryResult
GeometryManager(Widget w, XtWidgetGeometry *request,
XtWidgetGeometry *geometry_return)
{
_XmHTMLDebug(1, ("XmHTML.c: GeometryManager Start\n"));
if(request->request_mode & CWX)
geometry_return->x = request->x;
if(request->request_mode & CWY)
geometry_return->y = request->y;
if(request->request_mode & CWWidth)
geometry_return->width = request->width;
if(request->request_mode & CWHeight)
geometry_return->height = request->height;
if(request->request_mode & CWBorderWidth)
geometry_return->border_width = request->border_width;
geometry_return->request_mode = request->request_mode;
_XmHTMLDebug(1, ("XmHTML.c: GeometryManager End\n"));
return(XtGeometryYes);
}
/*****
* Name: Destroy
* Return Type: void
* Description: XmHTMLWidgetClass destroy method. Frees up allocated resources.
* In:
* w: widget to destroy
* Returns:
* nothing
*****/
static void
Destroy(Widget w)
{
XmHTMLWidget html = (XmHTMLWidget)w;
_XmHTMLDebug(1, ("XmHTML.c: Destroy Start\n"));
/* destroy common resources */
_XmHTMLDestroyPhaseZero(html);
/* remove all callbacks */
XtRemoveAllCallbacks(w, XmNactivateCallback);
XtRemoveAllCallbacks(w, XmNarmCallback);
XtRemoveAllCallbacks(w, XmNanchorTrackCallback);
XtRemoveAllCallbacks(w, XmNframeCallback);
XtRemoveAllCallbacks(w, XmNformCallback);
XtRemoveAllCallbacks(w, XmNinputCallback);
XtRemoveAllCallbacks(w, XmNlinkCallback);
XtRemoveAllCallbacks(w, XmNmotionTrackCallback);
XtRemoveAllCallbacks(w, XmNimagemapCallback);
XtRemoveAllCallbacks(w, XmNdocumentCallback);
XtRemoveAllCallbacks(w, XmNfocusCallback);
XtRemoveAllCallbacks(w, XmNlosingFocusCallback);
XtRemoveAllCallbacks(w, XmNeventCallback);
/* Destroy our ToolkitAbstraction */
XmHTMLTkaDestroy(HTML_ATTR(tka));
/* invalidate this widget */
w = NULL;
_XmHTMLDebug(1, ("XmHTML.c: Destroy End\n"));
return;
}
/*****
* Name: HTMLProcessInput
* Return Type: void
* Description: handles keyboard input for the HTML widget.
* In:
* w: XmHTMLWidget
* event: ButtonEvent structure
* params: additional args, unused
* num_params: no of addition args, unused
* Returns:
* nothing
* Note:
* This routine calls any installed XmNinputCallback callback resources.
*****/
static void
HTMLProcessInput(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
XmHTMLWidget html;
/*
* If this action proc is called directly from within application code,
* w is a html widget. In all other cases this action proc is called
* for the translations installed on the work_area, and thus we need to
* use XtParent to get our html widget.
*/
if(XmIsHTML(w))
html = (XmHTMLWidget)w;
else
html = (XmHTMLWidget)XtParent(w);
/* pass down if callback is installed */
if(HTML_ATTR(input_callback))
_XmHTMLInputCallback(html, event);
_XmHTMLDebug(1, ("XmHTML.c: ProcessInput End\n"));
}
/*****
* Name: HTMLPageUpOrLeft
* Return Type: void
* Description: keyboard navigation action routine
* In:
* w: widget id; XmHTMLWidget id if called from within application
* code, work_area if handled by XmHTML itself;
* event: key event;
* params: 0 for pageUp, 1 for pageLeft
* num_params: always 1
* Returns:
* nothing
* Note:
* This routine also honors the repeatDelay resource.
*****/
static void
HTMLPageUpOrLeft(Widget w, XEvent *event, String *params,
Cardinal *num_params)
{
int which;
XmHTMLWidget html;
static Time prev_time = 0;
if(XmIsHTML(w))
html = (XmHTMLWidget)w;
else
html = (XmHTMLWidget)XtParent(w);
if(*num_params != 1 || !XtIsRealized(w))
{
if(*num_params != 1)
_XmHTMLWarning(__WFUNC__(w, "HTMLPageUpOrLeft"), XMHTML_MSG_13,
"page-up-or-left");
return;
}
/* check repeat delay */
if(event->xkey.time - prev_time < HTML_ATTR(repeat_delay))
return;
prev_time = event->xkey.time;
which = atoi(params[0]);
_XmHTMLDebug(1, ("XmHTML.c: HTMLPageUpOrLeft, which = %i\n", which));
if(which == 0 && XtIsManaged(HTML_ATTR(vsb)))
XtCallActionProc(HTML_ATTR(vsb), "PageUpOrLeft", event, params, 1);
else if(which == 1 && XtIsManaged(HTML_ATTR(hsb)))
XtCallActionProc(HTML_ATTR(hsb), "PageUpOrLeft", event, params, 1);
}
/*****
* Name: HTMLDownOrRight
* Return Type: void
* Description: keyboard navigation action routine
* In:
* w: widget id; XmHTMLWidget id if called from within application
* code, work_area if handled by XmHTML itself;
* event: key event;
* params: 0 for pageDown, 1 for pageRight
* num_params: always 1
* Returns:
* nothing
* Note:
* This routine also honors the repeatDelay resource.
*****/
static void
HTMLPageDownOrRight(Widget w, XEvent *event, String *params,
Cardinal *num_params)
{
int which;
XmHTMLWidget html;
static Time prev_time = 0;
if(XmIsHTML(w))
html = (XmHTMLWidget)w;
else
html = (XmHTMLWidget)XtParent(w);
if(*num_params != 1 || !XtIsRealized(w))
{
if(*num_params != 1)
_XmHTMLWarning(__WFUNC__(w, "HTMLPageDownOrRight"), XMHTML_MSG_13,
"page-down-or-right");
return;
}
/* check repeat delay */
if(event->xkey.time - prev_time < HTML_ATTR(repeat_delay))
return;
prev_time = event->xkey.time;
which = atoi(params[0]);
_XmHTMLDebug(1, ("XmHTML.c: HTMLPageDownOrRight, which = %i\n", which));
if(which == 0 && XtIsManaged(HTML_ATTR(vsb)))
XtCallActionProc(HTML_ATTR(vsb), "PageDownOrRight", event, params, 1);
else if(which == 1 && XtIsManaged(HTML_ATTR(hsb)))
XtCallActionProc(HTML_ATTR(hsb), "PageDownOrRight", event, params, 1);
}
/*****
* Name: HTMLIncrementUpOrLeft
* Return Type: void
* Description: keyboard navigation action routine
* In:
* w: widget id; XmHTMLWidget id if called from within application
* code, work_area if handled by XmHTML itself;
* event: key event;
* params: 0 for IncrementUp, 1 for IncrementLeft
* num_params: always 1
* Returns:
* nothing
* Note:
* This routine also honors the repeatDelay resource.
*****/
static void
HTMLIncrementUpOrLeft(Widget w, XEvent *event, String *params,
Cardinal *num_params)
{
int which;
XmHTMLWidget html;
static Time prev_time = 0;
if(XmIsHTML(w))
html = (XmHTMLWidget)w;
else
html = (XmHTMLWidget)XtParent(w);
if(*num_params != 1 || !XtIsRealized(w))
{
if(*num_params != 1)
_XmHTMLWarning(__WFUNC__(w, "HTMLIncrementUpOrLeft"), XMHTML_MSG_13,
"increment-up-or-left");
return;
}
/* check repeat delay */
if(event->xkey.time - prev_time < HTML_ATTR(repeat_delay))
return;
prev_time = event->xkey.time;
which = atoi(params[0]);
_XmHTMLDebug(1, ("XmHTML.c: HTMLIncrementUpOrLeft, which = %i\n", which));
if(which == 0 && XtIsManaged(HTML_ATTR(vsb)))
XtCallActionProc(HTML_ATTR(vsb), "IncrementUpOrLeft", event,
params, 1);
else if(which == 1 && XtIsManaged(HTML_ATTR(hsb)))
XtCallActionProc(HTML_ATTR(hsb), "IncrementUpOrLeft", event,
params, 1);
}
/*****
* Name: HTMLIncrementDownOrRight
* Return Type: void
* Description: keyboard navigation action routine
* In:
* w: widget id; XmHTMLWidget id if called from within application
* code, work_area if handled by XmHTML itself;
* event: key event;
* params: 0 for IncrementDown, 1 for IncrementRight
* num_params: always 1
* Returns:
* nothing
* Note:
* This routine also honors the repeatDelay resource.
*****/
static void
HTMLIncrementDownOrRight(Widget w, XEvent *event, String *params,
Cardinal *num_params)
{
int which;
XmHTMLWidget html;
static Time prev_time = 0;
if(XmIsHTML(w))
html = (XmHTMLWidget)w;
else
html = (XmHTMLWidget)XtParent(w);
if(*num_params != 1 || !XtIsRealized(w))
{
if(*num_params != 1)
_XmHTMLWarning(__WFUNC__(w, "HTMLIncrementDownOrRight"),
XMHTML_MSG_13, "increment-down-or-right");
return;
}
/* check repeat delay */
if(event->xkey.time - prev_time < HTML_ATTR(repeat_delay))
return;
prev_time = event->xkey.time;
which = atoi(params[0]);
_XmHTMLDebug(1, ("XmHTML.c: HTMLIncrementDownOrRight, which = %i\n",
which));
if(which == 0 && XtIsManaged(HTML_ATTR(vsb)))
XtCallActionProc(HTML_ATTR(vsb), "IncrementDownOrRight", event,
params, 1);
else if(which == 1 && XtIsManaged(HTML_ATTR(hsb)))
XtCallActionProc(HTML_ATTR(hsb), "IncrementDownOrRight", event,
params, 1);
}
/*****
* Name: HTMLTopOrBottom
* Return Type: void
* Description: keyboard navigation action routine
* In:
* w: widget id; XmHTMLWidget id if called from within application
* code, work_area if handled by XmHTML itself;
* event: key event;
* params: 0 for top, 1 for bottom
* num_params: always 1
* Returns:
* nothing
* Note:
* no repeatDelay by this action routine, it only moves from top to bottom
* or vice-versa
*****/
static void
HTMLTopOrBottom(Widget w, XEvent *event, String *params,
Cardinal *num_params)
{
int which;
XmHTMLWidget html;
if(XmIsHTML(w))
html = (XmHTMLWidget)w;
else
html = (XmHTMLWidget)XtParent(w);
if(*num_params != 1 || !XtIsRealized(w))
{
if(*num_params != 1)
_XmHTMLWarning(__WFUNC__(w, "HTMLTopOrBottom"), XMHTML_MSG_13,
"top-or-bottom");
return;
}
which = atoi(params[0]);
_XmHTMLDebug(1, ("XmHTML.c: HTMLTopOrBottom, which = %i\n", which));
if(which == 0 && XtIsManaged(HTML_ATTR(vsb)))
{
/* no move if already on top */
if(HTML_ATTR(top_line) == 0)
return;
HTML_ATTR(top_line) = 0;
_XmHTMLMoveToPos(HTML_ATTR(vsb), html, 0);
}
else if(which == 1 && XtIsManaged(HTML_ATTR(vsb)))
{
int value;
/* no move if already on bottom */
if(HTML_ATTR(top_line) == HTML_ATTR(nlines))
return;
HTML_ATTR(top_line) = HTML_ATTR(nlines);
value = HTML_ATTR(formatted_height);
/* fix 01/30/97-04, kdh */
_XmHTMLAdjustVerticalScrollValue(HTML_ATTR(vsb), &value);
_XmHTMLMoveToPos(HTML_ATTR(vsb), html, value);
}
}
static void
HTMLTraverseCurrent(Widget w, XEvent *event, String *params,
Cardinal *num_params)
{
if(!XtIsRealized(w))
return;
_XmHTMLProcessTraversal(w, XmTRAVERSE_CURRENT);
}
static void
HTMLTraverseNext(Widget w, XEvent *event, String *params,
Cardinal *num_params)
{
if(!XtIsRealized(w))
return;
_XmHTMLProcessTraversal(w, XmTRAVERSE_NEXT);
}
static void
HTMLTraversePrev(Widget w, XEvent *event, String *params,
Cardinal *num_params)
{
if(!XtIsRealized(w))
return;
_XmHTMLProcessTraversal(w, XmTRAVERSE_PREV);
}
static void
HTMLTraverseNextOrPrev(Widget w, XEvent *event, String *params,
Cardinal *num_params)
{
int which;
if(*num_params != 1 || !XtIsRealized(w))
{
if(*num_params != 1)
_XmHTMLWarning(__WFUNC__(w, "HTMLTraverseNextOrPrev"),
XMHTML_MSG_13, "traverse-next-or-prev");
return;
}
which = atoi(params[0]);
if(which == 0)
_XmHTMLProcessTraversal(w, XmTRAVERSE_NEXT_TAB_GROUP);
else
_XmHTMLProcessTraversal(w, XmTRAVERSE_PREV_TAB_GROUP);
}
/*****
* Name: ExtendStart
* Return Type: void
* Description: buttonPress action routine. Initializes a selection when
* not over an anchor, else paints the anchor as being selected.
* In:
*
* Returns:
* nothing.
*****/
static void
ExtendStart(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
/* need to use XtParent since we only get button events from work_area */
XmHTMLWidget html = (XmHTMLWidget)XtParent(w);
XButtonPressedEvent *pressed = (XButtonPressedEvent*)event;
XmHTMLAnchor *anchor = NULL;
XmHTMLWord *anchor_word = NULL;
XmHTMLImage anchor_img;
int x,y;
/* no needless lingering in this routine */
if(XtClass(XtParent(w)) != xmHTMLWidgetClass)
return;
/* we don't do a thing with events generated by button3 */
if(pressed->button == Button3 && HTML_ATTR(arm_callback) == NULL)
return;
_XmHTMLFullDebug(1, ("XmHTML.c: ExtendStart Start\n"));
/* Get coordinates of button event and add core offsets */
x = pressed->x;
y = pressed->y;
/* try to get current anchor element */
if(pressed->button != Button3 &&
(((anchor_word = _XmHTMLGetAnchor(html, x, y, &anchor_img)) != NULL) ||
((anchor = _XmHTMLGetImageAnchor(html, x, y, &anchor_img)) != NULL)))
{
/*****
* User has selected an anchor. Get the text for this anchor.
* Note: if anchor is NULL it means the user was over a real anchor
* (regular anchor, anchored image or a form image button) and
* anchor_word is non-NULL (this object the referenced URL). If it
* is non-NULL the mouse was over an imagemap, in which case we
* may not show visual feedback to the user.
* I admit, the naming of the variables is rather confusing.
******/
if(anchor == NULL)
{
/* store anchor & paint as selected */
anchor = anchor_word->owner->anchor;
/*****
* uncheck currently selected anchor if it's not the same as
* the current anchor (mouse dragging)
*****/
if(HTML_ATTR(current_anchor) != NULL &&
HTML_ATTR(current_anchor) != anchor_word->owner)
_XmHTMLPaintAnchorUnSelected(html);
_XmHTMLPaintAnchorSelected(html, anchor_word);
}
else if(HTML_ATTR(selected) != NULL &&
HTML_ATTR(selected) != anchor)
_XmHTMLPaintAnchorUnSelected(html);
/* check for the onMouseDown event */
if(anchor->event_mask & EVENT_MOUSEDOWN)
{
/*****
* Check return value, document might have changed from under
* us upon return.
*****/
if(_XmHTMLEventProcess(html, event, anchor->events->onMouseDown))
return;
}
HTML_ATTR(selected) = anchor;
_XmHTMLFullDebug(1, ("XmHTML.c: ExtendStart, anchor selected is %s\n",
anchor->href));
}
else if(HTML_ATTR(current_anchor) != NULL)
{
ToolkitAbstraction *tka = HTML_ATTR(tka);
/* not over an anchor, unselect current anchor and reset cursor */
_XmHTMLPaintAnchorUnSelected(html);
tka->UndefineCursor(tka->dpy, tka->win);
}
/* remember pointer position and time */
HTML_ATTR(press_x) = pressed->x;
HTML_ATTR(press_y) = pressed->y;
HTML_ATTR(pressed_time) = pressed->time;
if(anchor_word == NULL && anchor == NULL && HTML_ATTR(arm_callback))
_XmHTMLArmCallback(html, event);
_XmHTMLFullDebug(1, ("XmHTML.c: ExtendStart End\n"));
}
/*****
* Name: ExtendAdjust
* Return Type: void
* Description: buttondrag action routine. Adjusts the selection initiated
* by ExtendStart.
* In:
*
* Returns:
* nothing.
*****/
static void
ExtendAdjust(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
/* need to use XtParent since we only get motion events from work_area */
if(XtClass(XtParent(w)) != xmHTMLWidgetClass)
return;
_XmHTMLFullDebug(1, ("XmHTML.c: ExtendAdjust Start\n"));
_XmHTMLFullDebug(1, ("XmHTML.c: ExtendAdjust End\n"));
return;
}
/*****
* Name: ExtendEnd
* Return Type: void
* Description: buttonrelease tracking action routine. Terminates the selection
* initiated by ExtendStart. When over an anchor, paints the
* anchor as being deselected. XmNactivateCallback or
* XmNarmCallback callback resources are only called if the
* buttonpress and release occur within a certain time limit
* (XmHTML_MAX_BUTTON_RELEASE_TIME, defined XmHTMLfuncs.h)
* In:
*
* Returns:
* nothing
*****/
static void
ExtendEnd(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
/* need to use XtParent since we only get button events from work_area */
XmHTMLWidget html = (XmHTMLWidget)XtParent(w);
XButtonReleasedEvent *release = (XButtonReleasedEvent*)event;
XmHTMLAnchor *anchor = NULL;
XmHTMLWord *anchor_word = NULL;
XmHTMLImage anchor_img;
int x,y;
/* no needless lingering in this routine */
if(XtClass(XtParent(w)) != xmHTMLWidgetClass)
return;
/* we don't do a thing with events generated by button3 */
if(release->button == Button3)
return;
_XmHTMLFullDebug(1, ("XmHTML.c: ExtendEnd Start\n"));
/* Get coordinates of button event */
x = release->x;
y = release->y;
/* try to get current anchor element */
if(((anchor_word = _XmHTMLGetAnchor(html, x, y, &anchor_img)) != NULL) ||
((anchor = _XmHTMLGetImageAnchor(html, x, y, &anchor_img)) != NULL))
{
/*
* OK, release took place over an anchor, see if it falls within the
* allowable time limit and we are still over the anchor selected by
* ExtendStart.
*/
if(anchor == NULL)
anchor = anchor_word->owner->anchor;
/*
* If we already have an active anchor and it's different from the
* current anchor, deselect it.
*/
if(HTML_ATTR(current_anchor) &&
HTML_ATTR(current_anchor) != anchor_word->owner)
_XmHTMLPaintAnchorUnSelected(html);
/* see if we need to serve the mouseUp event */
if(anchor->event_mask & EVENT_MOUSEUP)
{
/*****
* Process this event. If we get a non-zero return value it
* means that the document has been changed from under us
* so we won't perform any other processing as we most
* likely will be referencing invalid data.
*****/
if(_XmHTMLEventProcess(html, event, anchor->events->onMouseUp))
return;
}
/* this anchor is still in selection */
if(anchor_word)
{
if(HTML_ATTR(highlight_on_enter))
_XmHTMLPaintAnchorEntry(html, anchor_word->owner);
else
_XmHTMLPaintAnchorUnSelected(html);
}
_XmHTMLFullDebug(1, ("XmHTML.c: ExtendEnd, anchor selected is %s\n",
anchor->href));
/*
* if we had a selected anchor and it's equal to the current anchor
* and the button was released in time, trigger the activation callback.
*/
if(HTML_ATTR(selected) != NULL && anchor == HTML_ATTR(selected) &&
(release->time - HTML_ATTR(pressed_time)) < XmHTML_BUTTON_RELEASE_TIME)
{
/* check for the onClick event */
if(anchor->event_mask & EVENT_CLICK)
{
_XmHTMLDebug(1, ("XmHTML.c:ExtendEnd, onClick: anchor=%x ->\n"
"events=%x -> onClick = %x -> (type=%d, data=%x)\n",
anchor, anchor->events, anchor->events->onClick,
anchor->events->onClick->type,
anchor->events->onClick->data));
/*****
* Process this event. If we get a non-zero return value it
* means that the document has been changed from under us
* so we won't perform any other processing as we most
* likely will be referencing invalid data.
*****/
if(_XmHTMLEventProcess(html, event, anchor->events->onClick))
return;
}
/*****
* Trigger form callback
* No need to check return value, we return after this call.
*****/
if(anchor->url_type == ANCHOR_FORM_IMAGE)
_XmHTMLFormActivate(html, event, anchor_word->form);
else if(HTML_ATTR(activate_callback))
{
/*****
* Trigger activation callback
* No need to check return value, we return after this call.
*****/
_XmHTMLActivateCallback(html, event, anchor);
_XmHTMLFullDebug(1, ("XmHTML.c: ExtendEnd End\n"));
}
return;
}
}
/* unset any previously selected anchor */
if(HTML_ATTR(current_anchor) != NULL)
{
/* keep current anchor selection or unset it */
if(anchor_word)
_XmHTMLPaintAnchorEntry(html, anchor_word->owner);
else
_XmHTMLPaintAnchorUnSelected(html);
}
_XmHTMLFullDebug(1, ("XmHTML.c: ExtendEnd End\n"));
return;
}
/*****
* Name: TrackMotion
* Return Type: void
* Description: mouse tracker; calls XmNanchorTrackCallback and/or HTML4.0
* event processing if entering/leaving an anchor.
* Also calls XmNmotionTrackCallback when installed.
* In:
* w: XmHTMLWidget
* event: MotionEvent structure
* params: additional args, unused
* num_parmas: no of additional args, unused
* Returns:
* nothing
*****/
static void
TrackMotion(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
/* need to use XtParent since we only get motion events from work_area */
XmHTMLWidget html = (XmHTMLWidget)XtParent(w);
XMotionEvent *motion = (XMotionEvent*)event;
XmHTMLAnchor *anchor = NULL;
XmHTMLWord *anchor_word = NULL;
XmHTMLImage anchor_img;
int x = 0, y = 0;
ToolkitAbstraction *tka = NULL;
/* no needless lingering in this routine */
if(XtClass(XtParent(w)) != xmHTMLWidgetClass)
return;
/* ignore if we don't have to make any more feedback to the user */
if(!HTML_ATTR(need_tracking) || event->xany.type != MotionNotify)
return;
/* get handle to the ToolkitAbstraction */
tka = HTML_ATTR(tka);
/* we are already on the correct anchor, just return */
_XmHTMLFullDebug(1, ("XmHTML.c: TrackMotion Start.\n"));
/* save x and y position, we need it to get anchor data */
/* pass down to motion tracker callback if installed */
if(HTML_ATTR(motion_track_callback))
_XmHTMLMotionCallback(html, event);
x = motion->x;
y = motion->y;
/* try to get current anchor element (if any) */
if(((anchor_word = _XmHTMLGetAnchor(html, x, y, &anchor_img)) == NULL) &&
((anchor = _XmHTMLGetImageAnchor(html, x, y, &anchor_img)) == NULL))
{
_XmHTMLFullDebug(1, ("XmHTML.c: TrackMotion, no current anchor.\n"));
/* invalidate current selection or check event mask if there is one */
if(HTML_ATTR(anchor_current_cursor_element))
{
XmHTMLAnchor *pa = HTML_ATTR(anchor_current_cursor_element);
/*****
* First check for onMouseOut event. Return if document has
* been modified during event processing.
*****/
if(pa->event_mask & EVENT_MOUSEOUT)
{
if(_XmHTMLEventProcess(html, event, pa->events->onMouseOut))
return;
}
if(HTML_ATTR(anchor_track_callback))
_XmHTMLTrackCallback(html, event, NULL);
}
if(HTML_ATTR(highlight_on_enter) && HTML_ATTR(armed_anchor))
_XmHTMLPaintAnchorLeave(html);
HTML_ATTR(armed_anchor) = NULL;
HTML_ATTR(anchor_current_cursor_element) = NULL;
tka->UndefineCursor(tka->dpy, tka->win);
return;
}
if(anchor == NULL)
anchor = anchor_word->owner->anchor;
/* Trigger callback and set cursor if we are entering a new element */
if(anchor != HTML_ATTR(anchor_current_cursor_element))
{
_XmHTMLFullDebug(1, ("XmHTML.c: TrackMotion, new anchor.\n"));
/*****
* When anchors are painted next to each other or the user is
* moving the mouse very fast from one anchor to another, the previous
* check (anchor_word and anchor == NULL) will fail, thereby leaving
* a few loose ends (possible HTML4.0 events and anchor tracking).
* So if we had a current anchor, we need to check if it a mouseOut
* event was present and if so, we need to process this event.
* After that we call the TrackCallback so the application will be
* notified of the fact that the current anchor is no longer valid
* and that the user is moving towards a new anchor.
*****/
if(HTML_ATTR(anchor_current_cursor_element))
{
XmHTMLAnchor *pa = HTML_ATTR(anchor_current_cursor_element);
/*****
* First check for onMouseOut event. Return if document has
* been modified during event processing.
*****/
if(pa->event_mask & EVENT_MOUSEOUT)
{
if(_XmHTMLEventProcess(html, event, pa->events->onMouseOut))
return;
}
if(HTML_ATTR(anchor_track_callback))
_XmHTMLTrackCallback(html, event, NULL);
}
/* Check for onMouseOver event */
if(anchor->event_mask & EVENT_MOUSEOVER)
{
/* Check return value of event processing */
if(_XmHTMLEventProcess(html, event, anchor->events->onMouseOver))
return;
}
/* remove highlight of previous anchor */
if(HTML_ATTR(highlight_on_enter))
{
if(anchor_word)
{
/* unarm previous selection */
if(HTML_ATTR(armed_anchor) &&
HTML_ATTR(armed_anchor) != anchor_word->owner)
_XmHTMLPaintAnchorLeave(html);
/* highlight new selection */
_XmHTMLPaintAnchorEntry(html, anchor_word->owner);
}
else /* unarm previous selection */
if(HTML_ATTR(armed_anchor))
_XmHTMLPaintAnchorLeave(html);
}
HTML_ATTR(anchor_current_cursor_element) = anchor;
_XmHTMLTrackCallback(html, event, anchor);
tka->DefineCursor(tka->dpy, tka->win, HTML_ATTR(anchor_cursor));
return;
}
else if(anchor->event_mask & EVENT_MOUSEMOVE)
{
/*****
* Current anchor. Need to call onMouseMove event if defined.
* No need to check return value as we return immediatly after
* event processing.
*****/
_XmHTMLEventProcess(html, event, anchor->events->onMouseMove);
}
/* we are already on the correct anchor, just return */
_XmHTMLFullDebug(1, ("XmHTML.c: TrackMotion End, over current anchor\n"));
}
/*****
* Name: TrackFocus
* Return Type: void
* Description: focus tracker; calls XmNanchorTrackCallback if
* entering/leaving an anchor.
* Also calls XmNfocusCallback when installed.
* In:
* w: XmHTMLWidget
* event: FocusIn/FocusOut/Leave/Event structure
* params: additional args, unused
* num_parmas: no of additional args, unused
* Returns:
* nothing
*****/
static void
TrackFocus(Widget w, XEvent *event, String *params, Cardinal *num_params)
{
/* need to use XtParent since we only get motion events from work_area */
XmHTMLWidget html = (XmHTMLWidget)XtParent(w);
ToolkitAbstraction *tka = NULL;
/* no needless lingering in this routine */
if(XtClass(XtParent(w)) != xmHTMLWidgetClass)
return;
/* ignore if we don't have to make any feedback to the user */
if(!HTML_ATTR(need_tracking))
return;
/* get handle to the ToolkitAbstraction */
tka = HTML_ATTR(tka);
/* we are already on the correct anchor, just return */
_XmHTMLFullDebug(1, ("XmHTML.c: TrackFocus Start.\n"));
/* check event and act accordingly */
switch(event->type)
{
case FocusIn:
_XmHTMLFullDebug(1, ("XmHTML.c: TrackFocus, FocusIn.\n"));
_XmHTMLFocusInCallback(html, event);
/*****
* Might seem silly to test for the presence of a window in the
* current tka, but in some very rare cases it can happen that a
* FocusIn event is generated *before* a SubStructure event is
* generated. This leads to the weird possibility that we have an
* event on a window which has yet to be mapped to the screen!
* This leads to a BadValue error and so we need to check if we have
* a valid window id before doing anything with it.
*****/
if(tka->win)
tka->UndefineCursor(tka->dpy, tka->win);
break;
case LeaveNotify:
/*****
* LeaveNotify Events occur when the pointer focus is transferred
* from the DrawingArea child to another window. This can occur
* when the pointer is moved outside the Widget *OR* when a
* ButtonPress event occurs ON the drawingArea. When that happens,
* the pointer focus is transferred from the drawingArea to it's
* parent, being the Widget itself. In this case the detail
* detail member of the XEnterWindowEvent will be NotifyAncestor,
* and we would want to ignore this event (as it will cause a
* flicker of the screen or an unnecessary call to any installed
* callbacks).
*****/
if(((XEnterWindowEvent*)event)->detail == NotifyAncestor)
return;
/* else fall through */
case FocusOut:
_XmHTMLFullDebug(1, ("XmHTML.c: TrackFocus, "
"%s.\n", event->type == LeaveNotify ?
"LeaveNotify" : "FocusOut"));
/* invalidate current selection if there is one */
if(HTML_ATTR(anchor_track_callback) &&
HTML_ATTR(anchor_current_cursor_element))
_XmHTMLTrackCallback(html, event, NULL);
/* loses focus, remove anchor highlight */
if(HTML_ATTR(highlight_on_enter) && HTML_ATTR(armed_anchor))
_XmHTMLPaintAnchorLeave(html);
HTML_ATTR(armed_anchor) = NULL;
HTML_ATTR(anchor_current_cursor_element) = NULL;
tka->UndefineCursor(tka->dpy, tka->win);
/* final step: call focusOut callback */
if(event->type == FocusOut)
_XmHTMLFocusOutCallback(html, event);
/* fall through */
default:
/* uninteresting event, throw away */
break;
}
}
/*****
* Name: CheckAnchorUnderlining
* Return Type: void
* Description: validate anchor underlining enumeration values.
* In:
* html: target widget
* req: requester widget
* Returns:
* nothing.
*****/
static void
CheckAnchorUnderlining(XmHTMLWidget html, XmHTMLWidget req)
{
/* Anchor Underlining values */
if(!XmRepTypeValidValue(underline_repid, req->html.anchor_underline_type,
(Widget)html))
HTML_ATTR(anchor_underline_type) = XmSINGLE_LINE;
else
HTML_ATTR(anchor_underline_type) = ATTR_HTML(req,anchor_underline_type);
/* Set corresponding private resources */
switch(HTML_ATTR(anchor_underline_type))
{
case XmNO_LINE:
HTML_ATTR(anchor_line) = NO_LINE;
break;
case XmSINGLE_DASHED_LINE:
HTML_ATTR(anchor_line) = LINE_DASHED|LINE_UNDER|LINE_SINGLE;
break;
case XmDOUBLE_LINE:
HTML_ATTR(anchor_line) = LINE_SOLID|LINE_UNDER|LINE_DOUBLE;;
break;
case XmDOUBLE_DASHED_LINE:
HTML_ATTR(anchor_line) = LINE_DASHED|LINE_UNDER|LINE_DOUBLE;;
break;
case XmSINGLE_LINE: /* default */
default:
HTML_ATTR(anchor_line) = LINE_SOLID | LINE_UNDER | LINE_SINGLE;
break;
}
/* Visited Anchor Underlining values */
if(!XmRepTypeValidValue(underline_repid,
ATTR_HTML(req, anchor_visited_underline_type), (Widget)html))
HTML_ATTR(anchor_visited_underline_type) = XmSINGLE_LINE;
else
HTML_ATTR(anchor_visited_underline_type) =
ATTR_HTML(req, anchor_visited_underline_type);
/* Set corresponding private resources */
switch(HTML_ATTR(anchor_visited_underline_type))
{
case XmNO_LINE:
HTML_ATTR(anchor_visited_line) = NO_LINE;
break;
case XmSINGLE_DASHED_LINE:
HTML_ATTR(anchor_visited_line) = LINE_DASHED|LINE_UNDER|LINE_SINGLE;
break;
case XmDOUBLE_LINE:
HTML_ATTR(anchor_visited_line) = LINE_SOLID|LINE_UNDER|LINE_DOUBLE;
break;
case XmDOUBLE_DASHED_LINE:
HTML_ATTR(anchor_visited_line) = LINE_DASHED|LINE_UNDER|LINE_DOUBLE;
break;
case XmSINGLE_LINE: /* default */
default:
HTML_ATTR(anchor_visited_line) = LINE_SOLID|LINE_UNDER|LINE_SINGLE;
break;
}
/* Target Anchor Underlining values */
if(!XmRepTypeValidValue(underline_repid,
HTML_ATTR(anchor_target_underline_type), (Widget)html))
ATTR_HTML(req, anchor_target_underline_type) = XmSINGLE_DASHED_LINE;
else
HTML_ATTR(anchor_target_underline_type) =
ATTR_HTML(req, anchor_target_underline_type);
/* Set corresponding private resources */
switch(HTML_ATTR(anchor_target_underline_type))
{
case XmNO_LINE:
HTML_ATTR(anchor_target_line) = NO_LINE;
break;
case XmSINGLE_LINE:
HTML_ATTR(anchor_target_line) = LINE_SOLID|LINE_UNDER|LINE_SINGLE;
break;
case XmDOUBLE_LINE:
HTML_ATTR(anchor_target_line) = LINE_SOLID|LINE_UNDER|LINE_DOUBLE;
break;
case XmDOUBLE_DASHED_LINE:
HTML_ATTR(anchor_target_line) = LINE_DASHED|LINE_UNDER|LINE_DOUBLE;
break;
case XmSINGLE_DASHED_LINE: /* default */
default:
HTML_ATTR(anchor_target_line) = LINE_DASHED|LINE_UNDER|LINE_SINGLE;
break;
}
}
/*****
* Name: CheckAlignment
* Return Type: void
* Description: checks and sets the alignment resources
* In:
* html: target widget
* req: requestor widget
* Returns:
* nothing.
*****/
static void
CheckAlignment(XmHTMLWidget html, XmHTMLWidget req)
{
/* Set default alignment */
if(ATTR_HTML(req, enable_outlining))
HTML_ATTR(default_halign) = XmHALIGN_JUSTIFY;
else
{
/* default alignment depends on string direction */
if(HTML_ATTR(string_direction) == XmSTRING_DIRECTION_R_TO_L)
HTML_ATTR(default_halign) = XmHALIGN_RIGHT;
else
HTML_ATTR(default_halign) = XmHALIGN_LEFT;
/* verify alignment */
if(XmRepTypeValidValue(string_repid, ATTR_HTML(req, alignment),
(Widget)html))
{
if(HTML_ATTR(alignment) == XmALIGNMENT_BEGINNING)
HTML_ATTR(default_halign) = XmHALIGN_LEFT;
if(HTML_ATTR(alignment) == XmALIGNMENT_END)
HTML_ATTR(default_halign) = XmHALIGN_RIGHT;
else if(HTML_ATTR(alignment) == XmALIGNMENT_CENTER)
HTML_ATTR(default_halign) = XmHALIGN_CENTER;
}
}
}
/*****
* Name: _XmHTMLCvtStringToWarning
* Return Type: Boolean
* Description: converts a XmHTML XmCHTMLWarningType to it's internal value.
* In:
* dpy: display with which this conversion is associated;
* args: any XrmValue arguments to this converter. Always NULL;
* num_args: no of args. Always 0;
* from_val: address and size of value to be converted;
* to_val: address where the converted value must be stored;
* convert..: data to be passed to the destructor routine. Since this
* converter doesn't allocate any data, this argument is ignored.
* Returns:
* True when the conversion was successfull, False if not.
*****/
Boolean
_XmHTMLCvtStringToWarning(Display *dpy, XrmValuePtr args, Cardinal *num_args,
XrmValuePtr from_val, XrmValuePtr to_val, XtPointer *converter_data)
{
static String warn_styles[] = {"unknown_element", "bad", "open_block",
"close_block", "open_element", "nested", "violation"};
Byte warn_values[] = {XmHTML_UNKNOWN_ELEMENT, XmHTML_BAD,
XmHTML_OPEN_BLOCK, XmHTML_CLOSE_BLOCK, XmHTML_OPEN_ELEMENT,
XmHTML_NESTED, XmHTML_VIOLATION};
String warning = NULL;
int i;
String ptr = (String)from_val->addr;
Byte ret_val = XmHTML_NONE;
if(*num_args != 0)
{
_XmHTMLWarning(__WFUNC__(NULL, "_XmHTMLCvtStringToWarning"),
XMHTML_MSG_19);
return(False);
}
/* hmm, shouldn't happen */
if(ptr == NULL || *ptr == '\0' || from_val->size < 3)
goto end;
/* copy so we scan it safely */
warning = my_strndup(ptr, from_val->size);
/* check if we have NONE */
if(my_strcasestr(warning, "none"))
goto end;
/* check if we have HTML_ALL */
if(my_strcasestr(warning, "all"))
{
ret_val = XmHTML_ALL;
goto end;
}
#define NUM_WARNINGS 7
/* now scan the string for the possible warning types */
for(i = 0; i < NUM_WARNINGS; i++)
{
if(my_strcasestr(warning, warn_styles[i]))
ret_val |= warn_values[i];
}
#undef NUM_WARNINGS
/* this is an error */
if(ret_val == XmHTML_NONE)
{
_XmHTMLWarning(__WFUNC__(NULL, "_XmHTMLCvtStringToWarning"),
XMHTML_MSG_20, warning);
free(warning);
return(False);
}
end:
/* no longer needed, free it */
if(warning != NULL)
free(warning);
if(to_val->addr != NULL)
{
if(to_val->size < sizeof(Byte))
{
to_val->size = sizeof(Byte);
return(False);
}
*(Byte*)to_val->addr = ret_val;
return(True);
}
else
{
static Byte static_val;
static_val = ret_val;
to_val->addr = (char *)&static_val;
to_val->size = sizeof(Byte);
return(True);
}
}
/*****
* Name: _XmHTMLAdjustVerticalScrollValue
* Return Type: void
* Description: adjust slider value so it does not exceed the maximum
* slider value.
* In:
* vsb: vertical scrollbar widget id;
* value: current slider value.
* Returns:
* nothing, but value can be updated upon return.
*****/
void
_XmHTMLAdjustVerticalScrollValue(Widget vsb, int *value)
{
int max = 0, size = 0;
XtVaGetValues(vsb,
XmNmaximum, &max,
XmNsliderSize, &size,
NULL);
if(*value > (max - size))
*value = (max - size);
}
/********
****** Public XmHTML Functions
********/
/*****
* Name: XmCreateHTML
* Return Type: Widget
* Description: creates a XmHTML widget
* In:
* parent: widget to act as parent for this new XmHTMLWidget
* name: name for the new widget
* arglist: arguments for this new XmHTMLWidget
* argcount: no of arguments
* Returns:
* a newly created widget. This routine exits if parent is NULL or a subclass
* of XmGadget.
*****/
Widget
XmCreateHTML(Widget parent, String name, ArgList arglist, Cardinal argcount)
{
#ifdef MOTIF_IN_DLL
/*****
* See comment above (search for other instance of this ifdef)
* We must do this BEFORE creating the widget or we'd have serious
* problems...
*****/
xmHTMLClassRec.core_class.superclass = (WidgetClass)&xmManagerClassRec;
#endif
if(parent && !XmIsGadget(parent))
return(XtCreateWidget(name, xmHTMLWidgetClass, parent,
arglist, argcount));
/* invalid parent, needs a widget, not a gadget */
__XmHTMLWarning(__WFUNC__(parent, "XmCreateHTML"),
XMHTML_MSG_34, (parent ? "Invalid" : "NULL"), "XmCreateHTML");
/* keep compiler happy */
return(NULL);
}
|