Ignore:
Timestamp:
Sep 27, 1999, 12:24:51 AM (26 years ago)
Author:
sandervl
Message:

Keyboard msg fixes

File:
1 edited

Legend:

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

    r1057 r1067  
    1 /* $Id: pmwindow.cpp,v 1.9 1999-09-26 10:09:59 sandervl Exp $ */
     1/* $Id: pmwindow.cpp,v 1.10 1999-09-26 22:24:28 sandervl Exp $ */
    22/*
    33 * Win32 Window Managment Code for OS/2
     
    2828#include "oslibmsg.h"
    2929#include "dc.h"
     30#include <thread.h>
     31#include <wprocess.h>
    3032
    3133HMQ  hmq = 0;                             /* Message queue handle         */
     
    3638ULONG ScreenHeight = 0;
    3739
    38 MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
    39 
    40 //******************************************************************************
    41 //Initialize PM; create hab, message queue and register special Win32 window classes
    42 //******************************************************************************
    43 BOOL InitPM()
    44 {
    45   hab = WinInitialize(0);
    46   dprintf(("Winitialize returned %x", hab));
    47   hmq = WinCreateMsgQueue(hab, 0);
    48 
    49   if(!hab || !hmq)
    50   {
    51         UINT error;
    52         //CB: only fail on real error
    53         error = WinGetLastError(hab) & 0xFFFF; //error code
    54         if (!hab || error != PMERR_MSG_QUEUE_ALREADY_EXISTS)
    55         {
    56             dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
    57             dprintf((" Error = %x",error));
    58             return(FALSE);
    59         }
    60     else
    61         {
    62         if(!hab) {
    63                 hab = WinQueryAnchorBlock(HWND_DESKTOP);
    64             dprintf(("WinQueryAnchorBlock returned %x", hab));
    65         }
    66         if(!hmq) {
    67             hmq = HMQ_CURRENT;
    68         }
    69         }
    70   }
    71   SetThreadHAB(hab);
    72   dprintf(("InitPM: hmq = %x", hmq));
    73   SetThreadMessageQueue(hmq);
    74 
    75   if(!WinRegisterClass(                 /* Register window class        */
    76      hab,                               /* Anchor block handle          */
    77      (PSZ)WIN32_STDCLASS,               /* Window class name            */
    78      (PFNWP)Win32WindowProc,            /* Address of window procedure  */
    79      CS_SIZEREDRAW | CS_HITTEST | CS_MOVENOTIFY,
    80      NROF_WIN32WNDBYTES)) {
    81         dprintf(("WinRegisterClass Win32BaseWindow failed"));
    82         return(FALSE);
    83    }
    84 
    85    WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
    86    ScreenWidth  = desktopRectl.xRight;
    87    ScreenHeight = desktopRectl.yTop;
    88 
    89    dprintf(("InitPM: Desktop (%d,%d)", ScreenWidth, ScreenHeight));
    90    return OSLibInitMsgQueue();
    91 } /* End of main */
    92 //******************************************************************************
    93 //Win32 window message handler
    94 //******************************************************************************
    95 MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
    96 {
    97  POSTMSG_PACKET *postmsg;
    98  OSLIBPOINT      point, ClientPoint;
    99  Win32BaseWindow    *win32wnd;
    100  APIRET          rc;
    101 
    102   //Restore our FS selector
    103   SetWin32TIB();
    104 
    105   win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
    106 
    107   if(msg != WM_CREATE && win32wnd == NULL) {
    108         dprintf(("Invalid win32wnd pointer for window %x!!", hwnd));
    109         goto RunDefWndProc;
    110   }
    111   if(msg > WIN32APP_USERMSGBASE) {
    112     //win32 app user message
    113     dprintf(("PMWINDOW: Message %x (%x,%x) posted to window %x", (ULONG)msg-WIN32APP_USERMSGBASE, mp1, mp2, hwnd));
    114         win32wnd->SendMessageA((ULONG)msg-WIN32APP_USERMSGBASE, (ULONG)mp1, (ULONG)mp2);
    115   }
    116   switch( msg )
    117   {
    118     //OS/2 msgs
    119     case WM_CREATE:
    120         //Processing is done in after WinCreateWindow returns
    121         dprintf(("OS2: WM_CREATE %x", hwnd));
    122         RestoreOS2TIB();
    123         return (MRESULT)FALSE;
    124 
    125     case WM_QUIT:
    126         dprintf(("OS2: WM_QUIT %x", hwnd));
    127         if(win32wnd->MsgQuit()) {
    128                 goto RunDefWndProc;
    129         }
    130         break;
    131 
    132     case WM_CLOSE:
    133         dprintf(("OS2: WM_CLOSE %x", hwnd));
    134 //        win32wnd->RemoveFakeOpen32();
    135         if(win32wnd->MsgClose()) {
    136                 goto RunDefWndProc;
    137         }
    138         break;
    139 
    140     case WM_DESTROY:
    141         dprintf(("OS2: WM_DESTROY %x", hwnd));
    142         if(win32wnd->MsgDestroy()) {
    143                 goto RunDefWndProc;
    144         }
    145         break;
    146 
    147     case WM_ENABLE:
    148         dprintf(("OS2: WM_ENABLE %x", hwnd));
    149         if(win32wnd->MsgEnable((ULONG)mp1)) {
    150                 goto RunDefWndProc;
    151         }
    152         break;
    153 
    154     case WM_SHOW:
    155         dprintf(("OS2: WM_SHOW %x", hwnd));
    156         if(win32wnd->MsgShow((ULONG)mp1)) {
    157                 goto RunDefWndProc;
    158         }
    159         break;
    160 
    161     case WM_ADJUSTWINDOWPOS:
    162     {
    163       PSWP     pswp = (PSWP)mp1;
    164       SWP      swpOld;
    165       WINDOWPOS wp;
    166       ULONG    parentHeight = 0;
    167       HWND      hParent = NULLHANDLE, hFrame = NULLHANDLE;
    168 
    169         dprintf(("OS2: WM_ADJUSTWINDOWPOS %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
    170 
    171         if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
    172 
    173         WinQueryWindowPos(hwnd, &swpOld);
    174 
    175         if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
    176             if (win32wnd->isChild())
    177                 hParent = win32wnd->getParent()->getOS2WindowHandle();
    178             else
    179                 hFrame = win32wnd->getOS2FrameWindowHandle();
    180         }
    181         OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, hParent, hFrame);
    182 
    183         wp.hwnd = win32wnd->getWindowHandle();
    184         if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
    185         {
    186            Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
    187            if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
    188         }
    189         win32wnd->MsgPosChanging((LPARAM)&wp);
    190         break;
    191     }
    192 
    193     case WM_WINDOWPOSCHANGED:
    194     {
    195       PSWP      pswp  = (PSWP)mp1;
    196       PSWP      pswpo = pswp + 1;
    197       WINDOWPOS wp;
    198       ULONG     parentHeight = 0;
    199       HWND      hParent = NULLHANDLE, hFrame = NULLHANDLE;
    200       LONG      yDelta = pswp->cy - pswpo->cy;
    201       ULONG     classStyle;
    202 
    203         dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
    204 
    205         if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
    206 
    207         if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
    208             if (win32wnd->isChild())
    209                 hParent = win32wnd->getParent()->getOS2WindowHandle();
    210             else
    211                 hFrame = win32wnd->getOS2FrameWindowHandle();
    212         }
    213         OSLibMapSWPtoWINDOWPOS(pswp, &wp, pswpo, hParent, hFrame);
    214 
    215         win32wnd->setWindowRect(wp.x, wp.y, wp.x + wp.cx, wp.y + wp.cy);
    216         win32wnd->setClientRect(pswpo->x, pswpo->y, pswpo->x + pswpo->cx, pswpo->y + pswpo->cy);
    217 
    218         wp.hwnd = win32wnd->getWindowHandle();
    219         if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
    220         {
    221            Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
    222            wp.hwndInsertAfter = wndAfter->getWindowHandle();
    223         }
    224         classStyle = win32wnd->getClass()->getStyle();
    225         if ((yDelta != 0) && ((classStyle & CS_VREDRAW_W) ||
    226            ((classStyle & CS_HREDRAW_W) && (pswp->cx != pswpo->cx))))
    227         {
    228             HENUM henum = WinBeginEnumWindows(pswp->hwnd);
    229             SWP swp[10];
    230             int i = 0;
    231             HWND hwnd;
    232 
    233             while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE)
    234             {
    235 #if 0
    236                if (mdiClient )
    237                {
    238                   continue;
    239                }
    240 #endif
    241                WinQueryWindowPos(hwnd, &(swp[i]));
    242                swp[i].y += yDelta;
    243 
    244                if (i == 9)
    245                {
    246                   WinSetMultWindowPos(GetThreadHAB(), swp, 10);
    247                   i = 0;
    248                }
    249                else
    250                {
    251                   i++;
    252                }
    253             }
    254 
    255             WinEndEnumWindows(henum);
    256 
    257             if (i)
    258                WinSetMultWindowPos(GetThreadHAB(), swp, i);
    259         }
    260         win32wnd->MsgPosChanged((LPARAM)&wp);
    261 
    262         break;
    263     }
    264 
    265     case WM_ERASEBACKGROUND:
    266     {
    267         if (!win32wnd->isSupressErase()) {
    268             BOOL erased = sendEraseBkgnd (win32wnd);
    269             win32wnd->setEraseBkgnd (!erased, !erased);
    270         }
    271         break;
    272     }
    273 
    274     case WM_MOVE:
    275     {
    276         if (!win32wnd->isFrameWindow()) break;
    277 
    278         HWND      hFrame = win32wnd->getOS2FrameWindowHandle();
    279         SWP       swp, swpo;
    280         WINDOWPOS wp;
    281         ULONG     parentHeight = 0;
    282         RECTL     rcl;
    283 
    284         WinQueryWindowRect (hwnd, &rcl);
    285         WinMapWindowPoints (hwnd, hFrame, (PPOINTL)&rcl, 2);
    286         swp.x  = swpo.x  = rcl.xLeft;
    287         swp.y  = swpo.y  = rcl.yBottom;
    288         swp.cx = swpo.cx = rcl.xRight - rcl.xLeft;
    289         swp.cy = swpo.cy = rcl.yTop   - rcl.yBottom;
    290         swp.fl = SWP_MOVE | SWP_NOREDRAW;
    291         swp.hwnd             = hwnd;
    292         swp.hwndInsertBehind = NULLHANDLE;
    293 
    294         OSLibMapSWPtoWINDOWPOS(&swp, &wp, &swpo, NULLHANDLE, hFrame);
    295 
    296         wp.flags &= ~SWP_NOMOVE_W;
    297         wp.hwnd = win32wnd->getWindowHandle();
    298         win32wnd->setWindowRect(wp.x, wp.y, wp.x + wp.cx, wp.y + wp.cy);
    299         win32wnd->setClientRect(swpo.x, swpo.y, swpo.x + swpo.cx, swpo.y + swpo.cy);
    300         win32wnd->MsgPosChanged((LPARAM)&wp);
    301         break;
    302     }
    303     case WM_SIZE:
    304     {
    305         break;
    306     }
    307 
    308     case WM_ACTIVATE:
    309     {
    310       HWND hwndActivate = (HWND)mp1;
    311 
    312         dprintf(("OS2: WM_ACTIVATE %x", hwnd));
    313         if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
    314                 //another (non-win32) application's window
    315                 //set to NULL (allowed according to win32 SDK) to avoid problems
    316                 hwndActivate = NULL;
    317         }
    318         if(win32wnd->MsgActivate(1, hwndActivate)) {
    319                 goto RunDefWndProc;
    320         }
    321         break;
    322     }
    323     case WM_FOCUSCHANGE:
    324         dprintf(("OS2: WM_FOCUSCHANGE %x", hwnd));
    325         goto RunDefWndProc;
    326 
    327     case WM_SETFOCUS:
    328     {
    329       HWND hwndFocus = (HWND)mp1;
    330 
    331         dprintf(("OS2: WM_SETFOCUS %x %d", hwnd, mp2));
    332         if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
    333                 //another (non-win32) application's window
    334                 //set to NULL (allowed according to win32 SDK) to avoid problems
    335                 hwndFocus = NULL;
    336         }
    337         if((ULONG)mp2 == TRUE) {
    338                 rc = win32wnd->MsgSetFocus(hwndFocus);
    339         }
    340         else    rc = win32wnd->MsgKillFocus(hwndFocus);
    341         if(rc) {
    342                 goto RunDefWndProc;
    343         }
    344         break;
    345     }
    346     //**************************************************************************
    347     //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
    348     //**************************************************************************
    349     case WM_BUTTON1DOWN:
    350         dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd));
    351         point.x = (*(POINTS *)&mp1).x;
    352         point.y = (*(POINTS *)&mp1).y;
    353         ClientPoint.x = point.x;
    354         ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
    355         MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
    356         if(win32wnd->MsgButton(BUTTON_LEFTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
    357                 goto RunDefWndProc;
    358         }
    359         break;
    360 
    361     case WM_BUTTON1UP:
    362         dprintf(("OS2: WM_BUTTON1UP %x", hwnd));
    363         point.x = (*(POINTS *)&mp1).x;
    364         point.y = (*(POINTS *)&mp1).y;
    365         ClientPoint.x = point.x;
    366         ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
    367         MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
    368         if(win32wnd->MsgButton(BUTTON_LEFTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
    369                 goto RunDefWndProc;
    370         }
    371         break;
    372     case WM_BUTTON1DBLCLK:
    373         point.x = (*(POINTS *)&mp1).x;
    374         point.y = (*(POINTS *)&mp1).y;
    375         ClientPoint.x = point.x;
    376         ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
    377         MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
    378         if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
    379                 goto RunDefWndProc;
    380         }
    381         break;
    382     case WM_BUTTON2DOWN:
    383         point.x = (*(POINTS *)&mp1).x;
    384         point.y = (*(POINTS *)&mp1).y;
    385         ClientPoint.x = point.x;
    386         ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
    387         MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
    388         if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
    389                 goto RunDefWndProc;
    390         }
    391         break;
    392     case WM_BUTTON2UP:
    393         point.x = (*(POINTS *)&mp1).x;
    394         point.y = (*(POINTS *)&mp1).y;
    395         ClientPoint.x = point.x;
    396         ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
    397         MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
    398         if(win32wnd->MsgButton(BUTTON_RIGHTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
    399                 goto RunDefWndProc;
    400         }
    401         break;
    402     case WM_BUTTON2DBLCLK:
    403         point.x = (*(POINTS *)&mp1).x;
    404         point.y = (*(POINTS *)&mp1).y;
    405         ClientPoint.x = point.x;
    406         ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
    407         MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
    408         if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
    409                 goto RunDefWndProc;
    410         }
    411         break;
    412     case WM_BUTTON3DOWN:
    413         point.x = (*(POINTS *)&mp1).x;
    414         point.y = (*(POINTS *)&mp1).y;
    415         ClientPoint.x = point.x;
    416         ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
    417         MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
    418         if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
    419                 goto RunDefWndProc;
    420         }
    421         break;
    422     case WM_BUTTON3UP:
    423         point.x = (*(POINTS *)&mp1).x;
    424         point.y = (*(POINTS *)&mp1).y;
    425         ClientPoint.x = point.x;
    426         ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
    427         MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
    428         if(win32wnd->MsgButton(BUTTON_MIDDLEUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
    429                 goto RunDefWndProc;
    430         }
    431         break;
    432     case WM_BUTTON3DBLCLK:
    433         point.x = (*(POINTS *)&mp1).x;
    434         point.y = (*(POINTS *)&mp1).y;
    435         ClientPoint.x = point.x;
    436         ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
    437         MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
    438         if(win32wnd->MsgButton(BUTTON_MIDDLEDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
    439                 goto RunDefWndProc;
    440         }
    441         break;
    442 
    443     case WM_BUTTON2MOTIONSTART:
    444     case WM_BUTTON2MOTIONEND:
    445     case WM_BUTTON2CLICK:
    446     case WM_BUTTON1MOTIONSTART:
    447     case WM_BUTTON1MOTIONEND:
    448     case WM_BUTTON1CLICK:
    449     case WM_BUTTON3MOTIONSTART:
    450     case WM_BUTTON3MOTIONEND:
    451     case WM_BUTTON3CLICK:
    452         goto RunDefWndProc;
    453 
    454     case WM_MOUSEMOVE:
    455     {
    456     //Only send this message when the mouse isn't captured
    457         if(WinQueryCapture(HWND_DESKTOP) != NULLHANDLE) {
    458                 goto RunDefWndProc;
    459         }
    460         ULONG keystate = 0;
    461         if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1))
    462             keystate |= WMMOVE_LBUTTON;
    463         if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
    464             keystate |= WMMOVE_MBUTTON;
    465         if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3))
    466             keystate |= WMMOVE_RBUTTON;
    467         if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT))
    468             keystate |= WMMOVE_SHIFT;
    469         if(WinGetKeyState(HWND_DESKTOP, VK_CTRL))
    470             keystate |= WMMOVE_CTRL;
    471 
    472         //OS/2 Window coordinates -> Win32 Window coordinates
    473         //NOTE: Do not call the default OS/2 window handler as that one changes
    474         //      the mousepointer!
    475         win32wnd->MsgMouseMove(keystate, SHORT1FROMMP(mp1), MapOS2ToWin32Y(win32wnd, SHORT2FROMMP(mp1)));
    476         break;
    477     }
    478 
    479     //**************************************************************************
    480     //Slider messages
    481     //**************************************************************************
    482     case WM_VSCROLL:
    483     case WM_HSCROLL:
    484     {
    485      ULONG scrollPos, scrollCode, scrollMsg;
    486 
    487         scrollCode = SHORT2FROMMP(mp2);
    488         scrollPos  = SHORT1FROMMP(mp2);
    489         scrollMsg  = msg;
    490 
    491         OSLibTranslateScrollCmdAndMsg(&scrollMsg, &scrollCode);
    492 
    493         if(win32wnd->MsgScroll(scrollMsg, scrollCode, scrollPos)) {
    494             goto RunDefWndProc;
    495         }
    496         break;
    497     }
    498 
    499     case WM_CONTROL:
    500 
    501     case WM_COMMAND:
    502         if(SHORT1FROMMP(mp2) == CMDSRC_MENU) {
    503             win32wnd->MsgCommand(CMD_MENU, SHORT1FROMMP(mp1), 0);
    504         }
    505         if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR) {
    506             win32wnd->MsgCommand(CMD_ACCELERATOR, SHORT1FROMMP(mp1), 0);
    507         }
    508         //todo controls + accelerators
    509         break;
    510 
    511     case WM_SYSCOMMAND:
    512     {
    513       ULONG x = 0, y = 0;
    514       ULONG win32sc;
    515 
    516         if(SHORT2FROMMP(mp2) == TRUE) {//syscommand caused by mouse action
    517             POINTL pointl;
    518             WinQueryPointerPos(HWND_DESKTOP, &pointl);
    519             x = pointl.x;
    520             y = ScreenHeight - y;
    521         }
    522         switch(SHORT1FROMMP(mp1)) {
    523         case SC_MOVE:
    524             win32sc = WIN32SC_MOVE;
    525             break;
    526         case SC_CLOSE:
    527             win32sc = WIN32SC_CLOSE;
    528             break;
    529         case SC_MAXIMIZE:
    530             win32sc = WIN32SC_MAXIMIZE;
    531             break;
    532         case SC_MINIMIZE:
    533             win32sc = WIN32SC_MINIMIZE;
    534             break;
    535         case SC_NEXTFRAME:
    536         case SC_NEXTWINDOW:
    537             win32sc = WIN32SC_NEXTWINDOW;
    538             break;
    539         case SC_RESTORE:
    540             win32sc = WIN32SC_RESTORE;
    541             break;
    542         case SC_TASKMANAGER:
    543             win32sc = WIN32SC_TASKLIST;
    544             break;
    545         default:
    546             goto RunDefWndProc;
    547         }
    548         dprintf(("WM_SYSCOMMAND %x %x (%d,%d)", hwnd, win32sc, x, y));
    549         if(win32wnd->MsgSysCommand(win32sc, x, y)) {
    550             goto RunDefWndProc;
    551         }
    552         break;
    553     }
    554     case WM_CHAR:
    555     {
    556         ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
    557         ULONG flags = SHORT1FROMMP(mp1);
    558         BOOL keyWasPressed;
    559         char c;
    560         USHORT virtualKeyTable [66] = {
     40//Used for key translation while processing WM_CHAR message
     41USHORT virtualKeyTable [66] = {
    56142               0x00,    //   OS/2 VK         Win32 VK,    Entry 0 is not used
    56243               0x01,    // VK_BUTTON1       VK_LBUTTON
     
    57657               0x1B,    // VK_ESC           VK_ESCAPE
    57758               0x20,    // VK_SPACE         VK_SPACE
    578                0x00,    // VK_PAGEUP        No equivalent! At least, I think
    579                0x00,    // VK_PAGEDOWN      No equivalent! At least, I think
     59               0x22,    // VK_PAGEUP        VK_NEXT
     60               0x21,    // VK_PAGEDOWN      VK_PRIOR
    58061               0x23,    // VK_END           VK_END
    58162               0x24,    // VK_HOME          VK_HOME
     
    626107               0x00};   // VK_BLK2          No equivalent!
    627108
    628 
    629         repeatCount = SHORT2FROMMP (mp1) >> 8;
    630         scanCode = SHORT2FROMMP (mp1) & 255;
     109MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
     110
     111//******************************************************************************
     112//Initialize PM; create hab, message queue and register special Win32 window classes
     113//******************************************************************************
     114BOOL InitPM()
     115{
     116  hab = WinInitialize(0);
     117  dprintf(("Winitialize returned %x", hab));
     118  hmq = WinCreateMsgQueue(hab, 0);
     119
     120  if(!hab || !hmq)
     121  {
     122        UINT error;
     123        //CB: only fail on real error
     124        error = WinGetLastError(hab) & 0xFFFF; //error code
     125        if (!hab || error != PMERR_MSG_QUEUE_ALREADY_EXISTS)
     126        {
     127            dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
     128            dprintf((" Error = %x",error));
     129            return(FALSE);
     130        }
     131    else
     132        {
     133        if(!hab) {
     134                hab = WinQueryAnchorBlock(HWND_DESKTOP);
     135            dprintf(("WinQueryAnchorBlock returned %x", hab));
     136        }
     137        if(!hmq) {
     138            hmq = HMQ_CURRENT;
     139        }
     140        }
     141  }
     142  SetThreadHAB(hab);
     143  dprintf(("InitPM: hmq = %x", hmq));
     144  SetThreadMessageQueue(hmq);
     145
     146  if(!WinRegisterClass(                 /* Register window class        */
     147     hab,                               /* Anchor block handle          */
     148     (PSZ)WIN32_STDCLASS,               /* Window class name            */
     149     (PFNWP)Win32WindowProc,            /* Address of window procedure  */
     150     CS_SIZEREDRAW | CS_HITTEST | CS_MOVENOTIFY,
     151     NROF_WIN32WNDBYTES)) {
     152        dprintf(("WinRegisterClass Win32BaseWindow failed"));
     153        return(FALSE);
     154   }
     155
     156   WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
     157   ScreenWidth  = desktopRectl.xRight;
     158   ScreenHeight = desktopRectl.yTop;
     159
     160   dprintf(("InitPM: Desktop (%d,%d)", ScreenWidth, ScreenHeight));
     161   return OSLibInitMsgQueue();
     162} /* End of main */
     163//******************************************************************************
     164//Win32 window message handler
     165//******************************************************************************
     166MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
     167{
     168 POSTMSG_PACKET *postmsg;
     169 OSLIBPOINT      point, ClientPoint;
     170 Win32BaseWindow    *win32wnd;
     171 APIRET          rc;
     172
     173  //Restore our FS selector
     174  SetWin32TIB();
     175
     176  win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
     177
     178  if(msg != WM_CREATE && win32wnd == NULL) {
     179        dprintf(("Invalid win32wnd pointer for window %x!!", hwnd));
     180        goto RunDefWndProc;
     181  }
     182  if(msg > WIN32APP_USERMSGBASE) {
     183    //win32 app user message
     184    dprintf(("PMWINDOW: Message %x (%x,%x) posted to window %x", (ULONG)msg-WIN32APP_USERMSGBASE, mp1, mp2, hwnd));
     185        win32wnd->SendMessageA((ULONG)msg-WIN32APP_USERMSGBASE, (ULONG)mp1, (ULONG)mp2);
     186  }
     187  switch( msg )
     188  {
     189    //OS/2 msgs
     190    case WM_CREATE:
     191        //Processing is done in after WinCreateWindow returns
     192        dprintf(("OS2: WM_CREATE %x", hwnd));
     193        RestoreOS2TIB();
     194        return (MRESULT)FALSE;
     195
     196    case WM_QUIT:
     197        dprintf(("OS2: WM_QUIT %x", hwnd));
     198        if(win32wnd->MsgQuit()) {
     199                goto RunDefWndProc;
     200        }
     201        break;
     202
     203    case WM_CLOSE:
     204        dprintf(("OS2: WM_CLOSE %x", hwnd));
     205//        win32wnd->RemoveFakeOpen32();
     206        if(win32wnd->MsgClose()) {
     207                goto RunDefWndProc;
     208        }
     209        break;
     210
     211    case WM_DESTROY:
     212        dprintf(("OS2: WM_DESTROY %x", hwnd));
     213        if(win32wnd->MsgDestroy()) {
     214                goto RunDefWndProc;
     215        }
     216        break;
     217
     218    case WM_ENABLE:
     219        dprintf(("OS2: WM_ENABLE %x", hwnd));
     220        if(win32wnd->MsgEnable((ULONG)mp1)) {
     221                goto RunDefWndProc;
     222        }
     223        break;
     224
     225    case WM_SHOW:
     226        dprintf(("OS2: WM_SHOW %x", hwnd));
     227        if(win32wnd->MsgShow((ULONG)mp1)) {
     228                goto RunDefWndProc;
     229        }
     230        break;
     231
     232    case WM_ADJUSTWINDOWPOS:
     233    {
     234      PSWP     pswp = (PSWP)mp1;
     235      SWP      swpOld;
     236      WINDOWPOS wp;
     237      ULONG    parentHeight = 0;
     238      HWND      hParent = NULLHANDLE, hFrame = NULLHANDLE;
     239
     240        dprintf(("OS2: WM_ADJUSTWINDOWPOS %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
     241
     242        if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
     243
     244        WinQueryWindowPos(hwnd, &swpOld);
     245
     246        if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
     247            if (win32wnd->isChild())
     248                hParent = win32wnd->getParent()->getOS2WindowHandle();
     249            else
     250                hFrame = win32wnd->getOS2FrameWindowHandle();
     251        }
     252        OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, hParent, hFrame);
     253
     254        wp.hwnd = win32wnd->getWindowHandle();
     255        if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
     256        {
     257           Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
     258           if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
     259        }
     260        win32wnd->MsgPosChanging((LPARAM)&wp);
     261        break;
     262    }
     263
     264    case WM_WINDOWPOSCHANGED:
     265    {
     266      PSWP      pswp  = (PSWP)mp1;
     267      PSWP      pswpo = pswp + 1;
     268      WINDOWPOS wp;
     269      ULONG     parentHeight = 0;
     270      HWND      hParent = NULLHANDLE, hFrame = NULLHANDLE;
     271      LONG      yDelta = pswp->cy - pswpo->cy;
     272      ULONG     classStyle;
     273
     274        dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
     275
     276        if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
     277
     278        if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
     279            if (win32wnd->isChild())
     280                hParent = win32wnd->getParent()->getOS2WindowHandle();
     281            else
     282                hFrame = win32wnd->getOS2FrameWindowHandle();
     283        }
     284        OSLibMapSWPtoWINDOWPOS(pswp, &wp, pswpo, hParent, hFrame);
     285
     286        win32wnd->setWindowRect(wp.x, wp.y, wp.x + wp.cx, wp.y + wp.cy);
     287        win32wnd->setClientRect(pswpo->x, pswpo->y, pswpo->x + pswpo->cx, pswpo->y + pswpo->cy);
     288
     289        wp.hwnd = win32wnd->getWindowHandle();
     290        if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
     291        {
     292           Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
     293           wp.hwndInsertAfter = wndAfter->getWindowHandle();
     294        }
     295        classStyle = win32wnd->getClass()->getStyle();
     296        if ((yDelta != 0) && ((classStyle & CS_VREDRAW_W) ||
     297           ((classStyle & CS_HREDRAW_W) && (pswp->cx != pswpo->cx))))
     298        {
     299            HENUM henum = WinBeginEnumWindows(pswp->hwnd);
     300            SWP swp[10];
     301            int i = 0;
     302            HWND hwnd;
     303
     304            while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE)
     305            {
     306#if 0
     307               if (mdiClient )
     308               {
     309                  continue;
     310               }
     311#endif
     312               WinQueryWindowPos(hwnd, &(swp[i]));
     313               swp[i].y += yDelta;
     314
     315               if (i == 9)
     316               {
     317                  WinSetMultWindowPos(GetThreadHAB(), swp, 10);
     318                  i = 0;
     319               }
     320               else
     321               {
     322                  i++;
     323               }
     324            }
     325
     326            WinEndEnumWindows(henum);
     327
     328            if (i)
     329               WinSetMultWindowPos(GetThreadHAB(), swp, i);
     330        }
     331        win32wnd->MsgPosChanged((LPARAM)&wp);
     332
     333        break;
     334    }
     335
     336    case WM_ERASEBACKGROUND:
     337    {
     338        if (!win32wnd->isSupressErase()) {
     339            BOOL erased = sendEraseBkgnd (win32wnd);
     340            win32wnd->setEraseBkgnd (!erased, !erased);
     341        }
     342        break;
     343    }
     344
     345    case WM_MOVE:
     346    {
     347        if (!win32wnd->isFrameWindow()) break;
     348
     349        HWND      hFrame = win32wnd->getOS2FrameWindowHandle();
     350        SWP       swp, swpo;
     351        WINDOWPOS wp;
     352        ULONG     parentHeight = 0;
     353        RECTL     rcl;
     354
     355        WinQueryWindowRect (hwnd, &rcl);
     356        WinMapWindowPoints (hwnd, hFrame, (PPOINTL)&rcl, 2);
     357        swp.x  = swpo.x  = rcl.xLeft;
     358        swp.y  = swpo.y  = rcl.yBottom;
     359        swp.cx = swpo.cx = rcl.xRight - rcl.xLeft;
     360        swp.cy = swpo.cy = rcl.yTop   - rcl.yBottom;
     361        swp.fl = SWP_MOVE | SWP_NOREDRAW;
     362        swp.hwnd             = hwnd;
     363        swp.hwndInsertBehind = NULLHANDLE;
     364
     365        OSLibMapSWPtoWINDOWPOS(&swp, &wp, &swpo, NULLHANDLE, hFrame);
     366
     367        wp.flags &= ~SWP_NOMOVE_W;
     368        wp.hwnd = win32wnd->getWindowHandle();
     369        win32wnd->setWindowRect(wp.x, wp.y, wp.x + wp.cx, wp.y + wp.cy);
     370        win32wnd->setClientRect(swpo.x, swpo.y, swpo.x + swpo.cx, swpo.y + swpo.cy);
     371        win32wnd->MsgPosChanged((LPARAM)&wp);
     372        break;
     373    }
     374    case WM_SIZE:
     375    {
     376        break;
     377    }
     378
     379    case WM_ACTIVATE:
     380    {
     381      HWND hwndActivate = (HWND)mp1;
     382
     383        dprintf(("OS2: WM_ACTIVATE %x", hwnd));
     384        if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
     385                //another (non-win32) application's window
     386                //set to NULL (allowed according to win32 SDK) to avoid problems
     387                hwndActivate = NULL;
     388        }
     389        if(win32wnd->MsgActivate(1, hwndActivate)) {
     390                goto RunDefWndProc;
     391        }
     392        break;
     393    }
     394    case WM_FOCUSCHANGE:
     395        dprintf(("OS2: WM_FOCUSCHANGE %x", hwnd));
     396        goto RunDefWndProc;
     397
     398    case WM_SETFOCUS:
     399    {
     400      HWND hwndFocus = (HWND)mp1;
     401
     402        dprintf(("OS2: WM_SETFOCUS %x %d", hwnd, mp2));
     403        if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
     404                //another (non-win32) application's window
     405                //set to NULL (allowed according to win32 SDK) to avoid problems
     406                hwndFocus = NULL;
     407        }
     408        if((ULONG)mp2 == TRUE) {
     409                rc = win32wnd->MsgSetFocus(hwndFocus);
     410        }
     411        else    rc = win32wnd->MsgKillFocus(hwndFocus);
     412        if(rc) {
     413                goto RunDefWndProc;
     414        }
     415        break;
     416    }
     417    //**************************************************************************
     418    //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
     419    //**************************************************************************
     420    case WM_BUTTON1DOWN:
     421        dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd));
     422        point.x = (*(POINTS *)&mp1).x;
     423        point.y = (*(POINTS *)&mp1).y;
     424        ClientPoint.x = point.x;
     425        ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
     426        MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
     427        if(win32wnd->MsgButton(BUTTON_LEFTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
     428                goto RunDefWndProc;
     429        }
     430        break;
     431
     432    case WM_BUTTON1UP:
     433        dprintf(("OS2: WM_BUTTON1UP %x", hwnd));
     434        point.x = (*(POINTS *)&mp1).x;
     435        point.y = (*(POINTS *)&mp1).y;
     436        ClientPoint.x = point.x;
     437        ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
     438        MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
     439        if(win32wnd->MsgButton(BUTTON_LEFTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
     440                goto RunDefWndProc;
     441        }
     442        break;
     443    case WM_BUTTON1DBLCLK:
     444        point.x = (*(POINTS *)&mp1).x;
     445        point.y = (*(POINTS *)&mp1).y;
     446        ClientPoint.x = point.x;
     447        ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
     448        MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
     449        if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
     450                goto RunDefWndProc;
     451        }
     452        break;
     453    case WM_BUTTON2DOWN:
     454        point.x = (*(POINTS *)&mp1).x;
     455        point.y = (*(POINTS *)&mp1).y;
     456        ClientPoint.x = point.x;
     457        ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
     458        MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
     459        if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
     460                goto RunDefWndProc;
     461        }
     462        break;
     463    case WM_BUTTON2UP:
     464        point.x = (*(POINTS *)&mp1).x;
     465        point.y = (*(POINTS *)&mp1).y;
     466        ClientPoint.x = point.x;
     467        ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
     468        MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
     469        if(win32wnd->MsgButton(BUTTON_RIGHTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
     470                goto RunDefWndProc;
     471        }
     472        break;
     473    case WM_BUTTON2DBLCLK:
     474        point.x = (*(POINTS *)&mp1).x;
     475        point.y = (*(POINTS *)&mp1).y;
     476        ClientPoint.x = point.x;
     477        ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
     478        MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
     479        if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
     480                goto RunDefWndProc;
     481        }
     482        break;
     483    case WM_BUTTON3DOWN:
     484        point.x = (*(POINTS *)&mp1).x;
     485        point.y = (*(POINTS *)&mp1).y;
     486        ClientPoint.x = point.x;
     487        ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
     488        MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
     489        if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
     490                goto RunDefWndProc;
     491        }
     492        break;
     493    case WM_BUTTON3UP:
     494        point.x = (*(POINTS *)&mp1).x;
     495        point.y = (*(POINTS *)&mp1).y;
     496        ClientPoint.x = point.x;
     497        ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
     498        MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
     499        if(win32wnd->MsgButton(BUTTON_MIDDLEUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
     500                goto RunDefWndProc;
     501        }
     502        break;
     503    case WM_BUTTON3DBLCLK:
     504        point.x = (*(POINTS *)&mp1).x;
     505        point.y = (*(POINTS *)&mp1).y;
     506        ClientPoint.x = point.x;
     507        ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
     508        MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
     509        if(win32wnd->MsgButton(BUTTON_MIDDLEDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
     510                goto RunDefWndProc;
     511        }
     512        break;
     513
     514    case WM_BUTTON2MOTIONSTART:
     515    case WM_BUTTON2MOTIONEND:
     516    case WM_BUTTON2CLICK:
     517    case WM_BUTTON1MOTIONSTART:
     518    case WM_BUTTON1MOTIONEND:
     519    case WM_BUTTON1CLICK:
     520    case WM_BUTTON3MOTIONSTART:
     521    case WM_BUTTON3MOTIONEND:
     522    case WM_BUTTON3CLICK:
     523        goto RunDefWndProc;
     524
     525    case WM_MOUSEMOVE:
     526    {
     527    //Only send this message when the mouse isn't captured
     528        if(WinQueryCapture(HWND_DESKTOP) != NULLHANDLE) {
     529                goto RunDefWndProc;
     530        }
     531        ULONG keystate = 0;
     532        if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1))
     533            keystate |= WMMOVE_LBUTTON;
     534        if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
     535            keystate |= WMMOVE_MBUTTON;
     536        if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3))
     537            keystate |= WMMOVE_RBUTTON;
     538        if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT))
     539            keystate |= WMMOVE_SHIFT;
     540        if(WinGetKeyState(HWND_DESKTOP, VK_CTRL))
     541            keystate |= WMMOVE_CTRL;
     542
     543        //OS/2 Window coordinates -> Win32 Window coordinates
     544    //NOTE: Do not call the default OS/2 window handler as that one changes
     545        //      the mousepointer!
     546        win32wnd->MsgMouseMove(keystate, SHORT1FROMMP(mp1), MapOS2ToWin32Y(win32wnd, SHORT2FROMMP(mp1)));
     547        break;
     548    }
     549
     550    //**************************************************************************
     551    //Slider messages
     552    //**************************************************************************
     553    case WM_VSCROLL:
     554    case WM_HSCROLL:
     555    {
     556     ULONG scrollPos, scrollCode, scrollMsg;
     557
     558    scrollCode = SHORT2FROMMP(mp2);
     559    scrollPos  = SHORT1FROMMP(mp2);
     560    scrollMsg  = msg;
     561
     562    OSLibTranslateScrollCmdAndMsg(&scrollMsg, &scrollCode);
     563
     564        if(win32wnd->MsgScroll(scrollMsg, scrollCode, scrollPos)) {
     565            goto RunDefWndProc;
     566        }
     567    break;
     568    }
     569
     570    case WM_CONTROL:
     571
     572    case WM_COMMAND:
     573        if(SHORT1FROMMP(mp2) == CMDSRC_MENU) {
     574            win32wnd->MsgCommand(CMD_MENU, SHORT1FROMMP(mp1), 0);
     575        }
     576        if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR) {
     577            win32wnd->MsgCommand(CMD_ACCELERATOR, SHORT1FROMMP(mp1), 0);
     578        }
     579        //todo controls + accelerators
     580        break;
     581
     582    case WM_SYSCOMMAND:
     583    {
     584      ULONG x = 0, y = 0;
     585      ULONG win32sc;
     586
     587        if(SHORT2FROMMP(mp2) == TRUE) {//syscommand caused by mouse action
     588            POINTL pointl;
     589            WinQueryPointerPos(HWND_DESKTOP, &pointl);
     590            x = pointl.x;
     591            y = ScreenHeight - y;
     592        }
     593        switch(SHORT1FROMMP(mp1)) {
     594        case SC_MOVE:
     595            win32sc = SC_MOVE_W;
     596            break;
     597        case SC_CLOSE:
     598            win32sc = SC_CLOSE_W;
     599            break;
     600        case SC_MAXIMIZE:
     601            win32sc = SC_MAXIMIZE_W;
     602            break;
     603        case SC_MINIMIZE:
     604            win32sc = SC_MINIMIZE_W;
     605            break;
     606        case SC_NEXTFRAME:
     607        case SC_NEXTWINDOW:
     608            win32sc = SC_NEXTWINDOW_W;
     609            break;
     610        case SC_RESTORE:
     611            win32sc = SC_RESTORE_W;
     612            break;
     613        case SC_TASKMANAGER:
     614            win32sc = SC_TASKLIST_W;
     615            break;
     616        default:
     617            goto RunDefWndProc;
     618        }
     619        dprintf(("WM_SYSCOMMAND %x %x (%d,%d)", hwnd, win32sc, x, y));
     620        if(win32wnd->MsgSysCommand(win32sc, x, y)) {
     621            goto RunDefWndProc;
     622        }
     623        break;
     624    }
     625    case WM_CHAR:
     626    {
     627        THDB *thdb;
     628        ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
     629        ULONG flags = SHORT1FROMMP(mp1);
     630        BOOL keyWasPressed, fTranslated = FALSE, fRunDefWndProc = FALSE;
     631        char c;
     632
     633        repeatCount = CHAR3FROMMP(mp1);
     634        scanCode = CHAR4FROMMP(mp1);
    631635        keyWasPressed = ((SHORT1FROMMP (mp1) & KC_PREVDOWN) == KC_PREVDOWN);
    632636
     
    658662VirtualKeyFound:
    659663
    660         if ((WinGetKeyState (HWND_DESKTOP, VK_ALT) & 0x8000) == 0)
     664        if(!(SHORT1FROMMP(mp1) & KC_ALT))
    661665        {
    662666            //
     
    667671
    668672                if(win32wnd->MsgKeyUp (repeatCount, scanCode, virtualKey)) {
    669                     goto RunDefWndProc;
     673                    fRunDefWndProc = TRUE;
    670674                }
    671675            }
     
    673677                // send WM_KEYDOWN message
    674678                if (win32wnd->MsgKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
    675                     goto RunDefWndProc;
     679                    fRunDefWndProc = TRUE;
    676680            }
    677681        }
     
    684688
    685689                if(win32wnd->MsgSysKeyUp (repeatCount, scanCode, virtualKey)) {
    686                     goto RunDefWndProc;
     690                    fRunDefWndProc = TRUE;
    687691                }
    688692            }
     
    690694                // send WM_SYSKEYDOWN message
    691695                if (win32wnd->MsgSysKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
    692                     goto RunDefWndProc;
    693             }
    694         }
    695 
    696         break;
    697     }
    698 #if 0
    699     case WM_CHAR:
    700     {
    701      ULONG keyflags = 0, vkey = 0;
    702      ULONG fl = SHORT1FROMMP(mp1);
    703 
    704         if(!(fl & KC_CHAR)) {
    705 //            dprintf(("WM_CHAR: no valid character code"));
    706             goto RunDefWndProc;
    707         }
    708         if(fl & KC_VIRTUALKEY) {
    709             vkey = SHORT2FROMMP(mp2);
    710         }
    711         if(fl & KC_KEYUP) {
    712             keyflags |= KEY_UP;
    713         }
    714         if(fl & KC_ALT) {
    715             keyflags |= KEY_ALTDOWN;
    716         }
    717         if(fl & KC_PREVDOWN) {
    718             keyflags |= KEY_PREVDOWN;
    719         }
    720         if(fl & KC_DEADKEY) {
    721             keyflags |= KEY_DEADKEY;
    722         }
    723         if(win32wnd->MsgChar(SHORT1FROMMP(mp2), CHAR3FROMMP(mp1), CHAR4FROMMP(mp1), vkey, keyflags)) {
    724             goto RunDefWndProc;
    725         }
    726         break;
    727     }
    728 #endif
     696                    fRunDefWndProc = TRUE;
     697            }
     698        }
     699
     700        thdb = GetThreadTHDB();
     701        if(thdb) {
     702            fTranslated = thdb->fMsgTranslated;
     703            thdb->fMsgTranslated = FALSE;  //reset flag
     704        }
     705        //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
     706        //      the newly generated WM_CHAR message.
     707        if(fTranslated) {//TranslatedMessage was called before DispatchMessage, so send WM_CHAR messages
     708            ULONG keyflags = 0, vkey = 0;
     709            ULONG fl = SHORT1FROMMP(mp1);
     710
     711            if(!(fl & KC_CHAR)) {
     712                goto RunDefWndProc;
     713            }
     714            if(fl & KC_VIRTUALKEY) {
     715                vkey = SHORT2FROMMP(mp2);
     716            }
     717            if(fl & KC_KEYUP) {
     718                keyflags |= KEY_UP;
     719            }
     720            if(fl & KC_ALT) {
     721                keyflags |= KEY_ALTDOWN;
     722            }
     723            if(fl & KC_PREVDOWN) {
     724                keyflags |= KEY_PREVDOWN;
     725            }
     726            if(fl & KC_DEADKEY) {
     727                keyflags |= KEY_DEADKEY;
     728            }
     729            if(win32wnd->MsgChar(SHORT1FROMMP(mp2), CHAR3FROMMP(mp1), CHAR4FROMMP(mp1), virtualKey, keyflags)) {
     730                goto RunDefWndProc;
     731            }
     732        }
     733        if(fRunDefWndProc) goto RunDefWndProc;
     734        break;
     735    }
     736
    729737    case WM_INITMENU:
    730738    case WM_MENUSELECT:
Note: See TracChangeset for help on using the changeset viewer.