source: trunk/src/user32/pmframe.cpp@ 1405

Last change on this file since 1405 was 1405, checked in by sandervl, 26 years ago

Lots of changes/fixes

File size: 15.2 KB
Line 
1/* $Id: pmframe.cpp,v 1.9 1999-10-22 18:11:46 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#include "oslibwin.h"
25#include "caret.h"
26
27#define PMFRAMELOG
28
29VOID Draw3DRect(HPS hps,RECTL rect,LONG colorBR,LONG colorTL)
30{
31 POINTL point;
32
33 GpiSetColor(hps,colorBR);
34 point.x = rect.xLeft;
35 point.y = rect.yBottom;
36 GpiMove(hps,&point);
37 point.x = rect.xRight-1;
38 GpiLine(hps,&point);
39 point.y = rect.yTop-1;
40 GpiLine(hps,&point);
41 GpiSetColor(hps,colorTL);
42 point.x--;
43 GpiMove(hps,&point);
44 point.x = rect.xLeft;
45 GpiLine(hps,&point);
46 point.y = rect.yBottom+1;
47 GpiLine(hps,&point);
48}
49
50VOID DeflateRect(RECTL *rect)
51{
52 rect->xLeft++;
53 rect->xRight--;
54 rect->yTop--;
55 rect->yBottom++;
56}
57
58VOID DrawFrame(HPS hps,RECTL *rect,Win32BaseWindow *win32wnd)
59{
60 LONG clrWhite,clrBlack,clrDark,clrLight;
61 POINTL point;
62 DWORD dwExStyle = win32wnd->getExStyle();
63 DWORD dwStyle = win32wnd->getStyle();
64
65 clrWhite = CLR_WHITE;
66 clrBlack = CLR_BLACK;
67 clrLight = CLR_PALEGRAY;
68 clrDark = CLR_DARKGRAY;
69
70 if (dwExStyle & WS_EX_CLIENTEDGE_W)
71 {
72 Draw3DRect(hps,*rect,clrWhite,clrDark);
73 DeflateRect(rect);
74 Draw3DRect(hps,*rect,clrLight,clrBlack);
75 } else if (dwExStyle & WS_EX_DLGMODALFRAME_W)
76 {
77 Draw3DRect(hps,*rect,clrBlack,clrLight);
78 DeflateRect(rect);
79 Draw3DRect(hps,*rect,clrDark,clrWhite);
80 DeflateRect(rect);
81 Draw3DRect(hps,*rect,clrLight,clrLight);
82 } else if (dwExStyle & WS_EX_STATICEDGE_W)
83 {
84 Draw3DRect(hps,*rect,clrWhite,clrDark);
85 } else if (dwExStyle & WS_EX_WINDOWEDGE_W);
86 else if (dwStyle & WS_BORDER_W)
87 {
88 Draw3DRect(hps,*rect,clrBlack,clrBlack);
89 }
90
91 DeflateRect(rect);
92}
93
94BOOL CanDrawSizeBox(Win32BaseWindow *win32wnd)
95{
96 return (win32wnd->getStyle() & WS_SIZEBOX_W && WinQueryWindowULong(win32wnd->getOS2FrameWindowHandle(),QWL_STYLE) & FS_SIZEBORDER
97 && win32wnd->getVertScrollHandle() && WinQueryWindow(win32wnd->getVertScrollHandle(),QW_PARENT) == win32wnd->getOS2FrameWindowHandle()
98 && win32wnd->getHorzScrollHandle() && WinQueryWindow(win32wnd->getHorzScrollHandle(),QW_PARENT) == win32wnd->getOS2FrameWindowHandle());
99}
100
101VOID GetSizeBox(Win32BaseWindow *win32wnd,RECTL *rect)
102{
103 SWP swpHorz,swpVert;
104
105 WinQueryWindowPos(win32wnd->getVertScrollHandle(),&swpVert);
106 WinQueryWindowPos(win32wnd->getHorzScrollHandle(),&swpHorz);
107 rect->xLeft = swpVert.x;
108 rect->xRight = swpVert.x+swpVert.cx;
109 rect->yTop = swpHorz.y+swpHorz.cy;
110 rect->yBottom = swpHorz.y;
111}
112
113BOOL InSizeBox(Win32BaseWindow *win32wnd,POINTS *points)
114{
115 if (CanDrawSizeBox(win32wnd))
116 {
117 RECTL rect;
118 POINTL point;
119
120 point.x = points->x;
121 point.y = points->y;
122 GetSizeBox(win32wnd,&rect);
123 return (WinPtInRect(GetThreadHAB(),&rect,&point));
124 }
125
126 return FALSE;
127}
128
129VOID DrawSizeBox(HPS hps,RECTL rect)
130{
131 POINTL p1,p2;
132 LONG clrDark = CLR_DARKGRAY,clrWhite = CLR_WHITE;
133 INT x;
134
135 WinFillRect(hps,&rect,SYSCLR_DIALOGBACKGROUND);
136 p1.x = rect.xRight-2;
137 p1.y = rect.yBottom;
138 p2.x = rect.xRight-1;
139 p2.y = rect.yBottom+1;
140 for (x = 0;x < 3;x++)
141 {
142 GpiSetColor(hps,clrDark);
143 GpiMove(hps,&p1);
144 GpiLine(hps,&p2);
145 p1.x--;
146 p2.y++;
147 GpiMove(hps,&p1);
148 GpiLine(hps,&p2);
149 GpiSetColor(hps,clrWhite);
150 p1.x--;
151 p2.y++;
152 GpiMove(hps,&p1);
153 GpiLine(hps,&p2);
154 p1.x -= 2;
155 p2.y += 2;
156 }
157}
158
159//******************************************************************************
160//Win32 frame message handler
161//******************************************************************************
162MRESULT EXPENTRY Win32FrameProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
163{
164 Win32BaseWindow *win32wnd;
165 PFNWP OldFrameProc;
166 MRESULT rc;
167
168 SetWin32TIB();
169
170 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
171
172 if(win32wnd == NULL || !win32wnd->getOldFrameProc())
173 {
174 dprintf(("Invalid win32wnd pointer for frame %x!!", hwnd));
175 goto RunDefWndProc;
176 }
177
178 OldFrameProc = (PFNWP)win32wnd->getOldFrameProc();
179
180 switch(msg)
181 {
182#if 1
183 case WM_ADJUSTWINDOWPOS:
184 {
185 PSWP pswp = (PSWP)mp1;
186 SWP swpOld;
187 WINDOWPOS wp;
188 ULONG parentHeight = 0;
189 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE, hwndAfter;
190
191 dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS %x %x %x (%d,%d) (%d,%d)", hwnd, pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
192
193 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
194 goto RunDefFrameProc;
195 if(!win32wnd->CanReceiveSizeMsgs()) {
196 break;
197 }
198
199 WinQueryWindowPos(hwnd, &swpOld);
200
201 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
202 if (win32wnd->isChild()) {
203 if(win32wnd->getParent()) {
204 hParent = win32wnd->getParent()->getOS2WindowHandle();
205 }
206 else goto RunDefFrameProc;
207 }
208 }
209 hwndAfter = pswp->hwndInsertBehind;
210 hFrame = win32wnd->getOS2FrameWindowHandle();
211 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hFrame);
212
213 wp.hwnd = win32wnd->getWindowHandle();
214 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
215 {
216 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
217 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
218 }
219 if(win32wnd->MsgPosChanging((LPARAM)&wp) == 0)
220 {//app or default window handler changed wp
221 dprintf(("OS2: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
222 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
223 OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, hParent, hFrame);
224 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
225 pswp->fl |= SWP_NOADJUST;
226 pswp->hwndInsertBehind = hwndAfter;
227 pswp->hwnd = hFrame;
228
229 RestoreOS2TIB();
230 return (MRESULT)0xf;
231 }
232 break;
233 }
234
235 case WM_WINDOWPOSCHANGED:
236 {
237 PSWP pswp = (PSWP)mp1;
238 SWP swpOld = *(pswp + 1);
239 WINDOWPOS wp;
240 ULONG parentHeight = 0;
241 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE;
242 LONG yDelta = pswp->cy - swpOld.cy;
243 LONG xDelta = pswp->cx - swpOld.cx;
244
245 dprintf(("PMFRAME: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
246 RestoreOS2TIB();
247 rc = OldFrameProc(hwnd,msg,mp1,mp2);
248 SetWin32TIB();
249// dprintf(("After calling frameproc: (%x) %x %x (%d,%d) (%d,%d)", mp2, hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
250
251 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
252 break;
253
254 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
255 if (win32wnd->isChild()) {
256 if(win32wnd->getParent()) {
257 hParent = win32wnd->getParent()->getOS2WindowHandle();
258 }
259 else break; //parent has just been destroyed
260 }
261 }
262 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
263
264 //delta is difference between old and new client height
265 yDelta = swpOld.cy - win32wnd->getWindowHeight();
266
267 win32wnd->setWindowRect(wp.x, wp.y, wp.x+wp.cx, wp.y+wp.cy);
268 win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
269
270 if(!win32wnd->CanReceiveSizeMsgs())
271 break;
272
273 wp.hwnd = win32wnd->getWindowHandle();
274 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
275 {
276 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
277 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
278 }
279
280 if (yDelta != 0 || xDelta != 0)
281 {
282 HENUM henum = WinBeginEnumWindows(WinWindowFromID(pswp->hwnd, FID_CLIENT));
283 SWP swp[10];
284 int i = 0;
285 HWND hwnd;
286
287 while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE)
288 {
289#if 0
290 if (mdiClient )
291 {
292 continue;
293 }
294#endif
295 WinQueryWindowPos(hwnd, &(swp[i]));
296
297#ifdef DEBUG
298 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
299 dprintf(("ENUMERATE %x delta %d (%d,%d) (%d,%d) %x", (window) ? window->getWindowHandle() : hwnd,
300 yDelta, swp[i].x, swp[i].y, swp[i].cx, swp[i].cy, swp[i].fl));
301#endif
302
303 if(swp[i].y != 0) {
304 //child window at offset <> 0 from client area -> offset now changes
305 swp[i].y += yDelta;
306 swp[i].fl &= ~(SWP_NOREDRAW);
307 }
308 //else child window with the same start coorindates as the client area
309 //The app should resize it.
310
311 if (i == 9)
312 {
313 WinSetMultWindowPos(GetThreadHAB(), swp, 10);
314 i = 0;
315 }
316 else
317 {
318 i++;
319 }
320 }
321
322 WinEndEnumWindows(henum);
323
324 if (i)
325 WinSetMultWindowPos(GetThreadHAB(), swp, i);
326 }
327 if (yDelta != 0)
328 {
329 POINT pt;
330 if(GetCaretPos (&pt) == TRUE)
331 {
332 pt.y -= yDelta;
333 SetCaretPos (pt.x, pt.y);
334 }
335 }
336 win32wnd->MsgPosChanged((LPARAM)&wp);
337 break;
338 }
339#else
340 case WM_ADJUSTWINDOWPOS:
341 {
342 PSWP pswp = (PSWP)mp1;
343 Win32BaseWindow *wndchild;
344
345 wndchild = Win32BaseWindow::GetWindowFromOS2FrameHandle(pswp->hwnd);
346 if(wndchild && wndchild->isChild())
347 {
348 dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS %x %x %x (%d,%d) (%d,%d)", hwnd, pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
349 RestoreOS2TIB();
350 return (MRESULT)0;
351 }
352 goto RunDefFrameProc;
353 }
354
355#endif
356
357 case WM_DESTROY:
358 #ifdef PMFRAMELOG
359 dprintf(("PMFRAME: WM_DESTROY"));
360 #endif
361 WinSubclassWindow(hwnd,OldFrameProc);
362 win32wnd->setOldFrameProc(NULL);
363 goto RunDefFrameProc;
364
365 case WM_MOUSEMOVE:
366 if (InSizeBox(win32wnd,(POINTS*)&mp1))
367 {
368 WinSetPointer(HWND_DESKTOP,WinQuerySysPointer(HWND_DESKTOP,SPTR_SIZENWSE,FALSE));
369 RestoreOS2TIB();
370 return (MRESULT)TRUE;
371 } else if (win32wnd->isChild()) goto RunDefWndProc;
372 else goto RunDefFrameProc;
373
374 case WM_BUTTON1DOWN:
375 #ifdef PMFRAMELOG
376 dprintf(("PMFRAME: WM_BUTTON1DOWN"));
377 #endif
378 if (InSizeBox(win32wnd,(POINTS*)&mp1))
379 {
380 WinSendMsg(hwnd,WM_TRACKFRAME,(MPARAM)(TF_RIGHT | TF_BOTTOM),(MPARAM)0);
381 RestoreOS2TIB();
382 return (MRESULT)TRUE;
383 } else if (win32wnd->isChild()) goto RunDefWndProc;
384 else goto RunDefFrameProc;
385
386 case WM_BUTTON2DOWN:
387 case WM_BUTTON3DOWN:
388 #ifdef PMFRAMELOG
389 dprintf(("PMFRAME: WM_BUTTON2/3DOWN"));
390 #endif
391 if (win32wnd->isChild()) goto RunDefWndProc;
392 else goto RunDefFrameProc;
393
394 case WM_ACTIVATE:
395 #ifdef PMFRAMELOG
396 dprintf(("PMFRAME: WM_ACTIVATE"));
397 #endif
398 if (!win32wnd->isChild())
399 {
400 if (CanDrawSizeBox(win32wnd))
401 {
402 MRESULT res;
403 HPS hps;
404 RECTL rect;
405
406 RestoreOS2TIB();
407 res = OldFrameProc(hwnd,msg,mp1,mp2);
408 SetWin32TIB();
409
410 GetSizeBox(win32wnd,&rect);
411 hps = WinGetClipPS(hwnd,0,PSF_CLIPCHILDREN | PSF_CLIPSIBLINGS);
412 DrawSizeBox(hps,rect);
413 WinReleasePS(hps);
414
415 RestoreOS2TIB();
416 return res;
417 } else goto RunDefFrameProc;
418 } else
419 {
420 MRESULT res;
421 HPS hps;
422 RECTL rect;
423
424 RestoreOS2TIB();
425 res = OldFrameProc(hwnd,msg,mp1,mp2);
426 SetWin32TIB();
427
428 WinQueryWindowRect(hwnd,&rect);
429 rect.xRight = rect.xRight-rect.xLeft;
430 rect.yTop = rect.yTop-rect.yBottom;
431 rect.xLeft = rect.yBottom = 0;
432 hps = WinGetClipPS(hwnd,0,PSF_CLIPCHILDREN | PSF_CLIPSIBLINGS);
433 DrawFrame(hps,&rect,win32wnd);
434 WinReleasePS(hps);
435
436 RestoreOS2TIB();
437 return res;
438 }
439
440 case WM_PAINT:
441 #ifdef PMFRAMELOG
442 dprintf(("PMFRAME: WM_PAINT"));
443 #endif
444 if (!win32wnd->isChild())
445 {
446 if (CanDrawSizeBox(win32wnd))
447 {
448 MRESULT res;
449 HPS hps;
450 RECTL rect;
451
452 RestoreOS2TIB();
453 res = OldFrameProc(hwnd,msg,mp1,mp2);
454 SetWin32TIB();
455
456 GetSizeBox(win32wnd,&rect);
457 hps = WinGetClipPS(hwnd,0,PSF_CLIPCHILDREN | PSF_CLIPSIBLINGS);
458 DrawSizeBox(hps,rect);
459 WinReleasePS(hps);
460
461 RestoreOS2TIB();
462 return res;
463 } else goto RunDefFrameProc;
464 } else
465 {
466 RECTL rect;
467 HPS hps;
468
469 RestoreOS2TIB();
470 OldFrameProc(hwnd,msg,mp1,mp2);
471 SetWin32TIB();
472
473 WinQueryWindowRect(hwnd,&rect);
474 rect.xRight = rect.xRight-rect.xLeft;
475 rect.yTop = rect.yTop-rect.yBottom;
476 rect.xLeft = rect.yBottom = 0;
477 hps = WinGetClipPS(hwnd,0,PSF_CLIPCHILDREN | PSF_CLIPSIBLINGS);
478 DrawFrame(hps,&rect,win32wnd);
479 WinReleasePS(hps);
480
481 RestoreOS2TIB();
482 return (MRESULT)0;
483 }
484
485 default:
486 RestoreOS2TIB();
487 return OldFrameProc(hwnd,msg,mp1,mp2);
488 }
489
490 RestoreOS2TIB();
491 return (MRESULT)FALSE;
492
493RunDefFrameProc:
494 RestoreOS2TIB();
495 return OldFrameProc(hwnd,msg,mp1,mp2);
496
497RunDefWndProc:
498 RestoreOS2TIB();
499 return WinDefWindowProc(hwnd,msg,mp1,mp2);
500}
501
502PVOID FrameSubclassFrameWindow(Win32BaseWindow *win32wnd)
503{
504 return WinSubclassWindow(win32wnd->getOS2FrameWindowHandle(),PFNWP(Win32FrameProc));
505}
506
507VOID FrameGetBorderSize(Win32BaseWindow *win32wnd,PWPOINT pSize)
508{
509 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_QUERYBORDERSIZE,(MPARAM)pSize,(MPARAM)0);
510}
511
512VOID FrameSetBorderSize(Win32BaseWindow *win32wnd,BOOL resize)
513{
514 POINTL point;
515
516 if (!resize)
517 {
518 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_SETBORDERSIZE,(MPARAM)win32wnd->getBorderWidth(),(MPARAM)win32wnd->getBorderHeight());
519
520 return;
521 }
522
523 FrameGetBorderSize(win32wnd,&point);
524 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_SETBORDERSIZE,(MPARAM)win32wnd->getBorderWidth(),(MPARAM)win32wnd->getBorderHeight());
525 if (point.x != win32wnd->getBorderWidth() || point.y != win32wnd->getBorderHeight())
526 {
527 INT xDiff = win32wnd->getBorderWidth()-point.x;
528 INT yDiff = win32wnd->getBorderHeight()-point.y;
529 SWP swp;
530
531 WinQueryWindowPos(win32wnd->getOS2FrameWindowHandle(),&swp);
532 swp.x += xDiff;
533 swp.y += yDiff;
534 swp.cx -= 2*xDiff;
535 swp.cy -= 2*yDiff;
536 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),0,swp.x,swp.y,swp.cx,swp.cy,SWP_MOVE | SWP_SIZE);
537 }
538}
539
540UINT FrameGetDefSizeBorderSize(VOID)
541{
542 return WinQuerySysValue(HWND_DESKTOP,SV_CXSIZEBORDER);
543}
Note: See TracBrowser for help on using the repository browser.