Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve status bar resize handling #15090

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
87 changes: 39 additions & 48 deletions PowerEditor/src/ScintillaComponent/FindReplaceDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -294,10 +294,19 @@ void FindReplaceDlg::create(int dialogID, bool isRTL, bool msgDestParent, bool t
_statusBar.init(GetModuleHandle(NULL), _hSelf, 0);
_statusBar.display();

DPIManager& dpiManager = NppParameters::getInstance()._dpiManager;
setDpi();

RECT rcClient{};
getClientRect(rcClient);

const LONG padding = _dpiManager.getSystemMetricsForDpi(SM_CXPADDEDBORDER);
_szBorder.cx = (_dpiManager.getSystemMetricsForDpi(SM_CXFRAME) + padding) * 2;
_szBorder.cy = (_dpiManager.getSystemMetricsForDpi(SM_CYFRAME) + padding) * 2 + _dpiManager.getSystemMetricsForDpi(SM_CYCAPTION);

//fill min dialog size info
_szMinDialog.cx = rcClient.right - rcClient.left;
_szMinDialog.cy = rcClient.bottom - rcClient.top;

RECT rect{};
getClientRect(rect);
_tab.init(_hInst, _hSelf, false, true);
NppDarkMode::subclassTabControl(_tab.getHSelf());

Expand All @@ -313,23 +322,10 @@ void FindReplaceDlg::create(int dialogID, bool isRTL, bool msgDestParent, bool t
_tab.insertAtEnd(findInProjects);
_tab.insertAtEnd(mark);

_tab.reSizeTo(rect);
_tab.reSizeTo(rcClient);
_tab.display();

_initialClientWidth = rect.right - rect.left;

//fill min dialog size info
getWindowRect(_initialWindowRect);
_initialWindowRect.right = _initialWindowRect.right - _initialWindowRect.left + dpiManager.scaleX(10);
_initialWindowRect.left = 0;
_initialWindowRect.bottom = _initialWindowRect.bottom - _initialWindowRect.top;
_initialWindowRect.top = 0;

RECT dlgRc{};
getWindowRect(dlgRc);

RECT countRc{};
::GetWindowRect(::GetDlgItem(_hSelf, IDCCOUNTALL), &countRc);
_initialClientWidth = rcClient.right - rcClient.left;

NppParameters& nppParam = NppParameters::getInstance();
NppGUI& nppGUI = nppParam.getNppGUI();
Expand All @@ -345,9 +341,15 @@ void FindReplaceDlg::create(int dialogID, bool isRTL, bool msgDestParent, bool t
goToCenter(swpFlags);
}

RECT rcCount{};
getMappedChildRect(IDCCOUNTALL, rcCount);

RECT rcOk{};
getMappedChildRect(IDOK, rcOk);

RECT rcStatusBar{};
::GetClientRect(_statusBar.getHSelf(), &rcStatusBar);
_lesssModeHeight = (countRc.bottom - dlgRc.top) + (rcStatusBar.bottom - rcStatusBar.top) + dpiManager.scaleY(10);
_lesssModeHeight = (rcCount.bottom + (rcCount.top - rcOk.bottom) + (rcStatusBar.bottom - rcStatusBar.top));

if (nppGUI._findWindowLessMode)
{
Expand Down Expand Up @@ -1167,13 +1169,13 @@ void FindReplaceDlg::resizeDialogElements(LONG newWidth)
IDC_FINDPREV, IDC_FINDNEXT, IDC_2_BUTTONS_MODE, IDC_COPY_MARKED_TEXT, IDD_FINDINFILES_REPLACEINPROJECTS, IDD_RESIZE_TOGGLE_BUTTON
};

const UINT flags = SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOCOPYBITS;
constexpr UINT flags = SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOACTIVATE | SWP_NOCOPYBITS;

auto newDeltaWidth = newWidth - _initialClientWidth;
auto addWidth = newDeltaWidth - _deltaWidth;
_deltaWidth = newDeltaWidth;

RECT rc;
RECT rc{};
for (int id : resizeWindowIDs)
{
HWND resizeHwnd = ::GetDlgItem(_hSelf, id);
Expand All @@ -1200,13 +1202,8 @@ void FindReplaceDlg::resizeDialogElements(LONG newWidth)
::SetWindowPos(moveHwnd, NULL, rc.left + addWidth, rc.top, 0, 0, SWP_NOSIZE | flags);
}

auto additionalWindowHwndsToResize = { _tab.getHSelf() , _statusBar.getHSelf() };

for (HWND resizeHwnd : additionalWindowHwndsToResize)
{
::GetClientRect(resizeHwnd, &rc);
::SetWindowPos(resizeHwnd, NULL, 0, 0, rc.right + addWidth, rc.bottom, SWP_NOMOVE | flags);
}
::GetClientRect(_tab.getHSelf(), &rc);
::SetWindowPos(_tab.getHSelf(), nullptr, 0, 0, rc.right + addWidth, rc.bottom, SWP_NOMOVE | flags);
}

std::mutex findOps_mutex;
Expand All @@ -1219,16 +1216,18 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
{
bool isLessModeOn = NppParameters::getInstance().getNppGUI()._findWindowLessMode;
MINMAXINFO* mmi = reinterpret_cast<MINMAXINFO*>(lParam);
mmi->ptMinTrackSize.y = isLessModeOn ? _lesssModeHeight : _initialWindowRect.bottom;
mmi->ptMinTrackSize.x = _initialWindowRect.right;
mmi->ptMaxTrackSize.y = isLessModeOn ? _lesssModeHeight : _initialWindowRect.bottom;
mmi->ptMinTrackSize.x = _szMinDialog.cx + _szBorder.cx;
const LONG h = (isLessModeOn ? _lesssModeHeight : _szMinDialog.cy) + _szBorder.cy;
mmi->ptMinTrackSize.y = h;
mmi->ptMaxTrackSize.y = h;

return 0;
return TRUE;
}

case WM_SIZE:
{
resizeDialogElements(LOWORD(lParam));
::SendMessage(_statusBar.getHSelf(), WM_SIZE, 0, 0); // pass WM_SIZE to status bar to automatically adjusts its size
return TRUE;
}

Expand Down Expand Up @@ -2396,22 +2395,12 @@ intptr_t CALLBACK FindReplaceDlg::run_dlgProc(UINT message, WPARAM wParam, LPARA
LONG w = rc.right - rc.left;
bool& isLessModeOn = NppParameters::getInstance().getNppGUI()._findWindowLessMode;
isLessModeOn = !isLessModeOn;
long dlgH = isLessModeOn ? _lesssModeHeight : _initialWindowRect.bottom;
long dlgH = (isLessModeOn ? _lesssModeHeight : _szMinDialog.cy) + _szBorder.cy;

DIALOG_TYPE dlgT = getCurrentStatus();
calcAndSetCtrlsPos(dlgT, true);

// For unknown reason, the original default width doesn't make the status bar moveed
// Here we use a dirty workaround: increase 1 pixel so WM_SIZE message will be triggered
if (w == _initialWindowRect.right)
w += 1;

::SetWindowPos(_hSelf, nullptr, 0, 0, w, dlgH, SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW); // WM_SIZE message to call resizeDialogElements - status bar will be reposition correctly.

// Reposition the status bar
constexpr UINT flags = SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | SWP_FRAMECHANGED;
::GetClientRect(_statusBar.getHSelf(), &rc);
::SetWindowPos(_statusBar.getHSelf(), nullptr, 0, 0, w, rc.bottom, flags);
::SetWindowPos(_hSelf, nullptr, 0, 0, w, dlgH, SWP_NOMOVE | SWP_NOZORDER | SWP_NOREDRAW);

hideOrShowCtrl4reduceOrNormalMode(dlgT);

Expand Down Expand Up @@ -4481,18 +4470,20 @@ void FindReplaceDlg::calcAndSetCtrlsPos(DIALOG_TYPE dlgT, bool fromColBtn)

if (fromColBtn)
{
LONG yColBtn = 0;
RECT rc2ModeCheck{};
getMappedChildRect(IDC_2_BUTTONS_MODE, rc2ModeCheck);
LONG yColBtn = btnGap / 2;
if (isNotLessMode)
{
RECT rcSlider{};
getMappedChildRect(IDC_PERCENTAGE_SLIDER, rcSlider);
yColBtn = rcSlider.top + btnGap;
yColBtn += rcSlider.top;
}
else
{
yColBtn = rcBtn2ndPos.top + btnGap / 2;
yColBtn += rcBtn2ndPos.top;
}
::SetWindowPos(::GetDlgItem(_hSelf, IDD_RESIZE_TOGGLE_BUTTON), nullptr, rcBtn2ndPos.right + btnGap, yColBtn, 0, 0, SWP_NOSIZE | flags);
::SetWindowPos(::GetDlgItem(_hSelf, IDD_RESIZE_TOGGLE_BUTTON), nullptr, rc2ModeCheck.left, yColBtn, 0, 0, SWP_NOSIZE | flags);
}
}

Expand Down
6 changes: 4 additions & 2 deletions PowerEditor/src/ScintillaComponent/FindReplaceDlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,10 @@ protected :

void combo2ExtendedMode(int comboID);

private :
RECT _initialWindowRect{};
private:
SIZE _szMinDialog{};
SIZE _szBorder{};

LONG _deltaWidth = 0;
LONG _initialClientWidth = 0;
LONG _lesssModeHeight = 0;
Expand Down
18 changes: 9 additions & 9 deletions PowerEditor/src/ScintillaComponent/FindReplaceDlg.rc
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <windows.h>
#include "FindReplaceDlg_rc.h"

IDD_FIND_REPLACE_DLG DIALOGEX 0, 0, 392, 200
IDD_FIND_REPLACE_DLG DIALOGEX 0, 0, 391, 197
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME
EXSTYLE WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE
CAPTION "Replace"
Expand Down Expand Up @@ -60,13 +60,13 @@ BEGIN
GROUPBOX "",IDC_REPLACEINSELECTION,192,50,180,23
CONTROL "In select&ion",IDC_IN_SELECTION_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,200,58,59,10

PUSHBUTTON "",IDC_FINDPREV,278,20,18,14,WS_GROUP | BS_MULTILINE
PUSHBUTTON "",IDC_FINDNEXT,299,20,70,14,WS_GROUP | BS_MULTILINE
PUSHBUTTON "",IDC_FINDPREV,278,20,17,14,WS_GROUP
PUSHBUTTON "",IDC_FINDNEXT,299,20,70,14,WS_GROUP
PUSHBUTTON "Find Next",IDOK,278,20,91,14,WS_GROUP
CONTROL "",IDC_2_BUTTONS_MODE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,373,22,14,10
PUSHBUTTON "Coun&t",IDCCOUNTALL,278,38,91,14
PUSHBUTTON "Find All in Current &Document",IDC_FINDALL_CURRENTFILE,278,56,91,21,BS_MULTILINE
PUSHBUTTON "Find All in All &Opened Documents",IDC_FINDALL_OPENEDFILES,278,80,91,21,BS_MULTILINE
PUSHBUTTON "Find All in All &Opened Documents",IDC_FINDALL_OPENEDFILES,278,81,91,21,BS_MULTILINE

PUSHBUTTON "&Replace",IDREPLACE,278,38,91,14
PUSHBUTTON "Replace &All",IDREPLACEALL,278,56,91,14
Expand All @@ -82,15 +82,15 @@ BEGIN
PUSHBUTTON "Clear all marks",IDC_CLEAR_ALL,278,38,91,14
PUSHBUTTON "Copy Marked Text",IDC_COPY_MARKED_TEXT,278,56,91,14

PUSHBUTTON "Close",IDCANCEL,278,98,91,14
PUSHBUTTON "Close",IDCANCEL,278,106,91,14

GROUPBOX "",IDC_TRANSPARENT_GRPBOX,268,131,99,48
CONTROL "Transparenc&y",IDC_TRANSPARENT_CHECK,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_TABSTOP,264,131,80,10
GROUPBOX "",IDC_TRANSPARENT_GRPBOX,268,131,101,48
CONTROL "Transparenc&y",IDC_TRANSPARENT_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,264,131,80,10
CONTROL "On losing focus",IDC_TRANSPARENT_LOSSFOCUS_RADIO,"Button",BS_AUTORADIOBUTTON | WS_GROUP | WS_TABSTOP,278,143,85,10
CONTROL "Always",IDC_TRANSPARENT_ALWAYS_RADIO,"Button",BS_AUTORADIOBUTTON ,278,155,85,10
CONTROL "",IDC_PERCENTAGE_SLIDER,"msctls_trackbar32",TBS_BOTH | TBS_NOTICKS | TBS_TRANSPARENTBKGND | NOT WS_VISIBLE | WS_TABSTOP,275,166,85,10
CONTROL "",IDC_PERCENTAGE_SLIDER,"msctls_trackbar32",TBS_BOTH | TBS_NOTICKS | TBS_TRANSPARENTBKGND | WS_TABSTOP,275,166,85,10

PUSHBUTTON "",IDD_RESIZE_TOGGLE_BUTTON,375,171,16,14
PUSHBUTTON "",IDD_RESIZE_TOGGLE_BUTTON,373,168,16,14
END

IDB_INCREMENTAL_BG BITMAP "../icons/incrementalBg.bmp"
Expand Down
3 changes: 3 additions & 0 deletions PowerEditor/src/dpiManagerV2.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ class DPIManagerV2
static void initDpiAPI();

static int getSystemMetricsForDpi(int nIndex, UINT dpi);
int getSystemMetricsForDpi(int nIndex) {
return getSystemMetricsForDpi(nIndex, _dpi);
}
static DPI_AWARENESS_CONTEXT setThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT dpiContext);

static UINT getDpiForSystem();
Expand Down