From f4f7cb67cd38b011abe8826b609cf07211818e9e Mon Sep 17 00:00:00 2001 From: funap <31555185+funap@users.noreply.github.com> Date: Sat, 4 Mar 2023 15:08:27 +0900 Subject: [PATCH] Improved small toolbar button size issue in hidpi (#48) --- src/Explorer/ExplorerDialog.cpp | 34 +++++++++++++++++++-------------- src/Explorer/FavesDialog.cpp | 12 +++++++----- src/Explorer/ToolBar.cpp | 11 +++++------ 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/src/Explorer/ExplorerDialog.cpp b/src/Explorer/ExplorerDialog.cpp index df12f73..57f5897 100644 --- a/src/Explorer/ExplorerDialog.cpp +++ b/src/Explorer/ExplorerDialog.cpp @@ -413,22 +413,25 @@ INT_PTR CALLBACK ExplorerDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM _ToolBar.reSizeTo(rc); _Rebar.reSizeTo(rc); + auto toolBarHeight = _ToolBar.getHeight(); + auto filterHeight = GetSystemMetrics(SM_CYSMSIZE); + /* set position of tree control */ getClientRect(rc); - rc.top += 26; + rc.top += toolBarHeight; rc.bottom = splitterPos; ::SetWindowPos(_hTreeCtrl, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW); /* set splitter */ getClientRect(rc); - rc.top = (splitterPos + 26); + rc.top = (splitterPos + toolBarHeight); rc.bottom = 6; ::SetWindowPos(_hSplitterCtrl, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW); /* set position of list control */ getClientRect(rc); - rc.top = (splitterPos + 32); - rc.bottom -= (splitterPos + 32 + 22); + rc.top = (splitterPos + toolBarHeight + 6); + rc.bottom -= (splitterPos + toolBarHeight + 6 + filterHeight); ::SetWindowPos(_hListCtrl, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW); /* set position of filter controls */ @@ -438,16 +441,16 @@ INT_PTR CALLBACK ExplorerDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM /* set position of static text */ hWnd = ::GetDlgItem(_hSelf, IDC_STATIC_FILTER); ::GetWindowRect(hWnd, &rcWnd); - rc.top = rcBuff.bottom - 18; - rc.bottom = 12; + rc.top = rcBuff.bottom - filterHeight + 6; + rc.bottom = filterHeight; rc.left += 2; rc.right = rcWnd.right - rcWnd.left; ::SetWindowPos(hWnd, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW); rcBuff.left = rc.right + 4; /* set position of combo */ - rc.top = rcBuff.bottom - 21; - rc.bottom = 20; + rc.top = rcBuff.bottom - filterHeight + 6; + rc.bottom = filterHeight; rc.left = rcBuff.left; rc.right = rcBuff.right - rcBuff.left; ::SetWindowPos(_hFilter, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW); @@ -466,10 +469,13 @@ INT_PTR CALLBACK ExplorerDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM _ToolBar.reSizeTo(rc); _Rebar.reSizeTo(rc); + auto toolBarHeight = _ToolBar.getHeight(); + auto filterHeight = GetSystemMetrics(SM_CYSMSIZE); + /* set position of tree control */ getClientRect(rc); - rc.top += 26; - rc.bottom -= 26 + 22; + rc.top += toolBarHeight; + rc.bottom -= toolBarHeight + filterHeight; rc.right = splitterPos; ::SetWindowPos(_hTreeCtrl, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW); @@ -480,8 +486,8 @@ INT_PTR CALLBACK ExplorerDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM /* set position of static text */ hWnd = ::GetDlgItem(_hSelf, IDC_STATIC_FILTER); ::GetWindowRect(hWnd, &rcWnd); - rc.top = rcBuff.bottom - 18; - rc.bottom = 12; + rc.top = rcBuff.bottom - filterHeight + 6; + rc.bottom = filterHeight; rc.left += 2; rc.right = rcWnd.right - rcWnd.left; ::SetWindowPos(hWnd, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW); @@ -489,8 +495,8 @@ INT_PTR CALLBACK ExplorerDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM rcBuff.left = rc.right + 4; /* set position of combo */ - rc.top = rcBuff.bottom - 21; - rc.bottom = 20; + rc.top = rcBuff.bottom - filterHeight + 6; + rc.bottom = filterHeight; rc.left = rcBuff.left; rc.right = splitterPos - rcBuff.left; ::SetWindowPos(_hFilter, NULL, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW); diff --git a/src/Explorer/FavesDialog.cpp b/src/Explorer/FavesDialog.cpp index 23ce1c6..3f02e5d 100644 --- a/src/Explorer/FavesDialog.cpp +++ b/src/Explorer/FavesDialog.cpp @@ -328,14 +328,16 @@ INT_PTR CALLBACK FavesDialog::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lP case WM_SIZE: case WM_MOVE: { RECT rc = {}; + /* set position of toolbar */ + getClientRect(rc); + _ToolBar.reSizeTo(rc); + _Rebar.reSizeTo(rc); - /* set position of toolbar */ - getClientRect(rc); - _Rebar.reSizeTo(rc); + auto toolBarHeight = _ToolBar.getHeight(); /* set position of tree control */ - rc.top += 26; - rc.bottom -= 26; + rc.top += toolBarHeight; + rc.bottom -= toolBarHeight; ::SetWindowPos(_hTreeCtrl, nullptr, rc.left, rc.top, rc.right, rc.bottom, SWP_NOZORDER | SWP_SHOWWINDOW); break; diff --git a/src/Explorer/ToolBar.cpp b/src/Explorer/ToolBar.cpp index 6ce11fa..d88df18 100644 --- a/src/Explorer/ToolBar.cpp +++ b/src/Explorer/ToolBar.cpp @@ -25,7 +25,7 @@ bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type, { Window::init(hInst, hPere); _state = type; - int iconSize = (_state == TB_LARGE?32:16); + int iconSize = GetSystemMetrics(SM_CYSMICON); _toolBarIcons.init(buttonUnitArray, arraySize); _toolBarIcons.create(_hInst, iconSize); @@ -80,7 +80,7 @@ void ToolBar::destroy() ::DestroyWindow(_hSelf); _hSelf = NULL; _toolBarIcons.destroy(); -}; +} int ToolBar::getWidth() const { @@ -172,11 +172,10 @@ void ToolBar::reset(bool create) if (create) { //if the toolbar has been recreated, readd the buttons SIZE_T nrBtnToAdd = _nrButtons; _nrCurrentButtons = nrBtnToAdd; - WORD btnSize = (_state == TB_LARGE?32:16); - ::SendMessage(_hSelf, TB_SETBUTTONSIZE , (WPARAM)0, (LPARAM)MAKELONG (btnSize, btnSize)); + WORD btnSize = GetSystemMetrics(SM_CYSMICON); ::SendMessage(_hSelf, TB_ADDBUTTONS, (WPARAM)nrBtnToAdd, (LPARAM)_pTBB); - } - ::SendMessage(_hSelf, TB_AUTOSIZE, 0, 0); + ::SendMessage(_hSelf, TB_SETBUTTONSIZE, (WPARAM)0, (LPARAM)MAKELONG(btnSize, btnSize)); + } if (_pRebar) { _rbBand.hwndChild = getHSelf();