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 TRACE("DrawItem(iItem %d bHotTrack %d)\n", iItem, bHotTrack);
149 if (!infoPtr->bRectsValid)
150 HEADER_SetItemBounds(hwnd);
153 if (r.right - r.left == 0)
154 return phdi->rect.right;
156 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) {
158 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
159 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
164 DrawEdge (hdc, &r, EDGE_RAISED,
165 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
168 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
170 if (phdi->fmt & HDF_OWNERDRAW) {
172 dis.CtlType = ODT_HEADER;
173 dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
175 dis.itemAction = ODA_DRAWENTIRE;
176 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
180 dis.itemData = phdi->lParam;
181 SendMessageA (GetParent (hwnd), WM_DRAWITEM,
182 (WPARAM)dis.CtlID, (LPARAM)&dis);
185 UINT uTextJustify = DT_LEFT;
187 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
188 uTextJustify = DT_CENTER;
189 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
190 uTextJustify = DT_RIGHT;
192 if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
195 INT yD, yS, cx, cy, rx, ry;
197 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
199 ry = r.bottom - r.top;
200 rx = r.right - r.left;
202 if (ry >= bmp.bmHeight) {
204 yD = r.top + (ry - bmp.bmHeight) / 2;
210 yS = (bmp.bmHeight - ry) / 2;
214 if (rx >= bmp.bmWidth + 6) {
221 hdcBitmap = CreateCompatibleDC (hdc);
222 SelectObject (hdcBitmap, phdi->hbm);
223 BitBlt (hdc, r.left + 3, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
224 DeleteDC (hdcBitmap);
226 r.left += (bmp.bmWidth + 3);
230 if ((phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
233 INT xD, yD, yS, cx, cy, rx, ry, tx;
236 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
239 DrawTextW (hdc, phdi->pszText, -1,
240 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
241 tx = textRect.right - textRect.left;
242 ry = r.bottom - r.top;
243 rx = r.right - r.left;
245 if (ry >= bmp.bmHeight) {
247 yD = r.top + (ry - bmp.bmHeight) / 2;
253 yS = (bmp.bmHeight - ry) / 2;
257 if (r.left + tx + bmp.bmWidth + 9 <= r.right) {
259 xD = r.left + tx + 6;
262 if (rx >= bmp.bmWidth + 6) {
264 xD = r.right - bmp.bmWidth - 3;
274 hdcBitmap = CreateCompatibleDC (hdc);
275 SelectObject (hdcBitmap, phdi->hbm);
276 BitBlt (hdc, xD, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
277 DeleteDC (hdcBitmap);
280 if ((phdi->fmt & HDF_IMAGE) && (infoPtr->himl)) {
282 /* FIXME: (r.bottom- (infoPtr->himl->cy))/2 should horicontal center the image
283 It looks like it doesn't work as expected*/
284 ImageList_Draw (infoPtr->himl, phdi->iImage,hdc,r.left, (r.bottom- (infoPtr->himl->cy))/2,0);
285 r.left += infoPtr->himl->cx;
288 if (((phdi->fmt & HDF_STRING)
289 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
290 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
291 && (phdi->pszText)) {
292 oldBkMode = SetBkMode(hdc, TRANSPARENT);
295 SetTextColor (hdc, (bHotTrack) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
296 DrawTextW (hdc, phdi->pszText, -1,
297 &r, uTextJustify|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
298 if (oldBkMode != TRANSPARENT)
299 SetBkMode(hdc, oldBkMode);
303 return phdi->rect.right;
308 HEADER_Refresh (HWND hwnd, HDC hdc)
310 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
311 HFONT hFont, hOldFont;
316 /* get rect for the bar, adjusted for the border */
317 GetClientRect (hwnd, &rect);
319 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
320 hOldFont = SelectObject (hdc, hFont);
322 /* draw Background */
323 hbrBk = GetSysColorBrush(COLOR_3DFACE);
324 FillRect(hdc, &rect, hbrBk);
327 for (i = 0; i < infoPtr->uNumItem; i++) {
328 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i), FALSE);
331 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
333 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS)
334 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
336 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
339 SelectObject (hdc, hOldFont);
344 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
346 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
347 HFONT hFont, hOldFont;
349 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
350 hOldFont = SelectObject (hdc, hFont);
351 HEADER_DrawItem (hwnd, hdc, iItem, FALSE);
352 SelectObject (hdc, hOldFont);
357 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
359 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
364 GetClientRect (hwnd, &rect);
368 if (PtInRect (&rect, *lpPt))
370 if (infoPtr->uNumItem == 0) {
371 *pFlags |= HHT_NOWHERE;
377 /* somewhere inside */
378 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
379 rect = infoPtr->items[iCount].rect;
380 width = rect.right - rect.left;
385 if (PtInRect (&rect, *lpPt)) {
386 if (width <= 2 * DIVIDER_WIDTH) {
387 *pFlags |= HHT_ONHEADER;
389 TRACE("ON HEADER %d\n", iCount);
394 rcTest.right = rcTest.left + DIVIDER_WIDTH;
395 if (PtInRect (&rcTest, *lpPt)) {
397 *pFlags |= HHT_ONDIVOPEN;
399 TRACE("ON DIVOPEN %d\n", *pItem);
403 *pFlags |= HHT_ONDIVIDER;
405 TRACE("ON DIVIDER %d\n", *pItem);
411 rcTest.left = rcTest.right - DIVIDER_WIDTH;
412 if (PtInRect (&rcTest, *lpPt)) {
413 *pFlags |= HHT_ONDIVIDER;
415 TRACE("ON DIVIDER %d\n", *pItem);
419 *pFlags |= HHT_ONHEADER;
421 TRACE("ON HEADER %d\n", iCount);
426 /* check for last divider part (on nowhere) */
427 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
428 rect.left = rect.right;
429 rect.right += DIVIDER_WIDTH;
430 if (PtInRect (&rect, *lpPt)) {
432 *pFlags |= HHT_ONDIVOPEN;
433 *pItem = infoPtr->uNumItem - 1;
434 TRACE("ON DIVOPEN %d\n", *pItem);
438 *pFlags |= HHT_ONDIVIDER;
439 *pItem = infoPtr->uNumItem-1;
440 TRACE("ON DIVIDER %d\n", *pItem);
445 *pFlags |= HHT_NOWHERE;
452 if (lpPt->x < rect.left) {
454 *pFlags |= HHT_TOLEFT;
456 else if (lpPt->x > rect.right) {
458 *pFlags |= HHT_TORIGHT;
461 if (lpPt->y < rect.top) {
463 *pFlags |= HHT_ABOVE;
465 else if (lpPt->y > rect.bottom) {
467 *pFlags |= HHT_BELOW;
472 TRACE("flags=0x%X\n", *pFlags);
478 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
484 GetClientRect (hwnd, &rect);
486 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
487 oldRop = SetROP2 (hdc, R2_XORPEN);
488 MoveToEx (hdc, x, rect.top, NULL);
489 LineTo (hdc, x, rect.bottom);
490 SetROP2 (hdc, oldRop);
491 SelectObject (hdc, hOldPen);
496 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
498 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
501 nmhdr.hwndFrom = hwnd;
502 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
505 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
506 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
510 HEADER_SendHeaderNotify (HWND hwnd, UINT code, INT iItem, INT mask)
512 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
516 nmhdr.hdr.hwndFrom = hwnd;
517 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
518 nmhdr.hdr.code = code;
521 nmhdr.pitem = &nmitem;
523 nmitem.cxy = infoPtr->items[iItem].cxy;
524 nmitem.hbm = infoPtr->items[iItem].hbm;
525 nmitem.pszText = NULL;
526 nmitem.cchTextMax = 0;
527 /* nmitem.pszText = infoPtr->items[iItem].pszText; */
528 /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
529 nmitem.fmt = infoPtr->items[iItem].fmt;
530 nmitem.lParam = infoPtr->items[iItem].lParam;
531 nmitem.iOrder = infoPtr->items[iItem].iOrder;
532 nmitem.iImage = infoPtr->items[iItem].iImage;
534 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
535 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
540 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
542 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
545 nmhdr.hdr.hwndFrom = hwnd;
546 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
547 nmhdr.hdr.code = code;
552 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
553 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
558 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
560 FIXME("empty stub!\n");
566 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
568 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
569 INT iItem = (INT)wParam;
571 TRACE("[iItem=%d]\n", iItem);
573 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
576 if (infoPtr->uNumItem == 1) {
577 TRACE("Simple delete!\n");
578 if (infoPtr->items[0].pszText)
579 COMCTL32_Free (infoPtr->items[0].pszText);
580 COMCTL32_Free (infoPtr->items);
582 infoPtr->uNumItem = 0;
585 HEADER_ITEM *oldItems = infoPtr->items;
586 TRACE("Complex delete! [iItem=%d]\n", iItem);
588 if (infoPtr->items[iItem].pszText)
589 COMCTL32_Free (infoPtr->items[iItem].pszText);
592 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
593 /* pre delete copy */
595 memcpy (&infoPtr->items[0], &oldItems[0],
596 iItem * sizeof(HEADER_ITEM));
599 /* post delete copy */
600 if (iItem < infoPtr->uNumItem) {
601 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
602 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
605 COMCTL32_Free (oldItems);
608 HEADER_SetItemBounds (hwnd);
610 InvalidateRect(hwnd, NULL, FALSE);
617 HEADER_GetImageList (HWND hwnd)
619 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
621 return (LRESULT)infoPtr->himl;
626 HEADER_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
628 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
629 HDITEMA *phdi = (HDITEMA*)lParam;
630 INT nItem = (INT)wParam;
635 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
638 TRACE("[nItem=%d]\n", nItem);
643 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
644 if (phdi->mask & HDI_BITMAP)
645 phdi->hbm = lpItem->hbm;
647 if (phdi->mask & HDI_FORMAT)
648 phdi->fmt = lpItem->fmt;
650 if (phdi->mask & HDI_WIDTH)
651 phdi->cxy = lpItem->cxy;
653 if (phdi->mask & HDI_LPARAM)
654 phdi->lParam = lpItem->lParam;
656 if (phdi->mask & HDI_TEXT) {
657 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
659 WideCharToMultiByte (CP_ACP, 0, lpItem->pszText, -1,
660 phdi->pszText, phdi->cchTextMax, NULL, NULL);
665 phdi->pszText = LPSTR_TEXTCALLBACKA;
668 if (phdi->mask & HDI_IMAGE)
669 phdi->iImage = lpItem->iImage;
671 if (phdi->mask & HDI_ORDER)
672 phdi->iOrder = lpItem->iOrder;
679 HEADER_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
681 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
682 HDITEMW *phdi = (HDITEMW*)lParam;
683 INT nItem = (INT)wParam;
688 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
691 TRACE("[nItem=%d]\n", nItem);
696 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
697 if (phdi->mask & HDI_BITMAP)
698 phdi->hbm = lpItem->hbm;
700 if (phdi->mask & HDI_FORMAT)
701 phdi->fmt = lpItem->fmt;
703 if (phdi->mask & HDI_WIDTH)
704 phdi->cxy = lpItem->cxy;
706 if (phdi->mask & HDI_LPARAM)
707 phdi->lParam = lpItem->lParam;
709 if (phdi->mask & HDI_TEXT) {
710 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
712 lstrcpynW (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
717 phdi->pszText = LPSTR_TEXTCALLBACKW;
720 if (phdi->mask & HDI_IMAGE)
721 phdi->iImage = lpItem->iImage;
723 if (phdi->mask & HDI_ORDER)
724 phdi->iOrder = lpItem->iOrder;
730 inline static LRESULT
731 HEADER_GetItemCount (HWND hwnd)
733 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
734 return infoPtr->uNumItem;
739 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
741 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
742 INT iItem = (INT)wParam;
743 LPRECT lpRect = (LPRECT)lParam;
745 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
748 lpRect->left = infoPtr->items[iItem].rect.left;
749 lpRect->right = infoPtr->items[iItem].rect.right;
750 lpRect->top = infoPtr->items[iItem].rect.top;
751 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
758 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
761 LPINT order = (LPINT) lParam;
762 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
764 if ((int)wParam <infoPtr->uNumItem)
766 for (i=0; i<(int)wParam; i++)
767 *order++=HEADER_OrderToIndex(hwnd,i);
772 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
775 LPINT order = (LPINT) lParam;
776 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
779 if ((int)wParam <infoPtr->uNumItem)
781 for (i=0; i<(int)wParam; i++)
783 lpItem = (HEADER_ITEM*)&infoPtr->items[*order++];
786 infoPtr->bRectsValid=0;
787 InvalidateRect(hwnd, NULL, FALSE);
791 inline static LRESULT
792 HEADER_GetUnicodeFormat (HWND hwnd)
794 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
795 return infoPtr->bUnicode;
800 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
802 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
804 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
806 if (phti->flags == HHT_ONHEADER)
814 HEADER_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
816 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
817 HDITEMA *phdi = (HDITEMA*)lParam;
818 INT nItem = (INT)wParam;
822 if ((phdi == NULL) || (nItem < 0))
825 if (nItem > infoPtr->uNumItem)
826 nItem = infoPtr->uNumItem;
828 if (infoPtr->uNumItem == 0) {
829 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
833 HEADER_ITEM *oldItems = infoPtr->items;
836 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
838 memcpy (&infoPtr->items[1], &oldItems[0],
839 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
843 /* pre insert copy */
845 memcpy (&infoPtr->items[0], &oldItems[0],
846 nItem * sizeof(HEADER_ITEM));
849 /* post insert copy */
850 if (nItem < infoPtr->uNumItem - 1) {
851 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
852 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
856 COMCTL32_Free (oldItems);
859 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
860 lpItem->bDown = FALSE;
862 if (phdi->mask & HDI_WIDTH)
863 lpItem->cxy = phdi->cxy;
865 if (phdi->mask & HDI_TEXT) {
866 if (!phdi->pszText) /* null pointer check */
868 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
869 len = MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, NULL, 0);
870 lpItem->pszText = COMCTL32_Alloc( len*sizeof(WCHAR) );
871 MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, lpItem->pszText, len);
874 lpItem->pszText = LPSTR_TEXTCALLBACKW;
877 if (phdi->mask & HDI_FORMAT)
878 lpItem->fmt = phdi->fmt;
880 if (lpItem->fmt == 0)
881 lpItem->fmt = HDF_LEFT;
883 if (!(lpItem->fmt &HDF_STRING) && (phdi->mask & HDI_TEXT))
885 lpItem->fmt |= HDF_STRING;
887 if (phdi->mask & HDI_BITMAP)
888 lpItem->hbm = phdi->hbm;
890 if (phdi->mask & HDI_LPARAM)
891 lpItem->lParam = phdi->lParam;
893 if (phdi->mask & HDI_IMAGE)
894 lpItem->iImage = phdi->iImage;
896 if (phdi->mask & HDI_ORDER)
898 lpItem->iOrder = phdi->iOrder;
901 lpItem->iOrder=nItem;
904 HEADER_SetItemBounds (hwnd);
906 InvalidateRect(hwnd, NULL, FALSE);
913 HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
915 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
916 HDITEMW *phdi = (HDITEMW*)lParam;
917 INT nItem = (INT)wParam;
921 if ((phdi == NULL) || (nItem < 0))
924 if (nItem > infoPtr->uNumItem)
925 nItem = infoPtr->uNumItem;
927 if (infoPtr->uNumItem == 0) {
928 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
932 HEADER_ITEM *oldItems = infoPtr->items;
935 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
936 /* pre insert copy */
938 memcpy (&infoPtr->items[0], &oldItems[0],
939 nItem * sizeof(HEADER_ITEM));
942 /* post insert copy */
943 if (nItem < infoPtr->uNumItem - 1) {
944 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
945 (infoPtr->uNumItem - nItem) * sizeof(HEADER_ITEM));
948 COMCTL32_Free (oldItems);
951 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
952 lpItem->bDown = FALSE;
954 if (phdi->mask & HDI_WIDTH)
955 lpItem->cxy = phdi->cxy;
957 if (phdi->mask & HDI_TEXT) {
958 WCHAR wide_null_char = 0;
959 if (!phdi->pszText) /* null pointer check */
960 phdi->pszText = &wide_null_char;
961 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
962 len = strlenW (phdi->pszText);
963 lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
964 strcpyW (lpItem->pszText, phdi->pszText);
967 lpItem->pszText = LPSTR_TEXTCALLBACKW;
970 if (phdi->mask & HDI_FORMAT)
971 lpItem->fmt = phdi->fmt;
973 if (lpItem->fmt == 0)
974 lpItem->fmt = HDF_LEFT;
976 if (phdi->mask & HDI_BITMAP)
977 lpItem->hbm = phdi->hbm;
979 if (phdi->mask & HDI_LPARAM)
980 lpItem->lParam = phdi->lParam;
982 if (phdi->mask & HDI_IMAGE)
983 lpItem->iImage = phdi->iImage;
985 if (phdi->mask & HDI_ORDER)
987 lpItem->iOrder = phdi->iOrder;
990 lpItem->iOrder = nItem;
992 HEADER_SetItemBounds (hwnd);
994 InvalidateRect(hwnd, NULL, FALSE);
1001 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
1003 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1004 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1006 lpLayout->pwpos->hwnd = hwnd;
1007 lpLayout->pwpos->hwndInsertAfter = 0;
1008 lpLayout->pwpos->x = lpLayout->prc->left;
1009 lpLayout->pwpos->y = lpLayout->prc->top;
1010 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1011 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_HIDDEN)
1012 lpLayout->pwpos->cy = 0;
1014 lpLayout->pwpos->cy = infoPtr->nHeight;
1015 lpLayout->prc->top += infoPtr->nHeight;
1017 lpLayout->pwpos->flags = SWP_NOZORDER;
1019 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1020 lpLayout->pwpos->x, lpLayout->pwpos->y,
1021 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1023 infoPtr->bRectsValid = FALSE;
1030 HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
1032 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1035 TRACE("(himl 0x%x)\n", (int)himl);
1036 himlOld = infoPtr->himl;
1037 infoPtr->himl = himl;
1039 /* FIXME: Refresh needed??? */
1041 return (LRESULT)himlOld;
1046 HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1048 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1049 HDITEMA *phdi = (HDITEMA*)lParam;
1050 INT nItem = (INT)wParam;
1051 HEADER_ITEM *lpItem;
1055 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1058 TRACE("[nItem=%d]\n", nItem);
1060 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem, phdi->mask))
1063 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
1064 if (phdi->mask & HDI_BITMAP)
1065 lpItem->hbm = phdi->hbm;
1067 if (phdi->mask & HDI_FORMAT)
1068 lpItem->fmt = phdi->fmt;
1070 if (phdi->mask & HDI_LPARAM)
1071 lpItem->lParam = phdi->lParam;
1073 if (phdi->mask & HDI_TEXT) {
1074 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
1075 if (lpItem->pszText) {
1076 COMCTL32_Free (lpItem->pszText);
1077 lpItem->pszText = NULL;
1079 if (phdi->pszText) {
1080 INT len = MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,NULL,0);
1081 lpItem->pszText = COMCTL32_Alloc( len*sizeof(WCHAR) );
1082 MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,lpItem->pszText,len);
1086 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1089 if (phdi->mask & HDI_WIDTH)
1090 lpItem->cxy = phdi->cxy;
1092 if (phdi->mask & HDI_IMAGE)
1093 lpItem->iImage = phdi->iImage;
1095 if (phdi->mask & HDI_ORDER)
1097 lpItem->iOrder = phdi->iOrder;
1100 lpItem->iOrder = nItem;
1102 HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem, phdi->mask);
1104 HEADER_SetItemBounds (hwnd);
1106 InvalidateRect(hwnd, NULL, FALSE);
1113 HEADER_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1115 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1116 HDITEMW *phdi = (HDITEMW*)lParam;
1117 INT nItem = (INT)wParam;
1118 HEADER_ITEM *lpItem;
1122 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1125 TRACE("[nItem=%d]\n", nItem);
1127 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask))
1130 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
1131 if (phdi->mask & HDI_BITMAP)
1132 lpItem->hbm = phdi->hbm;
1134 if (phdi->mask & HDI_FORMAT)
1135 lpItem->fmt = phdi->fmt;
1137 if (phdi->mask & HDI_LPARAM)
1138 lpItem->lParam = phdi->lParam;
1140 if (phdi->mask & HDI_TEXT) {
1141 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1142 if (lpItem->pszText) {
1143 COMCTL32_Free (lpItem->pszText);
1144 lpItem->pszText = NULL;
1146 if (phdi->pszText) {
1147 INT len = strlenW (phdi->pszText);
1148 lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1149 strcpyW (lpItem->pszText, phdi->pszText);
1153 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1156 if (phdi->mask & HDI_WIDTH)
1157 lpItem->cxy = phdi->cxy;
1159 if (phdi->mask & HDI_IMAGE)
1160 lpItem->iImage = phdi->iImage;
1162 if (phdi->mask & HDI_ORDER)
1164 lpItem->iOrder = phdi->iOrder;
1167 lpItem->iOrder = nItem;
1169 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask);
1171 HEADER_SetItemBounds (hwnd);
1173 InvalidateRect(hwnd, NULL, FALSE);
1178 inline static LRESULT
1179 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1181 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1182 BOOL bTemp = infoPtr->bUnicode;
1184 infoPtr->bUnicode = (BOOL)wParam;
1191 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1193 HEADER_INFO *infoPtr;
1198 infoPtr = (HEADER_INFO *)COMCTL32_Alloc (sizeof(HEADER_INFO));
1199 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1201 infoPtr->hwndNotify = GetParent(hwnd);
1202 infoPtr->uNumItem = 0;
1203 infoPtr->nHeight = 20;
1206 infoPtr->bRectsValid = FALSE;
1207 infoPtr->hcurArrow = LoadCursorA (0, IDC_ARROWA);
1208 infoPtr->hcurDivider = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDER));
1209 infoPtr->hcurDivopen = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDEROPEN));
1210 infoPtr->bPressed = FALSE;
1211 infoPtr->bTracking = FALSE;
1212 infoPtr->iMoveItem = 0;
1214 infoPtr->iHotItem = -1;
1215 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1216 infoPtr->nNotifyFormat =
1217 SendMessageA (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1220 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1221 GetTextMetricsA (hdc, &tm);
1222 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1223 SelectObject (hdc, hOldFont);
1231 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1233 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1234 HEADER_ITEM *lpItem;
1237 if (infoPtr->items) {
1238 lpItem = (HEADER_ITEM*)infoPtr->items;
1239 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1240 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
1241 COMCTL32_Free (lpItem->pszText);
1243 COMCTL32_Free (infoPtr->items);
1247 ImageList_Destroy (infoPtr->himl);
1249 COMCTL32_Free (infoPtr);
1250 SetWindowLongA (hwnd, 0, 0);
1255 static inline LRESULT
1256 HEADER_GetFont (HWND hwnd)
1258 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1260 return (LRESULT)infoPtr->hFont;
1265 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1271 pt.x = (INT)LOWORD(lParam);
1272 pt.y = (INT)HIWORD(lParam);
1273 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1275 if ((GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1276 HEADER_SendHeaderNotify (hwnd, HDN_ITEMDBLCLICKA, nItem,0);
1277 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1278 HEADER_SendHeaderNotify (hwnd, HDN_DIVIDERDBLCLICKA, nItem,0);
1285 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1287 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1288 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1294 pt.x = (INT)LOWORD(lParam);
1295 pt.y = (INT)HIWORD(lParam);
1296 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1298 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1300 infoPtr->bCaptured = TRUE;
1301 infoPtr->bPressed = TRUE;
1302 infoPtr->iMoveItem = nItem;
1304 infoPtr->items[nItem].bDown = TRUE;
1306 /* Send WM_CUSTOMDRAW */
1308 HEADER_RefreshItem (hwnd, hdc, nItem);
1309 ReleaseDC (hwnd, hdc);
1311 TRACE("Pressed item %d!\n", nItem);
1313 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1314 if (!(HEADER_SendHeaderNotify (hwnd, HDN_BEGINTRACKA, nItem,0))) {
1316 infoPtr->bCaptured = TRUE;
1317 infoPtr->bTracking = TRUE;
1318 infoPtr->iMoveItem = nItem;
1319 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1320 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1322 if (!(dwStyle & HDS_FULLDRAG)) {
1323 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1325 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1326 ReleaseDC (hwnd, hdc);
1329 TRACE("Begin tracking item %d!\n", nItem);
1338 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1340 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1342 *DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1349 pt.x = (INT)SLOWORD(lParam);
1350 pt.y = (INT)SHIWORD(lParam);
1351 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1353 if (infoPtr->bPressed) {
1354 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1355 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1357 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1358 ReleaseDC (hwnd, hdc);
1360 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1362 else if (flags == HHT_ONHEADER)
1364 HEADER_ITEM *lpItem;
1365 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1366 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1368 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1369 infoPtr->iMoveItem,oldindex,nItem,newindex);
1370 lpItem= (HEADER_ITEM*)&infoPtr->items[nItem];
1371 lpItem->iOrder=oldindex;
1373 lpItem= (HEADER_ITEM*)&infoPtr->items[infoPtr->iMoveItem];
1374 lpItem->iOrder = newindex;
1376 infoPtr->bRectsValid = FALSE;
1377 InvalidateRect(hwnd, NULL, FALSE);
1378 /* FIXME: Should some WM_NOTIFY be sent */
1381 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1382 infoPtr->bPressed = FALSE;
1384 else if (infoPtr->bTracking) {
1385 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1386 infoPtr->bTracking = FALSE;
1388 HEADER_SendHeaderNotify (hwnd, HDN_ENDTRACKA, infoPtr->iMoveItem,0);
1391 * we want to do this even for HDS_FULLDRAG because this is where
1392 * we send the HDN_ITEMCHANGING and HDN_ITEMCHANGED notifications
1394 * if (!(dwStyle & HDS_FULLDRAG)) {
1398 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1399 ReleaseDC (hwnd, hdc);
1400 if (HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1402 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1405 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1408 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1411 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH);
1412 HEADER_SetItemBounds (hwnd);
1413 InvalidateRect(hwnd, NULL, FALSE);
1419 if (infoPtr->bCaptured) {
1420 infoPtr->bCaptured = FALSE;
1422 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1430 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1432 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1437 return infoPtr->nNotifyFormat;
1440 infoPtr->nNotifyFormat =
1441 SendMessageA ((HWND)wParam, WM_NOTIFYFORMAT,
1442 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1443 return infoPtr->nNotifyFormat;
1451 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1453 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1454 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1460 pt.x = (INT)SLOWORD(lParam);
1461 pt.y = (INT)SHIWORD(lParam);
1462 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1464 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1465 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1466 infoPtr->iHotItem = nItem;
1468 infoPtr->iHotItem = -1;
1469 InvalidateRect(hwnd, NULL, FALSE);
1472 if (infoPtr->bCaptured) {
1473 if (infoPtr->bPressed) {
1474 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1475 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1477 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1479 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1480 ReleaseDC (hwnd, hdc);
1482 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1484 else if (infoPtr->bTracking) {
1485 if (dwStyle & HDS_FULLDRAG) {
1486 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1488 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1491 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1492 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1494 HEADER_SetItemBounds (hwnd);
1495 InvalidateRect(hwnd, NULL, FALSE);
1499 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1500 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1501 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1502 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1503 infoPtr->items[infoPtr->iMoveItem].cxy =
1504 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1505 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1506 ReleaseDC (hwnd, hdc);
1507 HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH);
1510 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1514 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1515 FIXME("hot track support!\n");
1523 HEADER_Paint (HWND hwnd, WPARAM wParam)
1528 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1529 HEADER_Refresh (hwnd, hdc);
1531 EndPaint (hwnd, &ps);
1537 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1542 pt.x = LOWORD(lParam);
1543 pt.y = HIWORD(lParam);
1545 /* Send a Notify message */
1546 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1548 /* Change to screen coordinate for WM_CONTEXTMENU */
1549 ClientToScreen(hwnd, &pt);
1551 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1552 SendMessageA( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1559 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1561 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1566 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1569 ScreenToClient (hwnd, &pt);
1571 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1573 if (flags == HHT_ONDIVIDER)
1574 SetCursor (infoPtr->hcurDivider);
1575 else if (flags == HHT_ONDIVOPEN)
1576 SetCursor (infoPtr->hcurDivopen);
1578 SetCursor (infoPtr->hcurArrow);
1585 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1587 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1589 HFONT hFont, hOldFont;
1592 infoPtr->hFont = (HFONT)wParam;
1594 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1597 hOldFont = SelectObject (hdc, hFont);
1598 GetTextMetricsA (hdc, &tm);
1599 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1600 SelectObject (hdc, hOldFont);
1603 infoPtr->bRectsValid = FALSE;
1606 InvalidateRect(hwnd, NULL, FALSE);
1613 static LRESULT WINAPI
1614 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1616 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1617 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1618 return DefWindowProcA (hwnd, msg, wParam, lParam);
1620 /* case HDM_CLEARFILTER: */
1622 case HDM_CREATEDRAGIMAGE:
1623 return HEADER_CreateDragImage (hwnd, wParam);
1625 case HDM_DELETEITEM:
1626 return HEADER_DeleteItem (hwnd, wParam);
1628 /* case HDM_EDITFILTER: */
1630 /* case HDM_GETBITMAPMARGIN: */
1632 case HDM_GETIMAGELIST:
1633 return HEADER_GetImageList (hwnd);
1636 return HEADER_GetItemA (hwnd, wParam, lParam);
1639 return HEADER_GetItemW (hwnd, wParam, lParam);
1641 case HDM_GETITEMCOUNT:
1642 return HEADER_GetItemCount (hwnd);
1644 case HDM_GETITEMRECT:
1645 return HEADER_GetItemRect (hwnd, wParam, lParam);
1647 case HDM_GETORDERARRAY:
1648 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1650 case HDM_GETUNICODEFORMAT:
1651 return HEADER_GetUnicodeFormat (hwnd);
1654 return HEADER_HitTest (hwnd, wParam, lParam);
1656 case HDM_INSERTITEMA:
1657 return HEADER_InsertItemA (hwnd, wParam, lParam);
1659 case HDM_INSERTITEMW:
1660 return HEADER_InsertItemW (hwnd, wParam, lParam);
1663 return HEADER_Layout (hwnd, wParam, lParam);
1665 case HDM_ORDERTOINDEX:
1666 return HEADER_OrderToIndex(hwnd, wParam);
1668 /* case HDM_SETBITMAPMARGIN: */
1670 /* case HDM_SETFILTERCHANGETIMEOUT: */
1672 /* case HDM_SETHOTDIVIDER: */
1674 case HDM_SETIMAGELIST:
1675 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
1678 return HEADER_SetItemA (hwnd, wParam, lParam);
1681 return HEADER_SetItemW (hwnd, wParam, lParam);
1683 case HDM_SETORDERARRAY:
1684 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1686 case HDM_SETUNICODEFORMAT:
1687 return HEADER_SetUnicodeFormat (hwnd, wParam);
1690 return HEADER_Create (hwnd, wParam, lParam);
1693 return HEADER_Destroy (hwnd, wParam, lParam);
1699 return DLGC_WANTTAB | DLGC_WANTARROWS;
1702 return HEADER_GetFont (hwnd);
1704 case WM_LBUTTONDBLCLK:
1705 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1707 case WM_LBUTTONDOWN:
1708 return HEADER_LButtonDown (hwnd, wParam, lParam);
1711 return HEADER_LButtonUp (hwnd, wParam, lParam);
1714 return HEADER_MouseMove (hwnd, wParam, lParam);
1716 case WM_NOTIFYFORMAT:
1717 return HEADER_NotifyFormat (hwnd, wParam, lParam);
1720 return HEADER_Size (hwnd, wParam);
1723 return HEADER_Paint (hwnd, wParam);
1726 return HEADER_RButtonUp (hwnd, wParam, lParam);
1729 return HEADER_SetCursor (hwnd, wParam, lParam);
1732 return HEADER_SetFont (hwnd, wParam, lParam);
1736 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1737 msg, wParam, lParam );
1738 return DefWindowProcA (hwnd, msg, wParam, lParam);
1745 HEADER_Register (void)
1749 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1750 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1751 wndClass.lpfnWndProc = (WNDPROC)HEADER_WindowProc;
1752 wndClass.cbClsExtra = 0;
1753 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1754 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
1755 wndClass.lpszClassName = WC_HEADERA;
1757 RegisterClassA (&wndClass);
1762 HEADER_Unregister (void)
1764 UnregisterClassA (WC_HEADERA, (HINSTANCE)NULL);