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

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

Fix for multiple WM_CHAR_SPECIAL_CONSOLE_BREAK

File size: 82.0 KB
Line 
1/* $Id: pmwindow.cpp,v 1.204 2003-03-28 11:49:02 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_CHAR_SPECIAL_CONSOLE_BREAK:
1263 {
1264 //ignore this message. don't forward it to the default PM frame window handler
1265 //as that one sends it to the client. as a result we end up translating
1266 //it twice
1267 break;
1268 }
1269
1270 case WM_ADJUSTWINDOWPOS:
1271 {
1272 PSWP pswp = (PSWP)mp1;
1273 SWP swpOld;
1274 WINDOWPOS wp,wpOld;
1275 ULONG ulFlags;
1276 ULONG ret = 0;
1277 HWND hParent = NULLHANDLE, hwndAfter;
1278
1279 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));
1280
1281 ulFlags = pswp->fl;
1282
1283 if(win32wnd->IsParentChanging()) {
1284 rc = 0;
1285 break;
1286 }
1287
1288 //@@PF all commands from minimized window viewer or from Ctrl-Esc
1289 //are 'pure' and should be handled only by DeFrameProc - this is weird
1290 //but without them we will not have results. Pure = plain flag of restore/minimize/maximize
1291 if((pswp->fl == SWP_MINIMIZE) || (pswp->fl & SWP_RESTORE)) {
1292 // note the purity of SWP no other SWP_FLAGS allowed
1293 goto RunDefFrameWndProc;
1294 }
1295
1296 if(pswp->fl & SWP_NOADJUST) {
1297 //ignore weird messages (TODO: why are they sent?)
1298 dprintf(("WARNING: WM_ADJUSTWINDOWPOS with SWP_NOADJUST flag!!"));
1299 break;
1300 }
1301 if ((pswp->fl == SWP_FOCUSACTIVATE) || (pswp->fl == SWP_FOCUSDEACTIVATE))
1302 {
1303 dprintf(("Pure focus flags are not sent to win32 windows"));
1304 goto RunDefFrameWndProc;
1305 }
1306
1307 //CB: show dialog in front of owner
1308 if (win32wnd->IsModalDialogOwner())
1309 {
1310 dprintf(("win32wnd->IsModalDialogOwner %x", win32wnd->getWindowHandle()));
1311 pswp->fl |= SWP_ZORDER;
1312 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
1313 if (pswp->fl & SWP_ACTIVATE)
1314 {
1315 pswp->fl &= ~SWP_ACTIVATE;
1316 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
1317 }
1318 }
1319
1320 if(!win32wnd->CanReceiveSizeMsgs())
1321 break;
1322
1323 WinQueryWindowPos(hwnd, &swpOld);
1324 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
1325 if (win32wnd->isChild()) {
1326 if(win32wnd->getParent()) {
1327 hParent = win32wnd->getParent()->getOS2WindowHandle();
1328 }
1329 else goto RunDefFrameWndProc;
1330 }
1331 }
1332 hwndAfter = pswp->hwndInsertBehind;
1333 if(win32wnd->getParent()) {
1334 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(), hwnd);
1335 }
1336 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1337
1338 wp.hwnd = win32wnd->getWindowHandle();
1339 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1340 {
1341 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1342 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
1343 if(wndAfter) {
1344 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1345 RELEASE_WNDOBJ(wndAfter);
1346 }
1347 else wp.hwndInsertAfter = HWND_TOP_W;
1348 }
1349
1350 wpOld = wp;
1351 win32wnd->MsgPosChanging((LPARAM)&wp);
1352
1353 if(win32wnd->getOldStyle() != win32wnd->getStyle())
1354 {
1355 OSLibSetWindowStyle(win32wnd->getOS2FrameWindowHandle(), win32wnd->getOS2WindowHandle(), win32wnd->getStyle(), win32wnd->getExStyle(), win32wnd->getStyle());
1356 if(fOS2Look) {
1357 DWORD dwOldStyle = win32wnd->getOldStyle();
1358 DWORD dwStyle = win32wnd->getStyle();
1359
1360 win32wnd->setOldStyle(dwStyle);
1361 if((dwOldStyle & WS_MINIMIZE_W) && !(dwStyle & WS_MINIMIZE_W)) {
1362 //SC_RESTORE -> SC_MINIMIZE
1363 dprintf(("%x -> SC_RESTORE -> SC_MINIMIZE", win32wnd->getWindowHandle()));
1364 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_RESTORE, SC_MINIMIZE, hbmFrameMenu[PMMENU_MINBUTTON]);
1365 if(dwStyle & WS_MAXIMIZE_W) {
1366 //SC_MAXIMIZE -> SC_RESTORE
1367 dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE (1)", win32wnd->getWindowHandle()));
1368 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[PMMENU_RESTOREBUTTON]);
1369 }
1370 }
1371 else
1372 if((dwOldStyle & WS_MAXIMIZE_W) && !(dwStyle & WS_MAXIMIZE_W)) {
1373 //SC_RESTORE -> SC_MAXIMIZE
1374 dprintf(("%x -> SC_RESTORE -> SC_MAXIMIZE", win32wnd->getWindowHandle()));
1375 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_RESTORE, SC_MAXIMIZE, hbmFrameMenu[PMMENU_MAXBUTTON]);
1376 }
1377 else
1378 if(!(dwOldStyle & WS_MINIMIZE_W) && (dwStyle & WS_MINIMIZE_W)) {
1379 //SC_MINIMIZE -> SC_RESTORE
1380 dprintf(("%x -> SC_MINIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
1381 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_MINIMIZE, SC_RESTORE, hbmFrameMenu[PMMENU_RESTOREBUTTON]);
1382 }
1383 else
1384 if(!(dwOldStyle & WS_MAXIMIZE_W) && (dwStyle & WS_MAXIMIZE_W)) {
1385 //SC_MAXIMIZE -> SC_RESTORE
1386 dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE (2)", win32wnd->getWindowHandle()));
1387 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[PMMENU_RESTOREBUTTON]);
1388 }
1389 }
1390 }
1391
1392 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
1393 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
1394 {
1395 ULONG flags = pswp->fl; //make a backup copy; OSLibMapWINDOWPOStoSWP will modify it
1396
1397 dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
1398 dprintf(("%x (%s) (%d,%d), (%d,%d)", pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy));
1399
1400 if(win32wnd->getParent()) {
1401 OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getClientHeight(),
1402 hwnd);
1403 }
1404 else OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1405
1406 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
1407
1408 //OSLibMapWINDOWPOStoSWP can add flags, but we must not let it remove flags!
1409 if(pswp->fl & SWP_SIZE)
1410 flags |= SWP_SIZE;
1411
1412 if(pswp->fl & SWP_MOVE)
1413 flags |= SWP_MOVE;
1414
1415 pswp->fl = flags; //restore flags
1416
1417 pswp->fl |= SWP_NOADJUST;
1418 pswp->hwndInsertBehind = hwndAfter;
1419 pswp->hwnd = hwnd;
1420
1421 ret = 0xf;
1422 }
1423adjustend:
1424 //The next part needs to be done for top-level windows only
1425 if(!((win32wnd->getStyle() & (WS_POPUP_W|WS_CHILD_W)) == WS_CHILD_W))
1426 {
1427 //Setting these flags is necessary to avoid activation/focus problems
1428 if(ulFlags & SWP_DEACTIVATE) {
1429 ret |= AWP_DEACTIVATE;
1430 }
1431 if(ulFlags & SWP_ACTIVATE)
1432 {
1433 if(ulFlags & SWP_ZORDER) {
1434 dprintf(("Set FF_NOACTIVATESWP"));
1435 ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
1436 WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags | FF_NOACTIVATESWP);
1437 }
1438
1439 if(!(ulFlags & SWP_SHOW))
1440 {
1441 ret |= AWP_ACTIVATE;
1442 }
1443 else
1444 {
1445 FrameSetFocus(hwnd);
1446 }
1447 }
1448 }
1449 else {
1450 if(ulFlags & (SWP_ACTIVATE|SWP_FOCUSACTIVATE))
1451 {
1452 win32wnd->MsgChildActivate(TRUE);
1453 if(fOS2Look) {
1454 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1455 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, (MPARAM)1, 0);
1456 }
1457 }
1458 else
1459 if(ulFlags & (SWP_DEACTIVATE|SWP_FOCUSDEACTIVATE))
1460 {
1461 win32wnd->MsgChildActivate(FALSE);
1462 if(fOS2Look) {
1463 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1464 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, 0, 0);
1465 }
1466 }
1467 }
1468 dprintf(("WM_ADJUSTWINDOWPOS ret %x flags %x", ret, WinQueryWindowUShort(hwnd, QWS_FLAGS)));
1469//testestset
1470 if(ret == 0x0f) {
1471 dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
1472 dprintf(("%x (%s) (%d,%d), (%d,%d)", pswp->fl, DbgGetStringSWPFlags(pswp->fl), pswp->x, pswp->y, pswp->cx, pswp->cy));
1473 }
1474//testestset
1475 rc = (MRESULT)ret;
1476 break;
1477 }
1478
1479 case WM_WINDOWPOSCHANGED:
1480 {
1481 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
1482 SWP swpOld = *(pswp + 1);
1483 WINDOWPOS wp;
1484 ULONG flAfp = (ULONG)mp2;
1485 HWND hParent = NULLHANDLE;
1486 RECTL rect;
1487
1488 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)));
1489 if(win32wnd->IsParentChanging()) {
1490 goto PosChangedEnd;
1491 }
1492
1493 //SvL: When a window is made visible, then we don't receive a
1494 // WM_VRNENABLED message (for some weird reason)
1495 if(pswp->fl & SWP_SHOW) {
1496 win32wnd->callVisibleRgnNotifyProc(TRUE);
1497 }
1498 else
1499 if(pswp->fl & SWP_HIDE) {
1500 win32wnd->callVisibleRgnNotifyProc(FALSE);
1501 }
1502
1503 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
1504 {
1505 if(pswp->fl & SWP_RESTORE && win32wnd->getStyle() & WS_MINIMIZE_W) {
1506 dprintf(("Restoring minimized window %x", win32wnd->getWindowHandle()));
1507 win32wnd->ShowWindow(SW_RESTORE_W);
1508 }
1509 if(pswp->fl & SWP_SHOW) {
1510 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
1511 }
1512 else
1513 if(pswp->fl & SWP_HIDE) {
1514 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
1515 }
1516 //MUST call the old frame window proc!
1517 goto RunDefFrameWndProc;
1518 }
1519
1520 if(pswp->fl & (SWP_MOVE | SWP_SIZE))
1521 {
1522 if(win32wnd->isChild())
1523 {
1524 if(win32wnd->getParent()) {
1525 hParent = win32wnd->getParent()->getOS2WindowHandle();
1526 }
1527 else goto PosChangedEnd; //parent has just been destroyed
1528 }
1529 }
1530
1531
1532 if(win32wnd->getParent()) {
1533 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1534 hwnd);
1535 }
1536 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1537
1538 wp.hwnd = win32wnd->getWindowHandle();
1539 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1540 {
1541 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1542 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
1543 if(wndAfter) {
1544 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1545 RELEASE_WNDOBJ(wndAfter);
1546 }
1547 else wp.hwndInsertAfter = HWND_TOP_W;
1548 }
1549
1550 if(pswp->fl & SWP_SHOW) {
1551 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
1552 }
1553 else
1554 if(pswp->fl & SWP_HIDE) {
1555 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
1556 }
1557
1558 if(flAfp & AWP_ACTIVATE)
1559 {
1560 FrameSetFocus(hwnd);
1561 }
1562
1563#ifndef USE_CALCVALIDRECT
1564 if((pswp->fl & (SWP_MOVE | SWP_SIZE)))
1565 {
1566 //CB: todo: use result for WM_CALCVALIDRECTS
1567 //Get old client rectangle (for invalidation of frame window parts later on)
1568 //Use new window height to calculate the client area
1569 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
1570
1571 //Note: Also updates the new window rectangle
1572 win32wnd->MsgFormatFrame(&wp);
1573
1574 if(win32wnd->isOwnDC()) {
1575 setPageXForm(win32wnd, (pDCData)GpiQueryDCData(win32wnd->getOwnDC()));
1576 }
1577
1578 if(win32wnd->CanReceiveSizeMsgs())
1579 win32wnd->MsgPosChanged((LPARAM)&wp);
1580
1581 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
1582 {
1583 //redraw the frame (to prevent unnecessary client updates)
1584 BOOL redrawAll = FALSE;
1585
1586 dprintf2(("WM_WINDOWPOSCHANGED: redraw frame"));
1587 if (win32wnd->getWindowClass())
1588 {
1589 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
1590
1591 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
1592 redrawAll = TRUE;
1593 else
1594 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
1595 redrawAll = TRUE;
1596 }
1597 else redrawAll = TRUE;
1598
1599 if(win32wnd->IsMixMaxStateChanging()) {
1600 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1601 redrawAll = TRUE;
1602 }
1603
1604 if (redrawAll)
1605 {
1606 //CB: redraw all children for now
1607 // -> problems with update region if we don't do it
1608 // todo: rewrite whole handling
1609 dprintf(("PMFRAME: WM_WINDOWPOSCHANGED invalidate all"));
1610 WinInvalidateRect(hwnd,NULL,TRUE);
1611 }
1612 else
1613 {
1614 HPS hps = WinGetPS(hwnd);
1615 RECTL frame,client,arcl[4];
1616
1617 WinQueryWindowRect(hwnd,&frame);
1618
1619 //top
1620 arcl[0].xLeft = 0;
1621 arcl[0].xRight = frame.xRight;
1622 arcl[0].yBottom = rect.yTop;
1623 arcl[0].yTop = frame.yTop;
1624 //right
1625 arcl[1].xLeft = rect.xRight;
1626 arcl[1].xRight = frame.xRight;
1627 arcl[1].yBottom = 0;
1628 arcl[1].yTop = frame.yTop;
1629 //left
1630 arcl[2].xLeft = 0;
1631 arcl[2].xRight = rect.xLeft;
1632 arcl[2].yBottom = 0;
1633 arcl[2].yTop = frame.yTop;
1634 //bottom
1635 arcl[3].xLeft = 0;
1636 arcl[3].xRight = frame.xRight;
1637 arcl[3].yBottom = 0;
1638 arcl[3].yTop = rect.yBottom;
1639
1640 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
1641
1642 WinInvalidateRegion(hwnd,hrgn,FALSE);
1643 GpiDestroyRegion(hps,hrgn);
1644 WinReleasePS(hps);
1645 }
1646 }
1647 }
1648 else
1649 {
1650#endif //USE_CALCVALIDRECT
1651 if(win32wnd->CanReceiveSizeMsgs())
1652 win32wnd->MsgPosChanged((LPARAM)&wp);
1653#ifndef USE_CALCVALIDRECT
1654 }
1655#endif
1656
1657PosChangedEnd:
1658 rc = (MRESULT)FALSE;
1659 break;
1660 }
1661
1662 case WM_CALCVALIDRECTS:
1663#ifdef USE_CALCVALIDRECT
1664 {
1665 PRECTL oldRect = (PRECTL)mp1, newRect = oldRect+1;
1666 PSWP pswp = (PSWP)mp2;
1667 SWP swpOld;
1668 WINDOWPOS wp;
1669 RECTL newClientRect, oldClientRect;
1670 ULONG nccalcret;
1671// UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
1672 UINT res = 0;
1673
1674 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1675
1676 //Get old position info
1677 WinQueryWindowPos(hwnd, &swpOld);
1678
1679 if(win32wnd->getParent()) {
1680 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1681 win32wnd->getParent()->getClientRectPtr()->left,
1682 win32wnd->getParent()->getClientRectPtr()->top,
1683 hwnd);
1684 }
1685 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
1686
1687 wp.hwnd = win32wnd->getWindowHandle();
1688 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1689 {
1690 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1691 if(wndAfter) {
1692 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1693 RELEASE_WNDOBJ(wndAfter);
1694 }
1695 else wp.hwndInsertAfter = HWND_TOP_W;
1696 }
1697
1698 //Get old client rectangle
1699 mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
1700
1701 //Note: Also updates the new window rectangle
1702 nccalcret = win32wnd->MsgFormatFrame(&wp);
1703
1704 //Get new client rectangle
1705 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
1706
1707 if(nccalcret == 0) {
1708 res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
1709 }
1710 else {
1711 if(nccalcret & WVR_ALIGNTOP_W) {
1712 res |= CVR_ALIGNTOP;
1713 }
1714 else
1715 if(nccalcret & WVR_ALIGNBOTTOM_W) {
1716 res |= CVR_ALIGNBOTTOM;
1717 }
1718
1719 if(nccalcret & WVR_ALIGNLEFT_W) {
1720 res |= CVR_ALIGNLEFT;
1721 }
1722 else
1723 if(nccalcret & WVR_ALIGNRIGHT_W) {
1724 res |= CVR_ALIGNRIGHT;
1725 }
1726
1727 if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
1728 res |= CVR_REDRAW;
1729 }
1730 else
1731 if(nccalcret & WVR_VALIDRECTS_W) {
1732 //TODO:
1733 //res = 0;
1734 }
1735 }
1736 if(win32wnd->IsMixMaxStateChanging()) {
1737 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1738 res |= CVR_REDRAW;
1739 }
1740 if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
1741 oldRect->xRight -= oldClientRect.xLeft;
1742 oldRect->yBottom += oldClientRect.yBottom;
1743 newRect->xRight -= newClientRect.xLeft;
1744 newRect->yBottom += newClientRect.yBottom;
1745 }
1746 rc = res;
1747 break;
1748 }
1749#else
1750 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1751 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
1752 break;
1753#endif
1754
1755 case WM_CALCFRAMERECT:
1756 dprintf(("PMFRAME:WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
1757 rc = (MRESULT)TRUE;
1758 break;
1759
1760 case WM_QUERYCTLTYPE:
1761 // This is a frame window
1762 dprintf(("PMFRAME:WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
1763 rc = (MRESULT)CCT_FRAME;
1764 break;
1765
1766#ifdef DEBUG
1767 case WM_QUERYFOCUSCHAIN:
1768 dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x (%s) parent %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), DbgPrintQFCFlags(SHORT1FROMMP(mp1)), (mp2) ? OS2ToWin32Handle((DWORD)mp2) : 0));
1769
1770 RestoreOS2TIB();
1771 rc = pfnFrameWndProc(hwnd, msg, mp1, mp2);
1772 SetWin32TIB();
1773 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));
1774 break;
1775// goto RunDefFrameWndProc;
1776#endif
1777
1778 case WM_FOCUSCHANGE:
1779 {
1780 HWND hwndFocus = (HWND)mp1;
1781 HWND hwndLoseFocus, hwndGainFocus;
1782 USHORT usSetFocus = SHORT1FROMMP(mp2);
1783 USHORT fsFocusChange = SHORT2FROMMP(mp2);
1784
1785 //Save window that gains focus so we can determine which
1786 //process we lose activation to
1787 hwndFocusChange = (HWND)mp1;
1788
1789 dprintf(("PMFRAME:WM_FOCUSCHANGE %x %x (%x) %x %x", win32wnd->getWindowHandle(), OS2ToWin32Handle(hwndFocus), hwndFocus, usSetFocus, fsFocusChange));
1790 goto RunDefFrameWndProc;
1791 }
1792
1793#ifdef DEBUG
1794 case WM_SETFOCUS:
1795 {
1796 dprintf(("PMFRAME: WM_SETFOCUS %x %x %d -> %x", win32wnd->getWindowHandle(), hwnd, mp2, mp1));
1797 goto RunDefFrameWndProc;
1798 }
1799#endif
1800
1801 case WM_ACTIVATE:
1802 {
1803 HWND hwndTitle;
1804 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
1805
1806 dprintf(("PMFRAME: WM_ACTIVATE %x %x %x", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle((DWORD)mp2)));
1807 if (win32wnd->IsWindowCreated())
1808 {
1809 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1810 if(fOS2Look) {
1811 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1812 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, mp1, 0);
1813 }
1814 if(SHORT1FROMMP(mp1) == 0) {
1815 //deactivate
1816 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
1817 }
1818 PID pidThis, pidPartner, pidTemp;
1819 TID tidPartner;
1820 HENUM henum;
1821 HWND hwndEnum;
1822
1823 WinQueryWindowProcess(hwnd, &pidThis, NULL);
1824 WinQueryWindowProcess(hwndFocusChange, &pidPartner, &tidPartner);
1825
1826 if(pidThis != pidPartner) {
1827 //Gain or lose activation to window in other process
1828 //must send WM_ACTIVATEAPP to top-level windows
1829
1830 //Iterate over all child windows of the desktop
1831 henum = WinBeginEnumWindows(HWND_DESKTOP);
1832
1833 while(hwndEnum = WinGetNextWindow(henum))
1834 {
1835 WinQueryWindowProcess(hwndEnum, &pidTemp, NULL);
1836 if(pidTemp == pidThis)
1837 {
1838 SendMessageA(OS2ToWin32Handle(hwndEnum), WM_ACTIVATEAPP_W, (WPARAM)SHORT1FROMMP(mp1), (LPARAM)tidPartner);
1839 }
1840 }
1841 WinEndEnumWindows(henum);
1842 }
1843 if(SHORT1FROMMP(mp1)) {
1844 //activate
1845 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
1846 }
1847
1848 //CB: show owner behind the dialog
1849 if (win32wnd->IsModalDialog())
1850 {
1851 if(win32wnd->getOwner()) {
1852 Win32BaseWindow *topOwner = Win32BaseWindow::GetWindowFromHandle(win32wnd->getOwner()->GetTopParent());
1853
1854 if (topOwner) {
1855 WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
1856 RELEASE_WNDOBJ(topOwner);
1857 }
1858 }
1859 }
1860 }
1861 else
1862 {
1863 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1864 }
1865 rc = 0;
1866 break;
1867 }
1868
1869 case WM_ENABLE:
1870 dprintf(("PMFRAME: WM_ENABLE %x", hwnd));
1871 win32wnd->MsgEnable(SHORT1FROMMP(mp1));
1872 break;
1873
1874 case WM_SHOW:
1875 dprintf(("PMFRAME: WM_SHOW %x %d", hwnd, mp1));
1876 //show client window
1877 WinShowWindow(win32wnd->getOS2WindowHandle(), (BOOL)mp1);
1878 break;
1879
1880 case WM_QUERYTRACKINFO:
1881 {
1882 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
1883
1884 dprintf(("PMFRAME:WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
1885 trackInfo->cxBorder = 4;
1886 trackInfo->cyBorder = 4;
1887 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
1888 rc = (MRESULT)TRUE;
1889 break;
1890 }
1891
1892 case WM_QUERYBORDERSIZE:
1893 {
1894 PWPOINT size = (PWPOINT)mp1;
1895
1896 dprintf(("PMFRAME:WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
1897
1898 size->x = 0;
1899 size->y = 0;
1900 rc = (MRESULT)TRUE;
1901 break;
1902 }
1903
1904#ifdef DEBUG
1905 case WM_QUERYFRAMEINFO:
1906 dprintf(("PMFRAME:WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
1907 goto RunDefFrameWndProc;
1908#endif
1909
1910 case WM_FORMATFRAME:
1911 dprintf(("PMFRAME:WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
1912 break;
1913
1914 case WM_ADJUSTFRAMEPOS:
1915 {
1916 PSWP pswp = (PSWP)mp1;
1917
1918 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));
1919 //hack alert: the PM frame control changes the z-order of a child window
1920 // if it receives focus after a window has been destroyed
1921 // We can't let this happen as this messes up assumptions
1922 // elsewhere (e.g. GetNextDlgGroupItem)
1923 // By returning 0 here, we prevent the default frame handler
1924 // from messing things up. (one example is a group of radio buttons)
1925 //NOTE: We really need to get rid of frame & client windows for each
1926 // win32 window
1927 if(pswp->fl == SWP_FOCUSACTIVATE && win32wnd->isChild()) {
1928 rc = 0;
1929 break;
1930 }
1931 //hack alert: as we return zero as border size (check handler) we need
1932 //to do adjustments here as well or PM will calculate it for us and
1933 //result will be illegal. Btw we do not honour PM border size settings
1934 //and never will. I was unable to figure out why only X coordinate
1935 //is being broken but not Y as well.
1936
1937 if ((pswp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1938 {
1939 RECT rect;
1940 rect.left = rect.top = rect.right = rect.bottom = 0;
1941 win32wnd->AdjustMaximizedRect(&rect);
1942
1943 pswp->x += rect.left;
1944 }
1945 goto RunDefFrameWndProc;
1946 }
1947
1948#ifdef DEBUG
1949 case WM_OWNERPOSCHANGE:
1950 {
1951 PSWP pswp = (PSWP)mp1;
1952
1953 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));
1954 goto RunDefFrameWndProc;
1955 }
1956#endif
1957
1958 case WM_MINMAXFRAME:
1959 {
1960 PSWP swp = (PSWP)mp1;
1961
1962 if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
1963
1964 dprintf(("PMFRAME:WM_MINMAXFRAME %x",hwnd));
1965 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1966 {
1967 RECT rect;
1968 rect.left = rect.top = rect.right = rect.bottom = 0;
1969 win32wnd->AdjustMaximizedRect(&rect);
1970
1971 swp->x += rect.left;
1972 swp->cx += rect.right-rect.left;
1973 swp->y -= rect.bottom;
1974 swp->cy += rect.bottom-rect.top;
1975
1976 win32wnd->ShowWindow(SW_RESTORE_W);
1977 }
1978 else
1979 if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
1980 {
1981 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
1982 }
1983 else
1984 if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
1985 {
1986 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
1987 }
1988 goto RunDefWndProc;
1989 }
1990
1991#ifdef DEBUG
1992 case WM_UPDATEFRAME:
1993 dprintf(("PMFRAME:WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
1994 goto RunDefFrameWndProc;
1995#endif
1996
1997 case WM_TRACKFRAME:
1998 dprintf(("PMFRAME: WM_TRACKFRAME %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
1999 if(fOS2Look) {//sent by titlebar control
2000 Frame_SysCommandSizeMove(win32wnd, SC_MOVE_W+HTCAPTION_W);
2001 }
2002 rc = 0;
2003 break;
2004
2005 case WM_SYSCOMMAND:
2006 dprintf(("PMFRAME: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
2007 if (fOS2Look == OS2_APPEARANCE_SYSMENU && mp1 == (MPARAM)OSSC_SYSMENU)
2008 goto RunDefFrameWndProc;
2009
2010 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
2011 RELEASE_WNDOBJ(win32wnd);
2012 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
2013 }
2014 if(win32wnd)
2015 win32wnd->DispatchMsgA(pWinMsg);
2016 break;
2017
2018#ifdef DEBUG
2019 case WM_DDE_INITIATE:
2020 case WM_DDE_INITIATEACK:
2021 case WM_DDE_REQUEST:
2022 case WM_DDE_ACK:
2023 case WM_DDE_DATA:
2024 case WM_DDE_ADVISE:
2025 case WM_DDE_UNADVISE:
2026 case WM_DDE_POKE:
2027 case WM_DDE_EXECUTE:
2028 case WM_DDE_TERMINATE:
2029 dprintf(("PMFRAME: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
2030 break;
2031#endif
2032
2033 default:
2034 goto RunDefFrameWndProc;
2035 }
2036 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2037 RestoreOS2TIB();
2038
2039#ifdef DEBUG
2040 dbg_ThreadPopCall();
2041#endif
2042 return (MRESULT)rc;
2043
2044RunDefFrameWndProc:
2045 dprintf2(("RunDefFrameWndProc"));
2046 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2047 RestoreOS2TIB();
2048
2049#ifdef DEBUG
2050 dbg_ThreadPopCall();
2051#endif
2052 return pfnFrameWndProc(hwnd, msg, mp1, mp2);
2053
2054RunDefWndProc:
2055 dprintf2(("RunDefWndProc"));
2056 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2057 RestoreOS2TIB();
2058 //calling WinDefWindowProc here breaks Opera hotlist window (WM_ADJUSTWINDOWPOS)
2059// return pfnFrameWndProc(hwnd, msg, mp1, mp2);
2060
2061#ifdef DEBUG
2062 dbg_ThreadPopCall();
2063#endif
2064 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
2065}
2066//******************************************************************************
2067//******************************************************************************
2068MRESULT EXPENTRY Win32FakeWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
2069{
2070 PFNWP pfnOldWindowProc;
2071 Win32BaseWindow *win32wnd, *win32wndchild;
2072 TEB *teb;
2073 MRESULT rc = 0;
2074
2075 //Restore our FS selector
2076 SetWin32TIB();
2077
2078 //We can't query the window object directly from this window as it's not the
2079 //real thing. There should be a genuine win32 child window which we can use.
2080 HWND hwndChild = WinQueryWindow(hwnd, QW_TOP);
2081
2082 win32wndchild = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwndChild);
2083 if(win32wndchild == NULL) {
2084 DebugInt3();
2085 goto RunDefWndProc;
2086 }
2087 //now get the parent window object
2088 win32wnd = Win32BaseWindow::GetWindowFromHandle(GetParent(win32wndchild->getWindowHandle()));
2089 if(win32wndchild) RELEASE_WNDOBJ(win32wndchild);
2090
2091 if(win32wnd == NULL) {
2092 DebugInt3();
2093 goto RunDefWndProc;
2094 }
2095
2096 pfnOldWindowProc = (PFNWP)win32wnd->getOldPMWindowProc();
2097 if(pfnOldWindowProc == NULL) {
2098 DebugInt3();
2099 goto RunDefWndProc;
2100 }
2101
2102 rc = pfnOldWindowProc(hwnd, msg, mp1, mp2);
2103 switch(msg) {
2104 case WM_WINDOWPOSCHANGED:
2105 {
2106 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
2107 SWP swpOld = *(pswp + 1);
2108 WINDOWPOS wp;
2109
2110 if(win32wnd->getParent()) {
2111 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
2112 hwnd);
2113 }
2114 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
2115
2116 win32wnd->SetWindowPos(wp.hwndInsertAfter, wp.x, wp.y, wp.cx, wp.cy, wp.flags);
2117 break;
2118 }
2119
2120 }
2121 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2122 RestoreOS2TIB();
2123 return rc;
2124
2125RunDefWndProc:
2126 RestoreOS2TIB();
2127 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
2128}
2129//******************************************************************************
2130// PMWinSubclassFakeWindow
2131//
2132// Subclass a fake window (converted PM window)
2133//
2134// Parameters
2135//
2136// HWND hwndOS2 - PM handle of fake window
2137//
2138// Returns
2139// NULL - Failure
2140// else - Old PM window procedure
2141//
2142//******************************************************************************
2143PVOID PMWinSubclassFakeWindow(HWND hwndOS2)
2144{
2145 return WinSubclassWindow(hwndOS2, Win32FakeWindowProc);
2146}
2147//******************************************************************************
2148//******************************************************************************
2149void FrameSetFocus(HWND hwnd)
2150{
2151 HWND hwndFocusSave = WinQueryWindowULong(hwnd, QWL_HWNDFOCUSSAVE);
2152 if(!WinIsWindow(hab, hwndFocusSave)) {
2153 hwndFocusSave = WinWindowFromID(hwnd, FID_CLIENT);
2154 WinSetWindowULong(hwnd, QWL_HWNDFOCUSSAVE, hwndFocusSave);
2155 }
2156 dprintf(("FrameSetFocus: hwndFocusSave %x %x", OS2ToWin32Handle(hwndFocusSave), hwndFocusSave));
2157 WinSetFocus(HWND_DESKTOP, hwndFocusSave);
2158
2159 ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
2160 ulFrameFlags &= ~FF_NOACTIVATESWP;
2161 WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags);
2162}
2163//******************************************************************************
2164//******************************************************************************
2165void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG idNew,
2166 HBITMAP hbmNew)
2167{
2168 MENUITEM mi;
2169
2170 if (!hwndMenu)
2171 return;
2172
2173 WinEnableWindowUpdate(hwndMenu, FALSE);
2174
2175 if (WinSendMsg(hwndMenu, MM_QUERYITEM, MPFROM2SHORT(idOld, TRUE), MPFROMP(&mi)))
2176 {
2177 WinSendMsg(hwndMenu, MM_REMOVEITEM, (MPARAM)idOld, 0);
2178 mi.afStyle = MIS_BITMAP | MIS_SYSCOMMAND;
2179 mi.afAttribute = 0;
2180 mi.hwndSubMenu = 0;
2181 mi.id = idNew;
2182 mi.hItem = (ULONG)hbmNew;
2183 WinSendMsg(hwndMenu, MM_INSERTITEM, (MPARAM)&mi, 0);
2184 }
2185 else
2186 dprintf(("WARNING: FrameReplaceMenuItem control %x not found",idOld));
2187
2188 WinEnableWindowUpdate(hwndMenu, TRUE);
2189
2190 WinInvalidateRect(hwndMenu, NULL, TRUE);
2191}
2192//******************************************************************************
2193//******************************************************************************
2194static char *PMDragExtractFiles(PDRAGINFO pDragInfo, ULONG *pcItems, ULONG *pulBytes)
2195{
2196 PDRAGITEM pDragItem;
2197 int i, cItems;
2198 BOOL ret;
2199 char szFileName[CCHMAXPATH];
2200 char szContainerName[CCHMAXPATH];
2201 ULONG ulBytes;
2202 char *pszCurFile = NULL;
2203
2204 /* Get access to the DRAGINFO data structure */
2205 if(!DrgAccessDraginfo(pDragInfo)) {
2206 return NULL;
2207 }
2208
2209 cItems = DrgQueryDragitemCount(pDragInfo);
2210
2211 //computer memory required to hold all filenames
2212 int bufsize = 0;
2213 for (i = 0; i < cItems; i++) {
2214 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
2215
2216 bufsize += DrgQueryStrNameLen(pDragItem->hstrContainerName) + DrgQueryStrNameLen(pDragItem->hstrSourceName);
2217 bufsize++; //0 terminator
2218 bufsize++; //+ potential missing backslash
2219 }
2220 bufsize++; //extra 0 terminator
2221 char *pszFiles = (char *)malloc(bufsize);
2222 if(pszFiles == NULL) {
2223 dprintf(("Out of memory!!"));
2224 DebugInt3();
2225 goto failure;
2226 }
2227 memset(pszFiles, 0, bufsize);
2228
2229 pszCurFile = pszFiles;
2230
2231 //copy all filenames
2232 for (i = 0; i < cItems; i++) {
2233 char *pszTemp = pszCurFile;
2234
2235 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
2236
2237 ulBytes = DrgQueryStrNameLen(pDragItem->hstrContainerName);
2238 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
2239 ulBytes, pszCurFile);
2240 if(pszCurFile[ulBytes-1] != '\\') {
2241 pszCurFile[ulBytes] = '\\';
2242 pszCurFile++;
2243 }
2244 pszCurFile += ulBytes;
2245
2246 ulBytes = DrgQueryStrNameLen(pDragItem->hstrSourceName);
2247 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
2248 ulBytes+1, pszCurFile);
2249 pszCurFile += ulBytes + 1; //+ terminator
2250
2251 dprintf(("dropped file %s", pszTemp));
2252 }
2253
2254 /* Release the draginfo data structure */
2255 DrgFreeDraginfo(pDragInfo);
2256
2257 *pulBytes = bufsize;
2258 *pcItems = cItems;
2259
2260 return pszFiles;
2261
2262failure:
2263 /* Release the draginfo data structure */
2264 DrgFreeDraginfo(pDragInfo);
2265 if(pszFiles) {
2266 free(pszFiles);
2267 }
2268 return NULL;
2269}
2270//******************************************************************************
2271//******************************************************************************
2272static BOOL PMDragValidate(PDRAGINFO pDragInfo)
2273{
2274 PDRAGITEM pDragItem;
2275 ULONG ulBytes;
2276 int i, cItems;
2277 BOOL ret;
2278 char szFileName[CCHMAXPATH];
2279 char szContainerName[CCHMAXPATH];
2280 USHORT usOp = DO_MOVE;
2281
2282 /* Get access to the DRAGINFO data structure */
2283 if(!DrgAccessDraginfo(pDragInfo)) {
2284 return FALSE;
2285 }
2286
2287 /* Can we accept this drop? */
2288 switch (pDragInfo->usOperation) {
2289 /* Return DOR_NODROPOP if current operation */
2290 /* is link or unknown */
2291 case DO_LINK:
2292 case DO_COPY:
2293 case DO_UNKNOWN:
2294 goto failure;
2295
2296 /* Our default operation is Move */
2297 case DO_MOVE:
2298 case DO_DEFAULT:
2299 pDragItem = DrgQueryDragitemPtr(pDragInfo, 0);
2300 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
2301 sizeof(szContainerName),
2302 szContainerName);
2303 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
2304 sizeof(szFileName),
2305 szFileName);
2306 if (!ulBytes) {
2307 goto failure;
2308 }
2309
2310 dprintf(("dropped file %s%s", szContainerName, szFileName));
2311 break;
2312 }
2313
2314 cItems = DrgQueryDragitemCount(pDragInfo);
2315
2316 /* Now, we need to look at each item in turn */
2317 for (i = 0; i < cItems; i++) {
2318 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
2319
2320 /* Make sure we can move for a Move request */
2321 if (!((pDragItem->fsSupportedOps & DO_MOVEABLE) &&
2322 (usOp == (USHORT)DO_MOVE)))
2323 {
2324 dprintf(("item %d not accepted", i));
2325 goto failure;
2326 }
2327 }
2328 /* Release the draginfo data structure */
2329 DrgFreeDraginfo(pDragInfo);
2330 return TRUE;
2331
2332failure:
2333 DrgFreeDraginfo(pDragInfo);
2334 return FALSE;
2335}
2336//******************************************************************************
2337//******************************************************************************
2338#ifdef DEBUG
2339static char *DbgGetStringSWPFlags(ULONG flags)
2340{
2341 static char szSWPFlags[512];
2342
2343 szSWPFlags[0] = 0;
2344
2345 if(flags & SWP_SIZE) {
2346 strcat(szSWPFlags, "SWP_SIZE ");
2347 }
2348 if(flags & SWP_MOVE) {
2349 strcat(szSWPFlags, "SWP_MOVE ");
2350 }
2351 if(flags & SWP_ZORDER) {
2352 strcat(szSWPFlags, "SWP_ZORDER ");
2353 }
2354 if(flags & SWP_SHOW) {
2355 strcat(szSWPFlags, "SWP_SHOW ");
2356 }
2357 if(flags & SWP_HIDE) {
2358 strcat(szSWPFlags, "SWP_HIDE ");
2359 }
2360 if(flags & SWP_NOREDRAW) {
2361 strcat(szSWPFlags, "SWP_NOREDRAW ");
2362 }
2363 if(flags & SWP_NOADJUST) {
2364 strcat(szSWPFlags, "SWP_NOADJUST ");
2365 }
2366 if(flags & SWP_ACTIVATE) {
2367 strcat(szSWPFlags, "SWP_ACTIVATE ");
2368 }
2369 if(flags & SWP_DEACTIVATE) {
2370 strcat(szSWPFlags, "SWP_DEACTIVATE ");
2371 }
2372 if(flags & SWP_EXTSTATECHANGE) {
2373 strcat(szSWPFlags, "SWP_EXTSTATECHANGE ");
2374 }
2375 if(flags & SWP_MINIMIZE) {
2376 strcat(szSWPFlags, "SWP_MINIMIZE ");
2377 }
2378 if(flags & SWP_MAXIMIZE) {
2379 strcat(szSWPFlags, "SWP_MAXIMIZE ");
2380 }
2381 if(flags & SWP_RESTORE) {
2382 strcat(szSWPFlags, "SWP_RESTORE ");
2383 }
2384 if(flags & SWP_FOCUSACTIVATE) {
2385 strcat(szSWPFlags, "SWP_FOCUSACTIVATE ");
2386 }
2387 if(flags & SWP_FOCUSDEACTIVATE) {
2388 strcat(szSWPFlags, "SWP_FOCUSDEACTIVATE ");
2389 }
2390 if(flags & SWP_NOAUTOCLOSE) {
2391 strcat(szSWPFlags, "SWP_NOAUTOCLOSE ");
2392 }
2393 return szSWPFlags;
2394}
2395static char *DbgPrintQFCFlags(ULONG flags)
2396{
2397 static char szQFCFlags[64];
2398
2399 szQFCFlags[0] = 0;
2400
2401 if(flags & QFC_NEXTINCHAIN) {
2402 strcat(szQFCFlags, "QFC_NEXTINCHAIN");
2403 }
2404 else
2405 if(flags & QFC_ACTIVE) {
2406 strcat(szQFCFlags, "QFC_ACTIVE");
2407 }
2408 else
2409 if(flags & QFC_FRAME) {
2410 strcat(szQFCFlags, "QFC_FRAME");
2411 }
2412 else
2413 if(flags & QFC_SELECTACTIVE) {
2414 strcat(szQFCFlags, "QFC_SELECTACTIVE");
2415 }
2416 else
2417 if(flags & QFC_PARTOFCHAIN) {
2418 strcat(szQFCFlags, "QFC_PARTOFCHAIN");
2419 }
2420
2421 return szQFCFlags;
2422}
2423#endif
2424//******************************************************************************
2425//******************************************************************************
Note: See TracBrowser for help on using the repository browser.