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

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

activation + sc_close fixes

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