4 * Copyright 1998 Eric Kohl
7 * - Imagelist support (partially).
8 * - Callback items (under construction).
9 * - Order list support.
10 * - Control specific cursors (over dividers).
11 * - Hottrack support (partially).
12 * - Custom draw support (including Notifications).
13 * - Drag and Drop support (including Notifications).
17 * - Replace DrawText32A by DrawTextEx32A(...|DT_ENDELLIPSIS) in
19 * - Little flaw when drawing a bitmap on the right side of the text.
29 DEFAULT_DEBUG_CHANNEL(header)
32 #define __HDM_LAYOUT_HACK__
36 #define DIVIDER_WIDTH 10
38 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongA(hwnd,0))
42 HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
44 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
45 HEADER_ITEM *phdi = &infoPtr->items[iItem];
50 if (r.right - r.left == 0)
51 return phdi->rect.right;
53 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) {
55 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
56 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
61 DrawEdge (hdc, &r, EDGE_RAISED,
62 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
65 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
67 if (phdi->fmt & HDF_OWNERDRAW) {
69 dis.CtlType = ODT_HEADER;
70 dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
72 dis.itemAction = ODA_DRAWENTIRE;
73 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
77 dis.itemData = phdi->lParam;
78 SendMessageA (GetParent (hwnd), WM_DRAWITEM,
79 (WPARAM)dis.CtlID, (LPARAM)&dis);
82 UINT uTextJustify = DT_LEFT;
84 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
85 uTextJustify = DT_CENTER;
86 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
87 uTextJustify = DT_RIGHT;
89 if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
92 INT yD, yS, cx, cy, rx, ry;
94 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
96 ry = r.bottom - r.top;
97 rx = r.right - r.left;
99 if (ry >= bmp.bmHeight) {
101 yD = r.top + (ry - bmp.bmHeight) / 2;
107 yS = (bmp.bmHeight - ry) / 2;
111 if (rx >= bmp.bmWidth + 6) {
118 hdcBitmap = CreateCompatibleDC (hdc);
119 SelectObject (hdcBitmap, phdi->hbm);
120 BitBlt (hdc, r.left + 3, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
121 DeleteDC (hdcBitmap);
123 r.left += (bmp.bmWidth + 3);
127 if ((phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
130 INT xD, yD, yS, cx, cy, rx, ry, tx;
133 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
136 DrawTextW (hdc, phdi->pszText, lstrlenW (phdi->pszText),
137 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
138 tx = textRect.right - textRect.left;
139 ry = r.bottom - r.top;
140 rx = r.right - r.left;
142 if (ry >= bmp.bmHeight) {
144 yD = r.top + (ry - bmp.bmHeight) / 2;
150 yS = (bmp.bmHeight - ry) / 2;
154 if (r.left + tx + bmp.bmWidth + 9 <= r.right) {
156 xD = r.left + tx + 6;
159 if (rx >= bmp.bmWidth + 6) {
161 xD = r.right - bmp.bmWidth - 3;
171 hdcBitmap = CreateCompatibleDC (hdc);
172 SelectObject (hdcBitmap, phdi->hbm);
173 BitBlt (hdc, xD, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
174 DeleteDC (hdcBitmap);
177 if (phdi->fmt & HDF_IMAGE) {
180 /* ImageList_Draw (infoPtr->himl, phdi->iImage,...); */
183 if ((phdi->fmt & HDF_STRING) && (phdi->pszText)) {
184 oldBkMode = SetBkMode(hdc, TRANSPARENT);
187 SetTextColor (hdc, bHotTrack ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
188 DrawTextW (hdc, phdi->pszText, lstrlenW (phdi->pszText),
189 &r, uTextJustify|DT_VCENTER|DT_SINGLELINE);
190 if (oldBkMode != TRANSPARENT)
191 SetBkMode(hdc, oldBkMode);
195 return phdi->rect.right;
200 HEADER_Refresh (HWND hwnd, HDC hdc)
202 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
203 HFONT hFont, hOldFont;
208 /* get rect for the bar, adjusted for the border */
209 GetClientRect (hwnd, &rect);
211 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
212 hOldFont = SelectObject (hdc, hFont);
214 /* draw Background */
215 hbrBk = GetSysColorBrush(COLOR_3DFACE);
216 FillRect(hdc, &rect, hbrBk);
219 for (i = 0; i < infoPtr->uNumItem; i++) {
220 x = HEADER_DrawItem (hwnd, hdc, i, FALSE);
223 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
225 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS)
226 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
228 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
231 SelectObject (hdc, hOldFont);
236 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
238 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
239 HFONT hFont, hOldFont;
241 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
242 hOldFont = SelectObject (hdc, hFont);
243 HEADER_DrawItem (hwnd, hdc, iItem, FALSE);
244 SelectObject (hdc, hOldFont);
249 HEADER_SetItemBounds (HWND hwnd)
251 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
256 if (infoPtr->uNumItem == 0)
259 GetClientRect (hwnd, &rect);
262 for (i = 0; i < infoPtr->uNumItem; i++) {
263 phdi = &infoPtr->items[i];
264 phdi->rect.top = rect.top;
265 phdi->rect.bottom = rect.bottom;
267 phdi->rect.right = phdi->rect.left + phdi->cxy;
268 x = phdi->rect.right;
274 HEADER_ForceItemBounds (HWND hwnd, INT cy)
276 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
280 if (infoPtr->uNumItem == 0)
284 for (i = 0; i < infoPtr->uNumItem; i++) {
285 phdi = &infoPtr->items[i];
287 phdi->rect.bottom = cy;
289 phdi->rect.right = phdi->rect.left + phdi->cxy;
290 x = phdi->rect.right;
296 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
298 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
303 GetClientRect (hwnd, &rect);
307 if (PtInRect (&rect, *lpPt))
309 if (infoPtr->uNumItem == 0) {
310 *pFlags |= HHT_NOWHERE;
312 TRACE (header, "NOWHERE\n");
316 /* somewhere inside */
317 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
318 rect = infoPtr->items[iCount].rect;
319 width = rect.right - rect.left;
324 if (PtInRect (&rect, *lpPt)) {
325 if (width <= 2 * DIVIDER_WIDTH) {
326 *pFlags |= HHT_ONHEADER;
328 TRACE (header, "ON HEADER %d\n", iCount);
333 rcTest.right = rcTest.left + DIVIDER_WIDTH;
334 if (PtInRect (&rcTest, *lpPt)) {
336 *pFlags |= HHT_ONDIVOPEN;
338 TRACE (header, "ON DIVOPEN %d\n", *pItem);
342 *pFlags |= HHT_ONDIVIDER;
344 TRACE (header, "ON DIVIDER %d\n", *pItem);
350 rcTest.left = rcTest.right - DIVIDER_WIDTH;
351 if (PtInRect (&rcTest, *lpPt)) {
352 *pFlags |= HHT_ONDIVIDER;
354 TRACE (header, "ON DIVIDER %d\n", *pItem);
358 *pFlags |= HHT_ONHEADER;
360 TRACE (header, "ON HEADER %d\n", iCount);
365 /* check for last divider part (on nowhere) */
366 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
367 rect.left = rect.right;
368 rect.right += DIVIDER_WIDTH;
369 if (PtInRect (&rect, *lpPt)) {
371 *pFlags |= HHT_ONDIVOPEN;
372 *pItem = infoPtr->uNumItem - 1;
373 TRACE (header, "ON DIVOPEN %d\n", *pItem);
377 *pFlags |= HHT_ONDIVIDER;
378 *pItem = infoPtr->uNumItem-1;
379 TRACE (header, "ON DIVIDER %d\n", *pItem);
384 *pFlags |= HHT_NOWHERE;
386 TRACE (header, "NOWHERE\n");
391 if (lpPt->x < rect.left) {
392 TRACE (header, "TO LEFT\n");
393 *pFlags |= HHT_TOLEFT;
395 else if (lpPt->x > rect.right) {
396 TRACE (header, "TO LEFT\n");
397 *pFlags |= HHT_TORIGHT;
400 if (lpPt->y < rect.top) {
401 TRACE (header, "ABOVE\n");
402 *pFlags |= HHT_ABOVE;
404 else if (lpPt->y > rect.bottom) {
405 TRACE (header, "BELOW\n");
406 *pFlags |= HHT_BELOW;
411 TRACE (header, "flags=0x%X\n", *pFlags);
417 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
423 GetClientRect (hwnd, &rect);
425 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
426 oldRop = SetROP2 (hdc, R2_XORPEN);
427 MoveToEx (hdc, x, rect.top, NULL);
428 LineTo (hdc, x, rect.bottom);
429 SetROP2 (hdc, oldRop);
430 SelectObject (hdc, hOldPen);
435 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
439 nmhdr.hwndFrom = hwnd;
440 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
443 return (BOOL)SendMessageA (GetParent (hwnd), WM_NOTIFY,
444 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
449 HEADER_SendHeaderNotify (HWND hwnd, UINT code, INT iItem)
451 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
455 nmhdr.hdr.hwndFrom = hwnd;
456 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
457 nmhdr.hdr.code = code;
460 nmhdr.pitem = &nmitem;
462 nmitem.cxy = infoPtr->items[iItem].cxy;
463 nmitem.hbm = infoPtr->items[iItem].hbm;
464 nmitem.pszText = NULL;
465 nmitem.cchTextMax = 0;
466 /* nmitem.pszText = infoPtr->items[iItem].pszText; */
467 /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
468 nmitem.fmt = infoPtr->items[iItem].fmt;
469 nmitem.lParam = infoPtr->items[iItem].lParam;
470 nmitem.iOrder = infoPtr->items[iItem].iOrder;
471 nmitem.iImage = infoPtr->items[iItem].iImage;
473 return (BOOL)SendMessageA (GetParent (hwnd), WM_NOTIFY,
474 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
479 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
483 nmhdr.hdr.hwndFrom = hwnd;
484 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
485 nmhdr.hdr.code = code;
490 return (BOOL)SendMessageA (GetParent (hwnd), WM_NOTIFY,
491 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
496 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
498 FIXME (header, "empty stub!\n");
504 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
506 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
507 INT iItem = (INT)wParam;
510 TRACE(header, "[iItem=%d]\n", iItem);
512 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
515 if (infoPtr->uNumItem == 1) {
516 TRACE(header, "Simple delete!\n");
517 if (infoPtr->items[0].pszText)
518 COMCTL32_Free (infoPtr->items[0].pszText);
519 COMCTL32_Free (infoPtr->items);
521 infoPtr->uNumItem = 0;
524 HEADER_ITEM *oldItems = infoPtr->items;
525 TRACE(header, "Complex delete! [iItem=%d]\n", iItem);
527 if (infoPtr->items[iItem].pszText)
528 COMCTL32_Free (infoPtr->items[iItem].pszText);
531 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
532 /* pre delete copy */
534 memcpy (&infoPtr->items[0], &oldItems[0],
535 iItem * sizeof(HEADER_ITEM));
538 /* post delete copy */
539 if (iItem < infoPtr->uNumItem) {
540 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
541 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
544 COMCTL32_Free (oldItems);
547 HEADER_SetItemBounds (hwnd);
550 HEADER_Refresh (hwnd, hdc);
551 ReleaseDC (hwnd, hdc);
558 HEADER_GetImageList (HWND hwnd)
560 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
562 return (LRESULT)infoPtr->himl;
567 HEADER_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
569 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
570 HDITEMA *phdi = (HDITEMA*)lParam;
571 INT nItem = (INT)wParam;
576 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
579 TRACE (header, "[nItem=%d]\n", nItem);
584 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
585 if (phdi->mask & HDI_BITMAP)
586 phdi->hbm = lpItem->hbm;
588 if (phdi->mask & HDI_FORMAT)
589 phdi->fmt = lpItem->fmt;
591 if (phdi->mask & HDI_WIDTH)
592 phdi->cxy = lpItem->cxy;
594 if (phdi->mask & HDI_LPARAM)
595 phdi->lParam = lpItem->lParam;
597 if (phdi->mask & HDI_TEXT) {
598 if (lpItem->pszText != LPSTR_TEXTCALLBACKW)
599 lstrcpynWtoA (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
601 phdi->pszText = LPSTR_TEXTCALLBACKA;
604 if (phdi->mask & HDI_IMAGE)
605 phdi->iImage = lpItem->iImage;
607 if (phdi->mask & HDI_ORDER)
608 phdi->iOrder = lpItem->iOrder;
615 HEADER_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
617 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
618 HDITEMW *phdi = (HDITEMW*)lParam;
619 INT nItem = (INT)wParam;
624 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
627 TRACE (header, "[nItem=%d]\n", nItem);
632 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
633 if (phdi->mask & HDI_BITMAP)
634 phdi->hbm = lpItem->hbm;
636 if (phdi->mask & HDI_FORMAT)
637 phdi->fmt = lpItem->fmt;
639 if (phdi->mask & HDI_WIDTH)
640 phdi->cxy = lpItem->cxy;
642 if (phdi->mask & HDI_LPARAM)
643 phdi->lParam = lpItem->lParam;
645 if (phdi->mask & HDI_TEXT) {
646 if (lpItem->pszText != LPSTR_TEXTCALLBACKW)
647 lstrcpynW (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
649 phdi->pszText = LPSTR_TEXTCALLBACKW;
652 if (phdi->mask & HDI_IMAGE)
653 phdi->iImage = lpItem->iImage;
655 if (phdi->mask & HDI_ORDER)
656 phdi->iOrder = lpItem->iOrder;
662 __inline__ static LRESULT
663 HEADER_GetItemCount (HWND hwnd)
665 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
666 return infoPtr->uNumItem;
671 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
673 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
674 INT iItem = (INT)wParam;
675 LPRECT lpRect = (LPRECT)lParam;
677 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
680 lpRect->left = infoPtr->items[iItem].rect.left;
681 lpRect->right = infoPtr->items[iItem].rect.right;
682 lpRect->top = infoPtr->items[iItem].rect.top;
683 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
689 /* << HEADER_GetOrderArray >> */
692 __inline__ static LRESULT
693 HEADER_GetUnicodeFormat (HWND hwnd)
695 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
696 return infoPtr->bUnicode;
701 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
703 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
705 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
712 HEADER_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
714 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
715 HDITEMA *phdi = (HDITEMA*)lParam;
716 INT nItem = (INT)wParam;
721 if ((phdi == NULL) || (nItem < 0))
724 if (nItem > infoPtr->uNumItem)
725 nItem = infoPtr->uNumItem;
727 if (infoPtr->uNumItem == 0) {
728 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
732 HEADER_ITEM *oldItems = infoPtr->items;
735 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
737 memcpy (&infoPtr->items[1], &oldItems[0],
738 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
742 /* pre insert copy */
744 memcpy (&infoPtr->items[0], &oldItems[0],
745 nItem * sizeof(HEADER_ITEM));
748 /* post insert copy */
749 if (nItem < infoPtr->uNumItem - 1) {
750 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
751 (infoPtr->uNumItem - nItem) * sizeof(HEADER_ITEM));
755 COMCTL32_Free (oldItems);
758 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
759 lpItem->bDown = FALSE;
761 if (phdi->mask & HDI_WIDTH)
762 lpItem->cxy = phdi->cxy;
764 if (phdi->mask & HDI_TEXT) {
765 if (!phdi->pszText) /* null pointer check */
767 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
768 len = lstrlenA (phdi->pszText);
769 lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
770 lstrcpyAtoW (lpItem->pszText, phdi->pszText);
773 lpItem->pszText = LPSTR_TEXTCALLBACKW;
776 if (phdi->mask & HDI_FORMAT)
777 lpItem->fmt = phdi->fmt;
779 if (lpItem->fmt == 0)
780 lpItem->fmt = HDF_LEFT;
782 if (phdi->mask & HDI_BITMAP)
783 lpItem->hbm = phdi->hbm;
785 if (phdi->mask & HDI_LPARAM)
786 lpItem->lParam = phdi->lParam;
788 if (phdi->mask & HDI_IMAGE)
789 lpItem->iImage = phdi->iImage;
791 if (phdi->mask & HDI_ORDER)
792 lpItem->iOrder = phdi->iOrder;
794 HEADER_SetItemBounds (hwnd);
797 HEADER_Refresh (hwnd, hdc);
798 ReleaseDC (hwnd, hdc);
805 HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
807 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
808 HDITEMW *phdi = (HDITEMW*)lParam;
809 INT nItem = (INT)wParam;
814 if ((phdi == NULL) || (nItem < 0))
817 if (nItem > infoPtr->uNumItem)
818 nItem = infoPtr->uNumItem;
820 if (infoPtr->uNumItem == 0) {
821 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
825 HEADER_ITEM *oldItems = infoPtr->items;
828 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
829 /* pre insert copy */
831 memcpy (&infoPtr->items[0], &oldItems[0],
832 nItem * sizeof(HEADER_ITEM));
835 /* post insert copy */
836 if (nItem < infoPtr->uNumItem - 1) {
837 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
838 (infoPtr->uNumItem - nItem) * sizeof(HEADER_ITEM));
841 COMCTL32_Free (oldItems);
844 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
845 lpItem->bDown = FALSE;
847 if (phdi->mask & HDI_WIDTH)
848 lpItem->cxy = phdi->cxy;
850 if (phdi->mask & HDI_TEXT) {
851 if (!phdi->pszText) /* null pointer check */
853 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
854 len = lstrlenW (phdi->pszText);
855 lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
856 lstrcpyW (lpItem->pszText, phdi->pszText);
859 lpItem->pszText = LPSTR_TEXTCALLBACKW;
862 if (phdi->mask & HDI_FORMAT)
863 lpItem->fmt = phdi->fmt;
865 if (lpItem->fmt == 0)
866 lpItem->fmt = HDF_LEFT;
868 if (phdi->mask & HDI_BITMAP)
869 lpItem->hbm = phdi->hbm;
871 if (phdi->mask & HDI_LPARAM)
872 lpItem->lParam = phdi->lParam;
874 if (phdi->mask & HDI_IMAGE)
875 lpItem->iImage = phdi->iImage;
877 if (phdi->mask & HDI_ORDER)
878 lpItem->iOrder = phdi->iOrder;
880 HEADER_SetItemBounds (hwnd);
883 HEADER_Refresh (hwnd, hdc);
884 ReleaseDC (hwnd, hdc);
891 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
893 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
894 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
896 lpLayout->pwpos->hwnd = hwnd;
897 lpLayout->pwpos->hwndInsertAfter = 0;
898 lpLayout->pwpos->x = lpLayout->prc->left;
899 lpLayout->pwpos->y = lpLayout->prc->top;
900 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
901 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_HIDDEN)
902 lpLayout->pwpos->cy = 0;
904 lpLayout->pwpos->cy = infoPtr->nHeight;
905 lpLayout->pwpos->flags = SWP_NOZORDER;
907 TRACE (header, "Layout x=%d y=%d cx=%d cy=%d\n",
908 lpLayout->pwpos->x, lpLayout->pwpos->y,
909 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
911 HEADER_ForceItemBounds (hwnd, lpLayout->pwpos->cy);
914 #ifdef __HDM_LAYOUT_HACK__
915 MoveWindow (lpLayout->pwpos->hwnd, lpLayout->pwpos->x, lpLayout->pwpos->y,
916 lpLayout->pwpos->cx, lpLayout->pwpos->cy, TRUE);
924 HEADER_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
926 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
929 himlOld = infoPtr->himl;
930 infoPtr->himl = (HIMAGELIST)lParam;
932 /* FIXME: Refresh needed??? */
934 return (LRESULT)himlOld;
939 HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
941 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
942 HDITEMA *phdi = (HDITEMA*)lParam;
943 INT nItem = (INT)wParam;
949 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
952 TRACE (header, "[nItem=%d]\n", nItem);
954 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem))
957 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
958 if (phdi->mask & HDI_BITMAP)
959 lpItem->hbm = phdi->hbm;
961 if (phdi->mask & HDI_FORMAT)
962 lpItem->fmt = phdi->fmt;
964 if (phdi->mask & HDI_LPARAM)
965 lpItem->lParam = phdi->lParam;
967 if (phdi->mask & HDI_TEXT) {
968 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
969 if (lpItem->pszText) {
970 COMCTL32_Free (lpItem->pszText);
971 lpItem->pszText = NULL;
974 INT len = lstrlenA (phdi->pszText);
975 lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
976 lstrcpyAtoW (lpItem->pszText, phdi->pszText);
980 lpItem->pszText = LPSTR_TEXTCALLBACKW;
983 if (phdi->mask & HDI_WIDTH)
984 lpItem->cxy = phdi->cxy;
986 if (phdi->mask & HDI_IMAGE)
987 lpItem->iImage = phdi->iImage;
989 if (phdi->mask & HDI_ORDER)
990 lpItem->iOrder = phdi->iOrder;
992 HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem);
994 HEADER_SetItemBounds (hwnd);
996 HEADER_Refresh (hwnd, hdc);
997 ReleaseDC (hwnd, hdc);
1004 HEADER_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1006 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1007 HDITEMW *phdi = (HDITEMW*)lParam;
1008 INT nItem = (INT)wParam;
1009 HEADER_ITEM *lpItem;
1014 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1017 TRACE (header, "[nItem=%d]\n", nItem);
1019 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem))
1022 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
1023 if (phdi->mask & HDI_BITMAP)
1024 lpItem->hbm = phdi->hbm;
1026 if (phdi->mask & HDI_FORMAT)
1027 lpItem->fmt = phdi->fmt;
1029 if (phdi->mask & HDI_LPARAM)
1030 lpItem->lParam = phdi->lParam;
1032 if (phdi->mask & HDI_TEXT) {
1033 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1034 if (lpItem->pszText) {
1035 COMCTL32_Free (lpItem->pszText);
1036 lpItem->pszText = NULL;
1038 if (phdi->pszText) {
1039 INT len = lstrlenW (phdi->pszText);
1040 lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1041 lstrcpyW (lpItem->pszText, phdi->pszText);
1045 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1048 if (phdi->mask & HDI_WIDTH)
1049 lpItem->cxy = phdi->cxy;
1051 if (phdi->mask & HDI_IMAGE)
1052 lpItem->iImage = phdi->iImage;
1054 if (phdi->mask & HDI_ORDER)
1055 lpItem->iOrder = phdi->iOrder;
1057 HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem);
1059 HEADER_SetItemBounds (hwnd);
1061 HEADER_Refresh (hwnd, hdc);
1062 ReleaseDC (hwnd, hdc);
1068 /* << HEADER_SetOrderArray >> */
1071 __inline__ static LRESULT
1072 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1074 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1075 BOOL bTemp = infoPtr->bUnicode;
1077 infoPtr->bUnicode = (BOOL)wParam;
1084 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1086 HEADER_INFO *infoPtr;
1091 infoPtr = (HEADER_INFO *)COMCTL32_Alloc (sizeof(HEADER_INFO));
1092 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1094 infoPtr->uNumItem = 0;
1095 infoPtr->nHeight = 20;
1098 infoPtr->hcurArrow = LoadCursorA (0, IDC_ARROWA);
1099 infoPtr->hcurDivider = LoadCursorA (0, IDC_SIZEWEA);
1100 infoPtr->hcurDivopen = LoadCursorA (0, IDC_SIZENSA);
1101 infoPtr->bPressed = FALSE;
1102 infoPtr->bTracking = FALSE;
1103 infoPtr->iMoveItem = 0;
1105 infoPtr->iHotItem = -1;
1106 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1109 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1110 GetTextMetricsA (hdc, &tm);
1111 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1112 SelectObject (hdc, hOldFont);
1120 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1122 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1123 HEADER_ITEM *lpItem;
1126 if (infoPtr->items) {
1127 lpItem = (HEADER_ITEM*)infoPtr->items;
1128 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1129 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
1130 COMCTL32_Free (lpItem->pszText);
1132 COMCTL32_Free (infoPtr->items);
1136 ImageList_Destroy (infoPtr->himl);
1138 COMCTL32_Free (infoPtr);
1144 static __inline__ LRESULT
1145 HEADER_GetFont (HWND hwnd)
1147 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1149 return (LRESULT)infoPtr->hFont;
1154 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1160 pt.x = (INT)LOWORD(lParam);
1161 pt.y = (INT)HIWORD(lParam);
1162 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1164 if ((GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1165 HEADER_SendHeaderNotify (hwnd, HDN_ITEMDBLCLICKA, nItem);
1166 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1167 HEADER_SendHeaderNotify (hwnd, HDN_DIVIDERDBLCLICKA, nItem);
1174 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1176 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1177 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1183 pt.x = (INT)LOWORD(lParam);
1184 pt.y = (INT)HIWORD(lParam);
1185 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1187 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1189 infoPtr->bCaptured = TRUE;
1190 infoPtr->bPressed = TRUE;
1191 infoPtr->iMoveItem = nItem;
1193 infoPtr->items[nItem].bDown = TRUE;
1195 /* Send WM_CUSTOMDRAW */
1197 HEADER_RefreshItem (hwnd, hdc, nItem);
1198 ReleaseDC (hwnd, hdc);
1200 TRACE (header, "Pressed item %d!\n", nItem);
1202 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1203 if (!(HEADER_SendHeaderNotify (hwnd, HDN_BEGINTRACKA, nItem))) {
1205 infoPtr->bCaptured = TRUE;
1206 infoPtr->bTracking = TRUE;
1207 infoPtr->iMoveItem = nItem;
1208 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1209 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1211 if (!(dwStyle & HDS_FULLDRAG)) {
1212 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1214 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1215 ReleaseDC (hwnd, hdc);
1218 TRACE (header, "Begin tracking item %d!\n", nItem);
1227 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1229 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1230 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1236 pt.x = (INT)LOWORD(lParam);
1237 pt.y = (INT)HIWORD(lParam);
1238 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1240 if (infoPtr->bPressed) {
1241 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1242 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1244 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1245 ReleaseDC (hwnd, hdc);
1247 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1249 TRACE (header, "Released item %d!\n", infoPtr->iMoveItem);
1250 infoPtr->bPressed = FALSE;
1252 else if (infoPtr->bTracking) {
1253 TRACE (header, "End tracking item %d!\n", infoPtr->iMoveItem);
1254 infoPtr->bTracking = FALSE;
1256 HEADER_SendHeaderNotify (hwnd, HDN_ENDTRACKA, infoPtr->iMoveItem);
1258 if (!(dwStyle & HDS_FULLDRAG)) {
1260 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1261 ReleaseDC (hwnd, hdc);
1262 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem))
1263 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1265 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1268 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1269 HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem);
1272 HEADER_SetItemBounds (hwnd);
1274 HEADER_Refresh (hwnd, hdc);
1275 ReleaseDC (hwnd, hdc);
1279 if (infoPtr->bCaptured) {
1280 infoPtr->bCaptured = FALSE;
1282 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1290 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1292 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1293 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1299 pt.x = (INT)LOWORD(lParam);
1300 pt.y = (INT)HIWORD(lParam);
1301 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1303 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1304 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1305 infoPtr->iHotItem = nItem;
1307 infoPtr->iHotItem = -1;
1309 HEADER_Refresh (hwnd, hdc);
1310 ReleaseDC (hwnd, hdc);
1313 if (infoPtr->bCaptured) {
1314 if (infoPtr->bPressed) {
1315 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1316 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1318 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1320 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1321 ReleaseDC (hwnd, hdc);
1323 TRACE (header, "Moving pressed item %d!\n", infoPtr->iMoveItem);
1325 else if (infoPtr->bTracking) {
1326 if (dwStyle & HDS_FULLDRAG) {
1327 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem))
1328 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1330 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1333 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1334 HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA,
1335 infoPtr->iMoveItem);
1337 HEADER_SetItemBounds (hwnd);
1339 HEADER_Refresh (hwnd, hdc);
1340 ReleaseDC (hwnd, hdc);
1344 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1345 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1346 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1347 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1348 infoPtr->items[infoPtr->iMoveItem].cxy =
1349 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1350 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1351 ReleaseDC (hwnd, hdc);
1354 HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem);
1355 TRACE (header, "Tracking item %d!\n", infoPtr->iMoveItem);
1359 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1360 FIXME (header, "hot track support!\n");
1368 HEADER_Paint (HWND hwnd, WPARAM wParam)
1373 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1374 HEADER_Refresh (hwnd, hdc);
1376 EndPaint (hwnd, &ps);
1382 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1384 return HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1389 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1391 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1396 TRACE (header, "code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1399 ScreenToClient (hwnd, &pt);
1401 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1403 if (flags == HHT_ONDIVIDER)
1404 SetCursor (infoPtr->hcurDivider);
1405 else if (flags == HHT_ONDIVOPEN)
1406 SetCursor (infoPtr->hcurDivopen);
1408 SetCursor (infoPtr->hcurArrow);
1415 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1417 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1419 HFONT hFont, hOldFont;
1422 infoPtr->hFont = (HFONT)wParam;
1424 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1427 hOldFont = SelectObject (hdc, hFont);
1428 GetTextMetricsA (hdc, &tm);
1429 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1430 SelectObject (hdc, hOldFont);
1434 HEADER_ForceItemBounds (hwnd, infoPtr->nHeight);
1436 HEADER_Refresh (hwnd, hdc);
1437 ReleaseDC (hwnd, hdc);
1445 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1448 case HDM_CREATEDRAGIMAGE:
1449 return HEADER_CreateDragImage (hwnd, wParam);
1451 case HDM_DELETEITEM:
1452 return HEADER_DeleteItem (hwnd, wParam);
1454 case HDM_GETIMAGELIST:
1455 return HEADER_GetImageList (hwnd);
1458 return HEADER_GetItemA (hwnd, wParam, lParam);
1461 return HEADER_GetItemW (hwnd, wParam, lParam);
1463 case HDM_GETITEMCOUNT:
1464 return HEADER_GetItemCount (hwnd);
1466 case HDM_GETITEMRECT:
1467 return HEADER_GetItemRect (hwnd, wParam, lParam);
1469 /* case HDM_GETORDERARRAY: */
1471 case HDM_GETUNICODEFORMAT:
1472 return HEADER_GetUnicodeFormat (hwnd);
1475 return HEADER_HitTest (hwnd, wParam, lParam);
1477 case HDM_INSERTITEMA:
1478 return HEADER_InsertItemA (hwnd, wParam, lParam);
1480 case HDM_INSERTITEMW:
1481 return HEADER_InsertItemW (hwnd, wParam, lParam);
1484 return HEADER_Layout (hwnd, wParam, lParam);
1486 case HDM_SETIMAGELIST:
1487 return HEADER_SetImageList (hwnd, wParam, lParam);
1490 return HEADER_SetItemA (hwnd, wParam, lParam);
1493 return HEADER_SetItemW (hwnd, wParam, lParam);
1495 /* case HDM_SETORDERARRAY: */
1497 case HDM_SETUNICODEFORMAT:
1498 return HEADER_SetUnicodeFormat (hwnd, wParam);
1502 return HEADER_Create (hwnd, wParam, lParam);
1505 return HEADER_Destroy (hwnd, wParam, lParam);
1511 return DLGC_WANTTAB | DLGC_WANTARROWS;
1514 return HEADER_GetFont (hwnd);
1516 case WM_LBUTTONDBLCLK:
1517 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1519 case WM_LBUTTONDOWN:
1520 return HEADER_LButtonDown (hwnd, wParam, lParam);
1523 return HEADER_LButtonUp (hwnd, wParam, lParam);
1526 return HEADER_MouseMove (hwnd, wParam, lParam);
1528 /* case WM_NOTIFYFORMAT: */
1531 return HEADER_Paint (hwnd, wParam);
1534 return HEADER_RButtonUp (hwnd, wParam, lParam);
1537 return HEADER_SetCursor (hwnd, wParam, lParam);
1540 return HEADER_SetFont (hwnd, wParam, lParam);
1544 ERR (header, "unknown msg %04x wp=%04x lp=%08lx\n",
1545 msg, wParam, lParam );
1546 return DefWindowProcA (hwnd, msg, wParam, lParam);
1553 HEADER_Register (VOID)
1557 if (GlobalFindAtomA (WC_HEADERA)) return;
1559 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1560 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1561 wndClass.lpfnWndProc = (WNDPROC)HEADER_WindowProc;
1562 wndClass.cbClsExtra = 0;
1563 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1564 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
1565 wndClass.lpszClassName = WC_HEADERA;
1567 RegisterClassA (&wndClass);
1572 HEADER_Unregister (VOID)
1574 if (GlobalFindAtomA (WC_HEADERA))
1575 UnregisterClassA (WC_HEADERA, (HINSTANCE)NULL);