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

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

translation added for WM_V/HSCROLL

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