Skip to content

Commit

Permalink
improve ListView group header drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
DartVanya committed Dec 18, 2024
1 parent e4210cb commit 82a061f
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions phlib/theme.c
Original file line number Diff line number Diff line change
Expand Up @@ -2087,30 +2087,55 @@ LRESULT CALLBACK PhpThemeWindowDrawListViewGroup(

memset(&groupInfo, 0, sizeof(LVGROUP));
groupInfo.cbSize = sizeof(LVGROUP);
groupInfo.mask = LVGF_HEADER;
groupInfo.mask = LVGF_HEADER | LVGF_STATE;
groupInfo.stateMask = LVGS_SELECTED | LVGS_FOCUSED | LVGS_COLLAPSED | LVGS_COLLAPSIBLE;

if (ListView_GetGroupInfo(DrawInfo->nmcd.hdr.hwndFrom, (ULONG)DrawInfo->nmcd.dwItemSpec, &groupInfo) != INT_ERROR)
{
RECT headerRect = DrawInfo->rcText;
POINT pt;
HTHEME glyphTheme;

GetCursorPos(&pt);
MapWindowPoints(NULL, DrawInfo->nmcd.hdr.hwndFrom, &pt, 1);
BOOLEAN isCollapsible = (groupInfo.state & LVGS_COLLAPSIBLE) == LVGS_COLLAPSIBLE;
BOOLEAN isCollapsed = (groupInfo.state & LVGS_COLLAPSED) == LVGS_COLLAPSED;
BOOLEAN isHot = PtInRect(&DrawInfo->rcText, pt); // LVGS_HOT is missing

SetTextColor(DrawInfo->nmcd.hdc, PhThemeWindowTextColor);
SetDCBrushColor(DrawInfo->nmcd.hdc, PhThemeWindowBackground2Color);
SetDCBrushColor(DrawInfo->nmcd.hdc, !isHot ? PhThemeWindowBackground2Color : PhMakeColorBrighter(PhThemeWindowBackground2Color, 12));

headerRect.top += PhGetDpi(2, dpiValue);
headerRect.bottom -= PhGetDpi(2, dpiValue);
FillRect(DrawInfo->nmcd.hdc, &headerRect, PhGetStockBrush(DC_BRUSH));

DrawInfo->rcText.top += PhGetDpi(2, dpiValue);
DrawInfo->rcText.bottom -= PhGetDpi(2, dpiValue);
FillRect(DrawInfo->nmcd.hdc, &DrawInfo->rcText, PhGetStockBrush(DC_BRUSH));
DrawInfo->rcText.top -= PhGetDpi(2, dpiValue);
DrawInfo->rcText.bottom += PhGetDpi(2, dpiValue);
if (isCollapsible &&
(glyphTheme = PhOpenThemeData(DrawInfo->nmcd.hdr.hwndFrom, VSCLASS_LISTVIEW, dpiValue)))
{
SIZE glyphSize;
INT partId = isCollapsed ? LVP_EXPANDBUTTON : LVP_COLLAPSEBUTTON;
INT stateId = LVCB_NORMAL;

PhGetThemePartSize(glyphTheme, DrawInfo->nmcd.hdc, partId, stateId, &headerRect, TS_TRUE, &glyphSize);
INT old_left = headerRect.left;
headerRect.left = headerRect.right - glyphSize.cx - glyphSize.cx / 2;

if (PtInRect(&headerRect, pt)) stateId = IsLButtonDown() ? LVCB_PUSHED : LVCB_HOVER;
PhDrawThemeBackground(glyphTheme, DrawInfo->nmcd.hdc, partId, stateId, &headerRect, NULL);
headerRect.left = old_left;
PhCloseThemeData(glyphTheme);
}

if (groupInfo.pszHeader)
{
DrawInfo->rcText.left += PhGetDpi(10, dpiValue);
headerRect.left += PhGetDpi(10, dpiValue);
DrawText(
DrawInfo->nmcd.hdc,
groupInfo.pszHeader,
(UINT)PhCountStringZ(groupInfo.pszHeader),
&DrawInfo->rcText,
&headerRect,
DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_HIDEPREFIX
);
DrawInfo->rcText.left -= PhGetDpi(10, dpiValue);
}
}

Expand Down

0 comments on commit 82a061f

Please sign in to comment.