dinput: Move mouse to using new EnumObjects from base class.
[wine/dcerpc.git] / dlls / dinput / mouse.c
blob935c64b6044977ad170d9d876a9f92ad408edf7f
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 "winuser.h"
32 #include "winerror.h"
33 #include "dinput.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
46 /* ------------------------------- */
47 /* Wine mouse internal data format */
48 /* ------------------------------- */
50 /* Constants used to access the offset array */
51 #define WINE_MOUSE_X_POSITION 0
52 #define WINE_MOUSE_Y_POSITION 1
53 #define WINE_MOUSE_Z_POSITION 2
54 #define WINE_MOUSE_L_POSITION 3
55 #define WINE_MOUSE_R_POSITION 4
56 #define WINE_MOUSE_M_POSITION 5
58 static const IDirectInputDevice8AVtbl SysMouseAvt;
59 static const IDirectInputDevice8WVtbl SysMouseWvt;
61 typedef struct SysMouseImpl SysMouseImpl;
63 struct SysMouseImpl
65 struct IDirectInputDevice2AImpl base;
67 IDirectInputImpl *dinput;
69 /* SysMouseAImpl */
70 /* These are used in case of relative -> absolute transitions */
71 POINT org_coords;
72 POINT mapped_center;
73 DWORD win_centerX, win_centerY;
74 /* warping: whether we need to move mouse back to middle once we
75 * reach window borders (for e.g. shooters, "surface movement" games) */
76 BOOL need_warp;
77 DWORD last_warped;
79 /* This is for mouse reporting. */
80 DIMOUSESTATE2 m_state;
83 /* FIXME: This is ugly and not thread safe :/ */
84 static IDirectInputDevice8A* current_lock = NULL;
86 static GUID DInput_Wine_Mouse_GUID = { /* 9e573ed8-7734-11d2-8d4a-23903fb6bdf7 */
87 0x9e573ed8,
88 0x7734,
89 0x11d2,
90 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
93 static void fill_mouse_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, DWORD version) {
94 DWORD dwSize;
95 DIDEVICEINSTANCEA ddi;
97 dwSize = lpddi->dwSize;
99 TRACE("%d %p\n", dwSize, lpddi);
101 memset(lpddi, 0, dwSize);
102 memset(&ddi, 0, sizeof(ddi));
104 ddi.dwSize = dwSize;
105 ddi.guidInstance = GUID_SysMouse;/* DInput's GUID */
106 ddi.guidProduct = DInput_Wine_Mouse_GUID; /* Vendor's GUID */
107 if (version >= 0x0800)
108 ddi.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
109 else
110 ddi.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
111 strcpy(ddi.tszInstanceName, "Mouse");
112 strcpy(ddi.tszProductName, "Wine Mouse");
114 memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
117 static void fill_mouse_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, DWORD version) {
118 DWORD dwSize;
119 DIDEVICEINSTANCEW ddi;
121 dwSize = lpddi->dwSize;
123 TRACE("%d %p\n", dwSize, lpddi);
125 memset(lpddi, 0, dwSize);
126 memset(&ddi, 0, sizeof(ddi));
128 ddi.dwSize = dwSize;
129 ddi.guidInstance = GUID_SysMouse;/* DInput's GUID */
130 ddi.guidProduct = DInput_Wine_Mouse_GUID; /* Vendor's GUID */
131 if (version >= 0x0800)
132 ddi.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
133 else
134 ddi.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
135 MultiByteToWideChar(CP_ACP, 0, "Mouse", -1, ddi.tszInstanceName, MAX_PATH);
136 MultiByteToWideChar(CP_ACP, 0, "Wine Mouse", -1, ddi.tszProductName, MAX_PATH);
138 memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
141 static BOOL mousedev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, DWORD version, int id)
143 if (id != 0)
144 return FALSE;
146 if ((dwDevType == 0) ||
147 ((dwDevType == DIDEVTYPE_MOUSE) && (version < 0x0800)) ||
148 (((dwDevType == DI8DEVCLASS_POINTER) || (dwDevType == DI8DEVTYPE_MOUSE)) && (version >= 0x0800))) {
149 TRACE("Enumerating the mouse device\n");
151 fill_mouse_dideviceinstanceA(lpddi, version);
153 return TRUE;
156 return FALSE;
159 static BOOL mousedev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, DWORD version, int id)
161 if (id != 0)
162 return FALSE;
164 if ((dwDevType == 0) ||
165 ((dwDevType == DIDEVTYPE_MOUSE) && (version < 0x0800)) ||
166 (((dwDevType == DI8DEVCLASS_POINTER) || (dwDevType == DI8DEVTYPE_MOUSE)) && (version >= 0x0800))) {
167 TRACE("Enumerating the mouse device\n");
169 fill_mouse_dideviceinstanceW(lpddi, version);
171 return TRUE;
174 return FALSE;
177 static SysMouseImpl *alloc_device(REFGUID rguid, const void *mvt, IDirectInputImpl *dinput)
179 SysMouseImpl* newDevice;
180 LPDIDATAFORMAT df = NULL;
181 int i;
183 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouseImpl));
184 if (!newDevice) return NULL;
185 newDevice->base.lpVtbl = mvt;
186 newDevice->base.ref = 1;
187 newDevice->base.dwCoopLevel = DISCL_NONEXCLUSIVE | DISCL_BACKGROUND;
188 memcpy(&newDevice->base.guid, rguid, sizeof(*rguid));
189 InitializeCriticalSection(&newDevice->base.crit);
190 newDevice->dinput = dinput;
192 /* Create copy of default data format */
193 if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIMouse2.dwSize))) goto failed;
194 memcpy(df, &c_dfDIMouse2, c_dfDIMouse2.dwSize);
195 if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;
196 memcpy(df->rgodf, c_dfDIMouse2.rgodf, df->dwNumObjs * df->dwObjSize);
198 /* Because we don't do any detection yet just modify instance and type */
199 for (i = 0; i < df->dwNumObjs; i++)
200 if (DIDFT_GETTYPE(df->rgodf[i].dwType) & DIDFT_AXIS)
201 df->rgodf[i].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_RELAXIS;
202 else
203 df->rgodf[i].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
205 newDevice->base.data_format.wine_df = df;
206 IDirectInput_AddRef((LPDIRECTINPUTDEVICE8A)newDevice->dinput);
207 return newDevice;
209 failed:
210 if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
211 HeapFree(GetProcessHeap(), 0, df);
212 HeapFree(GetProcessHeap(), 0, newDevice);
213 return NULL;
216 static HRESULT mousedev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
218 if ((IsEqualGUID(&GUID_SysMouse,rguid)) || /* Generic Mouse */
219 (IsEqualGUID(&DInput_Wine_Mouse_GUID,rguid))) { /* Wine Mouse */
220 if ((riid == NULL) ||
221 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
222 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
223 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
224 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
225 *pdev = (IDirectInputDeviceA*) alloc_device(rguid, &SysMouseAvt, dinput);
226 TRACE("Creating a Mouse device (%p)\n", *pdev);
227 if (!*pdev) return DIERR_OUTOFMEMORY;
228 return DI_OK;
229 } else
230 return DIERR_NOINTERFACE;
233 return DIERR_DEVICENOTREG;
236 static HRESULT mousedev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* 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_IDirectInputDeviceW,riid) ||
242 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
243 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
244 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
245 *pdev = (IDirectInputDeviceW*) alloc_device(rguid, &SysMouseWvt, dinput);
246 TRACE("Creating a Mouse device (%p)\n", *pdev);
247 if (!*pdev) return DIERR_OUTOFMEMORY;
248 return DI_OK;
249 } else
250 return DIERR_NOINTERFACE;
253 return DIERR_DEVICENOTREG;
256 const struct dinput_device mouse_device = {
257 "Wine mouse driver",
258 mousedev_enum_deviceA,
259 mousedev_enum_deviceW,
260 mousedev_create_deviceA,
261 mousedev_create_deviceW
264 /******************************************************************************
265 * SysMouseA (DInput Mouse support)
268 /******************************************************************************
269 * Release : release the mouse buffer.
271 static ULONG WINAPI SysMouseAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
273 SysMouseImpl *This = (SysMouseImpl *)iface;
274 ULONG ref;
276 ref = InterlockedDecrement(&This->base.ref);
277 if (ref)
278 return ref;
280 set_dinput_hook(WH_MOUSE_LL, NULL);
282 /* Free the data queue */
283 HeapFree(GetProcessHeap(), 0, This->base.data_queue);
285 /* Free data format */
286 HeapFree(GetProcessHeap(), 0, (LPVOID)This->base.data_format.wine_df);
287 release_DataFormat(&This->base.data_format);
289 IDirectInput_Release((LPDIRECTINPUTDEVICE8A)This->dinput);
290 DeleteCriticalSection(&This->base.crit);
291 HeapFree(GetProcessHeap(),0,This);
292 return 0;
295 /* low-level mouse hook */
296 static LRESULT CALLBACK dinput_mouse_hook( int code, WPARAM wparam, LPARAM lparam )
298 MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam;
299 SysMouseImpl* This = (SysMouseImpl*) current_lock;
300 DWORD dwCoop;
301 int wdata;
303 if (code != HC_ACTION) return CallNextHookEx( 0, code, wparam, lparam );
305 EnterCriticalSection(&This->base.crit);
306 dwCoop = This->base.dwCoopLevel;
308 switch(wparam) {
309 case WM_MOUSEMOVE:
311 POINT pt, pt1;
313 GetCursorPos(&pt);
314 This->m_state.lX += pt.x = hook->pt.x - pt.x;
315 This->m_state.lY += pt.y = hook->pt.y - pt.y;
317 if (This->base.data_format.user_df->dwFlags & DIDF_ABSAXIS)
319 pt1.x = This->m_state.lX;
320 pt1.y = This->m_state.lY;
321 } else
322 pt1 = pt;
324 if (pt.x)
325 queue_event((LPDIRECTINPUTDEVICE8A)This, This->base.data_format.offsets[WINE_MOUSE_X_POSITION],
326 pt1.x, hook->time, This->dinput->evsequence);
327 if (pt.y)
328 queue_event((LPDIRECTINPUTDEVICE8A)This, This->base.data_format.offsets[WINE_MOUSE_Y_POSITION],
329 pt1.y, hook->time, This->dinput->evsequence);
331 This->need_warp = (pt.x || pt.y) && dwCoop & DISCL_EXCLUSIVE;
332 break;
334 case WM_LBUTTONDOWN:
335 queue_event((LPDIRECTINPUTDEVICE8A)This, This->base.data_format.offsets[WINE_MOUSE_L_POSITION],
336 0x80, hook->time, This->dinput->evsequence);
337 This->m_state.rgbButtons[0] = 0x80;
338 break;
339 case WM_LBUTTONUP:
340 queue_event((LPDIRECTINPUTDEVICE8A)This, This->base.data_format.offsets[WINE_MOUSE_L_POSITION],
341 0x00, hook->time, This->dinput->evsequence);
342 This->m_state.rgbButtons[0] = 0x00;
343 break;
344 case WM_RBUTTONDOWN:
345 queue_event((LPDIRECTINPUTDEVICE8A)This, This->base.data_format.offsets[WINE_MOUSE_R_POSITION],
346 0x80, hook->time, This->dinput->evsequence);
347 This->m_state.rgbButtons[1] = 0x80;
348 break;
349 case WM_RBUTTONUP:
350 queue_event((LPDIRECTINPUTDEVICE8A)This, This->base.data_format.offsets[WINE_MOUSE_R_POSITION],
351 0x00, hook->time, This->dinput->evsequence);
352 This->m_state.rgbButtons[1] = 0x00;
353 break;
354 case WM_MBUTTONDOWN:
355 queue_event((LPDIRECTINPUTDEVICE8A)This, This->base.data_format.offsets[WINE_MOUSE_M_POSITION],
356 0x80, hook->time, This->dinput->evsequence);
357 This->m_state.rgbButtons[2] = 0x80;
358 break;
359 case WM_MBUTTONUP:
360 queue_event((LPDIRECTINPUTDEVICE8A)This, This->base.data_format.offsets[WINE_MOUSE_M_POSITION],
361 0x00, hook->time, This->dinput->evsequence);
362 This->m_state.rgbButtons[2] = 0x00;
363 break;
364 case WM_MOUSEWHEEL:
365 wdata = (short)HIWORD(hook->mouseData);
366 queue_event((LPDIRECTINPUTDEVICE8A)This, This->base.data_format.offsets[WINE_MOUSE_Z_POSITION],
367 wdata, hook->time, This->dinput->evsequence);
368 This->m_state.lZ += wdata;
369 break;
372 TRACE("msg %x @ (%d %d): (X: %d - Y: %d L: %02x M: %02x R: %02x)\n",
373 wparam, hook->pt.x, hook->pt.y, This->m_state.lX, This->m_state.lY,
374 This->m_state.rgbButtons[0], This->m_state.rgbButtons[2], This->m_state.rgbButtons[1]);
376 This->dinput->evsequence++;
378 /* Mouse moved -> send event if asked */
379 if (This->base.hEvent) SetEvent(This->base.hEvent);
381 LeaveCriticalSection(&This->base.crit);
383 /* Ignore message */
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) {
391 RECT rect;
392 DWORD centerX, centerY;
394 /* make sure the window hasn't moved */
395 if(!GetWindowRect(This->base.win, &rect))
396 return FALSE;
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);
406 return TRUE;
410 /******************************************************************************
411 * Acquire : gets exclusive control of the mouse
413 static HRESULT WINAPI SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
415 SysMouseImpl *This = (SysMouseImpl *)iface;
416 RECT rect;
417 POINT point;
418 HRESULT res;
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;
433 } else {
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;
466 return DI_OK;
469 /******************************************************************************
470 * Unacquire : frees the mouse
472 static HRESULT WINAPI SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
474 SysMouseImpl *This = (SysMouseImpl *)iface;
475 HRESULT res;
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 */
485 /* No more locks */
486 if (current_lock == (IDirectInputDevice8A*) This)
487 current_lock = NULL;
488 else
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);
498 return DI_OK;
501 /******************************************************************************
502 * GetDeviceState : returns the "state" of the mouse.
504 * For the moment, only the "standard" return structure (DIMOUSESTATE) is
505 * supported.
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 EnterCriticalSection(&This->base.crit);
515 TRACE("(this=%p,0x%08x,%p):\n", This, len, ptr);
516 TRACE("(X: %d - Y: %d - Z: %d L: %02x M: %02x R: %02x)\n",
517 This->m_state.lX, This->m_state.lY, This->m_state.lZ,
518 This->m_state.rgbButtons[0], This->m_state.rgbButtons[2], This->m_state.rgbButtons[1]);
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;
531 /* Check if we need to do a mouse warping */
532 if (This->need_warp && (GetCurrentTime() - This->last_warped > 10))
534 if(!dinput_window_check(This))
536 LeaveCriticalSection(&This->base.crit);
537 return DIERR_GENERIC;
539 TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y);
540 SetCursorPos( This->mapped_center.x, This->mapped_center.y );
541 This->last_warped = GetCurrentTime();
543 This->need_warp = FALSE;
546 LeaveCriticalSection(&This->base.crit);
548 return DI_OK;
551 /******************************************************************************
552 * GetDeviceData : gets buffered input data.
554 static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
555 DWORD dodsize, LPDIDEVICEOBJECTDATA dod, LPDWORD entries, DWORD flags)
557 SysMouseImpl *This = (SysMouseImpl *)iface;
558 HRESULT res;
560 res = IDirectInputDevice2AImpl_GetDeviceData(iface, dodsize, dod, entries, flags);
561 if (FAILED(res)) return res;
563 /* Check if we need to do a mouse warping */
564 if (This->need_warp && (GetCurrentTime() - This->last_warped > 10))
566 if(!dinput_window_check(This))
567 return DIERR_GENERIC;
568 TRACE("Warping mouse to %d - %d\n", This->mapped_center.x, This->mapped_center.y);
569 SetCursorPos( This->mapped_center.x, This->mapped_center.y );
570 This->last_warped = GetCurrentTime();
572 This->need_warp = FALSE;
574 return res;
577 /******************************************************************************
578 * GetProperty : get input device properties
580 static HRESULT WINAPI SysMouseAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
581 REFGUID rguid,
582 LPDIPROPHEADER pdiph)
584 SysMouseImpl *This = (SysMouseImpl *)iface;
586 TRACE("(%p) %s,%p\n", This, debugstr_guid(rguid), pdiph);
587 _dump_DIPROPHEADER(pdiph);
589 if (!HIWORD(rguid)) {
590 switch (LOWORD(rguid)) {
591 case (DWORD) DIPROP_GRANULARITY: {
592 LPDIPROPDWORD pr = (LPDIPROPDWORD) pdiph;
594 /* We'll just assume that the app asks about the Z axis */
595 pr->dwData = WHEEL_DELTA;
597 break;
600 case (DWORD) DIPROP_RANGE: {
601 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
603 if ((pdiph->dwHow == DIPH_BYID) &&
604 ((pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS)) ||
605 (pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS)))) {
606 /* Querying the range of either the X or the Y axis. As I do
607 not know the range, do as if the range were
608 unrestricted...*/
609 pr->lMin = DIPROPRANGE_NOMIN;
610 pr->lMax = DIPROPRANGE_NOMAX;
613 break;
616 default:
617 return IDirectInputDevice2AImpl_GetProperty(iface, rguid, pdiph);
621 return DI_OK;
624 /******************************************************************************
625 * GetCapabilities : get the device capablitites
627 static HRESULT WINAPI SysMouseAImpl_GetCapabilities(
628 LPDIRECTINPUTDEVICE8A iface,
629 LPDIDEVCAPS lpDIDevCaps)
631 SysMouseImpl *This = (SysMouseImpl *)iface;
632 DIDEVCAPS devcaps;
634 TRACE("(this=%p,%p)\n",This,lpDIDevCaps);
636 if ((lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) && (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS_DX3))) {
637 WARN("invalid parameter\n");
638 return DIERR_INVALIDPARAM;
641 devcaps.dwSize = lpDIDevCaps->dwSize;
642 devcaps.dwFlags = DIDC_ATTACHED;
643 if (This->dinput->dwVersion >= 0x0800)
644 devcaps.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
645 else
646 devcaps.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
647 devcaps.dwAxes = 3;
648 devcaps.dwButtons = 8;
649 devcaps.dwPOVs = 0;
650 devcaps.dwFFSamplePeriod = 0;
651 devcaps.dwFFMinTimeResolution = 0;
652 devcaps.dwFirmwareRevision = 100;
653 devcaps.dwHardwareRevision = 100;
654 devcaps.dwFFDriverVersion = 0;
656 memcpy(lpDIDevCaps, &devcaps, lpDIDevCaps->dwSize);
658 return DI_OK;
662 /******************************************************************************
663 * GetDeviceInfo : get information about a device's identity
665 static HRESULT WINAPI SysMouseAImpl_GetDeviceInfo(
666 LPDIRECTINPUTDEVICE8A iface,
667 LPDIDEVICEINSTANCEA pdidi)
669 SysMouseImpl *This = (SysMouseImpl *)iface;
670 TRACE("(this=%p,%p)\n", This, pdidi);
672 if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA)) {
673 WARN(" dinput3 not supporte yet...\n");
674 return DI_OK;
677 fill_mouse_dideviceinstanceA(pdidi, This->dinput->dwVersion);
679 return DI_OK;
682 static HRESULT WINAPI SysMouseWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW pdidi)
684 SysMouseImpl *This = (SysMouseImpl *)iface;
685 TRACE("(this=%p,%p)\n", This, pdidi);
687 if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)) {
688 WARN(" dinput3 not supporte yet...\n");
689 return DI_OK;
692 fill_mouse_dideviceinstanceW(pdidi, This->dinput->dwVersion);
694 return DI_OK;
698 static const IDirectInputDevice8AVtbl SysMouseAvt =
700 IDirectInputDevice2AImpl_QueryInterface,
701 IDirectInputDevice2AImpl_AddRef,
702 SysMouseAImpl_Release,
703 SysMouseAImpl_GetCapabilities,
704 IDirectInputDevice2AImpl_EnumObjects,
705 SysMouseAImpl_GetProperty,
706 IDirectInputDevice2AImpl_SetProperty,
707 SysMouseAImpl_Acquire,
708 SysMouseAImpl_Unacquire,
709 SysMouseAImpl_GetDeviceState,
710 SysMouseAImpl_GetDeviceData,
711 IDirectInputDevice2AImpl_SetDataFormat,
712 IDirectInputDevice2AImpl_SetEventNotification,
713 IDirectInputDevice2AImpl_SetCooperativeLevel,
714 IDirectInputDevice2AImpl_GetObjectInfo,
715 SysMouseAImpl_GetDeviceInfo,
716 IDirectInputDevice2AImpl_RunControlPanel,
717 IDirectInputDevice2AImpl_Initialize,
718 IDirectInputDevice2AImpl_CreateEffect,
719 IDirectInputDevice2AImpl_EnumEffects,
720 IDirectInputDevice2AImpl_GetEffectInfo,
721 IDirectInputDevice2AImpl_GetForceFeedbackState,
722 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
723 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
724 IDirectInputDevice2AImpl_Escape,
725 IDirectInputDevice2AImpl_Poll,
726 IDirectInputDevice2AImpl_SendDeviceData,
727 IDirectInputDevice7AImpl_EnumEffectsInFile,
728 IDirectInputDevice7AImpl_WriteEffectToFile,
729 IDirectInputDevice8AImpl_BuildActionMap,
730 IDirectInputDevice8AImpl_SetActionMap,
731 IDirectInputDevice8AImpl_GetImageInfo
734 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
735 # define XCAST(fun) (typeof(SysMouseWvt.fun))
736 #else
737 # define XCAST(fun) (void*)
738 #endif
740 static const IDirectInputDevice8WVtbl SysMouseWvt =
742 IDirectInputDevice2WImpl_QueryInterface,
743 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
744 XCAST(Release)SysMouseAImpl_Release,
745 XCAST(GetCapabilities)SysMouseAImpl_GetCapabilities,
746 IDirectInputDevice2WImpl_EnumObjects,
747 XCAST(GetProperty)SysMouseAImpl_GetProperty,
748 XCAST(SetProperty)IDirectInputDevice2AImpl_SetProperty,
749 XCAST(Acquire)SysMouseAImpl_Acquire,
750 XCAST(Unacquire)SysMouseAImpl_Unacquire,
751 XCAST(GetDeviceState)SysMouseAImpl_GetDeviceState,
752 XCAST(GetDeviceData)SysMouseAImpl_GetDeviceData,
753 XCAST(SetDataFormat)IDirectInputDevice2AImpl_SetDataFormat,
754 XCAST(SetEventNotification)IDirectInputDevice2AImpl_SetEventNotification,
755 XCAST(SetCooperativeLevel)IDirectInputDevice2AImpl_SetCooperativeLevel,
756 IDirectInputDevice2WImpl_GetObjectInfo,
757 SysMouseWImpl_GetDeviceInfo,
758 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
759 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
760 XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
761 IDirectInputDevice2WImpl_EnumEffects,
762 IDirectInputDevice2WImpl_GetEffectInfo,
763 XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
764 XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
765 XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
766 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
767 XCAST(Poll)IDirectInputDevice2AImpl_Poll,
768 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
769 IDirectInputDevice7WImpl_EnumEffectsInFile,
770 IDirectInputDevice7WImpl_WriteEffectToFile,
771 IDirectInputDevice8WImpl_BuildActionMap,
772 IDirectInputDevice8WImpl_SetActionMap,
773 IDirectInputDevice8WImpl_GetImageInfo
775 #undef XCAST