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

Last change on this file since 1849 was 1849, checked in by cbratschi, 26 years ago

map rect, WM_ERASEBKGND and other fixes

File size: 33.8 KB
Line 
1/* $Id: pmwindow.cpp,v 1.57 1999-11-26 17:06:08 cbratschi Exp $ */
2/*
3 * Win32 Window Managment Code for OS/2
4 *
5 * Copyright 1998-1999 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
17#include <os2wrap.h>
18#include <stdlib.h>
19#include "win32type.h"
20#include <winconst.h>
21#include <wprocess.h>
22#include <misc.h>
23#include <win32wbase.h>
24#include <win32dlg.h>
25#include "win32wdesktop.h"
26#include "pmwindow.h"
27#include "oslibwin.h"
28#include "oslibutil.h"
29#include "oslibgdi.h"
30#include "oslibmsg.h"
31#include "dc.h"
32#include <thread.h>
33#include <wprocess.h>
34#include "caret.h"
35#include "timer.h"
36
37HMQ hmq = 0; /* Message queue handle */
38HAB hab = 0;
39
40RECTL desktopRectl = {0};
41ULONG ScreenWidth = 0;
42ULONG ScreenHeight = 0;
43ULONG ScreenBitsPerPel = 0;
44
45//Used for key translation while processing WM_CHAR message
46USHORT virtualKeyTable [66] = {
47 0x00, // OS/2 VK Win32 VK, Entry 0 is not used
48 0x01, // VK_BUTTON1 VK_LBUTTON
49 0x02, // VK_BUTTON2 VK_RBUTTON
50 0x04, // VK_BUTTON3 VK_MBUTTON
51 0x03, // VK_BREAK VK_CANCEL
52 0x08, // VK_BACKSPACE VK_BACK
53 0x09, // VK_TAB VK_TAB
54 0x00, // VK_BACKTAB No equivalent!
55 0x0A, // VK_NEWLINE 0x0A (no VK_* def)
56 0x10, // VK_SHIFT VK_SHIFT
57 0x11, // VK_CTRL VK_CONTROL
58 0x12, // VK_ALT VK_MENU, best match I guess
59 0x12, // VK_ALTGRAF VK_MENU, best match I guess
60 0x13, // VK_PAUSE VK_PAUSE
61 0x14, // VK_CAPSLOCK VK_CAPITAL
62 0x1B, // VK_ESC VK_ESCAPE
63 0x20, // VK_SPACE VK_SPACE
64 0x21, // VK_PAGEUP VK_PRIOR
65 0x22, // VK_PAGEDOWN VK_NEXT
66 0x23, // VK_END VK_END
67 0x24, // VK_HOME VK_HOME
68 0x25, // VK_LEFT VK_LEFT
69 0x26, // VK_UP VK_UP
70 0x27, // VK_RIGHT VK_RIGHT
71 0x28, // VK_DOWN VK_DOWN
72 0x2C, // VK_PRINTSCRN VK_SNAPSHOT
73 0x2D, // VK_INSERT VK_INSERT
74 0x2E, // VK_DELETE VK_DELETE
75 0x91, // VK_SCRLLOCK VK_SCROLL
76 0x90, // VK_NUMLOCK VK_NUMLOCK
77 0x0D, // VK_ENTER VK_RETURN
78 0x00, // VK_SYSRQ No equivalent!
79 0x70, // VK_F1 VK_F1
80 0x71, // VK_F2 VK_F2
81 0x72, // VK_F3 VK_F3
82 0x73, // VK_F4 VK_F4
83 0x74, // VK_F5 VK_F5
84 0x75, // VK_F6 VK_F6
85 0x76, // VK_F7 VK_F7
86 0x77, // VK_F8 VK_F8
87 0x78, // VK_F9 VK_F9
88 0x79, // VK_F10 VK_F10
89 0x7A, // VK_F11 VK_F11
90 0x7B, // VK_F12 VK_F12
91 0x7C, // VK_F13 VK_F13
92 0x7D, // VK_F14 VK_F14
93 0x7E, // VK_F15 VK_F15
94 0x7F, // VK_F16 VK_F16
95 0x80, // VK_F17 VK_F17
96 0x81, // VK_F18 VK_F18
97 0x82, // VK_F19 VK_F19
98 0x83, // VK_F20 VK_F20
99 0x84, // VK_F21 VK_F21
100 0x85, // VK_F22 VK_F22
101 0x86, // VK_F23 VK_F23
102 0x87, // VK_F24 VK_F24
103 0x00, // VK_ENDDRAG No equivalent!
104 0x0C, // VK_CLEAR VK_CLEAR
105 0xF9, // VK_EREOF VK_EREOF
106 0xFD, // VK_PA1 VK_PA1
107 0xF6, // VK_ATTN VK_ATTN
108 0xF7, // VK_CRSEL VK_CRSEL
109 0xF8, // VK_EXSEL VK_EXSEL
110 0x00, // VK_COPY No equivalent!
111 0x00, // VK_BLK1 No equivalent!
112 0x00}; // VK_BLK2 No equivalent!
113
114MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
115
116//******************************************************************************
117//Initialize PM; create hab, message queue and register special Win32 window classes
118//******************************************************************************
119BOOL InitPM()
120{
121 CLASSINFO FrameClassInfo;
122
123 hab = WinInitialize(0);
124 dprintf(("Winitialize returned %x", hab));
125 hmq = WinCreateMsgQueue(hab, 0);
126
127 if(!hab || !hmq)
128 {
129 UINT error;
130 //CB: only fail on real error
131 error = WinGetLastError(hab) & 0xFFFF; //error code
132 if (!hab || error != PMERR_MSG_QUEUE_ALREADY_EXISTS)
133 {
134 dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
135 dprintf((" Error = %x",error));
136 return(FALSE);
137 }
138 else
139 {
140 if(!hab) {
141 hab = WinQueryAnchorBlock(HWND_DESKTOP);
142 dprintf(("WinQueryAnchorBlock returned %x", hab));
143 }
144 if(!hmq) {
145 hmq = HMQ_CURRENT;
146 }
147 }
148 }
149 SetThreadHAB(hab);
150 dprintf(("InitPM: hmq = %x", hmq));
151 SetThreadMessageQueue(hmq);
152
153 if(!WinRegisterClass( /* Register window class */
154 hab, /* Anchor block handle */
155 (PSZ)WIN32_STDCLASS, /* Window class name */
156 (PFNWP)Win32WindowProc, /* Address of window procedure */
157// CS_SIZEREDRAW | CS_HITTEST | CS_MOVENOTIFY,
158 CS_SIZEREDRAW | CS_HITTEST,
159 NROF_WIN32WNDBYTES)) {
160 dprintf(("WinRegisterClass Win32BaseWindow failed"));
161 return(FALSE);
162 }
163 if (!WinQueryClassInfo (hab, WC_FRAME, &FrameClassInfo)) {
164 dprintf (("WinQueryClassInfo WC_FRAME failed"));
165 return (FALSE);
166 }
167 FrameClassInfo.flClassStyle &= ~(CS_PUBLIC | CS_CLIPSIBLINGS);
168 if (!WinRegisterClass (hab,
169 WIN32_INNERFRAME,
170 FrameClassInfo.pfnWindowProc,
171 FrameClassInfo.flClassStyle,
172 FrameClassInfo.cbWindowData)) {
173 dprintf (("WinRegisterClass Win32InnerFrame failed"));
174 return (FALSE);
175 }
176
177 WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
178 ScreenWidth = desktopRectl.xRight;
179 ScreenHeight = desktopRectl.yTop;
180
181
182 HDC hdc; /* Device-context handle */
183 /* context data structure */
184 DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
185 NULL, NULL, NULL};
186
187 /* create memory device context */
188 hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
189 DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, (PLONG)&ScreenBitsPerPel);
190 DevCloseDC(hdc);
191
192 dprintf(("InitPM: Desktop (%d,%d)", ScreenWidth, ScreenHeight));
193 return OSLibInitMsgQueue();
194} /* End of main */
195//******************************************************************************
196//Win32 window message handler
197//******************************************************************************
198MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
199{
200 POSTMSG_PACKET *postmsg;
201 OSLIBPOINT point, ClientPoint;
202 Win32BaseWindow *win32wnd;
203 APIRET rc;
204
205 //Restore our FS selector
206 SetWin32TIB();
207
208 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
209
210 if(msg != WM_CREATE && win32wnd == NULL) {
211 dprintf(("Invalid win32wnd pointer for window %x!!", hwnd));
212 goto RunDefWndProc;
213 }
214 if(msg == WIN32APP_POSTMSG && (ULONG)mp1 == WIN32PM_MAGIC) {
215 //win32 app user message
216 win32wnd->PostMessage((POSTMSG_PACKET *)mp2);
217 return (MRESULT)0;
218 }
219 switch( msg )
220 {
221 //OS/2 msgs
222 case WM_CREATE:
223 {
224 THDB *thdb = GetThreadTHDB();
225
226 if(thdb == NULL || thdb->newWindow == 0)
227 goto createfail;
228
229 //Processing is done in after WinCreateWindow returns
230 dprintf(("OS2: WM_CREATE %x", hwnd));
231 win32wnd = (Win32BaseWindow *)thdb->newWindow;
232
233 if(win32wnd->MsgCreate(WinQueryWindow(hwnd, QW_PARENT), hwnd) == FALSE)
234 {
235 RestoreOS2TIB();
236 return (MRESULT)TRUE; //discontinue window creation
237 }
238 createfail:
239 RestoreOS2TIB();
240 return (MRESULT)FALSE;
241 }
242
243 case WM_QUIT:
244 dprintf(("OS2: WM_QUIT %x", hwnd));
245 if(win32wnd->MsgQuit()) {
246 goto RunDefWndProc;
247 }
248 break;
249
250 case WM_CLOSE:
251 dprintf(("OS2: WM_CLOSE %x", hwnd));
252// win32wnd->RemoveFakeOpen32();
253 if(win32wnd->MsgClose()) {
254 goto RunDefWndProc;
255 }
256 break;
257
258 case WM_DESTROY:
259 dprintf(("OS2: WM_DESTROY %x", hwnd));
260 if(win32wnd->MsgDestroy()) {
261 goto RunDefWndProc;
262 }
263 break;
264
265 case WM_ENABLE:
266 dprintf(("OS2: WM_ENABLE %x", hwnd));
267 if(win32wnd->MsgEnable(SHORT1FROMMP(mp1))) {
268 goto RunDefWndProc;
269 }
270 break;
271
272 case WM_SHOW:
273 dprintf(("OS2: WM_SHOW %x %d", hwnd, mp1));
274 if(win32wnd->MsgShow((ULONG)mp1)) {
275 goto RunDefWndProc;
276 }
277 break;
278
279#if 0
280 case WM_ADJUSTWINDOWPOS:
281 {
282 PSWP pswp = (PSWP)mp1;
283 SWP swpOld, swpNew;
284 WINDOWPOS wp;
285 ULONG parentHeight = 0;
286 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE, hwndAfter;
287
288 dprintf(("OS2: WM_ADJUSTWINDOWPOS %x %x %x (%d,%d) (%d,%d)", hwnd, pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
289
290 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) goto RunDefWndProc;;
291
292 //SvL: TODO: Workaround. Why is this happening?
293 // When this flag is set the coordinates are 0, even though SWP_SIZE & SWP_MOVE are set.
294// if ((pswp->fl & SWP_NOADJUST)) goto RunDefWndProc;
295
296 if(!win32wnd->CanReceiveSizeMsgs()) goto RunDefWndProc;;
297
298 WinQueryWindowPos(hwnd, &swpOld);
299
300 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
301 if (win32wnd->isChild()) {
302 if(win32wnd->getParent()) {
303 hParent = win32wnd->getParent()->getOS2WindowHandle();
304 }
305 else goto RunDefWndProc;;
306 }
307 }
308 hwndAfter = pswp->hwndInsertBehind;
309 hFrame = win32wnd->getOS2FrameWindowHandle();
310 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, hParent, hFrame);
311
312 wp.hwnd = win32wnd->getWindowHandle();
313 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
314 {
315 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
316 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
317 }
318 if(win32wnd->MsgPosChanging((LPARAM)&wp) == 0)
319 {//app or default window handler changed wp
320 dprintf(("OS2: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
321 dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
322 OSLibMapWINDOWPOStoSWP(&wp, &swpNew, &swpOld, hParent, hFrame);
323 dprintf(("%x (%d,%d), (%d,%d)", swpNew.fl, swpNew.x, swpNew.y, swpNew.cx, swpNew.cy));
324 swpNew.fl |= SWP_NOADJUST;
325 swpNew.hwndInsertBehind = hwndAfter;
326 swpNew.hwnd = hFrame;
327
328 WinSetMultWindowPos(GetThreadHAB(), &swpNew, 1);
329 return (MRESULT)0;
330 }
331 break;
332 }
333
334 case WM_WINDOWPOSCHANGED:
335 {
336 PSWP pswp = (PSWP)mp1;
337 SWP swpOld = *(pswp + 1);
338 WINDOWPOS wp;
339 HWND hParent = NULLHANDLE;
340 LONG yDelta = pswp->cy - swpOld.cy;
341 LONG xDelta = pswp->cx - swpOld.cx;
342
343 dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
344
345 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
346
347 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
348 if (win32wnd->isChild()) {
349 if(win32wnd->getParent()) {
350 hParent = win32wnd->getParent()->getOS2WindowHandle();
351 }
352 else goto RunDefWndProc; //parent has just been destroyed
353 }
354 }
355 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, hParent, win32wnd->getOS2FrameWindowHandle());
356
357 if (!win32wnd->CanReceiveSizeMsgs()) break;
358
359 win32wnd->setWindowRect(wp.x, wp.y, wp.x+wp.cx, wp.y+wp.cy);
360 win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
361
362 wp.hwnd = win32wnd->getWindowHandle();
363 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
364 {
365 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
366 wp.hwndInsertAfter = wndAfter->getWindowHandle();
367 }
368
369 if (yDelta != 0 || xDelta != 0)
370 {
371 HENUM henum = WinBeginEnumWindows(pswp->hwnd);
372 SWP swp[10];
373 int i = 0;
374 HWND hwnd;
375
376 while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE)
377 {
378#if 0
379 if (mdiClient )
380 {
381 continue;
382 }
383#endif
384 WinQueryWindowPos(hwnd, &(swp[i]));
385
386#ifdef DEBUG
387 Win32BaseWindow *window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
388 dprintf(("ENUMERATE %x delta %d (%d,%d) (%d,%d) %x", (window) ? window->getWindowHandle() : hwnd,
389 yDelta, swp[i].x, swp[i].y, swp[i].cx, swp[i].cy, swp[i].fl));
390#endif
391
392 if(swp[i].y != 0) {
393 //child window at offset <> 0 from client area -> offset now changes
394 swp[i].y += yDelta;
395 swp[i].fl &= ~(SWP_NOREDRAW);
396 }
397 //else child window with the same start coorindates as the client area
398 //The app should resize it.
399
400 if (i == 9)
401 {
402 WinSetMultWindowPos(GetThreadHAB(), swp, 10);
403 i = 0;
404 }
405 else
406 {
407 i++;
408 }
409 }
410
411 WinEndEnumWindows(henum);
412
413 if (i)
414 WinSetMultWindowPos(GetThreadHAB(), swp, i);
415 }
416 if (yDelta != 0)
417 {
418 POINT pt;
419 if(GetCaretPos (&pt) == TRUE)
420 {
421 pt.y -= yDelta;
422 SetCaretPos (pt.x, pt.y);
423 }
424 }
425 win32wnd->MsgPosChanged((LPARAM)&wp);
426
427 goto RunDefWndProc;
428 }
429#endif
430
431 case WM_ACTIVATE:
432 {
433 HWND hwndActivate = (HWND)mp2;
434 BOOL fMinimized = FALSE;
435
436 dprintf(("OS2: WM_ACTIVATE %x %x", hwnd, hwndActivate));
437 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
438 //another (non-win32) application's window
439 //set to NULL (allowed according to win32 SDK) to avoid problems
440 hwndActivate = NULL;
441 }
442 if(WinQueryWindowULong(hwnd, QWL_STYLE) & WS_MINIMIZED)
443 {
444 fMinimized = TRUE;
445 }
446
447 if(win32wnd->MsgActivate(SHORT1FROMMP(mp1), fMinimized, Win32BaseWindow::OS2ToWin32Handle(hwndActivate))) {
448 goto RunDefWndProc;
449 }
450 break;
451 }
452
453 case WM_SIZE:
454 {
455 dprintf(("OS2: WM_SIZE (%d,%d) (%d,%d)", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), SHORT1FROMMP(mp1), SHORT2FROMMP(mp2)));
456 break;
457 }
458
459 case WM_OWNERPOSCHANGE:
460 {
461 dprintf(("OS2: WM_OWNERPOSCHANGE"));
462 goto RunDefWndProc;
463 }
464
465 case WM_CALCVALIDRECTS:
466 {
467 dprintf(("OS2: WM_CALCVALIDRECTS"));
468 goto RunDefWndProc;
469 }
470
471 case WM_FOCUSCHANGE:
472 dprintf(("OS2: WM_FOCUSCHANGE %x", win32wnd->getWindowHandle()));
473 goto RunDefWndProc;
474
475 case WM_SETFOCUS:
476 {
477 HWND hwndFocus = (HWND)mp1;
478
479 dprintf(("OS2: WM_SETFOCUS %x %x %d", win32wnd->getWindowHandle(), mp1, mp2));
480 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
481 //another (non-win32) application's window
482 //set to NULL (allowed according to win32 SDK) to avoid problems
483 hwndFocus = NULL;
484 }
485 if((ULONG)mp2 == TRUE) {
486 HWND hwndFocusWin32 = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
487 recreateCaret (hwndFocusWin32);
488 rc = win32wnd->MsgSetFocus(hwndFocusWin32);
489 }
490 else rc = win32wnd->MsgKillFocus(Win32BaseWindow::OS2ToWin32Handle(hwndFocus));
491 if(rc) {
492 goto RunDefWndProc;
493 }
494 break;
495 }
496
497 //**************************************************************************
498 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
499 //**************************************************************************
500 case WM_BUTTON1DOWN:
501 dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd));
502 point.x = (*(POINTS *)&mp1).x;
503 point.y = (*(POINTS *)&mp1).y;
504 ClientPoint.x = point.x;
505 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
506 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
507 if(win32wnd->MsgButton(BUTTON_LEFTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
508 goto RunDefWndProc;
509 }
510 break;
511
512 case WM_BUTTON1UP:
513 dprintf(("OS2: WM_BUTTON1UP %x", hwnd));
514 point.x = (*(POINTS *)&mp1).x;
515 point.y = (*(POINTS *)&mp1).y;
516 ClientPoint.x = point.x;
517 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
518 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
519 if(win32wnd->MsgButton(BUTTON_LEFTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
520 goto RunDefWndProc;
521 }
522 break;
523 case WM_BUTTON1DBLCLK:
524 point.x = (*(POINTS *)&mp1).x;
525 point.y = (*(POINTS *)&mp1).y;
526 ClientPoint.x = point.x;
527 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
528 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
529 if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
530 goto RunDefWndProc;
531 }
532 break;
533 case WM_BUTTON2DOWN:
534 point.x = (*(POINTS *)&mp1).x;
535 point.y = (*(POINTS *)&mp1).y;
536 ClientPoint.x = point.x;
537 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
538 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
539 if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
540 goto RunDefWndProc;
541 }
542 break;
543 case WM_BUTTON2UP:
544 point.x = (*(POINTS *)&mp1).x;
545 point.y = (*(POINTS *)&mp1).y;
546 ClientPoint.x = point.x;
547 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
548 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
549 if(win32wnd->MsgButton(BUTTON_RIGHTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
550 goto RunDefWndProc;
551 }
552 break;
553 case WM_BUTTON2DBLCLK:
554 point.x = (*(POINTS *)&mp1).x;
555 point.y = (*(POINTS *)&mp1).y;
556 ClientPoint.x = point.x;
557 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
558 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
559 if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
560 goto RunDefWndProc;
561 }
562 break;
563 case WM_BUTTON3DOWN:
564 point.x = (*(POINTS *)&mp1).x;
565 point.y = (*(POINTS *)&mp1).y;
566 ClientPoint.x = point.x;
567 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
568 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
569 if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
570 goto RunDefWndProc;
571 }
572 break;
573 case WM_BUTTON3UP:
574 point.x = (*(POINTS *)&mp1).x;
575 point.y = (*(POINTS *)&mp1).y;
576 ClientPoint.x = point.x;
577 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
578 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
579 if(win32wnd->MsgButton(BUTTON_MIDDLEUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
580 goto RunDefWndProc;
581 }
582 break;
583 case WM_BUTTON3DBLCLK:
584 point.x = (*(POINTS *)&mp1).x;
585 point.y = (*(POINTS *)&mp1).y;
586 ClientPoint.x = point.x;
587 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
588 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
589 if(win32wnd->MsgButton(BUTTON_MIDDLEDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
590 goto RunDefWndProc;
591 }
592 break;
593
594 case WM_BUTTON2MOTIONSTART:
595 case WM_BUTTON2MOTIONEND:
596 case WM_BUTTON2CLICK:
597 case WM_BUTTON1MOTIONSTART:
598 case WM_BUTTON1MOTIONEND:
599 case WM_BUTTON1CLICK:
600 case WM_BUTTON3MOTIONSTART:
601 case WM_BUTTON3MOTIONEND:
602 case WM_BUTTON3CLICK:
603 goto RunDefWndProc;
604
605 case WM_MOUSEMOVE:
606 {
607 ULONG keystate = 0;
608 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1))
609 keystate |= WMMOVE_LBUTTON;
610 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
611 keystate |= WMMOVE_MBUTTON;
612 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3))
613 keystate |= WMMOVE_RBUTTON;
614 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT))
615 keystate |= WMMOVE_SHIFT;
616 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL))
617 keystate |= WMMOVE_CTRL;
618
619 //OS/2 Window coordinates -> Win32 Window coordinates
620 win32wnd->MsgMouseMove(keystate, SHORT1FROMMP(mp1), MapOS2ToWin32Y(win32wnd, SHORT2FROMMP(mp1)));
621 break;
622 }
623
624 case WM_CONTROL:
625
626 case WM_COMMAND:
627 if(SHORT1FROMMP(mp2) == CMDSRC_MENU) {
628 win32wnd->MsgCommand(CMD_MENU, SHORT1FROMMP(mp1), 0);
629 }
630 if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR) {
631 win32wnd->MsgCommand(CMD_ACCELERATOR, SHORT1FROMMP(mp1), 0);
632 }
633 //todo controls + accelerators
634 break;
635
636 case WM_SYSCOMMAND:
637 {
638 ULONG x = 0, y = 0;
639 ULONG win32sc;
640
641 if(SHORT2FROMMP(mp2) == TRUE) {//syscommand caused by mouse action
642 POINTL pointl;
643 WinQueryPointerPos(HWND_DESKTOP, &pointl);
644 x = pointl.x;
645 y = ScreenHeight - y;
646 }
647 switch(SHORT1FROMMP(mp1)) {
648 case SC_MOVE:
649 win32sc = SC_MOVE_W;
650 break;
651 case SC_CLOSE:
652 win32sc = SC_CLOSE_W;
653 break;
654 case SC_MAXIMIZE:
655 win32sc = SC_MAXIMIZE_W;
656 break;
657 case SC_MINIMIZE:
658 win32sc = SC_MINIMIZE_W;
659 break;
660 case SC_NEXTFRAME:
661 case SC_NEXTWINDOW:
662 win32sc = SC_NEXTWINDOW_W;
663 break;
664 case SC_RESTORE:
665 win32sc = SC_RESTORE_W;
666 break;
667 case SC_TASKMANAGER:
668 win32sc = SC_TASKLIST_W;
669 break;
670 default:
671 goto RunDefWndProc;
672 }
673 dprintf(("WM_SYSCOMMAND %x %x (%d,%d)", hwnd, win32sc, x, y));
674 if(win32wnd->MsgSysCommand(win32sc, x, y)) {
675 goto RunDefWndProc;
676 }
677 break;
678 }
679 case WM_CHAR:
680 {
681 THDB *thdb;
682 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
683 ULONG flags = SHORT1FROMMP(mp1);
684 BOOL keyWasPressed, fTranslated = FALSE, fRunDefWndProc = FALSE;
685
686 char c;
687
688 repeatCount = CHAR3FROMMP(mp1);
689 scanCode = CHAR4FROMMP(mp1);
690 keyWasPressed = ((SHORT1FROMMP (mp1) & KC_PREVDOWN) == KC_PREVDOWN);
691
692 dprintf(("PM: WM_CHAR: %x %x %d %x", SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), repeatCount, scanCode));
693 dprintf(("PM: WM_CHAR: %x", flags));
694 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
695 // given the OS/2 virtual key and OS/2 character
696
697 //if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
698 // ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
699 c = 0;
700 if ((SHORT1FROMMP (mp1) & 0xFF) != 0)
701 {
702 c = SHORT1FROMMP (mp2);
703 if ((c >= 'A') && (c <= 'Z')) {
704 virtualKey = c;
705 goto VirtualKeyFound;
706 }
707 if ((c >='a') && (c <= 'z')) {
708 virtualKey = c - 32; // make it uppercase
709 goto VirtualKeyFound;
710 }
711 if ((c >= '0') && (c <= '9')) {
712 virtualKey = c;
713 goto VirtualKeyFound;
714 }
715 }
716
717 // convert OS/2 virtual keys to Win32 virtual key
718 if (SHORT2FROMMP (mp2) <= VK_BLK2)
719 virtualKey = virtualKeyTable [SHORT2FROMMP (mp2)];
720
721VirtualKeyFound:
722 dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
723
724 if(!(SHORT1FROMMP(mp1) & KC_ALT))
725 {
726 //
727 // the Alt key is not pressed
728 //
729 if ((flags & KC_KEYUP) == KC_KEYUP) {
730 // send WM_KEYUP message
731
732 if(win32wnd->MsgKeyUp (repeatCount, scanCode, virtualKey)) {
733 fRunDefWndProc = TRUE;
734 }
735 }
736 else {
737 // send WM_KEYDOWN message
738 if (win32wnd->MsgKeyDown (repeatCount, scanCode,
739 virtualKey, keyWasPressed))
740 fRunDefWndProc = TRUE;
741 }
742 }
743 else {
744 //
745 // the Alt key is pressed
746 //
747 if ((flags & KC_KEYUP) == KC_KEYUP) {
748 // send WM_SYSKEYUP message
749
750 dprintf(("PMWINDOW_WM_SYSKEYUP: vkey:(%x)", virtualKey));
751 if(win32wnd->MsgSysKeyUp (repeatCount, scanCode, virtualKey)) {
752 fRunDefWndProc = TRUE;
753 }
754 }
755 else {
756 // send WM_SYSKEYDOWN message
757 dprintf(("PMWINDOW_WM_SYSKEYDOWN: vkey:(%x)", virtualKey));
758 if (win32wnd->MsgSysKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
759 fRunDefWndProc = TRUE;
760 }
761 }
762
763 thdb = GetThreadTHDB();
764 if(thdb) {
765 fTranslated = thdb->fMsgTranslated;
766 thdb->fMsgTranslated = FALSE; //reset flag
767 }
768 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
769 // the newly generated WM_CHAR message.
770 if(fTranslated && !((flags & KC_KEYUP) == KC_KEYUP))
771 {//TranslatedMessage was called before DispatchMessage, so send WM_CHAR messages
772 ULONG keyflags = 0, vkey = 0;
773 ULONG fl = SHORT1FROMMP(mp1);
774 ULONG chCode = SHORT1FROMMP(mp2);
775
776 if(!(fl & KC_CHAR)) {
777//SvL: Test
778 break;
779// goto RunDefWndProc;
780 }
781 if(fl & KC_VIRTUALKEY) {
782 if(virtualKey)
783 vkey = virtualKey;
784 else vkey = SHORT2FROMMP(mp2);
785 chCode = vkey;
786 }
787 if(fl & KC_KEYUP) {
788 keyflags |= KEY_UP;
789 }
790 if(fl & KC_ALT) {
791 keyflags |= KEY_ALTDOWN;
792 }
793 if(fl & KC_PREVDOWN) {
794 keyflags |= KEY_PREVDOWN;
795 }
796 if(fl & KC_DEADKEY) {
797 keyflags |= KEY_DEADKEY;
798 }
799 if(win32wnd->MsgChar(chCode, CHAR3FROMMP(mp1), CHAR4FROMMP(mp1), virtualKey, keyflags)) {
800//SvL: Test
801// goto RunDefWndProc;
802
803 }
804 }
805//SvL: Test
806// if(fRunDefWndProc) goto RunDefWndProc;
807 break;
808 }
809
810 case WM_INITMENU:
811 case WM_MENUSELECT:
812 case WM_MENUEND:
813 case WM_NEXTMENU:
814 goto RunDefWndProc;
815
816 case WM_TIMER:
817 if (mp2)
818 {
819 BOOL sys;
820 ULONG id;
821
822 dprintf(("OS2: WM_TIMER %x %d", hwnd, mp1));
823 if (TIMER_GetTimerInfo(hwnd,(ULONG)mp1,&sys,&id))
824 {
825 if (sys)
826 win32wnd->MsgSysTimer(id);
827 else
828 win32wnd->MsgTimer(id);
829 }
830 }
831 goto RunDefWndProc;
832
833 case WM_SETWINDOWPARAMS:
834 {
835 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
836
837 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
838 if(wndParams->fsStatus & WPM_TEXT) {
839 if(win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText)) {
840 goto RunDefWndProc;
841 }
842 }
843 goto RunDefWndProc;
844 }
845
846 case WM_QUERYWINDOWPARAMS:
847 {
848 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
849 ULONG textlen;
850 PSZ wintext;
851
852 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
853 {
854 if(wndpars->fsStatus & WPM_CCHTEXT)
855 wndpars->cchText = win32wnd->MsgGetTextLength();
856 if(wndpars->fsStatus & WPM_TEXT)
857 wndpars->pszText = win32wnd->MsgGetText();
858
859 wndpars->fsStatus = 0;
860 wndpars->cbCtlData = 0;
861 wndpars->cbPresParams = 0;
862 RestoreOS2TIB();
863 return (MRESULT)TRUE;
864 }
865 goto RunDefWndProc;
866 }
867
868 case WM_ERASEBACKGROUND:
869 {
870 dprintf(("OS2: WM_ERASEBACKGROUND %x", win32wnd->getWindowHandle()));
871 //CB: handled in WM_PAINT too, don't do it twice!
872
873 if (WinQueryUpdateRect (hwnd, NULL) && !win32wnd->isSupressErase()) {
874 BOOL erased = sendEraseBkgnd (win32wnd);
875 win32wnd->setEraseBkgnd (!erased, !erased);
876 }
877
878 break;
879 }
880
881 case WM_PAINT:
882 {
883 dprintf(("OS2: WM_PAINT %x", hwnd));
884
885 if (WinQueryUpdateRect (hwnd, NULL)) {
886 if (!win32wnd->isSupressErase()) {
887 BOOL erased = sendEraseBkgnd (win32wnd);
888 win32wnd->setEraseBkgnd (!erased, !erased);
889 }
890 }
891
892 win32wnd->setSupressErase (FALSE);
893
894 win32wnd->MsgPaint(0, 0);
895
896 //validate the update region, WM_PAINT has no return value
897 goto RunDefWndProc;
898 }
899
900 case WM_HITTEST:
901 // Only send this message if the window is enabled
902 if (WinIsWindowEnabled(hwnd))
903 {
904 if(win32wnd->MsgHitTest((*(POINTS *)&mp1).x, MapOS2ToWin32Y(OSLIB_HWND_DESKTOP, hwnd, (*(POINTS *)&mp1).y))) {
905 goto RunDefWndProc;
906 }
907 }
908 else goto RunDefWndProc;
909 break;
910
911 case WM_CONTEXTMENU:
912 {
913 POINTL pt;
914
915 dprintf(("OS2: WM_CONTEXTMENU %x", hwnd));
916 pt.x = (*(POINTS *)&mp1).x;
917 pt.y = (*(POINTS *)&mp1).y;
918 WinMapWindowPoints(hwnd,HWND_DESKTOP,&pt,1);
919 pt.y = WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN)-pt.y-1;
920 win32wnd->MsgContextMenu(pt.x,pt.y);
921
922 RestoreOS2TIB();
923 return (MRESULT)TRUE;
924 }
925
926 case WM_SYSCOLORCHANGE:
927 case WM_SYSVALUECHANGED:
928 case WM_SETSELECTION:
929 case WM_PPAINT:
930 case WM_PSETFOCUS:
931 case WM_PSYSCOLORCHANGE:
932 case WM_PSIZE:
933 case WM_PACTIVATE:
934 case WM_PCONTROL:
935 case WM_HELP:
936 case WM_APPTERMINATENOTIFY:
937 case WM_PRESPARAMCHANGED:
938 case WM_DRAWITEM:
939 case WM_MEASUREITEM:
940 case WM_CONTROLPOINTER:
941 case WM_QUERYDLGCODE:
942 case WM_SUBSTITUTESTRING:
943 case WM_MATCHMNEMONIC:
944 case WM_SAVEAPPLICATION:
945 case WM_SEMANTICEVENT:
946 default:
947// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
948 RestoreOS2TIB();
949 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
950 }
951 RestoreOS2TIB();
952 return (MRESULT)FALSE;
953
954RunDefWndProc:
955// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
956 RestoreOS2TIB();
957 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
958} /* End of Win32WindowProc */
959//******************************************************************************
960//******************************************************************************
961MRESULT EXPENTRY Win32SubclassWindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
962{
963 Win32BaseWindow* win32wnd;
964
965 //Restore our FS selector
966 SetWin32TIB();
967
968 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
969
970 if (!win32wnd)
971 {
972 dprintf(("Invalid win32wnd pointer for subclassed window %x!!", hwnd));
973 goto RunDefWndProc;
974 }
975
976 switch (msg)
977 {
978 case WM_WINDOWPOSCHANGED:
979 {
980 PSWP pswp = (PSWP)mp1;
981 SWP swpOld = *(pswp + 1);
982 WINDOWPOS wp;
983 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE;
984
985 dprintf(("OS2Subclass: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
986 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
987
988 hParent = hFrame = WinQueryWindow(hwnd, QW_PARENT);
989
990 OSLibMapSWPtoWINDOWPOS(pswp,&wp, &swpOld,hParent,hFrame);
991
992 win32wnd->setWindowRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
993 win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
994 wp.x = swpOld.x;
995 wp.y = swpOld.y;
996 wp.cx = swpOld.cx;
997 wp.cy = swpOld.cy;
998
999 wp.hwnd = win32wnd->getWindowHandle();
1000
1001 win32wnd->MsgPosChanged((LPARAM)&wp);
1002
1003 goto RunOldWndProc;
1004 }
1005
1006 default:
1007 goto RunDefHandler;
1008 }
1009
1010RunDefWndProc:
1011 RestoreOS2TIB();
1012 return WinDefWindowProc(hwnd,msg,mp1,mp2);
1013
1014RunOldWndProc:
1015 RestoreOS2TIB();
1016 return ((PFNWP)win32wnd->getOldWndProc())(hwnd,msg,mp1,mp2);
1017
1018RunDefHandler:
1019 RestoreOS2TIB();
1020 return Win32WindowProc(hwnd,msg,mp1,mp2);
1021}
1022
1023PVOID SubclassWithDefHandler(HWND hwnd)
1024{
1025 return WinSubclassWindow(hwnd,Win32SubclassWindowProc);
1026}
Note: See TracBrowser for help on using the repository browser.