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
31 * - Little flaw when drawing a bitmap on the right side of the text.
37 #include "wine/unicode.h"
40 #include "imagelist.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(header);
53 INT iOrder; /* see documentation of HD_ITEM */
55 BOOL bDown; /* is item pressed? (used for drawing) */
56 RECT rect; /* bounding rectangle of the item */
62 HWND hwndNotify; /* Owner window to send notifications to */
63 INT nNotifyFormat; /* format used for WM_NOTIFY messages */
64 UINT uNumItem; /* number of items (columns) */
65 INT nHeight; /* height of the header (pixels) */
66 HFONT hFont; /* handle to the current font */
67 HCURSOR hcurArrow; /* handle to the arrow cursor */
68 HCURSOR hcurDivider; /* handle to a cursor (used over dividers) <-|-> */
69 HCURSOR hcurDivopen; /* handle to a cursor (used over dividers) <-||-> */
70 BOOL bCaptured; /* Is the mouse captured? */
71 BOOL bPressed; /* Is a header item pressed (down)? */
72 BOOL bTracking; /* Is in tracking mode? */
73 BOOL bUnicode; /* Unicode flag */
74 INT iMoveItem; /* index of tracked item. (Tracking mode) */
75 INT xTrackOffset; /* distance between the right side of the tracked item and the cursor */
76 INT xOldTrack; /* track offset (see above) after the last WM_MOUSEMOVE */
77 INT nOldWidth; /* width of a sizing item after the last WM_MOUSEMOVE */
78 INT iHotItem; /* index of hot item (cursor is over this item) */
80 HIMAGELIST himl; /* handle to a image list (may be 0) */
81 HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */
82 BOOL bRectsValid; /* validity flag for bounding rectangles */
87 #define DIVIDER_WIDTH 10
89 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongA(hwnd,0))
93 HEADER_IndexToOrder (HWND hwnd, INT iItem)
95 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
96 HEADER_ITEM *lpItem = (HEADER_ITEM*)&infoPtr->items[iItem];
97 return lpItem->iOrder;
102 HEADER_OrderToIndex(HWND hwnd, WPARAM wParam)
104 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
105 INT i,iorder = (INT)wParam;
108 if ((iorder <0) || iorder >infoPtr->uNumItem)
110 for (i=0; i<infoPtr->uNumItem; i++)
111 if (HEADER_IndexToOrder(hwnd,i) == iorder)
117 HEADER_SetItemBounds (HWND hwnd)
119 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
124 infoPtr->bRectsValid = TRUE;
126 if (infoPtr->uNumItem == 0)
129 GetClientRect (hwnd, &rect);
132 for (i = 0; i < infoPtr->uNumItem; i++) {
133 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
134 phdi->rect.top = rect.top;
135 phdi->rect.bottom = rect.bottom;
137 phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
138 x = phdi->rect.right;
143 HEADER_Size (HWND hwnd, WPARAM wParam)
145 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
147 infoPtr->bRectsValid = FALSE;
154 HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
156 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
157 HEADER_ITEM *phdi = &infoPtr->items[iItem];
161 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, infoPtr->bUnicode);
163 if (!infoPtr->bRectsValid)
164 HEADER_SetItemBounds(hwnd);
167 if (r.right - r.left == 0)
168 return phdi->rect.right;
170 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) {
172 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
173 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
178 DrawEdge (hdc, &r, EDGE_RAISED,
179 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
182 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
184 if (phdi->fmt & HDF_OWNERDRAW) {
186 dis.CtlType = ODT_HEADER;
187 dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
189 dis.itemAction = ODA_DRAWENTIRE;
190 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
194 dis.itemData = phdi->lParam;
195 oldBkMode = SetBkMode(hdc, TRANSPARENT);
196 SendMessageA (GetParent (hwnd), WM_DRAWITEM,
197 (WPARAM)dis.CtlID, (LPARAM)&dis);
198 if (oldBkMode != TRANSPARENT)
199 SetBkMode(hdc, oldBkMode);
202 UINT uTextJustify = DT_LEFT;
204 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
205 uTextJustify = DT_CENTER;
206 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
207 uTextJustify = DT_RIGHT;
209 if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
212 INT yD, yS, cx, cy, rx, ry;
214 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
216 ry = r.bottom - r.top;
217 rx = r.right - r.left;
219 if (ry >= bmp.bmHeight) {
221 yD = r.top + (ry - bmp.bmHeight) / 2;
227 yS = (bmp.bmHeight - ry) / 2;
231 if (rx >= bmp.bmWidth + 6) {
238 hdcBitmap = CreateCompatibleDC (hdc);
239 SelectObject (hdcBitmap, phdi->hbm);
240 BitBlt (hdc, r.left + 3, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
241 DeleteDC (hdcBitmap);
243 r.left += (bmp.bmWidth + 3);
247 if ((phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
250 INT xD, yD, yS, cx, cy, rx, ry, tx;
253 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
256 if (infoPtr->bUnicode)
257 DrawTextW (hdc, phdi->pszText, -1,
258 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
260 DrawTextA (hdc, (LPCSTR)phdi->pszText, -1,
261 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
262 tx = textRect.right - textRect.left;
263 ry = r.bottom - r.top;
264 rx = r.right - r.left;
266 if (ry >= bmp.bmHeight) {
268 yD = r.top + (ry - bmp.bmHeight) / 2;
274 yS = (bmp.bmHeight - ry) / 2;
278 if (r.left + tx + bmp.bmWidth + 9 <= r.right) {
280 xD = r.left + tx + 6;
283 if (rx >= bmp.bmWidth + 6) {
285 xD = r.right - bmp.bmWidth - 3;
295 hdcBitmap = CreateCompatibleDC (hdc);
296 SelectObject (hdcBitmap, phdi->hbm);
297 BitBlt (hdc, xD, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
298 DeleteDC (hdcBitmap);
301 if ((phdi->fmt & HDF_IMAGE) && (infoPtr->himl)) {
303 /* FIXME: (r.bottom- (infoPtr->himl->cy))/2 should horicontal center the image
304 It looks like it doesn't work as expected*/
305 ImageList_Draw (infoPtr->himl, phdi->iImage,hdc,r.left, (r.bottom- (infoPtr->himl->cy))/2,0);
306 r.left += infoPtr->himl->cx;
309 if (((phdi->fmt & HDF_STRING)
310 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
311 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
312 && (phdi->pszText)) {
313 oldBkMode = SetBkMode(hdc, TRANSPARENT);
316 SetTextColor (hdc, (bHotTrack) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
317 if (infoPtr->bUnicode)
318 DrawTextW (hdc, phdi->pszText, -1,
319 &r, uTextJustify|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
321 DrawTextA (hdc, (LPCSTR)phdi->pszText, -1,
322 &r, uTextJustify|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
323 if (oldBkMode != TRANSPARENT)
324 SetBkMode(hdc, oldBkMode);
328 return phdi->rect.right;
333 HEADER_Refresh (HWND hwnd, HDC hdc)
335 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
336 HFONT hFont, hOldFont;
341 /* get rect for the bar, adjusted for the border */
342 GetClientRect (hwnd, &rect);
344 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
345 hOldFont = SelectObject (hdc, hFont);
347 /* draw Background */
348 hbrBk = GetSysColorBrush(COLOR_3DFACE);
349 FillRect(hdc, &rect, hbrBk);
352 for (i = 0; i < infoPtr->uNumItem; i++) {
353 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i), FALSE);
356 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
358 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS)
359 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
361 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
364 SelectObject (hdc, hOldFont);
369 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
371 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
372 HFONT hFont, hOldFont;
374 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
375 hOldFont = SelectObject (hdc, hFont);
376 HEADER_DrawItem (hwnd, hdc, iItem, FALSE);
377 SelectObject (hdc, hOldFont);
382 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
384 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
389 GetClientRect (hwnd, &rect);
393 if (PtInRect (&rect, *lpPt))
395 if (infoPtr->uNumItem == 0) {
396 *pFlags |= HHT_NOWHERE;
402 /* somewhere inside */
403 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
404 rect = infoPtr->items[iCount].rect;
405 width = rect.right - rect.left;
410 if (PtInRect (&rect, *lpPt)) {
411 if (width <= 2 * DIVIDER_WIDTH) {
412 *pFlags |= HHT_ONHEADER;
414 TRACE("ON HEADER %d\n", iCount);
419 rcTest.right = rcTest.left + DIVIDER_WIDTH;
420 if (PtInRect (&rcTest, *lpPt)) {
422 *pFlags |= HHT_ONDIVOPEN;
424 TRACE("ON DIVOPEN %d\n", *pItem);
428 *pFlags |= HHT_ONDIVIDER;
430 TRACE("ON DIVIDER %d\n", *pItem);
436 rcTest.left = rcTest.right - DIVIDER_WIDTH;
437 if (PtInRect (&rcTest, *lpPt)) {
438 *pFlags |= HHT_ONDIVIDER;
440 TRACE("ON DIVIDER %d\n", *pItem);
444 *pFlags |= HHT_ONHEADER;
446 TRACE("ON HEADER %d\n", iCount);
451 /* check for last divider part (on nowhere) */
452 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
453 rect.left = rect.right;
454 rect.right += DIVIDER_WIDTH;
455 if (PtInRect (&rect, *lpPt)) {
457 *pFlags |= HHT_ONDIVOPEN;
458 *pItem = infoPtr->uNumItem - 1;
459 TRACE("ON DIVOPEN %d\n", *pItem);
463 *pFlags |= HHT_ONDIVIDER;
464 *pItem = infoPtr->uNumItem-1;
465 TRACE("ON DIVIDER %d\n", *pItem);
470 *pFlags |= HHT_NOWHERE;
477 if (lpPt->x < rect.left) {
479 *pFlags |= HHT_TOLEFT;
481 else if (lpPt->x > rect.right) {
483 *pFlags |= HHT_TORIGHT;
486 if (lpPt->y < rect.top) {
488 *pFlags |= HHT_ABOVE;
490 else if (lpPt->y > rect.bottom) {
492 *pFlags |= HHT_BELOW;
497 TRACE("flags=0x%X\n", *pFlags);
503 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
509 GetClientRect (hwnd, &rect);
511 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
512 oldRop = SetROP2 (hdc, R2_XORPEN);
513 MoveToEx (hdc, x, rect.top, NULL);
514 LineTo (hdc, x, rect.bottom);
515 SetROP2 (hdc, oldRop);
516 SelectObject (hdc, hOldPen);
521 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
523 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
526 nmhdr.hwndFrom = hwnd;
527 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
530 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
531 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
535 HEADER_SendHeaderNotify (HWND hwnd, UINT code, INT iItem, INT mask)
537 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
541 nmhdr.hdr.hwndFrom = hwnd;
542 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
543 nmhdr.hdr.code = code;
546 nmhdr.pitem = &nmitem;
548 nmitem.cxy = infoPtr->items[iItem].cxy;
549 nmitem.hbm = infoPtr->items[iItem].hbm;
550 nmitem.pszText = NULL;
551 nmitem.cchTextMax = 0;
552 /* nmitem.pszText = infoPtr->items[iItem].pszText; */
553 /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
554 nmitem.fmt = infoPtr->items[iItem].fmt;
555 nmitem.lParam = infoPtr->items[iItem].lParam;
556 nmitem.iOrder = infoPtr->items[iItem].iOrder;
557 nmitem.iImage = infoPtr->items[iItem].iImage;
559 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
560 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
565 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
567 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
570 nmhdr.hdr.hwndFrom = hwnd;
571 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
572 nmhdr.hdr.code = code;
577 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
578 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
583 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
585 FIXME("empty stub!\n");
591 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
593 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
594 INT iItem = (INT)wParam;
596 TRACE("[iItem=%d]\n", iItem);
598 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
601 if (infoPtr->uNumItem == 1) {
602 TRACE("Simple delete!\n");
603 if (infoPtr->items[0].pszText)
604 COMCTL32_Free (infoPtr->items[0].pszText);
605 COMCTL32_Free (infoPtr->items);
607 infoPtr->uNumItem = 0;
610 HEADER_ITEM *oldItems = infoPtr->items;
611 TRACE("Complex delete! [iItem=%d]\n", iItem);
613 if (infoPtr->items[iItem].pszText)
614 COMCTL32_Free (infoPtr->items[iItem].pszText);
617 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
618 /* pre delete copy */
620 memcpy (&infoPtr->items[0], &oldItems[0],
621 iItem * sizeof(HEADER_ITEM));
624 /* post delete copy */
625 if (iItem < infoPtr->uNumItem) {
626 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
627 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
630 COMCTL32_Free (oldItems);
633 HEADER_SetItemBounds (hwnd);
635 InvalidateRect(hwnd, NULL, FALSE);
642 HEADER_GetImageList (HWND hwnd)
644 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
646 return (LRESULT)infoPtr->himl;
651 HEADER_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
653 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
654 HDITEMA *phdi = (HDITEMA*)lParam;
655 INT nItem = (INT)wParam;
660 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
663 TRACE("[nItem=%d]\n", nItem);
668 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
669 if (phdi->mask & HDI_BITMAP)
670 phdi->hbm = lpItem->hbm;
672 if (phdi->mask & HDI_FORMAT)
673 phdi->fmt = lpItem->fmt;
675 if (phdi->mask & HDI_WIDTH)
676 phdi->cxy = lpItem->cxy;
678 if (phdi->mask & HDI_LPARAM)
679 phdi->lParam = lpItem->lParam;
681 if (phdi->mask & HDI_TEXT) {
682 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
684 WideCharToMultiByte (CP_ACP, 0, lpItem->pszText, -1,
685 phdi->pszText, phdi->cchTextMax, NULL, NULL);
690 phdi->pszText = LPSTR_TEXTCALLBACKA;
693 if (phdi->mask & HDI_IMAGE)
694 phdi->iImage = lpItem->iImage;
696 if (phdi->mask & HDI_ORDER)
697 phdi->iOrder = lpItem->iOrder;
704 HEADER_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
706 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
707 HDITEMW *phdi = (HDITEMW*)lParam;
708 INT nItem = (INT)wParam;
713 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
716 TRACE("[nItem=%d]\n", nItem);
721 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
722 if (phdi->mask & HDI_BITMAP)
723 phdi->hbm = lpItem->hbm;
725 if (phdi->mask & HDI_FORMAT)
726 phdi->fmt = lpItem->fmt;
728 if (phdi->mask & HDI_WIDTH)
729 phdi->cxy = lpItem->cxy;
731 if (phdi->mask & HDI_LPARAM)
732 phdi->lParam = lpItem->lParam;
734 if (phdi->mask & HDI_TEXT) {
735 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
737 lstrcpynW (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
742 phdi->pszText = LPSTR_TEXTCALLBACKW;
745 if (phdi->mask & HDI_IMAGE)
746 phdi->iImage = lpItem->iImage;
748 if (phdi->mask & HDI_ORDER)
749 phdi->iOrder = lpItem->iOrder;
755 inline static LRESULT
756 HEADER_GetItemCount (HWND hwnd)
758 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
759 return infoPtr->uNumItem;
764 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
766 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
767 INT iItem = (INT)wParam;
768 LPRECT lpRect = (LPRECT)lParam;
770 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
773 lpRect->left = infoPtr->items[iItem].rect.left;
774 lpRect->right = infoPtr->items[iItem].rect.right;
775 lpRect->top = infoPtr->items[iItem].rect.top;
776 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
783 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
786 LPINT order = (LPINT) lParam;
787 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
789 if ((int)wParam <infoPtr->uNumItem)
791 for (i=0; i<(int)wParam; i++)
792 *order++=HEADER_OrderToIndex(hwnd,i);
797 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
800 LPINT order = (LPINT) lParam;
801 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
804 if ((int)wParam <infoPtr->uNumItem)
806 for (i=0; i<(int)wParam; i++)
808 lpItem = (HEADER_ITEM*)&infoPtr->items[*order++];
811 infoPtr->bRectsValid=0;
812 InvalidateRect(hwnd, NULL, FALSE);
816 inline static LRESULT
817 HEADER_GetUnicodeFormat (HWND hwnd)
819 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
820 return infoPtr->bUnicode;
825 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
827 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
829 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
831 if (phti->flags == HHT_ONHEADER)
839 HEADER_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
841 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
842 HDITEMA *phdi = (HDITEMA*)lParam;
843 INT nItem = (INT)wParam;
847 if ((phdi == NULL) || (nItem < 0))
850 if (nItem > infoPtr->uNumItem)
851 nItem = infoPtr->uNumItem;
853 if (infoPtr->uNumItem == 0) {
854 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
858 HEADER_ITEM *oldItems = infoPtr->items;
861 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
863 memcpy (&infoPtr->items[1], &oldItems[0],
864 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
868 /* pre insert copy */
870 memcpy (&infoPtr->items[0], &oldItems[0],
871 nItem * sizeof(HEADER_ITEM));
874 /* post insert copy */
875 if (nItem < infoPtr->uNumItem - 1) {
876 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
877 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
881 COMCTL32_Free (oldItems);
884 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
885 lpItem->bDown = FALSE;
887 if (phdi->mask & HDI_WIDTH)
888 lpItem->cxy = phdi->cxy;
890 if (phdi->mask & HDI_TEXT) {
891 if (!phdi->pszText) /* null pointer check */
893 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
894 len = MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, NULL, 0);
895 lpItem->pszText = COMCTL32_Alloc( len*sizeof(WCHAR) );
896 MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, lpItem->pszText, len);
899 lpItem->pszText = LPSTR_TEXTCALLBACKW;
902 if (phdi->mask & HDI_FORMAT)
903 lpItem->fmt = phdi->fmt;
905 if (lpItem->fmt == 0)
906 lpItem->fmt = HDF_LEFT;
908 if (!(lpItem->fmt & HDF_STRING) && (phdi->mask & HDI_TEXT))
910 lpItem->fmt |= HDF_STRING;
912 if (phdi->mask & HDI_BITMAP)
913 lpItem->hbm = phdi->hbm;
915 if (phdi->mask & HDI_LPARAM)
916 lpItem->lParam = phdi->lParam;
918 if (phdi->mask & HDI_IMAGE)
919 lpItem->iImage = phdi->iImage;
921 if (phdi->mask & HDI_ORDER)
923 lpItem->iOrder = phdi->iOrder;
926 lpItem->iOrder=nItem;
929 HEADER_SetItemBounds (hwnd);
931 InvalidateRect(hwnd, NULL, FALSE);
938 HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
940 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
941 HDITEMW *phdi = (HDITEMW*)lParam;
942 INT nItem = (INT)wParam;
946 if ((phdi == NULL) || (nItem < 0))
949 if (nItem > infoPtr->uNumItem)
950 nItem = infoPtr->uNumItem;
952 if (infoPtr->uNumItem == 0) {
953 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
957 HEADER_ITEM *oldItems = infoPtr->items;
960 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
961 /* pre insert copy */
963 memcpy (&infoPtr->items[0], &oldItems[0],
964 nItem * sizeof(HEADER_ITEM));
967 /* post insert copy */
968 if (nItem < infoPtr->uNumItem - 1) {
969 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
970 (infoPtr->uNumItem - nItem) * sizeof(HEADER_ITEM));
973 COMCTL32_Free (oldItems);
976 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
977 lpItem->bDown = FALSE;
979 if (phdi->mask & HDI_WIDTH)
980 lpItem->cxy = phdi->cxy;
982 if (phdi->mask & HDI_TEXT) {
983 WCHAR wide_null_char = 0;
984 if (!phdi->pszText) /* null pointer check */
985 phdi->pszText = &wide_null_char;
986 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
987 len = strlenW (phdi->pszText);
988 lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
989 strcpyW (lpItem->pszText, phdi->pszText);
992 lpItem->pszText = LPSTR_TEXTCALLBACKW;
995 if (phdi->mask & HDI_FORMAT)
996 lpItem->fmt = phdi->fmt;
998 if (lpItem->fmt == 0)
999 lpItem->fmt = HDF_LEFT;
1001 if (phdi->mask & HDI_BITMAP)
1002 lpItem->hbm = phdi->hbm;
1004 if (phdi->mask & HDI_LPARAM)
1005 lpItem->lParam = phdi->lParam;
1007 if (phdi->mask & HDI_IMAGE)
1008 lpItem->iImage = phdi->iImage;
1010 if (phdi->mask & HDI_ORDER)
1012 lpItem->iOrder = phdi->iOrder;
1015 lpItem->iOrder = nItem;
1017 HEADER_SetItemBounds (hwnd);
1019 InvalidateRect(hwnd, NULL, FALSE);
1026 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
1028 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1029 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1031 lpLayout->pwpos->hwnd = hwnd;
1032 lpLayout->pwpos->hwndInsertAfter = 0;
1033 lpLayout->pwpos->x = lpLayout->prc->left;
1034 lpLayout->pwpos->y = lpLayout->prc->top;
1035 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1036 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_HIDDEN)
1037 lpLayout->pwpos->cy = 0;
1039 lpLayout->pwpos->cy = infoPtr->nHeight;
1040 lpLayout->prc->top += infoPtr->nHeight;
1042 lpLayout->pwpos->flags = SWP_NOZORDER;
1044 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1045 lpLayout->pwpos->x, lpLayout->pwpos->y,
1046 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1048 infoPtr->bRectsValid = FALSE;
1055 HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
1057 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1060 TRACE("(himl 0x%x)\n", (int)himl);
1061 himlOld = infoPtr->himl;
1062 infoPtr->himl = himl;
1064 /* FIXME: Refresh needed??? */
1066 return (LRESULT)himlOld;
1071 HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1073 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1074 HDITEMA *phdi = (HDITEMA*)lParam;
1075 INT nItem = (INT)wParam;
1076 HEADER_ITEM *lpItem;
1080 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1083 TRACE("[nItem=%d]\n", nItem);
1085 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem, phdi->mask))
1088 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
1089 if (phdi->mask & HDI_BITMAP)
1090 lpItem->hbm = phdi->hbm;
1092 if (phdi->mask & HDI_FORMAT)
1093 lpItem->fmt = phdi->fmt;
1095 if (phdi->mask & HDI_LPARAM)
1096 lpItem->lParam = phdi->lParam;
1098 if (phdi->mask & HDI_TEXT) {
1099 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
1100 if (lpItem->pszText) {
1101 COMCTL32_Free (lpItem->pszText);
1102 lpItem->pszText = NULL;
1104 if (phdi->pszText) {
1105 INT len = MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,NULL,0);
1106 lpItem->pszText = COMCTL32_Alloc( len*sizeof(WCHAR) );
1107 MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,lpItem->pszText,len);
1111 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1114 if (phdi->mask & HDI_WIDTH)
1115 lpItem->cxy = phdi->cxy;
1117 if (phdi->mask & HDI_IMAGE)
1118 lpItem->iImage = phdi->iImage;
1120 if (phdi->mask & HDI_ORDER)
1122 lpItem->iOrder = phdi->iOrder;
1125 lpItem->iOrder = nItem;
1127 HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem, phdi->mask);
1129 HEADER_SetItemBounds (hwnd);
1131 InvalidateRect(hwnd, NULL, FALSE);
1138 HEADER_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1140 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1141 HDITEMW *phdi = (HDITEMW*)lParam;
1142 INT nItem = (INT)wParam;
1143 HEADER_ITEM *lpItem;
1147 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1150 TRACE("[nItem=%d]\n", nItem);
1152 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask))
1155 lpItem = (HEADER_ITEM*)&infoPtr->items[nItem];
1156 if (phdi->mask & HDI_BITMAP)
1157 lpItem->hbm = phdi->hbm;
1159 if (phdi->mask & HDI_FORMAT)
1160 lpItem->fmt = phdi->fmt;
1162 if (phdi->mask & HDI_LPARAM)
1163 lpItem->lParam = phdi->lParam;
1165 if (phdi->mask & HDI_TEXT) {
1166 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1167 if (lpItem->pszText) {
1168 COMCTL32_Free (lpItem->pszText);
1169 lpItem->pszText = NULL;
1171 if (phdi->pszText) {
1172 INT len = strlenW (phdi->pszText);
1173 lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1174 strcpyW (lpItem->pszText, phdi->pszText);
1178 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1181 if (phdi->mask & HDI_WIDTH)
1182 lpItem->cxy = phdi->cxy;
1184 if (phdi->mask & HDI_IMAGE)
1185 lpItem->iImage = phdi->iImage;
1187 if (phdi->mask & HDI_ORDER)
1189 lpItem->iOrder = phdi->iOrder;
1192 lpItem->iOrder = nItem;
1194 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask);
1196 HEADER_SetItemBounds (hwnd);
1198 InvalidateRect(hwnd, NULL, FALSE);
1203 inline static LRESULT
1204 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1206 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1207 BOOL bTemp = infoPtr->bUnicode;
1209 infoPtr->bUnicode = (BOOL)wParam;
1216 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1218 HEADER_INFO *infoPtr;
1223 infoPtr = (HEADER_INFO *)COMCTL32_Alloc (sizeof(HEADER_INFO));
1224 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1226 infoPtr->hwndNotify = GetParent(hwnd);
1227 infoPtr->uNumItem = 0;
1228 infoPtr->nHeight = 20;
1231 infoPtr->bRectsValid = FALSE;
1232 infoPtr->hcurArrow = LoadCursorA (0, IDC_ARROWA);
1233 infoPtr->hcurDivider = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDER));
1234 infoPtr->hcurDivopen = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDEROPEN));
1235 infoPtr->bPressed = FALSE;
1236 infoPtr->bTracking = FALSE;
1237 infoPtr->iMoveItem = 0;
1239 infoPtr->iHotItem = -1;
1240 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1241 infoPtr->nNotifyFormat =
1242 SendMessageA (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1245 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1246 GetTextMetricsA (hdc, &tm);
1247 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1248 SelectObject (hdc, hOldFont);
1256 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1258 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1259 HEADER_ITEM *lpItem;
1262 if (infoPtr->items) {
1263 lpItem = (HEADER_ITEM*)infoPtr->items;
1264 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1265 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
1266 COMCTL32_Free (lpItem->pszText);
1268 COMCTL32_Free (infoPtr->items);
1272 ImageList_Destroy (infoPtr->himl);
1274 COMCTL32_Free (infoPtr);
1275 SetWindowLongA (hwnd, 0, 0);
1280 static inline LRESULT
1281 HEADER_GetFont (HWND hwnd)
1283 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1285 return (LRESULT)infoPtr->hFont;
1290 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1296 pt.x = (INT)LOWORD(lParam);
1297 pt.y = (INT)HIWORD(lParam);
1298 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1300 if ((GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1301 HEADER_SendHeaderNotify (hwnd, HDN_ITEMDBLCLICKA, nItem,0);
1302 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1303 HEADER_SendHeaderNotify (hwnd, HDN_DIVIDERDBLCLICKA, nItem,0);
1310 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1312 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1313 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1319 pt.x = (INT)LOWORD(lParam);
1320 pt.y = (INT)HIWORD(lParam);
1321 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1323 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1325 infoPtr->bCaptured = TRUE;
1326 infoPtr->bPressed = TRUE;
1327 infoPtr->iMoveItem = nItem;
1329 infoPtr->items[nItem].bDown = TRUE;
1331 /* Send WM_CUSTOMDRAW */
1333 HEADER_RefreshItem (hwnd, hdc, nItem);
1334 ReleaseDC (hwnd, hdc);
1336 TRACE("Pressed item %d!\n", nItem);
1338 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1339 if (!(HEADER_SendHeaderNotify (hwnd, HDN_BEGINTRACKA, nItem,0))) {
1341 infoPtr->bCaptured = TRUE;
1342 infoPtr->bTracking = TRUE;
1343 infoPtr->iMoveItem = nItem;
1344 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1345 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1347 if (!(dwStyle & HDS_FULLDRAG)) {
1348 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1350 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1351 ReleaseDC (hwnd, hdc);
1354 TRACE("Begin tracking item %d!\n", nItem);
1363 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1365 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1367 *DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1374 pt.x = (INT)SLOWORD(lParam);
1375 pt.y = (INT)SHIWORD(lParam);
1376 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1378 if (infoPtr->bPressed) {
1379 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1380 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1382 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1383 ReleaseDC (hwnd, hdc);
1385 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1387 else if (flags == HHT_ONHEADER)
1389 HEADER_ITEM *lpItem;
1390 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1391 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1393 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1394 infoPtr->iMoveItem,oldindex,nItem,newindex);
1395 lpItem= (HEADER_ITEM*)&infoPtr->items[nItem];
1396 lpItem->iOrder=oldindex;
1398 lpItem= (HEADER_ITEM*)&infoPtr->items[infoPtr->iMoveItem];
1399 lpItem->iOrder = newindex;
1401 infoPtr->bRectsValid = FALSE;
1402 InvalidateRect(hwnd, NULL, FALSE);
1403 /* FIXME: Should some WM_NOTIFY be sent */
1406 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1407 infoPtr->bPressed = FALSE;
1409 else if (infoPtr->bTracking) {
1410 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1411 infoPtr->bTracking = FALSE;
1413 HEADER_SendHeaderNotify (hwnd, HDN_ENDTRACKA, infoPtr->iMoveItem,HDI_WIDTH);
1416 * we want to do this even for HDS_FULLDRAG because this is where
1417 * we send the HDN_ITEMCHANGING and HDN_ITEMCHANGED notifications
1419 * if (!(dwStyle & HDS_FULLDRAG)) {
1423 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1424 ReleaseDC (hwnd, hdc);
1425 if (HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1427 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1430 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1433 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1436 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH);
1437 HEADER_SetItemBounds (hwnd);
1438 InvalidateRect(hwnd, NULL, FALSE);
1444 if (infoPtr->bCaptured) {
1445 infoPtr->bCaptured = FALSE;
1447 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1455 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1457 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1462 return infoPtr->nNotifyFormat;
1465 infoPtr->nNotifyFormat =
1466 SendMessageA ((HWND)wParam, WM_NOTIFYFORMAT,
1467 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1468 return infoPtr->nNotifyFormat;
1476 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1478 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1479 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1485 pt.x = (INT)SLOWORD(lParam);
1486 pt.y = (INT)SHIWORD(lParam);
1487 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1489 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1490 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1491 infoPtr->iHotItem = nItem;
1493 infoPtr->iHotItem = -1;
1494 InvalidateRect(hwnd, NULL, FALSE);
1497 if (infoPtr->bCaptured) {
1498 if (infoPtr->bPressed) {
1499 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1500 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1502 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1504 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1505 ReleaseDC (hwnd, hdc);
1507 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1509 else if (infoPtr->bTracking) {
1510 if (dwStyle & HDS_FULLDRAG) {
1511 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1513 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1516 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1517 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1519 HEADER_SetItemBounds (hwnd);
1520 InvalidateRect(hwnd, NULL, FALSE);
1524 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1525 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1526 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1527 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1528 infoPtr->items[infoPtr->iMoveItem].cxy =
1529 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1530 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1531 ReleaseDC (hwnd, hdc);
1532 HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH);
1535 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1539 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1540 FIXME("hot track support!\n");
1548 HEADER_Paint (HWND hwnd, WPARAM wParam)
1553 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1554 HEADER_Refresh (hwnd, hdc);
1556 EndPaint (hwnd, &ps);
1562 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1567 pt.x = LOWORD(lParam);
1568 pt.y = HIWORD(lParam);
1570 /* Send a Notify message */
1571 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1573 /* Change to screen coordinate for WM_CONTEXTMENU */
1574 ClientToScreen(hwnd, &pt);
1576 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1577 SendMessageA( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1584 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1586 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1591 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1594 ScreenToClient (hwnd, &pt);
1596 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1598 if (flags == HHT_ONDIVIDER)
1599 SetCursor (infoPtr->hcurDivider);
1600 else if (flags == HHT_ONDIVOPEN)
1601 SetCursor (infoPtr->hcurDivopen);
1603 SetCursor (infoPtr->hcurArrow);
1610 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1612 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1614 HFONT hFont, hOldFont;
1617 infoPtr->hFont = (HFONT)wParam;
1619 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1622 hOldFont = SelectObject (hdc, hFont);
1623 GetTextMetricsA (hdc, &tm);
1624 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1625 SelectObject (hdc, hOldFont);
1628 infoPtr->bRectsValid = FALSE;
1631 InvalidateRect(hwnd, NULL, FALSE);
1638 static LRESULT WINAPI
1639 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1641 TRACE("hwnd=%x msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1642 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1643 return DefWindowProcA (hwnd, msg, wParam, lParam);
1645 /* case HDM_CLEARFILTER: */
1647 case HDM_CREATEDRAGIMAGE:
1648 return HEADER_CreateDragImage (hwnd, wParam);
1650 case HDM_DELETEITEM:
1651 return HEADER_DeleteItem (hwnd, wParam);
1653 /* case HDM_EDITFILTER: */
1655 /* case HDM_GETBITMAPMARGIN: */
1657 case HDM_GETIMAGELIST:
1658 return HEADER_GetImageList (hwnd);
1661 return HEADER_GetItemA (hwnd, wParam, lParam);
1664 return HEADER_GetItemW (hwnd, wParam, lParam);
1666 case HDM_GETITEMCOUNT:
1667 return HEADER_GetItemCount (hwnd);
1669 case HDM_GETITEMRECT:
1670 return HEADER_GetItemRect (hwnd, wParam, lParam);
1672 case HDM_GETORDERARRAY:
1673 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1675 case HDM_GETUNICODEFORMAT:
1676 return HEADER_GetUnicodeFormat (hwnd);
1679 return HEADER_HitTest (hwnd, wParam, lParam);
1681 case HDM_INSERTITEMA:
1682 return HEADER_InsertItemA (hwnd, wParam, lParam);
1684 case HDM_INSERTITEMW:
1685 return HEADER_InsertItemW (hwnd, wParam, lParam);
1688 return HEADER_Layout (hwnd, wParam, lParam);
1690 case HDM_ORDERTOINDEX:
1691 return HEADER_OrderToIndex(hwnd, wParam);
1693 /* case HDM_SETBITMAPMARGIN: */
1695 /* case HDM_SETFILTERCHANGETIMEOUT: */
1697 /* case HDM_SETHOTDIVIDER: */
1699 case HDM_SETIMAGELIST:
1700 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
1703 return HEADER_SetItemA (hwnd, wParam, lParam);
1706 return HEADER_SetItemW (hwnd, wParam, lParam);
1708 case HDM_SETORDERARRAY:
1709 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1711 case HDM_SETUNICODEFORMAT:
1712 return HEADER_SetUnicodeFormat (hwnd, wParam);
1715 return HEADER_Create (hwnd, wParam, lParam);
1718 return HEADER_Destroy (hwnd, wParam, lParam);
1724 return DLGC_WANTTAB | DLGC_WANTARROWS;
1727 return HEADER_GetFont (hwnd);
1729 case WM_LBUTTONDBLCLK:
1730 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1732 case WM_LBUTTONDOWN:
1733 return HEADER_LButtonDown (hwnd, wParam, lParam);
1736 return HEADER_LButtonUp (hwnd, wParam, lParam);
1739 return HEADER_MouseMove (hwnd, wParam, lParam);
1741 case WM_NOTIFYFORMAT:
1742 return HEADER_NotifyFormat (hwnd, wParam, lParam);
1745 return HEADER_Size (hwnd, wParam);
1748 return HEADER_Paint (hwnd, wParam);
1751 return HEADER_RButtonUp (hwnd, wParam, lParam);
1754 return HEADER_SetCursor (hwnd, wParam, lParam);
1757 return HEADER_SetFont (hwnd, wParam, lParam);
1761 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1762 msg, wParam, lParam );
1763 return DefWindowProcA (hwnd, msg, wParam, lParam);
1770 HEADER_Register (void)
1774 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1775 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1776 wndClass.lpfnWndProc = (WNDPROC)HEADER_WindowProc;
1777 wndClass.cbClsExtra = 0;
1778 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1779 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
1780 wndClass.lpszClassName = WC_HEADERA;
1782 RegisterClassA (&wndClass);
1787 HEADER_Unregister (void)
1789 UnregisterClassA (WC_HEADERA, (HINSTANCE)NULL);