DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Untracked file

Line Code
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
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
 *
 * The contents of this file are subject to the Netscape Public License
 * Version 1.0 (the "NPL"); you may not use this file except in
 * compliance with the NPL.  You may obtain a copy of the NPL at
 * http://www.mozilla.org/NPL/
 *
 * Software distributed under the NPL is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
 * for the specific language governing rights and limitations under the
 * NPL.
 *
 * The Initial Developer of this code under the NPL is Netscape
 * Communications Corporation.  Portions created by Netscape are
 * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
 * Reserved.
 */
/* 
   commands.c --- menus and toolbar.
   Created: Jamie Zawinski <jwz@netscape.com>, 27-Jun-94.
 */


#include "mozilla.h"
#include "xfe.h"
#include "felocale.h"
#include "xlate.h"
#include "menu.h"
#include "net.h"
#include "e_kit.h"
#include "prefapi.h"
#include "intl_csi.h"
#include <netdb.h>
#ifdef FORTEZZA
#include "ssl.h"
#endif
#include "selection.h"

#include "outline.h"
#include "layers.h"


#ifdef EDITOR
#include "xeditor.h"
#include "edt.h" /* just for EDT_MailDocument() */
#endif /*EDITOR*/

#ifdef MOZ_MAIL_NEWS
#include "msgcom.h"
#include "msg_srch.h"
#include "mailnews.h"
#endif /* MOZ_MAIL_NEWS */

#include "il_icons.h"           /* Image icon enumeration. */

#include "mozjava.h"

#ifdef X_PLUGINS
#include "np.h"
#endif /* X_PLUGINS */

#ifndef NO_WEB_FONTS
#include "nf.h"
#endif /* NO_WEB_FONTS */

#include <Xm/RowColumn.h>
#include <XmL/Grid.h>

/* for XP_GetString() */
#include <xpgetstr.h>

extern int XFE_COMMANDS_UPLOAD_FILE;
extern int XFE_CANNOT_SEE_FILE;
extern int XFE_CANNOT_READ_FILE;
extern int XFE_IS_A_DIRECTORY;
extern int XFE_UNKNOWN_ESCAPE_CODE;
extern int XFE_LOG_IN_AS;
extern int XFE_COULDNT_FORK;
extern int XFE_EXECVP_FAILED;
extern int XFE_OUT_OF_MEMORY_URL;
extern int XFE_COMMANDS_OPEN_URL_USAGE;
extern int XFE_COMMANDS_HTML_HELP_USAGE;
extern int XFE_COMMANDS_UNPARSABLE_ENCODING_FILTER_SPEC;
extern int XFE_NETSCAPE_MAIL;
extern int XFE_NETSCAPE_NEWS;
extern int XFE_BOOKMARKS;
extern int XFE_ADDRESS_BOOK;
extern int XFE_DOWNLOAD_FILE;
extern int XFE_COMPOSE_NO_SUBJECT;
extern int XFE_COMPOSE;
extern int XFE_NETSCAPE_UNTITLED;
extern int XFE_NETSCAPE;
extern int XFE_COMMANDS_MAIL_TO_USAGE;

extern char* help_menu_names[];
extern char* directory_menu_names[];

extern MWContext * fe_reuseBrowser(MWContext *context,URL_Struct *url);

/* Local forward declarations */
extern void fe_InsertMessageCompositionText(MWContext *context, 
			const char *text,
			XP_Bool leaveCursorAtBeginning);

extern void fe_mailfilter_cb(Widget, XtPointer, XtPointer);

/* Externs from dialog.c: */
extern int fe_await_synchronous_url (MWContext *context);

/* Externs from mozilla.c */
extern char * fe_MakeSashGeometry(char *old_geom_str, int pane_config,
			unsigned int w, unsigned int h);

static void
fe_page_forward_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  Widget sb = CONTEXT_DATA (context)->vscroll;
  XmScrollBarCallbackStruct cb;
  int pi = 0, v = 0, max = 1, min = 0;

  XP_ASSERT(sb);
  if (!sb) return;
  XtVaGetValues (sb, XmNpageIncrement, &pi, XmNvalue, &v,
		 XmNmaximum, &max, XmNminimum, &min, 0);
  cb.reason = XmCR_PAGE_INCREMENT;
  cb.event = 0;
  cb.pixel = 0;
  cb.value = v + pi;
  if (cb.value > max - pi) cb.value = max - pi;
  if (cb.value < min) cb.value = min;
  XtCallCallbacks (sb, XmNvalueChangedCallback, &cb);
}


static void
fe_page_backward_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  Widget sb = CONTEXT_DATA (context)->vscroll;
  XmScrollBarCallbackStruct cb;
  int pi = 0, v = 0, min = 0;

  XP_ASSERT(sb);
  if (!sb) return;
  fe_UserActivity (context);
  XtVaGetValues (sb, XmNpageIncrement, &pi, XmNvalue, &v, XmNminimum, &min, 0);
  cb.reason = XmCR_PAGE_INCREMENT;
  cb.event = 0;
  cb.pixel = 0;
  cb.value = v - pi;
  if (cb.value < min) cb.value = min;
  XtCallCallbacks (sb, XmNvalueChangedCallback, &cb);
}


static void
fe_line_forward_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  Widget sb = CONTEXT_DATA (context)->vscroll;
  XmScrollBarCallbackStruct cb;
  int li = 0, v = 0, max = 1, min = 0;

#ifdef EDITOR
  if (context->is_editor) return;
#endif /* EDITOR */
    
  XP_ASSERT(sb);
  if (!sb) return;
  fe_UserActivity (context);
  XtVaGetValues (sb, XmNincrement, &li, XmNvalue, &v,
		 XmNmaximum, &max, XmNminimum, &min, 0);
  cb.reason = XmCR_INCREMENT;
  cb.event = 0;
  cb.pixel = 0;
  cb.value = v + li;
  if (cb.value > max - li) cb.value = max - li;
  if (cb.value < min) cb.value = min;
  XtCallCallbacks (sb, XmNvalueChangedCallback, &cb);
}


static void
fe_line_backward_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  Widget sb = CONTEXT_DATA (context)->vscroll;
  XmScrollBarCallbackStruct cb;
  int li = 0, v = 0, min = 0;

#ifdef EDITOR
  if (context->is_editor) return;
#endif /* EDITOR */
    
  XP_ASSERT(sb);
  if (!sb) return;
  fe_UserActivity (context);
  XtVaGetValues (sb, XmNincrement, &li, XmNvalue, &v, XmNminimum, &min, 0);
  cb.reason = XmCR_INCREMENT;
  cb.event = 0;
  cb.pixel = 0;
  cb.value = v - li;
  if (cb.value < min) cb.value = min;
  XtCallCallbacks (sb, XmNvalueChangedCallback, &cb);
}

static void
fe_column_forward_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  Widget sb = CONTEXT_DATA (context)->hscroll;
  XmScrollBarCallbackStruct cb;
  int li = 0, v = 0, min = 0;

  XP_ASSERT(sb);
  if (!sb) return;
  fe_UserActivity (context);
  XtVaGetValues (sb, XmNincrement, &li, XmNvalue, &v, XmNminimum, &min, 0);
  cb.reason = XmCR_INCREMENT;
  cb.event = 0;
  cb.pixel = 0;
  cb.value = v - li;
  if (cb.value < min) cb.value = min;
  XtCallCallbacks (sb, XmNvalueChangedCallback, &cb);
}


static void
fe_column_backward_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  Widget sb = CONTEXT_DATA (context)->hscroll;
  XmScrollBarCallbackStruct cb;
  int li = 0, v = 0, max = 1, min = 0;

  XP_ASSERT(sb);
  if (!sb) return;
  fe_UserActivity (context);
  XtVaGetValues (sb, XmNincrement, &li, XmNvalue, &v,
		 XmNmaximum, &max, XmNminimum, &min, 0);
  cb.reason = XmCR_INCREMENT;
  cb.event = 0;
  cb.pixel = 0;
  cb.value = v + li;
  if (cb.value > max - li) cb.value = max - li;
  if (cb.value < min) cb.value = min;
  XtCallCallbacks (sb, XmNvalueChangedCallback, &cb);
}


/* File menu
 */

static void
fe_open_url_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  fe_UserActivity (context);
  fe_OpenURLDialog(context);
}

void
fe_upload_file_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  XmString xm_title;
  char *title = XP_GetString(XFE_COMMANDS_UPLOAD_FILE);
  char *file, *msg;

  fe_UserActivity (context);

  file = fe_ReadFileName (context, title, 0, True, 0);

  /* validate filename */
  if (file) {
    if (!fe_isFileExist(file)) {
      msg = PR_smprintf( XP_GetString( XFE_CANNOT_SEE_FILE ), file);
      if (msg) {
	XFE_Alert(context, msg);
	XP_FREE(msg);
      }
      XP_FREE (file);
      file = NULL;
    }
    else if (!fe_isFileReadable(file)) {
      msg = PR_smprintf( XP_GetString( XFE_CANNOT_READ_FILE ) , file);
      if (msg) {
	XFE_Alert(context, msg);
	XP_FREE(msg);
      }
      XP_FREE (file);
      file = NULL;
    }
    else if (fe_isDir(file)) {
      msg = PR_smprintf( XP_GetString( XFE_IS_A_DIRECTORY ), file);
      if (msg) {
	  XFE_Alert(context, msg);
	  if (msg) XP_FREE(msg);
      }
      XP_FREE (file);
      file = NULL;
    }
  }

  if (file)
    {
      History_entry *he = SHIST_GetCurrent (&context->hist);
      URL_Struct *url;

      if (he && he->address && (XP_STRNCMP (he->address, "ftp://", 6) == 0)
	  && he->address [strlen (he->address)-1] == '/')
	{
	  url = NET_CreateURLStruct (he->address, NET_SUPER_RELOAD);
	  if (!url)
	    {
	      XP_FREE (file);
	      return;
	    }
	  url->method = URL_POST_METHOD;
	  url->files_to_post = XP_ALLOC (2);
	  if (!url->files_to_post)
	    {
	      XP_FREE (file);
	      return;
	    }

	  url->files_to_post [0] = XP_STRDUP ((const char *) file);
	  url->files_to_post [1] = 0;

	  fe_GetURL (context, url, FALSE);
	}

      XP_FREE (file);
    }
}

void
fe_reload_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  XmPushButtonCallbackStruct *cd = (XmPushButtonCallbackStruct *) call_data;
  
  fe_UserActivity (context);
  
  if (cd && cd->event->xkey.state & ShiftMask)
    fe_ReLayout (context, NET_SUPER_RELOAD);
  else
    fe_ReLayout (context, NET_NORMAL_RELOAD);
}

/* not static -- it's needed by src/HTMLView.cpp */
void
fe_abort_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  fe_UserActivity (context);
  fe_AbortCallback (widget, closure, call_data);
}

void
fe_refresh_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  Widget wid;
  Display *dpy;
  Window win;
  Dimension w = 0, h = 0;
  XGCValues gcv;
  GC gc;

  if (fe_IsGridParent (context)) context = fe_GetFocusGridOfContext (context);
  XP_ASSERT (context);
  if (!context) return;

  wid = CONTEXT_DATA (context)->drawing_area;
  if (wid == NULL) return;

  dpy = XtDisplay (wid);
  win = XtWindow (wid);

  fe_UserActivity (context);

  XtVaGetValues (wid, XmNbackground, &gcv.foreground,
		 XmNwidth, &w, XmNheight, &h, 0);
  gc = XCreateGC (dpy, win, GCForeground, &gcv);
  XFillRectangle (dpy, win, gc, 0, 0, w, h);
  XFreeGC (dpy, gc);

  if (context->compositor) {
    XP_Rect rect;
    
    rect.left = CONTEXT_DATA(context)->document_x;
    rect.top = CONTEXT_DATA(context)->document_y;
    rect.right = rect.left + w;
    rect.bottom = rect.top + h;
    CL_UpdateDocumentRect(context->compositor,
			  &rect, (PRBool)FALSE);
  }
}


