From ef840de150ca8ddac36a186a451b2186452e4d93 Mon Sep 17 00:00:00 2001 From: ozone10 Date: Sun, 19 May 2024 13:50:36 +0200 Subject: [PATCH] Make top bar indicate applied tab color for unfocused view - use new dpi scaled metrics. - replace c-casts. Fix #15140, close #15160 --- PowerEditor/src/WinControls/TabBar/TabBar.cpp | 31 +++++++++---------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.cpp b/PowerEditor/src/WinControls/TabBar/TabBar.cpp index 8fb56a3b2..0b1746b29 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.cpp +++ b/PowerEditor/src/WinControls/TabBar/TabBar.cpp @@ -250,7 +250,7 @@ void TabBar::reSizeTo(RECT & rc2Ajust) ::SetWindowLongPtr(_hSelf, GWL_STYLE, style); tabsHight = rowCount * (larger - smaller) + marge; - tabsHight += GetSystemMetrics(_isVertical ? SM_CXEDGE : SM_CYEDGE); + tabsHight += _dpiManager.getSystemMetricsForDpi(_isVertical ? SM_CXEDGE : SM_CYEDGE); if (_isVertical) { @@ -1148,7 +1148,7 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode) ::SetBkMode(hDC, TRANSPARENT); HBRUSH hBrush = ::CreateSolidBrush(colorInactiveBgBase); ::FillRect(hDC, &rect, hBrush); - ::DeleteObject((HGDIOBJ)hBrush); + ::DeleteObject(static_cast(hBrush)); // equalize drawing areas of active and inactive tabs int paddingDynamicTwoX = _dpiManager.scale(2); @@ -1156,10 +1156,9 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode) if (isSelected && !isDarkMode) { // the drawing area of the active tab extends on all borders by default - rect.top += ::GetSystemMetrics(SM_CYEDGE); - rect.bottom -= ::GetSystemMetrics(SM_CYEDGE); - rect.left += ::GetSystemMetrics(SM_CXEDGE); - rect.right -= ::GetSystemMetrics(SM_CXEDGE); + const int xEdge = _dpiManager.getSystemMetricsForDpi(SM_CXEDGE); + const int yEdge = _dpiManager.getSystemMetricsForDpi(SM_CYEDGE); + ::InflateRect(&rect, -xEdge, -yEdge); // the active tab is also slightly higher by default (use this to shift the tab cotent up bx two pixels if tobBar is not drawn) if (_isVertical) { @@ -1228,20 +1227,18 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode) barRect.bottom = barRect.top + topBarHeight; } - if (::SendMessage(_hParent, NPPM_INTERNAL_ISFOCUSEDTAB, 0, reinterpret_cast(_hSelf))) + const bool isFocused = ::SendMessage(_hParent, NPPM_INTERNAL_ISFOCUSEDTAB, 0, reinterpret_cast(_hSelf)); + COLORREF topBarColour = isFocused ? _activeTopBarFocusedColour : _activeTopBarUnfocusedColour; // #FAAA3C, #FAD296 + + if (individualColourId != -1) { - COLORREF topBarColour = _activeTopBarFocusedColour; // #FAAA3C - if (individualColourId != -1) - { - topBarColour = NppDarkMode::getIndividualTabColour(individualColourId, isDarkMode, true); - } - hBrush = ::CreateSolidBrush(topBarColour); + topBarColour = NppDarkMode::getIndividualTabColour(individualColourId, isDarkMode, isFocused); } - else - hBrush = ::CreateSolidBrush(_activeTopBarUnfocusedColour); // #FAD296 + + hBrush = ::CreateSolidBrush(topBarColour); ::FillRect(hDC, &barRect, hBrush); - ::DeleteObject((HGDIOBJ)hBrush); + ::DeleteObject(static_cast(hBrush)); } } else // inactive tabs @@ -1264,7 +1261,7 @@ void TabBarPlus::drawItem(DRAWITEMSTRUCT *pDrawItemStruct, bool isDarkMode) hBrush = ::CreateSolidBrush(brushColour); ::FillRect(hDC, &inactiveRect, hBrush); - ::DeleteObject((HGDIOBJ)hBrush); + ::DeleteObject(static_cast(hBrush)); } if (isDarkMode && hasMultipleLines)