[10240] | 1 | /* $Id: oslibmsg.cpp,v 1.76 2003-08-22 13:16:44 sandervl Exp $ */
|
---|
[2469] | 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
|
---|
[9598] | 16 | * a PM version)
|
---|
[2469] | 17 | *
|
---|
[9598] | 18 | * TODO: Flaw in our message handling; we don't handle posted/sent (by the app)
|
---|
| 19 | * system messages properly if removed from the queue with PeekMessage.
|
---|
| 20 | * e.g.
|
---|
| 21 | * PostMessage(WM_KEYDOWN)
|
---|
| 22 | * PeekMessage(any, PM_NOREMOVE)
|
---|
| 23 | * ...
|
---|
| 24 | * PeekMessage(WM_KEYDOWN, WM_KEYDOWN, PM_REMOVE)
|
---|
| 25 | *
|
---|
| 26 | * So what we really need is a complete win to os2 message translation
|
---|
| 27 | * in Post/SendMessage. Quite a lot of work though...
|
---|
| 28 | *
|
---|
[2469] | 29 | */
|
---|
| 30 | #define INCL_WIN
|
---|
| 31 | #define INCL_PM
|
---|
| 32 | #define INCL_DOSPROCESS
|
---|
[9928] | 33 | #define INCL_WINMESSAGEMGR
|
---|
| 34 | #define INCL_DOSSEMAPHORES
|
---|
| 35 | #define INCL_DOSERRORS
|
---|
[2469] | 36 | #include <os2wrap.h>
|
---|
[7211] | 37 | #include <odinwrap.h>
|
---|
[2469] | 38 | #include <string.h>
|
---|
| 39 | #include <misc.h>
|
---|
| 40 | #include "oslibmsg.h"
|
---|
[3101] | 41 | #include <winconst.h>
|
---|
[3274] | 42 | #include <win32api.h>
|
---|
[4848] | 43 | #include <winuser32.h>
|
---|
[2469] | 44 | #include "oslibutil.h"
|
---|
| 45 | #include "timer.h"
|
---|
| 46 | #include <thread.h>
|
---|
| 47 | #include <wprocess.h>
|
---|
[10212] | 48 | #include <winnls.h>
|
---|
[2469] | 49 | #include "pmwindow.h"
|
---|
| 50 | #include "oslibwin.h"
|
---|
[21916] | 51 | #include <win/hook.h>
|
---|
[7370] | 52 | #include <winscan.h>
|
---|
| 53 | #include <winkeyboard.h>
|
---|
[9791] | 54 | #include "user32api.h"
|
---|
[2469] | 55 |
|
---|
[10012] | 56 | #define DBG_LOCALLOG DBG_oslibmsg
|
---|
[2804] | 57 | #include "dbglocal.h"
|
---|
| 58 |
|
---|
[6614] | 59 |
|
---|
[7211] | 60 | ODINDEBUGCHANNEL(USER32-OSLIBMSG)
|
---|
[6614] | 61 |
|
---|
[7211] | 62 |
|
---|
| 63 |
|
---|
[2469] | 64 | typedef BOOL (EXPENTRY FNTRANS)(MSG *, QMSG *);
|
---|
| 65 | typedef FNTRANS *PFNTRANS;
|
---|
| 66 |
|
---|
| 67 | typedef struct
|
---|
| 68 | {
|
---|
| 69 | ULONG msgOS2;
|
---|
| 70 | ULONG msgWin32;
|
---|
| 71 | // PFNTRANS toOS2;
|
---|
| 72 | // PFNTRANS toWIN32;
|
---|
| 73 | } MSGTRANSTAB, *PMSGTRANSTAB;
|
---|
| 74 |
|
---|
| 75 | //NOTE: Must be ordered by win32 message id!!
|
---|
| 76 | MSGTRANSTAB MsgTransTab[] = {
|
---|
| 77 | WM_NULL, WINWM_NULL,
|
---|
| 78 | WM_CREATE, WINWM_CREATE,
|
---|
| 79 | WM_DESTROY, WINWM_DESTROY,
|
---|
| 80 | WM_MOVE, WINWM_MOVE, //TODO: Sent directly
|
---|
| 81 | WM_SIZE, WINWM_SIZE, //TODO: Sent directly
|
---|
| 82 | WM_ACTIVATE, WINWM_ACTIVATE,
|
---|
| 83 | WM_SETFOCUS, WINWM_SETFOCUS,
|
---|
| 84 | WM_SETFOCUS, WINWM_KILLFOCUS,
|
---|
| 85 | WM_ENABLE, WINWM_ENABLE,
|
---|
| 86 | WM_PAINT, WINWM_PAINT,
|
---|
| 87 | WM_CLOSE, WINWM_CLOSE,
|
---|
| 88 | WM_QUIT, WINWM_QUIT,
|
---|
| 89 | WM_SHOW, WINWM_SHOWWINDOW,
|
---|
| 90 |
|
---|
| 91 | WM_HITTEST, WINWM_NCHITTEST,
|
---|
| 92 |
|
---|
[5606] | 93 | //todo: not always right if mouse msg turns out to be for the client window
|
---|
| 94 | WM_MOUSEMOVE, WINWM_NCMOUSEMOVE,
|
---|
| 95 | WM_BUTTON1DOWN, WINWM_NCLBUTTONDOWN,
|
---|
| 96 | WM_BUTTON1UP, WINWM_NCLBUTTONUP,
|
---|
| 97 | WM_BUTTON1DBLCLK, WINWM_NCLBUTTONDBLCLK,
|
---|
| 98 | WM_BUTTON2DOWN, WINWM_NCRBUTTONDOWN,
|
---|
| 99 | WM_BUTTON2UP, WINWM_NCRBUTTONUP,
|
---|
| 100 | WM_BUTTON2DBLCLK, WINWM_NCRBUTTONDBLCLK,
|
---|
| 101 | WM_BUTTON3DOWN, WINWM_NCMBUTTONDOWN,
|
---|
| 102 | WM_BUTTON3UP, WINWM_NCMBUTTONUP,
|
---|
| 103 | WM_BUTTON3DBLCLK, WINWM_NCMBUTTONDBLCLK,
|
---|
| 104 |
|
---|
[2469] | 105 | //TODO: Needs better translation!
|
---|
[6941] | 106 | WM_CHAR, WINWM_KEYDOWN, //WM_KEYFIRST
|
---|
[2469] | 107 | WM_CHAR, WINWM_KEYUP,
|
---|
| 108 | WM_CHAR, WINWM_CHAR,
|
---|
| 109 | WM_CHAR, WINWM_DEADCHAR,
|
---|
| 110 | WM_CHAR, WINWM_SYSKEYDOWN,
|
---|
| 111 | WM_CHAR, WINWM_SYSKEYUP,
|
---|
| 112 | WM_CHAR, WINWM_SYSCHAR,
|
---|
| 113 | WM_CHAR, WINWM_SYSDEADCHAR,
|
---|
| 114 | WM_CHAR, WINWM_KEYLAST,
|
---|
| 115 |
|
---|
| 116 | //
|
---|
| 117 | WM_TIMER, WINWM_TIMER,
|
---|
[4658] | 118 |
|
---|
[2469] | 119 | //
|
---|
[5606] | 120 | //todo: not always right if mouse msg turns out to be for the nonclient window
|
---|
[6941] | 121 | WM_MOUSEMOVE, WINWM_MOUSEMOVE, //WM_MOUSEFIRST
|
---|
[2469] | 122 | WM_BUTTON1DOWN, WINWM_LBUTTONDOWN,
|
---|
| 123 | WM_BUTTON1UP, WINWM_LBUTTONUP,
|
---|
| 124 | WM_BUTTON1DBLCLK, WINWM_LBUTTONDBLCLK,
|
---|
| 125 | WM_BUTTON2DOWN, WINWM_RBUTTONDOWN,
|
---|
| 126 | WM_BUTTON2UP, WINWM_RBUTTONUP,
|
---|
| 127 | WM_BUTTON2DBLCLK, WINWM_RBUTTONDBLCLK,
|
---|
| 128 | WM_BUTTON3DOWN, WINWM_MBUTTONDOWN,
|
---|
| 129 | WM_BUTTON3UP, WINWM_MBUTTONUP,
|
---|
| 130 | WM_BUTTON3DBLCLK, WINWM_MBUTTONDBLCLK,
|
---|
[21502] | 131 | WM_VSCROLL, WINWM_MOUSEWHEEL, //WM_MOUSELAST
|
---|
[2469] | 132 | 999999999, 999999999,
|
---|
| 133 | };
|
---|
| 134 | #define MAX_MSGTRANSTAB (sizeof(MsgTransTab)/sizeof(MsgTransTab[0]))
|
---|
| 135 |
|
---|
| 136 | //******************************************************************************
|
---|
| 137 | //******************************************************************************
|
---|
| 138 | void WinToOS2MsgTranslate(MSG *winMsg, QMSG *os2Msg, BOOL isUnicode)
|
---|
| 139 | {
|
---|
[7211] | 140 | dprintf(("WinToOS2MsgTranslate not implemented"));
|
---|
[2469] | 141 | // memcpy(os2Msg, winMsg, sizeof(MSG));
|
---|
[4848] | 142 | // os2Msg->hwnd = Win32ToOS2Handle(winMsg->hwnd);
|
---|
[2469] | 143 | // os2Msg->reserved = 0;
|
---|
| 144 | }
|
---|
| 145 | //******************************************************************************
|
---|
| 146 | //TODO: NOT COMPLETE nor 100% CORRECT!!!
|
---|
| 147 | //If both the minimum & maximum message are unknown, the result can be wrong (max > min)!
|
---|
| 148 | //******************************************************************************
|
---|
[8689] | 149 | ULONG TranslateWinMsg(ULONG msg, BOOL fMinFilter, BOOL fExactMatch = FALSE)
|
---|
[2469] | 150 | {
|
---|
| 151 | if(msg == 0)
|
---|
| 152 | return 0;
|
---|
| 153 |
|
---|
| 154 | if(msg >= WINWM_USER)
|
---|
[5805] | 155 | return msg + WIN32APP_POSTMSG;
|
---|
[2469] | 156 |
|
---|
| 157 | for(int i=0;i<MAX_MSGTRANSTAB;i++)
|
---|
| 158 | {
|
---|
[8689] | 159 | if(fExactMatch) {
|
---|
[2469] | 160 | if(MsgTransTab[i].msgWin32 == msg)
|
---|
[9354] | 161 | return MsgTransTab[i].msgOS2;
|
---|
[2469] | 162 | }
|
---|
[8689] | 163 | else {
|
---|
| 164 | if(fMinFilter && MsgTransTab[i].msgWin32 >= msg) {
|
---|
| 165 | return MsgTransTab[i].msgOS2;
|
---|
| 166 | }
|
---|
| 167 | else
|
---|
| 168 | if(!fMinFilter && MsgTransTab[i].msgWin32 >= msg) {
|
---|
| 169 | if(MsgTransTab[i].msgWin32 == msg)
|
---|
| 170 | return MsgTransTab[i].msgOS2;
|
---|
| 171 | else return MsgTransTab[i-1].msgOS2;
|
---|
| 172 | }
|
---|
| 173 | }
|
---|
[2469] | 174 | }
|
---|
| 175 |
|
---|
[5805] | 176 | //not found, get everything
|
---|
[8689] | 177 | dprintf2(("WARNING: TranslateWinMsg: message %x not found", msg));
|
---|
[5805] | 178 | return 0;
|
---|
[2469] | 179 | }
|
---|
| 180 | //******************************************************************************
|
---|
| 181 | //******************************************************************************
|
---|
| 182 | void OSLibWinPostQuitMessage(ULONG nExitCode)
|
---|
| 183 | {
|
---|
| 184 | APIRET rc;
|
---|
| 185 |
|
---|
[8130] | 186 | //NOTE: mp2 must always be zero or else we won't be able to distinguish
|
---|
| 187 | // between the WM_QUIT sent by us and the one sent by the window list!!
|
---|
[2469] | 188 | rc = WinPostQueueMsg(NULLHANDLE, WM_QUIT, MPFROMLONG(nExitCode), 0);
|
---|
| 189 | dprintf(("WinPostQueueMsg %d returned %d", nExitCode, rc));
|
---|
| 190 | }
|
---|
| 191 | //******************************************************************************
|
---|
| 192 | //******************************************************************************
|
---|
| 193 | LONG OSLibWinDispatchMsg(MSG *msg, BOOL isUnicode)
|
---|
| 194 | {
|
---|
[4658] | 195 | TEB *teb;
|
---|
[2469] | 196 | QMSG os2msg;
|
---|
| 197 | LONG rc;
|
---|
| 198 |
|
---|
[4658] | 199 | teb = GetThreadTEB();
|
---|
| 200 | if(teb == NULL) {
|
---|
[2469] | 201 | DebugInt3();
|
---|
| 202 | return FALSE;
|
---|
| 203 | }
|
---|
| 204 |
|
---|
| 205 | //TODO: What to do if app changed msg? (translate)
|
---|
| 206 | // WinToOS2MsgTranslate(msg, &qmsg, isUnicode);
|
---|
| 207 |
|
---|
[4658] | 208 | if(!memcmp(msg, &teb->o.odin.winmsg, sizeof(MSG)) || msg->hwnd == 0) {
|
---|
| 209 | memcpy(&os2msg, &teb->o.odin.os2msg, sizeof(QMSG));
|
---|
| 210 | teb->o.odin.os2msg.time = -1;
|
---|
| 211 | teb->o.odin.winmsg.time = -1;
|
---|
[2469] | 212 | if(msg->hwnd) {
|
---|
[10012] | 213 | teb->o.odin.nrOfMsgs = 1;
|
---|
| 214 | teb->o.odin.msgstate++; //odd -> next call to our PM window handler should dispatch the translated msg
|
---|
| 215 | memcpy(&teb->o.odin.msg, msg, sizeof(MSG));
|
---|
[2469] | 216 | }
|
---|
| 217 | if(os2msg.hwnd || os2msg.msg == WM_QUIT) {
|
---|
[10012] | 218 | memset(&teb->o.odin.os2msg, 0, sizeof(teb->o.odin.os2msg));
|
---|
| 219 | memset(&teb->o.odin.winmsg, 0, sizeof(teb->o.odin.winmsg));
|
---|
| 220 | return (LONG)WinDispatchMsg(teb->o.odin.hab, &os2msg);
|
---|
[2469] | 221 | }
|
---|
| 222 | //SvL: Don't dispatch messages sent by PostThreadMessage (correct??)
|
---|
| 223 | // Or WM_TIMER msgs with no window handle or timer proc
|
---|
| 224 | return 0;
|
---|
| 225 |
|
---|
| 226 | }
|
---|
| 227 | else {//is this allowed?
|
---|
| 228 | // dprintf(("WARNING: OSLibWinDispatchMsg: called with own message!"));
|
---|
[10190] | 229 | return isUnicode ? SendMessageW(msg->hwnd, msg->message, msg->wParam, msg->lParam) :
|
---|
| 230 | SendMessageA(msg->hwnd, msg->message, msg->wParam, msg->lParam);
|
---|
[2469] | 231 | }
|
---|
| 232 | }
|
---|
| 233 | //******************************************************************************
|
---|
[10212] | 234 | // ReturnQueuedWMCHAR:
|
---|
| 235 | //
|
---|
| 236 | // Check for a queued WM_CHAR message (e.g. inserted by TranslateMessage)
|
---|
[2469] | 237 | //******************************************************************************
|
---|
[10216] | 238 | BOOL ReturnQueuedWMCHAR(LPMSG pMsg, TEB *teb, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
|
---|
[10212] | 239 | BOOL isUnicode, BOOL fRemove)
|
---|
[2469] | 240 | {
|
---|
[10012] | 241 | if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd))
|
---|
[8689] | 242 | {
|
---|
[7612] | 243 | dprintf(("Return queued WM_CHAR message hwnd=%x msg=%d wParam=%x lParam=%x", teb->o.odin.msgWCHAR.hwnd, teb->o.odin.msgWCHAR.message, teb->o.odin.msgWCHAR.wParam, teb->o.odin.msgWCHAR.lParam));
|
---|
[10212] | 244 |
|
---|
[2469] | 245 | if(uMsgFilterMin) {
|
---|
[4658] | 246 | if(teb->o.odin.msgWCHAR.message < uMsgFilterMin)
|
---|
[10212] | 247 | return FALSE;
|
---|
[2469] | 248 | }
|
---|
| 249 | if(uMsgFilterMax) {
|
---|
[4658] | 250 | if(teb->o.odin.msgWCHAR.message > uMsgFilterMax)
|
---|
[10212] | 251 | return FALSE;
|
---|
[2469] | 252 | }
|
---|
[10216] | 253 |
|
---|
[10212] | 254 | if(fRemove & PM_REMOVE_W) {
|
---|
| 255 | teb->o.odin.fTranslated = FALSE;
|
---|
| 256 | teb->o.odin.os2msg.msg = 0;
|
---|
| 257 | teb->o.odin.os2msg.hwnd = 0;
|
---|
| 258 | }
|
---|
[4658] | 259 | memcpy(pMsg, &teb->o.odin.msgWCHAR, sizeof(MSG));
|
---|
[9791] | 260 | //After SetFocus(0), all keystrokes are converted in WM_SYS*
|
---|
| 261 | if(pMsg->message == WINWM_CHAR && fIgnoreKeystrokes) {
|
---|
| 262 | pMsg->message = WINWM_SYSCHAR;
|
---|
| 263 | }
|
---|
| 264 |
|
---|
[9027] | 265 | if(!IsWindow(pMsg->hwnd)) {
|
---|
| 266 | //could be a queued char message for a window that was just destroyed
|
---|
| 267 | //when that's the case, we ignore it (MFC assertions are triggered by this)
|
---|
[10212] | 268 | teb->o.odin.fTranslated = FALSE;
|
---|
| 269 | teb->o.odin.os2msg.msg = 0;
|
---|
| 270 | teb->o.odin.os2msg.hwnd = 0;
|
---|
| 271 | return FALSE;
|
---|
[9027] | 272 | }
|
---|
| 273 |
|
---|
[7211] | 274 | // @@@PH verify this
|
---|
| 275 | // if this is a keyup or keydown message, we've got to
|
---|
| 276 | // call the keyboard hook here
|
---|
[7212] | 277 | // send keyboard messages to the registered hooks
|
---|
[10216] | 278 | if(fRemove & PM_REMOVE_W)
|
---|
[7211] | 279 | {
|
---|
[10212] | 280 | switch (pMsg->message)
|
---|
| 281 | {
|
---|
| 282 | case WINWM_KEYDOWN:
|
---|
| 283 | case WINWM_KEYUP:
|
---|
| 284 | case WINWM_SYSKEYDOWN:
|
---|
| 285 | case WINWM_SYSKEYUP:
|
---|
| 286 | // only supposed to be called upon WM_KEYDOWN
|
---|
| 287 | // and WM_KEYUP according to docs.
|
---|
| 288 | if(ProcessKbdHook(pMsg, fRemove))
|
---|
| 289 | return FALSE;
|
---|
| 290 | break;
|
---|
| 291 | }
|
---|
[7211] | 292 | }
|
---|
[10216] | 293 |
|
---|
[10212] | 294 | //GetMessageW and PeekMessageW expect the character code in UTF-16
|
---|
| 295 | //(we save it in ascii format)
|
---|
| 296 | if(isUnicode && (pMsg->message == WINWM_CHAR || pMsg->message == WINWM_SYSCHAR))
|
---|
| 297 | {
|
---|
| 298 | CHAR charA;
|
---|
| 299 | WCHAR charW;
|
---|
[10216] | 300 |
|
---|
[10212] | 301 | charA = pMsg->wParam;
|
---|
| 302 | MultiByteToWideChar(CP_ACP, 0, &charA, 1, &charW, 1);
|
---|
| 303 | pMsg->wParam= charW;
|
---|
| 304 | dprintf(("ReturnQueuedWMCHAR: Convert to Unicode src=%x res=%x", charA, charW));
|
---|
| 305 | }
|
---|
| 306 | return TRUE;
|
---|
| 307 | }
|
---|
| 308 | return FALSE;
|
---|
| 309 | }
|
---|
| 310 | //******************************************************************************
|
---|
| 311 | //******************************************************************************
|
---|
| 312 | BOOL OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
|
---|
| 313 | BOOL isUnicode)
|
---|
| 314 | {
|
---|
| 315 | BOOL rc, eaten;
|
---|
| 316 | TEB *teb;
|
---|
| 317 | QMSG os2msg;
|
---|
| 318 | HWND hwndOS2 = 0;
|
---|
| 319 | ULONG filtermin, filtermax;
|
---|
[7612] | 320 |
|
---|
[10212] | 321 | if(hwnd) {
|
---|
| 322 | hwndOS2 = Win32ToOS2Handle(hwnd);
|
---|
| 323 | if(hwndOS2 == NULL) {
|
---|
| 324 | memset(pMsg, 0, sizeof(MSG));
|
---|
| 325 | dprintf(("GetMsg: window %x NOT FOUND!", hwnd));
|
---|
| 326 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
| 327 | return TRUE;
|
---|
| 328 | }
|
---|
| 329 | }
|
---|
| 330 |
|
---|
| 331 | teb = GetThreadTEB();
|
---|
| 332 | if(teb == NULL) {
|
---|
| 333 | DebugInt3();
|
---|
| 334 | return TRUE;
|
---|
| 335 | }
|
---|
| 336 |
|
---|
| 337 | //check for a queued WM_CHAR message (e.g. inserted by TranslateMessage)
|
---|
| 338 | if(ReturnQueuedWMCHAR(pMsg, teb, hwnd, uMsgFilterMin, uMsgFilterMax, isUnicode, PM_REMOVE_W) == TRUE)
|
---|
| 339 | {
|
---|
[2469] | 340 | return (pMsg->message != WINWM_QUIT);
|
---|
[8689] | 341 | }
|
---|
[2469] | 342 |
|
---|
| 343 | continuegetmsg:
|
---|
[8689] | 344 | if(hwnd) {
|
---|
[10012] | 345 | filtermin = TranslateWinMsg(uMsgFilterMin, TRUE);
|
---|
[10122] | 346 | filtermax = TranslateWinMsg(uMsgFilterMax, FALSE);
|
---|
| 347 | if(filtermin > filtermax) {
|
---|
| 348 | ULONG tmp = filtermin;
|
---|
| 349 | filtermin = filtermax;
|
---|
[21527] | 350 | filtermax = tmp;
|
---|
[10122] | 351 | }
|
---|
[2469] | 352 | do {
|
---|
[10122] | 353 | WinWaitMsg(teb->o.odin.hab, filtermin, filtermax);
|
---|
| 354 | rc = OSLibWinPeekMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, PM_REMOVE_W, isUnicode);
|
---|
[2469] | 355 | }
|
---|
| 356 | while(rc == FALSE);
|
---|
| 357 |
|
---|
| 358 | return (pMsg->message != WINWM_QUIT);
|
---|
[8689] | 359 | }
|
---|
| 360 | else
|
---|
| 361 | {
|
---|
[10012] | 362 | filtermin = TranslateWinMsg(uMsgFilterMin, TRUE);
|
---|
[10104] | 363 | filtermax = TranslateWinMsg(uMsgFilterMax, FALSE);
|
---|
| 364 | if(filtermin > filtermax) {
|
---|
| 365 | ULONG tmp = filtermin;
|
---|
| 366 | filtermin = filtermax;
|
---|
| 367 | filtermax = filtermin;
|
---|
| 368 | }
|
---|
| 369 | rc = WinGetMsg(teb->o.odin.hab, &os2msg, 0, filtermin, filtermax);
|
---|
| 370 | if (os2msg.msg == WM_QUIT && ((ULONG)os2msg.mp2 != 0) ) {
|
---|
| 371 | // Don't return FALSE when the window list sends us
|
---|
| 372 | // a WM_QUIT message, improper killing can lead to
|
---|
| 373 | // application crashes.
|
---|
| 374 | // In the WM_QUIT handler in pmwindow we send a WM_CLOSE
|
---|
| 375 | // in this case. When the app calls PostQuitMessage (mp2 == 0),
|
---|
| 376 | // then we handle it the normal way
|
---|
| 377 | rc = 1;
|
---|
| 378 | }
|
---|
[8689] | 379 | }
|
---|
| 380 | if(OS2ToWinMsgTranslate((PVOID)teb, &os2msg, pMsg, isUnicode, MSG_REMOVE) == FALSE) {
|
---|
| 381 | //dispatch untranslated message immediately
|
---|
| 382 | WinDispatchMsg(teb->o.odin.hab, &os2msg);
|
---|
| 383 | //and get the next one
|
---|
| 384 | return OSLibWinGetMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, isUnicode);
|
---|
| 385 | }
|
---|
[2469] | 386 |
|
---|
[8689] | 387 | memcpy(&teb->o.odin.os2msg, &os2msg, sizeof(QMSG));
|
---|
| 388 | memcpy(&teb->o.odin.winmsg, pMsg, sizeof(MSG));
|
---|
[10012] | 389 |
|
---|
[8689] | 390 | // send keyboard messages to the registered hooks
|
---|
| 391 | switch (pMsg->message)
|
---|
| 392 | {
|
---|
[7212] | 393 | case WINWM_KEYDOWN:
|
---|
| 394 | case WINWM_KEYUP:
|
---|
| 395 | case WINWM_SYSKEYDOWN:
|
---|
| 396 | case WINWM_SYSKEYUP:
|
---|
[8689] | 397 | // only supposed to be called upon WM_KEYDOWN
|
---|
| 398 | // and WM_KEYUP according to docs.
|
---|
[21340] | 399 | dprintf(("OSLibWinGetMsg: ProcessKbdHook call"));
|
---|
[8689] | 400 | if(ProcessKbdHook(pMsg, TRUE))
|
---|
| 401 | goto continuegetmsg;
|
---|
| 402 | break;
|
---|
[10216] | 403 | case WINWM_IME_CHAR:
|
---|
[10205] | 404 | // prevent from calling wrong DispatchMsg() (DBCS generated WM_CHAR)
|
---|
| 405 | memset( &teb->o.odin.winmsg, 0, sizeof( MSG ));
|
---|
| 406 | break;
|
---|
[8689] | 407 | }
|
---|
| 408 | return rc;
|
---|
[2469] | 409 | }
|
---|
[7211] | 410 |
|
---|
| 411 |
|
---|
[2469] | 412 | //******************************************************************************
|
---|
[10012] | 413 | //PeekMessage retrieves only messages associated with the window identified by the
|
---|
| 414 | //hwnd parameter or any of its children as specified by the IsChild function, and within
|
---|
| 415 | //the range of message values given by the uMsgFilterMin and uMsgFilterMax
|
---|
| 416 | //parameters. If hwnd is NULL, PeekMessage retrieves messages for any window that
|
---|
| 417 | //belongs to the current thread making the call. (PeekMessage does not retrieve
|
---|
| 418 | //messages for windows that belong to other threads.) If hwnd is -1, PeekMessage only
|
---|
| 419 | //returns messages with a hwnd value of NULL, as posted by the PostAppMessage
|
---|
| 420 | //function. If uMsgFilterMin and uMsgFilterMax are both zero, PeekMessage returns all
|
---|
| 421 | //available messages (no range filtering is performed).
|
---|
[2469] | 422 | //TODO: Not working as specified right now!
|
---|
| 423 | //******************************************************************************
|
---|
[7223] | 424 | BOOL OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
|
---|
[2469] | 425 | DWORD fRemove, BOOL isUnicode)
|
---|
| 426 | {
|
---|
[8689] | 427 | BOOL rc, eaten;
|
---|
| 428 | TEB *teb;
|
---|
| 429 | QMSG os2msg;
|
---|
| 430 | HWND hwndOS2 = 0;
|
---|
[2469] | 431 |
|
---|
[8689] | 432 | if(uMsgFilterMin > uMsgFilterMax) {
|
---|
| 433 | //TODO: is this correct behaviour?
|
---|
| 434 | dprintf(("!ERROR!: invalid message filter range!!!"));
|
---|
| 435 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
| 436 | return FALSE;
|
---|
| 437 | }
|
---|
| 438 | if(hwnd && hwnd != -1) {
|
---|
[10212] | 439 | hwndOS2 = Win32ToOS2Handle(hwnd);
|
---|
| 440 | if(hwndOS2 == NULL) {
|
---|
| 441 | dprintf(("PeekMsg: window %x NOT FOUND!", hwnd));
|
---|
| 442 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
|
---|
| 443 | return FALSE;
|
---|
| 444 | }
|
---|
[8689] | 445 | }
|
---|
[3274] | 446 |
|
---|
[8689] | 447 | teb = GetThreadTEB();
|
---|
| 448 | if(teb == NULL) {
|
---|
[2469] | 449 | DebugInt3();
|
---|
| 450 | return FALSE;
|
---|
[8689] | 451 | }
|
---|
[2469] | 452 |
|
---|
[10212] | 453 | //check for a queued WM_CHAR message (e.g. inserted by TranslateMessage)
|
---|
| 454 | if(ReturnQueuedWMCHAR(pMsg, teb, hwnd, uMsgFilterMin, uMsgFilterMax, isUnicode, fRemove) == TRUE)
|
---|
[8689] | 455 | {
|
---|
[2469] | 456 | return TRUE;
|
---|
[8689] | 457 | }
|
---|
[2469] | 458 |
|
---|
| 459 | continuepeekmsg:
|
---|
[10012] | 460 | if(uMsgFilterMin && uMsgFilterMax)
|
---|
[8689] | 461 | { //we can't use the PM message filter (since the message nrs aren't similar), so we must
|
---|
| 462 | //filter each message seperately
|
---|
| 463 | //to do so, we will translate each win32 message in the filter range and call WinPeekMsg
|
---|
| 464 | ULONG ulPMFilter;
|
---|
[2469] | 465 |
|
---|
[10216] | 466 | for(int i=0;i<uMsgFilterMax-uMsgFilterMin+1;i++)
|
---|
[10122] | 467 | {
|
---|
[8691] | 468 | rc = 0;
|
---|
| 469 |
|
---|
[8689] | 470 | ulPMFilter = TranslateWinMsg(uMsgFilterMin+i, TRUE, TRUE);
|
---|
| 471 | if(ulPMFilter) {
|
---|
[10122] | 472 | rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, ulPMFilter, ulPMFilter,
|
---|
| 473 | (fRemove & PM_REMOVE_W) ? PM_REMOVE : PM_NOREMOVE);
|
---|
| 474 | //Sadly indeed WinPeekMsg sometimes does not filter well!
|
---|
| 475 | if (rc && (os2msg.msg != ulPMFilter)) {// drop this message
|
---|
| 476 | dprintf(("WARNING: WinPeekMsg returns %x even though we filter for %x", os2msg.msg, ulPMFilter));
|
---|
| 477 | rc = 0;
|
---|
[8689] | 478 | }
|
---|
| 479 | }
|
---|
| 480 | if(rc) {
|
---|
| 481 | break;
|
---|
| 482 | }
|
---|
[2469] | 483 | }
|
---|
[8689] | 484 | }
|
---|
| 485 | else {
|
---|
[10104] | 486 | rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, 0, 0, (fRemove & PM_REMOVE_W) ? PM_REMOVE : PM_NOREMOVE);
|
---|
[8689] | 487 | }
|
---|
| 488 | if(rc == FALSE) {
|
---|
| 489 | return FALSE;
|
---|
| 490 | }
|
---|
[10012] | 491 |
|
---|
[8689] | 492 | // @@@PH
|
---|
| 493 | // warning - OS2ToWinMsgTranslate might insert additional messages
|
---|
| 494 | // into the queue
|
---|
[10012] | 495 | if(OS2ToWinMsgTranslate((PVOID)teb, &os2msg, pMsg, isUnicode, (fRemove & PM_REMOVE_W) ? MSG_REMOVE : MSG_NOREMOVE) == FALSE)
|
---|
[8689] | 496 | {
|
---|
| 497 | //unused PM message; dispatch immediately and grab next one
|
---|
| 498 | dprintf2(("OSLibWinPeekMsg: Untranslated message; dispatched immediately"));
|
---|
| 499 | if(!(fRemove & PM_REMOVE_W)) {
|
---|
[9950] | 500 | rc = WinPeekMsg(teb->o.odin.hab, &os2msg, os2msg.hwnd, os2msg.msg,
|
---|
| 501 | os2msg.msg, PM_REMOVE);
|
---|
[8689] | 502 | }
|
---|
| 503 | WinDispatchMsg(teb->o.odin.hab, &os2msg);
|
---|
| 504 | return OSLibWinPeekMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, fRemove, isUnicode);
|
---|
| 505 | }
|
---|
| 506 | //TODO: This is not safe! There's no guarantee this message will be dispatched and it might overwrite a previous message
|
---|
| 507 | if(fRemove & PM_REMOVE_W) {
|
---|
[10012] | 508 | memcpy(&teb->o.odin.os2msg, &os2msg, sizeof(QMSG));
|
---|
| 509 | memcpy(&teb->o.odin.winmsg, pMsg, sizeof(MSG));
|
---|
[8689] | 510 | }
|
---|
[2948] | 511 |
|
---|
[8689] | 512 | // send keyboard messages to the registered hooks
|
---|
[8801] | 513 | if(fRemove & PM_REMOVE_W) {
|
---|
| 514 | switch (pMsg->message)
|
---|
| 515 | {
|
---|
| 516 | case WINWM_KEYDOWN:
|
---|
| 517 | case WINWM_KEYUP:
|
---|
| 518 | case WINWM_SYSKEYDOWN:
|
---|
| 519 | case WINWM_SYSKEYUP:
|
---|
| 520 | // only supposed to be called upon WM_KEYDOWN
|
---|
| 521 | // and WM_KEYUP according to docs.
|
---|
[21527] | 522 | dprintf(("OSLibWinPeekMsg: ProcessKbdHook call"));
|
---|
[8801] | 523 | if(ProcessKbdHook(pMsg, fRemove))
|
---|
| 524 | goto continuepeekmsg;
|
---|
| 525 | break;
|
---|
[10216] | 526 | case WINWM_IME_CHAR:
|
---|
[10205] | 527 | // prevent from calling wrong DispatchMsg() (DBCS generated WM_CHAR)
|
---|
| 528 | memset( &teb->o.odin.winmsg, 0, sizeof( MSG ));
|
---|
| 529 | break;
|
---|
[8801] | 530 | }
|
---|
[8689] | 531 | }
|
---|
[2948] | 532 |
|
---|
[8689] | 533 | return rc;
|
---|
[2469] | 534 | }
|
---|
| 535 | //******************************************************************************
|
---|
| 536 | //******************************************************************************
|
---|
| 537 | ULONG OSLibWinQueryMsgTime()
|
---|
| 538 | {
|
---|
[8689] | 539 | return WinQueryMsgTime(GetThreadHAB());
|
---|
[2469] | 540 | }
|
---|
| 541 | //******************************************************************************
|
---|
| 542 | //******************************************************************************
|
---|
| 543 | BOOL OSLibWinWaitMessage()
|
---|
| 544 | {
|
---|
[8689] | 545 | return WinWaitMsg(GetThreadHAB(), 0, 0);
|
---|
[2469] | 546 | }
|
---|
| 547 | //******************************************************************************
|
---|
| 548 | //TODO: QS_HOTKEY
|
---|
| 549 | //******************************************************************************
|
---|
[21955] | 550 | ULONG OSLibWinQueryQueueStatus(ULONG flags)
|
---|
[2469] | 551 | {
|
---|
[8689] | 552 | ULONG statusOS2, statusWin32 = 0;
|
---|
[2469] | 553 |
|
---|
[8689] | 554 | statusOS2 = WinQueryQueueStatus(HWND_DESKTOP);
|
---|
[2469] | 555 |
|
---|
[21955] | 556 | if (flags & QS_KEY)
|
---|
| 557 | {
|
---|
| 558 | // WinQueryQueueStatus() has a bug which causes it to always return
|
---|
| 559 | // the QS_KEY bit set when the associated window is active, regardless
|
---|
| 560 | // of whether thiere are WM_CHAR messages in the queue or not. We try to
|
---|
| 561 | // fix this by looking up the queue ourselves if the caller actually
|
---|
| 562 | // wants this state to be checked
|
---|
| 563 | QMSG qmsg;
|
---|
| 564 | BOOL haveKey = WinPeekMsg (0, &qmsg, 0, WM_CHAR, WM_CHAR, PM_NOREMOVE);
|
---|
| 565 | if (haveKey)
|
---|
| 566 | {
|
---|
| 567 | // set the proper "summary" status
|
---|
| 568 | statusOS2 |= (QS_KEY << 16);
|
---|
| 569 | }
|
---|
| 570 | else
|
---|
| 571 | {
|
---|
| 572 | statusOS2 &= ~(QS_KEY << 16);
|
---|
| 573 | // according to PMREF, the "added" field is a subset of the
|
---|
| 574 | // "summary" field, so it makes no sense to have it set when it is
|
---|
| 575 | // reset in "summary"
|
---|
| 576 | statusOS2 &= ~(QS_KEY);
|
---|
| 577 | }
|
---|
| 578 | }
|
---|
| 579 |
|
---|
[21555] | 580 | // convert the flags since last call (low word)
|
---|
| 581 |
|
---|
[8689] | 582 | if(statusOS2 & QS_KEY)
|
---|
| 583 | statusWin32 |= QS_KEY_W;
|
---|
| 584 | if(statusOS2 & QS_MOUSEBUTTON)
|
---|
| 585 | statusWin32 |= QS_MOUSEBUTTON_W;
|
---|
| 586 | if(statusOS2 & QS_MOUSEMOVE)
|
---|
| 587 | statusWin32 |= QS_MOUSEMOVE_W;
|
---|
| 588 | if(statusOS2 & QS_TIMER)
|
---|
| 589 | statusWin32 |= QS_TIMER_W;
|
---|
| 590 | if(statusOS2 & QS_PAINT)
|
---|
| 591 | statusWin32 |= QS_PAINT_W;
|
---|
| 592 | if(statusOS2 & QS_POSTMSG)
|
---|
| 593 | statusWin32 |= QS_POSTMESSAGE_W;
|
---|
| 594 | if(statusOS2 & QS_SENDMSG)
|
---|
| 595 | statusWin32 |= QS_SENDMESSAGE_W;
|
---|
[2469] | 596 |
|
---|
[21555] | 597 | // convert the summary flags (high word)
|
---|
| 598 |
|
---|
| 599 | statusOS2 >>= 16;
|
---|
| 600 |
|
---|
| 601 | if(statusOS2 & QS_KEY)
|
---|
| 602 | statusWin32 |= QS_KEY_W << 16;
|
---|
| 603 | if(statusOS2 & QS_MOUSEBUTTON)
|
---|
| 604 | statusWin32 |= QS_MOUSEBUTTON_W << 16;
|
---|
| 605 | if(statusOS2 & QS_MOUSEMOVE)
|
---|
| 606 | statusWin32 |= QS_MOUSEMOVE_W << 16;
|
---|
| 607 | if(statusOS2 & QS_TIMER)
|
---|
| 608 | statusWin32 |= QS_TIMER_W << 16;
|
---|
| 609 | if(statusOS2 & QS_PAINT)
|
---|
| 610 | statusWin32 |= QS_PAINT_W << 16;
|
---|
| 611 | if(statusOS2 & QS_POSTMSG)
|
---|
| 612 | statusWin32 |= QS_POSTMESSAGE_W << 16;
|
---|
| 613 | if(statusOS2 & QS_SENDMSG)
|
---|
| 614 | statusWin32 |= QS_SENDMESSAGE_W << 16;
|
---|
| 615 |
|
---|
[8689] | 616 | return statusWin32;
|
---|
[2469] | 617 | }
|
---|
| 618 | //******************************************************************************
|
---|
| 619 | //******************************************************************************
|
---|
| 620 | BOOL OSLibWinInSendMessage()
|
---|
| 621 | {
|
---|
[8689] | 622 | return WinInSendMsg(GetThreadHAB());
|
---|
[2469] | 623 | }
|
---|
| 624 | //******************************************************************************
|
---|
| 625 | //******************************************************************************
|
---|
| 626 | DWORD OSLibWinGetMessagePos()
|
---|
| 627 | {
|
---|
[8689] | 628 | APIRET rc;
|
---|
| 629 | POINTL ptl;
|
---|
[2469] | 630 |
|
---|
[8689] | 631 | rc = WinQueryMsgPos(GetThreadHAB(), &ptl);
|
---|
| 632 | if(!rc) {
|
---|
| 633 | return 0;
|
---|
| 634 | }
|
---|
| 635 | //convert to windows coordinates
|
---|
| 636 | return MAKEULONG(ptl.x,mapScreenY(ptl.y));
|
---|
[2469] | 637 | }
|
---|
| 638 | //******************************************************************************
|
---|
| 639 | //******************************************************************************
|
---|
| 640 | LONG OSLibWinGetMessageTime()
|
---|
| 641 | {
|
---|
[8689] | 642 | return (LONG)WinQueryMsgTime(GetThreadHAB());
|
---|
[2469] | 643 | }
|
---|
| 644 | //******************************************************************************
|
---|
| 645 | //******************************************************************************
|
---|
| 646 | BOOL OSLibWinReplyMessage(ULONG result)
|
---|
| 647 | {
|
---|
[8689] | 648 | return (BOOL)WinReplyMsg( NULLHANDLE, NULLHANDLE, HMQ_CURRENT, (MRESULT)result);
|
---|
[2469] | 649 | }
|
---|
[10012] | 650 |
|
---|
[2469] | 651 | //******************************************************************************
|
---|
[10012] | 652 |
|
---|
| 653 | /**
|
---|
| 654 | * Send and Post message helper for packing down interprocess and interthread messages.
|
---|
| 655 | *
|
---|
| 656 | * @returns Pointer to packet on success. (shared memory)
|
---|
| 657 | * @returns NULL on failure with SendMessage return code suggestion in *pRc if pRc is set.
|
---|
| 658 | * @param hwndOdin Odin window handle. (NULL allowed)
|
---|
| 659 | * @param hwndOS2 OS/2 window handle.
|
---|
| 660 | * @param msg Message id.
|
---|
| 661 | * @param wParam Message param.
|
---|
| 662 | * @param lParam Message param.
|
---|
| 663 | * @param fUnicode Unicode or ansi indicator.
|
---|
| 664 | * @param pRc Where to store SendMessage return code. Optional.
|
---|
| 665 | * @author knut st. osmundsen<bird@anduin.net>
|
---|
| 666 | */
|
---|
| 667 | void * OSLibPackMessage(HWND hwndOdin, HWND hwndOS2, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode, PULONG pRc)
|
---|
| 668 | {
|
---|
| 669 | POSTMSG_PACKET * pMsgPacket;
|
---|
| 670 |
|
---|
| 671 | /*
|
---|
| 672 | * Pack message by id.
|
---|
| 673 | */
|
---|
| 674 | switch (msg)
|
---|
| 675 | {
|
---|
| 676 | /*
|
---|
| 677 | * lParam = PCOPYDATASTRUCT.
|
---|
| 678 | * Must move this to shared memory together with any
|
---|
| 679 | * data it's pointing at.
|
---|
| 680 | *
|
---|
| 681 | * We put everything into the package that might ease cleanup...
|
---|
| 682 | * WARNING! Currently there are cleanup hacks which works with acrobat.
|
---|
| 683 | */
|
---|
| 684 | case WINWM_COPYDATA:
|
---|
| 685 | {
|
---|
| 686 | PCOPYDATASTRUCT_W pOrg = (PCOPYDATASTRUCT_W)lParam;
|
---|
| 687 | dprintf(("user32::oslibmsg::OSLibPackMessage - WM_COPYDATA: lParam=%#x dwData=%#x cbData=%d lpData=%#x",
|
---|
| 688 | pOrg, pOrg ? pOrg->dwData : -1, pOrg ? pOrg->cbData : -1, pOrg ? pOrg->lpData : (LPVOID)-1));
|
---|
| 689 |
|
---|
| 690 | /*
|
---|
| 691 | * Calc packet size.
|
---|
| 692 | */
|
---|
| 693 | unsigned cb = sizeof(POSTMSG_PACKET);
|
---|
| 694 | if (pOrg)
|
---|
| 695 | {
|
---|
| 696 | cb += sizeof(COPYDATASTRUCT_W);
|
---|
| 697 | if (pOrg->lpData && pOrg->cbData)
|
---|
| 698 | cb += 16 + pOrg->cbData; //add 16 Bytes for safty and alignment.
|
---|
| 699 | }
|
---|
| 700 |
|
---|
| 701 | /*
|
---|
| 702 | * Allocate packet.
|
---|
| 703 | */
|
---|
| 704 | pMsgPacket = (POSTMSG_PACKET *)_smalloc(cb);
|
---|
| 705 | if (!pMsgPacket)
|
---|
| 706 | {
|
---|
| 707 | dprintf(("user32::oslibmsg::OSLibPackMessage - WM_COPYDATA: failed to allocate %d shared bytes for packing", cb));
|
---|
| 708 | DebugInt3();
|
---|
| 709 | if (pRc)
|
---|
| 710 | *pRc = FALSE;
|
---|
| 711 | //@todo figure out which error to set. This is plain guesswork!
|
---|
| 712 | SetLastError(ERROR_NOT_ENOUGH_MEMORY_W);
|
---|
| 713 | break;
|
---|
| 714 | }
|
---|
| 715 |
|
---|
| 716 | /*
|
---|
| 717 | * Initialize packet.
|
---|
| 718 | */
|
---|
| 719 | PCOPYDATASTRUCT_W pNew = (PCOPYDATASTRUCT_W)(pMsgPacket + 1);
|
---|
| 720 | pMsgPacket->wParam = wParam;
|
---|
| 721 | pMsgPacket->lParam = (LPARAM)pNew;
|
---|
| 722 | *pNew = *pOrg;
|
---|
| 723 | if (pNew->cbData && pNew->lpData)
|
---|
| 724 | {
|
---|
| 725 | pNew->lpData = (LPVOID)(((unsigned)(pNew + 1) + 15) & ~15); //16byte align for safty.
|
---|
| 726 | //@todo what about a safe_memcpy?
|
---|
| 727 | memcpy(pNew->lpData, pOrg->lpData, pNew->cbData);
|
---|
| 728 | }
|
---|
| 729 |
|
---|
| 730 | /* done! */
|
---|
| 731 | dprintf(("user32::oslibmsg::OSLibPackMessage - WM_COPYDATA: Packed down %d bytes at %#x (pMsgPacket)",
|
---|
| 732 | cb, pMsgPacket));
|
---|
| 733 | break;
|
---|
| 734 | }
|
---|
| 735 |
|
---|
| 736 |
|
---|
| 737 | /*
|
---|
| 738 | * Default packing
|
---|
| 739 | */
|
---|
| 740 | default:
|
---|
| 741 | {
|
---|
[10240] | 742 | ULONG pid;
|
---|
| 743 |
|
---|
| 744 | GetWindowThreadProcessId(hwndOdin, &pid);
|
---|
| 745 |
|
---|
| 746 | //use shared or local memory depending on the target window
|
---|
| 747 | //(sfree can be used for any heap)
|
---|
| 748 | if(pid != GetCurrentProcessId()) {
|
---|
| 749 | pMsgPacket = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
|
---|
| 750 | }
|
---|
| 751 | else pMsgPacket = (POSTMSG_PACKET *)malloc(sizeof(POSTMSG_PACKET));
|
---|
| 752 |
|
---|
[10012] | 753 | if (!pMsgPacket)
|
---|
| 754 | {
|
---|
| 755 | dprintf(("user32::oslibmsg::OSLibPackMessage - allocated packet structure is NULL"));
|
---|
| 756 | if (pRc)
|
---|
| 757 | { // Can't find any better return code than 0 :/
|
---|
| 758 | *pRc = 0;
|
---|
| 759 | }
|
---|
| 760 | DebugInt3();
|
---|
| 761 | break;
|
---|
| 762 | }
|
---|
| 763 | pMsgPacket->wParam = wParam;
|
---|
| 764 | pMsgPacket->lParam = lParam;
|
---|
| 765 | }
|
---|
| 766 |
|
---|
| 767 | }
|
---|
| 768 |
|
---|
| 769 | return pMsgPacket;
|
---|
| 770 | }
|
---|
| 771 |
|
---|
| 772 |
|
---|
| 773 | /**
|
---|
| 774 | * Send an inter thread/proces message.
|
---|
| 775 | *
|
---|
| 776 | * @returns
|
---|
[10240] | 777 | * @param hwndWin32 Odin window handle.
|
---|
| 778 | * @param hwndOS2 OS/2 window handle
|
---|
[10012] | 779 | * @param msg Odin message id.
|
---|
| 780 | * @param wParam Message param.
|
---|
| 781 | * @param lParam Message param.
|
---|
| 782 | * @param fUnicode Unicode indicator.
|
---|
| 783 | */
|
---|
[10240] | 784 | ULONG OSLibSendMessage(HWND hwndWin32, HWND hwndOS2, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode)
|
---|
[2469] | 785 | {
|
---|
[10012] | 786 | ULONG rc; /* return code on packing failure */
|
---|
| 787 | void * pvMsgPacket; /* packed message (shared memory) */
|
---|
| 788 |
|
---|
[10240] | 789 | if(GetDesktopWindow() == hwndWin32) {
|
---|
| 790 | dprintf(("Ignore messages sent to the desktop window"));
|
---|
| 791 | return TRUE;
|
---|
| 792 | }
|
---|
| 793 |
|
---|
[10012] | 794 | /*
|
---|
| 795 | * Call message packer.
|
---|
| 796 | */
|
---|
[10240] | 797 | pvMsgPacket = OSLibPackMessage(hwndWin32, hwndOS2, msg, wParam, lParam, fUnicode, &rc);
|
---|
[10012] | 798 | if (!pvMsgPacket)
|
---|
[6620] | 799 | {
|
---|
[10012] | 800 | dprintf(("user32::oslibmsg::OSLibSendMessage - Failed to pack message !!"));
|
---|
| 801 | DebugInt3();
|
---|
| 802 | return rc;
|
---|
[6620] | 803 | }
|
---|
[2469] | 804 |
|
---|
[10240] | 805 | return (ULONG)WinSendMsg(hwndOS2, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), pvMsgPacket);
|
---|
[2469] | 806 | }
|
---|
| 807 | //******************************************************************************
|
---|
| 808 | //******************************************************************************
|
---|
[21502] | 809 | BOOL OSLibSendWinMessage(HWND hwnd, ULONG winmsg, ULONG extra /*= 0*/)
|
---|
[10185] | 810 | {
|
---|
[21502] | 811 | if (winmsg == WINWM_MOUSEWHEEL)
|
---|
| 812 | {
|
---|
| 813 | return (BOOL)WinSendMsg(Win32ToOS2Handle(hwnd), TranslateWinMsg(winmsg, TRUE),
|
---|
| 814 | 0, MPFROM2SHORT(0, extra < 0 ? SB_LINEDOWN : SB_LINEUP));
|
---|
| 815 | }
|
---|
[10185] | 816 | return (BOOL)WinSendMsg(Win32ToOS2Handle(hwnd), TranslateWinMsg(winmsg, TRUE), 0, 0);
|
---|
| 817 | }
|
---|
| 818 | //******************************************************************************
|
---|
| 819 | //******************************************************************************
|
---|
[2469] | 820 | ULONG OSLibWinBroadcastMsg(ULONG msg, ULONG wParam, ULONG lParam, BOOL fSend)
|
---|
| 821 | {
|
---|
[10012] | 822 | #ifdef DEBUG
|
---|
| 823 | if (msg == WINWM_COPYDATA)
|
---|
| 824 | {
|
---|
| 825 | dprintf(("user32::oslibmsg::OSLibWinBroadcastMsg - WM_COPYDATA will not work outside this process !!!"));
|
---|
| 826 | DebugInt3();
|
---|
| 827 | }
|
---|
| 828 | #endif
|
---|
[5805] | 829 | return WinBroadcastMsg(HWND_DESKTOP, WIN32APP_POSTMSG+msg, (MPARAM)wParam, (MPARAM)lParam,
|
---|
[2469] | 830 | (fSend) ? BMSG_SEND : BMSG_POST);
|
---|
| 831 | }
|
---|
[10012] | 832 |
|
---|
| 833 |
|
---|
| 834 | /**
|
---|
| 835 | * Post a message.
|
---|
| 836 | *
|
---|
| 837 | * @returns Success indicator.
|
---|
| 838 | *
|
---|
| 839 | * @param hwndWin32 Odin window handle.
|
---|
| 840 | * @param hwndOS2 OS/2 window handle
|
---|
| 841 | * @param msg Odin message id.
|
---|
| 842 | * @param wParam Message param.
|
---|
| 843 | * @param lParam Message param.
|
---|
| 844 | * @param fUnicode Unicode indicator.
|
---|
| 845 | */
|
---|
[8953] | 846 | BOOL OSLibPostMessage(HWND hwndWin32, HWND hwndOS2, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode)
|
---|
[2469] | 847 | {
|
---|
[10012] | 848 | void * pvMsgPacket; /* packed message (shared memory) */
|
---|
[8953] | 849 |
|
---|
[10240] | 850 | if(GetDesktopWindow() == hwndWin32) {
|
---|
| 851 | dprintf(("Ignore messages posted to the desktop window"));
|
---|
| 852 | return TRUE;
|
---|
| 853 | }
|
---|
| 854 |
|
---|
[10012] | 855 | /*
|
---|
| 856 | * Call message packer.
|
---|
| 857 | */
|
---|
| 858 | pvMsgPacket = OSLibPackMessage(hwndWin32, hwndOS2, msg, wParam, lParam, fUnicode, NULL);
|
---|
| 859 | if (!pvMsgPacket)
|
---|
[6620] | 860 | {
|
---|
[10012] | 861 | dprintf(("user32::oslibmsg::OSLibPostMessage - Failed to pack message !!"));
|
---|
| 862 | DebugInt3();
|
---|
[6620] | 863 | return FALSE;
|
---|
| 864 | }
|
---|
[10012] | 865 |
|
---|
| 866 | /*
|
---|
| 867 | * Post the message.
|
---|
| 868 | * Signal the receiver for if it's doing MsgWaitForMultipleObjects() at the time.
|
---|
| 869 | */
|
---|
[8953] | 870 | TEB *teb = GetTEBFromThreadId(GetWindowThreadProcessId(hwndWin32, NULL));
|
---|
[10012] | 871 | BOOL ret = WinPostMsg(hwndOS2,
|
---|
| 872 | WIN32APP_POSTMSG+msg,
|
---|
| 873 | (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA),
|
---|
| 874 | pvMsgPacket);
|
---|
| 875 | if (teb && (teb->o.odin.dwWakeMask & QS_POSTMESSAGE_W))
|
---|
| 876 | {
|
---|
[8953] | 877 | //thread is blocked in MsgWaitForMultipleObjects waiting for
|
---|
| 878 | //posted messages
|
---|
| 879 | dprintf(("PostMessage: Wake up thread %x which is blocked in MsgWaitForMultipleObjects", teb->o.odin.threadId));
|
---|
| 880 | SetEvent(teb->o.odin.hPostMsgEvent);
|
---|
| 881 | }
|
---|
| 882 | return ret;
|
---|
[2469] | 883 | }
|
---|
| 884 | //******************************************************************************
|
---|
[5137] | 885 | //Direct posting of messages that must remain invisible to the win32 app
|
---|
| 886 | //******************************************************************************
|
---|
| 887 | BOOL OSLibPostMessageDirect(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
|
---|
| 888 | {
|
---|
| 889 | return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
|
---|
| 890 | }
|
---|
| 891 | //******************************************************************************
|
---|
[2469] | 892 | //******************************************************************************
|
---|
| 893 | BOOL OSLibPostThreadMessage(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
|
---|
| 894 | {
|
---|
[8689] | 895 | TEB *teb = GetTEBFromThreadId(threadid);
|
---|
| 896 | POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
|
---|
| 897 | BOOL ret;
|
---|
[10012] | 898 |
|
---|
| 899 | if (NULL == packet)
|
---|
[6620] | 900 | {
|
---|
[8908] | 901 | dprintf(("user32::oslibmsg::OSLibPostMessage - allocated packet structure is NULL"));
|
---|
[6620] | 902 |
|
---|
[10012] | 903 | DebugInt3();
|
---|
[6620] | 904 | // PH: we can provide a correct returncode
|
---|
| 905 | return FALSE;
|
---|
| 906 | }
|
---|
[10012] | 907 |
|
---|
[6501] | 908 | if(teb == NULL) {
|
---|
| 909 | dprintf(("OSLibPostThreadMessage: thread %x not found!", threadid));
|
---|
| 910 | return FALSE;
|
---|
| 911 | }
|
---|
| 912 | dprintf(("PostThreadMessageA %x %x %x %x -> hmq %x", threadid, msg, wParam, lParam, teb->o.odin.hmq));
|
---|
[5805] | 913 | packet->wParam = wParam;
|
---|
| 914 | packet->lParam = lParam;
|
---|
[6501] | 915 |
|
---|
[10012] | 916 | ret = WinPostQueueMsg((HMQ)teb->o.odin.hmq, WIN32APP_POSTMSG+msg,
|
---|
| 917 | (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA),
|
---|
[6501] | 918 | (MPARAM)packet);
|
---|
| 919 |
|
---|
| 920 | if(ret == FALSE)
|
---|
| 921 | {
|
---|
| 922 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
---|
| 923 | return FALSE;
|
---|
| 924 | }
|
---|
[8953] | 925 |
|
---|
| 926 | if(teb->o.odin.dwWakeMask & QS_POSTMESSAGE_W) {
|
---|
| 927 | //thread is blocked in MsgWaitForMultipleObjects waiting for
|
---|
| 928 | //posted messages
|
---|
| 929 | dprintf(("PostMessage: Wake up thread %x which is blocked in MsgWaitForMultipleObjects", teb->o.odin.threadId));
|
---|
| 930 | SetEvent(teb->o.odin.hPostMsgEvent);
|
---|
| 931 | }
|
---|
| 932 |
|
---|
[6501] | 933 | SetLastError(ERROR_SUCCESS_W);
|
---|
| 934 | return TRUE;
|
---|
[2469] | 935 | }
|
---|
| 936 | //******************************************************************************
|
---|
| 937 | //******************************************************************************
|
---|
[7620] | 938 | DWORD GetThreadMessageExtraInfo()
|
---|
| 939 | {
|
---|
[8689] | 940 | TEB *teb;
|
---|
[2469] | 941 |
|
---|
[8689] | 942 | teb = GetThreadTEB();
|
---|
| 943 | if(teb)
|
---|
| 944 | {
|
---|
| 945 | return teb->o.odin.dwMsgExtraInfo;
|
---|
| 946 | }
|
---|
| 947 | dprintf(("GetThreadMessageExtraInfo: teb == NULL!!"));
|
---|
| 948 | return 0;
|
---|
[7620] | 949 | }
|
---|
| 950 | //******************************************************************************
|
---|
| 951 | //******************************************************************************
|
---|
| 952 | DWORD SetThreadMessageExtraInfo(DWORD lParam)
|
---|
| 953 | {
|
---|
[8689] | 954 | TEB *teb;
|
---|
[7620] | 955 |
|
---|
[8689] | 956 | teb = GetThreadTEB();
|
---|
| 957 | if(teb)
|
---|
| 958 | {
|
---|
| 959 | teb->o.odin.dwMsgExtraInfo = lParam;
|
---|
| 960 | }
|
---|
| 961 | else dprintf(("SetThreadMessageExtraInfo: teb == NULL!!"));
|
---|
| 962 | return 0;
|
---|
[7620] | 963 | }
|
---|
| 964 | //******************************************************************************
|
---|
| 965 | //******************************************************************************
|
---|