char **fe_encoding_extensions = 0; /* gag.  used by mkcache.c. */



#ifdef EDITOR
/*
 *    Hack, hack, hack. These are in editor.c, please move the menu
 *    definition there.
 */
extern void fe_editor_view_source_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_edit_source_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_browse_doc_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_about_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_open_file_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_edit_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_paragraph_style_menu_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_paragraph_style_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_new_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_new_from_wizard_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_new_from_template_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_open_file_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_save_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_save_as_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_edit_menu_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_undo_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_redo_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_view_menu_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_properties_menu_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_hrule_properties_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_display_tables_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_paragraph_marks_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_insert_menu_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_insert_link_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_insert_target_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_insert_image_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_insert_hrule_dialog_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_insert_html_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_insert_line_break_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_insert_non_breaking_space_cb(Widget,XtPointer,XtPointer);
extern void fe_editor_char_props_menu_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_toggle_char_props_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_char_props_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_clear_char_props_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_font_size_menu_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_font_size_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_paragraph_props_menu_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_paragraph_props_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_indent_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_properties_dialog_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_delete_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_refresh_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_insert_hrule_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_cut_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_copy_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_paste_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_table_menu_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_table_insert_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_table_row_insert_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_table_column_insert_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_table_cell_insert_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_table_delete_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_table_row_delete_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_table_column_delete_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_table_cell_delete_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_file_menu_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_document_properties_dialog_cb(Widget, XtPointer,
						    XtPointer);
extern void fe_editor_preferences_dialog_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_target_properties_dialog_cb(Widget, XtPointer,
						    XtPointer);
extern void fe_editor_html_properties_dialog_cb(Widget, XtPointer,
						XtPointer);
extern void fe_editor_table_properties_dialog_cb(Widget, XtPointer,
						 XtPointer);
extern void fe_editor_publish_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_find_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_find_again_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_windows_menu_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_select_all_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_delete_item_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_select_table_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_reload_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_set_colors_dialog_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_default_color_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_remove_links_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_open_url_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_options_menu_cb(Widget, XtPointer, XtPointer);
extern void fe_editor_browse_publish_location_cb(Widget, XtPointer, XtPointer);

#endif /* EDITOR */

/* not static -- it's needed by src/HTMLView.cpp */
void
fe_save_as_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  URL_Struct *url;

  fe_UserActivity (context);

  {
    MWContext *ctx = fe_GetFocusGridOfContext (context);
    if (ctx)
      context = ctx;
  }

  url =	SHIST_CreateWysiwygURLStruct (context,
					    SHIST_GetCurrent (&context->hist));

  if (url)
    fe_SaveURL (context, url);
  else
    FE_Alert (context, fe_globalData.no_url_loaded_message);
}

/* not static -- it's needed by src/HTMLView.cpp */
void
fe_save_top_frame_as_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  URL_Struct *url;

  fe_UserActivity (context);

  url =	SHIST_CreateWysiwygURLStruct (context,
					    SHIST_GetCurrent (&context->hist));

  if (url)
    fe_SaveURL (context, url);
  else
    FE_Alert (context, fe_globalData.no_url_loaded_message);
}

static unsigned int
fe_save_as_stream_write_ready_method (NET_StreamClass *stream)
{
  return(MAX_WRITE_READY);
}

struct view_source_data
{
  MWContext *context;
  Widget widget;
};


void
fe_view_source_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  History_entry *h;
  URL_Struct *url;
  char *new_url_add=0;

  h = SHIST_GetCurrent (&context->hist);
  url = SHIST_CreateURLStructFromHistoryEntry(context, h);
  if (! url)
    {
      FE_Alert (context, fe_globalData.no_url_loaded_message);
      return;
    }

  /* check to make sure it doesn't already have a view-source
   * prefix.  If it does then this window is already viewing
   * the source of another window.  In this case just
   * show the same thing by reloading the url...
   */
  if(strncmp(VIEW_SOURCE_URL_PREFIX, 
			 url->address, 
			 sizeof(VIEW_SOURCE_URL_PREFIX)-1))
    {
      /* prepend VIEW_SOURCE_URL_PREFIX to the url to
       * get the netlib to display the source view
       */
      StrAllocCopy(new_url_add, VIEW_SOURCE_URL_PREFIX);
      StrAllocCat(new_url_add, url->address);
      free(url->address);
      url->address = new_url_add;
    }

   /* make damn sure the form_data slot is zero'd or else all
    * hell will break loose
    */
   XP_MEMSET (&url->savedData, 0, sizeof (SHIST_SavedData));

#ifdef EDITOR
   if (EDT_IS_EDITOR(context) && !FE_CheckAndSaveDocument(context))
	   return;
#endif

/*
  fe_GetSecondaryURL (context, url, FO_PRESENT, NULL, FALSE);
*/
  fe_GetURL (context, url, FALSE);

}

static int
fe_view_source_stream_write_method (NET_StreamClass *stream, const char *str, int32 len)
{
  struct view_source_data *vsd = (struct view_source_data *) stream->data_object;
  char buf [1024];
  XmTextPosition pos, cpos;

  if (!vsd || !vsd->widget) return -1;
  pos = XmTextGetLastPosition (vsd->widget);
  cpos = 0;
  XtVaGetValues (vsd->widget, XmNcursorPosition, &cpos, 0);

  /* We copy the data first because XmTextInsert() needs a null-terminated
     string, and there isn't necessarily room on the end of `str' for us
     to plop down a null. */
  while (len > 0)
    {
      int i;
      int L = (len > (sizeof(buf)-1) ? (sizeof(buf)-1) : len);
      memcpy (buf, str, L);
      buf [L] = 0;
      str += L;
      len -= L;
      /* Crockishly translate CR to LF for the Motif text widget... */
      for (i = 0; i < L; i++)
	if (buf[i] == '\r' && buf[i+1] != '\n')
	  buf[i] = '\n';
      XmTextInsert (vsd->widget, pos, buf);
      pos += L;
    }
  XtVaSetValues (vsd->widget, XmNcursorPosition, cpos, 0);
  return 1;
}

static void
fe_view_source_stream_complete_method (NET_StreamClass *stream)
{
  struct view_source_data *vsd = (struct view_source_data *) stream->data_object;
  free (vsd);
}

static void
fe_view_source_stream_abort_method (NET_StreamClass *stream, int status)
{
  struct view_source_data *vsd = (struct view_source_data *) stream->data_object;
  free (vsd);
}


/* Creates and returns a stream object which writes the data read into a
   text widget.
 */
NET_StreamClass *
fe_MakeViewSourceStream (int format_out, void *data_obj,
			 URL_Struct *url_struct, MWContext *context)
{
  struct view_source_data *vsd;
  NET_StreamClass* stream;

  if (url_struct->is_binary)
    {
      FE_Alert (context, fe_globalData.binary_document_message);
      return 0;
    }

  vsd = url_struct->fe_data;
  if (! vsd) abort ();
  url_struct->fe_data = 0;

  stream = (NET_StreamClass *) calloc (sizeof (NET_StreamClass), 1);
  if (!stream) return 0;

  stream->name           = "ViewSource";
  stream->complete       = fe_view_source_stream_complete_method;
  stream->abort          = fe_view_source_stream_abort_method;
  stream->put_block      = fe_view_source_stream_write_method;
  stream->is_write_ready = fe_save_as_stream_write_ready_method;
  stream->data_object    = vsd;
  stream->window_id      = context;
  return stream;
}

#if defined(MOZ_MAIL_NEWS) || defined(MOZ_MAIL_COMPOSE)

/* Mailing documents
 */

void
fe_mailNew_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  fe_UserActivity (context);
  MSG_Mail (context);
}


void
fe_mailto_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  fe_UserActivity (context);

  /*
   * You cannot mail a frameset, you must mail the frame child
   * with focus
   */
  if (fe_IsGridParent (context))
    {
      MWContext *ctx = fe_GetFocusGridOfContext (context);
      if (ctx)
        context = ctx;
    }
#ifdef EDITOR
  if (EDT_IS_EDITOR(context))
	  EDT_MailDocument (context);
  else
#endif
	  MSG_MailDocument (context);

}

#endif  /* MOZ_MAIL_NEWS || MOZ_MAIL_COMPOSE */

void
fe_print_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  URL_Struct *url;

  fe_UserActivity (context);

#ifdef EDITOR
  if (EDT_IS_EDITOR(context) && !FE_CheckAndSaveDocument(context))
      return;
#endif

  {
    MWContext *ctx = fe_GetFocusGridOfContext (context);
    if (ctx)
      context = ctx;
  }

  url = SHIST_CreateURLStructFromHistoryEntry (context, SHIST_GetCurrent(&context->hist));
  if (url) {
    /* Free the url struct we created */
    NET_FreeURLStruct(url);

#ifdef X_PLUGINS
    if (CONTEXT_DATA(context)->is_fullpage_plugin) {
      /* Full page plugins need a step here. We need to ask the plugin if
       * it wants to handle the printing.
       */
      NPPrint npprint;
      
      npprint.mode = NP_FULL;
      npprint.print.fullPrint.pluginPrinted = FALSE;
      npprint.print.fullPrint.printOne = TRUE;
      npprint.print.fullPrint.platformPrint = NULL;
      NPL_Print(context->pluginList, &npprint);
      if (npprint.print.fullPrint.pluginPrinted == TRUE)
	return;
    }
#endif /* X_PLUGINS */

    fe_PrintDialog (context);
  }
  else
    FE_Alert(context, fe_globalData.no_url_loaded_message);
}

#define fe_quit_cb fe_QuitCallback
void
fe_QuitCallback (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;

  fe_UserActivity (context);
#ifdef MOZ_MAIL_NEWS
  if (!fe_CheckUnsentMail ())
    return;
  if (!fe_CheckDeferredMail ())
    return;
#endif
#ifdef EDITOR
  if (!fe_EditorCheckUnsaved(context))
      return;
#endif /*EDITOR*/
  if (!CONTEXT_DATA (context)->confirm_exit_p ||
      FE_Confirm (context, fe_globalData.really_quit_message))
    {
      fe_AbortCallback (widget, closure, call_data);
      fe_Exit (0);
    }
}


/* FIND */

void
fe_find_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  MWContext *top_context;

  fe_unset_findcommand_context();

  top_context = XP_GetNonGridContext(context);
  if (!top_context) top_context = context;

  fe_UserActivity (top_context);

  fe_FindDialog (top_context, False);
}


void
fe_find_again_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  MWContext *top_context;
  fe_FindData *find_data;

  fe_unset_findcommand_context();

  top_context = XP_GetNonGridContext(context);
  if (!top_context) top_context = context;

  fe_UserActivity (top_context);

  find_data = CONTEXT_DATA(top_context)->find_data;

  if ((top_context->type == MWContextBrowser
#ifdef MOZ_MAIL_NEWS
	|| top_context->type == MWContextMail
	|| top_context->type == MWContextNews
	|| top_context->type == MWContextMailMsg
#endif
	) &&
      find_data && find_data->string && find_data->string[0] != '\0')
    fe_FindDialog (top_context, True);
  else
    XBell (XtDisplay (widget), 0);
}


#ifdef FORTEZZA

static void
fe_fortezza_card_cb (Widget widget,
		       XtPointer closure,
		       XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  fe_UserActivity (context);

  SSL_FortezzaMenu(context,SSL_FORTEZZA_CARD_SELECT);
}

static void
fe_fortezza_change_cb (Widget widget,
		       XtPointer closure,
		       XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  fe_UserActivity (context);
  SSL_FortezzaMenu(context,SSL_FORTEZZA_CHANGE_PERSONALITY);
}

