Ignore:
Timestamp:
Dec 24, 1999, 7:42:46 PM (26 years ago)
Author:
sandervl
Message:

Message handling rewrite

File:
1 edited

Legend:

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

    r1971 r2200  
    1 /* $Id: oslibmsg.cpp,v 1.14 1999-12-05 00:31:47 sandervl Exp $ */
     1/* $Id: oslibmsg.cpp,v 1.15 1999-12-24 18:39:10 sandervl Exp $ */
    22/*
    33 * Window message translation functions for OS/2
     
    99 * Project Odin Software License can be found in LICENSE.TXT
    1010 *
    11  * TODO: Simply copy for now. Need to make a real translation
     11 * TODO: Some messages that are sent to the frame window are directly passed on to the client
     12 *       -> Get/PeekMessage never gets them as we return a dummy message for non-client windows
     13 *       (i.e. menu WM_COMMAND messages)
     14 *
    1215 * TODO: Filter translation isn't correct for posted messages
    1316 *
     
    2730#include <wprocess.h>
    2831#include "pmwindow.h"
     32#include "oslibwin.h"
    2933
    3034typedef BOOL (EXPENTRY FNTRANS)(MSG *, QMSG *);
     
    8084   0x020a, 0x020a,   // WM_???,             WM_???
    8185   WM_CHAR,          WINWM_CHAR,
    82    
     86
    8387   //TODO: Needs better translation!
    8488   WM_CHAR,          WINWM_KEYDOWN,
     
    9296QMSG *MsgThreadPtr = 0;
    9397
     98LRESULT WIN32API SendMessageA(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
     99
    94100//******************************************************************************
    95101//******************************************************************************
     
    108114void WinToOS2MsgTranslate(MSG *winMsg, QMSG *os2Msg, BOOL isUnicode)
    109115{
    110   int i;
    111 
    112   memcpy(os2Msg, winMsg, sizeof(MSG));
    113   os2Msg->hwnd = Win32Window::Win32ToOS2Handle(winMsg->hwnd);
    114   os2Msg->reserved = 0;
    115   for(i=0;i<MAX_MSGTRANSTAB;i++)
    116   {
    117     if(MsgTransTab[i].msgWin32 == winMsg->message)
    118     {
    119       os2Msg->msg = MsgTransTab[i].msgOS2;
    120       break;
    121     }
    122   }
    123 }
    124 //******************************************************************************
    125 //******************************************************************************
    126 void OS2ToWinMsgTranslate(QMSG *os2Msg, MSG *winMsg, BOOL isUnicode)
    127 {
    128   POSTMSG_PACKET *packet;
    129   int i;
    130 
    131   memcpy(winMsg, os2Msg, sizeof(MSG));
    132   winMsg->hwnd = Win32Window::OS2ToWin32Handle(os2Msg->hwnd);
    133 
    134   if(os2Msg->msg == WIN32APP_POSTMSG) {
    135         packet = (POSTMSG_PACKET *)os2Msg->mp2;
    136         if(packet && (ULONG)os2Msg->mp1 == WIN32PM_MAGIC) {
    137                 winMsg->message = packet->Msg;
    138                 winMsg->wParam  = packet->wParam;
    139                 winMsg->lParam  = packet->lParam;
    140         }
    141         return;
    142   }
    143   for(i=0;i<MAX_MSGTRANSTAB;i++)
    144   {
    145     if(MsgTransTab[i].msgOS2 == os2Msg->msg)
    146     {
    147       winMsg->message = MsgTransTab[i].msgWin32;
    148       break;
    149     }
    150   }
     116//  memcpy(os2Msg, winMsg, sizeof(MSG));
     117//  os2Msg->hwnd = Win32Window::Win32ToOS2Handle(winMsg->hwnd);
     118//  os2Msg->reserved = 0;
    151119}
    152120//******************************************************************************
     
    159127{
    160128 POSTMSG_PACKET *packet;
    161  THDB *thdb;
    162 
    163   thdb = GetThreadTHDB();
    164   if(thdb) {
    165         thdb->fMsgTranslated = TRUE;
    166   }
    167129
    168130  if(msg >= WINWM_USER)
     
    192154LONG OSLibWinDispatchMsg(MSG *msg, BOOL isUnicode)
    193155{
    194  BOOL eaten = 0;
    195 
    196 //TODO: What to do if app changed msg? (translate)
    197 //  WinToOS2MsgTranslate(msg, &qmsg, isUnicode);
    198 
    199   //SvL: Some apps use PeeKMessage(remove) & DispatchMessage instead of
    200   //     GetMessage/DispatchMessage
    201   if (MsgThreadPtr->msg == WM_TIMER)
    202       eaten = TIMER_HandleTimer (MsgThreadPtr);
    203  
    204   if(eaten)     return 0;
    205 
    206   return (LONG)WinDispatchMsg(GetThreadHAB(), MsgThreadPtr);
     156 THDB *thdb;
     157 QMSG  os2msg;
     158 LONG  rc;
     159
     160  thdb = GetThreadTHDB();
     161  if(thdb == NULL) {
     162        DebugInt3();
     163        return FALSE;
     164  }
     165
     166  //TODO: What to do if app changed msg? (translate)
     167  //  WinToOS2MsgTranslate(msg, &qmsg, isUnicode);
     168
     169  if(msg->time == MsgThreadPtr->time || msg->hwnd == 0) {
     170        memcpy(&os2msg, MsgThreadPtr, sizeof(QMSG));
     171        MsgThreadPtr->time = -1;
     172        if(msg->hwnd) {
     173            thdb->nrOfMsgs = 1;
     174            thdb->msgstate++; //odd -> next call to our PM window handler should dispatch the translated msg
     175            memcpy(&thdb->msg, msg, sizeof(MSG));
     176        }
     177        return (LONG)WinDispatchMsg(thdb->hab, &os2msg);
     178  }
     179  else {//is this allowed?
     180//        dprintf(("WARNING: OSLibWinDispatchMsg: called with own message!"));
     181        return SendMessageA(msg->hwnd, msg->message, msg->wParam, msg->lParam);
     182  }
    207183}
    208184//******************************************************************************
     
    212188{
    213189 BOOL rc, eaten;
     190 THDB *thdb;
     191
     192  thdb = GetThreadTHDB();
     193  if(thdb == NULL) {
     194        DebugInt3();
     195        return FALSE;
     196  }
     197
     198  if(thdb->fTranslated && (!hwnd || hwnd == thdb->msgWCHAR.hwnd)) {
     199        thdb->fTranslated = FALSE;
     200        memcpy(pMsg, &thdb->msgWCHAR, sizeof(MSG));
     201        MsgThreadPtr->msg  = 0;
     202        MsgThreadPtr->hwnd = 0;
     203        return TRUE;
     204  }
     205  if(hwnd) {
     206        do {
     207            WinWaitMsg(thdb->hab, TranslateWinMsg(uMsgFilterMin), TranslateWinMsg(uMsgFilterMax));
     208            rc = OSLibWinPeekMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, PM_REMOVE_W, isUnicode);
     209        }
     210        while(rc == FALSE);
     211  }
     212  else
     213  {
     214    do {
     215        eaten = FALSE;
     216        rc = WinGetMsg(thdb->hab, MsgThreadPtr, TranslateWinMsg(uMsgFilterMin), TranslateWinMsg(uMsgFilterMax), 0);
     217        if (MsgThreadPtr->msg == WM_TIMER)
     218            eaten = TIMER_HandleTimer (MsgThreadPtr);
     219    } while (eaten);
     220  }
     221  OS2ToWinMsgTranslate((PVOID)thdb, MsgThreadPtr, pMsg, isUnicode);
     222  return rc;
     223}
     224//******************************************************************************
     225//******************************************************************************
     226BOOL OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
     227                     DWORD fRemove, BOOL isUnicode)
     228{
     229 BOOL  rc, eaten;
     230 THDB *thdb;
     231 QMSG  os2msg;
     232
     233  thdb = GetThreadTHDB();
     234  if(thdb == NULL) {
     235        DebugInt3();
     236        return FALSE;
     237  }
     238
     239  if(thdb->fTranslated && (!hwnd || hwnd == thdb->msgWCHAR.hwnd)) {
     240        if(fRemove == PM_REMOVE_W) {
     241            thdb->fTranslated = FALSE;
     242            MsgThreadPtr->msg  = 0;
     243            MsgThreadPtr->hwnd = 0;
     244        }
     245        memcpy(pMsg, &thdb->msgWCHAR, sizeof(MSG));
     246        return TRUE;
     247  }
    214248
    215249  do {
    216     eaten = FALSE;
    217     rc = WinGetMsg(GetThreadHAB(), MsgThreadPtr, TranslateWinMsg(uMsgFilterMin), TranslateWinMsg(uMsgFilterMax), 0);
    218     if (MsgThreadPtr->msg == WM_TIMER)
    219       eaten = TIMER_HandleTimer (MsgThreadPtr);
    220   } while (eaten);
    221 
    222   OS2ToWinMsgTranslate(MsgThreadPtr, pMsg, isUnicode);
     250        eaten = FALSE;
     251        rc = WinPeekMsg(thdb->hab, &os2msg, Win32BaseWindow::OS2ToWin32Handle(hwnd), TranslateWinMsg(uMsgFilterMin),
     252                        TranslateWinMsg(uMsgFilterMax), (fRemove == PM_REMOVE_W) ? PM_REMOVE : PM_NOREMOVE);
     253
     254        if (rc && fRemove == PM_REMOVE_W && os2msg.msg == WM_TIMER)
     255            eaten = TIMER_HandleTimer(&os2msg);
     256  }
     257  while (eaten && rc);
     258
     259  OS2ToWinMsgTranslate((PVOID)thdb, &os2msg, pMsg, isUnicode);
     260  //TODO: This is not safe! There's no guarantee this message will be dispatched and it might overwrite a previous message
     261  if(fRemove == PM_REMOVE_W) {
     262        memcpy(MsgThreadPtr, &os2msg, sizeof(QMSG));
     263  }
    223264  return rc;
    224265}
    225266//******************************************************************************
    226267//******************************************************************************
    227 BOOL  OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
    228                       BOOL fRemove, BOOL isUnicode)
    229 {
    230  BOOL rc;
    231 
    232   rc = WinPeekMsg(GetThreadHAB(), MsgThreadPtr, hwnd, TranslateWinMsg(uMsgFilterMin),
    233                   TranslateWinMsg(uMsgFilterMax), (fRemove == MSG_REMOVE) ? PM_REMOVE : PM_NOREMOVE);
    234   OS2ToWinMsgTranslate(MsgThreadPtr, pMsg, isUnicode);
    235   return rc;
    236 }
    237 //******************************************************************************
    238 //******************************************************************************
    239268ULONG OSLibWinQueryMsgTime()
    240269{
     
    252281ULONG OSLibWinQueryQueueStatus()
    253282{
    254  ULONG statusOS2, statusWin32;
     283 ULONG statusOS2, statusWin32 = 0;
    255284
    256285   statusOS2 = WinQueryQueueStatus(HWND_DESKTOP);
    257286
    258287   if(statusOS2 & QS_KEY)
    259         statusWin32 |= QS_KEY_W;
    260    if(statusOS2 & QS_MOUSEBUTTON)   
    261         statusWin32 |= QS_MOUSEBUTTON_W;
     288    statusWin32 |= QS_KEY_W;
     289   if(statusOS2 & QS_MOUSEBUTTON)
     290    statusWin32 |= QS_MOUSEBUTTON_W;
    262291   if(statusOS2 & QS_MOUSEMOVE)
    263         statusWin32 |= QS_MOUSEMOVE_W;
    264    if(statusOS2 & QS_TIMER)   
    265         statusWin32 |= QS_TIMER_W;
    266    if(statusOS2 & QS_PAINT)   
    267         statusWin32 |= QS_PAINT_W;
    268    if(statusOS2 & QS_POSTMSG)   
    269         statusWin32 |= QS_POSTMESSAGE_W;
    270    if(statusOS2 & QS_SENDMSG)   
    271         statusWin32 |= QS_SENDMESSAGE_W;
     292    statusWin32 |= QS_MOUSEMOVE_W;
     293   if(statusOS2 & QS_TIMER)
     294    statusWin32 |= QS_TIMER_W;
     295   if(statusOS2 & QS_PAINT)
     296    statusWin32 |= QS_PAINT_W;
     297   if(statusOS2 & QS_POSTMSG)
     298    statusWin32 |= QS_POSTMESSAGE_W;
     299   if(statusOS2 & QS_SENDMSG)
     300    statusWin32 |= QS_SENDMESSAGE_W;
    272301
    273302   return statusWin32;
Note: See TracChangeset for help on using the changeset viewer.