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

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

Support full window drag for Odin windows

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