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 BOOL bRectsValid; /* validity flag for bounding rectangles */
95 #define DIVIDER_WIDTH 10
97 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongPtrW(hwnd,0))
99 static const WCHAR themeClass[] = {'H','e','a','d','e','r',0};
102 inline static LRESULT
103 HEADER_IndexToOrder (HWND hwnd, INT iItem)
105 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
106 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
107 return lpItem->iOrder;
112 HEADER_OrderToIndex(HWND hwnd, WPARAM wParam)
114 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
115 INT iorder = (INT)wParam;
118 if ((iorder <0) || iorder >infoPtr->uNumItem)
120 for (i=0; i<infoPtr->uNumItem; i++)
121 if (HEADER_IndexToOrder(hwnd,i) == iorder)
127 HEADER_SetItemBounds (HWND hwnd)
129 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
135 infoPtr->bRectsValid = TRUE;
137 if (infoPtr->uNumItem == 0)
140 GetClientRect (hwnd, &rect);
143 for (i = 0; i < infoPtr->uNumItem; i++) {
144 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
145 phdi->rect.top = rect.top;
146 phdi->rect.bottom = rect.bottom;
148 phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
149 x = phdi->rect.right;
154 HEADER_Size (HWND hwnd, WPARAM wParam)
156 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
158 infoPtr->bRectsValid = FALSE;
165 HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
167 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
168 HEADER_ITEM *phdi = &infoPtr->items[iItem];
170 INT oldBkMode, cxEdge = GetSystemMetrics(SM_CXEDGE);
171 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 if (phdi->fmt & HDF_OWNERDRAW) {
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,
226 (WPARAM)nmcd.hdr.idFrom, (LPARAM)&nmcd);
228 dis.CtlType = ODT_HEADER;
229 dis.CtlID = GetWindowLongPtrW (hwnd, GWLP_ID);
231 dis.itemAction = ODA_DRAWENTIRE;
232 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
236 dis.itemData = phdi->lParam;
237 oldBkMode = SetBkMode(hdc, TRANSPARENT);
238 SendMessageW (infoPtr->hwndNotify, WM_DRAWITEM,
239 (WPARAM)dis.CtlID, (LPARAM)&dis);
240 if (oldBkMode != TRANSPARENT)
241 SetBkMode(hdc, oldBkMode);
244 UINT rw, rh, /* width and height of r */
245 *x = NULL, *w = NULL; /* x and width of the pic (bmp or img) which is part of cnt */
246 /* cnt,txt,img,bmp */
251 cw = tw = iw = bw = 0;
252 rw = r.right - r.left;
253 rh = r.bottom - r.top;
255 if (phdi->fmt & HDF_STRING) {
258 DrawTextW (hdc, phdi->pszText, -1,
259 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
260 cw = textRect.right - textRect.left + 2 * infoPtr->iMargin;
263 if ((phdi->fmt & HDF_IMAGE) && (infoPtr->himl)) {
264 iw = infoPtr->himl->cx + 2 * infoPtr->iMargin;
269 if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
270 GetObjectW (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
271 bw = bmp.bmWidth + 2 * infoPtr->iMargin;
281 /* align cx using the unclipped cw */
282 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_LEFT)
284 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
285 cx = r.left + rw / 2 - cw / 2;
292 if (cx + cw > r.right)
295 tx = cx + infoPtr->iMargin;
296 /* since cw might have changed we have to recalculate tw */
297 tw = cw - infoPtr->iMargin * 2;
301 if (phdi->fmt & HDF_BITMAP_ON_RIGHT) {
302 /* put pic behind text */
303 *x = cx + tw + infoPtr->iMargin * 3;
305 *x = cx + infoPtr->iMargin;
306 /* move text behind pic */
312 /* since we're done with the layout we can
313 now calculate the position of bmp which
314 has no influence on alignment and layout
316 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
317 bx = cx - bw + infoPtr->iMargin;
319 bx = cx + cw + infoPtr->iMargin;
323 HDC hClipDC = GetDC(hwnd);
324 HRGN hClipRgn = CreateRectRgn(r.left, r.top, r.right, r.bottom);
325 SelectClipRgn(hClipDC, hClipRgn);
328 HDC hdcBitmap = CreateCompatibleDC (hClipDC);
329 SelectObject (hdcBitmap, phdi->hbm);
330 BitBlt (hClipDC, bx, r.top + ((INT)rh - bmp.bmHeight) / 2,
331 bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
332 DeleteDC (hdcBitmap);
336 ImageList_DrawEx (infoPtr->himl, phdi->iImage, hClipDC,
337 ix, r.top + ((INT)rh - infoPtr->himl->cy) / 2,
338 infoPtr->himl->cx, infoPtr->himl->cy, CLR_DEFAULT, CLR_DEFAULT, 0);
341 DeleteObject(hClipRgn);
342 ReleaseDC(hwnd, hClipDC);
345 if (((phdi->fmt & HDF_STRING)
346 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
347 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
348 && (phdi->pszText)) {
349 oldBkMode = SetBkMode(hdc, TRANSPARENT);
350 SetTextColor (hdc, (bHotTrack && !theme) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
353 DrawTextW (hdc, phdi->pszText, -1,
354 &r, DT_LEFT|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
355 if (oldBkMode != TRANSPARENT)
356 SetBkMode(hdc, oldBkMode);
360 return phdi->rect.right;
365 HEADER_Refresh (HWND hwnd, HDC hdc)
367 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
368 HFONT hFont, hOldFont;
373 HTHEME theme = GetWindowTheme (hwnd);
375 /* get rect for the bar, adjusted for the border */
376 GetClientRect (hwnd, &rect);
378 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
379 hOldFont = SelectObject (hdc, hFont);
381 /* draw Background */
383 hbrBk = GetSysColorBrush(COLOR_3DFACE);
384 FillRect(hdc, &rect, hbrBk);
388 for (i = 0; i < infoPtr->uNumItem; i++) {
389 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i),
390 infoPtr->iHotItem == i);
393 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
396 DrawThemeBackground (theme, hdc, HP_HEADERITEM, HIS_NORMAL, &rect,
400 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS)
401 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
403 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
407 SelectObject (hdc, hOldFont);
412 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
414 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
415 HFONT hFont, hOldFont;
417 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
418 hOldFont = SelectObject (hdc, hFont);
419 HEADER_DrawItem (hwnd, hdc, iItem, infoPtr->iHotItem == iItem);
420 SelectObject (hdc, hOldFont);
425 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
427 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
433 GetClientRect (hwnd, &rect);
437 if (PtInRect (&rect, *lpPt))
439 if (infoPtr->uNumItem == 0) {
440 *pFlags |= HHT_NOWHERE;
446 /* somewhere inside */
447 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
448 rect = infoPtr->items[iCount].rect;
449 width = rect.right - rect.left;
454 if (PtInRect (&rect, *lpPt)) {
455 if (width <= 2 * DIVIDER_WIDTH) {
456 *pFlags |= HHT_ONHEADER;
458 TRACE("ON HEADER %d\n", iCount);
463 rcTest.right = rcTest.left + DIVIDER_WIDTH;
464 if (PtInRect (&rcTest, *lpPt)) {
466 *pFlags |= HHT_ONDIVOPEN;
468 TRACE("ON DIVOPEN %d\n", *pItem);
472 *pFlags |= HHT_ONDIVIDER;
474 TRACE("ON DIVIDER %d\n", *pItem);
480 rcTest.left = rcTest.right - DIVIDER_WIDTH;
481 if (PtInRect (&rcTest, *lpPt)) {
482 *pFlags |= HHT_ONDIVIDER;
484 TRACE("ON DIVIDER %d\n", *pItem);
488 *pFlags |= HHT_ONHEADER;
490 TRACE("ON HEADER %d\n", iCount);
495 /* check for last divider part (on nowhere) */
496 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
497 rect.left = rect.right;
498 rect.right += DIVIDER_WIDTH;
499 if (PtInRect (&rect, *lpPt)) {
501 *pFlags |= HHT_ONDIVOPEN;
502 *pItem = infoPtr->uNumItem - 1;
503 TRACE("ON DIVOPEN %d\n", *pItem);
507 *pFlags |= HHT_ONDIVIDER;
508 *pItem = infoPtr->uNumItem-1;
509 TRACE("ON DIVIDER %d\n", *pItem);
514 *pFlags |= HHT_NOWHERE;
521 if (lpPt->x < rect.left) {
523 *pFlags |= HHT_TOLEFT;
525 else if (lpPt->x > rect.right) {
527 *pFlags |= HHT_TORIGHT;
530 if (lpPt->y < rect.top) {
532 *pFlags |= HHT_ABOVE;
534 else if (lpPt->y > rect.bottom) {
536 *pFlags |= HHT_BELOW;
541 TRACE("flags=0x%X\n", *pFlags);
547 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
553 GetClientRect (hwnd, &rect);
555 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
556 oldRop = SetROP2 (hdc, R2_XORPEN);
557 MoveToEx (hdc, x, rect.top, NULL);
558 LineTo (hdc, x, rect.bottom);
559 SetROP2 (hdc, oldRop);
560 SelectObject (hdc, hOldPen);
565 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
567 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
570 nmhdr.hwndFrom = hwnd;
571 nmhdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
574 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
575 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
579 HEADER_SendHeaderNotify (HWND hwnd, UINT code, INT iItem, INT mask)
581 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
585 nmhdr.hdr.hwndFrom = hwnd;
586 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
587 nmhdr.hdr.code = code;
590 nmhdr.pitem = &nmitem;
592 nmitem.cxy = infoPtr->items[iItem].cxy;
593 nmitem.hbm = infoPtr->items[iItem].hbm;
594 nmitem.pszText = NULL;
595 nmitem.cchTextMax = 0;
596 /* nmitem.pszText = infoPtr->items[iItem].pszText; */
597 /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
598 nmitem.fmt = infoPtr->items[iItem].fmt;
599 nmitem.lParam = infoPtr->items[iItem].lParam;
600 nmitem.iOrder = infoPtr->items[iItem].iOrder;
601 nmitem.iImage = infoPtr->items[iItem].iImage;
603 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
604 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
609 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
611 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
614 nmhdr.hdr.hwndFrom = hwnd;
615 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
616 nmhdr.hdr.code = code;
621 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
622 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
627 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
629 FIXME("empty stub!\n");
635 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
637 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
638 INT iItem = (INT)wParam;
640 TRACE("[iItem=%d]\n", iItem);
642 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
645 if (infoPtr->uNumItem == 1) {
646 TRACE("Simple delete!\n");
647 if (infoPtr->items[0].pszText)
648 Free (infoPtr->items[0].pszText);
649 Free (infoPtr->items);
651 infoPtr->uNumItem = 0;
654 HEADER_ITEM *oldItems = infoPtr->items;
658 TRACE("Complex delete! [iItem=%d]\n", iItem);
660 if (infoPtr->items[iItem].pszText)
661 Free (infoPtr->items[iItem].pszText);
662 iOrder = infoPtr->items[iItem].iOrder;
665 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
666 /* pre delete copy */
668 memcpy (&infoPtr->items[0], &oldItems[0],
669 iItem * sizeof(HEADER_ITEM));
672 /* post delete copy */
673 if (iItem < infoPtr->uNumItem) {
674 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
675 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
678 /* Correct the orders */
679 for (i=infoPtr->uNumItem, pItem = infoPtr->items; i; i--, pItem++)
681 if (pItem->iOrder > iOrder)
687 HEADER_SetItemBounds (hwnd);
689 InvalidateRect(hwnd, NULL, FALSE);
696 HEADER_GetImageList (HWND hwnd)
698 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
700 return (LRESULT)infoPtr->himl;
705 HEADER_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
707 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
708 HDITEMA *phdi = (HDITEMA*)lParam;
709 INT nItem = (INT)wParam;
715 TRACE("[nItem=%d]\n", nItem);
720 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem)) {
724 lpItem = &infoPtr->items[nItem];
727 if (phdi->mask & HDI_BITMAP)
728 phdi->hbm = (lpItem != NULL) ? lpItem->hbm : 0;
730 if (phdi->mask & HDI_FORMAT)
731 phdi->fmt = (lpItem != NULL) ? lpItem->fmt : 0;
733 if (phdi->mask & HDI_WIDTH)
734 phdi->cxy = (lpItem != NULL) ? lpItem->cxy : 0;
736 if (phdi->mask & HDI_LPARAM)
737 phdi->lParam = (lpItem != NULL) ? lpItem->lParam : 0;
739 if (phdi->mask & HDI_TEXT) {
740 if (lpItem == NULL) {
743 else if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
745 WideCharToMultiByte (CP_ACP, 0, lpItem->pszText, -1,
746 phdi->pszText, phdi->cchTextMax, NULL, NULL);
751 phdi->pszText = LPSTR_TEXTCALLBACKA;
754 if (phdi->mask & HDI_IMAGE)
755 phdi->iImage = (lpItem != NULL) ? lpItem->iImage : 0;
757 if (phdi->mask & HDI_ORDER)
758 phdi->iOrder = (lpItem != NULL) ? lpItem->iOrder : 0;
765 HEADER_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
767 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
768 HDITEMW *phdi = (HDITEMW*)lParam;
769 INT nItem = (INT)wParam;
775 TRACE("[nItem=%d]\n", nItem);
780 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem)) {
784 lpItem = &infoPtr->items[nItem];
787 if (phdi->mask & HDI_BITMAP)
788 phdi->hbm = (lpItem != NULL) ? lpItem->hbm : 0;
790 if (phdi->mask & HDI_FORMAT)
791 phdi->fmt = (lpItem != NULL) ? lpItem->fmt : 0;
793 if (phdi->mask & HDI_WIDTH)
794 phdi->cxy = (lpItem != NULL) ? lpItem->cxy : 0;
796 if (phdi->mask & HDI_LPARAM)
797 phdi->lParam = (lpItem != NULL) ? lpItem->lParam : 0;
799 if (phdi->mask & HDI_TEXT) {
800 if (lpItem == NULL) {
803 else if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
805 lstrcpynW (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
810 phdi->pszText = LPSTR_TEXTCALLBACKW;
813 if (phdi->mask & HDI_IMAGE)
814 phdi->iImage = (lpItem != NULL) ? lpItem->iImage : 0;
816 if (phdi->mask & HDI_ORDER)
817 phdi->iOrder = (lpItem != NULL) ? lpItem->iOrder : 0;
823 inline static LRESULT
824 HEADER_GetItemCount (HWND hwnd)
826 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
827 return infoPtr->uNumItem;
832 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
834 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
835 INT iItem = (INT)wParam;
836 LPRECT lpRect = (LPRECT)lParam;
838 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
841 lpRect->left = infoPtr->items[iItem].rect.left;
842 lpRect->right = infoPtr->items[iItem].rect.right;
843 lpRect->top = infoPtr->items[iItem].rect.top;
844 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
851 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
854 LPINT order = (LPINT) lParam;
855 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
857 if ((unsigned int)wParam <infoPtr->uNumItem)
859 for (i=0; i<(int)wParam; i++)
860 *order++=HEADER_OrderToIndex(hwnd,i);
865 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
868 LPINT order = (LPINT) lParam;
869 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
872 if ((unsigned int)wParam <infoPtr->uNumItem)
874 for (i=0; i<(int)wParam; i++)
876 lpItem = &infoPtr->items[*order++];
879 infoPtr->bRectsValid=0;
880 InvalidateRect(hwnd, NULL, FALSE);
884 inline static LRESULT
885 HEADER_GetUnicodeFormat (HWND hwnd)
887 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
888 return infoPtr->bUnicode;
893 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
895 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
897 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
899 if (phti->flags == HHT_NOWHERE)
907 HEADER_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
909 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
910 HDITEMA *phdi = (HDITEMA*)lParam;
911 INT nItem = (INT)wParam;
916 if ((phdi == NULL) || (nItem < 0))
919 if (nItem > infoPtr->uNumItem)
920 nItem = infoPtr->uNumItem;
922 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
924 if (infoPtr->uNumItem == 0) {
925 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
929 HEADER_ITEM *oldItems = infoPtr->items;
932 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
934 memcpy (&infoPtr->items[1], &oldItems[0],
935 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
939 /* pre insert copy */
941 memcpy (&infoPtr->items[0], &oldItems[0],
942 nItem * sizeof(HEADER_ITEM));
945 /* post insert copy */
946 if (nItem < infoPtr->uNumItem - 1) {
947 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
948 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
955 for (i=0; i < infoPtr->uNumItem; i++)
957 if (infoPtr->items[i].iOrder >= iOrder)
958 infoPtr->items[i].iOrder++;
961 lpItem = &infoPtr->items[nItem];
962 lpItem->bDown = FALSE;
964 if (phdi->mask & HDI_WIDTH)
965 lpItem->cxy = phdi->cxy;
967 if (phdi->mask & HDI_TEXT) {
968 if (!phdi->pszText) /* null pointer check */
970 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
971 len = MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, NULL, 0);
972 lpItem->pszText = Alloc( len*sizeof(WCHAR) );
973 MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, lpItem->pszText, len);
976 lpItem->pszText = LPSTR_TEXTCALLBACKW;
979 if (phdi->mask & HDI_FORMAT)
980 lpItem->fmt = phdi->fmt;
982 if (lpItem->fmt == 0)
983 lpItem->fmt = HDF_LEFT;
985 if (!(lpItem->fmt & HDF_STRING) && (phdi->mask & HDI_TEXT))
987 lpItem->fmt |= HDF_STRING;
989 if (phdi->mask & HDI_BITMAP)
990 lpItem->hbm = phdi->hbm;
992 if (phdi->mask & HDI_LPARAM)
993 lpItem->lParam = phdi->lParam;
995 if (phdi->mask & HDI_IMAGE)
996 lpItem->iImage = phdi->iImage;
998 lpItem->iOrder = iOrder;
1000 HEADER_SetItemBounds (hwnd);
1002 InvalidateRect(hwnd, NULL, FALSE);
1009 HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1011 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1012 HDITEMW *phdi = (HDITEMW*)lParam;
1013 INT nItem = (INT)wParam;
1014 HEADER_ITEM *lpItem;
1018 if ((phdi == NULL) || (nItem < 0))
1021 if (nItem > infoPtr->uNumItem)
1022 nItem = infoPtr->uNumItem;
1024 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
1026 if (infoPtr->uNumItem == 0) {
1027 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
1028 infoPtr->uNumItem++;
1031 HEADER_ITEM *oldItems = infoPtr->items;
1033 infoPtr->uNumItem++;
1034 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
1036 memcpy (&infoPtr->items[1], &oldItems[0],
1037 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
1041 /* pre insert copy */
1043 memcpy (&infoPtr->items[0], &oldItems[0],
1044 nItem * sizeof(HEADER_ITEM));
1047 /* post insert copy */
1048 if (nItem < infoPtr->uNumItem - 1) {
1049 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
1050 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
1057 for (i=0; i < infoPtr->uNumItem; i++)
1059 if (infoPtr->items[i].iOrder >= iOrder)
1060 infoPtr->items[i].iOrder++;
1063 lpItem = &infoPtr->items[nItem];
1064 lpItem->bDown = FALSE;
1066 if (phdi->mask & HDI_WIDTH)
1067 lpItem->cxy = phdi->cxy;
1069 if (phdi->mask & HDI_TEXT) {
1070 WCHAR wide_null_char = 0;
1071 if (!phdi->pszText) /* null pointer check */
1072 phdi->pszText = &wide_null_char;
1073 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1074 len = strlenW (phdi->pszText);
1075 lpItem->pszText = Alloc ((len+1)*sizeof(WCHAR));
1076 strcpyW (lpItem->pszText, phdi->pszText);
1079 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1082 if (phdi->mask & HDI_FORMAT)
1083 lpItem->fmt = phdi->fmt;
1085 if (lpItem->fmt == 0)
1086 lpItem->fmt = HDF_LEFT;
1088 if (!(lpItem->fmt &HDF_STRING) && (phdi->mask & HDI_TEXT))
1090 lpItem->fmt |= HDF_STRING;
1092 if (phdi->mask & HDI_BITMAP)
1093 lpItem->hbm = phdi->hbm;
1095 if (phdi->mask & HDI_LPARAM)
1096 lpItem->lParam = phdi->lParam;
1098 if (phdi->mask & HDI_IMAGE)
1099 lpItem->iImage = phdi->iImage;
1101 lpItem->iOrder = iOrder;
1103 HEADER_SetItemBounds (hwnd);
1105 InvalidateRect(hwnd, NULL, FALSE);
1112 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
1114 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1115 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1117 lpLayout->pwpos->hwnd = hwnd;
1118 lpLayout->pwpos->hwndInsertAfter = 0;
1119 lpLayout->pwpos->x = lpLayout->prc->left;
1120 lpLayout->pwpos->y = lpLayout->prc->top;
1121 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1122 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_HIDDEN)
1123 lpLayout->pwpos->cy = 0;
1125 lpLayout->pwpos->cy = infoPtr->nHeight;
1126 lpLayout->prc->top += infoPtr->nHeight;
1128 lpLayout->pwpos->flags = SWP_NOZORDER;
1130 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1131 lpLayout->pwpos->x, lpLayout->pwpos->y,
1132 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1134 infoPtr->bRectsValid = FALSE;
1141 HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
1143 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1146 TRACE("(himl 0x%x)\n", (int)himl);
1147 himlOld = infoPtr->himl;
1148 infoPtr->himl = himl;
1150 /* FIXME: Refresh needed??? */
1152 return (LRESULT)himlOld;
1157 HEADER_GetBitmapMargin(HWND hwnd)
1159 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
1161 return infoPtr->iMargin;
1165 HEADER_SetBitmapMargin(HWND hwnd, WPARAM wParam)
1167 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1168 INT oldMargin = infoPtr->iMargin;
1170 infoPtr->iMargin = (INT)wParam;
1176 HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1178 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1179 HDITEMA *phdi = (HDITEMA*)lParam;
1180 INT nItem = (INT)wParam;
1181 HEADER_ITEM *lpItem;
1185 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1188 TRACE("[nItem=%d]\n", nItem);
1190 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem, phdi->mask))
1193 lpItem = &infoPtr->items[nItem];
1194 if (phdi->mask & HDI_BITMAP)
1195 lpItem->hbm = phdi->hbm;
1197 if (phdi->mask & HDI_FORMAT)
1198 lpItem->fmt = phdi->fmt;
1200 if (phdi->mask & HDI_LPARAM)
1201 lpItem->lParam = phdi->lParam;
1203 if (phdi->mask & HDI_TEXT) {
1204 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
1205 if (lpItem->pszText) {
1206 Free (lpItem->pszText);
1207 lpItem->pszText = NULL;
1209 if (phdi->pszText) {
1210 INT len = MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,NULL,0);
1211 lpItem->pszText = Alloc( len*sizeof(WCHAR) );
1212 MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,lpItem->pszText,len);
1216 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1219 if (phdi->mask & HDI_WIDTH)
1220 lpItem->cxy = phdi->cxy;
1222 if (phdi->mask & HDI_IMAGE)
1223 lpItem->iImage = phdi->iImage;
1225 if (phdi->mask & HDI_ORDER)
1227 lpItem->iOrder = phdi->iOrder;
1230 HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem, phdi->mask);
1232 HEADER_SetItemBounds (hwnd);
1234 InvalidateRect(hwnd, NULL, FALSE);
1241 HEADER_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1243 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1244 HDITEMW *phdi = (HDITEMW*)lParam;
1245 INT nItem = (INT)wParam;
1246 HEADER_ITEM *lpItem;
1250 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1253 TRACE("[nItem=%d]\n", nItem);
1255 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask))
1258 lpItem = &infoPtr->items[nItem];
1259 if (phdi->mask & HDI_BITMAP)
1260 lpItem->hbm = phdi->hbm;
1262 if (phdi->mask & HDI_FORMAT)
1263 lpItem->fmt = phdi->fmt;
1265 if (phdi->mask & HDI_LPARAM)
1266 lpItem->lParam = phdi->lParam;
1268 if (phdi->mask & HDI_TEXT) {
1269 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1270 if (lpItem->pszText) {
1271 Free (lpItem->pszText);
1272 lpItem->pszText = NULL;
1274 if (phdi->pszText) {
1275 INT len = strlenW (phdi->pszText);
1276 lpItem->pszText = Alloc ((len+1)*sizeof(WCHAR));
1277 strcpyW (lpItem->pszText, phdi->pszText);
1281 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1284 if (phdi->mask & HDI_WIDTH)
1285 lpItem->cxy = phdi->cxy;
1287 if (phdi->mask & HDI_IMAGE)
1288 lpItem->iImage = phdi->iImage;
1290 if (phdi->mask & HDI_ORDER)
1292 lpItem->iOrder = phdi->iOrder;
1295 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDW, nItem, phdi->mask);
1297 HEADER_SetItemBounds (hwnd);
1299 InvalidateRect(hwnd, NULL, FALSE);
1304 inline static LRESULT
1305 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1307 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1308 BOOL bTemp = infoPtr->bUnicode;
1310 infoPtr->bUnicode = (BOOL)wParam;
1317 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1319 HEADER_INFO *infoPtr;
1324 infoPtr = (HEADER_INFO *)Alloc (sizeof(HEADER_INFO));
1325 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1327 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
1328 infoPtr->uNumItem = 0;
1331 infoPtr->bRectsValid = FALSE;
1332 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1333 infoPtr->hcurDivider = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDER));
1334 infoPtr->hcurDivopen = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDEROPEN));
1335 infoPtr->bPressed = FALSE;
1336 infoPtr->bTracking = FALSE;
1337 infoPtr->iMoveItem = 0;
1339 infoPtr->iHotItem = -1;
1340 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1341 infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
1342 infoPtr->nNotifyFormat =
1343 SendMessageW (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1346 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1347 GetTextMetricsW (hdc, &tm);
1348 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1349 SelectObject (hdc, hOldFont);
1352 OpenThemeData(hwnd, themeClass);
1359 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1361 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1362 HEADER_ITEM *lpItem;
1366 if (infoPtr->items) {
1367 lpItem = infoPtr->items;
1368 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1369 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
1370 Free (lpItem->pszText);
1372 Free (infoPtr->items);
1376 ImageList_Destroy (infoPtr->himl);
1378 SetWindowLongPtrW (hwnd, 0, 0);
1381 theme = GetWindowTheme(hwnd);
1382 CloseThemeData(theme);
1387 static inline LRESULT
1388 HEADER_GetFont (HWND hwnd)
1390 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1392 return (LRESULT)infoPtr->hFont;
1397 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1403 pt.x = (INT)LOWORD(lParam);
1404 pt.y = (INT)HIWORD(lParam);
1405 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1407 if ((GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1408 HEADER_SendHeaderNotify (hwnd, HDN_ITEMDBLCLICKA, nItem,0);
1409 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1410 HEADER_SendHeaderNotify (hwnd, HDN_DIVIDERDBLCLICKA, nItem,0);
1417 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1419 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1420 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1426 pt.x = (INT)LOWORD(lParam);
1427 pt.y = (INT)HIWORD(lParam);
1428 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1430 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1432 infoPtr->bCaptured = TRUE;
1433 infoPtr->bPressed = TRUE;
1434 infoPtr->iMoveItem = nItem;
1436 infoPtr->items[nItem].bDown = TRUE;
1438 /* Send WM_CUSTOMDRAW */
1440 HEADER_RefreshItem (hwnd, hdc, nItem);
1441 ReleaseDC (hwnd, hdc);
1443 TRACE("Pressed item %d!\n", nItem);
1445 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1446 if (!(HEADER_SendHeaderNotify (hwnd, HDN_BEGINTRACKA, nItem,0))) {
1448 infoPtr->bCaptured = TRUE;
1449 infoPtr->bTracking = TRUE;
1450 infoPtr->iMoveItem = nItem;
1451 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1452 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1454 if (!(dwStyle & HDS_FULLDRAG)) {
1455 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1457 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1458 ReleaseDC (hwnd, hdc);
1461 TRACE("Begin tracking item %d!\n", nItem);
1470 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1472 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1474 *DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1481 pt.x = (INT)(SHORT)LOWORD(lParam);
1482 pt.y = (INT)(SHORT)HIWORD(lParam);
1483 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1485 if (infoPtr->bPressed) {
1486 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1487 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1489 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1490 ReleaseDC (hwnd, hdc);
1492 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1494 else if (flags == HHT_ONHEADER)
1496 HEADER_ITEM *lpItem;
1497 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1498 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1500 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1501 infoPtr->iMoveItem,oldindex,nItem,newindex);
1502 lpItem= &infoPtr->items[nItem];
1503 lpItem->iOrder=oldindex;
1505 lpItem= &infoPtr->items[infoPtr->iMoveItem];
1506 lpItem->iOrder = newindex;
1508 infoPtr->bRectsValid = FALSE;
1509 InvalidateRect(hwnd, NULL, FALSE);
1510 /* FIXME: Should some WM_NOTIFY be sent */
1513 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1514 infoPtr->bPressed = FALSE;
1516 else if (infoPtr->bTracking) {
1517 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1518 infoPtr->bTracking = FALSE;
1520 HEADER_SendHeaderNotify (hwnd, HDN_ENDTRACKA, infoPtr->iMoveItem,HDI_WIDTH);
1523 * we want to do this even for HDS_FULLDRAG because this is where
1524 * we send the HDN_ITEMCHANGING and HDN_ITEMCHANGED notifications
1526 * if (!(dwStyle & HDS_FULLDRAG)) {
1530 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1531 ReleaseDC (hwnd, hdc);
1532 if (HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1534 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1537 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1540 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1543 HEADER_SetItemBounds (hwnd);
1544 InvalidateRect(hwnd, NULL, TRUE);
1545 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1551 if (infoPtr->bCaptured) {
1552 infoPtr->bCaptured = FALSE;
1554 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1562 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1564 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1569 return infoPtr->nNotifyFormat;
1572 infoPtr->nNotifyFormat =
1573 SendMessageW ((HWND)wParam, WM_NOTIFYFORMAT,
1574 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1575 return infoPtr->nNotifyFormat;
1583 HEADER_MouseLeave (HWND hwnd, WPARAM wParam, LPARAM lParam)
1585 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1586 /* Reset hot-tracked item when mouse leaves control. */
1587 INT oldHotItem = infoPtr->iHotItem;
1588 HDC hdc = GetDC (hwnd);
1590 infoPtr->iHotItem = -1;
1591 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem);
1592 ReleaseDC (hwnd, hdc);
1599 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1601 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1602 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1607 /* With theming, hottracking is always enabled */
1608 BOOL hotTrackEnabled =
1609 ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK))
1610 || (GetWindowTheme (hwnd) != NULL);
1611 INT oldHotItem = infoPtr->iHotItem;
1613 pt.x = (INT)(SHORT)LOWORD(lParam);
1614 pt.y = (INT)(SHORT)HIWORD(lParam);
1615 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1617 if (hotTrackEnabled) {
1618 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1619 infoPtr->iHotItem = nItem;
1621 infoPtr->iHotItem = -1;
1624 if (infoPtr->bCaptured) {
1625 if (infoPtr->bPressed) {
1626 BOOL oldState = infoPtr->items[infoPtr->iMoveItem].bDown;
1627 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1628 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1630 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1631 if (oldState != infoPtr->items[infoPtr->iMoveItem].bDown) {
1633 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1634 ReleaseDC (hwnd, hdc);
1637 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1639 else if (infoPtr->bTracking) {
1640 if (dwStyle & HDS_FULLDRAG) {
1641 if (HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH))
1643 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1646 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1647 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1649 HEADER_SetItemBounds (hwnd);
1653 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1654 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1655 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1656 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1657 infoPtr->items[infoPtr->iMoveItem].cxy =
1658 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1659 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1660 ReleaseDC (hwnd, hdc);
1661 HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH);
1664 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1668 if (hotTrackEnabled) {
1669 TRACKMOUSEEVENT tme;
1670 if (oldHotItem != infoPtr->iHotItem) {
1672 if (oldHotItem != -1) HEADER_RefreshItem (hwnd, hdc, oldHotItem);
1673 if (infoPtr->iHotItem != -1) HEADER_RefreshItem (hwnd, hdc, infoPtr->iHotItem);
1674 ReleaseDC (hwnd, hdc);
1676 tme.cbSize = sizeof( tme );
1677 tme.dwFlags = TME_LEAVE;
1678 tme.hwndTrack = hwnd;
1679 TrackMouseEvent( &tme );
1687 HEADER_Paint (HWND hwnd, WPARAM wParam)
1692 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1693 HEADER_Refresh (hwnd, hdc);
1695 EndPaint (hwnd, &ps);
1701 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1706 pt.x = LOWORD(lParam);
1707 pt.y = HIWORD(lParam);
1709 /* Send a Notify message */
1710 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1712 /* Change to screen coordinate for WM_CONTEXTMENU */
1713 ClientToScreen(hwnd, &pt);
1715 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1716 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1723 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1725 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1730 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1733 ScreenToClient (hwnd, &pt);
1735 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1737 if (flags == HHT_ONDIVIDER)
1738 SetCursor (infoPtr->hcurDivider);
1739 else if (flags == HHT_ONDIVOPEN)
1740 SetCursor (infoPtr->hcurDivopen);
1742 SetCursor (infoPtr->hcurArrow);
1749 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1751 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1753 HFONT hFont, hOldFont;
1756 infoPtr->hFont = (HFONT)wParam;
1758 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1761 hOldFont = SelectObject (hdc, hFont);
1762 GetTextMetricsW (hdc, &tm);
1763 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1764 SelectObject (hdc, hOldFont);
1767 infoPtr->bRectsValid = FALSE;
1770 InvalidateRect(hwnd, NULL, FALSE);
1776 /* Update the theme handle after a theme change */
1777 static LRESULT HEADER_ThemeChanged(HWND hwnd)
1779 HTHEME theme = GetWindowTheme(hwnd);
1780 CloseThemeData(theme);
1781 OpenThemeData(hwnd, themeClass);
1782 InvalidateRect(hwnd, NULL, FALSE);
1787 static LRESULT WINAPI
1788 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1790 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1791 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1792 return DefWindowProcW (hwnd, msg, wParam, lParam);
1794 /* case HDM_CLEARFILTER: */
1796 case HDM_CREATEDRAGIMAGE:
1797 return HEADER_CreateDragImage (hwnd, wParam);
1799 case HDM_DELETEITEM:
1800 return HEADER_DeleteItem (hwnd, wParam);
1802 /* case HDM_EDITFILTER: */
1804 case HDM_GETBITMAPMARGIN:
1805 return HEADER_GetBitmapMargin(hwnd);
1807 case HDM_GETIMAGELIST:
1808 return HEADER_GetImageList (hwnd);
1811 return HEADER_GetItemA (hwnd, wParam, lParam);
1814 return HEADER_GetItemW (hwnd, wParam, lParam);
1816 case HDM_GETITEMCOUNT:
1817 return HEADER_GetItemCount (hwnd);
1819 case HDM_GETITEMRECT:
1820 return HEADER_GetItemRect (hwnd, wParam, lParam);
1822 case HDM_GETORDERARRAY:
1823 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1825 case HDM_GETUNICODEFORMAT:
1826 return HEADER_GetUnicodeFormat (hwnd);
1829 return HEADER_HitTest (hwnd, wParam, lParam);
1831 case HDM_INSERTITEMA:
1832 return HEADER_InsertItemA (hwnd, wParam, lParam);
1834 case HDM_INSERTITEMW:
1835 return HEADER_InsertItemW (hwnd, wParam, lParam);
1838 return HEADER_Layout (hwnd, wParam, lParam);
1840 case HDM_ORDERTOINDEX:
1841 return HEADER_OrderToIndex(hwnd, wParam);
1843 case HDM_SETBITMAPMARGIN:
1844 return HEADER_SetBitmapMargin(hwnd, wParam);
1846 /* case HDM_SETFILTERCHANGETIMEOUT: */
1848 /* case HDM_SETHOTDIVIDER: */
1850 case HDM_SETIMAGELIST:
1851 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
1854 return HEADER_SetItemA (hwnd, wParam, lParam);
1857 return HEADER_SetItemW (hwnd, wParam, lParam);
1859 case HDM_SETORDERARRAY:
1860 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1862 case HDM_SETUNICODEFORMAT:
1863 return HEADER_SetUnicodeFormat (hwnd, wParam);
1866 return HEADER_Create (hwnd, wParam, lParam);
1869 return HEADER_Destroy (hwnd, wParam, lParam);
1875 return DLGC_WANTTAB | DLGC_WANTARROWS;
1878 return HEADER_GetFont (hwnd);
1880 case WM_LBUTTONDBLCLK:
1881 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1883 case WM_LBUTTONDOWN:
1884 return HEADER_LButtonDown (hwnd, wParam, lParam);
1887 return HEADER_LButtonUp (hwnd, wParam, lParam);
1890 return HEADER_MouseLeave (hwnd, wParam, lParam);
1893 return HEADER_MouseMove (hwnd, wParam, lParam);
1895 case WM_NOTIFYFORMAT:
1896 return HEADER_NotifyFormat (hwnd, wParam, lParam);
1899 return HEADER_Size (hwnd, wParam);
1901 case WM_THEMECHANGED:
1902 return HEADER_ThemeChanged (hwnd);
1905 return HEADER_Paint (hwnd, wParam);
1908 return HEADER_RButtonUp (hwnd, wParam, lParam);
1911 return HEADER_SetCursor (hwnd, wParam, lParam);
1914 return HEADER_SetFont (hwnd, wParam, lParam);
1917 if ((msg >= WM_USER) && (msg < WM_APP))
1918 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1919 msg, wParam, lParam );
1920 return DefWindowProcA (hwnd, msg, wParam, lParam);
1926 HEADER_Register (void)
1930 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1931 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1932 wndClass.lpfnWndProc = HEADER_WindowProc;
1933 wndClass.cbClsExtra = 0;
1934 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1935 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1936 wndClass.lpszClassName = WC_HEADERW;
1938 RegisterClassW (&wndClass);
1943 HEADER_Unregister (void)
1945 UnregisterClassW (WC_HEADERW, NULL);