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

Last change on this file since 3105 was 3101, checked in by sandervl, 25 years ago

replaced os2.h includes by os2wrap.h

File size: 16.0 KB
Line 
1/* $Id: pmframe.cpp,v 1.45 2000-03-13 13:10:47 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 <os2wrap.h>
16#include <stdlib.h>
17#include <string.h>
18#include <win32type.h>
19#include <winconst.h>
20#include <misc.h>
21#include <win32wbase.h>
22#include "wprocess.h"
23#include "pmframe.h"
24#include "oslibutil.h"
25#include "oslibwin.h"
26#include "caret.h"
27#include "oslibmsg.h"
28
29#define DBG_LOCALLOG DBG_pmframe
30#include "dbglocal.h"
31
32#define PMFRAMELOG
33
34//******************************************************************************
35//******************************************************************************
36VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
37{
38 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_TRACKFRAME,(MPARAM)flags,(MPARAM)0);
39}
40//******************************************************************************
41//******************************************************************************
42VOID FrameUpdateChildPositions(HWND hwnd)
43{
44 HENUM henum;
45 HWND hchild;
46 RECTL rectl;
47
48 henum = WinBeginEnumWindows(hwnd);
49 while ((hchild = WinGetNextWindow(henum)) != NULLHANDLE)
50 {
51 Win32BaseWindow *child = Win32BaseWindow::GetWindowFromOS2FrameHandle(hchild);
52
53 if (child)
54 {
55 WinQueryWindowRect(child->getOS2FrameWindowHandle(),&rectl);
56 mapOS2ToWin32Rect(child->getOS2FrameWindowHandle(),OSLIB_HWND_DESKTOP,(PRECTLOS2)&rectl,child->getWindowRect());
57 FrameUpdateChildPositions(child->getOS2WindowHandle());
58 }
59 }
60 WinEndEnumWindows(henum);
61}
62//******************************************************************************
63//Win32 frame message handler
64//******************************************************************************
65MRESULT EXPENTRY Win32FrameProc(HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
66{
67 Win32BaseWindow *win32wnd;
68 PFNWP OldFrameProc;
69 MRESULT rc;
70 THDB *thdb;
71 MSG *pWinMsg,winMsg;
72
73 SetWin32TIB();
74
75 thdb = GetThreadTHDB();
76 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
77
78 if (!thdb || (win32wnd == NULL) || !win32wnd->getOldFrameProc())
79 {
80 dprintf(("Invalid win32wnd pointer for frame %x!!", hwnd));
81 goto RunDefWndProc;
82 }
83
84 if((thdb->msgstate & 1) == 0)
85 {//message that was sent directly to our window proc handler; translate it here
86 QMSG qmsg;
87
88 qmsg.msg = msg;
89 qmsg.hwnd = hwnd;
90 qmsg.mp1 = mp1;
91 qmsg.mp2 = mp2;
92 qmsg.time = WinQueryMsgTime(thdb->hab);
93 WinQueryMsgPos(thdb->hab, &qmsg.ptl);
94 qmsg.reserved = 0;
95
96 if(OS2ToWinMsgTranslate((PVOID)thdb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
97 {//message was not translated
98 memset(&winMsg, 0, sizeof(MSG));
99 }
100 pWinMsg = &winMsg;
101 }
102 else {
103 pWinMsg = &thdb->msg;
104 thdb->msgstate++;
105 }
106
107 OldFrameProc = (PFNWP)win32wnd->getOldFrameProc();
108
109 switch(msg)
110 {
111 case WM_FORMATFRAME:
112 break;
113
114 case WM_MINMAXFRAME:
115 {
116 PSWP swp = (PSWP)mp1;
117
118 if (!win32wnd->IsWindowCreated()) goto RunDefFrameProc;
119 dprintf(("PMFRAME: WM_MINMAXFRAME %x",hwnd));
120 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
121 {
122 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
123
124 RECT rect;
125
126 rect.left = rect.top = rect.right = rect.bottom = 0;
127 win32wnd->AdjustMaximizedRect(&rect);
128 swp->x += rect.left;
129 swp->cx += rect.right-rect.left;
130 swp->y -= rect.bottom;
131 swp->cy += rect.bottom-rect.top;
132 }
133 else if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
134 {
135 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
136 }
137 else if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
138 {
139 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
140 }
141 goto RunDefFrameProc;
142 }
143
144 case WM_QUERYTRACKINFO:
145 {
146 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
147
148 RestoreOS2TIB();
149 OldFrameProc(hwnd,msg,mp1,mp2);
150 SetWin32TIB();
151 trackInfo->cxBorder = 0;
152 trackInfo->cyBorder = 0;
153 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
154 RestoreOS2TIB();
155 return (MRESULT)TRUE;
156 }
157
158 case WM_QUERYBORDERSIZE:
159 {
160 PWPOINT size = (PWPOINT)mp1;
161
162 size->x = 0;
163 size->y = 0;
164 RestoreOS2TIB();
165 return (MRESULT)TRUE;
166 }
167
168 case WM_BUTTON1DOWN:
169 case WM_BUTTON1UP:
170 case WM_BUTTON1DBLCLK:
171 case WM_BUTTON2DOWN:
172 case WM_BUTTON2UP:
173 case WM_BUTTON2DBLCLK:
174 case WM_BUTTON3DOWN:
175 case WM_BUTTON3UP:
176 case WM_BUTTON3DBLCLK:
177 {
178 if (win32wnd->IsWindowCreated())
179 {
180 win32wnd->MsgButton(pWinMsg);
181 RestoreOS2TIB();
182 }
183 return (MRESULT)TRUE;
184 }
185
186 case WM_BUTTON2MOTIONSTART:
187 case WM_BUTTON2MOTIONEND:
188 case WM_BUTTON2CLICK:
189 case WM_BUTTON1MOTIONSTART:
190 case WM_BUTTON1MOTIONEND:
191 case WM_BUTTON1CLICK:
192 case WM_BUTTON3MOTIONSTART:
193 case WM_BUTTON3MOTIONEND:
194 case WM_BUTTON3CLICK:
195 RestoreOS2TIB();
196 return (MRESULT)TRUE;
197
198 case WM_MOUSEMOVE:
199 {
200 //OS/2 Window coordinates -> Win32 Window coordinates
201 if (win32wnd->IsWindowCreated())
202 win32wnd->MsgMouseMove(pWinMsg);
203 RestoreOS2TIB();
204 return (MRESULT)TRUE;
205 }
206
207 case WM_PAINT:
208 {
209 dprintf(("PMFRAME: WM_PAINT"));
210 if (win32wnd->getStyle() & WS_MINIMIZE_W)
211 goto RunDefFrameProc;
212 if (win32wnd->IsWindowCreated())
213 win32wnd->MsgNCPaint();
214 goto RunDefWndProc;
215 }
216
217 case WM_SIZE:
218 dprintf(("PMFRAME: WM_SIZE"));
219 goto RunDefFrameProc;
220
221 case WM_ADJUSTWINDOWPOS:
222 {
223 PSWP pswp = (PSWP)mp1;
224 SWP swpOld;
225 WINDOWPOS wp,wpOld;
226 HWND hParent = NULLHANDLE, hwndAfter;
227
228 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));
229
230 //CB: show dialog in front of owner
231 if (win32wnd->IsModalDialogOwner())
232 {
233 pswp->fl |= SWP_ZORDER;
234 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
235 if (pswp->fl & SWP_ACTIVATE)
236 {
237 pswp->fl &= ~SWP_ACTIVATE;
238 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
239 }
240 }
241
242 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
243 goto RunDefFrameProc;
244
245 if(!win32wnd->CanReceiveSizeMsgs())
246 break;
247
248 WinQueryWindowPos(hwnd, &swpOld);
249 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
250 if (win32wnd->isChild()) {
251 if(win32wnd->getParent()) {
252 hParent = win32wnd->getParent()->getOS2WindowHandle();
253 }
254 else goto RunDefFrameProc;
255 }
256 }
257 hwndAfter = pswp->hwndInsertBehind;
258 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
259
260 wp.hwnd = win32wnd->getWindowHandle();
261 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
262 {
263 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
264 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
265 }
266
267 wpOld = wp;
268 win32wnd->MsgPosChanging((LPARAM)&wp);
269
270 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
271 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
272 {
273 dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
274 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
275
276 OSLibMapWINDOWPOStoSWPFrame(&wp, pswp, &swpOld, hParent, hwnd);
277 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
278 pswp->fl |= SWP_NOADJUST;
279 pswp->hwndInsertBehind = hwndAfter;
280 pswp->hwnd = hwnd;
281
282 RestoreOS2TIB();
283 return (MRESULT)0xf;
284 }
285 RestoreOS2TIB();
286 return (MRESULT)0;
287 }
288
289 case WM_WINDOWPOSCHANGED:
290 {
291 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
292 SWP swpOld = *(pswp + 1);
293 WINDOWPOS wp;
294 HWND hParent = NULLHANDLE;
295 RECTL rect;
296 SWP swpClient = {0};
297
298 dprintf(("PMFRAME: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
299
300 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
301 {
302 goto RunDefFrameProc;
303 }
304
305 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
306 if (win32wnd->isChild()) {
307 if(win32wnd->getParent()) {
308 hParent = win32wnd->getParent()->getOS2WindowHandle();
309 }
310 else goto PosChangedEnd; //parent has just been destroyed
311 }
312 }
313
314 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
315
316 if(pswp->fl & SWP_ACTIVATE)
317 {
318 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
319 }
320
321 if((pswp->fl & (SWP_MOVE | SWP_SIZE)) && !(win32wnd->getStyle() & WS_MINIMIZE_W))
322 {
323 //Note: Also updates the new window rectangle
324 win32wnd->MsgFormatFrame(&wp);
325
326 //CB: todo: use result for WM_CALCVALIDRECTS
327 mapWin32ToOS2Rect(win32wnd->getOS2FrameWindowHandle(), win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
328
329 swpClient.hwnd = win32wnd->getOS2WindowHandle();
330 swpClient.hwndInsertBehind = 0;
331 swpClient.x = rect.xLeft;
332 swpClient.y = rect.yBottom;
333 swpClient.cx = rect.xRight-rect.xLeft;
334 swpClient.cy = rect.yTop-rect.yBottom;
335 //TODO: Get rid of SWP_SHOW; needed for winhlp32 button bar for now
336 swpClient.fl = (pswp->fl & ~SWP_ZORDER) | SWP_MOVE | SWP_SHOW;
337 WinSetMultWindowPos(thdb->hab, &swpClient, 1);
338
339 //update child positions: rectWindow is in window coordinates
340 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
341 FrameUpdateChildPositions(win32wnd->getOS2WindowHandle());
342 }
343
344 if(win32wnd->CanReceiveSizeMsgs())
345 win32wnd->MsgPosChanged((LPARAM)&wp);
346
347 if ((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
348 {
349 //redraw the frame (to prevent unnecessary client updates)
350 BOOL redrawAll = FALSE;
351
352 if (win32wnd->getWindowClass())
353 {
354 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
355
356 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
357 redrawAll = TRUE;
358 else if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
359 redrawAll = TRUE;
360 } else redrawAll = TRUE;
361
362 if (redrawAll)
363 {
364 //CB: redraw all children for now
365 // -> problems with update region if we don't do it
366 // todo: rewrite whole handling
367 WinInvalidateRect(hwnd,NULL,TRUE);
368 }
369 else
370 {
371 HPS hps = WinGetPS(hwnd);
372 RECTL frame,client,arcl[4];
373
374 WinQueryWindowRect(hwnd,&frame);
375 //top
376 arcl[0].xLeft = 0;
377 arcl[0].xRight = frame.xRight;
378 arcl[0].yBottom = rect.yTop;
379 arcl[0].yTop = frame.yTop;
380 //right
381 arcl[1].xLeft = rect.xRight;
382 arcl[1].xRight = frame.xRight;
383 arcl[1].yBottom = 0;
384 arcl[1].yTop = frame.yTop;
385 //left
386 arcl[2].xLeft = 0;
387 arcl[2].xRight = rect.xLeft;
388 arcl[2].yBottom = 0;
389 arcl[2].yTop = frame.yTop;
390 //bottom
391 arcl[3].xLeft = 0;
392 arcl[3].xRight = frame.xRight;
393 arcl[3].yBottom = 0;
394 arcl[3].yTop = rect.yBottom;
395
396 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
397
398 WinInvalidateRegion(hwnd,hrgn,FALSE);
399 GpiDestroyRegion(hps,hrgn);
400 WinReleasePS(hps);
401 }
402 }
403 }
404 else
405 {
406 //update child positions: rectWindow is in window coordinates
407 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
408 FrameUpdateChildPositions(win32wnd->getOS2WindowHandle());
409 }
410
411 if(win32wnd->CanReceiveSizeMsgs())
412 win32wnd->MsgPosChanged((LPARAM)&wp);
413 }
414
415PosChangedEnd:
416 RestoreOS2TIB();
417 return (MRESULT)FALSE;
418 }
419
420 case WM_ERASEBACKGROUND:
421 break;
422
423 case WM_CALCVALIDRECTS:
424 {
425 //don't redraw here or PM redraw the whole frame (done in WM_WINDOWPOSCHANGED)
426 dprintf(("PMFRAME: WM_CALCVALIDRECTS"));
427 RestoreOS2TIB();
428 return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
429 }
430
431 case WM_ACTIVATE:
432 {
433 HWND hwndTitle;
434 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
435
436 dprintf(("PMFRAME: WM_ACTIVATE %x %x", hwnd, mp2));
437 if(win32wnd->IsWindowCreated())
438 win32wnd->DispatchMsgA(pWinMsg);
439
440 if (win32wnd->IsWindowCreated())
441 {
442 WinSendMsg(WinWindowFromID(hwnd,FID_CLIENT),WM_ACTIVATE,mp1,mp2);
443 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
444
445 //CB: show owner behind the dialog
446 if (win32wnd->IsModalDialog())
447 {
448 Win32BaseWindow *topOwner = win32wnd->getOwner()->GetTopParent();
449
450 if (topOwner) WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
451 }
452 }
453 else
454 {
455 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
456 }
457 RestoreOS2TIB();
458 return 0;
459 }
460
461 case WM_DESTROY:
462 dprintf(("PMFRAME: WM_DESTROY %x",hwnd));
463 WinSubclassWindow(hwnd,OldFrameProc);
464 win32wnd->setOldFrameProc(NULL);
465 goto RunDefFrameProc;
466
467 default:
468 RestoreOS2TIB();
469 return OldFrameProc(hwnd,msg,mp1,mp2);
470 }
471
472 RestoreOS2TIB();
473 return (MRESULT)FALSE;
474
475RunDefFrameProc:
476 RestoreOS2TIB();
477 return OldFrameProc(hwnd,msg,mp1,mp2);
478
479RunDefWndProc:
480 RestoreOS2TIB();
481 return WinDefWindowProc(hwnd,msg,mp1,mp2);
482}
483//******************************************************************************
484//******************************************************************************
485PVOID FrameSubclassFrameWindow(Win32BaseWindow *win32wnd)
486{
487 return WinSubclassWindow(win32wnd->getOS2FrameWindowHandle(),PFNWP(Win32FrameProc));
488}
489//******************************************************************************
490//******************************************************************************
491VOID FrameUpdateClient(Win32BaseWindow *win32wnd)
492{
493 RECT rectOld, rectNew;
494 RECTL rect;
495 SWP swpClient = {0};
496
497 rectOld = *win32wnd->getClientRectPtr();
498 win32wnd->MsgFormatFrame(NULL);
499 rectNew = *win32wnd->getClientRectPtr();
500 if(WinEqualRect(0, (PRECTL)&rectOld, (PRECTL)&rectNew) == 1) {
501 WinInvalidateRect(win32wnd->getOS2FrameWindowHandle(), NULL, FALSE);
502 return;
503 }
504 //CB: todo: use result for WM_CALCVALIDRECTS
505 mapWin32ToOS2Rect(win32wnd->getOS2FrameWindowHandle(), win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
506
507
508 swpClient.hwnd = win32wnd->getOS2WindowHandle();
509 swpClient.hwndInsertBehind = 0;
510 swpClient.x = rect.xLeft;
511 swpClient.y = rect.yBottom;
512 swpClient.cx = rect.xRight-rect.xLeft;
513 swpClient.cy = rect.yTop-rect.yBottom;
514 swpClient.fl = SWP_MOVE | SWP_SIZE;
515 WinSetMultWindowPos(GetThreadHAB(), &swpClient, 1);
516}
517//******************************************************************************
518//******************************************************************************
Note: See TracBrowser for help on using the repository browser.