| 1 | /* $Id: pmwindow.cpp,v 1.106 2000-10-22 14:54:35 sandervl Exp $ */ | 
|---|
| 2 | /* | 
|---|
| 3 | * Win32 Window Managment Code for OS/2 | 
|---|
| 4 | * | 
|---|
| 5 | * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl) | 
|---|
| 6 | * Copyright 1999      Daniela Engert (dani@ngrt.de) | 
|---|
| 7 | * | 
|---|
| 8 | * | 
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 10 | * | 
|---|
| 11 | */ | 
|---|
| 12 | #define INCL_WIN | 
|---|
| 13 | #define INCL_GPI | 
|---|
| 14 | #define INCL_DEV                /* Device Function definitions  */ | 
|---|
| 15 | #define INCL_GPICONTROL         /* GPI control Functions        */ | 
|---|
| 16 | #define INCL_DOSPROCESS | 
|---|
| 17 | #define INCL_WINTRACKRECT | 
|---|
| 18 |  | 
|---|
| 19 | #include <os2wrap.h> | 
|---|
| 20 | #include <stdlib.h> | 
|---|
| 21 | #include <string.h> | 
|---|
| 22 | #include <win32type.h> | 
|---|
| 23 | #include <winconst.h> | 
|---|
| 24 | #include <wprocess.h> | 
|---|
| 25 | #include <misc.h> | 
|---|
| 26 | #include <win32wbase.h> | 
|---|
| 27 | #include <win32dlg.h> | 
|---|
| 28 | #include "win32wdesktop.h" | 
|---|
| 29 | #include "pmwindow.h" | 
|---|
| 30 | #include "oslibwin.h" | 
|---|
| 31 | #include "oslibutil.h" | 
|---|
| 32 | #include "oslibgdi.h" | 
|---|
| 33 | #include "oslibmsg.h" | 
|---|
| 34 | #include "dc.h" | 
|---|
| 35 | #include <thread.h> | 
|---|
| 36 | #include <wprocess.h> | 
|---|
| 37 | #include "caret.h" | 
|---|
| 38 | #include "timer.h" | 
|---|
| 39 | #include <codepage.h> | 
|---|
| 40 |  | 
|---|
| 41 | #define DBG_LOCALLOG    DBG_pmwindow | 
|---|
| 42 | #include "dbglocal.h" | 
|---|
| 43 |  | 
|---|
| 44 | HMQ  hmq = 0;                             /* Message queue handle         */ | 
|---|
| 45 | HAB  hab = 0; | 
|---|
| 46 |  | 
|---|
| 47 | RECTL desktopRectl = {0}; | 
|---|
| 48 | ULONG ScreenWidth  = 0; | 
|---|
| 49 | ULONG ScreenHeight = 0; | 
|---|
| 50 | ULONG ScreenBitsPerPel = 0; | 
|---|
| 51 |  | 
|---|
| 52 |  | 
|---|
| 53 | MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2); | 
|---|
| 54 |  | 
|---|
| 55 | //****************************************************************************** | 
|---|
| 56 | //Initialize PM; create hab, message queue and register special Win32 window classes | 
|---|
| 57 | //****************************************************************************** | 
|---|
| 58 | BOOL InitPM() | 
|---|
| 59 | { | 
|---|
| 60 |  | 
|---|
| 61 | hab = WinInitialize(0); | 
|---|
| 62 | dprintf(("Winitialize returned %x", hab)); | 
|---|
| 63 | hmq = WinCreateMsgQueue(hab, 0); | 
|---|
| 64 |  | 
|---|
| 65 | if(!hab || !hmq) | 
|---|
| 66 | { | 
|---|
| 67 | UINT error; | 
|---|
| 68 | //CB: only fail on real error | 
|---|
| 69 | error = WinGetLastError(hab) & 0xFFFF; //error code | 
|---|
| 70 | if (!hab || (error != PMERR_MSG_QUEUE_ALREADY_EXISTS)) | 
|---|
| 71 | { | 
|---|
| 72 | dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq)); | 
|---|
| 73 | dprintf((" Error = %x",error)); | 
|---|
| 74 | return(FALSE); | 
|---|
| 75 | } | 
|---|
| 76 | else | 
|---|
| 77 | { | 
|---|
| 78 | if(!hab) { | 
|---|
| 79 | hab = WinQueryAnchorBlock(HWND_DESKTOP); | 
|---|
| 80 | dprintf(("WinQueryAnchorBlock returned %x", hab)); | 
|---|
| 81 | } | 
|---|
| 82 | if(!hmq) { | 
|---|
| 83 | hmq = HMQ_CURRENT; | 
|---|
| 84 | } | 
|---|
| 85 | } | 
|---|
| 86 | } | 
|---|
| 87 | SetThreadHAB(hab); | 
|---|
| 88 | dprintf(("InitPM: hmq = %x", hmq)); | 
|---|
| 89 | SetThreadMessageQueue(hmq); | 
|---|
| 90 |  | 
|---|
| 91 | BOOL rc = WinSetCp(hmq, GetDisplayCodepage()); | 
|---|
| 92 | dprintf(("InitPM: WinSetCP was %sOK", rc ? "" : "not ")); | 
|---|
| 93 |  | 
|---|
| 94 | if(!WinRegisterClass(                 /* Register window class        */ | 
|---|
| 95 | hab,                               /* Anchor block handle          */ | 
|---|
| 96 | (PSZ)WIN32_STDCLASS,               /* Window class name            */ | 
|---|
| 97 | (PFNWP)Win32WindowProc,            /* Address of window procedure  */ | 
|---|
| 98 | CS_HITTEST, | 
|---|
| 99 | NROF_WIN32WNDBYTES)) { | 
|---|
| 100 | dprintf(("WinRegisterClass Win32BaseWindow failed")); | 
|---|
| 101 | return(FALSE); | 
|---|
| 102 | } | 
|---|
| 103 |  | 
|---|
| 104 | CLASSINFO FrameClassInfo; | 
|---|
| 105 | if(!WinQueryClassInfo (hab, WC_FRAME, &FrameClassInfo)) { | 
|---|
| 106 | dprintf (("WinQueryClassInfo WC_FRAME failed")); | 
|---|
| 107 | return (FALSE); | 
|---|
| 108 | } | 
|---|
| 109 | dprintf(("WC_FRAME style %x", FrameClassInfo.flClassStyle)); | 
|---|
| 110 |  | 
|---|
| 111 | if(!WinRegisterClass(                 /* Register window class        */ | 
|---|
| 112 | hab,                               /* Anchor block handle          */ | 
|---|
| 113 | (PSZ)WIN32_STDFRAMECLASS,          /* Window class name            */ | 
|---|
| 114 | (PFNWP)Win32WindowProc,            /* Address of window procedure  */ | 
|---|
| 115 | CS_HITTEST | CS_FRAME, | 
|---|
| 116 | FrameClassInfo.cbWindowData+NROF_WIN32WNDBYTES)) { | 
|---|
| 117 | dprintf(("WinRegisterClass Win32BaseWindow failed %x", WinGetLastError(hab))); | 
|---|
| 118 | return(FALSE); | 
|---|
| 119 | } | 
|---|
| 120 |  | 
|---|
| 121 | WinQueryWindowRect(HWND_DESKTOP, &desktopRectl); | 
|---|
| 122 | ScreenWidth  = desktopRectl.xRight; | 
|---|
| 123 | ScreenHeight = desktopRectl.yTop; | 
|---|
| 124 |  | 
|---|
| 125 | HDC   hdc;              /* Device-context handle                */ | 
|---|
| 126 | /* context data structure */ | 
|---|
| 127 | DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL, | 
|---|
| 128 | NULL, NULL, NULL}; | 
|---|
| 129 |  | 
|---|
| 130 | /* create memory device context */ | 
|---|
| 131 | hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE); | 
|---|
| 132 | DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, (PLONG)&ScreenBitsPerPel); | 
|---|
| 133 | DevCloseDC(hdc); | 
|---|
| 134 |  | 
|---|
| 135 | dprintf(("InitPM: Desktop (%d,%d)", ScreenWidth, ScreenHeight)); | 
|---|
| 136 | return TRUE; | 
|---|
| 137 | } /* End of main */ | 
|---|
| 138 | //****************************************************************************** | 
|---|
| 139 | //Win32 window message handler | 
|---|
| 140 | //****************************************************************************** | 
|---|
| 141 | MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2) | 
|---|
| 142 | { | 
|---|
| 143 | POSTMSG_PACKET  *postmsg; | 
|---|
| 144 | OSLIBPOINT       point, ClientPoint; | 
|---|
| 145 | Win32BaseWindow *win32wnd; | 
|---|
| 146 | THDB            *thdb; | 
|---|
| 147 | APIRET           rc = 0; | 
|---|
| 148 | MSG              winMsg, *pWinMsg; | 
|---|
| 149 |  | 
|---|
| 150 | //Restore our FS selector | 
|---|
| 151 | SetWin32TIB(); | 
|---|
| 152 |  | 
|---|
| 153 | thdb = GetThreadTHDB(); | 
|---|
| 154 | win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd); | 
|---|
| 155 |  | 
|---|
| 156 | if(!thdb || (msg != WM_CREATE && win32wnd == NULL)) { | 
|---|
| 157 | dprintf(("Invalid win32wnd pointer for window %x msg %x", hwnd, msg)); | 
|---|
| 158 | goto RunDefWndProc; | 
|---|
| 159 | } | 
|---|
| 160 |  | 
|---|
| 161 | if((thdb->msgstate & 1) == 0) | 
|---|
| 162 | {//message that was sent directly to our window proc handler; translate it here | 
|---|
| 163 | QMSG qmsg; | 
|---|
| 164 |  | 
|---|
| 165 | qmsg.msg  = msg; | 
|---|
| 166 | qmsg.hwnd = hwnd; | 
|---|
| 167 | qmsg.mp1  = mp1; | 
|---|
| 168 | qmsg.mp2  = mp2; | 
|---|
| 169 | qmsg.time = WinQueryMsgTime(thdb->hab); | 
|---|
| 170 | WinQueryMsgPos(thdb->hab, &qmsg.ptl); | 
|---|
| 171 | qmsg.reserved = 0; | 
|---|
| 172 |  | 
|---|
| 173 | if(OS2ToWinMsgTranslate((PVOID)thdb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE) | 
|---|
| 174 | {//message was not translated | 
|---|
| 175 | memset(&winMsg, 0, sizeof(MSG)); | 
|---|
| 176 | } | 
|---|
| 177 | pWinMsg = &winMsg; | 
|---|
| 178 | } | 
|---|
| 179 | else { | 
|---|
| 180 | pWinMsg = &thdb->msg; | 
|---|
| 181 | thdb->msgstate++; | 
|---|
| 182 | } | 
|---|
| 183 |  | 
|---|
| 184 | if(msg == WIN32APP_POSTMSG) { | 
|---|
| 185 | //probably win32 app user message | 
|---|
| 186 | if((ULONG)mp1 == WIN32MSG_MAGICA) { | 
|---|
| 187 | return (MRESULT)win32wnd->DispatchMsgA(pWinMsg); | 
|---|
| 188 | } | 
|---|
| 189 | else | 
|---|
| 190 | if((ULONG)mp1 == WIN32MSG_MAGICW) { | 
|---|
| 191 | return (MRESULT)win32wnd->DispatchMsgW(pWinMsg); | 
|---|
| 192 | } | 
|---|
| 193 | } | 
|---|
| 194 | switch( msg ) | 
|---|
| 195 | { | 
|---|
| 196 | //OS/2 msgs | 
|---|
| 197 | case WM_CREATE: | 
|---|
| 198 | { | 
|---|
| 199 | if(thdb->newWindow == 0) | 
|---|
| 200 | goto createfail; | 
|---|
| 201 |  | 
|---|
| 202 | //Processing is done in after WinCreateWindow returns | 
|---|
| 203 | dprintf(("OS2: WM_CREATE %x", hwnd)); | 
|---|
| 204 | win32wnd = (Win32BaseWindow *)thdb->newWindow; | 
|---|
| 205 | thdb->newWindow = 0; | 
|---|
| 206 | if(win32wnd->MsgCreate(hwnd) == FALSE) | 
|---|
| 207 | { | 
|---|
| 208 | RestoreOS2TIB(); | 
|---|
| 209 | return (MRESULT)TRUE; //discontinue window creation | 
|---|
| 210 | } | 
|---|
| 211 | createfail: | 
|---|
| 212 | RestoreOS2TIB(); | 
|---|
| 213 | return (MRESULT)FALSE; | 
|---|
| 214 | } | 
|---|
| 215 |  | 
|---|
| 216 | case WM_QUIT: | 
|---|
| 217 | dprintf(("OS2: WM_QUIT %x", hwnd)); | 
|---|
| 218 | win32wnd->MsgQuit(); | 
|---|
| 219 | break; | 
|---|
| 220 |  | 
|---|
| 221 | case WM_CLOSE: | 
|---|
| 222 | dprintf(("OS2: WM_CLOSE %x", hwnd)); | 
|---|
| 223 | win32wnd->MsgClose(); | 
|---|
| 224 | break; | 
|---|
| 225 |  | 
|---|
| 226 | case WM_DESTROY: | 
|---|
| 227 | dprintf(("OS2: WM_DESTROY %x", hwnd)); | 
|---|
| 228 | win32wnd->MsgDestroy(); | 
|---|
| 229 | WinSetVisibleRegionNotify(hwnd, FALSE); | 
|---|
| 230 | goto RunDefWndProc; | 
|---|
| 231 |  | 
|---|
| 232 | case WM_ENABLE: | 
|---|
| 233 | dprintf(("OS2: WM_ENABLE %x", hwnd)); | 
|---|
| 234 | win32wnd->MsgEnable(SHORT1FROMMP(mp1)); | 
|---|
| 235 | break; | 
|---|
| 236 |  | 
|---|
| 237 | case WM_SHOW: | 
|---|
| 238 | dprintf(("OS2: WM_SHOW %x %d", hwnd, mp1)); | 
|---|
| 239 | win32wnd->MsgShow((ULONG)mp1); | 
|---|
| 240 | break; | 
|---|
| 241 |  | 
|---|
| 242 | case WM_ADJUSTWINDOWPOS: | 
|---|
| 243 | { | 
|---|
| 244 | PSWP     pswp = (PSWP)mp1; | 
|---|
| 245 | SWP      swpOld; | 
|---|
| 246 | WINDOWPOS wp,wpOld; | 
|---|
| 247 | HWND      hParent = NULLHANDLE, hwndAfter; | 
|---|
| 248 |  | 
|---|
| 249 | dprintf(("OS2: WM_ADJUSTWINDOWPOS %x %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy)); | 
|---|
| 250 |  | 
|---|
| 251 | if(pswp->fl & SWP_NOADJUST) { | 
|---|
| 252 | //ignore weird messages (TODO: why are they sent?) | 
|---|
| 253 | break; | 
|---|
| 254 | } | 
|---|
| 255 | //CB: show dialog in front of owner | 
|---|
| 256 | if (win32wnd->IsModalDialogOwner()) | 
|---|
| 257 | { | 
|---|
| 258 | pswp->fl |= SWP_ZORDER; | 
|---|
| 259 | pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog(); | 
|---|
| 260 | if (pswp->fl & SWP_ACTIVATE) | 
|---|
| 261 | { | 
|---|
| 262 | pswp->fl &= ~SWP_ACTIVATE; | 
|---|
| 263 | WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE); | 
|---|
| 264 | } | 
|---|
| 265 | } | 
|---|
| 266 |  | 
|---|
| 267 | if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) | 
|---|
| 268 | goto RunDefWndProc; | 
|---|
| 269 |  | 
|---|
| 270 | if(!win32wnd->CanReceiveSizeMsgs()) | 
|---|
| 271 | break; | 
|---|
| 272 |  | 
|---|
| 273 | WinQueryWindowPos(hwnd, &swpOld); | 
|---|
| 274 | if(pswp->fl & (SWP_MOVE | SWP_SIZE)) { | 
|---|
| 275 | if (win32wnd->isChild()) { | 
|---|
| 276 | if(win32wnd->getParent()) { | 
|---|
| 277 | hParent = win32wnd->getParent()->getOS2WindowHandle(); | 
|---|
| 278 | } | 
|---|
| 279 | else    goto RunDefWndProc; | 
|---|
| 280 | } | 
|---|
| 281 | } | 
|---|
| 282 | hwndAfter = pswp->hwndInsertBehind; | 
|---|
| 283 | if(win32wnd->getParent()) { | 
|---|
| 284 | OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getWindowHeight(), | 
|---|
| 285 | win32wnd->getParent()->getClientRectPtr()->left, | 
|---|
| 286 | win32wnd->getParent()->getClientRectPtr()->top, | 
|---|
| 287 | hwnd); | 
|---|
| 288 | } | 
|---|
| 289 | else  OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd); | 
|---|
| 290 |  | 
|---|
| 291 | wp.hwnd = win32wnd->getWindowHandle(); | 
|---|
| 292 | if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM)) | 
|---|
| 293 | { | 
|---|
| 294 | Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind); | 
|---|
| 295 | if(wndAfter) { | 
|---|
| 296 | wp.hwndInsertAfter = wndAfter->getWindowHandle(); | 
|---|
| 297 | } | 
|---|
| 298 | else wp.hwndInsertAfter = HWND_TOP_W; | 
|---|
| 299 | } | 
|---|
| 300 |  | 
|---|
| 301 | wpOld = wp; | 
|---|
| 302 | win32wnd->MsgPosChanging((LPARAM)&wp); | 
|---|
| 303 |  | 
|---|
| 304 | if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) || | 
|---|
| 305 | (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags)) | 
|---|
| 306 | { | 
|---|
| 307 | dprintf(("OS2: WM_ADJUSTWINDOWPOS, app changed windowpos struct")); | 
|---|
| 308 | dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy)); | 
|---|
| 309 |  | 
|---|
| 310 | if(win32wnd->getParent()) { | 
|---|
| 311 | OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getWindowHeight(), | 
|---|
| 312 | win32wnd->getParent()->getClientRectPtr()->left, | 
|---|
| 313 | win32wnd->getParent()->getClientRectPtr()->top, | 
|---|
| 314 | hwnd); | 
|---|
| 315 | } | 
|---|
| 316 | else  OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd); | 
|---|
| 317 |  | 
|---|
| 318 | dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy)); | 
|---|
| 319 | pswp->fl |= SWP_NOADJUST; | 
|---|
| 320 | pswp->hwndInsertBehind = hwndAfter; | 
|---|
| 321 | pswp->hwnd = hwnd; | 
|---|
| 322 |  | 
|---|
| 323 | RestoreOS2TIB(); | 
|---|
| 324 | return (MRESULT)0xf; | 
|---|
| 325 | } | 
|---|
| 326 | RestoreOS2TIB(); | 
|---|
| 327 | return (MRESULT)0; | 
|---|
| 328 | } | 
|---|
| 329 |  | 
|---|
| 330 | case WM_WINDOWPOSCHANGED: | 
|---|
| 331 | { | 
|---|
| 332 | PSWP      pswp   = (PSWP)mp1,pswpOld = pswp+1; | 
|---|
| 333 | SWP       swpOld = *(pswp + 1); | 
|---|
| 334 | WINDOWPOS wp; | 
|---|
| 335 | HWND      hParent = NULLHANDLE; | 
|---|
| 336 | RECTL rect; | 
|---|
| 337 |  | 
|---|
| 338 | dprintf(("OS2: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy)); | 
|---|
| 339 |  | 
|---|
| 340 | if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) | 
|---|
| 341 | { | 
|---|
| 342 | if(pswp->fl & SWP_ACTIVATE) | 
|---|
| 343 | { | 
|---|
| 344 | if(!(WinQueryWindowUShort(hwnd,QWS_FLAGS) & FF_ACTIVE)) { | 
|---|
| 345 | WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd); | 
|---|
| 346 | } | 
|---|
| 347 | } | 
|---|
| 348 | goto RunDefWndProc; | 
|---|
| 349 | } | 
|---|
| 350 |  | 
|---|
| 351 | if(pswp->fl & (SWP_MOVE | SWP_SIZE)) { | 
|---|
| 352 | if(win32wnd->isChild()) { | 
|---|
| 353 | if(win32wnd->getParent()) { | 
|---|
| 354 | hParent = win32wnd->getParent()->getOS2WindowHandle(); | 
|---|
| 355 | } | 
|---|
| 356 | else    goto PosChangedEnd; //parent has just been destroyed | 
|---|
| 357 | } | 
|---|
| 358 | } | 
|---|
| 359 |  | 
|---|
| 360 |  | 
|---|
| 361 | if(win32wnd->getParent()) { | 
|---|
| 362 | OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getWindowHeight(), | 
|---|
| 363 | win32wnd->getParent()->getClientRectPtr()->left, | 
|---|
| 364 | win32wnd->getParent()->getClientRectPtr()->top, | 
|---|
| 365 | hwnd); | 
|---|
| 366 | } | 
|---|
| 367 | else  OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd); | 
|---|
| 368 |  | 
|---|
| 369 | wp.hwnd = win32wnd->getWindowHandle(); | 
|---|
| 370 | if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM)) | 
|---|
| 371 | { | 
|---|
| 372 | Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind); | 
|---|
| 373 | if(wndAfter) { | 
|---|
| 374 | wp.hwndInsertAfter = wndAfter->getWindowHandle(); | 
|---|
| 375 | } | 
|---|
| 376 | else wp.hwndInsertAfter = HWND_TOP_W; | 
|---|
| 377 | } | 
|---|
| 378 |  | 
|---|
| 379 | if((pswp->fl & (SWP_MOVE | SWP_SIZE)) && !(win32wnd->getStyle() & WS_MINIMIZE_W)) | 
|---|
| 380 | { | 
|---|
| 381 | //CB: todo: use result for WM_CALCVALIDRECTS | 
|---|
| 382 | //Get old client rectangle (for invalidation of frame window parts later on) | 
|---|
| 383 | mapWin32ToOS2Rect(win32wnd->getWindowHeight(), win32wnd->getClientRectPtr(), (PRECTLOS2)&rect); | 
|---|
| 384 |  | 
|---|
| 385 | //Note: Also updates the new window rectangle | 
|---|
| 386 | win32wnd->MsgFormatFrame(&wp); | 
|---|
| 387 |  | 
|---|
| 388 | if(win32wnd->CanReceiveSizeMsgs()) | 
|---|
| 389 | win32wnd->MsgPosChanged((LPARAM)&wp); | 
|---|
| 390 |  | 
|---|
| 391 | if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy))) | 
|---|
| 392 | { | 
|---|
| 393 | //redraw the frame (to prevent unnecessary client updates) | 
|---|
| 394 | BOOL redrawAll = FALSE; | 
|---|
| 395 |  | 
|---|
| 396 | if (win32wnd->getWindowClass()) | 
|---|
| 397 | { | 
|---|
| 398 | DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W); | 
|---|
| 399 |  | 
|---|
| 400 | if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx)) | 
|---|
| 401 | redrawAll = TRUE; | 
|---|
| 402 | else if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy)) | 
|---|
| 403 | redrawAll = TRUE; | 
|---|
| 404 | } else redrawAll = TRUE; | 
|---|
| 405 |  | 
|---|
| 406 | if (redrawAll) | 
|---|
| 407 | { | 
|---|
| 408 | //CB: redraw all children for now | 
|---|
| 409 | //    -> problems with update region if we don't do it | 
|---|
| 410 | //       todo: rewrite whole handling | 
|---|
| 411 | WinInvalidateRect(hwnd,NULL,TRUE); | 
|---|
| 412 | } | 
|---|
| 413 | else | 
|---|
| 414 | { | 
|---|
| 415 | HPS hps = WinGetPS(hwnd); | 
|---|
| 416 | RECTL frame,client,arcl[4]; | 
|---|
| 417 |  | 
|---|
| 418 | WinQueryWindowRect(hwnd,&frame); | 
|---|
| 419 | //top | 
|---|
| 420 | arcl[0].xLeft = 0; | 
|---|
| 421 | arcl[0].xRight = frame.xRight; | 
|---|
| 422 | arcl[0].yBottom = rect.yTop; | 
|---|
| 423 | arcl[0].yTop = frame.yTop; | 
|---|
| 424 | //right | 
|---|
| 425 | arcl[1].xLeft = rect.xRight; | 
|---|
| 426 | arcl[1].xRight = frame.xRight; | 
|---|
| 427 | arcl[1].yBottom = 0; | 
|---|
| 428 | arcl[1].yTop = frame.yTop; | 
|---|
| 429 | //left | 
|---|
| 430 | arcl[2].xLeft = 0; | 
|---|
| 431 | arcl[2].xRight = rect.xLeft; | 
|---|
| 432 | arcl[2].yBottom = 0; | 
|---|
| 433 | arcl[2].yTop = frame.yTop; | 
|---|
| 434 | //bottom | 
|---|
| 435 | arcl[3].xLeft = 0; | 
|---|
| 436 | arcl[3].xRight = frame.xRight; | 
|---|
| 437 | arcl[3].yBottom = 0; | 
|---|
| 438 | arcl[3].yTop = rect.yBottom; | 
|---|
| 439 |  | 
|---|
| 440 | HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl); | 
|---|
| 441 |  | 
|---|
| 442 | WinInvalidateRegion(hwnd,hrgn,FALSE); | 
|---|
| 443 | GpiDestroyRegion(hps,hrgn); | 
|---|
| 444 | WinReleasePS(hps); | 
|---|
| 445 | } | 
|---|
| 446 | } | 
|---|
| 447 | } | 
|---|
| 448 | else | 
|---|
| 449 | { | 
|---|
| 450 | if(win32wnd->CanReceiveSizeMsgs()) | 
|---|
| 451 | win32wnd->MsgPosChanged((LPARAM)&wp); | 
|---|
| 452 | } | 
|---|
| 453 |  | 
|---|
| 454 | if(pswp->fl & SWP_ACTIVATE) | 
|---|
| 455 | { | 
|---|
| 456 | if(!(WinQueryWindowUShort(hwnd,QWS_FLAGS) & FF_ACTIVE)) { | 
|---|
| 457 | WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd); | 
|---|
| 458 | } | 
|---|
| 459 | } | 
|---|
| 460 |  | 
|---|
| 461 | PosChangedEnd: | 
|---|
| 462 | RestoreOS2TIB(); | 
|---|
| 463 | return (MRESULT)FALSE; | 
|---|
| 464 | } | 
|---|
| 465 |  | 
|---|
| 466 | case WM_ACTIVATE: | 
|---|
| 467 | { | 
|---|
| 468 | USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS); | 
|---|
| 469 |  | 
|---|
| 470 | dprintf(("OS2: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2)); | 
|---|
| 471 |  | 
|---|
| 472 | WinSetWindowUShort(hwnd,QWS_FLAGS, SHORT1FROMMP(mp1) ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE)); | 
|---|
| 473 | if(win32wnd->IsWindowCreated()) | 
|---|
| 474 | { | 
|---|
| 475 | win32wnd->MsgActivate((LOWORD(pWinMsg->wParam) == WA_ACTIVE_W) ? 1 : 0, HIWORD(pWinMsg->wParam), pWinMsg->lParam, (HWND)mp2); | 
|---|
| 476 |  | 
|---|
| 477 | //CB: show owner behind the dialog | 
|---|
| 478 | if(win32wnd->IsModalDialog()) | 
|---|
| 479 | { | 
|---|
| 480 | Win32BaseWindow *topOwner = win32wnd->getOwner()->GetTopParent(); | 
|---|
| 481 |  | 
|---|
| 482 | if(topOwner) WinSetWindowPos(topOwner->getOS2WindowHandle(),hwnd,0,0,0,0,SWP_ZORDER); | 
|---|
| 483 | } | 
|---|
| 484 | } | 
|---|
| 485 | RestoreOS2TIB(); | 
|---|
| 486 | return 0; | 
|---|
| 487 | } | 
|---|
| 488 |  | 
|---|
| 489 | case WM_SIZE: | 
|---|
| 490 | { | 
|---|
| 491 | dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp2))); | 
|---|
| 492 | goto RunDefWndProc; | 
|---|
| 493 | } | 
|---|
| 494 |  | 
|---|
| 495 | case WM_MINMAXFRAME: | 
|---|
| 496 | { | 
|---|
| 497 | PSWP swp = (PSWP)mp1; | 
|---|
| 498 |  | 
|---|
| 499 | if (!win32wnd->IsWindowCreated()) goto RunDefWndProc; | 
|---|
| 500 |  | 
|---|
| 501 | dprintf(("OS2: WM_MINMAXFRAME %x",hwnd)); | 
|---|
| 502 | if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE) | 
|---|
| 503 | { | 
|---|
| 504 | win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W); | 
|---|
| 505 |  | 
|---|
| 506 | RECT rect; | 
|---|
| 507 |  | 
|---|
| 508 | rect.left = rect.top = rect.right = rect.bottom = 0; | 
|---|
| 509 | win32wnd->AdjustMaximizedRect(&rect); | 
|---|
| 510 | swp->x += rect.left; | 
|---|
| 511 | swp->cx += rect.right-rect.left; | 
|---|
| 512 | swp->y -= rect.bottom; | 
|---|
| 513 | swp->cy += rect.bottom-rect.top; | 
|---|
| 514 | } | 
|---|
| 515 | else if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE) | 
|---|
| 516 | { | 
|---|
| 517 | win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W); | 
|---|
| 518 | } | 
|---|
| 519 | else if ((swp->fl & SWP_RESTORE) == SWP_RESTORE) | 
|---|
| 520 | { | 
|---|
| 521 | win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W)); | 
|---|
| 522 | } | 
|---|
| 523 | goto RunDefWndProc; | 
|---|
| 524 | } | 
|---|
| 525 |  | 
|---|
| 526 | case WM_CALCVALIDRECTS: | 
|---|
| 527 | #if 0 | 
|---|
| 528 | { | 
|---|
| 529 | PRECTL oldRect = (PRECTL)mp1,newRect = oldRect+1; | 
|---|
| 530 | UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP; | 
|---|
| 531 |  | 
|---|
| 532 | //CB: todo: use WM_NCCALCSIZE result | 
|---|
| 533 | if (win32wnd->getWindowClass()) | 
|---|
| 534 | { | 
|---|
| 535 | DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W); | 
|---|
| 536 |  | 
|---|
| 537 | if ((dwStyle & CS_HREDRAW_W) && (newRect->xRight-newRect->xLeft != oldRect->xRight-oldRect->xLeft)) | 
|---|
| 538 | res |= CVR_REDRAW; | 
|---|
| 539 | else if ((dwStyle & CS_VREDRAW_W) && (newRect->yTop-newRect->yBottom != oldRect->yTop-oldRect->yBottom)) | 
|---|
| 540 | res |= CVR_REDRAW; | 
|---|
| 541 | } else res |= CVR_REDRAW; | 
|---|
| 542 |  | 
|---|
| 543 | RestoreOS2TIB(); | 
|---|
| 544 | return (MRESULT)res; | 
|---|
| 545 | } | 
|---|
| 546 | #else | 
|---|
| 547 | dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle())); | 
|---|
| 548 | RestoreOS2TIB(); | 
|---|
| 549 | return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP); | 
|---|
| 550 | #endif | 
|---|
| 551 |  | 
|---|
| 552 | case WM_VRNENABLED: | 
|---|
| 553 | dprintf(("OS2: WM_VRNENABLED %x", win32wnd->getWindowHandle())); | 
|---|
| 554 | if(!win32wnd->isComingToTop() && ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == WS_EX_TOPMOST_W)) | 
|---|
| 555 | { | 
|---|
| 556 | HWND hwndrelated; | 
|---|
| 557 | Win32BaseWindow *topwindow; | 
|---|
| 558 |  | 
|---|
| 559 | win32wnd->setComingToTop(TRUE); | 
|---|
| 560 |  | 
|---|
| 561 | hwndrelated = WinQueryWindow(hwnd, QW_PREV); | 
|---|
| 562 | dprintf(("WM_VRNENABLED hwndrelated = %x (hwnd=%x)", hwndrelated, hwnd)); | 
|---|
| 563 | topwindow = Win32BaseWindow::GetWindowFromOS2Handle(hwndrelated); | 
|---|
| 564 | if(topwindow == NULL || ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == 0)) { | 
|---|
| 565 | //put window at the top of z order | 
|---|
| 566 | WinSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER ); | 
|---|
| 567 | } | 
|---|
| 568 |  | 
|---|
| 569 | win32wnd->setComingToTop(FALSE); | 
|---|
| 570 | break; | 
|---|
| 571 | } | 
|---|
| 572 | goto RunDefWndProc; | 
|---|
| 573 |  | 
|---|
| 574 | case WM_SETFOCUS: | 
|---|
| 575 | { | 
|---|
| 576 | HWND hwndFocus = (HWND)mp1; | 
|---|
| 577 |  | 
|---|
| 578 | dprintf(("OS2: WM_SETFOCUS %x %x %d", win32wnd->getWindowHandle(), mp1, mp2)); | 
|---|
| 579 | if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) { | 
|---|
| 580 | //another (non-win32) application's window | 
|---|
| 581 | //set to NULL (allowed according to win32 SDK) to avoid problems | 
|---|
| 582 | hwndFocus = NULL; | 
|---|
| 583 | } | 
|---|
| 584 | if((ULONG)mp2 == TRUE) { | 
|---|
| 585 | HWND hwndFocusWin32 = Win32BaseWindow::OS2ToWin32Handle(hwndFocus); | 
|---|
| 586 | recreateCaret (hwndFocusWin32); | 
|---|
| 587 | win32wnd->MsgSetFocus(hwndFocusWin32); | 
|---|
| 588 | } | 
|---|
| 589 | else win32wnd->MsgKillFocus(Win32BaseWindow::OS2ToWin32Handle(hwndFocus)); | 
|---|
| 590 | break; | 
|---|
| 591 | } | 
|---|
| 592 |  | 
|---|
| 593 | //is sent to both windows gaining and loosing the focus | 
|---|
| 594 | case WM_FOCUSCHANGE: | 
|---|
| 595 | { | 
|---|
| 596 | HWND   hwndFocus = (HWND)mp1; | 
|---|
| 597 | HWND   hwndLoseFocus, hwndGainFocus; | 
|---|
| 598 | USHORT usSetFocus = SHORT1FROMMP(mp2); | 
|---|
| 599 | USHORT fsFocusChange = SHORT2FROMMP(mp2); | 
|---|
| 600 |  | 
|---|
| 601 | rc = 0; | 
|---|
| 602 | dprintf(("OS2: WM_FOCUSCHANGE (start) %x %x %x %x", win32wnd->getWindowHandle(), hwndFocus, usSetFocus, fsFocusChange)); | 
|---|
| 603 | RestoreOS2TIB(); | 
|---|
| 604 | if(usSetFocus) { | 
|---|
| 605 | hwndGainFocus = hwnd; | 
|---|
| 606 | hwndLoseFocus = hwndFocus; | 
|---|
| 607 | } | 
|---|
| 608 | else { | 
|---|
| 609 | hwndGainFocus = hwndFocus; | 
|---|
| 610 | hwndLoseFocus = hwnd; | 
|---|
| 611 | } | 
|---|
| 612 |  | 
|---|
| 613 | if(usSetFocus) | 
|---|
| 614 | { | 
|---|
| 615 | Win32BaseWindow *winfocus = Win32BaseWindow::GetWindowFromOS2Handle(hwndLoseFocus); | 
|---|
| 616 | if(!(fsFocusChange & FC_NOSETACTIVE)) | 
|---|
| 617 | { | 
|---|
| 618 | if(!winfocus || (winfocus->GetTopParent() != win32wnd->GetTopParent())) | 
|---|
| 619 | { | 
|---|
| 620 | if(winfocus) | 
|---|
| 621 | WinSendMsg(winfocus->GetTopParent()->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus); | 
|---|
| 622 | else | 
|---|
| 623 | WinSendMsg(hwndLoseFocus, WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus); | 
|---|
| 624 | } | 
|---|
| 625 | } | 
|---|
| 626 | //SvL: Check if window is still valid | 
|---|
| 627 | win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd); | 
|---|
| 628 | if(win32wnd == NULL) | 
|---|
| 629 | return (MRESULT)rc; | 
|---|
| 630 |  | 
|---|
| 631 | if(!(fsFocusChange & FC_NOSETACTIVE)) | 
|---|
| 632 | { | 
|---|
| 633 | Win32BaseWindow *topparent = win32wnd->GetTopParent(); | 
|---|
| 634 | if(!winfocus || (winfocus->GetTopParent() != topparent)) | 
|---|
| 635 | { | 
|---|
| 636 | if(!(fsFocusChange & FC_NOBRINGTOTOP)) | 
|---|
| 637 | { | 
|---|
| 638 | if(topparent) { | 
|---|
| 639 | //put window at the top of z order | 
|---|
| 640 | WinSetWindowPos(topparent->getOS2WindowHandle(), HWND_TOP, 0, 0, 0, 0, SWP_ZORDER); | 
|---|
| 641 | } | 
|---|
| 642 | } | 
|---|
| 643 |  | 
|---|
| 644 | // PH 2000/09/01 Netscape 4.7 | 
|---|
| 645 | // check if topparent is valid | 
|---|
| 646 | if (topparent) | 
|---|
| 647 | WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus); | 
|---|
| 648 | } | 
|---|
| 649 | } | 
|---|
| 650 | //SvL: Check if window is still valid | 
|---|
| 651 | win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd); | 
|---|
| 652 | if(win32wnd == NULL) | 
|---|
| 653 | return (MRESULT)rc; | 
|---|
| 654 |  | 
|---|
| 655 | //TODO: Don't send WM_SETSELECTION to child window if frame already has selection | 
|---|
| 656 | if(!(fsFocusChange & FC_NOSETSELECTION)) { | 
|---|
| 657 | WinSendMsg(hwndGainFocus, WM_SETSELECTION, (MPARAM)1, (MPARAM)0); | 
|---|
| 658 | } | 
|---|
| 659 |  | 
|---|
| 660 | if(!(fsFocusChange & FC_NOSETFOCUS)) { | 
|---|
| 661 | WinSendMsg(hwndGainFocus, WM_SETFOCUS, (MPARAM)hwndLoseFocus, (MPARAM)1); | 
|---|
| 662 | } | 
|---|
| 663 | } | 
|---|
| 664 | else /* no usSetFocus */ | 
|---|
| 665 | { | 
|---|
| 666 | if(!(fsFocusChange & FC_NOLOSEFOCUS)) { | 
|---|
| 667 | WinSendMsg(hwndLoseFocus, WM_SETFOCUS, (MPARAM)hwndGainFocus, (MPARAM)0); | 
|---|
| 668 | } | 
|---|
| 669 | //TODO: Don't send WM_SETSELECTION to child window if frame already has selection | 
|---|
| 670 | if(!(fsFocusChange & FC_NOLOSESELECTION)) { | 
|---|
| 671 | WinSendMsg(hwndLoseFocus, WM_SETSELECTION, (MPARAM)0, (MPARAM)0); | 
|---|
| 672 | } | 
|---|
| 673 | //SvL: Check if window is still valid | 
|---|
| 674 | win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd); | 
|---|
| 675 | if(win32wnd == NULL) { | 
|---|
| 676 | return (MRESULT)rc; | 
|---|
| 677 | } | 
|---|
| 678 |  | 
|---|
| 679 | Win32BaseWindow *winfocus = Win32BaseWindow::GetWindowFromOS2Handle(hwndGainFocus); | 
|---|
| 680 | if(!(fsFocusChange & FC_NOLOSEACTIVE)) | 
|---|
| 681 | { | 
|---|
| 682 | Win32BaseWindow *topparent = win32wnd->GetTopParent(); | 
|---|
| 683 |  | 
|---|
| 684 | if(!winfocus || (winfocus->GetTopParent() != topparent)) | 
|---|
| 685 | { | 
|---|
| 686 | // PH 2000/09/01 Netscape 4.7 | 
|---|
| 687 | // check if topparent is valid | 
|---|
| 688 | if (topparent) | 
|---|
| 689 | WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)0, (MPARAM)hwndGainFocus); | 
|---|
| 690 | } | 
|---|
| 691 | } | 
|---|
| 692 | //SvL: Check if window is still valid | 
|---|
| 693 | win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd); | 
|---|
| 694 | if(win32wnd == NULL) | 
|---|
| 695 | return (MRESULT)rc; | 
|---|
| 696 |  | 
|---|
| 697 | if(!(fsFocusChange & FC_NOSETACTIVE)) | 
|---|
| 698 | { | 
|---|
| 699 | if(!winfocus || (winfocus->GetTopParent() != win32wnd->GetTopParent())) | 
|---|
| 700 | { | 
|---|
| 701 | if(winfocus) | 
|---|
| 702 | { | 
|---|
| 703 | // PH 2000/09/01 Netscape 4.7 | 
|---|
| 704 | // check if topparent is valid | 
|---|
| 705 | Win32BaseWindow *topparent = winfocus->GetTopParent(); | 
|---|
| 706 | if (topparent) | 
|---|
| 707 | WinSendMsg(topparent->getOS2WindowHandle(), WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus); | 
|---|
| 708 | } | 
|---|
| 709 | else | 
|---|
| 710 | WinSendMsg(hwndGainFocus, WM_ACTIVATE, (MPARAM)1, (MPARAM)hwndLoseFocus); | 
|---|
| 711 | } | 
|---|
| 712 | } | 
|---|
| 713 | } | 
|---|
| 714 |  | 
|---|
| 715 |  | 
|---|
| 716 | #ifdef DEBUG | 
|---|
| 717 | SetWin32TIB(); | 
|---|
| 718 | dprintf(("OS2: WM_FOCUSCHANGE (end) %x %x %x", win32wnd->getWindowHandle(), mp1, mp2)); | 
|---|
| 719 | RestoreOS2TIB(); | 
|---|
| 720 | #endif | 
|---|
| 721 | return (MRESULT)rc; | 
|---|
| 722 | } | 
|---|
| 723 |  | 
|---|
| 724 | //************************************************************************** | 
|---|
| 725 | //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen | 
|---|
| 726 | //************************************************************************** | 
|---|
| 727 | case WM_HITTEST: | 
|---|
| 728 | { | 
|---|
| 729 | if(win32wnd->getWindowHandle() != pWinMsg->hwnd) { | 
|---|
| 730 | win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd); | 
|---|
| 731 | } | 
|---|
| 732 | if(win32wnd && win32wnd->IsWindowCreated()) | 
|---|
| 733 | { | 
|---|
| 734 | MRESULT rc; | 
|---|
| 735 |  | 
|---|
| 736 | rc = (MRESULT)win32wnd->MsgHitTest(pWinMsg); | 
|---|
| 737 | RestoreOS2TIB(); | 
|---|
| 738 | return rc; | 
|---|
| 739 | } | 
|---|
| 740 | return (MRESULT)HT_NORMAL; | 
|---|
| 741 | } | 
|---|
| 742 |  | 
|---|
| 743 | case WM_BUTTON1DOWN: | 
|---|
| 744 | case WM_BUTTON1UP: | 
|---|
| 745 | case WM_BUTTON1DBLCLK: | 
|---|
| 746 | case WM_BUTTON2DOWN: | 
|---|
| 747 | case WM_BUTTON2UP: | 
|---|
| 748 | case WM_BUTTON2DBLCLK: | 
|---|
| 749 | case WM_BUTTON3DOWN: | 
|---|
| 750 | case WM_BUTTON3UP: | 
|---|
| 751 | case WM_BUTTON3DBLCLK: | 
|---|
| 752 | if(win32wnd->getWindowHandle() != pWinMsg->hwnd) { | 
|---|
| 753 | win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd); | 
|---|
| 754 | } | 
|---|
| 755 | if(win32wnd) | 
|---|
| 756 | win32wnd->MsgButton(pWinMsg); | 
|---|
| 757 | rc = TRUE; | 
|---|
| 758 | break; | 
|---|
| 759 |  | 
|---|
| 760 | case WM_BUTTON2MOTIONSTART: | 
|---|
| 761 | case WM_BUTTON2MOTIONEND: | 
|---|
| 762 | case WM_BUTTON2CLICK: | 
|---|
| 763 | case WM_BUTTON1MOTIONSTART: | 
|---|
| 764 | case WM_BUTTON1MOTIONEND: | 
|---|
| 765 | case WM_BUTTON1CLICK: | 
|---|
| 766 | case WM_BUTTON3MOTIONSTART: | 
|---|
| 767 | case WM_BUTTON3MOTIONEND: | 
|---|
| 768 | case WM_BUTTON3CLICK: | 
|---|
| 769 | rc = TRUE; | 
|---|
| 770 | break; | 
|---|
| 771 |  | 
|---|
| 772 | case WM_MOUSEMOVE: | 
|---|
| 773 | { | 
|---|
| 774 | if(win32wnd->getWindowHandle() != pWinMsg->hwnd) { | 
|---|
| 775 | win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd); | 
|---|
| 776 | } | 
|---|
| 777 | if(win32wnd) | 
|---|
| 778 | win32wnd->MsgMouseMove(pWinMsg); | 
|---|
| 779 | break; | 
|---|
| 780 | } | 
|---|
| 781 |  | 
|---|
| 782 | case WM_CONTROL: | 
|---|
| 783 | goto RunDefWndProc; | 
|---|
| 784 |  | 
|---|
| 785 | case WM_COMMAND: | 
|---|
| 786 | dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2)); | 
|---|
| 787 | win32wnd->DispatchMsgA(pWinMsg); | 
|---|
| 788 | break; | 
|---|
| 789 |  | 
|---|
| 790 | case WM_SYSCOMMAND: | 
|---|
| 791 | win32wnd->DispatchMsgA(pWinMsg); | 
|---|
| 792 | break; | 
|---|
| 793 |  | 
|---|
| 794 | case WM_CHAR: | 
|---|
| 795 | win32wnd->MsgChar(pWinMsg); | 
|---|
| 796 | break; | 
|---|
| 797 |  | 
|---|
| 798 | case WM_TIMER: | 
|---|
| 799 | win32wnd->DispatchMsgA(pWinMsg); | 
|---|
| 800 | goto RunDefWndProc; | 
|---|
| 801 |  | 
|---|
| 802 | case WM_SETWINDOWPARAMS: | 
|---|
| 803 | { | 
|---|
| 804 | WNDPARAMS *wndParams = (WNDPARAMS *)mp1; | 
|---|
| 805 |  | 
|---|
| 806 | dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd)); | 
|---|
| 807 | if(wndParams->fsStatus & WPM_TEXT) { | 
|---|
| 808 | win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText); | 
|---|
| 809 | } | 
|---|
| 810 | goto RunDefWndProc; | 
|---|
| 811 | } | 
|---|
| 812 |  | 
|---|
| 813 | case WM_QUERYWINDOWPARAMS: | 
|---|
| 814 | { | 
|---|
| 815 | PWNDPARAMS wndpars = (PWNDPARAMS)mp1; | 
|---|
| 816 | ULONG textlen; | 
|---|
| 817 | PSZ   wintext; | 
|---|
| 818 |  | 
|---|
| 819 | if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT)) | 
|---|
| 820 | { | 
|---|
| 821 | if(wndpars->fsStatus & WPM_TEXT) | 
|---|
| 822 | win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText); | 
|---|
| 823 | if(wndpars->fsStatus & WPM_CCHTEXT) | 
|---|
| 824 | wndpars->cchText = win32wnd->MsgGetTextLength(); | 
|---|
| 825 |  | 
|---|
| 826 | wndpars->fsStatus = 0; | 
|---|
| 827 | wndpars->cbCtlData = 0; | 
|---|
| 828 | wndpars->cbPresParams = 0; | 
|---|
| 829 | RestoreOS2TIB(); | 
|---|
| 830 | return (MRESULT)TRUE; | 
|---|
| 831 | } | 
|---|
| 832 | goto RunDefWndProc; | 
|---|
| 833 | } | 
|---|
| 834 |  | 
|---|
| 835 | case WM_PAINT: | 
|---|
| 836 | { | 
|---|
| 837 | RECTL rectl; | 
|---|
| 838 | BOOL  rc; | 
|---|
| 839 |  | 
|---|
| 840 | rc = WinQueryUpdateRect(hwnd, &rectl); | 
|---|
| 841 | dprintf(("OS2: WM_PAINT %x (%d,%d) (%d,%d) rc=%d", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop, rc)); | 
|---|
| 842 |  | 
|---|
| 843 | if(rc && win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight && | 
|---|
| 844 | rectl.yBottom != rectl.yTop)) | 
|---|
| 845 | { | 
|---|
| 846 | PRECT pClient = win32wnd->getClientRectPtr(); | 
|---|
| 847 | PRECT pWindow = win32wnd->getWindowRect(); | 
|---|
| 848 |  | 
|---|
| 849 | if(!(pClient->left == 0 && pClient->top == 0 && | 
|---|
| 850 | win32wnd->getClientHeight() == win32wnd->getWindowHeight() && | 
|---|
| 851 | win32wnd->getClientWidth()  == win32wnd->getWindowWidth())) | 
|---|
| 852 | { | 
|---|
| 853 | win32wnd->MsgNCPaint(); | 
|---|
| 854 | } | 
|---|
| 855 | win32wnd->DispatchMsgA(pWinMsg); | 
|---|
| 856 | } | 
|---|
| 857 | else    goto RunDefWndProc; | 
|---|
| 858 |  | 
|---|
| 859 | //SvL: Not calling the default window procedure causes all sorts of | 
|---|
| 860 | //     strange problems (redraw & hanging app) | 
|---|
| 861 | //     -> check what WinBeginPaint does what we're forgetting in BeginPaint | 
|---|
| 862 | //      WinQueryUpdateRect(hwnd, &rectl); | 
|---|
| 863 | //        if(rectl.xLeft == 0 && rectl.yTop == 0 && rectl.xRight == 0 && rectl.yBottom == 0) { | 
|---|
| 864 | //              RestoreOS2TIB(); | 
|---|
| 865 | //              return (MRESULT)FALSE; | 
|---|
| 866 | //      } | 
|---|
| 867 | //      dprintf(("Update rectangle (%d,%d)(%d,%d) not empty, msg %x", rectl.xLeft, rectl.yTop, rectl.xRight, rectl.yBottom, pWinMsg->message)); | 
|---|
| 868 | //      goto RunDefWndProc; | 
|---|
| 869 | break; | 
|---|
| 870 | } | 
|---|
| 871 |  | 
|---|
| 872 | case WM_ERASEBACKGROUND: | 
|---|
| 873 | { | 
|---|
| 874 | dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle())); | 
|---|
| 875 | RestoreOS2TIB(); | 
|---|
| 876 | return (MRESULT)FALSE; | 
|---|
| 877 | } | 
|---|
| 878 |  | 
|---|
| 879 | #if 0 | 
|---|
| 880 | case WM_CONTEXTMENU: | 
|---|
| 881 | { | 
|---|
| 882 | win32wnd->DispatchMsgA(pWinMsg); | 
|---|
| 883 |  | 
|---|
| 884 | RestoreOS2TIB(); | 
|---|
| 885 | return (MRESULT)TRUE; | 
|---|
| 886 | } | 
|---|
| 887 | #endif | 
|---|
| 888 |  | 
|---|
| 889 | case WM_QUERYTRACKINFO: | 
|---|
| 890 | { | 
|---|
| 891 | PTRACKINFO trackInfo = (PTRACKINFO)mp2; | 
|---|
| 892 |  | 
|---|
| 893 | dprintf(("OS2: WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle())); | 
|---|
| 894 | trackInfo->cxBorder = 4; | 
|---|
| 895 | trackInfo->cyBorder = 4; | 
|---|
| 896 | win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize); | 
|---|
| 897 | RestoreOS2TIB(); | 
|---|
| 898 | return (MRESULT)TRUE; | 
|---|
| 899 | } | 
|---|
| 900 |  | 
|---|
| 901 | case WM_QUERYBORDERSIZE: | 
|---|
| 902 | { | 
|---|
| 903 | PWPOINT size = (PWPOINT)mp1; | 
|---|
| 904 |  | 
|---|
| 905 | dprintf(("OS2: WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle())); | 
|---|
| 906 |  | 
|---|
| 907 | size->x = 0; | 
|---|
| 908 | size->y = 0; | 
|---|
| 909 | RestoreOS2TIB(); | 
|---|
| 910 | return (MRESULT)TRUE; | 
|---|
| 911 | } | 
|---|
| 912 |  | 
|---|
| 913 | case WM_REALIZEPALETTE: | 
|---|
| 914 | { | 
|---|
| 915 | dprintf(("OS2: WM_REALIZEPALETTE")); | 
|---|
| 916 | goto RunDefWndProc; | 
|---|
| 917 | } | 
|---|
| 918 |  | 
|---|
| 919 | case WM_OWNERPOSCHANGE: | 
|---|
| 920 | { | 
|---|
| 921 | dprintf(("OS2: WM_OWNERPOSCHANGE")); | 
|---|
| 922 | goto RunDefWndProc; | 
|---|
| 923 | } | 
|---|
| 924 |  | 
|---|
| 925 | case WM_FORMATFRAME: | 
|---|
| 926 | dprintf(("OS2: WM_FORMATFRAME %x", win32wnd->getWindowHandle())); | 
|---|
| 927 | //        goto RunDefWndProc; | 
|---|
| 928 | break; | 
|---|
| 929 |  | 
|---|
| 930 | case WM_ADJUSTFRAMEPOS: | 
|---|
| 931 | { | 
|---|
| 932 | PSWP pswp   = (PSWP)mp1; | 
|---|
| 933 |  | 
|---|
| 934 | dprintf(("OS2: WM_ADJUSTFRAMEPOS %x %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy)); | 
|---|
| 935 | break; | 
|---|
| 936 | } | 
|---|
| 937 |  | 
|---|
| 938 | case WM_QUERYFRAMEINFO: | 
|---|
| 939 | dprintf(("OS2: WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle())); | 
|---|
| 940 | return (MRESULT)(FI_FRAME|FI_ACTIVATEOK); | 
|---|
| 941 |  | 
|---|
| 942 | case WM_QUERYFOCUSCHAIN: | 
|---|
| 943 | { | 
|---|
| 944 | USHORT fsCmd = SHORT1FROMMP(mp1); | 
|---|
| 945 |  | 
|---|
| 946 | dprintf(("OS2: WM_QUERYFOCUSCHAIN %x %x %x", win32wnd->getWindowHandle(), mp1, mp2)); | 
|---|
| 947 | #if 1 | 
|---|
| 948 | goto RunDefWndProc; | 
|---|
| 949 | #else | 
|---|
| 950 | switch(fsCmd) { | 
|---|
| 951 | case QFC_NEXTINCHAIN: | 
|---|
| 952 | break; | 
|---|
| 953 | case QFC_ACTIVE: | 
|---|
| 954 | case QFC_FRAME: | 
|---|
| 955 | if(win32wnd->GetTopParent()) { | 
|---|
| 956 | dprintf(("Frame = %x", win32wnd->GetTopParent()->getOS2WindowHandle())); | 
|---|
| 957 | return (MRESULT)win32wnd->GetTopParent()->getOS2WindowHandle(); | 
|---|
| 958 | } | 
|---|
| 959 | break; | 
|---|
| 960 | case QFC_SELECTACTIVE: | 
|---|
| 961 | break; | 
|---|
| 962 | case QFC_PARTOFCHAIN: | 
|---|
| 963 | return (MRESULT)TRUE; | 
|---|
| 964 | } | 
|---|
| 965 | break; | 
|---|
| 966 | #endif | 
|---|
| 967 | } | 
|---|
| 968 |  | 
|---|
| 969 | case WM_INITMENU: | 
|---|
| 970 | case WM_MENUSELECT: | 
|---|
| 971 | case WM_MENUEND: | 
|---|
| 972 | case WM_NEXTMENU: | 
|---|
| 973 | case WM_SYSCOLORCHANGE: | 
|---|
| 974 | case WM_SYSVALUECHANGED: | 
|---|
| 975 | case WM_SETSELECTION: | 
|---|
| 976 | case WM_PPAINT: | 
|---|
| 977 | case WM_PSETFOCUS: | 
|---|
| 978 | case WM_PSYSCOLORCHANGE: | 
|---|
| 979 | case WM_PSIZE: | 
|---|
| 980 | case WM_PACTIVATE: | 
|---|
| 981 | case WM_PCONTROL: | 
|---|
| 982 | case WM_HELP: | 
|---|
| 983 | case WM_APPTERMINATENOTIFY: | 
|---|
| 984 | case WM_PRESPARAMCHANGED: | 
|---|
| 985 | case WM_DRAWITEM: | 
|---|
| 986 | case WM_MEASUREITEM: | 
|---|
| 987 | case WM_CONTROLPOINTER: | 
|---|
| 988 | case WM_QUERYDLGCODE: | 
|---|
| 989 | case WM_SUBSTITUTESTRING: | 
|---|
| 990 | case WM_MATCHMNEMONIC: | 
|---|
| 991 | case WM_SAVEAPPLICATION: | 
|---|
| 992 | case WM_SEMANTICEVENT: | 
|---|
| 993 | default: | 
|---|
| 994 | //        dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd)); | 
|---|
| 995 | RestoreOS2TIB(); | 
|---|
| 996 | return WinDefWindowProc( hwnd, msg, mp1, mp2 ); | 
|---|
| 997 | } | 
|---|
| 998 | RestoreOS2TIB(); | 
|---|
| 999 | return (MRESULT)rc; | 
|---|
| 1000 |  | 
|---|
| 1001 | RunDefWndProc: | 
|---|
| 1002 | //  dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd)); | 
|---|
| 1003 | RestoreOS2TIB(); | 
|---|
| 1004 | return WinDefWindowProc( hwnd, msg, mp1, mp2 ); | 
|---|
| 1005 | } /* End of Win32WindowProc */ | 
|---|
| 1006 | //****************************************************************************** | 
|---|
| 1007 | //TODO: Quickly moving a window two times doesn't force a repaint (1st time) | 
|---|
| 1008 | //****************************************************************************** | 
|---|
| 1009 | VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags) | 
|---|
| 1010 | { | 
|---|
| 1011 | TRACKINFO track; | 
|---|
| 1012 | RECTL     rcl; | 
|---|
| 1013 | PRECT     pWindowRect, pClientRect; | 
|---|
| 1014 | HWND      hwndTracking; | 
|---|
| 1015 | HPS       hpsTrack; | 
|---|
| 1016 | LONG      parentHeight, parentWidth; | 
|---|
| 1017 |  | 
|---|
| 1018 | dprintf(("FrameTrackFrame: %x %x", win32wnd->getWindowHandle(), flags)); | 
|---|
| 1019 | track.cxBorder = 4; | 
|---|
| 1020 | track.cyBorder = 4;  /* 4 pel wide lines used for rectangle */ | 
|---|
| 1021 | track.cxGrid = 1; | 
|---|
| 1022 | track.cyGrid = 1;    /* smooth tracking with mouse */ | 
|---|
| 1023 | track.cxKeyboard = 8; | 
|---|
| 1024 | track.cyKeyboard = 8; /* faster tracking using cursor keys */ | 
|---|
| 1025 |  | 
|---|
| 1026 | pWindowRect = win32wnd->getWindowRect(); | 
|---|
| 1027 | if(win32wnd->getParent()) { | 
|---|
| 1028 | parentHeight = win32wnd->getParent()->getWindowHeight(); | 
|---|
| 1029 | parentWidth  = win32wnd->getParent()->getWindowWidth(); | 
|---|
| 1030 | hwndTracking = win32wnd->getParent()->getOS2WindowHandle(); | 
|---|
| 1031 | hpsTrack     = WinGetPS(hwndTracking); | 
|---|
| 1032 | } | 
|---|
| 1033 | else { | 
|---|
| 1034 | parentHeight = OSLibQueryScreenHeight(); | 
|---|
| 1035 | parentWidth  = OSLibQueryScreenWidth(); | 
|---|
| 1036 | hwndTracking = HWND_DESKTOP; | 
|---|
| 1037 | hpsTrack     = NULL; | 
|---|
| 1038 | } | 
|---|
| 1039 |  | 
|---|
| 1040 | mapWin32ToOS2Rect(parentHeight, pWindowRect, (PRECTLOS2)&track.rclTrack); | 
|---|
| 1041 | WinQueryWindowRect(hwndTracking, &track.rclBoundary); | 
|---|
| 1042 |  | 
|---|
| 1043 | track.ptlMinTrackSize.x = 10; | 
|---|
| 1044 | track.ptlMinTrackSize.y = 10;  /* set smallest allowed size of rectangle */ | 
|---|
| 1045 | track.ptlMaxTrackSize.x = parentWidth; | 
|---|
| 1046 | track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */ | 
|---|
| 1047 |  | 
|---|
| 1048 | win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize); | 
|---|
| 1049 |  | 
|---|
| 1050 | track.fs = flags; | 
|---|
| 1051 |  | 
|---|
| 1052 | if(WinTrackRect(hwndTracking, NULL, &track) ) | 
|---|
| 1053 | { | 
|---|
| 1054 | if(hpsTrack)    WinReleasePS(hpsTrack); | 
|---|
| 1055 |  | 
|---|
| 1056 | /* if successful copy final position back */ | 
|---|
| 1057 | if(!WinEqualRect(0, &rcl, &track.rclTrack)) { | 
|---|
| 1058 | 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)); | 
|---|
| 1059 | if(flags == TF_MOVE) { | 
|---|
| 1060 | WinSetWindowPos(win32wnd->getOS2WindowHandle(), | 
|---|
| 1061 | 0, track.rclTrack.xLeft, track.rclTrack.yBottom, | 
|---|
| 1062 | 0, 0, SWP_MOVE); | 
|---|
| 1063 | } | 
|---|
| 1064 | else { | 
|---|
| 1065 | WinSetWindowPos(win32wnd->getOS2WindowHandle(), | 
|---|
| 1066 | 0, track.rclTrack.xLeft, track.rclTrack.yBottom, | 
|---|
| 1067 | track.rclTrack.xRight - track.rclTrack.xLeft, | 
|---|
| 1068 | track.rclTrack.yTop - track.rclTrack.yBottom, | 
|---|
| 1069 | SWP_SIZE|SWP_MOVE); | 
|---|
| 1070 | } | 
|---|
| 1071 | } | 
|---|
| 1072 | return; | 
|---|
| 1073 | } | 
|---|
| 1074 | if(hpsTrack) WinReleasePS(hpsTrack); | 
|---|
| 1075 | return; | 
|---|
| 1076 | } | 
|---|
| 1077 | //****************************************************************************** | 
|---|
| 1078 | //****************************************************************************** | 
|---|