Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 4105 lines (3647 sloc) 103.293 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105
/* vi:set ts=8 sts=4 sw=4:
*
* VIM - Vi IMproved by Bram Moolenaar
* GUI/Motif support by Robert Webb
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/

#include <Xm/Form.h>
#include <Xm/RowColumn.h>
#include <Xm/PushB.h>
#include <Xm/Text.h>
#include <Xm/TextF.h>
#include <Xm/Separator.h>
#include <Xm/Label.h>
#include <Xm/CascadeB.h>
#include <Xm/ScrollBar.h>
#include <Xm/MenuShell.h>
#include <Xm/DrawingA.h>
#if (XmVersion >= 1002)
# include <Xm/RepType.h>
#endif
#include <Xm/Frame.h>
#include <Xm/LabelG.h>
#include <Xm/ToggleBG.h>
#include <Xm/SeparatoG.h>
#include <Xm/XmP.h>

#include <X11/keysym.h>
#include <X11/Xatom.h>
#include <X11/StringDefs.h>
#include <X11/Intrinsic.h>

#include "vim.h"

#ifdef HAVE_X11_XPM_H
# include <X11/xpm.h>
#else
# ifdef HAVE_XM_XPMP_H
# include <Xm/XpmP.h>
# endif
#endif
#ifdef HAVE_XM_NOTEBOOK_H
# include <Xm/Notebook.h>
#endif

#include "gui_xmebw.h" /* for our Enhanced Button Widget */

#if defined(FEAT_GUI_DIALOG) && defined(HAVE_XPM)
# include "../pixmaps/alert.xpm"
# include "../pixmaps/error.xpm"
# include "../pixmaps/generic.xpm"
# include "../pixmaps/info.xpm"
# include "../pixmaps/quest.xpm"
#endif

#define MOTIF_POPUP

extern Widget vimShell;

static Widget vimForm;
static Widget textAreaForm;
Widget textArea;
#ifdef FEAT_TOOLBAR
static Widget toolBarFrame;
static Widget toolBar;
#endif
#ifdef FEAT_GUI_TABLINE
static Widget tabLine;
static Widget tabLine_menu = 0;
static int showing_tabline = 0;
#endif
#ifdef FEAT_FOOTER
static Widget footer;
#endif
#ifdef FEAT_MENU
# if (XmVersion >= 1002)
/* remember the last set value for the tearoff item */
static int tearoff_val = (int)XmTEAR_OFF_ENABLED;
# endif
static Widget menuBar;
#endif

static void scroll_cb __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
#ifdef FEAT_GUI_TABLINE
static void tabline_cb __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
static void tabline_button_cb __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
static void tabline_menu_cb __ARGS((Widget w, XtPointer closure, XEvent *e, Boolean *continue_dispatch));
static void tabline_balloon_cb __ARGS((BalloonEval *beval, int state));
#endif
#ifdef FEAT_TOOLBAR
# ifdef FEAT_FOOTER
static void toolbarbutton_enter_cb __ARGS((Widget, XtPointer, XEvent *, Boolean *));
static void toolbarbutton_leave_cb __ARGS((Widget, XtPointer, XEvent *, Boolean *));
# endif
static void reset_focus __ARGS((void));
#endif
#ifdef FEAT_FOOTER
static int gui_mch_compute_footer_height __ARGS((void));
#endif
#ifdef WSDEBUG
static void attachDump(Widget, char *);
#endif

static void gui_motif_menu_colors __ARGS((Widget id));
static void gui_motif_scroll_colors __ARGS((Widget id));

#if (XmVersion >= 1002)
# define STRING_TAG XmFONTLIST_DEFAULT_TAG
#else
# define STRING_TAG XmSTRING_DEFAULT_CHARSET
#endif

/*
* Call-back routines.
*/

    static void
scroll_cb(w, client_data, call_data)
    Widget w UNUSED;
    XtPointer client_data, call_data;
{
    scrollbar_T *sb;
    long value;
    int dragging;

    sb = gui_find_scrollbar((long)client_data);

    value = ((XmScrollBarCallbackStruct *)call_data)->value;
    dragging = (((XmScrollBarCallbackStruct *)call_data)->reason ==
(int)XmCR_DRAG);
    gui_drag_scrollbar(sb, value, dragging);
}

#ifdef FEAT_GUI_TABLINE
    static void
tabline_cb(w, client_data, call_data)
    Widget w UNUSED;
    XtPointer client_data UNUSED;
    XtPointer call_data;
{
    XmNotebookCallbackStruct *nptr;

    nptr = (XmNotebookCallbackStruct *)call_data;
    if (nptr->reason != (int)XmCR_NONE)
send_tabline_event(nptr->page_number);
}

    static void
tabline_button_cb(w, client_data, call_data)
    Widget w;
    XtPointer client_data UNUSED;
    XtPointer call_data UNUSED;
{
    int cmd, tab_idx;

    XtVaGetValues(w, XmNuserData, &cmd, NULL);
    XtVaGetValues(tabLine_menu, XmNuserData, &tab_idx, NULL);

    send_tabline_menu_event(tab_idx, cmd);
}

/*
* Tabline single mouse click timeout handler
*/
    static void
motif_tabline_timer_cb (timed_out, interval_id)
    XtPointer timed_out;
    XtIntervalId *interval_id UNUSED;
{
    *((int *)timed_out) = TRUE;
}

/*
* check if the tabline tab scroller is clicked
*/
    static int
tabline_scroller_clicked(scroller_name, event)
    char *scroller_name;
    XButtonPressedEvent *event;
{
    Widget tab_scroll_w;
    Position pos_x, pos_y;
    Dimension width, height;

    tab_scroll_w = XtNameToWidget(tabLine, scroller_name);
    if (tab_scroll_w != (Widget)0) {
XtVaGetValues(tab_scroll_w, XmNx, &pos_x, XmNy, &pos_y, XmNwidth,
&width, XmNheight, &height, NULL);
if (pos_x >= 0) {
/* Tab scroller (next) is visible */
if ((event->x >= pos_x) && (event->x <= pos_x + width) &&
(event->y >= pos_y) && (event->y <= pos_y + height)) {
/* Clicked on the scroller */
return TRUE;
}
}
    }
    return FALSE;
}

    static void
tabline_menu_cb(w, closure, e, continue_dispatch)
    Widget w;
    XtPointer closure UNUSED;
    XEvent *e;
    Boolean *continue_dispatch UNUSED;
{
    Widget tab_w;
    XButtonPressedEvent *event;
    int tab_idx = 0;
    WidgetList children;
    Cardinal numChildren;
    static XtIntervalId timer = (XtIntervalId)0;
    static int timed_out = TRUE;

    event = (XButtonPressedEvent *)e;

    if (event->button == Button1)
    {
if (tabline_scroller_clicked("MajorTabScrollerNext", event)
|| tabline_scroller_clicked("MajorTabScrollerPrevious", event))
return;

if (!timed_out)
{
XtRemoveTimeOut(timer);
timed_out = TRUE;

/*
* Double click on the tabline gutter, add a new tab
*/
send_tabline_menu_event(0, TABLINE_MENU_NEW);
}
else
{
/*
* Single click on the tabline gutter, start a timer to check
* for double clicks
*/
timer = XtAppAddTimeOut(app_context, (long_u)p_mouset,
motif_tabline_timer_cb, &timed_out);
timed_out = FALSE;
}
return;
    }

    if (event->button != Button3)
return;

    /* When ignoring events don't show the menu. */
    if (hold_gui_events
# ifdef FEAT_CMDWIN
|| cmdwin_type != 0
# endif
       )
return;

    if (event->subwindow != None)
    {
tab_w = XtWindowToWidget(XtDisplay(w), event->subwindow);
/* LINTED: avoid warning: dubious operation on enum */
if (tab_w != (Widget)0 && XmIsPushButton(tab_w))
XtVaGetValues(tab_w, XmNpageNumber, &tab_idx, NULL);
    }

    XtVaSetValues(tabLine_menu, XmNuserData, tab_idx, NULL);
    XtVaGetValues(tabLine_menu, XmNchildren, &children, XmNnumChildren,
&numChildren, NULL);
    XtManageChildren(children, numChildren);
    XmMenuPosition(tabLine_menu, (XButtonPressedEvent *)e) ;
    XtManageChild(tabLine_menu);
}

    static void
tabline_balloon_cb(beval, state)
    BalloonEval *beval;
    int state UNUSED;
{
    int nr;
    tabpage_T *tp;

    if (beval->target == (Widget)0)
return;

    XtVaGetValues(beval->target, XmNpageNumber, &nr, NULL);
    tp = find_tabpage(nr);
    if (tp == NULL)
return;

    get_tabline_label(tp, TRUE);
    gui_mch_post_balloon(beval, NameBuff);
}

#endif

/*
* End of call-back routines
*/

/*
* Implement three dimensional shading of insensitive labels.
* By Marcin Dalecki.
*/

#include <Xm/XmP.h>
#include <Xm/LabelP.h>

static XtExposeProc old_label_expose = NULL;

static void label_expose __ARGS((Widget _w, XEvent *_event, Region _region));

    static void
label_expose(_w, _event, _region)
    Widget _w;
    XEvent *_event;
    Region _region;
{
    GC insensitiveGC;
    XmLabelWidget lw = (XmLabelWidget)_w;
    unsigned char label_type = (int)XmSTRING;

    XtVaGetValues(_w, XmNlabelType, &label_type, (XtPointer)0);

    if (XtIsSensitive(_w) || label_type != (int)XmSTRING)
(*old_label_expose)(_w, _event, _region);
    else
    {
XGCValues values;
XtGCMask mask;
XtGCMask dynamic;
XFontStruct *fs;

_XmFontListGetDefaultFont(lw->label.font, &fs);

/* FIXME: we should be doing the whole drawing ourself here. */
insensitiveGC = lw->label.insensitive_GC;

mask = GCForeground | GCBackground | GCGraphicsExposures;
dynamic = GCClipMask | GCClipXOrigin | GCClipYOrigin;
values.graphics_exposures = False;

if (fs != 0)
{
mask |= GCFont;
values.font = fs->fid;
}

if (lw->primitive.top_shadow_pixmap != None
&& lw->primitive.top_shadow_pixmap != XmUNSPECIFIED_PIXMAP)
{
mask |= GCFillStyle | GCTile;
values.fill_style = FillTiled;
values.tile = lw->primitive.top_shadow_pixmap;
}

lw->label.TextRect.x += 1;
lw->label.TextRect.y += 1;
if (lw->label._acc_text != 0)
{
lw->label.acc_TextRect.x += 1;
lw->label.acc_TextRect.y += 1;
}

values.foreground = lw->primitive.top_shadow_color;
values.background = lw->core.background_pixel;

lw->label.insensitive_GC = XtAllocateGC((Widget)lw, 0, mask,
&values, dynamic, (XtGCMask)0);
(*old_label_expose)(_w, _event, _region);
XtReleaseGC(_w, lw->label.insensitive_GC);

lw->label.TextRect.x -= 1;
lw->label.TextRect.y -= 1;
if (lw->label._acc_text != 0)
{
lw->label.acc_TextRect.x -= 1;
lw->label.acc_TextRect.y -= 1;
}

values.foreground = lw->primitive.bottom_shadow_color;
values.background = lw->core.background_pixel;

lw->label.insensitive_GC = XtAllocateGC((Widget) lw, 0, mask,
&values, dynamic, (XtGCMask)0);
(*old_label_expose)(_w, _event, _region);
XtReleaseGC(_w, lw->label.insensitive_GC);

lw->label.insensitive_GC = insensitiveGC;
    }
}

/*
* Create all the motif widgets necessary.
*/
    void
