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

Last change on this file since 8542 was 8542, checked in by sandervl, 23 years ago

moved drag 'n drop code to seperate file; minor updates

File size: 69.4 KB
Line 
1/* $Id: pmwindow.cpp,v 1.175 2002-06-02 10:07:57 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_DOSDEVICES
19#define INCL_DOSDEVIOCTL
20#define INCL_WINTRACKRECT
21
22#include <os2wrap.h>
23#include <stdlib.h>
24#include <string.h>
25#include <win32type.h>
26#include <win32api.h>
27#include <winconst.h>
28#include <winuser32.h>
29#include <wprocess.h>
30#include <misc.h>
31#include <win32wbase.h>
32#include <win32dlg.h>
33#include "win32wdesktop.h"
34#include "pmwindow.h"
35#include "oslibwin.h"
36#include "oslibutil.h"
37#include "oslibgdi.h"
38#include "oslibmsg.h"
39#define INCLUDED_BY_DC
40#include "dc.h"
41#include <thread.h>
42#include <wprocess.h>
43#include "caret.h"
44#include "timer.h"
45#include <codepage.h>
46#include "syscolor.h"
47#include "options.h"
48#include "menu.h"
49#include <pmkbdhk.h>
50#include <pmscan.h>
51#include <winscan.h>
52#include <win\dbt.h>
53#include "dragdrop.h"
54
55#define DBG_LOCALLOG DBG_pmwindow
56#include "dbglocal.h"
57
58//define this to use the new code for WM_CALCVALIDRECT handling
59//#define USE_CALCVALIDRECT
60
61HMQ hmq = 0; /* Message queue handle */
62HAB hab = 0;
63RECTL desktopRectl = {0};
64ULONG ScreenWidth = 0;
65ULONG ScreenHeight = 0;
66ULONG ScreenBitsPerPel = 0;
67BOOL fOS2Look = FALSE;
68BOOL fForceMonoCursor = FALSE;
69HBITMAP hbmFrameMenu[3] = {0};
70
71static PFNWP pfnFrameWndProc = NULL;
72static HWND hwndFocusChange = 0;
73 HWND hwndCD = 0;
74
75// this holds the font height that the display driver returns using DevQueryCaps
76// 13 would be small fonts, 16 medium fonts and 20 large fonts
77LONG CapsCharHeight = 0;
78
79// Note:
80// For a "lonekey"-press of AltGr, we only receive WM_KEYUP
81// messages. If the key is pressed longer and starts to repeat,
82// WM_KEYDOWN messages come in properly.
83static BOOL fKeyAltGrDown = FALSE;
84
85
86
87MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
88MRESULT EXPENTRY Win32CDWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
89MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
90void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG idNew,
91 HBITMAP hbmNew);
92void FrameSetFocus(HWND hwnd);
93
94VOID APIENTRY DspInitSystemDriverName(PSZ pszDriverName, ULONG lenDriverName);
95
96//******************************************************************************
97//Initialize PM; create hab, message queue and register special Win32 window classes
98//******************************************************************************
99BOOL InitPM()
100{
101 hab = WinInitialize(0);
102 dprintf(("Winitialize returned %x", hab));
103 hmq = WinCreateMsgQueue(hab, 0);
104
105 if(!hab || !hmq)
106 {
107 UINT error;
108 //CB: only fail on real error
109 error = WinGetLastError(hab) & 0xFFFF; //error code
110 if (!hab || (error != PMERR_MSG_QUEUE_ALREADY_EXISTS))
111 {
112 dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
113 dprintf((" Error = %x",error));
114 return(FALSE);
115 }
116 else
117 {
118 if(!hab) {
119 hab = WinQueryAnchorBlock(HWND_DESKTOP);
120 dprintf(("WinQueryAnchorBlock returned %x", hab));
121 }
122 if(!hmq) {
123 PTIB ptib;
124 PPIB ppib;
125
126 DosGetInfoBlocks(&ptib, &ppib);
127
128 hmq = WinQueueFromID(hab, ppib->pib_ulpid, ptib->tib_ptib2->tib2_ultid);
129 }
130 }
131 }
132 SetThreadHAB(hab);
133 dprintf(("InitPM: hmq = %x", hmq));
134 SetThreadMessageQueue(hmq);
135
136 BOOL rc = WinSetCp(hmq, GetDisplayCodepage());
137 dprintf(("InitPM: WinSetCP was %sOK", rc ? "" : "not "));
138
139 //CD polling window class
140 if(!WinRegisterClass( /* Register window class */
141 hab, /* Anchor block handle */
142 (PSZ)WIN32_CDCLASS, /* Window class name */
143 (PFNWP)Win32CDWindowProc, /* Address of window procedure */
144 0,
145 0))
146 {
147 dprintf(("WinRegisterClass Win32BaseWindow failed"));
148 return(FALSE);
149 }
150
151 //Standard Odin window class
152 if(!WinRegisterClass( /* Register window class */
153 hab, /* Anchor block handle */
154 (PSZ)WIN32_STDCLASS, /* Window class name */
155 (PFNWP)Win32WindowProc, /* Address of window procedure */
156 0,
157 NROF_WIN32WNDBYTES))
158 {
159 dprintf(("WinRegisterClass Win32BaseWindow failed"));
160 return(FALSE);
161 }
162
163 CLASSINFO FrameClassInfo;
164 if(!WinQueryClassInfo (hab, WC_FRAME, &FrameClassInfo)) {
165 dprintf (("WinQueryClassInfo WC_FRAME failed"));
166 return (FALSE);
167 }
168 pfnFrameWndProc = FrameClassInfo.pfnWindowProc;
169
170 dprintf(("WC_FRAME style %x", FrameClassInfo.flClassStyle));
171
172 if(!WinRegisterClass( /* Register window class */
173 hab, /* Anchor block handle */
174 (PSZ)WIN32_STDFRAMECLASS, /* Window class name */
175 (PFNWP)Win32FrameWindowProc, /* Address of window procedure */
176 CS_FRAME,
177 FrameClassInfo.cbWindowData))
178 {
179 dprintf(("WinRegisterClass Win32BaseWindow failed %x", WinGetLastError(hab)));
180 return(FALSE);
181 }
182
183 WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
184 ScreenWidth = desktopRectl.xRight;
185 ScreenHeight = desktopRectl.yTop;
186
187 HDC hdc; /* Device-context handle */
188 /* context data structure */
189 DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
190 NULL, NULL, NULL};
191
192 /* create memory device context */
193 hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
194
195 fOS2Look = PROFILE_GetOdinIniBool(ODINSYSTEM_SECTION, "OS2Look", FALSE);
196 if(fOS2Look)
197 {
198 CHAR szDisplay[30];
199 HMODULE hModDisplay;
200
201 SYSCOLOR_Init(FALSE); //use OS/2 colors
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 }
210
211 DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, (PLONG)&ScreenBitsPerPel);
212
213 // query the font height to find out whether we have small or large fonts
214 DevQueryCaps(hdc, CAPS_GRAPHICS_CHAR_HEIGHT, 1, (PLONG)&CapsCharHeight);
215
216 DevCloseDC(hdc);
217
218 dprintf(("InitPM: Desktop (%d,%d) bpp %d", ScreenWidth, ScreenHeight, ScreenBitsPerPel));
219 return TRUE;
220} /* End of main */
221//******************************************************************************
222//menu.cpp
223BOOL MENU_Init();
224//******************************************************************************
225void WIN32API SetWindowAppearance(int fLooks)
226{
227 if(fLooks == OS2_APPEARANCE || fLooks == OS2_APPEARANCE_SYSMENU)
228 {
229 CHAR szDisplay[30];
230 HMODULE hModDisplay;
231
232 SYSCOLOR_Init(FALSE); //use OS/2 colors
233
234 if(hbmFrameMenu[0] == 0)
235 {
236 CHAR szDisplay[30];
237 HMODULE hModDisplay;
238 HDC hdc; /* Device-context handle */
239 DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
240 NULL, NULL, NULL};
241
242 /* create memory device context */
243 hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
244
245 DspInitSystemDriverName(szDisplay, sizeof(szDisplay));
246 DosQueryModuleHandle(szDisplay, &hModDisplay);
247
248 hbmFrameMenu[0] = GpiLoadBitmap(hdc, hModDisplay, SBMP_MINBUTTON, 0, 0);
249 hbmFrameMenu[1] = GpiLoadBitmap(hdc, hModDisplay, SBMP_MAXBUTTON, 0, 0);
250 hbmFrameMenu[2] = GpiLoadBitmap(hdc, hModDisplay, SBMP_RESTOREBUTTON, 0, 0);
251 DevCloseDC(hdc);
252 }
253 }
254 fOS2Look = fLooks;
255 MENU_Init();
256}
257//******************************************************************************
258//******************************************************************************
259void WIN32API CustForceMonoCursor()
260{
261 fForceMonoCursor = TRUE;
262}
263//******************************************************************************
264//CD notification window class
265//******************************************************************************
266MRESULT EXPENTRY Win32CDWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
267{
268#pragma pack(1)
269 typedef struct
270 {
271 BYTE ucCommandInfo;
272 WORD usDriveUnit;
273 } ParameterBlock;
274#pragma pack()
275
276 MRESULT rc = 0;
277 static ULONG drives[26] = {0};
278 static int drivestatus[26] = {0};
279
280 switch( msg )
281 {
282 //OS/2 msgs
283 case WM_CREATE:
284 {
285 char drive[4];
286
287 //skip floppy drives
288 drive[0] = 'C';
289 drive[1] = ':';
290 drive[2] = '\0';
291
292 for(int i=2;i<26;i++) {
293 drives[i] = GetDriveTypeA(drive);
294 if(drives[i] == DRIVE_CDROM_W)
295 {
296 DWORD parsize = sizeof(ParameterBlock);
297 DWORD datasize = 2;
298 WORD status = 0;
299 DWORD rc;
300 ParameterBlock parm;
301
302 parm.ucCommandInfo = 0;
303 parm.usDriveUnit = i;
304 rc = DosDevIOCtl(-1, IOCTL_DISK, DSK_GETLOCKSTATUS, &parm, sizeof(parm), &parsize,
305 &status, sizeof(status), &datasize);
306 if(rc != NO_ERROR) {
307 dprintf(("DosDevIOCtl failed with rc %d", rc));
308 drives[i] = 0;
309 continue;
310 }
311 //if no disk present, return FALSE
312 if(status & 4) {
313 drivestatus[i] = status & 4;
314 }
315 }
316 drive[0]++;
317 }
318 WinStartTimer(hab, hwnd, TIMERID_DRIVEPOLL, 32*60);
319//// WinStartTimer(hab, hwnd, TIMERID_DRIVEPOLL, 32*3);
320//// WinStartTimer(hab, hwnd, TIMERID_DRIVEPOLL, 5000);
321 rc = (MRESULT)FALSE;
322 break;
323 }
324 case WM_TIMER:
325 {
326 for(int i=0;i<26;i++)
327 {
328 //for now only cdrom/dvd drives
329 if(drives[i] == DRIVE_CDROM_W)
330 {
331 DWORD parsize = sizeof(ParameterBlock);
332 DWORD datasize = 2;
333 WORD status = 0;
334 DWORD rc;
335 ParameterBlock parm;
336
337 parm.ucCommandInfo = 0;
338 parm.usDriveUnit = i;
339 rc = DosDevIOCtl(-1, IOCTL_DISK, DSK_GETLOCKSTATUS, &parm, sizeof(parm), &parsize,
340 &status, sizeof(status), &datasize);
341 if(rc != NO_ERROR) {
342 dprintf(("DosDevIOCtl failed with rc %d", rc));
343 return FALSE;
344 }
345 //Send WM_DEVICECHANGE message when CD status changes
346 if((status & 4) != drivestatus[i])
347 {
348 PID pidThis, pidTemp;
349 HENUM henum;
350 HWND hwndEnum;
351 DEV_BROADCAST_VOLUME volchange;
352
353 dprintf(("Disk status 0x%x", status));
354
355 volchange.dbcv_size = sizeof(volchange);
356 volchange.dbcv_devicetype = DBT_DEVTYP_VOLUME;
357 volchange.dbcv_reserved = 0;
358 volchange.dbcv_unitmask = (1 << i);
359 volchange.dbcv_flags = DBTF_MEDIA;
360
361 WinQueryWindowProcess(hwnd, &pidThis, NULL);
362
363 //Iterate over all child windows of the desktop
364 henum = WinBeginEnumWindows(HWND_DESKTOP);
365
366 SetWin32TIB();
367 while(hwndEnum = WinGetNextWindow(henum))
368 {
369 WinQueryWindowProcess(hwndEnum, &pidTemp, NULL);
370 if(pidTemp == pidThis)
371 {
372 HWND hwndWin32 = OS2ToWin32Handle(hwndEnum);
373 if(hwndWin32) {
374 SendMessageA(hwndWin32,
375 WM_DEVICECHANGE_W,
376 (status & 4) ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE,
377 (LPARAM)&volchange);
378 }
379 }
380 }
381 RestoreOS2TIB();
382 WinEndEnumWindows(henum);
383
384 drivestatus[i] = (status & 4);
385 }
386 }
387 }
388 break;
389 }
390
391 case WM_DESTROY:
392 dprintf(("WM_DESTROY for CD notification window"));
393 WinStopTimer(hab, hwnd, TIMERID_DRIVEPOLL);
394 break;
395
396 default:
397 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
398 }
399 return (MRESULT)rc;
400}
401//******************************************************************************
402//Win32 window message handler
403//******************************************************************************
404MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
405{
406 Win32BaseWindow *win32wnd;
407 TEB *teb;
408 MSG winMsg, *pWinMsg;
409 MRESULT rc = 0;
410 POSTMSG_PACKET *postmsg;
411 OSLIBPOINT point, ClientPoint;
412
413 //Restore our FS selector
414 SetWin32TIB();
415
416 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
417 teb = GetThreadTEB();
418 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
419
420//// dprintf(("window %x msg %x", (win32wnd) ? win32wnd->getWindowHandle() : 0, msg));
421
422 if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
423 dprintf(("OS2: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
424 goto RunDefWndProc;
425 }
426//// if(teb->o.odin.fIgnoreMsgs) {
427//// goto RunDefWndProc;
428//// }
429
430 if((teb->o.odin.msgstate & 1) == 0)
431 {//message that was sent directly to our window proc handler; translate it here
432 QMSG qmsg;
433
434 qmsg.msg = msg;
435 qmsg.hwnd = hwnd;
436 qmsg.mp1 = mp1;
437 qmsg.mp2 = mp2;
438 qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
439 WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
440 qmsg.reserved = 0;
441
442 if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
443 {//message was not translated
444 memset(&winMsg, 0, sizeof(MSG));
445 }
446 pWinMsg = &winMsg;
447 }
448 else {
449 pWinMsg = &teb->o.odin.msg;
450 teb->o.odin.msgstate++;
451 }
452 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
453
454 if(msg >= WIN32APP_POSTMSG) {
455 //probably win32 app user message
456 dprintf2(("Posted message %x->%x", msg, msg-WIN32APP_POSTMSG));
457 if((ULONG)mp1 == WIN32MSG_MAGICA) {
458 rc = (MRESULT)win32wnd->DispatchMsgA(pWinMsg);
459 }
460 else
461 if((ULONG)mp1 == WIN32MSG_MAGICW) {
462 rc = (MRESULT)win32wnd->DispatchMsgW(pWinMsg);
463 }
464 else {//broadcasted message
465 rc = (MRESULT)win32wnd->DispatchMsgA(pWinMsg);
466 }
467 RELEASE_WNDOBJ(win32wnd);
468 RestoreOS2TIB();
469 return rc;
470 }
471
472 switch( msg )
473 {
474 //OS/2 msgs
475 case WM_CREATE:
476 {
477 if(teb->o.odin.newWindow == 0)
478 goto createfail;
479
480 //Processing is done in after WinCreateWindow returns
481 dprintf(("OS2: WM_CREATE %x", hwnd));
482 win32wnd = (Win32BaseWindow *)teb->o.odin.newWindow;
483 win32wnd->addRef();
484 teb->o.odin.newWindow = 0;
485 if(win32wnd->MsgCreate(hwnd) == FALSE)
486 {
487 rc = (MRESULT)TRUE; //discontinue window creation
488 break;
489 }
490
491 //Create CD notification window
492 if(hwndCD == 0) {
493 hwndCD = WinCreateWindow(HWND_DESKTOP, WIN32_CDCLASS,
494 NULL, 0, 0, 0, 0, 0,
495 HWND_DESKTOP, HWND_TOP, 0, NULL, NULL);
496 }
497
498 createfail:
499 rc = (MRESULT)FALSE;
500 break;
501 }
502
503 case WM_QUIT:
504 dprintf(("OS2: WM_QUIT %x", hwnd));
505 win32wnd->MsgQuit();
506 break;
507
508 case WM_CLOSE:
509 dprintf(("OS2: WM_CLOSE %x", hwnd));
510 win32wnd->MsgClose();
511 break;
512
513 case WM_DESTROY:
514 dprintf(("OS2: WM_DESTROY %x", hwnd));
515 win32wnd->MsgDestroy();
516 WinSetVisibleRegionNotify(hwnd, FALSE);
517 goto RunDefWndProc;
518
519 case WM_ENABLE:
520 dprintf(("OS2: WM_ENABLE %x", hwnd));
521 break;
522
523 case WM_SHOW:
524 dprintf(("OS2: WM_SHOW %x %d", hwnd, mp1));
525 win32wnd->MsgShow((ULONG)mp1);
526 break;
527
528 case WM_ACTIVATE:
529 {
530 ULONG flags = WinQueryWindowULong(hwnd, OFFSET_WIN32FLAGS);
531
532 dprintf(("OS2: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2));
533 WinSetWindowULong(hwnd, OFFSET_WIN32FLAGS, SHORT1FROMMP(mp1) ? (flags | WINDOWFLAG_ACTIVE):(flags & ~WINDOWFLAG_ACTIVE));
534 if(win32wnd->IsWindowCreated())
535 {
536 win32wnd->MsgActivate((LOWORD(pWinMsg->wParam) == WA_ACTIVE_W) ? 1 : 0, HIWORD(pWinMsg->wParam), pWinMsg->lParam, (HWND)mp2);
537 }
538 break;
539 }
540
541 case WM_SIZE:
542 {
543 dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp1)));
544 win32wnd->SetVisibleRegionChanged(TRUE);
545 goto RunDefWndProc;
546 }
547
548
549 case WM_VRNENABLED:
550 dprintf(("OS2: WM_VRNENABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
551 //Always call handler; even if mp1 is 0. If we don't do this, the
552 //DivX 4 player will never be allowed to draw after putting another window
553 //on top of it.
554 win32wnd->callVisibleRgnNotifyProc(TRUE);
555 if(!win32wnd->isComingToTop() && ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == WS_EX_TOPMOST_W))
556 {
557 HWND hwndrelated;
558 Win32BaseWindow *topwindow;
559
560 win32wnd->setComingToTop(TRUE);
561
562 hwndrelated = WinQueryWindow(hwnd, QW_PREV);
563 dprintf(("WM_VRNENABLED hwndrelated = %x (hwnd=%x)", hwndrelated, hwnd));
564 topwindow = Win32BaseWindow::GetWindowFromOS2Handle(hwndrelated);
565 if(topwindow == NULL || ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == 0)) {
566 //put window at the top of z order
567 WinSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
568 }
569 if(topwindow) RELEASE_WNDOBJ(topwindow);
570
571 win32wnd->setComingToTop(FALSE);
572 break;
573 }
574 goto RunDefWndProc;
575
576 case WM_VRNDISABLED:
577 dprintf(("OS2: WM_VRNDISABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
578 //visible region is about to change or WinLockWindowUpdate called
579 //suspend window drawing
580 win32wnd->callVisibleRgnNotifyProc(FALSE);
581 goto RunDefWndProc;
582
583 case WIN32APP_SETFOCUSMSG:
584 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
585 //must delay this function call
586 //mp1 = win32 window handle
587 //mp2 = top parent if activation required
588 dprintf(("USER32: Delayed SetFocus %x %x %x call!", teb->o.odin.hwndFocus, mp1, mp2));
589 if(teb->o.odin.hwndFocus) {
590 RELEASE_WNDOBJ(win32wnd);
591 win32wnd = Win32BaseWindow::GetWindowFromHandle(teb->o.odin.hwndFocus);
592 if(win32wnd) {
593 if(mp2) {
594 SetActiveWindow((HWND)mp2);
595 }
596 if(!IsWindow(win32wnd->getWindowHandle())) break; //abort if window destroyed
597 WinFocusChange(HWND_DESKTOP, win32wnd->getOS2WindowHandle(), FC_NOSETACTIVE);
598 }
599 else DebugInt3();
600 }
601 break;
602
603 case WM_SETFOCUS:
604 {
605 HWND hwndFocus = (HWND)mp1;
606
607 dprintf(("OS2: WM_SETFOCUS %x %x (%x) %d", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle(hwndFocus), mp2));
608
609 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
610 //must delay this function call
611
612 teb->o.odin.fWM_SETFOCUS = TRUE;
613 teb->o.odin.hwndFocus = 0;
614 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC)
615 {
616 //another (non-win32) application's window
617 //set to NULL (allowed according to win32 SDK) to avoid problems
618 hwndFocus = NULL;
619 }
620 if((ULONG)mp2 == TRUE) {
621 HWND hwndFocusWin32 = OS2ToWin32Handle(hwndFocus);
622 recreateCaret (hwndFocusWin32);
623 win32wnd->MsgSetFocus(hwndFocusWin32);
624 }
625 else win32wnd->MsgKillFocus(OS2ToWin32Handle(hwndFocus));
626 teb->o.odin.fWM_SETFOCUS = FALSE;
627
628 break;
629 }
630
631 //**************************************************************************
632 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
633 //**************************************************************************
634
635 case WM_BUTTON1DOWN:
636 case WM_BUTTON1UP:
637 case WM_BUTTON1DBLCLK:
638 case WM_BUTTON2DOWN:
639 case WM_BUTTON2UP:
640 case WM_BUTTON2DBLCLK:
641 case WM_BUTTON3DOWN:
642 case WM_BUTTON3UP:
643 case WM_BUTTON3DBLCLK:
644 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
645 RELEASE_WNDOBJ(win32wnd);
646 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
647 }
648 if(win32wnd)
649 win32wnd->MsgButton(pWinMsg);
650
651 rc = (MRESULT)TRUE;
652 break;
653
654 case WM_BUTTON2MOTIONSTART:
655 case WM_BUTTON2MOTIONEND:
656 case WM_BUTTON2CLICK:
657 case WM_BUTTON1MOTIONSTART:
658 case WM_BUTTON1MOTIONEND:
659 case WM_BUTTON1CLICK:
660 case WM_BUTTON3MOTIONSTART:
661 case WM_BUTTON3MOTIONEND:
662 case WM_BUTTON3CLICK:
663 rc = (MRESULT)TRUE;
664 break;
665
666 case WM_MOUSEMOVE:
667 {
668 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
669 RELEASE_WNDOBJ(win32wnd);
670 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
671 }
672 if(win32wnd)
673 win32wnd->MsgMouseMove(pWinMsg);
674 break;
675 }
676
677 case WM_CONTROL:
678 goto RunDefWndProc;
679
680 case WM_COMMAND:
681 dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2));
682 win32wnd->DispatchMsgA(pWinMsg);
683 break;
684
685 case WM_SYSCOMMAND:
686 dprintf(("OS2: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
687 win32wnd->DispatchMsgA(pWinMsg);
688 break;
689
690 case WM_RENDERFMT:
691 case WM_RENDERALLFMTS:
692 case WM_DESTROYCLIPBOARD:
693 win32wnd->DispatchMsgA(pWinMsg);
694 break;
695
696 case WM_CHAR_SPECIAL:
697 /* NO BREAK! FALLTHRU CASE! */
698
699 case WM_CHAR:
700 dprintf(("OS2: WM_CHAR %x %x %x, %x %x", win32wnd->getWindowHandle(), mp1, mp2, pWinMsg->wParam, pWinMsg->lParam));
701 win32wnd->MsgChar(pWinMsg);
702 break;
703
704 case WM_TIMER:
705 dprintf(("OS2: WM_TIMER %x %x time %x", win32wnd->getWindowHandle(), pWinMsg->wParam, GetTickCount()));
706 win32wnd->DispatchMsgA(pWinMsg);
707 goto RunDefWndProc;
708
709 case WM_SETWINDOWPARAMS:
710 {
711 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
712
713 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
714 if(wndParams->fsStatus & WPM_TEXT) {
715 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
716 }
717 goto RunDefWndProc;
718 }
719
720 case WM_QUERYWINDOWPARAMS:
721 {
722 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
723 ULONG textlen;
724 PSZ wintext;
725
726 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
727 {
728 if(wndpars->fsStatus & WPM_TEXT)
729 win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
730 if(wndpars->fsStatus & WPM_CCHTEXT)
731 wndpars->cchText = win32wnd->MsgGetTextLength();
732
733 wndpars->fsStatus = 0;
734 wndpars->cbCtlData = 0;
735 wndpars->cbPresParams = 0;
736 rc = (MRESULT)TRUE;
737 break;
738 }
739 goto RunDefWndProc;
740 }
741
742 case WM_PAINT:
743 {
744 RECTL rectl;
745 BOOL rc;
746
747 rc = WinQueryUpdateRect(hwnd, &rectl);
748 dprintf(("OS2: WM_PAINT %x (%d,%d) (%d,%d) rc=%d", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop, rc));
749
750 if(rc && win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
751 rectl.yBottom != rectl.yTop))
752 {
753 win32wnd->DispatchMsgA(pWinMsg);
754 }
755 else goto RunDefWndProc;
756 break;
757 }
758
759 case WM_ERASEBACKGROUND:
760 {
761 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
762 rc = (MRESULT)FALSE;
763 break;
764 }
765
766 case WM_CALCVALIDRECTS:
767 dprintf(("OS2: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
768 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
769 break;
770
771 case WM_REALIZEPALETTE:
772 {
773 dprintf(("OS2: WM_REALIZEPALETTE"));
774 goto RunDefWndProc;
775 }
776
777 case WM_HSCROLL:
778 case WM_VSCROLL:
779 dprintf(("OS2: %s %x %x %x", (msg == WM_HSCROLL) ? "WM_HSCROLL" : "WM_VSCROLL", win32wnd->getWindowHandle(), mp1, mp2));
780 win32wnd->DispatchMsgA(pWinMsg);
781 break;
782
783 case DM_DRAGOVER:
784 {
785 PDRAGINFO pDragInfo = (PDRAGINFO)mp1;
786 PDRAGITEM pDragItem;
787 USHORT sxDrop = SHORT1FROMMP(mp2);
788 USHORT syDrop = SHORT2FROMMP(mp2);
789 USHORT usIndicator, usOp;
790 ULONG ulBytes;
791 int i, cItems;
792 BOOL ret;
793 char szFileName[CCHMAXPATH];
794 char szContainerName[CCHMAXPATH];
795
796 dprintf(("OS2: DM_DRAGOVER %x (%d,%d)", win32wnd->getWindowHandle(), sxDrop, syDrop));
797
798 //does this window accept dropped files?
799 if(!DragDropAccept(win32wnd->getWindowHandle())) {
800 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
801 break;
802 }
803 /* Get access to the DRAGINFO data structure */
804 if(!DrgAccessDraginfo(pDragInfo)) {
805 rc = (MRFROM2SHORT (DOR_NODROP, 0));
806 break;
807 }
808
809 /* Can we accept this drop? */
810 switch (pDragInfo->usOperation) {
811 /* Return DOR_NODROPOP if current operation */
812 /* is link or unknown */
813 case DO_LINK:
814 case DO_COPY:
815 case DO_UNKNOWN:
816 DrgFreeDraginfo(pDragInfo);
817 rc = (MRFROM2SHORT (DOR_NODROPOP, 0));
818 break;
819
820 /* Our default operation is Move */
821 case DO_MOVE:
822 case DO_DEFAULT:
823 pDragItem = DrgQueryDragitemPtr(pDragInfo, 0);
824 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
825 sizeof(szContainerName),
826 szContainerName);
827 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
828 sizeof(szFileName),
829 szFileName);
830 if (!ulBytes) {
831 rc = (MRFROM2SHORT (DOR_NODROPOP, 0));
832 break;
833 }
834 else usOp = DO_MOVE;
835
836 dprintf(("dropped file %s%s", szContainerName, szFileName));
837 break;
838 }
839 if(rc == MRFROM2SHORT (DOR_NODROPOP, 0)) {
840 break;
841 }
842
843 usIndicator = (USHORT)DOR_DROP;
844 cItems = DrgQueryDragitemCount(pDragInfo);
845
846 /* Now, we need to look at each item in turn */
847 for (i = 0; i < cItems; i++) {
848 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
849
850 /* Make sure we can move for a Move request */
851 if ((pDragItem->fsSupportedOps & DO_MOVEABLE) &&
852 (usOp == (USHORT)DO_MOVE))
853 {
854 usIndicator = DOR_DROP;
855 }
856 else {
857 dprintf(("item %d not accepted", i));
858 usIndicator = DOR_NODROPOP;
859 break;
860 }
861 }
862 /* Release the draginfo data structure */
863 DrgFreeDraginfo(pDragInfo);
864
865 dprintf(("return %x", MRFROM2SHORT(usIndicator, usOp)));
866 rc = (MRFROM2SHORT(usIndicator, usOp));
867 break;
868 }
869
870 case DM_DRAGLEAVE:
871 {
872 dprintf(("OS2: DM_DRAGLEAVE %x", win32wnd->getWindowHandle()));
873 break;
874 }
875
876 case DM_DROP:
877 {
878 PDRAGINFO pDragInfo = (PDRAGINFO)mp1;
879 PDRAGITEM pDragItem;
880 USHORT sxDrop = SHORT1FROMMP(mp2);
881 USHORT syDrop = SHORT2FROMMP(mp2);
882 USHORT usIndicator, usOp;
883 ULONG ulBytes;
884 int i, cItems;
885 BOOL ret;
886 char szFileName[CCHMAXPATH];
887 char szContainerName[CCHMAXPATH];
888
889 dprintf(("OS2: DM_DROP %x (%d,%d)", win32wnd->getWindowHandle(), sxDrop, syDrop));
890
891 //does this window accept dropped files?
892 if(!DragDropAccept(win32wnd->getWindowHandle())) {
893 rc = 0;
894 break;
895 }
896 /* Get access to the DRAGINFO data structure */
897 if(!DrgAccessDraginfo(pDragInfo)) {
898 rc = 0;
899 break;
900 }
901
902 usIndicator = (USHORT)DOR_DROP;
903 cItems = DrgQueryDragitemCount(pDragInfo);
904
905 //computer memory required to hold all filenames
906 int bufsize = 0;
907 for (i = 0; i < cItems; i++) {
908 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
909
910 bufsize += DrgQueryStrNameLen(pDragItem->hstrContainerName) + DrgQueryStrNameLen(pDragItem->hstrSourceName);
911 bufsize++; //0 terminator
912 bufsize++; //+ potential missing backslash
913 }
914 //copy all filenames
915 char *pszFiles = (char *)malloc(bufsize);
916 if(pszFiles == NULL) {
917 dprintf(("Out of memory!!"));
918 DebugInt3();
919 break;
920 }
921 char *pszCurFile = pszFiles;
922
923 for (i = 0; i < cItems; i++) {
924 char *pszTemp = pszCurFile;
925
926 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
927
928 ulBytes = DrgQueryStrNameLen(pDragItem->hstrContainerName);
929
930 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
931 ulBytes, pszCurFile);
932 if(pszCurFile[ulBytes-1] != '\\') {
933 pszCurFile[ulBytes] = '\\';
934 pszCurFile++;
935 }
936 pszCurFile += ulBytes;
937
938 ulBytes = DrgQueryStrNameLen(pDragItem->hstrSourceName);
939 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
940 ulBytes+1, pszCurFile);
941 pszCurFile += ulBytes + 1; //+ terminator
942
943 dprintf(("dropped file %s", pszTemp));
944 }
945 POINT point = {sxDrop, syDrop};
946 DragDropFiles(win32wnd->getWindowHandle(), cItems, point, pszFiles, bufsize);
947 free(pszFiles);
948
949 /* Release the draginfo data structure */
950 DrgFreeDraginfo(pDragInfo);
951
952 rc = 0;
953 break;
954 }
955
956 case WM_DDE_INITIATE:
957 case WM_DDE_INITIATEACK:
958 case WM_DDE_REQUEST:
959 case WM_DDE_ACK:
960 case WM_DDE_DATA:
961 case WM_DDE_ADVISE:
962 case WM_DDE_UNADVISE:
963 case WM_DDE_POKE:
964 case WM_DDE_EXECUTE:
965 case WM_DDE_TERMINATE:
966 dprintf(("OS2: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
967 goto RunDefWndProc;
968
969 case WM_INITMENU:
970 case WM_MENUSELECT:
971 case WM_MENUEND:
972 case WM_NEXTMENU:
973 case WM_SYSCOLORCHANGE:
974 case WM_SYSVALUECHANGED:
975 case WM_SETSELECTION:
976 case WM_PPAINT:
977 case WM_PSETFOCUS:
978 case WM_PSYSCOLORCHANGE:
979 case WM_PSIZE:
980 case WM_PACTIVATE:
981 case WM_PCONTROL:
982 case WM_HELP:
983 case WM_APPTERMINATENOTIFY:
984 case WM_PRESPARAMCHANGED:
985 case WM_DRAWITEM:
986 case WM_MEASUREITEM:
987 case WM_CONTROLPOINTER:
988 case WM_QUERYDLGCODE:
989 case WM_SUBSTITUTESTRING:
990 case WM_MATCHMNEMONIC:
991 case WM_SAVEAPPLICATION:
992 case WM_SEMANTICEVENT:
993 default:
994 dprintf2(("OS2: RunDefWndProc hwnd %x msg %x mp1 %x mp2 %x", hwnd, msg, mp1, mp2));
995 goto RunDefWndProc;
996 }
997 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
998 RestoreOS2TIB();
999 return (MRESULT)rc;
1000
1001RunDefWndProc:
1002// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
1003 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1004 RestoreOS2TIB();
1005 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
1006} /* End of Win32WindowProc */
1007//******************************************************************************
1008//******************************************************************************
1009MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1010{
1011 POSTMSG_PACKET *postmsg;
1012 OSLIBPOINT point, ClientPoint;
1013 Win32BaseWindow *win32wnd;
1014 TEB *teb;
1015 MRESULT rc = 0;
1016 MSG winMsg, *pWinMsg;
1017
1018 //Restore our FS selector
1019 SetWin32TIB();
1020
1021 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
1022 teb = GetThreadTEB();
1023 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
1024
1025 if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
1026 dprintf(("PMFRAME: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
1027 goto RunDefFrameWndProc;
1028 }
1029//// if(teb->o.odin.fIgnoreMsgs) {
1030//// goto RunDefWndProc;
1031//// }
1032
1033 if((teb->o.odin.msgstate & 1) == 0)
1034 {//message that was sent directly to our window proc handler; translate it here
1035 QMSG qmsg;
1036
1037 qmsg.msg = msg;
1038 qmsg.hwnd = hwnd;
1039 qmsg.mp1 = mp1;
1040 qmsg.mp2 = mp2;
1041 qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
1042 WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
1043 qmsg.reserved = 0;
1044
1045 if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
1046 {//message was not translated
1047 memset(&winMsg, 0, sizeof(MSG));
1048 }
1049 pWinMsg = &winMsg;
1050 }
1051 else {
1052 pWinMsg = &teb->o.odin.msg;
1053 teb->o.odin.msgstate++;
1054 }
1055 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
1056
1057 switch( msg )
1058 {
1059 case WM_CREATE:
1060 {
1061 //WM_CREATE handled during client window creation
1062 dprintf(("PMFRAME: WM_CREATE %x", hwnd));
1063 goto RunDefFrameWndProc;
1064 }
1065
1066#ifdef DEBUG
1067 case WM_CLOSE:
1068 {
1069 dprintf(("PMFRAME: WM_CLOSE %x", hwnd));
1070 goto RunDefFrameWndProc;
1071 }
1072#endif
1073
1074 case WM_PAINT:
1075 {
1076 RECTL rectl;
1077
1078 HPS hps = WinBeginPaint(hwnd, NULL, &rectl);
1079 dprintf(("PMFRAME: WM_PAINT %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
1080
1081 if(win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
1082 rectl.yBottom != rectl.yTop))
1083 {
1084 PRECT pClient = win32wnd->getClientRectPtr();
1085 PRECT pWindow = win32wnd->getWindowRect();
1086
1087 if(!(pClient->left == 0 && pClient->top == 0 &&
1088 win32wnd->getClientHeight() == win32wnd->getWindowHeight() &&
1089 win32wnd->getClientWidth() == win32wnd->getWindowWidth()))
1090 {
1091 RECT rectUpdate;
1092
1093 mapOS2ToWin32Rect(win32wnd->getWindowHeight(), (PRECTLOS2)&rectl, &rectUpdate);
1094 win32wnd->MsgNCPaint(&rectUpdate);
1095 }
1096 }
1097 WinEndPaint(hps);
1098 break;
1099 }
1100
1101 case WM_ERASEBACKGROUND:
1102 {
1103 dprintf(("PMFRAME:WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
1104 rc = (MRESULT)FALSE;
1105 break;
1106 }
1107
1108 //**************************************************************************
1109 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
1110 //**************************************************************************
1111
1112 case WM_BUTTON1DOWN:
1113 case WM_BUTTON1UP:
1114 case WM_BUTTON1DBLCLK:
1115 case WM_BUTTON2DOWN:
1116 case WM_BUTTON2UP:
1117 case WM_BUTTON2DBLCLK:
1118 case WM_BUTTON3DOWN:
1119 case WM_BUTTON3UP:
1120 case WM_BUTTON3DBLCLK:
1121 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
1122 RELEASE_WNDOBJ(win32wnd);
1123 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
1124 }
1125 if(win32wnd)
1126 win32wnd->MsgButton(pWinMsg);
1127
1128 rc = (MRESULT)TRUE;
1129 break;
1130
1131 case WM_BUTTON2MOTIONSTART:
1132 case WM_BUTTON2MOTIONEND:
1133 case WM_BUTTON2CLICK:
1134 case WM_BUTTON1MOTIONSTART:
1135 case WM_BUTTON1MOTIONEND:
1136 case WM_BUTTON1CLICK:
1137 case WM_BUTTON3MOTIONSTART:
1138 case WM_BUTTON3MOTIONEND:
1139 case WM_BUTTON3CLICK:
1140 rc = (MRESULT)TRUE;
1141 break;
1142
1143 case WM_MOUSEMOVE:
1144 {
1145 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
1146 RELEASE_WNDOBJ(win32wnd);
1147 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
1148 }
1149 if(win32wnd)
1150 win32wnd->MsgMouseMove(pWinMsg);
1151 break;
1152 }
1153
1154 case WM_ADJUSTWINDOWPOS:
1155 {
1156 PSWP pswp = (PSWP)mp1;
1157 SWP swpOld;
1158 WINDOWPOS wp,wpOld;
1159 ULONG ulFlags;
1160 ULONG ret = 0;
1161 HWND hParent = NULLHANDLE, hwndAfter;
1162
1163 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));
1164
1165 ulFlags = pswp->fl;
1166
1167 if(win32wnd->IsParentChanging()) {
1168 rc = 0;
1169 break;
1170 }
1171
1172 //@@PF all commands from minimized window viewer or from Ctrl-Esc
1173 //are 'pure' and should be handled only by DeFrameProc - this is weird
1174 //but without them we will not have results. Pure = plain flag of restore/minimize/maximize
1175 if((pswp->fl == SWP_MINIMIZE) || (pswp->fl & SWP_RESTORE)) {
1176 // note the purity of SWP no other SWP_FLAGS allowed
1177 goto RunDefFrameWndProc;
1178 }
1179
1180 if(pswp->fl & SWP_NOADJUST) {
1181 //ignore weird messages (TODO: why are they sent?)
1182 dprintf(("WARNING: WM_ADJUSTWINDOWPOS with SWP_NOADJUST flag!!"));
1183 break;
1184 }
1185 if ((pswp->fl == SWP_FOCUSACTIVATE) || (pswp->fl == SWP_FOCUSDEACTIVATE))
1186 {
1187 dprintf(("Pure focus flags are not sent to win32 windows"));
1188 goto RunDefFrameWndProc;
1189 }
1190
1191 //CB: show dialog in front of owner
1192 if (win32wnd->IsModalDialogOwner())
1193 {
1194 dprintf(("win32wnd->IsModalDialogOwner %x", win32wnd->getWindowHandle()));
1195 pswp->fl |= SWP_ZORDER;
1196 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
1197 if (pswp->fl & SWP_ACTIVATE)
1198 {
1199 pswp->fl &= ~SWP_ACTIVATE;
1200 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
1201 }
1202 }
1203
1204 if(!win32wnd->CanReceiveSizeMsgs())
1205 break;
1206
1207 WinQueryWindowPos(hwnd, &swpOld);
1208 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
1209 if (win32wnd->isChild()) {
1210 if(win32wnd->getParent()) {
1211 hParent = win32wnd->getParent()->getOS2WindowHandle();
1212 }
1213 else goto RunDefFrameWndProc;
1214 }
1215 }
1216 hwndAfter = pswp->hwndInsertBehind;
1217 if(win32wnd->getParent()) {
1218 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(), hwnd);
1219 }
1220 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1221
1222 wp.hwnd = win32wnd->getWindowHandle();
1223 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1224 {
1225 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1226 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
1227 if(wndAfter) {
1228 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1229 RELEASE_WNDOBJ(wndAfter);
1230 }
1231 else wp.hwndInsertAfter = HWND_TOP_W;
1232 }
1233
1234 wpOld = wp;
1235 win32wnd->MsgPosChanging((LPARAM)&wp);
1236
1237 if(win32wnd->getOldStyle() != win32wnd->getStyle())
1238 {
1239 OSLibSetWindowStyle(win32wnd->getOS2FrameWindowHandle(), win32wnd->getOS2WindowHandle(), win32wnd->getStyle(), win32wnd->getExStyle());
1240 if(fOS2Look) {
1241 DWORD dwOldStyle = win32wnd->getOldStyle();
1242 DWORD dwStyle = win32wnd->getStyle();
1243
1244 win32wnd->setOldStyle(dwStyle);
1245 if((dwOldStyle & WS_MINIMIZE_W) && !(dwStyle & WS_MINIMIZE_W)) {
1246 //SC_RESTORE -> SC_MINIMIZE
1247 dprintf(("%x -> SC_RESTORE -> SC_MINIMIZE", win32wnd->getWindowHandle()));
1248 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_RESTORE, SC_MINIMIZE, hbmFrameMenu[0]);
1249 if(dwStyle & WS_MAXIMIZE_W) {
1250 //SC_MAXIMIZE -> SC_RESTORE
1251 dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
1252 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[2]);
1253 }
1254 }
1255 else
1256 if((dwOldStyle & WS_MAXIMIZE_W) && !(dwStyle & WS_MAXIMIZE_W)) {
1257 //SC_RESTORE -> SC_MAXIMIZE
1258 dprintf(("%x -> SC_RESTORE -> SC_MAXIMIZE", win32wnd->getWindowHandle()));
1259 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_RESTORE, SC_MAXIMIZE, hbmFrameMenu[1]);
1260 }
1261 else
1262 if(!(dwOldStyle & WS_MINIMIZE_W) && (dwStyle & WS_MINIMIZE_W)) {
1263 //SC_MINIMIZE -> SC_RESTORE
1264 dprintf(("%x -> SC_MINIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
1265 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_MINIMIZE, SC_RESTORE, hbmFrameMenu[2]);
1266 }
1267 else
1268 if(!(dwOldStyle & WS_MAXIMIZE_W) && (dwStyle & WS_MAXIMIZE_W)) {
1269 //SC_MAXIMIZE -> SC_RESTORE
1270 dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
1271 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[2]);
1272 }
1273 }
1274 }
1275
1276 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
1277 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
1278 {
1279 ULONG flags = pswp->fl; //make a backup copy; OSLibMapWINDOWPOStoSWP will modify it
1280
1281 dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
1282 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
1283
1284 if(win32wnd->getParent()) {
1285 OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getClientHeight(),
1286 hwnd);
1287 }
1288 else OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1289
1290 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
1291
1292 //OSLibMapWINDOWPOStoSWP can add flags, but we must not let it remove flags!
1293 if(pswp->fl & SWP_SIZE)
1294 flags |= SWP_SIZE;
1295
1296 if(pswp->fl & SWP_MOVE)
1297 flags |= SWP_MOVE;
1298
1299 pswp->fl = flags; //restore flags
1300
1301 pswp->fl |= SWP_NOADJUST;
1302 pswp->hwndInsertBehind = hwndAfter;
1303 pswp->hwnd = hwnd;
1304
1305 ret = 0xf;
1306 }
1307adjustend:
1308 //The next part needs to be done for top-level windows only
1309 if(!((win32wnd->getStyle() & (WS_POPUP_W|WS_CHILD_W)) == WS_CHILD_W))
1310 {
1311 //Setting these flags is necessary to avoid activation/focus problems
1312 if(ulFlags & SWP_DEACTIVATE) {
1313 ret |= AWP_DEACTIVATE;
1314 }
1315 if(ulFlags & SWP_ACTIVATE)
1316 {
1317 if(ulFlags & SWP_ZORDER) {
1318 dprintf(("Set FF_NOACTIVATESWP"));
1319 ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
1320 WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags | FF_NOACTIVATESWP);
1321 }
1322
1323 if(!(ulFlags & SWP_SHOW))
1324 {
1325 ret |= AWP_ACTIVATE;
1326 }
1327 else
1328 {
1329 FrameSetFocus(hwnd);
1330 }
1331 }
1332 }
1333 else {
1334 if(ulFlags & (SWP_ACTIVATE|SWP_FOCUSACTIVATE))
1335 {
1336 win32wnd->MsgChildActivate(TRUE);
1337 if(fOS2Look) {
1338 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1339 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, (MPARAM)1, 0);
1340 }
1341 }
1342 else
1343 if(ulFlags & (SWP_DEACTIVATE|SWP_FOCUSDEACTIVATE))
1344 {
1345 win32wnd->MsgChildActivate(FALSE);
1346 if(fOS2Look) {
1347 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1348 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, 0, 0);
1349 }
1350 }
1351 }
1352 dprintf(("WM_ADJUSTWINDOWPOS ret %x flags %x", ret, WinQueryWindowUShort(hwnd, QWS_FLAGS)));
1353 rc = (MRESULT)ret;
1354 break;
1355 }
1356
1357 case WM_WINDOWPOSCHANGED:
1358 {
1359 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
1360 SWP swpOld = *(pswp + 1);
1361 WINDOWPOS wp;
1362 ULONG flAfp = (ULONG)mp2;
1363 HWND hParent = NULLHANDLE;
1364 RECTL rect;
1365
1366 dprintf(("PMFRAME:WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
1367 if(win32wnd->IsParentChanging()) {
1368 goto PosChangedEnd;
1369 }
1370
1371 //SvL: When a window is made visible, then we don't receive a
1372 // WM_VRNENABLED message (for some weird reason)
1373 if(pswp->fl & SWP_SHOW) {
1374 win32wnd->callVisibleRgnNotifyProc(TRUE);
1375 }
1376 else
1377 if(pswp->fl & SWP_HIDE) {
1378 win32wnd->callVisibleRgnNotifyProc(FALSE);
1379 }
1380
1381 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
1382 {
1383 if(pswp->fl & SWP_RESTORE && win32wnd->getStyle() & WS_MINIMIZE_W) {
1384 dprintf(("Restoring minimized window %x", win32wnd->getWindowHandle()));
1385 win32wnd->ShowWindow(SW_RESTORE_W);
1386 }
1387 if(pswp->fl & SWP_SHOW) {
1388 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
1389 }
1390 else
1391 if(pswp->fl & SWP_HIDE) {
1392 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
1393 }
1394 //MUST call the old frame window proc!
1395 goto RunDefFrameWndProc;
1396 }
1397
1398 if(pswp->fl & (SWP_MOVE | SWP_SIZE))
1399 {
1400 if(win32wnd->isChild())
1401 {
1402 if(win32wnd->getParent()) {
1403 hParent = win32wnd->getParent()->getOS2WindowHandle();
1404 }
1405 else goto PosChangedEnd; //parent has just been destroyed
1406 }
1407 }
1408
1409
1410 if(win32wnd->getParent()) {
1411 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1412 hwnd);
1413 }
1414 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1415
1416 wp.hwnd = win32wnd->getWindowHandle();
1417 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1418 {
1419 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1420 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
1421 if(wndAfter) {
1422 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1423 RELEASE_WNDOBJ(wndAfter);
1424 }
1425 else wp.hwndInsertAfter = HWND_TOP_W;
1426 }
1427
1428 if(pswp->fl & SWP_SHOW) {
1429 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
1430 }
1431 else
1432 if(pswp->fl & SWP_HIDE) {
1433 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
1434 }
1435
1436 if(flAfp & AWP_ACTIVATE)
1437 {
1438 FrameSetFocus(hwnd);
1439 }
1440
1441#ifndef USE_CALCVALIDRECT
1442 if((pswp->fl & (SWP_MOVE | SWP_SIZE)))
1443 {
1444 //CB: todo: use result for WM_CALCVALIDRECTS
1445 //Get old client rectangle (for invalidation of frame window parts later on)
1446 //Use new window height to calculate the client area
1447 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
1448
1449 //Note: Also updates the new window rectangle
1450 win32wnd->MsgFormatFrame(&wp);
1451
1452 if(win32wnd->isOwnDC()) {
1453 setPageXForm(win32wnd, (pDCData)GpiQueryDCData(win32wnd->getOwnDC()));
1454 }
1455
1456 if(win32wnd->CanReceiveSizeMsgs())
1457 win32wnd->MsgPosChanged((LPARAM)&wp);
1458
1459 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
1460 {
1461 //redraw the frame (to prevent unnecessary client updates)
1462 BOOL redrawAll = FALSE;
1463
1464 dprintf2(("WM_WINDOWPOSCHANGED: redraw frame"));
1465 if (win32wnd->getWindowClass())
1466 {
1467 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
1468
1469 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
1470 redrawAll = TRUE;
1471 else
1472 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
1473 redrawAll = TRUE;
1474 }
1475 else redrawAll = TRUE;
1476
1477 if(win32wnd->IsMixMaxStateChanging()) {
1478 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1479 redrawAll = TRUE;
1480 }
1481
1482 if (redrawAll)
1483 {
1484 //CB: redraw all children for now
1485 // -> problems with update region if we don't do it
1486 // todo: rewrite whole handling
1487 WinInvalidateRect(hwnd,NULL,TRUE);
1488 }
1489 else
1490 {
1491 HPS hps = WinGetPS(hwnd);
1492 RECTL frame,client,arcl[4];
1493
1494 WinQueryWindowRect(hwnd,&frame);
1495
1496 //top
1497 arcl[0].xLeft = 0;
1498 arcl[0].xRight = frame.xRight;
1499 arcl[0].yBottom = rect.yTop;
1500 arcl[0].yTop = frame.yTop;
1501 //right
1502 arcl[1].xLeft = rect.xRight;
1503 arcl[1].xRight = frame.xRight;
1504 arcl[1].yBottom = 0;
1505 arcl[1].yTop = frame.yTop;
1506 //left
1507 arcl[2].xLeft = 0;
1508 arcl[2].xRight = rect.xLeft;
1509 arcl[2].yBottom = 0;
1510 arcl[2].yTop = frame.yTop;
1511 //bottom
1512 arcl[3].xLeft = 0;
1513 arcl[3].xRight = frame.xRight;
1514 arcl[3].yBottom = 0;
1515 arcl[3].yTop = rect.yBottom;
1516
1517 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
1518
1519 WinInvalidateRegion(hwnd,hrgn,FALSE);
1520 GpiDestroyRegion(hps,hrgn);
1521 WinReleasePS(hps);
1522 }
1523 }
1524 }
1525 else
1526 {
1527#endif //USE_CALCVALIDRECT
1528 if(win32wnd->CanReceiveSizeMsgs())
1529 win32wnd->MsgPosChanged((LPARAM)&wp);
1530#ifndef USE_CALCVALIDRECT
1531 }
1532#endif
1533
1534PosChangedEnd:
1535 rc = (MRESULT)FALSE;
1536 break;
1537 }
1538
1539 case WM_CALCVALIDRECTS:
1540#ifdef USE_CALCVALIDRECT
1541 {
1542 PRECTL oldRect = (PRECTL)mp1, newRect = oldRect+1;
1543 PSWP pswp = (PSWP)mp2;
1544 SWP swpOld;
1545 WINDOWPOS wp;
1546 RECTL newClientRect, oldClientRect;
1547 ULONG nccalcret;
1548// UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
1549 UINT res = 0;
1550
1551 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1552
1553 //Get old position info
1554 WinQueryWindowPos(hwnd, &swpOld);
1555
1556 if(win32wnd->getParent()) {
1557 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1558 win32wnd->getParent()->getClientRectPtr()->left,
1559 win32wnd->getParent()->getClientRectPtr()->top,
1560 hwnd);
1561 }
1562 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
1563
1564 wp.hwnd = win32wnd->getWindowHandle();
1565 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1566 {
1567 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1568 if(wndAfter) {
1569 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1570 RELEASE_WNDOBJ(wndAfter);
1571 }
1572 else wp.hwndInsertAfter = HWND_TOP_W;
1573 }
1574
1575 //Get old client rectangle
1576 mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
1577
1578 //Note: Also updates the new window rectangle
1579 nccalcret = win32wnd->MsgFormatFrame(&wp);
1580
1581 //Get new client rectangle
1582 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
1583
1584 if(nccalcret == 0) {
1585 res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
1586 }
1587 else {
1588 if(nccalcret & WVR_ALIGNTOP_W) {
1589 res |= CVR_ALIGNTOP;
1590 }
1591 else
1592 if(nccalcret & WVR_ALIGNBOTTOM_W) {
1593 res |= CVR_ALIGNBOTTOM;
1594 }
1595
1596 if(nccalcret & WVR_ALIGNLEFT_W) {
1597 res |= CVR_ALIGNLEFT;
1598 }
1599 else
1600 if(nccalcret & WVR_ALIGNRIGHT_W) {
1601 res |= CVR_ALIGNRIGHT;
1602 }
1603
1604 if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
1605 res |= CVR_REDRAW;
1606 }
1607 else
1608 if(nccalcret & WVR_VALIDRECTS_W) {
1609 //TODO:
1610 //res = 0;
1611 }
1612 }
1613 if(win32wnd->IsMixMaxStateChanging()) {
1614 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1615 res |= CVR_REDRAW;
1616 }
1617 if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
1618 oldRect->xRight -= oldClientRect.xLeft;
1619 oldRect->yBottom += oldClientRect.yBottom;
1620 newRect->xRight -= newClientRect.xLeft;
1621 newRect->yBottom += newClientRect.yBottom;
1622 }
1623 rc = res;
1624 break;
1625 }
1626#else
1627 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1628 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
1629 break;
1630#endif
1631
1632 case WM_CALCFRAMERECT:
1633 dprintf(("PMFRAME:WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
1634 rc = (MRESULT)TRUE;
1635 break;
1636
1637 case WM_QUERYCTLTYPE:
1638 // This is a frame window
1639 dprintf(("PMFRAME:WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
1640 rc = (MRESULT)CCT_FRAME;
1641 break;
1642
1643#ifdef DEBUG
1644 case WM_QUERYFOCUSCHAIN:
1645 dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x parent %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), (mp2) ? OS2ToWin32Handle((DWORD)mp2) : 0));
1646
1647 RestoreOS2TIB();
1648 rc = pfnFrameWndProc(hwnd, msg, mp1, mp2);
1649 SetWin32TIB();
1650 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));
1651 break;
1652// goto RunDefFrameWndProc;
1653#endif
1654
1655 case WM_FOCUSCHANGE:
1656 {
1657 HWND hwndFocus = (HWND)mp1;
1658 HWND hwndLoseFocus, hwndGainFocus;
1659 USHORT usSetFocus = SHORT1FROMMP(mp2);
1660 USHORT fsFocusChange = SHORT2FROMMP(mp2);
1661
1662 //Save window that gains focus so we can determine which
1663 //process we lose activation to
1664 hwndFocusChange = (HWND)mp1;
1665
1666 dprintf(("PMFRAME:WM_FOCUSCHANGE %x %x (%x) %x %x", win32wnd->getWindowHandle(), OS2ToWin32Handle(hwndFocus), hwndFocus, usSetFocus, fsFocusChange));
1667 goto RunDefFrameWndProc;
1668 }
1669
1670#ifdef DEBUG
1671 case WM_SETFOCUS:
1672 {
1673 dprintf(("PMFRAME: WM_SETFOCUS %x %x", win32wnd->getWindowHandle(), hwnd));
1674 goto RunDefFrameWndProc;
1675 }
1676#endif
1677
1678 case WM_ACTIVATE:
1679 {
1680 HWND hwndTitle;
1681 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
1682
1683 dprintf(("PMFRAME: WM_ACTIVATE %x %x %x", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle((DWORD)mp2)));
1684 if (win32wnd->IsWindowCreated())
1685 {
1686 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1687 if(fOS2Look) {
1688 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1689 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, mp1, 0);
1690 }
1691 if(SHORT1FROMMP(mp1) == 0) {
1692 //deactivate
1693 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
1694 }
1695 PID pidThis, pidPartner, pidTemp;
1696 TID tidPartner;
1697 HENUM henum;
1698 HWND hwndEnum;
1699
1700 WinQueryWindowProcess(hwnd, &pidThis, NULL);
1701 WinQueryWindowProcess(hwndFocusChange, &pidPartner, &tidPartner);
1702
1703 if(pidThis != pidPartner) {
1704 //Gain or lose activation to window in other process
1705 //must send WM_ACTIVATEAPP to top-level windows
1706
1707 //Iterate over all child windows of the desktop
1708 henum = WinBeginEnumWindows(HWND_DESKTOP);
1709
1710 while(hwndEnum = WinGetNextWindow(henum))
1711 {
1712 WinQueryWindowProcess(hwndEnum, &pidTemp, NULL);
1713 if(pidTemp == pidThis)
1714 {
1715 SendMessageA(OS2ToWin32Handle(hwndEnum), WM_ACTIVATEAPP_W, (WPARAM)SHORT1FROMMP(mp1), (LPARAM)tidPartner);
1716 }
1717 }
1718 WinEndEnumWindows(henum);
1719 }
1720 if(SHORT1FROMMP(mp1)) {
1721 //activate
1722 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
1723 }
1724
1725 //CB: show owner behind the dialog
1726 if (win32wnd->IsModalDialog())
1727 {
1728 if(win32wnd->getOwner()) {
1729 Win32BaseWindow *topOwner = Win32BaseWindow::GetWindowFromHandle(win32wnd->getOwner()->GetTopParent());
1730
1731 if (topOwner) {
1732 WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
1733 RELEASE_WNDOBJ(topOwner);
1734 }
1735 }
1736 }
1737 }
1738 else
1739 {
1740 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1741 }
1742 rc = 0;
1743 break;
1744 }
1745
1746 case WM_ENABLE:
1747 dprintf(("PMFRAME: WM_ENABLE %x", hwnd));
1748 win32wnd->MsgEnable(SHORT1FROMMP(mp1));
1749 break;
1750
1751 case WM_SHOW:
1752 dprintf(("PMFRAME: WM_SHOW %x %d", hwnd, mp1));
1753 //show client window
1754 WinShowWindow(win32wnd->getOS2WindowHandle(), (BOOL)mp1);
1755 break;
1756
1757 case WM_QUERYTRACKINFO:
1758 {
1759 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
1760
1761 dprintf(("PMFRAME:WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
1762 trackInfo->cxBorder = 4;
1763 trackInfo->cyBorder = 4;
1764 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
1765 rc = (MRESULT)TRUE;
1766 break;
1767 }
1768
1769 case WM_QUERYBORDERSIZE:
1770 {
1771 PWPOINT size = (PWPOINT)mp1;
1772
1773 dprintf(("PMFRAME:WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
1774
1775 size->x = 0;
1776 size->y = 0;
1777 rc = (MRESULT)TRUE;
1778 break;
1779 }
1780
1781#ifdef DEBUG
1782 case WM_QUERYFRAMEINFO:
1783 dprintf(("PMFRAME:WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
1784 goto RunDefFrameWndProc;
1785#endif
1786
1787 case WM_FORMATFRAME:
1788 dprintf(("PMFRAME:WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
1789 break;
1790
1791#ifdef DEBUG
1792 case WM_ADJUSTFRAMEPOS:
1793 {
1794 PSWP pswp = (PSWP)mp1;
1795
1796 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));
1797 goto RunDefFrameWndProc;
1798 }
1799
1800 case WM_OWNERPOSCHANGE:
1801 {
1802 PSWP pswp = (PSWP)mp1;
1803
1804 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));
1805 goto RunDefFrameWndProc;
1806 }
1807#endif
1808
1809 case WM_MINMAXFRAME:
1810 {
1811 PSWP swp = (PSWP)mp1;
1812
1813 if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
1814
1815 dprintf(("PMFRAME:WM_MINMAXFRAME %x",hwnd));
1816 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1817 {
1818 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
1819
1820 RECT rect;
1821
1822 rect.left = rect.top = rect.right = rect.bottom = 0;
1823 win32wnd->AdjustMaximizedRect(&rect);
1824 swp->x += rect.left;
1825 swp->cx += rect.right-rect.left;
1826 swp->y -= rect.bottom;
1827 swp->cy += rect.bottom-rect.top;
1828 }
1829 else
1830 if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
1831 {
1832 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
1833 }
1834 else
1835 if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
1836 {
1837 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
1838 }
1839 goto RunDefWndProc;
1840 }
1841
1842#ifdef DEBUG
1843 case WM_UPDATEFRAME:
1844 dprintf(("PMFRAME:WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
1845 goto RunDefFrameWndProc;
1846#endif
1847
1848 case WM_TRACKFRAME:
1849 dprintf(("PMFRAME: WM_TRACKFRAME %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
1850 if(fOS2Look) {//sent by titlebar control
1851#ifdef CUSTOM_TRACKFRAME
1852 Frame_SysCommandSizeMove(win32wnd, SC_MOVE_W+HTCAPTION_W);
1853#else
1854 FrameTrackFrame(win32wnd, TF_MOVE);
1855#endif
1856 }
1857 rc = 0;
1858 break;
1859
1860 case WM_SYSCOMMAND:
1861 dprintf(("PMFRAME: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
1862 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
1863 RELEASE_WNDOBJ(win32wnd);
1864 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
1865 }
1866 if(win32wnd)
1867 win32wnd->DispatchMsgA(pWinMsg);
1868 break;
1869
1870#ifdef DEBUG
1871 case WM_DDE_INITIATE:
1872 case WM_DDE_INITIATEACK:
1873 case WM_DDE_REQUEST:
1874 case WM_DDE_ACK:
1875 case WM_DDE_DATA:
1876 case WM_DDE_ADVISE:
1877 case WM_DDE_UNADVISE:
1878 case WM_DDE_POKE:
1879 case WM_DDE_EXECUTE:
1880 case WM_DDE_TERMINATE:
1881 dprintf(("PMFRAME: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
1882 break;
1883#endif
1884
1885 default:
1886 goto RunDefFrameWndProc;
1887 }
1888 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1889 RestoreOS2TIB();
1890 return (MRESULT)rc;
1891
1892RunDefFrameWndProc:
1893 dprintf2(("RunDefFrameWndProc"));
1894 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1895 RestoreOS2TIB();
1896 return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1897
1898RunDefWndProc:
1899 dprintf2(("RunDefWndProc"));
1900 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1901 RestoreOS2TIB();
1902 //calling WinDefWindowProc here breaks Opera hotlist window (WM_ADJUSTWINDOWPOS)
1903// return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1904 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
1905}
1906//******************************************************************************
1907//******************************************************************************
1908void FrameSetFocus(HWND hwnd)
1909{
1910 HWND hwndFocusSave = WinQueryWindowULong(hwnd, QWL_HWNDFOCUSSAVE);
1911 if(!WinIsWindow(hab, hwndFocusSave)) {
1912 hwndFocusSave = WinWindowFromID(hwnd, FID_CLIENT);
1913 WinSetWindowULong(hwnd, QWL_HWNDFOCUSSAVE, hwndFocusSave);
1914 }
1915 dprintf(("FrameSetFocus: hwndFocusSave %x %x", OS2ToWin32Handle(hwndFocusSave), hwndFocusSave));
1916 WinSetFocus(HWND_DESKTOP, hwndFocusSave);
1917
1918 ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
1919 ulFrameFlags &= ~FF_NOACTIVATESWP;
1920 WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags);
1921}
1922#ifndef CUSTOM_TRACKFRAME
1923//******************************************************************************
1924//TODO: Quickly moving a window two times doesn't force a repaint (1st time)
1925//
1926//
1927BOOL (APIENTRY *WinTrackWindow)(HWND hwndTrack, PTRACKINFO pti) = NULL;
1928//
1929//******************************************************************************
1930VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
1931{
1932 TRACKINFO track;
1933 RECTL rcl;
1934 PRECT pWindowRect, pClientRect;
1935 HWND hwndTracking;
1936 LONG parentHeight, parentWidth;
1937 static BOOL fInit = FALSE;
1938 APIRET rc;
1939 BOOL ret;
1940 HWND hwnd = win32wnd->getWindowHandle();
1941
1942 if(!fInit) {
1943 HMODULE hModule;
1944 char buf[CCHMAXPATH];
1945 rc = DosLoadModule(buf, sizeof(buf), "PMMERGE", &hModule);
1946 rc = DosQueryProcAddr(hModule, 5466, NULL, (PFN *)&WinTrackWindow);
1947 if(rc) WinTrackWindow = NULL;
1948 fInit = TRUE;
1949 }
1950 dprintf(("FrameTrackFrame: %x %x", hwnd, flags));
1951 track.cxBorder = 4;
1952 track.cyBorder = 4; /* 4 pel wide lines used for rectangle */
1953 track.cxGrid = 1;
1954 track.cyGrid = 1; /* smooth tracking with mouse */
1955 track.cxKeyboard = 8;
1956 track.cyKeyboard = 8; /* faster tracking using cursor keys */
1957
1958 pWindowRect = win32wnd->getWindowRect();
1959 if(win32wnd->getParent()) {
1960 parentHeight = win32wnd->getParent()->getClientHeight();
1961 parentWidth = win32wnd->getParent()->getClientWidth();
1962 hwndTracking = win32wnd->getParent()->getOS2WindowHandle();
1963 }
1964 else {
1965 parentHeight = OSLibQueryScreenHeight();
1966 parentWidth = OSLibQueryScreenWidth();
1967 hwndTracking = HWND_DESKTOP;
1968 }
1969
1970 mapWin32ToOS2Rect(parentHeight, pWindowRect, (PRECTLOS2)&track.rclTrack);
1971 rcl = track.rclTrack;
1972 WinQueryWindowRect(hwndTracking, &track.rclBoundary);
1973
1974 track.ptlMinTrackSize.x = 10;
1975 track.ptlMinTrackSize.y = 10; /* set smallest allowed size of rectangle */
1976 track.ptlMaxTrackSize.x = parentWidth;
1977 track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */
1978
1979 win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize);
1980
1981 track.fs = flags;
1982
1983 BOOL fDynamicDrag = WinQuerySysValue(HWND_DESKTOP, SVOS_DYNAMICDRAG);
1984
1985 //TODO: send WM_QUERYDRAGICON to fetch icon (not really necessary)
1986
1987 SendMessageA( hwnd, WM_ENTERSIZEMOVE_W, 0, 0);
1988
1989 SEL sel = RestoreOS2FS();
1990 if(fDynamicDrag && WinTrackWindow) {
1991 ret = WinTrackWindow(win32wnd->getOS2FrameWindowHandle(), &track);
1992 }
1993 else ret = WinTrackRect(hwndTracking, NULL, &track);
1994 SetFS(sel);
1995
1996//TODO:
1997// if (HOOK_CallHooksA( WH_CBT_W, HCBT_MOVESIZE_W, (WPARAM)hwnd, (LPARAM)&sizingRect )) moved = FALSE;
1998
1999 SendMessageA( hwnd, WM_EXITSIZEMOVE_W, 0, 0 );
2000 SendMessageA( hwnd, WM_SETVISIBLE_W, !IsIconic(hwnd), 0L);
2001
2002 if(ret) {
2003 /* if successful copy final position back */
2004 if(!WinEqualRect(0, &rcl, &track.rclTrack)) {
2005 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));
2006 if(flags == TF_MOVE) {
2007 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
2008 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
2009 0, 0, SWP_MOVE);
2010 }
2011 else {
2012 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
2013 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
2014 track.rclTrack.xRight - track.rclTrack.xLeft,
2015 track.rclTrack.yTop - track.rclTrack.yBottom,
2016 SWP_SIZE|SWP_MOVE);
2017 }
2018 }
2019 return;
2020 }
2021 return;
2022}
2023#endif
2024//******************************************************************************
2025//******************************************************************************
2026void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG idNew,
2027 HBITMAP hbmNew)
2028{
2029 MENUITEM mi;
2030
2031 if (!hwndMenu)
2032 return;
2033
2034 WinEnableWindowUpdate(hwndMenu, FALSE);
2035
2036 if (WinSendMsg(hwndMenu, MM_QUERYITEM, MPFROM2SHORT(idOld, TRUE), MPFROMP(&mi)))
2037 {
2038 WinSendMsg(hwndMenu, MM_REMOVEITEM, (MPARAM)idOld, 0);
2039 mi.afStyle = MIS_BITMAP | MIS_SYSCOMMAND;
2040 mi.afAttribute = 0;
2041 mi.hwndSubMenu = 0;
2042 mi.id = idNew;
2043 mi.hItem = (ULONG)hbmNew;
2044 WinSendMsg(hwndMenu, MM_INSERTITEM, (MPARAM)&mi, 0);
2045 }
2046 WinEnableWindowUpdate(hwndMenu, TRUE);
2047
2048 WinInvalidateRect(hwndMenu, NULL, TRUE);
2049}
2050//******************************************************************************
2051//******************************************************************************
Note: See TracBrowser for help on using the repository browser.