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

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

focus fixes + changes for dinput

File size: 27.4 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.19 2000-03-01 13:30:04 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 <os2.h>
21#include <os2wrap.h>
22#include <string.h>
23#include <misc.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 0x0A, // VK_NEWLINE 0x0A (no VK_* def)
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 ULONG hittest;
141 int i;
142
143 memset(winMsg, 0, sizeof(MSG));
144 win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(os2Msg->hwnd);
145 if (!win32wnd) win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(os2Msg->hwnd);
146
147 //PostThreadMessage posts WIN32APP_POSTMSG msg without window handle
148 //Realplayer starts a timer with hwnd 0 & proc 0; check this here
149 if(win32wnd == 0 && (os2Msg->msg != WM_CREATE && os2Msg->msg != WM_QUIT && os2Msg->msg != WM_TIMER && os2Msg->msg != WIN32APP_POSTMSG))
150 {
151 goto dummymessage; //not a win32 client window
152 }
153 winMsg->time = os2Msg->time;
154 //CB: PM bug or undocumented feature? ptl.x highword is set!
155 winMsg->pt.x = os2Msg->ptl.x & 0xFFFF;
156 winMsg->pt.y = mapScreenY(os2Msg->ptl.y);
157
158 if(win32wnd) //==0 for WM_CREATE/WM_QUIT
159 winMsg->hwnd = win32wnd->getWindowHandle();
160
161 if (win32wnd && (os2Msg->hwnd == win32wnd->getOS2FrameWindowHandle()))
162 {
163 //special frame messages
164
165 switch (os2Msg->msg)
166 {
167 case WM_BUTTON1DOWN:
168 case WM_BUTTON1UP:
169 case WM_BUTTON1DBLCLK:
170 case WM_BUTTON2DOWN:
171 case WM_BUTTON2UP:
172 case WM_BUTTON2DBLCLK:
173 case WM_BUTTON3DOWN:
174 case WM_BUTTON3UP:
175 case WM_BUTTON3DBLCLK:
176 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
177
178 hittest = win32wnd->MsgHitTest(winMsg->pt.x, winMsg->pt.y);
179
180 if (IsNCMouseMsg(win32wnd)) {
181 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
182 winMsg->wParam = hittest;
183 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
184 }
185 else {
186 point.x = (*(POINTS *)&os2Msg->mp1).x;
187 point.y = (*(POINTS *)&os2Msg->mp1).y;
188 ClientPoint.x = point.x;
189 ClientPoint.y = mapOS2ToWin32Y(os2Msg->hwnd,win32wnd->getOS2WindowHandle(),point.y);
190
191 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
192 winMsg->wParam = GetMouseKeyState();
193 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
194 }
195
196 return TRUE;
197
198 case WM_BUTTON2MOTIONSTART:
199 case WM_BUTTON2MOTIONEND:
200 case WM_BUTTON2CLICK:
201 case WM_BUTTON1MOTIONSTART:
202 case WM_BUTTON1MOTIONEND:
203 case WM_BUTTON1CLICK:
204 case WM_BUTTON3MOTIONSTART:
205 case WM_BUTTON3MOTIONEND:
206 case WM_BUTTON3CLICK:
207 goto dummymessage;
208
209 case WM_MOUSEMOVE:
210 {
211 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
212 hittest = win32wnd->MsgHitTest(winMsg->pt.x, winMsg->pt.y);
213
214 if (IsNCMouseMsg(win32wnd))
215 {
216 winMsg->message = WINWM_NCMOUSEMOVE;
217 winMsg->wParam = (WPARAM)hittest;
218 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
219 }
220 else
221 {
222 winMsg->message = WINWM_MOUSEMOVE;
223 winMsg->wParam = GetMouseKeyState();
224 winMsg->lParam = MAKELONG(SHORT1FROMMP(os2Msg->mp1),mapOS2ToWin32Y(win32wnd->getOS2FrameWindowHandle(),win32wnd->getOS2WindowHandle(),SHORT2FROMMP(os2Msg->mp1)));
225 }
226 //OS/2 Window coordinates -> Win32 Window coordinates
227 return TRUE;
228 }
229
230 case WM_PAINT:
231 {
232 winMsg->message = WINWM_NCPAINT;
233 return TRUE;
234 }
235
236 case WM_ACTIVATE:
237 {
238 winMsg->message = WINWM_NCACTIVATE;
239 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
240 return TRUE;
241 }
242 case WM_WINDOWPOSCHANGED:
243 {
244 //todo: proper translation
245 return FALSE;
246 }
247 }
248 //do normal translation for all other messages
249 }
250
251 switch(os2Msg->msg)
252 {
253 case WIN32APP_POSTMSG:
254 {
255 packet = (POSTMSG_PACKET *)os2Msg->mp2;
256 if(packet && ((ULONG)os2Msg->mp1 == WIN32MSG_MAGICA || (ULONG)os2Msg->mp1 == WIN32MSG_MAGICW)) {
257 winMsg->message = packet->Msg;
258 winMsg->wParam = packet->wParam;
259 winMsg->lParam = packet->lParam;
260 if(fMsgRemoved == MSG_REMOVE) free(packet); //free the shared memory here
261 break;
262 }
263 goto dummymessage;
264 }
265
266 //OS/2 msgs
267 case WM_CREATE:
268 {
269 if(thdb->newWindow == 0) {
270 DebugInt3();
271 goto dummymessage;
272 }
273
274 win32wnd = (Win32BaseWindow *)thdb->newWindow;
275
276 winMsg->message = WINWM_CREATE;
277 winMsg->hwnd = win32wnd->getWindowHandle();
278 winMsg->wParam = 0;
279 winMsg->lParam = (LPARAM)win32wnd->tmpcs;
280 break;
281 }
282
283 case WM_QUIT:
284 winMsg->message = WINWM_QUIT;
285 break;
286
287 case WM_CLOSE:
288 winMsg->message = WINWM_CLOSE;
289 break;
290
291 case WM_DESTROY:
292 winMsg->message = WINWM_DESTROY;
293 break;
294
295 case WM_ENABLE:
296 winMsg->message = WINWM_ENABLE;
297 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
298 break;
299
300 case WM_SHOW:
301 winMsg->message = WINWM_SHOWWINDOW;
302 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
303 break;
304
305 case WM_WINDOWPOSCHANGED:
306 {
307 PSWP pswp = (PSWP)os2Msg->mp1;
308 SWP swpOld = *(pswp + 1);
309 HWND hParent = NULLHANDLE;
310 LONG yDelta = pswp->cy - swpOld.cy;
311 LONG xDelta = pswp->cx - swpOld.cx;
312
313 dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
314
315 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) goto dummymessage;
316
317 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
318 if (win32wnd->isChild()) {
319 if(win32wnd->getParent()) {
320 hParent = win32wnd->getParent()->getOS2WindowHandle();
321 }
322 else goto dummymessage; //parent has just been destroyed
323 }
324 }
325 OSLibMapSWPtoWINDOWPOS(pswp, &thdb->wp, &swpOld, hParent, win32wnd->getOS2FrameWindowHandle());
326
327 if (!win32wnd->CanReceiveSizeMsgs()) goto dummymessage;
328
329 ULONG windowStyle = WinQueryWindowULong(os2Msg->hwnd, QWL_STYLE);
330 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MAXIMIZE_W|WS_MINIMIZE_W));
331 if (windowStyle & WS_MINIMIZED) {
332 win32wnd->setStyle(win32wnd->getStyle() | WS_MINIMIZE_W);
333 }
334 else
335 if (windowStyle & WS_MAXIMIZED) {
336 win32wnd->setStyle(win32wnd->getStyle() | WS_MAXIMIZE_W);
337 }
338
339 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
340 dprintf(("Set client rectangle to (%d,%d)(%d,%d)", swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy));
341 win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
342
343 thdb->wp.hwnd = win32wnd->getWindowHandle();
344 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
345 {
346 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
347 if(wndAfter)
348 thdb->wp.hwndInsertAfter = wndAfter->getWindowHandle();
349 }
350
351 PRECT lpRect = win32wnd->getWindowRect();
352 //SvL: Only send it when the client has changed & the frame hasn't
353 // If the frame size/position has changed, pmframe.cpp will send
354 // this message
355 if(lpRect->right == thdb->wp.x+thdb->wp.cx && lpRect->bottom == thdb->wp.y+thdb->wp.cy) {
356 winMsg->message = WINWM_WINDOWPOSCHANGED;
357 winMsg->lParam = (LPARAM)&thdb->wp;
358 break;
359 }
360 }
361 goto dummymessage;
362 }
363
364 case WM_ACTIVATE:
365 {
366 HWND hwndActivate = (HWND)os2Msg->mp2;
367 BOOL fMinimized = FALSE;
368
369 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
370 //another (non-win32) application's window
371 //set to desktop window handle
372 hwndActivate = windowDesktop->getWindowHandle();
373 }
374 else hwndActivate = Win32BaseWindow::OS2ToWin32Handle(hwndActivate);
375
376 if(WinQueryWindowULong(os2Msg->hwnd, QWL_STYLE) & WS_MINIMIZED)
377 {
378 fMinimized = TRUE;
379 }
380
381 winMsg->message = WINWM_ACTIVATE;
382 winMsg->wParam = MAKELONG((SHORT1FROMMP(os2Msg->mp1)) ? WA_ACTIVE_W : WA_INACTIVE_W, fMinimized);
383 winMsg->lParam = (LPARAM)hwndActivate;
384 break;
385 }
386
387 case WM_SETFOCUS:
388 {
389 HWND hwndFocus = (HWND)os2Msg->mp1;
390
391 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
392 //another (non-win32) application's window
393 //set to NULL (allowed according to win32 SDK) to avoid problems
394 hwndFocus = NULL;
395 }
396 else hwndFocus = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
397
398 if((ULONG)os2Msg->mp2 == TRUE) {
399 winMsg->message = WINWM_SETFOCUS;
400 winMsg->wParam = (WPARAM)hwndFocus;
401 }
402 else {
403 winMsg->message = WINWM_KILLFOCUS;
404 winMsg->wParam = (WPARAM)hwndFocus;
405 }
406 break;
407 }
408
409 //**************************************************************************
410 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
411 //**************************************************************************
412 case WM_BUTTON1DOWN:
413 case WM_BUTTON1UP:
414 case WM_BUTTON1DBLCLK:
415 case WM_BUTTON2DOWN:
416 case WM_BUTTON2UP:
417 case WM_BUTTON2DBLCLK:
418 case WM_BUTTON3DOWN:
419 case WM_BUTTON3UP:
420 case WM_BUTTON3DBLCLK:
421 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
422 hittest = win32wnd->MsgHitTest(winMsg->pt.x, winMsg->pt.y);
423
424 if(IsNCMouseMsg(win32wnd)) {
425 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
426 winMsg->wParam = hittest;
427 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
428 }
429 else {
430 point.x = (*(POINTS *)&os2Msg->mp1).x;
431 point.y = (*(POINTS *)&os2Msg->mp1).y;
432 ClientPoint.x = point.x;
433 ClientPoint.y = mapY(os2Msg->hwnd,point.y);
434
435 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
436 winMsg->wParam = GetMouseKeyState();
437 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
438 }
439 if(ISMOUSE_CAPTURED())
440 {
441 if(DInputMouseHandler(win32wnd->getWindowHandle(), MOUSEMSG_BUTTON, winMsg->pt.x, winMsg->pt.y))
442 goto dummymessage;
443 }
444
445 break;
446
447 case WM_BUTTON2MOTIONSTART:
448 case WM_BUTTON2MOTIONEND:
449 case WM_BUTTON2CLICK:
450 case WM_BUTTON1MOTIONSTART:
451 case WM_BUTTON1MOTIONEND:
452 case WM_BUTTON1CLICK:
453 case WM_BUTTON3MOTIONSTART:
454 case WM_BUTTON3MOTIONEND:
455 case WM_BUTTON3CLICK:
456 goto dummymessage;
457
458 case WM_MOUSEMOVE:
459 {
460 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
461 hittest = win32wnd->MsgHitTest(winMsg->pt.x, winMsg->pt.y);
462
463 if(IsNCMouseMsg(win32wnd))
464 {
465 winMsg->message = WINWM_NCMOUSEMOVE;
466 winMsg->wParam = (WPARAM)hittest;
467 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
468 }
469 else
470 {
471 winMsg->message = WINWM_MOUSEMOVE;
472 winMsg->wParam = GetMouseKeyState();
473 winMsg->lParam = MAKELONG(SHORT1FROMMP(os2Msg->mp1),mapY(win32wnd,SHORT2FROMMP(os2Msg->mp1)));
474 }
475 if(ISMOUSE_CAPTURED())
476 {
477 if(DInputMouseHandler(win32wnd->getWindowHandle(), MOUSEMSG_MOVE, winMsg->pt.x, winMsg->pt.y))
478 goto dummymessage;
479 }
480 //OS/2 Window coordinates -> Win32 Window coordinates
481 break;
482 }
483
484 case WM_CONTROL:
485 goto dummymessage;
486
487 case WM_COMMAND:
488 if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
489 winMsg->message = WINWM_COMMAND;
490 winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
491 break;
492 }
493 //todo controls
494 goto dummymessage;
495
496 case WM_SYSCOMMAND:
497 {
498 ULONG x = 0, y = 0;
499 ULONG win32sc;
500
501 if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
502 POINTL pointl;
503 WinQueryPointerPos(HWND_DESKTOP, &pointl);
504 x = pointl.x;
505 y = mapScreenY(y);
506 }
507 switch(SHORT1FROMMP(os2Msg->mp1)) {
508 case SC_MOVE:
509 win32sc = SC_MOVE_W;
510 break;
511 case SC_CLOSE:
512 win32sc = SC_CLOSE_W;
513 break;
514 case SC_MAXIMIZE:
515 win32sc = SC_MAXIMIZE_W;
516 break;
517 case SC_MINIMIZE:
518 win32sc = SC_MINIMIZE_W;
519 break;
520 case SC_NEXTFRAME:
521 case SC_NEXTWINDOW:
522 win32sc = SC_NEXTWINDOW_W;
523 break;
524 case SC_RESTORE:
525 win32sc = SC_RESTORE_W;
526 break;
527 case SC_TASKMANAGER:
528 win32sc = SC_TASKLIST_W;
529 break;
530 default:
531 goto dummymessage;
532 }
533 winMsg->message = WINWM_SYSCOMMAND;
534 winMsg->wParam = (WPARAM)win32sc;
535 winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
536 break;
537 }
538 case WM_CHAR:
539 {
540 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
541 ULONG flags = SHORT1FROMMP(os2Msg->mp1);
542 BOOL keyWasPressed;
543 char c;
544
545 thdb->fTranslated = FALSE;
546 repeatCount = CHAR3FROMMP(os2Msg->mp1);
547 scanCode = CHAR4FROMMP(os2Msg->mp1);
548 keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
549
550 dprintf(("PM: WM_CHAR: %x %x %d %x", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode));
551 dprintf(("PM: WM_CHAR: %x", flags));
552
553 // vitali add begin
554 if ( ( SHORT1FROMMP(os2Msg->mp2) & 0x0FF ) == 0x0E0 )
555 {
556 // an extended key ( arrows, ins, del and so on )
557 // get "virtual" scancode from character code cause
558 // for "regular" keys they are equal
559 scanCode = ( SHORT1FROMMP(os2Msg->mp2) >> 8) & 0x0FF;
560 }
561 // vitali add end
562
563 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
564 // given the OS/2 virtual key and OS/2 character
565
566 //if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
567 // ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
568 c = 0;
569 if ((SHORT1FROMMP (os2Msg->mp1) & 0xFF) != 0)
570 {
571 c = SHORT1FROMMP (os2Msg->mp2);
572 if ((c >= 'A') && (c <= 'Z')) {
573 virtualKey = c;
574 goto VirtualKeyFound;
575 }
576 if ((c >='a') && (c <= 'z')) {
577 virtualKey = c - 32; // make it uppercase
578 goto VirtualKeyFound;
579 }
580 if ((c >= '0') && (c <= '9')) {
581 virtualKey = c;
582 goto VirtualKeyFound;
583 }
584 }
585
586 // convert OS/2 virtual keys to Win32 virtual key
587 if (SHORT2FROMMP (os2Msg->mp2) <= VK_BLK2)
588 virtualKey = virtualKeyTable [SHORT2FROMMP (os2Msg->mp2)];
589
590VirtualKeyFound:
591 dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
592
593 winMsg->wParam = virtualKey;
594 winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
595 winMsg->lParam |= (scanCode & 0x0FF) << 16; // bit 16-23, scancode
596 win32wnd->setExtendedKey(virtualKey, (ULONG *)&winMsg->lParam);
597
598 if(!(SHORT1FROMMP(os2Msg->mp1) & KC_ALT))
599 {
600 //
601 // the Alt key is not pressed
602 //
603 if ((flags & KC_KEYUP) == KC_KEYUP) {
604 // send WM_KEYUP message
605
606 winMsg->message = WINWM_KEYUP;
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_KEYDOWN message
612 winMsg->message = WINWM_KEYDOWN;
613 if (keyWasPressed)
614 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
615 }
616 }
617 else {
618 //
619 // the Alt key is pressed
620 //
621 if ((flags & KC_KEYUP) == KC_KEYUP) {
622 // send WM_SYSKEYUP message
623
624 winMsg->message = WINWM_SYSKEYUP;
625 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
626 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
627 }
628 else {
629 // send WM_SYSKEYDOWN message
630 winMsg->message = WINWM_SYSKEYDOWN;
631 if (keyWasPressed)
632 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
633 }
634 }
635 if(ISKDB_CAPTURED())
636 {
637 DInputKeyBoardHandler(winMsg);
638 }
639 break;
640 }
641
642 case WM_TIMER:
643 if (os2Msg->mp2)
644 {
645 BOOL sys;
646 ULONG id;
647
648 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
649 {
650 winMsg->wParam = (WPARAM)id;
651 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
652 break;
653 }
654 }
655 goto dummymessage; //for caret blinking
656
657 case WM_SETWINDOWPARAMS:
658 {
659 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
660
661 if(wndParams->fsStatus & WPM_TEXT) {
662 winMsg->message = WINWM_SETTEXT;
663 winMsg->lParam = (LPARAM)wndParams->pszText;
664 break;
665 }
666 goto dummymessage;
667 }
668
669#if 0
670 case WM_QUERYWINDOWPARAMS:
671 {
672 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
673 ULONG textlen;
674 PSZ wintext;
675
676 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
677 {
678 if(wndpars->fsStatus & WPM_CCHTEXT)
679 wndpars->cchText = win32wnd->MsgGetTextLength();
680 if(wndpars->fsStatus & WPM_TEXT)
681 wndpars->pszText = win32wnd->MsgGetText();
682
683 wndpars->fsStatus = 0;
684 wndpars->cbCtlData = 0;
685 wndpars->cbPresParams = 0;
686 goto dummymessage;
687 }
688 }
689#endif
690
691 case WM_PAINT:
692 {
693 if(win32wnd->IsWindowIconic()) {
694 winMsg->message = WINWM_PAINTICON;
695 }
696 else winMsg->message = WINWM_PAINT;
697 break;
698 }
699
700 case WM_CONTEXTMENU:
701 winMsg->message = WINWM_CONTEXTMENU;
702 winMsg->wParam = win32wnd->getWindowHandle();
703 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
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 return FALSE;
733 }
734 return TRUE;
735}
736//******************************************************************************
737//******************************************************************************
738BOOL OSLibWinTranslateMessage(MSG *msg)
739{
740 THDB *thdb;
741
742 thdb = GetThreadTHDB();
743 if(!thdb) {
744 return FALSE;
745 }
746 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
747 // the newly generated WM_CHAR message.
748 if(!thdb->fTranslated && MsgThreadPtr->msg == WM_CHAR && !((SHORT1FROMMP(MsgThreadPtr->mp1) & KC_KEYUP) == KC_KEYUP))
749 {//TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
750 ULONG fl = SHORT1FROMMP(MsgThreadPtr->mp1);
751 MSG extramsg;
752
753 memcpy(&extramsg, msg, sizeof(MSG));
754 extramsg.wParam = SHORT1FROMMP(MsgThreadPtr->mp2);
755 extramsg.lParam = 0;
756
757 if(!(fl & KC_CHAR)) {
758 return FALSE;
759 }
760
761 if(fl & KC_VIRTUALKEY) {
762 if(msg->wParam)
763 extramsg.wParam = msg->wParam;
764 else extramsg.wParam = SHORT2FROMMP(MsgThreadPtr->mp2);
765 }
766
767 if(msg->message >= WINWM_SYSKEYDOWN) {
768 extramsg.message = WINWM_SYSCHAR;
769 }
770 else extramsg.message = WINWM_CHAR;
771
772 if(fl & KC_DEADKEY) {
773 extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
774 }
775
776 extramsg.lParam = msg->lParam & 0x00FFFFFF;
777 if(fl & KC_ALT)
778 extramsg.lParam |= (1<<29);
779 if(fl & KC_PREVDOWN)
780 extramsg.lParam |= (1<<30);
781 if(fl & KC_KEYUP)
782 extramsg.lParam |= (1<<31);
783
784 thdb->fTranslated = TRUE;
785 memcpy(&thdb->msgWCHAR, &extramsg, sizeof(MSG));
786 return TRUE;
787 }
788 return FALSE;
789}
790//******************************************************************************
791//******************************************************************************
792
Note: See TracBrowser for help on using the repository browser.