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

Last change on this file since 5685 was 5685, checked in by sandervl, 24 years ago

client/frame rewrite

File size: 28.0 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.50 2001-05-11 08:39:43 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 <win32api.h>
25#include "oslibmsg.h"
26#include <winuser32.h>
27#include "win32wdesktop.h"
28#include "oslibutil.h"
29#include "timer.h"
30#include <thread.h>
31#include <wprocess.h>
32#include "pmwindow.h"
33#include "oslibwin.h"
34#include "winmouse.h"
35
36#define DBG_LOCALLOG DBG_oslibmsgtranslate
37#include "dbglocal.h"
38
39// Formerly used method of translation based on OS/2 VKEY value didn't work
40// right. We need to take a look at the scan code we get from PM and derive
41// the Win32 VKEY and scancode from that because sometimes even the scancode
42// used in Win32 is different from the PM scancode!
43// The format is:
44// Win VKEY, Win scancode, (PM scancode) (key description)
45USHORT pmscan2winkey [][2] = {
46 0, 0, // 0x00
47 0x1B, 0x01, // 0x01 Esc
48 0x31, 0x02, // 0x02 1
49 0x32, 0x03, // 0x03 2
50 0x33, 0x04, // 0x04 3
51 0x34, 0x05, // 0x05 4
52 0x35, 0x06, // 0x06 5
53 0x36, 0x07, // 0x07 6
54 0x37, 0x08, // 0x08 7
55 0x38, 0x09, // 0x09 8
56 0x39, 0x0A, // 0x0A 9
57 0x30, 0x0B, // 0x0B 0
58 0xBD, 0x0C, // 0x0C -
59 0xBB, 0x0D, // 0x0D =
60 0x08, 0x0E, // 0x0E Bksp
61 0x09, 0x0F, // 0x0F Tab
62 0x51, 0x10, // 0x10 q
63 0x57, 0x11, // 0x11 w
64 0x45, 0x12, // 0x12 e
65 0x52, 0x13, // 0x13 r
66 0x54, 0x14, // 0x14 t
67 0x59, 0x15, // 0x15 y
68 0x55, 0x16, // 0x16 u
69 0x49, 0x17, // 0x17 i
70 0x4F, 0x18, // 0x18 o
71 0x50, 0x19, // 0x19 p
72 0xDB, 0x1A, // 0x1A [
73 0xDD, 0x1B, // 0x1B ]
74 0x0D, 0x1C, // 0x1C Enter
75 0x11, 0x1D, // 0x1D LCtrl
76 0x41, 0x1E, // 0x1E a
77 0x53, 0x1F, // 0x1F s
78 0x44, 0x20, // 0x20 d
79 0x46, 0x21, // 0x21 f
80 0x47, 0x22, // 0x22 g
81 0x48, 0x23, // 0x23 h
82 0x4A, 0x24, // 0x24 j
83 0x4B, 0x25, // 0x25 k
84 0x4C, 0x26, // 0x26 l
85 0xBA, 0x27, // 0x27 ;
86 0xDE, 0x28, // 0x28 '
87 0xC0, 0x29, // 0x29 `
88 0x10, 0x2A, // 0x2A LShift
89 0xDC, 0x2B, // 0x2B Bkslsh
90 0x5A, 0x2C, // 0x2C z
91 0x58, 0x2D, // 0x2D x
92 0x43, 0x2E, // 0x2E c
93 0x56, 0x2F, // 0x2F v
94 0x42, 0x30, // 0x30 b
95 0x4E, 0x31, // 0x31 n
96 0x4D, 0x32, // 0x32 m
97 0xBC, 0x33, // 0x33 ,
98 0xBE, 0x34, // 0x34 .
99 0xBF, 0x35, // 0x35 /
100 0x10, 0x36, // 0x36 RShift
101 0x6A, 0x37, // 0x37 * Pad
102 0x12, 0x38, // 0x38 LAlt
103 0x20, 0x39, // 0x39 Space
104 0x14, 0x3A, // 0x3A CapsLk
105 0x70, 0x3B, // 0x3B F1
106 0x71, 0x3C, // 0x3C F2
107 0x72, 0x3D, // 0x3D F3
108 0x73, 0x3E, // 0x3E F4
109 0x74, 0x3F, // 0x3F F5
110 0x75, 0x40, // 0x40 F6
111 0x76, 0x41, // 0x41 F7
112 0x77, 0x42, // 0x42 F8
113 0x78, 0x43, // 0x43 F9
114 0x79, 0x44, // 0x44 F10 (?)
115 0x90, 0x145, // 0x45 NumLk
116 0x91, 0x46, // 0x46 ScrLk
117 0x24, 0x47, // 0x47 7 Pad
118 0x26, 0x48, // 0x48 8 Pad
119 0x21, 0x49, // 0x49 9 Pad
120 0x6D, 0x4A, // 0x4A - Pad
121 0x25, 0x4B, // 0x4B 4 Pad
122 0x0C, 0x4C, // 0x4C 5 Pad
123 0x27, 0x4D, // 0x4D 6 Pad
124 0x6B, 0x4E, // 0x4E + Pad
125 0x23, 0x4F, // 0x4F 1 Pad
126 0x28, 0x50, // 0x50 2 Pad
127 0x22, 0x51, // 0x51 3 Pad
128 0x2D, 0x52, // 0x52 0 Pad
129 0x2E, 0x53, // 0x53 . Pad
130 0, 0, // 0x54
131 0, 0, // 0x55
132 0, 0, // 0x56
133 0x7A, 0x57, // 0x57 F11
134 0x7B, 0x58, // 0x58 F12
135 0, 0, // 0x59
136 0x0D, 0x11C, // 0x5A Enter Pad
137 0x11, 0x11D, // 0x5B RCtrl
138 0x6F, 0x135, // 0x5C / Pad
139 0x2D, 0x152, // 0x5D PrtSc
140 0x12, 0x5E, // 0x5E RAlt
141 0x13, 0x45, // 0x5F Pause
142 0, 0, // 0x60
143 0, 0, // 0x61
144 0, 0, // 0x62
145 0, 0, // 0x63
146 0, 0, // 0x64
147 0, 0, // 0x65
148 0, 0, // 0x66
149 0, 0, // 0x67
150 0, 0, // 0x68
151 0, 0, // 0x69
152 0, 0, // 0x6A
153 0, 0, // 0x6B
154 0x5D, 0x15D, // 0x6C RWin (PM scan 0x7C)
155 0, 0, // 0x6D
156 0x5B, 0x15B, // 0x6E LWin (PM scan 0x7E)
157 0x5C, 0x15C // 0x6F RMenu? (PM scan 0x7F)
158};
159
160//******************************************************************************
161//******************************************************************************
162ULONG GetMouseKeyState()
163{
164 ULONG keystate = 0;
165
166 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & 0x8000)
167 keystate |= MK_LBUTTON_W;
168 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2) & 0x8000)
169 keystate |= MK_RBUTTON_W;
170 if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) & 0x8000)
171 keystate |= MK_MBUTTON_W;
172 if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x8000)
173 keystate |= MK_SHIFT_W;
174 if(WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000)
175 keystate |= MK_CONTROL_W;
176
177 return keystate;
178}
179//******************************************************************************
180//******************************************************************************
181LONG IsNCMouseMsg(Win32BaseWindow *win32wnd)
182{
183 return ((win32wnd->getLastHitTestVal() != HTCLIENT_W) && (WinQueryCapture(HWND_DESKTOP) != win32wnd->getOS2WindowHandle()));
184}
185//******************************************************************************
186//******************************************************************************
187BOOL OS2ToWinMsgTranslate(void *pTeb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fMsgRemoved)
188{
189 Win32BaseWindow *win32wnd = 0;
190 OSLIBPOINT point, ClientPoint;
191 POSTMSG_PACKET *packet;
192 TEB *teb = (TEB *)pTeb;
193 BOOL fWasDisabled = FALSE;
194 int i;
195
196 memset(winMsg, 0, sizeof(MSG));
197 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(os2Msg->hwnd);
198 if(!win32wnd) {
199 win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(os2Msg->hwnd);
200 }
201
202 //PostThreadMessage posts WIN32APP_POSTMSG msg without window handle
203 //Realplayer starts a timer with hwnd 0 & proc 0; check this here
204 if(win32wnd == 0 && (os2Msg->msg != WM_CREATE && os2Msg->msg != WM_QUIT && os2Msg->msg != WM_TIMER && os2Msg->msg != WIN32APP_POSTMSG))
205 {
206 goto dummymessage; //not a win32 client window
207 }
208 winMsg->time = os2Msg->time;
209 //CB: PM bug or undocumented feature? ptl.x highword is set!
210 winMsg->pt.x = os2Msg->ptl.x & 0xFFFF;
211 winMsg->pt.y = mapScreenY(os2Msg->ptl.y);
212
213 if(win32wnd) //==0 for WM_CREATE/WM_QUIT
214 winMsg->hwnd = win32wnd->getWindowHandle();
215
216 switch(os2Msg->msg)
217 {
218 case WIN32APP_POSTMSG:
219 {
220 packet = (POSTMSG_PACKET *)os2Msg->mp2;
221 if(packet && ((ULONG)os2Msg->mp1 == WIN32MSG_MAGICA || (ULONG)os2Msg->mp1 == WIN32MSG_MAGICW)) {
222 winMsg->message = packet->Msg;
223 winMsg->wParam = packet->wParam;
224 winMsg->lParam = packet->lParam;
225 if(fMsgRemoved == MSG_REMOVE) free(packet); //free the shared memory here
226 break;
227 }
228 goto dummymessage;
229 }
230
231 //OS/2 msgs
232 case WM_CREATE:
233 {
234 if(teb->o.odin.newWindow == 0) {
235 DebugInt3();
236 goto dummymessage;
237 }
238
239 win32wnd = (Win32BaseWindow *)teb->o.odin.newWindow;
240
241 winMsg->message = WINWM_CREATE;
242 winMsg->hwnd = win32wnd->getWindowHandle();
243 winMsg->wParam = 0;
244 winMsg->lParam = (LPARAM)win32wnd->tmpcs;
245 break;
246 }
247
248 case WM_QUIT:
249 winMsg->message = WINWM_QUIT;
250 break;
251
252 case WM_CLOSE:
253 winMsg->message = WINWM_CLOSE;
254 break;
255
256 case WM_DESTROY:
257 winMsg->message = WINWM_DESTROY;
258 break;
259
260 case WM_ENABLE:
261 winMsg->message = WINWM_ENABLE;
262 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
263 break;
264
265 case WM_SHOW:
266 winMsg->message = WINWM_SHOWWINDOW;
267 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
268 break;
269
270 case WM_WINDOWPOSCHANGED:
271 {
272 PSWP pswp = (PSWP)os2Msg->mp1;
273 SWP swpOld = *(pswp + 1);
274 HWND hParent = NULLHANDLE;
275 LONG yDelta = pswp->cy - swpOld.cy;
276 LONG xDelta = pswp->cx - swpOld.cx;
277
278 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) goto dummymessage;
279
280 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
281 if (win32wnd->isChild()) {
282 if(win32wnd->getParent()) {
283 hParent = win32wnd->getParent()->getOS2WindowHandle();
284 }
285 else goto dummymessage; //parent has just been destroyed
286 }
287 }
288 if(win32wnd->getParent()) {
289 OSLibMapSWPtoWINDOWPOS(pswp, &teb->o.odin.wp, &swpOld, win32wnd->getParent()->getClientHeight(),
290 win32wnd->getOS2WindowHandle());
291 }
292 else OSLibMapSWPtoWINDOWPOS(pswp, &teb->o.odin.wp, &swpOld, OSLibQueryScreenHeight(), win32wnd->getOS2WindowHandle());
293
294 if (!win32wnd->CanReceiveSizeMsgs()) goto dummymessage;
295
296 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
297///// dprintf(("Set client rectangle to (%d,%d)(%d,%d)", swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy));
298///// win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
299
300 teb->o.odin.wp.hwnd = win32wnd->getWindowHandle();
301 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
302 {
303 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
304 if(wndAfter)
305 teb->o.odin.wp.hwndInsertAfter = wndAfter->getWindowHandle();
306 else teb->o.odin.wp.hwndInsertAfter = HWND_TOP_W;
307 }
308 }
309 winMsg->message = WINWM_WINDOWPOSCHANGED;
310 winMsg->lParam = (LPARAM)&teb->o.odin.wp;
311 break;
312 }
313
314 case WM_ACTIVATE:
315 {
316 HWND hwndActivate = (HWND)os2Msg->mp2;
317 BOOL fMinimized = FALSE;
318
319 hwndActivate = OS2ToWin32Handle(hwndActivate);
320 if(hwndActivate == 0) {
321 //another (non-win32) application's window
322 //set to desktop window handle
323 hwndActivate = windowDesktop->getWindowHandle();
324 }
325
326 if(win32wnd->getStyle() & WS_MINIMIZE_W)
327 {
328 fMinimized = TRUE;
329 }
330
331 winMsg->message = WINWM_ACTIVATE;
332 winMsg->wParam = MAKELONG((SHORT1FROMMP(os2Msg->mp1)) ? WA_ACTIVE_W : WA_INACTIVE_W, fMinimized);
333 winMsg->lParam = (LPARAM)hwndActivate;
334 break;
335 }
336
337 case WM_SETFOCUS:
338 {
339 HWND hwndFocus = (HWND)os2Msg->mp1;
340
341 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
342 //another (non-win32) application's window
343 //set to NULL (allowed according to win32 SDK) to avoid problems
344 hwndFocus = NULL;
345 }
346 else hwndFocus = OS2ToWin32Handle(hwndFocus);
347
348 if((ULONG)os2Msg->mp2 == TRUE) {
349 winMsg->message = WINWM_SETFOCUS;
350 winMsg->wParam = (WPARAM)hwndFocus;
351 }
352 else {
353 winMsg->message = WINWM_KILLFOCUS;
354 winMsg->wParam = (WPARAM)hwndFocus;
355 }
356 break;
357 }
358
359 //**************************************************************************
360 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
361 //**************************************************************************
362 case WM_BUTTON1DOWN:
363 case WM_BUTTON1UP:
364 case WM_BUTTON1DBLCLK:
365 case WM_BUTTON2DOWN:
366 case WM_BUTTON2UP:
367 case WM_BUTTON2DBLCLK:
368 case WM_BUTTON3DOWN:
369 case WM_BUTTON3UP:
370 case WM_BUTTON3DBLCLK:
371 {
372 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
373
374 HWND hwnd;
375
376 DisableLogging();
377 if(GetCapture() != winMsg->hwnd)
378 {
379 hwnd = WindowFromPoint(winMsg->pt);
380 if(win32wnd->getWindowHandle() != hwnd) {
381 win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
382 if(win32wnd == NULL) {
383 DebugInt3();
384 EnableLogging();
385 goto dummymessage;
386 }
387 winMsg->hwnd = hwnd;
388 }
389 }
390
391 //if a window is disabled, it's parent receives the mouse messages
392 if(!IsWindowEnabled(win32wnd->getWindowHandle())) {
393 if(win32wnd->getParent()) {
394 win32wnd = win32wnd->getParent();
395 }
396 fWasDisabled = TRUE;
397 }
398
399 if(IsNCMouseMsg(win32wnd)) {
400 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
401 winMsg->wParam = win32wnd->getLastHitTestVal();
402 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
403 }
404 else {
405 ClientPoint.x = winMsg->pt.x;
406 ClientPoint.y = winMsg->pt.y;
407 MapWindowPoints(0, win32wnd->getWindowHandle(), (LPPOINT)&ClientPoint, 1);
408 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
409 winMsg->wParam = GetMouseKeyState();
410 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
411 }
412 EnableLogging();
413 if((fMsgRemoved == MSG_REMOVE) && ISMOUSE_CAPTURED())
414 {
415 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
416 goto dummymessage; //dinput swallowed message
417 }
418 }
419
420 if(fWasDisabled) {
421 if(win32wnd) {
422 winMsg->hwnd = win32wnd->getWindowHandle();
423 }
424 else goto dummymessage; //don't send mouse messages to disabled windows
425 }
426 break;
427 }
428
429 case WM_BUTTON2CLICK:
430 case WM_BUTTON1CLICK:
431 case WM_BUTTON3CLICK:
432 goto dummymessage;
433
434 case WM_BUTTON2MOTIONSTART:
435 case WM_BUTTON2MOTIONEND:
436 case WM_BUTTON1MOTIONSTART:
437 case WM_BUTTON1MOTIONEND:
438 case WM_BUTTON3MOTIONSTART:
439 case WM_BUTTON3MOTIONEND:
440 //no break; translate to WM_MOUSEMOVE
441 //Some applications (e.g. Unreal) retrieve all mouse messages
442 //when a mouse button is pressed and don't expect WM_NULL
443
444 case WM_MOUSEMOVE:
445 {
446 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
447
448 HWND hwnd;
449
450 dprintf2(("WM_NCMOUSEMOVE (%d,%d)", winMsg->pt.x, winMsg->pt.y));
451 DisableLogging();
452 if(GetCapture() != winMsg->hwnd)
453 {
454 hwnd = WindowFromPoint(winMsg->pt);
455 if(win32wnd->getWindowHandle() != hwnd) {
456 win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
457 if(win32wnd == NULL) {
458 DebugInt3();
459 EnableLogging();
460 goto dummymessage;
461 }
462 winMsg->hwnd = hwnd;
463 }
464 }
465
466 //if a window is disabled, it's parent receives the mouse messages
467 if(!IsWindowEnabled(win32wnd->getWindowHandle())) {
468 if(win32wnd->getParent()) {
469 win32wnd = win32wnd->getParent();
470 }
471 fWasDisabled = TRUE;
472 }
473 if(IsNCMouseMsg(win32wnd))
474 {
475 winMsg->message = WINWM_NCMOUSEMOVE;
476 winMsg->wParam = (WPARAM)win32wnd->getLastHitTestVal();
477 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
478 }
479 else
480 {
481 ClientPoint.x = winMsg->pt.x;
482 ClientPoint.y = winMsg->pt.y;
483 MapWindowPoints(0, win32wnd->getWindowHandle(), (LPPOINT)&ClientPoint, 1);
484
485 winMsg->message = WINWM_MOUSEMOVE;
486 winMsg->wParam = GetMouseKeyState();
487 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
488 }
489 EnableLogging();
490 if((fMsgRemoved == MSG_REMOVE) && ISMOUSE_CAPTURED())
491 {
492 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
493 goto dummymessage; //dinput swallowed message
494 }
495 }
496 if(fWasDisabled) {
497 if(win32wnd) {
498 winMsg->hwnd = win32wnd->getWindowHandle();
499 }
500 else {
501 goto dummymessage; //don't send mouse messages to disabled windows
502 }
503 }
504 //OS/2 Window coordinates -> Win32 Window coordinates
505 break;
506 }
507
508 case WM_CONTROL:
509 goto dummymessage;
510
511 case WM_COMMAND:
512 if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
513 winMsg->message = WINWM_COMMAND;
514 winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
515 break;
516 }
517 //todo controls
518 goto dummymessage;
519
520 case WM_SYSCOMMAND:
521 {
522 ULONG x = 0, y = 0;
523 ULONG win32sc;
524
525 if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
526 POINTL pointl;
527 WinQueryPointerPos(HWND_DESKTOP, &pointl);
528 x = pointl.x;
529 y = mapScreenY(y);
530 }
531 switch(SHORT1FROMMP(os2Msg->mp1)) {
532 case SC_MOVE:
533 win32sc = SC_MOVE_W;
534 break;
535 case SC_CLOSE:
536 win32sc = SC_CLOSE_W;
537 break;
538 case SC_MAXIMIZE:
539 win32sc = SC_MAXIMIZE_W;
540 break;
541 case SC_MINIMIZE:
542 win32sc = SC_MINIMIZE_W;
543 break;
544 case SC_NEXTFRAME:
545 case SC_NEXTWINDOW:
546 win32sc = SC_NEXTWINDOW_W;
547 break;
548 case SC_RESTORE:
549 win32sc = SC_RESTORE_W;
550 break;
551 case SC_TASKMANAGER:
552 win32sc = SC_TASKLIST_W;
553 break;
554 default:
555 goto dummymessage;
556 }
557 winMsg->message = WINWM_SYSCOMMAND;
558 winMsg->wParam = (WPARAM)win32sc;
559 winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
560 break;
561 }
562 case WM_CHAR:
563 {
564 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
565 ULONG flags = SHORT1FROMMP(os2Msg->mp1);
566 BOOL keyWasPressed, isExtended = FALSE;
567 char c;
568
569 teb->o.odin.fTranslated = FALSE;
570 repeatCount = CHAR3FROMMP(os2Msg->mp1);
571 scanCode = CHAR4FROMMP(os2Msg->mp1);
572 keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
573
574 dprintf(("PM: WM_CHAR: %x %x %d %x", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode));
575 dprintf(("PM: WM_CHAR: hwnd %x flags %x", win32wnd->getWindowHandle(), flags));
576
577 // vitali add begin
578 if ( ( SHORT1FROMMP(os2Msg->mp2) & 0x0FF ) == 0x0E0 )
579 {
580 // an extended key ( arrows, ins, del and so on )
581 // get "virtual" scancode from character code because
582 // for "regular" keys they are equal
583 scanCode = ( SHORT1FROMMP(os2Msg->mp2) >> 8) & 0x0FF;
584 isExtended = TRUE;
585 }
586 // vitali add end
587
588 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
589 // given the OS/2 virtual key and OS/2 character
590
591 //if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
592 // ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
593 c = 0;
594 if ((SHORT1FROMMP (os2Msg->mp1) & 0xFF) != 0)
595 {
596 c = SHORT1FROMMP (os2Msg->mp2);
597 if ((c >= 'A') && (c <= 'Z')) {
598 virtualKey = c;
599 goto VirtualKeyFound;
600 }
601 if ((c >='a') && (c <= 'z')) {
602 virtualKey = c - 32; // make it uppercase
603 goto VirtualKeyFound;
604 }
605 if ((c >= '0') && (c <= '9')) {
606 virtualKey = c;
607 goto VirtualKeyFound;
608 }
609 }
610
611VirtualKeyFound:
612// dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
613
614 // Adjust PM scancodes for Win* keys
615 if (scanCode >= 0x70)
616 scanCode -= 0x10;
617 winMsg->wParam = pmscan2winkey[scanCode][0];
618 winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
619 winMsg->lParam |= (pmscan2winkey[scanCode][1] & 0x1FF) << 16; // bit 16-23, scancode + bit 15 extended
620
621 // Adjust VKEY value for pad digits if NumLock is on
622 if ((scanCode >= 0x47) && (scanCode <= 0x53) &&
623 (virtualKey >= 0x30) && (virtualKey >= 39))
624 winMsg->wParam = virtualKey + 0x30;
625
626 // Set the extended bit when appropriate
627 if (isExtended)
628 winMsg->lParam = winMsg->lParam | (1<<24);
629
630 if (!(SHORT1FROMMP(os2Msg->mp1) & KC_ALT))
631 {
632 //
633 // the Alt key is not pressed
634 //
635 if ((flags & KC_KEYUP) == KC_KEYUP) {
636 // send WM_KEYUP message
637
638 winMsg->message = WINWM_KEYUP;
639 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
640 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
641 }
642 else {
643 // send WM_KEYDOWN message
644 winMsg->message = WINWM_KEYDOWN;
645 if (keyWasPressed)
646 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
647 }
648 }
649 else {
650 //
651 // the Alt key is pressed
652 //
653 if ((flags & KC_KEYUP) == KC_KEYUP) {
654 // send WM_SYSKEYUP message
655
656 winMsg->message = WINWM_SYSKEYUP;
657 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
658 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
659 }
660 else {
661 // send WM_SYSKEYDOWN message
662 winMsg->message = WINWM_SYSKEYDOWN;
663 if (keyWasPressed)
664 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
665 }
666 if(winMsg->wParam == VK_MENU_W) {
667 winMsg->message = 0; //WM_SYS* already implies Alt
668 }
669 }
670 if (ISKDB_CAPTURED())
671 {
672 if (DInputKeyBoardHandler(winMsg)) {
673 goto dummymessage; //dinput swallowed message
674 }
675 }
676 break;
677 }
678
679 case WM_TIMER:
680 if (os2Msg->mp2)
681 {
682 BOOL sys;
683 ULONG id;
684
685 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
686 {
687 winMsg->wParam = (WPARAM)id;
688 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
689 break;
690 }
691 }
692 goto dummymessage; //for caret blinking
693
694 case WM_SETWINDOWPARAMS:
695 {
696 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
697
698 if(wndParams->fsStatus & WPM_TEXT) {
699 winMsg->message = WINWM_SETTEXT;
700 winMsg->lParam = (LPARAM)wndParams->pszText;
701 break;
702 }
703 goto dummymessage;
704 }
705
706#if 0
707 case WM_QUERYWINDOWPARAMS:
708 {
709 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
710 ULONG textlen;
711 PSZ wintext;
712
713 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
714 {
715 if(wndpars->fsStatus & WPM_CCHTEXT)
716 wndpars->cchText = win32wnd->MsgGetTextLength();
717 if(wndpars->fsStatus & WPM_TEXT)
718 wndpars->pszText = win32wnd->MsgGetText();
719
720 wndpars->fsStatus = 0;
721 wndpars->cbCtlData = 0;
722 wndpars->cbPresParams = 0;
723 goto dummymessage;
724 }
725 }
726#endif
727
728 case WM_PAINT:
729 {
730 if(win32wnd->IsWindowIconic()) {
731 winMsg->message = WINWM_PAINTICON;
732 }
733 else winMsg->message = WINWM_PAINT;
734 break;
735 }
736
737 case WM_CONTEXTMENU:
738 winMsg->message = WINWM_CONTEXTMENU;
739 winMsg->wParam = win32wnd->getWindowHandle();
740 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
741 break;
742
743 case WM_RENDERFMT:
744 winMsg->message = WINWM_RENDERFORMAT;
745 winMsg->wParam = (UINT) os2Msg->mp1;
746 break;
747
748 case WM_RENDERALLFMTS:
749 winMsg->message = WINWM_RENDERALLFORMATS;
750 break;
751
752 case WM_DESTROYCLIPBOARD:
753 winMsg->message = WINWM_DESTROYCLIPBOARD;
754 break;
755
756 case WM_INITMENU:
757 case WM_MENUSELECT:
758 case WM_MENUEND:
759 case WM_NEXTMENU:
760 case WM_SYSCOLORCHANGE:
761 case WM_SYSVALUECHANGED:
762 case WM_SETSELECTION:
763 case WM_PPAINT:
764 case WM_PSETFOCUS:
765 case WM_PSYSCOLORCHANGE:
766 case WM_PSIZE:
767 case WM_PACTIVATE:
768 case WM_PCONTROL:
769 case WM_HELP:
770 case WM_APPTERMINATENOTIFY:
771 case WM_PRESPARAMCHANGED:
772 case WM_DRAWITEM:
773 case WM_MEASUREITEM:
774 case WM_CONTROLPOINTER:
775 case WM_QUERYDLGCODE:
776 case WM_SUBSTITUTESTRING:
777 case WM_MATCHMNEMONIC:
778 case WM_SAVEAPPLICATION:
779 case WM_SEMANTICEVENT:
780 default:
781dummymessage:
782 dprintf2(("dummy message %x %x %x %x", os2Msg->hwnd, os2Msg->msg, os2Msg->mp1, os2Msg->mp2));
783 winMsg->message = 0;
784 winMsg->wParam = 0;
785 winMsg->lParam = 0;
786 return FALSE;
787 }
788 return TRUE;
789}
790//******************************************************************************
791//******************************************************************************
792BOOL OSLibWinTranslateMessage(MSG *msg)
793{
794 TEB *teb;
795
796 teb = GetThreadTEB();
797 if(!teb) {
798 return FALSE;
799 }
800 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
801 // the newly generated WM_CHAR message.
802 if(!teb->o.odin.fTranslated && teb->o.odin.os2msg.msg == WM_CHAR && !((SHORT1FROMMP(teb->o.odin.os2msg.mp1) & KC_KEYUP) == KC_KEYUP))
803 {//TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
804 ULONG fl = SHORT1FROMMP(teb->o.odin.os2msg.mp1);
805 MSG extramsg;
806
807 memcpy(&extramsg, msg, sizeof(MSG));
808 extramsg.wParam = SHORT1FROMMP(teb->o.odin.os2msg.mp2);
809 extramsg.lParam = 0;
810
811 if(!(fl & KC_CHAR) && msg->message < WINWM_SYSKEYDOWN) {
812 return FALSE;
813 }
814
815 if(fl & KC_VIRTUALKEY) {
816 if(msg->wParam) {
817 if ((msg->wParam >= VK_NUMPAD0_W) && (msg->wParam <= VK_NUMPAD9_W))
818 extramsg.wParam = msg->wParam - 0x30;
819 else
820 extramsg.wParam = msg->wParam;
821 }
822 else extramsg.wParam = SHORT2FROMMP(teb->o.odin.os2msg.mp2);
823 }
824
825
826 if(msg->message >= WINWM_SYSKEYDOWN) {
827 extramsg.message = WINWM_SYSCHAR;
828 }
829 else extramsg.message = WINWM_CHAR;
830
831 if(fl & KC_DEADKEY) {
832 extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
833 }
834
835 extramsg.lParam = msg->lParam & 0x00FFFFFF;
836 if(fl & KC_ALT)
837 extramsg.lParam |= (1<<29);
838 if(fl & KC_PREVDOWN)
839 extramsg.lParam |= (1<<30);
840 if(fl & KC_KEYUP)
841 extramsg.lParam |= (1<<31);
842
843 teb->o.odin.fTranslated = TRUE;
844 memcpy(&teb->o.odin.msgWCHAR, &extramsg, sizeof(MSG));
845 return TRUE;
846 }
847 return FALSE;
848}
849//******************************************************************************
850//******************************************************************************
851
Note: See TracBrowser for help on using the repository browser.