static void
fe_fortezza_view_cb (Widget widget,
		       XtPointer closure,
		       XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  fe_UserActivity (context);
  SSL_FortezzaMenu(context,SSL_FORTEZZA_VIEW_PERSONALITY);
}

static void
fe_fortezza_info_cb (Widget widget,
		       XtPointer closure,
		       XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  fe_UserActivity (context);
  SSL_FortezzaMenu(context,SSL_FORTEZZA_CARD_INFO);
}

static void
fe_fortezza_logout_cb (Widget widget,
		       XtPointer closure,
		       XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  fe_UserActivity (context);
  SSL_FortezzaMenu(context,SSL_FORTEZZA_LOGOUT);
}
#endif


#define HTTP_OFF		42

	/* "about:document" */
#define DOCINFO			"about:document"

	/* ".netscape.com/" */
#define DOT_NETSCAPE_DOT_COM_SLASH \
				"\130\230\217\236\235\215\213\232\217\130\215"\
				"\231\227\131"

	/* "http://home.netscape.com/" */
#define HTTP_NETSCAPE		"\222\236\236\232\144\131\131\222\231\227\217"\
				"\130\230\217\236\235\215\213\232\217\130\215"\
				"\231\227\131"

	/* "http://cgi.netscape.com/cgi-bin/" */
#define HTTP_CGI		"\222\236\236\232\144\131\131\215\221\223\130"\
				"\230\217\236\235\215\213\232\217\130\215\231"\
				"\227\131\215\221\223\127\214\223\230\131"

        /* "http://home.netscape.com/home/" */
#define HTTP_HOME               "\222\236\236\232\144\131\131\222\231\227\217"\
                                "\130\230\217\236\235\215\213\232\217\130\215"\
                                "\231\227\131\222\231\227\217\131"

        /* "http://home.netscape.com/eng/mozilla/4.0/" */
#define HTTP_ENG                "\222\236\236\232\144\131\131\222\231\227\217"\
                                "\130\230\217\236\235\215\213\232\217\130\215"\
                                "\231\227\131\217\230\221\131\227\231\244\223"\
                		"\226\226\213\131\136\130\132\131"

        /* "http://home.netscape.com/eng/mozilla/2.0/" */
#define HTTP_ENG_2_0            "\222\236\236\232\144\131\131\222\231\227\217"\
                                "\130\230\217\236\235\215\213\232\217\130\215"\
                                "\231\227\131\217\230\221\131\227\231\244\223"\
                                "\226\226\213\131\134\130\132\131"

		/* "http://guide.netscape.com/" */
#define HTTP_GUIDE              "\222\236\236\232\144\131\131\221\237\223"\
                                "\216\217\130\230\217\236\235\215\213\232"\
                                "\217\130\215\231\227\131"

        /* "http://help.netscape.com/" */
#define HTTP_HELP         "\222\236\236\232\144\131\131\222\217\226\232"\
                          "\130\230\217\236\235\215\213\232\217\130\215"\
                          "\231\227\131"

        /* "http://home.netscape.com/info/" */
#define HTTP_INFO               "\222\236\236\232\144\131\131\222\231\227\217"\
                                "\130\230\217\236\235\215\213\232\217\130\215"\
                                "\231\227\131\223\230\220\231\131"

        /* "fishcam/" */
#define HTTP_FC                 HTTP_NETSCAPE \
                                "\220\223\235\222\215\213\227\131"

#ifdef MOZ_MAIL_NEWS
        /* "newsrc:" */
#define HTTP_NEWSRC             "\230\217\241\235\234\215\144"
#endif
 
        /* "whats_new/" */
#define HTTP_WHATS_NEW          HTTP_GUIDE \
                                "\241\222\213\236\235\211\230\217\241\131"
        /* "whats_cool/" */
#define HTTP_WHATS_COOL         HTTP_GUIDE \
                                "\241\222\213\236\235\211\215\231\231\226"\
                                "\131"
        /* "" */
#define HTTP_INET_DIRECTORY     HTTP_GUIDE
 
        /* "internet-search.html" */
#define HTTP_INET_SEARCH        HTTP_HOME "\223\230\236\217\234\230\217\236"\
                                "\127\235\217\213\234\215\222\130\222\236\227"\
                                "\226"
        /* "people/" */
#define HTTP_INET_WHITE         HTTP_GUIDE \
                                "\232\217\231\232\226\217\131"
 
        /* "yellow_pages/" */
#define HTTP_INET_YELLOW        HTTP_GUIDE \
                                "\243\217\226\226\231\241\211\232\213\221"\
                                "\217\235\131"

        /* "about-the-internet.html" */
#define HTTP_INET_ABOUT         HTTP_HOME "\213\214\231\237\236\127\236\222"\
                                "\217\127\223\230\236\217\234\230\217\236\130"\
                                "\222\236\227\226"
 
        /* "update.html" */
#define HTTP_SOFTWARE           HTTP_HOME "\237\232\216\213\236\217\130\222\236\227\226"
 
        /* "how-to-create-web-services.html" */
#define HTTP_HOWTO              HTTP_HOME "\222\231\241\127\236\231\127\215"\
                                "\234\217\213\236\217\127\241\217\214\127\235"\
                                "\217\234\240\223\215\217\235\130\222\236\227"\
                                "\226"
        /* "netscape-galleria.html" */
#define HTTP_GALLERIA           HTTP_HOME "\230\217\236\235\215\213\232\217"\
                                "\127\221\213\226\226\217\234\223\213\130\222"\
                                "\236\227\226"
 
        /* "relnotes/unix-" */
# define HTTP_REL_VERSION_PREFIX HTTP_ENG "\234\217\226\230\231\236\217\235"\
                                "\131\237\230\223\242\127"
 
# define HTTP_BETA_VERSION_PREFIX H_REL_VERSION_PREFIX
 
        /* "reginfo-x.cgi" */
#define HTTP_REG		HTTP_HOME "\234\217\221\223\235\236\217\234\130\222\236\227\226"

 
        /* "handbook/" */
#define HTTP_MANUAL             HTTP_ENG "\222\213\230\216\214\231\231\225\131"

	/* "starter.html" */
#define HTTP_STARTER            HTTP_HOME "\235\236\213\234\236\217\234\130"\
				"\222\236\227\226"

#ifdef NON_BETA
       /* "http://help.netscape.com/faqs.html" */
#define HTTP_FAQ                "\222\236\236\232\144\131\131\222\217\226\232"\
                                "\130\230\217\236\235\215\213\232\217\130\215"\
                                "\231\227\131\220\213\233\235\130\222\236\227"\
                                "\226" 
#else
        /* "eng/beta_central/faq/index.html" */
#define HTTP_FAQ		HTTP_NETSCAPE "\217\230\221\131\214\217\236"\
				"\213\211\215\217\230\236\234\213\226\131\220\213\233"\
				"\131\223\230\216\217\242\130\222\236\227\226"
#endif
 
        /* "security-doc.html" */
#define HTTP_SECURITY           HTTP_INFO "\235\217\215\237\234\223\236\243"\
                                "\127\216\231\215\130\222\236\227\226"
 
#ifdef NON_BETA
        /* "auto_bug.cgi" */
#define HTTP_FEEDBACK		HTTP_CGI "\213\237\236\231\211\214\237\221"\
				"\130\215\221\223"
#else
        /* "eng/beta_central" */
#define HTTP_FEEDBACK		HTTP_NETSCAPE "\217\230\221\131\214\217\236"\
				"\213\211\215\217\230\236\234\213\226"
#endif
 
#ifdef NON_BETA
        /* "http://help.netscape.com/" */
#define HTTP_SUPPORT            "\222\236\236\232\144\131\131\222\217\226\232"\
				"\130\230\217\236\235\215\213\232\217\130\215"\
				"\231\227\131"
#else
        /* "eng/beta_central" */
#define HTTP_SUPPORT		HTTP_NETSCAPE "\217\230\221\131\214\217\236"\
				"\213\211\215\217\230\236\234\213\226"
#endif

#ifdef MOZ_MAIL_NEWS
        /* "news/news.html" */
#define HTTP_USENET         HTTP_ENG_2_0 "\230\217\241\235\131\230\217\241"\
                                "\235\130\222\236\227\226"
#endif

        /* "about:plugins" */
#define HTTP_PLUGINS "\213\214\231\237\236\144\232\226\237\221\223\230\235"

        /* "about:fonts" */
#define HTTP_FONTS "\213\214\231\237\236\144\220\231\230\236\235"

#ifdef __sgi

	/* "http://www.sgi.com/surfer/silicon_sites.html" */
# define HTTP_SGI_MENU "\222\236\236\232\144\131\131\241\241\241\130\235\221"\
		  "\223\130\215\231\227\131\235\237\234\220\217\234\131\235"\
		  "\223\226\223\215\231\230\211\235\223\236\217\235\130\222"\
		  "\236\227\226"

	/* "http://www.sgi.com" */
# define HTTP_SGI_BUTTON "\222\236\236\232\144\131\131\241\241\241\130\235"\
			 "\221\223\130\215\231\227"

	/* "file:/usr/local/lib/netscape/docs/Welcome.html" */
# define HTTP_SGI_WELCOME "\220\223\226\217\144\131\237\235\234\131\226\231"\
			  "\215\213\226\131\226\223\214\131\230\217\236\235"\
			  "\215\213\232\217\131\216\231\215\235\131\201\217"\
			  "\226\215\231\227\217\130\222\236\227\226"

	/* "http://www.adobe.com" */
# define HTTP_ADOBE_MENU "\222\236\236\232\144\131\131\241\241\241\130\213"\
			 "\216\231\214\217\130\215\231\227"

	/* "http://www.sgi.com/surfer/cool_sites.html" */
# define SGI_WHATS_COOL  "\222\236\236\232\144\131\131\241\241\241\130\235"\
			 "\221\223\130\215\231\227\131\235\237\234\220\217"\
			 "\234\131\215\231\231\226\211\235\223\236\217\235"\
			 "\130\222\236\227\226"

	/* "http://www.sgi.com/surfer/netscape/relnotes-" */
# define SGI_VERSION_PREFIX	"\222\236\236\232\144\131\131\241\241\241\130"\
				"\235\221\223\130\215\231\227\131\235\237\234"\
				"\220\217\234\131\230\217\236\235\215\213\232"\
				"\217\131\234\217\226\230\231\236\217\235\127"

#endif /* __sgi */

	/* "products/client/communicator/" */
#define HTTP_PRODUCT_INFO HTTP_HELP "\232\234\231\216\237\215\236"\
				"\235\131\215\226\223\217\230\236\131\215\231\227"\
				"\227\237\230\223\215\213\236\231\234\131"

	/* "http://home.netscape.com/eng/intl/" */
#define HTTP_INTL "\222\236\236\232\144\131\131\222\231\227\217\130"\
				"\230\217\236\235\215\213\232\217\130\215\231\227"\
				"\131\217\230\221\131\223\230\236\226\131"

	/* "services.html" */
#define HTTP_SERVICES HTTP_HOME "\235\217\234\240\223\215\217\235"\
				"\130\222\236\227\226"


static char *
go_get_url(char *which)
{
	char		clas[128];
	char		name[128];
	char		*p;
	char		*ret;
	char		*type;
	XrmValue	value;

	PR_snprintf(clas, sizeof (clas), "%s.Url.Which", fe_progclass);
	PR_snprintf(name, sizeof (name), "%s.url.%s", fe_progclass, which);
	if (XrmGetResource(XtDatabase(fe_display), name, clas, &type, &value))
	{
		ret = strdup(value.addr);
		if (!ret)
		{
			return NULL;
		}
		p = ret;
		while (*p)
		{
			*p += HTTP_OFF;
			p++;
		}
		if (!strstr(ret, DOT_NETSCAPE_DOT_COM_SLASH))
		{
			free(ret);
			return NULL;
		}
		return ret;
	}

	return NULL;
}


