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

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

WS_MAXIMIZE & WS_MINIMIZE flags updated when necessary & RedrawWindow changes

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