4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2003 Maxime Bellenge
7 * Copyright 2006 Mikolaj Zalewski
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * - Imagelist support (completed?)
25 * - Hottrack support (completed?)
26 * - Filters support (HDS_FILTER, HDI_FILTER, HDM_*FILTER*, HDN_*FILTER*)
27 * - New Windows Vista features
32 WINE_DEFAULT_DEBUG_CHANNEL(header
);
42 INT iOrder
; /* see documentation of HD_ITEM */
44 BOOL bDown
; /* is item pressed? (used for drawing) */
45 RECT rect
; /* bounding rectangle of the item */
46 DWORD callbackMask
; /* HDI_* flags for items that are callback */
52 HWND hwndSelf
; /* Control window */
53 HWND hwndNotify
; /* Owner window to send notifications to */
54 INT nNotifyFormat
; /* format used for WM_NOTIFY messages */
55 UINT uNumItem
; /* number of items (columns) */
56 INT nHeight
; /* height of the header (pixels) */
57 HFONT hFont
; /* handle to the current font */
58 HCURSOR hcurArrow
; /* handle to the arrow cursor */
59 HCURSOR hcurDivider
; /* handle to a cursor (used over dividers) <-|-> */
60 HCURSOR hcurDivopen
; /* handle to a cursor (used over dividers) <-||-> */
61 BOOL bCaptured
; /* Is the mouse captured? */
62 BOOL bPressed
; /* Is a header item pressed (down)? */
63 BOOL bDragging
; /* Are we dragging an item? */
64 BOOL bTracking
; /* Is in tracking mode? */
65 POINT ptLButtonDown
; /* The point where the left button was pressed */
66 DWORD dwStyle
; /* the cached window GWL_STYLE */
67 INT iMoveItem
; /* index of tracked item. (Tracking mode) */
68 INT xTrackOffset
; /* distance between the right side of the tracked item and the cursor */
69 INT xOldTrack
; /* track offset (see above) after the last WM_MOUSEMOVE */
70 INT iHotItem
; /* index of hot item (cursor is over this item) */
71 INT iHotDivider
; /* index of the hot divider (used while dragging an item or by HDM_SETHOTDIVIDER) */
72 INT iMargin
; /* width of the margin that surrounds a bitmap */
74 HIMAGELIST himl
; /* handle to an image list (may be 0) */
75 HEADER_ITEM
*items
; /* pointer to array of HEADER_ITEM's */
76 INT
*order
; /* array of item IDs indexed by order */
77 BOOL bRectsValid
; /* validity flag for bounding rectangles */
82 #define DIVIDER_WIDTH 10
83 #define HOT_DIVIDER_WIDTH 2
84 #define MAX_HEADER_TEXT_LEN 260
85 #define HDN_UNICODE_OFFSET 20
86 #define HDN_FIRST_UNICODE (HDN_FIRST-HDN_UNICODE_OFFSET)
88 #define HDI_SUPPORTED_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP|HDI_IMAGE|HDI_ORDER)
89 #define HDI_UNSUPPORTED_FIELDS (HDI_FILTER)
90 #define HDI_UNKNOWN_FIELDS (~(HDI_SUPPORTED_FIELDS|HDI_UNSUPPORTED_FIELDS|HDI_DI_SETITEM))
91 #define HDI_COMCTL32_4_0_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP)
94 static BOOL
HEADER_PrepareCallbackItems(const HEADER_INFO
*infoPtr
, INT iItem
, INT reqMask
);
95 static void HEADER_FreeCallbackItems(HEADER_ITEM
*lpItem
);
96 static LRESULT
HEADER_SendNotify(const HEADER_INFO
*infoPtr
, UINT code
, NMHDR
*hdr
);
97 static LRESULT
HEADER_SendCtrlCustomDraw(const HEADER_INFO
*infoPtr
, DWORD dwDrawStage
, HDC hdc
, const RECT
*rect
);
99 static const WCHAR themeClass
[] = {'H','e','a','d','e','r',0};
101 static void HEADER_StoreHDItemInHeader(HEADER_ITEM
*lpItem
, UINT mask
, const HDITEMW
*phdi
, BOOL fUnicode
)
103 if (mask
& HDI_UNSUPPORTED_FIELDS
)
104 FIXME("unsupported header fields %x\n", (mask
& HDI_UNSUPPORTED_FIELDS
));
106 if (mask
& HDI_BITMAP
)
107 lpItem
->hbm
= phdi
->hbm
;
109 if (mask
& HDI_FORMAT
)
110 lpItem
->fmt
= phdi
->fmt
;
112 if (mask
& HDI_LPARAM
)
113 lpItem
->lParam
= phdi
->lParam
;
115 if (mask
& HDI_WIDTH
)
116 lpItem
->cxy
= phdi
->cxy
;
118 if (mask
& HDI_IMAGE
)
120 lpItem
->iImage
= phdi
->iImage
;
121 if (phdi
->iImage
== I_IMAGECALLBACK
)
122 lpItem
->callbackMask
|= HDI_IMAGE
;
124 lpItem
->callbackMask
&= ~HDI_IMAGE
;
129 Free(lpItem
->pszText
);
130 lpItem
->pszText
= NULL
;
132 if (phdi
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers != TEXTCALLBACKA too */
134 static const WCHAR emptyString
[] = {0};
136 LPCWSTR pszText
= (phdi
->pszText
!= NULL
? phdi
->pszText
: emptyString
);
138 Str_SetPtrW(&lpItem
->pszText
, pszText
);
140 Str_SetPtrAtoW(&lpItem
->pszText
, (LPCSTR
)pszText
);
141 lpItem
->callbackMask
&= ~HDI_TEXT
;
145 lpItem
->pszText
= NULL
;
146 lpItem
->callbackMask
|= HDI_TEXT
;
151 static inline LRESULT
152 HEADER_IndexToOrder (const HEADER_INFO
*infoPtr
, INT iItem
)
154 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
155 return lpItem
->iOrder
;
160 HEADER_OrderToIndex(const HEADER_INFO
*infoPtr
, INT iorder
)
162 if ((iorder
<0) || iorder
>= infoPtr
->uNumItem
)
164 return infoPtr
->order
[iorder
];
168 HEADER_ChangeItemOrder(const HEADER_INFO
*infoPtr
, INT iItem
, INT iNewOrder
)
170 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
173 TRACE("%d: %d->%d\n", iItem
, lpItem
->iOrder
, iNewOrder
);
174 if (lpItem
->iOrder
< iNewOrder
)
176 memmove(&infoPtr
->order
[lpItem
->iOrder
],
177 &infoPtr
->order
[lpItem
->iOrder
+ 1],
178 (iNewOrder
- lpItem
->iOrder
) * sizeof(INT
));
180 if (iNewOrder
< lpItem
->iOrder
)
182 memmove(&infoPtr
->order
[iNewOrder
+ 1],
183 &infoPtr
->order
[iNewOrder
],
184 (lpItem
->iOrder
- iNewOrder
) * sizeof(INT
));
186 infoPtr
->order
[iNewOrder
] = iItem
;
187 nMin
= min(lpItem
->iOrder
, iNewOrder
);
188 nMax
= max(lpItem
->iOrder
, iNewOrder
);
189 for (i
= nMin
; i
<= nMax
; i
++)
190 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
193 /* Note: if iItem is the last item then this function returns infoPtr->uNumItem */
195 HEADER_NextItem(const HEADER_INFO
*infoPtr
, INT iItem
)
197 return HEADER_OrderToIndex(infoPtr
, HEADER_IndexToOrder(infoPtr
, iItem
)+1);
201 HEADER_PrevItem(const HEADER_INFO
*infoPtr
, INT iItem
)
203 return HEADER_OrderToIndex(infoPtr
, HEADER_IndexToOrder(infoPtr
, iItem
)-1);
206 /* TRUE when item is not resizable with dividers,
207 note that valid index should be supplied */
209 HEADER_IsItemFixed(const HEADER_INFO
*infoPtr
, INT iItem
)
211 return (infoPtr
->dwStyle
& HDS_NOSIZING
) || (infoPtr
->items
[iItem
].fmt
& HDF_FIXEDWIDTH
);
215 HEADER_SetItemBounds (HEADER_INFO
*infoPtr
)
222 infoPtr
->bRectsValid
= TRUE
;
224 if (infoPtr
->uNumItem
== 0)
227 GetClientRect (infoPtr
->hwndSelf
, &rect
);
230 for (i
= 0; i
< infoPtr
->uNumItem
; i
++) {
231 phdi
= &infoPtr
->items
[HEADER_OrderToIndex(infoPtr
,i
)];
232 phdi
->rect
.top
= rect
.top
;
233 phdi
->rect
.bottom
= rect
.bottom
;
235 phdi
->rect
.right
= phdi
->rect
.left
+ ((phdi
->cxy
>0)?phdi
->cxy
:0);
236 x
= phdi
->rect
.right
;
241 HEADER_Size (HEADER_INFO
*infoPtr
)
243 HEADER_SetItemBounds(infoPtr
);
247 static void HEADER_GetHotDividerRect(const HEADER_INFO
*infoPtr
, RECT
*r
)
249 INT iDivider
= infoPtr
->iHotDivider
;
250 if (infoPtr
->uNumItem
> 0)
254 if (iDivider
< infoPtr
->uNumItem
)
256 lpItem
= &infoPtr
->items
[iDivider
];
257 r
->left
= lpItem
->rect
.left
- HOT_DIVIDER_WIDTH
/2;
258 r
->right
= lpItem
->rect
.left
+ HOT_DIVIDER_WIDTH
/2;
262 lpItem
= &infoPtr
->items
[HEADER_OrderToIndex(infoPtr
, infoPtr
->uNumItem
-1)];
263 r
->left
= lpItem
->rect
.right
- HOT_DIVIDER_WIDTH
/2;
264 r
->right
= lpItem
->rect
.right
+ HOT_DIVIDER_WIDTH
/2;
266 r
->top
= lpItem
->rect
.top
;
267 r
->bottom
= lpItem
->rect
.bottom
;
272 GetClientRect(infoPtr
->hwndSelf
, &clientRect
);
274 r
->right
= r
->left
+ HOT_DIVIDER_WIDTH
/2;
279 HEADER_FillItemFrame(HEADER_INFO
*infoPtr
, HDC hdc
, RECT
*r
, const HEADER_ITEM
*item
, BOOL hottrack
)
281 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
284 int state
= (item
->bDown
) ? HIS_PRESSED
: (hottrack
? HIS_HOT
: HIS_NORMAL
);
285 DrawThemeBackground (theme
, hdc
, HP_HEADERITEM
, state
, r
, NULL
);
286 GetThemeBackgroundContentRect (theme
, hdc
, HP_HEADERITEM
, state
, r
, r
);
290 HBRUSH hbr
= CreateSolidBrush(GetBkColor(hdc
));
291 FillRect(hdc
, r
, hbr
);
297 HEADER_DrawItemFrame(HEADER_INFO
*infoPtr
, HDC hdc
, RECT
*r
, const HEADER_ITEM
*item
)
299 if (GetWindowTheme(infoPtr
->hwndSelf
)) return;
301 if (!(infoPtr
->dwStyle
& HDS_FLAT
))
303 if (infoPtr
->dwStyle
& HDS_BUTTONS
) {
305 DrawEdge (hdc
, r
, BDR_RAISEDOUTER
, BF_RECT
| BF_FLAT
| BF_ADJUST
);
307 DrawEdge (hdc
, r
, EDGE_RAISED
, BF_RECT
| BF_SOFT
| BF_ADJUST
);
310 DrawEdge (hdc
, r
, EDGE_ETCHED
, BF_BOTTOM
| BF_RIGHT
| BF_ADJUST
);
315 HEADER_DrawItem (HEADER_INFO
*infoPtr
, HDC hdc
, INT iItem
, BOOL bHotTrack
, LRESULT lCDFlags
)
317 HEADER_ITEM
*phdi
= &infoPtr
->items
[iItem
];
320 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
323 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem
, bHotTrack
, (infoPtr
->nNotifyFormat
== NFR_UNICODE
));
326 if (r
.right
- r
.left
== 0)
327 return phdi
->rect
.right
;
329 /* Set the colors before sending NM_CUSTOMDRAW so that it can change them */
330 SetTextColor(hdc
, (bHotTrack
&& !theme
) ? COLOR_HIGHLIGHT
: COLOR_BTNTEXT
);
331 SetBkColor(hdc
, comctl32_color
.clr3dFace
);
333 if (lCDFlags
& CDRF_NOTIFYITEMDRAW
&& !(phdi
->fmt
& HDF_OWNERDRAW
))
335 LRESULT lCDItemFlags
;
337 nmcd
.dwDrawStage
= CDDS_PREPAINT
| CDDS_ITEM
;
339 nmcd
.dwItemSpec
= iItem
;
341 nmcd
.uItemState
= phdi
->bDown
? CDIS_SELECTED
: 0;
342 nmcd
.lItemlParam
= phdi
->lParam
;
344 lCDItemFlags
= HEADER_SendNotify(infoPtr
, NM_CUSTOMDRAW
, (NMHDR
*)&nmcd
);
345 if (lCDItemFlags
& CDRF_SKIPDEFAULT
)
346 return phdi
->rect
.right
;
349 /* Fill background, owner could draw over it. */
350 HEADER_FillItemFrame(infoPtr
, hdc
, &r
, phdi
, bHotTrack
);
352 if (phdi
->fmt
& HDF_OWNERDRAW
)
357 dis
.CtlType
= ODT_HEADER
;
358 dis
.CtlID
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
360 dis
.itemAction
= ODA_DRAWENTIRE
;
361 dis
.itemState
= phdi
->bDown
? ODS_SELECTED
: 0;
362 dis
.hwndItem
= infoPtr
->hwndSelf
;
364 dis
.rcItem
= phdi
->rect
;
365 dis
.itemData
= phdi
->lParam
;
366 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
367 ret
= SendMessageW (infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
368 if (oldBkMode
!= TRANSPARENT
)
369 SetBkMode(hdc
, oldBkMode
);
372 HEADER_FillItemFrame(infoPtr
, hdc
, &r
, phdi
, bHotTrack
);
374 /* Edges are always drawn if we don't have attached theme. */
375 HEADER_DrawItemFrame(infoPtr
, hdc
, &r
, phdi
);
376 /* If application processed WM_DRAWITEM we should skip label painting,
377 edges are drawn no matter what. */
378 if (ret
) return phdi
->rect
.right
;
382 HEADER_FillItemFrame(infoPtr
, hdc
, &r
, phdi
, bHotTrack
);
383 HEADER_DrawItemFrame(infoPtr
, hdc
, &r
, phdi
);
391 /* Now text and image */
393 UINT rw
, rh
, /* width and height of r */
394 *x
= NULL
, *w
= NULL
; /* x and width of the pic (bmp or img) which is part of cnt */
395 /* cnt,txt,img,bmp */
401 HEADER_PrepareCallbackItems(infoPtr
, iItem
, HDI_TEXT
|HDI_IMAGE
);
402 cw
= tw
= iw
= bw
= 0;
403 rw
= r
.right
- r
.left
;
404 rh
= r
.bottom
- r
.top
;
406 if (phdi
->fmt
& HDF_STRING
) {
409 SetRectEmpty(&textRect
);
410 DrawTextW (hdc
, phdi
->pszText
, -1,
411 &textRect
, DT_LEFT
|DT_VCENTER
|DT_SINGLELINE
|DT_CALCRECT
);
412 cw
= textRect
.right
- textRect
.left
+ 2 * infoPtr
->iMargin
;
415 if ((phdi
->fmt
& HDF_IMAGE
) && ImageList_GetIconSize( infoPtr
->himl
, &img_cx
, &img_cy
)) {
416 iw
= img_cx
+ 2 * infoPtr
->iMargin
;
421 if ((phdi
->fmt
& HDF_BITMAP
) && (phdi
->hbm
)) {
422 GetObjectW (phdi
->hbm
, sizeof(BITMAP
), &bmp
);
423 bw
= bmp
.bmWidth
+ 2 * infoPtr
->iMargin
;
433 /* align cx using the unclipped cw */
434 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_LEFT
)
436 else if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_CENTER
)
437 cx
= r
.left
+ rw
/ 2 - cw
/ 2;
444 if (cx
+ cw
> r
.right
)
447 tx
= cx
+ infoPtr
->iMargin
;
448 /* since cw might have changed we have to recalculate tw */
449 tw
= cw
- infoPtr
->iMargin
* 2;
453 if (phdi
->fmt
& HDF_BITMAP_ON_RIGHT
) {
454 /* put pic behind text */
455 *x
= cx
+ tw
+ infoPtr
->iMargin
* 3;
457 *x
= cx
+ infoPtr
->iMargin
;
458 /* move text behind pic */
464 /* since we're done with the layout we can
465 now calculate the position of bmp which
466 has no influence on alignment and layout
468 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_RIGHT
)
469 bx
= cx
- bw
+ infoPtr
->iMargin
;
471 bx
= cx
+ cw
+ infoPtr
->iMargin
;
475 HDC hClipDC
= GetDC(infoPtr
->hwndSelf
);
476 HRGN hClipRgn
= CreateRectRgn(r
.left
, r
.top
, r
.right
, r
.bottom
);
477 SelectClipRgn(hClipDC
, hClipRgn
);
480 HDC hdcBitmap
= CreateCompatibleDC (hClipDC
);
481 SelectObject (hdcBitmap
, phdi
->hbm
);
482 BitBlt (hClipDC
, bx
, r
.top
+ ((INT
)rh
- bmp
.bmHeight
) / 2,
483 bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
484 DeleteDC (hdcBitmap
);
488 ImageList_DrawEx (infoPtr
->himl
, phdi
->iImage
, hClipDC
,
489 ix
, r
.top
+ ((INT
)rh
- img_cy
) / 2,
490 img_cx
, img_cy
, CLR_DEFAULT
, CLR_DEFAULT
, 0);
493 DeleteObject(hClipRgn
);
494 ReleaseDC(infoPtr
->hwndSelf
, hClipDC
);
497 if (((phdi
->fmt
& HDF_STRING
)
498 || (!(phdi
->fmt
& (HDF_OWNERDRAW
|HDF_STRING
|HDF_BITMAP
|
499 HDF_BITMAP_ON_RIGHT
|HDF_IMAGE
)))) /* no explicit format specified? */
500 && (phdi
->pszText
)) {
501 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
504 DrawTextW (hdc
, phdi
->pszText
, -1,
505 &r
, DT_LEFT
|DT_END_ELLIPSIS
|DT_VCENTER
|DT_SINGLELINE
);
506 if (oldBkMode
!= TRANSPARENT
)
507 SetBkMode(hdc
, oldBkMode
);
509 HEADER_FreeCallbackItems(phdi
);
512 return phdi
->rect
.right
;
516 HEADER_DrawHotDivider(const HEADER_INFO
*infoPtr
, HDC hdc
)
521 HEADER_GetHotDividerRect(infoPtr
, &r
);
522 brush
= CreateSolidBrush(comctl32_color
.clrHighlight
);
523 FillRect(hdc
, &r
, brush
);
528 HEADER_Refresh (HEADER_INFO
*infoPtr
, HDC hdc
)
530 HFONT hFont
, hOldFont
;
536 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
538 if (!infoPtr
->bRectsValid
)
539 HEADER_SetItemBounds(infoPtr
);
541 /* get rect for the bar, adjusted for the border */
542 GetClientRect (infoPtr
->hwndSelf
, &rect
);
543 lCDFlags
= HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_PREPAINT
, hdc
, &rect
);
545 if (infoPtr
->bDragging
)
546 ImageList_DragShowNolock(FALSE
);
548 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
);
549 hOldFont
= SelectObject (hdc
, hFont
);
551 /* draw Background */
552 if (infoPtr
->uNumItem
== 0 && theme
== NULL
) {
553 hbrBk
= GetSysColorBrush(COLOR_3DFACE
);
554 FillRect(hdc
, &rect
, hbrBk
);
558 for (i
= 0; x
<= rect
.right
&& i
< infoPtr
->uNumItem
; i
++) {
559 int idx
= HEADER_OrderToIndex(infoPtr
,i
);
560 if (RectVisible(hdc
, &infoPtr
->items
[idx
].rect
))
561 HEADER_DrawItem(infoPtr
, hdc
, idx
, infoPtr
->iHotItem
== idx
, lCDFlags
);
562 x
= infoPtr
->items
[idx
].rect
.right
;
567 if ((x
<= rect
.right
) && RectVisible(hdc
, &rcRest
) && (infoPtr
->uNumItem
> 0)) {
569 DrawThemeBackground(theme
, hdc
, HP_HEADERITEM
, HIS_NORMAL
, &rcRest
, NULL
);
571 else if (infoPtr
->dwStyle
& HDS_FLAT
) {
572 hbrBk
= GetSysColorBrush(COLOR_3DFACE
);
573 FillRect(hdc
, &rcRest
, hbrBk
);
577 if (infoPtr
->dwStyle
& HDS_BUTTONS
)
578 DrawEdge (hdc
, &rcRest
, EDGE_RAISED
, BF_TOP
|BF_LEFT
|BF_BOTTOM
|BF_SOFT
|BF_MIDDLE
);
580 DrawEdge (hdc
, &rcRest
, EDGE_ETCHED
, BF_BOTTOM
|BF_MIDDLE
);
584 if (infoPtr
->iHotDivider
!= -1)
585 HEADER_DrawHotDivider(infoPtr
, hdc
);
587 if (infoPtr
->bDragging
)
588 ImageList_DragShowNolock(TRUE
);
589 SelectObject (hdc
, hOldFont
);
591 if (lCDFlags
& CDRF_NOTIFYPOSTPAINT
)
592 HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_POSTPAINT
, hdc
, &rect
);
597 HEADER_RefreshItem (HEADER_INFO
*infoPtr
, INT iItem
)
599 if (!infoPtr
->bRectsValid
)
600 HEADER_SetItemBounds(infoPtr
);
602 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->items
[iItem
].rect
, FALSE
);
607 HEADER_InternalHitTest (const HEADER_INFO
*infoPtr
, const POINT
*lpPt
, UINT
*pFlags
, INT
*pItem
)
614 GetClientRect (infoPtr
->hwndSelf
, &rect
);
618 if (PtInRect (&rect
, *lpPt
))
620 if (infoPtr
->uNumItem
== 0) {
621 *pFlags
|= HHT_NOWHERE
;
627 /* somewhere inside */
628 for (iCount
= 0; iCount
< infoPtr
->uNumItem
; iCount
++) {
629 rect
= infoPtr
->items
[iCount
].rect
;
630 width
= rect
.right
- rect
.left
;
635 if (PtInRect (&rect
, *lpPt
)) {
636 if (width
<= 2 * DIVIDER_WIDTH
) {
637 *pFlags
|= HHT_ONHEADER
;
639 TRACE("ON HEADER %d\n", iCount
);
642 if (HEADER_IndexToOrder(infoPtr
, iCount
) > 0) {
644 rcTest
.right
= rcTest
.left
+ DIVIDER_WIDTH
;
645 if (PtInRect (&rcTest
, *lpPt
)) {
646 if (HEADER_IsItemFixed(infoPtr
, HEADER_PrevItem(infoPtr
, iCount
)))
648 *pFlags
|= HHT_ONHEADER
;
650 TRACE("ON HEADER %d\n", *pItem
);
654 *pFlags
|= HHT_ONDIVOPEN
;
655 *pItem
= HEADER_PrevItem(infoPtr
, iCount
);
656 TRACE("ON DIVOPEN %d\n", *pItem
);
660 *pFlags
|= HHT_ONDIVIDER
;
661 *pItem
= HEADER_PrevItem(infoPtr
, iCount
);
662 TRACE("ON DIVIDER %d\n", *pItem
);
668 rcTest
.left
= rcTest
.right
- DIVIDER_WIDTH
;
669 if (!HEADER_IsItemFixed(infoPtr
, iCount
) && PtInRect (&rcTest
, *lpPt
))
671 *pFlags
|= HHT_ONDIVIDER
;
673 TRACE("ON DIVIDER %d\n", *pItem
);
677 *pFlags
|= HHT_ONHEADER
;
679 TRACE("ON HEADER %d\n", iCount
);
684 /* check for last divider part (on nowhere) */
685 if (!HEADER_IsItemFixed(infoPtr
, infoPtr
->uNumItem
- 1))
687 rect
= infoPtr
->items
[infoPtr
->uNumItem
-1].rect
;
688 rect
.left
= rect
.right
;
689 rect
.right
+= DIVIDER_WIDTH
;
690 if (PtInRect (&rect
, *lpPt
)) {
692 *pFlags
|= HHT_ONDIVOPEN
;
693 *pItem
= infoPtr
->uNumItem
- 1;
694 TRACE("ON DIVOPEN %d\n", *pItem
);
698 *pFlags
|= HHT_ONDIVIDER
;
699 *pItem
= infoPtr
->uNumItem
- 1;
700 TRACE("ON DIVIDER %d\n", *pItem
);
706 *pFlags
|= HHT_NOWHERE
;
713 if (lpPt
->x
< rect
.left
) {
715 *pFlags
|= HHT_TOLEFT
;
717 else if (lpPt
->x
> rect
.right
) {
719 *pFlags
|= HHT_TORIGHT
;
722 if (lpPt
->y
< rect
.top
) {
724 *pFlags
|= HHT_ABOVE
;
726 else if (lpPt
->y
> rect
.bottom
) {
728 *pFlags
|= HHT_BELOW
;
733 TRACE("flags=0x%X\n", *pFlags
);
739 HEADER_DrawTrackLine (const HEADER_INFO
*infoPtr
, HDC hdc
, INT x
)
743 GetClientRect (infoPtr
->hwndSelf
, &rect
);
744 PatBlt( hdc
, x
, rect
.top
, 1, rect
.bottom
- rect
.top
, DSTINVERT
);
749 * Convert a HDITEM into the correct format (ANSI/Unicode) to send it in a notify
752 * [I] infoPtr : the header that wants to send the notify
753 * [O] dest : The buffer to store the HDITEM for notify. It may be set to a HDITEMA of HDITEMW
754 * [I] src : The source HDITEM. It may be a HDITEMA or HDITEMW
755 * [I] fSourceUnicode : is src a HDITEMW or HDITEMA
756 * [O] ppvScratch : a pointer to a scratch buffer that needs to be freed after
757 * the HDITEM is no longer in use or NULL if none was needed
759 * NOTE: We depend on HDITEMA and HDITEMW having the same structure
761 static void HEADER_CopyHDItemForNotify(const HEADER_INFO
*infoPtr
, HDITEMW
*dest
,
762 const HDITEMW
*src
, BOOL fSourceUnicode
, LPVOID
*ppvScratch
)
767 if (src
->mask
& HDI_TEXT
&& src
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers TEXTCALLBACKA as well */
769 if (fSourceUnicode
&& infoPtr
->nNotifyFormat
!= NFR_UNICODE
)
771 dest
->pszText
= NULL
;
772 Str_SetPtrWtoA((LPSTR
*)&dest
->pszText
, src
->pszText
);
773 *ppvScratch
= dest
->pszText
;
776 if (!fSourceUnicode
&& infoPtr
->nNotifyFormat
== NFR_UNICODE
)
778 dest
->pszText
= NULL
;
779 Str_SetPtrAtoW(&dest
->pszText
, (LPSTR
)src
->pszText
);
780 *ppvScratch
= dest
->pszText
;
785 static UINT
HEADER_NotifyCodeWtoA(UINT code
)
787 /* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
788 if (code
>= HDN_LAST
&& code
<= HDN_FIRST_UNICODE
)
789 return code
+ HDN_UNICODE_OFFSET
;
795 HEADER_SendNotify(const HEADER_INFO
*infoPtr
, UINT code
, NMHDR
*nmhdr
)
797 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
798 nmhdr
->idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
801 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
802 nmhdr
->idFrom
, (LPARAM
)nmhdr
);
806 HEADER_SendSimpleNotify (const HEADER_INFO
*infoPtr
, UINT code
)
809 return (BOOL
)HEADER_SendNotify(infoPtr
, code
, &nmhdr
);
813 HEADER_SendCtrlCustomDraw(const HEADER_INFO
*infoPtr
, DWORD dwDrawStage
, HDC hdc
, const RECT
*rect
)
816 nm
.dwDrawStage
= dwDrawStage
;
823 return HEADER_SendNotify(infoPtr
, NM_CUSTOMDRAW
, (NMHDR
*)&nm
);
827 HEADER_SendNotifyWithHDItemT(const HEADER_INFO
*infoPtr
, UINT code
, INT iItem
, HDITEMW
*lpItem
)
831 if (infoPtr
->nNotifyFormat
!= NFR_UNICODE
)
832 code
= HEADER_NotifyCodeWtoA(code
);
835 nmhdr
.pitem
= lpItem
;
837 return (BOOL
)HEADER_SendNotify(infoPtr
, code
, (NMHDR
*)&nmhdr
);
841 HEADER_SendNotifyWithIntFieldT(const HEADER_INFO
*infoPtr
, UINT code
, INT iItem
, INT mask
, INT iValue
)
845 /* copying only the iValue should be ok but to make the code more robust we copy everything */
846 nmitem
.cxy
= infoPtr
->items
[iItem
].cxy
;
847 nmitem
.hbm
= infoPtr
->items
[iItem
].hbm
;
848 nmitem
.pszText
= NULL
;
849 nmitem
.cchTextMax
= 0;
850 nmitem
.fmt
= infoPtr
->items
[iItem
].fmt
;
851 nmitem
.lParam
= infoPtr
->items
[iItem
].lParam
;
852 nmitem
.iOrder
= infoPtr
->items
[iItem
].iOrder
;
853 nmitem
.iImage
= infoPtr
->items
[iItem
].iImage
;
862 nmitem
.iOrder
= iValue
;
865 ERR("invalid mask value 0x%x\n", iValue
);
868 return HEADER_SendNotifyWithHDItemT(infoPtr
, code
, iItem
, &nmitem
);
872 * Prepare callback items
873 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
874 * (so we handle the two cases only doing a specific cast for pszText).
875 * Checks if any of the required fields is a callback. If this is the case sends a
876 * NMHDISPINFO notify to retrieve these items. The items are stored in the
877 * HEADER_ITEM pszText and iImage fields. They should be freed with
878 * HEADER_FreeCallbackItems.
880 * @param hwnd : hwnd header container handler
881 * @param iItem : the header item id
882 * @param reqMask : required fields. If any of them is callback this function will fetch it
884 * @return TRUE on success, else FALSE
887 HEADER_PrepareCallbackItems(const HEADER_INFO
*infoPtr
, INT iItem
, INT reqMask
)
889 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
890 DWORD mask
= reqMask
& lpItem
->callbackMask
;
891 NMHDDISPINFOW dispInfo
;
892 void *pvBuffer
= NULL
;
896 if (mask
&HDI_TEXT
&& lpItem
->pszText
!= NULL
)
898 ERR("(): function called without a call to FreeCallbackItems\n");
899 Free(lpItem
->pszText
);
900 lpItem
->pszText
= NULL
;
903 memset(&dispInfo
, 0, sizeof(NMHDDISPINFOW
));
904 dispInfo
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
905 dispInfo
.hdr
.idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
906 if (infoPtr
->nNotifyFormat
== NFR_UNICODE
)
908 dispInfo
.hdr
.code
= HDN_GETDISPINFOW
;
910 pvBuffer
= Alloc(MAX_HEADER_TEXT_LEN
* sizeof(WCHAR
));
914 dispInfo
.hdr
.code
= HDN_GETDISPINFOA
;
916 pvBuffer
= Alloc(MAX_HEADER_TEXT_LEN
* sizeof(CHAR
));
918 dispInfo
.pszText
= pvBuffer
;
919 dispInfo
.cchTextMax
= (pvBuffer
!=NULL
?MAX_HEADER_TEXT_LEN
:0);
920 dispInfo
.iItem
= iItem
;
921 dispInfo
.mask
= mask
;
922 dispInfo
.lParam
= lpItem
->lParam
;
924 TRACE("Sending HDN_GETDISPINFO%c\n", infoPtr
->nNotifyFormat
== NFR_UNICODE
?'W':'A');
925 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, dispInfo
.hdr
.idFrom
, (LPARAM
)&dispInfo
);
927 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
929 (infoPtr
->nNotifyFormat
== NFR_UNICODE
? debugstr_w(dispInfo
.pszText
) : (LPSTR
) dispInfo
.pszText
),
930 (void*) dispInfo
.lParam
);
932 if (mask
& HDI_IMAGE
)
933 lpItem
->iImage
= dispInfo
.iImage
;
936 if (infoPtr
->nNotifyFormat
== NFR_UNICODE
)
938 lpItem
->pszText
= pvBuffer
;
940 /* the user might have used his own buffer */
941 if (dispInfo
.pszText
!= lpItem
->pszText
)
942 Str_GetPtrW(dispInfo
.pszText
, lpItem
->pszText
, MAX_HEADER_TEXT_LEN
);
946 Str_SetPtrAtoW(&lpItem
->pszText
, (LPSTR
)dispInfo
.pszText
);
951 if (dispInfo
.mask
& HDI_DI_SETITEM
)
953 /* make the items permanent */
954 lpItem
->callbackMask
&= ~dispInfo
.mask
;
962 * Free the items that might be allocated with HEADER_PrepareCallbackItems
965 * [I] lpItem : the item to free the data
969 HEADER_FreeCallbackItems(HEADER_ITEM
*lpItem
)
971 if (lpItem
->callbackMask
&HDI_TEXT
)
973 Free(lpItem
->pszText
);
974 lpItem
->pszText
= NULL
;
977 if (lpItem
->callbackMask
&HDI_IMAGE
)
978 lpItem
->iImage
= I_IMAGECALLBACK
;
982 HEADER_CreateDragImage (HEADER_INFO
*infoPtr
, INT iItem
)
986 HBITMAP hMemory
, hOldBitmap
;
994 if (iItem
>= infoPtr
->uNumItem
)
997 if (!infoPtr
->bRectsValid
)
998 HEADER_SetItemBounds(infoPtr
);
1000 lpItem
= &infoPtr
->items
[iItem
];
1001 width
= lpItem
->rect
.right
- lpItem
->rect
.left
;
1002 height
= lpItem
->rect
.bottom
- lpItem
->rect
.top
;
1004 hDeviceDC
= GetDC(NULL
);
1005 hMemoryDC
= CreateCompatibleDC(hDeviceDC
);
1006 hMemory
= CreateCompatibleBitmap(hDeviceDC
, width
, height
);
1007 ReleaseDC(NULL
, hDeviceDC
);
1008 hOldBitmap
= SelectObject(hMemoryDC
, hMemory
);
1009 SetViewportOrgEx(hMemoryDC
, -lpItem
->rect
.left
, -lpItem
->rect
.top
, NULL
);
1010 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject(SYSTEM_FONT
);
1011 SelectObject(hMemoryDC
, hFont
);
1013 GetClientRect(infoPtr
->hwndSelf
, &rc
);
1014 lCDFlags
= HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_PREPAINT
, hMemoryDC
, &rc
);
1015 HEADER_DrawItem(infoPtr
, hMemoryDC
, iItem
, FALSE
, lCDFlags
);
1016 if (lCDFlags
& CDRF_NOTIFYPOSTPAINT
)
1017 HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_POSTPAINT
, hMemoryDC
, &rc
);
1019 hMemory
= SelectObject(hMemoryDC
, hOldBitmap
);
1020 DeleteDC(hMemoryDC
);
1022 if (hMemory
== NULL
) /* if anything failed */
1025 himl
= ImageList_Create(width
, height
, ILC_COLORDDB
, 1, 1);
1026 ImageList_Add(himl
, hMemory
, NULL
);
1027 DeleteObject(hMemory
);
1028 return (LRESULT
)himl
;
1032 HEADER_SetHotDivider(HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1041 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1043 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &iDivider
);
1045 if (flags
& HHT_TOLEFT
)
1047 else if (flags
& HHT_NOWHERE
|| flags
& HHT_TORIGHT
)
1048 iDivider
= infoPtr
->uNumItem
;
1051 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iDivider
];
1052 if (pt
.x
> (lpItem
->rect
.left
+lpItem
->rect
.right
)/2)
1053 iDivider
= HEADER_NextItem(infoPtr
, iDivider
);
1057 iDivider
= (INT
)lParam
;
1059 /* Note; wParam==FALSE, lParam==-1 is valid and is used to clear the hot divider */
1060 if (iDivider
<-1 || iDivider
>(int)infoPtr
->uNumItem
)
1063 if (iDivider
!= infoPtr
->iHotDivider
)
1065 if (infoPtr
->iHotDivider
!= -1)
1067 HEADER_GetHotDividerRect(infoPtr
, &r
);
1068 InvalidateRect(infoPtr
->hwndSelf
, &r
, FALSE
);
1070 infoPtr
->iHotDivider
= iDivider
;
1073 HEADER_GetHotDividerRect(infoPtr
, &r
);
1074 InvalidateRect(infoPtr
->hwndSelf
, &r
, FALSE
);
1081 HEADER_DeleteItem (HEADER_INFO
*infoPtr
, INT iItem
)
1086 TRACE("[iItem=%d]\n", iItem
);
1088 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
1091 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1092 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
1094 iOrder
= infoPtr
->items
[iItem
].iOrder
;
1095 Free(infoPtr
->items
[iItem
].pszText
);
1097 infoPtr
->uNumItem
--;
1098 memmove(&infoPtr
->items
[iItem
], &infoPtr
->items
[iItem
+ 1],
1099 (infoPtr
->uNumItem
- iItem
) * sizeof(HEADER_ITEM
));
1100 memmove(&infoPtr
->order
[iOrder
], &infoPtr
->order
[iOrder
+ 1],
1101 (infoPtr
->uNumItem
- iOrder
) * sizeof(INT
));
1102 infoPtr
->items
= ReAlloc(infoPtr
->items
, sizeof(HEADER_ITEM
) * infoPtr
->uNumItem
);
1103 infoPtr
->order
= ReAlloc(infoPtr
->order
, sizeof(INT
) * infoPtr
->uNumItem
);
1105 /* Correct the orders */
1106 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1108 if (infoPtr
->order
[i
] > iItem
)
1109 infoPtr
->order
[i
]--;
1111 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
1113 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1114 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
1116 HEADER_SetItemBounds (infoPtr
);
1117 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1124 HEADER_GetImageList (const HEADER_INFO
*infoPtr
)
1126 return (LRESULT
)infoPtr
->himl
;
1131 HEADER_GetItemT (const HEADER_INFO
*infoPtr
, INT nItem
, LPHDITEMW phdi
, BOOL bUnicode
)
1133 HEADER_ITEM
*lpItem
;
1139 TRACE("[nItem=%d]\n", nItem
);
1145 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
1148 if (mask
& HDI_UNKNOWN_FIELDS
)
1150 TRACE("mask %x contains unknown fields. Using only comctl32 4.0 fields\n", mask
);
1151 mask
&= HDI_COMCTL32_4_0_FIELDS
;
1154 lpItem
= &infoPtr
->items
[nItem
];
1155 HEADER_PrepareCallbackItems(infoPtr
, nItem
, mask
);
1157 if (mask
& HDI_BITMAP
)
1158 phdi
->hbm
= lpItem
->hbm
;
1160 if (mask
& HDI_FORMAT
)
1161 phdi
->fmt
= lpItem
->fmt
;
1163 if (mask
& HDI_WIDTH
)
1164 phdi
->cxy
= lpItem
->cxy
;
1166 if (mask
& HDI_LPARAM
)
1167 phdi
->lParam
= lpItem
->lParam
;
1169 if (mask
& HDI_IMAGE
)
1170 phdi
->iImage
= lpItem
->iImage
;
1172 if (mask
& HDI_ORDER
)
1173 phdi
->iOrder
= lpItem
->iOrder
;
1175 if (mask
& HDI_TEXT
)
1178 Str_GetPtrW (lpItem
->pszText
, phdi
->pszText
, phdi
->cchTextMax
);
1180 Str_GetPtrWtoA (lpItem
->pszText
, (LPSTR
)phdi
->pszText
, phdi
->cchTextMax
);
1183 HEADER_FreeCallbackItems(lpItem
);
1188 static inline LRESULT
1189 HEADER_GetItemCount (const HEADER_INFO
*infoPtr
)
1191 return infoPtr
->uNumItem
;
1196 HEADER_GetItemRect (const HEADER_INFO
*infoPtr
, INT iItem
, LPRECT lpRect
)
1198 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
1201 lpRect
->left
= infoPtr
->items
[iItem
].rect
.left
;
1202 lpRect
->right
= infoPtr
->items
[iItem
].rect
.right
;
1203 lpRect
->top
= infoPtr
->items
[iItem
].rect
.top
;
1204 lpRect
->bottom
= infoPtr
->items
[iItem
].rect
.bottom
;
1211 HEADER_GetOrderArray(const HEADER_INFO
*infoPtr
, INT size
, LPINT order
)
1213 if ((UINT
)size
<infoPtr
->uNumItem
)
1216 memcpy(order
, infoPtr
->order
, infoPtr
->uNumItem
* sizeof(INT
));
1220 /* Returns index of first duplicate 'value' from [0,to) range,
1221 or -1 if there isn't any */
1222 static INT
has_duplicate(const INT
*array
, INT to
, INT value
)
1225 for(i
= 0; i
< to
; i
++)
1226 if (array
[i
] == value
) return i
;
1230 /* returns next available value from [0,max] not to duplicate in [0,to) */
1231 static INT
get_nextvalue(const INT
*array
, INT to
, INT max
)
1234 for(i
= 0; i
< max
; i
++)
1235 if (has_duplicate(array
, to
, i
) == -1) return i
;
1240 HEADER_SetOrderArray(HEADER_INFO
*infoPtr
, INT size
, const INT
*order
)
1242 HEADER_ITEM
*lpItem
;
1245 if ((UINT
)size
!= infoPtr
->uNumItem
)
1248 if (TRACE_ON(header
))
1250 TRACE("count=%d, order array={", size
);
1251 for (i
= 0; i
< size
; i
++)
1252 TRACE("%d%c", order
[i
], i
!= size
-1 ? ',' : '}');
1256 for (i
=0; i
<size
; i
++)
1258 if (order
[i
] >= size
|| order
[i
] < 0)
1259 /* on invalid index get next available */
1260 /* FIXME: if i==0 array item is out of range behaviour is
1261 different, see tests */
1262 infoPtr
->order
[i
] = get_nextvalue(infoPtr
->order
, i
, size
);
1267 infoPtr
->order
[i
] = order
[i
];
1269 /* remove duplicates */
1270 while ((dup
= has_duplicate(infoPtr
->order
, j
, order
[j
])) != -1)
1274 next
= get_nextvalue(infoPtr
->order
, j
, size
);
1275 infoPtr
->order
[dup
] = next
;
1280 /* sync with item data */
1281 for (i
=0; i
<size
; i
++)
1283 lpItem
= &infoPtr
->items
[infoPtr
->order
[i
]];
1286 HEADER_SetItemBounds(infoPtr
);
1287 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1291 static inline LRESULT
1292 HEADER_GetUnicodeFormat (const HEADER_INFO
*infoPtr
)
1294 return (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1299 HEADER_HitTest (const HEADER_INFO
*infoPtr
, LPHDHITTESTINFO phti
)
1301 UINT outside
= HHT_NOWHERE
| HHT_ABOVE
| HHT_BELOW
| HHT_TOLEFT
| HHT_TORIGHT
;
1303 HEADER_InternalHitTest (infoPtr
, &phti
->pt
, &phti
->flags
, &phti
->iItem
);
1305 if (phti
->flags
& outside
)
1306 return phti
->iItem
= -1;
1313 HEADER_InsertItemT (HEADER_INFO
*infoPtr
, INT nItem
, const HDITEMW
*phdi
, BOOL bUnicode
)
1315 HEADER_ITEM
*lpItem
;
1320 if ((phdi
== NULL
) || (nItem
< 0) || (phdi
->mask
== 0))
1323 if (nItem
> infoPtr
->uNumItem
)
1324 nItem
= infoPtr
->uNumItem
;
1326 iOrder
= (phdi
->mask
& HDI_ORDER
) ? phdi
->iOrder
: nItem
;
1329 else if (infoPtr
->uNumItem
< iOrder
)
1330 iOrder
= infoPtr
->uNumItem
;
1332 infoPtr
->uNumItem
++;
1333 infoPtr
->items
= ReAlloc(infoPtr
->items
, sizeof(HEADER_ITEM
) * infoPtr
->uNumItem
);
1334 infoPtr
->order
= ReAlloc(infoPtr
->order
, sizeof(INT
) * infoPtr
->uNumItem
);
1336 /* make space for the new item */
1337 memmove(&infoPtr
->items
[nItem
+ 1], &infoPtr
->items
[nItem
],
1338 (infoPtr
->uNumItem
- nItem
- 1) * sizeof(HEADER_ITEM
));
1339 memmove(&infoPtr
->order
[iOrder
+ 1], &infoPtr
->order
[iOrder
],
1340 (infoPtr
->uNumItem
- iOrder
- 1) * sizeof(INT
));
1342 /* update the order array */
1343 infoPtr
->order
[iOrder
] = nItem
;
1344 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1346 if (i
!= iOrder
&& infoPtr
->order
[i
] >= nItem
)
1347 infoPtr
->order
[i
]++;
1348 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
1351 lpItem
= &infoPtr
->items
[nItem
];
1352 ZeroMemory(lpItem
, sizeof(HEADER_ITEM
));
1353 /* cxy, fmt and lParam are copied even if not in the HDITEM mask */
1354 copyMask
= phdi
->mask
| HDI_WIDTH
| HDI_FORMAT
| HDI_LPARAM
;
1355 HEADER_StoreHDItemInHeader(lpItem
, copyMask
, phdi
, bUnicode
);
1356 lpItem
->iOrder
= iOrder
;
1358 /* set automatically some format bits */
1359 if (phdi
->mask
& HDI_TEXT
)
1360 lpItem
->fmt
|= HDF_STRING
;
1362 lpItem
->fmt
&= ~HDF_STRING
;
1364 if (lpItem
->hbm
!= NULL
)
1365 lpItem
->fmt
|= HDF_BITMAP
;
1367 lpItem
->fmt
&= ~HDF_BITMAP
;
1369 if (phdi
->mask
& HDI_IMAGE
)
1370 lpItem
->fmt
|= HDF_IMAGE
;
1372 HEADER_SetItemBounds (infoPtr
);
1373 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1380 HEADER_Layout (HEADER_INFO
*infoPtr
, LPHDLAYOUT lpLayout
)
1382 lpLayout
->pwpos
->hwnd
= infoPtr
->hwndSelf
;
1383 lpLayout
->pwpos
->hwndInsertAfter
= 0;
1384 lpLayout
->pwpos
->x
= lpLayout
->prc
->left
;
1385 lpLayout
->pwpos
->y
= lpLayout
->prc
->top
;
1386 lpLayout
->pwpos
->cx
= lpLayout
->prc
->right
- lpLayout
->prc
->left
;
1387 if (infoPtr
->dwStyle
& HDS_HIDDEN
)
1388 lpLayout
->pwpos
->cy
= 0;
1390 lpLayout
->pwpos
->cy
= infoPtr
->nHeight
;
1391 lpLayout
->prc
->top
+= infoPtr
->nHeight
;
1393 lpLayout
->pwpos
->flags
= SWP_NOZORDER
;
1395 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1396 lpLayout
->pwpos
->x
, lpLayout
->pwpos
->y
,
1397 lpLayout
->pwpos
->cx
, lpLayout
->pwpos
->cy
);
1399 infoPtr
->bRectsValid
= FALSE
;
1406 HEADER_SetImageList (HEADER_INFO
*infoPtr
, HIMAGELIST himl
)
1410 TRACE("(himl %p)\n", himl
);
1411 himlOld
= infoPtr
->himl
;
1412 infoPtr
->himl
= himl
;
1414 /* FIXME: Refresh needed??? */
1416 return (LRESULT
)himlOld
;
1421 HEADER_GetBitmapMargin(const HEADER_INFO
*infoPtr
)
1423 return infoPtr
->iMargin
;
1427 HEADER_SetBitmapMargin(HEADER_INFO
*infoPtr
, INT iMargin
)
1429 INT oldMargin
= infoPtr
->iMargin
;
1431 infoPtr
->iMargin
= iMargin
;
1437 HEADER_SetItemT (HEADER_INFO
*infoPtr
, INT nItem
, const HDITEMW
*phdi
, BOOL bUnicode
)
1439 HEADER_ITEM
*lpItem
;
1445 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
1448 TRACE("[nItem=%d]\n", nItem
);
1450 HEADER_CopyHDItemForNotify(infoPtr
, &hdNotify
, phdi
, bUnicode
, &pvScratch
);
1451 if (HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCHANGINGW
, nItem
, &hdNotify
))
1457 lpItem
= &infoPtr
->items
[nItem
];
1458 HEADER_StoreHDItemInHeader(lpItem
, phdi
->mask
, phdi
, bUnicode
);
1460 if (phdi
->mask
& HDI_ORDER
)
1461 if (phdi
->iOrder
>= 0 && phdi
->iOrder
< infoPtr
->uNumItem
)
1462 HEADER_ChangeItemOrder(infoPtr
, nItem
, phdi
->iOrder
);
1464 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCHANGEDW
, nItem
, &hdNotify
);
1466 HEADER_SetItemBounds (infoPtr
);
1468 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1474 static inline LRESULT
1475 HEADER_SetUnicodeFormat (HEADER_INFO
*infoPtr
, WPARAM wParam
)
1477 BOOL bTemp
= (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1479 infoPtr
->nNotifyFormat
= ((BOOL
)wParam
? NFR_UNICODE
: NFR_ANSI
);
1486 HEADER_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1488 HEADER_INFO
*infoPtr
;
1493 infoPtr
= Alloc (sizeof(HEADER_INFO
));
1494 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1496 infoPtr
->hwndSelf
= hwnd
;
1497 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1498 infoPtr
->uNumItem
= 0;
1502 infoPtr
->bRectsValid
= FALSE
;
1503 infoPtr
->hcurArrow
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1504 infoPtr
->hcurDivider
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDER
));
1505 infoPtr
->hcurDivopen
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDEROPEN
));
1506 infoPtr
->bPressed
= FALSE
;
1507 infoPtr
->bTracking
= FALSE
;
1508 infoPtr
->dwStyle
= lpcs
->style
;
1509 infoPtr
->iMoveItem
= 0;
1511 infoPtr
->iHotItem
= -1;
1512 infoPtr
->iHotDivider
= -1;
1513 infoPtr
->iMargin
= 3*GetSystemMetrics(SM_CXEDGE
);
1514 infoPtr
->nNotifyFormat
=
1515 SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_QUERY
);
1518 hOldFont
= SelectObject (hdc
, GetStockObject (SYSTEM_FONT
));
1519 GetTextMetricsW (hdc
, &tm
);
1520 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
1521 SelectObject (hdc
, hOldFont
);
1524 OpenThemeData(hwnd
, themeClass
);
1531 HEADER_Destroy (HEADER_INFO
*infoPtr
)
1533 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
1534 CloseThemeData(theme
);
1539 HEADER_NCDestroy (HEADER_INFO
*infoPtr
)
1541 HEADER_ITEM
*lpItem
;
1544 if (infoPtr
->items
) {
1545 lpItem
= infoPtr
->items
;
1546 for (nItem
= 0; nItem
< infoPtr
->uNumItem
; nItem
++, lpItem
++) {
1547 Free(lpItem
->pszText
);
1549 Free (infoPtr
->items
);
1552 Free(infoPtr
->order
);
1554 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
1561 static inline LRESULT
1562 HEADER_GetFont (const HEADER_INFO
*infoPtr
)
1564 return (LRESULT
)infoPtr
->hFont
;
1569 HEADER_IsDragDistance(const HEADER_INFO
*infoPtr
, const POINT
*pt
)
1571 /* Windows allows for a mouse movement before starting the drag. We use the
1572 * SM_CXDOUBLECLICK/SM_CYDOUBLECLICK as that distance.
1574 return (abs(infoPtr
->ptLButtonDown
.x
- pt
->x
)>GetSystemMetrics(SM_CXDOUBLECLK
) ||
1575 abs(infoPtr
->ptLButtonDown
.y
- pt
->y
)>GetSystemMetrics(SM_CYDOUBLECLK
));
1579 HEADER_LButtonDblClk (const HEADER_INFO
*infoPtr
, INT x
, INT y
)
1587 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1589 if ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (flags
== HHT_ONHEADER
))
1590 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMDBLCLICKW
, nItem
, NULL
);
1591 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
))
1592 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_DIVIDERDBLCLICKW
, nItem
, NULL
);
1599 HEADER_LButtonDown (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1608 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1610 if ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (flags
== HHT_ONHEADER
)) {
1611 SetCapture (infoPtr
->hwndSelf
);
1612 infoPtr
->bCaptured
= TRUE
;
1613 infoPtr
->bPressed
= TRUE
;
1614 infoPtr
->bDragging
= FALSE
;
1615 infoPtr
->iMoveItem
= nItem
;
1616 infoPtr
->ptLButtonDown
= pt
;
1618 infoPtr
->items
[nItem
].bDown
= TRUE
;
1620 /* Send WM_CUSTOMDRAW */
1621 hdc
= GetDC (infoPtr
->hwndSelf
);
1622 HEADER_RefreshItem (infoPtr
, nItem
);
1623 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1625 TRACE("Pressed item %d!\n", nItem
);
1627 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
)) {
1628 INT iCurrWidth
= infoPtr
->items
[nItem
].cxy
;
1629 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_BEGINTRACKW
, nItem
, HDI_WIDTH
, iCurrWidth
))
1631 SetCapture (infoPtr
->hwndSelf
);
1632 infoPtr
->bCaptured
= TRUE
;
1633 infoPtr
->bTracking
= TRUE
;
1634 infoPtr
->iMoveItem
= nItem
;
1635 infoPtr
->xTrackOffset
= infoPtr
->items
[nItem
].rect
.right
- pt
.x
;
1637 if (!(infoPtr
->dwStyle
& HDS_FULLDRAG
)) {
1638 infoPtr
->xOldTrack
= infoPtr
->items
[nItem
].rect
.right
;
1639 hdc
= GetDC (infoPtr
->hwndSelf
);
1640 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1641 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1644 TRACE("Begin tracking item %d!\n", nItem
);
1653 HEADER_LButtonUp (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1662 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1664 if (infoPtr
->bPressed
) {
1666 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1668 if (infoPtr
->bDragging
)
1670 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1673 ImageList_DragShowNolock(FALSE
);
1674 ImageList_EndDrag();
1676 if (infoPtr
->iHotDivider
== -1)
1678 else if (infoPtr
->iHotDivider
== infoPtr
->uNumItem
)
1679 iNewOrder
= infoPtr
->uNumItem
-1;
1682 iNewOrder
= HEADER_IndexToOrder(infoPtr
, infoPtr
->iHotDivider
);
1683 if (iNewOrder
> lpItem
->iOrder
)
1687 if (iNewOrder
!= -1 &&
1688 !HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ENDDRAG
, infoPtr
->iMoveItem
, HDI_ORDER
, iNewOrder
))
1690 HEADER_ChangeItemOrder(infoPtr
, infoPtr
->iMoveItem
, iNewOrder
);
1691 infoPtr
->bRectsValid
= FALSE
;
1692 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1695 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->items
[infoPtr
->iMoveItem
].rect
, FALSE
);
1697 infoPtr
->bDragging
= FALSE
;
1698 HEADER_SetHotDivider(infoPtr
, FALSE
, -1);
1702 hdc
= GetDC (infoPtr
->hwndSelf
);
1703 HEADER_RefreshItem (infoPtr
, infoPtr
->iMoveItem
);
1704 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1706 if (!(infoPtr
->dwStyle
& HDS_DRAGDROP
) || !HEADER_IsDragDistance(infoPtr
, &pt
))
1707 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCLICKW
, infoPtr
->iMoveItem
, NULL
);
1710 TRACE("Released item %d!\n", infoPtr
->iMoveItem
);
1711 infoPtr
->bPressed
= FALSE
;
1713 else if (infoPtr
->bTracking
) {
1714 INT iNewWidth
= pt
.x
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
+ infoPtr
->xTrackOffset
;
1717 TRACE("End tracking item %d!\n", infoPtr
->iMoveItem
);
1718 infoPtr
->bTracking
= FALSE
;
1720 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ENDTRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
);
1722 if (!(infoPtr
->dwStyle
& HDS_FULLDRAG
)) {
1723 hdc
= GetDC (infoPtr
->hwndSelf
);
1724 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1725 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1728 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
))
1730 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= iNewWidth
;
1731 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
);
1734 HEADER_SetItemBounds (infoPtr
);
1735 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1738 if (infoPtr
->bCaptured
) {
1739 infoPtr
->bCaptured
= FALSE
;
1741 HEADER_SendSimpleNotify (infoPtr
, NM_RELEASEDCAPTURE
);
1749 HEADER_NotifyFormat (HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1754 return infoPtr
->nNotifyFormat
;
1757 infoPtr
->nNotifyFormat
=
1758 SendMessageW ((HWND
)wParam
, WM_NOTIFYFORMAT
,
1759 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1760 return infoPtr
->nNotifyFormat
;
1767 HEADER_MouseLeave (HEADER_INFO
*infoPtr
)
1769 /* Reset hot-tracked item when mouse leaves control. */
1770 INT oldHotItem
= infoPtr
->iHotItem
;
1771 HDC hdc
= GetDC (infoPtr
->hwndSelf
);
1773 infoPtr
->iHotItem
= -1;
1774 if (oldHotItem
!= -1) HEADER_RefreshItem (infoPtr
, oldHotItem
);
1775 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1782 HEADER_MouseMove (HEADER_INFO
*infoPtr
, LPARAM lParam
)
1788 /* With theming, hottracking is always enabled */
1789 BOOL hotTrackEnabled
=
1790 ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (infoPtr
->dwStyle
& HDS_HOTTRACK
))
1791 || (GetWindowTheme (infoPtr
->hwndSelf
) != NULL
);
1792 INT oldHotItem
= infoPtr
->iHotItem
;
1794 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1795 pt
.y
= (INT
)(SHORT
)HIWORD(lParam
);
1796 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1798 if (hotTrackEnabled
) {
1799 if (flags
& (HHT_ONHEADER
| HHT_ONDIVIDER
| HHT_ONDIVOPEN
))
1800 infoPtr
->iHotItem
= nItem
;
1802 infoPtr
->iHotItem
= -1;
1805 if (infoPtr
->bCaptured
) {
1806 /* check if we should drag the header */
1807 if (infoPtr
->bPressed
&& !infoPtr
->bDragging
&& (infoPtr
->dwStyle
& HDS_DRAGDROP
)
1808 && HEADER_IsDragDistance(infoPtr
, &pt
))
1810 if (!HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_BEGINDRAG
, infoPtr
->iMoveItem
, NULL
))
1812 HIMAGELIST hDragItem
= (HIMAGELIST
)HEADER_CreateDragImage(infoPtr
, infoPtr
->iMoveItem
);
1813 if (hDragItem
!= NULL
)
1815 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1816 TRACE("Starting item drag\n");
1817 ImageList_BeginDrag(hDragItem
, 0, pt
.x
- lpItem
->rect
.left
, 0);
1818 ImageList_DragShowNolock(TRUE
);
1819 ImageList_Destroy(hDragItem
);
1820 infoPtr
->bDragging
= TRUE
;
1825 if (infoPtr
->bDragging
)
1830 ClientToScreen(infoPtr
->hwndSelf
, &drag
);
1831 ImageList_DragMove(drag
.x
, drag
.y
);
1832 HEADER_SetHotDivider(infoPtr
, TRUE
, lParam
);
1835 if (infoPtr
->bPressed
&& !infoPtr
->bDragging
) {
1836 BOOL oldState
= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
;
1837 if ((nItem
== infoPtr
->iMoveItem
) && (flags
== HHT_ONHEADER
))
1838 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= TRUE
;
1840 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1841 if (oldState
!= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
) {
1842 hdc
= GetDC (infoPtr
->hwndSelf
);
1843 HEADER_RefreshItem (infoPtr
, infoPtr
->iMoveItem
);
1844 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1847 TRACE("Moving pressed item %d!\n", infoPtr
->iMoveItem
);
1849 else if (infoPtr
->bTracking
) {
1850 if (infoPtr
->dwStyle
& HDS_FULLDRAG
) {
1851 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1852 nWidth
= pt
.x
- lpItem
->rect
.left
+ infoPtr
->xTrackOffset
;
1853 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, nWidth
))
1855 INT nOldWidth
= lpItem
->rect
.right
- lpItem
->rect
.left
;
1859 if (nWidth
< 0) nWidth
= 0;
1860 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= nWidth
;
1861 HEADER_SetItemBounds(infoPtr
);
1863 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1864 rcScroll
= rcClient
;
1865 rcScroll
.left
= lpItem
->rect
.left
+ nOldWidth
;
1866 ScrollWindowEx(infoPtr
->hwndSelf
, nWidth
- nOldWidth
, 0, &rcScroll
, &rcClient
, NULL
, NULL
, 0);
1867 InvalidateRect(infoPtr
->hwndSelf
, &lpItem
->rect
, FALSE
);
1868 UpdateWindow(infoPtr
->hwndSelf
);
1870 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, nWidth
);
1875 hdc
= GetDC (infoPtr
->hwndSelf
);
1876 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1877 infoPtr
->xOldTrack
= pt
.x
+ infoPtr
->xTrackOffset
;
1878 if (infoPtr
->xOldTrack
< infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
)
1879 infoPtr
->xOldTrack
= infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1880 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1881 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1882 iTrackWidth
= infoPtr
->xOldTrack
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1883 /* FIXME: should stop tracking if HDN_TRACK returns TRUE */
1884 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_TRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iTrackWidth
);
1887 TRACE("Tracking item %d!\n", infoPtr
->iMoveItem
);
1891 if (hotTrackEnabled
) {
1892 TRACKMOUSEEVENT tme
;
1893 if (oldHotItem
!= infoPtr
->iHotItem
&& !infoPtr
->bDragging
) {
1894 hdc
= GetDC (infoPtr
->hwndSelf
);
1895 if (oldHotItem
!= -1) HEADER_RefreshItem (infoPtr
, oldHotItem
);
1896 if (infoPtr
->iHotItem
!= -1) HEADER_RefreshItem (infoPtr
, infoPtr
->iHotItem
);
1897 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1899 tme
.cbSize
= sizeof( tme
);
1900 tme
.dwFlags
= TME_LEAVE
;
1901 tme
.hwndTrack
= infoPtr
->hwndSelf
;
1902 TrackMouseEvent( &tme
);
1910 HEADER_Paint (HEADER_INFO
*infoPtr
, HDC hdcParam
)
1915 hdc
= hdcParam
==0 ? BeginPaint (infoPtr
->hwndSelf
, &ps
) : hdcParam
;
1916 HEADER_Refresh (infoPtr
, hdc
);
1918 EndPaint (infoPtr
->hwndSelf
, &ps
);
1924 HEADER_RButtonUp (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1932 /* Send a Notify message */
1933 bRet
= HEADER_SendSimpleNotify (infoPtr
, NM_RCLICK
);
1935 /* Change to screen coordinate for WM_CONTEXTMENU */
1936 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
1938 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1939 SendMessageW( infoPtr
->hwndSelf
, WM_CONTEXTMENU
, (WPARAM
) infoPtr
->hwndSelf
, MAKELPARAM(pt
.x
, pt
.y
));
1946 HEADER_SetCursor (HEADER_INFO
*infoPtr
, LPARAM lParam
)
1952 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam
), HIWORD(lParam
));
1955 ScreenToClient (infoPtr
->hwndSelf
, &pt
);
1957 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1959 if (flags
== HHT_ONDIVIDER
)
1960 SetCursor (infoPtr
->hcurDivider
);
1961 else if (flags
== HHT_ONDIVOPEN
)
1962 SetCursor (infoPtr
->hcurDivopen
);
1964 SetCursor (infoPtr
->hcurArrow
);
1971 HEADER_SetFont (HEADER_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
1977 infoPtr
->hFont
= hFont
;
1980 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
));
1981 GetTextMetricsW (hdc
, &tm
);
1982 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
1983 SelectObject (hdc
, hOldFont
);
1986 infoPtr
->bRectsValid
= FALSE
;
1989 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1995 static LRESULT
HEADER_SetRedraw(HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1997 /* ignoring the InvalidateRect calls is handled by user32. But some apps expect
1998 * that we invalidate the header and this has to be done manually */
2001 ret
= DefWindowProcW(infoPtr
->hwndSelf
, WM_SETREDRAW
, wParam
, lParam
);
2003 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2007 static INT
HEADER_StyleChanged(HEADER_INFO
*infoPtr
, WPARAM wStyleType
,
2008 const STYLESTRUCT
*lpss
)
2010 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2011 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
2013 if (wStyleType
!= GWL_STYLE
) return 0;
2015 infoPtr
->dwStyle
= lpss
->styleNew
;
2020 /* Update the theme handle after a theme change */
2021 static LRESULT
HEADER_ThemeChanged(const HEADER_INFO
*infoPtr
)
2023 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
2024 CloseThemeData(theme
);
2025 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
2026 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
2031 static LRESULT WINAPI
2032 HEADER_WindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2034 HEADER_INFO
*infoPtr
= (HEADER_INFO
*)GetWindowLongPtrW(hwnd
, 0);
2036 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, msg
, wParam
, lParam
);
2037 if (!infoPtr
&& (msg
!= WM_CREATE
))
2038 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
2040 /* case HDM_CLEARFILTER: */
2042 case HDM_CREATEDRAGIMAGE
:
2043 return HEADER_CreateDragImage (infoPtr
, (INT
)wParam
);
2045 case HDM_DELETEITEM
:
2046 return HEADER_DeleteItem (infoPtr
, (INT
)wParam
);
2048 /* case HDM_EDITFILTER: */
2050 case HDM_GETBITMAPMARGIN
:
2051 return HEADER_GetBitmapMargin(infoPtr
);
2053 case HDM_GETIMAGELIST
:
2054 return HEADER_GetImageList (infoPtr
);
2058 return HEADER_GetItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_GETITEMW
);
2060 case HDM_GETITEMCOUNT
:
2061 return HEADER_GetItemCount (infoPtr
);
2063 case HDM_GETITEMRECT
:
2064 return HEADER_GetItemRect (infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
2066 case HDM_GETORDERARRAY
:
2067 return HEADER_GetOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
2069 case HDM_GETUNICODEFORMAT
:
2070 return HEADER_GetUnicodeFormat (infoPtr
);
2073 return HEADER_HitTest (infoPtr
, (LPHDHITTESTINFO
)lParam
);
2075 case HDM_INSERTITEMA
:
2076 case HDM_INSERTITEMW
:
2077 return HEADER_InsertItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_INSERTITEMW
);
2080 return HEADER_Layout (infoPtr
, (LPHDLAYOUT
)lParam
);
2082 case HDM_ORDERTOINDEX
:
2083 return HEADER_OrderToIndex(infoPtr
, (INT
)wParam
);
2085 case HDM_SETBITMAPMARGIN
:
2086 return HEADER_SetBitmapMargin(infoPtr
, (INT
)wParam
);
2088 /* case HDM_SETFILTERCHANGETIMEOUT: */
2090 case HDM_SETHOTDIVIDER
:
2091 return HEADER_SetHotDivider(infoPtr
, wParam
, lParam
);
2093 case HDM_SETIMAGELIST
:
2094 return HEADER_SetImageList (infoPtr
, (HIMAGELIST
)lParam
);
2098 return HEADER_SetItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_SETITEMW
);
2100 case HDM_SETORDERARRAY
:
2101 return HEADER_SetOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
2103 case HDM_SETUNICODEFORMAT
:
2104 return HEADER_SetUnicodeFormat (infoPtr
, wParam
);
2107 return HEADER_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
2110 return HEADER_Destroy (infoPtr
);
2113 return HEADER_NCDestroy (infoPtr
);
2119 return DLGC_WANTTAB
| DLGC_WANTARROWS
;
2122 return HEADER_GetFont (infoPtr
);
2124 case WM_LBUTTONDBLCLK
:
2125 return HEADER_LButtonDblClk (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2127 case WM_LBUTTONDOWN
:
2128 return HEADER_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2131 return HEADER_LButtonUp (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2134 return HEADER_MouseLeave (infoPtr
);
2137 return HEADER_MouseMove (infoPtr
, lParam
);
2139 case WM_NOTIFYFORMAT
:
2140 return HEADER_NotifyFormat (infoPtr
, wParam
, lParam
);
2143 return HEADER_Size (infoPtr
);
2145 case WM_THEMECHANGED
:
2146 return HEADER_ThemeChanged (infoPtr
);
2148 case WM_PRINTCLIENT
:
2150 return HEADER_Paint (infoPtr
, (HDC
)wParam
);
2153 return HEADER_RButtonUp (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2156 return HEADER_SetCursor (infoPtr
, lParam
);
2159 return HEADER_SetFont (infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
2162 return HEADER_SetRedraw(infoPtr
, wParam
, lParam
);
2164 case WM_STYLECHANGED
:
2165 return HEADER_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
2167 case WM_SYSCOLORCHANGE
:
2168 COMCTL32_RefreshSysColors();
2172 if ((msg
>= WM_USER
) && (msg
< WM_APP
) && !COMCTL32_IsReflectedMessage(msg
))
2173 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
2174 msg
, wParam
, lParam
);
2175 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
2181 HEADER_Register (void)
2185 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2186 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
2187 wndClass
.lpfnWndProc
= HEADER_WindowProc
;
2188 wndClass
.cbClsExtra
= 0;
2189 wndClass
.cbWndExtra
= sizeof(HEADER_INFO
*);
2190 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2191 wndClass
.lpszClassName
= WC_HEADERW
;
2193 RegisterClassW (&wndClass
);
2198 HEADER_Unregister (void)
2200 UnregisterClassW (WC_HEADERW
, NULL
);