4 * Copyright 1998 Ulrich Weigand
10 #include "debugtools.h"
12 #include "builtin16.h"
20 #include "wine/winbase16.h"
22 DEFAULT_DEBUG_CHANNEL(event)
24 /**********************************************************************/
26 MOUSE_DRIVER *MOUSE_Driver = NULL;
28 static LPMOUSE_EVENT_PROC DefMouseEventProc = NULL;
30 /***********************************************************************
31 * MOUSE_Inquire (MOUSE.1)
33 WORD WINAPI MOUSE_Inquire(LPMOUSEINFO mouseInfo)
35 mouseInfo->msExist = TRUE;
36 mouseInfo->msRelative = FALSE;
37 mouseInfo->msNumButtons = 2;
38 mouseInfo->msRate = 34; /* the DDK says so ... */
39 mouseInfo->msXThreshold = 0;
40 mouseInfo->msYThreshold = 0;
41 mouseInfo->msXRes = 0;
42 mouseInfo->msYRes = 0;
43 mouseInfo->msMouseCommPort = 0;
45 return sizeof(MOUSEINFO);
48 /***********************************************************************
49 * MOUSE_Enable (MOUSE.2)
51 VOID WINAPI MOUSE_Enable(LPMOUSE_EVENT_PROC lpMouseEventProc)
53 static BOOL initDone = FALSE;
55 THUNK_Free( (FARPROC)DefMouseEventProc );
56 DefMouseEventProc = lpMouseEventProc;
58 /* Now initialize the mouse driver */
59 if (initDone == FALSE)
61 MOUSE_Driver->pInit();
66 static VOID WINAPI MOUSE_CallMouseEventProc( FARPROC16 proc,
67 DWORD dwFlags, DWORD dx, DWORD dy,
68 DWORD cButtons, DWORD dwExtraInfo )
72 memset( &context, 0, sizeof(context) );
73 CS_reg(&context) = SELECTOROF( proc );
74 EIP_reg(&context) = OFFSETOF( proc );
75 AX_reg(&context) = (WORD)dwFlags;
76 BX_reg(&context) = (WORD)dx;
77 CX_reg(&context) = (WORD)dy;
78 DX_reg(&context) = (WORD)cButtons;
79 SI_reg(&context) = LOWORD( dwExtraInfo );
80 DI_reg(&context) = HIWORD( dwExtraInfo );
82 CallTo16RegisterShort( &context, 0 );
85 VOID WINAPI WIN16_MOUSE_Enable( FARPROC16 proc )
87 LPMOUSE_EVENT_PROC thunk =
88 (LPMOUSE_EVENT_PROC)THUNK_Alloc( proc, (RELAY)MOUSE_CallMouseEventProc );
90 MOUSE_Enable( thunk );
93 /***********************************************************************
94 * MOUSE_Disable (MOUSE.3)
96 VOID WINAPI MOUSE_Disable(VOID)
98 THUNK_Free( (FARPROC)DefMouseEventProc );
99 DefMouseEventProc = 0;
102 /***********************************************************************
105 void MOUSE_SendEvent( DWORD mouseStatus, DWORD posX, DWORD posY,
106 DWORD keyState, DWORD time, HWND hWnd )
108 int width = MONITOR_GetWidth (&MONITOR_PrimaryMonitor);
109 int height = MONITOR_GetHeight(&MONITOR_PrimaryMonitor);
113 if ( !DefMouseEventProc ) return;
115 TRACE("(%04lX,%ld,%ld)\n", mouseStatus, posX, posY );
117 if (mouseStatus & MOUSEEVENTF_MOVE) {
118 if (mouseStatus & MOUSEEVENTF_ABSOLUTE) {
119 /* Relative mouse movements seems not to be scaled as absolute ones */
120 posX = (((long)posX << 16) + width-1) / width;
121 posY = (((long)posY << 16) + height-1) / height;
125 wme.magic = WINE_MOUSEEVENT_MAGIC;
128 wme.keyState = keyState;
130 MOUSE_Driver->pEnableWarpPointer(FALSE);
131 /* To avoid deadlocks, we have to suspend all locks on windows structures
132 before the program control is passed to the mouse driver */
133 iWndsLocks = WIN_SuspendWndsLock();
134 DefMouseEventProc( mouseStatus, posX, posY, 0, (DWORD)&wme );
135 WIN_RestoreWndsLock(iWndsLocks);
136 MOUSE_Driver->pEnableWarpPointer(TRUE);