1 | /* $Id: oslibmsgtranslate.cpp,v 1.74 2001-10-27 09:06:02 phaller 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 <win32api.h>
|
---|
25 | #include "oslibmsg.h"
|
---|
26 | #include <winuser32.h>
|
---|
27 | #include "win32wdesktop.h"
|
---|
28 | #include "oslibutil.h"
|
---|
29 | #include "timer.h"
|
---|
30 | #include <thread.h>
|
---|
31 | #include <wprocess.h>
|
---|
32 | #include "pmwindow.h"
|
---|
33 | #include "oslibwin.h"
|
---|
34 | #include "winmouse.h"
|
---|
35 | #include <pmkbdhk.h>
|
---|
36 | #include <pmscan.h>
|
---|
37 | #include <winscan.h>
|
---|
38 | #include <winkeyboard.h>
|
---|
39 |
|
---|
40 | #define DBG_LOCALLOG DBG_oslibmsgtranslate
|
---|
41 | #include "dbglocal.h"
|
---|
42 |
|
---|
43 |
|
---|
44 | static BOOL fGenerateDoubleClick = FALSE;
|
---|
45 | static MSG doubleClickMsg = {0};
|
---|
46 |
|
---|
47 | //******************************************************************************
|
---|
48 | //******************************************************************************
|
---|
49 | BOOL setThreadQueueExtraCharMessage(TEB* teb, MSG* pExtraMsg)
|
---|
50 | {
|
---|
51 | // check if the single slot is occupied already
|
---|
52 | if (teb->o.odin.fTranslated == TRUE)
|
---|
53 | // there's still an already translated message to be processed
|
---|
54 | return FALSE;
|
---|
55 |
|
---|
56 | teb->o.odin.fTranslated = TRUE;
|
---|
57 | memcpy(&teb->o.odin.msgWCHAR, pExtraMsg, sizeof(MSG));
|
---|
58 | return TRUE;
|
---|
59 | }
|
---|
60 |
|
---|
61 | //******************************************************************************
|
---|
62 | //******************************************************************************
|
---|
63 | ULONG GetMouseKeyState()
|
---|
64 | {
|
---|
65 | ULONG keystate = 0;
|
---|
66 |
|
---|
67 | if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON1) & 0x8000)
|
---|
68 | keystate |= MK_LBUTTON_W;
|
---|
69 | if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON2) & 0x8000)
|
---|
70 | keystate |= MK_RBUTTON_W;
|
---|
71 | if(WinGetKeyState(HWND_DESKTOP, VK_BUTTON3) & 0x8000)
|
---|
72 | keystate |= MK_MBUTTON_W;
|
---|
73 | if(WinGetKeyState(HWND_DESKTOP, VK_SHIFT) & 0x8000)
|
---|
74 | keystate |= MK_SHIFT_W;
|
---|
75 | if(WinGetKeyState(HWND_DESKTOP, VK_CTRL) & 0x8000)
|
---|
76 | keystate |= MK_CONTROL_W;
|
---|
77 |
|
---|
78 | return keystate;
|
---|
79 | }
|
---|
80 | //******************************************************************************
|
---|
81 | //******************************************************************************
|
---|
82 | LONG IsNCMouseMsg(Win32BaseWindow *win32wnd)
|
---|
83 | {
|
---|
84 | return ((win32wnd->getLastHitTestVal() != HTCLIENT_W) && (WinQueryCapture(HWND_DESKTOP) != win32wnd->getOS2WindowHandle()));
|
---|
85 | }
|
---|
86 | //******************************************************************************
|
---|
87 | //******************************************************************************
|
---|
88 | void SetMenuDoubleClick(BOOL fSet)
|
---|
89 | {
|
---|
90 | fGenerateDoubleClick = fSet;
|
---|
91 | }
|
---|
92 | //******************************************************************************
|
---|
93 | //******************************************************************************
|
---|
94 | BOOL OS2ToWinMsgTranslate(void *pTeb, QMSG *os2Msg, MSG *winMsg, BOOL isUnicode, BOOL fMsgRemoved)
|
---|
95 | {
|
---|
96 | Win32BaseWindow *win32wnd = 0;
|
---|
97 | OSLIBPOINT point, ClientPoint;
|
---|
98 | POSTMSG_PACKET *packet;
|
---|
99 | TEB *teb = (TEB *)pTeb;
|
---|
100 | BOOL fWasDisabled = FALSE;
|
---|
101 | BOOL fIsFrame = FALSE;
|
---|
102 | int i;
|
---|
103 |
|
---|
104 | memset(winMsg, 0, sizeof(MSG));
|
---|
105 | win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(os2Msg->hwnd);
|
---|
106 | if(!win32wnd) {
|
---|
107 | win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(os2Msg->hwnd);
|
---|
108 | if(win32wnd) {
|
---|
109 | fIsFrame = TRUE;
|
---|
110 | }
|
---|
111 | }
|
---|
112 |
|
---|
113 | //PostThreadMessage posts WIN32APP_POSTMSG msg without window handle
|
---|
114 | //Realplayer starts a timer with hwnd 0 & proc 0; check this here
|
---|
115 | if(win32wnd == 0 && (os2Msg->msg != WM_CREATE && os2Msg->msg != WM_QUIT && os2Msg->msg != WM_TIMER && os2Msg->msg < WIN32APP_POSTMSG))
|
---|
116 | {
|
---|
117 | goto dummymessage; //not a win32 client window
|
---|
118 | }
|
---|
119 | winMsg->time = os2Msg->time;
|
---|
120 | //CB: PM bug or undocumented feature? ptl.x highword is set!
|
---|
121 | winMsg->pt.x = os2Msg->ptl.x & 0xFFFF;
|
---|
122 | winMsg->pt.y = mapScreenY(os2Msg->ptl.y);
|
---|
123 |
|
---|
124 | if(win32wnd) //==0 for WM_CREATE/WM_QUIT
|
---|
125 | winMsg->hwnd = win32wnd->getWindowHandle();
|
---|
126 |
|
---|
127 | if(os2Msg->msg >= WIN32APP_POSTMSG) {
|
---|
128 | packet = (POSTMSG_PACKET *)os2Msg->mp2;
|
---|
129 | if(packet && ((ULONG)os2Msg->mp1 == WIN32MSG_MAGICA || (ULONG)os2Msg->mp1 == WIN32MSG_MAGICW)) {
|
---|
130 | winMsg->message = os2Msg->msg - WIN32APP_POSTMSG;
|
---|
131 | winMsg->wParam = packet->wParam;
|
---|
132 | winMsg->lParam = packet->lParam;
|
---|
133 | if(fMsgRemoved == MSG_REMOVE) free(packet); //free the shared memory here
|
---|
134 | if(win32wnd) RELEASE_WNDOBJ(win32wnd);
|
---|
135 | return TRUE;
|
---|
136 | }
|
---|
137 | else {//broadcasted message (no packet present)
|
---|
138 | winMsg->message = os2Msg->msg - WIN32APP_POSTMSG;
|
---|
139 | winMsg->wParam = (UINT)os2Msg->mp1;
|
---|
140 | winMsg->lParam = (DWORD)os2Msg->mp2;
|
---|
141 | if(win32wnd) RELEASE_WNDOBJ(win32wnd);
|
---|
142 | return TRUE;
|
---|
143 | }
|
---|
144 | goto dummymessage;
|
---|
145 | }
|
---|
146 |
|
---|
147 | switch(os2Msg->msg)
|
---|
148 | {
|
---|
149 | //OS/2 msgs
|
---|
150 | case WM_CREATE:
|
---|
151 | {
|
---|
152 | if(teb->o.odin.newWindow == 0) {
|
---|
153 | DebugInt3();
|
---|
154 | goto dummymessage;
|
---|
155 | }
|
---|
156 |
|
---|
157 | win32wnd = (Win32BaseWindow *)teb->o.odin.newWindow;
|
---|
158 | win32wnd->addRef();
|
---|
159 |
|
---|
160 | winMsg->message = WINWM_CREATE;
|
---|
161 | winMsg->hwnd = win32wnd->getWindowHandle();
|
---|
162 | winMsg->wParam = 0;
|
---|
163 | winMsg->lParam = (LPARAM)win32wnd->tmpcs;
|
---|
164 | break;
|
---|
165 | }
|
---|
166 |
|
---|
167 | case WM_QUIT:
|
---|
168 | winMsg->message = WINWM_QUIT;
|
---|
169 | break;
|
---|
170 |
|
---|
171 | case WM_CLOSE:
|
---|
172 | winMsg->message = WINWM_CLOSE;
|
---|
173 | break;
|
---|
174 |
|
---|
175 | case WM_DESTROY:
|
---|
176 | winMsg->message = WINWM_DESTROY;
|
---|
177 | break;
|
---|
178 |
|
---|
179 | case WM_ENABLE:
|
---|
180 | winMsg->message = WINWM_ENABLE;
|
---|
181 | winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
|
---|
182 | break;
|
---|
183 |
|
---|
184 | case WM_SHOW:
|
---|
185 | winMsg->message = WINWM_SHOWWINDOW;
|
---|
186 | winMsg->wParam = SHORT1FROMMP(os2Msg->mp1);
|
---|
187 | break;
|
---|
188 |
|
---|
189 | case WM_WINDOWPOSCHANGED:
|
---|
190 | {
|
---|
191 | PSWP pswp = (PSWP)os2Msg->mp1;
|
---|
192 | SWP swpOld = *(pswp + 1);
|
---|
193 | HWND hParent = NULLHANDLE;
|
---|
194 | LONG yDelta = pswp->cy - swpOld.cy;
|
---|
195 | LONG xDelta = pswp->cx - swpOld.cx;
|
---|
196 |
|
---|
197 | if(!fIsFrame) goto dummymessage;
|
---|
198 |
|
---|
199 | if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0) goto dummymessage;
|
---|
200 |
|
---|
201 | if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
|
---|
202 | if (win32wnd->isChild()) {
|
---|
203 | if(win32wnd->getParent()) {
|
---|
204 | hParent = win32wnd->getParent()->getOS2WindowHandle();
|
---|
205 | }
|
---|
206 | else goto dummymessage; //parent has just been destroyed
|
---|
207 | }
|
---|
208 | }
|
---|
209 | if(win32wnd->getParent()) {
|
---|
210 | OSLibMapSWPtoWINDOWPOS(pswp, &teb->o.odin.wp, &swpOld, win32wnd->getParent()->getClientHeight(),
|
---|
211 | win32wnd->getOS2WindowHandle());
|
---|
212 | }
|
---|
213 | else OSLibMapSWPtoWINDOWPOS(pswp, &teb->o.odin.wp, &swpOld, OSLibQueryScreenHeight(), win32wnd->getOS2WindowHandle());
|
---|
214 |
|
---|
215 | if (!win32wnd->CanReceiveSizeMsgs()) goto dummymessage;
|
---|
216 |
|
---|
217 | if(pswp->fl & (SWP_MOVE | SWP_SIZE))
|
---|
218 | {
|
---|
219 | teb->o.odin.wp.hwnd = win32wnd->getWindowHandle();
|
---|
220 | if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
|
---|
221 | {
|
---|
222 | Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
|
---|
223 | if(wndAfter) {
|
---|
224 | teb->o.odin.wp.hwndInsertAfter = wndAfter->getWindowHandle();
|
---|
225 | RELEASE_WNDOBJ(wndAfter);
|
---|
226 | }
|
---|
227 | else teb->o.odin.wp.hwndInsertAfter = HWND_TOP_W;
|
---|
228 | }
|
---|
229 | }
|
---|
230 | winMsg->message = WINWM_WINDOWPOSCHANGED;
|
---|
231 | winMsg->lParam = (LPARAM)&teb->o.odin.wp;
|
---|
232 | break;
|
---|
233 | }
|
---|
234 |
|
---|
235 | case WM_ACTIVATE:
|
---|
236 | {
|
---|
237 | HWND hwndActivate = (HWND)os2Msg->mp2;
|
---|
238 | BOOL fMinimized = FALSE;
|
---|
239 |
|
---|
240 | hwndActivate = OS2ToWin32Handle(hwndActivate);
|
---|
241 | if(hwndActivate == 0) {
|
---|
242 | //another (non-win32) application's window
|
---|
243 | //set to desktop window handle
|
---|
244 | hwndActivate = windowDesktop->getWindowHandle();
|
---|
245 | }
|
---|
246 |
|
---|
247 | if(win32wnd->getStyle() & WS_MINIMIZE_W)
|
---|
248 | {
|
---|
249 | fMinimized = TRUE;
|
---|
250 | }
|
---|
251 |
|
---|
252 | winMsg->message = WINWM_ACTIVATE;
|
---|
253 | winMsg->wParam = MAKELONG((SHORT1FROMMP(os2Msg->mp1)) ? WA_ACTIVE_W : WA_INACTIVE_W, fMinimized);
|
---|
254 | winMsg->lParam = (LPARAM)hwndActivate;
|
---|
255 | break;
|
---|
256 | }
|
---|
257 |
|
---|
258 | case WM_SETFOCUS:
|
---|
259 | {
|
---|
260 | HWND hwndFocus = (HWND)os2Msg->mp1;
|
---|
261 |
|
---|
262 | if(WinQueryWindowULong(hwndFocus, OFFSET_WIN32PM_MAGIC) != WIN32PM_MAGIC) {
|
---|
263 | //another (non-win32) application's window
|
---|
264 | //set to NULL (allowed according to win32 SDK) to avoid problems
|
---|
265 | hwndFocus = NULL;
|
---|
266 | }
|
---|
267 | else hwndFocus = OS2ToWin32Handle(hwndFocus);
|
---|
268 |
|
---|
269 | if((ULONG)os2Msg->mp2 == TRUE) {
|
---|
270 | winMsg->message = WINWM_SETFOCUS;
|
---|
271 | winMsg->wParam = (WPARAM)hwndFocus;
|
---|
272 | }
|
---|
273 | else {
|
---|
274 | winMsg->message = WINWM_KILLFOCUS;
|
---|
275 | winMsg->wParam = (WPARAM)hwndFocus;
|
---|
276 | }
|
---|
277 | break;
|
---|
278 | }
|
---|
279 |
|
---|
280 | //**************************************************************************
|
---|
281 | //Mouse messages (OS/2 Window coordinates -> Win32 coordinates relative to screen
|
---|
282 | //**************************************************************************
|
---|
283 | case WM_BUTTON1DOWN:
|
---|
284 | case WM_BUTTON1UP:
|
---|
285 | case WM_BUTTON1DBLCLK:
|
---|
286 | case WM_BUTTON2DOWN:
|
---|
287 | case WM_BUTTON2UP:
|
---|
288 | case WM_BUTTON2DBLCLK:
|
---|
289 | case WM_BUTTON3DOWN:
|
---|
290 | case WM_BUTTON3UP:
|
---|
291 | case WM_BUTTON3DBLCLK:
|
---|
292 | {
|
---|
293 | //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
|
---|
294 |
|
---|
295 | dprintf(("MsgButton %x (%x) %d at (%d,%d) time %x", winMsg->hwnd, os2Msg->hwnd, WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN), winMsg->pt.x, winMsg->pt.y, winMsg->time));
|
---|
296 |
|
---|
297 | HWND hwnd;
|
---|
298 |
|
---|
299 | DisableLogging();
|
---|
300 | if(GetCapture() != winMsg->hwnd)
|
---|
301 | {
|
---|
302 | hwnd = WindowFromPoint(winMsg->pt);
|
---|
303 | if(win32wnd->getWindowHandle() != hwnd) {
|
---|
304 | RELEASE_WNDOBJ(win32wnd);
|
---|
305 | win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
306 | if(win32wnd == NULL) {
|
---|
307 | DebugInt3();
|
---|
308 | EnableLogging();
|
---|
309 | goto dummymessage;
|
---|
310 | }
|
---|
311 | winMsg->hwnd = hwnd;
|
---|
312 | }
|
---|
313 | }
|
---|
314 |
|
---|
315 | //if a window is disabled, it's parent receives the mouse messages
|
---|
316 | if(!IsWindowEnabled(win32wnd->getWindowHandle())) {
|
---|
317 | if(win32wnd->getParent()) {
|
---|
318 | Win32BaseWindow *parent = win32wnd->getParent();;
|
---|
319 | if(parent) parent->addRef();
|
---|
320 | RELEASE_WNDOBJ(win32wnd);
|
---|
321 | win32wnd = parent;
|
---|
322 | }
|
---|
323 | fWasDisabled = TRUE;
|
---|
324 | }
|
---|
325 |
|
---|
326 | if(IsNCMouseMsg(win32wnd)) {
|
---|
327 | winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
|
---|
328 | winMsg->wParam = win32wnd->getLastHitTestVal();
|
---|
329 | winMsg->lParam = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
|
---|
330 | }
|
---|
331 | else {
|
---|
332 | ClientPoint.x = winMsg->pt.x;
|
---|
333 | ClientPoint.y = winMsg->pt.y;
|
---|
334 | MapWindowPoints(0, win32wnd->getWindowHandle(), (LPPOINT)&ClientPoint, 1);
|
---|
335 | winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
|
---|
336 | winMsg->wParam = GetMouseKeyState();
|
---|
337 | winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
|
---|
338 | }
|
---|
339 | EnableLogging();
|
---|
340 | if((fMsgRemoved == MSG_REMOVE) && ISMOUSE_CAPTURED())
|
---|
341 | {
|
---|
342 | if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
|
---|
343 | goto dummymessage; //dinput swallowed message
|
---|
344 | }
|
---|
345 | }
|
---|
346 |
|
---|
347 | if(fWasDisabled) {
|
---|
348 | if(win32wnd) {
|
---|
349 | winMsg->hwnd = win32wnd->getWindowHandle();
|
---|
350 | }
|
---|
351 | else goto dummymessage; //don't send mouse messages to disabled windows
|
---|
352 | }
|
---|
353 |
|
---|
354 | DisableLogging();
|
---|
355 | if ((winMsg->message == WINWM_LBUTTONDOWN) ||
|
---|
356 | (winMsg->message == WINWM_RBUTTONDOWN) ||
|
---|
357 | (winMsg->message == WINWM_MBUTTONDOWN) ||
|
---|
358 | (winMsg->message == WINWM_NCLBUTTONDOWN) ||
|
---|
359 | (winMsg->message == WINWM_NCRBUTTONDOWN) ||
|
---|
360 | (winMsg->message == WINWM_NCMBUTTONDOWN))
|
---|
361 | {
|
---|
362 | if(fGenerateDoubleClick && doubleClickMsg.message == winMsg->message &&
|
---|
363 | winMsg->time - doubleClickMsg.time < GetDoubleClickTime() &&
|
---|
364 | (abs(winMsg->pt.x - doubleClickMsg.pt.x) < GetSystemMetrics(SM_CXDOUBLECLK_W)/2) &&
|
---|
365 | (abs(winMsg->pt.y - doubleClickMsg.pt.y) < GetSystemMetrics(SM_CYDOUBLECLK_W)/2))
|
---|
366 | {
|
---|
367 | dprintf(("single -> double click"));
|
---|
368 | if(winMsg->message >= WINWM_LBUTTONDOWN) {
|
---|
369 | winMsg->message += (WINWM_LBUTTONDBLCLK - WINWM_LBUTTONDOWN);
|
---|
370 | }
|
---|
371 | else winMsg->message += (WINWM_LBUTTONDBLCLK - WINWM_NCLBUTTONDOWN);
|
---|
372 | doubleClickMsg.message = 0;
|
---|
373 | }
|
---|
374 | else {
|
---|
375 | dprintf(("save for double click"));
|
---|
376 | doubleClickMsg = *winMsg;
|
---|
377 | if(doubleClickMsg.message >= WINWM_NCLBUTTONDOWN && doubleClickMsg.message <= WINWM_NCMBUTTONDOWN) {
|
---|
378 | doubleClickMsg.message += (WINWM_LBUTTONDOWN - WINWM_NCLBUTTONDOWN);
|
---|
379 | }
|
---|
380 | }
|
---|
381 | }
|
---|
382 | EnableLogging();
|
---|
383 |
|
---|
384 | break;
|
---|
385 | }
|
---|
386 |
|
---|
387 | case WM_BUTTON2CLICK:
|
---|
388 | case WM_BUTTON1CLICK:
|
---|
389 | case WM_BUTTON3CLICK:
|
---|
390 | goto dummymessage;
|
---|
391 |
|
---|
392 | case WM_BUTTON2MOTIONSTART:
|
---|
393 | case WM_BUTTON2MOTIONEND:
|
---|
394 | case WM_BUTTON1MOTIONSTART:
|
---|
395 | case WM_BUTTON1MOTIONEND:
|
---|
396 | case WM_BUTTON3MOTIONSTART:
|
---|
397 | case WM_BUTTON3MOTIONEND:
|
---|
398 | //no break; translate to WM_MOUSEMOVE
|
---|
399 | //Some applications (e.g. Unreal) retrieve all mouse messages
|
---|
400 | //when a mouse button is pressed and don't expect WM_NULL
|
---|
401 |
|
---|
402 | case WM_MOUSEMOVE:
|
---|
403 | {
|
---|
404 | //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
|
---|
405 |
|
---|
406 | HWND hwnd;
|
---|
407 |
|
---|
408 | dprintf2(("WM_NCMOUSEMOVE (%d,%d)", winMsg->pt.x, winMsg->pt.y));
|
---|
409 | DisableLogging();
|
---|
410 | if(GetCapture() != winMsg->hwnd)
|
---|
411 | {
|
---|
412 | hwnd = WindowFromPoint(winMsg->pt);
|
---|
413 | if(win32wnd->getWindowHandle() != hwnd) {
|
---|
414 | RELEASE_WNDOBJ(win32wnd);
|
---|
415 | win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
416 | if(win32wnd == NULL) {
|
---|
417 | DebugInt3();
|
---|
418 | EnableLogging();
|
---|
419 | goto dummymessage;
|
---|
420 | }
|
---|
421 | winMsg->hwnd = hwnd;
|
---|
422 | }
|
---|
423 | }
|
---|
424 |
|
---|
425 | //if a window is disabled, it's parent receives the mouse messages
|
---|
426 | if(!IsWindowEnabled(win32wnd->getWindowHandle())) {
|
---|
427 | if(win32wnd->getParent()) {
|
---|
428 | Win32BaseWindow *parent = win32wnd->getParent();;
|
---|
429 | if(parent) parent->addRef();
|
---|
430 | RELEASE_WNDOBJ(win32wnd);
|
---|
431 | win32wnd = parent;
|
---|
432 | }
|
---|
433 | fWasDisabled = TRUE;
|
---|
434 | }
|
---|
435 | if(IsNCMouseMsg(win32wnd))
|
---|
436 | {
|
---|
437 | winMsg->message = WINWM_NCMOUSEMOVE;
|
---|
438 | winMsg->wParam = (WPARAM)win32wnd->getLastHitTestVal();
|
---|
439 | winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
|
---|
440 | }
|
---|
441 | else
|
---|
442 | {
|
---|
443 | ClientPoint.x = winMsg->pt.x;
|
---|
444 | ClientPoint.y = winMsg->pt.y;
|
---|
445 | MapWindowPoints(0, win32wnd->getWindowHandle(), (LPPOINT)&ClientPoint, 1);
|
---|
446 |
|
---|
447 | winMsg->message = WINWM_MOUSEMOVE;
|
---|
448 | winMsg->wParam = GetMouseKeyState();
|
---|
449 | winMsg->lParam = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
|
---|
450 | }
|
---|
451 | EnableLogging();
|
---|
452 | if((fMsgRemoved == MSG_REMOVE) && ISMOUSE_CAPTURED())
|
---|
453 | {
|
---|
454 | if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
|
---|
455 | goto dummymessage; //dinput swallowed message
|
---|
456 | }
|
---|
457 | }
|
---|
458 | if(fWasDisabled) {
|
---|
459 | if(win32wnd) {
|
---|
460 | winMsg->hwnd = win32wnd->getWindowHandle();
|
---|
461 | }
|
---|
462 | else {
|
---|
463 | goto dummymessage; //don't send mouse messages to disabled windows
|
---|
464 | }
|
---|
465 | }
|
---|
466 | //OS/2 Window coordinates -> Win32 Window coordinates
|
---|
467 | break;
|
---|
468 | }
|
---|
469 |
|
---|
470 | case WM_CONTROL:
|
---|
471 | goto dummymessage;
|
---|
472 |
|
---|
473 | case WM_COMMAND:
|
---|
474 | if(SHORT1FROMMP(os2Msg->mp2) == CMDSRC_MENU) {
|
---|
475 | winMsg->message = WINWM_COMMAND;
|
---|
476 | winMsg->wParam = (WPARAM)SHORT1FROMMP(os2Msg->mp1); //id
|
---|
477 | break;
|
---|
478 | }
|
---|
479 | //todo controls
|
---|
480 | goto dummymessage;
|
---|
481 |
|
---|
482 | case WM_SYSCOMMAND:
|
---|
483 | {
|
---|
484 | ULONG x = 0, y = 0;
|
---|
485 | ULONG win32sc;
|
---|
486 |
|
---|
487 | if(SHORT2FROMMP(os2Msg->mp2) == TRUE) {//syscommand caused by mouse action
|
---|
488 | POINTL pointl;
|
---|
489 | WinQueryPointerPos(HWND_DESKTOP, &pointl);
|
---|
490 | x = pointl.x;
|
---|
491 | y = mapScreenY(y);
|
---|
492 | }
|
---|
493 | switch(SHORT1FROMMP(os2Msg->mp1)) {
|
---|
494 | case SC_MOVE:
|
---|
495 | win32sc = SC_MOVE_W;
|
---|
496 | break;
|
---|
497 | case SC_CLOSE:
|
---|
498 | {
|
---|
499 | //FALSE -> keyboard operation = user pressed Alt-F4 -> close app
|
---|
500 | //TRUE -> user clicked on close button -> close window
|
---|
501 | if(SHORT2FROMMP(os2Msg->mp2) == FALSE)
|
---|
502 | {
|
---|
503 | HWND hwnd = win32wnd->GetTopParent();
|
---|
504 | if(win32wnd->getWindowHandle() != hwnd) {
|
---|
505 | RELEASE_WNDOBJ(win32wnd);
|
---|
506 | win32wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
|
---|
507 | if(win32wnd == NULL) {
|
---|
508 | DebugInt3();
|
---|
509 | goto dummymessage;
|
---|
510 | }
|
---|
511 | winMsg->hwnd = hwnd;
|
---|
512 | }
|
---|
513 | }
|
---|
514 | win32sc = SC_CLOSE_W;
|
---|
515 | break;
|
---|
516 | }
|
---|
517 | case SC_MAXIMIZE:
|
---|
518 | win32sc = SC_MAXIMIZE_W;
|
---|
519 | break;
|
---|
520 | case SC_MINIMIZE:
|
---|
521 | win32sc = SC_MINIMIZE_W;
|
---|
522 | break;
|
---|
523 | case SC_NEXTFRAME:
|
---|
524 | case SC_NEXTWINDOW:
|
---|
525 | win32sc = SC_NEXTWINDOW_W;
|
---|
526 | break;
|
---|
527 | case SC_RESTORE:
|
---|
528 | win32sc = SC_RESTORE_W;
|
---|
529 | break;
|
---|
530 | case SC_TASKMANAGER:
|
---|
531 | win32sc = SC_TASKLIST_W;
|
---|
532 | break;
|
---|
533 | default:
|
---|
534 | dprintf(("Unknown/unsupported SC command %d", SHORT1FROMMP(os2Msg->mp1)));
|
---|
535 | goto dummymessage;
|
---|
536 | }
|
---|
537 | winMsg->message= WINWM_SYSCOMMAND;
|
---|
538 | winMsg->wParam = (WPARAM)win32sc;
|
---|
539 | winMsg->lParam = MAKELONG((USHORT)x, (USHORT)y);
|
---|
540 | break;
|
---|
541 | }
|
---|
542 |
|
---|
543 | case WM_CHAR_SPECIAL:
|
---|
544 | {
|
---|
545 | // @@@PH
|
---|
546 | // special char message from the keyboard hook
|
---|
547 | dprintf(("PM: WM_CHAR_SPECIAL\n"));
|
---|
548 |
|
---|
549 | // NO BREAK! FALLTHRU CASE!
|
---|
550 | }
|
---|
551 |
|
---|
552 | case WM_CHAR:
|
---|
553 | {
|
---|
554 | ULONG repeatCount=0;
|
---|
555 | ULONG virtualKey=0;
|
---|
556 | ULONG keyFlags=0;
|
---|
557 | USHORT scanCode=0;
|
---|
558 | ULONG flags = SHORT1FROMMP(os2Msg->mp1);
|
---|
559 | BOOL keyWasPressed, isExtended = FALSE;
|
---|
560 | char c;
|
---|
561 | USHORT usPMScanCode = CHAR4FROMMP(os2Msg->mp1);
|
---|
562 |
|
---|
563 | teb->o.odin.fTranslated = FALSE;
|
---|
564 | repeatCount = CHAR3FROMMP(os2Msg->mp1);
|
---|
565 | scanCode = CHAR4FROMMP(os2Msg->mp1);
|
---|
566 | keyWasPressed = ((SHORT1FROMMP (os2Msg->mp1) & KC_PREVDOWN) == KC_PREVDOWN);
|
---|
567 |
|
---|
568 | dprintf(("PM: WM_CHAR: %x %x rep=%d scancode=%x", SHORT1FROMMP(os2Msg->mp2), SHORT2FROMMP(os2Msg->mp2), repeatCount, scanCode));
|
---|
569 | dprintf(("PM: WM_CHAR: hwnd %x flags %x mp1 %x, mp2 %x, time=%08xh", win32wnd->getWindowHandle(), flags, os2Msg->mp1, os2Msg->mp2, os2Msg->time));
|
---|
570 |
|
---|
571 | // vitali add begin
|
---|
572 | if ( ( SHORT1FROMMP(os2Msg->mp2) & 0x0FF ) == 0x0E0 )
|
---|
573 | {
|
---|
574 | // an extended key ( arrows, ins, del and so on )
|
---|
575 | // get "virtual" scancode from character code because
|
---|
576 | // for "regular" keys they are equal
|
---|
577 | if(!(flags & (KC_SHIFT|KC_ALT|KC_CTRL))) {
|
---|
578 | scanCode = ( SHORT1FROMMP(os2Msg->mp2) >> 8) & 0x0FF;
|
---|
579 | }
|
---|
580 | isExtended = TRUE;
|
---|
581 | }
|
---|
582 | // vitali add end
|
---|
583 |
|
---|
584 | // both WM_KEYUP & WM_KEYDOWN want a virtual key, find the right Win32 virtual key
|
---|
585 | // given the OS/2 virtual key and OS/2 character
|
---|
586 |
|
---|
587 | //if (((SHORT1FROMMP (mp1) & KC_CHAR) == KC_CHAR) ||
|
---|
588 | // ((SHORT1FROMMP (mp1) & KC_LONEKEY) == KC_LONEKEY))
|
---|
589 | c = 0;
|
---|
590 | if ((SHORT1FROMMP (os2Msg->mp1) & 0xFF) != 0)
|
---|
591 | {
|
---|
592 | c = SHORT1FROMMP (os2Msg->mp2);
|
---|
593 | if ((c >= 'A') && (c <= 'Z')) {
|
---|
594 | virtualKey = c;
|
---|
595 | goto VirtualKeyFound;
|
---|
596 | }
|
---|
597 | if ((c >='a') && (c <= 'z')) {
|
---|
598 | virtualKey = c - 32; // make it uppercase
|
---|
599 | goto VirtualKeyFound;
|
---|
600 | }
|
---|
601 | if ((c >= '0') && (c <= '9')) {
|
---|
602 | virtualKey = c;
|
---|
603 | goto VirtualKeyFound;
|
---|
604 | }
|
---|
605 | }
|
---|
606 |
|
---|
607 | VirtualKeyFound:
|
---|
608 | // dprintf (("VIRTUALKEYFOUND:(%x)", virtualKey));
|
---|
609 |
|
---|
610 | // @@@PH: what's this supposed to be?
|
---|
611 | // Adjust PM scancodes for Win* keys
|
---|
612 | if (scanCode >= 0x70)
|
---|
613 | scanCode -= 0x10;
|
---|
614 | // winMsg->wParam = pmscan2winkey[scanCode][0];
|
---|
615 | // wWinScan = pmscan2winkey[scanCode][1];
|
---|
616 |
|
---|
617 | {
|
---|
618 | BOOL fWinExtended;
|
---|
619 | BYTE bWinVKey;
|
---|
620 | WORD wWinScan;
|
---|
621 |
|
---|
622 | // Note: Numlock-state currently ignored, see below
|
---|
623 | KeyTranslatePMScanToWinVKey(usPMScanCode,
|
---|
624 | FALSE,
|
---|
625 | &bWinVKey,
|
---|
626 | &wWinScan,
|
---|
627 | &fWinExtended);
|
---|
628 | winMsg->wParam = bWinVKey;
|
---|
629 | winMsg->lParam = repeatCount & 0x0FFFF; // bit 0-15, repeatcount
|
---|
630 | winMsg->lParam |= (wWinScan & 0x1FF) << 16; // bit 16-23, scancode + bit 15 extended
|
---|
631 |
|
---|
632 | // Set the extended bit when appropriate
|
---|
633 | if (fWinExtended)
|
---|
634 | winMsg->lParam = winMsg->lParam | (1<<24);
|
---|
635 | }
|
---|
636 |
|
---|
637 | // Adjust VKEY value for pad digits if NumLock is on
|
---|
638 | if ((scanCode >= 0x47) && (scanCode <= 0x53) &&
|
---|
639 | (virtualKey >= 0x30) && (virtualKey >= 39))
|
---|
640 | winMsg->wParam = virtualKey + 0x30;
|
---|
641 |
|
---|
642 |
|
---|
643 | #define WIN_KEY_EXTENDED 0x01000000
|
---|
644 | #define WIN_KEY_DONTCARE 0x02000000
|
---|
645 | #define WIN_KEY_ALTHELD 0x20000000
|
---|
646 | #define WIN_KEY_PREVSTATE 0x40000000
|
---|
647 |
|
---|
648 | if (usPMScanCode == PMSCAN_ALTRIGHT)
|
---|
649 | {
|
---|
650 | // Turn message into CTRL-event
|
---|
651 | // The original PM message is still saved inside
|
---|
652 | // the TEB, the next call to TranslateMessage()
|
---|
653 | // will then generate the required additional message
|
---|
654 | // for the ALTGR-event.
|
---|
655 | winMsg->wParam = VK_LCONTROL_W;
|
---|
656 | winMsg->lParam = repeatCount & 0x0FFFF;
|
---|
657 | winMsg->lParam |= WINSCAN_CTRLLEFT << 16
|
---|
658 | | WIN_KEY_DONTCARE;
|
---|
659 |
|
---|
660 | if (flags & KC_KEYUP)
|
---|
661 | {
|
---|
662 | winMsg->message = WINWM_SYSKEYUP;
|
---|
663 | // winMsg->lParam |= 1 << 29; // bit 29, alt was pressed
|
---|
664 | winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
|
---|
665 | winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
|
---|
666 | }
|
---|
667 | else
|
---|
668 | {
|
---|
669 | winMsg->lParam |= WIN_KEY_ALTHELD;
|
---|
670 | if (keyWasPressed)
|
---|
671 | winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
|
---|
672 | winMsg->message = WINWM_KEYDOWN;
|
---|
673 | }
|
---|
674 |
|
---|
675 | break;
|
---|
676 | }
|
---|
677 |
|
---|
678 |
|
---|
679 | if (!(flags & KC_ALT))
|
---|
680 | {
|
---|
681 | //
|
---|
682 | // the Alt key is not pressed
|
---|
683 | // or no more pressed
|
---|
684 | //
|
---|
685 | if (flags & KC_KEYUP)
|
---|
686 | {
|
---|
687 | // check for a lonesome ALT key ...
|
---|
688 | if ( (flags & KC_LONEKEY) &&
|
---|
689 | (winMsg->wParam == VK_LMENU_W) )
|
---|
690 | {
|
---|
691 | winMsg->message = WINWM_SYSKEYUP;
|
---|
692 |
|
---|
693 | // held ALT-key when current key is released
|
---|
694 | // generates additional flag 0x2000000
|
---|
695 | // Note: PM seems to do this differently,
|
---|
696 | // KC_ALT is already reset
|
---|
697 | }
|
---|
698 | else
|
---|
699 | {
|
---|
700 | // send WM_KEYUP message
|
---|
701 | winMsg->message = WINWM_KEYUP;
|
---|
702 | }
|
---|
703 |
|
---|
704 | winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
|
---|
705 | winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
|
---|
706 | }
|
---|
707 | else
|
---|
708 | {
|
---|
709 | // send WM_KEYDOWN message
|
---|
710 | winMsg->message = WINWM_KEYDOWN;
|
---|
711 | if (keyWasPressed)
|
---|
712 | winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
|
---|
713 | }
|
---|
714 | }
|
---|
715 | else
|
---|
716 | {
|
---|
717 | //
|
---|
718 | // the Alt key is pressed
|
---|
719 | //
|
---|
720 | if (flags & KC_KEYUP)
|
---|
721 | {
|
---|
722 | // send WM_SYSKEYUP message
|
---|
723 | winMsg->message = WINWM_SYSKEYUP;
|
---|
724 | winMsg->lParam |= 1 << 30; // bit 30, previous state, always 1 for a WM_KEYUP message
|
---|
725 | winMsg->lParam |= 1 << 31; // bit 31, transition state, always 1 for WM_KEYUP
|
---|
726 | }
|
---|
727 | else
|
---|
728 | {
|
---|
729 | // send WM_SYSKEYDOWN message
|
---|
730 | winMsg->message = WINWM_SYSKEYDOWN;
|
---|
731 | if (keyWasPressed)
|
---|
732 | winMsg->lParam |= 1 << 30; // bit 30, previous state, 1 means key was pressed
|
---|
733 |
|
---|
734 | // pressed ALT-key generates additional flag 0x2000000
|
---|
735 | // if the current window has keyboard focus
|
---|
736 | winMsg->lParam |= 1 << 29;
|
---|
737 | }
|
---|
738 | }
|
---|
739 |
|
---|
740 | if (ISKDB_CAPTURED())
|
---|
741 | {
|
---|
742 | if (DInputKeyBoardHandler(winMsg)) {
|
---|
743 | goto dummymessage; //dinput swallowed message
|
---|
744 | }
|
---|
745 | }
|
---|
746 | break;
|
---|
747 | }
|
---|
748 |
|
---|
749 | case WM_TIMER:
|
---|
750 | //Why was this check here????
|
---|
751 | // if (os2Msg->mp2)
|
---|
752 | // {
|
---|
753 | BOOL sys;
|
---|
754 | ULONG id;
|
---|
755 |
|
---|
756 | if (TIMER_GetTimerInfo(os2Msg->hwnd,(ULONG)os2Msg->mp1,&sys,&id))
|
---|
757 | {
|
---|
758 | winMsg->wParam = (WPARAM)id;
|
---|
759 | winMsg->message= (sys) ? WINWM_SYSTIMER : WINWM_TIMER;
|
---|
760 | break;
|
---|
761 | }
|
---|
762 | // }
|
---|
763 | goto dummymessage; //for caret blinking
|
---|
764 |
|
---|
765 | case WM_SETWINDOWPARAMS:
|
---|
766 | {
|
---|
767 | WNDPARAMS *wndParams = (WNDPARAMS *)os2Msg->mp1;
|
---|
768 |
|
---|
769 | if(wndParams->fsStatus & WPM_TEXT) {
|
---|
770 | winMsg->message = WINWM_SETTEXT;
|
---|
771 | winMsg->lParam = (LPARAM)wndParams->pszText;
|
---|
772 | break;
|
---|
773 | }
|
---|
774 | goto dummymessage;
|
---|
775 | }
|
---|
776 |
|
---|
777 | #if 0
|
---|
778 | case WM_QUERYWINDOWPARAMS:
|
---|
779 | {
|
---|
780 | PWNDPARAMS wndpars = (PWNDPARAMS)mp1;
|
---|
781 | ULONG textlen;
|
---|
782 | PSZ wintext;
|
---|
783 |
|
---|
784 | if(wndpars->fsStatus & (WPM_CCHTEXT | WPM_TEXT))
|
---|
785 | {
|
---|
786 | if(wndpars->fsStatus & WPM_CCHTEXT)
|
---|
787 | wndpars->cchText = win32wnd->MsgGetTextLength();
|
---|
788 | if(wndpars->fsStatus & WPM_TEXT)
|
---|
789 | wndpars->pszText = win32wnd->MsgGetText();
|
---|
790 |
|
---|
791 | wndpars->fsStatus = 0;
|
---|
792 | wndpars->cbCtlData = 0;
|
---|
793 | wndpars->cbPresParams = 0;
|
---|
794 | goto dummymessage;
|
---|
795 | }
|
---|
796 | }
|
---|
797 | #endif
|
---|
798 |
|
---|
799 | case WM_PAINT:
|
---|
800 | {
|
---|
801 | if(win32wnd->IsWindowIconic()) {
|
---|
802 | winMsg->message = WINWM_PAINTICON;
|
---|
803 | }
|
---|
804 | else winMsg->message = WINWM_PAINT;
|
---|
805 | break;
|
---|
806 | }
|
---|
807 |
|
---|
808 | case WM_CONTEXTMENU:
|
---|
809 | winMsg->message = WINWM_CONTEXTMENU;
|
---|
810 | winMsg->wParam = win32wnd->getWindowHandle();
|
---|
811 | winMsg->lParam = MAKELONG(winMsg->pt.x,winMsg->pt.y);
|
---|
812 | break;
|
---|
813 |
|
---|
814 | case WM_RENDERFMT:
|
---|
815 | winMsg->message = WINWM_RENDERFORMAT;
|
---|
816 | winMsg->wParam = (UINT) os2Msg->mp1;
|
---|
817 | break;
|
---|
818 |
|
---|
819 | case WM_RENDERALLFMTS:
|
---|
820 | winMsg->message = WINWM_RENDERALLFORMATS;
|
---|
821 | break;
|
---|
822 |
|
---|
823 | case WM_DESTROYCLIPBOARD:
|
---|
824 | winMsg->message = WINWM_DESTROYCLIPBOARD;
|
---|
825 | break;
|
---|
826 |
|
---|
827 | case WM_HSCROLL:
|
---|
828 | case WM_VSCROLL:
|
---|
829 | winMsg->message = (os2Msg->msg == WM_HSCROLL) ? WINWM_HSCROLL : WINWM_VSCROLL;
|
---|
830 | winMsg->lParam = 0;
|
---|
831 | winMsg->wParam = 0;
|
---|
832 | switch(SHORT2FROMMP(os2Msg->mp2)) {
|
---|
833 | case SB_LINERIGHT:
|
---|
834 | winMsg->wParam = SB_LINERIGHT_W;
|
---|
835 | break;
|
---|
836 | case SB_LINELEFT:
|
---|
837 | winMsg->wParam = SB_LINELEFT_W;
|
---|
838 | break;
|
---|
839 | case SB_PAGELEFT:
|
---|
840 | winMsg->wParam = SB_PAGELEFT_W;
|
---|
841 | break;
|
---|
842 | case SB_PAGERIGHT:
|
---|
843 | winMsg->wParam = SB_PAGERIGHT_W;
|
---|
844 | break;
|
---|
845 | default:
|
---|
846 | dprintf(("Unsupported WM_H/VSCROLL message %x!!", SHORT2FROMMP(os2Msg->mp2)));
|
---|
847 | goto dummymessage;
|
---|
848 | }
|
---|
849 | break;
|
---|
850 |
|
---|
851 | case WM_INITMENU:
|
---|
852 | case WM_MENUSELECT:
|
---|
853 | case WM_MENUEND:
|
---|
854 | case WM_NEXTMENU:
|
---|
855 | case WM_SYSCOLORCHANGE:
|
---|
856 | case WM_SYSVALUECHANGED:
|
---|
857 | case WM_SETSELECTION:
|
---|
858 | case WM_PPAINT:
|
---|
859 | case WM_PSETFOCUS:
|
---|
860 | case WM_PSYSCOLORCHANGE:
|
---|
861 | case WM_PSIZE:
|
---|
862 | case WM_PACTIVATE:
|
---|
863 | case WM_PCONTROL:
|
---|
864 | case WM_HELP:
|
---|
865 | case WM_APPTERMINATENOTIFY:
|
---|
866 | case WM_PRESPARAMCHANGED:
|
---|
867 | case WM_DRAWITEM:
|
---|
868 | case WM_MEASUREITEM:
|
---|
869 | case WM_CONTROLPOINTER:
|
---|
870 | case WM_QUERYDLGCODE:
|
---|
871 | case WM_SUBSTITUTESTRING:
|
---|
872 | case WM_MATCHMNEMONIC:
|
---|
873 | case WM_SAVEAPPLICATION:
|
---|
874 | case WM_SEMANTICEVENT:
|
---|
875 | default:
|
---|
876 | dummymessage:
|
---|
877 | dprintf2(("dummy message %x %x %x %x", os2Msg->hwnd, os2Msg->msg, os2Msg->mp1, os2Msg->mp2));
|
---|
878 | winMsg->message = 0;
|
---|
879 | winMsg->wParam = 0;
|
---|
880 | winMsg->lParam = 0;
|
---|
881 | if(win32wnd) RELEASE_WNDOBJ(win32wnd);
|
---|
882 | return FALSE;
|
---|
883 | }
|
---|
884 | if(win32wnd) RELEASE_WNDOBJ(win32wnd);
|
---|
885 | return TRUE;
|
---|
886 | }
|
---|
887 | //******************************************************************************
|
---|
888 | //******************************************************************************
|
---|
889 | BOOL OSLibWinTranslateMessage(MSG *msg)
|
---|
890 | {
|
---|
891 | TEB *teb;
|
---|
892 | MSG extramsg;
|
---|
893 |
|
---|
894 | teb = GetThreadTEB();
|
---|
895 | if(!teb)
|
---|
896 | return FALSE;
|
---|
897 |
|
---|
898 | UCHAR ucPMScanCode = CHAR4FROMMP(teb->o.odin.os2msg.mp1);
|
---|
899 | ULONG fl = SHORT1FROMMP(teb->o.odin.os2msg.mp1);
|
---|
900 |
|
---|
901 |
|
---|
902 | // special ALTRIGHT treatment:
|
---|
903 | // we try to insert another WM_KEYDOWN or WM_KEYUP instead of
|
---|
904 | // the usual WM_CHAR which is expected here.
|
---|
905 | // -> experimental
|
---|
906 | if (ucPMScanCode == PMSCAN_ALTRIGHT)
|
---|
907 | {
|
---|
908 | // it's really an OS/2-style WM_CHAR message?
|
---|
909 | // and not previously translated?
|
---|
910 | if ( ( (teb->o.odin.os2msg.msg != WM_CHAR) &&
|
---|
911 | (teb->o.odin.os2msg.msg != WM_CHAR_SPECIAL) ) ||
|
---|
912 | (teb->o.odin.fTranslated) )
|
---|
913 | return FALSE;
|
---|
914 |
|
---|
915 | memcpy(&extramsg, msg, sizeof(MSG));
|
---|
916 |
|
---|
917 | // AltGr is not released with WINWM_SYSKEYUP, but WINWM_KEYUP
|
---|
918 | if (fl & KC_KEYUP)
|
---|
919 | extramsg.message = WINWM_KEYUP;
|
---|
920 |
|
---|
921 | extramsg.wParam = VK_RMENU_W;
|
---|
922 |
|
---|
923 | // mask out message bits and scan code
|
---|
924 | extramsg.lParam &= (0xDC00FFFF);
|
---|
925 | extramsg.lParam |= (WINSCAN_ALTRIGHT & 0x1FF) << 16;
|
---|
926 | extramsg.lParam |= WIN_KEY_EXTENDED;
|
---|
927 | if (!(fl & KC_KEYUP))
|
---|
928 | extramsg.lParam |= WIN_KEY_ALTHELD;
|
---|
929 |
|
---|
930 | // insert message into the queue
|
---|
931 | setThreadQueueExtraCharMessage(teb, &extramsg);
|
---|
932 | return TRUE;
|
---|
933 | }
|
---|
934 |
|
---|
935 | //NOTE: These actually need to be posted so that the next message retrieved by GetMessage contains
|
---|
936 | // the newly generated WM_CHAR message.
|
---|
937 | if(!teb->o.odin.fTranslated &&
|
---|
938 | teb->o.odin.os2msg.msg == WM_CHAR &&
|
---|
939 | !((SHORT1FROMMP(teb->o.odin.os2msg.mp1) & KC_KEYUP) == KC_KEYUP))
|
---|
940 | {
|
---|
941 | //TranslatedMessage was called before DispatchMessage, so queue WM_CHAR message
|
---|
942 | memcpy(&extramsg, msg, sizeof(MSG));
|
---|
943 | extramsg.wParam = SHORT1FROMMP(teb->o.odin.os2msg.mp2);
|
---|
944 | extramsg.lParam = 0;
|
---|
945 |
|
---|
946 | // ESCAPE generates a WM_CHAR under windows, so take
|
---|
947 | // special care for this here.
|
---|
948 | switch (ucPMScanCode)
|
---|
949 | {
|
---|
950 | case PMSCAN_ESC:
|
---|
951 | extramsg.wParam = VK_ESCAPE_W;
|
---|
952 | fl |= KC_CHAR;
|
---|
953 | break;
|
---|
954 | }
|
---|
955 |
|
---|
956 | if(!(fl & KC_CHAR) && msg->message < WINWM_SYSKEYDOWN)
|
---|
957 | {
|
---|
958 | return FALSE;
|
---|
959 | }
|
---|
960 |
|
---|
961 | if(fl & KC_VIRTUALKEY)
|
---|
962 | {
|
---|
963 | if(msg->wParam)
|
---|
964 | {
|
---|
965 | if ((msg->wParam >= VK_NUMPAD0_W) &&
|
---|
966 | (msg->wParam <= VK_NUMPAD9_W))
|
---|
967 | extramsg.wParam = msg->wParam - 0x30;
|
---|
968 | else
|
---|
969 | extramsg.wParam = msg->wParam;
|
---|
970 | }
|
---|
971 | else
|
---|
972 | extramsg.wParam = SHORT2FROMMP(teb->o.odin.os2msg.mp2);
|
---|
973 | }
|
---|
974 |
|
---|
975 |
|
---|
976 | if(msg->message >= WINWM_SYSKEYDOWN)
|
---|
977 | extramsg.message = WINWM_SYSCHAR;
|
---|
978 | else
|
---|
979 | extramsg.message = WINWM_CHAR;
|
---|
980 |
|
---|
981 | if(fl & KC_DEADKEY)
|
---|
982 | extramsg.message++; //WM_DEADCHAR/WM_SYSDEADCHAR
|
---|
983 |
|
---|
984 |
|
---|
985 | extramsg.lParam = msg->lParam & 0x00FFFFFF;
|
---|
986 | if(fl & KC_ALT)
|
---|
987 | extramsg.lParam |= (1<<29);
|
---|
988 | if(fl & KC_PREVDOWN)
|
---|
989 | extramsg.lParam |= (1<<30);
|
---|
990 | if(fl & KC_KEYUP)
|
---|
991 | extramsg.lParam |= (1<<31);
|
---|
992 |
|
---|
993 | // insert message into the queue
|
---|
994 | setThreadQueueExtraCharMessage(teb, &extramsg);
|
---|
995 | return TRUE;
|
---|
996 | }
|
---|
997 | return FALSE;
|
---|
998 | }
|
---|
999 | //******************************************************************************
|
---|
1000 | //******************************************************************************
|
---|
1001 |
|
---|