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