void UpdatePadList()

in Lilypad/Config.cpp [1688:1754]


void UpdatePadList(HWND hWnd) {
	static u8 recurse = 0;
	if (recurse) return;
	recurse = 1;
	HWND hWndList = GetDlgItem(hWnd, IDC_PAD_LIST);
	HWND hWndCombo = GetDlgItem(hWnd, IDC_PAD_TYPE);
	HWND hWndAnalog = GetDlgItem(hWnd, IDC_ANALOG_START1);
	int slot;
	int port;
	int index = 0;
	wchar_t *padTypes[] = {L"Unplugged", L"Dualshock 2", L"Guitar"};
	for (port=0; port<2; port++) {
		for (slot = 0; slot<4; slot++) {
			wchar_t text[20];
			if (!GetPadString(text, port, slot)) continue;
			LVITEM item;
			item.iItem = index;
			item.iSubItem = 0;
			item.mask = LVIF_TEXT;
			item.pszText = text;
			if (SendMessage(hWndList, LVM_GETITEMCOUNT, 0, 0) <= index) {
				ListView_InsertItem(hWndList, &item);
			}
			else {
				ListView_SetItem(hWndList, &item);
			}

			item.iSubItem = 1;
			if (2 < (unsigned int)config.padConfigs[port][slot].type) config.padConfigs[port][slot].type = Dualshock2Pad;
			item.pszText = padTypes[config.padConfigs[port][slot].type];
			//if (!slot && !config.padConfigs[port][slot].type)
			//	item.pszText = L"Unplugged (Kinda)";

			ListView_SetItem(hWndList, &item);

			item.iSubItem = 2;
			int count = 0;
			for (int i = 0; i<dm->numDevices; i++) {
				Device *dev = dm->devices[i];
				if (!dev->enabled) continue;
				count += dev->pads[port][slot].numBindings + dev->pads[port][slot].numFFBindings;
			}
			wsprintf(text, L"%i", count);
			item.pszText = text;
			ListView_SetItem(hWndList, &item);
			index++;
		}
	}
	while (ListView_DeleteItem(hWndList, index));
	int sel = ListView_GetNextItem(hWndList, -1, LVNI_SELECTED);

	int enable;
	if (!ListIndexToPortAndSlot(sel, &port, &slot)) {
		enable = 0;
		SendMessage(hWndCombo, CB_SETCURSEL, -1, 0);
		CheckDlgButton(hWnd, IDC_ANALOG_START1, BST_UNCHECKED);
	}
	else {
		enable = 1;
		SendMessage(hWndCombo, CB_SETCURSEL, config.padConfigs[port][slot].type, 0);
		CheckDlgButton(hWnd, IDC_ANALOG_START1, BST_CHECKED*config.padConfigs[port][slot].autoAnalog);
	}
	EnableWindow(hWndCombo, enable);
	EnableWindow(hWndAnalog, enable && !ps2e);
	//ListView_SetExtendedListViewStyleEx(hWndList, LVS_EX_DOUBLEBUFFER|LVS_EX_ONECLICKACTIVATE, LVS_EX_DOUBLEBUFFER|LVS_EX_ONECLICKACTIVATE);
	recurse = 0;
}