dinput: Warp mouse each 10ms instead of dropping events.
[wine] / dlls / dinput / mouse.c
1 /*              DirectInput Mouse device
2  *
3  * Copyright 1998 Marcus Meissner
4  * Copyright 1998,1999 Lionel Ulmer
5  * Copyright 2000-2001 TransGaming Technologies Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdarg.h>
26 #include <string.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winerror.h"
33 #include "dinput.h"
34
35 #include "dinput_private.h"
36 #include "device_private.h"
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
39
40 #define MOUSE_HACK
41
42 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
43
44 /* Wine mouse driver object instances */
45 #define WINE_MOUSE_X_AXIS_INSTANCE   0
46 #define WINE_MOUSE_Y_AXIS_INSTANCE   1
47 #define WINE_MOUSE_Z_AXIS_INSTANCE   2
48 #define WINE_MOUSE_L_BUTTON_INSTANCE 0
49 #define WINE_MOUSE_R_BUTTON_INSTANCE 1
50 #define WINE_MOUSE_M_BUTTON_INSTANCE 2
51 #define WINE_MOUSE_D_BUTTON_INSTANCE 3
52
53 /* ------------------------------- */
54 /* Wine mouse internal data format */
55 /* ------------------------------- */
56
57 /* Constants used to access the offset array */
58 #define WINE_MOUSE_X_POSITION 0
59 #define WINE_MOUSE_Y_POSITION 1
60 #define WINE_MOUSE_Z_POSITION 2
61 #define WINE_MOUSE_L_POSITION 3
62 #define WINE_MOUSE_R_POSITION 4
63 #define WINE_MOUSE_M_POSITION 5
64
65 typedef struct {
66     LONG lX;
67     LONG lY;
68     LONG lZ;
69     BYTE rgbButtons[4];
70 } Wine_InternalMouseData;
71
72 #define WINE_INTERNALMOUSE_NUM_OBJS 6
73
74 static const DIOBJECTDATAFORMAT Wine_InternalMouseObjectFormat[WINE_INTERNALMOUSE_NUM_OBJS] = {
75     { &GUID_XAxis,   FIELD_OFFSET(Wine_InternalMouseData, lX),
76           DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS, 0 },
77     { &GUID_YAxis,   FIELD_OFFSET(Wine_InternalMouseData, lY),
78           DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS, 0 },
79     { &GUID_ZAxis,   FIELD_OFFSET(Wine_InternalMouseData, lZ),
80           DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS, 0 },
81     { &GUID_Button, (FIELD_OFFSET(Wine_InternalMouseData, rgbButtons)) + 0,
82           DIDFT_MAKEINSTANCE(WINE_MOUSE_L_BUTTON_INSTANCE) | DIDFT_PSHBUTTON, 0 },
83     { &GUID_Button, (FIELD_OFFSET(Wine_InternalMouseData, rgbButtons)) + 1,
84           DIDFT_MAKEINSTANCE(WINE_MOUSE_R_BUTTON_INSTANCE) | DIDFT_PSHBUTTON, 0 },
85     { &GUID_Button, (FIELD_OFFSET(Wine_InternalMouseData, rgbButtons)) + 2,
86           DIDFT_MAKEINSTANCE(WINE_MOUSE_M_BUTTON_INSTANCE) | DIDFT_PSHBUTTON, 0 }
87 };
88
89 static const DIDATAFORMAT Wine_InternalMouseFormat = {
90     0, /* dwSize - unused */
91     0, /* dwObjsize - unused */
92     0, /* dwFlags - unused */
93     sizeof(Wine_InternalMouseData),
94     WINE_INTERNALMOUSE_NUM_OBJS, /* dwNumObjs */
95     (LPDIOBJECTDATAFORMAT) Wine_InternalMouseObjectFormat
96 };
97
98 static const IDirectInputDevice8AVtbl SysMouseAvt;
99 static const IDirectInputDevice8WVtbl SysMouseWvt;
100
101 typedef struct SysMouseImpl SysMouseImpl;
102
103 typedef enum {
104     WARP_DONE,   /* Warping has been done */
105     WARP_NEEDED, /* Warping is needed */
106     WARP_STARTED /* Warping has been done, waiting for the warp event */
107 } WARP_STATUS;
108
109 struct SysMouseImpl
110 {
111     const void                     *lpVtbl;
112     LONG                            ref;
113     GUID                            guid;
114     
115     IDirectInputImpl               *dinput;
116     
117     /* The current data format and the conversion between internal
118        and external data formats */
119     DIDATAFORMAT                   *df;
120     DataFormat                     *wine_df;
121     int                             offset_array[WINE_INTERNALMOUSE_NUM_OBJS];
122     
123     /* SysMouseAImpl */
124     BYTE                            absolute;
125     /* Previous position for relative moves */
126     LONG                            prevX, prevY;
127     /* These are used in case of relative -> absolute transitions */
128     POINT                           org_coords;
129     HWND                            win;
130     DWORD                           dwCoopLevel;
131     POINT                           mapped_center;
132     DWORD                           win_centerX, win_centerY;
133     LPDIDEVICEOBJECTDATA            data_queue;
134     int                             queue_head, queue_tail, queue_len;
135     BOOL                            overflow;
136     /* warping: whether we need to move mouse back to middle once we
137      * reach window borders (for e.g. shooters, "surface movement" games) */
138     WARP_STATUS                     need_warp;
139     DWORD                           last_warped;
140     int                             acquired;
141     HANDLE                          hEvent;
142     CRITICAL_SECTION                crit;
143     
144     /* This is for mouse reporting. */
145     Wine_InternalMouseData          m_state;
146 };
147
148 /* FIXME: This is ugly and not thread safe :/ */
149 static IDirectInputDevice8A* current_lock = NULL;
150
151 static GUID DInput_Wine_Mouse_GUID = { /* 9e573ed8-7734-11d2-8d4a-23903fb6bdf7 */
152     0x9e573ed8,
153     0x7734,
154     0x11d2,
155     {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
156 };
157
158 static void fill_mouse_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, DWORD version) {
159     DWORD dwSize;
160     DIDEVICEINSTANCEA ddi;
161     
162     dwSize = lpddi->dwSize;
163
164     TRACE("%ld %p\n", dwSize, lpddi);
165     
166     memset(lpddi, 0, dwSize);
167     memset(&ddi, 0, sizeof(ddi));
168
169     ddi.dwSize = dwSize;
170     ddi.guidInstance = GUID_SysMouse;/* DInput's GUID */
171     ddi.guidProduct = DInput_Wine_Mouse_GUID; /* Vendor's GUID */
172     if (version >= 0x0800)
173         ddi.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
174     else
175         ddi.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
176     strcpy(ddi.tszInstanceName, "Mouse");
177     strcpy(ddi.tszProductName, "Wine Mouse");
178
179     memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
180 }
181
182 static void fill_mouse_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version) {
183     DWORD dwSize;
184     DIDEVICEINSTANCEW ddi;
185     
186     dwSize = lpddi->dwSize;
187
188     TRACE("%ld %p\n", dwSize, lpddi);
189     
190     memset(lpddi, 0, dwSize);
191     memset(&ddi, 0, sizeof(ddi));
192
193     ddi.dwSize = dwSize;
194     ddi.guidInstance = GUID_SysMouse;/* DInput's GUID */
195     ddi.guidProduct = DInput_Wine_Mouse_GUID; /* Vendor's GUID */
196     if (version >= 0x0800)
197         ddi.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
198     else
199         ddi.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
200     MultiByteToWideChar(CP_ACP, 0, "Mouse", -1, ddi.tszInstanceName, MAX_PATH);
201     MultiByteToWideChar(CP_ACP, 0, "Wine Mouse", -1, ddi.tszProductName, MAX_PATH);
202
203     memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
204 }
205
206 static BOOL mousedev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
207 {
208     if (id != 0)
209         return FALSE;
210
211     if ((dwDevType == 0) ||
212         ((dwDevType == DIDEVTYPE_MOUSE) && (version < 0x0800)) ||
213         (((dwDevType == DI8DEVCLASS_POINTER) || (dwDevType == DI8DEVTYPE_MOUSE)) && (version >= 0x0800))) {
214         TRACE("Enumerating the mouse device\n");
215         
216         fill_mouse_dideviceinstanceA(lpddi, version);
217         
218         return TRUE;
219     }
220     
221     return FALSE;
222 }
223
224 static BOOL mousedev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
225 {
226     if (id != 0)
227         return FALSE;
228
229     if ((dwDevType == 0) ||
230         ((dwDevType == DIDEVTYPE_MOUSE) && (version < 0x0800)) ||
231         (((dwDevType == DI8DEVCLASS_POINTER) || (dwDevType == DI8DEVTYPE_MOUSE)) && (version >= 0x0800))) {
232         TRACE("Enumerating the mouse device\n");
233         
234         fill_mouse_dideviceinstanceW(lpddi, version);
235         
236         return TRUE;
237     }
238     
239     return FALSE;
240 }
241
242 static SysMouseImpl *alloc_device(REFGUID rguid, const void *mvt, IDirectInputImpl *dinput)
243 {
244     int offset_array[WINE_INTERNALMOUSE_NUM_OBJS] = {
245         FIELD_OFFSET(Wine_InternalMouseData, lX),
246         FIELD_OFFSET(Wine_InternalMouseData, lY),
247         FIELD_OFFSET(Wine_InternalMouseData, lZ),
248         FIELD_OFFSET(Wine_InternalMouseData, rgbButtons) + 0,
249         FIELD_OFFSET(Wine_InternalMouseData, rgbButtons) + 1,
250         FIELD_OFFSET(Wine_InternalMouseData, rgbButtons) + 2
251     };
252     SysMouseImpl* newDevice;
253     newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouseImpl));
254     newDevice->ref = 1;
255     newDevice->lpVtbl = mvt;
256     InitializeCriticalSection(&(newDevice->crit));
257     memcpy(&(newDevice->guid),rguid,sizeof(*rguid));
258
259     /* Per default, Wine uses its internal data format */
260     newDevice->df = (DIDATAFORMAT *) &Wine_InternalMouseFormat;
261     memcpy(newDevice->offset_array, offset_array, WINE_INTERNALMOUSE_NUM_OBJS * sizeof(int));
262     newDevice->wine_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DataFormat));
263     newDevice->wine_df->size = 0;
264     newDevice->wine_df->internal_format_size = Wine_InternalMouseFormat.dwDataSize;
265     newDevice->wine_df->dt = NULL;
266     newDevice->dinput = dinput;
267
268     return newDevice;
269 }
270
271 static HRESULT mousedev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
272 {
273     if ((IsEqualGUID(&GUID_SysMouse,rguid)) ||             /* Generic Mouse */
274         (IsEqualGUID(&DInput_Wine_Mouse_GUID,rguid))) { /* Wine Mouse */
275         if ((riid == NULL) ||
276             IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
277             IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
278             IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
279             IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
280             *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &SysMouseAvt, dinput);
281             TRACE("Creating a Mouse device (%p)\n", *pdev);
282             return DI_OK;
283         } else
284             return DIERR_NOINTERFACE;
285     }
286     
287     return DIERR_DEVICENOTREG;
288 }
289
290 static HRESULT mousedev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
291 {
292     if ((IsEqualGUID(&GUID_SysMouse,rguid)) ||             /* Generic Mouse */
293         (IsEqualGUID(&DInput_Wine_Mouse_GUID,rguid))) { /* Wine Mouse */
294         if ((riid == NULL) ||
295             IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
296             IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
297             IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
298             IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
299             *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &SysMouseWvt, dinput);
300             TRACE("Creating a Mouse device (%p)\n", *pdev);
301             return DI_OK;
302         } else
303             return DIERR_NOINTERFACE;
304     }
305     
306     return DIERR_DEVICENOTREG;
307 }
308
309 const struct dinput_device mouse_device = {
310     "Wine mouse driver",
311     mousedev_enum_deviceA,
312     mousedev_enum_deviceW,
313     mousedev_create_deviceA,
314     mousedev_create_deviceW
315 };
316
317 /******************************************************************************
318  *      SysMouseA (DInput Mouse support)
319  */
320
321 /******************************************************************************
322   *     Release : release the mouse buffer.
323   */
324 static ULONG WINAPI SysMouseAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
325 {
326     SysMouseImpl *This = (SysMouseImpl *)iface;
327     ULONG ref;
328  
329     ref = InterlockedDecrement(&(This->ref));
330     if (ref)
331         return ref;
332
333     set_dinput_hook(WH_MOUSE_LL, NULL);
334
335     /* Free the data queue */
336     HeapFree(GetProcessHeap(),0,This->data_queue);
337     DeleteCriticalSection(&(This->crit));
338     
339     /* Free the DataFormat */
340     if (This->df != &(Wine_InternalMouseFormat)) {
341         HeapFree(GetProcessHeap(), 0, This->df->rgodf);
342         HeapFree(GetProcessHeap(), 0, This->df);
343     }
344     
345     HeapFree(GetProcessHeap(),0,This);
346     return 0;
347 }
348
349
350 /******************************************************************************
351   *     SetCooperativeLevel : store the window in which we will do our
352   *   grabbing.
353   */
354 static HRESULT WINAPI SysMouseAImpl_SetCooperativeLevel(
355         LPDIRECTINPUTDEVICE8A iface,HWND hwnd,DWORD dwflags
356 )
357 {
358     SysMouseImpl *This = (SysMouseImpl *)iface;
359     
360     TRACE("(this=%p,%p,0x%08lx)\n",This,hwnd,dwflags);
361     
362     if (TRACE_ON(dinput)) {
363         TRACE(" cooperative level : ");
364         _dump_cooperativelevel_DI(dwflags);
365     }
366     
367     if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND) {
368         return DIERR_UNSUPPORTED;
369     }
370     
371     /* Store the window which asks for the mouse */
372     if (!hwnd)
373         hwnd = GetDesktopWindow();
374     This->win = hwnd;
375     This->dwCoopLevel = dwflags;
376     
377     return DI_OK;
378 }
379
380
381 /******************************************************************************
382   *     SetDataFormat : the application can choose the format of the data
383   *   the device driver sends back with GetDeviceState.
384   *
385   *   For the moment, only the "standard" configuration (c_dfDIMouse) is supported
386   *   in absolute and relative mode.
387   */
388 static HRESULT WINAPI SysMouseAImpl_SetDataFormat(
389         LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
390 )
391 {
392     SysMouseImpl *This = (SysMouseImpl *)iface;
393     
394     TRACE("(this=%p,%p)\n",This,df);
395     
396     _dump_DIDATAFORMAT(df);
397     
398     /* Tests under windows show that a call to SetDataFormat always sets the mouse
399        in relative mode whatever the dwFlags value (DIDF_ABSAXIS/DIDF_RELAXIS).
400        To switch in absolute mode, SetProperty must be used. */
401     This->absolute = 0;
402     
403     /* Store the new data format */
404     This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
405     memcpy(This->df, df, df->dwSize);
406     This->df->rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
407     memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
408     
409     /* Prepare all the data-conversion filters */
410     This->wine_df = create_DataFormat(&(Wine_InternalMouseFormat), df, This->offset_array);
411     
412     return DI_OK;
413 }
414
415 /* low-level mouse hook */
416 static LRESULT CALLBACK dinput_mouse_hook( int code, WPARAM wparam, LPARAM lparam )
417 {
418     LRESULT ret;
419     MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam;
420     SysMouseImpl* This = (SysMouseImpl*) current_lock;
421     DWORD dwCoop;
422     int wdata;
423
424     if (code != HC_ACTION) return CallNextHookEx( 0, code, wparam, lparam );
425
426     EnterCriticalSection(&(This->crit));
427     dwCoop = This->dwCoopLevel;
428
429     /* Mouse moved -> send event if asked */
430     if (This->hEvent)
431         SetEvent(This->hEvent);
432     
433     if (wparam == WM_MOUSEMOVE) {
434         if (This->absolute) {
435             if (hook->pt.x != This->prevX)
436                 GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x, hook->time, 0);
437             if (hook->pt.y != This->prevY)
438                 GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y, hook->time, 0);
439         } else {
440             /* Now, warp handling */
441             if ((This->need_warp == WARP_STARTED) &&
442                 (hook->pt.x == This->mapped_center.x) && (hook->pt.y == This->mapped_center.y)) {
443                 /* Warp has been done... */
444                 This->need_warp = WARP_DONE;
445                 goto end;
446             }
447             
448             /* Relative mouse input with absolute mouse event : the real fun starts here... */
449             if ((This->need_warp == WARP_NEEDED) ||
450                 (This->need_warp == WARP_STARTED)) {
451                 if (hook->pt.x != This->prevX)
452                     GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->prevX,
453                               hook->time, (This->dinput->evsequence)++);
454                 if (hook->pt.y != This->prevY)
455                     GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->prevY,
456                               hook->time, (This->dinput->evsequence)++);
457             } else {
458                 /* This is the first time the event handler has been called after a
459                    GetDeviceData or GetDeviceState. */
460                 if (hook->pt.x != This->mapped_center.x) {
461                     GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->mapped_center.x,
462                               hook->time, (This->dinput->evsequence)++);
463                     This->need_warp = WARP_NEEDED;
464                 }
465                 
466                 if (hook->pt.y != This->mapped_center.y) {
467                     GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->mapped_center.y,
468                               hook->time, (This->dinput->evsequence)++);
469                     This->need_warp = WARP_NEEDED;
470                 }
471             }
472         }
473         
474         This->prevX = hook->pt.x;
475         This->prevY = hook->pt.y;
476         
477         if (This->absolute) {
478             This->m_state.lX = hook->pt.x;
479             This->m_state.lY = hook->pt.y;
480         } else {
481             This->m_state.lX = hook->pt.x - This->mapped_center.x;
482             This->m_state.lY = hook->pt.y - This->mapped_center.y;
483         }
484     }
485     
486     TRACE(" msg %x pt %ld %ld (W=%d)\n",
487           wparam, hook->pt.x, hook->pt.y, (!This->absolute) && This->need_warp );
488     
489     switch(wparam) {
490         case WM_LBUTTONDOWN:
491             GEN_EVENT(This->offset_array[WINE_MOUSE_L_POSITION], 0x80,
492                       hook->time, This->dinput->evsequence++);
493             This->m_state.rgbButtons[0] = 0x80;
494             break;
495         case WM_LBUTTONUP:
496             GEN_EVENT(This->offset_array[WINE_MOUSE_L_POSITION], 0x00,
497                       hook->time, This->dinput->evsequence++);
498             This->m_state.rgbButtons[0] = 0x00;
499             break;
500         case WM_RBUTTONDOWN:
501             GEN_EVENT(This->offset_array[WINE_MOUSE_R_POSITION], 0x80,
502                       hook->time, This->dinput->evsequence++);
503             This->m_state.rgbButtons[1] = 0x80;
504             break;
505         case WM_RBUTTONUP:
506             GEN_EVENT(This->offset_array[WINE_MOUSE_R_POSITION], 0x00,
507                       hook->time, This->dinput->evsequence++);
508             This->m_state.rgbButtons[1] = 0x00;
509             break;
510         case WM_MBUTTONDOWN:
511             GEN_EVENT(This->offset_array[WINE_MOUSE_M_POSITION], 0x80,
512                       hook->time, This->dinput->evsequence++);
513             This->m_state.rgbButtons[2] = 0x80;
514             break;
515         case WM_MBUTTONUP:
516             GEN_EVENT(This->offset_array[WINE_MOUSE_M_POSITION], 0x00,
517                       hook->time, This->dinput->evsequence++);
518             This->m_state.rgbButtons[2] = 0x00;
519             break;
520         case WM_MOUSEWHEEL:
521             wdata = (short)HIWORD(hook->mouseData);
522             GEN_EVENT(This->offset_array[WINE_MOUSE_Z_POSITION], wdata,
523                       hook->time, This->dinput->evsequence++);
524             This->m_state.lZ += wdata;
525             break;
526     }
527     
528     TRACE("(X: %ld - Y: %ld   L: %02x M: %02x R: %02x)\n",
529           This->m_state.lX, This->m_state.lY,
530           This->m_state.rgbButtons[0], This->m_state.rgbButtons[2], This->m_state.rgbButtons[1]);
531     
532   end:
533     LeaveCriticalSection(&(This->crit));
534     
535     if (dwCoop & DISCL_NONEXCLUSIVE) {
536         /* Pass the events down to previous handlers (e.g. win32 input) */
537         ret = CallNextHookEx( 0, code, wparam, lparam );
538     } else {
539         /* Ignore message */
540         ret = 1;
541     }
542     return ret;
543 }
544
545 static void dinput_window_check(SysMouseImpl* This) {
546     RECT rect;
547     DWORD centerX, centerY;
548     
549     /* make sure the window hasn't moved */
550     GetWindowRect(This->win, &rect);
551     centerX = (rect.right  - rect.left) / 2;
552     centerY = (rect.bottom - rect.top ) / 2;
553     if (This->win_centerX != centerX || This->win_centerY != centerY) {
554         This->win_centerX = centerX;
555         This->win_centerY = centerY;
556     }
557     This->mapped_center.x = This->win_centerX;
558     This->mapped_center.y = This->win_centerY;
559     MapWindowPoints(This->win, HWND_DESKTOP, &This->mapped_center, 1);
560 }
561
562
563 /******************************************************************************
564   *     Acquire : gets exclusive control of the mouse
565   */
566 static HRESULT WINAPI SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
567 {
568     SysMouseImpl *This = (SysMouseImpl *)iface;
569     RECT  rect;
570     POINT point;
571     
572     TRACE("(this=%p)\n",This);
573     
574     if (This->acquired)
575       return S_FALSE;
576     
577     This->acquired = 1;
578
579     /* Store (in a global variable) the current lock */
580     current_lock = (IDirectInputDevice8A*)This;
581     
582     /* Init the mouse state */
583     GetCursorPos( &point );
584     if (This->absolute) {
585       This->m_state.lX = point.x;
586       This->m_state.lY = point.y;
587       This->prevX = point.x;
588       This->prevY = point.y;
589     } else {
590       This->m_state.lX = 0;
591       This->m_state.lY = 0;
592       This->org_coords = point;
593     }
594     This->m_state.lZ = 0;
595     This->m_state.rgbButtons[0] = GetKeyState(VK_LBUTTON) & 0x80;
596     This->m_state.rgbButtons[1] = GetKeyState(VK_RBUTTON) & 0x80;
597     This->m_state.rgbButtons[2] = GetKeyState(VK_MBUTTON) & 0x80;
598     
599     /* Install our mouse hook */
600     if (This->dwCoopLevel & DISCL_EXCLUSIVE)
601       ShowCursor(FALSE); /* hide cursor */
602     set_dinput_hook(WH_MOUSE_LL, dinput_mouse_hook);
603     
604     /* Get the window dimension and find the center */
605     GetWindowRect(This->win, &rect);
606     This->win_centerX = (rect.right  - rect.left) / 2;
607     This->win_centerY = (rect.bottom - rect.top ) / 2;
608     
609     /* Warp the mouse to the center of the window */
610     if (This->absolute == 0) {
611       This->mapped_center.x = This->win_centerX;
612       This->mapped_center.y = This->win_centerY;
613       MapWindowPoints(This->win, HWND_DESKTOP, &This->mapped_center, 1);
614       TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y);
615       SetCursorPos( This->mapped_center.x, This->mapped_center.y );
616       This->last_warped = GetCurrentTime();
617
618 #ifdef MOUSE_HACK
619       This->need_warp = WARP_DONE;
620 #else
621       This->need_warp = WARP_STARTED;
622 #endif
623     }
624         
625     return DI_OK;
626 }
627
628 /******************************************************************************
629   *     Unacquire : frees the mouse
630   */
631 static HRESULT WINAPI SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
632 {
633     SysMouseImpl *This = (SysMouseImpl *)iface;
634     
635     TRACE("(this=%p)\n",This);
636     
637     if (0 == This->acquired) {
638         return DI_NOEFFECT;
639     }
640
641     set_dinput_hook(WH_MOUSE_LL, NULL);
642     if (This->dwCoopLevel & DISCL_EXCLUSIVE)
643         ShowCursor(TRUE); /* show cursor */
644
645     /* No more locks */
646     if (current_lock == (IDirectInputDevice8A*) This)
647       current_lock = NULL;
648     else
649       ERR("this(%p) != current_lock(%p)\n", This, current_lock);
650
651     /* Unacquire device */
652     This->acquired = 0;
653     
654     /* And put the mouse cursor back where it was at acquire time */
655     if (This->absolute == 0) {
656       TRACE(" warping mouse back to (%ld , %ld)\n", This->org_coords.x, This->org_coords.y);
657       SetCursorPos(This->org_coords.x, This->org_coords.y);
658     }
659         
660     return DI_OK;
661 }
662
663 /******************************************************************************
664   *     GetDeviceState : returns the "state" of the mouse.
665   *
666   *   For the moment, only the "standard" return structure (DIMOUSESTATE) is
667   *   supported.
668   */
669 static HRESULT WINAPI SysMouseAImpl_GetDeviceState(
670         LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
671 ) {
672     SysMouseImpl *This = (SysMouseImpl *)iface;
673
674     if(This->acquired == 0) return DIERR_NOTACQUIRED;
675
676     EnterCriticalSection(&(This->crit));
677     TRACE("(this=%p,0x%08lx,%p):\n", This, len, ptr);
678     TRACE("(X: %ld - Y: %ld - Z: %ld  L: %02x M: %02x R: %02x)\n",
679           This->m_state.lX, This->m_state.lY, This->m_state.lZ,
680           This->m_state.rgbButtons[0], This->m_state.rgbButtons[2], This->m_state.rgbButtons[1]);
681     
682     /* Copy the current mouse state */
683     fill_DataFormat(ptr, &(This->m_state), This->wine_df);
684     
685     /* Initialize the buffer when in relative mode */
686     if (This->absolute == 0) {
687         This->m_state.lX = 0;
688         This->m_state.lY = 0;
689         This->m_state.lZ = 0;
690     }
691     
692     /* Check if we need to do a mouse warping */
693     if (This->need_warp == WARP_NEEDED && (GetCurrentTime() - This->last_warped > 10)) {
694         dinput_window_check(This);
695         TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y);
696         SetCursorPos( This->mapped_center.x, This->mapped_center.y );
697         This->last_warped = GetCurrentTime();
698
699 #ifdef MOUSE_HACK
700         This->need_warp = WARP_DONE;
701 #else
702         This->need_warp = WARP_STARTED;
703 #endif
704     }
705     
706     LeaveCriticalSection(&(This->crit));
707     
708     return DI_OK;
709 }
710
711 /******************************************************************************
712   *     GetDeviceData : gets buffered input data.
713   */
714 static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
715                                                   DWORD dodsize,
716                                                   LPDIDEVICEOBJECTDATA dod,
717                                                   LPDWORD entries,
718                                                   DWORD flags
719 ) {
720     SysMouseImpl *This = (SysMouseImpl *)iface;
721     DWORD len;
722     int nqtail = 0;
723     
724     TRACE("(%p)->(dods=%ld,dod=%p,entries=%p (%ld)%s,fl=0x%08lx%s)\n",This,dodsize,dod,
725           entries, *entries,*entries == INFINITE ? " (INFINITE)" : "",
726           flags, (flags & DIGDD_PEEK) ? " (DIGDD_PEEK)": "" );
727     
728     if (This->acquired == 0) {
729         WARN(" application tries to get data from an unacquired device !\n");
730         return DIERR_NOTACQUIRED;
731     }
732     
733     EnterCriticalSection(&(This->crit));
734
735     len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0)
736         + (This->queue_head - This->queue_tail);
737     if ((*entries != INFINITE) && (len > *entries)) len = *entries;
738     
739     if (dod == NULL) {
740         *entries = len;
741         
742         if (!(flags & DIGDD_PEEK)) {
743             if (len)
744                 TRACE("Application discarding %ld event(s).\n", len);
745             
746             nqtail = This->queue_tail + len;
747             while (nqtail >= This->queue_len) nqtail -= This->queue_len;
748         } else {
749             TRACE("Telling application that %ld event(s) are in the queue.\n", len);
750         }
751     } else {
752         if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) {
753             ERR("Wrong structure size !\n");
754             LeaveCriticalSection(&(This->crit));
755             return DIERR_INVALIDPARAM;
756         }
757         
758         if (len)
759             TRACE("Application retrieving %ld event(s):\n", len);
760         
761         *entries = 0;
762         nqtail = This->queue_tail;
763         while (len) {
764             /* Copy the buffered data into the application queue */
765             TRACE(" - queuing Offs:%2ld Data:%5ld TS:%8ld Seq:%8ld at address %p from queue tail %4d\n",
766                   (This->data_queue)->dwOfs,
767                   (This->data_queue)->dwData,
768                   (This->data_queue)->dwTimeStamp,
769                   (This->data_queue)->dwSequence,
770                   (char *)dod + *entries * dodsize,
771                   nqtail);
772             memcpy((char *)dod + *entries * dodsize, This->data_queue + nqtail, dodsize);
773             /* Advance position */
774             nqtail++;
775             if (nqtail >= This->queue_len)
776                 nqtail -= This->queue_len;
777             (*entries)++;
778             len--;
779         }
780     }
781     if (!(flags & DIGDD_PEEK))
782         This->queue_tail = nqtail;
783     
784     LeaveCriticalSection(&(This->crit));
785     
786     /* Check if we need to do a mouse warping */
787     if (This->need_warp == WARP_NEEDED && (GetCurrentTime() - This->last_warped > 10)) {
788         dinput_window_check(This);
789         TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y);
790         SetCursorPos( This->mapped_center.x, This->mapped_center.y );
791         This->last_warped = GetCurrentTime();
792
793 #ifdef MOUSE_HACK
794         This->need_warp = WARP_DONE;
795 #else
796         This->need_warp = WARP_STARTED;
797 #endif
798     }
799     return DI_OK;
800 }
801
802 /******************************************************************************
803   *     SetProperty : change input device properties
804   */
805 static HRESULT WINAPI SysMouseAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
806                                             REFGUID rguid,
807                                             LPCDIPROPHEADER ph)
808 {
809     SysMouseImpl *This = (SysMouseImpl *)iface;
810     
811     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
812     
813     if (!HIWORD(rguid)) {
814         switch (LOWORD(rguid)) {
815             case (DWORD) DIPROP_BUFFERSIZE: {
816                 LPCDIPROPDWORD  pd = (LPCDIPROPDWORD)ph;
817                 
818                 TRACE("buffersize = %ld\n",pd->dwData);
819                 
820                 This->data_queue = HeapAlloc(GetProcessHeap(),0, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
821                 This->queue_head = 0;
822                 This->queue_tail = 0;
823                 This->queue_len  = pd->dwData;
824                 break;
825             }
826             case (DWORD) DIPROP_AXISMODE: {
827                 LPCDIPROPDWORD    pd = (LPCDIPROPDWORD)ph;
828                 This->absolute = !(pd->dwData);
829                 TRACE("Using %s coordinates mode now\n", This->absolute ? "absolute" : "relative");
830                 break;
831             }
832             default:
833               FIXME("Unknown type %p (%s)\n",rguid,debugstr_guid(rguid));
834               break;
835         }
836     }
837     
838     return DI_OK;
839 }
840
841 /******************************************************************************
842   *     GetProperty : get input device properties
843   */
844 static HRESULT WINAPI SysMouseAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
845                                                 REFGUID rguid,
846                                                 LPDIPROPHEADER pdiph)
847 {
848     SysMouseImpl *This = (SysMouseImpl *)iface;
849     
850     TRACE("(this=%p,%s,%p)\n",
851           iface, debugstr_guid(rguid), pdiph);
852     
853     if (TRACE_ON(dinput))
854         _dump_DIPROPHEADER(pdiph);
855     
856     if (!HIWORD(rguid)) {
857         switch (LOWORD(rguid)) {
858             case (DWORD) DIPROP_BUFFERSIZE: {
859                 LPDIPROPDWORD   pd = (LPDIPROPDWORD)pdiph;
860                 
861                 TRACE(" return buffersize = %d\n",This->queue_len);
862                 pd->dwData = This->queue_len;
863                 break;
864             }
865               
866             case (DWORD) DIPROP_GRANULARITY: {
867                 LPDIPROPDWORD pr = (LPDIPROPDWORD) pdiph;
868                 
869                 /* We'll just assume that the app asks about the Z axis */
870                 pr->dwData = WHEEL_DELTA;
871                 
872                 break;
873             }
874               
875             case (DWORD) DIPROP_RANGE: {
876                 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
877                 
878                 if ((pdiph->dwHow == DIPH_BYID) &&
879                     ((pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS)) ||
880                      (pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS)))) {
881                     /* Querying the range of either the X or the Y axis.  As I do
882                        not know the range, do as if the range were
883                        unrestricted...*/
884                     pr->lMin = DIPROPRANGE_NOMIN;
885                     pr->lMax = DIPROPRANGE_NOMAX;
886                 }
887                 
888                 break;
889             }
890               
891             default:
892               FIXME("Unknown type %p (%s)\n",rguid,debugstr_guid(rguid));
893               break;
894           }
895       }
896     
897     return DI_OK;
898 }
899
900
901
902 /******************************************************************************
903   *     SetEventNotification : specifies event to be sent on state change
904   */
905 static HRESULT WINAPI SysMouseAImpl_SetEventNotification(LPDIRECTINPUTDEVICE8A iface,
906                                                          HANDLE hnd) {
907     SysMouseImpl *This = (SysMouseImpl *)iface;
908     
909     TRACE("(this=%p,%p)\n",This,hnd);
910     
911     This->hEvent = hnd;
912     
913     return DI_OK;
914 }
915
916 /******************************************************************************
917   *     GetCapabilities : get the device capablitites
918   */
919 static HRESULT WINAPI SysMouseAImpl_GetCapabilities(
920         LPDIRECTINPUTDEVICE8A iface,
921         LPDIDEVCAPS lpDIDevCaps)
922 {
923     SysMouseImpl *This = (SysMouseImpl *)iface;
924     DIDEVCAPS devcaps;
925
926     TRACE("(this=%p,%p)\n",This,lpDIDevCaps);
927
928     if ((lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) && (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS_DX3))) {
929         WARN("invalid parameter\n");
930         return DIERR_INVALIDPARAM;
931     }
932
933     devcaps.dwSize = lpDIDevCaps->dwSize;
934     devcaps.dwFlags = DIDC_ATTACHED;
935     if (This->dinput->dwVersion >= 0x0800)
936         devcaps.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
937     else
938         devcaps.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
939     devcaps.dwAxes = 3;
940     devcaps.dwButtons = 3;
941     devcaps.dwPOVs = 0;
942     devcaps.dwFFSamplePeriod = 0;
943     devcaps.dwFFMinTimeResolution = 0;
944     devcaps.dwFirmwareRevision = 100;
945     devcaps.dwHardwareRevision = 100;
946     devcaps.dwFFDriverVersion = 0;
947
948     memcpy(lpDIDevCaps, &devcaps, lpDIDevCaps->dwSize);
949     
950     return DI_OK;
951 }
952
953
954 /******************************************************************************
955   *     EnumObjects : enumerate the different buttons and axis...
956   */
957 static HRESULT WINAPI SysMouseAImpl_EnumObjects(
958         LPDIRECTINPUTDEVICE8A iface,
959         LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
960         LPVOID lpvRef,
961         DWORD dwFlags)
962 {
963     SysMouseImpl *This = (SysMouseImpl *)iface;
964     DIDEVICEOBJECTINSTANCEA ddoi;
965     
966     TRACE("(this=%p,%p,%p,%08lx)\n", This, lpCallback, lpvRef, dwFlags);
967     if (TRACE_ON(dinput)) {
968         TRACE("  - flags = ");
969         _dump_EnumObjects_flags(dwFlags);
970         TRACE("\n");
971     }
972     
973     /* Only the fields till dwFFMaxForce are relevant */
974     memset(&ddoi, 0, sizeof(ddoi));
975     ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
976     
977     /* In a mouse, we have : two relative axis and three buttons */
978     if ((dwFlags == DIDFT_ALL) ||
979         (dwFlags & DIDFT_AXIS)) {
980         /* X axis */
981         ddoi.guidType = GUID_XAxis;
982         ddoi.dwOfs = This->offset_array[WINE_MOUSE_X_POSITION];
983         ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS;
984         strcpy(ddoi.tszName, "X-Axis");
985         _dump_OBJECTINSTANCEA(&ddoi);
986         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
987         
988         /* Y axis */
989         ddoi.guidType = GUID_YAxis;
990         ddoi.dwOfs = This->offset_array[WINE_MOUSE_Y_POSITION];
991         ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS;
992         strcpy(ddoi.tszName, "Y-Axis");
993         _dump_OBJECTINSTANCEA(&ddoi);
994         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
995         
996         /* Z axis */
997         ddoi.guidType = GUID_ZAxis;
998         ddoi.dwOfs = This->offset_array[WINE_MOUSE_Z_POSITION];
999         ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS;
1000         strcpy(ddoi.tszName, "Z-Axis");
1001         _dump_OBJECTINSTANCEA(&ddoi);
1002         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1003     }
1004
1005     if ((dwFlags == DIDFT_ALL) ||
1006         (dwFlags & DIDFT_BUTTON)) {
1007         ddoi.guidType = GUID_Button;
1008         
1009         /* Left button */
1010         ddoi.dwOfs = This->offset_array[WINE_MOUSE_L_POSITION];
1011         ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_L_BUTTON_INSTANCE) | DIDFT_PSHBUTTON;
1012         strcpy(ddoi.tszName, "Left-Button");
1013         _dump_OBJECTINSTANCEA(&ddoi);
1014         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1015         
1016         /* Right button */
1017         ddoi.dwOfs = This->offset_array[WINE_MOUSE_R_POSITION];
1018         ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_R_BUTTON_INSTANCE) | DIDFT_PSHBUTTON;
1019         strcpy(ddoi.tszName, "Right-Button");
1020         _dump_OBJECTINSTANCEA(&ddoi);
1021         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1022         
1023         /* Middle button */
1024         ddoi.dwOfs = This->offset_array[WINE_MOUSE_M_POSITION];
1025         ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_M_BUTTON_INSTANCE) | DIDFT_PSHBUTTON;
1026         strcpy(ddoi.tszName, "Middle-Button");
1027         _dump_OBJECTINSTANCEA(&ddoi);
1028         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1029     }
1030     
1031     return DI_OK;
1032 }
1033
1034 static HRESULT WINAPI SysMouseWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface, LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID lpvRef,DWORD dwFlags)
1035 {
1036     SysMouseImpl *This = (SysMouseImpl *)iface;
1037     
1038     device_enumobjects_AtoWcb_data data;
1039     
1040     data.lpCallBack = lpCallback;
1041     data.lpvRef = lpvRef;
1042     
1043     return SysMouseAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A) This, (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, (LPVOID) &data, dwFlags);
1044 }
1045
1046 /******************************************************************************
1047   *     GetDeviceInfo : get information about a device's identity
1048   */
1049 static HRESULT WINAPI SysMouseAImpl_GetDeviceInfo(
1050         LPDIRECTINPUTDEVICE8A iface,
1051         LPDIDEVICEINSTANCEA pdidi)
1052 {
1053     SysMouseImpl *This = (SysMouseImpl *)iface;
1054     TRACE("(this=%p,%p)\n", This, pdidi);
1055
1056     if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA)) {
1057         WARN(" dinput3 not supporte yet...\n");
1058         return DI_OK;
1059     }
1060
1061     fill_mouse_dideviceinstanceA(pdidi, This->dinput->dwVersion);
1062     
1063     return DI_OK;
1064 }
1065
1066 static HRESULT WINAPI SysMouseWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW pdidi)
1067 {
1068     SysMouseImpl *This = (SysMouseImpl *)iface;
1069     TRACE("(this=%p,%p)\n", This, pdidi);
1070
1071     if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)) {
1072         WARN(" dinput3 not supporte yet...\n");
1073         return DI_OK;
1074     }
1075
1076     fill_mouse_dideviceinstanceW(pdidi, This->dinput->dwVersion);
1077     
1078     return DI_OK;
1079 }
1080
1081
1082 static const IDirectInputDevice8AVtbl SysMouseAvt =
1083 {
1084     IDirectInputDevice2AImpl_QueryInterface,
1085     IDirectInputDevice2AImpl_AddRef,
1086     SysMouseAImpl_Release,
1087     SysMouseAImpl_GetCapabilities,
1088     SysMouseAImpl_EnumObjects,
1089     SysMouseAImpl_GetProperty,
1090     SysMouseAImpl_SetProperty,
1091     SysMouseAImpl_Acquire,
1092     SysMouseAImpl_Unacquire,
1093     SysMouseAImpl_GetDeviceState,
1094     SysMouseAImpl_GetDeviceData,
1095     SysMouseAImpl_SetDataFormat,
1096     SysMouseAImpl_SetEventNotification,
1097     SysMouseAImpl_SetCooperativeLevel,
1098     IDirectInputDevice2AImpl_GetObjectInfo,
1099     SysMouseAImpl_GetDeviceInfo,
1100     IDirectInputDevice2AImpl_RunControlPanel,
1101     IDirectInputDevice2AImpl_Initialize,
1102     IDirectInputDevice2AImpl_CreateEffect,
1103     IDirectInputDevice2AImpl_EnumEffects,
1104     IDirectInputDevice2AImpl_GetEffectInfo,
1105     IDirectInputDevice2AImpl_GetForceFeedbackState,
1106     IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1107     IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1108     IDirectInputDevice2AImpl_Escape,
1109     IDirectInputDevice2AImpl_Poll,
1110     IDirectInputDevice2AImpl_SendDeviceData,
1111     IDirectInputDevice7AImpl_EnumEffectsInFile,
1112     IDirectInputDevice7AImpl_WriteEffectToFile,
1113     IDirectInputDevice8AImpl_BuildActionMap,
1114     IDirectInputDevice8AImpl_SetActionMap,
1115     IDirectInputDevice8AImpl_GetImageInfo
1116 };
1117
1118 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1119 # define XCAST(fun)     (typeof(SysMouseWvt.fun))
1120 #else
1121 # define XCAST(fun)     (void*)
1122 #endif
1123
1124 static const IDirectInputDevice8WVtbl SysMouseWvt =
1125 {
1126     IDirectInputDevice2WImpl_QueryInterface,
1127     XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1128     XCAST(Release)SysMouseAImpl_Release,
1129     XCAST(GetCapabilities)SysMouseAImpl_GetCapabilities,
1130     SysMouseWImpl_EnumObjects,
1131     XCAST(GetProperty)SysMouseAImpl_GetProperty,
1132     XCAST(SetProperty)SysMouseAImpl_SetProperty,
1133     XCAST(Acquire)SysMouseAImpl_Acquire,
1134     XCAST(Unacquire)SysMouseAImpl_Unacquire,
1135     XCAST(GetDeviceState)SysMouseAImpl_GetDeviceState,
1136     XCAST(GetDeviceData)SysMouseAImpl_GetDeviceData,
1137     XCAST(SetDataFormat)SysMouseAImpl_SetDataFormat,
1138     XCAST(SetEventNotification)SysMouseAImpl_SetEventNotification,
1139     XCAST(SetCooperativeLevel)SysMouseAImpl_SetCooperativeLevel,
1140     IDirectInputDevice2WImpl_GetObjectInfo,
1141     SysMouseWImpl_GetDeviceInfo,
1142     XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1143     XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1144     XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
1145     IDirectInputDevice2WImpl_EnumEffects,
1146     IDirectInputDevice2WImpl_GetEffectInfo,
1147     XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
1148     XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1149     XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1150     XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1151     XCAST(Poll)IDirectInputDevice2AImpl_Poll,
1152     XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1153     IDirectInputDevice7WImpl_EnumEffectsInFile,
1154     IDirectInputDevice7WImpl_WriteEffectToFile,
1155     IDirectInputDevice8WImpl_BuildActionMap,
1156     IDirectInputDevice8WImpl_SetActionMap,
1157     IDirectInputDevice8WImpl_GetImageInfo
1158 };
1159 #undef XCAST