From fb086bbcdaadc2b0c434948e0397c8395b6b3a94 Mon Sep 17 00:00:00 2001 From: ozone10 Date: Sun, 19 May 2024 10:16:20 +0200 Subject: [PATCH] Fix moving Find dialog to center of Notepad++ bug (new DPI manager) Move window for dpi change for goToCenter(). ref #14959 Close #15158 --- PowerEditor/src/MISC/md5/md5Dlgs.cpp | 8 +++++-- .../src/ScintillaComponent/FindReplaceDlg.cpp | 23 +++++++++++++++++-- .../src/WinControls/AboutDlg/AboutDlg.cpp | 12 ++++------ .../StaticDialog/RunDlg/RunDlg.cpp | 3 ++- .../WinControls/StaticDialog/StaticDialog.cpp | 10 ++++++++ .../WinControls/StaticDialog/StaticDialog.h | 1 + 6 files changed, 44 insertions(+), 13 deletions(-) diff --git a/PowerEditor/src/MISC/md5/md5Dlgs.cpp b/PowerEditor/src/MISC/md5/md5Dlgs.cpp index 02de5735e..b5a6e5946 100644 --- a/PowerEditor/src/MISC/md5/md5Dlgs.cpp +++ b/PowerEditor/src/MISC/md5/md5Dlgs.cpp @@ -97,6 +97,8 @@ intptr_t CALLBACK HashFromFilesDlg::run_dlgProc(UINT message, WPARAM wParam, LPA setPositionDpi(lParam); + getWindowRect(_rc); + return TRUE; } @@ -303,7 +305,7 @@ void HashFromFilesDlg::doDialog(bool isRTL) } // Adjust the position in the center - goToCenter(SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE); + moveForDpiChange(); goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE); } @@ -545,6 +547,8 @@ intptr_t CALLBACK HashFromTextDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR setPositionDpi(lParam); + getWindowRect(_rc); + return TRUE; } @@ -659,7 +663,7 @@ void HashFromTextDlg::doDialog(bool isRTL) } // Adjust the position in the center - goToCenter(SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE); + moveForDpiChange(); goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE); } diff --git a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp index 338e9624b..4bb37e95a 100644 --- a/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp +++ b/PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp @@ -349,7 +349,9 @@ void FindReplaceDlg::create(int dialogID, bool isRTL, bool msgDestParent, bool t 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, swpFlags); + ::SetWindowPos(_hSelf, HWND_TOP, rc.left, rc.top, 0, 0, SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE); + ::SetWindowPos(_hSelf, HWND_TOP, 0, 0, _rc.right - _rc.left, _rc.bottom - _rc.top, swpFlags | SWP_NOMOVE); + if ((swpFlags & SWP_SHOWWINDOW) == SWP_SHOWWINDOW) ::SendMessageW(_hSelf, DM_REPOSITION, 0, 0); } @@ -1799,6 +1801,11 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA setPositionDpi(lParam, SWP_NOZORDER | SWP_NOACTIVATE); + _rc.left = 0; + _rc.top = 0; + _rc.right = _szMinDialog.cx + _szBorder.cx; + _rc.bottom = _szMinDialog.cy + _szBorder.cy; + return TRUE; } @@ -1977,28 +1984,40 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA case IDM_SEARCH_FIND: if (_currentStatus == FIND_DLG) + { + moveForDpiChange(); goToCenter(); + } else enableReplaceFunc(false); return TRUE; case IDM_SEARCH_REPLACE: if (_currentStatus == REPLACE_DLG) + { + moveForDpiChange(); goToCenter(); + } else enableReplaceFunc(true); return TRUE; case IDM_SEARCH_FINDINFILES: if (_currentStatus == FINDINFILES_DLG) + { + moveForDpiChange(); goToCenter(); + } else enableFindInFilesFunc(); return TRUE; case IDM_SEARCH_MARK: if (_currentStatus == MARK_DLG) + { + moveForDpiChange(); goToCenter(); + } else enableMarkFunc(); return TRUE; @@ -4843,7 +4862,7 @@ void FindReplaceDlg::combo2ExtendedMode(int comboID) ::SendDlgItemMessage(_hSelf, IDREGEXP, BM_SETCHECK, FALSE, 0); delete [] newBuffer; - } + } } void FindReplaceDlg::drawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) diff --git a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp index 8c0b04dec..35d2a1056 100644 --- a/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp +++ b/PowerEditor/src/WinControls/AboutDlg/AboutDlg.cpp @@ -61,9 +61,6 @@ intptr_t CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar _pageLink.init(_hInst, _hSelf); _pageLink.create(::GetDlgItem(_hSelf, IDC_HOME_ADDR), L"https://notepad-plus-plus.org/"); - - getClientRect(_rc); - return TRUE; } @@ -98,7 +95,7 @@ intptr_t CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar _dpiManager.setDpiWP(wParam); destroy(); //setPositionDpi(lParam); - getClientRect(_rc); + getWindowRect(_rc); return TRUE; } @@ -151,7 +148,7 @@ void AboutDlg::doDialog() create(IDD_ABOUTBOX); // Adjust the position of AboutBox - goToCenter(SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE); + moveForDpiChange(); goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE); } @@ -353,7 +350,6 @@ intptr_t CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM _debugInfoStr += _loadedPlugins.length() == 0 ? L"none" : _loadedPlugins; _debugInfoStr += L"\r\n"; - getClientRect(_rc); return TRUE; } @@ -381,8 +377,8 @@ intptr_t CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM case WM_DPICHANGED: { _dpiManager.setDpiWP(wParam); - getClientRect(_rc); setPositionDpi(lParam); + getWindowRect(_rc); return TRUE; } @@ -433,7 +429,7 @@ void DebugInfoDlg::doDialog() refreshDebugInfo(); // Adjust the position of DebugBox - goToCenter(SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE); + moveForDpiChange(); goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE); } diff --git a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp index c2d90112b..b5148d0bb 100644 --- a/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp +++ b/PowerEditor/src/WinControls/StaticDialog/RunDlg/RunDlg.cpp @@ -315,6 +315,7 @@ intptr_t CALLBACK RunDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam { _dpiManager.setDpiWP(wParam); setPositionDpi(lParam); + getWindowRect(_rc); return TRUE; } @@ -446,7 +447,7 @@ void RunDlg::doDialog(bool isRTL) create(IDD_RUN_DLG, isRTL); // Adjust the position in the center - goToCenter(SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE); + moveForDpiChange(); goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE); ::SetFocus(::GetDlgItem(_hSelf, IDC_COMBO_RUN_PATH)); } diff --git a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp index bbc8b05e9..d541b6000 100644 --- a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp +++ b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp @@ -97,6 +97,16 @@ void StaticDialog::goToCenter(UINT swpFlags) ::SendMessageW(_hSelf, DM_REPOSITION, 0, 0); } +bool StaticDialog::moveForDpiChange() +{ + if (_dpiManager.getDpi() != _dpiManager.getDpiForWindow(_hParent)) + { + goToCenter(SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE); + return true; + } + return false; +} + void StaticDialog::display(bool toShow, bool enhancedPositioningCheckWhenShowing) const { if (toShow) diff --git a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.h b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.h index aa968edec..9aa41d1f4 100644 --- a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.h +++ b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.h @@ -54,6 +54,7 @@ public : void redrawDlgItem(const int nIDDlgItem, bool forceUpdate = false) const; void goToCenter(UINT swpFlags = SWP_SHOWWINDOW); + bool moveForDpiChange(); void display(bool toShow = true, bool enhancedPositioningCheckWhenShowing = false) const;