From 25686c22e4e882c63f41705405da13e2db97b78e Mon Sep 17 00:00:00 2001 From: ozone10 Date: Wed, 19 Jun 2024 23:38:10 +0200 Subject: [PATCH] Separate imagelist for tab bar close button icons for dark/light modes Ref: https://github.com/notepad-plus-plus/notepad-plus-plus/pull/15321 Close #15326 --- PowerEditor/src/WinControls/TabBar/TabBar.cpp | 37 ++++++++++--------- PowerEditor/src/WinControls/TabBar/TabBar.h | 2 +- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.cpp b/PowerEditor/src/WinControls/TabBar/TabBar.cpp index 7874a9f20..9c105f91f 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.cpp +++ b/PowerEditor/src/WinControls/TabBar/TabBar.cpp @@ -462,21 +462,31 @@ void TabBarPlus::currentTabToEnd() void TabBarPlus::setCloseBtnImageList() { + int iconSize = 0; + std::vector ids; + + if (NppDarkMode::isEnabled()) + { + iconSize = g_TabCloseBtnSize_DM; + ids = { IDR_CLOSETAB_DM, IDR_CLOSETAB_INACT_DM, IDR_CLOSETAB_HOVER_DM, IDR_CLOSETAB_PUSH_DM }; + } + else + { + iconSize = g_TabCloseBtnSize; + ids = { IDR_CLOSETAB, IDR_CLOSETAB_INACT, IDR_CLOSETAB_HOVER, IDR_CLOSETAB_PUSH }; + } + if (_hCloseBtnImgLst != nullptr) { ::ImageList_Destroy(_hCloseBtnImgLst); _hCloseBtnImgLst = nullptr; } - const int btnSize = _dpiManager.scale(g_TabCloseBtnSize); + const int btnSize = _dpiManager.scale(iconSize); - const auto idsCloseIcons = { - IDR_CLOSETAB, IDR_CLOSETAB_INACT, IDR_CLOSETAB_HOVER, IDR_CLOSETAB_PUSH, - IDR_CLOSETAB_DM, IDR_CLOSETAB_INACT_DM, IDR_CLOSETAB_HOVER_DM, IDR_CLOSETAB_PUSH_DM }; + _hCloseBtnImgLst = ::ImageList_Create(btnSize, btnSize, ILC_COLOR32 | ILC_MASK, static_cast(ids.size()), 0); - _hCloseBtnImgLst = ::ImageList_Create(btnSize, btnSize, ILC_COLOR32 | ILC_MASK, static_cast(idsCloseIcons.size()), 0); - - for (const auto& id : idsCloseIcons) + for (const auto& id : ids) { HICON hIcon = nullptr; DPIManagerV2::loadIcon(_hInst, MAKEINTRESOURCE(id), btnSize, btnSize, &hIcon); @@ -552,6 +562,7 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara case NPPM_INTERNAL_REFRESHDARKMODE: { NppDarkMode::setDarkTooltips(hwnd, NppDarkMode::ToolTipsType::tabbar); + setCloseBtnImageList(); return TRUE; } @@ -1304,7 +1315,7 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode) { // 3 status for each inactive tab and selected tab close item : // normal / hover / pushed - int idxCloseImg = isDarkMode ? 4 : 0; // selected + int idxCloseImg = 0; // selected if (_isCloseHover && (_currentHoverTabItem == nTab)) { @@ -1557,16 +1568,6 @@ void TabBarPlus::exchangeItemData(POINT point) } -CloseButtonZone::CloseButtonZone() -{ - // TODO: get width/height of close button dynamically - if (_parent) - { - _width = DPIManagerV2::scale(g_TabCloseBtnSize, _parent); - } - _height = _width; -} - bool CloseButtonZone::isHit(int x, int y, const RECT & tabRect, bool isVertical) const { RECT buttonRect = getButtonRectFrom(tabRect, isVertical); diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.h b/PowerEditor/src/WinControls/TabBar/TabBar.h index b907ad93d..17f27ff45 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.h +++ b/PowerEditor/src/WinControls/TabBar/TabBar.h @@ -54,6 +54,7 @@ constexpr int g_TabHeightLarge = 25; constexpr int g_TabWidth = 45; constexpr int g_TabWidthCloseBtn = 60; constexpr int g_TabCloseBtnSize = 11; +constexpr int g_TabCloseBtnSize_DM = 16; struct TBHDR { @@ -138,7 +139,6 @@ protected: struct CloseButtonZone { - CloseButtonZone(); bool isHit(int x, int y, const RECT & tabRect, bool isVertical) const; RECT getButtonRectFrom(const RECT & tabRect, bool isVertical) const; void setParent(HWND parent) { _parent = parent; }