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

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

wm_activate fixes, scrollbar fix, drawframe fix

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