From 1b9fc2a170b17888e71fa229657d02240f37ffb5 Mon Sep 17 00:00:00 2001 From: Phil Krylov Date: Tue, 10 Jan 2006 19:58:24 +0100 Subject: [PATCH] comctl32: Fix emitting of NM_CUSTOMDRAW header notifications. Emit NM_CUSTOMDRAW header notifications for all headers, not only ownerdrawn. Allow to change item text and background colors in an application's NM_CUSTOMDRAW handler. --- dlls/comctl32/header.c | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/dlls/comctl32/header.c b/dlls/comctl32/header.c index 4b533fca635..5e1c4c800fc 100644 --- a/dlls/comctl32/header.c +++ b/dlls/comctl32/header.c @@ -166,6 +166,7 @@ HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack) RECT r; INT oldBkMode, cxEdge = GetSystemMetrics(SM_CXEDGE); HTHEME theme = GetWindowTheme (hwnd); + NMCUSTOMDRAW nmcd; TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, infoPtr->bUnicode); @@ -205,22 +206,24 @@ HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack) r.left -= cxEdge; r.right += cxEdge; + /* Set the colors before sending NM_CUSTOMDRAW so that it can change them */ + SetTextColor (hdc, (bHotTrack && !theme) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT); + SetBkColor(hdc, GetSysColor(COLOR_3DFACE)); + + nmcd.hdr.hwndFrom = hwnd; + nmcd.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID); + nmcd.hdr.code = NM_CUSTOMDRAW; + nmcd.dwDrawStage = CDDS_PREPAINT | CDDS_ITEM | CDDS_ITEMPOSTERASE; + nmcd.hdc = hdc; + nmcd.dwItemSpec = iItem; + nmcd.rc = r; + nmcd.uItemState = phdi->bDown ? CDIS_SELECTED : 0; + nmcd.lItemlParam = phdi->lParam; + + SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, nmcd.hdr.idFrom, (LPARAM)&nmcd); + if (phdi->fmt & HDF_OWNERDRAW) { DRAWITEMSTRUCT dis; - NMCUSTOMDRAW nmcd; - - nmcd.hdr.hwndFrom = hwnd; - nmcd.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID); - nmcd.hdr.code = NM_CUSTOMDRAW; - nmcd.dwDrawStage = CDDS_PREPAINT | CDDS_ITEM | CDDS_ITEMPOSTERASE; - nmcd.hdc = hdc; - nmcd.dwItemSpec = iItem; - nmcd.rc = r; - nmcd.uItemState = phdi->bDown ? CDIS_SELECTED : 0; - nmcd.lItemlParam = phdi->lParam; - - SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, - (WPARAM)nmcd.hdr.idFrom, (LPARAM)&nmcd); dis.CtlType = ODT_HEADER; dis.CtlID = GetWindowLongPtrW (hwnd, GWLP_ID); @@ -249,6 +252,14 @@ HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack) rw = r.right - r.left; rh = r.bottom - r.top; + if (theme == NULL) { + HBRUSH hbr = CreateSolidBrush(GetBkColor(hdc)); + RECT rcBackground = r; + + rcBackground.right -= cxEdge; + FillRect(hdc, &rcBackground, hbr); + DeleteObject(hbr); + } if (phdi->fmt & HDF_STRING) { RECT textRect; @@ -344,7 +355,6 @@ HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack) HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */ && (phdi->pszText)) { oldBkMode = SetBkMode(hdc, TRANSPARENT); - SetTextColor (hdc, (bHotTrack && !theme) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT); r.left = tx; r.right = tx + tw; DrawTextW (hdc, phdi->pszText, -1,