Fixed joystick device type for dinput8.
[wine] / dlls / dinput / joystick_linux.c
1 /*              DirectInput Joystick device
2  *
3  * Copyright 1998 Marcus Meissner
4  * Copyright 1998,1999 Lionel Ulmer
5  * Copyright 2000-2001 TransGaming Technologies Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #ifdef HAVE_LINUX_22_JOYSTICK_API
26
27 #include <stdarg.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <time.h>
31 #ifdef HAVE_UNISTD_H
32 # include <unistd.h>
33 #endif
34 #ifdef HAVE_SYS_TIME_H
35 # include <sys/time.h>
36 #endif
37 #include <sys/fcntl.h>
38 #ifdef HAVE_SYS_IOCTL_H
39 # include <sys/ioctl.h>
40 #endif
41 #include <errno.h>
42 #ifdef HAVE_SYS_ERRNO_H
43 # include <sys/errno.h>
44 #endif
45 #ifdef HAVE_LINUX_IOCTL_H
46 # include <linux/ioctl.h>
47 #endif
48 #ifdef HAVE_LINUX_JOYSTICK_H
49 # include <linux/joystick.h>
50 #endif
51 #define JOYDEV  "/dev/js0"
52
53 #include "wine/debug.h"
54 #include "wine/unicode.h"
55 #include "windef.h"
56 #include "winbase.h"
57 #include "winerror.h"
58 #include "dinput.h"
59
60 #include "dinput_private.h"
61 #include "device_private.h"
62
63 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
64
65 /* Wine joystick driver object instances */
66 #define WINE_JOYSTICK_AXIS_BASE   0
67 #define WINE_JOYSTICK_BUTTON_BASE 8
68
69 typedef struct JoystickImpl JoystickImpl;
70 static ICOM_VTABLE(IDirectInputDevice8A) JoystickAvt;
71 static ICOM_VTABLE(IDirectInputDevice8W) JoystickWvt;
72 struct JoystickImpl
73 {
74         LPVOID                          lpVtbl;
75         DWORD                           ref;
76         GUID                            guid;
77
78         /* The 'parent' DInput */
79         IDirectInputImpl               *dinput;
80
81         /* joystick private */
82         int                             joyfd;
83         LPDIDATAFORMAT                  df;
84         HANDLE                          hEvent;
85         LONG                            lMin,lMax,deadzone;
86         LPDIDEVICEOBJECTDATA            data_queue;
87         int                             queue_head, queue_tail, queue_len;
88         DIJOYSTATE2                     js;
89 };
90
91 static GUID DInput_Wine_Joystick_GUID = { /* 9e573ed9-7734-11d2-8d4a-23903fb6bdf7 */
92   0x9e573ed9,
93   0x7734,
94   0x11d2,
95   {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
96 };
97
98 static BOOL joydev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, int version)
99 {
100   int fd = -1;
101
102   if (dwFlags & DIEDFL_FORCEFEEDBACK)
103     return FALSE;
104
105   if ((dwDevType==0) || (GET_DIDEVICE_TYPE(dwDevType)==DIDEVTYPE_JOYSTICK)) {
106     /* check whether we have a joystick */
107     if ((fd = open(JOYDEV,O_RDONLY) != -1) || (errno!=ENODEV && errno!=ENOENT)) {
108       TRACE("Enumerating the linux Joystick device\n");
109
110       /* Return joystick */
111       lpddi->guidInstance       = GUID_Joystick;
112       lpddi->guidProduct        = DInput_Wine_Joystick_GUID;
113       /* we only support traditional joysticks for now */
114       if (version >= 8)
115         lpddi->dwDevType        = DI8DEVTYPE_JOYSTICK | (DI8DEVTYPEJOYSTICK_STANDARD << 8);
116       else
117         lpddi->dwDevType        = DIDEVTYPE_JOYSTICK | (DIDEVTYPEJOYSTICK_TRADITIONAL << 8);
118       strcpy(lpddi->tszInstanceName,    "Joystick");
119       /* ioctl JSIOCGNAME(len) */
120       strcpy(lpddi->tszProductName,     "Wine Joystick");
121
122       lpddi->guidFFDriver = GUID_NULL;
123       if (fd != -1)
124         close(fd);
125       return TRUE;
126     }
127   }
128
129   return FALSE;
130 }
131
132 static BOOL joydev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, int version)
133 {
134   int fd = -1;
135
136   if (dwFlags & DIEDFL_FORCEFEEDBACK)
137     return FALSE;
138
139   if ((dwDevType==0) || (GET_DIDEVICE_TYPE(dwDevType)==DIDEVTYPE_JOYSTICK)) {
140     /* check whether we have a joystick */
141     if ((fd = open(JOYDEV,O_RDONLY) != -1) || (errno!=ENODEV && errno!=ENOENT)) {
142       TRACE("Enumerating the linux Joystick device\n");
143
144       /* Return joystick */
145       lpddi->guidInstance       = GUID_Joystick;
146       lpddi->guidProduct        = DInput_Wine_Joystick_GUID;
147       /* we only support traditional joysticks for now */
148       lpddi->dwDevType  = DIDEVTYPE_JOYSTICK |
149                          (DIDEVTYPEJOYSTICK_TRADITIONAL<<8);
150
151       MultiByteToWideChar(CP_ACP, 0, "Joystick", -1, lpddi->tszInstanceName, MAX_PATH);
152       /* ioctl JSIOCGNAME(len) */
153       MultiByteToWideChar(CP_ACP, 0, "Wine Joystick", -1, lpddi->tszProductName, MAX_PATH);
154       lpddi->guidFFDriver = GUID_NULL;
155       if (fd != -1)
156         close(fd);
157       return TRUE;
158     }
159   }
160
161   return FALSE;
162 }
163
164 static JoystickImpl *alloc_device(REFGUID rguid, LPVOID jvt, IDirectInputImpl *dinput)
165 {
166   JoystickImpl* newDevice;
167
168   newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(JoystickImpl));
169   newDevice->lpVtbl = jvt;
170   newDevice->ref = 1;
171   newDevice->joyfd = -1;
172   newDevice->lMin = -32768;
173   newDevice->lMax = +32767;
174   newDevice->dinput = dinput;
175   memcpy(&(newDevice->guid),rguid,sizeof(*rguid));
176
177   return newDevice;
178 }
179
180 static HRESULT joydev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
181 {
182   if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
183       (IsEqualGUID(&DInput_Wine_Joystick_GUID,rguid))) {
184     if ((riid == NULL) ||
185         IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
186         IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
187         IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
188         IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
189       *pdev=(IDirectInputDeviceA*) alloc_device(rguid, &JoystickAvt, dinput);
190
191       TRACE("Creating a Joystick device (%p)\n", *pdev);
192       return DI_OK;
193     } else
194       return DIERR_NOINTERFACE;
195   }
196
197   return DIERR_DEVICENOTREG;
198 }
199
200 static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
201 {
202   if ((IsEqualGUID(&GUID_Joystick,rguid)) ||
203       (IsEqualGUID(&DInput_Wine_Joystick_GUID,rguid))) {
204     if ((riid == NULL) ||
205         IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
206         IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
207         IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
208         IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
209       *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &JoystickWvt, dinput);
210
211       TRACE("Creating a Joystick device (%p)\n", *pdev);
212       return DI_OK;
213     } else
214       return DIERR_NOINTERFACE;
215   }
216
217   return DIERR_DEVICENOTREG;
218 }
219
220 static dinput_device joydev = {
221   10,
222   joydev_enum_deviceA,
223   joydev_enum_deviceW,
224   joydev_create_deviceA,
225   joydev_create_deviceW
226 };
227
228 DECL_GLOBAL_CONSTRUCTOR(joydev_register) { dinput_register_device(&joydev); }
229
230 /******************************************************************************
231  *      Joystick
232  */
233 static ULONG WINAPI JoystickAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
234 {
235         ICOM_THIS(JoystickImpl,iface);
236
237         This->ref--;
238         if (This->ref)
239                 return This->ref;
240
241         /* Free the data queue */
242         if (This->data_queue != NULL)
243           HeapFree(GetProcessHeap(),0,This->data_queue);
244
245         /* Free the DataFormat */
246         HeapFree(GetProcessHeap(), 0, This->df);
247
248         HeapFree(GetProcessHeap(),0,This);
249         return 0;
250 }
251
252 /******************************************************************************
253   *   SetDataFormat : the application can choose the format of the data
254   *   the device driver sends back with GetDeviceState.
255   */
256 static HRESULT WINAPI JoystickAImpl_SetDataFormat(
257         LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
258 )
259 {
260   ICOM_THIS(JoystickImpl,iface);
261   int i;
262
263   TRACE("(this=%p,%p)\n",This,df);
264
265   TRACE("(df.dwSize=%ld)\n",df->dwSize);
266   TRACE("(df.dwObjsize=%ld)\n",df->dwObjSize);
267   TRACE("(df.dwFlags=0x%08lx)\n",df->dwFlags);
268   TRACE("(df.dwDataSize=%ld)\n",df->dwDataSize);
269   TRACE("(df.dwNumObjs=%ld)\n",df->dwNumObjs);
270
271   for (i=0;i<df->dwNumObjs;i++) {
272     TRACE("df.rgodf[%d].guid %s (%p)\n",i,debugstr_guid(df->rgodf[i].pguid), df->rgodf[i].pguid);
273     TRACE("df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
274     TRACE("dwType 0x%02x,dwInstance %d\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
275     TRACE("df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
276   }
277
278   /* Store the new data format */
279   This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
280   memcpy(This->df, df, df->dwSize);
281   This->df->rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
282   memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
283
284   return 0;
285 }
286
287 /******************************************************************************
288   *     Acquire : gets exclusive control of the joystick
289   */
290 static HRESULT WINAPI JoystickAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
291 {
292     ICOM_THIS(JoystickImpl,iface);
293
294     TRACE("(this=%p)\n",This);
295     if (This->joyfd!=-1)
296         return 0;
297     This->joyfd=open(JOYDEV,O_RDONLY);
298     if (This->joyfd==-1)
299         return DIERR_NOTFOUND;
300     return 0;
301 }
302
303 /******************************************************************************
304   *     Unacquire : frees the joystick
305   */
306 static HRESULT WINAPI JoystickAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
307 {
308     ICOM_THIS(JoystickImpl,iface);
309
310     TRACE("(this=%p)\n",This);
311     if (This->joyfd!=-1) {
312         close(This->joyfd);
313         This->joyfd = -1;
314         return DI_OK;
315     }
316     else 
317         return DI_NOEFFECT;
318 }
319
320 #define map_axis(val) ((val+32768)*(This->lMax-This->lMin)/65536+This->lMin)
321
322 static void joy_polldev(JoystickImpl *This) {
323     struct timeval tv;
324     fd_set      readfds;
325     struct      js_event jse;
326
327     if (This->joyfd==-1)
328         return;
329     while (1) {
330         memset(&tv,0,sizeof(tv));
331         FD_ZERO(&readfds);FD_SET(This->joyfd,&readfds);
332         if (1>select(This->joyfd+1,&readfds,NULL,NULL,&tv))
333             return;
334         /* we have one event, so we can read */
335         if (sizeof(jse)!=read(This->joyfd,&jse,sizeof(jse))) {
336             return;
337         }
338         TRACE("js_event: type 0x%x, number %d, value %d\n",jse.type,jse.number,jse.value);
339         if (jse.type & JS_EVENT_BUTTON) {
340             GEN_EVENT(DIJOFS_BUTTON(jse.number),jse.value?0x80:0x00,jse.time,(This->dinput->evsequence)++);
341             This->js.rgbButtons[jse.number] = jse.value?0x80:0x00;
342         }
343         if (jse.type & JS_EVENT_AXIS) {
344             switch (jse.number) {
345             case 0:
346                 GEN_EVENT(jse.number*4,jse.value,jse.time,(This->dinput->evsequence)++);
347                 This->js.lX = map_axis(jse.value);
348                 break;
349             case 1:
350                 GEN_EVENT(jse.number*4,jse.value,jse.time,(This->dinput->evsequence)++);
351                 This->js.lY = map_axis(jse.value);
352                 break;
353             case 2:
354                 GEN_EVENT(jse.number*4,jse.value,jse.time,(This->dinput->evsequence)++);
355                 This->js.lZ = map_axis(jse.value);
356                 break;
357             default:
358                 FIXME("more than 3 axes (%d) not handled!\n",jse.number);
359                 break;
360             }
361         }
362     }
363 }
364
365 /******************************************************************************
366   *     GetDeviceState : returns the "state" of the joystick.
367   *
368   */
369 static HRESULT WINAPI JoystickAImpl_GetDeviceState(
370         LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
371 ) {
372     ICOM_THIS(JoystickImpl,iface);
373
374     joy_polldev(This);
375     TRACE("(this=%p,0x%08lx,%p)\n",This,len,ptr);
376     if ((len != sizeof(DIJOYSTATE)) && (len != sizeof(DIJOYSTATE2))) {
377         FIXME("len %ld is not sizeof(DIJOYSTATE), unsupported format.\n",len);
378         return E_FAIL;
379     }
380     memcpy(ptr,&(This->js),len);
381     This->queue_head = 0;
382     This->queue_tail = 0;
383     return 0;
384 }
385
386 /******************************************************************************
387   *     GetDeviceData : gets buffered input data.
388   */
389 static HRESULT WINAPI JoystickAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
390                                               DWORD dodsize,
391                                               LPDIDEVICEOBJECTDATA dod,
392                                               LPDWORD entries,
393                                               DWORD flags
394 ) {
395   ICOM_THIS(JoystickImpl,iface);
396
397   FIXME("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx),STUB!\n",This,dodsize,*entries,flags);
398
399   joy_polldev(This);
400   if (flags & DIGDD_PEEK)
401     FIXME("DIGDD_PEEK\n");
402
403   if (dod == NULL) {
404   } else {
405   }
406   return 0;
407 }
408
409 /******************************************************************************
410   *     SetProperty : change input device properties
411   */
412 static HRESULT WINAPI JoystickAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
413                                             REFGUID rguid,
414                                             LPCDIPROPHEADER ph)
415 {
416   ICOM_THIS(JoystickImpl,iface);
417
418   FIXME("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
419   FIXME("ph.dwSize = %ld, ph.dwHeaderSize =%ld, ph.dwObj = %ld, ph.dwHow= %ld\n",ph->dwSize, ph->dwHeaderSize,ph->dwObj,ph->dwHow);
420
421   if (!HIWORD(rguid)) {
422     switch ((DWORD)rguid) {
423     case (DWORD) DIPROP_BUFFERSIZE: {
424       LPCDIPROPDWORD    pd = (LPCDIPROPDWORD)ph;
425
426       FIXME("buffersize = %ld\n",pd->dwData);
427       break;
428     }
429     case (DWORD)DIPROP_RANGE: {
430       LPCDIPROPRANGE    pr = (LPCDIPROPRANGE)ph;
431
432       FIXME("proprange(%ld,%ld)\n",pr->lMin,pr->lMax);
433       This->lMin = pr->lMin;
434       This->lMax = pr->lMax;
435       break;
436     }
437     case (DWORD)DIPROP_DEADZONE: {
438       LPCDIPROPDWORD    pd = (LPCDIPROPDWORD)ph;
439
440       FIXME("deadzone(%ld)\n",pd->dwData);
441       This->deadzone = pd->dwData;
442       break;
443     }
444     default:
445       FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
446       break;
447     }
448   }
449   return 0;
450 }
451
452 /******************************************************************************
453   *     SetEventNotification : specifies event to be sent on state change
454   */
455 static HRESULT WINAPI JoystickAImpl_SetEventNotification(
456         LPDIRECTINPUTDEVICE8A iface, HANDLE hnd
457 ) {
458     ICOM_THIS(JoystickImpl,iface);
459
460     TRACE("(this=%p,0x%08lx)\n",This,(DWORD)hnd);
461     This->hEvent = hnd;
462     return DI_OK;
463 }
464
465 static HRESULT WINAPI JoystickAImpl_GetCapabilities(
466         LPDIRECTINPUTDEVICE8A iface,
467         LPDIDEVCAPS lpDIDevCaps)
468 {
469     ICOM_THIS(JoystickImpl,iface);
470     BYTE        axes,buttons;
471     int         xfd = This->joyfd;
472
473     TRACE("%p->(%p)\n",iface,lpDIDevCaps);
474     if (xfd==-1)
475         xfd = open(JOYDEV,O_RDONLY);
476     lpDIDevCaps->dwFlags        = DIDC_ATTACHED;
477     lpDIDevCaps->dwDevType      = DIDEVTYPE_JOYSTICK;
478 #ifdef JSIOCGAXES
479     if (-1==ioctl(xfd,JSIOCGAXES,&axes))
480         axes = 2;
481     lpDIDevCaps->dwAxes = axes;
482 #endif
483 #ifdef JSIOCGBUTTONS
484     if (-1==ioctl(xfd,JSIOCGAXES,&buttons))
485         buttons = 2;
486     lpDIDevCaps->dwButtons = buttons;
487 #endif
488     if (xfd!=This->joyfd)
489         close(xfd);
490     return DI_OK;
491 }
492 static HRESULT WINAPI JoystickAImpl_Poll(LPDIRECTINPUTDEVICE8A iface) {
493     ICOM_THIS(JoystickImpl,iface);
494     TRACE("(),stub!\n");
495
496     joy_polldev(This);
497     return DI_OK;
498 }
499
500 /******************************************************************************
501   *     EnumObjects : enumerate the different buttons and axis...
502   */
503 static HRESULT WINAPI JoystickAImpl_EnumObjects(
504         LPDIRECTINPUTDEVICE8A iface,
505         LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
506         LPVOID lpvRef,
507         DWORD dwFlags)
508 {
509   ICOM_THIS(JoystickImpl,iface);
510   DIDEVICEOBJECTINSTANCEA ddoi;
511   int xfd = This->joyfd;
512
513   TRACE("(this=%p,%p,%p,%08lx)\n", This, lpCallback, lpvRef, dwFlags);
514   if (TRACE_ON(dinput)) {
515     TRACE("  - flags = ");
516     _dump_EnumObjects_flags(dwFlags);
517     TRACE("\n");
518   }
519
520   /* Only the fields till dwFFMaxForce are relevant */
521   ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
522
523   /* For the joystick, do as is done in the GetCapabilities function */
524   if ((dwFlags == DIDFT_ALL) ||
525       (dwFlags & DIDFT_AXIS)) {
526     BYTE axes, i;
527
528 #ifdef JSIOCGAXES
529     if (-1==ioctl(xfd,JSIOCGAXES,&axes))
530       axes = 2;
531 #endif
532
533     for (i = 0; i < axes; i++) {
534       switch (i) {
535       case 0:
536         ddoi.guidType = GUID_XAxis;
537         ddoi.dwOfs = DIJOFS_X;
538         break;
539       case 1:
540         ddoi.guidType = GUID_YAxis;
541         ddoi.dwOfs = DIJOFS_Y;
542         break;
543       case 2:
544         ddoi.guidType = GUID_ZAxis;
545         ddoi.dwOfs = DIJOFS_Z;
546         break;
547       default:
548         ddoi.guidType = GUID_Unknown;
549         ddoi.dwOfs = DIJOFS_Z + (i - 2) * sizeof(LONG);
550       }
551       ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << i) << WINE_JOYSTICK_AXIS_BASE) | DIDFT_ABSAXIS;
552       sprintf(ddoi.tszName, "%d-Axis", i);
553       _dump_OBJECTINSTANCEA(&ddoi);
554       if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
555     }
556   }
557
558   if ((dwFlags == DIDFT_ALL) ||
559       (dwFlags & DIDFT_BUTTON)) {
560     BYTE buttons, i;
561
562 #ifdef JSIOCGBUTTONS
563     if (-1==ioctl(xfd,JSIOCGAXES,&buttons))
564       buttons = 2;
565 #endif
566
567     /* The DInput SDK says that GUID_Button is only for mouse buttons but well... */
568     ddoi.guidType = GUID_Button;
569
570     for (i = 0; i < buttons; i++) {
571       ddoi.dwOfs = DIJOFS_BUTTON(i);
572       ddoi.dwType = DIDFT_MAKEINSTANCE((0x0001 << i) << WINE_JOYSTICK_BUTTON_BASE) | DIDFT_PSHBUTTON;
573       sprintf(ddoi.tszName, "%d-Button", i);
574       _dump_OBJECTINSTANCEA(&ddoi);
575       if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
576     }
577   }
578
579   if (xfd!=This->joyfd)
580     close(xfd);
581
582   return DI_OK;
583 }
584
585 /******************************************************************************
586   *     EnumObjects : enumerate the different buttons and axis...
587   */
588 static HRESULT WINAPI JoystickWImpl_EnumObjects(
589         LPDIRECTINPUTDEVICE8W iface,
590         LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
591         LPVOID lpvRef,
592         DWORD dwFlags)
593 {
594   ICOM_THIS(JoystickImpl,iface);
595
596   device_enumobjects_AtoWcb_data data;
597
598   data.lpCallBack = lpCallback;
599   data.lpvRef = lpvRef;
600
601   return JoystickAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A) This, (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, (LPVOID) &data, dwFlags);
602 }
603
604 /******************************************************************************
605   *     GetProperty : get input device properties
606   */
607 static HRESULT WINAPI JoystickAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
608                                                 REFGUID rguid,
609                                                 LPDIPROPHEADER pdiph)
610 {
611   ICOM_THIS(JoystickImpl,iface);
612
613   TRACE("(this=%p,%s,%p): stub!\n",
614         iface, debugstr_guid(rguid), pdiph);
615
616   if (TRACE_ON(dinput))
617     _dump_DIPROPHEADER(pdiph);
618
619   if (!HIWORD(rguid)) {
620     switch ((DWORD)rguid) {
621     case (DWORD) DIPROP_BUFFERSIZE: {
622       LPDIPROPDWORD     pd = (LPDIPROPDWORD)pdiph;
623
624       TRACE(" return buffersize = %d\n",This->queue_len);
625       pd->dwData = This->queue_len;
626       break;
627     }
628
629     case (DWORD) DIPROP_RANGE: {
630       LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
631
632       if ((pdiph->dwHow == DIPH_BYID) &&
633           (pdiph->dwObj & DIDFT_ABSAXIS)) {
634         /* The app is querying the current range of the axis : return the lMin and lMax values */
635         pr->lMin = This->lMin;
636         pr->lMax = This->lMax;
637       }
638
639       break;
640     }
641
642     default:
643       FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
644       break;
645     }
646   }
647
648
649   return DI_OK;
650 }
651
652 static ICOM_VTABLE(IDirectInputDevice8A) JoystickAvt =
653 {
654         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
655         IDirectInputDevice2AImpl_QueryInterface,
656         IDirectInputDevice2AImpl_AddRef,
657         JoystickAImpl_Release,
658         JoystickAImpl_GetCapabilities,
659         JoystickAImpl_EnumObjects,
660         JoystickAImpl_GetProperty,
661         JoystickAImpl_SetProperty,
662         JoystickAImpl_Acquire,
663         JoystickAImpl_Unacquire,
664         JoystickAImpl_GetDeviceState,
665         JoystickAImpl_GetDeviceData,
666         JoystickAImpl_SetDataFormat,
667         JoystickAImpl_SetEventNotification,
668         IDirectInputDevice2AImpl_SetCooperativeLevel,
669         IDirectInputDevice2AImpl_GetObjectInfo,
670         IDirectInputDevice2AImpl_GetDeviceInfo,
671         IDirectInputDevice2AImpl_RunControlPanel,
672         IDirectInputDevice2AImpl_Initialize,
673         IDirectInputDevice2AImpl_CreateEffect,
674         IDirectInputDevice2AImpl_EnumEffects,
675         IDirectInputDevice2AImpl_GetEffectInfo,
676         IDirectInputDevice2AImpl_GetForceFeedbackState,
677         IDirectInputDevice2AImpl_SendForceFeedbackCommand,
678         IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
679         IDirectInputDevice2AImpl_Escape,
680         JoystickAImpl_Poll,
681         IDirectInputDevice2AImpl_SendDeviceData,
682         IDirectInputDevice7AImpl_EnumEffectsInFile,
683         IDirectInputDevice7AImpl_WriteEffectToFile,
684         IDirectInputDevice8AImpl_BuildActionMap,
685         IDirectInputDevice8AImpl_SetActionMap,
686         IDirectInputDevice8AImpl_GetImageInfo
687 };
688
689 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
690 # define XCAST(fun)     (typeof(SysJoystickWvt.fun))
691 #else
692 # define XCAST(fun)     (void*)
693 #endif
694
695 static ICOM_VTABLE(IDirectInputDevice8W) SysJoystickWvt =
696 {
697         ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
698         IDirectInputDevice2WImpl_QueryInterface,
699         XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
700         XCAST(Release)JoystickAImpl_Release,
701         XCAST(GetCapabilities)JoystickAImpl_GetCapabilities,
702         JoystickWImpl_EnumObjects,
703         XCAST(GetProperty)JoystickAImpl_GetProperty,
704         XCAST(SetProperty)JoystickAImpl_SetProperty,
705         XCAST(Acquire)JoystickAImpl_Acquire,
706         XCAST(Unacquire)JoystickAImpl_Unacquire,
707         XCAST(GetDeviceState)JoystickAImpl_GetDeviceState,
708         XCAST(GetDeviceData)JoystickAImpl_GetDeviceData,
709         XCAST(SetDataFormat)JoystickAImpl_SetDataFormat,
710         XCAST(SetEventNotification)JoystickAImpl_SetEventNotification,
711         XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
712         IDirectInputDevice2WImpl_GetObjectInfo,
713         IDirectInputDevice2WImpl_GetDeviceInfo,
714         XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
715         XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
716         XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
717         IDirectInputDevice2WImpl_EnumEffects,
718         IDirectInputDevice2WImpl_GetEffectInfo,
719         XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
720         XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
721         XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
722         XCAST(Escape)IDirectInputDevice2AImpl_Escape,
723         XCAST(Poll)JoystickAImpl_Poll,
724         XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
725         IDirectInputDevice7WImpl_EnumEffectsInFile,
726         IDirectInputDevice7WImpl_WriteEffectToFile,
727         IDirectInputDevice8WImpl_BuildActionMap,
728         IDirectInputDevice8WImpl_SetActionMap,
729         IDirectInputDevice8WImpl_GetImageInfo
730 };
731 #undef XCAST
732
733 #endif  /* HAVE_LINUX_22_JOYSTICK_API */