#define GO_GET_URL(func, res)			\
	static char *				\
	func(char *builtin)			\
	{					\
		static char	*ret = NULL;	\
						\
		if (ret)			\
		{				\
			return ret;		\
		}				\
						\
		ret = go_get_url(res);		\
		if (ret)			\
		{				\
			return ret;		\
		}				\
						\
		return builtin;			\
	}


GO_GET_URL(go_get_url_plugins, "aboutplugins")
GO_GET_URL(go_get_url_fonts, "aboutfonts")
GO_GET_URL(go_get_url_whats_new, "whats_new")
GO_GET_URL(go_get_url_whats_cool, "whats_cool")
GO_GET_URL(go_get_url_inet_directory, "directory")
GO_GET_URL(go_get_url_inet_search, "search")
GO_GET_URL(go_get_url_inet_white, "white")
GO_GET_URL(go_get_url_inet_yellow, "yellow")
GO_GET_URL(go_get_url_inet_about, "about")
GO_GET_URL(go_get_url_software, "software")
GO_GET_URL(go_get_url_howto, "howto")
GO_GET_URL(go_get_url_netscape, "netscape")
GO_GET_URL(go_get_url_galleria, "galleria")
GO_GET_URL(go_get_url_starter, "starter")
GO_GET_URL(go_get_url_rel_version_prefix, "rel_notes")
GO_GET_URL(go_get_url_reg, "reg")
GO_GET_URL(go_get_url_manual, "manual")
GO_GET_URL(go_get_url_faq, "faq")
GO_GET_URL(go_get_url_usenet, "usenet")
GO_GET_URL(go_get_url_security, "security")
GO_GET_URL(go_get_url_feedback, "feedback")
GO_GET_URL(go_get_url_support, "support")
GO_GET_URL(go_get_url_product_info, "productInfo")
GO_GET_URL(go_get_url_intl, "intl")
GO_GET_URL(go_get_url_services, "services")


#define H_WHATS_NEW             go_get_url_whats_new(HTTP_WHATS_NEW)
#define H_WHATS_COOL            go_get_url_whats_cool(HTTP_WHATS_COOL)
#define H_INET_DIRECTORY        go_get_url_inet_directory(HTTP_INET_DIRECTORY)
#define H_INET_SEARCH           go_get_url_inet_search(HTTP_INET_SEARCH)
#define H_INET_WHITE            go_get_url_inet_white(HTTP_INET_WHITE)
#define H_INET_YELLOW           go_get_url_inet_yellow(HTTP_INET_YELLOW)
#define H_INET_ABOUT            go_get_url_inet_about(HTTP_INET_ABOUT)
#define H_SOFTWARE              go_get_url_software(HTTP_SOFTWARE)
#define H_HOWTO                 go_get_url_howto(HTTP_HOWTO)
#define H_NETSCAPE              go_get_url_netscape(HTTP_NETSCAPE)
#define H_GALLERIA              go_get_url_galleria(HTTP_GALLERIA)
#define H_REL_VERSION_PREFIX    go_get_url_rel_version_prefix(HTTP_REL_VERSION_PREFIX)
#define H_REG                   go_get_url_reg(HTTP_REG)
#define H_MANUAL                go_get_url_manual(HTTP_MANUAL)
#define H_STARTER               go_get_url_starter(HTTP_STARTER)
#define H_FAQ                   go_get_url_faq(HTTP_FAQ)
#define H_USENET                go_get_url_usenet(HTTP_USENET)
#define H_SECURITY              go_get_url_security(HTTP_SECURITY)
#define H_FEEDBACK              go_get_url_feedback(HTTP_FEEDBACK)
#define H_SUPPORT               go_get_url_support(HTTP_SUPPORT)
#define H_PRODUCT_INFO          go_get_url_product_info(HTTP_PRODUCT_INFO)
#define H_INTL                  go_get_url_intl(HTTP_INTL)
#define H_SERVICES              go_get_url_services(HTTP_SERVICES)

/*
 * EXPORT_URL creates a function that returns a localized URL.
 * It is needed by the e-kit in order to allow localized URL's.
 */
#define EXPORT_URL(func, builtin) char* xfe_##func(void) {return func(builtin);}

EXPORT_URL(go_get_url_plugins, HTTP_PLUGINS)
EXPORT_URL(go_get_url_fonts, HTTP_FONTS)
EXPORT_URL(go_get_url_whats_new, HTTP_WHATS_NEW)
EXPORT_URL(go_get_url_whats_cool, HTTP_WHATS_COOL)
EXPORT_URL(go_get_url_inet_directory, HTTP_INET_DIRECTORY)
EXPORT_URL(go_get_url_inet_search, HTTP_INET_SEARCH)
EXPORT_URL(go_get_url_inet_white, HTTP_INET_WHITE)
EXPORT_URL(go_get_url_inet_yellow, HTTP_INET_YELLOW)
EXPORT_URL(go_get_url_inet_about, HTTP_INET_ABOUT)
EXPORT_URL(go_get_url_software, HTTP_SOFTWARE)
EXPORT_URL(go_get_url_howto, HTTP_HOWTO)
EXPORT_URL(go_get_url_netscape, HTTP_NETSCAPE)
EXPORT_URL(go_get_url_galleria, HTTP_GALLERIA)
EXPORT_URL(go_get_url_reg, HTTP_REG)
EXPORT_URL(go_get_url_manual, HTTP_MANUAL)
EXPORT_URL(go_get_url_starter, HTTP_STARTER)
EXPORT_URL(go_get_url_faq, HTTP_FAQ)
#ifdef MOZ_MAIL_NEWS
EXPORT_URL(go_get_url_usenet, HTTP_USENET)
#endif
EXPORT_URL(go_get_url_security, HTTP_SECURITY)
EXPORT_URL(go_get_url_feedback, HTTP_FEEDBACK)
EXPORT_URL(go_get_url_support, HTTP_SUPPORT)
EXPORT_URL(go_get_url_product_info, HTTP_PRODUCT_INFO)
EXPORT_URL(go_get_url_intl, HTTP_INTL)
EXPORT_URL(go_get_url_services, HTTP_SERVICES)

/*
 * xfe_go_get_url_relnotes
 */
char*
xfe_go_get_url_relnotes(void)
{
  static char* url = NULL;

  if ( url == NULL ) {
      char buf[1024];
      char* ptr;
      char* prefix = (strchr(fe_version, 'a') || strchr(fe_version, 'b'))
                     ? HTTP_BETA_VERSION_PREFIX
                     : H_REL_VERSION_PREFIX;

      sprintf(buf, "%s.html", fe_version);

      for ( ptr = buf; *ptr; ptr++ ) {
          *ptr+= HTTP_OFF;
      }
      url = (char*) malloc(strlen(prefix)+strlen(buf)+1);
      strcpy(url, prefix);
      strcat(url, buf);
  }

  return url;
}

void
fe_docinfo_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  char buf [1024], *in, *out;
  fe_UserActivity (context);
  for (in = DOCINFO, out = buf; *in; in++, out++) *out = *in - HTTP_OFF;
    *out = 0;

#ifdef EDITOR
  if (EDT_IS_EDITOR(context) && !FE_CheckAndSaveDocument(context))
    return;
#endif
  /* @@@@ this is the proper way to do it but I dont'
   * know the encoding scheme
   * fe_GetURL (context,NET_CreateURLStruct(buf, FALSE), FALSE);
   */
  fe_GetURL (context,NET_CreateURLStruct(DOCINFO, FALSE), FALSE);

#ifdef EDITOR
  fe_EditorRefresh(context);
#endif
}

char *
xfe_get_netscape_home_page_url()
{
  static char buf [128];
  char *in, *out;
  for (in = H_NETSCAPE, out = buf; *in; in++, out++) *out = *in - HTTP_OFF;
  *out = 0;
  return buf;
}

static void
fe_net_showstatus_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  char *rv;

  fe_UserActivity (context);
  rv = NET_PrintNetlibStatus();
  NET_ToggleTrace();  /* toggle trace mode on and off */
  XFE_Alert (context, rv);
  free(rv);
}

static void
fe_fishcam_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  char buf [1024], *in, *out;
  fe_UserActivity (context);
  for (in = HTTP_FC, out = buf; *in; in++, out++) *out = *in - HTTP_OFF;
  *out = 0;
  fe_GetURL (context,NET_CreateURLStruct(buf, FALSE), FALSE);
}

void
fe_SearchCallback (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  char* url;
  fe_UserActivity (context);
  if ( PREF_GetUrl("internal_url.net_search", &url) ) {
    fe_GetURL (context,NET_CreateURLStruct(url, FALSE), FALSE);
  }
}

void
fe_GuideCallback (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  char* url = NULL;
  int ok;

  fe_UserActivity (context);

  ok = PREF_CopyConfigString("toolbar.places.default_url",&url);

  if (ok == PREF_NOERROR) 
  {
      FE_GetURL(context,NET_CreateURLStruct(url,NET_DONT_RELOAD));
  }                                                                       
  
  if (url)
  {
      XP_FREE(url);  
  }
}

void
fe_NetscapeCallback (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  char* url;
  fe_UserActivity (context);

  if ( PREF_GetUrl("toolbar.logo", &url) ) {
	  /*
	   *    Call this guy, it will sort out if the current context
	   *    is suitable, etc...
	   */
	  FE_GetURL(context,  NET_CreateURLStruct(url, NET_DONT_RELOAD));
  }
}

#ifdef __sgi
static void
fe_sgi_menu_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  char buf [1024], *in, *out;
  fe_UserActivity (context);
  for (in = HTTP_SGI_MENU, out = buf; *in; in++, out++) *out = *in - HTTP_OFF;
  *out = 0;
  fe_GetURL (context, NET_CreateURLStruct (buf, FALSE), FALSE);
}

static void
fe_adobe_menu_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  char buf [1024], *in, *out;
  fe_UserActivity (context);
  for (in = HTTP_ADOBE_MENU, out = buf; *in; in++, out++)
    *out = *in - HTTP_OFF;
  *out = 0;
  fe_GetURL (context, NET_CreateURLStruct (buf, FALSE), FALSE);
}

void
fe_SGICallback (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  char buf [1024], *in, *out;
  fe_UserActivity (context);
  for (in = HTTP_SGI_BUTTON, out = buf; *in; in++, out++)
    *out = *in - HTTP_OFF;
  *out = 0;
  fe_GetURL (context, NET_CreateURLStruct (buf, FALSE), FALSE);
}

void
fe_sgi_welcome_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  char buf [1024], *in, *out;
  fe_UserActivity (context);
  for (in = HTTP_SGI_WELCOME, out = buf; *in; in++, out++)
    *out = *in - HTTP_OFF;
  *out = 0;
  fe_GetURL (context, NET_CreateURLStruct (buf, FALSE), FALSE);
}
#endif /* __sgi */

#ifdef JAVA

void
fe_new_show_java_console_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  LJ_HideConsole();
  LJ_ShowConsole();
}

#endif

void
fe_load_images_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  fe_UserActivity (context);
  fe_LoadDelayedImages (context);
}

/* Navigate menu
 */

/* not static -- it's needed by src/HTMLView.cpp */
void
fe_back_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  MWContext *top_context = XP_GetNonGridContext(context);
  URL_Struct *url;
  if (fe_IsGridParent(top_context))
    {
        if (LO_BackInGrid(top_context))
          {
            return;
          }
    }
  fe_UserActivity (top_context);
  url = SHIST_CreateURLStructFromHistoryEntry (top_context,
					       SHIST_GetPrevious (top_context));
  if (url)
    {
      fe_GetURL (top_context, url, FALSE);
    }
  else
    {
      FE_Alert (top_context, fe_globalData.no_previous_url_message);
    }
}

