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

Last change on this file since 8555 was 8555, checked in by sandervl, 23 years ago

Drag and drop fixes

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