
Sat Aug 22 17:46:19 1998 Ulrich Weigand <weigand@informatik.uni-erlangen.de> * [include/dosexe.h] [include/module.h] [include/pe_image.h] [include/process.h] [include/windows.h] [loader/dos/module.c] [loader/module.c] [loader/ne/module.c] [loader/pe_image.c] [scheduler/process.c] [win32/process.c] Partially implemented CreateProcess32. * [win32/device.c] [relay32/kernel32.spec] [scheduler/k32obj.c] [misc/registry.c] [win32/file.c] Partially implemented VxDCall (VMM registry services). * [files/dos_fs.c] DOSFS_FindNext made thread-safe. * [include/sig_context.h] [include/syslevel.h] [loader/signal.c] [scheduler/syslevel.c] [tools/build.c] Replaced CALLTO16_Current_fs by SYSLEVEL_Win16CurrentTeb. * [win32/kernel32.c] Bugfix: QT_Thunk/FT_Thunk should return 'long' in DX:AX, not EAX. * [if1632/relay.c] [relay32/builtin32.c] [windows/msgbox.c] [msdos/int20.c] [msdos/int21.c] Use ExitProcess instead of TASK_KillCurrentTask. * [include/task.h] [include/thread.h] [loader/task.c] [scheduler/thread.c] [include/queue.h] [windows/message.c] [windows/queue.c] [windows/win.c] Prevent Win32 threads from entering the TASK_Reschedule loop. (Note: Win32 messaging still doesn't work correctly; this patch is just preventing the system from crashing when Win32 threads call messaging functions. Messages will probably still get lost.) * [scheduler/critsection.c] Deactivated the use of SEM_UNDO for the SYSTEM_LOCK semaphore; for some reason, this leads to problems after threads terminate... Sat Aug 22 15:00:00 1998 Jürgen Schmied <juergen.schmied@metronet.de> * [include/authors.h] New file, includes all names of the developer (former shell.c) * [Makefile.in][configure][configure.in][dlls/Makefile.in] [dlls/shell32/Makefile.in][shres.rc] Created dlls/shell32 and moved the shell32 stuff in it. Started to create internal resources. * [dlls/shell32/*] Split the shell32 implementation into smaller files. New classes: IContextMenu, IExtractIcon, IShellView. Implemented Shell_GetImageList(). shell32 links to comctl32 now dynamically so it can use internal/external implementations. * [documentation/internal-dll] [documentation/shell32] New, could anybody do a spellcheck? * [include/commctrl.h] Many new LV constants, structures, functions. * [controls/comctl32undoc.c] Rewrote the DSA* functions. * [windows/winpos.c] SetShellWindow32, GetShellWindow32. Sat Aug 22 14:02:15 1998 Alexander Lukyanov <lav@long.yar.ru> * [loader/resource.c] Mark last accelerator as such in LoadAccelerators32W. * [relay32/shell32.spec] [misc/shell.c] Add stubs for SHGetSpecialFolderPath[AW]. Sat Aug 22 02:07:42 1998 Adrian Harvey <adrian@select.com.au> * [include/file.h] [file/file.c] [msdos/int21.c] [msdos/vxd.c] [misc/lzexpand.c] [win32/kernel32.c] [documentation/filehandles] Fixed file handle handling. Created universal HFILE16 to HFILE32 translation macro from msdos/int21 code by Ove Kaaven. Used macro in all Win16 functions so that win32 handles are translated to avoid DOS/Win16 stdxx handles. Removed handle translation from int21.c where Win16 functions are called. Changed remaining calls to use new macro names. Documented filehandle handling and differences between win 16 & 32. Fri Aug 21 20:32:49 1998 Alexandre Julliard <julliard@lrc.epfl.ch> * [server/process.c] [server/thread.c] Implemented object wait queues and synchronization. Fri Aug 21 18:40:02 1998 Huw D M Davies <daviesh@abacus.physics.ox.ac.uk> * [graphics/psdrv/*] DEVMODE dmPaper{Width|Length} fields are in 0.1mm. Select a 100 pixel default font in CreateDC. Thu Aug 20 22:47:39 1998 Uwe Bonnes <bon@elektron.ikp.physik.tu-darmstadt.de> * [objects/bitmap.c] Handle bits=32 in SetBitmapBits32 and GetBitmapBits32. * [msdos/int21.c] Add handling of Int21 0A and 37. * [misc/commdlg.c] Use MapHModuleLS and MapHModuleSL when translating HINSTANCE16 to HINSTANCE32 and vice versa. * [win32/file.c] CreateFile32A: Abort if filename == NULL. Thu Aug 20 12:28:31 1998 Marcus Meissner <marcus@jet.franken.de> * [*/*] Lots of missing prototypes added, some parameter types adapted to match SDK. * [debugger/stabs.c] Don't loop forever if we don't find wine or one of the libxxx.so. * [loader/ne/module.c] Implemented MapHModuleLS,MapHModuleSL,MapHinstLS,MapHinstSL. * [misc/network.c] Implemented WNetGetUser32A. * [misc/shellord.c] Implemented ILRemoveLastID. * [multimedia/dsound.c] Fixed StarCraft memory leak. * [graphics/ddraw.c] Removed some unnecessary simple relaying functions, tried polishing up the Xlib implementation (still doesn't work), temp. removed Xshm code (to be remerged with working Xlib code). Tue Aug 18 22:29:17 1998 Ove Kaaven <ovek@arcticnet.no> * [multimedia/mmio.c] [multimedia/mmsystem.c] Fixed most mmio bugs, fully implementing mmioSetBuffer buffering, ability to read memory files, and the sndPlaySound() SND_MEMORY flag. Most mmio-using programs now work fine. * [include/dosexe.h] [include/miscemu.h] [include/module.h] [loader/module.c] [loader/task.c] [msdos/dosmem.c] Improved DOS VM flexibility and portability somewhat. (Did I get the #ifdefs right this time, BSD-ers?) * [msdos/int21.c] Made "Get Current PSP address" work as expected in a DOS VM. * [loader/dos/*] Began improving flexibility and portability somewhat. It should be easier to add DPMI RMCB callbacks now. The DOS VM no longer leaves big files lying around in /tmp after a crash. Tue Aug 18 12:38:31 1998 Turchanov Sergey <turchanov@usa.net> * [relay32/winmm.spec] This patch allows WinAmp to play WAV files (at least in PCM format). Sun Aug 16 05:34:13 1998 Pablo Saratxaga <srtxg@chanae.alphanet.ch> * [windows/keyboard.c] Corrected keyboard code to properly handle keys : ? ~ and " on non US keyboards. Sat Aug 15 18:47:14 1998 Brian Craft <bcboy@dorothy.wanglab.brandeis.edu> * [windows/win.c] Fixed severe bug in EnumChildWindwos(). Thu Aug 13 21:05:35 1998 Eric Kohl <ekohl@abo.rhein-zeitung.de> * [controls/tooltips.c] Fixed some bugs. Added subclassing support. * [controls/toolbar.c] Improved tooltip integration. Fixed some bugs. * [controls/commctrl.c] Changed control registration and added some documentation. Fixed ShowHideMenuCtl. * [controls/rebar.c][include/rebar.h][include/commctrl.h] Improved rebar implementation (still no display). * [controls/pager.c][include/pager.h][include/commctrl.h] Improved pager implementation (still no display). * [misc/imagelist.c] Fixed a bug. * [documentation/common_controls] Updated. Sun Aug 9 19:50:20 1998 James Juran <jrj120@psu.edu> * [Makefile.in] [documentation/Makefile.in] [programs/Makefile.in] [programs/*/Makefile.in] Added uninstall rules, cleaned up install rules a little bit. Sun Aug 9 13:21:35 1998 Andreas Mohr <100.30936@germany.net> * [loader/ne/module.c] [if1632/kernel.spec] Added the undocumented HIWORD of GetModuleHandle (hFirstModule). * [loader/ne/segment.c] Wine forgot to set some NE_SEGFLAGS_*. Combined with another loader change, this fixed the "BLINKER -- error in loading module" or ghost MessageBox problem that about 1% of all Windows programs have. Some BLINKER programs still don't work, though. But I'm working on it, with great help from Blinkinc. * [loader/task.c] InitTask needs to decrement the SP register by two as Win95 does. Sun Aug 9 02:41:28 1998 Ulrich Weigand <weigand@informatik.uni-erlangen.de> * [if1632/kernel.spec] [relay32/kernel32.spec] [scheduler/syslevel.c] [loader/main.c] [win32/ordinals.c] [include/syslevel.h] [scheduler/Makefile.in] Implemented Win95 'syslevel' routines (including Win16Lock). * [if1632/relay.c] [if1632/thunk.c] [tools/build.c] [loader/task.c] [loader/ne/segment.c] [win32/kernel32.c] [memory/selector.c] [include/stackframe.h] [include/thread.h] 16-bit %fs handling revised. Use Win16Lock where appropriate. * [include/thread.h] [scheduler/synchro.c] [windows/message.c] [windows/queue.c] [win32/process.c] Implemented MsgWaitForMultipleObjects. * [files/change.c] [files/Makefile.in] [scheduler/k32obj.c] [win32/newfns.c] Implemented (dummy) file change notification objects. * [debugger/dbg.y] [scheduler/process.c] [scheduler/thread.c] [include/process.h] [include/thread.h] Suspend all threads except current when hitting debugger break point. * [objects/dib.c] Bugfix for CreateDIBSection.
927 lines
26 KiB
C
927 lines
26 KiB
C
/*
|
|
* Message queues related functions
|
|
*
|
|
* Copyright 1993, 1994 Alexandre Julliard
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <signal.h>
|
|
#include "miscemu.h"
|
|
#include "module.h"
|
|
#include "queue.h"
|
|
#include "task.h"
|
|
#include "win.h"
|
|
#include "clipboard.h"
|
|
#include "hook.h"
|
|
#include "heap.h"
|
|
#include "thread.h"
|
|
#include "process.h"
|
|
#include "debug.h"
|
|
|
|
#define MAX_QUEUE_SIZE 120 /* Max. size of a message queue */
|
|
|
|
static HQUEUE16 hFirstQueue = 0;
|
|
static HQUEUE16 hExitingQueue = 0;
|
|
static HQUEUE16 hmemSysMsgQueue = 0;
|
|
static MESSAGEQUEUE *sysMsgQueue = NULL;
|
|
|
|
static MESSAGEQUEUE *pMouseQueue = NULL; /* Queue for last mouse message */
|
|
static MESSAGEQUEUE *pKbdQueue = NULL; /* Queue for last kbd message */
|
|
|
|
MESSAGEQUEUE *pCursorQueue = NULL;
|
|
MESSAGEQUEUE *pActiveQueue = NULL;
|
|
|
|
/***********************************************************************
|
|
* QUEUE_DumpQueue
|
|
*/
|
|
void QUEUE_DumpQueue( HQUEUE16 hQueue )
|
|
{
|
|
MESSAGEQUEUE *pq;
|
|
|
|
if (!(pq = (MESSAGEQUEUE*) GlobalLock16( hQueue )) ||
|
|
GlobalSize16(hQueue) < sizeof(MESSAGEQUEUE)+pq->queueSize*sizeof(QMSG))
|
|
{
|
|
WARN(msg, "%04x is not a queue handle\n", hQueue );
|
|
return;
|
|
}
|
|
|
|
DUMP( "next: %12.4x Intertask SendMessage:\n"
|
|
"hTask: %11.4x ----------------------\n"
|
|
"msgSize: %9.4x hWnd: %10.4x\n"
|
|
"msgCount: %8.4x msg: %11.4x\n"
|
|
"msgNext: %9.4x wParam: %8.4x\n"
|
|
"msgFree: %9.4x lParam: %8.8x\n"
|
|
"qSize: %11.4x lRet: %10.8x\n"
|
|
"wWinVer: %9.4x ISMH: %10.4x\n"
|
|
"paints: %10.4x hSendTask: %5.4x\n"
|
|
"timers: %10.4x hPrevSend: %5.4x\n"
|
|
"wakeBits: %8.4x\n"
|
|
"wakeMask: %8.4x\n"
|
|
"hCurHook: %8.4x\n",
|
|
pq->next, pq->hTask, pq->msgSize, pq->hWnd,
|
|
pq->msgCount, pq->msg, pq->nextMessage, pq->wParam,
|
|
pq->nextFreeMessage, (unsigned)pq->lParam, pq->queueSize,
|
|
(unsigned)pq->SendMessageReturn, pq->wWinVersion, pq->InSendMessageHandle,
|
|
pq->wPaintCount, pq->hSendingTask, pq->wTimerCount,
|
|
pq->hPrevSendingTask, pq->wakeBits, pq->wakeMask, pq->hCurHook);
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_WalkQueues
|
|
*/
|
|
void QUEUE_WalkQueues(void)
|
|
{
|
|
char module[10];
|
|
HQUEUE16 hQueue = hFirstQueue;
|
|
|
|
DUMP( "Queue Size Msgs Task\n" );
|
|
while (hQueue)
|
|
{
|
|
MESSAGEQUEUE *queue = (MESSAGEQUEUE *)GlobalLock16( hQueue );
|
|
if (!queue)
|
|
{
|
|
WARN( msg, "Bad queue handle %04x\n", hQueue );
|
|
return;
|
|
}
|
|
if (!GetModuleName( queue->hTask, module, sizeof(module )))
|
|
strcpy( module, "???" );
|
|
DUMP( "%04x %5d %4d %04x %s\n", hQueue, queue->msgSize,
|
|
queue->msgCount, queue->hTask, module );
|
|
hQueue = queue->next;
|
|
}
|
|
DUMP( "\n" );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_IsExitingQueue
|
|
*/
|
|
BOOL32 QUEUE_IsExitingQueue( HQUEUE16 hQueue )
|
|
{
|
|
return (hExitingQueue && (hQueue == hExitingQueue));
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_SetExitingQueue
|
|
*/
|
|
void QUEUE_SetExitingQueue( HQUEUE16 hQueue )
|
|
{
|
|
hExitingQueue = hQueue;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_CreateMsgQueue
|
|
*
|
|
* Creates a message queue. Doesn't link it into queue list!
|
|
*/
|
|
static HQUEUE16 QUEUE_CreateMsgQueue( int size )
|
|
{
|
|
HQUEUE16 hQueue;
|
|
MESSAGEQUEUE * msgQueue;
|
|
int queueSize;
|
|
TDB *pTask = (TDB *)GlobalLock16( GetCurrentTask() );
|
|
|
|
TRACE(msg,"Creating message queue...\n");
|
|
|
|
queueSize = sizeof(MESSAGEQUEUE) + size * sizeof(QMSG);
|
|
if (!(hQueue = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT, queueSize )))
|
|
return 0;
|
|
msgQueue = (MESSAGEQUEUE *) GlobalLock16( hQueue );
|
|
msgQueue->self = hQueue;
|
|
msgQueue->msgSize = sizeof(QMSG);
|
|
msgQueue->queueSize = size;
|
|
msgQueue->wakeBits = msgQueue->changeBits = QS_SMPARAMSFREE;
|
|
msgQueue->wWinVersion = pTask ? pTask->version : 0;
|
|
GlobalUnlock16( hQueue );
|
|
return hQueue;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_DeleteMsgQueue
|
|
*
|
|
* Unlinks and deletes a message queue.
|
|
*
|
|
* Note: We need to mask asynchronous events to make sure PostMessage works
|
|
* even in the signal handler.
|
|
*/
|
|
BOOL32 QUEUE_DeleteMsgQueue( HQUEUE16 hQueue )
|
|
{
|
|
MESSAGEQUEUE * msgQueue = (MESSAGEQUEUE*)GlobalLock16(hQueue);
|
|
HQUEUE16 senderQ;
|
|
HQUEUE16 *pPrev;
|
|
|
|
TRACE(msg,"Deleting message queue %04x\n", hQueue);
|
|
|
|
if (!hQueue || !msgQueue)
|
|
{
|
|
WARN(msg, "invalid argument.\n");
|
|
return 0;
|
|
}
|
|
if( pCursorQueue == msgQueue ) pCursorQueue = NULL;
|
|
if( pActiveQueue == msgQueue ) pActiveQueue = NULL;
|
|
|
|
/* flush sent messages */
|
|
senderQ = msgQueue->hSendingTask;
|
|
while( senderQ )
|
|
{
|
|
MESSAGEQUEUE* sq = (MESSAGEQUEUE*)GlobalLock16(senderQ);
|
|
if( !sq ) break;
|
|
sq->SendMessageReturn = 0L;
|
|
QUEUE_SetWakeBit( sq, QS_SMRESULT );
|
|
senderQ = sq->hPrevSendingTask;
|
|
}
|
|
|
|
SIGNAL_MaskAsyncEvents( TRUE );
|
|
|
|
pPrev = &hFirstQueue;
|
|
while (*pPrev && (*pPrev != hQueue))
|
|
{
|
|
MESSAGEQUEUE *msgQ = (MESSAGEQUEUE*)GlobalLock16(*pPrev);
|
|
pPrev = &msgQ->next;
|
|
}
|
|
if (*pPrev) *pPrev = msgQueue->next;
|
|
msgQueue->self = 0;
|
|
|
|
SIGNAL_MaskAsyncEvents( FALSE );
|
|
|
|
GlobalFree16( hQueue );
|
|
return 1;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_CreateSysMsgQueue
|
|
*
|
|
* Create the system message queue, and set the double-click speed.
|
|
* Must be called only once.
|
|
*/
|
|
BOOL32 QUEUE_CreateSysMsgQueue( int size )
|
|
{
|
|
if (size > MAX_QUEUE_SIZE) size = MAX_QUEUE_SIZE;
|
|
else if (size <= 0) size = 1;
|
|
if (!(hmemSysMsgQueue = QUEUE_CreateMsgQueue( size ))) return FALSE;
|
|
sysMsgQueue = (MESSAGEQUEUE *) GlobalLock16( hmemSysMsgQueue );
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_GetSysQueue
|
|
*/
|
|
MESSAGEQUEUE *QUEUE_GetSysQueue(void)
|
|
{
|
|
return sysMsgQueue;
|
|
}
|
|
|
|
/***********************************************************************
|
|
* QUEUE_Signal
|
|
*/
|
|
void QUEUE_Signal( HTASK16 hTask )
|
|
{
|
|
PDB32 *pdb;
|
|
THREAD_ENTRY *entry;
|
|
int wakeup = FALSE;
|
|
|
|
TDB *pTask = (TDB *)GlobalLock16( hTask );
|
|
if ( !pTask ) return;
|
|
|
|
TRACE(msg, "calling SYNC_MsgWakeUp\n");
|
|
|
|
/* Wake up thread waiting for message */
|
|
/* NOTE: This should really wake up *the* thread that owns
|
|
the queue. Since we dont't have thread-local message
|
|
queues yet, we wake up all waiting threads ... */
|
|
SYSTEM_LOCK();
|
|
pdb = pTask->thdb->process;
|
|
entry = pdb? pdb->thread_list->next : NULL;
|
|
|
|
if (entry)
|
|
for (;;)
|
|
{
|
|
if (entry->thread->wait_struct.wait_msg)
|
|
{
|
|
SYNC_MsgWakeUp( entry->thread );
|
|
wakeup = TRUE;
|
|
}
|
|
if (entry == pdb->thread_list) break;
|
|
entry = entry->next;
|
|
}
|
|
SYSTEM_UNLOCK();
|
|
|
|
if ( !wakeup && THREAD_IsWin16( THREAD_Current() ) )
|
|
PostEvent( hTask );
|
|
}
|
|
|
|
/***********************************************************************
|
|
* QUEUE_Wait
|
|
*/
|
|
void QUEUE_Wait( void )
|
|
{
|
|
if ( THREAD_IsWin16( THREAD_Current() ) )
|
|
WaitEvent( 0 );
|
|
else
|
|
{
|
|
TRACE(msg, "current task is 32-bit, calling SYNC_DoWait\n");
|
|
SYNC_DoWait( 0, NULL, FALSE, INFINITE32, FALSE, TRUE );
|
|
}
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_SetWakeBit
|
|
*
|
|
* See "Windows Internals", p.449
|
|
*/
|
|
void QUEUE_SetWakeBit( MESSAGEQUEUE *queue, WORD bit )
|
|
{
|
|
TRACE(msg,"queue = %04x (wm=%04x), bit = %04x\n",
|
|
queue->self, queue->wakeMask, bit );
|
|
|
|
if (bit & QS_MOUSE) pMouseQueue = queue;
|
|
if (bit & QS_KEY) pKbdQueue = queue;
|
|
queue->changeBits |= bit;
|
|
queue->wakeBits |= bit;
|
|
if (queue->wakeMask & bit)
|
|
{
|
|
queue->wakeMask = 0;
|
|
QUEUE_Signal( queue->hTask );
|
|
}
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_ClearWakeBit
|
|
*/
|
|
void QUEUE_ClearWakeBit( MESSAGEQUEUE *queue, WORD bit )
|
|
{
|
|
queue->changeBits &= ~bit;
|
|
queue->wakeBits &= ~bit;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_WaitBits
|
|
*
|
|
* See "Windows Internals", p.447
|
|
*/
|
|
void QUEUE_WaitBits( WORD bits )
|
|
{
|
|
MESSAGEQUEUE *queue;
|
|
|
|
TRACE(msg,"q %04x waiting for %04x\n", GetTaskQueue(0), bits);
|
|
|
|
for (;;)
|
|
{
|
|
if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return;
|
|
|
|
if (queue->changeBits & bits)
|
|
{
|
|
/* One of the bits is set; we can return */
|
|
queue->wakeMask = 0;
|
|
return;
|
|
}
|
|
if (queue->wakeBits & QS_SENDMESSAGE)
|
|
{
|
|
/* Process the sent message immediately */
|
|
|
|
queue->wakeMask = 0;
|
|
QUEUE_ReceiveMessage( queue );
|
|
continue; /* nested sm crux */
|
|
}
|
|
|
|
queue->wakeMask = bits | QS_SENDMESSAGE;
|
|
if(queue->changeBits & bits) continue;
|
|
|
|
TRACE(msg,"%04x) wakeMask is %04x, waiting\n", queue->self, queue->wakeMask);
|
|
|
|
QUEUE_Wait();
|
|
}
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_ReceiveMessage
|
|
*
|
|
* This routine is called when a sent message is waiting for the queue.
|
|
*/
|
|
void QUEUE_ReceiveMessage( MESSAGEQUEUE *queue )
|
|
{
|
|
MESSAGEQUEUE *senderQ = NULL;
|
|
HQUEUE16 prevSender = 0;
|
|
QSMCTRL* prevCtrlPtr = NULL;
|
|
LRESULT result = 0;
|
|
|
|
TRACE(msg, "ReceiveMessage, queue %04x\n", queue->self );
|
|
if (!(queue->wakeBits & QS_SENDMESSAGE) ||
|
|
!(senderQ = (MESSAGEQUEUE*)GlobalLock16( queue->hSendingTask)))
|
|
{ TRACE(msg,"\trcm: nothing to do\n"); return; }
|
|
|
|
if( !senderQ->hPrevSendingTask )
|
|
{
|
|
queue->wakeBits &= ~QS_SENDMESSAGE; /* no more sent messages */
|
|
queue->changeBits &= ~QS_SENDMESSAGE;
|
|
}
|
|
|
|
/* Save current state on stack */
|
|
prevSender = queue->InSendMessageHandle;
|
|
prevCtrlPtr = queue->smResultCurrent;
|
|
|
|
/* Remove sending queue from the list */
|
|
queue->InSendMessageHandle = queue->hSendingTask;
|
|
queue->smResultCurrent = senderQ->smResultInit;
|
|
queue->hSendingTask = senderQ->hPrevSendingTask;
|
|
|
|
TRACE(msg, "\trcm: smResultCurrent = %08x, prevCtrl = %08x\n",
|
|
(unsigned)queue->smResultCurrent, (unsigned)prevCtrlPtr );
|
|
QUEUE_SetWakeBit( senderQ, QS_SMPARAMSFREE );
|
|
|
|
TRACE(msg, "\trcm: calling wndproc - %04x %04x %04x%04x %08x\n",
|
|
senderQ->hWnd, senderQ->msg, senderQ->wParamHigh,
|
|
senderQ->wParam, (unsigned)senderQ->lParam );
|
|
|
|
if (IsWindow32( senderQ->hWnd ))
|
|
{
|
|
WND *wndPtr = WIN_FindWndPtr( senderQ->hWnd );
|
|
DWORD extraInfo = queue->GetMessageExtraInfoVal;
|
|
queue->GetMessageExtraInfoVal = senderQ->GetMessageExtraInfoVal;
|
|
|
|
if (senderQ->flags & QUEUE_SM_WIN32)
|
|
{
|
|
WPARAM32 wParam = MAKELONG( senderQ->wParam, senderQ->wParamHigh );
|
|
TRACE(msg, "\trcm: msg is Win32\n" );
|
|
if (senderQ->flags & QUEUE_SM_UNICODE)
|
|
result = CallWindowProc32W( wndPtr->winproc,
|
|
senderQ->hWnd, senderQ->msg,
|
|
wParam, senderQ->lParam );
|
|
else
|
|
result = CallWindowProc32A( wndPtr->winproc,
|
|
senderQ->hWnd, senderQ->msg,
|
|
wParam, senderQ->lParam );
|
|
}
|
|
else /* Win16 message */
|
|
result = CallWindowProc16( (WNDPROC16)wndPtr->winproc,
|
|
senderQ->hWnd, senderQ->msg,
|
|
senderQ->wParam, senderQ->lParam );
|
|
|
|
queue->GetMessageExtraInfoVal = extraInfo; /* Restore extra info */
|
|
TRACE(msg,"\trcm: result = %08x\n", (unsigned)result );
|
|
}
|
|
else WARN(msg, "\trcm: bad hWnd\n");
|
|
|
|
/* Return the result to the sender task */
|
|
ReplyMessage16( result );
|
|
|
|
queue->InSendMessageHandle = prevSender;
|
|
queue->smResultCurrent = prevCtrlPtr;
|
|
|
|
TRACE(msg,"done!\n");
|
|
}
|
|
|
|
/***********************************************************************
|
|
* QUEUE_FlushMessage
|
|
*
|
|
* Try to reply to all pending sent messages on exit.
|
|
*/
|
|
void QUEUE_FlushMessages( HQUEUE16 hQueue )
|
|
{
|
|
MESSAGEQUEUE *queue = (MESSAGEQUEUE*)GlobalLock16( hQueue );
|
|
|
|
if( queue )
|
|
{
|
|
MESSAGEQUEUE *senderQ = (MESSAGEQUEUE*)GlobalLock16( queue->hSendingTask);
|
|
QSMCTRL* CtrlPtr = queue->smResultCurrent;
|
|
|
|
while( senderQ )
|
|
{
|
|
if( !(queue->hSendingTask = senderQ->hPrevSendingTask) )
|
|
queue->wakeBits &= ~QS_SENDMESSAGE;
|
|
QUEUE_SetWakeBit( senderQ, QS_SMPARAMSFREE );
|
|
|
|
queue->smResultCurrent = CtrlPtr;
|
|
while( senderQ->wakeBits & QS_SMRESULT ) OldYield();
|
|
|
|
senderQ->SendMessageReturn = 0;
|
|
senderQ->smResult = queue->smResultCurrent;
|
|
QUEUE_SetWakeBit( senderQ, QS_SMRESULT);
|
|
|
|
if( (senderQ = (MESSAGEQUEUE*)GlobalLock16( queue->hSendingTask)) )
|
|
CtrlPtr = senderQ->smResultInit;
|
|
}
|
|
queue->InSendMessageHandle = 0;
|
|
}
|
|
}
|
|
|
|
/***********************************************************************
|
|
* QUEUE_AddMsg
|
|
*
|
|
* Add a message to the queue. Return FALSE if queue is full.
|
|
*/
|
|
BOOL32 QUEUE_AddMsg( HQUEUE16 hQueue, MSG16 * msg, DWORD extraInfo )
|
|
{
|
|
int pos;
|
|
MESSAGEQUEUE *msgQueue;
|
|
|
|
SIGNAL_MaskAsyncEvents( TRUE );
|
|
|
|
if (!(msgQueue = (MESSAGEQUEUE *)GlobalLock16( hQueue ))) return FALSE;
|
|
pos = msgQueue->nextFreeMessage;
|
|
|
|
/* Check if queue is full */
|
|
if ((pos == msgQueue->nextMessage) && (msgQueue->msgCount > 0))
|
|
{
|
|
SIGNAL_MaskAsyncEvents( FALSE );
|
|
WARN( msg,"Queue is full!\n" );
|
|
return FALSE;
|
|
}
|
|
|
|
/* Store message */
|
|
msgQueue->messages[pos].msg = *msg;
|
|
msgQueue->messages[pos].extraInfo = extraInfo;
|
|
if (pos < msgQueue->queueSize-1) pos++;
|
|
else pos = 0;
|
|
msgQueue->nextFreeMessage = pos;
|
|
msgQueue->msgCount++;
|
|
|
|
SIGNAL_MaskAsyncEvents( FALSE );
|
|
|
|
QUEUE_SetWakeBit( msgQueue, QS_POSTMESSAGE );
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_FindMsg
|
|
*
|
|
* Find a message matching the given parameters. Return -1 if none available.
|
|
*/
|
|
int QUEUE_FindMsg( MESSAGEQUEUE * msgQueue, HWND32 hwnd, int first, int last )
|
|
{
|
|
int i, pos = msgQueue->nextMessage;
|
|
|
|
TRACE(msg,"hwnd=%04x pos=%d\n", hwnd, pos );
|
|
|
|
if (!msgQueue->msgCount) return -1;
|
|
if (!hwnd && !first && !last) return pos;
|
|
|
|
for (i = 0; i < msgQueue->msgCount; i++)
|
|
{
|
|
MSG16 * msg = &msgQueue->messages[pos].msg;
|
|
|
|
if (!hwnd || (msg->hwnd == hwnd))
|
|
{
|
|
if (!first && !last) return pos;
|
|
if ((msg->message >= first) && (msg->message <= last)) return pos;
|
|
}
|
|
if (pos < msgQueue->queueSize-1) pos++;
|
|
else pos = 0;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_RemoveMsg
|
|
*
|
|
* Remove a message from the queue (pos must be a valid position).
|
|
*/
|
|
void QUEUE_RemoveMsg( MESSAGEQUEUE * msgQueue, int pos )
|
|
{
|
|
SIGNAL_MaskAsyncEvents( TRUE );
|
|
|
|
if (pos >= msgQueue->nextMessage)
|
|
{
|
|
for ( ; pos > msgQueue->nextMessage; pos--)
|
|
msgQueue->messages[pos] = msgQueue->messages[pos-1];
|
|
msgQueue->nextMessage++;
|
|
if (msgQueue->nextMessage >= msgQueue->queueSize)
|
|
msgQueue->nextMessage = 0;
|
|
}
|
|
else
|
|
{
|
|
for ( ; pos < msgQueue->nextFreeMessage; pos++)
|
|
msgQueue->messages[pos] = msgQueue->messages[pos+1];
|
|
if (msgQueue->nextFreeMessage) msgQueue->nextFreeMessage--;
|
|
else msgQueue->nextFreeMessage = msgQueue->queueSize-1;
|
|
}
|
|
msgQueue->msgCount--;
|
|
if (!msgQueue->msgCount) msgQueue->wakeBits &= ~QS_POSTMESSAGE;
|
|
|
|
SIGNAL_MaskAsyncEvents( FALSE );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_WakeSomeone
|
|
*
|
|
* Wake a queue upon reception of a hardware event.
|
|
*/
|
|
static void QUEUE_WakeSomeone( UINT32 message )
|
|
{
|
|
WND* wndPtr = NULL;
|
|
WORD wakeBit;
|
|
HWND32 hwnd;
|
|
MESSAGEQUEUE *queue = pCursorQueue;
|
|
|
|
if( (message >= WM_KEYFIRST) && (message <= WM_KEYLAST) )
|
|
{
|
|
wakeBit = QS_KEY;
|
|
if( pActiveQueue ) queue = pActiveQueue;
|
|
}
|
|
else
|
|
{
|
|
wakeBit = (message == WM_MOUSEMOVE) ? QS_MOUSEMOVE : QS_MOUSEBUTTON;
|
|
if( (hwnd = GetCapture32()) )
|
|
if( (wndPtr = WIN_FindWndPtr( hwnd )) )
|
|
queue = (MESSAGEQUEUE *)GlobalLock16( wndPtr->hmemTaskQ );
|
|
}
|
|
|
|
if( (hwnd = GetSysModalWindow16()) )
|
|
if( (wndPtr = WIN_FindWndPtr( hwnd )) )
|
|
queue = (MESSAGEQUEUE *)GlobalLock16( wndPtr->hmemTaskQ );
|
|
|
|
if( !queue )
|
|
{
|
|
queue = GlobalLock16( hFirstQueue );
|
|
while( queue )
|
|
{
|
|
if (queue->wakeMask & wakeBit) break;
|
|
queue = GlobalLock16( queue->next );
|
|
}
|
|
if( !queue )
|
|
{
|
|
WARN(msg, "couldn't find queue\n");
|
|
return;
|
|
}
|
|
}
|
|
|
|
QUEUE_SetWakeBit( queue, wakeBit );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* hardware_event
|
|
*
|
|
* Add an event to the system message queue.
|
|
* Note: the position is relative to the desktop window.
|
|
*/
|
|
void hardware_event( WORD message, WORD wParam, LONG lParam,
|
|
int xPos, int yPos, DWORD time, DWORD extraInfo )
|
|
{
|
|
MSG16 *msg;
|
|
int pos;
|
|
|
|
if (!sysMsgQueue) return;
|
|
pos = sysMsgQueue->nextFreeMessage;
|
|
|
|
/* Merge with previous event if possible */
|
|
|
|
if ((message == WM_MOUSEMOVE) && sysMsgQueue->msgCount)
|
|
{
|
|
if (pos > 0) pos--;
|
|
else pos = sysMsgQueue->queueSize - 1;
|
|
msg = &sysMsgQueue->messages[pos].msg;
|
|
if ((msg->message == message) && (msg->wParam == wParam))
|
|
sysMsgQueue->msgCount--; /* Merge events */
|
|
else
|
|
pos = sysMsgQueue->nextFreeMessage; /* Don't merge */
|
|
}
|
|
|
|
/* Check if queue is full */
|
|
|
|
if ((pos == sysMsgQueue->nextMessage) && sysMsgQueue->msgCount)
|
|
{
|
|
/* Queue is full, beep (but not on every mouse motion...) */
|
|
if (message != WM_MOUSEMOVE) MessageBeep32(0);
|
|
return;
|
|
}
|
|
|
|
/* Store message */
|
|
|
|
msg = &sysMsgQueue->messages[pos].msg;
|
|
msg->hwnd = 0;
|
|
msg->message = message;
|
|
msg->wParam = wParam;
|
|
msg->lParam = lParam;
|
|
msg->time = time;
|
|
msg->pt.x = xPos & 0xffff;
|
|
msg->pt.y = yPos & 0xffff;
|
|
sysMsgQueue->messages[pos].extraInfo = extraInfo;
|
|
if (pos < sysMsgQueue->queueSize - 1) pos++;
|
|
else pos = 0;
|
|
sysMsgQueue->nextFreeMessage = pos;
|
|
sysMsgQueue->msgCount++;
|
|
QUEUE_WakeSomeone( message );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_GetQueueTask
|
|
*/
|
|
HTASK16 QUEUE_GetQueueTask( HQUEUE16 hQueue )
|
|
{
|
|
MESSAGEQUEUE *queue = GlobalLock16( hQueue );
|
|
return (queue) ? queue->hTask : 0 ;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_IncPaintCount
|
|
*/
|
|
void QUEUE_IncPaintCount( HQUEUE16 hQueue )
|
|
{
|
|
MESSAGEQUEUE *queue;
|
|
|
|
if (!(queue = (MESSAGEQUEUE *)GlobalLock16( hQueue ))) return;
|
|
queue->wPaintCount++;
|
|
QUEUE_SetWakeBit( queue, QS_PAINT );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_DecPaintCount
|
|
*/
|
|
void QUEUE_DecPaintCount( HQUEUE16 hQueue )
|
|
{
|
|
MESSAGEQUEUE *queue;
|
|
|
|
if (!(queue = (MESSAGEQUEUE *)GlobalLock16( hQueue ))) return;
|
|
queue->wPaintCount--;
|
|
if (!queue->wPaintCount) queue->wakeBits &= ~QS_PAINT;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_IncTimerCount
|
|
*/
|
|
void QUEUE_IncTimerCount( HQUEUE16 hQueue )
|
|
{
|
|
MESSAGEQUEUE *queue;
|
|
|
|
if (!(queue = (MESSAGEQUEUE *)GlobalLock16( hQueue ))) return;
|
|
queue->wTimerCount++;
|
|
QUEUE_SetWakeBit( queue, QS_TIMER );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* QUEUE_DecTimerCount
|
|
*/
|
|
void QUEUE_DecTimerCount( HQUEUE16 hQueue )
|
|
{
|
|
MESSAGEQUEUE *queue;
|
|
|
|
if (!(queue = (MESSAGEQUEUE *)GlobalLock16( hQueue ))) return;
|
|
queue->wTimerCount--;
|
|
if (!queue->wTimerCount) queue->wakeBits &= ~QS_TIMER;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* PostQuitMessage16 (USER.6)
|
|
*/
|
|
void WINAPI PostQuitMessage16( INT16 exitCode )
|
|
{
|
|
PostQuitMessage32( exitCode );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* PostQuitMessage32 (USER32.421)
|
|
*/
|
|
void WINAPI PostQuitMessage32( INT32 exitCode )
|
|
{
|
|
MESSAGEQUEUE *queue;
|
|
|
|
if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return;
|
|
queue->wPostQMsg = TRUE;
|
|
queue->wExitCode = (WORD)exitCode;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetWindowTask16 (USER.224)
|
|
*/
|
|
HTASK16 WINAPI GetWindowTask16( HWND16 hwnd )
|
|
{
|
|
WND *wndPtr = WIN_FindWndPtr( hwnd );
|
|
|
|
if (!wndPtr) return 0;
|
|
return QUEUE_GetQueueTask( wndPtr->hmemTaskQ );
|
|
}
|
|
|
|
/***********************************************************************
|
|
* GetWindowThreadProcessId (USER32.313)
|
|
*/
|
|
DWORD WINAPI GetWindowThreadProcessId( HWND32 hwnd, LPDWORD process )
|
|
{
|
|
HTASK16 htask;
|
|
TDB *tdb;
|
|
|
|
WND *wndPtr = WIN_FindWndPtr( hwnd );
|
|
|
|
if (!wndPtr) return 0;
|
|
htask=QUEUE_GetQueueTask( wndPtr->hmemTaskQ );
|
|
tdb = (TDB*)GlobalLock16(htask);
|
|
if (!tdb || !tdb->thdb) return 0;
|
|
if (process) *process = PDB_TO_PROCESS_ID( tdb->thdb->process );
|
|
return THDB_TO_THREAD_ID( tdb->thdb );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* SetMessageQueue16 (USER.266)
|
|
*/
|
|
BOOL16 WINAPI SetMessageQueue16( INT16 size )
|
|
{
|
|
return SetMessageQueue32( size );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* SetMessageQueue32 (USER32.494)
|
|
*/
|
|
BOOL32 WINAPI SetMessageQueue32( INT32 size )
|
|
{
|
|
HQUEUE16 hQueue, hNewQueue;
|
|
MESSAGEQUEUE *queuePtr;
|
|
|
|
TRACE(msg,"task %04x size %i\n", GetCurrentTask(), size);
|
|
|
|
if ((size > MAX_QUEUE_SIZE) || (size <= 0)) return TRUE;
|
|
|
|
if( !(hNewQueue = QUEUE_CreateMsgQueue( size )))
|
|
{
|
|
WARN(msg, "failed!\n");
|
|
return FALSE;
|
|
}
|
|
queuePtr = (MESSAGEQUEUE *)GlobalLock16( hNewQueue );
|
|
|
|
SIGNAL_MaskAsyncEvents( TRUE );
|
|
|
|
/* Copy data and free the old message queue */
|
|
if ((hQueue = GetTaskQueue(0)) != 0)
|
|
{
|
|
MESSAGEQUEUE *oldQ = (MESSAGEQUEUE *)GlobalLock16( hQueue );
|
|
memcpy( &queuePtr->wParamHigh, &oldQ->wParamHigh,
|
|
(int)oldQ->messages - (int)(&oldQ->wParamHigh) );
|
|
HOOK_ResetQueueHooks( hNewQueue );
|
|
if( WIN_GetDesktop()->hmemTaskQ == hQueue )
|
|
WIN_GetDesktop()->hmemTaskQ = hNewQueue;
|
|
WIN_ResetQueueWindows( WIN_GetDesktop(), hQueue, hNewQueue );
|
|
CLIPBOARD_ResetLock( hQueue, hNewQueue );
|
|
QUEUE_DeleteMsgQueue( hQueue );
|
|
}
|
|
|
|
/* Link new queue into list */
|
|
queuePtr->hTask = GetCurrentTask();
|
|
queuePtr->next = hFirstQueue;
|
|
hFirstQueue = hNewQueue;
|
|
|
|
if( !queuePtr->next ) pCursorQueue = queuePtr;
|
|
SetTaskQueue( 0, hNewQueue );
|
|
|
|
SIGNAL_MaskAsyncEvents( FALSE );
|
|
return TRUE;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetQueueStatus16 (USER.334)
|
|
*/
|
|
DWORD WINAPI GetQueueStatus16( UINT16 flags )
|
|
{
|
|
MESSAGEQUEUE *queue;
|
|
DWORD ret;
|
|
|
|
if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return 0;
|
|
ret = MAKELONG( queue->changeBits, queue->wakeBits );
|
|
queue->changeBits = 0;
|
|
return ret & MAKELONG( flags, flags );
|
|
}
|
|
|
|
/***********************************************************************
|
|
* GetQueueStatus32 (USER32.283)
|
|
*/
|
|
DWORD WINAPI GetQueueStatus32( UINT32 flags )
|
|
{
|
|
MESSAGEQUEUE *queue;
|
|
DWORD ret;
|
|
|
|
if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return 0;
|
|
ret = MAKELONG( queue->changeBits, queue->wakeBits );
|
|
queue->changeBits = 0;
|
|
return ret & MAKELONG( flags, flags );
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetInputState16 (USER.335)
|
|
*/
|
|
BOOL16 WINAPI GetInputState16(void)
|
|
{
|
|
return GetInputState32();
|
|
}
|
|
|
|
/***********************************************************************
|
|
* WaitForInputIdle (USER32.577)
|
|
*/
|
|
DWORD WINAPI WaitForInputIdle (HANDLE32 hProcess, DWORD dwTimeOut)
|
|
{
|
|
FIXME (msg, "(hProcess=%d, dwTimeOut=%ld): stub\n", hProcess, dwTimeOut);
|
|
|
|
return WAIT_TIMEOUT;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetInputState32 (USER32.244)
|
|
*/
|
|
BOOL32 WINAPI GetInputState32(void)
|
|
{
|
|
MESSAGEQUEUE *queue;
|
|
|
|
if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) )))
|
|
return FALSE;
|
|
return queue->wakeBits & (QS_KEY | QS_MOUSEBUTTON);
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetMessagePos (USER.119) (USER32.272)
|
|
*/
|
|
DWORD WINAPI GetMessagePos(void)
|
|
{
|
|
MESSAGEQUEUE *queue;
|
|
|
|
if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return 0;
|
|
return queue->GetMessagePosVal;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetMessageTime (USER.120) (USER32.273)
|
|
*/
|
|
LONG WINAPI GetMessageTime(void)
|
|
{
|
|
MESSAGEQUEUE *queue;
|
|
|
|
if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return 0;
|
|
return queue->GetMessageTimeVal;
|
|
}
|
|
|
|
|
|
/***********************************************************************
|
|
* GetMessageExtraInfo (USER.288) (USER32.271)
|
|
*/
|
|
LONG WINAPI GetMessageExtraInfo(void)
|
|
{
|
|
MESSAGEQUEUE *queue;
|
|
|
|
if (!(queue = (MESSAGEQUEUE *)GlobalLock16( GetTaskQueue(0) ))) return 0;
|
|
return queue->GetMessageExtraInfoVal;
|
|
}
|