Ignore:
Timestamp:
Jan 30, 2004, 11:10:07 PM (22 years ago)
Author:
bird
Message:

#682: Drag & Drop - AttachThreadInput().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/windowmsg.cpp

    r10216 r10430  
    1 /* $Id: windowmsg.cpp,v 1.47 2003-08-08 13:30:22 sandervl Exp $ */
     1/* $Id: windowmsg.cpp,v 1.48 2004-01-30 22:10:07 bird Exp $ */
    22/*
    33 * Win32 window message APIs for OS/2
     
    4040ODINDEBUGCHANNEL(USER32-WINDOWMSG)
    4141
    42 
    4342//******************************************************************************
    4443//******************************************************************************
     
    121120{
    122121    BOOL ret;
     122    TEB *pTeb = GetThreadTEB();
    123123
    124124    dprintf2(("GetMessageA %x %x-%x", hwnd, uMsgFilterMin, uMsgFilterMax));
    125     ret = OSLibWinGetMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax);
    126     if(ret) dprintf2(("GetMessageA %x %x %x %x", hwnd, pMsg->message, pMsg->wParam, pMsg->lParam));
     125    do
     126    {
     127        ret = OSLibWinGetMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax);
     128        if(ret) dprintf2(("GetMessageA %x %x %x %x", hwnd, pMsg->message, pMsg->wParam, pMsg->lParam));
     129    } while (   pTeb->o.odin.tidAttachedInputThread
     130             && OSLibForwardMessageToAttachedThread(pTeb, pMsg, NULL));
    127131    HOOK_CallHooksA(WH_GETMESSAGE, HC_ACTION, PM_REMOVE, (LPARAM)pMsg);
    128132    return ret;
     
    133137{
    134138    BOOL ret;
     139    TEB *pTeb = GetThreadTEB();
    135140
    136141    dprintf2(("GetMessageW %x %x-%x", hwnd, uMsgFilterMin, uMsgFilterMax));
    137     ret = OSLibWinGetMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, TRUE);
     142    do
     143    {
     144        ret = OSLibWinGetMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, TRUE);
     145    } while (   pTeb->o.odin.tidAttachedInputThread
     146             && OSLibForwardMessageToAttachedThread(pTeb, pMsg, NULL));
    138147    HOOK_CallHooksW(WH_GETMESSAGE, HC_ACTION, PM_REMOVE, (LPARAM)pMsg);
    139148    return ret;
     
    145154{
    146155    BOOL fFoundMsg;
     156    TEB *pTeb = GetThreadTEB();
    147157
    148158    dprintf2(("PeekMessageA %x %d-%d %d", hwndOwner, uMsgFilterMin, uMsgFilterMax, fuRemoveMsg));
    149     fFoundMsg = OSLibWinPeekMsg(msg, hwndOwner, uMsgFilterMin, uMsgFilterMax,
    150                                 fuRemoveMsg, FALSE);
    151     if(fFoundMsg) {
     159    do
     160    {
     161        fFoundMsg = OSLibWinPeekMsg(msg, hwndOwner, uMsgFilterMin, uMsgFilterMax, fuRemoveMsg, FALSE);
     162        if (   fFoundMsg
     163            && pTeb->o.odin.tidAttachedInputThread
     164            && OSLibForwardMessageToAttachedThread(pTeb, msg, NULL));
     165        {
     166            if (!fuRemoveMsg)
     167                OSLibWinPeekMsg(msg, hwndOwner, uMsgFilterMin, uMsgFilterMax, TRUE, FALSE);
     168            continue;
     169        }
     170    } while (0);
     171
     172    if (fFoundMsg) {
    152173        dprintf2(("PeekMessageA %x %d-%d %d found message %x %d %x %x", hwndOwner, uMsgFilterMin, uMsgFilterMax, fuRemoveMsg, msg->hwnd, msg->message, msg->wParam, msg->lParam));
    153174        HOOK_CallHooksA(WH_GETMESSAGE, HC_ACTION, fuRemoveMsg & PM_REMOVE, (LPARAM)msg );
     
    164185{
    165186    BOOL fFoundMsg;
     187    TEB *pTeb = GetThreadTEB();
    166188
    167189    dprintf2(("PeekMessageW %x %d-%d %d", hwndOwner, uMsgFilterMin, uMsgFilterMax, fuRemoveMsg));
    168     fFoundMsg = OSLibWinPeekMsg(msg, hwndOwner, uMsgFilterMin, uMsgFilterMax,
    169                                 fuRemoveMsg, TRUE);
     190    do
     191    {
     192        fFoundMsg = OSLibWinPeekMsg(msg, hwndOwner, uMsgFilterMin, uMsgFilterMax, fuRemoveMsg, TRUE);
     193        if (   fFoundMsg
     194            && pTeb->o.odin.tidAttachedInputThread
     195            && OSLibForwardMessageToAttachedThread(pTeb, msg, NULL));
     196        {
     197            if (!fuRemoveMsg)
     198                OSLibWinPeekMsg(msg, hwndOwner, uMsgFilterMin, uMsgFilterMax, TRUE, TRUE);
     199            continue;
     200        }
     201    } while (0);
     202
    170203    if(fFoundMsg) {
    171204        dprintf2(("PeekMessageW %x %d-%d %d found message %x %d %x %x", hwndOwner, uMsgFilterMin, uMsgFilterMax, fuRemoveMsg, msg->hwnd, msg->message, msg->wParam, msg->lParam));
     
    277310}
    278311//******************************************************************************
     312
     313/**
     314 * Attach one threads input queue to another thread.
     315 *
     316 * @returns Success indicator.
     317 * @param   idAttach    Thread ID of the thread to attach/detach the input
     318 *                      of idAttachTo to.
     319 * @param   idAttachTo  The Thread ID of the thread which input is to be taken
     320 *                      over or reattached.
     321 * @param   fAttach     If set attach the input queue of thread idAttachTo
     322 *                      to idAttach.
     323 *                      If clear detach the input queue of thread idAttach
     324 *                      reattaching it to idAttachTo.
     325 * @status  partially implemented.
     326 * @author  knut st. osmundsen <bird-srcspam@anduin.net>
     327 * @remark  One cannot attach a threads input queue to it self.
     328 * @todo    Not sure if all this is 100% ok according to the windows reality.
     329 *          I'm sure some error cases aren't caught.
     330 */
     331BOOL WIN32API AttachThreadInput(DWORD idAttach, DWORD idAttachTo, BOOL fAttach)
     332{
     333    dprintf(("USER32: AttachThreadInput\n"));
     334    if (idAttach != idAttachTo)
     335    {
     336        /* pray noone frees the TEB while we're working on it... */
     337        TEB *pTeb = GetTEBFromThreadId(idAttach);
     338        if (pTeb)
     339        {
     340            TEB *pTebTo = GetTEBFromThreadId(idAttachTo);
     341            if (pTebTo)
     342            {
     343                if (fAttach)
     344                {   /* attach. */
     345                    if (pTebTo->o.odin.tidAttachedInputThread)
     346                    {
     347                        dprintf(("USER32: AttachThreadInput: WARNING! %#x is already attached to %#x\n", idAttachTo, pTebTo->o.odin.tidAttachedInputThread));
     348                        DebugInt3();
     349                    }
     350                    pTebTo->o.odin.tidAttachedInputThread = idAttach;
     351                    dprintf(("USER32: AttachThreadInput: Attached input from %#x to %#x\n", idAttachTo, idAttach));
     352                }
     353                else
     354                {   /* deattach - i.e. undo previous AttachThreadInput(,,TRUE). */
     355                    if (pTebTo->o.odin.tidAttachedInputThread != idAttach)
     356                    {
     357                        dprintf(("USER32: AttachThreadInput: WARNING! %#x is not attached to %#x\n", idAttachTo, pTebTo->o.odin.tidAttachedInputThread));
     358                        DebugInt3();
     359                    }
     360                    pTebTo->o.odin.tidAttachedInputThread = 0;
     361                    dprintf(("USER32: AttachThreadInput: Detached input from %#x to %#x\n", idAttach, idAttachTo));
     362                }
     363                return TRUE;
     364            }
     365            else
     366            {
     367                dprintf(("USER32: AttachThreadInput: Invalid tid=%#x\n", idAttachTo));
     368                SetLastError(ERROR_INVALID_PARAMETER);
     369            }
     370        }
     371        else
     372        {
     373            dprintf(("USER32: AttachThreadInput: Invalid tid=%#x\n", idAttach));
     374            SetLastError(ERROR_INVALID_PARAMETER);
     375        }
     376    }
     377    else
     378    {
     379        dprintf(("USER32: AttachThreadInput idAttach == idAttachTo (== %#x)\n", idAttach));
     380        SetLastError(ERROR_ACCESS_DENIED);
     381    }
     382    return FALSE;
     383}
     384
    279385//******************************************************************************
    280386/**********************************************************************
Note: See TracChangeset for help on using the changeset viewer.