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"
42 #include "imagelist.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(header);
57 INT iOrder; /* see documentation of HD_ITEM */
59 BOOL bDown; /* is item pressed? (used for drawing) */
60 RECT rect; /* bounding rectangle of the item */
61 DWORD callbackMask; /* HDI_* flags for items that are callback */
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 INT iMoveItem; /* index of tracked item. (Tracking mode) */
81 INT xTrackOffset; /* distance between the right side of the tracked item and the cursor */
82 INT xOldTrack; /* track offset (see above) after the last WM_MOUSEMOVE */
83 INT iHotItem; /* index of hot item (cursor is over this item) */
84 INT iHotDivider; /* index of the hot divider (used while dragging an item or by HDM_SETHOTDIVIDER) */
85 INT iMargin; /* width of the margin that surrounds a bitmap */
87 HIMAGELIST himl; /* handle to an image list (may be 0) */
88 HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */
89 INT *order; /* array of item IDs indexed by order */
90 BOOL bRectsValid; /* validity flag for bounding rectangles */
95 #define DIVIDER_WIDTH 10
96 #define HOT_DIVIDER_WIDTH 2
97 #define MAX_HEADER_TEXT_LEN 260
98 #define HDN_UNICODE_OFFSET 20
99 #define HDN_FIRST_UNICODE (HDN_FIRST-HDN_UNICODE_OFFSET)
101 #define HDI_SUPPORTED_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP|HDI_IMAGE|HDI_ORDER)
102 #define HDI_UNSUPPORTED_FIELDS (HDI_FILTER)
103 #define HDI_UNKNOWN_FIELDS (~(HDI_SUPPORTED_FIELDS|HDI_UNSUPPORTED_FIELDS|HDI_DI_SETITEM))
104 #define HDI_COMCTL32_4_0_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP)
106 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongPtrW(hwnd,0))
108 static BOOL HEADER_PrepareCallbackItems(HWND hwnd, INT iItem, INT reqMask);
109 static void HEADER_FreeCallbackItems(HEADER_ITEM *lpItem);
110 static LRESULT HEADER_SendNotify(HWND hwnd, UINT code, NMHDR *hdr);
111 static LRESULT HEADER_SendCtrlCustomDraw(HWND hwnd, 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 (HWND hwnd, INT iItem)
168 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
169 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
170 return lpItem->iOrder;
175 HEADER_OrderToIndex(HWND hwnd, WPARAM wParam)
177 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
178 INT iorder = (INT)wParam;
180 if ((iorder <0) || iorder >= infoPtr->uNumItem)
182 return infoPtr->order[iorder];
186 HEADER_ChangeItemOrder(const HEADER_INFO *infoPtr, INT iItem, INT iNewOrder)
188 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
191 TRACE("%d: %d->%d\n", iItem, lpItem->iOrder, iNewOrder);
192 if (lpItem->iOrder < iNewOrder)
194 memmove(&infoPtr->order[lpItem->iOrder],
195 &infoPtr->order[lpItem->iOrder + 1],
196 (iNewOrder - lpItem->iOrder) * sizeof(INT));
198 if (iNewOrder < lpItem->iOrder)
200 memmove(&infoPtr->order[iNewOrder + 1],
201 &infoPtr->order[iNewOrder],
202 (lpItem->iOrder - iNewOrder) * sizeof(INT));
204 infoPtr->order[iNewOrder] = iItem;
205 nMin = min(lpItem->iOrder, iNewOrder);
206 nMax = max(lpItem->iOrder, iNewOrder);
207 for (i = nMin; i <= nMax; i++)
208 infoPtr->items[infoPtr->order[i]].iOrder = i;
211 /* Note: if iItem is the last item then this function returns infoPtr->uNumItem */
213 HEADER_NextItem(HWND hwnd, INT iItem)
215 return HEADER_OrderToIndex(hwnd, HEADER_IndexToOrder(hwnd, iItem)+1);
219 HEADER_PrevItem(HWND hwnd, INT iItem)
221 return HEADER_OrderToIndex(hwnd, HEADER_IndexToOrder(hwnd, iItem)-1);
225 HEADER_SetItemBounds (HWND hwnd)
227 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
233 infoPtr->bRectsValid = TRUE;
235 if (infoPtr->uNumItem == 0)
238 GetClientRect (hwnd, &rect);
241 for (i = 0; i < infoPtr->uNumItem; i++) {
242 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
243 phdi->rect.top = rect.top;
244 phdi->rect.bottom = rect.bottom;
246 phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
247 x = phdi->rect.right;
252 HEADER_Size (HWND hwnd)
254 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
256 infoPtr->bRectsValid = FALSE;
261 static void HEADER_GetHotDividerRect(HWND hwnd, 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(hwnd, 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(hwnd, &clientRect);
288 r->right = r->left + HOT_DIVIDER_WIDTH/2;
294 HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack, LRESULT lCDFlags)
296 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
297 HEADER_ITEM *phdi = &infoPtr->items[iItem];
300 HTHEME theme = GetWindowTheme (hwnd);
303 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, (infoPtr->nNotifyFormat == NFR_UNICODE));
306 if (r.right - r.left == 0)
307 return phdi->rect.right;
309 /* Set the colors before sending NM_CUSTOMDRAW so that it can change them */
310 SetTextColor(hdc, (bHotTrack && !theme) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
311 SetBkColor(hdc, GetSysColor(COLOR_3DFACE));
313 if (lCDFlags & CDRF_NOTIFYITEMDRAW && !(phdi->fmt & HDF_OWNERDRAW))
315 LRESULT lCDItemFlags;
317 nmcd.dwDrawStage = CDDS_PREPAINT | CDDS_ITEM;
319 nmcd.dwItemSpec = iItem;
321 nmcd.uItemState = phdi->bDown ? CDIS_SELECTED : 0;
322 nmcd.lItemlParam = phdi->lParam;
324 lCDItemFlags = HEADER_SendNotify(hwnd, NM_CUSTOMDRAW, (NMHDR *)&nmcd);
325 if (lCDItemFlags & CDRF_SKIPDEFAULT)
326 return phdi->rect.right;
330 int state = (phdi->bDown) ? HIS_PRESSED :
331 (bHotTrack ? HIS_HOT : HIS_NORMAL);
332 DrawThemeBackground (theme, hdc, HP_HEADERITEM, state,
334 GetThemeBackgroundContentRect (theme, hdc, HP_HEADERITEM, state,
340 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) {
342 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
343 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
346 DrawEdge (hdc, &r, EDGE_RAISED,
347 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
350 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
352 hbr = CreateSolidBrush(GetBkColor(hdc));
353 FillRect(hdc, &r, hbr);
361 if (phdi->fmt & HDF_OWNERDRAW) {
364 dis.CtlType = ODT_HEADER;
365 dis.CtlID = GetWindowLongPtrW (hwnd, GWLP_ID);
367 dis.itemAction = ODA_DRAWENTIRE;
368 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
371 dis.rcItem = phdi->rect;
372 dis.itemData = phdi->lParam;
373 oldBkMode = SetBkMode(hdc, TRANSPARENT);
374 SendMessageW (infoPtr->hwndNotify, WM_DRAWITEM,
375 (WPARAM)dis.CtlID, (LPARAM)&dis);
376 if (oldBkMode != TRANSPARENT)
377 SetBkMode(hdc, oldBkMode);
380 UINT rw, rh, /* width and height of r */
381 *x = NULL, *w = NULL; /* x and width of the pic (bmp or img) which is part of cnt */
382 /* cnt,txt,img,bmp */
387 HEADER_PrepareCallbackItems(hwnd, iItem, HDI_TEXT|HDI_IMAGE);
388 cw = tw = iw = bw = 0;
389 rw = r.right - r.left;
390 rh = r.bottom - r.top;
392 if (phdi->fmt & HDF_STRING) {
395 SetRectEmpty(&textRect);
396 DrawTextW (hdc, phdi->pszText, -1,
397 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
398 cw = textRect.right - textRect.left + 2 * infoPtr->iMargin;
401 if ((phdi->fmt & HDF_IMAGE) && (infoPtr->himl)) {
402 iw = infoPtr->himl->cx + 2 * infoPtr->iMargin;
407 if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
408 GetObjectW (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
409 bw = bmp.bmWidth + 2 * infoPtr->iMargin;
419 /* align cx using the unclipped cw */
420 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_LEFT)
422 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
423 cx = r.left + rw / 2 - cw / 2;
430 if (cx + cw > r.right)
433 tx = cx + infoPtr->iMargin;
434 /* since cw might have changed we have to recalculate tw */
435 tw = cw - infoPtr->iMargin * 2;
439 if (phdi->fmt & HDF_BITMAP_ON_RIGHT) {
440 /* put pic behind text */
441 *x = cx + tw + infoPtr->iMargin * 3;
443 *x = cx + infoPtr->iMargin;
444 /* move text behind pic */
450 /* since we're done with the layout we can
451 now calculate the position of bmp which
452 has no influence on alignment and layout
454 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
455 bx = cx - bw + infoPtr->iMargin;
457 bx = cx + cw + infoPtr->iMargin;
461 HDC hClipDC = GetDC(hwnd);
462 HRGN hClipRgn = CreateRectRgn(r.left, r.top, r.right, r.bottom);
463 SelectClipRgn(hClipDC, hClipRgn);
466 HDC hdcBitmap = CreateCompatibleDC (hClipDC);
467 SelectObject (hdcBitmap, phdi->hbm);
468 BitBlt (hClipDC, bx, r.top + ((INT)rh - bmp.bmHeight) / 2,
469 bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
470 DeleteDC (hdcBitmap);
474 ImageList_DrawEx (infoPtr->himl, phdi->iImage, hClipDC,
475 ix, r.top + ((INT)rh - infoPtr->himl->cy) / 2,
476 infoPtr->himl->cx, infoPtr->himl->cy, CLR_DEFAULT, CLR_DEFAULT, 0);
479 DeleteObject(hClipRgn);
480 ReleaseDC(hwnd, hClipDC);
483 if (((phdi->fmt & HDF_STRING)
484 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
485 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
486 && (phdi->pszText)) {
487 oldBkMode = SetBkMode(hdc, TRANSPARENT);
490 DrawTextW (hdc, phdi->pszText, -1,
491 &r, DT_LEFT|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
492 if (oldBkMode != TRANSPARENT)
493 SetBkMode(hdc, oldBkMode);
495 HEADER_FreeCallbackItems(phdi);
498 return phdi->rect.right;
502 HEADER_DrawHotDivider(HWND hwnd, HDC hdc)
504 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
508 HEADER_GetHotDividerRect(hwnd, infoPtr, &r);
509 brush = CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT));
510 FillRect(hdc, &r, brush);
515 HEADER_Refresh (HWND hwnd, HDC hdc)
517 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
518 HFONT hFont, hOldFont;
524 HTHEME theme = GetWindowTheme (hwnd);
526 if (!infoPtr->bRectsValid)
527 HEADER_SetItemBounds(hwnd);
529 /* get rect for the bar, adjusted for the border */
530 GetClientRect (hwnd, &rect);
531 lCDFlags = HEADER_SendCtrlCustomDraw(hwnd, 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(hwnd,i);
548 if (RectVisible(hdc, &infoPtr->items[idx].rect))
549 HEADER_DrawItem(hwnd, 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);
560 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS)
561 DrawEdge (hdc, &rcRest, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT|BF_MIDDLE);
563 DrawEdge (hdc, &rcRest, EDGE_ETCHED, BF_BOTTOM|BF_MIDDLE);
567 if (infoPtr->iHotDivider != -1)
568 HEADER_DrawHotDivider(hwnd, hdc);
570 if (infoPtr->bDragging)
571 ImageList_DragShowNolock(TRUE);
572 SelectObject (hdc, hOldFont);
574 if (lCDFlags & CDRF_NOTIFYPOSTPAINT)
575 HEADER_SendCtrlCustomDraw(hwnd, CDDS_POSTPAINT, hdc, &rect);
580 HEADER_RefreshItem (HWND hwnd, INT iItem)
582 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
584 if (!infoPtr->bRectsValid)
585 HEADER_SetItemBounds(hwnd);
587 InvalidateRect(hwnd, &infoPtr->items[iItem].rect, FALSE);
592 HEADER_InternalHitTest (HWND hwnd, const POINT *lpPt, UINT *pFlags, INT *pItem)
594 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
600 GetClientRect (hwnd, &rect);
604 if (PtInRect (&rect, *lpPt))
606 if (infoPtr->uNumItem == 0) {
607 *pFlags |= HHT_NOWHERE;
613 /* somewhere inside */
614 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
615 rect = infoPtr->items[iCount].rect;
616 width = rect.right - rect.left;
621 if (PtInRect (&rect, *lpPt)) {
622 if (width <= 2 * DIVIDER_WIDTH) {
623 *pFlags |= HHT_ONHEADER;
625 TRACE("ON HEADER %d\n", iCount);
628 if (HEADER_IndexToOrder(hwnd, iCount) > 0) {
630 rcTest.right = rcTest.left + DIVIDER_WIDTH;
631 if (PtInRect (&rcTest, *lpPt)) {
633 *pFlags |= HHT_ONDIVOPEN;
634 *pItem = HEADER_PrevItem(hwnd, iCount);
635 TRACE("ON DIVOPEN %d\n", *pItem);
639 *pFlags |= HHT_ONDIVIDER;
640 *pItem = HEADER_PrevItem(hwnd, iCount);
641 TRACE("ON DIVIDER %d\n", *pItem);
647 rcTest.left = rcTest.right - DIVIDER_WIDTH;
648 if (PtInRect (&rcTest, *lpPt)) {
649 *pFlags |= HHT_ONDIVIDER;
651 TRACE("ON DIVIDER %d\n", *pItem);
655 *pFlags |= HHT_ONHEADER;
657 TRACE("ON HEADER %d\n", iCount);
662 /* check for last divider part (on nowhere) */
663 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
664 rect.left = rect.right;
665 rect.right += DIVIDER_WIDTH;
666 if (PtInRect (&rect, *lpPt)) {
668 *pFlags |= HHT_ONDIVOPEN;
669 *pItem = infoPtr->uNumItem - 1;
670 TRACE("ON DIVOPEN %d\n", *pItem);
674 *pFlags |= HHT_ONDIVIDER;
675 *pItem = infoPtr->uNumItem-1;
676 TRACE("ON DIVIDER %d\n", *pItem);
681 *pFlags |= HHT_NOWHERE;
688 if (lpPt->x < rect.left) {
690 *pFlags |= HHT_TOLEFT;
692 else if (lpPt->x > rect.right) {
694 *pFlags |= HHT_TORIGHT;
697 if (lpPt->y < rect.top) {
699 *pFlags |= HHT_ABOVE;
701 else if (lpPt->y > rect.bottom) {
703 *pFlags |= HHT_BELOW;
708 TRACE("flags=0x%X\n", *pFlags);
714 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
720 GetClientRect (hwnd, &rect);
722 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
723 oldRop = SetROP2 (hdc, R2_XORPEN);
724 MoveToEx (hdc, x, rect.top, NULL);
725 LineTo (hdc, x, rect.bottom);
726 SetROP2 (hdc, oldRop);
727 SelectObject (hdc, hOldPen);
732 * Convert a HDITEM into the correct format (ANSI/Unicode) to send it in a notify
735 * [I] infoPtr : the header that wants to send the notify
736 * [O] dest : The buffer to store the HDITEM for notify. It may be set to a HDITEMA of HDITEMW
737 * [I] src : The source HDITEM. It may be a HDITEMA or HDITEMW
738 * [I] fSourceUnicode : is src a HDITEMW or HDITEMA
739 * [O] ppvScratch : a pointer to a scratch buffer that needs to be freed after
740 * the HDITEM is no longer in use or NULL if none was needed
742 * NOTE: We depend on HDITEMA and HDITEMW having the same structure
744 static void HEADER_CopyHDItemForNotify(const HEADER_INFO *infoPtr, HDITEMW *dest,
745 const HDITEMW *src, BOOL fSourceUnicode, LPVOID *ppvScratch)
750 if (src->mask & HDI_TEXT && src->pszText != LPSTR_TEXTCALLBACKW) /* covers TEXTCALLBACKA as well */
752 if (fSourceUnicode && infoPtr->nNotifyFormat != NFR_UNICODE)
754 dest->pszText = NULL;
755 Str_SetPtrWtoA((LPSTR *)&dest->pszText, src->pszText);
756 *ppvScratch = dest->pszText;
759 if (!fSourceUnicode && infoPtr->nNotifyFormat == NFR_UNICODE)
761 dest->pszText = NULL;
762 Str_SetPtrAtoW(&dest->pszText, (LPSTR)src->pszText);
763 *ppvScratch = dest->pszText;
768 static UINT HEADER_NotifyCodeWtoA(UINT code)
770 /* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
771 if (code >= HDN_LAST && code <= HDN_FIRST_UNICODE)
772 return code + HDN_UNICODE_OFFSET;
778 HEADER_SendNotify(HWND hwnd, UINT code, NMHDR *nmhdr)
780 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
782 nmhdr->hwndFrom = hwnd;
783 nmhdr->idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
786 return SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
787 nmhdr->idFrom, (LPARAM)nmhdr);
791 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
794 return (BOOL)HEADER_SendNotify(hwnd, code, &nmhdr);
798 HEADER_SendCtrlCustomDraw(HWND hwnd, DWORD dwDrawStage, HDC hdc, const RECT *rect)
801 nm.dwDrawStage = dwDrawStage;
808 return HEADER_SendNotify(hwnd, NM_CUSTOMDRAW, (NMHDR *)&nm);
812 HEADER_SendNotifyWithHDItemT(HWND hwnd, UINT code, INT iItem, HDITEMW *lpItem)
814 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
817 if (infoPtr->nNotifyFormat != NFR_UNICODE)
818 code = HEADER_NotifyCodeWtoA(code);
821 nmhdr.pitem = lpItem;
823 return (BOOL)HEADER_SendNotify(hwnd, code, (NMHDR *)&nmhdr);
827 HEADER_SendNotifyWithIntFieldT(HWND hwnd, UINT code, INT iItem, INT mask, INT iValue)
829 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
832 /* copying only the iValue should be ok but to make the code more robust we copy everything */
833 nmitem.cxy = infoPtr->items[iItem].cxy;
834 nmitem.hbm = infoPtr->items[iItem].hbm;
835 nmitem.pszText = NULL;
836 nmitem.cchTextMax = 0;
837 nmitem.fmt = infoPtr->items[iItem].fmt;
838 nmitem.lParam = infoPtr->items[iItem].lParam;
839 nmitem.iOrder = infoPtr->items[iItem].iOrder;
840 nmitem.iImage = infoPtr->items[iItem].iImage;
849 nmitem.iOrder = iValue;
852 ERR("invalid mask value 0x%x\n", iValue);
855 return HEADER_SendNotifyWithHDItemT(hwnd, code, iItem, &nmitem);
859 * Prepare callback items
860 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
861 * (so we handle the two cases only doing a specific cast for pszText).
862 * Checks if any of the required field are callback. If there are sends a
863 * NMHDISPINFO notify to retrieve these items. The items are stored in the
864 * HEADER_ITEM pszText and iImage fields. They should be freed with
865 * HEADER_FreeCallbackItems.
867 * @param hwnd : hwnd header container handler
868 * @param iItem : the header item id
869 * @param reqMask : required fields. If any of them is callback this function will fetch it
871 * @return TRUE on success, else FALSE
874 HEADER_PrepareCallbackItems(HWND hwnd, INT iItem, INT reqMask)
876 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
877 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
878 DWORD mask = reqMask & lpItem->callbackMask;
879 NMHDDISPINFOW dispInfo;
880 void *pvBuffer = NULL;
884 if (mask&HDI_TEXT && lpItem->pszText != NULL)
886 ERR("(): function called without a call to FreeCallbackItems\n");
887 Free(lpItem->pszText);
888 lpItem->pszText = NULL;
891 memset(&dispInfo, 0, sizeof(NMHDDISPINFOW));
892 dispInfo.hdr.hwndFrom = hwnd;
893 dispInfo.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
894 if (infoPtr->nNotifyFormat == NFR_UNICODE)
896 dispInfo.hdr.code = HDN_GETDISPINFOW;
898 pvBuffer = Alloc(MAX_HEADER_TEXT_LEN * sizeof(WCHAR));
902 dispInfo.hdr.code = HDN_GETDISPINFOA;
904 pvBuffer = Alloc(MAX_HEADER_TEXT_LEN * sizeof(CHAR));
906 dispInfo.pszText = (LPWSTR)pvBuffer;
907 dispInfo.cchTextMax = (pvBuffer!=NULL?MAX_HEADER_TEXT_LEN:0);
908 dispInfo.iItem = iItem;
909 dispInfo.mask = mask;
910 dispInfo.lParam = lpItem->lParam;
912 TRACE("Sending HDN_GETDISPINFO%c\n", infoPtr->nNotifyFormat == NFR_UNICODE?'W':'A');
913 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY, dispInfo.hdr.idFrom, (LPARAM)&dispInfo);
915 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
917 (infoPtr->nNotifyFormat == NFR_UNICODE ? debugstr_w(dispInfo.pszText) : (LPSTR) dispInfo.pszText),
918 (void*) dispInfo.lParam);
920 if (mask & HDI_IMAGE)
921 lpItem->iImage = dispInfo.iImage;
924 if (infoPtr->nNotifyFormat == NFR_UNICODE)
926 lpItem->pszText = (LPWSTR)pvBuffer;
928 /* the user might have used his own buffer */
929 if (dispInfo.pszText != lpItem->pszText)
930 Str_GetPtrW(dispInfo.pszText, lpItem->pszText, MAX_HEADER_TEXT_LEN);
934 Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)dispInfo.pszText);
939 if (dispInfo.mask & HDI_DI_SETITEM)
941 /* make the items permanent */
942 lpItem->callbackMask &= ~dispInfo.mask;
950 * Free the items that might be allocated with HEADER_PrepareCallbackItems
953 * [I] lpItem : the item to free the data
957 HEADER_FreeCallbackItems(HEADER_ITEM *lpItem)
959 if (lpItem->callbackMask&HDI_TEXT)
961 Free(lpItem->pszText);
962 lpItem->pszText = NULL;
965 if (lpItem->callbackMask&HDI_IMAGE)
966 lpItem->iImage = I_IMAGECALLBACK;
970 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
972 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
975 HBITMAP hMemory, hOldBitmap;
983 if (wParam >= infoPtr->uNumItem)
986 if (!infoPtr->bRectsValid)
987 HEADER_SetItemBounds(hwnd);
989 lpItem = &infoPtr->items[wParam];
990 width = lpItem->rect.right - lpItem->rect.left;
991 height = lpItem->rect.bottom - lpItem->rect.top;
993 hDeviceDC = GetDC(NULL);
994 hMemoryDC = CreateCompatibleDC(hDeviceDC);
995 hMemory = CreateCompatibleBitmap(hDeviceDC, width, height);
996 ReleaseDC(NULL, hDeviceDC);
997 hOldBitmap = SelectObject(hMemoryDC, hMemory);
998 SetViewportOrgEx(hMemoryDC, -lpItem->rect.left, -lpItem->rect.top, NULL);
999 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject(SYSTEM_FONT);
1000 SelectObject(hMemoryDC, hFont);
1002 GetClientRect(hwnd, &rc);
1003 lCDFlags = HEADER_SendCtrlCustomDraw(hwnd, CDDS_PREPAINT, hMemoryDC, &rc);
1004 HEADER_DrawItem(hwnd, hMemoryDC, wParam, FALSE, lCDFlags);
1005 if (lCDFlags & CDRF_NOTIFYPOSTPAINT)
1006 HEADER_SendCtrlCustomDraw(hwnd, CDDS_POSTPAINT, hMemoryDC, &rc);
1008 hMemory = SelectObject(hMemoryDC, hOldBitmap);
1009 DeleteDC(hMemoryDC);
1011 if (hMemory == NULL) /* if anything failed */
1014 himl = ImageList_Create(width, height, ILC_COLORDDB, 1, 1);
1015 ImageList_Add(himl, hMemory, NULL);
1016 DeleteObject(hMemory);
1017 return (LRESULT)himl;
1021 HEADER_SetHotDivider(HWND hwnd, WPARAM wParam, LPARAM lParam)
1023 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
1031 pt.x = (INT)(SHORT)LOWORD(lParam);
1033 HEADER_InternalHitTest (hwnd, &pt, &flags, &iDivider);
1035 if (flags & HHT_TOLEFT)
1037 else if (flags & HHT_NOWHERE || flags & HHT_TORIGHT)
1038 iDivider = infoPtr->uNumItem;
1041 HEADER_ITEM *lpItem = &infoPtr->items[iDivider];
1042 if (pt.x > (lpItem->rect.left+lpItem->rect.right)/2)
1043 iDivider = HEADER_NextItem(hwnd, iDivider);
1047 iDivider = (INT)lParam;
1049 /* Note; wParam==FALSE, lParam==-1 is valid and is used to clear the hot divider */
1050 if (iDivider<-1 || iDivider>(int)infoPtr->uNumItem)
1053 if (iDivider != infoPtr->iHotDivider)
1055 if (infoPtr->iHotDivider != -1)
1057 HEADER_GetHotDividerRect(hwnd, infoPtr, &r);
1058 InvalidateRect(hwnd, &r, FALSE);
1060 infoPtr->iHotDivider = iDivider;
1063 HEADER_GetHotDividerRect(hwnd, infoPtr, &r);
1064 InvalidateRect(hwnd, &r, FALSE);
1071 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
1073 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
1074 INT iItem = (INT)wParam;
1078 TRACE("[iItem=%d]\n", iItem);
1080 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
1083 for (i = 0; i < infoPtr->uNumItem; i++)
1084 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
1086 iOrder = infoPtr->items[iItem].iOrder;
1087 Free(infoPtr->items[iItem].pszText);
1089 infoPtr->uNumItem--;
1090 memmove(&infoPtr->items[iItem], &infoPtr->items[iItem + 1],
1091 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
1092 memmove(&infoPtr->order[iOrder], &infoPtr->order[iOrder + 1],
1093 (infoPtr->uNumItem - iOrder) * sizeof(INT));
1094 infoPtr->items = ReAlloc(infoPtr->items, sizeof(HEADER_ITEM) * infoPtr->uNumItem);
1095 infoPtr->order = ReAlloc(infoPtr->order, sizeof(INT) * infoPtr->uNumItem);
1097 /* Correct the orders */
1098 for (i = 0; i < infoPtr->uNumItem; i++)
1100 if (infoPtr->order[i] > iItem)
1101 infoPtr->order[i]--;
1103 infoPtr->items[infoPtr->order[i]].iOrder = i;
1105 for (i = 0; i < infoPtr->uNumItem; i++)
1106 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
1108 HEADER_SetItemBounds (hwnd);
1109 InvalidateRect(hwnd, NULL, FALSE);
1116 HEADER_GetImageList (HWND hwnd)
1118 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1120 return (LRESULT)infoPtr->himl;
1125 HEADER_GetItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
1127 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1128 HEADER_ITEM *lpItem;
1134 TRACE("[nItem=%d]\n", nItem);
1140 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1143 if (mask & HDI_UNKNOWN_FIELDS)
1145 TRACE("mask %x contains unknown fields. Using only comctl32 4.0 fields\n", mask);
1146 mask &= HDI_COMCTL32_4_0_FIELDS;
1149 lpItem = &infoPtr->items[nItem];
1150 HEADER_PrepareCallbackItems(hwnd, nItem, mask);
1152 if (mask & HDI_BITMAP)
1153 phdi->hbm = lpItem->hbm;
1155 if (mask & HDI_FORMAT)
1156 phdi->fmt = lpItem->fmt;
1158 if (mask & HDI_WIDTH)
1159 phdi->cxy = lpItem->cxy;
1161 if (mask & HDI_LPARAM)
1162 phdi->lParam = lpItem->lParam;
1164 if (mask & HDI_IMAGE)
1165 phdi->iImage = lpItem->iImage;
1167 if (mask & HDI_ORDER)
1168 phdi->iOrder = lpItem->iOrder;
1170 if (mask & HDI_TEXT)
1173 Str_GetPtrW (lpItem->pszText, phdi->pszText, phdi->cchTextMax);
1175 Str_GetPtrWtoA (lpItem->pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
1178 HEADER_FreeCallbackItems(lpItem);
1183 static inline LRESULT
1184 HEADER_GetItemCount (HWND hwnd)
1186 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1187 return infoPtr->uNumItem;
1192 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
1194 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1195 INT iItem = (INT)wParam;
1196 LPRECT lpRect = (LPRECT)lParam;
1198 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
1201 lpRect->left = infoPtr->items[iItem].rect.left;
1202 lpRect->right = infoPtr->items[iItem].rect.right;
1203 lpRect->top = infoPtr->items[iItem].rect.top;
1204 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
1211 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
1213 LPINT order = (LPINT) lParam;
1214 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1216 if ((unsigned int)wParam <infoPtr->uNumItem)
1219 memcpy(order, infoPtr->order, infoPtr->uNumItem * sizeof(INT));
1224 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
1227 LPINT order = (LPINT) lParam;
1228 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1229 HEADER_ITEM *lpItem;
1231 if ((unsigned int)wParam <infoPtr->uNumItem)
1233 memcpy(infoPtr->order, order, infoPtr->uNumItem * sizeof(INT));
1234 for (i=0; i<(int)wParam; i++)
1236 lpItem = &infoPtr->items[*order++];
1239 infoPtr->bRectsValid=0;
1240 InvalidateRect(hwnd, NULL, FALSE);
1244 static inline LRESULT
1245 HEADER_GetUnicodeFormat (HWND hwnd)
1247 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1248 return (infoPtr->nNotifyFormat == NFR_UNICODE);
1253 HEADER_HitTest (HWND hwnd, LPARAM lParam)
1255 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
1257 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
1259 if (phti->flags == HHT_NOWHERE)
1267 HEADER_InsertItemT (HWND hwnd, INT nItem, const HDITEMW *phdi, BOOL bUnicode)
1269 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1270 HEADER_ITEM *lpItem;
1275 if ((phdi == NULL) || (nItem < 0) || (phdi->mask == 0))
1278 if (nItem > infoPtr->uNumItem)
1279 nItem = infoPtr->uNumItem;
1281 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
1284 else if (infoPtr->uNumItem < iOrder)
1285 iOrder = infoPtr->uNumItem;
1287 infoPtr->uNumItem++;
1288 infoPtr->items = ReAlloc(infoPtr->items, sizeof(HEADER_ITEM) * infoPtr->uNumItem);
1289 infoPtr->order = ReAlloc(infoPtr->order, sizeof(INT) * infoPtr->uNumItem);
1291 /* make space for the new item */
1292 memmove(&infoPtr->items[nItem + 1], &infoPtr->items[nItem],
1293 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
1294 memmove(&infoPtr->order[iOrder + 1], &infoPtr->order[iOrder],
1295 (infoPtr->uNumItem - iOrder - 1) * sizeof(INT));
1297 /* update the order array */
1298 infoPtr->order[iOrder] = nItem;
1299 for (i = 0; i < infoPtr->uNumItem; i++)
1301 if (i != iOrder && infoPtr->order[i] >= nItem)
1302 infoPtr->order[i]++;
1303 infoPtr->items[infoPtr->order[i]].iOrder = i;
1306 lpItem = &infoPtr->items[nItem];
1307 ZeroMemory(lpItem, sizeof(HEADER_ITEM));
1308 /* cxy, fmt and lParam are copied even if not in the HDITEM mask */
1309 copyMask = phdi->mask | HDI_WIDTH | HDI_FORMAT | HDI_LPARAM;
1310 HEADER_StoreHDItemInHeader(lpItem, copyMask, phdi, bUnicode);
1311 lpItem->iOrder = iOrder;
1313 /* set automatically some format bits */
1314 if (phdi->mask & HDI_TEXT)
1315 lpItem->fmt |= HDF_STRING;
1317 lpItem->fmt &= ~HDF_STRING;
1319 if (lpItem->hbm != NULL)
1320 lpItem->fmt |= HDF_BITMAP;
1322 lpItem->fmt &= ~HDF_BITMAP;
1324 if (phdi->mask & HDI_IMAGE)
1325 lpItem->fmt |= HDF_IMAGE;
1327 HEADER_SetItemBounds (hwnd);
1328 InvalidateRect(hwnd, NULL, FALSE);
1335 HEADER_Layout (HWND hwnd, LPARAM lParam)
1337 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1338 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1340 lpLayout->pwpos->hwnd = hwnd;
1341 lpLayout->pwpos->hwndInsertAfter = 0;
1342 lpLayout->pwpos->x = lpLayout->prc->left;
1343 lpLayout->pwpos->y = lpLayout->prc->top;
1344 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1345 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_HIDDEN)
1346 lpLayout->pwpos->cy = 0;
1348 lpLayout->pwpos->cy = infoPtr->nHeight;
1349 lpLayout->prc->top += infoPtr->nHeight;
1351 lpLayout->pwpos->flags = SWP_NOZORDER;
1353 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1354 lpLayout->pwpos->x, lpLayout->pwpos->y,
1355 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1357 infoPtr->bRectsValid = FALSE;
1364 HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
1366 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1369 TRACE("(himl %p)\n", himl);
1370 himlOld = infoPtr->himl;
1371 infoPtr->himl = himl;
1373 /* FIXME: Refresh needed??? */
1375 return (LRESULT)himlOld;
1380 HEADER_GetBitmapMargin(HWND hwnd)
1382 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
1384 return infoPtr->iMargin;
1388 HEADER_SetBitmapMargin(HWND hwnd, WPARAM wParam)
1390 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1391 INT oldMargin = infoPtr->iMargin;
1393 infoPtr->iMargin = (INT)wParam;
1399 HEADER_SetItemT (HWND hwnd, INT nItem, const HDITEMW *phdi, BOOL bUnicode)
1401 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1402 HEADER_ITEM *lpItem;
1408 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1411 TRACE("[nItem=%d]\n", nItem);
1413 HEADER_CopyHDItemForNotify(infoPtr, &hdNotify, phdi, bUnicode, &pvScratch);
1414 if (HEADER_SendNotifyWithHDItemT(hwnd, HDN_ITEMCHANGINGW, nItem, &hdNotify))
1420 lpItem = &infoPtr->items[nItem];
1421 HEADER_StoreHDItemInHeader(lpItem, phdi->mask, phdi, bUnicode);
1423 if (phdi->mask & HDI_ORDER)
1424 if (phdi->iOrder >= 0 && phdi->iOrder < infoPtr->uNumItem)
1425 HEADER_ChangeItemOrder(infoPtr, nItem, phdi->iOrder);
1427 HEADER_SendNotifyWithHDItemT(hwnd, HDN_ITEMCHANGEDW, nItem, &hdNotify);
1429 HEADER_SetItemBounds (hwnd);
1431 InvalidateRect(hwnd, NULL, FALSE);
1437 static inline LRESULT
1438 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1440 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1441 BOOL bTemp = (infoPtr->nNotifyFormat == NFR_UNICODE);
1443 infoPtr->nNotifyFormat = ((BOOL)wParam ? NFR_UNICODE : NFR_ANSI);
1450 HEADER_Create (HWND hwnd, LPARAM lParam)
1452 HEADER_INFO *infoPtr;
1457 infoPtr = Alloc (sizeof(HEADER_INFO));
1458 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1460 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
1461 infoPtr->uNumItem = 0;
1465 infoPtr->bRectsValid = FALSE;
1466 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1467 infoPtr->hcurDivider = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDER));
1468 infoPtr->hcurDivopen = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDEROPEN));
1469 infoPtr->bPressed = FALSE;
1470 infoPtr->bTracking = FALSE;
1471 infoPtr->iMoveItem = 0;
1473 infoPtr->iHotItem = -1;
1474 infoPtr->iHotDivider = -1;
1475 infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
1476 infoPtr->nNotifyFormat =
1477 SendMessageW (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1480 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1481 GetTextMetricsW (hdc, &tm);
1482 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1483 SelectObject (hdc, hOldFont);
1486 OpenThemeData(hwnd, themeClass);
1493 HEADER_Destroy (HWND hwnd)
1495 HTHEME theme = GetWindowTheme(hwnd);
1496 CloseThemeData(theme);
1501 HEADER_NCDestroy (HWND hwnd)
1503 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1504 HEADER_ITEM *lpItem;
1507 if (infoPtr->items) {
1508 lpItem = infoPtr->items;
1509 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1510 Free(lpItem->pszText);
1512 Free (infoPtr->items);
1515 Free(infoPtr->order);
1518 ImageList_Destroy (infoPtr->himl);
1520 SetWindowLongPtrW (hwnd, 0, 0);
1527 static inline LRESULT
1528 HEADER_GetFont (HWND hwnd)
1530 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1532 return (LRESULT)infoPtr->hFont;
1537 HEADER_IsDragDistance(const HEADER_INFO *infoPtr, const POINT *pt)
1539 /* Windows allows for a mouse movement before starting the drag. We use the
1540 * SM_CXDOUBLECLICK/SM_CYDOUBLECLICK as that distance.
1542 return (abs(infoPtr->ptLButtonDown.x - pt->x)>GetSystemMetrics(SM_CXDOUBLECLK) ||
1543 abs(infoPtr->ptLButtonDown.y - pt->y)>GetSystemMetrics(SM_CYDOUBLECLK));
1547 HEADER_LButtonDblClk (HWND hwnd, LPARAM lParam)
1553 pt.x = (short)LOWORD(lParam);
1554 pt.y = (short)HIWORD(lParam);
1555 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1557 if ((GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1558 HEADER_SendNotifyWithHDItemT(hwnd, HDN_ITEMDBLCLICKW, nItem, NULL);
1559 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1560 HEADER_SendNotifyWithHDItemT(hwnd, HDN_DIVIDERDBLCLICKW, nItem, NULL);
1567 HEADER_LButtonDown (HWND hwnd, LPARAM lParam)
1569 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1570 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1576 pt.x = (short)LOWORD(lParam);
1577 pt.y = (short)HIWORD(lParam);
1578 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1580 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1582 infoPtr->bCaptured = TRUE;
1583 infoPtr->bPressed = TRUE;
1584 infoPtr->bDragging = FALSE;
1585 infoPtr->iMoveItem = nItem;
1586 infoPtr->ptLButtonDown = pt;
1588 infoPtr->items[nItem].bDown = TRUE;
1590 /* Send WM_CUSTOMDRAW */
1592 HEADER_RefreshItem (hwnd, nItem);
1593 ReleaseDC (hwnd, hdc);
1595 TRACE("Pressed item %d!\n", nItem);
1597 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1598 INT iCurrWidth = infoPtr->items[nItem].cxy;
1599 if (!HEADER_SendNotifyWithIntFieldT(hwnd, HDN_BEGINTRACKW, nItem, HDI_WIDTH, iCurrWidth))
1602 infoPtr->bCaptured = TRUE;
1603 infoPtr->bTracking = TRUE;
1604 infoPtr->iMoveItem = nItem;
1605 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1607 if (!(dwStyle & HDS_FULLDRAG)) {
1608 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1610 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1611 ReleaseDC (hwnd, hdc);
1614 TRACE("Begin tracking item %d!\n", nItem);
1623 HEADER_LButtonUp (HWND hwnd, LPARAM lParam)
1625 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1626 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1632 pt.x = (INT)(SHORT)LOWORD(lParam);
1633 pt.y = (INT)(SHORT)HIWORD(lParam);
1634 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1636 if (infoPtr->bPressed) {
1637 if (infoPtr->bDragging)
1639 HEADER_ITEM *lpItem = &infoPtr->items[infoPtr->iMoveItem];
1642 ImageList_DragShowNolock(FALSE);
1643 ImageList_EndDrag();
1644 lpItem->bDown=FALSE;
1646 if (infoPtr->iHotDivider == -1)
1648 else if (infoPtr->iHotDivider == infoPtr->uNumItem)
1649 iNewOrder = infoPtr->uNumItem-1;
1652 iNewOrder = HEADER_IndexToOrder(hwnd, infoPtr->iHotDivider);
1653 if (iNewOrder > lpItem->iOrder)
1657 if (iNewOrder != -1 &&
1658 !HEADER_SendNotifyWithIntFieldT(hwnd, HDN_ENDDRAG, infoPtr->iMoveItem, HDI_ORDER, iNewOrder))
1660 HEADER_ChangeItemOrder(infoPtr, infoPtr->iMoveItem, iNewOrder);
1661 infoPtr->bRectsValid = FALSE;
1662 InvalidateRect(hwnd, NULL, FALSE);
1665 InvalidateRect(hwnd, &infoPtr->items[infoPtr->iMoveItem].rect, FALSE);
1667 HEADER_SetHotDivider(hwnd, FALSE, -1);
1669 else if (!(dwStyle&HDS_DRAGDROP) || !HEADER_IsDragDistance(infoPtr, &pt))
1671 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1673 HEADER_RefreshItem (hwnd, infoPtr->iMoveItem);
1674 ReleaseDC (hwnd, hdc);
1676 HEADER_SendNotifyWithHDItemT(hwnd, HDN_ITEMCLICKW, infoPtr->iMoveItem, NULL);
1679 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1680 infoPtr->bPressed = FALSE;
1682 else if (infoPtr->bTracking) {
1683 INT iNewWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1686 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1687 infoPtr->bTracking = FALSE;
1689 HEADER_SendNotifyWithIntFieldT(hwnd, HDN_ENDTRACKW, infoPtr->iMoveItem, HDI_WIDTH, iNewWidth);
1691 if (!(dwStyle & HDS_FULLDRAG)) {
1693 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1694 ReleaseDC (hwnd, hdc);
1697 if (!HEADER_SendNotifyWithIntFieldT(hwnd, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH, iNewWidth))
1699 infoPtr->items[infoPtr->iMoveItem].cxy = iNewWidth;
1700 HEADER_SendNotifyWithIntFieldT(hwnd, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH, iNewWidth);
1703 HEADER_SetItemBounds (hwnd);
1704 InvalidateRect(hwnd, NULL, TRUE);
1707 if (infoPtr->bCaptured) {
1708 infoPtr->bCaptured = FALSE;
1710 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1718 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1720 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1725 return infoPtr->nNotifyFormat;
1728 infoPtr->nNotifyFormat =
1729 SendMessageW ((HWND)wParam, WM_NOTIFYFORMAT,
1730 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1731 return infoPtr->nNotifyFormat;
1738 HEADER_MouseLeave (HWND hwnd)
1740 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1741 /* Reset hot-tracked item when mouse leaves control. */
1742 INT oldHotItem = infoPtr->iHotItem;
1743 HDC hdc = GetDC (hwnd);
1745 infoPtr->iHotItem = -1;
1746 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, oldHotItem);
1747 ReleaseDC (hwnd, hdc);
1754 HEADER_MouseMove (HWND hwnd, LPARAM lParam)
1756 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1757 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1762 /* With theming, hottracking is always enabled */
1763 BOOL hotTrackEnabled =
1764 ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK))
1765 || (GetWindowTheme (hwnd) != NULL);
1766 INT oldHotItem = infoPtr->iHotItem;
1768 pt.x = (INT)(SHORT)LOWORD(lParam);
1769 pt.y = (INT)(SHORT)HIWORD(lParam);
1770 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1772 if (hotTrackEnabled) {
1773 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1774 infoPtr->iHotItem = nItem;
1776 infoPtr->iHotItem = -1;
1779 if (infoPtr->bCaptured) {
1780 /* check if we should drag the header */
1781 if (infoPtr->bPressed && !infoPtr->bDragging && dwStyle&HDS_DRAGDROP
1782 && HEADER_IsDragDistance(infoPtr, &pt))
1784 if (!HEADER_SendNotifyWithHDItemT(hwnd, HDN_BEGINDRAG, infoPtr->iMoveItem, NULL))
1786 HIMAGELIST hDragItem = (HIMAGELIST)HEADER_CreateDragImage(hwnd, infoPtr->iMoveItem);
1787 if (hDragItem != NULL)
1789 HEADER_ITEM *lpItem = &infoPtr->items[infoPtr->iMoveItem];
1790 TRACE("Starting item drag\n");
1791 ImageList_BeginDrag(hDragItem, 0, pt.x - lpItem->rect.left, 0);
1792 ImageList_DragShowNolock(TRUE);
1793 ImageList_Destroy(hDragItem);
1794 infoPtr->bDragging = TRUE;
1799 if (infoPtr->bDragging)
1804 ClientToScreen(hwnd, &drag);
1805 ImageList_DragMove(drag.x, drag.y);
1806 HEADER_SetHotDivider(hwnd, TRUE, lParam);
1809 if (infoPtr->bPressed && !infoPtr->bDragging) {
1810 BOOL oldState = infoPtr->items[infoPtr->iMoveItem].bDown;
1811 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1812 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1814 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1815 if (oldState != infoPtr->items[infoPtr->iMoveItem].bDown) {
1817 HEADER_RefreshItem (hwnd, infoPtr->iMoveItem);
1818 ReleaseDC (hwnd, hdc);
1821 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1823 else if (infoPtr->bTracking) {
1824 if (dwStyle & HDS_FULLDRAG) {
1825 HEADER_ITEM *lpItem = &infoPtr->items[infoPtr->iMoveItem];
1826 nWidth = pt.x - lpItem->rect.left + infoPtr->xTrackOffset;
1827 if (!HEADER_SendNotifyWithIntFieldT(hwnd, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH, nWidth))
1829 INT nOldWidth = lpItem->rect.right - lpItem->rect.left;
1833 if (nWidth < 0) nWidth = 0;
1834 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1835 HEADER_SetItemBounds(hwnd);
1837 GetClientRect(hwnd, &rcClient);
1838 rcScroll = rcClient;
1839 rcScroll.left = lpItem->rect.left + nOldWidth;
1840 ScrollWindowEx(hwnd, nWidth - nOldWidth, 0, &rcScroll, &rcClient, NULL, NULL, 0);
1841 InvalidateRect(hwnd, &lpItem->rect, FALSE);
1844 HEADER_SendNotifyWithIntFieldT(hwnd, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH, nWidth);
1850 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1851 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1852 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1853 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1854 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1855 ReleaseDC (hwnd, hdc);
1856 iTrackWidth = infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1857 /* FIXME: should stop tracking if HDN_TRACK returns TRUE */
1858 HEADER_SendNotifyWithIntFieldT(hwnd, HDN_TRACKW, infoPtr->iMoveItem, HDI_WIDTH, iTrackWidth);
1861 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1865 if (hotTrackEnabled) {
1866 TRACKMOUSEEVENT tme;
1867 if (oldHotItem != infoPtr->iHotItem && !infoPtr->bDragging) {
1869 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, oldHotItem);
1870 if (infoPtr->iHotItem != -1) HEADER_RefreshItem (hwnd, infoPtr->iHotItem);
1871 ReleaseDC (hwnd, hdc);
1873 tme.cbSize = sizeof( tme );
1874 tme.dwFlags = TME_LEAVE;
1875 tme.hwndTrack = hwnd;
1876 TrackMouseEvent( &tme );
1884 HEADER_Paint (HWND hwnd, WPARAM wParam)
1889 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1890 HEADER_Refresh (hwnd, hdc);
1892 EndPaint (hwnd, &ps);
1898 HEADER_RButtonUp (HWND hwnd, LPARAM lParam)
1903 pt.x = (short)LOWORD(lParam);
1904 pt.y = (short)HIWORD(lParam);
1906 /* Send a Notify message */
1907 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1909 /* Change to screen coordinate for WM_CONTEXTMENU */
1910 ClientToScreen(hwnd, &pt);
1912 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1913 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1920 HEADER_SetCursor (HWND hwnd, LPARAM lParam)
1922 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1927 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1930 ScreenToClient (hwnd, &pt);
1932 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1934 if (flags == HHT_ONDIVIDER)
1935 SetCursor (infoPtr->hcurDivider);
1936 else if (flags == HHT_ONDIVOPEN)
1937 SetCursor (infoPtr->hcurDivopen);
1939 SetCursor (infoPtr->hcurArrow);
1946 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1948 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1950 HFONT hFont, hOldFont;
1953 infoPtr->hFont = (HFONT)wParam;
1955 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1958 hOldFont = SelectObject (hdc, hFont);
1959 GetTextMetricsW (hdc, &tm);
1960 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1961 SelectObject (hdc, hOldFont);
1964 infoPtr->bRectsValid = FALSE;
1967 InvalidateRect(hwnd, NULL, FALSE);
1973 static LRESULT HEADER_SetRedraw(HWND hwnd, WPARAM wParam, LPARAM lParam)
1975 /* ignoring the InvalidateRect calls is handled by user32. But some apps expect
1976 * that we invalidate the header and this has to be done manually */
1979 ret = DefWindowProcW(hwnd, WM_SETREDRAW, wParam, lParam);
1981 InvalidateRect(hwnd, NULL, TRUE);
1985 /* Update the theme handle after a theme change */
1986 static LRESULT HEADER_ThemeChanged(HWND hwnd)
1988 HTHEME theme = GetWindowTheme(hwnd);
1989 CloseThemeData(theme);
1990 OpenThemeData(hwnd, themeClass);
1991 InvalidateRect(hwnd, NULL, FALSE);
1996 static LRESULT WINAPI
1997 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1999 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd, msg, wParam, lParam);
2000 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
2001 return DefWindowProcW (hwnd, msg, wParam, lParam);
2003 /* case HDM_CLEARFILTER: */
2005 case HDM_CREATEDRAGIMAGE:
2006 return HEADER_CreateDragImage (hwnd, wParam);
2008 case HDM_DELETEITEM:
2009 return HEADER_DeleteItem (hwnd, wParam);
2011 /* case HDM_EDITFILTER: */
2013 case HDM_GETBITMAPMARGIN:
2014 return HEADER_GetBitmapMargin(hwnd);
2016 case HDM_GETIMAGELIST:
2017 return HEADER_GetImageList (hwnd);
2021 return HEADER_GetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_GETITEMW);
2023 case HDM_GETITEMCOUNT:
2024 return HEADER_GetItemCount (hwnd);
2026 case HDM_GETITEMRECT:
2027 return HEADER_GetItemRect (hwnd, wParam, lParam);
2029 case HDM_GETORDERARRAY:
2030 return HEADER_GetOrderArray(hwnd, wParam, lParam);
2032 case HDM_GETUNICODEFORMAT:
2033 return HEADER_GetUnicodeFormat (hwnd);
2036 return HEADER_HitTest (hwnd, lParam);
2038 case HDM_INSERTITEMA:
2039 case HDM_INSERTITEMW:
2040 return HEADER_InsertItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_INSERTITEMW);
2043 return HEADER_Layout (hwnd, lParam);
2045 case HDM_ORDERTOINDEX:
2046 return HEADER_OrderToIndex(hwnd, wParam);
2048 case HDM_SETBITMAPMARGIN:
2049 return HEADER_SetBitmapMargin(hwnd, wParam);
2051 /* case HDM_SETFILTERCHANGETIMEOUT: */
2053 case HDM_SETHOTDIVIDER:
2054 return HEADER_SetHotDivider(hwnd, wParam, lParam);
2056 case HDM_SETIMAGELIST:
2057 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
2061 return HEADER_SetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_SETITEMW);
2063 case HDM_SETORDERARRAY:
2064 return HEADER_SetOrderArray(hwnd, wParam, lParam);
2066 case HDM_SETUNICODEFORMAT:
2067 return HEADER_SetUnicodeFormat (hwnd, wParam);
2070 return HEADER_Create (hwnd, lParam);
2073 return HEADER_Destroy (hwnd);
2076 return HEADER_NCDestroy (hwnd);
2082 return DLGC_WANTTAB | DLGC_WANTARROWS;
2085 return HEADER_GetFont (hwnd);
2087 case WM_LBUTTONDBLCLK:
2088 return HEADER_LButtonDblClk (hwnd, lParam);
2090 case WM_LBUTTONDOWN:
2091 return HEADER_LButtonDown (hwnd, lParam);
2094 return HEADER_LButtonUp (hwnd, lParam);
2097 return HEADER_MouseLeave (hwnd);
2100 return HEADER_MouseMove (hwnd, lParam);
2102 case WM_NOTIFYFORMAT:
2103 return HEADER_NotifyFormat (hwnd, wParam, lParam);
2106 return HEADER_Size (hwnd);
2108 case WM_THEMECHANGED:
2109 return HEADER_ThemeChanged (hwnd);
2111 case WM_PRINTCLIENT:
2113 return HEADER_Paint (hwnd, wParam);
2116 return HEADER_RButtonUp (hwnd, lParam);
2119 return HEADER_SetCursor (hwnd, lParam);
2122 return HEADER_SetFont (hwnd, wParam, lParam);
2125 return HEADER_SetRedraw(hwnd, wParam, lParam);
2128 if ((msg >= WM_USER) && (msg < WM_APP) && !COMCTL32_IsReflectedMessage(msg))
2129 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
2130 msg, wParam, lParam );
2131 return DefWindowProcW(hwnd, msg, wParam, lParam);
2137 HEADER_Register (void)
2141 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
2142 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
2143 wndClass.lpfnWndProc = HEADER_WindowProc;
2144 wndClass.cbClsExtra = 0;
2145 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
2146 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
2147 wndClass.lpszClassName = WC_HEADERW;
2149 RegisterClassW (&wndClass);
2154 HEADER_Unregister (void)
2156 UnregisterClassW (WC_HEADERW, NULL);