Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 1 | /* * Message queues related functions |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 2 | * |
| 3 | * Copyright 1993, 1994 Alexandre Julliard |
| 4 | */ |
| 5 | |
Alexandre Julliard | 8feb3bc | 1999-02-28 12:25:03 +0000 | [diff] [blame] | 6 | #include <string.h> |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 7 | #include <signal.h> |
Marcus Meissner | 317af32 | 1999-02-17 13:51:06 +0000 | [diff] [blame] | 8 | #include "wine/winbase16.h" |
| 9 | #include "wine/winuser16.h" |
Alexandre Julliard | 641ee76 | 1997-08-04 16:34:36 +0000 | [diff] [blame] | 10 | #include "miscemu.h" |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 11 | #include "module.h" |
| 12 | #include "queue.h" |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 13 | #include "task.h" |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 14 | #include "win.h" |
Alexandre Julliard | a0b2b1d | 1997-11-16 17:38:29 +0000 | [diff] [blame] | 15 | #include "clipboard.h" |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 16 | #include "hook.h" |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 17 | #include "heap.h" |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 18 | #include "thread.h" |
| 19 | #include "process.h" |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 20 | #include <assert.h> |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 21 | #include "debug.h" |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 22 | #include "spy.h" |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 23 | |
| 24 | #define MAX_QUEUE_SIZE 120 /* Max. size of a message queue */ |
| 25 | |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 26 | static HQUEUE16 hFirstQueue = 0; |
Alexandre Julliard | 7ff1c41 | 1997-05-25 13:58:18 +0000 | [diff] [blame] | 27 | static HQUEUE16 hExitingQueue = 0; |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 28 | static HQUEUE16 hmemSysMsgQueue = 0; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 29 | static MESSAGEQUEUE *sysMsgQueue = NULL; |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 30 | static PERQUEUEDATA *pQDataWin16 = NULL; /* Global perQData for Win16 tasks */ |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 31 | |
Alexandre Julliard | 8b91563 | 1996-06-16 16:16:05 +0000 | [diff] [blame] | 32 | static MESSAGEQUEUE *pMouseQueue = NULL; /* Queue for last mouse message */ |
| 33 | static MESSAGEQUEUE *pKbdQueue = NULL; /* Queue for last kbd message */ |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 34 | |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 35 | HQUEUE16 hCursorQueue = 0; |
| 36 | HQUEUE16 hActiveQueue = 0; |
| 37 | |
| 38 | |
| 39 | /*********************************************************************** |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 40 | * PERQDATA_CreateInstance |
| 41 | * |
| 42 | * Creates an instance of a reference counted PERQUEUEDATA element |
| 43 | * for the message queue. perQData is stored globally for 16 bit tasks. |
| 44 | * |
| 45 | * Note: We don't implement perQdata exactly the same way Windows does. |
| 46 | * Each perQData element is reference counted since it may be potentially |
| 47 | * shared by multiple message Queues (via AttachThreadInput). |
| 48 | * We only store the current values for Active, Capture and focus windows |
| 49 | * currently. |
| 50 | */ |
| 51 | PERQUEUEDATA * PERQDATA_CreateInstance( ) |
| 52 | { |
| 53 | PERQUEUEDATA *pQData; |
| 54 | |
| 55 | BOOL16 bIsWin16 = 0; |
| 56 | |
| 57 | TRACE(msg,"()\n"); |
| 58 | |
| 59 | /* Share a single instance of perQData for all 16 bit tasks */ |
| 60 | if ( ( bIsWin16 = THREAD_IsWin16( THREAD_Current() ) ) ) |
| 61 | { |
| 62 | /* If previously allocated, just bump up ref count */ |
| 63 | if ( pQDataWin16 ) |
| 64 | { |
| 65 | PERQDATA_Addref( pQDataWin16 ); |
| 66 | return pQDataWin16; |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | /* Allocate PERQUEUEDATA from the system heap */ |
| 71 | if (!( pQData = (PERQUEUEDATA *) HeapAlloc( SystemHeap, 0, |
| 72 | sizeof(PERQUEUEDATA) ) )) |
| 73 | return 0; |
| 74 | |
| 75 | /* Initialize */ |
| 76 | pQData->hWndCapture = pQData->hWndFocus = pQData->hWndActive = 0; |
| 77 | pQData->ulRefCount = 1; |
| 78 | pQData->nCaptureHT = HTCLIENT; |
| 79 | |
| 80 | /* Note: We have an independent critical section for the per queue data |
| 81 | * since this may be shared by different threads. see AttachThreadInput() |
| 82 | */ |
| 83 | InitializeCriticalSection( &pQData->cSection ); |
| 84 | |
| 85 | /* Save perQData globally for 16 bit tasks */ |
| 86 | if ( bIsWin16 ) |
| 87 | pQDataWin16 = pQData; |
| 88 | |
| 89 | return pQData; |
| 90 | } |
| 91 | |
| 92 | |
| 93 | /*********************************************************************** |
| 94 | * PERQDATA_Addref |
| 95 | * |
| 96 | * Increment reference count for the PERQUEUEDATA instance |
| 97 | * Returns reference count for debugging purposes |
| 98 | */ |
| 99 | ULONG PERQDATA_Addref( PERQUEUEDATA *pQData ) |
| 100 | { |
| 101 | assert(pQData != 0 ); |
| 102 | TRACE(msg,"(): current refcount %lu ...\n", pQData->ulRefCount); |
| 103 | |
| 104 | EnterCriticalSection( &pQData->cSection ); |
| 105 | ++pQData->ulRefCount; |
| 106 | LeaveCriticalSection( &pQData->cSection ); |
| 107 | |
| 108 | return pQData->ulRefCount; |
| 109 | } |
| 110 | |
| 111 | |
| 112 | /*********************************************************************** |
| 113 | * PERQDATA_Release |
| 114 | * |
| 115 | * Release a reference to a PERQUEUEDATA instance. |
| 116 | * Destroy the instance if no more references exist |
| 117 | * Returns reference count for debugging purposes |
| 118 | */ |
| 119 | ULONG PERQDATA_Release( PERQUEUEDATA *pQData ) |
| 120 | { |
| 121 | assert(pQData != 0 ); |
| 122 | TRACE(msg,"(): current refcount %lu ...\n", |
| 123 | (LONG)pQData->ulRefCount ); |
| 124 | |
| 125 | EnterCriticalSection( &pQData->cSection ); |
| 126 | if ( --pQData->ulRefCount == 0 ) |
| 127 | { |
| 128 | LeaveCriticalSection( &pQData->cSection ); |
| 129 | DeleteCriticalSection( &pQData->cSection ); |
| 130 | |
| 131 | TRACE(msg,"(): deleting PERQUEUEDATA instance ...\n" ); |
| 132 | |
| 133 | /* Deleting our global 16 bit perQData? */ |
| 134 | if ( pQData == pQDataWin16 ) |
| 135 | pQDataWin16 = 0; |
| 136 | |
| 137 | /* Free the PERQUEUEDATA instance */ |
| 138 | HeapFree( SystemHeap, 0, pQData ); |
| 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | LeaveCriticalSection( &pQData->cSection ); |
| 143 | |
| 144 | return pQData->ulRefCount; |
| 145 | } |
| 146 | |
| 147 | |
| 148 | /*********************************************************************** |
| 149 | * PERQDATA_GetFocusWnd |
| 150 | * |
| 151 | * Get the focus hwnd member in a threadsafe manner |
| 152 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 153 | HWND PERQDATA_GetFocusWnd( PERQUEUEDATA *pQData ) |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 154 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 155 | HWND hWndFocus; |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 156 | assert(pQData != 0 ); |
| 157 | |
| 158 | EnterCriticalSection( &pQData->cSection ); |
| 159 | hWndFocus = pQData->hWndFocus; |
| 160 | LeaveCriticalSection( &pQData->cSection ); |
| 161 | |
| 162 | return hWndFocus; |
| 163 | } |
| 164 | |
| 165 | |
| 166 | /*********************************************************************** |
| 167 | * PERQDATA_SetFocusWnd |
| 168 | * |
| 169 | * Set the focus hwnd member in a threadsafe manner |
| 170 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 171 | HWND PERQDATA_SetFocusWnd( PERQUEUEDATA *pQData, HWND hWndFocus ) |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 172 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 173 | HWND hWndFocusPrv; |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 174 | assert(pQData != 0 ); |
| 175 | |
| 176 | EnterCriticalSection( &pQData->cSection ); |
| 177 | hWndFocusPrv = pQData->hWndFocus; |
| 178 | pQData->hWndFocus = hWndFocus; |
| 179 | LeaveCriticalSection( &pQData->cSection ); |
| 180 | |
| 181 | return hWndFocusPrv; |
| 182 | } |
| 183 | |
| 184 | |
| 185 | /*********************************************************************** |
| 186 | * PERQDATA_GetActiveWnd |
| 187 | * |
| 188 | * Get the active hwnd member in a threadsafe manner |
| 189 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 190 | HWND PERQDATA_GetActiveWnd( PERQUEUEDATA *pQData ) |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 191 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 192 | HWND hWndActive; |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 193 | assert(pQData != 0 ); |
| 194 | |
| 195 | EnterCriticalSection( &pQData->cSection ); |
| 196 | hWndActive = pQData->hWndActive; |
| 197 | LeaveCriticalSection( &pQData->cSection ); |
| 198 | |
| 199 | return hWndActive; |
| 200 | } |
| 201 | |
| 202 | |
| 203 | /*********************************************************************** |
| 204 | * PERQDATA_SetActiveWnd |
| 205 | * |
| 206 | * Set the active focus hwnd member in a threadsafe manner |
| 207 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 208 | HWND PERQDATA_SetActiveWnd( PERQUEUEDATA *pQData, HWND hWndActive ) |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 209 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 210 | HWND hWndActivePrv; |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 211 | assert(pQData != 0 ); |
| 212 | |
| 213 | EnterCriticalSection( &pQData->cSection ); |
| 214 | hWndActivePrv = pQData->hWndActive; |
| 215 | pQData->hWndActive = hWndActive; |
| 216 | LeaveCriticalSection( &pQData->cSection ); |
| 217 | |
| 218 | return hWndActivePrv; |
| 219 | } |
| 220 | |
| 221 | |
| 222 | /*********************************************************************** |
| 223 | * PERQDATA_GetCaptureWnd |
| 224 | * |
| 225 | * Get the capture hwnd member in a threadsafe manner |
| 226 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 227 | HWND PERQDATA_GetCaptureWnd( PERQUEUEDATA *pQData ) |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 228 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 229 | HWND hWndCapture; |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 230 | assert(pQData != 0 ); |
| 231 | |
| 232 | EnterCriticalSection( &pQData->cSection ); |
| 233 | hWndCapture = pQData->hWndCapture; |
| 234 | LeaveCriticalSection( &pQData->cSection ); |
| 235 | |
| 236 | return hWndCapture; |
| 237 | } |
| 238 | |
| 239 | |
| 240 | /*********************************************************************** |
| 241 | * PERQDATA_SetCaptureWnd |
| 242 | * |
| 243 | * Set the capture hwnd member in a threadsafe manner |
| 244 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 245 | HWND PERQDATA_SetCaptureWnd( PERQUEUEDATA *pQData, HWND hWndCapture ) |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 246 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 247 | HWND hWndCapturePrv; |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 248 | assert(pQData != 0 ); |
| 249 | |
| 250 | EnterCriticalSection( &pQData->cSection ); |
| 251 | hWndCapturePrv = pQData->hWndCapture; |
| 252 | pQData->hWndCapture = hWndCapture; |
| 253 | LeaveCriticalSection( &pQData->cSection ); |
| 254 | |
| 255 | return hWndCapturePrv; |
| 256 | } |
| 257 | |
| 258 | |
| 259 | /*********************************************************************** |
| 260 | * PERQDATA_GetCaptureInfo |
| 261 | * |
| 262 | * Get the capture info member in a threadsafe manner |
| 263 | */ |
| 264 | INT16 PERQDATA_GetCaptureInfo( PERQUEUEDATA *pQData ) |
| 265 | { |
| 266 | INT16 nCaptureHT; |
| 267 | assert(pQData != 0 ); |
| 268 | |
| 269 | EnterCriticalSection( &pQData->cSection ); |
| 270 | nCaptureHT = pQData->nCaptureHT; |
| 271 | LeaveCriticalSection( &pQData->cSection ); |
| 272 | |
| 273 | return nCaptureHT; |
| 274 | } |
| 275 | |
| 276 | |
| 277 | /*********************************************************************** |
| 278 | * PERQDATA_SetCaptureInfo |
| 279 | * |
| 280 | * Set the capture info member in a threadsafe manner |
| 281 | */ |
| 282 | INT16 PERQDATA_SetCaptureInfo( PERQUEUEDATA *pQData, INT16 nCaptureHT ) |
| 283 | { |
| 284 | INT16 nCaptureHTPrv; |
| 285 | assert(pQData != 0 ); |
| 286 | |
| 287 | EnterCriticalSection( &pQData->cSection ); |
| 288 | nCaptureHTPrv = pQData->nCaptureHT; |
| 289 | pQData->nCaptureHT = nCaptureHT; |
| 290 | LeaveCriticalSection( &pQData->cSection ); |
| 291 | |
| 292 | return nCaptureHTPrv; |
| 293 | } |
| 294 | |
| 295 | |
| 296 | /*********************************************************************** |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 297 | * QUEUE_Lock |
| 298 | * |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 299 | * Function for getting a 32 bit pointer on queue strcture. For thread |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 300 | * safeness programmers should use this function instead of GlobalLock to |
| 301 | * retrieve a pointer on the structure. QUEUE_Unlock should also be called |
| 302 | * when access to the queue structure is not required anymore. |
| 303 | */ |
| 304 | MESSAGEQUEUE *QUEUE_Lock( HQUEUE16 hQueue ) |
| 305 | { |
| 306 | MESSAGEQUEUE *queue; |
| 307 | |
Alexandre Julliard | 34bf815 | 1999-03-21 08:36:55 +0000 | [diff] [blame] | 308 | HeapLock( SystemHeap ); /* FIXME: a bit overkill */ |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 309 | queue = GlobalLock16( hQueue ); |
| 310 | if ( !queue || (queue->magic != QUEUE_MAGIC) ) |
| 311 | { |
Alexandre Julliard | 34bf815 | 1999-03-21 08:36:55 +0000 | [diff] [blame] | 312 | HeapUnlock( SystemHeap ); |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 313 | return NULL; |
| 314 | } |
| 315 | |
| 316 | queue->lockCount++; |
Alexandre Julliard | 34bf815 | 1999-03-21 08:36:55 +0000 | [diff] [blame] | 317 | HeapUnlock( SystemHeap ); |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 318 | return queue; |
| 319 | } |
| 320 | |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 321 | |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 322 | /*********************************************************************** |
| 323 | * QUEUE_Unlock |
| 324 | * |
| 325 | * Use with QUEUE_Lock to get a thread safe acces to message queue |
| 326 | * structure |
| 327 | */ |
| 328 | void QUEUE_Unlock( MESSAGEQUEUE *queue ) |
| 329 | { |
| 330 | if (queue) |
| 331 | { |
Alexandre Julliard | 34bf815 | 1999-03-21 08:36:55 +0000 | [diff] [blame] | 332 | HeapLock( SystemHeap ); /* FIXME: a bit overkill */ |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 333 | |
| 334 | if ( --queue->lockCount == 0 ) |
| 335 | { |
| 336 | DeleteCriticalSection ( &queue->cSection ); |
Stephane Lussier | b3a99de | 1999-02-09 15:35:12 +0000 | [diff] [blame] | 337 | if (queue->hEvent) |
| 338 | CloseHandle( queue->hEvent ); |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 339 | GlobalFree16( queue->self ); |
| 340 | } |
| 341 | |
Alexandre Julliard | 34bf815 | 1999-03-21 08:36:55 +0000 | [diff] [blame] | 342 | HeapUnlock( SystemHeap ); |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 346 | |
Alexandre Julliard | e2bfa4c | 1996-05-16 18:21:06 +0000 | [diff] [blame] | 347 | /*********************************************************************** |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 348 | * QUEUE_DumpQueue |
| 349 | */ |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 350 | void QUEUE_DumpQueue( HQUEUE16 hQueue ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 351 | { |
| 352 | MESSAGEQUEUE *pq; |
| 353 | |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 354 | if (!(pq = (MESSAGEQUEUE*) QUEUE_Lock( hQueue )) ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 355 | { |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 356 | WARN(msg, "%04x is not a queue handle\n", hQueue ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 357 | return; |
| 358 | } |
| 359 | |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 360 | DUMP( "next: %12.4x Intertask SendMessage:\n" |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 361 | "thread: %10p ----------------------\n" |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 362 | "firstMsg: %8p smWaiting: %10p\n" |
| 363 | "lastMsg: %8p smPending: %10p\n" |
| 364 | "msgCount: %8.4x smProcessing: %10p\n" |
| 365 | "lockCount: %7.4x\n" |
| 366 | "wWinVer: %9.4x\n" |
| 367 | "paints: %10.4x\n" |
| 368 | "timers: %10.4x\n" |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 369 | "wakeBits: %8.4x\n" |
| 370 | "wakeMask: %8.4x\n" |
| 371 | "hCurHook: %8.4x\n", |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 372 | pq->next, pq->thdb, pq->firstMsg, pq->smWaiting, pq->lastMsg, |
| 373 | pq->smPending, pq->msgCount, pq->smProcessing, |
| 374 | (unsigned)pq->lockCount, pq->wWinVersion, |
| 375 | pq->wPaintCount, pq->wTimerCount, |
| 376 | pq->wakeBits, pq->wakeMask, pq->hCurHook); |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 377 | |
| 378 | QUEUE_Unlock( pq ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | |
| 382 | /*********************************************************************** |
| 383 | * QUEUE_WalkQueues |
| 384 | */ |
| 385 | void QUEUE_WalkQueues(void) |
| 386 | { |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 387 | char module[10]; |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 388 | HQUEUE16 hQueue = hFirstQueue; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 389 | |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 390 | DUMP( "Queue Msgs Thread Task Module\n" ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 391 | while (hQueue) |
| 392 | { |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 393 | MESSAGEQUEUE *queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 394 | if (!queue) |
| 395 | { |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 396 | WARN( msg, "Bad queue handle %04x\n", hQueue ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 397 | return; |
| 398 | } |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 399 | if (!GetModuleName16( queue->thdb->process->task, module, sizeof(module ))) |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 400 | strcpy( module, "???" ); |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 401 | DUMP( "%04x %4d %p %04x %s\n", hQueue,queue->msgCount, |
| 402 | queue->thdb, queue->thdb->process->task, module ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 403 | hQueue = queue->next; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 404 | QUEUE_Unlock( queue ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 405 | } |
Alexandre Julliard | a845b88 | 1998-06-01 10:44:35 +0000 | [diff] [blame] | 406 | DUMP( "\n" ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 407 | } |
| 408 | |
| 409 | |
| 410 | /*********************************************************************** |
Alexandre Julliard | 7ff1c41 | 1997-05-25 13:58:18 +0000 | [diff] [blame] | 411 | * QUEUE_IsExitingQueue |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 412 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 413 | BOOL QUEUE_IsExitingQueue( HQUEUE16 hQueue ) |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 414 | { |
Alexandre Julliard | 7ff1c41 | 1997-05-25 13:58:18 +0000 | [diff] [blame] | 415 | return (hExitingQueue && (hQueue == hExitingQueue)); |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | |
| 419 | /*********************************************************************** |
Alexandre Julliard | 7ff1c41 | 1997-05-25 13:58:18 +0000 | [diff] [blame] | 420 | * QUEUE_SetExitingQueue |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 421 | */ |
Alexandre Julliard | 7ff1c41 | 1997-05-25 13:58:18 +0000 | [diff] [blame] | 422 | void QUEUE_SetExitingQueue( HQUEUE16 hQueue ) |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 423 | { |
Alexandre Julliard | 7ff1c41 | 1997-05-25 13:58:18 +0000 | [diff] [blame] | 424 | hExitingQueue = hQueue; |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 425 | } |
| 426 | |
| 427 | |
| 428 | /*********************************************************************** |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 429 | * QUEUE_CreateMsgQueue |
| 430 | * |
| 431 | * Creates a message queue. Doesn't link it into queue list! |
| 432 | */ |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 433 | static HQUEUE16 QUEUE_CreateMsgQueue( BOOL16 bCreatePerQData ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 434 | { |
Alexandre Julliard | 8cc3a5e | 1996-08-11 15:49:51 +0000 | [diff] [blame] | 435 | HQUEUE16 hQueue; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 436 | MESSAGEQUEUE * msgQueue; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 437 | TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 438 | |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 439 | TRACE(msg,"(): Creating message queue...\n"); |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 440 | |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 441 | if (!(hQueue = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, |
| 442 | sizeof(MESSAGEQUEUE) ))) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 443 | return 0; |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 444 | |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 445 | msgQueue = (MESSAGEQUEUE *) GlobalLock16( hQueue ); |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 446 | if ( !msgQueue ) |
| 447 | return 0; |
| 448 | |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 449 | msgQueue->self = hQueue; |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 450 | msgQueue->wakeBits = msgQueue->changeBits = 0; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 451 | msgQueue->wWinVersion = pTask ? pTask->version : 0; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 452 | |
| 453 | InitializeCriticalSection( &msgQueue->cSection ); |
Stephane Lussier | 7798307 | 1999-02-13 12:24:04 +0000 | [diff] [blame] | 454 | MakeCriticalSectionGlobal( &msgQueue->cSection ); |
Stephane Lussier | b3a99de | 1999-02-09 15:35:12 +0000 | [diff] [blame] | 455 | |
| 456 | /* Create an Event object for waiting on message, used by win32 thread |
| 457 | only */ |
| 458 | if ( !THREAD_IsWin16( THREAD_Current() ) ) |
| 459 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 460 | msgQueue->hEvent = CreateEventA( NULL, FALSE, FALSE, NULL); |
Stephane Lussier | b3a99de | 1999-02-09 15:35:12 +0000 | [diff] [blame] | 461 | |
| 462 | if (msgQueue->hEvent == 0) |
| 463 | { |
| 464 | WARN(msg, "CreateEvent32A is not able to create an event object"); |
| 465 | return 0; |
| 466 | } |
| 467 | msgQueue->hEvent = ConvertToGlobalHandle( msgQueue->hEvent ); |
| 468 | } |
| 469 | else |
| 470 | msgQueue->hEvent = 0; |
| 471 | |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 472 | msgQueue->lockCount = 1; |
| 473 | msgQueue->magic = QUEUE_MAGIC; |
| 474 | |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 475 | /* Create and initialize our per queue data */ |
| 476 | msgQueue->pQData = bCreatePerQData ? PERQDATA_CreateInstance() : NULL; |
| 477 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 478 | return hQueue; |
| 479 | } |
| 480 | |
| 481 | |
| 482 | /*********************************************************************** |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 483 | * QUEUE_FlushMessage |
| 484 | * |
| 485 | * Try to reply to all pending sent messages on exit. |
| 486 | */ |
| 487 | void QUEUE_FlushMessages( MESSAGEQUEUE *queue ) |
| 488 | { |
| 489 | SMSG *smsg; |
| 490 | MESSAGEQUEUE *senderQ = 0; |
| 491 | |
| 492 | if( queue ) |
| 493 | { |
| 494 | EnterCriticalSection( &queue->cSection ); |
| 495 | |
| 496 | /* empty the list of pending SendMessage waiting to be received */ |
| 497 | while (queue->smPending) |
| 498 | { |
| 499 | smsg = QUEUE_RemoveSMSG( queue, SM_PENDING_LIST, 0); |
| 500 | |
| 501 | senderQ = (MESSAGEQUEUE*)QUEUE_Lock( smsg->hSrcQueue ); |
| 502 | if ( !senderQ ) |
| 503 | continue; |
| 504 | |
| 505 | /* return 0, to unblock other thread */ |
| 506 | smsg->lResult = 0; |
| 507 | smsg->flags |= SMSG_HAVE_RESULT; |
| 508 | QUEUE_SetWakeBit( senderQ, QS_SMRESULT); |
| 509 | |
| 510 | QUEUE_Unlock( senderQ ); |
| 511 | } |
| 512 | |
| 513 | QUEUE_ClearWakeBit( queue, QS_SENDMESSAGE ); |
| 514 | |
| 515 | LeaveCriticalSection( &queue->cSection ); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | |
| 520 | /*********************************************************************** |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 521 | * QUEUE_DeleteMsgQueue |
| 522 | * |
| 523 | * Unlinks and deletes a message queue. |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 524 | * |
| 525 | * Note: We need to mask asynchronous events to make sure PostMessage works |
| 526 | * even in the signal handler. |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 527 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 528 | BOOL QUEUE_DeleteMsgQueue( HQUEUE16 hQueue ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 529 | { |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 530 | MESSAGEQUEUE * msgQueue = (MESSAGEQUEUE*)QUEUE_Lock(hQueue); |
Alexandre Julliard | 18f92e7 | 1996-07-17 20:02:21 +0000 | [diff] [blame] | 531 | HQUEUE16 *pPrev; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 532 | |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 533 | TRACE(msg,"(): Deleting message queue %04x\n", hQueue); |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 534 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 535 | if (!hQueue || !msgQueue) |
| 536 | { |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 537 | WARN(msg, "invalid argument.\n"); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 538 | return 0; |
| 539 | } |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 540 | |
| 541 | msgQueue->magic = 0; |
| 542 | |
| 543 | if( hCursorQueue == hQueue ) hCursorQueue = 0; |
| 544 | if( hActiveQueue == hQueue ) hActiveQueue = 0; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 545 | |
| 546 | /* flush sent messages */ |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 547 | QUEUE_FlushMessages( msgQueue ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 548 | |
Alexandre Julliard | 34bf815 | 1999-03-21 08:36:55 +0000 | [diff] [blame] | 549 | HeapLock( SystemHeap ); /* FIXME: a bit overkill */ |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 550 | |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 551 | /* Release per queue data if present */ |
| 552 | if ( msgQueue->pQData ) |
| 553 | { |
| 554 | PERQDATA_Release( msgQueue->pQData ); |
| 555 | msgQueue->pQData = 0; |
| 556 | } |
| 557 | |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 558 | /* remove the message queue from the global link list */ |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 559 | pPrev = &hFirstQueue; |
| 560 | while (*pPrev && (*pPrev != hQueue)) |
| 561 | { |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 562 | MESSAGEQUEUE *msgQ = (MESSAGEQUEUE*)GlobalLock16(*pPrev); |
Stephane Lussier | 91bb1f9 | 1999-02-09 14:07:07 +0000 | [diff] [blame] | 563 | |
| 564 | /* sanity check */ |
| 565 | if ( !msgQ || (msgQ->magic != QUEUE_MAGIC) ) |
| 566 | { |
| 567 | /* HQUEUE link list is corrupted, try to exit gracefully */ |
| 568 | WARN( msg, "HQUEUE link list corrupted!\n"); |
| 569 | pPrev = 0; |
| 570 | break; |
| 571 | } |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 572 | pPrev = &msgQ->next; |
| 573 | } |
Stephane Lussier | 91bb1f9 | 1999-02-09 14:07:07 +0000 | [diff] [blame] | 574 | if (pPrev && *pPrev) *pPrev = msgQueue->next; |
Alexandre Julliard | 8b91563 | 1996-06-16 16:16:05 +0000 | [diff] [blame] | 575 | msgQueue->self = 0; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 576 | |
Alexandre Julliard | 34bf815 | 1999-03-21 08:36:55 +0000 | [diff] [blame] | 577 | HeapUnlock( SystemHeap ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 578 | |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 579 | /* free up resource used by MESSAGEQUEUE strcture */ |
| 580 | msgQueue->lockCount--; |
| 581 | QUEUE_Unlock( msgQueue ); |
| 582 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 583 | return 1; |
| 584 | } |
| 585 | |
| 586 | |
| 587 | /*********************************************************************** |
| 588 | * QUEUE_CreateSysMsgQueue |
| 589 | * |
| 590 | * Create the system message queue, and set the double-click speed. |
| 591 | * Must be called only once. |
| 592 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 593 | BOOL QUEUE_CreateSysMsgQueue( int size ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 594 | { |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 595 | /* Note: We dont need perQ data for the system message queue */ |
| 596 | if (!(hmemSysMsgQueue = QUEUE_CreateMsgQueue( FALSE ))) |
| 597 | return FALSE; |
| 598 | |
Alexandre Julliard | 1285c2f | 1996-05-06 16:06:24 +0000 | [diff] [blame] | 599 | sysMsgQueue = (MESSAGEQUEUE *) GlobalLock16( hmemSysMsgQueue ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 600 | return TRUE; |
| 601 | } |
| 602 | |
| 603 | |
| 604 | /*********************************************************************** |
| 605 | * QUEUE_GetSysQueue |
| 606 | */ |
| 607 | MESSAGEQUEUE *QUEUE_GetSysQueue(void) |
| 608 | { |
| 609 | return sysMsgQueue; |
| 610 | } |
| 611 | |
Alexandre Julliard | 85ed45e | 1998-08-22 19:03:56 +0000 | [diff] [blame] | 612 | |
| 613 | /*********************************************************************** |
Stephane Lussier | 91bb1f9 | 1999-02-09 14:07:07 +0000 | [diff] [blame] | 614 | * QUEUE_SetWakeBit |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 615 | * |
| 616 | * See "Windows Internals", p.449 |
| 617 | */ |
| 618 | void QUEUE_SetWakeBit( MESSAGEQUEUE *queue, WORD bit ) |
| 619 | { |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 620 | TRACE(msg,"queue = %04x (wm=%04x), bit = %04x\n", |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 621 | queue->self, queue->wakeMask, bit ); |
| 622 | |
Alexandre Julliard | 8b91563 | 1996-06-16 16:16:05 +0000 | [diff] [blame] | 623 | if (bit & QS_MOUSE) pMouseQueue = queue; |
| 624 | if (bit & QS_KEY) pKbdQueue = queue; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 625 | queue->changeBits |= bit; |
| 626 | queue->wakeBits |= bit; |
| 627 | if (queue->wakeMask & bit) |
| 628 | { |
| 629 | queue->wakeMask = 0; |
Stephane Lussier | b3a99de | 1999-02-09 15:35:12 +0000 | [diff] [blame] | 630 | |
| 631 | /* Wake up thread waiting for message */ |
| 632 | if ( THREAD_IsWin16( queue->thdb ) ) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 633 | PostEvent16( queue->thdb->process->task ); |
Stephane Lussier | b3a99de | 1999-02-09 15:35:12 +0000 | [diff] [blame] | 634 | else |
| 635 | { |
| 636 | SetEvent( queue->hEvent ); |
| 637 | } |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
| 641 | |
| 642 | /*********************************************************************** |
Alexandre Julliard | 8b91563 | 1996-06-16 16:16:05 +0000 | [diff] [blame] | 643 | * QUEUE_ClearWakeBit |
| 644 | */ |
| 645 | void QUEUE_ClearWakeBit( MESSAGEQUEUE *queue, WORD bit ) |
| 646 | { |
| 647 | queue->changeBits &= ~bit; |
| 648 | queue->wakeBits &= ~bit; |
| 649 | } |
| 650 | |
| 651 | |
| 652 | /*********************************************************************** |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 653 | * QUEUE_WaitBits |
| 654 | * |
| 655 | * See "Windows Internals", p.447 |
Stephane Lussier | bae5552 | 1999-03-10 16:21:12 +0000 | [diff] [blame] | 656 | * |
| 657 | * return values: |
| 658 | * 0 if exit with timeout |
| 659 | * 1 otherwise |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 660 | */ |
Stephane Lussier | bae5552 | 1999-03-10 16:21:12 +0000 | [diff] [blame] | 661 | int QUEUE_WaitBits( WORD bits, DWORD timeout ) |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 662 | { |
| 663 | MESSAGEQUEUE *queue; |
Stephane Lussier | bae5552 | 1999-03-10 16:21:12 +0000 | [diff] [blame] | 664 | DWORD curTime = 0; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 665 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 666 | TRACE(msg,"q %04x waiting for %04x\n", GetFastQueue16(), bits); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 667 | |
Stephane Lussier | bae5552 | 1999-03-10 16:21:12 +0000 | [diff] [blame] | 668 | if ( THREAD_IsWin16( THREAD_Current() ) && (timeout != INFINITE) ) |
| 669 | curTime = GetTickCount(); |
| 670 | |
| 671 | if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0; |
| 672 | |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 673 | for (;;) |
| 674 | { |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 675 | if (queue->changeBits & bits) |
| 676 | { |
| 677 | /* One of the bits is set; we can return */ |
| 678 | queue->wakeMask = 0; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 679 | QUEUE_Unlock( queue ); |
Stephane Lussier | bae5552 | 1999-03-10 16:21:12 +0000 | [diff] [blame] | 680 | return 1; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 681 | } |
| 682 | if (queue->wakeBits & QS_SENDMESSAGE) |
| 683 | { |
| 684 | /* Process the sent message immediately */ |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 685 | |
| 686 | queue->wakeMask = 0; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 687 | QUEUE_ReceiveMessage( queue ); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 688 | continue; /* nested sm crux */ |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 689 | } |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 690 | |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 691 | queue->wakeMask = bits | QS_SENDMESSAGE; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 692 | if(queue->changeBits & bits) |
| 693 | { |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 694 | continue; |
| 695 | } |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 696 | |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 697 | TRACE(msg,"%04x) wakeMask is %04x, waiting\n", queue->self, queue->wakeMask); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 698 | |
Stephane Lussier | bae5552 | 1999-03-10 16:21:12 +0000 | [diff] [blame] | 699 | if ( !THREAD_IsWin16( THREAD_Current() ) ) |
| 700 | { |
| 701 | /* win32 thread, use WaitForMultipleObjects */ |
| 702 | MsgWaitForMultipleObjects( 0, NULL, FALSE, timeout, queue->wakeMask ); |
| 703 | } |
| 704 | else |
| 705 | { |
| 706 | if ( timeout == INFINITE ) |
| 707 | WaitEvent16( 0 ); /* win 16 thread, use WaitEvent */ |
| 708 | else |
| 709 | { |
| 710 | /* check for timeout, then give control to other tasks */ |
| 711 | if (GetTickCount() - curTime > timeout) |
| 712 | { |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 713 | |
| 714 | QUEUE_Unlock( queue ); |
Stephane Lussier | bae5552 | 1999-03-10 16:21:12 +0000 | [diff] [blame] | 715 | return 0; /* exit with timeout */ |
| 716 | } |
| 717 | Yield16(); |
| 718 | } |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 719 | } |
| 720 | } |
Stephane Lussier | bae5552 | 1999-03-10 16:21:12 +0000 | [diff] [blame] | 721 | } |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 722 | |
| 723 | |
| 724 | /*********************************************************************** |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 725 | * QUEUE_AddSMSG |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 726 | * |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 727 | * This routine is called when a SMSG need to be added to one of the three |
| 728 | * SM list. (SM_PROCESSING_LIST, SM_PENDING_LIST, SM_WAITING_LIST) |
| 729 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 730 | BOOL QUEUE_AddSMSG( MESSAGEQUEUE *queue, int list, SMSG *smsg ) |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 731 | { |
| 732 | TRACE(sendmsg,"queue=%x, list=%d, smsg=%p msg=%s\n", queue->self, list, |
| 733 | smsg, SPY_GetMsgName(smsg->msg)); |
| 734 | |
| 735 | switch (list) |
| 736 | { |
| 737 | case SM_PROCESSING_LIST: |
| 738 | /* don't need to be thread safe, only accessed by the |
| 739 | thread associated with the sender queue */ |
| 740 | smsg->nextProcessing = queue->smProcessing; |
| 741 | queue->smProcessing = smsg; |
| 742 | break; |
| 743 | |
| 744 | case SM_WAITING_LIST: |
| 745 | /* don't need to be thread safe, only accessed by the |
| 746 | thread associated with the receiver queue */ |
| 747 | smsg->nextWaiting = queue->smWaiting; |
| 748 | queue->smWaiting = smsg; |
| 749 | break; |
| 750 | |
| 751 | case SM_PENDING_LIST: |
Ulrich Weigand | c68c4b1 | 1999-03-17 15:14:31 +0000 | [diff] [blame] | 752 | { |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 753 | /* make it thread safe, could be accessed by the sender and |
| 754 | receiver thread */ |
Ulrich Weigand | c68c4b1 | 1999-03-17 15:14:31 +0000 | [diff] [blame] | 755 | SMSG **prev; |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 756 | |
| 757 | EnterCriticalSection( &queue->cSection ); |
Ulrich Weigand | c68c4b1 | 1999-03-17 15:14:31 +0000 | [diff] [blame] | 758 | smsg->nextPending = NULL; |
| 759 | prev = &queue->smPending; |
| 760 | while ( *prev ) |
| 761 | prev = &(*prev)->nextPending; |
| 762 | *prev = smsg; |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 763 | LeaveCriticalSection( &queue->cSection ); |
Ulrich Weigand | c68c4b1 | 1999-03-17 15:14:31 +0000 | [diff] [blame] | 764 | |
| 765 | QUEUE_SetWakeBit( queue, QS_SENDMESSAGE ); |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 766 | break; |
Ulrich Weigand | c68c4b1 | 1999-03-17 15:14:31 +0000 | [diff] [blame] | 767 | } |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 768 | |
| 769 | default: |
| 770 | WARN(sendmsg, "Invalid list: %d", list); |
| 771 | break; |
| 772 | } |
| 773 | |
| 774 | return TRUE; |
| 775 | } |
| 776 | |
| 777 | |
| 778 | /*********************************************************************** |
| 779 | * QUEUE_RemoveSMSG |
| 780 | * |
| 781 | * This routine is called when a SMSG need to be remove from one of the three |
| 782 | * SM list. (SM_PROCESSING_LIST, SM_PENDING_LIST, SM_WAITING_LIST) |
| 783 | * If smsg == 0, remove the first smsg from the specified list |
| 784 | */ |
| 785 | SMSG *QUEUE_RemoveSMSG( MESSAGEQUEUE *queue, int list, SMSG *smsg ) |
| 786 | { |
| 787 | |
| 788 | switch (list) |
| 789 | { |
| 790 | case SM_PROCESSING_LIST: |
| 791 | /* don't need to be thread safe, only accessed by the |
| 792 | thread associated with the sender queue */ |
| 793 | |
| 794 | /* if smsg is equal to null, it means the first in the list */ |
| 795 | if (!smsg) |
| 796 | smsg = queue->smProcessing; |
| 797 | |
| 798 | TRACE(sendmsg,"queue=%x, list=%d, smsg=%p msg=%s\n", queue->self, list, |
| 799 | smsg, SPY_GetMsgName(smsg->msg)); |
| 800 | /* In fact SM_PROCESSING_LIST is a stack, and smsg |
| 801 | should be always at the top of the list */ |
| 802 | if ( (smsg != queue->smProcessing) || !queue->smProcessing ) |
| 803 | { |
| 804 | ERR( sendmsg, "smsg not at the top of Processing list, smsg=0x%p queue=0x%p", smsg, queue); |
| 805 | return 0; |
| 806 | } |
| 807 | else |
| 808 | { |
| 809 | queue->smProcessing = smsg->nextProcessing; |
| 810 | smsg->nextProcessing = 0; |
| 811 | } |
| 812 | return smsg; |
| 813 | |
| 814 | case SM_WAITING_LIST: |
| 815 | /* don't need to be thread safe, only accessed by the |
| 816 | thread associated with the receiver queue */ |
| 817 | |
| 818 | /* if smsg is equal to null, it means the first in the list */ |
| 819 | if (!smsg) |
| 820 | smsg = queue->smWaiting; |
| 821 | |
| 822 | TRACE(sendmsg,"queue=%x, list=%d, smsg=%p msg=%s\n", queue->self, list, |
| 823 | smsg, SPY_GetMsgName(smsg->msg)); |
| 824 | /* In fact SM_WAITING_LIST is a stack, and smsg |
| 825 | should be always at the top of the list */ |
| 826 | if ( (smsg != queue->smWaiting) || !queue->smWaiting ) |
| 827 | { |
| 828 | ERR( sendmsg, "smsg not at the top of Waiting list, smsg=0x%p queue=0x%p", smsg, queue); |
| 829 | return 0; |
| 830 | } |
| 831 | else |
| 832 | { |
| 833 | queue->smWaiting = smsg->nextWaiting; |
| 834 | smsg->nextWaiting = 0; |
| 835 | } |
| 836 | return smsg; |
| 837 | |
| 838 | case SM_PENDING_LIST: |
| 839 | /* make it thread safe, could be accessed by the sender and |
| 840 | receiver thread */ |
| 841 | EnterCriticalSection( &queue->cSection ); |
| 842 | |
| 843 | if (!smsg || !queue->smPending) |
| 844 | smsg = queue->smPending; |
| 845 | else |
| 846 | { |
| 847 | ERR( sendmsg, "should always remove the top one in Pending list, smsg=0x%p queue=0x%p", smsg, queue); |
| 848 | return 0; |
| 849 | } |
| 850 | |
| 851 | TRACE(sendmsg,"queue=%x, list=%d, smsg=%p msg=%s\n", queue->self, list, |
| 852 | smsg, SPY_GetMsgName(smsg->msg)); |
| 853 | |
| 854 | queue->smPending = smsg->nextPending; |
| 855 | smsg->nextPending = 0; |
| 856 | |
| 857 | /* if no more SMSG in Pending list, clear QS_SENDMESSAGE flag */ |
| 858 | if (!queue->smPending) |
| 859 | QUEUE_ClearWakeBit( queue, QS_SENDMESSAGE ); |
| 860 | |
| 861 | LeaveCriticalSection( &queue->cSection ); |
| 862 | return smsg; |
| 863 | |
| 864 | default: |
| 865 | WARN(sendmsg, "Invalid list: %d", list); |
| 866 | break; |
| 867 | } |
| 868 | |
| 869 | return 0; |
| 870 | } |
| 871 | |
| 872 | |
| 873 | /*********************************************************************** |
| 874 | * QUEUE_ReceiveMessage |
| 875 | * |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 876 | * This routine is called when a sent message is waiting for the queue. |
| 877 | */ |
| 878 | void QUEUE_ReceiveMessage( MESSAGEQUEUE *queue ) |
| 879 | { |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 880 | LRESULT result = 0; |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 881 | SMSG *smsg; |
| 882 | MESSAGEQUEUE *senderQ; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 883 | |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 884 | TRACE(sendmsg, "queue %04x\n", queue->self ); |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 885 | |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 886 | if ( !(queue->wakeBits & QS_SENDMESSAGE) && queue->smPending ) |
Alexandre Julliard | 8b91563 | 1996-06-16 16:16:05 +0000 | [diff] [blame] | 887 | { |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 888 | TRACE(sendmsg,"\trcm: nothing to do\n"); |
| 889 | return; |
| 890 | } |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 891 | |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 892 | /* remove smsg on the top of the pending list and put it in the processing list */ |
| 893 | smsg = QUEUE_RemoveSMSG(queue, SM_PENDING_LIST, 0); |
| 894 | QUEUE_AddSMSG(queue, SM_WAITING_LIST, smsg); |
| 895 | |
| 896 | TRACE(sendmsg,"RM: %s [%04x] (%04x -> %04x)\n", |
| 897 | SPY_GetMsgName(smsg->msg), smsg->msg, smsg->hSrcQueue, smsg->hDstQueue ); |
| 898 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 899 | if (IsWindow( smsg->hWnd )) |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 900 | { |
| 901 | WND *wndPtr = WIN_FindWndPtr( smsg->hWnd ); |
| 902 | DWORD extraInfo = queue->GetMessageExtraInfoVal; /* save ExtraInfo */ |
| 903 | |
| 904 | /* use sender queue extra info value while calling the window proc */ |
| 905 | senderQ = (MESSAGEQUEUE*)QUEUE_Lock( smsg->hSrcQueue ); |
| 906 | if (senderQ) |
| 907 | { |
| 908 | queue->GetMessageExtraInfoVal = senderQ->GetMessageExtraInfoVal; |
| 909 | QUEUE_Unlock( senderQ ); |
| 910 | } |
| 911 | |
| 912 | /* call the right version of CallWindowProcXX */ |
| 913 | if (smsg->flags & SMSG_WIN32) |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 914 | { |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 915 | TRACE(sendmsg, "\trcm: msg is Win32\n" ); |
| 916 | if (smsg->flags & SMSG_UNICODE) |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 917 | result = CallWindowProcW( wndPtr->winproc, |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 918 | smsg->hWnd, smsg->msg, |
| 919 | smsg->wParam, smsg->lParam ); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 920 | else |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 921 | result = CallWindowProcA( wndPtr->winproc, |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 922 | smsg->hWnd, smsg->msg, |
| 923 | smsg->wParam, smsg->lParam ); |
Alexandre Julliard | d37eb36 | 1997-07-20 16:23:21 +0000 | [diff] [blame] | 924 | } |
| 925 | else /* Win16 message */ |
| 926 | result = CallWindowProc16( (WNDPROC16)wndPtr->winproc, |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 927 | (HWND16) smsg->hWnd, |
| 928 | (UINT16) smsg->msg, |
| 929 | LOWORD (smsg->wParam), |
| 930 | smsg->lParam ); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 931 | |
| 932 | queue->GetMessageExtraInfoVal = extraInfo; /* Restore extra info */ |
Francois Boisvert | 6b1b41c | 1999-03-14 17:25:32 +0000 | [diff] [blame] | 933 | WIN_ReleaseWndPtr(wndPtr); |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 934 | TRACE(sendmsg,"result = %08x\n", (unsigned)result ); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 935 | } |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 936 | else WARN(sendmsg, "\trcm: bad hWnd\n"); |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 937 | |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 938 | |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 939 | /* set SMSG_SENDING_REPLY flag to tell ReplyMessage16, it's not |
| 940 | an early reply */ |
| 941 | smsg->flags |= SMSG_SENDING_REPLY; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 942 | ReplyMessage( result ); |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 943 | |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 944 | TRACE( sendmsg,"done! \n" ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 945 | } |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 946 | |
Stephane Lussier | 2c86dab | 1999-02-18 17:34:09 +0000 | [diff] [blame] | 947 | |
| 948 | |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 949 | /*********************************************************************** |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 950 | * QUEUE_AddMsg |
| 951 | * |
| 952 | * Add a message to the queue. Return FALSE if queue is full. |
| 953 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 954 | BOOL QUEUE_AddMsg( HQUEUE16 hQueue, MSG *msg, DWORD extraInfo ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 955 | { |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 956 | MESSAGEQUEUE *msgQueue; |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 957 | QMSG *qmsg; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 958 | |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 959 | |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 960 | if (!(msgQueue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue ))) return FALSE; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 961 | |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 962 | /* allocate new message in global heap for now */ |
| 963 | if (!(qmsg = (QMSG *) HeapAlloc( SystemHeap, 0, sizeof(QMSG) ) )) |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 964 | { |
| 965 | QUEUE_Unlock( msgQueue ); |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 966 | return 0; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 967 | } |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 968 | |
| 969 | EnterCriticalSection( &msgQueue->cSection ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 970 | |
| 971 | /* Store message */ |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 972 | qmsg->msg = *msg; |
| 973 | qmsg->extraInfo = extraInfo; |
| 974 | |
| 975 | /* insert the message in the link list */ |
| 976 | qmsg->nextMsg = 0; |
| 977 | qmsg->prevMsg = msgQueue->lastMsg; |
| 978 | |
| 979 | if (msgQueue->lastMsg) |
| 980 | msgQueue->lastMsg->nextMsg = qmsg; |
| 981 | |
| 982 | /* update first and last anchor in message queue */ |
| 983 | msgQueue->lastMsg = qmsg; |
| 984 | if (!msgQueue->firstMsg) |
| 985 | msgQueue->firstMsg = qmsg; |
| 986 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 987 | msgQueue->msgCount++; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 988 | |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 989 | LeaveCriticalSection( &msgQueue->cSection ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 990 | |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 991 | QUEUE_SetWakeBit( msgQueue, QS_POSTMESSAGE ); |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 992 | QUEUE_Unlock( msgQueue ); |
| 993 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 994 | return TRUE; |
| 995 | } |
| 996 | |
| 997 | |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 998 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 999 | /*********************************************************************** |
| 1000 | * QUEUE_FindMsg |
| 1001 | * |
| 1002 | * Find a message matching the given parameters. Return -1 if none available. |
| 1003 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1004 | QMSG* QUEUE_FindMsg( MESSAGEQUEUE * msgQueue, HWND hwnd, int first, int last ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1005 | { |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1006 | QMSG* qmsg; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1007 | |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1008 | EnterCriticalSection( &msgQueue->cSection ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1009 | |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1010 | if (!msgQueue->msgCount) |
| 1011 | qmsg = 0; |
| 1012 | else if (!hwnd && !first && !last) |
| 1013 | qmsg = msgQueue->firstMsg; |
| 1014 | else |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1015 | { |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1016 | /* look in linked list for message matching first and last criteria */ |
| 1017 | for (qmsg = msgQueue->firstMsg; qmsg; qmsg = qmsg->nextMsg) |
| 1018 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1019 | MSG *msg = &(qmsg->msg); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1020 | |
| 1021 | if (!hwnd || (msg->hwnd == hwnd)) |
| 1022 | { |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1023 | if (!first && !last) |
| 1024 | break; /* found it */ |
| 1025 | |
Martin Walker | 4d1d359 | 1999-02-19 16:50:24 +0000 | [diff] [blame] | 1026 | if ((msg->message >= first) && (!last || (msg->message <= last))) |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1027 | break; /* found it */ |
| 1028 | } |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1029 | } |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1030 | } |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1031 | |
| 1032 | LeaveCriticalSection( &msgQueue->cSection ); |
| 1033 | |
| 1034 | return qmsg; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1038 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1039 | /*********************************************************************** |
| 1040 | * QUEUE_RemoveMsg |
| 1041 | * |
| 1042 | * Remove a message from the queue (pos must be a valid position). |
| 1043 | */ |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1044 | void QUEUE_RemoveMsg( MESSAGEQUEUE * msgQueue, QMSG *qmsg ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1045 | { |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1046 | EnterCriticalSection( &msgQueue->cSection ); |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1047 | |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1048 | /* set the linked list */ |
| 1049 | if (qmsg->prevMsg) |
| 1050 | qmsg->prevMsg->nextMsg = qmsg->nextMsg; |
| 1051 | |
| 1052 | if (qmsg->nextMsg) |
| 1053 | qmsg->nextMsg->prevMsg = qmsg->prevMsg; |
| 1054 | |
| 1055 | if (msgQueue->firstMsg == qmsg) |
| 1056 | msgQueue->firstMsg = qmsg->nextMsg; |
| 1057 | |
| 1058 | if (msgQueue->lastMsg == qmsg) |
| 1059 | msgQueue->lastMsg = qmsg->prevMsg; |
| 1060 | |
| 1061 | /* deallocate the memory for the message */ |
| 1062 | HeapFree( SystemHeap, 0, qmsg ); |
| 1063 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1064 | msgQueue->msgCount--; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 1065 | if (!msgQueue->msgCount) msgQueue->wakeBits &= ~QS_POSTMESSAGE; |
Alexandre Julliard | da0cfb3 | 1996-12-01 17:17:47 +0000 | [diff] [blame] | 1066 | |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1067 | LeaveCriticalSection( &msgQueue->cSection ); |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | |
| 1071 | /*********************************************************************** |
| 1072 | * QUEUE_WakeSomeone |
| 1073 | * |
| 1074 | * Wake a queue upon reception of a hardware event. |
| 1075 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1076 | static void QUEUE_WakeSomeone( UINT message ) |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 1077 | { |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1078 | WND* wndPtr = NULL; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1079 | WORD wakeBit; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1080 | HWND hwnd; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1081 | HQUEUE16 hQueue = 0; |
| 1082 | MESSAGEQUEUE *queue = NULL; |
| 1083 | |
| 1084 | if (hCursorQueue) |
| 1085 | hQueue = hCursorQueue; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 1086 | |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1087 | if( (message >= WM_KEYFIRST) && (message <= WM_KEYLAST) ) |
| 1088 | { |
| 1089 | wakeBit = QS_KEY; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1090 | if( hActiveQueue ) |
| 1091 | hQueue = hActiveQueue; |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1092 | } |
| 1093 | else |
| 1094 | { |
| 1095 | wakeBit = (message == WM_MOUSEMOVE) ? QS_MOUSEMOVE : QS_MOUSEBUTTON; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1096 | if( (hwnd = GetCapture()) ) |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1097 | if( (wndPtr = WIN_FindWndPtr( hwnd )) ) |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1098 | { |
| 1099 | hQueue = wndPtr->hmemTaskQ; |
Francois Boisvert | 6b1b41c | 1999-03-14 17:25:32 +0000 | [diff] [blame] | 1100 | WIN_ReleaseWndPtr(wndPtr); |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1101 | } |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1102 | } |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 1103 | |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1104 | if( (hwnd = GetSysModalWindow16()) ) |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1105 | { |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1106 | if( (wndPtr = WIN_FindWndPtr( hwnd )) ) |
Francois Boisvert | 6b1b41c | 1999-03-14 17:25:32 +0000 | [diff] [blame] | 1107 | { |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1108 | hQueue = wndPtr->hmemTaskQ; |
Francois Boisvert | 6b1b41c | 1999-03-14 17:25:32 +0000 | [diff] [blame] | 1109 | WIN_ReleaseWndPtr(wndPtr); |
| 1110 | } |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1111 | } |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1112 | |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1113 | if (hQueue) |
| 1114 | queue = QUEUE_Lock( hQueue ); |
| 1115 | |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1116 | if( !queue ) |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 1117 | { |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1118 | queue = QUEUE_Lock( hFirstQueue ); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1119 | while( queue ) |
| 1120 | { |
| 1121 | if (queue->wakeMask & wakeBit) break; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1122 | |
| 1123 | QUEUE_Unlock(queue); |
| 1124 | queue = QUEUE_Lock( queue->next ); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1125 | } |
| 1126 | if( !queue ) |
| 1127 | { |
Alexandre Julliard | a69b88b | 1998-03-15 20:29:56 +0000 | [diff] [blame] | 1128 | WARN(msg, "couldn't find queue\n"); |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1129 | return; |
| 1130 | } |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 1131 | } |
Alexandre Julliard | 2c69f6d | 1996-09-28 18:11:01 +0000 | [diff] [blame] | 1132 | |
| 1133 | QUEUE_SetWakeBit( queue, wakeBit ); |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1134 | |
| 1135 | QUEUE_Unlock( queue ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1136 | } |
| 1137 | |
| 1138 | |
| 1139 | /*********************************************************************** |
| 1140 | * hardware_event |
| 1141 | * |
| 1142 | * Add an event to the system message queue. |
| 1143 | * Note: the position is relative to the desktop window. |
| 1144 | */ |
| 1145 | void hardware_event( WORD message, WORD wParam, LONG lParam, |
| 1146 | int xPos, int yPos, DWORD time, DWORD extraInfo ) |
| 1147 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1148 | MSG *msg; |
Ulrich Weigand | 831560c | 1999-03-28 13:10:54 +0000 | [diff] [blame] | 1149 | QMSG *qmsg; |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1150 | int mergeMsg = 0; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 1151 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1152 | if (!sysMsgQueue) return; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1153 | |
Ulrich Weigand | 831560c | 1999-03-28 13:10:54 +0000 | [diff] [blame] | 1154 | EnterCriticalSection( &sysMsgQueue->cSection ); |
| 1155 | |
| 1156 | /* Merge with previous event if possible */ |
| 1157 | qmsg = sysMsgQueue->lastMsg; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1158 | |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1159 | if ((message == WM_MOUSEMOVE) && sysMsgQueue->lastMsg) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1160 | { |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1161 | msg = &(sysMsgQueue->lastMsg->msg); |
| 1162 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1163 | if ((msg->message == message) && (msg->wParam == wParam)) |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1164 | { |
| 1165 | /* Merge events */ |
| 1166 | qmsg = sysMsgQueue->lastMsg; |
| 1167 | mergeMsg = 1; |
| 1168 | } |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1171 | if (!mergeMsg) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1172 | { |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1173 | /* Should I limit the number of message in |
| 1174 | the system message queue??? */ |
| 1175 | |
| 1176 | /* Don't merge allocate a new msg in the global heap */ |
| 1177 | |
| 1178 | if (!(qmsg = (QMSG *) HeapAlloc( SystemHeap, 0, sizeof(QMSG) ) )) |
Ulrich Weigand | 831560c | 1999-03-28 13:10:54 +0000 | [diff] [blame] | 1179 | { |
| 1180 | LeaveCriticalSection( &sysMsgQueue->cSection ); |
| 1181 | return; |
| 1182 | } |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1183 | |
| 1184 | /* put message at the end of the linked list */ |
| 1185 | qmsg->nextMsg = 0; |
| 1186 | qmsg->prevMsg = sysMsgQueue->lastMsg; |
| 1187 | |
| 1188 | if (sysMsgQueue->lastMsg) |
| 1189 | sysMsgQueue->lastMsg->nextMsg = qmsg; |
| 1190 | |
| 1191 | /* set last and first anchor index in system message queue */ |
| 1192 | sysMsgQueue->lastMsg = qmsg; |
| 1193 | if (!sysMsgQueue->firstMsg) |
| 1194 | sysMsgQueue->firstMsg = qmsg; |
| 1195 | |
| 1196 | sysMsgQueue->msgCount++; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
| 1199 | /* Store message */ |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1200 | msg = &(qmsg->msg); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1201 | msg->hwnd = 0; |
| 1202 | msg->message = message; |
| 1203 | msg->wParam = wParam; |
| 1204 | msg->lParam = lParam; |
| 1205 | msg->time = time; |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1206 | msg->pt.x = xPos; |
| 1207 | msg->pt.y = yPos; |
| 1208 | qmsg->extraInfo = extraInfo; |
| 1209 | |
Ulrich Weigand | 831560c | 1999-03-28 13:10:54 +0000 | [diff] [blame] | 1210 | LeaveCriticalSection( &sysMsgQueue->cSection ); |
| 1211 | |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 1212 | QUEUE_WakeSomeone( message ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1213 | } |
| 1214 | |
| 1215 | |
| 1216 | /*********************************************************************** |
| 1217 | * QUEUE_GetQueueTask |
| 1218 | */ |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1219 | HTASK16 QUEUE_GetQueueTask( HQUEUE16 hQueue ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1220 | { |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1221 | HTASK16 hTask = 0; |
| 1222 | |
| 1223 | MESSAGEQUEUE *queue = QUEUE_Lock( hQueue ); |
| 1224 | |
| 1225 | if (queue) |
| 1226 | { |
| 1227 | hTask = queue->thdb->process->task; |
| 1228 | QUEUE_Unlock( queue ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1229 | } |
| 1230 | |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1231 | return hTask; |
| 1232 | } |
| 1233 | |
| 1234 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1235 | |
| 1236 | /*********************************************************************** |
| 1237 | * QUEUE_IncPaintCount |
| 1238 | */ |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1239 | void QUEUE_IncPaintCount( HQUEUE16 hQueue ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1240 | { |
| 1241 | MESSAGEQUEUE *queue; |
| 1242 | |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1243 | if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue ))) return; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1244 | queue->wPaintCount++; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 1245 | QUEUE_SetWakeBit( queue, QS_PAINT ); |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1246 | QUEUE_Unlock( queue ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1247 | } |
| 1248 | |
| 1249 | |
| 1250 | /*********************************************************************** |
| 1251 | * QUEUE_DecPaintCount |
| 1252 | */ |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1253 | void QUEUE_DecPaintCount( HQUEUE16 hQueue ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1254 | { |
| 1255 | MESSAGEQUEUE *queue; |
| 1256 | |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1257 | if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue ))) return; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1258 | queue->wPaintCount--; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 1259 | if (!queue->wPaintCount) queue->wakeBits &= ~QS_PAINT; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1260 | QUEUE_Unlock( queue ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | |
| 1264 | /*********************************************************************** |
| 1265 | * QUEUE_IncTimerCount |
| 1266 | */ |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1267 | void QUEUE_IncTimerCount( HQUEUE16 hQueue ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1268 | { |
| 1269 | MESSAGEQUEUE *queue; |
| 1270 | |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1271 | if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue ))) return; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1272 | queue->wTimerCount++; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 1273 | QUEUE_SetWakeBit( queue, QS_TIMER ); |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1274 | QUEUE_Unlock( queue ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1275 | } |
| 1276 | |
| 1277 | |
| 1278 | /*********************************************************************** |
| 1279 | * QUEUE_DecTimerCount |
| 1280 | */ |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1281 | void QUEUE_DecTimerCount( HQUEUE16 hQueue ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1282 | { |
| 1283 | MESSAGEQUEUE *queue; |
| 1284 | |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1285 | if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( hQueue ))) return; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1286 | queue->wTimerCount--; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 1287 | if (!queue->wTimerCount) queue->wakeBits &= ~QS_TIMER; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1288 | QUEUE_Unlock( queue ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1289 | } |
| 1290 | |
| 1291 | |
| 1292 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1293 | * PostQuitMessage16 (USER.6) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1294 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1295 | void WINAPI PostQuitMessage16( INT16 exitCode ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1296 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1297 | PostQuitMessage( exitCode ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | |
| 1301 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 1302 | * PostQuitMessage32 (USER32.421) |
Douglas Ridgway | efaa573 | 1998-10-25 09:20:30 +0000 | [diff] [blame] | 1303 | * |
| 1304 | * PostQuitMessage() posts a message to the system requesting an |
| 1305 | * application to terminate execution. As a result of this function, |
| 1306 | * the WM_QUIT message is posted to the application, and |
| 1307 | * PostQuitMessage() returns immediately. The exitCode parameter |
| 1308 | * specifies an application-defined exit code, which appears in the |
| 1309 | * _wParam_ parameter of the WM_QUIT message posted to the application. |
| 1310 | * |
| 1311 | * CONFORMANCE |
| 1312 | * |
| 1313 | * ECMA-234, Win32 |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1314 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1315 | void WINAPI PostQuitMessage( INT exitCode ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1316 | { |
| 1317 | MESSAGEQUEUE *queue; |
| 1318 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1319 | if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1320 | queue->wPostQMsg = TRUE; |
| 1321 | queue->wExitCode = (WORD)exitCode; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1322 | QUEUE_Unlock( queue ); |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
| 1325 | |
| 1326 | /*********************************************************************** |
Alexandre Julliard | ca22b33 | 1996-07-12 19:02:39 +0000 | [diff] [blame] | 1327 | * GetWindowTask16 (USER.224) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1328 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1329 | HTASK16 WINAPI GetWindowTask16( HWND16 hwnd ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1330 | { |
Francois Boisvert | 6b1b41c | 1999-03-14 17:25:32 +0000 | [diff] [blame] | 1331 | HTASK16 retvalue; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1332 | WND *wndPtr = WIN_FindWndPtr( hwnd ); |
| 1333 | |
| 1334 | if (!wndPtr) return 0; |
Francois Boisvert | 6b1b41c | 1999-03-14 17:25:32 +0000 | [diff] [blame] | 1335 | retvalue = QUEUE_GetQueueTask( wndPtr->hmemTaskQ ); |
| 1336 | WIN_ReleaseWndPtr(wndPtr); |
| 1337 | return retvalue; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1338 | } |
| 1339 | |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 1340 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 1341 | * GetWindowThreadProcessId (USER32.313) |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 1342 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1343 | DWORD WINAPI GetWindowThreadProcessId( HWND hwnd, LPDWORD process ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1344 | { |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 1345 | HTASK16 htask; |
| 1346 | TDB *tdb; |
| 1347 | |
| 1348 | WND *wndPtr = WIN_FindWndPtr( hwnd ); |
| 1349 | |
| 1350 | if (!wndPtr) return 0; |
| 1351 | htask=QUEUE_GetQueueTask( wndPtr->hmemTaskQ ); |
Francois Boisvert | 6b1b41c | 1999-03-14 17:25:32 +0000 | [diff] [blame] | 1352 | WIN_ReleaseWndPtr(wndPtr); |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 1353 | tdb = (TDB*)GlobalLock16(htask); |
Alexandre Julliard | 60ce85c | 1998-02-01 18:33:27 +0000 | [diff] [blame] | 1354 | if (!tdb || !tdb->thdb) return 0; |
Alexandre Julliard | 8feb3bc | 1999-02-28 12:25:03 +0000 | [diff] [blame] | 1355 | if (process) *process = (DWORD)tdb->thdb->process->server_pid; |
Marcus Meissner | 88e651d | 1999-03-13 18:20:26 +0000 | [diff] [blame] | 1356 | return (DWORD)tdb->thdb->server_tid; |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 1357 | } |
| 1358 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1359 | |
| 1360 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1361 | * SetMessageQueue16 (USER.266) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1362 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1363 | BOOL16 WINAPI SetMessageQueue16( INT16 size ) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1364 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1365 | return SetMessageQueue( size ); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | |
| 1369 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 1370 | * SetMessageQueue32 (USER32.494) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1371 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1372 | BOOL WINAPI SetMessageQueue( INT size ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1373 | { |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1374 | /* now obsolete the message queue will be expanded dynamically |
| 1375 | as necessary */ |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1376 | |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1377 | /* access the queue to create it if it's not existing */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1378 | GetFastQueue16(); |
Alexandre Julliard | 2ace16a | 1996-04-28 15:09:19 +0000 | [diff] [blame] | 1379 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1380 | return TRUE; |
| 1381 | } |
| 1382 | |
Ulrich Weigand | 89b93bf | 1998-12-24 15:15:00 +0000 | [diff] [blame] | 1383 | /*********************************************************************** |
| 1384 | * InitThreadInput (USER.409) |
| 1385 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1386 | HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags ) |
Ulrich Weigand | 89b93bf | 1998-12-24 15:15:00 +0000 | [diff] [blame] | 1387 | { |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1388 | HQUEUE16 hQueue; |
| 1389 | MESSAGEQUEUE *queuePtr; |
| 1390 | |
| 1391 | THDB *thdb = THREAD_Current(); |
| 1392 | |
| 1393 | if (!thdb) |
| 1394 | return 0; |
| 1395 | |
| 1396 | hQueue = thdb->teb.queue; |
| 1397 | |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 1398 | if ( !hQueue ) |
| 1399 | { |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1400 | /* Create thread message queue */ |
Noel Borthwick | b427856 | 1999-02-05 10:37:53 +0000 | [diff] [blame] | 1401 | if( !(hQueue = QUEUE_CreateMsgQueue( TRUE ))) |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1402 | { |
| 1403 | WARN(msg, "failed!\n"); |
| 1404 | return FALSE; |
| 1405 | } |
| 1406 | |
| 1407 | /* Link new queue into list */ |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1408 | queuePtr = (MESSAGEQUEUE *)QUEUE_Lock( hQueue ); |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1409 | queuePtr->thdb = THREAD_Current(); |
| 1410 | |
Alexandre Julliard | 34bf815 | 1999-03-21 08:36:55 +0000 | [diff] [blame] | 1411 | HeapLock( SystemHeap ); /* FIXME: a bit overkill */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1412 | SetThreadQueue16( 0, hQueue ); |
Stephane Lussier | a4c8445 | 1999-01-26 09:30:05 +0000 | [diff] [blame] | 1413 | thdb->teb.queue = hQueue; |
| 1414 | |
| 1415 | queuePtr->next = hFirstQueue; |
| 1416 | hFirstQueue = hQueue; |
Alexandre Julliard | 34bf815 | 1999-03-21 08:36:55 +0000 | [diff] [blame] | 1417 | HeapUnlock( SystemHeap ); |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1418 | |
| 1419 | QUEUE_Unlock( queuePtr ); |
Alexandre Julliard | 638f169 | 1999-01-17 16:32:32 +0000 | [diff] [blame] | 1420 | } |
Ulrich Weigand | 89b93bf | 1998-12-24 15:15:00 +0000 | [diff] [blame] | 1421 | |
Ulrich Weigand | 89b93bf | 1998-12-24 15:15:00 +0000 | [diff] [blame] | 1422 | return hQueue; |
| 1423 | } |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1424 | |
| 1425 | /*********************************************************************** |
Alexandre Julliard | 2197901 | 1997-03-05 08:22:35 +0000 | [diff] [blame] | 1426 | * GetQueueStatus16 (USER.334) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1427 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1428 | DWORD WINAPI GetQueueStatus16( UINT16 flags ) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1429 | { |
| 1430 | MESSAGEQUEUE *queue; |
| 1431 | DWORD ret; |
| 1432 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1433 | if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0; |
Alexandre Julliard | ef702d8 | 1996-05-28 18:54:58 +0000 | [diff] [blame] | 1434 | ret = MAKELONG( queue->changeBits, queue->wakeBits ); |
| 1435 | queue->changeBits = 0; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1436 | QUEUE_Unlock( queue ); |
| 1437 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1438 | return ret & MAKELONG( flags, flags ); |
| 1439 | } |
| 1440 | |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 1441 | /*********************************************************************** |
| 1442 | * GetQueueStatus32 (USER32.283) |
| 1443 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1444 | DWORD WINAPI GetQueueStatus( UINT flags ) |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 1445 | { |
| 1446 | MESSAGEQUEUE *queue; |
| 1447 | DWORD ret; |
| 1448 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1449 | if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0; |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 1450 | ret = MAKELONG( queue->changeBits, queue->wakeBits ); |
| 1451 | queue->changeBits = 0; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1452 | QUEUE_Unlock( queue ); |
| 1453 | |
Alexandre Julliard | e658d82 | 1997-11-30 17:45:40 +0000 | [diff] [blame] | 1454 | return ret & MAKELONG( flags, flags ); |
| 1455 | } |
| 1456 | |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1457 | |
| 1458 | /*********************************************************************** |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1459 | * GetInputState16 (USER.335) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1460 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1461 | BOOL16 WINAPI GetInputState16(void) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1462 | { |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1463 | return GetInputState(); |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1464 | } |
| 1465 | |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1466 | /*********************************************************************** |
| 1467 | * WaitForInputIdle (USER32.577) |
| 1468 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1469 | DWORD WINAPI WaitForInputIdle (HANDLE hProcess, DWORD dwTimeOut) |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1470 | { |
Alexandre Julliard | dadf78f | 1998-05-17 17:13:43 +0000 | [diff] [blame] | 1471 | FIXME (msg, "(hProcess=%d, dwTimeOut=%ld): stub\n", hProcess, dwTimeOut); |
Alexandre Julliard | 46ea8b3 | 1998-05-03 19:01:20 +0000 | [diff] [blame] | 1472 | |
Alexandre Julliard | 54c2711 | 1998-03-29 19:44:57 +0000 | [diff] [blame] | 1473 | return WAIT_TIMEOUT; |
| 1474 | } |
| 1475 | |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1476 | |
| 1477 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 1478 | * GetInputState32 (USER32.244) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1479 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1480 | BOOL WINAPI GetInputState(void) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1481 | { |
| 1482 | MESSAGEQUEUE *queue; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1483 | BOOL ret; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1484 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1485 | if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) |
Alexandre Julliard | f0cbfa0 | 1997-02-15 14:29:56 +0000 | [diff] [blame] | 1486 | return FALSE; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1487 | ret = queue->wakeBits & (QS_KEY | QS_MOUSEBUTTON); |
| 1488 | QUEUE_Unlock( queue ); |
| 1489 | |
| 1490 | return ret; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1491 | } |
| 1492 | |
Ulrich Weigand | 89b93bf | 1998-12-24 15:15:00 +0000 | [diff] [blame] | 1493 | /*********************************************************************** |
| 1494 | * UserYield (USER.332) |
| 1495 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1496 | void WINAPI UserYield16(void) |
Ulrich Weigand | 89b93bf | 1998-12-24 15:15:00 +0000 | [diff] [blame] | 1497 | { |
Ulrich Weigand | da5779e | 1999-03-27 16:10:52 +0000 | [diff] [blame] | 1498 | MESSAGEQUEUE *queue; |
Ulrich Weigand | 89b93bf | 1998-12-24 15:15:00 +0000 | [diff] [blame] | 1499 | |
| 1500 | /* Handle sent messages */ |
Ulrich Weigand | da5779e | 1999-03-27 16:10:52 +0000 | [diff] [blame] | 1501 | queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ); |
| 1502 | |
Ulrich Weigand | 89b93bf | 1998-12-24 15:15:00 +0000 | [diff] [blame] | 1503 | while (queue && (queue->wakeBits & QS_SENDMESSAGE)) |
| 1504 | QUEUE_ReceiveMessage( queue ); |
| 1505 | |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1506 | QUEUE_Unlock( queue ); |
| 1507 | |
Ulrich Weigand | da5779e | 1999-03-27 16:10:52 +0000 | [diff] [blame] | 1508 | /* Yield */ |
| 1509 | if ( THREAD_IsWin16( THREAD_Current() ) ) |
| 1510 | OldYield16(); |
| 1511 | else |
| 1512 | { |
Eric Pouech | 7f14c08 | 1999-04-01 09:58:53 +0000 | [diff] [blame] | 1513 | DWORD count; |
| 1514 | |
| 1515 | ReleaseThunkLock(&count); |
| 1516 | RestoreThunkLock(count); |
Ulrich Weigand | da5779e | 1999-03-27 16:10:52 +0000 | [diff] [blame] | 1517 | } |
Ulrich Weigand | 89b93bf | 1998-12-24 15:15:00 +0000 | [diff] [blame] | 1518 | |
Ulrich Weigand | da5779e | 1999-03-27 16:10:52 +0000 | [diff] [blame] | 1519 | /* Handle sent messages again */ |
| 1520 | queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ); |
| 1521 | |
Ulrich Weigand | 89b93bf | 1998-12-24 15:15:00 +0000 | [diff] [blame] | 1522 | while (queue && (queue->wakeBits & QS_SENDMESSAGE)) |
| 1523 | QUEUE_ReceiveMessage( queue ); |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1524 | |
| 1525 | QUEUE_Unlock( queue ); |
Ulrich Weigand | 89b93bf | 1998-12-24 15:15:00 +0000 | [diff] [blame] | 1526 | } |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1527 | |
| 1528 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 1529 | * GetMessagePos (USER.119) (USER32.272) |
Douglas Ridgway | efaa573 | 1998-10-25 09:20:30 +0000 | [diff] [blame] | 1530 | * |
| 1531 | * The GetMessagePos() function returns a long value representing a |
| 1532 | * cursor position, in screen coordinates, when the last message |
| 1533 | * retrieved by the GetMessage() function occurs. The x-coordinate is |
| 1534 | * in the low-order word of the return value, the y-coordinate is in |
| 1535 | * the high-order word. The application can use the MAKEPOINT() |
| 1536 | * macro to obtain a POINT structure from the return value. |
| 1537 | * |
| 1538 | * For the current cursor position, use GetCursorPos(). |
| 1539 | * |
| 1540 | * RETURNS |
| 1541 | * |
| 1542 | * Cursor position of last message on success, zero on failure. |
| 1543 | * |
| 1544 | * CONFORMANCE |
| 1545 | * |
| 1546 | * ECMA-234, Win32 |
| 1547 | * |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1548 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1549 | DWORD WINAPI GetMessagePos(void) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1550 | { |
| 1551 | MESSAGEQUEUE *queue; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1552 | DWORD ret; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1553 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1554 | if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1555 | ret = queue->GetMessagePosVal; |
| 1556 | QUEUE_Unlock( queue ); |
| 1557 | |
| 1558 | return ret; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | |
| 1562 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 1563 | * GetMessageTime (USER.120) (USER32.273) |
Douglas Ridgway | efaa573 | 1998-10-25 09:20:30 +0000 | [diff] [blame] | 1564 | * |
| 1565 | * GetMessageTime() returns the message time for the last message |
| 1566 | * retrieved by the function. The time is measured in milliseconds with |
| 1567 | * the same offset as GetTickCount(). |
| 1568 | * |
| 1569 | * Since the tick count wraps, this is only useful for moderately short |
| 1570 | * relative time comparisons. |
| 1571 | * |
| 1572 | * RETURNS |
| 1573 | * |
| 1574 | * Time of last message on success, zero on failure. |
| 1575 | * |
| 1576 | * CONFORMANCE |
| 1577 | * |
| 1578 | * ECMA-234, Win32 |
| 1579 | * |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1580 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1581 | LONG WINAPI GetMessageTime(void) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1582 | { |
| 1583 | MESSAGEQUEUE *queue; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1584 | LONG ret; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1585 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1586 | if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1587 | ret = queue->GetMessageTimeVal; |
| 1588 | QUEUE_Unlock( queue ); |
| 1589 | |
| 1590 | return ret; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | |
| 1594 | /*********************************************************************** |
Alexandre Julliard | c7c217b | 1998-04-13 12:21:30 +0000 | [diff] [blame] | 1595 | * GetMessageExtraInfo (USER.288) (USER32.271) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1596 | */ |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 1597 | LONG WINAPI GetMessageExtraInfo(void) |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1598 | { |
| 1599 | MESSAGEQUEUE *queue; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1600 | LONG ret; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1601 | |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 1602 | if (!(queue = (MESSAGEQUEUE *)QUEUE_Lock( GetFastQueue16() ))) return 0; |
Stephane Lussier | 1c4786f | 1999-01-28 10:54:11 +0000 | [diff] [blame] | 1603 | ret = queue->GetMessageExtraInfoVal; |
| 1604 | QUEUE_Unlock( queue ); |
| 1605 | |
| 1606 | return ret; |
Alexandre Julliard | b817f4f | 1996-03-14 18:08:34 +0000 | [diff] [blame] | 1607 | } |