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