| 1 | /* $Id: oslibmsg.cpp,v 1.4 1999-10-15 10:03:14 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: Simply copy for now. Need to make a real translation
|
|---|
| 12 | *
|
|---|
| 13 | */
|
|---|
| 14 | #define INCL_WIN
|
|---|
| 15 | #define INCL_PM
|
|---|
| 16 | #define INCL_DOSPROCESS
|
|---|
| 17 | #include <os2.h>
|
|---|
| 18 | #include <os2wrap.h>
|
|---|
| 19 | #include <string.h>
|
|---|
| 20 | #include <misc.h>
|
|---|
| 21 | #include "oslibmsg.h"
|
|---|
| 22 | #include <win32wnd.h>
|
|---|
| 23 | #include "oslibutil.h"
|
|---|
| 24 | #include "timer.h"
|
|---|
| 25 | #include <thread.h>
|
|---|
| 26 | #include <wprocess.h>
|
|---|
| 27 |
|
|---|
| 28 | typedef BOOL (EXPENTRY FNTRANS)(MSG *, QMSG *);
|
|---|
| 29 | typedef FNTRANS *PFNTRANS;
|
|---|
| 30 |
|
|---|
| 31 | typedef struct
|
|---|
| 32 | {
|
|---|
| 33 | ULONG msgOS2;
|
|---|
| 34 | ULONG msgWin32;
|
|---|
| 35 | // PFNTRANS toOS2;
|
|---|
| 36 | // PFNTRANS toWIN32;
|
|---|
| 37 | } MSGTRANSTAB, *PMSGTRANSTAB;
|
|---|
| 38 |
|
|---|
| 39 | #define MAX_MSGTRANSTAB 12
|
|---|
| 40 | MSGTRANSTAB MsgTransTab[MAX_MSGTRANSTAB] = {
|
|---|
| 41 | 0x0000, 0x0000, // WM_NULL, WM_NULL
|
|---|
| 42 | 0x0070, 0x0200, // WM_MOUSEMOVE, WM_MOUSEMOVE
|
|---|
| 43 | 0x0071, 0x0201, // WM_BUTTON1DOWN, WM_LBUTTONDOWN
|
|---|
| 44 | 0x0072, 0x0202, // WM_BUTTON1UP, WM_LBUTTONUP
|
|---|
| 45 | 0x0073, 0x0203, // WM_BUTTON1DBLCLK, WM_LBUTTONDBLCLK
|
|---|
| 46 | 0x0074, 0x0204, // WM_BUTTON2DOWN, WM_RBUTTONDOWN
|
|---|
| 47 | 0x0075, 0x0205, // WM_BUTTON2UP, WM_RBUTTONUP
|
|---|
| 48 | 0x0076, 0x0206, // WM_BUTTON2DBLCLK, WM_RBUTTONDBLCLK
|
|---|
| 49 | 0x0077, 0x0207, // WM_BUTTON3DOWN, WM_MBUTTONDOWN
|
|---|
| 50 | 0x0078, 0x0208, // WM_BUTTON3UP, WM_MBUTTONUP
|
|---|
| 51 | 0x0079, 0x0209, // WM_BUTTON3DBLCLK, WM_MBUTTONDBLCLK
|
|---|
| 52 | 0x020a, 0x020a, // WM_???, WM_???
|
|---|
| 53 | };
|
|---|
| 54 |
|
|---|
| 55 | QMSG *MsgThreadPtr = 0;
|
|---|
| 56 |
|
|---|
| 57 | //******************************************************************************
|
|---|
| 58 | //******************************************************************************
|
|---|
| 59 | BOOL OSLibInitMsgQueue()
|
|---|
| 60 | {
|
|---|
| 61 | if(DosAllocThreadLocalMemory(sizeof(QMSG)/sizeof(ULONG), (PULONG *)&MsgThreadPtr) != 0)
|
|---|
| 62 | {
|
|---|
| 63 | dprintf(("OSLibInitMsgQueue: local thread memory alloc failed!!"));
|
|---|
| 64 | DebugInt3();
|
|---|
| 65 | return FALSE;
|
|---|
| 66 | }
|
|---|
| 67 | return TRUE;
|
|---|
| 68 | }
|
|---|
| 69 | //******************************************************************************
|
|---|
| 70 | //******************************************************************************
|
|---|
| 71 | void WinToOS2MsgTranslate(MSG *winMsg, QMSG *os2Msg, BOOL isUnicode)
|
|---|
| 72 | {
|
|---|
| 73 | int i;
|
|---|
| 74 |
|
|---|
| 75 | memcpy(os2Msg, winMsg, sizeof(MSG));
|
|---|
| 76 | os2Msg->hwnd = Win32Window::Win32ToOS2Handle(winMsg->hwnd);
|
|---|
| 77 | os2Msg->reserved = 0;
|
|---|
| 78 | for(i=0;i<MAX_MSGTRANSTAB;i++)
|
|---|
| 79 | {
|
|---|
| 80 | if(MsgTransTab[i].msgWin32 == winMsg->message)
|
|---|
| 81 | {
|
|---|
| 82 | os2Msg->msg = MsgTransTab[i].msgOS2;
|
|---|
| 83 | break;
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 | }
|
|---|
| 87 | //******************************************************************************
|
|---|
| 88 | //******************************************************************************
|
|---|
| 89 | void OS2ToWinMsgTranslate(QMSG *os2Msg, MSG *winMsg, BOOL isUnicode)
|
|---|
| 90 | {
|
|---|
| 91 | int i;
|
|---|
| 92 |
|
|---|
| 93 | memcpy(winMsg, os2Msg, sizeof(MSG));
|
|---|
| 94 | winMsg->hwnd = Win32Window::OS2ToWin32Handle(os2Msg->hwnd);
|
|---|
| 95 | for(i=0;i<MAX_MSGTRANSTAB;i++)
|
|---|
| 96 | {
|
|---|
| 97 | if(MsgTransTab[i].msgOS2 == os2Msg->msg)
|
|---|
| 98 | {
|
|---|
| 99 | winMsg->message = MsgTransTab[i].msgWin32;
|
|---|
| 100 | break;
|
|---|
| 101 | }
|
|---|
| 102 | }
|
|---|
| 103 | }
|
|---|
| 104 | //******************************************************************************
|
|---|
| 105 | //TODO!!!
|
|---|
| 106 | //Signal that the incoming messages in pmwindow need to be translated
|
|---|
| 107 | //(i.e. PM WM_CHAR when translated generates WM_CHAR messages, otherwise
|
|---|
| 108 | // WM_KEYUP/DOWN (etc))
|
|---|
| 109 | //******************************************************************************
|
|---|
| 110 | ULONG TranslateWinMsg(ULONG msg)
|
|---|
| 111 | {
|
|---|
| 112 | THDB *thdb;
|
|---|
| 113 |
|
|---|
| 114 | thdb = GetThreadTHDB();
|
|---|
| 115 | if(thdb) {
|
|---|
| 116 | thdb->fMsgTranslated = TRUE;
|
|---|
| 117 | }
|
|---|
| 118 |
|
|---|
| 119 | for(int i=0;i<MAX_MSGTRANSTAB;i++)
|
|---|
| 120 | {
|
|---|
| 121 | if(MsgTransTab[i].msgWin32 == msg)
|
|---|
| 122 | {
|
|---|
| 123 | return MsgTransTab[i].msgOS2;
|
|---|
| 124 | }
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | return 0;
|
|---|
| 128 | }
|
|---|
| 129 | //******************************************************************************
|
|---|
| 130 | //******************************************************************************
|
|---|
| 131 | void OSLibWinPostQuitMessage(ULONG nExitCode)
|
|---|
| 132 | {
|
|---|
| 133 | WinPostQueueMsg(NULLHANDLE, WM_QUIT, (MPARAM)nExitCode, 0);
|
|---|
| 134 | }
|
|---|
| 135 | //******************************************************************************
|
|---|
| 136 | //******************************************************************************
|
|---|
| 137 | LONG OSLibWinDispatchMsg(MSG *msg, BOOL isUnicode)
|
|---|
| 138 | {
|
|---|
| 139 | //TODO: What to do if app changed msg? (translate)
|
|---|
| 140 | // WinToOS2MsgTranslate(msg, &qmsg, isUnicode);
|
|---|
| 141 |
|
|---|
| 142 | return (LONG)WinDispatchMsg(GetThreadHAB(), MsgThreadPtr);
|
|---|
| 143 | }
|
|---|
| 144 | //******************************************************************************
|
|---|
| 145 | //******************************************************************************
|
|---|
| 146 | BOOL OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
|
|---|
| 147 | BOOL isUnicode)
|
|---|
| 148 | {
|
|---|
| 149 | BOOL rc, eaten;
|
|---|
| 150 |
|
|---|
| 151 | do {
|
|---|
| 152 | eaten = FALSE;
|
|---|
| 153 | rc = WinGetMsg(GetThreadHAB(), MsgThreadPtr, TranslateWinMsg(uMsgFilterMin), TranslateWinMsg(uMsgFilterMax), 0);
|
|---|
| 154 | if (MsgThreadPtr->msg == WM_TIMER)
|
|---|
| 155 | eaten = TIMER_HandleTimer (MsgThreadPtr);
|
|---|
| 156 | } while (eaten);
|
|---|
| 157 |
|
|---|
| 158 | OS2ToWinMsgTranslate(MsgThreadPtr, pMsg, isUnicode);
|
|---|
| 159 | return rc;
|
|---|
| 160 | }
|
|---|
| 161 | //******************************************************************************
|
|---|
| 162 | //******************************************************************************
|
|---|
| 163 | BOOL OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
|
|---|
| 164 | BOOL fRemove, BOOL isUnicode)
|
|---|
| 165 | {
|
|---|
| 166 | BOOL rc;
|
|---|
| 167 |
|
|---|
| 168 | rc = WinPeekMsg(GetThreadHAB(), MsgThreadPtr, hwnd, TranslateWinMsg(uMsgFilterMin),
|
|---|
| 169 | TranslateWinMsg(uMsgFilterMax), (fRemove == MSG_REMOVE) ? PM_REMOVE : PM_NOREMOVE);
|
|---|
| 170 | OS2ToWinMsgTranslate(MsgThreadPtr, pMsg, isUnicode);
|
|---|
| 171 | return rc;
|
|---|
| 172 | }
|
|---|
| 173 | //******************************************************************************
|
|---|
| 174 | //******************************************************************************
|
|---|