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

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

ported the Wine MDI control + some menu fixes

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