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

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

KSO: Properties allocated from shared memory & Fake window updates & SW_SHOWDEFAULT update

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