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
|
#include "wingui.h"
/* C RunTime Header Files */
#ifndef DEBUG_GUI
#include <kpathsea/c-minmax.h>
#endif
LRESULT DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM);
/* Functions defined in winevt.c */
#include <stdio.h>
#include <setjmp.h>
#include "xdvi-config.h"
/*
System type
*/
int iSystemType = -1;
int GetSystemType(void);
/****************************************************************************
Global Variables
***************************************************************************/
HINSTANCE hInst; /* Current instance */
char szAppName[100]; /* Name of the app */
char szTitle[100]; /* The title bar text */
HWND hWndMain; /* Application main window handle */
HWND hWndDraw; /* The window with the dvi page */
HWND hViewLog = NULL; /* Logging window */
HDC maneDC; /* DC for the screen window */
HBITMAP maneDIB; /* In memory bitmap for the dvi page */
HBITMAP magDIB; /* In memory bitmap for the magnifying glass */
HMENU hMenuMain; /* Main menu */
char *szLogFileName; /* Temporary log file for kpathsea */
HANDLE hCrtIn, hCrtOut, hCrtErr; /* Standard handles */
/* hCrtOut and hCrtErr are the same handle, duplicated
from the writable part of a pipe.
*/
HANDLE hLogIn; /* One side of the pipe for logging */
/*
Logging needs 2 threads :
- one sentinel for reading on the other (readable) end of the pipe
- one loop message for the hViewLog window.
With these threads, anybody writing on stdout/stderr will
make hViewLog pop up, and the writings will be displayed
almost synchronously.
*/
HANDLE hViewLogThread = 0,
hLogLoopThread = 0;
BOOL bLogShown; /* Log window is shown */
int tbHeight, sbHeight; /* Toolbar and Status bar heights */
int maneHeight, maneWidth; /* hWndDraw height and width */
RECT maneRect; /* hWndDraw Rect */
RECT rectWndPrev; /* Previous instance window rectangle */
BOOL bPrevInstance = FALSE; /* Is there a previous instance ? */
BOOL bSkipFirstClick = FALSE; /* Avoid mag. glass at click to gain focus. */
/* Scrollbars' variables */
SCROLLINFO si;
int xMinScroll;
int xMaxScroll;
int xCurrentScroll;
int yMinScroll;
int yMaxScroll;
int yCurrentScroll;
BOOL fScroll;
BOOL fSize;
BOOL bInitComplete = FALSE; /* Initialization phase completed */
/* Mouse Position */
int xMousePos;
int yMousePos;
/*
Last used files.
This is a queue. It is addressed in thae arry, indexes modulo number of
entries. Two values tell the head and tail of the queue.
*/
char **lpLastUsedFiles;
int iLastUsedFilesNum;
int iLastCurrentUsed, iLastLatestUsed;
/*****************************************************************************
Main window message table definition.
****************************************************************************/
MSD rgmsd[] =
{
{WM_CREATE, MsgCreate },
{WM_SIZE, MsgSize },
{WM_MOVE, MsgMove },
{WM_DROPFILES, MsgDropFiles },
{WM_COMMAND, MsgCommand },
{WM_NOTIFY, MsgNotify },
{WM_MENUSELECT, MsgMenuSelect},
{WM_DESTROY, MsgDestroy },
{WM_CHAR, MsgChar },
{WM_KEYDOWN, MsgKeyDown },
{WM_ACTIVATE, MsgActivate },
{WM_COPYDATA, MsgCopyData }
/* {WM_PAINT, MsgPaint } */
};
MSDI msdiMain =
{
sizeof(rgmsd) / sizeof(MSD),
rgmsd,
edwpWindow
};
/* Main window command table definition. */
CMD rgcmd[] =
{
{IDM_FILEOPEN, CmdOpen},
{IDM_FILECLOSE, CmdClose},
{IDM_FILEPRINT, CmdFilePrint},
{IDM_FILEPRINTDVIPS, CmdFilePrint},
{IDM_FILEPAGESU, CmdStub},
{IDM_FILEPRINTSU, CmdFilePrSetup},
{IDM_EXIT, CmdExit},
{IDM_FILE_RECENT, CmdOpenRecentFile},
{IDM_FILE_RECENT1, CmdOpenRecentFile},
{IDM_FILE_RECENT2, CmdOpenRecentFile},
{IDM_FILE_RECENT3, CmdOpenRecentFile},
{IDM_FILE_RECENT4, CmdOpenRecentFile},
{IDM_FILE_RECENT5, CmdOpenRecentFile},
{IDM_FILE_RECENT6, CmdOpenRecentFile},
{IDM_FILE_RECENT7, CmdOpenRecentFile},
{IDM_FILE_RECENT8, CmdOpenRecentFile},
{IDM_FILE_RECENT9, CmdOpenRecentFile},
{IDM_ZOOMIN, CmdZoomIn},
{IDM_ZOOMOUT, CmdZoomOut},
{IDM_REDRAWPAGE, CmdRedrawPage},
{IDM_KEEPPOS, CmdKeepPosition},
{IDM_TOGGLEPS, CmdTogglePS},
{IDM_TOGGLEGRID, CmdToggleGrid},
{IDM_NEXTPAGE, CmdNextPage},
{IDM_PREVIOUSPAGE,CmdPreviousPage},
{IDM_NEXT5, CmdNext5},
{IDM_PREVIOUS5, CmdPrevious5},
{IDM_NEXT10, CmdNext10},
{IDM_PREVIOUS10, CmdPrevious10},
{IDM_GOTOPAGE, CmdGotoPage},
{IDM_SRCSPECIALS, CmdSrcSpecials},
{IDM_FIRSTPAGE, CmdFirstPage},
{IDM_LASTPAGE, CmdLastPage},
#ifdef HTEX
{IDM_URLBACK, CmdUrlBack},
#endif
{ID_OPTIONS_WINDVI, CmdWindviConfig},
{ID_OPTIONS_TEXCONFIG, CmdTexConfig},
{IDM_HELPTOPICS, CmdHelpTopics},
/* {IDM_HELPCONTENTS, CmdHelpContents}, */
/* {IDM_HELPSEARCH, CmdHelpSearch}, */
/* {IDM_HELPHELP, CmdHelpHelp}, */
{IDM_VIEW_LOG, CmdViewLog},
{IDM_ABOUT, CmdAbout},
};
CMDI cmdiMain =
{
sizeof(rgcmd) / sizeof(CMD),
rgcmd,
edwpWindow
};
/*****************************************************************************
Toolbar window
****************************************************************************/
HWND hWndToolbar;
int bVertToolbar = 0;
/*
**TODO** Change the following values to match your toolbar bitmap
NUMIMAGES = Number of images in toolbar.bmp. Note that this is not
the same as the number of elements on the toolbar.
IMAGEWIDTH = Width of a single button image in toolbar.bmp
IMAGEHEIGHT = Height of a single button image in toolbar.bmp
BUTTONWIDTH = Width of a button on the toolbar (zero = default)
BUTTONHEIGHT = Height of a button on the toolbar (zero = default)
*/
#define NUMIMAGES 17
#define IMAGEWIDTH 18
#define IMAGEHEIGHT 17
#define BUTTONWIDTH 0
#define BUTTONHEIGHT 0
/*
**TODO** Add/remove entries in the following array to define the
toolbar buttons (see documentation for TBBUTTON).
*/
TBBUTTON tbButton[] =
{
{0, IDM_FILEOPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{1, IDM_FILEPRINT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0},
{2, IDM_ZOOMIN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{3, IDM_ZOOMOUT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0},
{4, IDM_PREVIOUS10, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{6, IDM_PREVIOUS5, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{8, IDM_PREVIOUSPAGE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{11, IDM_REDRAWPAGE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{9, IDM_NEXTPAGE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{7, IDM_NEXT5, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{5, IDM_NEXT10, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0},
{13,IDM_GOTOPAGE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{16,IDM_SRCSPECIALS,
#ifdef SRC_SPECIALS
TBSTATE_ENABLED,
#else
TBSTATE_HIDDEN,
#endif
TBSTYLE_BUTTON | TBSTYLE_CHECK, 0, 0},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0},
{10,IDM_TOGGLEGRID, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0},
{12,IDM_TOGGLEPS,
#ifdef PS_GS
TBSTATE_ENABLED,
#else
TBSTATE_HIDDEN,
#endif
TBSTYLE_BUTTON | TBSTYLE_CHECK, 0, 0},
{15,IDM_BOOKMODE, TBSTATE_ENABLED, TBSTYLE_BUTTON | TBSTYLE_CHECK, 0, 0},
{0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0},
{14,IDM_URLBACK,
#ifdef HTEX
TBSTATE_ENABLED,
#else
TBSTATE_HIDDEN,
#endif
TBSTYLE_BUTTON, 0, 0},
};
/****************************************************************************
Status Bar Window
****************************************************************************/
HWND hWndStatusbar;
/* **TODO** Add entries to this array for each popup menu in the same
positions as they appear in the main menu. Remember to define
the ID's in globals.h and add the strings to windvi.rc. */
UINT idPopup[] =
{
IDS_FILEMENU,
IDS_MOVEMENU,
IDS_VIEWMENU,
IDS_HELPMENU,
};
/*
6 -> 123,123
5 -> Cursor Pos:
4 -> 999
3 -> Scaling:
2 -> 999999
1 -> Page:
*/
/*****************************************************************************/
/*
FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
PURPOSE: Entry point for the application.
COMMENTS:
This function initializes the application and processes the
message loop.
*/
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
MSG msg;
HANDLE hAccelTable;
/* Initialize global strings */
lstrcpy (szAppName, SZAPPNAME);
LoadString (hInstance, IDS_APPNAME, szTitle, 100);
/* Setup standard io, real-time logging ... */
SetupEnv();
/* are we nt, w9x ? */
iSystemType = GetSystemType();
/* Get all information from command line */
ParseCmdLine(GetCommandLine());
if (!hPrevInstance) {
/* Perform instance initialization: */
if (!InitApplication(hInstance)) {
CleanUp();
return (FALSE);
}
}
/* Perform application initialization: */
if (!InitInstance(hInstance, nCmdShow)) {
CleanUp();
return (FALSE);
}
#if 0
hAccelTable = LoadAccelerators (hInstance, szAppName);
#endif
bInitComplete = TRUE;
SetForegroundWindow(hWndMain);
/* Main message loop: */
while (GetMessage(&msg, NULL, 0, 0)) {
#if 0
if (!TranslateAccelerator (msg.hwnd, hAccelTable, &msg)) {
#endif
TranslateMessage(&msg);
DispatchMessage(&msg);
#if 0
}
#endif
}
CleanUp();
#if 0
DestroyWindow(hWndMain);
#endif
return (msg.wParam);
}
/*
FUNCTION: SetupEnv()
PURPOSE: initializing stdi, stdout, stderr, redirecting output to the
view log window in real-time.
*/
void SetupEnv()
{
SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
HANDLE current_pid, hTmpOut;
DWORD idLogThread;
FILE *hf;
int fdIn, fdOut, fdErr;
int i;
extern char tick_tmp[];
/* if _DEBUG is not defined, these macros will result in nothing. */
SETUP_CRTDBG;
/* Set the debug-heap flag so that freed blocks are kept on the
linked list, to catch any inadvertent use of freed memory */
/* SET_CRT_DEBUG_FIELD( _CRTDBG_DELAY_FREE_MEM_DF );
SET_CRT_DEBUG_FIELD( _CRTDBG_CHECK_ALWAYS_DF ); */
#if 0
/* maybe we could still have an option to write log to some temp file ? */
szLogFileName = xmalloc(260);
if (GetTempFileName(szTempPath, "xdvi", 0, szLogFileName) == 0)
Win32Error("GetTempFileName");
#endif
if (GetTempPath(PATH_MAX, tick_tmp) == 0)
Win32Error("GetTempPath/tick_tmp");
hCrtIn = CreateFile("NUL", GENERIC_READ, FILE_SHARE_READ,
&sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (SetStdHandle(STD_INPUT_HANDLE, hCrtIn) == FALSE)
Win32Error("SetStdHandle/hCrtIn");
if (CreatePipe(&hLogIn, &hTmpOut, &sa, 0) == FALSE) {
Win32Error("Init/CreatePipe");
}
current_pid = GetCurrentProcess();
if (DuplicateHandle(current_pid, hTmpOut,
current_pid, &hCrtOut,
0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE)
Win32Error("DuplicateHandle/OutErr");
if (DuplicateHandle(current_pid, hTmpOut,
current_pid, &hCrtErr,
0, TRUE, DUPLICATE_SAME_ACCESS) == FALSE)
Win32Error("DuplicateHandle/OutErr");
CloseHandleAndClear(&hTmpOut);
if (SetStdHandle(STD_OUTPUT_HANDLE, hCrtOut) == FALSE)
Win32Error("SetStdHandle/hCrtOut");
if (SetStdHandle(STD_ERROR_HANDLE, hCrtErr) == FALSE)
Win32Error("SetStdHandle/hCrtErr");
fdIn = _open_osfhandle((long) hCrtIn,
// (long) GetStdHandle(STD_INPUT_HANDLE),
_O_TEXT
);
hf = _fdopen( fdIn, "r" );
*stdin = *hf;
i = setvbuf( stdin, NULL, _IONBF, 0 );
fdOut = _open_osfhandle((long) hCrtOut,
// (long) GetStdHandle(STD_OUTPUT_HANDLE),
_O_TEXT
);
hf = _fdopen( fdOut, "w" );
*stdout = *hf;
i = setvbuf( stdout, NULL, _IONBF, 0 );
fdErr = _open_osfhandle((long) hCrtErr,
// (long) GetStdHandle(STD_ERROR_HANDLE),
_O_TEXT
);
hf = _fdopen( fdErr, "w" );
*stderr = *hf;
i = setvbuf( stderr, NULL, _IONBF, 0 );
/* Run a thread for the ViewLog dialog box. The thread will
wait for something to read on hLogIn. */
if ((hViewLogThread = CreateThread(&sa, /* security attributes */
0, /* default stack size */
ViewLogSentinel, /* start address of thread */
0, /* parameter */
0, /* creation flags */
&idLogThread /* thread id */
)) == NULL)
Win32Error("Log/CreateThread");
#if 0
fprintf(stderr, "Setupenv done\n");
#endif
}
/*
FUNCTION: InitApplication(HANDLE)
PURPOSE: Initializes window data and registers window class
COMMENTS:
In this function, we initialize a window class by filling out a data
structure of type WNDCLASS and calling either RegisterClass or
the internal MyRegisterClass.
*/
BOOL InitApplication(HINSTANCE hInstance)
{
WNDCLASSEX wc;
HWND hWndPrev;
HANDLE hMutex;
#if 0
/* Win32 will always set hPrevInstance to NULL, so lets check
things a little closer. This is because we only want a single
version of this app to run at a time */
hwnd = FindWindow (szAppName, szTitle);
if (hwnd) {
/* We found another version of ourself. Lets defer to it: */
if (IsIconic(hwnd)) {
ShowWindow(hwnd, SW_RESTORE);
}
SetForegroundWindow (hwnd);
/* If this app actually had any functionality, we would
also want to communicate any action that our 'twin'
should now perform based on how the user tried to
execute us. */
return FALSE;
}
#endif
hWndPrev = FindWindow(szAppName, NULL);
if (hWndPrev) {
GetWindowRect(hWndPrev, &rectWndPrev);
bPrevInstance = TRUE;
}
/* hPrevInstance is always NULL under Win32. We have been asked to run only one instance
of windvi. Next instance will have to wake up the first one, and send it :
- at least new working directory and file name
- other params ? With the restriction that we cannot send pointers. */
if (resource.single_flag) {
COPYDATASTRUCT CopyData;
SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };
struct data_exchange DataEx;
/* We create a mutex to be sure to be alone, but only if the option
single_instance has been given. */
if ((hMutex = CreateMutex(&sa, TRUE, "WindviMutex")) == NULL) {
Win32Error("WinMain/CreateMutex");
return FALSE;
}
if (GetLastError() == ERROR_ALREADY_EXISTS) {
/* send the right message to the existing instance */
if (!hWndPrev) {
MessageBox(hWndMain, "Can't find the previous instance.", NULL, MB_APPLMODAL | MB_ICONHAND | MB_OK);
return FALSE;
}
/* We found another version of ourself. Lets defer to it: */
if (IsIconic(hWndPrev)) {
ShowWindow(hWndPrev, SW_RESTORE);
}
if (!SetForegroundWindow(hWndPrev))
Win32Error("WinMain/SetForegroundWindow");
/* We send the data_exchange structure ! */
GetCurrentDirectory(sizeof(DataEx.cwd), DataEx.cwd);
lstrcpy(DataEx.dviname, dvi_name);
if (curr_page) {
current_page = (*curr_page ? atoi(curr_page) : 1) - 1;
}
DataEx.currentpage = current_page;
DataEx.shrinkfactor = mane.shrinkfactor;
CopyData.dwData = 0;
CopyData.cbData = sizeof(DataEx);
CopyData.lpData = &DataEx;
SendMessage(hWndPrev, WM_COPYDATA, (WPARAM)NULL, (LPARAM)&CopyData);
/* and exit */
return FALSE;
}
}
/* Fill in window class structure with parameters that describe
the main window. */
/* CS_OWNDC : un DC pour chaque fentre de la classe */
wc.cbSize = sizeof(WNDCLASSEX);
wc.lpszClassName = szAppName;
wc.hInstance = hInstance;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_APPICON));
wc.lpszMenuName = szAppName;
wc.style = CS_OWNDC;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hbrBackground = (HBRUSH) (COLOR_WINDOW+1);
wc.hIconSm = LoadIcon(hInstance, MAKEINTRESOURCE(IDI_APPICON));
/* wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);*/
if (!RegisterClassEx(&wc)) {
/* Assume we are running on NT where RegisterClassEx() is
not implemented, so let's try calling RegisterClass(). */
if (!RegisterClass((LPWNDCLASS)&wc.style)) {
Win32Error("RegisterClassEx");
return FALSE;
}
}
wc.lpszClassName = "ClientDrawClass";
wc.hInstance = hInstance;
wc.lpfnWndProc = (WNDPROC)DrawProc;
wc.hCursor = NULL; /* Different cursors may be loaded */
wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_APPICON));
wc.lpszMenuName = NULL;
wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
wc.style = CS_OWNDC /* 0| CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNCLIENT */;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_APPICON));
if (!RegisterClassEx(&wc)) {
/* Assume we are running on NT where RegisterClassEx() is
not implemented, so let's try calling RegisterClass(). */
if (!RegisterClass((LPWNDCLASS)&wc.style)) {
Win32Error("RegisterClassEx");
return FALSE;
}
}
wc.lpszClassName = "MagnifyGlass";
wc.hInstance = hInstance;
wc.lpfnWndProc = (WNDPROC)MagnifyProc;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_APPICON));
wc.lpszMenuName = NULL;
wc.hbrBackground = GetStockObject(LTGRAY_BRUSH);
wc.style = CS_OWNDC /* | CS_HREDRAW | CS_VREDRAW | CS_BYTEALIGNCLIENT */;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hIcon = LoadIcon (hInstance, MAKEINTRESOURCE(IDI_APPICON));
if (!RegisterClassEx(&wc)) {
/* Assume we are running on NT where RegisterClassEx() is
not implemented, so let's try calling RegisterClass(). */
if (!RegisterClass((LPWNDCLASS)&wc.style)) {
Win32Error("RegisterClassEx");
return FALSE;
}
}
return TRUE;
}
/*
FUNCTION: InitInstance(HANDLE, int)
PURPOSE: Saves instance handle and creates main window
COMMENTS:
In this function, we save the instance handle in a global variable and
create and display the main program window.
*/
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
extern void UpdateMainMenuUsedFiles(void);
hInst = hInstance; /* Store instance handle in our global variable */
magDIB = maneDIB = NULL;
/* Setup bswap function */
bswap = (check_386() ? bswap_c : bswap_asm);
/* setup units */
pixel_to_unit();
#ifdef _TRACE
fprintf(stderr, "w = %d, h = %d\n", page_w, page_h);
#endif
hCursWait = LoadCursor(NULL, IDC_WAIT);
hCursArrow = LoadCursor(NULL, IDC_ARROW);
hCursCross = LoadCursor(NULL, IDC_CROSS);
/* BEGIN CHUNK xdvi.c 2 */
#ifdef SRC_SPECIALS
hCursSrc = LoadCursor(NULL, IDC_IBEAM);
#endif
/* END CHUNK xdvi.c 2 */
hWndMain = CreateWindowEx(WS_EX_ACCEPTFILES, szAppName, szTitle,
WS_OVERLAPPEDWINDOW /*| WS_CLIPCHILDREN */,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
NULL, NULL, hInstance, NULL);
if (!hWndMain) {
Win32Error("CreateWindow");
return (FALSE);
}
if (!CreateTBar(hWndMain))
return FALSE;
if (!CreateSBar(hWndMain))
return FALSE;
if (!CreateDraw(hWndMain))
return FALSE;
if (!CreateMagnify(hWndDraw))
return FALSE;
hMenuMain = GetMenu(hWndMain);
CheckMenuItem(hMenuMain, IDM_TOGGLEPS, (resource._postscript ? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem(hMenuMain, IDM_TOGGLEGRID, (resource._grid_mode ? MF_CHECKED : MF_UNCHECKED));
CheckMenuItem(hMenuMain, IDM_KEEPPOS, (resource.keep_flag ? MF_CHECKED : MF_UNCHECKED));
UpdateMainMenuUsedFiles();
ShowWindow(hWndMain, nCmdShow);
return (TRUE);
}
/*
FUNCTION: DispMessage(LPMSDI, HWND, UINT, WPARAM, LPARAM)
PURPOSE: Call the function associated with a message.
PARAMETERS:
lpmsdi - Structure containing the message dispatch information.
hwnd - The window handle
uMessage - The message number
wparam - Message specific data
lparam - Message specific data
RETURN VALUE:
The value returned by the message function that was called.
COMMENTS:
Runs the table of messages stored in lpmsdi->rgmsd searching
for a message number that matches uMessage. If a match is found,
call the associated function. Otherwise, call DispDefault to
call the default function, if any, associated with the message
structure. In either case, return the value recieved from the
message or default function.
*/
LRESULT DispMessage(LPMSDI lpmsdi,
HWND hwnd,
UINT uMessage,
WPARAM wparam,
LPARAM lparam)
{
int imsd = 0;
MSD *rgmsd = lpmsdi->rgmsd;
int cmsd = lpmsdi->cmsd;
for (imsd = 0; imsd < cmsd; imsd++)
{
if (rgmsd[imsd].uMessage == uMessage)
return rgmsd[imsd].pfnmsg(hwnd, uMessage, wparam, lparam);
}
return DispDefault(lpmsdi->edwp, hwnd, uMessage, wparam, lparam);
}
/*
FUNCTION: DispCommand(LPCMDI, HWND, WPARAM, LPARAM)
PURPOSE: Call the function associated with a command.
PARAMETERS:
lpcmdi - Structure containing the command dispatch information.
hwnd - The window handle
GET_WM_COMMAND_ID(wparam, lparam) - Identifier of the menu item,
control, or accelerator.
GET_WM_COMMAND_CMD(wparam, lparam) - Notification code.
GET_WM_COMMAND_HWND(wparam, lparam) - The control handle or NULL.
RETURN VALUE:
The value returned by the command function that was called.
COMMENTS:
Runs the table of commands stored in lpcmdi->rgcmd searching
for a command number that matches wCommand. If a match is found,
call the associated function. Otherwise, call DispDefault to
call the default function, if any, associated with the command
structure. In either case, return the value recieved from the
command or default function.
*/
LRESULT DispCommand(LPCMDI lpcmdi,
HWND hwnd,
WPARAM wparam,
LPARAM lparam)
{
LRESULT lRet = 0;
WORD wCommand = GET_WM_COMMAND_ID(wparam, lparam);
int icmd;
CMD *rgcmd = lpcmdi->rgcmd;
int ccmd = lpcmdi->ccmd;
/* Message packing of wparam and lparam have changed for Win32,
so use the GET_WM_COMMAND macro to unpack the commnad */
for (icmd = 0; icmd < ccmd; icmd++) {
if (rgcmd[icmd].wCommand == wCommand) {
return rgcmd[icmd].pfncmd(hwnd,
wCommand,
GET_WM_COMMAND_CMD(wparam, lparam),
GET_WM_COMMAND_HWND(wparam, lparam));
}
}
return DispDefault(lpcmdi->edwp, hwnd, WM_COMMAND, wparam, lparam);
}
/*
FUNCTION: DispDefault(EDWP, HWND, UINT, WPARAM, LPARAM)
PURPOSE: Call the appropriate default window procedure.
PARAMETERS:
edwp - Enumerate specifying the appropriate default winow procedure.
hwnd - The window handle
uMessage - The message number
wparam - Message specific data
lparam - Message specific data
RETURN VALUE:
If there is a default proc, return the value returned by the
default proc. Otherwise, return 0.
COMMENTS:
Calls the default procedure associated with edwp using the specified
parameters.
*/
LRESULT DispDefault(EDWP edwp,
HWND hwnd,
UINT uMessage,
WPARAM wparam,
LPARAM lparam)
{
switch (edwp)
{
case edwpNone:
return 0;
case edwpWindow:
return DefWindowProc(hwnd, uMessage, wparam, lparam);
case edwpDialog:
return DefDlgProc(hwnd, uMessage, wparam, lparam);
case edwpMDIFrame:
return DefFrameProc(hwnd, NULL, uMessage, wparam, lparam);
case edwpMDIChild:
return DefMDIChildProc(hwnd, uMessage, wparam, lparam);
}
return 0;
}
/*****************************************************************************
Main Window messages
****************************************************************************/
/*
FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM)
PURPOSE: Processes messages for the main window.
PARAMETERS:
hwnd - window handle
uMessage - message number
wparam - additional information (dependant on message number)
lparam - additional information (dependant on message number)
RETURN VALUE:
The return value depends on the message number. If the message
is implemented in the message dispatch table, the return value is
the value returned by the message handling function. Otherwise,
the return value is the value returned by the default window procedure.
COMMENTS:
Call the DispMessage() function with the main window's message dispatch
information (msdiMain) and the message specific information.
*/
LRESULT CALLBACK WndProc(HWND hwnd,
UINT uMessage,
WPARAM wparam,
LPARAM lparam)
{
return DispMessage(&msdiMain, hwnd, uMessage, wparam, lparam);
}
/*
FUNCTION: MsgCommand(HWND, UINT, WPARAM, LPARAM)
PURPOSE: Handle the WM_COMMAND messages for the main window.
PARAMETERS:
hwnd - window handle
uMessage - WM_COMMAND (Unused)
GET_WM_COMMAND_ID(wparam, lparam) - Command identifier
GET_WM_COMMAND_HWND(wparam, lparam) - Control handle
RETURN VALUE:
The return value depends on the message number. If the message
is implemented in the message dispatch table, the return value is
the value returned by the message handling function. Otherwise,
the return value is the value returned by the default window procedure.
COMMENTS:
Call the DispCommand() function with the main window's command dispatch
information (cmdiMain) and the command specific information.
*/
LRESULT MsgCommand(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
return DispCommand(&cmdiMain, hwnd, wparam, lparam);
}
/*
FUNCTION: MsgCreate(HWND, UINT, WPARAM, LPARAM)
PURPOSE: Handle the WM_CREATE messages for the main window.
and call InitCommonControls() API to initialize the
common control library.
PARAMETERS:
hwnd - window handle
RETURN VALUE:
Return 0 if the StatusBar and ToolBar Windows could be created
successfully. Otherwise, returns -1 to abort the main window
creation.
COMMENTS:
Call the CreateTSBars function with the main window's window handle
information (msdiMain).
*/
LRESULT MsgCreate(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
int nRet = -1;
FARPROC icce;
top_level = hwnd;
if (!(icce = GetProcAddress(GetModuleHandle("comctl32.dll"),
"InitCommonControlsEx"))) {
#if 0
fprintf(stderr, "Not running the latest comctl32.dll\n");
#endif
bVertToolbar = 0;
InitCommonControls() ; /* Initialize the common control library. */
}
else {
INITCOMMONCONTROLSEX icc = { sizeof(INITCOMMONCONTROLSEX),
ICC_BAR_CLASSES };
if ((*icce)(&icc) == FALSE)
Win32Error("InitCommonControlsEx");;
bVertToolbar = 1;
}
DragAcceptFiles(hwnd, TRUE);
return 0;
}
void UpdateGeometry()
{
RECT r;
char buf[256];
/* Avoid updating when in iconic form */
if (IsIconic(hWndMain)) return;
/* Update the geometry string */
GetWindowRect(hWndMain, &r);
sprintf(buf, "%ux%u%+d%+d",
r.right - r.left,
r.bottom - r.top,
/* be safe, do not allow huge numbers */
(r.left < 0 ? 0 : r.left) % maneHorzRes,
(r.top < 0 ? 0 : r.top) % maneVertRes
);
if (geometry) free(geometry);
geometry = strdup(buf);
}
/*
FUNCTION: MsgSize(HWND, UINT, WPARAM, LPARAM)
PURPOSE: This function resizes the toolbar and statusbar controls.
PARAMETERS:
hwnd - Window handle (Used)
uMessage - Message number (Used)
wparam - Extra data (Used)
lparam - Extra data (Used)
RETURN VALUE:
Always returns 0 - Message handled
COMMENTS:
When the window procdure that has the status and tool bar controls
receive the WM_SIZE message, it has to pass the message on to these
controls so that these controls can adjust their size accordingly.
*/
LRESULT MsgSize(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
fSize = TRUE;
SendMessage(hWndStatusbar, uMessage, wparam, lparam);
SendMessage(hWndToolbar, uMessage, wparam, lparam);
/* Re-position the panes in the status bar */
InitializeStatusBar(hwnd);
/* Re-size client window relative to the tool/status bars */
if (wparam != SIZE_MINIMIZED)
SizeClientWindow(hwnd);
UpdateGeometry();
return 0;
}
/*
We need to update geometry in case of moving.
*/
LRESULT MsgMove(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
UpdateGeometry();
return 0;
}
void SetScrollBars(HWND hwnd)
{
RECT r;
GetClientRect(hwnd, &r);
/* Scrollbars */
xMinScroll = 0;
xMaxScroll = max((unsigned)page_w, r.right) - 1;
/* mane.base_x = */xCurrentScroll = min(xCurrentScroll, xMaxScroll - max(r.right-1, 0));
si.cbSize = sizeof(si);
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
si.nMin = xMinScroll;
si.nMax = xMaxScroll;
si.nPage = r.right;
si.nPos = xCurrentScroll;
SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
yMinScroll = 0;
yMaxScroll = max((unsigned)page_h, r.bottom) - 1;
/* mane.base_y = */yCurrentScroll = min(yCurrentScroll, yMaxScroll - max(r.bottom-1, 0));
si.cbSize = sizeof(si);
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
si.nMin = yMinScroll;
si.nMax = yMaxScroll;
si.nPage = r.bottom;
si.nPos = yCurrentScroll;
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
#ifdef _TRACE
fprintf(stderr, "Page %d x %d\nScrollbars to [%d, %d, %d] and [%d, %d, %d]\n",
r.right, r.bottom,
xMinScroll, xCurrentScroll, xMaxScroll,
yMinScroll, yCurrentScroll, yMaxScroll);
#endif
}
void SizeClientWindow(HWND hwnd)
{
int xNewSize, yNewSize;
POINT ptOldOrg;
int xorg, yorg;
RECT r;
int parentWidth, parentHeight;
/* Re-position the child window */
GetClientRect(hwnd, &r);
parentHeight = r.bottom;
parentWidth = r.right;
GetClientRect(hWndToolbar, &r);
tbHeight = r.bottom;
GetClientRect(hWndStatusbar, &r);
sbHeight = r.bottom;
maneRect.left = 0;
maneRect.right = parentWidth;
maneRect.top = 0;
maneRect.bottom = parentHeight - sbHeight -tbHeight - 1;
xNewSize = parentWidth;
yNewSize = parentHeight - sbHeight -tbHeight;
/* FIXME: try to SetWindowPos() instead */
SetWindowPos(hWndDraw, HWND_TOPMOST, 0, tbHeight+1,
xNewSize, yNewSize,
SWP_NOACTIVATE | SWP_DEFERERASE | SWP_SHOWWINDOW
| SWP_NOOWNERZORDER | SWP_NOZORDER);
GetClientRect(hWndDraw, &r);
maneWidth = r.right;
maneHeight = r.bottom;
SetScrollBars(hWndDraw);
#if 1
/* GdiFlush(); */
/* UpdateWindow(hWndDraw); */
/* FIXME : adjust the position of the page */
if (maneDrawDC && hWndDraw && bInitComplete) {
GetWindowOrgEx(maneDrawDC, &ptOldOrg);
if (mane.win == hWndDraw && GetClientRect(hWndDraw, &maneRect)) {
int xorg = (int)(page_w - maneRect.right)/2;
int yorg = (int)(page_h - maneRect.bottom)/2;
xorg = min(0, xorg);
yorg = min(0, yorg);
#if 0
fprintf(stderr, "Old org (%ld, %ld) New org (%ld, %ld) page %d %d rect %d %d\n",
ptOldOrg.x, ptOldOrg.y,
xorg, yorg, page_w, page_h, maneRect.right, maneRect.bottom);
#endif
ScrollWindowEx(hWndDraw,
- xorg + ptOldOrg.x, - yorg + ptOldOrg.y,
NULL, NULL, (HRGN)NULL, (LPRECT)NULL,
SW_INVALIDATE | SW_ERASE);
/* fprintf(stderr, "scrolled window by %d, %d\n", */
/* - xorg + ptOldOrg.x, - yorg + ptOldOrg.y); */
/* GdiFlush(); */
/* UpdateWindow(hWndDraw); */
if (SetWindowOrgEx(maneDrawDC, xorg, yorg, NULL) == 0) {
Win32Error("MsgDrawPaint/SetWindowOrgEx(x,y)");
}
/* fprintf(stderr, "Set new org @ (%ld, %ld)\n", xorg, yorg); */
/* GdiFlush(); */
/* UpdateWindow(hWndDraw); */
}
else {
Win32Error("MsgDrawPaint/GetClientRect(hwnd)");
}
}
#endif
}
/*
FUNCTION: MsgDestroy(HWND, UINT, WPARAM, LPARAM)
PURPOSE: Calls PostQuitMessage().
PARAMETERS:
hwnd - Window handle (Unused)
uMessage - Message number (Unused)
wparam - Extra data (Unused)
lparam - Extra data (Unused)
RETURN VALUE:
Always returns 0 - Message handled
COMMENTS:
*/
LRESULT MsgDestroy(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
DragAcceptFiles(hwnd, FALSE);
SaveOptions();
PostQuitMessage(0);
return 0;
}
/*
FUNCTION: CmdExit(HWND, WORD, WORD, HWND)
PURPOSE: Exit the application.
PARAMETERS:
hwnd - The window.
wCommand - IDM_EXIT (unused)
wNotify - Notification number (unused)
hwndCtrl - NULL (unused)
RETURN VALUE:
Always returns 0 - command handled.
COMMENTS:
*/
LRESULT CmdExit(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
DragAcceptFiles(hwnd, FALSE);
SaveOptions();
PostQuitMessage(0);
return 0;
}
/*
Status Bar functions
*/
LRESULT MsgDropFiles(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
WORD cFiles;
char lpszFile[MAX_PATH];
cFiles = DragQueryFile((HANDLE) wparam, 0xFFFFFFFF, (LPSTR) NULL, 0);
if (cFiles != 1) {
MessageBox(hWndMain, "Only one dvi file open.", NULL, MB_APPLMODAL | MB_ICONHAND | MB_OK);
}
DragQueryFile((HANDLE) wparam, 0, lpszFile, sizeof(lpszFile));
dvi_name = xstrdup(lpszFile);
DragFinish((HANDLE) wparam);
open_dvi_file();
if (reconfig() == FALSE) {
char buf[40];
mane.shrinkfactor +=3;
wsprintf(buf, "New shrink factor : %d\n", mane.shrinkfactor);
UpdateStatusBar(buf, 0, 0);
if (reconfig() == FALSE) {
MessageBox(hWndMain, "Can't allocate page bitmap !\r\nPlease report this error.", NULL, MB_APPLMODAL | MB_ICONERROR | MB_OK);
CleanExit(1);
}
}
redraw_page();
SetForegroundWindow(hwnd);
return 0;
}
#if 0
/*
FUNCTION: MsgTimer(HWND, UINT, WPARAM, LPARAM)
PURPOSE: Calls GetLocalTime() to set the time on the status bar
PARAMETERS:
hwnd - Window handle (Unused)
uMessage - Message number (Unused)
wparam - Extra data (Unused)
lparam - Extra data (Unused)
RETURN VALUE:
Always returns 0 - Message handled
COMMENTS:
Every time the window procedure receives a Timer message, it calls
GetLocalTime() to obtain the time and then formats the time into
a string. The time sting is then displayed on the status bar.
*/
LRESULT MsgTimer(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
char szBuf[16]; /* Temp buffer. */
SYSTEMTIME sysTime;
GetLocalTime(&sysTime);
wsprintf(szBuf,
"%2d:%02d:%02d %s",
(sysTime.wHour == 0 ? 12 :
(sysTime.wHour <= 12 ? sysTime.wHour : sysTime.wHour -12)),
sysTime.wMinute,
sysTime.wSecond,
(sysTime.wHour < 12 ? "AM":"PM"));
UpdateStatusBar(szBuf, 8, 0);
return 0;
}
/*
FUNCTION: MsgMousemove(HWND, UINT, WPARAM, LPARAM)
PURPOSE: Obtains the Cursor position to display coordinates on
the status bar.
PARAMETERS:
hwnd - Window handle (Unused)
uMessage - Message number (Unused)
wparam - Extra data (Unused)
lparam - Extra data (Used)
RETURN VALUE:
Always returns 0 - Message handled
COMMENTS:
The mouse coordinates (x and y) are in the HI And LO words
of LPARAM
*/
LRESULT MsgMousemove(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
char szBuf[20]; /* Array for formatting mouse coordinates */
wsprintf(szBuf, "%d,%d", LOWORD(lparam), HIWORD(lparam));
UpdateStatusBar(szBuf, 6, 0);
return 0;
}
#endif
/*
FUNCTION: MsgMenuSelect(HWND, UINT, WPARAM, LPARAM)
PURPOSE: Upadates menu selections on the status bar.
PARAMETERS:
hwnd - Window handle (Used)
uMessage - Message number (Used)
wparam - Extra data (Used)
lparam - Extra data (Used)
RETURN VALUE:
Always returns 0 - Message handled
COMMENTS:
This message is sent when the user selects menu items by
by pulling down a popup menu move the mouse around to highlite
different menu items.
*/
LRESULT MsgMenuSelect(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
static char szBuffer[128];
UINT nStringID = 0;
UINT fuFlags = GET_WM_MENUSELECT_FLAGS(wparam, lparam) & 0xffff;
UINT uCmd = GET_WM_MENUSELECT_CMD(wparam, lparam);
HMENU hMenu = GET_WM_MENUSELECT_HMENU(wparam, lparam);
szBuffer[0] = 0; /* First reset the buffer */
if (fuFlags == 0xffff && hMenu == NULL) /* Menu has been closed */
nStringID = IDS_DESCRIPTION;
else if (fuFlags & MFT_SEPARATOR) /* Ignore separators */
nStringID = 0;
else if (fuFlags & MF_POPUP) /* Popup menu */
{
if (fuFlags & MF_SYSMENU) /* System menu */
nStringID = IDS_SYSMENU;
else
/* Get string ID for popup menu from idPopup array. */
nStringID = ((uCmd < sizeof(idPopup)/sizeof(idPopup[0])) ?
idPopup[uCmd] : 0);
} /* for MF_POPUP */
else /* Must be a command item */
nStringID = uCmd; /* String ID == Command ID */
/* Load the string if we have an ID */
if (0 != nStringID)
LoadString(hInst, nStringID, szBuffer, sizeof(szBuffer));
/* Finally... send the string to the status bar */
UpdateStatusBar(szBuffer, 0, 0);
return 0;
}
/*
FUNCTION: InitializeStatusBar(HWND)
PURPOSE: Initialize statusbar control with time and mouse positions.
PARAMETERS:
hwndParent - Window handle of the status bar's parent
RETURN VALUE: NONE
COMMENTS:
This function initializes the time and mouse positions sections of
the statubar window. The Date for the time section is obtained by
calling SetTimer API. When the timer messages start comming in,
GetSytemTime() to fill the time section.
The WPARAM of SB_SETTEXT is divided into 2 parameters. The LOWORD
determines which section/part the text goes into, and the HIWORD
tells how the bar is drawn (popin or popout).
*/
void InitializeStatusBar(HWND hwndParent)
{
const cSpaceInBetween = 8;
char szBuf[20];
int ptArray[7]; /* Array defining the number of parts/sections */
SIZE size; /* the Status bar will display. */
RECT rect;
HDC hDC;
/*
* Fill in the ptArray...
*/
hDC = GetDC(hwndParent);
GetClientRect(hwndParent, &rect);
ptArray[6] = rect.right;
if (GetTextExtentPoint(hDC, "999999.999xx x 999999.999xx", 27, &size))
ptArray[5] = ptArray[6] - (size.cx) - cSpaceInBetween;
else
ptArray[5] = 0;
if (GetTextExtentPoint(hDC, "Cursor Pos:", 12, &size))
ptArray[4] = ptArray[5] - (size.cx) - cSpaceInBetween;
else
ptArray[4] = 0;
if (GetTextExtentPoint(hDC, "999", 2, &size))
ptArray[3] = ptArray[4] - (size.cx) - cSpaceInBetween;
else
ptArray[3] = 0;
if (GetTextExtentPoint(hDC, "Scaling:", 9, &size))
ptArray[2] = ptArray[3] - (size.cx) - cSpaceInBetween;
else
ptArray[2] = 0;
if (GetTextExtentPoint(hDC, "99999 of 99999", 14, &size))
ptArray[1] = ptArray[2] - (size.cx) - cSpaceInBetween;
else
ptArray[1] = 0;
if (GetTextExtentPoint(hDC, "Page:", 6, &size))
ptArray[0] = ptArray[1] - (size.cx) - cSpaceInBetween;
else
ptArray[0] = 0;
ReleaseDC(hwndParent, hDC);
SendMessage(hWndStatusbar,
SB_SETPARTS,
sizeof(ptArray)/sizeof(ptArray[0]),
(LPARAM)(LPINT)ptArray);
UpdateStatusBar(SZDESCRIPTION, 0, 0);
UpdateStatusBar("Page:", 1, SBT_POPOUT);
wsprintf(szBuf, "%5d of %5d", current_page+1, total_pages);
UpdateStatusBar(szBuf, 2, 0);
UpdateStatusBar("Page:", 1, SBT_POPOUT);
UpdateStatusBar("Scaling:", 3, SBT_POPOUT);
wsprintf(szBuf, "%2d", mane.shrinkfactor);
UpdateStatusBar(szBuf, 4, 0);
UpdateStatusBar("Cursor Pos:", 5, SBT_POPOUT);
}
/*
FUNCTION: CreateSBar(HWND, UINT, WPARAM, LPARAM)
PURPOSE: Calls CreateStatusWindow() to create the status bar
PARAMETERS:
hwndParent - Window handle of the status bar's parent
RETURN VALUE:
If both controls were created successfully Return TRUE,
else returns FALSE.
COMMENTS:
*/
BOOL CreateSBar(HWND hwndParent)
{
hWndStatusbar = CreateStatusWindow(WS_CHILD | WS_VISIBLE | WS_BORDER,
SZDESCRIPTION,
hwndParent,
IDM_STATUSBAR);
if(hWndStatusbar)
{
InitializeStatusBar(hwndParent);
return TRUE;
}
return FALSE;
}
/*
FUNCTION: UpdateStatusBar(HWND)
PURPOSE: Updates the statusbar control with appropriate text
PARAMETERS:
lpszStatusString - text to be displayed
partNumber - which part of the status bar to display text in
displayFlags - display flags
RETURN VALUE: NONE
COMMENTS:
None
*/
void UpdateStatusBar(LPSTR lpszStatusString, WORD partNumber, WORD displayFlags)
{
SendMessage(hWndStatusbar,
SB_SETTEXT,
partNumber | displayFlags,
(LPARAM)lpszStatusString);
}
/*
FUNCTION: CreateTBar(HWND)
PURPOSE: Calls CreateToolBarEx()
PARAMETERS:
hwnd - Window handle : Used for the hWndParent parameter of the control.
RETURN VALUE:
If toolbar control was created successfully Return TRUE,
else returns FALSE.
COMMENTS:
*/
BOOL CreateTBar(HWND hwnd)
{
DWORD style = WS_CHILD | WS_VISIBLE | TBSTYLE_TOOLTIPS;
hWndToolbar = CreateToolbarEx(hwnd,
style,
IDR_TOOLBAR1,
NUMIMAGES,
hInst,
IDR_TOOLBAR1,
tbButton,
sizeof(tbButton)/sizeof(TBBUTTON),
BUTTONWIDTH,
BUTTONHEIGHT,
IMAGEWIDTH,
IMAGEHEIGHT,
sizeof(TBBUTTON));
if (hWndToolbar != NULL) {
ShowWindow(hWndToolbar, SW_SHOW);
return TRUE;
}
return FALSE;
}
/*
FUNCTION: MsgNotify(HWND, UINT, WPARAM, LPARAM)
PURPOSE: WM_NOTIFY is sent to the parent window to get the
tooltip text assoc'd with that toolbar button.
PARAMETERS:
hwnd - Window handle (Unused)
uMessage - Message number (Unused)
wparam - Extra data (Unused)
lparam - TOOLTIPTEXT FAR*
RETURN VALUE:
Always returns 0 - Message handled
COMMENTS:
This message fills in the lpszText field of the TOOLTIPTEXT
structure if code == TTN_NEEDTEXT
*/
LRESULT MsgNotify(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
LPTOOLTIPTEXT lpToolTipText;
static char szBuffer[64];
lpToolTipText = (LPTOOLTIPTEXT)lparam;
if (lpToolTipText->hdr.code == TTN_NEEDTEXT)
{
LoadString(hInst,
lpToolTipText->hdr.idFrom, /* string ID == command ID */
szBuffer,
sizeof(szBuffer));
lpToolTipText->lpszText = szBuffer;
}
return 0;
}
/*
Miscellaneous functions
*/
/*
FUNCTION: CenterWindow(HWND, HWND)
PURPOSE: Center one window over another.
PARAMETERS:
hwndChild - The handle of the window to be centered.
hwndParent- The handle of the window to center on.
RETURN VALUE:
TRUE - Success
FALSE - Failure
COMMENTS:
Dialog boxes take on the screen position that they were designed
at, which is not always appropriate. Centering the dialog over a
particular window usually results in a better position.
*/
BOOL CenterWindow(HWND hwndChild, HWND hwndParent)
{
RECT rcChild, rcParent;
int cxChild, cyChild, cxParent, cyParent;
int cxScreen, cyScreen, xNew, yNew;
HDC hdc;
/* Get the Height and Width of the child window */
GetWindowRect(hwndChild, &rcChild);
cxChild = rcChild.right - rcChild.left;
cyChild = rcChild.bottom - rcChild.top;
/* Get the Height and Width of the parent window */
GetWindowRect(hwndParent, &rcParent);
cxParent = rcParent.right - rcParent.left;
cyParent = rcParent.bottom - rcParent.top;
/* Get the display limits */
hdc = GetDC(hwndChild);
cxScreen = GetDeviceCaps(hdc, HORZRES);
cyScreen = GetDeviceCaps(hdc, VERTRES);
ReleaseDC(hwndChild, hdc);
/* Calculate new X position, then adjust for screen */
xNew = rcParent.left + ((cxParent - cxChild) / 2);
if (xNew < 0)
{
xNew = 0;
}
else if ((xNew + cxChild) > cxScreen)
{
xNew = cxScreen - cxChild;
}
/* Calculate new Y position, then adjust for screen */
yNew = rcParent.top + ((cyParent - cyChild) / 2);
if (yNew < 0)
{
yNew = 0;
}
else if ((yNew + cyChild) > cyScreen)
{
yNew = cyScreen - cyChild;
}
/* Set it, and return */
return SetWindowPos(hwndChild,
NULL,
xNew, yNew,
0, 0,
SWP_NOSIZE | SWP_NOZORDER);
}
/*
FUNCTION: CmdStub(HWND, WORD, WORD, HWND)
PURPOSE: Display statusbar updates by calling UpdateStatusBar
PARAMETERS:
hwnd - The window.
wCommand - Menu command ID
wNotify - Notification number (unused)
hwndCtrl - NULL (unused)
RETURN VALUE:
Always returns 0 - command handled.
COMMENTS:
Assumes there is a resource string describing this command with the
same ID as the command ID. Loads the string and calls UpdateStatusBar
to put the string into main pane of the status bar.
*/
LRESULT CmdStub(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
char szBuffer[50];
int cbWritten = 0;
cbWritten = LoadString(hInst, wCommand, szBuffer, sizeof(szBuffer));
if(cbWritten == 0)
{
lstrcpy(szBuffer, "Unknown Command");
UpdateStatusBar(szBuffer, 0, 0);
}
else
{
UpdateStatusBar(szBuffer, 0, 0);
MessageBox (hwnd,
"Command Not Yet Implemented.\r\n",
"Windvi",
MB_OK | MB_ICONEXCLAMATION);
}
/*
* Once the command is executed, set the statusbar text to
* original text.
*/
UpdateStatusBar(SZDESCRIPTION, 0, 0);
return 0;
}
/*
Utility functions
*/
#if 0
/****************************************************************************
* *
* FUNCTION : PaletteSize(VOID FAR * pv) *
* *
* PURPOSE : Calculates the palette size in bytes. If the info. block *
* is of the BITMAPCOREHEADER type, the number of colors is *
* multiplied by 3 to give the palette size, otherwise the *
* number of colors is multiplied by 4. *
* *
* RETURNS : Palette size in number of bytes. *
* *
****************************************************************************/
WORD PaletteSize (VOID FAR * pv)
{
LPBITMAPINFOHEADER lpbi;
WORD NumColors;
lpbi = (LPBITMAPINFOHEADER)pv;
/* NumColors = DibNumColors(lpbi); */
NumColors = lpbi->biBitCount;
if (lpbi->biSize == sizeof(BITMAPCOREHEADER))
return (WORD)(NumColors * sizeof(RGBTRIPLE));
else
return (WORD)(NumColors * sizeof(RGBQUAD));
}
/****************************************************************************
* *
* FUNCTION : DibBlt( HDC hdc, *
* int x0, int y0, *
* int dx, int dy, *
* HANDLE hdib, *
* int x1, int y1, *
* LONG rop) *
* *
* PURPOSE : Draws a bitmap in CF_DIB format, using SetDIBits to device.*
* taking the same parameters as BitBlt(). *
* *
* RETURNS : TRUE - if function succeeds. *
* FALSE - otherwise. *
* *
****************************************************************************/
BOOL DibBlt (
HDC hdc,
INT x0,
INT y0,
INT dx,
INT dy,
HANDLE hdib,
INT x1,
INT y1,
LONG rop)
{
LPBITMAPINFOHEADER lpbi;
LPSTR pBuf;
DIBSECTION ds;
if (!hdib)
return PatBlt(hdc,x0,y0,dx,dy,rop);
/* our dibs are created with CreateDIBsection(),
so are DIBSECTION. We need to retrieve them with GetObject().
FIXME : this does not work as-is.
*/
if (GetObject(hdib, sizeof(DIBSECTION), &ds) == 0)
Win32Error("DibBlt/GetObject");
/* lpbi = (VOID FAR *)GlobalLock(hdib); */
lpbi = &(ds.dsBmih);
if (!lpbi)
return FALSE;
/* pBuf = (LPSTR)lpbi + (WORD)lpbi->biSize + PaletteSize(lpbi); */
pBuf = (LPSTR)lpbi + (WORD)lpbi->biSize +
lpbi->biBitCount * sizeof(RGBQUAD);
if (SetDIBitsToDevice (hdc, x0, y0, dx, dy,
x1,y1,
x1,
dy,
pBuf, (LPBITMAPINFO)lpbi,
DIB_RGB_COLORS ) == 0)
Win32Error("DibBlt/SetDIBitsToDevice");
/* GlobalUnlock(hdib); */
return TRUE;
}
#endif
static char full_dviname[512];
void CloseDviFile()
{
char *fp, *name;
/* Nothing to close ? */
if (!dvi_file)
return;
if (dvistate != SAVED) {
/* Just in case we have tried to change directory : retain
the full name. */
/* Get the full file name */
#if 1
/* Beware : might have added file:
FIXME: there should be a copy of original dvi_name
rather that parsing it back !
In fact, dvi_name must be made absolute first.
*/
if (memicmp(dvi_name, "file:", 5) == 0) {
if (GetFullPathName(dvi_name+5, sizeof(full_dviname), full_dviname, &fp) == 0)
Win32Error("CloseDviFile/GetFullPathName");
}
else
#endif
if (GetFullPathName(dvi_name, sizeof(full_dviname), full_dviname, &fp) == 0) {
Win32Error("CloseDviFile/GetFullPathName");
}
dvistate = SAVED;
dvipos = ftell(dvi_file);
fclose(dvi_file);
dvi_file = NULL;
#if 0
fprintf(stderr, "Dvi file %s is closed\n", dvi_name);
#endif
}
}
void ReopenDviFile()
{
if (dvistate == SAVED && dvi_file == NULL) {
dvi_file = fopen(full_dviname, OPEN_MODE);
if (dvi_file) {
/* user may have destroyed it !
FIXME: this needs testing */
fseek(dvi_file, dvipos, SEEK_SET);
}
dvistate = RESTORED;
#if 0
fprintf(stderr, "Dvi file %s is reopened\n", dvi_name);
#endif
}
}
BOOL IsOpenedDviFile()
{
return dvistate == RESTORED;
}
LRESULT MsgActivate(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
extern Boolean check_dvi_file();
int fActive = LOWORD(wparam);
if (debug & DBG_EVENT) {
fprintf(stderr, "Activate Draw: mag %s, set_home %s, init %scomplete, activated by %s\n",
(bMagDisp ? "on" : "off"),
(bSetHome ? "on" : "off"),
(bInitComplete ? "" : "in"),
(fActive == WA_CLICKACTIVE ? "click" : "other than click"));
}
if (!bInitComplete || !dvi_file)
return;
if (/* !bMagDisp && !bSetHome && */ bInitComplete) {
if (fActive == WA_ACTIVE)
bSkipFirstClick = FALSE;
else if (fActive == WA_CLICKACTIVE)
bSkipFirstClick = TRUE;
if (fActive == WA_ACTIVE || fActive == WA_CLICKACTIVE) {
/* We are being activated */
/* Reopen dvi file */
ReopenDviFile();
if (resource.scan_flag) {
if (dvi_file) check_dvi_file();
/* ChangePage(0); */
}
}
else if (fActive == WA_INACTIVE) {
/* We are being deactivated */
if (bMagDisp) {
/* Remove the mag glass !
Look at windraw.c for more precisions.
*/
foreGC = ruleGC = highGC = maneDrawDC;
fprintf(stderr, "hiding mag glass\n");
ShowWindow(hWndMagnify, SW_HIDE);
bMagDisp = FALSE;
/* FIXME : is this needed ? */
bDrawKeep = FALSE;
UpdateWindow(hWndDraw);
/* restores the old shrink factor and redisplay page */
ClipCursor(NULL);
ReleaseCapture();
}
else if (bSetHome) {
/* Restore cursor */
bSetHome = FALSE;
ClipCursor(NULL);
ReleaseCapture();
SetCursor(hCursArrow);
}
/* Save dvi file params & close it if possible */
if (dvi_file) {
CloseDviFile();
}
}
}
return 0;
}
LRESULT MsgCopyData(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
char oldDir[256];
int fa;
struct data_exchange *lpDataEx = (struct data_exchange *)(((COPYDATASTRUCT *)lparam)->lpData);
#if 0
MessageBox(hWndMain, lpDataEx->cwd, lpDataEx->dviname,
MB_APPLMODAL | MB_ICONINFORMATION);
#endif
/* Should we check for new file existence ? */
GetCurrentDirectory(sizeof(oldDir), oldDir);
SetCurrentDirectory(lpDataEx->cwd);
NormalizeDviName(sizeof(lpDataEx->dviname), lpDataEx->dviname);
if (((fa = GetFileAttributes(lpDataEx->dviname)) != 0xFFFFFFFF)
&& ((fa & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)) {
CloseCurrentFile();
mane.shrinkfactor = lpDataEx->shrinkfactor;
current_page = lpDataEx->currentpage;
wsprintf(oldDir, "page %d shrink %d", current_page, mane.shrinkfactor);
#if 0
MessageBox(hWndMain, oldDir, lpDataEx->dviname,
MB_APPLMODAL | MB_ICONINFORMATION);
#endif
OpenCurrentFile(lpDataEx->dviname);
SetForegroundWindow(hwnd);
}
else {
MessageBox(hWndMain, "Can't find file !", lpDataEx->dviname,
MB_APPLMODAL | MB_ICONERROR);
SetCurrentDirectory(oldDir);
}
return TRUE;
}
#define TRSIZE 100
/* BEGIN CHUNK events.c 1 */
#ifdef SRC_SPECIALS
#define src_jumpButton resource._src_jumpButton
#endif
/* END CHUNK events.c 1 */
LRESULT MsgChar(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
char szBuf[80];
static BOOL has_arg = FALSE;
static int number = 0;
static int sign = 1;
char ch;
BOOL arg0;
int number0;
/* BEGIN CHUNK events.c 3 */
int src_x, src_y;
/* END CHUNK events.c 3 */
ch = wparam;
#if 0
printf("char %c (%d) (%x) \n", ch, ch, ch);
#endif
if (ch >= '0' && ch <= '9') {
has_arg = TRUE;
number = number * 10 + sign * (ch - '0');
return 0;
}
else if (ch == '-') {
has_arg = TRUE;
sign = -1;
number = 0;
return 0;
}
number0 = number;
number = 0;
sign = 1;
arg0 = has_arg;
has_arg = FALSE;
#if 0
printf("arg0 %d number0 %d\n", arg0, number0);
#endif
switch (wparam) {
case 'Z':
debug = (arg0 ? number0 : -1);
break;
case 'q':
case 'Q':
case '\003': /* control-C */
case '\004': /* control-D */
#ifdef VMS
case '\032': /* control-Z */
if (MessageBox(hWndMain, "Really want to quit ?", "Exit",
MB_APPLMODAL | MB_ICONQUESTION | MB_OKCANCEL) == IDOK)
PostQuitMessage((ch == 'Q') ? 2 : 0);
break;
#endif
#if PS
ps_destroy();
#endif
case 'n':
case 'f':
case ' ':
/* case '\r': */
/* case '\n': */
/* scroll forward; i.e. go to relative page */
ChangePage(arg0 ? number0 : 1);
break;
#ifdef HTEX
case 'F': /* Follow link forward! */
{
int x, y;
if (pointerlocate(&x, &y)) {
/* screen_to_page(&mane,s_x,s_y,&page,&px,&py); */
(void) htex_handleref(current_page, x, y);
#if 0
redraw_page();
#endif
}
}
return 0; /* Should goto bad if problem arises? */
case 'B': /* Go back to previous anchor. */
htex_goback(); /* Should goto bad if problem arises? */
#if 0
redraw_page();
#endif
return 0;
#endif
case 'p':
case 'b':
/* case '\b':
case '\177': Del */
/* scroll backward */
ChangePage( - (arg0 ? number0 : 1));
break;
case '<':
ChangePage(-current_page);
break;
case 'g':
case 'j':
case '>':
/* go to absolute page (last by default) */
ChangePage((arg0 ? number0 - pageno_correct :
total_pages - 1) - current_page);
break;
case '?':
case 'h':
case 'H': /* Help */
show_help();
return 0;
case 'P': /* declare current page */
pageno_correct = arg0 * number0 - current_page;
return 0;
case 'k':
resource.keep_flag = (arg0 ? number0 : !resource.keep_flag);
CheckMenuItem(hMenuMain, IDM_KEEPPOS, (resource.keep_flag ? MF_CHECKED : MF_UNCHECKED));
wsprintf(szBuf, "Home position %skept.", (resource.keep_flag ? "" : "not "));
UpdateStatusBar(szBuf, 0, 0);
break;
case '\f':
/* redisplay current page */
ChangePage(0);
break;
case '^':
home(TRUE);
break;
case 'l':
SendMessage(hWndDraw, WM_HSCROLL, MAKELONG(SB_PAGEUP, 0), 0L);
break;
case 'r':
SendMessage(hWndDraw, WM_HSCROLL, MAKELONG(SB_PAGEDOWN, 0), 0L);
break;
case 'u':
SendMessage(hWndDraw, WM_VSCROLL, MAKELONG(SB_PAGEUP, 0), 0L);
break;
case 'd':
SendMessage(hWndDraw, WM_VSCROLL, MAKELONG(SB_PAGEDOWN, 0), 0L);
break;
case 'c':
#ifndef WIN32
scrollwindow(&mane, mane.base_x + eventp->xkey.x - clip_w/2,
mane.base_y + eventp->xkey.y - clip_h/2);
if (x_bar) paint_x_bar();
if (y_bar) paint_y_bar();
XWarpPointer(DISP, None, None, 0, 0, 0, 0,
clip_w/2 - eventp->xkey.x, clip_h/2 - eventp->xkey.y);
return;
#else
break;
#endif
case 'M':
{
POINT ptOrg = { 0, 0};
GetWindowOrgEx(maneDrawDC, &ptOrg);
home_x = min(xMousePos + xCurrentScroll + ptOrg.x, (unsigned) page_w) * mane.shrinkfactor;
home_y = min(yMousePos + yCurrentScroll + ptOrg.y, (unsigned) page_h) * mane.shrinkfactor;
if (resource.sidemargin) free(resource.sidemargin);
resource.sidemargin = pixtoa(home_x);
if (resource.topmargin) free(resource.topmargin);
resource.topmargin = pixtoa(home_y);
wsprintf(szBuf, "Setting home to %5d, %5d", home_x, home_y);
UpdateStatusBar(szBuf, 0, 0);
}
break;
/* BEGIN CHUNK events.c 4 */
#ifdef SRC_SPECIALS
case 'X':
{
POINT ptOrg = { 0, 0};
GetWindowOrgEx(maneDrawDC, &ptOrg);
src_x = min(xMousePos + ptOrg.x + xCurrentScroll, (unsigned) page_w) /* * mane.shrinkfactor */;
src_y = min(yMousePos + ptOrg.y + yCurrentScroll, (unsigned) page_h) /* * mane.shrinkfactor */;
/* just highlight next special without calling editor for it */
src_find_special(0, src_x, src_y);
}
return;
#endif
/* END CHUNK events.c 4 */
case 's':
if (!arg0) {
int temp;
number0 = ROUNDUP(unshrunk_page_w, window_w - 2);
temp = ROUNDUP(unshrunk_page_h, window_h - 2);
if (number0 < temp) number0 = temp;
}
if (number0 <= 0) goto bad;
if (number0 == mane.shrinkfactor) return 0;
ChangeZoom(number0);
break;
/* BEGIN CHUNK events.c 6 */
#ifdef SRC_SPECIALS
/*
* Control-S toggles visibility of src specials
* (mnemonic for isearch in Emacs ;-)
* Also changes the cursor to emphasize the new mode.
*/
case '\023': /* Control-S */
if (src_evalMode) {
if (src_warn_verbosity >= SRC_WARNINGS_MEDIUM) {
Fprintf(stdout, "SRC specials OFF\n");
}
/* free src_arr */
src_cleanup();
src_evalMode = False;
SetCursor(hCursArrow);
}
else {
if (src_warn_verbosity >= SRC_WARNINGS_MEDIUM) {
Fprintf(stdout, "SRC specials ON\n");
}
src_evalMode = True;
/* used to have this in addition to emphasize the mode,
* but usage seems more coherent without it: */
/* src_tickVisibility = True; */
SetCursor(hCursSrc);
}
redraw_page();
break;
case 'T':
/*
* change shape of specials, but only when they're visible;
* this makes the key usable for other purposes in ordinary mode.
* However, it seems that in ordinary mode `T' already does the same
* as Ctrl-p: print the Unit/bitord/byteord stuff; what's
* the reason for this ???
*/
if (src_evalMode) {
src_tickShape++;
if (src_tickShape > SPECIAL_SHAPE_MAX_NUM) {
src_tickShape = 0;
}
if (src_warn_verbosity >= SRC_WARNINGS_MEDIUM) {
Fprintf(stdout, "changing shape to \"%d\"\n", src_tickShape);
}
if (src_tickVisibility) {
redraw_page();
}
break;
}
#ifndef PS_GS
case 'V':
if (src_evalMode) {
/*
* toggle visibility of src specials
*/
if (src_tickVisibility) {
if (src_warn_verbosity >= SRC_WARNINGS_MEDIUM) {
Fprintf(stdout, "SRC special visibility OFF\n");
}
src_tickVisibility = False;
}
else {
if (src_warn_verbosity >= SRC_WARNINGS_MEDIUM) {
Fprintf(stdout, "SRC special visibility ON\n");
}
src_tickVisibility = True;
}
redraw_page();
return;
}
#endif /* PS_GS */
#endif /* SRC_SPECIALS */
/* END CHUNK events.c 6 */
case 'S':
if (!arg0) goto bad;
#ifdef GREY
if (use_grey) {
float newgamma = number0 != 0 ? number0 / 100.0 : 1.0;
if (newgamma == gamma) return 0;
gamma = newgamma;
init_colors();
ChangePage(0);
return 0;
}
#endif
if (number0 < 0) goto bad;
if (number0 == density) return 0;
density = number0;
reset_fonts();
if (mane.shrinkfactor == 1) return 0;
ChangePage(0);
break;
case 't':
{ /* toggle through magnifier ruler tick units */
extern void pixel_to_unit(void);
extern char * pos_format;
extern double p2u_factor;
char szBuf[80];
int k = 0;
static char *TeX_units[] = {
"bp", "cc", "cm", "dd", "in", "mm", "pc", "pt", "sp",
};
POINT ptOrg = { 0, 0};
GetWindowOrgEx(maneDrawDC, &ptOrg);
for (k = 0; k < sizeof(TeX_units)/sizeof(TeX_units[0]); ++k)
if (strcmp(resource._tick_units,TeX_units[k]) == 0)
break;
k++;
if (k >= sizeof(TeX_units)/sizeof(TeX_units[0]))
k = 0;
resource._tick_units = TeX_units[k];
pixel_to_unit();
wsprintf(szBuf, "Ruler units = %.2s\n", resource._tick_units);
UpdateStatusBar(szBuf, 0, 0);
sprintf(szBuf, pos_format,
(xMousePos + xCurrentScroll + ptOrg.x) * mane.shrinkfactor * p2u_factor,
(yMousePos + yCurrentScroll + ptOrg.y) * mane.shrinkfactor * p2u_factor);
UpdateStatusBar(szBuf, 6, 0);
}
break;
case 'G':
use_grey = (arg0 ? number0 : !use_grey);
if (use_grey) init_colors();
reset_fonts();
ChangePage(0);
break;
case 'D':
grid_mode = (arg0 ? number0 : !grid_mode );
init_page();
reconfig();
ChangePage(0);
break;
#if PS
case 'v':
if (!arg0 || resource._postscript != !number0) {
resource._postscript = !resource._postscript;
if (resource._postscript) scanned_page = scanned_page_bak;
psp.toggle();
}
ChangePage(0);
break;
#endif
#ifdef SELFILE
case '\006': /* control-f */
++dvi_time ; /* notice we want a new file in check_dvi_file */
ChangePage(0);
break ;
#endif /* SELFILE */
#if PS_GS
case 'V':
/* BEGIN CHUNK events.c 7 */
#ifdef SRC_SPECIALS
if (src_evalMode) {
/*
* toggle visibility of src specials
*/
if (src_tickVisibility) {
if (src_warn_verbosity >= SRC_WARNINGS_MEDIUM) {
Fprintf(stdout, "SRC special visibility OFF\n");
}
src_tickVisibility = False;
}
else {
if (src_warn_verbosity >= SRC_WARNINGS_MEDIUM) {
Fprintf(stdout, "SRC special visibility ON\n");
}
src_tickVisibility = True;
}
redraw_page();
return;
}
else {
#endif
/* END CHUNK events.c 7 */
if (!arg0 || resource.gs_alpha != !number0)
resource.gs_alpha = !resource.gs_alpha;
break;
/* BEGIN CHUNK events.c 8 */
#ifdef SRC_SPECIALS
}
#endif
/* END CHUNK events.c 8 */
#endif
case 'R':
/* reread DVI file */
--dvi_time; /* then it will notice a change */
ChangePage(0);
break;
default:
break;
}
goto good;
bad:
if (MessageBeep(0xFFFFFFFF) == 0)
Win32Error("HandleKey/MessageBeep");
good:
return 0;
}
LRESULT MsgKeyDown(HWND hwnd, UINT uMessage, WPARAM wparam, LPARAM lparam)
{
WORD wScrollNotify = 0xFFFF;
UINT msg = WM_VSCROLL;
int new_zoom = shrink_factor,
rel_page = 0;
#define SHIFTED 0x8000
#define KEYCOUNT 0x000F
int ctrl = (GetKeyState(VK_CONTROL) & SHIFTED);
int shift = (GetKeyState(VK_SHIFT) & SHIFTED);
int l_alt = (GetKeyState(VK_LMENU) & SHIFTED);
int r_alt = (GetKeyState(VK_RMENU) & SHIFTED);
int count = lparam & KEYCOUNT;
#if 0
fprintf(stderr, "ctrl = %x, shift = %x, wparam = %x, count = %x\n",
ctrl, shift, wparam, count);
#endif
switch (wparam) {
case VK_LEFT:
msg = WM_HSCROLL;
if (ctrl)
wScrollNotify = SB_LEFT;
else if (shift)
wScrollNotify = SB_PAGELEFT;
else
wScrollNotify = SB_LINELEFT;
break;
case VK_RIGHT:
msg = WM_HSCROLL;
if (ctrl)
wScrollNotify = SB_RIGHT;
else if (shift)
wScrollNotify = SB_PAGERIGHT;
else
wScrollNotify = SB_LINERIGHT;
break;
case VK_UP:
msg = WM_VSCROLL;
if (ctrl)
wScrollNotify = SB_TOP;
else if (shift)
wScrollNotify = SB_PAGEUP;
else
wScrollNotify = SB_LINEUP;
break;
case VK_DOWN:
msg = WM_VSCROLL;
if (ctrl)
wScrollNotify = SB_BOTTOM;
else if (shift)
wScrollNotify = SB_PAGEDOWN;
else
wScrollNotify = SB_LINEDOWN;
break;
case VK_PRIOR:
if (ctrl)
ChangePage(-current_page);
wScrollNotify = SB_PAGEUP;
break;
case VK_NEXT:
if (ctrl)
ChangePage(total_pages - 1 - current_page);
wScrollNotify = SB_PAGEDOWN;
break;
case VK_END:
/* Only vertical end */
wScrollNotify = SB_BOTTOM;
break;
case VK_HOME:
home(TRUE);
break;
case VK_ADD:
new_zoom -= count;
break;
case VK_SUBTRACT:
new_zoom += count;
break;
case VK_RETURN:
rel_page = count;
break;
case VK_BACK:
rel_page = -count;
break;
case 'L':
if (ctrl) {
ChangePage(0);
}
break;
}
#if 0
fprintf(stderr, "wScrollNotify = %x msg = %x\n", wScrollNotify, msg);
#endif
if (new_zoom != shrink_factor)
ChangeZoom(new_zoom);
if (rel_page != 0)
ChangePage(rel_page);
if (wScrollNotify != 0xFFFF) {
int i;
for (i = 0; i < count; i++)
SendMessage(hWndDraw, msg, MAKELONG(wScrollNotify, 0), 0L);
}
return 0;
}
LRESULT CmdOpen (HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
extern FILE *select_filename(int, int);
extern void open_dvi_file();
if (dvi_file = select_filename(TRUE, TRUE)) {
open_dvi_file();
if (reconfig() == FALSE) {
char buf[40];
mane.shrinkfactor +=3;
wsprintf(buf, "New shrink factor : %d\n", mane.shrinkfactor);
UpdateStatusBar(buf, 0, 0);
if (reconfig() == FALSE) {
MessageBox(hWndMain, "Can't allocate page bitmap !\r\nPlease report this error.", NULL, MB_APPLMODAL | MB_ICONERROR | MB_OK);
CleanExit(1);
}
};
#if 0
redraw_page();
#else
ChangeZoom(resource.shrinkfactor);
#endif
ChangePage(0);
SetForegroundWindow(hwnd);
}
return 0;
}
LRESULT CmdOpenRecentFile (HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
extern void UpdateMainMenuUsedFiles(void);
int nCount = wCommand - IDM_FILE_RECENT;
char *new_name, *new_cwd, *last_sep, *p;
char oldDir[260];
int fa, i;
new_name = strdup(p = lpLastUsedFiles[nCount]);
/* shift the first files down to this one */
for (i = nCount; i >= 1; i--)
lpLastUsedFiles[i] = lpLastUsedFiles[i-1];
lpLastUsedFiles[0] = p;
UpdateMainMenuUsedFiles();
if ((last_sep = strrchr(new_name, '/')) == NULL)
last_sep = strrchr(new_name, '\\');
if (!last_sep)
return 0;
*last_sep = '\0';
new_cwd = new_name;
new_name = last_sep+1;
/* Should we check for new file existence ? */
GetCurrentDirectory(sizeof(oldDir), oldDir);
SetCurrentDirectory(new_cwd);
if (((fa = GetFileAttributes(new_name)) != 0xFFFFFFFF)
&& ((fa & FILE_ATTRIBUTE_DIRECTORY) != FILE_ATTRIBUTE_DIRECTORY)) {
CloseCurrentFile();
current_page = 0;
#if 0
MessageBox(hWndMain, oldDir, lpDataEx->dviname,
MB_APPLMODAL | MB_ICONINFORMATION);
#endif
OpenCurrentFile(new_name);
if (reconfig() == FALSE) {
char buf[40];
mane.shrinkfactor +=3;
wsprintf(buf, "New shrink factor : %d\n", mane.shrinkfactor);
UpdateStatusBar(buf, 0, 0);
if (reconfig() == FALSE) {
MessageBox(hWndMain, "Can't allocate page bitmap !\r\nPlease report this error.", NULL, MB_APPLMODAL | MB_ICONERROR | MB_OK);
CleanExit(1);
}
};
#if 0
redraw_page();
#endif
ChangePage(0);
SetForegroundWindow(hwnd);
}
else {
MessageBox(hWndMain, "Can't find file !", new_name,
MB_APPLMODAL | MB_ICONERROR);
SetCurrentDirectory(oldDir);
}
free(new_cwd);
return 0;
}
LRESULT CmdClose (HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
if (dvi_file)
CloseDviFile();
if (dvi_name) {
free(dvi_name);
dvi_name = NULL;
set_icon_and_title("", NULL, NULL, 1);
}
redraw_page();
return 0;
}
/* Choose a decent shrink factor, given the page size
and the screen params */
int ChooseShrink()
{
extern HWND hWndMain, hWndDraw;
RECT rcTotal, rcDraw;
int total_width, total_height, draw_width, draw_height;
int usable_screen_width, usable_screen_height;
int xNewSize, yNewSize;
int shrink_x, shrink_y;
char szBuf[80];
/*
Principle : get the size of the non-drawing area
remove it from the size of the screen
and calculate the best shrink factor of this size
next resize the frame window
*/
GetWindowRect(hWndMain, &rcTotal);
GetWindowRect(hWndDraw, &rcDraw);
total_width = rcTotal.right - rcTotal.left;
total_height = rcTotal.bottom - rcTotal.top;
draw_width = rcDraw.right - rcDraw.left;
draw_height = rcDraw.bottom - rcDraw.top;
usable_screen_width = maneHorzRes - (total_width - draw_width);
usable_screen_height = maneVertRes - (total_height - draw_height);
shrink_x = ROUNDUP(unshrunk_page_w, draw_width);
shrink_y = ROUNDUP(unshrunk_page_h, draw_height);
if (shrink_x > shrink_y) shrink_x = shrink_y;
xNewSize = ROUNDUP(unshrunk_page_w,shrink_x)
+ (total_width - draw_width) + 1;
yNewSize = ROUNDUP(unshrunk_page_h,shrink_x)
+ (total_height - draw_height) + 1;
wsprintf(szBuf, "Shrink choosen %d (%d x %d)", shrink_x,
xNewSize, yNewSize);
UpdateStatusBar(szBuf, 0, 0);
return shrink_x;
}
void ChangeZoom(int new_shrink)
{
char szBuf[20];
if (new_shrink <= 0 || new_shrink == mane.shrinkfactor)
return;
mane.shrinkfactor = new_shrink;
init_page();
#if 0
fprintf(stderr, "new_shrink (%d) != bak_shrink (%d)\n",
new_shrink, bak_shrink);
#endif
if (new_shrink != 1 && new_shrink != bak_shrink) {
bak_shrink = new_shrink;
#ifdef GREY
/* if (use_grey) init_pix(RGB(0,0,0), RGB(255,255,255)); */
if (use_grey)
init_pix(string_to_colorref(resource.fore_color),
string_to_colorref(resource.back_color));
#endif
}
if (reconfig() == FALSE) {
char buf[40];
mane.shrinkfactor += 1;
wsprintf(buf, "Can't allocate bitmap for this shrink factor.");
UpdateStatusBar(buf, 0, 0);
init_page();
if (reconfig() == FALSE) {
MessageBox(hWndMain, "Not enough storage for page bitmap\r\n",
NULL, MB_OK | MB_APPLMODAL | MB_ICONERROR);
CleanExit(1);
}
}
reset_fonts();
/* In case the ScrollBars will disappear */
SetScrollBars(hWndDraw);
redraw_page();
resource.shrinkfactor = mane.shrinkfactor;
wsprintf(szBuf, "%2d", mane.shrinkfactor);
UpdateStatusBar(szBuf, 4, 0);
}
LRESULT CmdZoomIn(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
ChangeZoom(mane.shrinkfactor - 1);
return 0;
}
LRESULT CmdZoomOut(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
ChangeZoom(mane.shrinkfactor + 1);
return 0;
}
LRESULT CmdTogglePS(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
resource._postscript = (resource._postscript ? 0 : 1);
CheckMenuItem(hMenuMain, IDM_TOGGLEPS, (resource._postscript ? MF_CHECKED : MF_UNCHECKED));
if (resource._postscript) scanned_page = scanned_page_bak;
psp.toggle();
redraw_page();
return 0;
}
LRESULT CmdToggleGrid(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
char szBuf[80];
float sep = 0.0;
resource._grid_mode = (resource._grid_mode + 1) % 4;
if (resource._grid_mode == 3) {
sep = (float)ROUNDUP(unshrunk_paper_unit, shrink_factor) / 4.0;
sprintf(szBuf, "Grid mode %4.2f pixels", sep);
}
else if (resource._grid_mode == 2) {
sep = (float)ROUNDUP(unshrunk_paper_unit, shrink_factor) / 2.0;
sprintf(szBuf, "Grid mode %4.2f pixels", sep);
}
else if (resource._grid_mode == 1) {
sep = (float)ROUNDUP(unshrunk_paper_unit, shrink_factor);
sprintf(szBuf, "Grid mode %4.2f pixels", sep);
}
else
sprintf(szBuf, "Grid mode off");
UpdateStatusBar(szBuf, 0, 0);
CheckMenuItem(hMenuMain, IDM_TOGGLEGRID, (resource._grid_mode ? MF_CHECKED : MF_UNCHECKED));
init_page();
redraw_page();
return 0;
}
/*
Warning : ChangePage takes a relative count
*/
void ChangePage(int count)
{
extern int total_pages;
char szBuf[20];
if (count == 0) {
/* Explicit call to redraw the current page */
redraw_page();
}
else {
int next_page;
#ifdef BOOK_MODE
if (resource.book_mode) {
if (count == 1 || count == -1) {
/* in this case, should be 2 */
next_page = current_page + 2*count;
}
/* ensure that the left page is even */
current_page = (current_page % 2 ? current_page - 1 : current_page);
}
else {
next_page = current_page + count;
}
#else
next_page = current_page + count;
#endif
#if 1
next_page = min(next_page, total_pages - 1);
next_page = max(next_page, 0);
if (current_page != next_page) {
/* BEGIN CHUNK events.c 0 */
#ifdef SRC_SPECIALS
src_delete_all_specials();
#endif
/* END CHUNK events.c 0 */
current_page = next_page;
warn_spec_now = warn_spec;
redraw_page();
}
#else
if (0 <= next_page && next_page < total_pages) {
current_page = next_page;
warn_spec_now = warn_spec;
redraw_page();
}
#endif
}
#ifdef BOOK_MODE
if (resource.book_mode) {
wsprintf(szBuf, "%5d-%5d of %5d", current_page+1, current_page+2, total_pages);
}
else {
wsprintf(szBuf, "%5d of %5d", current_page+1, total_pages);
}
#else
wsprintf(szBuf, "%5d of %5d", current_page+1, total_pages);
#endif
UpdateStatusBar(szBuf, 2, 0);
}
LRESULT CmdNextPage(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
ChangePage(+1);
return 0;
}
LRESULT CmdPreviousPage(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
ChangePage(-1);
return 0;
}
LRESULT CmdNext5(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
ChangePage(+5);
return 0;
}
LRESULT CmdPrevious5(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
ChangePage(-5);
return 0;
}
LRESULT CmdNext10(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
ChangePage(+10);
return 0;
}
LRESULT CmdPrevious10(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
ChangePage(-10);
return 0;
}
LRESULT CmdFirstPage(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
ChangePage(- current_page);
return 0;
}
LRESULT CmdLastPage(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
ChangePage(total_pages - current_page - 1);
return 0;
}
LRESULT CmdRedrawPage(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
warn_spec_now = warn_spec;
redraw_page();
return 0;
}
LRESULT CmdKeepPosition(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
char szBuf[80];
resource.keep_flag = !resource.keep_flag;
CheckMenuItem(hMenuMain, IDM_KEEPPOS, (resource.keep_flag ? MF_CHECKED : MF_UNCHECKED));
wsprintf(szBuf, "Home position %s kept.", (resource.keep_flag ? "" : "not"));
UpdateStatusBar(szBuf, 0, 0);
return 0;
}
LRESULT CmdGotoPage(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
DialogBox(hInst, "DlgGotoPage", hwnd, (DLGPROC)DlgGotoPage);
return 0;
}
LRESULT CmdSrcSpecials(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
/* BEGIN CHUNK events.c 2 */
#ifdef SRC_SPECIALS
if (src_evalMode) {
if (src_warn_verbosity >= SRC_WARNINGS_MEDIUM) {
Fprintf(stdout, "SRC specials OFF\n");
}
/* free src_arr */
src_cleanup();
src_evalMode = False;
SetCursor(hCursArrow);
}
else {
if (src_warn_verbosity >= SRC_WARNINGS_MEDIUM) {
Fprintf(stdout, "SRC specials ON\n");
}
src_evalMode = True;
/* used to have this too to make the mode clearer, but usage seems more coherent without it: */
/* src_tickVisibility = True; */
SetCursor(hCursSrc);
}
redraw_page();
#endif
/* END CHUNK events.c 2 */
return 0;
}
#ifdef HTEX
LRESULT CmdUrlBack(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
htex_goback();
#if 0
redraw_page();
#endif
return 0;
}
#endif
LRESULT CmdViewLog(HWND hwnd, WORD wCommand,
WORD wNotify, HWND hwndCtrl)
{
ShowWindow(hViewLog, SW_SHOW);
bLogShown = TRUE;
return 0;
}
void CleanUp()
{
#ifdef TRANSFORM
extern HRGN hClipRgn;
#endif
#ifdef PS
#ifdef TRANSFORM
extern HANDLE hGsEvent;
#endif
#endif
extern HDC hdcDrawSave;
#if 0
__asm int 3;
#endif
_fcloseall();
#ifdef PS
if (hGsDll) {
ps_destroy();
gs_dll_release();
}
#endif
#ifdef HTEX
htex_cleanup(0);
#endif
remove_temporary_dir();
#if 0
/* resources that should be freed */
/*
Colors
*/
CRefFree(scan_fore_colors);
#endif
FreeOptions();
#if 0
MessageBox( NULL, "LogLoopThread finished", "", MB_OK|MB_ICONINFORMATION );
#endif
/* close any handle */
fprintf(stderr, "\n");
_flushall();
fclose(stdin);
fclose(stdout);
fclose(stderr);
if (dvi_file)
Fclose(dvi_file);
/* terminate thread */
if (WaitForSingleObject(hViewLogThread, 2000) == WAIT_TIMEOUT) {
/* This is really unclean. From 20/04/99, it seems that closing
stdout and stderr is not enough to make the ReadFile()
call return broken_pipe. So we have to make it the hard way. */
// MessageBox( NULL, "ViewLog thread does not want to shut down...", "", MB_OK|MB_ICONINFORMATION );
TerminateThread(hViewLogThread, 1);
CloseHandleAndClear(&hViewLogThread);
PostMessage(hViewLog, WM_QUIT, 0, 0);
if (WaitForSingleObject(hLogLoopThread, 250) == WAIT_TIMEOUT) {
TerminateThread(hLogLoopThread, 1);
}
CloseHandleAndClear(&hLogLoopThread);
}
CloseHandleAndClear(&hLogIn);
CloseHandleAndClear(&hViewLogThread);
/* Deallocate gdi resources */
if (forePen && !DeleteObject(forePen))
Win32Error("CleanUp/DeleteObject/forePen");
if (foreBrush && !DeleteObject(foreBrush))
Win32Error("CleanUp/DeleteObject/foreBrush");
if (backBrush && !DeleteObject(backBrush))
Win32Error("CleanUp/DeleteObject/backBrush");
if (backTPicPen && !DeleteObject(backTPicPen))
Win32Error("CleanUp/DeleteObject/backTPicPen");
if (foreTPicPen && !DeleteObject(foreTPicPen))
Win32Error("CleanUp/DeleteObject/foreTPicPen");
if (foreTPicBrush && !DeleteObject(foreTPicBrush))
Win32Error("CleanUp/DeleteObject/foreTPicBrush");
if (resource.in_memory) {
if (oldmaneDIB) {
/* There is an old maneDIB, put it back in the DC
and delete the current one */
if ((maneDIB = SelectObject(maneDrawDC, oldmaneDIB)) == NULL)
Win32Error("reconfig/SelectObject");
if (DeleteObject(maneDIB) == FALSE)
Win32Error("DeleteObject/maneDIB");
}
if (oldmagDIB) {
/* There is an old magDIB, put it back in the DC
and delete the current one */
if ((magDIB = SelectObject(magMemDC, oldmagDIB)) == NULL)
Win32Error("SelectObject/oldmagDIB");
if (DeleteObject(magDIB) == FALSE)
Win32Error("DeleteObject/magDIB");
}
if (maneDrawDC && !DeleteDC(maneDrawDC)) Win32Error("CleanUp/DeleteDC/maneDrawDC");
if (magMemDC && !DeleteDC(magMemDC)) Win32Error("CleanUp/DeleteDC/magMemDC");
}
if (hdcDrawSave) DeleteDC(hdcDrawSave);
#ifdef TRANSFORM
if (hClipRgn)
DeleteObject(hClipRgn);
#endif
}
void CleanExit(int code)
{
CleanUp();
ExitProcess(code);
}
/*
Be warned: the string has to be used before this function is called
a second time.
*/
LPTSTR GetStringRes (int id)
{
static TCHAR buffer[MAX_PATH];
buffer[0]=0;
LoadString (GetModuleHandle (NULL), id, buffer, MAX_PATH);
return buffer;
}
LRESULT CmdHelpTopics(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
ReadHelp (hwnd, SZAPPNAME".HTML");
return 0;
}
#if 0
LRESULT CmdHelpContents(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
BOOL bGotHelp;
/* Not called in Windows 95 */
bGotHelp = WinHelp (hwnd, SZAPPNAME".HLP", HELP_CONTENTS,(DWORD)0);
if (!bGotHelp) {
MessageBox (GetFocus(), GetStringRes(IDS_NO_HELP),
szAppName, MB_OK|MB_ICONHAND);
}
return 0;
}
LRESULT CmdHelpSearch(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
/* Not called in Windows 95 */
if (!WinHelp(hwnd, SZAPPNAME".HLP", HELP_PARTIALKEY, (DWORD)(LPSTR)"")) {
MessageBox (GetFocus(), GetStringRes(IDS_NO_HELP),
szAppName, MB_OK|MB_ICONHAND);
}
return 0;
}
LRESULT CmdHelpHelp(HWND hwnd, WORD wCommand, WORD wNotify, HWND hwndCtrl)
{
/* Not called in Windows 95 */
if(!WinHelp(hwnd, (LPSTR)NULL, HELP_HELPONHELP, 0)) {
MessageBox (GetFocus(), GetStringRes(IDS_NO_HELP),
szAppName, MB_OK|MB_ICONHAND);
}
return 0;
}
#endif
/*F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F
Function: GetErrorMsg
Summary: Accepts a Win32 error code and retrieves a human readable
system message for it. Args: HRESULT hr
SCODE error code. LPTSTR pszMsg
Pointer string where message will be placed.
UINT uiSize Max size of the msg string.
Returns: BOOL TRUE if hr was error; FALSE if not.
F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F-F*/
BOOL GetErrorMsg(HRESULT hr, LPTSTR pszMsg, UINT uiSize)
{
BOOL bErr = FAILED(hr);
DWORD dwSize;
if (bErr) {
memset(pszMsg, 0, uiSize * sizeof(TCHAR));
dwSize = FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
NULL, hr, MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
pszMsg, uiSize, NULL);
if (dwSize>2) {
/* Take out the trailing CRLF. */
pszMsg[--dwSize] = 0;
pszMsg[--dwSize] = 0;
}
}
return bErr;
}
/*F+F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F+++F
Function: HrMsg
Summary: HRESULT Error Message box. Takes standard result code,
looks it up in the system tables, and shows a message
box with the error code (in hex) and the associated
system message. Args: HWND hWndOwner,
Handle to owner parent window. LPTSTR pszTitle
User message string (eg, designating the attempted function).
Appears in dialog title bar. HRESULT hr,
Standard result code. Returns: void
F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F---F-F*/
void HrMsg(HWND hWndOwner, LPTSTR pszTitle, HRESULT hr)
{
TCHAR szMsg[MAX_PATH];
TCHAR szErrMsg[MAX_PATH];
int iResult;
wsprintf(szMsg, TEXT("Error=0x%X:\r\n"), hr);
GetErrorMsg(hr, szErrMsg, MAX_PATH);
lstrcat(szMsg, szErrMsg);
iResult = MessageBox(hWndOwner, szMsg, pszTitle, MB_OK | MB_ICONEXCLAMATION);
return;
}
/*
We can replace the WinHelp() system by html files using this.
*/
void ReadHelp(HWND hWndOwner, LPTSTR pszHelpFile)
{
#define NOBROWSE_ERROR_STR "Can't run browser."
#define NOHTM_ERROR_STR "Can't find .HTM file."
#define ERROR_TITLE_STR "-Error-"
int iRes;
LPSTR lpFullHelpFile = NULL;
if (NULL != pszHelpFile) {
/* First check if the .HTM help file is there at all. */
lpFullHelpFile = kpse_var_expand("$TEXMFMAIN/doc/html/windvi/windvi.html");
MessageBox(hWndOwner, lpFullHelpFile, "Help File",
MB_OK | MB_ICONEXCLAMATION);
if (!lpFullHelpFile || GetFileAttributes(lpFullHelpFile) == -1)
lpFullHelpFile = kpse_find_file(pszHelpFile, kpse_texdoc_format, TRUE);
if (lpFullHelpFile) {
/* Use shell to invoke web browser on the HTML help file. */
iRes = (int) ShellExecute(hWndOwner, TEXT("open"), lpFullHelpFile,
NULL, NULL, SW_SHOWNORMAL);
if (iRes <= 32) {
/* If unable to browse then put up an error box. */
Win32Error(TEXT(NOBROWSE_ERROR_STR));
}
}
else {
/* If the .HTM file doesn't exist then put up an error box. */
iRes = MessageBox(hWndOwner, TEXT(NOHTM_ERROR_STR), TEXT(ERROR_TITLE_STR),
MB_OK | MB_ICONEXCLAMATION);
}
}
return;
}
/*
Add Last Used Files to main menu
*/
#define RECENT_POSITION 8
void UpdateMainMenuUsedFiles()
{
int nCount;
TCHAR szTemp[MAX_PATH + 6];
HMENU hMenu;
MENUITEMINFO ItemInfo;
/* Validate parameters. */
if (!IsWindow(hWndMain)) {
return;
}
if ((hMenu = GetSubMenu(GetMenu(hWndMain), 0)) == NULL)
Win32Error("UpdateMainMenuUsedFiled/GetSubMenu");
for (nCount = 0; nCount < iLastUsedFilesNum; nCount++) {
/* Only add strings that are not null or zero length. */
if ((lpLastUsedFiles[nCount] != NULL) && (lstrlen(lpLastUsedFiles[nCount]) != 0)) {
/* Build recent file menu string. */
wsprintf(szTemp, __TEXT("&%d %s"), nCount +1, lpLastUsedFiles[nCount]);
/* Determine if replacing item or inserting.*/
memset(&ItemInfo, 0, sizeof(MENUITEMINFO));
ItemInfo.cbSize = sizeof(MENUITEMINFO);
ItemInfo.fMask = MIIM_TYPE;
GetMenuItemInfo(hMenu, RECENT_POSITION + nCount, TRUE, &ItemInfo);
if (MFT_SEPARATOR == ItemInfo.fType) {
/* Insert item. MIIM_ID */
ItemInfo.fMask = MIIM_TYPE | MIIM_ID;
ItemInfo.wID = IDM_FILE_RECENT + nCount;
ItemInfo.fType = MFT_STRING;
ItemInfo.dwTypeData = szTemp;
ItemInfo.cch = lstrlen(ItemInfo.dwTypeData);
InsertMenuItem(hMenu, RECENT_POSITION + nCount, TRUE, &ItemInfo);
}
else {
/* Replace menu item. */
ItemInfo.fMask = MIIM_TYPE | MIIM_STATE;
ItemInfo.fState = MFS_ENABLED;
ItemInfo.fType = MFT_STRING;
ItemInfo.dwTypeData = szTemp;
ItemInfo.cch = lstrlen(ItemInfo.dwTypeData);
SetMenuItemInfo(hMenu, RECENT_POSITION + nCount, TRUE, &ItemInfo);
}
}
}
DrawMenuBar(hWndMain);
}
int GetSystemType()
{
OSVERSIONINFOEX osvi;
BOOL bOsVersionInfoEx;
int result = -1;
/* Try calling GetVersionEx using the OSVERSIONINFOEX structure,
which is supported on Windows NT versions 5.0 and later.
If that fails, try using the OSVERSIONINFO structure,
which is supported on earlier versions of Windows and Windows NT */
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
if (! (bOsVersionInfoEx = GetVersionEx ( (OSVERSIONINFO *) &osvi) ) ) {
/* If OSVERSIONINFOEX doesn't work, try OSVERSIONINFO. */
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
if (! GetVersionEx ( (OSVERSIONINFO *) &osvi) ) {
fprintf(stderr, "GetVersion() failed \n");
MessageBox(NULL, "GetVersion() failed.", NULL, MB_APPLMODAL | MB_ICONHAND | MB_OK);
return -1;
}
}
switch (osvi.dwPlatformId) {
case VER_PLATFORM_WIN32_NT:
if (osvi.dwMajorVersion == 3)
result = WINNT3;
else if (osvi.dwMajorVersion == 4)
result = WINNT4;
else
result = WINNT5;
break;
case VER_PLATFORM_WIN32_WINDOWS:
if ((osvi.dwMajorVersion > 4) ||
((osvi.dwMajorVersion == 4) && (osvi.dwMinorVersion > 0)))
result = WIN98;
else
result = WIN95;
break;
case VER_PLATFORM_WIN32s:
result = WIN31;
break;
}
#if 0
fprintf (stderr, "version %d.%d (Build %d)\n",
osvi.dwMajorVersion,
osvi.dwMinorVersion,
osvi.dwBuildNumber & 0xFFFF);
if (bOsVersionInfoEx)
fprintf (stderr, "Service Pack %d.%d\n",
osvi.wServicePackMajor,
osvi.wServicePackMinor);
#endif
return result;
}
void CloseHandleAndClear(HANDLE *h)
{
if (h && *h != INVALID_HANDLE_VALUE) {
if (CloseHandle(*h) == FALSE) {
Win32Error("CloseHandle");
}
*h = INVALID_HANDLE_VALUE;
}
}
|