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

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

PF: Correctly finish PM restore procedure from minimized state; Use Stock brush for minimized icon fill when it is not allocated

File size: 83.6 KB
Line 
1/* $Id: pmwindow.cpp,v 1.212 2003-04-28 08:41:07 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 // PF: MDI window is not a common OS/2 frame window so we just skipped all
1504 // PM default processing for it that basicly moved this window to 0,0 point
1505 // and changed frame controls. Now do our own processing.
1506
1507 if ((pswp->fl & SWP_MAXIMIZE) && (win32wnd->getExStyle() & WS_EX_MDICHILD_W))
1508 {
1509 SendMessageA(win32wnd->getWindowHandle(), WM_SYSCOMMAND_W, SC_MAXIMIZE_W, 0);
1510 goto PosChangedEnd;
1511 }
1512
1513 //SvL: When a window is made visible, then we don't receive a
1514 // WM_VRNENABLED message (for some weird reason)
1515 if(pswp->fl & SWP_SHOW) {
1516 win32wnd->callVisibleRgnNotifyProc(TRUE);
1517 }
1518 else
1519 if(pswp->fl & SWP_HIDE) {
1520 win32wnd->callVisibleRgnNotifyProc(FALSE);
1521 }
1522
1523 if(pswp->fl & (SWP_MOVE | SWP_SIZE))
1524 {
1525 if(win32wnd->isChild())
1526 {
1527 if(win32wnd->getParent()) {
1528 hParent = win32wnd->getParent()->getOS2WindowHandle();
1529 }
1530 else goto PosChangedEnd; //parent has just been destroyed
1531 }
1532 }
1533
1534
1535 if(win32wnd->getParent()) {
1536 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1537 hwnd);
1538 }
1539 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1540
1541 wp.hwnd = win32wnd->getWindowHandle();
1542 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1543 {
1544 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1545 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
1546 if(wndAfter) {
1547 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1548 RELEASE_WNDOBJ(wndAfter);
1549 }
1550 else wp.hwndInsertAfter = HWND_TOP_W;
1551 }
1552
1553 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
1554 {
1555 if(pswp->fl & SWP_RESTORE && win32wnd->getStyle() & WS_MINIMIZE_W) {
1556 dprintf(("Restoring minimized window %x", win32wnd->getWindowHandle()));
1557 win32wnd->ShowWindow(SW_RESTORE_W);
1558 }
1559 if(pswp->fl & SWP_SHOW) {
1560 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
1561 }
1562 else
1563 if(pswp->fl & SWP_HIDE) {
1564 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
1565 }
1566 if(pswp->fl & (SWP_SHOW|SWP_HIDE))
1567 {//TODO: necessary for more options? (activate?)
1568 if(win32wnd->CanReceiveSizeMsgs())
1569 win32wnd->MsgPosChanged((LPARAM)&wp);
1570 }
1571
1572 //MUST call the old frame window proc!
1573 goto RunDefFrameWndProc;
1574 }
1575
1576 if(pswp->fl & SWP_SHOW) {
1577 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
1578 }
1579 else
1580 if(pswp->fl & SWP_HIDE) {
1581 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
1582 }
1583
1584 if(flAfp & AWP_ACTIVATE)
1585 {
1586 FrameSetFocus(hwnd);
1587 }
1588
1589#ifndef USE_CALCVALIDRECT
1590 if((pswp->fl & (SWP_MOVE | SWP_SIZE)))
1591 {
1592 //CB: todo: use result for WM_CALCVALIDRECTS
1593 //Get old client rectangle (for invalidation of frame window parts later on)
1594 //Use new window height to calculate the client area
1595 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
1596
1597 //Note: Also updates the new window rectangle
1598 win32wnd->MsgFormatFrame(&wp);
1599
1600 if(win32wnd->isOwnDC()) {
1601 setPageXForm(win32wnd, (pDCData)GpiQueryDCData(win32wnd->getOwnDC()));
1602 }
1603
1604 if(win32wnd->CanReceiveSizeMsgs())
1605 win32wnd->MsgPosChanged((LPARAM)&wp);
1606
1607 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
1608 {
1609 //redraw the frame (to prevent unnecessary client updates)
1610 BOOL redrawAll = FALSE;
1611
1612 dprintf2(("WM_WINDOWPOSCHANGED: redraw frame"));
1613 if (win32wnd->getWindowClass())
1614 {
1615 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
1616
1617 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
1618 redrawAll = TRUE;
1619 else
1620 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
1621 redrawAll = TRUE;
1622 }
1623 else redrawAll = TRUE;
1624
1625 if(win32wnd->IsMixMaxStateChanging()) {
1626 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1627 redrawAll = TRUE;
1628 }
1629
1630 if (redrawAll)
1631 {
1632 //CB: redraw all children for now
1633 // -> problems with update region if we don't do it
1634 // todo: rewrite whole handling
1635 dprintf(("PMFRAME: WM_WINDOWPOSCHANGED invalidate all"));
1636 WinInvalidateRect(hwnd,NULL,TRUE);
1637 }
1638 else
1639 {
1640 HPS hps = WinGetPS(hwnd);
1641 RECTL frame,client,arcl[4];
1642
1643 WinQueryWindowRect(hwnd,&frame);
1644
1645 //top
1646 arcl[0].xLeft = 0;
1647 arcl[0].xRight = frame.xRight;
1648 arcl[0].yBottom = rect.yTop;
1649 arcl[0].yTop = frame.yTop;
1650 //right
1651 arcl[1].xLeft = rect.xRight;
1652 arcl[1].xRight = frame.xRight;
1653 arcl[1].yBottom = 0;
1654 arcl[1].yTop = frame.yTop;
1655 //left
1656 arcl[2].xLeft = 0;
1657 arcl[2].xRight = rect.xLeft;
1658 arcl[2].yBottom = 0;
1659 arcl[2].yTop = frame.yTop;
1660 //bottom
1661 arcl[3].xLeft = 0;
1662 arcl[3].xRight = frame.xRight;
1663 arcl[3].yBottom = 0;
1664 arcl[3].yTop = rect.yBottom;
1665
1666 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
1667
1668 WinInvalidateRegion(hwnd,hrgn,FALSE);
1669 GpiDestroyRegion(hps,hrgn);
1670 WinReleasePS(hps);
1671 }
1672 }
1673 }
1674 else
1675 {
1676#endif //USE_CALCVALIDRECT
1677 if(win32wnd->CanReceiveSizeMsgs())
1678 win32wnd->MsgPosChanged((LPARAM)&wp);
1679#ifndef USE_CALCVALIDRECT
1680 }
1681#endif
1682 //PF This is the final step of PM restoration - should end up
1683 //in default handler.
1684 if (win32wnd->getOldStyle() & WS_MINIMIZE_W && pswp->fl & SWP_RESTORE)
1685 goto RunDefFrameWndProc;
1686
1687PosChangedEnd:
1688 rc = (MRESULT)FALSE;
1689 break;
1690 }
1691
1692 case WM_CALCVALIDRECTS:
1693#ifdef USE_CALCVALIDRECT
1694 {
1695 PRECTL oldRect = (PRECTL)mp1, newRect = oldRect+1;
1696 PSWP pswp = (PSWP)mp2;
1697 SWP swpOld;
1698 WINDOWPOS wp;
1699 RECTL newClientRect, oldClientRect;
1700 ULONG nccalcret;
1701// UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
1702 UINT res = 0;
1703
1704 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1705
1706 //Get old position info
1707 WinQueryWindowPos(hwnd, &swpOld);
1708
1709 if(win32wnd->getParent()) {
1710 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1711 win32wnd->getParent()->getClientRectPtr()->left,
1712 win32wnd->getParent()->getClientRectPtr()->top,
1713 hwnd);
1714 }
1715 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
1716
1717 wp.hwnd = win32wnd->getWindowHandle();
1718 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1719 {
1720 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1721 if(wndAfter) {
1722 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1723 RELEASE_WNDOBJ(wndAfter);
1724 }
1725 else wp.hwndInsertAfter = HWND_TOP_W;
1726 }
1727
1728 //Get old client rectangle
1729 mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
1730
1731 //Note: Also updates the new window rectangle
1732 nccalcret = win32wnd->MsgFormatFrame(&wp);
1733
1734 //Get new client rectangle
1735 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
1736
1737 if(nccalcret == 0) {
1738 res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
1739 }
1740 else {
1741 if(nccalcret & WVR_ALIGNTOP_W) {
1742 res |= CVR_ALIGNTOP;
1743 }
1744 else
1745 if(nccalcret & WVR_ALIGNBOTTOM_W) {
1746 res |= CVR_ALIGNBOTTOM;
1747 }
1748
1749 if(nccalcret & WVR_ALIGNLEFT_W) {
1750 res |= CVR_ALIGNLEFT;
1751 }
1752 else
1753 if(nccalcret & WVR_ALIGNRIGHT_W) {
1754 res |= CVR_ALIGNRIGHT;
1755 }
1756
1757 if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
1758 res |= CVR_REDRAW;
1759 }
1760 else
1761 if(nccalcret & WVR_VALIDRECTS_W) {
1762 //TODO:
1763 //res = 0;
1764 }
1765 }
1766 if(win32wnd->IsMixMaxStateChanging()) {
1767 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1768 res |= CVR_REDRAW;
1769 }
1770 if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
1771 oldRect->xRight -= oldClientRect.xLeft;
1772 oldRect->yBottom += oldClientRect.yBottom;
1773 newRect->xRight -= newClientRect.xLeft;
1774 newRect->yBottom += newClientRect.yBottom;
1775 }
1776 rc = res;
1777 break;
1778 }
1779#else
1780 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1781 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
1782 break;
1783#endif
1784
1785 case WM_CALCFRAMERECT:
1786 dprintf(("PMFRAME:WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
1787 rc = (MRESULT)TRUE;
1788 break;
1789
1790 case WM_QUERYCTLTYPE:
1791 // This is a frame window
1792 dprintf(("PMFRAME:WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
1793 rc = (MRESULT)CCT_FRAME;
1794 break;
1795
1796#ifdef DEBUG
1797 case WM_QUERYFOCUSCHAIN:
1798 dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x (%s) parent %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), DbgPrintQFCFlags(SHORT1FROMMP(mp1)), (mp2) ? OS2ToWin32Handle((DWORD)mp2) : 0));
1799
1800 RestoreOS2TIB();
1801 rc = pfnFrameWndProc(hwnd, msg, mp1, mp2);
1802 SetWin32TIB();
1803 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));
1804 break;
1805// goto RunDefFrameWndProc;
1806#endif
1807
1808 case WM_FOCUSCHANGE:
1809 {
1810 HWND hwndFocus = (HWND)mp1;
1811 HWND hwndLoseFocus, hwndGainFocus;
1812 USHORT usSetFocus = SHORT1FROMMP(mp2);
1813 USHORT fsFocusChange = SHORT2FROMMP(mp2);
1814
1815 //Save window that gains focus so we can determine which
1816 //process we lose activation to
1817 hwndFocusChange = (HWND)mp1;
1818
1819 dprintf(("PMFRAME:WM_FOCUSCHANGE %x %x (%x) %x %x", win32wnd->getWindowHandle(), OS2ToWin32Handle(hwndFocus), hwndFocus, usSetFocus, fsFocusChange));
1820 goto RunDefFrameWndProc;
1821 }
1822
1823#ifdef DEBUG
1824 case WM_SETFOCUS:
1825 {
1826 dprintf(("PMFRAME: WM_SETFOCUS %x %x %d -> %x", win32wnd->getWindowHandle(), hwnd, mp2, mp1));
1827 goto RunDefFrameWndProc;
1828 }
1829#endif
1830
1831 case WM_ACTIVATE:
1832 {
1833 HWND hwndTitle;
1834 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
1835
1836 dprintf(("PMFRAME: WM_ACTIVATE %x %x %x", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle((DWORD)mp2)));
1837 if (win32wnd->IsWindowCreated())
1838 {
1839 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1840 if(fOS2Look) {
1841 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1842 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, mp1, 0);
1843 }
1844 if(SHORT1FROMMP(mp1) == 0) {
1845 //deactivate
1846 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
1847 }
1848 PID pidThis, pidPartner, pidTemp;
1849 TID tidPartner;
1850 HENUM henum;
1851 HWND hwndEnum;
1852
1853 WinQueryWindowProcess(hwnd, &pidThis, NULL);
1854 WinQueryWindowProcess(hwndFocusChange, &pidPartner, &tidPartner);
1855
1856 if(pidThis != pidPartner) {
1857 //Gain or lose activation to window in other process
1858 //must send WM_ACTIVATEAPP to top-level windows
1859
1860 //Iterate over all child windows of the desktop
1861 henum = WinBeginEnumWindows(HWND_DESKTOP);
1862
1863 while(hwndEnum = WinGetNextWindow(henum))
1864 {
1865 WinQueryWindowProcess(hwndEnum, &pidTemp, NULL);
1866 if(pidTemp == pidThis)
1867 {
1868 SendMessageA(OS2ToWin32Handle(hwndEnum), WM_ACTIVATEAPP_W, (WPARAM)SHORT1FROMMP(mp1), (LPARAM)tidPartner);
1869 }
1870 }
1871 WinEndEnumWindows(henum);
1872 }
1873 if(SHORT1FROMMP(mp1)) {
1874 //activate
1875 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
1876 }
1877
1878 //CB: show owner behind the dialog
1879 if (win32wnd->IsModalDialog())
1880 {
1881 if(win32wnd->getOwner()) {
1882 Win32BaseWindow *topOwner = Win32BaseWindow::GetWindowFromHandle(win32wnd->getOwner()->GetTopParent());
1883
1884 if (topOwner) {
1885 WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
1886 RELEASE_WNDOBJ(topOwner);
1887 }
1888 }
1889 }
1890 }
1891 else
1892 {
1893 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1894 }
1895 rc = 0;
1896 break;
1897 }
1898
1899 case WM_ENABLE:
1900 dprintf(("PMFRAME: WM_ENABLE %x", hwnd));
1901 win32wnd->MsgEnable(SHORT1FROMMP(mp1));
1902 break;
1903
1904 case WM_SHOW:
1905 dprintf(("PMFRAME: WM_SHOW %x %d", hwnd, mp1));
1906 //show client window
1907 WinShowWindow(win32wnd->getOS2WindowHandle(), (BOOL)mp1);
1908 break;
1909
1910 case WM_QUERYTRACKINFO:
1911 {
1912 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
1913
1914 dprintf(("PMFRAME:WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
1915 trackInfo->cxBorder = 4;
1916 trackInfo->cyBorder = 4;
1917 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
1918 rc = (MRESULT)TRUE;
1919 break;
1920 }
1921
1922 case WM_QUERYBORDERSIZE:
1923 {
1924 PWPOINT size = (PWPOINT)mp1;
1925
1926 dprintf(("PMFRAME:WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
1927
1928 size->x = 0;
1929 size->y = 0;
1930 rc = (MRESULT)TRUE;
1931 break;
1932 }
1933
1934#ifdef DEBUG
1935 case WM_QUERYFRAMEINFO:
1936 dprintf(("PMFRAME:WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
1937 goto RunDefFrameWndProc;
1938#endif
1939
1940 case WM_FORMATFRAME:
1941 dprintf(("PMFRAME:WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
1942 break;
1943
1944 case WM_ADJUSTFRAMEPOS:
1945 {
1946 PSWP pswp = (PSWP)mp1;
1947
1948 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));
1949 //hack alert: the PM frame control changes the z-order of a child window
1950 // if it receives focus after a window has been destroyed
1951 // We can't let this happen as this messes up assumptions
1952 // elsewhere (e.g. GetNextDlgGroupItem)
1953 // By returning 0 here, we prevent the default frame handler
1954 // from messing things up. (one example is a group of radio buttons)
1955 //NOTE: We really need to get rid of frame & client windows for each
1956 // win32 window
1957 if(pswp->fl == SWP_FOCUSACTIVATE && win32wnd->isChild()) {
1958 rc = 0;
1959 break;
1960 }
1961 //hack alert: as we return zero as border size (check handler) we need
1962 //to do adjustments here as well or PM will calculate it for us and
1963 //result will be illegal. Btw we do not honour PM border size settings
1964 //and never will. I was unable to figure out why only X coordinate
1965 //is being broken but not Y as well.
1966
1967 if ((pswp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1968 {
1969 RECT rect;
1970 rect.left = rect.top = rect.right = rect.bottom = 0;
1971 win32wnd->AdjustMaximizedRect(&rect);
1972
1973 pswp->x += rect.left;
1974 }
1975 goto RunDefFrameWndProc;
1976 }
1977
1978#ifdef DEBUG
1979 case WM_OWNERPOSCHANGE:
1980 {
1981 PSWP pswp = (PSWP)mp1;
1982
1983 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));
1984 goto RunDefFrameWndProc;
1985 }
1986#endif
1987
1988 case WM_MINMAXFRAME:
1989 {
1990 PSWP swp = (PSWP)mp1;
1991
1992 if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
1993
1994 dprintf(("PMFRAME:WM_MINMAXFRAME %x",hwnd));
1995 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1996 {
1997 // MDI frame windows are not common PM windows so we need to
1998 // drop-out WHOLE chain of WM_X commands with SWP_MAXIMIZE flag
1999 // finally last WM_WINDOWPOSCHANGED will take care of maximization
2000
2001 if (win32wnd->getExStyle() & WS_EX_MDICHILD_W) {
2002 rc = 0;
2003 break;
2004 }
2005
2006 RECT rect;
2007 rect.left = rect.top = rect.right = rect.bottom = 0;
2008 win32wnd->AdjustMaximizedRect(&rect);
2009
2010 swp->x += rect.left;
2011 swp->cx += rect.right-rect.left;
2012 swp->y -= rect.bottom;
2013 swp->cy += rect.bottom-rect.top;
2014
2015 win32wnd->ShowWindow(SW_RESTORE_W);
2016 }
2017 else
2018 if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
2019 {
2020 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
2021 }
2022 else
2023 if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
2024 {
2025 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
2026 }
2027 goto RunDefWndProc;
2028 }
2029
2030#ifdef DEBUG
2031 case WM_UPDATEFRAME:
2032 dprintf(("PMFRAME:WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
2033 goto RunDefFrameWndProc;
2034#endif
2035
2036 case WM_TRACKFRAME:
2037 dprintf(("PMFRAME: WM_TRACKFRAME %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
2038 if(fOS2Look) {//sent by titlebar control
2039 Frame_SysCommandSizeMove(win32wnd, SC_MOVE_W+HTCAPTION_W);
2040 }
2041 rc = 0;
2042 break;
2043
2044 case WM_SYSCOMMAND:
2045 dprintf(("PMFRAME: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
2046 if (fOS2Look == OS2_APPEARANCE_SYSMENU && mp1 == (MPARAM)OSSC_SYSMENU)
2047 goto RunDefFrameWndProc;
2048
2049 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
2050 RELEASE_WNDOBJ(win32wnd);
2051 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
2052 }
2053 if(win32wnd)
2054 win32wnd->DispatchMsgA(pWinMsg);
2055 break;
2056
2057#ifdef DEBUG
2058 case WM_DDE_INITIATE:
2059 case WM_DDE_INITIATEACK:
2060 case WM_DDE_REQUEST:
2061 case WM_DDE_ACK:
2062 case WM_DDE_DATA:
2063 case WM_DDE_ADVISE:
2064 case WM_DDE_UNADVISE:
2065 case WM_DDE_POKE:
2066 case WM_DDE_EXECUTE:
2067 case WM_DDE_TERMINATE:
2068 dprintf(("PMFRAME: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
2069 break;
2070#endif
2071
2072 default:
2073 goto RunDefFrameWndProc;
2074 }
2075 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2076 RestoreOS2TIB();
2077
2078#ifdef DEBUG
2079 dbg_ThreadPopCall();
2080#endif
2081 return (MRESULT)rc;
2082
2083RunDefFrameWndProc:
2084 dprintf2(("RunDefFrameWndProc"));
2085 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2086 RestoreOS2TIB();
2087
2088#ifdef DEBUG
2089 dbg_ThreadPopCall();
2090#endif
2091 return pfnFrameWndProc(hwnd, msg, mp1, mp2);
2092
2093RunDefWndProc:
2094 dprintf2(("RunDefWndProc"));
2095 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2096 RestoreOS2TIB();
2097 //calling WinDefWindowProc here breaks Opera hotlist window (WM_ADJUSTWINDOWPOS)
2098// return pfnFrameWndProc(hwnd, msg, mp1, mp2);
2099
2100#ifdef DEBUG
2101 dbg_ThreadPopCall();
2102#endif
2103 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
2104}
2105//******************************************************************************
2106//******************************************************************************
2107MRESULT EXPENTRY Win32FakeWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
2108{
2109 PFNWP pfnOldWindowProc;
2110 Win32BaseWindow *win32wnd, *win32wndchild;
2111 TEB *teb;
2112 MRESULT rc = 0;
2113
2114 //Restore our FS selector
2115 SetWin32TIB();
2116
2117 win32wnd = Win32FakeWindow::GetWindowFromOS2Handle(hwnd);
2118 if(win32wnd == NULL) {
2119 DebugInt3();
2120 goto RunDefWndProc;
2121 }
2122
2123 pfnOldWindowProc = (PFNWP)win32wnd->getOldPMWindowProc();
2124 if(pfnOldWindowProc == NULL) {
2125 DebugInt3();
2126 goto RunDefWndProc;
2127 }
2128
2129 RestoreOS2TIB();
2130 rc = pfnOldWindowProc(hwnd, msg, mp1, mp2);
2131 SetWin32TIB();
2132 switch(msg) {
2133 case WM_WINDOWPOSCHANGED:
2134 {
2135 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
2136 SWP swpOld = *(pswp + 1);
2137 WINDOWPOS wp;
2138
2139 if(win32wnd->getParent()) {
2140 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
2141 hwnd);
2142 }
2143 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
2144
2145 win32wnd->SetWindowPos(wp.hwndInsertAfter, wp.x, wp.y, wp.cx, wp.cy, wp.flags);
2146 break;
2147 }
2148
2149 }
2150 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
2151 RestoreOS2TIB();
2152 return rc;
2153
2154RunDefWndProc:
2155 RestoreOS2TIB();
2156 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
2157}
2158//******************************************************************************
2159// PMWinSubclassFakeWindow
2160//
2161// Subclass a fake window (converted PM window)
2162//
2163// Parameters
2164//
2165// HWND hwndOS2 - PM handle of fake window
2166//
2167// Returns
2168// NULL - Failure
2169// else - Old PM window procedure
2170//
2171//******************************************************************************
2172PVOID PMWinSubclassFakeWindow(HWND hwndOS2)
2173{
2174 return WinSubclassWindow(hwndOS2, Win32FakeWindowProc);
2175}
2176//******************************************************************************
2177//******************************************************************************
2178void FrameSetFocus(HWND hwnd)
2179{
2180 HWND hwndFocusSave = WinQueryWindowULong(hwnd, QWL_HWNDFOCUSSAVE);
2181 if(!WinIsWindow(hab, hwndFocusSave)) {
2182 hwndFocusSave = WinWindowFromID(hwnd, FID_CLIENT);
2183 WinSetWindowULong(hwnd, QWL_HWNDFOCUSSAVE, hwndFocusSave);
2184 }
2185 dprintf(("FrameSetFocus: hwndFocusSave %x %x", OS2ToWin32Handle(hwndFocusSave), hwndFocusSave));
2186 WinSetFocus(HWND_DESKTOP, hwndFocusSave);
2187
2188 ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
2189 ulFrameFlags &= ~FF_NOACTIVATESWP;
2190 WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags);
2191}
2192//******************************************************************************
2193//******************************************************************************
2194void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG idNew,
2195 HBITMAP hbmNew)
2196{
2197 MENUITEM mi;
2198
2199 if (!hwndMenu)
2200 return;
2201
2202 WinEnableWindowUpdate(hwndMenu, FALSE);
2203
2204 if (WinSendMsg(hwndMenu, MM_QUERYITEM, MPFROM2SHORT(idOld, TRUE), MPFROMP(&mi)))
2205 {
2206 WinSendMsg(hwndMenu, MM_REMOVEITEM, (MPARAM)idOld, 0);
2207 mi.afStyle = MIS_BITMAP | MIS_SYSCOMMAND;
2208 mi.afAttribute = 0;
2209 mi.hwndSubMenu = 0;
2210 mi.id = idNew;
2211 mi.hItem = (ULONG)hbmNew;
2212 WinSendMsg(hwndMenu, MM_INSERTITEM, (MPARAM)&mi, 0);
2213 }
2214 else
2215 dprintf(("WARNING: FrameReplaceMenuItem control %x not found",idOld));
2216
2217 WinEnableWindowUpdate(hwndMenu, TRUE);
2218
2219 WinInvalidateRect(hwndMenu, NULL, TRUE);
2220}
2221//******************************************************************************
2222//******************************************************************************
2223static char *PMDragExtractFiles(PDRAGINFO pDragInfo, ULONG *pcItems, ULONG *pulBytes)
2224{
2225 PDRAGITEM pDragItem;
2226 int i, cItems;
2227 BOOL ret;
2228 char szFileName[CCHMAXPATH];
2229 char szContainerName[CCHMAXPATH];
2230 ULONG ulBytes;
2231 char *pszCurFile = NULL;
2232
2233 /* Get access to the DRAGINFO data structure */
2234 if(!DrgAccessDraginfo(pDragInfo)) {
2235 return NULL;
2236 }
2237
2238 cItems = DrgQueryDragitemCount(pDragInfo);
2239
2240 //computer memory required to hold all filenames
2241 int bufsize = 0;
2242 for (i = 0; i < cItems; i++) {
2243 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
2244
2245 bufsize += DrgQueryStrNameLen(pDragItem->hstrContainerName) + DrgQueryStrNameLen(pDragItem->hstrSourceName);
2246 bufsize++; //0 terminator
2247 bufsize++; //+ potential missing backslash
2248 }
2249 bufsize++; //extra 0 terminator
2250 char *pszFiles = (char *)malloc(bufsize);
2251 if(pszFiles == NULL) {
2252 dprintf(("Out of memory!!"));
2253 DebugInt3();
2254 goto failure;
2255 }
2256 memset(pszFiles, 0, bufsize);
2257
2258 pszCurFile = pszFiles;
2259
2260 //copy all filenames
2261 for (i = 0; i < cItems; i++) {
2262 char *pszTemp = pszCurFile;
2263
2264 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
2265
2266 ulBytes = DrgQueryStrNameLen(pDragItem->hstrContainerName);
2267 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
2268 ulBytes, pszCurFile);
2269 if(pszCurFile[ulBytes-1] != '\\') {
2270 pszCurFile[ulBytes] = '\\';
2271 pszCurFile++;
2272 }
2273 pszCurFile += ulBytes;
2274
2275 ulBytes = DrgQueryStrNameLen(pDragItem->hstrSourceName);
2276 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
2277 ulBytes+1, pszCurFile);
2278 pszCurFile += ulBytes + 1; //+ terminator
2279
2280 dprintf(("dropped file %s", pszTemp));
2281 }
2282
2283 /* Release the draginfo data structure */
2284 DrgFreeDraginfo(pDragInfo);
2285
2286 *pulBytes = bufsize;
2287 *pcItems = cItems;
2288
2289 return pszFiles;
2290
2291failure:
2292 /* Release the draginfo data structure */
2293 DrgFreeDraginfo(pDragInfo);
2294 if(pszFiles) {
2295 free(pszFiles);
2296 }
2297 return NULL;
2298}
2299//******************************************************************************
2300//******************************************************************************
2301static BOOL PMDragValidate(PDRAGINFO pDragInfo)
2302{
2303 PDRAGITEM pDragItem;
2304 ULONG ulBytes;
2305 int i, cItems;
2306 BOOL ret;
2307 char szFileName[CCHMAXPATH];
2308 char szContainerName[CCHMAXPATH];
2309 USHORT usOp = DO_MOVE;
2310
2311 /* Get access to the DRAGINFO data structure */
2312 if(!DrgAccessDraginfo(pDragInfo)) {
2313 return FALSE;
2314 }
2315
2316 /* Can we accept this drop? */
2317 switch (pDragInfo->usOperation) {
2318 /* Return DOR_NODROPOP if current operation */
2319 /* is link or unknown */
2320 case DO_LINK:
2321 case DO_COPY:
2322 case DO_UNKNOWN:
2323 goto failure;
2324
2325 /* Our default operation is Move */
2326 case DO_MOVE:
2327 case DO_DEFAULT:
2328 pDragItem = DrgQueryDragitemPtr(pDragInfo, 0);
2329 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
2330 sizeof(szContainerName),
2331 szContainerName);
2332 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
2333 sizeof(szFileName),
2334 szFileName);
2335 if (!ulBytes) {
2336 goto failure;
2337 }
2338
2339 dprintf(("dropped file %s%s", szContainerName, szFileName));
2340 break;
2341 }
2342
2343 cItems = DrgQueryDragitemCount(pDragInfo);
2344
2345 /* Now, we need to look at each item in turn */
2346 for (i = 0; i < cItems; i++) {
2347 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
2348
2349 /* Make sure we can move for a Move request */
2350 if (!((pDragItem->fsSupportedOps & DO_MOVEABLE) &&
2351 (usOp == (USHORT)DO_MOVE)))
2352 {
2353 dprintf(("item %d not accepted", i));
2354 goto failure;
2355 }
2356 }
2357 /* Release the draginfo data structure */
2358 DrgFreeDraginfo(pDragInfo);
2359 return TRUE;
2360
2361failure:
2362 DrgFreeDraginfo(pDragInfo);
2363 return FALSE;
2364}
2365
2366// @@PF Three funcs to override std class names we use in Odin
2367//******************************************************************************
2368//******************************************************************************
2369void WIN32API SetCustomCDClassName(LPSTR pszCDClassName)
2370{
2371 strcpy(WIN32_CDCLASS, pszCDClassName);
2372}
2373//******************************************************************************
2374//******************************************************************************
2375void WIN32API SetCustomStdClassName(LPSTR pszStdClassName)
2376{
2377 strcpy(WIN32_STDCLASS, pszStdClassName);
2378}
2379//******************************************************************************
2380//******************************************************************************
2381void WIN32API SetCustomStdFrameClassName(LPSTR pszStdFrameClassName)
2382{
2383 strcpy(WIN32_STDFRAMECLASS, pszStdFrameClassName);
2384}
2385//******************************************************************************
2386//******************************************************************************
2387
2388#ifdef DEBUG
2389static char *DbgGetStringSWPFlags(ULONG flags)
2390{
2391 static char szSWPFlags[512];
2392
2393 szSWPFlags[0] = 0;
2394
2395 if(flags & SWP_SIZE) {
2396 strcat(szSWPFlags, "SWP_SIZE ");
2397 }
2398 if(flags & SWP_MOVE) {
2399 strcat(szSWPFlags, "SWP_MOVE ");
2400 }
2401 if(flags & SWP_ZORDER) {
2402 strcat(szSWPFlags, "SWP_ZORDER ");
2403 }
2404 if(flags & SWP_SHOW) {
2405 strcat(szSWPFlags, "SWP_SHOW ");
2406 }
2407 if(flags & SWP_HIDE) {
2408 strcat(szSWPFlags, "SWP_HIDE ");
2409 }
2410 if(flags & SWP_NOREDRAW) {
2411 strcat(szSWPFlags, "SWP_NOREDRAW ");
2412 }
2413 if(flags & SWP_NOADJUST) {
2414 strcat(szSWPFlags, "SWP_NOADJUST ");
2415 }
2416 if(flags & SWP_ACTIVATE) {
2417 strcat(szSWPFlags, "SWP_ACTIVATE ");
2418 }
2419 if(flags & SWP_DEACTIVATE) {
2420 strcat(szSWPFlags, "SWP_DEACTIVATE ");
2421 }
2422 if(flags & SWP_EXTSTATECHANGE) {
2423 strcat(szSWPFlags, "SWP_EXTSTATECHANGE ");
2424 }
2425 if(flags & SWP_MINIMIZE) {
2426 strcat(szSWPFlags, "SWP_MINIMIZE ");
2427 }
2428 if(flags & SWP_MAXIMIZE) {
2429 strcat(szSWPFlags, "SWP_MAXIMIZE ");
2430 }
2431 if(flags & SWP_RESTORE) {
2432 strcat(szSWPFlags, "SWP_RESTORE ");
2433 }
2434 if(flags & SWP_FOCUSACTIVATE) {
2435 strcat(szSWPFlags, "SWP_FOCUSACTIVATE ");
2436 }
2437 if(flags & SWP_FOCUSDEACTIVATE) {
2438 strcat(szSWPFlags, "SWP_FOCUSDEACTIVATE ");
2439 }
2440 if(flags & SWP_NOAUTOCLOSE) {
2441 strcat(szSWPFlags, "SWP_NOAUTOCLOSE ");
2442 }
2443 return szSWPFlags;
2444}
2445static char *DbgPrintQFCFlags(ULONG flags)
2446{
2447 static char szQFCFlags[64];
2448
2449 szQFCFlags[0] = 0;
2450
2451 if(flags & QFC_NEXTINCHAIN) {
2452 strcat(szQFCFlags, "QFC_NEXTINCHAIN");
2453 }
2454 else
2455 if(flags & QFC_ACTIVE) {
2456 strcat(szQFCFlags, "QFC_ACTIVE");
2457 }
2458 else
2459 if(flags & QFC_FRAME) {
2460 strcat(szQFCFlags, "QFC_FRAME");
2461 }
2462 else
2463 if(flags & QFC_SELECTACTIVE) {
2464 strcat(szQFCFlags, "QFC_SELECTACTIVE");
2465 }
2466 else
2467 if(flags & QFC_PARTOFCHAIN) {
2468 strcat(szQFCFlags, "QFC_PARTOFCHAIN");
2469 }
2470
2471 return szQFCFlags;
2472}
2473#endif
Note: See TracBrowser for help on using the repository browser.