Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Message queues related functions |
| 3 | * |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 4 | * Copyright 1993, 1994 Alexandre Julliard |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Lesser General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2.1 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Lesser General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Lesser General Public |
| 17 | * License along with this library; if not, write to the Free Software |
| 18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
Patrik Stridvall | d016f81 | 2002-08-17 00:43:16 +0000 | [diff] [blame] | 21 | #include "config.h" |
| 22 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 23 | #include <stdarg.h> |
Alexandre Julliard | 401710d | 1993-09-04 10:09:32 +0000 | [diff] [blame] | 24 | #include <stdlib.h> |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 25 | #include <string.h> |
Alexandre Julliard | d1ce8b2 | 1996-09-02 16:46:30 +0000 | [diff] [blame] | 26 | #include <ctype.h> |
Patrik Stridvall | d016f81 | 2002-08-17 00:43:16 +0000 | [diff] [blame] | 27 | #ifdef HAVE_SYS_TIME_H |
| 28 | # include <sys/time.h> |
| 29 | #endif |
Alexandre Julliard | 5f721f8 | 1994-01-04 20:14:34 +0000 | [diff] [blame] | 30 | #include <sys/types.h> |
Alexandre Julliard | f41aeca | 1993-09-14 16:47:10 +0000 | [diff] [blame] | 31 | |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 32 | #include "windef.h" |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 33 | #include "winbase.h" |
| 34 | #include "wingdi.h" |
| 35 | #include "winuser.h" |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 36 | #include "message.h" |
Alexandre Julliard | dbf2bf0 | 1999-01-01 17:05:53 +0000 | [diff] [blame] | 37 | #include "winerror.h" |
Alexandre Julliard | e37c6e1 | 2003-09-05 23:08:26 +0000 | [diff] [blame] | 38 | #include "ntstatus.h" |
Alexandre Julliard | 37e9503 | 2001-07-19 00:39:09 +0000 | [diff] [blame] | 39 | #include "wine/server.h" |
Alexandre Julliard | 91222da | 2000-12-10 23:01:33 +0000 | [diff] [blame] | 40 | #include "controls.h" |
Alexandre Julliard | 18d0297 | 2002-12-03 23:34:52 +0000 | [diff] [blame] | 41 | #include "dde.h" |
Alexandre Julliard | 18d0297 | 2002-12-03 23:34:52 +0000 | [diff] [blame] | 42 | #include "message.h" |
Alexandre Julliard | 18d0297 | 2002-12-03 23:34:52 +0000 | [diff] [blame] | 43 | #include "user.h" |
| 44 | #include "win.h" |
| 45 | #include "winpos.h" |
| 46 | #include "winproc.h" |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 47 | #include "wine/debug.h" |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 48 | |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 49 | WINE_DEFAULT_DEBUG_CHANNEL(msg); |
| 50 | WINE_DECLARE_DEBUG_CHANNEL(key); |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 51 | |
Alexandre Julliard | ac9c9b0 | 1996-07-28 18:50:11 +0000 | [diff] [blame] | 52 | #define WM_NCMOUSEFIRST WM_NCMOUSEMOVE |
| 53 | #define WM_NCMOUSELAST WM_NCMBUTTONDBLCLK |
| 54 | |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 55 | |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 56 | /*********************************************************************** |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 57 | * is_keyboard_message |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 58 | */ |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 59 | inline static BOOL is_keyboard_message( UINT message ) |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 60 | { |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 61 | return (message >= WM_KEYFIRST && message <= WM_KEYLAST); |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 62 | } |
| 63 | |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 64 | |
| 65 | /*********************************************************************** |
| 66 | * is_mouse_message |
| 67 | */ |
| 68 | inline static BOOL is_mouse_message( UINT message ) |
| 69 | { |
| 70 | return ((message >= WM_NCMOUSEFIRST && message <= WM_NCMOUSELAST) || |
| 71 | (message >= WM_MOUSEFIRST && message <= WM_MOUSELAST)); |
| 72 | } |
| 73 | |
| 74 | |
| 75 | /*********************************************************************** |
| 76 | * check_message_filter |
| 77 | */ |
| 78 | inline static BOOL check_message_filter( const MSG *msg, HWND hwnd, UINT first, UINT last ) |
| 79 | { |
| 80 | if (hwnd) |
| 81 | { |
| 82 | if (msg->hwnd != hwnd && !IsChild( hwnd, msg->hwnd )) return FALSE; |
| 83 | } |
| 84 | if (first || last) |
| 85 | { |
| 86 | return (msg->message >= first && msg->message <= last); |
| 87 | } |
| 88 | return TRUE; |
| 89 | } |
| 90 | |
| 91 | |
| 92 | /*********************************************************************** |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 93 | * process_sent_messages |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 94 | * |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 95 | * Process all pending sent messages. |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 96 | */ |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 97 | inline static void process_sent_messages(void) |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 98 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 99 | MSG msg; |
| 100 | MSG_peek_message( &msg, 0, 0, 0, GET_MSG_REMOVE | GET_MSG_SENT_ONLY ); |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | |
| 104 | /*********************************************************************** |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 105 | * queue_hardware_message |
| 106 | * |
| 107 | * store a hardware message in the thread queue |
| 108 | */ |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 109 | #if 0 |
| 110 | static void queue_hardware_message( MSG *msg, ULONG_PTR extra_info ) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 111 | { |
| 112 | SERVER_START_REQ( send_message ) |
| 113 | { |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 114 | req->type = MSG_HARDWARE; |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 115 | req->id = GetWindowThreadProcessId( msg->hwnd, NULL ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 116 | req->win = msg->hwnd; |
| 117 | req->msg = msg->message; |
| 118 | req->wparam = msg->wParam; |
| 119 | req->lparam = msg->lParam; |
| 120 | req->x = msg->pt.x; |
| 121 | req->y = msg->pt.y; |
| 122 | req->time = msg->time; |
| 123 | req->info = extra_info; |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 124 | req->timeout = 0; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 125 | wine_server_call( req ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 126 | } |
| 127 | SERVER_END_REQ; |
| 128 | } |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 129 | #endif |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 130 | |
| 131 | |
Alexandre Julliard | 9ea19e5 | 1997-01-01 17:29:55 +0000 | [diff] [blame] | 132 | /*********************************************************************** |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 133 | * MSG_SendParentNotify |
| 134 | * |
| 135 | * Send a WM_PARENTNOTIFY to all ancestors of the given window, unless |
| 136 | * the window has the WS_EX_NOPARENTNOTIFY style. |
| 137 | */ |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 138 | static void MSG_SendParentNotify( HWND hwnd, WORD event, WORD idChild, POINT pt ) |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 139 | { |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 140 | /* pt has to be in the client coordinates of the parent window */ |
Alexandre Julliard | 4ff32c8 | 2001-08-18 18:08:26 +0000 | [diff] [blame] | 141 | MapWindowPoints( 0, hwnd, &pt, 1 ); |
| 142 | for (;;) |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 143 | { |
Alexandre Julliard | 4ff32c8 | 2001-08-18 18:08:26 +0000 | [diff] [blame] | 144 | HWND parent; |
| 145 | |
| 146 | if (!(GetWindowLongA( hwnd, GWL_STYLE ) & WS_CHILD)) break; |
| 147 | if (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY) break; |
| 148 | if (!(parent = GetParent(hwnd))) break; |
| 149 | MapWindowPoints( hwnd, parent, &pt, 1 ); |
| 150 | hwnd = parent; |
| 151 | SendMessageA( hwnd, WM_PARENTNOTIFY, |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 152 | MAKEWPARAM( event, idChild ), MAKELPARAM( pt.x, pt.y ) ); |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 153 | } |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 157 | #if 0 /* this is broken for now, will require proper support in the server */ |
| 158 | |
Alexandre Julliard | 77b9918 | 1997-09-14 17:17:23 +0000 | [diff] [blame] | 159 | /*********************************************************************** |
Alexandre Julliard | d1ce8b2 | 1996-09-02 16:46:30 +0000 | [diff] [blame] | 160 | * MSG_JournalPlayBackMsg |
| 161 | * |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 162 | * Get an EVENTMSG struct via call JOURNALPLAYBACK hook function |
Alexandre Julliard | d1ce8b2 | 1996-09-02 16:46:30 +0000 | [diff] [blame] | 163 | */ |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 164 | void MSG_JournalPlayBackMsg(void) |
Alexandre Julliard | d1ce8b2 | 1996-09-02 16:46:30 +0000 | [diff] [blame] | 165 | { |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 166 | EVENTMSG tmpMsg; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 167 | MSG msg; |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 168 | LRESULT wtime; |
| 169 | int keyDown,i; |
Alexandre Julliard | d1ce8b2 | 1996-09-02 16:46:30 +0000 | [diff] [blame] | 170 | |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 171 | wtime=HOOK_CallHooks( WH_JOURNALPLAYBACK, HC_GETNEXT, 0, (LPARAM)&tmpMsg, TRUE ); |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 172 | /* TRACE(msg,"Playback wait time =%ld\n",wtime); */ |
| 173 | if (wtime<=0) |
Alexandre Julliard | d1ce8b2 | 1996-09-02 16:46:30 +0000 | [diff] [blame] | 174 | { |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 175 | wtime=0; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 176 | msg.message = tmpMsg.message; |
| 177 | msg.hwnd = tmpMsg.hwnd; |
| 178 | msg.time = tmpMsg.time; |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 179 | if ((tmpMsg.message >= WM_KEYFIRST) && (tmpMsg.message <= WM_KEYLAST)) |
| 180 | { |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 181 | msg.wParam = tmpMsg.paramL & 0xFF; |
| 182 | msg.lParam = MAKELONG(tmpMsg.paramH&0x7ffff,tmpMsg.paramL>>8); |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 183 | if (tmpMsg.message == WM_KEYDOWN || tmpMsg.message == WM_SYSKEYDOWN) |
| 184 | { |
| 185 | for (keyDown=i=0; i<256 && !keyDown; i++) |
| 186 | if (InputKeyStateTable[i] & 0x80) |
| 187 | keyDown++; |
| 188 | if (!keyDown) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 189 | msg.lParam |= 0x40000000; |
Alexandre Julliard | a21672e | 2001-10-02 18:53:59 +0000 | [diff] [blame] | 190 | InputKeyStateTable[msg.wParam] |= 0x80; |
| 191 | AsyncKeyStateTable[msg.wParam] |= 0x80; |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 192 | } |
| 193 | else /* WM_KEYUP, WM_SYSKEYUP */ |
| 194 | { |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 195 | msg.lParam |= 0xC0000000; |
Alexandre Julliard | a21672e | 2001-10-02 18:53:59 +0000 | [diff] [blame] | 196 | InputKeyStateTable[msg.wParam] &= ~0x80; |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 197 | } |
| 198 | if (InputKeyStateTable[VK_MENU] & 0x80) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 199 | msg.lParam |= 0x20000000; |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 200 | if (tmpMsg.paramH & 0x8000) /*special_key bit*/ |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 201 | msg.lParam |= 0x01000000; |
| 202 | |
| 203 | msg.pt.x = msg.pt.y = 0; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 204 | queue_hardware_message( &msg, 0 ); |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 205 | } |
| 206 | else if ((tmpMsg.message>= WM_MOUSEFIRST) && (tmpMsg.message <= WM_MOUSELAST)) |
| 207 | { |
| 208 | switch (tmpMsg.message) |
| 209 | { |
| 210 | case WM_LBUTTONDOWN: |
Alexandre Julliard | a21672e | 2001-10-02 18:53:59 +0000 | [diff] [blame] | 211 | InputKeyStateTable[VK_LBUTTON] |= 0x80; |
| 212 | AsyncKeyStateTable[VK_LBUTTON] |= 0x80; |
| 213 | break; |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 214 | case WM_LBUTTONUP: |
Alexandre Julliard | a21672e | 2001-10-02 18:53:59 +0000 | [diff] [blame] | 215 | InputKeyStateTable[VK_LBUTTON] &= ~0x80; |
| 216 | break; |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 217 | case WM_MBUTTONDOWN: |
Alexandre Julliard | a21672e | 2001-10-02 18:53:59 +0000 | [diff] [blame] | 218 | InputKeyStateTable[VK_MBUTTON] |= 0x80; |
| 219 | AsyncKeyStateTable[VK_MBUTTON] |= 0x80; |
| 220 | break; |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 221 | case WM_MBUTTONUP: |
Alexandre Julliard | a21672e | 2001-10-02 18:53:59 +0000 | [diff] [blame] | 222 | InputKeyStateTable[VK_MBUTTON] &= ~0x80; |
| 223 | break; |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 224 | case WM_RBUTTONDOWN: |
Alexandre Julliard | a21672e | 2001-10-02 18:53:59 +0000 | [diff] [blame] | 225 | InputKeyStateTable[VK_RBUTTON] |= 0x80; |
| 226 | AsyncKeyStateTable[VK_RBUTTON] |= 0x80; |
| 227 | break; |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 228 | case WM_RBUTTONUP: |
Alexandre Julliard | a21672e | 2001-10-02 18:53:59 +0000 | [diff] [blame] | 229 | InputKeyStateTable[VK_RBUTTON] &= ~0x80; |
| 230 | break; |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 231 | } |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 232 | SetCursorPos(tmpMsg.paramL,tmpMsg.paramH); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 233 | msg.lParam=MAKELONG(tmpMsg.paramL,tmpMsg.paramH); |
| 234 | msg.wParam=0; |
Alexandre Julliard | a21672e | 2001-10-02 18:53:59 +0000 | [diff] [blame] | 235 | if (InputKeyStateTable[VK_LBUTTON] & 0x80) msg.wParam |= MK_LBUTTON; |
| 236 | if (InputKeyStateTable[VK_MBUTTON] & 0x80) msg.wParam |= MK_MBUTTON; |
| 237 | if (InputKeyStateTable[VK_RBUTTON] & 0x80) msg.wParam |= MK_RBUTTON; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 238 | |
| 239 | msg.pt.x = tmpMsg.paramL; |
| 240 | msg.pt.y = tmpMsg.paramH; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 241 | queue_hardware_message( &msg, 0 ); |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 242 | } |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 243 | HOOK_CallHooks( WH_JOURNALPLAYBACK, HC_SKIP, 0, (LPARAM)&tmpMsg, TRUE ); |
Alexandre Julliard | d1ce8b2 | 1996-09-02 16:46:30 +0000 | [diff] [blame] | 244 | } |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 245 | else |
| 246 | { |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 247 | if( tmpMsg.message == WM_QUEUESYNC ) HOOK_CallHooks( WH_CBT, HCBT_QS, 0, 0, TRUE ); |
Alexandre Julliard | da2892c | 2001-02-23 01:13:42 +0000 | [diff] [blame] | 248 | } |
| 249 | } |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 250 | #endif |
Alexandre Julliard | 940d58c | 1994-09-16 09:24:37 +0000 | [diff] [blame] | 251 | |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 252 | |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 253 | /*********************************************************************** |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 254 | * process_raw_keyboard_message |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 255 | * |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 256 | * returns TRUE if the contents of 'msg' should be passed to the application |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 257 | */ |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 258 | static void process_raw_keyboard_message( MSG *msg ) |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 259 | { |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 260 | EVENTMSG event; |
| 261 | |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 262 | event.message = msg->message; |
| 263 | event.hwnd = msg->hwnd; |
| 264 | event.time = msg->time; |
| 265 | event.paramL = (msg->wParam & 0xFF) | (HIWORD(msg->lParam) << 8); |
| 266 | event.paramH = msg->lParam & 0x7FFF; |
| 267 | if (HIWORD(msg->lParam) & 0x0100) event.paramH |= 0x8000; /* special_key - bit */ |
| 268 | HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | |
| 272 | /*********************************************************************** |
| 273 | * process_cooked_keyboard_message |
| 274 | * |
| 275 | * returns TRUE if the contents of 'msg' should be passed to the application |
| 276 | */ |
| 277 | static BOOL process_cooked_keyboard_message( MSG *msg, BOOL remove ) |
| 278 | { |
| 279 | if (remove) |
| 280 | { |
| 281 | /* Handle F1 key by sending out WM_HELP message */ |
| 282 | if ((msg->message == WM_KEYUP) && |
| 283 | (msg->wParam == VK_F1) && |
| 284 | (msg->hwnd != GetDesktopWindow()) && |
| 285 | !MENU_IsMenuActive()) |
| 286 | { |
| 287 | HELPINFO hi; |
| 288 | hi.cbSize = sizeof(HELPINFO); |
| 289 | hi.iContextType = HELPINFO_WINDOW; |
| 290 | hi.iCtrlId = GetWindowLongA( msg->hwnd, GWL_ID ); |
| 291 | hi.hItemHandle = msg->hwnd; |
| 292 | hi.dwContextId = GetWindowContextHelpId( msg->hwnd ); |
| 293 | hi.MousePos = msg->pt; |
| 294 | SendMessageA(msg->hwnd, WM_HELP, 0, (LPARAM)&hi); |
| 295 | } |
| 296 | } |
| 297 | |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 298 | if (HOOK_CallHooks( WH_KEYBOARD, remove ? HC_ACTION : HC_NOREMOVE, |
| 299 | LOWORD(msg->wParam), msg->lParam, TRUE )) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 300 | { |
| 301 | /* skip this message */ |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 302 | HOOK_CallHooks( WH_CBT, HCBT_KEYSKIPPED, LOWORD(msg->wParam), msg->lParam, TRUE ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 303 | return FALSE; |
| 304 | } |
| 305 | return TRUE; |
| 306 | } |
| 307 | |
| 308 | |
| 309 | /*********************************************************************** |
| 310 | * process_raw_mouse_message |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 311 | */ |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 312 | static void process_raw_mouse_message( MSG *msg, BOOL remove ) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 313 | { |
| 314 | static MSG clk_msg; |
| 315 | |
| 316 | POINT pt; |
Alexandre Julliard | a9e8f59 | 2002-10-12 01:24:37 +0000 | [diff] [blame] | 317 | INT hittest; |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 318 | EVENTMSG event; |
Alexandre Julliard | a9e8f59 | 2002-10-12 01:24:37 +0000 | [diff] [blame] | 319 | GUITHREADINFO info; |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 320 | HWND hWndScope = msg->hwnd; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 321 | |
| 322 | /* find the window to dispatch this mouse message to */ |
| 323 | |
Alexandre Julliard | ee8ab7a | 2001-06-20 23:16:34 +0000 | [diff] [blame] | 324 | hittest = HTCLIENT; |
Alexandre Julliard | a9e8f59 | 2002-10-12 01:24:37 +0000 | [diff] [blame] | 325 | GetGUIThreadInfo( GetCurrentThreadId(), &info ); |
| 326 | if (!(msg->hwnd = info.hwndCapture)) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 327 | { |
| 328 | /* If no capture HWND, find window which contains the mouse position. |
| 329 | * Also find the position of the cursor hot spot (hittest) */ |
Alexandre Julliard | ee8ab7a | 2001-06-20 23:16:34 +0000 | [diff] [blame] | 330 | if (!IsWindow(hWndScope)) hWndScope = 0; |
| 331 | if (!(msg->hwnd = WINPOS_WindowFromPoint( hWndScope, msg->pt, &hittest ))) |
| 332 | msg->hwnd = GetDesktopWindow(); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 333 | } |
| 334 | |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 335 | event.message = msg->message; |
| 336 | event.time = msg->time; |
| 337 | event.hwnd = msg->hwnd; |
| 338 | event.paramL = msg->pt.x; |
| 339 | event.paramH = msg->pt.y; |
| 340 | HOOK_CallHooks( WH_JOURNALRECORD, HC_ACTION, 0, (LPARAM)&event, TRUE ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 341 | |
| 342 | /* translate double clicks */ |
| 343 | |
| 344 | if ((msg->message == WM_LBUTTONDOWN) || |
| 345 | (msg->message == WM_RBUTTONDOWN) || |
| 346 | (msg->message == WM_MBUTTONDOWN)) |
| 347 | { |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 348 | BOOL update = remove; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 349 | /* translate double clicks - |
| 350 | * note that ...MOUSEMOVEs can slip in between |
| 351 | * ...BUTTONDOWN and ...BUTTONDBLCLK messages */ |
| 352 | |
Alexandre Julliard | a9e8f59 | 2002-10-12 01:24:37 +0000 | [diff] [blame] | 353 | if ((info.flags & (GUI_INMENUMODE|GUI_INMOVESIZE)) || |
| 354 | hittest != HTCLIENT || |
| 355 | (GetClassLongA( msg->hwnd, GCL_STYLE ) & CS_DBLCLKS)) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 356 | { |
| 357 | if ((msg->message == clk_msg.message) && |
| 358 | (msg->hwnd == clk_msg.hwnd) && |
Andriy Palamarchuk | 2489dc9 | 2001-12-06 22:28:43 +0000 | [diff] [blame] | 359 | (msg->time - clk_msg.time < GetDoubleClickTime()) && |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 360 | (abs(msg->pt.x - clk_msg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK)/2) && |
| 361 | (abs(msg->pt.y - clk_msg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK)/2)) |
| 362 | { |
| 363 | msg->message += (WM_LBUTTONDBLCLK - WM_LBUTTONDOWN); |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 364 | if (remove) |
| 365 | { |
| 366 | clk_msg.message = 0; |
| 367 | update = FALSE; |
| 368 | } |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 369 | } |
| 370 | } |
| 371 | /* update static double click conditions */ |
| 372 | if (update) clk_msg = *msg; |
| 373 | } |
| 374 | |
| 375 | pt = msg->pt; |
Travis Michielsen | b9bd3f8 | 2001-06-29 01:17:55 +0000 | [diff] [blame] | 376 | /* Note: windows has no concept of a non-client wheel message */ |
| 377 | if (hittest != HTCLIENT && msg->message != WM_MOUSEWHEEL) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 378 | { |
| 379 | msg->message += WM_NCMOUSEMOVE - WM_MOUSEMOVE; |
| 380 | msg->wParam = hittest; |
| 381 | } |
Alexandre Julliard | a9e8f59 | 2002-10-12 01:24:37 +0000 | [diff] [blame] | 382 | else |
| 383 | { |
| 384 | /* coordinates don't get translated while tracking a menu */ |
| 385 | /* FIXME: should differentiate popups and top-level menus */ |
| 386 | if (!(info.flags & GUI_INMENUMODE)) ScreenToClient( msg->hwnd, &pt ); |
| 387 | } |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 388 | msg->lParam = MAKELONG( pt.x, pt.y ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | |
| 392 | /*********************************************************************** |
| 393 | * process_cooked_mouse_message |
| 394 | * |
| 395 | * returns TRUE if the contents of 'msg' should be passed to the application |
| 396 | */ |
Alexandre Julliard | 516e40e | 2001-10-17 17:48:49 +0000 | [diff] [blame] | 397 | static BOOL process_cooked_mouse_message( MSG *msg, ULONG_PTR extra_info, BOOL remove ) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 398 | { |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 399 | MOUSEHOOKSTRUCT hook; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 400 | INT hittest = HTCLIENT; |
| 401 | UINT raw_message = msg->message; |
| 402 | BOOL eatMsg; |
| 403 | |
| 404 | if (msg->message >= WM_NCMOUSEFIRST && msg->message <= WM_NCMOUSELAST) |
| 405 | { |
| 406 | raw_message += WM_MOUSEFIRST - WM_NCMOUSEFIRST; |
| 407 | hittest = msg->wParam; |
| 408 | } |
| 409 | if (raw_message == WM_LBUTTONDBLCLK || |
| 410 | raw_message == WM_RBUTTONDBLCLK || |
| 411 | raw_message == WM_MBUTTONDBLCLK) |
| 412 | { |
| 413 | raw_message += WM_LBUTTONDOWN - WM_LBUTTONDBLCLK; |
| 414 | } |
| 415 | |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 416 | hook.pt = msg->pt; |
| 417 | hook.hwnd = msg->hwnd; |
| 418 | hook.wHitTestCode = hittest; |
| 419 | hook.dwExtraInfo = extra_info; |
| 420 | if (HOOK_CallHooks( WH_MOUSE, remove ? HC_ACTION : HC_NOREMOVE, |
| 421 | msg->message, (LPARAM)&hook, TRUE )) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 422 | { |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 423 | hook.pt = msg->pt; |
| 424 | hook.hwnd = msg->hwnd; |
| 425 | hook.wHitTestCode = hittest; |
Alexandre Julliard | 516e40e | 2001-10-17 17:48:49 +0000 | [diff] [blame] | 426 | hook.dwExtraInfo = extra_info; |
Alexandre Julliard | 0286135 | 2002-10-29 00:41:42 +0000 | [diff] [blame] | 427 | HOOK_CallHooks( WH_CBT, HCBT_CLICKSKIPPED, msg->message, (LPARAM)&hook, TRUE ); |
| 428 | return FALSE; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | if ((hittest == HTERROR) || (hittest == HTNOWHERE)) |
| 432 | { |
Michael Stefaniuc | 2247af3 | 2002-09-04 19:37:01 +0000 | [diff] [blame] | 433 | SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, |
| 434 | MAKELONG( hittest, raw_message )); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 435 | return FALSE; |
| 436 | } |
| 437 | |
| 438 | if (!remove || GetCapture()) return TRUE; |
| 439 | |
| 440 | eatMsg = FALSE; |
| 441 | |
| 442 | if ((raw_message == WM_LBUTTONDOWN) || |
| 443 | (raw_message == WM_RBUTTONDOWN) || |
| 444 | (raw_message == WM_MBUTTONDOWN)) |
| 445 | { |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 446 | /* Send the WM_PARENTNOTIFY, |
| 447 | * note that even for double/nonclient clicks |
| 448 | * notification message is still WM_L/M/RBUTTONDOWN. |
| 449 | */ |
| 450 | MSG_SendParentNotify( msg->hwnd, raw_message, 0, msg->pt ); |
| 451 | |
| 452 | /* Activate the window if needed */ |
| 453 | |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 454 | if (msg->hwnd != GetActiveWindow()) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 455 | { |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 456 | HWND hwndTop = msg->hwnd; |
| 457 | while (hwndTop) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 458 | { |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 459 | if ((GetWindowLongW( hwndTop, GWL_STYLE ) & (WS_POPUP|WS_CHILD)) != WS_CHILD) break; |
| 460 | hwndTop = GetParent( hwndTop ); |
| 461 | } |
| 462 | |
| 463 | if (hwndTop && hwndTop != GetDesktopWindow()) |
| 464 | { |
| 465 | LONG ret = SendMessageA( msg->hwnd, WM_MOUSEACTIVATE, (WPARAM)hwndTop, |
| 466 | MAKELONG( hittest, raw_message ) ); |
| 467 | switch(ret) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 468 | { |
Alexandre Julliard | 5030bda | 2002-10-11 23:41:06 +0000 | [diff] [blame] | 469 | case MA_NOACTIVATEANDEAT: |
| 470 | eatMsg = TRUE; |
| 471 | /* fall through */ |
| 472 | case MA_NOACTIVATE: |
| 473 | break; |
| 474 | case MA_ACTIVATEANDEAT: |
| 475 | eatMsg = TRUE; |
| 476 | /* fall through */ |
| 477 | case MA_ACTIVATE: |
| 478 | case 0: |
| 479 | if (!FOCUS_MouseActivate( hwndTop )) eatMsg = TRUE; |
| 480 | break; |
| 481 | default: |
| 482 | WARN( "unknown WM_MOUSEACTIVATE code %ld\n", ret ); |
| 483 | break; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 484 | } |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | /* send the WM_SETCURSOR message */ |
| 490 | |
| 491 | /* Windows sends the normal mouse message as the message parameter |
| 492 | in the WM_SETCURSOR message even if it's non-client mouse message */ |
Michael Stefaniuc | 2247af3 | 2002-09-04 19:37:01 +0000 | [diff] [blame] | 493 | SendMessageA( msg->hwnd, WM_SETCURSOR, (WPARAM)msg->hwnd, |
| 494 | MAKELONG( hittest, raw_message )); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 495 | |
| 496 | return !eatMsg; |
| 497 | } |
| 498 | |
| 499 | |
| 500 | /*********************************************************************** |
| 501 | * process_hardware_message |
| 502 | * |
| 503 | * returns TRUE if the contents of 'msg' should be passed to the application |
| 504 | */ |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 505 | BOOL MSG_process_raw_hardware_message( MSG *msg, ULONG_PTR extra_info, HWND hwnd_filter, |
| 506 | UINT first, UINT last, BOOL remove ) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 507 | { |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 508 | if (is_keyboard_message( msg->message )) |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 509 | { |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 510 | process_raw_keyboard_message( msg ); |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 511 | } |
| 512 | else if (is_mouse_message( msg->message )) |
| 513 | { |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 514 | process_raw_mouse_message( msg, remove ); |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 515 | } |
| 516 | else |
| 517 | { |
| 518 | ERR( "unknown message type %x\n", msg->message ); |
| 519 | return FALSE; |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 520 | } |
Alexandre Julliard | 242e395 | 2003-01-08 00:27:58 +0000 | [diff] [blame] | 521 | return check_message_filter( msg, hwnd_filter, first, last ); |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 522 | } |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 523 | |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 524 | |
| 525 | /*********************************************************************** |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 526 | * MSG_process_cooked_hardware_message |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 527 | * |
| 528 | * returns TRUE if the contents of 'msg' should be passed to the application |
| 529 | */ |
Alexandre Julliard | 516e40e | 2001-10-17 17:48:49 +0000 | [diff] [blame] | 530 | BOOL MSG_process_cooked_hardware_message( MSG *msg, ULONG_PTR extra_info, BOOL remove ) |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 531 | { |
| 532 | if (is_keyboard_message( msg->message )) |
| 533 | return process_cooked_keyboard_message( msg, remove ); |
| 534 | |
| 535 | if (is_mouse_message( msg->message )) |
Alexandre Julliard | 516e40e | 2001-10-17 17:48:49 +0000 | [diff] [blame] | 536 | return process_cooked_mouse_message( msg, extra_info, remove ); |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 537 | |
| 538 | ERR( "unknown message type %x\n", msg->message ); |
Alexandre Julliard | 838d65a | 2001-06-19 19:16:41 +0000 | [diff] [blame] | 539 | return FALSE; |
Alexandre Julliard | aca0578 | 1994-10-17 18:12:41 +0000 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | |
Alexandre Julliard | cdd0923 | 1994-01-12 11:12:51 +0000 | [diff] [blame] | 543 | /*********************************************************************** |
Patrik Stridvall | 01d5e5b | 2001-07-02 19:59:40 +0000 | [diff] [blame] | 544 | * WaitMessage (USER.112) Suspend thread pending messages |
| 545 | * WaitMessage (USER32.@) Suspend thread pending messages |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 546 | * |
| 547 | * WaitMessage() suspends a thread until events appear in the thread's |
| 548 | * queue. |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 549 | */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 550 | BOOL WINAPI WaitMessage(void) |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 551 | { |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 552 | return (MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, QS_ALLINPUT, 0 ) != WAIT_FAILED); |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 553 | } |
| 554 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 555 | |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 556 | /*********************************************************************** |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 557 | * MsgWaitForMultipleObjectsEx (USER32.@) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 558 | */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 559 | DWORD WINAPI MsgWaitForMultipleObjectsEx( DWORD count, CONST HANDLE *pHandles, |
| 560 | DWORD timeout, DWORD mask, DWORD flags ) |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 561 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 562 | HANDLE handles[MAXIMUM_WAIT_OBJECTS]; |
Alexandre Julliard | 3c43df8 | 2002-07-01 18:20:16 +0000 | [diff] [blame] | 563 | DWORD i, ret, lock; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 564 | MESSAGEQUEUE *msgQueue; |
Alexandre Julliard | dbf2bf0 | 1999-01-01 17:05:53 +0000 | [diff] [blame] | 565 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 566 | if (count > MAXIMUM_WAIT_OBJECTS-1) |
Alexandre Julliard | dbf2bf0 | 1999-01-01 17:05:53 +0000 | [diff] [blame] | 567 | { |
| 568 | SetLastError( ERROR_INVALID_PARAMETER ); |
| 569 | return WAIT_FAILED; |
| 570 | } |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 571 | |
Alexandre Julliard | 8afe662 | 2001-07-26 20:12:22 +0000 | [diff] [blame] | 572 | if (!(msgQueue = QUEUE_Current())) return WAIT_FAILED; |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 573 | |
| 574 | /* set the queue mask */ |
| 575 | SERVER_START_REQ( set_queue_mask ) |
| 576 | { |
| 577 | req->wake_mask = (flags & MWMO_INPUTAVAILABLE) ? mask : 0; |
| 578 | req->changed_mask = mask; |
| 579 | req->skip_wait = 0; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 580 | wine_server_call( req ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 581 | } |
| 582 | SERVER_END_REQ; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 583 | |
Alexandre Julliard | dbf2bf0 | 1999-01-01 17:05:53 +0000 | [diff] [blame] | 584 | /* Add the thread event to the handle list */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 585 | for (i = 0; i < count; i++) handles[i] = pHandles[i]; |
| 586 | handles[count] = msgQueue->server_queue; |
| 587 | |
Alexandre Julliard | 3c43df8 | 2002-07-01 18:20:16 +0000 | [diff] [blame] | 588 | ReleaseThunkLock( &lock ); |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 589 | if (USER_Driver.pMsgWaitForMultipleObjectsEx) |
Alexandre Julliard | 4323004 | 2001-05-16 19:52:29 +0000 | [diff] [blame] | 590 | { |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 591 | ret = USER_Driver.pMsgWaitForMultipleObjectsEx( count+1, handles, timeout, mask, flags ); |
| 592 | if (ret == count+1) ret = count; /* pretend the msg queue is ready */ |
Alexandre Julliard | 4323004 | 2001-05-16 19:52:29 +0000 | [diff] [blame] | 593 | } |
| 594 | else |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 595 | ret = WaitForMultipleObjectsEx( count+1, handles, flags & MWMO_WAITALL, |
| 596 | timeout, flags & MWMO_ALERTABLE ); |
Alexandre Julliard | 3c43df8 | 2002-07-01 18:20:16 +0000 | [diff] [blame] | 597 | if (lock) RestoreThunkLock( lock ); |
Stephane Lussier | b3a99de | 1999-02-09 15:35:12 +0000 | [diff] [blame] | 598 | return ret; |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 599 | } |
| 600 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 601 | |
Eric Pouech | 982e0ce | 2001-01-28 23:44:56 +0000 | [diff] [blame] | 602 | /*********************************************************************** |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 603 | * MsgWaitForMultipleObjects (USER32.@) |
Eric Pouech | 982e0ce | 2001-01-28 23:44:56 +0000 | [diff] [blame] | 604 | */ |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 605 | DWORD WINAPI MsgWaitForMultipleObjects( DWORD count, CONST HANDLE *handles, |
| 606 | BOOL wait_all, DWORD timeout, DWORD mask ) |
Eric Pouech | 982e0ce | 2001-01-28 23:44:56 +0000 | [diff] [blame] | 607 | { |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 608 | return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask, |
| 609 | wait_all ? MWMO_WAITALL : 0 ); |
Eric Pouech | 982e0ce | 2001-01-28 23:44:56 +0000 | [diff] [blame] | 610 | } |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 611 | |
Alexandre Julliard | 51ab43b | 2001-05-18 22:51:56 +0000 | [diff] [blame] | 612 | |
| 613 | /*********************************************************************** |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 614 | * WaitForInputIdle (USER32.@) |
| 615 | */ |
| 616 | DWORD WINAPI WaitForInputIdle( HANDLE hProcess, DWORD dwTimeOut ) |
| 617 | { |
Francois Gouget | 671a2ee | 2001-10-08 20:28:12 +0000 | [diff] [blame] | 618 | DWORD start_time, elapsed, ret; |
Michael Stefaniuc | ec5612e | 2002-10-30 23:45:38 +0000 | [diff] [blame] | 619 | HANDLE idle_event = (HANDLE)-1; |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 620 | |
| 621 | SERVER_START_REQ( wait_input_idle ) |
| 622 | { |
| 623 | req->handle = hProcess; |
| 624 | req->timeout = dwTimeOut; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 625 | if (!(ret = wine_server_call_err( req ))) idle_event = reply->event; |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 626 | } |
| 627 | SERVER_END_REQ; |
Francois Gouget | 671a2ee | 2001-10-08 20:28:12 +0000 | [diff] [blame] | 628 | if (ret) return WAIT_FAILED; /* error */ |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 629 | if (!idle_event) return 0; /* no event to wait on */ |
| 630 | |
Francois Gouget | 671a2ee | 2001-10-08 20:28:12 +0000 | [diff] [blame] | 631 | start_time = GetTickCount(); |
| 632 | elapsed = 0; |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 633 | |
Alexandre Julliard | aff7dda | 2002-11-22 21:22:14 +0000 | [diff] [blame] | 634 | TRACE("waiting for %p\n", idle_event ); |
Francois Gouget | 671a2ee | 2001-10-08 20:28:12 +0000 | [diff] [blame] | 635 | do |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 636 | { |
Francois Gouget | 671a2ee | 2001-10-08 20:28:12 +0000 | [diff] [blame] | 637 | ret = MsgWaitForMultipleObjects ( 1, &idle_event, FALSE, dwTimeOut - elapsed, QS_SENDMESSAGE ); |
| 638 | switch (ret) |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 639 | { |
Francois Gouget | 671a2ee | 2001-10-08 20:28:12 +0000 | [diff] [blame] | 640 | case WAIT_OBJECT_0+1: |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 641 | process_sent_messages(); |
Francois Gouget | 671a2ee | 2001-10-08 20:28:12 +0000 | [diff] [blame] | 642 | break; |
| 643 | case WAIT_TIMEOUT: |
| 644 | case WAIT_FAILED: |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 645 | TRACE("timeout or error\n"); |
| 646 | return ret; |
Francois Gouget | 671a2ee | 2001-10-08 20:28:12 +0000 | [diff] [blame] | 647 | default: |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 648 | TRACE("finished\n"); |
| 649 | return 0; |
| 650 | } |
Francois Gouget | 671a2ee | 2001-10-08 20:28:12 +0000 | [diff] [blame] | 651 | if (dwTimeOut != INFINITE) |
| 652 | { |
| 653 | elapsed = GetTickCount() - start_time; |
| 654 | if (elapsed > dwTimeOut) |
| 655 | break; |
| 656 | } |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 657 | } |
Francois Gouget | 671a2ee | 2001-10-08 20:28:12 +0000 | [diff] [blame] | 658 | while (1); |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 659 | |
| 660 | return WAIT_TIMEOUT; |
| 661 | } |
| 662 | |
| 663 | |
| 664 | /*********************************************************************** |
| 665 | * UserYield (USER.332) |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 666 | */ |
| 667 | void WINAPI UserYield16(void) |
| 668 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 669 | DWORD count; |
| 670 | |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 671 | /* Handle sent messages */ |
| 672 | process_sent_messages(); |
| 673 | |
| 674 | /* Yield */ |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 675 | ReleaseThunkLock(&count); |
| 676 | if (count) |
| 677 | { |
| 678 | RestoreThunkLock(count); |
| 679 | /* Handle sent messages again */ |
| 680 | process_sent_messages(); |
| 681 | } |
Alexandre Julliard | 9f55ae6 | 2001-06-28 04:37:22 +0000 | [diff] [blame] | 682 | } |
| 683 | |
| 684 | |
Alexandre Julliard | 7e50df3 | 1994-08-06 11:22:41 +0000 | [diff] [blame] | 685 | /*********************************************************************** |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 686 | * TranslateMessage (USER32.@) |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 687 | * |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 688 | * Implementation of TranslateMessage. |
| 689 | * |
| 690 | * TranslateMessage translates virtual-key messages into character-messages, |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 691 | * as follows : |
| 692 | * WM_KEYDOWN/WM_KEYUP combinations produce a WM_CHAR or WM_DEADCHAR message. |
| 693 | * ditto replacing WM_* with WM_SYS* |
| 694 | * This produces WM_CHAR messages only for keys mapped to ASCII characters |
| 695 | * by the keyboard driver. |
Alexandre Julliard | 01ecb57 | 2002-06-10 23:02:19 +0000 | [diff] [blame] | 696 | * |
| 697 | * If the message is WM_KEYDOWN, WM_KEYUP, WM_SYSKEYDOWN, or WM_SYSKEYUP, the |
| 698 | * return value is nonzero, regardless of the translation. |
| 699 | * |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 700 | */ |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 701 | BOOL WINAPI TranslateMessage( const MSG *msg ) |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 702 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 703 | UINT message; |
Dmitry Timoshkov | 2fa0c66 | 2000-11-25 02:09:45 +0000 | [diff] [blame] | 704 | WCHAR wp[2]; |
Alexandre Julliard | 01ecb57 | 2002-06-10 23:02:19 +0000 | [diff] [blame] | 705 | BOOL rc = FALSE; |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 706 | BYTE state[256]; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 707 | |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 708 | if (msg->message >= WM_KEYFIRST && msg->message <= WM_KEYLAST) |
Alexandre Julliard | 01ecb57 | 2002-06-10 23:02:19 +0000 | [diff] [blame] | 709 | { |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 710 | TRACE_(key)("(%s, %04X, %08lX)\n", |
Guy L. Albertelli | db9b549 | 2001-09-07 18:38:57 +0000 | [diff] [blame] | 711 | SPY_GetMsgName(msg->message, msg->hwnd), msg->wParam, msg->lParam ); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 712 | |
Alexandre Julliard | 01ecb57 | 2002-06-10 23:02:19 +0000 | [diff] [blame] | 713 | /* Return code must be TRUE no matter what! */ |
| 714 | rc = TRUE; |
| 715 | } |
| 716 | |
| 717 | if ((msg->message != WM_KEYDOWN) && (msg->message != WM_SYSKEYDOWN)) return rc; |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 718 | |
Dmitry Timoshkov | 740bb92 | 2000-11-05 20:07:59 +0000 | [diff] [blame] | 719 | TRACE_(key)("Translating key %s (%04x), scancode %02x\n", |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 720 | SPY_GetVKeyName(msg->wParam), msg->wParam, LOBYTE(HIWORD(msg->lParam))); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 721 | |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 722 | GetKeyboardState( state ); |
Dmitry Timoshkov | 2fa0c66 | 2000-11-25 02:09:45 +0000 | [diff] [blame] | 723 | /* FIXME : should handle ToUnicode yielding 2 */ |
Alexandre Julliard | 8ba666f | 2003-01-08 19:56:31 +0000 | [diff] [blame] | 724 | switch (ToUnicode(msg->wParam, HIWORD(msg->lParam), state, wp, 2, 0)) |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 725 | { |
Andreas Mohr | 1af53cb | 2000-12-09 03:15:32 +0000 | [diff] [blame] | 726 | case 1: |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 727 | message = (msg->message == WM_KEYDOWN) ? WM_CHAR : WM_SYSCHAR; |
Mike McCormack | 020f8a4 | 2003-05-19 18:56:49 +0000 | [diff] [blame] | 728 | TRACE_(key)("1 -> PostMessageW(%p,%s,%04x,%08lx)\n", |
| 729 | msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 730 | PostMessageW( msg->hwnd, message, wp[0], msg->lParam ); |
Alexandre Julliard | 01ecb57 | 2002-06-10 23:02:19 +0000 | [diff] [blame] | 731 | break; |
Alexandre Julliard | c981d0b | 1996-03-31 16:40:13 +0000 | [diff] [blame] | 732 | |
Andreas Mohr | 1af53cb | 2000-12-09 03:15:32 +0000 | [diff] [blame] | 733 | case -1: |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 734 | message = (msg->message == WM_KEYDOWN) ? WM_DEADCHAR : WM_SYSDEADCHAR; |
Mike McCormack | 020f8a4 | 2003-05-19 18:56:49 +0000 | [diff] [blame] | 735 | TRACE_(key)("-1 -> PostMessageW(%p,%s,%04x,%08lx)\n", |
| 736 | msg->hwnd, SPY_GetMsgName(message, msg->hwnd), wp[0], msg->lParam); |
Alexandre Julliard | d253c58 | 2001-08-07 19:19:08 +0000 | [diff] [blame] | 737 | PostMessageW( msg->hwnd, message, wp[0], msg->lParam ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 738 | return TRUE; |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 739 | } |
Alexandre Julliard | 01ecb57 | 2002-06-10 23:02:19 +0000 | [diff] [blame] | 740 | return rc; |
Alexandre Julliard | 75a839a | 1993-07-15 11:13:45 +0000 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | |
| 744 | /*********************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 745 | * DispatchMessageA (USER32.@) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 746 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 747 | LONG WINAPI DispatchMessageA( const MSG* msg ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 748 | { |
| 749 | WND * wndPtr; |
| 750 | LONG retval; |
| 751 | int painting; |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 752 | WNDPROC winproc; |
| 753 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 754 | /* Process timer messages */ |
| 755 | if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER)) |
| 756 | { |
| 757 | if (msg->lParam) |
| 758 | { |
| 759 | /* HOOK_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */ |
Stephane Lussier | 6bac4f2 | 2000-09-29 00:56:05 +0000 | [diff] [blame] | 760 | |
Andreas Mohr | 1af53cb | 2000-12-09 03:15:32 +0000 | [diff] [blame] | 761 | /* before calling window proc, verify whether timer is still valid; |
| 762 | there's a slim chance that the application kills the timer |
| 763 | between GetMessage and DispatchMessage API calls */ |
Alexandre Julliard | 18d0297 | 2002-12-03 23:34:52 +0000 | [diff] [blame] | 764 | if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (WNDPROC)msg->lParam)) |
Stephane Lussier | 6bac4f2 | 2000-09-29 00:56:05 +0000 | [diff] [blame] | 765 | return 0; /* invalid winproc */ |
| 766 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 767 | return CallWindowProcA( (WNDPROC)msg->lParam, msg->hwnd, |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 768 | msg->message, msg->wParam, GetTickCount() ); |
| 769 | } |
| 770 | } |
| 771 | |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 772 | if (!(wndPtr = WIN_GetPtr( msg->hwnd ))) |
Francois Boisvert | 3a3cd9f | 1999-03-28 12:42:52 +0000 | [diff] [blame] | 773 | { |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 774 | if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE ); |
| 775 | return 0; |
| 776 | } |
| 777 | if (wndPtr == WND_OTHER_PROCESS) |
| 778 | { |
| 779 | if (IsWindow( msg->hwnd )) |
Alexandre Julliard | aff7dda | 2002-11-22 21:22:14 +0000 | [diff] [blame] | 780 | ERR( "cannot dispatch msg to other process window %p\n", msg->hwnd ); |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 781 | SetLastError( ERROR_INVALID_WINDOW_HANDLE ); |
| 782 | return 0; |
| 783 | } |
| 784 | if (!(winproc = wndPtr->winproc)) |
| 785 | { |
| 786 | WIN_ReleasePtr( wndPtr ); |
| 787 | return 0; |
Francois Boisvert | 3a3cd9f | 1999-03-28 12:42:52 +0000 | [diff] [blame] | 788 | } |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 789 | painting = (msg->message == WM_PAINT); |
| 790 | if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT; |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 791 | WIN_ReleasePtr( wndPtr ); |
| 792 | /* hook_CallHooks32A( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */ |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 793 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 794 | SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message, |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 795 | msg->wParam, msg->lParam ); |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 796 | retval = CallWindowProcA( winproc, msg->hwnd, msg->message, |
| 797 | msg->wParam, msg->lParam ); |
Guy L. Albertelli | 936c6c4 | 2000-10-22 23:52:47 +0000 | [diff] [blame] | 798 | SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval, |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 799 | msg->wParam, msg->lParam ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 800 | |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 801 | if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS)) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 802 | { |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 803 | BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate); |
| 804 | wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT; |
| 805 | WIN_ReleasePtr( wndPtr ); |
| 806 | if (validate) |
| 807 | { |
Alexandre Julliard | aff7dda | 2002-11-22 21:22:14 +0000 | [diff] [blame] | 808 | ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg->hwnd ); |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 809 | /* Validate the update region to avoid infinite WM_PAINT loop */ |
| 810 | RedrawWindow( msg->hwnd, NULL, 0, |
| 811 | RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT ); |
| 812 | } |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 813 | } |
| 814 | return retval; |
| 815 | } |
| 816 | |
| 817 | |
| 818 | /*********************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 819 | * DispatchMessageW (USER32.@) Process Message |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 820 | * |
| 821 | * Process the message specified in the structure *_msg_. |
| 822 | * |
| 823 | * If the lpMsg parameter points to a WM_TIMER message and the |
| 824 | * parameter of the WM_TIMER message is not NULL, the lParam parameter |
| 825 | * points to the function that is called instead of the window |
| 826 | * procedure. |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 827 | * |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 828 | * The message must be valid. |
| 829 | * |
| 830 | * RETURNS |
| 831 | * |
| 832 | * DispatchMessage() returns the result of the window procedure invoked. |
| 833 | * |
| 834 | * CONFORMANCE |
| 835 | * |
Vincent Béron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 836 | * ECMA-234, Win32 |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 837 | * |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 838 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 839 | LONG WINAPI DispatchMessageW( const MSG* msg ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 840 | { |
| 841 | WND * wndPtr; |
| 842 | LONG retval; |
| 843 | int painting; |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 844 | WNDPROC winproc; |
| 845 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 846 | /* Process timer messages */ |
| 847 | if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER)) |
| 848 | { |
| 849 | if (msg->lParam) |
| 850 | { |
| 851 | /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */ |
Stephane Lussier | 6bac4f2 | 2000-09-29 00:56:05 +0000 | [diff] [blame] | 852 | |
Andreas Mohr | 1af53cb | 2000-12-09 03:15:32 +0000 | [diff] [blame] | 853 | /* before calling window proc, verify whether timer is still valid; |
| 854 | there's a slim chance that the application kills the timer |
| 855 | between GetMessage and DispatchMessage API calls */ |
Alexandre Julliard | 18d0297 | 2002-12-03 23:34:52 +0000 | [diff] [blame] | 856 | if (!TIMER_IsTimerValid(msg->hwnd, (UINT) msg->wParam, (WNDPROC)msg->lParam)) |
Stephane Lussier | 6bac4f2 | 2000-09-29 00:56:05 +0000 | [diff] [blame] | 857 | return 0; /* invalid winproc */ |
| 858 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 859 | return CallWindowProcW( (WNDPROC)msg->lParam, msg->hwnd, |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 860 | msg->message, msg->wParam, GetTickCount() ); |
| 861 | } |
| 862 | } |
| 863 | |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 864 | if (!(wndPtr = WIN_GetPtr( msg->hwnd ))) |
Francois Boisvert | 3a3cd9f | 1999-03-28 12:42:52 +0000 | [diff] [blame] | 865 | { |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 866 | if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE ); |
| 867 | return 0; |
| 868 | } |
| 869 | if (wndPtr == WND_OTHER_PROCESS) |
| 870 | { |
| 871 | if (IsWindow( msg->hwnd )) |
Alexandre Julliard | aff7dda | 2002-11-22 21:22:14 +0000 | [diff] [blame] | 872 | ERR( "cannot dispatch msg to other process window %p\n", msg->hwnd ); |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 873 | SetLastError( ERROR_INVALID_WINDOW_HANDLE ); |
| 874 | return 0; |
| 875 | } |
| 876 | if (!(winproc = wndPtr->winproc)) |
| 877 | { |
| 878 | WIN_ReleasePtr( wndPtr ); |
| 879 | return 0; |
Francois Boisvert | 3a3cd9f | 1999-03-28 12:42:52 +0000 | [diff] [blame] | 880 | } |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 881 | painting = (msg->message == WM_PAINT); |
| 882 | if (painting) wndPtr->flags |= WIN_NEEDS_BEGINPAINT; |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 883 | WIN_ReleasePtr( wndPtr ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 884 | /* HOOK_CallHooks32W( WH_CALLWNDPROC, HC_ACTION, 0, FIXME ); */ |
| 885 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 886 | SPY_EnterMessage( SPY_DISPATCHMESSAGE, msg->hwnd, msg->message, |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 887 | msg->wParam, msg->lParam ); |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 888 | retval = CallWindowProcW( winproc, msg->hwnd, msg->message, |
| 889 | msg->wParam, msg->lParam ); |
Guy L. Albertelli | 936c6c4 | 2000-10-22 23:52:47 +0000 | [diff] [blame] | 890 | SPY_ExitMessage( SPY_RESULT_OK, msg->hwnd, msg->message, retval, |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 891 | msg->wParam, msg->lParam ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 892 | |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 893 | if (painting && (wndPtr = WIN_GetPtr( msg->hwnd )) && (wndPtr != WND_OTHER_PROCESS)) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 894 | { |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 895 | BOOL validate = ((wndPtr->flags & WIN_NEEDS_BEGINPAINT) && wndPtr->hrgnUpdate); |
| 896 | wndPtr->flags &= ~WIN_NEEDS_BEGINPAINT; |
| 897 | WIN_ReleasePtr( wndPtr ); |
| 898 | if (validate) |
| 899 | { |
Alexandre Julliard | aff7dda | 2002-11-22 21:22:14 +0000 | [diff] [blame] | 900 | ERR( "BeginPaint not called on WM_PAINT for hwnd %p!\n", msg->hwnd ); |
Alexandre Julliard | 8fd26b9 | 2001-10-15 17:56:45 +0000 | [diff] [blame] | 901 | /* Validate the update region to avoid infinite WM_PAINT loop */ |
| 902 | RedrawWindow( msg->hwnd, NULL, 0, |
| 903 | RDW_NOFRAME | RDW_VALIDATE | RDW_NOCHILDREN | RDW_NOINTERNALPAINT ); |
| 904 | } |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 905 | } |
| 906 | return retval; |
| 907 | } |
| 908 | |
| 909 | |
| 910 | /*********************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 911 | * RegisterWindowMessage (USER.118) |
| 912 | * RegisterWindowMessageA (USER32.@) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 913 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 914 | WORD WINAPI RegisterWindowMessageA( LPCSTR str ) |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 915 | { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 916 | TRACE("%s\n", str ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 917 | return GlobalAddAtomA( str ); |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 918 | } |
Alexandre Julliard | 86a8d0f | 1994-01-18 23:04:40 +0000 | [diff] [blame] | 919 | |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 920 | |
| 921 | /*********************************************************************** |
Patrik Stridvall | 2ece70e | 2000-12-22 01:38:01 +0000 | [diff] [blame] | 922 | * RegisterWindowMessageW (USER32.@) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 923 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 924 | WORD WINAPI RegisterWindowMessageW( LPCWSTR str ) |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 925 | { |
Dimitrie O. Paun | dd03cc1 | 1999-12-08 03:56:23 +0000 | [diff] [blame] | 926 | TRACE("%p\n", str ); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 927 | return GlobalAddAtomW( str ); |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | |
Alexandre Julliard | 86a8d0f | 1994-01-18 23:04:40 +0000 | [diff] [blame] | 931 | /*********************************************************************** |
Patrik Stridvall | fc34344 | 2002-08-20 00:20:43 +0000 | [diff] [blame] | 932 | * BroadcastSystemMessage (USER32.@) |
| 933 | * BroadcastSystemMessageA (USER32.@) |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 934 | */ |
| 935 | LONG WINAPI BroadcastSystemMessage( |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 936 | DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam, |
Aric Stewart | 5501f12 | 2002-08-16 23:29:48 +0000 | [diff] [blame] | 937 | LPARAM lParam ) |
| 938 | { |
| 939 | if ((*recipients & BSM_APPLICATIONS)|| |
| 940 | (*recipients == BSM_ALLCOMPONENTS)) |
| 941 | { |
| 942 | FIXME("(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", |
| 943 | dwFlags,*recipients,uMessage,wParam,lParam); |
| 944 | PostMessageA(HWND_BROADCAST,uMessage,wParam,lParam); |
| 945 | return 1; |
| 946 | } |
| 947 | else |
| 948 | { |
| 949 | FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", |
| 950 | dwFlags,*recipients,uMessage,wParam,lParam); |
| 951 | return -1; |
| 952 | } |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 953 | } |
Mike McCormack | 020f8a4 | 2003-05-19 18:56:49 +0000 | [diff] [blame] | 954 | |
| 955 | /*********************************************************************** |
| 956 | * BroadcastSystemMessageW (USER32.@) |
| 957 | */ |
| 958 | LONG WINAPI BroadcastSystemMessageW( |
| 959 | DWORD dwFlags,LPDWORD recipients,UINT uMessage,WPARAM wParam, |
| 960 | LPARAM lParam ) |
| 961 | { |
| 962 | if ((*recipients & BSM_APPLICATIONS)|| |
| 963 | (*recipients == BSM_ALLCOMPONENTS)) |
| 964 | { |
| 965 | FIXME("(%08lx,%08lx,%08x,%08x,%08lx): semi-stub!\n", |
| 966 | dwFlags,*recipients,uMessage,wParam,lParam); |
| 967 | PostMessageW(HWND_BROADCAST,uMessage,wParam,lParam); |
| 968 | return 1; |
| 969 | } |
| 970 | else |
| 971 | { |
| 972 | FIXME("(%08lx,%08lx,%08x,%08x,%08lx): stub!\n", |
| 973 | dwFlags,*recipients,uMessage,wParam,lParam); |
| 974 | return -1; |
| 975 | } |
| 976 | } |