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

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

frame tracking updates + fixes

File size: 53.7 KB
Line 
1/* $Id: pmwindow.cpp,v 1.153 2001-10-07 11:48:28 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 //Always call handler; even if mp1 is 0. If we don't do this, the
358 //DivX 4 player will never be allowed to draw after putting another window
359 //on top of it.
360 win32wnd->callVisibleRgnNotifyProc(TRUE);
361 if(!win32wnd->isComingToTop() && ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == WS_EX_TOPMOST_W))
362 {
363 HWND hwndrelated;
364 Win32BaseWindow *topwindow;
365
366 win32wnd->setComingToTop(TRUE);
367
368 hwndrelated = WinQueryWindow(hwnd, QW_PREV);
369 dprintf(("WM_VRNENABLED hwndrelated = %x (hwnd=%x)", hwndrelated, hwnd));
370 topwindow = Win32BaseWindow::GetWindowFromOS2Handle(hwndrelated);
371 if(topwindow == NULL || ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == 0)) {
372 //put window at the top of z order
373 WinSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
374 }
375 if(topwindow) RELEASE_WNDOBJ(topwindow);
376
377 win32wnd->setComingToTop(FALSE);
378 break;
379 }
380 goto RunDefWndProc;
381
382 case WM_VRNDISABLED:
383 dprintf(("OS2: WM_VRNDISABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
384 //visible region is about to change or WinLockWindowUpdate called
385 //suspend window drawing
386 win32wnd->callVisibleRgnNotifyProc(FALSE);
387 goto RunDefWndProc;
388
389 case WIN32APP_SETFOCUSMSG:
390 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
391 //must delay this function call
392 //mp1 = win32 window handle
393 //mp2 = top parent if activation required
394 dprintf(("USER32: Delayed SetFocus %x %x %x call!", teb->o.odin.hwndFocus, mp1, mp2));
395 if(teb->o.odin.hwndFocus) {
396 RELEASE_WNDOBJ(win32wnd);
397 win32wnd = Win32BaseWindow::GetWindowFromHandle(teb->o.odin.hwndFocus);
398 if(win32wnd) {
399 if(mp2) {
400 SetActiveWindow((HWND)mp2);
401 }
402 if(!IsWindow(win32wnd->getWindowHandle())) break; //abort if window destroyed
403 WinFocusChange(HWND_DESKTOP, win32wnd->getOS2WindowHandle(), FC_NOSETACTIVE);
404 }
405 else DebugInt3();
406 }
407 break;
408
409 case WM_SETFOCUS:
410 {
411 HWND hwndFocus = (HWND)mp1;
412
413 dprintf(("OS2: WM_SETFOCUS %x %x (%x) %d", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle(hwndFocus), mp2));
414
415 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
416 //must delay this function call
417
418 teb->o.odin.fWM_SETFOCUS = TRUE;
419 teb->o.odin.hwndFocus = 0;
420 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC)
421 {
422 //another (non-win32) application's window
423 //set to NULL (allowed according to win32 SDK) to avoid problems
424 hwndFocus = NULL;
425 }
426 if((ULONG)mp2 == TRUE) {
427 HWND hwndFocusWin32 = OS2ToWin32Handle(hwndFocus);
428 recreateCaret (hwndFocusWin32);
429 win32wnd->MsgSetFocus(hwndFocusWin32);
430 }
431 else win32wnd->MsgKillFocus(OS2ToWin32Handle(hwndFocus));
432 teb->o.odin.fWM_SETFOCUS = FALSE;
433
434 break;
435 }
436
437 //**************************************************************************
438 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
439 //**************************************************************************
440
441 case WM_BUTTON1DOWN:
442 case WM_BUTTON1UP:
443 case WM_BUTTON1DBLCLK:
444 case WM_BUTTON2DOWN:
445 case WM_BUTTON2UP:
446 case WM_BUTTON2DBLCLK:
447 case WM_BUTTON3DOWN:
448 case WM_BUTTON3UP:
449 case WM_BUTTON3DBLCLK:
450 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
451 RELEASE_WNDOBJ(win32wnd);
452 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
453 }
454 if(win32wnd)
455 win32wnd->MsgButton(pWinMsg);
456
457 rc = (MRESULT)TRUE;
458 break;
459
460 case WM_BUTTON2MOTIONSTART:
461 case WM_BUTTON2MOTIONEND:
462 case WM_BUTTON2CLICK:
463 case WM_BUTTON1MOTIONSTART:
464 case WM_BUTTON1MOTIONEND:
465 case WM_BUTTON1CLICK:
466 case WM_BUTTON3MOTIONSTART:
467 case WM_BUTTON3MOTIONEND:
468 case WM_BUTTON3CLICK:
469 rc = (MRESULT)TRUE;
470 break;
471
472 case WM_MOUSEMOVE:
473 {
474 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
475 RELEASE_WNDOBJ(win32wnd);
476 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
477 }
478 if(win32wnd)
479 win32wnd->MsgMouseMove(pWinMsg);
480 break;
481 }
482
483 case WM_CONTROL:
484 goto RunDefWndProc;
485
486 case WM_COMMAND:
487 dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2));
488 win32wnd->DispatchMsgA(pWinMsg);
489 break;
490
491 case WM_SYSCOMMAND:
492 dprintf(("OS2: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
493 win32wnd->DispatchMsgA(pWinMsg);
494 break;
495
496 case WM_RENDERFMT:
497 case WM_RENDERALLFMTS:
498 case WM_DESTROYCLIPBOARD:
499 win32wnd->DispatchMsgA(pWinMsg);
500 break;
501
502 case WM_CHAR:
503 dprintf(("OS2: WM_CHAR %x %x %x, %x %x", win32wnd->getWindowHandle(), mp1, mp2, pWinMsg->wParam, pWinMsg->lParam));
504 win32wnd->MsgChar(pWinMsg);
505 break;
506
507 case WM_TIMER:
508 dprintf(("OS2: WM_TIMER %x %x time %x", win32wnd->getWindowHandle(), pWinMsg->wParam, GetTickCount()));
509 win32wnd->DispatchMsgA(pWinMsg);
510 goto RunDefWndProc;
511
512 case WM_SETWINDOWPARAMS:
513 {
514 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
515
516 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
517 if(wndParams->fsStatus & WPM_TEXT) {
518 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
519 }
520 goto RunDefWndProc;
521 }
522
523 case WM_QUERYWINDOWPARAMS:
524 {
525 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
526 ULONG textlen;
527 PSZ wintext;
528
529 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
530 {
531 if(wndpars->fsStatus & WPM_TEXT)
532 win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
533 if(wndpars->fsStatus & WPM_CCHTEXT)
534 wndpars->cchText = win32wnd->MsgGetTextLength();
535
536 wndpars->fsStatus = 0;
537 wndpars->cbCtlData = 0;
538 wndpars->cbPresParams = 0;
539 rc = (MRESULT)TRUE;
540 break;
541 }
542 goto RunDefWndProc;
543 }
544
545 case WM_PAINT:
546 {
547 RECTL rectl;
548 BOOL rc;
549
550 rc = WinQueryUpdateRect(hwnd, &rectl);
551 dprintf(("OS2: WM_PAINT %x (%d,%d) (%d,%d) rc=%d", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop, rc));
552
553 if(rc && win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
554 rectl.yBottom != rectl.yTop))
555 {
556 win32wnd->DispatchMsgA(pWinMsg);
557 }
558 else goto RunDefWndProc;
559 break;
560 }
561
562 case WM_ERASEBACKGROUND:
563 {
564 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
565 rc = (MRESULT)FALSE;
566 break;
567 }
568
569 case WM_CALCVALIDRECTS:
570 dprintf(("OS2: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
571 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
572 break;
573
574 case WM_REALIZEPALETTE:
575 {
576 dprintf(("OS2: WM_REALIZEPALETTE"));
577 goto RunDefWndProc;
578 }
579
580 case WM_HSCROLL:
581 case WM_VSCROLL:
582 dprintf(("OS2: %s %x %x %x", (msg == WM_HSCROLL) ? "WM_HSCROLL" : "WM_VSCROLL", win32wnd->getWindowHandle(), mp1, mp2));
583 win32wnd->DispatchMsgA(pWinMsg);
584 break;
585
586 case WM_DDE_INITIATE:
587 case WM_DDE_INITIATEACK:
588 case WM_DDE_REQUEST:
589 case WM_DDE_ACK:
590 case WM_DDE_DATA:
591 case WM_DDE_ADVISE:
592 case WM_DDE_UNADVISE:
593 case WM_DDE_POKE:
594 case WM_DDE_EXECUTE:
595 case WM_DDE_TERMINATE:
596 dprintf(("OS2: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
597 goto RunDefWndProc;
598
599 case WM_INITMENU:
600 case WM_MENUSELECT:
601 case WM_MENUEND:
602 case WM_NEXTMENU:
603 case WM_SYSCOLORCHANGE:
604 case WM_SYSVALUECHANGED:
605 case WM_SETSELECTION:
606 case WM_PPAINT:
607 case WM_PSETFOCUS:
608 case WM_PSYSCOLORCHANGE:
609 case WM_PSIZE:
610 case WM_PACTIVATE:
611 case WM_PCONTROL:
612 case WM_HELP:
613 case WM_APPTERMINATENOTIFY:
614 case WM_PRESPARAMCHANGED:
615 case WM_DRAWITEM:
616 case WM_MEASUREITEM:
617 case WM_CONTROLPOINTER:
618 case WM_QUERYDLGCODE:
619 case WM_SUBSTITUTESTRING:
620 case WM_MATCHMNEMONIC:
621 case WM_SAVEAPPLICATION:
622 case WM_SEMANTICEVENT:
623 default:
624 dprintf2(("OS2: RunDefWndProc hwnd %x msg %x mp1 %x mp2 %x", hwnd, msg, mp1, mp2));
625 goto RunDefWndProc;
626 }
627 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
628 RestoreOS2TIB();
629 return (MRESULT)rc;
630
631RunDefWndProc:
632// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
633 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
634 RestoreOS2TIB();
635 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
636} /* End of Win32WindowProc */
637//******************************************************************************
638//******************************************************************************
639MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
640{
641 POSTMSG_PACKET *postmsg;
642 OSLIBPOINT point, ClientPoint;
643 Win32BaseWindow *win32wnd;
644 TEB *teb;
645 MRESULT rc = 0;
646 MSG winMsg, *pWinMsg;
647
648 //Restore our FS selector
649 SetWin32TIB();
650
651 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
652 teb = GetThreadTEB();
653 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
654
655 if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
656 dprintf(("PMFRAME: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
657 goto RunDefFrameWndProc;
658 }
659//// if(teb->o.odin.fIgnoreMsgs) {
660//// goto RunDefWndProc;
661//// }
662
663 if((teb->o.odin.msgstate & 1) == 0)
664 {//message that was sent directly to our window proc handler; translate it here
665 QMSG qmsg;
666
667 qmsg.msg = msg;
668 qmsg.hwnd = hwnd;
669 qmsg.mp1 = mp1;
670 qmsg.mp2 = mp2;
671 qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
672 WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
673 qmsg.reserved = 0;
674
675 if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
676 {//message was not translated
677 memset(&winMsg, 0, sizeof(MSG));
678 }
679 pWinMsg = &winMsg;
680 }
681 else {
682 pWinMsg = &teb->o.odin.msg;
683 teb->o.odin.msgstate++;
684 }
685 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
686
687 switch( msg )
688 {
689 case WM_CREATE:
690 {
691 //WM_CREATE handled during client window creation
692 dprintf(("PMFRAME: WM_CREATE %x"));
693 goto RunDefFrameWndProc;
694 }
695
696 case WM_PAINT:
697 {
698 RECTL rectl;
699
700 HPS hps = WinBeginPaint(hwnd, NULL, &rectl);
701 dprintf(("PMFRAME: WM_PAINT %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
702
703 if(win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
704 rectl.yBottom != rectl.yTop))
705 {
706 PRECT pClient = win32wnd->getClientRectPtr();
707 PRECT pWindow = win32wnd->getWindowRect();
708
709 if(!(pClient->left == 0 && pClient->top == 0 &&
710 win32wnd->getClientHeight() == win32wnd->getWindowHeight() &&
711 win32wnd->getClientWidth() == win32wnd->getWindowWidth()))
712 {
713 RECT rectUpdate;
714
715 mapOS2ToWin32Rect(win32wnd->getWindowHeight(), (PRECTLOS2)&rectl, &rectUpdate);
716 win32wnd->MsgNCPaint(&rectUpdate);
717 }
718 }
719 WinEndPaint(hps);
720 break;
721 }
722
723 case WM_ERASEBACKGROUND:
724 {
725 dprintf(("PMFRAME:WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
726 rc = (MRESULT)FALSE;
727 break;
728 }
729
730 //**************************************************************************
731 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
732 //**************************************************************************
733
734 case WM_BUTTON1DOWN:
735 case WM_BUTTON1UP:
736 case WM_BUTTON1DBLCLK:
737 case WM_BUTTON2DOWN:
738 case WM_BUTTON2UP:
739 case WM_BUTTON2DBLCLK:
740 case WM_BUTTON3DOWN:
741 case WM_BUTTON3UP:
742 case WM_BUTTON3DBLCLK:
743 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
744 RELEASE_WNDOBJ(win32wnd);
745 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
746 }
747 if(win32wnd)
748 win32wnd->MsgButton(pWinMsg);
749
750 rc = (MRESULT)TRUE;
751 break;
752
753 case WM_BUTTON2MOTIONSTART:
754 case WM_BUTTON2MOTIONEND:
755 case WM_BUTTON2CLICK:
756 case WM_BUTTON1MOTIONSTART:
757 case WM_BUTTON1MOTIONEND:
758 case WM_BUTTON1CLICK:
759 case WM_BUTTON3MOTIONSTART:
760 case WM_BUTTON3MOTIONEND:
761 case WM_BUTTON3CLICK:
762 rc = (MRESULT)TRUE;
763 break;
764
765 case WM_MOUSEMOVE:
766 {
767 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
768 RELEASE_WNDOBJ(win32wnd);
769 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
770 }
771 if(win32wnd)
772 win32wnd->MsgMouseMove(pWinMsg);
773 break;
774 }
775
776 case WM_ADJUSTWINDOWPOS:
777 {
778 PSWP pswp = (PSWP)mp1;
779 SWP swpOld;
780 WINDOWPOS wp,wpOld;
781 ULONG ulFlags;
782 ULONG ret = 0;
783 HWND hParent = NULLHANDLE, hwndAfter;
784
785 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));
786
787 ulFlags = pswp->fl;
788
789 if(win32wnd->IsParentChanging()) {
790 rc = 0;
791 break;
792 }
793
794 if(pswp->fl & SWP_NOADJUST) {
795 //ignore weird messages (TODO: why are they sent?)
796 dprintf(("WARNING: WM_ADJUSTWINDOWPOS with SWP_NOADJUST flag!!"));
797 break;
798 }
799 //CB: show dialog in front of owner
800 if (win32wnd->IsModalDialogOwner())
801 {
802 dprintf(("win32wnd->IsModalDialogOwner %x", win32wnd->getWindowHandle()));
803 pswp->fl |= SWP_ZORDER;
804 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
805 if (pswp->fl & SWP_ACTIVATE)
806 {
807 pswp->fl &= ~SWP_ACTIVATE;
808 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
809 }
810 }
811
812 if(!win32wnd->CanReceiveSizeMsgs())
813 break;
814
815 WinQueryWindowPos(hwnd, &swpOld);
816 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
817 if (win32wnd->isChild()) {
818 if(win32wnd->getParent()) {
819 hParent = win32wnd->getParent()->getOS2WindowHandle();
820 }
821 else goto RunDefFrameWndProc;
822 }
823 }
824 hwndAfter = pswp->hwndInsertBehind;
825 if(win32wnd->getParent()) {
826 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(), hwnd);
827 }
828 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
829
830 wp.hwnd = win32wnd->getWindowHandle();
831 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
832 {
833 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
834 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
835 if(wndAfter) {
836 wp.hwndInsertAfter = wndAfter->getWindowHandle();
837 RELEASE_WNDOBJ(wndAfter);
838 }
839 else wp.hwndInsertAfter = HWND_TOP_W;
840 }
841
842 wpOld = wp;
843 win32wnd->MsgPosChanging((LPARAM)&wp);
844
845 if(win32wnd->getOldStyle() != win32wnd->getStyle())
846 {
847 OSLibSetWindowStyle(win32wnd->getOS2FrameWindowHandle(), win32wnd->getOS2WindowHandle(), win32wnd->getStyle(), win32wnd->getExStyle());
848 if(fOS2Look) {
849 DWORD dwOldStyle = win32wnd->getOldStyle();
850 DWORD dwStyle = win32wnd->getStyle();
851
852 if((dwOldStyle & WS_MINIMIZE_W) && !(dwStyle & WS_MINIMIZE_W)) {
853 //SC_RESTORE -> SC_MINIMIZE
854 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_RESTORE, SC_MINIMIZE, hbmFrameMenu[0]);
855 }
856 else
857 if((dwOldStyle & WS_MAXIMIZE_W) && !(dwStyle & WS_MAXIMIZE_W)) {
858 //SC_RESTORE -> SC_MAXIMIZE
859 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_RESTORE, SC_MAXIMIZE, hbmFrameMenu[1]);
860 }
861 else
862 if(!(dwOldStyle & WS_MINIMIZE_W) && (dwStyle & WS_MINIMIZE_W)) {
863 //SC_MINIMIZE -> SC_RESTORE
864 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_MINIMIZE, SC_RESTORE, hbmFrameMenu[2]);
865 }
866 else
867 if(!(dwOldStyle & WS_MAXIMIZE_W) && (dwStyle & WS_MAXIMIZE_W)) {
868 //SC_MAXIMIZE -> SC_RESTORE
869 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[2]);
870 }
871 }
872 }
873
874 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
875 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
876 {
877 ULONG flags = pswp->fl; //make a backup copy; OSLibMapWINDOWPOStoSWP will modify it
878
879 dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
880 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
881
882 if(win32wnd->getParent()) {
883 OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getClientHeight(),
884 hwnd);
885 }
886 else OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), hwnd);
887
888 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
889
890 //OSLibMapWINDOWPOStoSWP can add flags, but we must not let it remove flags!
891 if(pswp->fl & SWP_SIZE)
892 flags |= SWP_SIZE;
893
894 if(pswp->fl & SWP_MOVE)
895 flags |= SWP_MOVE;
896
897 pswp->fl = flags; //restore flags
898
899 pswp->fl |= SWP_NOADJUST;
900 pswp->hwndInsertBehind = hwndAfter;
901 pswp->hwnd = hwnd;
902
903 ret = 0xf;
904 }
905adjustend:
906 //The next part needs to be done for top-level windows only
907 if(!((win32wnd->getStyle() & (WS_POPUP_W|WS_CHILD_W)) == WS_CHILD_W))
908 {
909 //Setting these flags is necessary to avoid activation/focus problems
910 if(ulFlags & SWP_DEACTIVATE) {
911 ret |= AWP_DEACTIVATE;
912 }
913 if(ulFlags & SWP_ACTIVATE)
914 {
915 ULONG ulFrameFlags;
916
917 if(ulFlags & SWP_ZORDER) {
918 ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
919 WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags | FF_NOACTIVATESWP);
920 }
921
922 if(!(ulFlags & SWP_SHOW))
923 {
924 ret |= AWP_ACTIVATE;
925 }
926 else
927 {
928 HWND hwndFocusSave = WinQueryWindowULong(hwnd, QWL_HWNDFOCUSSAVE);
929 if(!WinIsWindow(hab, hwndFocusSave)) {
930 hwndFocusSave = WinWindowFromID(hwnd, FID_CLIENT);
931 WinSetWindowULong(hwnd, QWL_HWNDFOCUSSAVE, hwndFocusSave);
932 }
933 dprintf(("WM_ADJUSTWINDOWPOS: hwndFocusSave %x %x", OS2ToWin32Handle(hwndFocusSave), hwndFocusSave));
934 WinSetFocus(HWND_DESKTOP, hwndFocusSave);
935
936 ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
937 ulFrameFlags &= ~FF_NOACTIVATESWP;
938 WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags);
939 }
940 }
941 }
942 else {
943 if(ulFlags & (SWP_ACTIVATE|SWP_FOCUSACTIVATE))
944 {
945 win32wnd->MsgChildActivate(TRUE);
946 if(fOS2Look) {
947 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
948 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, (MPARAM)1, 0);
949 }
950 }
951 else
952 if(ulFlags & (SWP_DEACTIVATE|SWP_FOCUSDEACTIVATE))
953 {
954 win32wnd->MsgChildActivate(FALSE);
955 if(fOS2Look) {
956 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
957 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, 0, 0);
958 }
959 }
960 }
961 dprintf(("WM_ADJUSTWINDOWPOS ret %x", ret));
962 rc = (MRESULT)ret;
963 break;
964 }
965
966 case WM_WINDOWPOSCHANGED:
967 {
968 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
969 SWP swpOld = *(pswp + 1);
970 WINDOWPOS wp;
971 HWND hParent = NULLHANDLE;
972 RECTL rect;
973
974 dprintf(("PMFRAME:WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
975 if(win32wnd->IsParentChanging()) {
976 goto PosChangedEnd;
977 }
978
979 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
980 {
981 if(pswp->fl & SWP_RESTORE && win32wnd->getStyle() & WS_MINIMIZE_W) {
982 dprintf(("Restoring minimized window %x", win32wnd->getWindowHandle()));
983 win32wnd->ShowWindow(SW_RESTORE_W);
984 }
985 if(pswp->fl & SWP_SHOW) {
986 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
987 }
988 else
989 if(pswp->fl & SWP_HIDE) {
990 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
991 }
992 goto RunDefFrameWndProc;
993 }
994
995 if(pswp->fl & (SWP_MOVE | SWP_SIZE))
996 {
997 if(win32wnd->isChild())
998 {
999 if(win32wnd->getParent()) {
1000 hParent = win32wnd->getParent()->getOS2WindowHandle();
1001 }
1002 else goto PosChangedEnd; //parent has just been destroyed
1003 }
1004 }
1005
1006
1007 if(win32wnd->getParent()) {
1008 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1009 hwnd);
1010 }
1011 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1012
1013 wp.hwnd = win32wnd->getWindowHandle();
1014 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1015 {
1016 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1017 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
1018 if(wndAfter) {
1019 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1020 RELEASE_WNDOBJ(wndAfter);
1021 }
1022 else wp.hwndInsertAfter = HWND_TOP_W;
1023 }
1024
1025 if(pswp->fl & SWP_SHOW) {
1026 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
1027 }
1028 else
1029 if(pswp->fl & SWP_HIDE) {
1030 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
1031 }
1032
1033#ifndef USE_CALCVALIDRECT
1034 if((pswp->fl & (SWP_MOVE | SWP_SIZE)))
1035 {
1036 //CB: todo: use result for WM_CALCVALIDRECTS
1037 //Get old client rectangle (for invalidation of frame window parts later on)
1038 //Use new window height to calculate the client area
1039 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
1040
1041 //Note: Also updates the new window rectangle
1042 win32wnd->MsgFormatFrame(&wp);
1043
1044 if(win32wnd->isOwnDC()) {
1045 setPageXForm(win32wnd, (pDCData)GpiQueryDCData(win32wnd->getOwnDC()));
1046 }
1047
1048 if(win32wnd->CanReceiveSizeMsgs())
1049 win32wnd->MsgPosChanged((LPARAM)&wp);
1050
1051 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
1052 {
1053 //redraw the frame (to prevent unnecessary client updates)
1054 BOOL redrawAll = FALSE;
1055
1056 dprintf2(("WM_WINDOWPOSCHANGED: redraw frame"));
1057 if (win32wnd->getWindowClass())
1058 {
1059 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
1060
1061 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
1062 redrawAll = TRUE;
1063 else
1064 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
1065 redrawAll = TRUE;
1066 }
1067 else redrawAll = TRUE;
1068
1069 if(win32wnd->IsMixMaxStateChanging()) {
1070 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1071 redrawAll = TRUE;
1072 }
1073
1074 if (redrawAll)
1075 {
1076 //CB: redraw all children for now
1077 // -> problems with update region if we don't do it
1078 // todo: rewrite whole handling
1079 WinInvalidateRect(hwnd,NULL,TRUE);
1080 }
1081 else
1082 {
1083 HPS hps = WinGetPS(hwnd);
1084 RECTL frame,client,arcl[4];
1085
1086 WinQueryWindowRect(hwnd,&frame);
1087
1088 //top
1089 arcl[0].xLeft = 0;
1090 arcl[0].xRight = frame.xRight;
1091 arcl[0].yBottom = rect.yTop;
1092 arcl[0].yTop = frame.yTop;
1093 //right
1094 arcl[1].xLeft = rect.xRight;
1095 arcl[1].xRight = frame.xRight;
1096 arcl[1].yBottom = 0;
1097 arcl[1].yTop = frame.yTop;
1098 //left
1099 arcl[2].xLeft = 0;
1100 arcl[2].xRight = rect.xLeft;
1101 arcl[2].yBottom = 0;
1102 arcl[2].yTop = frame.yTop;
1103 //bottom
1104 arcl[3].xLeft = 0;
1105 arcl[3].xRight = frame.xRight;
1106 arcl[3].yBottom = 0;
1107 arcl[3].yTop = rect.yBottom;
1108
1109 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
1110
1111 WinInvalidateRegion(hwnd,hrgn,FALSE);
1112 GpiDestroyRegion(hps,hrgn);
1113 WinReleasePS(hps);
1114 }
1115 }
1116 }
1117 else
1118 {
1119#endif //USE_CALCVALIDRECT
1120 if(win32wnd->CanReceiveSizeMsgs())
1121 win32wnd->MsgPosChanged((LPARAM)&wp);
1122#ifndef USE_CALCVALIDRECT
1123 }
1124#endif
1125
1126PosChangedEnd:
1127 rc = (MRESULT)FALSE;
1128 break;
1129 }
1130
1131 case WM_CALCVALIDRECTS:
1132#ifdef USE_CALCVALIDRECT
1133 {
1134 PRECTL oldRect = (PRECTL)mp1, newRect = oldRect+1;
1135 PSWP pswp = (PSWP)mp2;
1136 SWP swpOld;
1137 WINDOWPOS wp;
1138 RECTL newClientRect, oldClientRect;
1139 ULONG nccalcret;
1140// UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
1141 UINT res = 0;
1142
1143 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1144
1145 //Get old position info
1146 WinQueryWindowPos(hwnd, &swpOld);
1147
1148 if(win32wnd->getParent()) {
1149 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1150 win32wnd->getParent()->getClientRectPtr()->left,
1151 win32wnd->getParent()->getClientRectPtr()->top,
1152 hwnd);
1153 }
1154 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
1155
1156 wp.hwnd = win32wnd->getWindowHandle();
1157 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1158 {
1159 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1160 if(wndAfter) {
1161 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1162 RELEASE_WNDOBJ(wndAfter);
1163 }
1164 else wp.hwndInsertAfter = HWND_TOP_W;
1165 }
1166
1167 //Get old client rectangle
1168 mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
1169
1170 //Note: Also updates the new window rectangle
1171 nccalcret = win32wnd->MsgFormatFrame(&wp);
1172
1173 //Get new client rectangle
1174 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
1175
1176 if(nccalcret == 0) {
1177 res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
1178 }
1179 else {
1180 if(nccalcret & WVR_ALIGNTOP_W) {
1181 res |= CVR_ALIGNTOP;
1182 }
1183 else
1184 if(nccalcret & WVR_ALIGNBOTTOM_W) {
1185 res |= CVR_ALIGNBOTTOM;
1186 }
1187
1188 if(nccalcret & WVR_ALIGNLEFT_W) {
1189 res |= CVR_ALIGNLEFT;
1190 }
1191 else
1192 if(nccalcret & WVR_ALIGNRIGHT_W) {
1193 res |= CVR_ALIGNRIGHT;
1194 }
1195
1196 if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
1197 res |= CVR_REDRAW;
1198 }
1199 else
1200 if(nccalcret & WVR_VALIDRECTS_W) {
1201 //TODO:
1202 //res = 0;
1203 }
1204 }
1205 if(win32wnd->IsMixMaxStateChanging()) {
1206 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1207 res |= CVR_REDRAW;
1208 }
1209 if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
1210 oldRect->xRight -= oldClientRect.xLeft;
1211 oldRect->yBottom += oldClientRect.yBottom;
1212 newRect->xRight -= newClientRect.xLeft;
1213 newRect->yBottom += newClientRect.yBottom;
1214 }
1215 rc = res;
1216 break;
1217 }
1218#else
1219 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1220 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
1221 break;
1222#endif
1223
1224 case WM_CALCFRAMERECT:
1225 dprintf(("PMFRAME:WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
1226 rc = (MRESULT)TRUE;
1227 break;
1228
1229 case WM_QUERYCTLTYPE:
1230 // This is a frame window
1231 dprintf(("PMFRAME:WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
1232 rc = (MRESULT)CCT_FRAME;
1233 break;
1234
1235#ifdef DEBUG
1236 case WM_QUERYFOCUSCHAIN:
1237 dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x parent %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), (mp2) ? OS2ToWin32Handle((DWORD)mp2) : 0));
1238
1239 RestoreOS2TIB();
1240 rc = pfnFrameWndProc(hwnd, msg, mp1, mp2);
1241 SetWin32TIB();
1242 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));
1243 break;
1244// goto RunDefFrameWndProc;
1245#endif
1246
1247#ifdef DEBUG
1248 case WM_FOCUSCHANGE:
1249 {
1250 HWND hwndFocus = (HWND)mp1;
1251 HWND hwndLoseFocus, hwndGainFocus;
1252 USHORT usSetFocus = SHORT1FROMMP(mp2);
1253 USHORT fsFocusChange = SHORT2FROMMP(mp2);
1254
1255 dprintf(("PMFRAME:WM_FOCUSCHANGE %x %x (%x) %x %x", win32wnd->getWindowHandle(), OS2ToWin32Handle(hwndFocus), hwndFocus, usSetFocus, fsFocusChange));
1256 goto RunDefFrameWndProc;
1257 }
1258
1259 case WM_SETFOCUS:
1260 {
1261 dprintf(("PMFRAME: WM_SETFOCUS %x %x", win32wnd->getWindowHandle(), hwnd));
1262 goto RunDefFrameWndProc;
1263 }
1264#endif
1265
1266 case WM_ACTIVATE:
1267 {
1268 HWND hwndTitle;
1269 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
1270
1271 dprintf(("PMFRAME: WM_ACTIVATE %x %x %x", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle((DWORD)mp2)));
1272 if (win32wnd->IsWindowCreated())
1273 {
1274 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1275 if(fOS2Look) {
1276 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1277 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, mp1, 0);
1278 }
1279 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
1280
1281 //CB: show owner behind the dialog
1282 if (win32wnd->IsModalDialog())
1283 {
1284 if(win32wnd->getOwner()) {
1285 Win32BaseWindow *topOwner = Win32BaseWindow::GetWindowFromHandle(win32wnd->getOwner()->GetTopParent());
1286
1287 if (topOwner) {
1288 WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
1289 RELEASE_WNDOBJ(topOwner);
1290 }
1291 }
1292 }
1293 }
1294 else
1295 {
1296 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1297 }
1298 rc = 0;
1299 break;
1300 }
1301
1302 case WM_ENABLE:
1303 dprintf(("PMFRAME: WM_ENABLE %x", hwnd));
1304 win32wnd->MsgEnable(SHORT1FROMMP(mp1));
1305 break;
1306
1307 case WM_SHOW:
1308 dprintf(("PMFRAME: WM_SHOW %x %d", hwnd, mp1));
1309 //show client window
1310 WinShowWindow(win32wnd->getOS2WindowHandle(), (BOOL)mp1);
1311 break;
1312
1313 case WM_QUERYTRACKINFO:
1314 {
1315 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
1316
1317 dprintf(("PMFRAME:WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
1318 trackInfo->cxBorder = 4;
1319 trackInfo->cyBorder = 4;
1320 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
1321 rc = (MRESULT)TRUE;
1322 break;
1323 }
1324
1325 case WM_QUERYBORDERSIZE:
1326 {
1327 PWPOINT size = (PWPOINT)mp1;
1328
1329 dprintf(("PMFRAME:WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
1330
1331 size->x = 0;
1332 size->y = 0;
1333 rc = (MRESULT)TRUE;
1334 break;
1335 }
1336
1337#ifdef DEBUG
1338 case WM_QUERYFRAMEINFO:
1339 dprintf(("PMFRAME:WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
1340 goto RunDefFrameWndProc;
1341#endif
1342
1343 case WM_FORMATFRAME:
1344 dprintf(("PMFRAME:WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
1345 break;
1346
1347#ifdef DEBUG
1348 case WM_ADJUSTFRAMEPOS:
1349 {
1350 PSWP pswp = (PSWP)mp1;
1351
1352 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));
1353 goto RunDefFrameWndProc;
1354 }
1355
1356 case WM_OWNERPOSCHANGE:
1357 {
1358 PSWP pswp = (PSWP)mp1;
1359
1360 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));
1361 goto RunDefFrameWndProc;
1362 }
1363#endif
1364
1365 case WM_MINMAXFRAME:
1366 {
1367 PSWP swp = (PSWP)mp1;
1368
1369 if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
1370
1371 dprintf(("PMFRAME:WM_MINMAXFRAME %x",hwnd));
1372 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1373 {
1374 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
1375
1376 RECT rect;
1377
1378 rect.left = rect.top = rect.right = rect.bottom = 0;
1379 win32wnd->AdjustMaximizedRect(&rect);
1380 swp->x += rect.left;
1381 swp->cx += rect.right-rect.left;
1382 swp->y -= rect.bottom;
1383 swp->cy += rect.bottom-rect.top;
1384 }
1385 else
1386 if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
1387 {
1388 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
1389 }
1390 else
1391 if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
1392 {
1393 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
1394 }
1395 goto RunDefWndProc;
1396 }
1397
1398#ifdef DEBUG
1399 case WM_UPDATEFRAME:
1400 dprintf(("PMFRAME:WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
1401 goto RunDefFrameWndProc;
1402#endif
1403
1404 case WM_TRACKFRAME:
1405 dprintf(("PMFRAME: WM_TRACKFRAME %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
1406 if(fOS2Look) {//sent by titlebar control
1407#ifdef CUSTOM_TRACKFRAME
1408 Frame_SysCommandSizeMove(win32wnd, SC_MOVE_W+HTCAPTION_W);
1409#else
1410 FrameTrackFrame(win32wnd, TF_MOVE);
1411#endif
1412 }
1413 rc = 0;
1414 break;
1415
1416 case WM_SYSCOMMAND:
1417 dprintf(("PMFRAME: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
1418 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
1419 RELEASE_WNDOBJ(win32wnd);
1420 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
1421 }
1422 if(win32wnd)
1423 win32wnd->DispatchMsgA(pWinMsg);
1424 break;
1425
1426#ifdef DEBUG
1427 case WM_DDE_INITIATE:
1428 case WM_DDE_INITIATEACK:
1429 case WM_DDE_REQUEST:
1430 case WM_DDE_ACK:
1431 case WM_DDE_DATA:
1432 case WM_DDE_ADVISE:
1433 case WM_DDE_UNADVISE:
1434 case WM_DDE_POKE:
1435 case WM_DDE_EXECUTE:
1436 case WM_DDE_TERMINATE:
1437 dprintf(("PMFRAME: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
1438 break;
1439#endif
1440
1441 default:
1442 goto RunDefFrameWndProc;
1443 }
1444 RestoreOS2TIB();
1445 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1446 return (MRESULT)rc;
1447
1448RunDefFrameWndProc:
1449 dprintf2(("RunDefFrameWndProc"));
1450 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1451 RestoreOS2TIB();
1452 return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1453
1454RunDefWndProc:
1455 dprintf2(("RunDefWndProc"));
1456 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1457 RestoreOS2TIB();
1458 //calling WinDefWindowProc here breaks Opera hotlist window (WM_ADJUSTWINDOWPOS)
1459// return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1460 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
1461}
1462#ifndef CUSTOM_TRACKFRAME
1463//******************************************************************************
1464//TODO: Quickly moving a window two times doesn't force a repaint (1st time)
1465//
1466//
1467BOOL (APIENTRY *WinTrackWindow)(HWND hwndTrack, PTRACKINFO pti) = NULL;
1468//
1469//******************************************************************************
1470VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
1471{
1472 TRACKINFO track;
1473 RECTL rcl;
1474 PRECT pWindowRect, pClientRect;
1475 HWND hwndTracking;
1476 LONG parentHeight, parentWidth;
1477 static BOOL fInit = FALSE;
1478 APIRET rc;
1479 BOOL ret;
1480 HWND hwnd = win32wnd->getWindowHandle();
1481
1482 if(!fInit) {
1483 HMODULE hModule;
1484 char buf[CCHMAXPATH];
1485 rc = DosLoadModule(buf, sizeof(buf), "PMMERGE", &hModule);
1486 rc = DosQueryProcAddr(hModule, 5466, NULL, (PFN *)&WinTrackWindow);
1487 if(rc) WinTrackWindow = NULL;
1488 fInit = TRUE;
1489 }
1490 dprintf(("FrameTrackFrame: %x %x", hwnd, flags));
1491 track.cxBorder = 4;
1492 track.cyBorder = 4; /* 4 pel wide lines used for rectangle */
1493 track.cxGrid = 1;
1494 track.cyGrid = 1; /* smooth tracking with mouse */
1495 track.cxKeyboard = 8;
1496 track.cyKeyboard = 8; /* faster tracking using cursor keys */
1497
1498 pWindowRect = win32wnd->getWindowRect();
1499 if(win32wnd->getParent()) {
1500 parentHeight = win32wnd->getParent()->getClientHeight();
1501 parentWidth = win32wnd->getParent()->getClientWidth();
1502 hwndTracking = win32wnd->getParent()->getOS2WindowHandle();
1503 }
1504 else {
1505 parentHeight = OSLibQueryScreenHeight();
1506 parentWidth = OSLibQueryScreenWidth();
1507 hwndTracking = HWND_DESKTOP;
1508 }
1509
1510 mapWin32ToOS2Rect(parentHeight, pWindowRect, (PRECTLOS2)&track.rclTrack);
1511 rcl = track.rclTrack;
1512 WinQueryWindowRect(hwndTracking, &track.rclBoundary);
1513
1514 track.ptlMinTrackSize.x = 10;
1515 track.ptlMinTrackSize.y = 10; /* set smallest allowed size of rectangle */
1516 track.ptlMaxTrackSize.x = parentWidth;
1517 track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */
1518
1519 win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize);
1520
1521 track.fs = flags;
1522
1523 BOOL fDynamicDrag = WinQuerySysValue(HWND_DESKTOP, SVOS_DYNAMICDRAG);
1524
1525 //TODO: send WM_QUERYDRAGICON to fetch icon (not really necessary)
1526
1527 SendMessageA( hwnd, WM_ENTERSIZEMOVE_W, 0, 0);
1528
1529 SEL sel = RestoreOS2FS();
1530 if(fDynamicDrag && WinTrackWindow) {
1531 ret = WinTrackWindow(win32wnd->getOS2FrameWindowHandle(), &track);
1532 }
1533 else ret = WinTrackRect(hwndTracking, NULL, &track);
1534 SetFS(sel);
1535
1536//TODO:
1537// if (HOOK_CallHooksA( WH_CBT_W, HCBT_MOVESIZE_W, (WPARAM)hwnd, (LPARAM)&sizingRect )) moved = FALSE;
1538
1539 SendMessageA( hwnd, WM_EXITSIZEMOVE_W, 0, 0 );
1540 SendMessageA( hwnd, WM_SETVISIBLE_W, !IsIconic(hwnd), 0L);
1541
1542 if(ret) {
1543 /* if successful copy final position back */
1544 if(!WinEqualRect(0, &rcl, &track.rclTrack)) {
1545 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));
1546 if(flags == TF_MOVE) {
1547 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
1548 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1549 0, 0, SWP_MOVE);
1550 }
1551 else {
1552 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
1553 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1554 track.rclTrack.xRight - track.rclTrack.xLeft,
1555 track.rclTrack.yTop - track.rclTrack.yBottom,
1556 SWP_SIZE|SWP_MOVE);
1557 }
1558 }
1559 return;
1560 }
1561 return;
1562}
1563#endif
1564//******************************************************************************
1565//******************************************************************************
1566void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG idNew,
1567 HBITMAP hbmNew)
1568{
1569 MENUITEM mi;
1570
1571 if (!hwndMenu)
1572 return;
1573
1574 WinEnableWindowUpdate(hwndMenu, FALSE);
1575
1576 if (WinSendMsg(hwndMenu, MM_QUERYITEM, MPFROM2SHORT(idOld, TRUE), MPFROMP(&mi)))
1577 {
1578 WinSendMsg(hwndMenu, MM_REMOVEITEM, (MPARAM)idOld, 0);
1579 mi.afStyle = MIS_BITMAP | MIS_SYSCOMMAND;
1580 mi.afAttribute = 0;
1581 mi.hwndSubMenu = 0;
1582 mi.id = idNew;
1583 mi.hItem = (ULONG)hbmNew;
1584 WinSendMsg(hwndMenu, MM_INSERTITEM, (MPARAM)&mi, 0);
1585 }
1586 WinEnableWindowUpdate(hwndMenu, TRUE);
1587
1588 WinInvalidateRect(hwndMenu, NULL, TRUE);
1589}
1590//******************************************************************************
1591//******************************************************************************
Note: See TracBrowser for help on using the repository browser.