/* not static -- it's needed by src/HTMLView.cpp */
void
fe_forward_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  MWContext *top_context = XP_GetNonGridContext(context);
  URL_Struct *url;
  if (fe_IsGridParent(top_context))
    {
        if (LO_ForwardInGrid(top_context))
          {
            return;
          }
    }
  fe_UserActivity (top_context);
  url = SHIST_CreateURLStructFromHistoryEntry (top_context,
					       SHIST_GetNext (top_context));
  if (url)
    {
      fe_GetURL (top_context, url, FALSE);
    }
  else
    {
      FE_Alert (top_context, fe_globalData.no_next_url_message);
    }
}

/* not static -- it's needed by src/HTMLView.cpp ; BrowserFrame.cpp */
void
fe_home_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  URL_Struct *url;
  MWContext *context = (MWContext *) closure;
  fe_UserActivity (context);
  if (!fe_globalPrefs.home_document || !*fe_globalPrefs.home_document)
    {
      XClearArea (XtDisplay (CONTEXT_WIDGET (context)),
		  XtWindow (CONTEXT_DATA (context)->drawing_area), 
		  0, 0,
		  CONTEXT_DATA (context)->scrolled_width,
		  CONTEXT_DATA (context)->scrolled_height, 
		  False);
      FE_Alert (context, fe_globalData.no_home_url_message);
      return;
    }
  url = NET_CreateURLStruct (fe_globalPrefs.home_document, FALSE);
  fe_GetURL ((MWContext *) closure, url, FALSE);
}

/* Help menu
 */
void
fe_about_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;

  fe_UserActivity (context);

  fe_reuseBrowser(context, NET_CreateURLStruct ("about:", FALSE));
}

void
fe_manual_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  char* url;
  char buf[1024], *in, *out;

  fe_UserActivity (context);

  url = HTTP_MANUAL;

  if ( url ) {
	for (in = url, out = buf; *in; in++, out++) *out = *in - HTTP_OFF;
	*out = 0;
	
	fe_reuseBrowser(context, NET_CreateURLStruct (buf, FALSE));
  }
}

#ifdef X_PLUGINS
void
fe_aboutPlugins_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  fe_UserActivity (context);
  fe_GetURL (context, NET_CreateURLStruct ("about:plugins", FALSE), FALSE);
}
#endif /* X_PLUGINS */

void
fe_aboutFonts_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  fe_UserActivity (context);
  fe_GetURL (context, NET_CreateURLStruct ("about:fonts", FALSE), FALSE);
}

/* Message composition stuff. */

void
fe_mailcompose_obeycb(MWContext *context, fe_MailComposeCallback cbid,
			void *call_data)
{
    switch (cbid) {
	case ComposeClearAllText_cb: {
	    Widget text = CONTEXT_DATA (context)->mcBodyText;
	    fe_SetTextFieldAndCallBack(text, "");
	    break;
	}
	case ComposeSelectAllText_cb: {
	    Widget text = CONTEXT_DATA (context)->mcBodyText;
	    XmPushButtonCallbackStruct *cb = (XmPushButtonCallbackStruct *)
						call_data;
	    if (cb)
		XmTextSetSelection(text, 0, XmTextGetLastPosition(text),
					cb->event->xkey.time);
	    break;
	}
    default:
      XP_ASSERT (0);
      break;
    }
}

#if defined(MOZ_MAIL_NEWS) || defined(MOZ_MAIL_COMPOSE)
void
FE_InsertMessageCompositionText(MSG_Pane* comppane,
				const char* text,
				XP_Bool leaveCursorAtBeginning) {

  MWContext* context = MSG_GetContext(comppane);
  /* call - function defined in src/ComposeView.cpp */
  fe_InsertMessageCompositionText(context, text, leaveCursorAtBeginning);
  return;
}
#endif  /* MOZ_MAIL_NEWS || MOZ_MAIL_COMPOSE */

/* rlogin 
 */

void
FE_ConnectToRemoteHost (MWContext *context, int url_type, char *hostname,
			char *port, char *username)
{
  char *name;
  const char *command;
  const char *user_command;
  char *buf;
  const char *in;
  char *out;
  char **av, **ac, **ae;
  int na;
  Boolean cop_out_p = False;
  pid_t forked;

  switch (url_type)
    {
    case FE_TELNET_URL_TYPE:
      name = "telnet";
      command = fe_globalPrefs.telnet_command;
      user_command = 0 /* fe_globalPrefs.telnet_user_command */;
      break;
    case FE_TN3270_URL_TYPE:
      name = "tn3270";
      command = fe_globalPrefs.tn3270_command;
      user_command = 0 /* fe_globalPrefs.tn3270_user_command */;
      break;
    case FE_RLOGIN_URL_TYPE:
      name = "rlogin";
      command = fe_globalPrefs.rlogin_command;
      user_command = fe_globalPrefs.rlogin_user_command;
      break;
    default:
      abort ();
    }

  if (username && user_command && *user_command)
    command = user_command;
  else if (username)
    cop_out_p = True;

  buf = (char*) malloc( strlen(command) + 1
    + (hostname && *hostname ? strlen(hostname) : strlen("localhost"))
    + (username && *username ? strlen(username) : 0)
    + (port && *port ? strlen(port) : 0) );
  ac = av = (char**) malloc(10 * sizeof (char*));
  if (buf == NULL || av == NULL)
    goto malloc_lossage;
  ae = av + 10;
  in = command;
  *ac = out = buf;
  na = 0;
  while (*in)
    {
      if (*in == '%')
	{
	  in++;
	  if (*in == 'h')
	    {
	      char *s;
	      char *h = (hostname && *hostname ? hostname : "localhost");

	      /* Only allow the hostname to contain alphanumerics or
		 _ - and . to prevent people from embedding shell command
		 security holes in the host name. */
	      for (s = h; *s; s++)
		if (*s == '_' || (*s == '-' && s != h) || *s == '.' ||
		    isalpha(*s) || isdigit(*s))
		  *out++ = *s;
	    }
	  else if (*in == 'p')
	    {
	      if (port && *port)
		{
		  int port_num = atoi(port);

		  if (port_num > 0)
		    {
		      char buf1[6];
		      PR_snprintf (buf1, sizeof (buf1), "%.5u", port_num);
		      strcpy(out, buf1);
		      out += strlen(buf1);
		    }
		}
	    }
	  else if (*in == 'u')
	    {
	      char *s;
	      /* Only allow the user name to contain alphanumerics or
		 _ - and . to prevent people from embedding shell command
		 security holes in the host name. */
	      if (username && *username)
		{
		  for (s = username; *s; s++)
		    if (*s == '_' || (*s == '-' && s != username) ||
			*s == '.' || isalpha(*s) || isdigit(*s))
		      *out++ = *s;
		}
	    }
	  else if (*in == '%')
	    {
	      *out++ = '%';
	    }
	  else
	    {
	      char buf2 [255];
	      PR_snprintf (buf2, sizeof (buf2),
				 XP_GetString( XFE_UNKNOWN_ESCAPE_CODE ), name, *in);
	      FE_Alert (context, buf2);
	    }
	  if (*in)
	    in++;
	}
      else if (*in == ' ')
	{
	  if (out != *ac)
	    {
	      *out++ = '\0';
	      na++;
	      if (++ac == ae)
		{
		  av = (char**) realloc(av, (na + 10) * sizeof (char*));
		  if (av == NULL)
		    goto malloc_lossage;
		  ac = av + na;
		  ae = ac + 10;
		}
	      *ac = out;
	    }
	  in++;
	}
      else
	{
	  *out = *in;
	  out++;
	  in++;
	}
    }

  if (out != *ac)
    {
      *out = '\0';
      na++;
      ac++;
    }
  if (ac == ae)
    {
      av = (char**) realloc(av, (na + 1) * sizeof (char*));
      if (av == NULL)
	goto malloc_lossage;
      ac = av + na;
    }
  *ac = 0;

  if (cop_out_p)
    {
      char buf2 [1024];
      PR_snprintf (buf2, sizeof (buf2), XP_GetString(XFE_LOG_IN_AS), username);
      fe_Message (context, buf2);
    }

  switch (forked = fork ())
    {
    case -1:
      fe_perror (context, XP_GetString( XFE_COULDNT_FORK ) );
      break;
    case 0:
      {
	Display *dpy = XtDisplay (CONTEXT_WIDGET (context));
	close (ConnectionNumber (dpy));

	execvp (av [0], av);

	PR_snprintf (buf, sizeof (buf), XP_GetString( XFE_EXECVP_FAILED ),
			fe_progname, av[0]);
	perror (buf);
	exit (1);	/* Note that this only exits a child fork.  */
	break;
      }
    default:
      /* This is the "old" process (subproc pid is in `forked'.) */
      break;
    }
  free(av);
  free(buf);
  return;

malloc_lossage:
  if (av) free(av);
  if (buf) free(buf);
  fe_Message (context, XP_GetString(XFE_OUT_OF_MEMORY_URL));
}

/* The popup menu
 */

URL_Struct *fe_url_under_mouse = 0;
URL_Struct *fe_image_under_mouse = 0;

static void
fe_save_image_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  XmString xm_title = 0;
  char *title = 0;
  URL_Struct *url;

  fe_UserActivity (context);

  XtVaGetValues (widget, XmNlabelString, &xm_title, 0);
  XmStringGetLtoR (xm_title, XmFONTLIST_DEFAULT_TAG, &title);
  XmStringFree(xm_title);

  url =	fe_image_under_mouse;
  if (! url)
    FE_Alert (context, fe_globalData.not_over_image_message);
  if (title) free (title);
  if (url)
    fe_SaveURL (context, url);
  fe_image_under_mouse = 0; /* it will be freed in the exit routine. */
}


static void
fe_save_link_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  XmString xm_title = 0;
  char *title = 0;
  URL_Struct *url;

  fe_UserActivity (context);

  XtVaGetValues (widget, XmNlabelString, &xm_title, 0);
  XmStringGetLtoR (xm_title, XmFONTLIST_DEFAULT_TAG, &title);
  XmStringFree(xm_title);

  url =	fe_url_under_mouse;
  if (! url)
    FE_Alert (context, fe_globalData.not_over_link_message);
  if (title) free (title);
  if (url)
    fe_SaveURL (context, url);
  fe_url_under_mouse = 0; /* it will be freed in the exit routine. */
}

static void
fe_open_image_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  URL_Struct *url;
  fe_UserActivity (context);
  url =	fe_image_under_mouse;
  if (! url)
    FE_Alert (context, fe_globalData.not_over_image_message);
  else
    {
      fe_GetURL (XP_GetNonGridContext(context), url, FALSE);
      fe_image_under_mouse = 0; /* it will be freed in the exit routine. */
    }
}

static void
fe_clipboard_url_1 (Widget widget, XtPointer closure, XtPointer call_data,
					URL_Struct *url, char* html)
{
  MWContext *context = (MWContext *) closure;
  XmPushButtonCallbackStruct *cb = (XmPushButtonCallbackStruct *) call_data;
  XEvent *event = (cb ? cb->event : 0);
  Time time = (event && (event->type == KeyPress ||
			 event->type == KeyRelease)
	       ? event->xkey.time :
	       event && (event->type == ButtonPress ||
			 event->type == ButtonRelease)
	       ? event->xbutton.time :
	       XtLastTimestampProcessed (XtDisplay(CONTEXT_WIDGET (context))));
  fe_UserActivity (context);

  if (! url)
    FE_Alert (context, fe_globalData.not_over_link_message);
  else
    {
		fe_OwnClipboard(widget, time,
						strdup (url->address), html, NULL, 0, False);
#ifdef NOT_rhess
		/*
		 * NOTE:  it's not really valid to make a primary selection if you
		 *        can't show the selection on the display...
		 *        [ this is a hidden selection ]
		 *
		 */
		fe_OwnPrimarySelection(widget, time, 
							   strdup (url->address), html, NULL, 0, context);
#endif
		NET_FreeURLStruct (url);
    }
}

