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