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

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

disabled drag 'n drop for now

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