gui_x11_create_widgets()
{
#ifdef FEAT_GUI_TABLINE
    Widget button, scroller;
    Arg args[10];
    int n;
    XmString xms;
#endif

    /*
* Install the 3D shade effect drawing routines.
*/
    if (old_label_expose == NULL)
    {
old_label_expose = xmLabelWidgetClass->core_class.expose;
xmLabelWidgetClass->core_class.expose = label_expose;
    }

    /*
* Start out by adding the configured border width into the border offset
*/
    gui.border_offset = gui.border_width;

    /*
* Install the tearOffModel resource converter.
*/
#if (XmVersion >= 1002)
    XmRepTypeInstallTearOffModelConverter();
#endif

    /* Make sure the "Quit" menu entry of the window manager is ignored */
    XtVaSetValues(vimShell, XmNdeleteResponse, XmDO_NOTHING, NULL);

    vimForm = XtVaCreateManagedWidget("vimForm",
xmFormWidgetClass, vimShell,
XmNborderWidth, 0,
XmNhighlightThickness, 0,
XmNshadowThickness, 0,
XmNmarginWidth, 0,
XmNmarginHeight, 0,
XmNresizePolicy, XmRESIZE_ANY,
NULL);
    gui_motif_menu_colors(vimForm);

#ifdef FEAT_MENU
    {
Arg al[7]; /* Make sure there is enough room for arguments! */
int ac = 0;

# if (XmVersion >= 1002)
XtSetArg(al[ac], XmNtearOffModel, tearoff_val); ac++;
# endif
XtSetArg(al[ac], XmNleftAttachment, XmATTACH_FORM); ac++;
XtSetArg(al[ac], XmNtopAttachment, XmATTACH_FORM); ac++;
XtSetArg(al[ac], XmNrightAttachment, XmATTACH_FORM); ac++;
# ifndef FEAT_TOOLBAR
/* Always stick to right hand side. */
XtSetArg(al[ac], XmNrightOffset, 0); ac++;
# endif
XtSetArg(al[ac], XmNmarginHeight, 0); ac++;
menuBar = XmCreateMenuBar(vimForm, "menuBar", al, ac);
XtManageChild(menuBar);

/* Remember the default colors, needed for ":hi clear". */
XtVaGetValues(menuBar,
XmNbackground, &gui.menu_def_bg_pixel,
XmNforeground, &gui.menu_def_fg_pixel,
NULL);
gui_motif_menu_colors(menuBar);
    }
#endif

#ifdef FEAT_TOOLBAR
    /*
* Create an empty ToolBar. We should get buttons defined from menu.vim.
*/
    toolBarFrame = XtVaCreateWidget("toolBarFrame",
xmFrameWidgetClass, vimForm,
XmNshadowThickness, 0,
XmNmarginHeight, 0,
XmNmarginWidth, 0,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL);
    gui_motif_menu_colors(toolBarFrame);

    toolBar = XtVaCreateManagedWidget("toolBar",
xmRowColumnWidgetClass, toolBarFrame,
XmNchildType, XmFRAME_WORKAREA_CHILD,
XmNrowColumnType, XmWORK_AREA,
XmNorientation, XmHORIZONTAL,
XmNtraversalOn, False,
XmNisHomogeneous, False,
XmNpacking, XmPACK_TIGHT,
XmNspacing, 0,
XmNshadowThickness, 0,
XmNhighlightThickness, 0,
XmNmarginHeight, 0,
XmNmarginWidth, 0,
XmNadjustLast, True,
NULL);
    gui_motif_menu_colors(toolBar);

#endif

#ifdef FEAT_GUI_TABLINE
    /* Create the Vim GUI tabline */
    n = 0;
    XtSetArg(args[n], XmNbindingType, XmNONE); n++;
    XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
    XtSetArg(args[n], XmNbackPageSize, XmNONE); n++;
    XtSetArg(args[n], XmNbackPageNumber, 0); n++;
    XtSetArg(args[n], XmNbackPagePlacement, XmTOP_RIGHT); n++;
    XtSetArg(args[n], XmNmajorTabSpacing, 0); n++;
    XtSetArg(args[n], XmNshadowThickness, 0); n++;
    XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
    XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
    tabLine = XmCreateNotebook(vimForm, "Vim tabline", args, n);

    XtAddCallback(tabLine, XmNpageChangedCallback, (XtCallbackProc)tabline_cb,
NULL);
    XtAddEventHandler(tabLine, ButtonPressMask, False,
(XtEventHandler)tabline_menu_cb, NULL);

    gui.tabline_height = TABLINE_HEIGHT;

    /*
* Set the size of the minor next/prev scrollers to zero, so
* that they are not displayed. Due to a bug in OpenMotif 2.3,
* even if these children widget are unmanaged, they are again
* managed by the Notebook widget and the notebook widget geometry
* is adjusted to account for the minor scroller widgets.
*/
    scroller = XtNameToWidget(tabLine, "MinorTabScrollerNext");
    XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
XmNtraversalOn, False, NULL);
    scroller = XtNameToWidget(tabLine, "MinorTabScrollerPrevious");
    XtVaSetValues(scroller, XmNwidth, 0, XmNresizable, False,
XmNtraversalOn, False, NULL);

    /* Create the tabline popup menu */
    tabLine_menu = XmCreatePopupMenu(tabLine, "tabline popup", NULL, 0);

    /* Add the buttons to the menu */
    n = 0;
    XtSetArg(args[n], XmNuserData, TABLINE_MENU_CLOSE); n++;
    xms = XmStringCreate((char *)"Close tab", STRING_TAG);
    XtSetArg(args[n], XmNlabelString, xms); n++;
    button = XmCreatePushButton(tabLine_menu, "Close", args, n);
    XtAddCallback(button, XmNactivateCallback,
(XtCallbackProc)tabline_button_cb, NULL);
    XmStringFree(xms);

    n = 0;
    XtSetArg(args[n], XmNuserData, TABLINE_MENU_NEW); n++;
    xms = XmStringCreate((char *)"New Tab", STRING_TAG);
    XtSetArg(args[n], XmNlabelString, xms); n++;
    button = XmCreatePushButton(tabLine_menu, "New Tab", args, n);
    XtAddCallback(button, XmNactivateCallback,
(XtCallbackProc)tabline_button_cb, NULL);
    XmStringFree(xms);

    n = 0;
    XtSetArg(args[n], XmNuserData, TABLINE_MENU_OPEN); n++;
    xms = XmStringCreate((char *)"Open tab...", STRING_TAG);
    XtSetArg(args[n], XmNlabelString, xms); n++;
    button = XmCreatePushButton(tabLine_menu, "Open tab...", args, n);
    XtAddCallback(button, XmNactivateCallback,
(XtCallbackProc)tabline_button_cb, NULL);
    XmStringFree(xms);
#endif

    textAreaForm = XtVaCreateManagedWidget("textAreaForm",
xmFormWidgetClass, vimForm,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
XmNmarginWidth, 0,
XmNmarginHeight, 0,
XmNresizePolicy, XmRESIZE_ANY,
NULL);
    gui_motif_scroll_colors(textAreaForm);

    textArea = XtVaCreateManagedWidget("textArea",
xmDrawingAreaWidgetClass, textAreaForm,
XmNforeground, gui.norm_pixel,
XmNbackground, gui.back_pixel,
XmNleftAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,

/*
* These take some control away from the user, but avoids making them
* add resources to get a decent looking setup.
*/
XmNborderWidth, 0,
XmNhighlightThickness, 0,
XmNshadowThickness, 0,
NULL);

#ifdef FEAT_FOOTER
    /*
* Create the Footer.
*/
    footer = XtVaCreateWidget("footer",
xmLabelGadgetClass, vimForm,
XmNalignment, XmALIGNMENT_BEGINNING,
XmNmarginHeight, 0,
XmNmarginWidth, 0,
XmNtraversalOn, False,
XmNrecomputeSize, False,
XmNleftAttachment, XmATTACH_FORM,
XmNleftOffset, 5,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
    gui_mch_set_footer((char_u *) "");
#endif

    /*
* Install the callbacks.
*/
    gui_x11_callbacks(textArea, vimForm);

    /* Pretend we don't have input focus, we will get an event if we do. */
    gui.in_focus = FALSE;
}

/*
* Called when the GUI is not going to start after all.
*/
    void
gui_x11_destroy_widgets()
{
    textArea = NULL;
#ifdef FEAT_MENU
    menuBar = NULL;
#endif
}

    void
gui_mch_set_text_area_pos(x, y, w, h)
    int x UNUSED;
    int y UNUSED;
    int w UNUSED;
    int h UNUSED;
{
#ifdef FEAT_TOOLBAR
    /* Give keyboard focus to the textArea instead of the toolbar. */
    reset_focus();
#endif
}

    void
gui_x11_set_back_color()
{
    if (textArea != NULL)
#if (XmVersion >= 1002)
XmChangeColor(textArea, gui.back_pixel);
#else
XtVaSetValues(textArea,
XmNbackground, gui.back_pixel,
NULL);
#endif
}

/*
* Manage dialog centered on pointer. This could be used by the Athena code as
* well.
*/
    void
manage_centered(dialog_child)
    Widget dialog_child;
{
    Widget shell = XtParent(dialog_child);
    Window root, child;
    unsigned int mask;
    unsigned int width, height, border_width, depth;
    int x, y, win_x, win_y, maxX, maxY;
    Boolean mappedWhenManaged;

    /* Temporarily set value of XmNmappedWhenManaged
to stop the dialog from popping up right away */
    XtVaGetValues(shell, XmNmappedWhenManaged, &mappedWhenManaged, NULL);
    XtVaSetValues(shell, XmNmappedWhenManaged, False, NULL);

    XtManageChild(dialog_child);

    /* Get the pointer position (x, y) */
    XQueryPointer(XtDisplay(shell), XtWindow(shell), &root, &child,
&x, &y, &win_x, &win_y, &mask);

    /* Translate the pointer position (x, y) into a position for the new
window that will place the pointer at its center */
    XGetGeometry(XtDisplay(shell), XtWindow(shell), &root, &win_x, &win_y,
&width, &height, &border_width, &depth);
    width += 2 * border_width;
    height += 2 * border_width;
    x -= width / 2;
    y -= height / 2;

    /* Ensure that the dialog remains on screen */
    maxX = XtScreen(shell)->width - width;
    maxY = XtScreen(shell)->height - height;
    if (x < 0)
x = 0;
    if (x > maxX)
x = maxX;
    if (y < 0)
y = 0;
    if (y > maxY)
y = maxY;

    /* Set desired window position in the DialogShell */
    XtVaSetValues(shell, XmNx, x, XmNy, y, NULL);

    /* Map the widget */
    XtMapWidget(shell);

    /* Restore the value of XmNmappedWhenManaged */
    XtVaSetValues(shell, XmNmappedWhenManaged, mappedWhenManaged, NULL);
}

#if defined(FEAT_MENU) || defined(FEAT_SUN_WORKSHOP) \
|| defined(FEAT_GUI_DIALOG) || defined(PROTO)

/*
* Encapsulate the way an XmFontList is created.
*/
    XmFontList
gui_motif_create_fontlist(font)
    XFontStruct *font;
{
    XmFontList font_list;

# if (XmVersion <= 1001)
    /* Motif 1.1 method */
    font_list = XmFontListCreate(font, STRING_TAG);
# else
    /* Motif 1.2 method */
    XmFontListEntry font_list_entry;

    font_list_entry = XmFontListEntryCreate(STRING_TAG, XmFONT_IS_FONT,
(XtPointer)font);
    font_list = XmFontListAppendEntry(NULL, font_list_entry);
    XmFontListEntryFree(&font_list_entry);
# endif
    return font_list;
}

# if ((XmVersion > 1001) && defined(FEAT_XFONTSET)) || defined(PROTO)
    XmFontList
gui_motif_fontset2fontlist(fontset)
    XFontSet *fontset;
{
    XmFontList font_list;

    /* Motif 1.2 method */
    XmFontListEntry font_list_entry;

    font_list_entry = XmFontListEntryCreate(STRING_TAG,
XmFONT_IS_FONTSET,
(XtPointer)*fontset);
    font_list = XmFontListAppendEntry(NULL, font_list_entry);
    XmFontListEntryFree(&font_list_entry);
    return font_list;
}
# endif

#endif

#if defined(FEAT_MENU) || defined(PROTO)
/*
* Menu stuff.
*/

static void gui_motif_add_actext __ARGS((vimmenu_T *menu));
#if (XmVersion >= 1002)
static void toggle_tearoff __ARGS((Widget wid));
static void gui_mch_recurse_tearoffs __ARGS((vimmenu_T *menu));
#endif
static void submenu_change __ARGS((vimmenu_T *mp, int colors));

static void do_set_mnemonics __ARGS((int enable));
static int menu_enabled = TRUE;

    void
gui_mch_enable_menu(flag)
    int flag;
{
    if (flag)
    {
XtManageChild(menuBar);
#ifdef FEAT_TOOLBAR
if (XtIsManaged(XtParent(toolBar)))
{
/* toolBar is attached to top form */
XtVaSetValues(XtParent(toolBar),
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, menuBar,
NULL);
#ifdef FEAT_GUI_TABLINE
if (showing_tabline)
{
XtVaSetValues(tabLine,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, XtParent(toolBar),
NULL);
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, tabLine,
NULL);
}
else
#endif
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, XtParent(toolBar),
NULL);
}
else
#endif
{
#ifdef FEAT_GUI_TABLINE
if (showing_tabline)
{
XtVaSetValues(tabLine,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, menuBar,
NULL);
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, tabLine,
NULL);
}
else
#endif
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, menuBar,
NULL);
}
    }
    else
    {
XtUnmanageChild(menuBar);
#ifdef FEAT_TOOLBAR
if (XtIsManaged(XtParent(toolBar)))
{
XtVaSetValues(XtParent(toolBar),
XmNtopAttachment, XmATTACH_FORM,
NULL);
#ifdef FEAT_GUI_TABLINE
if (showing_tabline)
{
XtVaSetValues(tabLine,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, XtParent(toolBar),
NULL);
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, tabLine,
NULL);
}
else
#endif
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, XtParent(toolBar),
NULL);
}
else
#endif
{
#ifdef FEAT_GUI_TABLINE
if (showing_tabline)
{
XtVaSetValues(tabLine,
XmNtopAttachment, XmATTACH_FORM,
NULL);
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, tabLine,
NULL);
}
else
#endif
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_FORM,
NULL);
}
    }

}

/*
* Enable or disable mnemonics for the toplevel menus.
*/
    void
gui_motif_set_mnemonics(enable)
    int enable;
{
    /*
* Don't enable menu mnemonics when the menu bar is disabled, LessTif
* crashes when using a mnemonic then.
*/
    if (!menu_enabled)
enable = FALSE;
    do_set_mnemonics(enable);
}

    static void
do_set_mnemonics(enable)
    int enable;
{
    vimmenu_T *menu;

    for (menu = root_menu; menu != NULL; menu = menu->next)
if (menu->id != (Widget)0)
XtVaSetValues(menu->id,
XmNmnemonic, enable ? menu->mnemonic : NUL,
NULL);
}

    void
gui_mch_add_menu(menu, idx)
    vimmenu_T *menu;
    int idx;
{
    XmString label;
    Widget shell;
    vimmenu_T *parent = menu->parent;

#ifdef MOTIF_POPUP
    if (menu_is_popup(menu->name))
    {
Arg arg[2];
int n = 0;

/* Only create the popup menu when it's actually used, otherwise there
* is a delay when using the right mouse button. */
# if (XmVersion <= 1002)
if (mouse_model_popup())
# endif
{
if (gui.menu_bg_pixel != INVALCOLOR)
{
XtSetArg(arg[0], XmNbackground, gui.menu_bg_pixel); n++;
}
if (gui.menu_fg_pixel != INVALCOLOR)
{
XtSetArg(arg[1], XmNforeground, gui.menu_fg_pixel); n++;
}
menu->submenu_id = XmCreatePopupMenu(textArea, "contextMenu",
arg, n);
menu->id = (Widget)0;
}
return;
    }
#endif

    if (!menu_is_menubar(menu->name)
|| (parent != NULL && parent->submenu_id == (Widget)0))
return;

    label = XmStringCreate((char *)menu->dname, STRING_TAG);
    if (label == NULL)
return;
    menu->id = XtVaCreateWidget("subMenu",
xmCascadeButtonWidgetClass,
(parent == NULL) ? menuBar : parent->submenu_id,
XmNlabelString, label,
XmNmnemonic, p_wak[0] == 'n' ? NUL : menu->mnemonic,
#if (XmVersion >= 1002)
/* submenu: count the tearoff item (needed for LessTif) */
XmNpositionIndex, idx + (parent != NULL
&& tearoff_val == (int)XmTEAR_OFF_ENABLED ? 1 : 0),
#endif
NULL);
    gui_motif_menu_colors(menu->id);
    gui_motif_menu_fontlist(menu->id);
    XmStringFree(label);

    if (menu->id == (Widget)0) /* failed */
return;

    /* add accelerator text */
    gui_motif_add_actext(menu);

    shell = XtVaCreateWidget("subMenuShell",
xmMenuShellWidgetClass, menu->id,
XmNwidth, 1,
XmNheight, 1,
NULL);
    gui_motif_menu_colors(shell);
    menu->submenu_id = XtVaCreateWidget("rowColumnMenu",
xmRowColumnWidgetClass, shell,
XmNrowColumnType, XmMENU_PULLDOWN,
NULL);
    gui_motif_menu_colors(menu->submenu_id);

    if (menu->submenu_id == (Widget)0) /* failed */
return;

#if (XmVersion >= 1002)
    /* Set the colors for the tear off widget */
    toggle_tearoff(menu->submenu_id);
#endif

    XtVaSetValues(menu->id,
XmNsubMenuId, menu->submenu_id,
NULL);

    /*
* The "Help" menu is a special case, and should be placed at the far
* right hand side of the menu-bar. It's recognized by its high priority.
*/
    if (parent == NULL && menu->priority >= 9999)
XtVaSetValues(menuBar,
XmNmenuHelpWidget, menu->id,
NULL);

    /*
* When we add a top-level item to the menu bar, we can figure out how
* high the menu bar should be.
*/
    if (parent == NULL)
gui_mch_compute_menu_height(menu->id);
}


