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

Last change on this file since 10060 was 10060, checked in by sandervl, 22 years ago

Keep track of all open DCs and query the visible region during WM_VRNENABLED to work around a PM bug

File size: 84.8 KB
Line 
1/* $Id: pmwindow.cpp,v 1.213 2003-05-02 15:33:15 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 <odinwrap.h>
24#include <stdlib.h>
25#include <string.h>
26#include <win32type.h>
27#include <win32api.h>
28#include <winconst.h>
29#include <winuser32.h>
30#include <wprocess.h>
31#include <dbglog.h>
32#include <win32wbase.h>
33#include <win32wfake.h>
34#include <win32dlg.h>
35#include "win32wdesktop.h"
36#include "pmwindow.h"
37#include "oslibwin.h"
38#include "oslibutil.h"
39#include "oslibgdi.h"
40#include "oslibmsg.h"
41#define INCLUDED_BY_DC
42#include "dc.h"
43#include <thread.h>
44#include <wprocess.h>
45#include "caret.h"
46#include "timer.h"
47#include <codepage.h>
48#include "syscolor.h"
49#include "options.h"
50#include "menu.h"
51#include <pmkbdhk.h>
52#include <pmscan.h>
53#include <winscan.h>
54#include <win\dbt.h>
55#include "dragdrop.h"
56#include "menu.h"
57#include "user32api.h"
58
59#define DBG_LOCALLOG DBG_pmwindow
60#include "dbglocal.h"
61
62//define this to use the new code for WM_CALCVALIDRECT handling
63//#define USE_CALCVALIDRECT
64
65HMQ hmq = 0; /* Message queue handle */
66HAB hab = 0;
67RECTL desktopRectl = {0};
68ULONG ScreenWidth = 0;
69ULONG ScreenHeight = 0;
70ULONG ScreenBitsPerPel = 0;
71BOOL fOS2Look = FALSE;
72BOOL fForceMonoCursor = FALSE;
73BOOL fDragDropActive = FALSE;
74BOOL fDragDropDisabled = FALSE;
75
76char WIN32_CDCLASS[255] = "Win32CDWindowClass";
77char WIN32_STDCLASS[255] = "Win32WindowClass";
78char WIN32_STDFRAMECLASS[255] = "Win32FrameClass";
79
80#define PMMENU_MINBUTTON 0
81#define PMMENU_MAXBUTTON 1
82#define PMMENU_RESTOREBUTTON 2
83#define PMMENU_CLOSEBUTTON 3
84#define PMMENU_MINBUTTONDOWN 4
85#define PMMENU_MAXBUTTONDOWN 5
86#define PMMENU_RESTOREBUTTONDOWN 6
87#define PMMENU_CLOSEBUTTONDOWN 7
88
89HBITMAP hbmFrameMenu[8] = {0};
90
91//Win32 bitmap handles of the OS/2 min, max and restore buttons
92HBITMAP hBmpMinButton = 0;
93HBITMAP hBmpMaxButton = 0;
94HBITMAP hBmpRestoreButton = 0;
95HBITMAP hBmpCloseButton = 0;
96HBITMAP hBmpMinButtonDown = 0;
97HBITMAP hBmpMaxButtonDown = 0;
98HBITMAP hBmpRestoreButtonDown = 0;
99HBITMAP hBmpCloseButtonDown = 0;
100
101static PFNWP pfnFrameWndProc = NULL;
102static HWND hwndFocusChange = 0;
103 HWND hwndCD = 0;
104
105// this holds the font height that the display driver returns using DevQueryCaps
106// 13 would be small fonts, 16 medium fonts and 20 large fonts
107LONG CapsCharHeight = 0;
108
109// Note:
110// For a "lonekey"-press of AltGr, we only receive WM_KEYUP
111// messages. If the key is pressed longer and starts to repeat,
112// WM_KEYDOWN messages come in properly.
113static BOOL fKeyAltGrDown = FALSE;
114
115
116static char *PMDragExtractFiles(PDRAGINFO pDragInfo, ULONG *pcItems, ULONG *pulBytes);
117static BOOL PMDragValidate(PDRAGINFO pDragInfo);
118static void QueryPMMenuBitmaps();
119
120MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
121MRESULT EXPENTRY Win32CDWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
122MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
123void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG idNew,
124 HBITMAP hbmNew);
125void FrameSetFocus(HWND hwnd);
126
127VOID APIENTRY DspInitSystemDriverName(PSZ pszDriverName, ULONG lenDriverName);
128
129#ifdef DEBUG
130static char *DbgGetStringSWPFlags(ULONG flags);
131static char *DbgPrintQFCFlags(ULONG flags);
132#endif
133
134//******************************************************************************
135// Initialize PM; create hab, message queue and register special Win32 window classes
136//
137// This is called from the initterm, so we call it only once for each process.
138// We make sure PM is up and running for our purposes and init the existing
139// thread 0.
140//******************************************************************************
141BOOL InitPM()
142{
143 hab = WinInitialize(0);
144 dprintf(("Winitialize returned %x", hab));
145 hmq = WinCreateMsgQueue(hab, 0);
146
147 if(!hab || !hmq)
148 {
149 UINT error;
150 //CB: only fail on real error
151 error = WinGetLastError(hab) & 0xFFFF; //error code
152 if (!hab || (error != PMERR_MSG_QUEUE_ALREADY_EXISTS))
153 {
154 dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
155 dprintf((" Error = %x",error));
156 if(error == PMERR_NOT_IN_A_PM_SESSION) return TRUE;
157
158 return(FALSE);
159 }
160 else
161 {
162 if(!hab) {
163 hab = WinQueryAnchorBlock(HWND_DESKTOP);
164 dprintf(("WinQueryAnchorBlock returned %x", hab));
165 }
166 if(!hmq) {
167 PTIB ptib;
168 PPIB ppib;
169
170 DosGetInfoBlocks(&ptib, &ppib);
171
172 hmq = WinQueueFromID(hab, ppib->pib_ulpid, ptib->tib_ptib2->tib2_ultid);
173 }
174 }
175 }
176
177 // store our HAB and HMQ in the TEB - we need it quite often
178 // and they don't map 1:1 to Windows entities
179 SetThreadHAB(hab);
180 dprintf(("InitPM: hmq = %x", hmq));
181 SetThreadMessageQueue(hmq);
182
183 BOOL rc = WinSetCp(hmq, GetDisplayCodepage());
184 dprintf(("InitPM: WinSetCP was %sOK", rc ? "" : "not "));
185
186 //CD polling window class
187 if(!WinRegisterClass( /* Register window class */
188 hab, /* Anchor block handle */
189 (PSZ)WIN32_CDCLASS, /* Window class name */
190 (PFNWP)Win32CDWindowProc, /* Address of window procedure */
191 0,
192 0))
193 {
194 dprintf(("WinRegisterClass Win32BaseWindow failed"));
195 return(FALSE);
196 }
197
198 //Standard Odin window class
199 if(!WinRegisterClass( /* Register window class */
200 hab, /* Anchor block handle */
201 (PSZ)WIN32_STDCLASS, /* Window class name */
202 (PFNWP)Win32WindowProc, /* Address of window procedure */
203 0,
204 NROF_WIN32WNDBYTES))
205 {
206 dprintf(("WinRegisterClass Win32BaseWindow failed"));
207 return(FALSE);
208 }
209
210 CLASSINFO FrameClassInfo;
211 if(!WinQueryClassInfo (hab, WC_FRAME, &FrameClassInfo)) {
212 dprintf (("WinQueryClassInfo WC_FRAME failed"));
213 return (FALSE);
214 }
215 pfnFrameWndProc = FrameClassInfo.pfnWindowProc;
216
217 dprintf(("WC_FRAME style %x", FrameClassInfo.flClassStyle));
218
219 // this is our OS/2 window class for frame windows
220 if(!WinRegisterClass( /* Register window class */
221 hab, /* Anchor block handle */
222 (PSZ)WIN32_STDFRAMECLASS, /* Window class name */
223 (PFNWP)Win32FrameWindowProc, /* Address of window procedure */
224 CS_FRAME,
225 FrameClassInfo.cbWindowData))
226 {
227 dprintf(("WinRegisterClass Win32BaseWindow failed %x", WinGetLastError(hab)));
228 return(FALSE);
229 }
230
231 // get the screen dimensions and store them
232 WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
233 ScreenWidth = desktopRectl.xRight;
234 ScreenHeight = desktopRectl.yTop;
235
236 HDC hdc; /* Device-context handle */
237 /* context data structure */
238 DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
239 NULL, NULL, NULL};
240
241 /* create memory device context - it's temporary to query some information */
242 hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
243
244 // check if we have the OS/2 Look and Feel enabled
245 fOS2Look = PROFILE_GetOdinIniBool(ODINSYSTEM_SECTION, "OS2Look", TRUE);
246 if(fOS2Look)
247 {
248 SYSCOLOR_Init(FALSE); //use OS/2 colors
249 QueryPMMenuBitmaps();
250 }
251
252 // find out which colordepth we're running
253 DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, (PLONG)&ScreenBitsPerPel);
254
255 // query the font height to find out whether we have small or large fonts
256 DevQueryCaps(hdc, CAPS_GRAPHICS_CHAR_HEIGHT, 1, (PLONG)&CapsCharHeight);
257
258 DevCloseDC(hdc);
259
260 dprintf(("InitPM: Desktop (%d,%d) bpp %d", ScreenWidth, ScreenHeight, ScreenBitsPerPel));
261 return TRUE;
262} /* End of main */
263//******************************************************************************
264HBITMAP OPEN32API _O32_CreateBitmapFromPMHandle(HBITMAP hPMBitmap);
265
266inline HBITMAP O32_CreateBitmapFromPMHandle(HBITMAP hPMBitmap)
267{
268 HBITMAP yyrc;
269 USHORT sel = RestoreOS2FS();
270
271 yyrc = _O32_CreateBitmapFromPMHandle(hPMBitmap);
272 SetFS(sel);
273
274 return yyrc;
275}
276//******************************************************************************
277static void QueryPMMenuBitmaps()
278{
279 CHAR szDisplay[30];
280 HMODULE hModDisplay;
281
282 if(hbmFrameMenu[0] == 0)
283 {
284 CHAR szDisplay[30];
285 HMODULE hModDisplay;
286 HDC hdc; /* Device-context handle */
287 DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
288 NULL, NULL, NULL};
289
290 /* create memory device context */
291 hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
292
293 DspInitSystemDriverName(szDisplay, sizeof(szDisplay));
294 DosQueryModuleHandle(szDisplay, &hModDisplay);
295
296 hbmFrameMenu[PMMENU_MINBUTTON] = GpiLoadBitmap(hdc, hModDisplay, SBMP_MINBUTTON, 0, 0);
297 hbmFrameMenu[PMMENU_MINBUTTONDOWN] = GpiLoadBitmap(hdc, hModDisplay, SBMP_MINBUTTONDEP, 0, 0);
298 hbmFrameMenu[PMMENU_MAXBUTTON] = GpiLoadBitmap(hdc, hModDisplay, SBMP_MAXBUTTON, 0, 0);
299 hbmFrameMenu[PMMENU_MAXBUTTONDOWN] = GpiLoadBitmap(hdc, hModDisplay, SBMP_MAXBUTTONDEP, 0, 0);
300 hbmFrameMenu[PMMENU_RESTOREBUTTON] = GpiLoadBitmap(hdc, hModDisplay, SBMP_RESTOREBUTTON, 0, 0);
301 hbmFrameMenu[PMMENU_RESTOREBUTTONDOWN] = GpiLoadBitmap(hdc, hModDisplay, SBMP_RESTOREBUTTONDEP, 0, 0);
302 hbmFrameMenu[PMMENU_CLOSEBUTTON] = GpiLoadBitmap(hdc, hModDisplay, SBMP_CLOSE, 0, 0);
303 hbmFrameMenu[PMMENU_CLOSEBUTTONDOWN] = GpiLoadBitmap(hdc, hModDisplay, SBMP_CLOSEDEP, 0, 0);
304
305 //Create win32 bitmap handles of the OS/2 min, max and restore buttons
306 hBmpMinButton = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_MINBUTTON]);
307 hBmpMinButtonDown = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_MINBUTTONDOWN]);
308 hBmpMaxButton = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_MAXBUTTON]);
309 hBmpMaxButtonDown = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_MAXBUTTONDOWN]);
310 hBmpRestoreButton = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_RESTOREBUTTON]);
311 hBmpRestoreButtonDown = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_RESTOREBUTTONDOWN]);
312 hBmpCloseButton = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_CLOSEBUTTON]);
313 hBmpCloseButtonDown = O32_CreateBitmapFromPMHandle(hbmFrameMenu[PMMENU_CLOSEBUTTONDOWN]);
314 DevCloseDC(hdc);
315 }
316}
317//******************************************************************************
318//******************************************************************************
319void WIN32API SetWindowAppearance(int fLooks)
320{
321 if(fLooks == OS2_APPEARANCE || fLooks == OS2_APPEARANCE_SYSMENU)
322 {
323 SYSCOLOR_Init(FALSE); //use OS/2 colors
324 QueryPMMenuBitmaps();
325 }
326 fOS2Look = fLooks;
327 MENU_Init();
328}
329//******************************************************************************
330//******************************************************************************
331void WIN32API CustForceMonoCursor()
332{
333 fForceMonoCursor = TRUE;
334}
335//******************************************************************************
336//******************************************************************************
337void WIN32API DisableDragDrop(BOOL fDisabled)
338{
339 fDragDropDisabled = fDisabled;
340}
341//******************************************************************************
342//CD notification window class
343//******************************************************************************
344MRESULT EXPENTRY Win32CDWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
345{
346#pragma pack(1)
347 typedef struct
348 {
349 BYTE ucCommandInfo;
350 WORD usDriveUnit;
351 } ParameterBlock;
352#pragma pack()
353
354 MRESULT rc = 0;
355 static ULONG drives[26] = {0};
356 static int drivestatus[26] = {0};
357
358 switch( msg )
359 {
360 //OS/2 msgs
361 case WM_CREATE:
362 {
363 char drive[4];
364
365 //skip floppy drives
366 drive[0] = 'C';
367 drive[1] = ':';
368 drive[2] = '\0';
369
370 for(int i=2;i<26;i++) {
371 drives[i] = GetDriveTypeA(drive);
372 if(drives[i] == DRIVE_CDROM_W)
373 {
374 DWORD parsize = sizeof(ParameterBlock);
375 DWORD datasize = 2;
376 WORD status = 0;
377 DWORD rc;
378 ParameterBlock parm;
379
380 parm.ucCommandInfo = 0;
381 parm.usDriveUnit = i;
382 rc = DosDevIOCtl(-1, IOCTL_DISK, DSK_GETLOCKSTATUS, &parm, sizeof(parm), &parsize,
383 &status, sizeof(status), &datasize);
384 if(rc != NO_ERROR) {
385 dprintf(("DosDevIOCtl failed with rc %d", rc));
386 drives[i] = 0;
387 continue;
388 }
389 //if no disk present, return FALSE
390 if(status & 4) {
391 drivestatus[i] = status & 4;
392 }
393 }
394 drive[0]++;
395 }
396 WinStartTimer(hab, hwnd, TIMERID_DRIVEPOLL, 32*60);
397//// WinStartTimer(hab, hwnd, TIMERID_DRIVEPOLL, 32*3);
398//// WinStartTimer(hab, hwnd, TIMERID_DRIVEPOLL, 5000);
399 rc = (MRESULT)FALSE;
400 break;
401 }
402 case WM_TIMER:
403 {
404 for(int i=0;i<26;i++)
405 {
406 //for now only cdrom/dvd drives
407 if(drives[i] == DRIVE_CDROM_W)
408 {
409 DWORD parsize = sizeof(ParameterBlock);
410 DWORD datasize = 2;
411 WORD status = 0;
412 DWORD rc;
413 ParameterBlock parm;
414
415 parm.ucCommandInfo = 0;
416 parm.usDriveUnit = i;
417 rc = DosDevIOCtl(-1, IOCTL_DISK, DSK_GETLOCKSTATUS, &parm, sizeof(parm), &parsize,
418 &status, sizeof(status), &datasize);
419 if(rc != NO_ERROR) {
420 dprintf(("DosDevIOCtl failed with rc %d", rc));
421 return FALSE;
422 }
423 //Send WM_DEVICECHANGE message when CD status changes
424 if((status & 4) != drivestatus[i])
425 {
426 PID pidThis, pidTemp;
427 HENUM henum;
428 HWND hwndEnum;
429 DEV_BROADCAST_VOLUME volchange;
430
431 dprintf(("Disk status 0x%x", status));
432
433 volchange.dbcv_size = sizeof(volchange);
434 volchange.dbcv_devicetype = DBT_DEVTYP_VOLUME;
435 volchange.dbcv_reserved = 0;
436 volchange.dbcv_unitmask = (1 << i);
437 volchange.dbcv_flags = DBTF_MEDIA;
438
439 WinQueryWindowProcess(hwnd, &pidThis, NULL);
440
441 //Iterate over all child windows of the desktop
442 henum = WinBeginEnumWindows(HWND_DESKTOP);
443
444 SetWin32TIB();
445 while(hwndEnum = WinGetNextWindow(henum))
446 {
447 WinQueryWindowProcess(hwndEnum, &pidTemp, NULL);
448 if(pidTemp == pidThis)
449 {
450 HWND hwndWin32 = OS2ToWin32Handle(hwndEnum);
451 if(hwndWin32) {
452 SendMessageA(hwndWin32,
453 WM_DEVICECHANGE_W,
454 (status & 4) ? DBT_DEVICEARRIVAL : DBT_DEVICEREMOVECOMPLETE,
455 (LPARAM)&volchange);
456 }
457 }
458 }
459 RestoreOS2TIB();
460 WinEndEnumWindows(henum);
461
462 drivestatus[i] = (status & 4);
463 }
464 }
465 }
466 break;
467 }
468
469 case WM_DESTROY:
470 dprintf(("WM_DESTROY for CD notification window"));
471 WinStopTimer(hab, hwnd, TIMERID_DRIVEPOLL);
472 break;
473
474 default:
475 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
476 }
477 return (MRESULT)rc;
478}
479//******************************************************************************
480// Win32 window message handler
481// The PM window procedure for our client window class (non frame)
482//******************************************************************************
483MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
484{
485 Win32BaseWindow *win32wnd;
486 TEB *teb;
487 MSG winMsg, *pWinMsg;
488 MRESULT rc = 0;
489 POSTMSG_PACKET *postmsg;
490 OSLIBPOINT point, ClientPoint;
491
492 // restore our FS selector
493 SetWin32TIB();
494
495#ifdef DEBUG
496 dbg_ThreadPushCall("Win32WindowProc");
497#endif
498
499 // BEGIN NOTE-------------->>>>>> If this is changed, also change Win32FrameWindowProc!! <<<<<<<<<<<-------------------- BEGIN
500 teb = GetThreadTEB();
501 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
502
503//// dprintf(("window %x msg %x", (win32wnd) ? win32wnd->getWindowHandle() : 0, msg));
504
505 // do some sanity checking here:
506 // - we need to have a TEB handle
507 // - unless this is WM_CREATE (the very first message), there has to be
508 // a USER32 window object for this window handle
509 if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
510 dprintf(("OS2: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
511 goto RunDefWndProc;
512 }
513//// if(teb->o.odin.fIgnoreMsgs) {
514//// goto RunDefWndProc;
515//// }
516
517 // check if the message state counter in the TEB is odd
518 // This means the message has been sent directly from PM to our message
519 // handler (so it is the first time we know about this PM message).
520 // If this is the case, we have to translate it here to a Win32
521 // message first. The other case is that the message is the result of a
522 // WinDispatchMsg call and therefore has already been translated.
523 if((teb->o.odin.msgstate & 1) == 0)
524 {
525 // message that was sent directly to our window proc handler; translate it here
526 QMSG qmsg;
527
528 qmsg.msg = msg;
529 qmsg.hwnd = hwnd;
530 qmsg.mp1 = mp1;
531 qmsg.mp2 = mp2;
532 qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
533 WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
534 qmsg.reserved = 0;
535
536 if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
537 {//message was not translated
538 memset(&winMsg, 0, sizeof(MSG));
539 }
540 pWinMsg = &winMsg;
541 }
542 else {
543 // message has already been translated before (GetMessage/PeekMessage).
544 // Use the translated information. Flip the translation flag.
545 pWinMsg = &teb->o.odin.msg;
546 teb->o.odin.msgstate++;
547 }
548 // END NOTE-------------->>>>>> If this is changed, also change Win32FrameWindowProc!! <<<<<<<<<<<-------------------- END
549
550 if(msg >= WIN32APP_POSTMSG) {
551 //probably win32 app user message
552 dprintf2(("Posted message %x->%x", msg, msg-WIN32APP_POSTMSG));
553 if((ULONG)mp1 == WIN32MSG_MAGICA) {
554 rc = (MRESULT)win32wnd->DispatchMsgA(pWinMsg);
555 }
556 else
557 if((ULONG)mp1 == WIN32MSG_MAGICW) {
558 rc = (MRESULT)win32wnd->DispatchMsgW(pWinMsg);
559 }
560 else {//broadcasted message
561 rc = (MRESULT)win32wnd->DispatchMsgA(pWinMsg);
562 }
563 RELEASE_WNDOBJ(win32wnd);
564 RestoreOS2TIB();
565
566#ifdef DEBUG
567 dbg_ThreadPopCall();
568#endif
569 return rc;
570 }
571
572 switch( msg )
573 {
574 //OS/2 msgs
575 case WM_CREATE:
576 {
577 if(teb->o.odin.newWindow == 0)
578 goto createfail;
579
580 //Processing is done in after WinCreateWindow returns
581 dprintf(("OS2: WM_CREATE %x", hwnd));
582 win32wnd = (Win32BaseWindow *)teb->o.odin.newWindow;
583 win32wnd->addRef();
584 teb->o.odin.newWindow = 0;
585 if(win32wnd->MsgCreate(hwnd) == FALSE)
586 {
587 rc = (MRESULT)TRUE; //discontinue window creation
588 break;
589 }
590
591 //Create CD notification window
592 if(hwndCD == 0) {
593 hwndCD = WinCreateWindow(HWND_DESKTOP, WIN32_CDCLASS,
594 NULL, 0, 0, 0, 0, 0,
595 HWND_DESKTOP, HWND_TOP, 0, NULL, NULL);
596 }
597
598 createfail:
599 rc = (MRESULT)FALSE;
600 break;
601 }
602
603 case WM_QUIT:
604 dprintf(("OS2: WM_QUIT %x", hwnd));
605 win32wnd->MsgQuit();
606 break;
607
608 case WM_CLOSE:
609 dprintf(("OS2: WM_CLOSE %x", hwnd));
610 win32wnd->MsgClose();
611 break;
612
613 case WM_DESTROY:
614 dprintf(("OS2: WM_DESTROY %x", hwnd));
615 win32wnd->MsgDestroy();
616 WinSetVisibleRegionNotify(hwnd, FALSE);
617 goto RunDefWndProc;
618
619 case WM_ENABLE:
620 dprintf(("OS2: WM_ENABLE %x", hwnd));
621 break;
622
623 case WM_SHOW:
624 dprintf(("OS2: WM_SHOW %x %d", hwnd, mp1));
625 win32wnd->MsgShow((ULONG)mp1);
626 break;
627
628 case WM_ACTIVATE:
629 {
630 ULONG flags = WinQueryWindowULong(hwnd, OFFSET_WIN32FLAGS);
631
632 dprintf(("OS2: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2));
633 WinSetWindowULong(hwnd, OFFSET_WIN32FLAGS, SHORT1FROMMP(mp1) ? (flags | WINDOWFLAG_ACTIVE):(flags & ~WINDOWFLAG_ACTIVE));
634 if(win32wnd->IsWindowCreated())
635 {
636 win32wnd->MsgActivate((LOWORD(pWinMsg->wParam) == WA_ACTIVE_W) ? 1 : 0, HIWORD(pWinMsg->wParam), pWinMsg->lParam, (HWND)mp2);
637 }
638 break;
639 }
640
641 case WM_SIZE:
642 {
643 dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp1)));
644 win32wnd->SetVisibleRegionChanged(TRUE);
645 goto RunDefWndProc;
646 }
647
648
649 case WM_VRNENABLED:
650 {
651 dprintf(("OS2: WM_VRNENABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
652 //Always call handler; even if mp1 is 0. If we don't do this, the
653 //DivX 4 player will never be allowed to draw after putting another window
654 //on top of it.
655
656 win32wnd->callVisibleRgnNotifyProc(TRUE);
657
658 //Workaround for PM/GPI bug when moving/sizing a window with open DCs
659 //
660 //Windows applictions often get a DC and keep it open for the duration
661 //of the application. When the DC's window is moved (full window dragging on)
662 //PM/GPI doesn't seem to update the DC properly/in time.
663 //This can result is visible distortions on the screen.
664 //Debugging showed that querying the visible region of a DC will cure
665 //this problem (GPI probably recalculates the visible region).
666 int nrdcs = 0;
667 HDC hdcWindow[MAX_OPENDCS];
668
669 if(win32wnd->queryOpenDCs(hdcWindow, MAX_OPENDCS, &nrdcs))
670 {
671 RECTL rcl = {0,0,1,1};
672 HRGN hrgnRect;
673
674 for(int i=0;i<nrdcs;i++) {
675 dprintf(("Recalc visible region of DC %x for window %x", hdcWindow[i], win32wnd->getWindowHandle()));
676 hrgnRect = GreCreateRectRegion(hdcWindow[i], &rcl, 1);
677 GreCopyClipRegion(hdcWindow[i], hrgnRect, 0, COPYCRGN_VISRGN);
678 GreDestroyRegion(hdcWindow[i], hrgnRect);
679 }
680 }
681
682 //Workaround END
683
684 if(!win32wnd->isComingToTop() && ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == WS_EX_TOPMOST_W))
685 {
686 HWND hwndrelated;
687 Win32BaseWindow *topwindow;
688
689 win32wnd->setComingToTop(TRUE);
690
691 hwndrelated = WinQueryWindow(hwnd, QW_PREV);
692 dprintf(("WM_VRNENABLED hwndrelated = %x (hwnd=%x)", hwndrelated, hwnd));
693 topwindow = Win32BaseWindow::GetWindowFromOS2Handle(hwndrelated);
694 if(topwindow == NULL || ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == 0)) {
695 //put window at the top of z order
696 WinSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
697 }
698 if(topwindow) RELEASE_WNDOBJ(topwindow);
699
700 win32wnd->setComingToTop(FALSE);
701 break;
702 }
703 goto RunDefWndProc;
704 }
705
706 case WM_VRNDISABLED:
707 {
708 dprintf(("OS2: WM_VRNDISABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
709 //visible region is about to change or WinLockWindowUpdate called
710 //suspend window drawing
711
712 win32wnd->callVisibleRgnNotifyProc(FALSE);
713 goto RunDefWndProc;
714 }
715
716 case WIN32APP_DDRAWFULLSCREEN:
717 //Changing the size of the win32 window in SetCooperativeLevel can
718 //fail if this happens during WM_ADJUSTWINDOWPOS
719 //NOTE: This is not a good solution, but a proper fix is more difficult
720 // with the current window mess
721 dprintf(("WIN32APP_DDRAWFULLSCREEN %x (%d,%d)", win32wnd->getWindowHandle(), mp1, mp2));
722 SetWindowPos(win32wnd->getWindowHandle(), HWND_TOP_W, 0, 0, (DWORD)mp1, (DWORD)mp2, 0);
723 ShowWindow(win32wnd->getWindowHandle(), SW_SHOW_W);
724 break;
725
726 case WIN32APP_SETFOCUSMSG:
727 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
728 //must delay this function call
729 //mp1 = win32 window handle
730 //mp2 = top parent if activation required
731 dprintf(("USER32: Delayed SetFocus %x %x %x call!", teb->o.odin.hwndFocus, mp1, mp2));
732 if(teb->o.odin.hwndFocus) {
733 RELEASE_WNDOBJ(win32wnd);
734 win32wnd = Win32BaseWindow::GetWindowFromHandle(teb->o.odin.hwndFocus);
735 if(win32wnd) {
736 if(mp2) {
737 SetActiveWindow((HWND)mp2);
738 }
739 if(!IsWindow(win32wnd->getWindowHandle())) break; //abort if window destroyed
740 WinFocusChange(HWND_DESKTOP, win32wnd->getOS2WindowHandle(), FC_NOSETACTIVE);
741 }
742 else DebugInt3();
743 }
744 break;
745
746 case WIN32APP_CHNGEFRAMECTRLS:
747 {
748 dprintf(("OS2: WIN32APP_CHANGEFRAMECTRLS"));
749 OSLibSetWindowStyle(win32wnd->getOS2FrameWindowHandle(), win32wnd->getOS2WindowHandle(), (ULONG)mp1, win32wnd->getExStyle(), (ULONG)mp2);
750 break;
751 }
752
753 case WM_SETFOCUS:
754 {
755 HWND hwndFocus = (HWND)mp1;
756
757 dprintf(("OS2: WM_SETFOCUS %x %x (%x) %d cur focus %x", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle(hwndFocus), mp2, WinQueryFocus(HWND_DESKTOP)));
758
759 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
760 //must delay this function call
761
762 teb->o.odin.fWM_SETFOCUS = TRUE;
763 teb->o.odin.hwndFocus = 0;
764 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC)
765 {
766 //another (non-win32) application's window
767 //set to NULL (allowed according to win32 SDK) to avoid problems
768 hwndFocus = NULL;
769 }
770 if((ULONG)mp2 == TRUE) {
771 HWND hwndFocusWin32 = OS2ToWin32Handle(hwndFocus);
772 recreateCaret (hwndFocusWin32);
773 win32wnd->MsgSetFocus(hwndFocusWin32);
774 }
775 else {
776 //If SetFocus(0) was called, then the window has already received
777 //a WM_KILLFOCUS; don't send another one
778 if(!fIgnoreKeystrokes) {
779 win32wnd->MsgKillFocus(OS2ToWin32Handle(hwndFocus));
780 }
781 else dprintf(("Window has already received a WM_KILLFOCUS (SetFocus(0)); ignore"));
782 }
783 teb->o.odin.fWM_SETFOCUS = FALSE;
784
785 break;
786 }
787
788 //**************************************************************************
789 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
790 //**************************************************************************
791
792 case WM_BUTTON1DOWN:
793 case WM_BUTTON1UP:
794 case WM_BUTTON1DBLCLK:
795 case WM_BUTTON2DOWN:
796 case WM_BUTTON2UP:
797 case WM_BUTTON2DBLCLK:
798 case WM_BUTTON3DOWN:
799 case WM_BUTTON3UP:
800 case WM_BUTTON3DBLCLK:
801 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
802 RELEASE_WNDOBJ(win32wnd);
803 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
804 }
805 if(win32wnd)
806 win32wnd->MsgButton(pWinMsg);
807
808 rc = (MRESULT)TRUE;
809 break;
810
811 case WM_BUTTON2MOTIONSTART:
812 case WM_BUTTON2MOTIONEND:
813 case WM_BUTTON2CLICK:
814 case WM_BUTTON1MOTIONSTART:
815 case WM_BUTTON1MOTIONEND:
816 case WM_BUTTON1CLICK:
817 case WM_BUTTON3MOTIONSTART:
818 case WM_BUTTON3MOTIONEND:
819 case WM_BUTTON3CLICK:
820 rc = (MRESULT)TRUE;
821 break;
822
823 case WM_MOUSEMOVE:
824 {
825 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
826 RELEASE_WNDOBJ(win32wnd);
827 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
828 }
829 if(win32wnd)
830 win32wnd->MsgMouseMove(pWinMsg);
831 break;
832 }
833
834 case WM_CONTROL:
835 goto RunDefWndProc;
836
837 case WM_COMMAND:
838 dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2));
839 win32wnd->DispatchMsgA(pWinMsg);
840 break;
841
842 case WM_SYSCOMMAND:
843 dprintf(("OS2: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
844 win32wnd->DispatchMsgA(pWinMsg);
845 break;
846
847 case WM_RENDERFMT:
848 case WM_RENDERALLFMTS:
849 case WM_DESTROYCLIPBOARD:
850 case WM_DRAWCLIPBOARD:
851 win32wnd->DispatchMsgA(pWinMsg);
852 break;
853
854 case WM_CHAR_SPECIAL:
855 /* NO BREAK! FALLTHRU CASE! */
856
857 case WM_CHAR:
858 dprintf(("OS2: WM_CHAR %x %x %x, %x %x focus wnd %x", win32wnd->getWindowHandle(), mp1, mp2, pWinMsg->wParam, pWinMsg->lParam, WinQueryFocus(HWND_DESKTOP)));
859 win32wnd->MsgChar(pWinMsg);
860 break;
861
862 case WM_TIMER:
863 dprintf(("OS2: WM_TIMER %x %x time %x", win32wnd->getWindowHandle(), pWinMsg->wParam, GetTickCount()));
864 win32wnd->DispatchMsgA(pWinMsg);
865 goto RunDefWndProc;
866
867 case WM_SETWINDOWPARAMS:
868 {
869 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
870
871 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
872 if(wndParams->fsStatus & WPM_TEXT) {
873 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
874 }
875 goto RunDefWndProc;
876 }
877
878 case WM_QUERYWINDOWPARAMS:
879 {
880 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
881 ULONG textlen;
882 PSZ wintext;
883
884 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
885 {
886 if(wndpars->fsStatus & WPM_TEXT)
887 win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
888 if(wndpars->fsStatus & WPM_CCHTEXT)
889 wndpars->cchText = win32wnd->MsgGetTextLength();
890
891 wndpars->fsStatus = 0;
892 wndpars->cbCtlData = 0;
893 wndpars->cbPresParams = 0;
894 rc = (MRESULT)TRUE;
895 break;
896 }
897 goto RunDefWndProc;
898 }
899
900 case WM_PAINT:
901 {
902 RECTL rectl;
903 BOOL rc;
904
905 win32wnd->checkForDirtyUpdateRegion();
906
907 rc = WinQueryUpdateRect(hwnd, &rectl);
908 dprintf(("OS2: WM_PAINT %x (%d,%d) (%d,%d) rc=%d", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop, rc));
909
910 if(rc && win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
911 rectl.yBottom != rectl.yTop) && !IsIconic(win32wnd->GetTopParent()))
912 {
913 win32wnd->DispatchMsgA(pWinMsg);
914 if(WinQueryUpdateRect(hwnd, NULL) == TRUE)
915 {//the application didn't validate the update region; Windows
916 //will only send a WM_PAINT once until another part of the
917 //window is invalidated. Unfortunately PM keeps on sending
918 //WM_PAINT messages until we validate the update region.
919
920 win32wnd->saveAndValidateUpdateRegion();
921 }
922 }
923 else goto RunDefWndProc;
924 break;
925 }
926
927 case WM_ERASEBACKGROUND:
928 {
929 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
930 rc = (MRESULT)FALSE;
931 break;
932 }
933
934 case WM_CALCVALIDRECTS:
935 dprintf(("OS2: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
936 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
937 break;
938
939 case WM_REALIZEPALETTE:
940 {
941 dprintf(("OS2: WM_REALIZEPALETTE %x", win32wnd->getWindowHandle()));
942 win32wnd->DispatchMsgA(pWinMsg);
943 break;
944 }
945
946 case WM_HSCROLL:
947 case WM_VSCROLL:
948 dprintf(("OS2: %s %x %x %x", (msg == WM_HSCROLL) ? "WM_HSCROLL" : "WM_VSCROLL", win32wnd->getWindowHandle(), mp1, mp2));
949 win32wnd->DispatchMsgA(pWinMsg);
950 break;
951
952 case DM_DRAGOVER:
953 {
954 PDRAGINFO pDragInfo = (PDRAGINFO)mp1;
955 PDRAGITEM pDragItem;
956 USHORT sxDrop = SHORT1FROMMP(mp2);
957 USHORT syDrop = SHORT2FROMMP(mp2);
958
959 dprintf(("OS2: DM_DRAGOVER %x (%d,%d)", win32wnd->getWindowHandle(), sxDrop, syDrop));
960
961 if(fDragDropDisabled) {
962 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
963 break;
964 }
965
966 //does this window accept dropped files?
967 if(!DragDropAccept(win32wnd->getWindowHandle())) {
968 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
969 break;
970 }
971
972 if(PMDragValidate(pDragInfo) == FALSE) {
973 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
974 break;
975 }
976 if(win32wnd->isDragDropActive() == FALSE) {
977 ULONG ulBytes, cItems;
978 char *pszFiles;
979
980 pszFiles = PMDragExtractFiles(pDragInfo, &cItems, &ulBytes);
981 if(pszFiles) {
982 POINT point = {sxDrop, syDrop};
983 if(DragDropDragEnter(win32wnd->getWindowHandle(), point, cItems, pszFiles, ulBytes, DROPEFFECT_COPY_W) == FALSE) {
984 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
985 }
986 else {
987 fDragDropActive = TRUE;
988 rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
989 win32wnd->setDragDropActive(TRUE);
990 }
991 free(pszFiles);
992 }
993 else {
994 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
995 }
996 }
997 else {
998 if(DragDropDragOver(win32wnd->getWindowHandle(), DROPEFFECT_COPY_W) == FALSE) {
999 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
1000 }
1001 else rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
1002 }
1003 break;
1004 }
1005
1006 case DM_DRAGLEAVE:
1007 {
1008 dprintf(("OS2: DM_DRAGLEAVE %x", win32wnd->getWindowHandle()));
1009
1010 if(fDragDropDisabled) {
1011 break;
1012 }
1013
1014 fDragDropActive = FALSE;
1015
1016 //does this window accept dropped files?
1017 if(!DragDropAccept(win32wnd->getWindowHandle())) {
1018 break;
1019 }
1020
1021 DragDropDragLeave(win32wnd->getWindowHandle());
1022 win32wnd->setDragDropActive(FALSE);
1023 break;
1024 }
1025
1026 case DM_DROP:
1027 {
1028 PDRAGINFO pDragInfo = (PDRAGINFO)mp1;
1029 PDRAGITEM pDragItem;
1030 USHORT sxDrop = SHORT1FROMMP(mp2);
1031 USHORT syDrop = SHORT2FROMMP(mp2);
1032 USHORT usIndicator, usOp;
1033
1034 dprintf(("OS2: DM_DROP %x (%d,%d)", win32wnd->getWindowHandle(), sxDrop, syDrop));
1035
1036 fDragDropActive = FALSE;
1037 rc = (MRFROM2SHORT (DOR_NODROP, 0));
1038
1039 if(fDragDropDisabled) {
1040 rc = (MRFROM2SHORT (DOR_NODROP, 0));
1041 break;
1042 }
1043
1044 //does this window accept dropped files?
1045 if(!DragDropAccept(win32wnd->getWindowHandle())) {
1046 break;
1047 }
1048
1049 ULONG ulBytes, cItems;
1050 char *pszFiles;
1051
1052 pszFiles = PMDragExtractFiles(pDragInfo, &cItems, &ulBytes);
1053 if(pszFiles) {
1054 POINT point = {sxDrop, syDrop};
1055 if(DragDropFiles(win32wnd->getWindowHandle(), point, cItems, pszFiles, ulBytes) == FALSE) {
1056 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
1057 }
1058 else {
1059 rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
1060 win32wnd->setDragDropActive(FALSE);
1061 }
1062 free(pszFiles);
1063 }
1064 else {
1065 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
1066 }
1067 break;
1068 }
1069
1070 case WM_DDE_INITIATE:
1071 case WM_DDE_INITIATEACK:
1072 case WM_DDE_REQUEST:
1073 case WM_DDE_ACK:
1074 case WM_DDE_DATA:
1075 case WM_DDE_ADVISE:
1076 case WM_DDE_UNADVISE:
1077 case WM_DDE_POKE:
1078 case WM_DDE_EXECUTE:
1079 case WM_DDE_TERMINATE:
1080 dprintf(("OS2: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
1081 goto RunDefWndProc;
1082
1083 case WM_INITMENU:
1084 case WM_MENUSELECT:
1085 case WM_MENUEND:
1086 case WM_NEXTMENU:
1087 case WM_SYSCOLORCHANGE:
1088 case WM_SYSVALUECHANGED:
1089 case WM_SETSELECTION:
1090 case WM_PPAINT:
1091 case WM_PSETFOCUS:
1092 case WM_PSYSCOLORCHANGE:
1093 case WM_PSIZE:
1094 case WM_PACTIVATE:
1095 case WM_PCONTROL:
1096 case WM_HELP:
1097 case WM_APPTERMINATENOTIFY:
1098 case WM_PRESPARAMCHANGED:
1099 case WM_DRAWITEM:
1100 case WM_MEASUREITEM:
1101 case WM_CONTROLPOINTER:
1102 case WM_QUERYDLGCODE:
1103 case WM_SUBSTITUTESTRING:
1104 case WM_MATCHMNEMONIC:
1105 case WM_SAVEAPPLICATION:
1106 case WM_SEMANTICEVENT:
1107 default:
1108 dprintf2(("OS2: RunDefWndProc hwnd %x msg %x mp1 %x mp2 %x", hwnd, msg, mp1, mp2));
1109 goto RunDefWndProc;
1110 }
1111 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1112 RestoreOS2TIB();
1113
1114#ifdef DEBUG
1115 dbg_ThreadPopCall();
1116#endif
1117 return (MRESULT)rc;
1118
1119RunDefWndProc:
1120// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
1121 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1122 RestoreOS2TIB();
1123
1124#ifdef DEBUG
1125 dbg_ThreadPopCall();
1126#endif
1127 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
1128} /* End of Win32WindowProc */
1129//******************************************************************************
1130//******************************************************************************
1131MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1132{
1133 POSTMSG_PACKET *postmsg;
1134 OSLIBPOINT point, ClientPoint;
1135 Win32BaseWindow *win32wnd;
1136 TEB *teb;
1137 MRESULT rc = 0;
1138 MSG winMsg, *pWinMsg;
1139
1140#ifdef DEBUG
1141 dbg_ThreadPushCall("Win32FrameWindowProc");
1142#endif
1143
1144 //Restore our FS selector
1145 SetWin32TIB();
1146
1147 // BEGIN NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
1148 teb = GetThreadTEB();
1149 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
1150
1151 // do some sanity checking here:
1152 // - we need to have a TEB handle
1153 // - unless this is WM_CREATE (the very first message), there has to be
1154 // a USER32 window object for this window handle
1155 if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
1156 dprintf(("PMFRAME: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
1157 goto RunDefFrameWndProc;
1158 }
1159//// if(teb->o.odin.fIgnoreMsgs) {
1160//// goto RunDefWndProc;
1161//// }
1162
1163 // check if the message state counter in the TEB is odd
1164 // This means the message has been sent directly from PM to our message
1165 // handler (so it is the first time we know about this PM message).
1166 // If this is the case, we have to translate it here to a Win32
1167 // message first. The other case is that the message is the result of a
1168 // WinDispatchMsg call and therefore has already been translated.
1169 if((teb->o.odin.msgstate & 1) == 0)
1170 {//message that was sent directly to our window proc handler; translate it here
1171 QMSG qmsg;
1172
1173 qmsg.msg = msg;
1174 qmsg.hwnd = hwnd;
1175 qmsg.mp1 = mp1;
1176 qmsg.mp2 = mp2;
1177 qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
1178 WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
1179 qmsg.reserved = 0;
1180
1181 if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
1182 {//message was not translated
1183 memset(&winMsg, 0, sizeof(MSG));
1184 }
1185 pWinMsg = &winMsg;
1186 }
1187 else {
1188 // message has already been translated before (GetMessage/PeekMessage).
1189 // Use the translated information. Flip the translation flag.
1190 pWinMsg = &teb->o.odin.msg;
1191 teb->o.odin.msgstate++;
1192 }
1193 // END NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
1194
1195 switch( msg )
1196 {
1197 case WM_CREATE:
1198 {
1199 //WM_CREATE handled during client window creation
1200 dprintf(("PMFRAME: WM_CREATE %x", hwnd));
1201 goto RunDefFrameWndProc;
1202 }
1203
1204//hack alert; PM crashes if child calls DestroyWindow for parent/owner in WM_DESTROY
1205// handler; must postpone it, so do it here
1206 case WIN32APP_POSTPONEDESTROY:
1207 OSLibWinDestroyWindow(hwnd);
1208 break;
1209//hack end
1210
1211#ifdef DEBUG
1212 case WM_CLOSE:
1213 {
1214 dprintf(("PMFRAME: WM_CLOSE %x", hwnd));
1215 goto RunDefFrameWndProc;
1216 }
1217#endif
1218
1219 case WM_PAINT:
1220 {
1221 RECTL rectl;
1222
1223 HPS hps = WinBeginPaint(hwnd, NULL, &rectl);
1224 dprintf(("PMFRAME: WM_PAINT %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
1225
1226 if(win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
1227 rectl.yBottom != rectl.yTop))
1228 {
1229 PRECT pClient = win32wnd->getClientRectPtr();
1230 PRECT pWindow = win32wnd->getWindowRect();
1231
1232 if(!(pClient->left == 0 && pClient->top == 0 &&
1233 win32wnd->getClientHeight() == win32wnd->getWindowHeight() &&
1234 win32wnd->getClientWidth() == win32wnd->getWindowWidth()))
1235 {
1236 RECT rectUpdate;
1237
1238 mapOS2ToWin32Rect(win32wnd->getWindowHeight(), (PRECTLOS2)&rectl, &rectUpdate);
1239 win32wnd->MsgNCPaint(&rectUpdate);
1240 }
1241 }
1242 WinEndPaint(hps);
1243 break;
1244 }
1245
1246 case WM_ERASEBACKGROUND:
1247 {
1248 dprintf(("PMFRAME:WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
1249 rc = (MRESULT)FALSE;
1250 break;
1251 }
1252
1253 //**************************************************************************
1254 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
1255 //**************************************************************************
1256
1257 case WM_BUTTON1DOWN:
1258 case WM_BUTTON1UP:
1259 case WM_BUTTON1DBLCLK:
1260 case WM_BUTTON2DOWN:
1261 case WM_BUTTON2UP:
1262 case WM_BUTTON2DBLCLK:
1263 case WM_BUTTON3DOWN:
1264 case WM_BUTTON3UP:
1265 case WM_BUTTON3DBLCLK:
1266 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
1267 RELEASE_WNDOBJ(win32wnd);
1268 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
1269 }
1270 if(win32wnd)
1271 win32wnd->MsgButton(pWinMsg);
1272
1273 rc = (MRESULT)TRUE;
1274 break;
1275
1276 case WM_BUTTON2MOTIONSTART:
1277 case WM_BUTTON2MOTIONEND:
1278 case WM_BUTTON2CLICK:
1279 case WM_BUTTON1MOTIONSTART:
1280 case WM_BUTTON1MOTIONEND:
1281 case WM_BUTTON1CLICK:
1282 case WM_BUTTON3MOTIONSTART:
1283 case WM_BUTTON3MOTIONEND:
1284 case WM_BUTTON3CLICK:
1285 rc = (MRESULT)TRUE;
1286 break;
1287
1288 case WM_MOUSEMOVE:
1289 {
1290 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
1291 RELEASE_WNDOBJ(win32wnd);
1292 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
1293 }
1294 if(win32wnd)
1295 win32wnd->MsgMouseMove(pWinMsg);
1296 break;
1297 }
1298
1299 case WM_CHAR_SPECIAL_CONSOLE_BREAK:
1300 {
1301 //ignore this message. don't forward it to the default PM frame window handler
1302 //as that one sends it to the client. as a result we end up translating
1303 //it twice
1304 break;
1305 }
1306
1307 case WM_ADJUSTWINDOWPOS:
1308 {
1309 PSWP pswp = (PSWP)mp1;
1310 SWP swpOld;
1311 WINDOWPOS wp,wpOld;
1312 ULONG ulFlags;
1313 ULONG ret = 0;
1314 HWND hParent = NULLHANDLE, hwndAfter;
1315
1316 dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS %x %x %x (%s) (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy));
1317
1318 ulFlags = pswp->fl;
1319
1320 if(win32wnd->IsParentChanging()) {
1321 rc = 0;
1322 break;
1323 }
1324
1325 //@@PF all commands from minimized window viewer or from Ctrl-Esc
1326 //are 'pure' and should be handled only by DeFrameProc - this is weird
1327 //but without them we will not have results. Pure = plain flag of restore/minimize/maximize
1328 if((pswp->fl == SWP_MINIMIZE) || (pswp->fl & SWP_RESTORE)) {
1329 // note the purity of SWP no other SWP_FLAGS allowed
1330 goto RunDefFrameWndProc;
1331 }
1332
1333 if(pswp->fl & SWP_NOADJUST) {
1334 //ignore weird messages (TODO: why are they sent?)
1335 dprintf(("WARNING: WM_ADJUSTWINDOWPOS with SWP_NOADJUST flag!!"));
1336 break;
1337 }
1338 if ((pswp->fl == SWP_FOCUSACTIVATE) || (pswp->fl == SWP_FOCUSDEACTIVATE))
1339 {
1340 dprintf(("Pure focus flags are not sent to win32 windows"));
1341 goto RunDefFrameWndProc;
1342 }
1343
1344 //CB: show dialog in front of owner
1345 if (win32wnd->IsModalDialogOwner())
1346 {
1347 dprintf(("win32wnd->IsModalDialogOwner %x", win32wnd->getWindowHandle()));
1348 pswp->fl |= SWP_ZORDER;
1349 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
1350 if (pswp->fl & SWP_ACTIVATE)
1351 {
1352 pswp->fl &= ~SWP_ACTIVATE;
1353 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
1354 }
1355 }
1356
1357 if(!win32wnd->CanReceiveSizeMsgs())
1358 break;
1359
1360 WinQueryWindowPos(hwnd, &swpOld);
1361 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
1362 if (win32wnd->isChild()) {
1363 if(win32wnd->getParent()) {
1364 hParent = win32wnd->getParent()->getOS2WindowHandle();
1365 }
1366 else goto RunDefFrameWndProc;
1367 }
1368 }
1369 hwndAfter = pswp->hwndInsertBehind;
1370 if(win32wnd->getParent()) {
1371 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(), hwnd);
1372 }
1373 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1374
1375 wp.hwnd = win32wnd->getWindowHandle();
1376 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1377 {
1378 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1379 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
1380 if(wndAfter) {
1381 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1382 RELEASE_WNDOBJ(wndAfter);
1383 }
1384 else wp.hwndInsertAfter = HWND_TOP_W;
1385 }
1386
1387 wpOld = wp;
1388 win32wnd->MsgPosChanging((LPARAM)&wp);
1389
1390 if(win32wnd->getOldStyle() != win32wnd->getStyle())
1391 {
1392 OSLibSetWindowStyle(win32wnd->getOS2FrameWindowHandle(), win32wnd->getOS2WindowHandle(), win32wnd->getStyle(), win32wnd->getExStyle(), win32wnd->getStyle());
1393 if(fOS2Look) {
1394 DWORD dwOldStyle = win32wnd->getOldStyle();
1395 DWORD dwStyle = win32wnd->getStyle();
1396
1397 win32wnd->setOldStyle(dwStyle);
1398 if((dwOldStyle & WS_MINIMIZE_W) && !(dwStyle & WS_MINIMIZE_W)) {
1399 //SC_RESTORE -> SC_MINIMIZE
1400 dprintf(("%x -> SC_RESTORE -> SC_MINIMIZE", win32wnd->getWindowHandle()));
1401 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_RESTORE, SC_MINIMIZE, hbmFrameMenu[PMMENU_MINBUTTON]);
1402 if(dwStyle & WS_MAXIMIZE_W) {
1403 //SC_MAXIMIZE -> SC_RESTORE
1404 dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE (1)", win32wnd->getWindowHandle()));
1405 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[PMMENU_RESTOREBUTTON]);
1406 }
1407 }
1408 else
1409 if((dwOldStyle & WS_MAXIMIZE_W) && !(dwStyle & WS_MAXIMIZE_W)) {
1410 //SC_RESTORE -> SC_MAXIMIZE
1411 dprintf(("%x -> SC_RESTORE -> SC_MAXIMIZE", win32wnd->getWindowHandle()));
1412 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_RESTORE, SC_MAXIMIZE, hbmFrameMenu[PMMENU_MAXBUTTON]);
1413 }
1414 else
1415 if(!(dwOldStyle & WS_MINIMIZE_W) && (dwStyle & WS_MINIMIZE_W)) {
1416 //SC_MINIMIZE -> SC_RESTORE
1417 dprintf(("%x -> SC_MINIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
1418 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_MINIMIZE, SC_RESTORE, hbmFrameMenu[PMMENU_RESTOREBUTTON]);
1419 }
1420 else
1421 if(!(dwOldStyle & WS_MAXIMIZE_W) && (dwStyle & WS_MAXIMIZE_W)) {
1422 //SC_MAXIMIZE -> SC_RESTORE
1423 dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE (2)", win32wnd->getWindowHandle()));
1424 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[PMMENU_RESTOREBUTTON]);
1425 }
1426 }
1427 }
1428
1429 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
1430 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
1431 {
1432 ULONG flags = pswp->fl; //make a backup copy; OSLibMapWINDOWPOStoSWP will modify it
1433
1434 dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
1435 dprintf(("%x (%s) (%d,%d), (%d,%d)", pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy));
1436
1437 if(win32wnd->getParent()) {
1438 OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getClientHeight(),
1439 hwnd);
1440 }
1441 else OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1442
1443 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
1444
1445 //OSLibMapWINDOWPOStoSWP can add flags, but we must not let it remove flags!
1446 if(pswp->fl & SWP_SIZE)
1447 flags |= SWP_SIZE;
1448
1449 if(pswp->fl & SWP_MOVE)
1450 flags |= SWP_MOVE;
1451
1452 pswp->fl = flags; //restore flags
1453
1454 pswp->fl |= SWP_NOADJUST;
1455 pswp->hwndInsertBehind = hwndAfter;
1456 pswp->hwnd = hwnd;
1457
1458 ret = 0xf;
1459 }
1460adjustend:
1461 //The next part needs to be done for top-level windows only
1462 if(!((win32wnd->getStyle() & (WS_POPUP_W|WS_CHILD_W)) == WS_CHILD_W))
1463 {
1464 //Setting these flags is necessary to avoid activation/focus problems
1465 if(ulFlags & SWP_DEACTIVATE) {
1466 ret |= AWP_DEACTIVATE;
1467 }
1468 if(ulFlags & SWP_ACTIVATE)
1469 {
1470 if(ulFlags & SWP_ZORDER) {
1471 dprintf(("Set FF_NOACTIVATESWP"));
1472 ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
1473 WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags | FF_NOACTIVATESWP);
1474 }
1475
1476 if(!(ulFlags & SWP_SHOW))
1477 {
1478 ret |= AWP_ACTIVATE;
1479 }
1480 else
1481 {
1482 FrameSetFocus(hwnd);
1483 }
1484 }
1485 }
1486 else {
1487 if(ulFlags & (SWP_ACTIVATE|SWP_FOCUSACTIVATE))
1488 {
1489 win32wnd->MsgChildActivate(TRUE);
1490 if(fOS2Look) {
1491 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1492 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, (MPARAM)1, 0);
1493 }
1494 }
1495 else
1496 if(ulFlags & (SWP_DEACTIVATE|SWP_FOCUSDEACTIVATE))
1497 {
1498 win32wnd->MsgChildActivate(FALSE);
1499 if(fOS2Look) {
1500 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1501 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, 0, 0);
1502 }
1503 }
1504 }
1505#ifdef DEBUG
1506 dprintf(("WM_ADJUSTWINDOWPOS ret %x flags %x", ret, WinQueryWindowUShort(hwnd, QWS_FLAGS)));
1507 if(ret == 0x0f) {
1508 dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
1509 dprintf(("%x (%s) (%d,%d), (%d,%d)", pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy));
1510 }
1511#endif
1512 rc = (MRESULT)ret;
1513 break;
1514 }
1515
1516 case WM_WINDOWPOSCHANGED:
1517 {
1518 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
1519 SWP swpOld = *(pswp + 1);
1520 WINDOWPOS wp;
1521 ULONG flAfp = (ULONG)mp2;
1522 HWND hParent = NULLHANDLE;
1523 RECTL rect;
1524
1525 dprintf(("PMFRAME:WM_WINDOWPOSCHANGED (%x) %x %x (%s) (%d,%d) (%d,%d) z %x", mp2, win32wnd->getWindowHandle(), pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy, Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind)));
1526 if(win32wnd->IsParentChanging()) {
1527 goto PosChangedEnd;
1528 }
1529
1530 // PF: MDI window is not a common OS/2 frame window so we just skipped all
1531 // PM default processing for it that basicly moved this window to 0,0 point
1532 // and changed frame controls. Now do our own processing.
1533
1534 if ((pswp->fl & SWP_MAXIMIZE) && (win32wnd->getExStyle() & WS_EX_MDICHILD_W))
1535 {
1536 SendMessageA(win32wnd->getWindowHandle(), WM_SYSCOMMAND_W, SC_MAXIMIZE_W, 0);
1537 goto PosChangedEnd;
1538 }
1539
1540 //SvL: When a window is made visible, then we don't receive a
1541 // WM_VRNENABLED message (for some weird reason)
1542 if(pswp->fl & SWP_SHOW) {
1543 win32wnd->callVisibleRgnNotifyProc(TRUE);
1544 }
1545 else
1546 if(pswp->fl & SWP_HIDE) {
1547 win32wnd->callVisibleRgnNotifyProc(FALSE);
1548 }
1549
1550 if(pswp->fl & (SWP_MOVE | SWP_SIZE))
1551 {
1552 if(win32wnd->isChild())
1553 {
1554 if(win32wnd->getParent()) {
1555 hParent = win32wnd->getParent()->getOS2WindowHandle();
1556 }
1557 else goto PosChangedEnd; //parent has just been destroyed
1558 }
1559 }
1560
1561
1562 if(win32wnd->getParent()) {
1563 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1564 hwnd);
1565 }
1566 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1567
1568 wp.hwnd = win32wnd->getWindowHandle();
1569 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1570 {
1571 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1572 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
1573 if(wndAfter) {
1574 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1575 RELEASE_WNDOBJ(wndAfter);
1576 }
1577 else wp.hwndInsertAfter = HWND_TOP_W;
1578 }
1579
1580 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
1581 {
1582 if(pswp->fl & SWP_RESTORE && win32wnd->getStyle() & WS_MINIMIZE_W) {
1583 dprintf(("Restoring minimized window %x", win32wnd->getWindowHandle()));
1584 win32wnd->ShowWindow(SW_RESTORE_W);
1585 }
1586 if(pswp->fl & SWP_SHOW) {
1587 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
1588 }
1589 else
1590 if(pswp->fl & SWP_HIDE) {
1591 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
1592 }
1593 if(pswp->fl & (SWP_SHOW|SWP_HIDE))
1594 {//TODO: necessary for more options? (activate?)
1595 if(win32wnd->CanReceiveSizeMsgs())
1596 win32wnd->MsgPosChanged((LPARAM)&wp);
1597 }
1598
1599 //MUST call the old frame window proc!
1600 goto RunDefFrameWndProc;
1601 }
1602
1603 if(pswp->fl & SWP_SHOW) {
1604 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
1605 }
1606 else
1607 if(pswp->fl & SWP_HIDE) {
1608 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
1609 }
1610
1611 if(flAfp & AWP_ACTIVATE)
1612 {
1613 FrameSetFocus(hwnd);
1614 }
1615
1616#ifndef USE_CALCVALIDRECT
1617 if((pswp->fl & (SWP_MOVE | SWP_SIZE)))
1618 {
1619 //CB: todo: use result for WM_CALCVALIDRECTS
1620 //Get old client rectangle (for invalidation of frame window parts later on)
1621 //Use new window height to calculate the client area
1622 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
1623
1624 //Note: Also updates the new window rectangle
1625 win32wnd->MsgFormatFrame(&wp);
1626
1627 if(win32wnd->isOwnDC()) {
1628 setPageXForm(win32wnd, (pDCData)GpiQueryDCData(win32wnd->getOwnDC()));
1629 }
1630
1631 if(win32wnd->CanReceiveSizeMsgs())
1632 win32wnd->MsgPosChanged((LPARAM)&wp);
1633
1634 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
1635 {
1636 //redraw the frame (to prevent unnecessary client updates)
1637 BOOL redrawAll = FALSE;
1638
1639 dprintf2(("WM_WINDOWPOSCHANGED: redraw frame"));
1640 if (win32wnd->getWindowClass())
1641 {
1642 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
1643
1644 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
1645 redrawAll = TRUE;
1646 else
1647 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
1648 redrawAll = TRUE;
1649 }
1650 else redrawAll = TRUE;
1651
1652 if(win32wnd->IsMixMaxStateChanging()) {
1653 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1654 redrawAll = TRUE;
1655 }
1656
1657 if (redrawAll)
1658 {
1659 //CB: redraw all children for now
1660 // -> problems with update region if we don't do it
1661 // todo: rewrite whole handling
1662 dprintf(("PMFRAME: WM_WINDOWPOSCHANGED invalidate all"));
1663 WinInvalidateRect(hwnd,NULL,TRUE);
1664 }
1665 else
1666 {
1667 HPS hps = WinGetPS(hwnd);
1668 RECTL frame,client,arcl[4];
1669
1670 WinQueryWindowRect(hwnd,&frame);
1671
1672 //top
1673 arcl[0].xLeft = 0;
1674 arcl[0].xRight = frame.xRight;
1675 arcl[0].yBottom = rect.yTop;
1676 arcl[0].yTop = frame.yTop;
1677 //right
1678 arcl[1].xLeft = rect.xRight;
1679 arcl[1].xRight = frame.xRight;
1680 arcl[1].yBottom = 0;
1681 arcl[1].yTop = frame.yTop;
1682 //left
1683 arcl[2].xLeft = 0;
1684 arcl[2].xRight = rect.xLeft;
1685 arcl[2].yBottom = 0;
1686 arcl[2].yTop = frame.yTop;
1687 //bottom
1688 arcl[3].xLeft = 0;
1689 arcl[3].xRight = frame.xRight;
1690 arcl[3].yBottom = 0;
1691 arcl[3].yTop = rect.yBottom;
1692
1693 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
1694
1695 WinInvalidateRegion(hwnd,hrgn,FALSE);
1696 GpiDestroyRegion(hps,hrgn);
1697 WinReleasePS(hps);
1698 }
1699 }
1700 }
1701 else
1702 {
1703#endif //USE_CALCVALIDRECT
1704 if(win32wnd->CanReceiveSizeMsgs())
1705 win32wnd->MsgPosChanged((LPARAM)&wp);
1706#ifndef USE_CALCVALIDRECT
1707 }
1708#endif
1709 //PF This is the final step of PM restoration - should end up
1710 //in default handler.
1711 if (win32wnd->getOldStyle() & WS_MINIMIZE_W && pswp->fl & SWP_RESTORE)
1712 goto RunDefFrameWndProc;
1713
1714PosChangedEnd:
1715 rc = (MRESULT)FALSE;
1716 break;
1717 }
1718
1719 case WM_CALCVALIDRECTS:
1720#ifdef USE_CALCVALIDRECT
1721 {
1722 PRECTL oldRect = (PRECTL)mp1, newRect = oldRect+1;
1723 PSWP pswp = (PSWP)mp2;
1724 SWP swpOld;
1725 WINDOWPOS wp;
1726 RECTL newClientRect, oldClientRect;
1727 ULONG nccalcret;
1728// UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
1729 UINT res = 0;
1730
1731 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1732
1733 //Get old position info
1734 WinQueryWindowPos(hwnd, &swpOld);
1735
1736 if(win32wnd->getParent()) {
1737 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1738 win32wnd->getParent()->getClientRectPtr()->left,
1739 win32wnd->getParent()->getClientRectPtr()->top,
1740 hwnd);
1741 }
1742 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
1743
1744 wp.hwnd = win32wnd->getWindowHandle();
1745 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1746 {
1747 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1748 if(wndAfter) {
1749 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1750 RELEASE_WNDOBJ(wndAfter);
1751 }
1752 else wp.hwndInsertAfter = HWND_TOP_W;
1753 }
1754
1755 //Get old client rectangle
1756 mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
1757
1758 //Note: Also updates the new window rectangle
1759 nccalcret = win32wnd->MsgFormatFrame(&wp);
1760
1761 //Get new client rectangle
1762 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
1763
1764 if(nccalcret == 0) {
1765 res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
1766 }
1767 else {
1768 if(nccalcret & WVR_ALIGNTOP_W) {
1769 res |= CVR_ALIGNTOP;
1770 }
1771 else
1772 if(nccalcret & WVR_ALIGNBOTTOM_W) {
1773 res |= CVR_ALIGNBOTTOM;
1774 }
1775
1776 if(nccalcret & WVR_ALIGNLEFT_W) {
1777 res |= CVR_ALIGNLEFT;
1778 }
1779 else
1780 if(nccalcret & WVR_ALIGNRIGHT_W) {
1781 res |= CVR_ALIGNRIGHT;
1782 }
1783
1784 if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
1785 res |= CVR_REDRAW;
1786 }
1787 else
1788 if(nccalcret & WVR_VALIDRECTS_W) {
1789 //TODO:
1790 //res = 0;
1791 }
1792 }
1793 if(win32wnd->IsMixMaxStateChanging()) {
1794 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1795 res |= CVR_REDRAW;
1796 }
1797 if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
1798 oldRect->xRight -= oldClientRect.xLeft;
1799 oldRect->yBottom += oldClientRect.yBottom;
1800 newRect->xRight -= newClientRect.xLeft;
1801 newRect->yBottom += newClientRect.yBottom;
1802 }
1803 rc = res;
1804 break;
1805 }
1806#else
1807 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1808 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
1809 break;
1810#endif
1811
1812 case WM_CALCFRAMERECT:
1813 dprintf(("PMFRAME:WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
1814 rc = (MRESULT)TRUE;
1815 break;
1816
1817 case WM_QUERYCTLTYPE:
1818 // This is a frame window
1819 dprintf(("PMFRAME:WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
1820 rc = (MRESULT)CCT_FRAME;
1821 break;
1822
1823#ifdef DEBUG
1824 case WM_QUERYFOCUSCHAIN:
1825 dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x (%s) parent %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), DbgPrintQFCFlags(SHORT1FROMMP(mp1)), (mp2) ? OS2ToWin32Handle((DWORD)mp2) : 0));
1826
1827 RestoreOS2TIB();
1828 rc = pfnFrameWndProc(hwnd, msg, mp1, mp2);
1829 SetWin32TIB();
1830 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));
1831 break;
1832// goto RunDefFrameWndProc;
1833#endif
1834
1835 case WM_FOCUSCHANGE:
1836 {
1837 HWND hwndFocus = (HWND)mp1;
1838 HWND hwndLoseFocus, hwndGainFocus;
1839 USHORT usSetFocus = SHORT1FROMMP(mp2);
1840 USHORT fsFocusChange = SHORT2FROMMP(mp2);
1841
1842 //Save window that gains focus so we can determine which
1843 //process we lose activation to
1844 hwndFocusChange = (HWND)mp1;
1845
1846 dprintf(("PMFRAME:WM_FOCUSCHANGE %x %x (%x) %x %x", win32wnd->getWindowHandle(), OS2ToWin32Handle(hwndFocus), hwndFocus, usSetFocus, fsFocusChange));
1847 goto RunDefFrameWndProc;
1848 }
1849
1850#ifdef DEBUG
1851 case WM_SETFOCUS:
1852 {
1853 dprintf(("PMFRAME: WM_SETFOCUS %x %x %d -> %x", win32wnd->getWindowHandle(), hwnd, mp2, mp1));
1854 goto RunDefFrameWndProc;
1855 }
1856#endif
1857
1858 case WM_ACTIVATE:
1859 {
1860 HWND hwndTitle;
1861 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
1862
1863 dprintf(("PMFRAME: WM_ACTIVATE %x %x %x", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle((DWORD)mp2)));
1864 if (win32wnd->IsWindowCreated())
1865 {
1866 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1867 if(fOS2Look) {
1868 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1869 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, mp1, 0);
1870 }
1871 if(SHORT1FROMMP(mp1) == 0) {
1872 //deactivate
1873 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
1874 }
1875 PID pidThis, pidPartner, pidTemp;
1876 TID tidPartner;
1877 HENUM henum;
1878 HWND hwndEnum;
1879
1880 WinQueryWindowProcess(hwnd, &pidThis, NULL);
1881 WinQueryWindowProcess(hwndFocusChange, &pidPartner, &tidPartner);
1882
1883 if(pidThis != pidPartner) {
1884 //Gain or lose activation to window in other process
1885 //must send WM_ACTIVATEAPP to top-level windows
1886
1887 //Iterate over all child windows of the desktop
1888 henum = WinBeginEnumWindows(HWND_DESKTOP);
1889
1890 while(hwndEnum = WinGetNextWindow(henum))
1891 {
1892 WinQueryWindowProcess(hwndEnum, &pidTemp, NULL);
1893 if(pidTemp == pidThis)
1894 {
1895 SendMessageA(OS2ToWin32Handle(hwndEnum), WM_ACTIVATEAPP_W, (WPARAM)SHORT1FROMMP(mp1), (LPARAM)tidPartner);
1896 }
1897 }
1898 WinEndEnumWindows(henum);
1899 }
1900 if(SHORT1FROMMP(mp1)) {
1901 //activate
1902 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
1903 }
1904
1905 //CB: show owner behind the dialog
1906 if (win32wnd->IsModalDialog())
1907 {
1908 if(win32wnd->getOwner()) {
1909 Win32BaseWindow *topOwner = Win32BaseWindow::GetWindowFromHandle(win32wnd->getOwner()->GetTopParent());
1910
1911 if (topOwner) {
1912 WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
1913 RELEASE_WNDOBJ(topOwner);
1914 }
1915 }
1916 }
1917 }
1918 else
1919 {
1920 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1921 }
1922 rc = 0;
1923 break;
1924 }
1925
1926 case WM_ENABLE:
1927 dprintf(("PMFRAME: WM_ENABLE %x", hwnd));
1928 win32wnd->MsgEnable(SHORT1FROMMP(mp1));
1929 break;
1930
1931 case WM_SHOW:
1932 dprintf(("PMFRAME: WM_SHOW %x %d", hwnd, mp1));
1933 //show client window
1934 WinShowWindow(win32wnd->getOS2WindowHandle(), (BOOL)mp1);
1935 break;
1936
1937 case WM_QUERYTRACKINFO:
1938 {
1939 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
1940
1941 dprintf(("PMFRAME:WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
1942 trackInfo->cxBorder = 4;
1943 trackInfo->cyBorder = 4;
1944 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
1945 rc = (MRESULT)TRUE;
1946 break;
1947 }
1948
1949 case WM_QUERYBORDERSIZE:
1950 {
1951 PWPOINT size = (PWPOINT)mp1;
1952
1953 dprintf(("PMFRAME:WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
1954
1955 size->x = 0;
1956 size->y = 0;
1957 rc = (MRESULT)TRUE;
1958 break;
1959 }
1960
1961#ifdef DEBUG
1962 case WM_QUERYFRAMEINFO:
1963 dprintf(("PMFRAME:WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
1964 goto RunDefFrameWndProc;
1965#endif
1966
1967 case WM_FORMATFRAME:
1968 dprintf(("PMFRAME:WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
1969 break;
1970
1971 case WM_ADJUSTFRAMEPOS:
1972 {
1973 PSWP pswp = (PSWP)mp1;
1974
1975 dprintf(("PMFRAME:WM_ADJUSTFRAMEPOS %x %x %x (%s) (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy));
1976 //hack alert: the PM frame control changes the z-order of a child window
1977 // if it receives focus after a window has been destroyed
1978 // We can't let this happen as this messes up assumptions
1979 // elsewhere (e.g. GetNextDlgGroupItem)
1980 // By returning 0 here, we prevent the default frame handler
1981 // from messing things up. (one example is a group of radio buttons)
1982 //NOTE: We really need to get rid of frame & client windows for each
1983 // win32 window
1984 if(pswp->fl == SWP_FOCUSACTIVATE && win32wnd->isChild()) {
1985 rc = 0;
1986 break;
1987 }
1988 //hack alert: as we return zero as border size (check handler) we need
1989 //to do adjustments here as well or PM will calculate it for us and
1990 //result will be illegal. Btw we do not honour PM border size settings
1991 //and never will. I was unable to figure out why only X coordinate
1992 //is being broken but not Y as well.
1993
1994 if ((pswp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1995 {
1996 RECT rect;
1997 rect.left = rect.top = rect.right = rect.bottom = 0;
1998 win32wnd->AdjustMaximizedRect(&rect);
1999
2000 pswp->x += rect.left;
2001 }
2002 goto RunDefFrameWndProc;
2003 }
2004
2005#ifdef DEBUG
2006 case WM_OWNERPOSCHANGE:
2007 {
2008 PSWP pswp = (PSWP)mp1;
2009
2010 dprintf(("PMFRAME:WM_OWNERPOSCHANGE %x %x %x (%s) (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy));
2011 goto RunDefFrameWndProc;
2012 }
2013#endif
2014
2015 case WM_MINMAXFRAME:
2016 {
2017 PSWP swp = (PSWP)mp1;
2018
2019 if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
2020
2021 dprintf(("PMFRAME:WM_MINMAXFRAME %x",hwnd));
2022 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
2023 {
2024 // MDI frame windows are not common PM windows so we need to
2025 // drop-out WHOLE chain of WM_X commands with SWP_MAXIMIZE flag
2026 // finally last WM_WINDOWPOSCHANGED will take care of maximization
2027
2028 if (win32wnd->getExStyle() & WS_EX_MDICHILD_W) {
2029 rc = 0;
2030 break;
2031 }
2032
2033 RECT rect;
2034 rect.left = rect.top = rect.right = rect.bottom = 0;
2035 win32wnd->AdjustMaximizedRect(&rect);
2036
2037 swp->x += rect.left;
2038 swp->cx += rect.right-rect.left;
2039 swp->y -= rect.bottom;
2040 swp->cy += rect.bottom-rect.top;
2041
2042 win32wnd->ShowWindow(SW_RESTORE_W);
2043 }
2044 else
2045 if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
2046 {
2047 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
2048 }
2049 else
2050 if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
2051 {
2052 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
2053 }
2054 goto RunDefWndProc;
2055 }
2056
2057#ifdef DEBUG
2058 case WM_UPDATEFRAME:
2059 dprintf(("PMFRAME:WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
2060 goto RunDefFrameWndProc;
2061#endif
2062
2063 case WM_TRACKFRAME:
2064 dprintf(("PMFRAME: WM_TRACKFRAME %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
2065 if(fOS2Look) {//sent by titlebar control
2066 Frame_SysCommandSizeMove(win32wnd, SC_MOVE_W+HTCAPTION_W);
2067 }
2068 rc = 0;
2069 break;
2070
2071 case WM_SYSCOMMAND:
2072 dprintf(("PMFRAME: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
2073 if (fOS2Look == OS2_APPEARANCE_SYSMENU && mp1 == (MPARAM)OSSC_SYSMENU)
2074 goto RunDefFrameWndProc;
2075
2076 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
2077 RELEASE_WNDOBJ(win32wnd);
2078 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
2079 }
2080 if(win32wnd)
2081 win32wnd->DispatchMsgA(pWinMsg);
2082 break;
2083
2084#ifdef DEBUG
2085 case WM_DDE_INITIATE:
2086 case WM_DDE_INITIATEACK:
2087 case WM_DDE_REQUEST:
2088 case WM_DDE_ACK:
2089 case WM_DDE_DATA:
2090 case WM_DDE_ADVISE:
2091 case WM_DDE_UNADVISE:
2092 case WM_DDE_POKE:
2093 case WM_DDE_EXECUTE:
2094 case WM_DDE_TERMINATE:
2095 dprintf(("PMFRAME: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
2096 break;
2097#endif
2098
2099 default:
2100 goto RunDefFrameWndProc;
2101 }
2102 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2103 RestoreOS2TIB();
2104
2105#ifdef DEBUG
2106 dbg_ThreadPopCall();
2107#endif
2108 return (MRESULT)rc;
2109
2110RunDefFrameWndProc:
2111 dprintf2(("RunDefFrameWndProc"));
2112 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2113 RestoreOS2TIB();
2114
2115#ifdef DEBUG
2116 dbg_ThreadPopCall();
2117#endif
2118 return pfnFrameWndProc(hwnd, msg, mp1, mp2);
2119
2120RunDefWndProc:
2121 dprintf2(("RunDefWndProc"));
2122 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2123 RestoreOS2TIB();
2124 //calling WinDefWindowProc here breaks Opera hotlist window (WM_ADJUSTWINDOWPOS)
2125// return pfnFrameWndProc(hwnd, msg, mp1, mp2);
2126
2127#ifdef DEBUG
2128 dbg_ThreadPopCall();
2129#endif
2130 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
2131}
2132//******************************************************************************
2133//******************************************************************************
2134MRESULT EXPENTRY Win32FakeWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
2135{
2136 PFNWP pfnOldWindowProc;
2137 Win32BaseWindow *win32wnd, *win32wndchild;
2138 TEB *teb;
2139 MRESULT rc = 0;
2140
2141 //Restore our FS selector
2142 SetWin32TIB();
2143
2144 win32wnd = Win32FakeWindow::GetWindowFromOS2Handle(hwnd);
2145 if(win32wnd == NULL) {
2146 DebugInt3();
2147 goto RunDefWndProc;
2148 }
2149
2150 pfnOldWindowProc = (PFNWP)win32wnd->getOldPMWindowProc();
2151 if(pfnOldWindowProc == NULL) {
2152 DebugInt3();
2153 goto RunDefWndProc;
2154 }
2155
2156 RestoreOS2TIB();
2157 rc = pfnOldWindowProc(hwnd, msg, mp1, mp2);
2158 SetWin32TIB();
2159 switch(msg) {
2160 case WM_WINDOWPOSCHANGED:
2161 {
2162 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
2163 SWP swpOld = *(pswp + 1);
2164 WINDOWPOS wp;
2165
2166 if(win32wnd->getParent()) {
2167 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
2168 hwnd);
2169 }
2170 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
2171
2172 win32wnd->SetWindowPos(wp.hwndInsertAfter, wp.x, wp.y, wp.cx, wp.cy, wp.flags);
2173 break;
2174 }
2175
2176 }
2177 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2178 RestoreOS2TIB();
2179 return rc;
2180
2181RunDefWndProc:
2182 RestoreOS2TIB();
2183 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
2184}
2185//******************************************************************************
2186// PMWinSubclassFakeWindow
2187//
2188// Subclass a fake window (converted PM window)
2189//
2190// Parameters
2191//
2192// HWND hwndOS2 - PM handle of fake window
2193//
2194// Returns
2195// NULL - Failure
2196// else - Old PM window procedure
2197//
2198//******************************************************************************
2199PVOID PMWinSubclassFakeWindow(HWND hwndOS2)
2200{
2201 return WinSubclassWindow(hwndOS2, Win32FakeWindowProc);
2202}
2203//******************************************************************************
2204//******************************************************************************
2205void FrameSetFocus(HWND hwnd)
2206{
2207 HWND hwndFocusSave = WinQueryWindowULong(hwnd, QWL_HWNDFOCUSSAVE);
2208 if(!WinIsWindow(hab, hwndFocusSave)) {
2209 hwndFocusSave = WinWindowFromID(hwnd, FID_CLIENT);
2210 WinSetWindowULong(hwnd, QWL_HWNDFOCUSSAVE, hwndFocusSave);
2211 }
2212 dprintf(("FrameSetFocus: hwndFocusSave %x %x", OS2ToWin32Handle(hwndFocusSave), hwndFocusSave));
2213 WinSetFocus(HWND_DESKTOP, hwndFocusSave);
2214
2215 ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
2216 ulFrameFlags &= ~FF_NOACTIVATESWP;
2217 WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags);
2218}
2219//******************************************************************************
2220//******************************************************************************
2221void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG idNew,
2222 HBITMAP hbmNew)
2223{
2224 MENUITEM mi;
2225
2226 if (!hwndMenu)
2227 return;
2228
2229 WinEnableWindowUpdate(hwndMenu, FALSE);
2230
2231 if (WinSendMsg(hwndMenu, MM_QUERYITEM, MPFROM2SHORT(idOld, TRUE), MPFROMP(&mi)))
2232 {
2233 WinSendMsg(hwndMenu, MM_REMOVEITEM, (MPARAM)idOld, 0);
2234 mi.afStyle = MIS_BITMAP | MIS_SYSCOMMAND;
2235 mi.afAttribute = 0;
2236 mi.hwndSubMenu = 0;
2237 mi.id = idNew;
2238 mi.hItem = (ULONG)hbmNew;
2239 WinSendMsg(hwndMenu, MM_INSERTITEM, (MPARAM)&mi, 0);
2240 }
2241 else
2242 dprintf(("WARNING: FrameReplaceMenuItem control %x not found",idOld));
2243
2244 WinEnableWindowUpdate(hwndMenu, TRUE);
2245
2246 WinInvalidateRect(hwndMenu, NULL, TRUE);
2247}
2248//******************************************************************************
2249//******************************************************************************
2250static char *PMDragExtractFiles(PDRAGINFO pDragInfo, ULONG *pcItems, ULONG *pulBytes)
2251{
2252 PDRAGITEM pDragItem;
2253 int i, cItems;
2254 BOOL ret;
2255 char szFileName[CCHMAXPATH];
2256 char szContainerName[CCHMAXPATH];
2257 ULONG ulBytes;
2258 char *pszCurFile = NULL;
2259
2260 /* Get access to the DRAGINFO data structure */
2261 if(!DrgAccessDraginfo(pDragInfo)) {
2262 return NULL;
2263 }
2264
2265 cItems = DrgQueryDragitemCount(pDragInfo);
2266
2267 //computer memory required to hold all filenames
2268 int bufsize = 0;
2269 for (i = 0; i < cItems; i++) {
2270 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
2271
2272 bufsize += DrgQueryStrNameLen(pDragItem->hstrContainerName) + DrgQueryStrNameLen(pDragItem->hstrSourceName);
2273 bufsize++; //0 terminator
2274 bufsize++; //+ potential missing backslash
2275 }
2276 bufsize++; //extra 0 terminator
2277 char *pszFiles = (char *)malloc(bufsize);
2278 if(pszFiles == NULL) {
2279 dprintf(("Out of memory!!"));
2280 DebugInt3();
2281 goto failure;
2282 }
2283 memset(pszFiles, 0, bufsize);
2284
2285 pszCurFile = pszFiles;
2286
2287 //copy all filenames
2288 for (i = 0; i < cItems; i++) {
2289 char *pszTemp = pszCurFile;
2290
2291 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
2292
2293 ulBytes = DrgQueryStrNameLen(pDragItem->hstrContainerName);
2294 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
2295 ulBytes, pszCurFile);
2296 if(pszCurFile[ulBytes-1] != '\\') {
2297 pszCurFile[ulBytes] = '\\';
2298 pszCurFile++;
2299 }
2300 pszCurFile += ulBytes;
2301
2302 ulBytes = DrgQueryStrNameLen(pDragItem->hstrSourceName);
2303 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
2304 ulBytes+1, pszCurFile);
2305 pszCurFile += ulBytes + 1; //+ terminator
2306
2307 dprintf(("dropped file %s", pszTemp));
2308 }
2309
2310 /* Release the draginfo data structure */
2311 DrgFreeDraginfo(pDragInfo);
2312
2313 *pulBytes = bufsize;
2314 *pcItems = cItems;
2315
2316 return pszFiles;
2317
2318failure:
2319 /* Release the draginfo data structure */
2320 DrgFreeDraginfo(pDragInfo);
2321 if(pszFiles) {
2322 free(pszFiles);
2323 }
2324 return NULL;
2325}
2326//******************************************************************************
2327//******************************************************************************
2328static BOOL PMDragValidate(PDRAGINFO pDragInfo)
2329{
2330 PDRAGITEM pDragItem;
2331 ULONG ulBytes;
2332 int i, cItems;
2333 BOOL ret;
2334 char szFileName[CCHMAXPATH];
2335 char szContainerName[CCHMAXPATH];
2336 USHORT usOp = DO_MOVE;
2337
2338 /* Get access to the DRAGINFO data structure */
2339 if(!DrgAccessDraginfo(pDragInfo)) {
2340 return FALSE;
2341 }
2342
2343 /* Can we accept this drop? */
2344 switch (pDragInfo->usOperation) {
2345 /* Return DOR_NODROPOP if current operation */
2346 /* is link or unknown */
2347 case DO_LINK:
2348 case DO_COPY:
2349 case DO_UNKNOWN:
2350 goto failure;
2351
2352 /* Our default operation is Move */
2353 case DO_MOVE:
2354 case DO_DEFAULT:
2355 pDragItem = DrgQueryDragitemPtr(pDragInfo, 0);
2356 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
2357 sizeof(szContainerName),
2358 szContainerName);
2359 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
2360 sizeof(szFileName),
2361 szFileName);
2362 if (!ulBytes) {
2363 goto failure;
2364 }
2365
2366 dprintf(("dropped file %s%s", szContainerName, szFileName));
2367 break;
2368 }
2369
2370 cItems = DrgQueryDragitemCount(pDragInfo);
2371
2372 /* Now, we need to look at each item in turn */
2373 for (i = 0; i < cItems; i++) {
2374 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
2375
2376 /* Make sure we can move for a Move request */
2377 if (!((pDragItem->fsSupportedOps & DO_MOVEABLE) &&
2378 (usOp == (USHORT)DO_MOVE)))
2379 {
2380 dprintf(("item %d not accepted", i));
2381 goto failure;
2382 }
2383 }
2384 /* Release the draginfo data structure */
2385 DrgFreeDraginfo(pDragInfo);
2386 return TRUE;
2387
2388failure:
2389 DrgFreeDraginfo(pDragInfo);
2390 return FALSE;
2391}
2392
2393// @@PF Three funcs to override std class names we use in Odin
2394//******************************************************************************
2395//******************************************************************************
2396void WIN32API SetCustomCDClassName(LPSTR pszCDClassName)
2397{
2398 strcpy(WIN32_CDCLASS, pszCDClassName);
2399}
2400//******************************************************************************
2401//******************************************************************************
2402void WIN32API SetCustomStdClassName(LPSTR pszStdClassName)
2403{
2404 strcpy(WIN32_STDCLASS, pszStdClassName);
2405}
2406//******************************************************************************
2407//******************************************************************************
2408void WIN32API SetCustomStdFrameClassName(LPSTR pszStdFrameClassName)
2409{
2410 strcpy(WIN32_STDFRAMECLASS, pszStdFrameClassName);
2411}
2412//******************************************************************************
2413//******************************************************************************
2414
2415#ifdef DEBUG
2416static char *DbgGetStringSWPFlags(ULONG flags)
2417{
2418 static char szSWPFlags[512];
2419
2420 szSWPFlags[0] = 0;
2421
2422 if(flags & SWP_SIZE) {
2423 strcat(szSWPFlags, "SWP_SIZE ");
2424 }
2425 if(flags & SWP_MOVE) {
2426 strcat(szSWPFlags, "SWP_MOVE ");
2427 }
2428 if(flags & SWP_ZORDER) {
2429 strcat(szSWPFlags, "SWP_ZORDER ");
2430 }
2431 if(flags & SWP_SHOW) {
2432 strcat(szSWPFlags, "SWP_SHOW ");
2433 }
2434 if(flags & SWP_HIDE) {
2435 strcat(szSWPFlags, "SWP_HIDE ");
2436 }
2437 if(flags & SWP_NOREDRAW) {
2438 strcat(szSWPFlags, "SWP_NOREDRAW ");
2439 }
2440 if(flags & SWP_NOADJUST) {
2441 strcat(szSWPFlags, "SWP_NOADJUST ");
2442 }
2443 if(flags & SWP_ACTIVATE) {
2444 strcat(szSWPFlags, "SWP_ACTIVATE ");
2445 }
2446 if(flags & SWP_DEACTIVATE) {
2447 strcat(szSWPFlags, "SWP_DEACTIVATE ");
2448 }
2449 if(flags & SWP_EXTSTATECHANGE) {
2450 strcat(szSWPFlags, "SWP_EXTSTATECHANGE ");
2451 }
2452 if(flags & SWP_MINIMIZE) {
2453 strcat(szSWPFlags, "SWP_MINIMIZE ");
2454 }
2455 if(flags & SWP_MAXIMIZE) {
2456 strcat(szSWPFlags, "SWP_MAXIMIZE ");
2457 }
2458 if(flags & SWP_RESTORE) {
2459 strcat(szSWPFlags, "SWP_RESTORE ");
2460 }
2461 if(flags & SWP_FOCUSACTIVATE) {
2462 strcat(szSWPFlags, "SWP_FOCUSACTIVATE ");
2463 }
2464 if(flags & SWP_FOCUSDEACTIVATE) {
2465 strcat(szSWPFlags, "SWP_FOCUSDEACTIVATE ");
2466 }
2467 if(flags & SWP_NOAUTOCLOSE) {
2468 strcat(szSWPFlags, "SWP_NOAUTOCLOSE ");
2469 }
2470 return szSWPFlags;
2471}
2472static char *DbgPrintQFCFlags(ULONG flags)
2473{
2474 static char szQFCFlags[64];
2475
2476 szQFCFlags[0] = 0;
2477
2478 if(flags & QFC_NEXTINCHAIN) {
2479 strcat(szQFCFlags, "QFC_NEXTINCHAIN");
2480 }
2481 else
2482 if(flags & QFC_ACTIVE) {
2483 strcat(szQFCFlags, "QFC_ACTIVE");
2484 }
2485 else
2486 if(flags & QFC_FRAME) {
2487 strcat(szQFCFlags, "QFC_FRAME");
2488 }
2489 else
2490 if(flags & QFC_SELECTACTIVE) {
2491 strcat(szQFCFlags, "QFC_SELECTACTIVE");
2492 }
2493 else
2494 if(flags & QFC_PARTOFCHAIN) {
2495 strcat(szQFCFlags, "QFC_PARTOFCHAIN");
2496 }
2497
2498 return szQFCFlags;
2499}
2500#endif
Note: See TracBrowser for help on using the repository browser.