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

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

focus/activation changes

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