/*
* Add mnemonic and accelerator text to a menu button.
*/
    static void
gui_motif_add_actext(menu)
    vimmenu_T *menu;
{
    XmString label;

    /* Add accelerator text, if there is one */
    if (menu->actext != NULL && menu->id != (Widget)0)
    {
label = XmStringCreate((char *)menu->actext, STRING_TAG);
if (label == NULL)
return;
XtVaSetValues(menu->id, XmNacceleratorText, label, NULL);
XmStringFree(label);
    }
}

    void
gui_mch_toggle_tearoffs(enable)
    int enable;
{
#if (XmVersion >= 1002)
    if (enable)
tearoff_val = (int)XmTEAR_OFF_ENABLED;
    else
tearoff_val = (int)XmTEAR_OFF_DISABLED;
    toggle_tearoff(menuBar);
    gui_mch_recurse_tearoffs(root_menu);
#endif
}

#if (XmVersion >= 1002)
/*
* Set the tearoff for one menu widget on or off, and set the color of the
* tearoff widget.
*/
    static void
toggle_tearoff(wid)
    Widget wid;
{
    Widget w;

    XtVaSetValues(wid, XmNtearOffModel, tearoff_val, NULL);
    if (tearoff_val == (int)XmTEAR_OFF_ENABLED
&& (w = XmGetTearOffControl(wid)) != (Widget)0)
gui_motif_menu_colors(w);
}

    static void
gui_mch_recurse_tearoffs(menu)
    vimmenu_T *menu;
{
    while (menu != NULL)
    {
if (!menu_is_popup(menu->name))
{
if (menu->submenu_id != (Widget)0)
toggle_tearoff(menu->submenu_id);
gui_mch_recurse_tearoffs(menu->children);
}
menu = menu->next;
    }
}
#endif

    int
gui_mch_text_area_extra_height()
{
    Dimension shadowHeight;

    XtVaGetValues(textAreaForm, XmNshadowThickness, &shadowHeight, NULL);
    return shadowHeight;
}

/*
* Compute the height of the menu bar.
* We need to check all the items for their position and height, for the case
* there are several rows, and/or some characters extend higher or lower.
*/
    void
gui_mch_compute_menu_height(id)
    Widget id; /* can be NULL when deleting menu */
{
    Dimension y, maxy;
    Dimension margin, shadow;
    vimmenu_T *mp;
    static Dimension height = 21; /* normal height of a menu item */

    /*
* Get the height of the new item, before managing it, because it will
* still reflect the font size. After managing it depends on the menu
* height, which is what we just wanted to get!.
*/
    if (id != (Widget)0)
XtVaGetValues(id, XmNheight, &height, NULL);

    /* Find any menu Widget, to be able to call XtManageChild() */
    else
for (mp = root_menu; mp != NULL; mp = mp->next)
if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
{
id = mp->id;
break;
}

    /*
* Now manage the menu item, to make them all be positioned (makes an
* extra row when needed, removes it when not needed).
*/
    if (id != (Widget)0)
XtManageChild(id);

    /*
* Now find the menu item that is the furthest down, and get it's position.
*/
    maxy = 0;
    for (mp = root_menu; mp != NULL; mp = mp->next)
    {
if (mp->id != (Widget)0 && menu_is_menubar(mp->name))
{
XtVaGetValues(mp->id, XmNy, &y, NULL);
if (y > maxy)
maxy = y;
}
    }

    XtVaGetValues(menuBar,
XmNmarginHeight, &margin,
XmNshadowThickness, &shadow,
NULL);

    /*
* This computation is the result of trial-and-error:
* maxy = The maximum position of an item; required for when there are
* two or more rows
* height = height of an item, before managing it; Hopefully this will
* change with the font height. Includes shadow-border.
* shadow = shadow-border; must be subtracted from the height.
* margin = margin around the menu buttons; Must be added.
* Add 4 for the underlining of shortcut keys.
*/
    gui.menu_height = maxy + height - 2 * shadow + 2 * margin + 4;

    /* Somehow the menu bar doesn't resize automatically. Set it here,
* even though this is a catch 22. Don't do this when starting up,
* somehow the menu gets very high then. */
    if (gui.shell_created)
XtVaSetValues(menuBar, XmNheight, gui.menu_height, NULL);
}

#ifdef FEAT_TOOLBAR

/*
* Icons used by the toolbar code.
*/
#include "gui_x11_pm.h"

static int check_xpm __ARGS((char_u *path));
static char **get_toolbar_pixmap __ARGS((vimmenu_T *menu, char **fname));
static int add_pixmap_args __ARGS((vimmenu_T *menu, Arg *args, int n));

/*
* Read an Xpm file. Return OK or FAIL.
*/
    static int
check_xpm(path)
    char_u *path;
{
    XpmAttributes attrs;
    int status;
    Pixmap mask;
    Pixmap map;

    attrs.valuemask = 0;

    /* Create the "sensitive" pixmap */
    status = XpmReadFileToPixmap(gui.dpy,
RootWindow(gui.dpy, DefaultScreen(gui.dpy)),
(char *)path, &map, &mask, &attrs);
    XpmFreeAttributes(&attrs);

    if (status == XpmSuccess)
return OK;
    return FAIL;
}


/*
* Allocated a pixmap for toolbar menu "menu".
* When it's to be read from a file, "fname" is set to the file name
* (in allocated memory).
* Return a blank pixmap if it fails.
*/
    static char **
get_toolbar_pixmap(menu, fname)
    vimmenu_T *menu;
    char **fname;
{
    char_u buf[MAXPATHL]; /* buffer storing expanded pathname */
    char **xpm = NULL; /* xpm array */
    int res;

    *fname = NULL;
    buf[0] = NUL; /* start with NULL path */

    if (menu->iconfile != NULL)
    {
/* Use the "icon=" argument. */
gui_find_iconfile(menu->iconfile, buf, "xpm");
res = check_xpm(buf);

/* If it failed, try using the menu name. */
if (res == FAIL && gui_find_bitmap(menu->name, buf, "xpm") == OK)
res = check_xpm(buf);
if (res == OK)
{
*fname = (char *)vim_strsave(buf);
return tb_blank_xpm;
}
    }

    if (menu->icon_builtin || gui_find_bitmap(menu->name, buf, "xpm") == FAIL)
    {
if (menu->iconidx >= 0 && menu->iconidx
< (int)(sizeof(built_in_pixmaps) / sizeof(built_in_pixmaps[0])))
xpm = built_in_pixmaps[menu->iconidx];
else
xpm = tb_blank_xpm;
    }

    return xpm;
}

/*
* Add arguments for the toolbar pixmap to a menu item.
*/
    static int
add_pixmap_args(menu, args, n)
    vimmenu_T *menu;
    Arg *args;
    int n;
{
    vim_free(menu->xpm_fname);
    menu->xpm = get_toolbar_pixmap(menu, &menu->xpm_fname);
    if (menu->xpm == NULL)
    {
XtSetArg(args[n], XmNlabelType, XmSTRING); n++;
    }
    else
    {
if (menu->xpm_fname != NULL)
{
XtSetArg(args[n], XmNpixmapFile, menu->xpm_fname); n++;
}
XtSetArg(args[n], XmNpixmapData, menu->xpm); n++;
XtSetArg(args[n], XmNlabelLocation, XmBOTTOM); n++;
    }
    return n;
}
#endif /* FEAT_TOOLBAR */

    void
gui_mch_add_menu_item(menu, idx)
    vimmenu_T *menu;
    int idx;
{
    XmString label;
    vimmenu_T *parent = menu->parent;

# ifdef EBCDIC
    menu->mnemonic = 0;
# endif

# if (XmVersion <= 1002)
    /* Don't add Popup menu items when the popup menu isn't used. */
    if (menu_is_child_of_popup(menu) && !mouse_model_popup())
return;
# endif

# ifdef FEAT_TOOLBAR
    if (menu_is_toolbar(parent->name))
    {
WidgetClass type;
XmString xms = NULL; /* fallback label if pixmap not found */
int n;
Arg args[18];

n = 0;
if (menu_is_separator(menu->name))
{
char *cp;
Dimension wid;

/*
* A separator has the format "-sep%d[:%d]-". The optional :%d is
* a width specifier. If no width is specified then we choose one.
*/
cp = (char *)vim_strchr(menu->name, ':');
if (cp != NULL)
wid = (Dimension)atoi(++cp);
else
wid = 4;

type = xmSeparatorWidgetClass;
XtSetArg(args[n], XmNwidth, wid); n++;
XtSetArg(args[n], XmNminWidth, wid); n++;
XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
XtSetArg(args[n], XmNseparatorType, XmSHADOW_ETCHED_IN); n++;
}
else
{
/* Without shadows one can't sense whatever the button has been
* pressed or not! However we wan't to save a bit of space...
* Need the highlightThickness to see the focus.
*/
XtSetArg(args[n], XmNhighlightThickness, 1); n++;
XtSetArg(args[n], XmNhighlightOnEnter, True); n++;
XtSetArg(args[n], XmNmarginWidth, 0); n++;
XtSetArg(args[n], XmNmarginHeight, 0); n++;
XtSetArg(args[n], XmNtraversalOn, False); n++;
/* Set the label here, so that we can switch between icons/text
* by changing the XmNlabelType resource. */
xms = XmStringCreate((char *)menu->dname, STRING_TAG);
XtSetArg(args[n], XmNlabelString, xms); n++;

n = add_pixmap_args(menu, args, n);

type = xmEnhancedButtonWidgetClass;
}

XtSetArg(args[n], XmNpositionIndex, idx); n++;
if (menu->id == NULL)
{
menu->id = XtCreateManagedWidget((char *)menu->dname,
type, toolBar, args, n);
if (menu->id != NULL && type == xmEnhancedButtonWidgetClass)
{
XtAddCallback(menu->id,
XmNactivateCallback, gui_x11_menu_cb, menu);
# ifdef FEAT_FOOTER
XtAddEventHandler(menu->id, EnterWindowMask, False,
toolbarbutton_enter_cb, menu);
XtAddEventHandler(menu->id, LeaveWindowMask, False,
toolbarbutton_leave_cb, menu);
# endif
}
}
else
XtSetValues(menu->id, args, n);
if (xms != NULL)
XmStringFree(xms);

# ifdef FEAT_BEVAL
gui_mch_menu_set_tip(menu);
# endif

menu->parent = parent;
menu->submenu_id = NULL;
/* When adding first item to toolbar it might have to be enabled .*/
if (!XtIsManaged(XtParent(toolBar))
&& vim_strchr(p_go, GO_TOOLBAR) != NULL)
gui_mch_show_toolbar(TRUE);
gui.toolbar_height = gui_mch_compute_toolbar_height();
return;
    } /* toolbar menu item */
# endif

    /* No parent, must be a non-menubar menu */
    if (parent->submenu_id == (Widget)0)
return;

    menu->submenu_id = (Widget)0;

    /* Add menu separator */
    if (menu_is_separator(menu->name))
    {
menu->id = XtVaCreateWidget("subMenu",
xmSeparatorGadgetClass, parent->submenu_id,
#if (XmVersion >= 1002)
/* count the tearoff item (needed for LessTif) */
XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
? 1 : 0),
#endif
NULL);
gui_motif_menu_colors(menu->id);
return;
    }

    label = XmStringCreate((char *)menu->dname, STRING_TAG);
    if (label == NULL)
return;
    menu->id = XtVaCreateWidget("subMenu",
xmPushButtonWidgetClass, parent->submenu_id,
XmNlabelString, label,
XmNmnemonic, menu->mnemonic,
#if (XmVersion >= 1002)
/* count the tearoff item (needed for LessTif) */
XmNpositionIndex, idx + (tearoff_val == (int)XmTEAR_OFF_ENABLED
? 1 : 0),
#endif
NULL);
    gui_motif_menu_colors(menu->id);
    gui_motif_menu_fontlist(menu->id);
    XmStringFree(label);

    if (menu->id != (Widget)0)
    {
XtAddCallback(menu->id, XmNactivateCallback, gui_x11_menu_cb,
(XtPointer)menu);
/* add accelerator text */
gui_motif_add_actext(menu);
    }
}

#if (XmVersion <= 1002) || defined(PROTO)
/*
* This function will destroy/create the popup menus dynamically,
* according to the value of 'mousemodel'.
* This will fix the "right mouse button freeze" that occurs when
* there exists a popup menu but it isn't managed.
*/
    void
gui_motif_update_mousemodel(menu)
    vimmenu_T *menu;
{
    int idx = 0;

    /* When GUI hasn't started the menus have not been created. */
    if (!gui.in_use)
      return;

    while (menu)
    {
      if (menu->children != NULL)
      {
if (menu_is_popup(menu->name))
{
if (mouse_model_popup())
{
/* Popup menu will be used. Create the popup menus. */
gui_mch_add_menu(menu, idx);
gui_motif_update_mousemodel(menu->children);
}
else
{
/* Popup menu will not be used. Destroy the popup menus. */
gui_motif_update_mousemodel(menu->children);
gui_mch_destroy_menu(menu);
}
}
      }
      else if (menu_is_child_of_popup(menu))
      {
if (mouse_model_popup())
gui_mch_add_menu_item(menu, idx);
else
gui_mch_destroy_menu(menu);
      }
      menu = menu->next;
      ++idx;
    }
}
#endif

    void
gui_mch_new_menu_colors()
{
    if (menuBar == (Widget)0)
return;
    gui_motif_menu_colors(menuBar);
#ifdef FEAT_TOOLBAR
    gui_motif_menu_colors(toolBarFrame);
    gui_motif_menu_colors(toolBar);
#endif

    submenu_change(root_menu, TRUE);
}

    void
