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

Last change on this file since 2418 was 2418, checked in by sandervl, 26 years ago

client positioning + scrollbar fixes

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