| 1 | /* $Id: oslibmsg.cpp,v 1.45 2001-10-09 05:18:02 phaller 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 | // send keyboard messages to the registered hooks | 
|---|
| 288 | if(pMsg->message <= WINWM_KEYLAST && pMsg->message >= WINWM_KEYDOWN) | 
|---|
| 289 | { | 
|---|
| 290 | //    if(ProcessKbdHookLL(pMsg, TRUE)) | 
|---|
| 291 | //      goto continuegetmsg; | 
|---|
| 292 |  | 
|---|
| 293 | // @@@PH | 
|---|
| 294 | // only supposed to be called upon WM_KEYDOWN | 
|---|
| 295 | // and WM_KEYUP according to docs. | 
|---|
| 296 | if(ProcessKbdHook(pMsg, TRUE)) | 
|---|
| 297 | goto continuegetmsg; | 
|---|
| 298 | } | 
|---|
| 299 | return rc; | 
|---|
| 300 | } | 
|---|
| 301 | //****************************************************************************** | 
|---|
| 302 | //PeekMessage retrieves only messages associated with the window identified by the | 
|---|
| 303 | //hwnd parameter or any of its children as specified by the IsChild function, and within | 
|---|
| 304 | //the range of message values given by the uMsgFilterMin and uMsgFilterMax | 
|---|
| 305 | //parameters. If hwnd is NULL, PeekMessage retrieves messages for any window that | 
|---|
| 306 | //belongs to the current thread making the call. (PeekMessage does not retrieve | 
|---|
| 307 | //messages for windows that belong to other threads.) If hwnd is -1, PeekMessage only | 
|---|
| 308 | //returns messages with a hwnd value of NULL, as posted by the PostAppMessage | 
|---|
| 309 | //function. If uMsgFilterMin and uMsgFilterMax are both zero, PeekMessage returns all | 
|---|
| 310 | //available messages (no range filtering is performed). | 
|---|
| 311 | //TODO: Not working as specified right now! | 
|---|
| 312 | //****************************************************************************** | 
|---|
| 313 | BOOL OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax, | 
|---|
| 314 | DWORD fRemove, BOOL isUnicode) | 
|---|
| 315 | { | 
|---|
| 316 | BOOL  rc, eaten; | 
|---|
| 317 | TEB  *teb; | 
|---|
| 318 | QMSG  os2msg; | 
|---|
| 319 | HWND  hwndOS2 = 0; | 
|---|
| 320 |  | 
|---|
| 321 | if(hwnd && hwnd != -1) { | 
|---|
| 322 | hwndOS2 = Win32ToOS2Handle(hwnd); | 
|---|
| 323 | if(hwndOS2 == NULL) { | 
|---|
| 324 | dprintf(("PeekMsg: window %x NOT FOUND!", hwnd)); | 
|---|
| 325 | SetLastError(ERROR_INVALID_WINDOW_HANDLE_W); | 
|---|
| 326 | return FALSE; | 
|---|
| 327 | } | 
|---|
| 328 | } | 
|---|
| 329 |  | 
|---|
| 330 | teb = GetThreadTEB(); | 
|---|
| 331 | if(teb == NULL) { | 
|---|
| 332 | DebugInt3(); | 
|---|
| 333 | return FALSE; | 
|---|
| 334 | } | 
|---|
| 335 |  | 
|---|
| 336 | if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd)) { | 
|---|
| 337 | if(uMsgFilterMin) { | 
|---|
| 338 | if(teb->o.odin.msgWCHAR.message < uMsgFilterMin) | 
|---|
| 339 | goto continuepeekmsg; | 
|---|
| 340 | } | 
|---|
| 341 | if(uMsgFilterMax) { | 
|---|
| 342 | if(teb->o.odin.msgWCHAR.message > uMsgFilterMax) | 
|---|
| 343 | goto continuepeekmsg; | 
|---|
| 344 | } | 
|---|
| 345 |  | 
|---|
| 346 | if(fRemove & PM_REMOVE_W) { | 
|---|
| 347 | teb->o.odin.fTranslated = FALSE; | 
|---|
| 348 | teb->o.odin.os2msg.msg  = 0; | 
|---|
| 349 | teb->o.odin.os2msg.hwnd = 0; | 
|---|
| 350 | } | 
|---|
| 351 | memcpy(pMsg, &teb->o.odin.msgWCHAR, sizeof(MSG)); | 
|---|
| 352 | return TRUE; | 
|---|
| 353 | } | 
|---|
| 354 |  | 
|---|
| 355 | continuepeekmsg: | 
|---|
| 356 | do { | 
|---|
| 357 | eaten = FALSE; | 
|---|
| 358 | rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, TranslateWinMsg(uMsgFilterMin, TRUE), | 
|---|
| 359 | TranslateWinMsg(uMsgFilterMax, FALSE), (fRemove & PM_REMOVE_W) ? PM_REMOVE : PM_NOREMOVE); | 
|---|
| 360 |  | 
|---|
| 361 | if (rc && (fRemove & PM_REMOVE_W) && os2msg.msg == WM_TIMER) { | 
|---|
| 362 | eaten = TIMER_HandleTimer(&os2msg); | 
|---|
| 363 | } | 
|---|
| 364 | } | 
|---|
| 365 | while (eaten && rc); | 
|---|
| 366 |  | 
|---|
| 367 | if(rc == FALSE) { | 
|---|
| 368 | return FALSE; | 
|---|
| 369 | } | 
|---|
| 370 |  | 
|---|
| 371 | if(OS2ToWinMsgTranslate((PVOID)teb, &os2msg, pMsg, isUnicode, (fRemove & PM_REMOVE_W) ? MSG_REMOVE : MSG_NOREMOVE) == FALSE) | 
|---|
| 372 | { | 
|---|
| 373 | //unused PM message; dispatch immediately and grab next one | 
|---|
| 374 | dprintf2(("OSLibWinPeekMsg: Untranslated message; dispatched immediately")); | 
|---|
| 375 | if(!(fRemove & PM_REMOVE_W)) { | 
|---|
| 376 | rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, TranslateWinMsg(uMsgFilterMin, TRUE), | 
|---|
| 377 | TranslateWinMsg(uMsgFilterMax, FALSE), PM_REMOVE); | 
|---|
| 378 | } | 
|---|
| 379 | WinDispatchMsg(teb->o.odin.hab, &os2msg); | 
|---|
| 380 | return OSLibWinPeekMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, | 
|---|
| 381 | fRemove, isUnicode); | 
|---|
| 382 | } | 
|---|
| 383 | //TODO: This is not safe! There's no guarantee this message will be dispatched and it might overwrite a previous message | 
|---|
| 384 | if(fRemove & PM_REMOVE_W) { | 
|---|
| 385 | memcpy(&teb->o.odin.os2msg, &os2msg, sizeof(QMSG)); | 
|---|
| 386 | memcpy(&teb->o.odin.winmsg, pMsg, sizeof(MSG)); | 
|---|
| 387 | } | 
|---|
| 388 |  | 
|---|
| 389 | // send keyboard messages to the registered hooks | 
|---|
| 390 | if(pMsg->message <= WINWM_KEYLAST && pMsg->message >= WINWM_KEYDOWN) | 
|---|
| 391 | { | 
|---|
| 392 | //    if(ProcessKbdHookLL(pMsg, fRemove)) | 
|---|
| 393 | //      goto continuepeekmsg; | 
|---|
| 394 |  | 
|---|
| 395 | // @@@PH | 
|---|
| 396 | // only supposed to be called upon WM_KEYDOWN | 
|---|
| 397 | // and WM_KEYUP according to docs. | 
|---|
| 398 | if(ProcessKbdHook(pMsg, fRemove)) | 
|---|
| 399 | goto continuepeekmsg; | 
|---|
| 400 | } | 
|---|
| 401 |  | 
|---|
| 402 | return rc; | 
|---|
| 403 | } | 
|---|
| 404 | //****************************************************************************** | 
|---|
| 405 | //****************************************************************************** | 
|---|
| 406 | ULONG OSLibWinQueryMsgTime() | 
|---|
| 407 | { | 
|---|
| 408 | return WinQueryMsgTime(GetThreadHAB()); | 
|---|
| 409 | } | 
|---|
| 410 | //****************************************************************************** | 
|---|
| 411 | //****************************************************************************** | 
|---|
| 412 | BOOL OSLibWinWaitMessage() | 
|---|
| 413 | { | 
|---|
| 414 | return WinWaitMsg(GetThreadHAB(), 0, 0); | 
|---|
| 415 | } | 
|---|
| 416 | //****************************************************************************** | 
|---|
| 417 | //TODO: QS_HOTKEY | 
|---|
| 418 | //****************************************************************************** | 
|---|
| 419 | ULONG OSLibWinQueryQueueStatus() | 
|---|
| 420 | { | 
|---|
| 421 | ULONG statusOS2, statusWin32 = 0; | 
|---|
| 422 |  | 
|---|
| 423 | statusOS2 = WinQueryQueueStatus(HWND_DESKTOP); | 
|---|
| 424 |  | 
|---|
| 425 | if(statusOS2 & QS_KEY) | 
|---|
| 426 | statusWin32 |= QS_KEY_W; | 
|---|
| 427 | if(statusOS2 & QS_MOUSEBUTTON) | 
|---|
| 428 | statusWin32 |= QS_MOUSEBUTTON_W; | 
|---|
| 429 | if(statusOS2 & QS_MOUSEMOVE) | 
|---|
| 430 | statusWin32 |= QS_MOUSEMOVE_W; | 
|---|
| 431 | if(statusOS2 & QS_TIMER) | 
|---|
| 432 | statusWin32 |= QS_TIMER_W; | 
|---|
| 433 | if(statusOS2 & QS_PAINT) | 
|---|
| 434 | statusWin32 |= QS_PAINT_W; | 
|---|
| 435 | if(statusOS2 & QS_POSTMSG) | 
|---|
| 436 | statusWin32 |= QS_POSTMESSAGE_W; | 
|---|
| 437 | if(statusOS2 & QS_SENDMSG) | 
|---|
| 438 | statusWin32 |= QS_SENDMESSAGE_W; | 
|---|
| 439 |  | 
|---|
| 440 | return statusWin32; | 
|---|
| 441 | } | 
|---|
| 442 | //****************************************************************************** | 
|---|
| 443 | //****************************************************************************** | 
|---|
| 444 | BOOL OSLibWinInSendMessage() | 
|---|
| 445 | { | 
|---|
| 446 | return WinInSendMsg(GetThreadHAB()); | 
|---|
| 447 | } | 
|---|
| 448 | //****************************************************************************** | 
|---|
| 449 | //****************************************************************************** | 
|---|
| 450 | DWORD OSLibWinGetMessagePos() | 
|---|
| 451 | { | 
|---|
| 452 | APIRET rc; | 
|---|
| 453 | POINTL ptl; | 
|---|
| 454 |  | 
|---|
| 455 | rc = WinQueryMsgPos(GetThreadHAB(), &ptl); | 
|---|
| 456 | if(!rc) { | 
|---|
| 457 | return 0; | 
|---|
| 458 | } | 
|---|
| 459 | //convert to windows coordinates | 
|---|
| 460 | return MAKEULONG(ptl.x,mapScreenY(ptl.y)); | 
|---|
| 461 | } | 
|---|
| 462 | //****************************************************************************** | 
|---|
| 463 | //****************************************************************************** | 
|---|
| 464 | LONG OSLibWinGetMessageTime() | 
|---|
| 465 | { | 
|---|
| 466 | return (LONG)WinQueryMsgTime(GetThreadHAB()); | 
|---|
| 467 | } | 
|---|
| 468 | //****************************************************************************** | 
|---|
| 469 | //****************************************************************************** | 
|---|
| 470 | BOOL OSLibWinReplyMessage(ULONG result) | 
|---|
| 471 | { | 
|---|
| 472 | return (BOOL)WinReplyMsg( NULLHANDLE, NULLHANDLE, HMQ_CURRENT, (MRESULT)result); | 
|---|
| 473 | } | 
|---|
| 474 | //****************************************************************************** | 
|---|
| 475 | //****************************************************************************** | 
|---|
| 476 | ULONG OSLibSendMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode) | 
|---|
| 477 | { | 
|---|
| 478 | POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET)); | 
|---|
| 479 |  | 
|---|
| 480 | if(NULL == packet) | 
|---|
| 481 | { | 
|---|
| 482 | dprintf(("user32::oslibmsg::OSLibSendMessage - allocated packet structure is NULL, heapmin=%d\n", | 
|---|
| 483 | _sheapmin() )); | 
|---|
| 484 |  | 
|---|
| 485 | // PH: we cannot provide a correct returncode :( | 
|---|
| 486 | DebugInt3(); | 
|---|
| 487 | return 0; | 
|---|
| 488 | } | 
|---|
| 489 |  | 
|---|
| 490 | packet->wParam   = wParam; | 
|---|
| 491 | packet->lParam   = lParam; | 
|---|
| 492 |  | 
|---|
| 493 | return (ULONG)WinSendMsg(hwnd, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet); | 
|---|
| 494 | } | 
|---|
| 495 | //****************************************************************************** | 
|---|
| 496 | //****************************************************************************** | 
|---|
| 497 | ULONG OSLibWinBroadcastMsg(ULONG msg, ULONG wParam, ULONG lParam, BOOL fSend) | 
|---|
| 498 | { | 
|---|
| 499 | return WinBroadcastMsg(HWND_DESKTOP, WIN32APP_POSTMSG+msg, (MPARAM)wParam, (MPARAM)lParam, | 
|---|
| 500 | (fSend) ? BMSG_SEND : BMSG_POST); | 
|---|
| 501 | } | 
|---|
| 502 | //****************************************************************************** | 
|---|
| 503 | //****************************************************************************** | 
|---|
| 504 | BOOL OSLibPostMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode) | 
|---|
| 505 | { | 
|---|
| 506 | POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET)); | 
|---|
| 507 |  | 
|---|
| 508 | if (NULL == packet) | 
|---|
| 509 | { | 
|---|
| 510 | dprintf(("user32::oslibmsg::OSLibPostMessage - allocated packet structure is NULL, heapmin=%d\n", | 
|---|
| 511 | _sheapmin() )); | 
|---|
| 512 |  | 
|---|
| 513 | // PH: we can provide a correct returncode | 
|---|
| 514 | DebugInt3(); | 
|---|
| 515 | return FALSE; | 
|---|
| 516 | } | 
|---|
| 517 | packet->wParam   = wParam; | 
|---|
| 518 | packet->lParam   = lParam; | 
|---|
| 519 | return WinPostMsg(hwnd, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet); | 
|---|
| 520 | } | 
|---|
| 521 | //****************************************************************************** | 
|---|
| 522 | //Direct posting of messages that must remain invisible to the win32 app | 
|---|
| 523 | //****************************************************************************** | 
|---|
| 524 | BOOL OSLibPostMessageDirect(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam) | 
|---|
| 525 | { | 
|---|
| 526 | return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam); | 
|---|
| 527 | } | 
|---|
| 528 | //****************************************************************************** | 
|---|
| 529 | BOOL    _System _O32_PostThreadMessage( DWORD, UINT, WPARAM, LPARAM ); | 
|---|
| 530 |  | 
|---|
| 531 | inline BOOL O32_PostThreadMessage(DWORD a, UINT b, WPARAM c, LPARAM d) | 
|---|
| 532 | { | 
|---|
| 533 | BOOL yyrc; | 
|---|
| 534 | USHORT sel = RestoreOS2FS(); | 
|---|
| 535 |  | 
|---|
| 536 | yyrc = _O32_PostThreadMessage(a, b, c, d); | 
|---|
| 537 | SetFS(sel); | 
|---|
| 538 |  | 
|---|
| 539 | return yyrc; | 
|---|
| 540 | } | 
|---|
| 541 | //****************************************************************************** | 
|---|
| 542 | BOOL OSLibPostThreadMessage(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode) | 
|---|
| 543 | { | 
|---|
| 544 | TEB *teb = GetTEBFromThreadId(threadid); | 
|---|
| 545 | POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET)); | 
|---|
| 546 | BOOL ret; | 
|---|
| 547 |  | 
|---|
| 548 | if(NULL == packet) | 
|---|
| 549 | { | 
|---|
| 550 | dprintf(("user32::oslibmsg::OSLibPostMessage - allocated packet structure is NULL, heapmin=%d\n", | 
|---|
| 551 | _sheapmin() )); | 
|---|
| 552 |  | 
|---|
| 553 | DebugInt3(); | 
|---|
| 554 | // PH: we can provide a correct returncode | 
|---|
| 555 | return FALSE; | 
|---|
| 556 | } | 
|---|
| 557 |  | 
|---|
| 558 | if(teb == NULL) { | 
|---|
| 559 | dprintf(("OSLibPostThreadMessage: thread %x not found!", threadid)); | 
|---|
| 560 | return FALSE; | 
|---|
| 561 | } | 
|---|
| 562 | dprintf(("PostThreadMessageA %x %x %x %x -> hmq %x", threadid, msg, wParam, lParam, teb->o.odin.hmq)); | 
|---|
| 563 | packet->wParam   = wParam; | 
|---|
| 564 | packet->lParam   = lParam; | 
|---|
| 565 |  | 
|---|
| 566 | ret = WinPostQueueMsg((HMQ)teb->o.odin.hmq, WIN32APP_POSTMSG+msg, | 
|---|
| 567 | (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), | 
|---|
| 568 | (MPARAM)packet); | 
|---|
| 569 |  | 
|---|
| 570 | if(ret == FALSE) | 
|---|
| 571 | { | 
|---|
| 572 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 573 | return FALSE; | 
|---|
| 574 | } | 
|---|
| 575 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 576 | return TRUE; | 
|---|
| 577 | } | 
|---|
| 578 | //****************************************************************************** | 
|---|
| 579 | //****************************************************************************** | 
|---|
| 580 |  | 
|---|