gui_mch_new_menu_font()
{
    if (menuBar == (Widget)0)
return;
    submenu_change(root_menu, FALSE);
    {
Dimension height;
Position w, h;

XtVaGetValues(menuBar, XmNheight, &height, NULL);
gui.menu_height = height;

XtVaGetValues(vimShell, XtNwidth, &w, XtNheight, &h, NULL);
gui_resize_shell(w, h
#ifdef FEAT_XIM
- xim_get_status_area_height()
#endif
);
    }
    gui_set_shellsize(FALSE, TRUE, RESIZE_VERT);
    ui_new_shellsize();
}

#if defined(FEAT_BEVAL) || defined(PROTO)
    void
gui_mch_new_tooltip_font()
{
# ifdef FEAT_TOOLBAR
    vimmenu_T *menu;

    if (toolBar == (Widget)0)
return;

    menu = gui_find_menu((char_u *)"ToolBar");
    if (menu != NULL)
submenu_change(menu, FALSE);
# endif
}

    void
gui_mch_new_tooltip_colors()
{
# ifdef FEAT_TOOLBAR
    vimmenu_T *toolbar;

    if (toolBar == (Widget)0)
return;

    toolbar = gui_find_menu((char_u *)"ToolBar");
    if (toolbar != NULL)
submenu_change(toolbar, TRUE);
# endif
}
#endif

    static void
submenu_change(menu, colors)
    vimmenu_T *menu;
    int colors; /* TRUE for colors, FALSE for font */
{
    vimmenu_T *mp;

    for (mp = menu; mp != NULL; mp = mp->next)
    {
if (mp->id != (Widget)0)
{
if (colors)
{
gui_motif_menu_colors(mp->id);
#ifdef FEAT_TOOLBAR
/* For a toolbar item: Free the pixmap and allocate a new one,
* so that the background color is right. */
if (mp->xpm != NULL)
{
int n = 0;
Arg args[18];

n = add_pixmap_args(mp, args, n);
XtSetValues(mp->id, args, n);
}
# ifdef FEAT_BEVAL
/* If we have a tooltip, then we need to change it's font */
if (mp->tip != NULL)
{
Arg args[2];

args[0].name = XmNbackground;
args[0].value = gui.tooltip_bg_pixel;
args[1].name = XmNforeground;
args[1].value = gui.tooltip_fg_pixel;
XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
}
# endif
#endif
}
else
{
gui_motif_menu_fontlist(mp->id);
#ifdef FEAT_BEVAL
/* If we have a tooltip, then we need to change it's font */
if (mp->tip != NULL)
{
Arg args[1];

args[0].name = XmNfontList;
args[0].value = (XtArgVal)gui_motif_fontset2fontlist(
&gui.tooltip_fontset);
XtSetValues(mp->tip->balloonLabel, &args[0], XtNumber(args));
}
#endif
}
}

if (mp->children != NULL)
{
#if (XmVersion >= 1002)
/* Set the colors/font for the tear off widget */
if (mp->submenu_id != (Widget)0)
{
if (colors)
gui_motif_menu_colors(mp->submenu_id);
else
gui_motif_menu_fontlist(mp->submenu_id);
toggle_tearoff(mp->submenu_id);
}
#endif
/* Set the colors for the children */
submenu_change(mp->children, colors);
}
    }
}

/*
* Destroy the machine specific menu widget.
*/
    void
gui_mch_destroy_menu(menu)
    vimmenu_T *menu;
{
    /* Please be sure to destroy the parent widget first (i.e. menu->id).
* On the other hand, problems have been reported that the submenu must be
* deleted first...
*
* This code should be basically identical to that in the file gui_athena.c
* because they are both Xt based.
*/
    if (menu->submenu_id != (Widget)0)
    {
XtDestroyWidget(menu->submenu_id);
menu->submenu_id = (Widget)0;
    }

    if (menu->id != (Widget)0)
    {
Widget parent;

parent = XtParent(menu->id);
#if defined(FEAT_TOOLBAR) && defined(FEAT_BEVAL)
if (parent == toolBar && menu->tip != NULL)
{
/* We try to destroy this before the actual menu, because there are
* callbacks, etc. that will be unregistered during the tooltip
* destruction.
*
* If you call "gui_mch_destroy_beval_area()" after destroying
* menu->id, then the tooltip's window will have already been
* deallocated by Xt, and unknown behaviour will ensue (probably
* a core dump).
*/
gui_mch_destroy_beval_area(menu->tip);
menu->tip = NULL;
}
#endif
XtDestroyWidget(menu->id);
menu->id = (Widget)0;
if (parent == menuBar)
gui_mch_compute_menu_height((Widget)0);
#ifdef FEAT_TOOLBAR
else if (parent == toolBar)
{
Cardinal num_children;

/* When removing last toolbar item, don't display the toolbar. */
XtVaGetValues(toolBar, XmNnumChildren, &num_children, NULL);
if (num_children == 0)
gui_mch_show_toolbar(FALSE);
else
gui.toolbar_height = gui_mch_compute_toolbar_height();
}
#endif
    }
}

    void
gui_mch_show_popupmenu(menu)
    vimmenu_T *menu UNUSED;
{
#ifdef MOTIF_POPUP
    XmMenuPosition(menu->submenu_id, gui_x11_get_last_mouse_event());
    XtManageChild(menu->submenu_id);
#endif
}

#endif /* FEAT_MENU */

/*
* Set the menu and scrollbar colors to their default values.
*/
    void
gui_mch_def_colors()
{
    if (gui.in_use)
    {
/* Use the values saved when starting up. These should come from the
* window manager or a resources file. */
gui.menu_fg_pixel = gui.menu_def_fg_pixel;
gui.menu_bg_pixel = gui.menu_def_bg_pixel;
gui.scroll_fg_pixel = gui.scroll_def_fg_pixel;
gui.scroll_bg_pixel = gui.scroll_def_bg_pixel;
#ifdef FEAT_BEVAL
gui.tooltip_fg_pixel =
gui_get_color((char_u *)gui.rsrc_tooltip_fg_name);
gui.tooltip_bg_pixel =
gui_get_color((char_u *)gui.rsrc_tooltip_bg_name);
#endif
    }
}


/*
* Scrollbar stuff.
*/

    void
gui_mch_set_scrollbar_thumb(sb, val, size, max)
    scrollbar_T *sb;
    long val;
    long size;
    long max;
{
    if (sb->id != (Widget)0)
XtVaSetValues(sb->id,
XmNvalue, val,
XmNsliderSize, size,
XmNpageIncrement, (size > 2 ? size - 2 : 1),
XmNmaximum, max + 1, /* Motif has max one past the end */
NULL);
}

    void
gui_mch_set_scrollbar_pos(sb, x, y, w, h)
    scrollbar_T *sb;
    int x;
    int y;
    int w;
    int h;
{
    if (sb->id != (Widget)0)
    {
if (sb->type == SBAR_LEFT || sb->type == SBAR_RIGHT)
{
if (y == 0)
h -= gui.border_offset;
else
y -= gui.border_offset;
XtVaSetValues(sb->id,
XmNtopOffset, y,
XmNbottomOffset, -y - h,
XmNwidth, w,
NULL);
}
else
XtVaSetValues(sb->id,
XmNtopOffset, y,
XmNleftOffset, x,
XmNrightOffset, gui.which_scrollbars[SBAR_RIGHT]
? gui.scrollbar_width : 0,
XmNheight, h,
NULL);
XtManageChild(sb->id);
    }
}

    void
gui_mch_enable_scrollbar(sb, flag)
    scrollbar_T *sb;
    int flag;
{
    Arg args[16];
    int n;

    if (sb->id != (Widget)0)
    {
n = 0;
if (flag)
{
switch (sb->type)
{
case SBAR_LEFT:
XtSetArg(args[n], XmNleftOffset, gui.scrollbar_width); n++;
break;

case SBAR_RIGHT:
XtSetArg(args[n], XmNrightOffset, gui.scrollbar_width); n++;
break;

case SBAR_BOTTOM:
XtSetArg(args[n], XmNbottomOffset, gui.scrollbar_height);n++;
break;
}
XtSetValues(textArea, args, n);
XtManageChild(sb->id);
}
else
{
if (!gui.which_scrollbars[sb->type])
{
/* The scrollbars of this type are all disabled, adjust the
* textArea attachment offset. */
switch (sb->type)
{
case SBAR_LEFT:
XtSetArg(args[n], XmNleftOffset, 0); n++;
break;

case SBAR_RIGHT:
XtSetArg(args[n], XmNrightOffset, 0); n++;
break;

case SBAR_BOTTOM:
XtSetArg(args[n], XmNbottomOffset, 0);n++;
break;
}
XtSetValues(textArea, args, n);
}
XtUnmanageChild(sb->id);
}
    }
}

    void
gui_mch_create_scrollbar(sb, orient)
    scrollbar_T *sb;
    int orient; /* SBAR_VERT or SBAR_HORIZ */
{
    Arg args[16];
    int n;

    n = 0;
    XtSetArg(args[n], XmNminimum, 0); n++;
    XtSetArg(args[n], XmNorientation,
(orient == SBAR_VERT) ? XmVERTICAL : XmHORIZONTAL); n++;

    switch (sb->type)
    {
case SBAR_LEFT:
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
break;

case SBAR_RIGHT:
XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_OPPOSITE_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
break;

case SBAR_BOTTOM:
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
break;
    }

    sb->id = XtCreateWidget("scrollBar",
xmScrollBarWidgetClass, textAreaForm, args, n);

    /* Remember the default colors, needed for ":hi clear". */
    if (gui.scroll_def_bg_pixel == (guicolor_T)0
&& gui.scroll_def_fg_pixel == (guicolor_T)0)
XtVaGetValues(sb->id,
XmNbackground, &gui.scroll_def_bg_pixel,
XmNforeground, &gui.scroll_def_fg_pixel,
NULL);

    if (sb->id != (Widget)0)
    {
gui_mch_set_scrollbar_colors(sb);
XtAddCallback(sb->id, XmNvalueChangedCallback,
scroll_cb, (XtPointer)sb->ident);
XtAddCallback(sb->id, XmNdragCallback,
scroll_cb, (XtPointer)sb->ident);
XtAddEventHandler(sb->id, KeyPressMask, FALSE, gui_x11_key_hit_cb,
(XtPointer)0);
    }
}

#if defined(FEAT_WINDOWS) || defined(PROTO)
    void
gui_mch_destroy_scrollbar(sb)
    scrollbar_T *sb;
{
    if (sb->id != (Widget)0)
XtDestroyWidget(sb->id);
}
#endif

    void
gui_mch_set_scrollbar_colors(sb)
    scrollbar_T *sb;
{
    if (sb->id != (Widget)0)
    {
if (gui.scroll_bg_pixel != INVALCOLOR)
{
#if (XmVersion>=1002)
XmChangeColor(sb->id, gui.scroll_bg_pixel);
#else
XtVaSetValues(sb->id,
XmNtroughColor, gui.scroll_bg_pixel,
NULL);
#endif
}

if (gui.scroll_fg_pixel != INVALCOLOR)
XtVaSetValues(sb->id,
XmNforeground, gui.scroll_fg_pixel,
#if (XmVersion<1002)
XmNbackground, gui.scroll_fg_pixel,
#endif
NULL);
    }

    /* This is needed for the rectangle below the vertical scrollbars. */
    if (sb == &gui.bottom_sbar && textAreaForm != (Widget)0)
gui_motif_scroll_colors(textAreaForm);
}

/*
* Miscellaneous stuff:
*/

    Window
gui_x11_get_wid()
{
    return(XtWindow(textArea));
}

/*
* Look for a widget in the widget tree w, with a mnemonic matching keycode.
* When one is found, simulate a button press on that widget and give it the
* keyboard focus. If the mnemonic is on a label, look in the userData field
* of the label to see if it points to another widget, and give that the focus.
*/
    static void
do_mnemonic(Widget w, unsigned int keycode)
{
    WidgetList children;
    int numChildren, i;
    Boolean isMenu;
    KeySym mnemonic = '\0';
    char mneString[2];
    Widget userData;
    unsigned char rowColType;

    if (XtIsComposite(w))
    {
if (XtClass(w) == xmRowColumnWidgetClass)
{
XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
isMenu = (rowColType != (unsigned char)XmWORK_AREA);
}
else
isMenu = False;
if (!isMenu)
{
XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
&numChildren, NULL);
for (i = 0; i < numChildren; i++)
do_mnemonic(children[i], keycode);
}
    }
    else
    {
XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
if (mnemonic != '\0')
{
mneString[0] = mnemonic;
mneString[1] = '\0';
if (XKeysymToKeycode(XtDisplay(XtParent(w)),
XStringToKeysym(mneString)) == keycode)
{
if (XtClass(w) == xmLabelWidgetClass
|| XtClass(w) == xmLabelGadgetClass)
{
XtVaGetValues(w, XmNuserData, &userData, NULL);
if (userData != NULL && XtIsWidget(userData))
XmProcessTraversal(userData, XmTRAVERSE_CURRENT);
}
else
{
XKeyPressedEvent keyEvent;

XmProcessTraversal(w, XmTRAVERSE_CURRENT);

vim_memset((char *) &keyEvent, 0, sizeof(XKeyPressedEvent));
keyEvent.type = KeyPress;
keyEvent.serial = 1;
keyEvent.send_event = True;
keyEvent.display = XtDisplay(w);
keyEvent.window = XtWindow(w);
XtCallActionProc(w, "Activate", (XEvent *) & keyEvent,
NULL, 0);
}
}
}
    }
}

/*
* Callback routine for dialog mnemonic processing.
*/
    static void
mnemonic_event(Widget w, XtPointer call_data UNUSED, XKeyEvent *event)
{
    do_mnemonic(w, event->keycode);
}


/*
* Search the widget tree under w for widgets with mnemonics. When found, add
* a passive grab to the dialog widget for the mnemonic character, thus
* directing mnemonic events to the dialog widget.
*/
    static void
