From 3c558804f49746fc51701d60e6aecb948de2becf Mon Sep 17 00:00:00 2001 From: Rainer Kottenhoff Date: Wed, 17 Feb 2021 20:40:48 +0100 Subject: [PATCH] + fix: F/R show wrap-around tooltip only if message boxes are hidden --- src/Config/Config.cpp | 2 +- src/Dialogs.c | 13 +++--- src/Dialogs.h | 5 ++- src/Edit.c | 98 +++++++++++++------------------------------ src/Notepad3.c | 22 +++++----- src/crypto/crypto.c | 2 +- 6 files changed, 54 insertions(+), 88 deletions(-) diff --git a/src/Config/Config.cpp b/src/Config/Config.cpp index 113feadba..dbc6fa5a2 100644 --- a/src/Config/Config.cpp +++ b/src/Config/Config.cpp @@ -2192,7 +2192,7 @@ void CmdSaveSettingsNow() return; } if (dwFileAttributes & FILE_ATTRIBUTE_READONLY) { - INT_PTR const answer = InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_INIFILE_READONLY); + WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_INIFILE_READONLY)); if ((IDOK == answer) || (IDYES == answer)) { SetFileAttributes(Globals.IniFile, FILE_ATTRIBUTE_NORMAL); // override read-only attrib Globals.bCanSaveIniFile = CanAccessPath(Globals.IniFile, GENERIC_WRITE); diff --git a/src/Dialogs.c b/src/Dialogs.c index 7baac28bf..2aa2824be 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -398,7 +398,7 @@ CASE_WM_CTLCOLOR_SET: // // -INT_PTR InfoBoxLng(UINT uType, LPCWSTR lpstrSetting, UINT uidMsg, ...) +LONG InfoBoxLng(UINT uType, LPCWSTR lpstrSetting, UINT uidMsg, ...) { int const iMode = StrIsEmpty(lpstrSetting) ? 0 : IniFileGetInt(Globals.IniFile, Constants.SectionSuppressedMessages, lpstrSetting, 0); @@ -410,7 +410,7 @@ INT_PTR InfoBoxLng(UINT uType, LPCWSTR lpstrSetting, UINT uidMsg, ...) case IDOK: case IDYES: case IDCONTINUE: - return iMode; + return MAKELONG(iMode, iMode); case 0: // no entry found @@ -427,7 +427,7 @@ INT_PTR InfoBoxLng(UINT uType, LPCWSTR lpstrSetting, UINT uidMsg, ...) WCHAR wchMessage[LARGE_BUFFER]; if (!GetLngString(uidMsg, wchMessage, COUNTOF(wchMessage))) { - return -1LL; + return MAKELONG(0, iMode); } INFOBOXLNG msgBox; @@ -505,7 +505,8 @@ INT_PTR InfoBoxLng(UINT uType, LPCWSTR lpstrSetting, UINT uidMsg, ...) HWND focus = GetFocus(); HWND hwnd = focus ? focus : Globals.hwndMain; - return ThemedDialogBoxParam(Globals.hLngResContainer, MAKEINTRESOURCE(idDlg), hwnd, _InfoBoxLngDlgProc, (LPARAM)&msgBox); + INT_PTR const answer = ThemedDialogBoxParam(Globals.hLngResContainer, MAKEINTRESOURCE(idDlg), hwnd, _InfoBoxLngDlgProc, (LPARAM)&msgBox); + return MAKELONG(answer, iMode); } @@ -2423,7 +2424,7 @@ CASE_WM_CTLCOLOR_SET: } // Ask... - INT_PTR const answer = (LOWORD(wParam) == IDOK) ? InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_ERR_MRUDLG) + WORD const answer = (LOWORD(wParam) == IDOK) ? INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_ERR_MRUDLG)) : ((iCur == lvi.iItem) ? IDNO : IDYES); if ((IDOK == answer) || (IDYES == answer)) { @@ -4575,7 +4576,7 @@ void DialogAdminExe(HWND hwnd, bool bExecInstaller) if (bExecInstaller) { ShellExecuteEx(&sei); if ((INT_PTR)sei.hInstApp < 32) { - INT_PTR const answer = InfoBoxLng(MB_OKCANCEL, L"NoAdminTool", IDS_MUI_ERR_ADMINEXE); + WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_OKCANCEL, L"NoAdminTool", IDS_MUI_ERR_ADMINEXE)); if ((IDOK == answer) || (IDYES == answer)) { sei.lpFile = VERSION_UPDATE_CHECK; ShellExecuteEx(&sei); diff --git a/src/Dialogs.h b/src/Dialogs.h index 5c1a0572e..82f74902d 100644 --- a/src/Dialogs.h +++ b/src/Dialogs.h @@ -65,10 +65,13 @@ void DialogGrepWin(HWND hwnd, LPCWSTR searchPattern); void DialogAdminExe(HWND hwnd,bool); int MessageBoxLng(UINT uType, UINT uidMsg, ...); -INT_PTR InfoBoxLng(UINT uType, LPCWSTR lpstrSetting, UINT uidMsg, ...); DWORD MsgBoxLastError(LPCWSTR lpszMessage, DWORD dwErrID); DWORD DbgMsgBoxLastError(LPCWSTR lpszMessage, DWORD dwErrID); +LONG InfoBoxLng(UINT uType, LPCWSTR lpstrSetting, UINT uidMsg, ...); +#define INFOBOX_ANSW(_R_) LOWORD(_R_) +#define INFOBOX_MODE(_R_) HIWORD(_R_) + void SetWindowTitle(HWND hwnd, UINT uIDAppName, bool bIsElevated, UINT uIDUntitled, LPCWSTR lpszFile, int iFormat, bool bModified, UINT uIDReadOnly, bool bReadOnly, LPCWSTR lpszExcerpt); diff --git a/src/Edit.c b/src/Edit.c index 5b54f44df..7822a0873 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -429,8 +429,8 @@ bool EditSetNewEncoding(HWND hwnd, cpi_enc_t iNewEncoding, bool bSupressWarning) } if (Sci_IsDocEmpty()) { - bool const doNewEncoding = (Sci_HaveUndoRedoHistory() && !bSupressWarning) ? - (InfoBoxLng(MB_YESNO, L"MsgConv2", IDS_MUI_ASK_ENCODING2) == IDYES) : true; + bool const doNewEncoding = (Sci_HaveUndoRedoHistory() && !bSupressWarning) ? + (INFOBOX_ANSW(InfoBoxLng(MB_YESNO, L"MsgConv2", IDS_MUI_ASK_ENCODING2)) == IDYES) : true; if (doNewEncoding) { return EditConvertText(hwnd, iCurrentEncoding, iNewEncoding); @@ -443,7 +443,8 @@ bool EditSetNewEncoding(HWND hwnd, cpi_enc_t iNewEncoding, bool bSupressWarning) bSupressWarning = bIsCurANSI && bIsTargetUTF; } - bool const doNewEncoding = (!bSupressWarning) ? (InfoBoxLng(MB_YESNO, L"MsgConv1", IDS_MUI_ASK_ENCODING) == IDYES) : true; + bool const doNewEncoding = (!bSupressWarning) ? + (INFOBOX_ANSW(InfoBoxLng(MB_YESNO, L"MsgConv1", IDS_MUI_ASK_ENCODING)) == IDYES) : true; if (doNewEncoding) { return EditConvertText(hwnd, iCurrentEncoding, iNewEncoding); @@ -1075,7 +1076,7 @@ bool EditLoadFile( WCHAR sizeWarnStr[64] = { L'\0' }; StrFormatByteSize((LONGLONG)fileSizeWarning, sizeWarnStr, COUNTOF(sizeWarnStr)); Flags.bHugeFileLoadState = true; - if (InfoBoxLng(MB_YESNO, L"MsgFileSizeWarning", IDS_MUI_WARN_LOAD_BIG_FILE, sizeStr, sizeWarnStr) != IDYES) { + if (INFOBOX_ANSW(InfoBoxLng(MB_YESNO, L"MsgFileSizeWarning", IDS_MUI_WARN_LOAD_BIG_FILE, sizeStr, sizeWarnStr)) != IDYES) { CloseHandle(hFile); Encoding_Forced(CPI_NONE); return false; @@ -1085,7 +1086,7 @@ bool EditLoadFile( // check for unknown file/extension status->bUnknownExt = false; if (!Style_HasLexerForExt(pszFile)) { - INT_PTR const answer = InfoBoxLng(MB_YESNO, L"MsgFileUnknownExt", IDS_MUI_WARN_UNKNOWN_EXT, PathFindFileName(pszFile)); + WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO, L"MsgFileUnknownExt", IDS_MUI_WARN_UNKNOWN_EXT, PathFindFileName(pszFile))); if (!((IDOK == answer) || (IDYES == answer))) { CloseHandle(hFile); Encoding_Forced(CPI_NONE); @@ -1122,7 +1123,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 = (InfoBoxLng(MB_OKCANCEL, L"MsgNoOrWrongPassphrase", IDS_MUI_NOPASS) == IDOK); + bReadSuccess = (INFOBOX_ANSW(InfoBoxLng(MB_OKCANCEL, L"MsgNoOrWrongPassphrase", IDS_MUI_NOPASS)) == IDOK); if (!bReadSuccess) { Encoding_Forced(CPI_NONE); FreeMem(lpData); @@ -1475,7 +1476,7 @@ bool EditSaveFile( FreeMem(lpDataWide); - if (!bCancelDataLoss || InfoBoxLng(MB_OKCANCEL, L"MsgConv3", IDS_MUI_ERR_UNICODE2) == IDOK) { + if (!bCancelDataLoss || INFOBOX_ANSW(InfoBoxLng(MB_OKCANCEL, L"MsgConv3", IDS_MUI_ERR_UNICODE2)) == IDOK) { SetEndOfFile(hFile); if (cbDataConverted != 0) { bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpData, cbDataConverted, &bytesWritten); @@ -6618,27 +6619,7 @@ bool EditFindNext(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bExtendSelection, boo SciCall_CallTipCancel(); - DocPos iPos = -1LL; - - if (start >= end) { - DocPos const _start = start; - DocPos const _end = end; - end = min_p(start, iDocEndPos); - start = 0LL; - iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, true, FRMOD_NORM); - - if ((iPos < 0LL) || (end == _start) || (IDOK != InfoBoxLng(MB_OKCANCEL, L"MsgFindWrap1", IDS_MUI_FIND_WRAPFW))) { - bSuppressNotFound = (iPos != -1LL); - if (iPos < 0LL) { - start = _start; - end = _end; - } - } - } - - if (iPos < 0LL) { - iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, true, FRMOD_NORM); - } + DocPos iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, true, FRMOD_NORM); if ((iPos < -1LL) && (lpefr->fuFlags & SCFIND_REGEXP)) { InfoBoxLng(MB_ICONWARNING, L"MsgInvalidRegex", IDS_MUI_REGEX_INVALID); @@ -6647,22 +6628,23 @@ bool EditFindNext(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bExtendSelection, boo UpdateStatusbar(false); if (!lpefr->bNoFindWrap && !bSuppressNotFound) { DocPos const _start = start; - DocPos const _end = end; + //DocPos const _end = end; end = min_p(start, iDocEndPos); start = 0LL; iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, false, FRMOD_WRAPED); - if ((iPos < 0LL) || (end == _start) || (IDOK != InfoBoxLng(MB_OKCANCEL, L"MsgFindWrap2", IDS_MUI_FIND_WRAPFW))) { + if ((iPos < 0LL) || (end == _start)) { if ((iPos < -1) && (lpefr->fuFlags & SCFIND_REGEXP)) { - InfoBoxLng(MB_ICONWARNING, L"MsgInvalidRegex2", IDS_MUI_REGEX_INVALID); - } - bSuppressNotFound = (iPos != -1LL); - if (iPos < 0LL) { - start = _start; - end = _end; + InfoBoxLng(MB_ICONWARNING, L"MsgInvalidRegex", IDS_MUI_REGEX_INVALID); + bSuppressNotFound = true; } } else { - bFoundWrapAround = true; + LONG const result = InfoBoxLng(MB_OKCANCEL, L"MsgFindWrap1", IDS_MUI_FIND_WRAPFW); + if (INFOBOX_ANSW(result) != IDOK) { + iPos = -1LL; + bSuppressNotFound = true; + } + bFoundWrapAround = (INFOBOX_MODE(result) != 0); } } } @@ -6726,28 +6708,7 @@ bool EditFindPrev(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bExtendSelection, boo SciCall_CallTipCancel(); - DocPos iPos = -1LL; - - if (start <= end) { - DocPos const _start = start; - DocPos const _end = end; - end = max_p(start, 0LL); - start = iDocEndPos; - - iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, true, FRMOD_NORM); - - if ((iPos < 0LL) || (start == _start) || (IDOK != InfoBoxLng(MB_OKCANCEL, L"MsgFindWrap1", IDS_MUI_FIND_WRAPRE))) { - bSuppressNotFound = (iPos != -1LL); - if (iPos < 0LL) { - start = _start; - end = _end; - } - } - } - - if (iPos < 0LL) { - iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, true, FRMOD_NORM); - } + DocPos iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, true, FRMOD_NORM); if ((iPos < -1LL) && (sFlags & SCFIND_REGEXP)) { InfoBoxLng(MB_ICONWARNING, L"MsgInvalidRegex", IDS_MUI_REGEX_INVALID); @@ -6756,22 +6717,23 @@ bool EditFindPrev(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bExtendSelection, boo UpdateStatusbar(false); if (!lpefr->bNoFindWrap && !bSuppressNotFound) { DocPos const _start = start; - DocPos const _end = end; + //DocPos const _end = end; end = max_p(start, 0LL); start = iDocEndPos; iPos = _FindInTarget(szFind, slen, sFlags, &start, &end, false, FRMOD_WRAPED); - if ((iPos < 0LL) || (start == _start) || (IDOK != InfoBoxLng(MB_OKCANCEL, L"MsgFindWrap2", IDS_MUI_FIND_WRAPRE))) { + if ((iPos < 0LL) || (start == _start)) { if ((iPos < -1LL) && (sFlags & SCFIND_REGEXP)) { - InfoBoxLng(MB_ICONWARNING, L"MsgInvalidRegex2", IDS_MUI_REGEX_INVALID); - } - bSuppressNotFound = (iPos != -1LL); - if (iPos < 0LL) { - start = _start; - end = _end; + InfoBoxLng(MB_ICONWARNING, L"MsgInvalidRegex", IDS_MUI_REGEX_INVALID); + bSuppressNotFound = true; } } else { - bFoundWrapAround = true; + LONG const result = InfoBoxLng(MB_OKCANCEL, L"MsgFindWrap2", IDS_MUI_FIND_WRAPRE); + if (INFOBOX_ANSW(result) != IDOK) { + iPos = -1LL; + bSuppressNotFound = true; + } + bFoundWrapAround = (INFOBOX_MODE(result) != 0); } } } diff --git a/src/Notepad3.c b/src/Notepad3.c index a175d46e5..7c83ac829 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -3343,7 +3343,7 @@ LRESULT MsgChangeNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) bool bRevertFile = (FileWatching.FileWatchingMode == FWM_AUTORELOAD && !GetDocModified()); if (!bRevertFile) { - INT_PTR const answer = InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_FILECHANGENOTIFY); + WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_FILECHANGENOTIFY)); bRevertFile = ((IDOK == answer) || (IDYES == answer)); } @@ -3360,7 +3360,7 @@ LRESULT MsgChangeNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) InstallFileWatching(true); } } else { - INT_PTR const answer = InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_FILECHANGENOTIFY2); + WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_FILECHANGENOTIFY2)); if ((IDOK == answer) || (IDYES == answer)) { FileSave(true, false, false, false, Flags.bPreserveFileModTime); } else if (!PathIsExistingFile(Globals.CurrentFile)) { @@ -3994,7 +3994,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) case IDM_FILE_REVERT: if (GetDocModified()) { - INT_PTR const answer = InfoBoxLng(MB_YESNO | MB_ICONQUESTION, NULL, IDS_MUI_ASK_REVERT); + WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONQUESTION, NULL, IDS_MUI_ASK_REVERT)); if (!((IDOK == answer) || (IDYES == answer))) { break; } @@ -4318,7 +4318,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) cpi_enc_t iNewEncoding = Encoding_MapSignature(Encoding_GetCurrent()); if (GetDocModified()) { - INT_PTR const answer = InfoBoxLng(MB_YESNO | MB_ICONQUESTION, NULL, IDS_MUI_ASK_RECODE); + WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONQUESTION, NULL, IDS_MUI_ASK_RECODE)); if (!((IDOK == answer) || (IDYES == answer))) { break; } @@ -7863,7 +7863,7 @@ LRESULT MsgNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) WCHAR wch[64] = {L'\0'}; GetLngString(msgid, wch, COUNTOF(wch)); - INT_PTR const answer = InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_WARN_NORMALIZE_EOLS, wch); + WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_WARN_NORMALIZE_EOLS, wch)); if ((IDOK == answer) || (IDYES == answer)) { PostWMCommand(hwnd, eol_cmd); @@ -9890,7 +9890,7 @@ bool FileLoad(bool bDontSave, bool bNew, bool bReload, if (!bReload && !PathIsExistingFile(szFilePath)) { bool bCreateFile = s_flagQuietCreate; if (!bCreateFile) { - INT_PTR const answer = InfoBoxLng(MB_YESNO | MB_ICONQUESTION, NULL, IDS_MUI_ASK_CREATE, PathFindFileName(szFilePath)); + WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONQUESTION, NULL, IDS_MUI_ASK_CREATE, PathFindFileName(szFilePath))); if ((IDOK == answer) || (IDYES == answer)) { bCreateFile = true; } @@ -10407,13 +10407,13 @@ bool FileSave(bool bSaveAlways, bool bAsk, bool bSaveAs, bool bSaveCopy, bool bP // if current file is settings/config file: ask to start if (Flags.bSettingsFileSoftLocked && !s_flagAppIsClosing) { //~ LoadSettings(); NOT all settings will be applied ... - INT_PTR answer = 0; + WORD answer = 0; if (Settings.SaveSettings) { WCHAR tch[256] = { L'\0' }; LoadLngStringW(IDS_MUI_RELOADCFGSEX, tch, COUNTOF(tch)); - answer = InfoBoxLng(MB_YESNO | MB_ICONWARNING, L"ReloadExSavedCfg", IDS_MUI_RELOADSETTINGS, tch); + answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, L"ReloadExSavedCfg", IDS_MUI_RELOADSETTINGS, tch)); } else { - answer = InfoBoxLng(MB_YESNO | MB_ICONINFORMATION, L"ReloadExSavedCfg", IDS_MUI_RELOADSETTINGS, L""); + answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONINFORMATION, L"ReloadExSavedCfg", IDS_MUI_RELOADSETTINGS, L"")); } if ((IDOK == answer) || (IDYES == answer)) { DialogNewWindow(Globals.hwndMain, false, Globals.CurrentFile); @@ -10703,7 +10703,7 @@ bool ActivatePrevInst() return true; } // IsWindowEnabled() - INT_PTR const answer = InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_ERR_PREVWINDISABLED); + WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_ERR_PREVWINDISABLED)); if ((IDOK == answer) || (IDYES == answer)) { return false; } @@ -10793,7 +10793,7 @@ bool ActivatePrevInst() return true; } // IsWindowEnabled() - INT_PTR const answer = InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_ERR_PREVWINDISABLED); + WORD const answer = INFOBOX_ANSW(InfoBoxLng(MB_YESNO | MB_ICONWARNING, NULL, IDS_MUI_ERR_PREVWINDISABLED)); return ((IDOK == answer) || (IDYES == answer)) ? false : true;; } return false; diff --git a/src/crypto/crypto.c b/src/crypto/crypto.c index 13a47da03..09e27d11f 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 = (InfoBoxLng(MB_RETRYCANCEL | MB_ICONWARNING, NULL, IDS_MUI_PASS_FAILURE) == IDRETRY); + bRetryPassPhrase = (INFOBOX_ANSW(InfoBoxLng(MB_RETRYCANCEL | MB_ICONWARNING, NULL, IDS_MUI_PASS_FAILURE)) == IDRETRY); if (!bRetryPassPhrase) { // enable raw encryption read