From 1f967767571048a8bbc3c209ecc7d0aa34c11f02 Mon Sep 17 00:00:00 2001 From: ozone10 Date: Mon, 20 Mar 2023 16:46:05 +0100 Subject: [PATCH] Fix find dialog flicker When using Select and Find cmds first time, and find dialog is not already created. Fix #9536, fix #13381, close #13383 --- .../src/ScintillaComponent/FindReplaceDlg.cpp | 22 +++++++++++-------- .../src/ScintillaComponent/FindReplaceDlg.h | 2 +- .../WinControls/StaticDialog/StaticDialog.cpp | 4 ++-- .../WinControls/StaticDialog/StaticDialog.h | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index b8e010823..bef6ecdd2 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -282,7 +282,7 @@ FindReplaceDlg::~FindReplaceDlg() delete[] _uniFileName; } -void FindReplaceDlg::create(int dialogID, bool isRTL, bool msgDestParent) +void FindReplaceDlg::create(int dialogID, bool isRTL, bool msgDestParent, bool toShow) { StaticDialog::create(dialogID, isRTL, msgDestParent); fillFindHistory(); @@ -294,7 +294,7 @@ void FindReplaceDlg::create(int dialogID, bool isRTL, bool msgDestParent) DPIManager& dpiManager = NppParameters::getInstance()._dpiManager; - RECT rect; + RECT rect{}; getClientRect(rect); _tab.init(_hInst, _hSelf, false, true); NppDarkMode::subclassTabControl(_tab.getHSelf()); @@ -325,25 +325,29 @@ void FindReplaceDlg::create(int dialogID, bool isRTL, bool msgDestParent) _initialWindowRect.bottom = _initialWindowRect.bottom - _initialWindowRect.top; _initialWindowRect.top = 0; - RECT dlgRc = {}; + RECT dlgRc{}; getWindowRect(dlgRc); - RECT countRc = {}; + RECT countRc{}; ::GetWindowRect(::GetDlgItem(_hSelf, IDCCOUNTALL), &countRc); NppParameters& nppParam = NppParameters::getInstance(); NppGUI& nppGUI = nppParam.getNppGUI(); + + const UINT swpFlags = toShow ? SWP_SHOWWINDOW : SWP_HIDEWINDOW; if (nppGUI._findWindowPos.bottom - nppGUI._findWindowPos.top != 0) // check height against 0 as a test of valid data from config { RECT rc = getViewablePositionRect(nppGUI._findWindowPos); - ::SetWindowPos(_hSelf, HWND_TOP, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW); + ::SetWindowPos(_hSelf, HWND_TOP, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, swpFlags); } else { - goToCenter(); + goToCenter(swpFlags); } - _lesssModeHeight = countRc.bottom - dlgRc.top + _statusBar.getHeight() + dpiManager.scaleY(10); + RECT rcStatusBar{}; + ::GetClientRect(_statusBar.getHSelf(), &rcStatusBar); + _lesssModeHeight = (countRc.bottom - dlgRc.top) + (rcStatusBar.bottom - rcStatusBar.top) + dpiManager.scaleY(10); if (nppGUI._findWindowLessMode) { @@ -4095,7 +4099,7 @@ void FindReplaceDlg::doDialog(DIALOG_TYPE whichType, bool isRTL, bool toShow) if (!isCreated()) { _isRTL = isRTL; - create(IDD_FIND_REPLACE_DLG, isRTL); + create(IDD_FIND_REPLACE_DLG, isRTL, true, toShow); } if (whichType == FINDINFILES_DLG) @@ -4107,7 +4111,7 @@ void FindReplaceDlg::doDialog(DIALOG_TYPE whichType, bool isRTL, bool toShow) else enableReplaceFunc(whichType == REPLACE_DLG); - ::SetFocus(::GetDlgItem(_hSelf, IDFINDWHAT)); + ::SetFocus(toShow ? ::GetDlgItem(_hSelf, IDFINDWHAT) : (*_ppEditView)->getHSelf()); display(toShow, true); } diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h index 6e9c919e0..383cdb728 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.h @@ -261,7 +261,7 @@ public : _ppEditView = ppEditView; }; - virtual void create(int dialogID, bool isRTL = false, bool msgDestParent = true); + virtual void create(int dialogID, bool isRTL = false, bool msgDestParent = true, bool toShow = true); void initOptionsFromDlg(); diff --git a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp index 14eb6ac93..b231089d5 100644 --- a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp +++ b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp @@ -64,7 +64,7 @@ POINT StaticDialog::getTopPoint(HWND hwnd, bool isLeft) const return p; } -void StaticDialog::goToCenter() +void StaticDialog::goToCenter(UINT swpFlags) { RECT rc{}; ::GetClientRect(_hParent, &rc); @@ -76,7 +76,7 @@ void StaticDialog::goToCenter() int x = center.x - (_rc.right - _rc.left)/2; int y = center.y - (_rc.bottom - _rc.top)/2; - ::SetWindowPos(_hSelf, HWND_TOP, x, y, _rc.right - _rc.left, _rc.bottom - _rc.top, SWP_SHOWWINDOW); + ::SetWindowPos(_hSelf, HWND_TOP, x, y, _rc.right - _rc.left, _rc.bottom - _rc.top, swpFlags); } void StaticDialog::display(bool toShow, bool enhancedPositioningCheckWhenShowing) const diff --git a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.h b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.h index bb938285c..b00aa491a 100644 --- a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.h +++ b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.h @@ -49,7 +49,7 @@ public : void redrawDlgItem(const int nIDDlgItem, bool forceUpdate = false) const; - void goToCenter(); + void goToCenter(UINT swpFlags = SWP_SHOWWINDOW); void display(bool toShow = true, bool enhancedPositioningCheckWhenShowing = false) const;