add_mnemonic_grabs(Widget dialog, Widget w)
{
    char mneString[2];
    WidgetList children;
    int numChildren, i;
    Boolean isMenu;
    KeySym mnemonic = '\0';
    unsigned char rowColType;

    if (XtIsComposite(w))
    {
if (XtClass(w) == xmRowColumnWidgetClass)
{
XtVaGetValues(w, XmNrowColumnType, &rowColType, NULL);
isMenu = (rowColType != (unsigned char)XmWORK_AREA);
}
else
isMenu = False;
if (!isMenu)
{
XtVaGetValues(w, XmNchildren, &children, XmNnumChildren,
&numChildren, NULL);
for (i = 0; i < numChildren; i++)
add_mnemonic_grabs(dialog, children[i]);
}
    }
    else
    {
XtVaGetValues(w, XmNmnemonic, &mnemonic, NULL);
if (mnemonic != '\0')
{
mneString[0] = mnemonic;
mneString[1] = '\0';
XtGrabKey(dialog, XKeysymToKeycode(XtDisplay(dialog),
XStringToKeysym(mneString)),
Mod1Mask, True, GrabModeAsync, GrabModeAsync);
}
    }
}

/*
* Add a handler for mnemonics in a dialog. Motif itself only handles
* mnemonics in menus. Mnemonics added or changed after this call will be
* ignored.
*
* To add a mnemonic to a text field or list, set the XmNmnemonic resource on
* the appropriate label and set the XmNuserData resource of the label to the
* widget to get the focus when the mnemonic is typed.
*/
    static void
activate_dialog_mnemonics(Widget dialog)
{
    if (!dialog)
return;

    XtAddEventHandler(dialog, KeyPressMask, False,
(XtEventHandler) mnemonic_event, (XtPointer) NULL);
    add_mnemonic_grabs(dialog, dialog);
}

/*
* Removes the event handler and key-grabs for dialog mnemonic handling.
*/
    static void
suppress_dialog_mnemonics(Widget dialog)
{
    if (!dialog)
return;

    XtUngrabKey(dialog, AnyKey, Mod1Mask);
    XtRemoveEventHandler(dialog, KeyPressMask, False,
(XtEventHandler) mnemonic_event, (XtPointer) NULL);
}

#if defined(FEAT_BROWSE) || defined(FEAT_GUI_DIALOG)
static void set_fontlist __ARGS((Widget wg));

/*
* Use the 'guifont' or 'guifontset' as a fontlist for a dialog widget.
*/
    static void
set_fontlist(id)
    Widget id;
{
    XmFontList fl;

#ifdef FONTSET_ALWAYS
    if (gui.fontset != NOFONTSET)
    {
fl = gui_motif_fontset2fontlist((XFontSet *)&gui.fontset);
if (fl != NULL)
{
if (XtIsManaged(id))
{
XtUnmanageChild(id);
XtVaSetValues(id, XmNfontList, fl, NULL);
/* We should force the widget to recalculate it's
* geometry now. */
XtManageChild(id);
}
else
XtVaSetValues(id, XmNfontList, fl, NULL);
XmFontListFree(fl);
}
    }
#else
    if (gui.norm_font != NOFONT)
    {
fl = gui_motif_create_fontlist((XFontStruct *)gui.norm_font);
if (fl != NULL)
{
if (XtIsManaged(id))
{
XtUnmanageChild(id);
XtVaSetValues(id, XmNfontList, fl, NULL);
/* We should force the widget to recalculate it's
* geometry now. */
XtManageChild(id);
}
else
XtVaSetValues(id, XmNfontList, fl, NULL);
XmFontListFree(fl);
}
    }
#endif
}
#endif

#if defined(FEAT_BROWSE) || defined(PROTO)

/*
* file selector related stuff
*/

#include <Xm/FileSB.h>
#include <Xm/XmStrDefs.h>

typedef struct dialog_callback_arg
{
    char * args; /* not used right now */
    int id;
} dcbarg_T;

static Widget dialog_wgt;
static char *browse_fname = NULL;
static XmStringCharSet charset = (XmStringCharSet) XmSTRING_DEFAULT_CHARSET;
/* used to set up XmStrings */

static void DialogCancelCB __ARGS((Widget, XtPointer, XtPointer));
static void DialogAcceptCB __ARGS((Widget, XtPointer, XtPointer));

/*
* This function is used to translate the predefined label text of the
* precomposed dialogs. We do this explicitly to allow:
*
* - usage of gettext for translation, as in all the other places.
*
* - equalize the messages between different GUI implementations as far as
* possible.
*/
static void set_predefined_label __ARGS((Widget parent, String name, char *new_label));

static void
set_predefined_label(parent, name, new_label)
    Widget parent;
    String name;
    char *new_label;
{
    XmString str;
    Widget w;
    char_u *p, *next;
    KeySym mnemonic = NUL;

    w = XtNameToWidget(parent, name);

    if (!w)
return;

    p = vim_strsave((char_u *)new_label);
    if (p == NULL)
return;
    for (next = p; *next; ++next)
    {
if (*next == DLG_HOTKEY_CHAR)
{
int len = STRLEN(next);

if (len > 0)
{
mch_memmove(next, next + 1, len);
mnemonic = next[0];
}
}
    }

    str = XmStringCreate((char *)p, STRING_TAG);
    vim_free(p);

    if (str != NULL)
    {
XtVaSetValues(w,
XmNlabelString, str,
XmNmnemonic, mnemonic,
NULL);
XmStringFree(str);
    }
    gui_motif_menu_fontlist(w);
}

static void
set_predefined_fontlist(parent, name)
    Widget parent;
    String name;
{
    Widget w;
    w = XtNameToWidget(parent, name);

    if (!w)
return;

    set_fontlist(w);
}

/*
* Put up a file requester.
* Returns the selected name in allocated memory, or NULL for Cancel.
*/
    char_u *
gui_mch_browse(saving, title, dflt, ext, initdir, filter)
    int saving UNUSED; /* select file to write */
    char_u *title; /* title for the window */
    char_u *dflt; /* default name */
    char_u *ext UNUSED; /* not used (extension added) */
    char_u *initdir; /* initial directory, NULL for current dir */
    char_u *filter; /* file name filter */
{
    char_u dirbuf[MAXPATHL];
    char_u dfltbuf[MAXPATHL];
    char_u *pattern;
    char_u *tofree = NULL;

    /* There a difference between the resource name and value, Therefore, we
* avoid to (ab-)use the (maybe internationalized!) dialog title as a
* dialog name.
*/

    dialog_wgt = XmCreateFileSelectionDialog(vimShell, "browseDialog", NULL, 0);

    if (initdir == NULL || *initdir == NUL)
    {
mch_dirname(dirbuf, MAXPATHL);
initdir = dirbuf;
    }

    if (dflt == NULL)
dflt = (char_u *)"";
    else if (STRLEN(initdir) + STRLEN(dflt) + 2 < MAXPATHL)
    {
/* The default selection should be the full path, "dflt" is only the
* file name. */
STRCPY(dfltbuf, initdir);
add_pathsep(dfltbuf);
STRCAT(dfltbuf, dflt);
dflt = dfltbuf;
    }

    /* Can only use one pattern for a file name. Get the first pattern out of
* the filter. An empty pattern means everything matches. */
    if (filter == NULL)
pattern = (char_u *)"";
    else
    {
char_u *s, *p;

s = filter;
for (p = filter; *p != NUL; ++p)
{
if (*p == '\t') /* end of description, start of pattern */
s = p + 1;
if (*p == ';' || *p == '\n') /* end of (first) pattern */
break;
}
pattern = vim_strnsave(s, p - s);
tofree = pattern;
if (pattern == NULL)
pattern = (char_u *)"";
    }

    XtVaSetValues(dialog_wgt,
XtVaTypedArg,
XmNdirectory, XmRString, (char *)initdir, STRLEN(initdir) + 1,
XtVaTypedArg,
XmNdirSpec, XmRString, (char *)dflt, STRLEN(dflt) + 1,
XtVaTypedArg,
XmNpattern, XmRString, (char *)pattern, STRLEN(pattern) + 1,
XtVaTypedArg,
XmNdialogTitle, XmRString, (char *)title, STRLEN(title) + 1,
NULL);

    set_predefined_label(dialog_wgt, "Apply", _("&Filter"));
    set_predefined_label(dialog_wgt, "Cancel", _("&Cancel"));
    set_predefined_label(dialog_wgt, "Dir", _("Directories"));
    set_predefined_label(dialog_wgt, "FilterLabel", _("Filter"));
    set_predefined_label(dialog_wgt, "Help", _("&Help"));
    set_predefined_label(dialog_wgt, "Items", _("Files"));
    set_predefined_label(dialog_wgt, "OK", _("&OK"));
    set_predefined_label(dialog_wgt, "Selection", _("Selection"));

    /* This is to save us from silly external settings using not fixed with
* fonts for file selection.
*/
    set_predefined_fontlist(dialog_wgt, "DirListSW.DirList");
    set_predefined_fontlist(dialog_wgt, "ItemsListSW.ItemsList");

    gui_motif_menu_colors(dialog_wgt);
    if (gui.scroll_bg_pixel != INVALCOLOR)
XtVaSetValues(dialog_wgt, XmNtroughColor, gui.scroll_bg_pixel, NULL);

    XtAddCallback(dialog_wgt, XmNokCallback, DialogAcceptCB, (XtPointer)0);
    XtAddCallback(dialog_wgt, XmNcancelCallback, DialogCancelCB, (XtPointer)0);
    /* We have no help in this window, so hide help button */
    XtUnmanageChild(XmFileSelectionBoxGetChild(dialog_wgt,
(unsigned char)XmDIALOG_HELP_BUTTON));

    manage_centered(dialog_wgt);
    activate_dialog_mnemonics(dialog_wgt);

    /* sit in a loop until the dialog box has gone away */
    do
    {
XtAppProcessEvent(XtWidgetToApplicationContext(dialog_wgt),
(XtInputMask)XtIMAll);
    } while (XtIsManaged(dialog_wgt));

    suppress_dialog_mnemonics(dialog_wgt);
    XtDestroyWidget(dialog_wgt);
    vim_free(tofree);

    if (browse_fname == NULL)
return NULL;
    return vim_strsave((char_u *)browse_fname);
}

/*
* The code below was originally taken from
* /usr/examples/motif/xmsamplers/xmeditor.c
* on Digital Unix 4.0d, but heavily modified.
*/

/*
* Process callback from Dialog cancel actions.
*/
    static void
DialogCancelCB(w, client_data, call_data)
    Widget w UNUSED; /* widget id */
    XtPointer client_data UNUSED; /* data from application */
    XtPointer call_data UNUSED; /* data from widget class */
{
    if (browse_fname != NULL)
    {
XtFree(browse_fname);
browse_fname = NULL;
    }
    XtUnmanageChild(dialog_wgt);
}

/*
* Process callback from Dialog actions.
*/
    static void
DialogAcceptCB(w, client_data, call_data)
    Widget w UNUSED; /* widget id */
    XtPointer client_data UNUSED; /* data from application */
    XtPointer call_data; /* data from widget class */
{
    XmFileSelectionBoxCallbackStruct *fcb;

    if (browse_fname != NULL)
    {
XtFree(browse_fname);
browse_fname = NULL;
    }
    fcb = (XmFileSelectionBoxCallbackStruct *)call_data;

    /* get the filename from the file selection box */
    XmStringGetLtoR(fcb->value, charset, &browse_fname);

    /* popdown the file selection box */
    XtUnmanageChild(dialog_wgt);
}

#endif /* FEAT_BROWSE */

#if defined(FEAT_GUI_DIALOG) || defined(PROTO)

static int dialogStatus;

static void keyhit_callback __ARGS((Widget w, XtPointer client_data, XEvent *event, Boolean *cont));
static void butproc __ARGS((Widget w, XtPointer client_data, XtPointer call_data));

/*
* Callback function for the textfield. When CR is hit this works like
* hitting the "OK" button, ESC like "Cancel".
*/
    static void
keyhit_callback(w, client_data, event, cont)
    Widget w;
    XtPointer client_data UNUSED;
    XEvent *event;
    Boolean *cont UNUSED;
{
    char buf[2];
    KeySym key_sym;

    if (XLookupString(&(event->xkey), buf, 2, &key_sym, NULL) == 1)
    {
if (*buf == CAR)
dialogStatus = 1;
else if (*buf == ESC)
dialogStatus = 2;
    }
    if ((key_sym == XK_Left || key_sym == XK_Right)
&& !(event->xkey.state & ShiftMask))
XmTextFieldClearSelection(w, XtLastTimestampProcessed(gui.dpy));
}

    static void
butproc(w, client_data, call_data)
    Widget w UNUSED;
    XtPointer client_data;
    XtPointer call_data UNUSED;
{
    dialogStatus = (int)(long)client_data + 1;
}

#ifdef HAVE_XPM

static Widget create_pixmap_label(Widget parent, String name, char **data, ArgList args, Cardinal arg);

    static Widget
create_pixmap_label(parent, name, data, args, arg)
    Widget parent;
    String name;
    char **data;
    ArgList args;
    Cardinal arg;
{
    Widget label;
    Display *dsp;
    Screen *scr;
    int depth;
    Pixmap pixmap = 0;
    XpmAttributes attr;
    Boolean rs;
    XpmColorSymbol color[5] =
    {
{"none", NULL, 0},
{"iconColor1", NULL, 0},
{"bottomShadowColor", NULL, 0},
{"topShadowColor", NULL, 0},
{"selectColor", NULL, 0}
    };

    label = XmCreateLabelGadget(parent, name, args, arg);

    /*
* We need to be careful here, since in case of gadgets, there is
* no way to get the background color directly from the widget itself.
* In such cases we get it from The Core part of his parent instead.
*/
    dsp = XtDisplayOfObject(label);
    scr = XtScreenOfObject(label);
    XtVaGetValues(XtIsSubclass(label, coreWidgetClass)
? label : XtParent(label),
XmNdepth, &depth,
XmNbackground, &color[0].pixel,
XmNforeground, &color[1].pixel,
XmNbottomShadowColor, &color[2].pixel,
XmNtopShadowColor, &color[3].pixel,
XmNhighlight, &color[4].pixel,
NULL);

    attr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
    attr.colorsymbols = color;
    attr.numsymbols = 5;
    attr.closeness = 65535;
    attr.depth = depth;
    XpmCreatePixmapFromData(dsp, RootWindowOfScreen(scr),
data, &pixmap, NULL, &attr);

    XtVaGetValues(label, XmNrecomputeSize, &rs, NULL);
    XtVaSetValues(label, XmNrecomputeSize, True, NULL);
    XtVaSetValues(label,
XmNlabelType, XmPIXMAP,
XmNlabelPixmap, pixmap,
NULL);
    XtVaSetValues(label, XmNrecomputeSize, rs, NULL);

    return label;
}
#endif

    int
