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

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

Changes for applications that don't validate the update region of a window during WM_PAINT

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