From 2855c9fa01c927086cf48f990a7b0c6086950b53 Mon Sep 17 00:00:00 2001 From: lx-s Date: Tue, 4 Jun 2024 08:45:54 +0200 Subject: [PATCH] Enable save-button after an item has been selected from the dropdown. Fixes #38 --- WinMute/AboutDlg.cpp | 4 ++-- WinMute/Settings_BluetoothDlg.cpp | 12 ++++++++---- WinMute/Settings_ManageEndpointsDlg.cpp | 11 ++++++++--- WinMute/Settings_WifiDlg.cpp | 11 ++++++++--- WinMute/Utility.cpp | 3 ++- WinMute/WMLog.cpp | 3 ++- WinMute/WMi18n.cpp | 4 ++-- WinMute/WMi18n.h | 4 ++-- 8 files changed, 34 insertions(+), 18 deletions(-) diff --git a/WinMute/AboutDlg.cpp b/WinMute/AboutDlg.cpp index 59ee1e7..e253e8c 100644 --- a/WinMute/AboutDlg.cpp +++ b/WinMute/AboutDlg.cpp @@ -148,10 +148,10 @@ static void ResizeTabs(HWND hTabCtrl, std::span tabs) static void TranslateAboutGeneralDlgProc(HWND hDlg) { - WMi18n &i18n = WMi18n::GetInstance(); + WMi18n &i18n = WMi18n::GetInstance(); const auto hpLink = std::vformat( - L"{}", + std::wstring_view(L"{}"), std::make_wformat_args(i18n.GetTranslationW("about.general.author-site-label"))); const auto projLink = std::vformat( diff --git a/WinMute/Settings_BluetoothDlg.cpp b/WinMute/Settings_BluetoothDlg.cpp index c43dfc9..815a318 100644 --- a/WinMute/Settings_BluetoothDlg.cpp +++ b/WinMute/Settings_BluetoothDlg.cpp @@ -119,11 +119,15 @@ static INT_PTR CALLBACK Settings_BluetoothAddDlgProc(HWND hDlg, UINT msg, WPARAM return TRUE; } case WM_COMMAND: { - - if (LOWORD(wParam) == IDC_BT_DEVICE_NAME && HIWORD(wParam) == CBN_EDITUPDATE) { + if (LOWORD(wParam) == IDC_BT_DEVICE_NAME) { HWND hDevName = GetDlgItem(hDlg, IDC_BT_DEVICE_NAME); - const int textLen = Edit_GetTextLength(hDevName); - EnableWindow(GetDlgItem(hDlg, IDOK), textLen > 0); + if (HIWORD(wParam) == CBN_EDITUPDATE) { + const int textLen = Edit_GetTextLength(hDevName); + EnableWindow(GetDlgItem(hDlg, IDOK), textLen > 0); + } else if (HIWORD(wParam) == CBN_SELCHANGE) { + const auto curSelIdx = SendMessage(hDevName, CB_GETCURSEL, 0, 0); + EnableWindow(GetDlgItem(hDlg, IDOK), curSelIdx != CB_ERR); + } } else if (LOWORD(wParam) == IDOK) { HWND hDevName = GetDlgItem(hDlg, IDC_BT_DEVICE_NAME); const int textLen = Edit_GetTextLength(hDevName); diff --git a/WinMute/Settings_ManageEndpointsDlg.cpp b/WinMute/Settings_ManageEndpointsDlg.cpp index eeae1ce..da880c4 100644 --- a/WinMute/Settings_ManageEndpointsDlg.cpp +++ b/WinMute/Settings_ManageEndpointsDlg.cpp @@ -156,10 +156,15 @@ static INT_PTR CALLBACK Settings_EndpointAddDlgProc(HWND hDlg, UINT msg, WPARAM return TRUE; } case WM_COMMAND: - if (LOWORD(wParam) == IDC_ENDPOINT_NAME && HIWORD(wParam) == CBN_EDITUPDATE) { + if (LOWORD(wParam) == IDC_ENDPOINT_NAME) { HWND hDevName = GetDlgItem(hDlg, IDC_ENDPOINT_NAME); - const int textLen = Edit_GetTextLength(hDevName); - EnableWindow(GetDlgItem(hDlg, IDOK), textLen > 0); + if (HIWORD(wParam) == CBN_EDITUPDATE) { + const int textLen = Edit_GetTextLength(hDevName); + EnableWindow(GetDlgItem(hDlg, IDOK), textLen > 0); + } else if (HIWORD(wParam) == CBN_SELCHANGE) { + const auto curSelIdx = SendMessage(hDevName, CB_GETCURSEL, 0, 0); + EnableWindow(GetDlgItem(hDlg, IDOK), curSelIdx != CB_ERR); + } } else if (LOWORD(wParam) == IDOK) { HWND hEpName = GetDlgItem(hDlg, IDC_ENDPOINT_NAME); const int textLen = Edit_GetTextLength(hEpName); diff --git a/WinMute/Settings_WifiDlg.cpp b/WinMute/Settings_WifiDlg.cpp index a1f8bec..1fcc253 100644 --- a/WinMute/Settings_WifiDlg.cpp +++ b/WinMute/Settings_WifiDlg.cpp @@ -83,10 +83,15 @@ INT_PTR CALLBACK Settings_WifiAddDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPA return TRUE; } case WM_COMMAND: - if (LOWORD(wParam) == IDC_WIFI_NAME && HIWORD(wParam) == CBN_EDITUPDATE) { + if (LOWORD(wParam) == IDC_WIFI_NAME) { HWND hSsid = GetDlgItem(hDlg, IDC_WIFI_NAME); - const int textLen = Edit_GetTextLength(hSsid); - EnableWindow(GetDlgItem(hDlg, IDOK), textLen > 0); + if (HIWORD(wParam) == CBN_EDITUPDATE) { + const int textLen = Edit_GetTextLength(hSsid); + EnableWindow(GetDlgItem(hDlg, IDOK), textLen > 0); + } else if (HIWORD(wParam) == CBN_SELCHANGE) { + const auto curSelIdx = SendMessage(hSsid, CB_GETCURSEL, 0, 0); + EnableWindow(GetDlgItem(hDlg, IDOK), curSelIdx != CB_ERR); + } } else if (LOWORD(wParam) == IDOK) { HWND hSsid = GetDlgItem(hDlg, IDC_WIFI_NAME); const int textLen = Edit_GetTextLength(hSsid); diff --git a/WinMute/Utility.cpp b/WinMute/Utility.cpp index ddfd875..4a7130a 100644 --- a/WinMute/Utility.cpp +++ b/WinMute/Utility.cpp @@ -67,12 +67,13 @@ void ShowWindowsError(const wchar_t *functionName, DWORD lastError) return; } // Display the error message and exit the process + const std::wstring errorMsgText{ reinterpret_cast(lpMsgBuf) }; const std::wstring errorMsg = std::vformat( WMi18n::GetInstance().GetTranslationW("general.error.winapi.text"), std::make_wformat_args( functionName, lastError, - reinterpret_cast(lpMsgBuf))); + errorMsgText)); TaskDialog( nullptr, nullptr, PROGRAM_NAME, errorMsg.c_str(), nullptr, TDCBF_OK_BUTTON, TD_ERROR_ICON, nullptr); diff --git a/WinMute/WMLog.cpp b/WinMute/WMLog.cpp index 8bd5ddb..da21380 100644 --- a/WinMute/WMLog.cpp +++ b/WinMute/WMLog.cpp @@ -192,12 +192,13 @@ void WMLog::LogWinError(const wchar_t *functionName, DWORD lastError) reinterpret_cast(&lpMsgBuf), 0, nullptr) == 0) { return; } + const std::wstring errorMsgText{ reinterpret_cast(lpMsgBuf) }; const std::wstring errorMsg = std::vformat( WMi18n::GetInstance().GetTranslationW("general.error.winapi.text"), std::make_wformat_args( functionName, lastError, - reinterpret_cast(lpMsgBuf))); + errorMsgText)); WriteMessage(L"Error", static_cast(lpMsgBuf)); LocalFree(lpMsgBuf); } diff --git a/WinMute/WMi18n.cpp b/WinMute/WMi18n.cpp index 0687b8c..fe13359 100644 --- a/WinMute/WMi18n.cpp +++ b/WinMute/WMi18n.cpp @@ -193,7 +193,7 @@ void WMi18n::UnloadLanguage() loadedLang_.clear(); } -std::wstring WMi18n::GetTranslationW(const std::string& textId) const +const std::wstring WMi18n::GetTranslationW(const std::string& textId) const { std::wstring text; const std::lock_guard lock(langMutex_); @@ -216,7 +216,7 @@ std::wstring WMi18n::GetTranslationW(const std::string& textId) const return text; } -std::string WMi18n::GetTranslationA(const std::string &textId) const +const std::string WMi18n::GetTranslationA(const std::string &textId) const { const std::wstring wtext = GetTranslationW(textId); return ConvertWideStringToString(wtext); diff --git a/WinMute/WMi18n.h b/WinMute/WMi18n.h index 29f722e..c2fa12a 100644 --- a/WinMute/WMi18n.h +++ b/WinMute/WMi18n.h @@ -54,8 +54,8 @@ public: std::optional GetLanguageFilesPath() const; std::wstring GetCurrentLanguageName() const; - std::wstring GetTranslationW(const std::string& textId) const; - std::string GetTranslationA(const std::string& textId) const; + const std::wstring GetTranslationW(const std::string& textId) const; + const std::string GetTranslationA(const std::string& textId) const; bool SetItemText(HWND hWnd, int dlgItem, const std::string &textId); bool SetItemText(HWND hItem, const std::string &textId); -- 2.43.0