gui_mch_dialog(type, title, message, button_names, dfltbutton, textfield, ex_cmd)
    int type UNUSED;
    char_u *title;
    char_u *message;
    char_u *button_names;
    int dfltbutton;
    char_u *textfield; /* buffer of size IOSIZE */
    int ex_cmd UNUSED;
{
    char_u *buts;
    char_u *p, *next;
    XtAppContext app;
    XmString label;
    int butcount;
    Widget w;
    Widget dialogform = NULL;
    Widget form = NULL;
    Widget dialogtextfield = NULL;
    Widget *buttons;
    Widget sep_form = NULL;
    Boolean vertical;
    Widget separator = NULL;
    int n;
    Arg args[6];
#ifdef HAVE_XPM
    char **icon_data = NULL;
    Widget dialogpixmap = NULL;
#endif

    if (title == NULL)
title = (char_u *)_("Vim dialog");

    /* if our pointer is currently hidden, then we should show it. */
    gui_mch_mousehide(FALSE);

    dialogform = XmCreateFormDialog(vimShell, (char *)"dialog", NULL, 0);

    /* Check 'v' flag in 'guioptions': vertical button placement. */
    vertical = (vim_strchr(p_go, GO_VERTICAL) != NULL);

    /* Set the title of the Dialog window */
    label = XmStringCreateSimple((char *)title);
    if (label == NULL)
return -1;
    XtVaSetValues(dialogform,
XmNdialogTitle, label,
XmNhorizontalSpacing, 4,
XmNverticalSpacing, vertical ? 0 : 4,
NULL);
    XmStringFree(label);

    /* make a copy, so that we can insert NULs */
    buts = vim_strsave(button_names);
    if (buts == NULL)
return -1;

    /* Count the number of buttons and allocate buttons[]. */
    butcount = 1;
    for (p = buts; *p; ++p)
if (*p == DLG_BUTTON_SEP)
++butcount;
    buttons = (Widget *)alloc((unsigned)(butcount * sizeof(Widget)));
    if (buttons == NULL)
    {
vim_free(buts);
return -1;
    }

    /*
* Create the buttons.
*/
    sep_form = (Widget) 0;
    p = buts;
    for (butcount = 0; *p; ++butcount)
    {
KeySym mnemonic = NUL;

for (next = p; *next; ++next)
{
if (*next == DLG_HOTKEY_CHAR)
{
int len = STRLEN(next);

if (len > 0)
{
mch_memmove(next, next + 1, len);
mnemonic = next[0];
}
}
if (*next == DLG_BUTTON_SEP)
{
*next++ = NUL;
break;
}
}
label = XmStringCreate(_((char *)p), STRING_TAG);
if (label == NULL)
break;

buttons[butcount] = XtVaCreateManagedWidget("button",
xmPushButtonWidgetClass, dialogform,
XmNlabelString, label,
XmNmnemonic, mnemonic,
XmNbottomAttachment, XmATTACH_FORM,
XmNbottomOffset, 4,
XmNshowAsDefault, butcount == dfltbutton - 1,
XmNdefaultButtonShadowThickness, 1,
NULL);
XmStringFree(label);
gui_motif_menu_fontlist(buttons[butcount]);

/* Layout properly. */

if (butcount > 0)
{
if (vertical)
XtVaSetValues(buttons[butcount],
XmNtopWidget, buttons[butcount - 1],
NULL);
else
{
if (*next == NUL)
{
XtVaSetValues(buttons[butcount],
XmNrightAttachment, XmATTACH_FORM,
XmNrightOffset, 4,
NULL);

/* fill in a form as invisible separator */
sep_form = XtVaCreateWidget("separatorForm",
xmFormWidgetClass, dialogform,
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, buttons[butcount - 1],
XmNrightAttachment, XmATTACH_WIDGET,
XmNrightWidget, buttons[butcount],
XmNbottomAttachment, XmATTACH_FORM,
XmNbottomOffset, 4,
NULL);
XtManageChild(sep_form);
}
else
{
XtVaSetValues(buttons[butcount],
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, buttons[butcount - 1],
NULL);
}
}
}
else if (!vertical)
{
if (*next == NUL)
{
XtVaSetValues(buttons[0],
XmNrightAttachment, XmATTACH_FORM,
XmNrightOffset, 4,
NULL);

/* fill in a form as invisible separator */
sep_form = XtVaCreateWidget("separatorForm",
xmFormWidgetClass, dialogform,
XmNleftAttachment, XmATTACH_FORM,
XmNleftOffset, 4,
XmNrightAttachment, XmATTACH_WIDGET,
XmNrightWidget, buttons[0],
XmNbottomAttachment, XmATTACH_FORM,
XmNbottomOffset, 4,
NULL);
XtManageChild(sep_form);
}
else
XtVaSetValues(buttons[0],
XmNleftAttachment, XmATTACH_FORM,
XmNleftOffset, 4,
NULL);
}

XtAddCallback(buttons[butcount], XmNactivateCallback,
(XtCallbackProc)butproc, (XtPointer)(long)butcount);
p = next;
    }
    vim_free(buts);

    separator = (Widget) 0;
    if (butcount > 0)
    {
/* Create the separator for beauty. */
n = 0;
XtSetArg(args[n], XmNorientation, XmHORIZONTAL); n++;
XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;
XtSetArg(args[n], XmNbottomWidget, buttons[0]); n++;
XtSetArg(args[n], XmNbottomOffset, 4); n++;
XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
XtSetArg(args[n], XmNrightAttachment, XmATTACH_FORM); n++;
separator = XmCreateSeparatorGadget(dialogform, "separator", args, n);
XtManageChild(separator);
    }

    if (textfield != NULL)
    {
dialogtextfield = XtVaCreateWidget("textField",
xmTextFieldWidgetClass, dialogform,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL);
if (butcount > 0)
XtVaSetValues(dialogtextfield,
XmNbottomAttachment, XmATTACH_WIDGET,
XmNbottomWidget, separator,
NULL);
else
XtVaSetValues(dialogtextfield,
XmNbottomAttachment, XmATTACH_FORM,
NULL);

set_fontlist(dialogtextfield);
XmTextFieldSetString(dialogtextfield, (char *)textfield);
XtManageChild(dialogtextfield);
XtAddEventHandler(dialogtextfield, KeyPressMask, False,
(XtEventHandler)keyhit_callback, (XtPointer)NULL);
    }

    /* Form holding both message and pixmap labels */
    form = XtVaCreateWidget("separatorForm",
xmFormWidgetClass, dialogform,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
NULL);
    XtManageChild(form);

#ifdef HAVE_XPM
    /* Add a pixmap, left of the message. */
    switch (type)
    {
case VIM_GENERIC:
icon_data = generic_xpm;
break;
case VIM_ERROR:
icon_data = error_xpm;
break;
case VIM_WARNING:
icon_data = alert_xpm;
break;
case VIM_INFO:
icon_data = info_xpm;
break;
case VIM_QUESTION:
icon_data = quest_xpm;
break;
default:
icon_data = generic_xpm;
    }

    n = 0;
    XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
    XtSetArg(args[n], XmNtopOffset, 8); n++;
    XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
    XtSetArg(args[n], XmNbottomOffset, 8); n++;
    XtSetArg(args[n], XmNleftAttachment, XmATTACH_FORM); n++;
    XtSetArg(args[n], XmNleftOffset, 8); n++;

    dialogpixmap = create_pixmap_label(form, "dialogPixmap",
icon_data, args, n);
    XtManageChild(dialogpixmap);
#endif

    /* Create the dialog message.
* Since LessTif is apparently having problems with the creation of
* properly localized string, we use LtoR here. The symptom is that the
* string sill not show properly in multiple lines as it does in native
* Motif.
*/
    label = XmStringCreateLtoR((char *)message, STRING_TAG);
    if (label == NULL)
return -1;
    w = XtVaCreateManagedWidget("dialogMessage",
xmLabelGadgetClass, form,
XmNlabelString, label,
XmNalignment, XmALIGNMENT_BEGINNING,
XmNtopAttachment, XmATTACH_FORM,
XmNtopOffset, 8,
#ifdef HAVE_XPM
XmNleftAttachment, XmATTACH_WIDGET,
XmNleftWidget, dialogpixmap,
#else
XmNleftAttachment, XmATTACH_FORM,
#endif
XmNleftOffset, 8,
XmNrightAttachment, XmATTACH_FORM,
XmNrightOffset, 8,
XmNbottomAttachment, XmATTACH_FORM,
XmNbottomOffset, 8,
NULL);
    XmStringFree(label);
    set_fontlist(w);

    if (textfield != NULL)
    {
XtVaSetValues(form,
XmNbottomAttachment, XmATTACH_WIDGET,
XmNbottomWidget, dialogtextfield,
NULL);
    }
    else
    {
if (butcount > 0)
XtVaSetValues(form,
XmNbottomAttachment, XmATTACH_WIDGET,
XmNbottomWidget, separator,
NULL);
else
XtVaSetValues(form,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
    }

    if (dfltbutton < 1)
dfltbutton = 1;
    if (dfltbutton > butcount)
dfltbutton = butcount;
    XtVaSetValues(dialogform,
XmNdefaultButton, buttons[dfltbutton - 1], NULL);
    if (textfield != NULL)
XtVaSetValues(dialogform, XmNinitialFocus, dialogtextfield, NULL);
    else
XtVaSetValues(dialogform, XmNinitialFocus, buttons[dfltbutton - 1],
NULL);

    manage_centered(dialogform);
    activate_dialog_mnemonics(dialogform);

    if (textfield != NULL && *textfield != NUL)
    {
/* This only works after the textfield has been realised. */
XmTextFieldSetSelection(dialogtextfield,
(XmTextPosition)0, (XmTextPosition)STRLEN(textfield),
XtLastTimestampProcessed(gui.dpy));
XmTextFieldSetCursorPosition(dialogtextfield,
(XmTextPosition)STRLEN(textfield));
    }

    app = XtWidgetToApplicationContext(dialogform);

    /* Loop until a button is pressed or the dialog is killed somehow. */
    dialogStatus = -1;
    for (;;)
    {
XtAppProcessEvent(app, (XtInputMask)XtIMAll);
if (dialogStatus >= 0 || !XtIsManaged(dialogform))
break;
    }

    vim_free(buttons);

    if (textfield != NULL)
    {
p = (char_u *)XmTextGetString(dialogtextfield);
if (p == NULL || dialogStatus < 0)
*textfield = NUL;
else
vim_strncpy(textfield, p, IOSIZE - 1);
XtFree((char *)p);
    }

    suppress_dialog_mnemonics(dialogform);
    XtDestroyWidget(dialogform);

    return dialogStatus;
}
#endif /* FEAT_GUI_DIALOG */

#if defined(FEAT_FOOTER) || defined(PROTO)

    static int
gui_mch_compute_footer_height()
{
    Dimension height; /* total Toolbar height */
    Dimension top; /* XmNmarginTop */
    Dimension bottom; /* XmNmarginBottom */
    Dimension shadow; /* XmNshadowThickness */

    XtVaGetValues(footer,
XmNheight, &height,
XmNmarginTop, &top,
XmNmarginBottom, &bottom,
XmNshadowThickness, &shadow,
NULL);

    return (int) height + top + bottom + (shadow << 1);
}

    void
gui_mch_enable_footer(showit)
    int showit;
{
    if (showit)
    {
gui.footer_height = gui_mch_compute_footer_height();
XtManageChild(footer);
    }
    else
    {
gui.footer_height = 0;
XtUnmanageChild(footer);
    }
    XtVaSetValues(textAreaForm, XmNbottomOffset, gui.footer_height, NULL);
}

    void
gui_mch_set_footer(s)
    char_u *s;
{
    XmString xms;

    xms = XmStringCreate((char *)s, STRING_TAG);
    if (xms != NULL)
    {
XtVaSetValues(footer, XmNlabelString, xms, NULL);
XmStringFree(xms);
    }
}

#endif


#if defined(FEAT_TOOLBAR) || defined(PROTO)
    void
gui_mch_show_toolbar(int showit)
{
    Cardinal numChildren; /* how many children toolBar has */

    if (toolBar == (Widget)0)
return;
    XtVaGetValues(toolBar, XmNnumChildren, &numChildren, NULL);
    if (showit && numChildren > 0)
    {
/* Assume that we want to show the toolbar if p_toolbar contains
* valid option settings, therefore p_toolbar must not be NULL.
*/
WidgetList children;

XtVaGetValues(toolBar, XmNchildren, &children, NULL);
{
void (*action)(BalloonEval *);
int text = 0;

if (strstr((const char *)p_toolbar, "tooltips"))
action = &gui_mch_enable_beval_area;
else
action = &gui_mch_disable_beval_area;
if (strstr((const char *)p_toolbar, "text"))
text = 1;
else if (strstr((const char *)p_toolbar, "icons"))
text = -1;
if (text != 0)
{
vimmenu_T *toolbar;
vimmenu_T *cur;

for (toolbar = root_menu; toolbar; toolbar = toolbar->next)
if (menu_is_toolbar(toolbar->dname))
break;
/* Assumption: toolbar is NULL if there is no toolbar,
* otherwise it contains the toolbar menu structure.
*
* Assumption: "numChildren" == the number of items in the list
* of items beginning with toolbar->children.
*/
if (toolbar)
{
for (cur = toolbar->children; cur; cur = cur->next)
{
Arg args[1];
int n = 0;

/* Enable/Disable tooltip (OK to enable while
* currently enabled). */
if (cur->tip != NULL)
(*action)(cur->tip);
if (!menu_is_separator(cur->name))
{
if (text == 1 || cur->xpm == NULL)
{
XtSetArg(args[n], XmNlabelType, XmSTRING);
++n;
}
if (cur->id != NULL)
{
XtUnmanageChild(cur->id);
XtSetValues(cur->id, args, n);
XtManageChild(cur->id);
}
}
}
}
}
}
gui.toolbar_height = gui_mch_compute_toolbar_height();
XtManageChild(XtParent(toolBar));
#ifdef FEAT_GUI_TABLINE
if (showing_tabline)
{
XtVaSetValues(tabLine,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, XtParent(toolBar),
NULL);
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, tabLine,
NULL);
}
else
#endif
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, XtParent(toolBar),
NULL);
if (XtIsManaged(menuBar))
XtVaSetValues(XtParent(toolBar),
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, menuBar,
NULL);
else
XtVaSetValues(XtParent(toolBar),
XmNtopAttachment, XmATTACH_FORM,
NULL);
    }
    else
    {
gui.toolbar_height = 0;
if (XtIsManaged(menuBar))
{
#ifdef FEAT_GUI_TABLINE
if (showing_tabline)
{
XtVaSetValues(tabLine,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, menuBar,
NULL);
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, tabLine,
NULL);
}
else
#endif
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, menuBar,
NULL);
}
else
{
#ifdef FEAT_GUI_TABLINE
if (showing_tabline)
{
XtVaSetValues(tabLine,
XmNtopAttachment, XmATTACH_FORM,
NULL);
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, tabLine,
NULL);
}
else
#endif
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_FORM,
NULL);
}

