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

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

PF: Pass on WM_PAINT of client window to default PM handler if window is minimized

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