source: trunk/src/user32/new/oslibmsgtranslate.cpp@ 2291

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

first few changes

File size: 26.6 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.2 2000-01-01 17:07:41 cbratschi Exp $ */
2/*
3 * Window message translation functions for OS/2
4 *
5 *
6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1999 Daniela Engert (dani@ngrt.de)
8 * Copyright 1999 Rene Pronk (R.Pronk@twi.tudelft.nl)
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 * TODO: Extra msgs: which messages must be put into the queue and which can be sent directly?
13 * (According to the docs TranslateMessage really inserts a msg in the queue)
14 * TODO: Filter translation isn't correct for posted messages
15 *
16 */
17#define INCL_WIN
18#define INCL_PM
19#define INCL_DOSPROCESS
20#include <os2.h>
21#include <os2wrap.h>
22#include <string.h>
23#include <misc.h>
24#include "oslibmsg.h"
25#include <win32wnd.h>
26#include "oslibutil.h"
27#include "timer.h"
28#include <thread.h>
29#include <wprocess.h>
30#include "pmwindow.h"
31#include "oslibwin.h"
32
33//Used for key translation while processing WM_CHAR message
34USHORT virtualKeyTable [66] = {
35 0x00, // OS/2 VK Win32 VK, Entry 0 is not used
36 0x01, // VK_BUTTON1 VK_LBUTTON
37 0x02, // VK_BUTTON2 VK_RBUTTON
38 0x04, // VK_BUTTON3 VK_MBUTTON
39 0x03, // VK_BREAK VK_CANCEL
40 0x08, // VK_BACKSPACE VK_BACK
41 0x09, // VK_TAB VK_TAB
42 0x00, // VK_BACKTAB No equivalent!
43 0x0A, // VK_NEWLINE 0x0A (no VK_* def)
44 0x10, // VK_SHIFT VK_SHIFT
45 0x11, // VK_CTRL VK_CONTROL
46 0x12, // VK_ALT VK_MENU, best match I guess
47 0x12, // VK_ALTGRAF VK_MENU, best match I guess
48 0x13, // VK_PAUSE VK_PAUSE
49 0x14, // VK_CAPSLOCK VK_CAPITAL
50 0x1B, // VK_ESC VK_ESCAPE
51 0x20, // VK_SPACE VK_SPACE
52 0x21, // VK_PAGEUP VK_PRIOR
53 0x22, // VK_PAGEDOWN VK_NEXT
54 0x23, // VK_END VK_END
55 0x24, // VK_HOME VK_HOME
56 0x25, // VK_LEFT VK_LEFT
57 0x26, // VK_UP VK_UP
58 0x27, // VK_RIGHT VK_RIGHT
59 0x28, // VK_DOWN VK_DOWN
60 0x2C, // VK_PRINTSCRN VK_SNAPSHOT
61 0x2D, // VK_INSERT VK_INSERT
62 0x2E, // VK_DELETE VK_DELETE
63 0x91, // VK_SCRLLOCK VK_SCROLL
64 0x90, // VK_NUMLOCK VK_NUMLOCK
65 0x0D, // VK_ENTER VK_RETURN
66 0x00, // VK_SYSRQ No equivalent!
67 0x70, // VK_F1 VK_F1
68 0x71, // VK_F2 VK_F2
69 0x72, // VK_F3 VK_F3
70 0x73, // VK_F4 VK_F4
71 0x74, // VK_F5 VK_F5
72 0x75, // VK_F6 VK_F6
73 0x76, // VK_F7 VK_F7
74 0x77, // VK_F8 VK_F8
75 0x78, // VK_F9 VK_F9
76 0x79, // VK_F10 VK_F10
77 0x7A, // VK_F11 VK_F11
78 0x7B, // VK_F12 VK_F12
79 0x7C, // VK_F13 VK_F13
80 0x7D, // VK_F14 VK_F14
81 0x7E, // VK_F15 VK_F15
82 0x7F, // VK_F16 VK_F16
83 0x80, // VK_F17 VK_F17
84 0x81, // VK_F18 VK_F18
85 0x82, // VK_F19 VK_F19
86 0x83, // VK_F20 VK_F20
87 0x84, // VK_F21 VK_F21
88 0x85, // VK_F22 VK_F22
89 0x86, // VK_F23 VK_F23
90 0x87, // VK_F24 VK_F24
91 0x00, // VK_ENDDRAG No equivalent!
92 0x0C, // VK_CLEAR VK_CLEAR
93 0xF9, // VK_EREOF VK_EREOF
94 0xFD, // VK_PA1 VK_PA1
95 0xF6, // VK_ATTN VK_ATTN
96 0xF7, // VK_CRSEL VK_CRSEL
97 0xF8, // VK_EXSEL VK_EXSEL
98 0x00, // VK_COPY No equivalent!
99 0x00, // VK_BLK1 No equivalent!
100 0x00}; // VK_BLK2 No equivalent!
101
102//******************************************************************************
103//******************************************************************************
104BOOL OS2ToWinMsgTranslate(void *pThdb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fMsgRemoved)
105{
106 Win32BaseWindow *win32wnd = 0;
107 OSLIBPOINT point, ClientPoint;
108 POSTMSG_PACKET *packet;
109 THDB *thdb = (THDB *)pThdb;
110 int i;
111
112 memset(winMsg, 0, sizeof(MSG));
113 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(os2Msg->hwnd);
114 //PostThreadMessage posts WIN32APP_POSTMSG msg without window handle
115 if((win32wnd == 0 && os2Msg->msg != WM_CREATE && os2Msg->msg != WIN32APP_POSTMSG))
116 {
117 goto dummymessage; //not a win32 client window
118 }
119 winMsg->time = os2Msg->time;
120 winMsg->pt.x = os2Msg->ptl.x;
121 winMsg->pt.y = mapScreenY(os2Msg->ptl.y);
122 if(win32wnd) //==0 for WM_CREATE
123 winMsg->hwnd = win32wnd->getWindowHandle();
124
125 if (win32wnd && (os2Msg->hwnd == win32wnd->getOS2FrameWindowHandle()))
126 {
127 //special frame messages
128
129 switch (os2Msg->msg)
130 {
131 case WM_BUTTON1DOWN:
132 case WM_BUTTON1UP:
133 case WM_BUTTON1DBLCLK:
134 case WM_BUTTON2DOWN:
135 case WM_BUTTON2UP:
136 case WM_BUTTON2DBLCLK:
137 case WM_BUTTON3DOWN:
138 case WM_BUTTON3UP:
139 case WM_BUTTON3DBLCLK:
140 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
141 if(win32wnd->lastHitTestVal != HTCLIENT_W) {
142 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
143 winMsg->wParam = win32wnd->lastHitTestVal;
144 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
145 }
146 else {
147 point.x = (*(POINTS *)&os2Msg->mp1).x;
148 point.y = (*(POINTS *)&os2Msg->mp1).y;
149 ClientPoint.x = point.x;
150 ClientPoint.y = mapOS2ToWin32Y(os2Msg->hwnd,win32wnd->getOS2WindowHandle(),point.y);
151
152 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
153 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
154 }
155
156 return TRUE;
157
158 case WM_BUTTON2MOTIONSTART:
159 case WM_BUTTON2MOTIONEND:
160 case WM_BUTTON2CLICK:
161 case WM_BUTTON1MOTIONSTART:
162 case WM_BUTTON1MOTIONEND:
163 case WM_BUTTON1CLICK:
164 case WM_BUTTON3MOTIONSTART:
165 case WM_BUTTON3MOTIONEND:
166 case WM_BUTTON3CLICK:
167 goto dummymessage;
168
169 case WM_MOUSEMOVE:
170 {
171 ULONG keystate = 0, setcursormsg = WINWM_MOUSEMOVE;
172
173 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & 0x8000)
174 keystate |= MK_LBUTTON_W;
175 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2) & 0x8000)
176 keystate |= MK_RBUTTON_W;
177 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) & 0x8000)
178 keystate |= MK_MBUTTON_W;
179 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x8000)
180 keystate |= MK_SHIFT_W;
181 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000)
182 keystate |= MK_CONTROL_W;
183
184 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
185 if(win32wnd->lastHitTestVal != HTCLIENT_W)
186 {
187 setcursormsg = WINWM_NCMOUSEMOVE;
188 winMsg->wParam = (WPARAM)win32wnd->lastHitTestVal;
189 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
190 } else
191 {
192 winMsg->wParam = (WPARAM)keystate;
193 winMsg->lParam = MAKELONG(SHORT1FROMMP(os2Msg->mp1),mapOS2ToWin32Y(win32wnd->getOS2FrameWindowHandle(),win32wnd->getOS2WindowHandle(),SHORT2FROMMP(os2Msg->mp1)));
194 }
195 //OS/2 Window coordinates -> Win32 Window coordinates
196 winMsg->message = setcursormsg;
197 return TRUE;
198 }
199
200 case WM_PAINT:
201 {
202 winMsg->message = WINWM_NCPAINT;
203 return TRUE;
204 }
205
206 case WM_HITTEST:
207 {
208 OSLIBPOINT pt;
209
210 pt.x = (*(POINTS *)&os2Msg->mp1).x;
211 pt.y = (*(POINTS *)&os2Msg->mp1).y;
212
213 mapOS2ToWin32Point(os2Msg->hwnd,OSLIB_HWND_DESKTOP,&pt);
214 winMsg->message = WINWM_NCHITTEST;
215 winMsg->wParam = 0;
216 winMsg->lParam = MAKELONG((USHORT)pt.x, (USHORT)pt.y);
217 return TRUE;
218 }
219 }
220 //do normal translation for all other messages
221 }
222
223 switch(os2Msg->msg)
224 {
225 case WIN32APP_POSTMSG:
226 {
227 packet = (POSTMSG_PACKET *)os2Msg->mp2;
228 if(packet && ((ULONG)os2Msg->mp1 == WIN32MSG_MAGICA || (ULONG)os2Msg->mp1 == WIN32MSG_MAGICW)) {
229 winMsg->message = packet->Msg;
230 winMsg->wParam = packet->wParam;
231 winMsg->lParam = packet->lParam;
232 if(fMsgRemoved == MSG_REMOVE) free(packet); //free the shared memory here
233 break;
234 }
235 goto dummymessage;
236 }
237
238 //OS/2 msgs
239 case WM_CREATE:
240 {
241 if(thdb->newWindow == 0) {
242 DebugInt3();
243 goto dummymessage;
244 }
245
246 win32wnd = (Win32BaseWindow *)thdb->newWindow;
247
248 winMsg->message = WINWM_CREATE;
249 winMsg->hwnd = win32wnd->getWindowHandle();
250 winMsg->wParam = 0;
251 winMsg->lParam = (LPARAM)win32wnd->tmpcs;
252 break;
253 }
254
255 case WM_QUIT:
256 winMsg->message = WINWM_QUIT;
257 break;
258
259 case WM_CLOSE:
260 winMsg->message = WINWM_CLOSE;
261 break;
262
263 case WM_DESTROY:
264 winMsg->message = WINWM_DESTROY;
265 break;
266
267 case WM_ENABLE:
268 winMsg->message = WINWM_ENABLE;
269 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
270 break;
271
272 case WM_SHOW:
273 winMsg->message = WINWM_SHOWWINDOW;
274 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
275 break;
276
277 case WM_WINDOWPOSCHANGED:
278 {
279 PSWP pswp = (PSWP)os2Msg->mp1;
280 SWP swpOld = *(pswp + 1);
281 HWND hParent = NULLHANDLE;
282 LONG yDelta = pswp->cy - swpOld.cy;
283 LONG xDelta = pswp->cx - swpOld.cx;
284
285 dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
286
287 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) goto dummymessage;
288
289 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
290 if (win32wnd->isChild()) {
291 if(win32wnd->getParent()) {
292 hParent = win32wnd->getParent()->getOS2WindowHandle();
293 }
294 else goto dummymessage; //parent has just been destroyed
295 }
296 }
297 OSLibMapSWPtoWINDOWPOS(pswp, &thdb->wp, &swpOld, hParent, win32wnd->getOS2FrameWindowHandle());
298
299 if (!win32wnd->CanReceiveSizeMsgs()) goto dummymessage;
300
301 dprintf(("Set client rectangle to (%d,%d)(%d,%d)", swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy));
302 win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
303
304 thdb->wp.hwnd = win32wnd->getWindowHandle();
305 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
306 {
307 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
308 thdb->wp.hwndInsertAfter = wndAfter->getWindowHandle();
309 }
310
311 PRECT lpRect = win32wnd->getWindowRect();
312 //SvL: Only send it when the client has changed & the frame hasn't
313 // If the frame size/position has changed, pmframe.cpp will send
314 // this message
315 if(lpRect->right == thdb->wp.x+thdb->wp.cx && lpRect->bottom == thdb->wp.y+thdb->wp.cy) {
316 winMsg->message = WINWM_WINDOWPOSCHANGED;
317 winMsg->lParam = (LPARAM)&thdb->wp;
318 }
319 else {
320 win32wnd->setWindowRect(thdb->wp.x, thdb->wp.y, thdb->wp.x+thdb->wp.cx, thdb->wp.y+thdb->wp.cy);
321 goto dummymessage;
322 }
323 }
324
325 case WM_ACTIVATE:
326 {
327 HWND hwndActivate = (HWND)os2Msg->mp2;
328 BOOL fMinimized = FALSE;
329
330 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
331 //another (non-win32) application's window
332 //set to NULL (allowed according to win32 SDK) to avoid problems
333 hwndActivate = NULL;
334 }
335 else hwndActivate = Win32BaseWindow::OS2ToWin32Handle(hwndActivate);
336
337 if(WinQueryWindowULong(os2Msg->hwnd, QWL_STYLE) & WS_MINIMIZED)
338 {
339 fMinimized = TRUE;
340 }
341
342 winMsg->message = WINWM_ACTIVATE;
343 winMsg->wParam = MAKELONG((SHORT1FROMMP(os2Msg->mp1)) ? WA_ACTIVE_W : WA_INACTIVE_W, fMinimized);
344 winMsg->lParam = (LPARAM)hwndActivate;
345 break;
346 }
347
348 case WM_SETFOCUS:
349 {
350 HWND hwndFocus = (HWND)os2Msg->mp1;
351
352 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
353 //another (non-win32) application's window
354 //set to NULL (allowed according to win32 SDK) to avoid problems
355 hwndFocus = NULL;
356 }
357 else hwndFocus = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
358
359 if((ULONG)os2Msg->mp2 == TRUE) {
360 winMsg->message = WINWM_SETFOCUS;
361 winMsg->wParam = (WPARAM)hwndFocus;
362 }
363 else {
364 winMsg->message = WINWM_KILLFOCUS;
365 winMsg->wParam = (WPARAM)hwndFocus;
366 }
367 break;
368 }
369
370 //**************************************************************************
371 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
372 //**************************************************************************
373 case WM_BUTTON1DOWN:
374 case WM_BUTTON1UP:
375 case WM_BUTTON1DBLCLK:
376 case WM_BUTTON2DOWN:
377 case WM_BUTTON2UP:
378 case WM_BUTTON2DBLCLK:
379 case WM_BUTTON3DOWN:
380 case WM_BUTTON3UP:
381 case WM_BUTTON3DBLCLK:
382 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
383 if(win32wnd->lastHitTestVal != HTCLIENT_W) {
384 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
385 winMsg->wParam = win32wnd->lastHitTestVal;
386 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
387 }
388 else {
389 point.x = (*(POINTS *)&os2Msg->mp1).x;
390 point.y = (*(POINTS *)&os2Msg->mp1).y;
391 ClientPoint.x = point.x;
392 ClientPoint.y = mapY(os2Msg->hwnd,point.y);
393
394 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
395 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
396 }
397
398 break;
399
400 case WM_BUTTON2MOTIONSTART:
401 case WM_BUTTON2MOTIONEND:
402 case WM_BUTTON2CLICK:
403 case WM_BUTTON1MOTIONSTART:
404 case WM_BUTTON1MOTIONEND:
405 case WM_BUTTON1CLICK:
406 case WM_BUTTON3MOTIONSTART:
407 case WM_BUTTON3MOTIONEND:
408 case WM_BUTTON3CLICK:
409 goto dummymessage;
410
411 case WM_MOUSEMOVE:
412 {
413 ULONG keystate = 0, setcursormsg = WINWM_MOUSEMOVE;
414
415 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & 0x8000)
416 keystate |= MK_LBUTTON_W;
417 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2) & 0x8000)
418 keystate |= MK_RBUTTON_W;
419 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) & 0x8000)
420 keystate |= MK_MBUTTON_W;
421 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x8000)
422 keystate |= MK_SHIFT_W;
423 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000)
424 keystate |= MK_CONTROL_W;
425
426 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
427 if(win32wnd->lastHitTestVal != HTCLIENT_W)
428 {
429 setcursormsg = WINWM_NCMOUSEMOVE;
430 winMsg->wParam = (WPARAM)win32wnd->lastHitTestVal;
431 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
432 } else
433 {
434 winMsg->wParam = (WPARAM)keystate;
435 winMsg->lParam = MAKELONG(SHORT1FROMMP(os2Msg->mp1),mapY(win32wnd,SHORT2FROMMP(os2Msg->mp1)));
436 }
437 //OS/2 Window coordinates -> Win32 Window coordinates
438 winMsg->message = setcursormsg;
439 break;
440 }
441
442 case WM_CONTROL:
443 goto dummymessage;
444
445 case WM_COMMAND:
446 if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
447 winMsg->message = WINWM_COMMAND;
448 winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
449 break;
450 }
451 //todo controls
452 goto dummymessage;
453
454 case WM_SYSCOMMAND:
455 {
456 ULONG x = 0, y = 0;
457 ULONG win32sc;
458
459 if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
460 POINTL pointl;
461 WinQueryPointerPos(HWND_DESKTOP, &pointl);
462 x = pointl.x;
463 y = mapScreenY(y);
464 }
465 switch(SHORT1FROMMP(os2Msg->mp1)) {
466 case SC_MOVE:
467 win32sc = SC_MOVE_W;
468 break;
469 case SC_CLOSE:
470 win32sc = SC_CLOSE_W;
471 break;
472 case SC_MAXIMIZE:
473 win32sc = SC_MAXIMIZE_W;
474 break;
475 case SC_MINIMIZE:
476 win32sc = SC_MINIMIZE_W;
477 break;
478 case SC_NEXTFRAME:
479 case SC_NEXTWINDOW:
480 win32sc = SC_NEXTWINDOW_W;
481 break;
482 case SC_RESTORE:
483 win32sc = SC_RESTORE_W;
484 break;
485 case SC_TASKMANAGER:
486 win32sc = SC_TASKLIST_W;
487 break;
488 default:
489 goto dummymessage;
490 }
491 winMsg->message = WINWM_SYSCOMMAND;
492 winMsg->wParam = (WPARAM)win32sc;
493 winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
494 break;
495 }
496 case WM_CHAR:
497 {
498 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
499 ULONG flags = SHORT1FROMMP(os2Msg->mp1);
500 BOOL keyWasPressed;
501 char c;
502
503 thdb->fTranslated = FALSE;
504 repeatCount = CHAR3FROMMP(os2Msg->mp1);
505 scanCode = CHAR4FROMMP(os2Msg->mp1);
506 keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
507
508 dprintf(("PM: WM_CHAR: %x %x %d %x", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode));
509 dprintf(("PM: WM_CHAR: %x", flags));
510
511 // vitali add begin
512 if ( ( SHORT1FROMMP(os2Msg->mp2) & 0x0FF ) == 0x0E0 )
513 {
514 // an extended key ( arrows, ins, del and so on )
515 // get "virtual" scancode from character code cause
516 // for "regular" keys they are equal
517 scanCode = ( SHORT1FROMMP(os2Msg->mp2) >> 8) & 0x0FF;
518 }
519 // vitali add end
520
521 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
522 // given the OS/2 virtual key and OS/2 character
523
524 //if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
525 // ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
526 c = 0;
527 if ((SHORT1FROMMP (os2Msg->mp1) & 0xFF) != 0)
528 {
529 c = SHORT1FROMMP (os2Msg->mp2);
530 if ((c >= 'A') && (c <= 'Z')) {
531 virtualKey = c;
532 goto VirtualKeyFound;
533 }
534 if ((c >='a') && (c <= 'z')) {
535 virtualKey = c - 32; // make it uppercase
536 goto VirtualKeyFound;
537 }
538 if ((c >= '0') && (c <= '9')) {
539 virtualKey = c;
540 goto VirtualKeyFound;
541 }
542 }
543
544 // convert OS/2 virtual keys to Win32 virtual key
545 if (SHORT2FROMMP (os2Msg->mp2) <= VK_BLK2)
546 virtualKey = virtualKeyTable [SHORT2FROMMP (os2Msg->mp2)];
547
548VirtualKeyFound:
549 dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
550
551 winMsg->wParam = virtualKey;
552 winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
553 winMsg->lParam |= (scanCode & 0x0FF) << 16; // bit 16-23, scancode
554 win32wnd->setExtendedKey(virtualKey, (ULONG *)&winMsg->lParam);
555
556 if(!(SHORT1FROMMP(os2Msg->mp1) & KC_ALT))
557 {
558 //
559 // the Alt key is not pressed
560 //
561 if ((flags & KC_KEYUP) == KC_KEYUP) {
562 // send WM_KEYUP message
563
564 winMsg->message = WINWM_KEYUP;
565 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
566 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
567 }
568 else {
569 // send WM_KEYDOWN message
570 winMsg->message = WINWM_KEYDOWN;
571 if (keyWasPressed)
572 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
573 }
574 }
575 else {
576 //
577 // the Alt key is pressed
578 //
579 if ((flags & KC_KEYUP) == KC_KEYUP) {
580 // send WM_SYSKEYUP message
581
582 winMsg->message = WINWM_SYSKEYUP;
583 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
584 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
585 }
586 else {
587 // send WM_SYSKEYDOWN message
588 winMsg->message = WINWM_SYSKEYDOWN;
589 if (keyWasPressed)
590 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
591 }
592 }
593
594 break;
595 }
596
597 case WM_INITMENU:
598 winMsg->message = WINWM_INITMENU;
599 winMsg->wParam = (WPARAM)os2Msg->mp2; //hMenu
600 break;
601
602 case WM_MENUSELECT:
603 case WM_MENUEND:
604 case WM_NEXTMENU:
605 goto dummymessage;
606
607 case WM_TIMER:
608 if (os2Msg->mp2)
609 {
610 BOOL sys;
611 ULONG id;
612
613 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
614 {
615 winMsg->wParam = (WPARAM)id;
616 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
617 break;
618 }
619 }
620 goto dummymessage; //for caret blinking
621
622 case WM_SETWINDOWPARAMS:
623 {
624 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
625
626 if(wndParams->fsStatus & WPM_TEXT) {
627 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
628 break;
629 }
630 goto dummymessage;
631 }
632
633#if 0
634 case WM_QUERYWINDOWPARAMS:
635 {
636 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
637 ULONG textlen;
638 PSZ wintext;
639
640 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
641 {
642 if(wndpars->fsStatus & WPM_CCHTEXT)
643 wndpars->cchText = win32wnd->MsgGetTextLength();
644 if(wndpars->fsStatus & WPM_TEXT)
645 wndpars->pszText = win32wnd->MsgGetText();
646
647 wndpars->fsStatus = 0;
648 wndpars->cbCtlData = 0;
649 wndpars->cbPresParams = 0;
650 goto dummymessage;
651 }
652 }
653#endif
654
655 case WM_PAINT:
656 {
657 if(win32wnd->IsIconic()) {
658 winMsg->message = WINWM_PAINTICON;
659 }
660 else winMsg->message = WINWM_PAINT;
661 break;
662 }
663
664 case WM_HITTEST:
665 {
666 OSLIBPOINT pt;
667
668 pt.x = (*(POINTS *)&os2Msg->mp1).x;
669 pt.y = (*(POINTS *)&os2Msg->mp1).y;
670
671 mapOS2ToWin32Point(os2Msg->hwnd,OSLIB_HWND_DESKTOP,&pt);
672 winMsg->message = WINWM_NCHITTEST;
673 winMsg->wParam = 0;
674 winMsg->lParam = MAKELONG((USHORT)pt.x, (USHORT)pt.y);
675 break;
676 }
677
678 case WM_CONTEXTMENU:
679 {
680 OSLIBPOINT pt;
681
682 pt.x = (*(POINTS *)&os2Msg->mp1).x;
683 pt.y = (*(POINTS *)&os2Msg->mp1).y;
684 mapOS2ToWin32Point(os2Msg->hwnd,OSLIB_HWND_DESKTOP,&pt);
685 winMsg->message = WINWM_CONTEXTMENU;
686 winMsg->wParam = (WPARAM)win32wnd->getWindowHandle();
687 winMsg->lParam = MAKELONG((USHORT)pt.x, (USHORT)pt.y);
688 break;
689 }
690
691 case WM_SYSCOLORCHANGE:
692 case WM_SYSVALUECHANGED:
693 case WM_SETSELECTION:
694 case WM_PPAINT:
695 case WM_PSETFOCUS:
696 case WM_PSYSCOLORCHANGE:
697 case WM_PSIZE:
698 case WM_PACTIVATE:
699 case WM_PCONTROL:
700 case WM_HELP:
701 case WM_APPTERMINATENOTIFY:
702 case WM_PRESPARAMCHANGED:
703 case WM_DRAWITEM:
704 case WM_MEASUREITEM:
705 case WM_CONTROLPOINTER:
706 case WM_QUERYDLGCODE:
707 case WM_SUBSTITUTESTRING:
708 case WM_MATCHMNEMONIC:
709 case WM_SAVEAPPLICATION:
710 case WM_SEMANTICEVENT:
711 default:
712dummymessage:
713 return FALSE;
714 }
715 return TRUE;
716}
717//******************************************************************************
718//******************************************************************************
719BOOL OSLibWinTranslateMessage(MSG *msg)
720{
721 THDB *thdb;
722
723 thdb = GetThreadTHDB();
724 if(!thdb) {
725 return FALSE;
726 }
727 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
728 // the newly generated WM_CHAR message.
729 if(!thdb->fTranslated && MsgThreadPtr->msg == WM_CHAR && !((SHORT1FROMMP(MsgThreadPtr->mp1) & KC_KEYUP) == KC_KEYUP))
730 {//TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
731 ULONG fl = SHORT1FROMMP(MsgThreadPtr->mp1);
732 MSG extramsg;
733
734 memcpy(&extramsg, msg, sizeof(MSG));
735 extramsg.wParam = SHORT1FROMMP(MsgThreadPtr->mp2);
736 extramsg.lParam = 0;
737
738 if(!(fl & KC_CHAR)) {
739 return FALSE;
740 }
741
742 if(fl & KC_VIRTUALKEY) {
743 if(msg->wParam)
744 extramsg.wParam = msg->wParam;
745 else extramsg.wParam = SHORT2FROMMP(MsgThreadPtr->mp2);
746 }
747
748 if(msg->message >= WINWM_SYSKEYDOWN) {
749 extramsg.message = WINWM_SYSCHAR;
750 }
751 else extramsg.message = WINWM_CHAR;
752
753 if(fl & KC_DEADKEY) {
754 extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
755 }
756
757 extramsg.lParam = msg->lParam & 0x00FFFFFF;
758 if(fl & KC_ALT)
759 extramsg.lParam |= (1<<29);
760 if(fl & KC_PREVDOWN)
761 extramsg.lParam |= (1<<30);
762 if(fl & KC_KEYUP)
763 extramsg.lParam |= (1<<31);
764
765 thdb->fTranslated = TRUE;
766 memcpy(&thdb->msgWCHAR, &extramsg, sizeof(MSG));
767 return TRUE;
768 }
769 return FALSE;
770}
771//******************************************************************************
772//******************************************************************************
773
Note: See TracBrowser for help on using the repository browser.