source: trunk/src/dinput/mouse.c@ 8348

Last change on this file since 8348 was 8348, checked in by sandervl, 23 years ago

* empty log message *

File size: 29.4 KB
Line 
1/* DirectInput Mouse device
2 *
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 *
6 */
7
8#include "config.h"
9#include <string.h>
10#ifdef HAVE_SYS_ERRNO_H
11# include <sys/errno.h>
12#endif
13
14#include "winbase.h"
15#include "wingdi.h"
16#include "winuser.h"
17#include "winerror.h"
18#include "dinput.h"
19
20#include "dinput_private.h"
21#include "device_private.h"
22#include "debugtools.h"
23
24#define MOUSE_HACK
25
26DEFAULT_DEBUG_CHANNEL(dinput);
27
28/* Wine mouse driver object instances */
29#define WINE_MOUSE_X_AXIS_INSTANCE 0x0001
30#define WINE_MOUSE_Y_AXIS_INSTANCE 0x0002
31#define WINE_MOUSE_L_BUTTON_INSTANCE 0x0004
32#define WINE_MOUSE_R_BUTTON_INSTANCE 0x0008
33#define WINE_MOUSE_M_BUTTON_INSTANCE 0x0010
34
35/* ------------------------------- */
36/* Wine mouse internal data format */
37/* ------------------------------- */
38
39/* Constants used to access the offset array */
40#define WINE_MOUSE_X_POSITION 0
41#define WINE_MOUSE_Y_POSITION 1
42#define WINE_MOUSE_L_POSITION 2
43#define WINE_MOUSE_R_POSITION 3
44#define WINE_MOUSE_M_POSITION 4
45
46typedef struct {
47 LONG lX;
48 LONG lY;
49 BYTE rgbButtons[4];
50} Wine_InternalMouseData;
51
52#define WINE_INTERNALMOUSE_NUM_OBJS 5
53
54static DIOBJECTDATAFORMAT Wine_InternalMouseObjectFormat[WINE_INTERNALMOUSE_NUM_OBJS] = {
55 { &GUID_XAxis, FIELD_OFFSET(Wine_InternalMouseData, lX),
56 DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS, 0 },
57 { &GUID_YAxis, FIELD_OFFSET(Wine_InternalMouseData, lY),
58 DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS, 0 },
59 { &GUID_Button, (FIELD_OFFSET(Wine_InternalMouseData, rgbButtons)) + 0,
60 DIDFT_MAKEINSTANCE(WINE_MOUSE_L_BUTTON_INSTANCE) | DIDFT_PSHBUTTON, 0 },
61 { &GUID_Button, (FIELD_OFFSET(Wine_InternalMouseData, rgbButtons)) + 1,
62 DIDFT_MAKEINSTANCE(WINE_MOUSE_R_BUTTON_INSTANCE) | DIDFT_PSHBUTTON, 0 },
63 { &GUID_Button, (FIELD_OFFSET(Wine_InternalMouseData, rgbButtons)) + 2,
64 DIDFT_MAKEINSTANCE(WINE_MOUSE_M_BUTTON_INSTANCE) | DIDFT_PSHBUTTON, 0 }
65};
66
67static DIDATAFORMAT Wine_InternalMouseFormat = {
68 0, /* dwSize - unused */
69 0, /* dwObjsize - unused */
70 0, /* dwFlags - unused */
71 sizeof(Wine_InternalMouseData),
72 WINE_INTERNALMOUSE_NUM_OBJS, /* dwNumObjs */
73 Wine_InternalMouseObjectFormat
74};
75
76static ICOM_VTABLE(IDirectInputDevice2A) SysMouseAvt;
77static ICOM_VTABLE(IDirectInputDevice7A) SysMouse7Avt;
78typedef struct SysMouseAImpl SysMouseAImpl;
79
80typedef enum {
81 WARP_NEEDED, /* Warping is needed */
82 WARP_STARTED, /* Warping has been done, waiting for the warp event */
83 WARP_DONE /* Warping has been done */
84} WARP_STATUS;
85
86struct SysMouseAImpl
87{
88 /* IDirectInputDevice2AImpl */
89 ICOM_VFIELD(IDirectInputDevice2A);
90 DWORD ref;
91 GUID guid;
92
93 IDirectInputAImpl *dinput;
94
95 /* The current data format and the conversion between internal
96 and external data formats */
97 LPDIDATAFORMAT df;
98 DataFormat *wine_df;
99 int offset_array[5];
100
101 /* SysMouseAImpl */
102 BYTE absolute;
103 /* Previous position for relative moves */
104 LONG prevX, prevY;
105 HHOOK hook;
106 HWND win;
107 DWORD dwCoopLevel;
108 POINT mapped_center;
109 DWORD win_centerX, win_centerY;
110 LPDIDEVICEOBJECTDATA data_queue;
111 int queue_head, queue_tail, queue_len;
112 /* warping: whether we need to move mouse back to middle once we
113 * reach window borders (for e.g. shooters, "surface movement" games) */
114 WARP_STATUS need_warp;
115 int acquired;
116 HANDLE hEvent;
117 CRITICAL_SECTION crit;
118
119 /* This is for mouse reporting. */
120 Wine_InternalMouseData m_state;
121};
122
123static GUID DInput_Wine_Mouse_GUID = { /* 9e573ed8-7734-11d2-8d4a-23903fb6bdf7 */
124 0x9e573ed8,
125 0x7734,
126 0x11d2,
127 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
128};
129
130/* FIXME: This is ugly and not thread safe :/ */
131static IDirectInputDevice2A* current_lock = NULL;
132
133
134static BOOL mousedev_enum_device(DWORD dwDevType, DWORD dwFlags, LPCDIDEVICEINSTANCEA lpddi)
135{
136 if ((dwDevType == 0) || (dwDevType == DIDEVTYPE_MOUSE)) {
137 TRACE("Enumerating the mouse device\n");
138
139 /* Return mouse */
140 lpddi->guidInstance = GUID_SysMouse;/* DInput's GUID */
141 lpddi->guidProduct = DInput_Wine_Mouse_GUID; /* Vendor's GUID */
142 lpddi->dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_UNKNOWN << 8);
143 strcpy(lpddi->tszInstanceName, "Mouse");
144 strcpy(lpddi->tszProductName, "Wine Mouse");
145
146 return TRUE;
147 }
148
149 return FALSE;
150}
151
152static SysMouseAImpl *alloc_device(REFGUID rguid, ICOM_VTABLE(IDirectInputDevice2A) *mvt, IDirectInputAImpl *dinput)
153{
154 int offset_array[5] = {
155 FIELD_OFFSET(Wine_InternalMouseData, lX),
156 FIELD_OFFSET(Wine_InternalMouseData, lY),
157 FIELD_OFFSET(Wine_InternalMouseData, rgbButtons) + 0,
158 FIELD_OFFSET(Wine_InternalMouseData, rgbButtons) + 1,
159 FIELD_OFFSET(Wine_InternalMouseData, rgbButtons) + 2
160 };
161 SysMouseAImpl* newDevice;
162 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouseAImpl));
163 newDevice->ref = 1;
164 ICOM_VTBL(newDevice) = mvt;
165 InitializeCriticalSection(&(newDevice->crit));
166 memcpy(&(newDevice->guid),rguid,sizeof(*rguid));
167
168 /* Per default, Wine uses its internal data format */
169 newDevice->df = &Wine_InternalMouseFormat;
170 memcpy(newDevice->offset_array, offset_array, 5 * sizeof(int));
171 newDevice->wine_df = (DataFormat *) HeapAlloc(GetProcessHeap(), 0, sizeof(DataFormat));
172 newDevice->wine_df->size = 0;
173 newDevice->wine_df->internal_format_size = Wine_InternalMouseFormat.dwDataSize;
174 newDevice->wine_df->dt = NULL;
175 newDevice->dinput = dinput;
176
177 return newDevice;
178}
179
180static HRESULT mousedev_create_device(IDirectInputAImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
181{
182 if ((IsEqualGUID(&GUID_SysMouse,rguid)) || /* Generic Mouse */
183 (IsEqualGUID(&DInput_Wine_Mouse_GUID,rguid))) { /* Wine Mouse */
184 if ((riid == NULL) || (IsEqualGUID(&IID_IDirectInputDevice2A,riid)) || (IsEqualGUID(&IID_IDirectInputDevice2A,riid))) {
185 *pdev=(IDirectInputDeviceA*) alloc_device(rguid, &SysMouseAvt, dinput);
186
187 TRACE("Creating a Mouse device (%p)\n", *pdev);
188 return DI_OK;
189 }else if (IsEqualGUID(&IID_IDirectInputDevice7A,riid)) {
190 *pdev=(IDirectInputDeviceA*) alloc_device(rguid, (ICOM_VTABLE(IDirectInputDevice2A) *) &SysMouse7Avt, dinput);
191
192 TRACE("Creating a Mouse DInput7A device (%p)\n", *pdev);
193 return DI_OK;
194 } else
195 return DIERR_NOINTERFACE;
196 }
197
198 return DIERR_DEVICENOTREG;
199}
200
201static dinput_device mousedev = {
202 100,
203 mousedev_enum_device,
204 mousedev_create_device
205};
206
207DECL_GLOBAL_CONSTRUCTOR(mousedev_register) { dinput_register_device(&mousedev); }
208
209/******************************************************************************
210 * SysMouseA (DInput Mouse support)
211 */
212
213/******************************************************************************
214 * Release : release the mouse buffer.
215 */
216static ULONG WINAPI SysMouseAImpl_Release(LPDIRECTINPUTDEVICE2A iface)
217{
218 ICOM_THIS(SysMouseAImpl,iface);
219
220 This->ref--;
221 if (This->ref)
222 return This->ref;
223
224 /* Free the data queue */
225 if (This->data_queue != NULL)
226 HeapFree(GetProcessHeap(),0,This->data_queue);
227
228 if (This->hook) UnhookWindowsHookEx( This->hook );
229 DeleteCriticalSection(&(This->crit));
230
231 /* Free the DataFormat */
232 if (This->df != &(Wine_InternalMouseFormat)) {
233 HeapFree(GetProcessHeap(), 0, This->df->rgodf);
234 HeapFree(GetProcessHeap(), 0, This->df);
235 }
236
237 HeapFree(GetProcessHeap(),0,This);
238 return 0;
239}
240
241
242/******************************************************************************
243 * SetCooperativeLevel : store the window in which we will do our
244 * grabbing.
245 */
246static HRESULT WINAPI SysMouseAImpl_SetCooperativeLevel(
247 LPDIRECTINPUTDEVICE2A iface,HWND hwnd,DWORD dwflags
248)
249{
250 ICOM_THIS(SysMouseAImpl,iface);
251
252 TRACE("(this=%p,0x%08lx,0x%08lx)\n",This,(DWORD)hwnd,dwflags);
253
254 if (TRACE_ON(dinput))
255 _dump_cooperativelevel_DI(dwflags);
256
257 /* Store the window which asks for the mouse */
258 if (!hwnd)
259 hwnd = GetDesktopWindow();
260 This->win = hwnd;
261 This->dwCoopLevel = dwflags;
262
263 return 0;
264}
265
266
267/******************************************************************************
268 * SetDataFormat : the application can choose the format of the data
269 * the device driver sends back with GetDeviceState.
270 *
271 * For the moment, only the "standard" configuration (c_dfDIMouse) is supported
272 * in absolute and relative mode.
273 */
274static HRESULT WINAPI SysMouseAImpl_SetDataFormat(
275 LPDIRECTINPUTDEVICE2A iface,LPCDIDATAFORMAT df
276)
277{
278 ICOM_THIS(SysMouseAImpl,iface);
279 int i;
280
281 TRACE("(this=%p,%p)\n",This,df);
282
283 TRACE("(df.dwSize=%ld)\n",df->dwSize);
284 TRACE("(df.dwObjsize=%ld)\n",df->dwObjSize);
285 TRACE("(df.dwFlags=0x%08lx)\n",df->dwFlags);
286 TRACE("(df.dwDataSize=%ld)\n",df->dwDataSize);
287 TRACE("(df.dwNumObjs=%ld)\n",df->dwNumObjs);
288
289 for (i=0;i<df->dwNumObjs;i++) {
290
291 TRACE("df.rgodf[%d].guid %s (%p)\n",i, debugstr_guid(df->rgodf[i].pguid), df->rgodf[i].pguid);
292 TRACE("df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
293 TRACE("dwType 0x%02x,dwInstance %d\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
294 TRACE("df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
295 }
296
297 /* Check if the mouse is in absolute or relative mode */
298 if (df->dwFlags == DIDF_ABSAXIS)
299 This->absolute = 1;
300 else if (df->dwFlags == DIDF_RELAXIS)
301 This->absolute = 0;
302 else
303 ERR("Neither absolute nor relative flag set\n");
304
305 /* Store the new data format */
306 This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
307 memcpy(This->df, df, df->dwSize);
308 This->df->rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
309 memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
310
311 /* Prepare all the data-conversion filters */
312 This->wine_df = create_DataFormat(&(Wine_InternalMouseFormat), df, This->offset_array);
313
314 return 0;
315}
316
317/* low-level mouse hook */
318static LRESULT CALLBACK dinput_mouse_hook( int code, WPARAM wparam, LPARAM lparam )
319{
320 LRESULT ret;
321 MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam;
322 SysMouseAImpl* This = (SysMouseAImpl*) current_lock;
323
324//testestest
325 dprintf(("dinput_mouse_hook %d %x %x", code, wparam, lparam));
326
327 if (code != HC_ACTION) return CallNextHookEx( This->hook, code, wparam, lparam );
328
329 EnterCriticalSection(&(This->crit));
330 /* Mouse moved -> send event if asked */
331 if (This->hEvent)
332 SetEvent(This->hEvent);
333
334 if (wparam == WM_MOUSEMOVE) {
335 if (This->absolute) {
336 if (hook->pt.x != This->prevX)
337 GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x, hook->time, 0);
338 if (hook->pt.y != This->prevY)
339 GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y, hook->time, 0);
340 } else {
341 /* Now, warp handling */
342 if ((This->need_warp == WARP_STARTED) &&
343 (hook->pt.x == This->mapped_center.x) && (hook->pt.y == This->mapped_center.y)) {
344 /* Warp has been done... */
345 This->need_warp = WARP_DONE;
346 goto end;
347 }
348
349 /* Relative mouse input with absolute mouse event : the real fun starts here... */
350 if ((This->need_warp == WARP_NEEDED) ||
351 (This->need_warp == WARP_STARTED)) {
352 if (hook->pt.x != This->prevX)
353 GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->prevX, hook->time, (This->dinput->evsequence)++);
354 if (hook->pt.y != This->prevY)
355 GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->prevY, hook->time, (This->dinput->evsequence)++);
356 } else {
357 /* This is the first time the event handler has been called after a
358 GetDeviceData or GetDeviceState. */
359 if (hook->pt.x != This->mapped_center.x) {
360 GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->mapped_center.x, hook->time, (This->dinput->evsequence)++);
361 This->need_warp = WARP_NEEDED;
362 }
363
364 if (hook->pt.y != This->mapped_center.y) {
365 GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->mapped_center.y, hook->time, (This->dinput->evsequence)++);
366 This->need_warp = WARP_NEEDED;
367 }
368 }
369 }
370
371 This->prevX = hook->pt.x;
372 This->prevY = hook->pt.y;
373
374 if (This->absolute) {
375 This->m_state.lX = hook->pt.x;
376 This->m_state.lY = hook->pt.y;
377 } else {
378 This->m_state.lX = hook->pt.x - This->mapped_center.x;
379 This->m_state.lY = hook->pt.y - This->mapped_center.y;
380 }
381 }
382
383 TRACE(" msg %x pt %ld %ld (W=%d)\n",
384 wparam, hook->pt.x, hook->pt.y, (!This->absolute) && This->need_warp );
385
386 switch(wparam)
387 {
388 case WM_LBUTTONDOWN:
389 GEN_EVENT(This->offset_array[WINE_MOUSE_L_POSITION], 0xFF,
390 hook->time, This->dinput->evsequence++);
391 This->m_state.rgbButtons[0] = 0xFF;
392 break;
393 case WM_LBUTTONUP:
394 GEN_EVENT(This->offset_array[WINE_MOUSE_L_POSITION], 0x00,
395 hook->time, This->dinput->evsequence++);
396 This->m_state.rgbButtons[0] = 0x00;
397 break;
398 case WM_RBUTTONDOWN:
399 GEN_EVENT(This->offset_array[WINE_MOUSE_R_POSITION], 0xFF,
400 hook->time, This->dinput->evsequence++);
401 This->m_state.rgbButtons[1] = 0xFF;
402 break;
403 case WM_RBUTTONUP:
404 GEN_EVENT(This->offset_array[WINE_MOUSE_R_POSITION], 0x00,
405 hook->time, This->dinput->evsequence++);
406 This->m_state.rgbButtons[1] = 0x00;
407 break;
408 case WM_MBUTTONDOWN:
409 GEN_EVENT(This->offset_array[WINE_MOUSE_M_POSITION], 0xFF,
410 hook->time, This->dinput->evsequence++);
411 This->m_state.rgbButtons[2] = 0xFF;
412 break;
413 case WM_MBUTTONUP:
414 GEN_EVENT(This->offset_array[WINE_MOUSE_M_POSITION], 0x00,
415 hook->time, This->dinput->evsequence++);
416 This->m_state.rgbButtons[2] = 0x00;
417 break;
418 }
419
420 TRACE("(X: %ld - Y: %ld L: %02x M: %02x R: %02x)\n",
421 This->m_state.lX, This->m_state.lY,
422 This->m_state.rgbButtons[0], This->m_state.rgbButtons[2], This->m_state.rgbButtons[1]);
423
424end:
425 if (This->dwCoopLevel & DISCL_NONEXCLUSIVE)
426 { /* pass the events down to previous handlers (e.g. win32 input) */
427 ret = CallNextHookEx( This->hook, code, wparam, lparam );
428 }
429 else ret = 1; /* ignore message */
430 LeaveCriticalSection(&(This->crit));
431 return ret;
432}
433
434
435/******************************************************************************
436 * Acquire : gets exclusive control of the mouse
437 */
438static HRESULT WINAPI SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE2A iface)
439{
440 ICOM_THIS(SysMouseAImpl,iface);
441 RECT rect;
442
443 TRACE("(this=%p)\n",This);
444
445 if (This->acquired == 0) {
446 POINT point;
447
448 /* Store (in a global variable) the current lock */
449 current_lock = (IDirectInputDevice2A*)This;
450
451 /* Init the mouse state */
452 if (This->absolute) {
453 GetCursorPos( &point );
454 This->m_state.lX = point.x;
455 This->m_state.lY = point.y;
456 This->prevX = point.x;
457 This->prevY = point.y;
458 } else {
459 This->m_state.lX = 0;
460 This->m_state.lY = 0;
461 }
462 This->m_state.rgbButtons[0] = (GetKeyState(VK_LBUTTON) ? 0xFF : 0x00);
463 This->m_state.rgbButtons[1] = (GetKeyState(VK_MBUTTON) ? 0xFF : 0x00);
464 This->m_state.rgbButtons[2] = (GetKeyState(VK_RBUTTON) ? 0xFF : 0x00);
465
466 /* Install our mouse hook */
467 This->hook = SetWindowsHookExW( WH_MOUSE_LL, dinput_mouse_hook, 0, 0 );
468
469 /* Get the window dimension and find the center */
470 GetWindowRect(This->win, &rect);
471 This->win_centerX = (rect.right - rect.left) / 2;
472 This->win_centerY = (rect.bottom - rect.top ) / 2;
473
474 /* Warp the mouse to the center of the window */
475 if (This->absolute == 0) {
476 This->mapped_center.x = This->win_centerX;
477 This->mapped_center.y = This->win_centerY;
478 MapWindowPoints(This->win, HWND_DESKTOP, &This->mapped_center, 1);
479 TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y);
480 SetCursorPos( This->mapped_center.x, This->mapped_center.y );
481#ifdef MOUSE_HACK
482 This->need_warp = WARP_DONE;
483#else
484 This->need_warp = WARP_STARTED;
485#endif
486 }
487
488 This->acquired = 1;
489 }
490 return DI_OK;
491}
492
493/******************************************************************************
494 * Unacquire : frees the mouse
495 */
496static HRESULT WINAPI SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE2A iface)
497{
498 ICOM_THIS(SysMouseAImpl,iface);
499
500 TRACE("(this=%p)\n",This);
501
502 if (This->acquired)
503 {
504 /* Reinstall previous mouse event handler */
505 if (This->hook) UnhookWindowsHookEx( This->hook );
506 This->hook = 0;
507
508 /* No more locks */
509 current_lock = NULL;
510
511 /* Unacquire device */
512 This->acquired = 0;
513 }
514 else
515 ERR("Unacquiring a not-acquired device !!!\n");
516
517 return DI_OK;
518}
519
520/******************************************************************************
521 * GetDeviceState : returns the "state" of the mouse.
522 *
523 * For the moment, only the "standard" return structure (DIMOUSESTATE) is
524 * supported.
525 */
526static HRESULT WINAPI SysMouseAImpl_GetDeviceState(
527 LPDIRECTINPUTDEVICE2A iface,DWORD len,LPVOID ptr
528) {
529 ICOM_THIS(SysMouseAImpl,iface);
530
531 EnterCriticalSection(&(This->crit));
532 TRACE("(this=%p,0x%08lx,%p): \n",This,len,ptr);
533
534 /* Copy the current mouse state */
535 fill_DataFormat(ptr, &(This->m_state), This->wine_df);
536
537 /* Initialize the buffer when in relative mode */
538 if (This->absolute == 0) {
539 This->m_state.lX = 0;
540 This->m_state.lY = 0;
541 }
542
543#ifndef __WIN32OS2__
544 //SvL: Completely breaks some apps
545 /* Check if we need to do a mouse warping */
546 if (This->need_warp == WARP_NEEDED) {
547 This->mapped_center.x = This->win_centerX;
548 This->mapped_center.y = This->win_centerY;
549 MapWindowPoints(This->win, HWND_DESKTOP, &This->mapped_center, 1);
550 TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y);
551 SetCursorPos( This->mapped_center.x, This->mapped_center.y );
552
553#ifdef MOUSE_HACK
554 This->need_warp = WARP_DONE;
555#else
556 This->need_warp = WARP_STARTED;
557#endif
558 }
559#endif
560
561 LeaveCriticalSection(&(This->crit));
562
563 TRACE("(X: %ld - Y: %ld L: %02x M: %02x R: %02x)\n",
564 This->m_state.lX, This->m_state.lY,
565 This->m_state.rgbButtons[0], This->m_state.rgbButtons[2], This->m_state.rgbButtons[1]);
566
567 return 0;
568}
569
570/******************************************************************************
571 * GetDeviceState : gets buffered input data.
572 */
573static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE2A iface,
574 DWORD dodsize,
575 LPDIDEVICEOBJECTDATA dod,
576 LPDWORD entries,
577 DWORD flags
578) {
579 ICOM_THIS(SysMouseAImpl,iface);
580 DWORD len, nqtail;
581
582 EnterCriticalSection(&(This->crit));
583 TRACE("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx)\n",This,dodsize,*entries,flags);
584
585 len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0)
586 + (This->queue_head - This->queue_tail);
587 if (len > *entries) len = *entries;
588
589 if (dod == NULL) {
590 *entries = len;
591 nqtail = This->queue_tail + len;
592 while (nqtail >= This->queue_len) nqtail -= This->queue_len;
593 } else {
594 if (dodsize != sizeof(DIDEVICEOBJECTDATA)) {
595 ERR("Wrong structure size !\n");
596 LeaveCriticalSection(&(This->crit));
597 return DIERR_INVALIDPARAM;
598 }
599
600 if (len)
601 TRACE("Application retrieving %ld event(s).\n", len);
602
603 *entries = 0;
604 nqtail = This->queue_tail;
605 while (len) {
606 DWORD span = ((This->queue_head < nqtail) ? This->queue_len : This->queue_head)
607 - nqtail;
608 if (span > len) span = len;
609 /* Copy the buffered data into the application queue */
610 memcpy(dod + *entries, This->data_queue + nqtail, span * dodsize);
611 /* Advance position */
612 nqtail += span;
613 if (nqtail >= This->queue_len) nqtail -= This->queue_len;
614 *entries += span;
615 len -= span;
616 }
617 }
618 if (!(flags & DIGDD_PEEK))
619 This->queue_tail = nqtail;
620
621 LeaveCriticalSection(&(This->crit));
622
623#ifndef __WIN32OS2__
624 //SvL: Completely breaks some apps
625 /* Check if we need to do a mouse warping */
626 if (This->need_warp == WARP_NEEDED) {
627 This->mapped_center.x = This->win_centerX;
628 This->mapped_center.y = This->win_centerY;
629 MapWindowPoints(This->win, HWND_DESKTOP, &This->mapped_center, 1);
630 TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y);
631 SetCursorPos( This->mapped_center.x, This->mapped_center.y );
632
633#ifdef MOUSE_HACK
634 This->need_warp = WARP_DONE;
635#else
636 This->need_warp = WARP_STARTED;
637#endif
638 }
639#endif
640 return 0;
641}
642
643/******************************************************************************
644 * SetProperty : change input device properties
645 */
646static HRESULT WINAPI SysMouseAImpl_SetProperty(LPDIRECTINPUTDEVICE2A iface,
647 REFGUID rguid,
648 LPCDIPROPHEADER ph)
649{
650 ICOM_THIS(SysMouseAImpl,iface);
651
652 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
653
654 if (!HIWORD(rguid)) {
655 switch ((DWORD)rguid) {
656 case (DWORD) DIPROP_BUFFERSIZE: {
657 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
658
659 TRACE("buffersize = %ld\n",pd->dwData);
660
661 This->data_queue = (LPDIDEVICEOBJECTDATA)HeapAlloc(GetProcessHeap(),0,
662 pd->dwData * sizeof(DIDEVICEOBJECTDATA));
663 This->queue_head = 0;
664 This->queue_tail = 0;
665 This->queue_len = pd->dwData;
666 break;
667 }
668 case (DWORD) DIPROP_AXISMODE: {
669 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
670 This->absolute = !(pd->dwData);
671 TRACE("Using %s coordinates mode now\n", This->absolute ? "absolute" : "relative");
672 break;
673 }
674 default:
675 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
676 break;
677 }
678 }
679
680 return 0;
681}
682
683/******************************************************************************
684 * GetProperty : get input device properties
685 */
686static HRESULT WINAPI SysMouseAImpl_GetProperty(LPDIRECTINPUTDEVICE2A iface,
687 REFGUID rguid,
688 LPDIPROPHEADER pdiph)
689{
690 ICOM_THIS(SysMouseAImpl,iface);
691
692 TRACE("(this=%p,%s,%p): stub!\n",
693 iface, debugstr_guid(rguid), pdiph);
694
695 if (TRACE_ON(dinput))
696 _dump_DIPROPHEADER(pdiph);
697
698 if (!HIWORD(rguid)) {
699 switch ((DWORD)rguid) {
700 case (DWORD) DIPROP_BUFFERSIZE: {
701 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
702
703 TRACE(" return buffersize = %d\n",This->queue_len);
704 pd->dwData = This->queue_len;
705 break;
706 }
707
708 case (DWORD) DIPROP_RANGE: {
709 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
710
711 if ((pdiph->dwHow == DIPH_BYID) &&
712 ((pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS)) ||
713 (pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS)))) {
714 /* Querying the range of either the X or the Y axis. As I do
715 not know the range, do as if the range were
716 unrestricted...*/
717 pr->lMin = DIPROPRANGE_NOMIN;
718 pr->lMax = DIPROPRANGE_NOMAX;
719 }
720
721 break;
722 }
723
724 default:
725 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
726 break;
727 }
728 }
729
730
731 return DI_OK;
732}
733
734
735
736/******************************************************************************
737 * SetEventNotification : specifies event to be sent on state change
738 */
739static HRESULT WINAPI SysMouseAImpl_SetEventNotification(LPDIRECTINPUTDEVICE2A iface,
740 HANDLE hnd) {
741 ICOM_THIS(SysMouseAImpl,iface);
742
743 TRACE("(this=%p,0x%08lx)\n",This,(DWORD)hnd);
744
745 This->hEvent = hnd;
746
747 return DI_OK;
748}
749
750/******************************************************************************
751 * GetCapabilities : get the device capablitites
752 */
753static HRESULT WINAPI SysMouseAImpl_GetCapabilities(
754 LPDIRECTINPUTDEVICE2A iface,
755 LPDIDEVCAPS lpDIDevCaps)
756{
757 ICOM_THIS(SysMouseAImpl,iface);
758
759 TRACE("(this=%p,%p)\n",This,lpDIDevCaps);
760
761 if (lpDIDevCaps->dwSize == sizeof(DIDEVCAPS)) {
762 lpDIDevCaps->dwFlags = DIDC_ATTACHED;
763 lpDIDevCaps->dwDevType = DIDEVTYPE_MOUSE;
764 lpDIDevCaps->dwAxes = 2;
765 lpDIDevCaps->dwButtons = 3;
766 lpDIDevCaps->dwPOVs = 0;
767 lpDIDevCaps->dwFFSamplePeriod = 0;
768 lpDIDevCaps->dwFFMinTimeResolution = 0;
769 lpDIDevCaps->dwFirmwareRevision = 100;
770 lpDIDevCaps->dwHardwareRevision = 100;
771 lpDIDevCaps->dwFFDriverVersion = 0;
772 } else {
773 /* DirectX 3.0 */
774 FIXME("DirectX 3.0 not supported....\n");
775 }
776
777 return DI_OK;
778}
779
780
781/******************************************************************************
782 * EnumObjects : enumerate the different buttons and axis...
783 */
784static HRESULT WINAPI SysMouseAImpl_EnumObjects(
785 LPDIRECTINPUTDEVICE2A iface,
786 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
787 LPVOID lpvRef,
788 DWORD dwFlags)
789{
790 ICOM_THIS(SysMouseAImpl,iface);
791 DIDEVICEOBJECTINSTANCEA ddoi;
792
793 TRACE("(this=%p,%p,%p,%08lx)\n", This, lpCallback, lpvRef, dwFlags);
794 if (TRACE_ON(dinput)) {
795 DPRINTF(" - flags = ");
796 _dump_EnumObjects_flags(dwFlags);
797 DPRINTF("\n");
798 }
799
800 /* Only the fields till dwFFMaxForce are relevant */
801 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
802
803 /* In a mouse, we have : two relative axis and three buttons */
804 if ((dwFlags == DIDFT_ALL) ||
805 (dwFlags & DIDFT_AXIS)) {
806 /* X axis */
807 ddoi.guidType = GUID_XAxis;
808 ddoi.dwOfs = This->offset_array[WINE_MOUSE_X_POSITION];
809 ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS;
810 strcpy(ddoi.tszName, "X-Axis");
811 _dump_OBJECTINSTANCEA(&ddoi);
812 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
813
814 /* Y axis */
815 ddoi.guidType = GUID_YAxis;
816 ddoi.dwOfs = This->offset_array[WINE_MOUSE_Y_POSITION];
817 ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS;
818 strcpy(ddoi.tszName, "Y-Axis");
819 _dump_OBJECTINSTANCEA(&ddoi);
820 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
821 }
822
823 if ((dwFlags == DIDFT_ALL) ||
824 (dwFlags & DIDFT_BUTTON)) {
825 ddoi.guidType = GUID_Button;
826
827 /* Left button */
828 ddoi.dwOfs = This->offset_array[WINE_MOUSE_L_POSITION];
829 ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_L_BUTTON_INSTANCE) | DIDFT_PSHBUTTON;
830 strcpy(ddoi.tszName, "Left-Button");
831 _dump_OBJECTINSTANCEA(&ddoi);
832 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
833
834 /* Right button */
835 ddoi.dwOfs = This->offset_array[WINE_MOUSE_R_POSITION];
836 ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_R_BUTTON_INSTANCE) | DIDFT_PSHBUTTON;
837 strcpy(ddoi.tszName, "Right-Button");
838 _dump_OBJECTINSTANCEA(&ddoi);
839 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
840
841 /* Middle button */
842 ddoi.dwOfs = This->offset_array[WINE_MOUSE_M_POSITION];
843 ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_M_BUTTON_INSTANCE) | DIDFT_PSHBUTTON;
844 strcpy(ddoi.tszName, "Middle-Button");
845 _dump_OBJECTINSTANCEA(&ddoi);
846 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
847 }
848
849 return DI_OK;
850}
851
852
853static ICOM_VTABLE(IDirectInputDevice2A) SysMouseAvt =
854{
855 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
856 IDirectInputDevice2AImpl_QueryInterface,
857 IDirectInputDevice2AImpl_AddRef,
858 SysMouseAImpl_Release,
859 SysMouseAImpl_GetCapabilities,
860 SysMouseAImpl_EnumObjects,
861 SysMouseAImpl_GetProperty,
862 SysMouseAImpl_SetProperty,
863 SysMouseAImpl_Acquire,
864 SysMouseAImpl_Unacquire,
865 SysMouseAImpl_GetDeviceState,
866 SysMouseAImpl_GetDeviceData,
867 SysMouseAImpl_SetDataFormat,
868 SysMouseAImpl_SetEventNotification,
869 SysMouseAImpl_SetCooperativeLevel,
870 IDirectInputDevice2AImpl_GetObjectInfo,
871 IDirectInputDevice2AImpl_GetDeviceInfo,
872 IDirectInputDevice2AImpl_RunControlPanel,
873 IDirectInputDevice2AImpl_Initialize,
874 IDirectInputDevice2AImpl_CreateEffect,
875 IDirectInputDevice2AImpl_EnumEffects,
876 IDirectInputDevice2AImpl_GetEffectInfo,
877 IDirectInputDevice2AImpl_GetForceFeedbackState,
878 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
879 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
880 IDirectInputDevice2AImpl_Escape,
881 IDirectInputDevice2AImpl_Poll,
882 IDirectInputDevice2AImpl_SendDeviceData,
883};
884
885#if !defined(__STRICT_ANSI__) && defined(__GNUC__)
886# define XCAST(fun) (typeof(SysMouse7Avt.fun))
887#else
888# define XCAST(fun) (void*)
889#endif
890
891static ICOM_VTABLE(IDirectInputDevice7A) SysMouse7Avt =
892{
893 ICOM_MSVTABLE_COMPAT_DummyRTTIVALUE
894 XCAST(QueryInterface)IDirectInputDevice2AImpl_QueryInterface,
895 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
896 XCAST(Release)SysMouseAImpl_Release,
897 XCAST(GetCapabilities)SysMouseAImpl_GetCapabilities,
898 XCAST(EnumObjects)SysMouseAImpl_EnumObjects,
899 XCAST(GetProperty)SysMouseAImpl_GetProperty,
900 XCAST(SetProperty)SysMouseAImpl_SetProperty,
901 XCAST(Acquire)SysMouseAImpl_Acquire,
902 XCAST(Unacquire)SysMouseAImpl_Unacquire,
903 XCAST(GetDeviceState)SysMouseAImpl_GetDeviceState,
904 XCAST(GetDeviceData)SysMouseAImpl_GetDeviceData,
905 XCAST(SetDataFormat)SysMouseAImpl_SetDataFormat,
906 XCAST(SetEventNotification)SysMouseAImpl_SetEventNotification,
907 XCAST(SetCooperativeLevel)SysMouseAImpl_SetCooperativeLevel,
908 XCAST(GetObjectInfo)IDirectInputDevice2AImpl_GetObjectInfo,
909 XCAST(GetDeviceInfo)IDirectInputDevice2AImpl_GetDeviceInfo,
910 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
911 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
912 XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
913 XCAST(EnumEffects)IDirectInputDevice2AImpl_EnumEffects,
914 XCAST(GetEffectInfo)IDirectInputDevice2AImpl_GetEffectInfo,
915 XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
916 XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
917 XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
918 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
919 XCAST(Poll)IDirectInputDevice2AImpl_Poll,
920 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
921 IDirectInputDevice7AImpl_EnumEffectsInFile,
922 IDirectInputDevice7AImpl_WriteEffectToFile
923};
924
925#undef XCAST
Note: See TracBrowser for help on using the repository browser.