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.
38 #include "wine/unicode.h"
41 #include "imagelist.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(header);
54 INT iOrder; /* see documentation of HD_ITEM */
56 BOOL bDown; /* is item pressed? (used for drawing) */
57 RECT rect; /* bounding rectangle of the item */
63 HWND hwndNotify; /* Owner window to send notifications to */
64 INT nNotifyFormat; /* format used for WM_NOTIFY messages */
65 UINT uNumItem; /* number of items (columns) */
66 INT nHeight; /* height of the header (pixels) */
67 HFONT hFont; /* handle to the current font */
68 HCURSOR hcurArrow; /* handle to the arrow cursor */
69 HCURSOR hcurDivider; /* handle to a cursor (used over dividers) <-|-> */
70 HCURSOR hcurDivopen; /* handle to a cursor (used over dividers) <-||-> */
71 BOOL bCaptured; /* Is the mouse captured? */
72 BOOL bPressed; /* Is a header item pressed (down)? */
73 BOOL bTracking; /* Is in tracking mode? */
74 BOOL bUnicode; /* Unicode flag */
75 INT iMoveItem; /* index of tracked item. (Tracking mode) */
76 INT xTrackOffset; /* distance between the right side of the tracked item and the cursor */
77 INT xOldTrack; /* track offset (see above) after the last WM_MOUSEMOVE */
78 INT nOldWidth; /* width of a sizing item after the last WM_MOUSEMOVE */
79 INT iHotItem; /* index of hot item (cursor is over this item) */
81 HIMAGELIST himl; /* handle to a image list (may be 0) */
82 HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */
83 BOOL bRectsValid; /* validity flag for bounding rectangles */
88 #define DIVIDER_WIDTH 10
90 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongA(hwnd,0))
94 HEADER_IndexToOrder (HWND hwnd, INT iItem)
96 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
97 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
98 return lpItem->iOrder;
103 HEADER_OrderToIndex(HWND hwnd, WPARAM wParam)
105 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
106 INT i,iorder = (INT)wParam;
109 if ((iorder <0) || iorder >infoPtr->uNumItem)
111 for (i=0; i<infoPtr->uNumItem; i++)
112 if (HEADER_IndexToOrder(hwnd,i) == iorder)
118 HEADER_SetItemBounds (HWND hwnd)
120 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
125 infoPtr->bRectsValid = TRUE;
127 if (infoPtr->uNumItem == 0)
130 GetClientRect (hwnd, &rect);
133 for (i = 0; i < infoPtr->uNumItem; i++) {
134 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
135 phdi->rect.top = rect.top;
136 phdi->rect.bottom = rect.bottom;
138 phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
139 x = phdi->rect.right;
144 HEADER_Size (HWND hwnd, WPARAM wParam)
146 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
148 infoPtr->bRectsValid = FALSE;
155 HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
157 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
158 HEADER_ITEM *phdi = &infoPtr->items[iItem];
162 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, infoPtr->bUnicode);
164 if (!infoPtr->bRectsValid)
165 HEADER_SetItemBounds(hwnd);
168 if (r.right - r.left == 0)
169 return phdi->rect.right;
171 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) {
173 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
174 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
179 DrawEdge (hdc, &r, EDGE_RAISED,
180 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
183 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
185 if (phdi->fmt & HDF_OWNERDRAW) {
187 dis.CtlType = ODT_HEADER;
188 dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
190 dis.itemAction = ODA_DRAWENTIRE;
191 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
195 dis.itemData = phdi->lParam;
196 oldBkMode = SetBkMode(hdc, TRANSPARENT);
197 SendMessageA (GetParent (hwnd), WM_DRAWITEM,
198 (WPARAM)dis.CtlID, (LPARAM)&dis);
199 if (oldBkMode != TRANSPARENT)
200 SetBkMode(hdc, oldBkMode);
203 UINT uTextJustify = DT_LEFT;
205 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
206 uTextJustify = DT_CENTER;
207 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
208 uTextJustify = DT_RIGHT;
210 if ((phdi->fmt & HDF_BITMAP) && !(phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
213 INT yD, yS, cx, cy, rx, ry;
215 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
217 ry = r.bottom - r.top;
218 rx = r.right - r.left;
220 if (ry >= bmp.bmHeight) {
222 yD = r.top + (ry - bmp.bmHeight) / 2;
228 yS = (bmp.bmHeight - ry) / 2;
232 if (rx >= bmp.bmWidth + 6) {
239 hdcBitmap = CreateCompatibleDC (hdc);
240 SelectObject (hdcBitmap, phdi->hbm);
241 BitBlt (hdc, r.left + 3, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
242 DeleteDC (hdcBitmap);
244 r.left += (bmp.bmWidth + 3);
248 if ((phdi->fmt & HDF_BITMAP) && (phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
251 INT xD, yD, yS, cx, cy, rx, ry, tx;
254 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
257 DrawTextW (hdc, phdi->pszText, -1,
258 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
259 tx = textRect.right - textRect.left;
260 ry = r.bottom - r.top;
261 rx = r.right - r.left;
263 if (ry >= bmp.bmHeight) {
265 yD = r.top + (ry - bmp.bmHeight) / 2;
271 yS = (bmp.bmHeight - ry) / 2;
275 if (r.left + tx + bmp.bmWidth + 9 <= r.right) {
277 xD = r.left + tx + 6;
280 if (rx >= bmp.bmWidth + 6) {
282 xD = r.right - bmp.bmWidth - 3;
292 hdcBitmap = CreateCompatibleDC (hdc);
293 SelectObject (hdcBitmap, phdi->hbm);
294 BitBlt (hdc, xD, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
295 DeleteDC (hdcBitmap);
298 if ((phdi->fmt & HDF_IMAGE) && (infoPtr->himl)) {
300 /* FIXME: (r.bottom- (infoPtr->himl->cy))/2 should horicontal center the image
301 It looks like it doesn't work as expected*/
302 ImageList_Draw (infoPtr->himl, phdi->iImage,hdc,r.left, (r.bottom- (infoPtr->himl->cy))/2,0);
303 r.left += infoPtr->himl->cx;
306 if (((phdi->fmt & HDF_STRING)
307 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
308 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
309 && (phdi->pszText)) {
310 oldBkMode = SetBkMode(hdc, TRANSPARENT);
313 SetTextColor (hdc, (bHotTrack) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
314 DrawTextW (hdc, phdi->pszText, -1,
315 &r, uTextJustify|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
316 if (oldBkMode != TRANSPARENT)
317 SetBkMode(hdc, oldBkMode);
321 return phdi->rect.right;
326 HEADER_Refresh (HWND hwnd, HDC hdc)
328 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
329 HFONT hFont, hOldFont;
334 /* get rect for the bar, adjusted for the border */
335 GetClientRect (hwnd, &rect);
337 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
338 hOldFont = SelectObject (hdc, hFont);
340 /* draw Background */
341 hbrBk = GetSysColorBrush(COLOR_3DFACE);
342 FillRect(hdc, &rect, hbrBk);
345 for (i = 0; i < infoPtr->uNumItem; i++) {
346 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i), FALSE);
349 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
351 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS)
352 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
354 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
357 SelectObject (hdc, hOldFont);
362 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
364 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
365 HFONT hFont, hOldFont;
367 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
368 hOldFont = SelectObject (hdc, hFont);
369 HEADER_DrawItem (hwnd, hdc, iItem, FALSE);
370 SelectObject (hdc, hOldFont);
375 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
377 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
382 GetClientRect (hwnd, &rect);
386 if (PtInRect (&rect, *lpPt))
388 if (infoPtr->uNumItem == 0) {
389 *pFlags |= HHT_NOWHERE;
395 /* somewhere inside */
396 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
397 rect = infoPtr->items[iCount].rect;
398 width = rect.right - rect.left;
403 if (PtInRect (&rect, *lpPt)) {
404 if (width <= 2 * DIVIDER_WIDTH) {
405 *pFlags |= HHT_ONHEADER;
407 TRACE("ON HEADER %d\n", iCount);
412 rcTest.right = rcTest.left + DIVIDER_WIDTH;
413 if (PtInRect (&rcTest, *lpPt)) {
415 *pFlags |= HHT_ONDIVOPEN;
417 TRACE("ON DIVOPEN %d\n", *pItem);
421 *pFlags |= HHT_ONDIVIDER;
423 TRACE("ON DIVIDER %d\n", *pItem);
429 rcTest.left = rcTest.right - DIVIDER_WIDTH;
430 if (PtInRect (&rcTest, *lpPt)) {
431 *pFlags |= HHT_ONDIVIDER;
433 TRACE("ON DIVIDER %d\n", *pItem);
437 *pFlags |= HHT_ONHEADER;
439 TRACE("ON HEADER %d\n", iCount);
444 /* check for last divider part (on nowhere) */
445 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
446 rect.left = rect.right;
447 rect.right += DIVIDER_WIDTH;
448 if (PtInRect (&rect, *lpPt)) {
450 *pFlags |= HHT_ONDIVOPEN;
451 *pItem = infoPtr->uNumItem - 1;
452 TRACE("ON DIVOPEN %d\n", *pItem);
456 *pFlags |= HHT_ONDIVIDER;
457 *pItem = infoPtr->uNumItem-1;
458 TRACE("ON DIVIDER %d\n", *pItem);
463 *pFlags |= HHT_NOWHERE;
470 if (lpPt->x < rect.left) {
472 *pFlags |= HHT_TOLEFT;
474 else if (lpPt->x > rect.right) {
476 *pFlags |= HHT_TORIGHT;
479 if (lpPt->y < rect.top) {
481 *pFlags |= HHT_ABOVE;
483 else if (lpPt->y > rect.bottom) {
485 *pFlags |= HHT_BELOW;
490 TRACE("flags=0x%X\n", *pFlags);
496 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
502 GetClientRect (hwnd, &rect);
504 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
505 oldRop = SetROP2 (hdc, R2_XORPEN);
506 MoveToEx (hdc, x, rect.top, NULL);
507 LineTo (hdc, x, rect.bottom);
508 SetROP2 (hdc, oldRop);
509 SelectObject (hdc, hOldPen);
514 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
516 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
519 nmhdr.hwndFrom = hwnd;
520 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
523 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
524 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
528 HEADER_SendHeaderNotify (HWND hwnd, UINT code, INT iItem, INT mask)
530 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
534 nmhdr.hdr.hwndFrom = hwnd;
535 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
536 nmhdr.hdr.code = code;
539 nmhdr.pitem = &nmitem;
541 nmitem.cxy = infoPtr->items[iItem].cxy;
542 nmitem.hbm = infoPtr->items[iItem].hbm;
543 nmitem.pszText = NULL;
544 nmitem.cchTextMax = 0;
545 /* nmitem.pszText = infoPtr->items[iItem].pszText; */
546 /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
547 nmitem.fmt = infoPtr->items[iItem].fmt;
548 nmitem.lParam = infoPtr->items[iItem].lParam;
549 nmitem.iOrder = infoPtr->items[iItem].iOrder;
550 nmitem.iImage = infoPtr->items[iItem].iImage;
552 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
553 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
558 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
560 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
563 nmhdr.hdr.hwndFrom = hwnd;
564 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
565 nmhdr.hdr.code = code;
570 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
571 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
576 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
578 FIXME("empty stub!\n");
584 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
586 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
587 INT iItem = (INT)wParam;
589 TRACE("[iItem=%d]\n", iItem);
591 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
594 if (infoPtr->uNumItem == 1) {
595 TRACE("Simple delete!\n");
596 if (infoPtr->items[0].pszText)
597 COMCTL32_Free (infoPtr->items[0].pszText);
598 COMCTL32_Free (infoPtr->items);
600 infoPtr->uNumItem = 0;
603 HEADER_ITEM *oldItems = infoPtr->items;
607 TRACE("Complex delete! [iItem=%d]\n", iItem);
609 if (infoPtr->items[iItem].pszText)
610 COMCTL32_Free (infoPtr->items[iItem].pszText);
611 iOrder = infoPtr->items[iItem].iOrder;
614 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
615 /* pre delete copy */
617 memcpy (&infoPtr->items[0], &oldItems[0],
618 iItem * sizeof(HEADER_ITEM));
621 /* post delete copy */
622 if (iItem < infoPtr->uNumItem) {
623 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
624 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
627 /* Correct the orders */
628 for (i=infoPtr->uNumItem, pItem = infoPtr->items; i; i--, pItem++)
630 if (pItem->iOrder > iOrder)
633 COMCTL32_Free (oldItems);
636 HEADER_SetItemBounds (hwnd);
638 InvalidateRect(hwnd, NULL, FALSE);
645 HEADER_GetImageList (HWND hwnd)
647 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
649 return (LRESULT)infoPtr->himl;
654 HEADER_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
656 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
657 HDITEMA *phdi = (HDITEMA*)lParam;
658 INT nItem = (INT)wParam;
663 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
666 TRACE("[nItem=%d]\n", nItem);
671 lpItem = &infoPtr->items[nItem];
672 if (phdi->mask & HDI_BITMAP)
673 phdi->hbm = lpItem->hbm;
675 if (phdi->mask & HDI_FORMAT)
676 phdi->fmt = lpItem->fmt;
678 if (phdi->mask & HDI_WIDTH)
679 phdi->cxy = lpItem->cxy;
681 if (phdi->mask & HDI_LPARAM)
682 phdi->lParam = lpItem->lParam;
684 if (phdi->mask & HDI_TEXT) {
685 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
687 WideCharToMultiByte (CP_ACP, 0, lpItem->pszText, -1,
688 phdi->pszText, phdi->cchTextMax, NULL, NULL);
693 phdi->pszText = LPSTR_TEXTCALLBACKA;
696 if (phdi->mask & HDI_IMAGE)
697 phdi->iImage = lpItem->iImage;
699 if (phdi->mask & HDI_ORDER)
700 phdi->iOrder = lpItem->iOrder;
707 HEADER_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
709 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
710 HDITEMW *phdi = (HDITEMW*)lParam;
711 INT nItem = (INT)wParam;
716 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
719 TRACE("[nItem=%d]\n", nItem);
724 lpItem = &infoPtr->items[nItem];
725 if (phdi->mask & HDI_BITMAP)
726 phdi->hbm = lpItem->hbm;
728 if (phdi->mask & HDI_FORMAT)
729 phdi->fmt = lpItem->fmt;
731 if (phdi->mask & HDI_WIDTH)
732 phdi->cxy = lpItem->cxy;
734 if (phdi->mask & HDI_LPARAM)
735 phdi->lParam = lpItem->lParam;
737 if (phdi->mask & HDI_TEXT) {
738 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
740 lstrcpynW (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
745 phdi->pszText = LPSTR_TEXTCALLBACKW;
748 if (phdi->mask & HDI_IMAGE)
749 phdi->iImage = lpItem->iImage;
751 if (phdi->mask & HDI_ORDER)
752 phdi->iOrder = lpItem->iOrder;
758 inline static LRESULT
759 HEADER_GetItemCount (HWND hwnd)
761 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
762 return infoPtr->uNumItem;
767 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
769 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
770 INT iItem = (INT)wParam;
771 LPRECT lpRect = (LPRECT)lParam;
773 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
776 lpRect->left = infoPtr->items[iItem].rect.left;
777 lpRect->right = infoPtr->items[iItem].rect.right;
778 lpRect->top = infoPtr->items[iItem].rect.top;
779 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
786 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
789 LPINT order = (LPINT) lParam;
790 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
792 if ((int)wParam <infoPtr->uNumItem)
794 for (i=0; i<(int)wParam; i++)
795 *order++=HEADER_OrderToIndex(hwnd,i);
800 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
803 LPINT order = (LPINT) lParam;
804 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
807 if ((int)wParam <infoPtr->uNumItem)
809 for (i=0; i<(int)wParam; i++)
811 lpItem = &infoPtr->items[*order++];
814 infoPtr->bRectsValid=0;
815 InvalidateRect(hwnd, NULL, FALSE);
819 inline static LRESULT
820 HEADER_GetUnicodeFormat (HWND hwnd)
822 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
823 return infoPtr->bUnicode;
828 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
830 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
832 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
834 if (phti->flags == HHT_ONHEADER)
842 HEADER_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
844 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
845 HDITEMA *phdi = (HDITEMA*)lParam;
846 INT nItem = (INT)wParam;
850 if ((phdi == NULL) || (nItem < 0))
853 if (nItem > infoPtr->uNumItem)
854 nItem = infoPtr->uNumItem;
856 if (infoPtr->uNumItem == 0) {
857 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
861 HEADER_ITEM *oldItems = infoPtr->items;
864 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
866 memcpy (&infoPtr->items[1], &oldItems[0],
867 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
871 /* pre insert copy */
873 memcpy (&infoPtr->items[0], &oldItems[0],
874 nItem * sizeof(HEADER_ITEM));
877 /* post insert copy */
878 if (nItem < infoPtr->uNumItem - 1) {
879 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
880 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
884 COMCTL32_Free (oldItems);
887 lpItem = &infoPtr->items[nItem];
888 lpItem->bDown = FALSE;
890 if (phdi->mask & HDI_WIDTH)
891 lpItem->cxy = phdi->cxy;
893 if (phdi->mask & HDI_TEXT) {
894 if (!phdi->pszText) /* null pointer check */
896 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
897 len = MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, NULL, 0);
898 lpItem->pszText = COMCTL32_Alloc( len*sizeof(WCHAR) );
899 MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, lpItem->pszText, len);
902 lpItem->pszText = LPSTR_TEXTCALLBACKW;
905 if (phdi->mask & HDI_FORMAT)
906 lpItem->fmt = phdi->fmt;
908 if (lpItem->fmt == 0)
909 lpItem->fmt = HDF_LEFT;
911 if (!(lpItem->fmt & HDF_STRING) && (phdi->mask & HDI_TEXT))
913 lpItem->fmt |= HDF_STRING;
915 if (phdi->mask & HDI_BITMAP)
916 lpItem->hbm = phdi->hbm;
918 if (phdi->mask & HDI_LPARAM)
919 lpItem->lParam = phdi->lParam;
921 if (phdi->mask & HDI_IMAGE)
922 lpItem->iImage = phdi->iImage;
924 if (phdi->mask & HDI_ORDER)
926 lpItem->iOrder = phdi->iOrder;
929 lpItem->iOrder=nItem;
932 HEADER_SetItemBounds (hwnd);
934 InvalidateRect(hwnd, NULL, FALSE);
941 HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
943 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
944 HDITEMW *phdi = (HDITEMW*)lParam;
945 INT nItem = (INT)wParam;
949 if ((phdi == NULL) || (nItem < 0))
952 if (nItem > infoPtr->uNumItem)
953 nItem = infoPtr->uNumItem;
955 if (infoPtr->uNumItem == 0) {
956 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM));
960 HEADER_ITEM *oldItems = infoPtr->items;
963 infoPtr->items = COMCTL32_Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
965 memcpy (&infoPtr->items[1], &oldItems[0],
966 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
970 /* pre insert copy */
972 memcpy (&infoPtr->items[0], &oldItems[0],
973 nItem * sizeof(HEADER_ITEM));
976 /* post insert copy */
977 if (nItem < infoPtr->uNumItem - 1) {
978 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
979 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
983 COMCTL32_Free (oldItems);
986 lpItem = &infoPtr->items[nItem];
987 lpItem->bDown = FALSE;
989 if (phdi->mask & HDI_WIDTH)
990 lpItem->cxy = phdi->cxy;
992 if (phdi->mask & HDI_TEXT) {
993 WCHAR wide_null_char = 0;
994 if (!phdi->pszText) /* null pointer check */
995 phdi->pszText = &wide_null_char;
996 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
997 len = strlenW (phdi->pszText);
998 lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
999 strcpyW (lpItem->pszText, phdi->pszText);
1002 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1005 if (phdi->mask & HDI_FORMAT)
1006 lpItem->fmt = phdi->fmt;
1008 if (lpItem->fmt == 0)
1009 lpItem->fmt = HDF_LEFT;
1011 if (!(lpItem->fmt &HDF_STRING) && (phdi->mask & HDI_TEXT))
1013 lpItem->fmt |= HDF_STRING;
1015 if (phdi->mask & HDI_BITMAP)
1016 lpItem->hbm = phdi->hbm;
1018 if (phdi->mask & HDI_LPARAM)
1019 lpItem->lParam = phdi->lParam;
1021 if (phdi->mask & HDI_IMAGE)
1022 lpItem->iImage = phdi->iImage;
1024 if (phdi->mask & HDI_ORDER)
1026 lpItem->iOrder = phdi->iOrder;
1029 lpItem->iOrder = nItem;
1031 HEADER_SetItemBounds (hwnd);
1033 InvalidateRect(hwnd, NULL, FALSE);
1040 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
1042 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1043 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1045 lpLayout->pwpos->hwnd = hwnd;
1046 lpLayout->pwpos->hwndInsertAfter = 0;
1047 lpLayout->pwpos->x = lpLayout->prc->left;
1048 lpLayout->pwpos->y = lpLayout->prc->top;
1049 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1050 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_HIDDEN)
1051 lpLayout->pwpos->cy = 0;
1053 lpLayout->pwpos->cy = infoPtr->nHeight;
1054 lpLayout->prc->top += infoPtr->nHeight;
1056 lpLayout->pwpos->flags = SWP_NOZORDER;
1058 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1059 lpLayout->pwpos->x, lpLayout->pwpos->y,
1060 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1062 infoPtr->bRectsValid = FALSE;
1069 HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
1071 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1074 TRACE("(himl 0x%x)\n", (int)himl);
1075 himlOld = infoPtr->himl;
1076 infoPtr->himl = himl;
1078 /* FIXME: Refresh needed??? */
1080 return (LRESULT)himlOld;
1085 HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1087 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1088 HDITEMA *phdi = (HDITEMA*)lParam;
1089 INT nItem = (INT)wParam;
1090 HEADER_ITEM *lpItem;
1094 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1097 TRACE("[nItem=%d]\n", nItem);
1099 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem, phdi->mask))
1102 lpItem = &infoPtr->items[nItem];
1103 if (phdi->mask & HDI_BITMAP)
1104 lpItem->hbm = phdi->hbm;
1106 if (phdi->mask & HDI_FORMAT)
1107 lpItem->fmt = phdi->fmt;
1109 if (phdi->mask & HDI_LPARAM)
1110 lpItem->lParam = phdi->lParam;
1112 if (phdi->mask & HDI_TEXT) {
1113 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
1114 if (lpItem->pszText) {
1115 COMCTL32_Free (lpItem->pszText);
1116 lpItem->pszText = NULL;
1118 if (phdi->pszText) {
1119 INT len = MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,NULL,0);
1120 lpItem->pszText = COMCTL32_Alloc( len*sizeof(WCHAR) );
1121 MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,lpItem->pszText,len);
1125 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1128 if (phdi->mask & HDI_WIDTH)
1129 lpItem->cxy = phdi->cxy;
1131 if (phdi->mask & HDI_IMAGE)
1132 lpItem->iImage = phdi->iImage;
1134 if (phdi->mask & HDI_ORDER)
1136 lpItem->iOrder = phdi->iOrder;
1139 lpItem->iOrder = nItem;
1141 HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem, phdi->mask);
1143 HEADER_SetItemBounds (hwnd);
1145 InvalidateRect(hwnd, NULL, FALSE);
1152 HEADER_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1154 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1155 HDITEMW *phdi = (HDITEMW*)lParam;
1156 INT nItem = (INT)wParam;
1157 HEADER_ITEM *lpItem;
1161 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1164 TRACE("[nItem=%d]\n", nItem);
1166 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask))
1169 lpItem = &infoPtr->items[nItem];
1170 if (phdi->mask & HDI_BITMAP)
1171 lpItem->hbm = phdi->hbm;
1173 if (phdi->mask & HDI_FORMAT)
1174 lpItem->fmt = phdi->fmt;
1176 if (phdi->mask & HDI_LPARAM)
1177 lpItem->lParam = phdi->lParam;
1179 if (phdi->mask & HDI_TEXT) {
1180 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1181 if (lpItem->pszText) {
1182 COMCTL32_Free (lpItem->pszText);
1183 lpItem->pszText = NULL;
1185 if (phdi->pszText) {
1186 INT len = strlenW (phdi->pszText);
1187 lpItem->pszText = COMCTL32_Alloc ((len+1)*sizeof(WCHAR));
1188 strcpyW (lpItem->pszText, phdi->pszText);
1192 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1195 if (phdi->mask & HDI_WIDTH)
1196 lpItem->cxy = phdi->cxy;
1198 if (phdi->mask & HDI_IMAGE)
1199 lpItem->iImage = phdi->iImage;
1201 if (phdi->mask & HDI_ORDER)
1203 lpItem->iOrder = phdi->iOrder;
1206 lpItem->iOrder = nItem;
1208 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDW, nItem, phdi->mask);
1210 HEADER_SetItemBounds (hwnd);
1212 InvalidateRect(hwnd, NULL, FALSE);
1217 inline static LRESULT
1218 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1220 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1221 BOOL bTemp = infoPtr->bUnicode;
1223 infoPtr->bUnicode = (BOOL)wParam;
1230 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1232 HEADER_INFO *infoPtr;
1237 infoPtr = (HEADER_INFO *)COMCTL32_Alloc (sizeof(HEADER_INFO));
1238 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1240 infoPtr->hwndNotify = GetParent(hwnd);
1241 infoPtr->uNumItem = 0;
1244 infoPtr->bRectsValid = FALSE;
1245 infoPtr->hcurArrow = LoadCursorA (0, IDC_ARROWA);
1246 infoPtr->hcurDivider = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDER));
1247 infoPtr->hcurDivopen = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDEROPEN));
1248 infoPtr->bPressed = FALSE;
1249 infoPtr->bTracking = FALSE;
1250 infoPtr->iMoveItem = 0;
1252 infoPtr->iHotItem = -1;
1253 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1254 infoPtr->nNotifyFormat =
1255 SendMessageA (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1258 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1259 GetTextMetricsA (hdc, &tm);
1260 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1261 SelectObject (hdc, hOldFont);
1269 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1271 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1272 HEADER_ITEM *lpItem;
1275 if (infoPtr->items) {
1276 lpItem = infoPtr->items;
1277 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1278 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
1279 COMCTL32_Free (lpItem->pszText);
1281 COMCTL32_Free (infoPtr->items);
1285 ImageList_Destroy (infoPtr->himl);
1287 COMCTL32_Free (infoPtr);
1288 SetWindowLongA (hwnd, 0, 0);
1293 static inline LRESULT
1294 HEADER_GetFont (HWND hwnd)
1296 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1298 return (LRESULT)infoPtr->hFont;
1303 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1309 pt.x = (INT)LOWORD(lParam);
1310 pt.y = (INT)HIWORD(lParam);
1311 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1313 if ((GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1314 HEADER_SendHeaderNotify (hwnd, HDN_ITEMDBLCLICKA, nItem,0);
1315 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1316 HEADER_SendHeaderNotify (hwnd, HDN_DIVIDERDBLCLICKA, nItem,0);
1323 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1325 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1326 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1332 pt.x = (INT)LOWORD(lParam);
1333 pt.y = (INT)HIWORD(lParam);
1334 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1336 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1338 infoPtr->bCaptured = TRUE;
1339 infoPtr->bPressed = TRUE;
1340 infoPtr->iMoveItem = nItem;
1342 infoPtr->items[nItem].bDown = TRUE;
1344 /* Send WM_CUSTOMDRAW */
1346 HEADER_RefreshItem (hwnd, hdc, nItem);
1347 ReleaseDC (hwnd, hdc);
1349 TRACE("Pressed item %d!\n", nItem);
1351 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1352 if (!(HEADER_SendHeaderNotify (hwnd, HDN_BEGINTRACKA, nItem,0))) {
1354 infoPtr->bCaptured = TRUE;
1355 infoPtr->bTracking = TRUE;
1356 infoPtr->iMoveItem = nItem;
1357 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1358 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1360 if (!(dwStyle & HDS_FULLDRAG)) {
1361 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1363 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1364 ReleaseDC (hwnd, hdc);
1367 TRACE("Begin tracking item %d!\n", nItem);
1376 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1378 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1380 *DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1387 pt.x = (INT)SLOWORD(lParam);
1388 pt.y = (INT)SHIWORD(lParam);
1389 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1391 if (infoPtr->bPressed) {
1392 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1393 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1395 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1396 ReleaseDC (hwnd, hdc);
1398 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1400 else if (flags == HHT_ONHEADER)
1402 HEADER_ITEM *lpItem;
1403 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1404 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1406 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1407 infoPtr->iMoveItem,oldindex,nItem,newindex);
1408 lpItem= &infoPtr->items[nItem];
1409 lpItem->iOrder=oldindex;
1411 lpItem= &infoPtr->items[infoPtr->iMoveItem];
1412 lpItem->iOrder = newindex;
1414 infoPtr->bRectsValid = FALSE;
1415 InvalidateRect(hwnd, NULL, FALSE);
1416 /* FIXME: Should some WM_NOTIFY be sent */
1419 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1420 infoPtr->bPressed = FALSE;
1422 else if (infoPtr->bTracking) {
1423 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1424 infoPtr->bTracking = FALSE;
1426 HEADER_SendHeaderNotify (hwnd, HDN_ENDTRACKA, infoPtr->iMoveItem,HDI_WIDTH);
1429 * we want to do this even for HDS_FULLDRAG because this is where
1430 * we send the HDN_ITEMCHANGING and HDN_ITEMCHANGED notifications
1432 * if (!(dwStyle & HDS_FULLDRAG)) {
1436 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1437 ReleaseDC (hwnd, hdc);
1438 if (HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1440 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1443 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1446 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1449 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH);
1450 HEADER_SetItemBounds (hwnd);
1451 InvalidateRect(hwnd, NULL, FALSE);
1457 if (infoPtr->bCaptured) {
1458 infoPtr->bCaptured = FALSE;
1460 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1468 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1470 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1475 return infoPtr->nNotifyFormat;
1478 infoPtr->nNotifyFormat =
1479 SendMessageA ((HWND)wParam, WM_NOTIFYFORMAT,
1480 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1481 return infoPtr->nNotifyFormat;
1489 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1491 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1492 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1498 pt.x = (INT)SLOWORD(lParam);
1499 pt.y = (INT)SHIWORD(lParam);
1500 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1502 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1503 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1504 infoPtr->iHotItem = nItem;
1506 infoPtr->iHotItem = -1;
1507 InvalidateRect(hwnd, NULL, FALSE);
1510 if (infoPtr->bCaptured) {
1511 if (infoPtr->bPressed) {
1512 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1513 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1515 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1517 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1518 ReleaseDC (hwnd, hdc);
1520 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1522 else if (infoPtr->bTracking) {
1523 if (dwStyle & HDS_FULLDRAG) {
1524 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1526 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1529 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1530 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1532 HEADER_SetItemBounds (hwnd);
1533 InvalidateRect(hwnd, NULL, FALSE);
1537 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1538 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1539 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1540 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1541 infoPtr->items[infoPtr->iMoveItem].cxy =
1542 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1543 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1544 ReleaseDC (hwnd, hdc);
1545 HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH);
1548 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1552 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1553 FIXME("hot track support!\n");
1561 HEADER_Paint (HWND hwnd, WPARAM wParam)
1566 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1567 HEADER_Refresh (hwnd, hdc);
1569 EndPaint (hwnd, &ps);
1575 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1580 pt.x = LOWORD(lParam);
1581 pt.y = HIWORD(lParam);
1583 /* Send a Notify message */
1584 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1586 /* Change to screen coordinate for WM_CONTEXTMENU */
1587 ClientToScreen(hwnd, &pt);
1589 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1590 SendMessageA( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1597 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1599 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1604 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1607 ScreenToClient (hwnd, &pt);
1609 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1611 if (flags == HHT_ONDIVIDER)
1612 SetCursor (infoPtr->hcurDivider);
1613 else if (flags == HHT_ONDIVOPEN)
1614 SetCursor (infoPtr->hcurDivopen);
1616 SetCursor (infoPtr->hcurArrow);
1623 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1625 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1627 HFONT hFont, hOldFont;
1630 infoPtr->hFont = (HFONT)wParam;
1632 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1635 hOldFont = SelectObject (hdc, hFont);
1636 GetTextMetricsA (hdc, &tm);
1637 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1638 SelectObject (hdc, hOldFont);
1641 infoPtr->bRectsValid = FALSE;
1644 InvalidateRect(hwnd, NULL, FALSE);
1651 static LRESULT WINAPI
1652 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1654 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1655 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1656 return DefWindowProcA (hwnd, msg, wParam, lParam);
1658 /* case HDM_CLEARFILTER: */
1660 case HDM_CREATEDRAGIMAGE:
1661 return HEADER_CreateDragImage (hwnd, wParam);
1663 case HDM_DELETEITEM:
1664 return HEADER_DeleteItem (hwnd, wParam);
1666 /* case HDM_EDITFILTER: */
1668 /* case HDM_GETBITMAPMARGIN: */
1670 case HDM_GETIMAGELIST:
1671 return HEADER_GetImageList (hwnd);
1674 return HEADER_GetItemA (hwnd, wParam, lParam);
1677 return HEADER_GetItemW (hwnd, wParam, lParam);
1679 case HDM_GETITEMCOUNT:
1680 return HEADER_GetItemCount (hwnd);
1682 case HDM_GETITEMRECT:
1683 return HEADER_GetItemRect (hwnd, wParam, lParam);
1685 case HDM_GETORDERARRAY:
1686 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1688 case HDM_GETUNICODEFORMAT:
1689 return HEADER_GetUnicodeFormat (hwnd);
1692 return HEADER_HitTest (hwnd, wParam, lParam);
1694 case HDM_INSERTITEMA:
1695 return HEADER_InsertItemA (hwnd, wParam, lParam);
1697 case HDM_INSERTITEMW:
1698 return HEADER_InsertItemW (hwnd, wParam, lParam);
1701 return HEADER_Layout (hwnd, wParam, lParam);
1703 case HDM_ORDERTOINDEX:
1704 return HEADER_OrderToIndex(hwnd, wParam);
1706 /* case HDM_SETBITMAPMARGIN: */
1708 /* case HDM_SETFILTERCHANGETIMEOUT: */
1710 /* case HDM_SETHOTDIVIDER: */
1712 case HDM_SETIMAGELIST:
1713 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
1716 return HEADER_SetItemA (hwnd, wParam, lParam);
1719 return HEADER_SetItemW (hwnd, wParam, lParam);
1721 case HDM_SETORDERARRAY:
1722 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1724 case HDM_SETUNICODEFORMAT:
1725 return HEADER_SetUnicodeFormat (hwnd, wParam);
1728 return HEADER_Create (hwnd, wParam, lParam);
1731 return HEADER_Destroy (hwnd, wParam, lParam);
1737 return DLGC_WANTTAB | DLGC_WANTARROWS;
1740 return HEADER_GetFont (hwnd);
1742 case WM_LBUTTONDBLCLK:
1743 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1745 case WM_LBUTTONDOWN:
1746 return HEADER_LButtonDown (hwnd, wParam, lParam);
1749 return HEADER_LButtonUp (hwnd, wParam, lParam);
1752 return HEADER_MouseMove (hwnd, wParam, lParam);
1754 case WM_NOTIFYFORMAT:
1755 return HEADER_NotifyFormat (hwnd, wParam, lParam);
1758 return HEADER_Size (hwnd, wParam);
1761 return HEADER_Paint (hwnd, wParam);
1764 return HEADER_RButtonUp (hwnd, wParam, lParam);
1767 return HEADER_SetCursor (hwnd, wParam, lParam);
1770 return HEADER_SetFont (hwnd, wParam, lParam);
1773 if ((msg >= WM_USER) && (msg < WM_APP))
1774 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1775 msg, wParam, lParam );
1776 return DefWindowProcA (hwnd, msg, wParam, lParam);
1783 HEADER_Register (void)
1787 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1788 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1789 wndClass.lpfnWndProc = (WNDPROC)HEADER_WindowProc;
1790 wndClass.cbClsExtra = 0;
1791 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1792 wndClass.hCursor = LoadCursorA (0, IDC_ARROWA);
1793 wndClass.lpszClassName = WC_HEADERA;
1795 RegisterClassA (&wndClass);
1800 HEADER_Unregister (void)
1802 UnregisterClassA (WC_HEADERA, NULL);