Fix moving Find dialog to center of Notepad++ bug (new DPI manager)

Move window for dpi change for goToCenter().

ref #14959

Close #15158
pull/15166/head
ozone10 2024-05-19 10:16:20 +02:00 committed by Don Ho
parent d0e3a1a210
commit fb086bbcda
6 changed files with 44 additions and 13 deletions

View File

@ -97,6 +97,8 @@ intptr_t CALLBACK HashFromFilesDlg::run_dlgProc(UINT message, WPARAM wParam, LPA
setPositionDpi(lParam); setPositionDpi(lParam);
getWindowRect(_rc);
return TRUE; return TRUE;
} }
@ -303,7 +305,7 @@ void HashFromFilesDlg::doDialog(bool isRTL)
} }
// Adjust the position in the center // Adjust the position in the center
goToCenter(SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE); moveForDpiChange();
goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE); goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE);
} }
@ -545,6 +547,8 @@ intptr_t CALLBACK HashFromTextDlg::run_dlgProc(UINT message, WPARAM wParam, LPAR
setPositionDpi(lParam); setPositionDpi(lParam);
getWindowRect(_rc);
return TRUE; return TRUE;
} }
@ -659,7 +663,7 @@ void HashFromTextDlg::doDialog(bool isRTL)
} }
// Adjust the position in the center // Adjust the position in the center
goToCenter(SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE); moveForDpiChange();
goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE); goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE);
} }

View File

@ -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 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); 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) if ((swpFlags & SWP_SHOWWINDOW) == SWP_SHOWWINDOW)
::SendMessageW(_hSelf, DM_REPOSITION, 0, 0); ::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); 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; return TRUE;
} }
@ -1977,28 +1984,40 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
case IDM_SEARCH_FIND: case IDM_SEARCH_FIND:
if (_currentStatus == FIND_DLG) if (_currentStatus == FIND_DLG)
{
moveForDpiChange();
goToCenter(); goToCenter();
}
else else
enableReplaceFunc(false); enableReplaceFunc(false);
return TRUE; return TRUE;
case IDM_SEARCH_REPLACE: case IDM_SEARCH_REPLACE:
if (_currentStatus == REPLACE_DLG) if (_currentStatus == REPLACE_DLG)
{
moveForDpiChange();
goToCenter(); goToCenter();
}
else else
enableReplaceFunc(true); enableReplaceFunc(true);
return TRUE; return TRUE;
case IDM_SEARCH_FINDINFILES: case IDM_SEARCH_FINDINFILES:
if (_currentStatus == FINDINFILES_DLG) if (_currentStatus == FINDINFILES_DLG)
{
moveForDpiChange();
goToCenter(); goToCenter();
}
else else
enableFindInFilesFunc(); enableFindInFilesFunc();
return TRUE; return TRUE;
case IDM_SEARCH_MARK: case IDM_SEARCH_MARK:
if (_currentStatus == MARK_DLG) if (_currentStatus == MARK_DLG)
{
moveForDpiChange();
goToCenter(); goToCenter();
}
else else
enableMarkFunc(); enableMarkFunc();
return TRUE; return TRUE;

View File

@ -61,9 +61,6 @@ intptr_t CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar
_pageLink.init(_hInst, _hSelf); _pageLink.init(_hInst, _hSelf);
_pageLink.create(::GetDlgItem(_hSelf, IDC_HOME_ADDR), L"https://notepad-plus-plus.org/"); _pageLink.create(::GetDlgItem(_hSelf, IDC_HOME_ADDR), L"https://notepad-plus-plus.org/");
getClientRect(_rc);
return TRUE; return TRUE;
} }
@ -98,7 +95,7 @@ intptr_t CALLBACK AboutDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lPar
_dpiManager.setDpiWP(wParam); _dpiManager.setDpiWP(wParam);
destroy(); destroy();
//setPositionDpi(lParam); //setPositionDpi(lParam);
getClientRect(_rc); getWindowRect(_rc);
return TRUE; return TRUE;
} }
@ -151,7 +148,7 @@ void AboutDlg::doDialog()
create(IDD_ABOUTBOX); create(IDD_ABOUTBOX);
// Adjust the position of AboutBox // Adjust the position of AboutBox
goToCenter(SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE); moveForDpiChange();
goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE); 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 += _loadedPlugins.length() == 0 ? L"none" : _loadedPlugins;
_debugInfoStr += L"\r\n"; _debugInfoStr += L"\r\n";
getClientRect(_rc);
return TRUE; return TRUE;
} }
@ -381,8 +377,8 @@ intptr_t CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
case WM_DPICHANGED: case WM_DPICHANGED:
{ {
_dpiManager.setDpiWP(wParam); _dpiManager.setDpiWP(wParam);
getClientRect(_rc);
setPositionDpi(lParam); setPositionDpi(lParam);
getWindowRect(_rc);
return TRUE; return TRUE;
} }
@ -433,7 +429,7 @@ void DebugInfoDlg::doDialog()
refreshDebugInfo(); refreshDebugInfo();
// Adjust the position of DebugBox // Adjust the position of DebugBox
goToCenter(SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE); moveForDpiChange();
goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE); goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE);
} }

View File

@ -315,6 +315,7 @@ intptr_t CALLBACK RunDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam
{ {
_dpiManager.setDpiWP(wParam); _dpiManager.setDpiWP(wParam);
setPositionDpi(lParam); setPositionDpi(lParam);
getWindowRect(_rc);
return TRUE; return TRUE;
} }
@ -446,7 +447,7 @@ void RunDlg::doDialog(bool isRTL)
create(IDD_RUN_DLG, isRTL); create(IDD_RUN_DLG, isRTL);
// Adjust the position in the center // Adjust the position in the center
goToCenter(SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE); moveForDpiChange();
goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE); goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE);
::SetFocus(::GetDlgItem(_hSelf, IDC_COMBO_RUN_PATH)); ::SetFocus(::GetDlgItem(_hSelf, IDC_COMBO_RUN_PATH));
} }

View File

@ -97,6 +97,16 @@ void StaticDialog::goToCenter(UINT swpFlags)
::SendMessageW(_hSelf, DM_REPOSITION, 0, 0); ::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 void StaticDialog::display(bool toShow, bool enhancedPositioningCheckWhenShowing) const
{ {
if (toShow) if (toShow)

View File

@ -54,6 +54,7 @@ public :
void redrawDlgItem(const int nIDDlgItem, bool forceUpdate = false) const; void redrawDlgItem(const int nIDDlgItem, bool forceUpdate = false) const;
void goToCenter(UINT swpFlags = SWP_SHOWWINDOW); void goToCenter(UINT swpFlags = SWP_SHOWWINDOW);
bool moveForDpiChange();
void display(bool toShow = true, bool enhancedPositioningCheckWhenShowing = false) const; void display(bool toShow = true, bool enhancedPositioningCheckWhenShowing = false) const;