XtUnmanageChild(XtParent(toolBar));
    }
    gui_set_shellsize(FALSE, FALSE, RESIZE_VERT);
}

/*
* A toolbar button has been pushed; now reset the input focus
* such that the user can type page up/down etc. and have the
* input go to the editor window, not the button
*/
    static void
reset_focus()
{
    if (textArea != NULL)
XmProcessTraversal(textArea, XmTRAVERSE_CURRENT);
}

    int
gui_mch_compute_toolbar_height()
{
    Dimension borders;
    Dimension height; /* total Toolbar height */
    Dimension whgt; /* height of each widget */
    WidgetList children; /* list of toolBar's children */
    Cardinal numChildren; /* how many children toolBar has */
    int i;

    borders = 0;
    height = 0;
    if (toolBar != (Widget)0 && toolBarFrame != (Widget)0)
    { /* get height of XmFrame parent */
Dimension fst;
Dimension fmh;
Dimension tst;
Dimension tmh;

XtVaGetValues(toolBarFrame,
XmNshadowThickness, &fst,
XmNmarginHeight, &fmh,
NULL);
borders += fst + fmh;
XtVaGetValues(toolBar,
XmNshadowThickness, &tst,
XmNmarginHeight, &tmh,
XmNchildren, &children,
XmNnumChildren, &numChildren, NULL);
borders += tst + tmh;
for (i = 0; i < (int)numChildren; i++)
{
whgt = 0;
XtVaGetValues(children[i], XmNheight, &whgt, NULL);
if (height < whgt)
height = whgt;
}
    }
#ifdef LESSTIF_VERSION
    /* Hack: When starting up we get wrong dimensions. */
    if (height < 10)
height = 24;
#endif

    return (int)(height + (borders << 1));
}

    void
motif_get_toolbar_colors(bgp, fgp, bsp, tsp, hsp)
    Pixel *bgp;
    Pixel *fgp;
    Pixel *bsp;
    Pixel *tsp;
    Pixel *hsp;
{
    XtVaGetValues(toolBar,
XmNbackground, bgp,
XmNforeground, fgp,
XmNbottomShadowColor, bsp,
XmNtopShadowColor, tsp,
XmNhighlightColor, hsp,
NULL);
}

# ifdef FEAT_FOOTER
/*
* The next toolbar enter/leave callbacks should really do balloon help. But
* I have to use footer help for backwards compatability. Hopefully both will
* get implemented and the user will have a choice.
*/
    static void
toolbarbutton_enter_cb(w, client_data, event, cont)
    Widget w UNUSED;
    XtPointer client_data;
    XEvent *event UNUSED;
    Boolean *cont UNUSED;
{
    vimmenu_T *menu = (vimmenu_T *) client_data;

    if (menu->strings[MENU_INDEX_TIP] != NULL)
    {
if (vim_strchr(p_go, GO_FOOTER) != NULL)
gui_mch_set_footer(menu->strings[MENU_INDEX_TIP]);
    }
}

    static void
toolbarbutton_leave_cb(w, client_data, event, cont)
    Widget w UNUSED;
    XtPointer client_data UNUSED;
    XEvent *event UNUSED;
    Boolean *cont UNUSED;
{
    gui_mch_set_footer((char_u *) "");
}
# endif
#endif

#if defined(FEAT_GUI_TABLINE) || defined(PROTO)
/*
* Show or hide the tabline.
*/
    void
gui_mch_show_tabline(int showit)
{
    if (tabLine == (Widget)0)
return;

    if (!showit != !showing_tabline)
    {
if (showit)
{
XtManageChild(tabLine);
XtUnmanageChild(XtNameToWidget(tabLine, "PageScroller"));
XtUnmanageChild(XtNameToWidget(tabLine, "MinorTabScrollerNext"));
XtUnmanageChild(XtNameToWidget(tabLine,
"MinorTabScrollerPrevious"));
#ifdef FEAT_MENU
# ifdef FEAT_TOOLBAR
if (XtIsManaged(XtParent(toolBar)))
XtVaSetValues(tabLine,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, XtParent(toolBar), NULL);
else
# endif
if (XtIsManaged(menuBar))
XtVaSetValues(tabLine,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, menuBar, NULL);
else
#endif
XtVaSetValues(tabLine,
XmNtopAttachment, XmATTACH_FORM, NULL);
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, tabLine,
NULL);
}
else
{
XtUnmanageChild(tabLine);
#ifdef FEAT_MENU
# ifdef FEAT_TOOLBAR
if (XtIsManaged(XtParent(toolBar)))
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, XtParent(toolBar), NULL);
else
# endif
if (XtIsManaged(menuBar))
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, menuBar, NULL);
else
#endif
XtVaSetValues(textAreaForm,
XmNtopAttachment, XmATTACH_FORM, NULL);
}
showing_tabline = showit;
    }
}

/*
* Return TRUE when tabline is displayed.
*/
    int
gui_mch_showing_tabline(void)
{
    return tabLine != (Widget)0 && showing_tabline;
}

/*
* Update the labels of the tabline.
*/
    void
gui_mch_update_tabline(void)
{
    tabpage_T *tp;
    int nr = 1, n;
    Arg args[10];
    int curtabidx = 0, currentpage;
    Widget tab;
    XmNotebookPageInfo page_info;
    XmNotebookPageStatus page_status;
    int last_page, tab_count;
    XmString label_str;
    char *label_cstr;
    BalloonEval *beval;

    if (tabLine == (Widget)0)
return;

    /* Add a label for each tab page. They all contain the same text area. */
    for (tp = first_tabpage; tp != NULL; tp = tp->tp_next, ++nr)
    {
if (tp == curtab)
curtabidx = nr;

page_status = XmNotebookGetPageInfo(tabLine, nr, &page_info);
if (page_status == XmPAGE_INVALID
|| page_info.major_tab_widget == (Widget)0)
{
/* Add the tab */
n = 0;
XtSetArg(args[n], XmNnotebookChildType, XmMAJOR_TAB); n++;
XtSetArg(args[n], XmNtraversalOn, False); n++;
XtSetArg(args[n], XmNalignment, XmALIGNMENT_BEGINNING); n++;
XtSetArg(args[n], XmNhighlightThickness, 1); n++;
XtSetArg(args[n], XmNshadowThickness , 1); n++;
tab = XmCreatePushButton(tabLine, "-Empty-", args, n);
XtManageChild(tab);
beval = gui_mch_create_beval_area(tab, NULL, tabline_balloon_cb,
NULL);
XtVaSetValues(tab, XmNuserData, beval, NULL);
}
else
tab = page_info.major_tab_widget;

XtVaSetValues(tab, XmNpageNumber, nr, NULL);

/*
* Change the label text only if it is different
*/
XtVaGetValues(tab, XmNlabelString, &label_str, NULL);
if (XmStringGetLtoR(label_str, XmSTRING_DEFAULT_CHARSET, &label_cstr))
{
get_tabline_label(tp, FALSE);
if (STRCMP(label_cstr, NameBuff) != 0)
{
XtVaSetValues(tab, XtVaTypedArg, XmNlabelString, XmRString,
NameBuff, STRLEN(NameBuff) + 1, NULL);
/*
* Force a resize of the tab label button
*/
XtUnmanageChild(tab);
XtManageChild(tab);
}
XtFree(label_cstr);
}
    }

    tab_count = nr - 1;

    XtVaGetValues(tabLine, XmNlastPageNumber, &last_page, NULL);

    /* Remove any old labels. */
    while (nr <= last_page)
    {
if (XmNotebookGetPageInfo(tabLine, nr, &page_info) != XmPAGE_INVALID
&& page_info.page_number == nr
&& page_info.major_tab_widget != (Widget)0)
{
XtVaGetValues(page_info.major_tab_widget, XmNuserData, &beval, NULL);
if (beval != NULL)
gui_mch_destroy_beval_area(beval);
XtUnmanageChild(page_info.major_tab_widget);
XtDestroyWidget(page_info.major_tab_widget);
}
nr++;
    }

    XtVaSetValues(tabLine, XmNlastPageNumber, tab_count, NULL);

    XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
    if (currentpage != curtabidx)
XtVaSetValues(tabLine, XmNcurrentPageNumber, curtabidx, NULL);
}

/*
* Set the current tab to "nr". First tab is 1.
*/
    void
gui_mch_set_curtab(nr)
    int nr;
{
    int currentpage;

    if (tabLine == (Widget)0)
return;

    XtVaGetValues(tabLine, XmNcurrentPageNumber, &currentpage, NULL);
    if (currentpage != nr)
XtVaSetValues(tabLine, XmNcurrentPageNumber, nr, NULL);
}
#endif

/*
* Set the colors of Widget "id" to the menu colors.
*/
    static void
gui_motif_menu_colors(id)
    Widget id;
{
    if (gui.menu_bg_pixel != INVALCOLOR)
#if (XmVersion >= 1002)
XmChangeColor(id, gui.menu_bg_pixel);
#else
XtVaSetValues(id, XmNbackground, gui.menu_bg_pixel, NULL);
#endif
    if (gui.menu_fg_pixel != INVALCOLOR)
XtVaSetValues(id, XmNforeground, gui.menu_fg_pixel, NULL);
}

/*
* Set the colors of Widget "id" to the scrollbar colors.
*/
    static void
gui_motif_scroll_colors(id)
    Widget id;
{
    if (gui.scroll_bg_pixel != INVALCOLOR)
#if (XmVersion >= 1002)
XmChangeColor(id, gui.scroll_bg_pixel);
#else
XtVaSetValues(id, XmNbackground, gui.scroll_bg_pixel, NULL);
#endif
    if (gui.scroll_fg_pixel != INVALCOLOR)
XtVaSetValues(id, XmNforeground, gui.scroll_fg_pixel, NULL);
}

/*
* Set the fontlist for Widget "id" to use gui.menu_fontset or gui.menu_font.
*/
    void
gui_motif_menu_fontlist(id)
    Widget id UNUSED;
{
#ifdef FEAT_MENU
#ifdef FONTSET_ALWAYS
    if (gui.menu_fontset != NOFONTSET)
    {
XmFontList fl;

fl = gui_motif_fontset2fontlist((XFontSet *)&gui.menu_fontset);
if (fl != NULL)
{
if (XtIsManaged(id))
{
XtUnmanageChild(id);
XtVaSetValues(id, XmNfontList, fl, NULL);
/* We should force the widget to recalculate it's
* geometry now. */
XtManageChild(id);
}
else
XtVaSetValues(id, XmNfontList, fl, NULL);
XmFontListFree(fl);
}
    }
#else
    if (gui.menu_font != NOFONT)
    {
XmFontList fl;

fl = gui_motif_create_fontlist((XFontStruct *)gui.menu_font);
if (fl != NULL)
{
if (XtIsManaged(id))
{
XtUnmanageChild(id);
XtVaSetValues(id, XmNfontList, fl, NULL);
/* We should force the widget to recalculate it's
* geometry now. */
XtManageChild(id);
}
else
XtVaSetValues(id, XmNfontList, fl, NULL);
XmFontListFree(fl);
}
    }
#endif
#endif
}


/*
* We don't create it twice for the sake of speed.
*/

typedef struct _SharedFindReplace
{
    Widget dialog; /* the main dialog widget */
    Widget wword; /* 'Exact match' check button */
    Widget mcase; /* 'match case' check button */
    Widget up; /* search direction 'Up' radio button */
    Widget down; /* search direction 'Down' radio button */
    Widget what; /* 'Find what' entry text widget */
    Widget with; /* 'Replace with' entry text widget */
    Widget find; /* 'Find Next' action button */
    Widget replace; /* 'Replace With' action button */
    Widget all; /* 'Replace All' action button */
    Widget undo; /* 'Undo' action button */

    Widget cancel;
} SharedFindReplace;

static SharedFindReplace find_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};
static SharedFindReplace repl_widgets = {NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL};

static void find_replace_destroy_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
static void find_replace_dismiss_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
static void entry_activate_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
static void find_replace_callback __ARGS((Widget w, XtPointer client_data, XtPointer call_data));
static void find_replace_keypress __ARGS((Widget w, SharedFindReplace * frdp, XKeyEvent * event));
static void find_replace_dialog_create __ARGS((char_u *entry_text, int do_replace));

    static void
find_replace_destroy_callback(w, client_data, call_data)
    Widget w UNUSED;
    XtPointer client_data;
    XtPointer call_data UNUSED;
{
    SharedFindReplace *cd = (SharedFindReplace *)client_data;

    if (cd != NULL)
       /* suppress_dialog_mnemonics(cd->dialog); */
cd->dialog = (Widget)0;
}

    static void
find_replace_dismiss_callback(w, client_data, call_data)
    Widget w UNUSED;
    XtPointer client_data;
    XtPointer call_data UNUSED;
{
    SharedFindReplace *cd = (SharedFindReplace *)client_data;

    if (cd != NULL)
XtUnmanageChild(cd->dialog);
}

    static void
entry_activate_callback(w, client_data, call_data)
    Widget w UNUSED;
    XtPointer client_data;
    XtPointer call_data UNUSED;
{
    XmProcessTraversal((Widget)client_data, XmTRAVERSE_CURRENT);
}

    static void
find_replace_callback(w, client_data, call_data)
    Widget w UNUSED;
    XtPointer client_data;
    XtPointer call_data UNUSED;
{
    long_u flags = (long_u)client_data;
    char *find_text, *repl_text;
    Boolean direction_down = TRUE;
    Boolean wword;
    Boolean mcase;
    SharedFindReplace *sfr;

    if (flags == FRD_UNDO)
    {
char_u *save_cpo = p_cpo;

/* No need to be Vi compatible here. */
p_cpo = (char_u *)"";
u_undo(1);
p_cpo = save_cpo;
gui_update_screen();
return;
    }

    /* Get the search/replace strings from the dialog */
    if (flags == FRD_FINDNEXT)
    {
repl_text = NULL;
sfr = &find_widgets;
    }
    else
    {
repl_text = XmTextFieldGetString(repl_widgets.with);
sfr = &repl_widgets;
    }
    find_text = XmTextFieldGetString(sfr->what);
    XtVaGetValues(sfr->down, XmNset, &direction_down, NULL);
    XtVaGetValues(sfr->wword, XmNset, &wword, NULL);
    XtVaGetValues(sfr->mcase, XmNset, &mcase, NULL);
    if (wword)
flags |= FRD_WHOLE_WORD;
    if (mcase)
flags |= FRD_MATCH_CASE;

    (void)gui_do_findrepl((int)flags, (char_u *)find_text, (char_u *)repl_text,
direction_down);

    if (find_text != NULL)
XtFree(find_text);
    if (repl_text != NULL)
XtFree(repl_text);
}

    static void
