4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 * - Imagelist support (partially).
23 * - Callback items (under construction).
24 * - Hottrack support (partially).
25 * - Custom draw support (including Notifications).
26 * - Drag and Drop support (including Notifications).
28 * - Use notification format
29 * - Correct the order maintenance code to preserve valid order
32 * - Little flaw when drawing a bitmap on the right side of the text.
40 #include "wine/unicode.h"
46 #include "imagelist.h"
47 #include "wine/debug.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(header);
59 INT iOrder; /* see documentation of HD_ITEM */
61 BOOL bDown; /* is item pressed? (used for drawing) */
62 RECT rect; /* bounding rectangle of the item */
68 HWND hwndNotify; /* Owner window to send notifications to */
69 INT nNotifyFormat; /* format used for WM_NOTIFY messages */
70 UINT uNumItem; /* number of items (columns) */
71 INT nHeight; /* height of the header (pixels) */
72 HFONT hFont; /* handle to the current font */
73 HCURSOR hcurArrow; /* handle to the arrow cursor */
74 HCURSOR hcurDivider; /* handle to a cursor (used over dividers) <-|-> */
75 HCURSOR hcurDivopen; /* handle to a cursor (used over dividers) <-||-> */
76 BOOL bCaptured; /* Is the mouse captured? */
77 BOOL bPressed; /* Is a header item pressed (down)? */
78 BOOL bTracking; /* Is in tracking mode? */
79 BOOL bUnicode; /* Unicode flag */
80 INT iMoveItem; /* index of tracked item. (Tracking mode) */
81 INT xTrackOffset; /* distance between the right side of the tracked item and the cursor */
82 INT xOldTrack; /* track offset (see above) after the last WM_MOUSEMOVE */
83 INT nOldWidth; /* width of a sizing item after the last WM_MOUSEMOVE */
84 INT iHotItem; /* index of hot item (cursor is over this item) */
86 HIMAGELIST himl; /* handle to a image list (may be 0) */
87 HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */
88 BOOL bRectsValid; /* validity flag for bounding rectangles */
93 #define DIVIDER_WIDTH 10
95 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongA(hwnd,0))
99 HEADER_IndexToOrder (HWND hwnd, INT iItem)
101 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
102 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
103 return lpItem->iOrder;
108 HEADER_OrderToIndex(HWND hwnd, WPARAM wParam)
110 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
111 INT i,iorder = (INT)wParam;
114 if ((iorder <0) || iorder >infoPtr->uNumItem)
116 for (i=0; i<infoPtr->uNumItem; i++)
117 if (HEADER_IndexToOrder(hwnd,i) == iorder)
123 HEADER_SetItemBounds (HWND hwnd)
125 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
130 infoPtr->bRectsValid = TRUE;
132 if (infoPtr->uNumItem == 0)
135 GetClientRect (hwnd, &rect);
138 for (i = 0; i < infoPtr->uNumItem; i++) {
139 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
140 phdi->rect.top = rect.top;
141 phdi->rect.bottom = rect.bottom;
143 phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
144 x = phdi->rect.right;
149 HEADER_Size (HWND hwnd, WPARAM wParam)
151 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
153 infoPtr->bRectsValid = FALSE;
160 HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
162 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
163 HEADER_ITEM *phdi = &infoPtr->items[iItem];
167 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, infoPtr->bUnicode);
169 if (!infoPtr->bRectsValid)
170 HEADER_SetItemBounds(hwnd);
173 if (r.right - r.left == 0)
174 return phdi->rect.right;
176 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) {
178 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
179 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
184 DrawEdge (hdc, &r, EDGE_RAISED,
185 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
188 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
190 if (phdi->fmt & HDF_OWNERDRAW) {
192 dis.CtlType = ODT_HEADER;
193 dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
195 dis.itemAction = ODA_DRAWENTIRE;
196 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
200 dis.itemData = phdi->lParam;
201 oldBkMode = SetBkMode(hdc, TRANSPARENT);
202 SendMessageA (GetParent (hwnd), WM_DRAWITEM,
203 (WPARAM)dis.CtlID, (LPARAM)&dis);
204 if (oldBkMode != TRANSPARENT)
205 SetBkMode(hdc, oldBkMode);
208 UINT uTextJustify = DT_LEFT;
210 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
211 uTextJustify = DT_CENTER;
212 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
213 uTextJustify = DT_RIGHT;
215 if ((phdi->fmt & HDF_BITMAP) && !(phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
218 INT yD, yS, cx, cy, rx, ry;
220 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
222 ry = r.bottom - r.top;
223 rx = r.right - r.left;
225 if (ry >= bmp.bmHeight) {
227 yD = r.top + (ry - bmp.bmHeight) / 2;
233 yS = (bmp.bmHeight - ry) / 2;
237 if (rx >= bmp.bmWidth + 6) {
244 hdcBitmap = CreateCompatibleDC (hdc);
245 SelectObject (hdcBitmap, phdi->hbm);
246 BitBlt (hdc, r.left + 3, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
247 DeleteDC (hdcBitmap);
249 r.left += (bmp.bmWidth + 3);
253 if ((phdi->fmt & HDF_BITMAP) && (phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
256 INT xD, yD, yS, cx, cy, rx, ry, tx;
259 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
262 DrawTextW (hdc, phdi->pszText, -1,
263 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
264 tx = textRect.right - textRect.left;
265 ry = r.bottom - r.top;
266 rx = r.right - r.left;
268 if (ry >= bmp.bmHeight) {
270 yD = r.top + (ry - bmp.bmHeight) / 2;
276 yS = (bmp.bmHeight - ry) / 2;
280 if (r.left + tx + bmp.bmWidth + 9 <= r.right) {
282 xD = r.left + tx + 6;
285 if (rx >= bmp.bmWidth + 6) {
287 xD = r.right - bmp.bmWidth - 3;
297 hdcBitmap = CreateCompatibleDC (hdc);
298 SelectObject (hdcBitmap, phdi->hbm);
299 BitBlt (hdc, xD, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
300 DeleteDC (hdcBitmap);
303 if ((phdi->fmt & HDF_IMAGE) && (infoPtr->himl)) {
305 /* FIXME: (r.bottom- (infoPtr->himl->cy))/2 should horicontal center the image
306 It looks like it doesn't work as expected*/
307 ImageList_Draw (infoPtr->himl, phdi->iImage,hdc,r.left, (r.bottom- (infoPtr->himl->cy))/2,0);
308 r.left += infoPtr->himl->cx;
311 if (((phdi->fmt & HDF_STRING)
312 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
313 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
314 && (phdi->pszText)) {
315 oldBkMode = SetBkMode(hdc, TRANSPARENT);
318 SetTextColor (hdc, (bHotTrack) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
319 DrawTextW (hdc, phdi->pszText, -1,
320 &r, uTextJustify|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
321 if (oldBkMode != TRANSPARENT)
322 SetBkMode(hdc, oldBkMode);
326 return phdi->rect.right;
331 HEADER_Refresh (HWND hwnd, HDC hdc)
333 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
334 HFONT hFont, hOldFont;
339 /* get rect for the bar, adjusted for the border */
340 GetClientRect (hwnd, &rect);
342 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
343 hOldFont = SelectObject (hdc, hFont);
345 /* draw Background */
346 hbrBk = GetSysColorBrush(COLOR_3DFACE);
347 FillRect(hdc, &rect, hbrBk);
350 for (i = 0; i < infoPtr->uNumItem; i++) {
351 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i), FALSE);
354 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
356 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS)
357 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
359 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
362 SelectObject (hdc, hOldFont);
367 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
369 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
370 HFONT hFont, hOldFont;
372 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
373 hOldFont = SelectObject (hdc, hFont);
374 HEADER_DrawItem (hwnd, hdc, iItem, FALSE);
375 SelectObject (hdc, hOldFont);
380 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
382 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
387 GetClientRect (hwnd, &rect);
391 if (PtInRect (&rect, *lpPt))
393 if (infoPtr->uNumItem == 0) {
394 *pFlags |= HHT_NOWHERE;
400 /* somewhere inside */
401 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
402 rect = infoPtr->items[iCount].rect;
403 width = rect.right - rect.left;
408 if (PtInRect (&rect, *lpPt)) {
409 if (width <= 2 * DIVIDER_WIDTH) {
410 *pFlags |= HHT_ONHEADER;
412 TRACE("ON HEADER %d\n", iCount);
417 rcTest.right = rcTest.left + DIVIDER_WIDTH;
418 if (PtInRect (&rcTest, *lpPt)) {
420 *pFlags |= HHT_ONDIVOPEN;
422 TRACE("ON DIVOPEN %d\n", *pItem);
426 *pFlags |= HHT_ONDIVIDER;
428 TRACE("ON DIVIDER %d\n", *pItem);
434 rcTest.left = rcTest.right - DIVIDER_WIDTH;
435 if (PtInRect (&rcTest, *lpPt)) {
436 *pFlags |= HHT_ONDIVIDER;
438 TRACE("ON DIVIDER %d\n", *pItem);
442 *pFlags |= HHT_ONHEADER;
444 TRACE("ON HEADER %d\n", iCount);
449 /* check for last divider part (on nowhere) */
450 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
451 rect.left = rect.right;
452 rect.right += DIVIDER_WIDTH;
453 if (PtInRect (&rect, *lpPt)) {
455 *pFlags |= HHT_ONDIVOPEN;
456 *pItem = infoPtr->uNumItem - 1;
457 TRACE("ON DIVOPEN %d\n", *pItem);
461 *pFlags |= HHT_ONDIVIDER;
462 *pItem = infoPtr->uNumItem-1;
463 TRACE("ON DIVIDER %d\n", *pItem);
468 *pFlags |= HHT_NOWHERE;
475 if (lpPt->x < rect.left) {
477 *pFlags |= HHT_TOLEFT;
479 else if (lpPt->x > rect.right) {
481 *pFlags |= HHT_TORIGHT;
484 if (lpPt->y < rect.top) {
486 *pFlags |= HHT_ABOVE;
488 else if (lpPt->y > rect.bottom) {
490 *pFlags |= HHT_BELOW;
495 TRACE("flags=0x%X\n", *pFlags);
501 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
507 GetClientRect (hwnd, &rect);
509 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
510 oldRop = SetROP2 (hdc, R2_XORPEN);
511 MoveToEx (hdc, x, rect.top, NULL);
512 LineTo (hdc, x, rect.bottom);
513 SetROP2 (hdc, oldRop);
514 SelectObject (hdc, hOldPen);
519 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
521 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
524 nmhdr.hwndFrom = hwnd;
525 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
528 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
529 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
533 HEADER_SendHeaderNotify (HWND hwnd, UINT code, INT iItem, INT mask)
535 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
539 nmhdr.hdr.hwndFrom = hwnd;
540 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
541 nmhdr.hdr.code = code;
544 nmhdr.pitem = &nmitem;
546 nmitem.cxy = infoPtr->items[iItem].cxy;
547 nmitem.hbm = infoPtr->items[iItem].hbm;
548 nmitem.pszText = NULL;
549 nmitem.cchTextMax = 0;
550 /* nmitem.pszText = infoPtr->items[iItem].pszText; */
551 /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
552 nmitem.fmt = infoPtr->items[iItem].fmt;
553 nmitem.lParam = infoPtr->items[iItem].lParam;
554 nmitem.iOrder = infoPtr->items[iItem].iOrder;
555 nmitem.iImage = infoPtr->items[iItem].iImage;
557 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
558 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
563 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
565 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
568 nmhdr.hdr.hwndFrom = hwnd;
569 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
570 nmhdr.hdr.code = code;
575 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
576 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
581 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
583 FIXME("empty stub!\n");
589 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
591 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
592 INT iItem = (INT)wParam;
594 TRACE("[iItem=%d]\n", iItem);
596 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
599 if (infoPtr->uNumItem == 1) {
600 TRACE("Simple delete!\n");
601 if (infoPtr->items[0].pszText)
602 Free (infoPtr->items[0].pszText);
603 Free (infoPtr->items);
605 infoPtr->uNumItem = 0;
608 HEADER_ITEM *oldItems = infoPtr->items;
612 TRACE("Complex delete! [iItem=%d]\n", iItem);
614 if (infoPtr->items[iItem].pszText)
615 Free (infoPtr->items[iItem].pszText);
616 iOrder = infoPtr->items[iItem].iOrder;
619 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
620 /* pre delete copy */
622 memcpy (&infoPtr->items[0], &oldItems[0],
623 iItem * sizeof(HEADER_ITEM));
626 /* post delete copy */
627 if (iItem < infoPtr->uNumItem) {
628 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
629 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
632 /* Correct the orders */
633 for (i=infoPtr->uNumItem, pItem = infoPtr->items; i; i--, pItem++)
635 if (pItem->iOrder > iOrder)
641 HEADER_SetItemBounds (hwnd);
643 InvalidateRect(hwnd, NULL, FALSE);
650 HEADER_GetImageList (HWND hwnd)
652 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
654 return (LRESULT)infoPtr->himl;
659 HEADER_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
661 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
662 HDITEMA *phdi = (HDITEMA*)lParam;
663 INT nItem = (INT)wParam;
668 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
671 TRACE("[nItem=%d]\n", nItem);
676 lpItem = &infoPtr->items[nItem];
677 if (phdi->mask & HDI_BITMAP)
678 phdi->hbm = lpItem->hbm;
680 if (phdi->mask & HDI_FORMAT)
681 phdi->fmt = lpItem->fmt;
683 if (phdi->mask & HDI_WIDTH)
684 phdi->cxy = lpItem->cxy;
686 if (phdi->mask & HDI_LPARAM)
687 phdi->lParam = lpItem->lParam;
689 if (phdi->mask & HDI_TEXT) {
690 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
692 WideCharToMultiByte (CP_ACP, 0, lpItem->pszText, -1,
693 phdi->pszText, phdi->cchTextMax, NULL, NULL);
698 phdi->pszText = LPSTR_TEXTCALLBACKA;
701 if (phdi->mask & HDI_IMAGE)
702 phdi->iImage = lpItem->iImage;
704 if (phdi->mask & HDI_ORDER)
705 phdi->iOrder = lpItem->iOrder;
712 HEADER_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
714 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
715 HDITEMW *phdi = (HDITEMW*)lParam;
716 INT nItem = (INT)wParam;
721 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
724 TRACE("[nItem=%d]\n", nItem);
729 lpItem = &infoPtr->items[nItem];
730 if (phdi->mask & HDI_BITMAP)
731 phdi->hbm = lpItem->hbm;
733 if (phdi->mask & HDI_FORMAT)
734 phdi->fmt = lpItem->fmt;
736 if (phdi->mask & HDI_WIDTH)
737 phdi->cxy = lpItem->cxy;
739 if (phdi->mask & HDI_LPARAM)
740 phdi->lParam = lpItem->lParam;
742 if (phdi->mask & HDI_TEXT) {
743 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
745 lstrcpynW (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
750 phdi->pszText = LPSTR_TEXTCALLBACKW;
753 if (phdi->mask & HDI_IMAGE)
754 phdi->iImage = lpItem->iImage;
756 if (phdi->mask & HDI_ORDER)
757 phdi->iOrder = lpItem->iOrder;
763 inline static LRESULT
764 HEADER_GetItemCount (HWND hwnd)
766 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
767 return infoPtr->uNumItem;
772 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
774 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
775 INT iItem = (INT)wParam;
776 LPRECT lpRect = (LPRECT)lParam;
778 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
781 lpRect->left = infoPtr->items[iItem].rect.left;
782 lpRect->right = infoPtr->items[iItem].rect.right;
783 lpRect->top = infoPtr->items[iItem].rect.top;
784 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
791 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
794 LPINT order = (LPINT) lParam;
795 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
797 if ((int)wParam <infoPtr->uNumItem)
799 for (i=0; i<(int)wParam; i++)
800 *order++=HEADER_OrderToIndex(hwnd,i);
805 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
808 LPINT order = (LPINT) lParam;
809 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
812 if ((int)wParam <infoPtr->uNumItem)
814 for (i=0; i<(int)wParam; i++)
816 lpItem = &infoPtr->items[*order++];
819 infoPtr->bRectsValid=0;
820 InvalidateRect(hwnd, NULL, FALSE);
824 inline static LRESULT
825 HEADER_GetUnicodeFormat (HWND hwnd)
827 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
828 return infoPtr->bUnicode;
833 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
835 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
837 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
839 if (phti->flags == HHT_ONHEADER)
847 HEADER_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
849 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
850 HDITEMA *phdi = (HDITEMA*)lParam;
851 INT nItem = (INT)wParam;
855 if ((phdi == NULL) || (nItem < 0))
858 if (nItem > infoPtr->uNumItem)
859 nItem = infoPtr->uNumItem;
861 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
863 if (infoPtr->uNumItem == 0) {
864 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
868 HEADER_ITEM *oldItems = infoPtr->items;
871 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
873 memcpy (&infoPtr->items[1], &oldItems[0],
874 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
878 /* pre insert copy */
880 memcpy (&infoPtr->items[0], &oldItems[0],
881 nItem * sizeof(HEADER_ITEM));
884 /* post insert copy */
885 if (nItem < infoPtr->uNumItem - 1) {
886 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
887 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
894 for (i=0; i < infoPtr->uNumItem; i++)
896 if (infoPtr->items[i].iOrder >= iOrder)
897 infoPtr->items[i].iOrder++;
900 lpItem = &infoPtr->items[nItem];
901 lpItem->bDown = FALSE;
903 if (phdi->mask & HDI_WIDTH)
904 lpItem->cxy = phdi->cxy;
906 if (phdi->mask & HDI_TEXT) {
907 static char empty[] = "";
908 if (!phdi->pszText) /* null pointer check */
909 phdi->pszText = empty;
910 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
911 len = MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, NULL, 0);
912 lpItem->pszText = Alloc( len*sizeof(WCHAR) );
913 MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, lpItem->pszText, len);
916 lpItem->pszText = LPSTR_TEXTCALLBACKW;
919 if (phdi->mask & HDI_FORMAT)
920 lpItem->fmt = phdi->fmt;
922 if (lpItem->fmt == 0)
923 lpItem->fmt = HDF_LEFT;
925 if (!(lpItem->fmt & HDF_STRING) && (phdi->mask & HDI_TEXT))
927 lpItem->fmt |= HDF_STRING;
929 if (phdi->mask & HDI_BITMAP)
930 lpItem->hbm = phdi->hbm;
932 if (phdi->mask & HDI_LPARAM)
933 lpItem->lParam = phdi->lParam;
935 if (phdi->mask & HDI_IMAGE)
936 lpItem->iImage = phdi->iImage;
938 lpItem->iOrder = iOrder;
940 HEADER_SetItemBounds (hwnd);
942 InvalidateRect(hwnd, NULL, FALSE);
949 HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
951 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
952 HDITEMW *phdi = (HDITEMW*)lParam;
953 INT nItem = (INT)wParam;
957 if ((phdi == NULL) || (nItem < 0))
960 if (nItem > infoPtr->uNumItem)
961 nItem = infoPtr->uNumItem;
963 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
965 if (infoPtr->uNumItem == 0) {
966 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
970 HEADER_ITEM *oldItems = infoPtr->items;
973 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
975 memcpy (&infoPtr->items[1], &oldItems[0],
976 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
980 /* pre insert copy */
982 memcpy (&infoPtr->items[0], &oldItems[0],
983 nItem * sizeof(HEADER_ITEM));
986 /* post insert copy */
987 if (nItem < infoPtr->uNumItem - 1) {
988 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
989 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
996 for (i=0; i < infoPtr->uNumItem; i++)
998 if (infoPtr->items[i].iOrder >= iOrder)
999 infoPtr->items[i].iOrder++;
1002 lpItem = &infoPtr->items[nItem];
1003 lpItem->bDown = FALSE;
1005 if (phdi->mask & HDI_WIDTH)
1006 lpItem->cxy = phdi->cxy;
1008 if (phdi->mask & HDI_TEXT) {
1009 WCHAR wide_null_char = 0;
1010 if (!phdi->pszText) /* null pointer check */
1011 phdi->pszText = &wide_null_char;
1012 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1013 len = strlenW (phdi->pszText);
1014 lpItem->pszText = Alloc ((len+1)*sizeof(WCHAR));
1015 strcpyW (lpItem->pszText, phdi->pszText);
1018 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1021 if (phdi->mask & HDI_FORMAT)
1022 lpItem->fmt = phdi->fmt;
1024 if (lpItem->fmt == 0)
1025 lpItem->fmt = HDF_LEFT;
1027 if (!(lpItem->fmt &HDF_STRING) && (phdi->mask & HDI_TEXT))
1029 lpItem->fmt |= HDF_STRING;
1031 if (phdi->mask & HDI_BITMAP)
1032 lpItem->hbm = phdi->hbm;
1034 if (phdi->mask & HDI_LPARAM)
1035 lpItem->lParam = phdi->lParam;
1037 if (phdi->mask & HDI_IMAGE)
1038 lpItem->iImage = phdi->iImage;
1040 lpItem->iOrder = iOrder;
1042 HEADER_SetItemBounds (hwnd);
1044 InvalidateRect(hwnd, NULL, FALSE);
1051 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
1053 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1054 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1056 lpLayout->pwpos->hwnd = hwnd;
1057 lpLayout->pwpos->hwndInsertAfter = 0;
1058 lpLayout->pwpos->x = lpLayout->prc->left;
1059 lpLayout->pwpos->y = lpLayout->prc->top;
1060 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1061 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_HIDDEN)
1062 lpLayout->pwpos->cy = 0;
1064 lpLayout->pwpos->cy = infoPtr->nHeight;
1065 lpLayout->prc->top += infoPtr->nHeight;
1067 lpLayout->pwpos->flags = SWP_NOZORDER;
1069 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1070 lpLayout->pwpos->x, lpLayout->pwpos->y,
1071 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1073 infoPtr->bRectsValid = FALSE;
1080 HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
1082 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1085 TRACE("(himl 0x%x)\n", (int)himl);
1086 himlOld = infoPtr->himl;
1087 infoPtr->himl = himl;
1089 /* FIXME: Refresh needed??? */
1091 return (LRESULT)himlOld;
1096 HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1098 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1099 HDITEMA *phdi = (HDITEMA*)lParam;
1100 INT nItem = (INT)wParam;
1101 HEADER_ITEM *lpItem;
1105 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1108 TRACE("[nItem=%d]\n", nItem);
1110 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem, phdi->mask))
1113 lpItem = &infoPtr->items[nItem];
1114 if (phdi->mask & HDI_BITMAP)
1115 lpItem->hbm = phdi->hbm;
1117 if (phdi->mask & HDI_FORMAT)
1118 lpItem->fmt = phdi->fmt;
1120 if (phdi->mask & HDI_LPARAM)
1121 lpItem->lParam = phdi->lParam;
1123 if (phdi->mask & HDI_TEXT) {
1124 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
1125 if (lpItem->pszText) {
1126 Free (lpItem->pszText);
1127 lpItem->pszText = NULL;
1129 if (phdi->pszText) {
1130 INT len = MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,NULL,0);
1131 lpItem->pszText = Alloc( len*sizeof(WCHAR) );
1132 MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,lpItem->pszText,len);
1136 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1139 if (phdi->mask & HDI_WIDTH)
1140 lpItem->cxy = phdi->cxy;
1142 if (phdi->mask & HDI_IMAGE)
1143 lpItem->iImage = phdi->iImage;
1145 if (phdi->mask & HDI_ORDER)
1147 lpItem->iOrder = phdi->iOrder;
1150 lpItem->iOrder = nItem;
1152 HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem, phdi->mask);
1154 HEADER_SetItemBounds (hwnd);
1156 InvalidateRect(hwnd, NULL, FALSE);
1163 HEADER_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1165 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1166 HDITEMW *phdi = (HDITEMW*)lParam;
1167 INT nItem = (INT)wParam;
1168 HEADER_ITEM *lpItem;
1172 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1175 TRACE("[nItem=%d]\n", nItem);
1177 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask))
1180 lpItem = &infoPtr->items[nItem];
1181 if (phdi->mask & HDI_BITMAP)
1182 lpItem->hbm = phdi->hbm;
1184 if (phdi->mask & HDI_FORMAT)
1185 lpItem->fmt = phdi->fmt;
1187 if (phdi->mask & HDI_LPARAM)
1188 lpItem->lParam = phdi->lParam;
1190 if (phdi->mask & HDI_TEXT) {
1191 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1192 if (lpItem->pszText) {
1193 Free (lpItem->pszText);
1194 lpItem->pszText = NULL;
1196 if (phdi->pszText) {
1197 INT len = strlenW (phdi->pszText);
1198 lpItem->pszText = Alloc ((len+1)*sizeof(WCHAR));
1199 strcpyW (lpItem->pszText, phdi->pszText);
1203 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1206 if (phdi->mask & HDI_WIDTH)
1207 lpItem->cxy = phdi->cxy;
1209 if (phdi->mask & HDI_IMAGE)
1210 lpItem->iImage = phdi->iImage;
1212 if (phdi->mask & HDI_ORDER)
1214 lpItem->iOrder = phdi->iOrder;
1217 lpItem->iOrder = nItem;
1219 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDW, nItem, phdi->mask);
1221 HEADER_SetItemBounds (hwnd);
1223 InvalidateRect(hwnd, NULL, FALSE);
1228 inline static LRESULT
1229 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1231 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1232 BOOL bTemp = infoPtr->bUnicode;
1234 infoPtr->bUnicode = (BOOL)wParam;
1241 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1243 HEADER_INFO *infoPtr;
1248 infoPtr = (HEADER_INFO *)Alloc (sizeof(HEADER_INFO));
1249 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1251 infoPtr->hwndNotify = GetParent(hwnd);
1252 infoPtr->uNumItem = 0;
1255 infoPtr->bRectsValid = FALSE;
1256 infoPtr->hcurArrow = LoadCursorA (0, (LPSTR)IDC_ARROW);
1257 infoPtr->hcurDivider = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDER));
1258 infoPtr->hcurDivopen = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDEROPEN));
1259 infoPtr->bPressed = FALSE;
1260 infoPtr->bTracking = FALSE;
1261 infoPtr->iMoveItem = 0;
1263 infoPtr->iHotItem = -1;
1264 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1265 infoPtr->nNotifyFormat =
1266 SendMessageA (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1269 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1270 GetTextMetricsA (hdc, &tm);
1271 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1272 SelectObject (hdc, hOldFont);
1280 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1282 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1283 HEADER_ITEM *lpItem;
1286 if (infoPtr->items) {
1287 lpItem = infoPtr->items;
1288 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1289 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
1290 Free (lpItem->pszText);
1292 Free (infoPtr->items);
1296 ImageList_Destroy (infoPtr->himl);
1299 SetWindowLongA (hwnd, 0, 0);
1304 static inline LRESULT
1305 HEADER_GetFont (HWND hwnd)
1307 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1309 return (LRESULT)infoPtr->hFont;
1314 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1320 pt.x = (INT)LOWORD(lParam);
1321 pt.y = (INT)HIWORD(lParam);
1322 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1324 if ((GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1325 HEADER_SendHeaderNotify (hwnd, HDN_ITEMDBLCLICKA, nItem,0);
1326 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1327 HEADER_SendHeaderNotify (hwnd, HDN_DIVIDERDBLCLICKA, nItem,0);
1334 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1336 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1337 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1343 pt.x = (INT)LOWORD(lParam);
1344 pt.y = (INT)HIWORD(lParam);
1345 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1347 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1349 infoPtr->bCaptured = TRUE;
1350 infoPtr->bPressed = TRUE;
1351 infoPtr->iMoveItem = nItem;
1353 infoPtr->items[nItem].bDown = TRUE;
1355 /* Send WM_CUSTOMDRAW */
1357 HEADER_RefreshItem (hwnd, hdc, nItem);
1358 ReleaseDC (hwnd, hdc);
1360 TRACE("Pressed item %d!\n", nItem);
1362 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1363 if (!(HEADER_SendHeaderNotify (hwnd, HDN_BEGINTRACKA, nItem,0))) {
1365 infoPtr->bCaptured = TRUE;
1366 infoPtr->bTracking = TRUE;
1367 infoPtr->iMoveItem = nItem;
1368 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1369 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1371 if (!(dwStyle & HDS_FULLDRAG)) {
1372 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1374 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1375 ReleaseDC (hwnd, hdc);
1378 TRACE("Begin tracking item %d!\n", nItem);
1387 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1389 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1391 *DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1398 pt.x = (INT)(SHORT)LOWORD(lParam);
1399 pt.y = (INT)(SHORT)HIWORD(lParam);
1400 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1402 if (infoPtr->bPressed) {
1403 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1404 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1406 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1407 ReleaseDC (hwnd, hdc);
1409 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1411 else if (flags == HHT_ONHEADER)
1413 HEADER_ITEM *lpItem;
1414 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1415 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1417 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1418 infoPtr->iMoveItem,oldindex,nItem,newindex);
1419 lpItem= &infoPtr->items[nItem];
1420 lpItem->iOrder=oldindex;
1422 lpItem= &infoPtr->items[infoPtr->iMoveItem];
1423 lpItem->iOrder = newindex;
1425 infoPtr->bRectsValid = FALSE;
1426 InvalidateRect(hwnd, NULL, FALSE);
1427 /* FIXME: Should some WM_NOTIFY be sent */
1430 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1431 infoPtr->bPressed = FALSE;
1433 else if (infoPtr->bTracking) {
1434 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1435 infoPtr->bTracking = FALSE;
1437 HEADER_SendHeaderNotify (hwnd, HDN_ENDTRACKA, infoPtr->iMoveItem,HDI_WIDTH);
1440 * we want to do this even for HDS_FULLDRAG because this is where
1441 * we send the HDN_ITEMCHANGING and HDN_ITEMCHANGED notifications
1443 * if (!(dwStyle & HDS_FULLDRAG)) {
1447 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1448 ReleaseDC (hwnd, hdc);
1449 if (HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1451 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1454 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1457 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1460 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH);
1461 HEADER_SetItemBounds (hwnd);
1462 InvalidateRect(hwnd, NULL, FALSE);
1468 if (infoPtr->bCaptured) {
1469 infoPtr->bCaptured = FALSE;
1471 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1479 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1481 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1486 return infoPtr->nNotifyFormat;
1489 infoPtr->nNotifyFormat =
1490 SendMessageA ((HWND)wParam, WM_NOTIFYFORMAT,
1491 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1492 return infoPtr->nNotifyFormat;
1500 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1502 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1503 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1509 pt.x = (INT)(SHORT)LOWORD(lParam);
1510 pt.y = (INT)(SHORT)HIWORD(lParam);
1511 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1513 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1514 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1515 infoPtr->iHotItem = nItem;
1517 infoPtr->iHotItem = -1;
1518 InvalidateRect(hwnd, NULL, FALSE);
1521 if (infoPtr->bCaptured) {
1522 if (infoPtr->bPressed) {
1523 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1524 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1526 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1528 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1529 ReleaseDC (hwnd, hdc);
1531 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1533 else if (infoPtr->bTracking) {
1534 if (dwStyle & HDS_FULLDRAG) {
1535 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1537 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1540 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1541 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1543 HEADER_SetItemBounds (hwnd);
1544 InvalidateRect(hwnd, NULL, FALSE);
1548 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1549 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1550 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1551 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1552 infoPtr->items[infoPtr->iMoveItem].cxy =
1553 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1554 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1555 ReleaseDC (hwnd, hdc);
1556 HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH);
1559 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1563 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1564 FIXME("hot track support!\n");
1572 HEADER_Paint (HWND hwnd, WPARAM wParam)
1577 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1578 HEADER_Refresh (hwnd, hdc);
1580 EndPaint (hwnd, &ps);
1586 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1591 pt.x = LOWORD(lParam);
1592 pt.y = HIWORD(lParam);
1594 /* Send a Notify message */
1595 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1597 /* Change to screen coordinate for WM_CONTEXTMENU */
1598 ClientToScreen(hwnd, &pt);
1600 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1601 SendMessageA( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1608 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1610 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1615 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1618 ScreenToClient (hwnd, &pt);
1620 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1622 if (flags == HHT_ONDIVIDER)
1623 SetCursor (infoPtr->hcurDivider);
1624 else if (flags == HHT_ONDIVOPEN)
1625 SetCursor (infoPtr->hcurDivopen);
1627 SetCursor (infoPtr->hcurArrow);
1634 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1636 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1638 HFONT hFont, hOldFont;
1641 infoPtr->hFont = (HFONT)wParam;
1643 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1646 hOldFont = SelectObject (hdc, hFont);
1647 GetTextMetricsA (hdc, &tm);
1648 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1649 SelectObject (hdc, hOldFont);
1652 infoPtr->bRectsValid = FALSE;
1655 InvalidateRect(hwnd, NULL, FALSE);
1662 static LRESULT WINAPI
1663 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1665 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1666 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1667 return DefWindowProcA (hwnd, msg, wParam, lParam);
1669 /* case HDM_CLEARFILTER: */
1671 case HDM_CREATEDRAGIMAGE:
1672 return HEADER_CreateDragImage (hwnd, wParam);
1674 case HDM_DELETEITEM:
1675 return HEADER_DeleteItem (hwnd, wParam);
1677 /* case HDM_EDITFILTER: */
1679 /* case HDM_GETBITMAPMARGIN: */
1681 case HDM_GETIMAGELIST:
1682 return HEADER_GetImageList (hwnd);
1685 return HEADER_GetItemA (hwnd, wParam, lParam);
1688 return HEADER_GetItemW (hwnd, wParam, lParam);
1690 case HDM_GETITEMCOUNT:
1691 return HEADER_GetItemCount (hwnd);
1693 case HDM_GETITEMRECT:
1694 return HEADER_GetItemRect (hwnd, wParam, lParam);
1696 case HDM_GETORDERARRAY:
1697 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1699 case HDM_GETUNICODEFORMAT:
1700 return HEADER_GetUnicodeFormat (hwnd);
1703 return HEADER_HitTest (hwnd, wParam, lParam);
1705 case HDM_INSERTITEMA:
1706 return HEADER_InsertItemA (hwnd, wParam, lParam);
1708 case HDM_INSERTITEMW:
1709 return HEADER_InsertItemW (hwnd, wParam, lParam);
1712 return HEADER_Layout (hwnd, wParam, lParam);
1714 case HDM_ORDERTOINDEX:
1715 return HEADER_OrderToIndex(hwnd, wParam);
1717 /* case HDM_SETBITMAPMARGIN: */
1719 /* case HDM_SETFILTERCHANGETIMEOUT: */
1721 /* case HDM_SETHOTDIVIDER: */
1723 case HDM_SETIMAGELIST:
1724 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
1727 return HEADER_SetItemA (hwnd, wParam, lParam);
1730 return HEADER_SetItemW (hwnd, wParam, lParam);
1732 case HDM_SETORDERARRAY:
1733 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1735 case HDM_SETUNICODEFORMAT:
1736 return HEADER_SetUnicodeFormat (hwnd, wParam);
1739 return HEADER_Create (hwnd, wParam, lParam);
1742 return HEADER_Destroy (hwnd, wParam, lParam);
1748 return DLGC_WANTTAB | DLGC_WANTARROWS;
1751 return HEADER_GetFont (hwnd);
1753 case WM_LBUTTONDBLCLK:
1754 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1756 case WM_LBUTTONDOWN:
1757 return HEADER_LButtonDown (hwnd, wParam, lParam);
1760 return HEADER_LButtonUp (hwnd, wParam, lParam);
1763 return HEADER_MouseMove (hwnd, wParam, lParam);
1765 case WM_NOTIFYFORMAT:
1766 return HEADER_NotifyFormat (hwnd, wParam, lParam);
1769 return HEADER_Size (hwnd, wParam);
1772 return HEADER_Paint (hwnd, wParam);
1775 return HEADER_RButtonUp (hwnd, wParam, lParam);
1778 return HEADER_SetCursor (hwnd, wParam, lParam);
1781 return HEADER_SetFont (hwnd, wParam, lParam);
1784 if ((msg >= WM_USER) && (msg < WM_APP))
1785 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1786 msg, wParam, lParam );
1787 return DefWindowProcA (hwnd, msg, wParam, lParam);
1794 HEADER_Register (void)
1798 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1799 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1800 wndClass.lpfnWndProc = (WNDPROC)HEADER_WindowProc;
1801 wndClass.cbClsExtra = 0;
1802 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1803 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
1804 wndClass.lpszClassName = WC_HEADERA;
1806 RegisterClassA (&wndClass);
1811 HEADER_Unregister (void)
1813 UnregisterClassA (WC_HEADERA, NULL);