dinput: Call *_create_device directly in IDirectInput7WImpl_CreateDeviceEx.
[wine.git] / dlls / dinput / mouse.c
blob325d38c90d37893e31414747cbc4560d1213682c
1 /* DirectInput Mouse device
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
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 #include <stdarg.h>
23 #include <string.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "wingdi.h"
28 #include "winternl.h"
29 #include "winuser.h"
30 #include "winerror.h"
31 #include "winreg.h"
32 #include "dinput.h"
34 #include "dinput_private.h"
35 #include "device_private.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
40 /* Wine mouse driver object instances */
41 #define WINE_MOUSE_X_AXIS_INSTANCE 0
42 #define WINE_MOUSE_Y_AXIS_INSTANCE 1
43 #define WINE_MOUSE_Z_AXIS_INSTANCE 2
44 #define WINE_MOUSE_BUTTONS_INSTANCE 3
46 static const struct dinput_device_vtbl mouse_vtbl;
48 typedef struct SysMouseImpl SysMouseImpl;
50 typedef enum
52 WARP_DEFAULT,
53 WARP_DISABLE,
54 WARP_FORCE_ON
55 } WARP_MOUSE;
57 struct SysMouseImpl
59 struct IDirectInputDeviceImpl base;
61 /* SysMouseAImpl */
62 /* These are used in case of relative -> absolute transitions */
63 POINT org_coords;
64 BOOL clipped;
65 /* warping: whether we need to move mouse back to middle once we
66 * reach window borders (for e.g. shooters, "surface movement" games) */
67 BOOL need_warp;
68 DWORD last_warped;
70 WARP_MOUSE warp_override;
73 static inline SysMouseImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface)
75 return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface), SysMouseImpl, base);
78 HRESULT mouse_enum_device( DWORD type, DWORD flags, DIDEVICEINSTANCEW *instance, DWORD version, int index )
80 DWORD size;
82 TRACE( "type %#x, flags %#x, instance %p, version %#04x, index %d\n", type, flags, instance, version, index );
84 if (index != 0) return DIERR_GENERIC;
85 if (flags & DIEDFL_FORCEFEEDBACK) return DI_NOEFFECT;
86 if (version < 0x0800 && type != 0 && type != DIDEVTYPE_MOUSE) return DI_NOEFFECT;
87 if (version >= 0x0800 && type != DI8DEVCLASS_ALL && type != DI8DEVCLASS_POINTER && type != DI8DEVTYPE_MOUSE)
88 return DI_NOEFFECT;
90 if (instance->dwSize != sizeof(DIDEVICEINSTANCEW) &&
91 instance->dwSize != sizeof(DIDEVICEINSTANCE_DX3W))
92 return DIERR_INVALIDPARAM;
94 size = instance->dwSize;
95 memset( instance, 0, size );
96 instance->dwSize = size;
97 instance->guidInstance = GUID_SysMouse;
98 instance->guidProduct = GUID_SysMouse;
99 if (version >= 0x0800) instance->dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
100 else instance->dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
101 MultiByteToWideChar( CP_ACP, 0, "Mouse", -1, instance->tszInstanceName, MAX_PATH );
102 MultiByteToWideChar( CP_ACP, 0, "Wine Mouse", -1, instance->tszProductName, MAX_PATH );
104 return DI_OK;
107 HRESULT mouse_create_device( IDirectInputImpl *dinput, const GUID *guid, IDirectInputDevice8W **out )
109 SysMouseImpl *impl;
110 HKEY hkey, appkey;
111 WCHAR buffer[20];
112 HRESULT hr;
114 TRACE( "dinput %p, guid %s, out %p\n", dinput, debugstr_guid( guid ), out );
116 *out = NULL;
117 if (!IsEqualGUID( &GUID_SysMouse, guid )) return DIERR_DEVICENOTREG;
119 if (FAILED(hr = direct_input_device_alloc( sizeof(SysMouseImpl), &mouse_vtbl,
120 guid, dinput, (void **)&impl )))
121 return hr;
122 impl->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit");
124 mouse_enum_device( 0, 0, &impl->base.instance, dinput->dwVersion, 0 );
125 impl->base.caps.dwDevType = impl->base.instance.dwDevType;
126 impl->base.caps.dwFirmwareRevision = 100;
127 impl->base.caps.dwHardwareRevision = 100;
128 impl->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
130 get_app_key(&hkey, &appkey);
131 if (!get_config_key( hkey, appkey, L"MouseWarpOverride", buffer, sizeof(buffer) ))
133 if (!wcsnicmp( buffer, L"disable", -1 )) impl->warp_override = WARP_DISABLE;
134 else if (!wcsnicmp( buffer, L"force", -1 )) impl->warp_override = WARP_FORCE_ON;
136 if (appkey) RegCloseKey(appkey);
137 if (hkey) RegCloseKey(hkey);
139 if (FAILED(hr = direct_input_device_init( &impl->base.IDirectInputDevice8W_iface )))
141 IDirectInputDevice_Release( &impl->base.IDirectInputDevice8W_iface );
142 return hr;
145 if (dinput->dwVersion >= 0x0800)
147 impl->base.use_raw_input = TRUE;
148 impl->base.raw_device.usUsagePage = 1; /* HID generic device page */
149 impl->base.raw_device.usUsage = 2; /* HID generic mouse */
152 *out = &impl->base.IDirectInputDevice8W_iface;
153 return DI_OK;
156 const struct dinput_device mouse_device = {
157 "Wine mouse driver",
158 mouse_enum_device,
159 mouse_create_device
162 /******************************************************************************
163 * SysMouseA (DInput Mouse support)
166 void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam, RAWINPUT *ri )
168 SysMouseImpl *This = impl_from_IDirectInputDevice8W( iface );
169 DIMOUSESTATE2 *state = (DIMOUSESTATE2 *)This->base.device_state;
170 POINT rel, pt;
171 DWORD seq;
172 int i, wdata = 0;
173 BOOL notify = FALSE;
175 static const USHORT mouse_button_flags[] =
177 RI_MOUSE_BUTTON_1_DOWN, RI_MOUSE_BUTTON_1_UP,
178 RI_MOUSE_BUTTON_2_DOWN, RI_MOUSE_BUTTON_2_UP,
179 RI_MOUSE_BUTTON_3_DOWN, RI_MOUSE_BUTTON_3_UP,
180 RI_MOUSE_BUTTON_4_DOWN, RI_MOUSE_BUTTON_4_UP,
181 RI_MOUSE_BUTTON_5_DOWN, RI_MOUSE_BUTTON_5_UP
184 TRACE( "(%p) wp %08lx, lp %08lx\n", iface, wparam, lparam );
186 if (ri->data.mouse.usFlags & MOUSE_VIRTUAL_DESKTOP)
187 FIXME( "Unimplemented MOUSE_VIRTUAL_DESKTOP flag\n" );
188 if (ri->data.mouse.usFlags & MOUSE_ATTRIBUTES_CHANGED)
189 FIXME( "Unimplemented MOUSE_ATTRIBUTES_CHANGED flag\n" );
191 EnterCriticalSection( &This->base.crit );
192 seq = This->base.dinput->evsequence++;
194 rel.x = ri->data.mouse.lLastX;
195 rel.y = ri->data.mouse.lLastY;
196 if (ri->data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE)
198 GetCursorPos( &pt );
199 rel.x -= pt.x;
200 rel.y -= pt.y;
203 state->lX += rel.x;
204 state->lY += rel.y;
206 if (This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS)
208 pt.x = state->lX;
209 pt.y = state->lY;
211 else
213 pt = rel;
216 if (rel.x)
218 queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS,
219 pt.x, GetCurrentTime(), seq );
220 notify = TRUE;
223 if (rel.y)
225 queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS,
226 pt.y, GetCurrentTime(), seq );
227 notify = TRUE;
230 if (rel.x || rel.y)
232 if ((This->warp_override == WARP_FORCE_ON) ||
233 (This->warp_override != WARP_DISABLE && (This->base.dwCoopLevel & DISCL_EXCLUSIVE)))
234 This->need_warp = TRUE;
237 if (ri->data.mouse.usButtonFlags & RI_MOUSE_WHEEL)
239 state->lZ += (wdata = (SHORT)ri->data.mouse.usButtonData);
240 queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS,
241 wdata, GetCurrentTime(), seq );
242 notify = TRUE;
245 for (i = 0; i < ARRAY_SIZE(mouse_button_flags); ++i)
247 if (ri->data.mouse.usButtonFlags & mouse_button_flags[i])
249 state->rgbButtons[i / 2] = 0x80 - (i % 2) * 0x80;
250 queue_event( iface, DIDFT_MAKEINSTANCE( WINE_MOUSE_BUTTONS_INSTANCE + (i / 2) ) | DIDFT_PSHBUTTON,
251 state->rgbButtons[i / 2], GetCurrentTime(), seq );
252 notify = TRUE;
256 TRACE( "buttons %02x %02x %02x %02x %02x, x %d, y %d, w %d\n", state->rgbButtons[0],
257 state->rgbButtons[1], state->rgbButtons[2], state->rgbButtons[3], state->rgbButtons[4],
258 state->lX, state->lY, state->lZ );
260 if (notify && This->base.hEvent) SetEvent( This->base.hEvent );
261 LeaveCriticalSection( &This->base.crit );
264 /* low-level mouse hook */
265 int dinput_mouse_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam )
267 MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam;
268 SysMouseImpl *This = impl_from_IDirectInputDevice8W( iface );
269 DIMOUSESTATE2 *state = (DIMOUSESTATE2 *)This->base.device_state;
270 int wdata = 0, inst_id = -1, ret = 0;
271 BOOL notify = FALSE;
273 TRACE("msg %lx @ (%d %d)\n", wparam, hook->pt.x, hook->pt.y);
275 EnterCriticalSection(&This->base.crit);
277 switch(wparam) {
278 case WM_MOUSEMOVE:
280 POINT pt, pt1;
282 GetCursorPos(&pt);
283 state->lX += pt.x = hook->pt.x - pt.x;
284 state->lY += pt.y = hook->pt.y - pt.y;
286 if (This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS)
288 pt1.x = state->lX;
289 pt1.y = state->lY;
290 } else
291 pt1 = pt;
293 if (pt.x)
295 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS;
296 wdata = pt1.x;
298 if (pt.y)
300 /* Already have X, need to queue it */
301 if (inst_id != -1)
303 queue_event(iface, inst_id,
304 wdata, GetCurrentTime(), This->base.dinput->evsequence);
305 notify = TRUE;
307 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS;
308 wdata = pt1.y;
311 if (pt.x || pt.y)
313 if ((This->warp_override == WARP_FORCE_ON) ||
314 (This->warp_override != WARP_DISABLE && (This->base.dwCoopLevel & DISCL_EXCLUSIVE)))
315 This->need_warp = TRUE;
317 break;
319 case WM_MOUSEWHEEL:
320 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS;
321 state->lZ += wdata = (short)HIWORD( hook->mouseData );
322 /* FarCry crashes if it gets a mouse wheel message */
323 /* FIXME: should probably filter out other messages too */
324 ret = This->clipped;
325 break;
326 case WM_LBUTTONDOWN:
327 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 0) | DIDFT_PSHBUTTON;
328 state->rgbButtons[0] = wdata = 0x80;
329 break;
330 case WM_LBUTTONUP:
331 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 0) | DIDFT_PSHBUTTON;
332 state->rgbButtons[0] = wdata = 0x00;
333 break;
334 case WM_RBUTTONDOWN:
335 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 1) | DIDFT_PSHBUTTON;
336 state->rgbButtons[1] = wdata = 0x80;
337 break;
338 case WM_RBUTTONUP:
339 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 1) | DIDFT_PSHBUTTON;
340 state->rgbButtons[1] = wdata = 0x00;
341 break;
342 case WM_MBUTTONDOWN:
343 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2) | DIDFT_PSHBUTTON;
344 state->rgbButtons[2] = wdata = 0x80;
345 break;
346 case WM_MBUTTONUP:
347 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2) | DIDFT_PSHBUTTON;
348 state->rgbButtons[2] = wdata = 0x00;
349 break;
350 case WM_XBUTTONDOWN:
351 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2 + HIWORD(hook->mouseData)) | DIDFT_PSHBUTTON;
352 state->rgbButtons[2 + HIWORD( hook->mouseData )] = wdata = 0x80;
353 break;
354 case WM_XBUTTONUP:
355 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2 + HIWORD(hook->mouseData)) | DIDFT_PSHBUTTON;
356 state->rgbButtons[2 + HIWORD( hook->mouseData )] = wdata = 0x00;
357 break;
361 if (inst_id != -1)
363 queue_event(iface, inst_id,
364 wdata, GetCurrentTime(), This->base.dinput->evsequence++);
365 notify = TRUE;
368 TRACE( "buttons %02x %02x %02x %02x %02x, x %d, y %d, w %d\n", state->rgbButtons[0],
369 state->rgbButtons[1], state->rgbButtons[2], state->rgbButtons[3], state->rgbButtons[4],
370 state->lX, state->lY, state->lZ );
372 if (notify && This->base.hEvent) SetEvent( This->base.hEvent );
373 LeaveCriticalSection(&This->base.crit);
374 return ret;
377 static void warp_check( SysMouseImpl* This, BOOL force )
379 DWORD now = GetCurrentTime();
380 const DWORD interval = This->clipped ? 500 : 10;
382 if (force || (This->need_warp && (now - This->last_warped > interval)))
384 RECT rect, new_rect;
385 POINT mapped_center;
387 This->last_warped = now;
388 This->need_warp = FALSE;
389 if (!GetClientRect(This->base.win, &rect)) return;
390 MapWindowPoints( This->base.win, 0, (POINT *)&rect, 2 );
391 if (!This->clipped)
393 mapped_center.x = (rect.left + rect.right) / 2;
394 mapped_center.y = (rect.top + rect.bottom) / 2;
395 TRACE("Warping mouse to %d - %d\n", mapped_center.x, mapped_center.y);
396 SetCursorPos( mapped_center.x, mapped_center.y );
398 if (This->base.dwCoopLevel & DISCL_EXCLUSIVE)
400 /* make sure we clip even if the window covers the whole screen */
401 rect.left = max( rect.left, GetSystemMetrics( SM_XVIRTUALSCREEN ) + 1 );
402 rect.top = max( rect.top, GetSystemMetrics( SM_YVIRTUALSCREEN ) + 1 );
403 rect.right = min( rect.right, rect.left + GetSystemMetrics( SM_CXVIRTUALSCREEN ) - 2 );
404 rect.bottom = min( rect.bottom, rect.top + GetSystemMetrics( SM_CYVIRTUALSCREEN ) - 2 );
405 TRACE("Clipping mouse to %s\n", wine_dbgstr_rect( &rect ));
406 ClipCursor( &rect );
407 This->clipped = GetClipCursor( &new_rect ) && EqualRect( &rect, &new_rect );
412 static HRESULT mouse_poll( IDirectInputDevice8W *iface )
414 SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface );
415 check_dinput_events();
416 warp_check( impl, FALSE );
417 return DI_OK;
420 static HRESULT mouse_acquire( IDirectInputDevice8W *iface )
422 SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface );
423 DIMOUSESTATE2 *state = (DIMOUSESTATE2 *)impl->base.device_state;
424 POINT point;
426 /* Init the mouse state */
427 GetCursorPos( &point );
428 if (impl->base.data_format.user_df->dwFlags & DIDF_ABSAXIS)
430 state->lX = point.x;
431 state->lY = point.y;
433 else
435 state->lX = 0;
436 state->lY = 0;
437 impl->org_coords = point;
439 state->lZ = 0;
440 state->rgbButtons[0] = GetKeyState( VK_LBUTTON ) & 0x80;
441 state->rgbButtons[1] = GetKeyState( VK_RBUTTON ) & 0x80;
442 state->rgbButtons[2] = GetKeyState( VK_MBUTTON ) & 0x80;
444 if (impl->base.dwCoopLevel & DISCL_EXCLUSIVE)
446 ShowCursor( FALSE ); /* hide cursor */
447 warp_check( impl, TRUE );
449 else if (impl->warp_override == WARP_FORCE_ON)
451 /* Need a window to warp mouse in. */
452 if (!impl->base.win) impl->base.win = GetDesktopWindow();
453 warp_check( impl, TRUE );
455 else if (impl->clipped)
457 ClipCursor( NULL );
458 impl->clipped = FALSE;
461 return DI_OK;
464 static HRESULT mouse_unacquire( IDirectInputDevice8W *iface )
466 SysMouseImpl *impl = impl_from_IDirectInputDevice8W( iface );
468 if (impl->base.dwCoopLevel & DISCL_EXCLUSIVE)
470 ClipCursor( NULL );
471 ShowCursor( TRUE ); /* show cursor */
472 impl->clipped = FALSE;
475 /* And put the mouse cursor back where it was at acquire time */
476 if (impl->base.dwCoopLevel & DISCL_EXCLUSIVE || impl->warp_override == WARP_FORCE_ON)
478 TRACE( "warping mouse back to %s\n", wine_dbgstr_point( &impl->org_coords ) );
479 SetCursorPos( impl->org_coords.x, impl->org_coords.y );
482 return DI_OK;
485 static BOOL try_enum_object( const DIPROPHEADER *filter, DWORD flags, LPDIENUMDEVICEOBJECTSCALLBACKW callback,
486 DIDEVICEOBJECTINSTANCEW *instance, void *data )
488 if (flags != DIDFT_ALL && !(flags & DIDFT_GETTYPE( instance->dwType ))) return DIENUM_CONTINUE;
490 switch (filter->dwHow)
492 case DIPH_DEVICE:
493 return callback( instance, data );
494 case DIPH_BYOFFSET:
495 if (filter->dwObj != instance->dwOfs) return DIENUM_CONTINUE;
496 return callback( instance, data );
497 case DIPH_BYID:
498 if ((filter->dwObj & 0x00ffffff) != (instance->dwType & 0x00ffffff)) return DIENUM_CONTINUE;
499 return callback( instance, data );
502 return DIENUM_CONTINUE;
505 static HRESULT mouse_enum_objects( IDirectInputDevice8W *iface, const DIPROPHEADER *filter,
506 DWORD flags, LPDIENUMDEVICEOBJECTSCALLBACKW callback, void *context )
508 DIDEVICEOBJECTINSTANCEW instances[] =
511 .dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
512 .guidType = GUID_XAxis,
513 .dwOfs = DIMOFS_X,
514 .dwType = DIDFT_RELAXIS|DIDFT_MAKEINSTANCE(0),
515 .dwFlags = DIDOI_ASPECTPOSITION,
516 .tszName = L"X-axis",
519 .dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
520 .guidType = GUID_YAxis,
521 .dwOfs = DIMOFS_Y,
522 .dwType = DIDFT_RELAXIS|DIDFT_MAKEINSTANCE(1),
523 .dwFlags = DIDOI_ASPECTPOSITION,
524 .tszName = L"Y-axis",
527 .dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
528 .guidType = GUID_ZAxis,
529 .dwOfs = DIMOFS_Z,
530 .dwType = DIDFT_RELAXIS|DIDFT_MAKEINSTANCE(2),
531 .dwFlags = DIDOI_ASPECTPOSITION,
532 .tszName = L"Wheel",
535 .dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
536 .guidType = GUID_Button,
537 .dwOfs = DIMOFS_BUTTON0,
538 .dwType = DIDFT_PSHBUTTON|DIDFT_MAKEINSTANCE(3),
539 .tszName = L"Button 0",
542 .dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
543 .guidType = GUID_Button,
544 .dwOfs = DIMOFS_BUTTON1,
545 .dwType = DIDFT_PSHBUTTON|DIDFT_MAKEINSTANCE(4),
546 .tszName = L"Button 1",
549 .dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
550 .guidType = GUID_Button,
551 .dwOfs = DIMOFS_BUTTON2,
552 .dwType = DIDFT_PSHBUTTON|DIDFT_MAKEINSTANCE(5),
553 .tszName = L"Button 2",
556 .dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
557 .guidType = GUID_Button,
558 .dwOfs = DIMOFS_BUTTON3,
559 .dwType = DIDFT_PSHBUTTON|DIDFT_MAKEINSTANCE(6),
560 .tszName = L"Button 3",
563 .dwSize = sizeof(DIDEVICEOBJECTINSTANCEW),
564 .guidType = GUID_Button,
565 .dwOfs = DIMOFS_BUTTON4,
566 .dwType = DIDFT_PSHBUTTON|DIDFT_MAKEINSTANCE(7),
567 .tszName = L"Button 4",
570 BOOL ret;
571 DWORD i;
573 for (i = 0; i < ARRAY_SIZE(instances); ++i)
575 ret = try_enum_object( filter, flags, callback, instances + i, context );
576 if (ret != DIENUM_CONTINUE) return DIENUM_STOP;
579 return DIENUM_CONTINUE;
582 static HRESULT mouse_get_property( IDirectInputDevice8W *iface, DWORD property,
583 DIPROPHEADER *header, DIDEVICEOBJECTINSTANCEW *instance )
585 switch (property)
587 case (DWORD_PTR)DIPROP_RANGE:
589 DIPROPRANGE *range = (DIPROPRANGE *)header;
590 range->lMin = DIPROPRANGE_NOMIN;
591 range->lMax = DIPROPRANGE_NOMAX;
592 return DI_OK;
594 case (DWORD_PTR)DIPROP_GRANULARITY:
596 DIPROPDWORD *value = (DIPROPDWORD *)header;
597 if (instance->dwType == DIMOFS_Z) value->dwData = WHEEL_DELTA;
598 else value->dwData = 1;
599 return DI_OK;
602 return DIERR_UNSUPPORTED;
605 static HRESULT mouse_set_property( IDirectInputDevice8W *iface, DWORD property,
606 const DIPROPHEADER *header, const DIDEVICEOBJECTINSTANCEW *instance )
608 return DIERR_UNSUPPORTED;
611 static const struct dinput_device_vtbl mouse_vtbl =
613 NULL,
614 mouse_poll,
615 NULL,
616 mouse_acquire,
617 mouse_unacquire,
618 mouse_enum_objects,
619 mouse_get_property,
620 mouse_set_property,
621 NULL,
622 NULL,
623 NULL,
624 NULL,