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

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

Translate WM_DRAWCLIPBOARD for clipboard change notification

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