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

Last change on this file since 1511 was 1511, checked in by cbratschi, 26 years ago

scrollbar updates

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