Recovery of release 990110 after disk crash.
[wine/multimedia.git] / windows / dinput.c
blob7e504ff0eb603eea203c886b3b6d7094b8d026bb
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 "config.h"
22 #include <string.h>
23 #include <unistd.h>
24 #include <assert.h>
25 #include <sys/signal.h>
27 #include "windows.h"
28 #include "winerror.h"
29 #include "shell.h"
30 #include "gdi.h"
31 #include "heap.h"
32 #include "win.h"
33 #include "dinput.h"
34 #include "objbase.h"
35 #include "debug.h"
36 #include "message.h"
38 extern BYTE InputKeyStateTable[256];
39 extern int min_keycode, max_keycode;
40 extern WORD keyc2vkey[256];
42 static IDirectInputA_VTable ddiavt;
43 static IDirectInputDeviceA_VTable SysKeyboardAvt;
44 static IDirectInputDeviceA_VTable SysMouseAvt;
46 /* UIDs for Wine "drivers".
47 When enumerating each device supporting DInput, they have two UIDs :
48 - the 'windows' UID
49 - a vendor UID */
50 static GUID DInput_Wine_Mouse_GUID = { /* 9e573ed8-7734-11d2-8d4a-23903fb6bdf7 */
51 0x9e573ed8,
52 0x7734,
53 0x11d2,
54 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
56 static GUID DInput_Wine_Keyboard_GUID = { /* 0ab8648a-7735-11d2-8c73-71df54a96441 */
57 0x0ab8648a,
58 0x7735,
59 0x11d2,
60 {0x8c, 0x73, 0x71, 0xdf, 0x54, 0xa9, 0x64, 0x41}
63 /******************************************************************************
64 * DirectInputCreate32A
66 HRESULT WINAPI DirectInputCreate32A(HINSTANCE32 hinst, DWORD dwVersion, LPDIRECTINPUT32A *ppDI, LPUNKNOWN punkOuter) {
67 TRACE(dinput, "(0x%08lx,%04lx,%p,%p)\n",
68 (DWORD)hinst,dwVersion,ppDI,punkOuter
70 (*ppDI) = (LPDIRECTINPUT32A)HeapAlloc(GetProcessHeap(),0,sizeof(IDirectInput32A));
71 (*ppDI)->ref = 1;
72 (*ppDI)->lpvtbl = &ddiavt;
73 return 0;
75 /******************************************************************************
76 * IDirectInputA_EnumDevices
78 static HRESULT WINAPI IDirectInputA_EnumDevices(
79 LPDIRECTINPUT32A this, DWORD dwDevType, LPDIENUMDEVICESCALLBACK32A lpCallback,
80 LPVOID pvRef, DWORD dwFlags
81 ) {
82 DIDEVICEINSTANCE32A devInstance;
83 int ret;
85 TRACE(dinput, "(this=%p,0x%04lx,%p,%p,%04lx)\n", this, dwDevType, lpCallback, pvRef, dwFlags);
87 devInstance.dwSize = sizeof(DIDEVICEINSTANCE32A);
89 if ((dwDevType == 0) || (dwDevType == DIDEVTYPE_KEYBOARD)) {
90 /* Return keyboard */
91 devInstance.guidInstance = GUID_SysKeyboard; /* DInput's GUID */
92 devInstance.guidProduct = DInput_Wine_Keyboard_GUID; /* Vendor's GUID */
93 devInstance.dwDevType = DIDEVTYPE_KEYBOARD | (DIDEVTYPEKEYBOARD_UNKNOWN << 8);
94 strcpy(devInstance.tszInstanceName, "Keyboard");
95 strcpy(devInstance.tszProductName, "Wine Keyboard");
97 ret = lpCallback(&devInstance, pvRef);
98 TRACE(dinput, "Keyboard registered\n");
100 if (ret == DIENUM_STOP)
101 return 0;
104 if ((dwDevType == 0) || (dwDevType == DIDEVTYPE_KEYBOARD)) {
105 /* Return mouse */
106 devInstance.guidInstance = GUID_SysMouse; /* DInput's GUID */
107 devInstance.guidProduct = DInput_Wine_Mouse_GUID; /* Vendor's GUID */
108 devInstance.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_UNKNOWN << 8);
109 strcpy(devInstance.tszInstanceName, "Mouse");
110 strcpy(devInstance.tszProductName, "Wine Mouse");
112 ret = lpCallback(&devInstance, pvRef);
113 TRACE(dinput, "Mouse registered\n");
116 /* Should also do joystick enumerations.... */
118 return 0;
121 static ULONG WINAPI IDirectInputA_AddRef(LPDIRECTINPUT32A this) {
122 return ++(this->ref);
125 static ULONG WINAPI IDirectInputA_Release(LPDIRECTINPUT32A this) {
126 if (!(--this->ref)) {
127 HeapFree(GetProcessHeap(),0,this);
128 return 0;
130 return this->ref;
133 static HRESULT WINAPI IDirectInputA_CreateDevice(
134 LPDIRECTINPUT32A this,REFGUID rguid,LPDIRECTINPUTDEVICE32A* pdev,
135 LPUNKNOWN punk
137 char xbuf[50];
139 WINE_StringFromCLSID(rguid,xbuf);
140 FIXME(dinput,"(this=%p,%s,%p,%p): stub\n",this,xbuf,pdev,punk);
141 if ((!memcmp(&GUID_SysKeyboard,rguid,sizeof(GUID_SysKeyboard))) || /* Generic Keyboard */
142 (!memcmp(&DInput_Wine_Keyboard_GUID,rguid,sizeof(GUID_SysKeyboard)))) { /* Wine Keyboard */
143 *pdev = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysKeyboard32A));
144 (*pdev)->ref = 1;
145 (*pdev)->lpvtbl = &SysKeyboardAvt;
146 memcpy(&((*pdev)->guid),rguid,sizeof(*rguid));
147 memset(((LPSYSKEYBOARD32A)(*pdev))->keystate,0,256);
148 return 0;
150 if ((!memcmp(&GUID_SysMouse,rguid,sizeof(GUID_SysMouse))) || /* Generic Mouse */
151 (!memcmp(&DInput_Wine_Mouse_GUID,rguid,sizeof(GUID_SysKeyboard)))) { /* Wine Mouse */
152 *pdev = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouse32A));
153 (*pdev)->ref = 1;
154 (*pdev)->lpvtbl = &SysMouseAvt;
155 memcpy(&((*pdev)->guid),rguid,sizeof(*rguid));
156 return 0;
158 return E_FAIL;
161 static HRESULT WINAPI IDirectInputA_QueryInterface(
162 LPDIRECTINPUT32A this,REFIID riid,LPVOID *ppobj
164 char xbuf[50];
166 WINE_StringFromCLSID(riid,xbuf);
167 TRACE(dinput,"(this=%p,%s,%p)\n",this,xbuf,ppobj);
168 if (!memcmp(&IID_IUnknown,riid,sizeof(*riid))) {
169 this->lpvtbl->fnAddRef(this);
170 *ppobj = this;
171 return 0;
173 if (!memcmp(&IID_IDirectInputA,riid,sizeof(*riid))) {
174 this->lpvtbl->fnAddRef(this);
175 *ppobj = this;
176 return 0;
178 return E_FAIL;
181 static HRESULT WINAPI IDirectInputA_Initialize(
182 LPDIRECTINPUT32A this,HINSTANCE32 hinst,DWORD x
184 return DIERR_ALREADYINITIALIZED;
187 static IDirectInputA_VTable ddiavt= {
188 IDirectInputA_QueryInterface,
189 IDirectInputA_AddRef,
190 IDirectInputA_Release,
191 IDirectInputA_CreateDevice,
192 IDirectInputA_EnumDevices,
193 (void*)6,
194 (void*)7,
195 IDirectInputA_Initialize
198 /******************************************************************************
199 * IDirectInputDeviceA
201 static HRESULT WINAPI IDirectInputDeviceA_SetDataFormat(
202 LPDIRECTINPUTDEVICE32A this,LPCDIDATAFORMAT df
205 int i;
206 TRACE(dinput,"(this=%p,%p)\n",this,df);
208 TRACE(dinput,"df.dwSize=%ld\n",df->dwSize);
209 TRACE(dinput,"(df.dwObjsize=%ld)\n",df->dwObjSize);
210 TRACE(dinput,"(df.dwFlags=0x%08lx)\n",df->dwFlags);
211 TRACE(dinput,"(df.dwDataSize=%ld)\n",df->dwDataSize);
212 TRACE(dinput,"(df.dwNumObjs=%ld)\n",df->dwNumObjs);
214 for (i=0;i<df->dwNumObjs;i++) {
215 char xbuf[50];
217 if (df->rgodf[i].pguid)
218 WINE_StringFromCLSID(df->rgodf[i].pguid,xbuf);
219 else
220 strcpy(xbuf,"<no guid>");
221 TRACE(dinput,"df.rgodf[%d].guid %s\n",i,xbuf);
222 TRACE(dinput,"df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
223 TRACE(dinput,"dwType 0x%02lx,dwInstance %ld\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
224 TRACE(dinput,"df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
227 return 0;
230 static HRESULT WINAPI IDirectInputDeviceA_SetCooperativeLevel(
231 LPDIRECTINPUTDEVICE32A this,HWND32 hwnd,DWORD dwflags
233 FIXME(dinput,"(this=%p,0x%08lx,0x%08lx): stub\n",this,(DWORD)hwnd,dwflags);
234 return 0;
237 static HRESULT WINAPI IDirectInputDeviceA_SetProperty(
238 LPDIRECTINPUTDEVICE32A this,REFGUID rguid,LPCDIPROPHEADER ph
240 char xbuf[50];
242 if (HIWORD(rguid))
243 WINE_StringFromCLSID(rguid,xbuf);
244 else
245 sprintf(xbuf,"<special guid %ld>",(DWORD)rguid);
246 TRACE(dinput,"(this=%p,%s,%p)\n",this,xbuf,ph);
247 if (!HIWORD(rguid)) {
248 switch ((DWORD)rguid) {
249 case DIPROP_BUFFERSIZE: {
250 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
252 TRACE(dinput,"buffersize = %ld\n",pd->dwData);
253 break;
255 default:
256 WARN(dinput,"Unknown type %ld\n",(DWORD)rguid);
257 break;
260 return 0;
263 static HRESULT WINAPI IDirectInputDeviceA_SetEventNotification(
264 LPDIRECTINPUTDEVICE32A this,HANDLE32 hnd
266 FIXME(dinput,"(this=%p,0x%08lx): stub\n",this,(DWORD)hnd);
267 return 0;
270 static HRESULT WINAPI IDirectInputDeviceA_GetDeviceData(
271 LPDIRECTINPUTDEVICE32A this,DWORD dodsize,LPDIDEVICEOBJECTDATA dod,
272 LPDWORD entries,DWORD flags
274 TRACE(dinput,"IDirectInputDeviceA(%p)->GetDeviceData(%ld,%p,%p(0x%08lx),0x%08lx)\n",
275 this,dodsize,dod,entries,*entries,flags);
276 return 0;
280 static HRESULT WINAPI IDirectInputDeviceA_Acquire(LPDIRECTINPUTDEVICE32A this) {
281 TRACE(dinput,"(this=%p): stub\n",this);
282 return 0;
285 static HRESULT WINAPI IDirectInputDeviceA_Unacquire(LPDIRECTINPUTDEVICE32A this) {
286 TRACE(dinput,"(this=%p): stub\n",this);
287 return 0;
290 static ULONG WINAPI IDirectInputDeviceA_Release(LPDIRECTINPUTDEVICE32A this) {
291 this->ref--;
292 if (this->ref)
293 return this->ref;
294 HeapFree(GetProcessHeap(),0,this);
295 return 0;
298 static HRESULT WINAPI SysKeyboardA_SetProperty(
299 LPDIRECTINPUTDEVICE32A this,REFGUID rguid,LPCDIPROPHEADER ph
301 char xbuf[50];
303 if (HIWORD(rguid))
304 WINE_StringFromCLSID(rguid,xbuf);
305 else
306 sprintf(xbuf,"<special guid %ld>",(DWORD)rguid);
307 TRACE(dinput,"(this=%p,%s,%p)\n",this,xbuf,ph);
308 TRACE(dinput,"(size=%ld,headersize=%ld,obj=%ld,how=%ld\n",
309 ph->dwSize,ph->dwHeaderSize,ph->dwObj,ph->dwHow);
310 if (!HIWORD(rguid)) {
311 switch ((DWORD)rguid) {
312 case DIPROP_BUFFERSIZE: {
313 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
315 TRACE(dinput,"(buffersize=%ld)\n",pd->dwData);
316 break;
318 default:
319 WARN(dinput,"Unknown type %ld\n",(DWORD)rguid);
320 break;
323 return 0;
326 static HRESULT WINAPI SysKeyboardA_GetDeviceState(
327 LPDIRECTINPUTDEVICE32A this,DWORD len,LPVOID ptr
329 if (len==256) {
330 int keyc,vkey;
332 memset(ptr,0,256);
333 for (keyc=min_keycode;keyc<max_keycode;keyc++)
335 /* X keycode to virtual key */
336 vkey = keyc2vkey[keyc] & 0xFF;
337 /* The windows scancode is keyc-min_keycode */
338 if (InputKeyStateTable[vkey]&0x80) {
339 ((LPBYTE)ptr)[keyc-min_keycode]=0x80;
340 ((LPBYTE)ptr)[(keyc-min_keycode)|0x80]=0x80;
343 return 0;
345 WARN(dinput,"whoops, SysKeyboardA_GetDeviceState got len %ld?\n",len);
346 return 0;
349 static HRESULT WINAPI SysKeyboardA_GetDeviceData(
350 LPDIRECTINPUTDEVICE32A this,DWORD dodsize,LPDIDEVICEOBJECTDATA dod,
351 LPDWORD entries,DWORD flags
353 int keyc,n,vkey,xentries;
354 LPSYSKEYBOARD32A kthis = (LPSYSKEYBOARD32A)this;
356 TRACE(dinput,"(this=%p,%ld,%p,%p(%ld)),0x%08lx)\n",
357 this,dodsize,dod,entries,entries?*entries:0,flags);
358 EVENT_WaitNetEvent(FALSE,TRUE);
359 if (entries)
360 xentries = *entries;
361 else
362 xentries = 1;
364 n = 0;
366 for (keyc=min_keycode;(keyc<max_keycode) && (n<*entries);keyc++)
368 /* X keycode to virtual key */
369 vkey = keyc2vkey[keyc] & 0xFF;
370 if (kthis->keystate[vkey] == (InputKeyStateTable[vkey]&0x80))
371 continue;
372 if (dod) {
373 /* add an entry */
374 dod[n].dwOfs = keyc-min_keycode; /* scancode */
375 dod[n].dwData = InputKeyStateTable[vkey]&0x80;
376 dod[n].dwTimeStamp = 0; /* umm */
377 dod[n].dwSequence = 0; /* umm */
378 n++;
380 if (!(flags & DIGDD_PEEK))
381 kthis->keystate[vkey] = InputKeyStateTable[vkey]&0x80;
385 if (n) fprintf(stderr,"%d entries\n",n);
386 *entries = n;
387 return 0;
390 static HRESULT WINAPI SysKeyboardA_Acquire(LPDIRECTINPUTDEVICE32A this) {
391 TRACE(dinput,"(this=%p): stub\n",this);
392 return 0;
395 static HRESULT WINAPI SysKeyboardA_Unacquire(LPDIRECTINPUTDEVICE32A this) {
396 TRACE(dinput,"(this=%p): stub\n",this);
397 return 0;
400 static HRESULT WINAPI IDirectInputDeviceA_QueryInterface(
401 LPDIRECTINPUTDEVICE32A this,REFIID riid,LPVOID *ppobj
403 char xbuf[50];
405 WINE_StringFromCLSID(riid,xbuf);
406 TRACE(dinput,"(this=%p,%s,%p)\n",this,xbuf,ppobj);
407 if (!memcmp(&IID_IUnknown,riid,sizeof(*riid))) {
408 this->lpvtbl->fnAddRef(this);
409 *ppobj = this;
410 return 0;
412 if (!memcmp(&IID_IDirectInputDeviceA,riid,sizeof(*riid))) {
413 this->lpvtbl->fnAddRef(this);
414 *ppobj = this;
415 return 0;
417 if (!memcmp(&IID_IDirectInputDevice2A,riid,sizeof(*riid))) {
418 this->lpvtbl->fnAddRef(this);
419 *ppobj = this;
420 return 0;
422 return E_FAIL;
425 static ULONG WINAPI IDirectInputDeviceA_AddRef(
426 LPDIRECTINPUTDEVICE32A this)
428 return ++this->ref;
431 static HRESULT WINAPI IDirectInputDeviceA_GetCapabilities(
432 LPDIRECTINPUTDEVICE32A this,
433 LPDIDEVCAPS lpDIDevCaps)
435 FIXME(dinput, "stub!\n");
436 return DI_OK;
439 static HRESULT WINAPI IDirectInputDeviceA_EnumObjects(
440 LPDIRECTINPUTDEVICE32A this,
441 LPDIENUMDEVICEOBJECTSCALLBACK32A lpCallback,
442 LPVOID lpvRef,
443 DWORD dwFlags)
445 FIXME(dinput, "stub!\n");
446 if (lpCallback)
447 lpCallback(NULL, lpvRef);
448 return DI_OK;
451 static HRESULT WINAPI IDirectInputDeviceA_GetProperty(
452 LPDIRECTINPUTDEVICE32A this,
453 REFGUID rguid,
454 LPDIPROPHEADER pdiph)
456 FIXME(dinput, "stub!\n");
457 return DI_OK;
460 static HRESULT WINAPI IDirectInputDeviceA_GetObjectInfo(
461 LPDIRECTINPUTDEVICE32A this,
462 LPDIDEVICEOBJECTINSTANCE32A pdidoi,
463 DWORD dwObj,
464 DWORD dwHow)
466 FIXME(dinput, "stub!\n");
467 return DI_OK;
470 static HRESULT WINAPI IDirectInputDeviceA_GetDeviceInfo(
471 LPDIRECTINPUTDEVICE32A this,
472 LPDIDEVICEINSTANCE32A pdidi)
474 FIXME(dinput, "stub!\n");
475 return DI_OK;
478 static HRESULT WINAPI IDirectInputDeviceA_RunControlPanel(
479 LPDIRECTINPUTDEVICE32A this,
480 HWND32 hwndOwner,
481 DWORD dwFlags)
483 FIXME(dinput, "stub!\n");
484 return DI_OK;
487 static HRESULT WINAPI IDirectInputDeviceA_Initialize(
488 LPDIRECTINPUTDEVICE32A this,
489 HINSTANCE32 hinst,
490 DWORD dwVersion,
491 REFGUID rguid)
493 FIXME(dinput, "stub!\n");
494 return DI_OK;
497 /******************************************************************************
498 * IDirectInputDevice2A
501 static HRESULT WINAPI IDirectInputDevice2A_CreateEffect(
502 LPDIRECTINPUTDEVICE32A this,
503 REFGUID rguid,
504 LPCDIEFFECT lpeff,
505 LPDIRECTINPUTEFFECT *ppdef,
506 LPUNKNOWN pUnkOuter)
508 FIXME(dinput, "stub!\n");
509 return DI_OK;
512 static HRESULT WINAPI IDirectInputDevice2A_EnumEffects(
513 LPDIRECTINPUTDEVICE32A this,
514 LPDIENUMEFFECTSCALLBACKA lpCallback,
515 LPVOID lpvRef,
516 DWORD dwFlags)
518 FIXME(dinput, "stub!\n");
519 if (lpCallback)
520 lpCallback(NULL, lpvRef);
521 return DI_OK;
524 static HRESULT WINAPI IDirectInputDevice2A_GetEffectInfo(
525 LPDIRECTINPUTDEVICE32A this,
526 LPDIEFFECTINFOA lpdei,
527 REFGUID rguid)
529 FIXME(dinput, "stub!\n");
530 return DI_OK;
533 static HRESULT WINAPI IDirectInputDevice2A_GetForceFeedbackState(
534 LPDIRECTINPUTDEVICE32A this,
535 LPDWORD pdwOut)
537 FIXME(dinput, "stub!\n");
538 return DI_OK;
541 static HRESULT WINAPI IDirectInputDevice2A_SendForceFeedbackCommand(
542 LPDIRECTINPUTDEVICE32A this,
543 DWORD dwFlags)
545 FIXME(dinput, "stub!\n");
546 return DI_OK;
549 static HRESULT WINAPI IDirectInputDevice2A_EnumCreatedEffectObjects(
550 LPDIRECTINPUTDEVICE32A this,
551 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
552 LPVOID lpvRef,
553 DWORD dwFlags)
555 FIXME(dinput, "stub!\n");
556 if (lpCallback)
557 lpCallback(NULL, lpvRef);
558 return DI_OK;
561 static HRESULT WINAPI IDirectInputDevice2A_Escape(
562 LPDIRECTINPUTDEVICE32A this,
563 LPDIEFFESCAPE lpDIEEsc)
565 FIXME(dinput, "stub!\n");
566 return DI_OK;
569 static HRESULT WINAPI IDirectInputDevice2A_Poll(
570 LPDIRECTINPUTDEVICE32A this)
572 FIXME(dinput, "stub!\n");
573 return DI_OK;
576 static HRESULT WINAPI IDirectInputDevice2A_SendDeviceData(
577 LPDIRECTINPUTDEVICE32A this,
578 DWORD cbObjectData,
579 LPDIDEVICEOBJECTDATA rgdod,
580 LPDWORD pdwInOut,
581 DWORD dwFlags)
583 FIXME(dinput, "stub!\n");
584 return DI_OK;
587 /******************************************************************************
588 * SysMouseA (DInput Mouse support)
591 /******************************************************************************
592 * SetDataFormat : the application can choose the format of the data
593 * the device driver sends back with GetDeviceState.
595 * For the moment, only the "standard" configuration (c_dfDIMouse) is supported
596 * in absolute and relative mode.
598 static HRESULT WINAPI SysMouseA_SetDataFormat(
599 LPDIRECTINPUTDEVICE32A this,LPCDIDATAFORMAT df
601 int i;
602 LPSYSMOUSE32A mthis = (LPSYSMOUSE32A) this;
604 TRACE(dinput,"(this=%p,%p)\n",this,df);
606 TRACE(dinput,"(df.dwSize=%ld)\n",df->dwSize);
607 TRACE(dinput,"(df.dwObjsize=%ld)\n",df->dwObjSize);
608 TRACE(dinput,"(df.dwFlags=0x%08lx)\n",df->dwFlags);
609 TRACE(dinput,"(df.dwDataSize=%ld)\n",df->dwDataSize);
610 TRACE(dinput,"(df.dwNumObjs=%ld)\n",df->dwNumObjs);
612 for (i=0;i<df->dwNumObjs;i++) {
613 char xbuf[50];
615 if (df->rgodf[i].pguid)
616 WINE_StringFromCLSID(df->rgodf[i].pguid,xbuf);
617 else
618 strcpy(xbuf,"<no guid>");
619 TRACE(dinput,"df.rgodf[%d].guid %s (%p)\n",i,xbuf, df->rgodf[i].pguid);
620 TRACE(dinput,"df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
621 TRACE(dinput,"dwType 0x%02x,dwInstance %d\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
622 TRACE(dinput,"df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
625 /* Check size of data format to prevent crashes if the applications
626 sends a smaller buffer */
627 if (df->dwDataSize != sizeof(struct DIMOUSESTATE)) {
628 FIXME(dinput, "non-standard mouse configuration not supported yet.");
629 return DIERR_INVALIDPARAM;
632 /* For the moment, ignore these fields and return always as if
633 c_dfDIMouse was passed as format... */
634 if (df->dwFlags == DIDF_ABSAXIS)
635 mthis->absolute = 1;
636 else {
637 DWORD rx, ry;
639 /* We need to get the initial "previous" position to be able
640 to return deltas */
641 mthis->absolute = 0;
643 /* Get the mouse position */
644 EVENT_QueryPointer(&rx, &ry, NULL);
646 /* Fill the initial mouse state structure */
647 mthis->prevX = rx;
648 mthis->prevY = ry;
651 return 0;
654 /******************************************************************************
655 * GetDeviceState : returns the "state" of the mouse.
657 * For the moment, only the "standard" return structure (DIMOUSESTATE) is
658 * supported.
660 static HRESULT WINAPI SysMouseA_GetDeviceState(
661 LPDIRECTINPUTDEVICE32A this,DWORD len,LPVOID ptr
663 DWORD rx, ry, state;
664 struct DIMOUSESTATE *mstate = (struct DIMOUSESTATE *) ptr;
665 LPSYSMOUSE32A mthis = (LPSYSMOUSE32A) this;
667 TRACE(dinput,"(this=%p,0x%08lx,%p): \n",this,len,ptr);
669 /* Check if the buffer is big enough */
670 if (len < sizeof(struct DIMOUSESTATE)) {
671 FIXME(dinput, "unsupported state structure.");
672 return DIERR_INVALIDPARAM;
675 /* Get the mouse position */
676 EVENT_QueryPointer(&rx, &ry, &state);
677 TRACE(dinput,"(X:%d - Y:%d)\n", rx, ry);
679 /* Fill the mouse state structure */
680 if (mthis->absolute) {
681 mstate->lX = rx;
682 mstate->lY = ry;
683 } else {
684 mstate->lX = rx - mthis->prevX;
685 mstate->lY = ry - mthis->prevY;
686 /* Fill the previous positions */
687 mthis->prevX = rx;
688 mthis->prevY = ry;
690 mstate->lZ = 0;
691 mstate->rgbButtons[0] = (state & MK_LBUTTON ? 0xFF : 0x00);
692 mstate->rgbButtons[1] = (state & MK_RBUTTON ? 0xFF : 0x00);
693 mstate->rgbButtons[2] = (state & MK_MBUTTON ? 0xFF : 0x00);
694 mstate->rgbButtons[3] = 0x00;
696 return 0;
701 static IDirectInputDeviceA_VTable SysKeyboardAvt={
702 IDirectInputDeviceA_QueryInterface,
703 IDirectInputDeviceA_AddRef,
704 IDirectInputDeviceA_Release,
705 IDirectInputDeviceA_GetCapabilities,
706 IDirectInputDeviceA_EnumObjects,
707 IDirectInputDeviceA_GetProperty,
708 SysKeyboardA_SetProperty,
709 SysKeyboardA_Acquire,
710 SysKeyboardA_Unacquire,
711 SysKeyboardA_GetDeviceState,
712 SysKeyboardA_GetDeviceData,
713 IDirectInputDeviceA_SetDataFormat,
714 IDirectInputDeviceA_SetEventNotification,
715 IDirectInputDeviceA_SetCooperativeLevel,
716 IDirectInputDeviceA_GetObjectInfo,
717 IDirectInputDeviceA_GetDeviceInfo,
718 IDirectInputDeviceA_RunControlPanel,
719 IDirectInputDeviceA_Initialize,
720 IDirectInputDevice2A_CreateEffect,
721 IDirectInputDevice2A_EnumEffects,
722 IDirectInputDevice2A_GetEffectInfo,
723 IDirectInputDevice2A_GetForceFeedbackState,
724 IDirectInputDevice2A_SendForceFeedbackCommand,
725 IDirectInputDevice2A_EnumCreatedEffectObjects,
726 IDirectInputDevice2A_Escape,
727 IDirectInputDevice2A_Poll,
728 IDirectInputDevice2A_SendDeviceData,
731 static IDirectInputDeviceA_VTable SysMouseAvt={
732 IDirectInputDeviceA_QueryInterface,
733 IDirectInputDeviceA_AddRef,
734 IDirectInputDeviceA_Release,
735 IDirectInputDeviceA_GetCapabilities,
736 IDirectInputDeviceA_EnumObjects,
737 IDirectInputDeviceA_GetProperty,
738 IDirectInputDeviceA_SetProperty,
739 IDirectInputDeviceA_Acquire,
740 IDirectInputDeviceA_Unacquire,
741 SysMouseA_GetDeviceState,
742 IDirectInputDeviceA_GetDeviceData,
743 SysMouseA_SetDataFormat,
744 IDirectInputDeviceA_SetEventNotification,
745 IDirectInputDeviceA_SetCooperativeLevel,
746 IDirectInputDeviceA_GetObjectInfo,
747 IDirectInputDeviceA_GetDeviceInfo,
748 IDirectInputDeviceA_RunControlPanel,
749 IDirectInputDeviceA_Initialize,
750 IDirectInputDevice2A_CreateEffect,
751 IDirectInputDevice2A_EnumEffects,
752 IDirectInputDevice2A_GetEffectInfo,
753 IDirectInputDevice2A_GetForceFeedbackState,
754 IDirectInputDevice2A_SendForceFeedbackCommand,
755 IDirectInputDevice2A_EnumCreatedEffectObjects,
756 IDirectInputDevice2A_Escape,
757 IDirectInputDevice2A_Poll,
758 IDirectInputDevice2A_SendDeviceData,