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

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

get/peekmessage fixes, timer fix, (user/new) replaced wm_hittest code; added wm_ncactivate, changed system menu

File size: 12.5 KB
Line 
1/* $Id: pmframe.cpp,v 1.10 2000-01-10 23:29:13 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 {
110 PSWP pswp = (PSWP)mp1,swpClient;
111 RECTL *client = (PRECTL)mp2,rect;
112 RECT winRect;
113 INT ccount;
114
115 if (!win32wnd->IsWindowCreated()) goto RunDefFrameProc;
116 dprintf(("PMFRAME: WM_FORMATFRAME %x",hwnd));
117 RestoreOS2TIB();
118 ccount = (INT)OldFrameProc(hwnd,msg,mp1,mp2);
119 SetWin32TIB();
120 dprintf(("Frame size: %d %d",win32wnd->getWindowWidth(),win32wnd->getWindowHeight()));
121 win32wnd->MsgFormatFrame();
122 //CB: todo: use result for WM_CALCVALIDRECTS
123 mapWin32ToOS2Rect(WinQueryWindow(hwnd,QW_PARENT),hwnd,win32wnd->getClientRectPtr(),(PRECTLOS2)&rect);
124 swpClient = &pswp[ccount-1];
125 swpClient->x = rect.xLeft;
126 swpClient->y = rect.yBottom;
127 swpClient->cx = rect.xRight-rect.xLeft;
128 swpClient->cy = rect.yTop-rect.yBottom;
129 dprintf(("New client position: x=%d y=%d w=%d h=%d",swpClient->x,swpClient->y,swpClient->cx,swpClient->cy));
130 RestoreOS2TIB();
131 return (MRESULT)ccount;
132 }
133
134 case WM_MINMAXFRAME:
135 {
136 PSWP swp = (PSWP)mp1;
137
138 if (!win32wnd->IsWindowCreated()) goto RunDefFrameProc;
139 dprintf(("PMFRAME: WM_MINMAXFRAME %x",hwnd));
140 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
141 {
142 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
143 } else if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
144 {
145 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
146 } else if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
147 {
148 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
149 }
150 goto RunDefFrameProc;
151 }
152
153 case WM_QUERYBORDERSIZE:
154 goto RunDefFrameProc;
155
156 case WM_BUTTON1DOWN:
157 case WM_BUTTON1UP:
158 case WM_BUTTON1DBLCLK:
159 case WM_BUTTON2DOWN:
160 case WM_BUTTON2UP:
161 case WM_BUTTON2DBLCLK:
162 case WM_BUTTON3DOWN:
163 case WM_BUTTON3UP:
164 case WM_BUTTON3DBLCLK:
165 {
166 if (win32wnd->IsWindowCreated())
167 {
168 win32wnd->MsgButton(pWinMsg);
169 RestoreOS2TIB();
170 }
171 return (MRESULT)TRUE;
172 }
173
174 case WM_BUTTON2MOTIONSTART:
175 case WM_BUTTON2MOTIONEND:
176 case WM_BUTTON2CLICK:
177 case WM_BUTTON1MOTIONSTART:
178 case WM_BUTTON1MOTIONEND:
179 case WM_BUTTON1CLICK:
180 case WM_BUTTON3MOTIONSTART:
181 case WM_BUTTON3MOTIONEND:
182 case WM_BUTTON3CLICK:
183 RestoreOS2TIB();
184 return (MRESULT)TRUE;
185
186 case WM_MOUSEMOVE:
187 {
188 //OS/2 Window coordinates -> Win32 Window coordinates
189 if (win32wnd->IsWindowCreated())
190 win32wnd->MsgMouseMove(pWinMsg);
191 RestoreOS2TIB();
192 return (MRESULT)TRUE;
193 }
194
195 case WM_PAINT:
196 {
197 dprintf(("PMFRAME: WM_PAINT"));
198 if (win32wnd->getStyle() & WS_MINIMIZE_W)
199 goto RunDefFrameProc;
200 if (win32wnd->IsWindowCreated())
201 win32wnd->MsgNCPaint();
202 goto RunDefWndProc;
203 }
204
205 case WM_SIZE:
206 dprintf(("PMFRAME: WM_SIZE"));
207 goto RunDefFrameProc;
208
209 case WM_ADJUSTWINDOWPOS:
210 {
211 PSWP pswp = (PSWP)mp1;
212 SWP swpOld;
213 WINDOWPOS wp;
214 HWND hParent = NULLHANDLE, hwndAfter;
215
216 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));
217
218 //CB: show dialog in front of owner
219 if (win32wnd->IsModalDialogOwner())
220 {
221 pswp->fl |= SWP_ZORDER;
222 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
223 if (pswp->fl & SWP_ACTIVATE)
224 {
225 pswp->fl &= ~SWP_ACTIVATE;
226 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
227 }
228 }
229
230 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
231 goto RunDefFrameProc;
232
233 if(!win32wnd->CanReceiveSizeMsgs())
234 break;
235
236 WinQueryWindowPos(hwnd, &swpOld);
237 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
238 if (win32wnd->isChild()) {
239 if(win32wnd->getParent()) {
240 hParent = win32wnd->getParent()->getOS2WindowHandle();
241 }
242 else goto RunDefFrameProc;
243 }
244 }
245 hwndAfter = pswp->hwndInsertBehind;
246 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
247
248 wp.hwnd = win32wnd->getWindowHandle();
249 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
250 {
251 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
252 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
253 }
254
255 //CB: problems with profmine titlebar tracking
256 if(win32wnd->MsgPosChanging((LPARAM)&wp) == 0)
257 {//app or default window handler changed wp
258 dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
259 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
260
261 OSLibMapWINDOWPOStoSWPFrame(&wp, pswp, &swpOld, hParent, hwnd);
262 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
263 pswp->fl |= SWP_NOADJUST;
264 pswp->hwndInsertBehind = hwndAfter;
265 pswp->hwnd = hwnd;
266
267 RestoreOS2TIB();
268 return (MRESULT)0xf;
269 }
270 goto RunDefFrameProc;
271 }
272
273 case WM_WINDOWPOSCHANGED:
274 {
275 PSWP pswp = (PSWP)mp1;
276 SWP swpOld = *(pswp + 1);
277 WINDOWPOS wp;
278 HWND hParent = NULLHANDLE;
279
280 dprintf(("PMFRAME: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
281
282 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
283 goto PosChangedEnd;
284
285 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
286 if (win32wnd->isChild()) {
287 if(win32wnd->getParent()) {
288 hParent = win32wnd->getParent()->getOS2WindowHandle();
289 }
290 else goto PosChangedEnd; //parent has just been destroyed
291 }
292 }
293 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
294
295 win32wnd->setWindowRect(wp.x, wp.y, wp.x+wp.cx, wp.y+wp.cy);
296
297 if(win32wnd->CanReceiveSizeMsgs())
298 win32wnd->MsgPosChanged((LPARAM)&wp);
299
300PosChangedEnd:
301 //update the client rect
302 RECTL rectl;
303
304 WinQueryWindowRect(win32wnd->getOS2FrameWindowHandle(),&rectl);
305 mapOS2ToWin32Rect(win32wnd->getOS2FrameWindowHandle(),OSLIB_HWND_DESKTOP,(PRECTLOS2)&rectl,win32wnd->getWindowRect());
306 WinQueryWindowRect(win32wnd->getOS2WindowHandle(),&rectl);
307 mapOS2ToWin32Rect(win32wnd->getOS2WindowHandle(),WinQueryWindow(hwnd,QW_PARENT),(PRECTLOS2)&rectl,win32wnd->getClientRectPtr());
308
309 //calls WM_FORMATFRAME if SWP_SIZE is set
310 RestoreOS2TIB();
311 rc = OldFrameProc(hwnd,msg,mp1,mp2);
312 SetWin32TIB();
313 //update child positions: rectWindow is in window coordinates
314 FrameUpdateChildPositions(win32wnd->getOS2WindowHandle());
315 RestoreOS2TIB();
316 return rc;
317 }
318
319 case WM_CALCVALIDRECTS:
320 {
321 PRECTL oldRect = (PRECTL)mp1,newRect = oldRect+1;
322 UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
323
324//CB: todo: use WM_NCCALCSIZE result
325 if (win32wnd->getWindowClass())
326 {
327 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
328
329 if ((dwStyle & CS_HREDRAW_W) && (newRect->xRight-newRect->xLeft != oldRect->xRight-oldRect->xLeft))
330 res |= CVR_REDRAW;
331 else if ((dwStyle & CS_VREDRAW_W) && (newRect->yTop-newRect->yBottom != oldRect->yTop-oldRect->yBottom))
332 res |= CVR_REDRAW;
333 } else res |= CVR_REDRAW;
334
335 //CB: PM sets client window position
336 RestoreOS2TIB();
337 OldFrameProc(hwnd,msg,mp1,mp2);
338 SetWin32TIB();
339
340 RestoreOS2TIB();
341 return (MRESULT)res;
342 }
343
344 case WM_ACTIVATE:
345 {
346 HWND hwndTitle;
347 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
348
349 if (win32wnd->IsWindowCreated())
350 {
351 WinSendMsg(WinWindowFromID(hwnd,FID_CLIENT),WM_ACTIVATE,mp1,mp2);
352 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
353
354 //CB: show owner behind the dialog
355 if (win32wnd->IsModalDialog())
356 {
357 Win32BaseWindow *topOwner = win32wnd->getOwner()->GetTopParent();
358
359 if (topOwner) WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
360 }
361 }
362 else
363 {
364 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
365 }
366 if(win32wnd->IsWindowCreated())
367 win32wnd->DispatchMsgA(pWinMsg);
368
369 RestoreOS2TIB();
370 return 0;
371 }
372
373 case WM_DESTROY:
374 dprintf(("PMFRAME: WM_DESTROY %x",hwnd));
375 WinSubclassWindow(hwnd,OldFrameProc);
376 win32wnd->setOldFrameProc(NULL);
377 goto RunDefFrameProc;
378
379 default:
380 RestoreOS2TIB();
381 return OldFrameProc(hwnd,msg,mp1,mp2);
382 }
383
384 RestoreOS2TIB();
385 return (MRESULT)FALSE;
386
387RunDefFrameProc:
388 RestoreOS2TIB();
389 return OldFrameProc(hwnd,msg,mp1,mp2);
390
391RunDefWndProc:
392 RestoreOS2TIB();
393 return WinDefWindowProc(hwnd,msg,mp1,mp2);
394}
395
396PVOID FrameSubclassFrameWindow(Win32BaseWindow *win32wnd)
397{
398 return WinSubclassWindow(win32wnd->getOS2FrameWindowHandle(),PFNWP(Win32FrameProc));
399}
400
401VOID FrameUpdateFrame(Win32BaseWindow *win32wnd,DWORD flags)
402{
403 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_UPDATEFRAME,(MPARAM)flags,(MPARAM)0);
404}
Note: See TracBrowser for help on using the repository browser.