Changeset 10012 for trunk/src


Ignore:
Timestamp:
Apr 11, 2003, 4:22:06 PM (22 years ago)
Author:
sandervl
Message:

KSO: Implemented WM_COPYDATA

Location:
trunk/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kernel32/wprocess.cpp

    r9971 r10012  
    1 /* $Id: wprocess.cpp,v 1.186 2003-04-02 11:03:33 sandervl Exp $ */
     1/* $Id: wprocess.cpp,v 1.187 2003-04-11 14:21:53 sandervl Exp $ */
    22
    33/*
     
    373373    if(winteb->o.odin.hPostMsgEvent) {
    374374        CloseHandle(winteb->o.odin.hPostMsgEvent);
     375    }
     376
     377    // free shared memory for WM_COPYDATA
     378    if (winteb->o.odin.pWM_COPYDATA)
     379    {
     380        dprintf(("DestroyTEB: freeing WM_COPYDATA: %#p", winteb->o.odin.pWM_COPYDATA));
     381        _sfree(winteb->o.odin.pWM_COPYDATA);
    375382    }
    376383
     
    20052012
    20062013    //Only use WGSS to launch the app if it's not PE or PE & win32k loaded
    2007     if(!fPEExe || (fPEExe && fWin32k)) 
     2014    if(!fPEExe || (fPEExe && fWin32k))
    20082015    {
    20092016      if(O32_CreateProcess(szAppName, lpCommandLine, lpProcessAttributes,
     
    20312038            lpProcessInfo->dwThreadId = MAKE_THREADID(lpProcessInfo->dwProcessId, lpProcessInfo->dwThreadId);
    20322039        }
    2033  
     2040
    20342041        if(cmdline)
    20352042            free(cmdline);
    20362043        return(TRUE);
    20372044      }
    2038  
     2045
    20392046      // verify why O32_CreateProcess actually failed.
    20402047      // If GetLastError() == 191 (ERROR_INVALID_EXE_SIGNATURE)
  • trunk/src/user32/oslibmsg.cpp

    r9950 r10012  
    1 /* $Id: oslibmsg.cpp,v 1.67 2003-03-28 11:49:01 sandervl Exp $ */
     1/* $Id: oslibmsg.cpp,v 1.68 2003-04-11 14:22:05 sandervl Exp $ */
    22/*
    33 * Window message translation functions for OS/2
     
    5353#include "user32api.h"
    5454
    55 #define DBG_LOCALLOG    DBG_oslibmsg
     55#define DBG_LOCALLOG    DBG_oslibmsg
    5656#include "dbglocal.h"
    5757
     
    210210        teb->o.odin.winmsg.time = -1;
    211211        if(msg->hwnd) {
    212                 teb->o.odin.nrOfMsgs = 1;
    213                 teb->o.odin.msgstate++; //odd -> next call to our PM window handler should dispatch the translated msg
    214                 memcpy(&teb->o.odin.msg, msg, sizeof(MSG));
     212                teb->o.odin.nrOfMsgs = 1;
     213                teb->o.odin.msgstate++; //odd -> next call to our PM window handler should dispatch the translated msg
     214                memcpy(&teb->o.odin.msg, msg, sizeof(MSG));
    215215        }
    216216        if(os2msg.hwnd || os2msg.msg == WM_QUIT) {
    217                 memset(&teb->o.odin.os2msg, 0, sizeof(teb->o.odin.os2msg));
    218                 memset(&teb->o.odin.winmsg, 0, sizeof(teb->o.odin.winmsg));
    219                 return (LONG)WinDispatchMsg(teb->o.odin.hab, &os2msg);
     217                memset(&teb->o.odin.os2msg, 0, sizeof(teb->o.odin.os2msg));
     218                memset(&teb->o.odin.winmsg, 0, sizeof(teb->o.odin.winmsg));
     219                return (LONG)WinDispatchMsg(teb->o.odin.hab, &os2msg);
    220220        }
    221221        //SvL: Don't dispatch messages sent by PostThreadMessage (correct??)
     
    241241
    242242    if(hwnd) {
    243         hwndOS2 = Win32ToOS2Handle(hwnd);
    244         if(hwndOS2 == NULL) {
    245                     memset(pMsg, 0, sizeof(MSG));
    246                     dprintf(("GetMsg: window %x NOT FOUND!", hwnd));
    247                     SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
    248                     return TRUE;
    249             }
     243        hwndOS2 = Win32ToOS2Handle(hwnd);
     244        if(hwndOS2 == NULL) {
     245                    memset(pMsg, 0, sizeof(MSG));
     246                    dprintf(("GetMsg: window %x NOT FOUND!", hwnd));
     247                    SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
     248                    return TRUE;
     249            }
    250250    }
    251251
     
    253253    if(teb == NULL) {
    254254        DebugInt3();
    255         return TRUE;
    256     }
    257    
    258     if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd)) 
     255        return TRUE;
     256    }
     257
     258    if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd))
    259259    {
    260260        dprintf(("Return queued WM_CHAR message hwnd=%x msg=%d wParam=%x lParam=%x", teb->o.odin.msgWCHAR.hwnd, teb->o.odin.msgWCHAR.message, teb->o.odin.msgWCHAR.wParam, teb->o.odin.msgWCHAR.lParam));
     
    277277        teb->o.odin.os2msg.msg  = 0;
    278278        teb->o.odin.os2msg.hwnd = 0;
    279    
     279
    280280        if(!IsWindow(pMsg->hwnd)) {
    281281            //could be a queued char message for a window that was just destroyed
     
    306306continuegetmsg:
    307307    if(hwnd) {
    308         filtermin = TranslateWinMsg(uMsgFilterMin, TRUE);
    309             filtermax = TranslateWinMsg(uMsgFilterMax, FALSE);
    310             if(filtermin > filtermax) {
    311                 ULONG tmp = filtermin;
    312                     filtermin = filtermax;
    313                     filtermax = filtermin;
    314             }
     308        filtermin = TranslateWinMsg(uMsgFilterMin, TRUE);
     309            filtermax = TranslateWinMsg(uMsgFilterMax, FALSE);
     310            if(filtermin > filtermax) {
     311                ULONG tmp = filtermin;
     312                    filtermin = filtermax;
     313                    filtermax = filtermin;
     314            }
    315315        do {
    316                 WinWaitMsg(teb->o.odin.hab, filtermin, filtermax);
    317                 rc = OSLibWinPeekMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, PM_REMOVE_W, isUnicode);
     316                WinWaitMsg(teb->o.odin.hab, filtermin, filtermax);
     317                rc = OSLibWinPeekMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, PM_REMOVE_W, isUnicode);
    318318        }
    319319        while(rc == FALSE);
     
    323323    else
    324324    {
    325         filtermin = TranslateWinMsg(uMsgFilterMin, TRUE);
    326             filtermax = TranslateWinMsg(uMsgFilterMax, FALSE);
    327             if(filtermin > filtermax) {
    328                 ULONG tmp = filtermin;
    329                     filtermin = filtermax;
    330                     filtermax = filtermin;
    331             }
    332         do {
    333                 eaten = FALSE;
    334                 rc = WinGetMsg(teb->o.odin.hab, &os2msg, 0, filtermin, filtermax);
    335                 if (os2msg.msg == WM_TIMER)
    336                     eaten = TIMER_HandleTimer(&os2msg);
     325        filtermin = TranslateWinMsg(uMsgFilterMin, TRUE);
     326            filtermax = TranslateWinMsg(uMsgFilterMax, FALSE);
     327            if(filtermin > filtermax) {
     328                ULONG tmp = filtermin;
     329                    filtermin = filtermax;
     330                    filtermax = filtermin;
     331            }
     332        do {
     333                eaten = FALSE;
     334                rc = WinGetMsg(teb->o.odin.hab, &os2msg, 0, filtermin, filtermax);
     335                if (os2msg.msg == WM_TIMER)
     336                    eaten = TIMER_HandleTimer(&os2msg);
    337337                if (os2msg.msg == WM_QUIT && ((ULONG)os2msg.mp2 != 0) ) {
    338338                    // Don't return FALSE when the window list sends us
     
    342342                    // in this case. When the app calls PostQuitMessage (mp2 == 0),
    343343                    // then we handle it the normal way
    344                     rc = 1; 
     344                    rc = 1;
    345345                }
    346             }
     346            }
    347347        while (eaten);
    348348    }
     
    356356    memcpy(&teb->o.odin.os2msg, &os2msg, sizeof(QMSG));
    357357    memcpy(&teb->o.odin.winmsg, pMsg, sizeof(MSG));
    358  
     358
    359359    // send keyboard messages to the registered hooks
    360360    switch (pMsg->message)
     
    375375
    376376//******************************************************************************
    377 //PeekMessage retrieves only messages associated with the window identified by the 
    378 //hwnd parameter or any of its children as specified by the IsChild function, and within 
    379 //the range of message values given by the uMsgFilterMin and uMsgFilterMax 
    380 //parameters. If hwnd is NULL, PeekMessage retrieves messages for any window that 
    381 //belongs to the current thread making the call. (PeekMessage does not retrieve 
    382 //messages for windows that belong to other threads.) If hwnd is -1, PeekMessage only 
    383 //returns messages with a hwnd value of NULL, as posted by the PostAppMessage 
    384 //function. If uMsgFilterMin and uMsgFilterMax are both zero, PeekMessage returns all 
    385 //available messages (no range filtering is performed). 
     377//PeekMessage retrieves only messages associated with the window identified by the
     378//hwnd parameter or any of its children as specified by the IsChild function, and within
     379//the range of message values given by the uMsgFilterMin and uMsgFilterMax
     380//parameters. If hwnd is NULL, PeekMessage retrieves messages for any window that
     381//belongs to the current thread making the call. (PeekMessage does not retrieve
     382//messages for windows that belong to other threads.) If hwnd is -1, PeekMessage only
     383//returns messages with a hwnd value of NULL, as posted by the PostAppMessage
     384//function. If uMsgFilterMin and uMsgFilterMax are both zero, PeekMessage returns all
     385//available messages (no range filtering is performed).
    386386//TODO: Not working as specified right now!
    387387//******************************************************************************
     
    401401    }
    402402    if(hwnd && hwnd != -1) {
    403             hwndOS2 = Win32ToOS2Handle(hwnd);
    404             if(hwndOS2 == NULL) {
    405                 dprintf(("PeekMsg: window %x NOT FOUND!", hwnd));
    406                     SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
    407                     return FALSE;
    408             }
     403            hwndOS2 = Win32ToOS2Handle(hwnd);
     404            if(hwndOS2 == NULL) {
     405                dprintf(("PeekMsg: window %x NOT FOUND!", hwnd));
     406                    SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
     407                    return FALSE;
     408            }
    409409    }
    410410
     
    415415    }
    416416
    417     if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd)) 
     417    if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd))
    418418    {
    419419        dprintf(("Return queued WM_CHAR message hwnd=%x msg=%d wParam=%x lParam=%x", teb->o.odin.msgWCHAR.hwnd, teb->o.odin.msgWCHAR.message, teb->o.odin.msgWCHAR.wParam, teb->o.odin.msgWCHAR.lParam));
     
    447447            goto continuepeekmsg;
    448448        }
    449    
     449
    450450        // @@@PH verify this
    451451        // if this is a keyup or keydown message, we've got to
     
    466466            }
    467467        }
    468    
     468
    469469        return TRUE;
    470470    }
    471471
    472472continuepeekmsg:
    473     if(uMsgFilterMin && uMsgFilterMax) 
     473    if(uMsgFilterMin && uMsgFilterMax)
    474474    {   //we can't use the PM message filter (since the message nrs aren't similar), so we must
    475475        //filter each message seperately
     
    485485                    eaten = FALSE;
    486486
    487                     rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, ulPMFilter, ulPMFilter, 
     487                    rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, ulPMFilter, ulPMFilter,
    488488                                    (fRemove & PM_REMOVE_W) ? PM_REMOVE : PM_NOREMOVE);
    489489                    //Sadly indeed WinPeekMsg sometimes does not filter well!
    490490                    if (rc && (os2msg.msg != ulPMFilter)) {// drop this message
    491491                       dprintf(("WARNING: WinPeekMsg returns %x even though we filter for %x", os2msg.msg, ulPMFilter));
    492                        rc = 0;   
     492                       rc = 0;
    493493                    }
    494494                    if (rc && (fRemove & PM_REMOVE_W) && os2msg.msg == WM_TIMER) {
     
    518518        return FALSE;
    519519    }
    520  
     520
    521521    // @@@PH
    522522    // warning - OS2ToWinMsgTranslate might insert additional messages
    523523    // into the queue
    524     if(OS2ToWinMsgTranslate((PVOID)teb, &os2msg, pMsg, isUnicode, (fRemove & PM_REMOVE_W) ? MSG_REMOVE : MSG_NOREMOVE) == FALSE) 
     524    if(OS2ToWinMsgTranslate((PVOID)teb, &os2msg, pMsg, isUnicode, (fRemove & PM_REMOVE_W) ? MSG_REMOVE : MSG_NOREMOVE) == FALSE)
    525525    {
    526526         //unused PM message; dispatch immediately and grab next one
     
    535535    //TODO: This is not safe! There's no guarantee this message will be dispatched and it might overwrite a previous message
    536536    if(fRemove & PM_REMOVE_W) {
    537         memcpy(&teb->o.odin.os2msg, &os2msg, sizeof(QMSG));
    538         memcpy(&teb->o.odin.winmsg, pMsg, sizeof(MSG));
     537        memcpy(&teb->o.odin.os2msg, &os2msg, sizeof(QMSG));
     538        memcpy(&teb->o.odin.winmsg, pMsg, sizeof(MSG));
    539539    }
    540540
     
    627627    return (BOOL)WinReplyMsg( NULLHANDLE, NULLHANDLE, HMQ_CURRENT, (MRESULT)result);
    628628}
    629 //******************************************************************************
    630 //******************************************************************************
     629
     630//******************************************************************************
     631
     632/**
     633 * Send and Post message helper for packing down interprocess and interthread messages.
     634 *
     635 * @returns Pointer to packet on success. (shared memory)
     636 * @returns NULL on failure with SendMessage return code suggestion in *pRc if pRc is set.
     637 * @param   hwndOdin    Odin window handle. (NULL allowed)
     638 * @param   hwndOS2     OS/2 window handle.
     639 * @param   msg         Message id.
     640 * @param   wParam      Message param.
     641 * @param   lParam      Message param.
     642 * @param   fUnicode    Unicode or ansi indicator.
     643 * @param   pRc         Where to store SendMessage return code. Optional.
     644 * @author  knut st. osmundsen<bird@anduin.net>
     645 */
     646void * OSLibPackMessage(HWND hwndOdin, HWND hwndOS2, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode, PULONG pRc)
     647{
     648    POSTMSG_PACKET  * pMsgPacket;
     649
     650    /*
     651     * Pack message by id.
     652     */
     653    switch (msg)
     654    {
     655        /*
     656         * lParam = PCOPYDATASTRUCT.
     657         *      Must move this to shared memory together with any
     658         *      data it's pointing at.
     659         *
     660         *      We put everything into the package that might ease cleanup...
     661         *      WARNING! Currently there are cleanup hacks which works with acrobat.
     662         */
     663        case WINWM_COPYDATA:
     664        {
     665            PCOPYDATASTRUCT_W pOrg = (PCOPYDATASTRUCT_W)lParam;
     666            dprintf(("user32::oslibmsg::OSLibPackMessage - WM_COPYDATA: lParam=%#x  dwData=%#x cbData=%d lpData=%#x",
     667                     pOrg, pOrg ? pOrg->dwData : -1, pOrg ? pOrg->cbData : -1, pOrg ? pOrg->lpData : (LPVOID)-1));
     668
     669            /*
     670             * Calc packet size.
     671             */
     672            unsigned cb = sizeof(POSTMSG_PACKET);
     673            if (pOrg)
     674            {
     675                cb += sizeof(COPYDATASTRUCT_W);
     676                if (pOrg->lpData && pOrg->cbData)
     677                    cb += 16 + pOrg->cbData; //add 16 Bytes for safty and alignment.
     678            }
     679
     680            /*
     681             * Allocate packet.
     682             */
     683            pMsgPacket = (POSTMSG_PACKET *)_smalloc(cb);
     684            if (!pMsgPacket)
     685            {
     686                dprintf(("user32::oslibmsg::OSLibPackMessage - WM_COPYDATA: failed to allocate %d shared bytes for packing", cb));
     687                DebugInt3();
     688                if (pRc)
     689                    *pRc = FALSE;
     690                //@todo figure out which error to set. This is plain guesswork!
     691                SetLastError(ERROR_NOT_ENOUGH_MEMORY_W);
     692                break;
     693            }
     694
     695            /*
     696             * Initialize packet.
     697             */
     698            PCOPYDATASTRUCT_W pNew = (PCOPYDATASTRUCT_W)(pMsgPacket + 1);
     699            pMsgPacket->wParam = wParam;
     700            pMsgPacket->lParam = (LPARAM)pNew;
     701            *pNew = *pOrg;
     702            if (pNew->cbData && pNew->lpData)
     703            {
     704                pNew->lpData = (LPVOID)(((unsigned)(pNew + 1) + 15) & ~15); //16byte align for safty.
     705                //@todo what about a safe_memcpy?
     706                memcpy(pNew->lpData, pOrg->lpData, pNew->cbData);
     707            }
     708
     709            /* done! */
     710            dprintf(("user32::oslibmsg::OSLibPackMessage - WM_COPYDATA: Packed down %d bytes at %#x (pMsgPacket)",
     711                     cb, pMsgPacket));
     712            break;
     713        }
     714
     715
     716        /*
     717         * Default packing
     718         */
     719        default:
     720        {
     721            pMsgPacket = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
     722            if (!pMsgPacket)
     723            {
     724                dprintf(("user32::oslibmsg::OSLibPackMessage - allocated packet structure is NULL"));
     725                if (pRc)
     726                {   // Can't find any better return code than 0 :/
     727                    *pRc = 0;
     728                }
     729                DebugInt3();
     730                break;
     731            }
     732            pMsgPacket->wParam = wParam;
     733            pMsgPacket->lParam = lParam;
     734        }
     735
     736    }
     737
     738    return pMsgPacket;
     739}
     740
     741
     742/**
     743 * Send an inter thread/proces message.
     744 *
     745 * @returns
     746 * @param   hwnd        OS/2 hwnd.
     747 * @param   msg         Odin message id.
     748 * @param   wParam      Message param.
     749 * @param   lParam      Message param.
     750 * @param   fUnicode    Unicode indicator.
     751 */
    631752ULONG OSLibSendMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode)
    632753{
    633     POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
    634  
    635     if(NULL == packet)
    636     {
    637         dprintf(("user32::oslibmsg::OSLibSendMessage - allocated packet structure is NULL"));
    638    
    639         // PH: we cannot provide a correct returncode :(
    640         DebugInt3();   
    641         return 0;
    642     }
    643  
    644     packet->wParam   = wParam;
    645     packet->lParam   = lParam;
    646 
    647     return (ULONG)WinSendMsg(hwnd, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet);
    648 }
     754    ULONG           rc;                 /* return code on packing failure */
     755    void *          pvMsgPacket;        /* packed message (shared memory) */
     756
     757    /*
     758     * Call message packer.
     759     */
     760    pvMsgPacket = OSLibPackMessage(NULLHANDLE, hwnd, msg, wParam, lParam, fUnicode, &rc);
     761    if (!pvMsgPacket)
     762    {
     763        dprintf(("user32::oslibmsg::OSLibSendMessage - Failed to pack message !!"));
     764        DebugInt3();
     765        return rc;
     766    }
     767
     768    return (ULONG)WinSendMsg(hwnd, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), pvMsgPacket);
     769}
     770
    649771//******************************************************************************
    650772//******************************************************************************
    651773ULONG OSLibWinBroadcastMsg(ULONG msg, ULONG wParam, ULONG lParam, BOOL fSend)
    652774{
     775    #ifdef DEBUG
     776    if (msg == WINWM_COPYDATA)
     777    {
     778        dprintf(("user32::oslibmsg::OSLibWinBroadcastMsg - WM_COPYDATA will not work outside this process !!!"));
     779        DebugInt3();
     780    }
     781    #endif
    653782    return WinBroadcastMsg(HWND_DESKTOP, WIN32APP_POSTMSG+msg, (MPARAM)wParam, (MPARAM)lParam,
    654783                           (fSend) ? BMSG_SEND : BMSG_POST);
    655784}
    656 //******************************************************************************
    657 //******************************************************************************
     785
     786
     787/**
     788 * Post a message.
     789 *
     790 * @returns Success indicator.
     791 *
     792 * @param   hwndWin32   Odin window handle.
     793 * @param   hwndOS2     OS/2 window handle
     794 * @param   msg         Odin message id.
     795 * @param   wParam      Message param.
     796 * @param   lParam      Message param.
     797 * @param   fUnicode    Unicode indicator.
     798 */
    658799BOOL OSLibPostMessage(HWND hwndWin32, HWND hwndOS2, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode)
    659800{
    660     POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
    661     BOOL ret;
    662 
    663     if (NULL == packet)
    664     {
    665         dprintf(("user32::oslibmsg::OSLibPostMessage - allocated packet structure is NULL"));
    666    
    667         // PH: we can provide a correct returncode
    668         DebugInt3();   
     801    void *          pvMsgPacket;        /* packed message (shared memory) */
     802
     803    /*
     804     * Call message packer.
     805     */
     806    pvMsgPacket = OSLibPackMessage(hwndWin32, hwndOS2, msg, wParam, lParam, fUnicode, NULL);
     807    if (!pvMsgPacket)
     808    {
     809        dprintf(("user32::oslibmsg::OSLibPostMessage - Failed to pack message !!"));
     810        DebugInt3();
    669811        return FALSE;
    670812    }
     813
     814    /*
     815     * Post the message.
     816     * Signal the receiver for if it's doing MsgWaitForMultipleObjects() at the time.
     817     */
    671818    TEB *teb = GetTEBFromThreadId(GetWindowThreadProcessId(hwndWin32, NULL));
    672 
    673     packet->wParam   = wParam;
    674     packet->lParam   = lParam;
    675     ret = WinPostMsg(hwndOS2, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet);
    676 
    677     if(teb && (teb->o.odin.dwWakeMask & QS_POSTMESSAGE_W)) {
     819    BOOL ret = WinPostMsg(hwndOS2,
     820                          WIN32APP_POSTMSG+msg,
     821                          (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA),
     822                          pvMsgPacket);
     823    if (teb && (teb->o.odin.dwWakeMask & QS_POSTMESSAGE_W))
     824    {
    678825        //thread is blocked in MsgWaitForMultipleObjects waiting for
    679826        //posted messages
     
    697844    POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
    698845    BOOL ret;
    699  
    700     if(NULL == packet)
     846
     847    if (NULL == packet)
    701848    {
    702849        dprintf(("user32::oslibmsg::OSLibPostMessage - allocated packet structure is NULL"));
    703850
    704         DebugInt3();   
     851        DebugInt3();
    705852        // PH: we can provide a correct returncode
    706853        return FALSE;
    707854    }
    708    
     855
    709856    if(teb == NULL) {
    710857        dprintf(("OSLibPostThreadMessage: thread %x not found!", threadid));
     
    715862    packet->lParam   = lParam;
    716863
    717     ret = WinPostQueueMsg((HMQ)teb->o.odin.hmq, WIN32APP_POSTMSG+msg, 
    718                           (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), 
     864    ret = WinPostQueueMsg((HMQ)teb->o.odin.hmq, WIN32APP_POSTMSG+msg,
     865                          (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA),
    719866                          (MPARAM)packet);
    720867
  • trunk/src/user32/oslibmsg.h

    r9598 r10012  
    1 /* $Id: oslibmsg.h,v 1.19 2003-01-03 16:35:54 sandervl Exp $ */
     1/* $Id: oslibmsg.h,v 1.20 2003-04-11 14:22:05 sandervl Exp $ */
    22/*
    33 * Window message translation functions for OS/2
     
    1414
    1515
     16typedef struct tagCOPYDATASTRUCT_W
     17{
     18    DWORD   dwData;
     19    DWORD   cbData;
     20    LPVOID  lpData;
     21} COPYDATASTRUCT_W, *PCOPYDATASTRUCT_W, *LPCOPYDATASTRUCT_W;
     22
     23
    1624#ifdef __cplusplus
    1725
    1826ULONG TranslateWinMsg(ULONG msg);
    1927
    20 #define MSG_NOREMOVE    0
    21 #define MSG_REMOVE      1
     28#define MSG_NOREMOVE    0
     29#define MSG_REMOVE      1
    2230
    2331#ifdef OS2DEF_INCLUDED
     
    2735#endif
    2836
    29 BOOL  OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, 
     37BOOL  OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin,
    3038                     UINT uMsgFilterMax, BOOL isUnicode = FALSE);
    31 BOOL  OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, 
     39BOOL  OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin,
    3240                      UINT uMsgFilterMax, DWORD fRemove, BOOL isUnicode = FALSE);
    3341void  OSLibWinPostQuitMessage(ULONG nExitCode);
  • trunk/src/user32/oslibmsgtranslate.cpp

    r9950 r10012  
    1 /* $Id: oslibmsgtranslate.cpp,v 1.107 2003-03-28 11:49:01 sandervl Exp $ */
     1/* $Id: oslibmsgtranslate.cpp,v 1.108 2003-04-11 14:22:06 sandervl Exp $ */
    22/*
    33 * Window message translation functions for OS/2
     
    5252//PF Correction is different for different mouse drivers. For now no correction
    5353//is ok because lots of Odin controls rely on minimum delta. However in future
    54 //we will possibly detect mouse driver and use correction if speed will be 
     54//we will possibly detect mouse driver and use correction if speed will be
    5555//too high or too low.
    56  
     56
    5757//******************************************************************************
    5858//******************************************************************************
     
    9090           ret = pmScan;
    9191  }
    92  
     92
    9393  KeyTranslatePMScanToWinVKey(ret, FALSE, (PBYTE)&winKey, NULL, NULL);
    9494  return winKey;
     
    127127}
    128128//******************************************************************************
     129
     130
     131/**
     132 * Inter process/thread packet cleanup.
     133 * See OSLibPackMessage() for details on the packing.
     134 *
     135 * @param   pTeb        Pointer to the thread environment block for the current thread.
     136 * @param   pPacket     Pointer to the packet in question.
     137 * @param   pWinMsg     Pointer to the window message corresponding to the packet.
     138 */
     139inline void OSLibCleanupPacket(TEB *pTeb, POSTMSG_PACKET *pPacket, MSG *pWinMsg)
     140{
     141    switch (pWinMsg->message)
     142    {
     143        /*
     144         * Place this in the TEB freeing any previous WM_COPYDATA packet.
     145         * Note! Nested WM_COPYDATA isn't working.
     146         */
     147        case WINWM_COPYDATA:
     148        {
     149            dprintf(("OSLibCleanupPacket: WM_COPYDATA: old %#p  new %#p", pTeb->o.odin.pWM_COPYDATA, pPacket));
     150            if (pTeb->o.odin.pWM_COPYDATA)
     151                _sfree(pTeb->o.odin.pWM_COPYDATA);
     152            pTeb->o.odin.pWM_COPYDATA = pPacket;
     153            break;
     154        }
     155
     156        /*
     157         * Default packing - free the shared memory here.
     158         */
     159        default:
     160            _sfree(pPacket);
     161            break;
     162    }
     163}
     164
    129165//******************************************************************************
    130166BOOL OS2ToWinMsgTranslate(void *pTeb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fMsgRemoved)
     
    167203            winMsg->wParam  = packet->wParam;
    168204            winMsg->lParam  = packet->lParam;
    169             if(fMsgRemoved == MSG_REMOVE) free(packet); //free the shared memory here
     205            if (fMsgRemoved == MSG_REMOVE)
     206                OSLibCleanupPacket(teb, packet, winMsg);
    170207            if(win32wnd) RELEASE_WNDOBJ(win32wnd);
    171208            return TRUE;
     
    407444            (winMsg->message == WINWM_NCMBUTTONDOWN))
    408445        {
    409             if(fGenerateDoubleClick && doubleClickMsg.message == winMsg->message && 
     446            if(fGenerateDoubleClick && doubleClickMsg.message == winMsg->message &&
    410447               winMsg->time - doubleClickMsg.time < GetDoubleClickTime() &&
    411448               (abs(winMsg->pt.x - doubleClickMsg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK_W)/2) &&
    412                (abs(winMsg->pt.y - doubleClickMsg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK_W)/2)) 
     449               (abs(winMsg->pt.y - doubleClickMsg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK_W)/2))
    413450            {
    414451                 dprintf(("single -> double click"));
     
    440477            }
    441478            else msg = winMsg->message;
    442            
     479
    443480            if(msg == WINWM_LBUTTONDBLCLK) {
    444481                msg = WINWM_LBUTTONDOWN;
     
    589626            //FALSE -> keyboard operation = user pressed Alt-F4 -> close app
    590627            //TRUE  -> user clicked on close button -> close window
    591             if(SHORT2FROMMP(os2Msg->mp2) == FALSE) 
     628            if(SHORT2FROMMP(os2Msg->mp2) == FALSE)
    592629            {
    593630                HWND hwnd = win32wnd->GetTopParent();
     
    655692      // NO BREAK! FALLTHRU CASE!
    656693    }
    657      
     694
    658695    case WM_CHAR_SPECIAL:
    659696    {
     
    665702      // NO BREAK! FALLTHRU CASE!
    666703    }
    667      
     704
    668705    case WM_CHAR:
    669706    {
     
    674711      ULONG  flags = SHORT1FROMMP(os2Msg->mp1);
    675712      BOOL   keyWasPressed;
    676       BOOL   numPressed = (BOOL)(WinGetKeyState(HWND_DESKTOP,VK_NUMLOCK) & 1);       
     713      BOOL   numPressed = (BOOL)(WinGetKeyState(HWND_DESKTOP,VK_NUMLOCK) & 1);
    677714      char   c;
    678715      USHORT usPMScanCode = CHAR4FROMMP(os2Msg->mp1);
     
    693730
    694731        KeyTranslatePMScanToWinVKey(usPMScanCode,
    695                                     FALSE, 
     732                                    FALSE,
    696733                                    &bWinVKey,
    697734                                    &wWinScan,
     
    700737        winMsg->lParam  = repeatCount & 0x0FFFF;                 // bit 0-15, repeatcount
    701738        winMsg->lParam |= (wWinScan & 0x1FF) << 16;  // bit 16-23, scancode + bit 15 extended
    702      
     739
    703740        // Set the extended bit when appropriate
    704741        if (fWinExtended)
    705742            winMsg->lParam = winMsg->lParam | WIN_KEY_EXTENDED;
    706743
    707         //PF When we press shift we enable non-numeric functions of Numpad
     744        //PF When we press shift we enable non-numeric functions of Numpad
    708745        if ((!numPressed || (flags & KC_SHIFT)) && (scanCode >= PMSCAN_PAD7) && (scanCode <= PMSCAN_PADPERIOD))
    709746             winMsg->wParam = ConvertNumPadKey(scanCode);
     
    728765            winMsg->lParam = 0x01460001;
    729766        }
    730      
     767
    731768        if (!(flags & KC_ALT))
    732769        {
     
    745782              // held ALT-key when current key is released
    746783              // generates additional flag 0x2000000
    747               // Note: PM seems to do this differently, 
     784              // Note: PM seems to do this differently,
    748785              // KC_ALT is already reset
    749786            }
     
    756793            winMsg->lParam |= 1 << 31;                              // bit 31, transition state, always 1 for WM_KEYUP
    757794          }
    758           else 
     795          else
    759796          { // send WM_KEYDOWN message
    760797            winMsg->message = WINWM_KEYDOWN;
     
    762799            if (keyWasPressed)
    763800              winMsg->lParam |= WIN_KEY_PREVSTATE;                  // bit 30, previous state, 1 means key was pressed
    764              
     801
    765802            //Shift-Enter and possibly others need to have special handling
    766803            if (flags & KC_SHIFT)
    767804            {
    768805                if(fMsgRemoved && !(teb->o.odin.fTranslated))
    769                 {                   
     806                {
    770807                  dprintf(("PM: KC_SHIFT: %x",winMsg->wParam));
    771808                  if (winMsg->wParam == VK_RETURN_W)
     
    773810                    MSG extramsg;
    774811                    memcpy(&extramsg, winMsg, sizeof(MSG));
    775    
     812
    776813                    //After SetFocus(0), all keystrokes are converted in WM_SYS*
    777814                    extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
     
    791828                    MSG extramsg;
    792829                    memcpy(&extramsg, winMsg, sizeof(MSG));
    793    
     830
    794831                    //After SetFocus(0), all keystrokes are converted in WM_SYS*
    795832                    extramsg.message = (fIgnoreKeystrokes) ? WINWM_SYSCHAR : WINWM_CHAR;
     
    802839          // if right alt is down, then we need to set the alt down bit too
    803840          // except for the fake Ctrl WM_CHAR sent for AltGr emulation
    804           if (os2Msg->msg != WM_CHAR_SPECIAL_ALTGRCONTROL && 
    805               (WinGetKeyState(HWND_DESKTOP, VK_ALTGRAF) & 0x8000)) 
     841          if (os2Msg->msg != WM_CHAR_SPECIAL_ALTGRCONTROL &&
     842              (WinGetKeyState(HWND_DESKTOP, VK_ALTGRAF) & 0x8000))
    806843          {
    807               winMsg->lParam |= WIN_KEY_ALTHELD;           
     844              winMsg->lParam |= WIN_KEY_ALTHELD;
    808845          }
    809846        }
    810         else 
     847        else
    811848        {
    812849          //
     
    817854             //@@PF Note that without pmkbdhook there will not be correct message for Alt-Enter
    818855              winMsg->message = WINWM_SYSKEYUP;
    819               winMsg->lParam |= WIN_KEY_PREVSTATE;           
     856              winMsg->lParam |= WIN_KEY_PREVSTATE;
    820857              // No ALTHELD for Alt itself ;)
    821               winMsg->lParam |= WIN_KEY_ALTHELD;           
    822               winMsg->lParam |= 1 << 31;                              // bit 31, transition state, always 1 for WM_KEYUP
     858              winMsg->lParam |= WIN_KEY_ALTHELD;
     859              winMsg->lParam |= 1 << 31;                              // bit 31, transition state, always 1 for WM_KEYUP
    823860          }
    824           else 
     861          else
    825862          {
    826863            // send WM_SYSKEYDOWN message
     
    838875        // AltGr needs special handling
    839876        //
    840         // AltGr -> WM_KEYDOWN (VK_CONTROL), WM_KEYDOWN (VK_MENU) 
     877        // AltGr -> WM_KEYDOWN (VK_CONTROL), WM_KEYDOWN (VK_MENU)
    841878        //          WM_SYSKEYUP (VK_CONTROL)
    842879        //          WM_KEYUP (VK_MENU)
    843880        //
    844         // Ctrl+AltGr -> WM_KEYDOWN (VK_CONTROL), WM_KEYUP (VK_CONTROL) 
    845         //               WM_KEYDOWN (VK_MENU) 
     881        // Ctrl+AltGr -> WM_KEYDOWN (VK_CONTROL), WM_KEYUP (VK_CONTROL)
     882        //               WM_KEYDOWN (VK_MENU)
    846883        //               WM_KEYUP (VK_MENU)
    847         //               WM_KEYUP (VK_CONTROL) 
     884        //               WM_KEYUP (VK_CONTROL)
    848885        //
    849         // AltGr+Ctrl -> WM_KEYDOWN (VK_CONTROL), WM_KEYDOWN (VK_MENU) 
    850         //               WM_KEYDOWN (VK_CONTROL) 
    851         //               WM_SYSKEYUP (VK_CONTROL) 
    852         //               WM_SYSKEYUP (VK_CONTROL) 
     886        // AltGr+Ctrl -> WM_KEYDOWN (VK_CONTROL), WM_KEYDOWN (VK_MENU)
     887        //               WM_KEYDOWN (VK_CONTROL)
     888        //               WM_SYSKEYUP (VK_CONTROL)
     889        //               WM_SYSKEYUP (VK_CONTROL)
    853890        //               WM_KEYUP (VK_MENU)
    854891        //
     
    861898        //               endif
    862899        //               Send WM_KEYDOWN (VK_MENU)
    863         // 
    864         if(winMsg->wParam == VK_MENU_W && (winMsg->lParam & WIN_KEY_EXTENDED)) 
     900        //
     901        if(winMsg->wParam == VK_MENU_W && (winMsg->lParam & WIN_KEY_EXTENDED))
    865902        {//AltGr
    866             if(GetKeyState(VK_CONTROL_W) & 0x8000) 
     903            if(GetKeyState(VK_CONTROL_W) & 0x8000)
    867904            {//Ctrl key pressed, send WM_KEYUP
    868            
     905
    869906            }
    870907        }
     
    876913                winMsg->message = WINWM_SYSKEYDOWN;
    877914            }
    878             else 
     915            else
    879916            if(winMsg->message == WINWM_KEYUP) {
    880917                winMsg->message = WINWM_SYSKEYUP;
     
    9711008        if (os2Msg->msg == WM_VSCROLL)
    9721009        {
    973             POINT CursorPoint;
     1010            POINT CursorPoint;
    9741011            winMsg->message = WINWM_MOUSEWHEEL;
    9751012            if (OSLibWinQueryPointerPos(&CursorPoint))
    9761013               mapScreenPoint((OSLIBPOINT*)&CursorPoint);
    977  
     1014
    9781015            if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEDOWN)
    979                 winMsg->wParam  = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION); 
     1016                winMsg->wParam  = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION);
    9801017            else
    9811018            if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEUP)
    982                 winMsg->wParam  = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION); 
     1019                winMsg->wParam  = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION);
    9831020            else
    984                 winMsg->wParam  = MAKELONG(GetMouseKeyState(), 0); 
    985 
    986             winMsg->lParam  = MAKELONG(CursorPoint.x, CursorPoint.y); 
    987 
    988             dprintf(("WM_MOUSEWHEEL message delta %d at (%d,%d)",HIWORD(winMsg->wParam),CursorPoint.x, CursorPoint.y)); 
     1021                winMsg->wParam  = MAKELONG(GetMouseKeyState(), 0);
     1022
     1023            winMsg->lParam  = MAKELONG(CursorPoint.x, CursorPoint.y);
     1024
     1025            dprintf(("WM_MOUSEWHEEL message delta %d at (%d,%d)",HIWORD(winMsg->wParam),CursorPoint.x, CursorPoint.y));
    9891026            if (fMsgRemoved == MSG_REMOVE)
    9901027            {
    991                     MSLLHOOKSTRUCT hook;
    992 
    993                     hook.pt.x       = os2Msg->ptl.x & 0xFFFF;
    994                     hook.pt.y       = mapScreenY(os2Msg->ptl.y);
    995                     if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEDOWN)
    996                         hook.mouseData   = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION); 
    997                     else
    998                     if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEUP)
    999                         hook.mouseData   = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION); 
    1000                     else goto dummymessage; // IBM driver produces other messages as well sometimes
    1001 
    1002                     hook.flags       = LLMHF_INJECTED;
    1003                     hook.time        = winMsg->time;
    1004                     hook.dwExtraInfo = 0;
    1005                     if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, WINWM_MOUSEWHEEL, (LPARAM)&hook))
    1006                         goto dummymessage; //hook swallowed message
    1007            }
     1028                    MSLLHOOKSTRUCT hook;
     1029
     1030                    hook.pt.x       = os2Msg->ptl.x & 0xFFFF;
     1031                    hook.pt.y       = mapScreenY(os2Msg->ptl.y);
     1032                    if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEDOWN)
     1033                        hook.mouseData   = MAKELONG(GetMouseKeyState(), -WHEEL_DELTA/OS2_WHEEL_CORRECTION);
     1034                    else
     1035                    if (SHORT2FROMMP(os2Msg->mp2) == SB_LINEUP)
     1036                        hook.mouseData   = MAKELONG(GetMouseKeyState(), WHEEL_DELTA/OS2_WHEEL_CORRECTION);
     1037                    else goto dummymessage; // IBM driver produces other messages as well sometimes
     1038
     1039                    hook.flags       = LLMHF_INJECTED;
     1040                    hook.time        = winMsg->time;
     1041                    hook.dwExtraInfo = 0;
     1042                    if(HOOK_CallHooksW( WH_MOUSE_LL, HC_ACTION, WINWM_MOUSEWHEEL, (LPARAM)&hook))
     1043                        goto dummymessage; //hook swallowed message
     1044           }
    10081045           break;
    1009         } 
     1046        }
    10101047        goto dummymessage; //eat this message
    10111048        break;
     
    10541091  TEB *teb;
    10551092  MSG extramsg;
    1056   BOOL   numPressed = (BOOL)(WinGetKeyState(HWND_DESKTOP,VK_NUMLOCK) & 1);       
     1093  BOOL   numPressed = (BOOL)(WinGetKeyState(HWND_DESKTOP,VK_NUMLOCK) & 1);
    10571094  teb = GetThreadTEB();
    10581095  if(!teb)
     
    10611098  UCHAR ucPMScanCode = CHAR4FROMMP(teb->o.odin.os2msg.mp1);
    10621099  ULONG fl = SHORT1FROMMP(teb->o.odin.os2msg.mp1);
    1063    
    1064  
     1100
     1101
    10651102    //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
    10661103    //      the newly generated WM_CHAR message.
    10671104    if(!teb->o.odin.fTranslated &&
    1068        teb->o.odin.os2msg.msg == WM_CHAR && 
     1105       teb->o.odin.os2msg.msg == WM_CHAR &&
    10691106       !((SHORT1FROMMP(teb->o.odin.os2msg.mp1) & KC_KEYUP) == KC_KEYUP))
    10701107    {
     
    10831120        break;
    10841121      }
    1085      
     1122
    10861123      // PF With NumLock off do not generate any WM_CHAR messages at all
    10871124      // PADMINUS,PADPLUS fall in range of PAD7..PADPERIOD but they should generate WM_CHAR
     
    10891126      if (!numPressed && (ucPMScanCode != PMSCAN_PADMINUS) && (ucPMScanCode != PMSCAN_PADPLUS) &&
    10901127         (ucPMScanCode >= PMSCAN_PAD7) && (ucPMScanCode <= PMSCAN_PADPERIOD))
    1091         return FALSE; 
    1092 
    1093       if(!(fl & KC_CHAR) && msg->message < WINWM_SYSKEYDOWN) 
     1128        return FALSE;
     1129
     1130      if(!(fl & KC_CHAR) && msg->message < WINWM_SYSKEYDOWN)
    10941131      {
    10951132        return FALSE;
     
    11031140        if(msg->wParam)
    11041141        {
    1105           if ((msg->wParam >= VK_NUMPAD0_W) && 
     1142          if ((msg->wParam >= VK_NUMPAD0_W) &&
    11061143              (msg->wParam <= VK_NUMPAD9_W))
    11071144            extramsg.wParam = msg->wParam - 0x30;
     
    11141151                extramsg.wParam = msg->wParam;
    11151152        }
    1116         else   
     1153        else
    11171154          extramsg.wParam = SHORT2FROMMP(teb->o.odin.os2msg.mp2);
    11181155      }
     
    11201157
    11211158      //After SetFocus(0), all keystrokes are converted in WM_SYS*
    1122       if(msg->message >= WINWM_SYSKEYDOWN || fIgnoreKeystrokes) 
     1159      if(msg->message >= WINWM_SYSKEYDOWN || fIgnoreKeystrokes)
    11231160        extramsg.message = WINWM_SYSCHAR;
    1124       else   
     1161      else
    11251162        extramsg.message = WINWM_CHAR;
    11261163
Note: See TracChangeset for help on using the changeset viewer.