Skip to content

Commit

Permalink
Adapt new DPI support for toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
donho committed Apr 25, 2024
1 parent 89aaf43 commit c823ca8
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions PowerEditor/src/NppBigSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3514,6 +3514,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT message, WPARAM wParam, LPARAM lPa
case WM_DPICHANGED:
{
const UINT dpi = LOWORD(wParam);
_toolBar.resizeIconsDpi(dpi);

_statusBar.setPartWidth(STATUSBAR_DOC_SIZE, DPIManagerV2::scale(220, dpi));
_statusBar.setPartWidth(STATUSBAR_CUR_POS, DPIManagerV2::scale(260, dpi));
Expand Down
25 changes: 18 additions & 7 deletions PowerEditor/src/WinControls/ToolBar/ToolBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,10 @@ bool ToolBar::init( HINSTANCE hInst, HWND hPere, toolBarStatusType type, ToolBar
Window::init(hInst, hPere);

_state = type;
int iconSize = NppParameters::getInstance()._dpiManager.scaleX(_state == TB_LARGE || _state == TB_LARGE2 ? 32 : 16);

_dpiManager.setDpi(hPere);

int iconSize = _dpiManager.scale(_state == TB_LARGE || _state == TB_LARGE2 ? 32 : 16);

_toolBarIcons.init(buttonUnitArray, arraySize, _vDynBtnReg);
_toolBarIcons.create(_hInst, iconSize);
Expand Down Expand Up @@ -231,7 +234,7 @@ int ToolBar::getHeight() const

void ToolBar::reduce()
{
int iconDpiDynamicalSize = NppParameters::getInstance()._dpiManager.scaleX(16);
int iconDpiDynamicalSize = _dpiManager.scale(16);
_toolBarIcons.resizeIcon(iconDpiDynamicalSize);
setState(TB_SMALL);
reset(true); //recreate toolbar if previous state was Std icons or Big icons
Expand All @@ -240,7 +243,7 @@ void ToolBar::reduce()

void ToolBar::enlarge()
{
int iconDpiDynamicalSize = NppParameters::getInstance()._dpiManager.scaleX(32);
int iconDpiDynamicalSize = _dpiManager.scale(32);
_toolBarIcons.resizeIcon(iconDpiDynamicalSize);
setState(TB_LARGE);
reset(true); //recreate toolbar if previous state was Std icons or Small icons
Expand All @@ -249,7 +252,7 @@ void ToolBar::enlarge()

void ToolBar::reduceToSet2()
{
int iconDpiDynamicalSize = NppParameters::getInstance()._dpiManager.scaleX(16);
int iconDpiDynamicalSize = _dpiManager.scale(16);
_toolBarIcons.resizeIcon(iconDpiDynamicalSize);

setState(TB_SMALL2);
Expand All @@ -259,7 +262,7 @@ void ToolBar::reduceToSet2()

void ToolBar::enlargeToSet2()
{
int iconDpiDynamicalSize = NppParameters::getInstance()._dpiManager.scaleX(32);
int iconDpiDynamicalSize = _dpiManager.scale(32);
_toolBarIcons.resizeIcon(iconDpiDynamicalSize);
setState(TB_LARGE2);
reset(true); //recreate toolbar if previous state was Std icons or Small icons
Expand Down Expand Up @@ -373,7 +376,7 @@ void ToolBar::reset(bool create)
else
{
//Else set the internal imagelist with standard bitmaps
int iconDpiDynamicalSize = NppParameters::getInstance()._dpiManager.scaleX(16);
int iconDpiDynamicalSize = _dpiManager.scale(16);
::SendMessage(_hSelf, TB_SETBITMAPSIZE, 0, MAKELPARAM(iconDpiDynamicalSize, iconDpiDynamicalSize));

TBADDBITMAP addbmp = { 0, 0 };
Expand All @@ -398,7 +401,7 @@ void ToolBar::reset(bool create)
if (create)
{ //if the toolbar has been recreated, readd the buttons
_nbCurrentButtons = _nbTotalButtons;
WORD btnSize = (_state == TB_LARGE ? 32 : 16);
WORD btnSize = static_cast<WORD>(_dpiManager.scale((_state == TB_LARGE || _state == TB_LARGE2) ? 32 : 16));
::SendMessage(_hSelf, TB_SETBUTTONSIZE , 0, MAKELONG(btnSize, btnSize));
::SendMessage(_hSelf, TB_ADDBUTTONS, _nbTotalButtons, reinterpret_cast<LPARAM>(_pTBB));
}
Expand Down Expand Up @@ -510,6 +513,14 @@ void ToolBar::doPopop(POINT chevPoint)
}
}

void ToolBar::resizeIconsDpi(UINT dpi)
{
_dpiManager.setDpi(dpi);
const int iconDpiDynamicalSize = _dpiManager.scale((_state == TB_LARGE || _state == TB_LARGE2) ? 32 : 16);
_toolBarIcons.resizeIcon(iconDpiDynamicalSize);
reset(true);
}

void ToolBar::addToRebar(ReBar * rebar)
{
if (_pRebar)
Expand Down
5 changes: 5 additions & 0 deletions PowerEditor/src/WinControls/ToolBar/ToolBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "Window.h"
#include "Notepad_plus_msgs.h"
#include "ImageListSet.h"
#include "dpiManagerV2.h"

#define REBAR_BAR_TOOLBAR 0
#define REBAR_BAR_SEARCH 1
Expand Down Expand Up @@ -101,6 +102,8 @@ public :

void addToRebar(ReBar * rebar);

void resizeIconsDpi(UINT dpi);

private :
TBBUTTON *_pTBB = nullptr;
ToolBarIcons _toolBarIcons;
Expand All @@ -116,6 +119,8 @@ private :

TiXmlNode *_toolIcons = nullptr;

DPIManagerV2 _dpiManager;

void setDefaultImageList() {
::SendMessage(_hSelf, TB_SETIMAGELIST, 0, reinterpret_cast<LPARAM>(_toolBarIcons.getDefaultLst()));
};
Expand Down

0 comments on commit c823ca8

Please sign in to comment.