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

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

implemented simple drag & drop with WM_DROPFILES

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