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
|
/*
* Message queues related functions
*
* Copyright 1993, 1994 Alexandre Julliard
*/
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/time.h>
#include <sys/types.h>
#include "wine/winbase16.h"
#include "message.h"
#include "winerror.h"
#include "win.h"
#include "heap.h"
#include "hook.h"
#include "input.h"
#include "spy.h"
#include "winpos.h"
#include "dde.h"
#include "queue.h"
#include "winproc.h"
#include "task.h"
#include "process.h"
#include "thread.h"
#include "options.h"
#include "struct32.h"
#include "debugtools.h"
DEFAULT_DEBUG_CHANNEL(msg)
DECLARE_DEBUG_CHANNEL(key)
DECLARE_DEBUG_CHANNEL(sendmsg)
#define WM_NCMOUSEFIRST WM_NCMOUSEMOVE
#define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK
typedef enum { SYSQ_MSG_ABANDON, SYSQ_MSG_SKIP,
SYSQ_MSG_ACCEPT, SYSQ_MSG_CONTINUE } SYSQ_STATUS;
extern HQUEUE16 hCursorQueue; /* queue.c */
DWORD MSG_WineStartTicks; /* Ticks at Wine startup */
static UINT doubleClickSpeed = 452;
/***********************************************************************
* MSG_CheckFilter
*/
static BOOL MSG_CheckFilter(DWORD uMsg, DWORD first, DWORD last)
{
if( first || last )
return (uMsg >= first && uMsg <= last);
return TRUE;
}
/***********************************************************************
* MSG_SendParentNotify
*
* Send a WM_PARENTNOTIFY to all ancestors of the given window, unless
* the window has the WS_EX_NOPARENTNOTIFY style.
*/
static void MSG_SendParentNotify(WND* wndPtr, WORD event, WORD idChild, LPARAM lValue)
{
#define lppt ((LPPOINT16)&lValue)
/* pt has to be in the client coordinates of the parent window */
WND *tmpWnd = WIN_LockWndPtr(wndPtr);
MapWindowPoints16( 0, tmpWnd->hwndSelf, lppt, 1 );
while (tmpWnd)
{
if (!(tmpWnd->dwStyle & WS_CHILD) || (tmpWnd->dwExStyle & WS_EX_NOPARENTNOTIFY))
{
WIN_ReleaseWndPtr(tmpWnd);
break;
}
lppt->x += tmpWnd->rectClient.left;
lppt->y += tmpWnd->rectClient.top;
WIN_UpdateWndPtr(&tmpWnd,tmpWnd->parent);
SendMessageA( tmpWnd->hwndSelf, WM_PARENTNOTIFY,
MAKEWPARAM( event, idChild ), lValue );
}
#undef lppt
}
/***********************************************************************
* MSG_TranslateMouseMsg
*
* Translate an mouse hardware event into a real mouse message.
*
* Returns:
*
* SYSQ_MSG_ABANDON - abandon the peek message loop
* SYSQ_MSG_CONTINUE - leave the message in the queue and
* continue with the translation loop
* SYSQ_MSG_ACCEPT - proceed to process the translated message
*/
static DWORD MSG_TranslateMouseMsg( HWND hTopWnd, DWORD first, DWORD last,
MSG *msg, BOOL remove, WND* pWndScope,
INT16 *pHitTest, POINT16 *pScreen_pt, BOOL *pmouseClick )
{
static DWORD dblclk_time_limit = 0;
static UINT16 clk_message = 0;
static HWND16 clk_hwnd = 0;
static POINT16 clk_pos = { 0, 0 };
WND *pWnd;
HWND hWnd;
INT16 ht, hittest;
UINT message = msg->message;
POINT16 screen_pt, pt;
HANDLE16 hQ = GetFastQueue16();
MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock(hQ);
BOOL mouseClick = ((message == WM_LBUTTONDOWN) ||
(message == WM_RBUTTONDOWN) ||
(message == WM_MBUTTONDOWN))?1:0;
DWORD retvalue;
/* Find the window to dispatch this mouse message to */
CONV_POINT32TO16( &msg->pt, &pt );
hWnd = GetCapture();
/* If no capture HWND, find window which contains the mouse position.
* Also find the position of the cursor hot spot (hittest) */
if( !hWnd )
{
ht = hittest = WINPOS_WindowFromPoint( pWndScope, pt, &pWnd );
if( !pWnd ) pWnd = WIN_GetDesktop();
else WIN_LockWndPtr(pWnd);
hWnd = pWnd->hwndSelf;
}
else
{
ht = hittest = HTCLIENT;
pWnd = WIN_FindWndPtr(hWnd);
if (queue)
ht = PERQDATA_GetCaptureInfo( queue->pQData );
}
/* Save hittest for return */
*pHitTest = hittest;
/* stop if not the right queue */
if (pWnd->hmemTaskQ != hQ)
{
/* Not for the current task */
if (queue) QUEUE_ClearWakeBit( queue, QS_MOUSE );
/* Wake up the other task */
QUEUE_Unlock( queue );
queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
if (queue) QUEUE_SetWakeBit( queue, QS_MOUSE );
QUEUE_Unlock( queue );
retvalue = SYSQ_MSG_ABANDON;
goto END;
}
/* check if hWnd is within hWndScope */
if( hTopWnd && hWnd != hTopWnd )
if( !IsChild(hTopWnd, hWnd) )
{
QUEUE_Unlock( queue );
retvalue = SYSQ_MSG_CONTINUE;
goto END;
}
/* Was it a mouse click message */
if( mouseClick )
{
/* translate double clicks -
* note that ...MOUSEMOVEs can slip in between
* ...BUTTONDOWN and ...BUTTONDBLCLK messages */
if(GetClassLongA(hWnd, GCL_STYLE) & CS_DBLCLKS || ht != HTCLIENT )
{
if ((message == clk_message) && (hWnd == clk_hwnd) &&
(msg->time - dblclk_time_limit < doubleClickSpeed) &&
(abs(msg->pt.x - clk_pos.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) &&
(abs(msg->pt.y - clk_pos.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2))
{
message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN);
mouseClick++; /* == 2 */
}
}
}
/* save mouse position */
screen_pt = pt;
*pScreen_pt = pt;
if (hittest != HTCLIENT)
{
message += WM_NCMOUSEMOVE - WM_MOUSEMOVE;
msg->wParam = hittest;
}
else
ScreenToClient16( hWnd, &pt );
/* check message filter */
if (!MSG_CheckFilter(message, first, last))
{
QUEUE_Unlock(queue);
retvalue = SYSQ_MSG_CONTINUE;
goto END;
}
/* Update global hCursorQueue */
hCursorQueue = queue->self;
/* Update static double click conditions */
if( remove && mouseClick )
{
if( mouseClick == 1 )
{
/* set conditions */
dblclk_time_limit = msg->time;
clk_message = msg->message;
clk_hwnd = hWnd;
clk_pos = screen_pt;
} else
/* got double click - zero them out */
dblclk_time_limit = clk_hwnd = 0;
}
QUEUE_Unlock(queue);
/* Update message params */
msg->hwnd = hWnd;
msg->message = message;
msg->lParam = MAKELONG( pt.x, pt.y );
retvalue = SYSQ_MSG_ACCEPT;
END:
WIN_ReleaseWndPtr(pWnd);
/* Return mouseclick flag */
*pmouseClick = mouseClick;
return retvalue;
}
/***********************************************************************
* MSG_ProcessMouseMsg
*
* Processes a translated mouse hardware event.
* The passed in msg structure should contain the updated hWnd,
* lParam, wParam and message fields from MSG_TranslateMouseMsg.
*
* Returns:
*
* SYSQ_MSG_SKIP - Message should be skipped entirely (in this case
* HIWORD contains hit test code). Continue translating..
* SYSQ_MSG_ACCEPT - the translated message must be passed to the user
* MSG_PeekHardwareMsg should return TRUE.
*/
static DWORD MSG_ProcessMouseMsg( MSG *msg, BOOL remove, INT16 hittest,
POINT16 screen_pt, BOOL mouseClick )
{
WND *pWnd;
HWND hWnd = msg->hwnd;
INT16 sendSC = (GetCapture() == 0);
UINT message = msg->message;
BOOL eatMsg = FALSE;
DWORD retvalue;
pWnd = WIN_FindWndPtr(hWnd);
/* call WH_MOUSE */
if (HOOK_IsHooked( WH_MOUSE ))
{
SYSQ_STATUS ret = 0;
MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
if( hook )
{
hook->pt = screen_pt;
hook->hwnd = hWnd;
hook->wHitTestCode = hittest;
hook->dwExtraInfo = 0;
ret = HOOK_CallHooks16( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE,
message, (LPARAM)SEGPTR_GET(hook) );
SEGPTR_FREE(hook);
}
if( ret )
{
retvalue = MAKELONG((INT16)SYSQ_MSG_SKIP, hittest);
goto END;
}
}
if ((hittest == HTERROR) || (hittest == HTNOWHERE))
eatMsg = sendSC = 1;
else if( remove && mouseClick )
{
HWND hwndTop = WIN_GetTopParent( hWnd );
if( sendSC )
{
/* Send the WM_PARENTNOTIFY,
* note that even for double/nonclient clicks
* notification message is still WM_L/M/RBUTTONDOWN.
*/
MSG_SendParentNotify( pWnd, msg->message & 0xffff, 0, MAKELPARAM(screen_pt.x, screen_pt.y) );
/* Activate the window if needed */
if (hWnd != GetActiveWindow() && hWnd != GetDesktopWindow())
{
LONG ret = SendMessageA( hWnd, WM_MOUSEACTIVATE, hwndTop,
MAKELONG( hittest, message ) );
if ((ret == MA_ACTIVATEANDEAT) || (ret == MA_NOACTIVATEANDEAT))
eatMsg = TRUE;
if (((ret == MA_ACTIVATE) || (ret == MA_ACTIVATEANDEAT))
&& hwndTop != GetForegroundWindow() )
{
if (!WINPOS_SetActiveWindow( hwndTop, TRUE , TRUE ))
eatMsg = TRUE;
}
}
}
} else sendSC = (remove && sendSC);
/* Send the WM_SETCURSOR message */
if (sendSC)
{
UINT uSCMessage = message;
/* Windows sends the normal mouse message as the message parameter
in the WM_SETCURSOR message even if it's non-client mouse message */
if (uSCMessage >= WM_NCMOUSEFIRST && uSCMessage <= WM_NCMOUSELAST)
uSCMessage += WM_MOUSEFIRST - WM_NCMOUSEFIRST;
SendMessageA( hWnd, WM_SETCURSOR, hWnd,
MAKELONG( hittest, uSCMessage));
}
if (eatMsg)
{
retvalue = MAKELONG( (UINT16)SYSQ_MSG_SKIP, hittest);
goto END;
}
retvalue = SYSQ_MSG_ACCEPT;
END:
WIN_ReleaseWndPtr(pWnd);
return retvalue;
}
/***********************************************************************
* MSG_TranslateKbdMsg
*
* Translate an keyboard hardware event into a real message.
*/
static DWORD MSG_TranslateKbdMsg( HWND hTopWnd, DWORD first, DWORD last,
MSG *msg, BOOL remove )
{
WORD message = msg->message;
HWND hWnd = GetFocus();
WND *pWnd;
/* Should check Ctrl-Esc and PrintScreen here */
if (!hWnd)
{
/* Send the message to the active window instead, */
/* translating messages to their WM_SYS equivalent */
hWnd = GetActiveWindow();
if( message < WM_SYSKEYDOWN )
message += WM_SYSKEYDOWN - WM_KEYDOWN;
}
pWnd = WIN_FindWndPtr( hWnd );
if (pWnd && (pWnd->hmemTaskQ != GetFastQueue16()))
{
/* Not for the current task */
MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() );
if (queue) QUEUE_ClearWakeBit( queue, QS_KEY );
QUEUE_Unlock( queue );
/* Wake up the other task */
queue = (MESSAGEQUEUE *)QUEUE_Lock( pWnd->hmemTaskQ );
if (queue) QUEUE_SetWakeBit( queue, QS_KEY );
QUEUE_Unlock( queue );
WIN_ReleaseWndPtr(pWnd);
return SYSQ_MSG_ABANDON;
}
WIN_ReleaseWndPtr(pWnd);
if (hTopWnd && hWnd != hTopWnd)
if (!IsChild(hTopWnd, hWnd)) return SYSQ_MSG_CONTINUE;
if (!MSG_CheckFilter(message, first, last)) return SYSQ_MSG_CONTINUE;
msg->hwnd = hWnd;
msg->message = message;
return SYSQ_MSG_ACCEPT;
}
/***********************************************************************
* MSG_ProcessKbdMsg
*
* Processes a translated keyboard message
*/
static DWORD MSG_ProcessKbdMsg( MSG *msg, BOOL remove )
{
return (HOOK_CallHooks16( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE,
LOWORD (msg->wParam), msg->lParam )
? SYSQ_MSG_SKIP : SYSQ_MSG_ACCEPT);
}
/***********************************************************************
* MSG_JournalRecordMsg
*
* Build an EVENTMSG structure and call JOURNALRECORD hook
*/
static void MSG_JournalRecordMsg( MSG *msg )
{
EVENTMSG *event = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
if (!event) return;
event->message = msg->message;
event->time = msg->time;
if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
{
event->paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8);
event->paramH = msg->lParam & 0x7FFF;
if (HIWORD(msg->lParam) & 0x0100)
event->paramH |= 0x8000; /* special_key - bit */
HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
}
else if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
{
event->paramL = LOWORD(msg->lParam); /* X pos */
event->paramH = HIWORD(msg->lParam); /* Y pos */
ClientToScreen16( msg->hwnd, (LPPOINT16)&event->paramL );
HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
}
else if ((msg->message >= WM_NCMOUSEFIRST) &&
(msg->message <= WM_NCMOUSELAST))
{
event->paramL = LOWORD(msg->lParam); /* X pos */
event->paramH = HIWORD(msg->lParam); /* Y pos */
event->message += WM_MOUSEMOVE-WM_NCMOUSEMOVE;/* give no info about NC area */
HOOK_CallHooksA( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)event );
}
HeapFree(SystemHeap, 0, event);
}
/***********************************************************************
* MSG_JournalPlayBackMsg
*
* Get an EVENTMSG struct via call JOURNALPLAYBACK hook function
*/
static int MSG_JournalPlayBackMsg(void)
{
EVENTMSG *tmpMsg;
long wtime,lParam,wParam;
WORD keyDown,i,result=0;
if ( HOOK_IsHooked( WH_JOURNALPLAYBACK ) )
{
tmpMsg = (EVENTMSG *) HeapAlloc(SystemHeap, 0, sizeof(EVENTMSG));
if (!tmpMsg) return result;
wtime=HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_GETNEXT, 0,
(LPARAM) tmpMsg );
/* TRACE(msg,"Playback wait time =%ld\n",wtime); */
if (wtime<=0)
{
wtime=0;
if ((tmpMsg->message>= WM_KEYFIRST) && (tmpMsg->message <= WM_KEYLAST))
{
wParam=tmpMsg->paramL & 0xFF;
lParam=MAKELONG(tmpMsg->paramH&0x7ffff,tmpMsg->paramL>>8);
if (tmpMsg->message == WM_KEYDOWN || tmpMsg->message == WM_SYSKEYDOWN)
{
for (keyDown=i=0; i<256 && !keyDown; i++)
if (InputKeyStateTable[i] & 0x80)
keyDown++;
if (!keyDown)
lParam |= 0x40000000;
AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] |= 0x80;
}
else /* WM_KEYUP, WM_SYSKEYUP */
{
lParam |= 0xC0000000;
AsyncKeyStateTable[wParam]=InputKeyStateTable[wParam] &= ~0x80;
}
if (InputKeyStateTable[VK_MENU] & 0x80)
lParam |= 0x20000000;
if (tmpMsg->paramH & 0x8000) /*special_key bit*/
lParam |= 0x01000000;
hardware_event( tmpMsg->message & 0xffff, LOWORD(wParam), lParam,
0, 0, tmpMsg->time, 0 );
}
else
{
if ((tmpMsg->message>= WM_MOUSEFIRST) && (tmpMsg->message <= WM_MOUSELAST))
{
switch (tmpMsg->message)
{
case WM_LBUTTONDOWN:
MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=TRUE;break;
case WM_LBUTTONUP:
MouseButtonsStates[0]=AsyncMouseButtonsStates[0]=FALSE;break;
case WM_MBUTTONDOWN:
MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=TRUE;break;
case WM_MBUTTONUP:
MouseButtonsStates[1]=AsyncMouseButtonsStates[1]=FALSE;break;
case WM_RBUTTONDOWN:
MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=TRUE;break;
case WM_RBUTTONUP:
MouseButtonsStates[2]=AsyncMouseButtonsStates[2]=FALSE;break;
}
AsyncKeyStateTable[VK_LBUTTON]= InputKeyStateTable[VK_LBUTTON] = MouseButtonsStates[0] ? 0x80 : 0;
AsyncKeyStateTable[VK_MBUTTON]= InputKeyStateTable[VK_MBUTTON] = MouseButtonsStates[1] ? 0x80 : 0;
AsyncKeyStateTable[VK_RBUTTON]= InputKeyStateTable[VK_RBUTTON] = MouseButtonsStates[2] ? 0x80 : 0;
SetCursorPos(tmpMsg->paramL,tmpMsg->paramH);
lParam=MAKELONG(tmpMsg->paramL,tmpMsg->paramH);
wParam=0;
if (MouseButtonsStates[0]) wParam |= MK_LBUTTON;
if (MouseButtonsStates[1]) wParam |= MK_MBUTTON;
if (MouseButtonsStates[2]) wParam |= MK_RBUTTON;
hardware_event( tmpMsg->message & 0xffff, LOWORD (wParam), lParam,
tmpMsg->paramL, tmpMsg->paramH, tmpMsg->time, 0 );
}
}
HOOK_CallHooksA( WH_JOURNALPLAYBACK, HC_SKIP, 0,
(LPARAM) tmpMsg);
}
else
{
if( tmpMsg->message == WM_QUEUESYNC )
if (HOOK_IsHooked( WH_CBT ))
HOOK_CallHooksA( WH_CBT, HCBT_QS, 0, 0L);
result= QS_MOUSE | QS_KEY; /* ? */
}
HeapFree(SystemHeap, 0, tmpMsg);
}
return result;
}
/***********************************************************************
* MSG_PeekHardwareMsg
*
* Peek for a hardware message matching the hwnd and message filters.
*/
static BOOL MSG_PeekHardwareMsg( MSG *msg, HWND hwnd, DWORD first, DWORD last,
BOOL remove )
{
/* FIXME: should deal with MSG32 instead of MSG16 */
DWORD status = SYSQ_MSG_ACCEPT;
MESSAGEQUEUE *sysMsgQueue = QUEUE_GetSysQueue();
enum { MOUSE_MSG = 0, KEYBOARD_MSG, HARDWARE_MSG } msgType;
QMSG *nextqmsg, *qmsg = 0;
BOOL bRet = FALSE;
/* FIXME: there has to be a better way to do this */
joySendMessages();
EnterCriticalSection(&sysMsgQueue->cSection);
/* Loop through the Q and translate the message we wish to process
* while we own the lock. Based on the translation status (abandon/cont/accept)
* we then process the message accordingly
*/
for ( qmsg = sysMsgQueue->firstMsg; qmsg; qmsg = nextqmsg )
{
INT16 hittest;
POINT16 screen_pt;
BOOL mouseClick;
*msg = qmsg->msg;
nextqmsg = qmsg->nextMsg;
/* Translate message */
if ((msg->message >= WM_MOUSEFIRST) && (msg->message <= WM_MOUSELAST))
{
HWND hWndScope = (HWND)qmsg->extraInfo;
WND *tmpWnd = (Options.managed && IsWindow(hWndScope) )
? WIN_FindWndPtr(hWndScope) : WIN_GetDesktop();
status = MSG_TranslateMouseMsg(hwnd, first, last, msg, remove, tmpWnd,
&hittest, &screen_pt, &mouseClick );
msgType = MOUSE_MSG;
WIN_ReleaseWndPtr(tmpWnd);
}
else if ((msg->message >= WM_KEYFIRST) && (msg->message <= WM_KEYLAST))
{
status = MSG_TranslateKbdMsg(hwnd, first, last, msg, remove);
msgType = KEYBOARD_MSG;
}
else /* Non-standard hardware event */
{
HARDWAREHOOKSTRUCT16 *hook;
msgType = HARDWARE_MSG;
if ((hook = SEGPTR_NEW(HARDWAREHOOKSTRUCT16)))
{
BOOL ret;
hook->hWnd = msg->hwnd;
hook->wMessage = msg->message & 0xffff;
hook->wParam = LOWORD (msg->wParam);
hook->lParam = msg->lParam;
ret = HOOK_CallHooks16( WH_HARDWARE,
remove ? HC_ACTION : HC_NOREMOVE,
0, (LPARAM)SEGPTR_GET(hook) );
SEGPTR_FREE(hook);
if (ret)
{
QUEUE_RemoveMsg( sysMsgQueue, qmsg );
continue;
}
status = SYSQ_MSG_ACCEPT;
}
}
switch (LOWORD(status))
{
case SYSQ_MSG_ACCEPT:
{
/* Remove the message from the system msg Q while it is still locked,
* before accepting it */
if (remove)
{
if (HOOK_IsHooked( WH_JOURNALRECORD )) MSG_JournalRecordMsg( msg );
QUEUE_RemoveMsg( sysMsgQueue, qmsg );
}
/* Now actually process the message, after we unlock the system msg Q.
* We should not hold on to the crst since SendMessage calls during processing
* will potentially cause callbacks to PeekMessage from the application.
* If we're holding the crst and QUEUE_WaitBits is called with a
* QS_SENDMESSAGE mask we will deadlock in hardware_event() when a
* message is being posted to the Q.
*/
LeaveCriticalSection(&sysMsgQueue->cSection);
if( msgType == KEYBOARD_MSG )
status = MSG_ProcessKbdMsg( msg, remove );
else if ( msgType == MOUSE_MSG )
status = MSG_ProcessMouseMsg( msg, remove, hittest, screen_pt, mouseClick );
/* Reclaim the sys msg Q crst */
EnterCriticalSection(&sysMsgQueue->cSection);
/* Pass the translated message to the user if it was accepted */
if (status == SYSQ_MSG_ACCEPT)
break;
/* If not accepted, fall through into the SYSQ_MSG_SKIP case */
}
case SYSQ_MSG_SKIP:
if (HOOK_IsHooked( WH_CBT ))
{
if( msgType == KEYBOARD_MSG )
HOOK_CallHooks16( WH_CBT, HCBT_KEYSKIPPED,
LOWORD (msg->wParam), msg->lParam );
else if ( msgType == MOUSE_MSG )
{
MOUSEHOOKSTRUCT16 *hook = SEGPTR_NEW(MOUSEHOOKSTRUCT16);
if (hook)
{
CONV_POINT32TO16( &msg->pt,&hook->pt );
hook->hwnd = msg->hwnd;
hook->wHitTestCode = HIWORD(status);
hook->dwExtraInfo = 0;
HOOK_CallHooks16( WH_CBT, HCBT_CLICKSKIPPED ,msg->message & 0xffff,
(LPARAM)SEGPTR_GET(hook) );
SEGPTR_FREE(hook);
}
}
}
/* If the message was removed earlier set up nextqmsg so that we start
* at the top of the queue again. We need to do this since our next pointer
* could be invalid due to us unlocking the system message Q to process the message.
* If not removed just refresh nextqmsg to point to the next msg.
*/
if (remove)
nextqmsg = sysMsgQueue->firstMsg;
else
nextqmsg = qmsg->nextMsg;
continue;
case SYSQ_MSG_CONTINUE:
continue;
case SYSQ_MSG_ABANDON:
bRet = FALSE;
goto END;
}
bRet = TRUE;
goto END;
}
END:
LeaveCriticalSection(&sysMsgQueue->cSection);
return bRet;
}
/**********************************************************************
* SetDoubleClickTime16 (USER.20)
*/
void WINAPI SetDoubleClickTime16( UINT16 interval )
{
SetDoubleClickTime( interval );
}
/**********************************************************************
* SetDoubleClickTime32 (USER32.480)
*/
BOOL WINAPI SetDoubleClickTime( UINT interval )
{
doubleClickSpeed = interval ? interval : 500;
return TRUE;
}
/**********************************************************************
* GetDoubleClickTime16 (USER.21)
*/
UINT16 WINAPI GetDoubleClickTime16(void)
{
return doubleClickSpeed;
}
/**********************************************************************
* GetDoubleClickTime32 (USER32.239)
*/
UINT WINAPI GetDoubleClickTime(void)
{
return doubleClickSpeed;
}
/***********************************************************************
* MSG_SendMessageInterThread
*
* Implementation of an inter-task SendMessage.
* Return values:
* 0 if error or timeout
* 1 if successflul
*/
static LRESULT MSG_SendMessageInterThread( HQUEUE16 hDestQueue,
HWND hwnd, UINT msg,
WPARAM wParam, LPARAM lParam,
DWORD timeout, WORD flags,
LRESULT *pRes)
{
MESSAGEQUEUE *queue, *destQ;
SMSG *smsg;
LRESULT retVal = 1;
int iWndsLocks;
*pRes = 0;
if (IsTaskLocked16() || !IsWindow(hwnd))
return 0;
/* create a SMSG structure to hold SendMessage() parameters */
if (! (smsg = (SMSG *) HeapAlloc( SystemHeap, 0, sizeof(SMSG) )) )
return 0;
if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() ))) return 0;
if (!(destQ = (MESSAGEQUEUE*)QUEUE_Lock( hDestQueue )))
{
QUEUE_Unlock( queue );
return 0;
}
TRACE_(sendmsg)("SM: %s [%04x] (%04x -> %04x)\n",
SPY_GetMsgName(msg), msg, queue->self, hDestQueue );
/* fill up SMSG structure */
smsg->hWnd = hwnd;
smsg->msg = msg;
smsg->wParam = wParam;
smsg->lParam = lParam;
smsg->lResult = 0;
smsg->hSrcQueue = GetFastQueue16();
smsg->hDstQueue = hDestQueue;
smsg->flags = flags;
/* add smsg struct in the processing SM list of the source queue */
QUEUE_AddSMSG(queue, SM_PROCESSING_LIST, smsg);
/* add smsg struct in the pending list of the destination queue */
if (QUEUE_AddSMSG(destQ, SM_PENDING_LIST, smsg) == FALSE)
return 0;
iWndsLocks = WIN_SuspendWndsLock();
/* force destination task to run next, if 16 bit threads */
if ( THREAD_IsWin16(NtCurrentTeb()) && THREAD_IsWin16(destQ->teb) )
DirectedYield16( destQ->teb->htask16 );
/* wait for the result, note that 16-bit apps almost always get out of
* DirectedYield() with SMSG_HAVE_RESULT flag already set */
while ( TRUE )
{
/*
* The sequence is crucial to avoid deadlock situations:
* - first, we clear the QS_SMRESULT bit
* - then, we check the SMSG_HAVE_RESULT bit
* - only if this isn't set, we enter the wait state.
*
* As the receiver first sets the SMSG_HAVE_RESULT and then wakes us,
* we are guaranteed that -should we now clear the QS_SMRESULT that
* was signalled already by the receiver- we will not start waiting.
*/
if ( smsg->flags & SMSG_HAVE_RESULT )
{
got:
*pRes = smsg->lResult;
TRACE_(sendmsg)("smResult = %08x\n", (unsigned)*pRes );
break;
}
QUEUE_ClearWakeBit( queue, QS_SMRESULT );
if ( smsg->flags & SMSG_HAVE_RESULT )
goto got;
if( QUEUE_WaitBits( QS_SMRESULT, timeout ) == 0 )
{
/* return with timeout */
SetLastError( 0 );
retVal = 0;
break;
}
}
WIN_RestoreWndsLock(iWndsLocks);
/* remove the smsg from the processingg list of the source queue */
QUEUE_RemoveSMSG( queue, SM_PROCESSING_LIST, smsg );
/* Note: the destination thread is in charge of removing the smsg from
the pending list */
/* In the case of an early reply (or a timeout), sender thread will
released the smsg structure if the receiver thread is done
(SMSG_RECEIVED set). If the receiver thread isn't done,
SMSG_RECEIVER_CLEANS_UP flag is set, and it will be the receiver
responsability to released smsg */
EnterCriticalSection( &queue->cSection );
if (smsg->flags & SMSG_RECEIVED)
HeapFree(SystemHeap, 0, smsg);
else
smsg->flags |= SMSG_RECEIVER_CLEANS;
LeaveCriticalSection( &queue->cSection );
QUEUE_Unlock( queue );
QUEUE_Unlock( destQ );
TRACE_(sendmsg)("done!\n");
return retVal;
}
/***********************************************************************
* ReplyMessage16 (USER.115)
*/
void WINAPI ReplyMessage16( LRESULT result )
{
ReplyMessage( result );
}
/***********************************************************************
* ReplyMessage (USER.115)
*/
BOOL WINAPI ReplyMessage( LRESULT result )
{
MESSAGEQUEUE *senderQ = 0;
MESSAGEQUEUE *queue = 0;
SMSG *smsg;
BOOL ret = FALSE;
if (!(queue = (MESSAGEQUEUE*)QUEUE_Lock( GetFastQueue16() )))
return FALSE;
TRACE_(sendmsg)("ReplyMessage, queue %04x\n", queue->self);
if ( !(smsg = queue->smWaiting)
|| !(senderQ = QUEUE_Lock( smsg->hSrcQueue )) )
goto ReplyMessageEnd;
if ( !(smsg->flags & SMSG_ALREADY_REPLIED) )
{
/* This is the first reply, so pass result to sender */
TRACE_(sendmsg)("\trpm: smResult = %08lx\n", (long) result );
EnterCriticalSection(&senderQ->cSection);
smsg->lResult = result;
smsg->flags |= SMSG_ALREADY_REPLIED;
/* check if it's an early reply (called by the application) or
a regular reply (called by ReceiveMessage) */
if ( !(smsg->flags & SMSG_SENDING_REPLY) )
smsg->flags |= SMSG_EARLY_REPLY;
smsg->flags |= SMSG_HAVE_RESULT;
LeaveCriticalSection(&senderQ->cSection);
/* tell the sending task that its reply is ready */
QUEUE_SetWakeBit( senderQ, QS_SMRESULT );
/* switch directly to sending task (16 bit thread only) */
if ( THREAD_IsWin16( NtCurrentTeb() ) && THREAD_IsWin16( senderQ->teb ) )
DirectedYield16( senderQ->teb->htask16 );
ret = TRUE;
}
if (smsg->flags & SMSG_SENDING_REPLY)
{
/* remove msg from the waiting list, since this is the last
ReplyMessage */
QUEUE_RemoveSMSG( queue, SM_WAITING_LIST, smsg );
EnterCriticalSection(&senderQ->cSection);
/* tell the sender we're all done with smsg structure */
smsg->flags |= SMSG_RECEIVED;
/* sender will set SMSG_RECEIVER_CLEANS_UP if it wants the
receiver to clean up smsg, it could only happens when there is
an early reply or a timeout */
if ( smsg->flags & SMSG_RECEIVER_CLEANS )
{
TRACE_(sendmsg)("Receiver cleans up!\n" );
HeapFree( SystemHeap, 0, smsg );
}
LeaveCriticalSection(&senderQ->cSection);
}
ReplyMessageEnd:
if ( senderQ )
QUEUE_Unlock( senderQ );
if ( queue )
QUEUE_Unlock( queue );
return ret;
}
/***********************************************************************
* MSG_ConvertMsg
*/
static BOOL MSG_ConvertMsg( MSG *msg, int srcType, int dstType )
{
UINT16 msg16;
MSGPARAM16 mp16;
switch ( MAKELONG( srcType, dstType ) )
{
case MAKELONG( QMSG_WIN16, QMSG_WIN16 ):
case MAKELONG( QMSG_WIN32A, QMSG_WIN32A ):
case MAKELONG( QMSG_WIN32W, QMSG_WIN32W ):
return TRUE;
case MAKELONG( QMSG_WIN16, QMSG_WIN32A ):
switch ( WINPROC_MapMsg16To32A( msg->message, msg->wParam,
&msg->message, &msg->wParam, &msg->lParam ) )
{
case 0:
return TRUE;
case 1:
/* Pointer messages were mapped --> need to free allocated memory and fail */
WINPROC_UnmapMsg16To32A( msg->hwnd, msg->message, msg->wParam, msg->lParam, 0 );
default:
return FALSE;
}
case MAKELONG( QMSG_WIN16, QMSG_WIN32W ):
switch ( WINPROC_MapMsg16To32W( msg->hwnd, msg->message, msg->wParam,
&msg->message, &msg->wParam, &msg->lParam ) )
{
case 0:
return TRUE;
case 1:
/* Pointer messages were mapped --> need to free allocated memory and fail */
WINPROC_UnmapMsg16To32W( msg->hwnd, msg->message, msg->wParam, msg->lParam, 0 );
default:
return FALSE;
}
case MAKELONG( QMSG_WIN32A, QMSG_WIN16 ):
mp16.lParam = msg->lParam;
switch ( WINPROC_MapMsg32ATo16( msg->hwnd, msg->message, msg->wParam,
&msg16, &mp16.wParam, &mp16.lParam ) )
{
case 0:
msg->message = msg16;
msg->wParam = mp16.wParam;
msg->lParam = mp16.lParam;
return TRUE;
case 1:
/* Pointer messages were mapped --> need to free allocated memory and fail */
WINPROC_UnmapMsg32ATo16( msg->hwnd, msg->message, msg->wParam, msg->lParam, &mp16 );
default:
return FALSE;
}
case MAKELONG( QMSG_WIN32W, QMSG_WIN16 ):
mp16.lParam = msg->lParam;
switch ( WINPROC_MapMsg32WTo16( msg->hwnd, msg->message, msg->wParam,
&msg16, &mp16.wParam, &mp16.lParam ) )
{
case 0:
msg->message = msg16;
msg->wParam = mp16.wParam;
msg->lParam = mp16.lParam;
return TRUE;
case 1:
/* Pointer messages were mapped --> need to free allocated memory and fail */
WINPROC_UnmapMsg32WTo16( msg->hwnd, msg->message, msg->wParam, msg->lParam, &mp16 );
default:
return FALSE;
}
case MAKELONG( QMSG_WIN32A, QMSG_WIN32W ):
switch ( WINPROC_MapMsg32ATo32W( msg->hwnd, msg->message, msg->wParam, &msg->lParam ) )
{
case 0:
return TRUE;
case 1:
/* Pointer messages were mapped --> need to free allocated memory and fail */
WINPROC_UnmapMsg32ATo32W( msg->hwnd, msg->message, msg->wParam, msg->lParam );
default:
return FALSE;
}
case MAKELONG( QMSG_WIN32W, QMSG_WIN32A ):
switch ( WINPROC_MapMsg32WTo32A( msg->hwnd, msg->message, msg->wParam, &msg->lParam ) )
{
case 0:
return TRUE;
case 1:
/* Pointer messages were mapped --> need to free allocated memory and fail */
WINPROC_UnmapMsg32WTo32A( msg->hwnd, msg->message, msg->wParam, msg->lParam );
default:
return FALSE;
}
default:
FIXME( "Invalid message type(s): %d / %d\n", srcType, dstType );
return FALSE;
}
}
/***********************************************************************
* MSG_PeekMessage
*/
static BOOL MSG_PeekMessage( int type, LPMSG msg, HWND hwnd,
DWORD first, DWORD last, WORD flags, BOOL peek )
{
int mask;
MESSAGEQUEUE *msgQueue;
HQUEUE16 hQueue;
POINT16 pt16;
int iWndsLocks;
mask = QS_POSTMESSAGE | QS_SENDMESSAGE; /* Always selected */
if (first || last)
{
if ((first <= WM_KEYLAST) && (last >= WM_KEYFIRST)) mask |= QS_KEY;
if ( ((first <= WM_MOUSELAST) && (last >= WM_MOUSEFIRST)) ||
((first <= WM_NCMOUSELAST) && (last >= WM_NCMOUSEFIRST)) ) mask |= QS_MOUSE;
if ((first <= WM_TIMER) && (last >= WM_TIMER)) mask |= QS_TIMER;
if ((first <= WM_SYSTIMER) && (last >= WM_SYSTIMER)) mask |= QS_TIMER;
if ((first <= WM_PAINT) && (last >= WM_PAINT)) mask |= QS_PAINT;
}
else mask |= QS_MOUSE | QS_KEY | QS_TIMER | QS_PAINT;
if (IsTaskLocked16()) flags |= PM_NOYIELD;
/* Never yield on Win32 threads */
if (!THREAD_IsWin16(NtCurrentTeb())) flags |= PM_NOYIELD;
iWndsLocks = WIN_SuspendWndsLock();
while(1)
{
QMSG *qmsg;
hQueue = GetFastQueue16();
msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
if (!msgQueue)
{
WIN_RestoreWndsLock(iWndsLocks);
return FALSE;
}
msgQueue->changeBits = 0;
/* First handle a message put by SendMessage() */
while (msgQueue->wakeBits & QS_SENDMESSAGE)
QUEUE_ReceiveMessage( msgQueue );
/* Now handle a WM_QUIT message */
if (msgQueue->wPostQMsg &&
(!first || WM_QUIT >= first) &&
(!last || WM_QUIT <= last) )
{
msg->hwnd = hwnd;
msg->message = WM_QUIT;
msg->wParam = msgQueue->wExitCode;
msg->lParam = 0;
if (flags & PM_REMOVE) msgQueue->wPostQMsg = 0;
break;
}
/* Now find a normal message */
retry:
if (((msgQueue->wakeBits & mask) & QS_POSTMESSAGE) &&
((qmsg = QUEUE_FindMsg( msgQueue, hwnd, first, last )) != 0))
{
/* Try to convert message to requested type */
MSG tmpMsg = qmsg->msg;
if ( !MSG_ConvertMsg( &tmpMsg, qmsg->type, type ) )
{
ERR( "Message of wrong type contains pointer parameters. Skipped!\n ");
QUEUE_RemoveMsg( msgQueue, qmsg );
goto retry;
}
*msg = tmpMsg;
msgQueue->GetMessageTimeVal = msg->time;
CONV_POINT32TO16(&msg->pt, &pt16);
msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
msgQueue->GetMessageExtraInfoVal = qmsg->extraInfo;
if (flags & PM_REMOVE) QUEUE_RemoveMsg( msgQueue, qmsg );
break;
}
msgQueue->changeBits |= MSG_JournalPlayBackMsg();
/* Now find a hardware event */
if (((msgQueue->wakeBits & mask) & (QS_MOUSE | QS_KEY)) &&
MSG_PeekHardwareMsg( msg, hwnd, first, last, flags & PM_REMOVE ))
{
/* Got one */
msgQueue->GetMessageTimeVal = msg->time;
CONV_POINT32TO16(&msg->pt, &pt16);
msgQueue->GetMessagePosVal = *(DWORD *)&pt16;
msgQueue->GetMessageExtraInfoVal = 0; /* Always 0 for now */
break;
}
/* Check again for SendMessage */
while (msgQueue->wakeBits & QS_SENDMESSAGE)
QUEUE_ReceiveMessage( msgQueue );
/* Now find a WM_PAINT message */
if ((msgQueue->wakeBits & mask) & QS_PAINT)
{
WND* wndPtr;
msg->hwnd = WIN_FindWinToRepaint( hwnd , hQueue );
msg->message = WM_PAINT;
msg->wParam = 0;
msg->lParam = 0;
if ((wndPtr = WIN_FindWndPtr(msg->hwnd)))
{
if( wndPtr->dwStyle & WS_MINIMIZE &&
(HICON) GetClassLongA(wndPtr->hwndSelf, GCL_HICON) )
{
msg->message = WM_PAINTICON;
msg->wParam = 1;
}
if( !hwnd || msg->hwnd == hwnd || IsChild16(hwnd,msg->hwnd) )
{
if( wndPtr->flags & WIN_INTERNAL_PAINT && !wndPtr->hrgnUpdate)
{
wndPtr->flags &= ~WIN_INTERNAL_PAINT;
QUEUE_DecPaintCount( hQueue );
}
WIN_ReleaseWndPtr(wndPtr);
break;
}
WIN_ReleaseWndPtr(wndPtr);
}
}
/* Check for timer messages, but yield first */
if (!(flags & PM_NOYIELD))
{
UserYield16();
while (msgQueue->wakeBits & QS_SENDMESSAGE)
QUEUE_ReceiveMessage( msgQueue );
}
if ((msgQueue->wakeBits & mask) & QS_TIMER)
{
if (TIMER_GetTimerMsg(msg, hwnd, hQueue, flags & PM_REMOVE)) break;
}
if (peek)
{
if (!(flags & PM_NOYIELD)) UserYield16();
QUEUE_Unlock( msgQueue );
WIN_RestoreWndsLock(iWndsLocks);
return FALSE;
}
msgQueue->wakeMask = mask;
QUEUE_WaitBits( mask, INFINITE );
QUEUE_Unlock( msgQueue );
}
WIN_RestoreWndsLock(iWndsLocks);
/* instead of unlocking queue for every break condition, all break
condition will fall here */
QUEUE_Unlock( msgQueue );
/* We got a message */
if (flags & PM_REMOVE)
{
WORD message = msg->message;
if (message == WM_KEYDOWN || message == WM_SYSKEYDOWN)
{
BYTE *p = &QueueKeyStateTable[msg->wParam & 0xff];
if (!(*p & 0x80))
*p ^= 0x01;
*p |= 0x80;
}
else if (message == WM_KEYUP || message == WM_SYSKEYUP)
QueueKeyStateTable[msg->wParam & 0xff] &= ~0x80;
}
if (peek)
return TRUE;
else
return (msg->message != WM_QUIT);
}
/***********************************************************************
* MSG_InternalGetMessage
*
* GetMessage() function for internal use. Behave like GetMessage(),
* but also call message filters and optionally send WM_ENTERIDLE messages.
* 'hwnd' must be the handle of the dialog or menu window.
* 'code' is the message filter value (MSGF_??? codes).
*/
BOOL MSG_InternalGetMessage( int type, MSG *msg, HWND hwnd, HWND hwndOwner,
WPARAM code, WORD flags, BOOL sendIdle, BOOL* idleSent )
{
for (;;)
{
if (sendIdle)
{
if (!MSG_PeekMessage( type, msg, 0, 0, 0, flags, TRUE ))
{
/* No message present -> send ENTERIDLE and wait */
if (IsWindow(hwndOwner))
{
SendMessageA( hwndOwner, WM_ENTERIDLE,
code, (LPARAM)hwnd );
if (idleSent!=NULL)
*idleSent=TRUE;
}
MSG_PeekMessage( type, msg, 0, 0, 0, flags, FALSE );
}
}
else /* Always wait for a message */
MSG_PeekMessage( type, msg, 0, 0, 0, flags, FALSE );
/* Call message filters */
if (HOOK_IsHooked( WH_SYSMSGFILTER ) || HOOK_IsHooked( WH_MSGFILTER ))
{
MSG *pmsg = HeapAlloc( SystemHeap, 0, sizeof(MSG) );
if (pmsg)
{
BOOL ret;
*pmsg = *msg;
ret = (HOOK_CallHooksA( WH_SYSMSGFILTER, code, 0,
(LPARAM) pmsg ) ||
HOOK_CallHooksA( WH_MSGFILTER, code, 0,
(LPARAM) pmsg ));
HeapFree( SystemHeap, 0, pmsg );
if (ret)
{
/* Message filtered -> remove it from the queue */
/* if it's still there. */
if (!(flags & PM_REMOVE))
MSG_PeekMessage( type, msg, 0, 0, 0, PM_REMOVE, TRUE );
continue;
}
}
}
return (msg->message != WM_QUIT);
}
}
/***********************************************************************
* PeekMessage32_16 (USER.819)
*/
BOOL16 WINAPI PeekMessage32_16( LPMSG16_32 lpmsg16_32, HWND16 hwnd,
UINT16 first, UINT16 last, UINT16 flags,
BOOL16 wHaveParamHigh )
{
BOOL ret;
MSG msg;
ret = MSG_PeekMessage( QMSG_WIN16, &msg, hwnd, first, last, flags, TRUE );
lpmsg16_32->msg.hwnd = msg.hwnd;
lpmsg16_32->msg.message = msg.message;
lpmsg16_32->msg.wParam = LOWORD(msg.wParam);
lpmsg16_32->msg.lParam = msg.lParam;
lpmsg16_32->msg.time = msg.time;
lpmsg16_32->msg.pt.x = (INT16)msg.pt.x;
lpmsg16_32->msg.pt.y = (INT16)msg.pt.y;
if ( wHaveParamHigh )
lpmsg16_32->wParamHigh = HIWORD(msg.wParam);
return ret;
}
/***********************************************************************
* PeekMessage16 (USER.109)
*/
BOOL16 WINAPI PeekMessage16( LPMSG16 lpmsg, HWND16 hwnd,
UINT16 first, UINT16 last, UINT16 flags )
{
return PeekMessage32_16( (LPMSG16_32)lpmsg, hwnd, first, last, flags, FALSE );
}
/***********************************************************************
* PeekMessageA
*/
BOOL WINAPI PeekMessageA( LPMSG lpmsg, HWND hwnd,
UINT min, UINT max, UINT wRemoveMsg)
{
return MSG_PeekMessage( QMSG_WIN32A, lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
}
/***********************************************************************
* PeekMessageW Check queue for messages
*
* Checks for a message in the thread's queue, filtered as for
* GetMessage(). Returns immediately whether a message is available
* or not.
*
* Whether a retrieved message is removed from the queue is set by the
* _wRemoveMsg_ flags, which should be one of the following values:
*
* PM_NOREMOVE Do not remove the message from the queue.
*
* PM_REMOVE Remove the message from the queue.
*
* In addition, PM_NOYIELD may be combined into _wRemoveMsg_ to
* request that the system not yield control during PeekMessage();
* however applications may not rely on scheduling behavior.
*
* RETURNS
*
* Nonzero if a message is available and is retrieved, zero otherwise.
*
* CONFORMANCE
*
* ECMA-234, Win32
*
*/
BOOL WINAPI PeekMessageW(
LPMSG lpmsg, /* buffer to receive message */
HWND hwnd, /* restrict to messages for hwnd */
UINT min, /* minimum message to receive */
UINT max, /* maximum message to receive */
UINT wRemoveMsg /* removal flags */
)
{
return MSG_PeekMessage( QMSG_WIN32W, lpmsg, hwnd, min, max, wRemoveMsg, TRUE );
}
/***********************************************************************
* GetMessage32_16 (USER.820)
*/
BOOL16 WINAPI GetMessage32_16( SEGPTR msg16_32, HWND16 hWnd, UINT16 first,
UINT16 last, BOOL16 wHaveParamHigh )
{
MSG32_16 *lpmsg16_32 = (MSG32_16 *)PTR_SEG_TO_LIN(msg16_32);
MSG msg;
MSG_PeekMessage( QMSG_WIN16, &msg, hWnd, first, last, PM_REMOVE, FALSE );
lpmsg16_32->msg.hwnd = msg.hwnd;
lpmsg16_32->msg.message = msg.message;
lpmsg16_32->msg.wParam = LOWORD(msg.wParam);
lpmsg16_32->msg.lParam = msg.lParam;
lpmsg16_32->msg.time = msg.time;
lpmsg16_32->msg.pt.x = (INT16)msg.pt.x;
lpmsg16_32->msg.pt.y = (INT16)msg.pt.y;
if ( wHaveParamHigh )
lpmsg16_32->wParamHigh = HIWORD(msg.wParam);
TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
lpmsg16_32->msg.message, hWnd, first, last );
HOOK_CallHooks16( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)msg16_32 );
return lpmsg16_32->msg.message != WM_QUIT;
}
/***********************************************************************
* GetMessage16 (USER.108)
*/
BOOL16 WINAPI GetMessage16( SEGPTR msg, HWND16 hwnd, UINT16 first, UINT16 last)
{
return GetMessage32_16( msg, hwnd, first, last, FALSE );
}
/***********************************************************************
* GetMessageA (USER32.270)
*/
BOOL WINAPI GetMessageA( MSG *lpmsg, HWND hwnd, UINT min, UINT max )
{
MSG_PeekMessage( QMSG_WIN32A, lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
lpmsg->message, hwnd, min, max );
HOOK_CallHooksA( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)lpmsg );
return lpmsg->message != WM_QUIT;
}
/***********************************************************************
* GetMessage32W (USER32.274) Retrieve next message
*
* GetMessage retrieves the next event from the calling thread's
* queue and deposits it in *lpmsg.
*
* If _hwnd_ is not NULL, only messages for window _hwnd_ and its
* children as specified by IsChild() are retrieved. If _hwnd_ is NULL
* all application messages are retrieved.
*
* _min_ and _max_ specify the range of messages of interest. If
* min==max==0, no filtering is performed. Useful examples are
* WM_KEYFIRST and WM_KEYLAST to retrieve keyboard input, and
* WM_MOUSEFIRST and WM_MOUSELAST to retrieve mouse input.
*
* WM_PAINT messages are not removed from the queue; they remain until
* processed. Other messages are removed from the queue.
*
* RETURNS
*
* -1 on error, 0 if message is WM_QUIT, nonzero otherwise.
*
* CONFORMANCE
*
* ECMA-234, Win32
*
*/
BOOL WINAPI GetMessageW(
MSG* lpmsg, /* buffer to receive message */
HWND hwnd, /* restrict to messages for hwnd */
UINT min, /* minimum message to receive */
UINT max /* maximum message to receive */
)
{
MSG_PeekMessage( QMSG_WIN32W, lpmsg, hwnd, min, max, PM_REMOVE, FALSE );
TRACE( "message %04x, hwnd %04x, filter(%04x - %04x)\n",
lpmsg->message, hwnd, min, max );
HOOK_CallHooksW( WH_GETMESSAGE, HC_ACTION, 0, (LPARAM)lpmsg );
return lpmsg->message != WM_QUIT;
}
/***********************************************************************
* MSG_PostToQueue
*/
static BOOL MSG_PostToQueue( HQUEUE16 hQueue, int type, HWND hwnd,
UINT message, WPARAM wParam, LPARAM lParam )
{
MSG msg;
if ( !hQueue ) return FALSE;
msg.hwnd = hwnd;
msg.message = message;
msg.wParam = wParam;
msg.lParam = lParam;
msg.time = GetTickCount();
msg.pt.x = 0;
msg.pt.y = 0;
return QUEUE_AddMsg( hQueue, type, &msg, 0 );
}
/***********************************************************************
* MSG_PostMessage
*/
static BOOL MSG_PostMessage( int type, HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam )
{
HQUEUE16 hQueue;
WND *wndPtr;
if (hwnd == HWND_BROADCAST)
{
WND *pDesktop = WIN_GetDesktop();
TRACE("HWND_BROADCAST !\n");
for (wndPtr=WIN_LockWndPtr(pDesktop->child); wndPtr; WIN_UpdateWndPtr(&wndPtr,wndPtr->next))
{
if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
{
TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04X l=%08lX !\n",
wndPtr->hwndSelf, message, wParam, lParam);
MSG_PostToQueue( wndPtr->hmemTaskQ, type,
wndPtr->hwndSelf, message, wParam, lParam );
}
}
WIN_ReleaseDesktop();
TRACE("End of HWND_BROADCAST !\n");
return TRUE;
}
wndPtr = WIN_FindWndPtr( hwnd );
hQueue = wndPtr? wndPtr->hmemTaskQ : 0;
WIN_ReleaseWndPtr(wndPtr);
return MSG_PostToQueue( hQueue, type, hwnd, message, wParam, lParam );
}
/***********************************************************************
* PostMessage16 (USER.110)
*/
BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 message, WPARAM16 wParam,
LPARAM lParam )
{
return (BOOL16) MSG_PostMessage( QMSG_WIN16, hwnd, message, wParam, lParam );
}
/***********************************************************************
* PostMessageA (USER32.419)
*/
BOOL WINAPI PostMessageA( HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam )
{
return MSG_PostMessage( QMSG_WIN32A, hwnd, message, wParam, lParam );
}
/***********************************************************************
* PostMessageW (USER32.420)
*/
BOOL WINAPI PostMessageW( HWND hwnd, UINT message, WPARAM wParam,
LPARAM lParam )
{
return MSG_PostMessage( QMSG_WIN32W, hwnd, message, wParam, lParam );
}
/***********************************************************************
* PostAppMessage16 (USER.116)
*/
BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 message,
WPARAM16 wParam, LPARAM lParam )
{
return MSG_PostToQueue( GetTaskQueue16(hTask), QMSG_WIN16,
0, message, wParam, lParam );
}
/**********************************************************************
* PostThreadMessageA (USER32.422)
*/
BOOL WINAPI PostThreadMessageA( DWORD idThread, UINT message,
WPARAM wParam, LPARAM lParam )
{
return MSG_PostToQueue( GetThreadQueue16(idThread), QMSG_WIN32A,
0, message, wParam, lParam );
}
/**********************************************************************
* PostThreadMessageW (USER32.423)
*/
BOOL WINAPI PostThreadMessageW( DWORD idThread, UINT message,
WPARAM wParam, LPARAM lParam )
{
return MSG_PostToQueue( GetThreadQueue16(idThread), QMSG_WIN32W,
0, message, wParam, lParam );
}
/************************************************************************
* MSG_CallWndProcHook32
*/
static void MSG_CallWndProcHook( LPMSG pmsg, BOOL bUnicode )
{
CWPSTRUCT cwp;
cwp.lParam = pmsg->lParam;
cwp.wParam = pmsg->wParam;
cwp.message = pmsg->message;
cwp.hwnd = pmsg->hwnd;
if (bUnicode) HOOK_CallHooksW(WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp);
else HOOK_CallHooksA( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp );
pmsg->lParam = cwp.lParam;
pmsg->wParam = cwp.wParam;
pmsg->message = cwp.message;
pmsg->hwnd = cwp.hwnd;
}
/***********************************************************************
* MSG_SendMessage
*
* return values: 0 if timeout occurs
* 1 otherwise
*/
static LRESULT MSG_SendMessage( HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam, DWORD timeout, WORD flags,
LRESULT *pRes)
{
WND * wndPtr = 0;
WND **list, **ppWnd;
LRESULT ret = 1;
*pRes = 0;
if (hwnd == HWND_BROADCAST|| hwnd == HWND_TOPMOST)
{
*pRes = 1;
if (!(list = WIN_BuildWinArray( WIN_GetDesktop(), 0, NULL )))
{
WIN_ReleaseDesktop();
return 1;
}
WIN_ReleaseDesktop();
TRACE("HWND_BROADCAST !\n");
for (ppWnd = list; *ppWnd; ppWnd++)
{
WIN_UpdateWndPtr(&wndPtr,*ppWnd);
if (!IsWindow(wndPtr->hwndSelf)) continue;
if (wndPtr->dwStyle & WS_POPUP || wndPtr->dwStyle & WS_CAPTION)
{
TRACE("BROADCAST Message to hWnd=%04x m=%04X w=%04lX l=%08lX !\n",
wndPtr->hwndSelf, msg, (DWORD)wParam, lParam);
MSG_SendMessage( wndPtr->hwndSelf, msg, wParam, lParam,
timeout, flags, pRes);
}
}
WIN_ReleaseWndPtr(wndPtr);
WIN_ReleaseWinArray(list);
TRACE("End of HWND_BROADCAST !\n");
return 1;
}
if (HOOK_IsHooked( WH_CALLWNDPROC ))
{
if (flags & SMSG_UNICODE)
MSG_CallWndProcHook( (LPMSG)&hwnd, TRUE);
else if (flags & SMSG_WIN32)
MSG_CallWndProcHook( (LPMSG)&hwnd, FALSE);
else
{
LPCWPSTRUCT16 pmsg;
if ((pmsg = SEGPTR_NEW(CWPSTRUCT16)))
{
pmsg->hwnd = hwnd & 0xffff;
pmsg->message= msg & 0xffff;
pmsg->wParam = wParam & 0xffff;
pmsg->lParam = lParam;
HOOK_CallHooks16( WH_CALLWNDPROC, HC_ACTION, 1,
(LPARAM)SEGPTR_GET(pmsg) );
hwnd = pmsg->hwnd;
msg = pmsg->message;
wParam = pmsg->wParam;
lParam = pmsg->lParam;
SEGPTR_FREE( pmsg );
}
}
}
if (!(wndPtr = WIN_FindWndPtr( hwnd )))
{
WARN("invalid hwnd %04x\n", hwnd );
return 0;
}
if (QUEUE_IsExitingQueue(wndPtr->hmemTaskQ))
{
ret = 0; /* Don't send anything if the task is dying */
goto END;
}
if (flags & SMSG_WIN32)
SPY_EnterMessage( SPY_SENDMESSAGE, hwnd, msg, wParam, lParam );
else
SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wParam, lParam );
if (wndPtr->hmemTaskQ != GetFastQueue16())
ret = MSG_SendMessageInterThread( wndPtr->hmemTaskQ, hwnd, msg,
wParam, lParam, timeout, flags, pRes );
else
{
/* Call the right CallWindowProc flavor */
if (flags & SMSG_UNICODE)
*pRes = CallWindowProcW( (WNDPROC)wndPtr->winproc,
hwnd, msg, wParam, lParam );
else if (flags & SMSG_WIN32)
*pRes = CallWindowProcA( (WNDPROC)wndPtr->winproc,
hwnd, msg, wParam, lParam );
else
*pRes = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
(HWND16) hwnd, (UINT16) msg,
(WPARAM16) wParam, lParam );
}
if (flags & SMSG_WIN32)
SPY_ExitMessage( SPY_RESULT_OK, hwnd, msg, ret );
else
SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, ret );
END:
WIN_ReleaseWndPtr(wndPtr);
return ret;
}
/***********************************************************************
* SendMessage16 (USER.111)
*/
LRESULT WINAPI SendMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
LPARAM lParam)
{
LRESULT res;
MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE, 0, &res);
return res;
}
/***********************************************************************
* SendMessage32A (USER32.454)
*/
LRESULT WINAPI SendMessageA( HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam )
{
LRESULT res;
MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
SMSG_WIN32, &res);
return res;
}
/***********************************************************************
* SendMessage32W (USER32.459) Send Window Message
*
* Sends a message to the window procedure of the specified window.
* SendMessage() will not return until the called window procedure
* either returns or calls ReplyMessage().
*
* Use PostMessage() to send message and return immediately. A window
* procedure may use InSendMessage() to detect
* SendMessage()-originated messages.
*
* Applications which communicate via HWND_BROADCAST may use
* RegisterWindowMessage() to obtain a unique message to avoid conflicts
* with other applications.
*
* CONFORMANCE
*
* ECMA-234, Win32
*/
LRESULT WINAPI SendMessageW(
HWND hwnd, /* Window to send message to. If HWND_BROADCAST,
the message will be sent to all top-level windows. */
UINT msg, /* message */
WPARAM wParam, /* message parameter */
LPARAM lParam /* additional message parameter */
) {
LRESULT res;
MSG_SendMessage(hwnd, msg, wParam, lParam, INFINITE,
SMSG_WIN32 | SMSG_UNICODE, &res);
return res;
}
/***********************************************************************
* SendMessageTimeout16 (not a WINAPI)
*/
LRESULT WINAPI SendMessageTimeout16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam,
LPARAM lParam, UINT16 flags,
UINT16 timeout, LPWORD resultp)
{
LRESULT ret;
LRESULT msgRet;
/* FIXME: need support for SMTO_BLOCK */
ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, 0, &msgRet);
if (resultp) *resultp = (WORD) msgRet;
return ret;
}
/***********************************************************************
* SendMessageTimeoutA (USER32.457)
*/
LRESULT WINAPI SendMessageTimeoutA( HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam, UINT flags,
UINT timeout, LPDWORD resultp)
{
LRESULT ret;
LRESULT msgRet;
/* FIXME: need support for SMTO_BLOCK */
ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout, SMSG_WIN32,
&msgRet);
if (resultp) *resultp = (DWORD) msgRet;
return ret;
}
/***********************************************************************
* SendMessageTimeoutW (USER32.458)
*/
LRESULT WINAPI SendMessageTimeoutW( HWND hwnd, UINT msg, WPARAM wParam,
LPARAM lParam, UINT flags,
UINT timeout, LPDWORD resultp)
{
LRESULT ret;
LRESULT msgRet;
/* FIXME: need support for SMTO_BLOCK */
ret = MSG_SendMessage(hwnd, msg, wParam, lParam, timeout,
SMSG_WIN32 | SMSG_UNICODE, &msgRet);
if (resultp) *resultp = (DWORD) msgRet;
return ret;
}
/***********************************************************************
* WaitMessage (USER.112) (USER32.578) Suspend thread pending messages
*
* WaitMessage() suspends a thread until events appear in the thread's
* queue.
*
* BUGS
*
* Is supposed to return BOOL under Win32.
*
* Thread-local message queues are not supported.
*
* CONFORMANCE
*
* ECMA-234, Win32
*
*/
void WINAPI WaitMessage( void )
{
QUEUE_WaitBits( QS_ALLINPUT, INFINITE );
}
/***********************************************************************
* MsgWaitForMultipleObjects (USER32.400)
*/
DWORD WINAPI MsgWaitForMultipleObjects( DWORD nCount, HANDLE *pHandles,
BOOL fWaitAll, DWORD dwMilliseconds,
DWORD dwWakeMask )
{
DWORD i;
HANDLE handles[MAXIMUM_WAIT_OBJECTS];
DWORD ret;
PDB * pdb = PROCESS_Current();
HQUEUE16 hQueue = GetFastQueue16();
MESSAGEQUEUE *msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue );
if (!msgQueue) return WAIT_FAILED;
if (nCount > MAXIMUM_WAIT_OBJECTS-1)
{
SetLastError( ERROR_INVALID_PARAMETER );
QUEUE_Unlock( msgQueue );
return WAIT_FAILED;
}
msgQueue->changeBits = 0;
msgQueue->wakeMask = dwWakeMask;
if (THREAD_IsWin16(NtCurrentTeb()))
{
/*
* This is a temporary solution to a big problem.
* You see, the main thread of all Win32 programs is created as a 16 bit
* task. This means that if you want on an event using Win32 synchronization
* methods, the 16 bit scheduler is stopped and things might just stop happening.
* This implements a semi-busy loop that checks the handles to wait on and
* also the message queue. When either one is ready, the wait function returns.
*
* This will all go away when the real Win32 threads are implemented for all
* the threads of an applications. Including the main thread.
*/
DWORD curTime = GetCurrentTime();
do
{
/*
* Check the handles in the list.
*/
SetEvent ( pdb->idle_event );
ret = WaitForMultipleObjects(nCount, pHandles, fWaitAll, 5L);
/*
* If the handles have been triggered, return.
*/
if (ret != WAIT_TIMEOUT)
break;
/*
* Then, let the 16 bit scheduler do it's thing.
*/
Yield16();
/*
* If a message matching the wait mask has arrived, return.
*/
if (msgQueue->changeBits & dwWakeMask)
{
ret = nCount;
break;
}
/*
* And continue doing this until we hit the timeout.
*/
} while ((dwMilliseconds == INFINITE) || (GetCurrentTime()-curTime < dwMilliseconds) );
}
else
{
/* Add the thread event to the handle list */
for (i = 0; i < nCount; i++)
handles[i] = pHandles[i];
handles[nCount] = msgQueue->hEvent;
if ( pdb->main_queue == INVALID_HANDLE_VALUE16 ) pdb->main_queue = hQueue;
if ( pdb->main_queue == hQueue ) SetEvent ( pdb->idle_event );
ret = WaitForMultipleObjects( nCount+1, handles, fWaitAll, dwMilliseconds );
if ( pdb->main_queue == hQueue ) ResetEvent ( pdb->idle_event );
}
QUEUE_Unlock( msgQueue );
return ret;
}
struct accent_char
{
BYTE ac_accent;
BYTE ac_char;
BYTE ac_result;
};
static const struct accent_char accent_chars[] =
{
/* A good idea should be to read /usr/X11/lib/X11/locale/iso8859-x/Compose */
{'`', 'A', '\300'}, {'`', 'a', '\340'},
{'\'', 'A', '\301'}, {'\'', 'a', '\341'},
{'^', 'A', '\302'}, {'^', 'a', '\342'},
{'~', 'A', '\303'}, {'~', 'a', '\343'},
{'"', 'A', '\304'}, {'"', 'a', '\344'},
{'O', 'A', '\305'}, {'o', 'a', '\345'},
{'0', 'A', '\305'}, {'0', 'a', '\345'},
{'A', 'A', '\305'}, {'a', 'a', '\345'},
{'A', 'E', '\306'}, {'a', 'e', '\346'},
{',', 'C', '\307'}, {',', 'c', '\347'},
{'`', 'E', '\310'}, {'`', 'e', '\350'},
{'\'', 'E', '\311'}, {'\'', 'e', '\351'},
{'^', 'E', '\312'}, {'^', 'e', '\352'},
{'"', 'E', '\313'}, {'"', 'e', '\353'},
{'`', 'I', '\314'}, {'`', 'i', '\354'},
{'\'', 'I', '\315'}, {'\'', 'i', '\355'},
{'^', 'I', '\316'}, {'^', 'i', '\356'},
{'"', 'I', '\317'}, {'"', 'i', '\357'},
{'-', 'D', '\320'}, {'-', 'd', '\360'},
{'~', 'N', '\321'}, {'~', 'n', '\361'},
{'`', 'O', '\322'}, {'`', 'o', '\362'},
{'\'', 'O', '\323'}, {'\'', 'o', '\363'},
{'^', 'O', '\324'}, {'^', 'o', '\364'},
{'~', 'O', '\325'}, {'~', 'o', '\365'},
{'"', 'O', '\326'}, {'"', 'o', '\366'},
{'/', 'O', '\330'}, {'/', 'o', '\370'},
{'`', 'U', '\331'}, {'`', 'u', '\371'},
{'\'', 'U', '\332'}, {'\'', 'u', '\372'},
{'^', 'U', '\333'}, {'^', 'u', '\373'},
{'"', 'U', '\334'}, {'"', 'u', '\374'},
{'\'', 'Y', '\335'}, {'\'', 'y', '\375'},
{'T', 'H', '\336'}, {'t', 'h', '\376'},
{'s', 's', '\337'}, {'"', 'y', '\377'},
{'s', 'z', '\337'}, {'i', 'j', '\377'},
/* iso-8859-2 uses this */
{'<', 'L', '\245'}, {'<', 'l', '\265'}, /* caron */
{'<', 'S', '\251'}, {'<', 's', '\271'},
{'<', 'T', '\253'}, {'<', 't', '\273'},
{'<', 'Z', '\256'}, {'<', 'z', '\276'},
{'<', 'C', '\310'}, {'<', 'c', '\350'},
{'<', 'E', '\314'}, {'<', 'e', '\354'},
{'<', 'D', '\317'}, {'<', 'd', '\357'},
{'<', 'N', '\322'}, {'<', 'n', '\362'},
{'<', 'R', '\330'}, {'<', 'r', '\370'},
{';', 'A', '\241'}, {';', 'a', '\261'}, /* ogonek */
{';', 'E', '\312'}, {';', 'e', '\332'},
{'\'', 'Z', '\254'}, {'\'', 'z', '\274'}, /* acute */
{'\'', 'R', '\300'}, {'\'', 'r', '\340'},
{'\'', 'L', '\305'}, {'\'', 'l', '\345'},
{'\'', 'C', '\306'}, {'\'', 'c', '\346'},
{'\'', 'N', '\321'}, {'\'', 'n', '\361'},
/* collision whith S, from iso-8859-9 !!! */
{',', 'S', '\252'}, {',', 's', '\272'}, /* cedilla */
{',', 'T', '\336'}, {',', 't', '\376'},
{'.', 'Z', '\257'}, {'.', 'z', '\277'}, /* dot above */
{'/', 'L', '\243'}, {'/', 'l', '\263'}, /* slash */
{'/', 'D', '\320'}, {'/', 'd', '\360'},
{'(', 'A', '\303'}, {'(', 'a', '\343'}, /* breve */
{'\275', 'O', '\325'}, {'\275', 'o', '\365'}, /* double acute */
{'\275', 'U', '\334'}, {'\275', 'u', '\374'},
{'0', 'U', '\332'}, {'0', 'u', '\372'}, /* ring above */
/* iso-8859-3 uses this */
{'/', 'H', '\241'}, {'/', 'h', '\261'}, /* slash */
{'>', 'H', '\246'}, {'>', 'h', '\266'}, /* circumflex */
{'>', 'J', '\254'}, {'>', 'j', '\274'},
{'>', 'C', '\306'}, {'>', 'c', '\346'},
{'>', 'G', '\330'}, {'>', 'g', '\370'},
{'>', 'S', '\336'}, {'>', 's', '\376'},
/* collision whith G( from iso-8859-9 !!! */
{'(', 'G', '\253'}, {'(', 'g', '\273'}, /* breve */
{'(', 'U', '\335'}, {'(', 'u', '\375'},
/* collision whith I. from iso-8859-3 !!! */
{'.', 'I', '\251'}, {'.', 'i', '\271'}, /* dot above */
{'.', 'C', '\305'}, {'.', 'c', '\345'},
{'.', 'G', '\325'}, {'.', 'g', '\365'},
/* iso-8859-4 uses this */
{',', 'R', '\243'}, {',', 'r', '\263'}, /* cedilla */
{',', 'L', '\246'}, {',', 'l', '\266'},
{',', 'G', '\253'}, {',', 'g', '\273'},
{',', 'N', '\321'}, {',', 'n', '\361'},
{',', 'K', '\323'}, {',', 'k', '\363'},
{'~', 'I', '\245'}, {'~', 'i', '\265'}, /* tilde */
{'-', 'E', '\252'}, {'-', 'e', '\272'}, /* macron */
{'-', 'A', '\300'}, {'-', 'a', '\340'},
{'-', 'I', '\317'}, {'-', 'i', '\357'},
{'-', 'O', '\322'}, {'-', 'o', '\362'},
{'-', 'U', '\336'}, {'-', 'u', '\376'},
{'/', 'T', '\254'}, {'/', 't', '\274'}, /* slash */
{'.', 'E', '\314'}, {'.', 'e', '\344'}, /* dot above */
{';', 'I', '\307'}, {';', 'i', '\347'}, /* ogonek */
{';', 'U', '\331'}, {';', 'u', '\371'},
/* iso-8859-9 uses this */
/* iso-8859-9 has really bad choosen G( S, and I. as they collide
* whith the same letters on other iso-8859-x (that is they are on
* different places :-( ), if you use turkish uncomment these and
* comment out the lines in iso-8859-2 and iso-8859-3 sections
* FIXME: should be dynamic according to chosen language
* if/when Wine has turkish support.
*/
/* collision whith G( from iso-8859-3 !!! */
/* {'(', 'G', '\320'}, {'(', 'g', '\360'}, */ /* breve */
/* collision whith S, from iso-8859-2 !!! */
/* {',', 'S', '\336'}, {',', 's', '\376'}, */ /* cedilla */
/* collision whith I. from iso-8859-3 !!! */
/* {'.', 'I', '\335'}, {'.', 'i', '\375'}, */ /* dot above */
};
/***********************************************************************
* MSG_DoTranslateMessage
*
* Implementation of TranslateMessage.
*
* TranslateMessage translates virtual-key messages into character-messages,
* as follows :
* WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message.
* ditto replacing WM_* with WM_SYS*
* This produces WM_CHAR messages only for keys mapped to ASCII characters
* by the keyboard driver.
*/
static BOOL MSG_DoTranslateMessage( UINT message, HWND hwnd,
WPARAM wParam, LPARAM lParam )
{
static int dead_char;
BYTE wp[2];
if (message != WM_MOUSEMOVE && message != WM_TIMER)
TRACE("(%s, %04X, %08lX)\n",
SPY_GetMsgName(message), wParam, lParam );
if(message >= WM_KEYFIRST && message <= WM_KEYLAST)
TRACE_(key)("(%s, %04X, %08lX)\n",
SPY_GetMsgName(message), wParam, lParam );
if ((message != WM_KEYDOWN) && (message != WM_SYSKEYDOWN)) return FALSE;
TRACE_(key)("Translating key %04X, scancode %04X\n",
wParam, HIWORD(lParam) );
/* FIXME : should handle ToAscii yielding 2 */
switch (ToAscii(wParam, HIWORD(lParam),
QueueKeyStateTable,(LPWORD)wp, 0))
{
case 1 :
message = (message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR;
/* Should dead chars handling go in ToAscii ? */
if (dead_char)
{
int i;
if (wp[0] == ' ') wp[0] = dead_char;
if (dead_char == 0xa2) dead_char = '(';
else if (dead_char == 0xa8) dead_char = '"';
else if (dead_char == 0xb2) dead_char = ';';
else if (dead_char == 0xb4) dead_char = '\'';
else if (dead_char == 0xb7) dead_char = '<';
else if (dead_char == 0xb8) dead_char = ',';
else if (dead_char == 0xff) dead_char = '.';
for (i = 0; i < sizeof(accent_chars)/sizeof(accent_chars[0]); i++)
if ((accent_chars[i].ac_accent == dead_char) &&
(accent_chars[i].ac_char == wp[0]))
{
wp[0] = accent_chars[i].ac_result;
break;
}
dead_char = 0;
}
TRACE_(key)("1 -> PostMessage(%s)\n", SPY_GetMsgName(message));
PostMessage16( hwnd, message, wp[0], lParam );
return TRUE;
case -1 :
message = (message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR;
dead_char = wp[0];
TRACE_(key)("-1 -> PostMessage(%s)\n",
SPY_GetMsgName(message));
PostMessage16( hwnd, message, wp[0], lParam );
return TRUE;
}
return FALSE;
}
/***********************************************************************
* TranslateMessage16 (USER.113)
*/
BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
{
return MSG_DoTranslateMessage( msg->message, msg->hwnd,
msg->wParam, msg->lParam );
}
/***********************************************************************
* WIN16_TranslateMessage32 (USER.821)
*/
BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
{
WPARAM wParam;
if (wHaveParamHigh)
wParam = MAKELONG(msg->msg.wParam, msg->wParamHigh);
else
wParam = (WPARAM)msg->msg.wParam;
return MSG_DoTranslateMessage( msg->msg.message, msg->msg.hwnd,
wParam, msg->msg.lParam );
}
/***********************************************************************
* TranslateMessage32 (USER32.556)
*/
BOOL WINAPI TranslateMessage( const MSG *msg )
{
return MSG_DoTranslateMessage( msg->message, msg->hwnd,
msg->wParam, msg->lParam );
}
/***********************************************************************
* DispatchMessage16 (USER.114)
*/
LONG WINAPI DispatchMessage16( const MSG16* msg )
{
WND * wndPtr;
LONG retval;
int painting;
/* Process timer messages */
if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
{
if (msg->lParam)
{
return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
msg->message, msg->wParam, GetTickCount() );
}
}
if (!msg->hwnd) return 0;
if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
if (!wndPtr->winproc)
{
retval = 0;
goto END;
}
painting = (msg->message == WM_PAINT);
if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
SPY_EnterMessage( SPY_DISPATCHMESSAGE16, msg->hwnd, msg->message,
msg->wParam, msg->lParam );
retval = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
msg->hwnd, msg->message,
msg->wParam, msg->lParam );
SPY_ExitMessage( SPY_RESULT_OK16, msg->hwnd, msg->message, retval );
WIN_ReleaseWndPtr(wndPtr);
wndPtr = WIN_FindWndPtr(msg->hwnd);
if (painting && wndPtr &&
(wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
{
ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
msg->hwnd);
wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
/* Validate the update region to avoid infinite WM_PAINT loop */
ValidateRect( msg->hwnd, NULL );
}
END:
WIN_ReleaseWndPtr(wndPtr);
return retval;
}
/***********************************************************************
* WIN16_DispatchMessage32 (USER.822)
*/
LONG WINAPI DispatchMessage32_16( const MSG32_16* lpmsg16_32, BOOL16 wHaveParamHigh )
{
if (wHaveParamHigh == FALSE)
return DispatchMessage16(&(lpmsg16_32->msg));
else
{
MSG msg;
msg.hwnd = lpmsg16_32->msg.hwnd;
msg.message = lpmsg16_32->msg.message;
msg.wParam = MAKELONG(lpmsg16_32->msg.wParam, lpmsg16_32->wParamHigh);
msg.lParam = lpmsg16_32->msg.lParam;
msg.time = lpmsg16_32->msg.time;
msg.pt.x = (INT)lpmsg16_32->msg.pt.x;
msg.pt.y = (INT)lpmsg16_32->msg.pt.y;
return DispatchMessageA(&msg);
}
}
/***********************************************************************
* DispatchMessage32A (USER32.141)
*/
LONG WINAPI DispatchMessageA( const MSG* msg )
{
WND * wndPtr;
LONG retval;
int painting;
/* Process timer messages */
if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
{
if (msg->lParam)
{
/* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd,
msg->message, msg->wParam, GetTickCount() );
}
}
if (!msg->hwnd) return 0;
if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
if (!wndPtr->winproc)
{
retval = 0;
goto END;
}
painting = (msg->message == WM_PAINT);
if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
/* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
msg->wParam, msg->lParam );
retval = CallWindowProcA( (WNDPROC)wndPtr->winproc,
msg->hwnd, msg->message,
msg->wParam, msg->lParam );
SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
WIN_ReleaseWndPtr(wndPtr);
wndPtr = WIN_FindWndPtr(msg->hwnd);
if (painting && wndPtr &&
(wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
{
ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
msg->hwnd);
wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
/* Validate the update region to avoid infinite WM_PAINT loop */
ValidateRect( msg->hwnd, NULL );
}
END:
WIN_ReleaseWndPtr(wndPtr);
return retval;
}
/***********************************************************************
* DispatchMessage32W (USER32.142) Process Message
*
* Process the message specified in the structure *_msg_.
*
* If the lpMsg parameter points to a WM_TIMER message and the
* parameter of the WM_TIMER message is not NULL, the lParam parameter
* points to the function that is called instead of the window
* procedure.
*
* The message must be valid.
*
* RETURNS
*
* DispatchMessage() returns the result of the window procedure invoked.
*
* CONFORMANCE
*
* ECMA-234, Win32
*
*/
LONG WINAPI DispatchMessageW( const MSG* msg )
{
WND * wndPtr;
LONG retval;
int painting;
/* Process timer messages */
if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
{
if (msg->lParam)
{
/* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd,
msg->message, msg->wParam, GetTickCount() );
}
}
if (!msg->hwnd) return 0;
if (!(wndPtr = WIN_FindWndPtr( msg->hwnd ))) return 0;
if (!wndPtr->winproc)
{
retval = 0;
goto END;
}
painting = (msg->message == WM_PAINT);
if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT;
/* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */
SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message,
msg->wParam, msg->lParam );
retval = CallWindowProcW( (WNDPROC)wndPtr->winproc,
msg->hwnd, msg->message,
msg->wParam, msg->lParam );
SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval );
WIN_ReleaseWndPtr(wndPtr);
wndPtr = WIN_FindWndPtr(msg->hwnd);
if (painting && wndPtr &&
(wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate)
{
ERR("BeginPaint not called on WM_PAINT for hwnd %04x!\n",
msg->hwnd);
wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT;
/* Validate the update region to avoid infinite WM_PAINT loop */
ValidateRect( msg->hwnd, NULL );
}
END:
WIN_ReleaseWndPtr(wndPtr);
return retval;
}
/***********************************************************************
* RegisterWindowMessage16 (USER.118)
*/
WORD WINAPI RegisterWindowMessage16( SEGPTR str )
{
TRACE("%08lx\n", (DWORD)str );
return GlobalAddAtom16( str );
}
/***********************************************************************
* RegisterWindowMessage32A (USER32.437)
*/
WORD WINAPI RegisterWindowMessageA( LPCSTR str )
{
TRACE("%s\n", str );
return GlobalAddAtomA( str );
}
/***********************************************************************
* RegisterWindowMessage32W (USER32.438)
*/
WORD WINAPI RegisterWindowMessageW( LPCWSTR str )
{
TRACE("%p\n", str );
return GlobalAddAtomW( str );
}
/***********************************************************************
* GetTickCount (USER.13) (KERNEL32.299) System Time
* Returns the number of milliseconds, modulo 2^32, since the start
* of the current session.
*
* CONFORMANCE
*
* ECMA-234, Win32
*/
DWORD WINAPI GetTickCount(void)
{
struct timeval t;
gettimeofday( &t, NULL );
return ((t.tv_sec * 1000) + (t.tv_usec / 1000)) - MSG_WineStartTicks;
}
/***********************************************************************
* GetCurrentTime16 (USER.15)
*
* (effectively identical to GetTickCount)
*/
DWORD WINAPI GetCurrentTime16(void)
{
return GetTickCount();
}
/***********************************************************************
* InSendMessage16 (USER.192)
*/
BOOL16 WINAPI InSendMessage16(void)
{
return InSendMessage();
}
/***********************************************************************
* InSendMessage32 (USER32.320)
*/
BOOL WINAPI InSendMessage(void)
{
MESSAGEQUEUE *queue;
BOOL ret;
if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() )))
return 0;
ret = (BOOL)queue->smWaiting;
QUEUE_Unlock( queue );
return ret;
}
/***********************************************************************
* BroadcastSystemMessage (USER32.12)
*/
LONG WINAPI BroadcastSystemMessage(
DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam,
LPARAM lParam
) {
FIXME_(sendmsg)("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n",
dwFlags,*recipients,uMessage,wParam,lParam
);
return 0;
}
/***********************************************************************
* SendNotifyMessageA (USER32.460)
* FIXME
* The message sended with PostMessage has to be put in the queue
* with a higher priority as the other "Posted" messages.
* QUEUE_AddMsg has to be modifyed.
*/
BOOL WINAPI SendNotifyMessageA(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{ BOOL ret = TRUE;
FIXME("(%04x,%08x,%08x,%08lx) not complete\n",
hwnd, msg, wParam, lParam);
if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
{ ret=SendMessageA ( hwnd, msg, wParam, lParam );
}
else
{ PostMessageA ( hwnd, msg, wParam, lParam );
}
return ret;
}
/***********************************************************************
* SendNotifyMessageW (USER32.461)
* FIXME
* The message sended with PostMessage has to be put in the queue
* with a higher priority as the other "Posted" messages.
* QUEUE_AddMsg has to be modifyed.
*/
BOOL WINAPI SendNotifyMessageW(HWND hwnd,UINT msg,WPARAM wParam,LPARAM lParam)
{ BOOL ret = TRUE;
FIXME("(%04x,%08x,%08x,%08lx) not complete\n",
hwnd, msg, wParam, lParam);
if ( GetCurrentThreadId() == GetWindowThreadProcessId ( hwnd, NULL))
{ ret=SendMessageW ( hwnd, msg, wParam, lParam );
}
else
{ PostMessageW ( hwnd, msg, wParam, lParam );
}
return ret;
}
/***********************************************************************
* SendMessageCallback32A
* FIXME: It's like PostMessage. The callback gets called when the message
* is processed. We have to modify the message processing for a exact
* implementation...
*/
BOOL WINAPI SendMessageCallbackA(
HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
FARPROC lpResultCallBack,DWORD dwData)
{
FIXME("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
if ( hWnd == HWND_BROADCAST)
{ PostMessageA( hWnd, Msg, wParam, lParam);
FIXME("Broadcast: Callback will not be called!\n");
return TRUE;
}
(lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
return TRUE;
}
/***********************************************************************
* SendMessageCallback32W
* FIXME: It's like PostMessage. The callback gets called when the message
* is processed. We have to modify the message processing for a exact
* implementation...
*/
BOOL WINAPI SendMessageCallbackW(
HWND hWnd,UINT Msg,WPARAM wParam,LPARAM lParam,
FARPROC lpResultCallBack,DWORD dwData)
{
FIXME("(0x%04x,0x%04x,0x%08x,0x%08lx,%p,0x%08lx),stub!\n",
hWnd,Msg,wParam,lParam,lpResultCallBack,dwData);
if ( hWnd == HWND_BROADCAST)
{ PostMessageW( hWnd, Msg, wParam, lParam);
FIXME("Broadcast: Callback will not be called!\n");
return TRUE;
}
(lpResultCallBack)( hWnd, Msg, dwData, SendMessageA ( hWnd, Msg, wParam, lParam ));
return TRUE;
}
|