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
23 #include "wine/port.h"
36 #include "dinput_private.h"
37 #include "device_private.h"
38 #include "wine/debug.h"
39 #include "wine/unicode.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
43 /* Wine mouse driver object instances */
44 #define WINE_MOUSE_X_AXIS_INSTANCE 0
45 #define WINE_MOUSE_Y_AXIS_INSTANCE 1
46 #define WINE_MOUSE_Z_AXIS_INSTANCE 2
47 #define WINE_MOUSE_BUTTONS_INSTANCE 3
49 static const IDirectInputDevice8AVtbl SysMouseAvt;
50 static const IDirectInputDevice8WVtbl SysMouseWvt;
52 typedef struct SysMouseImpl SysMouseImpl;
63 struct IDirectInputDevice2AImpl base;
66 /* These are used in case of relative -> absolute transitions */
69 DWORD win_centerX, win_centerY;
70 /* warping: whether we need to move mouse back to middle once we
71 * reach window borders (for e.g. shooters, "surface movement" games) */
75 /* This is for mouse reporting. */
76 DIMOUSESTATE2 m_state;
78 WARP_MOUSE warp_override;
81 static void dinput_mouse_hook( LPDIRECTINPUTDEVICE8A iface, WPARAM wparam, LPARAM lparam );
83 const GUID DInput_Wine_Mouse_GUID = { /* 9e573ed8-7734-11d2-8d4a-23903fb6bdf7 */
84 0x9e573ed8, 0x7734, 0x11d2, {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
87 static void _dump_mouse_state(DIMOUSESTATE2 *m_state)
91 if (!TRACE_ON(dinput)) return;
93 TRACE("(X: %d Y: %d Z: %d", m_state->lX, m_state->lY, m_state->lZ);
94 for (i = 0; i < 5; i++) TRACE(" B%d: %02x", i, m_state->rgbButtons[i]);
98 static void fill_mouse_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, DWORD version) {
100 DIDEVICEINSTANCEA ddi;
102 dwSize = lpddi->dwSize;
104 TRACE("%d %p\n", dwSize, lpddi);
106 memset(lpddi, 0, dwSize);
107 memset(&ddi, 0, sizeof(ddi));
110 ddi.guidInstance = GUID_SysMouse;/* DInput's GUID */
111 ddi.guidProduct = DInput_Wine_Mouse_GUID; /* Vendor's GUID */
112 if (version >= 0x0800)
113 ddi.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
115 ddi.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
116 strcpy(ddi.tszInstanceName, "Mouse");
117 strcpy(ddi.tszProductName, "Wine Mouse");
119 memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
122 static void fill_mouse_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version) {
124 DIDEVICEINSTANCEW ddi;
126 dwSize = lpddi->dwSize;
128 TRACE("%d %p\n", dwSize, lpddi);
130 memset(lpddi, 0, dwSize);
131 memset(&ddi, 0, sizeof(ddi));
134 ddi.guidInstance = GUID_SysMouse;/* DInput's GUID */
135 ddi.guidProduct = DInput_Wine_Mouse_GUID; /* Vendor's GUID */
136 if (version >= 0x0800)
137 ddi.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
139 ddi.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
140 MultiByteToWideChar(CP_ACP, 0, "Mouse", -1, ddi.tszInstanceName, MAX_PATH);
141 MultiByteToWideChar(CP_ACP, 0, "Wine Mouse", -1, ddi.tszProductName, MAX_PATH);
143 memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
146 static BOOL mousedev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
151 if ((dwDevType == 0) ||
152 ((dwDevType == DIDEVTYPE_MOUSE) && (version < 0x0800)) ||
153 (((dwDevType == DI8DEVCLASS_POINTER) || (dwDevType == DI8DEVTYPE_MOUSE)) && (version >= 0x0800))) {
154 TRACE("Enumerating the mouse device\n");
156 fill_mouse_dideviceinstanceA(lpddi, version);
164 static BOOL mousedev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
169 if ((dwDevType == 0) ||
170 ((dwDevType == DIDEVTYPE_MOUSE) && (version < 0x0800)) ||
171 (((dwDevType == DI8DEVCLASS_POINTER) || (dwDevType == DI8DEVTYPE_MOUSE)) && (version >= 0x0800))) {
172 TRACE("Enumerating the mouse device\n");
174 fill_mouse_dideviceinstanceW(lpddi, version);
182 static SysMouseImpl *alloc_device(REFGUID rguid, const void *mvt, IDirectInputImpl *dinput)
184 SysMouseImpl* newDevice;
185 LPDIDATAFORMAT df = NULL;
190 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouseImpl));
191 if (!newDevice) return NULL;
192 newDevice->base.lpVtbl = mvt;
193 newDevice->base.ref = 1;
194 newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
195 newDevice->base.guid = *rguid;
196 InitializeCriticalSection(&newDevice->base.crit);
197 newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysMouseImpl*->base.crit");
198 newDevice->base.dinput = dinput;
199 newDevice->base.event_proc = dinput_mouse_hook;
201 get_app_key(&hkey, &appkey);
202 if (!get_config_key(hkey, appkey, "MouseWarpOverride", buffer, sizeof(buffer)))
204 if (!strcasecmp(buffer, "disable"))
205 newDevice->warp_override = WARP_DISABLE;
206 else if (!strcasecmp(buffer, "force"))
207 newDevice->warp_override = WARP_FORCE_ON;
209 if (appkey) RegCloseKey(appkey);
210 if (hkey) RegCloseKey(hkey);
212 /* Create copy of default data format */
213 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIMouse2.dwSize))) goto failed;
214 memcpy(df, &c_dfDIMouse2, c_dfDIMouse2.dwSize);
215 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
216 memcpy(df->rgodf, c_dfDIMouse2.rgodf, df->dwNumObjs * df->dwObjSize);
218 /* Because we don't do any detection yet just modify instance and type */
219 for (i = 0; i < df->dwNumObjs; i++)
220 if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_AXIS)
221 df->rgodf[i].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_RELAXIS;
223 df->rgodf[i].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
225 newDevice->base.data_format.wine_df = df;
226 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->base.dinput);
230 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
231 HeapFree(GetProcessHeap(), 0, df);
232 HeapFree(GetProcessHeap(), 0, newDevice);
236 static HRESULT mousedev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
238 if ((IsEqualGUID(&GUID_SysMouse,rguid)) || /* Generic Mouse */
239 (IsEqualGUID(&DInput_Wine_Mouse_GUID,rguid))) { /* Wine Mouse */
240 if ((riid == NULL) ||
241 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
242 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
243 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
244 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
245 *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &SysMouseAvt, dinput);
246 TRACE("Creating a Mouse device (%p)\n", *pdev);
247 if (!*pdev) return DIERR_OUTOFMEMORY;
250 return DIERR_NOINTERFACE;
253 return DIERR_DEVICENOTREG;
256 static HRESULT mousedev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
258 if ((IsEqualGUID(&GUID_SysMouse,rguid)) || /* Generic Mouse */
259 (IsEqualGUID(&DInput_Wine_Mouse_GUID,rguid))) { /* Wine Mouse */
260 if ((riid == NULL) ||
261 IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
262 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
263 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
264 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
265 *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &SysMouseWvt, dinput);
266 TRACE("Creating a Mouse device (%p)\n", *pdev);
267 if (!*pdev) return DIERR_OUTOFMEMORY;
270 return DIERR_NOINTERFACE;
273 return DIERR_DEVICENOTREG;
276 const struct dinput_device mouse_device = {
278 mousedev_enum_deviceA,
279 mousedev_enum_deviceW,
280 mousedev_create_deviceA,
281 mousedev_create_deviceW
284 /******************************************************************************
285 * SysMouseA (DInput Mouse support)
288 /* low-level mouse hook */
289 static void dinput_mouse_hook( LPDIRECTINPUTDEVICE8A iface, WPARAM wparam, LPARAM lparam )
291 MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam;
292 SysMouseImpl* This = (SysMouseImpl*) iface;
294 int wdata = 0, inst_id = -1;
296 TRACE("msg %lx @ (%d %d)\n", wparam, hook->pt.x, hook->pt.y);
298 EnterCriticalSection(&This->base.crit);
299 dwCoop = This->base.dwCoopLevel;
307 This->m_state.lX += pt.x = hook->pt.x - pt.x;
308 This->m_state.lY += pt.y = hook->pt.y - pt.y;
310 if (This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS)
312 pt1.x = This->m_state.lX;
313 pt1.y = This->m_state.lY;
319 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS;
324 /* Already have X, need to queue it */
326 queue_event((LPDIRECTINPUTDEVICE8A)This, id_to_offset(&This->base.data_format, inst_id),
327 wdata, GetCurrentTime(), This->base.dinput->evsequence);
328 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS;
332 This->need_warp = This->warp_override != WARP_DISABLE &&
334 (dwCoop & DISCL_EXCLUSIVE || This->warp_override == WARP_FORCE_ON);
338 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS;
339 This->m_state.lZ += wdata = (short)HIWORD(hook->mouseData);
342 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 0) | DIDFT_PSHBUTTON;
343 This->m_state.rgbButtons[0] = wdata = 0x80;
346 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 0) | DIDFT_PSHBUTTON;
347 This->m_state.rgbButtons[0] = wdata = 0x00;
350 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 1) | DIDFT_PSHBUTTON;
351 This->m_state.rgbButtons[1] = wdata = 0x80;
354 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 1) | DIDFT_PSHBUTTON;
355 This->m_state.rgbButtons[1] = wdata = 0x00;
358 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2) | DIDFT_PSHBUTTON;
359 This->m_state.rgbButtons[2] = wdata = 0x80;
362 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2) | DIDFT_PSHBUTTON;
363 This->m_state.rgbButtons[2] = wdata = 0x00;
366 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2 + HIWORD(hook->mouseData)) | DIDFT_PSHBUTTON;
367 This->m_state.rgbButtons[2 + HIWORD(hook->mouseData)] = wdata = 0x80;
370 inst_id = DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE + 2 + HIWORD(hook->mouseData)) | DIDFT_PSHBUTTON;
371 This->m_state.rgbButtons[2 + HIWORD(hook->mouseData)] = wdata = 0x00;
378 _dump_mouse_state(&This->m_state);
379 queue_event((LPDIRECTINPUTDEVICE8A)This, id_to_offset(&This->base.data_format, inst_id),
380 wdata, GetCurrentTime(), This->base.dinput->evsequence++);
383 LeaveCriticalSection(&This->base.crit);
386 static BOOL dinput_window_check(SysMouseImpl* This) {
388 DWORD centerX, centerY;
390 /* make sure the window hasn't moved */
391 if(!GetWindowRect(This->base.win, &rect))
393 centerX = (rect.right - rect.left) / 2;
394 centerY = (rect.bottom - rect.top ) / 2;
395 if (This->win_centerX != centerX || This->win_centerY != centerY) {
396 This->win_centerX = centerX;
397 This->win_centerY = centerY;
399 This->mapped_center.x = This->win_centerX;
400 This->mapped_center.y = This->win_centerY;
401 MapWindowPoints(This->base.win, HWND_DESKTOP, &This->mapped_center, 1);
406 /******************************************************************************
407 * Acquire : gets exclusive control of the mouse
409 static HRESULT WINAPI SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
411 SysMouseImpl *This = (SysMouseImpl *)iface;
416 TRACE("(this=%p)\n",This);
418 if ((res = IDirectInputDevice2AImpl_Acquire(iface)) != DI_OK) return res;
420 /* Init the mouse state */
421 GetCursorPos( &point );
422 if (This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS)
424 This->m_state.lX = point.x;
425 This->m_state.lY = point.y;
427 This->m_state.lX = 0;
428 This->m_state.lY = 0;
429 This->org_coords = point;
431 This->m_state.lZ = 0;
432 This->m_state.rgbButtons[0] = GetKeyState(VK_LBUTTON) & 0x80;
433 This->m_state.rgbButtons[1] = GetKeyState(VK_RBUTTON) & 0x80;
434 This->m_state.rgbButtons[2] = GetKeyState(VK_MBUTTON) & 0x80;
436 /* Install our mouse hook */
437 if (This->base.dwCoopLevel & DISCL_EXCLUSIVE)
441 ShowCursor(FALSE); /* hide cursor */
442 if (GetWindowRect(This->base.win, &rc))
444 FIXME("Clipping cursor to %s\n", wine_dbgstr_rect( &rc ));
448 ERR("Failed to get RECT: %d\n", GetLastError());
451 /* Need a window to warp mouse in. */
452 if (This->warp_override == WARP_FORCE_ON && !This->base.win)
453 This->base.win = GetDesktopWindow();
455 /* Get the window dimension and find the center */
456 GetWindowRect(This->base.win, &rect);
457 This->win_centerX = (rect.right - rect.left) / 2;
458 This->win_centerY = (rect.bottom - rect.top ) / 2;
460 /* Warp the mouse to the center of the window */
461 if (This->base.dwCoopLevel & DISCL_EXCLUSIVE || This->warp_override == WARP_FORCE_ON)
463 This->mapped_center.x = This->win_centerX;
464 This->mapped_center.y = This->win_centerY;
465 MapWindowPoints(This->base.win, HWND_DESKTOP, &This->mapped_center, 1);
466 TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y);
467 SetCursorPos( This->mapped_center.x, This->mapped_center.y );
468 This->last_warped = GetCurrentTime();
470 This->need_warp = FALSE;
476 /******************************************************************************
477 * Unacquire : frees the mouse
479 static HRESULT WINAPI SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
481 SysMouseImpl *This = (SysMouseImpl *)iface;
484 TRACE("(this=%p)\n",This);
486 if ((res = IDirectInputDevice2AImpl_Unacquire(iface)) != DI_OK) return res;
488 if (This->base.dwCoopLevel & DISCL_EXCLUSIVE)
491 ShowCursor(TRUE); /* show cursor */
494 /* And put the mouse cursor back where it was at acquire time */
495 if (This->base.dwCoopLevel & DISCL_EXCLUSIVE || This->warp_override == WARP_FORCE_ON)
497 TRACE(" warping mouse back to (%d , %d)\n", This->org_coords.x, This->org_coords.y);
498 SetCursorPos(This->org_coords.x, This->org_coords.y);
504 /******************************************************************************
505 * GetDeviceState : returns the "state" of the mouse.
507 * For the moment, only the "standard" return structure (DIMOUSESTATE) is
510 static HRESULT WINAPI SysMouseAImpl_GetDeviceState(
511 LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
513 SysMouseImpl *This = (SysMouseImpl *)iface;
515 if(This->base.acquired == 0) return DIERR_NOTACQUIRED;
517 TRACE("(this=%p,0x%08x,%p):\n", This, len, ptr);
518 _dump_mouse_state(&This->m_state);
520 EnterCriticalSection(&This->base.crit);
521 /* Copy the current mouse state */
522 fill_DataFormat(ptr, len, &This->m_state, &This->base.data_format);
524 /* Initialize the buffer when in relative mode */
525 if (!(This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS))
527 This->m_state.lX = 0;
528 This->m_state.lY = 0;
529 This->m_state.lZ = 0;
531 LeaveCriticalSection(&This->base.crit);
533 /* Check if we need to do a mouse warping */
534 if (This->need_warp && (GetCurrentTime() - This->last_warped > 10))
536 if(!dinput_window_check(This))
537 return DIERR_GENERIC;
538 TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y);
539 SetCursorPos( This->mapped_center.x, This->mapped_center.y );
540 This->last_warped = GetCurrentTime();
542 This->need_warp = FALSE;
548 /******************************************************************************
549 * GetDeviceData : gets buffered input data.
551 static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
552 DWORD dodsize, LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
554 SysMouseImpl *This = (SysMouseImpl *)iface;
557 res = IDirectInputDevice2AImpl_GetDeviceData(iface, dodsize, dod, entries, flags);
558 if (FAILED(res)) return res;
560 /* Check if we need to do a mouse warping */
561 if (This->need_warp && (GetCurrentTime() - This->last_warped > 10))
563 if(!dinput_window_check(This))
564 return DIERR_GENERIC;
565 TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y);
566 SetCursorPos( This->mapped_center.x, This->mapped_center.y );
567 This->last_warped = GetCurrentTime();
569 This->need_warp = FALSE;
574 /******************************************************************************
575 * GetProperty : get input device properties
577 static HRESULT WINAPI SysMouseAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
579 LPDIPROPHEADER pdiph)
581 SysMouseImpl *This = (SysMouseImpl *)iface;
583 TRACE("(%p) %s,%p\n", This, debugstr_guid(rguid), pdiph);
584 _dump_DIPROPHEADER(pdiph);
586 if (!HIWORD(rguid)) {
587 switch (LOWORD(rguid)) {
588 case (DWORD) DIPROP_GRANULARITY: {
589 LPDIPROPDWORD pr = (LPDIPROPDWORD) pdiph;
591 /* We'll just assume that the app asks about the Z axis */
592 pr->dwData = WHEEL_DELTA;
597 case (DWORD) DIPROP_RANGE: {
598 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
600 if ((pdiph->dwHow == DIPH_BYID) &&
601 ((pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS)) ||
602 (pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS)))) {
603 /* Querying the range of either the X or the Y axis. As I do
604 not know the range, do as if the range were
606 pr->lMin = DIPROPRANGE_NOMIN;
607 pr->lMax = DIPROPRANGE_NOMAX;
614 return IDirectInputDevice2AImpl_GetProperty(iface, rguid, pdiph);
621 /******************************************************************************
622 * GetCapabilities : get the device capabilities
624 static HRESULT WINAPI SysMouseAImpl_GetCapabilities(
625 LPDIRECTINPUTDEVICE8A iface,
626 LPDIDEVCAPS lpDIDevCaps)
628 SysMouseImpl *This = (SysMouseImpl *)iface;
631 TRACE("(this=%p,%p)\n",This,lpDIDevCaps);
633 if ((lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) && (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS_DX3))) {
634 WARN("invalid parameter\n");
635 return DIERR_INVALIDPARAM;
638 devcaps.dwSize = lpDIDevCaps->dwSize;
639 devcaps.dwFlags = DIDC_ATTACHED;
640 if (This->base.dinput->dwVersion >= 0x0800)
641 devcaps.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
643 devcaps.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
645 devcaps.dwButtons = 8;
647 devcaps.dwFFSamplePeriod = 0;
648 devcaps.dwFFMinTimeResolution = 0;
649 devcaps.dwFirmwareRevision = 100;
650 devcaps.dwHardwareRevision = 100;
651 devcaps.dwFFDriverVersion = 0;
653 memcpy(lpDIDevCaps, &devcaps, lpDIDevCaps->dwSize);
658 /******************************************************************************
659 * GetObjectInfo : get information about a device object such as a button
662 static HRESULT WINAPI SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface,
663 LPDIDEVICEOBJECTINSTANCEW pdidoi, DWORD dwObj, DWORD dwHow)
665 static const WCHAR x_axisW[] = {'X','-','A','x','i','s',0};
666 static const WCHAR y_axisW[] = {'Y','-','A','x','i','s',0};
667 static const WCHAR wheelW[] = {'W','h','e','e','l',0};
668 static const WCHAR buttonW[] = {'B','u','t','t','o','n',' ','%','d',0};
671 res = IDirectInputDevice2WImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
672 if (res != DI_OK) return res;
674 if (IsEqualGUID(&pdidoi->guidType, &GUID_XAxis)) strcpyW(pdidoi->tszName, x_axisW);
675 else if (IsEqualGUID(&pdidoi->guidType, &GUID_YAxis)) strcpyW(pdidoi->tszName, y_axisW);
676 else if (IsEqualGUID(&pdidoi->guidType, &GUID_ZAxis)) strcpyW(pdidoi->tszName, wheelW);
677 else if (pdidoi->dwType & DIDFT_BUTTON)
678 wsprintfW(pdidoi->tszName, buttonW, DIDFT_GETINSTANCE(pdidoi->dwType) - 3);
680 _dump_OBJECTINSTANCEW(pdidoi);
684 static HRESULT WINAPI SysMouseAImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8A iface,
685 LPDIDEVICEOBJECTINSTANCEA pdidoi, DWORD dwObj, DWORD dwHow)
688 DIDEVICEOBJECTINSTANCEW didoiW;
689 DWORD dwSize = pdidoi->dwSize;
691 didoiW.dwSize = sizeof(didoiW);
692 res = SysMouseWImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W)iface, &didoiW, dwObj, dwHow);
693 if (res != DI_OK) return res;
695 memset(pdidoi, 0, pdidoi->dwSize);
696 memcpy(pdidoi, &didoiW, FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW, tszName));
697 pdidoi->dwSize = dwSize;
698 WideCharToMultiByte(CP_ACP, 0, didoiW.tszName, -1, pdidoi->tszName,
699 sizeof(pdidoi->tszName), NULL, NULL);
704 /******************************************************************************
705 * GetDeviceInfo : get information about a device's identity
707 static HRESULT WINAPI SysMouseAImpl_GetDeviceInfo(
708 LPDIRECTINPUTDEVICE8A iface,
709 LPDIDEVICEINSTANCEA pdidi)
711 SysMouseImpl *This = (SysMouseImpl *)iface;
712 TRACE("(this=%p,%p)\n", This, pdidi);
714 if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA)) {
715 WARN(" dinput3 not supporte yet...\n");
719 fill_mouse_dideviceinstanceA(pdidi, This->base.dinput->dwVersion);
724 static HRESULT WINAPI SysMouseWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW pdidi)
726 SysMouseImpl *This = (SysMouseImpl *)iface;
727 TRACE("(this=%p,%p)\n", This, pdidi);
729 if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)) {
730 WARN(" dinput3 not supporte yet...\n");
734 fill_mouse_dideviceinstanceW(pdidi, This->base.dinput->dwVersion);
740 static const IDirectInputDevice8AVtbl SysMouseAvt =
742 IDirectInputDevice2AImpl_QueryInterface,
743 IDirectInputDevice2AImpl_AddRef,
744 IDirectInputDevice2AImpl_Release,
745 SysMouseAImpl_GetCapabilities,
746 IDirectInputDevice2AImpl_EnumObjects,
747 SysMouseAImpl_GetProperty,
748 IDirectInputDevice2AImpl_SetProperty,
749 SysMouseAImpl_Acquire,
750 SysMouseAImpl_Unacquire,
751 SysMouseAImpl_GetDeviceState,
752 SysMouseAImpl_GetDeviceData,
753 IDirectInputDevice2AImpl_SetDataFormat,
754 IDirectInputDevice2AImpl_SetEventNotification,
755 IDirectInputDevice2AImpl_SetCooperativeLevel,
756 SysMouseAImpl_GetObjectInfo,
757 SysMouseAImpl_GetDeviceInfo,
758 IDirectInputDevice2AImpl_RunControlPanel,
759 IDirectInputDevice2AImpl_Initialize,
760 IDirectInputDevice2AImpl_CreateEffect,
761 IDirectInputDevice2AImpl_EnumEffects,
762 IDirectInputDevice2AImpl_GetEffectInfo,
763 IDirectInputDevice2AImpl_GetForceFeedbackState,
764 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
765 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
766 IDirectInputDevice2AImpl_Escape,
767 IDirectInputDevice2AImpl_Poll,
768 IDirectInputDevice2AImpl_SendDeviceData,
769 IDirectInputDevice7AImpl_EnumEffectsInFile,
770 IDirectInputDevice7AImpl_WriteEffectToFile,
771 IDirectInputDevice8AImpl_BuildActionMap,
772 IDirectInputDevice8AImpl_SetActionMap,
773 IDirectInputDevice8AImpl_GetImageInfo
776 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
777 # define XCAST(fun) (typeof(SysMouseWvt.fun))
779 # define XCAST(fun) (void*)
782 static const IDirectInputDevice8WVtbl SysMouseWvt =
784 IDirectInputDevice2WImpl_QueryInterface,
785 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
786 XCAST(Release)IDirectInputDevice2AImpl_Release,
787 XCAST(GetCapabilities)SysMouseAImpl_GetCapabilities,
788 IDirectInputDevice2WImpl_EnumObjects,
789 XCAST(GetProperty)SysMouseAImpl_GetProperty,
790 XCAST(SetProperty)IDirectInputDevice2AImpl_SetProperty,
791 XCAST(Acquire)SysMouseAImpl_Acquire,
792 XCAST(Unacquire)SysMouseAImpl_Unacquire,
793 XCAST(GetDeviceState)SysMouseAImpl_GetDeviceState,
794 XCAST(GetDeviceData)SysMouseAImpl_GetDeviceData,
795 XCAST(SetDataFormat)IDirectInputDevice2AImpl_SetDataFormat,
796 XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
797 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
798 SysMouseWImpl_GetObjectInfo,
799 SysMouseWImpl_GetDeviceInfo,
800 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
801 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
802 XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
803 IDirectInputDevice2WImpl_EnumEffects,
804 IDirectInputDevice2WImpl_GetEffectInfo,
805 XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
806 XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
807 XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
808 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
809 XCAST(Poll)IDirectInputDevice2AImpl_Poll,
810 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
811 IDirectInputDevice7WImpl_EnumEffectsInFile,
812 IDirectInputDevice7WImpl_WriteEffectToFile,
813 IDirectInputDevice8WImpl_BuildActionMap,
814 IDirectInputDevice8WImpl_SetActionMap,
815 IDirectInputDevice8WImpl_GetImageInfo