From 2fe2a9a37d5f0e61d61a26ce00a7d01ab8cf9ee2 Mon Sep 17 00:00:00 2001 From: "METANEOCORTEX\\Kotti" Date: Wed, 16 Feb 2022 00:28:43 +0100 Subject: [PATCH] +fix: ID mismatch using 'enter' to close infobox (vs. 'yes/ok' button) --- src/Config/Config.cpp | 3 +-- src/Dialogs.c | 29 +++++++++++++++-------------- src/Dialogs.h | 3 +++ src/Edit.c | 19 ++++++++----------- src/Notepad3.c | 37 ++++++++++++++----------------------- src/crypto/crypto.c | 2 +- 6 files changed, 42 insertions(+), 51 deletions(-) diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index 7a69c9ef5..f3229c1c4 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -2278,8 +2278,7 @@ void CmdSaveSettingsNow() return; } if (dwFileAttributes & FILE_ATTRIBUTE_READONLY) { - WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_INIFILE_READONLY)); - if ((IDOK == answer) || (IDYES == answer)) { + if (IsYesOkayRetryContinue(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_INIFILE_READONLY))) { Path_SetFileAttributes(Paths.IniFile, FILE_ATTRIBUTE_NORMAL); // override read-only attrib Globals.bCanSaveIniFile = CanAccessPath(Paths.IniFile, GENERIC_WRITE); } diff --git a/src/Dialogs.c b/src/Dialogs.c index dea7274c1..660008719 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -351,6 +351,7 @@ CASE_WM_CTLCOLOR_SET: if (IsButtonChecked(hwnd, IDC_INFOBOXCHECK) && StrIsNotEmpty(lpMsgBox->lpstrSetting) && Globals.bCanSaveIniFile) { IniFileSetInt(Paths.IniFile, Constants.SectionSuppressedMessages, lpMsgBox->lpstrSetting, LOWORD(wParam)); } + //[FallThrough] case IDNO: case IDABORT: case IDCLOSE: @@ -358,12 +359,15 @@ CASE_WM_CTLCOLOR_SET: EndDialog(hwnd, LOWORD(wParam)); break; - case IDC_INFOBOXCHECK: - DialogEnableControl(hwnd, IDNO, !IsButtonChecked(hwnd, IDC_INFOBOXCHECK)); - DialogEnableControl(hwnd, IDABORT, !IsButtonChecked(hwnd, IDC_INFOBOXCHECK)); - DialogEnableControl(hwnd, IDCLOSE, !IsButtonChecked(hwnd, IDC_INFOBOXCHECK)); - DialogEnableControl(hwnd, IDCANCEL, !IsButtonChecked(hwnd, IDC_INFOBOXCHECK)); - break; + case IDC_INFOBOXCHECK: { + bool const isChecked = IsButtonChecked(hwnd, IDC_INFOBOXCHECK); + DialogEnableControl(hwnd, IDNO, !isChecked); + DialogEnableControl(hwnd, IDABORT, !isChecked); + DialogEnableControl(hwnd, IDCLOSE, !isChecked); + DialogEnableControl(hwnd, IDCANCEL, !isChecked); + SendMessage(hwnd, WM_NEXTDLGCTL, 0, FALSE); + } + break; default: break; @@ -2523,10 +2527,10 @@ CASE_WM_CTLCOLOR_SET: } // Ask... - WORD const answer = (LOWORD(wParam) == IDOK) ? INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_ERR_MRUDLG)) + LONG const answer = (LOWORD(wParam) == IDOK) ? InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_ERR_MRUDLG) : ((iCur == lvi.iItem) ? IDNO : IDYES); - if ((IDOK == answer) || (IDYES == answer)) { + if (IsYesOkayRetryContinue(answer)) { MRU_Delete(Globals.pFileMRU, lvi.iItem); //SendDlgItemMessage(hwnd,IDC_FILEMRU,LB_DELETESTRING,(WPARAM)iItem,0); //ListView_DeleteItem(GetDlgItem(hwnd,IDC_FILEMRU),lvi.iItem); @@ -4996,12 +5000,9 @@ void DialogAdminExe(HWND hwnd, bool bExecInstaller) sei.nShow = SW_SHOWNORMAL; if (bExecInstaller) { ShellExecuteExW(&sei); - if ((INT_PTR)sei.hInstApp < 32) { - WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_OKCANCEL, L"NoAdminTool", IDS_MUI_ERR_ADMINEXE)); - if ((IDOK == answer) || (IDYES == answer)) { - sei.lpFile = VERSION_UPDATE_CHECK; - ShellExecuteExW(&sei); - } + if (IsYesOkayRetryContinue(InfoBoxLng(MB_OKCANCEL, L"NoAdminTool", IDS_MUI_ERR_ADMINEXE))) { + sei.lpFile = VERSION_UPDATE_CHECK; + ShellExecuteExW(&sei); } } else { sei.lpFile = VERSION_UPDATE_CHECK; diff --git a/src/Dialogs.h b/src/Dialogs.h index f07df5950..4983b068a 100644 --- a/src/Dialogs.h +++ b/src/Dialogs.h @@ -81,6 +81,9 @@ DWORD MsgBoxLastError(LPCWSTR lpszMessage, DWORD dwErrID); LONG InfoBoxLng(UINT uType, LPCWSTR lpstrSetting, UINT uidMsg, ...); #define INFOBOX_ANSW(_R_) LOWORD(_R_) #define INFOBOX_MODE(_R_) HIWORD(_R_) +inline bool IsYesOkayRetryContinue(LONG answ) { + return ((LOWORD(answ) == IDOK) || (LOWORD(answ) == IDYES) || (LOWORD(answ) == IDRETRY) || (LOWORD(answ) == IDCONTINUE)); +} void SetWindowTitle(HWND hwnd, const HPATHL pthFilePath, int iFormat, bool bPasteBoard, bool bIsElevated, bool bModified, diff --git a/src/Edit.c b/src/Edit.c index 9b574957a..ed7dd01db 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -559,7 +559,7 @@ bool EditSetNewEncoding(HWND hwnd, cpi_enc_t iNewEncoding, bool bSupressWarning) if (Sci_IsDocEmpty()) { bool const doNewEncoding = (Sci_HaveUndoRedoHistory() && !bSupressWarning) ? - (INFOBOX_ANSW(InfoBoxLng(MB_YESNO, L"MsgConv2", IDS_MUI_ASK_ENCODING2)) == IDYES) : true; + IsYesOkayRetryContinue(InfoBoxLng(MB_YESNO, L"MsgConv2", IDS_MUI_ASK_ENCODING2)) : true; if (doNewEncoding) { return EditConvertText(hwnd, iCurrentEncoding, iNewEncoding); @@ -572,9 +572,7 @@ bool EditSetNewEncoding(HWND hwnd, cpi_enc_t iNewEncoding, bool bSupressWarning) bSupressWarning = bIsCurANSI && bIsTargetUTF; } - bool const doNewEncoding = (!bSupressWarning) ? - (INFOBOX_ANSW(InfoBoxLng(MB_YESNO, L"MsgConv1", IDS_MUI_ASK_ENCODING)) == IDYES) : true; - + bool const doNewEncoding = (!bSupressWarning) ? IsYesOkayRetryContinue(InfoBoxLng(MB_YESNO, L"MsgConv1", IDS_MUI_ASK_ENCODING)) : true; if (doNewEncoding) { return EditConvertText(hwnd, iCurrentEncoding, iNewEncoding); } @@ -1215,7 +1213,7 @@ bool EditLoadFile( WCHAR sizeWarnStr[64] = { L'\0' }; StrFormatByteSizeEx(fileSizeWarning, SFBS_FLAGS_ROUND_TO_NEAREST_DISPLAYED_DIGIT, sizeWarnStr, COUNTOF(sizeWarnStr)); Flags.bHugeFileLoadState = true; - if (INFOBOX_ANSW(InfoBoxLng(MB_YESNO, L"MsgFileSizeWarning", IDS_MUI_WARN_LOAD_BIG_FILE, sizeStr, sizeWarnStr)) != IDYES) { + if (!IsYesOkayRetryContinue(InfoBoxLng(MB_YESNO, L"MsgFileSizeWarning", IDS_MUI_WARN_LOAD_BIG_FILE, sizeStr, sizeWarnStr))) { CloseHandle(hFile); Encoding_Forced(CPI_NONE); return false; @@ -1225,8 +1223,7 @@ bool EditLoadFile( // check for unknown file/extension status->bUnknownExt = false; if (!Style_HasLexerForExt(hfile_pth)) { - WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO, L"MsgFileUnknownExt", IDS_MUI_WARN_UNKNOWN_EXT, Path_FindFileName(hfile_pth))); - if (!((IDOK == answer) || (IDYES == answer))) { + if (!IsYesOkayRetryContinue(InfoBoxLng(MB_YESNO, L"MsgFileUnknownExt", IDS_MUI_WARN_UNKNOWN_EXT, Path_FindFileName(hfile_pth)))) { CloseHandle(hFile); Encoding_Forced(CPI_NONE); status->bUnknownExt = true; @@ -1253,7 +1250,7 @@ bool EditLoadFile( bool bReadSuccess = ((readFlag & DECRYPT_FATAL_ERROR) || (readFlag & DECRYPT_FREAD_FAILED)) ? false : true; if ((readFlag & DECRYPT_CANCELED_NO_PASS) || (readFlag & DECRYPT_WRONG_PASS)) { - bReadSuccess = (INFOBOX_ANSW(InfoBoxLng(MB_OKCANCEL, L"MsgNoOrWrongPassphrase", IDS_MUI_NOPASS)) == IDOK); + bReadSuccess = IsYesOkayRetryContinue(InfoBoxLng(MB_OKCANCEL, L"MsgNoOrWrongPassphrase", IDS_MUI_NOPASS)); if (!bReadSuccess) { Encoding_Forced(CPI_NONE); FreeMem(lpData); @@ -1625,7 +1622,7 @@ bool EditSaveFile( FreeMem(lpDataWide); - if (!bCancelDataLoss || INFOBOX_ANSW(InfoBoxLng(MB_OKCANCEL, L"MsgConv3", IDS_MUI_ERR_UNICODE2)) == IDOK) { + if (!bCancelDataLoss || IsYesOkayRetryContinue(InfoBoxLng(MB_OKCANCEL, L"MsgConv3", IDS_MUI_ERR_UNICODE2))) { SetEndOfFile(hFile); if (cbDataConverted != 0) { bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE *)lpData, cbDataConverted, &bytesWritten); @@ -7035,7 +7032,7 @@ bool EditFindNext(HWND hwnd, const LPEDITFINDREPLACE lpefr, bool bExtendSelectio } } else { LONG const result = InfoBoxLng(MB_OKCANCEL, L"MsgFindWrap1", IDS_MUI_FIND_WRAPFW); - if (INFOBOX_ANSW(result) != IDOK) { + if (!IsYesOkayRetryContinue(result)) { iPos = -1LL; bSuppressNotFound = true; } @@ -7119,7 +7116,7 @@ bool EditFindPrev(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bExtendSelection, boo } } else { LONG const result = InfoBoxLng(MB_OKCANCEL, L"MsgFindWrap2", IDS_MUI_FIND_WRAPRE); - if (INFOBOX_ANSW(result) != IDOK) { + if (!IsYesOkayRetryContinue(result)) { iPos = -1LL; bSuppressNotFound = true; } diff --git a/src/Notepad3.c b/src/Notepad3.c index 435049eb0..1df41cb42 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -3757,8 +3757,7 @@ LRESULT MsgFileChangeNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) if (!bRevertFile) { if (FileWatching.FileWatchingMode == FWM_MSGBOX) { - WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_FILECHANGENOTIFY)); - bRevertFile = ((IDOK == answer) || (IDYES == answer)); + bRevertFile = IsYesOkayRetryContinue(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_FILECHANGENOTIFY)); } else { // FWM_INDICATORSILENT: nothing todo here } @@ -3777,8 +3776,7 @@ LRESULT MsgFileChangeNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) } else { if (FileWatching.FileWatchingMode == FWM_MSGBOX) { - WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_FILECHANGENOTIFY2)); - if ((IDOK == answer) || (IDYES == answer)) { + if (IsYesOkayRetryContinue(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_FILECHANGENOTIFY2))) { FileSave(FSF_SaveAlways); } else { SetSaveNeeded(); @@ -4373,7 +4371,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) bool const bIsThemesMenuCmd = ((iLoWParam >= IDM_THEMES_FACTORY_RESET) && (iLoWParam < (int)(IDM_THEMES_FACTORY_RESET + ThemeItems_CountOf()))); if (bIsThemesMenuCmd) { if (iLoWParam == IDM_THEMES_FACTORY_RESET) { - if (INFOBOX_ANSW(InfoBoxLng(MB_OKCANCEL | MB_ICONWARNING, L"MsgResetScheme", IDS_MUI_WARN_STYLE_RESET)) != IDOK) { + if (!IsYesOkayRetryContinue(InfoBoxLng(MB_OKCANCEL | MB_ICONWARNING, L"MsgResetScheme", IDS_MUI_WARN_STYLE_RESET))) { return FALSE; } } @@ -4430,8 +4428,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_FILE_REVERT: if (IsDocumentModified()) { - WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONQUESTION, NULL, IDS_MUI_ASK_REVERT)); - if (!((IDOK == answer) || (IDYES == answer))) { + if (!IsYesOkayRetryContinue(InfoBoxLng(MB_YESNO | MB_ICONQUESTION, NULL, IDS_MUI_ASK_REVERT))) { break; } //~ don't revert if no save needed @@ -4772,8 +4769,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) cpi_enc_t iNewEncoding = Encoding_MapSignature(Encoding_GetCurrent()); if (IsDocumentModified()) { - WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONQUESTION, NULL, IDS_MUI_ASK_RECODE)); - if (!((IDOK == answer) || (IDYES == answer))) { + if (!IsYesOkayRetryContinue(InfoBoxLng(MB_YESNO | MB_ICONQUESTION, NULL, IDS_MUI_ASK_RECODE))) { break; } } @@ -6208,7 +6204,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_VIEW_WIN_DARK_MODE: { - if (INFOBOX_ANSW(InfoBoxLng(MB_OKCANCEL | MB_ICONWARNING, L"MsgResetScheme", IDS_MUI_WARN_STYLE_RESET)) != IDOK) { + if (!IsYesOkayRetryContinue(InfoBoxLng(MB_OKCANCEL | MB_ICONWARNING, L"MsgResetScheme", IDS_MUI_WARN_STYLE_RESET))) { break; } @@ -8597,9 +8593,7 @@ LRESULT MsgNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) WCHAR wch[64] = {L'\0'}; GetLngString(msgid, wch, COUNTOF(wch)); - WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_WARN_NORMALIZE_EOLS, wch)); - - if ((IDOK == answer) || (IDYES == answer)) { + if (IsYesOkayRetryContinue(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_WARN_NORMALIZE_EOLS, wch))) { PostWMCommand(hwnd, eol_cmd); } } @@ -10672,8 +10666,7 @@ bool FileLoad(const HPATHL hfile_pth, FileLoadFlags fLoadFlags) GetLngString(IDS_MUI_UNTITLED, szDisplayName, COUNTOF(szDisplayName)); Path_GetDisplayName(szDisplayName, COUNTOF(szDisplayName), hopen_file, NULL, false); //~Path_FindFileName(hopen_file) - WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONQUESTION, NULL, IDS_MUI_ASK_CREATE, szDisplayName)); - if ((IDOK == answer) || (IDYES == answer)) { + if (IsYesOkayRetryContinue(InfoBoxLng(MB_YESNO | MB_ICONQUESTION, NULL, IDS_MUI_ASK_CREATE, szDisplayName))) { bCreateFile = true; } } @@ -11223,15 +11216,15 @@ bool FileSave(FileSaveFlags fSaveFlags) // if current file is settings/config file: ask to start if (Flags.bSettingsFileSoftLocked && !s_flagAppIsClosing) { ///~ LoadSettings(); NOT all settings will be applied ... - WORD answer = 0; + LONG answer = 0L; if (Settings.SaveSettings) { WCHAR tch[256] = { L'\0' }; LoadLngStringW(IDS_MUI_RELOADCFGSEX, tch, COUNTOF(tch)); - answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, L"ReloadExSavedCfg", IDS_MUI_RELOADSETTINGS, tch)); + answer = InfoBoxLng(MB_YESNO | MB_ICONWARNING, L"ReloadExSavedCfg", IDS_MUI_RELOADSETTINGS, tch); } else { - answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONINFORMATION, L"ReloadExSavedCfg", IDS_MUI_RELOADSETTINGS, L"")); + answer = InfoBoxLng(MB_YESNO | MB_ICONINFORMATION, L"ReloadExSavedCfg", IDS_MUI_RELOADSETTINGS, L""); } - if ((IDOK == answer) || (IDYES == answer)) { + if (IsYesOkayRetryContinue(answer)) { DialogNewWindow(Globals.hwndMain, false, Paths.CurrentFile, NULL); CloseApplication(); } @@ -11441,8 +11434,7 @@ bool ActivatePrevInst() return true; } // IsWindowEnabled() - WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_ERR_PREVWINDISABLED)); - if ((IDOK == answer) || (IDYES == answer)) { + if (IsYesOkayRetryContinue(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_ERR_PREVWINDISABLED))) { return false; } return true; @@ -11532,8 +11524,7 @@ bool ActivatePrevInst() return true; } // IsWindowEnabled() - WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_ERR_PREVWINDISABLED)); - return ((IDOK == answer) || (IDYES == answer)) ? false : true;; + return !IsYesOkayRetryContinue(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_ERR_PREVWINDISABLED)); } return false; } diff --git a/src/crypto/crypto.c b/src/crypto/crypto.c index 782ccdb8d..714f4b93b 100644 --- a/src/crypto/crypto.c +++ b/src/crypto/crypto.c @@ -570,7 +570,7 @@ int ReadAndDecryptFile(HWND hwnd, HANDLE hFile, size_t fileSize, void** result, } else { - bRetryPassPhrase = (INFOBOX_ANSW(InfoBoxLng(MB_RETRYCANCEL | MB_ICONWARNING, NULL, IDS_MUI_PASS_FAILURE)) == IDRETRY); + bRetryPassPhrase = IsYesOkayRetryContinue(InfoBoxLng(MB_RETRYCANCEL | MB_ICONWARNING, NULL, IDS_MUI_PASS_FAILURE)); if (!bRetryPassPhrase) { // enable raw encryption read