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

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

ported all USER32 bitmaps, several bug fixes

File size: 27.0 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.4 2000-01-03 20:53:49 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) && (WinQueryCapture(HWND_DESKTOP) != win32wnd->getOS2WindowHandle())) {
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) && (WinQueryCapture(HWND_DESKTOP) != win32wnd->getOS2WindowHandle()))
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//CB: todo: send WM_NCCALCSIZE
301#if 0 //CB: ignore it
302 dprintf(("Set client rectangle to (%d,%d)(%d,%d)", swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy));
303 win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
304
305 thdb->wp.hwnd = win32wnd->getWindowHandle();
306 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
307 {
308 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
309 thdb->wp.hwndInsertAfter = wndAfter->getWindowHandle();
310 }
311
312 PRECT lpRect = win32wnd->getWindowRect();
313 //SvL: Only send it when the client has changed & the frame hasn't
314 // If the frame size/position has changed, pmframe.cpp will send
315 // this message
316 if(lpRect->right == thdb->wp.x+thdb->wp.cx && lpRect->bottom == thdb->wp.y+thdb->wp.cy) {
317 winMsg->message = WINWM_WINDOWPOSCHANGED;
318 winMsg->lParam = (LPARAM)&thdb->wp;
319 }
320 else {
321 win32wnd->setWindowRect(thdb->wp.x, thdb->wp.y, thdb->wp.x+thdb->wp.cx, thdb->wp.y+thdb->wp.cy);
322 goto dummymessage;
323 }
324#else
325 goto dummymessage;
326#endif
327 }
328
329 case WM_ACTIVATE:
330 {
331 HWND hwndActivate = (HWND)os2Msg->mp2;
332 BOOL fMinimized = FALSE;
333
334 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
335 //another (non-win32) application's window
336 //set to NULL (allowed according to win32 SDK) to avoid problems
337 hwndActivate = NULL;
338 }
339 else hwndActivate = Win32BaseWindow::OS2ToWin32Handle(hwndActivate);
340
341 if(WinQueryWindowULong(os2Msg->hwnd, QWL_STYLE) & WS_MINIMIZED)
342 {
343 fMinimized = TRUE;
344 }
345
346 winMsg->message = WINWM_ACTIVATE;
347 winMsg->wParam = MAKELONG((SHORT1FROMMP(os2Msg->mp1)) ? WA_ACTIVE_W : WA_INACTIVE_W, fMinimized);
348 winMsg->lParam = (LPARAM)hwndActivate;
349 break;
350 }
351
352 case WM_SETFOCUS:
353 {
354 HWND hwndFocus = (HWND)os2Msg->mp1;
355
356 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
357 //another (non-win32) application's window
358 //set to NULL (allowed according to win32 SDK) to avoid problems
359 hwndFocus = NULL;
360 }
361 else hwndFocus = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
362
363 if((ULONG)os2Msg->mp2 == TRUE) {
364 winMsg->message = WINWM_SETFOCUS;
365 winMsg->wParam = (WPARAM)hwndFocus;
366 }
367 else {
368 winMsg->message = WINWM_KILLFOCUS;
369 winMsg->wParam = (WPARAM)hwndFocus;
370 }
371 break;
372 }
373
374 //**************************************************************************
375 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
376 //**************************************************************************
377 case WM_BUTTON1DOWN:
378 case WM_BUTTON1UP:
379 case WM_BUTTON1DBLCLK:
380 case WM_BUTTON2DOWN:
381 case WM_BUTTON2UP:
382 case WM_BUTTON2DBLCLK:
383 case WM_BUTTON3DOWN:
384 case WM_BUTTON3UP:
385 case WM_BUTTON3DBLCLK:
386 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
387 if((win32wnd->lastHitTestVal != HTCLIENT_W) && (WinQueryCapture(HWND_DESKTOP) != win32wnd->getOS2WindowHandle())) {
388 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
389 winMsg->wParam = win32wnd->lastHitTestVal;
390 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
391 }
392 else {
393 point.x = (*(POINTS *)&os2Msg->mp1).x;
394 point.y = (*(POINTS *)&os2Msg->mp1).y;
395 ClientPoint.x = point.x;
396 ClientPoint.y = mapY(os2Msg->hwnd,point.y);
397
398 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
399 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
400 }
401
402 break;
403
404 case WM_BUTTON2MOTIONSTART:
405 case WM_BUTTON2MOTIONEND:
406 case WM_BUTTON2CLICK:
407 case WM_BUTTON1MOTIONSTART:
408 case WM_BUTTON1MOTIONEND:
409 case WM_BUTTON1CLICK:
410 case WM_BUTTON3MOTIONSTART:
411 case WM_BUTTON3MOTIONEND:
412 case WM_BUTTON3CLICK:
413 goto dummymessage;
414
415 case WM_MOUSEMOVE:
416 {
417 ULONG keystate = 0, setcursormsg = WINWM_MOUSEMOVE;
418
419 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & 0x8000)
420 keystate |= MK_LBUTTON_W;
421 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2) & 0x8000)
422 keystate |= MK_RBUTTON_W;
423 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) & 0x8000)
424 keystate |= MK_MBUTTON_W;
425 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x8000)
426 keystate |= MK_SHIFT_W;
427 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000)
428 keystate |= MK_CONTROL_W;
429
430 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
431 if((win32wnd->lastHitTestVal != HTCLIENT_W) && (WinQueryCapture(HWND_DESKTOP) != win32wnd->getOS2WindowHandle()))
432 {
433 setcursormsg = WINWM_NCMOUSEMOVE;
434 winMsg->wParam = (WPARAM)win32wnd->lastHitTestVal;
435 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
436 } else
437 {
438 winMsg->wParam = (WPARAM)keystate;
439 winMsg->lParam = MAKELONG(SHORT1FROMMP(os2Msg->mp1),mapY(win32wnd,SHORT2FROMMP(os2Msg->mp1)));
440 }
441 //OS/2 Window coordinates -> Win32 Window coordinates
442 winMsg->message = setcursormsg;
443 break;
444 }
445
446 case WM_CONTROL:
447 goto dummymessage;
448
449 case WM_COMMAND:
450 if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
451 winMsg->message = WINWM_COMMAND;
452 winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
453 break;
454 }
455 //todo controls
456 goto dummymessage;
457
458 case WM_SYSCOMMAND:
459 {
460 ULONG x = 0, y = 0;
461 ULONG win32sc;
462
463 if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
464 POINTL pointl;
465 WinQueryPointerPos(HWND_DESKTOP, &pointl);
466 x = pointl.x;
467 y = mapScreenY(y);
468 }
469 switch(SHORT1FROMMP(os2Msg->mp1)) {
470 case SC_MOVE:
471 win32sc = SC_MOVE_W;
472 break;
473 case SC_CLOSE:
474 win32sc = SC_CLOSE_W;
475 break;
476 case SC_MAXIMIZE:
477 win32sc = SC_MAXIMIZE_W;
478 break;
479 case SC_MINIMIZE:
480 win32sc = SC_MINIMIZE_W;
481 break;
482 case SC_NEXTFRAME:
483 case SC_NEXTWINDOW:
484 win32sc = SC_NEXTWINDOW_W;
485 break;
486 case SC_RESTORE:
487 win32sc = SC_RESTORE_W;
488 break;
489 case SC_TASKMANAGER:
490 win32sc = SC_TASKLIST_W;
491 break;
492 default:
493 goto dummymessage;
494 }
495 winMsg->message = WINWM_SYSCOMMAND;
496 winMsg->wParam = (WPARAM)win32sc;
497 winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
498 break;
499 }
500 case WM_CHAR:
501 {
502 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
503 ULONG flags = SHORT1FROMMP(os2Msg->mp1);
504 BOOL keyWasPressed;
505 char c;
506
507 thdb->fTranslated = FALSE;
508 repeatCount = CHAR3FROMMP(os2Msg->mp1);
509 scanCode = CHAR4FROMMP(os2Msg->mp1);
510 keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
511
512 dprintf(("PM: WM_CHAR: %x %x %d %x", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode));
513 dprintf(("PM: WM_CHAR: %x", flags));
514
515 // vitali add begin
516 if ( ( SHORT1FROMMP(os2Msg->mp2) & 0x0FF ) == 0x0E0 )
517 {
518 // an extended key ( arrows, ins, del and so on )
519 // get "virtual" scancode from character code cause
520 // for "regular" keys they are equal
521 scanCode = ( SHORT1FROMMP(os2Msg->mp2) >> 8) & 0x0FF;
522 }
523 // vitali add end
524
525 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
526 // given the OS/2 virtual key and OS/2 character
527
528 //if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
529 // ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
530 c = 0;
531 if ((SHORT1FROMMP (os2Msg->mp1) & 0xFF) != 0)
532 {
533 c = SHORT1FROMMP (os2Msg->mp2);
534 if ((c >= 'A') && (c <= 'Z')) {
535 virtualKey = c;
536 goto VirtualKeyFound;
537 }
538 if ((c >='a') && (c <= 'z')) {
539 virtualKey = c - 32; // make it uppercase
540 goto VirtualKeyFound;
541 }
542 if ((c >= '0') && (c <= '9')) {
543 virtualKey = c;
544 goto VirtualKeyFound;
545 }
546 }
547
548 // convert OS/2 virtual keys to Win32 virtual key
549 if (SHORT2FROMMP (os2Msg->mp2) <= VK_BLK2)
550 virtualKey = virtualKeyTable [SHORT2FROMMP (os2Msg->mp2)];
551
552VirtualKeyFound:
553 dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
554
555 winMsg->wParam = virtualKey;
556 winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
557 winMsg->lParam |= (scanCode & 0x0FF) << 16; // bit 16-23, scancode
558 win32wnd->setExtendedKey(virtualKey, (ULONG *)&winMsg->lParam);
559
560 if(!(SHORT1FROMMP(os2Msg->mp1) & KC_ALT))
561 {
562 //
563 // the Alt key is not pressed
564 //
565 if ((flags & KC_KEYUP) == KC_KEYUP) {
566 // send WM_KEYUP message
567
568 winMsg->message = WINWM_KEYUP;
569 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
570 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
571 }
572 else {
573 // send WM_KEYDOWN message
574 winMsg->message = WINWM_KEYDOWN;
575 if (keyWasPressed)
576 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
577 }
578 }
579 else {
580 //
581 // the Alt key is pressed
582 //
583 if ((flags & KC_KEYUP) == KC_KEYUP) {
584 // send WM_SYSKEYUP message
585
586 winMsg->message = WINWM_SYSKEYUP;
587 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
588 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
589 }
590 else {
591 // send WM_SYSKEYDOWN message
592 winMsg->message = WINWM_SYSKEYDOWN;
593 if (keyWasPressed)
594 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
595 }
596 }
597
598 break;
599 }
600
601 case WM_INITMENU:
602 winMsg->message = WINWM_INITMENU;
603 winMsg->wParam = (WPARAM)os2Msg->mp2; //hMenu
604 break;
605
606 case WM_MENUSELECT:
607 case WM_MENUEND:
608 case WM_NEXTMENU:
609 goto dummymessage;
610
611 case WM_TIMER:
612 if (os2Msg->mp2)
613 {
614 BOOL sys;
615 ULONG id;
616
617 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
618 {
619 winMsg->wParam = (WPARAM)id;
620 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
621 break;
622 }
623 }
624 goto dummymessage; //for caret blinking
625
626 case WM_SETWINDOWPARAMS:
627 {
628 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
629
630 if(wndParams->fsStatus & WPM_TEXT) {
631 win32wnd->MsgSetText(wndParams->pszText, wndParams->cchText);
632 break;
633 }
634 goto dummymessage;
635 }
636
637#if 0
638 case WM_QUERYWINDOWPARAMS:
639 {
640 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
641 ULONG textlen;
642 PSZ wintext;
643
644 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
645 {
646 if(wndpars->fsStatus & WPM_CCHTEXT)
647 wndpars->cchText = win32wnd->MsgGetTextLength();
648 if(wndpars->fsStatus & WPM_TEXT)
649 wndpars->pszText = win32wnd->MsgGetText();
650
651 wndpars->fsStatus = 0;
652 wndpars->cbCtlData = 0;
653 wndpars->cbPresParams = 0;
654 goto dummymessage;
655 }
656 }
657#endif
658
659 case WM_PAINT:
660 {
661 if(win32wnd->IsIconic()) {
662 winMsg->message = WINWM_PAINTICON;
663 }
664 else winMsg->message = WINWM_PAINT;
665 break;
666 }
667
668 case WM_HITTEST:
669 {
670 OSLIBPOINT pt;
671
672 pt.x = (*(POINTS *)&os2Msg->mp1).x;
673 pt.y = (*(POINTS *)&os2Msg->mp1).y;
674
675 mapOS2ToWin32Point(os2Msg->hwnd,OSLIB_HWND_DESKTOP,&pt);
676 winMsg->message = WINWM_NCHITTEST;
677 winMsg->wParam = 0;
678 winMsg->lParam = MAKELONG((USHORT)pt.x, (USHORT)pt.y);
679 break;
680 }
681
682 case WM_CONTEXTMENU:
683 {
684 OSLIBPOINT pt;
685
686 pt.x = (*(POINTS *)&os2Msg->mp1).x;
687 pt.y = (*(POINTS *)&os2Msg->mp1).y;
688 mapOS2ToWin32Point(os2Msg->hwnd,OSLIB_HWND_DESKTOP,&pt);
689 winMsg->message = WINWM_CONTEXTMENU;
690 winMsg->wParam = (WPARAM)win32wnd->getWindowHandle();
691 winMsg->lParam = MAKELONG((USHORT)pt.x, (USHORT)pt.y);
692 break;
693 }
694
695 case WM_SYSCOLORCHANGE:
696 case WM_SYSVALUECHANGED:
697 case WM_SETSELECTION:
698 case WM_PPAINT:
699 case WM_PSETFOCUS:
700 case WM_PSYSCOLORCHANGE:
701 case WM_PSIZE:
702 case WM_PACTIVATE:
703 case WM_PCONTROL:
704 case WM_HELP:
705 case WM_APPTERMINATENOTIFY:
706 case WM_PRESPARAMCHANGED:
707 case WM_DRAWITEM:
708 case WM_MEASUREITEM:
709 case WM_CONTROLPOINTER:
710 case WM_QUERYDLGCODE:
711 case WM_SUBSTITUTESTRING:
712 case WM_MATCHMNEMONIC:
713 case WM_SAVEAPPLICATION:
714 case WM_SEMANTICEVENT:
715 default:
716dummymessage:
717 return FALSE;
718 }
719 return TRUE;
720}
721//******************************************************************************
722//******************************************************************************
723BOOL OSLibWinTranslateMessage(MSG *msg)
724{
725 THDB *thdb;
726
727 thdb = GetThreadTHDB();
728 if(!thdb) {
729 return FALSE;
730 }
731 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
732 // the newly generated WM_CHAR message.
733 if(!thdb->fTranslated && MsgThreadPtr->msg == WM_CHAR && !((SHORT1FROMMP(MsgThreadPtr->mp1) & KC_KEYUP) == KC_KEYUP))
734 {//TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
735 ULONG fl = SHORT1FROMMP(MsgThreadPtr->mp1);
736 MSG extramsg;
737
738 memcpy(&extramsg, msg, sizeof(MSG));
739 extramsg.wParam = SHORT1FROMMP(MsgThreadPtr->mp2);
740 extramsg.lParam = 0;
741
742 if(!(fl & KC_CHAR)) {
743 return FALSE;
744 }
745
746 if(fl & KC_VIRTUALKEY) {
747 if(msg->wParam)
748 extramsg.wParam = msg->wParam;
749 else extramsg.wParam = SHORT2FROMMP(MsgThreadPtr->mp2);
750 }
751
752 if(msg->message >= WINWM_SYSKEYDOWN) {
753 extramsg.message = WINWM_SYSCHAR;
754 }
755 else extramsg.message = WINWM_CHAR;
756
757 if(fl & KC_DEADKEY) {
758 extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
759 }
760
761 extramsg.lParam = msg->lParam & 0x00FFFFFF;
762 if(fl & KC_ALT)
763 extramsg.lParam |= (1<<29);
764 if(fl & KC_PREVDOWN)
765 extramsg.lParam |= (1<<30);
766 if(fl & KC_KEYUP)
767 extramsg.lParam |= (1<<31);
768
769 thdb->fTranslated = TRUE;
770 memcpy(&thdb->msgWCHAR, &extramsg, sizeof(MSG));
771 return TRUE;
772 }
773 return FALSE;
774}
775//******************************************************************************
776//******************************************************************************
777
Note: See TracBrowser for help on using the repository browser.