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 BOOL bUnicode; /* Unicode flag */
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 HDN_UNICODE_OFFSET 20
98 #define HDN_FIRST_UNICODE (HDN_FIRST-HDN_UNICODE_OFFSET)
100 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongPtrW(hwnd,0))
102 static const WCHAR themeClass[] = {'H','e','a','d','e','r',0};
105 inline static LRESULT
106 HEADER_IndexToOrder (HWND hwnd, INT iItem)
108 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
109 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
110 return lpItem->iOrder;
115 HEADER_OrderToIndex(HWND hwnd, WPARAM wParam)
117 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
118 INT iorder = (INT)wParam;
120 if ((iorder <0) || iorder >= infoPtr->uNumItem)
122 return infoPtr->order[iorder];
126 HEADER_SetItemBounds (HWND hwnd)
128 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
134 infoPtr->bRectsValid = TRUE;
136 if (infoPtr->uNumItem == 0)
139 GetClientRect (hwnd, &rect);
142 for (i = 0; i < infoPtr->uNumItem; i++) {
143 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
144 phdi->rect.top = rect.top;
145 phdi->rect.bottom = rect.bottom;
147 phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
148 x = phdi->rect.right;
153 HEADER_Size (HWND hwnd, WPARAM wParam)
155 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
157 infoPtr->bRectsValid = FALSE;
164 HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
166 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
167 HEADER_ITEM *phdi = &infoPtr->items[iItem];
169 INT oldBkMode, cxEdge = GetSystemMetrics(SM_CXEDGE);
170 HTHEME theme = GetWindowTheme (hwnd);
173 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, infoPtr->bUnicode);
175 if (!infoPtr->bRectsValid)
176 HEADER_SetItemBounds(hwnd);
179 if (r.right - r.left == 0)
180 return phdi->rect.right;
183 int state = (phdi->bDown) ? HIS_PRESSED :
184 (bHotTrack ? HIS_HOT : HIS_NORMAL);
185 DrawThemeBackground (theme, hdc, HP_HEADERITEM, state,
187 GetThemeBackgroundContentRect (theme, hdc, HP_HEADERITEM, state,
191 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) {
193 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
194 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
197 DrawEdge (hdc, &r, EDGE_RAISED,
198 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
201 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
211 /* Set the colors before sending NM_CUSTOMDRAW so that it can change them */
212 SetTextColor (hdc, (bHotTrack && !theme) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
213 SetBkColor(hdc, GetSysColor(COLOR_3DFACE));
215 nmcd.hdr.hwndFrom = hwnd;
216 nmcd.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
217 nmcd.hdr.code = NM_CUSTOMDRAW;
218 nmcd.dwDrawStage = CDDS_PREPAINT | CDDS_ITEM | CDDS_ITEMPOSTERASE;
220 nmcd.dwItemSpec = iItem;
222 nmcd.uItemState = phdi->bDown ? CDIS_SELECTED : 0;
223 nmcd.lItemlParam = phdi->lParam;
225 SendMessageW (infoPtr->hwndNotify, WM_NOTIFY, nmcd.hdr.idFrom, (LPARAM)&nmcd);
227 if (phdi->fmt & HDF_OWNERDRAW) {
230 dis.CtlType = ODT_HEADER;
231 dis.CtlID = GetWindowLongPtrW (hwnd, GWLP_ID);
233 dis.itemAction = ODA_DRAWENTIRE;
234 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
238 dis.itemData = phdi->lParam;
239 oldBkMode = SetBkMode(hdc, TRANSPARENT);
240 SendMessageW (infoPtr->hwndNotify, WM_DRAWITEM,
241 (WPARAM)dis.CtlID, (LPARAM)&dis);
242 if (oldBkMode != TRANSPARENT)
243 SetBkMode(hdc, oldBkMode);
246 UINT rw, rh, /* width and height of r */
247 *x = NULL, *w = NULL; /* x and width of the pic (bmp or img) which is part of cnt */
248 /* cnt,txt,img,bmp */
253 cw = tw = iw = bw = 0;
254 rw = r.right - r.left;
255 rh = r.bottom - r.top;
258 HBRUSH hbr = CreateSolidBrush(GetBkColor(hdc));
259 RECT rcBackground = r;
261 rcBackground.right -= cxEdge;
262 FillRect(hdc, &rcBackground, hbr);
265 if (phdi->fmt & HDF_STRING) {
268 DrawTextW (hdc, phdi->pszText, -1,
269 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
270 cw = textRect.right - textRect.left + 2 * infoPtr->iMargin;
273 if ((phdi->fmt & HDF_IMAGE) && (infoPtr->himl)) {
274 iw = infoPtr->himl->cx + 2 * infoPtr->iMargin;
279 if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
280 GetObjectW (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
281 bw = bmp.bmWidth + 2 * infoPtr->iMargin;
291 /* align cx using the unclipped cw */
292 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_LEFT)
294 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
295 cx = r.left + rw / 2 - cw / 2;
302 if (cx + cw > r.right)
305 tx = cx + infoPtr->iMargin;
306 /* since cw might have changed we have to recalculate tw */
307 tw = cw - infoPtr->iMargin * 2;
311 if (phdi->fmt & HDF_BITMAP_ON_RIGHT) {
312 /* put pic behind text */
313 *x = cx + tw + infoPtr->iMargin * 3;
315 *x = cx + infoPtr->iMargin;
316 /* move text behind pic */
322 /* since we're done with the layout we can
323 now calculate the position of bmp which
324 has no influence on alignment and layout
326 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
327 bx = cx - bw + infoPtr->iMargin;
329 bx = cx + cw + infoPtr->iMargin;
333 HDC hClipDC = GetDC(hwnd);
334 HRGN hClipRgn = CreateRectRgn(r.left, r.top, r.right, r.bottom);
335 SelectClipRgn(hClipDC, hClipRgn);
338 HDC hdcBitmap = CreateCompatibleDC (hClipDC);
339 SelectObject (hdcBitmap, phdi->hbm);
340 BitBlt (hClipDC, bx, r.top + ((INT)rh - bmp.bmHeight) / 2,
341 bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
342 DeleteDC (hdcBitmap);
346 ImageList_DrawEx (infoPtr->himl, phdi->iImage, hClipDC,
347 ix, r.top + ((INT)rh - infoPtr->himl->cy) / 2,
348 infoPtr->himl->cx, infoPtr->himl->cy, CLR_DEFAULT, CLR_DEFAULT, 0);
351 DeleteObject(hClipRgn);
352 ReleaseDC(hwnd, hClipDC);
355 if (((phdi->fmt & HDF_STRING)
356 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
357 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
358 && (phdi->pszText)) {
359 oldBkMode = SetBkMode(hdc, TRANSPARENT);
362 DrawTextW (hdc, phdi->pszText, -1,
363 &r, DT_LEFT|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
364 if (oldBkMode != TRANSPARENT)
365 SetBkMode(hdc, oldBkMode);
369 return phdi->rect.right;
374 HEADER_Refresh (HWND hwnd, HDC hdc)
376 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
377 HFONT hFont, hOldFont;
382 HTHEME theme = GetWindowTheme (hwnd);
384 /* get rect for the bar, adjusted for the border */
385 GetClientRect (hwnd, &rect);
387 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
388 hOldFont = SelectObject (hdc, hFont);
390 /* draw Background */
392 hbrBk = GetSysColorBrush(COLOR_3DFACE);
393 FillRect(hdc, &rect, hbrBk);
397 for (i = 0; x <= rect.right && i < infoPtr->uNumItem; i++) {
398 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i),
399 infoPtr->iHotItem == i);
402 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
405 DrawThemeBackground (theme, hdc, HP_HEADERITEM, HIS_NORMAL, &rect,
409 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS)
410 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
412 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
416 SelectObject (hdc, hOldFont);
421 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
423 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
424 HFONT hFont, hOldFont;
426 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
427 hOldFont = SelectObject (hdc, hFont);
428 HEADER_DrawItem (hwnd, hdc, iItem, infoPtr->iHotItem == iItem);
429 SelectObject (hdc, hOldFont);
434 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
436 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
442 GetClientRect (hwnd, &rect);
446 if (PtInRect (&rect, *lpPt))
448 if (infoPtr->uNumItem == 0) {
449 *pFlags |= HHT_NOWHERE;
455 /* somewhere inside */
456 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
457 rect = infoPtr->items[iCount].rect;
458 width = rect.right - rect.left;
463 if (PtInRect (&rect, *lpPt)) {
464 if (width <= 2 * DIVIDER_WIDTH) {
465 *pFlags |= HHT_ONHEADER;
467 TRACE("ON HEADER %d\n", iCount);
472 rcTest.right = rcTest.left + DIVIDER_WIDTH;
473 if (PtInRect (&rcTest, *lpPt)) {
475 *pFlags |= HHT_ONDIVOPEN;
477 TRACE("ON DIVOPEN %d\n", *pItem);
481 *pFlags |= HHT_ONDIVIDER;
483 TRACE("ON DIVIDER %d\n", *pItem);
489 rcTest.left = rcTest.right - DIVIDER_WIDTH;
490 if (PtInRect (&rcTest, *lpPt)) {
491 *pFlags |= HHT_ONDIVIDER;
493 TRACE("ON DIVIDER %d\n", *pItem);
497 *pFlags |= HHT_ONHEADER;
499 TRACE("ON HEADER %d\n", iCount);
504 /* check for last divider part (on nowhere) */
505 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
506 rect.left = rect.right;
507 rect.right += DIVIDER_WIDTH;
508 if (PtInRect (&rect, *lpPt)) {
510 *pFlags |= HHT_ONDIVOPEN;
511 *pItem = infoPtr->uNumItem - 1;
512 TRACE("ON DIVOPEN %d\n", *pItem);
516 *pFlags |= HHT_ONDIVIDER;
517 *pItem = infoPtr->uNumItem-1;
518 TRACE("ON DIVIDER %d\n", *pItem);
523 *pFlags |= HHT_NOWHERE;
530 if (lpPt->x < rect.left) {
532 *pFlags |= HHT_TOLEFT;
534 else if (lpPt->x > rect.right) {
536 *pFlags |= HHT_TORIGHT;
539 if (lpPt->y < rect.top) {
541 *pFlags |= HHT_ABOVE;
543 else if (lpPt->y > rect.bottom) {
545 *pFlags |= HHT_BELOW;
550 TRACE("flags=0x%X\n", *pFlags);
556 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
562 GetClientRect (hwnd, &rect);
564 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
565 oldRop = SetROP2 (hdc, R2_XORPEN);
566 MoveToEx (hdc, x, rect.top, NULL);
567 LineTo (hdc, x, rect.bottom);
568 SetROP2 (hdc, oldRop);
569 SelectObject (hdc, hOldPen);
572 static UINT HEADER_NotifyCodeWtoA(UINT code)
574 /* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
575 if (code >= HDN_LAST && code <= HDN_FIRST_UNICODE)
576 return code + HDN_UNICODE_OFFSET;
582 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
584 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
587 nmhdr.hwndFrom = hwnd;
588 nmhdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
591 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
592 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
596 HEADER_SendHeaderNotifyT (HWND hwnd, UINT code, INT iItem, INT mask)
598 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
602 nmhdr.hdr.hwndFrom = hwnd;
603 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
604 nmhdr.hdr.code = (infoPtr->nNotifyFormat == NFR_UNICODE ? code : HEADER_NotifyCodeWtoA(code));
607 nmhdr.pitem = &nmitem;
609 nmitem.cxy = infoPtr->items[iItem].cxy;
610 nmitem.hbm = infoPtr->items[iItem].hbm;
611 nmitem.pszText = NULL;
612 nmitem.cchTextMax = 0;
613 /* nmitem.pszText = infoPtr->items[iItem].pszText; */
614 /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
615 nmitem.fmt = infoPtr->items[iItem].fmt;
616 nmitem.lParam = infoPtr->items[iItem].lParam;
617 nmitem.iOrder = infoPtr->items[iItem].iOrder;
618 nmitem.iImage = infoPtr->items[iItem].iImage;
620 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
621 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
625 * Send Disp Info notification.
626 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
627 * (so we handle the two cases only doing a specific cast for pszText).
629 * @param hwnd : hwnd header container handler
630 * @param mask : notification mask (usually HDI_TEXT or HDI_IMAGE)
631 * @param pDispInfo : NMHDDISPINFO structure (can be unicode or ansi)
632 * @param isW : TRUE if dispinfo is Unicode
635 HEADER_SendHeaderDispInfoNotify(HWND hwnd, INT iItem, INT mask, LPHDITEMW phdi, HEADER_ITEM* lpItem, BOOL isW)
637 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
639 BOOL convertToAnsi = FALSE;
640 BOOL convertToUnicode = FALSE;
641 BOOL isUnicodeNotify = FALSE;
642 NMHDDISPINFOW dispInfo;
646 convertToAnsi = (isW && infoPtr->nNotifyFormat == NFR_ANSI);
647 convertToUnicode = (!isW && infoPtr->nNotifyFormat == NFR_UNICODE);
649 isUnicodeNotify = (isW && !convertToAnsi);
651 memset(&dispInfo, 0, sizeof(NMHDDISPINFOW));
652 dispInfo.hdr.hwndFrom = hwnd;
653 dispInfo.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
654 if (isUnicodeNotify || convertToUnicode)
656 dispInfo.hdr.code = HDN_GETDISPINFOW;
660 dispInfo.hdr.code = HDN_GETDISPINFOA;
662 dispInfo.iItem = iItem;
663 dispInfo.mask = mask;
665 dispInfo.pszText = Alloc(sizeof(WCHAR) * 260);
666 dispInfo.cchTextMax = 260;
668 ret = (BOOL) SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
669 (WPARAM) dispInfo.hdr.idFrom,
672 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
674 (isUnicodeNotify ? debugstr_w(dispInfo.pszText) : (LPSTR) dispInfo.pszText),
675 (void*) dispInfo.lParam);
677 if (dispInfo.mask & HDI_DI_SETITEM)
679 if (dispInfo.mask & HDI_IMAGE)
681 lpItem->iImage = dispInfo.iImage;
683 if (dispInfo.mask & HDI_TEXT)
685 if (isUnicodeNotify || convertToUnicode)
686 Str_SetPtrW(&lpItem->pszText, (LPCWSTR)dispInfo.pszText);
687 else /*if (convertToAnsi || !isW)*/
688 Str_SetPtrAtoW(&lpItem->pszText, (LPCSTR)dispInfo.pszText);
691 FIXME("NMHDDISPINFO returns with flags HDI_DI_SETITEM\n");
696 if ((phdi->mask & mask) & HDI_IMAGE)
698 phdi->iImage = dispInfo.iImage;
700 if ((phdi->mask & mask) & HDI_TEXT)
703 Str_GetPtrW ((LPCWSTR)dispInfo.pszText, phdi->pszText, phdi->cchTextMax);
704 else if (convertToUnicode)
705 Str_GetPtrWtoA ((LPCWSTR)dispInfo.pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
707 Str_GetPtrA ((LPCSTR)dispInfo.pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
715 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
717 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
720 nmhdr.hdr.hwndFrom = hwnd;
721 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
722 nmhdr.hdr.code = code;
727 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
728 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
733 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
735 FIXME("empty stub!\n");
741 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
743 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
744 INT iItem = (INT)wParam;
746 TRACE("[iItem=%d]\n", iItem);
748 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
751 if (infoPtr->uNumItem == 1) {
752 TRACE("Simple delete!\n");
753 if (infoPtr->items[0].pszText)
754 Free (infoPtr->items[0].pszText);
755 Free (infoPtr->items);
756 Free(infoPtr->order);
759 infoPtr->uNumItem = 0;
762 HEADER_ITEM *oldItems = infoPtr->items;
765 TRACE("Complex delete! [iItem=%d]\n", iItem);
767 for (i = 0; i < infoPtr->uNumItem; i++)
768 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
769 if (infoPtr->items[iItem].pszText)
770 Free (infoPtr->items[iItem].pszText);
771 iOrder = infoPtr->items[iItem].iOrder;
774 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
775 /* pre delete copy */
777 memcpy (&infoPtr->items[0], &oldItems[0],
778 iItem * sizeof(HEADER_ITEM));
781 /* post delete copy */
782 if (iItem < infoPtr->uNumItem) {
783 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
784 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
787 /* Correct the orders */
788 if (iOrder < infoPtr->uNumItem)
790 memmove(&infoPtr->order[iOrder], &infoPtr->order[iOrder + 1],
791 (infoPtr->uNumItem - iOrder) * sizeof(INT));
792 for (i = 0; i < infoPtr->uNumItem; i++)
794 if (infoPtr->order[i] > iItem)
797 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
801 for (i = 0; i < infoPtr->uNumItem; i++)
802 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
806 HEADER_SetItemBounds (hwnd);
808 InvalidateRect(hwnd, NULL, FALSE);
815 HEADER_GetImageList (HWND hwnd)
817 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
819 return (LRESULT)infoPtr->himl;
824 HEADER_GetItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
826 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
832 TRACE("[nItem=%d]\n", nItem);
836 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
839 lpItem = &infoPtr->items[nItem];
841 if (phdi->mask & HDI_BITMAP)
842 phdi->hbm = (lpItem != NULL) ? lpItem->hbm : 0;
844 if (phdi->mask & HDI_FORMAT)
845 phdi->fmt = (lpItem != NULL) ? lpItem->fmt : 0;
847 if (phdi->mask & HDI_WIDTH)
848 phdi->cxy = (lpItem != NULL) ? lpItem->cxy : 0;
850 if (phdi->mask & HDI_LPARAM)
851 phdi->lParam = (lpItem != NULL) ? lpItem->lParam : 0;
853 if (phdi->mask & HDI_IMAGE)
855 phdi->iImage = (lpItem != NULL) ? lpItem->iImage : 0;
856 if (lpItem->iImage == I_IMAGECALLBACK)
858 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, phdi, lpItem, bUnicode);
862 if (phdi->mask & HDI_ORDER)
863 phdi->iOrder = (lpItem != NULL) ? lpItem->iOrder : 0;
865 if (phdi->mask & HDI_TEXT)
867 if (lpItem == NULL) *phdi->pszText = 0; /* null pointer check */
868 else if (lpItem->pszText == LPSTR_TEXTCALLBACKW) /* covers == TEXTCALLBACKA too */
870 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, phdi, lpItem, bUnicode);
875 Str_GetPtrW (lpItem->pszText, phdi->pszText, phdi->cchTextMax);
877 Str_GetPtrWtoA (lpItem->pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
885 inline static LRESULT
886 HEADER_GetItemCount (HWND hwnd)
888 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
889 return infoPtr->uNumItem;
894 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
896 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
897 INT iItem = (INT)wParam;
898 LPRECT lpRect = (LPRECT)lParam;
900 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
903 lpRect->left = infoPtr->items[iItem].rect.left;
904 lpRect->right = infoPtr->items[iItem].rect.right;
905 lpRect->top = infoPtr->items[iItem].rect.top;
906 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
913 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
915 LPINT order = (LPINT) lParam;
916 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
918 if ((unsigned int)wParam <infoPtr->uNumItem)
921 memcpy(order, infoPtr->order, infoPtr->uNumItem * sizeof(INT));
926 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
929 LPINT order = (LPINT) lParam;
930 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
933 if ((unsigned int)wParam <infoPtr->uNumItem)
935 memcpy(infoPtr->order, order, infoPtr->uNumItem * sizeof(INT));
936 for (i=0; i<(int)wParam; i++)
938 lpItem = &infoPtr->items[*order++];
941 infoPtr->bRectsValid=0;
942 InvalidateRect(hwnd, NULL, FALSE);
946 inline static LRESULT
947 HEADER_GetUnicodeFormat (HWND hwnd)
949 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
950 return infoPtr->bUnicode;
955 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
957 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
959 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
961 if (phti->flags == HHT_NOWHERE)
969 HEADER_InsertItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
971 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
976 if ((phdi == NULL) || (nItem < 0))
979 if (nItem > infoPtr->uNumItem)
980 nItem = infoPtr->uNumItem;
982 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
985 else if (infoPtr->uNumItem < iOrder)
986 iOrder = infoPtr->uNumItem;
988 if (infoPtr->uNumItem == 0) {
989 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
990 infoPtr->order = Alloc(sizeof(INT));
994 HEADER_ITEM *oldItems = infoPtr->items;
995 INT *oldOrder = infoPtr->order;
998 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
1000 memcpy (&infoPtr->items[1], &oldItems[0],
1001 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
1005 /* pre insert copy */
1007 memcpy (&infoPtr->items[0], &oldItems[0],
1008 nItem * sizeof(HEADER_ITEM));
1011 /* post insert copy */
1012 if (nItem < infoPtr->uNumItem - 1) {
1013 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
1014 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
1018 infoPtr->order = Alloc(sizeof(INT) * infoPtr->uNumItem);
1019 memcpy(infoPtr->order, oldOrder, iOrder * sizeof(INT));
1020 infoPtr->order[iOrder] = nItem;
1021 memcpy(&infoPtr->order[iOrder + 1], &oldOrder[iOrder],
1022 (infoPtr->uNumItem - iOrder - 1) * sizeof(INT));
1028 for (i = 0; i < infoPtr->uNumItem; i++)
1030 if (i != iOrder && infoPtr->order[i] >= nItem)
1031 infoPtr->order[i]++;
1032 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
1035 lpItem = &infoPtr->items[nItem];
1036 lpItem->bDown = FALSE;
1038 if (phdi->mask & HDI_WIDTH)
1039 lpItem->cxy = phdi->cxy;
1041 if (phdi->mask & HDI_FORMAT)
1042 lpItem->fmt = phdi->fmt;
1044 if (lpItem->fmt == 0)
1045 lpItem->fmt = HDF_LEFT;
1047 if (phdi->mask & HDI_BITMAP)
1048 lpItem->hbm = phdi->hbm;
1050 if (phdi->mask & HDI_LPARAM)
1051 lpItem->lParam = phdi->lParam;
1053 if (phdi->mask & HDI_IMAGE)
1055 if (phdi->iImage != I_IMAGECALLBACK)
1057 lpItem->iImage = phdi->iImage;
1061 lpItem->iImage = phdi->iImage;
1062 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, NULL, lpItem, bUnicode);
1066 if (phdi->mask & HDI_TEXT)
1068 if (!phdi->pszText) phdi->pszText = '\0'; /* null pointer check */
1069 if (phdi->pszText != LPSTR_TEXTCALLBACKW) /* covers != TEXTCALLBACKA too */
1072 Str_SetPtrW(&lpItem->pszText, phdi->pszText);
1074 Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)phdi->pszText);
1078 lpItem->pszText = phdi->pszText;
1079 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, NULL, lpItem, bUnicode);
1081 lpItem->fmt |= HDF_STRING;
1084 lpItem->iOrder = iOrder;
1086 HEADER_SetItemBounds (hwnd);
1088 InvalidateRect(hwnd, NULL, FALSE);
1095 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
1097 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1098 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1100 lpLayout->pwpos->hwnd = hwnd;
1101 lpLayout->pwpos->hwndInsertAfter = 0;
1102 lpLayout->pwpos->x = lpLayout->prc->left;
1103 lpLayout->pwpos->y = lpLayout->prc->top;
1104 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1105 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_HIDDEN)
1106 lpLayout->pwpos->cy = 0;
1108 lpLayout->pwpos->cy = infoPtr->nHeight;
1109 lpLayout->prc->top += infoPtr->nHeight;
1111 lpLayout->pwpos->flags = SWP_NOZORDER;
1113 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1114 lpLayout->pwpos->x, lpLayout->pwpos->y,
1115 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1117 infoPtr->bRectsValid = FALSE;
1124 HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
1126 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1129 TRACE("(himl %p)\n", himl);
1130 himlOld = infoPtr->himl;
1131 infoPtr->himl = himl;
1133 /* FIXME: Refresh needed??? */
1135 return (LRESULT)himlOld;
1140 HEADER_GetBitmapMargin(HWND hwnd)
1142 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
1144 return infoPtr->iMargin;
1148 HEADER_SetBitmapMargin(HWND hwnd, WPARAM wParam)
1150 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1151 INT oldMargin = infoPtr->iMargin;
1153 infoPtr->iMargin = (INT)wParam;
1159 HEADER_SetItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
1161 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1162 HEADER_ITEM *lpItem;
1166 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1169 TRACE("[nItem=%d]\n", nItem);
1171 if (HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask))
1174 lpItem = &infoPtr->items[nItem];
1175 if (phdi->mask & HDI_BITMAP)
1176 lpItem->hbm = phdi->hbm;
1178 if (phdi->mask & HDI_FORMAT)
1179 lpItem->fmt = phdi->fmt;
1181 if (phdi->mask & HDI_LPARAM)
1182 lpItem->lParam = phdi->lParam;
1184 if (phdi->mask & HDI_WIDTH)
1185 lpItem->cxy = phdi->cxy;
1187 if (phdi->mask & HDI_IMAGE)
1189 if (phdi->iImage != I_IMAGECALLBACK)
1191 lpItem->iImage = phdi->iImage;
1195 lpItem->iImage = phdi->iImage;
1196 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, NULL, lpItem, bUnicode);
1200 if (phdi->mask & HDI_TEXT)
1202 if (phdi->pszText != LPSTR_TEXTCALLBACKW) /* covers != TEXTCALLBACKA too */
1204 if (lpItem->pszText)
1206 Free(lpItem->pszText);
1207 lpItem->pszText = NULL;
1212 Str_SetPtrW(&lpItem->pszText, phdi->pszText);
1214 Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)phdi->pszText);
1219 lpItem->pszText = phdi->pszText;
1220 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, NULL, lpItem, bUnicode);
1224 if (phdi->mask & HDI_ORDER)
1228 if (lpItem->iOrder < phdi->iOrder)
1230 memmove(&infoPtr->order[lpItem->iOrder],
1231 &infoPtr->order[lpItem->iOrder + 1],
1232 (phdi->iOrder - lpItem->iOrder) * sizeof(INT));
1234 if (phdi->iOrder < lpItem->iOrder)
1236 memmove(&infoPtr->order[phdi->iOrder + 1],
1237 &infoPtr->order[phdi->iOrder],
1238 (lpItem->iOrder - phdi->iOrder) * sizeof(INT));
1240 infoPtr->order[phdi->iOrder] = nItem;
1241 nMin = min(lpItem->iOrder, phdi->iOrder);
1242 nMax = max(lpItem->iOrder, phdi->iOrder);
1243 for (i = nMin; i <= nMax; i++)
1245 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
1249 HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMCHANGEDW, nItem, phdi->mask);
1251 HEADER_SetItemBounds (hwnd);
1253 InvalidateRect(hwnd, NULL, FALSE);
1258 inline static LRESULT
1259 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1261 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1262 BOOL bTemp = infoPtr->bUnicode;
1264 infoPtr->bUnicode = (BOOL)wParam;
1271 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1273 HEADER_INFO *infoPtr;
1278 infoPtr = (HEADER_INFO *)Alloc (sizeof(HEADER_INFO));
1279 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1281 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
1282 infoPtr->uNumItem = 0;
1286 infoPtr->bRectsValid = FALSE;
1287 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1288 infoPtr->hcurDivider = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDER));
1289 infoPtr->hcurDivopen = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDEROPEN));
1290 infoPtr->bPressed = FALSE;
1291 infoPtr->bTracking = FALSE;
1292 infoPtr->iMoveItem = 0;
1294 infoPtr->iHotItem = -1;
1295 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1296 infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
1297 infoPtr->nNotifyFormat =
1298 SendMessageW (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1301 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1302 GetTextMetricsW (hdc, &tm);
1303 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1304 SelectObject (hdc, hOldFont);
1307 OpenThemeData(hwnd, themeClass);
1314 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1316 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1317 HEADER_ITEM *lpItem;
1321 if (infoPtr->items) {
1322 lpItem = infoPtr->items;
1323 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1324 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
1325 Free (lpItem->pszText);
1327 Free (infoPtr->items);
1331 Free(infoPtr->order);
1334 ImageList_Destroy (infoPtr->himl);
1336 SetWindowLongPtrW (hwnd, 0, 0);
1339 theme = GetWindowTheme(hwnd);
1340 CloseThemeData(theme);
1345 static inline LRESULT
1346 HEADER_GetFont (HWND hwnd)
1348 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1350 return (LRESULT)infoPtr->hFont;
1355 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1361 pt.x = (INT)LOWORD(lParam);
1362 pt.y = (INT)HIWORD(lParam);
1363 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1365 if ((GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1366 HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMDBLCLICKW, nItem,0);
1367 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1368 HEADER_SendHeaderNotifyT (hwnd, HDN_DIVIDERDBLCLICKW, nItem,0);
1375 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1377 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1378 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1384 pt.x = (INT)LOWORD(lParam);
1385 pt.y = (INT)HIWORD(lParam);
1386 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1388 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1390 infoPtr->bCaptured = TRUE;
1391 infoPtr->bPressed = TRUE;
1392 infoPtr->iMoveItem = nItem;
1394 infoPtr->items[nItem].bDown = TRUE;
1396 /* Send WM_CUSTOMDRAW */
1398 HEADER_RefreshItem (hwnd, hdc, nItem);
1399 ReleaseDC (hwnd, hdc);
1401 TRACE("Pressed item %d!\n", nItem);
1403 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1404 if (!(HEADER_SendHeaderNotifyT (hwnd, HDN_BEGINTRACKW, nItem,0))) {
1406 infoPtr->bCaptured = TRUE;
1407 infoPtr->bTracking = TRUE;
1408 infoPtr->iMoveItem = nItem;
1409 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1410 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1412 if (!(dwStyle & HDS_FULLDRAG)) {
1413 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1415 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1416 ReleaseDC (hwnd, hdc);
1419 TRACE("Begin tracking item %d!\n", nItem);
1428 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1430 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1431 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1437 pt.x = (INT)(SHORT)LOWORD(lParam);
1438 pt.y = (INT)(SHORT)HIWORD(lParam);
1439 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1441 if (infoPtr->bPressed) {
1442 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1443 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1445 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1446 ReleaseDC (hwnd, hdc);
1448 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1450 else if (flags == HHT_ONHEADER)
1452 HEADER_ITEM *lpItem;
1453 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1454 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1456 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1457 infoPtr->iMoveItem,oldindex,nItem,newindex);
1458 lpItem= &infoPtr->items[nItem];
1459 lpItem->iOrder=oldindex;
1461 lpItem= &infoPtr->items[infoPtr->iMoveItem];
1462 lpItem->iOrder = newindex;
1464 infoPtr->order[oldindex] = nItem;
1465 infoPtr->order[newindex] = infoPtr->iMoveItem;
1467 infoPtr->bRectsValid = FALSE;
1468 InvalidateRect(hwnd, NULL, FALSE);
1469 /* FIXME: Should some WM_NOTIFY be sent */
1472 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1473 infoPtr->bPressed = FALSE;
1475 else if (infoPtr->bTracking) {
1476 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1477 infoPtr->bTracking = FALSE;
1479 HEADER_SendHeaderNotifyT (hwnd, HDN_ENDTRACKW, infoPtr->iMoveItem,HDI_WIDTH);
1481 if (!(dwStyle & HDS_FULLDRAG)) {
1483 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1484 ReleaseDC (hwnd, hdc);
1487 if (HEADER_SendHeaderNotifyT(hwnd, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH))
1489 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1492 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1495 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1498 HEADER_SetItemBounds (hwnd);
1499 InvalidateRect(hwnd, NULL, TRUE);
1500 HEADER_SendHeaderNotifyT(hwnd, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH);
1503 if (infoPtr->bCaptured) {
1504 infoPtr->bCaptured = FALSE;
1506 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1514 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1516 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1521 return infoPtr->nNotifyFormat;
1524 infoPtr->nNotifyFormat =
1525 SendMessageW ((HWND)wParam, WM_NOTIFYFORMAT,
1526 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1527 return infoPtr->nNotifyFormat;
1535 HEADER_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
1537 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1538 /* Reset hot-tracked item when mouse leaves control. */
1539 INT oldHotItem = infoPtr->iHotItem;
1540 HDC hdc = GetDC (hwnd);
1542 infoPtr->iHotItem = -1;
1543 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem);
1544 ReleaseDC (hwnd, hdc);
1551 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1553 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1554 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1559 /* With theming, hottracking is always enabled */
1560 BOOL hotTrackEnabled =
1561 ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK))
1562 || (GetWindowTheme (hwnd) != NULL);
1563 INT oldHotItem = infoPtr->iHotItem;
1565 pt.x = (INT)(SHORT)LOWORD(lParam);
1566 pt.y = (INT)(SHORT)HIWORD(lParam);
1567 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1569 if (hotTrackEnabled) {
1570 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1571 infoPtr->iHotItem = nItem;
1573 infoPtr->iHotItem = -1;
1576 if (infoPtr->bCaptured) {
1577 if (infoPtr->bPressed) {
1578 BOOL oldState = infoPtr->items[infoPtr->iMoveItem].bDown;
1579 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1580 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1582 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1583 if (oldState != infoPtr->items[infoPtr->iMoveItem].bDown) {
1585 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1586 ReleaseDC (hwnd, hdc);
1589 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1591 else if (infoPtr->bTracking) {
1592 if (dwStyle & HDS_FULLDRAG) {
1593 if (!HEADER_SendHeaderNotifyT (hwnd, HDN_ITEMCHANGINGW, infoPtr->iMoveItem, HDI_WIDTH))
1595 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1598 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1599 HEADER_SendHeaderNotifyT(hwnd, HDN_ITEMCHANGEDW, infoPtr->iMoveItem, HDI_WIDTH);
1601 HEADER_SetItemBounds (hwnd);
1602 InvalidateRect(hwnd, NULL, FALSE);
1606 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1607 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1608 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1609 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1610 infoPtr->items[infoPtr->iMoveItem].cxy =
1611 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1612 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1613 ReleaseDC (hwnd, hdc);
1614 HEADER_SendHeaderNotifyT (hwnd, HDN_TRACKW, infoPtr->iMoveItem, HDI_WIDTH);
1617 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1621 if (hotTrackEnabled) {
1622 TRACKMOUSEEVENT tme;
1623 if (oldHotItem != infoPtr->iHotItem) {
1625 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem);
1626 if (infoPtr->iHotItem != -1) HEADER_RefreshItem (hwnd, hdc, infoPtr->iHotItem);
1627 ReleaseDC (hwnd, hdc);
1629 tme.cbSize = sizeof( tme );
1630 tme.dwFlags = TME_LEAVE;
1631 tme.hwndTrack = hwnd;
1632 TrackMouseEvent( &tme );
1640 HEADER_Paint (HWND hwnd, WPARAM wParam)
1645 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1646 HEADER_Refresh (hwnd, hdc);
1648 EndPaint (hwnd, &ps);
1654 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1659 pt.x = LOWORD(lParam);
1660 pt.y = HIWORD(lParam);
1662 /* Send a Notify message */
1663 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1665 /* Change to screen coordinate for WM_CONTEXTMENU */
1666 ClientToScreen(hwnd, &pt);
1668 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1669 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1676 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1678 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1683 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1686 ScreenToClient (hwnd, &pt);
1688 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1690 if (flags == HHT_ONDIVIDER)
1691 SetCursor (infoPtr->hcurDivider);
1692 else if (flags == HHT_ONDIVOPEN)
1693 SetCursor (infoPtr->hcurDivopen);
1695 SetCursor (infoPtr->hcurArrow);
1702 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1704 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1706 HFONT hFont, hOldFont;
1709 infoPtr->hFont = (HFONT)wParam;
1711 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1714 hOldFont = SelectObject (hdc, hFont);
1715 GetTextMetricsW (hdc, &tm);
1716 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1717 SelectObject (hdc, hOldFont);
1720 infoPtr->bRectsValid = FALSE;
1723 InvalidateRect(hwnd, NULL, FALSE);
1729 /* Update the theme handle after a theme change */
1730 static LRESULT HEADER_ThemeChanged(HWND hwnd)
1732 HTHEME theme = GetWindowTheme(hwnd);
1733 CloseThemeData(theme);
1734 OpenThemeData(hwnd, themeClass);
1735 InvalidateRect(hwnd, NULL, FALSE);
1740 static LRESULT WINAPI
1741 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1743 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1744 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1745 return DefWindowProcW (hwnd, msg, wParam, lParam);
1747 /* case HDM_CLEARFILTER: */
1749 case HDM_CREATEDRAGIMAGE:
1750 return HEADER_CreateDragImage (hwnd, wParam);
1752 case HDM_DELETEITEM:
1753 return HEADER_DeleteItem (hwnd, wParam);
1755 /* case HDM_EDITFILTER: */
1757 case HDM_GETBITMAPMARGIN:
1758 return HEADER_GetBitmapMargin(hwnd);
1760 case HDM_GETIMAGELIST:
1761 return HEADER_GetImageList (hwnd);
1765 return HEADER_GetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_GETITEMW);
1767 case HDM_GETITEMCOUNT:
1768 return HEADER_GetItemCount (hwnd);
1770 case HDM_GETITEMRECT:
1771 return HEADER_GetItemRect (hwnd, wParam, lParam);
1773 case HDM_GETORDERARRAY:
1774 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1776 case HDM_GETUNICODEFORMAT:
1777 return HEADER_GetUnicodeFormat (hwnd);
1780 return HEADER_HitTest (hwnd, wParam, lParam);
1782 case HDM_INSERTITEMA:
1783 case HDM_INSERTITEMW:
1784 return HEADER_InsertItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_INSERTITEMW);
1787 return HEADER_Layout (hwnd, wParam, lParam);
1789 case HDM_ORDERTOINDEX:
1790 return HEADER_OrderToIndex(hwnd, wParam);
1792 case HDM_SETBITMAPMARGIN:
1793 return HEADER_SetBitmapMargin(hwnd, wParam);
1795 /* case HDM_SETFILTERCHANGETIMEOUT: */
1797 /* case HDM_SETHOTDIVIDER: */
1799 case HDM_SETIMAGELIST:
1800 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
1804 return HEADER_SetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_SETITEMW);
1806 case HDM_SETORDERARRAY:
1807 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1809 case HDM_SETUNICODEFORMAT:
1810 return HEADER_SetUnicodeFormat (hwnd, wParam);
1813 return HEADER_Create (hwnd, wParam, lParam);
1816 return HEADER_Destroy (hwnd, wParam, lParam);
1822 return DLGC_WANTTAB | DLGC_WANTARROWS;
1825 return HEADER_GetFont (hwnd);
1827 case WM_LBUTTONDBLCLK:
1828 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1830 case WM_LBUTTONDOWN:
1831 return HEADER_LButtonDown (hwnd, wParam, lParam);
1834 return HEADER_LButtonUp (hwnd, wParam, lParam);
1837 return HEADER_MouseLeave (hwnd, wParam, lParam);
1840 return HEADER_MouseMove (hwnd, wParam, lParam);
1842 case WM_NOTIFYFORMAT:
1843 return HEADER_NotifyFormat (hwnd, wParam, lParam);
1846 return HEADER_Size (hwnd, wParam);
1848 case WM_THEMECHANGED:
1849 return HEADER_ThemeChanged (hwnd);
1851 case WM_PRINTCLIENT:
1853 return HEADER_Paint (hwnd, wParam);
1856 return HEADER_RButtonUp (hwnd, wParam, lParam);
1859 return HEADER_SetCursor (hwnd, wParam, lParam);
1862 return HEADER_SetFont (hwnd, wParam, lParam);
1865 if ((msg >= WM_USER) && (msg < WM_APP))
1866 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1867 msg, wParam, lParam );
1868 return DefWindowProcA (hwnd, msg, wParam, lParam);
1874 HEADER_Register (void)
1878 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1879 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1880 wndClass.lpfnWndProc = HEADER_WindowProc;
1881 wndClass.cbClsExtra = 0;
1882 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1883 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1884 wndClass.lpszClassName = WC_HEADERW;
1886 RegisterClassW (&wndClass);
1891 HEADER_Unregister (void)
1893 UnregisterClassW (WC_HEADERW, NULL);