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

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

wm_activate fixes, scrollbar fix, drawframe fix

File size: 14.7 KB
Line 
1/* $Id: pmframe.cpp,v 1.15 2000-01-13 13:54:52 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
291 swpClient.hwnd = win32wnd->getOS2WindowHandle();
292 swpClient.hwndInsertBehind = 0;
293 swpClient.x = rect.xLeft;
294 swpClient.y = rect.yBottom;
295 swpClient.cx = rect.xRight-rect.xLeft;
296 swpClient.cy = rect.yTop-rect.yBottom;
297 //TODO: Get rid of SWP_SHOW; needed for winhlp32 button bar for now
298 swpClient.fl = (pswp->fl & ~SWP_ZORDER) | SWP_MOVE | SWP_SHOW;
299 WinSetMultWindowPos(thdb->hab, &swpClient, 1);
300
301 //update child positions: rectWindow is in window coordinates
302 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
303 FrameUpdateChildPositions(win32wnd->getOS2WindowHandle());
304 }
305
306 if(win32wnd->CanReceiveSizeMsgs())
307 win32wnd->MsgPosChanged((LPARAM)&wp);
308
309 if ((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
310 {
311 //redraw the frame (to prevent unnecessary client updates)
312 BOOL redrawAll = FALSE;
313
314 if (win32wnd->getWindowClass())
315 {
316 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
317
318 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
319 redrawAll = TRUE;
320 else if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
321 redrawAll = TRUE;
322 } else redrawAll = TRUE;
323
324 if (redrawAll)
325 {
326 WinInvalidateRect(hwnd,NULL,TRUE);
327 }
328 else
329 {
330 HPS hps = WinGetPS(hwnd);
331 RECTL frame,client,arcl[4];
332
333 WinQueryWindowRect(hwnd,&frame);
334 //top
335 arcl[0].xLeft = 0;
336 arcl[0].xRight = frame.xRight;
337 arcl[0].yBottom = rect.yTop;
338 arcl[0].yTop = frame.yTop;
339 //right
340 arcl[1].xLeft = rect.xRight;
341 arcl[1].xRight = frame.xRight;
342 arcl[1].yBottom = 0;
343 arcl[1].yTop = frame.yTop;
344 //left
345 arcl[2].xLeft = 0;
346 arcl[2].xRight = rect.xLeft;
347 arcl[2].yBottom = 0;
348 arcl[2].yTop = frame.yTop;
349 //bottom
350 arcl[3].xLeft = 0;
351 arcl[3].xRight = frame.xRight;
352 arcl[3].yBottom = 0;
353 arcl[3].yTop = rect.yBottom;
354
355 HRGN hrgn = GpiCreateRegion(hps,3,(PRECTL)&arcl);
356
357 WinInvalidateRegion(hwnd,hrgn,FALSE);
358 GpiDestroyRegion(hps,hrgn);
359 WinReleasePS(hps);
360 }
361 }
362 }
363 else
364 {
365 //update child positions: rectWindow is in window coordinates
366 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
367 FrameUpdateChildPositions(win32wnd->getOS2WindowHandle());
368 }
369
370 if(win32wnd->CanReceiveSizeMsgs())
371 win32wnd->MsgPosChanged((LPARAM)&wp);
372 }
373
374PosChangedEnd:
375 RestoreOS2TIB();
376 return (MRESULT)FALSE;
377 }
378
379 case WM_CALCVALIDRECTS:
380 {
381 //don't redraw here or PM redraw the whole frame (done in WM_WINDOWPOSCHANGED)
382 RestoreOS2TIB();
383 return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
384 }
385
386 case WM_ACTIVATE:
387 {
388 HWND hwndTitle;
389 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
390
391 dprintf(("PMFRAME: WM_ACTIVATE %x %x", hwnd, mp2));
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(NULL);
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.