mfmediaengine: Handle Play() when called before topology is set.
[wine.git] / dlls / dinput / mouse.c
blob22e40a60285a1c840d7fb46cc83b7cee592eb15a
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 "config.h"
23 #include "wine/port.h"
25 #include <stdarg.h>
26 #include <string.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winternl.h"
32 #include "winuser.h"
33 #include "winerror.h"
34 #include "winreg.h"
35 #include "dinput.h"
37 #include "dinput_private.h"
38 #include "device_private.h"
39 #include "wine/debug.h"
40 #include "wine/unicode.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
44 /* Wine mouse driver object instances */
45 #define WINE_MOUSE_X_AXIS_INSTANCE 0
46 #define WINE_MOUSE_Y_AXIS_INSTANCE 1
47 #define WINE_MOUSE_Z_AXIS_INSTANCE 2
48 #define WINE_MOUSE_BUTTONS_INSTANCE 3
50 static const IDirectInputDevice8WVtbl SysMouseWvt;
52 typedef struct SysMouseImpl SysMouseImpl;
54 typedef enum
56 WARP_DEFAULT,
57 WARP_DISABLE,
58 WARP_FORCE_ON
59 } WARP_MOUSE;
61 struct SysMouseImpl
63 struct IDirectInputDeviceImpl base;
65 /* SysMouseAImpl */
66 /* These are used in case of relative -> absolute transitions */
67 POINT org_coords;
68 BOOL clipped;
69 /* warping: whether we need to move mouse back to middle once we
70 * reach window borders (for e.g. shooters, "surface movement" games) */
71 BOOL need_warp;
72 DWORD last_warped;
74 /* This is for mouse reporting. */
75 DIMOUSESTATE2 m_state;
77 WARP_MOUSE warp_override;
80 static inline SysMouseImpl *impl_from_IDirectInputDevice8W(IDirectInputDevice8W *iface)
82 return CONTAINING_RECORD(CONTAINING_RECORD(iface, IDirectInputDeviceImpl, IDirectInputDevice8W_iface), SysMouseImpl, base);
85 static void _dump_mouse_state(const DIMOUSESTATE2 *m_state)
87 int i;
89 if (!TRACE_ON(dinput)) return;
91 TRACE("(X: %d Y: %d Z: %d", m_state->lX, m_state->lY, m_state->lZ);
92 for (i = 0; i < 5; i++) TRACE(" B%d: %02x", i, m_state->rgbButtons[i]);
93 TRACE(")\n");
96 static void fill_mouse_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version) {
97 DWORD dwSize;
98 DIDEVICEINSTANCEW ddi;
100 dwSize = lpddi->dwSize;
102 TRACE("%d %p\n", dwSize, lpddi);
104 memset(lpddi, 0, dwSize);
105 memset(&ddi, 0, sizeof(ddi));
107 ddi.dwSize = dwSize;
108 ddi.guidInstance = GUID_SysMouse;/* DInput's GUID */
109 ddi.guidProduct = GUID_SysMouse;
110 if (version >= 0x0800)
111 ddi.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
112 else
113 ddi.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
114 MultiByteToWideChar(CP_ACP, 0, "Mouse", -1, ddi.tszInstanceName, MAX_PATH);
115 MultiByteToWideChar(CP_ACP, 0, "Wine Mouse", -1, ddi.tszProductName, MAX_PATH);
117 memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
120 static HRESULT mousedev_enum_device(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
122 if (id != 0)
123 return E_FAIL;
125 if (dwFlags & DIEDFL_FORCEFEEDBACK)
126 return S_FALSE;
128 if ((dwDevType == 0) ||
129 ((dwDevType == DIDEVTYPE_MOUSE) && (version < 0x0800)) ||
130 (((dwDevType == DI8DEVCLASS_POINTER) || (dwDevType == DI8DEVTYPE_MOUSE)) && (version >= 0x0800))) {
131 TRACE("Enumerating the mouse device\n");
133 fill_mouse_dideviceinstanceW(lpddi, version);
135 return S_OK;
138 return S_FALSE;
141 static HRESULT alloc_device( REFGUID rguid, IDirectInputImpl *dinput, SysMouseImpl **out )
143 SysMouseImpl* newDevice;
144 LPDIDATAFORMAT df = NULL;
145 unsigned i;
146 char buffer[20];
147 HKEY hkey, appkey;
148 HRESULT hr;
150 if (FAILED(hr = direct_input_device_alloc( sizeof(SysMouseImpl), &SysMouseWvt, rguid, dinput, (void **)&newDevice )))
151 return hr;
152 newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit");
154 newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
156 get_app_key(&hkey, &appkey);
157 if (!get_config_key(hkey, appkey, "MouseWarpOverride", buffer, sizeof(buffer)))
159 if (!_strnicmp(buffer, "disable", -1))
160 newDevice->warp_override = WARP_DISABLE;
161 else if (!_strnicmp(buffer, "force", -1))
162 newDevice->warp_override = WARP_FORCE_ON;
164 if (appkey) RegCloseKey(appkey);
165 if (hkey) RegCloseKey(hkey);
167 /* Create copy of default data format */
168 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIMouse2.dwSize))) goto failed;
169 memcpy(df, &c_dfDIMouse2, c_dfDIMouse2.dwSize);
170 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
171 memcpy(df->rgodf, c_dfDIMouse2.rgodf, df->dwNumObjs * df->dwObjSize);
173 /* Because we don't do any detection yet just modify instance and type */
174 for (i = 0; i < df->dwNumObjs; i++)
175 if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_AXIS)
176 df->rgodf[i].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_RELAXIS;
177 else
178 df->rgodf[i].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
180 newDevice->base.data_format.wine_df = df;
181 if (dinput->dwVersion >= 0x0800)
183 newDevice->base.use_raw_input = TRUE;
184 newDevice->base.raw_device.usUsagePage = 1; /* HID generic device page */
185 newDevice->base.raw_device.usUsage = 2; /* HID generic mouse */
188 *out = newDevice;
189 return DI_OK;
191 failed:
192 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
193 HeapFree(GetProcessHeap(), 0, df);
194 HeapFree(GetProcessHeap(), 0, newDevice);
195 return DIERR_OUTOFMEMORY;
198 static HRESULT mousedev_create_device( IDirectInputImpl *dinput, REFGUID rguid, IDirectInputDevice8W **out )
200 TRACE( "%p %s %p\n", dinput, debugstr_guid( rguid ), out );
201 *out = NULL;
203 if (IsEqualGUID(&GUID_SysMouse, rguid)) /* Wine Mouse */
205 SysMouseImpl *This;
206 HRESULT hr;
208 if (FAILED(hr = alloc_device( rguid, dinput, &This ))) return hr;
210 TRACE( "Created a Mouse device (%p)\n", This );
212 *out = &This->base.IDirectInputDevice8W_iface;
213 return DI_OK;
216 return DIERR_DEVICENOTREG;
219 const struct dinput_device mouse_device = {
220 "Wine mouse driver",
221 mousedev_enum_device,
222 mousedev_create_device
225 /******************************************************************************
226 * SysMouseA (DInput Mouse support)
229 void dinput_mouse_rawinput_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam, RAWINPUT *ri )
231 SysMouseImpl *This = impl_from_IDirectInputDevice8W( iface );
232 POINT rel, pt;
233 DWORD seq;
234 int i, wdata = 0;
236 static const USHORT mouse_button_flags[] =
238 RI_MOUSE_BUTTON_1_DOWN, RI_MOUSE_BUTTON_1_UP,
239 RI_MOUSE_BUTTON_2_DOWN, RI_MOUSE_BUTTON_2_UP,
240 RI_MOUSE_BUTTON_3_DOWN, RI_MOUSE_BUTTON_3_UP,
241 RI_MOUSE_BUTTON_4_DOWN, RI_MOUSE_BUTTON_4_UP,
242 RI_MOUSE_BUTTON_5_DOWN, RI_MOUSE_BUTTON_5_UP
245 TRACE( "(%p) wp %08lx, lp %08lx\n", iface, wparam, lparam );
247 if (ri->data.mouse.usFlags & MOUSE_VIRTUAL_DESKTOP)
248 FIXME( "Unimplemented MOUSE_VIRTUAL_DESKTOP flag\n" );
249 if (ri->data.mouse.usFlags & MOUSE_ATTRIBUTES_CHANGED)
250 FIXME( "Unimplemented MOUSE_ATTRIBUTES_CHANGED flag\n" );
252 EnterCriticalSection( &This->base.crit );
253 seq = This->base.dinput->evsequence++;
255 rel.x = ri->data.mouse.lLastX;
256 rel.y = ri->data.mouse.lLastY;
257 if (ri->data.mouse.usFlags & MOUSE_MOVE_ABSOLUTE)
259 GetCursorPos( &pt );
260 rel.x -= pt.x;
261 rel.y -= pt.y;
264 This->m_state.lX += rel.x;
265 This->m_state.lY += rel.y;
267 if (This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS)
269 pt.x = This->m_state.lX;
270 pt.y = This->m_state.lY;
272 else
274 pt = rel;
277 if (rel.x)
278 queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS,
279 pt.x, GetCurrentTime(), seq );
281 if (rel.y)
282 queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS,
283 pt.y, GetCurrentTime(), seq );
285 if (rel.x || rel.y)
287 if ((This->warp_override == WARP_FORCE_ON) ||
288 (This->warp_override != WARP_DISABLE && (This->base.dwCoopLevel & DISCL_EXCLUSIVE)))
289 This->need_warp = TRUE;
292 if (ri->data.mouse.usButtonFlags & RI_MOUSE_WHEEL)
294 This->m_state.lZ += (wdata = (SHORT)ri->data.mouse.usButtonData);
295 queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS,
296 wdata, GetCurrentTime(), seq );
299 for (i = 0; i < ARRAY_SIZE(mouse_button_flags); ++i)
301 if (ri->data.mouse.usButtonFlags & mouse_button_flags[i])
303 This->m_state.rgbButtons[i / 2] = 0x80 - (i % 2) * 0x80;
304 queue_event( iface, DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE +(i / 2) ) | DIDFT_PSHBUTTON,
305 This->m_state.rgbButtons[i / 2], GetCurrentTime(), seq );
309 LeaveCriticalSection( &This->base.crit );
312 /* low-level mouse hook */
313 int dinput_mouse_hook( IDirectInputDevice8W *iface, WPARAM wparam, LPARAM lparam )
315 MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam;
316 SysMouseImpl *This = impl_from_IDirectInputDevice8W( iface );
317 int wdata = 0, inst_id = -1, ret = 0;
319 TRACE("msg %lx @ (%d %d)\n", wparam, hook->pt.x, hook->pt.y);
321 EnterCriticalSection(&This->base.crit);
323 switch(wparam) {
324 case WM_MOUSEMOVE:
326 POINT pt, pt1;
328 GetCursorPos(&pt);
329 This->m_state.lX += pt.x = hook->pt.x - pt.x;
330 This->m_state.lY += pt.y = hook->pt.y - pt.y;
332 if (This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS)
334 pt1.x = This->m_state.lX;
335 pt1.y = This->m_state.lY;
336 } else
337 pt1 = pt;
339 if (pt.x)
341 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS;
342 wdata = pt1.x;
344 if (pt.y)
346 /* Already have X, need to queue it */
347 if (inst_id != -1)
348 queue_event(iface, inst_id,
349 wdata, GetCurrentTime(), This->base.dinput->evsequence);
350 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS;
351 wdata = pt1.y;
354 if (pt.x || pt.y)
356 if ((This->warp_override == WARP_FORCE_ON) ||
357 (This->warp_override != WARP_DISABLE && (This->base.dwCoopLevel & DISCL_EXCLUSIVE)))
358 This->need_warp = TRUE;
360 break;
362 case WM_MOUSEWHEEL:
363 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS;
364 This->m_state.lZ += wdata = (short)HIWORD(hook->mouseData);
365 /* FarCry crashes if it gets a mouse wheel message */
366 /* FIXME: should probably filter out other messages too */
367 ret = This->clipped;
368 break;
369 case WM_LBUTTONDOWN:
370 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 0) | DIDFT_PSHBUTTON;
371 This->m_state.rgbButtons[0] = wdata = 0x80;
372 break;
373 case WM_LBUTTONUP:
374 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 0) | DIDFT_PSHBUTTON;
375 This->m_state.rgbButtons[0] = wdata = 0x00;
376 break;
377 case WM_RBUTTONDOWN:
378 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 1) | DIDFT_PSHBUTTON;
379 This->m_state.rgbButtons[1] = wdata = 0x80;
380 break;
381 case WM_RBUTTONUP:
382 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 1) | DIDFT_PSHBUTTON;
383 This->m_state.rgbButtons[1] = wdata = 0x00;
384 break;
385 case WM_MBUTTONDOWN:
386 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2) | DIDFT_PSHBUTTON;
387 This->m_state.rgbButtons[2] = wdata = 0x80;
388 break;
389 case WM_MBUTTONUP:
390 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2) | DIDFT_PSHBUTTON;
391 This->m_state.rgbButtons[2] = wdata = 0x00;
392 break;
393 case WM_XBUTTONDOWN:
394 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2 + HIWORD(hook->mouseData)) | DIDFT_PSHBUTTON;
395 This->m_state.rgbButtons[2 + HIWORD(hook->mouseData)] = wdata = 0x80;
396 break;
397 case WM_XBUTTONUP:
398 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2 + HIWORD(hook->mouseData)) | DIDFT_PSHBUTTON;
399 This->m_state.rgbButtons[2 + HIWORD(hook->mouseData)] = wdata = 0x00;
400 break;
404 if (inst_id != -1)
406 _dump_mouse_state(&This->m_state);
407 queue_event(iface, inst_id,
408 wdata, GetCurrentTime(), This->base.dinput->evsequence++);
411 LeaveCriticalSection(&This->base.crit);
412 return ret;
415 static void warp_check( SysMouseImpl* This, BOOL force )
417 DWORD now = GetCurrentTime();
418 const DWORD interval = This->clipped ? 500 : 10;
420 if (force || (This->need_warp && (now - This->last_warped > interval)))
422 RECT rect, new_rect;
423 POINT mapped_center;
425 This->last_warped = now;
426 This->need_warp = FALSE;
427 if (!GetClientRect(This->base.win, &rect)) return;
428 MapWindowPoints( This->base.win, 0, (POINT *)&rect, 2 );
429 if (!This->clipped)
431 mapped_center.x = (rect.left + rect.right) / 2;
432 mapped_center.y = (rect.top + rect.bottom) / 2;
433 TRACE("Warping mouse to %d - %d\n", mapped_center.x, mapped_center.y);
434 SetCursorPos( mapped_center.x, mapped_center.y );
436 if (This->base.dwCoopLevel & DISCL_EXCLUSIVE)
438 /* make sure we clip even if the window covers the whole screen */
439 rect.left = max( rect.left, GetSystemMetrics( SM_XVIRTUALSCREEN ) + 1 );
440 rect.top = max( rect.top, GetSystemMetrics( SM_YVIRTUALSCREEN ) + 1 );
441 rect.right = min( rect.right, rect.left + GetSystemMetrics( SM_CXVIRTUALSCREEN ) - 2 );
442 rect.bottom = min( rect.bottom, rect.top + GetSystemMetrics( SM_CYVIRTUALSCREEN ) - 2 );
443 TRACE("Clipping mouse to %s\n", wine_dbgstr_rect( &rect ));
444 ClipCursor( &rect );
445 This->clipped = GetClipCursor( &new_rect ) && EqualRect( &rect, &new_rect );
451 /******************************************************************************
452 * Acquire : gets exclusive control of the mouse
454 static HRESULT WINAPI SysMouseWImpl_Acquire(LPDIRECTINPUTDEVICE8W iface)
456 SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
457 POINT point;
458 HRESULT res;
460 TRACE("(this=%p)\n",This);
462 if ((res = IDirectInputDevice2WImpl_Acquire(iface)) != DI_OK) return res;
464 /* Init the mouse state */
465 GetCursorPos( &point );
466 if (This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS)
468 This->m_state.lX = point.x;
469 This->m_state.lY = point.y;
470 } else {
471 This->m_state.lX = 0;
472 This->m_state.lY = 0;
473 This->org_coords = point;
475 This->m_state.lZ = 0;
476 This->m_state.rgbButtons[0] = GetKeyState(VK_LBUTTON) & 0x80;
477 This->m_state.rgbButtons[1] = GetKeyState(VK_RBUTTON) & 0x80;
478 This->m_state.rgbButtons[2] = GetKeyState(VK_MBUTTON) & 0x80;
480 if (This->base.dwCoopLevel & DISCL_EXCLUSIVE)
482 ShowCursor(FALSE); /* hide cursor */
483 warp_check( This, TRUE );
485 else if (This->warp_override == WARP_FORCE_ON)
487 /* Need a window to warp mouse in. */
488 if (!This->base.win) This->base.win = GetDesktopWindow();
489 warp_check( This, TRUE );
491 else if (This->clipped)
493 ClipCursor( NULL );
494 This->clipped = FALSE;
497 return DI_OK;
500 /******************************************************************************
501 * Unacquire : frees the mouse
503 static HRESULT WINAPI SysMouseWImpl_Unacquire(LPDIRECTINPUTDEVICE8W iface)
505 SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
506 HRESULT res;
508 TRACE("(this=%p)\n",This);
510 if ((res = IDirectInputDevice2WImpl_Unacquire(iface)) != DI_OK) return res;
512 if (This->base.dwCoopLevel & DISCL_EXCLUSIVE)
514 ClipCursor(NULL);
515 ShowCursor(TRUE); /* show cursor */
516 This->clipped = FALSE;
519 /* And put the mouse cursor back where it was at acquire time */
520 if (This->base.dwCoopLevel & DISCL_EXCLUSIVE || This->warp_override == WARP_FORCE_ON)
522 TRACE("warping mouse back to %s\n", wine_dbgstr_point(&This->org_coords));
523 SetCursorPos(This->org_coords.x, This->org_coords.y);
526 return DI_OK;
529 /******************************************************************************
530 * GetDeviceState : returns the "state" of the mouse.
532 * For the moment, only the "standard" return structure (DIMOUSESTATE) is
533 * supported.
535 static HRESULT WINAPI SysMouseWImpl_GetDeviceState(LPDIRECTINPUTDEVICE8W iface, DWORD len, LPVOID ptr)
537 SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
538 TRACE("(%p)->(%u,%p)\n", This, len, ptr);
540 if(This->base.acquired == 0) return DIERR_NOTACQUIRED;
542 check_dinput_events();
544 EnterCriticalSection(&This->base.crit);
545 _dump_mouse_state(&This->m_state);
547 /* Copy the current mouse state */
548 fill_DataFormat(ptr, len, &This->m_state, &This->base.data_format);
550 /* Initialize the buffer when in relative mode */
551 if (!(This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS))
553 This->m_state.lX = 0;
554 This->m_state.lY = 0;
555 This->m_state.lZ = 0;
557 LeaveCriticalSection(&This->base.crit);
559 warp_check( This, FALSE );
560 return DI_OK;
563 /******************************************************************************
564 * GetDeviceData : gets buffered input data.
566 static HRESULT WINAPI SysMouseWImpl_GetDeviceData(LPDIRECTINPUTDEVICE8W iface,
567 DWORD dodsize, LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
569 SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
570 HRESULT res;
572 res = IDirectInputDevice2WImpl_GetDeviceData(iface, dodsize, dod, entries, flags);
573 if (SUCCEEDED(res)) warp_check( This, FALSE );
574 return res;
577 /******************************************************************************
578 * GetProperty : get input device properties
580 static HRESULT WINAPI SysMouseWImpl_GetProperty(LPDIRECTINPUTDEVICE8W iface, REFGUID rguid, LPDIPROPHEADER pdiph)
582 SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
584 TRACE("(%p) %s,%p\n", This, debugstr_guid(rguid), pdiph);
585 _dump_DIPROPHEADER(pdiph);
587 if (IS_DIPROP(rguid)) {
588 switch (LOWORD(rguid)) {
589 case (DWORD_PTR) DIPROP_GRANULARITY: {
590 LPDIPROPDWORD pr = (LPDIPROPDWORD) pdiph;
592 if (
593 ((pdiph->dwHow == DIPH_BYOFFSET) &&
594 ((pdiph->dwObj == DIMOFS_X) ||
595 (pdiph->dwObj == DIMOFS_Y)))
597 ((pdiph->dwHow == DIPH_BYID) &&
598 ((pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS)) ||
599 (pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS))))
601 /* Set granularity of X/Y Axis to 1. See MSDN on DIPROP_GRANULARITY */
602 pr->dwData = 1;
603 } else {
604 /* We'll just assume that the app asks about the Z axis */
605 pr->dwData = WHEEL_DELTA;
608 break;
611 case (DWORD_PTR) DIPROP_RANGE: {
612 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
614 if ((pdiph->dwHow == DIPH_BYID) &&
615 ((pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS)) ||
616 (pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS)))) {
617 /* Querying the range of either the X or the Y axis. As I do
618 not know the range, do as if the range were
619 unrestricted...*/
620 pr->lMin = DIPROPRANGE_NOMIN;
621 pr->lMax = DIPROPRANGE_NOMAX;
624 break;
626 case (DWORD_PTR) DIPROP_VIDPID:
627 return DIERR_UNSUPPORTED;
628 default:
629 return IDirectInputDevice2WImpl_GetProperty(iface, rguid, pdiph);
633 return DI_OK;
636 /******************************************************************************
637 * GetCapabilities : get the device capabilities
639 static HRESULT WINAPI SysMouseWImpl_GetCapabilities(LPDIRECTINPUTDEVICE8W iface, LPDIDEVCAPS lpDIDevCaps)
641 SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
642 DIDEVCAPS devcaps;
644 TRACE("(this=%p,%p)\n",This,lpDIDevCaps);
646 if ((lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) && (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS_DX3))) {
647 WARN("invalid parameter\n");
648 return DIERR_INVALIDPARAM;
651 devcaps.dwSize = lpDIDevCaps->dwSize;
652 devcaps.dwFlags = DIDC_ATTACHED | DIDC_EMULATED;
653 if (This->base.dinput->dwVersion >= 0x0800)
654 devcaps.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
655 else
656 devcaps.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
657 devcaps.dwAxes = 3;
658 devcaps.dwButtons = 8;
659 devcaps.dwPOVs = 0;
660 devcaps.dwFFSamplePeriod = 0;
661 devcaps.dwFFMinTimeResolution = 0;
662 devcaps.dwFirmwareRevision = 100;
663 devcaps.dwHardwareRevision = 100;
664 devcaps.dwFFDriverVersion = 0;
666 memcpy(lpDIDevCaps, &devcaps, lpDIDevCaps->dwSize);
668 return DI_OK;
671 /******************************************************************************
672 * GetObjectInfo : get information about a device object such as a button
673 * or axis
675 static HRESULT WINAPI SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
676 LPDIDEVICEOBJECTINSTANCEW pdidoi, DWORD dwObj, DWORD dwHow)
678 static const WCHAR x_axisW[] = {'X','-','A','x','i','s',0};
679 static const WCHAR y_axisW[] = {'Y','-','A','x','i','s',0};
680 static const WCHAR wheelW[] = {'W','h','e','e','l',0};
681 static const WCHAR buttonW[] = {'B','u','t','t','o','n',' ','%','d',0};
682 HRESULT res;
684 res = IDirectInputDevice2WImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
685 if (res != DI_OK) return res;
687 if (IsEqualGUID(&pdidoi->guidType, &GUID_XAxis)) strcpyW(pdidoi->tszName, x_axisW);
688 else if (IsEqualGUID(&pdidoi->guidType, &GUID_YAxis)) strcpyW(pdidoi->tszName, y_axisW);
689 else if (IsEqualGUID(&pdidoi->guidType, &GUID_ZAxis)) strcpyW(pdidoi->tszName, wheelW);
690 else if (pdidoi->dwType & DIDFT_BUTTON)
691 wsprintfW(pdidoi->tszName, buttonW, DIDFT_GETINSTANCE(pdidoi->dwType) - 3);
693 if(pdidoi->dwType & DIDFT_AXIS)
694 pdidoi->dwFlags |= DIDOI_ASPECTPOSITION;
696 _dump_OBJECTINSTANCEW(pdidoi);
697 return res;
700 /******************************************************************************
701 * GetDeviceInfo : get information about a device's identity
703 static HRESULT WINAPI SysMouseWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW pdidi)
705 SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
706 TRACE("(this=%p,%p)\n", This, pdidi);
708 if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)) {
709 WARN(" dinput3 not supported yet...\n");
710 return DI_OK;
713 fill_mouse_dideviceinstanceW(pdidi, This->base.dinput->dwVersion);
715 return DI_OK;
718 static HRESULT WINAPI SysMouseWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
719 LPDIACTIONFORMATW lpdiaf,
720 LPCWSTR lpszUserName,
721 DWORD dwFlags)
723 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", iface, lpdiaf, debugstr_w(lpszUserName), dwFlags);
725 return _build_action_map(iface, lpdiaf, lpszUserName, dwFlags, DIMOUSE_MASK, &c_dfDIMouse2);
728 static HRESULT WINAPI SysMouseWImpl_SetActionMap(LPDIRECTINPUTDEVICE8W iface,
729 LPDIACTIONFORMATW lpdiaf,
730 LPCWSTR lpszUserName,
731 DWORD dwFlags)
733 SysMouseImpl *This = impl_from_IDirectInputDevice8W(iface);
734 FIXME("(%p)->(%p,%s,%08x): semi-stub !\n", This, lpdiaf, debugstr_w(lpszUserName), dwFlags);
736 return _set_action_map(iface, lpdiaf, lpszUserName, dwFlags, &c_dfDIMouse2);
739 static const IDirectInputDevice8WVtbl SysMouseWvt =
741 IDirectInputDevice2WImpl_QueryInterface,
742 IDirectInputDevice2WImpl_AddRef,
743 IDirectInputDevice2WImpl_Release,
744 SysMouseWImpl_GetCapabilities,
745 IDirectInputDevice2WImpl_EnumObjects,
746 SysMouseWImpl_GetProperty,
747 IDirectInputDevice2WImpl_SetProperty,
748 SysMouseWImpl_Acquire,
749 SysMouseWImpl_Unacquire,
750 SysMouseWImpl_GetDeviceState,
751 SysMouseWImpl_GetDeviceData,
752 IDirectInputDevice2WImpl_SetDataFormat,
753 IDirectInputDevice2WImpl_SetEventNotification,
754 IDirectInputDevice2WImpl_SetCooperativeLevel,
755 SysMouseWImpl_GetObjectInfo,
756 SysMouseWImpl_GetDeviceInfo,
757 IDirectInputDevice2WImpl_RunControlPanel,
758 IDirectInputDevice2WImpl_Initialize,
759 IDirectInputDevice2WImpl_CreateEffect,
760 IDirectInputDevice2WImpl_EnumEffects,
761 IDirectInputDevice2WImpl_GetEffectInfo,
762 IDirectInputDevice2WImpl_GetForceFeedbackState,
763 IDirectInputDevice2WImpl_SendForceFeedbackCommand,
764 IDirectInputDevice2WImpl_EnumCreatedEffectObjects,
765 IDirectInputDevice2WImpl_Escape,
766 IDirectInputDevice2WImpl_Poll,
767 IDirectInputDevice2WImpl_SendDeviceData,
768 IDirectInputDevice7WImpl_EnumEffectsInFile,
769 IDirectInputDevice7WImpl_WriteEffectToFile,
770 SysMouseWImpl_BuildActionMap,
771 SysMouseWImpl_SetActionMap,
772 IDirectInputDevice8WImpl_GetImageInfo