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
98 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongPtrW(hwnd,0))
100 static const WCHAR themeClass[] = {'H','e','a','d','e','r',0};
103 inline static LRESULT
104 HEADER_IndexToOrder (HWND hwnd, INT iItem)
106 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
107 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
108 return lpItem->iOrder;
113 HEADER_OrderToIndex(HWND hwnd, WPARAM wParam)
115 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
116 INT iorder = (INT)wParam;
118 if ((iorder <0) || iorder >= infoPtr->uNumItem)
120 return infoPtr->order[iorder];
124 HEADER_SetItemBounds (HWND hwnd)
126 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
132 infoPtr->bRectsValid = TRUE;
134 if (infoPtr->uNumItem == 0)
137 GetClientRect (hwnd, &rect);
140 for (i = 0; i < infoPtr->uNumItem; i++) {
141 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
142 phdi->rect.top = rect.top;
143 phdi->rect.bottom = rect.bottom;
145 phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
146 x = phdi->rect.right;
151 HEADER_Size (HWND hwnd, WPARAM wParam)
153 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
155 infoPtr->bRectsValid = FALSE;
162 HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
164 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
165 HEADER_ITEM *phdi = &infoPtr->items[iItem];
167 INT oldBkMode, cxEdge = GetSystemMetrics(SM_CXEDGE);
168 HTHEME theme = GetWindowTheme (hwnd);
170 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, infoPtr->bUnicode);
172 if (!infoPtr->bRectsValid)
173 HEADER_SetItemBounds(hwnd);
176 if (r.right - r.left == 0)
177 return phdi->rect.right;
180 int state = (phdi->bDown) ? HIS_PRESSED :
181 (bHotTrack ? HIS_HOT : HIS_NORMAL);
182 DrawThemeBackground (theme, hdc, HP_HEADERITEM, state,
184 GetThemeBackgroundContentRect (theme, hdc, HP_HEADERITEM, state,
188 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) {
190 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
191 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
194 DrawEdge (hdc, &r, EDGE_RAISED,
195 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
198 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
208 if (phdi->fmt & HDF_OWNERDRAW) {
212 nmcd.hdr.hwndFrom = hwnd;
213 nmcd.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
214 nmcd.hdr.code = NM_CUSTOMDRAW;
215 nmcd.dwDrawStage = CDDS_PREPAINT | CDDS_ITEM | CDDS_ITEMPOSTERASE;
217 nmcd.dwItemSpec = iItem;
219 nmcd.uItemState = phdi->bDown ? CDIS_SELECTED : 0;
220 nmcd.lItemlParam = phdi->lParam;
222 SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
223 (WPARAM)nmcd.hdr.idFrom, (LPARAM)&nmcd);
225 dis.CtlType = ODT_HEADER;
226 dis.CtlID = GetWindowLongPtrW (hwnd, GWLP_ID);
228 dis.itemAction = ODA_DRAWENTIRE;
229 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
233 dis.itemData = phdi->lParam;
234 oldBkMode = SetBkMode(hdc, TRANSPARENT);
235 SendMessageW (infoPtr->hwndNotify, WM_DRAWITEM,
236 (WPARAM)dis.CtlID, (LPARAM)&dis);
237 if (oldBkMode != TRANSPARENT)
238 SetBkMode(hdc, oldBkMode);
241 UINT rw, rh, /* width and height of r */
242 *x = NULL, *w = NULL; /* x and width of the pic (bmp or img) which is part of cnt */
243 /* cnt,txt,img,bmp */
248 cw = tw = iw = bw = 0;
249 rw = r.right - r.left;
250 rh = r.bottom - r.top;
252 if (phdi->fmt & HDF_STRING) {
255 DrawTextW (hdc, phdi->pszText, -1,
256 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
257 cw = textRect.right - textRect.left + 2 * infoPtr->iMargin;
260 if ((phdi->fmt & HDF_IMAGE) && (infoPtr->himl)) {
261 iw = infoPtr->himl->cx + 2 * infoPtr->iMargin;
266 if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
267 GetObjectW (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
268 bw = bmp.bmWidth + 2 * infoPtr->iMargin;
278 /* align cx using the unclipped cw */
279 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_LEFT)
281 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
282 cx = r.left + rw / 2 - cw / 2;
289 if (cx + cw > r.right)
292 tx = cx + infoPtr->iMargin;
293 /* since cw might have changed we have to recalculate tw */
294 tw = cw - infoPtr->iMargin * 2;
298 if (phdi->fmt & HDF_BITMAP_ON_RIGHT) {
299 /* put pic behind text */
300 *x = cx + tw + infoPtr->iMargin * 3;
302 *x = cx + infoPtr->iMargin;
303 /* move text behind pic */
309 /* since we're done with the layout we can
310 now calculate the position of bmp which
311 has no influence on alignment and layout
313 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
314 bx = cx - bw + infoPtr->iMargin;
316 bx = cx + cw + infoPtr->iMargin;
320 HDC hClipDC = GetDC(hwnd);
321 HRGN hClipRgn = CreateRectRgn(r.left, r.top, r.right, r.bottom);
322 SelectClipRgn(hClipDC, hClipRgn);
325 HDC hdcBitmap = CreateCompatibleDC (hClipDC);
326 SelectObject (hdcBitmap, phdi->hbm);
327 BitBlt (hClipDC, bx, r.top + ((INT)rh - bmp.bmHeight) / 2,
328 bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
329 DeleteDC (hdcBitmap);
333 ImageList_DrawEx (infoPtr->himl, phdi->iImage, hClipDC,
334 ix, r.top + ((INT)rh - infoPtr->himl->cy) / 2,
335 infoPtr->himl->cx, infoPtr->himl->cy, CLR_DEFAULT, CLR_DEFAULT, 0);
338 DeleteObject(hClipRgn);
339 ReleaseDC(hwnd, hClipDC);
342 if (((phdi->fmt & HDF_STRING)
343 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
344 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
345 && (phdi->pszText)) {
346 oldBkMode = SetBkMode(hdc, TRANSPARENT);
347 SetTextColor (hdc, (bHotTrack && !theme) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
350 DrawTextW (hdc, phdi->pszText, -1,
351 &r, DT_LEFT|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
352 if (oldBkMode != TRANSPARENT)
353 SetBkMode(hdc, oldBkMode);
357 return phdi->rect.right;
362 HEADER_Refresh (HWND hwnd, HDC hdc)
364 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
365 HFONT hFont, hOldFont;
370 HTHEME theme = GetWindowTheme (hwnd);
372 /* get rect for the bar, adjusted for the border */
373 GetClientRect (hwnd, &rect);
375 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
376 hOldFont = SelectObject (hdc, hFont);
378 /* draw Background */
380 hbrBk = GetSysColorBrush(COLOR_3DFACE);
381 FillRect(hdc, &rect, hbrBk);
385 for (i = 0; x <= rect.right && i < infoPtr->uNumItem; i++) {
386 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i),
387 infoPtr->iHotItem == i);
390 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
393 DrawThemeBackground (theme, hdc, HP_HEADERITEM, HIS_NORMAL, &rect,
397 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS)
398 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
400 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
404 SelectObject (hdc, hOldFont);
409 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
411 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
412 HFONT hFont, hOldFont;
414 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
415 hOldFont = SelectObject (hdc, hFont);
416 HEADER_DrawItem (hwnd, hdc, iItem, infoPtr->iHotItem == iItem);
417 SelectObject (hdc, hOldFont);
422 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
424 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
430 GetClientRect (hwnd, &rect);
434 if (PtInRect (&rect, *lpPt))
436 if (infoPtr->uNumItem == 0) {
437 *pFlags |= HHT_NOWHERE;
443 /* somewhere inside */
444 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
445 rect = infoPtr->items[iCount].rect;
446 width = rect.right - rect.left;
451 if (PtInRect (&rect, *lpPt)) {
452 if (width <= 2 * DIVIDER_WIDTH) {
453 *pFlags |= HHT_ONHEADER;
455 TRACE("ON HEADER %d\n", iCount);
460 rcTest.right = rcTest.left + DIVIDER_WIDTH;
461 if (PtInRect (&rcTest, *lpPt)) {
463 *pFlags |= HHT_ONDIVOPEN;
465 TRACE("ON DIVOPEN %d\n", *pItem);
469 *pFlags |= HHT_ONDIVIDER;
471 TRACE("ON DIVIDER %d\n", *pItem);
477 rcTest.left = rcTest.right - DIVIDER_WIDTH;
478 if (PtInRect (&rcTest, *lpPt)) {
479 *pFlags |= HHT_ONDIVIDER;
481 TRACE("ON DIVIDER %d\n", *pItem);
485 *pFlags |= HHT_ONHEADER;
487 TRACE("ON HEADER %d\n", iCount);
492 /* check for last divider part (on nowhere) */
493 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
494 rect.left = rect.right;
495 rect.right += DIVIDER_WIDTH;
496 if (PtInRect (&rect, *lpPt)) {
498 *pFlags |= HHT_ONDIVOPEN;
499 *pItem = infoPtr->uNumItem - 1;
500 TRACE("ON DIVOPEN %d\n", *pItem);
504 *pFlags |= HHT_ONDIVIDER;
505 *pItem = infoPtr->uNumItem-1;
506 TRACE("ON DIVIDER %d\n", *pItem);
511 *pFlags |= HHT_NOWHERE;
518 if (lpPt->x < rect.left) {
520 *pFlags |= HHT_TOLEFT;
522 else if (lpPt->x > rect.right) {
524 *pFlags |= HHT_TORIGHT;
527 if (lpPt->y < rect.top) {
529 *pFlags |= HHT_ABOVE;
531 else if (lpPt->y > rect.bottom) {
533 *pFlags |= HHT_BELOW;
538 TRACE("flags=0x%X\n", *pFlags);
544 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
550 GetClientRect (hwnd, &rect);
552 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
553 oldRop = SetROP2 (hdc, R2_XORPEN);
554 MoveToEx (hdc, x, rect.top, NULL);
555 LineTo (hdc, x, rect.bottom);
556 SetROP2 (hdc, oldRop);
557 SelectObject (hdc, hOldPen);
562 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
564 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
567 nmhdr.hwndFrom = hwnd;
568 nmhdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
571 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
572 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
576 HEADER_SendHeaderNotify (HWND hwnd, UINT code, INT iItem, INT mask)
578 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
582 nmhdr.hdr.hwndFrom = hwnd;
583 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
584 nmhdr.hdr.code = code;
587 nmhdr.pitem = &nmitem;
589 nmitem.cxy = infoPtr->items[iItem].cxy;
590 nmitem.hbm = infoPtr->items[iItem].hbm;
591 nmitem.pszText = NULL;
592 nmitem.cchTextMax = 0;
593 /* nmitem.pszText = infoPtr->items[iItem].pszText; */
594 /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
595 nmitem.fmt = infoPtr->items[iItem].fmt;
596 nmitem.lParam = infoPtr->items[iItem].lParam;
597 nmitem.iOrder = infoPtr->items[iItem].iOrder;
598 nmitem.iImage = infoPtr->items[iItem].iImage;
600 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
601 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
605 * Send Disp Info notification.
606 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
607 * (so we handle the two cases only doing a specific cast for pszText).
609 * @param hwnd : hwnd header container handler
610 * @param mask : notification mask (usually HDI_TEXT or HDI_IMAGE)
611 * @param pDispInfo : NMHDDISPINFO structure (can be unicode or ansi)
612 * @param isW : TRUE if dispinfo is Unicode
615 HEADER_SendHeaderDispInfoNotify(HWND hwnd, INT iItem, INT mask, LPHDITEMW phdi, HEADER_ITEM* lpItem, BOOL isW)
617 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
619 BOOL convertToAnsi = FALSE;
620 BOOL convertToUnicode = FALSE;
621 BOOL isUnicodeNotify = FALSE;
622 NMHDDISPINFOW dispInfo;
626 convertToAnsi = (isW && infoPtr->nNotifyFormat == NFR_ANSI);
627 convertToUnicode = (!isW && infoPtr->nNotifyFormat == NFR_UNICODE);
629 isUnicodeNotify = (isW && !convertToAnsi);
631 memset(&dispInfo, 0, sizeof(NMHDDISPINFOW));
632 dispInfo.hdr.hwndFrom = hwnd;
633 dispInfo.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
634 if (isUnicodeNotify || convertToUnicode)
636 dispInfo.hdr.code = HDN_GETDISPINFOW;
640 dispInfo.hdr.code = HDN_GETDISPINFOA;
642 dispInfo.iItem = iItem;
643 dispInfo.mask = mask;
645 dispInfo.pszText = Alloc(sizeof(WCHAR) * 260);
646 dispInfo.cchTextMax = 260;
648 ret = (BOOL) SendMessageW(infoPtr->hwndNotify, WM_NOTIFY,
649 (WPARAM) dispInfo.hdr.idFrom,
652 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
654 (isUnicodeNotify ? debugstr_w(dispInfo.pszText) : (LPSTR) dispInfo.pszText),
655 (void*) dispInfo.lParam);
657 if (dispInfo.mask & HDI_DI_SETITEM)
659 if (dispInfo.mask & HDI_IMAGE)
661 lpItem->iImage = dispInfo.iImage;
663 if (dispInfo.mask & HDI_TEXT)
665 if (isUnicodeNotify || convertToUnicode)
666 Str_SetPtrW(&lpItem->pszText, (LPCWSTR)dispInfo.pszText);
667 else /*if (convertToAnsi || !isW)*/
668 Str_SetPtrAtoW(&lpItem->pszText, (LPCSTR)dispInfo.pszText);
671 FIXME("NMHDDISPINFO returns with flags HDI_DI_SETITEM\n");
676 if ((phdi->mask & mask) & HDI_IMAGE)
678 phdi->iImage = dispInfo.iImage;
680 if ((phdi->mask & mask) & HDI_TEXT)
683 Str_GetPtrW ((LPCWSTR)dispInfo.pszText, phdi->pszText, phdi->cchTextMax);
684 else if (convertToUnicode)
685 Str_GetPtrWtoA ((LPCWSTR)dispInfo.pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
687 Str_GetPtrA ((LPCSTR)dispInfo.pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
695 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
697 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
700 nmhdr.hdr.hwndFrom = hwnd;
701 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
702 nmhdr.hdr.code = code;
707 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
708 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
713 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
715 FIXME("empty stub!\n");
721 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
723 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
724 INT iItem = (INT)wParam;
726 TRACE("[iItem=%d]\n", iItem);
728 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
731 if (infoPtr->uNumItem == 1) {
732 TRACE("Simple delete!\n");
733 if (infoPtr->items[0].pszText)
734 Free (infoPtr->items[0].pszText);
735 Free (infoPtr->items);
736 Free(infoPtr->order);
739 infoPtr->uNumItem = 0;
742 HEADER_ITEM *oldItems = infoPtr->items;
745 TRACE("Complex delete! [iItem=%d]\n", iItem);
747 for (i = 0; i < infoPtr->uNumItem; i++)
748 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
749 if (infoPtr->items[iItem].pszText)
750 Free (infoPtr->items[iItem].pszText);
751 iOrder = infoPtr->items[iItem].iOrder;
754 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
755 /* pre delete copy */
757 memcpy (&infoPtr->items[0], &oldItems[0],
758 iItem * sizeof(HEADER_ITEM));
761 /* post delete copy */
762 if (iItem < infoPtr->uNumItem) {
763 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
764 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
767 /* Correct the orders */
768 if (iOrder < infoPtr->uNumItem)
770 memmove(&infoPtr->order[iOrder], &infoPtr->order[iOrder + 1],
771 (infoPtr->uNumItem - iOrder) * sizeof(INT));
772 for (i = 0; i < infoPtr->uNumItem; i++)
774 if (infoPtr->order[i] > iItem)
777 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
781 for (i = 0; i < infoPtr->uNumItem; i++)
782 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i, infoPtr->order[i], infoPtr->items[i].iOrder, infoPtr->items[infoPtr->order[i]].iOrder);
786 HEADER_SetItemBounds (hwnd);
788 InvalidateRect(hwnd, NULL, FALSE);
795 HEADER_GetImageList (HWND hwnd)
797 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
799 return (LRESULT)infoPtr->himl;
804 HEADER_GetItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
806 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
812 TRACE("[nItem=%d]\n", nItem);
816 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
819 lpItem = &infoPtr->items[nItem];
821 if (phdi->mask & HDI_BITMAP)
822 phdi->hbm = (lpItem != NULL) ? lpItem->hbm : 0;
824 if (phdi->mask & HDI_FORMAT)
825 phdi->fmt = (lpItem != NULL) ? lpItem->fmt : 0;
827 if (phdi->mask & HDI_WIDTH)
828 phdi->cxy = (lpItem != NULL) ? lpItem->cxy : 0;
830 if (phdi->mask & HDI_LPARAM)
831 phdi->lParam = (lpItem != NULL) ? lpItem->lParam : 0;
833 if (phdi->mask & HDI_IMAGE)
835 phdi->iImage = (lpItem != NULL) ? lpItem->iImage : 0;
836 if (lpItem->iImage == I_IMAGECALLBACK)
838 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, phdi, lpItem, bUnicode);
842 if (phdi->mask & HDI_ORDER)
843 phdi->iOrder = (lpItem != NULL) ? lpItem->iOrder : 0;
845 if (phdi->mask & HDI_TEXT)
847 if (lpItem == NULL) *phdi->pszText = 0; /* null pointer check */
848 else if (lpItem->pszText == LPSTR_TEXTCALLBACKW) /* covers == TEXTCALLBACKA too */
850 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, phdi, lpItem, bUnicode);
855 Str_GetPtrW (lpItem->pszText, phdi->pszText, phdi->cchTextMax);
857 Str_GetPtrWtoA (lpItem->pszText, (LPSTR)phdi->pszText, phdi->cchTextMax);
865 inline static LRESULT
866 HEADER_GetItemCount (HWND hwnd)
868 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
869 return infoPtr->uNumItem;
874 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
876 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
877 INT iItem = (INT)wParam;
878 LPRECT lpRect = (LPRECT)lParam;
880 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
883 lpRect->left = infoPtr->items[iItem].rect.left;
884 lpRect->right = infoPtr->items[iItem].rect.right;
885 lpRect->top = infoPtr->items[iItem].rect.top;
886 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
893 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
895 LPINT order = (LPINT) lParam;
896 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
898 if ((unsigned int)wParam <infoPtr->uNumItem)
901 memcpy(order, infoPtr->order, infoPtr->uNumItem * sizeof(INT));
906 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
909 LPINT order = (LPINT) lParam;
910 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
913 if ((unsigned int)wParam <infoPtr->uNumItem)
915 memcpy(infoPtr->order, order, infoPtr->uNumItem * sizeof(INT));
916 for (i=0; i<(int)wParam; i++)
918 lpItem = &infoPtr->items[*order++];
921 infoPtr->bRectsValid=0;
922 InvalidateRect(hwnd, NULL, FALSE);
926 inline static LRESULT
927 HEADER_GetUnicodeFormat (HWND hwnd)
929 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
930 return infoPtr->bUnicode;
935 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
937 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
939 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
941 if (phti->flags == HHT_NOWHERE)
949 HEADER_InsertItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
951 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
956 if ((phdi == NULL) || (nItem < 0))
959 if (nItem > infoPtr->uNumItem)
960 nItem = infoPtr->uNumItem;
962 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
965 else if (infoPtr->uNumItem < iOrder)
966 iOrder = infoPtr->uNumItem;
968 if (infoPtr->uNumItem == 0) {
969 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
970 infoPtr->order = Alloc(sizeof(INT));
974 HEADER_ITEM *oldItems = infoPtr->items;
975 INT *oldOrder = infoPtr->order;
978 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
980 memcpy (&infoPtr->items[1], &oldItems[0],
981 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
985 /* pre insert copy */
987 memcpy (&infoPtr->items[0], &oldItems[0],
988 nItem * sizeof(HEADER_ITEM));
991 /* post insert copy */
992 if (nItem < infoPtr->uNumItem - 1) {
993 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
994 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
998 infoPtr->order = Alloc(sizeof(INT) * infoPtr->uNumItem);
999 memcpy(infoPtr->order, oldOrder, iOrder * sizeof(INT));
1000 infoPtr->order[iOrder] = nItem;
1001 memcpy(&infoPtr->order[iOrder + 1], &oldOrder[iOrder],
1002 (infoPtr->uNumItem - iOrder - 1) * sizeof(INT));
1008 for (i = 0; i < infoPtr->uNumItem; i++)
1010 if (i != iOrder && infoPtr->order[i] >= nItem)
1011 infoPtr->order[i]++;
1012 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
1015 lpItem = &infoPtr->items[nItem];
1016 lpItem->bDown = FALSE;
1018 if (phdi->mask & HDI_WIDTH)
1019 lpItem->cxy = phdi->cxy;
1021 if (phdi->mask & HDI_FORMAT)
1022 lpItem->fmt = phdi->fmt;
1024 if (lpItem->fmt == 0)
1025 lpItem->fmt = HDF_LEFT;
1027 if (phdi->mask & HDI_BITMAP)
1028 lpItem->hbm = phdi->hbm;
1030 if (phdi->mask & HDI_LPARAM)
1031 lpItem->lParam = phdi->lParam;
1033 if (phdi->mask & HDI_IMAGE)
1035 if (phdi->iImage != I_IMAGECALLBACK)
1037 lpItem->iImage = phdi->iImage;
1041 lpItem->iImage = phdi->iImage;
1042 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, NULL, lpItem, bUnicode);
1046 if (phdi->mask & HDI_TEXT)
1048 if (!phdi->pszText) phdi->pszText = '\0'; /* null pointer check */
1049 if (phdi->pszText != LPSTR_TEXTCALLBACKW) /* covers != TEXTCALLBACKA too */
1052 Str_SetPtrW(&lpItem->pszText, phdi->pszText);
1054 Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)phdi->pszText);
1058 lpItem->pszText = phdi->pszText;
1059 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, NULL, lpItem, bUnicode);
1061 lpItem->fmt |= HDF_STRING;
1064 lpItem->iOrder = iOrder;
1066 HEADER_SetItemBounds (hwnd);
1068 InvalidateRect(hwnd, NULL, FALSE);
1075 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
1077 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1078 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1080 lpLayout->pwpos->hwnd = hwnd;
1081 lpLayout->pwpos->hwndInsertAfter = 0;
1082 lpLayout->pwpos->x = lpLayout->prc->left;
1083 lpLayout->pwpos->y = lpLayout->prc->top;
1084 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1085 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_HIDDEN)
1086 lpLayout->pwpos->cy = 0;
1088 lpLayout->pwpos->cy = infoPtr->nHeight;
1089 lpLayout->prc->top += infoPtr->nHeight;
1091 lpLayout->pwpos->flags = SWP_NOZORDER;
1093 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1094 lpLayout->pwpos->x, lpLayout->pwpos->y,
1095 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1097 infoPtr->bRectsValid = FALSE;
1104 HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
1106 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1109 TRACE("(himl %p)\n", himl);
1110 himlOld = infoPtr->himl;
1111 infoPtr->himl = himl;
1113 /* FIXME: Refresh needed??? */
1115 return (LRESULT)himlOld;
1120 HEADER_GetBitmapMargin(HWND hwnd)
1122 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
1124 return infoPtr->iMargin;
1128 HEADER_SetBitmapMargin(HWND hwnd, WPARAM wParam)
1130 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1131 INT oldMargin = infoPtr->iMargin;
1133 infoPtr->iMargin = (INT)wParam;
1139 HEADER_SetItemT (HWND hwnd, INT nItem, LPHDITEMW phdi, BOOL bUnicode)
1141 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1142 HEADER_ITEM *lpItem;
1146 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1149 TRACE("[nItem=%d]\n", nItem);
1151 if (HEADER_SendHeaderNotify (hwnd, bUnicode ? HDN_ITEMCHANGINGW : HDN_ITEMCHANGINGA,
1155 lpItem = &infoPtr->items[nItem];
1156 if (phdi->mask & HDI_BITMAP)
1157 lpItem->hbm = phdi->hbm;
1159 if (phdi->mask & HDI_FORMAT)
1160 lpItem->fmt = phdi->fmt;
1162 if (phdi->mask & HDI_LPARAM)
1163 lpItem->lParam = phdi->lParam;
1165 if (phdi->mask & HDI_WIDTH)
1166 lpItem->cxy = phdi->cxy;
1168 if (phdi->mask & HDI_IMAGE)
1170 if (phdi->iImage != I_IMAGECALLBACK)
1172 lpItem->iImage = phdi->iImage;
1176 lpItem->iImage = phdi->iImage;
1177 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_IMAGE, NULL, lpItem, bUnicode);
1181 if (phdi->mask & HDI_TEXT)
1183 if (phdi->pszText != LPSTR_TEXTCALLBACKW) /* covers != TEXTCALLBACKA too */
1185 if (lpItem->pszText)
1187 Free(lpItem->pszText);
1188 lpItem->pszText = NULL;
1193 Str_SetPtrW(&lpItem->pszText, phdi->pszText);
1195 Str_SetPtrAtoW(&lpItem->pszText, (LPSTR)phdi->pszText);
1200 lpItem->pszText = phdi->pszText;
1201 HEADER_SendHeaderDispInfoNotify(hwnd, nItem, HDI_TEXT, NULL, lpItem, bUnicode);
1205 if (phdi->mask & HDI_ORDER)
1209 if (lpItem->iOrder < phdi->iOrder)
1211 memmove(&infoPtr->order[lpItem->iOrder],
1212 &infoPtr->order[lpItem->iOrder + 1],
1213 (phdi->iOrder - lpItem->iOrder) * sizeof(INT));
1215 if (phdi->iOrder < lpItem->iOrder)
1217 memmove(&infoPtr->order[phdi->iOrder + 1],
1218 &infoPtr->order[phdi->iOrder],
1219 (lpItem->iOrder - phdi->iOrder) * sizeof(INT));
1221 infoPtr->order[phdi->iOrder] = nItem;
1222 nMin = min(lpItem->iOrder, phdi->iOrder);
1223 nMax = max(lpItem->iOrder, phdi->iOrder);
1224 for (i = nMin; i <= nMax; i++)
1226 infoPtr->items[infoPtr->order[i]].iOrder = infoPtr->order[i];
1230 HEADER_SendHeaderNotify (hwnd, bUnicode ? HDN_ITEMCHANGEDW : HDN_ITEMCHANGEDA,
1233 HEADER_SetItemBounds (hwnd);
1235 InvalidateRect(hwnd, NULL, FALSE);
1240 inline static LRESULT
1241 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1243 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1244 BOOL bTemp = infoPtr->bUnicode;
1246 infoPtr->bUnicode = (BOOL)wParam;
1253 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1255 HEADER_INFO *infoPtr;
1260 infoPtr = (HEADER_INFO *)Alloc (sizeof(HEADER_INFO));
1261 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1263 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
1264 infoPtr->uNumItem = 0;
1268 infoPtr->bRectsValid = FALSE;
1269 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1270 infoPtr->hcurDivider = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDER));
1271 infoPtr->hcurDivopen = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDEROPEN));
1272 infoPtr->bPressed = FALSE;
1273 infoPtr->bTracking = FALSE;
1274 infoPtr->iMoveItem = 0;
1276 infoPtr->iHotItem = -1;
1277 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1278 infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
1279 infoPtr->nNotifyFormat =
1280 SendMessageW (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1283 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1284 GetTextMetricsW (hdc, &tm);
1285 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1286 SelectObject (hdc, hOldFont);
1289 OpenThemeData(hwnd, themeClass);
1296 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1298 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1299 HEADER_ITEM *lpItem;
1303 if (infoPtr->items) {
1304 lpItem = infoPtr->items;
1305 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1306 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
1307 Free (lpItem->pszText);
1309 Free (infoPtr->items);
1313 Free(infoPtr->order);
1316 ImageList_Destroy (infoPtr->himl);
1318 SetWindowLongPtrW (hwnd, 0, 0);
1321 theme = GetWindowTheme(hwnd);
1322 CloseThemeData(theme);
1327 static inline LRESULT
1328 HEADER_GetFont (HWND hwnd)
1330 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1332 return (LRESULT)infoPtr->hFont;
1337 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1343 pt.x = (INT)LOWORD(lParam);
1344 pt.y = (INT)HIWORD(lParam);
1345 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1347 if ((GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1348 HEADER_SendHeaderNotify (hwnd, HDN_ITEMDBLCLICKA, nItem,0);
1349 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1350 HEADER_SendHeaderNotify (hwnd, HDN_DIVIDERDBLCLICKA, nItem,0);
1357 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1359 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1360 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1366 pt.x = (INT)LOWORD(lParam);
1367 pt.y = (INT)HIWORD(lParam);
1368 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1370 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1372 infoPtr->bCaptured = TRUE;
1373 infoPtr->bPressed = TRUE;
1374 infoPtr->iMoveItem = nItem;
1376 infoPtr->items[nItem].bDown = TRUE;
1378 /* Send WM_CUSTOMDRAW */
1380 HEADER_RefreshItem (hwnd, hdc, nItem);
1381 ReleaseDC (hwnd, hdc);
1383 TRACE("Pressed item %d!\n", nItem);
1385 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1386 if (!(HEADER_SendHeaderNotify (hwnd, HDN_BEGINTRACKA, nItem,0))) {
1388 infoPtr->bCaptured = TRUE;
1389 infoPtr->bTracking = TRUE;
1390 infoPtr->iMoveItem = nItem;
1391 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1392 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1394 if (!(dwStyle & HDS_FULLDRAG)) {
1395 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1397 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1398 ReleaseDC (hwnd, hdc);
1401 TRACE("Begin tracking item %d!\n", nItem);
1410 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1412 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1414 *DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1421 pt.x = (INT)(SHORT)LOWORD(lParam);
1422 pt.y = (INT)(SHORT)HIWORD(lParam);
1423 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1425 if (infoPtr->bPressed) {
1426 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1427 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1429 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1430 ReleaseDC (hwnd, hdc);
1432 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1434 else if (flags == HHT_ONHEADER)
1436 HEADER_ITEM *lpItem;
1437 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1438 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1440 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1441 infoPtr->iMoveItem,oldindex,nItem,newindex);
1442 lpItem= &infoPtr->items[nItem];
1443 lpItem->iOrder=oldindex;
1445 lpItem= &infoPtr->items[infoPtr->iMoveItem];
1446 lpItem->iOrder = newindex;
1448 infoPtr->order[oldindex] = nItem;
1449 infoPtr->order[newindex] = infoPtr->iMoveItem;
1451 infoPtr->bRectsValid = FALSE;
1452 InvalidateRect(hwnd, NULL, FALSE);
1453 /* FIXME: Should some WM_NOTIFY be sent */
1456 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1457 infoPtr->bPressed = FALSE;
1459 else if (infoPtr->bTracking) {
1460 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1461 infoPtr->bTracking = FALSE;
1463 HEADER_SendHeaderNotify (hwnd, HDN_ENDTRACKA, infoPtr->iMoveItem,HDI_WIDTH);
1466 * we want to do this even for HDS_FULLDRAG because this is where
1467 * we send the HDN_ITEMCHANGING and HDN_ITEMCHANGED notifications
1469 * if (!(dwStyle & HDS_FULLDRAG)) {
1473 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1474 ReleaseDC (hwnd, hdc);
1475 if (HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1477 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1480 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1483 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1486 HEADER_SetItemBounds (hwnd);
1487 InvalidateRect(hwnd, NULL, TRUE);
1488 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1494 if (infoPtr->bCaptured) {
1495 infoPtr->bCaptured = FALSE;
1497 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1505 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1507 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1512 return infoPtr->nNotifyFormat;
1515 infoPtr->nNotifyFormat =
1516 SendMessageW ((HWND)wParam, WM_NOTIFYFORMAT,
1517 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1518 return infoPtr->nNotifyFormat;
1526 HEADER_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
1528 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1529 /* Reset hot-tracked item when mouse leaves control. */
1530 INT oldHotItem = infoPtr->iHotItem;
1531 HDC hdc = GetDC (hwnd);
1533 infoPtr->iHotItem = -1;
1534 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem);
1535 ReleaseDC (hwnd, hdc);
1542 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1544 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1545 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1550 /* With theming, hottracking is always enabled */
1551 BOOL hotTrackEnabled =
1552 ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK))
1553 || (GetWindowTheme (hwnd) != NULL);
1554 INT oldHotItem = infoPtr->iHotItem;
1556 pt.x = (INT)(SHORT)LOWORD(lParam);
1557 pt.y = (INT)(SHORT)HIWORD(lParam);
1558 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1560 if (hotTrackEnabled) {
1561 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1562 infoPtr->iHotItem = nItem;
1564 infoPtr->iHotItem = -1;
1567 if (infoPtr->bCaptured) {
1568 if (infoPtr->bPressed) {
1569 BOOL oldState = infoPtr->items[infoPtr->iMoveItem].bDown;
1570 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1571 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1573 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1574 if (oldState != infoPtr->items[infoPtr->iMoveItem].bDown) {
1576 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1577 ReleaseDC (hwnd, hdc);
1580 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1582 else if (infoPtr->bTracking) {
1583 if (dwStyle & HDS_FULLDRAG) {
1584 if (HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH))
1586 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1589 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1590 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1592 HEADER_SetItemBounds (hwnd);
1596 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1597 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1598 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1599 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1600 infoPtr->items[infoPtr->iMoveItem].cxy =
1601 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1602 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1603 ReleaseDC (hwnd, hdc);
1604 HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH);
1607 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1611 if (hotTrackEnabled) {
1612 TRACKMOUSEEVENT tme;
1613 if (oldHotItem != infoPtr->iHotItem) {
1615 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem);
1616 if (infoPtr->iHotItem != -1) HEADER_RefreshItem (hwnd, hdc, infoPtr->iHotItem);
1617 ReleaseDC (hwnd, hdc);
1619 tme.cbSize = sizeof( tme );
1620 tme.dwFlags = TME_LEAVE;
1621 tme.hwndTrack = hwnd;
1622 TrackMouseEvent( &tme );
1630 HEADER_Paint (HWND hwnd, WPARAM wParam)
1635 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1636 HEADER_Refresh (hwnd, hdc);
1638 EndPaint (hwnd, &ps);
1644 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1649 pt.x = LOWORD(lParam);
1650 pt.y = HIWORD(lParam);
1652 /* Send a Notify message */
1653 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1655 /* Change to screen coordinate for WM_CONTEXTMENU */
1656 ClientToScreen(hwnd, &pt);
1658 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1659 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1666 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1668 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1673 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1676 ScreenToClient (hwnd, &pt);
1678 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1680 if (flags == HHT_ONDIVIDER)
1681 SetCursor (infoPtr->hcurDivider);
1682 else if (flags == HHT_ONDIVOPEN)
1683 SetCursor (infoPtr->hcurDivopen);
1685 SetCursor (infoPtr->hcurArrow);
1692 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1694 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1696 HFONT hFont, hOldFont;
1699 infoPtr->hFont = (HFONT)wParam;
1701 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1704 hOldFont = SelectObject (hdc, hFont);
1705 GetTextMetricsW (hdc, &tm);
1706 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1707 SelectObject (hdc, hOldFont);
1710 infoPtr->bRectsValid = FALSE;
1713 InvalidateRect(hwnd, NULL, FALSE);
1719 /* Update the theme handle after a theme change */
1720 static LRESULT HEADER_ThemeChanged(HWND hwnd)
1722 HTHEME theme = GetWindowTheme(hwnd);
1723 CloseThemeData(theme);
1724 OpenThemeData(hwnd, themeClass);
1725 InvalidateRect(hwnd, NULL, FALSE);
1730 static LRESULT WINAPI
1731 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1733 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1734 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1735 return DefWindowProcW (hwnd, msg, wParam, lParam);
1737 /* case HDM_CLEARFILTER: */
1739 case HDM_CREATEDRAGIMAGE:
1740 return HEADER_CreateDragImage (hwnd, wParam);
1742 case HDM_DELETEITEM:
1743 return HEADER_DeleteItem (hwnd, wParam);
1745 /* case HDM_EDITFILTER: */
1747 case HDM_GETBITMAPMARGIN:
1748 return HEADER_GetBitmapMargin(hwnd);
1750 case HDM_GETIMAGELIST:
1751 return HEADER_GetImageList (hwnd);
1755 return HEADER_GetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_GETITEMW);
1757 case HDM_GETITEMCOUNT:
1758 return HEADER_GetItemCount (hwnd);
1760 case HDM_GETITEMRECT:
1761 return HEADER_GetItemRect (hwnd, wParam, lParam);
1763 case HDM_GETORDERARRAY:
1764 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1766 case HDM_GETUNICODEFORMAT:
1767 return HEADER_GetUnicodeFormat (hwnd);
1770 return HEADER_HitTest (hwnd, wParam, lParam);
1772 case HDM_INSERTITEMA:
1773 case HDM_INSERTITEMW:
1774 return HEADER_InsertItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_INSERTITEMW);
1777 return HEADER_Layout (hwnd, wParam, lParam);
1779 case HDM_ORDERTOINDEX:
1780 return HEADER_OrderToIndex(hwnd, wParam);
1782 case HDM_SETBITMAPMARGIN:
1783 return HEADER_SetBitmapMargin(hwnd, wParam);
1785 /* case HDM_SETFILTERCHANGETIMEOUT: */
1787 /* case HDM_SETHOTDIVIDER: */
1789 case HDM_SETIMAGELIST:
1790 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
1794 return HEADER_SetItemT (hwnd, (INT)wParam, (LPHDITEMW)lParam, msg == HDM_SETITEMW);
1796 case HDM_SETORDERARRAY:
1797 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1799 case HDM_SETUNICODEFORMAT:
1800 return HEADER_SetUnicodeFormat (hwnd, wParam);
1803 return HEADER_Create (hwnd, wParam, lParam);
1806 return HEADER_Destroy (hwnd, wParam, lParam);
1812 return DLGC_WANTTAB | DLGC_WANTARROWS;
1815 return HEADER_GetFont (hwnd);
1817 case WM_LBUTTONDBLCLK:
1818 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1820 case WM_LBUTTONDOWN:
1821 return HEADER_LButtonDown (hwnd, wParam, lParam);
1824 return HEADER_LButtonUp (hwnd, wParam, lParam);
1827 return HEADER_MouseLeave (hwnd, wParam, lParam);
1830 return HEADER_MouseMove (hwnd, wParam, lParam);
1832 case WM_NOTIFYFORMAT:
1833 return HEADER_NotifyFormat (hwnd, wParam, lParam);
1836 return HEADER_Size (hwnd, wParam);
1838 case WM_THEMECHANGED:
1839 return HEADER_ThemeChanged (hwnd);
1841 case WM_PRINTCLIENT:
1843 return HEADER_Paint (hwnd, wParam);
1846 return HEADER_RButtonUp (hwnd, wParam, lParam);
1849 return HEADER_SetCursor (hwnd, wParam, lParam);
1852 return HEADER_SetFont (hwnd, wParam, lParam);
1855 if ((msg >= WM_USER) && (msg < WM_APP))
1856 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1857 msg, wParam, lParam );
1858 return DefWindowProcA (hwnd, msg, wParam, lParam);
1864 HEADER_Register (void)
1868 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1869 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1870 wndClass.lpfnWndProc = HEADER_WindowProc;
1871 wndClass.cbClsExtra = 0;
1872 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1873 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1874 wndClass.lpszClassName = WC_HEADERW;
1876 RegisterClassW (&wndClass);
1881 HEADER_Unregister (void)
1883 UnregisterClassW (WC_HEADERW, NULL);