4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
8 * - Imagelist support (partially).
9 * - Callback items (under construction).
10 * - Hottrack support (partially).
11 * - Custom draw support (including Notifications).
12 * - Drag and Drop support (including Notifications).
16 * - Little flaw when drawing a bitmap on the right side of the text.
22 #include "wine/unicode.h"
23 #include "wine/winestring.h"
26 #include "imagelist.h"
27 #include "debugtools.h"
29 DEFAULT_DEBUG_CHANNEL(header);
39 INT iOrder; /* see documentation of HD_ITEM */
41 BOOL bDown; /* is item pressed? (used for drawing) */
42 RECT rect; /* bounding rectangle of the item */
48 HWND hwndNotify; /* Owner window to send notifications to */
49 UINT uNumItem; /* number of items (columns) */
50 INT nHeight; /* height of the header (pixels) */
51 HFONT hFont; /* handle to the current font */
52 HCURSOR hcurArrow; /* handle to the arrow cursor */
53 HCURSOR hcurDivider; /* handle to a cursor (used over dividers) <-|-> */
54 HCURSOR hcurDivopen; /* handle to a cursor (used over dividers) <-||-> */
55 BOOL bCaptured; /* Is the mouse captured? */
56 BOOL bPressed; /* Is a header item pressed (down)? */
57 BOOL bTracking; /* Is in tracking mode? */
58 BOOL bUnicode; /* Unicode flag */
59 INT iMoveItem; /* index of tracked item. (Tracking mode) */
60 INT xTrackOffset; /* distance between the right side of the tracked item and the cursor */
61 INT xOldTrack; /* track offset (see above) after the last WM_MOUSEMOVE */
62 INT nOldWidth; /* width of a sizing item after the last WM_MOUSEMOVE */
63 INT iHotItem; /* index of hot item (cursor is over this item) */
65 HIMAGELIST himl; /* handle to a image list (may be 0) */
66 HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */
67 BOOL bRectsValid; /* validity flag for bounding rectangles */
72 #define DIVIDER_WIDTH 10
74 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongA(hwnd,0))
78 HEADER_IndexToOrder (HWND hwnd, INT iItem)
80 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
81 HEADER_ITEM *lpItem = (HEADER_ITEM*)&infoPtr->items[iItem];
82 return lpItem->iOrder;
87 HEADER_OrderToIndex(HWND hwnd, WPARAM wParam)
89 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
90 INT i,iorder = (INT)wParam;
93 if ((iorder <0) || iorder >infoPtr->uNumItem)
95 for (i=0; i<infoPtr->uNumItem; i++)
96 if (HEADER_IndexToOrder(hwnd,i) == iorder)
102 HEADER_SetItemBounds (HWND hwnd)
104 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
109 infoPtr->bRectsValid = TRUE;
111 if (infoPtr->uNumItem == 0)
114 GetClientRect (hwnd, &rect);
117 for (i = 0; i < infoPtr->uNumItem; i++) {
118 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
119 phdi->rect.top = rect.top;
120 phdi->rect.bottom = rect.bottom;
122 phdi->rect.right = phdi->rect.left + phdi->cxy;
123 x = phdi->rect.right;
128 HEADER_Size (HWND hwnd, WPARAM wParam)
130 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
132 infoPtr->bRectsValid = FALSE;
139 HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
141 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
142 HEADER_ITEM *phdi = &infoPtr->items[iItem];
146 if (!infoPtr->bRectsValid)
147 HEADER_SetItemBounds(hwnd);
150 if (r.right - r.left == 0)
151 return phdi->rect.right;
153 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) {
155 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
156 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
161 DrawEdge (hdc, &r, EDGE_RAISED,
162 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
165 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
167 if (phdi->fmt & HDF_OWNERDRAW) {
169 dis.CtlType = ODT_HEADER;
170 dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
172 dis.itemAction = ODA_DRAWENTIRE;
173 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
177 dis.itemData = phdi->lParam;
178 SendMessageA (GetParent (hwnd), WM_DRAWITEM,
179 (WPARAM)dis.CtlID, (LPARAM)&dis);
182 UINT uTextJustify = DT_LEFT;
184 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
185 uTextJustify = DT_CENTER;
186 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
187 uTextJustify = DT_RIGHT;
189 if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
192 INT yD, yS, cx, cy, rx, ry;
194 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
196 ry = r.bottom - r.top;
197 rx = r.right - r.left;
199 if (ry >= bmp.bmHeight) {
201 yD = r.top + (ry - bmp.bmHeight) / 2;
207 yS = (bmp.bmHeight - ry) / 2;
211 if (rx >= bmp.bmWidth + 6) {
218 hdcBitmap = CreateCompatibleDC (hdc);
219 SelectObject (hdcBitmap, phdi->hbm);
220 BitBlt (hdc, r.left + 3, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
221 DeleteDC (hdcBitmap);
223 r.left += (bmp.bmWidth + 3);
227 if ((phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
230 INT xD, yD, yS, cx, cy, rx, ry, tx;
233 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
236 DrawTextW (hdc, phdi->pszText, -1,
237 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
238 tx = textRect.right - textRect.left;
239 ry = r.bottom - r.top;
240 rx = r.right - r.left;
242 if (ry >= bmp.bmHeight) {
244 yD = r.top + (ry - bmp.bmHeight) / 2;
250 yS = (bmp.bmHeight - ry) / 2;
254 if (r.left + tx + bmp.bmWidth + 9 <= r.right) {
256 xD = r.left + tx + 6;
259 if (rx >= bmp.bmWidth + 6) {
261 xD = r.right - bmp.bmWidth - 3;
271 hdcBitmap = CreateCompatibleDC (hdc);
272 SelectObject (hdcBitmap, phdi->hbm);
273 BitBlt (hdc, xD, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
274 DeleteDC (hdcBitmap);
277 if (phdi->fmt & HDF_IMAGE) {
279 /* FIXME: (r.bottom- (infoPtr->himl->cy))/2 should horicontal center the image
280 It looks like it doesn't work as expected*/
281 ImageList_Draw (infoPtr->himl, phdi->iImage,hdc,r.left, (r.bottom- (infoPtr->himl->cy))/2,NULL);
282 r.left += infoPtr->himl->cx;
285 if (((phdi->fmt & HDF_STRING)
286 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
287 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
288 && (phdi->pszText)) {
289 oldBkMode = SetBkMode(hdc, TRANSPARENT);
292 SetTextColor (hdc, (bHotTrack) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
293 DrawTextW (hdc, phdi->pszText, -1,
294 &r, uTextJustify|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
295 if (oldBkMode != TRANSPARENT)
296 SetBkMode(hdc, oldBkMode);
300 return phdi->rect.right;
305 HEADER_Refresh (HWND hwnd, HDC hdc)
307 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
308 HFONT hFont, hOldFont;
313 /* get rect for the bar, adjusted for the border */
314 GetClientRect (hwnd, &rect);
316 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
317 hOldFont = SelectObject (hdc, hFont);
319 /* draw Background */
320 hbrBk = GetSysColorBrush(COLOR_3DFACE);
321 FillRect(hdc, &rect, hbrBk);
324 for (i = 0; i < infoPtr->uNumItem; i++) {
325 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i), FALSE);
328 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
330 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS)
331 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
333 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
336 SelectObject (hdc, hOldFont);
341 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
343 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
344 HFONT hFont, hOldFont;
346 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
347 hOldFont = SelectObject (hdc, hFont);
348 HEADER_DrawItem (hwnd, hdc, iItem, FALSE);
349 SelectObject (hdc, hOldFont);
354 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
356 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
361 GetClientRect (hwnd, &rect);
365 if (PtInRect (&rect, *lpPt))
367 if (infoPtr->uNumItem == 0) {
368 *pFlags |= HHT_NOWHERE;
374 /* somewhere inside */
375 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
376 rect = infoPtr->items[iCount].rect;
377 width = rect.right - rect.left;
382 if (PtInRect (&rect, *lpPt)) {
383 if (width <= 2 * DIVIDER_WIDTH) {
384 *pFlags |= HHT_ONHEADER;
386 TRACE("ON HEADER %d\n", iCount);
391 rcTest.right = rcTest.left + DIVIDER_WIDTH;
392 if (PtInRect (&rcTest, *lpPt)) {
394 *pFlags |= HHT_ONDIVOPEN;
396 TRACE("ON DIVOPEN %d\n", *pItem);
400 *pFlags |= HHT_ONDIVIDER;
402 TRACE("ON DIVIDER %d\n", *pItem);
408 rcTest.left = rcTest.right - DIVIDER_WIDTH;
409 if (PtInRect (&rcTest, *lpPt)) {
410 *pFlags |= HHT_ONDIVIDER;
412 TRACE("ON DIVIDER %d\n", *pItem);
416 *pFlags |= HHT_ONHEADER;
418 TRACE("ON HEADER %d\n", iCount);
423 /* check for last divider part (on nowhere) */
424 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
425 rect.left = rect.right;
426 rect.right += DIVIDER_WIDTH;
427 if (PtInRect (&rect, *lpPt)) {
429 *pFlags |= HHT_ONDIVOPEN;
430 *pItem = infoPtr->uNumItem - 1;
431 TRACE("ON DIVOPEN %d\n", *pItem);
435 *pFlags |= HHT_ONDIVIDER;
436 *pItem = infoPtr->uNumItem-1;
437 TRACE("ON DIVIDER %d\n", *pItem);
442 *pFlags |= HHT_NOWHERE;
449 if (lpPt->x < rect.left) {
451 *pFlags |= HHT_TOLEFT;
453 else if (lpPt->x > rect.right) {
455 *pFlags |= HHT_TORIGHT;
458 if (lpPt->y < rect.top) {
460 *pFlags |= HHT_ABOVE;
462 else if (lpPt->y > rect.bottom) {
464 *pFlags |= HHT_BELOW;
469 TRACE("flags=0x%X\n", *pFlags);
475 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
481 GetClientRect (hwnd, &rect);
483 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
484 oldRop = SetROP2 (hdc, R2_XORPEN);
485 MoveToEx (hdc, x, rect.top, NULL);
486 LineTo (hdc, x, rect.bottom);
487 SetROP2 (hdc, oldRop);
488 SelectObject (hdc, hOldPen);
493 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
495 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
498 nmhdr.hwndFrom = hwnd;
499 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
502 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
503 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
507 HEADER_SendHeaderNotify (HWND hwnd, UINT code, INT iItem, INT mask)
509 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
513 nmhdr.hdr.hwndFrom = hwnd;
514 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
515 nmhdr.hdr.code = code;
518 nmhdr.pitem = &nmitem;
520 nmitem.cxy = infoPtr->items[iItem].cxy;
521 nmitem.hbm = infoPtr->items[iItem].hbm;
522 nmitem.pszText = NULL;
523 nmitem.cchTextMax = 0;
524 /* nmitem.pszText = infoPtr->items[iItem].pszText; */
525 /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
526 nmitem.fmt = infoPtr->items[iItem].fmt;
527 nmitem.lParam = infoPtr->items[iItem].lParam;
528 nmitem.iOrder = infoPtr->items[iItem].iOrder;
529 nmitem.iImage = infoPtr->items[iItem].iImage;
531 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
532 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
537 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
539 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
542 nmhdr.hdr.hwndFrom = hwnd;
543 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
544 nmhdr.hdr.code = code;
549 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
550 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
555 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
557 FIXME("empty stub!\n");
563 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
565 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
566 INT iItem = (INT)wParam;
568 TRACE("[iItem=%d]\n", iItem);
570 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
573 if (infoPtr->uNumItem == 1) {
574 TRACE("Simple delete!\n");
575 if (infoPtr->items[0].pszText)
576 COMCTL32_Free (infoPtr->items[0].pszText);
577 COMCTL32_Free (infoPtr->items);
579 infoPtr->uNumItem = 0;
582 HEADER_ITEM *oldItems = infoPtr->items;
583 TRACE("Complex delete! [iItem=%d]\n", iItem);
585 if (infoPtr->items[iItem].pszText)
586 COMCTL32_Free (infoPtr->items[iItem].pszText);
589 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
590 /* pre delete copy */
592 memcpy (&infoPtr->items[0], &oldItems[0],
593 iItem * sizeof(HEADER_ITEM));
596 /* post delete copy */
597 if (iItem < infoPtr->uNumItem) {
598 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
599 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
602 COMCTL32_Free (oldItems);
605 HEADER_SetItemBounds (hwnd);
607 InvalidateRect(hwnd, NULL, FALSE);
614 HEADER_GetImageList (HWND hwnd)
616 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
618 return (LRESULT)infoPtr->himl;
623 HEADER_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
625 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
626 HDITEMA *phdi = (HDITEMA*)lParam;
627 INT nItem = (INT)wParam;
632 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
635 TRACE("[nItem=%d]\n", nItem);
640 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
641 if (phdi->mask & HDI_BITMAP)
642 phdi->hbm = lpItem->hbm;
644 if (phdi->mask & HDI_FORMAT)
645 phdi->fmt = lpItem->fmt;
647 if (phdi->mask & HDI_WIDTH)
648 phdi->cxy = lpItem->cxy;
650 if (phdi->mask & HDI_LPARAM)
651 phdi->lParam = lpItem->lParam;
653 if (phdi->mask & HDI_TEXT) {
654 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
656 lstrcpynWtoA (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
661 phdi->pszText = LPSTR_TEXTCALLBACKA;
664 if (phdi->mask & HDI_IMAGE)
665 phdi->iImage = lpItem->iImage;
667 if (phdi->mask & HDI_ORDER)
668 phdi->iOrder = lpItem->iOrder;
675 HEADER_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
677 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
678 HDITEMW *phdi = (HDITEMW*)lParam;
679 INT nItem = (INT)wParam;
684 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
687 TRACE("[nItem=%d]\n", nItem);
692 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
693 if (phdi->mask & HDI_BITMAP)
694 phdi->hbm = lpItem->hbm;
696 if (phdi->mask & HDI_FORMAT)
697 phdi->fmt = lpItem->fmt;
699 if (phdi->mask & HDI_WIDTH)
700 phdi->cxy = lpItem->cxy;
702 if (phdi->mask & HDI_LPARAM)
703 phdi->lParam = lpItem->lParam;
705 if (phdi->mask & HDI_TEXT) {
706 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
708 lstrcpynW (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
713 phdi->pszText = LPSTR_TEXTCALLBACKW;
716 if (phdi->mask & HDI_IMAGE)
717 phdi->iImage = lpItem->iImage;
719 if (phdi->mask & HDI_ORDER)
720 phdi->iOrder = lpItem->iOrder;
726 inline static LRESULT
727 HEADER_GetItemCount (HWND hwnd)
729 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
730 return infoPtr->uNumItem;
735 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
737 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
738 INT iItem = (INT)wParam;
739 LPRECT lpRect = (LPRECT)lParam;
741 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
744 lpRect->left = infoPtr->items[iItem].rect.left;
745 lpRect->right = infoPtr->items[iItem].rect.right;
746 lpRect->top = infoPtr->items[iItem].rect.top;
747 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
754 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
757 LPINT order = (LPINT) lParam;
758 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
760 if ((int)wParam <infoPtr->uNumItem)
762 for (i=0; i<(int)wParam; i++)
763 *order++=HEADER_OrderToIndex(hwnd,i);
768 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
771 LPINT order = (LPINT) lParam;
772 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
775 if ((int)wParam <infoPtr->uNumItem)
777 for (i=0; i<(int)wParam; i++)
779 lpItem = (HEADER_ITEM*)&infoPtr->items[*order++];
782 infoPtr->bRectsValid=0;
783 InvalidateRect(hwnd, NULL, FALSE);
787 inline static LRESULT
788 HEADER_GetUnicodeFormat (HWND hwnd)
790 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
791 return infoPtr->bUnicode;
796 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
798 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
800 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
802 if (phti->flags == HHT_ONHEADER)
810 HEADER_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
812 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
813 HDITEMA *phdi = (HDITEMA*)lParam;
814 INT nItem = (INT)wParam;
818 if ((phdi == NULL) || (nItem < 0))
821 if (nItem > infoPtr->uNumItem)
822 nItem = infoPtr->uNumItem;
824 if (infoPtr->uNumItem == 0) {
825 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
829 HEADER_ITEM *oldItems = infoPtr->items;
832 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
834 memcpy (&infoPtr->items[1], &oldItems[0],
835 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
839 /* pre insert copy */
841 memcpy (&infoPtr->items[0], &oldItems[0],
842 nItem * sizeof(HEADER_ITEM));
845 /* post insert copy */
846 if (nItem < infoPtr->uNumItem - 1) {
847 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
848 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
852 COMCTL32_Free (oldItems);
855 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
856 lpItem->bDown = FALSE;
858 if (phdi->mask & HDI_WIDTH)
859 lpItem->cxy = phdi->cxy;
861 if (phdi->mask & HDI_TEXT) {
862 if (!phdi->pszText) /* null pointer check */
864 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
865 len = strlen (phdi->pszText);
866 lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
867 lstrcpyAtoW (lpItem->pszText, phdi->pszText);
870 lpItem->pszText = LPSTR_TEXTCALLBACKW;
873 if (phdi->mask & HDI_FORMAT)
874 lpItem->fmt = phdi->fmt;
876 if (lpItem->fmt == 0)
877 lpItem->fmt = HDF_LEFT;
879 if (!(lpItem->fmt &HDF_STRING) && (phdi->mask & HDI_TEXT))
881 lpItem->fmt |= HDF_STRING;
883 if (phdi->mask & HDI_BITMAP)
884 lpItem->hbm = phdi->hbm;
886 if (phdi->mask & HDI_LPARAM)
887 lpItem->lParam = phdi->lParam;
889 if (phdi->mask & HDI_IMAGE)
890 lpItem->iImage = phdi->iImage;
892 if (phdi->mask & HDI_ORDER)
894 lpItem->iOrder = phdi->iOrder;
897 lpItem->iOrder=nItem;
900 HEADER_SetItemBounds (hwnd);
902 InvalidateRect(hwnd, NULL, FALSE);
909 HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
911 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
912 HDITEMW *phdi = (HDITEMW*)lParam;
913 INT nItem = (INT)wParam;
917 if ((phdi == NULL) || (nItem < 0))
920 if (nItem > infoPtr->uNumItem)
921 nItem = infoPtr->uNumItem;
923 if (infoPtr->uNumItem == 0) {
924 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
928 HEADER_ITEM *oldItems = infoPtr->items;
931 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
932 /* pre insert copy */
934 memcpy (&infoPtr->items[0], &oldItems[0],
935 nItem * sizeof(HEADER_ITEM));
938 /* post insert copy */
939 if (nItem < infoPtr->uNumItem - 1) {
940 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
941 (infoPtr->uNumItem - nItem) * sizeof(HEADER_ITEM));
944 COMCTL32_Free (oldItems);
947 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
948 lpItem->bDown = FALSE;
950 if (phdi->mask & HDI_WIDTH)
951 lpItem->cxy = phdi->cxy;
953 if (phdi->mask & HDI_TEXT) {
954 WCHAR wide_null_char = 0;
955 if (!phdi->pszText) /* null pointer check */
956 phdi->pszText = &wide_null_char;
957 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
958 len = strlenW (phdi->pszText);
959 lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
960 strcpyW (lpItem->pszText, phdi->pszText);
963 lpItem->pszText = LPSTR_TEXTCALLBACKW;
966 if (phdi->mask & HDI_FORMAT)
967 lpItem->fmt = phdi->fmt;
969 if (lpItem->fmt == 0)
970 lpItem->fmt = HDF_LEFT;
972 if (phdi->mask & HDI_BITMAP)
973 lpItem->hbm = phdi->hbm;
975 if (phdi->mask & HDI_LPARAM)
976 lpItem->lParam = phdi->lParam;
978 if (phdi->mask & HDI_IMAGE)
979 lpItem->iImage = phdi->iImage;
981 if (phdi->mask & HDI_ORDER)
983 lpItem->iOrder = phdi->iOrder;
986 lpItem->iOrder = nItem;
988 HEADER_SetItemBounds (hwnd);
990 InvalidateRect(hwnd, NULL, FALSE);
997 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
999 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1000 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1002 lpLayout->pwpos->hwnd = hwnd;
1003 lpLayout->pwpos->hwndInsertAfter = 0;
1004 lpLayout->pwpos->x = lpLayout->prc->left;
1005 lpLayout->pwpos->y = lpLayout->prc->top;
1006 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1007 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_HIDDEN)
1008 lpLayout->pwpos->cy = 0;
1010 lpLayout->pwpos->cy = infoPtr->nHeight;
1011 lpLayout->prc->top += infoPtr->nHeight;
1013 lpLayout->pwpos->flags = SWP_NOZORDER;
1015 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1016 lpLayout->pwpos->x, lpLayout->pwpos->y,
1017 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1019 infoPtr->bRectsValid = FALSE;
1026 HEADER_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
1028 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1031 himlOld = infoPtr->himl;
1032 infoPtr->himl = (HIMAGELIST)lParam;
1034 /* FIXME: Refresh needed??? */
1036 return (LRESULT)himlOld;
1041 HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1043 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1044 HDITEMA *phdi = (HDITEMA*)lParam;
1045 INT nItem = (INT)wParam;
1046 HEADER_ITEM *lpItem;
1050 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1053 TRACE("[nItem=%d]\n", nItem);
1055 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem, phdi->mask))
1058 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
1059 if (phdi->mask & HDI_BITMAP)
1060 lpItem->hbm = phdi->hbm;
1062 if (phdi->mask & HDI_FORMAT)
1063 lpItem->fmt = phdi->fmt;
1065 if (phdi->mask & HDI_LPARAM)
1066 lpItem->lParam = phdi->lParam;
1068 if (phdi->mask & HDI_TEXT) {
1069 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
1070 if (lpItem->pszText) {
1071 COMCTL32_Free (lpItem->pszText);
1072 lpItem->pszText = NULL;
1074 if (phdi->pszText) {
1075 INT len = strlen (phdi->pszText);
1076 lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1077 // lstrcpyAtoW (lpItem->pszText, phdi->pszText);
1078 MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,
1079 lpItem->pszText,0x7fffffff);
1083 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1086 if (phdi->mask & HDI_WIDTH)
1087 lpItem->cxy = phdi->cxy;
1089 if (phdi->mask & HDI_IMAGE)
1090 lpItem->iImage = phdi->iImage;
1092 if (phdi->mask & HDI_ORDER)
1094 lpItem->iOrder = phdi->iOrder;
1097 lpItem->iOrder = nItem;
1099 HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem, phdi->mask);
1101 HEADER_SetItemBounds (hwnd);
1103 InvalidateRect(hwnd, NULL, FALSE);
1110 HEADER_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1112 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1113 HDITEMW *phdi = (HDITEMW*)lParam;
1114 INT nItem = (INT)wParam;
1115 HEADER_ITEM *lpItem;
1119 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1122 TRACE("[nItem=%d]\n", nItem);
1124 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask))
1127 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
1128 if (phdi->mask & HDI_BITMAP)
1129 lpItem->hbm = phdi->hbm;
1131 if (phdi->mask & HDI_FORMAT)
1132 lpItem->fmt = phdi->fmt;
1134 if (phdi->mask & HDI_LPARAM)
1135 lpItem->lParam = phdi->lParam;
1137 if (phdi->mask & HDI_TEXT) {
1138 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1139 if (lpItem->pszText) {
1140 COMCTL32_Free (lpItem->pszText);
1141 lpItem->pszText = NULL;
1143 if (phdi->pszText) {
1144 INT len = strlenW (phdi->pszText);
1145 lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1146 strcpyW (lpItem->pszText, phdi->pszText);
1150 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1153 if (phdi->mask & HDI_WIDTH)
1154 lpItem->cxy = phdi->cxy;
1156 if (phdi->mask & HDI_IMAGE)
1157 lpItem->iImage = phdi->iImage;
1159 if (phdi->mask & HDI_ORDER)
1161 lpItem->iOrder = phdi->iOrder;
1164 lpItem->iOrder = nItem;
1166 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask);
1168 HEADER_SetItemBounds (hwnd);
1170 InvalidateRect(hwnd, NULL, FALSE);
1175 inline static LRESULT
1176 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1178 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1179 BOOL bTemp = infoPtr->bUnicode;
1181 infoPtr->bUnicode = (BOOL)wParam;
1188 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1190 HEADER_INFO *infoPtr;
1195 infoPtr = (HEADER_INFO *)COMCTL32_Alloc (sizeof(HEADER_INFO));
1196 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1198 infoPtr->hwndNotify = GetParent(hwnd);
1199 infoPtr->uNumItem = 0;
1200 infoPtr->nHeight = 20;
1203 infoPtr->bRectsValid = FALSE;
1204 infoPtr->hcurArrow = LoadCursorA (0, IDC_ARROWA);
1205 infoPtr->hcurDivider = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDER));
1206 infoPtr->hcurDivopen = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDEROPEN));
1207 infoPtr->bPressed = FALSE;
1208 infoPtr->bTracking = FALSE;
1209 infoPtr->iMoveItem = 0;
1211 infoPtr->iHotItem = -1;
1212 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1215 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1216 GetTextMetricsA (hdc, &tm);
1217 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1218 SelectObject (hdc, hOldFont);
1226 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1228 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1229 HEADER_ITEM *lpItem;
1232 if (infoPtr->items) {
1233 lpItem = (HEADER_ITEM*)infoPtr->items;
1234 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1235 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
1236 COMCTL32_Free (lpItem->pszText);
1238 COMCTL32_Free (infoPtr->items);
1242 ImageList_Destroy (infoPtr->himl);
1244 COMCTL32_Free (infoPtr);
1245 SetWindowLongA (hwnd, 0, 0);
1250 static inline LRESULT
1251 HEADER_GetFont (HWND hwnd)
1253 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1255 return (LRESULT)infoPtr->hFont;
1260 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1266 pt.x = (INT)LOWORD(lParam);
1267 pt.y = (INT)HIWORD(lParam);
1268 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1270 if ((GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1271 HEADER_SendHeaderNotify (hwnd, HDN_ITEMDBLCLICKA, nItem,0);
1272 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1273 HEADER_SendHeaderNotify (hwnd, HDN_DIVIDERDBLCLICKA, nItem,0);
1280 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1282 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1283 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1289 pt.x = (INT)LOWORD(lParam);
1290 pt.y = (INT)HIWORD(lParam);
1291 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1293 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1295 infoPtr->bCaptured = TRUE;
1296 infoPtr->bPressed = TRUE;
1297 infoPtr->iMoveItem = nItem;
1299 infoPtr->items[nItem].bDown = TRUE;
1301 /* Send WM_CUSTOMDRAW */
1303 HEADER_RefreshItem (hwnd, hdc, nItem);
1304 ReleaseDC (hwnd, hdc);
1306 TRACE("Pressed item %d!\n", nItem);
1308 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1309 if (!(HEADER_SendHeaderNotify (hwnd, HDN_BEGINTRACKA, nItem,0))) {
1311 infoPtr->bCaptured = TRUE;
1312 infoPtr->bTracking = TRUE;
1313 infoPtr->iMoveItem = nItem;
1314 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1315 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1317 if (!(dwStyle & HDS_FULLDRAG)) {
1318 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1320 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1321 ReleaseDC (hwnd, hdc);
1324 TRACE("Begin tracking item %d!\n", nItem);
1333 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1335 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1337 *DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1344 pt.x = (INT)SLOWORD(lParam);
1345 pt.y = (INT)SHIWORD(lParam);
1346 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1348 if (infoPtr->bPressed) {
1349 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1350 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1352 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1353 ReleaseDC (hwnd, hdc);
1355 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1357 else if (flags == HHT_ONHEADER)
1359 HEADER_ITEM *lpItem;
1360 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1361 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1363 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1364 infoPtr->iMoveItem,oldindex,nItem,newindex);
1365 lpItem= (HEADER_ITEM*)&infoPtr->items[nItem];
1366 lpItem->iOrder=oldindex;
1368 lpItem= (HEADER_ITEM*)&infoPtr->items[infoPtr->iMoveItem];
1369 lpItem->iOrder = newindex;
1371 infoPtr->bRectsValid = FALSE;
1372 InvalidateRect(hwnd, NULL, FALSE);
1373 /* FIXME: Should some WM_NOTIFY be sent */
1376 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1377 infoPtr->bPressed = FALSE;
1379 else if (infoPtr->bTracking) {
1380 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1381 infoPtr->bTracking = FALSE;
1383 HEADER_SendHeaderNotify (hwnd, HDN_ENDTRACKA, infoPtr->iMoveItem,0);
1386 * we want to do this even for HDS_FULLDRAG because this is where
1387 * we send the HDN_ITEMCHANGING and HDN_ITEMCHANGED notifications
1389 * if (!(dwStyle & HDS_FULLDRAG)) {
1393 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1394 ReleaseDC (hwnd, hdc);
1395 if (HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1396 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1398 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1401 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1404 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH);
1405 HEADER_SetItemBounds (hwnd);
1406 InvalidateRect(hwnd, NULL, FALSE);
1412 if (infoPtr->bCaptured) {
1413 infoPtr->bCaptured = FALSE;
1415 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1423 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1425 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1426 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1432 pt.x = (INT)SLOWORD(lParam);
1433 pt.y = (INT)SHIWORD(lParam);
1434 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1436 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1437 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1438 infoPtr->iHotItem = nItem;
1440 infoPtr->iHotItem = -1;
1441 InvalidateRect(hwnd, NULL, FALSE);
1444 if (infoPtr->bCaptured) {
1445 if (infoPtr->bPressed) {
1446 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1447 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1449 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1451 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1452 ReleaseDC (hwnd, hdc);
1454 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1456 else if (infoPtr->bTracking) {
1457 if (dwStyle & HDS_FULLDRAG) {
1458 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1460 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1463 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1464 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1466 HEADER_SetItemBounds (hwnd);
1467 InvalidateRect(hwnd, NULL, FALSE);
1471 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1472 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1473 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1474 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1475 infoPtr->items[infoPtr->iMoveItem].cxy =
1476 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1477 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1478 ReleaseDC (hwnd, hdc);
1479 HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH);
1482 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1486 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1487 FIXME("hot track support!\n");
1495 HEADER_Paint (HWND hwnd, WPARAM wParam)
1500 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1501 HEADER_Refresh (hwnd, hdc);
1503 EndPaint (hwnd, &ps);
1509 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1514 pt.x = LOWORD(lParam);
1515 pt.y = HIWORD(lParam);
1517 /* Send a Notify message */
1518 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1520 /* Change to screen coordinate for WM_CONTEXTMENU */
1521 ClientToScreen(hwnd, &pt);
1523 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1524 SendMessageA( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1531 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1533 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1538 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1541 ScreenToClient (hwnd, &pt);
1543 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1545 if (flags == HHT_ONDIVIDER)
1546 SetCursor (infoPtr->hcurDivider);
1547 else if (flags == HHT_ONDIVOPEN)
1548 SetCursor (infoPtr->hcurDivopen);
1550 SetCursor (infoPtr->hcurArrow);
1557 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1559 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1561 HFONT hFont, hOldFont;
1564 infoPtr->hFont = (HFONT)wParam;
1566 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1569 hOldFont = SelectObject (hdc, hFont);
1570 GetTextMetricsA (hdc, &tm);
1571 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1572 SelectObject (hdc, hOldFont);
1575 infoPtr->bRectsValid = FALSE;
1578 InvalidateRect(hwnd, NULL, FALSE);
1585 static LRESULT WINAPI
1586 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1588 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1589 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1590 return DefWindowProcA (hwnd, msg, wParam, lParam);
1592 case HDM_CREATEDRAGIMAGE:
1593 return HEADER_CreateDragImage (hwnd, wParam);
1595 case HDM_DELETEITEM:
1596 return HEADER_DeleteItem (hwnd, wParam);
1598 case HDM_GETIMAGELIST:
1599 return HEADER_GetImageList (hwnd);
1602 return HEADER_GetItemA (hwnd, wParam, lParam);
1605 return HEADER_GetItemW (hwnd, wParam, lParam);
1607 case HDM_GETITEMCOUNT:
1608 return HEADER_GetItemCount (hwnd);
1610 case HDM_GETITEMRECT:
1611 return HEADER_GetItemRect (hwnd, wParam, lParam);
1613 case HDM_GETORDERARRAY:
1614 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1616 case HDM_SETORDERARRAY:
1617 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1619 case HDM_ORDERTOINDEX:
1620 return HEADER_OrderToIndex(hwnd, wParam);
1622 case HDM_GETUNICODEFORMAT:
1623 return HEADER_GetUnicodeFormat (hwnd);
1626 return HEADER_HitTest (hwnd, wParam, lParam);
1628 case HDM_INSERTITEMA:
1629 return HEADER_InsertItemA (hwnd, wParam, lParam);
1631 case HDM_INSERTITEMW:
1632 return HEADER_InsertItemW (hwnd, wParam, lParam);
1635 return HEADER_Layout (hwnd, wParam, lParam);
1637 case HDM_SETIMAGELIST:
1638 return HEADER_SetImageList (hwnd, wParam, lParam);
1641 return HEADER_SetItemA (hwnd, wParam, lParam);
1644 return HEADER_SetItemW (hwnd, wParam, lParam);
1646 case HDM_SETUNICODEFORMAT:
1647 return HEADER_SetUnicodeFormat (hwnd, wParam);
1650 return HEADER_Create (hwnd, wParam, lParam);
1653 return HEADER_Destroy (hwnd, wParam, lParam);
1659 return DLGC_WANTTAB | DLGC_WANTARROWS;
1662 return HEADER_GetFont (hwnd);
1664 case WM_LBUTTONDBLCLK:
1665 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1667 case WM_LBUTTONDOWN:
1668 return HEADER_LButtonDown (hwnd, wParam, lParam);
1671 return HEADER_LButtonUp (hwnd, wParam, lParam);
1674 return HEADER_MouseMove (hwnd, wParam, lParam);
1676 /* case WM_NOTIFYFORMAT: */
1679 return HEADER_Size (hwnd, wParam);
1682 return HEADER_Paint (hwnd, wParam);
1685 return HEADER_RButtonUp (hwnd, wParam, lParam);
1688 return HEADER_SetCursor (hwnd, wParam, lParam);
1691 return HEADER_SetFont (hwnd, wParam, lParam);
1695 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1696 msg, wParam, lParam );
1697 return DefWindowProcA (hwnd, msg, wParam, lParam);
1704 HEADER_Register (void)
1708 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1709 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1710 wndClass.lpfnWndProc = (WNDPROC)HEADER_WindowProc;
1711 wndClass.cbClsExtra = 0;
1712 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1713 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
1714 wndClass.lpszClassName = WC_HEADERA;
1716 RegisterClassA (&wndClass);
1721 HEADER_Unregister (void)
1723 UnregisterClassA (WC_HEADERA, (HINSTANCE)NULL);