Implemented the GetBinaryType API function.
[wine/multimedia.git] / windows / dinput.c
blob1679ccb5057e60784e3d40b68de9a7bc7e23ca7a
1 /* DirectInput
3 * Copyright 1998 Marcus Meissner
5 * Additions (mouse support) Copyright 1998 Lionel Ulmer
6 */
7 /* Status:
9 * - Tomb Raider 2 Demo:
10 * Playable using keyboard only.
11 * - WingCommander Prophecy Demo:
12 * Doesn't get Input Focus.
14 * - Fallout : works great in X and DGA mode
16 * FIXME: The keyboard handling needs to (and will) be merged into keyboard.c
17 * (The current implementation is currently only a proof of concept and
18 * an utter mess.)
21 #include "ts_xlib.h"
23 #include "config.h"
24 #include <string.h>
25 #include <unistd.h>
26 #include <assert.h>
27 #include <sys/signal.h>
29 #include "windows.h"
30 #include "winerror.h"
31 #include "shell.h"
32 #include "ole.h"
33 #include "compobj.h"
34 #include "interfaces.h"
35 #include "gdi.h"
36 #include "heap.h"
37 #include "win.h"
38 #include "dinput.h"
39 #include "debug.h"
40 #include "message.h"
42 extern BYTE InputKeyStateTable[256];
43 extern int min_keycode, max_keycode;
44 extern WORD keyc2vkey[256];
46 static IDirectInputA_VTable ddiavt;
47 static IDirectInputDeviceA_VTable SysKeyboardAvt;
48 static IDirectInputDeviceA_VTable SysMouseAvt;
50 /* UIDs for Wine "drivers".
51 When enumerating each device supporting DInput, they have two UIDs :
52 - the 'windows' UID
53 - a vendor UID */
54 static GUID DInput_Wine_Mouse_GUID = { /* 9e573ed8-7734-11d2-8d4a-23903fb6bdf7 */
55 0x9e573ed8,
56 0x7734,
57 0x11d2,
58 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
60 static GUID DInput_Wine_Keyboard_GUID = { /* 0ab8648a-7735-11d2-8c73-71df54a96441 */
61 0x0ab8648a,
62 0x7735,
63 0x11d2,
64 {0x8c, 0x73, 0x71, 0xdf, 0x54, 0xa9, 0x64, 0x41}
67 /******************************************************************************
68 * DirectInputCreate32A
70 HRESULT WINAPI DirectInputCreate32A(HINSTANCE32 hinst, DWORD dwVersion, LPDIRECTINPUT32A *ppDI, LPUNKNOWN punkOuter) {
71 TRACE(dinput, "(0x%08lx,%04lx,%p,%p)\n",
72 (DWORD)hinst,dwVersion,ppDI,punkOuter
74 (*ppDI) = (LPDIRECTINPUT32A)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInput32A));
75 (*ppDI)->ref = 1;
76 (*ppDI)->lpvtbl = &ddiavt;
77 return 0;
79 /******************************************************************************
80 * IDirectInputA_EnumDevices
82 static HRESULT WINAPI IDirectInputA_EnumDevices(
83 LPDIRECTINPUT32A this, DWORD dwDevType, LPDIENUMDEVICESCALLBACK32A lpCallback,
84 LPVOID pvRef, DWORD dwFlags
85 ) {
86 DIDEVICEINSTANCE32A devInstance;
87 int ret;
89 TRACE(dinput, "(this=%p,0x%04lx,%p,%p,%04lx)\n", this, dwDevType, lpCallback, pvRef, dwFlags);
91 devInstance.dwSize = sizeof(DIDEVICEINSTANCE32A);
93 if ((dwDevType == 0) || (dwDevType == DIDEVTYPE_KEYBOARD)) {
94 /* Return keyboard */
95 devInstance.guidInstance = GUID_SysKeyboard; /* DInput's GUID */
96 devInstance.guidProduct = DInput_Wine_Keyboard_GUID; /* Vendor's GUID */
97 devInstance.dwDevType = DIDEVTYPE_KEYBOARD | (DIDEVTYPEKEYBOARD_UNKNOWN << 8);
98 strcpy(devInstance.tszInstanceName, "Keyboard");
99 strcpy(devInstance.tszProductName, "Wine Keyboard");
101 ret = lpCallback(&devInstance, pvRef);
102 TRACE(dinput, "Keyboard registered\n");
104 if (ret == DIENUM_STOP)
105 return 0;
108 if ((dwDevType == 0) || (dwDevType == DIDEVTYPE_KEYBOARD)) {
109 /* Return mouse */
110 devInstance.guidInstance = GUID_SysMouse; /* DInput's GUID */
111 devInstance.guidProduct = DInput_Wine_Mouse_GUID; /* Vendor's GUID */
112 devInstance.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_UNKNOWN << 8);
113 strcpy(devInstance.tszInstanceName, "Mouse");
114 strcpy(devInstance.tszProductName, "Wine Mouse");
116 ret = lpCallback(&devInstance, pvRef);
117 TRACE(dinput, "Mouse registered\n");
120 /* Should also do joystick enumerations.... */
122 return 0;
125 static ULONG WINAPI IDirectInputA_AddRef(LPDIRECTINPUT32A this) {
126 return ++(this->ref);
129 static ULONG WINAPI IDirectInputA_Release(LPDIRECTINPUT32A this) {
130 if (!(--this->ref)) {
131 HeapFree(GetProcessHeap(),0,this);
132 return 0;
134 return this->ref;
137 static HRESULT WINAPI IDirectInputA_CreateDevice(
138 LPDIRECTINPUT32A this,REFGUID rguid,LPDIRECTINPUTDEVICE32A* pdev,
139 LPUNKNOWN punk
141 char xbuf[50];
143 WINE_StringFromCLSID(rguid,xbuf);
144 FIXME(dinput,"(this=%p,%s,%p,%p): stub\n",this,xbuf,pdev,punk);
145 if ((!memcmp(&GUID_SysKeyboard,rguid,sizeof(GUID_SysKeyboard))) || /* Generic Keyboard */
146 (!memcmp(&DInput_Wine_Keyboard_GUID,rguid,sizeof(GUID_SysKeyboard)))) { /* Wine Keyboard */
147 *pdev = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysKeyboard32A));
148 (*pdev)->ref = 1;
149 (*pdev)->lpvtbl = &SysKeyboardAvt;
150 memcpy(&((*pdev)->guid),rguid,sizeof(*rguid));
151 memset(((LPSYSKEYBOARD32A)(*pdev))->keystate,0,256);
152 return 0;
154 if ((!memcmp(&GUID_SysMouse,rguid,sizeof(GUID_SysMouse))) || /* Generic Mouse */
155 (!memcmp(&DInput_Wine_Mouse_GUID,rguid,sizeof(GUID_SysKeyboard)))) { /* Wine Mouse */
156 *pdev = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouse32A));
157 (*pdev)->ref = 1;
158 (*pdev)->lpvtbl = &SysMouseAvt;
159 memcpy(&((*pdev)->guid),rguid,sizeof(*rguid));
160 return 0;
162 return E_FAIL;
165 static HRESULT WINAPI IDirectInputA_QueryInterface(
166 LPDIRECTINPUT32A this,REFIID riid,LPVOID *ppobj
168 char xbuf[50];
170 WINE_StringFromCLSID(riid,xbuf);
171 TRACE(dinput,"(this=%p,%s,%p)\n",this,xbuf,ppobj);
172 if (!memcmp(&IID_IUnknown,riid,sizeof(*riid))) {
173 this->lpvtbl->fnAddRef(this);
174 *ppobj = this;
175 return 0;
177 if (!memcmp(&IID_IDirectInputA,riid,sizeof(*riid))) {
178 this->lpvtbl->fnAddRef(this);
179 *ppobj = this;
180 return 0;
182 return E_FAIL;
185 static HRESULT WINAPI IDirectInputA_Initialize(
186 LPDIRECTINPUT32A this,HINSTANCE32 hinst,DWORD x
188 return DIERR_ALREADYINITIALIZED;
191 static IDirectInputA_VTable ddiavt= {
192 IDirectInputA_QueryInterface,
193 IDirectInputA_AddRef,
194 IDirectInputA_Release,
195 IDirectInputA_CreateDevice,
196 IDirectInputA_EnumDevices,
197 (void*)6,
198 (void*)7,
199 IDirectInputA_Initialize
202 /******************************************************************************
203 * IDirectInputDeviceA
205 static HRESULT WINAPI IDirectInputDeviceA_SetDataFormat(
206 LPDIRECTINPUTDEVICE32A this,LPCDIDATAFORMAT df
209 int i;
210 TRACE(dinput,"(this=%p,%p)\n",this,df);
212 TRACE(dinput,"df.dwSize=%ld\n",df->dwSize);
213 TRACE(dinput,"(df.dwObjsize=%ld)\n",df->dwObjSize);
214 TRACE(dinput,"(df.dwFlags=0x%08lx)\n",df->dwFlags);
215 TRACE(dinput,"(df.dwDataSize=%ld)\n",df->dwDataSize);
216 TRACE(dinput,"(df.dwNumObjs=%ld)\n",df->dwNumObjs);
218 for (i=0;i<df->dwNumObjs;i++) {
219 char xbuf[50];
221 if (df->rgodf[i].pguid)
222 WINE_StringFromCLSID(df->rgodf[i].pguid,xbuf);
223 else
224 strcpy(xbuf,"<no guid>");
225 TRACE(dinput,"df.rgodf[%d].guid %s\n",i,xbuf);
226 TRACE(dinput,"df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
227 TRACE(dinput,"dwType 0x%02lx,dwInstance %ld\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
228 TRACE(dinput,"df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
231 return 0;
234 static HRESULT WINAPI IDirectInputDeviceA_SetCooperativeLevel(
235 LPDIRECTINPUTDEVICE32A this,HWND32 hwnd,DWORD dwflags
237 FIXME(dinput,"(this=%p,0x%08lx,0x%08lx): stub\n",this,(DWORD)hwnd,dwflags);
238 return 0;
241 static HRESULT WINAPI IDirectInputDeviceA_SetProperty(
242 LPDIRECTINPUTDEVICE32A this,REFGUID rguid,LPCDIPROPHEADER ph
244 char xbuf[50];
246 if (HIWORD(rguid))
247 WINE_StringFromCLSID(rguid,xbuf);
248 else
249 sprintf(xbuf,"<special guid %ld>",(DWORD)rguid);
250 TRACE(dinput,"(this=%p,%s,%p)\n",this,xbuf,ph);
251 if (!HIWORD(rguid)) {
252 switch ((DWORD)rguid) {
253 case DIPROP_BUFFERSIZE: {
254 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
256 TRACE(dinput,"buffersize = %ld\n",pd->dwData);
257 break;
259 default:
260 WARN(dinput,"Unknown type %ld\n",(DWORD)rguid);
261 break;
264 return 0;
267 static HRESULT WINAPI IDirectInputDeviceA_SetEventNotification(
268 LPDIRECTINPUTDEVICE32A this,HANDLE32 hnd
270 FIXME(dinput,"(this=%p,0x%08lx): stub\n",this,(DWORD)hnd);
271 return 0;
274 static HRESULT WINAPI IDirectInputDeviceA_GetDeviceData(
275 LPDIRECTINPUTDEVICE32A this,DWORD dodsize,LPDIDEVICEOBJECTDATA dod,
276 LPDWORD entries,DWORD flags
278 TRACE(dinput,"IDirectInputDeviceA(%p)->GetDeviceData(%ld,%p,%p(0x%08lx),0x%08lx)\n",
279 this,dodsize,dod,entries,*entries,flags);
280 return 0;
284 static HRESULT WINAPI IDirectInputDeviceA_Acquire(LPDIRECTINPUTDEVICE32A this) {
285 TRACE(dinput,"(this=%p): stub\n",this);
286 return 0;
289 static HRESULT WINAPI IDirectInputDeviceA_Unacquire(LPDIRECTINPUTDEVICE32A this) {
290 TRACE(dinput,"(this=%p): stub\n",this);
291 return 0;
294 static ULONG WINAPI IDirectInputDeviceA_Release(LPDIRECTINPUTDEVICE32A this) {
295 this->ref--;
296 if (this->ref)
297 return this->ref;
298 HeapFree(GetProcessHeap(),0,this);
299 return 0;
302 static HRESULT WINAPI SysKeyboardA_SetProperty(
303 LPDIRECTINPUTDEVICE32A this,REFGUID rguid,LPCDIPROPHEADER ph
305 char xbuf[50];
307 if (HIWORD(rguid))
308 WINE_StringFromCLSID(rguid,xbuf);
309 else
310 sprintf(xbuf,"<special guid %ld>",(DWORD)rguid);
311 TRACE(dinput,"(this=%p,%s,%p)\n",this,xbuf,ph);
312 TRACE(dinput,"(size=%ld,headersize=%ld,obj=%ld,how=%ld\n",
313 ph->dwSize,ph->dwHeaderSize,ph->dwObj,ph->dwHow);
314 if (!HIWORD(rguid)) {
315 switch ((DWORD)rguid) {
316 case DIPROP_BUFFERSIZE: {
317 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
319 TRACE(dinput,"(buffersize=%ld)\n",pd->dwData);
320 break;
322 default:
323 WARN(dinput,"Unknown type %ld\n",(DWORD)rguid);
324 break;
327 return 0;
330 static HRESULT WINAPI SysKeyboardA_GetDeviceState(
331 LPDIRECTINPUTDEVICE32A this,DWORD len,LPVOID ptr
333 if (len==256) {
334 int keyc,vkey;
336 memset(ptr,0,256);
337 for (keyc=min_keycode;keyc<max_keycode;keyc++)
339 /* X keycode to virtual key */
340 vkey = keyc2vkey[keyc] & 0xFF;
341 /* The windows scancode is keyc-min_keycode */
342 if (InputKeyStateTable[vkey]&0x80) {
343 ((LPBYTE)ptr)[keyc-min_keycode]=0x80;
344 ((LPBYTE)ptr)[(keyc-min_keycode)|0x80]=0x80;
347 return 0;
349 WARN(dinput,"whoops, SysKeyboardA_GetDeviceState got len %ld?\n",len);
350 return 0;
353 static HRESULT WINAPI SysKeyboardA_GetDeviceData(
354 LPDIRECTINPUTDEVICE32A this,DWORD dodsize,LPDIDEVICEOBJECTDATA dod,
355 LPDWORD entries,DWORD flags
357 int keyc,n,vkey,xentries;
358 LPSYSKEYBOARD32A kthis = (LPSYSKEYBOARD32A)this;
360 TRACE(dinput,"(this=%p,%ld,%p,%p(%ld)),0x%08lx)\n",
361 this,dodsize,dod,entries,entries?*entries:0,flags);
362 EVENT_WaitNetEvent(FALSE,TRUE);
363 if (entries)
364 xentries = *entries;
365 else
366 xentries = 1;
368 n = 0;
370 for (keyc=min_keycode;(keyc<max_keycode) && (n<*entries);keyc++)
372 /* X keycode to virtual key */
373 vkey = keyc2vkey[keyc] & 0xFF;
374 if (kthis->keystate[vkey] == (InputKeyStateTable[vkey]&0x80))
375 continue;
376 if (dod) {
377 /* add an entry */
378 dod[n].dwOfs = keyc-min_keycode; /* scancode */
379 dod[n].dwData = InputKeyStateTable[vkey]&0x80;
380 dod[n].dwTimeStamp = 0; /* umm */
381 dod[n].dwSequence = 0; /* umm */
382 n++;
384 if (!(flags & DIGDD_PEEK))
385 kthis->keystate[vkey] = InputKeyStateTable[vkey]&0x80;
389 if (n) fprintf(stderr,"%d entries\n",n);
390 *entries = n;
391 return 0;
394 static HRESULT WINAPI SysKeyboardA_Acquire(LPDIRECTINPUTDEVICE32A this) {
395 TRACE(dinput,"(this=%p): stub\n",this);
396 return 0;
399 static HRESULT WINAPI SysKeyboardA_Unacquire(LPDIRECTINPUTDEVICE32A this) {
400 TRACE(dinput,"(this=%p): stub\n",this);
401 return 0;
404 static HRESULT WINAPI IDirectInputDeviceA_QueryInterface(
405 LPDIRECTINPUTDEVICE32A this,REFIID riid,LPVOID *ppobj
407 char xbuf[50];
409 WINE_StringFromCLSID(riid,xbuf);
410 TRACE(dinput,"(this=%p,%s,%p)\n",this,xbuf,ppobj);
411 if (!memcmp(&IID_IUnknown,riid,sizeof(*riid))) {
412 this->lpvtbl->fnAddRef(this);
413 *ppobj = this;
414 return 0;
416 if (!memcmp(&IID_IDirectInputDeviceA,riid,sizeof(*riid))) {
417 this->lpvtbl->fnAddRef(this);
418 *ppobj = this;
419 return 0;
421 if (!memcmp(&IID_IDirectInputDevice2A,riid,sizeof(*riid))) {
422 this->lpvtbl->fnAddRef(this);
423 *ppobj = this;
424 return 0;
426 return E_FAIL;
429 static ULONG WINAPI IDirectInputDeviceA_AddRef(
430 LPDIRECTINPUTDEVICE32A this)
432 return ++this->ref;
435 static HRESULT WINAPI IDirectInputDeviceA_GetCapabilities(
436 LPDIRECTINPUTDEVICE32A this,
437 LPDIDEVCAPS lpDIDevCaps)
439 FIXME(dinput, "stub!\n");
440 return DI_OK;
443 static HRESULT WINAPI IDirectInputDeviceA_EnumObjects(
444 LPDIRECTINPUTDEVICE32A this,
445 LPDIENUMDEVICEOBJECTSCALLBACK32A lpCallback,
446 LPVOID lpvRef,
447 DWORD dwFlags)
449 FIXME(dinput, "stub!\n");
450 if (lpCallback)
451 lpCallback(NULL, lpvRef);
452 return DI_OK;
455 static HRESULT WINAPI IDirectInputDeviceA_GetProperty(
456 LPDIRECTINPUTDEVICE32A this,
457 REFGUID rguid,
458 LPDIPROPHEADER pdiph)
460 FIXME(dinput, "stub!\n");
461 return DI_OK;
464 static HRESULT WINAPI IDirectInputDeviceA_GetObjectInfo(
465 LPDIRECTINPUTDEVICE32A this,
466 LPDIDEVICEOBJECTINSTANCE32A pdidoi,
467 DWORD dwObj,
468 DWORD dwHow)
470 FIXME(dinput, "stub!\n");
471 return DI_OK;
474 static HRESULT WINAPI IDirectInputDeviceA_GetDeviceInfo(
475 LPDIRECTINPUTDEVICE32A this,
476 LPDIDEVICEINSTANCE32A pdidi)
478 FIXME(dinput, "stub!\n");
479 return DI_OK;
482 static HRESULT WINAPI IDirectInputDeviceA_RunControlPanel(
483 LPDIRECTINPUTDEVICE32A this,
484 HWND32 hwndOwner,
485 DWORD dwFlags)
487 FIXME(dinput, "stub!\n");
488 return DI_OK;
491 static HRESULT WINAPI IDirectInputDeviceA_Initialize(
492 LPDIRECTINPUTDEVICE32A this,
493 HINSTANCE32 hinst,
494 DWORD dwVersion,
495 REFGUID rguid)
497 FIXME(dinput, "stub!\n");
498 return DI_OK;
501 /******************************************************************************
502 * IDirectInputDevice2A
505 static HRESULT WINAPI IDirectInputDevice2A_CreateEffect(
506 LPDIRECTINPUTDEVICE32A this,
507 REFGUID rguid,
508 LPCDIEFFECT lpeff,
509 LPDIRECTINPUTEFFECT *ppdef,
510 LPUNKNOWN pUnkOuter)
512 FIXME(dinput, "stub!\n");
513 return DI_OK;
516 static HRESULT WINAPI IDirectInputDevice2A_EnumEffects(
517 LPDIRECTINPUTDEVICE32A this,
518 LPDIENUMEFFECTSCALLBACKA lpCallback,
519 LPVOID lpvRef,
520 DWORD dwFlags)
522 FIXME(dinput, "stub!\n");
523 if (lpCallback)
524 lpCallback(NULL, lpvRef);
525 return DI_OK;
528 static HRESULT WINAPI IDirectInputDevice2A_GetEffectInfo(
529 LPDIRECTINPUTDEVICE32A this,
530 LPDIEFFECTINFOA lpdei,
531 REFGUID rguid)
533 FIXME(dinput, "stub!\n");
534 return DI_OK;
537 static HRESULT WINAPI IDirectInputDevice2A_GetForceFeedbackState(
538 LPDIRECTINPUTDEVICE32A this,
539 LPDWORD pdwOut)
541 FIXME(dinput, "stub!\n");
542 return DI_OK;
545 static HRESULT WINAPI IDirectInputDevice2A_SendForceFeedbackCommand(
546 LPDIRECTINPUTDEVICE32A this,
547 DWORD dwFlags)
549 FIXME(dinput, "stub!\n");
550 return DI_OK;
553 static HRESULT WINAPI IDirectInputDevice2A_EnumCreatedEffectObjects(
554 LPDIRECTINPUTDEVICE32A this,
555 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
556 LPVOID lpvRef,
557 DWORD dwFlags)
559 FIXME(dinput, "stub!\n");
560 if (lpCallback)
561 lpCallback(NULL, lpvRef);
562 return DI_OK;
565 static HRESULT WINAPI IDirectInputDevice2A_Escape(
566 LPDIRECTINPUTDEVICE32A this,
567 LPDIEFFESCAPE lpDIEEsc)
569 FIXME(dinput, "stub!\n");
570 return DI_OK;
573 static HRESULT WINAPI IDirectInputDevice2A_Poll(
574 LPDIRECTINPUTDEVICE32A this)
576 FIXME(dinput, "stub!\n");
577 return DI_OK;
580 static HRESULT WINAPI IDirectInputDevice2A_SendDeviceData(
581 LPDIRECTINPUTDEVICE32A this,
582 DWORD cbObjectData,
583 LPDIDEVICEOBJECTDATA rgdod,
584 LPDWORD pdwInOut,
585 DWORD dwFlags)
587 FIXME(dinput, "stub!\n");
588 return DI_OK;
591 /******************************************************************************
592 * SysMouseA (DInput Mouse support)
595 /******************************************************************************
596 * SetDataFormat : the application can choose the format of the data
597 * the device driver sends back with GetDeviceState.
599 * For the moment, only the "standard" configuration (c_dfDIMouse) is supported
600 * in absolute and relative mode.
602 static HRESULT WINAPI SysMouseA_SetDataFormat(
603 LPDIRECTINPUTDEVICE32A this,LPCDIDATAFORMAT df
605 int i;
606 LPSYSMOUSE32A mthis = (LPSYSMOUSE32A) this;
608 TRACE(dinput,"(this=%p,%p)\n",this,df);
610 TRACE(dinput,"(df.dwSize=%ld)\n",df->dwSize);
611 TRACE(dinput,"(df.dwObjsize=%ld)\n",df->dwObjSize);
612 TRACE(dinput,"(df.dwFlags=0x%08lx)\n",df->dwFlags);
613 TRACE(dinput,"(df.dwDataSize=%ld)\n",df->dwDataSize);
614 TRACE(dinput,"(df.dwNumObjs=%ld)\n",df->dwNumObjs);
616 for (i=0;i<df->dwNumObjs;i++) {
617 char xbuf[50];
619 if (df->rgodf[i].pguid)
620 WINE_StringFromCLSID(df->rgodf[i].pguid,xbuf);
621 else
622 strcpy(xbuf,"<no guid>");
623 TRACE(dinput,"df.rgodf[%d].guid %s (%p)\n",i,xbuf, df->rgodf[i].pguid);
624 TRACE(dinput,"df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
625 TRACE(dinput,"dwType 0x%02x,dwInstance %d\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
626 TRACE(dinput,"df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
629 /* Check size of data format to prevent crashes if the applications
630 sends a smaller buffer */
631 if (df->dwDataSize != sizeof(struct DIMOUSESTATE)) {
632 FIXME(dinput, "non-standard mouse configuration not supported yet.");
633 return DIERR_INVALIDPARAM;
636 /* For the moment, ignore these fields and return always as if
637 c_dfDIMouse was passed as format... */
638 if (df->dwFlags == DIDF_ABSAXIS)
639 mthis->absolute = 1;
640 else {
641 DWORD rx, ry;
643 /* We need to get the initial "previous" position to be able
644 to return deltas */
645 mthis->absolute = 0;
647 /* Get the mouse position */
648 EVENT_QueryPointer(&rx, &ry, NULL);
650 /* Fill the initial mouse state structure */
651 mthis->prevX = rx;
652 mthis->prevY = ry;
655 return 0;
658 /******************************************************************************
659 * GetDeviceState : returns the "state" of the mouse.
661 * For the moment, only the "standard" return structure (DIMOUSESTATE) is
662 * supported.
664 static HRESULT WINAPI SysMouseA_GetDeviceState(
665 LPDIRECTINPUTDEVICE32A this,DWORD len,LPVOID ptr
667 DWORD rx, ry, state;
668 struct DIMOUSESTATE *mstate = (struct DIMOUSESTATE *) ptr;
669 LPSYSMOUSE32A mthis = (LPSYSMOUSE32A) this;
671 TRACE(dinput,"(this=%p,0x%08lx,%p): \n",this,len,ptr);
673 /* Check if the buffer is big enough */
674 if (len < sizeof(struct DIMOUSESTATE)) {
675 FIXME(dinput, "unsupported state structure.");
676 return DIERR_INVALIDPARAM;
679 /* Get the mouse position */
680 EVENT_QueryPointer(&rx, &ry, &state);
681 TRACE(dinput,"(X:%d - Y:%d)\n", rx, ry);
683 /* Fill the mouse state structure */
684 if (mthis->absolute) {
685 mstate->lX = rx;
686 mstate->lY = ry;
687 } else {
688 mstate->lX = rx - mthis->prevX;
689 mstate->lY = ry - mthis->prevY;
690 /* Fill the previous positions */
691 mthis->prevX = rx;
692 mthis->prevY = ry;
694 mstate->lZ = 0;
695 mstate->rgbButtons[0] = (state & MK_LBUTTON ? 0xFF : 0x00);
696 mstate->rgbButtons[1] = (state & MK_RBUTTON ? 0xFF : 0x00);
697 mstate->rgbButtons[2] = (state & MK_MBUTTON ? 0xFF : 0x00);
698 mstate->rgbButtons[3] = 0x00;
700 return 0;
705 static IDirectInputDeviceA_VTable SysKeyboardAvt={
706 IDirectInputDeviceA_QueryInterface,
707 IDirectInputDeviceA_AddRef,
708 IDirectInputDeviceA_Release,
709 IDirectInputDeviceA_GetCapabilities,
710 IDirectInputDeviceA_EnumObjects,
711 IDirectInputDeviceA_GetProperty,
712 SysKeyboardA_SetProperty,
713 SysKeyboardA_Acquire,
714 SysKeyboardA_Unacquire,
715 SysKeyboardA_GetDeviceState,
716 SysKeyboardA_GetDeviceData,
717 IDirectInputDeviceA_SetDataFormat,
718 IDirectInputDeviceA_SetEventNotification,
719 IDirectInputDeviceA_SetCooperativeLevel,
720 IDirectInputDeviceA_GetObjectInfo,
721 IDirectInputDeviceA_GetDeviceInfo,
722 IDirectInputDeviceA_RunControlPanel,
723 IDirectInputDeviceA_Initialize,
724 IDirectInputDevice2A_CreateEffect,
725 IDirectInputDevice2A_EnumEffects,
726 IDirectInputDevice2A_GetEffectInfo,
727 IDirectInputDevice2A_GetForceFeedbackState,
728 IDirectInputDevice2A_SendForceFeedbackCommand,
729 IDirectInputDevice2A_EnumCreatedEffectObjects,
730 IDirectInputDevice2A_Escape,
731 IDirectInputDevice2A_Poll,
732 IDirectInputDevice2A_SendDeviceData,
735 static IDirectInputDeviceA_VTable SysMouseAvt={
736 IDirectInputDeviceA_QueryInterface,
737 IDirectInputDeviceA_AddRef,
738 IDirectInputDeviceA_Release,
739 IDirectInputDeviceA_GetCapabilities,
740 IDirectInputDeviceA_EnumObjects,
741 IDirectInputDeviceA_GetProperty,
742 IDirectInputDeviceA_SetProperty,
743 IDirectInputDeviceA_Acquire,
744 IDirectInputDeviceA_Unacquire,
745 SysMouseA_GetDeviceState,
746 IDirectInputDeviceA_GetDeviceData,
747 SysMouseA_SetDataFormat,
748 IDirectInputDeviceA_SetEventNotification,
749 IDirectInputDeviceA_SetCooperativeLevel,
750 IDirectInputDeviceA_GetObjectInfo,
751 IDirectInputDeviceA_GetDeviceInfo,
752 IDirectInputDeviceA_RunControlPanel,
753 IDirectInputDeviceA_Initialize,
754 IDirectInputDevice2A_CreateEffect,
755 IDirectInputDevice2A_EnumEffects,
756 IDirectInputDevice2A_GetEffectInfo,
757 IDirectInputDevice2A_GetForceFeedbackState,
758 IDirectInputDevice2A_SendForceFeedbackCommand,
759 IDirectInputDevice2A_EnumCreatedEffectObjects,
760 IDirectInputDevice2A_Escape,
761 IDirectInputDevice2A_Poll,
762 IDirectInputDevice2A_SendDeviceData,