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

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

Client rectangle changes, GetDCEx bugfix (CS_OWNDC), scroll rectangle calculation fixes

File size: 14.9 KB
Line 
1/* $Id: pmframe.cpp,v 1.16 2000-01-13 20:11:37 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 <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 goto RunDefFrameProc;
266 }
267
268 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
269 if (win32wnd->isChild()) {
270 if(win32wnd->getParent()) {
271 hParent = win32wnd->getParent()->getOS2WindowHandle();
272 }
273 else goto PosChangedEnd; //parent has just been destroyed
274 }
275 }
276 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
277
278 if(pswp->fl & SWP_ACTIVATE)
279 {
280 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
281 }
282
283 if(pswp->fl & (SWP_MOVE | SWP_SIZE))
284 {
285 //Note: Also updates the new window rectangle
286 win32wnd->MsgFormatFrame(&wp);
287
288 //CB: todo: use result for WM_CALCVALIDRECTS
289// mapWin32ToOS2Rect(WinQueryWindow(hwnd,QW_PARENT),hwnd,win32wnd->getClientRectPtr(),(PRECTLOS2)&rect);
290 mapWin32ToOS2Rect(win32wnd->getOS2FrameWindowHandle(), win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
291
292 swpClient.hwnd = win32wnd->getOS2WindowHandle();
293 swpClient.hwndInsertBehind = 0;
294 swpClient.x = rect.xLeft;
295 swpClient.y = rect.yBottom;
296 swpClient.cx = rect.xRight-rect.xLeft;
297 swpClient.cy = rect.yTop-rect.yBottom;
298 //TODO: Get rid of SWP_SHOW; needed for winhlp32 button bar for now
299 swpClient.fl = (pswp->fl & ~SWP_ZORDER) | SWP_MOVE | SWP_SHOW;
300 WinSetMultWindowPos(thdb->hab, &swpClient, 1);
301
302 //update child positions: rectWindow is in window coordinates
303 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
304 FrameUpdateChildPositions(win32wnd->getOS2WindowHandle());
305 }
306
307 if(win32wnd->CanReceiveSizeMsgs())
308 win32wnd->MsgPosChanged((LPARAM)&wp);
309
310 if ((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
311 {
312 //redraw the frame (to prevent unnecessary client updates)
313 BOOL redrawAll = FALSE;
314
315 if (win32wnd->getWindowClass())
316 {
317 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
318
319 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
320 redrawAll = TRUE;
321 else if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
322 redrawAll = TRUE;
323 } else redrawAll = TRUE;
324
325 if (redrawAll)
326 {
327 WinInvalidateRect(hwnd,NULL,TRUE);
328 }
329 else
330 {
331 HPS hps = WinGetPS(hwnd);
332 RECTL frame,client,arcl[4];
333
334 WinQueryWindowRect(hwnd,&frame);
335 //top
336 arcl[0].xLeft = 0;
337 arcl[0].xRight = frame.xRight;
338 arcl[0].yBottom = rect.yTop;
339 arcl[0].yTop = frame.yTop;
340 //right
341 arcl[1].xLeft = rect.xRight;
342 arcl[1].xRight = frame.xRight;
343 arcl[1].yBottom = 0;
344 arcl[1].yTop = frame.yTop;
345 //left
346 arcl[2].xLeft = 0;
347 arcl[2].xRight = rect.xLeft;
348 arcl[2].yBottom = 0;
349 arcl[2].yTop = frame.yTop;
350 //bottom
351 arcl[3].xLeft = 0;
352 arcl[3].xRight = frame.xRight;
353 arcl[3].yBottom = 0;
354 arcl[3].yTop = rect.yBottom;
355
356 HRGN hrgn = GpiCreateRegion(hps,3,(PRECTL)&arcl);
357
358 WinInvalidateRegion(hwnd,hrgn,FALSE);
359 GpiDestroyRegion(hps,hrgn);
360 WinReleasePS(hps);
361 }
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 dprintf(("PMFRAME: WM_ACTIVATE %x %x", hwnd, mp2));
393 if (win32wnd->IsWindowCreated())
394 {
395 WinSendMsg(WinWindowFromID(hwnd,FID_CLIENT),WM_ACTIVATE,mp1,mp2);
396 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
397
398 //CB: show owner behind the dialog
399 if (win32wnd->IsModalDialog())
400 {
401 Win32BaseWindow *topOwner = win32wnd->getOwner()->GetTopParent();
402
403 if (topOwner) WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
404 }
405 }
406 else
407 {
408 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
409 }
410 if(win32wnd->IsWindowCreated())
411 win32wnd->DispatchMsgA(pWinMsg);
412
413 RestoreOS2TIB();
414 return 0;
415 }
416
417 case WM_DESTROY:
418 dprintf(("PMFRAME: WM_DESTROY %x",hwnd));
419 WinSubclassWindow(hwnd,OldFrameProc);
420 win32wnd->setOldFrameProc(NULL);
421 goto RunDefFrameProc;
422
423 default:
424 RestoreOS2TIB();
425 return OldFrameProc(hwnd,msg,mp1,mp2);
426 }
427
428 RestoreOS2TIB();
429 return (MRESULT)FALSE;
430
431RunDefFrameProc:
432 RestoreOS2TIB();
433 return OldFrameProc(hwnd,msg,mp1,mp2);
434
435RunDefWndProc:
436 RestoreOS2TIB();
437 return WinDefWindowProc(hwnd,msg,mp1,mp2);
438}
439//******************************************************************************
440//******************************************************************************
441PVOID FrameSubclassFrameWindow(Win32BaseWindow *win32wnd)
442{
443 return WinSubclassWindow(win32wnd->getOS2FrameWindowHandle(),PFNWP(Win32FrameProc));
444}
445//******************************************************************************
446//******************************************************************************
447VOID FrameUpdateClient(Win32BaseWindow *win32wnd)
448{
449 RECTL rect;
450 SWP swpClient = {0};
451
452 win32wnd->MsgFormatFrame(NULL);
453 //CB: todo: use result for WM_CALCVALIDRECTS
454// mapWin32ToOS2Rect(WinQueryWindow(win32wnd->getOS2FrameWindowHandle(),QW_PARENT),win32wnd->getOS2FrameWindowHandle(),win32wnd->getClientRectPtr(),(PRECTLOS2)&rect);
455 mapWin32ToOS2Rect(win32wnd->getOS2FrameWindowHandle(), win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
456
457
458 swpClient.hwnd = win32wnd->getOS2WindowHandle();
459 swpClient.hwndInsertBehind = 0;
460 swpClient.x = rect.xLeft;
461 swpClient.y = rect.yBottom;
462 swpClient.cx = rect.xRight-rect.xLeft;
463 swpClient.cy = rect.yTop-rect.yBottom;
464 swpClient.fl = SWP_MOVE | SWP_SIZE;
465 WinSetMultWindowPos(GetThreadHAB(), &swpClient, 1);
466}
467//******************************************************************************
468//******************************************************************************
Note: See TracBrowser for help on using the repository browser.