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

Last change on this file since 1042 was 1042, checked in by sandervl, 26 years ago

Cursor fixes + minor change to RedrawWindow

File size: 27.1 KB
Line 
1/* $Id: pmwindow.cpp,v 1.7 1999-09-25 14:18:11 sandervl 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
15#include <os2.h> /* PM header file */
16#include <os2wrap.h>
17#include <stdlib.h>
18#include "win32type.h"
19#include <winconst.h>
20#include <wprocess.h>
21#include <misc.h>
22#include <win32wbase.h>
23#include <win32dlg.h>
24#include "pmwindow.h"
25#include "oslibwin.h"
26#include "oslibutil.h"
27#include "oslibgdi.h"
28#include "oslibmsg.h"
29#include "dc.h"
30
31HMQ hmq = 0; /* Message queue handle */
32HAB hab = 0;
33
34RECTL desktopRectl = {0};
35ULONG ScreenWidth = 0;
36ULONG ScreenHeight = 0;
37
38MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
39
40//******************************************************************************
41//Initialize PM; create hab, message queue and register special Win32 window classes
42//******************************************************************************
43BOOL InitPM()
44{
45 hab = WinInitialize(0);
46 dprintf(("Winitialize returned %x", hab));
47 hmq = WinCreateMsgQueue(hab, 0);
48
49 if(!hab || !hmq)
50 {
51 UINT error;
52 //CB: only fail on real error
53 error = WinGetLastError(hab) & 0xFFFF; //error code
54 if (!hab || error != PMERR_MSG_QUEUE_ALREADY_EXISTS)
55 {
56 dprintf(("WinInitialize or WinCreateMsgQueue failed %x %x", hab, hmq));
57 dprintf((" Error = %x",error));
58 return(FALSE);
59 }
60 else
61 {
62 if(!hab) {
63 hab = WinQueryAnchorBlock(HWND_DESKTOP);
64 dprintf(("WinQueryAnchorBlock returned %x", hab));
65 }
66 if(!hmq) {
67 hmq = HMQ_CURRENT;
68 }
69 }
70 }
71 SetThreadHAB(hab);
72 dprintf(("InitPM: hmq = %x", hmq));
73 SetThreadMessageQueue(hmq);
74
75 if(!WinRegisterClass( /* Register window class */
76 hab, /* Anchor block handle */
77 (PSZ)WIN32_STDCLASS, /* Window class name */
78 (PFNWP)Win32WindowProc, /* Address of window procedure */
79 CS_SIZEREDRAW | CS_HITTEST | CS_MOVENOTIFY,
80 NROF_WIN32WNDBYTES)) {
81 dprintf(("WinRegisterClass Win32BaseWindow failed"));
82 return(FALSE);
83 }
84
85 WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
86 ScreenWidth = desktopRectl.xRight;
87 ScreenHeight = desktopRectl.yTop;
88
89 dprintf(("InitPM: Desktop (%d,%d)", ScreenWidth, ScreenHeight));
90 return OSLibInitMsgQueue();
91} /* End of main */
92//******************************************************************************
93//Win32 window message handler
94//******************************************************************************
95MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
96{
97 POSTMSG_PACKET *postmsg;
98 OSLIBPOINT point, ClientPoint;
99 Win32BaseWindow *win32wnd;
100 APIRET rc;
101
102 //Restore our FS selector
103 SetWin32TIB();
104
105 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
106
107 if(msg != WM_CREATE && win32wnd == NULL) {
108 dprintf(("Invalid win32wnd pointer for window %x!!", hwnd));
109 goto RunDefWndProc;
110 }
111 if(msg > WIN32APP_USERMSGBASE) {
112 //win32 app user message
113 dprintf(("PMWINDOW: Message %x (%x,%x) posted to window %x", (ULONG)msg-WIN32APP_USERMSGBASE, mp1, mp2, hwnd));
114 win32wnd->SendMessageA((ULONG)msg-WIN32APP_USERMSGBASE, (ULONG)mp1, (ULONG)mp2);
115 }
116 switch( msg )
117 {
118 //OS/2 msgs
119 case WM_CREATE:
120 //Processing is done in after WinCreateWindow returns
121 dprintf(("OS2: WM_CREATE %x", hwnd));
122 RestoreOS2TIB();
123 return (MRESULT)FALSE;
124
125 case WM_QUIT:
126 dprintf(("OS2: WM_QUIT %x", hwnd));
127 if(win32wnd->MsgQuit()) {
128 goto RunDefWndProc;
129 }
130 break;
131
132 case WM_CLOSE:
133 dprintf(("OS2: WM_CLOSE %x", hwnd));
134// win32wnd->RemoveFakeOpen32();
135 if(win32wnd->MsgClose()) {
136 goto RunDefWndProc;
137 }
138 break;
139
140 case WM_DESTROY:
141 dprintf(("OS2: WM_DESTROY %x", hwnd));
142 if(win32wnd->MsgDestroy()) {
143 goto RunDefWndProc;
144 }
145 break;
146
147 case WM_ENABLE:
148 dprintf(("OS2: WM_ENABLE %x", hwnd));
149 if(win32wnd->MsgEnable((ULONG)mp1)) {
150 goto RunDefWndProc;
151 }
152 break;
153
154 case WM_SHOW:
155 dprintf(("OS2: WM_SHOW %x", hwnd));
156 if(win32wnd->MsgShow((ULONG)mp1)) {
157 goto RunDefWndProc;
158 }
159 break;
160
161 case WM_ADJUSTWINDOWPOS:
162 {
163 PSWP pswp = (PSWP)mp1;
164 SWP swpOld;
165 WINDOWPOS wp;
166 ULONG parentHeight = 0;
167 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE;
168
169 dprintf(("OS2: WM_ADJUSTWINDOWPOS %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
170
171 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
172
173 WinQueryWindowPos(hwnd, &swpOld);
174
175 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
176 if (win32wnd->isChild())
177 hParent = win32wnd->getParent()->getOS2WindowHandle();
178 else
179 hFrame = win32wnd->getOS2FrameWindowHandle();
180 }
181 OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, hParent, hFrame);
182
183 wp.hwnd = win32wnd->getWindowHandle();
184 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
185 {
186 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
187 if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
188 }
189 win32wnd->MsgPosChanging((LPARAM)&wp);
190 break;
191 }
192
193 case WM_WINDOWPOSCHANGED:
194 {
195 PSWP pswp = (PSWP)mp1;
196 PSWP pswpo = pswp + 1;
197 WINDOWPOS wp;
198 ULONG parentHeight = 0;
199 HWND hParent = NULLHANDLE, hFrame = NULLHANDLE;
200 LONG yDelta = pswp->cy - pswpo->cy;
201 ULONG classStyle;
202
203 dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
204
205 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) break;
206
207 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
208 if (win32wnd->isChild())
209 hParent = win32wnd->getParent()->getOS2WindowHandle();
210 else
211 hFrame = win32wnd->getOS2FrameWindowHandle();
212 }
213 OSLibMapSWPtoWINDOWPOS(pswp, &wp, pswpo, hParent, hFrame);
214
215 win32wnd->setWindowRect(wp.x, wp.y, wp.x + wp.cx, wp.y + wp.cy);
216 win32wnd->setClientRect(pswpo->x, pswpo->y, pswpo->x + pswpo->cx, pswpo->y + pswpo->cy);
217
218 wp.hwnd = win32wnd->getWindowHandle();
219 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
220 {
221 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
222 wp.hwndInsertAfter = wndAfter->getWindowHandle();
223 }
224 classStyle = win32wnd->getClass()->getStyle();
225 if ((yDelta != 0) && ((classStyle & CS_VREDRAW_W) ||
226 ((classStyle & CS_HREDRAW_W) && (pswp->cx != pswpo->cx))))
227 {
228 HENUM henum = WinBeginEnumWindows(pswp->hwnd);
229 SWP swp[10];
230 int i = 0;
231 HWND hwnd;
232
233 while ((hwnd = WinGetNextWindow(henum)) != NULLHANDLE)
234 {
235#if 0
236 if (mdiClient )
237 {
238 continue;
239 }
240#endif
241 WinQueryWindowPos(hwnd, &(swp[i]));
242 swp[i].y += yDelta;
243
244 if (i == 9)
245 {
246 WinSetMultWindowPos(GetThreadHAB(), swp, 10);
247 i = 0;
248 }
249 else
250 {
251 i++;
252 }
253 }
254
255 WinEndEnumWindows(henum);
256
257 if (i)
258 WinSetMultWindowPos(GetThreadHAB(), swp, i);
259 }
260 win32wnd->MsgPosChanged((LPARAM)&wp);
261
262 break;
263 }
264
265 case WM_ERASEBACKGROUND:
266 {
267 if (!win32wnd->isSupressErase()) {
268 BOOL erased = sendEraseBkgnd (win32wnd);
269 win32wnd->setEraseBkgnd (!erased, !erased);
270 }
271 break;
272 }
273
274 case WM_MOVE:
275 {
276 if (!win32wnd->isFrameWindow()) break;
277
278 HWND hFrame = win32wnd->getOS2FrameWindowHandle();
279 SWP swp, swpo;
280 WINDOWPOS wp;
281 ULONG parentHeight = 0;
282 RECTL rcl;
283
284 WinQueryWindowRect (hwnd, &rcl);
285 WinMapWindowPoints (hwnd, hFrame, (PPOINTL)&rcl, 2);
286 swp.x = swpo.x = rcl.xLeft;
287 swp.y = swpo.y = rcl.yBottom;
288 swp.cx = swpo.cx = rcl.xRight - rcl.xLeft;
289 swp.cy = swpo.cy = rcl.yTop - rcl.yBottom;
290 swp.fl = SWP_MOVE | SWP_NOREDRAW;
291 swp.hwnd = hwnd;
292 swp.hwndInsertBehind = NULLHANDLE;
293
294 OSLibMapSWPtoWINDOWPOS(&swp, &wp, &swpo, NULLHANDLE, hFrame);
295
296 wp.flags &= ~SWP_NOMOVE_W;
297 wp.hwnd = win32wnd->getWindowHandle();
298 win32wnd->setWindowRect(wp.x, wp.y, wp.x + wp.cx, wp.y + wp.cy);
299 win32wnd->setClientRect(swpo.x, swpo.y, swpo.x + swpo.cx, swpo.y + swpo.cy);
300 win32wnd->MsgPosChanged((LPARAM)&wp);
301 break;
302 }
303 case WM_SIZE:
304 {
305 break;
306 }
307
308 case WM_ACTIVATE:
309 {
310 HWND hwndActivate = (HWND)mp1;
311
312 dprintf(("OS2: WM_ACTIVATE %x", hwnd));
313 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
314 //another (non-win32) application's window
315 //set to NULL (allowed according to win32 SDK) to avoid problems
316 hwndActivate = NULL;
317 }
318 if(win32wnd->MsgActivate(1, hwndActivate)) {
319 goto RunDefWndProc;
320 }
321 break;
322 }
323 case WM_FOCUSCHANGE:
324 dprintf(("OS2: WM_FOCUSCHANGE %x", hwnd));
325 goto RunDefWndProc;
326
327 case WM_SETFOCUS:
328 {
329 HWND hwndFocus = (HWND)mp1;
330
331 dprintf(("OS2: WM_SETFOCUS %x %d", hwnd, mp2));
332 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
333 //another (non-win32) application's window
334 //set to NULL (allowed according to win32 SDK) to avoid problems
335 hwndFocus = NULL;
336 }
337 if((ULONG)mp2 == TRUE) {
338 rc = win32wnd->MsgSetFocus(hwndFocus);
339 }
340 else rc = win32wnd->MsgKillFocus(hwndFocus);
341 if(rc) {
342 goto RunDefWndProc;
343 }
344 break;
345 }
346 //**************************************************************************
347 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
348 //**************************************************************************
349 case WM_BUTTON1DOWN:
350 dprintf(("OS2: WM_BUTTON1DOWN %x", hwnd));
351 point.x = (*(POINTS *)&mp1).x;
352 point.y = (*(POINTS *)&mp1).y;
353 ClientPoint.x = point.x;
354 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
355 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
356 if(win32wnd->MsgButton(BUTTON_LEFTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
357 goto RunDefWndProc;
358 }
359 break;
360
361 case WM_BUTTON1UP:
362 dprintf(("OS2: WM_BUTTON1UP %x", hwnd));
363 point.x = (*(POINTS *)&mp1).x;
364 point.y = (*(POINTS *)&mp1).y;
365 ClientPoint.x = point.x;
366 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
367 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
368 if(win32wnd->MsgButton(BUTTON_LEFTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
369 goto RunDefWndProc;
370 }
371 break;
372 case WM_BUTTON1DBLCLK:
373 point.x = (*(POINTS *)&mp1).x;
374 point.y = (*(POINTS *)&mp1).y;
375 ClientPoint.x = point.x;
376 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
377 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
378 if(win32wnd->MsgButton(BUTTON_LEFTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
379 goto RunDefWndProc;
380 }
381 break;
382 case WM_BUTTON2DOWN:
383 point.x = (*(POINTS *)&mp1).x;
384 point.y = (*(POINTS *)&mp1).y;
385 ClientPoint.x = point.x;
386 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
387 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
388 if(win32wnd->MsgButton(BUTTON_RIGHTDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
389 goto RunDefWndProc;
390 }
391 break;
392 case WM_BUTTON2UP:
393 point.x = (*(POINTS *)&mp1).x;
394 point.y = (*(POINTS *)&mp1).y;
395 ClientPoint.x = point.x;
396 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
397 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
398 if(win32wnd->MsgButton(BUTTON_RIGHTUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
399 goto RunDefWndProc;
400 }
401 break;
402 case WM_BUTTON2DBLCLK:
403 point.x = (*(POINTS *)&mp1).x;
404 point.y = (*(POINTS *)&mp1).y;
405 ClientPoint.x = point.x;
406 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
407 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
408 if(win32wnd->MsgButton(BUTTON_RIGHTDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
409 goto RunDefWndProc;
410 }
411 break;
412 case WM_BUTTON3DOWN:
413 point.x = (*(POINTS *)&mp1).x;
414 point.y = (*(POINTS *)&mp1).y;
415 ClientPoint.x = point.x;
416 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
417 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
418 if(win32wnd->MsgButton(BUTTON_MIDDLEDOWN, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
419 goto RunDefWndProc;
420 }
421 break;
422 case WM_BUTTON3UP:
423 point.x = (*(POINTS *)&mp1).x;
424 point.y = (*(POINTS *)&mp1).y;
425 ClientPoint.x = point.x;
426 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
427 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
428 if(win32wnd->MsgButton(BUTTON_MIDDLEUP, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
429 goto RunDefWndProc;
430 }
431 break;
432 case WM_BUTTON3DBLCLK:
433 point.x = (*(POINTS *)&mp1).x;
434 point.y = (*(POINTS *)&mp1).y;
435 ClientPoint.x = point.x;
436 ClientPoint.y = MapOS2ToWin32Y(hwnd, 1, point.y);
437 MapOS2ToWin32Point(OSLIB_HWND_DESKTOP, hwnd, &point);
438 if(win32wnd->MsgButton(BUTTON_MIDDLEDBLCLICK, point.x, point.y, ClientPoint.x, ClientPoint.y)) {
439 goto RunDefWndProc;
440 }
441 break;
442
443 case WM_BUTTON2MOTIONSTART:
444 case WM_BUTTON2MOTIONEND:
445 case WM_BUTTON2CLICK:
446 case WM_BUTTON1MOTIONSTART:
447 case WM_BUTTON1MOTIONEND:
448 case WM_BUTTON1CLICK:
449 case WM_BUTTON3MOTIONSTART:
450 case WM_BUTTON3MOTIONEND:
451 case WM_BUTTON3CLICK:
452 goto RunDefWndProc;
453
454 case WM_MOUSEMOVE:
455 {
456 //Only send this message when the mouse isn't captured
457 if(WinQueryCapture(HWND_DESKTOP) != NULLHANDLE) {
458 goto RunDefWndProc;
459 }
460 ULONG keystate = 0;
461 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1))
462 keystate |= WMMOVE_LBUTTON;
463 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2))
464 keystate |= WMMOVE_MBUTTON;
465 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3))
466 keystate |= WMMOVE_RBUTTON;
467 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT))
468 keystate |= WMMOVE_SHIFT;
469 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL))
470 keystate |= WMMOVE_CTRL;
471
472 //OS/2 Window coordinates -> Win32 Window coordinates
473 //NOTE: Do not call the default OS/2 window handler as that one changes
474 // the mousepointer!
475 win32wnd->MsgMouseMove(keystate, SHORT1FROMMP(mp1), MapOS2ToWin32Y(win32wnd, SHORT2FROMMP(mp1)));
476 break;
477 }
478
479 //**************************************************************************
480 //Slider messages
481 //**************************************************************************
482 case WM_VSCROLL:
483 case WM_HSCROLL:
484
485 case WM_CONTROL:
486
487 case WM_COMMAND:
488 if(SHORT1FROMMP(mp2) == CMDSRC_MENU) {
489 win32wnd->MsgCommand(CMD_MENU, SHORT1FROMMP(mp1), 0);
490 }
491 if(SHORT1FROMMP(mp2) == CMDSRC_ACCELERATOR) {
492 win32wnd->MsgCommand(CMD_ACCELERATOR, SHORT1FROMMP(mp1), 0);
493 }
494 //todo controls + accelerators
495 break;
496
497 case WM_SYSCOMMAND:
498 {
499 ULONG x = 0, y = 0;
500 ULONG win32sc;
501
502 if(SHORT2FROMMP(mp2) == TRUE) {//syscommand caused by mouse action
503 POINTL pointl;
504 WinQueryPointerPos(HWND_DESKTOP, &pointl);
505 x = pointl.x;
506 y = ScreenHeight - y;
507 }
508 switch(SHORT1FROMMP(mp1)) {
509 case SC_MOVE:
510 win32sc = WIN32SC_MOVE;
511 break;
512 case SC_CLOSE:
513 win32sc = WIN32SC_CLOSE;
514 break;
515 case SC_MAXIMIZE:
516 win32sc = WIN32SC_MAXIMIZE;
517 break;
518 case SC_MINIMIZE:
519 win32sc = WIN32SC_MINIMIZE;
520 break;
521 case SC_NEXTFRAME:
522 case SC_NEXTWINDOW:
523 win32sc = WIN32SC_NEXTWINDOW;
524 break;
525 case SC_RESTORE:
526 win32sc = WIN32SC_RESTORE;
527 break;
528 case SC_TASKMANAGER:
529 win32sc = WIN32SC_TASKLIST;
530 break;
531 default:
532 goto RunDefWndProc;
533 }
534 dprintf(("WM_SYSCOMMAND %x %x (%d,%d)", hwnd, win32sc, x, y));
535 if(win32wnd->MsgSysCommand(win32sc, x, y)) {
536 goto RunDefWndProc;
537 }
538 break;
539 }
540 case WM_CHAR:
541 {
542 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
543 ULONG flags = SHORT1FROMMP(mp1);
544 BOOL keyWasPressed;
545 char c;
546 USHORT virtualKeyTable [66] = {
547 0x00, // OS/2 VK Win32 VK, Entry 0 is not used
548 0x01, // VK_BUTTON1 VK_LBUTTON
549 0x02, // VK_BUTTON2 VK_RBUTTON
550 0x04, // VK_BUTTON3 VK_MBUTTON
551 0x03, // VK_BREAK VK_CANCEL
552 0x08, // VK_BACKSPACE VK_BACK
553 0x09, // VK_TAB VK_TAB
554 0x00, // VK_BACKTAB No equivalent!
555 0x0D, // VK_NEWLINE VK_RETURN
556 0x10, // VK_SHIFT VK_SHIFT
557 0x11, // VK_CTRL VK_CONTROL
558 0x12, // VK_ALT VK_MENU, best match I guess
559 0x12, // VK_ALTGRAF VK_MENU, best match I guess
560 0x13, // VK_PAUSE VK_PAUSE
561 0x14, // VK_CAPSLOCK VK_CAPITAL
562 0x1B, // VK_ESC VK_ESCAPE
563 0x20, // VK_SPACE VK_SPACE
564 0x00, // VK_PAGEUP No equivalent! At least, I think
565 0x00, // VK_PAGEDOWN No equivalent! At least, I think
566 0x23, // VK_END VK_END
567 0x24, // VK_HOME VK_HOME
568 0x25, // VK_LEFT VK_LEFT
569 0x26, // VK_UP VK_UP
570 0x27, // VK_RIGHT VK_RIGHT
571 0x28, // VK_DOWN VK_DOWN
572 0x2C, // VK_PRINTSCRN VK_SNAPSHOT
573 0x2D, // VK_INSERT VK_INSERT
574 0x2E, // VK_DELETE VK_DELETE
575 0x91, // VK_SCRLLOCK VK_SCROLL
576 0x90, // VK_NUMLOCK VK_NUMLOCK
577 0x2B, // VK_ENTER VK_EXECUTE, best match I guess
578 0x00, // VK_SYSRQ No equivalent!
579 0x70, // VK_F1 VK_F1
580 0x71, // VK_F2 VK_F2
581 0x72, // VK_F3 VK_F3
582 0x73, // VK_F4 VK_F4
583 0x74, // VK_F5 VK_F5
584 0x75, // VK_F6 VK_F6
585 0x76, // VK_F7 VK_F7
586 0x77, // VK_F8 VK_F8
587 0x78, // VK_F9 VK_F9
588 0x79, // VK_F10 VK_F10
589 0x7A, // VK_F11 VK_F11
590 0x7B, // VK_F12 VK_F12
591 0x7C, // VK_F13 VK_F13
592 0x7D, // VK_F14 VK_F14
593 0x7E, // VK_F15 VK_F15
594 0x7F, // VK_F16 VK_F16
595 0x80, // VK_F17 VK_F17
596 0x81, // VK_F18 VK_F18
597 0x82, // VK_F19 VK_F19
598 0x83, // VK_F20 VK_F20
599 0x84, // VK_F21 VK_F21
600 0x85, // VK_F22 VK_F22
601 0x86, // VK_F23 VK_F23
602 0x87, // VK_F24 VK_F24
603 0x00, // VK_ENDDRAG No equivalent!
604 0x0C, // VK_CLEAR VK_CLEAR
605 0xF9, // VK_EREOF VK_EREOF
606 0xFD, // VK_PA1 VK_PA1
607 0xF6, // VK_ATTN VK_ATTN
608 0xF7, // VK_CRSEL VK_CRSEL
609 0xF8, // VK_EXSEL VK_EXSEL
610 0x00, // VK_COPY No equivalent!
611 0x00, // VK_BLK1 No equivalent!
612 0x00}; // VK_BLK2 No equivalent!
613
614
615 repeatCount = SHORT2FROMMP (mp1) >> 8;
616 scanCode = SHORT2FROMMP (mp1) & 255;
617 keyWasPressed = ((SHORT1FROMMP (mp1) & KC_PREVDOWN) == KC_PREVDOWN);
618
619 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
620 // given the OS/2 virtual key and OS/2 character
621
622 if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
623 ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
624 {
625 c = SHORT1FROMMP (mp2);
626 if ((c >= 'A') && (c <= 'Z')) {
627 virtualKey = c;
628 goto VirtualKeyFound;
629 }
630 if ((c >='a') && (c <= 'z')) {
631 virtualKey = c - 32; // make it uppercase
632 goto VirtualKeyFound;
633 }
634 if ((c >= '0') && (c <= '9')) {
635 virtualKey = c;
636 goto VirtualKeyFound;
637 }
638 }
639
640 // convert OS/2 virtual keys to Win32 virtual key
641 if (SHORT2FROMMP (mp2) <= VK_BLK2)
642 virtualKey = virtualKeyTable [SHORT2FROMMP (mp2)];
643
644VirtualKeyFound:
645
646 if ((WinGetKeyState (HWND_DESKTOP, VK_ALT) & 0x8000) == 0)
647 {
648 //
649 // the Alt key is not pressed
650 //
651 if ((flags & KC_KEYUP) == KC_KEYUP) {
652 // send WM_KEYUP message
653
654 if(win32wnd->MsgKeyUp (repeatCount, scanCode, virtualKey)) {
655 goto RunDefWndProc;
656 }
657 }
658 else {
659 // send WM_KEYDOWN message
660 if (win32wnd->MsgKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
661 goto RunDefWndProc;
662 }
663 }
664 else {
665 //
666 // the Alt key is pressed
667 //
668 if ((flags & KC_KEYUP) == KC_KEYUP) {
669 // send WM_SYSKEYUP message
670
671 if(win32wnd->MsgSysKeyUp (repeatCount, scanCode, virtualKey)) {
672 goto RunDefWndProc;
673 }
674 }
675 else {
676 // send WM_SYSKEYDOWN message
677 if (win32wnd->MsgSysKeyDown (repeatCount, scanCode, virtualKey, keyWasPressed))
678 goto RunDefWndProc;
679 }
680 }
681
682 break;
683 }
684#if 0
685 case WM_CHAR:
686 {
687 ULONG keyflags = 0, vkey = 0;
688 ULONG fl = SHORT1FROMMP(mp1);
689
690 if(!(fl & KC_CHAR)) {
691// dprintf(("WM_CHAR: no valid character code"));
692 goto RunDefWndProc;
693 }
694 if(fl & KC_VIRTUALKEY) {
695 vkey = SHORT2FROMMP(mp2);
696 }
697 if(fl & KC_KEYUP) {
698 keyflags |= KEY_UP;
699 }
700 if(fl & KC_ALT) {
701 keyflags |= KEY_ALTDOWN;
702 }
703 if(fl & KC_PREVDOWN) {
704 keyflags |= KEY_PREVDOWN;
705 }
706 if(fl & KC_DEADKEY) {
707 keyflags |= KEY_DEADKEY;
708 }
709 if(win32wnd->MsgChar(SHORT1FROMMP(mp2), CHAR3FROMMP(mp1), CHAR4FROMMP(mp1), vkey, keyflags)) {
710 goto RunDefWndProc;
711 }
712 break;
713 }
714#endif
715 case WM_INITMENU:
716 case WM_MENUSELECT:
717 case WM_MENUEND:
718 case WM_NEXTMENU:
719 break;
720
721 case WM_TIMER:
722 win32wnd->MsgTimer((ULONG)mp1);
723 goto RunDefWndProc;
724
725 case WM_SETWINDOWPARAMS:
726 {
727 WNDPARAMS *wndParams = (WNDPARAMS *)mp1;
728
729 dprintf(("OS2: WM_SETWINDOWPARAMS %x", hwnd));
730 if(wndParams->fsStatus & WPM_TEXT) {
731 if(win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText)) {
732 goto RunDefWndProc;
733 }
734 }
735 goto RunDefWndProc;
736 }
737
738 case WM_QUERYWINDOWPARAMS:
739 {
740 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
741 ULONG textlen;
742 PSZ wintext;
743
744 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT)) {
745 if(wndpars->fsStatus & WPM_CCHTEXT)
746 wndpars->cchText = win32wnd->MsgGetTextLength();
747 if(wndpars->fsStatus & WPM_TEXT)
748 wndpars->pszText = win32wnd->MsgGetText();
749 return (MRESULT)TRUE;
750 }
751 goto RunDefWndProc;
752 }
753
754 case WM_PAINT:
755 dprintf(("OS2: WM_PAINT %x", hwnd));
756
757 if (WinQueryUpdateRect (hwnd, NULL)) {
758 if (!win32wnd->isSupressErase()) {
759 BOOL erased = sendEraseBkgnd (win32wnd);
760 win32wnd->setEraseBkgnd (!erased, !erased);
761 }
762 }
763 win32wnd->setSupressErase (FALSE);
764
765 if(win32wnd->MsgPaint(0, 0)) {
766 goto RunDefWndProc;
767 }
768 break;
769
770 case WM_HITTEST:
771 // Only send this message if the window is enabled
772 if (WinIsWindowEnabled(hwnd))
773 {
774 if(win32wnd->MsgHitTest((*(POINTS *)&mp1).x, MapOS2ToWin32Y(OSLIB_HWND_DESKTOP, hwnd, (*(POINTS *)&mp1).y))) {
775 goto RunDefWndProc;
776 }
777 }
778 else goto RunDefWndProc;
779 break;
780
781 case WM_SYSCOLORCHANGE:
782 case WM_SYSVALUECHANGED:
783 case WM_CALCVALIDRECTS:
784 case WM_SETSELECTION:
785 case WM_PPAINT:
786 case WM_PSETFOCUS:
787 case WM_PSYSCOLORCHANGE:
788 case WM_PSIZE:
789 case WM_PACTIVATE:
790 case WM_PCONTROL:
791 case WM_HELP:
792 case WM_APPTERMINATENOTIFY:
793 case WM_PRESPARAMCHANGED:
794 case WM_DRAWITEM:
795 case WM_MEASUREITEM:
796 case WM_CONTROLPOINTER:
797 case WM_QUERYDLGCODE:
798 case WM_SUBSTITUTESTRING:
799 case WM_MATCHMNEMONIC:
800 case WM_SAVEAPPLICATION:
801 case WM_SEMANTICEVENT:
802 default:
803// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
804 RestoreOS2TIB();
805 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
806 }
807 RestoreOS2TIB();
808 return (MRESULT)FALSE;
809
810RunDefWndProc:
811// dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
812 RestoreOS2TIB();
813 return WinDefWindowProc( hwnd, msg, mp1, mp2 );
814} /* End of Win32WindowProc */
815//******************************************************************************
816//******************************************************************************
Note: See TracBrowser for help on using the repository browser.