| 1 | /* $Id: pmframe.cpp,v 1.5 1999-10-14 18:27:58 sandervl Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Win32 Frame Managment Code for OS/2
|
|---|
| 4 | *
|
|---|
| 5 | * Copyright 1999 by Christoph Bratschi (cbratschi@datacomm.ch)
|
|---|
| 6 | *
|
|---|
| 7 | *
|
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 9 | *
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 | #define INCL_WIN
|
|---|
| 13 | #define INCL_GPI
|
|---|
| 14 |
|
|---|
| 15 | #include <os2.h> /* PM header file */
|
|---|
| 16 | #include <os2wrap.h>
|
|---|
| 17 | #include <stdlib.h>
|
|---|
| 18 | #include "win32type.h"
|
|---|
| 19 | #include <misc.h>
|
|---|
| 20 | #include <win32wbase.h>
|
|---|
| 21 | #include "wprocess.h"
|
|---|
| 22 | #include "pmframe.h"
|
|---|
| 23 | #include "oslibutil.h"
|
|---|
| 24 |
|
|---|
| 25 | #define PMFRAMELOG
|
|---|
| 26 |
|
|---|
| 27 | VOID Draw3DRect(HPS hps,RECTL rect,LONG colorBR,LONG colorTL)
|
|---|
| 28 | {
|
|---|
| 29 | POINTL point;
|
|---|
| 30 |
|
|---|
| 31 | GpiSetColor(hps,colorBR);
|
|---|
| 32 | point.x = rect.xLeft;
|
|---|
| 33 | point.y = rect.yBottom;
|
|---|
| 34 | GpiMove(hps,&point);
|
|---|
| 35 | point.x = rect.xRight-1;
|
|---|
| 36 | GpiLine(hps,&point);
|
|---|
| 37 | point.y = rect.yTop-1;
|
|---|
| 38 | GpiLine(hps,&point);
|
|---|
| 39 | GpiSetColor(hps,colorTL);
|
|---|
| 40 | point.x--;
|
|---|
| 41 | GpiMove(hps,&point);
|
|---|
| 42 | point.x = rect.xLeft;
|
|---|
| 43 | GpiLine(hps,&point);
|
|---|
| 44 | point.y = rect.yBottom+1;
|
|---|
| 45 | GpiLine(hps,&point);
|
|---|
| 46 | }
|
|---|
| 47 |
|
|---|
| 48 | VOID DeflateRect(RECTL *rect)
|
|---|
| 49 | {
|
|---|
| 50 | rect->xLeft++;
|
|---|
| 51 | rect->xRight--;
|
|---|
| 52 | rect->yTop--;
|
|---|
| 53 | rect->yBottom++;
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | VOID DrawFrame(HPS hps,RECTL *rect,Win32BaseWindow *win32wnd)
|
|---|
| 57 | {
|
|---|
| 58 | LONG clrWhite,clrBlack,clrDark,clrLight;
|
|---|
| 59 | POINTL point;
|
|---|
| 60 | DWORD dwExStyle = win32wnd->getExStyle();
|
|---|
| 61 | DWORD dwStyle = win32wnd->getStyle();
|
|---|
| 62 |
|
|---|
| 63 | clrWhite = CLR_WHITE;
|
|---|
| 64 | clrBlack = CLR_BLACK;
|
|---|
| 65 | clrLight = CLR_PALEGRAY;
|
|---|
| 66 | clrDark = CLR_DARKGRAY;
|
|---|
| 67 |
|
|---|
| 68 | if (dwExStyle & WS_EX_CLIENTEDGE_W)
|
|---|
| 69 | {
|
|---|
| 70 | Draw3DRect(hps,*rect,clrWhite,clrDark);
|
|---|
| 71 | DeflateRect(rect);
|
|---|
| 72 | Draw3DRect(hps,*rect,clrLight,clrBlack);
|
|---|
| 73 | } else if (dwExStyle & WS_EX_DLGMODALFRAME_W)
|
|---|
| 74 | {
|
|---|
| 75 | Draw3DRect(hps,*rect,clrBlack,clrLight);
|
|---|
| 76 | DeflateRect(rect);
|
|---|
| 77 | Draw3DRect(hps,*rect,clrDark,clrWhite);
|
|---|
| 78 | DeflateRect(rect);
|
|---|
| 79 | Draw3DRect(hps,*rect,clrLight,clrLight);
|
|---|
| 80 | } else if (dwExStyle & WS_EX_STATICEDGE_W)
|
|---|
| 81 | {
|
|---|
| 82 | Draw3DRect(hps,*rect,clrWhite,clrDark);
|
|---|
| 83 | } else if (dwExStyle & WS_EX_WINDOWEDGE_W);
|
|---|
| 84 | else if (dwStyle & WS_BORDER_W)
|
|---|
| 85 | {
|
|---|
| 86 | Draw3DRect(hps,*rect,clrBlack,clrBlack);
|
|---|
| 87 | }
|
|---|
| 88 |
|
|---|
| 89 | DeflateRect(rect);
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | BOOL CanDrawSizeBox(Win32BaseWindow *win32wnd)
|
|---|
| 93 | {
|
|---|
| 94 | return (!win32wnd->isChild() && WinQueryWindowULong(win32wnd->getOS2FrameWindowHandle(),QWL_STYLE) & FS_SIZEBORDER
|
|---|
| 95 | && win32wnd->getVertScrollHandle() && WinQueryWindow(win32wnd->getVertScrollHandle(),QW_PARENT) == win32wnd->getOS2FrameWindowHandle()
|
|---|
| 96 | && win32wnd->getHorzScrollHandle() && WinQueryWindow(win32wnd->getHorzScrollHandle(),QW_PARENT) == win32wnd->getOS2FrameWindowHandle());
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | VOID GetSizeBox(Win32BaseWindow *win32wnd,RECTL *rect)
|
|---|
| 100 | {
|
|---|
| 101 | SWP swpHorz,swpVert;
|
|---|
| 102 |
|
|---|
| 103 | WinQueryWindowPos(win32wnd->getVertScrollHandle(),&swpVert);
|
|---|
| 104 | WinQueryWindowPos(win32wnd->getHorzScrollHandle(),&swpHorz);
|
|---|
| 105 | rect->xLeft = swpVert.x;
|
|---|
| 106 | rect->xRight = swpVert.x+swpVert.cx;
|
|---|
| 107 | rect->yTop = swpHorz.y+swpHorz.cy;
|
|---|
| 108 | rect->yBottom = swpHorz.y;
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | BOOL InSizeBox(Win32BaseWindow *win32wnd,POINTS *points)
|
|---|
| 112 | {
|
|---|
| 113 | if (CanDrawSizeBox(win32wnd))
|
|---|
| 114 | {
|
|---|
| 115 | RECTL rect;
|
|---|
| 116 | POINTL point;
|
|---|
| 117 |
|
|---|
| 118 | point.x = points->x;
|
|---|
| 119 | point.y = points->y;
|
|---|
| 120 | GetSizeBox(win32wnd,&rect);
|
|---|
| 121 | return (WinPtInRect(GetThreadHAB(),&rect,&point));
|
|---|
| 122 | }
|
|---|
| 123 |
|
|---|
| 124 | return FALSE;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | VOID DrawSizeBox(HPS hps,RECTL rect)
|
|---|
| 128 | {
|
|---|
| 129 | POINTL p1,p2;
|
|---|
| 130 | LONG clrDark = CLR_DARKGRAY,clrWhite = CLR_WHITE;
|
|---|
| 131 | INT x;
|
|---|
| 132 |
|
|---|
| 133 | WinFillRect(hps,&rect,SYSCLR_DIALOGBACKGROUND);
|
|---|
| 134 | p1.x = rect.xRight-2;
|
|---|
| 135 | p1.y = rect.yBottom;
|
|---|
| 136 | p2.x = rect.xRight-1;
|
|---|
| 137 | p2.y = rect.yBottom+1;
|
|---|
| 138 | for (x = 0;x < 3;x++)
|
|---|
| 139 | {
|
|---|
| 140 | GpiSetColor(hps,clrDark);
|
|---|
| 141 | GpiMove(hps,&p1);
|
|---|
| 142 | GpiLine(hps,&p2);
|
|---|
| 143 | p1.x--;
|
|---|
| 144 | p2.y++;
|
|---|
| 145 | GpiMove(hps,&p1);
|
|---|
| 146 | GpiLine(hps,&p2);
|
|---|
| 147 | GpiSetColor(hps,clrWhite);
|
|---|
| 148 | p1.x--;
|
|---|
| 149 | p2.y++;
|
|---|
| 150 | GpiMove(hps,&p1);
|
|---|
| 151 | GpiLine(hps,&p2);
|
|---|
| 152 | p1.x -= 2;
|
|---|
| 153 | p2.y += 2;
|
|---|
| 154 | }
|
|---|
| 155 | }
|
|---|
| 156 |
|
|---|
| 157 | //******************************************************************************
|
|---|
| 158 | //Win32 frame message handler
|
|---|
| 159 | //******************************************************************************
|
|---|
| 160 | MRESULT EXPENTRY Win32FrameProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
|
|---|
| 161 | {
|
|---|
| 162 | Win32BaseWindow *win32wnd;
|
|---|
| 163 | PFNWP OldFrameProc;
|
|---|
| 164 |
|
|---|
| 165 | SetWin32TIB();
|
|---|
| 166 |
|
|---|
| 167 | win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
|
|---|
| 168 |
|
|---|
| 169 | if(win32wnd == NULL || !win32wnd->getOldFrameProc())
|
|---|
| 170 | {
|
|---|
| 171 | dprintf(("Invalid win32wnd pointer for frame %x!!", hwnd));
|
|---|
| 172 | goto RunDefWndProc;
|
|---|
| 173 | }
|
|---|
| 174 |
|
|---|
| 175 | OldFrameProc = (PFNWP)win32wnd->getOldFrameProc();
|
|---|
| 176 |
|
|---|
| 177 | switch(msg)
|
|---|
| 178 | {
|
|---|
| 179 | case WM_ADJUSTWINDOWPOS:
|
|---|
| 180 | {
|
|---|
| 181 | PSWP pswp = (PSWP)mp1;
|
|---|
| 182 | Win32BaseWindow *wndchild;
|
|---|
| 183 |
|
|---|
| 184 | wndchild = Win32BaseWindow::GetWindowFromOS2FrameHandle(pswp->hwnd);
|
|---|
| 185 | if(wndchild && wndchild->isChild()) {
|
|---|
| 186 | dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS %x %x %x (%d,%d) (%d,%d)", hwnd, pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
|
|---|
| 187 | RestoreOS2TIB();
|
|---|
| 188 | return (MRESULT)0;
|
|---|
| 189 | }
|
|---|
| 190 | goto RunDefFrameProc;
|
|---|
| 191 | }
|
|---|
| 192 | #if 0
|
|---|
| 193 | case WM_WINDOWPOSCHANGED:
|
|---|
| 194 | {
|
|---|
| 195 | PSWP pswp = (PSWP)mp1;
|
|---|
| 196 | dprintf(("PMFRAME: WM_WINDOWPOSCHANGED %x %x %x (%d,%d) (%d,%d)", hwnd, pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
|
|---|
| 197 | goto RunDefFrameProc;
|
|---|
| 198 | }
|
|---|
| 199 |
|
|---|
| 200 | case WM_FORMATFRAME:
|
|---|
| 201 | {
|
|---|
| 202 | PSWP pswp = (PSWP)mp1;
|
|---|
| 203 | dprintf(("PMFRAME: WM_FORMATFRAME %x %x %x (%d,%d) (%d,%d)", hwnd, pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
|
|---|
| 204 | goto RunDefFrameProc;
|
|---|
| 205 | }
|
|---|
| 206 | #endif
|
|---|
| 207 |
|
|---|
| 208 | case WM_DESTROY:
|
|---|
| 209 | #ifdef PMFRAMELOG
|
|---|
| 210 | dprintf(("PMFRAME: WM_DESTROY"));
|
|---|
| 211 | #endif
|
|---|
| 212 | WinSubclassWindow(hwnd,OldFrameProc);
|
|---|
| 213 | win32wnd->setOldFrameProc(NULL);
|
|---|
| 214 | goto RunDefFrameProc;
|
|---|
| 215 |
|
|---|
| 216 | case WM_MOUSEMOVE:
|
|---|
| 217 | #ifdef PMFRAMELOG
|
|---|
| 218 | dprintf(("PMFRAME: WM_MOUSEMOVE"));
|
|---|
| 219 | #endif
|
|---|
| 220 | if (InSizeBox(win32wnd,(POINTS*)&mp1))
|
|---|
| 221 | {
|
|---|
| 222 | WinSetPointer(HWND_DESKTOP,WinQuerySysPointer(HWND_DESKTOP,SPTR_SIZENWSE,FALSE));
|
|---|
| 223 | RestoreOS2TIB();
|
|---|
| 224 | return (MRESULT)TRUE;
|
|---|
| 225 | } else if (win32wnd->isChild()) goto RunDefWndProc;
|
|---|
| 226 | else goto RunDefFrameProc;
|
|---|
| 227 |
|
|---|
| 228 | case WM_BUTTON1DOWN:
|
|---|
| 229 | #ifdef PMFRAMELOG
|
|---|
| 230 | dprintf(("PMFRAME: WM_BUTTON1DOWN"));
|
|---|
| 231 | #endif
|
|---|
| 232 | if (InSizeBox(win32wnd,(POINTS*)&mp1))
|
|---|
| 233 | {
|
|---|
| 234 | WinSendMsg(hwnd,WM_TRACKFRAME,(MPARAM)(TF_RIGHT | TF_BOTTOM),(MPARAM)0);
|
|---|
| 235 | RestoreOS2TIB();
|
|---|
| 236 | return (MRESULT)TRUE;
|
|---|
| 237 | } else if (win32wnd->isChild()) goto RunDefWndProc;
|
|---|
| 238 | else goto RunDefFrameProc;
|
|---|
| 239 |
|
|---|
| 240 | case WM_BUTTON2DOWN:
|
|---|
| 241 | case WM_BUTTON3DOWN:
|
|---|
| 242 | #ifdef PMFRAMELOG
|
|---|
| 243 | dprintf(("PMFRAME: WM_BUTTON2/3DOWN"));
|
|---|
| 244 | #endif
|
|---|
| 245 | if (win32wnd->isChild()) goto RunDefWndProc;
|
|---|
| 246 | else goto RunDefFrameProc;
|
|---|
| 247 |
|
|---|
| 248 | case WM_ACTIVATE:
|
|---|
| 249 | #ifdef PMFRAMELOG
|
|---|
| 250 | dprintf(("PMFRAME: WM_ACTIVATE"));
|
|---|
| 251 | #endif
|
|---|
| 252 | if (!win32wnd->isChild())
|
|---|
| 253 | {
|
|---|
| 254 | if (CanDrawSizeBox(win32wnd))
|
|---|
| 255 | {
|
|---|
| 256 | MRESULT res;
|
|---|
| 257 | HPS hps;
|
|---|
| 258 | RECTL rect;
|
|---|
| 259 |
|
|---|
| 260 | RestoreOS2TIB();
|
|---|
| 261 | res = OldFrameProc(hwnd,msg,mp1,mp2);
|
|---|
| 262 | SetWin32TIB();
|
|---|
| 263 |
|
|---|
| 264 | GetSizeBox(win32wnd,&rect);
|
|---|
| 265 | hps = WinGetPS(hwnd);
|
|---|
| 266 | DrawSizeBox(hps,rect);
|
|---|
| 267 | WinReleasePS(hps);
|
|---|
| 268 |
|
|---|
| 269 | RestoreOS2TIB();
|
|---|
| 270 | return res;
|
|---|
| 271 | } else goto RunDefFrameProc;
|
|---|
| 272 | } else
|
|---|
| 273 | {
|
|---|
| 274 | MRESULT res;
|
|---|
| 275 | HPS hps;
|
|---|
| 276 | RECTL rect;
|
|---|
| 277 |
|
|---|
| 278 | RestoreOS2TIB();
|
|---|
| 279 | res = OldFrameProc(hwnd,msg,mp1,mp2);
|
|---|
| 280 | SetWin32TIB();
|
|---|
| 281 |
|
|---|
| 282 | hps = WinGetClipPS(hwnd,0,PSF_CLIPCHILDREN);
|
|---|
| 283 | WinQueryWindowRect(hwnd,&rect);
|
|---|
| 284 | DrawFrame(hps,&rect,win32wnd);
|
|---|
| 285 | WinFillRect(hps,&rect,SYSCLR_DIALOGBACKGROUND);
|
|---|
| 286 | WinReleasePS(hps);
|
|---|
| 287 |
|
|---|
| 288 | RestoreOS2TIB();
|
|---|
| 289 | return res;
|
|---|
| 290 | }
|
|---|
| 291 |
|
|---|
| 292 | case WM_PAINT:
|
|---|
| 293 | #ifdef PMFRAMELOG
|
|---|
| 294 | dprintf(("PMFRAME: WM_PAINT"));
|
|---|
| 295 | #endif
|
|---|
| 296 | if (!win32wnd->isChild())
|
|---|
| 297 | {
|
|---|
| 298 | if (CanDrawSizeBox(win32wnd))
|
|---|
| 299 | {
|
|---|
| 300 | MRESULT res;
|
|---|
| 301 | HPS hps;
|
|---|
| 302 | RECTL rect;
|
|---|
| 303 |
|
|---|
| 304 | RestoreOS2TIB();
|
|---|
| 305 | res = OldFrameProc(hwnd,msg,mp1,mp2);
|
|---|
| 306 | SetWin32TIB();
|
|---|
| 307 |
|
|---|
| 308 | GetSizeBox(win32wnd,&rect);
|
|---|
| 309 | hps = WinGetPS(hwnd);
|
|---|
| 310 | DrawSizeBox(hps,rect);
|
|---|
| 311 | WinReleasePS(hps);
|
|---|
| 312 |
|
|---|
| 313 | RestoreOS2TIB();
|
|---|
| 314 | return res;
|
|---|
| 315 | } else goto RunDefFrameProc;
|
|---|
| 316 | } else
|
|---|
| 317 | {
|
|---|
| 318 | RECTL rect;
|
|---|
| 319 | HPS hps = WinBeginPaint(hwnd,0,&rect);
|
|---|
| 320 |
|
|---|
| 321 | DrawFrame(hps,&rect,win32wnd);
|
|---|
| 322 | WinFillRect(hps,&rect,SYSCLR_DIALOGBACKGROUND);
|
|---|
| 323 | WinEndPaint(hps);
|
|---|
| 324 |
|
|---|
| 325 | RestoreOS2TIB();
|
|---|
| 326 | return (MRESULT)0;
|
|---|
| 327 | }
|
|---|
| 328 |
|
|---|
| 329 | default:
|
|---|
| 330 | RestoreOS2TIB();
|
|---|
| 331 | return OldFrameProc(hwnd,msg,mp1,mp2);
|
|---|
| 332 | }
|
|---|
| 333 |
|
|---|
| 334 | RestoreOS2TIB();
|
|---|
| 335 | return (MRESULT)FALSE;
|
|---|
| 336 |
|
|---|
| 337 | RunDefFrameProc:
|
|---|
| 338 | RestoreOS2TIB();
|
|---|
| 339 | return OldFrameProc(hwnd,msg,mp1,mp2);
|
|---|
| 340 |
|
|---|
| 341 | RunDefWndProc:
|
|---|
| 342 | RestoreOS2TIB();
|
|---|
| 343 | return WinDefWindowProc(hwnd,msg,mp1,mp2);
|
|---|
| 344 | }
|
|---|
| 345 |
|
|---|
| 346 | PVOID FrameSubclassFrameWindow(Win32BaseWindow *win32wnd)
|
|---|
| 347 | {
|
|---|
| 348 | return WinSubclassWindow(win32wnd->getOS2FrameWindowHandle(),PFNWP(Win32FrameProc));
|
|---|
| 349 | }
|
|---|
| 350 |
|
|---|
| 351 | VOID FrameGetBorderSize(Win32BaseWindow *win32wnd,PWPOINT pSize)
|
|---|
| 352 | {
|
|---|
| 353 | WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_QUERYBORDERSIZE,(MPARAM)pSize,(MPARAM)0);
|
|---|
| 354 | }
|
|---|
| 355 |
|
|---|
| 356 | VOID FrameSetBorderSize(Win32BaseWindow *win32wnd,BOOL resize)
|
|---|
| 357 | {
|
|---|
| 358 | POINTL point;
|
|---|
| 359 |
|
|---|
| 360 | if (!resize)
|
|---|
| 361 | {
|
|---|
| 362 | WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_SETBORDERSIZE,(MPARAM)win32wnd->getBorderWidth(),(MPARAM)win32wnd->getBorderHeight());
|
|---|
| 363 |
|
|---|
| 364 | return;
|
|---|
| 365 | }
|
|---|
| 366 |
|
|---|
| 367 | FrameGetBorderSize(win32wnd,&point);
|
|---|
| 368 | WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_SETBORDERSIZE,(MPARAM)win32wnd->getBorderWidth(),(MPARAM)win32wnd->getBorderHeight());
|
|---|
| 369 | if (point.x != win32wnd->getBorderWidth() || point.y != win32wnd->getBorderHeight())
|
|---|
| 370 | {
|
|---|
| 371 | INT xDiff = win32wnd->getBorderWidth()-point.x;
|
|---|
| 372 | INT yDiff = win32wnd->getBorderHeight()-point.y;
|
|---|
| 373 | SWP swp;
|
|---|
| 374 |
|
|---|
| 375 | WinQueryWindowPos(win32wnd->getOS2FrameWindowHandle(),&swp);
|
|---|
| 376 | swp.x += xDiff;
|
|---|
| 377 | swp.y += yDiff;
|
|---|
| 378 | swp.cx -= 2*xDiff;
|
|---|
| 379 | swp.cy -= 2*yDiff;
|
|---|
| 380 | WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),0,swp.x,swp.y,swp.cx,swp.cy,SWP_MOVE | SWP_SIZE);
|
|---|
| 381 | }
|
|---|
| 382 | }
|
|---|
| 383 |
|
|---|
| 384 | UINT FrameGetDefSizeBorderSize(VOID)
|
|---|
| 385 | {
|
|---|
| 386 | return WinQuerySysValue(HWND_DESKTOP,SV_CXSIZEBORDER);
|
|---|
| 387 | }
|
|---|