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

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

added ole drag and drop (wps -> odin app) support

File size: 71.1 KB
Line 
1/* $Id: pmwindow.cpp,v 1.176 2002-06-02 19:34:28 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 rc = (MRFROM2SHORT(DOR_DROP, DO_MOVE));
867 free(pszFiles);
868 }
869 else {
870 rc = (MRFROM2SHORT (DOR_NEVERDROP, 0));
871 }
872 break;
873 }
874
875 case WM_DDE_INITIATE:
876 case WM_DDE_INITIATEACK:
877 case WM_DDE_REQUEST:
878 case WM_DDE_ACK:
879 case WM_DDE_DATA:
880 case WM_DDE_ADVISE:
881 case WM_DDE_UNADVISE:
882 case WM_DDE_POKE:
883 case WM_DDE_EXECUTE:
884 case WM_DDE_TERMINATE:
885 dprintf(("OS2: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
886 goto RunDefWndProc;
887
888 case WM_INITMENU:
889 case WM_MENUSELECT:
890 case WM_MENUEND:
891 case WM_NEXTMENU:
892 case WM_SYSCOLORCHANGE:
893 case WM_SYSVALUECHANGED:
894 case WM_SETSELECTION:
895 case WM_PPAINT:
896 case WM_PSETFOCUS:
897 case WM_PSYSCOLORCHANGE:
898 case WM_PSIZE:
899 case WM_PACTIVATE:
900 case WM_PCONTROL:
901 case WM_HELP:
902 case WM_APPTERMINATENOTIFY:
903 case WM_PRESPARAMCHANGED:
904 case WM_DRAWITEM:
905 case WM_MEASUREITEM:
906 case WM_CONTROLPOINTER:
907 case WM_QUERYDLGCODE:
908 case WM_SUBSTITUTESTRING:
909 case WM_MATCHMNEMONIC:
910 case WM_SAVEAPPLICATION:
911 case WM_SEMANTICEVENT:
912 default:
913 dprintf2(("OS2: RunDefWndProc hwnd %x msg %x mp1 %x mp2 %x", hwnd, msg, mp1, mp2));
914 goto RunDefWndProc;
915 }
916 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
917 RestoreOS2TIB();
918 return (MRESULT)rc;
919
920RunDefWndProc:
921// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
922 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
923 RestoreOS2TIB();
924 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
925} /* End of Win32WindowProc */
926//******************************************************************************
927//******************************************************************************
928MRESULT EXPENTRY Win32FrameWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
929{
930 POSTMSG_PACKET *postmsg;
931 OSLIBPOINT point, ClientPoint;
932 Win32BaseWindow *win32wnd;
933 TEB *teb;
934 MRESULT rc = 0;
935 MSG winMsg, *pWinMsg;
936
937 //Restore our FS selector
938 SetWin32TIB();
939
940 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- BEGIN
941 teb = GetThreadTEB();
942 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
943
944 if(!teb || (msg != WM_CREATE && win32wnd == NULL)) {
945 dprintf(("PMFRAME: Invalid win32wnd pointer for window %x msg %x", hwnd, msg));
946 goto RunDefFrameWndProc;
947 }
948//// if(teb->o.odin.fIgnoreMsgs) {
949//// goto RunDefWndProc;
950//// }
951
952 if((teb->o.odin.msgstate & 1) == 0)
953 {//message that was sent directly to our window proc handler; translate it here
954 QMSG qmsg;
955
956 qmsg.msg = msg;
957 qmsg.hwnd = hwnd;
958 qmsg.mp1 = mp1;
959 qmsg.mp2 = mp2;
960 qmsg.time = WinQueryMsgTime(teb->o.odin.hab);
961 WinQueryMsgPos(teb->o.odin.hab, &qmsg.ptl);
962 qmsg.reserved = 0;
963
964 if(OS2ToWinMsgTranslate((PVOID)teb, &qmsg, &winMsg, FALSE, MSG_REMOVE) == FALSE)
965 {//message was not translated
966 memset(&winMsg, 0, sizeof(MSG));
967 }
968 pWinMsg = &winMsg;
969 }
970 else {
971 pWinMsg = &teb->o.odin.msg;
972 teb->o.odin.msgstate++;
973 }
974 //NOTE-------------->>>>>> If this is changed, also change Win32WindowProc!! <<<<<<<<<<<-------------------- END
975
976 switch( msg )
977 {
978 case WM_CREATE:
979 {
980 //WM_CREATE handled during client window creation
981 dprintf(("PMFRAME: WM_CREATE %x", hwnd));
982 goto RunDefFrameWndProc;
983 }
984
985#ifdef DEBUG
986 case WM_CLOSE:
987 {
988 dprintf(("PMFRAME: WM_CLOSE %x", hwnd));
989 goto RunDefFrameWndProc;
990 }
991#endif
992
993 case WM_PAINT:
994 {
995 RECTL rectl;
996
997 HPS hps = WinBeginPaint(hwnd, NULL, &rectl);
998 dprintf(("PMFRAME: WM_PAINT %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
999
1000 if(win32wnd->IsWindowCreated() && (rectl.xLeft != rectl.xRight &&
1001 rectl.yBottom != rectl.yTop))
1002 {
1003 PRECT pClient = win32wnd->getClientRectPtr();
1004 PRECT pWindow = win32wnd->getWindowRect();
1005
1006 if(!(pClient->left == 0 && pClient->top == 0 &&
1007 win32wnd->getClientHeight() == win32wnd->getWindowHeight() &&
1008 win32wnd->getClientWidth() == win32wnd->getWindowWidth()))
1009 {
1010 RECT rectUpdate;
1011
1012 mapOS2ToWin32Rect(win32wnd->getWindowHeight(), (PRECTLOS2)&rectl, &rectUpdate);
1013 win32wnd->MsgNCPaint(&rectUpdate);
1014 }
1015 }
1016 WinEndPaint(hps);
1017 break;
1018 }
1019
1020 case WM_ERASEBACKGROUND:
1021 {
1022 dprintf(("PMFRAME:WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
1023 rc = (MRESULT)FALSE;
1024 break;
1025 }
1026
1027 //**************************************************************************
1028 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
1029 //**************************************************************************
1030
1031 case WM_BUTTON1DOWN:
1032 case WM_BUTTON1UP:
1033 case WM_BUTTON1DBLCLK:
1034 case WM_BUTTON2DOWN:
1035 case WM_BUTTON2UP:
1036 case WM_BUTTON2DBLCLK:
1037 case WM_BUTTON3DOWN:
1038 case WM_BUTTON3UP:
1039 case WM_BUTTON3DBLCLK:
1040 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
1041 RELEASE_WNDOBJ(win32wnd);
1042 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
1043 }
1044 if(win32wnd)
1045 win32wnd->MsgButton(pWinMsg);
1046
1047 rc = (MRESULT)TRUE;
1048 break;
1049
1050 case WM_BUTTON2MOTIONSTART:
1051 case WM_BUTTON2MOTIONEND:
1052 case WM_BUTTON2CLICK:
1053 case WM_BUTTON1MOTIONSTART:
1054 case WM_BUTTON1MOTIONEND:
1055 case WM_BUTTON1CLICK:
1056 case WM_BUTTON3MOTIONSTART:
1057 case WM_BUTTON3MOTIONEND:
1058 case WM_BUTTON3CLICK:
1059 rc = (MRESULT)TRUE;
1060 break;
1061
1062 case WM_MOUSEMOVE:
1063 {
1064 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
1065 RELEASE_WNDOBJ(win32wnd);
1066 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
1067 }
1068 if(win32wnd)
1069 win32wnd->MsgMouseMove(pWinMsg);
1070 break;
1071 }
1072
1073 case WM_ADJUSTWINDOWPOS:
1074 {
1075 PSWP pswp = (PSWP)mp1;
1076 SWP swpOld;
1077 WINDOWPOS wp,wpOld;
1078 ULONG ulFlags;
1079 ULONG ret = 0;
1080 HWND hParent = NULLHANDLE, hwndAfter;
1081
1082 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));
1083
1084 ulFlags = pswp->fl;
1085
1086 if(win32wnd->IsParentChanging()) {
1087 rc = 0;
1088 break;
1089 }
1090
1091 //@@PF all commands from minimized window viewer or from Ctrl-Esc
1092 //are 'pure' and should be handled only by DeFrameProc - this is weird
1093 //but without them we will not have results. Pure = plain flag of restore/minimize/maximize
1094 if((pswp->fl == SWP_MINIMIZE) || (pswp->fl & SWP_RESTORE)) {
1095 // note the purity of SWP no other SWP_FLAGS allowed
1096 goto RunDefFrameWndProc;
1097 }
1098
1099 if(pswp->fl & SWP_NOADJUST) {
1100 //ignore weird messages (TODO: why are they sent?)
1101 dprintf(("WARNING: WM_ADJUSTWINDOWPOS with SWP_NOADJUST flag!!"));
1102 break;
1103 }
1104 if ((pswp->fl == SWP_FOCUSACTIVATE) || (pswp->fl == SWP_FOCUSDEACTIVATE))
1105 {
1106 dprintf(("Pure focus flags are not sent to win32 windows"));
1107 goto RunDefFrameWndProc;
1108 }
1109
1110 //CB: show dialog in front of owner
1111 if (win32wnd->IsModalDialogOwner())
1112 {
1113 dprintf(("win32wnd->IsModalDialogOwner %x", win32wnd->getWindowHandle()));
1114 pswp->fl |= SWP_ZORDER;
1115 pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
1116 if (pswp->fl & SWP_ACTIVATE)
1117 {
1118 pswp->fl &= ~SWP_ACTIVATE;
1119 WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
1120 }
1121 }
1122
1123 if(!win32wnd->CanReceiveSizeMsgs())
1124 break;
1125
1126 WinQueryWindowPos(hwnd, &swpOld);
1127 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
1128 if (win32wnd->isChild()) {
1129 if(win32wnd->getParent()) {
1130 hParent = win32wnd->getParent()->getOS2WindowHandle();
1131 }
1132 else goto RunDefFrameWndProc;
1133 }
1134 }
1135 hwndAfter = pswp->hwndInsertBehind;
1136 if(win32wnd->getParent()) {
1137 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(), hwnd);
1138 }
1139 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1140
1141 wp.hwnd = win32wnd->getWindowHandle();
1142 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1143 {
1144 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1145 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
1146 if(wndAfter) {
1147 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1148 RELEASE_WNDOBJ(wndAfter);
1149 }
1150 else wp.hwndInsertAfter = HWND_TOP_W;
1151 }
1152
1153 wpOld = wp;
1154 win32wnd->MsgPosChanging((LPARAM)&wp);
1155
1156 if(win32wnd->getOldStyle() != win32wnd->getStyle())
1157 {
1158 OSLibSetWindowStyle(win32wnd->getOS2FrameWindowHandle(), win32wnd->getOS2WindowHandle(), win32wnd->getStyle(), win32wnd->getExStyle());
1159 if(fOS2Look) {
1160 DWORD dwOldStyle = win32wnd->getOldStyle();
1161 DWORD dwStyle = win32wnd->getStyle();
1162
1163 win32wnd->setOldStyle(dwStyle);
1164 if((dwOldStyle & WS_MINIMIZE_W) && !(dwStyle & WS_MINIMIZE_W)) {
1165 //SC_RESTORE -> SC_MINIMIZE
1166 dprintf(("%x -> SC_RESTORE -> SC_MINIMIZE", win32wnd->getWindowHandle()));
1167 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_RESTORE, SC_MINIMIZE, hbmFrameMenu[0]);
1168 if(dwStyle & WS_MAXIMIZE_W) {
1169 //SC_MAXIMIZE -> SC_RESTORE
1170 dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
1171 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[2]);
1172 }
1173 }
1174 else
1175 if((dwOldStyle & WS_MAXIMIZE_W) && !(dwStyle & WS_MAXIMIZE_W)) {
1176 //SC_RESTORE -> SC_MAXIMIZE
1177 dprintf(("%x -> SC_RESTORE -> SC_MAXIMIZE", win32wnd->getWindowHandle()));
1178 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_RESTORE, SC_MAXIMIZE, hbmFrameMenu[1]);
1179 }
1180 else
1181 if(!(dwOldStyle & WS_MINIMIZE_W) && (dwStyle & WS_MINIMIZE_W)) {
1182 //SC_MINIMIZE -> SC_RESTORE
1183 dprintf(("%x -> SC_MINIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
1184 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), 0, SC_MINIMIZE, SC_RESTORE, hbmFrameMenu[2]);
1185 }
1186 else
1187 if(!(dwOldStyle & WS_MAXIMIZE_W) && (dwStyle & WS_MAXIMIZE_W)) {
1188 //SC_MAXIMIZE -> SC_RESTORE
1189 dprintf(("%x -> SC_MAXIMIZE -> SC_RESTORE", win32wnd->getWindowHandle()));
1190 FrameReplaceMenuItem(WinWindowFromID(hwnd, FID_MINMAX), MIT_END, SC_MAXIMIZE, SC_RESTORE, hbmFrameMenu[2]);
1191 }
1192 }
1193 }
1194
1195 if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
1196 (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
1197 {
1198 ULONG flags = pswp->fl; //make a backup copy; OSLibMapWINDOWPOStoSWP will modify it
1199
1200 dprintf(("PMFRAME:WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
1201 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
1202
1203 if(win32wnd->getParent()) {
1204 OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getClientHeight(),
1205 hwnd);
1206 }
1207 else OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1208
1209 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
1210
1211 //OSLibMapWINDOWPOStoSWP can add flags, but we must not let it remove flags!
1212 if(pswp->fl & SWP_SIZE)
1213 flags |= SWP_SIZE;
1214
1215 if(pswp->fl & SWP_MOVE)
1216 flags |= SWP_MOVE;
1217
1218 pswp->fl = flags; //restore flags
1219
1220 pswp->fl |= SWP_NOADJUST;
1221 pswp->hwndInsertBehind = hwndAfter;
1222 pswp->hwnd = hwnd;
1223
1224 ret = 0xf;
1225 }
1226adjustend:
1227 //The next part needs to be done for top-level windows only
1228 if(!((win32wnd->getStyle() & (WS_POPUP_W|WS_CHILD_W)) == WS_CHILD_W))
1229 {
1230 //Setting these flags is necessary to avoid activation/focus problems
1231 if(ulFlags & SWP_DEACTIVATE) {
1232 ret |= AWP_DEACTIVATE;
1233 }
1234 if(ulFlags & SWP_ACTIVATE)
1235 {
1236 if(ulFlags & SWP_ZORDER) {
1237 dprintf(("Set FF_NOACTIVATESWP"));
1238 ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
1239 WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags | FF_NOACTIVATESWP);
1240 }
1241
1242 if(!(ulFlags & SWP_SHOW))
1243 {
1244 ret |= AWP_ACTIVATE;
1245 }
1246 else
1247 {
1248 FrameSetFocus(hwnd);
1249 }
1250 }
1251 }
1252 else {
1253 if(ulFlags & (SWP_ACTIVATE|SWP_FOCUSACTIVATE))
1254 {
1255 win32wnd->MsgChildActivate(TRUE);
1256 if(fOS2Look) {
1257 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1258 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, (MPARAM)1, 0);
1259 }
1260 }
1261 else
1262 if(ulFlags & (SWP_DEACTIVATE|SWP_FOCUSDEACTIVATE))
1263 {
1264 win32wnd->MsgChildActivate(FALSE);
1265 if(fOS2Look) {
1266 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1267 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, 0, 0);
1268 }
1269 }
1270 }
1271 dprintf(("WM_ADJUSTWINDOWPOS ret %x flags %x", ret, WinQueryWindowUShort(hwnd, QWS_FLAGS)));
1272 rc = (MRESULT)ret;
1273 break;
1274 }
1275
1276 case WM_WINDOWPOSCHANGED:
1277 {
1278 PSWP pswp = (PSWP)mp1,pswpOld = pswp+1;
1279 SWP swpOld = *(pswp + 1);
1280 WINDOWPOS wp;
1281 ULONG flAfp = (ULONG)mp2;
1282 HWND hParent = NULLHANDLE;
1283 RECTL rect;
1284
1285 dprintf(("PMFRAME:WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
1286 if(win32wnd->IsParentChanging()) {
1287 goto PosChangedEnd;
1288 }
1289
1290 //SvL: When a window is made visible, then we don't receive a
1291 // WM_VRNENABLED message (for some weird reason)
1292 if(pswp->fl & SWP_SHOW) {
1293 win32wnd->callVisibleRgnNotifyProc(TRUE);
1294 }
1295 else
1296 if(pswp->fl & SWP_HIDE) {
1297 win32wnd->callVisibleRgnNotifyProc(FALSE);
1298 }
1299
1300 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
1301 {
1302 if(pswp->fl & SWP_RESTORE && win32wnd->getStyle() & WS_MINIMIZE_W) {
1303 dprintf(("Restoring minimized window %x", win32wnd->getWindowHandle()));
1304 win32wnd->ShowWindow(SW_RESTORE_W);
1305 }
1306 if(pswp->fl & SWP_SHOW) {
1307 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
1308 }
1309 else
1310 if(pswp->fl & SWP_HIDE) {
1311 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
1312 }
1313 //MUST call the old frame window proc!
1314 goto RunDefFrameWndProc;
1315 }
1316
1317 if(pswp->fl & (SWP_MOVE | SWP_SIZE))
1318 {
1319 if(win32wnd->isChild())
1320 {
1321 if(win32wnd->getParent()) {
1322 hParent = win32wnd->getParent()->getOS2WindowHandle();
1323 }
1324 else goto PosChangedEnd; //parent has just been destroyed
1325 }
1326 }
1327
1328
1329 if(win32wnd->getParent()) {
1330 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1331 hwnd);
1332 }
1333 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), hwnd);
1334
1335 wp.hwnd = win32wnd->getWindowHandle();
1336 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1337 {
1338 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1339 dprintf2(("SWP_ZORDER: %x %x", pswp->hwndInsertBehind, (wndAfter) ? wndAfter->getWindowHandle() : 0));
1340 if(wndAfter) {
1341 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1342 RELEASE_WNDOBJ(wndAfter);
1343 }
1344 else wp.hwndInsertAfter = HWND_TOP_W;
1345 }
1346
1347 if(pswp->fl & SWP_SHOW) {
1348 WinShowWindow(win32wnd->getOS2WindowHandle(), 1);
1349 }
1350 else
1351 if(pswp->fl & SWP_HIDE) {
1352 WinShowWindow(win32wnd->getOS2WindowHandle(), 0);
1353 }
1354
1355 if(flAfp & AWP_ACTIVATE)
1356 {
1357 FrameSetFocus(hwnd);
1358 }
1359
1360#ifndef USE_CALCVALIDRECT
1361 if((pswp->fl & (SWP_MOVE | SWP_SIZE)))
1362 {
1363 //CB: todo: use result for WM_CALCVALIDRECTS
1364 //Get old client rectangle (for invalidation of frame window parts later on)
1365 //Use new window height to calculate the client area
1366 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
1367
1368 //Note: Also updates the new window rectangle
1369 win32wnd->MsgFormatFrame(&wp);
1370
1371 if(win32wnd->isOwnDC()) {
1372 setPageXForm(win32wnd, (pDCData)GpiQueryDCData(win32wnd->getOwnDC()));
1373 }
1374
1375 if(win32wnd->CanReceiveSizeMsgs())
1376 win32wnd->MsgPosChanged((LPARAM)&wp);
1377
1378 if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
1379 {
1380 //redraw the frame (to prevent unnecessary client updates)
1381 BOOL redrawAll = FALSE;
1382
1383 dprintf2(("WM_WINDOWPOSCHANGED: redraw frame"));
1384 if (win32wnd->getWindowClass())
1385 {
1386 DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
1387
1388 if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
1389 redrawAll = TRUE;
1390 else
1391 if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
1392 redrawAll = TRUE;
1393 }
1394 else redrawAll = TRUE;
1395
1396 if(win32wnd->IsMixMaxStateChanging()) {
1397 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1398 redrawAll = TRUE;
1399 }
1400
1401 if (redrawAll)
1402 {
1403 //CB: redraw all children for now
1404 // -> problems with update region if we don't do it
1405 // todo: rewrite whole handling
1406 WinInvalidateRect(hwnd,NULL,TRUE);
1407 }
1408 else
1409 {
1410 HPS hps = WinGetPS(hwnd);
1411 RECTL frame,client,arcl[4];
1412
1413 WinQueryWindowRect(hwnd,&frame);
1414
1415 //top
1416 arcl[0].xLeft = 0;
1417 arcl[0].xRight = frame.xRight;
1418 arcl[0].yBottom = rect.yTop;
1419 arcl[0].yTop = frame.yTop;
1420 //right
1421 arcl[1].xLeft = rect.xRight;
1422 arcl[1].xRight = frame.xRight;
1423 arcl[1].yBottom = 0;
1424 arcl[1].yTop = frame.yTop;
1425 //left
1426 arcl[2].xLeft = 0;
1427 arcl[2].xRight = rect.xLeft;
1428 arcl[2].yBottom = 0;
1429 arcl[2].yTop = frame.yTop;
1430 //bottom
1431 arcl[3].xLeft = 0;
1432 arcl[3].xRight = frame.xRight;
1433 arcl[3].yBottom = 0;
1434 arcl[3].yTop = rect.yBottom;
1435
1436 HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
1437
1438 WinInvalidateRegion(hwnd,hrgn,FALSE);
1439 GpiDestroyRegion(hps,hrgn);
1440 WinReleasePS(hps);
1441 }
1442 }
1443 }
1444 else
1445 {
1446#endif //USE_CALCVALIDRECT
1447 if(win32wnd->CanReceiveSizeMsgs())
1448 win32wnd->MsgPosChanged((LPARAM)&wp);
1449#ifndef USE_CALCVALIDRECT
1450 }
1451#endif
1452
1453PosChangedEnd:
1454 rc = (MRESULT)FALSE;
1455 break;
1456 }
1457
1458 case WM_CALCVALIDRECTS:
1459#ifdef USE_CALCVALIDRECT
1460 {
1461 PRECTL oldRect = (PRECTL)mp1, newRect = oldRect+1;
1462 PSWP pswp = (PSWP)mp2;
1463 SWP swpOld;
1464 WINDOWPOS wp;
1465 RECTL newClientRect, oldClientRect;
1466 ULONG nccalcret;
1467// UINT res = CVR_ALIGNLEFT | CVR_ALIGNTOP;
1468 UINT res = 0;
1469
1470 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1471
1472 //Get old position info
1473 WinQueryWindowPos(hwnd, &swpOld);
1474
1475 if(win32wnd->getParent()) {
1476 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getClientHeight(),
1477 win32wnd->getParent()->getClientRectPtr()->left,
1478 win32wnd->getParent()->getClientRectPtr()->top,
1479 hwnd);
1480 }
1481 else OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
1482
1483 wp.hwnd = win32wnd->getWindowHandle();
1484 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
1485 {
1486 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
1487 if(wndAfter) {
1488 wp.hwndInsertAfter = wndAfter->getWindowHandle();
1489 RELEASE_WNDOBJ(wndAfter);
1490 }
1491 else wp.hwndInsertAfter = HWND_TOP_W;
1492 }
1493
1494 //Get old client rectangle
1495 mapWin32ToOS2Rect(oldRect->yTop - oldRect->yBottom, win32wnd->getClientRectPtr(), (PRECTLOS2)&oldClientRect);
1496
1497 //Note: Also updates the new window rectangle
1498 nccalcret = win32wnd->MsgFormatFrame(&wp);
1499
1500 //Get new client rectangle
1501 mapWin32ToOS2Rect(pswp->cy, win32wnd->getClientRectPtr(), (PRECTLOS2)&newClientRect);
1502
1503 if(nccalcret == 0) {
1504 res = CVR_ALIGNTOP | CVR_ALIGNLEFT;
1505 }
1506 else {
1507 if(nccalcret & WVR_ALIGNTOP_W) {
1508 res |= CVR_ALIGNTOP;
1509 }
1510 else
1511 if(nccalcret & WVR_ALIGNBOTTOM_W) {
1512 res |= CVR_ALIGNBOTTOM;
1513 }
1514
1515 if(nccalcret & WVR_ALIGNLEFT_W) {
1516 res |= CVR_ALIGNLEFT;
1517 }
1518 else
1519 if(nccalcret & WVR_ALIGNRIGHT_W) {
1520 res |= CVR_ALIGNRIGHT;
1521 }
1522
1523 if(nccalcret & WVR_REDRAW_W) {//WVR_REDRAW_W = (WVR_HREDRAW | WVR_VREDRAW)
1524 res |= CVR_REDRAW;
1525 }
1526 else
1527 if(nccalcret & WVR_VALIDRECTS_W) {
1528 //TODO:
1529 //res = 0;
1530 }
1531 }
1532 if(win32wnd->IsMixMaxStateChanging()) {
1533 dprintf(("WM_CALCVALIDRECT: window changed min/max/restore state, invalidate entire window"));
1534 res |= CVR_REDRAW;
1535 }
1536 if(res == (CVR_ALIGNTOP|CVR_ALIGNLEFT)) {
1537 oldRect->xRight -= oldClientRect.xLeft;
1538 oldRect->yBottom += oldClientRect.yBottom;
1539 newRect->xRight -= newClientRect.xLeft;
1540 newRect->yBottom += newClientRect.yBottom;
1541 }
1542 rc = res;
1543 break;
1544 }
1545#else
1546 dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
1547 rc = (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
1548 break;
1549#endif
1550
1551 case WM_CALCFRAMERECT:
1552 dprintf(("PMFRAME:WM_CALCFRAMERECT %x", win32wnd->getWindowHandle()));
1553 rc = (MRESULT)TRUE;
1554 break;
1555
1556 case WM_QUERYCTLTYPE:
1557 // This is a frame window
1558 dprintf(("PMFRAME:WM_QUERYCTLTYPE %x", win32wnd->getWindowHandle()));
1559 rc = (MRESULT)CCT_FRAME;
1560 break;
1561
1562#ifdef DEBUG
1563 case WM_QUERYFOCUSCHAIN:
1564 dprintf2(("PMFRAME:WM_QUERYFOCUSCHAIN %x fsCmd %x parent %x", win32wnd->getWindowHandle(), SHORT1FROMMP(mp1), (mp2) ? OS2ToWin32Handle((DWORD)mp2) : 0));
1565
1566 RestoreOS2TIB();
1567 rc = pfnFrameWndProc(hwnd, msg, mp1, mp2);
1568 SetWin32TIB();
1569 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));
1570 break;
1571// goto RunDefFrameWndProc;
1572#endif
1573
1574 case WM_FOCUSCHANGE:
1575 {
1576 HWND hwndFocus = (HWND)mp1;
1577 HWND hwndLoseFocus, hwndGainFocus;
1578 USHORT usSetFocus = SHORT1FROMMP(mp2);
1579 USHORT fsFocusChange = SHORT2FROMMP(mp2);
1580
1581 //Save window that gains focus so we can determine which
1582 //process we lose activation to
1583 hwndFocusChange = (HWND)mp1;
1584
1585 dprintf(("PMFRAME:WM_FOCUSCHANGE %x %x (%x) %x %x", win32wnd->getWindowHandle(), OS2ToWin32Handle(hwndFocus), hwndFocus, usSetFocus, fsFocusChange));
1586 goto RunDefFrameWndProc;
1587 }
1588
1589#ifdef DEBUG
1590 case WM_SETFOCUS:
1591 {
1592 dprintf(("PMFRAME: WM_SETFOCUS %x %x", win32wnd->getWindowHandle(), hwnd));
1593 goto RunDefFrameWndProc;
1594 }
1595#endif
1596
1597 case WM_ACTIVATE:
1598 {
1599 HWND hwndTitle;
1600 USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
1601
1602 dprintf(("PMFRAME: WM_ACTIVATE %x %x %x", win32wnd->getWindowHandle(), mp1, OS2ToWin32Handle((DWORD)mp2)));
1603 if (win32wnd->IsWindowCreated())
1604 {
1605 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1606 if(fOS2Look) {
1607 dprintf(("TBM_QUERYHILITE returned %d", WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_QUERYHILITE, 0, 0)));
1608 WinSendDlgItemMsg(hwnd, FID_TITLEBAR, TBM_SETHILITE, mp1, 0);
1609 }
1610 if(SHORT1FROMMP(mp1) == 0) {
1611 //deactivate
1612 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
1613 }
1614 PID pidThis, pidPartner, pidTemp;
1615 TID tidPartner;
1616 HENUM henum;
1617 HWND hwndEnum;
1618
1619 WinQueryWindowProcess(hwnd, &pidThis, NULL);
1620 WinQueryWindowProcess(hwndFocusChange, &pidPartner, &tidPartner);
1621
1622 if(pidThis != pidPartner) {
1623 //Gain or lose activation to window in other process
1624 //must send WM_ACTIVATEAPP to top-level windows
1625
1626 //Iterate over all child windows of the desktop
1627 henum = WinBeginEnumWindows(HWND_DESKTOP);
1628
1629 while(hwndEnum = WinGetNextWindow(henum))
1630 {
1631 WinQueryWindowProcess(hwndEnum, &pidTemp, NULL);
1632 if(pidTemp == pidThis)
1633 {
1634 SendMessageA(OS2ToWin32Handle(hwndEnum), WM_ACTIVATEAPP_W, (WPARAM)SHORT1FROMMP(mp1), (LPARAM)tidPartner);
1635 }
1636 }
1637 WinEndEnumWindows(henum);
1638 }
1639 if(SHORT1FROMMP(mp1)) {
1640 //activate
1641 WinSendDlgItemMsg(hwnd, FID_CLIENT, WM_ACTIVATE, mp1, mp2);
1642 }
1643
1644 //CB: show owner behind the dialog
1645 if (win32wnd->IsModalDialog())
1646 {
1647 if(win32wnd->getOwner()) {
1648 Win32BaseWindow *topOwner = Win32BaseWindow::GetWindowFromHandle(win32wnd->getOwner()->GetTopParent());
1649
1650 if (topOwner) {
1651 WinSetWindowPos(topOwner->getOS2FrameWindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
1652 RELEASE_WNDOBJ(topOwner);
1653 }
1654 }
1655 }
1656 }
1657 else
1658 {
1659 WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
1660 }
1661 rc = 0;
1662 break;
1663 }
1664
1665 case WM_ENABLE:
1666 dprintf(("PMFRAME: WM_ENABLE %x", hwnd));
1667 win32wnd->MsgEnable(SHORT1FROMMP(mp1));
1668 break;
1669
1670 case WM_SHOW:
1671 dprintf(("PMFRAME: WM_SHOW %x %d", hwnd, mp1));
1672 //show client window
1673 WinShowWindow(win32wnd->getOS2WindowHandle(), (BOOL)mp1);
1674 break;
1675
1676 case WM_QUERYTRACKINFO:
1677 {
1678 PTRACKINFO trackInfo = (PTRACKINFO)mp2;
1679
1680 dprintf(("PMFRAME:WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
1681 trackInfo->cxBorder = 4;
1682 trackInfo->cyBorder = 4;
1683 win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
1684 rc = (MRESULT)TRUE;
1685 break;
1686 }
1687
1688 case WM_QUERYBORDERSIZE:
1689 {
1690 PWPOINT size = (PWPOINT)mp1;
1691
1692 dprintf(("PMFRAME:WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
1693
1694 size->x = 0;
1695 size->y = 0;
1696 rc = (MRESULT)TRUE;
1697 break;
1698 }
1699
1700#ifdef DEBUG
1701 case WM_QUERYFRAMEINFO:
1702 dprintf(("PMFRAME:WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
1703 goto RunDefFrameWndProc;
1704#endif
1705
1706 case WM_FORMATFRAME:
1707 dprintf(("PMFRAME:WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
1708 break;
1709
1710#ifdef DEBUG
1711 case WM_ADJUSTFRAMEPOS:
1712 {
1713 PSWP pswp = (PSWP)mp1;
1714
1715 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));
1716 goto RunDefFrameWndProc;
1717 }
1718
1719 case WM_OWNERPOSCHANGE:
1720 {
1721 PSWP pswp = (PSWP)mp1;
1722
1723 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));
1724 goto RunDefFrameWndProc;
1725 }
1726#endif
1727
1728 case WM_MINMAXFRAME:
1729 {
1730 PSWP swp = (PSWP)mp1;
1731
1732 if (!win32wnd->IsWindowCreated()) goto RunDefWndProc;
1733
1734 dprintf(("PMFRAME:WM_MINMAXFRAME %x",hwnd));
1735 if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
1736 {
1737 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
1738
1739 RECT rect;
1740
1741 rect.left = rect.top = rect.right = rect.bottom = 0;
1742 win32wnd->AdjustMaximizedRect(&rect);
1743 swp->x += rect.left;
1744 swp->cx += rect.right-rect.left;
1745 swp->y -= rect.bottom;
1746 swp->cy += rect.bottom-rect.top;
1747 }
1748 else
1749 if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
1750 {
1751 win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
1752 }
1753 else
1754 if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
1755 {
1756 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
1757 }
1758 goto RunDefWndProc;
1759 }
1760
1761#ifdef DEBUG
1762 case WM_UPDATEFRAME:
1763 dprintf(("PMFRAME:WM_UPDATEFRAME %x", win32wnd->getWindowHandle()));
1764 goto RunDefFrameWndProc;
1765#endif
1766
1767 case WM_TRACKFRAME:
1768 dprintf(("PMFRAME: WM_TRACKFRAME %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
1769 if(fOS2Look) {//sent by titlebar control
1770#ifdef CUSTOM_TRACKFRAME
1771 Frame_SysCommandSizeMove(win32wnd, SC_MOVE_W+HTCAPTION_W);
1772#else
1773 FrameTrackFrame(win32wnd, TF_MOVE);
1774#endif
1775 }
1776 rc = 0;
1777 break;
1778
1779 case WM_SYSCOMMAND:
1780 dprintf(("PMFRAME: WM_SYSCOMMAND %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
1781 if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
1782 RELEASE_WNDOBJ(win32wnd);
1783 win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
1784 }
1785 if(win32wnd)
1786 win32wnd->DispatchMsgA(pWinMsg);
1787 break;
1788
1789#ifdef DEBUG
1790 case WM_DDE_INITIATE:
1791 case WM_DDE_INITIATEACK:
1792 case WM_DDE_REQUEST:
1793 case WM_DDE_ACK:
1794 case WM_DDE_DATA:
1795 case WM_DDE_ADVISE:
1796 case WM_DDE_UNADVISE:
1797 case WM_DDE_POKE:
1798 case WM_DDE_EXECUTE:
1799 case WM_DDE_TERMINATE:
1800 dprintf(("PMFRAME: WM_DDE %x %x", msg, win32wnd->getWindowHandle()));
1801 break;
1802#endif
1803
1804 default:
1805 goto RunDefFrameWndProc;
1806 }
1807 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1808 RestoreOS2TIB();
1809 return (MRESULT)rc;
1810
1811RunDefFrameWndProc:
1812 dprintf2(("RunDefFrameWndProc"));
1813 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1814 RestoreOS2TIB();
1815 return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1816
1817RunDefWndProc:
1818 dprintf2(("RunDefWndProc"));
1819 if(win32wnd) RELEASE_WNDOBJ(win32wnd);
1820 RestoreOS2TIB();
1821 //calling WinDefWindowProc here breaks Opera hotlist window (WM_ADJUSTWINDOWPOS)
1822// return pfnFrameWndProc(hwnd, msg, mp1, mp2);
1823 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
1824}
1825//******************************************************************************
1826//******************************************************************************
1827void FrameSetFocus(HWND hwnd)
1828{
1829 HWND hwndFocusSave = WinQueryWindowULong(hwnd, QWL_HWNDFOCUSSAVE);
1830 if(!WinIsWindow(hab, hwndFocusSave)) {
1831 hwndFocusSave = WinWindowFromID(hwnd, FID_CLIENT);
1832 WinSetWindowULong(hwnd, QWL_HWNDFOCUSSAVE, hwndFocusSave);
1833 }
1834 dprintf(("FrameSetFocus: hwndFocusSave %x %x", OS2ToWin32Handle(hwndFocusSave), hwndFocusSave));
1835 WinSetFocus(HWND_DESKTOP, hwndFocusSave);
1836
1837 ULONG ulFrameFlags = WinQueryWindowUShort(hwnd, QWS_FLAGS);
1838 ulFrameFlags &= ~FF_NOACTIVATESWP;
1839 WinSetWindowUShort(hwnd, QWS_FLAGS, ulFrameFlags);
1840}
1841#ifndef CUSTOM_TRACKFRAME
1842//******************************************************************************
1843//TODO: Quickly moving a window two times doesn't force a repaint (1st time)
1844//
1845//
1846BOOL (APIENTRY *WinTrackWindow)(HWND hwndTrack, PTRACKINFO pti) = NULL;
1847//
1848//******************************************************************************
1849VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
1850{
1851 TRACKINFO track;
1852 RECTL rcl;
1853 PRECT pWindowRect, pClientRect;
1854 HWND hwndTracking;
1855 LONG parentHeight, parentWidth;
1856 static BOOL fInit = FALSE;
1857 APIRET rc;
1858 BOOL ret;
1859 HWND hwnd = win32wnd->getWindowHandle();
1860
1861 if(!fInit) {
1862 HMODULE hModule;
1863 char buf[CCHMAXPATH];
1864 rc = DosLoadModule(buf, sizeof(buf), "PMMERGE", &hModule);
1865 rc = DosQueryProcAddr(hModule, 5466, NULL, (PFN *)&WinTrackWindow);
1866 if(rc) WinTrackWindow = NULL;
1867 fInit = TRUE;
1868 }
1869 dprintf(("FrameTrackFrame: %x %x", hwnd, flags));
1870 track.cxBorder = 4;
1871 track.cyBorder = 4; /* 4 pel wide lines used for rectangle */
1872 track.cxGrid = 1;
1873 track.cyGrid = 1; /* smooth tracking with mouse */
1874 track.cxKeyboard = 8;
1875 track.cyKeyboard = 8; /* faster tracking using cursor keys */
1876
1877 pWindowRect = win32wnd->getWindowRect();
1878 if(win32wnd->getParent()) {
1879 parentHeight = win32wnd->getParent()->getClientHeight();
1880 parentWidth = win32wnd->getParent()->getClientWidth();
1881 hwndTracking = win32wnd->getParent()->getOS2WindowHandle();
1882 }
1883 else {
1884 parentHeight = OSLibQueryScreenHeight();
1885 parentWidth = OSLibQueryScreenWidth();
1886 hwndTracking = HWND_DESKTOP;
1887 }
1888
1889 mapWin32ToOS2Rect(parentHeight, pWindowRect, (PRECTLOS2)&track.rclTrack);
1890 rcl = track.rclTrack;
1891 WinQueryWindowRect(hwndTracking, &track.rclBoundary);
1892
1893 track.ptlMinTrackSize.x = 10;
1894 track.ptlMinTrackSize.y = 10; /* set smallest allowed size of rectangle */
1895 track.ptlMaxTrackSize.x = parentWidth;
1896 track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */
1897
1898 win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize);
1899
1900 track.fs = flags;
1901
1902 BOOL fDynamicDrag = WinQuerySysValue(HWND_DESKTOP, SVOS_DYNAMICDRAG);
1903
1904 //TODO: send WM_QUERYDRAGICON to fetch icon (not really necessary)
1905
1906 SendMessageA( hwnd, WM_ENTERSIZEMOVE_W, 0, 0);
1907
1908 SEL sel = RestoreOS2FS();
1909 if(fDynamicDrag && WinTrackWindow) {
1910 ret = WinTrackWindow(win32wnd->getOS2FrameWindowHandle(), &track);
1911 }
1912 else ret = WinTrackRect(hwndTracking, NULL, &track);
1913 SetFS(sel);
1914
1915//TODO:
1916// if (HOOK_CallHooksA( WH_CBT_W, HCBT_MOVESIZE_W, (WPARAM)hwnd, (LPARAM)&sizingRect )) moved = FALSE;
1917
1918 SendMessageA( hwnd, WM_EXITSIZEMOVE_W, 0, 0 );
1919 SendMessageA( hwnd, WM_SETVISIBLE_W, !IsIconic(hwnd), 0L);
1920
1921 if(ret) {
1922 /* if successful copy final position back */
1923 if(!WinEqualRect(0, &rcl, &track.rclTrack)) {
1924 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));
1925 if(flags == TF_MOVE) {
1926 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
1927 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1928 0, 0, SWP_MOVE);
1929 }
1930 else {
1931 WinSetWindowPos(win32wnd->getOS2FrameWindowHandle(),
1932 0, track.rclTrack.xLeft, track.rclTrack.yBottom,
1933 track.rclTrack.xRight - track.rclTrack.xLeft,
1934 track.rclTrack.yTop - track.rclTrack.yBottom,
1935 SWP_SIZE|SWP_MOVE);
1936 }
1937 }
1938 return;
1939 }
1940 return;
1941}
1942#endif
1943//******************************************************************************
1944//******************************************************************************
1945void FrameReplaceMenuItem(HWND hwndMenu, ULONG nIndex, ULONG idOld, ULONG idNew,
1946 HBITMAP hbmNew)
1947{
1948 MENUITEM mi;
1949
1950 if (!hwndMenu)
1951 return;
1952
1953 WinEnableWindowUpdate(hwndMenu, FALSE);
1954
1955 if (WinSendMsg(hwndMenu, MM_QUERYITEM, MPFROM2SHORT(idOld, TRUE), MPFROMP(&mi)))
1956 {
1957 WinSendMsg(hwndMenu, MM_REMOVEITEM, (MPARAM)idOld, 0);
1958 mi.afStyle = MIS_BITMAP | MIS_SYSCOMMAND;
1959 mi.afAttribute = 0;
1960 mi.hwndSubMenu = 0;
1961 mi.id = idNew;
1962 mi.hItem = (ULONG)hbmNew;
1963 WinSendMsg(hwndMenu, MM_INSERTITEM, (MPARAM)&mi, 0);
1964 }
1965 WinEnableWindowUpdate(hwndMenu, TRUE);
1966
1967 WinInvalidateRect(hwndMenu, NULL, TRUE);
1968}
1969//******************************************************************************
1970//******************************************************************************
1971static char *PMDragExtractFiles(PDRAGINFO pDragInfo, ULONG *pcItems, ULONG *pulBytes)
1972{
1973 PDRAGITEM pDragItem;
1974 int i, cItems;
1975 BOOL ret;
1976 char szFileName[CCHMAXPATH];
1977 char szContainerName[CCHMAXPATH];
1978 ULONG ulBytes;
1979 char *pszCurFile = NULL;
1980
1981 /* Get access to the DRAGINFO data structure */
1982 if(!DrgAccessDraginfo(pDragInfo)) {
1983 return NULL;
1984 }
1985
1986 cItems = DrgQueryDragitemCount(pDragInfo);
1987
1988 //computer memory required to hold all filenames
1989 int bufsize = 0;
1990 for (i = 0; i < cItems; i++) {
1991 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
1992
1993 bufsize += DrgQueryStrNameLen(pDragItem->hstrContainerName) + DrgQueryStrNameLen(pDragItem->hstrSourceName);
1994 bufsize++; //0 terminator
1995 bufsize++; //+ potential missing backslash
1996 }
1997 bufsize++; //extra 0 terminator
1998 char *pszFiles = (char *)malloc(bufsize);
1999 if(pszFiles == NULL) {
2000 dprintf(("Out of memory!!"));
2001 DebugInt3();
2002 goto failure;
2003 }
2004 memset(pszFiles, 0, bufsize);
2005
2006 pszCurFile = pszFiles;
2007
2008 //copy all filenames
2009 for (i = 0; i < cItems; i++) {
2010 char *pszTemp = pszCurFile;
2011
2012 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
2013
2014 ulBytes = DrgQueryStrNameLen(pDragItem->hstrContainerName);
2015 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
2016 ulBytes, pszCurFile);
2017 if(pszCurFile[ulBytes-1] != '\\') {
2018 pszCurFile[ulBytes] = '\\';
2019 pszCurFile++;
2020 }
2021 pszCurFile += ulBytes;
2022
2023 ulBytes = DrgQueryStrNameLen(pDragItem->hstrSourceName);
2024 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
2025 ulBytes+1, pszCurFile);
2026 pszCurFile += ulBytes + 1; //+ terminator
2027
2028 dprintf(("dropped file %s", pszTemp));
2029 }
2030
2031 /* Release the draginfo data structure */
2032 DrgFreeDraginfo(pDragInfo);
2033
2034 *pulBytes = bufsize;
2035 *pcItems = cItems;
2036
2037 return pszFiles;
2038
2039failure:
2040 /* Release the draginfo data structure */
2041 DrgFreeDraginfo(pDragInfo);
2042 if(pszFiles) {
2043 free(pszFiles);
2044 }
2045 return NULL;
2046}
2047//******************************************************************************
2048//******************************************************************************
2049static BOOL PMDragValidate(PDRAGINFO pDragInfo)
2050{
2051 PDRAGITEM pDragItem;
2052 ULONG ulBytes;
2053 int i, cItems;
2054 BOOL ret;
2055 char szFileName[CCHMAXPATH];
2056 char szContainerName[CCHMAXPATH];
2057 USHORT usOp = DO_MOVE;
2058
2059 /* Get access to the DRAGINFO data structure */
2060 if(!DrgAccessDraginfo(pDragInfo)) {
2061 return FALSE;
2062 }
2063
2064 /* Can we accept this drop? */
2065 switch (pDragInfo->usOperation) {
2066 /* Return DOR_NODROPOP if current operation */
2067 /* is link or unknown */
2068 case DO_LINK:
2069 case DO_COPY:
2070 case DO_UNKNOWN:
2071 goto failure;
2072
2073 /* Our default operation is Move */
2074 case DO_MOVE:
2075 case DO_DEFAULT:
2076 pDragItem = DrgQueryDragitemPtr(pDragInfo, 0);
2077 ulBytes = DrgQueryStrName(pDragItem->hstrContainerName,
2078 sizeof(szContainerName),
2079 szContainerName);
2080 ulBytes = DrgQueryStrName(pDragItem->hstrSourceName,
2081 sizeof(szFileName),
2082 szFileName);
2083 if (!ulBytes) {
2084 goto failure;
2085 }
2086
2087 dprintf(("dropped file %s%s", szContainerName, szFileName));
2088 break;
2089 }
2090
2091 cItems = DrgQueryDragitemCount(pDragInfo);
2092
2093 /* Now, we need to look at each item in turn */
2094 for (i = 0; i < cItems; i++) {
2095 pDragItem = DrgQueryDragitemPtr(pDragInfo, i);
2096
2097 /* Make sure we can move for a Move request */
2098 if (!((pDragItem->fsSupportedOps & DO_MOVEABLE) &&
2099 (usOp == (USHORT)DO_MOVE)))
2100 {
2101 dprintf(("item %d not accepted", i));
2102 goto failure;
2103 }
2104 }
2105 /* Release the draginfo data structure */
2106 DrgFreeDraginfo(pDragInfo);
2107 return TRUE;
2108
2109failure:
2110 DrgFreeDraginfo(pDragInfo);
2111 return FALSE;
2112}
2113//******************************************************************************
2114//******************************************************************************
2115
Note: See TracBrowser for help on using the repository browser.