Remove local definitions for stuff which is now
[reactos.git] / reactos / lib / dinput / mouse.c
1 /* DirectInput Mouse device
2 *
3 * Copyright 1998 Marcus Meissner
4 * Copyright 1998,1999 Lionel Ulmer
5 * Copyright 2000-2001 TransGaming Technologies Inc.
6 *
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.
11 *
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.
16 *
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 */
21
22 #include "config.h"
23 #include "wine/port.h"
24
25 #include <stdarg.h>
26 #include <string.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "winuser.h"
32 #include "winerror.h"
33 #include "dinput.h"
34
35 #include "dinput_private.h"
36 #include "device_private.h"
37 #include "wine/debug.h"
38 #include "wine/unicode.h"
39
40 #define MOUSE_HACK
41
42 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
43
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
52
53 /* ------------------------------- */
54 /* Wine mouse internal data format */
55 /* ------------------------------- */
56
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
64
65 typedef struct {
66 LONG lX;
67 LONG lY;
68 LONG lZ;
69 BYTE rgbButtons[4];
70 } Wine_InternalMouseData;
71
72 #define WINE_INTERNALMOUSE_NUM_OBJS 6
73
74 static const DIOBJECTDATAFORMAT Wine_InternalMouseObjectFormat[WINE_INTERNALMOUSE_NUM_OBJS] = {
75 { &GUID_XAxis, FIELD_OFFSET(Wine_InternalMouseData, lX),
76 DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS, 0 },
77 { &GUID_YAxis, FIELD_OFFSET(Wine_InternalMouseData, lY),
78 DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS, 0 },
79 { &GUID_ZAxis, FIELD_OFFSET(Wine_InternalMouseData, lZ),
80 DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS, 0 },
81 { &GUID_Button, (FIELD_OFFSET(Wine_InternalMouseData, rgbButtons)) + 0,
82 DIDFT_MAKEINSTANCE(WINE_MOUSE_L_BUTTON_INSTANCE) | DIDFT_PSHBUTTON, 0 },
83 { &GUID_Button, (FIELD_OFFSET(Wine_InternalMouseData, rgbButtons)) + 1,
84 DIDFT_MAKEINSTANCE(WINE_MOUSE_R_BUTTON_INSTANCE) | DIDFT_PSHBUTTON, 0 },
85 { &GUID_Button, (FIELD_OFFSET(Wine_InternalMouseData, rgbButtons)) + 2,
86 DIDFT_MAKEINSTANCE(WINE_MOUSE_M_BUTTON_INSTANCE) | DIDFT_PSHBUTTON, 0 }
87 };
88
89 static const DIDATAFORMAT Wine_InternalMouseFormat = {
90 0, /* dwSize - unused */
91 0, /* dwObjsize - unused */
92 0, /* dwFlags - unused */
93 sizeof(Wine_InternalMouseData),
94 WINE_INTERNALMOUSE_NUM_OBJS, /* dwNumObjs */
95 (LPDIOBJECTDATAFORMAT) Wine_InternalMouseObjectFormat
96 };
97
98 static IDirectInputDevice8AVtbl SysMouseAvt;
99 static IDirectInputDevice8WVtbl SysMouseWvt;
100
101 typedef struct SysMouseImpl SysMouseImpl;
102
103 typedef enum {
104 WARP_DONE, /* Warping has been done */
105 WARP_NEEDED, /* Warping is needed */
106 WARP_STARTED /* Warping has been done, waiting for the warp event */
107 } WARP_STATUS;
108
109 struct SysMouseImpl
110 {
111 LPVOID lpVtbl;
112 DWORD ref;
113 GUID guid;
114
115 IDirectInputImpl *dinput;
116
117 /* The current data format and the conversion between internal
118 and external data formats */
119 DIDATAFORMAT *df;
120 DataFormat *wine_df;
121 int offset_array[WINE_INTERNALMOUSE_NUM_OBJS];
122
123 /* SysMouseAImpl */
124 BYTE absolute;
125 /* Previous position for relative moves */
126 LONG prevX, prevY;
127 /* These are used in case of relative -> absolute transitions */
128 POINT org_coords;
129 HHOOK hook;
130 HWND win;
131 DWORD dwCoopLevel;
132 POINT mapped_center;
133 DWORD win_centerX, win_centerY;
134 LPDIDEVICEOBJECTDATA data_queue;
135 int queue_head, queue_tail, queue_len;
136 BOOL overflow;
137 /* warping: whether we need to move mouse back to middle once we
138 * reach window borders (for e.g. shooters, "surface movement" games) */
139 WARP_STATUS need_warp;
140 int acquired;
141 HANDLE hEvent;
142 CRITICAL_SECTION crit;
143
144 /* This is for mouse reporting. */
145 Wine_InternalMouseData m_state;
146 };
147
148 /* FIXME: This is ugly and not thread safe :/ */
149 static IDirectInputDevice8A* current_lock = NULL;
150
151 /* FIXME: This is ugly but needed on Windows */
152 static int mouse_set = 0;
153
154 static GUID DInput_Wine_Mouse_GUID = { /* 9e573ed8-7734-11d2-8d4a-23903fb6bdf7 */
155 0x9e573ed8,
156 0x7734,
157 0x11d2,
158 {0x8d, 0x4a, 0x23, 0x90, 0x3f, 0xb6, 0xbd, 0xf7}
159 };
160
161 static void fill_mouse_dideviceinstanceA(LPDIDEVICEINSTANCEA lpddi, int version) {
162 DWORD dwSize;
163 DIDEVICEINSTANCEA ddi;
164
165 dwSize = lpddi->dwSize;
166
167 TRACE("%ld %p\n", dwSize, lpddi);
168
169 memset(lpddi, 0, dwSize);
170 memset(&ddi, 0, sizeof(ddi));
171
172 ddi.dwSize = dwSize;
173 ddi.guidInstance = GUID_SysMouse;/* DInput's GUID */
174 ddi.guidProduct = DInput_Wine_Mouse_GUID; /* Vendor's GUID */
175 if (version >= 8)
176 ddi.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
177 else
178 ddi.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
179 strcpy(ddi.tszInstanceName, "Mouse");
180 strcpy(ddi.tszProductName, "Wine Mouse");
181
182 memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
183 }
184
185 static void fill_mouse_dideviceinstanceW(LPDIDEVICEINSTANCEW lpddi, int version) {
186 DWORD dwSize;
187 DIDEVICEINSTANCEW ddi;
188
189 dwSize = lpddi->dwSize;
190
191 TRACE("%ld %p\n", dwSize, lpddi);
192
193 memset(lpddi, 0, dwSize);
194 memset(&ddi, 0, sizeof(ddi));
195
196 ddi.dwSize = dwSize;
197 ddi.guidInstance = GUID_SysMouse;/* DInput's GUID */
198 ddi.guidProduct = DInput_Wine_Mouse_GUID; /* Vendor's GUID */
199 if (version >= 8)
200 ddi.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
201 else
202 ddi.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
203 MultiByteToWideChar(CP_ACP, 0, "Mouse", -1, ddi.tszInstanceName, MAX_PATH);
204 MultiByteToWideChar(CP_ACP, 0, "Wine Mouse", -1, ddi.tszProductName, MAX_PATH);
205
206 memcpy(lpddi, &ddi, (dwSize < sizeof(ddi) ? dwSize : sizeof(ddi)));
207 }
208
209 static BOOL mousedev_enum_deviceA(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, int version, int id)
210 {
211 if (id != 0)
212 return FALSE;
213
214 if ((dwDevType == 0) ||
215 ((dwDevType == DIDEVTYPE_MOUSE) && (version < 8)) ||
216 (((dwDevType == DI8DEVCLASS_POINTER) || (dwDevType == DI8DEVTYPE_MOUSE)) && (version >= 8))) {
217 TRACE("Enumerating the mouse device\n");
218
219 fill_mouse_dideviceinstanceA(lpddi, version);
220
221 return TRUE;
222 }
223
224 return FALSE;
225 }
226
227 static BOOL mousedev_enum_deviceW(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, int version, int id)
228 {
229 if (id != 0)
230 return FALSE;
231
232 if ((dwDevType == 0) ||
233 ((dwDevType == DIDEVTYPE_MOUSE) && (version < 8)) ||
234 (((dwDevType == DI8DEVCLASS_POINTER) || (dwDevType == DI8DEVTYPE_MOUSE)) && (version >= 8))) {
235 TRACE("Enumerating the mouse device\n");
236
237 fill_mouse_dideviceinstanceW(lpddi, version);
238
239 return TRUE;
240 }
241
242 return FALSE;
243 }
244
245 static SysMouseImpl *alloc_device_mouse(REFGUID rguid, LPVOID mvt, IDirectInputImpl *dinput)
246 {
247 int offset_array[WINE_INTERNALMOUSE_NUM_OBJS] = {
248 FIELD_OFFSET(Wine_InternalMouseData, lX),
249 FIELD_OFFSET(Wine_InternalMouseData, lY),
250 FIELD_OFFSET(Wine_InternalMouseData, lZ),
251 FIELD_OFFSET(Wine_InternalMouseData, rgbButtons) + 0,
252 FIELD_OFFSET(Wine_InternalMouseData, rgbButtons) + 1,
253 FIELD_OFFSET(Wine_InternalMouseData, rgbButtons) + 2
254 };
255 SysMouseImpl* newDevice;
256 newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysMouseImpl));
257 newDevice->ref = 1;
258 newDevice->lpVtbl = mvt;
259 #ifndef __REACTOS__
260 InitializeCriticalSection(&(newDevice->crit));
261 #endif
262 memcpy(&(newDevice->guid),rguid,sizeof(*rguid));
263
264 /* Per default, Wine uses its internal data format */
265 newDevice->df = (DIDATAFORMAT *) &Wine_InternalMouseFormat;
266 memcpy(newDevice->offset_array, offset_array, WINE_INTERNALMOUSE_NUM_OBJS * sizeof(int));
267 newDevice->wine_df = HeapAlloc(GetProcessHeap(), 0, sizeof(DataFormat));
268 newDevice->wine_df->size = 0;
269 newDevice->wine_df->internal_format_size = Wine_InternalMouseFormat.dwDataSize;
270 newDevice->wine_df->dt = NULL;
271 newDevice->dinput = dinput;
272
273 return newDevice;
274 }
275
276 static HRESULT mousedev_create_deviceA(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev)
277 {
278 if ((IsEqualGUID(&GUID_SysMouse,rguid)) || /* Generic Mouse */
279 (IsEqualGUID(&DInput_Wine_Mouse_GUID,rguid))) { /* Wine Mouse */
280 if ((riid == NULL) ||
281 IsEqualGUID(&IID_IDirectInputDeviceA,riid) ||
282 IsEqualGUID(&IID_IDirectInputDevice2A,riid) ||
283 IsEqualGUID(&IID_IDirectInputDevice7A,riid) ||
284 IsEqualGUID(&IID_IDirectInputDevice8A,riid)) {
285 *pdev = (IDirectInputDeviceA*) alloc_device_mouse(rguid, &SysMouseAvt, dinput);
286 TRACE("Creating a Mouse device (%p)\n", *pdev);
287 return DI_OK;
288 } else
289 return DIERR_NOINTERFACE;
290 }
291
292 return DIERR_DEVICENOTREG;
293 }
294
295 static HRESULT mousedev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev)
296 {
297 if ((IsEqualGUID(&GUID_SysMouse,rguid)) || /* Generic Mouse */
298 (IsEqualGUID(&DInput_Wine_Mouse_GUID,rguid))) { /* Wine Mouse */
299 if ((riid == NULL) ||
300 IsEqualGUID(&IID_IDirectInputDeviceW,riid) ||
301 IsEqualGUID(&IID_IDirectInputDevice2W,riid) ||
302 IsEqualGUID(&IID_IDirectInputDevice7W,riid) ||
303 IsEqualGUID(&IID_IDirectInputDevice8W,riid)) {
304 *pdev = (IDirectInputDeviceW*) alloc_device_mouse(rguid, &SysMouseWvt, dinput);
305 TRACE("Creating a Mouse device (%p)\n", *pdev);
306 return DI_OK;
307 } else
308 return DIERR_NOINTERFACE;
309 }
310
311 return DIERR_DEVICENOTREG;
312 }
313
314 const struct dinput_device mouse_device = {
315 "Wine mouse driver",
316 mousedev_enum_deviceA,
317 mousedev_enum_deviceW,
318 mousedev_create_deviceA,
319 mousedev_create_deviceW
320 };
321
322 /******************************************************************************
323 * SysMouseA (DInput Mouse support)
324 */
325
326 /******************************************************************************
327 * Release : release the mouse buffer.
328 */
329 static ULONG WINAPI SysMouseAImpl_Release(LPDIRECTINPUTDEVICE8A iface)
330 {
331 SysMouseImpl *This = (SysMouseImpl *)iface;
332 ULONG ref;
333
334 ref = InterlockedDecrement(&(This->ref));
335 if (ref)
336 return ref;
337
338 /* Free the data queue */
339 HeapFree(GetProcessHeap(),0,This->data_queue);
340
341 #ifndef __REACTOS__
342 if (This->hook) {
343 UnhookWindowsHookEx( This->hook );
344 if (This->dwCoopLevel & DISCL_EXCLUSIVE)
345 ShowCursor(TRUE); /* show cursor */
346 }
347 DeleteCriticalSection(&(This->crit));
348 #endif
349
350 #ifdef __REACTOS__
351 if (This->dwCoopLevel & DISCL_EXCLUSIVE)
352 ShowCursor(TRUE); /* show cursor */
353
354 #endif
355 /* Free the DataFormat */
356 if (This->df != &(Wine_InternalMouseFormat)) {
357 HeapFree(GetProcessHeap(), 0, This->df->rgodf);
358 HeapFree(GetProcessHeap(), 0, This->df);
359 }
360
361 HeapFree(GetProcessHeap(),0,This);
362 return 0;
363 }
364
365
366 /******************************************************************************
367 * SetCooperativeLevel : store the window in which we will do our
368 * grabbing.
369 */
370 static HRESULT WINAPI SysMouseAImpl_SetCooperativeLevel(
371 LPDIRECTINPUTDEVICE8A iface,HWND hwnd,DWORD dwflags
372 )
373 {
374 SysMouseImpl *This = (SysMouseImpl *)iface;
375
376 TRACE("(this=%p,0x%08lx,0x%08lx)\n",This,(DWORD)hwnd,dwflags);
377
378 if (TRACE_ON(dinput)) {
379 TRACE(" cooperative level : ");
380 _dump_cooperativelevel_DI(dwflags);
381 }
382
383 /* Store the window which asks for the mouse */
384 if (!hwnd)
385 hwnd = GetDesktopWindow();
386 This->win = hwnd;
387 This->dwCoopLevel = dwflags;
388
389 return DI_OK;
390 }
391
392
393 /******************************************************************************
394 * SetDataFormat : the application can choose the format of the data
395 * the device driver sends back with GetDeviceState.
396 *
397 * For the moment, only the "standard" configuration (c_dfDIMouse) is supported
398 * in absolute and relative mode.
399 */
400 static HRESULT WINAPI SysMouseAImpl_SetDataFormat(
401 LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
402 )
403 {
404 SysMouseImpl *This = (SysMouseImpl *)iface;
405
406 TRACE("(this=%p,%p)\n",This,df);
407
408 _dump_DIDATAFORMAT(df);
409
410 /* Tests under windows show that a call to SetDataFormat always sets the mouse
411 in relative mode whatever the dwFlags value (DIDF_ABSAXIS/DIDF_RELAXIS).
412 To switch in absolute mode, SetProperty must be used. */
413 This->absolute = 0;
414
415 /* Store the new data format */
416 This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
417 memcpy(This->df, df, df->dwSize);
418 This->df->rgodf = HeapAlloc(GetProcessHeap(),0,df->dwNumObjs*df->dwObjSize);
419 memcpy(This->df->rgodf,df->rgodf,df->dwNumObjs*df->dwObjSize);
420
421 /* Prepare all the data-conversion filters */
422 This->wine_df = create_DataFormat(&(Wine_InternalMouseFormat), df, This->offset_array);
423
424 return DI_OK;
425 }
426
427 /* low-level mouse hook */
428 static LRESULT CALLBACK dinput_mouse_hook( int code, WPARAM wparam, LPARAM lparam )
429 {
430 LRESULT ret;
431 MSLLHOOKSTRUCT *hook = (MSLLHOOKSTRUCT *)lparam;
432 SysMouseImpl* This = (SysMouseImpl*) current_lock;
433 DWORD dwCoop;
434 static long last_event = 0;
435 int wdata;
436
437 if (code != HC_ACTION) return CallNextHookEx( This->hook, code, wparam, lparam );
438
439 EnterCriticalSection(&(This->crit));
440 dwCoop = This->dwCoopLevel;
441
442 /* Only allow mouse events every 10 ms.
443 * This is to allow the cursor to start acceleration before
444 * the warps happen. But if it involves a mouse button event we
445 * allow it since we don't want to lose the clicks.
446 */
447 if (((GetCurrentTime() - last_event) < 10)
448 && wparam == WM_MOUSEMOVE)
449 goto end;
450 else last_event = GetCurrentTime();
451
452 /* Mouse moved -> send event if asked */
453 if (This->hEvent)
454 SetEvent(This->hEvent);
455
456 if (wparam == WM_MOUSEMOVE) {
457 if (This->absolute) {
458 if (hook->pt.x != This->prevX)
459 GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x, hook->time, 0);
460 if (hook->pt.y != This->prevY)
461 GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y, hook->time, 0);
462 } else {
463 /* Now, warp handling */
464 if ((This->need_warp == WARP_STARTED) &&
465 (hook->pt.x == This->mapped_center.x) && (hook->pt.y == This->mapped_center.y)) {
466 /* Warp has been done... */
467 This->need_warp = WARP_DONE;
468 goto end;
469 }
470
471 /* Relative mouse input with absolute mouse event : the real fun starts here... */
472 if ((This->need_warp == WARP_NEEDED) ||
473 (This->need_warp == WARP_STARTED)) {
474 if (hook->pt.x != This->prevX)
475 GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->prevX,
476 hook->time, (This->dinput->evsequence)++);
477 if (hook->pt.y != This->prevY)
478 GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->prevY,
479 hook->time, (This->dinput->evsequence)++);
480 } else {
481 /* This is the first time the event handler has been called after a
482 GetDeviceData or GetDeviceState. */
483 if (hook->pt.x != This->mapped_center.x) {
484 GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->mapped_center.x,
485 hook->time, (This->dinput->evsequence)++);
486 This->need_warp = WARP_NEEDED;
487 }
488
489 if (hook->pt.y != This->mapped_center.y) {
490 GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->mapped_center.y,
491 hook->time, (This->dinput->evsequence)++);
492 This->need_warp = WARP_NEEDED;
493 }
494 }
495 }
496
497 This->prevX = hook->pt.x;
498 This->prevY = hook->pt.y;
499
500 if (This->absolute) {
501 This->m_state.lX = hook->pt.x;
502 This->m_state.lY = hook->pt.y;
503 } else {
504 This->m_state.lX = hook->pt.x - This->mapped_center.x;
505 This->m_state.lY = hook->pt.y - This->mapped_center.y;
506 }
507 }
508
509 TRACE(" msg %x pt %ld %ld (W=%d)\n",
510 wparam, hook->pt.x, hook->pt.y, (!This->absolute) && This->need_warp );
511
512 switch(wparam) {
513 case WM_LBUTTONDOWN:
514 GEN_EVENT(This->offset_array[WINE_MOUSE_L_POSITION], 0x80,
515 hook->time, This->dinput->evsequence++);
516 This->m_state.rgbButtons[0] = 0x80;
517 break;
518 case WM_LBUTTONUP:
519 GEN_EVENT(This->offset_array[WINE_MOUSE_L_POSITION], 0x00,
520 hook->time, This->dinput->evsequence++);
521 This->m_state.rgbButtons[0] = 0x00;
522 break;
523 case WM_RBUTTONDOWN:
524 GEN_EVENT(This->offset_array[WINE_MOUSE_R_POSITION], 0x80,
525 hook->time, This->dinput->evsequence++);
526 This->m_state.rgbButtons[1] = 0x80;
527 break;
528 case WM_RBUTTONUP:
529 GEN_EVENT(This->offset_array[WINE_MOUSE_R_POSITION], 0x00,
530 hook->time, This->dinput->evsequence++);
531 This->m_state.rgbButtons[1] = 0x00;
532 break;
533 case WM_MBUTTONDOWN:
534 GEN_EVENT(This->offset_array[WINE_MOUSE_M_POSITION], 0x80,
535 hook->time, This->dinput->evsequence++);
536 This->m_state.rgbButtons[2] = 0x80;
537 break;
538 case WM_MBUTTONUP:
539 GEN_EVENT(This->offset_array[WINE_MOUSE_M_POSITION], 0x00,
540 hook->time, This->dinput->evsequence++);
541 This->m_state.rgbButtons[2] = 0x00;
542 break;
543 case WM_MOUSEWHEEL:
544 wdata = (short)HIWORD(hook->mouseData);
545 GEN_EVENT(This->offset_array[WINE_MOUSE_Z_POSITION], wdata,
546 hook->time, This->dinput->evsequence++);
547 This->m_state.lZ += wdata;
548 break;
549 }
550
551 TRACE("(X: %ld - Y: %ld L: %02x M: %02x R: %02x)\n",
552 This->m_state.lX, This->m_state.lY,
553 This->m_state.rgbButtons[0], This->m_state.rgbButtons[2], This->m_state.rgbButtons[1]);
554
555 end:
556 LeaveCriticalSection(&(This->crit));
557
558 if (dwCoop & DISCL_NONEXCLUSIVE) {
559 /* Pass the events down to previous handlers (e.g. win32 input) */
560 ret = CallNextHookEx( This->hook, code, wparam, lparam );
561 } else {
562 /* Ignore message */
563 ret = 1;
564 }
565 return ret;
566 }
567
568
569 static void dinput_window_check(SysMouseImpl* This) {
570 RECT rect;
571 DWORD centerX, centerY;
572
573 /* make sure the window hasn't moved */
574 GetWindowRect(This->win, &rect);
575 centerX = (rect.right - rect.left) / 2;
576 centerY = (rect.bottom - rect.top ) / 2;
577 if (This->win_centerX != centerX || This->win_centerY != centerY) {
578 This->win_centerX = centerX;
579 This->win_centerY = centerY;
580 }
581 This->mapped_center.x = This->win_centerX;
582 This->mapped_center.y = This->win_centerY;
583 MapWindowPoints(This->win, HWND_DESKTOP, &This->mapped_center, 1);
584 }
585
586
587 /******************************************************************************
588 * Acquire : gets exclusive control of the mouse
589 */
590 static HRESULT WINAPI SysMouseAImpl_Acquire(LPDIRECTINPUTDEVICE8A iface)
591 {
592 SysMouseImpl *This = (SysMouseImpl *)iface;
593 RECT rect;
594 POINT point;
595
596 TRACE("(this=%p)\n",This);
597
598 if (This->acquired)
599 return S_FALSE;
600
601 This->acquired = 1;
602
603 /* Store (in a global variable) the current lock */
604 current_lock = (IDirectInputDevice8A*)This;
605
606 /* Init the mouse state */
607 GetCursorPos( &point );
608 if (This->absolute) {
609 This->m_state.lX = point.x;
610 This->m_state.lY = point.y;
611 This->prevX = point.x;
612 This->prevY = point.y;
613 } else {
614 This->m_state.lX = 0;
615 This->m_state.lY = 0;
616 This->org_coords = point;
617 }
618 This->m_state.lZ = 0;
619 This->m_state.rgbButtons[0] = ((GetKeyState(VK_LBUTTON) & 0x80) ? 0xFF : 0x00);
620 This->m_state.rgbButtons[1] = ((GetKeyState(VK_RBUTTON) & 0x80) ? 0xFF : 0x00);
621 This->m_state.rgbButtons[2] = ((GetKeyState(VK_MBUTTON) & 0x80) ? 0xFF : 0x00);
622
623 /* Install our mouse hook */
624 if (This->dwCoopLevel & DISCL_EXCLUSIVE)
625 ShowCursor(FALSE); /* hide cursor */
626 #ifndef __REACTOS__
627 This->hook = SetWindowsHookExA( WH_MOUSE_LL, dinput_mouse_hook, DINPUT_instance, 0 );
628 #endif
629
630 /* Get the window dimension and find the center */
631 GetWindowRect(This->win, &rect);
632 This->win_centerX = (rect.right - rect.left) / 2;
633 This->win_centerY = (rect.bottom - rect.top ) / 2;
634
635 /* Warp the mouse to the center of the window */
636 if (This->absolute == 0) {
637 This->mapped_center.x = This->win_centerX;
638 This->mapped_center.y = This->win_centerY;
639 MapWindowPoints(This->win, HWND_DESKTOP, &This->mapped_center, 1);
640 TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y);
641 SetCursorPos( This->mapped_center.x, This->mapped_center.y );
642 #ifdef MOUSE_HACK
643 This->need_warp = WARP_DONE;
644 #else
645 This->need_warp = WARP_STARTED;
646 #endif
647 }
648
649 return DI_OK;
650 }
651
652 /******************************************************************************
653 * Unacquire : frees the mouse
654 */
655 static HRESULT WINAPI SysMouseAImpl_Unacquire(LPDIRECTINPUTDEVICE8A iface)
656 {
657 SysMouseImpl *This = (SysMouseImpl *)iface;
658
659 TRACE("(this=%p)\n",This);
660
661 if (0 == This->acquired) {
662 return DI_NOEFFECT;
663 }
664
665 /* Reinstall previous mouse event handler */
666 if (This->hook) {
667 #ifndef __REACTOS__
668 UnhookWindowsHookEx( This->hook );
669 This->hook = 0;
670
671 if (This->dwCoopLevel & DISCL_EXCLUSIVE)
672 ShowCursor(TRUE); /* show cursor */
673 #endif
674 #ifdef __REACTOS__
675 if (This->dwCoopLevel & DISCL_EXCLUSIVE)
676 ShowCursor(TRUE); /* show cursor */
677 #endif
678 }
679
680 /* No more locks */
681 if (current_lock == (IDirectInputDevice8A*) This)
682 current_lock = NULL;
683 else
684 ERR("this(%p) != current_lock(%p)\n", This, current_lock);
685
686 /* Unacquire device */
687 This->acquired = 0;
688
689 /* And put the mouse cursor back where it was at acquire time */
690 if (This->absolute == 0) {
691 TRACE(" warping mouse back to (%ld , %ld)\n", This->org_coords.x, This->org_coords.y);
692 SetCursorPos(This->org_coords.x, This->org_coords.y);
693 }
694
695 return DI_OK;
696 }
697
698 // if you call poll then to getdevicestate
699 // it did not send back right value in windows
700 int poll_mouse=0;
701
702 #ifdef __REACTOS__
703 void getmousesvalue(LPDIRECTINPUTDEVICE8A iface);
704 int filp=0;
705 void getmousesvalue(LPDIRECTINPUTDEVICE8A iface)
706 {
707 static long last_event = 0;
708
709 POINT point;
710 SysMouseImpl *This = (SysMouseImpl *)iface;
711
712 This->m_state.rgbButtons[0] = ((GetKeyState(VK_LBUTTON) & 0x80) ? 0xFF : 0x00);
713 This->m_state.rgbButtons[1] = ((GetKeyState(VK_RBUTTON) & 0x80) ? 0xFF : 0x00);
714 This->m_state.rgbButtons[2] = ((GetKeyState(VK_MBUTTON) & 0x80) ? 0xFF : 0x00);
715 This->m_state.rgbButtons[3] = ((GetKeyState(VK_XBUTTON1) & 0x80) ? 0xFF : 0x00);
716 This->m_state.rgbButtons[4] = ((GetKeyState(VK_XBUTTON2) & 0x80) ? 0xFF : 0x00);
717
718
719
720
721 if (poll_mouse==1) filp=0;
722 if (filp==2) filp=0;
723 if (filp==0) {
724 GetCursorPos( &point );
725
726 if (This->prevX == point.x) This->m_state.lX = 0;
727 else {
728 This->prevX = point.x;
729 This->m_state.lX = point.x - This->org_coords.x;
730 }
731
732 if (This->prevY == point.y) This->m_state.lY = 0;
733 else {
734 This->prevY = point.y;
735 This->m_state.lY = point.y - This->org_coords.y;
736 }
737
738 }
739 else
740 {
741 This->m_state.lX = 0;
742 This->m_state.lY = 0;
743 }
744 filp++;
745
746 // check see if buffer have been set
747
748 }
749
750 #endif
751
752 static HRESULT WINAPI SysMouseAImpl_Poll(LPDIRECTINPUTDEVICE8A iface)
753 {
754 int retValue = DI_OK;
755
756 SysMouseImpl *This = (SysMouseImpl *)iface;
757 if (poll_mouse==0) {
758 retValue=SysMouseAImpl_Acquire(iface);
759 poll_mouse=1;
760 if (retValue!=DI_OK) retValue=DIERR_NOTACQUIRED;
761 else retValue = DI_OK;
762 }
763
764 return retValue;
765 }
766
767
768 /******************************************************************************
769 * GetDeviceState : returns the "state" of the mouse.
770 *
771 * For the moment, only the "standard" return structure (DIMOUSESTATE) is
772 * supported.
773 */
774 static HRESULT WINAPI SysMouseAImpl_GetDeviceState(
775 LPDIRECTINPUTDEVICE8A iface,DWORD len,LPVOID ptr
776 ) {
777 SysMouseImpl *This = (SysMouseImpl *)iface;
778 POINT point;
779
780 #ifndef __REACTOS__
781 EnterCriticalSection(&(This->crit));
782 #endif
783
784 #ifdef __REACTOS__
785 getmousesvalue(iface);
786 #endif
787 TRACE("(this=%p,0x%08lx,%p): \n",This,len,ptr);
788
789 /* Copy the current mouse state */
790 fill_DataFormat(ptr, &(This->m_state), This->wine_df);
791
792
793 // this fix windows bugs when
794 // some program calling on mouse poll
795 if (poll_mouse==1) poll_mouse=0;
796 else {
797 if (This->absolute == 0) {
798 This->m_state.lX = 0;
799 This->m_state.lY = 0;
800 This->m_state.lZ = 0;
801 }
802 }
803
804
805 /* Check if we need to do a mouse warping */
806 if (This->need_warp == WARP_NEEDED) {
807 dinput_window_check(This);
808 TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y);
809 if (mouse_set==0){
810 SetCursorPos( This->mapped_center.x, This->mapped_center.y );
811 mouse_set++;
812 }
813
814 #ifdef MOUSE_HACK
815 This->need_warp = WARP_DONE;
816 #else
817 This->need_warp = WARP_STARTED;
818 #endif
819 }
820
821 #ifndef __REACTOS__
822 LeaveCriticalSection(&(This->crit));
823 #endif
824
825 TRACE("(X: %ld - Y: %ld - Z: %ld L: %02x M: %02x R: %02x)\n",
826 This->m_state.lX, This->m_state.lY, This->m_state.lZ,
827 This->m_state.rgbButtons[0], This->m_state.rgbButtons[2], This->m_state.rgbButtons[1]);
828
829 return DI_OK;
830 }
831
832 /******************************************************************************
833 * GetDeviceState : gets buffered input data.
834 */
835
836
837 static HRESULT WINAPI SysMouseAImpl_GetDeviceData(LPDIRECTINPUTDEVICE8A iface,
838 DWORD dodsize,
839 LPDIDEVICEOBJECTDATA dod,
840 LPDWORD entries,
841 DWORD flags
842 ) {
843 SysMouseImpl *This = (SysMouseImpl *)iface;
844 DWORD len;
845 int nqtail;
846 #ifdef __REACTOS__
847 static int last_event=0;
848 const int size = sizeof(DIDEVICEOBJECTDATA) * 1;
849 int count=0;
850 DWORD count_ent=0;
851 static DWORD time=0;
852 static POINT save_point;
853 static int save_b[5];
854 static int b[5];
855 static POINT point;
856 int calc;
857 int count_button;
858 int add = 0;
859 #endif
860
861
862 TRACE("(%p)->(dods=%ld,entries=%ld,fl=0x%08lx)\n",This,dodsize,*entries,flags);
863
864 #ifdef __REACTOS__
865
866 if (flags != DIGDD_PEEK)
867 {
868 b[0] = ((GetKeyState(VK_LBUTTON) & 0x80) ? 0xFF : 0x00);
869 b[1] = ((GetKeyState(VK_RBUTTON) & 0x80) ? 0xFF : 0x00);
870 b[2] = ((GetKeyState(VK_MBUTTON) & 0x80) ? 0xFF : 0x00);
871 b[3] = ((GetKeyState(VK_XBUTTON1) & 0x80) ? 0xFF : 0x00);
872 b[4] = ((GetKeyState(VK_XBUTTON2) & 0x80) ? 0xFF : 0x00);
873 GetCursorPos( &point );
874 }
875
876 #endif
877
878
879
880
881
882
883
884 if (This->acquired == 0) {
885 WARN(" application tries to get data from an unacquired device !\n");
886 return DIERR_NOTACQUIRED;
887
888 // windows does not get any data if
889 // we do not call manual to mouse Acquire
890 // this is only need if some apps calling on getdevice data direcly
891 // in windows GetdeviceData does always update first the data
892 // then return it.
893 }
894
895
896
897
898
899 #ifdef __REACTOS__
900
901
902 if (*entries == 0) return DIERR_INVALIDPARAM;
903
904 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) {
905 ERR("Wrong structure size !\n");
906 return DIERR_INVALIDPARAM;
907 }
908 if (This->data_queue==NULL) {
909 WARN("No buffer have been set up !\n");
910 return DIERR_NOTINITIALIZED;
911 }
912
913 /* this code are not need it but if we want 100% compatible
914 with ms we should keep it. but the mouse will be choppy
915 in Unreal 2004 Demo
916
917 if (GetTickCount()-time <50) {
918 *entries=0;
919 return DI_OK;
920 }
921 time = GetTickCount();
922 */
923 if (GetTickCount()-time <50)
924 {
925 add=0;
926 }
927 else
928 {
929 add=1;
930 time = GetTickCount();
931 }
932
933
934 for (count=0;count<*entries;count++) {
935
936
937 if (save_point.x != point.x) {
938 dod[count_ent].dwOfs = DIMOFS_X;
939
940 dod[count_ent].dwData = point.x - save_point.x;
941 dod[count_ent].dwTimeStamp = GetTickCount();
942 dod[count_ent].dwSequence = last_event+=add;
943 count_ent++;
944 save_point.x = point.x;
945 }
946
947 else if (save_point.y != point.y) {
948 dod[count_ent].dwOfs = DIMOFS_Y;
949 dod[count_ent].dwData = point.y - save_point.y;
950
951 dod[count_ent].dwTimeStamp = GetTickCount();
952 dod[count_ent].dwSequence = last_event+=add;
953 count_ent++;
954 save_point.y = point.y;
955 }
956
957 else if (save_b[0] != b[0]) {
958 dod[count_ent].dwOfs = DIMOFS_BUTTON0;
959
960 dod[count_ent].dwData = b[0];
961 dod[count_ent].dwTimeStamp = GetTickCount();
962 dod[count_ent].dwSequence = last_event+=add;
963 count_ent++;
964 save_b[0] = b[0];
965 }
966
967 else if (save_b[1] != b[1]) {
968 dod[count_ent].dwOfs = DIMOFS_BUTTON1;
969
970 dod[count_ent].dwData = b[1];
971 dod[count_ent].dwTimeStamp = GetTickCount();
972 dod[count_ent].dwSequence = last_event+=add;
973 count_ent++;
974 save_b[1] = b[1];
975 }
976
977 else if (save_b[2] != b[2]) {
978 dod[count_ent].dwOfs = DIMOFS_BUTTON2;
979
980 dod[count_ent].dwData = b[2];
981 dod[count_ent].dwTimeStamp = GetTickCount();
982 dod[count_ent].dwSequence = last_event+=add;
983 count_ent++;
984 save_b[2] = b[2];
985 }
986
987 else if (save_b[3] != b[3]) {
988 dod[count_ent].dwOfs = DIMOFS_BUTTON3;
989
990 dod[count_ent].dwData = b[3];
991 dod[count_ent].dwTimeStamp = GetTickCount();
992 dod[count_ent].dwSequence = last_event+=add;
993 count_ent++;
994 save_b[3] = b[3];
995 }
996
997
998 } // end for
999
1000
1001 SetCursorPos(point.x, point.y);
1002 *entries = count_ent;
1003 #endif
1004
1005 #ifndef __REACTOS__
1006 EnterCriticalSection(&(This->crit));
1007
1008
1009 // FIXME mouse are bit choppy here.
1010
1011 len = ((This->queue_head < This->queue_tail) ? This->queue_len : 0)
1012 + (This->queue_head - This->queue_tail);
1013 if (len > *entries) len = *entries;
1014
1015 if (dod == NULL) {
1016 if (len)
1017 TRACE("Application discarding %ld event(s).\n", len);
1018
1019 *entries = len;
1020 nqtail = This->queue_tail + len;
1021 while (nqtail >= This->queue_len) nqtail -= This->queue_len;
1022 } else {
1023 if (dodsize < sizeof(DIDEVICEOBJECTDATA_DX3)) {
1024 ERR("Wrong structure size !\n");
1025
1026 LeaveCriticalSection(&(This->crit));
1027
1028 return DIERR_INVALIDPARAM;
1029 }
1030
1031 if (len)
1032 TRACE("Application retrieving %ld event(s).\n", len);
1033
1034 *entries = 0;
1035 nqtail = This->queue_tail;
1036 while (len) {
1037 /* Copy the buffered data into the application queue */
1038 memcpy((char *)dod + *entries * dodsize, This->data_queue + nqtail, dodsize);
1039
1040 /* Advance position */
1041 nqtail++;
1042 if (nqtail >= This->queue_len)
1043 nqtail -= This->queue_len;
1044 (*entries)++;
1045 len--;
1046 }
1047 }
1048 if (!(flags & DIGDD_PEEK))
1049 This->queue_tail = nqtail;
1050
1051 LeaveCriticalSection(&(This->crit));
1052
1053 /* Check if we need to do a mouse warping */
1054
1055
1056 if (This->need_warp == WARP_NEEDED) {
1057 dinput_window_check(This);
1058 TRACE("Warping mouse to %ld - %ld\n", This->mapped_center.x, This->mapped_center.y);
1059 if (mouse_set==0){
1060 SetCursorPos( This->mapped_center.x, This->mapped_center.y );
1061 mouse_set++;
1062 }
1063
1064 #ifdef MOUSE_HACK
1065 This->need_warp = WARP_DONE;
1066 #else
1067 This->need_warp = WARP_STARTED;
1068 #endif
1069 }
1070 #endif
1071 return DI_OK;
1072 }
1073
1074 /******************************************************************************
1075 * SetProperty : change input device properties
1076 */
1077 static HRESULT WINAPI SysMouseAImpl_SetProperty(LPDIRECTINPUTDEVICE8A iface,
1078 REFGUID rguid,
1079 LPCDIPROPHEADER ph)
1080 {
1081 SysMouseImpl *This = (SysMouseImpl *)iface;
1082
1083 TRACE("(this=%p,%s,%p)\n",This,debugstr_guid(rguid),ph);
1084
1085 if (!HIWORD(rguid)) {
1086 switch ((DWORD)rguid) {
1087 case (DWORD) DIPROP_BUFFERSIZE: {
1088 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
1089
1090 TRACE("buffersize = %ld\n",pd->dwData);
1091
1092 This->data_queue = HeapAlloc(GetProcessHeap(),0, pd->dwData * sizeof(DIDEVICEOBJECTDATA));
1093 This->queue_head = 0;
1094 This->queue_tail = 0;
1095 This->queue_len = pd->dwData;
1096 break;
1097 }
1098 case (DWORD) DIPROP_AXISMODE: {
1099 LPCDIPROPDWORD pd = (LPCDIPROPDWORD)ph;
1100 This->absolute = !(pd->dwData);
1101
1102 TRACE("Using %s coordinates mode now\n", This->absolute ? "absolute" : "relative");
1103 break;
1104 }
1105 default:
1106 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
1107 break;
1108 }
1109 }
1110
1111 return DI_OK;
1112 }
1113
1114 /******************************************************************************
1115 * GetProperty : get input device properties
1116 */
1117 static HRESULT WINAPI SysMouseAImpl_GetProperty(LPDIRECTINPUTDEVICE8A iface,
1118 REFGUID rguid,
1119 LPDIPROPHEADER pdiph)
1120 {
1121 SysMouseImpl *This = (SysMouseImpl *)iface;
1122
1123 TRACE("(this=%p,%s,%p)\n",
1124 iface, debugstr_guid(rguid), pdiph);
1125
1126 if (TRACE_ON(dinput))
1127 _dump_DIPROPHEADER(pdiph);
1128
1129 if (!HIWORD(rguid)) {
1130 switch ((DWORD)rguid) {
1131 case (DWORD) DIPROP_BUFFERSIZE: {
1132 LPDIPROPDWORD pd = (LPDIPROPDWORD)pdiph;
1133
1134 TRACE(" return buffersize = %d\n",This->queue_len);
1135 pd->dwData = This->queue_len;
1136 break;
1137 }
1138
1139 case (DWORD) DIPROP_GRANULARITY: {
1140 LPDIPROPDWORD pr = (LPDIPROPDWORD) pdiph;
1141
1142 /* We'll just assume that the app asks about the Z axis */
1143 pr->dwData = WHEEL_DELTA;
1144
1145 break;
1146 }
1147
1148 case (DWORD) DIPROP_RANGE: {
1149 LPDIPROPRANGE pr = (LPDIPROPRANGE) pdiph;
1150
1151 if ((pdiph->dwHow == DIPH_BYID) &&
1152 ((pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS)) ||
1153 (pdiph->dwObj == (DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS)))) {
1154 /* Querying the range of either the X or the Y axis. As I do
1155 not know the range, do as if the range were
1156 unrestricted...*/
1157 pr->lMin = DIPROPRANGE_NOMIN;
1158 pr->lMax = DIPROPRANGE_NOMAX;
1159 }
1160
1161 break;
1162 }
1163
1164 default:
1165 FIXME("Unknown type %ld (%s)\n",(DWORD)rguid,debugstr_guid(rguid));
1166 break;
1167 }
1168 }
1169
1170 return DI_OK;
1171 }
1172
1173
1174
1175 /******************************************************************************
1176 * SetEventNotification : specifies event to be sent on state change
1177 */
1178 static HRESULT WINAPI SysMouseAImpl_SetEventNotification(LPDIRECTINPUTDEVICE8A iface,
1179 HANDLE hnd) {
1180 SysMouseImpl *This = (SysMouseImpl *)iface;
1181
1182 TRACE("(this=%p,0x%08lx)\n",This,(DWORD)hnd);
1183
1184 This->hEvent = hnd;
1185
1186 return DI_OK;
1187 }
1188
1189 /******************************************************************************
1190 * GetCapabilities : get the device capablitites
1191 */
1192 static HRESULT WINAPI SysMouseAImpl_GetCapabilities(
1193 LPDIRECTINPUTDEVICE8A iface,
1194 LPDIDEVCAPS lpDIDevCaps)
1195 {
1196 SysMouseImpl *This = (SysMouseImpl *)iface;
1197 DIDEVCAPS devcaps;
1198
1199 TRACE("(this=%p,%p)\n",This,lpDIDevCaps);
1200
1201 if ((lpDIDevCaps->dwSize != sizeof(DIDEVCAPS)) && (lpDIDevCaps->dwSize != sizeof(DIDEVCAPS_DX3))) {
1202 WARN("invalid parameter\n");
1203 return DIERR_INVALIDPARAM;
1204 }
1205
1206 devcaps.dwSize = lpDIDevCaps->dwSize;
1207 devcaps.dwFlags = DIDC_ATTACHED;
1208 if (This->dinput->version >= 8)
1209 devcaps.dwDevType = DI8DEVTYPE_MOUSE | (DI8DEVTYPEMOUSE_TRADITIONAL << 8);
1210 else
1211 devcaps.dwDevType = DIDEVTYPE_MOUSE | (DIDEVTYPEMOUSE_TRADITIONAL << 8);
1212 devcaps.dwAxes = 3;
1213 devcaps.dwButtons = 3;
1214 devcaps.dwPOVs = 0;
1215 devcaps.dwFFSamplePeriod = 0;
1216 devcaps.dwFFMinTimeResolution = 0;
1217 devcaps.dwFirmwareRevision = 100;
1218 devcaps.dwHardwareRevision = 100;
1219 devcaps.dwFFDriverVersion = 0;
1220
1221 memcpy(lpDIDevCaps, &devcaps, lpDIDevCaps->dwSize);
1222
1223 return DI_OK;
1224 }
1225
1226
1227 /******************************************************************************
1228 * EnumObjects : enumerate the different buttons and axis...
1229 */
1230 static HRESULT WINAPI SysMouseAImpl_EnumObjects(
1231 LPDIRECTINPUTDEVICE8A iface,
1232 LPDIENUMDEVICEOBJECTSCALLBACKA lpCallback,
1233 LPVOID lpvRef,
1234 DWORD dwFlags)
1235 {
1236 SysMouseImpl *This = (SysMouseImpl *)iface;
1237 DIDEVICEOBJECTINSTANCEA ddoi;
1238
1239 TRACE("(this=%p,%p,%p,%08lx)\n", This, lpCallback, lpvRef, dwFlags);
1240 if (TRACE_ON(dinput)) {
1241 TRACE(" - flags = ");
1242 _dump_EnumObjects_flags(dwFlags);
1243 TRACE("\n");
1244 }
1245
1246 /* Only the fields till dwFFMaxForce are relevant */
1247 memset(&ddoi, 0, sizeof(ddoi));
1248 ddoi.dwSize = FIELD_OFFSET(DIDEVICEOBJECTINSTANCEA, dwFFMaxForce);
1249
1250 /* In a mouse, we have : two relative axis and three buttons */
1251 if ((dwFlags == DIDFT_ALL) ||
1252 (dwFlags & DIDFT_AXIS)) {
1253 /* X axis */
1254 ddoi.guidType = GUID_XAxis;
1255 ddoi.dwOfs = This->offset_array[WINE_MOUSE_X_POSITION];
1256 ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS;
1257 strcpy(ddoi.tszName, "X-Axis");
1258 _dump_OBJECTINSTANCEA(&ddoi);
1259 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1260
1261 /* Y axis */
1262 ddoi.guidType = GUID_YAxis;
1263 ddoi.dwOfs = This->offset_array[WINE_MOUSE_Y_POSITION];
1264 ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_Y_AXIS_INSTANCE) | DIDFT_RELAXIS;
1265 strcpy(ddoi.tszName, "Y-Axis");
1266 _dump_OBJECTINSTANCEA(&ddoi);
1267 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1268
1269 /* Z axis */
1270 ddoi.guidType = GUID_ZAxis;
1271 ddoi.dwOfs = This->offset_array[WINE_MOUSE_Z_POSITION];
1272 ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_Z_AXIS_INSTANCE) | DIDFT_RELAXIS;
1273 strcpy(ddoi.tszName, "Z-Axis");
1274 _dump_OBJECTINSTANCEA(&ddoi);
1275 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1276 }
1277
1278 if ((dwFlags == DIDFT_ALL) ||
1279 (dwFlags & DIDFT_BUTTON)) {
1280 ddoi.guidType = GUID_Button;
1281
1282 /* Left button */
1283 ddoi.dwOfs = This->offset_array[WINE_MOUSE_L_POSITION];
1284 ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_L_BUTTON_INSTANCE) | DIDFT_PSHBUTTON;
1285 strcpy(ddoi.tszName, "Left-Button");
1286 _dump_OBJECTINSTANCEA(&ddoi);
1287 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1288
1289 /* Right button */
1290 ddoi.dwOfs = This->offset_array[WINE_MOUSE_R_POSITION];
1291 ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_R_BUTTON_INSTANCE) | DIDFT_PSHBUTTON;
1292 strcpy(ddoi.tszName, "Right-Button");
1293 _dump_OBJECTINSTANCEA(&ddoi);
1294 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1295
1296 /* Middle button */
1297 ddoi.dwOfs = This->offset_array[WINE_MOUSE_M_POSITION];
1298 ddoi.dwType = DIDFT_MAKEINSTANCE(WINE_MOUSE_M_BUTTON_INSTANCE) | DIDFT_PSHBUTTON;
1299 strcpy(ddoi.tszName, "Middle-Button");
1300 _dump_OBJECTINSTANCEA(&ddoi);
1301 if (lpCallback(&ddoi, lpvRef) != DIENUM_CONTINUE) return DI_OK;
1302 }
1303
1304 return DI_OK;
1305 }
1306
1307 static HRESULT WINAPI SysMouseWImpl_EnumObjects(LPDIRECTINPUTDEVICE8W iface, LPDIENUMDEVICEOBJECTSCALLBACKW lpCallback, LPVOID lpvRef,DWORD dwFlags)
1308 {
1309 SysMouseImpl *This = (SysMouseImpl *)iface;
1310
1311 device_enumobjects_AtoWcb_data data;
1312
1313 data.lpCallBack = lpCallback;
1314 data.lpvRef = lpvRef;
1315
1316 return SysMouseAImpl_EnumObjects((LPDIRECTINPUTDEVICE8A) This, (LPDIENUMDEVICEOBJECTSCALLBACKA) DIEnumDevicesCallbackAtoW, (LPVOID) &data, dwFlags);
1317 }
1318
1319 /******************************************************************************
1320 * GetDeviceInfo : get information about a device's identity
1321 */
1322 static HRESULT WINAPI SysMouseAImpl_GetDeviceInfo(
1323 LPDIRECTINPUTDEVICE8A iface,
1324 LPDIDEVICEINSTANCEA pdidi)
1325 {
1326 SysMouseImpl *This = (SysMouseImpl *)iface;
1327 TRACE("(this=%p,%p)\n", This, pdidi);
1328
1329 if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEA)) {
1330 WARN(" dinput3 not supporte yet...\n");
1331 return DI_OK;
1332 }
1333
1334 fill_mouse_dideviceinstanceA(pdidi, This->dinput->version);
1335
1336 return DI_OK;
1337 }
1338
1339 static HRESULT WINAPI SysMouseWImpl_GetDeviceInfo(LPDIRECTINPUTDEVICE8W iface, LPDIDEVICEINSTANCEW pdidi)
1340 {
1341 SysMouseImpl *This = (SysMouseImpl *)iface;
1342 TRACE("(this=%p,%p)\n", This, pdidi);
1343
1344 if (pdidi->dwSize != sizeof(DIDEVICEINSTANCEW)) {
1345 WARN(" dinput3 not supporte yet...\n");
1346 return DI_OK;
1347 }
1348
1349 fill_mouse_dideviceinstanceW(pdidi, This->dinput->version);
1350
1351 return DI_OK;
1352 }
1353
1354
1355 static IDirectInputDevice8AVtbl SysMouseAvt =
1356 {
1357 IDirectInputDevice2AImpl_QueryInterface,
1358 IDirectInputDevice2AImpl_AddRef,
1359 SysMouseAImpl_Release,
1360 SysMouseAImpl_GetCapabilities,
1361 SysMouseAImpl_EnumObjects,
1362 SysMouseAImpl_GetProperty,
1363 SysMouseAImpl_SetProperty,
1364 SysMouseAImpl_Acquire,
1365 SysMouseAImpl_Unacquire,
1366 SysMouseAImpl_GetDeviceState,
1367 SysMouseAImpl_GetDeviceData,
1368 SysMouseAImpl_SetDataFormat,
1369 SysMouseAImpl_SetEventNotification,
1370 SysMouseAImpl_SetCooperativeLevel,
1371 IDirectInputDevice2AImpl_GetObjectInfo,
1372 SysMouseAImpl_GetDeviceInfo,
1373 IDirectInputDevice2AImpl_RunControlPanel,
1374 IDirectInputDevice2AImpl_Initialize,
1375 IDirectInputDevice2AImpl_CreateEffect,
1376 IDirectInputDevice2AImpl_EnumEffects,
1377 IDirectInputDevice2AImpl_GetEffectInfo,
1378 IDirectInputDevice2AImpl_GetForceFeedbackState,
1379 IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1380 IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1381 IDirectInputDevice2AImpl_Escape,
1382 SysMouseAImpl_Poll,
1383 IDirectInputDevice2AImpl_SendDeviceData,
1384 IDirectInputDevice7AImpl_EnumEffectsInFile,
1385 IDirectInputDevice7AImpl_WriteEffectToFile,
1386 IDirectInputDevice8AImpl_BuildActionMap,
1387 IDirectInputDevice8AImpl_SetActionMap,
1388 IDirectInputDevice8AImpl_GetImageInfo
1389 };
1390
1391 #if !defined(__STRICT_ANSI__) && defined(__GNUC__)
1392 # define XCAST(fun) (typeof(SysMouseWvt.fun))
1393 #else
1394 # define XCAST(fun) (void*)
1395 #endif
1396
1397 static IDirectInputDevice8WVtbl SysMouseWvt =
1398 {
1399 IDirectInputDevice2WImpl_QueryInterface,
1400 XCAST(AddRef)IDirectInputDevice2AImpl_AddRef,
1401 XCAST(Release)SysMouseAImpl_Release,
1402 XCAST(GetCapabilities)SysMouseAImpl_GetCapabilities,
1403 SysMouseWImpl_EnumObjects,
1404 XCAST(GetProperty)SysMouseAImpl_GetProperty,
1405 XCAST(SetProperty)SysMouseAImpl_SetProperty,
1406 XCAST(Acquire)SysMouseAImpl_Acquire,
1407 XCAST(Unacquire)SysMouseAImpl_Unacquire,
1408 XCAST(GetDeviceState)SysMouseAImpl_GetDeviceState,
1409 XCAST(GetDeviceData)SysMouseAImpl_GetDeviceData,
1410 XCAST(SetDataFormat)SysMouseAImpl_SetDataFormat,
1411 XCAST(SetEventNotification)SysMouseAImpl_SetEventNotification,
1412 XCAST(SetCooperativeLevel)SysMouseAImpl_SetCooperativeLevel,
1413 IDirectInputDevice2WImpl_GetObjectInfo,
1414 SysMouseWImpl_GetDeviceInfo,
1415 XCAST(RunControlPanel)IDirectInputDevice2AImpl_RunControlPanel,
1416 XCAST(Initialize)IDirectInputDevice2AImpl_Initialize,
1417 XCAST(CreateEffect)IDirectInputDevice2AImpl_CreateEffect,
1418 IDirectInputDevice2WImpl_EnumEffects,
1419 IDirectInputDevice2WImpl_GetEffectInfo,
1420 XCAST(GetForceFeedbackState)IDirectInputDevice2AImpl_GetForceFeedbackState,
1421 XCAST(SendForceFeedbackCommand)IDirectInputDevice2AImpl_SendForceFeedbackCommand,
1422 XCAST(EnumCreatedEffectObjects)IDirectInputDevice2AImpl_EnumCreatedEffectObjects,
1423 XCAST(Escape)IDirectInputDevice2AImpl_Escape,
1424 XCAST(Poll)SysMouseAImpl_Poll,
1425 XCAST(SendDeviceData)IDirectInputDevice2AImpl_SendDeviceData,
1426 IDirectInputDevice7WImpl_EnumEffectsInFile,
1427 IDirectInputDevice7WImpl_WriteEffectToFile,
1428 IDirectInputDevice8WImpl_BuildActionMap,
1429 IDirectInputDevice8WImpl_SetActionMap,
1430 IDirectInputDevice8WImpl_GetImageInfo
1431 };
1432 #undef XCAST