Ignore:
Timestamp:
Sep 27, 2001, 12:02:38 PM (24 years ago)
Author:
phaller
Message:

implemented SendInput

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/user32/winmouse.cpp

    r6395 r6846  
    1 /* $Id: winmouse.cpp,v 1.16 2001-07-28 13:43:54 sandervl Exp $ */
     1/* $Id: winmouse.cpp,v 1.17 2001-09-27 10:02:38 phaller Exp $ */
    22/*
    33 * Mouse handler for DINPUT
     
    1212 *
    1313 */
     14
     15#include <odin.h>
     16#include <odinwrap.h>
     17#include <os2sel.h>
     18
    1419#include <os2win.h>
    1520#include <misc.h>
    1621#include "win32wbase.h"
    1722#include <winuser32.h>
     23#include <winuser.h>
    1824#include <win\mouse.h>
    1925#include "winmouse.h"
     
    2531#include "dbglocal.h"
    2632
     33
     34ODINDEBUGCHANNEL(USER32-WINMOUSE)
     35
     36
     37/****************************************************************************
     38 * local variables
     39 ****************************************************************************/
     40
    2741LPMOUSE_EVENT_PROC mouseHandler = NULL;
    2842WNDPROC            keyboardHandler = NULL;
    2943
    30 //******************************************************************************
    31 //******************************************************************************
    32 VOID WIN32API MOUSE_Enable(LPMOUSE_EVENT_PROC lpMouseEventProc)
     44
     45//******************************************************************************
     46//******************************************************************************
     47ODINPROCEDURE1(MOUSE_Enable,
     48               LPMOUSE_EVENT_PROC, lpMouseEventProc)
    3349{
    3450  if(lpMouseEventProc == (LPMOUSE_EVENT_PROC)-1)
    35   {
    36         mouseHandler = NULL;
    37   }
    38   else  mouseHandler = lpMouseEventProc;
    39 }
    40 //******************************************************************************
    41 //******************************************************************************
    42 VOID WIN32API KEYBOARD_Enable(WNDPROC handler)
     51    mouseHandler = NULL;
     52  else 
     53    mouseHandler = lpMouseEventProc;
     54}
     55//******************************************************************************
     56//******************************************************************************
     57ODINPROCEDURE1(KEYBOARD_Enable,
     58               WNDPROC, handler)
    4359{
    4460  keyboardHandler = handler;
     
    109125//******************************************************************************
    110126//******************************************************************************
    111 HWND WIN32API GetCapture(void)
    112 {
    113  HWND hwnd;
    114 
    115     hwnd = OS2ToWin32Handle(OSLibWinQueryCapture());
    116     dprintf(("USER32: GetCapture returned %x", hwnd));
    117     return hwnd;
    118 }
    119 //******************************************************************************
    120 //******************************************************************************
    121 HWND WIN32API SetCapture(HWND hwnd)
    122 {
    123  HWND hwndPrev = GetCapture();
    124  BOOL rc;
    125 
    126     if(hwnd == 0) {
    127         ReleaseCapture();
    128         return hwndPrev;
    129     }
    130     if(hwnd == hwndPrev) {
    131         dprintf(("USER32: SetCapture %x; already set to that window; ignore", hwnd));
    132         return hwndPrev;
    133     }
    134     if(hwndPrev != NULL) {
    135         //SvL: WinSetCapture returns an error if mouse is already captured
    136         OSLibWinSetCapture(0);
    137     }
    138     rc = OSLibWinSetCapture(Win32ToOS2Handle(hwnd));
    139     dprintf(("USER32: SetCapture %x (prev %x) returned %d", hwnd, hwndPrev, rc));
    140     if(hwndPrev) {
    141         SendMessageA(hwndPrev, WM_CAPTURECHANGED, 0L, hwnd);
    142     }
     127ODINFUNCTION0(HWND, GetCapture)
     128{
     129  return OS2ToWin32Handle(OSLibWinQueryCapture());
     130}
     131//******************************************************************************
     132//******************************************************************************
     133ODINFUNCTION1(HWND, SetCapture,
     134              HWND, hwnd)
     135{
     136  HWND hwndPrev = GetCapture();
     137  BOOL rc;
     138
     139  if(hwnd == 0)
     140  {
     141    ReleaseCapture();
    143142    return hwndPrev;
    144 }
    145 //******************************************************************************
    146 //******************************************************************************
    147 BOOL WIN32API ReleaseCapture(void)
    148 {
    149  HWND hwndPrev;
    150  BOOL ret;
    151 
    152     dprintf(("USER32:  ReleaseCapture"));
    153     hwndPrev = GetCapture();
    154     ret = OSLibWinSetCapture(0);
    155     if(hwndPrev) {
    156         SendMessageA(hwndPrev, WM_CAPTURECHANGED, 0L, 0L);
    157     }
    158     return ret;
    159 }
    160 //******************************************************************************
    161 //******************************************************************************
    162 UINT WIN32API GetDoubleClickTime(void)
    163 {
    164     dprintf(("USER32: GetDoubleClickTime"));
    165     UINT result = OSLibWinQuerySysValue(SVOS_DBLCLKTIME);
    166     if(result == 0)
    167         SetLastError(ERROR_INVALID_PARAMETER); //TODO: ????
    168 
    169     return result;
    170 }
    171 //******************************************************************************
    172 //******************************************************************************
    173 BOOL WIN32API SetDoubleClickTime(UINT uInterval)
    174 {
    175     BOOL ret = TRUE;
    176 
    177     dprintf(("USER32: SetDoubleClickTime %d", uInterval));
    178 
    179     ret = OSLibWinSetSysValue(SVOS_DBLCLKTIME, uInterval);
    180     if(ret == FALSE )
    181     {
    182         SetLastError(ERROR_INVALID_PARAMETER); //TODO: ????
    183     }
    184     return (ret);
     143  }
     144 
     145  if(hwnd == hwndPrev)
     146  {
     147    dprintf(("USER32: SetCapture %x; already set to that window; ignore", hwnd));
     148    return hwndPrev;
     149  }
     150 
     151  if(hwndPrev != NULL)
     152  {
     153    //SvL: WinSetCapture returns an error if mouse is already captured
     154    OSLibWinSetCapture(0);
     155  }
     156 
     157  rc = OSLibWinSetCapture(Win32ToOS2Handle(hwnd));
     158  dprintf(("USER32: SetCapture %x (prev %x) returned %d", hwnd, hwndPrev, rc));
     159  if(hwndPrev)
     160  {
     161    SendMessageA(hwndPrev, WM_CAPTURECHANGED, 0L, hwnd);
     162  }
     163  return hwndPrev;
     164}
     165//******************************************************************************
     166//******************************************************************************
     167ODINFUNCTION0(BOOL, ReleaseCapture)
     168{
     169  HWND hwndPrev;
     170  BOOL ret;
     171
     172  hwndPrev = GetCapture();
     173  ret = OSLibWinSetCapture(0);
     174  if(hwndPrev)
     175  {
     176    SendMessageA(hwndPrev, WM_CAPTURECHANGED, 0L, 0L);
     177  }
     178  return ret;
     179}
     180//******************************************************************************
     181//******************************************************************************
     182ODINFUNCTION0(UINT, GetDoubleClickTime)
     183{
     184  UINT result = OSLibWinQuerySysValue(SVOS_DBLCLKTIME);
     185  if(result == 0)
     186    SetLastError(ERROR_INVALID_PARAMETER); //TODO: ????
     187
     188  return result;
     189}
     190//******************************************************************************
     191//******************************************************************************
     192ODINFUNCTION1(BOOL, SetDoubleClickTime,
     193              UINT, uInterval)
     194{
     195  BOOL ret = TRUE;
     196
     197  ret = OSLibWinSetSysValue(SVOS_DBLCLKTIME, uInterval);
     198  if(ret == FALSE )
     199  {
     200    SetLastError(ERROR_INVALID_PARAMETER); //TODO: ????
     201  }
     202  return (ret);
    185203}
    186204//******************************************************************************
     
    201219
    202220//******************************************************************************
    203 BOOL WIN32API SwapMouseButton(BOOL fSwap)
    204 {
    205     dprintf(("USER32: SwapMouseButton %d", fSwap));
    206     return _SwapMouseButton(fSwap);
    207 }
     221ODINFUNCTION1(BOOL, SwapMouseButton,
     222              BOOL, fSwap)
     223{
     224  return _SwapMouseButton(fSwap);
     225}
     226
    208227/*****************************************************************************
    209228 * Name      : VOID WIN32API mouse_event
     
    221240 * Author    : Patrick Haller [Thu, 1998/02/26 11:55]
    222241 *****************************************************************************/
    223 VOID WIN32API mouse_event(DWORD dwFlags, DWORD dx, DWORD dy, DWORD cButtons,
    224                           DWORD dwExtraInfo)
    225 {
    226   dprintf(("USER32:mouse_event (%08xh,%u,%u,%u,%08x) not implemented",
    227           dwFlags, dx, dy, cButtons, dwExtraInfo));
    228 }
    229 
    230 DWORD WIN32API TrackMouseEvent(DWORD param1)
    231 {
    232   dprintf(("USER32: TrackMouseEvent %x not implemented", param1));
     242
     243ODINPROCEDURE5(mouse_event,
     244               DWORD, dwFlags,
     245               DWORD, dx,
     246               DWORD, dy,
     247               DWORD, cButtons,
     248               DWORD, dwExtraInfo)
     249{
     250  dprintf(("not implemented"));
     251}
     252
     253
     254ODINFUNCTION1(DWORD, TrackMouseEvent,
     255              DWORD, param1)
     256{
     257  dprintf(("not implemented"));
    233258  return 0;
    234259}
    235260
    236 DWORD WIN32API SendInput(DWORD param1, DWORD param2, DWORD param3)
    237 {
    238   dprintf(("USER32: SendInput %x %x %x not implemented", param1, param2, param3));
     261
     262/*****************************************************************************
     263 * Name      : UINT SendInput
     264 * Purpose   : The SendInput function synthesizes keystrokes, mouse motions,
     265 *             and button clicks
     266 * Parameters: UINT    nInputs // count if input events
     267 *             LPINPUT pInputs // array of input structures
     268 *             int     chSize  // size of structure
     269 * Variables :
     270 * Result    : number of events successfully inserted,
     271 *             0 if the input was already blocked by another thread
     272 * Remark    :
     273 * Status    : UNTESTED STUB
     274 *
     275 * Author    : Patrick Haller [Thu, 1998/02/26 11:55]
     276 *****************************************************************************/
     277
     278ODINFUNCTION3(UINT,    SendInput,
     279              UINT,    nInputs,
     280              LPINPUT, pInputs,
     281              int,     chSize)
     282{
     283  dprintf(("not correctly implemented"));
     284 
     285  // The simulated input is sent to the
     286  // foreground thread's message queue.
     287  // (WM_KEYUP, WM_KEYDOWN)
     288  // After GetMessage or PeekMessage,
     289  // TranslateMessage posts an appropriate
     290  // WM_CHAR message.
     291  HWND hwnd = GetForegroundWindow();
     292 
     293  LPINPUT piBase = pInputs;
     294  for (int i = 0;
     295       i < nInputs;
     296       i++,
     297       piBase++)
     298  {
     299    switch(piBase->type)
     300    {
     301      case INPUT_MOUSE:
     302      {
     303        PMOUSEINPUT p = (PMOUSEINPUT)&piBase->mi;
     304        MSG msg;
     305       
     306        // simulate mouse input message
     307        // @@@PH
     308      } 
     309      break;
     310     
     311      // compose a keyboard input message
     312      case INPUT_KEYBOARD:
     313      {
     314        PKEYBDINPUT p = (PKEYBDINPUT)&piBase->ki;
     315        MSG msg;
     316        BOOL fUnicode = (p->dwFlags & KEYEVENTF_UNICODE) == KEYEVENTF_UNICODE;
     317       
     318        // build keyboard message
     319        msg.message = (p->dwFlags & KEYEVENTF_KEYUP) ? WM_KEYUP : WM_KEYDOWN;
     320       
     321        if (p->dwFlags & KEYEVENTF_SCANCODE)
     322        {
     323          // keystroke is identified by the scancode
     324          if (fUnicode)
     325            msg.wParam = MapVirtualKeyW(p->wScan, 1);
     326          else
     327            msg.wParam = MapVirtualKeyA(p->wScan, 1);
     328        }
     329        else
     330          msg.wParam = p->wVk;
     331       
     332        msg.lParam = 0x0000001 |                    // repeat count
     333                      ( (p->wScan & 0xff) << 16);   // scan code
     334       
     335        if (p->dwFlags & KEYEVENTF_EXTENDEDKEY)
     336          msg.lParam |= (1 << 24);
     337       
     338        // set additional message flags
     339        if (msg.message == WM_KEYDOWN)
     340        {
     341          // @@@PH
     342          // bit 30 - previous key state cannot be set, how to determine?
     343        }
     344        else
     345        {
     346          // WM_KEYUP -> previous key is always 1, transistion state
     347          // always 1
     348          msg.lParam |= (1 << 30);
     349          msg.lParam |= (1 << 31);
     350        }
     351       
     352        msg.time   = p->time;
     353       
     354        // @@@PH
     355        // unknown: do we have to post or to send the message?
     356       
     357        if (fUnicode)
     358          SendMessageW(hwnd, msg.message, msg.wParam, msg.lParam);
     359        else
     360          SendMessageA(hwnd, msg.message, msg.wParam, msg.lParam);
     361       
     362        SetMessageExtraInfo( (LPARAM)p->dwExtraInfo );
     363      } 
     364      break;
     365     
     366      case INPUT_HARDWARE:
     367      {
     368        PHARDWAREINPUT p = (PHARDWAREINPUT)&piBase->hi;
     369       
     370        // @@@PH
     371        // not supported for the time being
     372      } 
     373      break;
     374     
     375      default:
     376        dprintf(("unsupported input packet type %d",
     377                piBase->type));
     378        break;
     379    }
     380  }
     381 
    239382  return 0;
    240383}
     
    255398 * Author    : Patrick Haller [Thu, 1998/02/26 11:55]
    256399 *****************************************************************************/
    257 BOOL WIN32API DragDetect(HWND  hwnd,
    258                             POINT pt)
    259 {
    260   dprintf(("USER32:DragDetect(%08xh,...) not implemented", hwnd));
     400ODINFUNCTION2(BOOL,  DragDetect,
     401              HWND,  hwnd,
     402              POINT, pt)
     403{
     404  dprintf(("not implemented"));
    261405
    262406  return (FALSE);
Note: See TracChangeset for help on using the changeset viewer.