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"
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_L_BUTTON_INSTANCE 0
49 #define WINE_MOUSE_R_BUTTON_INSTANCE 1
50 #define WINE_MOUSE_M_BUTTON_INSTANCE 2
51 #define WINE_MOUSE_D_BUTTON_INSTANCE 3
53 /* ------------------------------- */
54 /* Wine mouse internal data format */
55 /* ------------------------------- */
57 /* Constants used to access the offset array */
58 #define WINE_MOUSE_X_POSITION 0
59 #define WINE_MOUSE_Y_POSITION 1
60 #define WINE_MOUSE_Z_POSITION 2
61 #define WINE_MOUSE_L_POSITION 3
62 #define WINE_MOUSE_R_POSITION 4
63 #define WINE_MOUSE_M_POSITION 5
65 static const IDirectInputDevice8AVtbl SysMouseAvt
;
66 static const IDirectInputDevice8WVtbl SysMouseWvt
;
68 typedef struct SysMouseImpl SysMouseImpl
;
71 WARP_DONE
, /* Warping has been done */
72 WARP_NEEDED
, /* Warping is needed */
73 WARP_STARTED
/* Warping has been done, waiting for the warp event */
78 struct IDirectInputDevice2AImpl base
;
80 IDirectInputImpl
*dinput
;
83 /* Previous position for relative moves */
85 /* These are used in case of relative -> absolute transitions */
88 DWORD win_centerX
, win_centerY
;
89 /* warping: whether we need to move mouse back to middle once we
90 * reach window borders (for e.g. shooters, "surface movement" games) */
91 WARP_STATUS need_warp
;
94 /* This is for mouse reporting. */
95 DIMOUSESTATE2 m_state
;
98 /* FIXME: This is ugly and not thread safe :/ */
99 static IDirectInputDevice8A
* current_lock
= NULL
;
101 static GUID DInput_Wine_Mouse_GUID
= { /* 9e573ed8-7734-11d2-8d4a-23903fb6bdf7 */
105 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
108 static void fill_mouse_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi
, DWORD version
) {
110 DIDEVICEINSTANCEA ddi
;
112 dwSize
= lpddi
->dwSize
;
114 TRACE("%d %p\n", dwSize
, lpddi
);
116 memset(lpddi
, 0, dwSize
);
117 memset(&ddi
, 0, sizeof(ddi
));
120 ddi
.guidInstance
= GUID_SysMouse
;/* DInput's GUID */
121 ddi
.guidProduct
= DInput_Wine_Mouse_GUID
; /* Vendor's GUID */
122 if (version
>= 0x0800)
123 ddi
.dwDevType
= DI8DEVTYPE_MOUSE
| (DI8DEVTYPEMOUSE_TRADITIONAL
<< 8);
125 ddi
.dwDevType
= DIDEVTYPE_MOUSE
| (DIDEVTYPEMOUSE_TRADITIONAL
<< 8);
126 strcpy(ddi
.tszInstanceName
, "Mouse");
127 strcpy(ddi
.tszProductName
, "Wine Mouse");
129 memcpy(lpddi
, &ddi
, (dwSize
< sizeof(ddi
) ? dwSize
: sizeof(ddi
)));
132 static void fill_mouse_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi
, DWORD version
) {
134 DIDEVICEINSTANCEW ddi
;
136 dwSize
= lpddi
->dwSize
;
138 TRACE("%d %p\n", dwSize
, lpddi
);
140 memset(lpddi
, 0, dwSize
);
141 memset(&ddi
, 0, sizeof(ddi
));
144 ddi
.guidInstance
= GUID_SysMouse
;/* DInput's GUID */
145 ddi
.guidProduct
= DInput_Wine_Mouse_GUID
; /* Vendor's GUID */
146 if (version
>= 0x0800)
147 ddi
.dwDevType
= DI8DEVTYPE_MOUSE
| (DI8DEVTYPEMOUSE_TRADITIONAL
<< 8);
149 ddi
.dwDevType
= DIDEVTYPE_MOUSE
| (DIDEVTYPEMOUSE_TRADITIONAL
<< 8);
150 MultiByteToWideChar(CP_ACP
, 0, "Mouse", -1, ddi
.tszInstanceName
, MAX_PATH
);
151 MultiByteToWideChar(CP_ACP
, 0, "Wine Mouse", -1, ddi
.tszProductName
, MAX_PATH
);
153 memcpy(lpddi
, &ddi
, (dwSize
< sizeof(ddi
) ? dwSize
: sizeof(ddi
)));
156 static BOOL
mousedev_enum_deviceA(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEA lpddi
, DWORD version
, int id
)
161 if ((dwDevType
== 0) ||
162 ((dwDevType
== DIDEVTYPE_MOUSE
) && (version
< 0x0800)) ||
163 (((dwDevType
== DI8DEVCLASS_POINTER
) || (dwDevType
== DI8DEVTYPE_MOUSE
)) && (version
>= 0x0800))) {
164 TRACE("Enumerating the mouse device\n");
166 fill_mouse_dideviceinstanceA(lpddi
, version
);
174 static BOOL
mousedev_enum_deviceW(DWORD dwDevType
, DWORD dwFlags
, LPDIDEVICEINSTANCEW lpddi
, DWORD version
, int id
)
179 if ((dwDevType
== 0) ||
180 ((dwDevType
== DIDEVTYPE_MOUSE
) && (version
< 0x0800)) ||
181 (((dwDevType
== DI8DEVCLASS_POINTER
) || (dwDevType
== DI8DEVTYPE_MOUSE
)) && (version
>= 0x0800))) {
182 TRACE("Enumerating the mouse device\n");
184 fill_mouse_dideviceinstanceW(lpddi
, version
);
192 static SysMouseImpl
*alloc_device(REFGUID rguid
, const void *mvt
, IDirectInputImpl
*dinput
)
194 SysMouseImpl
* newDevice
;
196 newDevice
= HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY
,sizeof(SysMouseImpl
));
197 if (!newDevice
) return NULL
;
198 newDevice
->base
.lpVtbl
= mvt
;
199 newDevice
->base
.ref
= 1;
200 newDevice
->base
.dwCoopLevel
= DISCL_NONEXCLUSIVE
| DISCL_BACKGROUND
;
201 memcpy(&newDevice
->base
.guid
, rguid
, sizeof(*rguid
));
202 InitializeCriticalSection(&newDevice
->base
.crit
);
203 newDevice
->dinput
= dinput
;
205 newDevice
->base
.data_format
.wine_df
= &c_dfDIMouse2
;
206 if (create_DataFormat(&c_dfDIMouse2
, &newDevice
->base
.data_format
) == DI_OK
)
212 static HRESULT
mousedev_create_deviceA(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEA
* pdev
)
214 if ((IsEqualGUID(&GUID_SysMouse
,rguid
)) || /* Generic Mouse */
215 (IsEqualGUID(&DInput_Wine_Mouse_GUID
,rguid
))) { /* Wine Mouse */
216 if ((riid
== NULL
) ||
217 IsEqualGUID(&IID_IDirectInputDeviceA
,riid
) ||
218 IsEqualGUID(&IID_IDirectInputDevice2A
,riid
) ||
219 IsEqualGUID(&IID_IDirectInputDevice7A
,riid
) ||
220 IsEqualGUID(&IID_IDirectInputDevice8A
,riid
)) {
221 *pdev
= (IDirectInputDeviceA
*) alloc_device(rguid
, &SysMouseAvt
, dinput
);
222 TRACE("Creating a Mouse device (%p)\n", *pdev
);
223 if (!*pdev
) return DIERR_OUTOFMEMORY
;
226 return DIERR_NOINTERFACE
;
229 return DIERR_DEVICENOTREG
;
232 static HRESULT
mousedev_create_deviceW(IDirectInputImpl
*dinput
, REFGUID rguid
, REFIID riid
, LPDIRECTINPUTDEVICEW
* pdev
)
234 if ((IsEqualGUID(&GUID_SysMouse
,rguid
)) || /* Generic Mouse */
235 (IsEqualGUID(&DInput_Wine_Mouse_GUID
,rguid
))) { /* Wine Mouse */
236 if ((riid
== NULL
) ||
237 IsEqualGUID(&IID_IDirectInputDeviceW
,riid
) ||
238 IsEqualGUID(&IID_IDirectInputDevice2W
,riid
) ||
239 IsEqualGUID(&IID_IDirectInputDevice7W
,riid
) ||
240 IsEqualGUID(&IID_IDirectInputDevice8W
,riid
)) {
241 *pdev
= (IDirectInputDeviceW
*) alloc_device(rguid
, &SysMouseWvt
, dinput
);
242 TRACE("Creating a Mouse device (%p)\n", *pdev
);
243 if (!*pdev
) return DIERR_OUTOFMEMORY
;
246 return DIERR_NOINTERFACE
;
249 return DIERR_DEVICENOTREG
;
252 const struct dinput_device mouse_device
= {
254 mousedev_enum_deviceA
,
255 mousedev_enum_deviceW
,
256 mousedev_create_deviceA
,
257 mousedev_create_deviceW
260 /******************************************************************************
261 * SysMouseA (DInput Mouse support)
264 /******************************************************************************
265 * Release : release the mouse buffer.
267 static ULONG WINAPI
SysMouseAImpl_Release(LPDIRECTINPUTDEVICE8A iface
)
269 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
272 ref
= InterlockedDecrement(&This
->base
.ref
);
276 set_dinput_hook(WH_MOUSE_LL
, NULL
);
278 /* Free the data queue */
279 HeapFree(GetProcessHeap(), 0, This
->base
.data_queue
);
281 release_DataFormat(&This
->base
.data_format
);
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
;
296 if (code
!= HC_ACTION
) return CallNextHookEx( 0, code
, wparam
, lparam
);
298 EnterCriticalSection(&This
->base
.crit
);
299 dwCoop
= This
->base
.dwCoopLevel
;
301 if (wparam
== WM_MOUSEMOVE
) {
302 if (This
->base
.data_format
.user_df
->dwFlags
& DIDF_ABSAXIS
) {
303 if (hook
->pt
.x
!= This
->prevX
)
304 queue_event((LPDIRECTINPUTDEVICE8A
)This
, This
->base
.data_format
.offsets
[WINE_MOUSE_X_POSITION
],
305 hook
->pt
.x
, hook
->time
, This
->dinput
->evsequence
);
306 if (hook
->pt
.y
!= This
->prevY
)
307 queue_event((LPDIRECTINPUTDEVICE8A
)This
, This
->base
.data_format
.offsets
[WINE_MOUSE_Y_POSITION
],
308 hook
->pt
.y
, hook
->time
, This
->dinput
->evsequence
);
310 /* Now, warp handling */
311 if ((This
->need_warp
== WARP_STARTED
) &&
312 (hook
->pt
.x
== This
->mapped_center
.x
) && (hook
->pt
.y
== This
->mapped_center
.y
)) {
313 /* Warp has been done... */
314 This
->need_warp
= WARP_DONE
;
318 /* Relative mouse input with absolute mouse event : the real fun starts here... */
319 if ((This
->need_warp
== WARP_NEEDED
) ||
320 (This
->need_warp
== WARP_STARTED
)) {
321 if (hook
->pt
.x
!= This
->prevX
)
322 queue_event((LPDIRECTINPUTDEVICE8A
)This
, This
->base
.data_format
.offsets
[WINE_MOUSE_X_POSITION
],
323 hook
->pt
.x
- This
->prevX
, hook
->time
, This
->dinput
->evsequence
);
324 if (hook
->pt
.y
!= This
->prevY
)
325 queue_event((LPDIRECTINPUTDEVICE8A
)This
, This
->base
.data_format
.offsets
[WINE_MOUSE_Y_POSITION
],
326 hook
->pt
.y
- This
->prevY
, hook
->time
, This
->dinput
->evsequence
);
328 /* This is the first time the event handler has been called after a
329 GetDeviceData or GetDeviceState. */
330 if (hook
->pt
.x
!= This
->mapped_center
.x
) {
331 queue_event((LPDIRECTINPUTDEVICE8A
)This
, This
->base
.data_format
.offsets
[WINE_MOUSE_X_POSITION
],
332 hook
->pt
.x
- This
->mapped_center
.x
, hook
->time
, This
->dinput
->evsequence
);
333 This
->need_warp
= WARP_NEEDED
;
336 if (hook
->pt
.y
!= This
->mapped_center
.y
) {
337 queue_event((LPDIRECTINPUTDEVICE8A
)This
, This
->base
.data_format
.offsets
[WINE_MOUSE_Y_POSITION
],
338 hook
->pt
.y
- This
->mapped_center
.y
, hook
->time
, This
->dinput
->evsequence
);
339 This
->need_warp
= WARP_NEEDED
;
344 This
->prevX
= hook
->pt
.x
;
345 This
->prevY
= hook
->pt
.y
;
347 if (This
->base
.data_format
.user_df
->dwFlags
& DIDF_ABSAXIS
) {
348 This
->m_state
.lX
= hook
->pt
.x
;
349 This
->m_state
.lY
= hook
->pt
.y
;
351 This
->m_state
.lX
= hook
->pt
.x
- This
->mapped_center
.x
;
352 This
->m_state
.lY
= hook
->pt
.y
- This
->mapped_center
.y
;
356 TRACE(" msg %x pt %d %d (W=%d)\n",
357 wparam
, hook
->pt
.x
, hook
->pt
.y
, !(This
->base
.data_format
.user_df
->dwFlags
& DIDF_ABSAXIS
) && This
->need_warp
);
361 queue_event((LPDIRECTINPUTDEVICE8A
)This
, This
->base
.data_format
.offsets
[WINE_MOUSE_L_POSITION
],
362 0x80, hook
->time
, This
->dinput
->evsequence
);
363 This
->m_state
.rgbButtons
[0] = 0x80;
366 queue_event((LPDIRECTINPUTDEVICE8A
)This
, This
->base
.data_format
.offsets
[WINE_MOUSE_L_POSITION
],
367 0x00, hook
->time
, This
->dinput
->evsequence
);
368 This
->m_state
.rgbButtons
[0] = 0x00;
371 queue_event((LPDIRECTINPUTDEVICE8A
)This
, This
->base
.data_format
.offsets
[WINE_MOUSE_R_POSITION
],
372 0x80, hook
->time
, This
->dinput
->evsequence
);
373 This
->m_state
.rgbButtons
[1] = 0x80;
376 queue_event((LPDIRECTINPUTDEVICE8A
)This
, This
->base
.data_format
.offsets
[WINE_MOUSE_R_POSITION
],
377 0x00, hook
->time
, This
->dinput
->evsequence
);
378 This
->m_state
.rgbButtons
[1] = 0x00;
381 queue_event((LPDIRECTINPUTDEVICE8A
)This
, This
->base
.data_format
.offsets
[WINE_MOUSE_M_POSITION
],
382 0x80, hook
->time
, This
->dinput
->evsequence
);
383 This
->m_state
.rgbButtons
[2] = 0x80;
386 queue_event((LPDIRECTINPUTDEVICE8A
)This
, This
->base
.data_format
.offsets
[WINE_MOUSE_M_POSITION
],
387 0x00, hook
->time
, This
->dinput
->evsequence
);
388 This
->m_state
.rgbButtons
[2] = 0x00;
391 wdata
= (short)HIWORD(hook
->mouseData
);
392 queue_event((LPDIRECTINPUTDEVICE8A
)This
, This
->base
.data_format
.offsets
[WINE_MOUSE_Z_POSITION
],
393 wdata
, hook
->time
, This
->dinput
->evsequence
);
394 This
->m_state
.lZ
+= wdata
;
398 TRACE("(X: %d - Y: %d L: %02x M: %02x R: %02x)\n",
399 This
->m_state
.lX
, This
->m_state
.lY
,
400 This
->m_state
.rgbButtons
[0], This
->m_state
.rgbButtons
[2], This
->m_state
.rgbButtons
[1]);
402 This
->dinput
->evsequence
++;
405 /* Mouse moved -> send event if asked */
406 if (This
->base
.hEvent
) SetEvent(This
->base
.hEvent
);
408 LeaveCriticalSection(&This
->base
.crit
);
411 if (dwCoop
& DISCL_EXCLUSIVE
) return 1;
413 /* Pass the events down to previous handlers (e.g. win32 input) */
414 return CallNextHookEx( 0, code
, wparam
, lparam
);
417 static BOOL
dinput_window_check(SysMouseImpl
* This
) {
419 DWORD centerX
, centerY
;
421 /* make sure the window hasn't moved */
422 if(!GetWindowRect(This
->base
.win
, &rect
))
424 centerX
= (rect
.right
- rect
.left
) / 2;
425 centerY
= (rect
.bottom
- rect
.top
) / 2;
426 if (This
->win_centerX
!= centerX
|| This
->win_centerY
!= centerY
) {
427 This
->win_centerX
= centerX
;
428 This
->win_centerY
= centerY
;
430 This
->mapped_center
.x
= This
->win_centerX
;
431 This
->mapped_center
.y
= This
->win_centerY
;
432 MapWindowPoints(This
->base
.win
, HWND_DESKTOP
, &This
->mapped_center
, 1);
437 /******************************************************************************
438 * Acquire : gets exclusive control of the mouse
440 static HRESULT WINAPI
SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface
)
442 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
447 TRACE("(this=%p)\n",This
);
449 if ((res
= IDirectInputDevice2AImpl_Acquire(iface
)) != DI_OK
) return res
;
451 /* Store (in a global variable) the current lock */
452 current_lock
= (IDirectInputDevice8A
*)This
;
454 /* Init the mouse state */
455 GetCursorPos( &point
);
456 if (This
->base
.data_format
.user_df
->dwFlags
& DIDF_ABSAXIS
)
458 This
->m_state
.lX
= point
.x
;
459 This
->m_state
.lY
= point
.y
;
460 This
->prevX
= point
.x
;
461 This
->prevY
= point
.y
;
463 This
->m_state
.lX
= 0;
464 This
->m_state
.lY
= 0;
465 This
->org_coords
= point
;
467 This
->m_state
.lZ
= 0;
468 This
->m_state
.rgbButtons
[0] = GetKeyState(VK_LBUTTON
) & 0x80;
469 This
->m_state
.rgbButtons
[1] = GetKeyState(VK_RBUTTON
) & 0x80;
470 This
->m_state
.rgbButtons
[2] = GetKeyState(VK_MBUTTON
) & 0x80;
472 /* Install our mouse hook */
473 if (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
)
474 ShowCursor(FALSE
); /* hide cursor */
475 set_dinput_hook(WH_MOUSE_LL
, dinput_mouse_hook
);
477 /* Get the window dimension and find the center */
478 GetWindowRect(This
->base
.win
, &rect
);
479 This
->win_centerX
= (rect
.right
- rect
.left
) / 2;
480 This
->win_centerY
= (rect
.bottom
- rect
.top
) / 2;
482 /* Warp the mouse to the center of the window */
483 if (!(This
->base
.data_format
.user_df
->dwFlags
& DIDF_ABSAXIS
))
485 This
->mapped_center
.x
= This
->win_centerX
;
486 This
->mapped_center
.y
= This
->win_centerY
;
487 MapWindowPoints(This
->base
.win
, HWND_DESKTOP
, &This
->mapped_center
, 1);
488 TRACE("Warping mouse to %d - %d\n", This
->mapped_center
.x
, This
->mapped_center
.y
);
489 SetCursorPos( This
->mapped_center
.x
, This
->mapped_center
.y
);
490 This
->last_warped
= GetCurrentTime();
493 This
->need_warp
= WARP_DONE
;
495 This
->need_warp
= WARP_STARTED
;
502 /******************************************************************************
503 * Unacquire : frees the mouse
505 static HRESULT WINAPI
SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface
)
507 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
510 TRACE("(this=%p)\n",This
);
512 if ((res
= IDirectInputDevice2AImpl_Unacquire(iface
)) != DI_OK
) return res
;
514 set_dinput_hook(WH_MOUSE_LL
, NULL
);
515 if (This
->base
.dwCoopLevel
& DISCL_EXCLUSIVE
)
516 ShowCursor(TRUE
); /* show cursor */
519 if (current_lock
== (IDirectInputDevice8A
*) This
)
522 ERR("this(%p) != current_lock(%p)\n", This
, current_lock
);
524 /* And put the mouse cursor back where it was at acquire time */
525 if (!(This
->base
.data_format
.user_df
->dwFlags
& DIDF_ABSAXIS
))
527 TRACE(" warping mouse back to (%d , %d)\n", This
->org_coords
.x
, This
->org_coords
.y
);
528 SetCursorPos(This
->org_coords
.x
, This
->org_coords
.y
);
534 /******************************************************************************
535 * GetDeviceState : returns the "state" of the mouse.
537 * For the moment, only the "standard" return structure (DIMOUSESTATE) is
540 static HRESULT WINAPI
SysMouseAImpl_GetDeviceState(
541 LPDIRECTINPUTDEVICE8A iface
,DWORD len
,LPVOID ptr
543 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
545 if(This
->base
.acquired
== 0) return DIERR_NOTACQUIRED
;
547 EnterCriticalSection(&This
->base
.crit
);
548 TRACE("(this=%p,0x%08x,%p):\n", This
, len
, ptr
);
549 TRACE("(X: %d - Y: %d - Z: %d L: %02x M: %02x R: %02x)\n",
550 This
->m_state
.lX
, This
->m_state
.lY
, This
->m_state
.lZ
,
551 This
->m_state
.rgbButtons
[0], This
->m_state
.rgbButtons
[2], This
->m_state
.rgbButtons
[1]);
553 /* Copy the current mouse state */
554 fill_DataFormat(ptr
, &(This
->m_state
), &This
->base
.data_format
);
556 /* Initialize the buffer when in relative mode */
557 if (!(This
->base
.data_format
.user_df
->dwFlags
& DIDF_ABSAXIS
))
559 This
->m_state
.lX
= 0;
560 This
->m_state
.lY
= 0;
561 This
->m_state
.lZ
= 0;
564 /* Check if we need to do a mouse warping */
565 if (This
->need_warp
== WARP_NEEDED
&& (GetCurrentTime() - This
->last_warped
> 10)) {
566 if(!dinput_window_check(This
))
568 LeaveCriticalSection(&This
->base
.crit
);
569 return DIERR_GENERIC
;
571 TRACE("Warping mouse to %d - %d\n", This
->mapped_center
.x
, This
->mapped_center
.y
);
572 SetCursorPos( This
->mapped_center
.x
, This
->mapped_center
.y
);
573 This
->last_warped
= GetCurrentTime();
576 This
->need_warp
= WARP_DONE
;
578 This
->need_warp
= WARP_STARTED
;
582 LeaveCriticalSection(&This
->base
.crit
);
587 /******************************************************************************
588 * GetDeviceData : gets buffered input data.
590 static HRESULT WINAPI
SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface
,
591 DWORD dodsize
, LPDIDEVICEOBJECTDATA dod
, LPDWORD entries
, DWORD flags
)
593 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
596 res
= IDirectInputDevice2AImpl_GetDeviceData(iface
, dodsize
, dod
, entries
, flags
);
597 if (FAILED(res
)) return res
;
599 /* Check if we need to do a mouse warping */
600 if (This
->need_warp
== WARP_NEEDED
&& (GetCurrentTime() - This
->last_warped
> 10)) {
601 if(!dinput_window_check(This
))
602 return DIERR_GENERIC
;
603 TRACE("Warping mouse to %d - %d\n", This
->mapped_center
.x
, This
->mapped_center
.y
);
604 SetCursorPos( This
->mapped_center
.x
, This
->mapped_center
.y
);
605 This
->last_warped
= GetCurrentTime();
608 This
->need_warp
= WARP_DONE
;
610 This
->need_warp
= WARP_STARTED
;
616 /******************************************************************************
617 * GetProperty : get input device properties
619 static HRESULT WINAPI
SysMouseAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface
,
621 LPDIPROPHEADER pdiph
)
623 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
625 TRACE("(%p) %s,%p\n", This
, debugstr_guid(rguid
), pdiph
);
626 _dump_DIPROPHEADER(pdiph
);
628 if (!HIWORD(rguid
)) {
629 switch (LOWORD(rguid
)) {
630 case (DWORD
) DIPROP_GRANULARITY
: {
631 LPDIPROPDWORD pr
= (LPDIPROPDWORD
) pdiph
;
633 /* We'll just assume that the app asks about the Z axis */
634 pr
->dwData
= WHEEL_DELTA
;
639 case (DWORD
) DIPROP_RANGE
: {
640 LPDIPROPRANGE pr
= (LPDIPROPRANGE
) pdiph
;
642 if ((pdiph
->dwHow
== DIPH_BYID
) &&
643 ((pdiph
->dwObj
== (DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE
) | DIDFT_RELAXIS
)) ||
644 (pdiph
->dwObj
== (DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE
) | DIDFT_RELAXIS
)))) {
645 /* Querying the range of either the X or the Y axis. As I do
646 not know the range, do as if the range were
648 pr
->lMin
= DIPROPRANGE_NOMIN
;
649 pr
->lMax
= DIPROPRANGE_NOMAX
;
656 return IDirectInputDevice2AImpl_GetProperty(iface
, rguid
, pdiph
);
663 /******************************************************************************
664 * GetCapabilities : get the device capablitites
666 static HRESULT WINAPI
SysMouseAImpl_GetCapabilities(
667 LPDIRECTINPUTDEVICE8A iface
,
668 LPDIDEVCAPS lpDIDevCaps
)
670 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
673 TRACE("(this=%p,%p)\n",This
,lpDIDevCaps
);
675 if ((lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS
)) && (lpDIDevCaps
->dwSize
!= sizeof(DIDEVCAPS_DX3
))) {
676 WARN("invalid parameter\n");
677 return DIERR_INVALIDPARAM
;
680 devcaps
.dwSize
= lpDIDevCaps
->dwSize
;
681 devcaps
.dwFlags
= DIDC_ATTACHED
;
682 if (This
->dinput
->dwVersion
>= 0x0800)
683 devcaps
.dwDevType
= DI8DEVTYPE_MOUSE
| (DI8DEVTYPEMOUSE_TRADITIONAL
<< 8);
685 devcaps
.dwDevType
= DIDEVTYPE_MOUSE
| (DIDEVTYPEMOUSE_TRADITIONAL
<< 8);
687 devcaps
.dwButtons
= 3;
689 devcaps
.dwFFSamplePeriod
= 0;
690 devcaps
.dwFFMinTimeResolution
= 0;
691 devcaps
.dwFirmwareRevision
= 100;
692 devcaps
.dwHardwareRevision
= 100;
693 devcaps
.dwFFDriverVersion
= 0;
695 memcpy(lpDIDevCaps
, &devcaps
, lpDIDevCaps
->dwSize
);
701 /******************************************************************************
702 * EnumObjects : enumerate the different buttons and axis...
704 static HRESULT WINAPI
SysMouseAImpl_EnumObjects(
705 LPDIRECTINPUTDEVICE8A iface
,
706 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback
,
710 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
711 DIDEVICEOBJECTINSTANCEA ddoi
;
713 TRACE("(this=%p,%p,%p,%08x)\n", This
, lpCallback
, lpvRef
, dwFlags
);
714 if (TRACE_ON(dinput
)) {
715 TRACE(" - flags = ");
716 _dump_EnumObjects_flags(dwFlags
);
720 /* Only the fields till dwFFMaxForce are relevant */
721 memset(&ddoi
, 0, sizeof(ddoi
));
722 ddoi
.dwSize
= FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA
, dwFFMaxForce
);
724 /* In a mouse, we have : two relative axis and three buttons */
725 if ((dwFlags
== DIDFT_ALL
) ||
726 (dwFlags
& DIDFT_AXIS
)) {
728 ddoi
.guidType
= GUID_XAxis
;
729 ddoi
.dwOfs
= This
->base
.data_format
.offsets
[WINE_MOUSE_X_POSITION
];
730 ddoi
.dwType
= DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE
) | DIDFT_RELAXIS
;
731 strcpy(ddoi
.tszName
, "X-Axis");
732 _dump_OBJECTINSTANCEA(&ddoi
);
733 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) return DI_OK
;
736 ddoi
.guidType
= GUID_YAxis
;
737 ddoi
.dwOfs
= This
->base
.data_format
.offsets
[WINE_MOUSE_Y_POSITION
];
738 ddoi
.dwType
= DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE
) | DIDFT_RELAXIS
;
739 strcpy(ddoi
.tszName
, "Y-Axis");
740 _dump_OBJECTINSTANCEA(&ddoi
);
741 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) return DI_OK
;
744 ddoi
.guidType
= GUID_ZAxis
;
745 ddoi
.dwOfs
= This
->base
.data_format
.offsets
[WINE_MOUSE_Z_POSITION
];
746 ddoi
.dwType
= DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE
) | DIDFT_RELAXIS
;
747 strcpy(ddoi
.tszName
, "Z-Axis");
748 _dump_OBJECTINSTANCEA(&ddoi
);
749 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) return DI_OK
;
752 if ((dwFlags
== DIDFT_ALL
) ||
753 (dwFlags
& DIDFT_BUTTON
)) {
754 ddoi
.guidType
= GUID_Button
;
757 ddoi
.dwOfs
= This
->base
.data_format
.offsets
[WINE_MOUSE_L_POSITION
];
758 ddoi
.dwType
= DIDFT_MAKEINSTANCE(WINE_MOUSE_L_BUTTON_INSTANCE
) | DIDFT_PSHBUTTON
;
759 strcpy(ddoi
.tszName
, "Left-Button");
760 _dump_OBJECTINSTANCEA(&ddoi
);
761 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) return DI_OK
;
764 ddoi
.dwOfs
= This
->base
.data_format
.offsets
[WINE_MOUSE_R_POSITION
];
765 ddoi
.dwType
= DIDFT_MAKEINSTANCE(WINE_MOUSE_R_BUTTON_INSTANCE
) | DIDFT_PSHBUTTON
;
766 strcpy(ddoi
.tszName
, "Right-Button");
767 _dump_OBJECTINSTANCEA(&ddoi
);
768 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) return DI_OK
;
771 ddoi
.dwOfs
= This
->base
.data_format
.offsets
[WINE_MOUSE_M_POSITION
];
772 ddoi
.dwType
= DIDFT_MAKEINSTANCE(WINE_MOUSE_M_BUTTON_INSTANCE
) | DIDFT_PSHBUTTON
;
773 strcpy(ddoi
.tszName
, "Middle-Button");
774 _dump_OBJECTINSTANCEA(&ddoi
);
775 if (lpCallback(&ddoi
, lpvRef
) != DIENUM_CONTINUE
) return DI_OK
;
781 static HRESULT WINAPI
SysMouseWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface
, LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback
, LPVOID lpvRef
,DWORD dwFlags
)
783 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
785 device_enumobjects_AtoWcb_data data
;
787 data
.lpCallBack
= lpCallback
;
788 data
.lpvRef
= lpvRef
;
790 return SysMouseAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A
) This
, (LPDIENUMDEVICEOBJECTSCALLBACKA
) DIEnumDevicesCallbackAtoW
, (LPVOID
) &data
, dwFlags
);
793 /******************************************************************************
794 * GetDeviceInfo : get information about a device's identity
796 static HRESULT WINAPI
SysMouseAImpl_GetDeviceInfo(
797 LPDIRECTINPUTDEVICE8A iface
,
798 LPDIDEVICEINSTANCEA pdidi
)
800 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
801 TRACE("(this=%p,%p)\n", This
, pdidi
);
803 if (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEA
)) {
804 WARN(" dinput3 not supporte yet...\n");
808 fill_mouse_dideviceinstanceA(pdidi
, This
->dinput
->dwVersion
);
813 static HRESULT WINAPI
SysMouseWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface
, LPDIDEVICEINSTANCEW pdidi
)
815 SysMouseImpl
*This
= (SysMouseImpl
*)iface
;
816 TRACE("(this=%p,%p)\n", This
, pdidi
);
818 if (pdidi
->dwSize
!= sizeof(DIDEVICEINSTANCEW
)) {
819 WARN(" dinput3 not supporte yet...\n");
823 fill_mouse_dideviceinstanceW(pdidi
, This
->dinput
->dwVersion
);
829 static const IDirectInputDevice8AVtbl SysMouseAvt
=
831 IDirectInputDevice2AImpl_QueryInterface
,
832 IDirectInputDevice2AImpl_AddRef
,
833 SysMouseAImpl_Release
,
834 SysMouseAImpl_GetCapabilities
,
835 SysMouseAImpl_EnumObjects
,
836 SysMouseAImpl_GetProperty
,
837 IDirectInputDevice2AImpl_SetProperty
,
838 SysMouseAImpl_Acquire
,
839 SysMouseAImpl_Unacquire
,
840 SysMouseAImpl_GetDeviceState
,
841 SysMouseAImpl_GetDeviceData
,
842 IDirectInputDevice2AImpl_SetDataFormat
,
843 IDirectInputDevice2AImpl_SetEventNotification
,
844 IDirectInputDevice2AImpl_SetCooperativeLevel
,
845 IDirectInputDevice2AImpl_GetObjectInfo
,
846 SysMouseAImpl_GetDeviceInfo
,
847 IDirectInputDevice2AImpl_RunControlPanel
,
848 IDirectInputDevice2AImpl_Initialize
,
849 IDirectInputDevice2AImpl_CreateEffect
,
850 IDirectInputDevice2AImpl_EnumEffects
,
851 IDirectInputDevice2AImpl_GetEffectInfo
,
852 IDirectInputDevice2AImpl_GetForceFeedbackState
,
853 IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
854 IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
855 IDirectInputDevice2AImpl_Escape
,
856 IDirectInputDevice2AImpl_Poll
,
857 IDirectInputDevice2AImpl_SendDeviceData
,
858 IDirectInputDevice7AImpl_EnumEffectsInFile
,
859 IDirectInputDevice7AImpl_WriteEffectToFile
,
860 IDirectInputDevice8AImpl_BuildActionMap
,
861 IDirectInputDevice8AImpl_SetActionMap
,
862 IDirectInputDevice8AImpl_GetImageInfo
865 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
866 # define XCAST(fun) (typeof(SysMouseWvt.fun))
868 # define XCAST(fun) (void*)
871 static const IDirectInputDevice8WVtbl SysMouseWvt
=
873 IDirectInputDevice2WImpl_QueryInterface
,
874 XCAST(AddRef
)IDirectInputDevice2AImpl_AddRef
,
875 XCAST(Release
)SysMouseAImpl_Release
,
876 XCAST(GetCapabilities
)SysMouseAImpl_GetCapabilities
,
877 SysMouseWImpl_EnumObjects
,
878 XCAST(GetProperty
)SysMouseAImpl_GetProperty
,
879 XCAST(SetProperty
)IDirectInputDevice2AImpl_SetProperty
,
880 XCAST(Acquire
)SysMouseAImpl_Acquire
,
881 XCAST(Unacquire
)SysMouseAImpl_Unacquire
,
882 XCAST(GetDeviceState
)SysMouseAImpl_GetDeviceState
,
883 XCAST(GetDeviceData
)SysMouseAImpl_GetDeviceData
,
884 XCAST(SetDataFormat
)IDirectInputDevice2AImpl_SetDataFormat
,
885 XCAST(SetEventNotification
)IDirectInputDevice2AImpl_SetEventNotification
,
886 XCAST(SetCooperativeLevel
)IDirectInputDevice2AImpl_SetCooperativeLevel
,
887 IDirectInputDevice2WImpl_GetObjectInfo
,
888 SysMouseWImpl_GetDeviceInfo
,
889 XCAST(RunControlPanel
)IDirectInputDevice2AImpl_RunControlPanel
,
890 XCAST(Initialize
)IDirectInputDevice2AImpl_Initialize
,
891 XCAST(CreateEffect
)IDirectInputDevice2AImpl_CreateEffect
,
892 IDirectInputDevice2WImpl_EnumEffects
,
893 IDirectInputDevice2WImpl_GetEffectInfo
,
894 XCAST(GetForceFeedbackState
)IDirectInputDevice2AImpl_GetForceFeedbackState
,
895 XCAST(SendForceFeedbackCommand
)IDirectInputDevice2AImpl_SendForceFeedbackCommand
,
896 XCAST(EnumCreatedEffectObjects
)IDirectInputDevice2AImpl_EnumCreatedEffectObjects
,
897 XCAST(Escape
)IDirectInputDevice2AImpl_Escape
,
898 XCAST(Poll
)IDirectInputDevice2AImpl_Poll
,
899 XCAST(SendDeviceData
)IDirectInputDevice2AImpl_SendDeviceData
,
900 IDirectInputDevice7WImpl_EnumEffectsInFile
,
901 IDirectInputDevice7WImpl_WriteEffectToFile
,
902 IDirectInputDevice8WImpl_BuildActionMap
,
903 IDirectInputDevice8WImpl_SetActionMap
,
904 IDirectInputDevice8WImpl_GetImageInfo