Split the multimedia/ directory into dlls/ subdirectories.
[wine.git] / windows / mouse.c
blob3089a19831bec4318d0c3a532364ed487e76a379
1 /*
2 * MOUSE driver
3 *
4 * Copyright 1998 Ulrich Weigand
5 *
6 */
8 #include <string.h>
10 #include "debugtools.h"
11 #include "callback.h"
12 #include "builtin16.h"
13 #include "mouse.h"
14 #include "monitor.h"
15 #include "winuser.h"
16 #include "win.h"
18 DEFAULT_DEBUG_CHANNEL(event)
20 /**********************************************************************/
22 MOUSE_DRIVER *MOUSE_Driver = NULL;
24 static LPMOUSE_EVENT_PROC DefMouseEventProc = NULL;
26 /***********************************************************************
27 * MOUSE_Inquire (MOUSE.1)
29 WORD WINAPI MOUSE_Inquire(LPMOUSEINFO mouseInfo)
31 mouseInfo->msExist = TRUE;
32 mouseInfo->msRelative = FALSE;
33 mouseInfo->msNumButtons = 2;
34 mouseInfo->msRate = 34; /* the DDK says so ... */
35 mouseInfo->msXThreshold = 0;
36 mouseInfo->msYThreshold = 0;
37 mouseInfo->msXRes = 0;
38 mouseInfo->msYRes = 0;
39 mouseInfo->msMouseCommPort = 0;
41 return sizeof(MOUSEINFO);
44 /***********************************************************************
45 * MOUSE_Enable (MOUSE.2)
47 VOID WINAPI MOUSE_Enable(LPMOUSE_EVENT_PROC lpMouseEventProc)
49 THUNK_Free( (FARPROC)DefMouseEventProc );
50 DefMouseEventProc = lpMouseEventProc;
53 static VOID WINAPI MOUSE_CallMouseEventProc( FARPROC16 proc,
54 DWORD dwFlags, DWORD dx, DWORD dy,
55 DWORD cButtons, DWORD dwExtraInfo )
57 CONTEXT86 context;
59 memset( &context, 0, sizeof(context) );
60 CS_reg(&context) = SELECTOROF( proc );
61 EIP_reg(&context) = OFFSETOF( proc );
62 AX_reg(&context) = (WORD)dwFlags;
63 BX_reg(&context) = (WORD)dx;
64 CX_reg(&context) = (WORD)dy;
65 DX_reg(&context) = (WORD)cButtons;
66 SI_reg(&context) = LOWORD( dwExtraInfo );
67 DI_reg(&context) = HIWORD( dwExtraInfo );
69 CallTo16RegisterShort( &context, 0 );
72 VOID WINAPI WIN16_MOUSE_Enable( FARPROC16 proc )
74 LPMOUSE_EVENT_PROC thunk =
75 (LPMOUSE_EVENT_PROC)THUNK_Alloc( proc, (RELAY)MOUSE_CallMouseEventProc );
77 MOUSE_Enable( thunk );
80 /***********************************************************************
81 * MOUSE_Disable (MOUSE.3)
83 VOID WINAPI MOUSE_Disable(VOID)
85 THUNK_Free( (FARPROC)DefMouseEventProc );
86 DefMouseEventProc = 0;
89 /***********************************************************************
90 * MOUSE_SendEvent
92 void MOUSE_SendEvent( DWORD mouseStatus, DWORD posX, DWORD posY,
93 DWORD keyState, DWORD time, HWND hWnd )
95 int width = MONITOR_GetWidth (&MONITOR_PrimaryMonitor);
96 int height = MONITOR_GetHeight(&MONITOR_PrimaryMonitor);
97 int iWndsLocks;
98 WINE_MOUSEEVENT wme;
99 BOOL bOldWarpPointer;
101 if ( !DefMouseEventProc ) return;
103 TRACE("(%04lX,%ld,%ld)\n", mouseStatus, posX, posY );
105 mouseStatus |= MOUSEEVENTF_ABSOLUTE;
106 posX = (((long)posX << 16) + width-1) / width;
107 posY = (((long)posY << 16) + height-1) / height;
109 wme.magic = WINE_MOUSEEVENT_MAGIC;
110 wme.keyState = keyState;
111 wme.time = time;
112 wme.hWnd = hWnd;
114 bOldWarpPointer = MOUSE_Driver->pEnableWarpPointer(FALSE);
115 /* To avoid deadlocks, we have to suspend all locks on windows structures
116 before the program control is passed to the mouse driver */
117 iWndsLocks = WIN_SuspendWndsLock();
118 DefMouseEventProc( mouseStatus, posX, posY, 0, (DWORD)&wme );
119 WIN_RestoreWndsLock(iWndsLocks);
120 MOUSE_Driver->pEnableWarpPointer(bOldWarpPointer);