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"
35 #include "dinput_private.h"
36 #include "device_private.h"
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(dinput
);
42 /* Wine mouse driver object instances */
43 #define WINE_MOUSE_X_AXIS_INSTANCE 0
44 #define WINE_MOUSE_Y_AXIS_INSTANCE 1
45 #define WINE_MOUSE_Z_AXIS_INSTANCE 2
46 #define WINE_MOUSE_BUTTONS_INSTANCE 3
48 static const IDirectInputDevice8AVtbl SysMouseAvt
;
49 static const IDirectInputDevice8WVtbl SysMouseWvt
;
51 typedef struct SysMouseImpl SysMouseImpl
;
55 struct IDirectInputDevice2AImpl base
;
57 IDirectInputImpl
*dinput
;
60 /* These are used in case of relative -> absolute transitions */
63 DWORD win_centerX
, win_centerY
;
64 /* warping: whether we need to move mouse back to middle once we
65 * reach window borders (for e.g. shooters, "surface movement" games) */
69 /* This is for mouse reporting. */
70 DIMOUSESTATE2 m_state
;
73 /* FIXME: This is ugly and not thread safe :/ */
74 static IDirectInputDevice8A
* current_lock
= NULL
;
76 static const GUID DInput_Wine_Mouse_GUID
= { /* 9e573ed8-7734-11d2-8d4a-23903fb6bdf7 */
80 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
83 static void fill_mouse_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
) {
85 DIDEVICEINSTANCEA ddi
;
87 dwSize
= lpddi
->dwSize
;
89 TRACE("%d %p\n", dwSize
, lpddi
);
91 memset(lpddi
, 0, dwSize
);
92 memset(&ddi
, 0, sizeof(ddi
));
95 ddi
.guidInstance
= GUID_SysMouse
;/* DInput's GUID */
96 ddi
.guidProduct
= DInput_Wine_Mouse_GUID
; /* Vendor's GUID */
97 if (version
>= 0x0800)
98 ddi
.dwDevType
= DI8DEVTYPE_MOUSE
| (DI8DEVTYPEMOUSE_TRADITIONAL
<< 8);
100 ddi
.dwDevType
= DIDEVTYPE_MOUSE
| (DIDEVTYPEMOUSE_TRADITIONAL
<< 8);
101 strcpy(ddi
.tszInstanceName
, "Mouse");
102 strcpy(ddi
.tszProductName
, "Wine Mouse");
104 memcpy(lpddi
, &ddi
, (dwSize
< sizeof(ddi
) ? dwSize
: sizeof(ddi
)));
107 static void fill_mouse_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
) {
109 DIDEVICEINSTANCEW ddi
;
111 dwSize
= lpddi
->dwSize
;
113 TRACE("%d %p\n", dwSize
, lpddi
);
115 memset(lpddi
, 0, dwSize
);
116 memset(&ddi
, 0, sizeof(ddi
));
119 ddi
.guidInstance
= GUID_SysMouse
;/* DInput's GUID */
120 ddi
.guidProduct
= DInput_Wine_Mouse_GUID
; /* Vendor's GUID */
121 if (version
>= 0x0800)
122 ddi
.dwDevType
= DI8DEVTYPE_MOUSE
| (DI8DEVTYPEMOUSE_TRADITIONAL
<< 8);
124 ddi
.dwDevType
= DIDEVTYPE_MOUSE
| (DIDEVTYPEMOUSE_TRADITIONAL
<< 8);
125 MultiByteToWideChar(CP_ACP
, 0, "Mouse", -1, ddi
.tszInstanceName
, MAX_PATH
);
126 MultiByteToWideChar(CP_ACP
, 0, "Wine Mouse", -1, ddi
.tszProductName
, MAX_PATH
);
128 memcpy(lpddi
, &ddi
, (dwSize
< sizeof(ddi
) ? dwSize
: sizeof(ddi
)));
131 static BOOL
mousedev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
136 if ((dwDevType
== 0) ||
137 ((dwDevType
== DIDEVTYPE_MOUSE
) && (version
< 0x0800)) ||
138 (((dwDevType
== DI8DEVCLASS_POINTER
) || (dwDevType
== DI8DEVTYPE_MOUSE
)) && (version
>= 0x0800))) {
139 TRACE("Enumerating the mouse device\n");
141 fill_mouse_dideviceinstanceA(lpddi
, version
);
149 static BOOL
mousedev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
154 if ((dwDevType
== 0) ||
155 ((dwDevType
== DIDEVTYPE_MOUSE
) && (version
< 0x0800)) ||
156 (((dwDevType
== DI8DEVCLASS_POINTER
) || (dwDevType
== DI8DEVTYPE_MOUSE
)) && (version
>= 0x0800))) {
157 TRACE("Enumerating the mouse device\n");
159 fill_mouse_dideviceinstanceW(lpddi
, version
);
167 static SysMouseImpl
*alloc_device(REFGUID rguid
, const void *mvt
, IDirectInputImpl
*dinput
)
169 SysMouseImpl
* newDevice
;
170 LPDIDATAFORMAT df
= NULL
;
173 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(SysMouseImpl
));
174 if (!newDevice
) return NULL
;
175 newDevice
->base
.lpVtbl
= mvt
;
176 newDevice
->base
.ref
= 1;
177 newDevice
->base
.dwCoopLevel
= DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
;
178 memcpy(&newDevice
->base
.guid
, rguid
, sizeof(*rguid
));
179 InitializeCriticalSection(&newDevice
->base
.crit
);
180 newDevice
->base
.crit
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": SysMouseImpl*->base.crit");
181 newDevice
->dinput
= dinput
;
183 /* Create copy of default data format */
184 if (!(df
= HeapAlloc(GetProcessHeap(), 0, c_dfDIMouse2
.dwSize
))) goto failed
;
185 memcpy(df
, &c_dfDIMouse2
, c_dfDIMouse2
.dwSize
);
186 if (!(df
->rgodf
= HeapAlloc(GetProcessHeap(), 0, df
->dwNumObjs
* df
->dwObjSize
))) goto failed
;
187 memcpy(df
->rgodf
, c_dfDIMouse2
.rgodf
, df
->dwNumObjs
* df
->dwObjSize
);
189 /* Because we don't do any detection yet just modify instance and type */
190 for (i
= 0; i
< df
->dwNumObjs
; i
++)
191 if (DIDFT_GETTYPE(df
->rgodf
[i
].dwType
) & DIDFT_AXIS
)
192 df
->rgodf
[i
].dwType
= DIDFT_MAKEINSTANCE(i
) | DIDFT_RELAXIS
;
194 df
->rgodf
[i
].dwType
= DIDFT_MAKEINSTANCE(i
) | DIDFT_PSHBUTTON
;
196 newDevice
->base
.data_format
.wine_df
= df
;
197 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A
)newDevice
->dinput
);
201 if (df
) HeapFree(GetProcessHeap(), 0, df
->rgodf
);
202 HeapFree(GetProcessHeap(), 0, df
);
203 HeapFree(GetProcessHeap(), 0, newDevice
);
207 static HRESULT
mousedev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
209 if ((IsEqualGUID(&GUID_SysMouse
,rguid
)) || /* Generic Mouse */
210 (IsEqualGUID(&DInput_Wine_Mouse_GUID
,rguid
))) { /* Wine Mouse */
211 if ((riid
== NULL
) ||
212 IsEqualGUID(&IID_IDirectInputDeviceA
,riid
) ||
213 IsEqualGUID(&IID_IDirectInputDevice2A
,riid
) ||
214 IsEqualGUID(&IID_IDirectInputDevice7A
,riid
) ||
215 IsEqualGUID(&IID_IDirectInputDevice8A
,riid
)) {
216 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &SysMouseAvt
, dinput
);
217 TRACE("Creating a Mouse device (%p)\n", *pdev
);
218 if (!*pdev
) return DIERR_OUTOFMEMORY
;
221 return DIERR_NOINTERFACE
;
224 return DIERR_DEVICENOTREG
;
227 static HRESULT
mousedev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
229 if ((IsEqualGUID(&GUID_SysMouse
,rguid
)) || /* Generic Mouse */
230 (IsEqualGUID(&DInput_Wine_Mouse_GUID
,rguid
))) { /* Wine Mouse */
231 if ((riid
== NULL
) ||
232 IsEqualGUID(&IID_IDirectInputDeviceW
,riid
) ||
233 IsEqualGUID(&IID_IDirectInputDevice2W
,riid
) ||
234 IsEqualGUID(&IID_IDirectInputDevice7W
,riid
) ||
235 IsEqualGUID(&IID_IDirectInputDevice8W
,riid
)) {
236 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &SysMouseWvt
, dinput
);
237 TRACE("Creating a Mouse device (%p)\n", *pdev
);
238 if (!*pdev
) return DIERR_OUTOFMEMORY
;
241 return DIERR_NOINTERFACE
;
244 return DIERR_DEVICENOTREG
;
247 const struct dinput_device mouse_device
= {
249 mousedev_enum_deviceA
,
250 mousedev_enum_deviceW
,
251 mousedev_create_deviceA
,
252 mousedev_create_deviceW
255 /******************************************************************************
256 * SysMouseA (DInput Mouse support)
259 /******************************************************************************
260 * Release : release the mouse buffer.
262 static ULONG WINAPI
SysMouseAImpl_Release(LPDIRECTINPUTDEVICE8A iface
)
264 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
267 ref
= InterlockedDecrement(&This
->base
.ref
);
271 IDirectInputDevice_Unacquire(iface
);
273 /* Free the data queue */
274 HeapFree(GetProcessHeap(), 0, This
->base
.data_queue
);
276 /* Free data format */
277 HeapFree(GetProcessHeap(), 0, This
->base
.data_format
.wine_df
->rgodf
);
278 HeapFree(GetProcessHeap(), 0, This
->base
.data_format
.wine_df
);
279 release_DataFormat(&This
->base
.data_format
);
281 IDirectInput_Release((LPDIRECTINPUTDEVICE8A
)This
->dinput
);
282 This
->base
.crit
.DebugInfo
->Spare
[0] = 0;
283 DeleteCriticalSection(&This
->base
.crit
);
284 HeapFree(GetProcessHeap(),0,This
);
288 /* low-level mouse hook */
289 static LRESULT CALLBACK
dinput_mouse_hook( int code
, WPARAM wparam
, LPARAM lparam
)
291 MSLLHOOKSTRUCT
*hook
= (MSLLHOOKSTRUCT
*)lparam
;
292 SysMouseImpl
* This
= (SysMouseImpl
*) current_lock
;
294 int wdata
= 0, inst_id
= -1;
296 if (code
!= HC_ACTION
) return CallNextHookEx( 0, code
, wparam
, lparam
);
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
;
318 queue_event((LPDIRECTINPUTDEVICE8A
)This
, id_to_offset(&This
->base
.data_format
,
319 DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE
) | DIDFT_RELAXIS
),
320 pt1
.x
, hook
->time
, This
->dinput
->evsequence
);
323 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE
) | DIDFT_RELAXIS
;
327 This
->need_warp
= (pt
.x
|| pt
.y
) && dwCoop
& DISCL_EXCLUSIVE
;
331 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE
) | DIDFT_RELAXIS
;
332 This
->m_state
.lZ
+= wdata
= (short)HIWORD(hook
->mouseData
);
335 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 0) | DIDFT_PSHBUTTON
;
336 This
->m_state
.rgbButtons
[0] = wdata
= 0x80;
339 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 0) | DIDFT_PSHBUTTON
;
340 This
->m_state
.rgbButtons
[0] = wdata
= 0x00;
343 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 1) | DIDFT_PSHBUTTON
;
344 This
->m_state
.rgbButtons
[1] = wdata
= 0x80;
347 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 1) | DIDFT_PSHBUTTON
;
348 This
->m_state
.rgbButtons
[1] = wdata
= 0x00;
351 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 2) | DIDFT_PSHBUTTON
;
352 This
->m_state
.rgbButtons
[2] = wdata
= 0x80;
355 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 2) | DIDFT_PSHBUTTON
;
356 This
->m_state
.rgbButtons
[2] = wdata
= 0x00;
359 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 2 + HIWORD(hook
->mouseData
)) | DIDFT_PSHBUTTON
;
360 This
->m_state
.rgbButtons
[2 + HIWORD(hook
->mouseData
)] = wdata
= 0x80;
363 inst_id
= DIDFT_MAKEINSTANCE(WINE_MOUSE_BUTTONS_INSTANCE
+ 2 + HIWORD(hook
->mouseData
)) | DIDFT_PSHBUTTON
;
364 This
->m_state
.rgbButtons
[2 + HIWORD(hook
->mouseData
)] = wdata
= 0x00;
368 if (TRACE_ON(dinput
))
372 TRACE("msg %lx @ (%d %d): (X: %d Y: %d Z: %d", wparam
, hook
->pt
.x
, hook
->pt
.y
,
373 This
->m_state
.lX
, This
->m_state
.lY
, This
->m_state
.lZ
);
374 for (i
= 0; i
< 5; i
++) TRACE(" B%d: %02x", i
, This
->m_state
.rgbButtons
[i
]);
378 queue_event((LPDIRECTINPUTDEVICE8A
)This
, id_to_offset(&This
->base
.data_format
, inst_id
),
379 wdata
, hook
->time
, This
->dinput
->evsequence
++);
381 LeaveCriticalSection(&This
->base
.crit
);
384 if (dwCoop
& DISCL_EXCLUSIVE
) return 1;
386 /* Pass the events down to previous handlers (e.g. win32 input) */
387 return CallNextHookEx( 0, code
, wparam
, lparam
);
390 static BOOL
dinput_window_check(SysMouseImpl
* This
) {
392 DWORD centerX
, centerY
;
394 /* make sure the window hasn't moved */
395 if(!GetWindowRect(This
->base
.win
, &rect
))
397 centerX
= (rect
.right
- rect
.left
) / 2;
398 centerY
= (rect
.bottom
- rect
.top
) / 2;
399 if (This
->win_centerX
!= centerX
|| This
->win_centerY
!= centerY
) {
400 This
->win_centerX
= centerX
;
401 This
->win_centerY
= centerY
;
403 This
->mapped_center
.x
= This
->win_centerX
;
404 This
->mapped_center
.y
= This
->win_centerY
;
405 MapWindowPoints(This
->base
.win
, HWND_DESKTOP
, &This
->mapped_center
, 1);
410 /******************************************************************************
411 * Acquire : gets exclusive control of the mouse
413 static HRESULT WINAPI
SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
415 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
420 TRACE("(this=%p)\n",This
);
422 if ((res
= IDirectInputDevice2AImpl_Acquire(iface
)) != DI_OK
) return res
;
424 /* Store (in a global variable) the current lock */
425 current_lock
= (IDirectInputDevice8A
*)This
;
427 /* Init the mouse state */
428 GetCursorPos( &point
);
429 if (This
->base
.data_format
.user_df
->dwFlags
& DIDF_ABSAXIS
)
431 This
->m_state
.lX
= point
.x
;
432 This
->m_state
.lY
= point
.y
;
434 This
->m_state
.lX
= 0;
435 This
->m_state
.lY
= 0;
436 This
->org_coords
= point
;
438 This
->m_state
.lZ
= 0;
439 This
->m_state
.rgbButtons
[0] = GetKeyState(VK_LBUTTON
) & 0x80;
440 This
->m_state
.rgbButtons
[1] = GetKeyState(VK_RBUTTON
) & 0x80;
441 This
->m_state
.rgbButtons
[2] = GetKeyState(VK_MBUTTON
) & 0x80;
443 /* Install our mouse hook */
444 if (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
)
445 ShowCursor(FALSE
); /* hide cursor */
446 set_dinput_hook(WH_MOUSE_LL
, dinput_mouse_hook
);
448 /* Get the window dimension and find the center */
449 GetWindowRect(This
->base
.win
, &rect
);
450 This
->win_centerX
= (rect
.right
- rect
.left
) / 2;
451 This
->win_centerY
= (rect
.bottom
- rect
.top
) / 2;
453 /* Warp the mouse to the center of the window */
454 if (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
)
456 This
->mapped_center
.x
= This
->win_centerX
;
457 This
->mapped_center
.y
= This
->win_centerY
;
458 MapWindowPoints(This
->base
.win
, HWND_DESKTOP
, &This
->mapped_center
, 1);
459 TRACE("Warping mouse to %d - %d\n", This
->mapped_center
.x
, This
->mapped_center
.y
);
460 SetCursorPos( This
->mapped_center
.x
, This
->mapped_center
.y
);
461 This
->last_warped
= GetCurrentTime();
463 This
->need_warp
= FALSE
;
469 /******************************************************************************
470 * Unacquire : frees the mouse
472 static HRESULT WINAPI
SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
474 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
477 TRACE("(this=%p)\n",This
);
479 if ((res
= IDirectInputDevice2AImpl_Unacquire(iface
)) != DI_OK
) return res
;
481 set_dinput_hook(WH_MOUSE_LL
, NULL
);
482 if (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
)
483 ShowCursor(TRUE
); /* show cursor */
486 if (current_lock
== (IDirectInputDevice8A
*) This
)
489 ERR("this(%p) != current_lock(%p)\n", This
, current_lock
);
491 /* And put the mouse cursor back where it was at acquire time */
492 if (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
)
494 TRACE(" warping mouse back to (%d , %d)\n", This
->org_coords
.x
, This
->org_coords
.y
);
495 SetCursorPos(This
->org_coords
.x
, This
->org_coords
.y
);
501 /******************************************************************************
502 * GetDeviceState : returns the "state" of the mouse.
504 * For the moment, only the "standard" return structure (DIMOUSESTATE) is
507 static HRESULT WINAPI
SysMouseAImpl_GetDeviceState(
508 LPDIRECTINPUTDEVICE8A iface
,DWORD len
,LPVOID ptr
510 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
512 if(This
->base
.acquired
== 0) return DIERR_NOTACQUIRED
;
514 TRACE("(this=%p,0x%08x,%p):\n", This
, len
, ptr
);
515 TRACE("(X: %d - Y: %d - Z: %d L: %02x M: %02x R: %02x)\n",
516 This
->m_state
.lX
, This
->m_state
.lY
, This
->m_state
.lZ
,
517 This
->m_state
.rgbButtons
[0], This
->m_state
.rgbButtons
[2], This
->m_state
.rgbButtons
[1]);
519 EnterCriticalSection(&This
->base
.crit
);
520 /* Copy the current mouse state */
521 fill_DataFormat(ptr
, &(This
->m_state
), &This
->base
.data_format
);
523 /* Initialize the buffer when in relative mode */
524 if (!(This
->base
.data_format
.user_df
->dwFlags
& DIDF_ABSAXIS
))
526 This
->m_state
.lX
= 0;
527 This
->m_state
.lY
= 0;
528 This
->m_state
.lZ
= 0;
530 LeaveCriticalSection(&This
->base
.crit
);
532 /* Check if we need to do a mouse warping */
533 if (This
->need_warp
&& (GetCurrentTime() - This
->last_warped
> 10))
535 if(!dinput_window_check(This
))
536 return DIERR_GENERIC
;
537 TRACE("Warping mouse to %d - %d\n", This
->mapped_center
.x
, This
->mapped_center
.y
);
538 SetCursorPos( This
->mapped_center
.x
, This
->mapped_center
.y
);
539 This
->last_warped
= GetCurrentTime();
541 This
->need_warp
= FALSE
;
547 /******************************************************************************
548 * GetDeviceData : gets buffered input data.
550 static HRESULT WINAPI
SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface
,
551 DWORD dodsize
, LPDIDEVICEOBJECTDATA dod
, LPDWORD entries
, DWORD flags
)
553 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
556 res
= IDirectInputDevice2AImpl_GetDeviceData(iface
, dodsize
, dod
, entries
, flags
);
557 if (FAILED(res
)) return res
;
559 /* Check if we need to do a mouse warping */
560 if (This
->need_warp
&& (GetCurrentTime() - This
->last_warped
> 10))
562 if(!dinput_window_check(This
))
563 return DIERR_GENERIC
;
564 TRACE("Warping mouse to %d - %d\n", This
->mapped_center
.x
, This
->mapped_center
.y
);
565 SetCursorPos( This
->mapped_center
.x
, This
->mapped_center
.y
);
566 This
->last_warped
= GetCurrentTime();
568 This
->need_warp
= FALSE
;
573 /******************************************************************************
574 * GetProperty : get input device properties
576 static HRESULT WINAPI
SysMouseAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
578 LPDIPROPHEADER pdiph
)
580 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
582 TRACE("(%p) %s,%p\n", This
, debugstr_guid(rguid
), pdiph
);
583 _dump_DIPROPHEADER(pdiph
);
585 if (!HIWORD(rguid
)) {
586 switch (LOWORD(rguid
)) {
587 case (DWORD
) DIPROP_GRANULARITY
: {
588 LPDIPROPDWORD pr
= (LPDIPROPDWORD
) pdiph
;
590 /* We'll just assume that the app asks about the Z axis */
591 pr
->dwData
= WHEEL_DELTA
;
596 case (DWORD
) DIPROP_RANGE
: {
597 LPDIPROPRANGE pr
= (LPDIPROPRANGE
) pdiph
;
599 if ((pdiph
->dwHow
== DIPH_BYID
) &&
600 ((pdiph
->dwObj
== (DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE
) | DIDFT_RELAXIS
)) ||
601 (pdiph
->dwObj
== (DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE
) | DIDFT_RELAXIS
)))) {
602 /* Querying the range of either the X or the Y axis. As I do
603 not know the range, do as if the range were
605 pr
->lMin
= DIPROPRANGE_NOMIN
;
606 pr
->lMax
= DIPROPRANGE_NOMAX
;
613 return IDirectInputDevice2AImpl_GetProperty(iface
, rguid
, pdiph
);
620 /******************************************************************************
621 * GetCapabilities : get the device capablitites
623 static HRESULT WINAPI
SysMouseAImpl_GetCapabilities(
624 LPDIRECTINPUTDEVICE8A iface
,
625 LPDIDEVCAPS lpDIDevCaps
)
627 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
630 TRACE("(this=%p,%p)\n",This
,lpDIDevCaps
);
632 if ((lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS
)) && (lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS_DX3
))) {
633 WARN("invalid parameter\n");
634 return DIERR_INVALIDPARAM
;
637 devcaps
.dwSize
= lpDIDevCaps
->dwSize
;
638 devcaps
.dwFlags
= DIDC_ATTACHED
;
639 if (This
->dinput
->dwVersion
>= 0x0800)
640 devcaps
.dwDevType
= DI8DEVTYPE_MOUSE
| (DI8DEVTYPEMOUSE_TRADITIONAL
<< 8);
642 devcaps
.dwDevType
= DIDEVTYPE_MOUSE
| (DIDEVTYPEMOUSE_TRADITIONAL
<< 8);
644 devcaps
.dwButtons
= 8;
646 devcaps
.dwFFSamplePeriod
= 0;
647 devcaps
.dwFFMinTimeResolution
= 0;
648 devcaps
.dwFirmwareRevision
= 100;
649 devcaps
.dwHardwareRevision
= 100;
650 devcaps
.dwFFDriverVersion
= 0;
652 memcpy(lpDIDevCaps
, &devcaps
, lpDIDevCaps
->dwSize
);
657 /******************************************************************************
658 * GetObjectInfo : get information about a device object such as a button
661 static HRESULT WINAPI
SysMouseWImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8W iface
,
662 LPDIDEVICEOBJECTINSTANCEW pdidoi
, DWORD dwObj
, DWORD dwHow
)
664 static const WCHAR x_axisW
[] = {'X','-','A','x','i','s',0};
665 static const WCHAR y_axisW
[] = {'Y','-','A','x','i','s',0};
666 static const WCHAR wheelW
[] = {'W','h','e','e','l',0};
667 static const WCHAR buttonW
[] = {'B','u','t','t','o','n',' ','%','d',0};
670 res
= IDirectInputDevice2WImpl_GetObjectInfo(iface
, pdidoi
, dwObj
, dwHow
);
671 if (res
!= DI_OK
) return res
;
673 if (IsEqualGUID(&pdidoi
->guidType
, &GUID_XAxis
)) strcpyW(pdidoi
->tszName
, x_axisW
);
674 else if (IsEqualGUID(&pdidoi
->guidType
, &GUID_YAxis
)) strcpyW(pdidoi
->tszName
, y_axisW
);
675 else if (IsEqualGUID(&pdidoi
->guidType
, &GUID_ZAxis
)) strcpyW(pdidoi
->tszName
, wheelW
);
676 else if (pdidoi
->dwType
& DIDFT_BUTTON
)
677 wsprintfW(pdidoi
->tszName
, buttonW
, DIDFT_GETINSTANCE(pdidoi
->dwType
) - 3);
679 _dump_OBJECTINSTANCEW(pdidoi
);
683 static HRESULT WINAPI
SysMouseAImpl_GetObjectInfo(LPDIRECTINPUTDEVICE8A iface
,
684 LPDIDEVICEOBJECTINSTANCEA pdidoi
, DWORD dwObj
, DWORD dwHow
)
687 DIDEVICEOBJECTINSTANCEW didoiW
;
688 DWORD dwSize
= pdidoi
->dwSize
;
690 didoiW
.dwSize
= sizeof(didoiW
);
691 res
= SysMouseWImpl_GetObjectInfo((LPDIRECTINPUTDEVICE8W
)iface
, &didoiW
, dwObj
, dwHow
);
692 if (res
!= DI_OK
) return res
;
694 memset(pdidoi
, 0, pdidoi
->dwSize
);
695 memcpy(pdidoi
, &didoiW
, FIELD_OFFSET(DIDEVICEOBJECTINSTANCEW
, tszName
));
696 pdidoi
->dwSize
= dwSize
;
697 WideCharToMultiByte(CP_ACP
, 0, didoiW
.tszName
, -1, pdidoi
->tszName
,
698 sizeof(pdidoi
->tszName
), NULL
, NULL
);
703 /******************************************************************************
704 * GetDeviceInfo : get information about a device's identity
706 static HRESULT WINAPI
SysMouseAImpl_GetDeviceInfo(
707 LPDIRECTINPUTDEVICE8A iface
,
708 LPDIDEVICEINSTANCEA pdidi
)
710 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
711 TRACE("(this=%p,%p)\n", This
, pdidi
);
713 if (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)) {
714 WARN(" dinput3 not supporte yet...\n");
718 fill_mouse_dideviceinstanceA(pdidi
, This
->dinput
->dwVersion
);
723 static HRESULT WINAPI
SysMouseWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
, LPDIDEVICEINSTANCEW pdidi
)
725 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
726 TRACE("(this=%p,%p)\n", This
, pdidi
);
728 if (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)) {
729 WARN(" dinput3 not supporte yet...\n");
733 fill_mouse_dideviceinstanceW(pdidi
, This
->dinput
->dwVersion
);
739 static const IDirectInputDevice8AVtbl SysMouseAvt
=
741 IDirectInputDevice2AImpl_QueryInterface
,
742 IDirectInputDevice2AImpl_AddRef
,
743 SysMouseAImpl_Release
,
744 SysMouseAImpl_GetCapabilities
,
745 IDirectInputDevice2AImpl_EnumObjects
,
746 SysMouseAImpl_GetProperty
,
747 IDirectInputDevice2AImpl_SetProperty
,
748 SysMouseAImpl_Acquire
,
749 SysMouseAImpl_Unacquire
,
750 SysMouseAImpl_GetDeviceState
,
751 SysMouseAImpl_GetDeviceData
,
752 IDirectInputDevice2AImpl_SetDataFormat
,
753 IDirectInputDevice2AImpl_SetEventNotification
,
754 IDirectInputDevice2AImpl_SetCooperativeLevel
,
755 SysMouseAImpl_GetObjectInfo
,
756 SysMouseAImpl_GetDeviceInfo
,
757 IDirectInputDevice2AImpl_RunControlPanel
,
758 IDirectInputDevice2AImpl_Initialize
,
759 IDirectInputDevice2AImpl_CreateEffect
,
760 IDirectInputDevice2AImpl_EnumEffects
,
761 IDirectInputDevice2AImpl_GetEffectInfo
,
762 IDirectInputDevice2AImpl_GetForceFeedbackState
,
763 IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
764 IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
765 IDirectInputDevice2AImpl_Escape
,
766 IDirectInputDevice2AImpl_Poll
,
767 IDirectInputDevice2AImpl_SendDeviceData
,
768 IDirectInputDevice7AImpl_EnumEffectsInFile
,
769 IDirectInputDevice7AImpl_WriteEffectToFile
,
770 IDirectInputDevice8AImpl_BuildActionMap
,
771 IDirectInputDevice8AImpl_SetActionMap
,
772 IDirectInputDevice8AImpl_GetImageInfo
775 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
776 # define XCAST(fun) (typeof(SysMouseWvt.fun))
778 # define XCAST(fun) (void*)
781 static const IDirectInputDevice8WVtbl SysMouseWvt
=
783 IDirectInputDevice2WImpl_QueryInterface
,
784 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
785 XCAST(Release
)SysMouseAImpl_Release
,
786 XCAST(GetCapabilities
)SysMouseAImpl_GetCapabilities
,
787 IDirectInputDevice2WImpl_EnumObjects
,
788 XCAST(GetProperty
)SysMouseAImpl_GetProperty
,
789 XCAST(SetProperty
)IDirectInputDevice2AImpl_SetProperty
,
790 XCAST(Acquire
)SysMouseAImpl_Acquire
,
791 XCAST(Unacquire
)SysMouseAImpl_Unacquire
,
792 XCAST(GetDeviceState
)SysMouseAImpl_GetDeviceState
,
793 XCAST(GetDeviceData
)SysMouseAImpl_GetDeviceData
,
794 XCAST(SetDataFormat
)IDirectInputDevice2AImpl_SetDataFormat
,
795 XCAST(SetEventNotification
)IDirectInputDevice2AImpl_SetEventNotification
,
796 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
797 SysMouseWImpl_GetObjectInfo
,
798 SysMouseWImpl_GetDeviceInfo
,
799 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
800 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
801 XCAST(CreateEffect
)IDirectInputDevice2AImpl_CreateEffect
,
802 IDirectInputDevice2WImpl_EnumEffects
,
803 IDirectInputDevice2WImpl_GetEffectInfo
,
804 XCAST(GetForceFeedbackState
)IDirectInputDevice2AImpl_GetForceFeedbackState
,
805 XCAST(SendForceFeedbackCommand
)IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
806 XCAST(EnumCreatedEffectObjects
)IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
807 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
808 XCAST(Poll
)IDirectInputDevice2AImpl_Poll
,
809 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
810 IDirectInputDevice7WImpl_EnumEffectsInFile
,
811 IDirectInputDevice7WImpl_WriteEffectToFile
,
812 IDirectInputDevice8WImpl_BuildActionMap
,
813 IDirectInputDevice8WImpl_SetActionMap
,
814 IDirectInputDevice8WImpl_GetImageInfo