source: trunk/src/user32/oslibmsgtranslate.cpp@ 3662

Last change on this file since 3662 was 3662, checked in by sandervl, 25 years ago

Major rewrite: frame/client -> frame

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