Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

pmwindow.cpp

Go to the documentation of this file.
00001 /* $Id: pmwindow.cpp,v 1.167 2002/01/07 11:18:10 sandervl Exp $ */
00002 /*
00003  * Win32 Window Managment Code for OS/2
00004  *
00005  * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl)
00006  * Copyright 1999      Daniela Engert (dani@ngrt.de)
00007  *
00008  *
00009  * Project Odin Software License can be found in LICENSE.TXT
00010  *
00011  */
00012 #define INCL_WIN
00013 #define INCL_GPI
00014 #define INCL_DEV                /* Device Function definitions  */
00015 #define INCL_GPICONTROL         /* GPI control Functions        */
00016 #define INCL_DOSPROCESS
00017 #define INCL_DOSMODULEMGR
00018 #define INCL_DOSDEVICES
00019 #define INCL_DOSDEVIOCTL
00020 #define INCL_WINTRACKRECT
00021 
00022 #include <os2wrap.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <win32type.h>
00026 #include <win32api.h>
00027 #include <winconst.h>
00028 #include <winuser32.h>
00029 #include <wprocess.h>
00030 #include <misc.h>
00031 #include <win32wbase.h>
00032 #include <win32dlg.h>
00033 #include "win32wdesktop.h"
00034 #include "pmwindow.h"
00035 #include "oslibwin.h"
00036 #include "oslibutil.h"
00037 #include "oslibgdi.h"
00038 #include "oslibmsg.h"
00039 #define INCLUDED_BY_DC
00040 #include "dc.h"
00041 #include <thread.h>
00042 #include <wprocess.h>
00043 #include "caret.h"
00044 #include "timer.h"
00045 #include <codepage.h>
00046 #include "syscolor.h"
00047 #include "options.h"
00048 #include "menu.h"
00049 #include <pmkbdhk.h>
00050 #include <pmscan.h>
00051 #include <winscan.h>
00052 #include <win\dbt.h>
00053 
00054 #define DBG_LOCALLOG    DBG_pmwindow
00055 #include "dbglocal.h"
00056 
00057 //define this to use the new code for WM_CALCVALIDRECT handling
00058 //#define USE_CALCVALIDRECT
00059 
00060 HMQ     hmq = 0;                             /* Message queue handle         */
00061 HAB     hab = 0;
00062 RECTL   desktopRectl = {0};
00063 ULONG   ScreenWidth  = 0;
00064 ULONG   ScreenHeight = 0;
00065 ULONG   ScreenBitsPerPel = 0;
00066 BOOL    fOS2Look = FALSE;
00067 HBITMAP hbmFrameMenu[3] = {0};
00068 
00069 static PFNWP pfnFrameWndProc = NULL;
00070 static HWND  hwndFocusChange = 0;
00071        HWND  hwndCD = 0;
00072 
00073 // this holds the font height that the display driver returns using DevQueryCaps
00074 // 13 would be small fonts, 16 medium fonts and 20 large fonts
00075 LONG CapsCharHeight = 0;
00076 
00077 // Note:
00078 // For a "lonekey"-press of AltGr, we only receive WM_KEYUP
00079 // messages. If the key is pressed longer and starts to repeat,
00080 // WM_KEYDOWN messages come in properly.
00081 static BOOL fKeyAltGrDown = FALSE;
00082 
00083 
00084 
00085 MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
00086 MRESULT EXPENTRY Win32CDWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
00087 MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
00088 void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG   idNew,
00089                           HBITMAP hbmNew);
00090 void FrameSetFocus(HWND hwnd);
00091 
00092 VOID APIENTRY DspInitSystemDriverName(PSZ pszDriverName, ULONG lenDriverName);
00093 
00094 //******************************************************************************
00095 //Initialize PM; create hab, message queue and register special Win32 window classes
00096 //******************************************************************************
00097 BOOL InitPM()
00098 {
00099     hab = WinInitialize(0);
00100     dprintf(("Winitialize returned %x", hab));
00101     hmq = WinCreateMsgQueue(hab, 0);
00102 
00103     if(!hab || !hmq)
00104     {
00105         UINT error;
00106         //CB: only fail on real error
00107         error = WinGetLastError(hab) & 0xFFFF; //error code
00108         if (!hab || (error != PMERR_MSG_QUEUE_ALREADY_EXISTS))
00109         {
00110             dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
00111             dprintf((" Error = %x",error));
00112             return(FALSE);
00113         }
00114         else
00115         {
00116             if(!hab) {
00117                 hab = WinQueryAnchorBlock(HWND_DESKTOP);
00118                 dprintf(("WinQueryAnchorBlock returned %x", hab));
00119             }
00120             if(!hmq) {
00121                 PTIB ptib;
00122                 PPIB ppib;
00123 
00124                 DosGetInfoBlocks(&ptib, &ppib);
00125 
00126                 hmq = WinQueueFromID(hab, ppib->pib_ulpid, ptib->tib_ptib2->tib2_ultid);
00127             }
00128         }
00129     }
00130     SetThreadHAB(hab);
00131     dprintf(("InitPM: hmq = %x", hmq));
00132     SetThreadMessageQueue(hmq);
00133 
00134     BOOL rc = WinSetCp(hmq, GetDisplayCodepage());
00135     dprintf(("InitPM: WinSetCP was %sOK", rc ? "" : "not "));
00136 
00137     //CD polling window class
00138     if(!WinRegisterClass(                    /* Register window class        */
00139         hab,                                 /* Anchor block handle          */
00140         (PSZ)WIN32_CDCLASS,                  /* Window class name            */
00141         (PFNWP)Win32CDWindowProc,            /* Address of window procedure  */
00142         0,
00143         0))
00144     {
00145             dprintf(("WinRegisterClass Win32BaseWindow failed"));
00146             return(FALSE);
00147     }
00148 
00149     //Standard Odin window class
00150     if(!WinRegisterClass(                 /* Register window class        */
00151         hab,                               /* Anchor block handle          */
00152         (PSZ)WIN32_STDCLASS,               /* Window class name            */
00153         (PFNWP)Win32WindowProc,            /* Address of window procedure  */
00154         0,
00155         NROF_WIN32WNDBYTES))
00156     {
00157             dprintf(("WinRegisterClass Win32BaseWindow failed"));
00158             return(FALSE);
00159     }
00160 
00161     CLASSINFO FrameClassInfo;
00162     if(!WinQueryClassInfo (hab, WC_FRAME, &FrameClassInfo)) {
00163         dprintf (("WinQueryClassInfo WC_FRAME failed"));
00164         return (FALSE);
00165     }
00166     pfnFrameWndProc = FrameClassInfo.pfnWindowProc;
00167 
00168     dprintf(("WC_FRAME style %x", FrameClassInfo.flClassStyle));
00169 
00170     if(!WinRegisterClass(                 /* Register window class        */
00171         hab,                               /* Anchor block handle          */
00172         (PSZ)WIN32_STDFRAMECLASS,          /* Window class name            */
00173         (PFNWP)Win32FrameWindowProc,       /* Address of window procedure  */
00174         CS_FRAME,
00175         FrameClassInfo.cbWindowData))
00176     {
00177         dprintf(("WinRegisterClass Win32BaseWindow failed %x", WinGetLastError(hab)));
00178         return(FALSE);
00179     }
00180 
00181     WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
00182     ScreenWidth  = desktopRectl.xRight;
00183     ScreenHeight = desktopRectl.yTop;
00184 
00185     HDC   hdc;              /* Device-context handle                */
00186     /* context data structure */
00187     DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
00188                         NULL, NULL, NULL};
00189 
00190     /* create memory device context */
00191     hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
00192 
00193     fOS2Look = PROFILE_GetOdinIniBool(ODINSYSTEM_SECTION, "OS2Look", FALSE);
00194     if(fOS2Look) 
00195     {
00196         CHAR szDisplay[30];
00197         HMODULE hModDisplay;
00198 
00199         SYSCOLOR_Init(FALSE); //use OS/2 colors
00200 
00201         DspInitSystemDriverName(szDisplay, sizeof(szDisplay));
00202         DosQueryModuleHandle(szDisplay, &hModDisplay);
00203 
00204         hbmFrameMenu[0] = GpiLoadBitmap(hdc, hModDisplay, SBMP_MINBUTTON, 0, 0);
00205         hbmFrameMenu[1] = GpiLoadBitmap(hdc, hModDisplay, SBMP_MAXBUTTON, 0, 0);
00206         hbmFrameMenu[2] = GpiLoadBitmap(hdc, hModDisplay, SBMP_RESTOREBUTTON, 0, 0);
00207     }
00208 
00209     DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, (PLONG)&ScreenBitsPerPel);
00210 
00211     // query the font height to find out whether we have small or large fonts
00212     DevQueryCaps(hdc, CAPS_GRAPHICS_CHAR_HEIGHT, 1, (PLONG)&CapsCharHeight);
00213 
00214     DevCloseDC(hdc);
00215 
00216     dprintf(("InitPM: Desktop (%d,%d) bpp %d", ScreenWidth, ScreenHeight, ScreenBitsPerPel));
00217     return TRUE;
00218 } /* End of main */
00219 //******************************************************************************
00220 //menu.cpp
00221 BOOL MENU_Init();
00222 //******************************************************************************
00223 void WIN32API SetWindowAppearance(int fLooks)
00224 {
00225     if(fLooks == OS2_APPEARANCE || fLooks == OS2_APPEARANCE_SYSMENU) 
00226     {
00227         CHAR szDisplay[30];
00228         HMODULE hModDisplay;
00229 
00230         SYSCOLOR_Init(FALSE); //use OS/2 colors
00231 
00232         if(hbmFrameMenu[0] == 0) 
00233         {
00234             CHAR szDisplay[30];
00235             HMODULE hModDisplay;
00236             HDC   hdc;              /* Device-context handle                */
00237             DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
00238                                 NULL, NULL, NULL};
00239 
00240             /* create memory device context */
00241             hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
00242 
00243             DspInitSystemDriverName(szDisplay, sizeof(szDisplay));
00244             DosQueryModuleHandle(szDisplay, &hModDisplay);
00245 
00246             hbmFrameMenu[0] = GpiLoadBitmap(hdc, hModDisplay, SBMP_MINBUTTON, 0, 0);
00247             hbmFrameMenu[1] = GpiLoadBitmap(hdc, hModDisplay, SBMP_MAXBUTTON, 0, 0);
00248             hbmFrameMenu[2] = GpiLoadBitmap(hdc, hModDisplay, SBMP_RESTOREBUTTON, 0, 0);
00249             DevCloseDC(hdc);
00250         }
00251     }
00252     fOS2Look = fLooks;
00253     MENU_Init();
00254 }
00255 //******************************************************************************
00256 //CD notification window class
00257 //******************************************************************************
00258 MRESULT EXPENTRY Win32CDWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
00259 {
00260 #pragma pack(1)
00261  typedef struct
00262  {
00263    BYTE  ucCommandInfo;
00264    WORD  usDriveUnit;
00265  } ParameterBlock;
00266 #pragma pack()
00267 
00268  MRESULT      rc              = 0;
00269  static ULONG drives[26]      = {0};
00270  static int   drivestatus[26] = {0};
00271 
00272     switch( msg )
00273     {
00274     //OS/2 msgs
00275     case WM_CREATE:
00276     {
00277         char drive[2];
00278 
00279         //skip floppy drives
00280         drive[0] = 'C';
00281         drive[1] = 0;
00282 
00283         for(int i=2;i<26;i++) {
00284            drives[i] = GetDriveTypeA(drive);
00285            if(drives[i] == DRIVE_CDROM_W) 
00286            {
00287                 DWORD parsize = sizeof(ParameterBlock);
00288                 DWORD datasize = 2;
00289                 WORD status = 0;
00290                 DWORD rc;
00291                 ParameterBlock parm;
00292 
00293                 parm.ucCommandInfo = 0;
00294                 parm.usDriveUnit   = i;
00295                 rc = DosDevIOCtl(-1, IOCTL_DISK, DSK_GETLOCKSTATUS, &parm, sizeof(parm), &parsize,
00296                                       &status, sizeof(status), &datasize);
00297                 if(rc != NO_ERROR) {
00298                     dprintf(("DosDevIOCtl failed with rc %d", rc));
00299                     drives[i] = 0;
00300                     continue;
00301                 }
00302                 //if no disk present, return FALSE
00303                 if(status & 4) {
00304                     drivestatus[i] = status & 4;
00305                 }
00306            }
00307            drive[0]++;
00308         }
00309         WinStartTimer(hab, hwnd, TIMERID_DRIVEPOLL, 32*60);
00310 ////        WinStartTimer(hab, hwnd, TIMERID_DRIVEPOLL, 32*3);
00311 ////        WinStartTimer(hab, hwnd, TIMERID_DRIVEPOLL, 5000);
00312         rc = (MRESULT)FALSE;
00313         break;
00314     }
00315     case WM_TIMER:
00316     {
00317         for(int i=0;i<26;i++) 
00318         {
00319             //for now only cdrom/dvd drives
00320             if(drives[i] == DRIVE_CDROM_W) 
00321             {
00322                 DWORD parsize = sizeof(ParameterBlock);
00323                 DWORD datasize = 2;
00324                 WORD status = 0;
00325                 DWORD rc;
00326                 ParameterBlock parm;
00327 
00328                 parm.ucCommandInfo = 0;
00329                 parm.usDriveUnit   = i;
00330                 rc = DosDevIOCtl(-1, IOCTL_DISK, DSK_GETLOCKSTATUS, &parm, sizeof(parm), &parsize,
00331                                       &status, sizeof(status), &datasize);
00332                 if(rc != NO_ERROR) {
00333                     dprintf(("DosDevIOCtl failed with rc %d", rc));
00334                     return FALSE;
00335                 }
00336                 //Send WM_DEVICECHANGE message when CD status changes
00337                 if((status & 4) != drivestatus[i]) 
00338                 {
00339                     PID pidThis, pidTemp;
00340                     HENUM henum;
00341                     HWND  hwndEnum;
00342                     DEV_BROADCAST_VOLUME volchange;
00343 
00344                     dprintf(("Disk status 0x%x", status));
00345 
00346                     volchange.dbcv_size       = sizeof(volchange);
00347                     volchange.dbcv_devicetype = DBT_DEVTYP_VOLUME;
00348                     volchange.dbcv_reserved   = 0;
00349                     volchange.dbcv_unitmask   = (1 << i);
00350                     volchange.dbcv_flags      = DBTF_MEDIA;
00351 
00352                     WinQueryWindowProcess(hwnd, &pidThis, NULL);
00353   
00354                     //Iterate over all child windows of the desktop
00355                     henum = WinBeginEnumWindows(HWND_DESKTOP);
00356 
00357                     SetWin32TIB();   
00358                     while(hwndEnum = WinGetNextWindow(henum))
00359                     {
00360                         WinQueryWindowProcess(hwndEnum, &pidTemp, NULL);
00361                         if(pidTemp == pidThis)
00362                         {
00363                             HWND hwndWin32 = OS2ToWin32Handle(hwndEnum);
00364                             if(hwndWin32) {
00365                                 SendMessageA(hwndWin32, 
00366                                              WM_DEVICECHANGE_W, 
00367                                              (status & 4) ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE, 
00368                                              (LPARAM)&volchange);
00369                             }
00370                         }
00371                     }
00372                     RestoreOS2TIB();
00373                     WinEndEnumWindows(henum);
00374 
00375                     drivestatus[i] = (status & 4);
00376                 }
00377             }
00378         }
00379         break;
00380     }
00381 
00382     case WM_DESTROY:
00383         dprintf(("WM_DESTROY for CD notification window"));
00384         WinStopTimer(hab, hwnd, TIMERID_DRIVEPOLL);
00385         break;
00386 
00387     default:
00388         return WinDefWindowProc( hwnd, msg, mp1, mp2 );
00389     }
00390     return (MRESULT)rc;
00391 }
00392 //******************************************************************************
00393 //Win32 window message handler
00394 //******************************************************************************
00395 MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
00396 {
00397  Win32BaseWindow *win32wnd;
00398  TEB             *teb;
00399  MSG              winMsg, *pWinMsg;
00400  MRESULT          rc = 0;
00401  POSTMSG_PACKET  *postmsg;
00402  OSLIBPOINT       point, ClientPoint;
00403 
00404     //Restore our FS selector
00405     SetWin32TIB();
00406 
00407     //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
00408     teb = GetThreadTEB();
00409     win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
00410 
00411 ////    dprintf(("window %x msg %x", (win32wnd) ? win32wnd->getWindowHandle() : 0, msg));
00412 
00413     if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
00414         dprintf(("OS2: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
00415         goto RunDefWndProc;
00416     }
00417 ////    if(teb->o.odin.fIgnoreMsgs) {
00418 ////        goto RunDefWndProc;
00419 ////    }
00420 
00421     if((teb->o.odin.msgstate & 1) == 0)
00422     {//message that was sent directly to our window proc handler; translate it here
00423         QMSG qmsg;
00424 
00425         qmsg.msg  = msg;
00426         qmsg.hwnd = hwnd;
00427         qmsg.mp1  = mp1;
00428         qmsg.mp2  = mp2;
00429         qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
00430         WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
00431         qmsg.reserved = 0;
00432 
00433         if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
00434         {//message was not translated
00435             memset(&winMsg, 0, sizeof(MSG));
00436         }
00437         pWinMsg = &winMsg;
00438     }
00439     else {
00440         pWinMsg = &teb->o.odin.msg;
00441         teb->o.odin.msgstate++;
00442     }
00443     //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
00444 
00445     if(msg >= WIN32APP_POSTMSG) {
00446         //probably win32 app user message
00447         dprintf2(("Posted message %x->%x", msg, msg-WIN32APP_POSTMSG));
00448         if((ULONG)mp1 == WIN32MSG_MAGICA) {
00449             rc = (MRESULT)win32wnd->DispatchMsgA(pWinMsg);
00450         }
00451         else
00452         if((ULONG)mp1 == WIN32MSG_MAGICW) {
00453             rc = (MRESULT)win32wnd->DispatchMsgW(pWinMsg);
00454         }
00455         else {//broadcasted message
00456             rc = (MRESULT)win32wnd->DispatchMsgA(pWinMsg);
00457         }
00458         RELEASE_WNDOBJ(win32wnd);
00459         RestoreOS2TIB();
00460         return rc;
00461     }
00462 
00463     switch( msg )
00464     {
00465     //OS/2 msgs
00466     case WM_CREATE:
00467     {
00468         if(teb->o.odin.newWindow == 0)
00469             goto createfail;
00470 
00471         //Processing is done in after WinCreateWindow returns
00472         dprintf(("OS2: WM_CREATE %x", hwnd));
00473         win32wnd = (Win32BaseWindow *)teb->o.odin.newWindow;
00474         win32wnd->addRef();
00475         teb->o.odin.newWindow = 0;
00476         if(win32wnd->MsgCreate(hwnd) == FALSE)
00477         {
00478             rc = (MRESULT)TRUE; //discontinue window creation
00479             break;
00480         }
00481 
00482         //Create CD notification window
00483         if(hwndCD == 0) {
00484             hwndCD = WinCreateWindow(HWND_DESKTOP, WIN32_CDCLASS,
00485                                      NULL, 0, 0, 0, 0, 0,
00486                                      HWND_DESKTOP, HWND_TOP, 0, NULL, NULL);
00487         }
00488 
00489     createfail:
00490         rc = (MRESULT)FALSE;
00491         break;
00492     }
00493 
00494     case WM_QUIT:
00495         dprintf(("OS2: WM_QUIT %x", hwnd));
00496         win32wnd->MsgQuit();
00497         break;
00498 
00499     case WM_CLOSE:
00500         dprintf(("OS2: WM_CLOSE %x", hwnd));
00501         win32wnd->MsgClose();
00502         break;
00503 
00504     case WM_DESTROY:
00505         dprintf(("OS2: WM_DESTROY %x", hwnd));
00506         win32wnd->MsgDestroy();
00507         WinSetVisibleRegionNotify(hwnd, FALSE);
00508         goto RunDefWndProc;
00509 
00510     case WM_ENABLE:
00511         dprintf(("OS2: WM_ENABLE %x", hwnd));
00512         break;
00513 
00514     case WM_SHOW:
00515         dprintf(("OS2: WM_SHOW %x %d", hwnd, mp1));
00516         win32wnd->MsgShow((ULONG)mp1);
00517         break;
00518 
00519     case WM_ACTIVATE:
00520     {
00521         ULONG flags = WinQueryWindowULong(hwnd, OFFSET_WIN32FLAGS);
00522 
00523         dprintf(("OS2: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2));
00524         WinSetWindowULong(hwnd, OFFSET_WIN32FLAGS, SHORT1FROMMP(mp1) ? (flags | WINDOWFLAG_ACTIVE):(flags & ~WINDOWFLAG_ACTIVE));
00525         if(win32wnd->IsWindowCreated())
00526         {
00527             win32wnd->MsgActivate((LOWORD(pWinMsg->wParam) == WA_ACTIVE_W) ? 1 : 0, HIWORD(pWinMsg->wParam), pWinMsg->lParam, (HWND)mp2);
00528         }
00529         break;
00530     }
00531 
00532     case WM_SIZE:
00533     {
00534         dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp1)));
00535         win32wnd->SetVisibleRegionChanged(TRUE);
00536         goto RunDefWndProc;
00537     }
00538 
00539 
00540     case WM_VRNENABLED:
00541         dprintf(("OS2: WM_VRNENABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
00542         //Always call handler; even if mp1 is 0. If we don't do this, the
00543         //DivX 4 player will never be allowed to draw after putting another window
00544         //on top of it.
00545         win32wnd->callVisibleRgnNotifyProc(TRUE);
00546         if(!win32wnd->isComingToTop() && ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == WS_EX_TOPMOST_W))
00547         {
00548             HWND hwndrelated;
00549             Win32BaseWindow *topwindow;
00550 
00551             win32wnd->setComingToTop(TRUE);
00552 
00553             hwndrelated = WinQueryWindow(hwnd, QW_PREV);
00554             dprintf(("WM_VRNENABLED hwndrelated = %x (hwnd=%x)", hwndrelated, hwnd));
00555             topwindow = Win32BaseWindow::GetWindowFromOS2Handle(hwndrelated);
00556             if(topwindow == NULL || ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == 0)) {
00557                 //put window at the top of z order
00558                 WinSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
00559             }
00560             if(topwindow) RELEASE_WNDOBJ(topwindow);
00561 
00562             win32wnd->setComingToTop(FALSE);
00563             break;
00564         }
00565         goto RunDefWndProc;
00566 
00567     case WM_VRNDISABLED:
00568         dprintf(("OS2: WM_VRNDISABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
00569         //visible region is about to change or WinLockWindowUpdate called
00570         //suspend window drawing
00571         win32wnd->callVisibleRgnNotifyProc(FALSE);
00572         goto RunDefWndProc;
00573 
00574     case WIN32APP_SETFOCUSMSG:
00575         //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
00576         //must delay this function call
00577         //mp1 = win32 window handle
00578         //mp2 = top parent if activation required
00579         dprintf(("USER32: Delayed SetFocus %x %x %x call!", teb->o.odin.hwndFocus, mp1, mp2));
00580         if(teb->o.odin.hwndFocus) {
00581             RELEASE_WNDOBJ(win32wnd);
00582             win32wnd = Win32BaseWindow::GetWindowFromHandle(teb->o.odin.hwndFocus);
00583             if(win32wnd) {
00584                  if(mp2) {
00585                     SetActiveWindow((HWND)mp2);
00586                  }
00587                  if(!IsWindow(win32wnd->getWindowHandle())) break;       //abort if window destroyed
00588                  WinFocusChange(HWND_DESKTOP, win32wnd->getOS2WindowHandle(), FC_NOSETACTIVE);
00589             }
00590             else DebugInt3();
00591         }
00592         break;
00593 
00594     case WM_SETFOCUS:
00595     {
00596       HWND hwndFocus = (HWND)mp1;
00597 
00598         dprintf(("OS2: WM_SETFOCUS %x %x (%x) %d", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle(hwndFocus), mp2));
00599 
00600         //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
00601         //must delay this function call
00602 
00603         teb->o.odin.fWM_SETFOCUS = TRUE;
00604         teb->o.odin.hwndFocus    = 0;
00605         if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC)
00606         {
00607                 //another (non-win32) application's window
00608                 //set to NULL (allowed according to win32 SDK) to avoid problems
00609                 hwndFocus = NULL;
00610         }
00611         if((ULONG)mp2 == TRUE) {
00612                 HWND hwndFocusWin32 = OS2ToWin32Handle(hwndFocus);
00613                 recreateCaret (hwndFocusWin32);
00614                 win32wnd->MsgSetFocus(hwndFocusWin32);
00615         }
00616         else win32wnd->MsgKillFocus(OS2ToWin32Handle(hwndFocus));
00617         teb->o.odin.fWM_SETFOCUS = FALSE;
00618 
00619         break;
00620     }
00621 
00622     //**************************************************************************
00623     //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
00624     //**************************************************************************
00625 
00626     case WM_BUTTON1DOWN:
00627     case WM_BUTTON1UP:
00628     case WM_BUTTON1DBLCLK:
00629     case WM_BUTTON2DOWN:
00630     case WM_BUTTON2UP:
00631     case WM_BUTTON2DBLCLK:
00632     case WM_BUTTON3DOWN:
00633     case WM_BUTTON3UP:
00634     case WM_BUTTON3DBLCLK:
00635         if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
00636             RELEASE_WNDOBJ(win32wnd);
00637             win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
00638         }
00639         if(win32wnd)
00640             win32wnd->MsgButton(pWinMsg);
00641 
00642         rc = (MRESULT)TRUE;
00643         break;
00644 
00645     case WM_BUTTON2MOTIONSTART:
00646     case WM_BUTTON2MOTIONEND:
00647     case WM_BUTTON2CLICK:
00648     case WM_BUTTON1MOTIONSTART:
00649     case WM_BUTTON1MOTIONEND:
00650     case WM_BUTTON1CLICK:
00651     case WM_BUTTON3MOTIONSTART:
00652     case WM_BUTTON3MOTIONEND:
00653     case WM_BUTTON3CLICK:
00654         rc = (MRESULT)TRUE;
00655         break;
00656 
00657     case WM_MOUSEMOVE:
00658     {
00659         if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
00660             RELEASE_WNDOBJ(win32wnd);
00661             win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
00662         }
00663         if(win32wnd)
00664             win32wnd->MsgMouseMove(pWinMsg);
00665         break;
00666     }
00667 
00668     case WM_CONTROL:
00669         goto RunDefWndProc;
00670 
00671     case WM_COMMAND:
00672         dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2));
00673         win32wnd->DispatchMsgA(pWinMsg);
00674         break;
00675 
00676     case WM_SYSCOMMAND:
00677         dprintf(("OS2: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
00678         win32wnd->DispatchMsgA(pWinMsg);
00679         break;
00680 
00681     case WM_RENDERFMT:
00682     case WM_RENDERALLFMTS:
00683     case WM_DESTROYCLIPBOARD:
00684         win32wnd->DispatchMsgA(pWinMsg);
00685         break;
00686       
00687     case WM_CHAR_SPECIAL:
00688       /* NO BREAK! FALLTHRU CASE! */
00689       
00690     case WM_CHAR:
00691         dprintf(("OS2: WM_CHAR %x %x %x, %x %x", win32wnd->getWindowHandle(), mp1, mp2, pWinMsg->wParam, pWinMsg->lParam));
00692         win32wnd->MsgChar(pWinMsg);
00693         break;
00694 
00695     case WM_TIMER:
00696         dprintf(("OS2: WM_TIMER %x %x time %x", win32wnd->getWindowHandle(), pWinMsg->wParam, GetTickCount()));
00697         win32wnd->DispatchMsgA(pWinMsg);
00698         goto RunDefWndProc;
00699 
00700     case WM_SETWINDOWPARAMS:
00701     {
00702         WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
00703 
00704         dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
00705         if(wndParams->fsStatus & WPM_TEXT) {
00706             win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
00707         }
00708         goto RunDefWndProc;
00709     }
00710 
00711     case WM_QUERYWINDOWPARAMS:
00712     {
00713      PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
00714      ULONG textlen;
00715      PSZ   wintext;
00716 
00717         if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
00718         {
00719             if(wndpars->fsStatus & WPM_TEXT)
00720                 win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
00721             if(wndpars->fsStatus & WPM_CCHTEXT)
00722                 wndpars->cchText = win32wnd->MsgGetTextLength();
00723 
00724             wndpars->fsStatus = 0;
00725             wndpars->cbCtlData = 0;
00726             wndpars->cbPresParams = 0;
00727             rc = (MRESULT)TRUE;
00728             break;
00729         }
00730         goto RunDefWndProc;
00731     }
00732 
00733     case WM_PAINT:
00734     {
00735       RECTL rectl;
00736       BOOL  rc;
00737 
00738         rc = WinQueryUpdateRect(hwnd, &rectl);
00739         dprintf(("OS2: WM_PAINT %x (%d,%d) (%d,%d) rc=%d", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop, rc));
00740 
00741         if(rc && win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
00742            rectl.yBottom != rectl.yTop))
00743         {
00744                 win32wnd->DispatchMsgA(pWinMsg);
00745         }
00746         else    goto RunDefWndProc;
00747         break;
00748     }
00749 
00750     case WM_ERASEBACKGROUND:
00751     {
00752         dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
00753         rc = (MRESULT)FALSE;
00754         break;
00755     }
00756 
00757     case WM_CALCVALIDRECTS:
00758         dprintf(("OS2: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
00759         rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
00760         break;
00761 
00762     case WM_REALIZEPALETTE:
00763     {
00764         dprintf(("OS2: WM_REALIZEPALETTE"));
00765         goto RunDefWndProc;
00766     }
00767 
00768     case WM_HSCROLL:
00769     case WM_VSCROLL:
00770         dprintf(("OS2: %s %x %x %x", (msg == WM_HSCROLL) ? "WM_HSCROLL" : "WM_VSCROLL", win32wnd->getWindowHandle(), mp1, mp2));
00771         win32wnd->DispatchMsgA(pWinMsg);
00772         break;
00773 
00774     case WM_DDE_INITIATE:
00775     case WM_DDE_INITIATEACK:
00776     case WM_DDE_REQUEST:
00777     case WM_DDE_ACK:
00778     case WM_DDE_DATA:
00779     case WM_DDE_ADVISE:
00780     case WM_DDE_UNADVISE:
00781     case WM_DDE_POKE:
00782     case WM_DDE_EXECUTE:
00783     case WM_DDE_TERMINATE:
00784         dprintf(("OS2: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
00785         goto RunDefWndProc;
00786 
00787     case WM_INITMENU:
00788     case WM_MENUSELECT:
00789     case WM_MENUEND:
00790     case WM_NEXTMENU:
00791     case WM_SYSCOLORCHANGE:
00792     case WM_SYSVALUECHANGED:
00793     case WM_SETSELECTION:
00794     case WM_PPAINT:
00795     case WM_PSETFOCUS:
00796     case WM_PSYSCOLORCHANGE:
00797     case WM_PSIZE:
00798     case WM_PACTIVATE:
00799     case WM_PCONTROL:
00800     case WM_HELP:
00801     case WM_APPTERMINATENOTIFY:
00802     case WM_PRESPARAMCHANGED:
00803     case WM_DRAWITEM:
00804     case WM_MEASUREITEM:
00805     case WM_CONTROLPOINTER:
00806     case WM_QUERYDLGCODE:
00807     case WM_SUBSTITUTESTRING:
00808     case WM_MATCHMNEMONIC:
00809     case WM_SAVEAPPLICATION:
00810     case WM_SEMANTICEVENT:
00811     default:
00812         dprintf2(("OS2: RunDefWndProc hwnd %x msg %x mp1 %x mp2 %x", hwnd, msg, mp1, mp2));
00813         goto RunDefWndProc;
00814     }
00815     if(win32wnd) RELEASE_WNDOBJ(win32wnd);
00816     RestoreOS2TIB();
00817     return (MRESULT)rc;
00818 
00819 RunDefWndProc:
00820 //  dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
00821     if(win32wnd) RELEASE_WNDOBJ(win32wnd);
00822     RestoreOS2TIB();
00823     return WinDefWindowProc( hwnd, msg, mp1, mp2 );
00824 } /* End of Win32WindowProc */
00825 //******************************************************************************
00826 //******************************************************************************
00827 MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
00828 {
00829  POSTMSG_PACKET  *postmsg;
00830  OSLIBPOINT       point, ClientPoint;
00831  Win32BaseWindow *win32wnd;
00832  TEB             *teb;
00833  MRESULT          rc = 0;
00834  MSG              winMsg, *pWinMsg;
00835 
00836     //Restore our FS selector
00837     SetWin32TIB();
00838 
00839     //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
00840     teb = GetThreadTEB();
00841     win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
00842 
00843     if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
00844         dprintf(("PMFRAME: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
00845         goto RunDefFrameWndProc;
00846     }
00847 ////    if(teb->o.odin.fIgnoreMsgs) {
00848 ////        goto RunDefWndProc;
00849 ////    }
00850 
00851     if((teb->o.odin.msgstate & 1) == 0)
00852     {//message that was sent directly to our window proc handler; translate it here
00853         QMSG qmsg;
00854 
00855         qmsg.msg  = msg;
00856         qmsg.hwnd = hwnd;
00857         qmsg.mp1  = mp1;
00858         qmsg.mp2  = mp2;
00859         qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
00860         WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
00861         qmsg.reserved = 0;
00862 
00863         if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
00864         {//message was not translated
00865             memset(&winMsg, 0, sizeof(MSG));
00866         }
00867         pWinMsg = &winMsg;
00868     }
00869     else {
00870         pWinMsg = &teb->o.odin.msg;
00871         teb->o.odin.msgstate++;
00872     }
00873     //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
00874 
00875     switch( msg )
00876     {
00877     case WM_CREATE:
00878     {
00879         //WM_CREATE handled during client window creation
00880         dprintf(("PMFRAME: WM_CREATE %x", hwnd));
00881         goto RunDefFrameWndProc;
00882     }
00883 
00884     case WM_PAINT:
00885     {
00886       RECTL rectl;
00887 
00888         HPS hps = WinBeginPaint(hwnd, NULL, &rectl);
00889         dprintf(("PMFRAME: WM_PAINT %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
00890 
00891         if(win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
00892            rectl.yBottom != rectl.yTop))
00893         {
00894             PRECT pClient = win32wnd->getClientRectPtr();
00895             PRECT pWindow = win32wnd->getWindowRect();
00896 
00897             if(!(pClient->left == 0 && pClient->top == 0 &&
00898                win32wnd->getClientHeight() == win32wnd->getWindowHeight() &&
00899                win32wnd->getClientWidth()  == win32wnd->getWindowWidth()))
00900             {
00901                 RECT rectUpdate;
00902 
00903                 mapOS2ToWin32Rect(win32wnd->getWindowHeight(), (PRECTLOS2)&rectl, &rectUpdate);
00904                 win32wnd->MsgNCPaint(&rectUpdate);
00905             }
00906         }
00907         WinEndPaint(hps);
00908         break;
00909     }
00910 
00911     case WM_ERASEBACKGROUND:
00912     {
00913         dprintf(("PMFRAME:WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
00914         rc = (MRESULT)FALSE;
00915         break;
00916     }
00917 
00918     //**************************************************************************
00919     //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
00920     //**************************************************************************
00921 
00922     case WM_BUTTON1DOWN:
00923     case WM_BUTTON1UP:
00924     case WM_BUTTON1DBLCLK:
00925     case WM_BUTTON2DOWN:
00926     case WM_BUTTON2UP:
00927     case WM_BUTTON2DBLCLK:
00928     case WM_BUTTON3DOWN:
00929     case WM_BUTTON3UP:
00930     case WM_BUTTON3DBLCLK:
00931         if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
00932             RELEASE_WNDOBJ(win32wnd);
00933             win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
00934         }
00935         if(win32wnd)
00936             win32wnd->MsgButton(pWinMsg);
00937 
00938         rc = (MRESULT)TRUE;
00939         break;
00940 
00941     case WM_BUTTON2MOTIONSTART:
00942     case WM_BUTTON2MOTIONEND:
00943     case WM_BUTTON2CLICK:
00944     case WM_BUTTON1MOTIONSTART:
00945     case WM_BUTTON1MOTIONEND:
00946     case WM_BUTTON1CLICK:
00947     case WM_BUTTON3MOTIONSTART:
00948     case WM_BUTTON3MOTIONEND:
00949     case WM_BUTTON3CLICK:
00950         rc = (MRESULT)TRUE;
00951         break;
00952 
00953     case WM_MOUSEMOVE:
00954     {
00955         if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
00956             RELEASE_WNDOBJ(win32wnd);
00957             win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
00958         }
00959         if(win32wnd)
00960             win32wnd->MsgMouseMove(pWinMsg);
00961         break;
00962     }
00963 
00964     case WM_ADJUSTWINDOWPOS:
00965     {
00966       PSWP     pswp = (PSWP)mp1;
00967       SWP      swpOld;
00968       WINDOWPOS wp,wpOld;
00969       ULONG     ulFlags;
00970       ULONG     ret = 0;
00971       HWND      hParent = NULLHANDLE, hwndAfter;
00972 
00973         dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS %x %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
00974 
00975         ulFlags = pswp->fl;
00976 
00977         if(win32wnd->IsParentChanging()) {
00978             rc = 0;
00979             break;
00980         }
00981 
00982         if(pswp->fl & SWP_NOADJUST) {
00983             //ignore weird messages (TODO: why are they sent?)
00984             dprintf(("WARNING: WM_ADJUSTWINDOWPOS with SWP_NOADJUST flag!!"));
00985             break;
00986         }
00987         //CB: show dialog in front of owner
00988         if (win32wnd->IsModalDialogOwner())
00989         {
00990             dprintf(("win32wnd->IsModalDialogOwner %x", win32wnd->getWindowHandle()));
00991             pswp->fl |= SWP_ZORDER;
00992             pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
00993             if (pswp->fl & SWP_ACTIVATE)
00994             {
00995                 pswp->fl &= ~SWP_ACTIVATE;
00996                 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
00997             }
00998         }
00999 
01000         if(!win32wnd->CanReceiveSizeMsgs())
01001             break;
01002 
01003         WinQueryWindowPos(hwnd, &swpOld);
01004         if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
01005             if (win32wnd->isChild()) {
01006                 if(win32wnd->getParent()) {
01007                         hParent = win32wnd->getParent()->getOS2WindowHandle();
01008                 }
01009                 else    goto RunDefFrameWndProc;
01010             }
01011         }
01012         hwndAfter = pswp->hwndInsertBehind;
01013         if(win32wnd->getParent()) {
01014              OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(), hwnd);
01015         }
01016         else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
01017 
01018         wp.hwnd = win32wnd->getWindowHandle();
01019         if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
01020         {
01021            Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
01022            dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
01023            if(wndAfter) {
01024                 wp.hwndInsertAfter = wndAfter->getWindowHandle();
01025                 RELEASE_WNDOBJ(wndAfter);
01026            }
01027            else wp.hwndInsertAfter = HWND_TOP_W;
01028         }
01029 
01030         wpOld = wp;
01031         win32wnd->MsgPosChanging((LPARAM)&wp);
01032 
01033         if(win32wnd->getOldStyle() != win32wnd->getStyle()) 
01034         {
01035              OSLibSetWindowStyle(win32wnd->getOS2FrameWindowHandle(), win32wnd->getOS2WindowHandle(), win32wnd->getStyle(), win32wnd->getExStyle());
01036              if(fOS2Look) {
01037                  DWORD dwOldStyle = win32wnd->getOldStyle();
01038                  DWORD dwStyle    = win32wnd->getStyle();
01039 
01040                  win32wnd->setOldStyle(dwStyle);
01041                  if((dwOldStyle & WS_MINIMIZE_W) && !(dwStyle & WS_MINIMIZE_W)) {
01042                      //SC_RESTORE -> SC_MINIMIZE
01043                      dprintf(("%x -> SC_RESTORE -> SC_MINIMIZE", win32wnd->getWindowHandle()));
01044                      FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_RESTORE, SC_MINIMIZE, hbmFrameMenu[0]);
01045                      if(dwStyle & WS_MAXIMIZE_W) {
01046                          //SC_MAXIMIZE -> SC_RESTORE
01047                          dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
01048                          FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[2]);
01049                      }
01050                  }
01051                  else
01052                  if((dwOldStyle & WS_MAXIMIZE_W) && !(dwStyle & WS_MAXIMIZE_W)) {
01053                      //SC_RESTORE -> SC_MAXIMIZE
01054                      dprintf(("%x -> SC_RESTORE -> SC_MAXIMIZE", win32wnd->getWindowHandle()));
01055                      FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_RESTORE, SC_MAXIMIZE, hbmFrameMenu[1]);
01056                  }
01057                  else
01058                  if(!(dwOldStyle & WS_MINIMIZE_W) && (dwStyle & WS_MINIMIZE_W)) {
01059                      //SC_MINIMIZE -> SC_RESTORE
01060                      dprintf(("%x -> SC_MINIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
01061                      FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_MINIMIZE, SC_RESTORE, hbmFrameMenu[2]);
01062                  }
01063                  else
01064                  if(!(dwOldStyle & WS_MAXIMIZE_W) && (dwStyle & WS_MAXIMIZE_W)) {
01065                      //SC_MAXIMIZE -> SC_RESTORE
01066                      dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
01067                      FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[2]);
01068                  }
01069              }
01070         }
01071 
01072         if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
01073             (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
01074         {
01075             ULONG flags = pswp->fl;      //make a backup copy; OSLibMapWINDOWPOStoSWP will modify it
01076 
01077             dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
01078             dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
01079 
01080             if(win32wnd->getParent()) {
01081                   OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getClientHeight(),
01082                                          hwnd);
01083             }
01084             else  OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), hwnd);
01085 
01086             dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
01087 
01088             //OSLibMapWINDOWPOStoSWP can add flags, but we must not let it remove flags!
01089             if(pswp->fl & SWP_SIZE)
01090                 flags |= SWP_SIZE;
01091 
01092             if(pswp->fl & SWP_MOVE)
01093                 flags |= SWP_MOVE;
01094 
01095             pswp->fl = flags;   //restore flags
01096 
01097             pswp->fl |= SWP_NOADJUST;
01098             pswp->hwndInsertBehind = hwndAfter;
01099             pswp->hwnd = hwnd;
01100 
01101             ret = 0xf;
01102         }
01103 adjustend:
01104         //The next part needs to be done for top-level windows only
01105         if(!((win32wnd->getStyle() & (WS_POPUP_W|WS_CHILD_W)) == WS_CHILD_W)) 
01106         {
01107             //Setting these flags is necessary to avoid activation/focus problems
01108             if(ulFlags & SWP_DEACTIVATE) {
01109                 ret |= AWP_DEACTIVATE;
01110             }
01111             if(ulFlags & SWP_ACTIVATE) 
01112             {
01113                 if(ulFlags & SWP_ZORDER) {
01114                     dprintf(("Set FF_NOACTIVATESWP"));
01115                     ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
01116                     WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags | FF_NOACTIVATESWP);
01117                 }
01118 
01119                 if(!(ulFlags & SWP_SHOW))
01120                 {
01121                     ret |= AWP_ACTIVATE;
01122                 }
01123                 else
01124                 {
01125                     FrameSetFocus(hwnd);
01126                 }
01127             }
01128         }
01129         else {
01130             if(ulFlags & (SWP_ACTIVATE|SWP_FOCUSACTIVATE)) 
01131             {
01132                 win32wnd->MsgChildActivate(TRUE);
01133                 if(fOS2Look) {
01134                     dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
01135                     WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, (MPARAM)1, 0);
01136                 }
01137             }
01138             else 
01139             if(ulFlags & (SWP_DEACTIVATE|SWP_FOCUSDEACTIVATE)) 
01140             {
01141                 win32wnd->MsgChildActivate(FALSE);
01142                 if(fOS2Look) {
01143                     dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
01144                     WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, 0, 0);
01145                 }
01146             }
01147         }
01148         dprintf(("WM_ADJUSTWINDOWPOS ret %x flags %x", ret, WinQueryWindowUShort(hwnd, QWS_FLAGS)));
01149         rc = (MRESULT)ret;
01150         break;
01151     }
01152 
01153     case WM_WINDOWPOSCHANGED:
01154     {
01155       PSWP      pswp    = (PSWP)mp1,pswpOld = pswp+1;
01156       SWP       swpOld  = *(pswp + 1);
01157       WINDOWPOS wp;
01158       ULONG     flAfp   = (ULONG)mp2;
01159       HWND      hParent = NULLHANDLE;
01160       RECTL     rect;
01161 
01162         dprintf(("PMFRAME:WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
01163         if(win32wnd->IsParentChanging()) {
01164             goto PosChangedEnd;
01165         }
01166 
01167         //SvL: When a window is made visible, then we don't receive a
01168         //     WM_VRNENABLED message (for some weird reason)
01169         if(pswp->fl & SWP_SHOW) {
01170             win32wnd->callVisibleRgnNotifyProc(TRUE);
01171         }
01172         else 
01173         if(pswp->fl & SWP_HIDE) {
01174             win32wnd->callVisibleRgnNotifyProc(FALSE);
01175         }
01176 
01177         if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
01178         {
01179             if(pswp->fl & SWP_RESTORE && win32wnd->getStyle() & WS_MINIMIZE_W) {
01180                 dprintf(("Restoring minimized window %x", win32wnd->getWindowHandle()));
01181                 win32wnd->ShowWindow(SW_RESTORE_W);
01182             }
01183             if(pswp->fl & SWP_SHOW) {
01184                 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
01185             }
01186             else
01187             if(pswp->fl & SWP_HIDE) {
01188                 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
01189             } 
01190             //MUST call the old frame window proc!
01191             goto RunDefFrameWndProc;
01192         }
01193 
01194         if(pswp->fl & (SWP_MOVE | SWP_SIZE))
01195         {
01196             if(win32wnd->isChild())
01197             {
01198                 if(win32wnd->getParent()) {
01199                         hParent = win32wnd->getParent()->getOS2WindowHandle();
01200                 }
01201                 else    goto PosChangedEnd; //parent has just been destroyed
01202             }
01203         }
01204 
01205 
01206         if(win32wnd->getParent()) {
01207              OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
01208                                     hwnd);
01209         }
01210         else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
01211 
01212         wp.hwnd = win32wnd->getWindowHandle();
01213         if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
01214         {
01215             Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
01216             dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
01217             if(wndAfter) {
01218                  wp.hwndInsertAfter = wndAfter->getWindowHandle();
01219                  RELEASE_WNDOBJ(wndAfter);
01220             }
01221             else wp.hwndInsertAfter = HWND_TOP_W;
01222         }
01223 
01224         if(pswp->fl & SWP_SHOW) {
01225             WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
01226         }
01227         else
01228         if(pswp->fl & SWP_HIDE) {
01229             WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
01230         }
01231 
01232         if(flAfp & AWP_ACTIVATE)
01233         {
01234             FrameSetFocus(hwnd);
01235         }
01236 
01237 #ifndef USE_CALCVALIDRECT
01238         if((pswp->fl & (SWP_MOVE | SWP_SIZE)))
01239         {
01240             //CB: todo: use result for WM_CALCVALIDRECTS
01241             //Get old client rectangle (for invalidation of frame window parts later on)
01242             //Use new window height to calculate the client area
01243             mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
01244 
01245             //Note: Also updates the new window rectangle
01246             win32wnd->MsgFormatFrame(&wp);
01247 
01248             if(win32wnd->isOwnDC()) {
01249                 setPageXForm(win32wnd, (pDCData)GpiQueryDCData(win32wnd->getOwnDC()));
01250             }
01251 
01252             if(win32wnd->CanReceiveSizeMsgs())
01253                 win32wnd->MsgPosChanged((LPARAM)&wp);
01254 
01255             if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
01256             {
01257                 //redraw the frame (to prevent unnecessary client updates)
01258                 BOOL redrawAll = FALSE;
01259 
01260                 dprintf2(("WM_WINDOWPOSCHANGED: redraw frame"));
01261                 if (win32wnd->getWindowClass())
01262                 {
01263                     DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
01264 
01265                     if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
01266                         redrawAll = TRUE;
01267                     else
01268                     if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
01269                         redrawAll = TRUE;
01270                 }
01271                 else redrawAll = TRUE;
01272 
01273                 if(win32wnd->IsMixMaxStateChanging()) {
01274                     dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
01275                     redrawAll = TRUE;
01276                 }
01277 
01278                 if (redrawAll)
01279                 {
01280                     //CB: redraw all children for now
01281                     //    -> problems with update region if we don't do it
01282                     //       todo: rewrite whole handling
01283                     WinInvalidateRect(hwnd,NULL,TRUE);
01284                 }
01285                 else
01286                 {
01287                     HPS hps = WinGetPS(hwnd);
01288                     RECTL frame,client,arcl[4];
01289 
01290                     WinQueryWindowRect(hwnd,&frame);
01291 
01292                     //top
01293                     arcl[0].xLeft = 0;
01294                     arcl[0].xRight = frame.xRight;
01295                     arcl[0].yBottom = rect.yTop;
01296                     arcl[0].yTop = frame.yTop;
01297                     //right
01298                     arcl[1].xLeft = rect.xRight;
01299                     arcl[1].xRight = frame.xRight;
01300                     arcl[1].yBottom = 0;
01301                     arcl[1].yTop = frame.yTop;
01302                     //left
01303                     arcl[2].xLeft = 0;
01304                     arcl[2].xRight = rect.xLeft;
01305                     arcl[2].yBottom = 0;
01306                     arcl[2].yTop = frame.yTop;
01307                     //bottom
01308                     arcl[3].xLeft = 0;
01309                     arcl[3].xRight = frame.xRight;
01310                     arcl[3].yBottom = 0;
01311                     arcl[3].yTop = rect.yBottom;
01312 
01313                     HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
01314 
01315                     WinInvalidateRegion(hwnd,hrgn,FALSE);
01316                     GpiDestroyRegion(hps,hrgn);
01317                     WinReleasePS(hps);
01318                 }
01319             }
01320         }
01321         else
01322         {
01323 #endif //USE_CALCVALIDRECT
01324             if(win32wnd->CanReceiveSizeMsgs())
01325                 win32wnd->MsgPosChanged((LPARAM)&wp);
01326 #ifndef USE_CALCVALIDRECT
01327         }
01328 #endif
01329 
01330 PosChangedEnd:
01331         rc = (MRESULT)FALSE;
01332         break;
01333     }
01334 
01335     case WM_CALCVALIDRECTS:
01336 #ifdef USE_CALCVALIDRECT
01337     {
01338         PRECTL    oldRect = (PRECTL)mp1, newRect = oldRect+1;
01339         PSWP      pswp = (PSWP)mp2;
01340         SWP       swpOld;
01341         WINDOWPOS wp;
01342         RECTL     newClientRect, oldClientRect;
01343         ULONG     nccalcret;
01344 //        UINT      res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
01345         UINT      res = 0;
01346 
01347         dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
01348 
01349         //Get old position info
01350         WinQueryWindowPos(hwnd, &swpOld);
01351 
01352         if(win32wnd->getParent()) {
01353              OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
01354                                     win32wnd->getParent()->getClientRectPtr()->left,
01355                                     win32wnd->getParent()->getClientRectPtr()->top,
01356                                     hwnd);
01357         }
01358         else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
01359 
01360         wp.hwnd = win32wnd->getWindowHandle();
01361         if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
01362         {
01363             Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
01364             if(wndAfter) {
01365                  wp.hwndInsertAfter = wndAfter->getWindowHandle();
01366                  RELEASE_WNDOBJ(wndAfter);
01367             }
01368             else wp.hwndInsertAfter = HWND_TOP_W;
01369         }
01370 
01371         //Get old client rectangle
01372         mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
01373 
01374         //Note: Also updates the new window rectangle
01375         nccalcret = win32wnd->MsgFormatFrame(&wp);
01376 
01377         //Get new client rectangle
01378         mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
01379 
01380         if(nccalcret == 0) {
01381             res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
01382         }
01383         else {
01384             if(nccalcret & WVR_ALIGNTOP_W) {
01385                 res |= CVR_ALIGNTOP;
01386             }
01387             else
01388             if(nccalcret & WVR_ALIGNBOTTOM_W) {
01389                 res |= CVR_ALIGNBOTTOM;
01390             }
01391 
01392             if(nccalcret & WVR_ALIGNLEFT_W) {
01393                 res |= CVR_ALIGNLEFT;
01394             }
01395             else
01396             if(nccalcret & WVR_ALIGNRIGHT_W) {
01397                 res |= CVR_ALIGNRIGHT;
01398             }
01399 
01400             if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
01401                 res |= CVR_REDRAW;
01402             }
01403             else
01404             if(nccalcret & WVR_VALIDRECTS_W) {
01405                 //TODO:
01406                 //res = 0;
01407             }
01408         }
01409         if(win32wnd->IsMixMaxStateChanging()) {
01410             dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
01411             res |= CVR_REDRAW;
01412         }
01413         if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
01414             oldRect->xRight  -= oldClientRect.xLeft;
01415             oldRect->yBottom += oldClientRect.yBottom;
01416             newRect->xRight  -= newClientRect.xLeft;
01417             newRect->yBottom += newClientRect.yBottom;
01418         }
01419         rc = res;
01420         break;
01421     }
01422 #else
01423         dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
01424         rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
01425         break;
01426 #endif
01427 
01428     case WM_CALCFRAMERECT:
01429         dprintf(("PMFRAME:WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
01430         rc = (MRESULT)TRUE;
01431         break;
01432 
01433     case WM_QUERYCTLTYPE:
01434         // This is a frame window
01435         dprintf(("PMFRAME:WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
01436         rc = (MRESULT)CCT_FRAME;
01437         break;
01438 
01439 #ifdef DEBUG
01440     case WM_QUERYFOCUSCHAIN:
01441         dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x parent %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), (mp2) ? OS2ToWin32Handle((DWORD)mp2) : 0));
01442 
01443         RestoreOS2TIB();
01444         rc = pfnFrameWndProc(hwnd, msg, mp1, mp2);
01445         SetWin32TIB();
01446         dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x parent %x returned %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), (mp2) ? OS2ToWin32Handle((DWORD)mp2) : 0, (rc) ? OS2ToWin32Handle((DWORD)rc) : 0));
01447         break;
01448 //        goto RunDefFrameWndProc;
01449 #endif
01450 
01451     case WM_FOCUSCHANGE:
01452     {
01453         HWND   hwndFocus = (HWND)mp1;
01454         HWND   hwndLoseFocus, hwndGainFocus;
01455         USHORT usSetFocus = SHORT1FROMMP(mp2);
01456         USHORT fsFocusChange = SHORT2FROMMP(mp2);
01457 
01458         //Save window that gains focus so we can determine which
01459         //process we lose activation to
01460         hwndFocusChange = (HWND)mp1;
01461 
01462         dprintf(("PMFRAME:WM_FOCUSCHANGE %x %x (%x) %x %x", win32wnd->getWindowHandle(), OS2ToWin32Handle(hwndFocus), hwndFocus, usSetFocus, fsFocusChange));
01463         goto RunDefFrameWndProc;
01464     }
01465 
01466 #ifdef DEBUG
01467     case WM_SETFOCUS:
01468     {
01469         dprintf(("PMFRAME: WM_SETFOCUS %x %x", win32wnd->getWindowHandle(), hwnd));
01470         goto RunDefFrameWndProc;
01471     }
01472 #endif
01473 
01474     case WM_ACTIVATE:
01475     {
01476         HWND hwndTitle;
01477         USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
01478 
01479         dprintf(("PMFRAME: WM_ACTIVATE %x %x %x", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle((DWORD)mp2)));
01480         if (win32wnd->IsWindowCreated())
01481         {
01482             WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
01483             if(fOS2Look) {
01484                 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
01485                 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, mp1, 0);
01486             }
01487             if(SHORT1FROMMP(mp1) == 0) {
01488                 //deactivate
01489                 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
01490             }
01491             PID pidThis, pidPartner, pidTemp;
01492             TID tidPartner;
01493             HENUM henum;
01494             HWND  hwndEnum;
01495 
01496             WinQueryWindowProcess(hwnd, &pidThis, NULL);
01497             WinQueryWindowProcess(hwndFocusChange, &pidPartner, &tidPartner);
01498 
01499             if(pidThis != pidPartner) {
01500                 //Gain or lose activation to window in other process
01501                 //must send WM_ACTIVATEAPP to top-level windows
01502 
01503                 //Iterate over all child windows of the desktop
01504                 henum = WinBeginEnumWindows(HWND_DESKTOP);
01505 
01506                 while(hwndEnum = WinGetNextWindow(henum))
01507                 {
01508                     WinQueryWindowProcess(hwndEnum, &pidTemp, NULL);
01509                     if(pidTemp == pidThis)
01510                     {
01511                         SendMessageA(OS2ToWin32Handle(hwndEnum), WM_ACTIVATEAPP_W, (WPARAM)SHORT1FROMMP(mp1), (LPARAM)tidPartner);
01512                     }
01513                 }
01514                 WinEndEnumWindows(henum);
01515             }
01516             if(SHORT1FROMMP(mp1)) {
01517                 //activate
01518                 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
01519             }
01520 
01521             //CB: show owner behind the dialog
01522             if (win32wnd->IsModalDialog())
01523             {
01524                 if(win32wnd->getOwner()) {
01525                     Win32BaseWindow *topOwner = Win32BaseWindow::GetWindowFromHandle(win32wnd->getOwner()->GetTopParent());
01526  
01527                     if (topOwner) {
01528                         WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
01529                         RELEASE_WNDOBJ(topOwner);
01530                     }
01531                 }
01532             }
01533         }
01534         else
01535         {
01536             WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
01537         }
01538         rc = 0;
01539         break;
01540     }
01541 
01542     case WM_ENABLE:
01543         dprintf(("PMFRAME: WM_ENABLE %x", hwnd));
01544         win32wnd->MsgEnable(SHORT1FROMMP(mp1));
01545         break;
01546 
01547     case WM_SHOW:
01548         dprintf(("PMFRAME: WM_SHOW %x %d", hwnd, mp1));
01549         //show client window
01550         WinShowWindow(win32wnd->getOS2WindowHandle(), (BOOL)mp1);
01551         break;
01552 
01553     case WM_QUERYTRACKINFO:
01554     {
01555         PTRACKINFO trackInfo = (PTRACKINFO)mp2;
01556 
01557         dprintf(("PMFRAME:WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
01558         trackInfo->cxBorder = 4;
01559         trackInfo->cyBorder = 4;
01560         win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
01561         rc = (MRESULT)TRUE;
01562         break;
01563     }
01564 
01565     case WM_QUERYBORDERSIZE:
01566     {
01567         PWPOINT size = (PWPOINT)mp1;
01568 
01569         dprintf(("PMFRAME:WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
01570 
01571         size->x = 0;
01572         size->y = 0;
01573         rc = (MRESULT)TRUE;
01574         break;
01575     }
01576 
01577 #ifdef DEBUG
01578     case WM_QUERYFRAMEINFO:
01579         dprintf(("PMFRAME:WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
01580         goto RunDefFrameWndProc;
01581 #endif
01582 
01583     case WM_FORMATFRAME:
01584         dprintf(("PMFRAME:WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
01585         break;
01586 
01587 #ifdef DEBUG
01588     case WM_ADJUSTFRAMEPOS:
01589     {
01590         PSWP pswp   = (PSWP)mp1;
01591 
01592         dprintf(("PMFRAME:WM_ADJUSTFRAMEPOS %x %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
01593         goto RunDefFrameWndProc;
01594     }
01595 
01596     case WM_OWNERPOSCHANGE:
01597     {
01598         PSWP pswp   = (PSWP)mp1;
01599 
01600         dprintf(("PMFRAME:WM_OWNERPOSCHANGE %x %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
01601         goto RunDefFrameWndProc;
01602     }
01603 #endif
01604 
01605     case WM_MINMAXFRAME:
01606     {
01607         PSWP swp = (PSWP)mp1;
01608 
01609         if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
01610 
01611         dprintf(("PMFRAME:WM_MINMAXFRAME %x",hwnd));
01612         if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
01613         {
01614             win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
01615 
01616             RECT rect;
01617 
01618             rect.left = rect.top = rect.right = rect.bottom = 0;
01619             win32wnd->AdjustMaximizedRect(&rect);
01620             swp->x += rect.left;
01621             swp->cx += rect.right-rect.left;
01622             swp->y -= rect.bottom;
01623             swp->cy += rect.bottom-rect.top;
01624         }
01625         else
01626         if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
01627         {
01628             win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
01629         }
01630         else
01631         if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
01632         {
01633             win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
01634         }
01635         goto RunDefWndProc;
01636     }
01637 
01638 #ifdef DEBUG
01639     case WM_UPDATEFRAME:
01640         dprintf(("PMFRAME:WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
01641         goto RunDefFrameWndProc;
01642 #endif
01643 
01644     case WM_TRACKFRAME:
01645         dprintf(("PMFRAME: WM_TRACKFRAME %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
01646         if(fOS2Look) {//sent by titlebar control
01647 #ifdef CUSTOM_TRACKFRAME
01648             Frame_SysCommandSizeMove(win32wnd, SC_MOVE_W+HTCAPTION_W);
01649 #else
01650             FrameTrackFrame(win32wnd, TF_MOVE);
01651 #endif
01652         }
01653         rc = 0;
01654         break;
01655 
01656     case WM_SYSCOMMAND:
01657         dprintf(("PMFRAME: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
01658         if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
01659             RELEASE_WNDOBJ(win32wnd);
01660             win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
01661         }
01662         if(win32wnd)
01663             win32wnd->DispatchMsgA(pWinMsg);
01664         break;
01665 
01666 #ifdef DEBUG
01667     case WM_DDE_INITIATE:
01668     case WM_DDE_INITIATEACK:
01669     case WM_DDE_REQUEST:
01670     case WM_DDE_ACK:
01671     case WM_DDE_DATA:
01672     case WM_DDE_ADVISE:
01673     case WM_DDE_UNADVISE:
01674     case WM_DDE_POKE:
01675     case WM_DDE_EXECUTE:
01676     case WM_DDE_TERMINATE:
01677          dprintf(("PMFRAME: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
01678          break;
01679 #endif
01680 
01681     default:
01682         goto RunDefFrameWndProc;
01683     }
01684     RestoreOS2TIB();
01685     if(win32wnd) RELEASE_WNDOBJ(win32wnd);
01686     return (MRESULT)rc;
01687 
01688 RunDefFrameWndProc:
01689     dprintf2(("RunDefFrameWndProc"));
01690     if(win32wnd) RELEASE_WNDOBJ(win32wnd);
01691     RestoreOS2TIB();
01692     return pfnFrameWndProc(hwnd, msg, mp1, mp2);
01693 
01694 RunDefWndProc:
01695     dprintf2(("RunDefWndProc"));
01696     if(win32wnd) RELEASE_WNDOBJ(win32wnd);
01697     RestoreOS2TIB();
01698     //calling WinDefWindowProc here breaks Opera hotlist window (WM_ADJUSTWINDOWPOS)
01699 //    return pfnFrameWndProc(hwnd, msg, mp1, mp2);
01700     return WinDefWindowProc( hwnd, msg, mp1, mp2 );
01701 }
01702 //******************************************************************************
01703 //******************************************************************************
01704 void FrameSetFocus(HWND hwnd)
01705 {
01706     HWND hwndFocusSave = WinQueryWindowULong(hwnd, QWL_HWNDFOCUSSAVE);
01707     if(!WinIsWindow(hab, hwndFocusSave)) {
01708         hwndFocusSave = WinWindowFromID(hwnd, FID_CLIENT);
01709         WinSetWindowULong(hwnd, QWL_HWNDFOCUSSAVE, hwndFocusSave);
01710     }
01711     dprintf(("FrameSetFocus: hwndFocusSave %x %x", OS2ToWin32Handle(hwndFocusSave), hwndFocusSave));
01712     WinSetFocus(HWND_DESKTOP, hwndFocusSave);
01713 
01714     ULONG ulFrameFlags  = WinQueryWindowUShort(hwnd, QWS_FLAGS);
01715     ulFrameFlags &= ~FF_NOACTIVATESWP;
01716     WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags);
01717 }
01718 #ifndef CUSTOM_TRACKFRAME 
01719 //******************************************************************************
01720 //TODO: Quickly moving a window two times doesn't force a repaint (1st time)
01721 //
01722 //
01723 BOOL (APIENTRY *WinTrackWindow)(HWND hwndTrack, PTRACKINFO pti) = NULL;
01724 //
01725 //******************************************************************************
01726 VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
01727 {
01728   TRACKINFO track;
01729   RECTL     rcl;
01730   PRECT     pWindowRect, pClientRect;
01731   HWND      hwndTracking;
01732   LONG      parentHeight, parentWidth;
01733   static    BOOL fInit = FALSE;
01734   APIRET    rc;
01735   BOOL      ret;
01736   HWND      hwnd = win32wnd->getWindowHandle();
01737 
01738     if(!fInit) {
01739         HMODULE hModule;
01740         char    buf[CCHMAXPATH];
01741         rc = DosLoadModule(buf, sizeof(buf), "PMMERGE", &hModule);
01742         rc = DosQueryProcAddr(hModule, 5466, NULL, (PFN *)&WinTrackWindow);
01743         if(rc) WinTrackWindow = NULL;
01744         fInit = TRUE;
01745     }
01746     dprintf(("FrameTrackFrame: %x %x", hwnd, flags));
01747     track.cxBorder = 4;
01748     track.cyBorder = 4;  /* 4 pel wide lines used for rectangle */
01749     track.cxGrid = 1;
01750     track.cyGrid = 1;    /* smooth tracking with mouse */
01751     track.cxKeyboard = 8;
01752     track.cyKeyboard = 8; /* faster tracking using cursor keys */
01753 
01754     pWindowRect = win32wnd->getWindowRect();
01755     if(win32wnd->getParent()) {
01756         parentHeight = win32wnd->getParent()->getClientHeight();
01757         parentWidth  = win32wnd->getParent()->getClientWidth();
01758         hwndTracking = win32wnd->getParent()->getOS2WindowHandle();
01759     }
01760     else {
01761         parentHeight = OSLibQueryScreenHeight();
01762         parentWidth  = OSLibQueryScreenWidth();
01763         hwndTracking = HWND_DESKTOP;
01764     }
01765 
01766     mapWin32ToOS2Rect(parentHeight, pWindowRect, (PRECTLOS2)&track.rclTrack);
01767     rcl = track.rclTrack;
01768     WinQueryWindowRect(hwndTracking, &track.rclBoundary);
01769 
01770     track.ptlMinTrackSize.x = 10;
01771     track.ptlMinTrackSize.y = 10;  /* set smallest allowed size of rectangle */
01772     track.ptlMaxTrackSize.x = parentWidth;
01773     track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */
01774 
01775     win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize);
01776 
01777     track.fs = flags;
01778 
01779     BOOL fDynamicDrag = WinQuerySysValue(HWND_DESKTOP, SVOS_DYNAMICDRAG);
01780 
01781     //TODO: send WM_QUERYDRAGICON to fetch icon (not really necessary)
01782 
01783     SendMessageA( hwnd, WM_ENTERSIZEMOVE_W, 0, 0);
01784 
01785     SEL sel = RestoreOS2FS();
01786     if(fDynamicDrag && WinTrackWindow) {
01787          ret = WinTrackWindow(win32wnd->getOS2FrameWindowHandle(), &track);
01788     }
01789     else ret = WinTrackRect(hwndTracking, NULL, &track);
01790     SetFS(sel);
01791 
01792 //TODO:
01793 //    if (HOOK_CallHooksA( WH_CBT_W, HCBT_MOVESIZE_W, (WPARAM)hwnd, (LPARAM)&sizingRect )) moved = FALSE;
01794 
01795     SendMessageA( hwnd, WM_EXITSIZEMOVE_W, 0, 0 );
01796     SendMessageA( hwnd, WM_SETVISIBLE_W, !IsIconic(hwnd), 0L);
01797 
01798     if(ret) {
01799         /* if successful copy final position back */
01800         if(!WinEqualRect(0, &rcl, &track.rclTrack)) {
01801             dprintf(("FrameTrackFrame: new (os/2) window rect: (%d,%d)(%d,%d)", track.rclTrack.xLeft, track.rclTrack.yBottom, track.rclTrack.xRight - track.rclTrack.xLeft, track.rclTrack.yTop - track.rclTrack.yBottom));
01802             if(flags == TF_MOVE) {
01803                 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
01804                                 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
01805                                 0, 0, SWP_MOVE);
01806             }
01807             else {
01808                 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
01809                                 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
01810                                 track.rclTrack.xRight - track.rclTrack.xLeft,
01811                                 track.rclTrack.yTop - track.rclTrack.yBottom,
01812                                 SWP_SIZE|SWP_MOVE);
01813             }
01814         }
01815         return;
01816    }
01817    return;
01818 }
01819 #endif
01820 //******************************************************************************
01821 //******************************************************************************
01822 void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG   idNew,
01823                           HBITMAP hbmNew)
01824 {
01825     MENUITEM mi;
01826 
01827     if (!hwndMenu)
01828         return;
01829 
01830     WinEnableWindowUpdate(hwndMenu, FALSE);
01831 
01832     if (WinSendMsg(hwndMenu, MM_QUERYITEM, MPFROM2SHORT(idOld, TRUE), MPFROMP(&mi)))
01833     {
01834         WinSendMsg(hwndMenu, MM_REMOVEITEM, (MPARAM)idOld, 0);
01835         mi.afStyle     = MIS_BITMAP | MIS_SYSCOMMAND;
01836         mi.afAttribute = 0;
01837         mi.hwndSubMenu = 0;
01838         mi.id    = idNew;
01839         mi.hItem = (ULONG)hbmNew;
01840         WinSendMsg(hwndMenu, MM_INSERTITEM, (MPARAM)&mi, 0);
01841     }
01842     WinEnableWindowUpdate(hwndMenu, TRUE);
01843 
01844     WinInvalidateRect(hwndMenu, NULL, TRUE);
01845 }
01846 //******************************************************************************
01847 //******************************************************************************

Generated on Wed Jan 23 23:17:41 2002 for ODIN-user32 by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001