00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #define INCL_WIN
00013 #define INCL_GPI
00014
00015 #include <os2wrap.h>
00016 #include <stdlib.h>
00017 #include <string.h>
00018 #include <win32type.h>
00019 #include <winconst.h>
00020 #include <misc.h>
00021 #include <win32wbase.h>
00022 #include "wprocess.h"
00023 #include "pmframe.h"
00024 #include "oslibutil.h"
00025 #include "oslibwin.h"
00026 #include "caret.h"
00027 #include "oslibmsg.h"
00028
00029 #define DBG_LOCALLOG DBG_pmframe
00030 #include "dbglocal.h"
00031
00032 #define PMFRAMELOG
00033
00034
00035
00036 VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
00037 {
00038 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_TRACKFRAME,(MPARAM)flags,(MPARAM)0);
00039 }
00040
00041
00042 VOID FrameUpdateChildPositions(HWND hwnd)
00043 {
00044 HENUM henum;
00045 HWND hchild;
00046 RECTL rectl;
00047
00048 henum = WinBeginEnumWindows(hwnd);
00049 while ((hchild = WinGetNextWindow(henum)) != NULLHANDLE)
00050 {
00051 Win32BaseWindow *child = Win32BaseWindow::GetWindowFromOS2FrameHandle(hchild);
00052
00053 if (child)
00054 {
00055 WinQueryWindowRect(child->getOS2FrameWindowHandle(),&rectl);
00056 mapOS2ToWin32Rect(child->getOS2FrameWindowHandle(),OSLIB_HWND_DESKTOP,(PRECTLOS2)&rectl,child->getWindowRect());
00057 FrameUpdateChildPositions(child->getOS2WindowHandle());
00058 }
00059 }
00060 WinEndEnumWindows(henum);
00061 }
00062
00063
00064
00065 MRESULT EXPENTRY Win32FrameProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
00066 {
00067 Win32BaseWindow *win32wnd;
00068 PFNWP OldFrameProc;
00069 MRESULT rc;
00070 TEB *teb;
00071 MSG *pWinMsg,winMsg;
00072
00073 SetWin32TIB();
00074
00075 teb = GetThreadTEB();
00076 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
00077
00078 if (!teb || (win32wnd == NULL) || !win32wnd->getOldFrameProc())
00079 {
00080 dprintf(("Invalid win32wnd pointer for frame %x!!", hwnd));
00081 goto RunDefWndProc;
00082 }
00083
00084 if((teb->o.odin.msgstate & 1) == 0)
00085 {
00086 QMSG qmsg;
00087
00088 qmsg.msg = msg;
00089 qmsg.hwnd = hwnd;
00090 qmsg.mp1 = mp1;
00091 qmsg.mp2 = mp2;
00092 qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
00093 WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
00094 qmsg.reserved = 0;
00095
00096 if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
00097 {
00098 memset(&winMsg, 0, sizeof(MSG));
00099 }
00100 pWinMsg = &winMsg;
00101 }
00102 else {
00103 pWinMsg = &teb->o.odin.msg;
00104 teb->o.odin.msgstate++;
00105 }
00106
00107 OldFrameProc = (PFNWP)win32wnd->getOldFrameProc();
00108
00109 switch(msg)
00110 {
00111 case WM_FORMATFRAME:
00112 break;
00113
00114 case WM_MINMAXFRAME:
00115 {
00116 PSWP swp = (PSWP)mp1;
00117
00118 if (!win32wnd->IsWindowCreated()) goto RunDefFrameProc;
00119 dprintf(("PMFRAME: WM_MINMAXFRAME %x",hwnd));
00120 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
00121 {
00122 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
00123
00124 RECT rect;
00125
00126 rect.left = rect.top = rect.right = rect.bottom = 0;
00127 win32wnd->AdjustMaximizedRect(&rect);
00128 swp->x += rect.left;
00129 swp->cx += rect.right-rect.left;
00130 swp->y -= rect.bottom;
00131 swp->cy += rect.bottom-rect.top;
00132 }
00133 else if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
00134 {
00135 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
00136 }
00137 else if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
00138 {
00139 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
00140 }
00141 goto RunDefFrameProc;
00142 }
00143
00144 case WM_QUERYTRACKINFO:
00145 {
00146 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
00147
00148 RestoreOS2TIB();
00149 OldFrameProc(hwnd,msg,mp1,mp2);
00150 SetWin32TIB();
00151 trackInfo->cxBorder = 4;
00152 trackInfo->cyBorder = 4;
00153 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
00154 RestoreOS2TIB();
00155 return (MRESULT)TRUE;
00156 }
00157
00158 case WM_QUERYBORDERSIZE:
00159 {
00160 PWPOINT size = (PWPOINT)mp1;
00161
00162 size->x = 0;
00163 size->y = 0;
00164 RestoreOS2TIB();
00165 return (MRESULT)TRUE;
00166 }
00167
00168 case WM_HITTEST:
00169 {
00170 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
00171 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
00172 }
00173 if(win32wnd && win32wnd->IsWindowCreated())
00174 {
00175 MRESULT rc;
00176
00177 rc = (MRESULT)win32wnd->MsgHitTest(pWinMsg);
00178 RestoreOS2TIB();
00179 return rc;
00180 }
00181 return (MRESULT)HT_NORMAL;
00182 }
00183
00184 case WM_BUTTON1DOWN:
00185 case WM_BUTTON1UP:
00186 case WM_BUTTON1DBLCLK:
00187 case WM_BUTTON2DOWN:
00188 case WM_BUTTON2UP:
00189 case WM_BUTTON2DBLCLK:
00190 case WM_BUTTON3DOWN:
00191 case WM_BUTTON3UP:
00192 case WM_BUTTON3DBLCLK:
00193 {
00194 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
00195 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
00196 }
00197 if(win32wnd && win32wnd->IsWindowCreated())
00198 {
00199 win32wnd->MsgButton(pWinMsg);
00200 RestoreOS2TIB();
00201 }
00202 return (MRESULT)TRUE;
00203 }
00204
00205 case WM_BUTTON2MOTIONSTART:
00206 case WM_BUTTON2MOTIONEND:
00207 case WM_BUTTON2CLICK:
00208 case WM_BUTTON1MOTIONSTART:
00209 case WM_BUTTON1MOTIONEND:
00210 case WM_BUTTON1CLICK:
00211 case WM_BUTTON3MOTIONSTART:
00212 case WM_BUTTON3MOTIONEND:
00213 case WM_BUTTON3CLICK:
00214 RestoreOS2TIB();
00215 return (MRESULT)TRUE;
00216
00217 case WM_MOUSEMOVE:
00218 {
00219 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
00220 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
00221 }
00222 if(win32wnd && win32wnd->IsWindowCreated())
00223 win32wnd->MsgMouseMove(pWinMsg);
00224 RestoreOS2TIB();
00225 return (MRESULT)TRUE;
00226 }
00227
00228 case WM_PAINT:
00229 {
00230 dprintf(("PMFRAME: WM_PAINT"));
00231 if(win32wnd->getStyle() & WS_MINIMIZE_W)
00232 goto RunDefFrameProc;
00233 if(win32wnd->IsWindowCreated())
00234 win32wnd->MsgNCPaint();
00235
00236 goto RunDefWndProc;
00237 }
00238
00239 case WM_SIZE:
00240 dprintf(("PMFRAME: WM_SIZE"));
00241 goto RunDefFrameProc;
00242
00243 case WM_ADJUSTWINDOWPOS:
00244 {
00245 PSWP pswp = (PSWP)mp1;
00246 SWP swpOld;
00247 WINDOWPOS wp,wpOld;
00248 HWND hParent = NULLHANDLE, hwndAfter;
00249
00250 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));
00251
00252
00253 if (win32wnd->IsModalDialogOwner())
00254 {
00255 pswp->fl |= SWP_ZORDER;
00256 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
00257 if (pswp->fl & SWP_ACTIVATE)
00258 {
00259 pswp->fl &= ~SWP_ACTIVATE;
00260 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
00261 }
00262 }
00263
00264 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
00265 goto RunDefFrameProc;
00266
00267 if(!win32wnd->CanReceiveSizeMsgs())
00268 break;
00269
00270 WinQueryWindowPos(hwnd, &swpOld);
00271 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
00272 if (win32wnd->isChild()) {
00273 if(win32wnd->getParent()) {
00274 hParent = win32wnd->getParent()->getOS2WindowHandle();
00275 }
00276 else goto RunDefFrameProc;
00277 }
00278 }
00279 hwndAfter = pswp->hwndInsertBehind;
00280 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
00281
00282 wp.hwnd = win32wnd->getWindowHandle();
00283 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
00284 {
00285 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
00286 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
00287 }
00288
00289 wpOld = wp;
00290 win32wnd->MsgPosChanging((LPARAM)&wp);
00291
00292 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
00293 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
00294 {
00295 dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
00296 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
00297
00298 OSLibMapWINDOWPOStoSWPFrame(&wp, pswp, &swpOld, hParent, hwnd);
00299 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
00300 pswp->fl |= SWP_NOADJUST;
00301 pswp->hwndInsertBehind = hwndAfter;
00302 pswp->hwnd = hwnd;
00303
00304 RestoreOS2TIB();
00305 return (MRESULT)0xf;
00306 }
00307 RestoreOS2TIB();
00308 return (MRESULT)0;
00309 }
00310
00311 case WM_WINDOWPOSCHANGED:
00312 {
00313 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
00314 SWP swpOld = *(pswp + 1);
00315 WINDOWPOS wp;
00316 HWND hParent = NULLHANDLE;
00317 RECTL rect;
00318 SWP swpClient = {0};
00319
00320 dprintf(("PMFRAME: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
00321
00322 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
00323 {
00324 goto RunDefFrameProc;
00325 }
00326
00327 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
00328 if (win32wnd->isChild()) {
00329 if(win32wnd->getParent()) {
00330 hParent = win32wnd->getParent()->getOS2WindowHandle();
00331 }
00332 else goto PosChangedEnd;
00333 }
00334 }
00335
00336 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
00337
00338 if(pswp->fl & SWP_ACTIVATE)
00339 {
00340 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
00341 }
00342
00343 if((pswp->fl & (SWP_MOVE | SWP_SIZE)) && !(win32wnd->getStyle() & WS_MINIMIZE_W))
00344 {
00345
00346 win32wnd->MsgFormatFrame(&wp);
00347
00348
00349 mapWin32ToOS2Rect(win32wnd->getOS2FrameWindowHandle(), win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
00350
00351 swpClient.hwnd = win32wnd->getOS2WindowHandle();
00352 swpClient.hwndInsertBehind = 0;
00353 swpClient.x = rect.xLeft;
00354 swpClient.y = rect.yBottom;
00355 swpClient.cx = rect.xRight-rect.xLeft;
00356 swpClient.cy = rect.yTop-rect.yBottom;
00357
00358 swpClient.fl = (pswp->fl & ~SWP_ZORDER) | SWP_MOVE | SWP_SHOW;
00359 WinSetMultWindowPos(teb->o.odin.hab, &swpClient, 1);
00360
00361
00362 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
00363 FrameUpdateChildPositions(win32wnd->getOS2WindowHandle());
00364 }
00365
00366 if(win32wnd->CanReceiveSizeMsgs())
00367 win32wnd->MsgPosChanged((LPARAM)&wp);
00368
00369 if ((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
00370 {
00371
00372 BOOL redrawAll = FALSE;
00373
00374 if (win32wnd->getWindowClass())
00375 {
00376 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
00377
00378 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
00379 redrawAll = TRUE;
00380 else if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
00381 redrawAll = TRUE;
00382 } else redrawAll = TRUE;
00383
00384 if (redrawAll)
00385 {
00386
00387
00388
00389 WinInvalidateRect(hwnd,NULL,TRUE);
00390 }
00391 else
00392 {
00393 HPS hps = WinGetPS(hwnd);
00394 RECTL frame,client,arcl[4];
00395
00396 WinQueryWindowRect(hwnd,&frame);
00397
00398 arcl[0].xLeft = 0;
00399 arcl[0].xRight = frame.xRight;
00400 arcl[0].yBottom = rect.yTop;
00401 arcl[0].yTop = frame.yTop;
00402
00403 arcl[1].xLeft = rect.xRight;
00404 arcl[1].xRight = frame.xRight;
00405 arcl[1].yBottom = 0;
00406 arcl[1].yTop = frame.yTop;
00407
00408 arcl[2].xLeft = 0;
00409 arcl[2].xRight = rect.xLeft;
00410 arcl[2].yBottom = 0;
00411 arcl[2].yTop = frame.yTop;
00412
00413 arcl[3].xLeft = 0;
00414 arcl[3].xRight = frame.xRight;
00415 arcl[3].yBottom = 0;
00416 arcl[3].yTop = rect.yBottom;
00417
00418 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
00419
00420 WinInvalidateRegion(hwnd,hrgn,FALSE);
00421 GpiDestroyRegion(hps,hrgn);
00422 WinReleasePS(hps);
00423 }
00424 }
00425 }
00426 else
00427 {
00428
00429 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
00430 FrameUpdateChildPositions(win32wnd->getOS2WindowHandle());
00431 }
00432
00433 if(win32wnd->CanReceiveSizeMsgs())
00434 win32wnd->MsgPosChanged((LPARAM)&wp);
00435 }
00436
00437 PosChangedEnd:
00438 RestoreOS2TIB();
00439 return (MRESULT)FALSE;
00440 }
00441
00442 case WM_SHOW:
00443 dprintf(("PMFRAME: WM_SHOW"));
00444 break;
00445
00446 case WM_ERASEBACKGROUND:
00447 {
00448 dprintf(("PMFRAME: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
00449 RestoreOS2TIB();
00450 return (MRESULT)FALSE;
00451 }
00452
00453 case WM_CALCVALIDRECTS:
00454 {
00455
00456 dprintf(("PMFRAME: WM_CALCVALIDRECTS"));
00457 RestoreOS2TIB();
00458 return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
00459 }
00460
00461 case WM_ACTIVATE:
00462 {
00463 HWND hwndTitle;
00464 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
00465
00466 dprintf(("PMFRAME: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2));
00467 if(win32wnd->IsWindowCreated())
00468 win32wnd->DispatchMsgA(pWinMsg);
00469
00470 if (win32wnd->IsWindowCreated())
00471 {
00472 WinSendMsg(WinWindowFromID(hwnd,FID_CLIENT),WM_ACTIVATE,mp1,mp2);
00473 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
00474
00475
00476 if (win32wnd->IsModalDialog())
00477 {
00478 Win32BaseWindow *topOwner = win32wnd->getOwner()->GetTopParent();
00479
00480 if (topOwner) WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
00481 }
00482 }
00483 else
00484 {
00485 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
00486 }
00487 RestoreOS2TIB();
00488 return 0;
00489 }
00490
00491 case WM_DESTROY:
00492 dprintf(("PMFRAME: WM_DESTROY %x",hwnd));
00493 WinSetVisibleRegionNotify(hwnd, FALSE);
00494 WinSubclassWindow(hwnd,OldFrameProc);
00495 win32wnd->setOldFrameProc(NULL);
00496 goto RunDefFrameProc;
00497
00498 case WM_VRNENABLED:
00499 if(!win32wnd->isComingToTop() && ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == WS_EX_TOPMOST_W))
00500 {
00501 HWND hwndrelated;
00502 Win32BaseWindow *topwindow;
00503
00504 win32wnd->setComingToTop(TRUE);
00505
00506 hwndrelated = WinQueryWindow(hwnd, QW_PREV);
00507 dprintf(("WM_VRNENABLED hwndrelated = %x (hwnd=%x)", hwndrelated, hwnd));
00508 topwindow = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwndrelated);
00509 if(topwindow == NULL || ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == 0)) {
00510
00511 WinSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
00512 }
00513
00514 win32wnd->setComingToTop(FALSE);
00515 break;
00516 }
00517 goto RunDefFrameProc;
00518
00519 default:
00520 RestoreOS2TIB();
00521 return OldFrameProc(hwnd,msg,mp1,mp2);
00522 }
00523
00524 RestoreOS2TIB();
00525 return (MRESULT)FALSE;
00526
00527 RunDefFrameProc:
00528 RestoreOS2TIB();
00529 return OldFrameProc(hwnd,msg,mp1,mp2);
00530
00531 RunDefWndProc:
00532 RestoreOS2TIB();
00533 return WinDefWindowProc(hwnd,msg,mp1,mp2);
00534 }
00535
00536
00537 PVOID FrameSubclassFrameWindow(Win32BaseWindow *win32wnd)
00538 {
00539 return WinSubclassWindow(win32wnd->getOS2FrameWindowHandle(),PFNWP(Win32FrameProc));
00540 }
00541
00542
00543 VOID FrameUpdateClient(Win32BaseWindow *win32wnd)
00544 {
00545 RECT rectOld, rectNew;
00546 RECTL rect;
00547 SWP swpClient = {0};
00548
00549 rectOld = *win32wnd->getClientRectPtr();
00550 win32wnd->MsgFormatFrame(NULL);
00551 rectNew = *win32wnd->getClientRectPtr();
00552 if(WinEqualRect(0, (PRECTL)&rectOld, (PRECTL)&rectNew) == 1) {
00553 WinInvalidateRect(win32wnd->getOS2FrameWindowHandle(), NULL, FALSE);
00554 return;
00555 }
00556
00557 mapWin32ToOS2Rect(win32wnd->getOS2FrameWindowHandle(), win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
00558
00559
00560 swpClient.hwnd = win32wnd->getOS2WindowHandle();
00561 swpClient.hwndInsertBehind = 0;
00562 swpClient.x = rect.xLeft;
00563 swpClient.y = rect.yBottom;
00564 swpClient.cx = rect.xRight-rect.xLeft;
00565 swpClient.cy = rect.yTop-rect.yBottom;
00566 swpClient.fl = SWP_MOVE | SWP_SIZE;
00567 WinSetMultWindowPos(GetThreadHAB(), &swpClient, 1);
00568 }
00569
00570