static char fe_link_html_head[]   = "<A HREF=\"";
static char fe_link_html_middle[] = "\" >";
static char fe_link_html_tail[]   = "</A>";

static char fe_image_html_head[]  = "<IMG SRC=\"";
static char fe_image_html_tail[]  = "\" ALT=\"Image\" BORDER=0 >";

#define XFE_LINK_HTML_HEAD   (fe_link_html_head)
#define XFE_LINK_HTML_MIDDLE (fe_link_html_middle)
#define XFE_LINK_HTML_TAIL   (fe_link_html_tail)

#define XFE_IMAGE_HTML_HEAD  (fe_image_html_head)
#define XFE_IMAGE_HTML_TAIL  (fe_image_html_tail)

void
fe_clipboard_link_cb (Widget widget, XtPointer closure, 
					  XtPointer call_data,
					  URL_Struct *url)
{
	char *html = NULL;
	char *link = url->address;
	int32 len = strlen(link);
	char *head = XFE_LINK_HTML_HEAD;
	char *midd = XFE_LINK_HTML_MIDDLE;
	char *tail = XFE_LINK_HTML_TAIL;

	html = XP_ALLOC(len + len + 2 +
					strlen(head) + strlen(midd) + strlen(tail)
					);
	sprintf(html, "%s%s%s%s%s\0", head, link, midd, link, tail);

	fe_clipboard_url_1 (widget, closure, call_data, url, html);
	XP_FREE(html);
}

void
fe_clipboard_image_link_cb (Widget widget, XtPointer closure, 
							XtPointer call_data,
							URL_Struct *url, URL_Struct *img)
{
	char *html = NULL;
	char *link = url->address;
	int32 len = strlen(link);
	char *head = XFE_LINK_HTML_HEAD;
	char *midd = XFE_LINK_HTML_MIDDLE;
	char *tail = XFE_LINK_HTML_TAIL;

	if (!img) {
		html = XP_ALLOC(len + len + 2 +
						strlen(head) + strlen(midd) + strlen(tail)
						);
		sprintf(html, "%s%s%s%s%s\0", head, link, midd, link, tail);

		fe_clipboard_url_1 (widget, closure, call_data, url, html);
		XP_FREE(html);
	}
	else {
		char *image = img->address;
		char *ihead = XFE_IMAGE_HTML_HEAD;
		char *itail = XFE_IMAGE_HTML_TAIL;

		html = XP_ALLOC(len + 2 + strlen(image) +
						strlen(head) + strlen(midd) + strlen(tail) +
						strlen(ihead) + strlen(itail)
						);
		sprintf(html, "%s%s%s%s%s%s%s\0", 
				head, link, midd, ihead, image, itail, tail);

		fe_clipboard_url_1 (widget, closure, call_data, url, html);
		NET_FreeURLStruct (img);
	}
	XP_FREE(html);
}

void
fe_clipboard_image_cb (Widget widget, XtPointer closure, 
					   XtPointer call_data,
					   URL_Struct *url)
{
	char *html = NULL;
	char *link = url->address;
	int32 len = strlen(link);

	char *head = XFE_IMAGE_HTML_HEAD;
	char *tail = XFE_IMAGE_HTML_TAIL;

	html = XP_ALLOC(len + 2 + strlen(head) + strlen(tail));

	sprintf(html, "%s%s%s\0", head, link, tail);

	fe_clipboard_url_1 (widget, closure, call_data, url, html);
	XP_FREE(html);
}

/*
 * For scrolling the window with the arrow keys, we need to
 * insert a lookahead key eater into each action routine,
 * else it is possible to queue up too many key events, and
 * screw up our careful scroll/expose event timing.
 */
static void
fe_eat_window_key_events(Display *display, Window window)
{
  XEvent event;

  XSync(display, FALSE);
  while (XCheckTypedWindowEvent(display, window, KeyPress, &event) == TRUE);
}


static void
fe_column_forward_action (Widget widget, XEvent *event,
			  String *av, Cardinal *ac)
{
  XKeyEvent *kev = (XKeyEvent *)event;
  MWContext *context = fe_WidgetToMWContext (widget);
  XP_ASSERT (context);
  if (!context) return;

  fe_column_forward_cb (widget, (XtPointer)context, (XtPointer)0);
  fe_eat_window_key_events(XtDisplay(widget), kev->window);
}


static void
fe_column_backward_action (Widget widget, XEvent *event,
			  String *av, Cardinal *ac)
{
  XKeyEvent *kev = (XKeyEvent *)event;
  MWContext *context = fe_WidgetToMWContext (widget);
  XP_ASSERT (context);
  if (!context) return;

  fe_column_backward_cb (widget, (XtPointer)context, (XtPointer)0);
  fe_eat_window_key_events(XtDisplay(widget), kev->window);
}


static void
fe_line_forward_action (Widget widget, XEvent *event,
			  String *av, Cardinal *ac)
{
  XKeyEvent *kev = (XKeyEvent *)event;
  MWContext *context = fe_WidgetToMWContext (widget);
  XP_ASSERT (context);
  if (!context) return;

  fe_line_forward_cb (widget, (XtPointer)context, (XtPointer)0);
  fe_eat_window_key_events(XtDisplay(widget), kev->window);
}


static void
fe_line_backward_action (Widget widget, XEvent *event,
			  String *av, Cardinal *ac)
{
  XKeyEvent *kev = (XKeyEvent *)event;
  MWContext *context = fe_WidgetToMWContext (widget);
  XP_ASSERT (context);
  if (!context) return;

  fe_line_backward_cb (widget, (XtPointer)context, (XtPointer)0);
  fe_eat_window_key_events(XtDisplay(widget), kev->window);
}


/* Actions for use in translations tables. 
 */

#define DEFACTION(NAME) \
static void \
fe_##NAME##_action (Widget widget, XEvent *event, String *av, Cardinal *ac) \
{  \
  MWContext *context = fe_WidgetToMWContext (widget); \
  XP_ASSERT (context); \
  if (!context) return; \
  fe_##NAME##_cb (widget, (XtPointer)context, (XtPointer)0); \
}

/* DEFACTION (new) */
/*DEFACTION (open_url)*/
/*DEFACTION (open_file)*/
#ifdef EDITOR
/*DEFACTION (edit)*/
#endif /* EDITOR */
/*DEFACTION (save_as)*/
/*DEFACTION (mailto)*/
/*DEFACTION (print)*/
/* DEFACTION (docinfo) */
/*DEFACTION (delete)*/
/* DEFACTION (quit) */
/* DEFACTION (cut) */
/* DEFACTION (copy) */
/* DEFACTION (paste) */
/* DEFACTION (paste_quoted) */
/*DEFACTION (find)*/
/* DEFACTION (find_again) */
/* DEFACTION (reload) */
/* DEFACTION (load_images) */
/* DEFACTION (refresh) */
/* DEFACTION (view_source) */
/* DEFACTION (back) */
/* DEFACTION (forward) */
/* DEFACTION (history) */
/* DEFACTION (home) */
/*DEFACTION (save_options)*/
/* DEFACTION (view_bookmark) */
DEFACTION (fishcam)
DEFACTION (net_showstatus)
/* DEFACTION (abort) */
DEFACTION (page_forward)
DEFACTION (page_backward)
/*DEFACTION (line_forward)*/
/*DEFACTION (line_backward)*/
/*DEFACTION (column_forward)*/
/*DEFACTION (column_backward)*/

DEFACTION (save_image)
DEFACTION (open_image)
DEFACTION (save_link)
/*DEFACTION (follow_link)*/
/*DEFACTION (follow_link_new)*/
#undef DEFACTION

static void
fe_open_url_action (Widget widget, XEvent *event, String *av, Cardinal *ac)
{
  /* openURL() pops up a file requestor.
     openURL(http:xxx) opens that URL.
     Really only one arg is meaningful, but we also accept the form
     openURL(http:xxx, remote) for the sake of remote.c, and treat
     openURL(remote) the same as openURL().
   */
  MWContext *context = fe_WidgetToMWContext (widget);
  MWContext *old_context = NULL;
  Boolean other_p = False;
  char *windowName = 0;
  XP_ASSERT (context);
  if (!context) return;
  context = XP_GetNonGridContext (context);
  fe_UserActivity (context);

  if (*ac && av[*ac-1] && !strcmp (av[*ac-1], "<remote>"))
    (*ac)--;

  if (*ac > 1 && av[*ac-1] )
  {
     if ( 
      (!strcasecomp (av[*ac-1], "new-window") ||
       !strcasecomp (av[*ac-1], "new_window") ||
       !strcasecomp (av[*ac-1], "newWindow") ||
       !strcasecomp (av[*ac-1], "new")))
    {
      other_p = True;
      (*ac)--;
    }
    else if ( (old_context = XP_FindNamedContextInList(context, av[*ac-1])))
    {
	context = old_context;
	other_p = False;
        (*ac)--;
    }
    else 
    {
	StrAllocCopy(windowName, av[*ac-1]);
	other_p = True;
        (*ac)--;
    }

   }

  if (*ac == 1 && av[0])
    {
      URL_Struct *url_struct = NET_CreateURLStruct (av[0], FALSE);

#if defined(MOZ_MAIL_NEWS) || defined(MOZ_MAIL_COMPOSE)
      /* Dont create new windows for Compose. fe_GetURL will take care of it */
      if (MSG_RequiresComposeWindow(url_struct->address))
	other_p = False;
#endif

      if (other_p)
      {
	context = fe_MakeWindow (XtParent (CONTEXT_WIDGET (context)),
		       context, url_struct, windowName, 
			MWContextBrowser, FALSE);
        XP_FREE(windowName);
      }
      else
	fe_GetURL (context, url_struct, FALSE);
    }
  else if (*ac > 1)
    {
      fprintf (stderr, 
	       XP_GetString(XFE_COMMANDS_OPEN_URL_USAGE),
	       fe_progname);
    }
  else
    {
      fe_open_url_cb (widget, (XtPointer)context, (XtPointer)0);
    }
}

static void
fe_print_remote_action (Widget widget, XEvent *event, String *av, Cardinal *ac)
{
  /* Silent print for remote. Valid invocations are
     print(filename, remote)           : print URL of context to filename
     print(remote)                     : print URL of context to printer
     print(remote)                     : print URL of context to printer
  */
  MWContext *context = fe_WidgetToMWContext (widget);
  URL_Struct *url_struct = NULL;
  Boolean toFile = False;
  char *filename = NULL;

  XP_ASSERT (context);
  if (!context) return;
  fe_UserActivity (context);

  if (*ac && av[*ac-1] && !strcmp (av[*ac-1], "<remote>"))
    (*ac)--;
  else
    return;    /* this is valid only for remote */

  if (*ac && av[*ac-1]) {
    filename = av[*ac-1];
    if (*filename) toFile = True;
    (*ac)--;
  }

  if (*ac > 0)
    fprintf (stderr, "%s: usage: print([filename])\n", fe_progname);

  url_struct = SHIST_CreateWysiwygURLStruct (context,
                                       SHIST_GetCurrent (&context->hist));

  if (url_struct)
    {
      if (!toFile || filename)
    fe_Print(context, url_struct, toFile, filename);
      else
        NET_FreeURLStruct (url_struct);
    }
}

