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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 */
64 DWORD callbackMask; /* HDI_* flags for items that are callback */
70 HWND hwndNotify; /* Owner window to send notifications to */
71 INT nNotifyFormat; /* format used for WM_NOTIFY messages */
72 UINT uNumItem; /* number of items (columns) */
73 INT nHeight; /* height of the header (pixels) */
74 HFONT hFont; /* handle to the current font */
75 HCURSOR hcurArrow; /* handle to the arrow cursor */
76 HCURSOR hcurDivider; /* handle to a cursor (used over dividers) <-|-> */
77 HCURSOR hcurDivopen; /* handle to a cursor (used over dividers) <-||-> */
78 BOOL bCaptured; /* Is the mouse captured? */
79 BOOL bPressed; /* Is a header item pressed (down)? */
80 BOOL bTracking; /* Is in tracking mode? */
81 INT iMoveItem; /* index of tracked item. (Tracking mode) */
82 INT xTrackOffset; /* distance between the right side of the tracked item and the cursor */
83 INT xOldTrack; /* track offset (see above) after the last WM_MOUSEMOVE */
84 INT nOldWidth; /* width of a sizing item after the last WM_MOUSEMOVE */
85 INT iHotItem; /* index of hot item (cursor is over this item) */
86 INT iMargin; /* width of the margin that surrounds a bitmap */
88 HIMAGELIST himl; /* handle to an image list (may be 0) */
89 HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */
90 INT *order; /* array of item IDs indexed by order */
91 BOOL bRectsValid; /* validity flag for bounding rectangles */
96 #define DIVIDER_WIDTH 10
97 #define MAX_HEADER_TEXT_LEN 260
98 #define HDN_UNICODE_OFFSET 20
99 #define HDN_FIRST_UNICODE (HDN_FIRST-HDN_UNICODE_OFFSET)
101 #define HDI_SUPPORTED_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP|HDI_IMAGE|HDI_ORDER)
102 #define HDI_UNSUPPORTED_FIELDS (HDI_FILTER)
103 #define HDI_UNKNOWN_FIELDS (~(HDI_SUPPORTED_FIELDS|HDI_UNSUPPORTED_FIELDS|HDI_DI_SETITEM))
104 #define HDI_COMCTL32_4_0_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP)
106 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongPtrW(hwnd,0))
108 static BOOL HEADER_PrepareCallbackItems(HWND hwnd, INT iItem, INT reqMask);
109 static void HEADER_FreeCallbackItems(HEADER_ITEM *lpItem);
111 static const WCHAR themeClass[] = {'H','e','a','d','e','r',0};
112 static WCHAR emptyString[] = {0};
114 static void HEADER_DisposeItem(HEADER_ITEM *lpItem)
118 Free(lpItem->pszText);
122 static void HEADER_StoreHDItemInHeader(HEADER_ITEM *lpItem, UINT mask, HDITEMW *phdi, BOOL fUnicode)
124 if (mask & HDI_UNSUPPORTED_FIELDS)
125 FIXME("unsupported header fields %x\n", (mask & HDI_UNSUPPORTED_FIELDS));
127 if (mask & HDI_BITMAP)
128 lpItem->hbm = phdi->hbm;
130 if (mask & HDI_FORMAT)
131 lpItem->fmt = phdi->fmt;
133 if (mask & HDI_LPARAM)
134 lpItem->lParam = phdi->lParam;
136 if (mask & HDI_WIDTH)
137 lpItem->cxy = phdi->cxy;
139 if (mask & HDI_IMAGE)
141 lpItem->iImage = phdi->iImage;
142 if (phdi->iImage == I_IMAGECALLBACK)
143 lpItem->callbackMask |= HDI_IMAGE;
145 lpItem->callbackMask &= ~HDI_IMAGE;
152 Free(lpItem->pszText);
153 lpItem->pszText = NULL;
156 if (phdi->pszText != LPSTR_TEXTCALLBACKW) /* covers != TEXTCALLBACKA too */
158 LPWSTR pszText = (phdi->pszText != NULL ? phdi->pszText : emptyString);
160 Str_SetPtrW(&lpItem->pszText, pszText);
162 Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)pszText);
163 lpItem->callbackMask &= ~HDI_TEXT;
167 lpItem->pszText = NULL;
168 lpItem->callbackMask |= HDI_TEXT;
173 inline static LRESULT
174 HEADER_IndexToOrder (HWND hwnd, INT iItem)
176 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
177 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
178 return lpItem->iOrder;
183 HEADER_OrderToIndex(HWND hwnd, WPARAM wParam)
185 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
186 INT iorder = (INT)wParam;
188 if ((iorder <0) || iorder >= infoPtr->uNumItem)
190 return infoPtr->order[iorder];
194 HEADER_SetItemBounds (HWND hwnd)
196 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
202 infoPtr->bRectsValid = TRUE;
204 if (infoPtr->uNumItem == 0)
207 GetClientRect (hwnd, &rect);
210 for (i = 0; i < infoPtr->uNumItem; i++) {
211 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
212 phdi->rect.top = rect.top;
213 phdi->rect.bottom = rect.bottom;
215 phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
216 x = phdi->rect.right;
221 HEADER_Size (HWND hwnd, WPARAM wParam)
223 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
225 infoPtr->bRectsValid = FALSE;
232 HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
234 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
235 HEADER_ITEM *phdi = &infoPtr->items[iItem];
237 INT oldBkMode, cxEdge = GetSystemMetrics(SM_CXEDGE);
238 HTHEME theme = GetWindowTheme (hwnd);
241 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, (infoPtr->nNotifyFormat == NFR_UNICODE));
243 if (!infoPtr->bRectsValid)
244 HEADER_SetItemBounds(hwnd);
247 if (r.right - r.left == 0)
248 return phdi->rect.right;
251 int state = (phdi->bDown) ? HIS_PRESSED :
252 (bHotTrack ? HIS_HOT : HIS_NORMAL);
253 DrawThemeBackground (theme, hdc, HP_HEADERITEM, state,
255 GetThemeBackgroundContentRect (theme, hdc, HP_HEADERITEM, state,
259 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) {
261 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
262 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
265 DrawEdge (hdc, &r, EDGE_RAISED,
266 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
269 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
279 /* Set the colors before sending NM_CUSTOMDRAW so that it can change them */
280 SetTextColor (hdc, (bHotTrack && !theme) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
281 SetBkColor(hdc, GetSysColor(COLOR_3DFACE));
283 nmcd.hdr.hwndFrom = hwnd;
284 nmcd.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
285 nmcd.hdr.code = NM_CUSTOMDRAW;
286 nmcd.dwDrawStage = CDDS_PREPAINT | CDDS_ITEM | CDDS_ITEMPOSTERASE;
288 nmcd.dwItemSpec = iItem;
290 nmcd.uItemState = phdi->bDown ? CDIS_SELECTED : 0;
291 nmcd.lItemlParam = phdi->lParam;
293 SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, nmcd.hdr.idFrom, (LPARAM)&nmcd);
295 if (phdi->fmt & HDF_OWNERDRAW) {
298 dis.CtlType = ODT_HEADER;
299 dis.CtlID = GetWindowLongPtrW (hwnd, GWLP_ID);
301 dis.itemAction = ODA_DRAWENTIRE;
302 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
306 dis.itemData = phdi->lParam;
307 oldBkMode = SetBkMode(hdc, TRANSPARENT);
308 SendMessageW (infoPtr->hwndNotify, WM_DRAWITEM,
309 (WPARAM)dis.CtlID, (LPARAM)&dis);
310 if (oldBkMode != TRANSPARENT)
311 SetBkMode(hdc, oldBkMode);
314 UINT rw, rh, /* width and height of r */
315 *x = NULL, *w = NULL; /* x and width of the pic (bmp or img) which is part of cnt */
316 /* cnt,txt,img,bmp */
321 HEADER_PrepareCallbackItems(hwnd, iItem, HDI_TEXT|HDI_IMAGE);
322 cw = tw = iw = bw = 0;
323 rw = r.right - r.left;
324 rh = r.bottom - r.top;
327 HBRUSH hbr = CreateSolidBrush(GetBkColor(hdc));
328 RECT rcBackground = r;
330 rcBackground.right -= cxEdge;
331 rcBackground.left += cxEdge;
332 FillRect(hdc, &rcBackground, hbr);
335 if (phdi->fmt & HDF_STRING) {
338 DrawTextW (hdc, phdi->pszText, -1,
339 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
340 cw = textRect.right - textRect.left + 2 * infoPtr->iMargin;
343 if ((phdi->fmt & HDF_IMAGE) && (infoPtr->himl)) {
344 iw = infoPtr->himl->cx + 2 * infoPtr->iMargin;
349 if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
350 GetObjectW (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
351 bw = bmp.bmWidth + 2 * infoPtr->iMargin;
361 /* align cx using the unclipped cw */
362 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_LEFT)
364 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
365 cx = r.left + rw / 2 - cw / 2;
372 if (cx + cw > r.right)
375 tx = cx + infoPtr->iMargin;
376 /* since cw might have changed we have to recalculate tw */
377 tw = cw - infoPtr->iMargin * 2;
381 if (phdi->fmt & HDF_BITMAP_ON_RIGHT) {
382 /* put pic behind text */
383 *x = cx + tw + infoPtr->iMargin * 3;
385 *x = cx + infoPtr->iMargin;
386 /* move text behind pic */
392 /* since we're done with the layout we can
393 now calculate the position of bmp which
394 has no influence on alignment and layout
396 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
397 bx = cx - bw + infoPtr->iMargin;
399 bx = cx + cw + infoPtr->iMargin;
403 HDC hClipDC = GetDC(hwnd);
404 HRGN hClipRgn = CreateRectRgn(r.left, r.top, r.right, r.bottom);
405 SelectClipRgn(hClipDC, hClipRgn);
408 HDC hdcBitmap = CreateCompatibleDC (hClipDC);
409 SelectObject (hdcBitmap, phdi->hbm);
410 BitBlt (hClipDC, bx, r.top + ((INT)rh - bmp.bmHeight) / 2,
411 bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
412 DeleteDC (hdcBitmap);
416 ImageList_DrawEx (infoPtr->himl, phdi->iImage, hClipDC,
417 ix, r.top + ((INT)rh - infoPtr->himl->cy) / 2,
418 infoPtr->himl->cx, infoPtr->himl->cy, CLR_DEFAULT, CLR_DEFAULT, 0);
421 DeleteObject(hClipRgn);
422 ReleaseDC(hwnd, hClipDC);
425 if (((phdi->fmt & HDF_STRING)
426 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
427 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
428 && (phdi->pszText)) {
429 oldBkMode = SetBkMode(hdc, TRANSPARENT);
432 DrawTextW (hdc, phdi->pszText, -1,
433 &r, DT_LEFT|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
434 if (oldBkMode != TRANSPARENT)
435 SetBkMode(hdc, oldBkMode);
437 HEADER_FreeCallbackItems(phdi);
440 return phdi->rect.right;
445 HEADER_Refresh (HWND hwnd, HDC hdc)
447 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
448 HFONT hFont, hOldFont;
453 HTHEME theme = GetWindowTheme (hwnd);
455 /* get rect for the bar, adjusted for the border */
456 GetClientRect (hwnd, &rect);
458 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
459 hOldFont = SelectObject (hdc, hFont);
461 /* draw Background */
462 if (infoPtr->uNumItem == 0 && theme == NULL) {
463 hbrBk = GetSysColorBrush(COLOR_3DFACE);
464 FillRect(hdc, &rect, hbrBk);
468 for (i = 0; x <= rect.right && i < infoPtr->uNumItem; i++) {
469 int idx = HEADER_OrderToIndex(hwnd,i);
470 if (RectVisible(hdc, &infoPtr->items[idx].rect))
471 HEADER_DrawItem (hwnd, hdc, idx, infoPtr->iHotItem == i);
472 x = infoPtr->items[idx].rect.right;
475 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
478 DrawThemeBackground (theme, hdc, HP_HEADERITEM, HIS_NORMAL, &rect,
482 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS)
483 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT|BF_MIDDLE);
485 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM|BF_MIDDLE);
489 SelectObject (hdc, hOldFont);
494 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
496 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
497 HFONT hFont, hOldFont;
499 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
500 hOldFont = SelectObject (hdc, hFont);
501 HEADER_DrawItem (hwnd, hdc, iItem, infoPtr->iHotItem == iItem);
502 SelectObject (hdc, hOldFont);
507 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
509 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
515 GetClientRect (hwnd, &rect);
519 if (PtInRect (&rect, *lpPt))
521 if (infoPtr->uNumItem == 0) {
522 *pFlags |= HHT_NOWHERE;
528 /* somewhere inside */
529 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
530 rect = infoPtr->items[iCount].rect;
531 width = rect.right - rect.left;
536 if (PtInRect (&rect, *lpPt)) {
537 if (width <= 2 * DIVIDER_WIDTH) {
538 *pFlags |= HHT_ONHEADER;
540 TRACE("ON HEADER %d\n", iCount);
545 rcTest.right = rcTest.left + DIVIDER_WIDTH;
546 if (PtInRect (&rcTest, *lpPt)) {
548 *pFlags |= HHT_ONDIVOPEN;
550 TRACE("ON DIVOPEN %d\n", *pItem);
554 *pFlags |= HHT_ONDIVIDER;
556 TRACE("ON DIVIDER %d\n", *pItem);
562 rcTest.left = rcTest.right - DIVIDER_WIDTH;
563 if (PtInRect (&rcTest, *lpPt)) {
564 *pFlags |= HHT_ONDIVIDER;
566 TRACE("ON DIVIDER %d\n", *pItem);
570 *pFlags |= HHT_ONHEADER;
572 TRACE("ON HEADER %d\n", iCount);
577 /* check for last divider part (on nowhere) */
578 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
579 rect.left = rect.right;
580 rect.right += DIVIDER_WIDTH;
581 if (PtInRect (&rect, *lpPt)) {
583 *pFlags |= HHT_ONDIVOPEN;
584 *pItem = infoPtr->uNumItem - 1;
585 TRACE("ON DIVOPEN %d\n", *pItem);
589 *pFlags |= HHT_ONDIVIDER;
590 *pItem = infoPtr->uNumItem-1;
591 TRACE("ON DIVIDER %d\n", *pItem);
596 *pFlags |= HHT_NOWHERE;
603 if (lpPt->x < rect.left) {
605 *pFlags |= HHT_TOLEFT;
607 else if (lpPt->x > rect.right) {
609 *pFlags |= HHT_TORIGHT;
612 if (lpPt->y < rect.top) {
614 *pFlags |= HHT_ABOVE;
616 else if (lpPt->y > rect.bottom) {
618 *pFlags |= HHT_BELOW;
623 TRACE("flags=0x%X\n", *pFlags);
629 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
635 GetClientRect (hwnd, &rect);
637 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
638 oldRop = SetROP2 (hdc, R2_XORPEN);
639 MoveToEx (hdc, x, rect.top, NULL);
640 LineTo (hdc, x, rect.bottom);
641 SetROP2 (hdc, oldRop);
642 SelectObject (hdc, hOldPen);
647 * Convert a HDITEM into the correct format (ANSI/Unicode) to send it in a notify
650 * [I] infoPtr : the header that wants to send the notify
651 * [O] dest : The buffer to store the HDITEM for notify. It may be set to a HDITEMA of HDITEMW
652 * [I] src : The source HDITEM. It may be a HDITEMA or HDITEMW
653 * [I] fSourceUnicode : is src a HDITEMW or HDITEMA
654 * [O] ppvScratch : a pointer to a scratch buffer that needs to be freed after
655 * the HDITEM is no longer in use or NULL if none was needed
657 * NOTE: We depend on HDITEMA and HDITEMW having the same structure
659 static void HEADER_CopyHDItemForNotify(HEADER_INFO *infoPtr, HDITEMW *dest,
660 HDITEMW *src, BOOL fSourceUnicode, LPVOID *ppvScratch)
665 if (src->mask & HDI_TEXT && src->pszText != LPSTR_TEXTCALLBACKW) /* covers TEXTCALLBACKA as well */
667 if (fSourceUnicode && infoPtr->nNotifyFormat != NFR_UNICODE)
669 dest->pszText = NULL;
670 Str_SetPtrWtoA((LPSTR *)&dest->pszText, src->pszText);
671 *ppvScratch = dest->pszText;
674 if (!fSourceUnicode && infoPtr->nNotifyFormat == NFR_UNICODE)
676 dest->pszText = NULL;
677 Str_SetPtrAtoW(&dest->pszText, (LPSTR)src->pszText);
678 *ppvScratch = dest->pszText;
683 static UINT HEADER_NotifyCodeWtoA(UINT code)
685 /* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
686 if (code >= HDN_LAST && code <= HDN_FIRST_UNICODE)
687 return code + HDN_UNICODE_OFFSET;
693 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
695 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
698 nmhdr.hwndFrom = hwnd;
699 nmhdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
702 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
703 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
707 HEADER_SendHeaderNotifyT (HWND hwnd, UINT code, INT iItem, INT mask, HDITEMW *lpItem)
709 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
715 /* lpItem == NULL means that we should take the actual data from the item */
718 FIXME("(): invalid parameters - lpItem == NULL and (mask & HDI_TEXT)\n");
722 nmitem.cxy = infoPtr->items[iItem].cxy;
723 nmitem.hbm = infoPtr->items[iItem].hbm;
724 nmitem.pszText = NULL;
725 nmitem.cchTextMax = 0;
726 nmitem.fmt = infoPtr->items[iItem].fmt;
727 nmitem.lParam = infoPtr->items[iItem].lParam;
728 nmitem.iOrder = infoPtr->items[iItem].iOrder;
729 nmitem.iImage = infoPtr->items[iItem].iImage;
733 nmhdr.hdr.hwndFrom = hwnd;
734 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
735 nmhdr.hdr.code = (infoPtr->nNotifyFormat == NFR_UNICODE ? code : HEADER_NotifyCodeWtoA(code));
738 nmhdr.pitem = lpItem;
740 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
741 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
745 * Prepare callback items
746 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
747 * (so we handle the two cases only doing a specific cast for pszText).
748 * Checks if any of the required field are callback. If there are sends a
749 * NMHDISPINFO notify to retrieve these items. The items are stored in the
750 * HEADER_ITEM pszText and iImage fields. They should be freed with
751 * HEADER_FreeCallbackItems.
753 * @param hwnd : hwnd header container handler
754 * @param iItem : the header item id
755 * @param reqMask : required fields. If any of them is callback this function will fetch it
757 * @return TRUE on success, else FALSE
760 HEADER_PrepareCallbackItems(HWND hwnd, INT iItem, INT reqMask)
762 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
763 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
764 DWORD mask = reqMask & lpItem->callbackMask;
765 NMHDDISPINFOW dispInfo;
766 void *pvBuffer = NULL;
770 if (mask&HDI_TEXT && lpItem->pszText != NULL)
772 ERR("(): function called without a call to FreeCallbackItems\n");
773 Free(lpItem->pszText);
774 lpItem->pszText = NULL;
777 memset(&dispInfo, 0, sizeof(NMHDDISPINFOW));
778 dispInfo.hdr.hwndFrom = hwnd;
779 dispInfo.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
780 if (infoPtr->nNotifyFormat == NFR_UNICODE)
782 dispInfo.hdr.code = HDN_GETDISPINFOW;
784 pvBuffer = Alloc(MAX_HEADER_TEXT_LEN * sizeof(WCHAR));
788 dispInfo.hdr.code = HDN_GETDISPINFOA;
790 pvBuffer = Alloc(MAX_HEADER_TEXT_LEN * sizeof(CHAR));
792 dispInfo.pszText = (LPWSTR)pvBuffer;
793 dispInfo.cchTextMax = (pvBuffer!=NULL?MAX_HEADER_TEXT_LEN:0);
794 dispInfo.iItem = iItem;
795 dispInfo.mask = mask;
796 dispInfo.lParam = lpItem->lParam;
798 TRACE("Sending HDN_GETDISPINFO%c\n", infoPtr->nNotifyFormat == NFR_UNICODE?'W':'A');
799 SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
800 (WPARAM) dispInfo.hdr.idFrom,
803 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
805 (infoPtr->nNotifyFormat == NFR_UNICODE ? debugstr_w(dispInfo.pszText) : (LPSTR) dispInfo.pszText),
806 (void*) dispInfo.lParam);
808 if (mask & HDI_IMAGE)
809 lpItem->iImage = dispInfo.iImage;
812 if (infoPtr->nNotifyFormat == NFR_UNICODE)
814 lpItem->pszText = (LPWSTR)pvBuffer;
816 /* the user might have used his own buffer */
817 if (dispInfo.pszText != lpItem->pszText)
818 Str_GetPtrW(dispInfo.pszText, lpItem->pszText, MAX_HEADER_TEXT_LEN);
822 Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)dispInfo.pszText);
827 if (dispInfo.mask & HDI_DI_SETITEM)
829 /* make the items permanent */
830 lpItem->callbackMask &= ~dispInfo.mask;
838 * Free the items that might be allocated with HEADER_PrepareCallbackItems
841 * [I] lpItem : the item to free the data
845 HEADER_FreeCallbackItems(HEADER_ITEM *lpItem)
847 if (lpItem->callbackMask&HDI_TEXT && lpItem->pszText != NULL)
849 Free(lpItem->pszText);
850 lpItem->pszText = NULL;
853 if (lpItem->callbackMask&HDI_IMAGE)
854 lpItem->iImage = I_IMAGECALLBACK;
858 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
860 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
863 nmhdr.hdr.hwndFrom = hwnd;
864 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
865 nmhdr.hdr.code = code;
870 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
871 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
876 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
878 FIXME("empty stub!\n");
884 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
886 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
887 INT iItem = (INT)wParam;
889 TRACE("[iItem=%d]\n", iItem);
891 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
894 if (infoPtr->uNumItem == 1) {
895 TRACE("Simple delete!\n");
896 HEADER_DisposeItem(&infoPtr->items[0]);
897 Free (infoPtr->items);
898 Free(infoPtr->order);
901 infoPtr->uNumItem = 0;
904 HEADER_ITEM *oldItems = infoPtr->items;
907 TRACE("Complex delete! [iItem=%d]\n", iItem);
909 for (i = 0; i < infoPtr->uNumItem; i++)
910 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
911 HEADER_DisposeItem(&infoPtr->items[iItem]);
912 iOrder = infoPtr->items[iItem].iOrder;
915 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
916 /* pre delete copy */
918 memcpy (&infoPtr->items[0], &oldItems[0],
919 iItem * sizeof(HEADER_ITEM));
922 /* post delete copy */
923 if (iItem < infoPtr->uNumItem) {
924 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
925 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
928 /* Correct the orders */
929 if (iOrder < infoPtr->uNumItem)
931 memmove(&infoPtr->order[iOrder], &infoPtr->order[iOrder + 1],
932 (infoPtr->uNumItem - iOrder) * sizeof(INT));
933 for (i = 0; i < infoPtr->uNumItem; i++)
935 if (infoPtr->order[i] > iItem)
938 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
942 for (i = 0; i < infoPtr->uNumItem; i++)
943 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
947 HEADER_SetItemBounds (hwnd);
949 InvalidateRect(hwnd, NULL, FALSE);
956 HEADER_GetImageList (HWND hwnd)
958 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
960 return (LRESULT)infoPtr->himl;
965 HEADER_GetItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
967 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
969 UINT mask = phdi->mask;
974 TRACE("[nItem=%d]\n", nItem);
978 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
981 if (mask & HDI_UNKNOWN_FIELDS)
983 TRACE("mask %x contains unknown fields. Using only comctl32 4.0 fields\n", mask);
984 mask &= HDI_COMCTL32_4_0_FIELDS;
987 lpItem = &infoPtr->items[nItem];
988 HEADER_PrepareCallbackItems(hwnd, nItem, mask);
990 if (mask & HDI_BITMAP)
991 phdi->hbm = lpItem->hbm;
993 if (mask & HDI_FORMAT)
994 phdi->fmt = lpItem->fmt;
996 if (mask & HDI_WIDTH)
997 phdi->cxy = lpItem->cxy;
999 if (mask & HDI_LPARAM)
1000 phdi->lParam = lpItem->lParam;
1002 if (mask & HDI_IMAGE)
1003 phdi->iImage = lpItem->iImage;
1005 if (mask & HDI_ORDER)
1006 phdi->iOrder = lpItem->iOrder;
1008 if (mask & HDI_TEXT)
1011 Str_GetPtrW (lpItem->pszText, phdi->pszText, phdi->cchTextMax);
1013 Str_GetPtrWtoA (lpItem->pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
1016 HEADER_FreeCallbackItems(lpItem);
1021 inline static LRESULT
1022 HEADER_GetItemCount (HWND hwnd)
1024 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1025 return infoPtr->uNumItem;
1030 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
1032 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1033 INT iItem = (INT)wParam;
1034 LPRECT lpRect = (LPRECT)lParam;
1036 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
1039 lpRect->left = infoPtr->items[iItem].rect.left;
1040 lpRect->right = infoPtr->items[iItem].rect.right;
1041 lpRect->top = infoPtr->items[iItem].rect.top;
1042 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
1049 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
1051 LPINT order = (LPINT) lParam;
1052 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1054 if ((unsigned int)wParam <infoPtr->uNumItem)
1057 memcpy(order, infoPtr->order, infoPtr->uNumItem * sizeof(INT));
1062 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
1065 LPINT order = (LPINT) lParam;
1066 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1067 HEADER_ITEM *lpItem;
1069 if ((unsigned int)wParam <infoPtr->uNumItem)
1071 memcpy(infoPtr->order, order, infoPtr->uNumItem * sizeof(INT));
1072 for (i=0; i<(int)wParam; i++)
1074 lpItem = &infoPtr->items[*order++];
1077 infoPtr->bRectsValid=0;
1078 InvalidateRect(hwnd, NULL, FALSE);
1082 inline static LRESULT
1083 HEADER_GetUnicodeFormat (HWND hwnd)
1085 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1086 return (infoPtr->nNotifyFormat == NFR_UNICODE);
1091 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
1093 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
1095 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
1097 if (phti->flags == HHT_NOWHERE)
1105 HEADER_InsertItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
1107 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1108 HEADER_ITEM *lpItem;
1113 if ((phdi == NULL) || (nItem < 0) || (phdi->mask == 0))
1116 if (nItem > infoPtr->uNumItem)
1117 nItem = infoPtr->uNumItem;
1119 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
1122 else if (infoPtr->uNumItem < iOrder)
1123 iOrder = infoPtr->uNumItem;
1125 if (infoPtr->uNumItem == 0) {
1126 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
1127 infoPtr->order = Alloc(sizeof(INT));
1128 infoPtr->uNumItem++;
1131 HEADER_ITEM *oldItems = infoPtr->items;
1132 INT *oldOrder = infoPtr->order;
1134 infoPtr->uNumItem++;
1135 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
1137 memcpy (&infoPtr->items[1], &oldItems[0],
1138 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
1142 /* pre insert copy */
1144 memcpy (&infoPtr->items[0], &oldItems[0],
1145 nItem * sizeof(HEADER_ITEM));
1148 /* post insert copy */
1149 if (nItem < infoPtr->uNumItem - 1) {
1150 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
1151 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
1155 infoPtr->order = Alloc(sizeof(INT) * infoPtr->uNumItem);
1156 memcpy(infoPtr->order, oldOrder, iOrder * sizeof(INT));
1157 infoPtr->order[iOrder] = nItem;
1158 memcpy(&infoPtr->order[iOrder + 1], &oldOrder[iOrder],
1159 (infoPtr->uNumItem - iOrder - 1) * sizeof(INT));
1165 for (i = 0; i < infoPtr->uNumItem; i++)
1167 if (i != iOrder && infoPtr->order[i] >= nItem)
1168 infoPtr->order[i]++;
1169 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
1172 lpItem = &infoPtr->items[nItem];
1173 ZeroMemory(lpItem, sizeof(HEADER_ITEM));
1174 /* cxy, fmt and lParam are copied even if not in the HDITEM mask */
1175 copyMask = phdi->mask | HDI_WIDTH | HDI_FORMAT | HDI_LPARAM;
1176 HEADER_StoreHDItemInHeader(lpItem, copyMask, phdi, bUnicode);
1178 /* set automatically some format bits */
1179 if (phdi->mask & HDI_TEXT)
1180 lpItem->fmt |= HDF_STRING;
1182 lpItem->fmt &= ~HDF_STRING;
1184 if (lpItem->hbm != NULL)
1185 lpItem->fmt |= HDF_BITMAP;
1187 lpItem->fmt &= ~HDF_BITMAP;
1189 if (phdi->mask & HDI_IMAGE)
1190 lpItem->fmt |= HDF_IMAGE;
1192 lpItem->iOrder = iOrder;
1194 HEADER_SetItemBounds (hwnd);
1196 InvalidateRect(hwnd, NULL, FALSE);
1203 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
1205 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1206 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1208 lpLayout->pwpos->hwnd = hwnd;
1209 lpLayout->pwpos->hwndInsertAfter = 0;
1210 lpLayout->pwpos->x = lpLayout->prc->left;
1211 lpLayout->pwpos->y = lpLayout->prc->top;
1212 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1213 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_HIDDEN)
1214 lpLayout->pwpos->cy = 0;
1216 lpLayout->pwpos->cy = infoPtr->nHeight;
1217 lpLayout->prc->top += infoPtr->nHeight;
1219 lpLayout->pwpos->flags = SWP_NOZORDER;
1221 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1222 lpLayout->pwpos->x, lpLayout->pwpos->y,
1223 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1225 infoPtr->bRectsValid = FALSE;
1232 HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
1234 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1237 TRACE("(himl %p)\n", himl);
1238 himlOld = infoPtr->himl;
1239 infoPtr->himl = himl;
1241 /* FIXME: Refresh needed??? */
1243 return (LRESULT)himlOld;
1248 HEADER_GetBitmapMargin(HWND hwnd)
1250 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
1252 return infoPtr->iMargin;
1256 HEADER_SetBitmapMargin(HWND hwnd, WPARAM wParam)
1258 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1259 INT oldMargin = infoPtr->iMargin;
1261 infoPtr->iMargin = (INT)wParam;
1267 HEADER_SetItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
1269 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1270 HEADER_ITEM *lpItem;
1276 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1279 TRACE("[nItem=%d]\n", nItem);
1281 HEADER_CopyHDItemForNotify(infoPtr, &hdNotify, phdi, bUnicode, &pvScratch);
1282 if (HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask, &hdNotify))
1284 if (pvScratch) Free(pvScratch);
1288 lpItem = &infoPtr->items[nItem];
1289 HEADER_StoreHDItemInHeader(lpItem, phdi->mask, phdi, bUnicode);
1291 if (phdi->mask & HDI_ORDER)
1295 if (lpItem->iOrder < phdi->iOrder)
1297 memmove(&infoPtr->order[lpItem->iOrder],
1298 &infoPtr->order[lpItem->iOrder + 1],
1299 (phdi->iOrder - lpItem->iOrder) * sizeof(INT));
1301 if (phdi->iOrder < lpItem->iOrder)
1303 memmove(&infoPtr->order[phdi->iOrder + 1],
1304 &infoPtr->order[phdi->iOrder],
1305 (lpItem->iOrder - phdi->iOrder) * sizeof(INT));
1307 infoPtr->order[phdi->iOrder] = nItem;
1308 nMin = min(lpItem->iOrder, phdi->iOrder);
1309 nMax = max(lpItem->iOrder, phdi->iOrder);
1310 for (i = nMin; i <= nMax; i++)
1312 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
1316 HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMCHANGEDW, nItem, phdi->mask, &hdNotify);
1318 HEADER_SetItemBounds (hwnd);
1320 InvalidateRect(hwnd, NULL, FALSE);
1322 if (pvScratch != NULL)
1327 inline static LRESULT
1328 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1330 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1331 BOOL bTemp = (infoPtr->nNotifyFormat == NFR_UNICODE);
1333 infoPtr->nNotifyFormat = ((BOOL)wParam ? NFR_UNICODE : NFR_ANSI);
1340 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1342 HEADER_INFO *infoPtr;
1347 infoPtr = (HEADER_INFO *)Alloc (sizeof(HEADER_INFO));
1348 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1350 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
1351 infoPtr->uNumItem = 0;
1355 infoPtr->bRectsValid = FALSE;
1356 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1357 infoPtr->hcurDivider = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDER));
1358 infoPtr->hcurDivopen = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDEROPEN));
1359 infoPtr->bPressed = FALSE;
1360 infoPtr->bTracking = FALSE;
1361 infoPtr->iMoveItem = 0;
1363 infoPtr->iHotItem = -1;
1364 infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
1365 infoPtr->nNotifyFormat =
1366 SendMessageW (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1369 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1370 GetTextMetricsW (hdc, &tm);
1371 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1372 SelectObject (hdc, hOldFont);
1375 OpenThemeData(hwnd, themeClass);
1382 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1384 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1385 HEADER_ITEM *lpItem;
1389 if (infoPtr->items) {
1390 lpItem = infoPtr->items;
1391 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1392 HEADER_DisposeItem(lpItem);
1394 Free (infoPtr->items);
1398 Free(infoPtr->order);
1401 ImageList_Destroy (infoPtr->himl);
1403 SetWindowLongPtrW (hwnd, 0, 0);
1406 theme = GetWindowTheme(hwnd);
1407 CloseThemeData(theme);
1412 static inline LRESULT
1413 HEADER_GetFont (HWND hwnd)
1415 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1417 return (LRESULT)infoPtr->hFont;
1422 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1428 pt.x = (INT)LOWORD(lParam);
1429 pt.y = (INT)HIWORD(lParam);
1430 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1432 if ((GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1433 HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMDBLCLICKW, nItem, 0, NULL);
1434 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1435 HEADER_SendHeaderNotifyT (hwnd, HDN_DIVIDERDBLCLICKW, nItem, 0, NULL);
1442 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1444 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1445 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1451 pt.x = (INT)LOWORD(lParam);
1452 pt.y = (INT)HIWORD(lParam);
1453 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1455 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1457 infoPtr->bCaptured = TRUE;
1458 infoPtr->bPressed = TRUE;
1459 infoPtr->iMoveItem = nItem;
1461 infoPtr->items[nItem].bDown = TRUE;
1463 /* Send WM_CUSTOMDRAW */
1465 HEADER_RefreshItem (hwnd, hdc, nItem);
1466 ReleaseDC (hwnd, hdc);
1468 TRACE("Pressed item %d!\n", nItem);
1470 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1471 if (!(HEADER_SendHeaderNotifyT (hwnd, HDN_BEGINTRACKW, nItem, HDI_WIDTH, NULL))) {
1473 infoPtr->bCaptured = TRUE;
1474 infoPtr->bTracking = TRUE;
1475 infoPtr->iMoveItem = nItem;
1476 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1477 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1479 if (!(dwStyle & HDS_FULLDRAG)) {
1480 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1482 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1483 ReleaseDC (hwnd, hdc);
1486 TRACE("Begin tracking item %d!\n", nItem);
1495 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1497 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1498 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1504 pt.x = (INT)(SHORT)LOWORD(lParam);
1505 pt.y = (INT)(SHORT)HIWORD(lParam);
1506 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1508 if (infoPtr->bPressed) {
1509 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1510 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1512 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1513 ReleaseDC (hwnd, hdc);
1515 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1517 else if (flags == HHT_ONHEADER)
1519 HEADER_ITEM *lpItem;
1520 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1521 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1523 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1524 infoPtr->iMoveItem,oldindex,nItem,newindex);
1525 lpItem= &infoPtr->items[nItem];
1526 lpItem->iOrder=oldindex;
1528 lpItem= &infoPtr->items[infoPtr->iMoveItem];
1529 lpItem->iOrder = newindex;
1531 infoPtr->order[oldindex] = nItem;
1532 infoPtr->order[newindex] = infoPtr->iMoveItem;
1534 infoPtr->bRectsValid = FALSE;
1535 InvalidateRect(hwnd, NULL, FALSE);
1536 /* FIXME: Should some WM_NOTIFY be sent */
1539 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1540 infoPtr->bPressed = FALSE;
1542 else if (infoPtr->bTracking) {
1543 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1544 infoPtr->bTracking = FALSE;
1546 HEADER_SendHeaderNotifyT (hwnd, HDN_ENDTRACKW, infoPtr->iMoveItem, HDI_WIDTH, NULL);
1548 if (!(dwStyle & HDS_FULLDRAG)) {
1550 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1551 ReleaseDC (hwnd, hdc);
1554 if (HEADER_SendHeaderNotifyT(hwnd, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH, NULL))
1556 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1559 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1562 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1565 HEADER_SetItemBounds (hwnd);
1566 InvalidateRect(hwnd, NULL, TRUE);
1567 HEADER_SendHeaderNotifyT(hwnd, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH, NULL);
1570 if (infoPtr->bCaptured) {
1571 infoPtr->bCaptured = FALSE;
1573 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1581 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1583 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1588 return infoPtr->nNotifyFormat;
1591 infoPtr->nNotifyFormat =
1592 SendMessageW ((HWND)wParam, WM_NOTIFYFORMAT,
1593 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1594 return infoPtr->nNotifyFormat;
1602 HEADER_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
1604 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1605 /* Reset hot-tracked item when mouse leaves control. */
1606 INT oldHotItem = infoPtr->iHotItem;
1607 HDC hdc = GetDC (hwnd);
1609 infoPtr->iHotItem = -1;
1610 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem);
1611 ReleaseDC (hwnd, hdc);
1618 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1620 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1621 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1626 /* With theming, hottracking is always enabled */
1627 BOOL hotTrackEnabled =
1628 ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK))
1629 || (GetWindowTheme (hwnd) != NULL);
1630 INT oldHotItem = infoPtr->iHotItem;
1632 pt.x = (INT)(SHORT)LOWORD(lParam);
1633 pt.y = (INT)(SHORT)HIWORD(lParam);
1634 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1636 if (hotTrackEnabled) {
1637 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1638 infoPtr->iHotItem = nItem;
1640 infoPtr->iHotItem = -1;
1643 if (infoPtr->bCaptured) {
1644 if (infoPtr->bPressed) {
1645 BOOL oldState = infoPtr->items[infoPtr->iMoveItem].bDown;
1646 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1647 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1649 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1650 if (oldState != infoPtr->items[infoPtr->iMoveItem].bDown) {
1652 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1653 ReleaseDC (hwnd, hdc);
1656 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1658 else if (infoPtr->bTracking) {
1659 if (dwStyle & HDS_FULLDRAG) {
1660 if (!HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH, NULL))
1662 HEADER_ITEM *lpItem = &infoPtr->items[infoPtr->iMoveItem];
1663 INT nOldWidth = lpItem->rect.right - lpItem->rect.left;
1667 nWidth = pt.x - lpItem->rect.left + infoPtr->xTrackOffset;
1668 if (nWidth < 0) nWidth = 0;
1669 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1670 HEADER_SetItemBounds(hwnd);
1672 GetClientRect(hwnd, &rcClient);
1673 rcScroll = rcClient;
1674 rcScroll.left = lpItem->rect.left + nOldWidth;
1675 ScrollWindowEx(hwnd, nWidth - nOldWidth, 0, &rcScroll, &rcClient, NULL, NULL, 0);
1676 InvalidateRect(hwnd, &lpItem->rect, FALSE);
1679 HEADER_SendHeaderNotifyT(hwnd, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH, NULL);
1684 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1685 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1686 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1687 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1688 infoPtr->items[infoPtr->iMoveItem].cxy =
1689 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1690 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1691 ReleaseDC (hwnd, hdc);
1692 HEADER_SendHeaderNotifyT (hwnd, HDN_TRACKW, infoPtr->iMoveItem, HDI_WIDTH, NULL);
1695 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1699 if (hotTrackEnabled) {
1700 TRACKMOUSEEVENT tme;
1701 if (oldHotItem != infoPtr->iHotItem) {
1703 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem);
1704 if (infoPtr->iHotItem != -1) HEADER_RefreshItem (hwnd, hdc, infoPtr->iHotItem);
1705 ReleaseDC (hwnd, hdc);
1707 tme.cbSize = sizeof( tme );
1708 tme.dwFlags = TME_LEAVE;
1709 tme.hwndTrack = hwnd;
1710 TrackMouseEvent( &tme );
1718 HEADER_Paint (HWND hwnd, WPARAM wParam)
1723 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1724 HEADER_Refresh (hwnd, hdc);
1726 EndPaint (hwnd, &ps);
1732 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1737 pt.x = LOWORD(lParam);
1738 pt.y = HIWORD(lParam);
1740 /* Send a Notify message */
1741 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1743 /* Change to screen coordinate for WM_CONTEXTMENU */
1744 ClientToScreen(hwnd, &pt);
1746 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1747 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1754 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1756 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1761 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1764 ScreenToClient (hwnd, &pt);
1766 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1768 if (flags == HHT_ONDIVIDER)
1769 SetCursor (infoPtr->hcurDivider);
1770 else if (flags == HHT_ONDIVOPEN)
1771 SetCursor (infoPtr->hcurDivopen);
1773 SetCursor (infoPtr->hcurArrow);
1780 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1782 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1784 HFONT hFont, hOldFont;
1787 infoPtr->hFont = (HFONT)wParam;
1789 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1792 hOldFont = SelectObject (hdc, hFont);
1793 GetTextMetricsW (hdc, &tm);
1794 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1795 SelectObject (hdc, hOldFont);
1798 infoPtr->bRectsValid = FALSE;
1801 InvalidateRect(hwnd, NULL, FALSE);
1807 /* Update the theme handle after a theme change */
1808 static LRESULT HEADER_ThemeChanged(HWND hwnd)
1810 HTHEME theme = GetWindowTheme(hwnd);
1811 CloseThemeData(theme);
1812 OpenThemeData(hwnd, themeClass);
1813 InvalidateRect(hwnd, NULL, FALSE);
1818 static LRESULT WINAPI
1819 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1821 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1822 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1823 return DefWindowProcW (hwnd, msg, wParam, lParam);
1825 /* case HDM_CLEARFILTER: */
1827 case HDM_CREATEDRAGIMAGE:
1828 return HEADER_CreateDragImage (hwnd, wParam);
1830 case HDM_DELETEITEM:
1831 return HEADER_DeleteItem (hwnd, wParam);
1833 /* case HDM_EDITFILTER: */
1835 case HDM_GETBITMAPMARGIN:
1836 return HEADER_GetBitmapMargin(hwnd);
1838 case HDM_GETIMAGELIST:
1839 return HEADER_GetImageList (hwnd);
1843 return HEADER_GetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_GETITEMW);
1845 case HDM_GETITEMCOUNT:
1846 return HEADER_GetItemCount (hwnd);
1848 case HDM_GETITEMRECT:
1849 return HEADER_GetItemRect (hwnd, wParam, lParam);
1851 case HDM_GETORDERARRAY:
1852 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1854 case HDM_GETUNICODEFORMAT:
1855 return HEADER_GetUnicodeFormat (hwnd);
1858 return HEADER_HitTest (hwnd, wParam, lParam);
1860 case HDM_INSERTITEMA:
1861 case HDM_INSERTITEMW:
1862 return HEADER_InsertItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_INSERTITEMW);
1865 return HEADER_Layout (hwnd, wParam, lParam);
1867 case HDM_ORDERTOINDEX:
1868 return HEADER_OrderToIndex(hwnd, wParam);
1870 case HDM_SETBITMAPMARGIN:
1871 return HEADER_SetBitmapMargin(hwnd, wParam);
1873 /* case HDM_SETFILTERCHANGETIMEOUT: */
1875 /* case HDM_SETHOTDIVIDER: */
1877 case HDM_SETIMAGELIST:
1878 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
1882 return HEADER_SetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_SETITEMW);
1884 case HDM_SETORDERARRAY:
1885 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1887 case HDM_SETUNICODEFORMAT:
1888 return HEADER_SetUnicodeFormat (hwnd, wParam);
1891 return HEADER_Create (hwnd, wParam, lParam);
1894 return HEADER_Destroy (hwnd, wParam, lParam);
1900 return DLGC_WANTTAB | DLGC_WANTARROWS;
1903 return HEADER_GetFont (hwnd);
1905 case WM_LBUTTONDBLCLK:
1906 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1908 case WM_LBUTTONDOWN:
1909 return HEADER_LButtonDown (hwnd, wParam, lParam);
1912 return HEADER_LButtonUp (hwnd, wParam, lParam);
1915 return HEADER_MouseLeave (hwnd, wParam, lParam);
1918 return HEADER_MouseMove (hwnd, wParam, lParam);
1920 case WM_NOTIFYFORMAT:
1921 return HEADER_NotifyFormat (hwnd, wParam, lParam);
1924 return HEADER_Size (hwnd, wParam);
1926 case WM_THEMECHANGED:
1927 return HEADER_ThemeChanged (hwnd);
1929 case WM_PRINTCLIENT:
1931 return HEADER_Paint (hwnd, wParam);
1934 return HEADER_RButtonUp (hwnd, wParam, lParam);
1937 return HEADER_SetCursor (hwnd, wParam, lParam);
1940 return HEADER_SetFont (hwnd, wParam, lParam);
1943 if ((msg >= WM_USER) && (msg < WM_APP))
1944 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1945 msg, wParam, lParam );
1946 return DefWindowProcA (hwnd, msg, wParam, lParam);
1952 HEADER_Register (void)
1956 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1957 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1958 wndClass.lpfnWndProc = HEADER_WindowProc;
1959 wndClass.cbClsExtra = 0;
1960 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1961 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1962 wndClass.lpszClassName = WC_HEADERW;
1964 RegisterClassW (&wndClass);
1969 HEADER_Unregister (void)
1971 UnregisterClassW (WC_HEADERW, NULL);