dinput: Move internal function calculate_ids to where it's really used.
[wine/wine-kai.git] / dlls / dinput / device.c
blobbee9ff736a595f32f1485677c714dcb4216cdf78
1 /* DirectInput Device
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
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.
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.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 /* This file contains all the Device specific functions that can be used as stubs
23 by real device implementations.
25 It also contains all the helper functions.
27 #include "config.h"
29 #include <stdarg.h>
30 #include <string.h>
31 #include "wine/debug.h"
32 #include "wine/unicode.h"
33 #include "windef.h"
34 #include "winbase.h"
35 #include "winuser.h"
36 #include "winerror.h"
37 #include "dinput.h"
38 #include "device_private.h"
39 #include "dinput_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
43 /******************************************************************************
44 * Various debugging tools
46 void _dump_cooperativelevel_DI(DWORD dwFlags) {
47 if (TRACE_ON(dinput)) {
48 unsigned int i;
49 static const struct {
50 DWORD mask;
51 const char *name;
52 } flags[] = {
53 #define FE(x) { x, #x}
54 FE(DISCL_BACKGROUND),
55 FE(DISCL_EXCLUSIVE),
56 FE(DISCL_FOREGROUND),
57 FE(DISCL_NONEXCLUSIVE),
58 FE(DISCL_NOWINKEY)
59 #undef FE
61 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
62 if (flags[i].mask & dwFlags)
63 DPRINTF("%s ",flags[i].name);
64 DPRINTF("\n");
68 void _dump_EnumObjects_flags(DWORD dwFlags) {
69 if (TRACE_ON(dinput)) {
70 unsigned int i;
71 DWORD type, instance;
72 static const struct {
73 DWORD mask;
74 const char *name;
75 } flags[] = {
76 #define FE(x) { x, #x}
77 FE(DIDFT_RELAXIS),
78 FE(DIDFT_ABSAXIS),
79 FE(DIDFT_PSHBUTTON),
80 FE(DIDFT_TGLBUTTON),
81 FE(DIDFT_POV),
82 FE(DIDFT_COLLECTION),
83 FE(DIDFT_NODATA),
84 FE(DIDFT_FFACTUATOR),
85 FE(DIDFT_FFEFFECTTRIGGER),
86 FE(DIDFT_OUTPUT),
87 FE(DIDFT_VENDORDEFINED),
88 FE(DIDFT_ALIAS),
89 FE(DIDFT_OPTIONAL)
90 #undef FE
92 type = (dwFlags & 0xFF0000FF);
93 instance = ((dwFlags >> 8) & 0xFFFF);
94 DPRINTF("Type:");
95 if (type == DIDFT_ALL) {
96 DPRINTF(" DIDFT_ALL");
97 } else {
98 for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) {
99 if (flags[i].mask & type) {
100 type &= ~flags[i].mask;
101 DPRINTF(" %s",flags[i].name);
104 if (type) {
105 DPRINTF(" (unhandled: %08x)", type);
108 DPRINTF(" / Instance: ");
109 if (instance == ((DIDFT_ANYINSTANCE >> 8) & 0xFFFF)) {
110 DPRINTF("DIDFT_ANYINSTANCE");
111 } else {
112 DPRINTF("%3d", instance);
117 void _dump_DIPROPHEADER(LPCDIPROPHEADER diph) {
118 if (TRACE_ON(dinput)) {
119 DPRINTF(" - dwObj = 0x%08x\n", diph->dwObj);
120 DPRINTF(" - dwHow = %s\n",
121 ((diph->dwHow == DIPH_DEVICE) ? "DIPH_DEVICE" :
122 ((diph->dwHow == DIPH_BYOFFSET) ? "DIPH_BYOFFSET" :
123 ((diph->dwHow == DIPH_BYID)) ? "DIPH_BYID" : "unknown")));
127 void _dump_OBJECTINSTANCEA(DIDEVICEOBJECTINSTANCEA *ddoi) {
128 if (TRACE_ON(dinput)) {
129 DPRINTF(" - enumerating : %s ('%s') - %2d - 0x%08x - %s\n",
130 debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, ddoi->tszName);
134 void _dump_OBJECTINSTANCEW(DIDEVICEOBJECTINSTANCEW *ddoi) {
135 if (TRACE_ON(dinput)) {
136 DPRINTF(" - enumerating : %s ('%s'), - %2d - 0x%08x - %s\n",
137 debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, debugstr_w(ddoi->tszName));
141 /* This function is a helper to convert a GUID into any possible DInput GUID out there */
142 const char *_dump_dinput_GUID(const GUID *guid) {
143 unsigned int i;
144 static const struct {
145 const GUID *guid;
146 const char *name;
147 } guids[] = {
148 #define FE(x) { &x, #x}
149 FE(GUID_XAxis),
150 FE(GUID_YAxis),
151 FE(GUID_ZAxis),
152 FE(GUID_RxAxis),
153 FE(GUID_RyAxis),
154 FE(GUID_RzAxis),
155 FE(GUID_Slider),
156 FE(GUID_Button),
157 FE(GUID_Key),
158 FE(GUID_POV),
159 FE(GUID_Unknown),
160 FE(GUID_SysMouse),
161 FE(GUID_SysKeyboard),
162 FE(GUID_Joystick),
163 FE(GUID_ConstantForce),
164 FE(GUID_RampForce),
165 FE(GUID_Square),
166 FE(GUID_Sine),
167 FE(GUID_Triangle),
168 FE(GUID_SawtoothUp),
169 FE(GUID_SawtoothDown),
170 FE(GUID_Spring),
171 FE(GUID_Damper),
172 FE(GUID_Inertia),
173 FE(GUID_Friction),
174 FE(GUID_CustomForce)
175 #undef FE
177 if (guid == NULL)
178 return "null GUID";
179 for (i = 0; i < (sizeof(guids) / sizeof(guids[0])); i++) {
180 if (IsEqualGUID(guids[i].guid, guid)) {
181 return guids[i].name;
184 return "Unknown GUID";
187 void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) {
188 unsigned int i;
190 TRACE("Dumping DIDATAFORMAT structure:\n");
191 TRACE(" - dwSize: %d\n", df->dwSize);
192 if (df->dwSize != sizeof(DIDATAFORMAT)) {
193 WARN("Non-standard DIDATAFORMAT structure size %d\n", df->dwSize);
195 TRACE(" - dwObjsize: %d\n", df->dwObjSize);
196 if (df->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) {
197 WARN("Non-standard DIOBJECTDATAFORMAT structure size %d\n", df->dwObjSize);
199 TRACE(" - dwFlags: 0x%08x (", df->dwFlags);
200 switch (df->dwFlags) {
201 case DIDF_ABSAXIS: TRACE("DIDF_ABSAXIS"); break;
202 case DIDF_RELAXIS: TRACE("DIDF_RELAXIS"); break;
203 default: TRACE("unknown"); break;
205 TRACE(")\n");
206 TRACE(" - dwDataSize: %d\n", df->dwDataSize);
207 TRACE(" - dwNumObjs: %d\n", df->dwNumObjs);
209 for (i = 0; i < df->dwNumObjs; i++) {
210 TRACE(" - Object %d:\n", i);
211 TRACE(" * GUID: %s ('%s')\n", debugstr_guid(df->rgodf[i].pguid), _dump_dinput_GUID(df->rgodf[i].pguid));
212 TRACE(" * dwOfs: %d\n", df->rgodf[i].dwOfs);
213 TRACE(" * dwType: 0x%08x\n", df->rgodf[i].dwType);
214 TRACE(" "); _dump_EnumObjects_flags(df->rgodf[i].dwType); TRACE("\n");
215 TRACE(" * dwFlags: 0x%08x\n", df->rgodf[i].dwFlags);
219 /* Conversion between internal data buffer and external data buffer */
220 void fill_DataFormat(void *out, const void *in, DataFormat *df) {
221 int i;
222 const char *in_c = in;
223 char *out_c = (char *) out;
225 if (df->dt == NULL) {
226 /* This means that the app uses Wine's internal data format */
227 memcpy(out, in, df->internal_format_size);
228 } else {
229 for (i = 0; i < df->size; i++) {
230 if (df->dt[i].offset_in >= 0) {
231 switch (df->dt[i].size) {
232 case 1:
233 TRACE("Copying (c) to %d from %d (value %d)\n",
234 df->dt[i].offset_out, df->dt[i].offset_in, *(in_c + df->dt[i].offset_in));
235 *(out_c + df->dt[i].offset_out) = *(in_c + df->dt[i].offset_in);
236 break;
238 case 2:
239 TRACE("Copying (s) to %d from %d (value %d)\n",
240 df->dt[i].offset_out, df->dt[i].offset_in, *((const short *)(in_c + df->dt[i].offset_in)));
241 *((short *)(out_c + df->dt[i].offset_out)) = *((const short *)(in_c + df->dt[i].offset_in));
242 break;
244 case 4:
245 TRACE("Copying (i) to %d from %d (value %d)\n",
246 df->dt[i].offset_out, df->dt[i].offset_in, *((const int *)(in_c + df->dt[i].offset_in)));
247 *((int *)(out_c + df->dt[i].offset_out)) = *((const int *)(in_c + df->dt[i].offset_in));
248 break;
250 default:
251 memcpy((out_c + df->dt[i].offset_out), (in_c + df->dt[i].offset_in), df->dt[i].size);
252 break;
254 } else {
255 switch (df->dt[i].size) {
256 case 1:
257 TRACE("Copying (c) to %d default value %d\n",
258 df->dt[i].offset_out, df->dt[i].value);
259 *(out_c + df->dt[i].offset_out) = (char) df->dt[i].value;
260 break;
262 case 2:
263 TRACE("Copying (s) to %d default value %d\n",
264 df->dt[i].offset_out, df->dt[i].value);
265 *((short *) (out_c + df->dt[i].offset_out)) = (short) df->dt[i].value;
266 break;
268 case 4:
269 TRACE("Copying (i) to %d default value %d\n",
270 df->dt[i].offset_out, df->dt[i].value);
271 *((int *) (out_c + df->dt[i].offset_out)) = (int) df->dt[i].value;
272 break;
274 default:
275 memset((out_c + df->dt[i].offset_out), 0, df->dt[i].size);
276 break;
283 void release_DataFormat(DataFormat * format)
285 TRACE("Deleting DataTransform :\n");
287 HeapFree(GetProcessHeap(), 0, format->dt);
290 /* Make all instances sequential */
291 static void calculate_ids(LPDIDATAFORMAT df)
293 int i, axis = 0, pov = 0, button = 0;
294 int axis_base, pov_base, button_base;
295 DWORD type;
297 /* Make two passes over the format. The first counts the number
298 * for each type and the second sets the id */
299 for (i = 0; i < df->dwNumObjs; i++)
301 type = DIDFT_GETTYPE(df->rgodf[i].dwType);
302 if (type & DIDFT_AXIS) axis++;
303 else if (type & DIDFT_POV) pov++;
304 else if (type & DIDFT_BUTTON) button++;
307 axis_base = 0;
308 pov_base = axis_base + axis;
309 button_base = pov_base + pov;
310 axis = pov = button = 0;
312 for (i = 0; i < df->dwNumObjs; i++)
314 type = DIDFT_GETTYPE(df->rgodf[i].dwType);
315 if (type & DIDFT_AXIS)
317 type |= DIDFT_MAKEINSTANCE(axis_base + axis++);
318 TRACE("axis type = 0x%08x\n", type);
319 } else if (type & DIDFT_POV)
321 type |= DIDFT_MAKEINSTANCE(pov_base + pov++);
322 TRACE("POV type = 0x%08x\n", type);
323 } else if (type & DIDFT_BUTTON)
325 type |= DIDFT_MAKEINSTANCE(button_base + button++);
326 TRACE("button type = 0x%08x\n", type);
328 df->rgodf[i].dwType = type;
332 DataFormat *create_DataFormat(LPCDIDATAFORMAT wine_format, LPDIDATAFORMAT asked_format, int *offset)
334 DataFormat *ret;
335 DataTransform *dt;
336 unsigned int i, j;
337 int same = 1;
338 int *done;
339 int index = 0;
340 DWORD next = 0;
342 ret = HeapAlloc(GetProcessHeap(), 0, sizeof(DataFormat));
344 done = HeapAlloc(GetProcessHeap(), 0, sizeof(int) * asked_format->dwNumObjs);
345 memset(done, 0, sizeof(int) * asked_format->dwNumObjs);
347 dt = HeapAlloc(GetProcessHeap(), 0, asked_format->dwNumObjs * sizeof(DataTransform));
349 TRACE("Creating DataTransform :\n");
351 for (i = 0; i < wine_format->dwNumObjs; i++) {
352 offset[i] = -1;
354 for (j = 0; j < asked_format->dwNumObjs; j++) {
355 if (done[j] == 1)
356 continue;
358 if (/* Check if the application either requests any GUID and if not, it if matches
359 * the GUID of the Wine object.
361 ((asked_format->rgodf[j].pguid == NULL) ||
362 (wine_format->rgodf[i].pguid == NULL) ||
363 (IsEqualGUID(wine_format->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
365 (/* Then check if it accepts any instance id, and if not, if it matches Wine's
366 * instance id.
368 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0xFFFF) ||
369 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == 0x00FF) || /* This is mentionned in no DX docs, but it works fine - tested on WinXP */
370 (DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType) == DIDFT_GETINSTANCE(wine_format->rgodf[i].dwType)))
372 ( /* Then if the asked type matches the one Wine provides */
373 DIDFT_GETTYPE(asked_format->rgodf[j].dwType) & wine_format->rgodf[i].dwType))
375 done[j] = 1;
377 TRACE("Matching :\n");
378 TRACE(" - Asked (%d) :\n", j);
379 TRACE(" * GUID: %s ('%s')\n",
380 debugstr_guid(asked_format->rgodf[j].pguid),
381 _dump_dinput_GUID(asked_format->rgodf[j].pguid));
382 TRACE(" * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
383 TRACE(" * dwType: %08x\n", asked_format->rgodf[j].dwType);
384 TRACE(" "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
386 TRACE(" - Wine (%d) :\n", i);
387 TRACE(" * GUID: %s ('%s')\n",
388 debugstr_guid(wine_format->rgodf[i].pguid),
389 _dump_dinput_GUID(wine_format->rgodf[i].pguid));
390 TRACE(" * Offset: %3d\n", wine_format->rgodf[i].dwOfs);
391 TRACE(" * dwType: %08x\n", wine_format->rgodf[i].dwType);
392 TRACE(" "); _dump_EnumObjects_flags(wine_format->rgodf[i].dwType); TRACE("\n");
394 if (wine_format->rgodf[i].dwType & DIDFT_BUTTON)
395 dt[index].size = sizeof(BYTE);
396 else
397 dt[index].size = sizeof(DWORD);
398 dt[index].offset_in = wine_format->rgodf[i].dwOfs;
399 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
400 offset[i] = asked_format->rgodf[j].dwOfs;
401 dt[index].value = 0;
402 next = next + dt[index].size;
404 if (wine_format->rgodf[i].dwOfs != dt[index].offset_out)
405 same = 0;
407 index++;
408 break;
412 if (j == asked_format->dwNumObjs)
413 same = 0;
416 TRACE("Setting to default value :\n");
417 for (j = 0; j < asked_format->dwNumObjs; j++) {
418 if (done[j] == 0) {
419 TRACE(" - Asked (%d) :\n", j);
420 TRACE(" * GUID: %s ('%s')\n",
421 debugstr_guid(asked_format->rgodf[j].pguid),
422 _dump_dinput_GUID(asked_format->rgodf[j].pguid));
423 TRACE(" * Offset: %3d\n", asked_format->rgodf[j].dwOfs);
424 TRACE(" * dwType: %08x\n", asked_format->rgodf[j].dwType);
425 TRACE(" "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
427 if (asked_format->rgodf[j].dwType & DIDFT_BUTTON)
428 dt[index].size = sizeof(BYTE);
429 else
430 dt[index].size = sizeof(DWORD);
431 dt[index].offset_in = -1;
432 dt[index].offset_out = asked_format->rgodf[j].dwOfs;
433 dt[index].value = 0;
434 index++;
436 same = 0;
440 ret->internal_format_size = wine_format->dwDataSize;
441 ret->size = index;
442 if (same) {
443 ret->dt = NULL;
444 HeapFree(GetProcessHeap(), 0, dt);
445 } else {
446 ret->dt = dt;
449 HeapFree(GetProcessHeap(), 0, done);
451 /* Last step - reset all instances of the new format */
452 calculate_ids(asked_format);
453 return ret;
456 BOOL DIEnumDevicesCallbackAtoW(LPCDIDEVICEOBJECTINSTANCEA lpddi, LPVOID lpvRef) {
457 DIDEVICEOBJECTINSTANCEW ddtmp;
458 device_enumobjects_AtoWcb_data* data;
460 data = (device_enumobjects_AtoWcb_data*) lpvRef;
462 memset(&ddtmp, 0, sizeof(ddtmp));
464 ddtmp.dwSize = sizeof(DIDEVICEINSTANCEW);
465 ddtmp.guidType = lpddi->guidType;
466 ddtmp.dwOfs = lpddi->dwOfs;
467 ddtmp.dwType = lpddi->dwType;
468 ddtmp.dwFlags = lpddi->dwFlags;
469 MultiByteToWideChar(CP_ACP, 0, lpddi->tszName, -1, ddtmp.tszName, MAX_PATH);
471 if (lpddi->dwSize == sizeof(DIDEVICEINSTANCEA)) {
473 * if dwSize < sizeof(DIDEVICEINSTANCEA of DInput version >= 5)
474 * force feedback and other newer datas aren't available
476 ddtmp.dwFFMaxForce = lpddi->dwFFMaxForce;
477 ddtmp.dwFFForceResolution = lpddi->dwFFForceResolution;
478 ddtmp.wCollectionNumber = lpddi->wCollectionNumber;
479 ddtmp.wDesignatorIndex = lpddi->wDesignatorIndex;
480 ddtmp.wUsagePage = lpddi->wUsagePage;
481 ddtmp.wUsage = lpddi->wUsage;
482 ddtmp.dwDimension = lpddi->dwDimension;
483 ddtmp.wExponent = lpddi->wExponent;
484 ddtmp.wReserved = lpddi->wReserved;
486 return data->lpCallBack(&ddtmp, data->lpvRef);
489 /******************************************************************************
490 * queue_event - add new event to the ring queue
493 void queue_event(LPDIRECTINPUTDEVICE8A iface, int ofs, DWORD data, DWORD time, DWORD seq)
495 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
496 int next_pos;
498 if (!This->queue_len || This->overflow || ofs < 0) return;
500 next_pos = (This->queue_head + 1) % This->queue_len;
501 if (next_pos == This->queue_tail)
503 TRACE(" queue overflowed\n");
504 This->overflow = TRUE;
505 return;
508 TRACE(" queueing %d at offset %d (queue head %d / size %d)\n",
509 data, ofs, This->queue_head, This->queue_len);
511 This->data_queue[This->queue_head].dwOfs = ofs;
512 This->data_queue[This->queue_head].dwData = data;
513 This->data_queue[This->queue_head].dwTimeStamp = time;
514 This->data_queue[This->queue_head].dwSequence = seq;
515 This->queue_head = next_pos;
518 /******************************************************************************
519 * Acquire
522 HRESULT WINAPI IDirectInputDevice2AImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
524 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
525 HRESULT res;
527 EnterCriticalSection(&This->crit);
528 res = This->acquired ? S_FALSE : DI_OK;
529 This->acquired = 1;
530 if (res == DI_OK)
531 This->queue_head = This->queue_tail = This->overflow = 0;
532 LeaveCriticalSection(&This->crit);
534 return res;
537 /******************************************************************************
538 * Unacquire
541 HRESULT WINAPI IDirectInputDevice2AImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
543 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
544 HRESULT res;
546 EnterCriticalSection(&This->crit);
547 res = !This->acquired ? DI_NOEFFECT : DI_OK;
548 This->acquired = 0;
549 LeaveCriticalSection(&This->crit);
551 return res;
554 /******************************************************************************
555 * IDirectInputDeviceA
558 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(
559 LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
561 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
563 TRACE("(this=%p,%p)\n",This,df);
565 _dump_DIDATAFORMAT(df);
567 return DI_OK;
570 /******************************************************************************
571 * SetCooperativeLevel
573 * Set cooperative level and the source window for the events.
575 HRESULT WINAPI IDirectInputDevice2AImpl_SetCooperativeLevel(
576 LPDIRECTINPUTDEVICE8A iface, HWND hwnd, DWORD dwflags)
578 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
580 TRACE("(%p) %p,0x%08x\n", This, hwnd, dwflags);
581 TRACE(" cooperative level : ");
582 _dump_cooperativelevel_DI(dwflags);
584 if ((dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == 0 ||
585 (dwflags & (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE)) == (DISCL_EXCLUSIVE | DISCL_NONEXCLUSIVE) ||
586 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == 0 ||
587 (dwflags & (DISCL_FOREGROUND | DISCL_BACKGROUND)) == (DISCL_FOREGROUND | DISCL_BACKGROUND))
588 return DIERR_INVALIDPARAM;
590 if (dwflags == (DISCL_NONEXCLUSIVE | DISCL_BACKGROUND))
591 hwnd = GetDesktopWindow();
593 if (!hwnd) return E_HANDLE;
595 /* For security reasons native does not allow exclusive background level
596 for mouse and keyboard only */
597 if (dwflags & DISCL_EXCLUSIVE && dwflags & DISCL_BACKGROUND &&
598 (IsEqualGUID(&This->guid, &GUID_SysMouse) ||
599 IsEqualGUID(&This->guid, &GUID_SysKeyboard)))
600 return DIERR_UNSUPPORTED;
602 /* Store the window which asks for the mouse */
603 EnterCriticalSection(&This->crit);
604 This->win = hwnd;
605 This->dwCoopLevel = dwflags;
606 LeaveCriticalSection(&This->crit);
608 return DI_OK;
611 /******************************************************************************
612 * SetEventNotification : specifies event to be sent on state change
614 HRESULT WINAPI IDirectInputDevice2AImpl_SetEventNotification(
615 LPDIRECTINPUTDEVICE8A iface, HANDLE event)
617 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
619 TRACE("(%p) %p\n", This, event);
621 EnterCriticalSection(&This->crit);
622 This->hEvent = event;
623 LeaveCriticalSection(&This->crit);
624 return DI_OK;
627 ULONG WINAPI IDirectInputDevice2AImpl_Release(LPDIRECTINPUTDEVICE8A iface)
629 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
630 ULONG ref;
632 ref = InterlockedDecrement(&(This->ref));
633 if (ref) return ref;
635 DeleteCriticalSection(&This->crit);
636 HeapFree(GetProcessHeap(), 0, This->data_queue);
637 HeapFree(GetProcessHeap(), 0, This);
639 return DI_OK;
642 HRESULT WINAPI IDirectInputDevice2AImpl_QueryInterface(
643 LPDIRECTINPUTDEVICE8A iface,REFIID riid,LPVOID *ppobj
646 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
648 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
649 if (IsEqualGUID(&IID_IUnknown,riid)) {
650 IDirectInputDevice2_AddRef(iface);
651 *ppobj = This;
652 return DI_OK;
654 if (IsEqualGUID(&IID_IDirectInputDeviceA,riid)) {
655 IDirectInputDevice2_AddRef(iface);
656 *ppobj = This;
657 return DI_OK;
659 if (IsEqualGUID(&IID_IDirectInputDevice2A,riid)) {
660 IDirectInputDevice2_AddRef(iface);
661 *ppobj = This;
662 return DI_OK;
664 if (IsEqualGUID(&IID_IDirectInputDevice7A,riid)) {
665 IDirectInputDevice7_AddRef(iface);
666 *ppobj = This;
667 return DI_OK;
669 if (IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
670 IDirectInputDevice8_AddRef(iface);
671 *ppobj = This;
672 return DI_OK;
674 TRACE("Unsupported interface !\n");
675 return E_FAIL;
678 HRESULT WINAPI IDirectInputDevice2WImpl_QueryInterface(
679 LPDIRECTINPUTDEVICE8W iface,REFIID riid,LPVOID *ppobj
682 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
684 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(riid),ppobj);
685 if (IsEqualGUID(&IID_IUnknown,riid)) {
686 IDirectInputDevice2_AddRef(iface);
687 *ppobj = This;
688 return DI_OK;
690 if (IsEqualGUID(&IID_IDirectInputDeviceW,riid)) {
691 IDirectInputDevice2_AddRef(iface);
692 *ppobj = This;
693 return DI_OK;
695 if (IsEqualGUID(&IID_IDirectInputDevice2W,riid)) {
696 IDirectInputDevice2_AddRef(iface);
697 *ppobj = This;
698 return DI_OK;
700 if (IsEqualGUID(&IID_IDirectInputDevice7W,riid)) {
701 IDirectInputDevice7_AddRef(iface);
702 *ppobj = This;
703 return DI_OK;
705 if (IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
706 IDirectInputDevice8_AddRef(iface);
707 *ppobj = This;
708 return DI_OK;
710 TRACE("Unsupported interface !\n");
711 return E_FAIL;
714 ULONG WINAPI IDirectInputDevice2AImpl_AddRef(
715 LPDIRECTINPUTDEVICE8A iface)
717 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
718 return InterlockedIncrement(&(This->ref));
721 HRESULT WINAPI IDirectInputDevice2AImpl_EnumObjects(
722 LPDIRECTINPUTDEVICE8A iface,
723 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
724 LPVOID lpvRef,
725 DWORD dwFlags)
727 FIXME("(this=%p,%p,%p,%08x): stub!\n", iface, lpCallback, lpvRef, dwFlags);
728 if (TRACE_ON(dinput)) {
729 DPRINTF(" - flags = ");
730 _dump_EnumObjects_flags(dwFlags);
731 DPRINTF("\n");
734 return DI_OK;
737 HRESULT WINAPI IDirectInputDevice2WImpl_EnumObjects(
738 LPDIRECTINPUTDEVICE8W iface,
739 LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback,
740 LPVOID lpvRef,
741 DWORD dwFlags)
743 FIXME("(this=%p,%p,%p,%08x): stub!\n", iface, lpCallback, lpvRef, dwFlags);
744 if (TRACE_ON(dinput)) {
745 DPRINTF(" - flags = ");
746 _dump_EnumObjects_flags(dwFlags);
747 DPRINTF("\n");
750 return DI_OK;
753 /******************************************************************************
754 * GetProperty
757 HRESULT WINAPI IDirectInputDevice2AImpl_GetProperty(
758 LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPDIPROPHEADER pdiph)
760 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
762 TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
763 _dump_DIPROPHEADER(pdiph);
765 if (HIWORD(rguid)) return DI_OK;
767 switch (LOWORD(rguid))
769 case (DWORD) DIPROP_BUFFERSIZE:
771 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
773 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
775 pd->dwData = This->queue_len;
776 TRACE("buffersize = %d\n", pd->dwData);
777 break;
779 default:
780 WARN("Unknown property %s\n", debugstr_guid(rguid));
781 break;
784 return DI_OK;
787 /******************************************************************************
788 * SetProperty
791 HRESULT WINAPI IDirectInputDevice2AImpl_SetProperty(
792 LPDIRECTINPUTDEVICE8A iface, REFGUID rguid, LPCDIPROPHEADER pdiph)
794 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
796 TRACE("(%p) %s,%p\n", iface, debugstr_guid(rguid), pdiph);
797 _dump_DIPROPHEADER(pdiph);
799 if (HIWORD(rguid)) return DI_OK;
801 switch (LOWORD(rguid))
803 case (DWORD) DIPROP_BUFFERSIZE:
805 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)pdiph;
807 if (pdiph->dwSize != sizeof(DIPROPDWORD)) return DIERR_INVALIDPARAM;
808 if (This->acquired) return DIERR_ACQUIRED;
810 TRACE("buffersize = %d\n", pd->dwData);
812 EnterCriticalSection(&This->crit);
813 HeapFree(GetProcessHeap(), 0, This->data_queue);
815 This->data_queue = !pd->dwData ? NULL : HeapAlloc(GetProcessHeap(), 0,
816 pd->dwData * sizeof(DIDEVICEOBJECTDATA));
817 This->queue_head = This->queue_tail = This->overflow = 0;
818 This->queue_len = pd->dwData;
820 LeaveCriticalSection(&This->crit);
821 break;
823 default:
824 WARN("Unknown property %s\n", debugstr_guid(rguid));
825 return DIERR_UNSUPPORTED;
828 return DI_OK;
831 HRESULT WINAPI IDirectInputDevice2AImpl_GetObjectInfo(
832 LPDIRECTINPUTDEVICE8A iface,
833 LPDIDEVICEOBJECTINSTANCEA pdidoi,
834 DWORD dwObj,
835 DWORD dwHow)
837 FIXME("(this=%p,%p,%d,0x%08x): stub!\n",
838 iface, pdidoi, dwObj, dwHow);
840 return DI_OK;
843 HRESULT WINAPI IDirectInputDevice2WImpl_GetObjectInfo(
844 LPDIRECTINPUTDEVICE8W iface,
845 LPDIDEVICEOBJECTINSTANCEW pdidoi,
846 DWORD dwObj,
847 DWORD dwHow)
849 FIXME("(this=%p,%p,%d,0x%08x): stub!\n",
850 iface, pdidoi, dwObj, dwHow);
852 return DI_OK;
855 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceData(
856 LPDIRECTINPUTDEVICE8A iface, DWORD dodsize, LPDIDEVICEOBJECTDATA dod,
857 LPDWORD entries, DWORD flags)
859 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
860 HRESULT ret = DI_OK;
861 int len;
863 TRACE("(%p) %p -> %p(%d) x%d, 0x%08x\n",
864 This, dod, entries, entries ? *entries : 0, dodsize, flags);
866 if (!This->acquired)
867 return DIERR_NOTACQUIRED;
868 if (!This->queue_len)
869 return DIERR_NOTBUFFERED;
870 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3))
871 return DIERR_INVALIDPARAM;
873 IDirectInputDevice2_Poll(iface);
874 EnterCriticalSection(&This->crit);
876 len = This->queue_head - This->queue_tail;
877 if (len < 0) len += This->queue_len;
879 if ((*entries != INFINITE) && (len > *entries)) len = *entries;
881 if (dod)
883 int i;
884 for (i = 0; i < len; i++)
886 int n = (This->queue_tail + i) % This->queue_len;
887 memcpy((char *)dod + dodsize * i, This->data_queue + n, dodsize);
890 *entries = len;
892 if (This->overflow)
893 ret = DI_BUFFEROVERFLOW;
895 if (!(flags & DIGDD_PEEK))
897 /* Advance reading position */
898 This->queue_tail = (This->queue_tail + len) % This->queue_len;
899 This->overflow = FALSE;
902 LeaveCriticalSection(&This->crit);
904 TRACE("Returning %d events queued\n", *entries);
905 return ret;
908 HRESULT WINAPI IDirectInputDevice2AImpl_GetDeviceInfo(
909 LPDIRECTINPUTDEVICE8A iface,
910 LPDIDEVICEINSTANCEA pdidi)
912 FIXME("(this=%p,%p): stub!\n",
913 iface, pdidi);
915 return DI_OK;
918 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo(
919 LPDIRECTINPUTDEVICE8W iface,
920 LPDIDEVICEINSTANCEW pdidi)
922 FIXME("(this=%p,%p): stub!\n",
923 iface, pdidi);
925 return DI_OK;
928 HRESULT WINAPI IDirectInputDevice2AImpl_RunControlPanel(
929 LPDIRECTINPUTDEVICE8A iface,
930 HWND hwndOwner,
931 DWORD dwFlags)
933 FIXME("(this=%p,%p,0x%08x): stub!\n",
934 iface, hwndOwner, dwFlags);
936 return DI_OK;
939 HRESULT WINAPI IDirectInputDevice2AImpl_Initialize(
940 LPDIRECTINPUTDEVICE8A iface,
941 HINSTANCE hinst,
942 DWORD dwVersion,
943 REFGUID rguid)
945 FIXME("(this=%p,%p,%d,%s): stub!\n",
946 iface, hinst, dwVersion, debugstr_guid(rguid));
947 return DI_OK;
950 /******************************************************************************
951 * IDirectInputDevice2A
954 HRESULT WINAPI IDirectInputDevice2AImpl_CreateEffect(
955 LPDIRECTINPUTDEVICE8A iface,
956 REFGUID rguid,
957 LPCDIEFFECT lpeff,
958 LPDIRECTINPUTEFFECT *ppdef,
959 LPUNKNOWN pUnkOuter)
961 FIXME("(this=%p,%s,%p,%p,%p): stub!\n",
962 iface, debugstr_guid(rguid), lpeff, ppdef, pUnkOuter);
963 return DI_OK;
966 HRESULT WINAPI IDirectInputDevice2AImpl_EnumEffects(
967 LPDIRECTINPUTDEVICE8A iface,
968 LPDIENUMEFFECTSCALLBACKA lpCallback,
969 LPVOID lpvRef,
970 DWORD dwFlags)
972 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
973 iface, lpCallback, lpvRef, dwFlags);
975 return DI_OK;
978 HRESULT WINAPI IDirectInputDevice2WImpl_EnumEffects(
979 LPDIRECTINPUTDEVICE8W iface,
980 LPDIENUMEFFECTSCALLBACKW lpCallback,
981 LPVOID lpvRef,
982 DWORD dwFlags)
984 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
985 iface, lpCallback, lpvRef, dwFlags);
987 return DI_OK;
990 HRESULT WINAPI IDirectInputDevice2AImpl_GetEffectInfo(
991 LPDIRECTINPUTDEVICE8A iface,
992 LPDIEFFECTINFOA lpdei,
993 REFGUID rguid)
995 FIXME("(this=%p,%p,%s): stub!\n",
996 iface, lpdei, debugstr_guid(rguid));
997 return DI_OK;
1000 HRESULT WINAPI IDirectInputDevice2WImpl_GetEffectInfo(
1001 LPDIRECTINPUTDEVICE8W iface,
1002 LPDIEFFECTINFOW lpdei,
1003 REFGUID rguid)
1005 FIXME("(this=%p,%p,%s): stub!\n",
1006 iface, lpdei, debugstr_guid(rguid));
1007 return DI_OK;
1010 HRESULT WINAPI IDirectInputDevice2AImpl_GetForceFeedbackState(
1011 LPDIRECTINPUTDEVICE8A iface,
1012 LPDWORD pdwOut)
1014 FIXME("(this=%p,%p): stub!\n",
1015 iface, pdwOut);
1016 return DI_OK;
1019 HRESULT WINAPI IDirectInputDevice2AImpl_SendForceFeedbackCommand(
1020 LPDIRECTINPUTDEVICE8A iface,
1021 DWORD dwFlags)
1023 FIXME("(this=%p,0x%08x): stub!\n",
1024 iface, dwFlags);
1025 return DI_OK;
1028 HRESULT WINAPI IDirectInputDevice2AImpl_EnumCreatedEffectObjects(
1029 LPDIRECTINPUTDEVICE8A iface,
1030 LPDIENUMCREATEDEFFECTOBJECTSCALLBACK lpCallback,
1031 LPVOID lpvRef,
1032 DWORD dwFlags)
1034 FIXME("(this=%p,%p,%p,0x%08x): stub!\n",
1035 iface, lpCallback, lpvRef, dwFlags);
1036 return DI_OK;
1039 HRESULT WINAPI IDirectInputDevice2AImpl_Escape(
1040 LPDIRECTINPUTDEVICE8A iface,
1041 LPDIEFFESCAPE lpDIEEsc)
1043 FIXME("(this=%p,%p): stub!\n",
1044 iface, lpDIEEsc);
1045 return DI_OK;
1048 HRESULT WINAPI IDirectInputDevice2AImpl_Poll(
1049 LPDIRECTINPUTDEVICE8A iface)
1051 IDirectInputDevice2AImpl *This = (IDirectInputDevice2AImpl *)iface;
1053 if (!This->acquired) return DIERR_NOTACQUIRED;
1054 /* Because wine devices do not need to be polled, just return DI_NOEFFECT */
1055 return DI_NOEFFECT;
1058 HRESULT WINAPI IDirectInputDevice2AImpl_SendDeviceData(
1059 LPDIRECTINPUTDEVICE8A iface,
1060 DWORD cbObjectData,
1061 LPCDIDEVICEOBJECTDATA rgdod,
1062 LPDWORD pdwInOut,
1063 DWORD dwFlags)
1065 FIXME("(this=%p,0x%08x,%p,%p,0x%08x): stub!\n",
1066 iface, cbObjectData, rgdod, pdwInOut, dwFlags);
1068 return DI_OK;
1071 HRESULT WINAPI IDirectInputDevice7AImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8A iface,
1072 LPCSTR lpszFileName,
1073 LPDIENUMEFFECTSINFILECALLBACK pec,
1074 LPVOID pvRef,
1075 DWORD dwFlags)
1077 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, lpszFileName, pec, pvRef, dwFlags);
1079 return DI_OK;
1082 HRESULT WINAPI IDirectInputDevice7WImpl_EnumEffectsInFile(LPDIRECTINPUTDEVICE8W iface,
1083 LPCWSTR lpszFileName,
1084 LPDIENUMEFFECTSINFILECALLBACK pec,
1085 LPVOID pvRef,
1086 DWORD dwFlags)
1088 FIXME("(%p)->(%s,%p,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), pec, pvRef, dwFlags);
1090 return DI_OK;
1093 HRESULT WINAPI IDirectInputDevice7AImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8A iface,
1094 LPCSTR lpszFileName,
1095 DWORD dwEntries,
1096 LPDIFILEEFFECT rgDiFileEft,
1097 DWORD dwFlags)
1099 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, lpszFileName, dwEntries, rgDiFileEft, dwFlags);
1101 return DI_OK;
1104 HRESULT WINAPI IDirectInputDevice7WImpl_WriteEffectToFile(LPDIRECTINPUTDEVICE8W iface,
1105 LPCWSTR lpszFileName,
1106 DWORD dwEntries,
1107 LPDIFILEEFFECT rgDiFileEft,
1108 DWORD dwFlags)
1110 FIXME("(%p)->(%s,%08x,%p,%08x): stub !\n", iface, debugstr_w(lpszFileName), dwEntries, rgDiFileEft, dwFlags);
1112 return DI_OK;
1115 HRESULT WINAPI IDirectInputDevice8AImpl_BuildActionMap(LPDIRECTINPUTDEVICE8A iface,
1116 LPDIACTIONFORMATA lpdiaf,
1117 LPCSTR lpszUserName,
1118 DWORD dwFlags)
1120 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1122 return DI_OK;
1125 HRESULT WINAPI IDirectInputDevice8WImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
1126 LPDIACTIONFORMATW lpdiaf,
1127 LPCWSTR lpszUserName,
1128 DWORD dwFlags)
1130 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1132 return DI_OK;
1135 HRESULT WINAPI IDirectInputDevice8AImpl_SetActionMap(LPDIRECTINPUTDEVICE8A iface,
1136 LPDIACTIONFORMATA lpdiaf,
1137 LPCSTR lpszUserName,
1138 DWORD dwFlags)
1140 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, lpszUserName, dwFlags);
1142 return DI_OK;
1145 HRESULT WINAPI IDirectInputDevice8WImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
1146 LPDIACTIONFORMATW lpdiaf,
1147 LPCWSTR lpszUserName,
1148 DWORD dwFlags)
1150 FIXME("(%p)->(%p,%s,%08x): stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
1152 return DI_OK;
1155 HRESULT WINAPI IDirectInputDevice8AImpl_GetImageInfo(LPDIRECTINPUTDEVICE8A iface,
1156 LPDIDEVICEIMAGEINFOHEADERA lpdiDevImageInfoHeader)
1158 FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1160 return DI_OK;
1163 HRESULT WINAPI IDirectInputDevice8WImpl_GetImageInfo(LPDIRECTINPUTDEVICE8W iface,
1164 LPDIDEVICEIMAGEINFOHEADERW lpdiDevImageInfoHeader)
1166 FIXME("(%p)->(%p): stub !\n", iface, lpdiDevImageInfoHeader);
1168 return DI_OK;