#if defined(MOZ_MAIL_NEWS) || defined(MOZ_MAIL_COMPOSE)
static void
fe_mailto_action (Widget widget, XEvent *event, String *av, Cardinal *ac)
{
  /* see also fe_open_url_action()

     #### This really ought to be implemented by opening a "mailto:" URL,
     instead of by calling MSG_ComposeMessage -- that'd be more abstract
     and stuff.  -jwz
   */

  MWContext *context = fe_WidgetToMWContext (widget);
  XP_ASSERT (context);
  if (!context) return;
  fe_UserActivity (context);
  if (*ac && av[*ac-1] && !strcmp (av[*ac-1], "<remote>"))
    (*ac)--;
  if (*ac >= 1)
    {
      char *to;
      int size = 0;
      int i;
      for (i = 0; i < *ac; i++)
	size += (strlen (av[i]) + 2);
      to = (char *) malloc (size + 1);
      *to = 0;
      for (i = 0; i < *ac; i++)
	{
	  strcat (to, av[i]);
	  if (i < (*ac)-1)
	    strcat (to, ", ");
	}

      MSG_ComposeMessage (context,
			  0, /* from */
			  0, /* reply_to */
			  to,
			  0, /* cc */
			  0, /* bcc */
			  0, /* fcc */
			  0, /* newsgroups */
			  0, /* followup_to */
			  0, /* organization */
			  0, /* subject */
			  0, /* references */
			  0, /* other_random_headers */
			  0, /* priority */
			  0, /* attachment */
			  0, /* newspost_url */
			  0, /* body */
			  FALSE, /* force_plain_text */
			  0 /* html_part */
			  );
    }
  else if (*ac > 1)
    {
      fprintf (stderr, 
			   XP_GetString(XFE_COMMANDS_MAIL_TO_USAGE),
			   fe_progname);
    }
  else
    {
      fe_mailto_cb (widget, (XtPointer)context, (XtPointer)0);
    }
}
#endif  /* MOZ_MAIL_NEWS || MOZ_MAIL_COMPOSE */

static void
fe_html_help_action (Widget widget, XEvent *event, String *av, Cardinal *ac)
{
  MWContext *context = fe_WidgetToMWContext (widget);
  XP_Bool remote_p = False;
  char *map_file_url;
  char *id;
  char *search_text;

  XP_ASSERT (context);
  if (!context) return;
  fe_UserActivity (context);
  if (*ac && av[*ac-1] && !strcmp (av[*ac-1], "<remote>")) {
    remote_p = True;
    (*ac)--;
  }

  if (*ac == 3) {
    map_file_url = av[0];
    id = av[1];
    search_text = av[2];
    NET_GetHTMLHelpFileFromMapFile(context, map_file_url, id, search_text);
  }
  else {
      fprintf (stderr,
			   XP_GetString(XFE_COMMANDS_HTML_HELP_USAGE),
			   fe_progname);
  }
}


static void
fe_deleteKey_action (Widget widget, XEvent *event, String *av, Cardinal *ac)
{
  MWContext *context = fe_WidgetToMWContext (widget);

  XP_ASSERT(context);
  if (!context) return;

#ifdef MOZ_MAIL_NEWS
  if (context->type == MWContextMail || context->type == MWContextNews)
    XP_ASSERT(0);
  else
#endif  /* MOZ_MAIL_NEWS */
    fe_page_backward_action(widget, event, av, ac);
}

static void
fe_undefined_key_action (Widget widget, XEvent *event,
			 String *av, Cardinal *ac)
{
  XBell (XtDisplay (widget), 0);
}

/* for the rest, look in src/Command.cpp -- for 'cmd_mapping mapping[]' */
XtActionsRec fe_CommandActions [] =
{
#if defined(MOZ_MAIL_NEWS) || defined(MOZ_MAIL_COMPOSE)
  { "mailto",		fe_mailto_action },
#endif

  { "print",        fe_print_remote_action },
  { "fishcam",		fe_fishcam_action	},
  { "net_showstatus",	fe_net_showstatus_action	},
  { "PageDown",		fe_page_forward_action	},
  { "PageUp",		fe_page_backward_action	},
  { "LineDown",		fe_line_forward_action	},
  { "LineUp",		fe_line_backward_action	},
  { "ColumnLeft",	fe_column_forward_action  },
  { "ColumnRight",	fe_column_backward_action },

  { "Delete",		fe_deleteKey_action },
  { "Backspace",	fe_deleteKey_action },

  { "SaveImage",	fe_save_image_action },
  { "OpenImage",	fe_open_image_action },
  { "SaveURL",		fe_save_link_action },
  { "OpenURL",		fe_open_url_action },
  { "OpenURLNewWindow",	fe_open_url_action },

  /* For Html Help */
  { "htmlHelp",		fe_html_help_action },

  { "undefined-key",	fe_undefined_key_action }
};

int fe_CommandActionsSize = countof (fe_CommandActions);

/**************************/
/* MessageCompose actions */
/* (Mail/News actions are */
/* defined in mailnews.c) */
/**************************/


void
fe_InitCommandActions ()
{
  XtAppAddActions(fe_XtAppContext, fe_CommandActions, fe_CommandActionsSize);
}


/* This installs all the usual translations on widgets which are a part
   of the main Netscape window -- it recursively decends the tree, 
   installing the appropriate translations everywhere.  This should
   not be called on popups/transients, but only on widgets which are
   children of the main Shell.
 */
void
fe_HackTranslations (MWContext *context, Widget widget)
{
  XtTranslations global_translations = 0;
  XtTranslations secondary_translations = 0;
  XP_Bool has_display_area = FALSE;

  if (XmIsGadget (widget))
    return;

 /* To prevent focus problems, dont enable translations on the menubar
    and its children. The problem was that when we had the translations
    in the menubar too, we could do a translation and popup a modal
    dialog when one of the menu's from the menubar was pulleddown. Now
    motif gets too confused about who holds pointer and keyboard focus.
 */

  if (XmIsRowColumn(widget)) {
    unsigned char type;
    XtVaGetValues(widget, XmNrowColumnType, &type, 0);
    if (type == XmMENU_BAR)
      return;
  }

  switch (context->type)
    {
#ifdef EDITOR
    case MWContextEditor:
      has_display_area = FALSE;
      global_translations    = fe_globalData.global_translations;
      secondary_translations = fe_globalData.editor_global_translations;
      break;
#endif /*EDITOR*/

    case MWContextBrowser:
      has_display_area = TRUE;
      global_translations    = fe_globalData.global_translations;
      secondary_translations = fe_globalData.browser_global_translations;
      break;

    case MWContextMail:
    case MWContextNews:
      has_display_area = TRUE;
      global_translations    = fe_globalData.global_translations;
      secondary_translations = fe_globalData.mailnews_global_translations;
      break;

    case MWContextMailMsg:
      has_display_area = TRUE;
      global_translations    = fe_globalData.global_translations;
      secondary_translations = fe_globalData.messagewin_global_translations;
      break;

    case MWContextMessageComposition:
      has_display_area = FALSE;
      global_translations    = fe_globalData.global_translations;
      secondary_translations = fe_globalData.mailcompose_global_translations;
      break;

    case MWContextAddressBook:
      has_display_area = FALSE;
      global_translations    = fe_globalData.global_translations;
      secondary_translations = fe_globalData.ab_global_translations;
      break;
    case MWContextDialog:
      has_display_area = TRUE;
      /*global_translations = 0;*/
      /*secondary_translations = fe_globalData.dialog_global_translations;*/
      global_translations    = fe_globalData.global_translations;
      secondary_translations = fe_globalData.browser_global_translations;
      break;
    case MWContextPane:  /*context used by navcenter right now */
      global_translations    = fe_globalData.global_translations;
      secondary_translations = fe_globalData.navcenter_global_translations;
    default:
      break;
  }
  if (!XP_STRCMP( XtName(widget), "editorDrawingArea" )) {
      XtOverrideTranslations (widget, fe_globalData.global_translations);
      XtOverrideTranslations (widget, fe_globalData.editor_global_translations);
  } else {
      if (global_translations)
          XtOverrideTranslations (widget, global_translations);
      if (secondary_translations)
          XtOverrideTranslations (widget, secondary_translations);
  }

  if (XmIsTextField (widget) || XmIsText (widget) || XmIsList(widget))
    {
      /* Set up the editing translations (all text fields, everywhere.) */
      if (XmIsTextField (widget) || XmIsText (widget))
	fe_HackTextTranslations (widget);

      /* Install globalTextFieldTranslations on single-line text fields in
	 windows which have an HTML display area (browser, mail, news) but
	 not in windows which don't have one (compose, download, bookmarks,
	 address book...)
       */
      if (has_display_area &&
	  XmIsTextField (widget) &&
	  fe_globalData.global_text_field_translations)
	XtOverrideTranslations (widget,
				fe_globalData.global_text_field_translations);
   }
  else
   {
       Widget *kids = 0;
       Cardinal nkids = 0;

      /* Not a Text or TextField.
       */
      /* Install globalNonTextTranslations on non-text widgets in windows which
	 have an HTML display area (browser, mail, news, view source) but not
	 in windows which don't have one (compose, download, bookmarks,
	 address book...)
       */
      if (has_display_area &&
	  fe_globalData.global_nontext_translations)
	XtOverrideTranslations (widget,
				fe_globalData.global_nontext_translations);

      /* Now recurse on the children.
       */
      XtVaGetValues (widget, XmNchildren, &kids, XmNnumChildren, &nkids, 0);
      while (nkids--)
	  fe_HackTranslations (context, kids [nkids]);
    }
}

/* This installs all the usual translations on Text and TextField widgets.
 */
void
fe_HackTextTranslations (Widget widget)
{ 
  Widget parent = widget;

  for (parent=widget; parent && !XtIsWMShell (parent); parent=XtParent(parent))
    if (XmLIsGrid(parent))
      /* We shouldn't be messing with Grid widget and its children */
      return;

  if (XmIsTextField(widget))
    {
      if (fe_globalData.editing_translations)
	XtOverrideTranslations (widget, fe_globalData.editing_translations);
      if (fe_globalData.single_line_editing_translations)
	XtOverrideTranslations (widget,
			      fe_globalData.single_line_editing_translations);
    }
  else if (XmIsText(widget))
    {
      if (fe_globalData.editing_translations)
	XtOverrideTranslations (widget, fe_globalData.editing_translations);
      if (fe_globalData.multi_line_editing_translations)
	XtOverrideTranslations (widget,
			      fe_globalData.multi_line_editing_translations);
    }
  else
    {
      XP_ASSERT(0);
    }
}

void
fe_HackFormTextTranslations(Widget widget)
{
  Widget parent = widget;

  for (parent=widget; parent && !XtIsWMShell (parent); parent=XtParent(parent))
    if (XmLIsGrid(parent))
      /* We shouldn't be messing with Grid widget and its children */
      return;

  if ((XmIsTextField(widget)) || (XmIsText(widget)) )
    {
      if (fe_globalData.form_elem_editing_translations)
	XtOverrideTranslations (widget, fe_globalData.form_elem_editing_translations);
    }
  else
    {
      XP_ASSERT(0);
    }
}


/* This installs all the usual translations for popups/transients.
   All it does is recurse the tree and call fe_HackTextTranslations
   on any Text or TextField widgets it finds.
 */
void
fe_HackDialogTranslations (Widget widget)
{
  if (XmIsGadget (widget))
    return;
  else if (XmIsText (widget) || XmIsTextField (widget))
    fe_HackTextTranslations (widget);
  else
    {
      Widget *kids = 0;
      Cardinal nkids = 0;
      XtVaGetValues (widget, XmNchildren, &kids, XmNnumChildren, &nkids, 0);
      while (nkids--)
	fe_HackDialogTranslations (kids [nkids]);
    }
}

/* these two are now in src/DownloadFrame.cpp */
extern NET_StreamClass *fe_MakeSaveAsStream (int format_out, void *data_obj,
											 URL_Struct *url_struct, MWContext *context);

extern NET_StreamClass *fe_MakeSaveAsStreamNoPrompt (int format_out, void *data_obj,
													 URL_Struct *url_struct, MWContext *context);

