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