Changeset 10430 for trunk/src


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

#682: Drag & Drop - AttachThreadInput().

Location:
trunk/src/user32
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/oslibmsg.h

    r10240 r10430  
    1 /* $Id: oslibmsg.h,v 1.23 2003-08-22 13:16:45 sandervl Exp $ */
     1/* $Id: oslibmsg.h,v 1.24 2004-01-30 22:10:06 bird Exp $ */
    22/*
    33 * Window message translation functions for OS/2
     
    5959//Direct posting of messages that must remain invisible to the win32 app
    6060BOOL OSLibPostMessageDirect(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam);
     61BOOL OSLibForwardMessageToAttachedThread(/*TEB*/ void *pvTeb, MSG *pMsg, void *hmm);
    6162
    6263#define WINWM_NULL                  0x0000
  • trunk/src/user32/oslibmsgtranslate.cpp

    r10288 r10430  
    1 /* $Id: oslibmsgtranslate.cpp,v 1.117 2003-10-22 15:56:38 sandervl Exp $ */
     1/* $Id: oslibmsgtranslate.cpp,v 1.118 2004-01-30 22:10:06 bird Exp $ */
    22/*
    33 * Window message translation functions for OS/2
     
    6767BOOL setThreadQueueExtraCharMessage(TEB* teb, MSG* pExtraMsg)
    6868{
     69  if (   teb->o.odin.tidAttachedInputThread
     70      && OSLibForwardMessageToAttachedThread(teb, pExtraMsg, NULL))
     71      return TRUE;
     72
    6973  // check if the single slot is occupied already
    7074  if (teb->o.odin.fTranslated == TRUE) {
     
    165169  BOOL             fIsFrame = FALSE;
    166170  int i;
     171
     172    /*
     173     * Forwarded input (AttachThreadInput()).
     174     */
     175    if (    os2Msg->hwnd == NULLHANDLE
     176        &&  os2Msg->msg == WIN32APP_FORWARDEDPOSTMSG
     177        &&  os2Msg->mp2 == (MPARAM)WIN32APP_FORWARDEDPOSTMSG_MAGIC
     178        &&  os2Msg->mp1 != NULL)
     179    {
     180        *winMsg = *(MSG*)os2Msg->mp1;
     181        if (fMsgRemoved)
     182            _sfree(os2Msg->mp1);
     183        dprintf(("OS2ToWinMsgTranslate: Received forwarded messaged %x\n", os2Msg->msg));
     184        return TRUE;
     185    }
    167186
    168187    memset(winMsg, 0, sizeof(MSG));
     
    12031222//******************************************************************************
    12041223
     1224/**
     1225 * Checks if the message is one that should be forwarded.
     1226 *
     1227 * @returns True if the message should be forwarded.
     1228 * @returns False if the message doesn't fall in to that group.
     1229 * @param   pMsg    Message to examin.
     1230 */
     1231BOOL OSLibForwardableMessage(const MSG *pMsg)
     1232{
     1233    return (    (pMsg->message >= WINWM_KEYFIRST   && pMsg->message <= WINWM_KEYLAST)
     1234            ||  (pMsg->message >= WINWM_MOUSEFIRST && pMsg->message <= WINWM_MOUSELAST) );
     1235}
     1236
     1237/**
     1238 * Forwards this message to the attached thread if it's in the group of messages
     1239 * which is supposed to be forwarded.
     1240 *
     1241 * @returns True if forwarded.
     1242 * @returns False if not forwarded.
     1243 * @param   pTeb    Pointer to the TEB of the current thread.
     1244 * @param   pMsg    Message to forward.
     1245 * @author  knut st. osmundsen <bird-srcspam@anduin.net>
     1246 */
     1247BOOL OSLibForwardMessageToAttachedThread(void *pvTeb, MSG *pMsg, void *hmm)
     1248{
     1249    TEB *pTeb = (TEB *)pvTeb;
     1250    dprintf(("OSLibForwardMessageToAttachedThread: %p %p (msg=%x)\n", pvTeb, pMsg, pMsg->message));
     1251    if (!OSLibForwardableMessage(pMsg))
     1252        return FALSE;
     1253
     1254    /*
     1255     * Find the actual receiver thread.
     1256     */
     1257    int c = 100;
     1258    TEB *pTebTo = pTeb;
     1259    do
     1260    {
     1261        pTebTo = GetTEBFromThreadId(pTebTo->o.odin.tidAttachedInputThread);
     1262    } while (c-- > 0 && !pTebTo && pTebTo->o.odin.tidAttachedInputThread);
     1263    if (!c || !pTebTo)
     1264    {
     1265        if (c)  dprintf(("OSLibForwardMessageToAttachedThread: The receiver thread is dead or non existing.\n"));
     1266        else    dprintf(("OSLibForwardMessageToAttachedThread: threads are attached in looooop.\n"));
     1267        return FALSE; /* hmm.... */
     1268    }
     1269    dprintf(("OSLibForwardMessageToAttachedThread: Forwarding message %#x to %#x\n",
     1270             pMsg->message, pTeb->o.odin.tidAttachedInputThread));
     1271
     1272    /*
     1273     * Pack down the message into shared memory.
     1274     */
     1275    MSG *pMsgCopy = (MSG *)_smalloc(sizeof(MSG));
     1276    if (!pMsgCopy)
     1277        return FALSE;
     1278    *pMsgCopy = *pMsg;
     1279
     1280    /*
     1281     * Figure out how we should send the message.
     1282     */
     1283    if (WinInSendMsg(pTebTo->o.odin.hab))
     1284    {
     1285#if 0
     1286        /*
     1287         * Hmm what do we do here....
     1288         */
     1289        MRESULT rc = WinSendQueueMsg(pTebTo->o.odin.hmq, /*special! */, pMsgCopy, /*magic*/ );
     1290        /* if (hmmSendMsgResult)
     1291            *hmmSendMsgResult = (???)rc; */
     1292#else
     1293        dprintf(("OSLibForwardMessage: ERROR! %x in sendmsg!!!\n", pMsg->message));
     1294        DebugInt3();
     1295
     1296        _sfree(pMsgCopy);
     1297        return FALSE;
     1298#endif
     1299    }
     1300    else
     1301    {
     1302        if (!WinPostQueueMsg(pTebTo->o.odin.hmq, WIN32APP_FORWARDEDPOSTMSG, pMsgCopy, (MPARAM)WIN32APP_FORWARDEDPOSTMSG_MAGIC))
     1303        {
     1304            dprintf(("OSLibForwardMessage: Failed to post queue message to hmq=%#x\n", pTebTo->o.odin.hmq));
     1305            _sfree(pMsgCopy);
     1306        }
     1307    }
     1308
     1309    return TRUE;
     1310}
  • 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.