diff --git a/agent-trail/architecture/codebase-and-conventions.md b/agent-trail/architecture/codebase-and-conventions.md index 416b6f8a6..017d249f5 100644 --- a/agent-trail/architecture/codebase-and-conventions.md +++ b/agent-trail/architecture/codebase-and-conventions.md @@ -83,6 +83,10 @@ Before an approved vendored-library change, consult the [Lexilla patch registry] - `ComboBox_SetText*` fires `CBN_EDITCHANGE` synchronously; reset one-shot flags before calling it. - `_FindInTarget` has an 8192-byte `chFind` buffer; a longer pattern makes `WideCharToMultiByte` fail (`len` = -1) and Scintilla reports "not found". +### Find/Replace dialog placement + +- For live recreation, capture the old screen rectangle and restore against its monitor. [`SetDlgPos`](../../src/Dialogs.c#L6157) is for owner-relative settings and clamps to the owner's monitor; [`_RestoreFindReplaceDlgPosition`](../../src/Edit.c#L6807) uses the old rectangle's monitor and fits the dialog again after any DPI resize. + ### Dynamic string/path buffer lifetime `StrgCreate(NULL)` can return a valid handle without allocating its text buffer; `StrgGet(h) == NULL` before initialization is normal, not proof of allocation failure. Initialize the fresh handle with `StrgReset(h, text)` and check its result (`> 0`) before using the text ([source](../../src/DynStrg.c#L432-L473): `StrgCreate`, `StrgReset`, `StrgGet`). diff --git a/agent-trail/domain/localization.md b/agent-trail/domain/localization.md index 2fe4c36ad..afc8687ef 100644 --- a/agent-trail/domain/localization.md +++ b/agent-trail/domain/localization.md @@ -6,6 +6,7 @@ There are 26 locales under `language\np3__\`; language packs buil ## Resource invariants +- Set the thread UI language before caching strings from `LoadMUILibrary`. Loading the module alone can leave `LoadStringW` resolving the previous language. Keep `SetMuiLanguage` before the status label loads in [`LoadLanguageResources`](../../src/MuiLanguage.c#L467-L486). A headless probe using the built language packs got `Z` when switching from German to French before `SetThreadUILanguage`, and `Lgn` after. - Every `IDS_MUI_*` in `language\common_res.h` must exist in all locale `strings_*.rc` files. A missing entry does not fail the build: `LoadLngStringW()` silently falls back to the built-in English string. - Every `IDS_LEX_*` must exist in the corresponding locale `lexer_*.rc` files. See [Lexer development](lexer-development.md) for style-label localization. - `.rc` files must be UTF-8 without BOM and use CRLF. Use `Build\rc_to_utf8.cmd` to strip accidental BOMs. In PowerShell use `[System.Text.UTF8Encoding]::new($false)`; in Python write `\r\n` explicitly. diff --git a/src/Edit.c b/src/Edit.c index f54181c88..39c037632 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -6799,6 +6799,34 @@ static void _AddPatternToComboMRU(HWND hwnd, int nIDDlgItem, LPCWSTR pszItem) // // EditFindReplaceDlgProc() // +typedef struct { + LPEDITFINDREPLACE pEfrData; + const FindReplaceDlgRestore* pRestore; +} FindReplaceDlgInit; + +static void _RestoreFindReplaceDlgPosition(HWND hwnd, const RECT* pPreviousRect) +{ + MONITORINFO mi = { sizeof(mi) }; + if (IsRectEmpty(pPreviousRect) || + !GetMonitorInfo(MonitorFromRect(pPreviousRect, MONITOR_DEFAULTTONEAREST), &mi)) { + return; + } + + // The first move can resize the dialog via WM_DPICHANGED. Fit it again using the new size. + for (int i = 0; i < 2; ++i) { + RECT rc; + if (!GetWindowRect(hwnd, &rc)) { + return; + } + LONG const x = max_l(mi.rcWork.left, min_l(pPreviousRect->left, mi.rcWork.right - (rc.right - rc.left))); + LONG const y = max_l(mi.rcWork.top, min_l(pPreviousRect->top, mi.rcWork.bottom - (rc.bottom - rc.top))); + if (rc.left == x && rc.top == y) { + break; + } + SetWindowPos(hwnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE); + } +} + extern int g_flagMatchText; // TODO: §§§ get rid of this buffer @@ -6811,6 +6839,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar static LPEDITFINDREPLACE s_pEfrData = NULL; static bool s_bIsReplaceDlg = false; + static bool s_bRestoreFocusedView = false; static UINT_PTR pTimerIdentifier = 0; @@ -6835,9 +6864,9 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar switch (umsg) { case WM_INITDIALOG: { - // the global static Find/Replace data structure (main) - SetWindowLongPtr(hwnd, DWLP_USER, (LONG_PTR)lParam); - s_pEfrData = (LPEDITFINDREPLACE)GetWindowLongPtr(hwnd, DWLP_USER); + const FindReplaceDlgInit* const pInit = (const FindReplaceDlgInit*)lParam; + s_pEfrData = pInit->pEfrData; + s_bRestoreFocusedView = pInit->pRestore && pInit->pRestore->bFocusedView; Globals.hwndDlgFindReplace = hwnd; s_bIsReplaceDlg = (GetDlgItem(hwnd, IDC_REPLACETEXT) != NULL); @@ -6963,7 +6992,15 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar // Now set combobox text — CBN_EDITCHANGE will fire and call // _SetSearchFlags(), which can now read the correct checkbox states. - if (!GetWindowTextLengthW(GetDlgItem(hwnd, IDC_FINDTEXT))) { + if (pInit->pRestore) { + // Restore both fields before edit notifications can sync the partially initialized dialog. + s_pEfrData = NULL; + ComboBox_SetTextHW(hwnd, IDC_FINDTEXT, pInit->pEfrData->chFindPattern); + if (s_bIsReplaceDlg) { + ComboBox_SetTextHW(hwnd, IDC_REPLACETEXT, pInit->pEfrData->chReplaceTemplate); + } + s_pEfrData = pInit->pEfrData; + } else if (!GetWindowTextLengthW(GetDlgItem(hwnd, IDC_FINDTEXT))) { if (StrgIsNotEmpty(s_pEfrData->chFindPattern)) { ComboBox_SetTextHW(hwnd, IDC_FINDTEXT, s_pEfrData->chFindPattern); } @@ -6976,7 +7013,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar } } - if (s_bIsReplaceDlg) { + if (s_bIsReplaceDlg && !pInit->pRestore) { if (!GetWindowTextLengthW(GetDlgItem(hwnd, IDC_REPLACETEXT))) { if (StrgIsNotEmpty(s_pEfrData->chReplaceTemplate)) { ComboBox_SetTextHW(hwnd, IDC_REPLACETEXT, s_pEfrData->chReplaceTemplate); @@ -6996,6 +7033,9 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar SetDlgPos(hwnd, s_xFindReplaceDlgSave, s_yFindReplaceDlgSave); s_bSwitchedFindReplace = false; } + else if (pInit->pRestore) { + _RestoreFindReplaceDlgPosition(hwnd, &pInit->pRestore->windowRect); + } else { if (Settings.FindReplaceDlgPosX == CW_USEDEFAULT || Settings.FindReplaceDlgPosY == CW_USEDEFAULT) { CenterDlgInParent(hwnd, false); @@ -7050,6 +7090,11 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar EnableWindow(Globals.hwndMain, (BOOL)wParam); return TRUE; + case WM_CLOSE: + // Language switching needs the modeless dialog destroyed before the resource DLL is unloaded. + DestroyWindow(hwnd); + return TRUE; + case WM_DESTROY: { KillTimer(hwnd, pTimerIdentifier); @@ -7374,19 +7419,26 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar break; case IDT_TIMER_CALLBACK_MRKALL: { - //DocPos const startPos = (DocPos)lParam; - s_anyMatch = _FindHasMatch(s_pEfrData->hwnd, s_pEfrData, 0, false); + bool const bRestoreFocusedView = s_bRestoreFocusedView; + s_bRestoreFocusedView = false; + static wchar_t s_lastFind[FNDRPL_BUFFER] = { L'\0' }; + bool const bRefreshMarks = s_pEfrData->bMarkOccurences && + (s_pEfrData->bStateChanged || (StringCchCompareX(s_lastFind, StrgGet(s_pEfrData->chFindPattern)) != 0)); + if (bRefreshMarks) { + StringCchCopyW(s_lastFind, COUNTOF(s_lastFind), StrgGet(s_pEfrData->chFindPattern)); + } + s_anyMatch = _FindHasMatch(s_pEfrData->hwnd, s_pEfrData, 0, bRefreshMarks); InvalidateRect(GetDlgItem(hwnd, IDC_FINDTEXT), NULL, TRUE); // coloring - if (s_pEfrData->bMarkOccurences) { - static wchar_t s_lastFind[FNDRPL_BUFFER] = { L'\0' }; - if (s_pEfrData->bStateChanged || (StringCchCompareX(s_lastFind, StrgGet(s_pEfrData->chFindPattern)) != 0)) { - StringCchCopyW(s_lastFind, COUNTOF(s_lastFind), StrgGet(s_pEfrData->chFindPattern)); - /*~s_anyMatch=~*/ _FindHasMatch(s_pEfrData->hwnd, s_pEfrData, 0, s_pEfrData->bMarkOccurences); - if (FocusedView.HideNonMatchedLines) { - EditToggleView(s_pEfrData->hwnd); - } + if (bRefreshMarks) { + if (bRestoreFocusedView && s_anyMatch == MATCH && (Settings.FocusViewMarkerMode & FVMM_FOLD)) { + // Fold the rebuilt matches without re-running Focused View's bookmark action. + FocusedView.HideNonMatchedLines = true; + EditFoldMarkedLineRange(s_pEfrData->hwnd, true); + UpdateDocumentReadOnlyState(); + } else if (FocusedView.HideNonMatchedLines) { + EditToggleView(s_pEfrData->hwnd); } - } else if (s_pEfrData->bStateChanged) { + } else if (!s_pEfrData->bMarkOccurences && s_pEfrData->bStateChanged) { if (FocusedView.HideNonMatchedLines) { SendWMCommand(hwnd, IDC_TOGGLE_VISIBILITY); } else { @@ -7422,6 +7474,7 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar case IDC_TOGGLE_VISIBILITY: if (s_pEfrData) { + s_bRestoreFocusedView = false; EditToggleView(s_pEfrData->hwnd); if (!FocusedView.HideNonMatchedLines) { s_pEfrData->bStateChanged = true; @@ -7799,17 +7852,22 @@ static INT_PTR CALLBACK EditFindReplaceDlgProc(HWND hwnd, UINT umsg, WPARAM wPar // // EditFindReplaceDlg() // -HWND EditFindReplaceDlg(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bReplace) +HWND EditFindReplaceDlg(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bReplace, const FindReplaceDlgRestore* pRestore) { lpefr->hwnd = hwnd; + FindReplaceDlgInit const init = { lpefr, pRestore }; HWND hDlg = CreateThemedDialogParam(Globals.hLngResContainer, (bReplace) ? MAKEINTRESOURCEW(IDD_MUI_REPLACE) : MAKEINTRESOURCEW(IDD_MUI_FIND), GetParent(hwnd), EditFindReplaceDlgProc, - (LPARAM) lpefr); + (LPARAM)&init); if (IS_VALID_HANDLE(hDlg)) { ShowWindow(hDlg, SW_SHOW); + if (pRestore) { + _EnableFRDlgCtrls(hDlg); + } + UpdateStatusbar(true); } return hDlg; } diff --git a/src/Edit.h b/src/Edit.h index fe4d4dee3..38f6112da 100644 --- a/src/Edit.h +++ b/src/Edit.h @@ -100,7 +100,12 @@ void EditFixPositions(); void EditEnsureConsistentLineEndings(HWND hwnd); void EditGetExcerpt(HWND hwnd,LPWSTR lpszExcerpt,DWORD cchExcerpt); -HWND EditFindReplaceDlg(HWND hwnd, LPEDITFINDREPLACE lpefr, bool); +typedef struct { + RECT windowRect; + bool bFocusedView; +} FindReplaceDlgRestore; + +HWND EditFindReplaceDlg(HWND hwnd, LPEDITFINDREPLACE lpefr, bool bReplace, const FindReplaceDlgRestore* pRestore); bool EditFindNext(HWND hwnd, const LPEDITFINDREPLACE lpefr, bool bExtendSelection, bool bFocusWnd, bool bFillEmpty); bool EditFindPrev(HWND hwnd, const LPEDITFINDREPLACE lpefr, bool bExtendSelection, bool bFocusWnd, bool bFillEmpty); bool EditReplace(HWND hwnd, LPEDITFINDREPLACE lpefr); diff --git a/src/MuiLanguage.c b/src/MuiLanguage.c index 8d2b5529c..2258f02d3 100644 --- a/src/MuiLanguage.c +++ b/src/MuiLanguage.c @@ -375,9 +375,8 @@ bool GetUserPreferredLanguage(LPWSTR pszPrefLocaleName_out, int cchBuffer) //============================================================================= // // LoadLanguageResources -// return MUI_LanguageDLLs index // -unsigned LoadLanguageResources(LPCWSTR pLocaleName) { +void LoadLanguageResources(LPCWSTR pLocaleName) { FreeLanguageResources(); // reset Globals.hLngResContainer = NULL; // (!) unlink from instance resources @@ -464,6 +463,9 @@ unsigned LoadLanguageResources(LPCWSTR pLocaleName) { } } + // LoadString can still resolve the previous language until the thread UI language is set. + SetMuiLanguage(iLngIndex); + // === update language dependent items === for (cpi_enc_t enc = 0; enc < Encoding_CountOf(); ++enc) { @@ -484,8 +486,6 @@ unsigned LoadLanguageResources(LPCWSTR pLocaleName) { GetLngString(IDS_MUI_STATUSBAR_POSTFIXES, tchDefaultStrg, COUNTOF(tchDefaultStrg)); IniFileGetString(Paths.IniFile, StatusBar_Section, L"SectionPostfixes", tchDefaultStrg, tchStatusBar, COUNTOF(tchStatusBar)); ReadStrgsFromCSV(tchStatusBar, g_mxSBPostfix, STATUS_SECTOR_COUNT, MICRO_BUFFER, L"_POFX_"); - - return iLngIndex; } @@ -562,33 +562,29 @@ bool InsertLanguageMenu(HMENU hMenuBar) { // // DynamicLanguageMenuCmd() - Handles IDS_MUI_LANG_XX_YY messages // -void DynamicLanguageMenuCmd(int cmd) { +bool DynamicLanguageMenuCmd(int cmd) { // consecutive resource IDs unsigned const iLngIdx = (unsigned)((cmd >= IDS_MUI_LANG_EN_US) ? (cmd - IDS_MUI_LANG_EN_US) : MuiLanguages_CountOf()); - if (iLngIdx >= MuiLanguages_CountOf()) { - return; + if (iLngIdx >= MuiLanguages_CountOf() || MUI_LanguageDLLs[iLngIdx].bIsActive) { + return false; } - if (!MUI_LanguageDLLs[iLngIdx].bIsActive) { - DestroyMenu(Globals.hMainMenu); + DestroyMenu(Globals.hMainMenu); - // desired language - LPCWSTR desiredLocaleName = MUI_LanguageDLLs[iLngIdx].LocaleName; - SetMuiLanguage(LoadLanguageResources(desiredLocaleName)); + LoadLanguageResources(MUI_LanguageDLLs[iLngIdx].LocaleName); - Globals.hMainMenu = LoadMenu(Globals.hLngResContainer, MAKEINTRESOURCE(IDR_MUI_MAINMENU)); - if (!Globals.hMainMenu) { - InfoBoxLastError(L"LoadMenu()", 0); - CloseApplication(); - return; - } - - InsertLanguageMenu(Globals.hMainMenu); - SetMenu(Globals.hwndMain, (Settings.ShowMenubar ? Globals.hMainMenu : NULL)); - DrawMenuBar(Globals.hwndMain); + Globals.hMainMenu = LoadMenu(Globals.hLngResContainer, MAKEINTRESOURCE(IDR_MUI_MAINMENU)); + if (!Globals.hMainMenu) { + InfoBoxLastError(L"LoadMenu()", 0); + CloseApplication(); + return false; } + + InsertLanguageMenu(Globals.hMainMenu); + SetMenu(Globals.hwndMain, (Settings.ShowMenubar ? Globals.hMainMenu : NULL)); + return true; } diff --git a/src/MuiLanguage.h b/src/MuiLanguage.h index 6d01e789e..40555f41d 100644 --- a/src/MuiLanguage.h +++ b/src/MuiLanguage.h @@ -113,10 +113,10 @@ inline bool IsSameLocale(const WCHAR *ln1, const WCHAR *ln2) { #if defined(HAVE_DYN_LOAD_LIBS_MUI_LNGS) bool GetUserPreferredLanguage(LPWSTR pszPrefLocaleName_out, int cchBuffer); -unsigned LoadLanguageResources(LPCWSTR localeName); +void LoadLanguageResources(LPCWSTR localeName); void FreeLanguageResources(); bool InsertLanguageMenu(HMENU hMenuBar); -void DynamicLanguageMenuCmd(int cmd); +bool DynamicLanguageMenuCmd(int cmd); #endif // HAVE_DYN_LOAD_LIBS_MUI_LNGS diff --git a/src/Notepad3.c b/src/Notepad3.c index 74ee98671..a73e4ecba 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -1417,7 +1417,7 @@ int WINAPI wWinMain(_In_ HINSTANCE hInstance, _In_opt_ HINSTANCE hPrevInstance, // MultiLingual // #if defined(HAVE_DYN_LOAD_LIBS_MUI_LNGS) - SetMuiLanguage(LoadLanguageResources(Settings2.PreferredLanguageLocaleName)); + LoadLanguageResources(Settings2.PreferredLanguageLocaleName); #else SetMuiLanguage(GetMUILanguageIndexByLocaleName(MUI_BASE_LNG_ID)); #endif @@ -6955,13 +6955,13 @@ static bool _HandleEditFind(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) if (!IsWindow(Globals.hwndDlgFindReplace)) { // Don't overwrite cmd-line search pattern with editor selection Globals.bFindReplCopySelOrClip = !g_flagMatchText; - /*Globals.hwndDlgFindReplace =*/ EditFindReplaceDlg(Globals.hwndEdit, &s_FindReplaceData, false); + /*Globals.hwndDlgFindReplace =*/ EditFindReplaceDlg(Globals.hwndEdit, &s_FindReplaceData, false, NULL); } else { Globals.bFindReplCopySelOrClip = (GetForegroundWindow() != Globals.hwndDlgFindReplace); if (GetDlgItem(Globals.hwndDlgFindReplace, IDC_REPLACE)) { SendWMCommand(Globals.hwndDlgFindReplace, IDMSG_SWITCHTOFIND); DestroyWindow(Globals.hwndDlgFindReplace); - /*Globals.hwndDlgFindReplace =*/ EditFindReplaceDlg(Globals.hwndEdit, &s_FindReplaceData, false); + /*Globals.hwndDlgFindReplace =*/ EditFindReplaceDlg(Globals.hwndEdit, &s_FindReplaceData, false, NULL); } else { SetForegroundWindow(Globals.hwndDlgFindReplace); PostMessage(Globals.hwndDlgFindReplace, WM_NEXTDLGCTL, (WPARAM)(GetDlgItem(Globals.hwndDlgFindReplace, IDC_FINDTEXT)), 1); @@ -6976,13 +6976,13 @@ static bool _HandleEditFind(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) if (!IsWindow(Globals.hwndDlgFindReplace)) { // Don't overwrite cmd-line search pattern with editor selection Globals.bFindReplCopySelOrClip = !g_flagMatchText; - /*Globals.hwndDlgFindReplace =*/ EditFindReplaceDlg(Globals.hwndEdit, &s_FindReplaceData, true); + /*Globals.hwndDlgFindReplace =*/ EditFindReplaceDlg(Globals.hwndEdit, &s_FindReplaceData, true, NULL); } else { Globals.bFindReplCopySelOrClip = (GetForegroundWindow() != Globals.hwndDlgFindReplace); if (!GetDlgItem(Globals.hwndDlgFindReplace, IDC_REPLACE)) { SendWMCommand(Globals.hwndDlgFindReplace, IDMSG_SWITCHTOREPLACE); DestroyWindow(Globals.hwndDlgFindReplace); - /*Globals.hwndDlgFindReplace =*/ EditFindReplaceDlg(Globals.hwndEdit, &s_FindReplaceData, true); + /*Globals.hwndDlgFindReplace =*/ EditFindReplaceDlg(Globals.hwndEdit, &s_FindReplaceData, true, NULL); } else { SetForegroundWindow(Globals.hwndDlgFindReplace); PostMessage(Globals.hwndDlgFindReplace, WM_NEXTDLGCTL, (WPARAM)(GetDlgItem(Globals.hwndDlgFindReplace, IDC_FINDTEXT)), 1); @@ -8701,10 +8701,26 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) #if defined(HAVE_DYN_LOAD_LIBS_MUI_LNGS) bool const bIsLngMenuCmd = ((iLoWParam >= IDS_MUI_LANG_EN_US) && (iLoWParam < (IDS_MUI_LANG_EN_US + MuiLanguages_CountOf()))); if (bIsLngMenuCmd) { - DynamicLanguageMenuCmd(iLoWParam); + bool const bHadFindReplace = IsWindow(Globals.hwndDlgFindReplace); + bool bReplace = false; + FindReplaceDlgRestore restore = { 0 }; + if (bHadFindReplace) { + bReplace = GetDlgItem(Globals.hwndDlgFindReplace, IDC_REPLACE) != NULL; + GetWindowRect(Globals.hwndDlgFindReplace, &restore.windowRect); + restore.bFocusedView = FocusedView.HideNonMatchedLines; + } + + if (!DynamicLanguageMenuCmd(iLoWParam)) { + return FALSE; + } Style_InsertThemesMenu(Globals.hMainMenu); DrawMenuBar(Globals.hwndMain); + if (bHadFindReplace && !IsWindow(Globals.hwndDlgFindReplace)) { + Globals.bFindReplCopySelOrClip = false; + EditFindReplaceDlg(Globals.hwndEdit, &s_FindReplaceData, bReplace, &restore); + } UpdateToolbar(); + UpdateStatusbar(true); return FALSE; } #endif @@ -8735,7 +8751,10 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam) return FALSE; case IDT_TIMER_CALLBACK_MRKALL: - EditMarkAllOccurrences(Globals.hwndEdit, (bool)lParam); + // A queued editor refresh must not clear the open dialog's occurrence marks. + if (!IsWindow(Globals.hwndDlgFindReplace)) { + EditMarkAllOccurrences(Globals.hwndEdit, (bool)lParam); + } return FALSE; case IDT_TIMER_CLEAR_CALLTIP: @@ -11559,7 +11578,9 @@ const static WCHAR *const FR_StatusW[] = { L"[>--<]", L"[>>--]", L"[>>-+]", L"[+ static void _UpdateStatusbarDelayed(bool bForceRedraw) { - if (!Settings.ShowStatusbar) { + bool const bShowStatusbar = Settings.ShowStatusbar; + bool const bIsWindowFindReplace = IsWindow(Globals.hwndDlgFindReplace); + if (!bShowStatusbar && !bIsWindowFindReplace) { return; } @@ -11578,8 +11599,6 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) bool const bIsSelectionEmpty = SciCall_IsSelectionEmpty(); bool const bIsMultiSelection = Sci_IsMultiOrRectangleSelection(); bool const bIsSelCharCountable = !bIsSelectionEmpty && !bIsMultiSelection; - bool const bIsWindowFindReplace = IsWindow(Globals.hwndDlgFindReplace); - bool bIsUpdateNeeded = bForceRedraw; static WCHAR tchLn[32] = { L'\0' }; @@ -11643,7 +11662,7 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) } // ------------------------------------------------------ - if (g_iStatusbarVisible[STATUS_DOCCHAR]) { + if (bShowStatusbar && g_iStatusbarVisible[STATUS_DOCCHAR]) { static WCHAR tchChr[32] = { L'\0' }; static WCHAR tchChrs[32] = { L'\0' }; static DocPos s_iChr = -1; @@ -11673,7 +11692,7 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) } // ------------------------------------------------------ - if (g_iStatusbarVisible[STATUS_UNICODEPT]) { + if (bShowStatusbar && g_iStatusbarVisible[STATUS_UNICODEPT]) { static WCHAR tchChr[32] = { L'\0' }; static UINT64 s_wChr = L'\0'; @@ -11697,7 +11716,7 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) else StringCchPrintf(tchChr, COUNTOF(tchChr), L"0x%.4X 0x%.4X", LOWORD(wChr), HIWORD(wChr)); } - if (s_wChr != wChr) { + if (bForceRedraw || (s_wChr != wChr)) { StringCchPrintf(tchStatusBar[STATUS_UNICODEPT], txtWidth, L"%s%s%s", g_mxSBPrefix[STATUS_UNICODEPT], tchChr, g_mxSBPostfix[STATUS_UNICODEPT]); s_wChr = wChr; @@ -11755,7 +11774,7 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) // ------------------------------------------------------ // number of selected lines in statusbar - if (g_iStatusbarVisible[STATUS_SELCTLINES]) { + if (bShowStatusbar && g_iStatusbarVisible[STATUS_SELCTLINES]) { static bool s_bIsSelectionEmpty = true; static DocLn s_iLinesSelected = -1; @@ -11788,7 +11807,7 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) // ------------------------------------------------------ // try calculate expression of selection - if (g_iStatusbarVisible[STATUS_TINYEXPR]) { + if (bShowStatusbar && g_iStatusbarVisible[STATUS_TINYEXPR]) { static WCHAR tchExpression[80] = { L'\0' }; // fits "0b" + 64 bits + NUL with headroom static te_int_t s_iExErr = -3; s_dExpression = 0.0; @@ -11885,10 +11904,11 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) // ------------------------------------------------------ // number of replaced pattern - if (g_iStatusbarVisible[STATUS_OCCREPLACE] || bIsWindowFindReplace) { + static WCHAR tchRepl[64] = L"--"; + bool const bShowReplacementCount = bShowStatusbar && g_iStatusbarVisible[STATUS_OCCREPLACE]; + if (bShowReplacementCount || bIsWindowFindReplace) { static DocPosU s_iReplacedOccurrences = 0; if (bForceRedraw || (s_iReplacedOccurrences != Globals.iReplacedOccurrences)) { - static WCHAR tchRepl[64] = { L'\0' }; if (Globals.iReplacedOccurrences) { StringCchPrintf(tchRepl, COUNTOF(tchRepl), DOCPOSFMTW, Globals.iReplacedOccurrences); FormatNumberStr(tchRepl, COUNTOF(tchRepl), 0); @@ -11896,17 +11916,18 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) StringCchCopy(tchRepl, COUNTOF(tchRepl), L"--"); } - StringCchPrintf(tchStatusBar[STATUS_OCCREPLACE], txtWidth, L"%s%s%s", - g_mxSBPrefix[STATUS_OCCREPLACE], tchRepl, g_mxSBPostfix[STATUS_OCCREPLACE]); - s_iReplacedOccurrences = Globals.iReplacedOccurrences; - bIsUpdateNeeded = true; + if (bShowReplacementCount) { + StringCchPrintf(tchStatusBar[STATUS_OCCREPLACE], txtWidth, L"%s%s%s", + g_mxSBPrefix[STATUS_OCCREPLACE], tchRepl, g_mxSBPostfix[STATUS_OCCREPLACE]); + bIsUpdateNeeded = true; + } } } // ------------------------------------------------------ // get number of bytes in current encoding - if (g_iStatusbarVisible[STATUS_DOCSIZE]) { + if (bShowStatusbar && g_iStatusbarVisible[STATUS_DOCSIZE]) { static DocPos s_iTextLength = -1; DocPos const iTextLength = SciCall_GetTextLength(); if (bForceRedraw || (s_iTextLength != iTextLength)) { @@ -11922,7 +11943,7 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) } // ------------------------------------------------------ - if (g_iStatusbarVisible[STATUS_CODEPAGE]) { + if (bShowStatusbar && g_iStatusbarVisible[STATUS_CODEPAGE]) { static cpi_enc_t s_iEncoding = CPI_NONE; static bool s_bUTF8WithNul = false; cpi_enc_t const iEncoding = Encoding_GetCurrent(); @@ -11945,7 +11966,7 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) const WCHAR* const _CRLF_f = L"%sCR+LF%s"; const WCHAR* const _CRLFi_f = L"%sCR+LF*%s"; - if (g_iStatusbarVisible[STATUS_EOLMODE]) { + if (bShowStatusbar && g_iStatusbarVisible[STATUS_EOLMODE]) { static int s_iEOLMode = -1; int const eol_mode = SciCall_GetEOLMode(); @@ -11967,7 +11988,7 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) } // ------------------------------------------------------ - if (g_iStatusbarVisible[STATUS_OVRMODE]) { + if (bShowStatusbar && g_iStatusbarVisible[STATUS_OVRMODE]) { static int s_bIsOVR = -1; // int for -1 sentinel (first-paint trigger) static bool s_bPasteBoard = false; bool const bIsOVR = SciCall_GetOverType(); @@ -11989,7 +12010,7 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) } // ------------------------------------------------------ - if (g_iStatusbarVisible[STATUS_2ND_DEF]) { + if (bShowStatusbar && g_iStatusbarVisible[STATUS_2ND_DEF]) { static bool s_bUse2ndDefault = true; bool const bUse2ndDefault = Style_GetUse2ndDefault(); if (bForceRedraw || (s_bUse2ndDefault != bUse2ndDefault)) { @@ -12006,7 +12027,7 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) } // ------------------------------------------------------ - if (g_iStatusbarVisible[STATUS_LEXER]) { + if (bShowStatusbar && g_iStatusbarVisible[STATUS_LEXER]) { static int s_iCurLexer = -1; int const iCurLexer = Style_GetCurrentLexerRID(); if (bForceRedraw || (s_iCurLexer != iCurLexer)) { @@ -12030,9 +12051,11 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) int g_vStatusbarSectionWidth[STATUS_SECTOR_COUNT] = SBS_INIT_MINUS; - _CalculateStatusbarSections(g_vStatusbarSectionWidth, tchStatusBar, &bIsUpdateNeeded); + if (bShowStatusbar) { + _CalculateStatusbarSections(g_vStatusbarSectionWidth, tchStatusBar, &bIsUpdateNeeded); + } - if (bIsUpdateNeeded) { + if (bShowStatusbar && bIsUpdateNeeded) { int aStatusbarSections[STATUS_SECTOR_COUNT] = SBS_INIT_ZERO; BYTE cnt = 0; int totalWidth = 0; @@ -12078,15 +12101,6 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) // update Find/Replace dialog (if any) if (bIsWindowFindReplace) { - static WCHAR tchReplOccs[64] = { L'\0' }; - if (Globals.iReplacedOccurrences) { - StringCchPrintf(tchReplOccs, COUNTOF(tchReplOccs), DOCPOSFMTW, Globals.iReplacedOccurrences); - FormatNumberStr(tchReplOccs, COUNTOF(tchReplOccs), 0); - } - else { - StringCchCopy(tchReplOccs, COUNTOF(tchReplOccs), L"--"); - } - const WCHAR* const SBFMT = L" %s%s / %s %s%s %s%s %s%s %s%s ( %s ) "; static WCHAR tchFRStatus[128] = { L'\0' }; @@ -12095,7 +12109,7 @@ static void _UpdateStatusbarDelayed(bool bForceRedraw) g_mxSBPrefix[STATUS_DOCCOLUMN], tchCol, g_mxSBPrefix[STATUS_SELECTION], tchSel, g_mxSBPrefix[STATUS_OCCURRENCE], tchOccOf, - g_mxSBPrefix[STATUS_OCCREPLACE], tchReplOccs, + g_mxSBPrefix[STATUS_OCCREPLACE], tchRepl, FR_StatusW[Globals.FindReplaceMatchFoundState]); SetWindowText(GetDlgItem(Globals.hwndDlgFindReplace, IDS_FR_STATUS_TEXT), tchFRStatus);