4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2003 Maxime Bellenge
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * - Imagelist support (partially).
24 * - Callback items (under construction).
25 * - Hottrack support (partially).
26 * - Custom draw support (including Notifications).
27 * - Drag and Drop support (including Notifications).
29 * - Use notification format
30 * - Correct the order maintenance code to preserve valid order
39 #include "wine/unicode.h"
45 #include "imagelist.h"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(header);
60 INT iOrder; /* see documentation of HD_ITEM */
62 BOOL bDown; /* is item pressed? (used for drawing) */
63 RECT rect; /* bounding rectangle of the item */
69 HWND hwndNotify; /* Owner window to send notifications to */
70 INT nNotifyFormat; /* format used for WM_NOTIFY messages */
71 UINT uNumItem; /* number of items (columns) */
72 INT nHeight; /* height of the header (pixels) */
73 HFONT hFont; /* handle to the current font */
74 HCURSOR hcurArrow; /* handle to the arrow cursor */
75 HCURSOR hcurDivider; /* handle to a cursor (used over dividers) <-|-> */
76 HCURSOR hcurDivopen; /* handle to a cursor (used over dividers) <-||-> */
77 BOOL bCaptured; /* Is the mouse captured? */
78 BOOL bPressed; /* Is a header item pressed (down)? */
79 BOOL bTracking; /* Is in tracking mode? */
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) */
85 INT iMargin; /* width of the margin that surrounds a bitmap */
87 HIMAGELIST himl; /* handle to an image list (may be 0) */
88 HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */
89 INT *order; /* array of item IDs indexed by order */
90 BOOL bRectsValid; /* validity flag for bounding rectangles */
95 #define DIVIDER_WIDTH 10
96 #define HDN_UNICODE_OFFSET 20
97 #define HDN_FIRST_UNICODE (HDN_FIRST-HDN_UNICODE_OFFSET)
99 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongPtrW(hwnd,0))
101 static const WCHAR themeClass[] = {'H','e','a','d','e','r',0};
102 static WCHAR emptyString[] = {0};
104 static void HEADER_DisposeItem(HEADER_ITEM *lpItem)
106 if (lpItem->pszText && lpItem->pszText != emptyString &&
107 lpItem->pszText != LPSTR_TEXTCALLBACKW) /* covers LPSTR_TEXTCALLBACKA too */
109 Free(lpItem->pszText);
113 inline static LRESULT
114 HEADER_IndexToOrder (HWND hwnd, INT iItem)
116 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
117 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
118 return lpItem->iOrder;
123 HEADER_OrderToIndex(HWND hwnd, WPARAM wParam)
125 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
126 INT iorder = (INT)wParam;
128 if ((iorder <0) || iorder >= infoPtr->uNumItem)
130 return infoPtr->order[iorder];
134 HEADER_SetItemBounds (HWND hwnd)
136 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
142 infoPtr->bRectsValid = TRUE;
144 if (infoPtr->uNumItem == 0)
147 GetClientRect (hwnd, &rect);
150 for (i = 0; i < infoPtr->uNumItem; i++) {
151 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
152 phdi->rect.top = rect.top;
153 phdi->rect.bottom = rect.bottom;
155 phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
156 x = phdi->rect.right;
161 HEADER_Size (HWND hwnd, WPARAM wParam)
163 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
165 infoPtr->bRectsValid = FALSE;
172 HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
174 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
175 HEADER_ITEM *phdi = &infoPtr->items[iItem];
177 INT oldBkMode, cxEdge = GetSystemMetrics(SM_CXEDGE);
178 HTHEME theme = GetWindowTheme (hwnd);
181 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, (infoPtr->nNotifyFormat == NFR_UNICODE));
183 if (!infoPtr->bRectsValid)
184 HEADER_SetItemBounds(hwnd);
187 if (r.right - r.left == 0)
188 return phdi->rect.right;
191 int state = (phdi->bDown) ? HIS_PRESSED :
192 (bHotTrack ? HIS_HOT : HIS_NORMAL);
193 DrawThemeBackground (theme, hdc, HP_HEADERITEM, state,
195 GetThemeBackgroundContentRect (theme, hdc, HP_HEADERITEM, state,
199 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) {
201 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
202 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
205 DrawEdge (hdc, &r, EDGE_RAISED,
206 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
209 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
219 /* Set the colors before sending NM_CUSTOMDRAW so that it can change them */
220 SetTextColor (hdc, (bHotTrack && !theme) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
221 SetBkColor(hdc, GetSysColor(COLOR_3DFACE));
223 nmcd.hdr.hwndFrom = hwnd;
224 nmcd.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
225 nmcd.hdr.code = NM_CUSTOMDRAW;
226 nmcd.dwDrawStage = CDDS_PREPAINT | CDDS_ITEM | CDDS_ITEMPOSTERASE;
228 nmcd.dwItemSpec = iItem;
230 nmcd.uItemState = phdi->bDown ? CDIS_SELECTED : 0;
231 nmcd.lItemlParam = phdi->lParam;
233 SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, nmcd.hdr.idFrom, (LPARAM)&nmcd);
235 if (phdi->fmt & HDF_OWNERDRAW) {
238 dis.CtlType = ODT_HEADER;
239 dis.CtlID = GetWindowLongPtrW (hwnd, GWLP_ID);
241 dis.itemAction = ODA_DRAWENTIRE;
242 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
246 dis.itemData = phdi->lParam;
247 oldBkMode = SetBkMode(hdc, TRANSPARENT);
248 SendMessageW (infoPtr->hwndNotify, WM_DRAWITEM,
249 (WPARAM)dis.CtlID, (LPARAM)&dis);
250 if (oldBkMode != TRANSPARENT)
251 SetBkMode(hdc, oldBkMode);
254 UINT rw, rh, /* width and height of r */
255 *x = NULL, *w = NULL; /* x and width of the pic (bmp or img) which is part of cnt */
256 /* cnt,txt,img,bmp */
261 cw = tw = iw = bw = 0;
262 rw = r.right - r.left;
263 rh = r.bottom - r.top;
266 HBRUSH hbr = CreateSolidBrush(GetBkColor(hdc));
267 RECT rcBackground = r;
269 rcBackground.right -= cxEdge;
270 FillRect(hdc, &rcBackground, hbr);
273 if (phdi->fmt & HDF_STRING) {
276 DrawTextW (hdc, phdi->pszText, -1,
277 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
278 cw = textRect.right - textRect.left + 2 * infoPtr->iMargin;
281 if ((phdi->fmt & HDF_IMAGE) && (infoPtr->himl)) {
282 iw = infoPtr->himl->cx + 2 * infoPtr->iMargin;
287 if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
288 GetObjectW (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
289 bw = bmp.bmWidth + 2 * infoPtr->iMargin;
299 /* align cx using the unclipped cw */
300 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_LEFT)
302 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
303 cx = r.left + rw / 2 - cw / 2;
310 if (cx + cw > r.right)
313 tx = cx + infoPtr->iMargin;
314 /* since cw might have changed we have to recalculate tw */
315 tw = cw - infoPtr->iMargin * 2;
319 if (phdi->fmt & HDF_BITMAP_ON_RIGHT) {
320 /* put pic behind text */
321 *x = cx + tw + infoPtr->iMargin * 3;
323 *x = cx + infoPtr->iMargin;
324 /* move text behind pic */
330 /* since we're done with the layout we can
331 now calculate the position of bmp which
332 has no influence on alignment and layout
334 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
335 bx = cx - bw + infoPtr->iMargin;
337 bx = cx + cw + infoPtr->iMargin;
341 HDC hClipDC = GetDC(hwnd);
342 HRGN hClipRgn = CreateRectRgn(r.left, r.top, r.right, r.bottom);
343 SelectClipRgn(hClipDC, hClipRgn);
346 HDC hdcBitmap = CreateCompatibleDC (hClipDC);
347 SelectObject (hdcBitmap, phdi->hbm);
348 BitBlt (hClipDC, bx, r.top + ((INT)rh - bmp.bmHeight) / 2,
349 bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
350 DeleteDC (hdcBitmap);
354 ImageList_DrawEx (infoPtr->himl, phdi->iImage, hClipDC,
355 ix, r.top + ((INT)rh - infoPtr->himl->cy) / 2,
356 infoPtr->himl->cx, infoPtr->himl->cy, CLR_DEFAULT, CLR_DEFAULT, 0);
359 DeleteObject(hClipRgn);
360 ReleaseDC(hwnd, hClipDC);
363 if (((phdi->fmt & HDF_STRING)
364 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
365 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
366 && (phdi->pszText)) {
367 oldBkMode = SetBkMode(hdc, TRANSPARENT);
370 DrawTextW (hdc, phdi->pszText, -1,
371 &r, DT_LEFT|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
372 if (oldBkMode != TRANSPARENT)
373 SetBkMode(hdc, oldBkMode);
377 return phdi->rect.right;
382 HEADER_Refresh (HWND hwnd, HDC hdc)
384 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
385 HFONT hFont, hOldFont;
390 HTHEME theme = GetWindowTheme (hwnd);
392 /* get rect for the bar, adjusted for the border */
393 GetClientRect (hwnd, &rect);
395 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
396 hOldFont = SelectObject (hdc, hFont);
398 /* draw Background */
400 hbrBk = GetSysColorBrush(COLOR_3DFACE);
401 FillRect(hdc, &rect, hbrBk);
405 for (i = 0; x <= rect.right && i < infoPtr->uNumItem; i++) {
406 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i),
407 infoPtr->iHotItem == i);
410 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
413 DrawThemeBackground (theme, hdc, HP_HEADERITEM, HIS_NORMAL, &rect,
417 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS)
418 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
420 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
424 SelectObject (hdc, hOldFont);
429 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
431 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
432 HFONT hFont, hOldFont;
434 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
435 hOldFont = SelectObject (hdc, hFont);
436 HEADER_DrawItem (hwnd, hdc, iItem, infoPtr->iHotItem == iItem);
437 SelectObject (hdc, hOldFont);
442 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
444 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
450 GetClientRect (hwnd, &rect);
454 if (PtInRect (&rect, *lpPt))
456 if (infoPtr->uNumItem == 0) {
457 *pFlags |= HHT_NOWHERE;
463 /* somewhere inside */
464 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
465 rect = infoPtr->items[iCount].rect;
466 width = rect.right - rect.left;
471 if (PtInRect (&rect, *lpPt)) {
472 if (width <= 2 * DIVIDER_WIDTH) {
473 *pFlags |= HHT_ONHEADER;
475 TRACE("ON HEADER %d\n", iCount);
480 rcTest.right = rcTest.left + DIVIDER_WIDTH;
481 if (PtInRect (&rcTest, *lpPt)) {
483 *pFlags |= HHT_ONDIVOPEN;
485 TRACE("ON DIVOPEN %d\n", *pItem);
489 *pFlags |= HHT_ONDIVIDER;
491 TRACE("ON DIVIDER %d\n", *pItem);
497 rcTest.left = rcTest.right - DIVIDER_WIDTH;
498 if (PtInRect (&rcTest, *lpPt)) {
499 *pFlags |= HHT_ONDIVIDER;
501 TRACE("ON DIVIDER %d\n", *pItem);
505 *pFlags |= HHT_ONHEADER;
507 TRACE("ON HEADER %d\n", iCount);
512 /* check for last divider part (on nowhere) */
513 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
514 rect.left = rect.right;
515 rect.right += DIVIDER_WIDTH;
516 if (PtInRect (&rect, *lpPt)) {
518 *pFlags |= HHT_ONDIVOPEN;
519 *pItem = infoPtr->uNumItem - 1;
520 TRACE("ON DIVOPEN %d\n", *pItem);
524 *pFlags |= HHT_ONDIVIDER;
525 *pItem = infoPtr->uNumItem-1;
526 TRACE("ON DIVIDER %d\n", *pItem);
531 *pFlags |= HHT_NOWHERE;
538 if (lpPt->x < rect.left) {
540 *pFlags |= HHT_TOLEFT;
542 else if (lpPt->x > rect.right) {
544 *pFlags |= HHT_TORIGHT;
547 if (lpPt->y < rect.top) {
549 *pFlags |= HHT_ABOVE;
551 else if (lpPt->y > rect.bottom) {
553 *pFlags |= HHT_BELOW;
558 TRACE("flags=0x%X\n", *pFlags);
564 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
570 GetClientRect (hwnd, &rect);
572 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
573 oldRop = SetROP2 (hdc, R2_XORPEN);
574 MoveToEx (hdc, x, rect.top, NULL);
575 LineTo (hdc, x, rect.bottom);
576 SetROP2 (hdc, oldRop);
577 SelectObject (hdc, hOldPen);
582 * Convert a HDITEM into the correct format (ANSI/Unicode) to send it in a notify
585 * [I] infoPtr : the header that wants to send the notify
586 * [O] dest : The buffer to store the HDITEM for notify. It may be set to a HDITEMA of HDITEMW
587 * [I] src : The source HDITEM. It may be a HDITEMA or HDITEMW
588 * [I] fSourceUnicode : is src a HDITEMW or HDITEMA
589 * [O] ppvScratch : a pointer to a scratch buffer that needs to be freed after
590 * the HDITEM is no longer in use or NULL if none was needed
592 * NOTE: We depend on HDITEMA and HDITEMW having the same structure
594 static void HEADER_CopyHDItemForNotify(HEADER_INFO *infoPtr, HDITEMW *dest,
595 HDITEMW *src, BOOL fSourceUnicode, LPVOID *ppvScratch)
600 if (src->mask & HDI_TEXT && src->pszText != LPSTR_TEXTCALLBACKW) /* covers TEXTCALLBACKA as well */
602 if (fSourceUnicode && infoPtr->nNotifyFormat != NFR_UNICODE)
604 dest->pszText = NULL;
605 Str_SetPtrWtoA((LPSTR *)&dest->pszText, src->pszText);
606 *ppvScratch = dest->pszText;
609 if (!fSourceUnicode && infoPtr->nNotifyFormat == NFR_UNICODE)
611 dest->pszText = NULL;
612 Str_SetPtrAtoW(&dest->pszText, (LPSTR)src->pszText);
613 *ppvScratch = dest->pszText;
618 static UINT HEADER_NotifyCodeWtoA(UINT code)
620 /* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
621 if (code >= HDN_LAST && code <= HDN_FIRST_UNICODE)
622 return code + HDN_UNICODE_OFFSET;
628 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
630 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
633 nmhdr.hwndFrom = hwnd;
634 nmhdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
637 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
638 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
642 HEADER_SendHeaderNotifyT (HWND hwnd, UINT code, INT iItem, INT mask, HDITEMW *lpItem)
644 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
650 /* lpItem == NULL means that we should take the actual data from the item */
653 FIXME("(): invalid parameters - lpItem == NULL and (mask & HDI_TEXT)\n");
657 nmitem.cxy = infoPtr->items[iItem].cxy;
658 nmitem.hbm = infoPtr->items[iItem].hbm;
659 nmitem.pszText = NULL;
660 nmitem.cchTextMax = 0;
661 nmitem.fmt = infoPtr->items[iItem].fmt;
662 nmitem.lParam = infoPtr->items[iItem].lParam;
663 nmitem.iOrder = infoPtr->items[iItem].iOrder;
664 nmitem.iImage = infoPtr->items[iItem].iImage;
668 nmhdr.hdr.hwndFrom = hwnd;
669 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
670 nmhdr.hdr.code = (infoPtr->nNotifyFormat == NFR_UNICODE ? code : HEADER_NotifyCodeWtoA(code));
673 nmhdr.pitem = lpItem;
675 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
676 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
680 * Send Disp Info notification.
681 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
682 * (so we handle the two cases only doing a specific cast for pszText).
684 * @param hwnd : hwnd header container handler
685 * @param mask : notification mask (usually HDI_TEXT or HDI_IMAGE)
686 * @param pDispInfo : NMHDDISPINFO structure (can be unicode or ansi)
687 * @param isW : TRUE if dispinfo is Unicode
690 HEADER_SendHeaderDispInfoNotify(HWND hwnd, INT iItem, INT mask, LPHDITEMW phdi, HEADER_ITEM* lpItem, BOOL isW)
692 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
694 BOOL convertToAnsi = FALSE;
695 BOOL convertToUnicode = FALSE;
696 BOOL isUnicodeNotify = FALSE;
697 NMHDDISPINFOW dispInfo;
701 convertToAnsi = (isW && infoPtr->nNotifyFormat == NFR_ANSI);
702 convertToUnicode = (!isW && infoPtr->nNotifyFormat == NFR_UNICODE);
704 isUnicodeNotify = (isW && !convertToAnsi);
706 memset(&dispInfo, 0, sizeof(NMHDDISPINFOW));
707 dispInfo.hdr.hwndFrom = hwnd;
708 dispInfo.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
709 if (isUnicodeNotify || convertToUnicode)
711 dispInfo.hdr.code = HDN_GETDISPINFOW;
715 dispInfo.hdr.code = HDN_GETDISPINFOA;
717 dispInfo.iItem = iItem;
718 dispInfo.mask = mask;
720 dispInfo.pszText = Alloc(sizeof(WCHAR) * 260);
721 dispInfo.cchTextMax = 260;
723 ret = (BOOL) SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
724 (WPARAM) dispInfo.hdr.idFrom,
727 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
729 (isUnicodeNotify ? debugstr_w(dispInfo.pszText) : (LPSTR) dispInfo.pszText),
730 (void*) dispInfo.lParam);
732 if (dispInfo.mask & HDI_DI_SETITEM)
734 if (dispInfo.mask & HDI_IMAGE)
736 lpItem->iImage = dispInfo.iImage;
738 if (dispInfo.mask & HDI_TEXT)
740 if (isUnicodeNotify || convertToUnicode)
741 Str_SetPtrW(&lpItem->pszText, (LPCWSTR)dispInfo.pszText);
742 else /*if (convertToAnsi || !isW)*/
743 Str_SetPtrAtoW(&lpItem->pszText, (LPCSTR)dispInfo.pszText);
746 FIXME("NMHDDISPINFO returns with flags HDI_DI_SETITEM\n");
751 if ((phdi->mask & mask) & HDI_IMAGE)
753 phdi->iImage = dispInfo.iImage;
755 if ((phdi->mask & mask) & HDI_TEXT)
758 Str_GetPtrW ((LPCWSTR)dispInfo.pszText, phdi->pszText, phdi->cchTextMax);
759 else if (convertToUnicode)
760 Str_GetPtrWtoA ((LPCWSTR)dispInfo.pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
762 Str_GetPtrA ((LPCSTR)dispInfo.pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
770 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
772 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
775 nmhdr.hdr.hwndFrom = hwnd;
776 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
777 nmhdr.hdr.code = code;
782 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
783 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
788 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
790 FIXME("empty stub!\n");
796 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
798 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
799 INT iItem = (INT)wParam;
801 TRACE("[iItem=%d]\n", iItem);
803 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
806 if (infoPtr->uNumItem == 1) {
807 TRACE("Simple delete!\n");
808 HEADER_DisposeItem(&infoPtr->items[0]);
809 Free (infoPtr->items);
810 Free(infoPtr->order);
813 infoPtr->uNumItem = 0;
816 HEADER_ITEM *oldItems = infoPtr->items;
819 TRACE("Complex delete! [iItem=%d]\n", iItem);
821 for (i = 0; i < infoPtr->uNumItem; i++)
822 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
823 HEADER_DisposeItem(&infoPtr->items[iItem]);
824 iOrder = infoPtr->items[iItem].iOrder;
827 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
828 /* pre delete copy */
830 memcpy (&infoPtr->items[0], &oldItems[0],
831 iItem * sizeof(HEADER_ITEM));
834 /* post delete copy */
835 if (iItem < infoPtr->uNumItem) {
836 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
837 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
840 /* Correct the orders */
841 if (iOrder < infoPtr->uNumItem)
843 memmove(&infoPtr->order[iOrder], &infoPtr->order[iOrder + 1],
844 (infoPtr->uNumItem - iOrder) * sizeof(INT));
845 for (i = 0; i < infoPtr->uNumItem; i++)
847 if (infoPtr->order[i] > iItem)
850 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
854 for (i = 0; i < infoPtr->uNumItem; i++)
855 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
859 HEADER_SetItemBounds (hwnd);
861 InvalidateRect(hwnd, NULL, FALSE);
868 HEADER_GetImageList (HWND hwnd)
870 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
872 return (LRESULT)infoPtr->himl;
877 HEADER_GetItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
879 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
885 TRACE("[nItem=%d]\n", nItem);
889 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
892 lpItem = &infoPtr->items[nItem];
894 if (phdi->mask & HDI_BITMAP)
895 phdi->hbm = (lpItem != NULL) ? lpItem->hbm : 0;
897 if (phdi->mask & HDI_FORMAT)
898 phdi->fmt = (lpItem != NULL) ? lpItem->fmt : 0;
900 if (phdi->mask & HDI_WIDTH)
901 phdi->cxy = (lpItem != NULL) ? lpItem->cxy : 0;
903 if (phdi->mask & HDI_LPARAM)
904 phdi->lParam = (lpItem != NULL) ? lpItem->lParam : 0;
906 if (phdi->mask & HDI_IMAGE)
908 phdi->iImage = (lpItem != NULL) ? lpItem->iImage : 0;
909 if (lpItem->iImage == I_IMAGECALLBACK)
911 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, phdi, lpItem, bUnicode);
915 if (phdi->mask & HDI_ORDER)
916 phdi->iOrder = (lpItem != NULL) ? lpItem->iOrder : 0;
918 if (phdi->mask & HDI_TEXT)
920 if (lpItem == NULL) *phdi->pszText = 0; /* null pointer check */
921 else if (lpItem->pszText == LPSTR_TEXTCALLBACKW) /* covers == TEXTCALLBACKA too */
923 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, phdi, lpItem, bUnicode);
928 Str_GetPtrW (lpItem->pszText, phdi->pszText, phdi->cchTextMax);
930 Str_GetPtrWtoA (lpItem->pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
938 inline static LRESULT
939 HEADER_GetItemCount (HWND hwnd)
941 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
942 return infoPtr->uNumItem;
947 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
949 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
950 INT iItem = (INT)wParam;
951 LPRECT lpRect = (LPRECT)lParam;
953 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
956 lpRect->left = infoPtr->items[iItem].rect.left;
957 lpRect->right = infoPtr->items[iItem].rect.right;
958 lpRect->top = infoPtr->items[iItem].rect.top;
959 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
966 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
968 LPINT order = (LPINT) lParam;
969 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
971 if ((unsigned int)wParam <infoPtr->uNumItem)
974 memcpy(order, infoPtr->order, infoPtr->uNumItem * sizeof(INT));
979 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
982 LPINT order = (LPINT) lParam;
983 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
986 if ((unsigned int)wParam <infoPtr->uNumItem)
988 memcpy(infoPtr->order, order, infoPtr->uNumItem * sizeof(INT));
989 for (i=0; i<(int)wParam; i++)
991 lpItem = &infoPtr->items[*order++];
994 infoPtr->bRectsValid=0;
995 InvalidateRect(hwnd, NULL, FALSE);
999 inline static LRESULT
1000 HEADER_GetUnicodeFormat (HWND hwnd)
1002 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1003 return (infoPtr->nNotifyFormat == NFR_UNICODE);
1008 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
1010 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
1012 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
1014 if (phti->flags == HHT_NOWHERE)
1022 HEADER_InsertItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
1024 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1025 HEADER_ITEM *lpItem;
1029 if ((phdi == NULL) || (nItem < 0))
1032 if (nItem > infoPtr->uNumItem)
1033 nItem = infoPtr->uNumItem;
1035 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
1038 else if (infoPtr->uNumItem < iOrder)
1039 iOrder = infoPtr->uNumItem;
1041 if (infoPtr->uNumItem == 0) {
1042 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
1043 infoPtr->order = Alloc(sizeof(INT));
1044 infoPtr->uNumItem++;
1047 HEADER_ITEM *oldItems = infoPtr->items;
1048 INT *oldOrder = infoPtr->order;
1050 infoPtr->uNumItem++;
1051 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
1053 memcpy (&infoPtr->items[1], &oldItems[0],
1054 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
1058 /* pre insert copy */
1060 memcpy (&infoPtr->items[0], &oldItems[0],
1061 nItem * sizeof(HEADER_ITEM));
1064 /* post insert copy */
1065 if (nItem < infoPtr->uNumItem - 1) {
1066 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
1067 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
1071 infoPtr->order = Alloc(sizeof(INT) * infoPtr->uNumItem);
1072 memcpy(infoPtr->order, oldOrder, iOrder * sizeof(INT));
1073 infoPtr->order[iOrder] = nItem;
1074 memcpy(&infoPtr->order[iOrder + 1], &oldOrder[iOrder],
1075 (infoPtr->uNumItem - iOrder - 1) * sizeof(INT));
1081 for (i = 0; i < infoPtr->uNumItem; i++)
1083 if (i != iOrder && infoPtr->order[i] >= nItem)
1084 infoPtr->order[i]++;
1085 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
1088 lpItem = &infoPtr->items[nItem];
1089 lpItem->bDown = FALSE;
1091 if (phdi->mask & HDI_WIDTH)
1092 lpItem->cxy = phdi->cxy;
1094 if (phdi->mask & HDI_FORMAT)
1095 lpItem->fmt = phdi->fmt;
1097 if (lpItem->fmt == 0)
1098 lpItem->fmt = HDF_LEFT;
1100 if (phdi->mask & HDI_BITMAP)
1101 lpItem->hbm = phdi->hbm;
1103 if (phdi->mask & HDI_LPARAM)
1104 lpItem->lParam = phdi->lParam;
1106 if (phdi->mask & HDI_IMAGE)
1108 if (phdi->iImage != I_IMAGECALLBACK)
1110 lpItem->iImage = phdi->iImage;
1114 lpItem->iImage = phdi->iImage;
1115 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, NULL, lpItem, bUnicode);
1119 if (phdi->mask & HDI_TEXT)
1121 if (!phdi->pszText) phdi->pszText = emptyString; /* null pointer check */
1122 if (phdi->pszText != LPSTR_TEXTCALLBACKW) /* covers != TEXTCALLBACKA too */
1125 Str_SetPtrW(&lpItem->pszText, phdi->pszText);
1127 Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)phdi->pszText);
1131 lpItem->pszText = phdi->pszText;
1132 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, NULL, lpItem, bUnicode);
1134 lpItem->fmt |= HDF_STRING;
1137 lpItem->iOrder = iOrder;
1139 HEADER_SetItemBounds (hwnd);
1141 InvalidateRect(hwnd, NULL, FALSE);
1148 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
1150 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1151 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1153 lpLayout->pwpos->hwnd = hwnd;
1154 lpLayout->pwpos->hwndInsertAfter = 0;
1155 lpLayout->pwpos->x = lpLayout->prc->left;
1156 lpLayout->pwpos->y = lpLayout->prc->top;
1157 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1158 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_HIDDEN)
1159 lpLayout->pwpos->cy = 0;
1161 lpLayout->pwpos->cy = infoPtr->nHeight;
1162 lpLayout->prc->top += infoPtr->nHeight;
1164 lpLayout->pwpos->flags = SWP_NOZORDER;
1166 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1167 lpLayout->pwpos->x, lpLayout->pwpos->y,
1168 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1170 infoPtr->bRectsValid = FALSE;
1177 HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
1179 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1182 TRACE("(himl %p)\n", himl);
1183 himlOld = infoPtr->himl;
1184 infoPtr->himl = himl;
1186 /* FIXME: Refresh needed??? */
1188 return (LRESULT)himlOld;
1193 HEADER_GetBitmapMargin(HWND hwnd)
1195 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
1197 return infoPtr->iMargin;
1201 HEADER_SetBitmapMargin(HWND hwnd, WPARAM wParam)
1203 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1204 INT oldMargin = infoPtr->iMargin;
1206 infoPtr->iMargin = (INT)wParam;
1212 HEADER_SetItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
1214 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1215 HEADER_ITEM *lpItem;
1221 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1224 TRACE("[nItem=%d]\n", nItem);
1226 HEADER_CopyHDItemForNotify(infoPtr, &hdNotify, phdi, bUnicode, &pvScratch);
1227 if (HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask, &hdNotify))
1229 if (pvScratch) Free(pvScratch);
1233 lpItem = &infoPtr->items[nItem];
1234 if (phdi->mask & HDI_BITMAP)
1235 lpItem->hbm = phdi->hbm;
1237 if (phdi->mask & HDI_FORMAT)
1238 lpItem->fmt = phdi->fmt;
1240 if (phdi->mask & HDI_LPARAM)
1241 lpItem->lParam = phdi->lParam;
1243 if (phdi->mask & HDI_WIDTH)
1244 lpItem->cxy = phdi->cxy;
1246 if (phdi->mask & HDI_IMAGE)
1248 if (phdi->iImage != I_IMAGECALLBACK)
1250 lpItem->iImage = phdi->iImage;
1254 lpItem->iImage = phdi->iImage;
1255 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, NULL, lpItem, bUnicode);
1259 if (phdi->mask & HDI_TEXT)
1261 if (phdi->pszText != LPSTR_TEXTCALLBACKW) /* covers != TEXTCALLBACKA too */
1263 if (lpItem->pszText)
1265 if (lpItem->pszText != emptyString && lpItem->pszText != LPSTR_TEXTCALLBACKW)
1266 Free(lpItem->pszText);
1267 lpItem->pszText = NULL;
1272 Str_SetPtrW(&lpItem->pszText, phdi->pszText);
1274 Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)phdi->pszText);
1279 lpItem->pszText = phdi->pszText;
1280 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, NULL, lpItem, bUnicode);
1284 if (phdi->mask & HDI_ORDER)
1288 if (lpItem->iOrder < phdi->iOrder)
1290 memmove(&infoPtr->order[lpItem->iOrder],
1291 &infoPtr->order[lpItem->iOrder + 1],
1292 (phdi->iOrder - lpItem->iOrder) * sizeof(INT));
1294 if (phdi->iOrder < lpItem->iOrder)
1296 memmove(&infoPtr->order[phdi->iOrder + 1],
1297 &infoPtr->order[phdi->iOrder],
1298 (lpItem->iOrder - phdi->iOrder) * sizeof(INT));
1300 infoPtr->order[phdi->iOrder] = nItem;
1301 nMin = min(lpItem->iOrder, phdi->iOrder);
1302 nMax = max(lpItem->iOrder, phdi->iOrder);
1303 for (i = nMin; i <= nMax; i++)
1305 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
1309 HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMCHANGEDW, nItem, phdi->mask, &hdNotify);
1311 HEADER_SetItemBounds (hwnd);
1313 InvalidateRect(hwnd, NULL, FALSE);
1315 if (pvScratch != NULL)
1320 inline static LRESULT
1321 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1323 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1324 BOOL bTemp = (infoPtr->nNotifyFormat == NFR_UNICODE);
1326 infoPtr->nNotifyFormat = ((BOOL)wParam ? NFR_UNICODE : NFR_ANSI);
1333 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1335 HEADER_INFO *infoPtr;
1340 infoPtr = (HEADER_INFO *)Alloc (sizeof(HEADER_INFO));
1341 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1343 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
1344 infoPtr->uNumItem = 0;
1348 infoPtr->bRectsValid = FALSE;
1349 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1350 infoPtr->hcurDivider = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDER));
1351 infoPtr->hcurDivopen = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDEROPEN));
1352 infoPtr->bPressed = FALSE;
1353 infoPtr->bTracking = FALSE;
1354 infoPtr->iMoveItem = 0;
1356 infoPtr->iHotItem = -1;
1357 infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
1358 infoPtr->nNotifyFormat =
1359 SendMessageW (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1362 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1363 GetTextMetricsW (hdc, &tm);
1364 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1365 SelectObject (hdc, hOldFont);
1368 OpenThemeData(hwnd, themeClass);
1375 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1377 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1378 HEADER_ITEM *lpItem;
1382 if (infoPtr->items) {
1383 lpItem = infoPtr->items;
1384 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1385 HEADER_DisposeItem(lpItem);
1387 Free (infoPtr->items);
1391 Free(infoPtr->order);
1394 ImageList_Destroy (infoPtr->himl);
1396 SetWindowLongPtrW (hwnd, 0, 0);
1399 theme = GetWindowTheme(hwnd);
1400 CloseThemeData(theme);
1405 static inline LRESULT
1406 HEADER_GetFont (HWND hwnd)
1408 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1410 return (LRESULT)infoPtr->hFont;
1415 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1421 pt.x = (INT)LOWORD(lParam);
1422 pt.y = (INT)HIWORD(lParam);
1423 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1425 if ((GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1426 HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMDBLCLICKW, nItem, 0, NULL);
1427 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1428 HEADER_SendHeaderNotifyT (hwnd, HDN_DIVIDERDBLCLICKW, nItem, 0, NULL);
1435 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1437 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1438 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1444 pt.x = (INT)LOWORD(lParam);
1445 pt.y = (INT)HIWORD(lParam);
1446 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1448 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1450 infoPtr->bCaptured = TRUE;
1451 infoPtr->bPressed = TRUE;
1452 infoPtr->iMoveItem = nItem;
1454 infoPtr->items[nItem].bDown = TRUE;
1456 /* Send WM_CUSTOMDRAW */
1458 HEADER_RefreshItem (hwnd, hdc, nItem);
1459 ReleaseDC (hwnd, hdc);
1461 TRACE("Pressed item %d!\n", nItem);
1463 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1464 if (!(HEADER_SendHeaderNotifyT (hwnd, HDN_BEGINTRACKW, nItem, 0, NULL))) {
1466 infoPtr->bCaptured = TRUE;
1467 infoPtr->bTracking = TRUE;
1468 infoPtr->iMoveItem = nItem;
1469 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1470 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1472 if (!(dwStyle & HDS_FULLDRAG)) {
1473 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1475 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1476 ReleaseDC (hwnd, hdc);
1479 TRACE("Begin tracking item %d!\n", nItem);
1488 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1490 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1491 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1497 pt.x = (INT)(SHORT)LOWORD(lParam);
1498 pt.y = (INT)(SHORT)HIWORD(lParam);
1499 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1501 if (infoPtr->bPressed) {
1502 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1503 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1505 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1506 ReleaseDC (hwnd, hdc);
1508 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1510 else if (flags == HHT_ONHEADER)
1512 HEADER_ITEM *lpItem;
1513 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1514 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1516 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1517 infoPtr->iMoveItem,oldindex,nItem,newindex);
1518 lpItem= &infoPtr->items[nItem];
1519 lpItem->iOrder=oldindex;
1521 lpItem= &infoPtr->items[infoPtr->iMoveItem];
1522 lpItem->iOrder = newindex;
1524 infoPtr->order[oldindex] = nItem;
1525 infoPtr->order[newindex] = infoPtr->iMoveItem;
1527 infoPtr->bRectsValid = FALSE;
1528 InvalidateRect(hwnd, NULL, FALSE);
1529 /* FIXME: Should some WM_NOTIFY be sent */
1532 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1533 infoPtr->bPressed = FALSE;
1535 else if (infoPtr->bTracking) {
1536 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1537 infoPtr->bTracking = FALSE;
1539 HEADER_SendHeaderNotifyT (hwnd, HDN_ENDTRACKW, infoPtr->iMoveItem, HDI_WIDTH, NULL);
1541 if (!(dwStyle & HDS_FULLDRAG)) {
1543 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1544 ReleaseDC (hwnd, hdc);
1547 if (HEADER_SendHeaderNotifyT(hwnd, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH, NULL))
1549 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1552 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1555 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1558 HEADER_SetItemBounds (hwnd);
1559 InvalidateRect(hwnd, NULL, TRUE);
1560 HEADER_SendHeaderNotifyT(hwnd, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH, NULL);
1563 if (infoPtr->bCaptured) {
1564 infoPtr->bCaptured = FALSE;
1566 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1574 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1576 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1581 return infoPtr->nNotifyFormat;
1584 infoPtr->nNotifyFormat =
1585 SendMessageW ((HWND)wParam, WM_NOTIFYFORMAT,
1586 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1587 return infoPtr->nNotifyFormat;
1595 HEADER_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
1597 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1598 /* Reset hot-tracked item when mouse leaves control. */
1599 INT oldHotItem = infoPtr->iHotItem;
1600 HDC hdc = GetDC (hwnd);
1602 infoPtr->iHotItem = -1;
1603 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem);
1604 ReleaseDC (hwnd, hdc);
1611 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1613 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1614 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1619 /* With theming, hottracking is always enabled */
1620 BOOL hotTrackEnabled =
1621 ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK))
1622 || (GetWindowTheme (hwnd) != NULL);
1623 INT oldHotItem = infoPtr->iHotItem;
1625 pt.x = (INT)(SHORT)LOWORD(lParam);
1626 pt.y = (INT)(SHORT)HIWORD(lParam);
1627 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1629 if (hotTrackEnabled) {
1630 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1631 infoPtr->iHotItem = nItem;
1633 infoPtr->iHotItem = -1;
1636 if (infoPtr->bCaptured) {
1637 if (infoPtr->bPressed) {
1638 BOOL oldState = infoPtr->items[infoPtr->iMoveItem].bDown;
1639 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1640 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1642 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1643 if (oldState != infoPtr->items[infoPtr->iMoveItem].bDown) {
1645 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1646 ReleaseDC (hwnd, hdc);
1649 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1651 else if (infoPtr->bTracking) {
1652 if (dwStyle & HDS_FULLDRAG) {
1653 if (!HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH, NULL))
1655 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1658 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1659 HEADER_SendHeaderNotifyT(hwnd, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH, NULL);
1661 HEADER_SetItemBounds (hwnd);
1662 InvalidateRect(hwnd, NULL, FALSE);
1666 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1667 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1668 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1669 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1670 infoPtr->items[infoPtr->iMoveItem].cxy =
1671 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1672 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1673 ReleaseDC (hwnd, hdc);
1674 HEADER_SendHeaderNotifyT (hwnd, HDN_TRACKW, infoPtr->iMoveItem, HDI_WIDTH, NULL);
1677 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1681 if (hotTrackEnabled) {
1682 TRACKMOUSEEVENT tme;
1683 if (oldHotItem != infoPtr->iHotItem) {
1685 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem);
1686 if (infoPtr->iHotItem != -1) HEADER_RefreshItem (hwnd, hdc, infoPtr->iHotItem);
1687 ReleaseDC (hwnd, hdc);
1689 tme.cbSize = sizeof( tme );
1690 tme.dwFlags = TME_LEAVE;
1691 tme.hwndTrack = hwnd;
1692 TrackMouseEvent( &tme );
1700 HEADER_Paint (HWND hwnd, WPARAM wParam)
1705 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1706 HEADER_Refresh (hwnd, hdc);
1708 EndPaint (hwnd, &ps);
1714 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1719 pt.x = LOWORD(lParam);
1720 pt.y = HIWORD(lParam);
1722 /* Send a Notify message */
1723 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1725 /* Change to screen coordinate for WM_CONTEXTMENU */
1726 ClientToScreen(hwnd, &pt);
1728 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1729 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1736 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1738 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1743 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1746 ScreenToClient (hwnd, &pt);
1748 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1750 if (flags == HHT_ONDIVIDER)
1751 SetCursor (infoPtr->hcurDivider);
1752 else if (flags == HHT_ONDIVOPEN)
1753 SetCursor (infoPtr->hcurDivopen);
1755 SetCursor (infoPtr->hcurArrow);
1762 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1764 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1766 HFONT hFont, hOldFont;
1769 infoPtr->hFont = (HFONT)wParam;
1771 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1774 hOldFont = SelectObject (hdc, hFont);
1775 GetTextMetricsW (hdc, &tm);
1776 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1777 SelectObject (hdc, hOldFont);
1780 infoPtr->bRectsValid = FALSE;
1783 InvalidateRect(hwnd, NULL, FALSE);
1789 /* Update the theme handle after a theme change */
1790 static LRESULT HEADER_ThemeChanged(HWND hwnd)
1792 HTHEME theme = GetWindowTheme(hwnd);
1793 CloseThemeData(theme);
1794 OpenThemeData(hwnd, themeClass);
1795 InvalidateRect(hwnd, NULL, FALSE);
1800 static LRESULT WINAPI
1801 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1803 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1804 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1805 return DefWindowProcW (hwnd, msg, wParam, lParam);
1807 /* case HDM_CLEARFILTER: */
1809 case HDM_CREATEDRAGIMAGE:
1810 return HEADER_CreateDragImage (hwnd, wParam);
1812 case HDM_DELETEITEM:
1813 return HEADER_DeleteItem (hwnd, wParam);
1815 /* case HDM_EDITFILTER: */
1817 case HDM_GETBITMAPMARGIN:
1818 return HEADER_GetBitmapMargin(hwnd);
1820 case HDM_GETIMAGELIST:
1821 return HEADER_GetImageList (hwnd);
1825 return HEADER_GetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_GETITEMW);
1827 case HDM_GETITEMCOUNT:
1828 return HEADER_GetItemCount (hwnd);
1830 case HDM_GETITEMRECT:
1831 return HEADER_GetItemRect (hwnd, wParam, lParam);
1833 case HDM_GETORDERARRAY:
1834 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1836 case HDM_GETUNICODEFORMAT:
1837 return HEADER_GetUnicodeFormat (hwnd);
1840 return HEADER_HitTest (hwnd, wParam, lParam);
1842 case HDM_INSERTITEMA:
1843 case HDM_INSERTITEMW:
1844 return HEADER_InsertItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_INSERTITEMW);
1847 return HEADER_Layout (hwnd, wParam, lParam);
1849 case HDM_ORDERTOINDEX:
1850 return HEADER_OrderToIndex(hwnd, wParam);
1852 case HDM_SETBITMAPMARGIN:
1853 return HEADER_SetBitmapMargin(hwnd, wParam);
1855 /* case HDM_SETFILTERCHANGETIMEOUT: */
1857 /* case HDM_SETHOTDIVIDER: */
1859 case HDM_SETIMAGELIST:
1860 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
1864 return HEADER_SetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_SETITEMW);
1866 case HDM_SETORDERARRAY:
1867 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1869 case HDM_SETUNICODEFORMAT:
1870 return HEADER_SetUnicodeFormat (hwnd, wParam);
1873 return HEADER_Create (hwnd, wParam, lParam);
1876 return HEADER_Destroy (hwnd, wParam, lParam);
1882 return DLGC_WANTTAB | DLGC_WANTARROWS;
1885 return HEADER_GetFont (hwnd);
1887 case WM_LBUTTONDBLCLK:
1888 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1890 case WM_LBUTTONDOWN:
1891 return HEADER_LButtonDown (hwnd, wParam, lParam);
1894 return HEADER_LButtonUp (hwnd, wParam, lParam);
1897 return HEADER_MouseLeave (hwnd, wParam, lParam);
1900 return HEADER_MouseMove (hwnd, wParam, lParam);
1902 case WM_NOTIFYFORMAT:
1903 return HEADER_NotifyFormat (hwnd, wParam, lParam);
1906 return HEADER_Size (hwnd, wParam);
1908 case WM_THEMECHANGED:
1909 return HEADER_ThemeChanged (hwnd);
1911 case WM_PRINTCLIENT:
1913 return HEADER_Paint (hwnd, wParam);
1916 return HEADER_RButtonUp (hwnd, wParam, lParam);
1919 return HEADER_SetCursor (hwnd, wParam, lParam);
1922 return HEADER_SetFont (hwnd, wParam, lParam);
1925 if ((msg >= WM_USER) && (msg < WM_APP))
1926 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1927 msg, wParam, lParam );
1928 return DefWindowProcA (hwnd, msg, wParam, lParam);
1934 HEADER_Register (void)
1938 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1939 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1940 wndClass.lpfnWndProc = HEADER_WindowProc;
1941 wndClass.cbClsExtra = 0;
1942 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1943 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1944 wndClass.lpszClassName = WC_HEADERW;
1946 RegisterClassW (&wndClass);
1951 HEADER_Unregister (void)
1953 UnregisterClassW (WC_HEADERW, NULL);