[DInput] Fix RailroadTycoon

Lionel Ulmer lionel.ulmer at free.fr
Mon May 31 14:29:55 CDT 2004


> Now, you're proposing, that would be cool. :-)

Here it is... It's a bit hard to read due to the tabbing, but well, it's a
LOT shorter :-)

         Lionel

-- 
		 Lionel Ulmer - http://www.bbrox.org/
-------------- next part --------------
? dlls/dinput/dinput.dll-UQrvOo.spec.c
Index: dlls/dinput/device.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput/device.c,v
retrieving revision 1.16
diff -u -w -r1.16 device.c
--- dlls/dinput/device.c	7 Oct 2003 03:30:47 -0000	1.16
+++ dlls/dinput/device.c	31 May 2004 19:27:04 -0000
@@ -42,77 +42,171 @@
  *	Various debugging tools
  */
 void _dump_cooperativelevel_DI(DWORD dwFlags) {
+    if (TRACE_ON(dinput)) {
   int   i;
-  const struct {
+	static const struct {
     DWORD       mask;
     const char  *name;
   } flags[] = {
-#define FE(x) { x, #x},
-    FE(DISCL_BACKGROUND)
-    FE(DISCL_EXCLUSIVE)
-    FE(DISCL_FOREGROUND)
+#define FE(x) { x, #x}
+	    FE(DISCL_BACKGROUND),
+	    FE(DISCL_EXCLUSIVE),
+	    FE(DISCL_FOREGROUND),
     FE(DISCL_NONEXCLUSIVE)
 #undef FE
   };
-  for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
+	for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++)
     if (flags[i].mask & dwFlags)
       DPRINTF("%s ",flags[i].name);
   DPRINTF("\n");
 }
+}
 
 void _dump_EnumObjects_flags(DWORD dwFlags) {
+    if (TRACE_ON(dinput)) {
   int   i;
-  const struct {
+	DWORD type, instance;
+	static const struct {
     DWORD       mask;
     const char  *name;
   } flags[] = {
-#define FE(x) { x, #x},
-    FE(DIDFT_ABSAXIS)
-    FE(DIDFT_ALL)
-    FE(DIDFT_AXIS)
-    FE(DIDFT_BUTTON)
-    FE(DIDFT_COLLECTION)
-    FE(DIDFT_FFACTUATOR)
-    FE(DIDFT_FFEFFECTTRIGGER)
-    FE(DIDFT_NOCOLLECTION)
-    FE(DIDFT_NODATA)
+#define FE(x) { x, #x}
+	    FE(DIDFT_RELAXIS),
+	    FE(DIDFT_ABSAXIS),
+	    FE(DIDFT_PSHBUTTON),
+	    FE(DIDFT_TGLBUTTON),
+	    FE(DIDFT_POV),
+	    FE(DIDFT_COLLECTION),
+	    FE(DIDFT_NODATA),	    
+	    FE(DIDFT_FFACTUATOR),
+	    FE(DIDFT_FFEFFECTTRIGGER),
     FE(DIDFT_OUTPUT)
-    FE(DIDFT_POV)
-    FE(DIDFT_PSHBUTTON)
-    FE(DIDFT_RELAXIS)
-    FE(DIDFT_TGLBUTTON)
 #undef FE
   };
-  if (dwFlags == DIDFT_ALL) {
+	type = (dwFlags & 0xFF0000FF);
+	instance = ((dwFlags >> 8) & 0xFFFF);
+	DPRINTF("Type:");
+	if (type == DIDFT_ALL) {
     DPRINTF("DIDFT_ALL");
-    return;
-  }
-  for (i=0;i<sizeof(flags)/sizeof(flags[0]);i++)
-    if (flags[i].mask & dwFlags)
+	} else {
+	    for (i = 0; i < (sizeof(flags) / sizeof(flags[0])); i++) {
+		if (flags[i].mask & type) {
+		    type &= ~flags[i].mask;
       DPRINTF("%s ",flags[i].name);
-  if (dwFlags & DIDFT_INSTANCEMASK)
-    DPRINTF("Instance(%04lx) ", dwFlags >> 8);
+		}
+	    }
+	    if (type) {
+		DPRINTF(" (unhandled: %08lx)", type);
+	    }
+	}
+	DPRINTF(" / Instance: ");
+	if (instance == ((DIDFT_ANYINSTANCE >> 8) & 0xFFFF)) {
+	    DPRINTF("DIDFT_ANYINSTANCE");
+	} else {
+	    DPRINTF("%3ld", instance);
+	}
+    }
 }
 
 void _dump_DIPROPHEADER(DIPROPHEADER *diph) {
+    if (TRACE_ON(dinput)) {
   DPRINTF("  - dwObj = 0x%08lx\n", diph->dwObj);
   DPRINTF("  - dwHow = %s\n",
 	  ((diph->dwHow == DIPH_DEVICE) ? "DIPH_DEVICE" :
 	   ((diph->dwHow == DIPH_BYOFFSET) ? "DIPH_BYOFFSET" :
 	    ((diph->dwHow == DIPH_BYID)) ? "DIPH_BYID" : "unknown")));
 }
+}
 
 void _dump_OBJECTINSTANCEA(DIDEVICEOBJECTINSTANCEA *ddoi) {
   if (TRACE_ON(dinput)) {
-    DPRINTF("    - enumerating : %s - %2ld - 0x%08lx - %s\n",
-	    debugstr_guid(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, ddoi->tszName);
+	DPRINTF("    - enumerating : %s ('%s') - %2ld - 0x%08lx - %s\n",
+		debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, ddoi->tszName);
   }
 }
 
 void _dump_OBJECTINSTANCEW(DIDEVICEOBJECTINSTANCEW *ddoi) {
   if (TRACE_ON(dinput)) {
-    DPRINTF("    - enumerating : %s - %2ld - 0x%08lx - %s\n",
-	    debugstr_guid(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, debugstr_w(ddoi->tszName));
+	DPRINTF("    - enumerating : %s ('%s'), - %2ld - 0x%08lx - %s\n",
+		debugstr_guid(&ddoi->guidType), _dump_dinput_GUID(&ddoi->guidType), ddoi->dwOfs, ddoi->dwType, debugstr_w(ddoi->tszName));
+    }
+}
+
+/* This function is a helper to convert a GUID into any possible DInput GUID out there */
+const char *_dump_dinput_GUID(const GUID *guid) {
+    int i;
+    static const struct {
+	const GUID *guid;
+	const char *name;
+    } guids[] = {
+#define FE(x) { &x, #x}
+	FE(GUID_XAxis),
+	FE(GUID_YAxis),
+	FE(GUID_ZAxis),
+	FE(GUID_RxAxis),
+	FE(GUID_RyAxis),
+	FE(GUID_RzAxis),
+	FE(GUID_Slider),
+	FE(GUID_Button),
+	FE(GUID_Key),
+	FE(GUID_POV),
+	FE(GUID_Unknown),
+	FE(GUID_SysMouse),
+	FE(GUID_SysKeyboard),
+	FE(GUID_Joystick),
+	FE(GUID_ConstantForce),
+	FE(GUID_RampForce),
+	FE(GUID_Square),
+	FE(GUID_Sine),
+	FE(GUID_Triangle),
+	FE(GUID_SawtoothUp),
+	FE(GUID_SawtoothDown),
+	FE(GUID_Spring),
+	FE(GUID_Damper),
+	FE(GUID_Inertia),
+	FE(GUID_Friction),
+	FE(GUID_CustomForce)
+#undef FE
+    };
+    if (guid == NULL)
+	return "null GUID";
+    for (i = 0; i < (sizeof(guids) / sizeof(guids[0])); i++) {
+	if (IsEqualGUID(guids[i].guid, guid)) {
+	    return guids[i].name;
+	}
+    }
+    return "Unknown GUID";
+}
+
+void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) {
+    int i;
+
+    TRACE("Dumping DIDATAFORMAT structure:\n");
+    TRACE("  - dwSize: %ld\n", df->dwSize);
+    if (df->dwSize != sizeof(DIDATAFORMAT)) {
+	WARN("Non-standard DIDATAFORMAT structure size (%ld instead of %d).\n", df->dwSize, sizeof(DIDATAFORMAT));
+    }
+    TRACE("  - dwObjsize: %ld\n", df->dwObjSize);
+    if (df->dwObjSize != sizeof(DIOBJECTDATAFORMAT)) {
+	WARN("Non-standard DIOBJECTDATAFORMAT structure size (%ld instead of %d).\n", df->dwObjSize, sizeof(DIOBJECTDATAFORMAT));
+    }
+    TRACE("  - dwFlags: 0x%08lx (", df->dwFlags);
+    switch (df->dwFlags) {
+        case DIDF_ABSAXIS: TRACE("DIDF_ABSAXIS"); break;
+	case DIDF_RELAXIS: TRACE("DIDF_RELAXIS"); break;
+	default: TRACE("unknown"); break;
+    }
+    TRACE(")\n");
+    TRACE("  - dwDataSize: %ld\n", df->dwDataSize);
+    TRACE("  - dwNumObjs: %ld\n", df->dwNumObjs);
+    
+    for (i = 0; i < df->dwNumObjs; i++) {
+	TRACE("  - Object %d:\n", i);
+	TRACE("      * GUID: %s ('%s')\n", debugstr_guid(df->rgodf[i].pguid), _dump_dinput_GUID(df->rgodf[i].pguid));
+	TRACE("      * dwOfs: %ld\n", df->rgodf[i].dwOfs);
+	TRACE("      * dwType: 0x%08lx\n", df->rgodf[i].dwType);
+	TRACE("        "); _dump_EnumObjects_flags(df->rgodf[i].dwType); TRACE("\n");
+	TRACE("      * dwFlags: 0x%08lx\n", df->rgodf[i].dwFlags);
   }
 }
 
@@ -149,6 +243,7 @@
 
 	default:
 	  memcpy((out_c + df->dt[i].offset_out), (in_c + df->dt[i].offset_in), df->dt[i].size);
+			break;
 	}
       } else {
 	switch (df->dt[i].size) {
@@ -172,13 +267,14 @@
 
 	default:
 	  memset((out_c + df->dt[i].offset_out), df->dt[i].size, 0);
+			break;
 	}
       }
     }
   }
 }
 
