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

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

some minor log msg updates

File size: 51.5 KB
Line 
1/* $Id: pmwindow.cpp,v 1.142 2001-08-02 14:50:42 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_HSCROLL:
570 case WM_VSCROLL:
571 dprintf(("OS2: %s %x %x %x", (msg == WM_HSCROLL) ? "WM_HSCROLL" : "WM_VSCROLL", win32wnd->getWindowHandle(), mp1, mp2));
572 win32wnd->DispatchMsgA(pWinMsg);
573 break;
574
575 case WM_DDE_INITIATE:
576 case WM_DDE_INITIATEACK:
577 case WM_DDE_REQUEST:
578 case WM_DDE_ACK:
579 case WM_DDE_DATA:
580 case WM_DDE_ADVISE:
581 case WM_DDE_UNADVISE:
582 case WM_DDE_POKE:
583 case WM_DDE_EXECUTE:
584 case WM_DDE_TERMINATE:
585 dprintf(("OS2: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
586 goto RunDefWndProc;
587
588 case WM_INITMENU:
589 case WM_MENUSELECT:
590 case WM_MENUEND:
591 case WM_NEXTMENU:
592 case WM_SYSCOLORCHANGE:
593 case WM_SYSVALUECHANGED:
594 case WM_SETSELECTION:
595 case WM_PPAINT:
596 case WM_PSETFOCUS:
597 case WM_PSYSCOLORCHANGE:
598 case WM_PSIZE:
599 case WM_PACTIVATE:
600 case WM_PCONTROL:
601 case WM_HELP:
602 case WM_APPTERMINATENOTIFY:
603 case WM_PRESPARAMCHANGED:
604 case WM_DRAWITEM:
605 case WM_MEASUREITEM:
606 case WM_CONTROLPOINTER:
607 case WM_QUERYDLGCODE:
608 case WM_SUBSTITUTESTRING:
609 case WM_MATCHMNEMONIC:
610 case WM_SAVEAPPLICATION:
611 case WM_SEMANTICEVENT:
612 default:
613 dprintf2(("OS2: RunDefWndProc hwnd %x msg %x mp1 %x mp2 %x", hwnd, msg, mp1, mp2));
614 goto RunDefWndProc;
615 }
616 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
617 RestoreOS2TIB();
618 return (MRESULT)rc;
619
620RunDefWndProc:
621// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
622 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
623 RestoreOS2TIB();
624 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
625} /* End of Win32WindowProc */
626//******************************************************************************
627//******************************************************************************
628MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
629{
630 POSTMSG_PACKET *postmsg;
631 OSLIBPOINT point, ClientPoint;
632 Win32BaseWindow *win32wnd;
633 TEB *teb;
634 MRESULT rc = 0;
635 MSG winMsg, *pWinMsg;
636
637 //Restore our FS selector
638 SetWin32TIB();
639
640 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
641 teb = GetThreadTEB();
642 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
643
644 if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
645 dprintf(("PMFRAME: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
646 goto RunDefFrameWndProc;
647 }
648//// if(teb->o.odin.fIgnoreMsgs) {
649//// goto RunDefWndProc;
650//// }
651
652 if((teb->o.odin.msgstate & 1) == 0)
653 {//message that was sent directly to our window proc handler; translate it here
654 QMSG qmsg;
655
656 qmsg.msg = msg;
657 qmsg.hwnd = hwnd;
658 qmsg.mp1 = mp1;
659 qmsg.mp2 = mp2;
660 qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
661 WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
662 qmsg.reserved = 0;
663
664 if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
665 {//message was not translated
666 memset(&winMsg, 0, sizeof(MSG));
667 }
668 pWinMsg = &winMsg;
669 }
670 else {
671 pWinMsg = &teb->o.odin.msg;
672 teb->o.odin.msgstate++;
673 }
674 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
675
676 switch( msg )
677 {
678 case WM_CREATE:
679 {
680 //WM_CREATE handled during client window creation
681 dprintf(("PMFRAME: WM_CREATE %x"));
682 goto RunDefFrameWndProc;
683 }
684
685 case WM_PAINT:
686 {
687 RECTL rectl;
688
689 HPS hps = WinBeginPaint(hwnd, NULL, &rectl);
690 dprintf(("PMFRAME: WM_PAINT %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
691
692 if(win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
693 rectl.yBottom != rectl.yTop))
694 {
695 PRECT pClient = win32wnd->getClientRectPtr();
696 PRECT pWindow = win32wnd->getWindowRect();
697
698 if(!(pClient->left == 0 && pClient->top == 0 &&
699 win32wnd->getClientHeight() == win32wnd->getWindowHeight() &&
700 win32wnd->getClientWidth() == win32wnd->getWindowWidth()))
701 {
702 RECT rectUpdate;
703
704 mapOS2ToWin32Rect(win32wnd->getWindowHeight(), (PRECTLOS2)&rectl, &rectUpdate);
705 win32wnd->MsgNCPaint(&rectUpdate);
706 }
707 }
708 WinEndPaint(hps);
709 break;
710 }
711
712 case WM_ERASEBACKGROUND:
713 {
714 dprintf(("PMFRAME:WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
715 rc = (MRESULT)FALSE;
716 break;
717 }
718
719 //**************************************************************************
720 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
721 //**************************************************************************
722
723 case WM_BUTTON1DOWN:
724 case WM_BUTTON1UP:
725 case WM_BUTTON1DBLCLK:
726 case WM_BUTTON2DOWN:
727 case WM_BUTTON2UP:
728 case WM_BUTTON2DBLCLK:
729 case WM_BUTTON3DOWN:
730 case WM_BUTTON3UP:
731 case WM_BUTTON3DBLCLK:
732 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
733 RELEASE_WNDOBJ(win32wnd);
734 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
735 }
736 if(win32wnd)
737 win32wnd->MsgButton(pWinMsg);
738
739 rc = (MRESULT)TRUE;
740 break;
741
742 case WM_BUTTON2MOTIONSTART:
743 case WM_BUTTON2MOTIONEND:
744 case WM_BUTTON2CLICK:
745 case WM_BUTTON1MOTIONSTART:
746 case WM_BUTTON1MOTIONEND:
747 case WM_BUTTON1CLICK:
748 case WM_BUTTON3MOTIONSTART:
749 case WM_BUTTON3MOTIONEND:
750 case WM_BUTTON3CLICK:
751 rc = (MRESULT)TRUE;
752 break;
753
754 case WM_MOUSEMOVE:
755 {
756 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
757 RELEASE_WNDOBJ(win32wnd);
758 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
759 }
760 if(win32wnd)
761 win32wnd->MsgMouseMove(pWinMsg);
762 break;
763 }
764
765 case WM_ADJUSTWINDOWPOS:
766 {
767 PSWP pswp = (PSWP)mp1;
768 SWP swpOld;
769 WINDOWPOS wp,wpOld;
770 HWND hParent = NULLHANDLE, hwndAfter;
771
772 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));
773
774 if(win32wnd->IsParentChanging()) {
775 rc = 0;
776 break;
777 }
778
779 if(pswp->fl & SWP_NOADJUST) {
780 //ignore weird messages (TODO: why are they sent?)
781 break;
782 }
783 //CB: show dialog in front of owner
784 if (win32wnd->IsModalDialogOwner())
785 {
786 dprintf(("win32wnd->IsModalDialogOwner %x", win32wnd->getWindowHandle()));
787 pswp->fl |= SWP_ZORDER;
788 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
789 if (pswp->fl & SWP_ACTIVATE)
790 {
791 pswp->fl &= ~SWP_ACTIVATE;
792 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
793 }
794 }
795
796 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
797 goto RunDefWndProc;
798
799 if(!win32wnd->CanReceiveSizeMsgs())
800 break;
801
802 WinQueryWindowPos(hwnd, &swpOld);
803 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
804 if (win32wnd->isChild()) {
805 if(win32wnd->getParent()) {
806 hParent = win32wnd->getParent()->getOS2WindowHandle();
807 }
808 else goto RunDefWndProc;
809 }
810 }
811 hwndAfter = pswp->hwndInsertBehind;
812 if(win32wnd->getParent()) {
813 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(), hwnd);
814 }
815 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
816
817 wp.hwnd = win32wnd->getWindowHandle();
818 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
819 {
820 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
821 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
822 if(wndAfter) {
823 wp.hwndInsertAfter = wndAfter->getWindowHandle();
824 RELEASE_WNDOBJ(wndAfter);
825 }
826 else wp.hwndInsertAfter = HWND_TOP_W;
827 }
828
829 wpOld = wp;
830 win32wnd->MsgPosChanging((LPARAM)&wp);
831
832 if(win32wnd->getOldStyle() != win32wnd->getStyle()) {
833 OSLibSetWindowStyle(win32wnd->getOS2FrameWindowHandle(), win32wnd->getOS2WindowHandle(), win32wnd->getStyle(), win32wnd->getExStyle());
834 if(fOS2Look) {
835 DWORD dwOldStyle = win32wnd->getOldStyle();
836 DWORD dwStyle = win32wnd->getStyle();
837
838 if((dwOldStyle & WS_MINIMIZE_W) && !(dwStyle & WS_MINIMIZE_W)) {
839 //SC_RESTORE -> SC_MINIMIZE
840 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_RESTORE, SC_MINIMIZE, hbmFrameMenu[0]);
841 }
842 else
843 if((dwOldStyle & WS_MAXIMIZE_W) && !(dwStyle & WS_MAXIMIZE_W)) {
844 //SC_RESTORE -> SC_MAXIMIZE
845 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_RESTORE, SC_MAXIMIZE, hbmFrameMenu[1]);
846 }
847 else
848 if(!(dwOldStyle & WS_MINIMIZE_W) && (dwStyle & WS_MINIMIZE_W)) {
849 //SC_MINIMIZE -> SC_RESTORE
850 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_MINIMIZE, SC_RESTORE, hbmFrameMenu[2]);
851 }
852 else
853 if(!(dwOldStyle & WS_MAXIMIZE_W) && (dwStyle & WS_MAXIMIZE_W)) {
854 //SC_MAXIMIZE -> SC_RESTORE
855 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[2]);
856 }
857 }
858 }
859
860 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
861 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
862 {
863 ULONG flags = pswp->fl; //make a backup copy; OSLibMapWINDOWPOStoSWP will modify it
864
865 dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
866 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
867
868 if(win32wnd->getParent()) {
869 OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getClientHeight(),
870 hwnd);
871 }
872 else OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), hwnd);
873
874 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
875
876 //OSLibMapWINDOWPOStoSWP can add flags, but we must not let it remove flags!
877 if(pswp->fl & SWP_SIZE)
878 flags |= SWP_SIZE;
879
880 if(pswp->fl & SWP_MOVE)
881 flags |= SWP_MOVE;
882
883 pswp->fl = flags; //restore flags
884
885 pswp->fl |= SWP_NOADJUST;
886 pswp->hwndInsertBehind = hwndAfter;
887 pswp->hwnd = hwnd;
888
889 rc = (MRESULT)0xf;
890 break;
891 }
892 rc = 0;
893 break;
894 }
895
896 case WM_WINDOWPOSCHANGED:
897 {
898 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
899 SWP swpOld = *(pswp + 1);
900 WINDOWPOS wp;
901 HWND hParent = NULLHANDLE;
902 RECTL rect;
903
904 dprintf(("PMFRAME:WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
905 if(win32wnd->IsParentChanging()) {
906 goto PosChangedEnd;
907 }
908
909 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
910 {
911 if(pswp->fl & SWP_RESTORE && win32wnd->getStyle() & WS_MINIMIZE_W) {
912 dprintf(("Restoring minimized window %x", win32wnd->getWindowHandle()));
913 win32wnd->ShowWindow(SW_RESTORE_W);
914 }
915 if(pswp->fl & SWP_SHOW) {
916 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
917 }
918 else
919 if(pswp->fl & SWP_HIDE) {
920 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
921 }
922 if(pswp->fl & SWP_ACTIVATE)
923 {
924 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
925 if(!(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE))
926 {
927 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
928 if(fOS2Look) {
929 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, MPFROMSHORT(TRUE), 0);
930 }
931 }
932 }
933 else
934 if(pswp->fl & SWP_DEACTIVATE)
935 {
936 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
937 if(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE)
938 {
939 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)FALSE, (MPARAM)hwnd);
940 if(fOS2Look) {
941 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, MPFROMSHORT(FALSE), 0);
942 }
943 }
944 }
945 goto RunDefWndProc;
946 }
947
948 if(pswp->fl & (SWP_MOVE | SWP_SIZE))
949 {
950 if(win32wnd->isChild())
951 {
952 if(win32wnd->getParent()) {
953 hParent = win32wnd->getParent()->getOS2WindowHandle();
954 }
955 else goto PosChangedEnd; //parent has just been destroyed
956 }
957 }
958
959
960 if(win32wnd->getParent()) {
961 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
962 hwnd);
963 }
964 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
965
966 wp.hwnd = win32wnd->getWindowHandle();
967 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
968 {
969 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
970 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
971 if(wndAfter) {
972 wp.hwndInsertAfter = wndAfter->getWindowHandle();
973 RELEASE_WNDOBJ(wndAfter);
974 }
975 else wp.hwndInsertAfter = HWND_TOP_W;
976 }
977
978 if(pswp->fl & SWP_SHOW) {
979 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
980 }
981 else
982 if(pswp->fl & SWP_HIDE) {
983 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
984 }
985
986#ifndef USE_CALCVALIDRECT
987 if((pswp->fl & (SWP_MOVE | SWP_SIZE)))
988 {
989 //CB: todo: use result for WM_CALCVALIDRECTS
990 //Get old client rectangle (for invalidation of frame window parts later on)
991 //Use new window height to calculate the client area
992 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
993
994 //Note: Also updates the new window rectangle
995 win32wnd->MsgFormatFrame(&wp);
996
997 if(win32wnd->isOwnDC()) {
998 setPageXForm(win32wnd, (pDCData)GpiQueryDCData(win32wnd->getOwnDC()));
999 }
1000
1001 if(win32wnd->CanReceiveSizeMsgs())
1002 win32wnd->MsgPosChanged((LPARAM)&wp);
1003
1004 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
1005 {
1006 //redraw the frame (to prevent unnecessary client updates)
1007 BOOL redrawAll = FALSE;
1008
1009 dprintf2(("WM_WINDOWPOSCHANGED: redraw frame"));
1010 if (win32wnd->getWindowClass())
1011 {
1012 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
1013
1014 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
1015 redrawAll = TRUE;
1016 else
1017 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
1018 redrawAll = TRUE;
1019 }
1020 else redrawAll = TRUE;
1021
1022 if(win32wnd->IsMixMaxStateChanging()) {
1023 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1024 redrawAll = TRUE;
1025 }
1026
1027 if (redrawAll)
1028 {
1029 //CB: redraw all children for now
1030 // -> problems with update region if we don't do it
1031 // todo: rewrite whole handling
1032 WinInvalidateRect(hwnd,NULL,TRUE);
1033 }
1034 else
1035 {
1036 HPS hps = WinGetPS(hwnd);
1037 RECTL frame,client,arcl[4];
1038
1039 WinQueryWindowRect(hwnd,&frame);
1040
1041 //top
1042 arcl[0].xLeft = 0;
1043 arcl[0].xRight = frame.xRight;
1044 arcl[0].yBottom = rect.yTop;
1045 arcl[0].yTop = frame.yTop;
1046 //right
1047 arcl[1].xLeft = rect.xRight;
1048 arcl[1].xRight = frame.xRight;
1049 arcl[1].yBottom = 0;
1050 arcl[1].yTop = frame.yTop;
1051 //left
1052 arcl[2].xLeft = 0;
1053 arcl[2].xRight = rect.xLeft;
1054 arcl[2].yBottom = 0;
1055 arcl[2].yTop = frame.yTop;
1056 //bottom
1057 arcl[3].xLeft = 0;
1058 arcl[3].xRight = frame.xRight;
1059 arcl[3].yBottom = 0;
1060 arcl[3].yTop = rect.yBottom;
1061
1062 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
1063
1064 WinInvalidateRegion(hwnd,hrgn,FALSE);
1065 GpiDestroyRegion(hps,hrgn);
1066 WinReleasePS(hps);
1067 }
1068 }
1069 }
1070 else
1071 {
1072#endif //USE_CALCVALIDRECT
1073 if(win32wnd->CanReceiveSizeMsgs())
1074 win32wnd->MsgPosChanged((LPARAM)&wp);
1075#ifndef USE_CALCVALIDRECT
1076 }
1077#endif
1078
1079 if(pswp->fl & SWP_ACTIVATE)
1080 {
1081 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
1082 if(!(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE))
1083 {
1084 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)TRUE, (MPARAM)hwnd);
1085 if(fOS2Look) {
1086 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, MPFROMSHORT(TRUE), 0);
1087 }
1088 }
1089 }
1090 else
1091 if(pswp->fl & SWP_DEACTIVATE)
1092 {
1093 //Only send PM WM_ACTIVATE to top-level windows (frame windows)
1094 if(WinQueryWindowULong(WinWindowFromID(hwnd,FID_CLIENT), OFFSET_WIN32FLAGS) & WINDOWFLAG_ACTIVE)
1095 {
1096 WinSendMsg(hwnd, WM_ACTIVATE, (MPARAM)FALSE, (MPARAM)hwnd);
1097 if(fOS2Look) {
1098 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, MPFROMSHORT(FALSE), 0);
1099 }
1100 }
1101 }
1102
1103PosChangedEnd:
1104 rc = (MRESULT)FALSE;
1105 break;
1106 }
1107
1108 case WM_CALCVALIDRECTS:
1109#ifdef USE_CALCVALIDRECT
1110 {
1111 PRECTL oldRect = (PRECTL)mp1, newRect = oldRect+1;
1112 PSWP pswp = (PSWP)mp2;
1113 SWP swpOld;
1114 WINDOWPOS wp;
1115 RECTL newClientRect, oldClientRect;
1116 ULONG nccalcret;
1117// UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
1118 UINT res = 0;
1119
1120 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1121
1122 //Get old position info
1123 WinQueryWindowPos(hwnd, &swpOld);
1124
1125 if(win32wnd->getParent()) {
1126 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1127 win32wnd->getParent()->getClientRectPtr()->left,
1128 win32wnd->getParent()->getClientRectPtr()->top,
1129 hwnd);
1130 }
1131 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
1132
1133 wp.hwnd = win32wnd->getWindowHandle();
1134 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1135 {
1136 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1137 if(wndAfter) {
1138 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1139 RELEASE_WNDOBJ(wndAfter);
1140 }
1141 else wp.hwndInsertAfter = HWND_TOP_W;
1142 }
1143
1144 //Get old client rectangle
1145 mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
1146
1147 //Note: Also updates the new window rectangle
1148 nccalcret = win32wnd->MsgFormatFrame(&wp);
1149
1150 //Get new client rectangle
1151 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
1152
1153 if(nccalcret == 0) {
1154 res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
1155 }
1156 else {
1157 if(nccalcret & WVR_ALIGNTOP_W) {
1158 res |= CVR_ALIGNTOP;
1159 }
1160 else
1161 if(nccalcret & WVR_ALIGNBOTTOM_W) {
1162 res |= CVR_ALIGNBOTTOM;
1163 }
1164
1165 if(nccalcret & WVR_ALIGNLEFT_W) {
1166 res |= CVR_ALIGNLEFT;
1167 }
1168 else
1169 if(nccalcret & WVR_ALIGNRIGHT_W) {
1170 res |= CVR_ALIGNRIGHT;
1171 }
1172
1173 if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
1174 res |= CVR_REDRAW;
1175 }
1176 else
1177 if(nccalcret & WVR_VALIDRECTS_W) {
1178 //TODO:
1179 //res = 0;
1180 }
1181 }
1182 if(win32wnd->IsMixMaxStateChanging()) {
1183 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1184 res |= CVR_REDRAW;
1185 }
1186 if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
1187 oldRect->xRight -= oldClientRect.xLeft;
1188 oldRect->yBottom += oldClientRect.yBottom;
1189 newRect->xRight -= newClientRect.xLeft;
1190 newRect->yBottom += newClientRect.yBottom;
1191 }
1192 rc = res;
1193 break;
1194 }
1195#else
1196 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1197 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
1198 break;
1199#endif
1200
1201 case WM_CALCFRAMERECT:
1202 dprintf(("PMFRAME:WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
1203 rc = (MRESULT)TRUE;
1204 break;
1205
1206 case WM_QUERYCTLTYPE:
1207 // This is a frame window
1208 dprintf(("PMFRAME:WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
1209 rc = (MRESULT)CCT_FRAME;
1210 break;
1211
1212#ifdef DEBUG
1213 case WM_QUERYFOCUSCHAIN:
1214 dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x parent %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), mp2));
1215
1216 RestoreOS2TIB();
1217 rc = pfnFrameWndProc(hwnd, msg, mp1, mp2);
1218 SetWin32TIB();
1219 dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x parent %x returned %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), mp2, rc));
1220 break;
1221// goto RunDefFrameWndProc;
1222#endif
1223
1224#ifdef DEBUG
1225 case WM_FOCUSCHANGE:
1226 {
1227 HWND hwndFocus = (HWND)mp1;
1228 HWND hwndLoseFocus, hwndGainFocus;
1229 USHORT usSetFocus = SHORT1FROMMP(mp2);
1230 USHORT fsFocusChange = SHORT2FROMMP(mp2);
1231
1232 dprintf(("PMFRAME:WM_FOCUSCHANGE %x %x %x %x", win32wnd->getWindowHandle(), hwndFocus, usSetFocus, fsFocusChange));
1233 goto RunDefFrameWndProc;
1234 }
1235#endif
1236
1237 case WM_ACTIVATE:
1238 {
1239 HWND hwndTitle;
1240 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
1241
1242 dprintf(("PMFRAME: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2));
1243 if (win32wnd->IsWindowCreated())
1244 {
1245 WinSendMsg(WinWindowFromID(hwnd,FID_CLIENT),WM_ACTIVATE,mp1,mp2);
1246 if(fOS2Look) {
1247 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, mp1, 0);
1248 }
1249 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1250
1251 //CB: show owner behind the dialog
1252 if (win32wnd->IsModalDialog())
1253 {
1254 if(win32wnd->getOwner()) {
1255 Win32BaseWindow *topOwner = Win32BaseWindow::GetWindowFromHandle(win32wnd->getOwner()->GetTopParent());
1256
1257 if (topOwner) {
1258 WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
1259 RELEASE_WNDOBJ(topOwner);
1260 }
1261 }
1262 }
1263 }
1264 else
1265 {
1266 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1267 }
1268 rc = 0;
1269 break;
1270 }
1271
1272 case WM_ENABLE:
1273 dprintf(("PMFRAME: WM_ENABLE %x", hwnd));
1274 win32wnd->MsgEnable(SHORT1FROMMP(mp1));
1275 break;
1276
1277 case WM_SHOW:
1278 dprintf(("PMFRAME: WM_SHOW %x %d", hwnd, mp1));
1279 //show client window
1280 WinShowWindow(win32wnd->getOS2WindowHandle(), (BOOL)mp1);
1281 break;
1282
1283 case WM_SETFOCUS:
1284 {
1285 dprintf(("PMFRAME: WM_SETFOCUS %x %x", win32wnd->getWindowHandle(), hwnd));
1286 goto RunDefFrameWndProc;
1287 }
1288
1289 case WM_QUERYTRACKINFO:
1290 {
1291 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
1292
1293 dprintf(("PMFRAME:WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
1294 trackInfo->cxBorder = 4;
1295 trackInfo->cyBorder = 4;
1296 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
1297 rc = (MRESULT)TRUE;
1298 break;
1299 }
1300
1301 case WM_QUERYBORDERSIZE:
1302 {
1303 PWPOINT size = (PWPOINT)mp1;
1304
1305 dprintf(("PMFRAME:WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
1306
1307 size->x = 0;
1308 size->y = 0;
1309 rc = (MRESULT)TRUE;
1310 break;
1311 }
1312
1313 case WM_QUERYFRAMEINFO:
1314 dprintf(("PMFRAME:WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
1315 goto RunDefFrameWndProc;
1316
1317 case WM_FORMATFRAME:
1318 dprintf(("PMFRAME:WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
1319 break;
1320
1321 case WM_ADJUSTFRAMEPOS:
1322 {
1323 PSWP pswp = (PSWP)mp1;
1324
1325 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));
1326 goto RunDefFrameWndProc;
1327 }
1328
1329 case WM_OWNERPOSCHANGE:
1330 {
1331 PSWP pswp = (PSWP)mp1;
1332
1333 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));
1334 goto RunDefFrameWndProc;
1335 }
1336
1337 case WM_MINMAXFRAME:
1338 {
1339 PSWP swp = (PSWP)mp1;
1340
1341 if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
1342
1343 dprintf(("PMFRAME:WM_MINMAXFRAME %x",hwnd));
1344 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1345 {
1346 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
1347
1348 RECT rect;
1349
1350 rect.left = rect.top = rect.right = rect.bottom = 0;
1351 win32wnd->AdjustMaximizedRect(&rect);
1352 swp->x += rect.left;
1353 swp->cx += rect.right-rect.left;
1354 swp->y -= rect.bottom;
1355 swp->cy += rect.bottom-rect.top;
1356 }
1357 else
1358 if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
1359 {
1360 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
1361 }
1362 else
1363 if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
1364 {
1365 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
1366 }
1367 goto RunDefWndProc;
1368 }
1369
1370 case WM_UPDATEFRAME:
1371 dprintf(("PMFRAME:WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
1372 goto RunDefFrameWndProc;
1373
1374 case WM_TRACKFRAME:
1375 dprintf(("PMFRAME: WM_TRACKFRAME %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
1376 if(fOS2Look) {//sent by titlebar control
1377 FrameTrackFrame(win32wnd, TF_MOVE);
1378 }
1379 rc = 0;
1380 break;
1381
1382 case WM_SYSCOMMAND:
1383 dprintf(("PMFRAME: WM_SYSCOMMAND %x", win32wnd->getWindowHandle()));
1384 win32wnd->DispatchMsgA(pWinMsg);
1385 break;
1386
1387 case WM_DDE_INITIATE:
1388 case WM_DDE_INITIATEACK:
1389 case WM_DDE_REQUEST:
1390 case WM_DDE_ACK:
1391 case WM_DDE_DATA:
1392 case WM_DDE_ADVISE:
1393 case WM_DDE_UNADVISE:
1394 case WM_DDE_POKE:
1395 case WM_DDE_EXECUTE:
1396 case WM_DDE_TERMINATE:
1397 dprintf(("PMFRAME: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
1398 break;
1399
1400 default:
1401 goto RunDefFrameWndProc;
1402 }
1403 RestoreOS2TIB();
1404 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1405 return (MRESULT)rc;
1406
1407RunDefFrameWndProc:
1408 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1409 RestoreOS2TIB();
1410 return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1411
1412RunDefWndProc:
1413 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1414 RestoreOS2TIB();
1415 //calling WinDefWindowProc here breaks Opera hotlist window (WM_ADJUSTWINDOWPOS)
1416// return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1417 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
1418}
1419//******************************************************************************
1420//TODO: Quickly moving a window two times doesn't force a repaint (1st time)
1421//
1422//
1423BOOL (APIENTRY *WinTrackWindow)(HWND hwndTrack, PTRACKINFO pti) = NULL;
1424//
1425//******************************************************************************
1426VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
1427{
1428 TRACKINFO track;
1429 RECTL rcl;
1430 PRECT pWindowRect, pClientRect;
1431 HWND hwndTracking;
1432 LONG parentHeight, parentWidth;
1433 static BOOL fInit = FALSE;
1434 APIRET rc;
1435 BOOL ret;
1436
1437 if(!fInit) {
1438 HMODULE hModule;
1439 char buf[CCHMAXPATH];
1440 rc = DosLoadModule(buf, sizeof(buf), "PMMERGE", &hModule);
1441 rc = DosQueryProcAddr(hModule, 5466, NULL, (PFN *)&WinTrackWindow);
1442 if(rc) WinTrackWindow = NULL;
1443 fInit = TRUE;
1444 }
1445 dprintf(("FrameTrackFrame: %x %x", win32wnd->getWindowHandle(), flags));
1446 track.cxBorder = 4;
1447 track.cyBorder = 4; /* 4 pel wide lines used for rectangle */
1448 track.cxGrid = 1;
1449 track.cyGrid = 1; /* smooth tracking with mouse */
1450 track.cxKeyboard = 8;
1451 track.cyKeyboard = 8; /* faster tracking using cursor keys */
1452
1453 pWindowRect = win32wnd->getWindowRect();
1454 if(win32wnd->getParent()) {
1455 parentHeight = win32wnd->getParent()->getClientHeight();
1456 parentWidth = win32wnd->getParent()->getClientWidth();
1457 hwndTracking = win32wnd->getParent()->getOS2WindowHandle();
1458 }
1459 else {
1460 parentHeight = OSLibQueryScreenHeight();
1461 parentWidth = OSLibQueryScreenWidth();
1462 hwndTracking = HWND_DESKTOP;
1463 }
1464
1465 mapWin32ToOS2Rect(parentHeight, pWindowRect, (PRECTLOS2)&track.rclTrack);
1466 rcl = track.rclTrack;
1467 WinQueryWindowRect(hwndTracking, &track.rclBoundary);
1468
1469 track.ptlMinTrackSize.x = 10;
1470 track.ptlMinTrackSize.y = 10; /* set smallest allowed size of rectangle */
1471 track.ptlMaxTrackSize.x = parentWidth;
1472 track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */
1473
1474 win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize);
1475
1476 track.fs = flags;
1477
1478 BOOL fDynamicDrag = WinQuerySysValue(HWND_DESKTOP, SVOS_DYNAMICDRAG);
1479
1480 SEL sel = RestoreOS2FS();
1481 if(fDynamicDrag && WinTrackWindow) {
1482 ret = WinTrackWindow(win32wnd->getOS2FrameWindowHandle(), &track);
1483 }
1484 else ret = WinTrackRect(hwndTracking, NULL, &track);
1485 SetFS(sel);
1486
1487 if(ret) {
1488 /* if successful copy final position back */
1489 if(!WinEqualRect(0, &rcl, &track.rclTrack)) {
1490 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));
1491 if(flags == TF_MOVE) {
1492 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
1493 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1494 0, 0, SWP_MOVE);
1495 }
1496 else {
1497 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
1498 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1499 track.rclTrack.xRight - track.rclTrack.xLeft,
1500 track.rclTrack.yTop - track.rclTrack.yBottom,
1501 SWP_SIZE|SWP_MOVE);
1502 }
1503 }
1504 return;
1505 }
1506 return;
1507}
1508//******************************************************************************
1509//******************************************************************************
1510void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG idNew,
1511 HBITMAP hbmNew)
1512{
1513 MENUITEM mi;
1514
1515 if (!hwndMenu)
1516 return;
1517
1518 WinEnableWindowUpdate(hwndMenu, FALSE);
1519
1520 if (WinSendMsg(hwndMenu, MM_QUERYITEM, MPFROM2SHORT(idOld, TRUE), MPFROMP(&mi)))
1521 {
1522 WinSendMsg(hwndMenu, MM_REMOVEITEM, (MPARAM)idOld, 0);
1523 mi.afStyle = MIS_BITMAP | MIS_SYSCOMMAND;
1524 mi.afAttribute = 0;
1525 mi.hwndSubMenu = 0;
1526 mi.id = idNew;
1527 mi.hItem = (ULONG)hbmNew;
1528 WinSendMsg(hwndMenu, MM_INSERTITEM, (MPARAM)&mi, 0);
1529 }
1530 WinEnableWindowUpdate(hwndMenu, TRUE);
1531
1532 WinInvalidateRect(hwndMenu, NULL, TRUE);
1533}
1534//******************************************************************************
1535//******************************************************************************
Note: See TracBrowser for help on using the repository browser.