avifil32: Use HeapAlloc instead of Local Alloc.
[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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  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     HHOOK                           hook;
130     HWND                            win;
131     DWORD                           dwCoopLevel;
132     POINT                           mapped_center;
133     DWORD                           win_centerX, win_centerY;
134     LPDIDEVICEOBJECTDATA            data_queue;
135     int                             queue_head, queue_tail, queue_len;
136     BOOL                            overflow;
137     /* warping: whether we need to move mouse back to middle once we
138      * reach window borders (for e.g. shooters, "surface movement" games) */
139     WARP_STATUS                     need_warp;
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     /* Free the data queue */
334     HeapFree(GetProcessHeap(),0,This->data_queue);
335     
336     if (This->hook) {
337         UnhookWindowsHookEx( This->hook );
338         if (This->dwCoopLevel & DISCL_EXCLUSIVE)
339             ShowCursor(TRUE); /* show cursor */
340     }
341     DeleteCriticalSection(&(This->crit));
342     
343     /* Free the DataFormat */
344     if (This->df != &(Wine_InternalMouseFormat)) {
345         HeapFree(GetProcessHeap(), 0, This->df->rgodf);
346         HeapFree(GetProcessHeap(), 0, This->df);
347     }
348     
349     HeapFree(GetProcessHeap(),0,This);
350     return 0;
351 }
352
353
354 /******************************************************************************
355   *     SetCooperativeLevel : store the window in which we will do our
356   *   grabbing.
357   */
358 static HRESULT WINAPI SysMouseAImpl_SetCooperativeLevel(
359         LPDIRECTINPUTDEVICE8A iface,HWND hwnd,DWORD dwflags
360 )
361 {
362     SysMouseImpl *This = (SysMouseImpl *)iface;
363     
364     TRACE("(this=%p,%p,0x%08lx)\n",This,hwnd,dwflags);
365     
366     if (TRACE_ON(dinput)) {
367         TRACE(" cooperative level : ");
368         _dump_cooperativelevel_DI(dwflags);
369     }
370     
371     if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND) {
372         return DIERR_UNSUPPORTED;
373     }
374     
375     /* Store the window which asks for the mouse */
376     if (!hwnd)
377         hwnd = GetDesktopWindow();
378     This->win = hwnd;
379     This->dwCoopLevel = dwflags;
380     
381     return DI_OK;
382 }
383
384
385 /******************************************************************************
386   *     SetDataFormat : the application can choose the format of the data
387   *   the device driver sends back with GetDeviceState.
388   *
389   *   For the moment, only the "standard" configuration (c_dfDIMouse) is supported
390   *   in absolute and relative mode.
391   */
392 static HRESULT WINAPI SysMouseAImpl_SetDataFormat(
393         LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
394 )
395 {
396     SysMouseImpl *This = (SysMouseImpl *)iface;
397     
398     TRACE("(this=%p,%p)\n",This,df);
399     
400     _dump_DIDATAFORMAT(df);
401     
402     /* Tests under windows show that a call to SetDataFormat always sets the mouse
403        in relative mode whatever the dwFlags value (DIDF_ABSAXIS/DIDF_RELAXIS).
404        To switch in absolute mode, SetProperty must be used. */
405     This->absolute = 0;
406     
407     /* Store the new data format */
408     This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
409     memcpy(This->df, df, df->dwSize);
410     This->df->rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
411     memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
412     
413     /* Prepare all the data-conversion filters */
414     This->wine_df = create_DataFormat(&(Wine_InternalMouseFormat), df, This->offset_array);
415     
416     return DI_OK;
417 }
418
419 /* low-level mouse hook */
420 static LRESULT CALLBACK dinput_mouse_hook( int code, WPARAM wparam, LPARAM lparam )
421 {
422     LRESULT ret;
423     MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam;
424     SysMouseImpl* This = (SysMouseImpl*) current_lock;
425     DWORD dwCoop;
426     static long last_event = 0;
427     int wdata;
428
429     if (code != HC_ACTION) return CallNextHookEx( This->hook, code, wparam, lparam );
430
431     EnterCriticalSection(&(This->crit));
432     dwCoop = This->dwCoopLevel;
433
434     /* Only allow mouse events every 10 ms.
435      * This is to allow the cursor to start acceleration before
436      * the warps happen. But if it involves a mouse button event we
437      * allow it since we don't want to lose the clicks.
438      */
439     if (((GetCurrentTime() - last_event) < 10)
440         && wparam == WM_MOUSEMOVE)
441         goto end;
442     else last_event = GetCurrentTime();
443     
444     /* Mouse moved -> send event if asked */
445     if (This->hEvent)
446         SetEvent(This->hEvent);
447     
448     if (wparam == WM_MOUSEMOVE) {
449         if (This->absolute) {
450             if (hook->pt.x != This->prevX)
451                 GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x, hook->time, 0);
452             if (hook->pt.y != This->prevY)
453                 GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y, hook->time, 0);
454         } else {
455             /* Now, warp handling */
456             if ((This->need_warp == WARP_STARTED) &&
457                 (hook->pt.x == This->mapped_center.x) && (hook->pt.y == This->mapped_center.y)) {
458                 /* Warp has been done... */
459                 This->need_warp = WARP_DONE;
460                 goto end;
461             }
462             
463             /* Relative mouse input with absolute mouse event : the real fun starts here... */
464             if ((This->need_warp == WARP_NEEDED) ||
465                 (This->need_warp == WARP_STARTED)) {
466                 if (hook->pt.x != This->prevX)
467                     GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->prevX,
468                               hook->time, (This->dinput->evsequence)++);
469                 if (hook->pt.y != This->prevY)
470                     GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->prevY,
471                               hook->time, (This->dinput->evsequence)++);
472             } else {
473                 /* This is the first time the event handler has been called after a
474                    GetDeviceData or GetDeviceState. */
475                 if (hook->pt.x != This->mapped_center.x) {
476                     GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->mapped_center.x,
477                               hook->time, (This->dinput->evsequence)++);
478                     This->need_warp = WARP_NEEDED;
479                 }
480                 
481                 if (hook->pt.y != This->mapped_center.y) {
482                     GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->mapped_center.y,
483                               hook->time, (This->dinput->evsequence)++);
484                     This->need_warp = WARP_NEEDED;
485                 }
486             }
487         }
488         
489         This->prevX = hook->pt.x;
490         This->prevY = hook->pt.y;
491         
492         if (This->absolute) {
493             This->m_state.lX = hook->pt.x;
494             This->m_state.lY = hook->pt.y;
495         } else {
496             This->m_state.lX = hook->pt.x - This->mapped_center.x;
497             This->m_state.lY = hook->pt.y - This->mapped_center.y;
498         }
499     }
500     
501     TRACE(" msg %x pt %ld %ld (W=%d)\n",
502           wparam, hook->pt.x, hook->pt.y, (!This->absolute) && This->need_warp );
503     
504     switch(wparam) {
505         case WM_LBUTTONDOWN:
506             GEN_EVENT(This->offset_array[WINE_MOUSE_L_POSITION], 0x80,
507                       hook->time, This->dinput->evsequence++);
508             This->m_state.rgbButtons[0] = 0x80;
509             break;
510         case WM_LBUTTONUP:
511             GEN_EVENT(This->offset_array[WINE_MOUSE_L_POSITION], 0x00,
512                       hook->time, This->dinput->evsequence++);
513             This->m_state.rgbButtons[0] = 0x00;
514             break;
515         case WM_RBUTTONDOWN:
516             GEN_EVENT(This->offset_array[WINE_MOUSE_R_POSITION], 0x80,
517                       hook->time, This->dinput->evsequence++);
518             This->m_state.rgbButtons[1] = 0x80;
519             break;
520         case WM_RBUTTONUP:
521             GEN_EVENT(This->offset_array[WINE_MOUSE_R_POSITION], 0x00,
522                       hook->time, This->dinput->evsequence++);
523             This->m_state.rgbButtons[1] = 0x00;
524             break;
525         case WM_MBUTTONDOWN:
526             GEN_EVENT(This->offset_array[WINE_MOUSE_M_POSITION], 0x80,
527                       hook->time, This->dinput->evsequence++);
528             This->m_state.rgbButtons[2] = 0x80;
529             break;
530         case WM_MBUTTONUP:
531             GEN_EVENT(This->offset_array[WINE_MOUSE_M_POSITION], 0x00,
532                       hook->time, This->dinput->evsequence++);
533             This->m_state.rgbButtons[2] = 0x00;
534             break;
535         case WM_MOUSEWHEEL:
536             wdata = (short)HIWORD(hook->mouseData);
537             GEN_EVENT(This->offset_array[WINE_MOUSE_Z_POSITION], wdata,
538                       hook->time, This->dinput->evsequence++);
539             This->m_state.lZ += wdata;
540             break;
541     }
542     
543     TRACE("(X: %ld - Y: %ld   L: %02x M: %02x R: %02x)\n",
544           This->m_state.lX, This->m_state.lY,
545           This->m_state.rgbButtons[0], This->m_state.rgbButtons[2], This->m_state.rgbButtons[1]);
546     
547   end:
548     LeaveCriticalSection(&(This->crit));
549     
550     if (dwCoop & DISCL_NONEXCLUSIVE) {
551         /* Pass the events down to previous handlers (e.g. win32 input) */
552         ret = CallNextHookEx( This->hook, code, wparam, lparam );
553     } else {
554         /* Ignore message */
555         ret = 1;
556     }
557     return ret;
558 }
559
560
561 static void dinput_window_check(SysMouseImpl* This) {
562     RECT rect;
563     DWORD centerX, centerY;
564     
565     /* make sure the window hasn't moved */
566     GetWindowRect(This->win, &rect);
567     centerX = (rect.right  - rect.left) / 2;
568     centerY = (rect.bottom - rect.top ) / 2;
569     if (This->win_centerX != centerX || This->win_centerY != centerY) {
570         This->win_centerX = centerX;
571         This->win_centerY = centerY;
572     }
573     This->mapped_center.x = This->win_centerX;
574     This->mapped_center.y = This->win_centerY;
575     MapWindowPoints(This->win, HWND_DESKTOP, &This->mapped_center, 1);
576 }
577
578
579 /******************************************************************************
580   *     Acquire : gets exclusive control of the mouse
581   */
582 static HRESULT WINAPI SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
583 {
584     SysMouseImpl *This = (SysMouseImpl *)iface;
585     RECT  rect;
586     POINT point;
587     
588     TRACE("(this=%p)\n",This);
589     
590     if (This->acquired)
591       return S_FALSE;
592     
593     This->acquired = 1;
594
595     /* Store (in a global variable) the current lock */
596     current_lock = (IDirectInputDevice8A*)This;
597     
598     /* Init the mouse state */
599     GetCursorPos( &point );
600     if (This->absolute) {
601       This->m_state.lX = point.x;
602       This->m_state.lY = point.y;
603       This->prevX = point.x;
604       This->prevY = point.y;
605     } else {
606       This->m_state.lX = 0;
607       This->m_state.lY = 0;
608       This->org_coords = point;
609     }
610     This->m_state.lZ = 0;
611     This->m_state.rgbButtons[0] = GetKeyState(VK_LBUTTON) & 0x80;
612     This->m_state.rgbButtons[1] = GetKeyState(VK_RBUTTON) & 0x80;
613     This->m_state.rgbButtons[2] = GetKeyState(VK_MBUTTON) & 0x80;
614     
615     /* Install our mouse hook */
616     if (This->dwCoopLevel & DISCL_EXCLUSIVE)
617       ShowCursor(FALSE); /* hide cursor */
618     This->hook = SetWindowsHookExA( WH_MOUSE_LL, dinput_mouse_hook, DINPUT_instance, 0 );
619     
620     /* Get the window dimension and find the center */
621     GetWindowRect(This->win, &rect);
622     This->win_centerX = (rect.right  - rect.left) / 2;
623     This->win_centerY = (rect.bottom - rect.top ) / 2;
624     
625     /* Warp the mouse to the center of the window */
626     if (This->absolute == 0) {
627       This->mapped_center.x = This->win_centerX;
628       This->mapped_center.y = This->win_centerY;
629       MapWindowPoints(This->win, HWND_DESKTOP, &This->mapped_center, 1);
630       TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y);
631       SetCursorPos( This->mapped_center.x, This->mapped_center.y );
632 #ifdef MOUSE_HACK
633       This->need_warp = WARP_DONE;
634 #else
635       This->need_warp = WARP_STARTED;
636 #endif
637     }
638         
639     return DI_OK;
640 }
641
642 /******************************************************************************
643   *     Unacquire : frees the mouse
644   */
645 static HRESULT WINAPI SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
646 {
647     SysMouseImpl *This = (SysMouseImpl *)iface;
648     
649     TRACE("(this=%p)\n",This);
650     
651     if (0 == This->acquired) {
652         return DI_NOEFFECT;
653     }
654         
655     /* Reinstall previous mouse event handler */
656     if (This->hook) {
657       UnhookWindowsHookEx( This->hook );
658       This->hook = 0;
659       
660       if (This->dwCoopLevel & DISCL_EXCLUSIVE)
661         ShowCursor(TRUE); /* show cursor */
662     }
663         
664     /* No more locks */
665     if (current_lock == (IDirectInputDevice8A*) This)
666       current_lock = NULL;
667     else
668       ERR("this(%p) != current_lock(%p)\n", This, current_lock);
669
670     /* Unacquire device */
671     This->acquired = 0;
672     
673     /* And put the mouse cursor back where it was at acquire time */
674     if (This->absolute == 0) {
675       TRACE(" warping mouse back to (%ld , %ld)\n", This->org_coords.x, This->org_coords.y);
676       SetCursorPos(This->org_coords.x, This->org_coords.y);
677     }
678         
679     return DI_OK;
680 }
681
682 /******************************************************************************
683   *     GetDeviceState : returns the "state" of the mouse.
684   *
685   *   For the moment, only the "standard" return structure (DIMOUSESTATE) is
686   *   supported.
687   */
688 static HRESULT WINAPI SysMouseAImpl_GetDeviceState(
689         LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
690 ) {
691     SysMouseImpl *This = (SysMouseImpl *)iface;
692
693     if(This->acquired == 0) return DIERR_NOTACQUIRED;
694
695     EnterCriticalSection(&(This->crit));
696     TRACE("(this=%p,0x%08lx,%p):\n", This, len, ptr);
697     TRACE("(X: %ld - Y: %ld - Z: %ld  L: %02x M: %02x R: %02x)\n",
698           This->m_state.lX, This->m_state.lY, This->m_state.lZ,
699           This->m_state.rgbButtons[0], This->m_state.rgbButtons[2], This->m_state.rgbButtons[1]);
700     
701     /* Copy the current mouse state */
702     fill_DataFormat(ptr, &(This->m_state), This->wine_df);
703     
704     /* Initialize the buffer when in relative mode */
705     if (This->absolute == 0) {
706         This->m_state.lX = 0;
707         This->m_state.lY = 0;
708         This->m_state.lZ = 0;
709     }
710     
711     /* Check if we need to do a mouse warping */
712     if (This->need_warp == WARP_NEEDED) {
713         dinput_window_check(This);
714         TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y);
715         SetCursorPos( This->mapped_center.x, This->mapped_center.y );
716         
717 #ifdef MOUSE_HACK
718         This->need_warp = WARP_DONE;
719 #else
720         This->need_warp = WARP_STARTED;
721 #endif
722     }
723     
724     LeaveCriticalSection(&(This->crit));
725     
726     return DI_OK;
727 }
728
729 /******************************************************************************
730   *     GetDeviceData : gets buffered input data.
731   */
732 static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
733                                                   DWORD dodsize,
734                                                   LPDIDEVICEOBJECTDATA dod,
735                                                   LPDWORD entries,
736                                                   DWORD flags
737 ) {
738     SysMouseImpl *This = (SysMouseImpl *)iface;
739     DWORD len;
740     int nqtail = 0;
741     
742     TRACE("(%p)->(dods=%ld,dod=%p,entries=%p (%ld)%s,fl=0x%08lx%s)\n",This,dodsize,dod,
743           entries, *entries,*entries == INFINITE ? " (INFINITE)" : "",
744           flags, (flags & DIGDD_PEEK) ? " (DIGDD_PEEK)": "" );
745     
746     if (This->acquired == 0) {
747         WARN(" application tries to get data from an unacquired device !\n");
748         return DIERR_NOTACQUIRED;
749     }
750     
751     EnterCriticalSection(&(This->crit));
752
753     len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0)
754         + (This->queue_head - This->queue_tail);
755     if ((*entries != INFINITE) && (len > *entries)) len = *entries;
756     
757     if (dod == NULL) {
758         *entries = len;
759         
760         if (!(flags & DIGDD_PEEK)) {
761             if (len)
762                 TRACE("Application discarding %ld event(s).\n", len);
763             
764             nqtail = This->queue_tail + len;
765             while (nqtail >= This->queue_len) nqtail -= This->queue_len;
766         } else {
767             TRACE("Telling application that %ld event(s) are in the queue.\n", len);
768         }
769     } else {
770         if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) {
771             ERR("Wrong structure size !\n");
772             LeaveCriticalSection(&(This->crit));
773             return DIERR_INVALIDPARAM;
774         }
775         
776         if (len)
777             TRACE("Application retrieving %ld event(s):\n", len);
778         
779         *entries = 0;
780         nqtail = This->queue_tail;
781         while (len) {
782             /* Copy the buffered data into the application queue */
783             TRACE(" - queuing Offs:%2ld Data:%5ld TS:%8ld Seq:%8ld at address %p from queue tail %4d\n",
784                   (This->data_queue)->dwOfs,
785                   (This->data_queue)->dwData,
786                   (This->data_queue)->dwTimeStamp,
787                   (This->data_queue)->dwSequence,
788                   (char *)dod + *entries * dodsize,
789                   nqtail);
790             memcpy((char *)dod + *entries * dodsize, This->data_queue + nqtail, dodsize);
791             /* Advance position */
792             nqtail++;
793             if (nqtail >= This->queue_len)
794                 nqtail -= This->queue_len;
795             (*entries)++;
796             len--;
797         }
798     }
799     if (!(flags & DIGDD_PEEK))
800         This->queue_tail = nqtail;
801     
802     LeaveCriticalSection(&(This->crit));
803     
804     /* Check if we need to do a mouse warping */
805     if (This->need_warp == WARP_NEEDED) {
806         dinput_window_check(This);
807         TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y);
808         SetCursorPos( This->mapped_center.x, This->mapped_center.y );
809         
810 #ifdef MOUSE_HACK
811         This->need_warp = WARP_DONE;
812 #else
813         This->need_warp = WARP_STARTED;
814 #endif
815     }
816     return DI_OK;
817 }
818
819 /******************************************************************************
820   *     SetProperty : change input device properties
821   */
822 static HRESULT WINAPI SysMouseAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
823                                             REFGUID rguid,
824                                             LPCDIPROPHEADER ph)
825 {
826     SysMouseImpl *This = (SysMouseImpl *)iface;
827     
828     TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
829     
830     if (!HIWORD(rguid)) {
831         switch (LOWORD(rguid)) {
832             case (DWORD) DIPROP_BUFFERSIZE: {
833                 LPCDIPROPDWORD  pd = (LPCDIPROPDWORD)ph;
834                 
835                 TRACE("buffersize = %ld\n",pd->dwData);
836                 
837                 This->data_queue = HeapAlloc(GetProcessHeap(),0, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
838                 This->queue_head = 0;
839                 This->queue_tail = 0;
840                 This->queue_len  = pd->dwData;
841                 break;
842             }
843             case (DWORD) DIPROP_AXISMODE: {
844                 LPCDIPROPDWORD    pd = (LPCDIPROPDWORD)ph;
845                 This->absolute = !(pd->dwData);
846                 TRACE("Using %s coordinates mode now\n", This->absolute ? "absolute" : "relative");
847                 break;
848             }
849             default:
850               FIXME("Unknown type %p (%s)\n",rguid,debugstr_guid(rguid));
851               break;
852         }
853     }
854     
855     return DI_OK;
856 }
857
858 /******************************************************************************
859   *     GetProperty : get input device properties
860   */
861 static HRESULT WINAPI SysMouseAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
862                                                 REFGUID rguid,
863                                                 LPDIPROPHEADER pdiph)
864 {
865     SysMouseImpl *This = (SysMouseImpl *)iface;
866     
867     TRACE("(this=%p,%s,%p)\n",
868           iface, debugstr_guid(rguid), pdiph);
869     
870     if (TRACE_ON(dinput))
871         _dump_DIPROPHEADER(pdiph);
872     
873     if (!HIWORD(rguid)) {
874         switch (LOWORD(rguid)) {
875             case (DWORD) DIPROP_BUFFERSIZE: {
876                 LPDIPROPDWORD   pd = (LPDIPROPDWORD)pdiph;
877                 
878                 TRACE(" return buffersize = %d\n",This->queue_len);
879                 pd->dwData = This->queue_len;
880                 break;
881             }
882               
883             case (DWORD) DIPROP_GRANULARITY: {
884                 LPDIPROPDWORD pr = (LPDIPROPDWORD) pdiph;
885                 
886                 /* We'll just assume that the app asks about the Z axis */
887                 pr->dwData = WHEEL_DELTA;
888                 
889                 break;
890             }
891               
892             case (DWORD) DIPROP_RANGE: {
893                 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
894                 
895                 if ((pdiph->dwHow == DIPH_BYID) &&
896                     ((pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS)) ||
897                      (pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS)))) {
898                     /* Querying the range of either the X or the Y axis.  As I do
899                        not know the range, do as if the range were
900                        unrestricted...*/
901                     pr->lMin = DIPROPRANGE_NOMIN;
902                     pr->lMax = DIPROPRANGE_NOMAX;
903                 }
904                 
905                 break;
906             }
907               
908             default:
909               FIXME("Unknown type %p (%s)\n",rguid,debugstr_guid(rguid));
910               break;
911           }
912       }
913     
914     return DI_OK;
915 }
916
917
918
919 /******************************************************************************
920   *     SetEventNotification : specifies event to be sent on state change
921   */
922 static HRESULT WINAPI SysMouseAImpl_SetEventNotification(LPDIRECTINPUTDEVICE8A iface,
923                                                          HANDLE hnd) {
924     SysMouseImpl *This = (SysMouseImpl *)iface;
925     
926     TRACE("(this=%p,%p)\n",This,hnd);
927     
928     This->hEvent = hnd;
929     
930     return DI_OK;
931 }
932
933 /******************************************************************************
934   *     GetCapabilities : get the device capablitites
935   */
936 static HRESULT WINAPI SysMouseAImpl_GetCapabilities(
937         LPDIRECTINPUTDEVICE8A iface,
938         LPDIDEVCAPS lpDIDevCaps)
939 {
940     SysMouseImpl *This = (SysMouseImpl *)iface;
941     DIDEVCAPS devcaps;
942
943     TRACE("(this=%p,%p)\n",This,lpDIDevCaps);
944
945     if ((lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) && (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS_DX3))) {
946         WARN("invalid parameter\n");
947         return DIERR_INVALIDPARAM;
948     }
949
950     devcaps.dwSize = lpDIDevCaps->dwSize;
951     devcaps.dwFlags = DIDC_ATTACHED;
952     if (This->dinput->dwVersion >= 0x0800)
953         devcaps.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
954     else
955         devcaps.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
956     devcaps.dwAxes = 3;
957     devcaps.dwButtons = 3;
958     devcaps.dwPOVs = 0;
959     devcaps.dwFFSamplePeriod = 0;
960     devcaps.dwFFMinTimeResolution = 0;
961     devcaps.dwFirmwareRevision = 100;
962     devcaps.dwHardwareRevision = 100;
963     devcaps.dwFFDriverVersion = 0;
964
965     memcpy(lpDIDevCaps, &devcaps, lpDIDevCaps->dwSize);
966     
967     return DI_OK;
968 }
969
970
971 /******************************************************************************
972   *     EnumObjects : enumerate the different buttons and axis...
973   */
974 static HRESULT WINAPI SysMouseAImpl_EnumObjects(
975         LPDIRECTINPUTDEVICE8A iface,
976         LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
977         LPVOID lpvRef,
978         DWORD dwFlags)
979 {
980     SysMouseImpl *This = (SysMouseImpl *)iface;
981     DIDEVICEOBJECTINSTANCEA ddoi;
982     
983     TRACE("(this=%p,%p,%p,%08lx)\n", This, lpCallback, lpvRef, dwFlags);
984     if (TRACE_ON(dinput)) {
985         TRACE("  - flags = ");
986         _dump_EnumObjects_flags(dwFlags);
987         TRACE("\n");
988     }
989     
990     /* Only the fields till dwFFMaxForce are relevant */
991     memset(&ddoi, 0, sizeof(ddoi));
992     ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
993     
994     /* In a mouse, we have : two relative axis and three buttons */
995     if ((dwFlags == DIDFT_ALL) ||
996         (dwFlags & DIDFT_AXIS)) {
997         /* X axis */
998         ddoi.guidType = GUID_XAxis;
999         ddoi.dwOfs = This->offset_array[WINE_MOUSE_X_POSITION];
1000         ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS;
1001         strcpy(ddoi.tszName, "X-Axis");
1002         _dump_OBJECTINSTANCEA(&ddoi);
1003         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1004         
1005         /* Y axis */
1006         ddoi.guidType = GUID_YAxis;
1007         ddoi.dwOfs = This->offset_array[WINE_MOUSE_Y_POSITION];
1008         ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS;
1009         strcpy(ddoi.tszName, "Y-Axis");
1010         _dump_OBJECTINSTANCEA(&ddoi);
1011         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1012         
1013         /* Z axis */
1014         ddoi.guidType = GUID_ZAxis;
1015         ddoi.dwOfs = This->offset_array[WINE_MOUSE_Z_POSITION];
1016         ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS;
1017         strcpy(ddoi.tszName, "Z-Axis");
1018         _dump_OBJECTINSTANCEA(&ddoi);
1019         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1020     }
1021
1022     if ((dwFlags == DIDFT_ALL) ||
1023         (dwFlags & DIDFT_BUTTON)) {
1024         ddoi.guidType = GUID_Button;
1025         
1026         /* Left button */
1027         ddoi.dwOfs = This->offset_array[WINE_MOUSE_L_POSITION];
1028         ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_L_BUTTON_INSTANCE) | DIDFT_PSHBUTTON;
1029         strcpy(ddoi.tszName, "Left-Button");
1030         _dump_OBJECTINSTANCEA(&ddoi);
1031         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1032         
1033         /* Right button */
1034         ddoi.dwOfs = This->offset_array[WINE_MOUSE_R_POSITION];
1035         ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_R_BUTTON_INSTANCE) | DIDFT_PSHBUTTON;
1036         strcpy(ddoi.tszName, "Right-Button");
1037         _dump_OBJECTINSTANCEA(&ddoi);
1038         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1039         
1040         /* Middle button */
1041         ddoi.dwOfs = This->offset_array[WINE_MOUSE_M_POSITION];
1042         ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_M_BUTTON_INSTANCE) | DIDFT_PSHBUTTON;
1043         strcpy(ddoi.tszName, "Middle-Button");
1044         _dump_OBJECTINSTANCEA(&ddoi);
1045         if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1046     }
1047     
1048     return DI_OK;
1049 }
1050
1051 static HRESULT WINAPI SysMouseWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface, LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID lpvRef,DWORD dwFlags)
1052 {
1053     SysMouseImpl *This = (SysMouseImpl *)iface;
1054     
1055     device_enumobjects_AtoWcb_data data;
1056     
1057     data.lpCallBack = lpCallback;
1058     data.lpvRef = lpvRef;
1059     
1060     return SysMouseAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A) This, (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, (LPVOID) &data, dwFlags);
1061 }
1062
1063 /******************************************************************************
1064   *     GetDeviceInfo : get information about a device's identity
1065   */
1066 static HRESULT WINAPI SysMouseAImpl_GetDeviceInfo(
1067         LPDIRECTINPUTDEVICE8A iface,
1068         LPDIDEVICEINSTANCEA pdidi)
1069 {
1070     SysMouseImpl *This = (SysMouseImpl *)iface;
1071     TRACE("(this=%p,%p)\n", This, pdidi);
1072
1073     if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA)) {
1074         WARN(" dinput3 not supporte yet...\n");
1075         return DI_OK;
1076     }
1077
1078     fill_mouse_dideviceinstanceA(pdidi, This->dinput->dwVersion);
1079     
1080     return DI_OK;
1081 }
1082
1083 static HRESULT WINAPI SysMouseWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW pdidi)
1084 {
1085     SysMouseImpl *This = (SysMouseImpl *)iface;
1086     TRACE("(this=%p,%p)\n", This, pdidi);
1087
1088     if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)) {
1089         WARN(" dinput3 not supporte yet...\n");
1090         return DI_OK;
1091     }
1092
1093     fill_mouse_dideviceinstanceW(pdidi, This->dinput->dwVersion);
1094     
1095     return DI_OK;
1096 }
1097
1098
1099 static const IDirectInputDevice8AVtbl SysMouseAvt =
1100 {
1101     IDirectInputDevice2AImpl_QueryInterface,
1102     IDirectInputDevice2AImpl_AddRef,
1103     SysMouseAImpl_Release,
1104     SysMouseAImpl_GetCapabilities,
1105     SysMouseAImpl_EnumObjects,
1106     SysMouseAImpl_GetProperty,
1107     SysMouseAImpl_SetProperty,
1108     SysMouseAImpl_Acquire,
1109     SysMouseAImpl_Unacquire,
1110     SysMouseAImpl_GetDeviceState,
1111     SysMouseAImpl_GetDeviceData,
1112     SysMouseAImpl_SetDataFormat,
1113     SysMouseAImpl_SetEventNotification,
1114     SysMouseAImpl_SetCooperativeLevel,
1115     IDirectInputDevice2AImpl_GetObjectInfo,
1116     SysMouseAImpl_GetDeviceInfo,
1117     IDirectInputDevice2AImpl_RunControlPanel,
1118     IDirectInputDevice2AImpl_Initialize,
1119     IDirectInputDevice2AImpl_CreateEffect,
1120     IDirectInputDevice2AImpl_EnumEffects,
1121     IDirectInputDevice2AImpl_GetEffectInfo,
1122     IDirectInputDevice2AImpl_GetForceFeedbackState,
1123     IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1124     IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1125     IDirectInputDevice2AImpl_Escape,
1126     IDirectInputDevice2AImpl_Poll,
1127     IDirectInputDevice2AImpl_SendDeviceData,
1128     IDirectInputDevice7AImpl_EnumEffectsInFile,
1129     IDirectInputDevice7AImpl_WriteEffectToFile,
1130     IDirectInputDevice8AImpl_BuildActionMap,
1131     IDirectInputDevice8AImpl_SetActionMap,
1132     IDirectInputDevice8AImpl_GetImageInfo
1133 };
1134
1135 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1136 # define XCAST(fun)     (typeof(SysMouseWvt.fun))
1137 #else
1138 # define XCAST(fun)     (void*)
1139 #endif
1140
1141 static const IDirectInputDevice8WVtbl SysMouseWvt =
1142 {
1143     IDirectInputDevice2WImpl_QueryInterface,
1144     XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1145     XCAST(Release)SysMouseAImpl_Release,
1146     XCAST(GetCapabilities)SysMouseAImpl_GetCapabilities,
1147     SysMouseWImpl_EnumObjects,
1148     XCAST(GetProperty)SysMouseAImpl_GetProperty,
1149     XCAST(SetProperty)SysMouseAImpl_SetProperty,
1150     XCAST(Acquire)SysMouseAImpl_Acquire,
1151     XCAST(Unacquire)SysMouseAImpl_Unacquire,
1152     XCAST(GetDeviceState)SysMouseAImpl_GetDeviceState,
1153     XCAST(GetDeviceData)SysMouseAImpl_GetDeviceData,
1154     XCAST(SetDataFormat)SysMouseAImpl_SetDataFormat,
1155     XCAST(SetEventNotification)SysMouseAImpl_SetEventNotification,
1156     XCAST(SetCooperativeLevel)SysMouseAImpl_SetCooperativeLevel,
1157     IDirectInputDevice2WImpl_GetObjectInfo,
1158     SysMouseWImpl_GetDeviceInfo,
1159     XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1160     XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1161     XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
1162     IDirectInputDevice2WImpl_EnumEffects,
1163     IDirectInputDevice2WImpl_GetEffectInfo,
1164     XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
1165     XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1166     XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1167     XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1168     XCAST(Poll)IDirectInputDevice2AImpl_Poll,
1169     XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1170     IDirectInputDevice7WImpl_EnumEffectsInFile,
1171     IDirectInputDevice7WImpl_WriteEffectToFile,
1172     IDirectInputDevice8WImpl_BuildActionMap,
1173     IDirectInputDevice8WImpl_SetActionMap,
1174     IDirectInputDevice8WImpl_GetImageInfo
1175 };
1176 #undef XCAST