find_replace_keypress(w, frdp, event)
    Widget w UNUSED;
    SharedFindReplace *frdp;
    XKeyEvent *event;
{
    KeySym keysym;

    if (frdp == NULL)
return;

    keysym = XLookupKeysym(event, 0);

    /* the scape key pops the whole dialog down */
    if (keysym == XK_Escape)
XtUnmanageChild(frdp->dialog);
}

    static void
set_label(w, label)
    Widget w;
    char_u *label;
{
    XmString str;
    char_u *p, *next;
    KeySym mnemonic = NUL;

    if (!w)
return;

    p = vim_strsave(label);
    if (p == NULL)
return;
    for (next = p; *next; ++next)
    {
if (*next == DLG_HOTKEY_CHAR)
{
int len = STRLEN(next);

if (len > 0)
{
mch_memmove(next, next + 1, len);
mnemonic = next[0];
}
}
    }

    str = XmStringCreateSimple((char *)p);
    vim_free(p);
    if (str)
    {
XtVaSetValues(w,
XmNlabelString, str,
XmNmnemonic, mnemonic,
NULL);
XmStringFree(str);
    }
    gui_motif_menu_fontlist(w);
}

    static void
find_replace_dialog_create(arg, do_replace)
    char_u *arg;
    int do_replace;
{
    SharedFindReplace *frdp;
    Widget separator;
    Widget input_form;
    Widget button_form;
    Widget toggle_form;
    Widget frame;
    XmString str;
    int n;
    Arg args[6];
    int wword = FALSE;
    int mcase = !p_ic;
    Dimension width;
    Dimension widest;
    char_u *entry_text;

    frdp = do_replace ? &repl_widgets : &find_widgets;

    /* Get the search string to use. */
    entry_text = get_find_dialog_text(arg, &wword, &mcase);

    /* If the dialog already exists, just raise it. */
    if (frdp->dialog)
    {
gui_motif_synch_fonts();

/* If the window is already up, just pop it to the top */
if (XtIsManaged(frdp->dialog))
XMapRaised(XtDisplay(frdp->dialog),
XtWindow(XtParent(frdp->dialog)));
else
XtManageChild(frdp->dialog);
XtPopup(XtParent(frdp->dialog), XtGrabNone);
XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);

if (entry_text != NULL)
XmTextFieldSetString(frdp->what, (char *)entry_text);
vim_free(entry_text);

XtVaSetValues(frdp->wword, XmNset, wword, NULL);
return;
    }

    /* Create a fresh new dialog window */
    if (do_replace)
str = XmStringCreateSimple(_("VIM - Search and Replace..."));
    else
str = XmStringCreateSimple(_("VIM - Search..."));

    n = 0;
    XtSetArg(args[n], XmNautoUnmanage, False); n++;
    XtSetArg(args[n], XmNnoResize, True); n++;
    XtSetArg(args[n], XmNdialogTitle, str); n++;

    frdp->dialog = XmCreateFormDialog(vimShell, "findReplaceDialog", args, n);
    XmStringFree(str);
    XtAddCallback(frdp->dialog, XmNdestroyCallback,
find_replace_destroy_callback, frdp);

    button_form = XtVaCreateWidget("buttonForm",
xmFormWidgetClass, frdp->dialog,
XmNrightAttachment, XmATTACH_FORM,
XmNrightOffset, 4,
XmNtopAttachment, XmATTACH_FORM,
XmNtopOffset, 4,
XmNbottomAttachment, XmATTACH_FORM,
XmNbottomOffset, 4,
NULL);

    frdp->find = XtVaCreateManagedWidget("findButton",
xmPushButtonWidgetClass, button_form,
XmNsensitive, True,
XmNtopAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL);
    set_label(frdp->find, _("Find &Next"));

    XtAddCallback(frdp->find, XmNactivateCallback,
find_replace_callback,
(do_replace ? (XtPointer)FRD_R_FINDNEXT : (XtPointer)FRD_FINDNEXT));

    if (do_replace)
    {
frdp->replace = XtVaCreateManagedWidget("replaceButton",
xmPushButtonWidgetClass, button_form,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, frdp->find,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL);
set_label(frdp->replace, _("&Replace"));
XtAddCallback(frdp->replace, XmNactivateCallback,
find_replace_callback, (XtPointer)FRD_REPLACE);

frdp->all = XtVaCreateManagedWidget("replaceAllButton",
xmPushButtonWidgetClass, button_form,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, frdp->replace,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL);
set_label(frdp->all, _("Replace &All"));
XtAddCallback(frdp->all, XmNactivateCallback,
find_replace_callback, (XtPointer)FRD_REPLACEALL);

frdp->undo = XtVaCreateManagedWidget("undoButton",
xmPushButtonWidgetClass, button_form,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, frdp->all,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
NULL);
set_label(frdp->undo, _("&Undo"));
XtAddCallback(frdp->undo, XmNactivateCallback,
find_replace_callback, (XtPointer)FRD_UNDO);
    }

    frdp->cancel = XtVaCreateManagedWidget("closeButton",
xmPushButtonWidgetClass, button_form,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
    set_label(frdp->cancel, _("&Cancel"));
    XtAddCallback(frdp->cancel, XmNactivateCallback,
find_replace_dismiss_callback, frdp);
    gui_motif_menu_fontlist(frdp->cancel);

    XtManageChild(button_form);

    n = 0;
    XtSetArg(args[n], XmNorientation, XmVERTICAL); n++;
    XtSetArg(args[n], XmNrightAttachment, XmATTACH_WIDGET); n++;
    XtSetArg(args[n], XmNrightWidget, button_form); n++;
    XtSetArg(args[n], XmNrightOffset, 4); n++;
    XtSetArg(args[n], XmNtopAttachment, XmATTACH_FORM); n++;
    XtSetArg(args[n], XmNbottomAttachment, XmATTACH_FORM); n++;
    separator = XmCreateSeparatorGadget(frdp->dialog, "separator", args, n);
    XtManageChild(separator);

    input_form = XtVaCreateWidget("inputForm",
xmFormWidgetClass, frdp->dialog,
XmNleftAttachment, XmATTACH_FORM,
XmNleftOffset, 4,
XmNrightAttachment, XmATTACH_WIDGET,
XmNrightWidget, separator,
XmNrightOffset, 4,
XmNtopAttachment, XmATTACH_FORM,
XmNtopOffset, 4,
NULL);

    {
Widget label_what;
Widget label_with = (Widget)0;

str = XmStringCreateSimple(_("Find what:"));
label_what = XtVaCreateManagedWidget("whatLabel",
xmLabelGadgetClass, input_form,
XmNlabelString, str,
XmNleftAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_FORM,
XmNtopOffset, 4,
NULL);
XmStringFree(str);
gui_motif_menu_fontlist(label_what);

frdp->what = XtVaCreateManagedWidget("whatText",
xmTextFieldWidgetClass, input_form,
XmNtopAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNleftAttachment, XmATTACH_FORM,
NULL);

if (do_replace)
{
frdp->with = XtVaCreateManagedWidget("withText",
xmTextFieldWidgetClass, input_form,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, frdp->what,
XmNtopOffset, 4,
XmNleftAttachment, XmATTACH_FORM,
XmNrightAttachment, XmATTACH_FORM,
XmNbottomAttachment, XmATTACH_FORM,
NULL);

XtAddCallback(frdp->with, XmNactivateCallback,
find_replace_callback, (XtPointer) FRD_R_FINDNEXT);

str = XmStringCreateSimple(_("Replace with:"));
label_with = XtVaCreateManagedWidget("withLabel",
xmLabelGadgetClass, input_form,
XmNlabelString, str,
XmNleftAttachment, XmATTACH_FORM,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, frdp->what,
XmNtopOffset, 4,
XmNbottomAttachment, XmATTACH_FORM,
NULL);
XmStringFree(str);
gui_motif_menu_fontlist(label_with);

/*
* Make the entry activation only change the input focus onto the
* with item.
*/
XtAddCallback(frdp->what, XmNactivateCallback,
entry_activate_callback, frdp->with);
XtAddEventHandler(frdp->with, KeyPressMask, False,
(XtEventHandler)find_replace_keypress,
(XtPointer) frdp);

}
else
{
/*
* Make the entry activation do the search.
*/
XtAddCallback(frdp->what, XmNactivateCallback,
find_replace_callback, (XtPointer)FRD_FINDNEXT);
}
XtAddEventHandler(frdp->what, KeyPressMask, False,
(XtEventHandler)find_replace_keypress,
(XtPointer)frdp);

/* Get the maximum width between the label widgets and line them up.
*/
n = 0;
XtSetArg(args[n], XmNwidth, &width); n++;
XtGetValues(label_what, args, n);
widest = width;
if (do_replace)
{
XtGetValues(label_with, args, n);
if (width > widest)
widest = width;
}

XtVaSetValues(frdp->what, XmNleftOffset, widest, NULL);
if (do_replace)
XtVaSetValues(frdp->with, XmNleftOffset, widest, NULL);

    }

    XtManageChild(input_form);

    {
Widget radio_box;
Widget w;

frame = XtVaCreateWidget("directionFrame",
xmFrameWidgetClass, frdp->dialog,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, input_form,
XmNtopOffset, 4,
XmNbottomAttachment, XmATTACH_FORM,
XmNbottomOffset, 4,
XmNrightAttachment, XmATTACH_OPPOSITE_WIDGET,
XmNrightWidget, input_form,
NULL);

str = XmStringCreateSimple(_("Direction"));
w = XtVaCreateManagedWidget("directionFrameLabel",
xmLabelGadgetClass, frame,
XmNlabelString, str,
XmNchildHorizontalAlignment, XmALIGNMENT_BEGINNING,
XmNchildType, XmFRAME_TITLE_CHILD,
NULL);
XmStringFree(str);
gui_motif_menu_fontlist(w);

radio_box = XmCreateRadioBox(frame, "radioBox",
(ArgList)NULL, 0);

str = XmStringCreateSimple( _("Up"));
frdp->up = XtVaCreateManagedWidget("upRadioButton",
xmToggleButtonGadgetClass, radio_box,
XmNlabelString, str,
XmNset, False,
NULL);
XmStringFree(str);
gui_motif_menu_fontlist(frdp->up);

str = XmStringCreateSimple(_("Down"));
frdp->down = XtVaCreateManagedWidget("downRadioButton",
xmToggleButtonGadgetClass, radio_box,
XmNlabelString, str,
XmNset, True,
NULL);
XmStringFree(str);
gui_motif_menu_fontlist(frdp->down);

XtManageChild(radio_box);
XtManageChild(frame);
    }

    toggle_form = XtVaCreateWidget("toggleForm",
xmFormWidgetClass, frdp->dialog,
XmNleftAttachment, XmATTACH_FORM,
XmNleftOffset, 4,
XmNrightAttachment, XmATTACH_WIDGET,
XmNrightWidget, frame,
XmNrightOffset, 4,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, input_form,
XmNtopOffset, 4,
XmNbottomAttachment, XmATTACH_FORM,
XmNbottomOffset, 4,
NULL);

    str = XmStringCreateSimple(_("Match whole word only"));
    frdp->wword = XtVaCreateManagedWidget("wordToggle",
xmToggleButtonGadgetClass, toggle_form,
XmNlabelString, str,
XmNtopAttachment, XmATTACH_FORM,
XmNtopOffset, 4,
XmNleftAttachment, XmATTACH_FORM,
XmNleftOffset, 4,
XmNset, wword,
NULL);
    XmStringFree(str);

    str = XmStringCreateSimple(_("Match case"));
    frdp->mcase = XtVaCreateManagedWidget("caseToggle",
xmToggleButtonGadgetClass, toggle_form,
XmNlabelString, str,
XmNleftAttachment, XmATTACH_FORM,
XmNleftOffset, 4,
XmNtopAttachment, XmATTACH_WIDGET,
XmNtopWidget, frdp->wword,
XmNtopOffset, 4,
XmNset, mcase,
NULL);
    XmStringFree(str);
    gui_motif_menu_fontlist(frdp->wword);
    gui_motif_menu_fontlist(frdp->mcase);

    XtManageChild(toggle_form);

    if (entry_text != NULL)
XmTextFieldSetString(frdp->what, (char *)entry_text);
    vim_free(entry_text);

    gui_motif_synch_fonts();

    manage_centered(frdp->dialog);
    activate_dialog_mnemonics(frdp->dialog);
    XmProcessTraversal(frdp->what, XmTRAVERSE_CURRENT);
}

   void
gui_mch_find_dialog(eap)
    exarg_T *eap;
{
    if (!gui.in_use)
return;

    find_replace_dialog_create(eap->arg, FALSE);
}


    void
gui_mch_replace_dialog(eap)
    exarg_T *eap;
{
    if (!gui.in_use)
return;

    find_replace_dialog_create(eap->arg, TRUE);
}

/*
* Synchronize all gui elements, which are dependant upon the
* main text font used. Those are in esp. the find/replace dialogs.
* If you don't understand why this should be needed, please try to
* search for "piê¶æ" in iso8859-2.
*/
    void
gui_motif_synch_fonts(void)
{
    SharedFindReplace *frdp;
    int do_replace;
    XFontStruct *font;
    XmFontList font_list;

    /* FIXME: Unless we find out how to create a XmFontList from a XFontSet,
* we just give up here on font synchronization. */
    font = (XFontStruct *)gui.norm_font;
    if (font == NULL)
return;

    font_list = gui_motif_create_fontlist(font);

    /* OK this loop is a bit tricky... */
    for (do_replace = 0; do_replace <= 1; ++do_replace)
    {
frdp = (do_replace) ? (&repl_widgets) : (&find_widgets);
if (frdp->dialog)
{
XtVaSetValues(frdp->what, XmNfontList, font_list, NULL);
if (do_replace)
XtVaSetValues(frdp->with, XmNfontList, font_list, NULL);
}
    }

    XmFontListFree(font_list);
}
Something went wrong with that request. Please try again.