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