Use d3dexecutebuffer_create only when compiling with MESA.
[wine] / dlls / mouse / mouse_main.c
1 /*
2  * MOUSE driver
3  * 
4  * Copyright 1998 Ulrich Weigand
5  * 
6  */
7
8 #include <string.h>
9
10 #include "debugtools.h"
11 #include "callback.h"
12 #include "builtin16.h"
13 #include "module.h"
14 #include "mouse.h"
15 #include "monitor.h"
16 #include "user.h"
17 #include "windef.h"
18 #include "wingdi.h"
19 #include "winuser.h"
20 #include "win.h"
21 #include "wine/winbase16.h"
22
23 DEFAULT_DEBUG_CHANNEL(event);
24
25 /**********************************************************************/
26
27 static LPMOUSE_EVENT_PROC DefMouseEventProc = NULL;
28
29 /***********************************************************************
30  *           MOUSE_Inquire                       (MOUSE.1)
31  */
32 WORD WINAPI MOUSE_Inquire(LPMOUSEINFO mouseInfo)
33 {
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;
43
44     return sizeof(MOUSEINFO);
45 }
46
47 /***********************************************************************
48  *           MOUSE_Enable                        (MOUSE.2)
49  */
50 VOID WINAPI MOUSE_Enable(LPMOUSE_EVENT_PROC lpMouseEventProc)
51 {
52     static BOOL initDone = FALSE;
53     
54     THUNK_Free( (FARPROC)DefMouseEventProc );
55     DefMouseEventProc = lpMouseEventProc;
56
57     /* Now initialize the mouse driver */
58     if (initDone == FALSE)
59     {
60         USER_Driver->pInitMouse();
61         initDone = TRUE;
62     }
63 }
64
65 static VOID WINAPI MOUSE_CallMouseEventProc( FARPROC16 proc,
66                                              DWORD dwFlags, DWORD dx, DWORD dy,
67                                              DWORD cButtons, DWORD dwExtraInfo )
68 {
69     CONTEXT86 context;
70
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 );
80
81     CallTo16RegisterShort( &context, 0 );
82 }
83
84 VOID WINAPI WIN16_MOUSE_Enable( FARPROC16 proc )
85 {
86     LPMOUSE_EVENT_PROC thunk = 
87       (LPMOUSE_EVENT_PROC)THUNK_Alloc( proc, (RELAY)MOUSE_CallMouseEventProc );
88
89     MOUSE_Enable( thunk );
90 }
91
92 /***********************************************************************
93  *           MOUSE_Disable                       (MOUSE.3)
94  */
95 VOID WINAPI MOUSE_Disable(VOID)
96 {
97     THUNK_Free( (FARPROC)DefMouseEventProc );
98     DefMouseEventProc = 0;
99 }
100
101 /***********************************************************************
102  *           MOUSE_SendEvent
103  */
104 void MOUSE_SendEvent( DWORD mouseStatus, DWORD posX, DWORD posY, 
105                       DWORD keyState, DWORD time, HWND hWnd )
106 {
107     int width  = MONITOR_GetWidth (&MONITOR_PrimaryMonitor);
108     int height = MONITOR_GetHeight(&MONITOR_PrimaryMonitor);
109     int iWndsLocks;
110     WINE_MOUSEEVENT wme;
111
112     if ( !DefMouseEventProc ) return;
113
114     TRACE("(%04lX,%ld,%ld)\n", mouseStatus, posX, posY );
115
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;
121       }
122     }
123
124     wme.magic    = WINE_MOUSEEVENT_MAGIC;
125     wme.time     = time;
126     wme.hWnd     = hWnd;
127     wme.keyState = keyState;
128     
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);
136 }