1 | /* $Id: oslibmsg.cpp,v 1.44 2001-10-03 18:37:51 sandervl Exp $ */
|
---|
2 | /*
|
---|
3 | * Window message translation functions for OS/2
|
---|
4 | *
|
---|
5 | *
|
---|
6 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | * TODO: Some messages that are sent to the frame window are directly passed on to the client
|
---|
12 | * -> Get/PeekMessage never gets them as we return a dummy message for non-client windows
|
---|
13 | * (i.e. menu WM_COMMAND messages)
|
---|
14 | *
|
---|
15 | * TODO: Filter translation isn't correct! (for posted messages or messages that don't have
|
---|
16 | * a PM version.
|
---|
17 | *
|
---|
18 | */
|
---|
19 | #define INCL_WIN
|
---|
20 | #define INCL_PM
|
---|
21 | #define INCL_DOSPROCESS
|
---|
22 | #include <os2wrap.h>
|
---|
23 | #include <string.h>
|
---|
24 | #include <misc.h>
|
---|
25 | #include "oslibmsg.h"
|
---|
26 | #include <winconst.h>
|
---|
27 | #include <win32api.h>
|
---|
28 | #include <winuser32.h>
|
---|
29 | #include "oslibutil.h"
|
---|
30 | #include "timer.h"
|
---|
31 | #include <thread.h>
|
---|
32 | #include <wprocess.h>
|
---|
33 | #include "pmwindow.h"
|
---|
34 | #include "oslibwin.h"
|
---|
35 | #include <win\hook.h>
|
---|
36 |
|
---|
37 | #define DBG_LOCALLOG DBG_oslibmsg
|
---|
38 | #include "dbglocal.h"
|
---|
39 |
|
---|
40 |
|
---|
41 |
|
---|
42 | typedef BOOL (EXPENTRY FNTRANS)(MSG *, QMSG *);
|
---|
43 | typedef FNTRANS *PFNTRANS;
|
---|
44 |
|
---|
45 | typedef struct
|
---|
46 | {
|
---|
47 | ULONG msgOS2;
|
---|
48 | ULONG msgWin32;
|
---|
49 | // PFNTRANS toOS2;
|
---|
50 | // PFNTRANS toWIN32;
|
---|
51 | } MSGTRANSTAB, *PMSGTRANSTAB;
|
---|
52 |
|
---|
53 | //NOTE: Must be ordered by win32 message id!!
|
---|
54 | MSGTRANSTAB MsgTransTab[] = {
|
---|
55 | WM_NULL, WINWM_NULL,
|
---|
56 | WM_CREATE, WINWM_CREATE,
|
---|
57 | WM_DESTROY, WINWM_DESTROY,
|
---|
58 | WM_MOVE, WINWM_MOVE, //TODO: Sent directly
|
---|
59 | WM_SIZE, WINWM_SIZE, //TODO: Sent directly
|
---|
60 | WM_ACTIVATE, WINWM_ACTIVATE,
|
---|
61 | WM_SETFOCUS, WINWM_SETFOCUS,
|
---|
62 | WM_SETFOCUS, WINWM_KILLFOCUS,
|
---|
63 | WM_ENABLE, WINWM_ENABLE,
|
---|
64 | WM_PAINT, WINWM_PAINT,
|
---|
65 | WM_CLOSE, WINWM_CLOSE,
|
---|
66 | WM_QUIT, WINWM_QUIT,
|
---|
67 | WM_SHOW, WINWM_SHOWWINDOW,
|
---|
68 |
|
---|
69 | WM_HITTEST, WINWM_NCHITTEST,
|
---|
70 |
|
---|
71 | //todo: not always right if mouse msg turns out to be for the client window
|
---|
72 | WM_MOUSEMOVE, WINWM_NCMOUSEMOVE,
|
---|
73 | WM_BUTTON1DOWN, WINWM_NCLBUTTONDOWN,
|
---|
74 | WM_BUTTON1UP, WINWM_NCLBUTTONUP,
|
---|
75 | WM_BUTTON1DBLCLK, WINWM_NCLBUTTONDBLCLK,
|
---|
76 | WM_BUTTON2DOWN, WINWM_NCRBUTTONDOWN,
|
---|
77 | WM_BUTTON2UP, WINWM_NCRBUTTONUP,
|
---|
78 | WM_BUTTON2DBLCLK, WINWM_NCRBUTTONDBLCLK,
|
---|
79 | WM_BUTTON3DOWN, WINWM_NCMBUTTONDOWN,
|
---|
80 | WM_BUTTON3UP, WINWM_NCMBUTTONUP,
|
---|
81 | WM_BUTTON3DBLCLK, WINWM_NCMBUTTONDBLCLK,
|
---|
82 |
|
---|
83 | //TODO: Needs better translation!
|
---|
84 | WM_CHAR, WINWM_KEYDOWN, //WM_KEYFIRST
|
---|
85 | WM_CHAR, WINWM_KEYUP,
|
---|
86 | WM_CHAR, WINWM_CHAR,
|
---|
87 | WM_CHAR, WINWM_DEADCHAR,
|
---|
88 | WM_CHAR, WINWM_SYSKEYDOWN,
|
---|
89 | WM_CHAR, WINWM_SYSKEYUP,
|
---|
90 | WM_CHAR, WINWM_SYSCHAR,
|
---|
91 | WM_CHAR, WINWM_SYSDEADCHAR,
|
---|
92 | WM_CHAR, WINWM_KEYLAST,
|
---|
93 |
|
---|
94 | //
|
---|
95 | WM_TIMER, WINWM_TIMER,
|
---|
96 |
|
---|
97 | //
|
---|
98 | //todo: not always right if mouse msg turns out to be for the nonclient window
|
---|
99 | WM_MOUSEMOVE, WINWM_MOUSEMOVE, //WM_MOUSEFIRST
|
---|
100 | WM_BUTTON1DOWN, WINWM_LBUTTONDOWN,
|
---|
101 | WM_BUTTON1UP, WINWM_LBUTTONUP,
|
---|
102 | WM_BUTTON1DBLCLK, WINWM_LBUTTONDBLCLK,
|
---|
103 | WM_BUTTON2DOWN, WINWM_RBUTTONDOWN,
|
---|
104 | WM_BUTTON2UP, WINWM_RBUTTONUP,
|
---|
105 | WM_BUTTON2DBLCLK, WINWM_RBUTTONDBLCLK,
|
---|
106 | WM_BUTTON3DOWN, WINWM_MBUTTONDOWN,
|
---|
107 | WM_BUTTON3UP, WINWM_MBUTTONUP,
|
---|
108 | WM_BUTTON3DBLCLK, WINWM_MBUTTONDBLCLK,
|
---|
109 | WM_BUTTON3DBLCLK, WINWM_MOUSEWHEEL, //WM_MOUSELAST
|
---|
110 | 999999999, 999999999,
|
---|
111 | };
|
---|
112 | #define MAX_MSGTRANSTAB (sizeof(MsgTransTab)/sizeof(MsgTransTab[0]))
|
---|
113 |
|
---|
114 | //******************************************************************************
|
---|
115 | //******************************************************************************
|
---|
116 | void WinToOS2MsgTranslate(MSG *winMsg, QMSG *os2Msg, BOOL isUnicode)
|
---|
117 | {
|
---|
118 | // memcpy(os2Msg, winMsg, sizeof(MSG));
|
---|
119 | // os2Msg->hwnd = Win32ToOS2Handle(winMsg->hwnd);
|
---|
120 | // os2Msg->reserved = 0;
|
---|
121 | }
|
---|
122 | //******************************************************************************
|
---|
123 | //TODO: NOT COMPLETE nor 100% CORRECT!!!
|
---|
124 | //If both the minimum & maximum message are unknown, the result can be wrong (max > min)!
|
---|
125 | //******************************************************************************
|
---|
126 | ULONG TranslateWinMsg(ULONG msg, BOOL fMinFilter)
|
---|
127 | {
|
---|
128 | if(msg == 0)
|
---|
129 | return 0;
|
---|
130 |
|
---|
131 | if(msg >= WINWM_USER)
|
---|
132 | return msg + WIN32APP_POSTMSG;
|
---|
133 |
|
---|
134 | for(int i=0;i<MAX_MSGTRANSTAB;i++)
|
---|
135 | {
|
---|
136 | if(fMinFilter && MsgTransTab[i].msgWin32 >= msg) {
|
---|
137 | return MsgTransTab[i].msgOS2;
|
---|
138 | }
|
---|
139 | else
|
---|
140 | if(!fMinFilter && MsgTransTab[i].msgWin32 >= msg) {
|
---|
141 | if(MsgTransTab[i].msgWin32 == msg)
|
---|
142 | return MsgTransTab[i].msgOS2;
|
---|
143 | else return MsgTransTab[i-1].msgOS2;
|
---|
144 | }
|
---|
145 | }
|
---|
146 |
|
---|
147 | //not found, get everything
|
---|
148 | dprintf(("WARNING: TranslateWinMsg: message %x not found", msg));
|
---|
149 | return 0;
|
---|
150 | }
|
---|
151 | //******************************************************************************
|
---|
152 | //******************************************************************************
|
---|
153 | void OSLibWinPostQuitMessage(ULONG nExitCode)
|
---|
154 | {
|
---|
155 | APIRET rc;
|
---|
156 |
|
---|
157 | rc = WinPostQueueMsg(NULLHANDLE, WM_QUIT, MPFROMLONG(nExitCode), 0);
|
---|
158 | dprintf(("WinPostQueueMsg %d returned %d", nExitCode, rc));
|
---|
159 | }
|
---|
160 | //******************************************************************************
|
---|
161 | //******************************************************************************
|
---|
162 | LONG OSLibWinDispatchMsg(MSG *msg, BOOL isUnicode)
|
---|
163 | {
|
---|
164 | TEB *teb;
|
---|
165 | QMSG os2msg;
|
---|
166 | LONG rc;
|
---|
167 |
|
---|
168 | teb = GetThreadTEB();
|
---|
169 | if(teb == NULL) {
|
---|
170 | DebugInt3();
|
---|
171 | return FALSE;
|
---|
172 | }
|
---|
173 |
|
---|
174 | //TODO: What to do if app changed msg? (translate)
|
---|
175 | // WinToOS2MsgTranslate(msg, &qmsg, isUnicode);
|
---|
176 |
|
---|
177 | if(!memcmp(msg, &teb->o.odin.winmsg, sizeof(MSG)) || msg->hwnd == 0) {
|
---|
178 | memcpy(&os2msg, &teb->o.odin.os2msg, sizeof(QMSG));
|
---|
179 | teb->o.odin.os2msg.time = -1;
|
---|
180 | teb->o.odin.winmsg.time = -1;
|
---|
181 | if(msg->hwnd) {
|
---|
182 | teb->o.odin.nrOfMsgs = 1;
|
---|
183 | teb->o.odin.msgstate++; //odd -> next call to our PM window handler should dispatch the translated msg
|
---|
184 | memcpy(&teb->o.odin.msg, msg, sizeof(MSG));
|
---|
185 | }
|
---|
186 | if(os2msg.hwnd || os2msg.msg == WM_QUIT) {
|
---|
187 | memset(&teb->o.odin.os2msg, 0, sizeof(teb->o.odin.os2msg));
|
---|
188 | memset(&teb->o.odin.winmsg, 0, sizeof(teb->o.odin.winmsg));
|
---|
189 | return (LONG)WinDispatchMsg(teb->o.odin.hab, &os2msg);
|
---|
190 | }
|
---|
191 | //SvL: Don't dispatch messages sent by PostThreadMessage (correct??)
|
---|
192 | // Or WM_TIMER msgs with no window handle or timer proc
|
---|
193 | return 0;
|
---|
194 |
|
---|
195 | }
|
---|
196 | else {//is this allowed?
|
---|
197 | // dprintf(("WARNING: OSLibWinDispatchMsg: called with own message!"));
|
---|
198 | return SendMessageA(msg->hwnd, msg->message, msg->wParam, msg->lParam);
|
---|
199 | }
|
---|
200 | }
|
---|
201 | //******************************************************************************
|
---|
202 | //******************************************************************************
|
---|
203 | BOOL OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
|
---|
204 | BOOL isUnicode)
|
---|
205 | {
|
---|
206 | BOOL rc, eaten;
|
---|
207 | TEB *teb;
|
---|
208 | QMSG os2msg;
|
---|
209 | HWND hwndOS2 = 0;
|
---|
210 | ULONG filtermin, filtermax;
|
---|
211 |
|
---|
212 | if(hwnd) {
|
---|
213 | hwndOS2 = Win32ToOS2Handle(hwnd);
|
---|
214 | if(hwndOS2 == NULL) {
|
---|
215 | memset(pMsg, 0, sizeof(MSG));
|
---|
216 | dprintf(("GetMsg: window %x NOT FOUND!", hwnd));
|
---|
217 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
218 | return TRUE;
|
---|
219 | }
|
---|
220 | }
|
---|
221 |
|
---|
222 | teb = GetThreadTEB();
|
---|
223 | if(teb == NULL) {
|
---|
224 | DebugInt3();
|
---|
225 | return TRUE;
|
---|
226 | }
|
---|
227 |
|
---|
228 | if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd)) {
|
---|
229 | if(uMsgFilterMin) {
|
---|
230 | if(teb->o.odin.msgWCHAR.message < uMsgFilterMin)
|
---|
231 | goto continuegetmsg;
|
---|
232 | }
|
---|
233 | if(uMsgFilterMax) {
|
---|
234 | if(teb->o.odin.msgWCHAR.message > uMsgFilterMax)
|
---|
235 | goto continuegetmsg;
|
---|
236 | }
|
---|
237 | teb->o.odin.fTranslated = FALSE;
|
---|
238 | memcpy(pMsg, &teb->o.odin.msgWCHAR, sizeof(MSG));
|
---|
239 | teb->o.odin.os2msg.msg = 0;
|
---|
240 | teb->o.odin.os2msg.hwnd = 0;
|
---|
241 | return (pMsg->message != WINWM_QUIT);
|
---|
242 | }
|
---|
243 |
|
---|
244 | continuegetmsg:
|
---|
245 | if(hwnd) {
|
---|
246 | filtermin = TranslateWinMsg(uMsgFilterMin, TRUE);
|
---|
247 | filtermax = TranslateWinMsg(uMsgFilterMax, FALSE);
|
---|
248 | if(filtermin > filtermax) {
|
---|
249 | ULONG tmp = filtermin;
|
---|
250 | filtermin = filtermax;
|
---|
251 | filtermax = filtermin;
|
---|
252 | }
|
---|
253 | do {
|
---|
254 | WinWaitMsg(teb->o.odin.hab, filtermin, filtermax);
|
---|
255 | rc = OSLibWinPeekMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, PM_REMOVE_W, isUnicode);
|
---|
256 | }
|
---|
257 | while(rc == FALSE);
|
---|
258 |
|
---|
259 | return (pMsg->message != WINWM_QUIT);
|
---|
260 | }
|
---|
261 | else
|
---|
262 | {
|
---|
263 | filtermin = TranslateWinMsg(uMsgFilterMin, TRUE);
|
---|
264 | filtermax = TranslateWinMsg(uMsgFilterMax, FALSE);
|
---|
265 | if(filtermin > filtermax) {
|
---|
266 | ULONG tmp = filtermin;
|
---|
267 | filtermin = filtermax;
|
---|
268 | filtermax = filtermin;
|
---|
269 | }
|
---|
270 | do {
|
---|
271 | eaten = FALSE;
|
---|
272 | rc = WinGetMsg(teb->o.odin.hab, &os2msg, 0, filtermin, filtermax);
|
---|
273 | if (os2msg.msg == WM_TIMER)
|
---|
274 | eaten = TIMER_HandleTimer(&os2msg);
|
---|
275 | } while (eaten);
|
---|
276 | }
|
---|
277 | if(OS2ToWinMsgTranslate((PVOID)teb, &os2msg, pMsg, isUnicode, MSG_REMOVE) == FALSE) {
|
---|
278 | //dispatch untranslated message immediately
|
---|
279 | WinDispatchMsg(teb->o.odin.hab, &os2msg);
|
---|
280 | //and get the next one
|
---|
281 | return OSLibWinGetMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, isUnicode);
|
---|
282 | }
|
---|
283 |
|
---|
284 | memcpy(&teb->o.odin.os2msg, &os2msg, sizeof(QMSG));
|
---|
285 | memcpy(&teb->o.odin.winmsg, pMsg, sizeof(MSG));
|
---|
286 |
|
---|
287 | if(pMsg->message <= WINWM_KEYLAST && pMsg->message >= WINWM_KEYDOWN)
|
---|
288 | {
|
---|
289 | if(ProcessKbdHook(pMsg, TRUE))
|
---|
290 | goto continuegetmsg;
|
---|
291 | }
|
---|
292 | return rc;
|
---|
293 | }
|
---|
294 | //******************************************************************************
|
---|
295 | //PeekMessage retrieves only messages associated with the window identified by the
|
---|
296 | //hwnd parameter or any of its children as specified by the IsChild function, and within
|
---|
297 | //the range of message values given by the uMsgFilterMin and uMsgFilterMax
|
---|
298 | //parameters. If hwnd is NULL, PeekMessage retrieves messages for any window that
|
---|
299 | //belongs to the current thread making the call. (PeekMessage does not retrieve
|
---|
300 | //messages for windows that belong to other threads.) If hwnd is -1, PeekMessage only
|
---|
301 | //returns messages with a hwnd value of NULL, as posted by the PostAppMessage
|
---|
302 | //function. If uMsgFilterMin and uMsgFilterMax are both zero, PeekMessage returns all
|
---|
303 | //available messages (no range filtering is performed).
|
---|
304 | //TODO: Not working as specified right now!
|
---|
305 | //******************************************************************************
|
---|
306 | BOOL OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
|
---|
307 | DWORD fRemove, BOOL isUnicode)
|
---|
308 | {
|
---|
309 | BOOL rc, eaten;
|
---|
310 | TEB *teb;
|
---|
311 | QMSG os2msg;
|
---|
312 | HWND hwndOS2 = 0;
|
---|
313 |
|
---|
314 | if(hwnd && hwnd != -1) {
|
---|
315 | hwndOS2 = Win32ToOS2Handle(hwnd);
|
---|
316 | if(hwndOS2 == NULL) {
|
---|
317 | dprintf(("PeekMsg: window %x NOT FOUND!", hwnd));
|
---|
318 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
319 | return FALSE;
|
---|
320 | }
|
---|
321 | }
|
---|
322 |
|
---|
323 | teb = GetThreadTEB();
|
---|
324 | if(teb == NULL) {
|
---|
325 | DebugInt3();
|
---|
326 | return FALSE;
|
---|
327 | }
|
---|
328 |
|
---|
329 | if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd)) {
|
---|
330 | if(uMsgFilterMin) {
|
---|
331 | if(teb->o.odin.msgWCHAR.message < uMsgFilterMin)
|
---|
332 | goto continuepeekmsg;
|
---|
333 | }
|
---|
334 | if(uMsgFilterMax) {
|
---|
335 | if(teb->o.odin.msgWCHAR.message > uMsgFilterMax)
|
---|
336 | goto continuepeekmsg;
|
---|
337 | }
|
---|
338 |
|
---|
339 | if(fRemove & PM_REMOVE_W) {
|
---|
340 | teb->o.odin.fTranslated = FALSE;
|
---|
341 | teb->o.odin.os2msg.msg = 0;
|
---|
342 | teb->o.odin.os2msg.hwnd = 0;
|
---|
343 | }
|
---|
344 | memcpy(pMsg, &teb->o.odin.msgWCHAR, sizeof(MSG));
|
---|
345 | return TRUE;
|
---|
346 | }
|
---|
347 |
|
---|
348 | continuepeekmsg:
|
---|
349 | do {
|
---|
350 | eaten = FALSE;
|
---|
351 | rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, TranslateWinMsg(uMsgFilterMin, TRUE),
|
---|
352 | TranslateWinMsg(uMsgFilterMax, FALSE), (fRemove & PM_REMOVE_W) ? PM_REMOVE : PM_NOREMOVE);
|
---|
353 |
|
---|
354 | if (rc && (fRemove & PM_REMOVE_W) && os2msg.msg == WM_TIMER) {
|
---|
355 | eaten = TIMER_HandleTimer(&os2msg);
|
---|
356 | }
|
---|
357 | }
|
---|
358 | while (eaten && rc);
|
---|
359 |
|
---|
360 | if(rc == FALSE) {
|
---|
361 | return FALSE;
|
---|
362 | }
|
---|
363 |
|
---|
364 | if(OS2ToWinMsgTranslate((PVOID)teb, &os2msg, pMsg, isUnicode, (fRemove & PM_REMOVE_W) ? MSG_REMOVE : MSG_NOREMOVE) == FALSE)
|
---|
365 | {
|
---|
366 | //unused PM message; dispatch immediately and grab next one
|
---|
367 | dprintf2(("OSLibWinPeekMsg: Untranslated message; dispatched immediately"));
|
---|
368 | if(!(fRemove & PM_REMOVE_W)) {
|
---|
369 | rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, TranslateWinMsg(uMsgFilterMin, TRUE),
|
---|
370 | TranslateWinMsg(uMsgFilterMax, FALSE), PM_REMOVE);
|
---|
371 | }
|
---|
372 | WinDispatchMsg(teb->o.odin.hab, &os2msg);
|
---|
373 | return OSLibWinPeekMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax,
|
---|
374 | fRemove, isUnicode);
|
---|
375 | }
|
---|
376 | //TODO: This is not safe! There's no guarantee this message will be dispatched and it might overwrite a previous message
|
---|
377 | if(fRemove & PM_REMOVE_W) {
|
---|
378 | memcpy(&teb->o.odin.os2msg, &os2msg, sizeof(QMSG));
|
---|
379 | memcpy(&teb->o.odin.winmsg, pMsg, sizeof(MSG));
|
---|
380 | }
|
---|
381 |
|
---|
382 | if(pMsg->message <= WINWM_KEYLAST && pMsg->message >= WINWM_KEYDOWN)
|
---|
383 | {
|
---|
384 | if(ProcessKbdHook(pMsg, fRemove))
|
---|
385 | goto continuepeekmsg;
|
---|
386 | }
|
---|
387 |
|
---|
388 | return rc;
|
---|
389 | }
|
---|
390 | //******************************************************************************
|
---|
391 | //******************************************************************************
|
---|
392 | ULONG OSLibWinQueryMsgTime()
|
---|
393 | {
|
---|
394 | return WinQueryMsgTime(GetThreadHAB());
|
---|
395 | }
|
---|
396 | //******************************************************************************
|
---|
397 | //******************************************************************************
|
---|
398 | BOOL OSLibWinWaitMessage()
|
---|
399 | {
|
---|
400 | return WinWaitMsg(GetThreadHAB(), 0, 0);
|
---|
401 | }
|
---|
402 | //******************************************************************************
|
---|
403 | //TODO: QS_HOTKEY
|
---|
404 | //******************************************************************************
|
---|
405 | ULONG OSLibWinQueryQueueStatus()
|
---|
406 | {
|
---|
407 | ULONG statusOS2, statusWin32 = 0;
|
---|
408 |
|
---|
409 | statusOS2 = WinQueryQueueStatus(HWND_DESKTOP);
|
---|
410 |
|
---|
411 | if(statusOS2 & QS_KEY)
|
---|
412 | statusWin32 |= QS_KEY_W;
|
---|
413 | if(statusOS2 & QS_MOUSEBUTTON)
|
---|
414 | statusWin32 |= QS_MOUSEBUTTON_W;
|
---|
415 | if(statusOS2 & QS_MOUSEMOVE)
|
---|
416 | statusWin32 |= QS_MOUSEMOVE_W;
|
---|
417 | if(statusOS2 & QS_TIMER)
|
---|
418 | statusWin32 |= QS_TIMER_W;
|
---|
419 | if(statusOS2 & QS_PAINT)
|
---|
420 | statusWin32 |= QS_PAINT_W;
|
---|
421 | if(statusOS2 & QS_POSTMSG)
|
---|
422 | statusWin32 |= QS_POSTMESSAGE_W;
|
---|
423 | if(statusOS2 & QS_SENDMSG)
|
---|
424 | statusWin32 |= QS_SENDMESSAGE_W;
|
---|
425 |
|
---|
426 | return statusWin32;
|
---|
427 | }
|
---|
428 | //******************************************************************************
|
---|
429 | //******************************************************************************
|
---|
430 | BOOL OSLibWinInSendMessage()
|
---|
431 | {
|
---|
432 | return WinInSendMsg(GetThreadHAB());
|
---|
433 | }
|
---|
434 | //******************************************************************************
|
---|
435 | //******************************************************************************
|
---|
436 | DWORD OSLibWinGetMessagePos()
|
---|
437 | {
|
---|
438 | APIRET rc;
|
---|
439 | POINTL ptl;
|
---|
440 |
|
---|
441 | rc = WinQueryMsgPos(GetThreadHAB(), &ptl);
|
---|
442 | if(!rc) {
|
---|
443 | return 0;
|
---|
444 | }
|
---|
445 | //convert to windows coordinates
|
---|
446 | return MAKEULONG(ptl.x,mapScreenY(ptl.y));
|
---|
447 | }
|
---|
448 | //******************************************************************************
|
---|
449 | //******************************************************************************
|
---|
450 | LONG OSLibWinGetMessageTime()
|
---|
451 | {
|
---|
452 | return (LONG)WinQueryMsgTime(GetThreadHAB());
|
---|
453 | }
|
---|
454 | //******************************************************************************
|
---|
455 | //******************************************************************************
|
---|
456 | BOOL OSLibWinReplyMessage(ULONG result)
|
---|
457 | {
|
---|
458 | return (BOOL)WinReplyMsg( NULLHANDLE, NULLHANDLE, HMQ_CURRENT, (MRESULT)result);
|
---|
459 | }
|
---|
460 | //******************************************************************************
|
---|
461 | //******************************************************************************
|
---|
462 | ULONG OSLibSendMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode)
|
---|
463 | {
|
---|
464 | POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
|
---|
465 |
|
---|
466 | if(NULL == packet)
|
---|
467 | {
|
---|
468 | dprintf(("user32::oslibmsg::OSLibSendMessage - allocated packet structure is NULL, heapmin=%d\n",
|
---|
469 | _sheapmin() ));
|
---|
470 |
|
---|
471 | // PH: we cannot provide a correct returncode :(
|
---|
472 | DebugInt3();
|
---|
473 | return 0;
|
---|
474 | }
|
---|
475 |
|
---|
476 | packet->wParam = wParam;
|
---|
477 | packet->lParam = lParam;
|
---|
478 |
|
---|
479 | return (ULONG)WinSendMsg(hwnd, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet);
|
---|
480 | }
|
---|
481 | //******************************************************************************
|
---|
482 | //******************************************************************************
|
---|
483 | ULONG OSLibWinBroadcastMsg(ULONG msg, ULONG wParam, ULONG lParam, BOOL fSend)
|
---|
484 | {
|
---|
485 | return WinBroadcastMsg(HWND_DESKTOP, WIN32APP_POSTMSG+msg, (MPARAM)wParam, (MPARAM)lParam,
|
---|
486 | (fSend) ? BMSG_SEND : BMSG_POST);
|
---|
487 | }
|
---|
488 | //******************************************************************************
|
---|
489 | //******************************************************************************
|
---|
490 | BOOL OSLibPostMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode)
|
---|
491 | {
|
---|
492 | POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
|
---|
493 |
|
---|
494 | if (NULL == packet)
|
---|
495 | {
|
---|
496 | dprintf(("user32::oslibmsg::OSLibPostMessage - allocated packet structure is NULL, heapmin=%d\n",
|
---|
497 | _sheapmin() ));
|
---|
498 |
|
---|
499 | // PH: we can provide a correct returncode
|
---|
500 | DebugInt3();
|
---|
501 | return FALSE;
|
---|
502 | }
|
---|
503 | packet->wParam = wParam;
|
---|
504 | packet->lParam = lParam;
|
---|
505 | return WinPostMsg(hwnd, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet);
|
---|
506 | }
|
---|
507 | //******************************************************************************
|
---|
508 | //Direct posting of messages that must remain invisible to the win32 app
|
---|
509 | //******************************************************************************
|
---|
510 | BOOL OSLibPostMessageDirect(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
|
---|
511 | {
|
---|
512 | return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
|
---|
513 | }
|
---|
514 | //******************************************************************************
|
---|
515 | BOOL _System _O32_PostThreadMessage( DWORD, UINT, WPARAM, LPARAM );
|
---|
516 |
|
---|
517 | inline BOOL O32_PostThreadMessage(DWORD a, UINT b, WPARAM c, LPARAM d)
|
---|
518 | {
|
---|
519 | BOOL yyrc;
|
---|
520 | USHORT sel = RestoreOS2FS();
|
---|
521 |
|
---|
522 | yyrc = _O32_PostThreadMessage(a, b, c, d);
|
---|
523 | SetFS(sel);
|
---|
524 |
|
---|
525 | return yyrc;
|
---|
526 | }
|
---|
527 | //******************************************************************************
|
---|
528 | BOOL OSLibPostThreadMessage(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
|
---|
529 | {
|
---|
530 | TEB *teb = GetTEBFromThreadId(threadid);
|
---|
531 | POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
|
---|
532 | BOOL ret;
|
---|
533 |
|
---|
534 | if(NULL == packet)
|
---|
535 | {
|
---|
536 | dprintf(("user32::oslibmsg::OSLibPostMessage - allocated packet structure is NULL, heapmin=%d\n",
|
---|
537 | _sheapmin() ));
|
---|
538 |
|
---|
539 | DebugInt3();
|
---|
540 | // PH: we can provide a correct returncode
|
---|
541 | return FALSE;
|
---|
542 | }
|
---|
543 |
|
---|
544 | if(teb == NULL) {
|
---|
545 | dprintf(("OSLibPostThreadMessage: thread %x not found!", threadid));
|
---|
546 | return FALSE;
|
---|
547 | }
|
---|
548 | dprintf(("PostThreadMessageA %x %x %x %x -> hmq %x", threadid, msg, wParam, lParam, teb->o.odin.hmq));
|
---|
549 | packet->wParam = wParam;
|
---|
550 | packet->lParam = lParam;
|
---|
551 |
|
---|
552 | ret = WinPostQueueMsg((HMQ)teb->o.odin.hmq, WIN32APP_POSTMSG+msg,
|
---|
553 | (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA),
|
---|
554 | (MPARAM)packet);
|
---|
555 |
|
---|
556 | if(ret == FALSE)
|
---|
557 | {
|
---|
558 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
559 | return FALSE;
|
---|
560 | }
|
---|
561 | SetLastError(ERROR_SUCCESS_W);
|
---|
562 | return TRUE;
|
---|
563 | }
|
---|
564 | //******************************************************************************
|
---|
565 | //******************************************************************************
|
---|
566 |
|
---|