| 1 | /* $Id: oslibmsg.cpp,v 1.30 2000-03-13 13:10:46 sandervl Exp $ */ | 
|---|
| 2 | /* | 
|---|
| 3 | * Window message translation functions for OS/2 | 
|---|
| 4 | * | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl) | 
|---|
| 7 | * | 
|---|
| 8 | * | 
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 10 | * | 
|---|
| 11 | * TODO: Some messages that are sent to the frame window are directly passed on to the client | 
|---|
| 12 | *       -> Get/PeekMessage never gets them as we return a dummy message for non-client windows | 
|---|
| 13 | *       (i.e. menu WM_COMMAND messages) | 
|---|
| 14 | * | 
|---|
| 15 | * TODO: Filter translation isn't correct! (for posted messages or messages that don't have | 
|---|
| 16 | *       a PM version. | 
|---|
| 17 | * | 
|---|
| 18 | */ | 
|---|
| 19 | #define  INCL_WIN | 
|---|
| 20 | #define  INCL_PM | 
|---|
| 21 | #define  INCL_DOSPROCESS | 
|---|
| 22 | #include <os2wrap.h> | 
|---|
| 23 | #include <string.h> | 
|---|
| 24 | #include <misc.h> | 
|---|
| 25 | #include "oslibmsg.h" | 
|---|
| 26 | #include <winconst.h> | 
|---|
| 27 | #include <win32wnd.h> | 
|---|
| 28 | #include "oslibutil.h" | 
|---|
| 29 | #include "timer.h" | 
|---|
| 30 | #include <thread.h> | 
|---|
| 31 | #include <wprocess.h> | 
|---|
| 32 | #include "pmwindow.h" | 
|---|
| 33 | #include "oslibwin.h" | 
|---|
| 34 | #include <win\hook.h> | 
|---|
| 35 |  | 
|---|
| 36 | #define DBG_LOCALLOG    DBG_oslibmsg | 
|---|
| 37 | #include "dbglocal.h" | 
|---|
| 38 |  | 
|---|
| 39 | typedef BOOL (EXPENTRY FNTRANS)(MSG *, QMSG *); | 
|---|
| 40 | typedef FNTRANS *PFNTRANS; | 
|---|
| 41 |  | 
|---|
| 42 | typedef struct | 
|---|
| 43 | { | 
|---|
| 44 | ULONG   msgOS2; | 
|---|
| 45 | ULONG   msgWin32; | 
|---|
| 46 | // PFNTRANS toOS2; | 
|---|
| 47 | // PFNTRANS toWIN32; | 
|---|
| 48 | } MSGTRANSTAB, *PMSGTRANSTAB; | 
|---|
| 49 |  | 
|---|
| 50 | //NOTE: Must be ordered by win32 message id!! | 
|---|
| 51 | MSGTRANSTAB MsgTransTab[] = { | 
|---|
| 52 | WM_NULL,          WINWM_NULL, | 
|---|
| 53 | WM_CREATE,        WINWM_CREATE, | 
|---|
| 54 | WM_DESTROY,       WINWM_DESTROY, | 
|---|
| 55 | WM_MOVE,          WINWM_MOVE,            //TODO: Sent directly | 
|---|
| 56 | WM_SIZE,          WINWM_SIZE,            //TODO: Sent directly | 
|---|
| 57 | WM_ACTIVATE,      WINWM_ACTIVATE, | 
|---|
| 58 | WM_SETFOCUS,      WINWM_SETFOCUS, | 
|---|
| 59 | WM_SETFOCUS,      WINWM_KILLFOCUS, | 
|---|
| 60 | WM_ENABLE,        WINWM_ENABLE, | 
|---|
| 61 | WM_PAINT,         WINWM_PAINT, | 
|---|
| 62 | WM_CLOSE,         WINWM_CLOSE, | 
|---|
| 63 | WM_QUIT,          WINWM_QUIT, | 
|---|
| 64 | WM_SHOW,          WINWM_SHOWWINDOW, | 
|---|
| 65 |  | 
|---|
| 66 | WM_HITTEST,       WINWM_NCHITTEST, | 
|---|
| 67 |  | 
|---|
| 68 | //TODO: Needs better translation! | 
|---|
| 69 | WM_CHAR,          WINWM_KEYDOWN, | 
|---|
| 70 | WM_CHAR,          WINWM_KEYUP, | 
|---|
| 71 | WM_CHAR,          WINWM_CHAR, | 
|---|
| 72 | WM_CHAR,          WINWM_DEADCHAR, | 
|---|
| 73 | WM_CHAR,          WINWM_SYSKEYDOWN, | 
|---|
| 74 | WM_CHAR,          WINWM_SYSKEYUP, | 
|---|
| 75 | WM_CHAR,          WINWM_SYSCHAR, | 
|---|
| 76 | WM_CHAR,          WINWM_SYSDEADCHAR, | 
|---|
| 77 | WM_CHAR,          WINWM_KEYLAST, | 
|---|
| 78 |  | 
|---|
| 79 | WM_COMMAND,       WINWM_COMMAND, | 
|---|
| 80 | WM_SYSCOMMAND,    WINWM_SYSCOMMAND, | 
|---|
| 81 | // | 
|---|
| 82 | WM_TIMER,         WINWM_TIMER, | 
|---|
| 83 | WM_INITMENU,      WINWM_INITMENU, | 
|---|
| 84 | // | 
|---|
| 85 | WM_MOUSEMOVE,     WINWM_MOUSEMOVE, | 
|---|
| 86 | WM_BUTTON1DOWN,   WINWM_LBUTTONDOWN, | 
|---|
| 87 | WM_BUTTON1UP,     WINWM_LBUTTONUP, | 
|---|
| 88 | WM_BUTTON1DBLCLK, WINWM_LBUTTONDBLCLK, | 
|---|
| 89 | WM_BUTTON2DOWN,   WINWM_RBUTTONDOWN, | 
|---|
| 90 | WM_BUTTON2UP,     WINWM_RBUTTONUP, | 
|---|
| 91 | WM_BUTTON2DBLCLK, WINWM_RBUTTONDBLCLK, | 
|---|
| 92 | WM_BUTTON3DOWN,   WINWM_MBUTTONDOWN, | 
|---|
| 93 | WM_BUTTON3UP,     WINWM_MBUTTONUP, | 
|---|
| 94 | WM_BUTTON3DBLCLK, WINWM_MBUTTONDBLCLK, | 
|---|
| 95 |  | 
|---|
| 96 | 999999999,        999999999, | 
|---|
| 97 | }; | 
|---|
| 98 | #define MAX_MSGTRANSTAB (sizeof(MsgTransTab)/sizeof(MsgTransTab[0])) | 
|---|
| 99 |  | 
|---|
| 100 | QMSG *MsgThreadPtr = 0; | 
|---|
| 101 |  | 
|---|
| 102 | LRESULT WIN32API SendMessageA(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); | 
|---|
| 103 |  | 
|---|
| 104 | //****************************************************************************** | 
|---|
| 105 | //****************************************************************************** | 
|---|
| 106 | BOOL OSLibInitMsgQueue() | 
|---|
| 107 | { | 
|---|
| 108 | if(DosAllocThreadLocalMemory(sizeof(QMSG)/sizeof(ULONG), (PULONG *)&MsgThreadPtr) != 0) | 
|---|
| 109 | { | 
|---|
| 110 | dprintf(("OSLibInitMsgQueue: local thread memory alloc failed!!")); | 
|---|
| 111 | DebugInt3(); | 
|---|
| 112 | return FALSE; | 
|---|
| 113 | } | 
|---|
| 114 | return TRUE; | 
|---|
| 115 | } | 
|---|
| 116 | //****************************************************************************** | 
|---|
| 117 | //****************************************************************************** | 
|---|
| 118 | void WinToOS2MsgTranslate(MSG *winMsg, QMSG *os2Msg, BOOL isUnicode) | 
|---|
| 119 | { | 
|---|
| 120 | //  memcpy(os2Msg, winMsg, sizeof(MSG)); | 
|---|
| 121 | //  os2Msg->hwnd = Win32Window::Win32ToOS2Handle(winMsg->hwnd); | 
|---|
| 122 | //  os2Msg->reserved = 0; | 
|---|
| 123 | } | 
|---|
| 124 | //****************************************************************************** | 
|---|
| 125 | //TODO: NOT COMPLETE nor 100% CORRECT!!! | 
|---|
| 126 | //If both the minimum & maximum message are unknown, the result can be wrong (max > min)! | 
|---|
| 127 | //****************************************************************************** | 
|---|
| 128 | ULONG TranslateWinMsg(ULONG msg, BOOL fMinFilter) | 
|---|
| 129 | { | 
|---|
| 130 | if(msg == 0) | 
|---|
| 131 | return 0; | 
|---|
| 132 |  | 
|---|
| 133 | if(msg >= WINWM_USER) | 
|---|
| 134 | return WIN32APP_POSTMSG; | 
|---|
| 135 |  | 
|---|
| 136 | for(int i=0;i<MAX_MSGTRANSTAB;i++) | 
|---|
| 137 | { | 
|---|
| 138 | if(fMinFilter && MsgTransTab[i].msgWin32 >= msg) { | 
|---|
| 139 | return MsgTransTab[i].msgOS2; | 
|---|
| 140 | } | 
|---|
| 141 | else | 
|---|
| 142 | if(!fMinFilter && MsgTransTab[i].msgWin32 >= msg) { | 
|---|
| 143 | if(MsgTransTab[i].msgWin32 == msg) | 
|---|
| 144 | return MsgTransTab[i].msgOS2; | 
|---|
| 145 | else    return MsgTransTab[i-1].msgOS2; | 
|---|
| 146 | } | 
|---|
| 147 | } | 
|---|
| 148 |  | 
|---|
| 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 | THDB *thdb; | 
|---|
| 165 | QMSG  os2msg; | 
|---|
| 166 | LONG  rc; | 
|---|
| 167 |  | 
|---|
| 168 | thdb = GetThreadTHDB(); | 
|---|
| 169 | if(thdb == 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(msg->time == MsgThreadPtr->time || msg->hwnd == 0) { | 
|---|
| 178 | memcpy(&os2msg, MsgThreadPtr, sizeof(QMSG)); | 
|---|
| 179 | MsgThreadPtr->time = -1; | 
|---|
| 180 | if(msg->hwnd) { | 
|---|
| 181 | thdb->nrOfMsgs = 1; | 
|---|
| 182 | thdb->msgstate++; //odd -> next call to our PM window handler should dispatch the translated msg | 
|---|
| 183 | memcpy(&thdb->msg, msg, sizeof(MSG)); | 
|---|
| 184 | } | 
|---|
| 185 | if(os2msg.hwnd || os2msg.msg == WM_QUIT) { | 
|---|
| 186 | return (LONG)WinDispatchMsg(thdb->hab, &os2msg); | 
|---|
| 187 | } | 
|---|
| 188 | //SvL: Don't dispatch messages sent by PostThreadMessage (correct??) | 
|---|
| 189 | //     Or WM_TIMER msgs with no window handle or timer proc | 
|---|
| 190 | return 0; | 
|---|
| 191 |  | 
|---|
| 192 | } | 
|---|
| 193 | else {//is this allowed? | 
|---|
| 194 | //        dprintf(("WARNING: OSLibWinDispatchMsg: called with own message!")); | 
|---|
| 195 | return SendMessageA(msg->hwnd, msg->message, msg->wParam, msg->lParam); | 
|---|
| 196 | } | 
|---|
| 197 | } | 
|---|
| 198 | //****************************************************************************** | 
|---|
| 199 | //****************************************************************************** | 
|---|
| 200 | BOOL OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax, | 
|---|
| 201 | BOOL isUnicode) | 
|---|
| 202 | { | 
|---|
| 203 | BOOL rc, eaten; | 
|---|
| 204 | THDB *thdb; | 
|---|
| 205 | QMSG  os2msg; | 
|---|
| 206 |  | 
|---|
| 207 | thdb = GetThreadTHDB(); | 
|---|
| 208 | if(thdb == NULL) { | 
|---|
| 209 | DebugInt3(); | 
|---|
| 210 | return FALSE; | 
|---|
| 211 | } | 
|---|
| 212 |  | 
|---|
| 213 | if(thdb->fTranslated && (!hwnd || hwnd == thdb->msgWCHAR.hwnd)) { | 
|---|
| 214 | if(uMsgFilterMin) { | 
|---|
| 215 | if(thdb->msgWCHAR.message < uMsgFilterMin) | 
|---|
| 216 | goto continuegetmsg; | 
|---|
| 217 | } | 
|---|
| 218 | if(uMsgFilterMax) { | 
|---|
| 219 | if(thdb->msgWCHAR.message > uMsgFilterMax) | 
|---|
| 220 | goto continuegetmsg; | 
|---|
| 221 | } | 
|---|
| 222 | thdb->fTranslated = FALSE; | 
|---|
| 223 | memcpy(pMsg, &thdb->msgWCHAR, sizeof(MSG)); | 
|---|
| 224 | MsgThreadPtr->msg  = 0; | 
|---|
| 225 | MsgThreadPtr->hwnd = 0; | 
|---|
| 226 | return (pMsg->message != WINWM_QUIT); | 
|---|
| 227 | } | 
|---|
| 228 |  | 
|---|
| 229 | continuegetmsg: | 
|---|
| 230 | if(hwnd) { | 
|---|
| 231 | do { | 
|---|
| 232 | WinWaitMsg(thdb->hab, TranslateWinMsg(uMsgFilterMin, TRUE), TranslateWinMsg(uMsgFilterMax, FALSE)); | 
|---|
| 233 | rc = OSLibWinPeekMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, PM_REMOVE_W, isUnicode); | 
|---|
| 234 | } | 
|---|
| 235 | while(rc == FALSE); | 
|---|
| 236 |  | 
|---|
| 237 | return (pMsg->message != WINWM_QUIT); | 
|---|
| 238 | } | 
|---|
| 239 | else | 
|---|
| 240 | { | 
|---|
| 241 | do { | 
|---|
| 242 | eaten = FALSE; | 
|---|
| 243 | rc = WinGetMsg(thdb->hab, &os2msg, TranslateWinMsg(uMsgFilterMin, TRUE), TranslateWinMsg(uMsgFilterMax, FALSE), 0); | 
|---|
| 244 | if (os2msg.msg == WM_TIMER) | 
|---|
| 245 | eaten = TIMER_HandleTimer(&os2msg); | 
|---|
| 246 | } while (eaten); | 
|---|
| 247 | } | 
|---|
| 248 |  | 
|---|
| 249 | OS2ToWinMsgTranslate((PVOID)thdb, &os2msg, pMsg, isUnicode, MSG_REMOVE); | 
|---|
| 250 | memcpy(MsgThreadPtr, &os2msg, sizeof(QMSG)); | 
|---|
| 251 |  | 
|---|
| 252 | if(pMsg->message <= WINWM_KEYLAST && pMsg->message >= WINWM_KEYDOWN) | 
|---|
| 253 | { | 
|---|
| 254 | if(ProcessKbdHook(pMsg, TRUE)) | 
|---|
| 255 | goto continuegetmsg; | 
|---|
| 256 | } | 
|---|
| 257 | return rc; | 
|---|
| 258 | } | 
|---|
| 259 | //****************************************************************************** | 
|---|
| 260 | //PeekMessage retrieves only messages associated with the window identified by the | 
|---|
| 261 | //hwnd parameter or any of its children as specified by the IsChild function, and within | 
|---|
| 262 | //the range of message values given by the uMsgFilterMin and uMsgFilterMax | 
|---|
| 263 | //parameters. If hwnd is NULL, PeekMessage retrieves messages for any window that | 
|---|
| 264 | //belongs to the current thread making the call. (PeekMessage does not retrieve | 
|---|
| 265 | //messages for windows that belong to other threads.) If hwnd is -1, PeekMessage only | 
|---|
| 266 | //returns messages with a hwnd value of NULL, as posted by the PostAppMessage | 
|---|
| 267 | //function. If uMsgFilterMin and uMsgFilterMax are both zero, PeekMessage returns all | 
|---|
| 268 | //available messages (no range filtering is performed). | 
|---|
| 269 | //TODO: Not working as specified right now! | 
|---|
| 270 | //****************************************************************************** | 
|---|
| 271 | BOOL OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax, | 
|---|
| 272 | DWORD fRemove, BOOL isUnicode) | 
|---|
| 273 | { | 
|---|
| 274 | BOOL  rc, eaten; | 
|---|
| 275 | THDB *thdb; | 
|---|
| 276 | QMSG  os2msg; | 
|---|
| 277 |  | 
|---|
| 278 | thdb = GetThreadTHDB(); | 
|---|
| 279 | if(thdb == NULL) { | 
|---|
| 280 | DebugInt3(); | 
|---|
| 281 | return FALSE; | 
|---|
| 282 | } | 
|---|
| 283 |  | 
|---|
| 284 | if(thdb->fTranslated && (!hwnd || hwnd == thdb->msgWCHAR.hwnd)) { | 
|---|
| 285 | if(uMsgFilterMin) { | 
|---|
| 286 | if(thdb->msgWCHAR.message < uMsgFilterMin) | 
|---|
| 287 | goto continuepeekmsg; | 
|---|
| 288 | } | 
|---|
| 289 | if(uMsgFilterMax) { | 
|---|
| 290 | if(thdb->msgWCHAR.message > uMsgFilterMax) | 
|---|
| 291 | goto continuepeekmsg; | 
|---|
| 292 | } | 
|---|
| 293 |  | 
|---|
| 294 | if(fRemove & PM_REMOVE_W) { | 
|---|
| 295 | thdb->fTranslated = FALSE; | 
|---|
| 296 | MsgThreadPtr->msg  = 0; | 
|---|
| 297 | MsgThreadPtr->hwnd = 0; | 
|---|
| 298 | } | 
|---|
| 299 | memcpy(pMsg, &thdb->msgWCHAR, sizeof(MSG)); | 
|---|
| 300 | return TRUE; | 
|---|
| 301 | } | 
|---|
| 302 |  | 
|---|
| 303 | continuepeekmsg: | 
|---|
| 304 | do { | 
|---|
| 305 | eaten = FALSE; | 
|---|
| 306 | rc = WinPeekMsg(thdb->hab, &os2msg, Win32BaseWindow::OS2ToWin32Handle(hwnd), TranslateWinMsg(uMsgFilterMin, TRUE), | 
|---|
| 307 | TranslateWinMsg(uMsgFilterMax, FALSE), (fRemove & PM_REMOVE_W) ? PM_REMOVE : PM_NOREMOVE); | 
|---|
| 308 |  | 
|---|
| 309 | if (rc && (fRemove & PM_REMOVE_W) && os2msg.msg == WM_TIMER) { | 
|---|
| 310 | eaten = TIMER_HandleTimer(&os2msg); | 
|---|
| 311 | } | 
|---|
| 312 | } | 
|---|
| 313 | while (eaten && rc); | 
|---|
| 314 |  | 
|---|
| 315 | if(rc == FALSE) { | 
|---|
| 316 | return FALSE; | 
|---|
| 317 | } | 
|---|
| 318 |  | 
|---|
| 319 | OS2ToWinMsgTranslate((PVOID)thdb, &os2msg, pMsg, isUnicode, (fRemove & PM_REMOVE_W) ? MSG_REMOVE : MSG_NOREMOVE); | 
|---|
| 320 | //TODO: This is not safe! There's no guarantee this message will be dispatched and it might overwrite a previous message | 
|---|
| 321 | if(fRemove & PM_REMOVE_W) { | 
|---|
| 322 | memcpy(MsgThreadPtr, &os2msg, sizeof(QMSG)); | 
|---|
| 323 | } | 
|---|
| 324 |  | 
|---|
| 325 | if(pMsg->message <= WINWM_KEYLAST && pMsg->message >= WINWM_KEYDOWN) | 
|---|
| 326 | { | 
|---|
| 327 | if(ProcessKbdHook(pMsg, fRemove)) | 
|---|
| 328 | goto continuepeekmsg; | 
|---|
| 329 | } | 
|---|
| 330 |  | 
|---|
| 331 | return rc; | 
|---|
| 332 | } | 
|---|
| 333 | //****************************************************************************** | 
|---|
| 334 | //****************************************************************************** | 
|---|
| 335 | ULONG OSLibWinQueryMsgTime() | 
|---|
| 336 | { | 
|---|
| 337 | return WinQueryMsgTime(GetThreadHAB()); | 
|---|
| 338 | } | 
|---|
| 339 | //****************************************************************************** | 
|---|
| 340 | //****************************************************************************** | 
|---|
| 341 | BOOL OSLibWinWaitMessage() | 
|---|
| 342 | { | 
|---|
| 343 | return WinWaitMsg(GetThreadHAB(), 0, 0); | 
|---|
| 344 | } | 
|---|
| 345 | //****************************************************************************** | 
|---|
| 346 | //TODO: QS_HOTKEY | 
|---|
| 347 | //****************************************************************************** | 
|---|
| 348 | ULONG OSLibWinQueryQueueStatus() | 
|---|
| 349 | { | 
|---|
| 350 | ULONG statusOS2, statusWin32 = 0; | 
|---|
| 351 |  | 
|---|
| 352 | statusOS2 = WinQueryQueueStatus(HWND_DESKTOP); | 
|---|
| 353 |  | 
|---|
| 354 | if(statusOS2 & QS_KEY) | 
|---|
| 355 | statusWin32 |= QS_KEY_W; | 
|---|
| 356 | if(statusOS2 & QS_MOUSEBUTTON) | 
|---|
| 357 | statusWin32 |= QS_MOUSEBUTTON_W; | 
|---|
| 358 | if(statusOS2 & QS_MOUSEMOVE) | 
|---|
| 359 | statusWin32 |= QS_MOUSEMOVE_W; | 
|---|
| 360 | if(statusOS2 & QS_TIMER) | 
|---|
| 361 | statusWin32 |= QS_TIMER_W; | 
|---|
| 362 | if(statusOS2 & QS_PAINT) | 
|---|
| 363 | statusWin32 |= QS_PAINT_W; | 
|---|
| 364 | if(statusOS2 & QS_POSTMSG) | 
|---|
| 365 | statusWin32 |= QS_POSTMESSAGE_W; | 
|---|
| 366 | if(statusOS2 & QS_SENDMSG) | 
|---|
| 367 | statusWin32 |= QS_SENDMESSAGE_W; | 
|---|
| 368 |  | 
|---|
| 369 | return statusWin32; | 
|---|
| 370 | } | 
|---|
| 371 | //****************************************************************************** | 
|---|
| 372 | //****************************************************************************** | 
|---|
| 373 | BOOL OSLibWinInSendMessage() | 
|---|
| 374 | { | 
|---|
| 375 | return WinInSendMsg(GetThreadHAB()); | 
|---|
| 376 | } | 
|---|
| 377 | //****************************************************************************** | 
|---|
| 378 | //****************************************************************************** | 
|---|
| 379 | DWORD OSLibWinGetMessagePos() | 
|---|
| 380 | { | 
|---|
| 381 | APIRET rc; | 
|---|
| 382 | POINTL ptl; | 
|---|
| 383 |  | 
|---|
| 384 | rc = WinQueryMsgPos(GetThreadHAB(), &ptl); | 
|---|
| 385 | if(!rc) { | 
|---|
| 386 | return 0; | 
|---|
| 387 | } | 
|---|
| 388 | //convert to windows coordinates | 
|---|
| 389 | return MAKEULONG(ptl.x,mapScreenY(ptl.y)); | 
|---|
| 390 | } | 
|---|
| 391 | //****************************************************************************** | 
|---|
| 392 | //****************************************************************************** | 
|---|
| 393 | LONG OSLibWinGetMessageTime() | 
|---|
| 394 | { | 
|---|
| 395 | return (LONG)WinQueryMsgTime(GetThreadHAB()); | 
|---|
| 396 | } | 
|---|
| 397 | //****************************************************************************** | 
|---|
| 398 | //****************************************************************************** | 
|---|
| 399 | BOOL OSLibWinReplyMessage(ULONG result) | 
|---|
| 400 | { | 
|---|
| 401 | return (BOOL)WinReplyMsg( NULLHANDLE, NULLHANDLE, HMQ_CURRENT, (MRESULT)result); | 
|---|
| 402 | } | 
|---|
| 403 | //****************************************************************************** | 
|---|
| 404 | //****************************************************************************** | 
|---|
| 405 | ULONG OSLibSendMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode) | 
|---|
| 406 | { | 
|---|
| 407 | POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET)); | 
|---|
| 408 |  | 
|---|
| 409 | packet->Msg    = msg; | 
|---|
| 410 | packet->wParam = wParam; | 
|---|
| 411 | packet->lParam = lParam; | 
|---|
| 412 |  | 
|---|
| 413 | return (ULONG)WinSendMsg(hwnd, WIN32APP_POSTMSG, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet); | 
|---|
| 414 | } | 
|---|
| 415 | //****************************************************************************** | 
|---|
| 416 | //****************************************************************************** | 
|---|
| 417 | ULONG OSLibWinBroadcastMsg(ULONG msg, ULONG wParam, ULONG lParam, BOOL fSend) | 
|---|
| 418 | { | 
|---|
| 419 | return WinBroadcastMsg(HWND_DESKTOP, msg, (MPARAM)wParam, (MPARAM)lParam, | 
|---|
| 420 | (fSend) ? BMSG_SEND : BMSG_POST); | 
|---|
| 421 | } | 
|---|
| 422 | //****************************************************************************** | 
|---|
| 423 | //****************************************************************************** | 
|---|
| 424 | BOOL OSLibPostMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode) | 
|---|
| 425 | { | 
|---|
| 426 | POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET)); | 
|---|
| 427 |  | 
|---|
| 428 | packet->Msg = msg; | 
|---|
| 429 | packet->wParam = wParam; | 
|---|
| 430 | packet->lParam = lParam; | 
|---|
| 431 | return WinPostMsg(hwnd, WIN32APP_POSTMSG, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet); | 
|---|
| 432 | } | 
|---|
| 433 | //****************************************************************************** | 
|---|
| 434 | BOOL    _System _O32_PostThreadMessage( DWORD, UINT, WPARAM, LPARAM ); | 
|---|
| 435 |  | 
|---|
| 436 | inline BOOL O32_PostThreadMessage(DWORD a, UINT b, WPARAM c, LPARAM d) | 
|---|
| 437 | { | 
|---|
| 438 | BOOL yyrc; | 
|---|
| 439 | USHORT sel = RestoreOS2FS(); | 
|---|
| 440 |  | 
|---|
| 441 | yyrc = _O32_PostThreadMessage(a, b, c, d); | 
|---|
| 442 | SetFS(sel); | 
|---|
| 443 |  | 
|---|
| 444 | return yyrc; | 
|---|
| 445 | } | 
|---|
| 446 | //****************************************************************************** | 
|---|
| 447 | BOOL OSLibPostThreadMessage(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode) | 
|---|
| 448 | { | 
|---|
| 449 | // THDB *thdb = GetTHDBFromThreadId(threadid); | 
|---|
| 450 | POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET)); | 
|---|
| 451 |  | 
|---|
| 452 | //    if(thdb == NULL) { | 
|---|
| 453 | //        dprintf(("OSLibPostThreadMessage: thread %x not found!", threadid)); | 
|---|
| 454 | //        return FALSE; | 
|---|
| 455 | //    } | 
|---|
| 456 | dprintf(("PostThreadMessageA %x %x %x %x", threadid, msg, wParam, lParam)); | 
|---|
| 457 | packet->Msg = msg; | 
|---|
| 458 | packet->wParam = wParam; | 
|---|
| 459 | packet->lParam = lParam; | 
|---|
| 460 | return O32_PostThreadMessage(threadid, WIN32APP_POSTMSG-OPEN32_MSGDIFF, ((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (LPARAM)packet); | 
|---|
| 461 | } | 
|---|
| 462 | //****************************************************************************** | 
|---|
| 463 | //****************************************************************************** | 
|---|
| 464 |  | 
|---|