1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353
|
/*
* Unit test suite for rich edit control
*
* Copyright 2006 Google (Thomas Kho)
* Copyright 2007 Matt Finnicum
* Copyright 2007 Dmitry Timoshkov
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include <stdarg.h>
#include <stdio.h>
#include <assert.h>
#include <windef.h>
#include <winbase.h>
#include <wingdi.h>
#include <winuser.h>
#include <winnls.h>
#include <ole2.h>
#include <richedit.h>
#include <time.h>
#include <wine/test.h>
#define ID_RICHEDITTESTDBUTTON 0x123
static CHAR string1[MAX_PATH], string2[MAX_PATH], string3[MAX_PATH];
#define ok_w3(format, szString1, szString2, szString3) \
WideCharToMultiByte(CP_ACP, 0, szString1, -1, string1, MAX_PATH, NULL, NULL); \
WideCharToMultiByte(CP_ACP, 0, szString2, -1, string2, MAX_PATH, NULL, NULL); \
WideCharToMultiByte(CP_ACP, 0, szString3, -1, string3, MAX_PATH, NULL, NULL); \
ok(!lstrcmpW(szString3, szString1) || !lstrcmpW(szString3, szString2), \
format, string1, string2, string3);
static HMODULE hmoduleRichEdit;
static HWND new_window(LPCSTR lpClassName, DWORD dwStyle, HWND parent) {
HWND hwnd;
hwnd = CreateWindowA(lpClassName, NULL, dwStyle|WS_POPUP|WS_HSCROLL|WS_VSCROLL
|WS_VISIBLE, 0, 0, 200, 60, parent, NULL,
hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", lpClassName, (int) GetLastError());
return hwnd;
}
static HWND new_windowW(LPCWSTR lpClassName, DWORD dwStyle, HWND parent) {
HWND hwnd;
hwnd = CreateWindowW(lpClassName, NULL, dwStyle|WS_POPUP|WS_HSCROLL|WS_VSCROLL
|WS_VISIBLE, 0, 0, 200, 60, parent, NULL,
hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", wine_dbgstr_w(lpClassName), (int) GetLastError());
return hwnd;
}
static HWND new_richedit(HWND parent) {
return new_window(RICHEDIT_CLASS, ES_MULTILINE, parent);
}
static HWND new_richeditW(HWND parent) {
return new_windowW(RICHEDIT_CLASS20W, ES_MULTILINE, parent);
}
/* Keeps the window reponsive for the deley_time in seconds.
* This is useful for debugging a test to see what is happening. */
static void keep_responsive(time_t delay_time)
{
MSG msg;
time_t end;
/* The message pump uses PeekMessage() to empty the queue and then
* sleeps for 50ms before retrying the queue. */
end = time(NULL) + delay_time;
while (time(NULL) < end) {
if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
} else {
Sleep(50);
}
}
}
static void simulate_typing_characters(HWND hwnd, const char* szChars)
{
int ret;
while (*szChars != '\0') {
SendMessageA(hwnd, WM_KEYDOWN, *szChars, 1);
ret = SendMessageA(hwnd, WM_CHAR, *szChars, 1);
ok(ret == 0, "WM_CHAR('%c') ret=%d\n", *szChars, ret);
SendMessageA(hwnd, WM_KEYUP, *szChars, 1);
szChars++;
}
}
static BOOL hold_key(int vk)
{
BYTE key_state[256];
BOOL result;
result = GetKeyboardState(key_state);
ok(result, "GetKeyboardState failed.\n");
if (!result) return FALSE;
key_state[vk] |= 0x80;
result = SetKeyboardState(key_state);
ok(result, "SetKeyboardState failed.\n");
return result != 0;
}
static BOOL release_key(int vk)
{
BYTE key_state[256];
BOOL result;
result = GetKeyboardState(key_state);
ok(result, "GetKeyboardState failed.\n");
if (!result) return FALSE;
key_state[vk] &= ~0x80;
result = SetKeyboardState(key_state);
ok(result, "SetKeyboardState failed.\n");
return result != 0;
}
static const char haystack[] = "WINEWine wineWine wine WineWine";
/* ^0 ^10 ^20 ^30 */
struct find_s {
int start;
int end;
const char *needle;
int flags;
int expected_loc;
};
static struct find_s find_tests[] = {
/* Find in empty text */
{0, -1, "foo", FR_DOWN, -1},
{0, -1, "foo", 0, -1},
{0, -1, "", FR_DOWN, -1},
{20, 5, "foo", FR_DOWN, -1},
{5, 20, "foo", FR_DOWN, -1}
};
static struct find_s find_tests2[] = {
/* No-result find */
{0, -1, "foo", FR_DOWN | FR_MATCHCASE, -1},
{5, 20, "WINE", FR_DOWN | FR_MATCHCASE, -1},
/* Subsequent finds */
{0, -1, "Wine", FR_DOWN | FR_MATCHCASE, 4},
{5, 31, "Wine", FR_DOWN | FR_MATCHCASE, 13},
{14, 31, "Wine", FR_DOWN | FR_MATCHCASE, 23},
{24, 31, "Wine", FR_DOWN | FR_MATCHCASE, 27},
/* Find backwards */
{19, 20, "Wine", FR_MATCHCASE, 13},
{10, 20, "Wine", FR_MATCHCASE, 4},
{20, 10, "Wine", FR_MATCHCASE, 13},
/* Case-insensitive */
{1, 31, "wInE", FR_DOWN, 4},
{1, 31, "Wine", FR_DOWN, 4},
/* High-to-low ranges */
{20, 5, "Wine", FR_DOWN, -1},
{2, 1, "Wine", FR_DOWN, -1},
{30, 29, "Wine", FR_DOWN, -1},
{20, 5, "Wine", 0, 13},
/* Find nothing */
{5, 10, "", FR_DOWN, -1},
{10, 5, "", FR_DOWN, -1},
{0, -1, "", FR_DOWN, -1},
{10, 5, "", 0, -1},
/* Whole-word search */
{0, -1, "wine", FR_DOWN | FR_WHOLEWORD, 18},
{0, -1, "win", FR_DOWN | FR_WHOLEWORD, -1},
{13, -1, "wine", FR_DOWN | FR_WHOLEWORD, 18},
{0, -1, "winewine", FR_DOWN | FR_WHOLEWORD, 0},
{10, -1, "winewine", FR_DOWN | FR_WHOLEWORD, 23},
{11, -1, "winewine", FR_WHOLEWORD, 0},
{31, -1, "winewine", FR_WHOLEWORD, 23},
/* Bad ranges */
{5, 200, "XXX", FR_DOWN, -1},
{-20, 20, "Wine", FR_DOWN, -1},
{-20, 20, "Wine", FR_DOWN, -1},
{-15, -20, "Wine", FR_DOWN, -1},
{1<<12, 1<<13, "Wine", FR_DOWN, -1},
/* Check the case noted in bug 4479 where matches at end aren't recognized */
{23, 31, "Wine", FR_DOWN | FR_MATCHCASE, 23},
{27, 31, "Wine", FR_DOWN | FR_MATCHCASE, 27},
{27, 32, "Wine", FR_DOWN | FR_MATCHCASE, 27},
{13, 31, "WineWine", FR_DOWN | FR_MATCHCASE, 23},
{13, 32, "WineWine", FR_DOWN | FR_MATCHCASE, 23},
/* The backwards case of bug 4479; bounds look right
* Fails because backward find is wrong */
{19, 20, "WINE", FR_MATCHCASE, 0},
{0, 20, "WINE", FR_MATCHCASE, -1},
{0, -1, "wineWine wine", 0, -1},
};
static void check_EM_FINDTEXT(HWND hwnd, const char *name, struct find_s *f, int id) {
int findloc;
FINDTEXT ft;
memset(&ft, 0, sizeof(ft));
ft.chrg.cpMin = f->start;
ft.chrg.cpMax = f->end;
ft.lpstrText = f->needle;
findloc = SendMessage(hwnd, EM_FINDTEXT, f->flags, (LPARAM) &ft);
ok(findloc == f->expected_loc,
"EM_FINDTEXT(%s,%d) '%s' in range(%d,%d), flags %08x, got start at %d, expected %d\n",
name, id, f->needle, f->start, f->end, f->flags, findloc, f->expected_loc);
}
static void check_EM_FINDTEXTEX(HWND hwnd, const char *name, struct find_s *f,
int id) {
int findloc;
FINDTEXTEX ft;
int expected_end_loc;
memset(&ft, 0, sizeof(ft));
ft.chrg.cpMin = f->start;
ft.chrg.cpMax = f->end;
ft.lpstrText = f->needle;
findloc = SendMessage(hwnd, EM_FINDTEXTEX, f->flags, (LPARAM) &ft);
ok(findloc == f->expected_loc,
"EM_FINDTEXTEX(%s,%d) '%s' in range(%d,%d), flags %08x, start at %d\n",
name, id, f->needle, f->start, f->end, f->flags, findloc);
ok(ft.chrgText.cpMin == f->expected_loc,
"EM_FINDTEXTEX(%s,%d) '%s' in range(%d,%d), flags %08x, start at %d\n",
name, id, f->needle, f->start, f->end, f->flags, ft.chrgText.cpMin);
expected_end_loc = ((f->expected_loc == -1) ? -1
: f->expected_loc + strlen(f->needle));
ok(ft.chrgText.cpMax == expected_end_loc,
"EM_FINDTEXTEX(%s,%d) '%s' in range(%d,%d), flags %08x, end at %d, expected %d\n",
name, id, f->needle, f->start, f->end, f->flags, ft.chrgText.cpMax, expected_end_loc);
}
static void run_tests_EM_FINDTEXT(HWND hwnd, const char *name, struct find_s *find,
int num_tests)
{
int i;
for (i = 0; i < num_tests; i++) {
check_EM_FINDTEXT(hwnd, name, &find[i], i);
check_EM_FINDTEXTEX(hwnd, name, &find[i], i);
}
}
static void test_EM_FINDTEXT(void)
{
HWND hwndRichEdit = new_richedit(NULL);
CHARFORMAT2 cf2;
/* Empty rich edit control */
run_tests_EM_FINDTEXT(hwndRichEdit, "1", find_tests,
sizeof(find_tests)/sizeof(struct find_s));
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) haystack);
/* Haystack text */
run_tests_EM_FINDTEXT(hwndRichEdit, "2", find_tests2,
sizeof(find_tests2)/sizeof(struct find_s));
/* Setting a format on an arbitrary range should have no effect in search
results. This tests correct offset reporting across runs. */
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf2);
cf2.dwMask = CFM_ITALIC | cf2.dwMask;
cf2.dwEffects = CFE_ITALIC ^ cf2.dwEffects;
SendMessage(hwndRichEdit, EM_SETSEL, 6, 20);
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
/* Haystack text, again */
run_tests_EM_FINDTEXT(hwndRichEdit, "2-bis", find_tests2,
sizeof(find_tests2)/sizeof(struct find_s));
/* Yet another range */
cf2.dwMask = CFM_BOLD | cf2.dwMask;
cf2.dwEffects = CFE_BOLD ^ cf2.dwEffects;
SendMessage(hwndRichEdit, EM_SETSEL, 11, 15);
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
/* Haystack text, again */
run_tests_EM_FINDTEXT(hwndRichEdit, "2-bisbis", find_tests2,
sizeof(find_tests2)/sizeof(struct find_s));
DestroyWindow(hwndRichEdit);
}
static const struct getline_s {
int line;
size_t buffer_len;
const char *text;
} gl[] = {
{0, 10, "foo bar\r"},
{1, 10, "\r"},
{2, 10, "bar\r"},
{3, 10, "\r"},
/* Buffer smaller than line length */
{0, 2, "foo bar\r"},
{0, 1, "foo bar\r"},
{0, 0, "foo bar\r"}
};
static void test_EM_GETLINE(void)
{
int i;
HWND hwndRichEdit = new_richedit(NULL);
static const int nBuf = 1024;
char dest[1024], origdest[1024];
const char text[] = "foo bar\n"
"\n"
"bar\n";
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text);
memset(origdest, 0xBB, nBuf);
for (i = 0; i < sizeof(gl)/sizeof(struct getline_s); i++)
{
int nCopied;
int expected_nCopied = min(gl[i].buffer_len, strlen(gl[i].text));
int expected_bytes_written = min(gl[i].buffer_len, strlen(gl[i].text));
memset(dest, 0xBB, nBuf);
*(WORD *) dest = gl[i].buffer_len;
/* EM_GETLINE appends a "\r\0" to the end of the line
* nCopied counts up to and including the '\r' */
nCopied = SendMessage(hwndRichEdit, EM_GETLINE, gl[i].line, (LPARAM) dest);
ok(nCopied == expected_nCopied, "%d: %d!=%d\n", i, nCopied,
expected_nCopied);
/* two special cases since a parameter is passed via dest */
if (gl[i].buffer_len == 0)
ok(!dest[0] && !dest[1] && !strncmp(dest+2, origdest+2, nBuf-2),
"buffer_len=0\n");
else if (gl[i].buffer_len == 1)
ok(dest[0] == gl[i].text[0] && !dest[1] &&
!strncmp(dest+2, origdest+2, nBuf-2), "buffer_len=1\n");
else
{
/* Prepare hex strings of buffers to dump on failure. */
char expectedbuf[1024];
char resultbuf[1024];
int j;
resultbuf[0] = '\0';
for (j = 0; j < 32; j++)
sprintf(resultbuf+strlen(resultbuf), "%02x", dest[j] & 0xFF);
expectedbuf[0] = '\0';
for (j = 0; j < expected_bytes_written; j++) /* Written bytes */
sprintf(expectedbuf+strlen(expectedbuf), "%02x", gl[i].text[j] & 0xFF);
for (; j < gl[i].buffer_len; j++) /* Ignored bytes */
sprintf(expectedbuf+strlen(expectedbuf), "??");
for (; j < 32; j++) /* Bytes after declared buffer size */
sprintf(expectedbuf+strlen(expectedbuf), "%02x", origdest[j] & 0xFF);
/* Test the part of the buffer that is expected to be written according
* to the MSDN documentation fo EM_GETLINE, which does not state that
* a NULL terminating character will be added unless no text is copied.
*
* Windows NT does not append a NULL terminating character, but
* Windows 2000 and up do append a NULL terminating character if there
* is space in the buffer. The test will ignore this difference. */
ok(!strncmp(dest, gl[i].text, expected_bytes_written),
"%d: expected_bytes_written=%d\n" "expected=0x%s\n" "but got= 0x%s\n",
i, expected_bytes_written, expectedbuf, resultbuf);
/* Test the part of the buffer after the declared length to make sure
* there are no buffer overruns. */
ok(!strncmp(dest + gl[i].buffer_len, origdest + gl[i].buffer_len,
nBuf - gl[i].buffer_len),
"%d: expected_bytes_written=%d\n" "expected=0x%s\n" "but got= 0x%s\n",
i, expected_bytes_written, expectedbuf, resultbuf);
}
}
DestroyWindow(hwndRichEdit);
}
static void test_EM_LINELENGTH(void)
{
HWND hwndRichEdit = new_richedit(NULL);
const char * text =
"richedit1\r"
"richedit1\n"
"richedit1\r\n"
"richedit1";
int offset_test[10][2] = {
{0, 9},
{5, 9},
{10, 9},
{15, 9},
{20, 9},
{25, 9},
{30, 9},
{35, 9},
{40, 0},
{45, 0},
};
int i;
LRESULT result;
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text);
for (i = 0; i < 10; i++) {
result = SendMessage(hwndRichEdit, EM_LINELENGTH, offset_test[i][0], 0);
ok(result == offset_test[i][1], "Length of line at offset %d is %ld, expected %d\n",
offset_test[i][0], result, offset_test[i][1]);
}
DestroyWindow(hwndRichEdit);
}
static int get_scroll_pos_y(HWND hwnd)
{
POINT p = {-1, -1};
SendMessage(hwnd, EM_GETSCROLLPOS, 0, (LPARAM) &p);
ok(p.x != -1 && p.y != -1, "p.x:%d p.y:%d\n", p.x, p.y);
return p.y;
}
static void move_cursor(HWND hwnd, LONG charindex)
{
CHARRANGE cr;
cr.cpMax = charindex;
cr.cpMin = charindex;
SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM) &cr);
}
static void line_scroll(HWND hwnd, int amount)
{
SendMessage(hwnd, EM_LINESCROLL, 0, amount);
}
static void test_EM_SCROLLCARET(void)
{
int prevY, curY;
const char text[] = "aa\n"
"this is a long line of text that should be longer than the "
"control's width\n"
"cc\n"
"dd\n"
"ee\n"
"ff\n"
"gg\n"
"hh\n";
/* The richedit window height needs to be large enough vertically to fit in
* more than two lines of text, so the new_richedit function can't be used
* since a height of 60 was not large enough on some systems.
*/
HWND hwndRichEdit = CreateWindow(RICHEDIT_CLASS, NULL,
ES_MULTILINE|WS_POPUP|WS_HSCROLL|WS_VSCROLL|WS_VISIBLE,
0, 0, 200, 80, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwndRichEdit != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
/* Can't verify this */
SendMessage(hwndRichEdit, EM_SCROLLCARET, 0, 0);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text);
/* Caret above visible window */
line_scroll(hwndRichEdit, 3);
prevY = get_scroll_pos_y(hwndRichEdit);
SendMessage(hwndRichEdit, EM_SCROLLCARET, 0, 0);
curY = get_scroll_pos_y(hwndRichEdit);
ok(prevY != curY, "%d == %d\n", prevY, curY);
/* Caret below visible window */
move_cursor(hwndRichEdit, sizeof(text) - 1);
line_scroll(hwndRichEdit, -3);
prevY = get_scroll_pos_y(hwndRichEdit);
SendMessage(hwndRichEdit, EM_SCROLLCARET, 0, 0);
curY = get_scroll_pos_y(hwndRichEdit);
ok(prevY != curY, "%d == %d\n", prevY, curY);
/* Caret in visible window */
move_cursor(hwndRichEdit, sizeof(text) - 2);
prevY = get_scroll_pos_y(hwndRichEdit);
SendMessage(hwndRichEdit, EM_SCROLLCARET, 0, 0);
curY = get_scroll_pos_y(hwndRichEdit);
ok(prevY == curY, "%d != %d\n", prevY, curY);
/* Caret still in visible window */
line_scroll(hwndRichEdit, -1);
prevY = get_scroll_pos_y(hwndRichEdit);
SendMessage(hwndRichEdit, EM_SCROLLCARET, 0, 0);
curY = get_scroll_pos_y(hwndRichEdit);
ok(prevY == curY, "%d != %d\n", prevY, curY);
DestroyWindow(hwndRichEdit);
}
static void test_EM_POSFROMCHAR(void)
{
HWND hwndRichEdit = new_richedit(NULL);
int i, expected;
LRESULT result;
unsigned int height = 0;
int xpos = 0;
POINTL pt;
LOCALESIGNATURE sig;
BOOL rtl;
static const char text[] = "aa\n"
"this is a long line of text that should be longer than the "
"control's width\n"
"cc\n"
"dd\n"
"ee\n"
"ff\n"
"gg\n"
"hh\n";
rtl = (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_FONTSIGNATURE,
(LPSTR) &sig, sizeof(LOCALESIGNATURE)) &&
(sig.lsUsb[3] & 0x08000000) != 0);
/* Fill the control to lines to ensure that most of them are offscreen */
for (i = 0; i < 50; i++)
{
/* Do not modify the string; it is exactly 16 characters long. */
SendMessage(hwndRichEdit, EM_SETSEL, 0, 0);
SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)"0123456789ABCDE\n");
}
/*
Richedit 1.0 receives a POINTL* on wParam and character offset on lParam, returns void.
Richedit 2.0 receives character offset on wParam, ignores lParam, returns MAKELONG(x,y)
Richedit 3.0 accepts either of the above API conventions.
*/
/* Testing Richedit 2.0 API format */
/* Testing start of lines. X-offset should be constant on all cases (native is 1).
Since all lines are identical and drawn with the same font,
they should have the same height... right?
*/
for (i = 0; i < 50; i++)
{
/* All the lines are 16 characters long */
result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, i * 16, 0);
if (i == 0)
{
ok(HIWORD(result) == 0, "EM_POSFROMCHAR reports y=%d, expected 0\n", HIWORD(result));
ok(LOWORD(result) == 1, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result));
xpos = LOWORD(result);
}
else if (i == 1)
{
ok(HIWORD(result) > 0, "EM_POSFROMCHAR reports y=%d, expected > 0\n", HIWORD(result));
ok(LOWORD(result) == xpos, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result));
height = HIWORD(result);
}
else
{
ok(HIWORD(result) == i * height, "EM_POSFROMCHAR reports y=%d, expected %d\n", HIWORD(result), i * height);
ok(LOWORD(result) == xpos, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result));
}
}
/* Testing position at end of text */
result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, 50 * 16, 0);
ok(HIWORD(result) == 50 * height, "EM_POSFROMCHAR reports y=%d, expected %d\n", HIWORD(result), 50 * height);
ok(LOWORD(result) == xpos, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result));
/* Testing position way past end of text */
result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, 55 * 16, 0);
ok(HIWORD(result) == 50 * height, "EM_POSFROMCHAR reports y=%d, expected %d\n", HIWORD(result), 50 * height);
expected = (rtl ? 8 : 1);
ok(LOWORD(result) == expected, "EM_POSFROMCHAR reports x=%d, expected %d\n", LOWORD(result), expected);
/* Testing that vertical scrolling does, in fact, have an effect on EM_POSFROMCHAR */
SendMessage(hwndRichEdit, EM_SCROLL, SB_LINEDOWN, 0); /* line down */
for (i = 0; i < 50; i++)
{
/* All the lines are 16 characters long */
result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, i * 16, 0);
ok((signed short)(HIWORD(result)) == (i - 1) * height,
"EM_POSFROMCHAR reports y=%hd, expected %d\n",
(signed short)(HIWORD(result)), (i - 1) * height);
ok(LOWORD(result) == xpos, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result));
}
/* Testing position at end of text */
result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, 50 * 16, 0);
ok(HIWORD(result) == (50 - 1) * height, "EM_POSFROMCHAR reports y=%d, expected %d\n", HIWORD(result), (50 - 1) * height);
ok(LOWORD(result) == xpos, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result));
/* Testing position way past end of text */
result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, 55 * 16, 0);
ok(HIWORD(result) == (50 - 1) * height, "EM_POSFROMCHAR reports y=%d, expected %d\n", HIWORD(result), (50 - 1) * height);
expected = (rtl ? 8 : 1);
ok(LOWORD(result) == expected, "EM_POSFROMCHAR reports x=%d, expected %d\n", LOWORD(result), expected);
/* Testing that horizontal scrolling does, in fact, have an effect on EM_POSFROMCHAR */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text);
SendMessage(hwndRichEdit, EM_SCROLL, SB_LINEUP, 0); /* line up */
result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, 0, 0);
ok(HIWORD(result) == 0, "EM_POSFROMCHAR reports y=%d, expected 0\n", HIWORD(result));
ok(LOWORD(result) == 1, "EM_POSFROMCHAR reports x=%d, expected 1\n", LOWORD(result));
xpos = LOWORD(result);
SendMessage(hwndRichEdit, WM_HSCROLL, SB_LINERIGHT, 0);
result = SendMessage(hwndRichEdit, EM_POSFROMCHAR, 0, 0);
ok(HIWORD(result) == 0, "EM_POSFROMCHAR reports y=%d, expected 0\n", HIWORD(result));
ok((signed short)(LOWORD(result)) < xpos,
"EM_POSFROMCHAR reports x=%hd, expected value less than %d\n",
(signed short)(LOWORD(result)), xpos);
SendMessage(hwndRichEdit, WM_HSCROLL, SB_LINELEFT, 0);
/* Test around end of text that doesn't end in a newline. */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "12345678901234");
SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM)&pt,
SendMessage(hwndRichEdit, WM_GETTEXTLENGTH, 0, 0)-1);
ok(pt.x > 1, "pt.x = %d\n", pt.x);
xpos = pt.x;
SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM)&pt,
SendMessage(hwndRichEdit, WM_GETTEXTLENGTH, 0, 0));
ok(pt.x > xpos, "pt.x = %d\n", pt.x);
xpos = (rtl ? pt.x + 7 : pt.x);
SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM)&pt,
SendMessage(hwndRichEdit, WM_GETTEXTLENGTH, 0, 0)+1);
ok(pt.x == xpos, "pt.x = %d\n", pt.x);
/* Try a negative position. */
SendMessage(hwndRichEdit, EM_POSFROMCHAR, (WPARAM)&pt, -1);
ok(pt.x == 1, "pt.x = %d\n", pt.x);
DestroyWindow(hwndRichEdit);
}
static void test_EM_SETCHARFORMAT(void)
{
HWND hwndRichEdit = new_richedit(NULL);
CHARFORMAT2 cf2;
int rc = 0;
int tested_effects[] = {
CFE_BOLD,
CFE_ITALIC,
CFE_UNDERLINE,
CFE_STRIKEOUT,
CFE_PROTECTED,
CFE_LINK,
CFE_SUBSCRIPT,
CFE_SUPERSCRIPT,
0
};
int i;
CHARRANGE cr;
LOCALESIGNATURE sig;
BOOL rtl;
rtl = (GetLocaleInfoA(LOCALE_USER_DEFAULT, LOCALE_FONTSIGNATURE,
(LPSTR) &sig, sizeof(LOCALESIGNATURE)) &&
(sig.lsUsb[3] & 0x08000000) != 0);
/* Invalid flags, CHARFORMAT2 structure blanked out */
memset(&cf2, 0, sizeof(cf2));
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) 0xfffffff0,
(LPARAM) &cf2);
ok(rc == 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc);
/* A valid flag, CHARFORMAT2 structure blanked out */
memset(&cf2, 0, sizeof(cf2));
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_DEFAULT,
(LPARAM) &cf2);
ok(rc == 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc);
/* A valid flag, CHARFORMAT2 structure blanked out */
memset(&cf2, 0, sizeof(cf2));
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_SELECTION,
(LPARAM) &cf2);
ok(rc == 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc);
/* A valid flag, CHARFORMAT2 structure blanked out */
memset(&cf2, 0, sizeof(cf2));
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_WORD,
(LPARAM) &cf2);
ok(rc == 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc);
/* A valid flag, CHARFORMAT2 structure blanked out */
memset(&cf2, 0, sizeof(cf2));
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_ALL,
(LPARAM) &cf2);
ok(rc == 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc);
/* Invalid flags, CHARFORMAT2 structure minimally filled */
memset(&cf2, 0, sizeof(cf2));
cf2.cbSize = sizeof(CHARFORMAT2);
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) 0xfffffff0,
(LPARAM) &cf2);
ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
rc = SendMessage(hwndRichEdit, EM_CANUNDO, 0, 0);
ok(rc == FALSE, "Should not be able to undo here.\n");
SendMessage(hwndRichEdit, EM_EMPTYUNDOBUFFER, 0, 0);
/* A valid flag, CHARFORMAT2 structure minimally filled */
memset(&cf2, 0, sizeof(cf2));
cf2.cbSize = sizeof(CHARFORMAT2);
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_DEFAULT,
(LPARAM) &cf2);
ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
rc = SendMessage(hwndRichEdit, EM_CANUNDO, 0, 0);
ok(rc == FALSE, "Should not be able to undo here.\n");
SendMessage(hwndRichEdit, EM_EMPTYUNDOBUFFER, 0, 0);
/* A valid flag, CHARFORMAT2 structure minimally filled */
memset(&cf2, 0, sizeof(cf2));
cf2.cbSize = sizeof(CHARFORMAT2);
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_SELECTION,
(LPARAM) &cf2);
ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
rc = SendMessage(hwndRichEdit, EM_CANUNDO, 0, 0);
ok(rc == FALSE, "Should not be able to undo here.\n");
SendMessage(hwndRichEdit, EM_EMPTYUNDOBUFFER, 0, 0);
/* A valid flag, CHARFORMAT2 structure minimally filled */
memset(&cf2, 0, sizeof(cf2));
cf2.cbSize = sizeof(CHARFORMAT2);
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_WORD,
(LPARAM) &cf2);
ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
rc = SendMessage(hwndRichEdit, EM_CANUNDO, 0, 0);
todo_wine ok(rc == TRUE, "Should not be able to undo here.\n");
SendMessage(hwndRichEdit, EM_EMPTYUNDOBUFFER, 0, 0);
/* A valid flag, CHARFORMAT2 structure minimally filled */
memset(&cf2, 0, sizeof(cf2));
cf2.cbSize = sizeof(CHARFORMAT2);
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_ALL,
(LPARAM) &cf2);
ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
rc = SendMessage(hwndRichEdit, EM_CANUNDO, 0, 0);
ok(rc == TRUE, "Should not be able to undo here.\n");
SendMessage(hwndRichEdit, EM_EMPTYUNDOBUFFER, 0, 0);
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, (WPARAM) SCF_DEFAULT,
(LPARAM) &cf2);
/* Test state of modify flag before and after valid EM_SETCHARFORMAT */
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, (WPARAM) SCF_DEFAULT,
(LPARAM) &cf2);
cf2.dwMask = CFM_ITALIC | cf2.dwMask;
cf2.dwEffects = CFE_ITALIC ^ cf2.dwEffects;
/* wParam==0 is default char format, does not set modify */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok(rc == 0, "Text marked as modified, expected not modified!\n");
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, 0, (LPARAM) &cf2);
ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
if (! rtl)
{
rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok(rc == 0, "Text marked as modified, expected not modified!\n");
}
else
skip("RTL language found\n");
/* wParam==SCF_SELECTION sets modify if nonempty selection */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok(rc == 0, "Text marked as modified, expected not modified!\n");
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok(rc == 0, "Text marked as modified, expected not modified!\n");
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"wine");
rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok(rc == 0, "Text marked as modified, expected not modified!\n");
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok(rc == 0, "Text marked as modified, expected not modified!\n");
SendMessage(hwndRichEdit, EM_SETSEL, 0, 2);
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok(rc == -1, "Text not marked as modified, expected modified! (%d)\n", rc);
/* wParam==SCF_ALL sets modify regardless of whether text is present */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok(rc == 0, "Text marked as modified, expected not modified!\n");
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_ALL, (LPARAM) &cf2);
ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok(rc == -1, "Text not marked as modified, expected modified! (%d)\n", rc);
DestroyWindow(hwndRichEdit);
/* EM_GETCHARFORMAT tests */
for (i = 0; tested_effects[i]; i++)
{
hwndRichEdit = new_richedit(NULL);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"wine");
/* Need to set a TrueType font to get consistent CFM_BOLD results */
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
cf2.dwMask = CFM_FACE|CFM_WEIGHT;
cf2.dwEffects = 0;
strcpy(cf2.szFaceName, "Courier New");
cf2.wWeight = FW_DONTCARE;
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &cf2);
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_SETSEL, 0, 4);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok ((((tested_effects[i] == CFE_SUBSCRIPT || tested_effects[i] == CFE_SUPERSCRIPT) &&
(cf2.dwMask & CFM_SUPERSCRIPT) == CFM_SUPERSCRIPT)
||
(cf2.dwMask & tested_effects[i]) == tested_effects[i]),
"%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, tested_effects[i]);
ok((cf2.dwEffects & tested_effects[i]) == 0,
"%d, cf2.dwEffects == 0x%08x expected effect 0x%08x clear\n", i, cf2.dwEffects, tested_effects[i]);
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
cf2.dwMask = tested_effects[i];
if (cf2.dwMask == CFE_SUBSCRIPT || cf2.dwMask == CFE_SUPERSCRIPT)
cf2.dwMask = CFM_SUPERSCRIPT;
cf2.dwEffects = tested_effects[i];
SendMessage(hwndRichEdit, EM_SETSEL, 0, 2);
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_SETSEL, 0, 2);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok ((((tested_effects[i] == CFE_SUBSCRIPT || tested_effects[i] == CFE_SUPERSCRIPT) &&
(cf2.dwMask & CFM_SUPERSCRIPT) == CFM_SUPERSCRIPT)
||
(cf2.dwMask & tested_effects[i]) == tested_effects[i]),
"%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, tested_effects[i]);
ok((cf2.dwEffects & tested_effects[i]) == tested_effects[i],
"%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i, cf2.dwEffects, tested_effects[i]);
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_SETSEL, 2, 4);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok ((((tested_effects[i] == CFE_SUBSCRIPT || tested_effects[i] == CFE_SUPERSCRIPT) &&
(cf2.dwMask & CFM_SUPERSCRIPT) == CFM_SUPERSCRIPT)
||
(cf2.dwMask & tested_effects[i]) == tested_effects[i]),
"%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, tested_effects[i]);
ok((cf2.dwEffects & tested_effects[i]) == 0,
"%d, cf2.dwEffects == 0x%08x expected effect 0x%08x clear\n", i, cf2.dwEffects, tested_effects[i]);
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_SETSEL, 1, 3);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok ((((tested_effects[i] == CFE_SUBSCRIPT || tested_effects[i] == CFE_SUPERSCRIPT) &&
(cf2.dwMask & CFM_SUPERSCRIPT) == 0)
||
(cf2.dwMask & tested_effects[i]) == 0),
"%d, cf2.dwMask == 0x%08x expected mask 0x%08x clear\n", i, cf2.dwMask, tested_effects[i]);
DestroyWindow(hwndRichEdit);
}
for (i = 0; tested_effects[i]; i++)
{
hwndRichEdit = new_richedit(NULL);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"wine");
/* Need to set a TrueType font to get consistent CFM_BOLD results */
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
cf2.dwMask = CFM_FACE|CFM_WEIGHT;
cf2.dwEffects = 0;
strcpy(cf2.szFaceName, "Courier New");
cf2.wWeight = FW_DONTCARE;
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &cf2);
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
cf2.dwMask = tested_effects[i];
if (cf2.dwMask == CFE_SUBSCRIPT || cf2.dwMask == CFE_SUPERSCRIPT)
cf2.dwMask = CFM_SUPERSCRIPT;
cf2.dwEffects = tested_effects[i];
SendMessage(hwndRichEdit, EM_SETSEL, 2, 4);
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_SETSEL, 0, 2);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok ((((tested_effects[i] == CFE_SUBSCRIPT || tested_effects[i] == CFE_SUPERSCRIPT) &&
(cf2.dwMask & CFM_SUPERSCRIPT) == CFM_SUPERSCRIPT)
||
(cf2.dwMask & tested_effects[i]) == tested_effects[i]),
"%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, tested_effects[i]);
ok((cf2.dwEffects & tested_effects[i]) == 0,
"%d, cf2.dwEffects == 0x%08x expected effect 0x%08x clear\n", i, cf2.dwEffects, tested_effects[i]);
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_SETSEL, 2, 4);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok ((((tested_effects[i] == CFE_SUBSCRIPT || tested_effects[i] == CFE_SUPERSCRIPT) &&
(cf2.dwMask & CFM_SUPERSCRIPT) == CFM_SUPERSCRIPT)
||
(cf2.dwMask & tested_effects[i]) == tested_effects[i]),
"%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, tested_effects[i]);
ok((cf2.dwEffects & tested_effects[i]) == tested_effects[i],
"%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i, cf2.dwEffects, tested_effects[i]);
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_SETSEL, 1, 3);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok ((((tested_effects[i] == CFE_SUBSCRIPT || tested_effects[i] == CFE_SUPERSCRIPT) &&
(cf2.dwMask & CFM_SUPERSCRIPT) == 0)
||
(cf2.dwMask & tested_effects[i]) == 0),
"%d, cf2.dwMask == 0x%08x expected mask 0x%08x clear\n", i, cf2.dwMask, tested_effects[i]);
ok((cf2.dwEffects & tested_effects[i]) == tested_effects[i],
"%d, cf2.dwEffects == 0x%08x expected effect 0x%08x set\n", i, cf2.dwEffects, tested_effects[i]);
DestroyWindow(hwndRichEdit);
}
/* Effects applied on an empty selection should take effect when selection is
replaced with text */
hwndRichEdit = new_richedit(NULL);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"wine");
SendMessage(hwndRichEdit, EM_SETSEL, 2, 2); /* Empty selection */
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
cf2.dwMask = CFM_BOLD;
cf2.dwEffects = CFE_BOLD;
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
/* Selection is now nonempty */
SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)"newi");
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_SETSEL, 2, 6);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok (((cf2.dwMask & CFM_BOLD) == CFM_BOLD),
"%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, CFM_BOLD);
ok((cf2.dwEffects & CFE_BOLD) == CFE_BOLD,
"%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i, cf2.dwEffects, CFE_BOLD);
/* Set two effects on an empty selection */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"wine");
SendMessage(hwndRichEdit, EM_SETSEL, 2, 2); /* Empty selection */
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
cf2.dwMask = CFM_BOLD;
cf2.dwEffects = CFE_BOLD;
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
cf2.dwMask = CFM_ITALIC;
cf2.dwEffects = CFE_ITALIC;
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
/* Selection is now nonempty */
SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)"newi");
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_SETSEL, 2, 6);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok (((cf2.dwMask & (CFM_BOLD|CFM_ITALIC)) == (CFM_BOLD|CFM_ITALIC)),
"%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, (CFM_BOLD|CFM_ITALIC));
ok((cf2.dwEffects & (CFE_BOLD|CFE_ITALIC)) == (CFE_BOLD|CFE_ITALIC),
"%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i, cf2.dwEffects, (CFE_BOLD|CFE_ITALIC));
/* Setting the (empty) selection to exactly the same place as before should
NOT clear the insertion style! */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"wine");
SendMessage(hwndRichEdit, EM_SETSEL, 2, 2); /* Empty selection */
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
cf2.dwMask = CFM_BOLD;
cf2.dwEffects = CFE_BOLD;
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
/* Empty selection in same place, insert style should NOT be forgotten here. */
SendMessage(hwndRichEdit, EM_SETSEL, 2, 2);
/* Selection is now nonempty */
SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)"newi");
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_SETSEL, 2, 6);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok (((cf2.dwMask & CFM_BOLD) == CFM_BOLD),
"%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, CFM_BOLD);
ok((cf2.dwEffects & CFE_BOLD) == CFE_BOLD,
"%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i, cf2.dwEffects, CFE_BOLD);
/* Ditto with EM_EXSETSEL */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"wine");
cr.cpMin = 2; cr.cpMax = 2;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM)&cr); /* Empty selection */
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
cf2.dwMask = CFM_BOLD;
cf2.dwEffects = CFE_BOLD;
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
/* Empty selection in same place, insert style should NOT be forgotten here. */
cr.cpMin = 2; cr.cpMax = 2;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM)&cr); /* Empty selection */
/* Selection is now nonempty */
SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)"newi");
memset(&cf2, 0, sizeof(CHARFORMAT2));
cf2.cbSize = sizeof(CHARFORMAT2);
cr.cpMin = 2; cr.cpMax = 6;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM)&cr); /* Empty selection */
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &cf2);
ok (((cf2.dwMask & CFM_BOLD) == CFM_BOLD),
"%d, cf2.dwMask == 0x%08x expected mask 0x%08x\n", i, cf2.dwMask, CFM_BOLD);
ok((cf2.dwEffects & CFE_BOLD) == CFE_BOLD,
"%d, cf2.dwEffects == 0x%08x expected effect 0x%08x\n", i, cf2.dwEffects, CFE_BOLD);
DestroyWindow(hwndRichEdit);
}
static void test_EM_SETTEXTMODE(void)
{
HWND hwndRichEdit = new_richedit(NULL);
CHARFORMAT2 cf2, cf2test;
CHARRANGE cr;
int rc = 0;
/*Attempt to use mutually exclusive modes*/
rc = SendMessage(hwndRichEdit, EM_SETTEXTMODE, (WPARAM) TM_PLAINTEXT|TM_RICHTEXT, 0);
ok(rc == E_INVALIDARG,
"EM_SETTEXTMODE: using mutually exclusive mode flags - returned: %x\n", rc);
/*Test that EM_SETTEXTMODE fails if text exists within the control*/
/*Insert text into the control*/
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "wine");
/*Attempt to change the control to plain text mode*/
rc = SendMessage(hwndRichEdit, EM_SETTEXTMODE, (WPARAM) TM_PLAINTEXT, 0);
ok(rc == E_UNEXPECTED,
"EM_SETTEXTMODE: changed text mode in control containing text - returned: %x\n", rc);
/*Test that EM_SETTEXTMODE does not allow rich edit text to be pasted.
If rich text is pasted, it should have the same formatting as the rest
of the text in the control*/
/*Italicize the text
*NOTE: If the default text was already italicized, the test will simply
reverse; in other words, it will copy a regular "wine" into a plain
text window that uses an italicized format*/
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, (WPARAM) SCF_DEFAULT,
(LPARAM) &cf2);
cf2.dwMask = CFM_ITALIC | cf2.dwMask;
cf2.dwEffects = CFE_ITALIC ^ cf2.dwEffects;
rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok(rc == 0, "Text marked as modified, expected not modified!\n");
/*EM_SETCHARFORMAT is not yet fully implemented for all WPARAMs in wine;
however, SCF_ALL has been implemented*/
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_ALL, (LPARAM) &cf2);
ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
rc = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok(rc == -1, "Text not marked as modified, expected modified! (%d)\n", rc);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "wine");
/*Select the string "wine"*/
cr.cpMin = 0;
cr.cpMax = 4;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
/*Copy the italicized "wine" to the clipboard*/
SendMessage(hwndRichEdit, WM_COPY, 0, 0);
/*Reset the formatting to default*/
cf2.dwEffects = CFE_ITALIC^cf2.dwEffects;
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, (WPARAM) SCF_ALL, (LPARAM) &cf2);
ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
/*Clear the text in the control*/
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "");
/*Switch to Plain Text Mode*/
rc = SendMessage(hwndRichEdit, EM_SETTEXTMODE, (WPARAM) TM_PLAINTEXT, 0);
ok(rc == 0, "EM_SETTEXTMODE: unable to switch to plain text mode with empty control: returned: %d\n", rc);
/*Input "wine" again in normal format*/
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "wine");
/*Paste the italicized "wine" into the control*/
SendMessage(hwndRichEdit, WM_PASTE, 0, 0);
/*Select a character from the first "wine" string*/
cr.cpMin = 2;
cr.cpMax = 3;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
/*Retrieve its formatting*/
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, (WPARAM) SCF_SELECTION,
(LPARAM) &cf2);
/*Select a character from the second "wine" string*/
cr.cpMin = 5;
cr.cpMax = 6;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
/*Retrieve its formatting*/
cf2test.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, (WPARAM) SCF_SELECTION,
(LPARAM) &cf2test);
/*Compare the two formattings*/
ok((cf2.dwMask == cf2test.dwMask) && (cf2.dwEffects == cf2test.dwEffects),
"two formats found in plain text mode - cf2.dwEffects: %x cf2test.dwEffects: %x\n",
cf2.dwEffects, cf2test.dwEffects);
/*Test TM_RICHTEXT by: switching back to Rich Text mode
printing "wine" in the current format(normal)
pasting "wine" from the clipboard(italicized)
comparing the two formats(should differ)*/
/*Attempt to switch with text in control*/
rc = SendMessage(hwndRichEdit, EM_SETTEXTMODE, (WPARAM) TM_RICHTEXT, 0);
ok(rc != 0, "EM_SETTEXTMODE: changed from plain text to rich text with text in control - returned: %d\n", rc);
/*Clear control*/
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "");
/*Switch into Rich Text mode*/
rc = SendMessage(hwndRichEdit, EM_SETTEXTMODE, (WPARAM) TM_RICHTEXT, 0);
ok(rc == 0, "EM_SETTEXTMODE: unable to change to rich text with empty control - returned: %d\n", rc);
/*Print "wine" in normal formatting into the control*/
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "wine");
/*Paste italicized "wine" into the control*/
SendMessage(hwndRichEdit, WM_PASTE, 0, 0);
/*Select text from the first "wine" string*/
cr.cpMin = 1;
cr.cpMax = 3;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
/*Retrieve its formatting*/
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, (WPARAM) SCF_SELECTION,
(LPARAM) &cf2);
/*Select text from the second "wine" string*/
cr.cpMin = 6;
cr.cpMax = 7;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
/*Retrieve its formatting*/
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, (WPARAM) SCF_SELECTION,
(LPARAM) &cf2test);
/*Test that the two formattings are not the same*/
todo_wine ok((cf2.dwMask == cf2test.dwMask) && (cf2.dwEffects != cf2test.dwEffects),
"expected different formats - cf2.dwMask: %x, cf2test.dwMask: %x, cf2.dwEffects: %x, cf2test.dwEffects: %x\n",
cf2.dwMask, cf2test.dwMask, cf2.dwEffects, cf2test.dwEffects);
DestroyWindow(hwndRichEdit);
}
static void test_SETPARAFORMAT(void)
{
HWND hwndRichEdit = new_richedit(NULL);
PARAFORMAT2 fmt;
HRESULT ret;
LONG expectedMask = PFM_ALL2 & ~PFM_TABLEROWDELIMITER;
fmt.cbSize = sizeof(PARAFORMAT2);
fmt.dwMask = PFM_ALIGNMENT;
fmt.wAlignment = PFA_LEFT;
ret = SendMessage(hwndRichEdit, EM_SETPARAFORMAT, 0, (LPARAM) &fmt);
ok(ret != 0, "expected non-zero got %d\n", ret);
fmt.cbSize = sizeof(PARAFORMAT2);
fmt.dwMask = -1;
ret = SendMessage(hwndRichEdit, EM_GETPARAFORMAT, 0, (LPARAM) &fmt);
/* Ignore the PFM_TABLEROWDELIMITER bit because it changes
* between richedit different native builds of riched20.dll
* used on different Windows versions. */
ret &= ~PFM_TABLEROWDELIMITER;
fmt.dwMask &= ~PFM_TABLEROWDELIMITER;
ok(ret == expectedMask, "expected %x got %x\n", expectedMask, ret);
ok(fmt.dwMask == expectedMask, "expected %x got %x\n", expectedMask, fmt.dwMask);
DestroyWindow(hwndRichEdit);
}
static void test_TM_PLAINTEXT(void)
{
/*Tests plain text properties*/
HWND hwndRichEdit = new_richedit(NULL);
CHARFORMAT2 cf2, cf2test;
CHARRANGE cr;
int rc = 0;
/*Switch to plain text mode*/
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "");
SendMessage(hwndRichEdit, EM_SETTEXTMODE, TM_PLAINTEXT, 0);
/*Fill control with text*/
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "Is Wine an emulator? No it's not");
/*Select some text and bold it*/
cr.cpMin = 10;
cr.cpMax = 20;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf2);
cf2.dwMask = CFM_BOLD | cf2.dwMask;
cf2.dwEffects = CFE_BOLD ^ cf2.dwEffects;
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf2);
ok(rc == 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc);
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_WORD | SCF_SELECTION, (LPARAM)&cf2);
ok(rc == 0, "EM_SETCHARFORMAT returned %d instead of 0\n", rc);
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf2);
ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
/*Get the formatting of those characters*/
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf2);
/*Get the formatting of some other characters*/
cf2test.cbSize = sizeof(CHARFORMAT2);
cr.cpMin = 21;
cr.cpMax = 30;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf2test);
/*Test that they are the same as plain text allows only one formatting*/
ok((cf2.dwMask == cf2test.dwMask) && (cf2.dwEffects == cf2test.dwEffects),
"two selections' formats differ - cf2.dwMask: %x, cf2test.dwMask %x, cf2.dwEffects: %x, cf2test.dwEffects: %x\n",
cf2.dwMask, cf2test.dwMask, cf2.dwEffects, cf2test.dwEffects);
/*Fill the control with a "wine" string, which when inserted will be bold*/
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "wine");
/*Copy the bolded "wine" string*/
cr.cpMin = 0;
cr.cpMax = 4;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
SendMessage(hwndRichEdit, WM_COPY, 0, 0);
/*Swap back to rich text*/
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "");
SendMessage(hwndRichEdit, EM_SETTEXTMODE, TM_RICHTEXT, 0);
/*Set the default formatting to bold italics*/
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf2);
cf2.dwMask |= CFM_ITALIC;
cf2.dwEffects ^= CFE_ITALIC;
rc = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf2);
ok(rc == 1, "EM_SETCHARFORMAT returned %d instead of 1\n", rc);
/*Set the text in the control to "wine", which will be bold and italicized*/
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "wine");
/*Paste the plain text "wine" string, which should take the insert
formatting, which at the moment is bold italics*/
SendMessage(hwndRichEdit, WM_PASTE, 0, 0);
/*Select the first "wine" string and retrieve its formatting*/
cr.cpMin = 1;
cr.cpMax = 3;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf2);
/*Select the second "wine" string and retrieve its formatting*/
cr.cpMin = 5;
cr.cpMax = 7;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM)&cf2test);
/*Compare the two formattings. They should be the same.*/
ok((cf2.dwMask == cf2test.dwMask) && (cf2.dwEffects == cf2test.dwEffects),
"Copied text retained formatting - cf2.dwMask: %x, cf2test.dwMask: %x, cf2.dwEffects: %x, cf2test.dwEffects: %x\n",
cf2.dwMask, cf2test.dwMask, cf2.dwEffects, cf2test.dwEffects);
DestroyWindow(hwndRichEdit);
}
static void test_WM_GETTEXT(void)
{
HWND hwndRichEdit = new_richedit(NULL);
static const char text[] = "Hello. My name is RichEdit!";
static const char text2[] = "Hello. My name is RichEdit!\r";
static const char text2_after[] = "Hello. My name is RichEdit!\r\n";
char buffer[1024] = {0};
int result;
/* Baseline test with normal-sized buffer */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok(result == lstrlen(buffer),
"WM_GETTEXT returned %d, expected %d\n", result, lstrlen(buffer));
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
result = strcmp(buffer,text);
ok(result == 0,
"WM_GETTEXT: settext and gettext differ. strcmp: %d\n", result);
/* Test for returned value of WM_GETTEXTLENGTH */
result = SendMessage(hwndRichEdit, WM_GETTEXTLENGTH, 0, 0);
ok(result == lstrlen(text),
"WM_GETTEXTLENGTH reports incorrect length %d, expected %d\n",
result, lstrlen(text));
/* Test for behavior in overflow case */
memset(buffer, 0, 1024);
result = SendMessage(hwndRichEdit, WM_GETTEXT, strlen(text), (LPARAM)buffer);
ok(result == 0 ||
result == lstrlenA(text) - 1, /* XP, win2k3 */
"WM_GETTEXT returned %d, expected 0 or %d\n", result, lstrlenA(text) - 1);
result = strcmp(buffer,text);
if (result)
result = strncmp(buffer, text, lstrlenA(text) - 1); /* XP, win2k3 */
ok(result == 0,
"WM_GETTEXT: settext and gettext differ. strcmp: %d\n", result);
/* Baseline test with normal-sized buffer and carriage return */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text2);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok(result == lstrlen(buffer),
"WM_GETTEXT returned %d, expected %d\n", result, lstrlen(buffer));
result = strcmp(buffer,text2_after);
ok(result == 0,
"WM_GETTEXT: settext and gettext differ. strcmp: %d\n", result);
/* Test for returned value of WM_GETTEXTLENGTH */
result = SendMessage(hwndRichEdit, WM_GETTEXTLENGTH, 0, 0);
ok(result == lstrlen(text2_after),
"WM_GETTEXTLENGTH reports incorrect length %d, expected %d\n",
result, lstrlen(text2_after));
/* Test for behavior of CRLF conversion in case of overflow */
memset(buffer, 0, 1024);
result = SendMessage(hwndRichEdit, WM_GETTEXT, strlen(text2), (LPARAM)buffer);
ok(result == 0 ||
result == lstrlenA(text2) - 1, /* XP, win2k3 */
"WM_GETTEXT returned %d, expected 0 or %d\n", result, lstrlenA(text2) - 1);
result = strcmp(buffer,text2);
if (result)
result = strncmp(buffer, text2, lstrlenA(text2) - 1); /* XP, win2k3 */
ok(result == 0,
"WM_GETTEXT: settext and gettext differ. strcmp: %d\n", result);
DestroyWindow(hwndRichEdit);
}
static void test_EM_GETTEXTRANGE(void)
{
HWND hwndRichEdit = new_richedit(NULL);
const char * text1 = "foo bar\r\nfoo bar";
const char * text2 = "foo bar\rfoo bar";
const char * expect = "bar\rfoo";
char buffer[1024] = {0};
LRESULT result;
TEXTRANGEA textRange;
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)text1);
textRange.lpstrText = buffer;
textRange.chrg.cpMin = 4;
textRange.chrg.cpMax = 11;
result = SendMessage(hwndRichEdit, EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
ok(result == 7, "EM_GETTEXTRANGE returned %ld\n", result);
ok(!strcmp(expect, buffer), "EM_GETTEXTRANGE filled %s\n", buffer);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)text2);
textRange.lpstrText = buffer;
textRange.chrg.cpMin = 4;
textRange.chrg.cpMax = 11;
result = SendMessage(hwndRichEdit, EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
ok(result == 7, "EM_GETTEXTRANGE returned %ld\n", result);
ok(!strcmp(expect, buffer), "EM_GETTEXTRANGE filled %s\n", buffer);
/* cpMax of text length is used instead of -1 in this case */
textRange.lpstrText = buffer;
textRange.chrg.cpMin = 0;
textRange.chrg.cpMax = -1;
result = SendMessage(hwndRichEdit, EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
ok(result == strlen(text2), "EM_GETTEXTRANGE returned %ld\n", result);
ok(!strcmp(text2, buffer), "EM_GETTEXTRANGE filled %s\n", buffer);
/* cpMin < 0 causes no text to be copied, and 0 to be returned */
textRange.lpstrText = buffer;
textRange.chrg.cpMin = -1;
textRange.chrg.cpMax = 1;
result = SendMessage(hwndRichEdit, EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
ok(result == 0, "EM_GETTEXTRANGE returned %ld\n", result);
ok(!strcmp(text2, buffer), "EM_GETTEXTRANGE filled %s\n", buffer);
/* cpMax of -1 is not replaced with text length if cpMin != 0 */
textRange.lpstrText = buffer;
textRange.chrg.cpMin = 1;
textRange.chrg.cpMax = -1;
result = SendMessage(hwndRichEdit, EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
ok(result == 0, "EM_GETTEXTRANGE returned %ld\n", result);
ok(!strcmp(text2, buffer), "EM_GETTEXTRANGE filled %s\n", buffer);
/* no end character is copied if cpMax - cpMin < 0 */
textRange.lpstrText = buffer;
textRange.chrg.cpMin = 5;
textRange.chrg.cpMax = 5;
result = SendMessage(hwndRichEdit, EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
ok(result == 0, "EM_GETTEXTRANGE returned %ld\n", result);
ok(!strcmp(text2, buffer), "EM_GETTEXTRANGE filled %s\n", buffer);
/* cpMax of text length is used if cpMax > text length*/
textRange.lpstrText = buffer;
textRange.chrg.cpMin = 0;
textRange.chrg.cpMax = 1000;
result = SendMessage(hwndRichEdit, EM_GETTEXTRANGE, 0, (LPARAM)&textRange);
ok(result == strlen(text2), "EM_GETTEXTRANGE returned %ld\n", result);
ok(!strcmp(text2, buffer), "EM_GETTEXTRANGE filled %s\n", buffer);
DestroyWindow(hwndRichEdit);
}
static void test_EM_GETSELTEXT(void)
{
HWND hwndRichEdit = new_richedit(NULL);
const char * text1 = "foo bar\r\nfoo bar";
const char * text2 = "foo bar\rfoo bar";
const char * expect = "bar\rfoo";
char buffer[1024] = {0};
LRESULT result;
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)text1);
SendMessage(hwndRichEdit, EM_SETSEL, 4, 11);
result = SendMessage(hwndRichEdit, EM_GETSELTEXT, 0, (LPARAM)buffer);
ok(result == 7, "EM_GETTEXTRANGE returned %ld\n", result);
ok(!strcmp(expect, buffer), "EM_GETTEXTRANGE filled %s\n", buffer);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)text2);
SendMessage(hwndRichEdit, EM_SETSEL, 4, 11);
result = SendMessage(hwndRichEdit, EM_GETSELTEXT, 0, (LPARAM)buffer);
ok(result == 7, "EM_GETTEXTRANGE returned %ld\n", result);
ok(!strcmp(expect, buffer), "EM_GETTEXTRANGE filled %s\n", buffer);
DestroyWindow(hwndRichEdit);
}
/* FIXME: need to test unimplemented options and robustly test wparam */
static void test_EM_SETOPTIONS(void)
{
HWND hwndRichEdit;
static const char text[] = "Hello. My name is RichEdit!";
char buffer[1024] = {0};
DWORD dwStyle, options, oldOptions;
DWORD optionStyles = ES_AUTOVSCROLL|ES_AUTOHSCROLL|ES_NOHIDESEL|
ES_READONLY|ES_WANTRETURN|ES_SAVESEL|
ES_SELECTIONBAR|ES_VERTICAL;
/* Test initial options. */
hwndRichEdit = CreateWindow(RICHEDIT_CLASS, NULL, WS_POPUP,
0, 0, 200, 60, NULL, NULL,
hmoduleRichEdit, NULL);
ok(hwndRichEdit != NULL, "class: %s, error: %d\n",
RICHEDIT_CLASS, (int) GetLastError());
options = SendMessage(hwndRichEdit, EM_GETOPTIONS, 0, 0);
ok(options == 0, "Incorrect initial options %x\n", options);
DestroyWindow(hwndRichEdit);
hwndRichEdit = CreateWindow(RICHEDIT_CLASS, NULL,
WS_POPUP|WS_HSCROLL|WS_VSCROLL|WS_VISIBLE,
0, 0, 200, 60, NULL, NULL,
hmoduleRichEdit, NULL);
ok(hwndRichEdit != NULL, "class: %s, error: %d\n",
RICHEDIT_CLASS, (int) GetLastError());
options = SendMessage(hwndRichEdit, EM_GETOPTIONS, 0, 0);
/* WS_[VH]SCROLL cause the ECO_AUTO[VH]SCROLL options to be set */
ok(options == (ECO_AUTOVSCROLL|ECO_AUTOHSCROLL),
"Incorrect initial options %x\n", options);
/* NEGATIVE TESTING - NO OPTIONS SET */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text);
SendMessage(hwndRichEdit, EM_SETOPTIONS, ECOOP_SET, 0);
/* testing no readonly by sending 'a' to the control*/
SendMessage(hwndRichEdit, WM_CHAR, 'a', 0x1E0001);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok(buffer[0]=='a',
"EM_SETOPTIONS: Text not changed! s1:%s s2:%s\n", text, buffer);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text);
/* READONLY - sending 'a' to the control */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text);
SendMessage(hwndRichEdit, EM_SETOPTIONS, ECOOP_SET, ECO_READONLY);
SendMessage(hwndRichEdit, WM_CHAR, 'a', 0x1E0001);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok(buffer[0]==text[0],
"EM_SETOPTIONS: Text changed! s1:%s s2:%s\n", text, buffer);
/* EM_SETOPTIONS changes the window style, but changing the
* window style does not change the options. */
dwStyle = GetWindowLong(hwndRichEdit, GWL_STYLE);
ok(dwStyle & ES_READONLY, "Readonly style not set by EM_SETOPTIONS\n");
SetWindowLong(hwndRichEdit, GWL_STYLE, dwStyle & ~ES_READONLY);
options = SendMessage(hwndRichEdit, EM_GETOPTIONS, 0, 0);
ok(options & ES_READONLY, "Readonly option set by SetWindowLong\n");
/* Confirm that the text is still read only. */
SendMessage(hwndRichEdit, WM_CHAR, 'a', ('a' << 16) | 0x0001);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok(buffer[0]==text[0],
"EM_SETOPTIONS: Text changed! s1:%s s2:%s\n", text, buffer);
oldOptions = options;
SetWindowLong(hwndRichEdit, GWL_STYLE, dwStyle|optionStyles);
options = SendMessage(hwndRichEdit, EM_GETOPTIONS, 0, 0);
ok(options == oldOptions,
"Options set by SetWindowLong (%x -> %x)\n", oldOptions, options);
DestroyWindow(hwndRichEdit);
}
static int check_CFE_LINK_selection(HWND hwnd, int sel_start, int sel_end)
{
CHARFORMAT2W text_format;
text_format.cbSize = sizeof(text_format);
SendMessage(hwnd, EM_SETSEL, sel_start, sel_end);
SendMessage(hwnd, EM_GETCHARFORMAT, SCF_SELECTION, (LPARAM) &text_format);
return (text_format.dwEffects & CFE_LINK) ? 1 : 0;
}
static void check_CFE_LINK_rcvd(HWND hwnd, int is_url, const char * url)
{
int link_present = 0;
link_present = check_CFE_LINK_selection(hwnd, 0, 1);
if (is_url)
{ /* control text is url; should get CFE_LINK */
ok(0 != link_present, "URL Case: CFE_LINK not set for [%s].\n", url);
}
else
{
ok(0 == link_present, "Non-URL Case: CFE_LINK set for [%s].\n", url);
}
}
static HWND new_static_wnd(HWND parent) {
return new_window("Static", 0, parent);
}
static void test_EM_AUTOURLDETECT(void)
{
/* DO NOT change the properties of the first two elements. To shorten the
tests, all tests after WM_SETTEXT test just the first two elements -
one non-URL and one URL */
struct urls_s {
const char *text;
int is_url;
} urls[12] = {
{"winehq.org", 0},
{"http://www.winehq.org", 1},
{"http//winehq.org", 0},
{"ww.winehq.org", 0},
{"www.winehq.org", 1},
{"ftp://192.168.1.1", 1},
{"ftp//192.168.1.1", 0},
{"mailto:your@email.com", 1},
{"prospero:prosperoserver", 1},
{"telnet:test", 1},
{"news:newserver", 1},
{"wais:waisserver", 1}
};
int i, j;
int urlRet=-1;
HWND hwndRichEdit, parent;
/* All of the following should cause the URL to be detected */
const char * templates_delim[] = {
"This is some text with X on it",
"This is some text with (X) on it",
"This is some text with X\r on it",
"This is some text with ---X--- on it",
"This is some text with \"X\" on it",
"This is some text with 'X' on it",
"This is some text with 'X' on it",
"This is some text with :X: on it",
"This text ends with X",
"This is some text with X) on it",
"This is some text with X--- on it",
"This is some text with X\" on it",
"This is some text with X' on it",
"This is some text with X: on it",
"This is some text with (X on it",
"This is some text with \rX on it",
"This is some text with ---X on it",
"This is some text with \"X on it",
"This is some text with 'X on it",
"This is some text with :X on it",
};
/* None of these should cause the URL to be detected */
const char * templates_non_delim[] = {
"This is some text with |X| on it",
"This is some text with *X* on it",
"This is some text with /X/ on it",
"This is some text with +X+ on it",
"This is some text with %X% on it",
"This is some text with #X# on it",
"This is some text with @X@ on it",
"This is some text with \\X\\ on it",
"This is some text with |X on it",
"This is some text with *X on it",
"This is some text with /X on it",
"This is some text with +X on it",
"This is some text with %X on it",
"This is some text with #X on it",
"This is some text with @X on it",
"This is some text with \\X on it",
};
/* All of these cause the URL detection to be extended by one more byte,
thus demonstrating that the tested character is considered as part
of the URL. */
const char * templates_xten_delim[] = {
"This is some text with X| on it",
"This is some text with X* on it",
"This is some text with X/ on it",
"This is some text with X+ on it",
"This is some text with X% on it",
"This is some text with X# on it",
"This is some text with X@ on it",
"This is some text with X\\ on it",
};
char buffer[1024];
parent = new_static_wnd(NULL);
hwndRichEdit = new_richedit(parent);
/* Try and pass EM_AUTOURLDETECT some test wParam values */
urlRet=SendMessage(hwndRichEdit, EM_AUTOURLDETECT, FALSE, 0);
ok(urlRet==0, "Good wParam: urlRet is: %d\n", urlRet);
urlRet=SendMessage(hwndRichEdit, EM_AUTOURLDETECT, 1, 0);
ok(urlRet==0, "Good wParam2: urlRet is: %d\n", urlRet);
/* Windows returns -2147024809 (0x80070057) on bad wParam values */
urlRet=SendMessage(hwndRichEdit, EM_AUTOURLDETECT, 8, 0);
ok(urlRet==E_INVALIDARG, "Bad wParam: urlRet is: %d\n", urlRet);
urlRet=SendMessage(hwndRichEdit, EM_AUTOURLDETECT, (WPARAM)"h", (LPARAM)"h");
ok(urlRet==E_INVALIDARG, "Bad wParam2: urlRet is: %d\n", urlRet);
/* for each url, check the text to see if CFE_LINK effect is present */
for (i = 0; i < sizeof(urls)/sizeof(struct urls_s); i++) {
SendMessage(hwndRichEdit, EM_AUTOURLDETECT, FALSE, 0);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) urls[i].text);
check_CFE_LINK_rcvd(hwndRichEdit, 0, urls[i].text);
/* Link detection should happen immediately upon WM_SETTEXT */
SendMessage(hwndRichEdit, EM_AUTOURLDETECT, TRUE, 0);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) urls[i].text);
check_CFE_LINK_rcvd(hwndRichEdit, urls[i].is_url, urls[i].text);
}
DestroyWindow(hwndRichEdit);
/* Test detection of URLs within normal text - WM_SETTEXT case. */
for (i = 0; i < sizeof(urls)/sizeof(struct urls_s); i++) {
hwndRichEdit = new_richedit(parent);
for (j = 0; j < sizeof(templates_delim) / sizeof(const char *); j++) {
char * at_pos;
int at_offset;
int end_offset;
at_pos = strchr(templates_delim[j], 'X');
at_offset = at_pos - templates_delim[j];
strncpy(buffer, templates_delim[j], at_offset);
buffer[at_offset] = '\0';
strcat(buffer, urls[i].text);
strcat(buffer, templates_delim[j] + at_offset + 1);
end_offset = at_offset + strlen(urls[i].text);
SendMessage(hwndRichEdit, EM_AUTOURLDETECT, TRUE, 0);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) buffer);
/* This assumes no templates start with the URL itself, and that they
have at least two characters before the URL text */
ok(!check_CFE_LINK_selection(hwndRichEdit, 0, 1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -2, at_offset -1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -2, at_offset -1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -1, at_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -1, at_offset, buffer);
if (urls[i].is_url)
{
ok(check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK not set in (%d-%d), text: %s\n", at_offset, at_offset +1, buffer);
ok(check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK not set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
else
{
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset, at_offset + 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
if (buffer[end_offset] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset, end_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset, end_offset + 1, buffer);
if (buffer[end_offset +1] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset +1, end_offset +2),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset +1, end_offset +2, buffer);
}
}
}
for (j = 0; j < sizeof(templates_non_delim) / sizeof(const char *); j++) {
char * at_pos;
int at_offset;
int end_offset;
at_pos = strchr(templates_non_delim[j], 'X');
at_offset = at_pos - templates_non_delim[j];
strncpy(buffer, templates_non_delim[j], at_offset);
buffer[at_offset] = '\0';
strcat(buffer, urls[i].text);
strcat(buffer, templates_non_delim[j] + at_offset + 1);
end_offset = at_offset + strlen(urls[i].text);
SendMessage(hwndRichEdit, EM_AUTOURLDETECT, TRUE, 0);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) buffer);
/* This assumes no templates start with the URL itself, and that they
have at least two characters before the URL text */
ok(!check_CFE_LINK_selection(hwndRichEdit, 0, 1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -2, at_offset -1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -2, at_offset -1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -1, at_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -1, at_offset, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset, at_offset + 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
if (buffer[end_offset] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset, end_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset, end_offset + 1, buffer);
if (buffer[end_offset +1] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset +1, end_offset +2),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset +1, end_offset +2, buffer);
}
}
}
for (j = 0; j < sizeof(templates_xten_delim) / sizeof(const char *); j++) {
char * at_pos;
int at_offset;
int end_offset;
at_pos = strchr(templates_xten_delim[j], 'X');
at_offset = at_pos - templates_xten_delim[j];
strncpy(buffer, templates_xten_delim[j], at_offset);
buffer[at_offset] = '\0';
strcat(buffer, urls[i].text);
strcat(buffer, templates_xten_delim[j] + at_offset + 1);
end_offset = at_offset + strlen(urls[i].text);
SendMessage(hwndRichEdit, EM_AUTOURLDETECT, TRUE, 0);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) buffer);
/* This assumes no templates start with the URL itself, and that they
have at least two characters before the URL text */
ok(!check_CFE_LINK_selection(hwndRichEdit, 0, 1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -2, at_offset -1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -2, at_offset -1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -1, at_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -1, at_offset, buffer);
if (urls[i].is_url)
{
ok(check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK not set in (%d-%d), text: %s\n", at_offset, at_offset +1, buffer);
ok(check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK not set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
ok(check_CFE_LINK_selection(hwndRichEdit, end_offset, end_offset +1),
"CFE_LINK not set in (%d-%d), text: %s\n", end_offset, end_offset +1, buffer);
}
else
{
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset, at_offset + 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset, end_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset, end_offset +1, buffer);
}
if (buffer[end_offset +1] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset +1, end_offset +2),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset +1, end_offset + 2, buffer);
if (buffer[end_offset +2] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset +2, end_offset +3),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset +2, end_offset +3, buffer);
}
}
}
DestroyWindow(hwndRichEdit);
hwndRichEdit = NULL;
}
/* Test detection of URLs within normal text - WM_CHAR case. */
/* Test only the first two URL examples for brevity */
for (i = 0; i < 2; i++) {
hwndRichEdit = new_richedit(parent);
/* Also for brevity, test only the first three delimiters */
for (j = 0; j < 3; j++) {
char * at_pos;
int at_offset;
int end_offset;
int u, v;
at_pos = strchr(templates_delim[j], 'X');
at_offset = at_pos - templates_delim[j];
end_offset = at_offset + strlen(urls[i].text);
SendMessage(hwndRichEdit, EM_AUTOURLDETECT, TRUE, 0);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
for (u = 0; templates_delim[j][u]; u++) {
if (templates_delim[j][u] == '\r') {
simulate_typing_characters(hwndRichEdit, "\r");
} else if (templates_delim[j][u] != 'X') {
SendMessage(hwndRichEdit, WM_CHAR, templates_delim[j][u], 1);
} else {
for (v = 0; urls[i].text[v]; v++) {
SendMessage(hwndRichEdit, WM_CHAR, urls[i].text[v], 1);
}
}
}
SendMessage(hwndRichEdit, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
/* This assumes no templates start with the URL itself, and that they
have at least two characters before the URL text */
ok(!check_CFE_LINK_selection(hwndRichEdit, 0, 1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -2, at_offset -1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -2, at_offset -1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -1, at_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -1, at_offset, buffer);
if (urls[i].is_url)
{
ok(check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK not set in (%d-%d), text: %s\n", at_offset, at_offset +1, buffer);
ok(check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK not set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
else
{
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset, at_offset + 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
if (buffer[end_offset] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset, end_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset, end_offset + 1, buffer);
if (buffer[end_offset +1] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset +1, end_offset +2),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset +1, end_offset +2, buffer);
}
}
/* The following will insert a paragraph break after the first character
of the URL candidate, thus breaking the URL. It is expected that the
CFE_LINK attribute should break across both pieces of the URL */
SendMessage(hwndRichEdit, EM_SETSEL, at_offset+1, at_offset+1);
simulate_typing_characters(hwndRichEdit, "\r");
SendMessage(hwndRichEdit, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, 0, 1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -2, at_offset -1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -2, at_offset -1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -1, at_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -1, at_offset, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset, at_offset + 1, buffer);
/* end_offset moved because of paragraph break */
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset, end_offset+1, buffer);
ok(buffer[end_offset], "buffer \"%s\" ended prematurely. Is it missing a newline character?\n", buffer);
if (buffer[end_offset] != 0 && buffer[end_offset+1] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset+1, end_offset +2),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset+1, end_offset +2, buffer);
if (buffer[end_offset +2] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset +2, end_offset +3),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset +2, end_offset +3, buffer);
}
}
/* The following will remove the just-inserted paragraph break, thus
restoring the URL */
SendMessage(hwndRichEdit, EM_SETSEL, at_offset+2, at_offset+2);
simulate_typing_characters(hwndRichEdit, "\b");
SendMessage(hwndRichEdit, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, 0, 1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -2, at_offset -1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -2, at_offset -1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -1, at_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -1, at_offset, buffer);
if (urls[i].is_url)
{
ok(check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK not set in (%d-%d), text: %s\n", at_offset, at_offset +1, buffer);
ok(check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK not set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
else
{
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset, at_offset + 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
if (buffer[end_offset] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset, end_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset, end_offset + 1, buffer);
if (buffer[end_offset +1] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset +1, end_offset +2),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset +1, end_offset +2, buffer);
}
}
}
DestroyWindow(hwndRichEdit);
hwndRichEdit = NULL;
}
/* Test detection of URLs within normal text - EM_SETTEXTEX case. */
/* Test just the first two URL examples for brevity */
for (i = 0; i < 2; i++) {
SETTEXTEX st;
hwndRichEdit = new_richedit(parent);
/* There are at least three ways in which EM_SETTEXTEX must cause URLs to
be detected:
1) Set entire text, a la WM_SETTEXT
2) Set a selection of the text to the URL
3) Set a portion of the text at a time, which eventually results in
an URL
All of them should give equivalent results
*/
/* Set entire text in one go, like WM_SETTEXT */
for (j = 0; j < sizeof(templates_delim) / sizeof(const char *); j++) {
char * at_pos;
int at_offset;
int end_offset;
st.codepage = CP_ACP;
st.flags = ST_DEFAULT;
at_pos = strchr(templates_delim[j], 'X');
at_offset = at_pos - templates_delim[j];
strncpy(buffer, templates_delim[j], at_offset);
buffer[at_offset] = '\0';
strcat(buffer, urls[i].text);
strcat(buffer, templates_delim[j] + at_offset + 1);
end_offset = at_offset + strlen(urls[i].text);
SendMessage(hwndRichEdit, EM_AUTOURLDETECT, TRUE, 0);
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&st, (LPARAM) buffer);
/* This assumes no templates start with the URL itself, and that they
have at least two characters before the URL text */
ok(!check_CFE_LINK_selection(hwndRichEdit, 0, 1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -2, at_offset -1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -2, at_offset -1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -1, at_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -1, at_offset, buffer);
if (urls[i].is_url)
{
ok(check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK not set in (%d-%d), text: %s\n", at_offset, at_offset +1, buffer);
ok(check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK not set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
else
{
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset, at_offset + 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
if (buffer[end_offset] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset, end_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset, end_offset + 1, buffer);
if (buffer[end_offset +1] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset +1, end_offset +2),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset +1, end_offset +2, buffer);
}
}
}
/* Set selection with X to the URL */
for (j = 0; j < sizeof(templates_delim) / sizeof(const char *); j++) {
char * at_pos;
int at_offset;
int end_offset;
at_pos = strchr(templates_delim[j], 'X');
at_offset = at_pos - templates_delim[j];
end_offset = at_offset + strlen(urls[i].text);
st.codepage = CP_ACP;
st.flags = ST_DEFAULT;
SendMessage(hwndRichEdit, EM_AUTOURLDETECT, TRUE, 0);
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&st, (LPARAM) templates_delim[j]);
st.flags = ST_SELECTION;
SendMessage(hwndRichEdit, EM_SETSEL, at_offset, at_offset+1);
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&st, (LPARAM) urls[i].text);
SendMessage(hwndRichEdit, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
/* This assumes no templates start with the URL itself, and that they
have at least two characters before the URL text */
ok(!check_CFE_LINK_selection(hwndRichEdit, 0, 1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -2, at_offset -1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -2, at_offset -1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -1, at_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -1, at_offset, buffer);
if (urls[i].is_url)
{
ok(check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK not set in (%d-%d), text: %s\n", at_offset, at_offset +1, buffer);
ok(check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK not set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
else
{
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset, at_offset + 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
if (buffer[end_offset] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset, end_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset, end_offset + 1, buffer);
if (buffer[end_offset +1] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset +1, end_offset +2),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset +1, end_offset +2, buffer);
}
}
}
/* Set selection with X to the first character of the URL, then the rest */
for (j = 0; j < sizeof(templates_delim) / sizeof(const char *); j++) {
char * at_pos;
int at_offset;
int end_offset;
at_pos = strchr(templates_delim[j], 'X');
at_offset = at_pos - templates_delim[j];
end_offset = at_offset + strlen(urls[i].text);
strcpy(buffer, "YY");
buffer[0] = urls[i].text[0];
st.codepage = CP_ACP;
st.flags = ST_DEFAULT;
SendMessage(hwndRichEdit, EM_AUTOURLDETECT, TRUE, 0);
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&st, (LPARAM) templates_delim[j]);
st.flags = ST_SELECTION;
SendMessage(hwndRichEdit, EM_SETSEL, at_offset, at_offset+1);
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&st, (LPARAM) buffer);
SendMessage(hwndRichEdit, EM_SETSEL, at_offset+1, at_offset+2);
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&st, (LPARAM)(urls[i].text + 1));
SendMessage(hwndRichEdit, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
/* This assumes no templates start with the URL itself, and that they
have at least two characters before the URL text */
ok(!check_CFE_LINK_selection(hwndRichEdit, 0, 1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -2, at_offset -1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -2, at_offset -1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -1, at_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -1, at_offset, buffer);
if (urls[i].is_url)
{
ok(check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK not set in (%d-%d), text: %s\n", at_offset, at_offset +1, buffer);
ok(check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK not set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
else
{
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset, at_offset + 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
if (buffer[end_offset] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset, end_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset, end_offset + 1, buffer);
if (buffer[end_offset +1] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset +1, end_offset +2),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset +1, end_offset +2, buffer);
}
}
}
DestroyWindow(hwndRichEdit);
hwndRichEdit = NULL;
}
/* Test detection of URLs within normal text - EM_REPLACESEL case. */
/* Test just the first two URL examples for brevity */
for (i = 0; i < 2; i++) {
hwndRichEdit = new_richedit(parent);
/* Set selection with X to the URL */
for (j = 0; j < sizeof(templates_delim) / sizeof(const char *); j++) {
char * at_pos;
int at_offset;
int end_offset;
at_pos = strchr(templates_delim[j], 'X');
at_offset = at_pos - templates_delim[j];
end_offset = at_offset + strlen(urls[i].text);
SendMessage(hwndRichEdit, EM_AUTOURLDETECT, TRUE, 0);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) templates_delim[j]);
SendMessage(hwndRichEdit, EM_SETSEL, at_offset, at_offset+1);
SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM) urls[i].text);
SendMessage(hwndRichEdit, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
/* This assumes no templates start with the URL itself, and that they
have at least two characters before the URL text */
ok(!check_CFE_LINK_selection(hwndRichEdit, 0, 1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -2, at_offset -1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -2, at_offset -1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -1, at_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -1, at_offset, buffer);
if (urls[i].is_url)
{
ok(check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK not set in (%d-%d), text: %s\n", at_offset, at_offset +1, buffer);
ok(check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK not set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
else
{
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset, at_offset + 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
if (buffer[end_offset] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset, end_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset, end_offset + 1, buffer);
if (buffer[end_offset +1] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset +1, end_offset +2),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset +1, end_offset +2, buffer);
}
}
}
/* Set selection with X to the first character of the URL, then the rest */
for (j = 0; j < sizeof(templates_delim) / sizeof(const char *); j++) {
char * at_pos;
int at_offset;
int end_offset;
at_pos = strchr(templates_delim[j], 'X');
at_offset = at_pos - templates_delim[j];
end_offset = at_offset + strlen(urls[i].text);
strcpy(buffer, "YY");
buffer[0] = urls[i].text[0];
SendMessage(hwndRichEdit, EM_AUTOURLDETECT, TRUE, 0);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) templates_delim[j]);
SendMessage(hwndRichEdit, EM_SETSEL, at_offset, at_offset+1);
SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM) buffer);
SendMessage(hwndRichEdit, EM_SETSEL, at_offset+1, at_offset+2);
SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM)(urls[i].text + 1));
SendMessage(hwndRichEdit, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
/* This assumes no templates start with the URL itself, and that they
have at least two characters before the URL text */
ok(!check_CFE_LINK_selection(hwndRichEdit, 0, 1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", 0, 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -2, at_offset -1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -2, at_offset -1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset -1, at_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset -1, at_offset, buffer);
if (urls[i].is_url)
{
ok(check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK not set in (%d-%d), text: %s\n", at_offset, at_offset +1, buffer);
ok(check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK not set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
else
{
ok(!check_CFE_LINK_selection(hwndRichEdit, at_offset, at_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", at_offset, at_offset + 1, buffer);
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset -1, end_offset),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset -1, end_offset, buffer);
}
if (buffer[end_offset] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset, end_offset +1),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset, end_offset + 1, buffer);
if (buffer[end_offset +1] != '\0')
{
ok(!check_CFE_LINK_selection(hwndRichEdit, end_offset +1, end_offset +2),
"CFE_LINK incorrectly set in (%d-%d), text: %s\n", end_offset +1, end_offset +2, buffer);
}
}
}
DestroyWindow(hwndRichEdit);
hwndRichEdit = NULL;
}
DestroyWindow(parent);
}
static void test_EM_SCROLL(void)
{
int i, j;
int r; /* return value */
int expr; /* expected return value */
HWND hwndRichEdit = new_richedit(NULL);
int y_before, y_after; /* units of lines of text */
/* test a richedit box containing a single line of text */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "a");/* one line of text */
expr = 0x00010000;
for (i = 0; i < 4; i++) {
static const int cmd[4] = { SB_PAGEDOWN, SB_PAGEUP, SB_LINEDOWN, SB_LINEUP };
r = SendMessage(hwndRichEdit, EM_SCROLL, cmd[i], 0);
y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
ok(expr == r, "EM_SCROLL improper return value returned (i == %d). "
"Got 0x%08x, expected 0x%08x\n", i, r, expr);
ok(y_after == 0, "EM_SCROLL improper scroll. scrolled to line %d, not 1 "
"(i == %d)\n", y_after, i);
}
/*
* test a richedit box that will scroll. There are two general
* cases: the case without any long lines and the case with a long
* line.
*/
for (i = 0; i < 2; i++) { /* iterate through different bodies of text */
if (i == 0)
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "a\nb\nc\nd\ne");
else
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)
"a LONG LINE LONG LINE LONG LINE LONG LINE LONG LINE "
"LONG LINE LONG LINE LONG LINE LONG LINE LONG LINE "
"LONG LINE \nb\nc\nd\ne");
for (j = 0; j < 12; j++) /* reset scroll position to top */
SendMessage(hwndRichEdit, EM_SCROLL, SB_PAGEUP, 0);
/* get first visible line */
y_before = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
r = SendMessage(hwndRichEdit, EM_SCROLL, SB_PAGEDOWN, 0); /* page down */
/* get new current first visible line */
y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
ok(((r & 0xffffff00) == 0x00010000) &&
((r & 0x000000ff) != 0x00000000),
"EM_SCROLL page down didn't scroll by a small positive number of "
"lines (r == 0x%08x)\n", r);
ok(y_after > y_before, "EM_SCROLL page down not functioning "
"(line %d scrolled to line %d\n", y_before, y_after);
y_before = y_after;
r = SendMessage(hwndRichEdit, EM_SCROLL, SB_PAGEUP, 0); /* page up */
y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
ok(((r & 0xffffff00) == 0x0001ff00),
"EM_SCROLL page up didn't scroll by a small negative number of lines "
"(r == 0x%08x)\n", r);
ok(y_after < y_before, "EM_SCROLL page up not functioning (line "
"%d scrolled to line %d\n", y_before, y_after);
y_before = y_after;
r = SendMessage(hwndRichEdit, EM_SCROLL, SB_LINEDOWN, 0); /* line down */
y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
ok(r == 0x00010001, "EM_SCROLL line down didn't scroll by one line "
"(r == 0x%08x)\n", r);
ok(y_after -1 == y_before, "EM_SCROLL line down didn't go down by "
"1 line (%d scrolled to %d)\n", y_before, y_after);
y_before = y_after;
r = SendMessage(hwndRichEdit, EM_SCROLL, SB_LINEUP, 0); /* line up */
y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
ok(r == 0x0001ffff, "EM_SCROLL line up didn't scroll by one line "
"(r == 0x%08x)\n", r);
ok(y_after +1 == y_before, "EM_SCROLL line up didn't go up by 1 "
"line (%d scrolled to %d)\n", y_before, y_after);
y_before = y_after;
r = SendMessage(hwndRichEdit, EM_SCROLL,
SB_LINEUP, 0); /* lineup beyond top */
y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
ok(r == 0x00010000,
"EM_SCROLL line up returned indicating movement (0x%08x)\n", r);
ok(y_before == y_after,
"EM_SCROLL line up beyond top worked (%d)\n", y_after);
y_before = y_after;
r = SendMessage(hwndRichEdit, EM_SCROLL,
SB_PAGEUP, 0);/*page up beyond top */
y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
ok(r == 0x00010000,
"EM_SCROLL page up returned indicating movement (0x%08x)\n", r);
ok(y_before == y_after,
"EM_SCROLL page up beyond top worked (%d)\n", y_after);
for (j = 0; j < 12; j++) /* page down all the way to the bottom */
SendMessage(hwndRichEdit, EM_SCROLL, SB_PAGEDOWN, 0);
y_before = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
r = SendMessage(hwndRichEdit, EM_SCROLL,
SB_PAGEDOWN, 0); /* page down beyond bot */
y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
ok(r == 0x00010000,
"EM_SCROLL page down returned indicating movement (0x%08x)\n", r);
ok(y_before == y_after,
"EM_SCROLL page down beyond bottom worked (%d -> %d)\n",
y_before, y_after);
y_before = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
SendMessage(hwndRichEdit, EM_SCROLL,
SB_LINEDOWN, 0); /* line down beyond bot */
y_after = SendMessage(hwndRichEdit, EM_GETFIRSTVISIBLELINE, 0, 0);
ok(r == 0x00010000,
"EM_SCROLL line down returned indicating movement (0x%08x)\n", r);
ok(y_before == y_after,
"EM_SCROLL line down beyond bottom worked (%d -> %d)\n",
y_before, y_after);
}
DestroyWindow(hwndRichEdit);
}
static unsigned int recursionLevel = 0;
static unsigned int WM_SIZE_recursionLevel = 0;
static BOOL bailedOutOfRecursion = FALSE;
static LRESULT (WINAPI *richeditProc)(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
static LRESULT WINAPI RicheditStupidOverrideProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT r;
if (bailedOutOfRecursion) return 0;
if (recursionLevel >= 32) {
bailedOutOfRecursion = TRUE;
return 0;
}
recursionLevel++;
switch (message) {
case WM_SIZE:
WM_SIZE_recursionLevel++;
r = richeditProc(hwnd, message, wParam, lParam);
/* Because, uhhhh... I never heard of ES_DISABLENOSCROLL */
ShowScrollBar(hwnd, SB_VERT, TRUE);
WM_SIZE_recursionLevel--;
break;
default:
r = richeditProc(hwnd, message, wParam, lParam);
break;
}
recursionLevel--;
return r;
}
static void test_scrollbar_visibility(void)
{
HWND hwndRichEdit;
const char * text="a\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\na\n";
SCROLLINFO si;
WNDCLASSA cls;
BOOL r;
/* These tests show that richedit should temporarily refrain from automatically
hiding or showing its scrollbars (vertical at least) when an explicit request
is made via ShowScrollBar() or similar, outside of standard richedit logic.
Some applications depend on forced showing (when otherwise richedit would
hide the vertical scrollbar) and are thrown on an endless recursive loop
if richedit auto-hides the scrollbar again. Apparently they never heard of
the ES_DISABLENOSCROLL style... */
hwndRichEdit = new_richedit(NULL);
/* Test default scrollbar visibility behavior */
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage == 0 && si.nMin == 0 && (si.nMax == 0 || si.nMax == 100),
"reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage == 0 && si.nMin == 0 && (si.nMax == 0 || si.nMax == 100),
"reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)text);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
si.nPage, si.nMin, si.nMax);
/* Oddly, setting text to NULL does *not* reset the scrollbar range,
even though it hides the scrollbar */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
si.nPage, si.nMin, si.nMax);
/* Setting non-scrolling text again does *not* reset scrollbar range */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"a");
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"a");
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"");
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
si.nPage, si.nMin, si.nMax);
DestroyWindow(hwndRichEdit);
/* Test again, with ES_DISABLENOSCROLL style */
hwndRichEdit = new_window(RICHEDIT_CLASS, ES_MULTILINE|ES_DISABLENOSCROLL, NULL);
/* Test default scrollbar visibility behavior */
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage == 0 && si.nMin == 0 && si.nMax == 1,
"reported page/range is %d (%d..%d) expected 0 (0..1)\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage == 0 && si.nMin == 0 && si.nMax == 1,
"reported page/range is %d (%d..%d) expected 0 (0..1)\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)text);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax > 1,
"reported page/range is %d (%d..%d)\n",
si.nPage, si.nMin, si.nMax);
/* Oddly, setting text to NULL does *not* reset the scrollbar range */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax > 1,
"reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
si.nPage, si.nMin, si.nMax);
/* Setting non-scrolling text again does *not* reset scrollbar range */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"a");
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax > 1,
"reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax > 1,
"reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"a");
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax > 1,
"reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"");
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax > 1,
"reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
si.nPage, si.nMin, si.nMax);
DestroyWindow(hwndRichEdit);
/* Test behavior with explicit visibility request, using ShowScrollBar() */
hwndRichEdit = new_richedit(NULL);
/* Previously failed because builtin incorrectly re-hides scrollbar forced visible */
ShowScrollBar(hwndRichEdit, SB_VERT, TRUE);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
todo_wine {
ok(si.nPage == 0 && si.nMin == 0 && si.nMax == 100,
"reported page/range is %d (%d..%d) expected 0 (0..100)\n",
si.nPage, si.nMin, si.nMax);
}
/* Ditto, see above */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
todo_wine {
ok(si.nPage == 0 && si.nMin == 0 && si.nMax == 100,
"reported page/range is %d (%d..%d) expected 0 (0..100)\n",
si.nPage, si.nMin, si.nMax);
}
/* Ditto, see above */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"a");
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
todo_wine {
ok(si.nPage == 0 && si.nMin == 0 && si.nMax == 100,
"reported page/range is %d (%d..%d) expected 0 (0..100)\n",
si.nPage, si.nMin, si.nMax);
}
/* Ditto, see above */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"a\na");
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
todo_wine {
ok(si.nPage == 0 && si.nMin == 0 && si.nMax == 100,
"reported page/range is %d (%d..%d) expected 0 (0..100)\n",
si.nPage, si.nMin, si.nMax);
}
/* Ditto, see above */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
todo_wine {
ok(si.nPage == 0 && si.nMin == 0 && si.nMax == 100,
"reported page/range is %d (%d..%d) expected 0 (0..100)\n",
si.nPage, si.nMin, si.nMax);
}
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)text);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
si.nPage, si.nMin, si.nMax);
DestroyWindow(hwndRichEdit);
hwndRichEdit = new_richedit(NULL);
ShowScrollBar(hwndRichEdit, SB_VERT, FALSE);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage == 0 && si.nMin == 0 && (si.nMax == 0 || si.nMax == 100),
"reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage == 0 && si.nMin == 0 && (si.nMax == 0 || si.nMax == 100),
"reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"a");
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage == 0 && si.nMin == 0 && (si.nMax == 0 || si.nMax == 100),
"reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage == 0 && si.nMin == 0 && (si.nMax == 0 || si.nMax == 100),
"reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)text);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d)\n",
si.nPage, si.nMin, si.nMax);
/* Previously, builtin incorrectly re-shows explicitly hidden scrollbar */
ShowScrollBar(hwndRichEdit, SB_VERT, FALSE);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d)\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)text);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d)\n",
si.nPage, si.nMin, si.nMax);
/* Testing effect of EM_SCROLL on scrollbar visibility. It seems that
EM_SCROLL will make visible any forcefully invisible scrollbar */
SendMessage(hwndRichEdit, EM_SCROLL, SB_LINEDOWN, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d)\n",
si.nPage, si.nMin, si.nMax);
ShowScrollBar(hwndRichEdit, SB_VERT, FALSE);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d)\n",
si.nPage, si.nMin, si.nMax);
/* Again, EM_SCROLL, with SB_LINEUP */
SendMessage(hwndRichEdit, EM_SCROLL, SB_LINEUP, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d)\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)text);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d)\n",
si.nPage, si.nMin, si.nMax);
DestroyWindow(hwndRichEdit);
/* Test behavior with explicit visibility request, using SetWindowLong()() */
hwndRichEdit = new_richedit(NULL);
#define ENABLE_WS_VSCROLL(hwnd) \
SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) | WS_VSCROLL)
#define DISABLE_WS_VSCROLL(hwnd) \
SetWindowLongA(hwnd, GWL_STYLE, GetWindowLongA(hwnd, GWL_STYLE) & ~WS_VSCROLL)
/* Previously failed because builtin incorrectly re-hides scrollbar forced visible */
ENABLE_WS_VSCROLL(hwndRichEdit);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage == 0 && si.nMin == 0 && (si.nMax == 0 || si.nMax == 100),
"reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
si.nPage, si.nMin, si.nMax);
/* Ditto, see above */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage == 0 && si.nMin == 0 && (si.nMax == 0 || si.nMax == 100),
"reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
si.nPage, si.nMin, si.nMax);
/* Ditto, see above */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"a");
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage == 0 && si.nMin == 0 && (si.nMax == 0 || si.nMax == 100),
"reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
si.nPage, si.nMin, si.nMax);
/* Ditto, see above */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"a\na");
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage == 0 && si.nMin == 0 && (si.nMax == 0 || si.nMax == 100),
"reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
si.nPage, si.nMin, si.nMax);
/* Ditto, see above */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage == 0 && si.nMin == 0 && (si.nMax == 0 || si.nMax == 100),
"reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)text);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
si.nPage, si.nMin, si.nMax);
DestroyWindow(hwndRichEdit);
hwndRichEdit = new_richedit(NULL);
DISABLE_WS_VSCROLL(hwndRichEdit);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage == 0 && si.nMin == 0 && (si.nMax == 0 || si.nMax == 100),
"reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage == 0 && si.nMin == 0 && (si.nMax == 0 || si.nMax == 100),
"reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"a");
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage == 0 && si.nMin == 0 && (si.nMax == 0 || si.nMax == 100),
"reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage == 0 && si.nMin == 0 && (si.nMax == 0 || si.nMax == 100),
"reported page/range is %d (%d..%d) expected all 0 or nMax=100\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)text);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d)\n",
si.nPage, si.nMin, si.nMax);
/* Previously, builtin incorrectly re-shows explicitly hidden scrollbar */
DISABLE_WS_VSCROLL(hwndRichEdit);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d)\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d) expected nMax/nPage nonzero\n",
si.nPage, si.nMin, si.nMax);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)text);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d)\n",
si.nPage, si.nMin, si.nMax);
DISABLE_WS_VSCROLL(hwndRichEdit);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d)\n",
si.nPage, si.nMin, si.nMax);
/* Testing effect of EM_SCROLL on scrollbar visibility. It seems that
EM_SCROLL will make visible any forcefully invisible scrollbar */
SendMessage(hwndRichEdit, EM_SCROLL, SB_LINEDOWN, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d)\n",
si.nPage, si.nMin, si.nMax);
DISABLE_WS_VSCROLL(hwndRichEdit);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) == 0),
"Vertical scrollbar is visible, should be invisible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d)\n",
si.nPage, si.nMin, si.nMax);
/* Again, EM_SCROLL, with SB_LINEUP */
SendMessage(hwndRichEdit, EM_SCROLL, SB_LINEUP, 0);
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si);
si.fMask = SIF_PAGE | SIF_RANGE;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok (((GetWindowLongA(hwndRichEdit, GWL_STYLE) & WS_VSCROLL) != 0),
"Vertical scrollbar is invisible, should be visible.\n");
ok(si.nPage != 0 && si.nMin == 0 && si.nMax != 0,
"reported page/range is %d (%d..%d)\n",
si.nPage, si.nMin, si.nMax);
DestroyWindow(hwndRichEdit);
/* This window proc models what is going on with Corman Lisp 3.0.
At WM_SIZE, this proc unconditionally calls ShowScrollBar() to
force the scrollbar into visibility. Recursion should NOT happen
as a result of this action.
*/
r = GetClassInfoA(NULL, RICHEDIT_CLASS, &cls);
if (r) {
richeditProc = cls.lpfnWndProc;
cls.lpfnWndProc = RicheditStupidOverrideProcA;
cls.lpszClassName = "RicheditStupidOverride";
if(!RegisterClassA(&cls)) assert(0);
recursionLevel = 0;
WM_SIZE_recursionLevel = 0;
bailedOutOfRecursion = FALSE;
hwndRichEdit = new_window(cls.lpszClassName, ES_MULTILINE, NULL);
ok(!bailedOutOfRecursion,
"WM_SIZE/scrollbar mutual recursion detected, expected none!\n");
recursionLevel = 0;
WM_SIZE_recursionLevel = 0;
bailedOutOfRecursion = FALSE;
MoveWindow(hwndRichEdit, 0, 0, 250, 100, TRUE);
ok(!bailedOutOfRecursion,
"WM_SIZE/scrollbar mutual recursion detected, expected none!\n");
/* Unblock window in order to process WM_DESTROY */
recursionLevel = 0;
bailedOutOfRecursion = FALSE;
WM_SIZE_recursionLevel = 0;
DestroyWindow(hwndRichEdit);
}
}
static void test_EM_SETUNDOLIMIT(void)
{
/* cases we test for:
* default behaviour - limiting at 100 undo's
* undo disabled - setting a limit of 0
* undo limited - undo limit set to some to some number, like 2
* bad input - sending a negative number should default to 100 undo's */
HWND hwndRichEdit = new_richedit(NULL);
CHARRANGE cr;
int i;
int result;
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "x");
cr.cpMin = 0;
cr.cpMax = 1;
SendMessage(hwndRichEdit, WM_COPY, 0, 0);
/*Load "x" into the clipboard. Paste is an easy, undo'able operation.
also, multiple pastes don't combine like WM_CHAR would */
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
/* first case - check the default */
SendMessage(hwndRichEdit,EM_EMPTYUNDOBUFFER, 0,0);
for (i=0; i<101; i++) /* Put 101 undo's on the stack */
SendMessage(hwndRichEdit, WM_PASTE, 0, 0);
for (i=0; i<100; i++) /* Undo 100 of them */
SendMessage(hwndRichEdit, WM_UNDO, 0, 0);
ok(!SendMessage(hwndRichEdit, EM_CANUNDO, 0, 0),
"EM_SETUNDOLIMIT allowed more than a hundred undo's by default.\n");
/* second case - cannot undo */
SendMessage(hwndRichEdit,EM_EMPTYUNDOBUFFER, 0, 0);
SendMessage(hwndRichEdit, EM_SETUNDOLIMIT, 0, 0);
SendMessage(hwndRichEdit,
WM_PASTE, 0, 0); /* Try to put something in the undo stack */
ok(!SendMessage(hwndRichEdit, EM_CANUNDO, 0, 0),
"EM_SETUNDOLIMIT allowed undo with UNDOLIMIT set to 0\n");
/* third case - set it to an arbitrary number */
SendMessage(hwndRichEdit,EM_EMPTYUNDOBUFFER, 0, 0);
SendMessage(hwndRichEdit, EM_SETUNDOLIMIT, 2, 0);
SendMessage(hwndRichEdit, WM_PASTE, 0, 0);
SendMessage(hwndRichEdit, WM_PASTE, 0, 0);
SendMessage(hwndRichEdit, WM_PASTE, 0, 0);
/* If SETUNDOLIMIT is working, there should only be two undo's after this */
ok(SendMessage(hwndRichEdit, EM_CANUNDO, 0,0),
"EM_SETUNDOLIMIT didn't allow the first undo with UNDOLIMIT set to 2\n");
SendMessage(hwndRichEdit, WM_UNDO, 0, 0);
ok(SendMessage(hwndRichEdit, EM_CANUNDO, 0, 0),
"EM_SETUNDOLIMIT didn't allow a second undo with UNDOLIMIT set to 2\n");
SendMessage(hwndRichEdit, WM_UNDO, 0, 0);
ok(!SendMessage(hwndRichEdit, EM_CANUNDO, 0, 0),
"EM_SETUNDOLIMIT allowed a third undo with UNDOLIMIT set to 2\n");
/* fourth case - setting negative numbers should default to 100 undos */
SendMessage(hwndRichEdit,EM_EMPTYUNDOBUFFER, 0,0);
result = SendMessage(hwndRichEdit, EM_SETUNDOLIMIT, -1, 0);
ok (result == 100,
"EM_SETUNDOLIMIT returned %d when set to -1, instead of 100\n",result);
DestroyWindow(hwndRichEdit);
}
static void test_ES_PASSWORD(void)
{
/* This isn't hugely testable, so we're just going to run it through its paces */
HWND hwndRichEdit = new_richedit(NULL);
WCHAR result;
/* First, check the default of a regular control */
result = SendMessage(hwndRichEdit, EM_GETPASSWORDCHAR, 0, 0);
ok (result == 0,
"EM_GETPASSWORDCHAR returned %c by default, instead of NULL\n",result);
/* Now, set it to something normal */
SendMessage(hwndRichEdit, EM_SETPASSWORDCHAR, 'x', 0);
result = SendMessage(hwndRichEdit, EM_GETPASSWORDCHAR, 0, 0);
ok (result == 120,
"EM_GETPASSWORDCHAR returned %c (%d) when set to 'x', instead of x (120)\n",result,result);
/* Now, set it to something odd */
SendMessage(hwndRichEdit, EM_SETPASSWORDCHAR, (WCHAR)1234, 0);
result = SendMessage(hwndRichEdit, EM_GETPASSWORDCHAR, 0, 0);
ok (result == 1234,
"EM_GETPASSWORDCHAR returned %c (%d) when set to 'x', instead of x (120)\n",result,result);
DestroyWindow(hwndRichEdit);
}
static DWORD CALLBACK test_WM_SETTEXT_esCallback(DWORD_PTR dwCookie,
LPBYTE pbBuff,
LONG cb,
LONG *pcb)
{
char** str = (char**)dwCookie;
*pcb = cb;
if (*pcb > 0) {
memcpy(*str, pbBuff, *pcb);
*str += *pcb;
}
return 0;
}
static void test_WM_SETTEXT(void)
{
HWND hwndRichEdit = new_richedit(NULL);
const char * TestItem1 = "TestSomeText";
const char * TestItem2 = "TestSomeText\r";
const char * TestItem2_after = "TestSomeText\r\n";
const char * TestItem3 = "TestSomeText\rSomeMoreText\r";
const char * TestItem3_after = "TestSomeText\r\nSomeMoreText\r\n";
const char * TestItem4 = "TestSomeText\n\nTestSomeText";
const char * TestItem4_after = "TestSomeText\r\n\r\nTestSomeText";
const char * TestItem5 = "TestSomeText\r\r\nTestSomeText";
const char * TestItem5_after = "TestSomeText TestSomeText";
const char * TestItem6 = "TestSomeText\r\r\n\rTestSomeText";
const char * TestItem6_after = "TestSomeText \r\nTestSomeText";
const char * TestItem7 = "TestSomeText\r\n\r\r\n\rTestSomeText";
const char * TestItem7_after = "TestSomeText\r\n \r\nTestSomeText";
const char rtftextA[] = "{\\rtf sometext}";
const char urtftextA[] = "{\\urtf sometext}";
const WCHAR rtftextW[] = {'{','\\','r','t','f',' ','s','o','m','e','t','e','x','t','}',0};
const WCHAR urtftextW[] = {'{','\\','u','r','t','f',' ','s','o','m','e','t','e','x','t','}',0};
const WCHAR sometextW[] = {'s','o','m','e','t','e','x','t',0};
char buf[1024] = {0};
WCHAR bufW[1024] = {0};
LRESULT result;
/* This test attempts to show that WM_SETTEXT on a riched20 control causes
any solitary \r to be converted to \r\n on return. Properly paired
\r\n are not affected. It also shows that the special sequence \r\r\n
gets converted to a single space.
*/
#define TEST_SETTEXT(a, b) \
result = SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) a); \
ok (result == 1, "WM_SETTEXT returned %ld instead of 1\n", result); \
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buf); \
ok (result == lstrlen(buf), \
"WM_GETTEXT returned %ld instead of expected %u\n", \
result, lstrlen(buf)); \
result = strcmp(b, buf); \
ok(result == 0, \
"WM_SETTEXT round trip: strcmp = %ld, text=\"%s\"\n", result, buf);
TEST_SETTEXT(TestItem1, TestItem1)
TEST_SETTEXT(TestItem2, TestItem2_after)
TEST_SETTEXT(TestItem3, TestItem3_after)
TEST_SETTEXT(TestItem3_after, TestItem3_after)
TEST_SETTEXT(TestItem4, TestItem4_after)
TEST_SETTEXT(TestItem5, TestItem5_after)
TEST_SETTEXT(TestItem6, TestItem6_after)
TEST_SETTEXT(TestItem7, TestItem7_after)
/* The following tests demonstrate that WM_SETTEXT supports RTF strings */
TEST_SETTEXT(rtftextA, "sometext") /* interpreted as ascii rtf */
TEST_SETTEXT(urtftextA, "sometext") /* interpreted as ascii rtf */
TEST_SETTEXT(rtftextW, "{") /* interpreted as ascii text */
TEST_SETTEXT(urtftextW, "{") /* interpreted as ascii text */
DestroyWindow(hwndRichEdit);
#undef TEST_SETTEXT
#define TEST_SETTEXTW(a, b) \
result = SendMessageW(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) a); \
ok (result == 1, "WM_SETTEXT returned %ld instead of 1\n", result); \
result = SendMessageW(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) bufW); \
ok (result == lstrlenW(bufW), \
"WM_GETTEXT returned %ld instead of expected %u\n", \
result, lstrlenW(bufW)); \
result = lstrcmpW(b, bufW); \
ok(result == 0, "WM_SETTEXT round trip: strcmp = %ld\n", result);
hwndRichEdit = CreateWindowW(RICHEDIT_CLASS20W, NULL,
ES_MULTILINE|WS_POPUP|WS_HSCROLL|WS_VSCROLL|WS_VISIBLE,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwndRichEdit != NULL, "class: RichEdit20W, error: %d\n", (int) GetLastError());
TEST_SETTEXTW(rtftextA, sometextW) /* interpreted as ascii rtf */
TEST_SETTEXTW(urtftextA, sometextW) /* interpreted as ascii rtf */
TEST_SETTEXTW(rtftextW, rtftextW) /* interpreted as ascii text */
TEST_SETTEXTW(urtftextW, urtftextW) /* interpreted as ascii text */
DestroyWindow(hwndRichEdit);
#undef TEST_SETTEXTW
}
static void test_EM_STREAMOUT(void)
{
HWND hwndRichEdit = new_richedit(NULL);
int r;
EDITSTREAM es;
char buf[1024] = {0};
char * p;
const char * TestItem1 = "TestSomeText";
const char * TestItem2 = "TestSomeText\r";
const char * TestItem3 = "TestSomeText\r\n";
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) TestItem1);
p = buf;
es.dwCookie = (DWORD_PTR)&p;
es.dwError = 0;
es.pfnCallback = test_WM_SETTEXT_esCallback;
memset(buf, 0, sizeof(buf));
SendMessage(hwndRichEdit, EM_STREAMOUT, SF_TEXT, (LPARAM)&es);
r = strlen(buf);
ok(r == 12, "streamed text length is %d, expecting 12\n", r);
ok(strcmp(buf, TestItem1) == 0,
"streamed text different, got %s\n", buf);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) TestItem2);
p = buf;
es.dwCookie = (DWORD_PTR)&p;
es.dwError = 0;
es.pfnCallback = test_WM_SETTEXT_esCallback;
memset(buf, 0, sizeof(buf));
SendMessage(hwndRichEdit, EM_STREAMOUT, SF_TEXT, (LPARAM)&es);
r = strlen(buf);
/* Here again, \r gets converted to \r\n, like WM_GETTEXT */
ok(r == 14, "streamed text length is %d, expecting 14\n", r);
ok(strcmp(buf, TestItem3) == 0,
"streamed text different from, got %s\n", buf);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) TestItem3);
p = buf;
es.dwCookie = (DWORD_PTR)&p;
es.dwError = 0;
es.pfnCallback = test_WM_SETTEXT_esCallback;
memset(buf, 0, sizeof(buf));
SendMessage(hwndRichEdit, EM_STREAMOUT, SF_TEXT, (LPARAM)&es);
r = strlen(buf);
ok(r == 14, "streamed text length is %d, expecting 14\n", r);
ok(strcmp(buf, TestItem3) == 0,
"streamed text different, got %s\n", buf);
DestroyWindow(hwndRichEdit);
}
static void test_EM_STREAMOUT_FONTTBL(void)
{
HWND hwndRichEdit = new_richedit(NULL);
EDITSTREAM es;
char buf[1024] = {0};
char * p;
char * fontTbl;
int brackCount;
const char * TestItem = "TestSomeText";
/* fills in the richedit control with some text */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) TestItem);
/* streams out the text in rtf format */
p = buf;
es.dwCookie = (DWORD_PTR)&p;
es.dwError = 0;
es.pfnCallback = test_WM_SETTEXT_esCallback;
memset(buf, 0, sizeof(buf));
SendMessage(hwndRichEdit, EM_STREAMOUT, SF_RTF, (LPARAM)&es);
/* scans for \fonttbl, error if not found */
fontTbl = strstr(buf, "\\fonttbl");
ok(fontTbl != NULL, "missing \\fonttbl section\n");
if(fontTbl)
{
/* scans for terminating closing bracket */
brackCount = 1;
while(*fontTbl && brackCount)
{
if(*fontTbl == '{')
brackCount++;
else if(*fontTbl == '}')
brackCount--;
fontTbl++;
}
/* checks whether closing bracket is ok */
ok(brackCount == 0, "missing closing bracket in \\fonttbl block\n");
if(!brackCount)
{
/* char before closing fonttbl block should be a closed bracket */
fontTbl -= 2;
ok(*fontTbl == '}', "spurious character '%02x' before \\fonttbl closing bracket\n", *fontTbl);
/* char after fonttbl block should be a crlf */
fontTbl += 2;
ok(*fontTbl == 0x0d && *(fontTbl+1) == 0x0a, "missing crlf after \\fonttbl block\n");
}
}
DestroyWindow(hwndRichEdit);
}
static void test_EM_SETTEXTEX(void)
{
HWND hwndRichEdit, parent;
SCROLLINFO si;
int sel_start, sel_end;
SETTEXTEX setText;
GETTEXTEX getText;
WCHAR TestItem1[] = {'T', 'e', 's', 't',
'S', 'o', 'm', 'e',
'T', 'e', 'x', 't', 0};
WCHAR TestItem1alt[] = {'T', 'T', 'e', 's',
't', 'S', 'o', 'm',
'e', 'T', 'e', 'x',
't', 't', 'S', 'o',
'm', 'e', 'T', 'e',
'x', 't', 0};
WCHAR TestItem1altn[] = {'T','T','e','s','t','S','o','m','e','T','e','x','t',
'\r','t','S','o','m','e','T','e','x','t',0};
WCHAR TestItem2[] = {'T', 'e', 's', 't',
'S', 'o', 'm', 'e',
'T', 'e', 'x', 't',
'\r', 0};
const char * TestItem2_after = "TestSomeText\r\n";
WCHAR TestItem3[] = {'T', 'e', 's', 't',
'S', 'o', 'm', 'e',
'T', 'e', 'x', 't',
'\r','\n','\r','\n', 0};
WCHAR TestItem3alt[] = {'T', 'e', 's', 't',
'S', 'o', 'm', 'e',
'T', 'e', 'x', 't',
'\n','\n', 0};
WCHAR TestItem3_after[] = {'T', 'e', 's', 't',
'S', 'o', 'm', 'e',
'T', 'e', 'x', 't',
'\r','\r', 0};
WCHAR TestItem4[] = {'T', 'e', 's', 't',
'S', 'o', 'm', 'e',
'T', 'e', 'x', 't',
'\r','\r','\n','\r',
'\n', 0};
WCHAR TestItem4_after[] = {'T', 'e', 's', 't',
'S', 'o', 'm', 'e',
'T', 'e', 'x', 't',
' ','\r', 0};
#define MAX_BUF_LEN 1024
WCHAR buf[MAX_BUF_LEN];
char bufACP[MAX_BUF_LEN];
char * p;
int result;
CHARRANGE cr;
EDITSTREAM es;
WNDCLASSA cls;
/* Test the scroll position with and without a parent window.
*
* For some reason the scroll position is 0 after EM_SETTEXTEX
* with the ST_SELECTION flag only when the control has a parent
* window, even though the selection is at the end. */
cls.style = 0;
cls.lpfnWndProc = DefWindowProcA;
cls.cbClsExtra = 0;
cls.cbWndExtra = 0;
cls.hInstance = GetModuleHandleA(0);
cls.hIcon = 0;
cls.hCursor = LoadCursorA(0, IDC_ARROW);
cls.hbrBackground = GetStockObject(WHITE_BRUSH);
cls.lpszMenuName = NULL;
cls.lpszClassName = "ParentTestClass";
if(!RegisterClassA(&cls)) assert(0);
parent = CreateWindow(cls.lpszClassName, NULL, WS_POPUP|WS_VISIBLE,
0, 0, 200, 60, NULL, NULL, NULL, NULL);
ok (parent != 0, "Failed to create parent window\n");
hwndRichEdit = CreateWindowEx(0,
RICHEDIT_CLASS, NULL,
ES_MULTILINE|WS_VSCROLL|WS_VISIBLE|WS_CHILD,
0, 0, 200, 60, parent, NULL,
hmoduleRichEdit, NULL);
setText.codepage = CP_ACP;
setText.flags = ST_SELECTION;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText,
(LPARAM)"{\\rtf 1\\par 2\\par 3\\par 4\\par 5\\par 6\\par 7\\par 8\\par 9\\par}");
si.cbSize = sizeof(si);
si.fMask = SIF_ALL;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
todo_wine ok(si.nPos == 0, "Position is incorrectly at %d\n", si.nPos);
SendMessage(hwndRichEdit, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
ok(sel_start == 18, "Selection start incorrectly at %d\n", sel_start);
ok(sel_end == 18, "Selection end incorrectly at %d\n", sel_end);
DestroyWindow(parent);
/* Test without a parent window */
hwndRichEdit = new_richedit(NULL);
setText.codepage = CP_ACP;
setText.flags = ST_SELECTION;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText,
(LPARAM)"{\\rtf 1\\par 2\\par 3\\par 4\\par 5\\par 6\\par 7\\par 8\\par 9\\par}");
si.cbSize = sizeof(si);
si.fMask = SIF_ALL;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok(si.nPos != 0, "Position is incorrectly at %d\n", si.nPos);
SendMessage(hwndRichEdit, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
ok(sel_start == 18, "Selection start incorrectly at %d\n", sel_start);
ok(sel_end == 18, "Selection end incorrectly at %d\n", sel_end);
/* The scroll position should also be 0 after EM_SETTEXTEX with ST_DEFAULT,
* but this time it is because the selection is at the beginning. */
setText.codepage = CP_ACP;
setText.flags = ST_DEFAULT;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText,
(LPARAM)"{\\rtf 1\\par 2\\par 3\\par 4\\par 5\\par 6\\par 7\\par 8\\par 9\\par}");
si.cbSize = sizeof(si);
si.fMask = SIF_ALL;
GetScrollInfo(hwndRichEdit, SB_VERT, &si);
ok(si.nPos == 0, "Position is incorrectly at %d\n", si.nPos);
SendMessage(hwndRichEdit, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
ok(sel_start == 0, "Selection start incorrectly at %d\n", sel_start);
ok(sel_end == 0, "Selection end incorrectly at %d\n", sel_end);
setText.codepage = 1200; /* no constant for unicode */
getText.codepage = 1200; /* no constant for unicode */
getText.cb = MAX_BUF_LEN;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
setText.flags = 0;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) TestItem1);
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
ok(lstrcmpW(buf, TestItem1) == 0,
"EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n");
/* Unlike WM_SETTEXT/WM_GETTEXT pair, EM_SETTEXTEX/EM_GETTEXTEX does not
convert \r to \r\n on return: !ST_SELECTION && Unicode && !\rtf
*/
setText.codepage = 1200; /* no constant for unicode */
getText.codepage = 1200; /* no constant for unicode */
getText.cb = MAX_BUF_LEN;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
setText.flags = 0;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) TestItem2);
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
ok(lstrcmpW(buf, TestItem2) == 0,
"EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n");
/* However, WM_GETTEXT *does* see \r\n where EM_GETTEXTEX would see \r */
SendMessage(hwndRichEdit, WM_GETTEXT, MAX_BUF_LEN, (LPARAM)buf);
ok(strcmp((const char *)buf, TestItem2_after) == 0,
"WM_GETTEXT did *not* see \\r converted to \\r\\n pairs.\n");
/* Baseline test for just-enough buffer space for string */
getText.cb = (lstrlenW(TestItem2) + 1) * sizeof(WCHAR);
getText.codepage = 1200; /* no constant for unicode */
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
memset(buf, 0, MAX_BUF_LEN);
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
ok(lstrcmpW(buf, TestItem2) == 0,
"EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n");
/* When there is enough space for one character, but not both, of the CRLF
pair at the end of the string, the CR is not copied at all. That is,
the caller must not see CRLF pairs truncated to CR at the end of the
string.
*/
getText.cb = (lstrlenW(TestItem2) + 1) * sizeof(WCHAR);
getText.codepage = 1200; /* no constant for unicode */
getText.flags = GT_USECRLF; /* <-- asking for CR -> CRLF conversion */
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
memset(buf, 0, MAX_BUF_LEN);
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
ok(lstrcmpW(buf, TestItem1) == 0,
"EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n");
/* \r\n pairs get changed into \r: !ST_SELECTION && Unicode && !\rtf */
setText.codepage = 1200; /* no constant for unicode */
getText.codepage = 1200; /* no constant for unicode */
getText.cb = MAX_BUF_LEN;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
setText.flags = 0;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) TestItem3);
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
ok(lstrcmpW(buf, TestItem3_after) == 0,
"EM_SETTEXTEX did not convert properly\n");
/* \n also gets changed to \r: !ST_SELECTION && Unicode && !\rtf */
setText.codepage = 1200; /* no constant for unicode */
getText.codepage = 1200; /* no constant for unicode */
getText.cb = MAX_BUF_LEN;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
setText.flags = 0;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) TestItem3alt);
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
ok(lstrcmpW(buf, TestItem3_after) == 0,
"EM_SETTEXTEX did not convert properly\n");
/* \r\r\n gets changed into single space: !ST_SELECTION && Unicode && !\rtf */
setText.codepage = 1200; /* no constant for unicode */
getText.codepage = 1200; /* no constant for unicode */
getText.cb = MAX_BUF_LEN;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
setText.flags = 0;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) TestItem4);
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
ok(lstrcmpW(buf, TestItem4_after) == 0,
"EM_SETTEXTEX did not convert properly\n");
/* !ST_SELECTION && Unicode && !\rtf */
result = SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, 0);
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
ok (result == 1,
"EM_SETTEXTEX returned %d, instead of 1\n",result);
ok(lstrlenW(buf) == 0,
"EM_SETTEXTEX with NULL lParam should clear rich edit.\n");
/* put some text back: !ST_SELECTION && Unicode && !\rtf */
setText.flags = 0;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) TestItem1);
/* select some text */
cr.cpMax = 1;
cr.cpMin = 3;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
/* replace current selection: ST_SELECTION && Unicode && !\rtf */
setText.flags = ST_SELECTION;
result = SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, 0);
ok(result == 0,
"EM_SETTEXTEX with NULL lParam to replace selection"
" with no text should return 0. Got %i\n",
result);
/* put some text back: !ST_SELECTION && Unicode && !\rtf */
setText.flags = 0;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) TestItem1);
/* select some text */
cr.cpMax = 1;
cr.cpMin = 3;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
/* replace current selection: ST_SELECTION && Unicode && !\rtf */
setText.flags = ST_SELECTION;
result = SendMessage(hwndRichEdit, EM_SETTEXTEX,
(WPARAM)&setText, (LPARAM) TestItem1);
/* get text */
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
ok(result == lstrlenW(TestItem1),
"EM_SETTEXTEX with NULL lParam to replace selection"
" with no text should return 0. Got %i\n",
result);
ok(lstrlenW(buf) == 22,
"EM_SETTEXTEX to replace selection with more text failed: %i.\n",
lstrlenW(buf) );
/* The following test demonstrates that EM_SETTEXTEX supports RTF strings */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "TestSomeText"); /* TestItem1 */
p = (char *)buf;
es.dwCookie = (DWORD_PTR)&p;
es.dwError = 0;
es.pfnCallback = test_WM_SETTEXT_esCallback;
memset(buf, 0, sizeof(buf));
SendMessage(hwndRichEdit, EM_STREAMOUT,
(WPARAM)(SF_RTF), (LPARAM)&es);
trace("EM_STREAMOUT produced:\n%s\n", (char *)buf);
/* !ST_SELECTION && !Unicode && \rtf */
setText.codepage = CP_ACP;/* EM_STREAMOUT saved as ANSI string */
getText.codepage = 1200; /* no constant for unicode */
getText.cb = MAX_BUF_LEN;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
setText.flags = 0;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) buf);
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
ok(lstrcmpW(buf, TestItem1) == 0,
"EM_GETTEXTEX results not what was set by EM_SETTEXTEX\n");
/* The following test demonstrates that EM_SETTEXTEX treats text as ASCII if it
* starts with ASCII characters "{\rtf" even when the codepage is unicode. */
setText.codepage = 1200; /* Lie about code page (actual ASCII) */
getText.codepage = CP_ACP;
getText.cb = MAX_BUF_LEN;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
setText.flags = ST_SELECTION;
SendMessage(hwndRichEdit, EM_SETSEL, 0, -1);
result = SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) "{\\rtf not unicode}");
todo_wine ok(result == 11, "EM_SETTEXTEX incorrectly returned %d\n", result);
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) bufACP);
ok(lstrcmpA(bufACP, "not unicode") == 0, "'%s' != 'not unicode'\n", bufACP);
/* The following test demonstrates that EM_SETTEXTEX supports RTF strings with a selection */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "TestSomeText"); /* TestItem1 */
p = (char *)buf;
es.dwCookie = (DWORD_PTR)&p;
es.dwError = 0;
es.pfnCallback = test_WM_SETTEXT_esCallback;
memset(buf, 0, sizeof(buf));
SendMessage(hwndRichEdit, EM_STREAMOUT,
(WPARAM)(SF_RTF), (LPARAM)&es);
trace("EM_STREAMOUT produced:\n%s\n", (char *)buf);
/* select some text */
cr.cpMax = 1;
cr.cpMin = 3;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
/* ST_SELECTION && !Unicode && \rtf */
setText.codepage = CP_ACP;/* EM_STREAMOUT saved as ANSI string */
getText.codepage = 1200; /* no constant for unicode */
getText.cb = MAX_BUF_LEN;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
setText.flags = ST_SELECTION;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) buf);
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
ok_w3("Expected \"%s\" or \"%s\", got \"%s\"\n", TestItem1alt, TestItem1altn, buf);
/* The following test demonstrates that EM_SETTEXTEX replacing a selection */
setText.codepage = 1200; /* no constant for unicode */
getText.codepage = CP_ACP;
getText.cb = MAX_BUF_LEN;
setText.flags = 0;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) TestItem1); /* TestItem1 */
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) bufACP);
/* select some text */
cr.cpMax = 1;
cr.cpMin = 3;
SendMessage(hwndRichEdit, EM_EXSETSEL, 0, (LPARAM) &cr);
/* ST_SELECTION && !Unicode && !\rtf */
setText.codepage = CP_ACP;
getText.codepage = 1200; /* no constant for unicode */
getText.cb = MAX_BUF_LEN;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
setText.flags = ST_SELECTION;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM) bufACP);
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
ok(lstrcmpW(buf, TestItem1alt) == 0,
"EM_GETTEXTEX results not what was set by EM_SETTEXTEX when"
" using ST_SELECTION and non-Unicode\n");
/* Test setting text using rich text format */
setText.flags = 0;
setText.codepage = CP_ACP;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM)"{\\rtf richtext}");
getText.codepage = CP_ACP;
getText.cb = MAX_BUF_LEN;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) bufACP);
ok(!strcmp(bufACP, "richtext"), "expected 'richtext' but got '%s'\n", bufACP);
setText.flags = 0;
setText.codepage = CP_ACP;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM)"{\\urtf morerichtext}");
getText.codepage = CP_ACP;
getText.cb = MAX_BUF_LEN;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) bufACP);
ok(!strcmp(bufACP, "morerichtext"), "expected 'morerichtext' but got '%s'\n", bufACP);
DestroyWindow(hwndRichEdit);
}
static void test_EM_LIMITTEXT(void)
{
int ret;
HWND hwndRichEdit = new_richedit(NULL);
/* The main purpose of this test is to demonstrate that the nonsense in MSDN
* about setting the length to -1 for multiline edit controls doesn't happen.
*/
/* Don't check default gettextlimit case. That's done in other tests */
/* Set textlimit to 100 */
SendMessage (hwndRichEdit, EM_LIMITTEXT, 100, 0);
ret = SendMessage (hwndRichEdit, EM_GETLIMITTEXT, 0, 0);
ok (ret == 100,
"EM_LIMITTEXT: set to 100, returned: %d, expected: 100\n", ret);
/* Set textlimit to 0 */
SendMessage (hwndRichEdit, EM_LIMITTEXT, 0, 0);
ret = SendMessage (hwndRichEdit, EM_GETLIMITTEXT, 0, 0);
ok (ret == 65536,
"EM_LIMITTEXT: set to 0, returned: %d, expected: 65536\n", ret);
/* Set textlimit to -1 */
SendMessage (hwndRichEdit, EM_LIMITTEXT, -1, 0);
ret = SendMessage (hwndRichEdit, EM_GETLIMITTEXT, 0, 0);
ok (ret == -1,
"EM_LIMITTEXT: set to -1, returned: %d, expected: -1\n", ret);
/* Set textlimit to -2 */
SendMessage (hwndRichEdit, EM_LIMITTEXT, -2, 0);
ret = SendMessage (hwndRichEdit, EM_GETLIMITTEXT, 0, 0);
ok (ret == -2,
"EM_LIMITTEXT: set to -2, returned: %d, expected: -2\n", ret);
DestroyWindow (hwndRichEdit);
}
static void test_EM_EXLIMITTEXT(void)
{
int i, selBegin, selEnd, len1, len2;
int result;
char text[1024 + 1];
char buffer[1024 + 1];
int textlimit = 0; /* multiple of 100 */
HWND hwndRichEdit = new_richedit(NULL);
i = SendMessage(hwndRichEdit, EM_GETLIMITTEXT, 0, 0);
ok(32767 == i, "EM_EXLIMITTEXT: expected: %d, actual: %d\n", 32767, i); /* default */
textlimit = 256000;
SendMessage(hwndRichEdit, EM_EXLIMITTEXT, 0, textlimit);
i = SendMessage(hwndRichEdit, EM_GETLIMITTEXT, 0, 0);
/* set higher */
ok(textlimit == i, "EM_EXLIMITTEXT: expected: %d, actual: %d\n", textlimit, i);
textlimit = 1000;
SendMessage(hwndRichEdit, EM_EXLIMITTEXT, 0, textlimit);
i = SendMessage(hwndRichEdit, EM_GETLIMITTEXT, 0, 0);
/* set lower */
ok(textlimit == i, "EM_EXLIMITTEXT: expected: %d, actual: %d\n", textlimit, i);
SendMessage(hwndRichEdit, EM_EXLIMITTEXT, 0, 0);
i = SendMessage(hwndRichEdit, EM_GETLIMITTEXT, 0, 0);
/* default for WParam = 0 */
ok(65536 == i, "EM_EXLIMITTEXT: expected: %d, actual: %d\n", 65536, i);
textlimit = sizeof(text)-1;
memset(text, 'W', textlimit);
text[sizeof(text)-1] = 0;
SendMessage(hwndRichEdit, EM_EXLIMITTEXT, 0, textlimit);
/* maxed out text */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text);
SendMessage(hwndRichEdit, EM_SETSEL, 0, -1); /* select everything */
SendMessage(hwndRichEdit, EM_GETSEL, (WPARAM)&selBegin, (LPARAM)&selEnd);
len1 = selEnd - selBegin;
SendMessage(hwndRichEdit, WM_KEYDOWN, VK_BACK, 1);
SendMessage(hwndRichEdit, WM_CHAR, VK_BACK, 1);
SendMessage(hwndRichEdit, WM_KEYUP, VK_BACK, 1);
SendMessage(hwndRichEdit, EM_SETSEL, 0, -1);
SendMessage(hwndRichEdit, EM_GETSEL, (WPARAM)&selBegin, (LPARAM)&selEnd);
len2 = selEnd - selBegin;
ok(len1 != len2,
"EM_EXLIMITTEXT: Change Expected\nOld Length: %d, New Length: %d, Limit: %d\n",
len1,len2,i);
SendMessage(hwndRichEdit, WM_KEYDOWN, 'A', 1);
SendMessage(hwndRichEdit, WM_CHAR, 'A', 1);
SendMessage(hwndRichEdit, WM_KEYUP, 'A', 1);
SendMessage(hwndRichEdit, EM_SETSEL, 0, -1);
SendMessage(hwndRichEdit, EM_GETSEL, (WPARAM)&selBegin, (LPARAM)&selEnd);
len1 = selEnd - selBegin;
ok(len1 != len2,
"EM_EXLIMITTEXT: Change Expected\nOld Length: %d, New Length: %d, Limit: %d\n",
len1,len2,i);
SendMessage(hwndRichEdit, WM_KEYDOWN, 'A', 1);
SendMessage(hwndRichEdit, WM_CHAR, 'A', 1);
SendMessage(hwndRichEdit, WM_KEYUP, 'A', 1); /* full; should be no effect */
SendMessage(hwndRichEdit, EM_SETSEL, 0, -1);
SendMessage(hwndRichEdit, EM_GETSEL, (WPARAM)&selBegin, (LPARAM)&selEnd);
len2 = selEnd - selBegin;
ok(len1 == len2,
"EM_EXLIMITTEXT: No Change Expected\nOld Length: %d, New Length: %d, Limit: %d\n",
len1,len2,i);
/* set text up to the limit, select all the text, then add a char */
textlimit = 5;
memset(text, 'W', textlimit);
text[textlimit] = 0;
SendMessage(hwndRichEdit, EM_EXLIMITTEXT, 0, textlimit);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text);
SendMessage(hwndRichEdit, EM_SETSEL, 0, -1);
SendMessage(hwndRichEdit, WM_CHAR, 'A', 1);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
result = strcmp(buffer, "A");
ok(0 == result, "got string = \"%s\"\n", buffer);
/* WM_SETTEXT not limited */
textlimit = 10;
memset(text, 'W', textlimit);
text[textlimit] = 0;
SendMessage(hwndRichEdit, EM_EXLIMITTEXT, 0, textlimit-5);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
i = strlen(buffer);
ok(10 == i, "expected 10 chars\n");
i = SendMessage(hwndRichEdit, EM_GETLIMITTEXT, 0, 0);
ok(10 == i, "EM_EXLIMITTEXT: expected: %d, actual: %d\n", 10, i);
/* try inserting more text at end */
i = SendMessage(hwndRichEdit, WM_CHAR, 'A', 0);
ok(0 == i, "WM_CHAR wasn't processed\n");
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
i = strlen(buffer);
ok(10 == i, "expected 10 chars, got %i\n", i);
i = SendMessage(hwndRichEdit, EM_GETLIMITTEXT, 0, 0);
ok(10 == i, "EM_EXLIMITTEXT: expected: %d, actual: %d\n", 10, i);
/* try inserting text at beginning */
SendMessage(hwndRichEdit, EM_SETSEL, 0, 0);
i = SendMessage(hwndRichEdit, WM_CHAR, 'A', 0);
ok(0 == i, "WM_CHAR wasn't processed\n");
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
i = strlen(buffer);
ok(10 == i, "expected 10 chars, got %i\n", i);
i = SendMessage(hwndRichEdit, EM_GETLIMITTEXT, 0, 0);
ok(10 == i, "EM_EXLIMITTEXT: expected: %d, actual: %d\n", 10, i);
/* WM_CHAR is limited */
textlimit = 1;
SendMessage(hwndRichEdit, EM_EXLIMITTEXT, 0, textlimit);
SendMessage(hwndRichEdit, EM_SETSEL, 0, -1); /* select everything */
i = SendMessage(hwndRichEdit, WM_CHAR, 'A', 0);
ok(0 == i, "WM_CHAR wasn't processed\n");
i = SendMessage(hwndRichEdit, WM_CHAR, 'A', 0);
ok(0 == i, "WM_CHAR wasn't processed\n");
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
i = strlen(buffer);
ok(1 == i, "expected 1 chars, got %i instead\n", i);
DestroyWindow(hwndRichEdit);
}
static void test_EM_GETLIMITTEXT(void)
{
int i;
HWND hwndRichEdit = new_richedit(NULL);
i = SendMessage(hwndRichEdit, EM_GETLIMITTEXT, 0, 0);
ok(32767 == i, "expected: %d, actual: %d\n", 32767, i); /* default value */
SendMessage(hwndRichEdit, EM_EXLIMITTEXT, 0, 50000);
i = SendMessage(hwndRichEdit, EM_GETLIMITTEXT, 0, 0);
ok(50000 == i, "expected: %d, actual: %d\n", 50000, i);
DestroyWindow(hwndRichEdit);
}
static void test_WM_SETFONT(void)
{
/* There is no invalid input or error conditions for this function.
* NULL wParam and lParam just fall back to their default values
* It should be noted that even if you use a gibberish name for your fonts
* here, it will still work because the name is stored. They will display as
* System, but will report their name to be whatever they were created as */
HWND hwndRichEdit = new_richedit(NULL);
HFONT testFont1 = CreateFontA (0,0,0,0,FW_LIGHT, 0, 0, 0, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH |
FF_DONTCARE, "Marlett");
HFONT testFont2 = CreateFontA (0,0,0,0,FW_LIGHT, 0, 0, 0, ANSI_CHARSET,
OUT_TT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH |
FF_DONTCARE, "MS Sans Serif");
HFONT testFont3 = CreateFontA (0,0,0,0,FW_LIGHT, 0, 0, 0, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH |
FF_DONTCARE, "Courier");
LOGFONTA sentLogFont;
CHARFORMAT2A returnedCF2A;
returnedCF2A.cbSize = sizeof(returnedCF2A);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "x");
SendMessage(hwndRichEdit, WM_SETFONT, (WPARAM)testFont1, MAKELPARAM(TRUE, 0));
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM) &returnedCF2A);
GetObjectA(testFont1, sizeof(LOGFONTA), &sentLogFont);
ok (!strcmp(sentLogFont.lfFaceName,returnedCF2A.szFaceName),
"EM_GETCHARFORMAT: Returned wrong font on test 1. Sent: %s, Returned: %s\n",
sentLogFont.lfFaceName,returnedCF2A.szFaceName);
SendMessage(hwndRichEdit, WM_SETFONT, (WPARAM)testFont2, MAKELPARAM(TRUE, 0));
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM) &returnedCF2A);
GetObjectA(testFont2, sizeof(LOGFONTA), &sentLogFont);
ok (!strcmp(sentLogFont.lfFaceName,returnedCF2A.szFaceName),
"EM_GETCHARFORMAT: Returned wrong font on test 2. Sent: %s, Returned: %s\n",
sentLogFont.lfFaceName,returnedCF2A.szFaceName);
SendMessage(hwndRichEdit, WM_SETFONT, (WPARAM)testFont3, MAKELPARAM(TRUE, 0));
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM) &returnedCF2A);
GetObjectA(testFont3, sizeof(LOGFONTA), &sentLogFont);
ok (!strcmp(sentLogFont.lfFaceName,returnedCF2A.szFaceName),
"EM_GETCHARFORMAT: Returned wrong font on test 3. Sent: %s, Returned: %s\n",
sentLogFont.lfFaceName,returnedCF2A.szFaceName);
/* This last test is special since we send in NULL. We clear the variables
* and just compare to "System" instead of the sent in font name. */
ZeroMemory(&returnedCF2A,sizeof(returnedCF2A));
ZeroMemory(&sentLogFont,sizeof(sentLogFont));
returnedCF2A.cbSize = sizeof(returnedCF2A);
SendMessage(hwndRichEdit, WM_SETFONT, 0, MAKELPARAM((WORD) TRUE, 0));
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM) &returnedCF2A);
GetObjectA(NULL, sizeof(LOGFONTA), &sentLogFont);
ok (!strcmp("System",returnedCF2A.szFaceName),
"EM_GETCHARFORMAT: Returned wrong font on test 4. Sent: NULL, Returned: %s. Expected \"System\".\n",returnedCF2A.szFaceName);
DestroyWindow(hwndRichEdit);
}
static DWORD CALLBACK test_EM_GETMODIFY_esCallback(DWORD_PTR dwCookie,
LPBYTE pbBuff,
LONG cb,
LONG *pcb)
{
const char** str = (const char**)dwCookie;
int size = strlen(*str);
if(size > 3) /* let's make it piecemeal for fun */
size = 3;
*pcb = cb;
if (*pcb > size) {
*pcb = size;
}
if (*pcb > 0) {
memcpy(pbBuff, *str, *pcb);
*str += *pcb;
}
return 0;
}
static void test_EM_GETMODIFY(void)
{
HWND hwndRichEdit = new_richedit(NULL);
LRESULT result;
SETTEXTEX setText;
WCHAR TestItem1[] = {'T', 'e', 's', 't',
'S', 'o', 'm', 'e',
'T', 'e', 'x', 't', 0};
WCHAR TestItem2[] = {'T', 'e', 's', 't',
'S', 'o', 'm', 'e',
'O', 't', 'h', 'e', 'r',
'T', 'e', 'x', 't', 0};
const char* streamText = "hello world";
CHARFORMAT2 cf2;
PARAFORMAT2 pf2;
EDITSTREAM es;
HFONT testFont = CreateFontA (0,0,0,0,FW_LIGHT, 0, 0, 0, ANSI_CHARSET,
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH |
FF_DONTCARE, "Courier");
setText.codepage = 1200; /* no constant for unicode */
setText.flags = ST_KEEPUNDO;
/* modify flag shouldn't be set when richedit is first created */
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result == 0,
"EM_GETMODIFY returned non-zero, instead of zero on create\n");
/* setting modify flag should actually set it */
SendMessage(hwndRichEdit, EM_SETMODIFY, TRUE, 0);
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result != 0,
"EM_GETMODIFY returned zero, instead of non-zero on EM_SETMODIFY\n");
/* clearing modify flag should actually clear it */
SendMessage(hwndRichEdit, EM_SETMODIFY, FALSE, 0);
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result == 0,
"EM_GETMODIFY returned non-zero, instead of zero on EM_SETMODIFY\n");
/* setting font doesn't change modify flag */
SendMessage(hwndRichEdit, EM_SETMODIFY, FALSE, 0);
SendMessage(hwndRichEdit, WM_SETFONT, (WPARAM)testFont, MAKELPARAM(TRUE, 0));
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result == 0,
"EM_GETMODIFY returned non-zero, instead of zero on setting font\n");
/* setting text should set modify flag */
SendMessage(hwndRichEdit, EM_SETMODIFY, FALSE, 0);
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM)TestItem1);
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result != 0,
"EM_GETMODIFY returned zero, instead of non-zero on setting text\n");
/* undo previous text doesn't reset modify flag */
SendMessage(hwndRichEdit, WM_UNDO, 0, 0);
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result != 0,
"EM_GETMODIFY returned zero, instead of non-zero on undo after setting text\n");
/* set text with no flag to keep undo stack should not set modify flag */
SendMessage(hwndRichEdit, EM_SETMODIFY, FALSE, 0);
setText.flags = 0;
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM)TestItem1);
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result == 0,
"EM_GETMODIFY returned non-zero, instead of zero when setting text while not keeping undo stack\n");
/* WM_SETTEXT doesn't modify */
SendMessage(hwndRichEdit, EM_SETMODIFY, FALSE, 0);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)TestItem2);
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result == 0,
"EM_GETMODIFY returned non-zero for WM_SETTEXT\n");
/* clear the text */
SendMessage(hwndRichEdit, EM_SETMODIFY, FALSE, 0);
SendMessage(hwndRichEdit, WM_CLEAR, 0, 0);
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result == 0,
"EM_GETMODIFY returned non-zero, instead of zero for WM_CLEAR\n");
/* replace text */
SendMessage(hwndRichEdit, EM_SETMODIFY, FALSE, 0);
SendMessage(hwndRichEdit, EM_SETTEXTEX, (WPARAM)&setText, (LPARAM)TestItem1);
SendMessage(hwndRichEdit, EM_SETSEL, 0, 2);
SendMessage(hwndRichEdit, EM_REPLACESEL, TRUE, (LPARAM)TestItem2);
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result != 0,
"EM_GETMODIFY returned zero, instead of non-zero when replacing text\n");
/* copy/paste text 1 */
SendMessage(hwndRichEdit, EM_SETMODIFY, FALSE, 0);
SendMessage(hwndRichEdit, EM_SETSEL, 0, 2);
SendMessage(hwndRichEdit, WM_COPY, 0, 0);
SendMessage(hwndRichEdit, WM_PASTE, 0, 0);
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result != 0,
"EM_GETMODIFY returned zero, instead of non-zero when pasting identical text\n");
/* copy/paste text 2 */
SendMessage(hwndRichEdit, EM_SETMODIFY, FALSE, 0);
SendMessage(hwndRichEdit, EM_SETSEL, 0, 2);
SendMessage(hwndRichEdit, WM_COPY, 0, 0);
SendMessage(hwndRichEdit, EM_SETSEL, 0, 3);
SendMessage(hwndRichEdit, WM_PASTE, 0, 0);
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result != 0,
"EM_GETMODIFY returned zero, instead of non-zero when pasting different text\n");
/* press char */
SendMessage(hwndRichEdit, EM_SETMODIFY, FALSE, 0);
SendMessage(hwndRichEdit, EM_SETSEL, 0, 1);
SendMessage(hwndRichEdit, WM_CHAR, 'A', 0);
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result != 0,
"EM_GETMODIFY returned zero, instead of non-zero for WM_CHAR\n");
/* press del */
SendMessage(hwndRichEdit, WM_CHAR, 'A', 0);
SendMessage(hwndRichEdit, EM_SETMODIFY, FALSE, 0);
SendMessage(hwndRichEdit, WM_KEYDOWN, VK_BACK, 0);
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result != 0,
"EM_GETMODIFY returned zero, instead of non-zero for backspace\n");
/* set char format */
SendMessage(hwndRichEdit, EM_SETMODIFY, FALSE, 0);
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichEdit, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf2);
cf2.dwMask = CFM_ITALIC | cf2.dwMask;
cf2.dwEffects = CFE_ITALIC ^ cf2.dwEffects;
SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf2);
result = SendMessage(hwndRichEdit, EM_SETCHARFORMAT, SCF_ALL, (LPARAM)&cf2);
ok(result == 1, "EM_SETCHARFORMAT returned %ld instead of 1\n", result);
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result != 0,
"EM_GETMODIFY returned zero, instead of non-zero for EM_SETCHARFORMAT\n");
/* set para format */
SendMessage(hwndRichEdit, EM_SETMODIFY, FALSE, 0);
pf2.cbSize = sizeof(PARAFORMAT2);
SendMessage(hwndRichEdit, EM_GETPARAFORMAT, 0,
(LPARAM) &pf2);
pf2.dwMask = PFM_ALIGNMENT | pf2.dwMask;
pf2.wAlignment = PFA_RIGHT;
SendMessage(hwndRichEdit, EM_SETPARAFORMAT, 0, (LPARAM) &pf2);
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result == 0,
"EM_GETMODIFY returned zero, instead of non-zero for EM_SETPARAFORMAT\n");
/* EM_STREAM */
SendMessage(hwndRichEdit, EM_SETMODIFY, FALSE, 0);
es.dwCookie = (DWORD_PTR)&streamText;
es.dwError = 0;
es.pfnCallback = test_EM_GETMODIFY_esCallback;
SendMessage(hwndRichEdit, EM_STREAMIN, SF_TEXT, (LPARAM)&es);
result = SendMessage(hwndRichEdit, EM_GETMODIFY, 0, 0);
ok (result != 0,
"EM_GETMODIFY returned zero, instead of non-zero for EM_STREAM\n");
DestroyWindow(hwndRichEdit);
}
struct exsetsel_s {
LONG min;
LONG max;
LRESULT expected_retval;
int expected_getsel_start;
int expected_getsel_end;
int _getsel_todo_wine;
};
const struct exsetsel_s exsetsel_tests[] = {
/* sanity tests */
{5, 10, 10, 5, 10, 0},
{15, 17, 17, 15, 17, 0},
/* test cpMax > strlen() */
{0, 100, 18, 0, 18, 1},
/* test cpMin == cpMax */
{5, 5, 5, 5, 5, 0},
/* test cpMin < 0 && cpMax >= 0 (bug 4462) */
{-1, 0, 5, 5, 5, 0},
{-1, 17, 5, 5, 5, 0},
{-1, 18, 5, 5, 5, 0},
/* test cpMin < 0 && cpMax < 0 */
{-1, -1, 17, 17, 17, 0},
{-4, -5, 17, 17, 17, 0},
/* test cMin >=0 && cpMax < 0 (bug 6814) */
{0, -1, 18, 0, 18, 1},
{17, -5, 18, 17, 18, 1},
{18, -3, 17, 17, 17, 0},
/* test if cpMin > cpMax */
{15, 19, 18, 15, 18, 1},
{19, 15, 18, 15, 18, 1}
};
static void check_EM_EXSETSEL(HWND hwnd, const struct exsetsel_s *setsel, int id) {
CHARRANGE cr;
LRESULT result;
int start, end;
cr.cpMin = setsel->min;
cr.cpMax = setsel->max;
result = SendMessage(hwnd, EM_EXSETSEL, 0, (LPARAM) &cr);
ok(result == setsel->expected_retval, "EM_EXSETSEL(%d): expected: %ld actual: %ld\n", id, setsel->expected_retval, result);
SendMessage(hwnd, EM_GETSEL, (WPARAM) &start, (LPARAM) &end);
if (setsel->_getsel_todo_wine) {
todo_wine {
ok(start == setsel->expected_getsel_start && end == setsel->expected_getsel_end, "EM_EXSETSEL(%d): expected (%d,%d) actual:(%d,%d)\n", id, setsel->expected_getsel_start, setsel->expected_getsel_end, start, end);
}
} else {
ok(start == setsel->expected_getsel_start && end == setsel->expected_getsel_end, "EM_EXSETSEL(%d): expected (%d,%d) actual:(%d,%d)\n", id, setsel->expected_getsel_start, setsel->expected_getsel_end, start, end);
}
}
static void test_EM_EXSETSEL(void)
{
HWND hwndRichEdit = new_richedit(NULL);
int i;
const int num_tests = sizeof(exsetsel_tests)/sizeof(struct exsetsel_s);
/* sending some text to the window */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "testing selection");
/* 01234567890123456*/
/* 10 */
for (i = 0; i < num_tests; i++) {
check_EM_EXSETSEL(hwndRichEdit, &exsetsel_tests[i], i);
}
DestroyWindow(hwndRichEdit);
}
static void test_EM_REPLACESEL(int redraw)
{
HWND hwndRichEdit = new_richedit(NULL);
char buffer[1024] = {0};
int r;
GETTEXTEX getText;
CHARRANGE cr;
/* sending some text to the window */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "testing selection");
/* 01234567890123456*/
/* 10 */
/* FIXME add more tests */
SendMessage(hwndRichEdit, EM_SETSEL, 7, 17);
r = SendMessage(hwndRichEdit, EM_REPLACESEL, 0, 0);
ok(0 == r, "EM_REPLACESEL returned %d, expected 0\n", r);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
r = strcmp(buffer, "testing");
ok(0 == r, "expected %d, got %d\n", 0, r);
DestroyWindow(hwndRichEdit);
hwndRichEdit = new_richedit(NULL);
trace("Testing EM_REPLACESEL behavior with redraw=%d\n", redraw);
SendMessage(hwndRichEdit, WM_SETREDRAW, redraw, 0);
/* Test behavior with carriage returns and newlines */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
r = SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM) "RichEdit1");
ok(9 == r, "EM_REPLACESEL returned %d, expected 9\n", r);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
r = strcmp(buffer, "RichEdit1");
ok(0 == r, "expected %d, got %d\n", 0, r);
getText.cb = 1024;
getText.codepage = CP_ACP;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buffer);
ok(strcmp(buffer, "RichEdit1") == 0,
"EM_GETTEXTEX results not what was set by EM_REPLACESEL\n");
/* Test number of lines reported after EM_REPLACESEL */
r = SendMessage(hwndRichEdit, EM_GETLINECOUNT, 0, 0);
ok(r == 1, "EM_GETLINECOUNT returned %d, expected 1\n", r);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
r = SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM) "RichEdit1\r");
ok(10 == r, "EM_REPLACESEL returned %d, expected 10\n", r);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
r = strcmp(buffer, "RichEdit1\r\n");
ok(0 == r, "expected %d, got %d\n", 0, r);
getText.cb = 1024;
getText.codepage = CP_ACP;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buffer);
ok(strcmp(buffer, "RichEdit1\r") == 0,
"EM_GETTEXTEX returned incorrect string\n");
/* Test number of lines reported after EM_REPLACESEL */
r = SendMessage(hwndRichEdit, EM_GETLINECOUNT, 0, 0);
ok(r == 2, "EM_GETLINECOUNT returned %d, expected 2\n", r);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
r = SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM) "RichEdit1\r\n");
ok(r == 11, "EM_REPLACESEL returned %d, expected 11\n", r);
/* Test number of lines reported after EM_REPLACESEL */
r = SendMessage(hwndRichEdit, EM_GETLINECOUNT, 0, 0);
ok(r == 2, "EM_GETLINECOUNT returned %d, expected 2\n", r);
r = SendMessage(hwndRichEdit, EM_EXGETSEL, 0, (LPARAM)&cr);
ok(0 == r, "EM_EXGETSEL returned %d, expected 0\n", r);
ok(cr.cpMin == 10, "EM_EXGETSEL returned cpMin=%d, expected 10\n", cr.cpMin);
ok(cr.cpMax == 10, "EM_EXGETSEL returned cpMax=%d, expected 10\n", cr.cpMax);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
r = strcmp(buffer, "RichEdit1\r\n");
ok(0 == r, "expected %d, got %d\n", 0, r);
getText.cb = 1024;
getText.codepage = CP_ACP;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buffer);
ok(strcmp(buffer, "RichEdit1\r") == 0,
"EM_GETTEXTEX returned incorrect string\n");
r = SendMessage(hwndRichEdit, EM_EXGETSEL, 0, (LPARAM)&cr);
ok(0 == r, "EM_EXGETSEL returned %d, expected 0\n", r);
ok(cr.cpMin == 10, "EM_EXGETSEL returned cpMin=%d, expected 10\n", cr.cpMin);
ok(cr.cpMax == 10, "EM_EXGETSEL returned cpMax=%d, expected 10\n", cr.cpMax);
/* The following tests show that richedit should handle the special \r\r\n
sequence by turning it into a single space on insertion. However,
EM_REPLACESEL on WinXP returns the number of characters in the original
string.
*/
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
r = SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM) "\r\r");
ok(2 == r, "EM_REPLACESEL returned %d, expected 4\n", r);
r = SendMessage(hwndRichEdit, EM_EXGETSEL, 0, (LPARAM)&cr);
ok(0 == r, "EM_EXGETSEL returned %d, expected 0\n", r);
ok(cr.cpMin == 2, "EM_EXGETSEL returned cpMin=%d, expected 2\n", cr.cpMin);
ok(cr.cpMax == 2, "EM_EXGETSEL returned cpMax=%d, expected 2\n", cr.cpMax);
/* Test the actual string */
getText.cb = 1024;
getText.codepage = CP_ACP;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buffer);
ok(strcmp(buffer, "\r\r") == 0,
"EM_GETTEXTEX returned incorrect string\n");
/* Test number of lines reported after EM_REPLACESEL */
r = SendMessage(hwndRichEdit, EM_GETLINECOUNT, 0, 0);
ok(r == 3, "EM_GETLINECOUNT returned %d, expected 3\n", r);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
r = SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM) "\r\r\n");
ok(r == 3, "EM_REPLACESEL returned %d, expected 3\n", r);
r = SendMessage(hwndRichEdit, EM_EXGETSEL, 0, (LPARAM)&cr);
ok(0 == r, "EM_EXGETSEL returned %d, expected 0\n", r);
ok(cr.cpMin == 1, "EM_EXGETSEL returned cpMin=%d, expected 1\n", cr.cpMin);
ok(cr.cpMax == 1, "EM_EXGETSEL returned cpMax=%d, expected 1\n", cr.cpMax);
/* Test the actual string */
getText.cb = 1024;
getText.codepage = CP_ACP;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buffer);
ok(strcmp(buffer, " ") == 0,
"EM_GETTEXTEX returned incorrect string\n");
/* Test number of lines reported after EM_REPLACESEL */
r = SendMessage(hwndRichEdit, EM_GETLINECOUNT, 0, 0);
ok(r == 1, "EM_GETLINECOUNT returned %d, expected 1\n", r);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
r = SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM) "\r\r\r\r\r\n\r\r\r");
ok(r == 9, "EM_REPLACESEL returned %d, expected 9\n", r);
r = SendMessage(hwndRichEdit, EM_EXGETSEL, 0, (LPARAM)&cr);
ok(0 == r, "EM_EXGETSEL returned %d, expected 0\n", r);
ok(cr.cpMin == 7, "EM_EXGETSEL returned cpMin=%d, expected 7\n", cr.cpMin);
ok(cr.cpMax == 7, "EM_EXGETSEL returned cpMax=%d, expected 7\n", cr.cpMax);
/* Test the actual string */
getText.cb = 1024;
getText.codepage = CP_ACP;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buffer);
ok(strcmp(buffer, "\r\r\r \r\r\r") == 0,
"EM_GETTEXTEX returned incorrect string\n");
/* Test number of lines reported after EM_REPLACESEL */
r = SendMessage(hwndRichEdit, EM_GETLINECOUNT, 0, 0);
ok(r == 7, "EM_GETLINECOUNT returned %d, expected 7\n", r);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
r = SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM) "\r\r\n\r\n");
ok(r == 5, "EM_REPLACESEL returned %d, expected 5\n", r);
r = SendMessage(hwndRichEdit, EM_EXGETSEL, 0, (LPARAM)&cr);
ok(0 == r, "EM_EXGETSEL returned %d, expected 0\n", r);
ok(cr.cpMin == 2, "EM_EXGETSEL returned cpMin=%d, expected 2\n", cr.cpMin);
ok(cr.cpMax == 2, "EM_EXGETSEL returned cpMax=%d, expected 2\n", cr.cpMax);
/* Test the actual string */
getText.cb = 1024;
getText.codepage = CP_ACP;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buffer);
ok(strcmp(buffer, " \r") == 0,
"EM_GETTEXTEX returned incorrect string\n");
/* Test number of lines reported after EM_REPLACESEL */
r = SendMessage(hwndRichEdit, EM_GETLINECOUNT, 0, 0);
ok(r == 2, "EM_GETLINECOUNT returned %d, expected 2\n", r);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
r = SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM) "\r\r\n\r\r");
ok(r == 5, "EM_REPLACESEL returned %d, expected 5\n", r);
r = SendMessage(hwndRichEdit, EM_EXGETSEL, 0, (LPARAM)&cr);
ok(0 == r, "EM_EXGETSEL returned %d, expected 0\n", r);
ok(cr.cpMin == 3, "EM_EXGETSEL returned cpMin=%d, expected 3\n", cr.cpMin);
ok(cr.cpMax == 3, "EM_EXGETSEL returned cpMax=%d, expected 3\n", cr.cpMax);
/* Test the actual string */
getText.cb = 1024;
getText.codepage = CP_ACP;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buffer);
ok(strcmp(buffer, " \r\r") == 0,
"EM_GETTEXTEX returned incorrect string\n");
/* Test number of lines reported after EM_REPLACESEL */
r = SendMessage(hwndRichEdit, EM_GETLINECOUNT, 0, 0);
ok(r == 3, "EM_GETLINECOUNT returned %d, expected 3\n", r);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
r = SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM) "\rX\r\n\r\r");
ok(r == 6, "EM_REPLACESEL returned %d, expected 6\n", r);
r = SendMessage(hwndRichEdit, EM_EXGETSEL, 0, (LPARAM)&cr);
ok(0 == r, "EM_EXGETSEL returned %d, expected 0\n", r);
ok(cr.cpMin == 5, "EM_EXGETSEL returned cpMin=%d, expected 5\n", cr.cpMin);
ok(cr.cpMax == 5, "EM_EXGETSEL returned cpMax=%d, expected 5\n", cr.cpMax);
/* Test the actual string */
getText.cb = 1024;
getText.codepage = CP_ACP;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buffer);
ok(strcmp(buffer, "\rX\r\r\r") == 0,
"EM_GETTEXTEX returned incorrect string\n");
/* Test number of lines reported after EM_REPLACESEL */
r = SendMessage(hwndRichEdit, EM_GETLINECOUNT, 0, 0);
ok(r == 5, "EM_GETLINECOUNT returned %d, expected 5\n", r);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
r = SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM) "\n\n");
ok(2 == r, "EM_REPLACESEL returned %d, expected 2\n", r);
r = SendMessage(hwndRichEdit, EM_EXGETSEL, 0, (LPARAM)&cr);
ok(0 == r, "EM_EXGETSEL returned %d, expected 0\n", r);
ok(cr.cpMin == 2, "EM_EXGETSEL returned cpMin=%d, expected 2\n", cr.cpMin);
ok(cr.cpMax == 2, "EM_EXGETSEL returned cpMax=%d, expected 2\n", cr.cpMax);
/* Test the actual string */
getText.cb = 1024;
getText.codepage = CP_ACP;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buffer);
ok(strcmp(buffer, "\r\r") == 0,
"EM_GETTEXTEX returned incorrect string\n");
/* Test number of lines reported after EM_REPLACESEL */
r = SendMessage(hwndRichEdit, EM_GETLINECOUNT, 0, 0);
ok(r == 3, "EM_GETLINECOUNT returned %d, expected 3\n", r);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
r = SendMessage(hwndRichEdit, EM_REPLACESEL, 0, (LPARAM) "\n\n\n\n\r\r\r\r\n");
ok(r == 9, "EM_REPLACESEL returned %d, expected 9\n", r);
r = SendMessage(hwndRichEdit, EM_EXGETSEL, 0, (LPARAM)&cr);
ok(0 == r, "EM_EXGETSEL returned %d, expected 0\n", r);
ok(cr.cpMin == 7, "EM_EXGETSEL returned cpMin=%d, expected 7\n", cr.cpMin);
ok(cr.cpMax == 7, "EM_EXGETSEL returned cpMax=%d, expected 7\n", cr.cpMax);
/* Test the actual string */
getText.cb = 1024;
getText.codepage = CP_ACP;
getText.flags = GT_DEFAULT;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buffer);
ok(strcmp(buffer, "\r\r\r\r\r\r ") == 0,
"EM_GETTEXTEX returned incorrect string\n");
/* Test number of lines reported after EM_REPLACESEL */
r = SendMessage(hwndRichEdit, EM_GETLINECOUNT, 0, 0);
ok(r == 7, "EM_GETLINECOUNT returned %d, expected 7\n", r);
if (!redraw)
/* This is needed to avoid interferring with keybd_event calls
* on other tests that simulate keyboard events. */
SendMessage(hwndRichEdit, WM_SETREDRAW, TRUE, 0);
DestroyWindow(hwndRichEdit);
}
/* Native riched20 inspects the keyboard state (e.g. GetKeyState)
* to test the state of the modifiers (Ctrl/Alt/Shift).
*
* Therefore Ctrl-<key> keystrokes need to be simulated with
* keybd_event or by using SetKeyboardState to set the modifiers
* and SendMessage to simulate the keystrokes.
*/
static LRESULT send_ctrl_key(HWND hwnd, UINT key)
{
LRESULT result;
hold_key(VK_CONTROL);
result = SendMessage(hwnd, WM_KEYDOWN, key, 1);
release_key(VK_CONTROL);
return result;
}
static void test_WM_PASTE(void)
{
int result;
char buffer[1024] = {0};
const char* text1 = "testing paste\r";
const char* text1_step1 = "testing paste\r\ntesting paste\r\n";
const char* text1_after = "testing paste\r\n";
const char* text2 = "testing paste\r\rtesting paste";
const char* text2_after = "testing paste\r\n\r\ntesting paste";
const char* text3 = "testing paste\r\npaste\r\ntesting paste";
HWND hwndRichEdit = new_richedit(NULL);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text1);
SendMessage(hwndRichEdit, EM_SETSEL, 0, 14);
send_ctrl_key(hwndRichEdit, 'C'); /* Copy */
SendMessage(hwndRichEdit, EM_SETSEL, 14, 14);
send_ctrl_key(hwndRichEdit, 'V'); /* Paste */
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
/* Pasted text should be visible at this step */
result = strcmp(text1_step1, buffer);
ok(result == 0,
"test paste: strcmp = %i, text='%s'\n", result, buffer);
send_ctrl_key(hwndRichEdit, 'Z'); /* Undo */
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
/* Text should be the same as before (except for \r -> \r\n conversion) */
result = strcmp(text1_after, buffer);
ok(result == 0,
"test paste: strcmp = %i, text='%s'\n", result, buffer);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text2);
SendMessage(hwndRichEdit, EM_SETSEL, 8, 13);
send_ctrl_key(hwndRichEdit, 'C'); /* Copy */
SendMessage(hwndRichEdit, EM_SETSEL, 14, 14);
send_ctrl_key(hwndRichEdit, 'V'); /* Paste */
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
/* Pasted text should be visible at this step */
result = strcmp(text3, buffer);
ok(result == 0,
"test paste: strcmp = %i\n", result);
send_ctrl_key(hwndRichEdit, 'Z'); /* Undo */
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
/* Text should be the same as before (except for \r -> \r\n conversion) */
result = strcmp(text2_after, buffer);
ok(result == 0,
"test paste: strcmp = %i\n", result);
send_ctrl_key(hwndRichEdit, 'Y'); /* Redo */
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
/* Text should revert to post-paste state */
result = strcmp(buffer,text3);
ok(result == 0,
"test paste: strcmp = %i\n", result);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
/* Send WM_CHAR to simulates Ctrl-V */
SendMessage(hwndRichEdit, WM_CHAR, 22,
(MapVirtualKey('V', MAPVK_VK_TO_VSC) << 16) | 1);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
/* Shouldn't paste because pasting is handled by WM_KEYDOWN */
result = strcmp(buffer,"");
ok(result == 0,
"test paste: strcmp = %i, actual = '%s'\n", result, buffer);
/* Send keystrokes with WM_KEYDOWN after setting the modifiers
* with SetKeyboard state. */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
/* Simulates paste (Ctrl-V) */
hold_key(VK_CONTROL);
SendMessage(hwndRichEdit, WM_KEYDOWN, 'V',
(MapVirtualKey('V', MAPVK_VK_TO_VSC) << 16) | 1);
release_key(VK_CONTROL);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
result = strcmp(buffer,"paste");
ok(result == 0,
"test paste: strcmp = %i, actual = '%s'\n", result, buffer);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) text1);
SendMessage(hwndRichEdit, EM_SETSEL, 0, 7);
/* Simulates copy (Ctrl-C) */
hold_key(VK_CONTROL);
SendMessage(hwndRichEdit, WM_KEYDOWN, 'C',
(MapVirtualKey('C', MAPVK_VK_TO_VSC) << 16) | 1);
release_key(VK_CONTROL);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
SendMessage(hwndRichEdit, WM_PASTE, 0, 0);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
result = strcmp(buffer,"testing");
ok(result == 0,
"test paste: strcmp = %i, actual = '%s'\n", result, buffer);
/* Cut with WM_KEYDOWN to simulate Ctrl-X */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) "cut");
/* Simulates select all (Ctrl-A) */
hold_key(VK_CONTROL);
SendMessage(hwndRichEdit, WM_KEYDOWN, 'A',
(MapVirtualKey('A', MAPVK_VK_TO_VSC) << 16) | 1);
/* Simulates select cut (Ctrl-X) */
SendMessage(hwndRichEdit, WM_KEYDOWN, 'X',
(MapVirtualKey('X', MAPVK_VK_TO_VSC) << 16) | 1);
release_key(VK_CONTROL);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
result = strcmp(buffer,"");
ok(result == 0,
"test paste: strcmp = %i, actual = '%s'\n", result, buffer);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, 0);
SendMessage(hwndRichEdit, WM_PASTE, 0, 0);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
result = strcmp(buffer,"cut\r\n");
todo_wine ok(result == 0,
"test paste: strcmp = %i, actual = '%s'\n", result, buffer);
/* Simulates undo (Ctrl-Z) */
hold_key(VK_CONTROL);
SendMessage(hwndRichEdit, WM_KEYDOWN, 'Z',
(MapVirtualKey('Z', MAPVK_VK_TO_VSC) << 16) | 1);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
result = strcmp(buffer,"");
ok(result == 0,
"test paste: strcmp = %i, actual = '%s'\n", result, buffer);
/* Simulates redo (Ctrl-Y) */
SendMessage(hwndRichEdit, WM_KEYDOWN, 'Y',
(MapVirtualKey('Y', MAPVK_VK_TO_VSC) << 16) | 1);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
result = strcmp(buffer,"cut\r\n");
todo_wine ok(result == 0,
"test paste: strcmp = %i, actual = '%s'\n", result, buffer);
release_key(VK_CONTROL);
DestroyWindow(hwndRichEdit);
}
static void test_EM_FORMATRANGE(void)
{
int r, i, tpp_x, tpp_y;
HDC hdc;
HWND hwndRichEdit = new_richedit(NULL);
FORMATRANGE fr;
BOOL skip_non_english;
static const struct {
const char *string; /* The string */
int first; /* First 'pagebreak', 0 for don't care */
int second; /* Second 'pagebreak', 0 for don't care */
} fmtstrings[] = {
{"WINE wine", 0, 0},
{"WINE wineWine", 0, 0},
{"WINE\r\nwine\r\nwine", 5, 10},
{"WINE\r\nWINEwine\r\nWINEwine", 5, 14},
{"WINE\r\n\r\nwine\r\nwine", 5, 6}
};
skip_non_english = (PRIMARYLANGID(GetUserDefaultLangID()) != LANG_ENGLISH);
if (skip_non_english)
skip("Skipping some tests on non-English platform\n");
hdc = GetDC(hwndRichEdit);
ok(hdc != NULL, "Could not get HDC\n");
/* Calculate the twips per pixel */
tpp_x = 1440 / GetDeviceCaps(hdc, LOGPIXELSX);
tpp_y = 1440 / GetDeviceCaps(hdc, LOGPIXELSY);
/* Test the simple case where all the text fits in the page rect. */
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"a");
fr.hdc = fr.hdcTarget = hdc;
fr.rc.top = fr.rcPage.top = fr.rc.left = fr.rcPage.left = 0;
fr.rc.right = fr.rcPage.right = 500 * tpp_x;
fr.rc.bottom = fr.rcPage.bottom = 500 * tpp_y;
fr.chrg.cpMin = 0;
fr.chrg.cpMax = -1;
r = SendMessage(hwndRichEdit, EM_FORMATRANGE, FALSE, (LPARAM)&fr);
todo_wine ok(r == 2, "r=%d expected r=2\n", r);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)"ab");
fr.rc.bottom = fr.rcPage.bottom;
r = SendMessage(hwndRichEdit, EM_FORMATRANGE, FALSE, (LPARAM)&fr);
todo_wine ok(r == 3, "r=%d expected r=3\n", r);
SendMessage(hwndRichEdit, EM_FORMATRANGE, FALSE, 0);
for (i = 0; i < sizeof(fmtstrings)/sizeof(fmtstrings[0]); i++)
{
GETTEXTLENGTHEX gtl;
SIZE stringsize;
int len;
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) fmtstrings[i].string);
gtl.flags = GTL_NUMCHARS | GTL_PRECISE;
gtl.codepage = CP_ACP;
len = SendMessageA(hwndRichEdit, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
/* Get some size information for the string */
GetTextExtentPoint32(hdc, fmtstrings[i].string, strlen(fmtstrings[i].string), &stringsize);
/* Define the box to be half the width needed and a bit larger than the height.
* Changes to the width means we have at least 2 pages. Changes to the height
* is done so we can check the changing of fr.rc.bottom.
*/
fr.hdc = fr.hdcTarget = hdc;
fr.rc.top = fr.rcPage.top = fr.rc.left = fr.rcPage.left = 0;
fr.rc.right = fr.rcPage.right = (stringsize.cx / 2) * tpp_x;
fr.rc.bottom = fr.rcPage.bottom = (stringsize.cy + 10) * tpp_y;
r = SendMessage(hwndRichEdit, EM_FORMATRANGE, TRUE, 0);
todo_wine {
ok(r == len, "Expected %d, got %d\n", len, r);
}
/* We know that the page can't hold the full string. See how many characters
* are on the first one
*/
fr.chrg.cpMin = 0;
fr.chrg.cpMax = -1;
r = SendMessage(hwndRichEdit, EM_FORMATRANGE, TRUE, (LPARAM) &fr);
todo_wine {
if (! skip_non_english)
ok(fr.rc.bottom == (stringsize.cy * tpp_y), "Expected bottom to be %d, got %d\n", (stringsize.cy * tpp_y), fr.rc.bottom);
}
if (fmtstrings[i].first)
todo_wine {
ok(r == fmtstrings[i].first, "Expected %d, got %d\n", fmtstrings[i].first, r);
}
else
ok(r < len, "Expected < %d, got %d\n", len, r);
/* Do another page */
fr.chrg.cpMin = r;
r = SendMessage(hwndRichEdit, EM_FORMATRANGE, TRUE, (LPARAM) &fr);
if (fmtstrings[i].second)
todo_wine {
ok(r == fmtstrings[i].second, "Expected %d, got %d\n", fmtstrings[i].second, r);
}
else if (! skip_non_english)
ok (r < len, "Expected < %d, got %d\n", len, r);
/* There is at least on more page, but we don't care */
r = SendMessage(hwndRichEdit, EM_FORMATRANGE, TRUE, 0);
todo_wine {
ok(r == len, "Expected %d, got %d\n", len, r);
}
}
ReleaseDC(NULL, hdc);
DestroyWindow(hwndRichEdit);
}
static int nCallbackCount = 0;
static DWORD CALLBACK EditStreamCallback(DWORD_PTR dwCookie, LPBYTE pbBuff,
LONG cb, LONG* pcb)
{
const char text[] = {'t','e','s','t'};
if (sizeof(text) <= cb)
{
if ((int)dwCookie != nCallbackCount)
{
*pcb = 0;
return 0;
}
memcpy (pbBuff, text, sizeof(text));
*pcb = sizeof(text);
nCallbackCount++;
return 0;
}
else
return 1; /* indicates callback failed */
}
static DWORD CALLBACK test_EM_STREAMIN_esCallback(DWORD_PTR dwCookie,
LPBYTE pbBuff,
LONG cb,
LONG *pcb)
{
const char** str = (const char**)dwCookie;
int size = strlen(*str);
*pcb = cb;
if (*pcb > size) {
*pcb = size;
}
if (*pcb > 0) {
memcpy(pbBuff, *str, *pcb);
*str += *pcb;
}
return 0;
}
struct StringWithLength {
int length;
char *buffer;
};
/* This callback is used to handled the null characters in a string. */
static DWORD CALLBACK test_EM_STREAMIN_esCallback2(DWORD_PTR dwCookie,
LPBYTE pbBuff,
LONG cb,
LONG *pcb)
{
struct StringWithLength* str = (struct StringWithLength*)dwCookie;
int size = str->length;
*pcb = cb;
if (*pcb > size) {
*pcb = size;
}
if (*pcb > 0) {
memcpy(pbBuff, str->buffer, *pcb);
str->buffer += *pcb;
str->length -= *pcb;
}
return 0;
}
static void test_EM_STREAMIN(void)
{
HWND hwndRichEdit = new_richedit(NULL);
LRESULT result;
EDITSTREAM es;
char buffer[1024] = {0};
const char * streamText0 = "{\\rtf1 TestSomeText}";
const char * streamText0a = "{\\rtf1 TestSomeText\\par}";
const char * streamText0b = "{\\rtf1 TestSomeText\\par\\par}";
const char * streamText1 =
"{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang12298{\\fonttbl{\\f0\\fswiss\\fprq2\\fcharset0 System;}}\r\n"
"\\viewkind4\\uc1\\pard\\f0\\fs17 TestSomeText\\par\r\n"
"}\r\n";
/* In richedit 2.0 mode, this should NOT be accepted, unlike 1.0 */
const char * streamText2 =
"{{\\colortbl;\\red0\\green255\\blue102;\\red255\\green255\\blue255;"
"\\red170\\green255\\blue255;\\red255\\green238\\blue0;\\red51\\green255"
"\\blue221;\\red238\\green238\\blue238;}\\tx0 \\tx424 \\tx848 \\tx1272 "
"\\tx1696 \\tx2120 \\tx2544 \\tx2968 \\tx3392 \\tx3816 \\tx4240 \\tx4664 "
"\\tx5088 \\tx5512 \\tx5936 \\tx6360 \\tx6784 \\tx7208 \\tx7632 \\tx8056 "
"\\tx8480 \\tx8904 \\tx9328 \\tx9752 \\tx10176 \\tx10600 \\tx11024 "
"\\tx11448 \\tx11872 \\tx12296 \\tx12720 \\tx13144 \\cf2 RichEdit1\\line }";
const char * streamText3 = "RichEdit1";
const char * streamText4 =
"This text just needs to be long enough to cause run to be split onto "
"two separate lines and make sure the null terminating character is "
"handled properly.\0";
int length4 = strlen(streamText4) + 1;
struct StringWithLength cookieForStream4 = {
length4,
(char *)streamText4,
};
const WCHAR streamText5[] = { 'T', 'e', 's', 't', 'S', 'o', 'm', 'e', 'T', 'e', 'x', 't' };
int length5 = sizeof(streamText5) / sizeof(WCHAR);
struct StringWithLength cookieForStream5 = {
sizeof(streamText5),
(char *)streamText5,
};
/* Minimal test without \par at the end */
es.dwCookie = (DWORD_PTR)&streamText0;
es.dwError = 0;
es.pfnCallback = test_EM_STREAMIN_esCallback;
result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
ok(result == 12, "got %ld, expected %d\n", result, 12);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok (result == 12,
"EM_STREAMIN: Test 0 returned %ld, expected 12\n", result);
result = strcmp (buffer,"TestSomeText");
ok (result == 0,
"EM_STREAMIN: Test 0 set wrong text: Result: %s\n",buffer);
ok(es.dwError == 0, "EM_STREAMIN: Test 0 set error %d, expected %d\n", es.dwError, 0);
/* Native richedit 2.0 ignores last \par */
es.dwCookie = (DWORD_PTR)&streamText0a;
es.dwError = 0;
es.pfnCallback = test_EM_STREAMIN_esCallback;
result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
ok(result == 12, "got %ld, expected %d\n", result, 12);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok (result == 12,
"EM_STREAMIN: Test 0-a returned %ld, expected 12\n", result);
result = strcmp (buffer,"TestSomeText");
ok (result == 0,
"EM_STREAMIN: Test 0-a set wrong text: Result: %s\n",buffer);
ok(es.dwError == 0, "EM_STREAMIN: Test 0-a set error %d, expected %d\n", es.dwError, 0);
/* Native richedit 2.0 ignores last \par, next-to-last \par appears */
es.dwCookie = (DWORD_PTR)&streamText0b;
es.dwError = 0;
es.pfnCallback = test_EM_STREAMIN_esCallback;
result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
ok(result == 13, "got %ld, expected %d\n", result, 13);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok (result == 14,
"EM_STREAMIN: Test 0-b returned %ld, expected 14\n", result);
result = strcmp (buffer,"TestSomeText\r\n");
ok (result == 0,
"EM_STREAMIN: Test 0-b set wrong text: Result: %s\n",buffer);
ok(es.dwError == 0, "EM_STREAMIN: Test 0-b set error %d, expected %d\n", es.dwError, 0);
es.dwCookie = (DWORD_PTR)&streamText1;
es.dwError = 0;
es.pfnCallback = test_EM_STREAMIN_esCallback;
result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
ok(result == 12, "got %ld, expected %d\n", result, 12);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok (result == 12,
"EM_STREAMIN: Test 1 returned %ld, expected 12\n", result);
result = strcmp (buffer,"TestSomeText");
ok (result == 0,
"EM_STREAMIN: Test 1 set wrong text: Result: %s\n",buffer);
ok(es.dwError == 0, "EM_STREAMIN: Test 1 set error %d, expected %d\n", es.dwError, 0);
es.dwCookie = (DWORD_PTR)&streamText2;
es.dwError = 0;
result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
ok(result == 0, "got %ld, expected %d\n", result, 0);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok (result == 0,
"EM_STREAMIN: Test 2 returned %ld, expected 0\n", result);
ok (strlen(buffer) == 0,
"EM_STREAMIN: Test 2 set wrong text: Result: %s\n",buffer);
ok(es.dwError == -16, "EM_STREAMIN: Test 2 set error %d, expected %d\n", es.dwError, -16);
es.dwCookie = (DWORD_PTR)&streamText3;
es.dwError = 0;
result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_RTF, (LPARAM)&es);
ok(result == 0, "got %ld, expected %d\n", result, 0);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok (result == 0,
"EM_STREAMIN: Test 3 returned %ld, expected 0\n", result);
ok (strlen(buffer) == 0,
"EM_STREAMIN: Test 3 set wrong text: Result: %s\n",buffer);
ok(es.dwError == -16, "EM_STREAMIN: Test 3 set error %d, expected %d\n", es.dwError, -16);
es.dwCookie = (DWORD_PTR)&cookieForStream4;
es.dwError = 0;
es.pfnCallback = test_EM_STREAMIN_esCallback2;
result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_TEXT, (LPARAM)&es);
ok(result == length4, "got %ld, expected %d\n", result, length4);
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok (result == length4,
"EM_STREAMIN: Test 4 returned %ld, expected %d\n", result, length4);
ok(es.dwError == 0, "EM_STREAMIN: Test 4 set error %d, expected %d\n", es.dwError, 0);
es.dwCookie = (DWORD_PTR)&cookieForStream5;
es.dwError = 0;
es.pfnCallback = test_EM_STREAMIN_esCallback2;
result = SendMessage(hwndRichEdit, EM_STREAMIN, SF_TEXT | SF_UNICODE, (LPARAM)&es);
ok(result == sizeof(streamText5), "got %ld, expected %u\n", result, (UINT)sizeof(streamText5));
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
ok (result == length5,
"EM_STREAMIN: Test 4 returned %ld, expected %d\n", result, length5);
ok(es.dwError == 0, "EM_STREAMIN: Test 5 set error %d, expected %d\n", es.dwError, 0);
DestroyWindow(hwndRichEdit);
}
static void test_EM_StreamIn_Undo(void)
{
/* The purpose of this test is to determine when a EM_StreamIn should be
* undoable. This is important because WM_PASTE currently uses StreamIn and
* pasting should always be undoable but streaming isn't always.
*
* cases to test:
* StreamIn plain text without SFF_SELECTION.
* StreamIn plain text with SFF_SELECTION set but a zero-length selection
* StreamIn plain text with SFF_SELECTION and a valid, normal selection
* StreamIn plain text with SFF_SELECTION and a backwards-selection (from>to)
* Feel free to add tests for other text modes or StreamIn things.
*/
HWND hwndRichEdit = new_richedit(NULL);
LRESULT result;
EDITSTREAM es;
char buffer[1024] = {0};
const char randomtext[] = "Some text";
es.pfnCallback = (EDITSTREAMCALLBACK) EditStreamCallback;
/* StreamIn, no SFF_SELECTION */
es.dwCookie = nCallbackCount;
SendMessage(hwndRichEdit,EM_EMPTYUNDOBUFFER, 0,0);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) randomtext);
SendMessage(hwndRichEdit, EM_SETSEL,0,0);
SendMessage(hwndRichEdit, EM_STREAMIN, SF_TEXT, (LPARAM)&es);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
result = strcmp (buffer,"test");
ok (result == 0,
"EM_STREAMIN: Test 1 set wrong text: Result: %s\n",buffer);
result = SendMessage(hwndRichEdit, EM_CANUNDO, 0, 0);
ok (result == FALSE,
"EM_STREAMIN without SFF_SELECTION wrongly allows undo\n");
/* StreamIn, SFF_SELECTION, but nothing selected */
es.dwCookie = nCallbackCount;
SendMessage(hwndRichEdit,EM_EMPTYUNDOBUFFER, 0,0);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) randomtext);
SendMessage(hwndRichEdit, EM_SETSEL,0,0);
SendMessage(hwndRichEdit, EM_STREAMIN, SF_TEXT|SFF_SELECTION, (LPARAM)&es);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
result = strcmp (buffer,"testSome text");
ok (result == 0,
"EM_STREAMIN: Test 2 set wrong text: Result: %s\n",buffer);
result = SendMessage(hwndRichEdit, EM_CANUNDO, 0, 0);
ok (result == TRUE,
"EM_STREAMIN with SFF_SELECTION but no selection set "
"should create an undo\n");
/* StreamIn, SFF_SELECTION, with a selection */
es.dwCookie = nCallbackCount;
SendMessage(hwndRichEdit,EM_EMPTYUNDOBUFFER, 0,0);
SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) randomtext);
SendMessage(hwndRichEdit, EM_SETSEL,4,5);
SendMessage(hwndRichEdit, EM_STREAMIN, SF_TEXT|SFF_SELECTION, (LPARAM)&es);
SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buffer);
result = strcmp (buffer,"Sometesttext");
ok (result == 0,
"EM_STREAMIN: Test 2 set wrong text: Result: %s\n",buffer);
result = SendMessage(hwndRichEdit, EM_CANUNDO, 0, 0);
ok (result == TRUE,
"EM_STREAMIN with SFF_SELECTION and selection set "
"should create an undo\n");
DestroyWindow(hwndRichEdit);
}
static BOOL is_em_settextex_supported(HWND hwnd)
{
SETTEXTEX stex = { ST_DEFAULT, CP_ACP };
return SendMessageA(hwnd, EM_SETTEXTEX, (WPARAM)&stex, 0) != 0;
}
static void test_unicode_conversions(void)
{
static const WCHAR tW[] = {'t',0};
static const WCHAR teW[] = {'t','e',0};
static const WCHAR textW[] = {'t','e','s','t',0};
static const char textA[] = "test";
char bufA[64];
WCHAR bufW[64];
HWND hwnd;
int em_settextex_supported, ret;
#define set_textA(hwnd, wm_set_text, txt) \
do { \
SETTEXTEX stex = { ST_DEFAULT, CP_ACP }; \
WPARAM wparam = (wm_set_text == WM_SETTEXT) ? 0 : (WPARAM)&stex; \
assert(wm_set_text == WM_SETTEXT || wm_set_text == EM_SETTEXTEX); \
ret = SendMessageA(hwnd, wm_set_text, wparam, (LPARAM)txt); \
ok(ret, "SendMessageA(%02x) error %u\n", wm_set_text, GetLastError()); \
} while(0)
#define expect_textA(hwnd, wm_get_text, txt) \
do { \
GETTEXTEX gtex = { 64, GT_DEFAULT, CP_ACP, NULL, NULL }; \
WPARAM wparam = (wm_get_text == WM_GETTEXT) ? 64 : (WPARAM)>ex; \
assert(wm_get_text == WM_GETTEXT || wm_get_text == EM_GETTEXTEX); \
memset(bufA, 0xAA, sizeof(bufA)); \
ret = SendMessageA(hwnd, wm_get_text, wparam, (LPARAM)bufA); \
ok(ret, "SendMessageA(%02x) error %u\n", wm_get_text, GetLastError()); \
ret = lstrcmpA(bufA, txt); \
ok(!ret, "%02x: strings do not match: expected %s got %s\n", wm_get_text, txt, bufA); \
} while(0)
#define set_textW(hwnd, wm_set_text, txt) \
do { \
SETTEXTEX stex = { ST_DEFAULT, 1200 }; \
WPARAM wparam = (wm_set_text == WM_SETTEXT) ? 0 : (WPARAM)&stex; \
assert(wm_set_text == WM_SETTEXT || wm_set_text == EM_SETTEXTEX); \
ret = SendMessageW(hwnd, wm_set_text, wparam, (LPARAM)txt); \
ok(ret, "SendMessageW(%02x) error %u\n", wm_set_text, GetLastError()); \
} while(0)
#define expect_textW(hwnd, wm_get_text, txt) \
do { \
GETTEXTEX gtex = { 64, GT_DEFAULT, 1200, NULL, NULL }; \
WPARAM wparam = (wm_get_text == WM_GETTEXT) ? 64 : (WPARAM)>ex; \
assert(wm_get_text == WM_GETTEXT || wm_get_text == EM_GETTEXTEX); \
memset(bufW, 0xAA, sizeof(bufW)); \
ret = SendMessageW(hwnd, wm_get_text, wparam, (LPARAM)bufW); \
ok(ret, "SendMessageW(%02x) error %u\n", wm_get_text, GetLastError()); \
ret = lstrcmpW(bufW, txt); \
ok(!ret, "%02x: strings do not match: expected[0] %x got[0] %x\n", wm_get_text, txt[0], bufW[0]); \
} while(0)
#define expect_empty(hwnd, wm_get_text) \
do { \
GETTEXTEX gtex = { 64, GT_DEFAULT, CP_ACP, NULL, NULL }; \
WPARAM wparam = (wm_get_text == WM_GETTEXT) ? 64 : (WPARAM)>ex; \
assert(wm_get_text == WM_GETTEXT || wm_get_text == EM_GETTEXTEX); \
memset(bufA, 0xAA, sizeof(bufA)); \
ret = SendMessageA(hwnd, wm_get_text, wparam, (LPARAM)bufA); \
ok(!ret, "empty richedit should return 0, got %d\n", ret); \
ok(!*bufA, "empty richedit should return empty string, got %s\n", bufA); \
} while(0)
hwnd = CreateWindowExA(0, "RichEdit20W", NULL, WS_POPUP,
0, 0, 200, 60, 0, 0, 0, 0);
ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
ret = IsWindowUnicode(hwnd);
ok(ret, "RichEdit20W should be unicode under NT\n");
/* EM_SETTEXTEX is supported starting from version 3.0 */
em_settextex_supported = is_em_settextex_supported(hwnd);
trace("EM_SETTEXTEX is %ssupported on this platform\n",
em_settextex_supported ? "" : "NOT ");
expect_empty(hwnd, WM_GETTEXT);
expect_empty(hwnd, EM_GETTEXTEX);
ret = SendMessageA(hwnd, WM_CHAR, textW[0], 0);
ok(!ret, "SendMessageA(WM_CHAR) should return 0, got %d\n", ret);
expect_textA(hwnd, WM_GETTEXT, "t");
expect_textA(hwnd, EM_GETTEXTEX, "t");
expect_textW(hwnd, EM_GETTEXTEX, tW);
ret = SendMessageA(hwnd, WM_CHAR, textA[1], 0);
ok(!ret, "SendMessageA(WM_CHAR) should return 0, got %d\n", ret);
expect_textA(hwnd, WM_GETTEXT, "te");
expect_textA(hwnd, EM_GETTEXTEX, "te");
expect_textW(hwnd, EM_GETTEXTEX, teW);
set_textA(hwnd, WM_SETTEXT, NULL);
expect_empty(hwnd, WM_GETTEXT);
expect_empty(hwnd, EM_GETTEXTEX);
set_textA(hwnd, WM_SETTEXT, textA);
expect_textA(hwnd, WM_GETTEXT, textA);
expect_textA(hwnd, EM_GETTEXTEX, textA);
expect_textW(hwnd, EM_GETTEXTEX, textW);
if (em_settextex_supported)
{
set_textA(hwnd, EM_SETTEXTEX, textA);
expect_textA(hwnd, WM_GETTEXT, textA);
expect_textA(hwnd, EM_GETTEXTEX, textA);
expect_textW(hwnd, EM_GETTEXTEX, textW);
}
set_textW(hwnd, WM_SETTEXT, textW);
expect_textW(hwnd, WM_GETTEXT, textW);
expect_textA(hwnd, WM_GETTEXT, textA);
expect_textW(hwnd, EM_GETTEXTEX, textW);
expect_textA(hwnd, EM_GETTEXTEX, textA);
if (em_settextex_supported)
{
set_textW(hwnd, EM_SETTEXTEX, textW);
expect_textW(hwnd, WM_GETTEXT, textW);
expect_textA(hwnd, WM_GETTEXT, textA);
expect_textW(hwnd, EM_GETTEXTEX, textW);
expect_textA(hwnd, EM_GETTEXTEX, textA);
}
DestroyWindow(hwnd);
hwnd = CreateWindowExA(0, "RichEdit20A", NULL, WS_POPUP,
0, 0, 200, 60, 0, 0, 0, 0);
ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
ret = IsWindowUnicode(hwnd);
ok(!ret, "RichEdit20A should NOT be unicode\n");
set_textA(hwnd, WM_SETTEXT, textA);
expect_textA(hwnd, WM_GETTEXT, textA);
expect_textA(hwnd, EM_GETTEXTEX, textA);
expect_textW(hwnd, EM_GETTEXTEX, textW);
if (em_settextex_supported)
{
set_textA(hwnd, EM_SETTEXTEX, textA);
expect_textA(hwnd, WM_GETTEXT, textA);
expect_textA(hwnd, EM_GETTEXTEX, textA);
expect_textW(hwnd, EM_GETTEXTEX, textW);
}
set_textW(hwnd, WM_SETTEXT, textW);
expect_textW(hwnd, WM_GETTEXT, textW);
expect_textA(hwnd, WM_GETTEXT, textA);
expect_textW(hwnd, EM_GETTEXTEX, textW);
expect_textA(hwnd, EM_GETTEXTEX, textA);
if (em_settextex_supported)
{
set_textW(hwnd, EM_SETTEXTEX, textW);
expect_textW(hwnd, WM_GETTEXT, textW);
expect_textA(hwnd, WM_GETTEXT, textA);
expect_textW(hwnd, EM_GETTEXTEX, textW);
expect_textA(hwnd, EM_GETTEXTEX, textA);
}
DestroyWindow(hwnd);
}
static void test_WM_CHAR(void)
{
HWND hwnd;
int ret;
const char * char_list = "abc\rabc\r";
const char * expected_content_single = "abcabc";
const char * expected_content_multi = "abc\r\nabc\r\n";
char buffer[64] = {0};
const char * p;
/* single-line control must IGNORE carriage returns */
hwnd = CreateWindowExA(0, "RichEdit20W", NULL, WS_POPUP,
0, 0, 200, 60, 0, 0, 0, 0);
ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
p = char_list;
while (*p != '\0') {
SendMessageA(hwnd, WM_KEYDOWN, *p, 1);
ret = SendMessageA(hwnd, WM_CHAR, *p, 1);
ok(ret == 0, "WM_CHAR('%c') ret=%d\n", *p, ret);
SendMessageA(hwnd, WM_KEYUP, *p, 1);
p++;
}
SendMessage(hwnd, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
ret = strcmp(buffer, expected_content_single);
ok(ret == 0, "WM_GETTEXT recovered incorrect string!\n");
DestroyWindow(hwnd);
/* multi-line control inserts CR normally */
hwnd = CreateWindowExA(0, "RichEdit20W", NULL, WS_POPUP|ES_MULTILINE,
0, 0, 200, 60, 0, 0, 0, 0);
ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
p = char_list;
while (*p != '\0') {
SendMessageA(hwnd, WM_KEYDOWN, *p, 1);
ret = SendMessageA(hwnd, WM_CHAR, *p, 1);
ok(ret == 0, "WM_CHAR('%c') ret=%d\n", *p, ret);
SendMessageA(hwnd, WM_KEYUP, *p, 1);
p++;
}
SendMessage(hwnd, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
ret = strcmp(buffer, expected_content_multi);
ok(ret == 0, "WM_GETTEXT recovered incorrect string!\n");
DestroyWindow(hwnd);
}
static void test_EM_GETTEXTLENGTHEX(void)
{
HWND hwnd;
GETTEXTLENGTHEX gtl;
int ret;
const char * base_string = "base string";
const char * test_string = "a\nb\n\n\r\n";
const char * test_string_after = "a";
const char * test_string_2 = "a\rtest\rstring";
char buffer[64] = {0};
/* single line */
hwnd = CreateWindowExA(0, "RichEdit20W", NULL, WS_POPUP,
0, 0, 200, 60, 0, 0, 0, 0);
ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
gtl.flags = GTL_NUMCHARS | GTL_PRECISE | GTL_USECRLF;
gtl.codepage = CP_ACP;
ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
ok(ret == 0, "ret %d\n",ret);
gtl.flags = GTL_NUMCHARS | GTL_PRECISE;
gtl.codepage = CP_ACP;
ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
ok(ret == 0, "ret %d\n",ret);
SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) base_string);
gtl.flags = GTL_NUMCHARS | GTL_PRECISE | GTL_USECRLF;
gtl.codepage = CP_ACP;
ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
ok(ret == strlen(base_string), "ret %d\n",ret);
gtl.flags = GTL_NUMCHARS | GTL_PRECISE;
gtl.codepage = CP_ACP;
ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
ok(ret == strlen(base_string), "ret %d\n",ret);
SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) test_string);
gtl.flags = GTL_NUMCHARS | GTL_PRECISE | GTL_USECRLF;
gtl.codepage = CP_ACP;
ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
ok(ret == 1, "ret %d\n",ret);
gtl.flags = GTL_NUMCHARS | GTL_PRECISE;
gtl.codepage = CP_ACP;
ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
ok(ret == 1, "ret %d\n",ret);
SendMessage(hwnd, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
ret = strcmp(buffer, test_string_after);
ok(ret == 0, "WM_GETTEXT recovered incorrect string!\n");
DestroyWindow(hwnd);
/* multi line */
hwnd = CreateWindowExA(0, "RichEdit20W", NULL, WS_POPUP | ES_MULTILINE,
0, 0, 200, 60, 0, 0, 0, 0);
ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
gtl.flags = GTL_NUMCHARS | GTL_PRECISE | GTL_USECRLF;
gtl.codepage = CP_ACP;
ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
ok(ret == 0, "ret %d\n",ret);
gtl.flags = GTL_NUMCHARS | GTL_PRECISE;
gtl.codepage = CP_ACP;
ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
ok(ret == 0, "ret %d\n",ret);
SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) base_string);
gtl.flags = GTL_NUMCHARS | GTL_PRECISE | GTL_USECRLF;
gtl.codepage = CP_ACP;
ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
ok(ret == strlen(base_string), "ret %d\n",ret);
gtl.flags = GTL_NUMCHARS | GTL_PRECISE;
gtl.codepage = CP_ACP;
ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
ok(ret == strlen(base_string), "ret %d\n",ret);
SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) test_string_2);
gtl.flags = GTL_NUMCHARS | GTL_PRECISE | GTL_USECRLF;
gtl.codepage = CP_ACP;
ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
ok(ret == strlen(test_string_2) + 2, "ret %d\n",ret);
gtl.flags = GTL_NUMCHARS | GTL_PRECISE;
gtl.codepage = CP_ACP;
ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
ok(ret == strlen(test_string_2), "ret %d\n",ret);
SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) test_string);
gtl.flags = GTL_NUMCHARS | GTL_PRECISE | GTL_USECRLF;
gtl.codepage = CP_ACP;
ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
ok(ret == 10, "ret %d\n",ret);
gtl.flags = GTL_NUMCHARS | GTL_PRECISE;
gtl.codepage = CP_ACP;
ret = SendMessageA(hwnd, EM_GETTEXTLENGTHEX, (WPARAM)>l, 0);
ok(ret == 6, "ret %d\n",ret);
/* Unicode/NUMCHARS/NUMBYTES */
SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) test_string_2);
gtl.flags = GTL_DEFAULT;
gtl.codepage = 1200;
ret = SendMessage(hwnd, EM_GETTEXTLENGTHEX, (WPARAM) >l, 0);
ok(ret == lstrlen(test_string_2),
"GTL_DEFAULT gave %i, expected %i\n", ret, lstrlen(test_string_2));
gtl.flags = GTL_NUMCHARS;
gtl.codepage = 1200;
ret = SendMessage(hwnd, EM_GETTEXTLENGTHEX, (WPARAM) >l, 0);
ok(ret == lstrlen(test_string_2),
"GTL_NUMCHARS gave %i, expected %i\n", ret, lstrlen(test_string_2));
gtl.flags = GTL_NUMBYTES;
gtl.codepage = 1200;
ret = SendMessage(hwnd, EM_GETTEXTLENGTHEX, (WPARAM) >l, 0);
ok(ret == lstrlen(test_string_2)*2,
"GTL_NUMBYTES gave %i, expected %i\n", ret, lstrlen(test_string_2)*2);
gtl.flags = GTL_PRECISE;
gtl.codepage = 1200;
ret = SendMessage(hwnd, EM_GETTEXTLENGTHEX, (WPARAM) >l, 0);
ok(ret == lstrlen(test_string_2)*2,
"GTL_PRECISE gave %i, expected %i\n", ret, lstrlen(test_string_2)*2);
gtl.flags = GTL_NUMCHARS | GTL_PRECISE;
gtl.codepage = 1200;
ret = SendMessage(hwnd, EM_GETTEXTLENGTHEX, (WPARAM) >l, 0);
ok(ret == lstrlen(test_string_2),
"GTL_NUMCHAR | GTL_PRECISE gave %i, expected %i\n", ret, lstrlen(test_string_2));
gtl.flags = GTL_NUMCHARS | GTL_NUMBYTES;
gtl.codepage = 1200;
ret = SendMessage(hwnd, EM_GETTEXTLENGTHEX, (WPARAM) >l, 0);
ok(ret == E_INVALIDARG,
"GTL_NUMCHARS | GTL_NUMBYTES gave %i, expected %i\n", ret, E_INVALIDARG);
DestroyWindow(hwnd);
}
/* globals that parent and child access when checking event masks & notifications */
static HWND eventMaskEditHwnd = 0;
static int queriedEventMask;
static int watchForEventMask = 0;
/* parent proc that queries the edit's event mask when it gets a WM_COMMAND */
static LRESULT WINAPI ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if(message == WM_COMMAND && (watchForEventMask & (wParam >> 16)))
{
queriedEventMask = SendMessage(eventMaskEditHwnd, EM_GETEVENTMASK, 0, 0);
}
return DefWindowProcA(hwnd, message, wParam, lParam);
}
/* test event masks in combination with WM_COMMAND */
static void test_eventMask(void)
{
HWND parent;
int ret, style;
WNDCLASSA cls;
const char text[] = "foo bar\n";
int eventMask;
/* register class to capture WM_COMMAND */
cls.style = 0;
cls.lpfnWndProc = ParentMsgCheckProcA;
cls.cbClsExtra = 0;
cls.cbWndExtra = 0;
cls.hInstance = GetModuleHandleA(0);
cls.hIcon = 0;
cls.hCursor = LoadCursorA(0, IDC_ARROW);
cls.hbrBackground = GetStockObject(WHITE_BRUSH);
cls.lpszMenuName = NULL;
cls.lpszClassName = "EventMaskParentClass";
if(!RegisterClassA(&cls)) assert(0);
parent = CreateWindow(cls.lpszClassName, NULL, WS_POPUP|WS_VISIBLE,
0, 0, 200, 60, NULL, NULL, NULL, NULL);
ok (parent != 0, "Failed to create parent window\n");
eventMaskEditHwnd = new_richedit(parent);
ok(eventMaskEditHwnd != 0, "Failed to create edit window\n");
eventMask = ENM_CHANGE | ENM_UPDATE;
ret = SendMessage(eventMaskEditHwnd, EM_SETEVENTMASK, 0, eventMask);
ok(ret == ENM_NONE, "wrong event mask\n");
ret = SendMessage(eventMaskEditHwnd, EM_GETEVENTMASK, 0, 0);
ok(ret == eventMask, "failed to set event mask\n");
/* check what happens when we ask for EN_CHANGE and send WM_SETTEXT */
queriedEventMask = 0; /* initialize to something other than we expect */
watchForEventMask = EN_CHANGE;
ret = SendMessage(eventMaskEditHwnd, WM_SETTEXT, 0, (LPARAM) text);
ok(ret == TRUE, "failed to set text\n");
/* richedit should mask off ENM_CHANGE when it sends an EN_CHANGE
notification in response to WM_SETTEXT */
ok(queriedEventMask == (eventMask & ~ENM_CHANGE),
"wrong event mask (0x%x) during WM_COMMAND\n", queriedEventMask);
/* check to see if EN_CHANGE is sent when redraw is turned off */
SendMessage(eventMaskEditHwnd, WM_CLEAR, 0, 0);
ok(IsWindowVisible(eventMaskEditHwnd), "Window should be visible.\n");
SendMessage(eventMaskEditHwnd, WM_SETREDRAW, FALSE, 0);
/* redraw is disabled by making the window invisible. */
ok(!IsWindowVisible(eventMaskEditHwnd), "Window shouldn't be visible.\n");
queriedEventMask = 0; /* initialize to something other than we expect */
SendMessage(eventMaskEditHwnd, EM_REPLACESEL, 0, (LPARAM) text);
ok(queriedEventMask == (eventMask & ~ENM_CHANGE),
"wrong event mask (0x%x) during WM_COMMAND\n", queriedEventMask);
SendMessage(eventMaskEditHwnd, WM_SETREDRAW, TRUE, 0);
ok(IsWindowVisible(eventMaskEditHwnd), "Window should be visible.\n");
/* check to see if EN_UPDATE is sent when the editor isn't visible */
SendMessage(eventMaskEditHwnd, WM_CLEAR, 0, 0);
style = GetWindowLong(eventMaskEditHwnd, GWL_STYLE);
SetWindowLong(eventMaskEditHwnd, GWL_STYLE, style & ~WS_VISIBLE);
ok(!IsWindowVisible(eventMaskEditHwnd), "Window shouldn't be visible.\n");
watchForEventMask = EN_UPDATE;
queriedEventMask = 0; /* initialize to something other than we expect */
SendMessage(eventMaskEditHwnd, EM_REPLACESEL, 0, (LPARAM) text);
ok(queriedEventMask == 0,
"wrong event mask (0x%x) during WM_COMMAND\n", queriedEventMask);
SetWindowLong(eventMaskEditHwnd, GWL_STYLE, style);
ok(IsWindowVisible(eventMaskEditHwnd), "Window should be visible.\n");
queriedEventMask = 0; /* initialize to something other than we expect */
SendMessage(eventMaskEditHwnd, EM_REPLACESEL, 0, (LPARAM) text);
ok(queriedEventMask == eventMask,
"wrong event mask (0x%x) during WM_COMMAND\n", queriedEventMask);
DestroyWindow(parent);
}
static int received_WM_NOTIFY = 0;
static int modify_at_WM_NOTIFY = 0;
static BOOL filter_on_WM_NOTIFY = FALSE;
static HWND hwndRichedit_WM_NOTIFY;
static LRESULT WINAPI WM_NOTIFY_ParentMsgCheckProcA(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
if(message == WM_NOTIFY)
{
received_WM_NOTIFY = 1;
modify_at_WM_NOTIFY = SendMessage(hwndRichedit_WM_NOTIFY, EM_GETMODIFY, 0, 0);
if (filter_on_WM_NOTIFY) return TRUE;
}
return DefWindowProcA(hwnd, message, wParam, lParam);
}
static void test_WM_NOTIFY(void)
{
HWND parent;
WNDCLASSA cls;
CHARFORMAT2 cf2;
int sel_start, sel_end;
/* register class to capture WM_NOTIFY */
cls.style = 0;
cls.lpfnWndProc = WM_NOTIFY_ParentMsgCheckProcA;
cls.cbClsExtra = 0;
cls.cbWndExtra = 0;
cls.hInstance = GetModuleHandleA(0);
cls.hIcon = 0;
cls.hCursor = LoadCursorA(0, IDC_ARROW);
cls.hbrBackground = GetStockObject(WHITE_BRUSH);
cls.lpszMenuName = NULL;
cls.lpszClassName = "WM_NOTIFY_ParentClass";
if(!RegisterClassA(&cls)) assert(0);
parent = CreateWindow(cls.lpszClassName, NULL, WS_POPUP|WS_VISIBLE,
0, 0, 200, 60, NULL, NULL, NULL, NULL);
ok (parent != 0, "Failed to create parent window\n");
hwndRichedit_WM_NOTIFY = new_richedit(parent);
ok(hwndRichedit_WM_NOTIFY != 0, "Failed to create edit window\n");
SendMessage(hwndRichedit_WM_NOTIFY, EM_SETEVENTMASK, 0, ENM_SELCHANGE);
/* Notifications for selection change should only be sent when selection
actually changes. EM_SETCHARFORMAT is one message that calls
ME_CommitUndo, which should check whether message should be sent */
received_WM_NOTIFY = 0;
cf2.cbSize = sizeof(CHARFORMAT2);
SendMessage(hwndRichedit_WM_NOTIFY, EM_GETCHARFORMAT, SCF_DEFAULT, (LPARAM)&cf2);
cf2.dwMask = CFM_ITALIC | cf2.dwMask;
cf2.dwEffects = CFE_ITALIC ^ cf2.dwEffects;
SendMessage(hwndRichedit_WM_NOTIFY, EM_SETCHARFORMAT, 0, (LPARAM) &cf2);
ok(received_WM_NOTIFY == 0, "Unexpected WM_NOTIFY was sent!\n");
/* WM_SETTEXT should NOT cause a WM_NOTIFY to be sent when selection is
already at 0. */
received_WM_NOTIFY = 0;
modify_at_WM_NOTIFY = 0;
SendMessage(hwndRichedit_WM_NOTIFY, WM_SETTEXT, 0, (LPARAM)"sometext");
ok(received_WM_NOTIFY == 0, "Unexpected WM_NOTIFY was sent!\n");
ok(modify_at_WM_NOTIFY == 0, "WM_NOTIFY callback saw text flagged as modified!\n");
received_WM_NOTIFY = 0;
modify_at_WM_NOTIFY = 0;
SendMessage(hwndRichedit_WM_NOTIFY, EM_SETSEL, 4, 4);
ok(received_WM_NOTIFY == 1, "Expected WM_NOTIFY was NOT sent!\n");
received_WM_NOTIFY = 0;
modify_at_WM_NOTIFY = 0;
SendMessage(hwndRichedit_WM_NOTIFY, WM_SETTEXT, 0, (LPARAM)"sometext");
ok(received_WM_NOTIFY == 1, "Expected WM_NOTIFY was NOT sent!\n");
ok(modify_at_WM_NOTIFY == 0, "WM_NOTIFY callback saw text flagged as modified!\n");
/* Test for WM_NOTIFY messages with redraw disabled. */
SendMessage(hwndRichedit_WM_NOTIFY, EM_SETSEL, 0, 0);
SendMessage(hwndRichedit_WM_NOTIFY, WM_SETREDRAW, FALSE, 0);
received_WM_NOTIFY = 0;
SendMessage(hwndRichedit_WM_NOTIFY, EM_REPLACESEL, FALSE, (LPARAM)"inserted");
ok(received_WM_NOTIFY == 1, "Expected WM_NOTIFY was NOT sent!\n");
SendMessage(hwndRichedit_WM_NOTIFY, WM_SETREDRAW, TRUE, 0);
/* Test filtering key events. */
SendMessage(hwndRichedit_WM_NOTIFY, EM_SETSEL, 0, 0);
SendMessage(hwndRichedit_WM_NOTIFY, EM_SETEVENTMASK, 0, ENM_KEYEVENTS);
SendMessage(hwndRichedit_WM_NOTIFY, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
received_WM_NOTIFY = 0;
SendMessage(hwndRichedit_WM_NOTIFY, WM_KEYDOWN, VK_RIGHT, 0);
SendMessage(hwndRichedit_WM_NOTIFY, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
ok(sel_start == 1 && sel_end == 1,
"selections is incorrectly at (%d,%d)\n", sel_start, sel_end);
filter_on_WM_NOTIFY = TRUE;
received_WM_NOTIFY = 0;
SendMessage(hwndRichedit_WM_NOTIFY, WM_KEYDOWN, VK_RIGHT, 0);
SendMessage(hwndRichedit_WM_NOTIFY, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
ok(sel_start == 1 && sel_end == 1,
"selections is incorrectly at (%d,%d)\n", sel_start, sel_end);
/* test with owner set to NULL */
SetWindowLongPtr(hwndRichedit_WM_NOTIFY, GWLP_HWNDPARENT, 0);
SendMessage(hwndRichedit_WM_NOTIFY, WM_KEYDOWN, VK_RIGHT, 0);
SendMessage(hwndRichedit_WM_NOTIFY, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
ok(sel_start == 1 && sel_end == 1,
"selections is incorrectly at (%d,%d)\n", sel_start, sel_end);
DestroyWindow(hwndRichedit_WM_NOTIFY);
DestroyWindow(parent);
}
static void test_undo_coalescing(void)
{
HWND hwnd;
int result;
char buffer[64] = {0};
/* multi-line control inserts CR normally */
hwnd = CreateWindowExA(0, "RichEdit20W", NULL, WS_POPUP|ES_MULTILINE,
0, 0, 200, 60, 0, 0, 0, 0);
ok(hwnd != 0, "CreateWindowExA error %u\n", GetLastError());
result = SendMessage(hwnd, EM_CANUNDO, 0, 0);
ok (result == FALSE, "Can undo after window creation.\n");
result = SendMessage(hwnd, EM_UNDO, 0, 0);
ok (result == FALSE, "Undo operation successful with nothing to undo.\n");
result = SendMessage(hwnd, EM_CANREDO, 0, 0);
ok (result == FALSE, "Can redo after window creation.\n");
result = SendMessage(hwnd, EM_REDO, 0, 0);
ok (result == FALSE, "Redo operation successful with nothing undone.\n");
/* Test the effect of arrows keys during typing on undo transactions*/
simulate_typing_characters(hwnd, "one two three");
SendMessage(hwnd, WM_KEYDOWN, VK_RIGHT, 1);
SendMessage(hwnd, WM_KEYUP, VK_RIGHT, 1);
simulate_typing_characters(hwnd, " four five six");
result = SendMessage(hwnd, EM_CANREDO, 0, 0);
ok (result == FALSE, "Can redo before anything is undone.\n");
result = SendMessage(hwnd, EM_CANUNDO, 0, 0);
ok (result == TRUE, "Cannot undo typed characters.\n");
result = SendMessage(hwnd, EM_UNDO, 0, 0);
ok (result == TRUE, "EM_UNDO Failed to undo typed characters.\n");
result = SendMessage(hwnd, EM_CANREDO, 0, 0);
ok (result == TRUE, "Cannot redo after undo.\n");
SendMessageA(hwnd, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
result = strcmp(buffer, "one two three");
ok (result == 0, "expected '%s' but got '%s'\n", "one two three", buffer);
result = SendMessage(hwnd, EM_CANUNDO, 0, 0);
ok (result == TRUE, "Cannot undo typed characters.\n");
result = SendMessage(hwnd, WM_UNDO, 0, 0);
ok (result == TRUE, "Failed to undo typed characters.\n");
SendMessageA(hwnd, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
result = strcmp(buffer, "");
ok (result == 0, "expected '%s' but got '%s'\n", "", buffer);
/* Test the effect of focus changes during typing on undo transactions*/
simulate_typing_characters(hwnd, "one two three");
result = SendMessage(hwnd, EM_CANREDO, 0, 0);
ok (result == FALSE, "Redo buffer should have been cleared by typing.\n");
SendMessage(hwnd, WM_KILLFOCUS, 0, 0);
SendMessage(hwnd, WM_SETFOCUS, 0, 0);
simulate_typing_characters(hwnd, " four five six");
result = SendMessage(hwnd, EM_UNDO, 0, 0);
ok (result == TRUE, "Failed to undo typed characters.\n");
SendMessageA(hwnd, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
result = strcmp(buffer, "one two three");
ok (result == 0, "expected '%s' but got '%s'\n", "one two three", buffer);
/* Test the effect of the back key during typing on undo transactions */
SendMessage(hwnd, EM_EMPTYUNDOBUFFER, 0, 0);
result = SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)"");
ok (result == TRUE, "Failed to clear the text.\n");
simulate_typing_characters(hwnd, "one two threa");
result = SendMessage(hwnd, EM_CANREDO, 0, 0);
ok (result == FALSE, "Redo buffer should have been cleared by typing.\n");
SendMessage(hwnd, WM_KEYDOWN, VK_BACK, 1);
SendMessage(hwnd, WM_KEYUP, VK_BACK, 1);
simulate_typing_characters(hwnd, "e four five six");
result = SendMessage(hwnd, EM_UNDO, 0, 0);
ok (result == TRUE, "Failed to undo typed characters.\n");
SendMessageA(hwnd, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
result = strcmp(buffer, "");
ok (result == 0, "expected '%s' but got '%s'\n", "", buffer);
/* Test the effect of the delete key during typing on undo transactions */
SendMessage(hwnd, EM_EMPTYUNDOBUFFER, 0, 0);
result = SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)"abcd");
ok(result == TRUE, "Failed to set the text.\n");
SendMessage(hwnd, EM_SETSEL, 1, 1);
SendMessage(hwnd, WM_KEYDOWN, VK_DELETE, 1);
SendMessage(hwnd, WM_KEYUP, VK_DELETE, 1);
SendMessage(hwnd, WM_KEYDOWN, VK_DELETE, 1);
SendMessage(hwnd, WM_KEYUP, VK_DELETE, 1);
result = SendMessage(hwnd, EM_UNDO, 0, 0);
ok (result == TRUE, "Failed to undo typed characters.\n");
SendMessageA(hwnd, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
result = strcmp(buffer, "acd");
ok (result == 0, "expected '%s' but got '%s'\n", "acd", buffer);
result = SendMessage(hwnd, EM_UNDO, 0, 0);
ok (result == TRUE, "Failed to undo typed characters.\n");
SendMessageA(hwnd, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
result = strcmp(buffer, "abcd");
ok (result == 0, "expected '%s' but got '%s'\n", "abcd", buffer);
/* Test the effect of EM_STOPGROUPTYPING on undo transactions*/
SendMessage(hwnd, EM_EMPTYUNDOBUFFER, 0, 0);
result = SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)"");
ok (result == TRUE, "Failed to clear the text.\n");
simulate_typing_characters(hwnd, "one two three");
result = SendMessage(hwnd, EM_STOPGROUPTYPING, 0, 0);
ok (result == 0, "expected %d but got %d\n", 0, result);
simulate_typing_characters(hwnd, " four five six");
result = SendMessage(hwnd, EM_UNDO, 0, 0);
ok (result == TRUE, "Failed to undo typed characters.\n");
SendMessageA(hwnd, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
result = strcmp(buffer, "one two three");
ok (result == 0, "expected '%s' but got '%s'\n", "one two three", buffer);
result = SendMessage(hwnd, EM_UNDO, 0, 0);
ok (result == TRUE, "Failed to undo typed characters.\n");
ok (result == TRUE, "Failed to undo typed characters.\n");
SendMessageA(hwnd, WM_GETTEXT, sizeof(buffer), (LPARAM)buffer);
result = strcmp(buffer, "");
ok (result == 0, "expected '%s' but got '%s'\n", "", buffer);
DestroyWindow(hwnd);
}
static LONG CALLBACK customWordBreakProc(WCHAR *text, int pos, int bytes, int code)
{
int length;
/* MSDN lied, length is actually the number of bytes. */
length = bytes / sizeof(WCHAR);
switch(code)
{
case WB_ISDELIMITER:
return text[pos] == 'X';
case WB_LEFT:
case WB_MOVEWORDLEFT:
if (customWordBreakProc(text, pos, bytes, WB_ISDELIMITER))
return pos-1;
return min(customWordBreakProc(text, pos, bytes, WB_LEFTBREAK)-1, 0);
case WB_LEFTBREAK:
pos--;
while (pos > 0 && !customWordBreakProc(text, pos, bytes, WB_ISDELIMITER))
pos--;
return pos;
case WB_RIGHT:
case WB_MOVEWORDRIGHT:
if (customWordBreakProc(text, pos, bytes, WB_ISDELIMITER))
return pos+1;
return min(customWordBreakProc(text, pos, bytes, WB_RIGHTBREAK)+1, length);
case WB_RIGHTBREAK:
pos++;
while (pos < length && !customWordBreakProc(text, pos, bytes, WB_ISDELIMITER))
pos++;
return pos;
default:
ok(FALSE, "Unexpected code %d\n", code);
break;
}
return 0;
}
static void test_word_movement(void)
{
HWND hwnd;
int result;
int sel_start, sel_end;
const WCHAR textW[] = {'o','n','e',' ','t','w','o','X','t','h','r','e','e',0};
/* multi-line control inserts CR normally */
hwnd = new_richedit(NULL);
result = SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)"one two three");
ok (result == TRUE, "Failed to clear the text.\n");
SendMessage(hwnd, EM_SETSEL, 0, 0);
/* |one two three */
send_ctrl_key(hwnd, VK_RIGHT);
/* one |two three */
SendMessage(hwnd, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
ok(sel_start == sel_end, "Selection should be empty\n");
ok(sel_start == 4, "Cursor is at %d instead of %d\n", sel_start, 4);
send_ctrl_key(hwnd, VK_RIGHT);
/* one two |three */
SendMessage(hwnd, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
ok(sel_start == sel_end, "Selection should be empty\n");
ok(sel_start == 9, "Cursor is at %d instead of %d\n", sel_start, 9);
send_ctrl_key(hwnd, VK_LEFT);
/* one |two three */
SendMessage(hwnd, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
ok(sel_start == sel_end, "Selection should be empty\n");
ok(sel_start == 4, "Cursor is at %d instead of %d\n", sel_start, 4);
send_ctrl_key(hwnd, VK_LEFT);
/* |one two three */
SendMessage(hwnd, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
ok(sel_start == sel_end, "Selection should be empty\n");
ok(sel_start == 0, "Cursor is at %d instead of %d\n", sel_start, 0);
SendMessage(hwnd, EM_SETSEL, 8, 8);
/* one two | three */
send_ctrl_key(hwnd, VK_RIGHT);
/* one two |three */
SendMessage(hwnd, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
ok(sel_start == sel_end, "Selection should be empty\n");
ok(sel_start == 9, "Cursor is at %d instead of %d\n", sel_start, 9);
SendMessage(hwnd, EM_SETSEL, 11, 11);
/* one two th|ree */
send_ctrl_key(hwnd, VK_LEFT);
/* one two |three */
SendMessage(hwnd, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
ok(sel_start == sel_end, "Selection should be empty\n");
ok(sel_start == 9, "Cursor is at %d instead of %d\n", sel_start, 9);
/* Test with a custom word break procedure that uses X as the delimiter. */
result = SendMessageA(hwnd, WM_SETTEXT, 0, (LPARAM)"one twoXthree");
ok (result == TRUE, "Failed to clear the text.\n");
SendMessage(hwnd, EM_SETWORDBREAKPROC, 0, (LPARAM)customWordBreakProc);
/* |one twoXthree */
send_ctrl_key(hwnd, VK_RIGHT);
/* one twoX|three */
SendMessage(hwnd, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
ok(sel_start == sel_end, "Selection should be empty\n");
ok(sel_start == 8, "Cursor is at %d instead of %d\n", sel_start, 8);
DestroyWindow(hwnd);
/* Make sure the behaviour is the same with a unicode richedit window,
* and using unicode functions. */
hwnd = CreateWindowW(RICHEDIT_CLASS20W, NULL,
ES_MULTILINE|WS_POPUP|WS_HSCROLL|WS_VSCROLL|WS_VISIBLE,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
/* Test with a custom word break procedure that uses X as the delimiter. */
result = SendMessageW(hwnd, WM_SETTEXT, 0, (LPARAM)textW);
ok (result == TRUE, "Failed to clear the text.\n");
SendMessageW(hwnd, EM_SETWORDBREAKPROC, 0, (LPARAM)customWordBreakProc);
/* |one twoXthree */
send_ctrl_key(hwnd, VK_RIGHT);
/* one twoX|three */
SendMessageW(hwnd, EM_GETSEL, (WPARAM)&sel_start, (LPARAM)&sel_end);
ok(sel_start == sel_end, "Selection should be empty\n");
ok(sel_start == 8, "Cursor is at %d instead of %d\n", sel_start, 8);
DestroyWindow(hwnd);
}
static void test_EM_CHARFROMPOS(void)
{
HWND hwnd;
int result;
RECT rcClient;
POINTL point;
point.x = 0;
point.y = 40;
/* multi-line control inserts CR normally */
hwnd = new_richedit(NULL);
result = SendMessageA(hwnd, WM_SETTEXT, 0,
(LPARAM)"one two three four five six seven\reight");
ok(result == 1, "Expected 1, got %d\n", result);
GetClientRect(hwnd, &rcClient);
result = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&point);
ok(result == 34, "expected character index of 34 but got %d\n", result);
/* Test with points outside the bounds of the richedit control. */
point.x = -1;
point.y = 40;
result = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&point);
todo_wine ok(result == 34, "expected character index of 34 but got %d\n", result);
point.x = 1000;
point.y = 0;
result = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&point);
todo_wine ok(result == 33, "expected character index of 33 but got %d\n", result);
point.x = 1000;
point.y = 36;
result = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&point);
todo_wine ok(result == 39, "expected character index of 39 but got %d\n", result);
point.x = 1000;
point.y = -1;
result = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&point);
todo_wine ok(result == 0, "expected character index of 0 but got %d\n", result);
point.x = 1000;
point.y = rcClient.bottom + 1;
result = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&point);
todo_wine ok(result == 34, "expected character index of 34 but got %d\n", result);
point.x = 1000;
point.y = rcClient.bottom;
result = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM)&point);
todo_wine ok(result == 39, "expected character index of 39 but got %d\n", result);
DestroyWindow(hwnd);
}
static void test_word_wrap(void)
{
HWND hwnd;
POINTL point = {0, 60}; /* This point must be below the first line */
const char *text = "Must be long enough to test line wrapping";
DWORD dwCommonStyle = WS_VISIBLE|WS_POPUP|WS_VSCROLL|ES_MULTILINE;
int res, pos, lines;
/* Test the effect of WS_HSCROLL and ES_AUTOHSCROLL styles on wrapping
* when specified on window creation and set later. */
hwnd = CreateWindow(RICHEDIT_CLASS, NULL, dwCommonStyle,
0, 0, 200, 80, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "error: %d\n", (int) GetLastError());
res = SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) text);
ok(res, "WM_SETTEXT failed.\n");
pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
ok(pos, "pos=%d indicating no word wrap when it is expected.\n", pos);
lines = SendMessage(hwnd, EM_GETLINECOUNT, 0, 0);
ok(lines > 1, "Line was expected to wrap (lines=%d).\n", lines);
SetWindowLongW(hwnd, GWL_STYLE, dwCommonStyle|WS_HSCROLL|ES_AUTOHSCROLL);
pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
ok(pos, "pos=%d indicating no word wrap when it is expected.\n", pos);
DestroyWindow(hwnd);
hwnd = CreateWindow(RICHEDIT_CLASS, NULL, dwCommonStyle|WS_HSCROLL,
0, 0, 200, 80, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "error: %d\n", (int) GetLastError());
res = SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) text);
ok(res, "WM_SETTEXT failed.\n");
pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
ok(!pos, "pos=%d indicating word wrap when none is expected.\n", pos);
lines = SendMessage(hwnd, EM_GETLINECOUNT, 0, 0);
ok(lines == 1, "Line wasn't expected to wrap (lines=%d).\n", lines);
SetWindowLongW(hwnd, GWL_STYLE, dwCommonStyle);
pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
ok(!pos, "pos=%d indicating word wrap when none is expected.\n", pos);
DestroyWindow(hwnd);
hwnd = CreateWindow(RICHEDIT_CLASS, NULL, dwCommonStyle|ES_AUTOHSCROLL,
0, 0, 200, 80, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "error: %d\n", (int) GetLastError());
res = SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) text);
ok(res, "WM_SETTEXT failed.\n");
pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
ok(!pos, "pos=%d indicating word wrap when none is expected.\n", pos);
SetWindowLongW(hwnd, GWL_STYLE, dwCommonStyle);
pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
ok(!pos, "pos=%d indicating word wrap when none is expected.\n", pos);
DestroyWindow(hwnd);
hwnd = CreateWindow(RICHEDIT_CLASS, NULL,
dwCommonStyle|WS_HSCROLL|ES_AUTOHSCROLL,
0, 0, 200, 80, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "error: %d\n", (int) GetLastError());
res = SendMessage(hwnd, WM_SETTEXT, 0, (LPARAM) text);
ok(res, "WM_SETTEXT failed.\n");
pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
ok(!pos, "pos=%d indicating word wrap when none is expected.\n", pos);
SetWindowLongW(hwnd, GWL_STYLE, dwCommonStyle);
pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
ok(!pos, "pos=%d indicating word wrap when none is expected.\n", pos);
/* Test the effect of EM_SETTARGETDEVICE on word wrap. */
res = SendMessage(hwnd, EM_SETTARGETDEVICE, 0, 1);
ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res);
pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
ok(!pos, "pos=%d indicating word wrap when none is expected.\n", pos);
res = SendMessage(hwnd, EM_SETTARGETDEVICE, 0, 0);
ok(res, "EM_SETTARGETDEVICE failed (returned %d).\n", res);
pos = SendMessage(hwnd, EM_CHARFROMPOS, 0, (LPARAM) &point);
ok(pos, "pos=%d indicating no word wrap when it is expected.\n", pos);
DestroyWindow(hwnd);
/* Test to see if wrapping happens with redraw disabled. */
hwnd = CreateWindow(RICHEDIT_CLASS, NULL, dwCommonStyle,
0, 0, 400, 80, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "error: %d\n", (int) GetLastError());
SendMessage(hwnd, WM_SETREDRAW, FALSE, 0);
res = SendMessage(hwnd, EM_REPLACESEL, FALSE, (LPARAM) text);
ok(res, "EM_REPLACESEL failed.\n");
lines = SendMessage(hwnd, EM_GETLINECOUNT, 0, 0);
ok(lines == 1, "Line wasn't expected to wrap (lines=%d).\n", lines);
MoveWindow(hwnd, 0, 0, 200, 80, FALSE);
lines = SendMessage(hwnd, EM_GETLINECOUNT, 0, 0);
ok(lines > 1, "Line was expected to wrap (lines=%d).\n", lines);
SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
DestroyWindow(hwnd);
}
static void test_autoscroll(void)
{
HWND hwnd = new_richedit(NULL);
int lines, ret, redraw;
POINT pt;
for (redraw = 0; redraw <= 1; redraw++) {
trace("testing with WM_SETREDRAW=%d\n", redraw);
SendMessage(hwnd, WM_SETREDRAW, redraw, 0);
SendMessage(hwnd, EM_REPLACESEL, 0, (LPARAM)"1\n2\n3\n4\n5\n6\n7\n8");
lines = SendMessage(hwnd, EM_GETLINECOUNT, 0, 0);
ok(lines == 8, "%d lines instead of 8\n", lines);
ret = SendMessage(hwnd, EM_GETSCROLLPOS, 0, (LPARAM)&pt);
ok(ret == 1, "EM_GETSCROLLPOS returned %d instead of 1\n", ret);
ok(pt.y != 0, "Didn't scroll down after replacing text.\n");
ret = GetWindowLong(hwnd, GWL_STYLE);
ok(ret & WS_VSCROLL, "Scrollbar was not shown yet (style=%x).\n", (UINT)ret);
SendMessage(hwnd, WM_SETTEXT, 0, 0);
lines = SendMessage(hwnd, EM_GETLINECOUNT, 0, 0);
ok(lines == 1, "%d lines instead of 1\n", lines);
ret = SendMessage(hwnd, EM_GETSCROLLPOS, 0, (LPARAM)&pt);
ok(ret == 1, "EM_GETSCROLLPOS returned %d instead of 1\n", ret);
ok(pt.y == 0, "y scroll position is %d after clearing text.\n", pt.y);
ret = GetWindowLong(hwnd, GWL_STYLE);
ok(!(ret & WS_VSCROLL), "Scrollbar is still shown (style=%x).\n", (UINT)ret);
}
SendMessage(hwnd, WM_SETREDRAW, TRUE, 0);
DestroyWindow(hwnd);
/* The WS_VSCROLL and WS_HSCROLL styles implicitly set
* auto vertical/horizontal scrolling options. */
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
WS_POPUP|ES_MULTILINE|WS_VSCROLL|WS_HSCROLL,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
ret = SendMessage(hwnd, EM_GETOPTIONS, 0, 0);
ok(ret & ECO_AUTOVSCROLL, "ECO_AUTOVSCROLL isn't set.\n");
ok(ret & ECO_AUTOHSCROLL, "ECO_AUTOHSCROLL isn't set.\n");
ret = GetWindowLong(hwnd, GWL_STYLE);
ok(!(ret & ES_AUTOVSCROLL), "ES_AUTOVSCROLL is set.\n");
ok(!(ret & ES_AUTOHSCROLL), "ES_AUTOHSCROLL is set.\n");
DestroyWindow(hwnd);
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
WS_POPUP|ES_MULTILINE,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
ret = SendMessage(hwnd, EM_GETOPTIONS, 0, 0);
ok(!(ret & ECO_AUTOVSCROLL), "ECO_AUTOVSCROLL is set.\n");
ok(!(ret & ECO_AUTOHSCROLL), "ECO_AUTOHSCROLL is set.\n");
ret = GetWindowLong(hwnd, GWL_STYLE);
ok(!(ret & ES_AUTOVSCROLL), "ES_AUTOVSCROLL is set.\n");
ok(!(ret & ES_AUTOHSCROLL), "ES_AUTOHSCROLL is set.\n");
DestroyWindow(hwnd);
}
static void test_format_rect(void)
{
HWND hwnd;
RECT rc, expected, clientRect;
int n;
DWORD options;
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
ES_MULTILINE|WS_POPUP|WS_HSCROLL|WS_VSCROLL|WS_VISIBLE,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
GetClientRect(hwnd, &clientRect);
expected = clientRect;
expected.left += 1;
expected.right -= 1;
SendMessageA(hwnd, EM_GETRECT, 0, (LPARAM)&rc);
ok(rc.top == expected.top && rc.left == expected.left &&
rc.bottom == expected.bottom && rc.right == expected.right,
"rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
rc.top, rc.left, rc.bottom, rc.right,
expected.top, expected.left, expected.bottom, expected.right);
for (n = -3; n <= 3; n++)
{
rc = clientRect;
rc.top += n;
rc.left += n;
rc.bottom -= n;
rc.right -= n;
SendMessageA(hwnd, EM_SETRECT, 0, (LPARAM)&rc);
expected = rc;
expected.top = max(0, rc.top);
expected.left = max(0, rc.left);
expected.bottom = min(clientRect.bottom, rc.bottom);
expected.right = min(clientRect.right, rc.right);
SendMessageA(hwnd, EM_GETRECT, 0, (LPARAM)&rc);
ok(rc.top == expected.top && rc.left == expected.left &&
rc.bottom == expected.bottom && rc.right == expected.right,
"[n=%d] rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
n, rc.top, rc.left, rc.bottom, rc.right,
expected.top, expected.left, expected.bottom, expected.right);
}
rc = clientRect;
SendMessageA(hwnd, EM_SETRECT, 0, (LPARAM)&rc);
expected = clientRect;
SendMessageA(hwnd, EM_GETRECT, 0, (LPARAM)&rc);
ok(rc.top == expected.top && rc.left == expected.left &&
rc.bottom == expected.bottom && rc.right == expected.right,
"rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
rc.top, rc.left, rc.bottom, rc.right,
expected.top, expected.left, expected.bottom, expected.right);
/* Adding the selectionbar adds the selectionbar width to the left side. */
SendMessageA(hwnd, EM_SETOPTIONS, ECOOP_OR, ECO_SELECTIONBAR);
options = SendMessageA(hwnd, EM_GETOPTIONS, 0, 0);
ok(options & ECO_SELECTIONBAR, "EM_SETOPTIONS failed to add selectionbar.\n");
expected.left += 8; /* selection bar width */
SendMessageA(hwnd, EM_GETRECT, 0, (LPARAM)&rc);
ok(rc.top == expected.top && rc.left == expected.left &&
rc.bottom == expected.bottom && rc.right == expected.right,
"rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
rc.top, rc.left, rc.bottom, rc.right,
expected.top, expected.left, expected.bottom, expected.right);
rc = clientRect;
SendMessageA(hwnd, EM_SETRECT, 0, (LPARAM)&rc);
expected = clientRect;
SendMessageA(hwnd, EM_GETRECT, 0, (LPARAM)&rc);
ok(rc.top == expected.top && rc.left == expected.left &&
rc.bottom == expected.bottom && rc.right == expected.right,
"rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
rc.top, rc.left, rc.bottom, rc.right,
expected.top, expected.left, expected.bottom, expected.right);
/* Removing the selectionbar subtracts the selectionbar width from the left side,
* even if the left side is already 0. */
SendMessageA(hwnd, EM_SETOPTIONS, ECOOP_AND, ~ECO_SELECTIONBAR);
options = SendMessageA(hwnd, EM_GETOPTIONS, 0, 0);
ok(!(options & ECO_SELECTIONBAR), "EM_SETOPTIONS failed to remove selectionbar.\n");
expected.left -= 8; /* selection bar width */
SendMessageA(hwnd, EM_GETRECT, 0, (LPARAM)&rc);
ok(rc.top == expected.top && rc.left == expected.left &&
rc.bottom == expected.bottom && rc.right == expected.right,
"rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
rc.top, rc.left, rc.bottom, rc.right,
expected.top, expected.left, expected.bottom, expected.right);
/* Set the absolute value of the formatting rectangle. */
rc = clientRect;
SendMessageA(hwnd, EM_SETRECT, 0, (LPARAM)&rc);
expected = clientRect;
SendMessageA(hwnd, EM_GETRECT, 0, (LPARAM)&rc);
ok(rc.top == expected.top && rc.left == expected.left &&
rc.bottom == expected.bottom && rc.right == expected.right,
"[n=%d] rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
n, rc.top, rc.left, rc.bottom, rc.right,
expected.top, expected.left, expected.bottom, expected.right);
/* MSDN documents the EM_SETRECT message as using the rectangle provided in
* LPARAM as being a relative offset when the WPARAM value is 1, but these
* tests show that this isn't true. */
rc.top = 15;
rc.left = 15;
rc.bottom = clientRect.bottom - 15;
rc.right = clientRect.right - 15;
expected = rc;
SendMessageA(hwnd, EM_SETRECT, 1, (LPARAM)&rc);
SendMessageA(hwnd, EM_GETRECT, 0, (LPARAM)&rc);
ok(rc.top == expected.top && rc.left == expected.left &&
rc.bottom == expected.bottom && rc.right == expected.right,
"rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
rc.top, rc.left, rc.bottom, rc.right,
expected.top, expected.left, expected.bottom, expected.right);
/* For some reason it does not limit the values to the client rect with
* a WPARAM value of 1. */
rc.top = -15;
rc.left = -15;
rc.bottom = clientRect.bottom + 15;
rc.right = clientRect.right + 15;
expected = rc;
SendMessageA(hwnd, EM_SETRECT, 1, (LPARAM)&rc);
SendMessageA(hwnd, EM_GETRECT, 0, (LPARAM)&rc);
ok(rc.top == expected.top && rc.left == expected.left &&
rc.bottom == expected.bottom && rc.right == expected.right,
"rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
rc.top, rc.left, rc.bottom, rc.right,
expected.top, expected.left, expected.bottom, expected.right);
/* Reset to default rect and check how the format rect adjusts to window
* resize and how it copes with very small windows */
SendMessageA(hwnd, EM_SETRECT, 0, (LPARAM)NULL);
MoveWindow(hwnd, 0, 0, 100, 30, FALSE);
GetClientRect(hwnd, &clientRect);
expected = clientRect;
expected.left += 1;
expected.right -= 1;
SendMessageA(hwnd, EM_GETRECT, 0, (LPARAM)&rc);
ok(rc.top == expected.top && rc.left == expected.left &&
rc.bottom == expected.bottom && rc.right == expected.right,
"rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
rc.top, rc.left, rc.bottom, rc.right,
expected.top, expected.left, expected.bottom, expected.right);
MoveWindow(hwnd, 0, 0, 0, 30, FALSE);
GetClientRect(hwnd, &clientRect);
expected = clientRect;
expected.left += 1;
expected.right -= 1;
SendMessageA(hwnd, EM_GETRECT, 0, (LPARAM)&rc);
ok(rc.top == expected.top && rc.left == expected.left &&
rc.bottom == expected.bottom && rc.right == expected.right,
"rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
rc.top, rc.left, rc.bottom, rc.right,
expected.top, expected.left, expected.bottom, expected.right);
MoveWindow(hwnd, 0, 0, 100, 0, FALSE);
GetClientRect(hwnd, &clientRect);
expected = clientRect;
expected.left += 1;
expected.right -= 1;
SendMessageA(hwnd, EM_GETRECT, 0, (LPARAM)&rc);
ok(rc.top == expected.top && rc.left == expected.left &&
rc.bottom == expected.bottom && rc.right == expected.right,
"rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
rc.top, rc.left, rc.bottom, rc.right,
expected.top, expected.left, expected.bottom, expected.right);
DestroyWindow(hwnd);
/* The extended window style affects the formatting rectangle. */
hwnd = CreateWindowEx(WS_EX_CLIENTEDGE, RICHEDIT_CLASS, NULL,
ES_MULTILINE|WS_POPUP|WS_HSCROLL|WS_VSCROLL|WS_VISIBLE,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
GetClientRect(hwnd, &clientRect);
expected = clientRect;
expected.left += 1;
expected.top += 1;
expected.right -= 1;
SendMessageA(hwnd, EM_GETRECT, 0, (LPARAM)&rc);
ok(rc.top == expected.top && rc.left == expected.left &&
rc.bottom == expected.bottom && rc.right == expected.right,
"rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
rc.top, rc.left, rc.bottom, rc.right,
expected.top, expected.left, expected.bottom, expected.right);
rc = clientRect;
rc.top += 5;
rc.left += 5;
rc.bottom -= 5;
rc.right -= 5;
expected = rc;
expected.top -= 1;
expected.left -= 1;
expected.right += 1;
SendMessageA(hwnd, EM_SETRECT, 0, (LPARAM)&rc);
SendMessageA(hwnd, EM_GETRECT, 0, (LPARAM)&rc);
ok(rc.top == expected.top && rc.left == expected.left &&
rc.bottom == expected.bottom && rc.right == expected.right,
"rect a(t=%d, l=%d, b=%d, r=%d) != e(t=%d, l=%d, b=%d, r=%d)\n",
rc.top, rc.left, rc.bottom, rc.right,
expected.top, expected.left, expected.bottom, expected.right);
DestroyWindow(hwnd);
}
static void test_WM_GETDLGCODE(void)
{
HWND hwnd;
UINT res, expected;
MSG msg;
expected = DLGC_WANTCHARS|DLGC_WANTTAB|DLGC_WANTARROWS|DLGC_HASSETSEL|DLGC_WANTMESSAGE;
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
ES_MULTILINE|ES_WANTRETURN|WS_POPUP,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
msg.hwnd = hwnd;
res = SendMessage(hwnd, WM_GETDLGCODE, VK_RETURN, 0);
expected = expected | DLGC_WANTMESSAGE;
ok(res == expected, "WM_GETDLGCODE returned %x but expected %x\n",
res, expected);
DestroyWindow(hwnd);
msg.message = WM_KEYDOWN;
msg.wParam = VK_RETURN;
msg.lParam = (MapVirtualKey(VK_RETURN, MAPVK_VK_TO_VSC) << 16) | 0x0001;
msg.pt.x = 0;
msg.pt.y = 0;
msg.time = GetTickCount();
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
ES_MULTILINE|ES_WANTRETURN|WS_POPUP,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
msg.hwnd = hwnd;
res = SendMessage(hwnd, WM_GETDLGCODE, VK_RETURN, (LPARAM)&msg);
expected = expected | DLGC_WANTMESSAGE;
ok(res == expected, "WM_GETDLGCODE returned %x but expected %x\n",
res, expected);
DestroyWindow(hwnd);
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
ES_MULTILINE|WS_POPUP,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
msg.hwnd = hwnd;
res = SendMessage(hwnd, WM_GETDLGCODE, VK_RETURN, (LPARAM)&msg);
expected = DLGC_WANTCHARS|DLGC_WANTTAB|DLGC_WANTARROWS|DLGC_HASSETSEL|DLGC_WANTMESSAGE;
ok(res == expected, "WM_GETDLGCODE returned %x but expected %x\n",
res, expected);
DestroyWindow(hwnd);
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
ES_WANTRETURN|WS_POPUP,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
msg.hwnd = hwnd;
res = SendMessage(hwnd, WM_GETDLGCODE, VK_RETURN, (LPARAM)&msg);
expected = DLGC_WANTCHARS|DLGC_WANTTAB|DLGC_WANTARROWS|DLGC_HASSETSEL;
ok(res == expected, "WM_GETDLGCODE returned %x but expected %x\n",
res, expected);
DestroyWindow(hwnd);
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
WS_POPUP,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
msg.hwnd = hwnd;
res = SendMessage(hwnd, WM_GETDLGCODE, VK_RETURN, (LPARAM)&msg);
expected = DLGC_WANTCHARS|DLGC_WANTTAB|DLGC_WANTARROWS|DLGC_HASSETSEL;
ok(res == expected, "WM_GETDLGCODE returned %x but expected %x\n",
res, expected);
DestroyWindow(hwnd);
msg.wParam = VK_TAB;
msg.lParam = (MapVirtualKey(VK_TAB, MAPVK_VK_TO_VSC) << 16) | 0x0001;
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
ES_MULTILINE|WS_POPUP,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
msg.hwnd = hwnd;
res = SendMessage(hwnd, WM_GETDLGCODE, VK_RETURN, (LPARAM)&msg);
expected = DLGC_WANTCHARS|DLGC_WANTTAB|DLGC_WANTARROWS|DLGC_HASSETSEL|DLGC_WANTMESSAGE;
ok(res == expected, "WM_GETDLGCODE returned %x but expected %x\n",
res, expected);
DestroyWindow(hwnd);
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
WS_POPUP,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
msg.hwnd = hwnd;
res = SendMessage(hwnd, WM_GETDLGCODE, VK_RETURN, (LPARAM)&msg);
expected = DLGC_WANTCHARS|DLGC_WANTTAB|DLGC_WANTARROWS|DLGC_HASSETSEL;
ok(res == expected, "WM_GETDLGCODE returned %x but expected %x\n",
res, expected);
DestroyWindow(hwnd);
hold_key(VK_CONTROL);
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
ES_MULTILINE|WS_POPUP,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
msg.hwnd = hwnd;
res = SendMessage(hwnd, WM_GETDLGCODE, VK_RETURN, (LPARAM)&msg);
expected = DLGC_WANTCHARS|DLGC_WANTTAB|DLGC_WANTARROWS|DLGC_HASSETSEL|DLGC_WANTMESSAGE;
ok(res == expected, "WM_GETDLGCODE returned %x but expected %x\n",
res, expected);
DestroyWindow(hwnd);
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
WS_POPUP,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
msg.hwnd = hwnd;
res = SendMessage(hwnd, WM_GETDLGCODE, VK_RETURN, (LPARAM)&msg);
expected = DLGC_WANTCHARS|DLGC_WANTTAB|DLGC_WANTARROWS|DLGC_HASSETSEL;
ok(res == expected, "WM_GETDLGCODE returned %x but expected %x\n",
res, expected);
DestroyWindow(hwnd);
release_key(VK_CONTROL);
msg.wParam = 'a';
msg.lParam = (MapVirtualKey('a', MAPVK_VK_TO_VSC) << 16) | 0x0001;
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
ES_MULTILINE|WS_POPUP,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
msg.hwnd = hwnd;
res = SendMessage(hwnd, WM_GETDLGCODE, VK_RETURN, (LPARAM)&msg);
expected = DLGC_WANTCHARS|DLGC_WANTTAB|DLGC_WANTARROWS|DLGC_HASSETSEL|DLGC_WANTMESSAGE;
ok(res == expected, "WM_GETDLGCODE returned %x but expected %x\n",
res, expected);
DestroyWindow(hwnd);
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
WS_POPUP,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
msg.hwnd = hwnd;
res = SendMessage(hwnd, WM_GETDLGCODE, VK_RETURN, (LPARAM)&msg);
expected = DLGC_WANTCHARS|DLGC_WANTTAB|DLGC_WANTARROWS|DLGC_HASSETSEL;
ok(res == expected, "WM_GETDLGCODE returned %x but expected %x\n",
res, expected);
DestroyWindow(hwnd);
msg.message = WM_CHAR;
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
ES_MULTILINE|WS_POPUP,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
msg.hwnd = hwnd;
res = SendMessage(hwnd, WM_GETDLGCODE, VK_RETURN, (LPARAM)&msg);
expected = DLGC_WANTCHARS|DLGC_WANTTAB|DLGC_WANTARROWS|DLGC_HASSETSEL|DLGC_WANTMESSAGE;
ok(res == expected, "WM_GETDLGCODE returned %x but expected %x\n",
res, expected);
DestroyWindow(hwnd);
hwnd = CreateWindowEx(0, RICHEDIT_CLASS, NULL,
WS_POPUP,
0, 0, 200, 60, NULL, NULL, hmoduleRichEdit, NULL);
ok(hwnd != NULL, "class: %s, error: %d\n", RICHEDIT_CLASS, (int) GetLastError());
msg.hwnd = hwnd;
res = SendMessage(hwnd, WM_GETDLGCODE, VK_RETURN, (LPARAM)&msg);
expected = DLGC_WANTCHARS|DLGC_WANTTAB|DLGC_WANTARROWS|DLGC_HASSETSEL;
ok(res == expected, "WM_GETDLGCODE returned %x but expected %x\n",
res, expected);
DestroyWindow(hwnd);
}
static void test_zoom(void)
{
HWND hwnd;
UINT ret;
RECT rc;
POINT pt;
int numerator, denominator;
hwnd = new_richedit(NULL);
GetClientRect(hwnd, &rc);
pt.x = (rc.right - rc.left) / 2;
pt.y = (rc.bottom - rc.top) / 2;
ClientToScreen(hwnd, &pt);
/* Test initial zoom value */
ret = SendMessage(hwnd, EM_GETZOOM, (WPARAM)&numerator, (LPARAM)&denominator);
ok(numerator == 0, "Numerator should be initialized to 0 (got %d).\n", numerator);
ok(denominator == 0, "Denominator should be initialized to 0 (got %d).\n", denominator);
ok(ret == TRUE, "EM_GETZOOM failed (%d).\n", ret);
/* test scroll wheel */
hold_key(VK_CONTROL);
ret = SendMessage(hwnd, WM_MOUSEWHEEL, MAKEWPARAM(MK_CONTROL, WHEEL_DELTA),
MAKELPARAM(pt.x, pt.y));
ok(!ret, "WM_MOUSEWHEEL failed (%d).\n", ret);
release_key(VK_CONTROL);
ret = SendMessage(hwnd, EM_GETZOOM, (WPARAM)&numerator, (LPARAM)&denominator);
ok(numerator == 110, "incorrect numerator is %d\n", numerator);
ok(denominator == 100, "incorrect denominator is %d\n", denominator);
ok(ret == TRUE, "EM_GETZOOM failed (%d).\n", ret);
/* Test how much the mouse wheel can zoom in and out. */
ret = SendMessage(hwnd, EM_SETZOOM, 490, 100);
ok(ret == TRUE, "EM_SETZOOM failed (%d).\n", ret);
hold_key(VK_CONTROL);
ret = SendMessage(hwnd, WM_MOUSEWHEEL, MAKEWPARAM(MK_CONTROL, WHEEL_DELTA),
MAKELPARAM(pt.x, pt.y));
ok(!ret, "WM_MOUSEWHEEL failed (%d).\n", ret);
release_key(VK_CONTROL);
ret = SendMessage(hwnd, EM_GETZOOM, (WPARAM)&numerator, (LPARAM)&denominator);
ok(numerator == 500, "incorrect numerator is %d\n", numerator);
ok(denominator == 100, "incorrect denominator is %d\n", denominator);
ok(ret == TRUE, "EM_GETZOOM failed (%d).\n", ret);
ret = SendMessage(hwnd, EM_SETZOOM, 491, 100);
ok(ret == TRUE, "EM_SETZOOM failed (%d).\n", ret);
hold_key(VK_CONTROL);
ret = SendMessage(hwnd, WM_MOUSEWHEEL, MAKEWPARAM(MK_CONTROL, WHEEL_DELTA),
MAKELPARAM(pt.x, pt.y));
ok(!ret, "WM_MOUSEWHEEL failed (%d).\n", ret);
release_key(VK_CONTROL);
ret = SendMessage(hwnd, EM_GETZOOM, (WPARAM)&numerator, (LPARAM)&denominator);
ok(numerator == 491, "incorrect numerator is %d\n", numerator);
ok(denominator == 100, "incorrect denominator is %d\n", denominator);
ok(ret == TRUE, "EM_GETZOOM failed (%d).\n", ret);
ret = SendMessage(hwnd, EM_SETZOOM, 20, 100);
ok(ret == TRUE, "EM_SETZOOM failed (%d).\n", ret);
hold_key(VK_CONTROL);
ret = SendMessage(hwnd, WM_MOUSEWHEEL, MAKEWPARAM(MK_CONTROL, -WHEEL_DELTA),
MAKELPARAM(pt.x, pt.y));
ok(!ret, "WM_MOUSEWHEEL failed (%d).\n", ret);
release_key(VK_CONTROL);
ret = SendMessage(hwnd, EM_GETZOOM, (WPARAM)&numerator, (LPARAM)&denominator);
ok(numerator == 10, "incorrect numerator is %d\n", numerator);
ok(denominator == 100, "incorrect denominator is %d\n", denominator);
ok(ret == TRUE, "EM_GETZOOM failed (%d).\n", ret);
ret = SendMessage(hwnd, EM_SETZOOM, 19, 100);
ok(ret == TRUE, "EM_SETZOOM failed (%d).\n", ret);
hold_key(VK_CONTROL);
ret = SendMessage(hwnd, WM_MOUSEWHEEL, MAKEWPARAM(MK_CONTROL, -WHEEL_DELTA),
MAKELPARAM(pt.x, pt.y));
ok(!ret, "WM_MOUSEWHEEL failed (%d).\n", ret);
release_key(VK_CONTROL);
ret = SendMessage(hwnd, EM_GETZOOM, (WPARAM)&numerator, (LPARAM)&denominator);
ok(numerator == 19, "incorrect numerator is %d\n", numerator);
ok(denominator == 100, "incorrect denominator is %d\n", denominator);
ok(ret == TRUE, "EM_GETZOOM failed (%d).\n", ret);
/* Test how WM_SCROLLWHEEL treats our custom denominator. */
ret = SendMessage(hwnd, EM_SETZOOM, 50, 13);
ok(ret == TRUE, "EM_SETZOOM failed (%d).\n", ret);
hold_key(VK_CONTROL);
ret = SendMessage(hwnd, WM_MOUSEWHEEL, MAKEWPARAM(MK_CONTROL, WHEEL_DELTA),
MAKELPARAM(pt.x, pt.y));
ok(!ret, "WM_MOUSEWHEEL failed (%d).\n", ret);
release_key(VK_CONTROL);
ret = SendMessage(hwnd, EM_GETZOOM, (WPARAM)&numerator, (LPARAM)&denominator);
ok(numerator == 394, "incorrect numerator is %d\n", numerator);
ok(denominator == 100, "incorrect denominator is %d\n", denominator);
ok(ret == TRUE, "EM_GETZOOM failed (%d).\n", ret);
/* Test bounds checking on EM_SETZOOM */
ret = SendMessage(hwnd, EM_SETZOOM, 2, 127);
ok(ret == TRUE, "EM_SETZOOM rejected valid values (%d).\n", ret);
ret = SendMessage(hwnd, EM_SETZOOM, 127, 2);
ok(ret == TRUE, "EM_SETZOOM rejected valid values (%d).\n", ret);
ret = SendMessage(hwnd, EM_SETZOOM, 2, 128);
ok(ret == FALSE, "EM_SETZOOM accepted invalid values (%d).\n", ret);
ret = SendMessage(hwnd, EM_GETZOOM, (WPARAM)&numerator, (LPARAM)&denominator);
ok(numerator == 127, "incorrect numerator is %d\n", numerator);
ok(denominator == 2, "incorrect denominator is %d\n", denominator);
ok(ret == TRUE, "EM_GETZOOM failed (%d).\n", ret);
ret = SendMessage(hwnd, EM_SETZOOM, 128, 2);
ok(ret == FALSE, "EM_SETZOOM accepted invalid values (%d).\n", ret);
/* See if negative numbers are accepted. */
ret = SendMessage(hwnd, EM_SETZOOM, -100, -100);
ok(ret == FALSE, "EM_SETZOOM accepted invalid values (%d).\n", ret);
/* See if negative numbers are accepted. */
ret = SendMessage(hwnd, EM_SETZOOM, 0, 100);
ok(ret == FALSE, "EM_SETZOOM failed (%d).\n", ret);
ret = SendMessage(hwnd, EM_GETZOOM, (WPARAM)&numerator, (LPARAM)&denominator);
ok(numerator == 127, "incorrect numerator is %d\n", numerator);
ok(denominator == 2, "incorrect denominator is %d\n", denominator);
ok(ret == TRUE, "EM_GETZOOM failed (%d).\n", ret);
/* Reset the zoom value */
ret = SendMessage(hwnd, EM_SETZOOM, 0, 0);
ok(ret == TRUE, "EM_SETZOOM failed (%d).\n", ret);
DestroyWindow(hwnd);
}
struct dialog_mode_messages
{
int wm_getdefid, wm_close, wm_nextdlgctl;
};
static struct dialog_mode_messages dm_messages;
#define test_dm_messages(wmclose, wmgetdefid, wmnextdlgctl) \
ok(dm_messages.wm_close == wmclose, "expected %d WM_CLOSE message, " \
"got %d\n", wmclose, dm_messages.wm_close); \
ok(dm_messages.wm_getdefid == wmgetdefid, "expected %d WM_GETDIFID message, " \
"got %d\n", wmgetdefid, dm_messages.wm_getdefid);\
ok(dm_messages.wm_nextdlgctl == wmnextdlgctl, "expected %d WM_NEXTDLGCTL message, " \
"got %d\n", wmnextdlgctl, dm_messages.wm_nextdlgctl)
static LRESULT CALLBACK dialog_mode_wnd_proc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
switch (iMsg)
{
case DM_GETDEFID:
dm_messages.wm_getdefid++;
return MAKELONG(ID_RICHEDITTESTDBUTTON, DC_HASDEFID);
case WM_NEXTDLGCTL:
dm_messages.wm_nextdlgctl++;
break;
case WM_CLOSE:
dm_messages.wm_close++;
break;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
static void test_dialogmode(void)
{
HWND hwRichEdit, hwParent, hwButton;
MSG msg= {0};
int lcount, r;
WNDCLASSA cls;
cls.style = 0;
cls.lpfnWndProc = dialog_mode_wnd_proc;
cls.cbClsExtra = 0;
cls.cbWndExtra = 0;
cls.hInstance = GetModuleHandleA(0);
cls.hIcon = 0;
cls.hCursor = LoadCursorA(0, IDC_ARROW);
cls.hbrBackground = GetStockObject(WHITE_BRUSH);
cls.lpszMenuName = NULL;
cls.lpszClassName = "DialogModeParentClass";
if(!RegisterClassA(&cls)) assert(0);
hwParent = CreateWindow("DialogModeParentClass", NULL, WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, 0, 200, 120, NULL, NULL, GetModuleHandleA(0), NULL);
/* Test richedit(ES_MULTILINE) */
hwRichEdit = new_window(RICHEDIT_CLASS, ES_MULTILINE, hwParent);
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
lcount = SendMessage(hwRichEdit, EM_GETLINECOUNT, 0, 0);
ok(2 == lcount, "expected 2, got %d\n", lcount);
r = SendMessage(hwRichEdit, WM_GETDLGCODE, 0, 0);
ok(0x8f == r, "expected 0x8f, got 0x%x\n", r);
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
lcount = SendMessage(hwRichEdit, EM_GETLINECOUNT, 0, 0);
ok(3 == lcount, "expected 3, got %d\n", lcount);
r = SendMessage(hwRichEdit, WM_GETDLGCODE, 0, (LPARAM)&msg);
ok(0x8f == r, "expected 0x8f, got 0x%x\n", r);
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
lcount = SendMessage(hwRichEdit, EM_GETLINECOUNT, 0, 0);
ok(3 == lcount, "expected 3, got %d\n", lcount);
DestroyWindow(hwRichEdit);
/* Test standalone richedit(ES_MULTILINE) */
hwRichEdit = new_window(RICHEDIT_CLASS, ES_MULTILINE, NULL);
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
lcount = SendMessage(hwRichEdit, EM_GETLINECOUNT, 0, 0);
ok(2 == lcount, "expected 2, got %d\n", lcount);
r = SendMessage(hwRichEdit, WM_GETDLGCODE, 0, (LPARAM)&msg);
ok(0x8f == r, "expected 0x8f, got 0x%x\n", r);
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
lcount = SendMessage(hwRichEdit, EM_GETLINECOUNT, 0, 0);
ok(2 == lcount, "expected 2, got %d\n", lcount);
DestroyWindow(hwRichEdit);
/* Check a destination for messages */
hwRichEdit = new_window(RICHEDIT_CLASS, ES_MULTILINE, hwParent);
SetWindowLong(hwRichEdit, GWL_STYLE, GetWindowLong(hwRichEdit, GWL_STYLE)& ~WS_POPUP);
SetParent( hwRichEdit, NULL);
r = SendMessage(hwRichEdit, WM_GETDLGCODE, 0, (LPARAM)&msg);
ok(0x8f == r, "expected 0x8f, got 0x%x\n", r);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 1, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 1);
DestroyWindow(hwRichEdit);
/* Check messages from richedit(ES_MULTILINE) */
hwRichEdit = new_window(RICHEDIT_CLASS, ES_MULTILINE, hwParent);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
lcount = SendMessage(hwRichEdit, EM_GETLINECOUNT, 0, 0);
ok(2 == lcount, "expected 2, got %d\n", lcount);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_GETDLGCODE, 0, (LPARAM)&msg);
ok(0x8f == r, "expected 0x8f, got 0x%x\n", r);
test_dm_messages(0, 0, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 1, 0);
lcount = SendMessage(hwRichEdit, EM_GETLINECOUNT, 0, 0);
ok(2 == lcount, "expected 2, got %d\n", lcount);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 1);
hwButton = CreateWindow("BUTTON", "OK", WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
100, 100, 50, 20, hwParent, (HMENU)ID_RICHEDITTESTDBUTTON, GetModuleHandleA(0), NULL);
ok(hwButton!=NULL, "CreateWindow failed with error code %d\n", GetLastError());
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 1, 1);
lcount = SendMessage(hwRichEdit, EM_GETLINECOUNT, 0, 0);
ok(2 == lcount, "expected 2, got %d\n", lcount);
DestroyWindow(hwButton);
DestroyWindow(hwRichEdit);
/* Check messages from richedit(ES_MULTILINE|ES_WANTRETURN) */
hwRichEdit = new_window(RICHEDIT_CLASS, ES_MULTILINE|ES_WANTRETURN, hwParent);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
lcount = SendMessage(hwRichEdit, EM_GETLINECOUNT, 0, 0);
ok(2 == lcount, "expected 2, got %d\n", lcount);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_GETDLGCODE, 0, (LPARAM)&msg);
ok(0x8f == r, "expected 0x8f, got 0x%x\n", r);
test_dm_messages(0, 0, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
lcount = SendMessage(hwRichEdit, EM_GETLINECOUNT, 0, 0);
ok(3 == lcount, "expected 3, got %d\n", lcount);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 1);
hwButton = CreateWindow("BUTTON", "OK", WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
100, 100, 50, 20, hwParent, (HMENU)ID_RICHEDITTESTDBUTTON, GetModuleHandleA(0), NULL);
ok(hwButton!=NULL, "CreateWindow failed with error code %d\n", GetLastError());
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
lcount = SendMessage(hwRichEdit, EM_GETLINECOUNT, 0, 0);
ok(4 == lcount, "expected 4, got %d\n", lcount);
DestroyWindow(hwButton);
DestroyWindow(hwRichEdit);
/* Check messages from richedit(0) */
hwRichEdit = new_window(RICHEDIT_CLASS, 0, hwParent);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_GETDLGCODE, 0, (LPARAM)&msg);
ok(0x8b == r, "expected 0x8b, got 0x%x\n", r);
test_dm_messages(0, 0, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 1, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_ESCAPE, 0x10001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_TAB, 0xf0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 1);
hwButton = CreateWindow("BUTTON", "OK", WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
100, 100, 50, 20, hwParent, (HMENU)ID_RICHEDITTESTDBUTTON, GetModuleHandleA(0), NULL);
ok(hwButton!=NULL, "CreateWindow failed with error code %d\n", GetLastError());
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 1, 1);
DestroyWindow(hwRichEdit);
/* Check messages from richedit(ES_WANTRETURN) */
hwRichEdit = new_window(RICHEDIT_CLASS, ES_WANTRETURN, hwParent);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_GETDLGCODE, 0, (LPARAM)&msg);
ok(0x8b == r, "expected 0x8b, got 0x%x\n", r);
test_dm_messages(0, 0, 0);
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
hwButton = CreateWindow("BUTTON", "OK", WS_VISIBLE|WS_CHILD|BS_PUSHBUTTON,
100, 100, 50, 20, hwParent, (HMENU)ID_RICHEDITTESTDBUTTON, GetModuleHandleA(0), NULL);
ok(hwButton!=NULL, "CreateWindow failed with error code %d\n", GetLastError());
memset(&dm_messages, 0, sizeof(dm_messages));
r = SendMessage(hwRichEdit, WM_KEYDOWN, VK_RETURN, 0x1c0001);
ok(0 == r, "expected 0, got %d\n", r);
test_dm_messages(0, 0, 0);
DestroyWindow(hwRichEdit);
DestroyWindow(hwParent);
}
static void test_EM_FINDWORDBREAK_W(void)
{
static const struct {
WCHAR c;
BOOL isdelimiter; /* expected result of WB_ISDELIMITER */
} delimiter_tests[] = {
{0x0a, FALSE}, /* newline */
{0x0b, FALSE}, /* vertical tab */
{0x0c, FALSE}, /* form feed */
{0x0d, FALSE}, /* carriage return */
{0x20, TRUE}, /* space */
{0x61, FALSE}, /* capital letter a */
{0xa0, FALSE}, /* no-break space */
{0x2000, FALSE}, /* en quad */
{0x3000, FALSE}, /* Ideographic space */
{0x1100, FALSE}, /* Hangul Choseong Kiyeok (G sound) Ordinary Letter*/
{0x11ff, FALSE}, /* Hangul Jongseoung Kiyeok-Hieuh (Hard N sound) Ordinary Letter*/
{0x115f, FALSE}, /* Hangul Choseong Filler (no sound, used with two letter Hangul words) Ordinary Letter */
{0xac00, FALSE}, /* Hangul character GA*/
{0xd7af, FALSE}, /* End of Hangul character chart */
{0xf020, TRUE}, /* MS private for CP_SYMBOL round trip?, see kb897872 */
{0xff20, FALSE}, /* fullwidth commercial @ */
{WCH_EMBEDDING, FALSE}, /* object replacement character*/
};
int i;
HWND hwndRichEdit = new_richeditW(NULL);
ok(IsWindowUnicode(hwndRichEdit), "window should be unicode\n");
for (i = 0; i < sizeof(delimiter_tests)/sizeof(delimiter_tests[0]); i++)
{
WCHAR wbuf[2];
int result;
wbuf[0] = delimiter_tests[i].c;
wbuf[1] = 0;
SendMessageW(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)wbuf);
result = SendMessageW(hwndRichEdit, EM_FINDWORDBREAK, WB_ISDELIMITER,0);
if (wbuf[0] == 0x20 || wbuf[0] == 0xf020)
todo_wine
ok(result == delimiter_tests[i].isdelimiter,
"wanted ISDELIMITER_W(0x%x) %d, got %d\n",
delimiter_tests[i].c, delimiter_tests[i].isdelimiter,result);
else
ok(result == delimiter_tests[i].isdelimiter,
"wanted ISDELIMITER_W(0x%x) %d, got %d\n",
delimiter_tests[i].c, delimiter_tests[i].isdelimiter, result);
}
DestroyWindow(hwndRichEdit);
}
static void test_EM_FINDWORDBREAK_A(void)
{
static const struct {
WCHAR c;
BOOL isdelimiter; /* expected result of WB_ISDELIMITER */
} delimiter_tests[] = {
{0x0a, FALSE}, /* newline */
{0x0b, FALSE}, /* vertical tab */
{0x0c, FALSE}, /* form feed */
{0x0d, FALSE}, /* carriage return */
{0x20, TRUE}, /* space */
{0x61, FALSE}, /* capital letter a */
};
int i;
HWND hwndRichEdit = new_richedit(NULL);
ok(!IsWindowUnicode(hwndRichEdit), "window should not be unicode\n");
for (i = 0; i < sizeof(delimiter_tests)/sizeof(delimiter_tests[0]); i++)
{
int result;
char buf[2];
buf[0] = delimiter_tests[i].c;
buf[1] = 0;
SendMessageW(hwndRichEdit, WM_SETTEXT, 0, (LPARAM)buf);
result = SendMessage(hwndRichEdit, EM_FINDWORDBREAK, WB_ISDELIMITER, 0);
if (buf[0] == 0x20)
todo_wine
ok(result == delimiter_tests[i].isdelimiter,
"wanted ISDELIMITER_A(0x%x) %d, got %d\n",
delimiter_tests[i].c, delimiter_tests[i].isdelimiter,result);
else
ok(result == delimiter_tests[i].isdelimiter,
"wanted ISDELIMITER_A(0x%x) %d, got %d\n",
delimiter_tests[i].c, delimiter_tests[i].isdelimiter, result);
}
DestroyWindow(hwndRichEdit);
}
/*
* This test attempts to show the effect of enter on a richedit
* control v1.0 inserts CRLF whereas for higher versions it only
* inserts CR. If shows that EM_GETTEXTEX with GT_USECRLF == WM_GETTEXT
* and also shows that GT_USECRLF has no effect in richedit 1.0, but
* does for higher. The same test is cloned in riched32 and riched20.
*/
static void test_enter(void)
{
static const struct {
const char *initialtext;
const int cursor;
const char *expectedwmtext;
const char *expectedemtext;
const char *expectedemtextcrlf;
} testenteritems[] = {
{ "aaabbb\r\n", 3, "aaa\r\nbbb\r\n", "aaa\rbbb\r", "aaa\r\nbbb\r\n"},
{ "aaabbb\r\n", 6, "aaabbb\r\n\r\n", "aaabbb\r\r", "aaabbb\r\n\r\n"},
{ "aa\rabbb\r\n", 7, "aa\r\nabbb\r\n\r\n", "aa\rabbb\r\r", "aa\r\nabbb\r\n\r\n"},
{ "aa\rabbb\r\n", 3, "aa\r\n\r\nabbb\r\n", "aa\r\rabbb\r", "aa\r\n\r\nabbb\r\n"},
{ "aa\rabbb\r\n", 2, "aa\r\n\r\nabbb\r\n", "aa\r\rabbb\r", "aa\r\n\r\nabbb\r\n"}
};
char expectedbuf[1024];
char resultbuf[1024];
HWND hwndRichEdit = new_richedit(NULL);
UINT i,j;
for (i = 0; i < sizeof(testenteritems)/sizeof(testenteritems[0]); i++) {
char buf[1024] = {0};
LRESULT result;
GETTEXTEX getText;
const char *expected;
/* Set the text to the initial text */
result = SendMessage(hwndRichEdit, WM_SETTEXT, 0, (LPARAM) testenteritems[i].initialtext);
ok (result == 1, "[%d] WM_SETTEXT returned %ld instead of 1\n", i, result);
/* Send Enter */
SendMessage(hwndRichEdit, EM_SETSEL, testenteritems[i].cursor, testenteritems[i].cursor);
simulate_typing_characters(hwndRichEdit, "\r");
/* 1. Retrieve with WM_GETTEXT */
buf[0] = 0x00;
result = SendMessage(hwndRichEdit, WM_GETTEXT, 1024, (LPARAM) buf);
expected = testenteritems[i].expectedwmtext;
resultbuf[0]=0x00;
for (j = 0; j < (UINT)result; j++)
sprintf(resultbuf+strlen(resultbuf), "%02x", buf[j] & 0xFF);
expectedbuf[0] = '\0';
for (j = 0; j < strlen(expected); j++)
sprintf(expectedbuf+strlen(expectedbuf), "%02x", expected[j] & 0xFF);
result = strcmp(expected, buf);
ok (result == 0,
"[%d] WM_GETTEXT unexpected '%s' expected '%s'\n",
i, resultbuf, expectedbuf);
/* 2. Retrieve with EM_GETTEXTEX, GT_DEFAULT */
getText.cb = sizeof(buf);
getText.flags = GT_DEFAULT;
getText.codepage = CP_ACP;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
buf[0] = 0x00;
result = SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
expected = testenteritems[i].expectedemtext;
resultbuf[0]=0x00;
for (j = 0; j < (UINT)result; j++)
sprintf(resultbuf+strlen(resultbuf), "%02x", buf[j] & 0xFF);
expectedbuf[0] = '\0';
for (j = 0; j < strlen(expected); j++)
sprintf(expectedbuf+strlen(expectedbuf), "%02x", expected[j] & 0xFF);
result = strcmp(expected, buf);
ok (result == 0,
"[%d] EM_GETTEXTEX, GT_DEFAULT unexpected '%s', expected '%s'\n",
i, resultbuf, expectedbuf);
/* 3. Retrieve with EM_GETTEXTEX, GT_USECRLF */
getText.cb = sizeof(buf);
getText.flags = GT_USECRLF;
getText.codepage = CP_ACP;
getText.lpDefaultChar = NULL;
getText.lpUsedDefChar = NULL;
buf[0] = 0x00;
result = SendMessage(hwndRichEdit, EM_GETTEXTEX, (WPARAM)&getText, (LPARAM) buf);
expected = testenteritems[i].expectedemtextcrlf;
resultbuf[0]=0x00;
for (j = 0; j < (UINT)result; j++)
sprintf(resultbuf+strlen(resultbuf), "%02x", buf[j] & 0xFF);
expectedbuf[0] = '\0';
for (j = 0; j < strlen(expected); j++)
sprintf(expectedbuf+strlen(expectedbuf), "%02x", expected[j] & 0xFF);
result = strcmp(expected, buf);
ok (result == 0,
"[%d] EM_GETTEXTEX, GT_USECRLF unexpected '%s', expected '%s'\n",
i, resultbuf, expectedbuf);
}
DestroyWindow(hwndRichEdit);
}
START_TEST( editor )
{
BOOL ret;
/* Must explicitly LoadLibrary(). The test has no references to functions in
* RICHED20.DLL, so the linker doesn't actually link to it. */
hmoduleRichEdit = LoadLibrary("RICHED20.DLL");
ok(hmoduleRichEdit != NULL, "error: %d\n", (int) GetLastError());
test_WM_CHAR();
test_EM_FINDTEXT();
test_EM_GETLINE();
test_EM_POSFROMCHAR();
test_EM_SCROLLCARET();
test_EM_SCROLL();
test_scrollbar_visibility();
test_WM_SETTEXT();
test_EM_LINELENGTH();
test_EM_SETCHARFORMAT();
test_EM_SETTEXTMODE();
test_TM_PLAINTEXT();
test_EM_SETOPTIONS();
test_WM_GETTEXT();
test_EM_GETTEXTRANGE();
test_EM_GETSELTEXT();
test_EM_SETUNDOLIMIT();
test_ES_PASSWORD();
test_EM_SETTEXTEX();
test_EM_LIMITTEXT();
test_EM_EXLIMITTEXT();
test_EM_GETLIMITTEXT();
test_WM_SETFONT();
test_EM_GETMODIFY();
test_EM_EXSETSEL();
test_WM_PASTE();
test_EM_STREAMIN();
test_EM_STREAMOUT();
test_EM_STREAMOUT_FONTTBL();
test_EM_StreamIn_Undo();
test_EM_FORMATRANGE();
test_unicode_conversions();
test_EM_GETTEXTLENGTHEX();
test_EM_REPLACESEL(1);
test_EM_REPLACESEL(0);
test_WM_NOTIFY();
test_EM_AUTOURLDETECT();
test_eventMask();
test_undo_coalescing();
test_word_movement();
test_EM_CHARFROMPOS();
test_SETPARAFORMAT();
test_word_wrap();
test_autoscroll();
test_format_rect();
test_WM_GETDLGCODE();
test_zoom();
test_dialogmode();
test_EM_FINDWORDBREAK_W();
test_EM_FINDWORDBREAK_A();
test_enter();
/* Set the environment variable WINETEST_RICHED20 to keep windows
* responsive and open for 30 seconds. This is useful for debugging.
*/
if (getenv( "WINETEST_RICHED20" )) {
keep_responsive(30);
}
OleFlushClipboard();
ret = FreeLibrary(hmoduleRichEdit);
ok(ret, "error: %d\n", (int) GetLastError());
}
|