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

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

some minor updates

File size: 82.0 KB
Line 
1/* $Id: pmwindow.cpp,v 1.206 2003-03-29 16:37:59 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 {
647 dprintf(("OS2: WM_VRNENABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
648 //Always call handler; even if mp1 is 0. If we don't do this, the
649 //DivX 4 player will never be allowed to draw after putting another window
650 //on top of it.
651
652 win32wnd->callVisibleRgnNotifyProc(TRUE);
653 if(!win32wnd->isComingToTop() && ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == WS_EX_TOPMOST_W))
654 {
655 HWND hwndrelated;
656 Win32BaseWindow *topwindow;
657
658 win32wnd->setComingToTop(TRUE);
659
660 hwndrelated = WinQueryWindow(hwnd, QW_PREV);
661 dprintf(("WM_VRNENABLED hwndrelated = %x (hwnd=%x)", hwndrelated, hwnd));
662 topwindow = Win32BaseWindow::GetWindowFromOS2Handle(hwndrelated);
663 if(topwindow == NULL || ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == 0)) {
664 //put window at the top of z order
665 WinSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
666 }
667 if(topwindow) RELEASE_WNDOBJ(topwindow);
668
669 win32wnd->setComingToTop(FALSE);
670 break;
671 }
672 goto RunDefWndProc;
673 }
674
675 case WM_VRNDISABLED:
676 {
677 dprintf(("OS2: WM_VRNDISABLED %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
678 //visible region is about to change or WinLockWindowUpdate called
679 //suspend window drawing
680
681 win32wnd->callVisibleRgnNotifyProc(FALSE);
682 goto RunDefWndProc;
683 }
684
685 case WIN32APP_DDRAWFULLSCREEN:
686 //Changing the size of the win32 window in SetCooperativeLevel can
687 //fail if this happens during WM_ADJUSTWINDOWPOS
688 //NOTE: This is not a good solution, but a proper fix is more difficult
689 // with the current window mess
690 dprintf(("WIN32APP_DDRAWFULLSCREEN %x (%d,%d)", win32wnd->getWindowHandle(), mp1, mp2));
691 SetWindowPos(win32wnd->getWindowHandle(), HWND_TOP_W, 0, 0, (DWORD)mp1, (DWORD)mp2, 0);
692 ShowWindow(win32wnd->getWindowHandle(), SW_SHOW_W);
693 break;
694
695 case WIN32APP_SETFOCUSMSG:
696 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
697 //must delay this function call
698 //mp1 = win32 window handle
699 //mp2 = top parent if activation required
700 dprintf(("USER32: Delayed SetFocus %x %x %x call!", teb->o.odin.hwndFocus, mp1, mp2));
701 if(teb->o.odin.hwndFocus) {
702 RELEASE_WNDOBJ(win32wnd);
703 win32wnd = Win32BaseWindow::GetWindowFromHandle(teb->o.odin.hwndFocus);
704 if(win32wnd) {
705 if(mp2) {
706 SetActiveWindow((HWND)mp2);
707 }
708 if(!IsWindow(win32wnd->getWindowHandle())) break; //abort if window destroyed
709 WinFocusChange(HWND_DESKTOP, win32wnd->getOS2WindowHandle(), FC_NOSETACTIVE);
710 }
711 else DebugInt3();
712 }
713 break;
714
715 case WIN32APP_CHNGEFRAMECTRLS:
716 {
717 dprintf(("OS2: WIN32APP_CHANGEFRAMECTRLS"));
718 OSLibSetWindowStyle(win32wnd->getOS2FrameWindowHandle(), win32wnd->getOS2WindowHandle(), (ULONG)mp1, win32wnd->getExStyle(), (ULONG)mp2);
719 break;
720 }
721
722 case WM_SETFOCUS:
723 {
724 HWND hwndFocus = (HWND)mp1;
725
726 dprintf(("OS2: WM_SETFOCUS %x %x (%x) %d cur focus %x", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle(hwndFocus), mp2, WinQueryFocus(HWND_DESKTOP)));
727
728 //PM doesn't allow SetFocus calls during WM_SETFOCUS message processing;
729 //must delay this function call
730
731 teb->o.odin.fWM_SETFOCUS = TRUE;
732 teb->o.odin.hwndFocus = 0;
733 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC)
734 {
735 //another (non-win32) application's window
736 //set to NULL (allowed according to win32 SDK) to avoid problems
737 hwndFocus = NULL;
738 }
739 if((ULONG)mp2 == TRUE) {
740 HWND hwndFocusWin32 = OS2ToWin32Handle(hwndFocus);
741 recreateCaret (hwndFocusWin32);
742 win32wnd->MsgSetFocus(hwndFocusWin32);
743 }
744 else {
745 //If SetFocus(0) was called, then the window has already received
746 //a WM_KILLFOCUS; don't send another one
747 if(!fIgnoreKeystrokes) {
748 win32wnd->MsgKillFocus(OS2ToWin32Handle(hwndFocus));
749 }
750 else dprintf(("Window has already received a WM_KILLFOCUS (SetFocus(0)); ignore"));
751 }
752 teb->o.odin.fWM_SETFOCUS = FALSE;
753
754 break;
755 }
756
757 //**************************************************************************
758 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
759 //**************************************************************************
760
761 case WM_BUTTON1DOWN:
762 case WM_BUTTON1UP:
763 case WM_BUTTON1DBLCLK:
764 case WM_BUTTON2DOWN:
765 case WM_BUTTON2UP:
766 case WM_BUTTON2DBLCLK:
767 case WM_BUTTON3DOWN:
768 case WM_BUTTON3UP:
769 case WM_BUTTON3DBLCLK:
770 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
771 RELEASE_WNDOBJ(win32wnd);
772 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
773 }
774 if(win32wnd)
775 win32wnd->MsgButton(pWinMsg);
776
777 rc = (MRESULT)TRUE;
778 break;
779
780 case WM_BUTTON2MOTIONSTART:
781 case WM_BUTTON2MOTIONEND:
782 case WM_BUTTON2CLICK:
783 case WM_BUTTON1MOTIONSTART:
784 case WM_BUTTON1MOTIONEND:
785 case WM_BUTTON1CLICK:
786 case WM_BUTTON3MOTIONSTART:
787 case WM_BUTTON3MOTIONEND:
788 case WM_BUTTON3CLICK:
789 rc = (MRESULT)TRUE;
790 break;
791
792 case WM_MOUSEMOVE:
793 {
794 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
795 RELEASE_WNDOBJ(win32wnd);
796 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
797 }
798 if(win32wnd)
799 win32wnd->MsgMouseMove(pWinMsg);
800 break;
801 }
802
803 case WM_CONTROL:
804 goto RunDefWndProc;
805
806 case WM_COMMAND:
807 dprintf(("OS2: WM_COMMAND %x %x %x", hwnd, mp1, mp2));
808 win32wnd->DispatchMsgA(pWinMsg);
809 break;
810
811 case WM_SYSCOMMAND:
812 dprintf(("OS2: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
813 win32wnd->DispatchMsgA(pWinMsg);
814 break;
815
816 case WM_RENDERFMT:
817 case WM_RENDERALLFMTS:
818 case WM_DESTROYCLIPBOARD:
819 case WM_DRAWCLIPBOARD:
820 win32wnd->DispatchMsgA(pWinMsg);
821 break;
822
823 case WM_CHAR_SPECIAL:
824 /* NO BREAK! FALLTHRU CASE! */
825
826 case WM_CHAR:
827 dprintf(("OS2: WM_CHAR %x %x %x, %x %x focus wnd %x", win32wnd->getWindowHandle(), mp1, mp2, pWinMsg->wParam, pWinMsg->lParam, WinQueryFocus(HWND_DESKTOP)));
828 win32wnd->MsgChar(pWinMsg);
829 break;
830
831 case WM_TIMER:
832 dprintf(("OS2: WM_TIMER %x %x time %x", win32wnd->getWindowHandle(), pWinMsg->wParam, GetTickCount()));
833 win32wnd->DispatchMsgA(pWinMsg);
834 goto RunDefWndProc;
835
836 case WM_SETWINDOWPARAMS:
837 {
838 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
839
840 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
841 if(wndParams->fsStatus & WPM_TEXT) {
842 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
843 }
844 goto RunDefWndProc;
845 }
846
847 case WM_QUERYWINDOWPARAMS:
848 {
849 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
850 ULONG textlen;
851 PSZ wintext;
852
853 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
854 {
855 if(wndpars->fsStatus & WPM_TEXT)
856 win32wnd->MsgGetText(wndpars->pszText, wndpars->cchText);
857 if(wndpars->fsStatus & WPM_CCHTEXT)
858 wndpars->cchText = win32wnd->MsgGetTextLength();
859
860 wndpars->fsStatus = 0;
861 wndpars->cbCtlData = 0;
862 wndpars->cbPresParams = 0;
863 rc = (MRESULT)TRUE;
864 break;
865 }
866 goto RunDefWndProc;
867 }
868
869 case WM_PAINT:
870 {
871 RECTL rectl;
872 BOOL rc;
873
874 win32wnd->checkForDirtyUpdateRegion();
875
876 rc = WinQueryUpdateRect(hwnd, &rectl);
877 dprintf(("OS2: WM_PAINT %x (%d,%d) (%d,%d) rc=%d", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop, rc));
878
879 if(rc && win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
880 rectl.yBottom != rectl.yTop) && !IsIconic(win32wnd->GetTopParent()))
881 {
882 win32wnd->DispatchMsgA(pWinMsg);
883 if(WinQueryUpdateRect(hwnd, NULL) == TRUE)
884 {//the application didn't validate the update region; Windows
885 //will only send a WM_PAINT once until another part of the
886 //window is invalidated. Unfortunately PM keeps on sending
887 //WM_PAINT messages until we validate the update region.
888
889 win32wnd->saveAndValidateUpdateRegion();
890 }
891 }
892 else goto RunDefWndProc;
893 break;
894 }
895
896 case WM_ERASEBACKGROUND:
897 {
898 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
899 rc = (MRESULT)FALSE;
900 break;
901 }
902
903 case WM_CALCVALIDRECTS:
904 dprintf(("OS2: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
905 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
906 break;
907
908 case WM_REALIZEPALETTE:
909 {
910 dprintf(("OS2: WM_REALIZEPALETTE %x", win32wnd->getWindowHandle()));
911 win32wnd->DispatchMsgA(pWinMsg);
912 break;
913 }
914
915 case WM_HSCROLL:
916 case WM_VSCROLL:
917 dprintf(("OS2: %s %x %x %x", (msg == WM_HSCROLL) ? "WM_HSCROLL" : "WM_VSCROLL", win32wnd->getWindowHandle(), mp1, mp2));
918 win32wnd->DispatchMsgA(pWinMsg);
919 break;
920
921 case DM_DRAGOVER:
922 {
923 PDRAGINFO pDragInfo = (PDRAGINFO)mp1;
924 PDRAGITEM pDragItem;
925 USHORT sxDrop = SHORT1FROMMP(mp2);
926 USHORT syDrop = SHORT2FROMMP(mp2);
927
928 dprintf(("OS2: DM_DRAGOVER %x (%d,%d)", win32wnd->getWindowHandle(), sxDrop, syDrop));
929
930 if(fDragDropDisabled) {
931 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
932 break;
933 }
934
935 //does this window accept dropped files?
936 if(!DragDropAccept(win32wnd->getWindowHandle())) {
937 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
938 break;
939 }
940
941 if(PMDragValidate(pDragInfo) == FALSE) {
942 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
943 break;
944 }
945 if(win32wnd->isDragDropActive() == FALSE) {
946 ULONG ulBytes, cItems;
947 char *pszFiles;
948
949 pszFiles = PMDragExtractFiles(pDragInfo, &cItems, &ulBytes);
950 if(pszFiles) {
951 POINT point = {sxDrop, syDrop};
952 if(DragDropDragEnter(win32wnd->getWindowHandle(), point, cItems, pszFiles, ulBytes, DROPEFFECT_COPY_W) == FALSE) {
953 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
954 }
955 else {
956 fDragDropActive = TRUE;
957 rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
958 win32wnd->setDragDropActive(TRUE);
959 }
960 free(pszFiles);
961 }
962 else {
963 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
964 }
965 }
966 else {
967 if(DragDropDragOver(win32wnd->getWindowHandle(), DROPEFFECT_COPY_W) == FALSE) {
968 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
969 }
970 else rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
971 }
972 break;
973 }
974
975 case DM_DRAGLEAVE:
976 {
977 dprintf(("OS2: DM_DRAGLEAVE %x", win32wnd->getWindowHandle()));
978
979 if(fDragDropDisabled) {
980 break;
981 }
982
983 fDragDropActive = FALSE;
984
985 //does this window accept dropped files?
986 if(!DragDropAccept(win32wnd->getWindowHandle())) {
987 break;
988 }
989
990 DragDropDragLeave(win32wnd->getWindowHandle());
991 win32wnd->setDragDropActive(FALSE);
992 break;
993 }
994
995 case DM_DROP:
996 {
997 PDRAGINFO pDragInfo = (PDRAGINFO)mp1;
998 PDRAGITEM pDragItem;
999 USHORT sxDrop = SHORT1FROMMP(mp2);
1000 USHORT syDrop = SHORT2FROMMP(mp2);
1001 USHORT usIndicator, usOp;
1002
1003 dprintf(("OS2: DM_DROP %x (%d,%d)", win32wnd->getWindowHandle(), sxDrop, syDrop));
1004
1005 fDragDropActive = FALSE;
1006 rc = (MRFROM2SHORT (DOR_NODROP, 0));
1007
1008 if(fDragDropDisabled) {
1009 rc = (MRFROM2SHORT (DOR_NODROP, 0));
1010 break;
1011 }
1012
1013 //does this window accept dropped files?
1014 if(!DragDropAccept(win32wnd->getWindowHandle())) {
1015 break;
1016 }
1017
1018 ULONG ulBytes, cItems;
1019 char *pszFiles;
1020
1021 pszFiles = PMDragExtractFiles(pDragInfo, &cItems, &ulBytes);
1022 if(pszFiles) {
1023 POINT point = {sxDrop, syDrop};
1024 if(DragDropFiles(win32wnd->getWindowHandle(), point, cItems, pszFiles, ulBytes) == FALSE) {
1025 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
1026 }
1027 else {
1028 rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
1029 win32wnd->setDragDropActive(FALSE);
1030 }
1031 free(pszFiles);
1032 }
1033 else {
1034 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
1035 }
1036 break;
1037 }
1038
1039 case WM_DDE_INITIATE:
1040 case WM_DDE_INITIATEACK:
1041 case WM_DDE_REQUEST:
1042 case WM_DDE_ACK:
1043 case WM_DDE_DATA:
1044 case WM_DDE_ADVISE:
1045 case WM_DDE_UNADVISE:
1046 case WM_DDE_POKE:
1047 case WM_DDE_EXECUTE:
1048 case WM_DDE_TERMINATE:
1049 dprintf(("OS2: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
1050 goto RunDefWndProc;
1051
1052 case WM_INITMENU:
1053 case WM_MENUSELECT:
1054 case WM_MENUEND:
1055 case WM_NEXTMENU:
1056 case WM_SYSCOLORCHANGE:
1057 case WM_SYSVALUECHANGED:
1058 case WM_SETSELECTION:
1059 case WM_PPAINT:
1060 case WM_PSETFOCUS:
1061 case WM_PSYSCOLORCHANGE:
1062 case WM_PSIZE:
1063 case WM_PACTIVATE:
1064 case WM_PCONTROL:
1065 case WM_HELP:
1066 case WM_APPTERMINATENOTIFY:
1067 case WM_PRESPARAMCHANGED:
1068 case WM_DRAWITEM:
1069 case WM_MEASUREITEM:
1070 case WM_CONTROLPOINTER:
1071 case WM_QUERYDLGCODE:
1072 case WM_SUBSTITUTESTRING:
1073 case WM_MATCHMNEMONIC:
1074 case WM_SAVEAPPLICATION:
1075 case WM_SEMANTICEVENT:
1076 default:
1077 dprintf2(("OS2: RunDefWndProc hwnd %x msg %x mp1 %x mp2 %x", hwnd, msg, mp1, mp2));
1078 goto RunDefWndProc;
1079 }
1080 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1081 RestoreOS2TIB();
1082
1083#ifdef DEBUG
1084 dbg_ThreadPopCall();
1085#endif
1086 return (MRESULT)rc;
1087
1088RunDefWndProc:
1089// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
1090 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1091 RestoreOS2TIB();
1092
1093#ifdef DEBUG
1094 dbg_ThreadPopCall();
1095#endif
1096 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
1097} /* End of Win32WindowProc */
1098//******************************************************************************
1099//******************************************************************************
1100MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
1101{
1102 POSTMSG_PACKET *postmsg;
1103 OSLIBPOINT point, ClientPoint;
1104 Win32BaseWindow *win32wnd;
1105 TEB *teb;
1106 MRESULT rc = 0;
1107 MSG winMsg, *pWinMsg;
1108
1109#ifdef DEBUG
1110 dbg_ThreadPushCall("Win32FrameWindowProc");
1111#endif
1112
1113 //Restore our FS selector
1114 SetWin32TIB();
1115
1116 // BEGIN NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
1117 teb = GetThreadTEB();
1118 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
1119
1120 // do some sanity checking here:
1121 // - we need to have a TEB handle
1122 // - unless this is WM_CREATE (the very first message), there has to be
1123 // a USER32 window object for this window handle
1124 if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
1125 dprintf(("PMFRAME: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
1126 goto RunDefFrameWndProc;
1127 }
1128//// if(teb->o.odin.fIgnoreMsgs) {
1129//// goto RunDefWndProc;
1130//// }
1131
1132 // check if the message state counter in the TEB is odd
1133 // This means the message has been sent directly from PM to our message
1134 // handler (so it is the first time we know about this PM message).
1135 // If this is the case, we have to translate it here to a Win32
1136 // message first. The other case is that the message is the result of a
1137 // WinDispatchMsg call and therefore has already been translated.
1138 if((teb->o.odin.msgstate & 1) == 0)
1139 {//message that was sent directly to our window proc handler; translate it here
1140 QMSG qmsg;
1141
1142 qmsg.msg = msg;
1143 qmsg.hwnd = hwnd;
1144 qmsg.mp1 = mp1;
1145 qmsg.mp2 = mp2;
1146 qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
1147 WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
1148 qmsg.reserved = 0;
1149
1150 if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
1151 {//message was not translated
1152 memset(&winMsg, 0, sizeof(MSG));
1153 }
1154 pWinMsg = &winMsg;
1155 }
1156 else {
1157 // message has already been translated before (GetMessage/PeekMessage).
1158 // Use the translated information. Flip the translation flag.
1159 pWinMsg = &teb->o.odin.msg;
1160 teb->o.odin.msgstate++;
1161 }
1162 // END NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
1163
1164 switch( msg )
1165 {
1166 case WM_CREATE:
1167 {
1168 //WM_CREATE handled during client window creation
1169 dprintf(("PMFRAME: WM_CREATE %x", hwnd));
1170 goto RunDefFrameWndProc;
1171 }
1172
1173//hack alert; PM crashes if child calls DestroyWindow for parent/owner in WM_DESTROY
1174// handler; must postpone it, so do it here
1175 case WIN32APP_POSTPONEDESTROY:
1176 OSLibWinDestroyWindow(hwnd);
1177 break;
1178//hack end
1179
1180#ifdef DEBUG
1181 case WM_CLOSE:
1182 {
1183 dprintf(("PMFRAME: WM_CLOSE %x", hwnd));
1184 goto RunDefFrameWndProc;
1185 }
1186#endif
1187
1188 case WM_PAINT:
1189 {
1190 RECTL rectl;
1191
1192 HPS hps = WinBeginPaint(hwnd, NULL, &rectl);
1193 dprintf(("PMFRAME: WM_PAINT %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
1194
1195 if(win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
1196 rectl.yBottom != rectl.yTop))
1197 {
1198 PRECT pClient = win32wnd->getClientRectPtr();
1199 PRECT pWindow = win32wnd->getWindowRect();
1200
1201 if(!(pClient->left == 0 && pClient->top == 0 &&
1202 win32wnd->getClientHeight() == win32wnd->getWindowHeight() &&
1203 win32wnd->getClientWidth() == win32wnd->getWindowWidth()))
1204 {
1205 RECT rectUpdate;
1206
1207 mapOS2ToWin32Rect(win32wnd->getWindowHeight(), (PRECTLOS2)&rectl, &rectUpdate);
1208 win32wnd->MsgNCPaint(&rectUpdate);
1209 }
1210 }
1211 WinEndPaint(hps);
1212 break;
1213 }
1214
1215 case WM_ERASEBACKGROUND:
1216 {
1217 dprintf(("PMFRAME:WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
1218 rc = (MRESULT)FALSE;
1219 break;
1220 }
1221
1222 //**************************************************************************
1223 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
1224 //**************************************************************************
1225
1226 case WM_BUTTON1DOWN:
1227 case WM_BUTTON1UP:
1228 case WM_BUTTON1DBLCLK:
1229 case WM_BUTTON2DOWN:
1230 case WM_BUTTON2UP:
1231 case WM_BUTTON2DBLCLK:
1232 case WM_BUTTON3DOWN:
1233 case WM_BUTTON3UP:
1234 case WM_BUTTON3DBLCLK:
1235 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
1236 RELEASE_WNDOBJ(win32wnd);
1237 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
1238 }
1239 if(win32wnd)
1240 win32wnd->MsgButton(pWinMsg);
1241
1242 rc = (MRESULT)TRUE;
1243 break;
1244
1245 case WM_BUTTON2MOTIONSTART:
1246 case WM_BUTTON2MOTIONEND:
1247 case WM_BUTTON2CLICK:
1248 case WM_BUTTON1MOTIONSTART:
1249 case WM_BUTTON1MOTIONEND:
1250 case WM_BUTTON1CLICK:
1251 case WM_BUTTON3MOTIONSTART:
1252 case WM_BUTTON3MOTIONEND:
1253 case WM_BUTTON3CLICK:
1254 rc = (MRESULT)TRUE;
1255 break;
1256
1257 case WM_MOUSEMOVE:
1258 {
1259 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
1260 RELEASE_WNDOBJ(win32wnd);
1261 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
1262 }
1263 if(win32wnd)
1264 win32wnd->MsgMouseMove(pWinMsg);
1265 break;
1266 }
1267
1268 case WM_CHAR_SPECIAL_CONSOLE_BREAK:
1269 {
1270 //ignore this message. don't forward it to the default PM frame window handler
1271 //as that one sends it to the client. as a result we end up translating
1272 //it twice
1273 break;
1274 }
1275
1276 case WM_ADJUSTWINDOWPOS:
1277 {
1278 PSWP pswp = (PSWP)mp1;
1279 SWP swpOld;
1280 WINDOWPOS wp,wpOld;
1281 ULONG ulFlags;
1282 ULONG ret = 0;
1283 HWND hParent = NULLHANDLE, hwndAfter;
1284
1285 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));
1286
1287 ulFlags = pswp->fl;
1288
1289 if(win32wnd->IsParentChanging()) {
1290 rc = 0;
1291 break;
1292 }
1293
1294 //@@PF all commands from minimized window viewer or from Ctrl-Esc
1295 //are 'pure' and should be handled only by DeFrameProc - this is weird
1296 //but without them we will not have results. Pure = plain flag of restore/minimize/maximize
1297 if((pswp->fl == SWP_MINIMIZE) || (pswp->fl & SWP_RESTORE)) {
1298 // note the purity of SWP no other SWP_FLAGS allowed
1299 goto RunDefFrameWndProc;
1300 }
1301
1302 if(pswp->fl & SWP_NOADJUST) {
1303 //ignore weird messages (TODO: why are they sent?)
1304 dprintf(("WARNING: WM_ADJUSTWINDOWPOS with SWP_NOADJUST flag!!"));
1305 break;
1306 }
1307 if ((pswp->fl == SWP_FOCUSACTIVATE) || (pswp->fl == SWP_FOCUSDEACTIVATE))
1308 {
1309 dprintf(("Pure focus flags are not sent to win32 windows"));
1310 goto RunDefFrameWndProc;
1311 }
1312
1313 //CB: show dialog in front of owner
1314 if (win32wnd->IsModalDialogOwner())
1315 {
1316 dprintf(("win32wnd->IsModalDialogOwner %x", win32wnd->getWindowHandle()));
1317 pswp->fl |= SWP_ZORDER;
1318 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
1319 if (pswp->fl & SWP_ACTIVATE)
1320 {
1321 pswp->fl &= ~SWP_ACTIVATE;
1322 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
1323 }
1324 }
1325
1326 if(!win32wnd->CanReceiveSizeMsgs())
1327 break;
1328
1329 WinQueryWindowPos(hwnd, &swpOld);
1330 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
1331 if (win32wnd->isChild()) {
1332 if(win32wnd->getParent()) {
1333 hParent = win32wnd->getParent()->getOS2WindowHandle();
1334 }
1335 else goto RunDefFrameWndProc;
1336 }
1337 }
1338 hwndAfter = pswp->hwndInsertBehind;
1339 if(win32wnd->getParent()) {
1340 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(), hwnd);
1341 }
1342 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1343
1344 wp.hwnd = win32wnd->getWindowHandle();
1345 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1346 {
1347 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1348 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
1349 if(wndAfter) {
1350 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1351 RELEASE_WNDOBJ(wndAfter);
1352 }
1353 else wp.hwndInsertAfter = HWND_TOP_W;
1354 }
1355
1356 wpOld = wp;
1357 win32wnd->MsgPosChanging((LPARAM)&wp);
1358
1359 if(win32wnd->getOldStyle() != win32wnd->getStyle())
1360 {
1361 OSLibSetWindowStyle(win32wnd->getOS2FrameWindowHandle(), win32wnd->getOS2WindowHandle(), win32wnd->getStyle(), win32wnd->getExStyle(), win32wnd->getStyle());
1362 if(fOS2Look) {
1363 DWORD dwOldStyle = win32wnd->getOldStyle();
1364 DWORD dwStyle = win32wnd->getStyle();
1365
1366 win32wnd->setOldStyle(dwStyle);
1367 if((dwOldStyle & WS_MINIMIZE_W) && !(dwStyle & WS_MINIMIZE_W)) {
1368 //SC_RESTORE -> SC_MINIMIZE
1369 dprintf(("%x -> SC_RESTORE -> SC_MINIMIZE", win32wnd->getWindowHandle()));
1370 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_RESTORE, SC_MINIMIZE, hbmFrameMenu[PMMENU_MINBUTTON]);
1371 if(dwStyle & WS_MAXIMIZE_W) {
1372 //SC_MAXIMIZE -> SC_RESTORE
1373 dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE (1)", win32wnd->getWindowHandle()));
1374 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[PMMENU_RESTOREBUTTON]);
1375 }
1376 }
1377 else
1378 if((dwOldStyle & WS_MAXIMIZE_W) && !(dwStyle & WS_MAXIMIZE_W)) {
1379 //SC_RESTORE -> SC_MAXIMIZE
1380 dprintf(("%x -> SC_RESTORE -> SC_MAXIMIZE", win32wnd->getWindowHandle()));
1381 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_RESTORE, SC_MAXIMIZE, hbmFrameMenu[PMMENU_MAXBUTTON]);
1382 }
1383 else
1384 if(!(dwOldStyle & WS_MINIMIZE_W) && (dwStyle & WS_MINIMIZE_W)) {
1385 //SC_MINIMIZE -> SC_RESTORE
1386 dprintf(("%x -> SC_MINIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
1387 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_MINIMIZE, SC_RESTORE, hbmFrameMenu[PMMENU_RESTOREBUTTON]);
1388 }
1389 else
1390 if(!(dwOldStyle & WS_MAXIMIZE_W) && (dwStyle & WS_MAXIMIZE_W)) {
1391 //SC_MAXIMIZE -> SC_RESTORE
1392 dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE (2)", win32wnd->getWindowHandle()));
1393 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[PMMENU_RESTOREBUTTON]);
1394 }
1395 }
1396 }
1397
1398 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
1399 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
1400 {
1401 ULONG flags = pswp->fl; //make a backup copy; OSLibMapWINDOWPOStoSWP will modify it
1402
1403 dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
1404 dprintf(("%x (%s) (%d,%d), (%d,%d)", pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy));
1405
1406 if(win32wnd->getParent()) {
1407 OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getClientHeight(),
1408 hwnd);
1409 }
1410 else OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1411
1412 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
1413
1414 //OSLibMapWINDOWPOStoSWP can add flags, but we must not let it remove flags!
1415 if(pswp->fl & SWP_SIZE)
1416 flags |= SWP_SIZE;
1417
1418 if(pswp->fl & SWP_MOVE)
1419 flags |= SWP_MOVE;
1420
1421 pswp->fl = flags; //restore flags
1422
1423 pswp->fl |= SWP_NOADJUST;
1424 pswp->hwndInsertBehind = hwndAfter;
1425 pswp->hwnd = hwnd;
1426
1427 ret = 0xf;
1428 }
1429adjustend:
1430 //The next part needs to be done for top-level windows only
1431 if(!((win32wnd->getStyle() & (WS_POPUP_W|WS_CHILD_W)) == WS_CHILD_W))
1432 {
1433 //Setting these flags is necessary to avoid activation/focus problems
1434 if(ulFlags & SWP_DEACTIVATE) {
1435 ret |= AWP_DEACTIVATE;
1436 }
1437 if(ulFlags & SWP_ACTIVATE)
1438 {
1439 if(ulFlags & SWP_ZORDER) {
1440 dprintf(("Set FF_NOACTIVATESWP"));
1441 ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
1442 WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags | FF_NOACTIVATESWP);
1443 }
1444
1445 if(!(ulFlags & SWP_SHOW))
1446 {
1447 ret |= AWP_ACTIVATE;
1448 }
1449 else
1450 {
1451 FrameSetFocus(hwnd);
1452 }
1453 }
1454 }
1455 else {
1456 if(ulFlags & (SWP_ACTIVATE|SWP_FOCUSACTIVATE))
1457 {
1458 win32wnd->MsgChildActivate(TRUE);
1459 if(fOS2Look) {
1460 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1461 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, (MPARAM)1, 0);
1462 }
1463 }
1464 else
1465 if(ulFlags & (SWP_DEACTIVATE|SWP_FOCUSDEACTIVATE))
1466 {
1467 win32wnd->MsgChildActivate(FALSE);
1468 if(fOS2Look) {
1469 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1470 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, 0, 0);
1471 }
1472 }
1473 }
1474#ifdef DEBUG
1475 dprintf(("WM_ADJUSTWINDOWPOS ret %x flags %x", ret, WinQueryWindowUShort(hwnd, QWS_FLAGS)));
1476 if(ret == 0x0f) {
1477 dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
1478 dprintf(("%x (%s) (%d,%d), (%d,%d)", pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy));
1479 }
1480#endif
1481 rc = (MRESULT)ret;
1482 break;
1483 }
1484
1485 case WM_WINDOWPOSCHANGED:
1486 {
1487 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
1488 SWP swpOld = *(pswp + 1);
1489 WINDOWPOS wp;
1490 ULONG flAfp = (ULONG)mp2;
1491 HWND hParent = NULLHANDLE;
1492 RECTL rect;
1493
1494 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)));
1495 if(win32wnd->IsParentChanging()) {
1496 goto PosChangedEnd;
1497 }
1498
1499 //SvL: When a window is made visible, then we don't receive a
1500 // WM_VRNENABLED message (for some weird reason)
1501 if(pswp->fl & SWP_SHOW) {
1502 win32wnd->callVisibleRgnNotifyProc(TRUE);
1503 }
1504 else
1505 if(pswp->fl & SWP_HIDE) {
1506 win32wnd->callVisibleRgnNotifyProc(FALSE);
1507 }
1508
1509 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
1510 {
1511 if(pswp->fl & SWP_RESTORE && win32wnd->getStyle() & WS_MINIMIZE_W) {
1512 dprintf(("Restoring minimized window %x", win32wnd->getWindowHandle()));
1513 win32wnd->ShowWindow(SW_RESTORE_W);
1514 }
1515 if(pswp->fl & SWP_SHOW) {
1516 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
1517 }
1518 else
1519 if(pswp->fl & SWP_HIDE) {
1520 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
1521 }
1522 //MUST call the old frame window proc!
1523 goto RunDefFrameWndProc;
1524 }
1525
1526 if(pswp->fl & (SWP_MOVE | SWP_SIZE))
1527 {
1528 if(win32wnd->isChild())
1529 {
1530 if(win32wnd->getParent()) {
1531 hParent = win32wnd->getParent()->getOS2WindowHandle();
1532 }
1533 else goto PosChangedEnd; //parent has just been destroyed
1534 }
1535 }
1536
1537
1538 if(win32wnd->getParent()) {
1539 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1540 hwnd);
1541 }
1542 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1543
1544 wp.hwnd = win32wnd->getWindowHandle();
1545 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1546 {
1547 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1548 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
1549 if(wndAfter) {
1550 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1551 RELEASE_WNDOBJ(wndAfter);
1552 }
1553 else wp.hwndInsertAfter = HWND_TOP_W;
1554 }
1555
1556 if(pswp->fl & SWP_SHOW) {
1557 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
1558 }
1559 else
1560 if(pswp->fl & SWP_HIDE) {
1561 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
1562 }
1563
1564 if(flAfp & AWP_ACTIVATE)
1565 {
1566 FrameSetFocus(hwnd);
1567 }
1568
1569#ifndef USE_CALCVALIDRECT
1570 if((pswp->fl & (SWP_MOVE | SWP_SIZE)))
1571 {
1572 //CB: todo: use result for WM_CALCVALIDRECTS
1573 //Get old client rectangle (for invalidation of frame window parts later on)
1574 //Use new window height to calculate the client area
1575 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
1576
1577 //Note: Also updates the new window rectangle
1578 win32wnd->MsgFormatFrame(&wp);
1579
1580 if(win32wnd->isOwnDC()) {
1581 setPageXForm(win32wnd, (pDCData)GpiQueryDCData(win32wnd->getOwnDC()));
1582 }
1583
1584 if(win32wnd->CanReceiveSizeMsgs())
1585 win32wnd->MsgPosChanged((LPARAM)&wp);
1586
1587 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
1588 {
1589 //redraw the frame (to prevent unnecessary client updates)
1590 BOOL redrawAll = FALSE;
1591
1592 dprintf2(("WM_WINDOWPOSCHANGED: redraw frame"));
1593 if (win32wnd->getWindowClass())
1594 {
1595 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
1596
1597 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
1598 redrawAll = TRUE;
1599 else
1600 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
1601 redrawAll = TRUE;
1602 }
1603 else redrawAll = TRUE;
1604
1605 if(win32wnd->IsMixMaxStateChanging()) {
1606 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1607 redrawAll = TRUE;
1608 }
1609
1610 if (redrawAll)
1611 {
1612 //CB: redraw all children for now
1613 // -> problems with update region if we don't do it
1614 // todo: rewrite whole handling
1615 dprintf(("PMFRAME: WM_WINDOWPOSCHANGED invalidate all"));
1616 WinInvalidateRect(hwnd,NULL,TRUE);
1617 }
1618 else
1619 {
1620 HPS hps = WinGetPS(hwnd);
1621 RECTL frame,client,arcl[4];
1622
1623 WinQueryWindowRect(hwnd,&frame);
1624
1625 //top
1626 arcl[0].xLeft = 0;
1627 arcl[0].xRight = frame.xRight;
1628 arcl[0].yBottom = rect.yTop;
1629 arcl[0].yTop = frame.yTop;
1630 //right
1631 arcl[1].xLeft = rect.xRight;
1632 arcl[1].xRight = frame.xRight;
1633 arcl[1].yBottom = 0;
1634 arcl[1].yTop = frame.yTop;
1635 //left
1636 arcl[2].xLeft = 0;
1637 arcl[2].xRight = rect.xLeft;
1638 arcl[2].yBottom = 0;
1639 arcl[2].yTop = frame.yTop;
1640 //bottom
1641 arcl[3].xLeft = 0;
1642 arcl[3].xRight = frame.xRight;
1643 arcl[3].yBottom = 0;
1644 arcl[3].yTop = rect.yBottom;
1645
1646 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
1647
1648 WinInvalidateRegion(hwnd,hrgn,FALSE);
1649 GpiDestroyRegion(hps,hrgn);
1650 WinReleasePS(hps);
1651 }
1652 }
1653 }
1654 else
1655 {
1656#endif //USE_CALCVALIDRECT
1657 if(win32wnd->CanReceiveSizeMsgs())
1658 win32wnd->MsgPosChanged((LPARAM)&wp);
1659#ifndef USE_CALCVALIDRECT
1660 }
1661#endif
1662
1663PosChangedEnd:
1664 rc = (MRESULT)FALSE;
1665 break;
1666 }
1667
1668 case WM_CALCVALIDRECTS:
1669#ifdef USE_CALCVALIDRECT
1670 {
1671 PRECTL oldRect = (PRECTL)mp1, newRect = oldRect+1;
1672 PSWP pswp = (PSWP)mp2;
1673 SWP swpOld;
1674 WINDOWPOS wp;
1675 RECTL newClientRect, oldClientRect;
1676 ULONG nccalcret;
1677// UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
1678 UINT res = 0;
1679
1680 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1681
1682 //Get old position info
1683 WinQueryWindowPos(hwnd, &swpOld);
1684
1685 if(win32wnd->getParent()) {
1686 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1687 win32wnd->getParent()->getClientRectPtr()->left,
1688 win32wnd->getParent()->getClientRectPtr()->top,
1689 hwnd);
1690 }
1691 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
1692
1693 wp.hwnd = win32wnd->getWindowHandle();
1694 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1695 {
1696 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1697 if(wndAfter) {
1698 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1699 RELEASE_WNDOBJ(wndAfter);
1700 }
1701 else wp.hwndInsertAfter = HWND_TOP_W;
1702 }
1703
1704 //Get old client rectangle
1705 mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
1706
1707 //Note: Also updates the new window rectangle
1708 nccalcret = win32wnd->MsgFormatFrame(&wp);
1709
1710 //Get new client rectangle
1711 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
1712
1713 if(nccalcret == 0) {
1714 res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
1715 }
1716 else {
1717 if(nccalcret & WVR_ALIGNTOP_W) {
1718 res |= CVR_ALIGNTOP;
1719 }
1720 else
1721 if(nccalcret & WVR_ALIGNBOTTOM_W) {
1722 res |= CVR_ALIGNBOTTOM;
1723 }
1724
1725 if(nccalcret & WVR_ALIGNLEFT_W) {
1726 res |= CVR_ALIGNLEFT;
1727 }
1728 else
1729 if(nccalcret & WVR_ALIGNRIGHT_W) {
1730 res |= CVR_ALIGNRIGHT;
1731 }
1732
1733 if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
1734 res |= CVR_REDRAW;
1735 }
1736 else
1737 if(nccalcret & WVR_VALIDRECTS_W) {
1738 //TODO:
1739 //res = 0;
1740 }
1741 }
1742 if(win32wnd->IsMixMaxStateChanging()) {
1743 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1744 res |= CVR_REDRAW;
1745 }
1746 if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
1747 oldRect->xRight -= oldClientRect.xLeft;
1748 oldRect->yBottom += oldClientRect.yBottom;
1749 newRect->xRight -= newClientRect.xLeft;
1750 newRect->yBottom += newClientRect.yBottom;
1751 }
1752 rc = res;
1753 break;
1754 }
1755#else
1756 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1757 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
1758 break;
1759#endif
1760
1761 case WM_CALCFRAMERECT:
1762 dprintf(("PMFRAME:WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
1763 rc = (MRESULT)TRUE;
1764 break;
1765
1766 case WM_QUERYCTLTYPE:
1767 // This is a frame window
1768 dprintf(("PMFRAME:WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
1769 rc = (MRESULT)CCT_FRAME;
1770 break;
1771
1772#ifdef DEBUG
1773 case WM_QUERYFOCUSCHAIN:
1774 dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x (%s) parent %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), DbgPrintQFCFlags(SHORT1FROMMP(mp1)), (mp2) ? OS2ToWin32Handle((DWORD)mp2) : 0));
1775
1776 RestoreOS2TIB();
1777 rc = pfnFrameWndProc(hwnd, msg, mp1, mp2);
1778 SetWin32TIB();
1779 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));
1780 break;
1781// goto RunDefFrameWndProc;
1782#endif
1783
1784 case WM_FOCUSCHANGE:
1785 {
1786 HWND hwndFocus = (HWND)mp1;
1787 HWND hwndLoseFocus, hwndGainFocus;
1788 USHORT usSetFocus = SHORT1FROMMP(mp2);
1789 USHORT fsFocusChange = SHORT2FROMMP(mp2);
1790
1791 //Save window that gains focus so we can determine which
1792 //process we lose activation to
1793 hwndFocusChange = (HWND)mp1;
1794
1795 dprintf(("PMFRAME:WM_FOCUSCHANGE %x %x (%x) %x %x", win32wnd->getWindowHandle(), OS2ToWin32Handle(hwndFocus), hwndFocus, usSetFocus, fsFocusChange));
1796 goto RunDefFrameWndProc;
1797 }
1798
1799#ifdef DEBUG
1800 case WM_SETFOCUS:
1801 {
1802 dprintf(("PMFRAME: WM_SETFOCUS %x %x %d -> %x", win32wnd->getWindowHandle(), hwnd, mp2, mp1));
1803 goto RunDefFrameWndProc;
1804 }
1805#endif
1806
1807 case WM_ACTIVATE:
1808 {
1809 HWND hwndTitle;
1810 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
1811
1812 dprintf(("PMFRAME: WM_ACTIVATE %x %x %x", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle((DWORD)mp2)));
1813 if (win32wnd->IsWindowCreated())
1814 {
1815 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1816 if(fOS2Look) {
1817 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1818 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, mp1, 0);
1819 }
1820 if(SHORT1FROMMP(mp1) == 0) {
1821 //deactivate
1822 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
1823 }
1824 PID pidThis, pidPartner, pidTemp;
1825 TID tidPartner;
1826 HENUM henum;
1827 HWND hwndEnum;
1828
1829 WinQueryWindowProcess(hwnd, &pidThis, NULL);
1830 WinQueryWindowProcess(hwndFocusChange, &pidPartner, &tidPartner);
1831
1832 if(pidThis != pidPartner) {
1833 //Gain or lose activation to window in other process
1834 //must send WM_ACTIVATEAPP to top-level windows
1835
1836 //Iterate over all child windows of the desktop
1837 henum = WinBeginEnumWindows(HWND_DESKTOP);
1838
1839 while(hwndEnum = WinGetNextWindow(henum))
1840 {
1841 WinQueryWindowProcess(hwndEnum, &pidTemp, NULL);
1842 if(pidTemp == pidThis)
1843 {
1844 SendMessageA(OS2ToWin32Handle(hwndEnum), WM_ACTIVATEAPP_W, (WPARAM)SHORT1FROMMP(mp1), (LPARAM)tidPartner);
1845 }
1846 }
1847 WinEndEnumWindows(henum);
1848 }
1849 if(SHORT1FROMMP(mp1)) {
1850 //activate
1851 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
1852 }
1853
1854 //CB: show owner behind the dialog
1855 if (win32wnd->IsModalDialog())
1856 {
1857 if(win32wnd->getOwner()) {
1858 Win32BaseWindow *topOwner = Win32BaseWindow::GetWindowFromHandle(win32wnd->getOwner()->GetTopParent());
1859
1860 if (topOwner) {
1861 WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
1862 RELEASE_WNDOBJ(topOwner);
1863 }
1864 }
1865 }
1866 }
1867 else
1868 {
1869 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1870 }
1871 rc = 0;
1872 break;
1873 }
1874
1875 case WM_ENABLE:
1876 dprintf(("PMFRAME: WM_ENABLE %x", hwnd));
1877 win32wnd->MsgEnable(SHORT1FROMMP(mp1));
1878 break;
1879
1880 case WM_SHOW:
1881 dprintf(("PMFRAME: WM_SHOW %x %d", hwnd, mp1));
1882 //show client window
1883 WinShowWindow(win32wnd->getOS2WindowHandle(), (BOOL)mp1);
1884 break;
1885
1886 case WM_QUERYTRACKINFO:
1887 {
1888 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
1889
1890 dprintf(("PMFRAME:WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
1891 trackInfo->cxBorder = 4;
1892 trackInfo->cyBorder = 4;
1893 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
1894 rc = (MRESULT)TRUE;
1895 break;
1896 }
1897
1898 case WM_QUERYBORDERSIZE:
1899 {
1900 PWPOINT size = (PWPOINT)mp1;
1901
1902 dprintf(("PMFRAME:WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
1903
1904 size->x = 0;
1905 size->y = 0;
1906 rc = (MRESULT)TRUE;
1907 break;
1908 }
1909
1910#ifdef DEBUG
1911 case WM_QUERYFRAMEINFO:
1912 dprintf(("PMFRAME:WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
1913 goto RunDefFrameWndProc;
1914#endif
1915
1916 case WM_FORMATFRAME:
1917 dprintf(("PMFRAME:WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
1918 break;
1919
1920 case WM_ADJUSTFRAMEPOS:
1921 {
1922 PSWP pswp = (PSWP)mp1;
1923
1924 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));
1925 //hack alert: the PM frame control changes the z-order of a child window
1926 // if it receives focus after a window has been destroyed
1927 // We can't let this happen as this messes up assumptions
1928 // elsewhere (e.g. GetNextDlgGroupItem)
1929 // By returning 0 here, we prevent the default frame handler
1930 // from messing things up. (one example is a group of radio buttons)
1931 //NOTE: We really need to get rid of frame & client windows for each
1932 // win32 window
1933 if(pswp->fl == SWP_FOCUSACTIVATE && win32wnd->isChild()) {
1934 rc = 0;
1935 break;
1936 }
1937 //hack alert: as we return zero as border size (check handler) we need
1938 //to do adjustments here as well or PM will calculate it for us and
1939 //result will be illegal. Btw we do not honour PM border size settings
1940 //and never will. I was unable to figure out why only X coordinate
1941 //is being broken but not Y as well.
1942
1943 if ((pswp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1944 {
1945 RECT rect;
1946 rect.left = rect.top = rect.right = rect.bottom = 0;
1947 win32wnd->AdjustMaximizedRect(&rect);
1948
1949 pswp->x += rect.left;
1950 }
1951 goto RunDefFrameWndProc;
1952 }
1953
1954#ifdef DEBUG
1955 case WM_OWNERPOSCHANGE:
1956 {
1957 PSWP pswp = (PSWP)mp1;
1958
1959 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));
1960 goto RunDefFrameWndProc;
1961 }
1962#endif
1963
1964 case WM_MINMAXFRAME:
1965 {
1966 PSWP swp = (PSWP)mp1;
1967
1968 if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
1969
1970 dprintf(("PMFRAME:WM_MINMAXFRAME %x",hwnd));
1971 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1972 {
1973 RECT rect;
1974 rect.left = rect.top = rect.right = rect.bottom = 0;
1975 win32wnd->AdjustMaximizedRect(&rect);
1976
1977 swp->x += rect.left;
1978 swp->cx += rect.right-rect.left;
1979 swp->y -= rect.bottom;
1980 swp->cy += rect.bottom-rect.top;
1981
1982 win32wnd->ShowWindow(SW_RESTORE_W);
1983 }
1984 else
1985 if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
1986 {
1987 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
1988 }
1989 else
1990 if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
1991 {
1992 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
1993 }
1994 goto RunDefWndProc;
1995 }
1996
1997#ifdef DEBUG
1998 case WM_UPDATEFRAME:
1999 dprintf(("PMFRAME:WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
2000 goto RunDefFrameWndProc;
2001#endif
2002
2003 case WM_TRACKFRAME:
2004 dprintf(("PMFRAME: WM_TRACKFRAME %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
2005 if(fOS2Look) {//sent by titlebar control
2006 Frame_SysCommandSizeMove(win32wnd, SC_MOVE_W+HTCAPTION_W);
2007 }
2008 rc = 0;
2009 break;
2010
2011 case WM_SYSCOMMAND:
2012 dprintf(("PMFRAME: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
2013 if (fOS2Look == OS2_APPEARANCE_SYSMENU && mp1 == (MPARAM)OSSC_SYSMENU)
2014 goto RunDefFrameWndProc;
2015
2016 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
2017 RELEASE_WNDOBJ(win32wnd);
2018 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
2019 }
2020 if(win32wnd)
2021 win32wnd->DispatchMsgA(pWinMsg);
2022 break;
2023
2024#ifdef DEBUG
2025 case WM_DDE_INITIATE:
2026 case WM_DDE_INITIATEACK:
2027 case WM_DDE_REQUEST:
2028 case WM_DDE_ACK:
2029 case WM_DDE_DATA:
2030 case WM_DDE_ADVISE:
2031 case WM_DDE_UNADVISE:
2032 case WM_DDE_POKE:
2033 case WM_DDE_EXECUTE:
2034 case WM_DDE_TERMINATE:
2035 dprintf(("PMFRAME: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
2036 break;
2037#endif
2038
2039 default:
2040 goto RunDefFrameWndProc;
2041 }
2042 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2043 RestoreOS2TIB();
2044
2045#ifdef DEBUG
2046 dbg_ThreadPopCall();
2047#endif
2048 return (MRESULT)rc;
2049
2050RunDefFrameWndProc:
2051 dprintf2(("RunDefFrameWndProc"));
2052 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2053 RestoreOS2TIB();
2054
2055#ifdef DEBUG
2056 dbg_ThreadPopCall();
2057#endif
2058 return pfnFrameWndProc(hwnd, msg, mp1, mp2);
2059
2060RunDefWndProc:
2061 dprintf2(("RunDefWndProc"));
2062 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2063 RestoreOS2TIB();
2064 //calling WinDefWindowProc here breaks Opera hotlist window (WM_ADJUSTWINDOWPOS)
2065// return pfnFrameWndProc(hwnd, msg, mp1, mp2);
2066
2067#ifdef DEBUG
2068 dbg_ThreadPopCall();
2069#endif
2070 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
2071}
2072//******************************************************************************
2073//******************************************************************************
2074MRESULT EXPENTRY Win32FakeWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
2075{
2076 PFNWP pfnOldWindowProc;
2077 Win32BaseWindow *win32wnd, *win32wndchild;
2078 TEB *teb;
2079 MRESULT rc = 0;
2080
2081 //Restore our FS selector
2082 SetWin32TIB();
2083
2084 //We can't query the window object directly from this window as it's not the
2085 //real thing. There should be a genuine win32 child window which we can use.
2086 HWND hwndChild = WinQueryWindow(hwnd, QW_TOP);
2087
2088 win32wndchild = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwndChild);
2089 if(win32wndchild == NULL) {
2090 DebugInt3();
2091 goto RunDefWndProc;
2092 }
2093 //now get the parent window object
2094 win32wnd = Win32BaseWindow::GetWindowFromHandle(GetParent(win32wndchild->getWindowHandle()));
2095 if(win32wndchild) RELEASE_WNDOBJ(win32wndchild);
2096
2097 if(win32wnd == NULL) {
2098 DebugInt3();
2099 goto RunDefWndProc;
2100 }
2101
2102 pfnOldWindowProc = (PFNWP)win32wnd->getOldPMWindowProc();
2103 if(pfnOldWindowProc == NULL) {
2104 DebugInt3();
2105 goto RunDefWndProc;
2106 }
2107
2108 rc = pfnOldWindowProc(hwnd, msg, mp1, mp2);
2109 switch(msg) {
2110 case WM_WINDOWPOSCHANGED:
2111 {
2112 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
2113 SWP swpOld = *(pswp + 1);
2114 WINDOWPOS wp;
2115
2116 if(win32wnd->getParent()) {
2117 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
2118 hwnd);
2119 }
2120 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
2121
2122 win32wnd->SetWindowPos(wp.hwndInsertAfter, wp.x, wp.y, wp.cx, wp.cy, wp.flags);
2123 break;
2124 }
2125
2126 }
2127 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2128 RestoreOS2TIB();
2129 return rc;
2130
2131RunDefWndProc:
2132 RestoreOS2TIB();
2133 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
2134}
2135//******************************************************************************
2136// PMWinSubclassFakeWindow
2137//
2138// Subclass a fake window (converted PM window)
2139//
2140// Parameters
2141//
2142// HWND hwndOS2 - PM handle of fake window
2143//
2144// Returns
2145// NULL - Failure
2146// else - Old PM window procedure
2147//
2148//******************************************************************************
2149PVOID PMWinSubclassFakeWindow(HWND hwndOS2)
2150{
2151 return WinSubclassWindow(hwndOS2, Win32FakeWindowProc);
2152}
2153//******************************************************************************
2154//******************************************************************************
2155void FrameSetFocus(HWND hwnd)
2156{
2157 HWND hwndFocusSave = WinQueryWindowULong(hwnd, QWL_HWNDFOCUSSAVE);
2158 if(!WinIsWindow(hab, hwndFocusSave)) {
2159 hwndFocusSave = WinWindowFromID(hwnd, FID_CLIENT);
2160 WinSetWindowULong(hwnd, QWL_HWNDFOCUSSAVE, hwndFocusSave);
2161 }
2162 dprintf(("FrameSetFocus: hwndFocusSave %x %x", OS2ToWin32Handle(hwndFocusSave), hwndFocusSave));
2163 WinSetFocus(HWND_DESKTOP, hwndFocusSave);
2164
2165 ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
2166 ulFrameFlags &= ~FF_NOACTIVATESWP;
2167 WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags);
2168}
2169//******************************************************************************
2170//******************************************************************************
2171void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG idNew,
2172 HBITMAP hbmNew)
2173{
2174 MENUITEM mi;
2175
2176 if (!hwndMenu)
2177 return;
2178
2179 WinEnableWindowUpdate(hwndMenu, FALSE);
2180
2181 if (WinSendMsg(hwndMenu, MM_QUERYITEM, MPFROM2SHORT(idOld, TRUE), MPFROMP(&mi)))
2182 {
2183 WinSendMsg(hwndMenu, MM_REMOVEITEM, (MPARAM)idOld, 0);
2184 mi.afStyle = MIS_BITMAP | MIS_SYSCOMMAND;
2185 mi.afAttribute = 0;
2186 mi.hwndSubMenu = 0;
2187 mi.id = idNew;
2188 mi.hItem = (ULONG)hbmNew;
2189 WinSendMsg(hwndMenu, MM_INSERTITEM, (MPARAM)&mi, 0);
2190 }
2191 else
2192 dprintf(("WARNING: FrameReplaceMenuItem control %x not found",idOld));
2193
2194 WinEnableWindowUpdate(hwndMenu, TRUE);
2195
2196 WinInvalidateRect(hwndMenu, NULL, TRUE);
2197}
2198//******************************************************************************
2199//******************************************************************************
2200static char *PMDragExtractFiles(PDRAGINFO pDragInfo, ULONG *pcItems, ULONG *pulBytes)
2201{
2202 PDRAGITEM pDragItem;
2203 int i, cItems;
2204 BOOL ret;
2205 char szFileName[CCHMAXPATH];
2206 char szContainerName[CCHMAXPATH];
2207 ULONG ulBytes;
2208 char *pszCurFile = NULL;
2209
2210 /* Get access to the DRAGINFO data structure */
2211 if(!DrgAccessDraginfo(pDragInfo)) {
2212 return NULL;
2213 }
2214
2215 cItems = DrgQueryDragitemCount(pDragInfo);
2216
2217 //computer memory required to hold all filenames
2218 int bufsize = 0;
2219 for (i = 0; i < cItems; i++) {
2220 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
2221
2222 bufsize += DrgQueryStrNameLen(pDragItem->hstrContainerName) + DrgQueryStrNameLen(pDragItem->hstrSourceName);
2223 bufsize++; //0 terminator
2224 bufsize++; //+ potential missing backslash
2225 }
2226 bufsize++; //extra 0 terminator
2227 char *pszFiles = (char *)malloc(bufsize);
2228 if(pszFiles == NULL) {
2229 dprintf(("Out of memory!!"));
2230 DebugInt3();
2231 goto failure;
2232 }
2233 memset(pszFiles, 0, bufsize);
2234
2235 pszCurFile = pszFiles;
2236
2237 //copy all filenames
2238 for (i = 0; i < cItems; i++) {
2239 char *pszTemp = pszCurFile;
2240
2241 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
2242
2243 ulBytes = DrgQueryStrNameLen(pDragItem->hstrContainerName);
2244 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
2245 ulBytes, pszCurFile);
2246 if(pszCurFile[ulBytes-1] != '\\') {
2247 pszCurFile[ulBytes] = '\\';
2248 pszCurFile++;
2249 }
2250 pszCurFile += ulBytes;
2251
2252 ulBytes = DrgQueryStrNameLen(pDragItem->hstrSourceName);
2253 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
2254 ulBytes+1, pszCurFile);
2255 pszCurFile += ulBytes + 1; //+ terminator
2256
2257 dprintf(("dropped file %s", pszTemp));
2258 }
2259
2260 /* Release the draginfo data structure */
2261 DrgFreeDraginfo(pDragInfo);
2262
2263 *pulBytes = bufsize;
2264 *pcItems = cItems;
2265
2266 return pszFiles;
2267
2268failure:
2269 /* Release the draginfo data structure */
2270 DrgFreeDraginfo(pDragInfo);
2271 if(pszFiles) {
2272 free(pszFiles);
2273 }
2274 return NULL;
2275}
2276//******************************************************************************
2277//******************************************************************************
2278static BOOL PMDragValidate(PDRAGINFO pDragInfo)
2279{
2280 PDRAGITEM pDragItem;
2281 ULONG ulBytes;
2282 int i, cItems;
2283 BOOL ret;
2284 char szFileName[CCHMAXPATH];
2285 char szContainerName[CCHMAXPATH];
2286 USHORT usOp = DO_MOVE;
2287
2288 /* Get access to the DRAGINFO data structure */
2289 if(!DrgAccessDraginfo(pDragInfo)) {
2290 return FALSE;
2291 }
2292
2293 /* Can we accept this drop? */
2294 switch (pDragInfo->usOperation) {
2295 /* Return DOR_NODROPOP if current operation */
2296 /* is link or unknown */
2297 case DO_LINK:
2298 case DO_COPY:
2299 case DO_UNKNOWN:
2300 goto failure;
2301
2302 /* Our default operation is Move */
2303 case DO_MOVE:
2304 case DO_DEFAULT:
2305 pDragItem = DrgQueryDragitemPtr(pDragInfo, 0);
2306 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
2307 sizeof(szContainerName),
2308 szContainerName);
2309 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
2310 sizeof(szFileName),
2311 szFileName);
2312 if (!ulBytes) {
2313 goto failure;
2314 }
2315
2316 dprintf(("dropped file %s%s", szContainerName, szFileName));
2317 break;
2318 }
2319
2320 cItems = DrgQueryDragitemCount(pDragInfo);
2321
2322 /* Now, we need to look at each item in turn */
2323 for (i = 0; i < cItems; i++) {
2324 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
2325
2326 /* Make sure we can move for a Move request */
2327 if (!((pDragItem->fsSupportedOps & DO_MOVEABLE) &&
2328 (usOp == (USHORT)DO_MOVE)))
2329 {
2330 dprintf(("item %d not accepted", i));
2331 goto failure;
2332 }
2333 }
2334 /* Release the draginfo data structure */
2335 DrgFreeDraginfo(pDragInfo);
2336 return TRUE;
2337
2338failure:
2339 DrgFreeDraginfo(pDragInfo);
2340 return FALSE;
2341}
2342//******************************************************************************
2343//******************************************************************************
2344#ifdef DEBUG
2345static char *DbgGetStringSWPFlags(ULONG flags)
2346{
2347 static char szSWPFlags[512];
2348
2349 szSWPFlags[0] = 0;
2350
2351 if(flags & SWP_SIZE) {
2352 strcat(szSWPFlags, "SWP_SIZE ");
2353 }
2354 if(flags & SWP_MOVE) {
2355 strcat(szSWPFlags, "SWP_MOVE ");
2356 }
2357 if(flags & SWP_ZORDER) {
2358 strcat(szSWPFlags, "SWP_ZORDER ");
2359 }
2360 if(flags & SWP_SHOW) {
2361 strcat(szSWPFlags, "SWP_SHOW ");
2362 }
2363 if(flags & SWP_HIDE) {
2364 strcat(szSWPFlags, "SWP_HIDE ");
2365 }
2366 if(flags & SWP_NOREDRAW) {
2367 strcat(szSWPFlags, "SWP_NOREDRAW ");
2368 }
2369 if(flags & SWP_NOADJUST) {
2370 strcat(szSWPFlags, "SWP_NOADJUST ");
2371 }
2372 if(flags & SWP_ACTIVATE) {
2373 strcat(szSWPFlags, "SWP_ACTIVATE ");
2374 }
2375 if(flags & SWP_DEACTIVATE) {
2376 strcat(szSWPFlags, "SWP_DEACTIVATE ");
2377 }
2378 if(flags & SWP_EXTSTATECHANGE) {
2379 strcat(szSWPFlags, "SWP_EXTSTATECHANGE ");
2380 }
2381 if(flags & SWP_MINIMIZE) {
2382 strcat(szSWPFlags, "SWP_MINIMIZE ");
2383 }
2384 if(flags & SWP_MAXIMIZE) {
2385 strcat(szSWPFlags, "SWP_MAXIMIZE ");
2386 }
2387 if(flags & SWP_RESTORE) {
2388 strcat(szSWPFlags, "SWP_RESTORE ");
2389 }
2390 if(flags & SWP_FOCUSACTIVATE) {
2391 strcat(szSWPFlags, "SWP_FOCUSACTIVATE ");
2392 }
2393 if(flags & SWP_FOCUSDEACTIVATE) {
2394 strcat(szSWPFlags, "SWP_FOCUSDEACTIVATE ");
2395 }
2396 if(flags & SWP_NOAUTOCLOSE) {
2397 strcat(szSWPFlags, "SWP_NOAUTOCLOSE ");
2398 }
2399 return szSWPFlags;
2400}
2401static char *DbgPrintQFCFlags(ULONG flags)
2402{
2403 static char szQFCFlags[64];
2404
2405 szQFCFlags[0] = 0;
2406
2407 if(flags & QFC_NEXTINCHAIN) {
2408 strcat(szQFCFlags, "QFC_NEXTINCHAIN");
2409 }
2410 else
2411 if(flags & QFC_ACTIVE) {
2412 strcat(szQFCFlags, "QFC_ACTIVE");
2413 }
2414 else
2415 if(flags & QFC_FRAME) {
2416 strcat(szQFCFlags, "QFC_FRAME");
2417 }
2418 else
2419 if(flags & QFC_SELECTACTIVE) {
2420 strcat(szQFCFlags, "QFC_SELECTACTIVE");
2421 }
2422 else
2423 if(flags & QFC_PARTOFCHAIN) {
2424 strcat(szQFCFlags, "QFC_PARTOFCHAIN");
2425 }
2426
2427 return szQFCFlags;
2428}
2429#endif
2430//******************************************************************************
2431//******************************************************************************
Note: See TracBrowser for help on using the repository browser.