/*
 * parse_extensions
 * Give a comma separated string of extensions, fills in the array of
 * character strings in NET_cdataStruct.
 * eg, "cpp,cc" becomes:
 * mimetype_entry->exts[0] = "cpp";
 * mimetype_entry->exts[1] = "cc";
 * mimetype_entry->exts[2] = NULL;
 */
static void
parse_extensions(NET_cdataStruct* mimetype_entry, char* exts)
{
	int i;
	char* p;

	XP_ASSERT(mimetype_entry && exts);

	mimetype_entry->num_exts = 0;
	for ( p = exts; p && *p; p = strchr(p, ',') ) {
		if ( *p == ',' ) p++;
		mimetype_entry->num_exts++;
	}

	mimetype_entry->exts = (char**) malloc(sizeof(char*) * (mimetype_entry->num_exts+1));
	if ( mimetype_entry->exts == NULL ) return;

	for ( i = 0, p = exts; p && *p; p = strchr(p, ','), i++ ) {
		if ( *p == ',' ) p++;
		mimetype_entry->exts[i] = strdup(p);
		if ( strchr(mimetype_entry->exts[i], ',') ) *strchr(mimetype_entry->exts[i], ',') = '\0';
	}
	mimetype_entry->exts[i] = NULL;
}


/*
 * add_pref_mime_type
 * Given the beginning of a mimetype preference, registers that
 * mimetype handler with netlib.
 */
static void
add_pref_mime_type(char* name)
{
	char buf[1024];
	int32 load_action;
	char* extension = NULL;
	char* contenttype = NULL;
	char* command = NULL;
	char* description = NULL;
	NET_cdataStruct* mimetype_entry = NULL;
	NET_mdataStruct* mailcap_entry = NULL;

	strcpy(buf, name); strcat(buf, ".mimetype");
	if ( PREF_CopyCharPref(buf, &contenttype) != PREF_OK ) goto failed;

	strcpy(buf, name); strcat(buf, ".extension");
	if ( PREF_CopyCharPref(buf, &extension) != PREF_OK ) goto failed;

	strcpy(buf, name); strcat(buf, ".load_action");
	if ( PREF_GetIntPref(buf, &load_action) != PREF_OK ) goto failed;

	strcpy(buf, name); strcat(buf, ".unix_appname");
	if ( PREF_CopyCharPref(buf, &command) != PREF_OK ) goto failed;

	strcpy(buf, name); strcat(buf, ".description");
	if ( PREF_CopyCharPref(buf, &description) != PREF_OK ) goto failed;

	mailcap_entry = NET_mdataCreate();
	mimetype_entry = NET_cdataCreate();

	mailcap_entry->contenttype = strdup(contenttype);
	mailcap_entry->command = command ? strdup(command) : NULL;
	mailcap_entry->xmode = (load_action == 1) ? 
							strdup(NET_COMMAND_SAVE_TO_DISK) :
							(load_action == 3) ?
							strdup(NET_COMMAND_UNKNOWN) :
							(load_action == 4) ?
							strdup(NET_COMMAND_PLUGIN) : NULL;

	mimetype_entry->ci.type = contenttype ? strdup(contenttype) : NULL;
	mimetype_entry->ci.desc = description ? strdup(description) : NULL;
	mimetype_entry->pref_name = strdup(name);

	parse_extensions(mimetype_entry, extension);

	if ( mailcap_entry->xmode == NULL && 
		 mailcap_entry->command && 
		 *(mailcap_entry->command) &&
		 strcasecmp(mailcap_entry->contenttype, TEXT_HTML) &&
		 strcasecmp(mailcap_entry->contenttype, MESSAGE_RFC822) &&
		 strcasecmp(mailcap_entry->contenttype, MESSAGE_NEWS) ) {
		NET_RegisterExternalViewerCommand(mailcap_entry->contenttype, mailcap_entry->command, mailcap_entry->stream_buffer_size);	
	}

	NET_cdataAdd(mimetype_entry);
	NET_mdataAdd(mailcap_entry);

	if ( extension ) XP_FREE(extension);
	if ( contenttype ) XP_FREE(contenttype);
	if ( description ) XP_FREE(description);
	if ( command ) XP_FREE(command);
	return;

failed:
	if ( extension ) XP_FREE(extension);
	if ( contenttype ) XP_FREE(contenttype);
	if ( description ) XP_FREE(description);
	if ( command ) XP_FREE(command);
	if ( mimetype_entry ) NET_cdataFree(mimetype_entry);
	if ( mailcap_entry ) NET_mdataFree(mailcap_entry);
}


/*
 * fe_RegisterPrefConverters
 * Registers the mimetype converters that are specified by the
 * preferences.
 */
void
fe_RegisterPrefConverters(void)
{
	extern FILE* real_stderr;
	char* children = NULL;
	char* child = NULL;
	int index = 0;

	if ( PREF_CreateChildList("mime", &children) != PREF_OK ) {
		return;
	}

	while ( (child = PREF_NextChild(children, &index)) != NULL ) {
		add_pref_mime_type(child);
	}

	XP_FREE(children);
}


void
fe_RegisterConverters (void)
{
#ifdef NEW_DECODERS
  NET_ClearAllConverters ();
#endif /* NEW_DECODERS */

  if (fe_encoding_extensions)
    {
      int i = 0;
      while (fe_encoding_extensions [i])
	free (fe_encoding_extensions [i++]);
      free (fe_encoding_extensions);
      fe_encoding_extensions = 0;
    }

  /* register X specific decoders
   */
  if (fe_globalData.encoding_filters)
    {
      char *copy = strdup (fe_globalData.encoding_filters);
      char *rest = copy;
      char *end = rest + strlen (rest);

      int exts_count = 0;
      int exts_size = 10;
      char **all_exts = (char **) malloc (sizeof (char *) * exts_size);

      while (rest < end)
	{
	  char *start;
	  char *eol, *colon;
	  char *input, *output, *extensions, *command;
	  eol = strchr (rest, '\n');
	  if (eol) *eol = 0;

	  rest = fe_StringTrim (rest);
	  if (! *rest)
	    /* blank lines are ok */
	    continue;

	  start = rest;

	  colon = strchr (rest, ':');
	  if (! colon) goto LOSER;
	  *colon = 0;
	  input = fe_StringTrim (rest);
	  rest = colon + 1;

	  colon = strchr (rest, ':');
	  if (! colon) goto LOSER;
	  *colon = 0;
	  output = fe_StringTrim (rest);
	  rest = colon + 1;

	  colon = strchr (rest, ':');
	  if (! colon) goto LOSER;
	  *colon = 0;
	  extensions = fe_StringTrim (rest);
	  rest = colon + 1;

	  command = fe_StringTrim (rest);
	  rest = colon + 1;
	  
	  if (*command)
	    {
	      /* First save away the extensions. */
	      char *rest = extensions;
	      while (*rest)
		{
		  char *start;
		  char *comma, *end;
		  while (isspace (*rest))
		    rest++;
		  start = rest;
		  comma = XP_STRCHR (start, ',');
		  end = (comma ? comma - 1 : start + strlen (start));
		  while (end >= start && isspace (*end))
		    end--;
		  if (comma) end++;
		  if (start < end)
		    {
		      all_exts [exts_count] =
			(char *) malloc (end - start + 1);
		      strncpy (all_exts [exts_count], start, end - start);
		      all_exts [exts_count][end - start] = 0;
		      if (++exts_count == exts_size)
			all_exts = (char **)
			  realloc (all_exts,
				   sizeof (char *) * (exts_size += 10));
		    }
		  rest = (comma ? comma + 1 : end);
		}
	      all_exts [exts_count] = 0;
	      fe_encoding_extensions = all_exts;

	      /* Now register the converter. */
	      NET_RegisterExternalDecoderCommand (input, output, command);
	    }
	  else
	    {
	  LOSER:
	      fprintf (stderr,
				   XP_GetString(XFE_COMMANDS_UNPARSABLE_ENCODING_FILTER_SPEC),
				   fe_progname, start);
	    }
	  rest = (eol ? eol + 1 : end);
	}
      free (copy);
    }

  /* Register standard decoders
     This must come AFTER all calls to NET_RegisterExternalDecoderCommand(),
     (at least in the `NEW_DECODERS' world.)
   */
  NET_RegisterMIMEDecoders ();

  /* How to save to disk. */
  NET_RegisterContentTypeConverter ("*", FO_SAVE_AS, NULL,
				    fe_MakeSaveAsStream);

  /* Saving any binary format as type `text' should save as `source' instead.
   */
  NET_RegisterContentTypeConverter ("*", FO_SAVE_AS_TEXT, NULL,
				    fe_MakeSaveAsStreamNoPrompt);
  NET_RegisterContentTypeConverter ("*", FO_QUOTE_MESSAGE, NULL,
				    fe_MakeSaveAsStreamNoPrompt);

  /* default presentation converter - offer to save unknown types. */
  NET_RegisterContentTypeConverter ("*", FO_PRESENT, NULL,
				    fe_MakeSaveAsStream);

#if 0
  NET_RegisterContentTypeConverter ("*", FO_VIEW_SOURCE, NULL,
				    fe_MakeViewSourceStream);
#endif

#ifndef NO_MOCHA_CONVERTER_HACK
  /* libmocha:LM_InitMocha() installs this convert. We blow away all
   * converters that were installed and hence these mocha default converters
   * dont get recreated. And mocha has no call to re-register them.
   * So this hack. - dp/brendan
   */
  NET_RegisterContentTypeConverter(APPLICATION_JAVASCRIPT, FO_PRESENT, 0,
				   NET_CreateMochaConverter);
#endif /* NO_MOCHA_CONVERTER_HACK */

  /* Parse stuff out of the .mime.types and .mailcap files.
   * We dont have to check dates of files for modified because all that
   * would have been done by the caller. The only place time checking
   * happens is
   * (1) Helperapp page is created
   * (2) Helpers are being saved (OK button pressed on the General Prefs).
   */
  NET_InitFileFormatTypes (fe_globalPrefs.private_mime_types_file,
			   fe_globalPrefs.global_mime_types_file);
  fe_isFileChanged(fe_globalPrefs.private_mime_types_file, 0,
		   &fe_globalData.privateMimetypeFileModifiedTime);

  NET_RegisterConverters (fe_globalPrefs.private_mailcap_file,
			  fe_globalPrefs.global_mailcap_file);
  fe_isFileChanged(fe_globalPrefs.private_mailcap_file, 0,
		   &fe_globalData.privateMailcapFileModifiedTime);

  fe_RegisterPrefConverters();

#ifndef NO_WEB_FONTS
  /* Register webfont converters */
  NF_RegisterConverters();
#endif /* NO_WEB_FONTS */

  /* Plugins go on top of all this */
  fe_RegisterPluginConverters();
}

/* The Windows menu in the toolbar */

static void
fe_switch_context_cb (Widget widget, XtPointer closure, XtPointer call_data)
{
  MWContext *context = (MWContext *) closure;
  struct fe_MWContext_cons *cntx = fe_all_MWContexts;

  /* We need to watchout here. If we were holding down the menu and
   * before we select, a context gets destroyed (ftp is done say), then
   * selecting on that item would give an invalid context here. Guard
   * against that case by validating the context.
   */
  
  while (cntx && (cntx->context != context))
    cntx = cntx->next;
  if (!cntx)
    /* Ah ha! invalid context. I told you! */
    return;
  
  XMapRaised(XtDisplay(CONTEXT_WIDGET(context)),
		   XtWindow(CONTEXT_WIDGET(context)));
  return;
}

void 
fe_SetString(Widget widget, const char* propname, char* str)
{
  XmString xmstr;
  xmstr = XmStringCreate(str, XmFONTLIST_DEFAULT_TAG);
  XtVaSetValues(widget, propname, xmstr, 0);
  XmStringFree(xmstr);
}