-DataFormat *create_DataFormat(DIDATAFORMAT *wine_format, LPCDIDATAFORMAT asked_format, int *offset) {
+DataFormat *create_DataFormat(const DIDATAFORMAT *wine_format, LPCDIDATAFORMAT asked_format, int *offset) {
   DataFormat *ret;
   DataTransform *dt;
   int i, j;
@@ -202,22 +298,36 @@
       if (done[j] == 1)
 	continue;
 
-      if (((asked_format->rgodf[j].pguid == NULL) || (IsEqualGUID(wine_format->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
+	    if (/* Check if the application either requests any GUID and if not, it if matches
+		 * the GUID of the Wine object.
+		 */
+		((asked_format->rgodf[j].pguid == NULL) ||
+		 (IsEqualGUID(wine_format->rgodf[i].pguid, asked_format->rgodf[j].pguid)))
 	  &&
-	  (wine_format->rgodf[i].dwType & asked_format->rgodf[j].dwType)) {
+		(/* Then check if it accepts any instance id, and if not, if it matches Wine's
+		  * instance id.
+		  */
+		 ((asked_format->rgodf[j].dwType & 0x00FFFF00) == DIDFT_ANYINSTANCE) ||
+		 (DIDFT_GETINSTANCE(wine_format->rgodf[i].dwType) == DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType)))) {
 
 	done[j] = 1;
 
 	TRACE("Matching : \n");
-	TRACE("   - Asked (%d) : %s - Ofs = %3ld - (Type = 0x%02x | Instance = %04x)\n",
-	      j, debugstr_guid(asked_format->rgodf[j].pguid),
-	      asked_format->rgodf[j].dwOfs,
-	      DIDFT_GETTYPE(asked_format->rgodf[j].dwType), DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType));
-
-	TRACE("   - Wine  (%d) : %s - Ofs = %3ld - (Type = 0x%02x | Instance = %04x)\n",
-	      j, debugstr_guid(wine_format->rgodf[i].pguid),
-	      wine_format->rgodf[i].dwOfs,
-	      DIDFT_GETTYPE(wine_format->rgodf[i].dwType), DIDFT_GETINSTANCE(wine_format->rgodf[i].dwType));
+		TRACE("   - Asked (%d) :\n", j);
+		TRACE("       * GUID: %s ('%s')\n",
+		      debugstr_guid(asked_format->rgodf[j].pguid),
+		      _dump_dinput_GUID(asked_format->rgodf[j].pguid));
+		TRACE("       * Offset: %3ld\n", asked_format->rgodf[j].dwOfs);
+		TRACE("       * dwType: %08lx\n", asked_format->rgodf[j].dwType);
+		TRACE("         "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
+		
+		TRACE("   - Wine  (%d) :\n", j);
+		TRACE("       * GUID: %s ('%s')\n",
+		      debugstr_guid(wine_format->rgodf[j].pguid),
+		      _dump_dinput_GUID(wine_format->rgodf[j].pguid));
+		TRACE("       * Offset: %3ld\n", wine_format->rgodf[j].dwOfs);
+		TRACE("       * dwType: %08lx\n", wine_format->rgodf[j].dwType);
+		TRACE("         "); _dump_EnumObjects_flags(wine_format->rgodf[j].dwType); TRACE("\n");
 
 	if (wine_format->rgodf[i].dwType & DIDFT_BUTTON)
 	  dt[index].size = sizeof(BYTE);
@@ -243,11 +353,13 @@
   TRACE("Setting to default value :\n");
   for (j = 0; j < asked_format->dwNumObjs; j++) {
     if (done[j] == 0) {
-      TRACE(" - Asked (%d) : %s - Ofs = %3ld - (Type = 0x%02x | Instance = %04x)\n",
-	    j, debugstr_guid(asked_format->rgodf[j].pguid),
-	    asked_format->rgodf[j].dwOfs,
-	    DIDFT_GETTYPE(asked_format->rgodf[j].dwType), DIDFT_GETINSTANCE(asked_format->rgodf[j].dwType));
-
+	    TRACE("   - Asked (%d) :\n", j);
+	    TRACE("       * GUID: %s ('%s')\n",
+		  debugstr_guid(asked_format->rgodf[j].pguid),
+		  _dump_dinput_GUID(asked_format->rgodf[j].pguid));
+	    TRACE("       * Offset: %3ld\n", asked_format->rgodf[j].dwOfs);
+	    TRACE("       * dwType: %08lx\n", asked_format->rgodf[j].dwType);
+	    TRACE("         "); _dump_EnumObjects_flags(asked_format->rgodf[j].dwType); TRACE("\n");
 
       if (asked_format->rgodf[j].dwType & DIDFT_BUTTON)
 	dt[index].size = sizeof(BYTE);
@@ -316,23 +428,12 @@
 HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(
 	LPDIRECTINPUTDEVICE8A iface,LPCDIDATAFORMAT df
 ) {
-  int i;
   ICOM_THIS(IDirectInputDevice2AImpl,iface);
 
   TRACE("(this=%p,%p)\n",This,df);
 
-  TRACE("df.dwSize=%ld\n",df->dwSize);
-  TRACE("(df.dwObjsize=%ld)\n",df->dwObjSize);
-  TRACE("(df.dwFlags=0x%08lx)\n",df->dwFlags);
-  TRACE("(df.dwDataSize=%ld)\n",df->dwDataSize);
-  TRACE("(df.dwNumObjs=%ld)\n",df->dwNumObjs);
+    _dump_DIDATAFORMAT(df);
 
-  for (i=0;i<df->dwNumObjs;i++) {
-    TRACE("df.rgodf[%d].guid %s\n",i,debugstr_guid(df->rgodf[i].pguid));
-    TRACE("df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
-    TRACE("dwType 0x%02x,dwInstance %d\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
-    TRACE("df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
-  }
   return DI_OK;
 }
 
@@ -514,6 +615,7 @@
 
 	return DI_OK;
 }
+
 HRESULT WINAPI IDirectInputDevice2WImpl_GetDeviceInfo(
 	LPDIRECTINPUTDEVICE8W iface,
 	LPDIDEVICEINSTANCEW pdidi)
Index: dlls/dinput/device_private.h
===================================================================
RCS file: /home/wine/wine/dlls/dinput/device_private.h,v
retrieving revision 1.6
diff -u -w -r1.6 device_private.h
--- dlls/dinput/device_private.h	5 Sep 2003 23:08:40 -0000	1.6
+++ dlls/dinput/device_private.h	31 May 2004 19:27:04 -0000
@@ -49,7 +49,7 @@
   DataTransform *dt;
 } DataFormat;
 extern void fill_DataFormat(void *out, void *in, DataFormat *df) ;
-extern DataFormat *create_DataFormat(DIDATAFORMAT *wine_format, LPCDIDATAFORMAT asked_format, int *offset) ;
+extern DataFormat *create_DataFormat(const DIDATAFORMAT *wine_format, LPCDIDATAFORMAT asked_format, int *offset) ;
 
 /* Used to fill events in the queue */
 #define GEN_EVENT(offset,data,xtime,seq)					\
@@ -91,6 +91,8 @@
 extern void _dump_DIPROPHEADER(DIPROPHEADER *diph) ;
 extern void _dump_OBJECTINSTANCEA(DIDEVICEOBJECTINSTANCEA *ddoi) ;
 extern void _dump_OBJECTINSTANCEW(DIDEVICEOBJECTINSTANCEW *ddoi) ;
+extern void _dump_DIDATAFORMAT(const DIDATAFORMAT *df) ;
+extern const char *_dump_dinput_GUID(const GUID *guid) ;
 
 /* And the stubs */
 extern HRESULT WINAPI IDirectInputDevice2AImpl_SetDataFormat(
Index: dlls/dinput/joystick_linux.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput/joystick_linux.c,v
retrieving revision 1.3
diff -u -w -r1.3 joystick_linux.c
--- dlls/dinput/joystick_linux.c	27 May 2004 01:54:43 -0000	1.3
+++ dlls/dinput/joystick_linux.c	31 May 2004 19:27:04 -0000
@@ -258,22 +258,10 @@
 )
 {
   ICOM_THIS(JoystickImpl,iface);
-  int i;
 
   TRACE("(this=%p,%p)\n",This,df);
 
-  TRACE("(df.dwSize=%ld)\n",df->dwSize);
-  TRACE("(df.dwObjsize=%ld)\n",df->dwObjSize);
-  TRACE("(df.dwFlags=0x%08lx)\n",df->dwFlags);
-  TRACE("(df.dwDataSize=%ld)\n",df->dwDataSize);
-  TRACE("(df.dwNumObjs=%ld)\n",df->dwNumObjs);
-
-  for (i=0;i<df->dwNumObjs;i++) {
-    TRACE("df.rgodf[%d].guid %s (%p)\n",i,debugstr_guid(df->rgodf[i].pguid), df->rgodf[i].pguid);
-    TRACE("df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
-    TRACE("dwType 0x%02x,dwInstance %d\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
-    TRACE("df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
-  }
+  _dump_DIDATAFORMAT(df);
 
   /* Store the new data format */
   This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
Index: dlls/dinput/joystick_linuxinput.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput/joystick_linuxinput.c,v
retrieving revision 1.4
diff -u -w -r1.4 joystick_linuxinput.c
--- dlls/dinput/joystick_linuxinput.c	27 May 2004 01:54:43 -0000	1.4
+++ dlls/dinput/joystick_linuxinput.c	31 May 2004 19:27:04 -0000
@@ -349,22 +349,10 @@
 )
 {
   ICOM_THIS(JoystickImpl,iface);
-  int i;
 
   TRACE("(this=%p,%p)\n",This,df);
 
-  TRACE("(df.dwSize=%ld)\n",df->dwSize);
-  TRACE("(df.dwObjsize=%ld)\n",df->dwObjSize);
-  TRACE("(df.dwFlags=0x%08lx)\n",df->dwFlags);
-  TRACE("(df.dwDataSize=%ld)\n",df->dwDataSize);
-  TRACE("(df.dwNumObjs=%ld)\n",df->dwNumObjs);
-
-  for (i=0;i<df->dwNumObjs;i++) {
-    TRACE("df.rgodf[%d].guid %s (%p)\n",i,debugstr_guid(df->rgodf[i].pguid), df->rgodf[i].pguid);
-    TRACE("df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
-    TRACE("dwType 0x%02x,dwInstance %d\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
-    TRACE("df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
-  }
+  _dump_DIDATAFORMAT(df);
 
   /* Store the new data format */
   This->df = HeapAlloc(GetProcessHeap(),0,df->dwSize);
Index: dlls/dinput/mouse.c
===================================================================
RCS file: /home/wine/wine/dlls/dinput/mouse.c,v
retrieving revision 1.1
diff -u -w -r1.1 mouse.c
--- dlls/dinput/mouse.c	12 Feb 2004 23:28:00 -0000	1.1
+++ dlls/dinput/mouse.c	31 May 2004 19:27:05 -0000
@@ -42,12 +42,13 @@
 WINE_DEFAULT_DEBUG_CHANNEL(dinput);
 
 /* Wine mouse driver object instances */
-#define WINE_MOUSE_X_AXIS_INSTANCE 0x0001
-#define WINE_MOUSE_Y_AXIS_INSTANCE 0x0002
-#define WINE_MOUSE_Z_AXIS_INSTANCE 0x0004
-#define WINE_MOUSE_L_BUTTON_INSTANCE 0x0008
-#define WINE_MOUSE_R_BUTTON_INSTANCE 0x0010
-#define WINE_MOUSE_M_BUTTON_INSTANCE 0x0020
+#define WINE_MOUSE_X_AXIS_INSTANCE   0
+#define WINE_MOUSE_Y_AXIS_INSTANCE   1
+#define WINE_MOUSE_Z_AXIS_INSTANCE   2
+#define WINE_MOUSE_L_BUTTON_INSTANCE 0
+#define WINE_MOUSE_R_BUTTON_INSTANCE 1
+#define WINE_MOUSE_M_BUTTON_INSTANCE 2
+#define WINE_MOUSE_D_BUTTON_INSTANCE 3
 
 /* ------------------------------- */
 /* Wine mouse internal data format */
@@ -70,7 +71,7 @@
 
 #define WINE_INTERNALMOUSE_NUM_OBJS 6
 
-static DIOBJECTDATAFORMAT Wine_InternalMouseObjectFormat[WINE_INTERNALMOUSE_NUM_OBJS] = {
+static const DIOBJECTDATAFORMAT Wine_InternalMouseObjectFormat[WINE_INTERNALMOUSE_NUM_OBJS] = {
   { &GUID_XAxis,   FIELD_OFFSET(Wine_InternalMouseData, lX),
       DIDFT_MAKEINSTANCE(WINE_MOUSE_X_AXIS_INSTANCE) | DIDFT_RELAXIS, 0 },
   { &GUID_YAxis,   FIELD_OFFSET(Wine_InternalMouseData, lY),
@@ -85,13 +86,13 @@
       DIDFT_MAKEINSTANCE(WINE_MOUSE_M_BUTTON_INSTANCE) | DIDFT_PSHBUTTON, 0 }
 };
 
-static DIDATAFORMAT Wine_InternalMouseFormat = {
+static const DIDATAFORMAT Wine_InternalMouseFormat = {
   0, /* dwSize - unused */
   0, /* dwObjsize - unused */
   0, /* dwFlags - unused */
   sizeof(Wine_InternalMouseData),
   WINE_INTERNALMOUSE_NUM_OBJS, /* dwNumObjs */
-  Wine_InternalMouseObjectFormat
+    (LPDIOBJECTDATAFORMAT) Wine_InternalMouseObjectFormat
 };
 
 static ICOM_VTABLE(IDirectInputDevice8A) SysMouseAvt;
@@ -100,9 +101,9 @@
 typedef struct SysMouseImpl SysMouseImpl;
 
 typedef enum {
+    WARP_DONE,   /* Warping has been done */
   WARP_NEEDED,  /* Warping is needed */
-  WARP_STARTED, /* Warping has been done, waiting for the warp event */
-  WARP_DONE     /* Warping has been done */
+    WARP_STARTED /* Warping has been done, waiting for the warp event */
 } WARP_STATUS;
 
 struct SysMouseImpl
@@ -115,7 +116,7 @@
 
 	/* The current data format and the conversion between internal
 	   and external data formats */
-	LPDIDATAFORMAT			df;
+    DIDATAFORMAT	           *df;
 	DataFormat                     *wine_df;
         int                             offset_array[WINE_INTERNALMOUSE_NUM_OBJS];
 
@@ -123,6 +124,8 @@
         BYTE                            absolute;
         /* Previous position for relative moves */
         LONG				prevX, prevY;
+    /* These are used in case of relative -> absolute transitions */
+    POINT                           org_coords;
         HHOOK                           hook;
         HWND				win;
         DWORD				dwCoopLevel;
@@ -247,7 +250,7 @@
     memcpy(&(newDevice->guid),rguid,sizeof(*rguid));
 
     /* Per default, Wine uses its internal data format */
-    newDevice->df = &Wine_InternalMouseFormat;
+    newDevice->df = (DIDATAFORMAT *) &Wine_InternalMouseFormat;
     memcpy(newDevice->offset_array, offset_array, WINE_INTERNALMOUSE_NUM_OBJS * sizeof(int));
     newDevice->wine_df = (DataFormat *) HeapAlloc(GetProcessHeap(), 0, sizeof(DataFormat));
     newDevice->wine_df->size = 0;
@@ -381,23 +384,10 @@
 )
 {
   ICOM_THIS(SysMouseImpl,iface);
-  int i;
 
   TRACE("(this=%p,%p)\n",This,df);
 
-  TRACE("(df.dwSize=%ld)\n",df->dwSize);
-  TRACE("(df.dwObjsize=%ld)\n",df->dwObjSize);
-  TRACE("(df.dwFlags=0x%08lx)\n",df->dwFlags);
-  TRACE("(df.dwDataSize=%ld)\n",df->dwDataSize);
-  TRACE("(df.dwNumObjs=%ld)\n",df->dwNumObjs);
-
-  for (i=0;i<df->dwNumObjs;i++) {
-
-    TRACE("df.rgodf[%d].guid %s (%p)\n",i, debugstr_guid(df->rgodf[i].pguid), df->rgodf[i].pguid);
-    TRACE("df.rgodf[%d].dwOfs %ld\n",i,df->rgodf[i].dwOfs);
-    TRACE("dwType 0x%02x,dwInstance %d\n",DIDFT_GETTYPE(df->rgodf[i].dwType),DIDFT_GETINSTANCE(df->rgodf[i].dwType));
-    TRACE("df.rgodf[%d].dwFlags 0x%08lx\n",i,df->rgodf[i].dwFlags);
-  }
+    _dump_DIDATAFORMAT(df);
 
   /* Tests under windows show that a call to SetDataFormat always sets the mouse
      in relative mode whatever the dwFlags value (DIDF_ABSAXIS/DIDF_RELAXIS).
@@ -464,19 +454,23 @@
 	  if ((This->need_warp == WARP_NEEDED) ||
 	      (This->need_warp == WARP_STARTED)) {
 	    if (hook->pt.x != This->prevX)
-	      GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->prevX, hook->time, (This->dinput->evsequence)++);
+		    GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->prevX,
+			      hook->time, (This->dinput->evsequence)++);
 	    if (hook->pt.y != This->prevY)
-	      GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->prevY, hook->time, (This->dinput->evsequence)++);
+		    GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->prevY,
+			      hook->time, (This->dinput->evsequence)++);
 	  } else {
 	    /* This is the first time the event handler has been called after a
 	       GetDeviceData or GetDeviceState. */
 	    if (hook->pt.x != This->mapped_center.x) {
-	      GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->mapped_center.x, hook->time, (This->dinput->evsequence)++);
+		    GEN_EVENT(This->offset_array[WINE_MOUSE_X_POSITION], hook->pt.x - This->mapped_center.x,
+			      hook->time, (This->dinput->evsequence)++);
 	      This->need_warp = WARP_NEEDED;
 	    }
 
 	    if (hook->pt.y != This->mapped_center.y) {
-	      GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->mapped_center.y, hook->time, (This->dinput->evsequence)++);
+		    GEN_EVENT(This->offset_array[WINE_MOUSE_Y_POSITION], hook->pt.y - This->mapped_center.y,
+			      hook->time, (This->dinput->evsequence)++);
 	      This->need_warp = WARP_NEEDED;
 	    }
 	  }
@@ -497,8 +491,7 @@
     TRACE(" msg %x pt %ld %ld (W=%d)\n",
           wparam, hook->pt.x, hook->pt.y, (!This->absolute) && This->need_warp );
 
-    switch(wparam)
-    {
+    switch(wparam) {
     case WM_LBUTTONDOWN:
         GEN_EVENT(This->offset_array[WINE_MOUSE_L_POSITION], 0xFF,
                   hook->time, This->dinput->evsequence++);
@@ -544,17 +537,18 @@
 end:
   LeaveCriticalSection(&(This->crit));
 
-  if (dwCoop & DISCL_NONEXCLUSIVE)
-  { /* pass the events down to previous handlers (e.g. win32 input) */
+    if (dwCoop & DISCL_NONEXCLUSIVE) {
+	/* Pass the events down to previous handlers (e.g. win32 input) */
       ret = CallNextHookEx( This->hook, code, wparam, lparam );
+    } else {
+	/* Ignore message */
+	ret = 1;
   }
-  else ret = 1;  /* ignore message */
   return ret;
 }
 
 
-static void dinput_window_check(SysMouseImpl* This)
-{
+static void dinput_window_check(SysMouseImpl* This) {
   RECT rect;
   DWORD centerX, centerY;
 
@@ -589,8 +583,8 @@
     current_lock = (IDirectInputDevice8A*)This;
 
     /* Init the mouse state */
-    if (This->absolute) {
       GetCursorPos( &point );
+	if (This->absolute) {
       This->m_state.lX = point.x;
       This->m_state.lY = point.y;
       This->prevX = point.x;
@@ -598,11 +592,12 @@
     } else {
       This->m_state.lX = 0;
       This->m_state.lY = 0;
+	    This->org_coords = point;
     }
     This->m_state.lZ = 0;
-    This->m_state.rgbButtons[0] = (GetKeyState(VK_LBUTTON) ? 0xFF : 0x00);
-    This->m_state.rgbButtons[1] = (GetKeyState(VK_MBUTTON) ? 0xFF : 0x00);
-    This->m_state.rgbButtons[2] = (GetKeyState(VK_RBUTTON) ? 0xFF : 0x00);
+	This->m_state.rgbButtons[0] = ((GetKeyState(VK_LBUTTON) & 0x80) ? 0xFF : 0x00);
+	This->m_state.rgbButtons[1] = ((GetKeyState(VK_RBUTTON) & 0x80) ? 0xFF : 0x00);
+	This->m_state.rgbButtons[2] = ((GetKeyState(VK_MBUTTON) & 0x80) ? 0xFF : 0x00);
 
     /* Install our mouse hook */
     if (This->dwCoopLevel & DISCL_EXCLUSIVE)
@@ -643,12 +638,12 @@
 
     TRACE("(this=%p)\n",This);
 
-    if (This->acquired)
-    {
+    if (This->acquired) {
         /* Reinstall previous mouse event handler */
         if (This->hook) {
           UnhookWindowsHookEx( This->hook );
           This->hook = 0;
+
           if (This->dwCoopLevel & DISCL_EXCLUSIVE)
             ShowCursor(TRUE); /* show cursor */
         }
@@ -658,9 +653,15 @@
 
         /* Unacquire device */
         This->acquired = 0;
+
+	/* And put the mouse cursor back where it was at acquire time */
+	if (This->absolute == 0) {
+	    TRACE(" warping mouse back to (%ld , %ld)\n", This->org_coords.x, This->org_coords.y);
+	    SetCursorPos(This->org_coords.x, This->org_coords.y);
     }
-    else
+    } else {
 	return DI_NOEFFECT;
+    }
 	
     return DI_OK;
 }
@@ -704,8 +705,8 @@
 
   LeaveCriticalSection(&(This->crit));
 
-  TRACE("(X: %ld - Y: %ld   L: %02x M: %02x R: %02x)\n",
-	This->m_state.lX, This->m_state.lY,
+    TRACE("(X: %ld - Y: %ld - Z: %ld  L: %02x M: %02x R: %02x)\n",
+	  This->m_state.lX, This->m_state.lY, This->m_state.lZ,
 	This->m_state.rgbButtons[0], This->m_state.rgbButtons[2], This->m_state.rgbButtons[1]);
 
   return DI_OK;
@@ -756,9 +757,10 @@
     *entries = 0;
     nqtail = This->queue_tail;
     while (len) {
-      DWORD span = ((This->queue_head < nqtail) ? This->queue_len : This->queue_head)
-                 - nqtail;
-      if (span > len) span = len;
+	    DWORD span = ((This->queue_head < nqtail) ? This->queue_len : This->queue_head) - nqtail;
+	    if (span > len)
+		span = len;
+	    
       /* Copy the buffered data into the application queue */
       memcpy(dod + *entries, This->data_queue + nqtail, span * dodsize);
       /* Advance position */
@@ -884,7 +886,6 @@
     }
   }
 
-
   return DI_OK;
 }
 


More information about the wine-devel mailing list