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

Last change on this file since 3284 was 3284, checked in by cbratschi, 25 years ago

HTTRANSPARENT

File size: 16.3 KB
Line 
1/* $Id: pmframe.cpp,v 1.46 2000-03-31 14:42:47 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 <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_HITTEST:
169 {
170 if (win32wnd->IsWindowCreated())
171 {
172 MRESULT rc;
173
174 rc = (MRESULT)win32wnd->MsgHitTest(pWinMsg);
175 RestoreOS2TIB();
176 return rc;
177 }
178 return (MRESULT)HT_NORMAL;
179 }
180
181 case WM_BUTTON1DOWN:
182 case WM_BUTTON1UP:
183 case WM_BUTTON1DBLCLK:
184 case WM_BUTTON2DOWN:
185 case WM_BUTTON2UP:
186 case WM_BUTTON2DBLCLK:
187 case WM_BUTTON3DOWN:
188 case WM_BUTTON3UP:
189 case WM_BUTTON3DBLCLK:
190 {
191 if (win32wnd->IsWindowCreated())
192 {
193 win32wnd->MsgButton(pWinMsg);
194 RestoreOS2TIB();
195 }
196 return (MRESULT)TRUE;
197 }
198
199 case WM_BUTTON2MOTIONSTART:
200 case WM_BUTTON2MOTIONEND:
201 case WM_BUTTON2CLICK:
202 case WM_BUTTON1MOTIONSTART:
203 case WM_BUTTON1MOTIONEND:
204 case WM_BUTTON1CLICK:
205 case WM_BUTTON3MOTIONSTART:
206 case WM_BUTTON3MOTIONEND:
207 case WM_BUTTON3CLICK:
208 RestoreOS2TIB();
209 return (MRESULT)TRUE;
210
211 case WM_MOUSEMOVE:
212 {
213 //OS/2 Window coordinates -> Win32 Window coordinates
214 if (win32wnd->IsWindowCreated())
215 win32wnd->MsgMouseMove(pWinMsg);
216 RestoreOS2TIB();
217 return (MRESULT)TRUE;
218 }
219
220 case WM_PAINT:
221 {
222 dprintf(("PMFRAME: WM_PAINT"));
223 if (win32wnd->getStyle() & WS_MINIMIZE_W)
224 goto RunDefFrameProc;
225 if (win32wnd->IsWindowCreated())
226 win32wnd->MsgNCPaint();
227 goto RunDefWndProc;
228 }
229
230 case WM_SIZE:
231 dprintf(("PMFRAME: WM_SIZE"));
232 goto RunDefFrameProc;
233
234 case WM_ADJUSTWINDOWPOS:
235 {
236 PSWP pswp = (PSWP)mp1;
237 SWP swpOld;
238 WINDOWPOS wp,wpOld;
239 HWND hParent = NULLHANDLE, hwndAfter;
240
241 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));
242
243 //CB: show dialog in front of owner
244 if (win32wnd->IsModalDialogOwner())
245 {
246 pswp->fl |= SWP_ZORDER;
247 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
248 if (pswp->fl & SWP_ACTIVATE)
249 {
250 pswp->fl &= ~SWP_ACTIVATE;
251 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
252 }
253 }
254
255 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
256 goto RunDefFrameProc;
257
258 if(!win32wnd->CanReceiveSizeMsgs())
259 break;
260
261 WinQueryWindowPos(hwnd, &swpOld);
262 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
263 if (win32wnd->isChild()) {
264 if(win32wnd->getParent()) {
265 hParent = win32wnd->getParent()->getOS2WindowHandle();
266 }
267 else goto RunDefFrameProc;
268 }
269 }
270 hwndAfter = pswp->hwndInsertBehind;
271 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
272
273 wp.hwnd = win32wnd->getWindowHandle();
274 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
275 {
276 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
277 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
278 }
279
280 wpOld = wp;
281 win32wnd->MsgPosChanging((LPARAM)&wp);
282
283 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
284 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
285 {
286 dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
287 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
288
289 OSLibMapWINDOWPOStoSWPFrame(&wp, pswp, &swpOld, hParent, hwnd);
290 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
291 pswp->fl |= SWP_NOADJUST;
292 pswp->hwndInsertBehind = hwndAfter;
293 pswp->hwnd = hwnd;
294
295 RestoreOS2TIB();
296 return (MRESULT)0xf;
297 }
298 RestoreOS2TIB();
299 return (MRESULT)0;
300 }
301
302 case WM_WINDOWPOSCHANGED:
303 {
304 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
305 SWP swpOld = *(pswp + 1);
306 WINDOWPOS wp;
307 HWND hParent = NULLHANDLE;
308 RECTL rect;
309 SWP swpClient = {0};
310
311 dprintf(("PMFRAME: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
312
313 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
314 {
315 goto RunDefFrameProc;
316 }
317
318 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
319 if (win32wnd->isChild()) {
320 if(win32wnd->getParent()) {
321 hParent = win32wnd->getParent()->getOS2WindowHandle();
322 }
323 else goto PosChangedEnd; //parent has just been destroyed
324 }
325 }
326
327 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
328
329 if(pswp->fl & SWP_ACTIVATE)
330 {
331 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
332 }
333
334 if((pswp->fl & (SWP_MOVE | SWP_SIZE)) && !(win32wnd->getStyle() & WS_MINIMIZE_W))
335 {
336 //Note: Also updates the new window rectangle
337 win32wnd->MsgFormatFrame(&wp);
338
339 //CB: todo: use result for WM_CALCVALIDRECTS
340 mapWin32ToOS2Rect(win32wnd->getOS2FrameWindowHandle(), win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
341
342 swpClient.hwnd = win32wnd->getOS2WindowHandle();
343 swpClient.hwndInsertBehind = 0;
344 swpClient.x = rect.xLeft;
345 swpClient.y = rect.yBottom;
346 swpClient.cx = rect.xRight-rect.xLeft;
347 swpClient.cy = rect.yTop-rect.yBottom;
348 //TODO: Get rid of SWP_SHOW; needed for winhlp32 button bar for now
349 swpClient.fl = (pswp->fl & ~SWP_ZORDER) | SWP_MOVE | SWP_SHOW;
350 WinSetMultWindowPos(thdb->hab, &swpClient, 1);
351
352 //update child positions: rectWindow is in window coordinates
353 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
354 FrameUpdateChildPositions(win32wnd->getOS2WindowHandle());
355 }
356
357 if(win32wnd->CanReceiveSizeMsgs())
358 win32wnd->MsgPosChanged((LPARAM)&wp);
359
360 if ((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
361 {
362 //redraw the frame (to prevent unnecessary client updates)
363 BOOL redrawAll = FALSE;
364
365 if (win32wnd->getWindowClass())
366 {
367 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
368
369 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
370 redrawAll = TRUE;
371 else if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
372 redrawAll = TRUE;
373 } else redrawAll = TRUE;
374
375 if (redrawAll)
376 {
377 //CB: redraw all children for now
378 // -> problems with update region if we don't do it
379 // todo: rewrite whole handling
380 WinInvalidateRect(hwnd,NULL,TRUE);
381 }
382 else
383 {
384 HPS hps = WinGetPS(hwnd);
385 RECTL frame,client,arcl[4];
386
387 WinQueryWindowRect(hwnd,&frame);
388 //top
389 arcl[0].xLeft = 0;
390 arcl[0].xRight = frame.xRight;
391 arcl[0].yBottom = rect.yTop;
392 arcl[0].yTop = frame.yTop;
393 //right
394 arcl[1].xLeft = rect.xRight;
395 arcl[1].xRight = frame.xRight;
396 arcl[1].yBottom = 0;
397 arcl[1].yTop = frame.yTop;
398 //left
399 arcl[2].xLeft = 0;
400 arcl[2].xRight = rect.xLeft;
401 arcl[2].yBottom = 0;
402 arcl[2].yTop = frame.yTop;
403 //bottom
404 arcl[3].xLeft = 0;
405 arcl[3].xRight = frame.xRight;
406 arcl[3].yBottom = 0;
407 arcl[3].yTop = rect.yBottom;
408
409 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
410
411 WinInvalidateRegion(hwnd,hrgn,FALSE);
412 GpiDestroyRegion(hps,hrgn);
413 WinReleasePS(hps);
414 }
415 }
416 }
417 else
418 {
419 //update child positions: rectWindow is in window coordinates
420 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
421 FrameUpdateChildPositions(win32wnd->getOS2WindowHandle());
422 }
423
424 if(win32wnd->CanReceiveSizeMsgs())
425 win32wnd->MsgPosChanged((LPARAM)&wp);
426 }
427
428PosChangedEnd:
429 RestoreOS2TIB();
430 return (MRESULT)FALSE;
431 }
432
433 case WM_ERASEBACKGROUND:
434 break;
435
436 case WM_CALCVALIDRECTS:
437 {
438 //don't redraw here or PM redraw the whole frame (done in WM_WINDOWPOSCHANGED)
439 dprintf(("PMFRAME: WM_CALCVALIDRECTS"));
440 RestoreOS2TIB();
441 return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
442 }
443
444 case WM_ACTIVATE:
445 {
446 HWND hwndTitle;
447 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
448
449 dprintf(("PMFRAME: WM_ACTIVATE %x %x", hwnd, mp2));
450 if(win32wnd->IsWindowCreated())
451 win32wnd->DispatchMsgA(pWinMsg);
452
453 if (win32wnd->IsWindowCreated())
454 {
455 WinSendMsg(WinWindowFromID(hwnd,FID_CLIENT),WM_ACTIVATE,mp1,mp2);
456 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
457
458 //CB: show owner behind the dialog
459 if (win32wnd->IsModalDialog())
460 {
461 Win32BaseWindow *topOwner = win32wnd->getOwner()->GetTopParent();
462
463 if (topOwner) WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
464 }
465 }
466 else
467 {
468 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
469 }
470 RestoreOS2TIB();
471 return 0;
472 }
473
474 case WM_DESTROY:
475 dprintf(("PMFRAME: WM_DESTROY %x",hwnd));
476 WinSubclassWindow(hwnd,OldFrameProc);
477 win32wnd->setOldFrameProc(NULL);
478 goto RunDefFrameProc;
479
480 default:
481 RestoreOS2TIB();
482 return OldFrameProc(hwnd,msg,mp1,mp2);
483 }
484
485 RestoreOS2TIB();
486 return (MRESULT)FALSE;
487
488RunDefFrameProc:
489 RestoreOS2TIB();
490 return OldFrameProc(hwnd,msg,mp1,mp2);
491
492RunDefWndProc:
493 RestoreOS2TIB();
494 return WinDefWindowProc(hwnd,msg,mp1,mp2);
495}
496//******************************************************************************
497//******************************************************************************
498PVOID FrameSubclassFrameWindow(Win32BaseWindow *win32wnd)
499{
500 return WinSubclassWindow(win32wnd->getOS2FrameWindowHandle(),PFNWP(Win32FrameProc));
501}
502//******************************************************************************
503//******************************************************************************
504VOID FrameUpdateClient(Win32BaseWindow *win32wnd)
505{
506 RECT rectOld, rectNew;
507 RECTL rect;
508 SWP swpClient = {0};
509
510 rectOld = *win32wnd->getClientRectPtr();
511 win32wnd->MsgFormatFrame(NULL);
512 rectNew = *win32wnd->getClientRectPtr();
513 if(WinEqualRect(0, (PRECTL)&rectOld, (PRECTL)&rectNew) == 1) {
514 WinInvalidateRect(win32wnd->getOS2FrameWindowHandle(), NULL, FALSE);
515 return;
516 }
517 //CB: todo: use result for WM_CALCVALIDRECTS
518 mapWin32ToOS2Rect(win32wnd->getOS2FrameWindowHandle(), win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
519
520
521 swpClient.hwnd = win32wnd->getOS2WindowHandle();
522 swpClient.hwndInsertBehind = 0;
523 swpClient.x = rect.xLeft;
524 swpClient.y = rect.yBottom;
525 swpClient.cx = rect.xRight-rect.xLeft;
526 swpClient.cy = rect.yTop-rect.yBottom;
527 swpClient.fl = SWP_MOVE | SWP_SIZE;
528 WinSetMultWindowPos(GetThreadHAB(), &swpClient, 1);
529}
530//******************************************************************************
531//******************************************************************************
Note: See TracBrowser for help on using the repository browser.