Handling for listviewstyles, view mode buttons in filedialogs
[wine/multimedia.git] / windows / queue.c
blob9db972d5bd41e8078ee2836e90360f03a91f6996
1 /*
2 * Message queues related functions
4 * Copyright 1993, 1994 Alexandre Julliard
5 */
7 #include <stdlib.h>
8 #include <signal.h>
9 #include "miscemu.h"
10 #include "module.h"
11 #include "queue.h"
12 #include "task.h"
13 #include "win.h"
14 #include "clipboard.h"
15 #include "hook.h"
16 #include "heap.h"
17 #include "thread.h"
18 #include "process.h"
19 #include "debug.h"
21 #define MAX_QUEUE_SIZE 120 /* Max. size of a message queue */
23 static HQUEUE16 hFirstQueue = 0;
24 static HQUEUE16 hExitingQueue = 0;
25 static HQUEUE16 hmemSysMsgQueue = 0;
26 static MESSAGEQUEUE *sysMsgQueue = NULL;
28 static MESSAGEQUEUE *pMouseQueue = NULL; /* Queue for last mouse message */
29 static MESSAGEQUEUE *pKbdQueue = NULL; /* Queue for last kbd message */
31 MESSAGEQUEUE *pCursorQueue = NULL;
32 MESSAGEQUEUE *pActiveQueue = NULL;
34 /***********************************************************************
35 * QUEUE_DumpQueue
37 void QUEUE_DumpQueue( HQUEUE16 hQueue )
39 MESSAGEQUEUE *pq;
41 if (!(pq = (MESSAGEQUEUE*) GlobalLock16( hQueue )) ||
42 GlobalSize16(hQueue) < sizeof(MESSAGEQUEUE)+pq->queueSize*sizeof(QMSG))
44 WARN(msg, "%04x is not a queue handle\n", hQueue );
45 return;
48 DUMP( "next: %12.4x Intertask SendMessage:\n"
49 "hTask: %11.4x ----------------------\n"
50 "msgSize: %9.4x hWnd: %10.4x\n"
51 "msgCount: %8.4x msg: %11.4x\n"
52 "msgNext: %9.4x wParam: %8.4x\n"
53 "msgFree: %9.4x lParam: %8.8x\n"
54 "qSize: %11.4x lRet: %10.8x\n"
55 "wWinVer: %9.4x ISMH: %10.4x\n"
56 "paints: %10.4x hSendTask: %5.4x\n"
57 "timers: %10.4x hPrevSend: %5.4x\n"
58 "wakeBits: %8.4x\n"
59 "wakeMask: %8.4x\n"
60 "hCurHook: %8.4x\n",
61 pq->next, pq->hTask, pq->msgSize, pq->hWnd,
62 pq->msgCount, pq->msg, pq->nextMessage, pq->wParam,
63 pq->nextFreeMessage, (unsigned)pq->lParam, pq->queueSize,
64 (unsigned)pq->SendMessageReturn, pq->wWinVersion, pq->InSendMessageHandle,
65 pq->wPaintCount, pq->hSendingTask, pq->wTimerCount,
66 pq->hPrevSendingTask, pq->wakeBits, pq->wakeMask, pq->hCurHook);
70 /***********************************************************************
71 * QUEUE_WalkQueues
73 void QUEUE_WalkQueues(void)
75 char module[10];
76 HQUEUE16 hQueue = hFirstQueue;
78 DUMP( "Queue Size Msgs Task\n" );
79 while (hQueue)
81 MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock16( hQueue );
82 if (!queue)
84 WARN( msg, "Bad queue handle %04x\n", hQueue );
85 return;
87 if (!GetModuleName( queue->hTask, module, sizeof(module )))
88 strcpy( module, "???" );
89 DUMP( "%04x %5d %4d %04x %s\n", hQueue, queue->msgSize,
90 queue->msgCount, queue->hTask, module );
91 hQueue = queue->next;
93 DUMP( "\n" );
97 /***********************************************************************
98 * QUEUE_IsExitingQueue
100 BOOL32 QUEUE_IsExitingQueue( HQUEUE16 hQueue )
102 return (hExitingQueue && (hQueue == hExitingQueue));
106 /***********************************************************************
107 * QUEUE_SetExitingQueue
109 void QUEUE_SetExitingQueue( HQUEUE16 hQueue )
111 hExitingQueue = hQueue;
115 /***********************************************************************
116 * QUEUE_CreateMsgQueue
118 * Creates a message queue. Doesn't link it into queue list!
120 static HQUEUE16 QUEUE_CreateMsgQueue( int size )
122 HQUEUE16 hQueue;
123 MESSAGEQUEUE * msgQueue;
124 int queueSize;
125 TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
127 TRACE(msg,"Creating message queue...\n");
129 queueSize = sizeof(MESSAGEQUEUE) + size * sizeof(QMSG);
130 if (!(hQueue = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, queueSize )))
131 return 0;
132 msgQueue = (MESSAGEQUEUE *) GlobalLock16( hQueue );
133 msgQueue->self = hQueue;
134 msgQueue->msgSize = sizeof(QMSG);
135 msgQueue->queueSize = size;
136 msgQueue->wakeBits = msgQueue->changeBits = QS_SMPARAMSFREE;
137 msgQueue->wWinVersion = pTask ? pTask->version : 0;
138 GlobalUnlock16( hQueue );
139 return hQueue;
143 /***********************************************************************
144 * QUEUE_DeleteMsgQueue
146 * Unlinks and deletes a message queue.
148 * Note: We need to mask asynchronous events to make sure PostMessage works
149 * even in the signal handler.
151 BOOL32 QUEUE_DeleteMsgQueue( HQUEUE16 hQueue )
153 MESSAGEQUEUE * msgQueue = (MESSAGEQUEUE*)GlobalLock16(hQueue);
154 HQUEUE16 senderQ;
155 HQUEUE16 *pPrev;
157 TRACE(msg,"Deleting message queue %04x\n", hQueue);
159 if (!hQueue || !msgQueue)
161 WARN(msg, "invalid argument.\n");
162 return 0;
164 if( pCursorQueue == msgQueue ) pCursorQueue = NULL;
165 if( pActiveQueue == msgQueue ) pActiveQueue = NULL;
167 /* flush sent messages */
168 senderQ = msgQueue->hSendingTask;
169 while( senderQ )
171 MESSAGEQUEUE* sq = (MESSAGEQUEUE*)GlobalLock16(senderQ);
172 if( !sq ) break;
173 sq->SendMessageReturn = 0L;
174 QUEUE_SetWakeBit( sq, QS_SMRESULT );
175 senderQ = sq->hPrevSendingTask;
178 SIGNAL_MaskAsyncEvents( TRUE );
180 pPrev = &hFirstQueue;
181 while (*pPrev && (*pPrev != hQueue))
183 MESSAGEQUEUE *msgQ = (MESSAGEQUEUE*)GlobalLock16(*pPrev);
184 pPrev = &msgQ->next;
186 if (*pPrev) *pPrev = msgQueue->next;
187 msgQueue->self = 0;
189 SIGNAL_MaskAsyncEvents( FALSE );
191 GlobalFree16( hQueue );
192 return 1;
196 /***********************************************************************
197 * QUEUE_CreateSysMsgQueue
199 * Create the system message queue, and set the double-click speed.
200 * Must be called only once.
202 BOOL32 QUEUE_CreateSysMsgQueue( int size )
204 if (size > MAX_QUEUE_SIZE) size = MAX_QUEUE_SIZE;
205 else if (size <= 0) size = 1;
206 if (!(hmemSysMsgQueue = QUEUE_CreateMsgQueue( size ))) return FALSE;
207 sysMsgQueue = (MESSAGEQUEUE *) GlobalLock16( hmemSysMsgQueue );
208 return TRUE;
212 /***********************************************************************
213 * QUEUE_GetSysQueue
215 MESSAGEQUEUE *QUEUE_GetSysQueue(void)
217 return sysMsgQueue;
220 /***********************************************************************
221 * QUEUE_Signal
223 void QUEUE_Signal( HTASK16 hTask )
225 PDB32 *pdb;
226 THREAD_ENTRY *entry;
227 int wakeup = FALSE;
229 TDB *pTask = (TDB *)GlobalLock16( hTask );
230 if ( !pTask ) return;
232 TRACE(msg, "calling SYNC_MsgWakeUp\n");
234 /* Wake up thread waiting for message */
235 /* NOTE: This should really wake up *the* thread that owns
236 the queue. Since we dont't have thread-local message
237 queues yet, we wake up all waiting threads ... */
238 SYSTEM_LOCK();
239 pdb = pTask->thdb->process;
240 entry = pdb? pdb->thread_list->next : NULL;
242 if (entry)
243 for (;;)
245 if (entry->thread->wait_struct.wait_msg)
247 SYNC_MsgWakeUp( entry->thread );
248 wakeup = TRUE;
250 if (entry == pdb->thread_list) break;
251 entry = entry->next;
253 SYSTEM_UNLOCK();
255 if ( !wakeup )
256 PostEvent( hTask );
259 /***********************************************************************
260 * QUEUE_Wait
262 void QUEUE_Wait( void )
264 if ( THREAD_IsWin16( THREAD_Current() ) )
265 WaitEvent( 0 );
266 else
268 TRACE(msg, "current task is 32-bit, calling SYNC_DoWait\n");
269 SYNC_DoWait( 0, NULL, FALSE, INFINITE32, FALSE, TRUE );
274 /***********************************************************************
275 * QUEUE_SetWakeBit
277 * See "Windows Internals", p.449
279 void QUEUE_SetWakeBit( MESSAGEQUEUE *queue, WORD bit )
281 TRACE(msg,"queue = %04x (wm=%04x), bit = %04x\n",
282 queue->self, queue->wakeMask, bit );
284 if (bit & QS_MOUSE) pMouseQueue = queue;
285 if (bit & QS_KEY) pKbdQueue = queue;
286 queue->changeBits |= bit;
287 queue->wakeBits |= bit;
288 if (queue->wakeMask & bit)
290 queue->wakeMask = 0;
291 QUEUE_Signal( queue->hTask );
296 /***********************************************************************
297 * QUEUE_ClearWakeBit
299 void QUEUE_ClearWakeBit( MESSAGEQUEUE *queue, WORD bit )
301 queue->changeBits &= ~bit;
302 queue->wakeBits &= ~bit;
306 /***********************************************************************
307 * QUEUE_WaitBits
309 * See "Windows Internals", p.447
311 void QUEUE_WaitBits( WORD bits )
313 MESSAGEQUEUE *queue;
315 TRACE(msg,"q %04x waiting for %04x\n", GetTaskQueue(0), bits);
317 for (;;)
319 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return;
321 if (queue->changeBits & bits)
323 /* One of the bits is set; we can return */
324 queue->wakeMask = 0;
325 return;
327 if (queue->wakeBits & QS_SENDMESSAGE)
329 /* Process the sent message immediately */
331 queue->wakeMask = 0;
332 QUEUE_ReceiveMessage( queue );
333 continue; /* nested sm crux */
336 queue->wakeMask = bits | QS_SENDMESSAGE;
337 if(queue->changeBits & bits) continue;
339 TRACE(msg,"%04x) wakeMask is %04x, waiting\n", queue->self, queue->wakeMask);
341 QUEUE_Wait();
346 /***********************************************************************
347 * QUEUE_ReceiveMessage
349 * This routine is called when a sent message is waiting for the queue.
351 void QUEUE_ReceiveMessage( MESSAGEQUEUE *queue )
353 MESSAGEQUEUE *senderQ = NULL;
354 HQUEUE16 prevSender = 0;
355 QSMCTRL* prevCtrlPtr = NULL;
356 LRESULT result = 0;
358 TRACE(msg, "ReceiveMessage, queue %04x\n", queue->self );
359 if (!(queue->wakeBits & QS_SENDMESSAGE) ||
360 !(senderQ = (MESSAGEQUEUE*)GlobalLock16( queue->hSendingTask)))
361 { TRACE(msg,"\trcm: nothing to do\n"); return; }
363 if( !senderQ->hPrevSendingTask )
365 queue->wakeBits &= ~QS_SENDMESSAGE; /* no more sent messages */
366 queue->changeBits &= ~QS_SENDMESSAGE;
369 /* Save current state on stack */
370 prevSender = queue->InSendMessageHandle;
371 prevCtrlPtr = queue->smResultCurrent;
373 /* Remove sending queue from the list */
374 queue->InSendMessageHandle = queue->hSendingTask;
375 queue->smResultCurrent = senderQ->smResultInit;
376 queue->hSendingTask = senderQ->hPrevSendingTask;
378 TRACE(msg, "\trcm: smResultCurrent = %08x, prevCtrl = %08x\n",
379 (unsigned)queue->smResultCurrent, (unsigned)prevCtrlPtr );
380 QUEUE_SetWakeBit( senderQ, QS_SMPARAMSFREE );
382 TRACE(msg, "\trcm: calling wndproc - %04x %04x %04x%04x %08x\n",
383 senderQ->hWnd, senderQ->msg, senderQ->wParamHigh,
384 senderQ->wParam, (unsigned)senderQ->lParam );
386 if (IsWindow32( senderQ->hWnd ))
388 WND *wndPtr = WIN_FindWndPtr( senderQ->hWnd );
389 DWORD extraInfo = queue->GetMessageExtraInfoVal;
390 queue->GetMessageExtraInfoVal = senderQ->GetMessageExtraInfoVal;
392 if (senderQ->flags & QUEUE_SM_WIN32)
394 WPARAM32 wParam = MAKELONG( senderQ->wParam, senderQ->wParamHigh );
395 TRACE(msg, "\trcm: msg is Win32\n" );
396 if (senderQ->flags & QUEUE_SM_UNICODE)
397 result = CallWindowProc32W( wndPtr->winproc,
398 senderQ->hWnd, senderQ->msg,
399 wParam, senderQ->lParam );
400 else
401 result = CallWindowProc32A( wndPtr->winproc,
402 senderQ->hWnd, senderQ->msg,
403 wParam, senderQ->lParam );
405 else /* Win16 message */
406 result = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
407 senderQ->hWnd, senderQ->msg,
408 senderQ->wParam, senderQ->lParam );
410 queue->GetMessageExtraInfoVal = extraInfo; /* Restore extra info */
411 TRACE(msg,"\trcm: result = %08x\n", (unsigned)result );
413 else WARN(msg, "\trcm: bad hWnd\n");
415 /* Return the result to the sender task */
416 ReplyMessage16( result );
418 queue->InSendMessageHandle = prevSender;
419 queue->smResultCurrent = prevCtrlPtr;
421 TRACE(msg,"done!\n");
424 /***********************************************************************
425 * QUEUE_FlushMessage
427 * Try to reply to all pending sent messages on exit.
429 void QUEUE_FlushMessages( HQUEUE16 hQueue )
431 MESSAGEQUEUE *queue = (MESSAGEQUEUE*)GlobalLock16( hQueue );
433 if( queue )
435 MESSAGEQUEUE *senderQ = (MESSAGEQUEUE*)GlobalLock16( queue->hSendingTask);
436 QSMCTRL* CtrlPtr = queue->smResultCurrent;
438 TRACE(msg,"Flushing queue %04x:\n", hQueue );
440 while( senderQ )
442 if( !CtrlPtr )
443 CtrlPtr = senderQ->smResultInit;
445 TRACE(msg,"\tfrom queue %04x, smResult %08x\n", queue->hSendingTask, (unsigned)CtrlPtr );
447 if( !(queue->hSendingTask = senderQ->hPrevSendingTask) )
448 queue->wakeBits &= ~QS_SENDMESSAGE;
449 QUEUE_SetWakeBit( senderQ, QS_SMPARAMSFREE );
451 queue->smResultCurrent = CtrlPtr;
452 while( senderQ->wakeBits & QS_SMRESULT ) OldYield();
454 senderQ->SendMessageReturn = 0;
455 senderQ->smResult = queue->smResultCurrent;
456 QUEUE_SetWakeBit( senderQ, QS_SMRESULT);
458 senderQ = (MESSAGEQUEUE*)GlobalLock16( queue->hSendingTask);
459 CtrlPtr = NULL;
461 queue->InSendMessageHandle = 0;
465 /***********************************************************************
466 * QUEUE_AddMsg
468 * Add a message to the queue. Return FALSE if queue is full.
470 BOOL32 QUEUE_AddMsg( HQUEUE16 hQueue, MSG16 * msg, DWORD extraInfo )
472 int pos;
473 MESSAGEQUEUE *msgQueue;
475 SIGNAL_MaskAsyncEvents( TRUE );
477 if (!(msgQueue = (MESSAGEQUEUE *)GlobalLock16( hQueue ))) return FALSE;
478 pos = msgQueue->nextFreeMessage;
480 /* Check if queue is full */
481 if ((pos == msgQueue->nextMessage) && (msgQueue->msgCount > 0))
483 SIGNAL_MaskAsyncEvents( FALSE );
484 WARN( msg,"Queue is full!\n" );
485 return FALSE;
488 /* Store message */
489 msgQueue->messages[pos].msg = *msg;
490 msgQueue->messages[pos].extraInfo = extraInfo;
491 if (pos < msgQueue->queueSize-1) pos++;
492 else pos = 0;
493 msgQueue->nextFreeMessage = pos;
494 msgQueue->msgCount++;
496 SIGNAL_MaskAsyncEvents( FALSE );
498 QUEUE_SetWakeBit( msgQueue, QS_POSTMESSAGE );
499 return TRUE;
503 /***********************************************************************
504 * QUEUE_FindMsg
506 * Find a message matching the given parameters. Return -1 if none available.
508 int QUEUE_FindMsg( MESSAGEQUEUE * msgQueue, HWND32 hwnd, int first, int last )
510 int i, pos = msgQueue->nextMessage;
512 TRACE(msg,"hwnd=%04x pos=%d\n", hwnd, pos );
514 if (!msgQueue->msgCount) return -1;
515 if (!hwnd && !first && !last) return pos;
517 for (i = 0; i < msgQueue->msgCount; i++)
519 MSG16 * msg = &msgQueue->messages[pos].msg;
521 if (!hwnd || (msg->hwnd == hwnd))
523 if (!first && !last) return pos;
524 if ((msg->message >= first) && (msg->message <= last)) return pos;
526 if (pos < msgQueue->queueSize-1) pos++;
527 else pos = 0;
529 return -1;
533 /***********************************************************************
534 * QUEUE_RemoveMsg
536 * Remove a message from the queue (pos must be a valid position).
538 void QUEUE_RemoveMsg( MESSAGEQUEUE * msgQueue, int pos )
540 SIGNAL_MaskAsyncEvents( TRUE );
542 if (pos >= msgQueue->nextMessage)
544 for ( ; pos > msgQueue->nextMessage; pos--)
545 msgQueue->messages[pos] = msgQueue->messages[pos-1];
546 msgQueue->nextMessage++;
547 if (msgQueue->nextMessage >= msgQueue->queueSize)
548 msgQueue->nextMessage = 0;
550 else
552 for ( ; pos < msgQueue->nextFreeMessage; pos++)
553 msgQueue->messages[pos] = msgQueue->messages[pos+1];
554 if (msgQueue->nextFreeMessage) msgQueue->nextFreeMessage--;
555 else msgQueue->nextFreeMessage = msgQueue->queueSize-1;
557 msgQueue->msgCount--;
558 if (!msgQueue->msgCount) msgQueue->wakeBits &= ~QS_POSTMESSAGE;
560 SIGNAL_MaskAsyncEvents( FALSE );
564 /***********************************************************************
565 * QUEUE_WakeSomeone
567 * Wake a queue upon reception of a hardware event.
569 static void QUEUE_WakeSomeone( UINT32 message )
571 WND* wndPtr = NULL;
572 WORD wakeBit;
573 HWND32 hwnd;
574 MESSAGEQUEUE *queue = pCursorQueue;
576 if( (message >= WM_KEYFIRST) && (message <= WM_KEYLAST) )
578 wakeBit = QS_KEY;
579 if( pActiveQueue ) queue = pActiveQueue;
581 else
583 wakeBit = (message == WM_MOUSEMOVE) ? QS_MOUSEMOVE : QS_MOUSEBUTTON;
584 if( (hwnd = GetCapture32()) )
585 if( (wndPtr = WIN_FindWndPtr( hwnd )) )
586 queue = (MESSAGEQUEUE *)GlobalLock16( wndPtr->hmemTaskQ );
589 if( (hwnd = GetSysModalWindow16()) )
590 if( (wndPtr = WIN_FindWndPtr( hwnd )) )
591 queue = (MESSAGEQUEUE *)GlobalLock16( wndPtr->hmemTaskQ );
593 if( !queue )
595 queue = GlobalLock16( hFirstQueue );
596 while( queue )
598 if (queue->wakeMask & wakeBit) break;
599 queue = GlobalLock16( queue->next );
601 if( !queue )
603 WARN(msg, "couldn't find queue\n");
604 return;
608 QUEUE_SetWakeBit( queue, wakeBit );
612 /***********************************************************************
613 * hardware_event
615 * Add an event to the system message queue.
616 * Note: the position is relative to the desktop window.
618 void hardware_event( WORD message, WORD wParam, LONG lParam,
619 int xPos, int yPos, DWORD time, DWORD extraInfo )
621 MSG16 *msg;
622 int pos;
624 if (!sysMsgQueue) return;
625 pos = sysMsgQueue->nextFreeMessage;
627 /* Merge with previous event if possible */
629 if ((message == WM_MOUSEMOVE) && sysMsgQueue->msgCount)
631 if (pos > 0) pos--;
632 else pos = sysMsgQueue->queueSize - 1;
633 msg = &sysMsgQueue->messages[pos].msg;
634 if ((msg->message == message) && (msg->wParam == wParam))
635 sysMsgQueue->msgCount--; /* Merge events */
636 else
637 pos = sysMsgQueue->nextFreeMessage; /* Don't merge */
640 /* Check if queue is full */
642 if ((pos == sysMsgQueue->nextMessage) && sysMsgQueue->msgCount)
644 /* Queue is full, beep (but not on every mouse motion...) */
645 if (message != WM_MOUSEMOVE) MessageBeep32(0);
646 return;
649 /* Store message */
651 msg = &sysMsgQueue->messages[pos].msg;
652 msg->hwnd = 0;
653 msg->message = message;
654 msg->wParam = wParam;
655 msg->lParam = lParam;
656 msg->time = time;
657 msg->pt.x = xPos & 0xffff;
658 msg->pt.y = yPos & 0xffff;
659 sysMsgQueue->messages[pos].extraInfo = extraInfo;
660 if (pos < sysMsgQueue->queueSize - 1) pos++;
661 else pos = 0;
662 sysMsgQueue->nextFreeMessage = pos;
663 sysMsgQueue->msgCount++;
664 QUEUE_WakeSomeone( message );
668 /***********************************************************************
669 * QUEUE_GetQueueTask
671 HTASK16 QUEUE_GetQueueTask( HQUEUE16 hQueue )
673 MESSAGEQUEUE *queue = GlobalLock16( hQueue );
674 return (queue) ? queue->hTask : 0 ;
678 /***********************************************************************
679 * QUEUE_IncPaintCount
681 void QUEUE_IncPaintCount( HQUEUE16 hQueue )
683 MESSAGEQUEUE *queue;
685 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( hQueue ))) return;
686 queue->wPaintCount++;
687 QUEUE_SetWakeBit( queue, QS_PAINT );
691 /***********************************************************************
692 * QUEUE_DecPaintCount
694 void QUEUE_DecPaintCount( HQUEUE16 hQueue )
696 MESSAGEQUEUE *queue;
698 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( hQueue ))) return;
699 queue->wPaintCount--;
700 if (!queue->wPaintCount) queue->wakeBits &= ~QS_PAINT;
704 /***********************************************************************
705 * QUEUE_IncTimerCount
707 void QUEUE_IncTimerCount( HQUEUE16 hQueue )
709 MESSAGEQUEUE *queue;
711 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( hQueue ))) return;
712 queue->wTimerCount++;
713 QUEUE_SetWakeBit( queue, QS_TIMER );
717 /***********************************************************************
718 * QUEUE_DecTimerCount
720 void QUEUE_DecTimerCount( HQUEUE16 hQueue )
722 MESSAGEQUEUE *queue;
724 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( hQueue ))) return;
725 queue->wTimerCount--;
726 if (!queue->wTimerCount) queue->wakeBits &= ~QS_TIMER;
730 /***********************************************************************
731 * PostQuitMessage16 (USER.6)
733 void WINAPI PostQuitMessage16( INT16 exitCode )
735 PostQuitMessage32( exitCode );
739 /***********************************************************************
740 * PostQuitMessage32 (USER32.421)
742 * PostQuitMessage() posts a message to the system requesting an
743 * application to terminate execution. As a result of this function,
744 * the WM_QUIT message is posted to the application, and
745 * PostQuitMessage() returns immediately. The exitCode parameter
746 * specifies an application-defined exit code, which appears in the
747 * _wParam_ parameter of the WM_QUIT message posted to the application.
749 * CONFORMANCE
751 * ECMA-234, Win32
753 void WINAPI PostQuitMessage32( INT32 exitCode )
755 MESSAGEQUEUE *queue;
757 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return;
758 queue->wPostQMsg = TRUE;
759 queue->wExitCode = (WORD)exitCode;
763 /***********************************************************************
764 * GetWindowTask16 (USER.224)
766 HTASK16 WINAPI GetWindowTask16( HWND16 hwnd )
768 WND *wndPtr = WIN_FindWndPtr( hwnd );
770 if (!wndPtr) return 0;
771 return QUEUE_GetQueueTask( wndPtr->hmemTaskQ );
774 /***********************************************************************
775 * GetWindowThreadProcessId (USER32.313)
777 DWORD WINAPI GetWindowThreadProcessId( HWND32 hwnd, LPDWORD process )
779 HTASK16 htask;
780 TDB *tdb;
782 WND *wndPtr = WIN_FindWndPtr( hwnd );
784 if (!wndPtr) return 0;
785 htask=QUEUE_GetQueueTask( wndPtr->hmemTaskQ );
786 tdb = (TDB*)GlobalLock16(htask);
787 if (!tdb || !tdb->thdb) return 0;
788 if (process) *process = PDB_TO_PROCESS_ID( tdb->thdb->process );
789 return THDB_TO_THREAD_ID( tdb->thdb );
793 /***********************************************************************
794 * SetMessageQueue16 (USER.266)
796 BOOL16 WINAPI SetMessageQueue16( INT16 size )
798 return SetMessageQueue32( size );
802 /***********************************************************************
803 * SetMessageQueue32 (USER32.494)
805 BOOL32 WINAPI SetMessageQueue32( INT32 size )
807 HQUEUE16 hQueue, hNewQueue;
808 MESSAGEQUEUE *queuePtr;
810 TRACE(msg,"task %04x size %i\n", GetCurrentTask(), size);
812 if ((size > MAX_QUEUE_SIZE) || (size <= 0)) return FALSE;
814 if( !(hNewQueue = QUEUE_CreateMsgQueue( size )))
816 WARN(msg, "failed!\n");
817 return FALSE;
819 queuePtr = (MESSAGEQUEUE *)GlobalLock16( hNewQueue );
821 SIGNAL_MaskAsyncEvents( TRUE );
823 /* Copy data and free the old message queue */
824 if ((hQueue = GetTaskQueue(0)) != 0)
826 MESSAGEQUEUE *oldQ = (MESSAGEQUEUE *)GlobalLock16( hQueue );
827 memcpy( &queuePtr->wParamHigh, &oldQ->wParamHigh,
828 (int)oldQ->messages - (int)(&oldQ->wParamHigh) );
829 HOOK_ResetQueueHooks( hNewQueue );
830 if( WIN_GetDesktop()->hmemTaskQ == hQueue )
831 WIN_GetDesktop()->hmemTaskQ = hNewQueue;
832 WIN_ResetQueueWindows( WIN_GetDesktop(), hQueue, hNewQueue );
833 CLIPBOARD_ResetLock( hQueue, hNewQueue );
834 QUEUE_DeleteMsgQueue( hQueue );
837 /* Link new queue into list */
838 queuePtr->hTask = GetCurrentTask();
839 queuePtr->next = hFirstQueue;
840 hFirstQueue = hNewQueue;
842 if( !queuePtr->next ) pCursorQueue = queuePtr;
843 SetTaskQueue( 0, hNewQueue );
845 SIGNAL_MaskAsyncEvents( FALSE );
846 return TRUE;
850 /***********************************************************************
851 * GetQueueStatus16 (USER.334)
853 DWORD WINAPI GetQueueStatus16( UINT16 flags )
855 MESSAGEQUEUE *queue;
856 DWORD ret;
858 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return 0;
859 ret = MAKELONG( queue->changeBits, queue->wakeBits );
860 queue->changeBits = 0;
861 return ret & MAKELONG( flags, flags );
864 /***********************************************************************
865 * GetQueueStatus32 (USER32.283)
867 DWORD WINAPI GetQueueStatus32( UINT32 flags )
869 MESSAGEQUEUE *queue;
870 DWORD ret;
872 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return 0;
873 ret = MAKELONG( queue->changeBits, queue->wakeBits );
874 queue->changeBits = 0;
875 return ret & MAKELONG( flags, flags );
879 /***********************************************************************
880 * GetInputState16 (USER.335)
882 BOOL16 WINAPI GetInputState16(void)
884 return GetInputState32();
887 /***********************************************************************
888 * WaitForInputIdle (USER32.577)
890 DWORD WINAPI WaitForInputIdle (HANDLE32 hProcess, DWORD dwTimeOut)
892 FIXME (msg, "(hProcess=%d, dwTimeOut=%ld): stub\n", hProcess, dwTimeOut);
894 return WAIT_TIMEOUT;
898 /***********************************************************************
899 * GetInputState32 (USER32.244)
901 BOOL32 WINAPI GetInputState32(void)
903 MESSAGEQUEUE *queue;
905 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) )))
906 return FALSE;
907 return queue->wakeBits & (QS_KEY | QS_MOUSEBUTTON);
911 /***********************************************************************
912 * GetMessagePos (USER.119) (USER32.272)
914 * The GetMessagePos() function returns a long value representing a
915 * cursor position, in screen coordinates, when the last message
916 * retrieved by the GetMessage() function occurs. The x-coordinate is
917 * in the low-order word of the return value, the y-coordinate is in
918 * the high-order word. The application can use the MAKEPOINT()
919 * macro to obtain a POINT structure from the return value.
921 * For the current cursor position, use GetCursorPos().
923 * RETURNS
925 * Cursor position of last message on success, zero on failure.
927 * CONFORMANCE
929 * ECMA-234, Win32
932 DWORD WINAPI GetMessagePos(void)
934 MESSAGEQUEUE *queue;
936 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return 0;
937 return queue->GetMessagePosVal;
941 /***********************************************************************
942 * GetMessageTime (USER.120) (USER32.273)
944 * GetMessageTime() returns the message time for the last message
945 * retrieved by the function. The time is measured in milliseconds with
946 * the same offset as GetTickCount().
948 * Since the tick count wraps, this is only useful for moderately short
949 * relative time comparisons.
951 * RETURNS
953 * Time of last message on success, zero on failure.
955 * CONFORMANCE
957 * ECMA-234, Win32
960 LONG WINAPI GetMessageTime(void)
962 MESSAGEQUEUE *queue;
964 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return 0;
965 return queue->GetMessageTimeVal;
969 /***********************************************************************
970 * GetMessageExtraInfo (USER.288) (USER32.271)
972 LONG WINAPI GetMessageExtraInfo(void)
974 MESSAGEQUEUE *queue;
976 if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return 0;
977 return queue->GetMessageExtraInfoVal;