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).
14 * - Use notification format
17 * - Little flaw when drawing a bitmap on the right side of the text.
23 #include "wine/unicode.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 INT nNotifyFormat; /* format used for WM_NOTIFY messages */
50 UINT uNumItem; /* number of items (columns) */
51 INT nHeight; /* height of the header (pixels) */
52 HFONT hFont; /* handle to the current font */
53 HCURSOR hcurArrow; /* handle to the arrow cursor */
54 HCURSOR hcurDivider; /* handle to a cursor (used over dividers) <-|-> */
55 HCURSOR hcurDivopen; /* handle to a cursor (used over dividers) <-||-> */
56 BOOL bCaptured; /* Is the mouse captured? */
57 BOOL bPressed; /* Is a header item pressed (down)? */
58 BOOL bTracking; /* Is in tracking mode? */
59 BOOL bUnicode; /* Unicode flag */
60 INT iMoveItem; /* index of tracked item. (Tracking mode) */
61 INT xTrackOffset; /* distance between the right side of the tracked item and the cursor */
62 INT xOldTrack; /* track offset (see above) after the last WM_MOUSEMOVE */
63 INT nOldWidth; /* width of a sizing item after the last WM_MOUSEMOVE */
64 INT iHotItem; /* index of hot item (cursor is over this item) */
66 HIMAGELIST himl; /* handle to a image list (may be 0) */
67 HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */
68 BOOL bRectsValid; /* validity flag for bounding rectangles */
73 #define DIVIDER_WIDTH 10
75 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongA(hwnd,0))
79 HEADER_IndexToOrder (HWND hwnd, INT iItem)
81 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
82 HEADER_ITEM *lpItem = (HEADER_ITEM*)&infoPtr->items[iItem];
83 return lpItem->iOrder;
88 HEADER_OrderToIndex(HWND hwnd, WPARAM wParam)
90 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
91 INT i,iorder = (INT)wParam;
94 if ((iorder <0) || iorder >infoPtr->uNumItem)
96 for (i=0; i<infoPtr->uNumItem; i++)
97 if (HEADER_IndexToOrder(hwnd,i) == iorder)
103 HEADER_SetItemBounds (HWND hwnd)
105 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
110 infoPtr->bRectsValid = TRUE;
112 if (infoPtr->uNumItem == 0)
115 GetClientRect (hwnd, &rect);
118 for (i = 0; i < infoPtr->uNumItem; i++) {
119 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
120 phdi->rect.top = rect.top;
121 phdi->rect.bottom = rect.bottom;
123 phdi->rect.right = phdi->rect.left + phdi->cxy;
124 x = phdi->rect.right;
129 HEADER_Size (HWND hwnd, WPARAM wParam)
131 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
133 infoPtr->bRectsValid = FALSE;
140 HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
142 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
143 HEADER_ITEM *phdi = &infoPtr->items[iItem];
147 if (!infoPtr->bRectsValid)
148 HEADER_SetItemBounds(hwnd);
151 if (r.right - r.left == 0)
152 return phdi->rect.right;
154 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) {
156 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
157 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
162 DrawEdge (hdc, &r, EDGE_RAISED,
163 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
166 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
168 if (phdi->fmt & HDF_OWNERDRAW) {
170 dis.CtlType = ODT_HEADER;
171 dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
173 dis.itemAction = ODA_DRAWENTIRE;
174 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
178 dis.itemData = phdi->lParam;
179 SendMessageA (GetParent (hwnd), WM_DRAWITEM,
180 (WPARAM)dis.CtlID, (LPARAM)&dis);
183 UINT uTextJustify = DT_LEFT;
185 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
186 uTextJustify = DT_CENTER;
187 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
188 uTextJustify = DT_RIGHT;
190 if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
193 INT yD, yS, cx, cy, rx, ry;
195 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
197 ry = r.bottom - r.top;
198 rx = r.right - r.left;
200 if (ry >= bmp.bmHeight) {
202 yD = r.top + (ry - bmp.bmHeight) / 2;
208 yS = (bmp.bmHeight - ry) / 2;
212 if (rx >= bmp.bmWidth + 6) {
219 hdcBitmap = CreateCompatibleDC (hdc);
220 SelectObject (hdcBitmap, phdi->hbm);
221 BitBlt (hdc, r.left + 3, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
222 DeleteDC (hdcBitmap);
224 r.left += (bmp.bmWidth + 3);
228 if ((phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
231 INT xD, yD, yS, cx, cy, rx, ry, tx;
234 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
237 DrawTextW (hdc, phdi->pszText, -1,
238 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
239 tx = textRect.right - textRect.left;
240 ry = r.bottom - r.top;
241 rx = r.right - r.left;
243 if (ry >= bmp.bmHeight) {
245 yD = r.top + (ry - bmp.bmHeight) / 2;
251 yS = (bmp.bmHeight - ry) / 2;
255 if (r.left + tx + bmp.bmWidth + 9 <= r.right) {
257 xD = r.left + tx + 6;
260 if (rx >= bmp.bmWidth + 6) {
262 xD = r.right - bmp.bmWidth - 3;
272 hdcBitmap = CreateCompatibleDC (hdc);
273 SelectObject (hdcBitmap, phdi->hbm);
274 BitBlt (hdc, xD, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
275 DeleteDC (hdcBitmap);
278 if (phdi->fmt & HDF_IMAGE) {
280 /* FIXME: (r.bottom- (infoPtr->himl->cy))/2 should horicontal center the image
281 It looks like it doesn't work as expected*/
282 ImageList_Draw (infoPtr->himl, phdi->iImage,hdc,r.left, (r.bottom- (infoPtr->himl->cy))/2,NULL);
283 r.left += infoPtr->himl->cx;
286 if (((phdi->fmt & HDF_STRING)
287 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
288 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
289 && (phdi->pszText)) {
290 oldBkMode = SetBkMode(hdc, TRANSPARENT);
293 SetTextColor (hdc, (bHotTrack) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
294 DrawTextW (hdc, phdi->pszText, -1,
295 &r, uTextJustify|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
296 if (oldBkMode != TRANSPARENT)
297 SetBkMode(hdc, oldBkMode);
301 return phdi->rect.right;
306 HEADER_Refresh (HWND hwnd, HDC hdc)
308 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
309 HFONT hFont, hOldFont;
314 /* get rect for the bar, adjusted for the border */
315 GetClientRect (hwnd, &rect);
317 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
318 hOldFont = SelectObject (hdc, hFont);
320 /* draw Background */
321 hbrBk = GetSysColorBrush(COLOR_3DFACE);
322 FillRect(hdc, &rect, hbrBk);
325 for (i = 0; i < infoPtr->uNumItem; i++) {
326 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i), FALSE);
329 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
331 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS)
332 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
334 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
337 SelectObject (hdc, hOldFont);
342 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
344 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
345 HFONT hFont, hOldFont;
347 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
348 hOldFont = SelectObject (hdc, hFont);
349 HEADER_DrawItem (hwnd, hdc, iItem, FALSE);
350 SelectObject (hdc, hOldFont);
355 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
357 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
362 GetClientRect (hwnd, &rect);
366 if (PtInRect (&rect, *lpPt))
368 if (infoPtr->uNumItem == 0) {
369 *pFlags |= HHT_NOWHERE;
375 /* somewhere inside */
376 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
377 rect = infoPtr->items[iCount].rect;
378 width = rect.right - rect.left;
383 if (PtInRect (&rect, *lpPt)) {
384 if (width <= 2 * DIVIDER_WIDTH) {
385 *pFlags |= HHT_ONHEADER;
387 TRACE("ON HEADER %d\n", iCount);
392 rcTest.right = rcTest.left + DIVIDER_WIDTH;
393 if (PtInRect (&rcTest, *lpPt)) {
395 *pFlags |= HHT_ONDIVOPEN;
397 TRACE("ON DIVOPEN %d\n", *pItem);
401 *pFlags |= HHT_ONDIVIDER;
403 TRACE("ON DIVIDER %d\n", *pItem);
409 rcTest.left = rcTest.right - DIVIDER_WIDTH;
410 if (PtInRect (&rcTest, *lpPt)) {
411 *pFlags |= HHT_ONDIVIDER;
413 TRACE("ON DIVIDER %d\n", *pItem);
417 *pFlags |= HHT_ONHEADER;
419 TRACE("ON HEADER %d\n", iCount);
424 /* check for last divider part (on nowhere) */
425 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
426 rect.left = rect.right;
427 rect.right += DIVIDER_WIDTH;
428 if (PtInRect (&rect, *lpPt)) {
430 *pFlags |= HHT_ONDIVOPEN;
431 *pItem = infoPtr->uNumItem - 1;
432 TRACE("ON DIVOPEN %d\n", *pItem);
436 *pFlags |= HHT_ONDIVIDER;
437 *pItem = infoPtr->uNumItem-1;
438 TRACE("ON DIVIDER %d\n", *pItem);
443 *pFlags |= HHT_NOWHERE;
450 if (lpPt->x < rect.left) {
452 *pFlags |= HHT_TOLEFT;
454 else if (lpPt->x > rect.right) {
456 *pFlags |= HHT_TORIGHT;
459 if (lpPt->y < rect.top) {
461 *pFlags |= HHT_ABOVE;
463 else if (lpPt->y > rect.bottom) {
465 *pFlags |= HHT_BELOW;
470 TRACE("flags=0x%X\n", *pFlags);
476 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
482 GetClientRect (hwnd, &rect);
484 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
485 oldRop = SetROP2 (hdc, R2_XORPEN);
486 MoveToEx (hdc, x, rect.top, NULL);
487 LineTo (hdc, x, rect.bottom);
488 SetROP2 (hdc, oldRop);
489 SelectObject (hdc, hOldPen);
494 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
496 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
499 nmhdr.hwndFrom = hwnd;
500 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
503 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
504 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
508 HEADER_SendHeaderNotify (HWND hwnd, UINT code, INT iItem, INT mask)
510 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
514 nmhdr.hdr.hwndFrom = hwnd;
515 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
516 nmhdr.hdr.code = code;
519 nmhdr.pitem = &nmitem;
521 nmitem.cxy = infoPtr->items[iItem].cxy;
522 nmitem.hbm = infoPtr->items[iItem].hbm;
523 nmitem.pszText = NULL;
524 nmitem.cchTextMax = 0;
525 /* nmitem.pszText = infoPtr->items[iItem].pszText; */
526 /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
527 nmitem.fmt = infoPtr->items[iItem].fmt;
528 nmitem.lParam = infoPtr->items[iItem].lParam;
529 nmitem.iOrder = infoPtr->items[iItem].iOrder;
530 nmitem.iImage = infoPtr->items[iItem].iImage;
532 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
533 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
538 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
540 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
543 nmhdr.hdr.hwndFrom = hwnd;
544 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
545 nmhdr.hdr.code = code;
550 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
551 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
556 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
558 FIXME("empty stub!\n");
564 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
566 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
567 INT iItem = (INT)wParam;
569 TRACE("[iItem=%d]\n", iItem);
571 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
574 if (infoPtr->uNumItem == 1) {
575 TRACE("Simple delete!\n");
576 if (infoPtr->items[0].pszText)
577 COMCTL32_Free (infoPtr->items[0].pszText);
578 COMCTL32_Free (infoPtr->items);
580 infoPtr->uNumItem = 0;
583 HEADER_ITEM *oldItems = infoPtr->items;
584 TRACE("Complex delete! [iItem=%d]\n", iItem);
586 if (infoPtr->items[iItem].pszText)
587 COMCTL32_Free (infoPtr->items[iItem].pszText);
590 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
591 /* pre delete copy */
593 memcpy (&infoPtr->items[0], &oldItems[0],
594 iItem * sizeof(HEADER_ITEM));
597 /* post delete copy */
598 if (iItem < infoPtr->uNumItem) {
599 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
600 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
603 COMCTL32_Free (oldItems);
606 HEADER_SetItemBounds (hwnd);
608 InvalidateRect(hwnd, NULL, FALSE);
615 HEADER_GetImageList (HWND hwnd)
617 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
619 return (LRESULT)infoPtr->himl;
624 HEADER_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
626 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
627 HDITEMA *phdi = (HDITEMA*)lParam;
628 INT nItem = (INT)wParam;
633 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
636 TRACE("[nItem=%d]\n", nItem);
641 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
642 if (phdi->mask & HDI_BITMAP)
643 phdi->hbm = lpItem->hbm;
645 if (phdi->mask & HDI_FORMAT)
646 phdi->fmt = lpItem->fmt;
648 if (phdi->mask & HDI_WIDTH)
649 phdi->cxy = lpItem->cxy;
651 if (phdi->mask & HDI_LPARAM)
652 phdi->lParam = lpItem->lParam;
654 if (phdi->mask & HDI_TEXT) {
655 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
657 WideCharToMultiByte (CP_ACP, 0, lpItem->pszText, -1,
658 phdi->pszText, phdi->cchTextMax, NULL, NULL);
663 phdi->pszText = LPSTR_TEXTCALLBACKA;
666 if (phdi->mask & HDI_IMAGE)
667 phdi->iImage = lpItem->iImage;
669 if (phdi->mask & HDI_ORDER)
670 phdi->iOrder = lpItem->iOrder;
677 HEADER_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
679 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
680 HDITEMW *phdi = (HDITEMW*)lParam;
681 INT nItem = (INT)wParam;
686 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
689 TRACE("[nItem=%d]\n", nItem);
694 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
695 if (phdi->mask & HDI_BITMAP)
696 phdi->hbm = lpItem->hbm;
698 if (phdi->mask & HDI_FORMAT)
699 phdi->fmt = lpItem->fmt;
701 if (phdi->mask & HDI_WIDTH)
702 phdi->cxy = lpItem->cxy;
704 if (phdi->mask & HDI_LPARAM)
705 phdi->lParam = lpItem->lParam;
707 if (phdi->mask & HDI_TEXT) {
708 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
710 lstrcpynW (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
715 phdi->pszText = LPSTR_TEXTCALLBACKW;
718 if (phdi->mask & HDI_IMAGE)
719 phdi->iImage = lpItem->iImage;
721 if (phdi->mask & HDI_ORDER)
722 phdi->iOrder = lpItem->iOrder;
728 inline static LRESULT
729 HEADER_GetItemCount (HWND hwnd)
731 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
732 return infoPtr->uNumItem;
737 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
739 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
740 INT iItem = (INT)wParam;
741 LPRECT lpRect = (LPRECT)lParam;
743 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
746 lpRect->left = infoPtr->items[iItem].rect.left;
747 lpRect->right = infoPtr->items[iItem].rect.right;
748 lpRect->top = infoPtr->items[iItem].rect.top;
749 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
756 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
759 LPINT order = (LPINT) lParam;
760 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
762 if ((int)wParam <infoPtr->uNumItem)
764 for (i=0; i<(int)wParam; i++)
765 *order++=HEADER_OrderToIndex(hwnd,i);
770 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
773 LPINT order = (LPINT) lParam;
774 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
777 if ((int)wParam <infoPtr->uNumItem)
779 for (i=0; i<(int)wParam; i++)
781 lpItem = (HEADER_ITEM*)&infoPtr->items[*order++];
784 infoPtr->bRectsValid=0;
785 InvalidateRect(hwnd, NULL, FALSE);
789 inline static LRESULT
790 HEADER_GetUnicodeFormat (HWND hwnd)
792 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
793 return infoPtr->bUnicode;
798 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
800 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
802 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
804 if (phti->flags == HHT_ONHEADER)
812 HEADER_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
814 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
815 HDITEMA *phdi = (HDITEMA*)lParam;
816 INT nItem = (INT)wParam;
820 if ((phdi == NULL) || (nItem < 0))
823 if (nItem > infoPtr->uNumItem)
824 nItem = infoPtr->uNumItem;
826 if (infoPtr->uNumItem == 0) {
827 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
831 HEADER_ITEM *oldItems = infoPtr->items;
834 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
836 memcpy (&infoPtr->items[1], &oldItems[0],
837 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
841 /* pre insert copy */
843 memcpy (&infoPtr->items[0], &oldItems[0],
844 nItem * sizeof(HEADER_ITEM));
847 /* post insert copy */
848 if (nItem < infoPtr->uNumItem - 1) {
849 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
850 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
854 COMCTL32_Free (oldItems);
857 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
858 lpItem->bDown = FALSE;
860 if (phdi->mask & HDI_WIDTH)
861 lpItem->cxy = phdi->cxy;
863 if (phdi->mask & HDI_TEXT) {
864 if (!phdi->pszText) /* null pointer check */
866 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
867 len = MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, NULL, 0);
868 lpItem->pszText = COMCTL32_Alloc( len*sizeof(WCHAR) );
869 MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, lpItem->pszText, len);
872 lpItem->pszText = LPSTR_TEXTCALLBACKW;
875 if (phdi->mask & HDI_FORMAT)
876 lpItem->fmt = phdi->fmt;
878 if (lpItem->fmt == 0)
879 lpItem->fmt = HDF_LEFT;
881 if (!(lpItem->fmt &HDF_STRING) && (phdi->mask & HDI_TEXT))
883 lpItem->fmt |= HDF_STRING;
885 if (phdi->mask & HDI_BITMAP)
886 lpItem->hbm = phdi->hbm;
888 if (phdi->mask & HDI_LPARAM)
889 lpItem->lParam = phdi->lParam;
891 if (phdi->mask & HDI_IMAGE)
892 lpItem->iImage = phdi->iImage;
894 if (phdi->mask & HDI_ORDER)
896 lpItem->iOrder = phdi->iOrder;
899 lpItem->iOrder=nItem;
902 HEADER_SetItemBounds (hwnd);
904 InvalidateRect(hwnd, NULL, FALSE);
911 HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
913 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
914 HDITEMW *phdi = (HDITEMW*)lParam;
915 INT nItem = (INT)wParam;
919 if ((phdi == NULL) || (nItem < 0))
922 if (nItem > infoPtr->uNumItem)
923 nItem = infoPtr->uNumItem;
925 if (infoPtr->uNumItem == 0) {
926 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
930 HEADER_ITEM *oldItems = infoPtr->items;
933 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
934 /* pre insert copy */
936 memcpy (&infoPtr->items[0], &oldItems[0],
937 nItem * sizeof(HEADER_ITEM));
940 /* post insert copy */
941 if (nItem < infoPtr->uNumItem - 1) {
942 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
943 (infoPtr->uNumItem - nItem) * sizeof(HEADER_ITEM));
946 COMCTL32_Free (oldItems);
949 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
950 lpItem->bDown = FALSE;
952 if (phdi->mask & HDI_WIDTH)
953 lpItem->cxy = phdi->cxy;
955 if (phdi->mask & HDI_TEXT) {
956 WCHAR wide_null_char = 0;
957 if (!phdi->pszText) /* null pointer check */
958 phdi->pszText = &wide_null_char;
959 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
960 len = strlenW (phdi->pszText);
961 lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
962 strcpyW (lpItem->pszText, phdi->pszText);
965 lpItem->pszText = LPSTR_TEXTCALLBACKW;
968 if (phdi->mask & HDI_FORMAT)
969 lpItem->fmt = phdi->fmt;
971 if (lpItem->fmt == 0)
972 lpItem->fmt = HDF_LEFT;
974 if (phdi->mask & HDI_BITMAP)
975 lpItem->hbm = phdi->hbm;
977 if (phdi->mask & HDI_LPARAM)
978 lpItem->lParam = phdi->lParam;
980 if (phdi->mask & HDI_IMAGE)
981 lpItem->iImage = phdi->iImage;
983 if (phdi->mask & HDI_ORDER)
985 lpItem->iOrder = phdi->iOrder;
988 lpItem->iOrder = nItem;
990 HEADER_SetItemBounds (hwnd);
992 InvalidateRect(hwnd, NULL, FALSE);
999 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
1001 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1002 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1004 lpLayout->pwpos->hwnd = hwnd;
1005 lpLayout->pwpos->hwndInsertAfter = 0;
1006 lpLayout->pwpos->x = lpLayout->prc->left;
1007 lpLayout->pwpos->y = lpLayout->prc->top;
1008 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1009 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_HIDDEN)
1010 lpLayout->pwpos->cy = 0;
1012 lpLayout->pwpos->cy = infoPtr->nHeight;
1013 lpLayout->prc->top += infoPtr->nHeight;
1015 lpLayout->pwpos->flags = SWP_NOZORDER;
1017 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1018 lpLayout->pwpos->x, lpLayout->pwpos->y,
1019 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1021 infoPtr->bRectsValid = FALSE;
1028 HEADER_SetImageList (HWND hwnd, WPARAM wParam, LPARAM lParam)
1030 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1033 himlOld = infoPtr->himl;
1034 infoPtr->himl = (HIMAGELIST)lParam;
1036 /* FIXME: Refresh needed??? */
1038 return (LRESULT)himlOld;
1043 HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1045 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1046 HDITEMA *phdi = (HDITEMA*)lParam;
1047 INT nItem = (INT)wParam;
1048 HEADER_ITEM *lpItem;
1052 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1055 TRACE("[nItem=%d]\n", nItem);
1057 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem, phdi->mask))
1060 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
1061 if (phdi->mask & HDI_BITMAP)
1062 lpItem->hbm = phdi->hbm;
1064 if (phdi->mask & HDI_FORMAT)
1065 lpItem->fmt = phdi->fmt;
1067 if (phdi->mask & HDI_LPARAM)
1068 lpItem->lParam = phdi->lParam;
1070 if (phdi->mask & HDI_TEXT) {
1071 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
1072 if (lpItem->pszText) {
1073 COMCTL32_Free (lpItem->pszText);
1074 lpItem->pszText = NULL;
1076 if (phdi->pszText) {
1077 INT len = MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,NULL,0);
1078 lpItem->pszText = COMCTL32_Alloc( len*sizeof(WCHAR) );
1079 MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,lpItem->pszText,len);
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);
1213 infoPtr->nNotifyFormat =
1214 SendMessageA (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1217 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1218 GetTextMetricsA (hdc, &tm);
1219 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1220 SelectObject (hdc, hOldFont);
1228 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1230 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1231 HEADER_ITEM *lpItem;
1234 if (infoPtr->items) {
1235 lpItem = (HEADER_ITEM*)infoPtr->items;
1236 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1237 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
1238 COMCTL32_Free (lpItem->pszText);
1240 COMCTL32_Free (infoPtr->items);
1244 ImageList_Destroy (infoPtr->himl);
1246 COMCTL32_Free (infoPtr);
1247 SetWindowLongA (hwnd, 0, 0);
1252 static inline LRESULT
1253 HEADER_GetFont (HWND hwnd)
1255 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1257 return (LRESULT)infoPtr->hFont;
1262 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1268 pt.x = (INT)LOWORD(lParam);
1269 pt.y = (INT)HIWORD(lParam);
1270 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1272 if ((GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1273 HEADER_SendHeaderNotify (hwnd, HDN_ITEMDBLCLICKA, nItem,0);
1274 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1275 HEADER_SendHeaderNotify (hwnd, HDN_DIVIDERDBLCLICKA, nItem,0);
1282 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1284 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1285 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1291 pt.x = (INT)LOWORD(lParam);
1292 pt.y = (INT)HIWORD(lParam);
1293 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1295 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1297 infoPtr->bCaptured = TRUE;
1298 infoPtr->bPressed = TRUE;
1299 infoPtr->iMoveItem = nItem;
1301 infoPtr->items[nItem].bDown = TRUE;
1303 /* Send WM_CUSTOMDRAW */
1305 HEADER_RefreshItem (hwnd, hdc, nItem);
1306 ReleaseDC (hwnd, hdc);
1308 TRACE("Pressed item %d!\n", nItem);
1310 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1311 if (!(HEADER_SendHeaderNotify (hwnd, HDN_BEGINTRACKA, nItem,0))) {
1313 infoPtr->bCaptured = TRUE;
1314 infoPtr->bTracking = TRUE;
1315 infoPtr->iMoveItem = nItem;
1316 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1317 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1319 if (!(dwStyle & HDS_FULLDRAG)) {
1320 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1322 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1323 ReleaseDC (hwnd, hdc);
1326 TRACE("Begin tracking item %d!\n", nItem);
1335 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1337 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1339 *DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1346 pt.x = (INT)SLOWORD(lParam);
1347 pt.y = (INT)SHIWORD(lParam);
1348 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1350 if (infoPtr->bPressed) {
1351 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1352 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1354 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1355 ReleaseDC (hwnd, hdc);
1357 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1359 else if (flags == HHT_ONHEADER)
1361 HEADER_ITEM *lpItem;
1362 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1363 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1365 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1366 infoPtr->iMoveItem,oldindex,nItem,newindex);
1367 lpItem= (HEADER_ITEM*)&infoPtr->items[nItem];
1368 lpItem->iOrder=oldindex;
1370 lpItem= (HEADER_ITEM*)&infoPtr->items[infoPtr->iMoveItem];
1371 lpItem->iOrder = newindex;
1373 infoPtr->bRectsValid = FALSE;
1374 InvalidateRect(hwnd, NULL, FALSE);
1375 /* FIXME: Should some WM_NOTIFY be sent */
1378 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1379 infoPtr->bPressed = FALSE;
1381 else if (infoPtr->bTracking) {
1382 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1383 infoPtr->bTracking = FALSE;
1385 HEADER_SendHeaderNotify (hwnd, HDN_ENDTRACKA, infoPtr->iMoveItem,0);
1388 * we want to do this even for HDS_FULLDRAG because this is where
1389 * we send the HDN_ITEMCHANGING and HDN_ITEMCHANGED notifications
1391 * if (!(dwStyle & HDS_FULLDRAG)) {
1395 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1396 ReleaseDC (hwnd, hdc);
1397 if (HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1398 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1400 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1403 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1406 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH);
1407 HEADER_SetItemBounds (hwnd);
1408 InvalidateRect(hwnd, NULL, FALSE);
1414 if (infoPtr->bCaptured) {
1415 infoPtr->bCaptured = FALSE;
1417 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1425 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1427 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1432 return infoPtr->nNotifyFormat;
1435 infoPtr->nNotifyFormat =
1436 SendMessageA ((HWND)wParam, WM_NOTIFYFORMAT,
1437 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1438 return infoPtr->nNotifyFormat;
1446 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1448 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1449 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1455 pt.x = (INT)SLOWORD(lParam);
1456 pt.y = (INT)SHIWORD(lParam);
1457 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1459 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1460 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1461 infoPtr->iHotItem = nItem;
1463 infoPtr->iHotItem = -1;
1464 InvalidateRect(hwnd, NULL, FALSE);
1467 if (infoPtr->bCaptured) {
1468 if (infoPtr->bPressed) {
1469 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1470 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1472 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1474 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1475 ReleaseDC (hwnd, hdc);
1477 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1479 else if (infoPtr->bTracking) {
1480 if (dwStyle & HDS_FULLDRAG) {
1481 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1483 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1486 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1487 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1489 HEADER_SetItemBounds (hwnd);
1490 InvalidateRect(hwnd, NULL, FALSE);
1494 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1495 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1496 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1497 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1498 infoPtr->items[infoPtr->iMoveItem].cxy =
1499 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1500 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1501 ReleaseDC (hwnd, hdc);
1502 HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH);
1505 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1509 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1510 FIXME("hot track support!\n");
1518 HEADER_Paint (HWND hwnd, WPARAM wParam)
1523 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1524 HEADER_Refresh (hwnd, hdc);
1526 EndPaint (hwnd, &ps);
1532 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1537 pt.x = LOWORD(lParam);
1538 pt.y = HIWORD(lParam);
1540 /* Send a Notify message */
1541 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1543 /* Change to screen coordinate for WM_CONTEXTMENU */
1544 ClientToScreen(hwnd, &pt);
1546 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1547 SendMessageA( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1554 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1556 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1561 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1564 ScreenToClient (hwnd, &pt);
1566 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1568 if (flags == HHT_ONDIVIDER)
1569 SetCursor (infoPtr->hcurDivider);
1570 else if (flags == HHT_ONDIVOPEN)
1571 SetCursor (infoPtr->hcurDivopen);
1573 SetCursor (infoPtr->hcurArrow);
1580 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1582 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1584 HFONT hFont, hOldFont;
1587 infoPtr->hFont = (HFONT)wParam;
1589 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1592 hOldFont = SelectObject (hdc, hFont);
1593 GetTextMetricsA (hdc, &tm);
1594 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1595 SelectObject (hdc, hOldFont);
1598 infoPtr->bRectsValid = FALSE;
1601 InvalidateRect(hwnd, NULL, FALSE);
1608 static LRESULT WINAPI
1609 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1611 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1612 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1613 return DefWindowProcA (hwnd, msg, wParam, lParam);
1615 /* case HDM_CLEARFILTER: */
1617 case HDM_CREATEDRAGIMAGE:
1618 return HEADER_CreateDragImage (hwnd, wParam);
1620 case HDM_DELETEITEM:
1621 return HEADER_DeleteItem (hwnd, wParam);
1623 /* case HDM_EDITFILTER: */
1625 /* case HDM_GETBITMAPMARGIN: */
1627 case HDM_GETIMAGELIST:
1628 return HEADER_GetImageList (hwnd);
1631 return HEADER_GetItemA (hwnd, wParam, lParam);
1634 return HEADER_GetItemW (hwnd, wParam, lParam);
1636 case HDM_GETITEMCOUNT:
1637 return HEADER_GetItemCount (hwnd);
1639 case HDM_GETITEMRECT:
1640 return HEADER_GetItemRect (hwnd, wParam, lParam);
1642 case HDM_GETORDERARRAY:
1643 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1645 case HDM_GETUNICODEFORMAT:
1646 return HEADER_GetUnicodeFormat (hwnd);
1649 return HEADER_HitTest (hwnd, wParam, lParam);
1651 case HDM_INSERTITEMA:
1652 return HEADER_InsertItemA (hwnd, wParam, lParam);
1654 case HDM_INSERTITEMW:
1655 return HEADER_InsertItemW (hwnd, wParam, lParam);
1658 return HEADER_Layout (hwnd, wParam, lParam);
1660 case HDM_ORDERTOINDEX:
1661 return HEADER_OrderToIndex(hwnd, wParam);
1663 /* case HDM_SETBITMAPMARGIN: */
1665 /* case HDM_SETFILTERCHANGETIMEOUT: */
1667 /* case HDM_SETHOTDIVIDER: */
1669 case HDM_SETIMAGELIST:
1670 return HEADER_SetImageList (hwnd, wParam, lParam);
1673 return HEADER_SetItemA (hwnd, wParam, lParam);
1676 return HEADER_SetItemW (hwnd, wParam, lParam);
1678 case HDM_SETORDERARRAY:
1679 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1681 case HDM_SETUNICODEFORMAT:
1682 return HEADER_SetUnicodeFormat (hwnd, wParam);
1685 return HEADER_Create (hwnd, wParam, lParam);
1688 return HEADER_Destroy (hwnd, wParam, lParam);
1694 return DLGC_WANTTAB | DLGC_WANTARROWS;
1697 return HEADER_GetFont (hwnd);
1699 case WM_LBUTTONDBLCLK:
1700 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1702 case WM_LBUTTONDOWN:
1703 return HEADER_LButtonDown (hwnd, wParam, lParam);
1706 return HEADER_LButtonUp (hwnd, wParam, lParam);
1709 return HEADER_MouseMove (hwnd, wParam, lParam);
1711 case WM_NOTIFYFORMAT:
1712 return HEADER_NotifyFormat (hwnd, wParam, lParam);
1715 return HEADER_Size (hwnd, wParam);
1718 return HEADER_Paint (hwnd, wParam);
1721 return HEADER_RButtonUp (hwnd, wParam, lParam);
1724 return HEADER_SetCursor (hwnd, wParam, lParam);
1727 return HEADER_SetFont (hwnd, wParam, lParam);
1731 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1732 msg, wParam, lParam );
1733 return DefWindowProcA (hwnd, msg, wParam, lParam);
1740 HEADER_Register (void)
1744 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1745 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1746 wndClass.lpfnWndProc = (WNDPROC)HEADER_WindowProc;
1747 wndClass.cbClsExtra = 0;
1748 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1749 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
1750 wndClass.lpszClassName = WC_HEADERA;
1752 RegisterClassA (&wndClass);
1757 HEADER_Unregister (void)
1759 UnregisterClassA (WC_HEADERA, (HINSTANCE)NULL);