source: trunk/src/user32/new/pmframe.cpp@ 2425

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

fixed WM_CALCVALIDRECTS

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