Finish the changeable iconset

This commit is contained in:
Laci bá
2021-11-16 19:38:31 +01:00
parent 98316e228f
commit 0aa6e9c8a6
20 changed files with 210 additions and 25 deletions

View File

@@ -36,6 +36,8 @@
/* Language */
static LCID temp_language;
static char temp_icon_set[256] = {0};
int enum_helper, c;
HWND hwndProgSett;
@@ -76,6 +78,86 @@ progsett_fill_languages(HWND hdlg)
SendMessage(lang_combo, CB_SETCURSEL, enum_helper, 0);
}
/* Load available iconsets */
static void
progsett_fill_iconsets(HWND hdlg)
{
HWND icon_combo = GetDlgItem(hdlg, IDC_COMBO_ICON);
/* Add the default one */
wchar_t buffer[512] = L"(";
wcscat(buffer, plat_get_string(IDS_2090));
wcscat(buffer, L")");
SendMessage(icon_combo, CB_RESETCONTENT, 0, 0);
SendMessage(icon_combo, CB_ADDSTRING, 0, (LPARAM)buffer);
SendMessage(icon_combo, CB_SETITEMDATA, 0, (LPARAM)strdup(""));
int combo_index = -1;
/* Find for extra ones */
HANDLE hFind;
WIN32_FIND_DATA data;
char icon_path_root[512];
plat_get_icons_path(icon_path_root);
wchar_t search[512];
pclog("icon_path_root: %s\n", icon_path_root);
mbstowcs(search, icon_path_root, strlen(icon_path_root) + 1);
wcscat(search, L"*.*");
pclog("search: %ls\n", search);
hFind = FindFirstFile((LPCWSTR)search, &data);
if (hFind != INVALID_HANDLE_VALUE) {
do {
if (wcscmp(data.cFileName, L".") && wcscmp(data.cFileName, L"..") &&
(data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
wchar_t temp[512] = {0}, dispname[512] = {0};
mbstowcs(temp, icon_path_root, strlen(icon_path_root) + 1);
wcscat(temp, data.cFileName);
wcscat(temp, L"\\iconinfo.txt");
pclog("temp: %ls\n", temp);
wcscpy(dispname, data.cFileName);
FILE *fp = _wfopen(temp, L"r");
if (fp)
{
char line[512];
if (fgets(line, 511, fp))
{
pclog("found! %s\n", line);
mbstowcs(dispname, line, strlen(line) + 1);
}
fclose(fp);
}
char filename[512];
wcstombs(filename, data.cFileName, 511);
int index = SendMessage(icon_combo, CB_ADDSTRING, 0, (LPARAM)dispname);
SendMessage(icon_combo, CB_SETITEMDATA, index, (LPARAM)(strdup(filename)));
if (!strcmp(filename, icon_set))
combo_index = index;
}
} while (FindNextFile(hFind, &data));
FindClose(hFind);
}
if (combo_index == -1)
{
combo_index = 0;
strcpy(temp_icon_set, "");
}
SendMessage(icon_combo, CB_SETCURSEL, combo_index, 0);
}
/* This returns 1 if any variable has changed, 0 if not. */
static int
progsett_settings_changed(void)
@@ -84,6 +166,7 @@ progsett_settings_changed(void)
/* Language */
i = i || has_language_changed(temp_language);
i = i || strcmp(temp_icon_set, icon_set);
return i;
}
@@ -107,6 +190,10 @@ progsett_settings_save(void)
/* Language */
set_language(temp_language);
/* Iconset */
strcpy(icon_set, temp_icon_set);
plat_load_icon_set(hinstance);
/* Update title bar */
update_mouse_msg();
@@ -131,7 +218,10 @@ ProgSettDlgProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
hwndProgSett = hdlg;
/* Language */
temp_language = lang_id;
strcpy(temp_icon_set, icon_set);
pclog("temp_icon_set: %s\n", temp_icon_set);
progsett_fill_languages(hdlg);
progsett_fill_iconsets(hdlg);
break;
case WM_COMMAND:
@@ -154,6 +244,16 @@ ProgSettDlgProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
}
break;
case IDC_COMBO_ICON:
if (HIWORD(wParam) == CBN_SELCHANGE) {
pclog("dosth\n");
HWND combo = GetDlgItem(hdlg, IDC_COMBO_ICON);
int index = SendMessage(combo, CB_GETCURSEL, 0, 0);
strcpy(temp_icon_set, (char*)SendMessage(combo, CB_GETITEMDATA, index, 0));
pclog("temp_icon_set: %s\n", temp_icon_set);
}
break;
case IDC_BUTTON_DEFAULT: {
HWND combo = GetDlgItem(hdlg, IDC_COMBO_LANG);
int index = progsett_indexof(combo, DEFAULT_LANGUAGE);
@@ -161,10 +261,35 @@ ProgSettDlgProcedure(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
temp_language = DEFAULT_LANGUAGE;
break;
}
case IDC_BUTTON_DEFICON: {
pclog("dosth\n");
SendMessage(GetDlgItem(hdlg, IDC_COMBO_ICON), CB_SETCURSEL, 0, 0);
strcpy(temp_icon_set, "");
pclog("temp_icon_set: %s\n", temp_icon_set);
break;
}
default:
break;
}
break;
case WM_DESTROY: {
int i;
LRESULT temp;
HWND combo = GetDlgItem(hdlg, IDC_COMBO_ICON);
for (i = 0; i < SendMessage(combo, CB_GETCOUNT, 0, 0); i++)
{
temp = SendMessage(combo, CB_GETITEMDATA, i, 0);
if (temp)
{
free((void*)temp);
SendMessage(combo, CB_SETITEMDATA, i, 0);
}
}
}
break;
}
return(FALSE);