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

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

scrollbar support and many other things

File size: 13.1 KB
Line 
1/* $Id: pmframe.cpp,v 1.9 2000-01-09 14:14:23 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 {
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_HITTEST:
196 {
197 DWORD res;
198
199 // Only send this message if the window is enabled
200 if (!win32wnd->IsWindowCreated())
201 res = HT_NORMAL;
202 else if (!WinIsWindowEnabled(hwnd))
203 res = HT_ERROR;
204 else if (win32wnd->getIgnoreHitTest())
205 res = HT_NORMAL;
206 else
207 {
208 dprintf(("PMFRAME: WM_HITTEST %x (%d,%d)",hwnd,(*(POINTS *)&mp1).x,(*(POINTS *)&mp1).y));
209
210 //CB: WinWindowFromPoint: PM sends WM_HITTEST -> loop -> stack overflow
211 win32wnd->setIgnoreHitTest(TRUE);
212 res = win32wnd->MsgHitTest(pWinMsg);
213 win32wnd->setIgnoreHitTest(FALSE);
214 }
215 RestoreOS2TIB();
216 return (MRESULT)res;
217 }
218
219 case WM_PAINT:
220 {
221 dprintf(("PMFRAME: WM_PAINT"));
222 if (win32wnd->getStyle() & WS_MINIMIZE_W)
223 goto RunDefFrameProc;
224 if (win32wnd->IsWindowCreated())
225 win32wnd->MsgNCPaint();
226 goto RunDefWndProc;
227 }
228
229 case WM_SIZE:
230 dprintf(("PMFRAME: WM_SIZE"));
231 goto RunDefFrameProc;
232
233 case WM_ADJUSTWINDOWPOS:
234 {
235 PSWP pswp = (PSWP)mp1;
236 SWP swpOld;
237 WINDOWPOS wp;
238 HWND hParent = NULLHANDLE, hwndAfter;
239
240 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));
241
242 //CB: show dialog in front of owner
243 if (win32wnd->IsModalDialogOwner())
244 {
245 pswp->fl |= SWP_ZORDER;
246 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
247 if (pswp->fl & SWP_ACTIVATE)
248 {
249 pswp->fl &= ~SWP_ACTIVATE;
250 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
251 }
252 }
253
254 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
255 goto RunDefFrameProc;
256
257 if(!win32wnd->CanReceiveSizeMsgs())
258 break;
259
260 WinQueryWindowPos(hwnd, &swpOld);
261 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
262 if (win32wnd->isChild()) {
263 if(win32wnd->getParent()) {
264 hParent = win32wnd->getParent()->getOS2WindowHandle();
265 }
266 else goto RunDefFrameProc;
267 }
268 }
269 hwndAfter = pswp->hwndInsertBehind;
270 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
271
272 wp.hwnd = win32wnd->getWindowHandle();
273 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
274 {
275 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
276 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
277 }
278
279 //CB: problems with profmine titlebar tracking
280 if(win32wnd->MsgPosChanging((LPARAM)&wp) == 0)
281 {//app or default window handler changed wp
282 dprintf(("PMFRAME: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
283 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
284
285 OSLibMapWINDOWPOStoSWPFrame(&wp, pswp, &swpOld, hParent, hwnd);
286 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
287 pswp->fl |= SWP_NOADJUST;
288 pswp->hwndInsertBehind = hwndAfter;
289 pswp->hwnd = hwnd;
290
291 RestoreOS2TIB();
292 return (MRESULT)0xf;
293 }
294 goto RunDefFrameProc;
295 }
296
297 case WM_WINDOWPOSCHANGED:
298 {
299 PSWP pswp = (PSWP)mp1;
300 SWP swpOld = *(pswp + 1);
301 WINDOWPOS wp;
302 HWND hParent = NULLHANDLE;
303
304 dprintf(("PMFRAME: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
305
306 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
307 goto PosChangedEnd;
308
309 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
310 if (win32wnd->isChild()) {
311 if(win32wnd->getParent()) {
312 hParent = win32wnd->getParent()->getOS2WindowHandle();
313 }
314 else goto PosChangedEnd; //parent has just been destroyed
315 }
316 }
317 OSLibMapSWPtoWINDOWPOSFrame(pswp, &wp, &swpOld, hParent, hwnd);
318
319 win32wnd->setWindowRect(wp.x, wp.y, wp.x+wp.cx, wp.y+wp.cy);
320
321 if(win32wnd->CanReceiveSizeMsgs())
322 win32wnd->MsgPosChanged((LPARAM)&wp);
323
324PosChangedEnd:
325 //update the client rect
326 RECTL rectl;
327
328 WinQueryWindowRect(win32wnd->getOS2FrameWindowHandle(),&rectl);
329 mapOS2ToWin32Rect(win32wnd->getOS2FrameWindowHandle(),OSLIB_HWND_DESKTOP,(PRECTLOS2)&rectl,win32wnd->getWindowRect());
330 WinQueryWindowRect(win32wnd->getOS2WindowHandle(),&rectl);
331 mapOS2ToWin32Rect(win32wnd->getOS2WindowHandle(),WinQueryWindow(hwnd,QW_PARENT),(PRECTLOS2)&rectl,win32wnd->getClientRectPtr());
332
333 //calls WM_FORMATFRAME if SWP_SIZE is set
334 RestoreOS2TIB();
335 rc = OldFrameProc(hwnd,msg,mp1,mp2);
336 SetWin32TIB();
337 //update child positions: rectWindow is in window coordinates
338 FrameUpdateChildPositions(win32wnd->getOS2WindowHandle());
339 RestoreOS2TIB();
340 return rc;
341 }
342
343 case WM_CALCVALIDRECTS:
344 {
345 PRECTL oldRect = (PRECTL)mp1,newRect = oldRect+1;
346 UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
347
348//CB: todo: use WM_NCCALCSIZE result
349 if (win32wnd->getWindowClass())
350 {
351 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
352
353 if ((dwStyle & CS_HREDRAW_W) && (newRect->xRight-newRect->xLeft != oldRect->xRight-oldRect->xLeft))
354 res |= CVR_REDRAW;
355 else if ((dwStyle & CS_VREDRAW_W) && (newRect->yTop-newRect->yBottom != oldRect->yTop-oldRect->yBottom))
356 res |= CVR_REDRAW;
357 } else res |= CVR_REDRAW;
358
359 //CB: PM sets client window position
360 RestoreOS2TIB();
361 OldFrameProc(hwnd,msg,mp1,mp2);
362 SetWin32TIB();
363
364 RestoreOS2TIB();
365 return (MRESULT)res;
366 }
367
368 case WM_ACTIVATE:
369 {
370 HWND hwndTitle;
371 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
372
373 if (win32wnd->IsWindowCreated())
374 {
375 WinSendMsg(WinWindowFromID(hwnd,FID_CLIENT),WM_ACTIVATE,mp1,mp2);
376 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
377
378 //CB: show owner behind the dialog
379 if (win32wnd->IsModalDialog())
380 {
381 Win32BaseWindow *topOwner = win32wnd->getOwner()->GetTopParent();
382
383 if (topOwner) WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
384 }
385 } else
386 {
387 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
388 }
389
390 RestoreOS2TIB();
391 return 0;
392 }
393
394 case WM_DESTROY:
395 dprintf(("PMFRAME: WM_DESTROY %x",hwnd));
396 WinSubclassWindow(hwnd,OldFrameProc);
397 win32wnd->setOldFrameProc(NULL);
398 goto RunDefFrameProc;
399
400 default:
401 RestoreOS2TIB();
402 return OldFrameProc(hwnd,msg,mp1,mp2);
403 }
404
405 RestoreOS2TIB();
406 return (MRESULT)FALSE;
407
408RunDefFrameProc:
409 RestoreOS2TIB();
410 return OldFrameProc(hwnd,msg,mp1,mp2);
411
412RunDefWndProc:
413 RestoreOS2TIB();
414 return WinDefWindowProc(hwnd,msg,mp1,mp2);
415}
416
417PVOID FrameSubclassFrameWindow(Win32BaseWindow *win32wnd)
418{
419 return WinSubclassWindow(win32wnd->getOS2FrameWindowHandle(),PFNWP(Win32FrameProc));
420}
421
422VOID FrameUpdateFrame(Win32BaseWindow *win32wnd,DWORD flags)
423{
424 WinSendMsg(win32wnd->getOS2FrameWindowHandle(),WM_UPDATEFRAME,(MPARAM)flags,(MPARAM)0);
425}
Note: See TracBrowser for help on using the repository browser.