Skip to content

Instantly share code, notes, and snippets.

@lfzawacki
Created August 18, 2011 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lfzawacki/1154946 to your computer and use it in GitHub Desktop.
Save lfzawacki/1154946 to your computer and use it in GitHub Desktop.
Configure Devices patches
From add0b3129623f3deb3cefd9d46d8950658fcb22c Mon Sep 17 00:00:00 2001
From: Lucas Fialho Zawacki <lfzawacki@gmail.com>
Date: Thu, 28 Jul 2011 16:05:44 -0300
Subject: dinput: Added ConfigureDevices A to W crosscall
I had to switch the position of the two implementations so that the A version could effectively call the W one.
---
dlls/dinput/dinput_main.c | 64 +++++++++++++++++++++++++++++++++++----------
1 files changed, 50 insertions(+), 14 deletions(-)
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c
index 6ddcd71..8907897 100644
--- a/dlls/dinput/dinput_main.c
+++ b/dlls/dinput/dinput_main.c
@@ -999,28 +999,64 @@ static HRESULT WINAPI IDirectInput8WImpl_EnumDevicesBySemantics(
return DI_OK;
}
-static HRESULT WINAPI IDirectInput8AImpl_ConfigureDevices(
- LPDIRECTINPUT8A iface, LPDICONFIGUREDEVICESCALLBACK lpdiCallback,
- LPDICONFIGUREDEVICESPARAMSA lpdiCDParams, DWORD dwFlags, LPVOID pvRefData
+static HRESULT WINAPI IDirectInput8WImpl_ConfigureDevices(
+ LPDIRECTINPUT8W iface, LPDICONFIGUREDEVICESCALLBACK lpdiCallback,
+ LPDICONFIGUREDEVICESPARAMSW lpdiCDParams, DWORD dwFlags, LPVOID pvRefData
)
{
- IDirectInputImpl *This = impl_from_IDirectInput8A( iface );
+ IDirectInputImpl *This = impl_from_IDirectInput8W(iface);
- FIXME("(this=%p,%p,%p,%04x,%p): stub\n", This, lpdiCallback, lpdiCDParams,
- dwFlags, pvRefData);
- return 0;
+ FIXME("(this=%p,%p,%p,%04x,%p): stub\n", This, lpdiCallback, lpdiCDParams, dwFlags, pvRefData);
+
+ return DI_OK;
}
-static HRESULT WINAPI IDirectInput8WImpl_ConfigureDevices(
- LPDIRECTINPUT8W iface, LPDICONFIGUREDEVICESCALLBACK lpdiCallback,
- LPDICONFIGUREDEVICESPARAMSW lpdiCDParams, DWORD dwFlags, LPVOID pvRefData
+static HRESULT WINAPI IDirectInput8AImpl_ConfigureDevices(
+ LPDIRECTINPUT8A iface, LPDICONFIGUREDEVICESCALLBACK lpdiCallback,
+ LPDICONFIGUREDEVICESPARAMSA lpdiCDParams, DWORD dwFlags, LPVOID pvRefData
)
{
- IDirectInputImpl *This = impl_from_IDirectInput8W( iface );
+ IDirectInputImpl *This = impl_from_IDirectInput8A(iface);
+ DIACTIONFORMATW diafW;
+ DICONFIGUREDEVICESPARAMSW diCDParamsW;
+ HRESULT hr;
+ int i;
+
+ FIXME("(this=%p,%p,%p,%04x,%p): stub\n", This, lpdiCallback, lpdiCDParams, dwFlags, pvRefData);
+
+ /* Copy parameters */
+ diCDParamsW.dwSize = sizeof(DICONFIGUREDEVICESPARAMSW);
+ diCDParamsW.dwcFormats = lpdiCDParams->dwcFormats;
+ diCDParamsW.lprgFormats = &diafW;
+ diCDParamsW.hwnd = lpdiCDParams->hwnd;
+
+ diafW.rgoAction = HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW)*lpdiCDParams->lprgFormats->dwNumActions);
+ _copy_diactionformatAtoW(&diafW, lpdiCDParams->lprgFormats);
+
+ /* Copy action names */
+ for (i=0; i < diafW.dwNumActions; i++)
+ {
+ const char* from = lpdiCDParams->lprgFormats->rgoAction[i].u.lptszActionName;
+ int len = MultiByteToWideChar(CP_ACP, 0, from , -1, NULL , 0);
+ WCHAR *to = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*len);
+
+ MultiByteToWideChar(CP_ACP, 0, from , -1, to , len);
+ diafW.rgoAction[i].u.lptszActionName = to;
+ }
+
+ hr = IDirectInput8WImpl_ConfigureDevices(&This->IDirectInput8W_iface, lpdiCallback, &diCDParamsW, dwFlags, pvRefData);
+
+ /* Copy back configuration */
+ if (SUCCEEDED(hr))
+ _copy_diactionformatWtoA(lpdiCDParams->lprgFormats, &diafW);
+
+ /* Free memory */
+ for (i=0; i < diafW.dwNumActions; i++)
+ HeapFree(GetProcessHeap(), 0, (LPVOID) diafW.rgoAction[i].u.lptszActionName);
+
+ HeapFree(GetProcessHeap(), 0, diafW.rgoAction);
- FIXME("(this=%p,%p,%p,%04x,%p): stub\n", This, lpdiCallback, lpdiCDParams,
- dwFlags, pvRefData);
- return 0;
+ return hr;
}
static const IDirectInput7AVtbl ddi7avt = {
--
1.7.0.4
From ca47606c27b969f48d58a4e2caa706ff3e132e00 Mon Sep 17 00:00:00 2001
From: Lucas Fialho Zawacki <lfzawacki@gmail.com>
Date: Thu, 28 Jul 2011 16:45:42 -0300
Subject: dinput: Added ConfigureDevices dialog (try 2)
Renamed the files to use shorter and more reasonable names.
---
dlls/dinput/Makefile.in | 7 +++--
dlls/dinput/config.c | 43 ++++++++++++++++++++++++++++++++++++++++
dlls/dinput/dinput.rc | 45 ++++++++++++++++++++++++++++++++++++++++++
dlls/dinput/dinput_main.c | 3 +-
dlls/dinput/dinput_private.h | 2 +
dlls/dinput/resource.h | 35 ++++++++++++++++++++++++++++++++
6 files changed, 131 insertions(+), 4 deletions(-)
create mode 100644 dlls/dinput/config.c
create mode 100644 dlls/dinput/dinput.rc
create mode 100644 dlls/dinput/resource.h
diff --git a/dlls/dinput/Makefile.in b/dlls/dinput/Makefile.in
index 24502e6..6f6d229 100644
--- a/dlls/dinput/Makefile.in
+++ b/dlls/dinput/Makefile.in
@@ -1,6 +1,6 @@
MODULE = dinput.dll
IMPORTLIB = dinput
-IMPORTS = dxguid uuid ole32 user32 advapi32
+IMPORTS = dxguid uuid ole32 user32 advapi32 comctl32
EXTRALIBS = @IOKITLIB@
C_SRCS = \
@@ -13,12 +13,13 @@ C_SRCS = \
joystick_linuxinput.c \
joystick_osx.c \
keyboard.c \
- mouse.c
+ mouse.c \
+ config.c
IMPLIB_SRCS = data_formats.c
IDL_R_SRCS = dinput_classes.idl
-RC_SRCS = version.rc
+RC_SRCS = version.rc dinput.rc
@MAKE_DLL_RULES@
diff --git a/dlls/dinput/config.c b/dlls/dinput/config.c
new file mode 100644
index 0000000..26625ac
--- /dev/null
+++ b/dlls/dinput/config.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2011 Lucas Fialho Zawacki
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "wine/debug.h"
+#include "wine/unicode.h"
+#include "objbase.h"
+#include "dinput_private.h"
+#include "device_private.h"
+#include "resource.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(dinput);
+
+static HINSTANCE g_hinstance;
+
+HRESULT _configure_devices(LPDIRECTINPUT8W iface,
+ LPDICONFIGUREDEVICESCALLBACK lpdiCallback,
+ LPDICONFIGUREDEVICESPARAMSW lpdiCDParams,
+ DWORD dwFlags,
+ LPVOID pvRefData,
+ HINSTANCE hinstance)
+{
+ InitCommonControls();
+
+ g_hinstance = hinstance;
+ DialogBoxParamW(g_hinstance, (LPCWSTR) MAKEINTRESOURCE(IDD_CONFIGUREDEVICES), lpdiCDParams->hwnd, 0, 0);
+
+ return DI_OK;
+}
diff --git a/dlls/dinput/dinput.rc b/dlls/dinput/dinput.rc
new file mode 100644
index 0000000..bfe39de
--- /dev/null
+++ b/dlls/dinput/dinput.rc
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2011 Lucas Fialho Zawacki
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "resource.h"
+
+STRINGTABLE
+BEGIN
+ IDS_NOACTION "-"
+ IDS_ACTIONCOLUMN "Action"
+ IDS_OBJECTCOLUMN "Object"
+END
+
+IDD_CONFIGUREDEVICES DIALOG 0, 0, 270, 260
+STYLE DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE
+CAPTION "Configure Devices"
+FONT 8, "Ms Shell Dlg"
+{
+ DEFPUSHBUTTON "OK", IDOK, 10, 236, 50, 14
+ DEFPUSHBUTTON "Cancel", IDCANCEL, 65, 236, 50, 14
+ DEFPUSHBUTTON "Reset", IDRESET, 210, 236, 50, 14
+ COMBOBOX IDC_PLAYERCOMBO, 10, 50, 90, 30, CBS_DROPDOWNLIST | CBS_HASSTRINGS
+ COMBOBOX IDC_CONTROLLERCOMBO, 10, 20, 90, 30, CBS_DROPDOWNLIST | CBS_HASSTRINGS
+ LTEXT "Player", IDC_PLAYERTEXT, 10, 40, 21, 8, SS_LEFT
+ LTEXT "Device", IDC_DEVICETEXT, 10, 10, 22, 8, SS_LEFT
+ LTEXT "Actions", IDC_ACTIONTEXT, 10, 70, 24, 8, SS_LEFT
+ LTEXT "Mapping", IDC_MAPPINGTEXT, 120, 8, 28, 8, SS_LEFT
+ LISTBOX IDC_ACTIONLIST, 10, 80, 90, 130, WS_TABSTOP | WS_VSCROLL | LBS_NOINTEGRALHEIGHT | LBS_NOTIFY
+ AUTOCHECKBOX "Sort Assigned", IDC_CHECKBOXSORT, 120, 215, 60, 8
+ CONTROL "Listview", IDC_DEVICEOBJECTSLIST, "SysListView32", LVS_REPORT | LVS_AUTOARRANGE | LVS_ALIGNLEFT | LVS_SHOWSELALWAYS | LVS_SINGLESEL | WS_BORDER | WS_TABSTOP, 120, 20, 140, 190
+}
diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c
index 8907897..6aed515 100644
--- a/dlls/dinput/dinput_main.c
+++ b/dlls/dinput/dinput_main.c
@@ -1008,7 +1008,8 @@ static HRESULT WINAPI IDirectInput8WImpl_ConfigureDevices(
FIXME("(this=%p,%p,%p,%04x,%p): stub\n", This, lpdiCallback, lpdiCDParams, dwFlags, pvRefData);
- return DI_OK;
+ /* Call helper function in config.c to do the real work */
+ return _configure_devices(iface, lpdiCallback, lpdiCDParams, dwFlags, pvRefData, DINPUT_instance);
}
static HRESULT WINAPI IDirectInput8AImpl_ConfigureDevices(
diff --git a/dlls/dinput/dinput_private.h b/dlls/dinput/dinput_private.h
index 94b16a5..6427ffa 100644
--- a/dlls/dinput/dinput_private.h
+++ b/dlls/dinput/dinput_private.h
@@ -66,6 +66,8 @@ typedef int (*DI_EVENT_PROC)(LPDIRECTINPUTDEVICE8A, WPARAM, LPARAM);
extern void _copy_diactionformatAtoW(LPDIACTIONFORMATW, LPDIACTIONFORMATA) DECLSPEC_HIDDEN;
extern void _copy_diactionformatWtoA(LPDIACTIONFORMATA, LPDIACTIONFORMATW) DECLSPEC_HIDDEN;
+extern HRESULT _configure_devices(LPDIRECTINPUT8W iface, LPDICONFIGUREDEVICESCALLBACK lpdiCallback, LPDICONFIGUREDEVICESPARAMSW lpdiCDParams, DWORD dwFlags, LPVOID pvRefData, HINSTANCE hinstance) DECLSPEC_HIDDEN;
+
#define IS_DIPROP(x) (((ULONG_PTR)(x) >> 16) == 0)
#define DIKEYBOARD_MASK 0x81000000
diff --git a/dlls/dinput/resource.h b/dlls/dinput/resource.h
new file mode 100644
index 0000000..a52695f
--- /dev/null
+++ b/dlls/dinput/resource.h
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2011 Lucas Fialho Zawacki
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "shlobj.h"
+
+#define IDD_CONFIGUREDEVICES 1
+#define IDC_DEVICETEXT 2
+#define IDRESET 3
+#define IDC_ACTIONTEXT 4
+#define IDC_PLAYERTEXT 5
+#define IDC_DEVICEOBJECTSTEXT 6
+#define IDC_CONTROLLERCOMBO 7
+#define IDC_PLAYERCOMBO 8
+#define IDC_ACTIONLIST 9
+#define IDC_DEVICEOBJECTSLIST 10
+#define IDC_CHECKBOXSORT 11
+#define IDC_MAPPINGTEXT 12
+#define IDS_NOACTION 13
+#define IDS_ACTIONCOLUMN 14
+#define IDS_OBJECTCOLUMN 15
--
1.7.0.4
From fc7f5da665c1d9054eb57786e4eaa478893a1769 Mon Sep 17 00:00:00 2001
From: Lucas Fialho Zawacki <lfzawacki@gmail.com>
Date: Thu, 28 Jul 2011 18:32:45 -0300
Subject: dinput: Added enumerated devices to ConfigureDevices dialog
---
dlls/dinput/config.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 116 insertions(+), 1 deletions(-)
diff --git a/dlls/dinput/config.c b/dlls/dinput/config.c
index 26625ac..ca85797 100644
--- a/dlls/dinput/config.c
+++ b/dlls/dinput/config.c
@@ -25,8 +25,120 @@
WINE_DEFAULT_DEBUG_CHANNEL(dinput);
+typedef struct {
+ int nobjects;
+ LPDIRECTINPUTDEVICE8W lpdid;
+ DIDEVICEINSTANCEW ddi;
+ DIDEVICEOBJECTINSTANCEW ddo[256];
+} DeviceData;
+
+typedef struct {
+ int ndevices;
+ DeviceData *devices;
+} DIDevicesData;
+
+typedef struct {
+ LPDIRECTINPUT8W lpDI;
+ LPDICONFIGUREDEVICESPARAMSW params;
+ DWORD flags;
+} ConfigureDevicesData;
+
static HINSTANCE g_hinstance;
+/*
+ * Enumeration callback functions
+ */
+static BOOL CALLBACK count_devices(LPCDIDEVICEINSTANCEW lpddi, LPDIRECTINPUTDEVICE8W lpdid, DWORD dwFlags, DWORD dwRemaining, LPVOID pvRef)
+{
+ DIDevicesData *data = (DIDevicesData*) pvRef;
+
+ data->ndevices++;
+ return DIENUM_CONTINUE;
+}
+
+static BOOL CALLBACK collect_devices(LPCDIDEVICEINSTANCEW lpddi, LPDIRECTINPUTDEVICE8W lpdid, DWORD dwFlags, DWORD dwRemaining, LPVOID pvRef)
+{
+ DIDevicesData *data = (DIDevicesData*) pvRef;
+ DeviceData *device = &data->devices[data->ndevices];
+ device->lpdid = lpdid;
+ device->ddi = *lpddi;
+
+ IDirectInputDevice_AddRef(lpdid);
+
+ data->ndevices++;
+ return DIENUM_CONTINUE;
+}
+
+/*
+ * Utility functions
+ */
+static void init_devices(HWND dialog, LPDIRECTINPUT8W lpDI, DIDevicesData *data, LPDIACTIONFORMATW lpdiaf)
+{
+ int i;
+
+ /* Count devices */
+ IDirectInput8_EnumDevicesBySemantics(lpDI, NULL, lpdiaf, count_devices, (LPVOID) data, 0);
+
+ /* Allocate devices */
+ data->devices = (DeviceData*) HeapAlloc(GetProcessHeap(), 0, sizeof(DeviceData) * data->ndevices);
+
+ /* Collect and insert */
+ data->ndevices = 0;
+ IDirectInput8_EnumDevicesBySemantics(lpDI, NULL, lpdiaf, collect_devices, (LPVOID) data, 0);
+
+ for (i=0; i < data->ndevices; i++)
+ SendDlgItemMessageW(dialog, IDC_CONTROLLERCOMBO, CB_ADDSTRING, 0, (LPARAM) data->devices[i].ddi.tszProductName );
+}
+
+static void destroy_devices(DIDevicesData *data)
+{
+ int i;
+ for (i=0; i < data->ndevices; i++)
+ IDirectInputDevice8_Release(data->devices[i].lpdid);
+
+ HeapFree(GetProcessHeap(), 0, data->devices);
+}
+
+static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+ static LPDIACTIONFORMATW lpdiaf;
+ static DIDevicesData devices_data;
+ static ConfigureDevicesData *conf_data;
+
+ switch(uMsg)
+ {
+ case WM_INITDIALOG:
+ /* Initialize action format and enumerate devices */
+ conf_data = (ConfigureDevicesData*) lParam;
+ lpdiaf = conf_data->params->lprgFormats;
+
+ init_devices(dialog, conf_data->lpDI, &devices_data, lpdiaf);
+
+ break;
+
+ case WM_COMMAND:
+
+ switch( LOWORD( wParam ) )
+ {
+ case IDOK:
+ EndDialog(dialog, 0);
+ destroy_devices(&devices_data);
+ break;
+
+ case IDCANCEL:
+ EndDialog(dialog, 0);
+ destroy_devices(&devices_data);
+ break;
+
+ case IDRESET:
+ break;
+ }
+ break;
+ }
+
+ return FALSE;
+}
+
HRESULT _configure_devices(LPDIRECTINPUT8W iface,
LPDICONFIGUREDEVICESCALLBACK lpdiCallback,
LPDICONFIGUREDEVICESPARAMSW lpdiCDParams,
@@ -34,10 +146,13 @@ HRESULT _configure_devices(LPDIRECTINPUT8W iface,
LPVOID pvRefData,
HINSTANCE hinstance)
{
+ ConfigureDevicesData data = { iface, lpdiCDParams, dwFlags };
+
InitCommonControls();
g_hinstance = hinstance;
- DialogBoxParamW(g_hinstance, (LPCWSTR) MAKEINTRESOURCE(IDD_CONFIGUREDEVICES), lpdiCDParams->hwnd, 0, 0);
+
+ DialogBoxParamW(g_hinstance, (LPCWSTR) MAKEINTRESOURCE(IDD_CONFIGUREDEVICES), lpdiCDParams->hwnd, ConfigureDevicesDlgProc, (LPARAM) &data);
return DI_OK;
}
--
1.7.0.4
From ecb8279fdbfe27a96a324fb43d27a2fdb9181b5c Mon Sep 17 00:00:00 2001
From: Lucas Fialho Zawacki <lfzawacki@gmail.com>
Date: Thu, 28 Jul 2011 19:03:31 -0300
Subject: dinput: Added object/action enumeration to ConfigureDevices dialog
---
dlls/dinput/config.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 121 insertions(+), 0 deletions(-)
diff --git a/dlls/dinput/config.c b/dlls/dinput/config.c
index ca85797..9c66c01 100644
--- a/dlls/dinput/config.c
+++ b/dlls/dinput/config.c
@@ -48,6 +48,16 @@ static HINSTANCE g_hinstance;
/*
* Enumeration callback functions
*/
+static BOOL CALLBACK collect_objects(LPCDIDEVICEOBJECTINSTANCEW lpddo, LPVOID pvRef)
+{
+ DeviceData *data = (DeviceData*) pvRef;
+
+ data->ddo[data->nobjects] = *lpddo;
+
+ data->nobjects++;
+ return DIENUM_CONTINUE;
+}
+
static BOOL CALLBACK count_devices(LPCDIDEVICEINSTANCEW lpddi, LPDIRECTINPUTDEVICE8W lpdid, DWORD dwFlags, DWORD dwRemaining, LPVOID pvRef)
{
DIDevicesData *data = (DIDevicesData*) pvRef;
@@ -65,13 +75,64 @@ static BOOL CALLBACK collect_devices(LPCDIDEVICEINSTANCEW lpddi, LPDIRECTINPUTDE
IDirectInputDevice_AddRef(lpdid);
+ device->nobjects = 0;
+ IDirectInputDevice_EnumObjects(lpdid, collect_objects, (LPVOID) device, DIDFT_ALL);
+
data->ndevices++;
return DIENUM_CONTINUE;
}
/*
+ * Listview utility functions
+ */
+static void init_listview_columns(HWND dialog)
+{
+ LVCOLUMNW listColumn;
+ RECT viewRect;
+ int width;
+ WCHAR column[MAX_PATH];
+
+ GetClientRect(GetDlgItem(dialog, IDC_DEVICEOBJECTSLIST), &viewRect);
+ width = (viewRect.right - viewRect.left)/2;
+
+ LoadStringW(g_hinstance, IDS_OBJECTCOLUMN, column, sizeof(column)/sizeof(column[0]));
+ listColumn.mask = LVCF_TEXT | LVCF_WIDTH | LVCF_SUBITEM;
+ listColumn.pszText = column;
+ listColumn.cchTextMax = lstrlenW(listColumn.pszText);
+ listColumn.cx = width;
+
+ SendDlgItemMessageW (dialog, IDC_DEVICEOBJECTSLIST, LVM_INSERTCOLUMNW, 0, (LPARAM) &listColumn);
+
+ LoadStringW(g_hinstance, IDS_ACTIONCOLUMN, column, sizeof(column)/sizeof(column[0]));
+ listColumn.cx = width;
+ listColumn.pszText = column;
+ listColumn.cchTextMax = lstrlenW(listColumn.pszText);
+
+ SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_INSERTCOLUMNW, 1, (LPARAM) &listColumn);
+}
+
+static void lv_set_item_text(HWND dialog, int item, int subItem, WCHAR *text)
+{
+ LVITEMW lvItem;
+ if (item < 0 || subItem < 0) return;
+ lvItem.mask = LVIF_TEXT;
+ lvItem.iItem = item;
+ lvItem.iSubItem = subItem;
+ lvItem.pszText = text;
+ lvItem.cchTextMax = lstrlenW(lvItem.pszText);
+
+ SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_SETITEMW, 0, (LPARAM) &lvItem);
+}
+
+/*
* Utility functions
*/
+static DeviceData* get_cur_device(HWND dialog, DIDevicesData *data)
+{
+ int sel = SendDlgItemMessageW(dialog, IDC_CONTROLLERCOMBO, CB_GETCURSEL, 0, 0);
+ return &data->devices[sel];
+}
+
static void init_devices(HWND dialog, LPDIRECTINPUT8W lpDI, DIDevicesData *data, LPDIACTIONFORMATW lpdiaf)
{
int i;
@@ -90,6 +151,54 @@ static void init_devices(HWND dialog, LPDIRECTINPUT8W lpDI, DIDevicesData *data,
SendDlgItemMessageW(dialog, IDC_CONTROLLERCOMBO, CB_ADDSTRING, 0, (LPARAM) data->devices[i].ddi.tszProductName );
}
+static void fill_device_object_list(HWND dialog, DeviceData *device, LPDIACTIONFORMATW lpdiaf)
+{
+ LVITEMW item;
+ WCHAR no_action[MAX_PATH];
+ int i, j;
+
+ LoadStringW(g_hinstance, IDS_NOACTION, no_action, sizeof(no_action)/sizeof(no_action[0]));
+
+ /* Clean the listview */
+ SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_DELETEALLITEMS, 0, 0);
+
+ /* Add each object */
+ for (i=0; i < device->nobjects; i++)
+ {
+ WCHAR *action_text = no_action;
+ int action = -1;
+
+ item.mask = LVIF_TEXT | LVIF_PARAM;
+ item.iItem = i;
+ item.iSubItem = 0;
+ item.pszText = device->ddo[i].tszName;
+ item.cchTextMax = lstrlenW(item.pszText);
+
+ /* Search for an assigned action for this device */
+ for (j=0; j < lpdiaf->dwNumActions; j++)
+ {
+ if (IsEqualGUID(&lpdiaf->rgoAction[j].guidInstance, &device->ddi.guidInstance) &&
+ lpdiaf->rgoAction[j].dwObjID == device->ddo[i].dwType)
+ {
+ action = j;
+ break;
+ }
+ }
+
+ /* Keep action index in the listview item */
+ item.lParam = (LPARAM) action;
+
+ /* Add the item */
+ SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_INSERTITEMW, 0, (LPARAM) &item);
+
+ if (action != -1)
+ action_text = (WCHAR*) lpdiaf->rgoAction[action].lptszActionName;
+
+ /* Object/Action text */
+ lv_set_item_text(dialog, i, 1, action_text);
+ }
+}
+
static void destroy_devices(DIDevicesData *data)
{
int i;
@@ -112,6 +221,7 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w
conf_data = (ConfigureDevicesData*) lParam;
lpdiaf = conf_data->params->lprgFormats;
+ init_listview_columns(dialog);
init_devices(dialog, conf_data->lpDI, &devices_data, lpdiaf);
break;
@@ -120,6 +230,17 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w
switch( LOWORD( wParam ) )
{
+
+ case IDC_CONTROLLERCOMBO:
+
+ switch (HIWORD(wParam))
+ {
+ case CBN_SELCHANGE:
+ fill_device_object_list(dialog, get_cur_device(dialog, &devices_data), lpdiaf);
+ break;
+ }
+ break;
+
case IDOK:
EndDialog(dialog, 0);
destroy_devices(&devices_data);
--
1.7.0.4
From c560df30a3865841fa71182946f98f51ae622eaa Mon Sep 17 00:00:00 2001
From: Lucas Fialho Zawacki <lfzawacki@gmail.com>
Date: Thu, 28 Jul 2011 19:28:24 -0300
Subject: dinput: Added display of available actions to ConfigureDevices dialog
---
dlls/dinput/config.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/dlls/dinput/config.c b/dlls/dinput/config.c
index 9c66c01..939f9ec 100644
--- a/dlls/dinput/config.c
+++ b/dlls/dinput/config.c
@@ -111,6 +111,11 @@ static void init_listview_columns(HWND dialog)
SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_INSERTCOLUMNW, 1, (LPARAM) &listColumn);
}
+static int lv_get_cur_item(HWND dialog)
+{
+ return SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
+}
+
static void lv_set_item_text(HWND dialog, int item, int subItem, WCHAR *text)
{
LVITEMW lvItem;
@@ -208,6 +213,35 @@ static void destroy_devices(DIDevicesData *data)
HeapFree(GetProcessHeap(), 0, data->devices);
}
+static void show_suitable_actions(HWND dialog, DeviceData* device, LPDIACTIONFORMATW lpdiaf)
+{
+ int i, added = 0;
+ int obj = lv_get_cur_item(dialog);
+
+ if (obj < 0) return;
+
+ SendDlgItemMessageW(dialog, IDC_ACTIONLIST, LB_RESETCONTENT, 0, 0);
+
+ for (i=0; i < lpdiaf->dwNumActions; i++)
+ {
+ /* Skip keyboard actions for non keyboards */
+ if (GET_DIDEVICE_TYPE(device->ddi.dwDevType) != DI8DEVTYPE_KEYBOARD &&
+ (lpdiaf->rgoAction[i].dwSemantic & DIKEYBOARD_MASK) == DIKEYBOARD_MASK) continue;
+
+ /* Skip mouse actions for non mouses */
+ if (GET_DIDEVICE_TYPE(device->ddi.dwDevType) != DI8DEVTYPE_MOUSE &&
+ (lpdiaf->rgoAction[i].dwSemantic & DIMOUSE_MASK) == DIMOUSE_MASK) continue;
+
+ /* Add action string and index in the action format to the list entry */
+ if (DIDFT_GETINSTANCE(lpdiaf->rgoAction[i].dwSemantic) & DIDFT_GETTYPE(device->ddo[obj].dwType))
+ {
+ SendDlgItemMessageW(dialog, IDC_ACTIONLIST, LB_ADDSTRING, 0, (LPARAM)lpdiaf->rgoAction[i].lptszActionName);
+ SendDlgItemMessageW(dialog, IDC_ACTIONLIST, LB_SETITEMDATA, added, (LPARAM) i);
+ added++;
+ }
+ }
+}
+
static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static LPDIACTIONFORMATW lpdiaf;
@@ -226,6 +260,18 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w
break;
+ case WM_NOTIFY:
+
+ switch (((LPNMHDR)lParam)->code)
+ {
+ case LVN_ITEMCHANGED:
+ show_suitable_actions(dialog, get_cur_device(dialog, &devices_data), lpdiaf);
+ break;
+
+ }
+ break;
+
+
case WM_COMMAND:
switch( LOWORD( wParam ) )
--
1.7.0.4
From 5f19f92f0945adee70b23ee76fe3323b1ab84b02 Mon Sep 17 00:00:00 2001
From: Lucas Fialho Zawacki <lfzawacki@gmail.com>
Date: Thu, 28 Jul 2011 19:56:39 -0300
Subject: dinput: Added possibility to change the action mapping in the ConfigureDevices dialog
---
dlls/dinput/config.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/dlls/dinput/config.c b/dlls/dinput/config.c
index 939f9ec..fa2a260 100644
--- a/dlls/dinput/config.c
+++ b/dlls/dinput/config.c
@@ -116,6 +116,17 @@ static int lv_get_cur_item(HWND dialog)
return SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
}
+static int lv_get_item_data(HWND dialog, int index)
+{
+ LVITEMW item;
+ item.iItem = index;
+ item.iSubItem = 0;
+
+ SendDlgItemMessageW(dialog, IDC_DEVICEOBJECTSLIST, LVM_GETITEMW , 0, (LPARAM)&item);
+
+ return item.lParam;
+}
+
static void lv_set_item_text(HWND dialog, int item, int subItem, WCHAR *text)
{
LVITEMW lvItem;
@@ -242,11 +253,35 @@ static void show_suitable_actions(HWND dialog, DeviceData* device, LPDIACTIONFOR
}
}
+static void assign_action(HWND dialog, DeviceData* device, LPDIACTIONFORMATW lpdiaf)
+{
+ int sel = SendDlgItemMessageW(dialog, IDC_ACTIONLIST, LB_GETCURSEL, 0, 0);
+ int action = SendDlgItemMessageW(dialog, IDC_ACTIONLIST, LB_GETITEMDATA, sel, 0);
+ int obj = lv_get_cur_item(dialog);
+ int old_action = lv_get_item_data(dialog, obj);
+
+ DIDEVICEOBJECTINSTANCEW ddo = device->ddo[obj];
+
+ /* Clear old action */
+ if (old_action != action)
+ {
+ lpdiaf->rgoAction[old_action].dwObjID = 0;
+ lpdiaf->rgoAction[old_action].guidInstance = GUID_NULL;
+ lpdiaf->rgoAction[old_action].dwHow = DIAH_UNMAPPED;
+ }
+
+ /* Set new action */
+ lpdiaf->rgoAction[action].dwObjID = ddo.dwType;
+ lpdiaf->rgoAction[action].guidInstance = device->ddi.guidInstance;
+ lpdiaf->rgoAction[action].dwHow = DIAH_USERCONFIG;
+}
+
static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static LPDIACTIONFORMATW lpdiaf;
static DIDevicesData devices_data;
static ConfigureDevicesData *conf_data;
+ static int display_only = 0;
switch(uMsg)
{
@@ -255,6 +290,8 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w
conf_data = (ConfigureDevicesData*) lParam;
lpdiaf = conf_data->params->lprgFormats;
+ if (!(conf_data->flags & DICD_EDIT)) display_only = 1;
+
init_listview_columns(dialog);
init_devices(dialog, conf_data->lpDI, &devices_data, lpdiaf);
@@ -277,6 +314,20 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w
switch( LOWORD( wParam ) )
{
+ case IDC_ACTIONLIST:
+
+ switch (HIWORD(wParam))
+ {
+ case LBN_DBLCLK:
+ /* Ignore this if app did not ask for editing */
+ if (display_only) break;
+
+ assign_action(dialog, get_cur_device(dialog, &devices_data), lpdiaf);
+ fill_device_object_list(dialog, get_cur_device(dialog, &devices_data), lpdiaf);
+ break;
+ }
+ break;
+
case IDC_CONTROLLERCOMBO:
switch (HIWORD(wParam))
--
1.7.0.4
From a392f3c6e980afe188c21ae5230ac0bbca3f76ff Mon Sep 17 00:00:00 2001
From: Lucas Fialho Zawacki <lfzawacki@gmail.com>
Date: Fri, 29 Jul 2011 03:13:05 -0300
Subject: dinput: Working CANCEL and RESET buttons in ConfigureDevices dialog.
---
dlls/dinput/config.c | 20 ++++++++++++++++++++
1 files changed, 20 insertions(+), 0 deletions(-)
diff --git a/dlls/dinput/config.c b/dlls/dinput/config.c
index fa2a260..464a982 100644
--- a/dlls/dinput/config.c
+++ b/dlls/dinput/config.c
@@ -276,9 +276,22 @@ static void assign_action(HWND dialog, DeviceData* device, LPDIACTIONFORMATW lpd
lpdiaf->rgoAction[action].dwHow = DIAH_USERCONFIG;
}
+static void copy_actions(LPDIACTIONFORMATW to, LPDIACTIONFORMATW from)
+{
+ int i;
+ for (i=0; i < from->dwNumActions; i++)
+ {
+ to->rgoAction[i].guidInstance = from->rgoAction[i].guidInstance;
+ to->rgoAction[i].dwObjID = from->rgoAction[i].dwObjID;
+ to->rgoAction[i].dwHow = from->rgoAction[i].dwHow;
+ to->rgoAction[i].lptszActionName = from->rgoAction[i].lptszActionName;
+ }
+}
+
static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
static LPDIACTIONFORMATW lpdiaf;
+ static DIACTIONFORMATW original_diaf;
static DIDevicesData devices_data;
static ConfigureDevicesData *conf_data;
static int display_only = 0;
@@ -290,6 +303,10 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w
conf_data = (ConfigureDevicesData*) lParam;
lpdiaf = conf_data->params->lprgFormats;
+ original_diaf.dwNumActions = lpdiaf->dwNumActions;
+ original_diaf.rgoAction = HeapAlloc(GetProcessHeap(), 0, sizeof(DIACTIONW) * lpdiaf->dwNumActions);
+ copy_actions(&original_diaf, lpdiaf);
+
if (!(conf_data->flags & DICD_EDIT)) display_only = 1;
init_listview_columns(dialog);
@@ -344,11 +361,14 @@ static INT_PTR CALLBACK ConfigureDevicesDlgProc(HWND dialog, UINT uMsg, WPARAM w
break;
case IDCANCEL:
+ copy_actions(lpdiaf, &original_diaf);
EndDialog(dialog, 0);
destroy_devices(&devices_data);
break;
case IDRESET:
+ copy_actions(lpdiaf, &original_diaf);
+ fill_device_object_list(dialog, get_cur_device(dialog, &devices_data), lpdiaf);
break;
}
break;
--
1.7.0.4
From 1906516e86ba239a0dd7ec28d0f7119181efeb6e Mon Sep 17 00:00:00 2001
From: Lucas Fialho Zawacki <lfzawacki@gmail.com>
Date: Fri, 29 Jul 2011 16:36:31 -0300
Subject: dinput: In BuildActionMap, don't assign objects to actions mapped by an user
---
dlls/dinput/joystick.c | 2 ++
dlls/dinput/keyboard.c | 2 ++
dlls/dinput/mouse.c | 2 ++
3 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/dlls/dinput/joystick.c b/dlls/dinput/joystick.c
index 2d8a818..e3babc6 100644
--- a/dlls/dinput/joystick.c
+++ b/dlls/dinput/joystick.c
@@ -445,6 +445,8 @@ HRESULT WINAPI JoystickWGenericImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
DWORD type = 0x000000ff & (lpdiaf->rgoAction[i].dwSemantic >> 8);
DWORD genre = 0xff000000 & lpdiaf->rgoAction[i].dwSemantic;
+ if (lpdiaf->rgoAction[i].dwHow == DIAH_USERCONFIG) continue;
+
/* Only consider actions of the right genre */
if (lpdiaf->dwGenre != genre && genre != DIGENRE_ANY) continue;
diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c
index 3c93bcd..4354a68 100644
--- a/dlls/dinput/keyboard.c
+++ b/dlls/dinput/keyboard.c
@@ -536,6 +536,8 @@ static HRESULT WINAPI SysKeyboardWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W ifac
for (i=0; i < lpdiaf->dwNumActions; i++)
{
+ if (lpdiaf->rgoAction[i].dwHow == DIAH_USERCONFIG) continue;
+
if ((lpdiaf->rgoAction[i].dwSemantic & DIKEYBOARD_MASK) == DIKEYBOARD_MASK)
{
DWORD obj_id = semantic_to_obj_id(&This->base, lpdiaf->rgoAction[i].dwSemantic);
diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c
index 8da35f4..fe4faef 100644
--- a/dlls/dinput/mouse.c
+++ b/dlls/dinput/mouse.c
@@ -783,6 +783,8 @@ static HRESULT WINAPI SysMouseWImpl_BuildActionMap(LPDIRECTINPUTDEVICE8W iface,
for (i=0; i < lpdiaf->dwNumActions; i++)
{
+ if (lpdiaf->rgoAction[i].dwHow == DIAH_USERCONFIG) continue;
+
if ((lpdiaf->rgoAction[i].dwSemantic & DIMOUSE_MASK) == DIMOUSE_MASK)
{
DWORD obj_id = semantic_to_obj_id(&This->base, lpdiaf->rgoAction[i].dwSemantic);
--
1.7.0.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment