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

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

fixes for minimizing frame windows + WM_BUTTONxMOTIONSTART/END handling

File size: 27.4 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.41 2001-02-21 20:51:06 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 <winuser32.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 *pTeb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fMsgRemoved)
135{
136 Win32BaseWindow *win32wnd = 0;
137 OSLIBPOINT point, ClientPoint;
138 POSTMSG_PACKET *packet;
139 TEB *teb = (TEB *)pTeb;
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(teb->o.odin.newWindow == 0) {
179 DebugInt3();
180 goto dummymessage;
181 }
182
183 win32wnd = (Win32BaseWindow *)teb->o.odin.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, &teb->o.odin.wp, &swpOld, win32wnd->getParent()->getWindowHeight(),
236 win32wnd->getParent()->getClientRectPtr()->left,
237 win32wnd->getParent()->getClientRectPtr()->top,
238 win32wnd->getOS2WindowHandle());
239 }
240 else OSLibMapSWPtoWINDOWPOS(pswp, &teb->o.odin.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 teb->o.odin.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 teb->o.odin.wp.hwndInsertAfter = wndAfter->getWindowHandle();
254 else teb->o.odin.wp.hwndInsertAfter = HWND_TOP_W;
255 }
256 }
257 winMsg->message = WINWM_WINDOWPOSCHANGED;
258 winMsg->lParam = (LPARAM)&teb->o.odin.wp;
259 break;
260 }
261
262 case WM_ACTIVATE:
263 {
264 HWND hwndActivate = (HWND)os2Msg->mp2;
265 BOOL fMinimized = FALSE;
266
267 hwndActivate = OS2ToWin32Handle(hwndActivate);
268 if(hwndActivate == 0) {
269 //another (non-win32) application's window
270 //set to desktop window handle
271 hwndActivate = windowDesktop->getWindowHandle();
272 }
273
274 if(win32wnd->getStyle() & WS_MINIMIZE_W)
275 {
276 fMinimized = TRUE;
277 }
278
279 winMsg->message = WINWM_ACTIVATE;
280 winMsg->wParam = MAKELONG((SHORT1FROMMP(os2Msg->mp1)) ? WA_ACTIVE_W : WA_INACTIVE_W, fMinimized);
281 winMsg->lParam = (LPARAM)hwndActivate;
282 break;
283 }
284
285 case WM_SETFOCUS:
286 {
287 HWND hwndFocus = (HWND)os2Msg->mp1;
288
289 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
290 //another (non-win32) application's window
291 //set to NULL (allowed according to win32 SDK) to avoid problems
292 hwndFocus = NULL;
293 }
294 else hwndFocus = OS2ToWin32Handle(hwndFocus);
295
296 if((ULONG)os2Msg->mp2 == TRUE) {
297 winMsg->message = WINWM_SETFOCUS;
298 winMsg->wParam = (WPARAM)hwndFocus;
299 }
300 else {
301 winMsg->message = WINWM_KILLFOCUS;
302 winMsg->wParam = (WPARAM)hwndFocus;
303 }
304 break;
305 }
306
307 //**************************************************************************
308 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
309 //**************************************************************************
310 case WM_HITTEST:
311 winMsg->message = WINWM_NCHITTEST;
312 winMsg->wParam = 0;
313 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
314 if(!win32wnd->IsWindowEnabled()) {
315 if(win32wnd->getParent()) {
316 winMsg->hwnd = win32wnd->getParent()->getWindowHandle();
317 }
318 else goto dummymessage; //don't send mouse messages to disabled windows
319 }
320 break;
321
322 case WM_BUTTON1DOWN:
323 case WM_BUTTON1UP:
324 case WM_BUTTON1DBLCLK:
325 case WM_BUTTON2DOWN:
326 case WM_BUTTON2UP:
327 case WM_BUTTON2DBLCLK:
328 case WM_BUTTON3DOWN:
329 case WM_BUTTON3UP:
330 case WM_BUTTON3DBLCLK:
331 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
332
333#ifdef ODIN_HITTEST
334 //Send WM_HITTEST message
335 win32wnd->sendHitTest(MAKELONG(winMsg->pt.x,winMsg->pt.y));
336#endif
337 win32wnd->sendHitTest(MAKELONG(winMsg->pt.x,winMsg->pt.y));
338
339 //if a window is disabled, it's parent receives the mouse messages
340 if(!win32wnd->IsWindowEnabled()) {
341 if(win32wnd->getParent()) {
342 win32wnd = win32wnd->getParent();
343 }
344 fWasDisabled = TRUE;
345 }
346
347 if(IsNCMouseMsg(win32wnd)) {
348 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
349 winMsg->wParam = win32wnd->getLastHitTestVal();
350 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
351 }
352 else {
353 point.x = (*(POINTS *)&os2Msg->mp1).x;
354 point.y = (*(POINTS *)&os2Msg->mp1).y;
355 ClientPoint.x = mapOS2ToWin32X(win32wnd, point.x);
356 ClientPoint.y = mapOS2ToWin32Y(win32wnd, point.y);
357
358 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
359 winMsg->wParam = GetMouseKeyState();
360 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
361 }
362 if((fMsgRemoved == MSG_REMOVE) && ISMOUSE_CAPTURED())
363 {
364 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
365 goto dummymessage; //dinput swallowed message
366 }
367 }
368
369 if(fWasDisabled) {
370 if(win32wnd) {
371 winMsg->hwnd = win32wnd->getWindowHandle();
372 }
373 else goto dummymessage; //don't send mouse messages to disabled windows
374 }
375 break;
376
377 case WM_BUTTON2CLICK:
378 case WM_BUTTON1CLICK:
379 case WM_BUTTON3CLICK:
380 goto dummymessage;
381
382 case WM_BUTTON2MOTIONSTART:
383 case WM_BUTTON2MOTIONEND:
384 case WM_BUTTON1MOTIONSTART:
385 case WM_BUTTON1MOTIONEND:
386 case WM_BUTTON3MOTIONSTART:
387 case WM_BUTTON3MOTIONEND:
388 //no break; translate to WM_MOUSEMOVE
389 //Some applications (e.g. Unreal) retrieve all mouse messages
390 //when a mouse button is pressed and don't expect WM_NULL
391
392 case WM_MOUSEMOVE:
393 {
394 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
395
396#ifdef ODIN_HITTEST
397 //Send WM_HITTEST message
398 win32wnd->sendHitTest(MAKELONG(winMsg->pt.x,winMsg->pt.y));
399#endif
400
401 //if a window is disabled, it's parent receives the mouse messages
402 if(!win32wnd->IsWindowEnabled()) {
403 if(win32wnd->getParent()) {
404 win32wnd = win32wnd->getParent();
405 }
406 fWasDisabled = TRUE;
407 }
408 if(IsNCMouseMsg(win32wnd))
409 {
410 winMsg->message = WINWM_NCMOUSEMOVE;
411 winMsg->wParam = (WPARAM)win32wnd->getLastHitTestVal();
412 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
413 }
414 else
415 {
416 point.x = (*(POINTS *)&os2Msg->mp1).x;
417 point.y = (*(POINTS *)&os2Msg->mp1).y;
418 ClientPoint.x = mapOS2ToWin32X(win32wnd, point.x);
419 ClientPoint.y = mapOS2ToWin32Y(win32wnd, point.y);
420
421 winMsg->message = WINWM_MOUSEMOVE;
422 winMsg->wParam = GetMouseKeyState();
423 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
424 }
425 if((fMsgRemoved == MSG_REMOVE) && ISMOUSE_CAPTURED())
426 {
427 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
428 goto dummymessage; //dinput swallowed message
429 }
430 }
431 if(fWasDisabled) {
432 if(win32wnd) {
433 winMsg->hwnd = win32wnd->getWindowHandle();
434 }
435 else goto dummymessage; //don't send mouse messages to disabled windows
436 }
437 //OS/2 Window coordinates -> Win32 Window coordinates
438 break;
439 }
440
441 case WM_CONTROL:
442 goto dummymessage;
443
444 case WM_COMMAND:
445 if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
446 winMsg->message = WINWM_COMMAND;
447 winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
448 break;
449 }
450 //todo controls
451 goto dummymessage;
452
453 case WM_SYSCOMMAND:
454 {
455 ULONG x = 0, y = 0;
456 ULONG win32sc;
457
458 if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
459 POINTL pointl;
460 WinQueryPointerPos(HWND_DESKTOP, &pointl);
461 x = pointl.x;
462 y = mapScreenY(y);
463 }
464 switch(SHORT1FROMMP(os2Msg->mp1)) {
465 case SC_MOVE:
466 win32sc = SC_MOVE_W;
467 break;
468 case SC_CLOSE:
469 win32sc = SC_CLOSE_W;
470 break;
471 case SC_MAXIMIZE:
472 win32sc = SC_MAXIMIZE_W;
473 break;
474 case SC_MINIMIZE:
475 win32sc = SC_MINIMIZE_W;
476 break;
477 case SC_NEXTFRAME:
478 case SC_NEXTWINDOW:
479 win32sc = SC_NEXTWINDOW_W;
480 break;
481 case SC_RESTORE:
482 win32sc = SC_RESTORE_W;
483 break;
484 case SC_TASKMANAGER:
485 win32sc = SC_TASKLIST_W;
486 break;
487 default:
488 goto dummymessage;
489 }
490 winMsg->message = WINWM_SYSCOMMAND;
491 winMsg->wParam = (WPARAM)win32sc;
492 winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
493 break;
494 }
495 case WM_CHAR:
496 {
497 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
498 ULONG flags = SHORT1FROMMP(os2Msg->mp1);
499 BOOL keyWasPressed;
500 char c;
501
502 teb->o.odin.fTranslated = FALSE;
503 repeatCount = CHAR3FROMMP(os2Msg->mp1);
504 scanCode = CHAR4FROMMP(os2Msg->mp1);
505 keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
506
507 dprintf(("PM: WM_CHAR: %x %x %d %x", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode));
508 dprintf(("PM: WM_CHAR: hwnd %x flags %x", win32wnd->getWindowHandle(), flags));
509
510 // vitali add begin
511 if ( ( SHORT1FROMMP(os2Msg->mp2) & 0x0FF ) == 0x0E0 )
512 {
513 // an extended key ( arrows, ins, del and so on )
514 // get "virtual" scancode from character code cause
515 // for "regular" keys they are equal
516 scanCode = ( SHORT1FROMMP(os2Msg->mp2) >> 8) & 0x0FF;
517 }
518 // vitali add end
519
520 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
521 // given the OS/2 virtual key and OS/2 character
522
523 //if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
524 // ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
525 c = 0;
526 if ((SHORT1FROMMP (os2Msg->mp1) & 0xFF) != 0)
527 {
528 c = SHORT1FROMMP (os2Msg->mp2);
529 if ((c >= 'A') && (c <= 'Z')) {
530 virtualKey = c;
531 goto VirtualKeyFound;
532 }
533 if ((c >='a') && (c <= 'z')) {
534 virtualKey = c - 32; // make it uppercase
535 goto VirtualKeyFound;
536 }
537 if ((c >= '0') && (c <= '9')) {
538 virtualKey = c;
539 goto VirtualKeyFound;
540 }
541 }
542
543 // convert OS/2 virtual keys to Win32 virtual key
544 if (SHORT2FROMMP (os2Msg->mp2) <= VK_BLK2)
545 virtualKey = virtualKeyTable [SHORT2FROMMP (os2Msg->mp2)];
546
547VirtualKeyFound:
548 dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
549
550 winMsg->wParam = virtualKey;
551 winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
552 winMsg->lParam |= (scanCode & 0x0FF) << 16; // bit 16-23, scancode
553
554 //TODO: Is this correct and complete? (how does PM differentiate between
555 // i.e numeric pad pgdn & 'normal' pgdn??)
556 //Check if it's an extended key
557 switch(virtualKey) {
558 case VK_RETURN_W:
559 //The enter key on the numeric keypad is an extended key
560 if(SHORT2FROMMP(os2Msg->mp2) != VK_NEWLINE)
561 break;
562 //no break
563 case VK_LEFT_W:
564 case VK_RIGHT_W:
565 case VK_DOWN_W:
566 case VK_UP_W:
567 case VK_PRIOR_W:
568 case VK_NEXT_W:
569 case VK_END_W:
570 case VK_DIVIDE_W:
571 case VK_DELETE_W:
572 case VK_HOME_W:
573 case VK_INSERT_W:
574 case VK_RCONTROL_W:
575 case VK_RMENU_W: //is this the right alt???
576 winMsg->lParam = winMsg->lParam | (1<<24);
577 break;
578 }
579
580 if(!(SHORT1FROMMP(os2Msg->mp1) & KC_ALT))
581 {
582 //
583 // the Alt key is not pressed
584 //
585 if ((flags & KC_KEYUP) == KC_KEYUP) {
586 // send WM_KEYUP message
587
588 winMsg->message = WINWM_KEYUP;
589 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
590 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
591 }
592 else {
593 // send WM_KEYDOWN message
594 winMsg->message = WINWM_KEYDOWN;
595 if (keyWasPressed)
596 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
597 }
598 }
599 else {
600 //
601 // the Alt key is pressed
602 //
603 if ((flags & KC_KEYUP) == KC_KEYUP) {
604 // send WM_SYSKEYUP message
605
606 winMsg->message = WINWM_SYSKEYUP;
607 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
608 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
609 }
610 else {
611 // send WM_SYSKEYDOWN message
612 winMsg->message = WINWM_SYSKEYDOWN;
613 if (keyWasPressed)
614 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
615 }
616 if(winMsg->wParam == VK_MENU_W) {
617 winMsg->message = 0; //WM_SYS* already implies Alt
618 }
619 }
620 if(ISKDB_CAPTURED())
621 {
622 if(DInputKeyBoardHandler(winMsg)) {
623 goto dummymessage; //dinput swallowed message
624 }
625 }
626 break;
627 }
628
629 case WM_TIMER:
630 if (os2Msg->mp2)
631 {
632 BOOL sys;
633 ULONG id;
634
635 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
636 {
637 winMsg->wParam = (WPARAM)id;
638 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
639 break;
640 }
641 }
642 goto dummymessage; //for caret blinking
643
644 case WM_SETWINDOWPARAMS:
645 {
646 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
647
648 if(wndParams->fsStatus & WPM_TEXT) {
649 winMsg->message = WINWM_SETTEXT;
650 winMsg->lParam = (LPARAM)wndParams->pszText;
651 break;
652 }
653 goto dummymessage;
654 }
655
656#if 0
657 case WM_QUERYWINDOWPARAMS:
658 {
659 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
660 ULONG textlen;
661 PSZ wintext;
662
663 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
664 {
665 if(wndpars->fsStatus & WPM_CCHTEXT)
666 wndpars->cchText = win32wnd->MsgGetTextLength();
667 if(wndpars->fsStatus & WPM_TEXT)
668 wndpars->pszText = win32wnd->MsgGetText();
669
670 wndpars->fsStatus = 0;
671 wndpars->cbCtlData = 0;
672 wndpars->cbPresParams = 0;
673 goto dummymessage;
674 }
675 }
676#endif
677
678 case WM_PAINT:
679 {
680 if(win32wnd->IsWindowIconic()) {
681 winMsg->message = WINWM_PAINTICON;
682 }
683 else winMsg->message = WINWM_PAINT;
684 break;
685 }
686
687 case WM_CONTEXTMENU:
688 winMsg->message = WINWM_CONTEXTMENU;
689 winMsg->wParam = win32wnd->getWindowHandle();
690 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
691 break;
692
693 case WM_RENDERFMT:
694 winMsg->message = WINWM_RENDERFORMAT;
695 winMsg->wParam = (UINT) os2Msg->mp1;
696 break;
697
698 case WM_RENDERALLFMTS:
699 winMsg->message = WINWM_RENDERALLFORMATS;
700 break;
701
702 case WM_DESTROYCLIPBOARD:
703 winMsg->message = WINWM_DESTROYCLIPBOARD;
704 break;
705
706 case WM_INITMENU:
707 case WM_MENUSELECT:
708 case WM_MENUEND:
709 case WM_NEXTMENU:
710 case WM_SYSCOLORCHANGE:
711 case WM_SYSVALUECHANGED:
712 case WM_SETSELECTION:
713 case WM_PPAINT:
714 case WM_PSETFOCUS:
715 case WM_PSYSCOLORCHANGE:
716 case WM_PSIZE:
717 case WM_PACTIVATE:
718 case WM_PCONTROL:
719 case WM_HELP:
720 case WM_APPTERMINATENOTIFY:
721 case WM_PRESPARAMCHANGED:
722 case WM_DRAWITEM:
723 case WM_MEASUREITEM:
724 case WM_CONTROLPOINTER:
725 case WM_QUERYDLGCODE:
726 case WM_SUBSTITUTESTRING:
727 case WM_MATCHMNEMONIC:
728 case WM_SAVEAPPLICATION:
729 case WM_SEMANTICEVENT:
730 default:
731dummymessage:
732 winMsg->message = 0;
733 winMsg->wParam = 0;
734 winMsg->lParam = 0;
735 return FALSE;
736 }
737 return TRUE;
738}
739//******************************************************************************
740//******************************************************************************
741BOOL OSLibWinTranslateMessage(MSG *msg)
742{
743 TEB *teb;
744
745 teb = GetThreadTEB();
746 if(!teb) {
747 return FALSE;
748 }
749 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
750 // the newly generated WM_CHAR message.
751 if(!teb->o.odin.fTranslated && teb->o.odin.os2msg.msg == WM_CHAR && !((SHORT1FROMMP(teb->o.odin.os2msg.mp1) & KC_KEYUP) == KC_KEYUP))
752 {//TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
753 ULONG fl = SHORT1FROMMP(teb->o.odin.os2msg.mp1);
754 MSG extramsg;
755
756 memcpy(&extramsg, msg, sizeof(MSG));
757 extramsg.wParam = SHORT1FROMMP(teb->o.odin.os2msg.mp2);
758 extramsg.lParam = 0;
759
760 if(!(fl & KC_CHAR) && msg->message < WINWM_SYSKEYDOWN) {
761 return FALSE;
762 }
763
764 if(fl & KC_VIRTUALKEY) {
765 if(msg->wParam)
766 extramsg.wParam = msg->wParam;
767 else extramsg.wParam = SHORT2FROMMP(teb->o.odin.os2msg.mp2);
768 }
769
770
771 if(msg->message >= WINWM_SYSKEYDOWN) {
772 extramsg.message = WINWM_SYSCHAR;
773 }
774 else extramsg.message = WINWM_CHAR;
775
776 if(fl & KC_DEADKEY) {
777 extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
778 }
779
780 extramsg.lParam = msg->lParam & 0x00FFFFFF;
781 if(fl & KC_ALT)
782 extramsg.lParam |= (1<<29);
783 if(fl & KC_PREVDOWN)
784 extramsg.lParam |= (1<<30);
785 if(fl & KC_KEYUP)
786 extramsg.lParam |= (1<<31);
787
788 teb->o.odin.fTranslated = TRUE;
789 memcpy(&teb->o.odin.msgWCHAR, &extramsg, sizeof(MSG));
790 return TRUE;
791 }
792 return FALSE;
793}
794//******************************************************************************
795//******************************************************************************
796
Note: See TracBrowser for help on using the repository browser.