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