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

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

RDW_FRAME support for GetDCEx; added wine dialog change; added extra logging

File size: 31.2 KB
Line 
1/* $Id: oslibmsgtranslate.cpp,v 1.29 2000-05-02 20:50:49 sandervl Exp $ */
2/*
3 * Window message translation functions for OS/2
4 *
5 *
6 * Copyright 1998-1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1999 Daniela Engert (dani@ngrt.de)
8 * Copyright 1999 Rene Pronk (R.Pronk@twi.tudelft.nl)
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 * TODO: Extra msgs: which messages must be put into the queue and which can be sent directly?
13 * (According to the docs TranslateMessage really inserts a msg in the queue)
14 * TODO: Filter translation isn't correct for posted messages
15 *
16 */
17#define INCL_WIN
18#define INCL_PM
19#define INCL_DOSPROCESS
20#include <os2wrap.h>
21#include <string.h>
22#include <misc.h>
23#include <winconst.h>
24#include "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 0x0D, // VK_NEWLINE VK_RETURN
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 BOOL fWasDisabled = FALSE;
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_HITTEST:
168 winMsg->message = WINWM_NCHITTEST;
169 winMsg->wParam = 0;
170 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
171
172 if(!win32wnd->IsWindowEnabled()) {
173 if(win32wnd->getParent()) {
174 winMsg->hwnd = win32wnd->getParent()->getWindowHandle();
175 }
176 else goto dummymessage; //don't send mouse messages to disabled windows
177 }
178 return TRUE;
179
180 case WM_BUTTON1DOWN:
181 case WM_BUTTON1UP:
182 case WM_BUTTON1DBLCLK:
183 case WM_BUTTON2DOWN:
184 case WM_BUTTON2UP:
185 case WM_BUTTON2DBLCLK:
186 case WM_BUTTON3DOWN:
187 case WM_BUTTON3UP:
188 case WM_BUTTON3DBLCLK:
189 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
190
191 //if a window is disabled, it's parent receives the mouse messages
192 if(!win32wnd->IsWindowEnabled()) {
193 if(win32wnd->getParent()) {
194 win32wnd = win32wnd->getParent();
195 }
196 dprintf(("Rerouting mouse messages to parent %x of disabled window %x", win32wnd->getWindowHandle(), winMsg->hwnd));
197 fWasDisabled = TRUE;
198 }
199
200 if (IsNCMouseMsg(win32wnd)) {
201 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
202 winMsg->wParam = win32wnd->getLastHitTestVal();
203 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
204 }
205 else {
206 point.x = (*(POINTS *)&os2Msg->mp1).x;
207 point.y = (*(POINTS *)&os2Msg->mp1).y;
208 ClientPoint.x = point.x;
209 ClientPoint.y = mapOS2ToWin32Y(os2Msg->hwnd,win32wnd->getOS2WindowHandle(),point.y);
210
211 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
212 winMsg->wParam = GetMouseKeyState();
213 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
214 }
215 if(ISMOUSE_CAPTURED())
216 {
217 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
218 goto dummymessage; //dinput swallowed message
219 }
220 }
221 if(fWasDisabled) {
222 if(win32wnd) {
223 winMsg->hwnd = win32wnd->getWindowHandle();
224 }
225 else goto dummymessage; //don't send mouse messages to disabled windows
226 }
227 return TRUE;
228
229 case WM_BUTTON2MOTIONSTART:
230 case WM_BUTTON2MOTIONEND:
231 case WM_BUTTON2CLICK:
232 case WM_BUTTON1MOTIONSTART:
233 case WM_BUTTON1MOTIONEND:
234 case WM_BUTTON1CLICK:
235 case WM_BUTTON3MOTIONSTART:
236 case WM_BUTTON3MOTIONEND:
237 case WM_BUTTON3CLICK:
238 goto dummymessage;
239
240 case WM_MOUSEMOVE:
241 {
242 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
243
244 //if a window is disabled, it's parent receives the mouse messages
245 if(!win32wnd->IsWindowEnabled()) {
246 if(win32wnd->getParent()) {
247 win32wnd = win32wnd->getParent();
248 }
249 dprintf(("Rerouting mouse messages to parent %x of disabled window %x", win32wnd->getWindowHandle(), winMsg->hwnd));
250 fWasDisabled = TRUE;
251 }
252 if (IsNCMouseMsg(win32wnd))
253 {
254 winMsg->message = WINWM_NCMOUSEMOVE;
255 winMsg->wParam = (WPARAM)win32wnd->getLastHitTestVal();
256 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
257 }
258 else
259 {
260 winMsg->message = WINWM_MOUSEMOVE;
261 winMsg->wParam = GetMouseKeyState();
262 winMsg->lParam = MAKELONG(SHORT1FROMMP(os2Msg->mp1),mapOS2ToWin32Y(win32wnd->getOS2FrameWindowHandle(),win32wnd->getOS2WindowHandle(),SHORT2FROMMP(os2Msg->mp1)));
263 }
264 if(ISMOUSE_CAPTURED())
265 {
266 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
267 goto dummymessage; //dinput swallowed message
268 }
269 }
270 if(fWasDisabled) {
271 if(win32wnd) {
272 winMsg->hwnd = win32wnd->getWindowHandle();
273 }
274 else goto dummymessage; //don't send mouse messages to disabled windows
275 }
276 //OS/2 Window coordinates -> Win32 Window coordinates
277 return TRUE;
278 }
279
280 case WM_PAINT:
281 {
282 winMsg->message = WINWM_NCPAINT;
283 return TRUE;
284 }
285
286 case WM_ACTIVATE:
287 {
288 winMsg->message = WINWM_NCACTIVATE;
289 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
290 return TRUE;
291 }
292 case WM_WINDOWPOSCHANGED:
293 {
294 //todo: proper translation
295 return FALSE;
296 }
297 }
298 //do normal translation for all other messages
299 }
300
301 switch(os2Msg->msg)
302 {
303 case WIN32APP_POSTMSG:
304 {
305 packet = (POSTMSG_PACKET *)os2Msg->mp2;
306 if(packet && ((ULONG)os2Msg->mp1 == WIN32MSG_MAGICA || (ULONG)os2Msg->mp1 == WIN32MSG_MAGICW)) {
307 winMsg->message = packet->Msg;
308 winMsg->wParam = packet->wParam;
309 winMsg->lParam = packet->lParam;
310 if(fMsgRemoved == MSG_REMOVE) free(packet); //free the shared memory here
311 break;
312 }
313 goto dummymessage;
314 }
315
316 //OS/2 msgs
317 case WM_CREATE:
318 {
319 if(thdb->newWindow == 0) {
320 DebugInt3();
321 goto dummymessage;
322 }
323
324 win32wnd = (Win32BaseWindow *)thdb->newWindow;
325
326 winMsg->message = WINWM_CREATE;
327 winMsg->hwnd = win32wnd->getWindowHandle();
328 winMsg->wParam = 0;
329 winMsg->lParam = (LPARAM)win32wnd->tmpcs;
330 break;
331 }
332
333 case WM_QUIT:
334 winMsg->message = WINWM_QUIT;
335 break;
336
337 case WM_CLOSE:
338 winMsg->message = WINWM_CLOSE;
339 break;
340
341 case WM_DESTROY:
342 winMsg->message = WINWM_DESTROY;
343 break;
344
345 case WM_ENABLE:
346 winMsg->message = WINWM_ENABLE;
347 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
348 break;
349
350 case WM_SHOW:
351 winMsg->message = WINWM_SHOWWINDOW;
352 winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
353 break;
354
355 case WM_WINDOWPOSCHANGED:
356 {
357 PSWP pswp = (PSWP)os2Msg->mp1;
358 SWP swpOld = *(pswp + 1);
359 HWND hParent = NULLHANDLE;
360 LONG yDelta = pswp->cy - swpOld.cy;
361 LONG xDelta = pswp->cx - swpOld.cx;
362
363 dprintf(("OS2: WM_WINDOWPOSCHANGED %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
364
365 if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) goto dummymessage;
366
367 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
368 if (win32wnd->isChild()) {
369 if(win32wnd->getParent()) {
370 hParent = win32wnd->getParent()->getOS2WindowHandle();
371 }
372 else goto dummymessage; //parent has just been destroyed
373 }
374 }
375 OSLibMapSWPtoWINDOWPOS(pswp, &thdb->wp, &swpOld, hParent, win32wnd->getOS2FrameWindowHandle());
376
377 if (!win32wnd->CanReceiveSizeMsgs()) goto dummymessage;
378
379 ULONG windowStyle = WinQueryWindowULong(os2Msg->hwnd, QWL_STYLE);
380 win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MAXIMIZE_W|WS_MINIMIZE_W));
381 if (windowStyle & WS_MINIMIZED) {
382 win32wnd->setStyle(win32wnd->getStyle() | WS_MINIMIZE_W);
383 }
384 else
385 if (windowStyle & WS_MAXIMIZED) {
386 win32wnd->setStyle(win32wnd->getStyle() | WS_MAXIMIZE_W);
387 }
388
389 if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
390 dprintf(("Set client rectangle to (%d,%d)(%d,%d)", swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy));
391 win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
392
393 thdb->wp.hwnd = win32wnd->getWindowHandle();
394 if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
395 {
396 Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
397 if(wndAfter)
398 thdb->wp.hwndInsertAfter = wndAfter->getWindowHandle();
399 }
400
401 PRECT lpRect = win32wnd->getWindowRect();
402 //SvL: Only send it when the client has changed & the frame hasn't
403 // If the frame size/position has changed, pmframe.cpp will send
404 // this message
405 if(lpRect->right == thdb->wp.x+thdb->wp.cx && lpRect->bottom == thdb->wp.y+thdb->wp.cy) {
406 winMsg->message = WINWM_WINDOWPOSCHANGED;
407 winMsg->lParam = (LPARAM)&thdb->wp;
408 break;
409 }
410 }
411 goto dummymessage;
412 }
413
414 case WM_ACTIVATE:
415 {
416 HWND hwndActivate = (HWND)os2Msg->mp2;
417 BOOL fMinimized = FALSE;
418
419 if(WinQueryWindowULong(hwndActivate, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
420 //another (non-win32) application's window
421 //set to desktop window handle
422 hwndActivate = windowDesktop->getWindowHandle();
423 }
424 else hwndActivate = Win32BaseWindow::OS2ToWin32Handle(hwndActivate);
425
426 if(WinQueryWindowULong(os2Msg->hwnd, QWL_STYLE) & WS_MINIMIZED)
427 {
428 fMinimized = TRUE;
429 }
430
431 winMsg->message = WINWM_ACTIVATE;
432 winMsg->wParam = MAKELONG((SHORT1FROMMP(os2Msg->mp1)) ? WA_ACTIVE_W : WA_INACTIVE_W, fMinimized);
433 winMsg->lParam = (LPARAM)hwndActivate;
434 break;
435 }
436
437 case WM_SETFOCUS:
438 {
439 HWND hwndFocus = (HWND)os2Msg->mp1;
440
441 if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
442 //another (non-win32) application's window
443 //set to NULL (allowed according to win32 SDK) to avoid problems
444 hwndFocus = NULL;
445 }
446 else hwndFocus = Win32BaseWindow::OS2ToWin32Handle(hwndFocus);
447
448 if((ULONG)os2Msg->mp2 == TRUE) {
449 winMsg->message = WINWM_SETFOCUS;
450 winMsg->wParam = (WPARAM)hwndFocus;
451 }
452 else {
453 winMsg->message = WINWM_KILLFOCUS;
454 winMsg->wParam = (WPARAM)hwndFocus;
455 }
456 break;
457 }
458
459 //**************************************************************************
460 //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
461 //**************************************************************************
462 case WM_HITTEST:
463 winMsg->message = WINWM_NCHITTEST;
464 winMsg->wParam = 0;
465 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
466 if(!win32wnd->IsWindowEnabled()) {
467 if(win32wnd->getParent()) {
468 winMsg->hwnd = win32wnd->getParent()->getWindowHandle();
469 }
470 else goto dummymessage; //don't send mouse messages to disabled windows
471 }
472 break;
473
474 case WM_BUTTON1DOWN:
475 case WM_BUTTON1UP:
476 case WM_BUTTON1DBLCLK:
477 case WM_BUTTON2DOWN:
478 case WM_BUTTON2UP:
479 case WM_BUTTON2DBLCLK:
480 case WM_BUTTON3DOWN:
481 case WM_BUTTON3UP:
482 case WM_BUTTON3DBLCLK:
483 //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
484
485 //if a window is disabled, it's parent receives the mouse messages
486 if(!win32wnd->IsWindowEnabled()) {
487 if(win32wnd->getParent()) {
488 win32wnd = win32wnd->getParent();
489 }
490 fWasDisabled = TRUE;
491 }
492
493 if(IsNCMouseMsg(win32wnd)) {
494 winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
495 winMsg->wParam = win32wnd->getLastHitTestVal();
496 winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
497 }
498 else {
499 point.x = (*(POINTS *)&os2Msg->mp1).x;
500 point.y = (*(POINTS *)&os2Msg->mp1).y;
501 ClientPoint.x = point.x;
502 ClientPoint.y = mapY(os2Msg->hwnd,point.y);
503
504 winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
505 winMsg->wParam = GetMouseKeyState();
506 winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
507 }
508 if(ISMOUSE_CAPTURED())
509 {
510 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
511 goto dummymessage; //dinput swallowed message
512 }
513 }
514
515 if(fWasDisabled) {
516 if(win32wnd) {
517 winMsg->hwnd = win32wnd->getWindowHandle();
518 }
519 else goto dummymessage; //don't send mouse messages to disabled windows
520 }
521 break;
522
523 case WM_BUTTON2MOTIONSTART:
524 case WM_BUTTON2MOTIONEND:
525 case WM_BUTTON2CLICK:
526 case WM_BUTTON1MOTIONSTART:
527 case WM_BUTTON1MOTIONEND:
528 case WM_BUTTON1CLICK:
529 case WM_BUTTON3MOTIONSTART:
530 case WM_BUTTON3MOTIONEND:
531 case WM_BUTTON3CLICK:
532 goto dummymessage;
533
534 case WM_MOUSEMOVE:
535 {
536 //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
537
538 //if a window is disabled, it's parent receives the mouse messages
539 if(!win32wnd->IsWindowEnabled()) {
540 if(win32wnd->getParent()) {
541 win32wnd = win32wnd->getParent();
542 }
543 fWasDisabled = TRUE;
544 }
545 if(IsNCMouseMsg(win32wnd))
546 {
547 winMsg->message = WINWM_NCMOUSEMOVE;
548 winMsg->wParam = (WPARAM)win32wnd->getLastHitTestVal();
549 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
550 }
551 else
552 {
553 winMsg->message = WINWM_MOUSEMOVE;
554 winMsg->wParam = GetMouseKeyState();
555 winMsg->lParam = MAKELONG(SHORT1FROMMP(os2Msg->mp1),mapY(win32wnd,SHORT2FROMMP(os2Msg->mp1)));
556 }
557 if(ISMOUSE_CAPTURED())
558 {
559 if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
560 goto dummymessage; //dinput swallowed message
561 }
562 }
563 if(fWasDisabled) {
564 if(win32wnd) {
565 winMsg->hwnd = win32wnd->getWindowHandle();
566 }
567 else goto dummymessage; //don't send mouse messages to disabled windows
568 }
569 //OS/2 Window coordinates -> Win32 Window coordinates
570 break;
571 }
572
573 case WM_CONTROL:
574 goto dummymessage;
575
576 case WM_COMMAND:
577 if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
578 winMsg->message = WINWM_COMMAND;
579 winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
580 break;
581 }
582 //todo controls
583 goto dummymessage;
584
585 case WM_SYSCOMMAND:
586 {
587 ULONG x = 0, y = 0;
588 ULONG win32sc;
589
590 if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
591 POINTL pointl;
592 WinQueryPointerPos(HWND_DESKTOP, &pointl);
593 x = pointl.x;
594 y = mapScreenY(y);
595 }
596 switch(SHORT1FROMMP(os2Msg->mp1)) {
597 case SC_MOVE:
598 win32sc = SC_MOVE_W;
599 break;
600 case SC_CLOSE:
601 win32sc = SC_CLOSE_W;
602 break;
603 case SC_MAXIMIZE:
604 win32sc = SC_MAXIMIZE_W;
605 break;
606 case SC_MINIMIZE:
607 win32sc = SC_MINIMIZE_W;
608 break;
609 case SC_NEXTFRAME:
610 case SC_NEXTWINDOW:
611 win32sc = SC_NEXTWINDOW_W;
612 break;
613 case SC_RESTORE:
614 win32sc = SC_RESTORE_W;
615 break;
616 case SC_TASKMANAGER:
617 win32sc = SC_TASKLIST_W;
618 break;
619 default:
620 goto dummymessage;
621 }
622 winMsg->message = WINWM_SYSCOMMAND;
623 winMsg->wParam = (WPARAM)win32sc;
624 winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
625 break;
626 }
627 case WM_CHAR:
628 {
629 ULONG repeatCount=0, virtualKey=0, keyFlags=0, scanCode=0;
630 ULONG flags = SHORT1FROMMP(os2Msg->mp1);
631 BOOL keyWasPressed;
632 char c;
633
634 thdb->fTranslated = FALSE;
635 repeatCount = CHAR3FROMMP(os2Msg->mp1);
636 scanCode = CHAR4FROMMP(os2Msg->mp1);
637 keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
638
639 dprintf(("PM: WM_CHAR: %x %x %d %x", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode));
640 dprintf(("PM: WM_CHAR: hwnd %x flags %x", win32wnd->getWindowHandle(), flags));
641
642 // vitali add begin
643 if ( ( SHORT1FROMMP(os2Msg->mp2) & 0x0FF ) == 0x0E0 )
644 {
645 // an extended key ( arrows, ins, del and so on )
646 // get "virtual" scancode from character code cause
647 // for "regular" keys they are equal
648 scanCode = ( SHORT1FROMMP(os2Msg->mp2) >> 8) & 0x0FF;
649 }
650 // vitali add end
651
652 // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
653 // given the OS/2 virtual key and OS/2 character
654
655 //if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
656 // ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
657 c = 0;
658 if ((SHORT1FROMMP (os2Msg->mp1) & 0xFF) != 0)
659 {
660 c = SHORT1FROMMP (os2Msg->mp2);
661 if ((c >= 'A') && (c <= 'Z')) {
662 virtualKey = c;
663 goto VirtualKeyFound;
664 }
665 if ((c >='a') && (c <= 'z')) {
666 virtualKey = c - 32; // make it uppercase
667 goto VirtualKeyFound;
668 }
669 if ((c >= '0') && (c <= '9')) {
670 virtualKey = c;
671 goto VirtualKeyFound;
672 }
673 }
674
675 // convert OS/2 virtual keys to Win32 virtual key
676 if (SHORT2FROMMP (os2Msg->mp2) <= VK_BLK2)
677 virtualKey = virtualKeyTable [SHORT2FROMMP (os2Msg->mp2)];
678
679VirtualKeyFound:
680 dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
681
682 winMsg->wParam = virtualKey;
683 winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
684 winMsg->lParam |= (scanCode & 0x0FF) << 16; // bit 16-23, scancode
685
686 //TODO: Is this correct and complete? (how does PM differentiate between
687 // i.e numeric pad pgdn & 'normal' pgdn??)
688 //Check if it's an extended key
689 switch(virtualKey) {
690 case VK_RETURN_W:
691 //The enter key on the numeric keypad is an extended key
692 if(SHORT2FROMMP(os2Msg->mp2) != VK_NEWLINE)
693 break;
694 //no break
695 case VK_LEFT_W:
696 case VK_RIGHT_W:
697 case VK_DOWN_W:
698 case VK_UP_W:
699 case VK_PRIOR_W:
700 case VK_NEXT_W:
701 case VK_END_W:
702 case VK_DIVIDE_W:
703 case VK_DELETE_W:
704 case VK_HOME_W:
705 case VK_INSERT_W:
706 case VK_RCONTROL_W:
707 case VK_RMENU_W: //is this the right alt???
708 winMsg->lParam = winMsg->lParam | (1<<24);
709 break;
710 }
711
712 if(!(SHORT1FROMMP(os2Msg->mp1) & KC_ALT))
713 {
714 //
715 // the Alt key is not pressed
716 //
717 if ((flags & KC_KEYUP) == KC_KEYUP) {
718 // send WM_KEYUP message
719
720 winMsg->message = WINWM_KEYUP;
721 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
722 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
723 }
724 else {
725 // send WM_KEYDOWN message
726 winMsg->message = WINWM_KEYDOWN;
727 if (keyWasPressed)
728 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
729 }
730 }
731 else {
732 //
733 // the Alt key is pressed
734 //
735 if ((flags & KC_KEYUP) == KC_KEYUP) {
736 // send WM_SYSKEYUP message
737
738 winMsg->message = WINWM_SYSKEYUP;
739 winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
740 winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
741 }
742 else {
743 // send WM_SYSKEYDOWN message
744 winMsg->message = WINWM_SYSKEYDOWN;
745 if (keyWasPressed)
746 winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
747 }
748 }
749 if(ISKDB_CAPTURED())
750 {
751 if(DInputKeyBoardHandler(winMsg)) {
752 goto dummymessage; //dinput swallowed message
753 }
754 }
755 break;
756 }
757
758 case WM_TIMER:
759 if (os2Msg->mp2)
760 {
761 BOOL sys;
762 ULONG id;
763
764 if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
765 {
766 winMsg->wParam = (WPARAM)id;
767 winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
768 break;
769 }
770 }
771 goto dummymessage; //for caret blinking
772
773 case WM_SETWINDOWPARAMS:
774 {
775 WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
776
777 if(wndParams->fsStatus & WPM_TEXT) {
778 winMsg->message = WINWM_SETTEXT;
779 winMsg->lParam = (LPARAM)wndParams->pszText;
780 break;
781 }
782 goto dummymessage;
783 }
784
785#if 0
786 case WM_QUERYWINDOWPARAMS:
787 {
788 PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
789 ULONG textlen;
790 PSZ wintext;
791
792 if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
793 {
794 if(wndpars->fsStatus & WPM_CCHTEXT)
795 wndpars->cchText = win32wnd->MsgGetTextLength();
796 if(wndpars->fsStatus & WPM_TEXT)
797 wndpars->pszText = win32wnd->MsgGetText();
798
799 wndpars->fsStatus = 0;
800 wndpars->cbCtlData = 0;
801 wndpars->cbPresParams = 0;
802 goto dummymessage;
803 }
804 }
805#endif
806
807 case WM_PAINT:
808 {
809 if(win32wnd->IsWindowIconic()) {
810 winMsg->message = WINWM_PAINTICON;
811 }
812 else winMsg->message = WINWM_PAINT;
813 break;
814 }
815
816 case WM_CONTEXTMENU:
817 winMsg->message = WINWM_CONTEXTMENU;
818 winMsg->wParam = win32wnd->getWindowHandle();
819 winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
820 break;
821
822 case WM_INITMENU:
823 case WM_MENUSELECT:
824 case WM_MENUEND:
825 case WM_NEXTMENU:
826 case WM_SYSCOLORCHANGE:
827 case WM_SYSVALUECHANGED:
828 case WM_SETSELECTION:
829 case WM_PPAINT:
830 case WM_PSETFOCUS:
831 case WM_PSYSCOLORCHANGE:
832 case WM_PSIZE:
833 case WM_PACTIVATE:
834 case WM_PCONTROL:
835 case WM_HELP:
836 case WM_APPTERMINATENOTIFY:
837 case WM_PRESPARAMCHANGED:
838 case WM_DRAWITEM:
839 case WM_MEASUREITEM:
840 case WM_CONTROLPOINTER:
841 case WM_QUERYDLGCODE:
842 case WM_SUBSTITUTESTRING:
843 case WM_MATCHMNEMONIC:
844 case WM_SAVEAPPLICATION:
845 case WM_SEMANTICEVENT:
846 default:
847dummymessage:
848 winMsg->message = 0;
849 winMsg->wParam = 0;
850 winMsg->lParam = 0;
851 return FALSE;
852 }
853 return TRUE;
854}
855//******************************************************************************
856//******************************************************************************
857BOOL OSLibWinTranslateMessage(MSG *msg)
858{
859 THDB *thdb;
860
861 thdb = GetThreadTHDB();
862 if(!thdb) {
863 return FALSE;
864 }
865 //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
866 // the newly generated WM_CHAR message.
867 if(!thdb->fTranslated && MsgThreadPtr->msg == WM_CHAR && !((SHORT1FROMMP(MsgThreadPtr->mp1) & KC_KEYUP) == KC_KEYUP))
868 {//TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
869 ULONG fl = SHORT1FROMMP(MsgThreadPtr->mp1);
870 MSG extramsg;
871
872 memcpy(&extramsg, msg, sizeof(MSG));
873 extramsg.wParam = SHORT1FROMMP(MsgThreadPtr->mp2);
874 extramsg.lParam = 0;
875
876 if(!(fl & KC_CHAR)) {
877 return FALSE;
878 }
879
880 if(fl & KC_VIRTUALKEY) {
881 if(msg->wParam)
882 extramsg.wParam = msg->wParam;
883 else extramsg.wParam = SHORT2FROMMP(MsgThreadPtr->mp2);
884 }
885
886 if(msg->message >= WINWM_SYSKEYDOWN) {
887 extramsg.message = WINWM_SYSCHAR;
888 }
889 else extramsg.message = WINWM_CHAR;
890
891 if(fl & KC_DEADKEY) {
892 extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
893 }
894
895 extramsg.lParam = msg->lParam & 0x00FFFFFF;
896 if(fl & KC_ALT)
897 extramsg.lParam |= (1<<29);
898 if(fl & KC_PREVDOWN)
899 extramsg.lParam |= (1<<30);
900 if(fl & KC_KEYUP)
901 extramsg.lParam |= (1<<31);
902
903 thdb->fTranslated = TRUE;
904 memcpy(&thdb->msgWCHAR, &extramsg, sizeof(MSG));
905 return TRUE;
906 }
907 return FALSE;
908}
909//******************************************************************************
910//******************************************************************************
911
Note: See TracBrowser for help on using the repository browser.