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

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

added visible region callback function

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