4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2003 Maxime Bellenge
7 * Copyright 2006 Mikolaj Zalewski
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * - Imagelist support (completed?)
25 * - Hottrack support (completed?)
26 * - Filters support (HDS_FILTER, HDI_FILTER, HDM_*FILTER*, HDN_*FILTER*)
27 * - New Windows Vista features
36 #include "wine/unicode.h"
44 #include "wine/debug.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(header);
56 INT iOrder; /* see documentation of HD_ITEM */
58 BOOL bDown; /* is item pressed? (used for drawing) */
59 RECT rect; /* bounding rectangle of the item */
60 DWORD callbackMask; /* HDI_* flags for items that are callback */
66 HWND hwndSelf; /* Control window */
67 HWND hwndNotify; /* Owner window to send notifications to */
68 INT nNotifyFormat; /* format used for WM_NOTIFY messages */
69 UINT uNumItem; /* number of items (columns) */
70 INT nHeight; /* height of the header (pixels) */
71 HFONT hFont; /* handle to the current font */
72 HCURSOR hcurArrow; /* handle to the arrow cursor */
73 HCURSOR hcurDivider; /* handle to a cursor (used over dividers) <-|-> */
74 HCURSOR hcurDivopen; /* handle to a cursor (used over dividers) <-||-> */
75 BOOL bCaptured; /* Is the mouse captured? */
76 BOOL bPressed; /* Is a header item pressed (down)? */
77 BOOL bDragging; /* Are we dragging an item? */
78 BOOL bTracking; /* Is in tracking mode? */
79 POINT ptLButtonDown; /* The point where the left button was pressed */
80 DWORD dwStyle; /* the cached window GWL_STYLE */
81 INT iMoveItem; /* index of tracked item. (Tracking mode) */
82 INT xTrackOffset; /* distance between the right side of the tracked item and the cursor */
83 INT xOldTrack; /* track offset (see above) after the last WM_MOUSEMOVE */
84 INT iHotItem; /* index of hot item (cursor is over this item) */
85 INT iHotDivider; /* index of the hot divider (used while dragging an item or by HDM_SETHOTDIVIDER) */
86 INT iMargin; /* width of the margin that surrounds a bitmap */
88 HIMAGELIST himl; /* handle to an image list (may be 0) */
89 HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */
90 INT *order; /* array of item IDs indexed by order */
91 BOOL bRectsValid; /* validity flag for bounding rectangles */
96 #define DIVIDER_WIDTH 10
97 #define HOT_DIVIDER_WIDTH 2
98 #define MAX_HEADER_TEXT_LEN 260
99 #define HDN_UNICODE_OFFSET 20
100 #define HDN_FIRST_UNICODE (HDN_FIRST-HDN_UNICODE_OFFSET)
102 #define HDI_SUPPORTED_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP|HDI_IMAGE|HDI_ORDER)
103 #define HDI_UNSUPPORTED_FIELDS (HDI_FILTER)
104 #define HDI_UNKNOWN_FIELDS (~(HDI_SUPPORTED_FIELDS|HDI_UNSUPPORTED_FIELDS|HDI_DI_SETITEM))
105 #define HDI_COMCTL32_4_0_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP)
108 static BOOL HEADER_PrepareCallbackItems(const HEADER_INFO *infoPtr, INT iItem, INT reqMask);
109 static void HEADER_FreeCallbackItems(HEADER_ITEM *lpItem);
110 static LRESULT HEADER_SendNotify(const HEADER_INFO *infoPtr, UINT code, NMHDR *hdr);
111 static LRESULT HEADER_SendCtrlCustomDraw(const HEADER_INFO *infoPtr, DWORD dwDrawStage, HDC hdc, const RECT *rect);
113 static const WCHAR themeClass[] = {'H','e','a','d','e','r',0};
115 static void HEADER_StoreHDItemInHeader(HEADER_ITEM *lpItem, UINT mask, const HDITEMW *phdi, BOOL fUnicode)
117 if (mask & HDI_UNSUPPORTED_FIELDS)
118 FIXME("unsupported header fields %x\n", (mask & HDI_UNSUPPORTED_FIELDS));
120 if (mask & HDI_BITMAP)
121 lpItem->hbm = phdi->hbm;
123 if (mask & HDI_FORMAT)
124 lpItem->fmt = phdi->fmt;
126 if (mask & HDI_LPARAM)
127 lpItem->lParam = phdi->lParam;
129 if (mask & HDI_WIDTH)
130 lpItem->cxy = phdi->cxy;
132 if (mask & HDI_IMAGE)
134 lpItem->iImage = phdi->iImage;
135 if (phdi->iImage == I_IMAGECALLBACK)
136 lpItem->callbackMask |= HDI_IMAGE;
138 lpItem->callbackMask &= ~HDI_IMAGE;
143 Free(lpItem->pszText);
144 lpItem->pszText = NULL;
146 if (phdi->pszText != LPSTR_TEXTCALLBACKW) /* covers != TEXTCALLBACKA too */
148 static const WCHAR emptyString[] = {0};
150 LPCWSTR pszText = (phdi->pszText != NULL ? phdi->pszText : emptyString);
152 Str_SetPtrW(&lpItem->pszText, pszText);
154 Str_SetPtrAtoW(&lpItem->pszText, (LPCSTR)pszText);
155 lpItem->callbackMask &= ~HDI_TEXT;
159 lpItem->pszText = NULL;
160 lpItem->callbackMask |= HDI_TEXT;
165 static inline LRESULT
166 HEADER_IndexToOrder (const HEADER_INFO *infoPtr, INT iItem)
168 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
169 return lpItem->iOrder;
174 HEADER_OrderToIndex(const HEADER_INFO *infoPtr, INT iorder)
176 if ((iorder <0) || iorder >= infoPtr->uNumItem)
178 return infoPtr->order[iorder];
182 HEADER_ChangeItemOrder(const HEADER_INFO *infoPtr, INT iItem, INT iNewOrder)
184 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
187 TRACE("%d: %d->%d\n", iItem, lpItem->iOrder, iNewOrder);
188 if (lpItem->iOrder < iNewOrder)
190 memmove(&infoPtr->order[lpItem->iOrder],
191 &infoPtr->order[lpItem->iOrder + 1],
192 (iNewOrder - lpItem->iOrder) * sizeof(INT));
194 if (iNewOrder < lpItem->iOrder)
196 memmove(&infoPtr->order[iNewOrder + 1],
197 &infoPtr->order[iNewOrder],
198 (lpItem->iOrder - iNewOrder) * sizeof(INT));
200 infoPtr->order[iNewOrder] = iItem;
201 nMin = min(lpItem->iOrder, iNewOrder);
202 nMax = max(lpItem->iOrder, iNewOrder);
203 for (i = nMin; i <= nMax; i++)
204 infoPtr->items[infoPtr->order[i]].iOrder = i;
207 /* Note: if iItem is the last item then this function returns infoPtr->uNumItem */
209 HEADER_NextItem(const HEADER_INFO *infoPtr, INT iItem)
211 return HEADER_OrderToIndex(infoPtr, HEADER_IndexToOrder(infoPtr, iItem)+1);
215 HEADER_PrevItem(const HEADER_INFO *infoPtr, INT iItem)
217 return HEADER_OrderToIndex(infoPtr, HEADER_IndexToOrder(infoPtr, iItem)-1);
220 /* TRUE when item is not resizable with dividers,
221 note that valid index should be supplied */
223 HEADER_IsItemFixed(const HEADER_INFO *infoPtr, INT iItem)
225 return (infoPtr->dwStyle & HDS_NOSIZING) || (infoPtr->items[iItem].fmt & HDF_FIXEDWIDTH);
229 HEADER_SetItemBounds (HEADER_INFO *infoPtr)
236 infoPtr->bRectsValid = TRUE;
238 if (infoPtr->uNumItem == 0)
241 GetClientRect (infoPtr->hwndSelf, &rect);
244 for (i = 0; i < infoPtr->uNumItem; i++) {
245 phdi = &infoPtr->items[HEADER_OrderToIndex(infoPtr,i)];
246 phdi->rect.top = rect.top;
247 phdi->rect.bottom = rect.bottom;
249 phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
250 x = phdi->rect.right;
255 HEADER_Size (HEADER_INFO *infoPtr)
257 HEADER_SetItemBounds(infoPtr);
261 static void HEADER_GetHotDividerRect(const HEADER_INFO *infoPtr, RECT *r)
263 INT iDivider = infoPtr->iHotDivider;
264 if (infoPtr->uNumItem > 0)
268 if (iDivider < infoPtr->uNumItem)
270 lpItem = &infoPtr->items[iDivider];
271 r->left = lpItem->rect.left - HOT_DIVIDER_WIDTH/2;
272 r->right = lpItem->rect.left + HOT_DIVIDER_WIDTH/2;
276 lpItem = &infoPtr->items[HEADER_OrderToIndex(infoPtr, infoPtr->uNumItem-1)];
277 r->left = lpItem->rect.right - HOT_DIVIDER_WIDTH/2;
278 r->right = lpItem->rect.right + HOT_DIVIDER_WIDTH/2;
280 r->top = lpItem->rect.top;
281 r->bottom = lpItem->rect.bottom;
286 GetClientRect(infoPtr->hwndSelf, &clientRect);
288 r->right = r->left + HOT_DIVIDER_WIDTH/2;
294 HEADER_DrawItem (HEADER_INFO *infoPtr, HDC hdc, INT iItem, BOOL bHotTrack, LRESULT lCDFlags)
296 HEADER_ITEM *phdi = &infoPtr->items[iItem];
299 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
302 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, (infoPtr->nNotifyFormat == NFR_UNICODE));
305 if (r.right - r.left == 0)
306 return phdi->rect.right;
308 /* Set the colors before sending NM_CUSTOMDRAW so that it can change them */
309 SetTextColor(hdc, (bHotTrack && !theme) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
310 SetBkColor(hdc, comctl32_color.clr3dFace);
312 if (lCDFlags & CDRF_NOTIFYITEMDRAW && !(phdi->fmt & HDF_OWNERDRAW))
314 LRESULT lCDItemFlags;
316 nmcd.dwDrawStage = CDDS_PREPAINT | CDDS_ITEM;
318 nmcd.dwItemSpec = iItem;
320 nmcd.uItemState = phdi->bDown ? CDIS_SELECTED : 0;
321 nmcd.lItemlParam = phdi->lParam;
323 lCDItemFlags = HEADER_SendNotify(infoPtr, NM_CUSTOMDRAW, (NMHDR *)&nmcd);
324 if (lCDItemFlags & CDRF_SKIPDEFAULT)
325 return phdi->rect.right;
329 int state = (phdi->bDown) ? HIS_PRESSED :
330 (bHotTrack ? HIS_HOT : HIS_NORMAL);
331 DrawThemeBackground (theme, hdc, HP_HEADERITEM, state,
333 GetThemeBackgroundContentRect (theme, hdc, HP_HEADERITEM, state,
339 if (!(infoPtr->dwStyle & HDS_FLAT))
341 if (infoPtr->dwStyle & HDS_BUTTONS) {
343 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
344 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
347 DrawEdge (hdc, &r, EDGE_RAISED,
348 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
351 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
354 hbr = CreateSolidBrush(GetBkColor(hdc));
355 FillRect(hdc, &r, hbr);
363 if (phdi->fmt & HDF_OWNERDRAW) {
366 dis.CtlType = ODT_HEADER;
367 dis.CtlID = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
369 dis.itemAction = ODA_DRAWENTIRE;
370 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
371 dis.hwndItem = infoPtr->hwndSelf;
373 dis.rcItem = phdi->rect;
374 dis.itemData = phdi->lParam;
375 oldBkMode = SetBkMode(hdc, TRANSPARENT);
376 SendMessageW (infoPtr->hwndNotify, WM_DRAWITEM, dis.CtlID, (LPARAM)&dis);
377 if (oldBkMode != TRANSPARENT)
378 SetBkMode(hdc, oldBkMode);
381 UINT rw, rh, /* width and height of r */
382 *x = NULL, *w = NULL; /* x and width of the pic (bmp or img) which is part of cnt */
383 /* cnt,txt,img,bmp */
389 HEADER_PrepareCallbackItems(infoPtr, iItem, HDI_TEXT|HDI_IMAGE);
390 cw = tw = iw = bw = 0;
391 rw = r.right - r.left;
392 rh = r.bottom - r.top;
394 if (phdi->fmt & HDF_STRING) {
397 SetRectEmpty(&textRect);
398 DrawTextW (hdc, phdi->pszText, -1,
399 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
400 cw = textRect.right - textRect.left + 2 * infoPtr->iMargin;
403 if ((phdi->fmt & HDF_IMAGE) && ImageList_GetIconSize( infoPtr->himl, &img_cx, &img_cy )) {
404 iw = img_cx + 2 * infoPtr->iMargin;
409 if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
410 GetObjectW (phdi->hbm, sizeof(BITMAP), &bmp);
411 bw = bmp.bmWidth + 2 * infoPtr->iMargin;
421 /* align cx using the unclipped cw */
422 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_LEFT)
424 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
425 cx = r.left + rw / 2 - cw / 2;
432 if (cx + cw > r.right)
435 tx = cx + infoPtr->iMargin;
436 /* since cw might have changed we have to recalculate tw */
437 tw = cw - infoPtr->iMargin * 2;
441 if (phdi->fmt & HDF_BITMAP_ON_RIGHT) {
442 /* put pic behind text */
443 *x = cx + tw + infoPtr->iMargin * 3;
445 *x = cx + infoPtr->iMargin;
446 /* move text behind pic */
452 /* since we're done with the layout we can
453 now calculate the position of bmp which
454 has no influence on alignment and layout
456 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
457 bx = cx - bw + infoPtr->iMargin;
459 bx = cx + cw + infoPtr->iMargin;
463 HDC hClipDC = GetDC(infoPtr->hwndSelf);
464 HRGN hClipRgn = CreateRectRgn(r.left, r.top, r.right, r.bottom);
465 SelectClipRgn(hClipDC, hClipRgn);
468 HDC hdcBitmap = CreateCompatibleDC (hClipDC);
469 SelectObject (hdcBitmap, phdi->hbm);
470 BitBlt (hClipDC, bx, r.top + ((INT)rh - bmp.bmHeight) / 2,
471 bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
472 DeleteDC (hdcBitmap);
476 ImageList_DrawEx (infoPtr->himl, phdi->iImage, hClipDC,
477 ix, r.top + ((INT)rh - img_cy) / 2,
478 img_cx, img_cy, CLR_DEFAULT, CLR_DEFAULT, 0);
481 DeleteObject(hClipRgn);
482 ReleaseDC(infoPtr->hwndSelf, hClipDC);
485 if (((phdi->fmt & HDF_STRING)
486 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
487 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
488 && (phdi->pszText)) {
489 oldBkMode = SetBkMode(hdc, TRANSPARENT);
492 DrawTextW (hdc, phdi->pszText, -1,
493 &r, DT_LEFT|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
494 if (oldBkMode != TRANSPARENT)
495 SetBkMode(hdc, oldBkMode);
497 HEADER_FreeCallbackItems(phdi);
500 return phdi->rect.right;
504 HEADER_DrawHotDivider(const HEADER_INFO *infoPtr, HDC hdc)
509 HEADER_GetHotDividerRect(infoPtr, &r);
510 brush = CreateSolidBrush(comctl32_color.clrHighlight);
511 FillRect(hdc, &r, brush);
516 HEADER_Refresh (HEADER_INFO *infoPtr, HDC hdc)
518 HFONT hFont, hOldFont;
524 HTHEME theme = GetWindowTheme (infoPtr->hwndSelf);
526 if (!infoPtr->bRectsValid)
527 HEADER_SetItemBounds(infoPtr);
529 /* get rect for the bar, adjusted for the border */
530 GetClientRect (infoPtr->hwndSelf, &rect);
531 lCDFlags = HEADER_SendCtrlCustomDraw(infoPtr, CDDS_PREPAINT, hdc, &rect);
533 if (infoPtr->bDragging)
534 ImageList_DragShowNolock(FALSE);
536 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
537 hOldFont = SelectObject (hdc, hFont);
539 /* draw Background */
540 if (infoPtr->uNumItem == 0 && theme == NULL) {
541 hbrBk = GetSysColorBrush(COLOR_3DFACE);
542 FillRect(hdc, &rect, hbrBk);
546 for (i = 0; x <= rect.right && i < infoPtr->uNumItem; i++) {
547 int idx = HEADER_OrderToIndex(infoPtr,i);
548 if (RectVisible(hdc, &infoPtr->items[idx].rect))
549 HEADER_DrawItem(infoPtr, hdc, idx, infoPtr->iHotItem == idx, lCDFlags);
550 x = infoPtr->items[idx].rect.right;
555 if ((x <= rect.right) && RectVisible(hdc, &rcRest) && (infoPtr->uNumItem > 0)) {
557 DrawThemeBackground(theme, hdc, HP_HEADERITEM, HIS_NORMAL, &rcRest, NULL);
559 else if (infoPtr->dwStyle & HDS_FLAT) {
560 hbrBk = GetSysColorBrush(COLOR_3DFACE);
561 FillRect(hdc, &rcRest, hbrBk);
565 if (infoPtr->dwStyle & HDS_BUTTONS)
566 DrawEdge (hdc, &rcRest, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT|BF_MIDDLE);
568 DrawEdge (hdc, &rcRest, EDGE_ETCHED, BF_BOTTOM|BF_MIDDLE);
572 if (infoPtr->iHotDivider != -1)
573 HEADER_DrawHotDivider(infoPtr, hdc);
575 if (infoPtr->bDragging)
576 ImageList_DragShowNolock(TRUE);
577 SelectObject (hdc, hOldFont);
579 if (lCDFlags & CDRF_NOTIFYPOSTPAINT)
580 HEADER_SendCtrlCustomDraw(infoPtr, CDDS_POSTPAINT, hdc, &rect);
585 HEADER_RefreshItem (HEADER_INFO *infoPtr, INT iItem)
587 if (!infoPtr->bRectsValid)
588 HEADER_SetItemBounds(infoPtr);
590 InvalidateRect(infoPtr->hwndSelf, &infoPtr->items[iItem].rect, FALSE);
595 HEADER_InternalHitTest (const HEADER_INFO *infoPtr, const POINT *lpPt, UINT *pFlags, INT *pItem)
602 GetClientRect (infoPtr->hwndSelf, &rect);
606 if (PtInRect (&rect, *lpPt))
608 if (infoPtr->uNumItem == 0) {
609 *pFlags |= HHT_NOWHERE;
615 /* somewhere inside */
616 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
617 rect = infoPtr->items[iCount].rect;
618 width = rect.right - rect.left;
623 if (PtInRect (&rect, *lpPt)) {
624 if (width <= 2 * DIVIDER_WIDTH) {
625 *pFlags |= HHT_ONHEADER;
627 TRACE("ON HEADER %d\n", iCount);
630 if (HEADER_IndexToOrder(infoPtr, iCount) > 0) {
632 rcTest.right = rcTest.left + DIVIDER_WIDTH;
633 if (PtInRect (&rcTest, *lpPt)) {
634 if (HEADER_IsItemFixed(infoPtr, HEADER_PrevItem(infoPtr, iCount)))
636 *pFlags |= HHT_ONHEADER;
638 TRACE("ON HEADER %d\n", *pItem);
642 *pFlags |= HHT_ONDIVOPEN;
643 *pItem = HEADER_PrevItem(infoPtr, iCount);
644 TRACE("ON DIVOPEN %d\n", *pItem);
648 *pFlags |= HHT_ONDIVIDER;
649 *pItem = HEADER_PrevItem(infoPtr, iCount);
650 TRACE("ON DIVIDER %d\n", *pItem);
656 rcTest.left = rcTest.right - DIVIDER_WIDTH;
657 if (!HEADER_IsItemFixed(infoPtr, iCount) && PtInRect (&rcTest, *lpPt))
659 *pFlags |= HHT_ONDIVIDER;
661 TRACE("ON DIVIDER %d\n", *pItem);
665 *pFlags |= HHT_ONHEADER;
667 TRACE("ON HEADER %d\n", iCount);
672 /* check for last divider part (on nowhere) */
673 if (!HEADER_IsItemFixed(infoPtr, infoPtr->uNumItem - 1))
675 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
676 rect.left = rect.right;
677 rect.right += DIVIDER_WIDTH;
678 if (PtInRect (&rect, *lpPt)) {
680 *pFlags |= HHT_ONDIVOPEN;
681 *pItem = infoPtr->uNumItem - 1;
682 TRACE("ON DIVOPEN %d\n", *pItem);
686 *pFlags |= HHT_ONDIVIDER;
687 *pItem = infoPtr->uNumItem - 1;
688 TRACE("ON DIVIDER %d\n", *pItem);
694 *pFlags |= HHT_NOWHERE;
701 if (lpPt->x < rect.left) {
703 *pFlags |= HHT_TOLEFT;
705 else if (lpPt->x > rect.right) {
707 *pFlags |= HHT_TORIGHT;
710 if (lpPt->y < rect.top) {
712 *pFlags |= HHT_ABOVE;
714 else if (lpPt->y > rect.bottom) {
716 *pFlags |= HHT_BELOW;
721 TRACE("flags=0x%X\n", *pFlags);
727 HEADER_DrawTrackLine (const HEADER_INFO *infoPtr, HDC hdc, INT x)
733 GetClientRect (infoPtr->hwndSelf, &rect);
735 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
736 oldRop = SetROP2 (hdc, R2_XORPEN);
737 MoveToEx (hdc, x, rect.top, NULL);
738 LineTo (hdc, x, rect.bottom);
739 SetROP2 (hdc, oldRop);
740 SelectObject (hdc, hOldPen);
745 * Convert a HDITEM into the correct format (ANSI/Unicode) to send it in a notify
748 * [I] infoPtr : the header that wants to send the notify
749 * [O] dest : The buffer to store the HDITEM for notify. It may be set to a HDITEMA of HDITEMW
750 * [I] src : The source HDITEM. It may be a HDITEMA or HDITEMW
751 * [I] fSourceUnicode : is src a HDITEMW or HDITEMA
752 * [O] ppvScratch : a pointer to a scratch buffer that needs to be freed after
753 * the HDITEM is no longer in use or NULL if none was needed
755 * NOTE: We depend on HDITEMA and HDITEMW having the same structure
757 static void HEADER_CopyHDItemForNotify(const HEADER_INFO *infoPtr, HDITEMW *dest,
758 const HDITEMW *src, BOOL fSourceUnicode, LPVOID *ppvScratch)
763 if (src->mask & HDI_TEXT && src->pszText != LPSTR_TEXTCALLBACKW) /* covers TEXTCALLBACKA as well */
765 if (fSourceUnicode && infoPtr->nNotifyFormat != NFR_UNICODE)
767 dest->pszText = NULL;
768 Str_SetPtrWtoA((LPSTR *)&dest->pszText, src->pszText);
769 *ppvScratch = dest->pszText;
772 if (!fSourceUnicode && infoPtr->nNotifyFormat == NFR_UNICODE)
774 dest->pszText = NULL;
775 Str_SetPtrAtoW(&dest->pszText, (LPSTR)src->pszText);
776 *ppvScratch = dest->pszText;
781 static UINT HEADER_NotifyCodeWtoA(UINT code)
783 /* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
784 if (code >= HDN_LAST && code <= HDN_FIRST_UNICODE)
785 return code + HDN_UNICODE_OFFSET;
791 HEADER_SendNotify(const HEADER_INFO *infoPtr, UINT code, NMHDR *nmhdr)
793 nmhdr->hwndFrom = infoPtr->hwndSelf;
794 nmhdr->idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
797 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
798 nmhdr->idFrom, (LPARAM)nmhdr);
802 HEADER_SendSimpleNotify (const HEADER_INFO *infoPtr, UINT code)
805 return (BOOL)HEADER_SendNotify(infoPtr, code, &nmhdr);
809 HEADER_SendCtrlCustomDraw(const HEADER_INFO *infoPtr, DWORD dwDrawStage, HDC hdc, const RECT *rect)
812 nm.dwDrawStage = dwDrawStage;
819 return HEADER_SendNotify(infoPtr, NM_CUSTOMDRAW, (NMHDR *)&nm);
823 HEADER_SendNotifyWithHDItemT(const HEADER_INFO *infoPtr, UINT code, INT iItem, HDITEMW *lpItem)
827 if (infoPtr->nNotifyFormat != NFR_UNICODE)
828 code = HEADER_NotifyCodeWtoA(code);
831 nmhdr.pitem = lpItem;
833 return (BOOL)HEADER_SendNotify(infoPtr, code, (NMHDR *)&nmhdr);
837 HEADER_SendNotifyWithIntFieldT(const HEADER_INFO *infoPtr, UINT code, INT iItem, INT mask, INT iValue)
841 /* copying only the iValue should be ok but to make the code more robust we copy everything */
842 nmitem.cxy = infoPtr->items[iItem].cxy;
843 nmitem.hbm = infoPtr->items[iItem].hbm;
844 nmitem.pszText = NULL;
845 nmitem.cchTextMax = 0;
846 nmitem.fmt = infoPtr->items[iItem].fmt;
847 nmitem.lParam = infoPtr->items[iItem].lParam;
848 nmitem.iOrder = infoPtr->items[iItem].iOrder;
849 nmitem.iImage = infoPtr->items[iItem].iImage;
858 nmitem.iOrder = iValue;
861 ERR("invalid mask value 0x%x\n", iValue);
864 return HEADER_SendNotifyWithHDItemT(infoPtr, code, iItem, &nmitem);
868 * Prepare callback items
869 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
870 * (so we handle the two cases only doing a specific cast for pszText).
871 * Checks if any of the required field are callback. If there are sends a
872 * NMHDISPINFO notify to retrieve these items. The items are stored in the
873 * HEADER_ITEM pszText and iImage fields. They should be freed with
874 * HEADER_FreeCallbackItems.
876 * @param hwnd : hwnd header container handler
877 * @param iItem : the header item id
878 * @param reqMask : required fields. If any of them is callback this function will fetch it
880 * @return TRUE on success, else FALSE
883 HEADER_PrepareCallbackItems(const HEADER_INFO *infoPtr, INT iItem, INT reqMask)
885 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
886 DWORD mask = reqMask & lpItem->callbackMask;
887 NMHDDISPINFOW dispInfo;
888 void *pvBuffer = NULL;
892 if (mask&HDI_TEXT && lpItem->pszText != NULL)
894 ERR("(): function called without a call to FreeCallbackItems\n");
895 Free(lpItem->pszText);
896 lpItem->pszText = NULL;
899 memset(&dispInfo, 0, sizeof(NMHDDISPINFOW));
900 dispInfo.hdr.hwndFrom = infoPtr->hwndSelf;
901 dispInfo.hdr.idFrom = GetWindowLongPtrW (infoPtr->hwndSelf, GWLP_ID);
902 if (infoPtr->nNotifyFormat == NFR_UNICODE)
904 dispInfo.hdr.code = HDN_GETDISPINFOW;
906 pvBuffer = Alloc(MAX_HEADER_TEXT_LEN * sizeof(WCHAR));
910 dispInfo.hdr.code = HDN_GETDISPINFOA;
912 pvBuffer = Alloc(MAX_HEADER_TEXT_LEN * sizeof(CHAR));
914 dispInfo.pszText = pvBuffer;
915 dispInfo.cchTextMax = (pvBuffer!=NULL?MAX_HEADER_TEXT_LEN:0);
916 dispInfo.iItem = iItem;
917 dispInfo.mask = mask;
918 dispInfo.lParam = lpItem->lParam;
920 TRACE("Sending HDN_GETDISPINFO%c\n", infoPtr->nNotifyFormat == NFR_UNICODE?'W':'A');
921 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, dispInfo.hdr.idFrom, (LPARAM)&dispInfo);
923 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
925 (infoPtr->nNotifyFormat == NFR_UNICODE ? debugstr_w(dispInfo.pszText) : (LPSTR) dispInfo.pszText),
926 (void*) dispInfo.lParam);
928 if (mask & HDI_IMAGE)
929 lpItem->iImage = dispInfo.iImage;
932 if (infoPtr->nNotifyFormat == NFR_UNICODE)
934 lpItem->pszText = pvBuffer;
936 /* the user might have used his own buffer */
937 if (dispInfo.pszText != lpItem->pszText)
938 Str_GetPtrW(dispInfo.pszText, lpItem->pszText, MAX_HEADER_TEXT_LEN);
942 Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)dispInfo.pszText);
947 if (dispInfo.mask & HDI_DI_SETITEM)
949 /* make the items permanent */
950 lpItem->callbackMask &= ~dispInfo.mask;
958 * Free the items that might be allocated with HEADER_PrepareCallbackItems
961 * [I] lpItem : the item to free the data
965 HEADER_FreeCallbackItems(HEADER_ITEM *lpItem)
967 if (lpItem->callbackMask&HDI_TEXT)
969 Free(lpItem->pszText);
970 lpItem->pszText = NULL;
973 if (lpItem->callbackMask&HDI_IMAGE)
974 lpItem->iImage = I_IMAGECALLBACK;
978 HEADER_CreateDragImage (HEADER_INFO *infoPtr, INT iItem)
982 HBITMAP hMemory, hOldBitmap;
990 if (iItem >= infoPtr->uNumItem)
993 if (!infoPtr->bRectsValid)
994 HEADER_SetItemBounds(infoPtr);
996 lpItem = &infoPtr->items[iItem];
997 width = lpItem->rect.right - lpItem->rect.left;
998 height = lpItem->rect.bottom - lpItem->rect.top;
1000 hDeviceDC = GetDC(NULL);
1001 hMemoryDC = CreateCompatibleDC(hDeviceDC);
1002 hMemory = CreateCompatibleBitmap(hDeviceDC, width, height);
1003 ReleaseDC(NULL, hDeviceDC);
1004 hOldBitmap = SelectObject(hMemoryDC, hMemory);
1005 SetViewportOrgEx(hMemoryDC, -lpItem->rect.left, -lpItem->rect.top, NULL);
1006 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject(SYSTEM_FONT);
1007 SelectObject(hMemoryDC, hFont);
1009 GetClientRect(infoPtr->hwndSelf, &rc);
1010 lCDFlags = HEADER_SendCtrlCustomDraw(infoPtr, CDDS_PREPAINT, hMemoryDC, &rc);
1011 HEADER_DrawItem(infoPtr, hMemoryDC, iItem, FALSE, lCDFlags);
1012 if (lCDFlags & CDRF_NOTIFYPOSTPAINT)
1013 HEADER_SendCtrlCustomDraw(infoPtr, CDDS_POSTPAINT, hMemoryDC, &rc);
1015 hMemory = SelectObject(hMemoryDC, hOldBitmap);
1016 DeleteDC(hMemoryDC);
1018 if (hMemory == NULL) /* if anything failed */
1021 himl = ImageList_Create(width, height, ILC_COLORDDB, 1, 1);
1022 ImageList_Add(himl, hMemory, NULL);
1023 DeleteObject(hMemory);
1024 return (LRESULT)himl;
1028 HEADER_SetHotDivider(HEADER_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1037 pt.x = (INT)(SHORT)LOWORD(lParam);
1039 HEADER_InternalHitTest (infoPtr, &pt, &flags, &iDivider);
1041 if (flags & HHT_TOLEFT)
1043 else if (flags & HHT_NOWHERE || flags & HHT_TORIGHT)
1044 iDivider = infoPtr->uNumItem;
1047 HEADER_ITEM *lpItem = &infoPtr->items[iDivider];
1048 if (pt.x > (lpItem->rect.left+lpItem->rect.right)/2)
1049 iDivider = HEADER_NextItem(infoPtr, iDivider);
1053 iDivider = (INT)lParam;
1055 /* Note; wParam==FALSE, lParam==-1 is valid and is used to clear the hot divider */
1056 if (iDivider<-1 || iDivider>(int)infoPtr->uNumItem)
1059 if (iDivider != infoPtr->iHotDivider)
1061 if (infoPtr->iHotDivider != -1)
1063 HEADER_GetHotDividerRect(infoPtr, &r);
1064 InvalidateRect(infoPtr->hwndSelf, &r, FALSE);
1066 infoPtr->iHotDivider = iDivider;
1069 HEADER_GetHotDividerRect(infoPtr, &r);
1070 InvalidateRect(infoPtr->hwndSelf, &r, FALSE);
1077 HEADER_DeleteItem (HEADER_INFO *infoPtr, INT iItem)
1082 TRACE("[iItem=%d]\n", iItem);
1084 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
1087 for (i = 0; i < infoPtr->uNumItem; i++)
1088 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
1090 iOrder = infoPtr->items[iItem].iOrder;
1091 Free(infoPtr->items[iItem].pszText);
1093 infoPtr->uNumItem--;
1094 memmove(&infoPtr->items[iItem], &infoPtr->items[iItem + 1],
1095 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
1096 memmove(&infoPtr->order[iOrder], &infoPtr->order[iOrder + 1],
1097 (infoPtr->uNumItem - iOrder) * sizeof(INT));
1098 infoPtr->items = ReAlloc(infoPtr->items, sizeof(HEADER_ITEM) * infoPtr->uNumItem);
1099 infoPtr->order = ReAlloc(infoPtr->order, sizeof(INT) * infoPtr->uNumItem);
1101 /* Correct the orders */
1102 for (i = 0; i < infoPtr->uNumItem; i++)
1104 if (infoPtr->order[i] > iItem)
1105 infoPtr->order[i]--;
1107 infoPtr->items[infoPtr->order[i]].iOrder = i;
1109 for (i = 0; i < infoPtr->uNumItem; i++)
1110 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
1112 HEADER_SetItemBounds (infoPtr);
1113 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1120 HEADER_GetImageList (const HEADER_INFO *infoPtr)
1122 return (LRESULT)infoPtr->himl;
1127 HEADER_GetItemT (const HEADER_INFO *infoPtr, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
1129 HEADER_ITEM *lpItem;
1135 TRACE("[nItem=%d]\n", nItem);
1141 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1144 if (mask & HDI_UNKNOWN_FIELDS)
1146 TRACE("mask %x contains unknown fields. Using only comctl32 4.0 fields\n", mask);
1147 mask &= HDI_COMCTL32_4_0_FIELDS;
1150 lpItem = &infoPtr->items[nItem];
1151 HEADER_PrepareCallbackItems(infoPtr, nItem, mask);
1153 if (mask & HDI_BITMAP)
1154 phdi->hbm = lpItem->hbm;
1156 if (mask & HDI_FORMAT)
1157 phdi->fmt = lpItem->fmt;
1159 if (mask & HDI_WIDTH)
1160 phdi->cxy = lpItem->cxy;
1162 if (mask & HDI_LPARAM)
1163 phdi->lParam = lpItem->lParam;
1165 if (mask & HDI_IMAGE)
1166 phdi->iImage = lpItem->iImage;
1168 if (mask & HDI_ORDER)
1169 phdi->iOrder = lpItem->iOrder;
1171 if (mask & HDI_TEXT)
1174 Str_GetPtrW (lpItem->pszText, phdi->pszText, phdi->cchTextMax);
1176 Str_GetPtrWtoA (lpItem->pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
1179 HEADER_FreeCallbackItems(lpItem);
1184 static inline LRESULT
1185 HEADER_GetItemCount (const HEADER_INFO *infoPtr)
1187 return infoPtr->uNumItem;
1192 HEADER_GetItemRect (const HEADER_INFO *infoPtr, INT iItem, LPRECT lpRect)
1194 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
1197 lpRect->left = infoPtr->items[iItem].rect.left;
1198 lpRect->right = infoPtr->items[iItem].rect.right;
1199 lpRect->top = infoPtr->items[iItem].rect.top;
1200 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
1207 HEADER_GetOrderArray(const HEADER_INFO *infoPtr, INT size, LPINT order)
1209 if ((UINT)size <infoPtr->uNumItem)
1212 memcpy(order, infoPtr->order, infoPtr->uNumItem * sizeof(INT));
1216 /* Returns index of first duplicate 'value' from [0,to) range,
1217 or -1 if there isn't any */
1218 static INT has_duplicate(const INT *array, INT to, INT value)
1221 for(i = 0; i < to; i++)
1222 if (array[i] == value) return i;
1226 /* returns next available value from [0,max] not to duplicate in [0,to) */
1227 static INT get_nextvalue(const INT *array, INT to, INT max)
1230 for(i = 0; i < max; i++)
1231 if (has_duplicate(array, to, i) == -1) return i;
1236 HEADER_SetOrderArray(HEADER_INFO *infoPtr, INT size, const INT *order)
1238 HEADER_ITEM *lpItem;
1241 if ((UINT)size != infoPtr->uNumItem)
1244 for (i=0; i<size; i++)
1246 if (order[i] >= size || order[i] < 0)
1247 /* on invalid index get next available */
1248 /* FIXME: if i==0 array item is out of range behaviour is
1249 different, see tests */
1250 infoPtr->order[i] = get_nextvalue(infoPtr->order, i, size);
1255 infoPtr->order[i] = order[i];
1257 /* remove duplicates */
1258 while ((dup = has_duplicate(infoPtr->order, j, order[j])) != -1)
1262 next = get_nextvalue(infoPtr->order, j, size);
1263 infoPtr->order[dup] = next;
1268 /* sync with item data */
1269 for (i=0; i<size; i++)
1271 lpItem = &infoPtr->items[infoPtr->order[i]];
1274 HEADER_SetItemBounds(infoPtr);
1275 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1279 static inline LRESULT
1280 HEADER_GetUnicodeFormat (const HEADER_INFO *infoPtr)
1282 return (infoPtr->nNotifyFormat == NFR_UNICODE);
1287 HEADER_HitTest (const HEADER_INFO *infoPtr, LPHDHITTESTINFO phti)
1289 UINT outside = HHT_NOWHERE | HHT_ABOVE | HHT_BELOW | HHT_TOLEFT | HHT_TORIGHT;
1291 HEADER_InternalHitTest (infoPtr, &phti->pt, &phti->flags, &phti->iItem);
1293 if (phti->flags & outside)
1294 return phti->iItem = -1;
1301 HEADER_InsertItemT (HEADER_INFO *infoPtr, INT nItem, const HDITEMW *phdi, BOOL bUnicode)
1303 HEADER_ITEM *lpItem;
1308 if ((phdi == NULL) || (nItem < 0) || (phdi->mask == 0))
1311 if (nItem > infoPtr->uNumItem)
1312 nItem = infoPtr->uNumItem;
1314 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
1317 else if (infoPtr->uNumItem < iOrder)
1318 iOrder = infoPtr->uNumItem;
1320 infoPtr->uNumItem++;
1321 infoPtr->items = ReAlloc(infoPtr->items, sizeof(HEADER_ITEM) * infoPtr->uNumItem);
1322 infoPtr->order = ReAlloc(infoPtr->order, sizeof(INT) * infoPtr->uNumItem);
1324 /* make space for the new item */
1325 memmove(&infoPtr->items[nItem + 1], &infoPtr->items[nItem],
1326 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
1327 memmove(&infoPtr->order[iOrder + 1], &infoPtr->order[iOrder],
1328 (infoPtr->uNumItem - iOrder - 1) * sizeof(INT));
1330 /* update the order array */
1331 infoPtr->order[iOrder] = nItem;
1332 for (i = 0; i < infoPtr->uNumItem; i++)
1334 if (i != iOrder && infoPtr->order[i] >= nItem)
1335 infoPtr->order[i]++;
1336 infoPtr->items[infoPtr->order[i]].iOrder = i;
1339 lpItem = &infoPtr->items[nItem];
1340 ZeroMemory(lpItem, sizeof(HEADER_ITEM));
1341 /* cxy, fmt and lParam are copied even if not in the HDITEM mask */
1342 copyMask = phdi->mask | HDI_WIDTH | HDI_FORMAT | HDI_LPARAM;
1343 HEADER_StoreHDItemInHeader(lpItem, copyMask, phdi, bUnicode);
1344 lpItem->iOrder = iOrder;
1346 /* set automatically some format bits */
1347 if (phdi->mask & HDI_TEXT)
1348 lpItem->fmt |= HDF_STRING;
1350 lpItem->fmt &= ~HDF_STRING;
1352 if (lpItem->hbm != NULL)
1353 lpItem->fmt |= HDF_BITMAP;
1355 lpItem->fmt &= ~HDF_BITMAP;
1357 if (phdi->mask & HDI_IMAGE)
1358 lpItem->fmt |= HDF_IMAGE;
1360 HEADER_SetItemBounds (infoPtr);
1361 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1368 HEADER_Layout (HEADER_INFO *infoPtr, LPHDLAYOUT lpLayout)
1370 lpLayout->pwpos->hwnd = infoPtr->hwndSelf;
1371 lpLayout->pwpos->hwndInsertAfter = 0;
1372 lpLayout->pwpos->x = lpLayout->prc->left;
1373 lpLayout->pwpos->y = lpLayout->prc->top;
1374 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1375 if (infoPtr->dwStyle & HDS_HIDDEN)
1376 lpLayout->pwpos->cy = 0;
1378 lpLayout->pwpos->cy = infoPtr->nHeight;
1379 lpLayout->prc->top += infoPtr->nHeight;
1381 lpLayout->pwpos->flags = SWP_NOZORDER;
1383 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1384 lpLayout->pwpos->x, lpLayout->pwpos->y,
1385 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1387 infoPtr->bRectsValid = FALSE;
1394 HEADER_SetImageList (HEADER_INFO *infoPtr, HIMAGELIST himl)
1398 TRACE("(himl %p)\n", himl);
1399 himlOld = infoPtr->himl;
1400 infoPtr->himl = himl;
1402 /* FIXME: Refresh needed??? */
1404 return (LRESULT)himlOld;
1409 HEADER_GetBitmapMargin(const HEADER_INFO *infoPtr)
1411 return infoPtr->iMargin;
1415 HEADER_SetBitmapMargin(HEADER_INFO *infoPtr, INT iMargin)
1417 INT oldMargin = infoPtr->iMargin;
1419 infoPtr->iMargin = iMargin;
1425 HEADER_SetItemT (HEADER_INFO *infoPtr, INT nItem, const HDITEMW *phdi, BOOL bUnicode)
1427 HEADER_ITEM *lpItem;
1433 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1436 TRACE("[nItem=%d]\n", nItem);
1438 HEADER_CopyHDItemForNotify(infoPtr, &hdNotify, phdi, bUnicode, &pvScratch);
1439 if (HEADER_SendNotifyWithHDItemT(infoPtr, HDN_ITEMCHANGINGW, nItem, &hdNotify))
1445 lpItem = &infoPtr->items[nItem];
1446 HEADER_StoreHDItemInHeader(lpItem, phdi->mask, phdi, bUnicode);
1448 if (phdi->mask & HDI_ORDER)
1449 if (phdi->iOrder >= 0 && phdi->iOrder < infoPtr->uNumItem)
1450 HEADER_ChangeItemOrder(infoPtr, nItem, phdi->iOrder);
1452 HEADER_SendNotifyWithHDItemT(infoPtr, HDN_ITEMCHANGEDW, nItem, &hdNotify);
1454 HEADER_SetItemBounds (infoPtr);
1456 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1462 static inline LRESULT
1463 HEADER_SetUnicodeFormat (HEADER_INFO *infoPtr, WPARAM wParam)
1465 BOOL bTemp = (infoPtr->nNotifyFormat == NFR_UNICODE);
1467 infoPtr->nNotifyFormat = ((BOOL)wParam ? NFR_UNICODE : NFR_ANSI);
1474 HEADER_Create (HWND hwnd, const CREATESTRUCTW *lpcs)
1476 HEADER_INFO *infoPtr;
1481 infoPtr = Alloc (sizeof(HEADER_INFO));
1482 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1484 infoPtr->hwndSelf = hwnd;
1485 infoPtr->hwndNotify = lpcs->hwndParent;
1486 infoPtr->uNumItem = 0;
1490 infoPtr->bRectsValid = FALSE;
1491 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1492 infoPtr->hcurDivider = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDER));
1493 infoPtr->hcurDivopen = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDEROPEN));
1494 infoPtr->bPressed = FALSE;
1495 infoPtr->bTracking = FALSE;
1496 infoPtr->dwStyle = lpcs->style;
1497 infoPtr->iMoveItem = 0;
1499 infoPtr->iHotItem = -1;
1500 infoPtr->iHotDivider = -1;
1501 infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
1502 infoPtr->nNotifyFormat =
1503 SendMessageW (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1506 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1507 GetTextMetricsW (hdc, &tm);
1508 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1509 SelectObject (hdc, hOldFont);
1512 OpenThemeData(hwnd, themeClass);
1519 HEADER_Destroy (HEADER_INFO *infoPtr)
1521 HTHEME theme = GetWindowTheme(infoPtr->hwndSelf);
1522 CloseThemeData(theme);
1527 HEADER_NCDestroy (HEADER_INFO *infoPtr)
1529 HEADER_ITEM *lpItem;
1532 if (infoPtr->items) {
1533 lpItem = infoPtr->items;
1534 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1535 Free(lpItem->pszText);
1537 Free (infoPtr->items);
1540 Free(infoPtr->order);
1542 SetWindowLongPtrW (infoPtr->hwndSelf, 0, 0);
1549 static inline LRESULT
1550 HEADER_GetFont (const HEADER_INFO *infoPtr)
1552 return (LRESULT)infoPtr->hFont;
1557 HEADER_IsDragDistance(const HEADER_INFO *infoPtr, const POINT *pt)
1559 /* Windows allows for a mouse movement before starting the drag. We use the
1560 * SM_CXDOUBLECLICK/SM_CYDOUBLECLICK as that distance.
1562 return (abs(infoPtr->ptLButtonDown.x - pt->x)>GetSystemMetrics(SM_CXDOUBLECLK) ||
1563 abs(infoPtr->ptLButtonDown.y - pt->y)>GetSystemMetrics(SM_CYDOUBLECLK));
1567 HEADER_LButtonDblClk (const HEADER_INFO *infoPtr, INT x, INT y)
1575 HEADER_InternalHitTest (infoPtr, &pt, &flags, &nItem);
1577 if ((infoPtr->dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1578 HEADER_SendNotifyWithHDItemT(infoPtr, HDN_ITEMDBLCLICKW, nItem, NULL);
1579 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1580 HEADER_SendNotifyWithHDItemT(infoPtr, HDN_DIVIDERDBLCLICKW, nItem, NULL);
1587 HEADER_LButtonDown (HEADER_INFO *infoPtr, INT x, INT y)
1596 HEADER_InternalHitTest (infoPtr, &pt, &flags, &nItem);
1598 if ((infoPtr->dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1599 SetCapture (infoPtr->hwndSelf);
1600 infoPtr->bCaptured = TRUE;
1601 infoPtr->bPressed = TRUE;
1602 infoPtr->bDragging = FALSE;
1603 infoPtr->iMoveItem = nItem;
1604 infoPtr->ptLButtonDown = pt;
1606 infoPtr->items[nItem].bDown = TRUE;
1608 /* Send WM_CUSTOMDRAW */
1609 hdc = GetDC (infoPtr->hwndSelf);
1610 HEADER_RefreshItem (infoPtr, nItem);
1611 ReleaseDC (infoPtr->hwndSelf, hdc);
1613 TRACE("Pressed item %d!\n", nItem);
1615 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1616 INT iCurrWidth = infoPtr->items[nItem].cxy;
1617 if (!HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_BEGINTRACKW, nItem, HDI_WIDTH, iCurrWidth))
1619 SetCapture (infoPtr->hwndSelf);
1620 infoPtr->bCaptured = TRUE;
1621 infoPtr->bTracking = TRUE;
1622 infoPtr->iMoveItem = nItem;
1623 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1625 if (!(infoPtr->dwStyle & HDS_FULLDRAG)) {
1626 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1627 hdc = GetDC (infoPtr->hwndSelf);
1628 HEADER_DrawTrackLine (infoPtr, hdc, infoPtr->xOldTrack);
1629 ReleaseDC (infoPtr->hwndSelf, hdc);
1632 TRACE("Begin tracking item %d!\n", nItem);
1641 HEADER_LButtonUp (HEADER_INFO *infoPtr, INT x, INT y)
1650 HEADER_InternalHitTest (infoPtr, &pt, &flags, &nItem);
1652 if (infoPtr->bPressed) {
1654 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1656 if (infoPtr->bDragging)
1658 HEADER_ITEM *lpItem = &infoPtr->items[infoPtr->iMoveItem];
1661 ImageList_DragShowNolock(FALSE);
1662 ImageList_EndDrag();
1664 if (infoPtr->iHotDivider == -1)
1666 else if (infoPtr->iHotDivider == infoPtr->uNumItem)
1667 iNewOrder = infoPtr->uNumItem-1;
1670 iNewOrder = HEADER_IndexToOrder(infoPtr, infoPtr->iHotDivider);
1671 if (iNewOrder > lpItem->iOrder)
1675 if (iNewOrder != -1 &&
1676 !HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_ENDDRAG, infoPtr->iMoveItem, HDI_ORDER, iNewOrder))
1678 HEADER_ChangeItemOrder(infoPtr, infoPtr->iMoveItem, iNewOrder);
1679 infoPtr->bRectsValid = FALSE;
1680 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1683 InvalidateRect(infoPtr->hwndSelf, &infoPtr->items[infoPtr->iMoveItem].rect, FALSE);
1685 infoPtr->bDragging = FALSE;
1686 HEADER_SetHotDivider(infoPtr, FALSE, -1);
1690 hdc = GetDC (infoPtr->hwndSelf);
1691 HEADER_RefreshItem (infoPtr, infoPtr->iMoveItem);
1692 ReleaseDC (infoPtr->hwndSelf, hdc);
1694 if (!(infoPtr->dwStyle & HDS_DRAGDROP) || !HEADER_IsDragDistance(infoPtr, &pt))
1695 HEADER_SendNotifyWithHDItemT(infoPtr, HDN_ITEMCLICKW, infoPtr->iMoveItem, NULL);
1698 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1699 infoPtr->bPressed = FALSE;
1701 else if (infoPtr->bTracking) {
1702 INT iNewWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1705 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1706 infoPtr->bTracking = FALSE;
1708 HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_ENDTRACKW, infoPtr->iMoveItem, HDI_WIDTH, iNewWidth);
1710 if (!(infoPtr->dwStyle & HDS_FULLDRAG)) {
1711 hdc = GetDC (infoPtr->hwndSelf);
1712 HEADER_DrawTrackLine (infoPtr, hdc, infoPtr->xOldTrack);
1713 ReleaseDC (infoPtr->hwndSelf, hdc);
1716 if (!HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH, iNewWidth))
1718 infoPtr->items[infoPtr->iMoveItem].cxy = iNewWidth;
1719 HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH, iNewWidth);
1722 HEADER_SetItemBounds (infoPtr);
1723 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1726 if (infoPtr->bCaptured) {
1727 infoPtr->bCaptured = FALSE;
1729 HEADER_SendSimpleNotify (infoPtr, NM_RELEASEDCAPTURE);
1737 HEADER_NotifyFormat (HEADER_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1742 return infoPtr->nNotifyFormat;
1745 infoPtr->nNotifyFormat =
1746 SendMessageW ((HWND)wParam, WM_NOTIFYFORMAT,
1747 (WPARAM)infoPtr->hwndSelf, NF_QUERY);
1748 return infoPtr->nNotifyFormat;
1755 HEADER_MouseLeave (HEADER_INFO *infoPtr)
1757 /* Reset hot-tracked item when mouse leaves control. */
1758 INT oldHotItem = infoPtr->iHotItem;
1759 HDC hdc = GetDC (infoPtr->hwndSelf);
1761 infoPtr->iHotItem = -1;
1762 if (oldHotItem != -1) HEADER_RefreshItem (infoPtr, oldHotItem);
1763 ReleaseDC (infoPtr->hwndSelf, hdc);
1770 HEADER_MouseMove (HEADER_INFO *infoPtr, LPARAM lParam)
1776 /* With theming, hottracking is always enabled */
1777 BOOL hotTrackEnabled =
1778 ((infoPtr->dwStyle & HDS_BUTTONS) && (infoPtr->dwStyle & HDS_HOTTRACK))
1779 || (GetWindowTheme (infoPtr->hwndSelf) != NULL);
1780 INT oldHotItem = infoPtr->iHotItem;
1782 pt.x = (INT)(SHORT)LOWORD(lParam);
1783 pt.y = (INT)(SHORT)HIWORD(lParam);
1784 HEADER_InternalHitTest (infoPtr, &pt, &flags, &nItem);
1786 if (hotTrackEnabled) {
1787 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1788 infoPtr->iHotItem = nItem;
1790 infoPtr->iHotItem = -1;
1793 if (infoPtr->bCaptured) {
1794 /* check if we should drag the header */
1795 if (infoPtr->bPressed && !infoPtr->bDragging && (infoPtr->dwStyle & HDS_DRAGDROP)
1796 && HEADER_IsDragDistance(infoPtr, &pt))
1798 if (!HEADER_SendNotifyWithHDItemT(infoPtr, HDN_BEGINDRAG, infoPtr->iMoveItem, NULL))
1800 HIMAGELIST hDragItem = (HIMAGELIST)HEADER_CreateDragImage(infoPtr, infoPtr->iMoveItem);
1801 if (hDragItem != NULL)
1803 HEADER_ITEM *lpItem = &infoPtr->items[infoPtr->iMoveItem];
1804 TRACE("Starting item drag\n");
1805 ImageList_BeginDrag(hDragItem, 0, pt.x - lpItem->rect.left, 0);
1806 ImageList_DragShowNolock(TRUE);
1807 ImageList_Destroy(hDragItem);
1808 infoPtr->bDragging = TRUE;
1813 if (infoPtr->bDragging)
1818 ClientToScreen(infoPtr->hwndSelf, &drag);
1819 ImageList_DragMove(drag.x, drag.y);
1820 HEADER_SetHotDivider(infoPtr, TRUE, lParam);
1823 if (infoPtr->bPressed && !infoPtr->bDragging) {
1824 BOOL oldState = infoPtr->items[infoPtr->iMoveItem].bDown;
1825 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1826 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1828 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1829 if (oldState != infoPtr->items[infoPtr->iMoveItem].bDown) {
1830 hdc = GetDC (infoPtr->hwndSelf);
1831 HEADER_RefreshItem (infoPtr, infoPtr->iMoveItem);
1832 ReleaseDC (infoPtr->hwndSelf, hdc);
1835 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1837 else if (infoPtr->bTracking) {
1838 if (infoPtr->dwStyle & HDS_FULLDRAG) {
1839 HEADER_ITEM *lpItem = &infoPtr->items[infoPtr->iMoveItem];
1840 nWidth = pt.x - lpItem->rect.left + infoPtr->xTrackOffset;
1841 if (!HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH, nWidth))
1843 INT nOldWidth = lpItem->rect.right - lpItem->rect.left;
1847 if (nWidth < 0) nWidth = 0;
1848 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1849 HEADER_SetItemBounds(infoPtr);
1851 GetClientRect(infoPtr->hwndSelf, &rcClient);
1852 rcScroll = rcClient;
1853 rcScroll.left = lpItem->rect.left + nOldWidth;
1854 ScrollWindowEx(infoPtr->hwndSelf, nWidth - nOldWidth, 0, &rcScroll, &rcClient, NULL, NULL, 0);
1855 InvalidateRect(infoPtr->hwndSelf, &lpItem->rect, FALSE);
1856 UpdateWindow(infoPtr->hwndSelf);
1858 HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH, nWidth);
1863 hdc = GetDC (infoPtr->hwndSelf);
1864 HEADER_DrawTrackLine (infoPtr, hdc, infoPtr->xOldTrack);
1865 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1866 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1867 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1868 HEADER_DrawTrackLine (infoPtr, hdc, infoPtr->xOldTrack);
1869 ReleaseDC (infoPtr->hwndSelf, hdc);
1870 iTrackWidth = infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1871 /* FIXME: should stop tracking if HDN_TRACK returns TRUE */
1872 HEADER_SendNotifyWithIntFieldT(infoPtr, HDN_TRACKW, infoPtr->iMoveItem, HDI_WIDTH, iTrackWidth);
1875 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1879 if (hotTrackEnabled) {
1880 TRACKMOUSEEVENT tme;
1881 if (oldHotItem != infoPtr->iHotItem && !infoPtr->bDragging) {
1882 hdc = GetDC (infoPtr->hwndSelf);
1883 if (oldHotItem != -1) HEADER_RefreshItem (infoPtr, oldHotItem);
1884 if (infoPtr->iHotItem != -1) HEADER_RefreshItem (infoPtr, infoPtr->iHotItem);
1885 ReleaseDC (infoPtr->hwndSelf, hdc);
1887 tme.cbSize = sizeof( tme );
1888 tme.dwFlags = TME_LEAVE;
1889 tme.hwndTrack = infoPtr->hwndSelf;
1890 TrackMouseEvent( &tme );
1898 HEADER_Paint (HEADER_INFO *infoPtr, HDC hdcParam)
1903 hdc = hdcParam==0 ? BeginPaint (infoPtr->hwndSelf, &ps) : hdcParam;
1904 HEADER_Refresh (infoPtr, hdc);
1906 EndPaint (infoPtr->hwndSelf, &ps);
1912 HEADER_RButtonUp (HEADER_INFO *infoPtr, INT x, INT y)
1920 /* Send a Notify message */
1921 bRet = HEADER_SendSimpleNotify (infoPtr, NM_RCLICK);
1923 /* Change to screen coordinate for WM_CONTEXTMENU */
1924 ClientToScreen(infoPtr->hwndSelf, &pt);
1926 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1927 SendMessageW( infoPtr->hwndSelf, WM_CONTEXTMENU, (WPARAM) infoPtr->hwndSelf, MAKELPARAM(pt.x, pt.y));
1934 HEADER_SetCursor (HEADER_INFO *infoPtr, LPARAM lParam)
1940 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1943 ScreenToClient (infoPtr->hwndSelf, &pt);
1945 HEADER_InternalHitTest (infoPtr, &pt, &flags, &nItem);
1947 if (flags == HHT_ONDIVIDER)
1948 SetCursor (infoPtr->hcurDivider);
1949 else if (flags == HHT_ONDIVOPEN)
1950 SetCursor (infoPtr->hcurDivopen);
1952 SetCursor (infoPtr->hcurArrow);
1959 HEADER_SetFont (HEADER_INFO *infoPtr, HFONT hFont, WORD Redraw)
1965 infoPtr->hFont = hFont;
1968 hOldFont = SelectObject (hdc, infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT));
1969 GetTextMetricsW (hdc, &tm);
1970 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1971 SelectObject (hdc, hOldFont);
1974 infoPtr->bRectsValid = FALSE;
1977 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
1983 static LRESULT HEADER_SetRedraw(HEADER_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
1985 /* ignoring the InvalidateRect calls is handled by user32. But some apps expect
1986 * that we invalidate the header and this has to be done manually */
1989 ret = DefWindowProcW(infoPtr->hwndSelf, WM_SETREDRAW, wParam, lParam);
1991 InvalidateRect(infoPtr->hwndSelf, NULL, TRUE);
1995 static INT HEADER_StyleChanged(HEADER_INFO *infoPtr, WPARAM wStyleType,
1996 const STYLESTRUCT *lpss)
1998 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1999 wStyleType, lpss->styleOld, lpss->styleNew);
2001 if (wStyleType != GWL_STYLE) return 0;
2003 infoPtr->dwStyle = lpss->styleNew;
2008 /* Update the theme handle after a theme change */
2009 static LRESULT HEADER_ThemeChanged(const HEADER_INFO *infoPtr)
2011 HTHEME theme = GetWindowTheme(infoPtr->hwndSelf);
2012 CloseThemeData(theme);
2013 OpenThemeData(infoPtr->hwndSelf, themeClass);
2014 InvalidateRect(infoPtr->hwndSelf, NULL, FALSE);
2019 static LRESULT WINAPI
2020 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
2022 HEADER_INFO *infoPtr = (HEADER_INFO *)GetWindowLongPtrW(hwnd, 0);
2024 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, msg, wParam, lParam);
2025 if (!infoPtr && (msg != WM_CREATE))
2026 return DefWindowProcW (hwnd, msg, wParam, lParam);
2028 /* case HDM_CLEARFILTER: */
2030 case HDM_CREATEDRAGIMAGE:
2031 return HEADER_CreateDragImage (infoPtr, (INT)wParam);
2033 case HDM_DELETEITEM:
2034 return HEADER_DeleteItem (infoPtr, (INT)wParam);
2036 /* case HDM_EDITFILTER: */
2038 case HDM_GETBITMAPMARGIN:
2039 return HEADER_GetBitmapMargin(infoPtr);
2041 case HDM_GETIMAGELIST:
2042 return HEADER_GetImageList (infoPtr);
2046 return HEADER_GetItemT (infoPtr, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_GETITEMW);
2048 case HDM_GETITEMCOUNT:
2049 return HEADER_GetItemCount (infoPtr);
2051 case HDM_GETITEMRECT:
2052 return HEADER_GetItemRect (infoPtr, (INT)wParam, (LPRECT)lParam);
2054 case HDM_GETORDERARRAY:
2055 return HEADER_GetOrderArray(infoPtr, (INT)wParam, (LPINT)lParam);
2057 case HDM_GETUNICODEFORMAT:
2058 return HEADER_GetUnicodeFormat (infoPtr);
2061 return HEADER_HitTest (infoPtr, (LPHDHITTESTINFO)lParam);
2063 case HDM_INSERTITEMA:
2064 case HDM_INSERTITEMW:
2065 return HEADER_InsertItemT (infoPtr, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_INSERTITEMW);
2068 return HEADER_Layout (infoPtr, (LPHDLAYOUT)lParam);
2070 case HDM_ORDERTOINDEX:
2071 return HEADER_OrderToIndex(infoPtr, (INT)wParam);
2073 case HDM_SETBITMAPMARGIN:
2074 return HEADER_SetBitmapMargin(infoPtr, (INT)wParam);
2076 /* case HDM_SETFILTERCHANGETIMEOUT: */
2078 case HDM_SETHOTDIVIDER:
2079 return HEADER_SetHotDivider(infoPtr, wParam, lParam);
2081 case HDM_SETIMAGELIST:
2082 return HEADER_SetImageList (infoPtr, (HIMAGELIST)lParam);
2086 return HEADER_SetItemT (infoPtr, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_SETITEMW);
2088 case HDM_SETORDERARRAY:
2089 return HEADER_SetOrderArray(infoPtr, (INT)wParam, (LPINT)lParam);
2091 case HDM_SETUNICODEFORMAT:
2092 return HEADER_SetUnicodeFormat (infoPtr, wParam);
2095 return HEADER_Create (hwnd, (LPCREATESTRUCTW)lParam);
2098 return HEADER_Destroy (infoPtr);
2101 return HEADER_NCDestroy (infoPtr);
2107 return DLGC_WANTTAB | DLGC_WANTARROWS;
2110 return HEADER_GetFont (infoPtr);
2112 case WM_LBUTTONDBLCLK:
2113 return HEADER_LButtonDblClk (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2115 case WM_LBUTTONDOWN:
2116 return HEADER_LButtonDown (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2119 return HEADER_LButtonUp (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2122 return HEADER_MouseLeave (infoPtr);
2125 return HEADER_MouseMove (infoPtr, lParam);
2127 case WM_NOTIFYFORMAT:
2128 return HEADER_NotifyFormat (infoPtr, wParam, lParam);
2131 return HEADER_Size (infoPtr);
2133 case WM_THEMECHANGED:
2134 return HEADER_ThemeChanged (infoPtr);
2136 case WM_PRINTCLIENT:
2138 return HEADER_Paint (infoPtr, (HDC)wParam);
2141 return HEADER_RButtonUp (infoPtr, (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam));
2144 return HEADER_SetCursor (infoPtr, lParam);
2147 return HEADER_SetFont (infoPtr, (HFONT)wParam, (WORD)lParam);
2150 return HEADER_SetRedraw(infoPtr, wParam, lParam);
2152 case WM_STYLECHANGED:
2153 return HEADER_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
2155 case WM_SYSCOLORCHANGE:
2156 COMCTL32_RefreshSysColors();
2160 if ((msg >= WM_USER) && (msg < WM_APP) && !COMCTL32_IsReflectedMessage(msg))
2161 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
2162 msg, wParam, lParam );
2163 return DefWindowProcW(hwnd, msg, wParam, lParam);
2169 HEADER_Register (void)
2173 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2174 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
2175 wndClass.lpfnWndProc = HEADER_WindowProc;
2176 wndClass.cbClsExtra = 0;
2177 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
2178 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2179 wndClass.lpszClassName = WC_HEADERW;
2181 RegisterClassW (&wndClass);
2186 HEADER_Unregister (void)
2188 UnregisterClassW (WC_HEADERW, NULL);