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

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

Added new logging feature

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