source: trunk/src/user32/pmwindow.cpp@ 5935

Last change on this file since 5935 was 5935, checked in by sandervl, 24 years ago

reference count (window + class objects) rewrite

File size: 43.8 KB
Line 
1/* $Id: pmwindow.cpp,v 1.133 2001-06-09 14:50:19 sandervl Exp $ */
2/*
3 * Win32 Window Managment Code for OS/2
4 *
5 * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl)
6 * Copyright 1999 Daniela Engert (dani@ngrt.de)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 */
12#define INCL_WIN
13#define INCL_GPI
14#define INCL_DEV /* Device Function definitions */
15#define INCL_GPICONTROL /* GPI control Functions */
16#define INCL_DOSPROCESS
17#define INCL_WINTRACKRECT
18
19#include <os2wrap.h>
20#include <stdlib.h>
21#include <string.h>
22#include <win32type.h>
23#include <win32api.h>
24#include <winconst.h>
25#include <winuser32.h>
26#include <wprocess.h>
27#include <misc.h>
28#include <win32wbase.h>
29#include <win32dlg.h>
30#include "win32wdesktop.h"
31#include "pmwindow.h"
32#include "oslibwin.h"
33#include "oslibutil.h"
34#include "oslibgdi.h"
35#include "oslibmsg.h"
36#define INCLUDED_BY_DC
37#include "dc.h"
38#include <thread.h>
39#include <wprocess.h>
40#include "caret.h"
41#include "timer.h"
42#include <codepage.h>
43
44#define DBG_LOCALLOG DBG_pmwindow
45#include "dbglocal.h"
46
47//define this to use the new code for WM_CALCVALIDRECT handling
48//#define USE_CALCVALIDRECT
49
50HMQ hmq = 0; /* Message queue handle */
51HAB hab = 0;
52
53RECTL desktopRectl = {0};
54ULONG ScreenWidth = 0;
55ULONG ScreenHeight = 0;
56ULONG ScreenBitsPerPel = 0;
57
58static PFNWP pfnFrameWndProc = NULL;
59
60MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
61MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
62
63//******************************************************************************
64//Initialize PM; create hab, message queue and register special Win32 window classes
65//******************************************************************************
66BOOL InitPM()
67{
68
69 hab = WinInitialize(0);
70 dprintf(("Winitialize returned %x", hab));
71 hmq = WinCreateMsgQueue(hab, 0);
72
73 if(!hab || !hmq)
74 {
75 UINT error;
76 //CB: only fail on real error
77 error = WinGetLastError(hab) & 0xFFFF; //error code
78 if (!hab || (error != PMERR_MSG_QUEUE_ALREADY_EXISTS))
79 {
80 dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
81 dprintf((" Error = %x",error));
82 return(FALSE);
83 }
84 else
85 {
86 if(!hab) {
87 hab = WinQueryAnchorBlock(HWND_DESKTOP);
88 dprintf(("WinQueryAnchorBlock returned %x", hab));
89 }
90 if(!hmq) {
91 hmq = HMQ_CURRENT;
92 }
93 }
94 }
95 SetThreadHAB(hab);
96 dprintf(("InitPM: hmq = %x", hmq));
97 SetThreadMessageQueue(hmq);
98
99 BOOL rc = WinSetCp(hmq, GetDisplayCodepage());
100 dprintf(("InitPM: WinSetCP was %sOK", rc ? "" : "not "));
101
102 if(!WinRegisterClass( /* Register window class */
103 hab, /* Anchor block handle */
104 (PSZ)WIN32_STDCLASS, /* Window class name */
105 (PFNWP)Win32WindowProc, /* Address of window procedure */
106 0,
107 NROF_WIN32WNDBYTES))
108 {
109 dprintf(("WinRegisterClass Win32BaseWindow failed"));
110 return(FALSE);
111 }
112
113 CLASSINFO FrameClassInfo;
114 if(!WinQueryClassInfo (hab, WC_FRAME, &FrameClassInfo)) {
115 dprintf (("WinQueryClassInfo WC_FRAME failed"));
116 return (FALSE);
117 }
118 pfnFrameWndProc = FrameClassInfo.pfnWindowProc;
119
120 dprintf(("WC_FRAME style %x", FrameClassInfo.flClassStyle));
121
122 if(!WinRegisterClass( /* Register window class */
123 hab, /* Anchor block handle */
124 (PSZ)WIN32_STDFRAMECLASS, /* Window class name */
125 (PFNWP)Win32FrameWindowProc, /* Address of window procedure */
126 CS_FRAME,
127 FrameClassInfo.cbWindowData))
128 {
129 dprintf(("WinRegisterClass Win32BaseWindow failed %x", WinGetLastError(hab)));
130 return(FALSE);
131 }
132
133 WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
134 ScreenWidth = desktopRectl.xRight;
135 ScreenHeight = desktopRectl.yTop;
136
137 HDC hdc; /* Device-context handle */
138 /* context data structure */
139 DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
140 NULL, NULL, NULL};
141
142 /* create memory device context */
143 hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
144 DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, (PLONG)&ScreenBitsPerPel);
145 DevCloseDC(hdc);
146
147 dprintf(("InitPM: Desktop (%d,%d) bpp %d", ScreenWidth, ScreenHeight, ScreenBitsPerPel));
148 return TRUE;
149} /* End of main */
150//******************************************************************************
151//Win32 window message handler
152//******************************************************************************
153MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
154{
155 Win32BaseWindow *win32wnd;
156 TEB *teb;
157 MSG winMsg, *pWinMsg;
158 MRESULT rc = 0;
159 POSTMSG_PACKET *postmsg;
160 OSLIBPOINT point, ClientPoint;
161
162 //Restore our FS selector
163 SetWin32TIB();
164
165 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
166 teb = GetThreadTEB();
167 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
168
169//// dprintf(("window %x msg %x", (win32wnd) ? win32wnd->getWindowHandle() : 0, msg));
170
171 if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
172 dprintf(("OS2: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
173 goto RunDefWndProc;
174 }
175//// if(teb->o.odin.fIgnoreMsgs) {
176//// goto RunDefWndProc;
177//// }
178
179 if((teb->o.odin.msgstate & 1) == 0)
180 {//message that was sent directly to our window proc handler; translate it here
181 QMSG qmsg;
182
183 qmsg.msg = msg;
184 qmsg.hwnd = hwnd;
185 qmsg.mp1 = mp1;
186 qmsg.mp2 = mp2;
187 qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
188 WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
189 qmsg.reserved = 0;
190
191 if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
192 {//message was not translated
193 memset(&winMsg, 0, sizeof(MSG));
194 }
195 pWinMsg = &winMsg;
196 }
197 else {
198 pWinMsg = &teb->o.odin.msg;
199 teb->o.odin.msgstate++;
200 }
201 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
202
203 if(msg >= WIN32APP_POSTMSG) {
204 //probably win32 app user message
205 dprintf2(("Posted message %x->%x", msg, msg-WIN32APP_POSTMSG));
206 if((ULONG)mp1 == WIN32MSG_MAGICA) {
207 rc = (MRESULT)win32wnd->DispatchMsgA(pWinMsg);
208 }
209 else
210 if((ULONG)mp1 == WIN32MSG_MAGICW) {
211 rc = (MRESULT)win32wnd->DispatchMsgW(pWinMsg);
212 }
213 else {//broadcasted message
214 rc = (MRESULT)win32wnd->DispatchMsgA(pWinMsg);
215 }
216 RELEASE_WNDOBJ(win32wnd);
217 RestoreOS2TIB();
218 return rc;
219 }
220
221 switch( msg )
222 {
223 //OS/2 msgs
224 case WM_CREATE:
225 {
226 if(teb->o.odin.newWindow == 0)
227 goto createfail;
228
229 //Processing is done in after WinCreateWindow returns
230 dprintf(("OS2: WM_CREATE %x", hwnd));
231 win32wnd = (Win32BaseWindow *)teb->o.odin.newWindow;
232 win32wnd->addRef();
233 teb->o.odin.newWindow = 0;
234 if(win32wnd->MsgCreate(hwnd) == FALSE)
235 {
236 rc = (MRESULT)TRUE; //discontinue window creation
237 break;
238 }
239 createfail:
240 rc = (MRESULT)FALSE;
241 break;
242 }
243
244 case WM_QUIT:
245 dprintf(("OS2: WM_QUIT %x", hwnd));
246 win32wnd->MsgQuit();
247 break;
248
249 case WM_CLOSE:
250 dprintf(("OS2: WM_CLOSE %x", hwnd));
251 win32wnd->MsgClose();
252 break;
253
254 case WM_DESTROY:
255 dprintf(("OS2: WM_DESTROY %x", hwnd));
256 win32wnd->MsgDestroy();
257 WinSetVisibleRegionNotify(hwnd, FALSE);
258 goto RunDefWndProc;
259
260 case WM_ENABLE:
261 dprintf(("OS2: WM_ENABLE %x", hwnd));
262 break;
263
264 case WM_SHOW:
265 dprintf(("OS2: WM_SHOW %x %d", hwnd, mp1));
266 win32wnd->MsgShow((ULONG)mp1);
267 break;
268
269 case WM_ACTIVATE:
270 {
271 ULONG flags = WinQueryWindowULong(hwnd, OFFSET_WIN32FLAGS);
272
273 dprintf(("OS2: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2));
274 WinSetWindowULong(hwnd, OFFSET_WIN32FLAGS, SHORT1FROMMP(mp1) ? (flags | WINDOWFLAG_ACTIVE):(flags & ~WINDOWFLAG_ACTIVE));
275 if(win32wnd->IsWindowCreated())
276 {
277 win32wnd->MsgActivate((LOWORD(pWinMsg->wParam) == WA_ACTIVE_W) ? 1 : 0, HIWORD(pWinMsg->wParam), pWinMsg->lParam, (HWND)mp2);
278 }
279 break;
280 }
281
282 case WM_SIZE:
283 {
284 dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp1)));
285 win32wnd->SetVisibleRegionChanged(TRUE);
286 goto RunDefWndProc;
287 }
288
289
290 case WM_VRNENABLED:
291 dprintf(("OS2: WM_VRNENABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
292 if(!win32wnd->isComingToTop() && ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == WS_EX_TOPMOST_W))
293 {
294 HWND hwndrelated;
295 Win32BaseWindow *topwindow;
296
297 win32wnd->setComingToTop(TRUE);
298
299 hwndrelated = WinQueryWindow(hwnd, QW_PREV);
300 dprintf(("WM_VRNENABLED hwndrelated = %x (hwnd=%x)", hwndrelated, hwnd));
301 topwindow = Win32BaseWindow::GetWindowFromOS2Handle(hwndrelated);
302 if(topwindow == NULL || ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == 0)) {
303 //put window at the top of z order
304 WinSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
305 }
306 if(topwindow) RELEASE_WNDOBJ(topwindow);
307
308 win32wnd->setComingToTop(FALSE);
309 break;
310 }
311 goto RunDefWndProc;
312
313 case WM_VRNDISABLED:
314 dprintf(("OS2: WM_VRNDISABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
315 goto RunDefWndProc;
316
317 case WIN32APP_SETFOCUSMSG:
318 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
319 //must delay this function call
320 //mp1 = win32 window handle
321 //mp2 = top parent if activation required
322 dprintf(("USER32: Delayed SetFocus %x %x %x call!", teb->o.odin.hwndFocus, mp1, mp2));
323 if(teb->o.odin.hwndFocus) {
324 RELEASE_WNDOBJ(win32wnd);
325 win32wnd = Win32BaseWindow::GetWindowFromHandle(teb->o.odin.hwndFocus);
326 if(win32wnd) {
327 if(mp2) {
328 SetActiveWindow((HWND)mp2);
329 }
330 if(!IsWindow(win32wnd->getWindowHandle())) break; //abort if window destroyed
331 WinFocusChange(HWND_DESKTOP, win32wnd->getOS2WindowHandle(), FC_NOSETACTIVE);
332 }
333 else DebugInt3();
334 }
335 break;
336
337 case WM_SETFOCUS:
338 {
339 HWND hwndFocus = (HWND)mp1;
340
341 dprintf(("OS2: WM_SETFOCUS %x %x (%x) %d", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle(hwndFocus), mp2));
342
343 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
344 //must delay this function call
345
346 teb->o.odin.fWM_SETFOCUS = TRUE;
347 teb->o.odin.hwndFocus = 0;
348 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC)
349 {
350 //another (non-win32) application's window
351 //set to NULL (allowed according to win32 SDK) to avoid problems
352 hwndFocus = NULL;
353 }
354 if((ULONG)mp2 == TRUE) {
355 HWND hwndFocusWin32 = OS2ToWin32Handle(hwndFocus);
356 recreateCaret (hwndFocusWin32);
357 win32wnd->MsgSetFocus(hwndFocusWin32);
358 }
359 else win32wnd->MsgKillFocus(OS2ToWin32Handle(hwndFocus));
360 teb->o.odin.fWM_SETFOCUS = FALSE;
361
362 break;
363 }
364
365 //**************************************************************************
366 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
367 //**************************************************************************
368
369 case WM_BUTTON1DOWN:
370 case WM_BUTTON1UP:
371 case WM_BUTTON1DBLCLK:
372 case WM_BUTTON2DOWN:
373 case WM_BUTTON2UP:
374 case WM_BUTTON2DBLCLK:
375 case WM_BUTTON3DOWN:
376 case WM_BUTTON3UP:
377 case WM_BUTTON3DBLCLK:
378 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
379 RELEASE_WNDOBJ(win32wnd);
380 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
381 }
382 if(win32wnd)
383 win32wnd->MsgButton(pWinMsg);
384
385 rc = (MRESULT)TRUE;
386 break;
387
388 case WM_BUTTON2MOTIONSTART:
389 case WM_BUTTON2MOTIONEND:
390 case WM_BUTTON2CLICK:
391 case WM_BUTTON1MOTIONSTART:
392 case WM_BUTTON1MOTIONEND:
393 case WM_BUTTON1CLICK:
394 case WM_BUTTON3MOTIONSTART:
395 case WM_BUTTON3MOTIONEND:
396 case WM_BUTTON3CLICK:
397 rc = (MRESULT)TRUE;
398 break;
399
400 case WM_MOUSEMOVE:
401 {
402 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
403 RELEASE_WNDOBJ(win32wnd);
404 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
405 }
406 if(win32wnd)
407 win32wnd->MsgMouseMove(pWinMsg);
408 break;
409 }
410
411 case WM_CONTROL:
412 goto RunDefWndProc;
413
414 case WM_COMMAND:
415 dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2));
416 win32wnd->DispatchMsgA(pWinMsg);
417 break;
418
419 case WM_SYSCOMMAND:
420 win32wnd->DispatchMsgA(pWinMsg);
421 break;
422
423 case WM_RENDERFMT:
424 case WM_RENDERALLFMTS:
425 case WM_DESTROYCLIPBOARD:
426 win32wnd->DispatchMsgA(pWinMsg);
427 break;
428
429 case WM_CHAR:
430 win32wnd->MsgChar(pWinMsg);
431 break;
432
433 case WM_TIMER:
434 win32wnd->DispatchMsgA(pWinMsg);
435 goto RunDefWndProc;
436
437 case WM_SETWINDOWPARAMS:
438 {
439 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
440
441 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
442 if(wndParams->fsStatus & WPM_TEXT) {
443 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
444 }
445 goto RunDefWndProc;
446 }
447
448 case WM_QUERYWINDOWPARAMS:
449 {
450 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
451 ULONG textlen;
452 PSZ wintext;
453
454 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
455 {
456 if(wndpars->fsStatus & WPM_TEXT)
457 win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
458 if(wndpars->fsStatus & WPM_CCHTEXT)
459 wndpars->cchText = win32wnd->MsgGetTextLength();
460
461 wndpars->fsStatus = 0;
462 wndpars->cbCtlData = 0;
463 wndpars->cbPresParams = 0;
464 rc = (MRESULT)TRUE;
465 break;
466 }
467 goto RunDefWndProc;
468 }
469
470 case WM_PAINT:
471 {
472 RECTL rectl;
473 BOOL rc;
474
475 rc = WinQueryUpdateRect(hwnd, &rectl);
476 dprintf(("OS2: WM_PAINT %x (%d,%d) (%d,%d) rc=%d", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop, rc));
477
478 if(rc && win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
479 rectl.yBottom != rectl.yTop))
480 {
481 win32wnd->DispatchMsgA(pWinMsg);
482 }
483 else goto RunDefWndProc;
484 break;
485 }
486
487 case WM_ERASEBACKGROUND:
488 {
489 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
490 rc = (MRESULT)FALSE;
491 break;
492 }
493
494 case WM_CALCVALIDRECTS:
495 dprintf(("OS2: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
496 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
497 break;
498
499 case WM_REALIZEPALETTE:
500 {
501 dprintf(("OS2: WM_REALIZEPALETTE"));
502 goto RunDefWndProc;
503 }
504
505 case WM_INITMENU:
506 case WM_MENUSELECT:
507 case WM_MENUEND:
508 case WM_NEXTMENU:
509 case WM_SYSCOLORCHANGE:
510 case WM_SYSVALUECHANGED:
511 case WM_SETSELECTION:
512 case WM_PPAINT:
513 case WM_PSETFOCUS:
514 case WM_PSYSCOLORCHANGE:
515 case WM_PSIZE:
516 case WM_PACTIVATE:
517 case WM_PCONTROL:
518 case WM_HELP:
519 case WM_APPTERMINATENOTIFY:
520 case WM_PRESPARAMCHANGED:
521 case WM_DRAWITEM:
522 case WM_MEASUREITEM:
523 case WM_CONTROLPOINTER:
524 case WM_QUERYDLGCODE:
525 case WM_SUBSTITUTESTRING:
526 case WM_MATCHMNEMONIC:
527 case WM_SAVEAPPLICATION:
528 case WM_SEMANTICEVENT:
529 default:
530 dprintf2(("OS2: RunDefWndProc hwnd %x msg %x mp1 %x mp2 %x", hwnd, msg, mp1, mp2));
531 goto RunDefWndProc;
532 }
533 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
534 RestoreOS2TIB();
535 return (MRESULT)rc;
536
537RunDefWndProc:
538// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
539 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
540 RestoreOS2TIB();
541 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
542} /* End of Win32WindowProc */
543//******************************************************************************
544//******************************************************************************
545MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
546{
547 POSTMSG_PACKET *postmsg;
548 OSLIBPOINT point, ClientPoint;
549 Win32BaseWindow *win32wnd;
550 TEB *teb;
551 MRESULT rc = 0;
552 MSG winMsg, *pWinMsg;
553
554 //Restore our FS selector
555 SetWin32TIB();
556
557 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
558 teb = GetThreadTEB();
559 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
560
561 if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
562 dprintf(("PMFRAME: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
563 goto RunDefFrameWndProc;
564 }
565//// if(teb->o.odin.fIgnoreMsgs) {
566//// goto RunDefWndProc;
567//// }
568
569 if((teb->o.odin.msgstate & 1) == 0)
570 {//message that was sent directly to our window proc handler; translate it here
571 QMSG qmsg;
572
573 qmsg.msg = msg;
574 qmsg.hwnd = hwnd;
575 qmsg.mp1 = mp1;
576 qmsg.mp2 = mp2;
577 qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
578 WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
579 qmsg.reserved = 0;
580
581 if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
582 {//message was not translated
583 memset(&winMsg, 0, sizeof(MSG));
584 }
585 pWinMsg = &winMsg;
586 }
587 else {
588 pWinMsg = &teb->o.odin.msg;
589 teb->o.odin.msgstate++;
590 }
591 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
592
593 switch( msg )
594 {
595 case WM_CREATE:
596 {
597 //WM_CREATE handled during client window creation
598 dprintf(("PMFRAME: WM_CREATE %x"));
599 goto RunDefFrameWndProc;
600 }
601
602 case WM_PAINT:
603 {
604 RECTL rectl;
605
606 HPS hps = WinBeginPaint(hwnd, NULL, &rectl);
607 dprintf(("PMFRAME: WM_PAINT %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
608
609 if(win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
610 rectl.yBottom != rectl.yTop))
611 {
612 PRECT pClient = win32wnd->getClientRectPtr();
613 PRECT pWindow = win32wnd->getWindowRect();
614
615 if(!(pClient->left == 0 && pClient->top == 0 &&
616 win32wnd->getClientHeight() == win32wnd->getWindowHeight() &&
617 win32wnd->getClientWidth() == win32wnd->getWindowWidth()))
618 {
619 RECT rectUpdate;
620
621 mapOS2ToWin32Rect(win32wnd->getWindowHeight(), (PRECTLOS2)&rectl, &rectUpdate);
622 win32wnd->MsgNCPaint(&rectUpdate);
623 }
624 }
625 WinEndPaint(hps);
626 break;
627 }
628
629 case WM_ERASEBACKGROUND:
630 {
631 dprintf(("PMFRAME:WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
632 rc = (MRESULT)FALSE;
633 break;
634 }
635
636 //**************************************************************************
637 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
638 //**************************************************************************
639
640 case WM_BUTTON1DOWN:
641 case WM_BUTTON1UP:
642 case WM_BUTTON1DBLCLK:
643 case WM_BUTTON2DOWN:
644 case WM_BUTTON2UP:
645 case WM_BUTTON2DBLCLK:
646 case WM_BUTTON3DOWN:
647 case WM_BUTTON3UP:
648 case WM_BUTTON3DBLCLK:
649 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
650 RELEASE_WNDOBJ(win32wnd);
651 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
652 }
653 if(win32wnd)
654 win32wnd->MsgButton(pWinMsg);
655
656 rc = (MRESULT)TRUE;
657 break;
658
659 case WM_BUTTON2MOTIONSTART:
660 case WM_BUTTON2MOTIONEND:
661 case WM_BUTTON2CLICK:
662 case WM_BUTTON1MOTIONSTART:
663 case WM_BUTTON1MOTIONEND:
664 case WM_BUTTON1CLICK:
665 case WM_BUTTON3MOTIONSTART:
666 case WM_BUTTON3MOTIONEND:
667 case WM_BUTTON3CLICK:
668 rc = (MRESULT)TRUE;
669 break;
670
671 case WM_MOUSEMOVE:
672 {
673 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
674 RELEASE_WNDOBJ(win32wnd);
675 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
676 }
677 if(win32wnd)
678 win32wnd->MsgMouseMove(pWinMsg);
679 break;
680 }
681
682 case WM_ADJUSTWINDOWPOS:
683 {
684 PSWP pswp = (PSWP)mp1;
685 SWP swpOld;
686 WINDOWPOS wp,wpOld;
687 HWND hParent = NULLHANDLE, hwndAfter;
688
689 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));
690
691 if(pswp->fl & SWP_NOADJUST) {
692 //ignore weird messages (TODO: why are they sent?)
693 break;
694 }
695 //CB: show dialog in front of owner
696 if (win32wnd->IsModalDialogOwner())
697 {
698 dprintf(("win32wnd->IsModalDialogOwner %x", win32wnd->getWindowHandle()));
699 pswp->fl |= SWP_ZORDER;
700 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
701 if (pswp->fl & SWP_ACTIVATE)
702 {
703 pswp->fl &= ~SWP_ACTIVATE;
704 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
705 }
706 }
707
708 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
709 goto RunDefWndProc;
710
711 if(!win32wnd->CanReceiveSizeMsgs())
712 break;
713
714 WinQueryWindowPos(hwnd, &swpOld);
715 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
716 if (win32wnd->isChild()) {
717 if(win32wnd->getParent()) {
718 hParent = win32wnd->getParent()->getOS2WindowHandle();
719 }
720 else goto RunDefWndProc;
721 }
722 }
723 hwndAfter = pswp->hwndInsertBehind;
724 if(win32wnd->getParent()) {
725 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(), hwnd);
726 }
727 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
728
729 wp.hwnd = win32wnd->getWindowHandle();
730 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
731 {
732 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
733 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
734 if(wndAfter) {
735 wp.hwndInsertAfter = wndAfter->getWindowHandle();
736 RELEASE_WNDOBJ(wndAfter);
737 }
738 else wp.hwndInsertAfter = HWND_TOP_W;
739 }
740
741 wpOld = wp;
742 win32wnd->MsgPosChanging((LPARAM)&wp);
743
744 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
745 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
746 {
747 ULONG flags = pswp->fl; //make a backup copy; OSLibMapWINDOWPOStoSWP will modify it
748
749 dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
750 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
751
752 if(win32wnd->getParent()) {
753 OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getClientHeight(),
754 hwnd);
755 }
756 else OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), hwnd);
757
758 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
759
760 //OSLibMapWINDOWPOStoSWP can add flags, but we must not let it remove flags!
761 if(pswp->fl & SWP_SIZE)
762 flags |= SWP_SIZE;
763
764 if(pswp->fl & SWP_MOVE)
765 flags |= SWP_MOVE;
766
767 pswp->fl = flags; //restore flags
768
769 pswp->fl |= SWP_NOADJUST;
770 pswp->hwndInsertBehind = hwndAfter;
771 pswp->hwnd = hwnd;
772
773 rc = (MRESULT)0xf;
774 break;
775 }
776 rc = 0;
777 break;
778 }
779
780 case WM_WINDOWPOSCHANGED:
781 {
782 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
783 SWP swpOld = *(pswp + 1);
784 WINDOWPOS wp;
785 HWND hParent = NULLHANDLE;
786 RECTL rect;
787
788 dprintf(("PMFRAME:WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
789
790 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
791 {
792 if(pswp->fl & SWP_RESTORE && win32wnd->getStyle() & WS_MINIMIZE_W) {
793 dprintf(("Restoring minimized window %x", win32wnd->getWindowHandle()));
794 win32wnd->ShowWindow(SW_RESTORE_W);
795 }
796 if(pswp->fl & SWP_SHOW) {
797 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
798 }
799 else
800 if(pswp->fl & SWP_HIDE) {
801 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
802 }
803 if(pswp->fl & SWP_ACTIVATE)
804 {
805 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
806 if(!(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE))
807 {
808 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
809 }
810 }
811 else
812 if(pswp->fl & SWP_DEACTIVATE)
813 {
814 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
815 if(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE)
816 {
817 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)FALSE, (MPARAM)hwnd);
818 }
819 }
820 goto RunDefWndProc;
821 }
822
823 if(pswp->fl & (SWP_MOVE | SWP_SIZE))
824 {
825 if(win32wnd->isChild())
826 {
827 if(win32wnd->getParent()) {
828 hParent = win32wnd->getParent()->getOS2WindowHandle();
829 }
830 else goto PosChangedEnd; //parent has just been destroyed
831 }
832 }
833
834
835 if(win32wnd->getParent()) {
836 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
837 hwnd);
838 }
839 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
840
841 wp.hwnd = win32wnd->getWindowHandle();
842 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
843 {
844 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
845 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
846 if(wndAfter) {
847 wp.hwndInsertAfter = wndAfter->getWindowHandle();
848 RELEASE_WNDOBJ(wndAfter);
849 }
850 else wp.hwndInsertAfter = HWND_TOP_W;
851 }
852
853 if(pswp->fl & SWP_SHOW) {
854 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
855 }
856 else
857 if(pswp->fl & SWP_HIDE) {
858 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
859 }
860
861#ifndef USE_CALCVALIDRECT
862 if((pswp->fl & (SWP_MOVE | SWP_SIZE)))
863 {
864 //CB: todo: use result for WM_CALCVALIDRECTS
865 //Get old client rectangle (for invalidation of frame window parts later on)
866 //Use new window height to calculate the client area
867 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
868
869 //Note: Also updates the new window rectangle
870 win32wnd->MsgFormatFrame(&wp);
871
872 if(win32wnd->isOwnDC()) {
873 setPageXForm(win32wnd, (pDCData)GpiQueryDCData(win32wnd->getOwnDC()));
874 }
875
876 if(win32wnd->CanReceiveSizeMsgs())
877 win32wnd->MsgPosChanged((LPARAM)&wp);
878
879 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
880 {
881 //redraw the frame (to prevent unnecessary client updates)
882 BOOL redrawAll = FALSE;
883
884 dprintf2(("WM_WINDOWPOSCHANGED: redraw frame"));
885 if (win32wnd->getWindowClass())
886 {
887 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
888
889 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
890 redrawAll = TRUE;
891 else
892 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
893 redrawAll = TRUE;
894 }
895 else redrawAll = TRUE;
896
897 if(win32wnd->IsMixMaxStateChanging()) {
898 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
899 redrawAll = TRUE;
900 }
901
902 if (redrawAll)
903 {
904 //CB: redraw all children for now
905 // -> problems with update region if we don't do it
906 // todo: rewrite whole handling
907 WinInvalidateRect(hwnd,NULL,TRUE);
908 }
909 else
910 {
911 HPS hps = WinGetPS(hwnd);
912 RECTL frame,client,arcl[4];
913
914 WinQueryWindowRect(hwnd,&frame);
915
916 //top
917 arcl[0].xLeft = 0;
918 arcl[0].xRight = frame.xRight;
919 arcl[0].yBottom = rect.yTop;
920 arcl[0].yTop = frame.yTop;
921 //right
922 arcl[1].xLeft = rect.xRight;
923 arcl[1].xRight = frame.xRight;
924 arcl[1].yBottom = 0;
925 arcl[1].yTop = frame.yTop;
926 //left
927 arcl[2].xLeft = 0;
928 arcl[2].xRight = rect.xLeft;
929 arcl[2].yBottom = 0;
930 arcl[2].yTop = frame.yTop;
931 //bottom
932 arcl[3].xLeft = 0;
933 arcl[3].xRight = frame.xRight;
934 arcl[3].yBottom = 0;
935 arcl[3].yTop = rect.yBottom;
936
937 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
938
939 WinInvalidateRegion(hwnd,hrgn,FALSE);
940 GpiDestroyRegion(hps,hrgn);
941 WinReleasePS(hps);
942 }
943 }
944 }
945 else
946 {
947#endif //USE_CALCVALIDRECT
948 if(win32wnd->CanReceiveSizeMsgs())
949 win32wnd->MsgPosChanged((LPARAM)&wp);
950#ifndef USE_CALCVALIDRECT
951 }
952#endif
953
954 if(pswp->fl & SWP_ACTIVATE)
955 {
956 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
957 if(!(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE))
958 {
959 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
960 }
961 }
962 else
963 if(pswp->fl & SWP_DEACTIVATE)
964 {
965 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
966 if(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE)
967 {
968 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)FALSE, (MPARAM)hwnd);
969 }
970 }
971
972PosChangedEnd:
973 rc = (MRESULT)FALSE;
974 break;
975 }
976
977 case WM_CALCVALIDRECTS:
978#ifdef USE_CALCVALIDRECT
979 {
980 PRECTL oldRect = (PRECTL)mp1, newRect = oldRect+1;
981 PSWP pswp = (PSWP)mp2;
982 SWP swpOld;
983 WINDOWPOS wp;
984 RECTL newClientRect, oldClientRect;
985 ULONG nccalcret;
986// UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
987 UINT res = 0;
988
989 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
990
991 //Get old position info
992 WinQueryWindowPos(hwnd, &swpOld);
993
994 if(win32wnd->getParent()) {
995 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
996 win32wnd->getParent()->getClientRectPtr()->left,
997 win32wnd->getParent()->getClientRectPtr()->top,
998 hwnd);
999 }
1000 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
1001
1002 wp.hwnd = win32wnd->getWindowHandle();
1003 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1004 {
1005 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1006 if(wndAfter) {
1007 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1008 RELEASE_WNDOBJ(wndAfter);
1009 }
1010 else wp.hwndInsertAfter = HWND_TOP_W;
1011 }
1012
1013 //Get old client rectangle
1014 mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
1015
1016 //Note: Also updates the new window rectangle
1017 nccalcret = win32wnd->MsgFormatFrame(&wp);
1018
1019 //Get new client rectangle
1020 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
1021
1022 if(nccalcret == 0) {
1023 res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
1024 }
1025 else {
1026 if(nccalcret & WVR_ALIGNTOP_W) {
1027 res |= CVR_ALIGNTOP;
1028 }
1029 else
1030 if(nccalcret & WVR_ALIGNBOTTOM_W) {
1031 res |= CVR_ALIGNBOTTOM;
1032 }
1033
1034 if(nccalcret & WVR_ALIGNLEFT_W) {
1035 res |= CVR_ALIGNLEFT;
1036 }
1037 else
1038 if(nccalcret & WVR_ALIGNRIGHT_W) {
1039 res |= CVR_ALIGNRIGHT;
1040 }
1041
1042 if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
1043 res |= CVR_REDRAW;
1044 }
1045 else
1046 if(nccalcret & WVR_VALIDRECTS_W) {
1047 //TODO:
1048 //res = 0;
1049 }
1050 }
1051 if(win32wnd->IsMixMaxStateChanging()) {
1052 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1053 res |= CVR_REDRAW;
1054 }
1055 if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
1056 oldRect->xRight -= oldClientRect.xLeft;
1057 oldRect->yBottom += oldClientRect.yBottom;
1058 newRect->xRight -= newClientRect.xLeft;
1059 newRect->yBottom += newClientRect.yBottom;
1060 }
1061 rc = res;
1062 break;
1063 }
1064#else
1065 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1066 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
1067 break;
1068#endif
1069
1070 case WM_CALCFRAMERECT:
1071 dprintf(("PMFRAME:WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
1072 rc = (MRESULT)TRUE;
1073 break;
1074
1075 case WM_QUERYCTLTYPE:
1076 // This is a frame window
1077 dprintf(("PMFRAME:WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
1078 rc = (MRESULT)CCT_FRAME;
1079 break;
1080
1081#ifdef DEBUG
1082 case WM_QUERYFOCUSCHAIN:
1083 dprintf(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x parent %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), mp2));
1084
1085 RestoreOS2TIB();
1086 rc = pfnFrameWndProc(hwnd, msg, mp1, mp2);
1087 SetWin32TIB();
1088 dprintf(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x parent %x returned %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), mp2, rc));
1089 break;
1090// goto RunDefFrameWndProc;
1091#endif
1092
1093#ifdef DEBUG
1094 case WM_FOCUSCHANGE:
1095 {
1096 HWND hwndFocus = (HWND)mp1;
1097 HWND hwndLoseFocus, hwndGainFocus;
1098 USHORT usSetFocus = SHORT1FROMMP(mp2);
1099 USHORT fsFocusChange = SHORT2FROMMP(mp2);
1100
1101 dprintf(("PMFRAME:WM_FOCUSCHANGE %x %x %x %x", win32wnd->getWindowHandle(), hwndFocus, usSetFocus, fsFocusChange));
1102 goto RunDefFrameWndProc;
1103 }
1104#endif
1105
1106 case WM_ACTIVATE:
1107 {
1108 HWND hwndTitle;
1109 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
1110
1111 dprintf(("PMFRAME: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2));
1112 if (win32wnd->IsWindowCreated())
1113 {
1114 WinSendMsg(WinWindowFromID(hwnd,FID_CLIENT),WM_ACTIVATE,mp1,mp2);
1115 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1116
1117 //CB: show owner behind the dialog
1118 if (win32wnd->IsModalDialog())
1119 {
1120 if(win32wnd->getOwner()) {
1121 Win32BaseWindow *topOwner = Win32BaseWindow::GetWindowFromHandle(win32wnd->getOwner()->GetTopParent());
1122
1123 if (topOwner) {
1124 WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
1125 RELEASE_WNDOBJ(topOwner);
1126 }
1127 }
1128 }
1129 }
1130 else
1131 {
1132 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1133 }
1134 rc = 0;
1135 break;
1136 }
1137
1138 case WM_ENABLE:
1139 dprintf(("PMFRAME: WM_ENABLE %x", hwnd));
1140 win32wnd->MsgEnable(SHORT1FROMMP(mp1));
1141 break;
1142
1143 case WM_SHOW:
1144 dprintf(("PMFRAME: WM_SHOW %x %d", hwnd, mp1));
1145 //show client window
1146 WinShowWindow(win32wnd->getOS2WindowHandle(), (BOOL)mp1);
1147 break;
1148
1149 case WM_SETFOCUS:
1150 {
1151 dprintf(("PMFRAME: WM_SETFOCUS %x %x", win32wnd->getWindowHandle(), hwnd));
1152 goto RunDefFrameWndProc;
1153 }
1154
1155 case WM_QUERYTRACKINFO:
1156 {
1157 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
1158
1159 dprintf(("PMFRAME:WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
1160 trackInfo->cxBorder = 4;
1161 trackInfo->cyBorder = 4;
1162 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
1163 rc = (MRESULT)TRUE;
1164 break;
1165 }
1166
1167 case WM_QUERYBORDERSIZE:
1168 {
1169 PWPOINT size = (PWPOINT)mp1;
1170
1171 dprintf(("PMFRAME:WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
1172
1173 size->x = 0;
1174 size->y = 0;
1175 rc = (MRESULT)TRUE;
1176 break;
1177 }
1178
1179 case WM_QUERYFRAMEINFO:
1180 dprintf(("PMFRAME:WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
1181 goto RunDefFrameWndProc;
1182
1183 case WM_FORMATFRAME:
1184 dprintf(("PMFRAME:WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
1185 break;
1186
1187 case WM_ADJUSTFRAMEPOS:
1188 {
1189 PSWP pswp = (PSWP)mp1;
1190
1191 dprintf(("PMFRAME:WM_ADJUSTFRAMEPOS %x %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
1192 goto RunDefFrameWndProc;
1193 }
1194
1195 case WM_OWNERPOSCHANGE:
1196 {
1197 PSWP pswp = (PSWP)mp1;
1198
1199 dprintf(("PMFRAME:WM_OWNERPOSCHANGE %x %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
1200 goto RunDefFrameWndProc;
1201 }
1202
1203 case WM_MINMAXFRAME:
1204 {
1205 PSWP swp = (PSWP)mp1;
1206
1207 if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
1208
1209 dprintf(("PMFRAME:WM_MINMAXFRAME %x",hwnd));
1210 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1211 {
1212 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
1213
1214 RECT rect;
1215
1216 rect.left = rect.top = rect.right = rect.bottom = 0;
1217 win32wnd->AdjustMaximizedRect(&rect);
1218 swp->x += rect.left;
1219 swp->cx += rect.right-rect.left;
1220 swp->y -= rect.bottom;
1221 swp->cy += rect.bottom-rect.top;
1222 }
1223 else
1224 if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
1225 {
1226 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
1227 }
1228 else
1229 if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
1230 {
1231 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
1232 }
1233 goto RunDefWndProc;
1234 }
1235
1236 case WM_UPDATEFRAME:
1237 dprintf(("PMFRAME:WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
1238 goto RunDefFrameWndProc;
1239
1240 default:
1241 goto RunDefFrameWndProc;
1242 }
1243 RestoreOS2TIB();
1244 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1245 return (MRESULT)rc;
1246
1247RunDefFrameWndProc:
1248 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1249 RestoreOS2TIB();
1250 return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1251
1252RunDefWndProc:
1253 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1254 RestoreOS2TIB();
1255 //calling WinDefWindowProc here breaks Opera hotlist window (WM_ADJUSTWINDOWPOS)
1256// return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1257 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
1258}
1259//******************************************************************************
1260//TODO: Quickly moving a window two times doesn't force a repaint (1st time)
1261//******************************************************************************
1262VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
1263{
1264 TRACKINFO track;
1265 RECTL rcl;
1266 PRECT pWindowRect, pClientRect;
1267 HWND hwndTracking;
1268 LONG parentHeight, parentWidth;
1269
1270 dprintf(("FrameTrackFrame: %x %x", win32wnd->getWindowHandle(), flags));
1271 track.cxBorder = 4;
1272 track.cyBorder = 4; /* 4 pel wide lines used for rectangle */
1273 track.cxGrid = 1;
1274 track.cyGrid = 1; /* smooth tracking with mouse */
1275 track.cxKeyboard = 8;
1276 track.cyKeyboard = 8; /* faster tracking using cursor keys */
1277
1278 pWindowRect = win32wnd->getWindowRect();
1279 if(win32wnd->getParent()) {
1280 parentHeight = win32wnd->getParent()->getClientHeight();
1281 parentWidth = win32wnd->getParent()->getClientWidth();
1282 hwndTracking = win32wnd->getParent()->getOS2WindowHandle();
1283 }
1284 else {
1285 parentHeight = OSLibQueryScreenHeight();
1286 parentWidth = OSLibQueryScreenWidth();
1287 hwndTracking = HWND_DESKTOP;
1288 }
1289
1290 mapWin32ToOS2Rect(parentHeight, pWindowRect, (PRECTLOS2)&track.rclTrack);
1291 rcl = track.rclTrack;
1292 WinQueryWindowRect(hwndTracking, &track.rclBoundary);
1293
1294 track.ptlMinTrackSize.x = 10;
1295 track.ptlMinTrackSize.y = 10; /* set smallest allowed size of rectangle */
1296 track.ptlMaxTrackSize.x = parentWidth;
1297 track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */
1298
1299 win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize);
1300
1301 track.fs = flags;
1302
1303 if(WinTrackRect(hwndTracking, NULL, &track) )
1304 {
1305 /* if successful copy final position back */
1306 if(!WinEqualRect(0, &rcl, &track.rclTrack)) {
1307 dprintf(("FrameTrackFrame: new (os/2) window rect: (%d,%d)(%d,%d)", track.rclTrack.xLeft, track.rclTrack.yBottom, track.rclTrack.xRight - track.rclTrack.xLeft, track.rclTrack.yTop - track.rclTrack.yBottom));
1308 if(flags == TF_MOVE) {
1309 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
1310 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1311 0, 0, SWP_MOVE);
1312 }
1313 else {
1314 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
1315 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1316 track.rclTrack.xRight - track.rclTrack.xLeft,
1317 track.rclTrack.yTop - track.rclTrack.yBottom,
1318 SWP_SIZE|SWP_MOVE);
1319 }
1320 }
1321 return;
1322 }
1323 return;
1324}
1325//******************************************************************************
1326//******************************************************************************
Note: See TracBrowser for help on using the repository browser.