4 * Copyright 1998 Ulrich Weigand
10 #include "debugtools.h"
12 #include "builtin16.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 static BOOL initDone
= FALSE
;
51 THUNK_Free( (FARPROC
)DefMouseEventProc
);
52 DefMouseEventProc
= lpMouseEventProc
;
54 /* Now initialize the mouse driver */
55 if (initDone
== FALSE
) MOUSE_Driver
->pInit();
59 static VOID WINAPI
MOUSE_CallMouseEventProc( FARPROC16 proc
,
60 DWORD dwFlags
, DWORD dx
, DWORD dy
,
61 DWORD cButtons
, DWORD dwExtraInfo
)
65 memset( &context
, 0, sizeof(context
) );
66 CS_reg(&context
) = SELECTOROF( proc
);
67 EIP_reg(&context
) = OFFSETOF( proc
);
68 AX_reg(&context
) = (WORD
)dwFlags
;
69 BX_reg(&context
) = (WORD
)dx
;
70 CX_reg(&context
) = (WORD
)dy
;
71 DX_reg(&context
) = (WORD
)cButtons
;
72 SI_reg(&context
) = LOWORD( dwExtraInfo
);
73 DI_reg(&context
) = HIWORD( dwExtraInfo
);
75 CallTo16RegisterShort( &context
, 0 );
78 VOID WINAPI
WIN16_MOUSE_Enable( FARPROC16 proc
)
80 LPMOUSE_EVENT_PROC thunk
=
81 (LPMOUSE_EVENT_PROC
)THUNK_Alloc( proc
, (RELAY
)MOUSE_CallMouseEventProc
);
83 MOUSE_Enable( thunk
);
86 /***********************************************************************
87 * MOUSE_Disable (MOUSE.3)
89 VOID WINAPI
MOUSE_Disable(VOID
)
91 THUNK_Free( (FARPROC
)DefMouseEventProc
);
92 DefMouseEventProc
= 0;
95 /***********************************************************************
98 void MOUSE_SendEvent( DWORD mouseStatus
, DWORD posX
, DWORD posY
,
99 DWORD keyState
, DWORD time
, HWND hWnd
)
101 int width
= MONITOR_GetWidth (&MONITOR_PrimaryMonitor
);
102 int height
= MONITOR_GetHeight(&MONITOR_PrimaryMonitor
);
105 BOOL bOldWarpPointer
;
107 if ( !DefMouseEventProc
) return;
109 TRACE("(%04lX,%ld,%ld)\n", mouseStatus
, posX
, posY
);
111 if (mouseStatus
& MOUSEEVENTF_MOVE
) {
112 if (mouseStatus
& MOUSEEVENTF_ABSOLUTE
) {
113 /* Relative mouse movements seems not to be scaled as absolute ones */
114 posX
= (((long)posX
<< 16) + width
-1) / width
;
115 posY
= (((long)posY
<< 16) + height
-1) / height
;
119 wme
.magic
= WINE_MOUSEEVENT_MAGIC
;
122 wme
.keyState
= keyState
;
124 bOldWarpPointer
= MOUSE_Driver
->pEnableWarpPointer(FALSE
);
125 /* To avoid deadlocks, we have to suspend all locks on windows structures
126 before the program control is passed to the mouse driver */
127 iWndsLocks
= WIN_SuspendWndsLock();
128 DefMouseEventProc( mouseStatus
, posX
, posY
, 0, (DWORD
)&wme
);
129 WIN_RestoreWndsLock(iWndsLocks
);
130 MOUSE_Driver
->pEnableWarpPointer(bOldWarpPointer
);