Changeset 10212 for trunk/src


Ignore:
Timestamp:
Aug 6, 2003, 1:00:45 PM (22 years ago)
Author:
sandervl
Message:

cleaned up Get/PeekMessage; do proper WM_CHAR conversion in those 4 functions

Location:
trunk/src/user32
Files:
2 edited

Legend:

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

    r10205 r10212  
    1 /* $Id: oslibmsg.cpp,v 1.73 2003-08-04 17:06:50 sandervl Exp $ */
     1/* $Id: oslibmsg.cpp,v 1.74 2003-08-06 11:00:44 sandervl Exp $ */
    22/*
    33 * Window message translation functions for OS/2
     
    4646#include <thread.h>
    4747#include <wprocess.h>
     48#include <winnls.h>
    4849#include "pmwindow.h"
    4950#include "oslibwin.h"
     
    231232}
    232233//******************************************************************************
     234// ReturnQueuedWMCHAR:
     235//
     236// Check for a queued WM_CHAR message (e.g. inserted by TranslateMessage)
     237//******************************************************************************
     238BOOL ReturnQueuedWMCHAR(LPMSG pMsg, TEB *teb, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
     239                        BOOL isUnicode, BOOL fRemove)
     240{
     241    if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd))
     242    {
     243        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));
     244
     245        if(uMsgFilterMin) {
     246            if(teb->o.odin.msgWCHAR.message < uMsgFilterMin)
     247                return FALSE;
     248        }
     249        if(uMsgFilterMax) {
     250            if(teb->o.odin.msgWCHAR.message > uMsgFilterMax)
     251                return FALSE;
     252        }
     253   
     254        if(fRemove & PM_REMOVE_W) {
     255            teb->o.odin.fTranslated = FALSE;
     256            teb->o.odin.os2msg.msg  = 0;
     257            teb->o.odin.os2msg.hwnd = 0;
     258        }
     259        memcpy(pMsg, &teb->o.odin.msgWCHAR, sizeof(MSG));
     260        //After SetFocus(0), all keystrokes are converted in WM_SYS*
     261        if(pMsg->message == WINWM_CHAR && fIgnoreKeystrokes) {
     262            pMsg->message = WINWM_SYSCHAR;
     263        }
     264
     265        if(!IsWindow(pMsg->hwnd)) {
     266            //could be a queued char message for a window that was just destroyed
     267            //when that's the case, we ignore it (MFC assertions are triggered by this)
     268            teb->o.odin.fTranslated = FALSE;
     269            teb->o.odin.os2msg.msg  = 0;
     270            teb->o.odin.os2msg.hwnd = 0;
     271            return FALSE;
     272        }
     273
     274        // @@@PH verify this
     275        // if this is a keyup or keydown message, we've got to
     276        // call the keyboard hook here
     277        // send keyboard messages to the registered hooks
     278        if(fRemove & PM_REMOVE_W)
     279        {
     280            switch (pMsg->message)
     281            {
     282            case WINWM_KEYDOWN:
     283            case WINWM_KEYUP:
     284            case WINWM_SYSKEYDOWN:
     285            case WINWM_SYSKEYUP:
     286                // only supposed to be called upon WM_KEYDOWN
     287                // and WM_KEYUP according to docs.
     288                if(ProcessKbdHook(pMsg, fRemove))
     289                    return FALSE;
     290                break;
     291            }
     292        }
     293   
     294        //GetMessageW and PeekMessageW expect the character code in UTF-16
     295        //(we save it in ascii format)
     296        if(isUnicode && (pMsg->message == WINWM_CHAR ||  pMsg->message == WINWM_SYSCHAR))
     297        {
     298            CHAR  charA;
     299            WCHAR charW;
     300   
     301            charA = pMsg->wParam;
     302            MultiByteToWideChar(CP_ACP, 0, &charA, 1, &charW, 1);
     303            pMsg->wParam= charW;
     304            dprintf(("ReturnQueuedWMCHAR: Convert to Unicode src=%x res=%x", charA, charW));
     305        }
     306        return TRUE;
     307    }
     308    return FALSE;
     309}
     310//******************************************************************************
    233311//******************************************************************************
    234312BOOL OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
     
    257335    }
    258336
    259     if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd))
    260     {
    261         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));
    262         if(uMsgFilterMin) {
    263             if(teb->o.odin.msgWCHAR.message < uMsgFilterMin)
    264                 goto continuegetmsg;
    265         }
    266         if(uMsgFilterMax) {
    267             if(teb->o.odin.msgWCHAR.message > uMsgFilterMax)
    268                 goto continuegetmsg;
    269         }
    270         teb->o.odin.fTranslated = FALSE;
    271         memcpy(pMsg, &teb->o.odin.msgWCHAR, sizeof(MSG));
    272 
    273         //After SetFocus(0), all keystrokes are converted in WM_SYS*
    274         if(pMsg->message == WINWM_CHAR && fIgnoreKeystrokes) {
    275             pMsg->message = WINWM_SYSCHAR;
    276         }
    277 
    278         teb->o.odin.os2msg.msg  = 0;
    279         teb->o.odin.os2msg.hwnd = 0;
    280 
    281         if(!IsWindow(pMsg->hwnd)) {
    282             //could be a queued char message for a window that was just destroyed
    283             //when that's the case, we ignore it (MFC assertions are triggered by this)
    284             goto continuegetmsg;
    285         }
    286 
    287         // @@@PH verify this
    288         // if this is a keyup or keydown message, we've got to
    289         // call the keyboard hook here
    290         // send keyboard messages to the registered hooks
    291         switch (pMsg->message)
    292         {
    293           case WINWM_KEYDOWN:
    294           case WINWM_KEYUP:
    295           case WINWM_SYSKEYDOWN:
    296           case WINWM_SYSKEYUP:
    297             // only supposed to be called upon WM_KEYDOWN
    298             // and WM_KEYUP according to docs.
    299             if(ProcessKbdHook(pMsg, TRUE))
    300                 goto continuegetmsg;
    301             break;
    302         }
    303 
     337    //check for a queued WM_CHAR message (e.g. inserted by TranslateMessage)
     338    if(ReturnQueuedWMCHAR(pMsg, teb, hwnd, uMsgFilterMin, uMsgFilterMax, isUnicode, PM_REMOVE_W) == TRUE)
     339    {
    304340        return (pMsg->message != WINWM_QUIT);
    305341    }
     
    401437    }
    402438    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             }
     439        hwndOS2 = Win32ToOS2Handle(hwnd);
     440        if(hwndOS2 == NULL) {
     441            dprintf(("PeekMsg: window %x NOT FOUND!", hwnd));
     442            SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
     443            return FALSE;
     444        }
    409445    }
    410446
     
    415451    }
    416452
    417     if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd))
    418     {
    419         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));
    420         if(uMsgFilterMin) {
    421             if(teb->o.odin.msgWCHAR.message < uMsgFilterMin)
    422                 goto continuepeekmsg;
    423         }
    424         if(uMsgFilterMax) {
    425             if(teb->o.odin.msgWCHAR.message > uMsgFilterMax)
    426                 goto continuepeekmsg;
    427         }
    428 
    429         if(fRemove & PM_REMOVE_W) {
    430             teb->o.odin.fTranslated = FALSE;
    431             teb->o.odin.os2msg.msg  = 0;
    432             teb->o.odin.os2msg.hwnd = 0;
    433         }
    434         memcpy(pMsg, &teb->o.odin.msgWCHAR, sizeof(MSG));
    435         //After SetFocus(0), all keystrokes are converted in WM_SYS*
    436         if(pMsg->message == WINWM_CHAR && fIgnoreKeystrokes) {
    437             pMsg->message = WINWM_SYSCHAR;
    438         }
    439 
    440 
    441         if(!IsWindow(pMsg->hwnd)) {
    442             //could be a queued char message for a window that was just destroyed
    443             //when that's the case, we ignore it (MFC assertions are triggered by this)
    444             teb->o.odin.fTranslated = FALSE;
    445             teb->o.odin.os2msg.msg  = 0;
    446             teb->o.odin.os2msg.hwnd = 0;
    447             goto continuepeekmsg;
    448         }
    449 
    450         // @@@PH verify this
    451         // if this is a keyup or keydown message, we've got to
    452         // call the keyboard hook here
    453         // send keyboard messages to the registered hooks
    454         if(fRemove & PM_REMOVE_W) {
    455             switch (pMsg->message)
    456             {
    457             case WINWM_KEYDOWN:
    458             case WINWM_KEYUP:
    459             case WINWM_SYSKEYDOWN:
    460             case WINWM_SYSKEYUP:
    461                 // only supposed to be called upon WM_KEYDOWN
    462                 // and WM_KEYUP according to docs.
    463                 if(ProcessKbdHook(pMsg, fRemove))
    464                     goto continuepeekmsg;
    465                 break;
    466             }
    467         }
    468 
     453    //check for a queued WM_CHAR message (e.g. inserted by TranslateMessage)
     454    if(ReturnQueuedWMCHAR(pMsg, teb, hwnd, uMsgFilterMin, uMsgFilterMax, isUnicode, fRemove) == TRUE)
     455    {
    469456        return TRUE;
    470457    }
  • trunk/src/user32/oslibmsgtranslate.cpp

    r10190 r10212  
    1 /* $Id: oslibmsgtranslate.cpp,v 1.113 2003-07-31 15:56:44 sandervl Exp $ */
     1/* $Id: oslibmsgtranslate.cpp,v 1.114 2003-08-06 11:00:45 sandervl Exp $ */
    22/*
    33 * Window message translation functions for OS/2
     
    6262//                                 by GetMessage & PeekMessage
    6363//
    64 // NOTE: Automatically converts ascii character code to UTF-16 if the target
    65 //       window is unicode.
     64// NOTE: WM_CHAR message always in ascii format
    6665//
    6766//******************************************************************************
     
    7271    // there's still an already translated message to be processed
    7372    return FALSE;
    74 
    75   //Unicode windows expect the character code in UTF-16
    76   if(IsWindowUnicode(pExtraMsg->hwnd))
    77   {
    78       CHAR  charA;
    79       WCHAR charW;
    80 
    81       charA = pExtraMsg->wParam;
    82       MultiByteToWideChar(CP_ACP, 0, &charA, 1, &charW, 1);
    83       pExtraMsg->wParam= charW;
    84       dprintf(("setThreadQueueExtraCharMessage: Convert to Unicode src=%x res=%x", charA, charW ));
    85   }
    8673
    8774  teb->o.odin.fTranslated = TRUE;
Note: See TracChangeset for help on using the changeset viewer.