From 07f86907186c45ccc9b76be4427d77979cf7585f Mon Sep 17 00:00:00 2001 From: Frank Richter Date: Wed, 3 Aug 2005 11:45:19 +0000 Subject: [PATCH] Add hottracking support for the header control. --- dlls/comctl32/header.c | 52 +++++++++++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/dlls/comctl32/header.c b/dlls/comctl32/header.c index 16f9d484d6c..7577384ee3a 100644 --- a/dlls/comctl32/header.c +++ b/dlls/comctl32/header.c @@ -416,7 +416,7 @@ HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem) hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT); hOldFont = SelectObject (hdc, hFont); - HEADER_DrawItem (hwnd, hdc, iItem, FALSE); + HEADER_DrawItem (hwnd, hdc, iItem, infoPtr->iHotItem == iItem); SelectObject (hdc, hOldFont); } @@ -1579,6 +1579,22 @@ HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam) } +static LRESULT +HEADER_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam) +{ + HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd); + /* Reset hot-tracked item when mouse leaves control. */ + INT oldHotItem = infoPtr->iHotItem; + HDC hdc = GetDC (hwnd); + + infoPtr->iHotItem = -1; + if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem); + ReleaseDC (hwnd, hdc); + + return 0; +} + + static LRESULT HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam) { @@ -1588,28 +1604,35 @@ HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam) UINT flags; INT nItem, nWidth; HDC hdc; + /* With theming, hottracking is always enabled */ + BOOL hotTrackEnabled = + ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) + || (GetWindowTheme (hwnd) != NULL); + INT oldHotItem = infoPtr->iHotItem; pt.x = (INT)(SHORT)LOWORD(lParam); pt.y = (INT)(SHORT)HIWORD(lParam); HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem); - if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) { + if (hotTrackEnabled) { if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN)) infoPtr->iHotItem = nItem; else infoPtr->iHotItem = -1; - InvalidateRect(hwnd, NULL, FALSE); } if (infoPtr->bCaptured) { if (infoPtr->bPressed) { + BOOL oldState = infoPtr->items[infoPtr->iMoveItem].bDown; if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) infoPtr->items[infoPtr->iMoveItem].bDown = TRUE; else infoPtr->items[infoPtr->iMoveItem].bDown = FALSE; - hdc = GetDC (hwnd); - HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem); - ReleaseDC (hwnd, hdc); + if (oldState != infoPtr->items[infoPtr->iMoveItem].bDown) { + hdc = GetDC (hwnd); + HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem); + ReleaseDC (hwnd, hdc); + } TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem); } @@ -1642,8 +1665,18 @@ HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam) } } - if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) { - FIXME("hot track support!\n"); + if (hotTrackEnabled) { + TRACKMOUSEEVENT tme; + if (oldHotItem != infoPtr->iHotItem) { + hdc = GetDC (hwnd); + if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem); + if (infoPtr->iHotItem != -1) HEADER_RefreshItem (hwnd, hdc, infoPtr->iHotItem); + ReleaseDC (hwnd, hdc); + } + tme.cbSize = sizeof( tme ); + tme.dwFlags = TME_LEAVE; + tme.hwndTrack = hwnd; + TrackMouseEvent( &tme ); } return 0; @@ -1853,6 +1886,9 @@ HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_LBUTTONUP: return HEADER_LButtonUp (hwnd, wParam, lParam); + case WM_MOUSELEAVE: + return HEADER_MouseLeave (hwnd, wParam, lParam); + case WM_MOUSEMOVE: return HEADER_MouseMove (hwnd, wParam, lParam);