4 * Copyright 1998 Ulrich Weigand
10 #include "debugtools.h"
12 #include "builtin16.h"
21 #include "wine/winbase16.h"
23 DEFAULT_DEBUG_CHANNEL(event);
25 /**********************************************************************/
27 static LPMOUSE_EVENT_PROC DefMouseEventProc = NULL;
29 /***********************************************************************
30 * MOUSE_Inquire (MOUSE.1)
32 WORD WINAPI MOUSE_Inquire(LPMOUSEINFO mouseInfo)
34 mouseInfo->msExist = TRUE;
35 mouseInfo->msRelative = FALSE;
36 mouseInfo->msNumButtons = 2;
37 mouseInfo->msRate = 34; /* the DDK says so ... */
38 mouseInfo->msXThreshold = 0;
39 mouseInfo->msYThreshold = 0;
40 mouseInfo->msXRes = 0;
41 mouseInfo->msYRes = 0;
42 mouseInfo->msMouseCommPort = 0;
44 return sizeof(MOUSEINFO);
47 /***********************************************************************
48 * MOUSE_Enable (MOUSE.2)
50 VOID WINAPI MOUSE_Enable(LPMOUSE_EVENT_PROC lpMouseEventProc)
52 static BOOL initDone = FALSE;
54 THUNK_Free( (FARPROC)DefMouseEventProc );
55 DefMouseEventProc = lpMouseEventProc;
57 /* Now initialize the mouse driver */
58 if (initDone == FALSE)
60 USER_Driver->pInitMouse();
65 static VOID WINAPI MOUSE_CallMouseEventProc( FARPROC16 proc,
66 DWORD dwFlags, DWORD dx, DWORD dy,
67 DWORD cButtons, DWORD dwExtraInfo )
71 memset( &context, 0, sizeof(context) );
72 CS_reg(&context) = SELECTOROF( proc );
73 EIP_reg(&context) = OFFSETOF( proc );
74 AX_reg(&context) = (WORD)dwFlags;
75 BX_reg(&context) = (WORD)dx;
76 CX_reg(&context) = (WORD)dy;
77 DX_reg(&context) = (WORD)cButtons;
78 SI_reg(&context) = LOWORD( dwExtraInfo );
79 DI_reg(&context) = HIWORD( dwExtraInfo );
81 CallTo16RegisterShort( &context, 0 );
84 VOID WINAPI WIN16_MOUSE_Enable( FARPROC16 proc )
86 LPMOUSE_EVENT_PROC thunk =
87 (LPMOUSE_EVENT_PROC)THUNK_Alloc( proc, (RELAY)MOUSE_CallMouseEventProc );
89 MOUSE_Enable( thunk );
92 /***********************************************************************
93 * MOUSE_Disable (MOUSE.3)
95 VOID WINAPI MOUSE_Disable(VOID)
97 THUNK_Free( (FARPROC)DefMouseEventProc );
98 DefMouseEventProc = 0;
101 /***********************************************************************
104 void MOUSE_SendEvent( DWORD mouseStatus, DWORD posX, DWORD posY,
105 DWORD keyState, DWORD time, HWND hWnd )
107 int width = MONITOR_GetWidth (&MONITOR_PrimaryMonitor);
108 int height = MONITOR_GetHeight(&MONITOR_PrimaryMonitor);
112 if ( !DefMouseEventProc ) return;
114 TRACE("(%04lX,%ld,%ld)\n", mouseStatus, posX, posY );
116 if (mouseStatus & MOUSEEVENTF_MOVE) {
117 if (mouseStatus & MOUSEEVENTF_ABSOLUTE) {
118 /* Relative mouse movements seems not to be scaled as absolute ones */
119 posX = (((long)posX << 16) + width-1) / width;
120 posY = (((long)posY << 16) + height-1) / height;
124 wme.magic = WINE_MOUSEEVENT_MAGIC;
127 wme.keyState = keyState;
129 USER_Driver->pEnableWarpPointer(FALSE);
130 /* To avoid deadlocks, we have to suspend all locks on windows structures
131 before the program control is passed to the mouse driver */
132 iWndsLocks = WIN_SuspendWndsLock();
133 DefMouseEventProc( mouseStatus, posX, posY, 0, (DWORD)&wme );
134 WIN_RestoreWndsLock(iWndsLocks);
135 USER_Driver->pEnableWarpPointer(TRUE);