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
36 #include "wine/unicode.h"
42 #include "imagelist.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(header
);
57 INT iOrder
; /* see documentation of HD_ITEM */
59 BOOL bDown
; /* is item pressed? (used for drawing) */
60 RECT rect
; /* bounding rectangle of the item */
61 DWORD callbackMask
; /* HDI_* flags for items that are callback */
67 HWND hwndSelf
; /* Control window */
68 HWND hwndNotify
; /* Owner window to send notifications to */
69 INT nNotifyFormat
; /* format used for WM_NOTIFY messages */
70 UINT uNumItem
; /* number of items (columns) */
71 INT nHeight
; /* height of the header (pixels) */
72 HFONT hFont
; /* handle to the current font */
73 HCURSOR hcurArrow
; /* handle to the arrow cursor */
74 HCURSOR hcurDivider
; /* handle to a cursor (used over dividers) <-|-> */
75 HCURSOR hcurDivopen
; /* handle to a cursor (used over dividers) <-||-> */
76 BOOL bCaptured
; /* Is the mouse captured? */
77 BOOL bPressed
; /* Is a header item pressed (down)? */
78 BOOL bDragging
; /* Are we dragging an item? */
79 BOOL bTracking
; /* Is in tracking mode? */
80 POINT ptLButtonDown
; /* The point where the left button was pressed */
81 DWORD dwStyle
; /* the cached window GWL_STYLE */
82 INT iMoveItem
; /* index of tracked item. (Tracking mode) */
83 INT xTrackOffset
; /* distance between the right side of the tracked item and the cursor */
84 INT xOldTrack
; /* track offset (see above) after the last WM_MOUSEMOVE */
85 INT iHotItem
; /* index of hot item (cursor is over this item) */
86 INT iHotDivider
; /* index of the hot divider (used while dragging an item or by HDM_SETHOTDIVIDER) */
87 INT iMargin
; /* width of the margin that surrounds a bitmap */
89 HIMAGELIST himl
; /* handle to an image list (may be 0) */
90 HEADER_ITEM
*items
; /* pointer to array of HEADER_ITEM's */
91 INT
*order
; /* array of item IDs indexed by order */
92 BOOL bRectsValid
; /* validity flag for bounding rectangles */
97 #define DIVIDER_WIDTH 10
98 #define HOT_DIVIDER_WIDTH 2
99 #define MAX_HEADER_TEXT_LEN 260
100 #define HDN_UNICODE_OFFSET 20
101 #define HDN_FIRST_UNICODE (HDN_FIRST-HDN_UNICODE_OFFSET)
103 #define HDI_SUPPORTED_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP|HDI_IMAGE|HDI_ORDER)
104 #define HDI_UNSUPPORTED_FIELDS (HDI_FILTER)
105 #define HDI_UNKNOWN_FIELDS (~(HDI_SUPPORTED_FIELDS|HDI_UNSUPPORTED_FIELDS|HDI_DI_SETITEM))
106 #define HDI_COMCTL32_4_0_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP)
109 static BOOL
HEADER_PrepareCallbackItems(const HEADER_INFO
*infoPtr
, INT iItem
, INT reqMask
);
110 static void HEADER_FreeCallbackItems(HEADER_ITEM
*lpItem
);
111 static LRESULT
HEADER_SendNotify(const HEADER_INFO
*infoPtr
, UINT code
, NMHDR
*hdr
);
112 static LRESULT
HEADER_SendCtrlCustomDraw(const HEADER_INFO
*infoPtr
, DWORD dwDrawStage
, HDC hdc
, const RECT
*rect
);
114 static const WCHAR themeClass
[] = {'H','e','a','d','e','r',0};
116 static void HEADER_StoreHDItemInHeader(HEADER_ITEM
*lpItem
, UINT mask
, const HDITEMW
*phdi
, BOOL fUnicode
)
118 if (mask
& HDI_UNSUPPORTED_FIELDS
)
119 FIXME("unsupported header fields %x\n", (mask
& HDI_UNSUPPORTED_FIELDS
));
121 if (mask
& HDI_BITMAP
)
122 lpItem
->hbm
= phdi
->hbm
;
124 if (mask
& HDI_FORMAT
)
125 lpItem
->fmt
= phdi
->fmt
;
127 if (mask
& HDI_LPARAM
)
128 lpItem
->lParam
= phdi
->lParam
;
130 if (mask
& HDI_WIDTH
)
131 lpItem
->cxy
= phdi
->cxy
;
133 if (mask
& HDI_IMAGE
)
135 lpItem
->iImage
= phdi
->iImage
;
136 if (phdi
->iImage
== I_IMAGECALLBACK
)
137 lpItem
->callbackMask
|= HDI_IMAGE
;
139 lpItem
->callbackMask
&= ~HDI_IMAGE
;
144 Free(lpItem
->pszText
);
145 lpItem
->pszText
= NULL
;
147 if (phdi
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers != TEXTCALLBACKA too */
149 static const WCHAR emptyString
[] = {0};
151 LPCWSTR pszText
= (phdi
->pszText
!= NULL
? phdi
->pszText
: emptyString
);
153 Str_SetPtrW(&lpItem
->pszText
, pszText
);
155 Str_SetPtrAtoW(&lpItem
->pszText
, (LPCSTR
)pszText
);
156 lpItem
->callbackMask
&= ~HDI_TEXT
;
160 lpItem
->pszText
= NULL
;
161 lpItem
->callbackMask
|= HDI_TEXT
;
166 static inline LRESULT
167 HEADER_IndexToOrder (const HEADER_INFO
*infoPtr
, INT iItem
)
169 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
170 return lpItem
->iOrder
;
175 HEADER_OrderToIndex(const HEADER_INFO
*infoPtr
, INT iorder
)
177 if ((iorder
<0) || iorder
>= infoPtr
->uNumItem
)
179 return infoPtr
->order
[iorder
];
183 HEADER_ChangeItemOrder(const HEADER_INFO
*infoPtr
, INT iItem
, INT iNewOrder
)
185 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
188 TRACE("%d: %d->%d\n", iItem
, lpItem
->iOrder
, iNewOrder
);
189 if (lpItem
->iOrder
< iNewOrder
)
191 memmove(&infoPtr
->order
[lpItem
->iOrder
],
192 &infoPtr
->order
[lpItem
->iOrder
+ 1],
193 (iNewOrder
- lpItem
->iOrder
) * sizeof(INT
));
195 if (iNewOrder
< lpItem
->iOrder
)
197 memmove(&infoPtr
->order
[iNewOrder
+ 1],
198 &infoPtr
->order
[iNewOrder
],
199 (lpItem
->iOrder
- iNewOrder
) * sizeof(INT
));
201 infoPtr
->order
[iNewOrder
] = iItem
;
202 nMin
= min(lpItem
->iOrder
, iNewOrder
);
203 nMax
= max(lpItem
->iOrder
, iNewOrder
);
204 for (i
= nMin
; i
<= nMax
; i
++)
205 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
208 /* Note: if iItem is the last item then this function returns infoPtr->uNumItem */
210 HEADER_NextItem(const HEADER_INFO
*infoPtr
, INT iItem
)
212 return HEADER_OrderToIndex(infoPtr
, HEADER_IndexToOrder(infoPtr
, iItem
)+1);
216 HEADER_PrevItem(const HEADER_INFO
*infoPtr
, INT iItem
)
218 return HEADER_OrderToIndex(infoPtr
, HEADER_IndexToOrder(infoPtr
, iItem
)-1);
221 /* TRUE when item is not resizable with dividers,
222 note that valid index should be supplied */
224 HEADER_IsItemFixed(const HEADER_INFO
*infoPtr
, INT iItem
)
226 return (infoPtr
->dwStyle
& HDS_NOSIZING
) || (infoPtr
->items
[iItem
].fmt
& HDF_FIXEDWIDTH
);
230 HEADER_SetItemBounds (HEADER_INFO
*infoPtr
)
237 infoPtr
->bRectsValid
= TRUE
;
239 if (infoPtr
->uNumItem
== 0)
242 GetClientRect (infoPtr
->hwndSelf
, &rect
);
245 for (i
= 0; i
< infoPtr
->uNumItem
; i
++) {
246 phdi
= &infoPtr
->items
[HEADER_OrderToIndex(infoPtr
,i
)];
247 phdi
->rect
.top
= rect
.top
;
248 phdi
->rect
.bottom
= rect
.bottom
;
250 phdi
->rect
.right
= phdi
->rect
.left
+ ((phdi
->cxy
>0)?phdi
->cxy
:0);
251 x
= phdi
->rect
.right
;
256 HEADER_Size (HEADER_INFO
*infoPtr
)
258 HEADER_SetItemBounds(infoPtr
);
262 static void HEADER_GetHotDividerRect(const HEADER_INFO
*infoPtr
, RECT
*r
)
264 INT iDivider
= infoPtr
->iHotDivider
;
265 if (infoPtr
->uNumItem
> 0)
269 if (iDivider
< infoPtr
->uNumItem
)
271 lpItem
= &infoPtr
->items
[iDivider
];
272 r
->left
= lpItem
->rect
.left
- HOT_DIVIDER_WIDTH
/2;
273 r
->right
= lpItem
->rect
.left
+ HOT_DIVIDER_WIDTH
/2;
277 lpItem
= &infoPtr
->items
[HEADER_OrderToIndex(infoPtr
, infoPtr
->uNumItem
-1)];
278 r
->left
= lpItem
->rect
.right
- HOT_DIVIDER_WIDTH
/2;
279 r
->right
= lpItem
->rect
.right
+ HOT_DIVIDER_WIDTH
/2;
281 r
->top
= lpItem
->rect
.top
;
282 r
->bottom
= lpItem
->rect
.bottom
;
287 GetClientRect(infoPtr
->hwndSelf
, &clientRect
);
289 r
->right
= r
->left
+ HOT_DIVIDER_WIDTH
/2;
295 HEADER_DrawItem (HEADER_INFO
*infoPtr
, HDC hdc
, INT iItem
, BOOL bHotTrack
, LRESULT lCDFlags
)
297 HEADER_ITEM
*phdi
= &infoPtr
->items
[iItem
];
300 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
303 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem
, bHotTrack
, (infoPtr
->nNotifyFormat
== NFR_UNICODE
));
306 if (r
.right
- r
.left
== 0)
307 return phdi
->rect
.right
;
309 /* Set the colors before sending NM_CUSTOMDRAW so that it can change them */
310 SetTextColor(hdc
, (bHotTrack
&& !theme
) ? COLOR_HIGHLIGHT
: COLOR_BTNTEXT
);
311 SetBkColor(hdc
, comctl32_color
.clr3dFace
);
313 if (lCDFlags
& CDRF_NOTIFYITEMDRAW
&& !(phdi
->fmt
& HDF_OWNERDRAW
))
315 LRESULT lCDItemFlags
;
317 nmcd
.dwDrawStage
= CDDS_PREPAINT
| CDDS_ITEM
;
319 nmcd
.dwItemSpec
= iItem
;
321 nmcd
.uItemState
= phdi
->bDown
? CDIS_SELECTED
: 0;
322 nmcd
.lItemlParam
= phdi
->lParam
;
324 lCDItemFlags
= HEADER_SendNotify(infoPtr
, NM_CUSTOMDRAW
, (NMHDR
*)&nmcd
);
325 if (lCDItemFlags
& CDRF_SKIPDEFAULT
)
326 return phdi
->rect
.right
;
330 int state
= (phdi
->bDown
) ? HIS_PRESSED
:
331 (bHotTrack
? HIS_HOT
: HIS_NORMAL
);
332 DrawThemeBackground (theme
, hdc
, HP_HEADERITEM
, state
,
334 GetThemeBackgroundContentRect (theme
, hdc
, HP_HEADERITEM
, state
,
340 if (!(infoPtr
->dwStyle
& HDS_FLAT
))
342 if (infoPtr
->dwStyle
& HDS_BUTTONS
) {
344 DrawEdge (hdc
, &r
, BDR_RAISEDOUTER
,
345 BF_RECT
| BF_FLAT
| BF_MIDDLE
| BF_ADJUST
);
348 DrawEdge (hdc
, &r
, EDGE_RAISED
,
349 BF_RECT
| BF_SOFT
| BF_MIDDLE
| BF_ADJUST
);
352 DrawEdge (hdc
, &r
, EDGE_ETCHED
, BF_BOTTOM
| BF_RIGHT
| BF_ADJUST
);
355 hbr
= CreateSolidBrush(GetBkColor(hdc
));
356 FillRect(hdc
, &r
, hbr
);
364 if (phdi
->fmt
& HDF_OWNERDRAW
) {
367 dis
.CtlType
= ODT_HEADER
;
368 dis
.CtlID
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
370 dis
.itemAction
= ODA_DRAWENTIRE
;
371 dis
.itemState
= phdi
->bDown
? ODS_SELECTED
: 0;
372 dis
.hwndItem
= infoPtr
->hwndSelf
;
374 dis
.rcItem
= phdi
->rect
;
375 dis
.itemData
= phdi
->lParam
;
376 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
377 SendMessageW (infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
378 if (oldBkMode
!= TRANSPARENT
)
379 SetBkMode(hdc
, oldBkMode
);
382 UINT rw
, rh
, /* width and height of r */
383 *x
= NULL
, *w
= NULL
; /* x and width of the pic (bmp or img) which is part of cnt */
384 /* cnt,txt,img,bmp */
389 HEADER_PrepareCallbackItems(infoPtr
, iItem
, HDI_TEXT
|HDI_IMAGE
);
390 cw
= tw
= iw
= bw
= 0;
391 rw
= r
.right
- r
.left
;
392 rh
= r
.bottom
- r
.top
;
394 if (phdi
->fmt
& HDF_STRING
) {
397 SetRectEmpty(&textRect
);
398 DrawTextW (hdc
, phdi
->pszText
, -1,
399 &textRect
, DT_LEFT
|DT_VCENTER
|DT_SINGLELINE
|DT_CALCRECT
);
400 cw
= textRect
.right
- textRect
.left
+ 2 * infoPtr
->iMargin
;
403 if ((phdi
->fmt
& HDF_IMAGE
) && (infoPtr
->himl
)) {
404 iw
= infoPtr
->himl
->cx
+ 2 * infoPtr
->iMargin
;
409 if ((phdi
->fmt
& HDF_BITMAP
) && (phdi
->hbm
)) {
410 GetObjectW (phdi
->hbm
, sizeof(BITMAP
), &bmp
);
411 bw
= bmp
.bmWidth
+ 2 * infoPtr
->iMargin
;
421 /* align cx using the unclipped cw */
422 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_LEFT
)
424 else if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_CENTER
)
425 cx
= r
.left
+ rw
/ 2 - cw
/ 2;
432 if (cx
+ cw
> r
.right
)
435 tx
= cx
+ infoPtr
->iMargin
;
436 /* since cw might have changed we have to recalculate tw */
437 tw
= cw
- infoPtr
->iMargin
* 2;
441 if (phdi
->fmt
& HDF_BITMAP_ON_RIGHT
) {
442 /* put pic behind text */
443 *x
= cx
+ tw
+ infoPtr
->iMargin
* 3;
445 *x
= cx
+ infoPtr
->iMargin
;
446 /* move text behind pic */
452 /* since we're done with the layout we can
453 now calculate the position of bmp which
454 has no influence on alignment and layout
456 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_RIGHT
)
457 bx
= cx
- bw
+ infoPtr
->iMargin
;
459 bx
= cx
+ cw
+ infoPtr
->iMargin
;
463 HDC hClipDC
= GetDC(infoPtr
->hwndSelf
);
464 HRGN hClipRgn
= CreateRectRgn(r
.left
, r
.top
, r
.right
, r
.bottom
);
465 SelectClipRgn(hClipDC
, hClipRgn
);
468 HDC hdcBitmap
= CreateCompatibleDC (hClipDC
);
469 SelectObject (hdcBitmap
, phdi
->hbm
);
470 BitBlt (hClipDC
, bx
, r
.top
+ ((INT
)rh
- bmp
.bmHeight
) / 2,
471 bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
472 DeleteDC (hdcBitmap
);
476 ImageList_DrawEx (infoPtr
->himl
, phdi
->iImage
, hClipDC
,
477 ix
, r
.top
+ ((INT
)rh
- infoPtr
->himl
->cy
) / 2,
478 infoPtr
->himl
->cx
, infoPtr
->himl
->cy
, CLR_DEFAULT
, CLR_DEFAULT
, 0);
481 DeleteObject(hClipRgn
);
482 ReleaseDC(infoPtr
->hwndSelf
, hClipDC
);
485 if (((phdi
->fmt
& HDF_STRING
)
486 || (!(phdi
->fmt
& (HDF_OWNERDRAW
|HDF_STRING
|HDF_BITMAP
|
487 HDF_BITMAP_ON_RIGHT
|HDF_IMAGE
)))) /* no explicit format specified? */
488 && (phdi
->pszText
)) {
489 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
492 DrawTextW (hdc
, phdi
->pszText
, -1,
493 &r
, DT_LEFT
|DT_END_ELLIPSIS
|DT_VCENTER
|DT_SINGLELINE
);
494 if (oldBkMode
!= TRANSPARENT
)
495 SetBkMode(hdc
, oldBkMode
);
497 HEADER_FreeCallbackItems(phdi
);
500 return phdi
->rect
.right
;
504 HEADER_DrawHotDivider(const HEADER_INFO
*infoPtr
, HDC hdc
)
509 HEADER_GetHotDividerRect(infoPtr
, &r
);
510 brush
= CreateSolidBrush(comctl32_color
.clrHighlight
);
511 FillRect(hdc
, &r
, brush
);
516 HEADER_Refresh (HEADER_INFO
*infoPtr
, HDC hdc
)
518 HFONT hFont
, hOldFont
;
524 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
526 if (!infoPtr
->bRectsValid
)
527 HEADER_SetItemBounds(infoPtr
);
529 /* get rect for the bar, adjusted for the border */
530 GetClientRect (infoPtr
->hwndSelf
, &rect
);
531 lCDFlags
= HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_PREPAINT
, hdc
, &rect
);
533 if (infoPtr
->bDragging
)
534 ImageList_DragShowNolock(FALSE
);
536 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
);
537 hOldFont
= SelectObject (hdc
, hFont
);
539 /* draw Background */
540 if (infoPtr
->uNumItem
== 0 && theme
== NULL
) {
541 hbrBk
= GetSysColorBrush(COLOR_3DFACE
);
542 FillRect(hdc
, &rect
, hbrBk
);
546 for (i
= 0; x
<= rect
.right
&& i
< infoPtr
->uNumItem
; i
++) {
547 int idx
= HEADER_OrderToIndex(infoPtr
,i
);
548 if (RectVisible(hdc
, &infoPtr
->items
[idx
].rect
))
549 HEADER_DrawItem(infoPtr
, hdc
, idx
, infoPtr
->iHotItem
== idx
, lCDFlags
);
550 x
= infoPtr
->items
[idx
].rect
.right
;
555 if ((x
<= rect
.right
) && RectVisible(hdc
, &rcRest
) && (infoPtr
->uNumItem
> 0)) {
557 DrawThemeBackground(theme
, hdc
, HP_HEADERITEM
, HIS_NORMAL
, &rcRest
, NULL
);
559 else if (infoPtr
->dwStyle
& HDS_FLAT
) {
560 hbrBk
= GetSysColorBrush(COLOR_3DFACE
);
561 FillRect(hdc
, &rcRest
, hbrBk
);
565 if (infoPtr
->dwStyle
& HDS_BUTTONS
)
566 DrawEdge (hdc
, &rcRest
, EDGE_RAISED
, BF_TOP
|BF_LEFT
|BF_BOTTOM
|BF_SOFT
|BF_MIDDLE
);
568 DrawEdge (hdc
, &rcRest
, EDGE_ETCHED
, BF_BOTTOM
|BF_MIDDLE
);
572 if (infoPtr
->iHotDivider
!= -1)
573 HEADER_DrawHotDivider(infoPtr
, hdc
);
575 if (infoPtr
->bDragging
)
576 ImageList_DragShowNolock(TRUE
);
577 SelectObject (hdc
, hOldFont
);
579 if (lCDFlags
& CDRF_NOTIFYPOSTPAINT
)
580 HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_POSTPAINT
, hdc
, &rect
);
585 HEADER_RefreshItem (HEADER_INFO
*infoPtr
, INT iItem
)
587 if (!infoPtr
->bRectsValid
)
588 HEADER_SetItemBounds(infoPtr
);
590 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->items
[iItem
].rect
, FALSE
);
595 HEADER_InternalHitTest (const HEADER_INFO
*infoPtr
, const POINT
*lpPt
, UINT
*pFlags
, INT
*pItem
)
602 GetClientRect (infoPtr
->hwndSelf
, &rect
);
606 if (PtInRect (&rect
, *lpPt
))
608 if (infoPtr
->uNumItem
== 0) {
609 *pFlags
|= HHT_NOWHERE
;
615 /* somewhere inside */
616 for (iCount
= 0; iCount
< infoPtr
->uNumItem
; iCount
++) {
617 rect
= infoPtr
->items
[iCount
].rect
;
618 width
= rect
.right
- rect
.left
;
623 if (PtInRect (&rect
, *lpPt
)) {
624 if (width
<= 2 * DIVIDER_WIDTH
) {
625 *pFlags
|= HHT_ONHEADER
;
627 TRACE("ON HEADER %d\n", iCount
);
630 if (HEADER_IndexToOrder(infoPtr
, iCount
) > 0) {
632 rcTest
.right
= rcTest
.left
+ DIVIDER_WIDTH
;
633 if (PtInRect (&rcTest
, *lpPt
)) {
634 if (HEADER_IsItemFixed(infoPtr
, HEADER_PrevItem(infoPtr
, iCount
)))
636 *pFlags
|= HHT_ONHEADER
;
638 TRACE("ON HEADER %d\n", *pItem
);
642 *pFlags
|= HHT_ONDIVOPEN
;
643 *pItem
= HEADER_PrevItem(infoPtr
, iCount
);
644 TRACE("ON DIVOPEN %d\n", *pItem
);
648 *pFlags
|= HHT_ONDIVIDER
;
649 *pItem
= HEADER_PrevItem(infoPtr
, iCount
);
650 TRACE("ON DIVIDER %d\n", *pItem
);
656 rcTest
.left
= rcTest
.right
- DIVIDER_WIDTH
;
657 if (!HEADER_IsItemFixed(infoPtr
, iCount
) && PtInRect (&rcTest
, *lpPt
))
659 *pFlags
|= HHT_ONDIVIDER
;
661 TRACE("ON DIVIDER %d\n", *pItem
);
665 *pFlags
|= HHT_ONHEADER
;
667 TRACE("ON HEADER %d\n", iCount
);
672 /* check for last divider part (on nowhere) */
673 if (!HEADER_IsItemFixed(infoPtr
, infoPtr
->uNumItem
- 1))
675 rect
= infoPtr
->items
[infoPtr
->uNumItem
-1].rect
;
676 rect
.left
= rect
.right
;
677 rect
.right
+= DIVIDER_WIDTH
;
678 if (PtInRect (&rect
, *lpPt
)) {
680 *pFlags
|= HHT_ONDIVOPEN
;
681 *pItem
= infoPtr
->uNumItem
- 1;
682 TRACE("ON DIVOPEN %d\n", *pItem
);
686 *pFlags
|= HHT_ONDIVIDER
;
687 *pItem
= infoPtr
->uNumItem
- 1;
688 TRACE("ON DIVIDER %d\n", *pItem
);
694 *pFlags
|= HHT_NOWHERE
;
701 if (lpPt
->x
< rect
.left
) {
703 *pFlags
|= HHT_TOLEFT
;
705 else if (lpPt
->x
> rect
.right
) {
707 *pFlags
|= HHT_TORIGHT
;
710 if (lpPt
->y
< rect
.top
) {
712 *pFlags
|= HHT_ABOVE
;
714 else if (lpPt
->y
> rect
.bottom
) {
716 *pFlags
|= HHT_BELOW
;
721 TRACE("flags=0x%X\n", *pFlags
);
727 HEADER_DrawTrackLine (const HEADER_INFO
*infoPtr
, HDC hdc
, INT x
)
733 GetClientRect (infoPtr
->hwndSelf
, &rect
);
735 hOldPen
= SelectObject (hdc
, GetStockObject (BLACK_PEN
));
736 oldRop
= SetROP2 (hdc
, R2_XORPEN
);
737 MoveToEx (hdc
, x
, rect
.top
, NULL
);
738 LineTo (hdc
, x
, rect
.bottom
);
739 SetROP2 (hdc
, oldRop
);
740 SelectObject (hdc
, hOldPen
);
745 * Convert a HDITEM into the correct format (ANSI/Unicode) to send it in a notify
748 * [I] infoPtr : the header that wants to send the notify
749 * [O] dest : The buffer to store the HDITEM for notify. It may be set to a HDITEMA of HDITEMW
750 * [I] src : The source HDITEM. It may be a HDITEMA or HDITEMW
751 * [I] fSourceUnicode : is src a HDITEMW or HDITEMA
752 * [O] ppvScratch : a pointer to a scratch buffer that needs to be freed after
753 * the HDITEM is no longer in use or NULL if none was needed
755 * NOTE: We depend on HDITEMA and HDITEMW having the same structure
757 static void HEADER_CopyHDItemForNotify(const HEADER_INFO
*infoPtr
, HDITEMW
*dest
,
758 const HDITEMW
*src
, BOOL fSourceUnicode
, LPVOID
*ppvScratch
)
763 if (src
->mask
& HDI_TEXT
&& src
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers TEXTCALLBACKA as well */
765 if (fSourceUnicode
&& infoPtr
->nNotifyFormat
!= NFR_UNICODE
)
767 dest
->pszText
= NULL
;
768 Str_SetPtrWtoA((LPSTR
*)&dest
->pszText
, src
->pszText
);
769 *ppvScratch
= dest
->pszText
;
772 if (!fSourceUnicode
&& infoPtr
->nNotifyFormat
== NFR_UNICODE
)
774 dest
->pszText
= NULL
;
775 Str_SetPtrAtoW(&dest
->pszText
, (LPSTR
)src
->pszText
);
776 *ppvScratch
= dest
->pszText
;
781 static UINT
HEADER_NotifyCodeWtoA(UINT code
)
783 /* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
784 if (code
>= HDN_LAST
&& code
<= HDN_FIRST_UNICODE
)
785 return code
+ HDN_UNICODE_OFFSET
;
791 HEADER_SendNotify(const HEADER_INFO
*infoPtr
, UINT code
, NMHDR
*nmhdr
)
793 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
794 nmhdr
->idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
797 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
798 nmhdr
->idFrom
, (LPARAM
)nmhdr
);
802 HEADER_SendSimpleNotify (const HEADER_INFO
*infoPtr
, UINT code
)
805 return (BOOL
)HEADER_SendNotify(infoPtr
, code
, &nmhdr
);
809 HEADER_SendCtrlCustomDraw(const HEADER_INFO
*infoPtr
, DWORD dwDrawStage
, HDC hdc
, const RECT
*rect
)
812 nm
.dwDrawStage
= dwDrawStage
;
819 return HEADER_SendNotify(infoPtr
, NM_CUSTOMDRAW
, (NMHDR
*)&nm
);
823 HEADER_SendNotifyWithHDItemT(const HEADER_INFO
*infoPtr
, UINT code
, INT iItem
, HDITEMW
*lpItem
)
827 if (infoPtr
->nNotifyFormat
!= NFR_UNICODE
)
828 code
= HEADER_NotifyCodeWtoA(code
);
831 nmhdr
.pitem
= lpItem
;
833 return (BOOL
)HEADER_SendNotify(infoPtr
, code
, (NMHDR
*)&nmhdr
);
837 HEADER_SendNotifyWithIntFieldT(const HEADER_INFO
*infoPtr
, UINT code
, INT iItem
, INT mask
, INT iValue
)
841 /* copying only the iValue should be ok but to make the code more robust we copy everything */
842 nmitem
.cxy
= infoPtr
->items
[iItem
].cxy
;
843 nmitem
.hbm
= infoPtr
->items
[iItem
].hbm
;
844 nmitem
.pszText
= NULL
;
845 nmitem
.cchTextMax
= 0;
846 nmitem
.fmt
= infoPtr
->items
[iItem
].fmt
;
847 nmitem
.lParam
= infoPtr
->items
[iItem
].lParam
;
848 nmitem
.iOrder
= infoPtr
->items
[iItem
].iOrder
;
849 nmitem
.iImage
= infoPtr
->items
[iItem
].iImage
;
858 nmitem
.iOrder
= iValue
;
861 ERR("invalid mask value 0x%x\n", iValue
);
864 return HEADER_SendNotifyWithHDItemT(infoPtr
, code
, iItem
, &nmitem
);
868 * Prepare callback items
869 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
870 * (so we handle the two cases only doing a specific cast for pszText).
871 * Checks if any of the required field are callback. If there are sends a
872 * NMHDISPINFO notify to retrieve these items. The items are stored in the
873 * HEADER_ITEM pszText and iImage fields. They should be freed with
874 * HEADER_FreeCallbackItems.
876 * @param hwnd : hwnd header container handler
877 * @param iItem : the header item id
878 * @param reqMask : required fields. If any of them is callback this function will fetch it
880 * @return TRUE on success, else FALSE
883 HEADER_PrepareCallbackItems(const HEADER_INFO
*infoPtr
, INT iItem
, INT reqMask
)
885 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
886 DWORD mask
= reqMask
& lpItem
->callbackMask
;
887 NMHDDISPINFOW dispInfo
;
888 void *pvBuffer
= NULL
;
892 if (mask
&HDI_TEXT
&& lpItem
->pszText
!= NULL
)
894 ERR("(): function called without a call to FreeCallbackItems\n");
895 Free(lpItem
->pszText
);
896 lpItem
->pszText
= NULL
;
899 memset(&dispInfo
, 0, sizeof(NMHDDISPINFOW
));
900 dispInfo
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
901 dispInfo
.hdr
.idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
902 if (infoPtr
->nNotifyFormat
== NFR_UNICODE
)
904 dispInfo
.hdr
.code
= HDN_GETDISPINFOW
;
906 pvBuffer
= Alloc(MAX_HEADER_TEXT_LEN
* sizeof(WCHAR
));
910 dispInfo
.hdr
.code
= HDN_GETDISPINFOA
;
912 pvBuffer
= Alloc(MAX_HEADER_TEXT_LEN
* sizeof(CHAR
));
914 dispInfo
.pszText
= pvBuffer
;
915 dispInfo
.cchTextMax
= (pvBuffer
!=NULL
?MAX_HEADER_TEXT_LEN
:0);
916 dispInfo
.iItem
= iItem
;
917 dispInfo
.mask
= mask
;
918 dispInfo
.lParam
= lpItem
->lParam
;
920 TRACE("Sending HDN_GETDISPINFO%c\n", infoPtr
->nNotifyFormat
== NFR_UNICODE
?'W':'A');
921 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, dispInfo
.hdr
.idFrom
, (LPARAM
)&dispInfo
);
923 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
925 (infoPtr
->nNotifyFormat
== NFR_UNICODE
? debugstr_w(dispInfo
.pszText
) : (LPSTR
) dispInfo
.pszText
),
926 (void*) dispInfo
.lParam
);
928 if (mask
& HDI_IMAGE
)
929 lpItem
->iImage
= dispInfo
.iImage
;
932 if (infoPtr
->nNotifyFormat
== NFR_UNICODE
)
934 lpItem
->pszText
= pvBuffer
;
936 /* the user might have used his own buffer */
937 if (dispInfo
.pszText
!= lpItem
->pszText
)
938 Str_GetPtrW(dispInfo
.pszText
, lpItem
->pszText
, MAX_HEADER_TEXT_LEN
);
942 Str_SetPtrAtoW(&lpItem
->pszText
, (LPSTR
)dispInfo
.pszText
);
947 if (dispInfo
.mask
& HDI_DI_SETITEM
)
949 /* make the items permanent */
950 lpItem
->callbackMask
&= ~dispInfo
.mask
;
958 * Free the items that might be allocated with HEADER_PrepareCallbackItems
961 * [I] lpItem : the item to free the data
965 HEADER_FreeCallbackItems(HEADER_ITEM
*lpItem
)
967 if (lpItem
->callbackMask
&HDI_TEXT
)
969 Free(lpItem
->pszText
);
970 lpItem
->pszText
= NULL
;
973 if (lpItem
->callbackMask
&HDI_IMAGE
)
974 lpItem
->iImage
= I_IMAGECALLBACK
;
978 HEADER_CreateDragImage (HEADER_INFO
*infoPtr
, INT iItem
)
982 HBITMAP hMemory
, hOldBitmap
;
990 if (iItem
>= infoPtr
->uNumItem
)
993 if (!infoPtr
->bRectsValid
)
994 HEADER_SetItemBounds(infoPtr
);
996 lpItem
= &infoPtr
->items
[iItem
];
997 width
= lpItem
->rect
.right
- lpItem
->rect
.left
;
998 height
= lpItem
->rect
.bottom
- lpItem
->rect
.top
;
1000 hDeviceDC
= GetDC(NULL
);
1001 hMemoryDC
= CreateCompatibleDC(hDeviceDC
);
1002 hMemory
= CreateCompatibleBitmap(hDeviceDC
, width
, height
);
1003 ReleaseDC(NULL
, hDeviceDC
);
1004 hOldBitmap
= SelectObject(hMemoryDC
, hMemory
);
1005 SetViewportOrgEx(hMemoryDC
, -lpItem
->rect
.left
, -lpItem
->rect
.top
, NULL
);
1006 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject(SYSTEM_FONT
);
1007 SelectObject(hMemoryDC
, hFont
);
1009 GetClientRect(infoPtr
->hwndSelf
, &rc
);
1010 lCDFlags
= HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_PREPAINT
, hMemoryDC
, &rc
);
1011 HEADER_DrawItem(infoPtr
, hMemoryDC
, iItem
, FALSE
, lCDFlags
);
1012 if (lCDFlags
& CDRF_NOTIFYPOSTPAINT
)
1013 HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_POSTPAINT
, hMemoryDC
, &rc
);
1015 hMemory
= SelectObject(hMemoryDC
, hOldBitmap
);
1016 DeleteDC(hMemoryDC
);
1018 if (hMemory
== NULL
) /* if anything failed */
1021 himl
= ImageList_Create(width
, height
, ILC_COLORDDB
, 1, 1);
1022 ImageList_Add(himl
, hMemory
, NULL
);
1023 DeleteObject(hMemory
);
1024 return (LRESULT
)himl
;
1028 HEADER_SetHotDivider(HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1037 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1039 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &iDivider
);
1041 if (flags
& HHT_TOLEFT
)
1043 else if (flags
& HHT_NOWHERE
|| flags
& HHT_TORIGHT
)
1044 iDivider
= infoPtr
->uNumItem
;
1047 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iDivider
];
1048 if (pt
.x
> (lpItem
->rect
.left
+lpItem
->rect
.right
)/2)
1049 iDivider
= HEADER_NextItem(infoPtr
, iDivider
);
1053 iDivider
= (INT
)lParam
;
1055 /* Note; wParam==FALSE, lParam==-1 is valid and is used to clear the hot divider */
1056 if (iDivider
<-1 || iDivider
>(int)infoPtr
->uNumItem
)
1059 if (iDivider
!= infoPtr
->iHotDivider
)
1061 if (infoPtr
->iHotDivider
!= -1)
1063 HEADER_GetHotDividerRect(infoPtr
, &r
);
1064 InvalidateRect(infoPtr
->hwndSelf
, &r
, FALSE
);
1066 infoPtr
->iHotDivider
= iDivider
;
1069 HEADER_GetHotDividerRect(infoPtr
, &r
);
1070 InvalidateRect(infoPtr
->hwndSelf
, &r
, FALSE
);
1077 HEADER_DeleteItem (HEADER_INFO
*infoPtr
, INT iItem
)
1082 TRACE("[iItem=%d]\n", iItem
);
1084 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
1087 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1088 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
1090 iOrder
= infoPtr
->items
[iItem
].iOrder
;
1091 Free(infoPtr
->items
[iItem
].pszText
);
1093 infoPtr
->uNumItem
--;
1094 memmove(&infoPtr
->items
[iItem
], &infoPtr
->items
[iItem
+ 1],
1095 (infoPtr
->uNumItem
- iItem
) * sizeof(HEADER_ITEM
));
1096 memmove(&infoPtr
->order
[iOrder
], &infoPtr
->order
[iOrder
+ 1],
1097 (infoPtr
->uNumItem
- iOrder
) * sizeof(INT
));
1098 infoPtr
->items
= ReAlloc(infoPtr
->items
, sizeof(HEADER_ITEM
) * infoPtr
->uNumItem
);
1099 infoPtr
->order
= ReAlloc(infoPtr
->order
, sizeof(INT
) * infoPtr
->uNumItem
);
1101 /* Correct the orders */
1102 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1104 if (infoPtr
->order
[i
] > iItem
)
1105 infoPtr
->order
[i
]--;
1107 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
1109 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1110 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
1112 HEADER_SetItemBounds (infoPtr
);
1113 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1120 HEADER_GetImageList (const HEADER_INFO
*infoPtr
)
1122 return (LRESULT
)infoPtr
->himl
;
1127 HEADER_GetItemT (const HEADER_INFO
*infoPtr
, INT nItem
, LPHDITEMW phdi
, BOOL bUnicode
)
1129 HEADER_ITEM
*lpItem
;
1135 TRACE("[nItem=%d]\n", nItem
);
1141 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
1144 if (mask
& HDI_UNKNOWN_FIELDS
)
1146 TRACE("mask %x contains unknown fields. Using only comctl32 4.0 fields\n", mask
);
1147 mask
&= HDI_COMCTL32_4_0_FIELDS
;
1150 lpItem
= &infoPtr
->items
[nItem
];
1151 HEADER_PrepareCallbackItems(infoPtr
, nItem
, mask
);
1153 if (mask
& HDI_BITMAP
)
1154 phdi
->hbm
= lpItem
->hbm
;
1156 if (mask
& HDI_FORMAT
)
1157 phdi
->fmt
= lpItem
->fmt
;
1159 if (mask
& HDI_WIDTH
)
1160 phdi
->cxy
= lpItem
->cxy
;
1162 if (mask
& HDI_LPARAM
)
1163 phdi
->lParam
= lpItem
->lParam
;
1165 if (mask
& HDI_IMAGE
)
1166 phdi
->iImage
= lpItem
->iImage
;
1168 if (mask
& HDI_ORDER
)
1169 phdi
->iOrder
= lpItem
->iOrder
;
1171 if (mask
& HDI_TEXT
)
1174 Str_GetPtrW (lpItem
->pszText
, phdi
->pszText
, phdi
->cchTextMax
);
1176 Str_GetPtrWtoA (lpItem
->pszText
, (LPSTR
)phdi
->pszText
, phdi
->cchTextMax
);
1179 HEADER_FreeCallbackItems(lpItem
);
1184 static inline LRESULT
1185 HEADER_GetItemCount (const HEADER_INFO
*infoPtr
)
1187 return infoPtr
->uNumItem
;
1192 HEADER_GetItemRect (const HEADER_INFO
*infoPtr
, INT iItem
, LPRECT lpRect
)
1194 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
1197 lpRect
->left
= infoPtr
->items
[iItem
].rect
.left
;
1198 lpRect
->right
= infoPtr
->items
[iItem
].rect
.right
;
1199 lpRect
->top
= infoPtr
->items
[iItem
].rect
.top
;
1200 lpRect
->bottom
= infoPtr
->items
[iItem
].rect
.bottom
;
1207 HEADER_GetOrderArray(const HEADER_INFO
*infoPtr
, INT size
, LPINT order
)
1209 if ((UINT
)size
<infoPtr
->uNumItem
)
1212 memcpy(order
, infoPtr
->order
, infoPtr
->uNumItem
* sizeof(INT
));
1216 /* Returns index of first duplicate 'value' from [0,to) range,
1217 or -1 if there isn't any */
1218 static INT
has_duplicate(INT
*array
, INT to
, INT value
)
1221 for(i
= 0; i
< to
; i
++)
1222 if (array
[i
] == value
) return i
;
1226 /* returns next available value from [0,max] not to duplicate in [0,to) */
1227 static INT
get_nextvalue(INT
*array
, INT to
, INT max
)
1230 for(i
= 0; i
< max
; i
++)
1231 if (has_duplicate(array
, to
, i
) == -1) return i
;
1236 HEADER_SetOrderArray(HEADER_INFO
*infoPtr
, INT size
, const INT
*order
)
1238 HEADER_ITEM
*lpItem
;
1241 if ((UINT
)size
!= infoPtr
->uNumItem
)
1244 for (i
=0; i
<size
; i
++)
1246 if (order
[i
] >= size
|| order
[i
] < 0)
1247 /* on invalid index get next available */
1248 /* FIXME: if i==0 array item is out of range behaviour is
1249 different, see tests */
1250 infoPtr
->order
[i
] = get_nextvalue(infoPtr
->order
, i
, size
);
1255 infoPtr
->order
[i
] = order
[i
];
1257 /* remove duplicates */
1258 while ((dup
= has_duplicate(infoPtr
->order
, j
, order
[j
])) != -1)
1262 next
= get_nextvalue(infoPtr
->order
, j
, size
);
1263 infoPtr
->order
[dup
] = next
;
1268 /* sync with item data */
1269 for (i
=0; i
<size
; i
++)
1271 lpItem
= &infoPtr
->items
[infoPtr
->order
[i
]];
1274 HEADER_SetItemBounds(infoPtr
);
1275 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1279 static inline LRESULT
1280 HEADER_GetUnicodeFormat (const HEADER_INFO
*infoPtr
)
1282 return (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1287 HEADER_HitTest (const HEADER_INFO
*infoPtr
, LPHDHITTESTINFO phti
)
1289 UINT outside
= HHT_NOWHERE
| HHT_ABOVE
| HHT_BELOW
| HHT_TOLEFT
| HHT_TORIGHT
;
1291 HEADER_InternalHitTest (infoPtr
, &phti
->pt
, &phti
->flags
, &phti
->iItem
);
1293 if (phti
->flags
& outside
)
1294 return phti
->iItem
= -1;
1301 HEADER_InsertItemT (HEADER_INFO
*infoPtr
, INT nItem
, const HDITEMW
*phdi
, BOOL bUnicode
)
1303 HEADER_ITEM
*lpItem
;
1308 if ((phdi
== NULL
) || (nItem
< 0) || (phdi
->mask
== 0))
1311 if (nItem
> infoPtr
->uNumItem
)
1312 nItem
= infoPtr
->uNumItem
;
1314 iOrder
= (phdi
->mask
& HDI_ORDER
) ? phdi
->iOrder
: nItem
;
1317 else if (infoPtr
->uNumItem
< iOrder
)
1318 iOrder
= infoPtr
->uNumItem
;
1320 infoPtr
->uNumItem
++;
1321 infoPtr
->items
= ReAlloc(infoPtr
->items
, sizeof(HEADER_ITEM
) * infoPtr
->uNumItem
);
1322 infoPtr
->order
= ReAlloc(infoPtr
->order
, sizeof(INT
) * infoPtr
->uNumItem
);
1324 /* make space for the new item */
1325 memmove(&infoPtr
->items
[nItem
+ 1], &infoPtr
->items
[nItem
],
1326 (infoPtr
->uNumItem
- nItem
- 1) * sizeof(HEADER_ITEM
));
1327 memmove(&infoPtr
->order
[iOrder
+ 1], &infoPtr
->order
[iOrder
],
1328 (infoPtr
->uNumItem
- iOrder
- 1) * sizeof(INT
));
1330 /* update the order array */
1331 infoPtr
->order
[iOrder
] = nItem
;
1332 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1334 if (i
!= iOrder
&& infoPtr
->order
[i
] >= nItem
)
1335 infoPtr
->order
[i
]++;
1336 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
1339 lpItem
= &infoPtr
->items
[nItem
];
1340 ZeroMemory(lpItem
, sizeof(HEADER_ITEM
));
1341 /* cxy, fmt and lParam are copied even if not in the HDITEM mask */
1342 copyMask
= phdi
->mask
| HDI_WIDTH
| HDI_FORMAT
| HDI_LPARAM
;
1343 HEADER_StoreHDItemInHeader(lpItem
, copyMask
, phdi
, bUnicode
);
1344 lpItem
->iOrder
= iOrder
;
1346 /* set automatically some format bits */
1347 if (phdi
->mask
& HDI_TEXT
)
1348 lpItem
->fmt
|= HDF_STRING
;
1350 lpItem
->fmt
&= ~HDF_STRING
;
1352 if (lpItem
->hbm
!= NULL
)
1353 lpItem
->fmt
|= HDF_BITMAP
;
1355 lpItem
->fmt
&= ~HDF_BITMAP
;
1357 if (phdi
->mask
& HDI_IMAGE
)
1358 lpItem
->fmt
|= HDF_IMAGE
;
1360 HEADER_SetItemBounds (infoPtr
);
1361 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1368 HEADER_Layout (HEADER_INFO
*infoPtr
, LPHDLAYOUT lpLayout
)
1370 lpLayout
->pwpos
->hwnd
= infoPtr
->hwndSelf
;
1371 lpLayout
->pwpos
->hwndInsertAfter
= 0;
1372 lpLayout
->pwpos
->x
= lpLayout
->prc
->left
;
1373 lpLayout
->pwpos
->y
= lpLayout
->prc
->top
;
1374 lpLayout
->pwpos
->cx
= lpLayout
->prc
->right
- lpLayout
->prc
->left
;
1375 if (infoPtr
->dwStyle
& HDS_HIDDEN
)
1376 lpLayout
->pwpos
->cy
= 0;
1378 lpLayout
->pwpos
->cy
= infoPtr
->nHeight
;
1379 lpLayout
->prc
->top
+= infoPtr
->nHeight
;
1381 lpLayout
->pwpos
->flags
= SWP_NOZORDER
;
1383 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1384 lpLayout
->pwpos
->x
, lpLayout
->pwpos
->y
,
1385 lpLayout
->pwpos
->cx
, lpLayout
->pwpos
->cy
);
1387 infoPtr
->bRectsValid
= FALSE
;
1394 HEADER_SetImageList (HEADER_INFO
*infoPtr
, HIMAGELIST himl
)
1398 TRACE("(himl %p)\n", himl
);
1399 himlOld
= infoPtr
->himl
;
1400 infoPtr
->himl
= himl
;
1402 /* FIXME: Refresh needed??? */
1404 return (LRESULT
)himlOld
;
1409 HEADER_GetBitmapMargin(const HEADER_INFO
*infoPtr
)
1411 return infoPtr
->iMargin
;
1415 HEADER_SetBitmapMargin(HEADER_INFO
*infoPtr
, INT iMargin
)
1417 INT oldMargin
= infoPtr
->iMargin
;
1419 infoPtr
->iMargin
= iMargin
;
1425 HEADER_SetItemT (HEADER_INFO
*infoPtr
, INT nItem
, const HDITEMW
*phdi
, BOOL bUnicode
)
1427 HEADER_ITEM
*lpItem
;
1433 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
1436 TRACE("[nItem=%d]\n", nItem
);
1438 HEADER_CopyHDItemForNotify(infoPtr
, &hdNotify
, phdi
, bUnicode
, &pvScratch
);
1439 if (HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCHANGINGW
, nItem
, &hdNotify
))
1445 lpItem
= &infoPtr
->items
[nItem
];
1446 HEADER_StoreHDItemInHeader(lpItem
, phdi
->mask
, phdi
, bUnicode
);
1448 if (phdi
->mask
& HDI_ORDER
)
1449 if (phdi
->iOrder
>= 0 && phdi
->iOrder
< infoPtr
->uNumItem
)
1450 HEADER_ChangeItemOrder(infoPtr
, nItem
, phdi
->iOrder
);
1452 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCHANGEDW
, nItem
, &hdNotify
);
1454 HEADER_SetItemBounds (infoPtr
);
1456 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1462 static inline LRESULT
1463 HEADER_SetUnicodeFormat (HEADER_INFO
*infoPtr
, WPARAM wParam
)
1465 BOOL bTemp
= (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1467 infoPtr
->nNotifyFormat
= ((BOOL
)wParam
? NFR_UNICODE
: NFR_ANSI
);
1474 HEADER_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1476 HEADER_INFO
*infoPtr
;
1481 infoPtr
= Alloc (sizeof(HEADER_INFO
));
1482 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1484 infoPtr
->hwndSelf
= hwnd
;
1485 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1486 infoPtr
->uNumItem
= 0;
1490 infoPtr
->bRectsValid
= FALSE
;
1491 infoPtr
->hcurArrow
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1492 infoPtr
->hcurDivider
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDER
));
1493 infoPtr
->hcurDivopen
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDEROPEN
));
1494 infoPtr
->bPressed
= FALSE
;
1495 infoPtr
->bTracking
= FALSE
;
1496 infoPtr
->dwStyle
= lpcs
->style
;
1497 infoPtr
->iMoveItem
= 0;
1499 infoPtr
->iHotItem
= -1;
1500 infoPtr
->iHotDivider
= -1;
1501 infoPtr
->iMargin
= 3*GetSystemMetrics(SM_CXEDGE
);
1502 infoPtr
->nNotifyFormat
=
1503 SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_QUERY
);
1506 hOldFont
= SelectObject (hdc
, GetStockObject (SYSTEM_FONT
));
1507 GetTextMetricsW (hdc
, &tm
);
1508 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
1509 SelectObject (hdc
, hOldFont
);
1512 OpenThemeData(hwnd
, themeClass
);
1519 HEADER_Destroy (HEADER_INFO
*infoPtr
)
1521 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
1522 CloseThemeData(theme
);
1527 HEADER_NCDestroy (HEADER_INFO
*infoPtr
)
1529 HEADER_ITEM
*lpItem
;
1532 if (infoPtr
->items
) {
1533 lpItem
= infoPtr
->items
;
1534 for (nItem
= 0; nItem
< infoPtr
->uNumItem
; nItem
++, lpItem
++) {
1535 Free(lpItem
->pszText
);
1537 Free (infoPtr
->items
);
1540 Free(infoPtr
->order
);
1543 ImageList_Destroy (infoPtr
->himl
);
1545 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
1552 static inline LRESULT
1553 HEADER_GetFont (const HEADER_INFO
*infoPtr
)
1555 return (LRESULT
)infoPtr
->hFont
;
1560 HEADER_IsDragDistance(const HEADER_INFO
*infoPtr
, const POINT
*pt
)
1562 /* Windows allows for a mouse movement before starting the drag. We use the
1563 * SM_CXDOUBLECLICK/SM_CYDOUBLECLICK as that distance.
1565 return (abs(infoPtr
->ptLButtonDown
.x
- pt
->x
)>GetSystemMetrics(SM_CXDOUBLECLK
) ||
1566 abs(infoPtr
->ptLButtonDown
.y
- pt
->y
)>GetSystemMetrics(SM_CYDOUBLECLK
));
1570 HEADER_LButtonDblClk (const HEADER_INFO
*infoPtr
, INT x
, INT y
)
1578 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1580 if ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (flags
== HHT_ONHEADER
))
1581 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMDBLCLICKW
, nItem
, NULL
);
1582 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
))
1583 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_DIVIDERDBLCLICKW
, nItem
, NULL
);
1590 HEADER_LButtonDown (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1599 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1601 if ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (flags
== HHT_ONHEADER
)) {
1602 SetCapture (infoPtr
->hwndSelf
);
1603 infoPtr
->bCaptured
= TRUE
;
1604 infoPtr
->bPressed
= TRUE
;
1605 infoPtr
->bDragging
= FALSE
;
1606 infoPtr
->iMoveItem
= nItem
;
1607 infoPtr
->ptLButtonDown
= pt
;
1609 infoPtr
->items
[nItem
].bDown
= TRUE
;
1611 /* Send WM_CUSTOMDRAW */
1612 hdc
= GetDC (infoPtr
->hwndSelf
);
1613 HEADER_RefreshItem (infoPtr
, nItem
);
1614 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1616 TRACE("Pressed item %d!\n", nItem
);
1618 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
)) {
1619 INT iCurrWidth
= infoPtr
->items
[nItem
].cxy
;
1620 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_BEGINTRACKW
, nItem
, HDI_WIDTH
, iCurrWidth
))
1622 SetCapture (infoPtr
->hwndSelf
);
1623 infoPtr
->bCaptured
= TRUE
;
1624 infoPtr
->bTracking
= TRUE
;
1625 infoPtr
->iMoveItem
= nItem
;
1626 infoPtr
->xTrackOffset
= infoPtr
->items
[nItem
].rect
.right
- pt
.x
;
1628 if (!(infoPtr
->dwStyle
& HDS_FULLDRAG
)) {
1629 infoPtr
->xOldTrack
= infoPtr
->items
[nItem
].rect
.right
;
1630 hdc
= GetDC (infoPtr
->hwndSelf
);
1631 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1632 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1635 TRACE("Begin tracking item %d!\n", nItem
);
1644 HEADER_LButtonUp (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1653 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1655 if (infoPtr
->bPressed
) {
1657 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1659 if (infoPtr
->bDragging
)
1661 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1664 ImageList_DragShowNolock(FALSE
);
1665 ImageList_EndDrag();
1667 if (infoPtr
->iHotDivider
== -1)
1669 else if (infoPtr
->iHotDivider
== infoPtr
->uNumItem
)
1670 iNewOrder
= infoPtr
->uNumItem
-1;
1673 iNewOrder
= HEADER_IndexToOrder(infoPtr
, infoPtr
->iHotDivider
);
1674 if (iNewOrder
> lpItem
->iOrder
)
1678 if (iNewOrder
!= -1 &&
1679 !HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ENDDRAG
, infoPtr
->iMoveItem
, HDI_ORDER
, iNewOrder
))
1681 HEADER_ChangeItemOrder(infoPtr
, infoPtr
->iMoveItem
, iNewOrder
);
1682 infoPtr
->bRectsValid
= FALSE
;
1683 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1686 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->items
[infoPtr
->iMoveItem
].rect
, FALSE
);
1688 infoPtr
->bDragging
= FALSE
;
1689 HEADER_SetHotDivider(infoPtr
, FALSE
, -1);
1693 hdc
= GetDC (infoPtr
->hwndSelf
);
1694 HEADER_RefreshItem (infoPtr
, infoPtr
->iMoveItem
);
1695 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1697 if (!(infoPtr
->dwStyle
& HDS_DRAGDROP
) || !HEADER_IsDragDistance(infoPtr
, &pt
))
1698 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCLICKW
, infoPtr
->iMoveItem
, NULL
);
1701 TRACE("Released item %d!\n", infoPtr
->iMoveItem
);
1702 infoPtr
->bPressed
= FALSE
;
1704 else if (infoPtr
->bTracking
) {
1705 INT iNewWidth
= pt
.x
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
+ infoPtr
->xTrackOffset
;
1708 TRACE("End tracking item %d!\n", infoPtr
->iMoveItem
);
1709 infoPtr
->bTracking
= FALSE
;
1711 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ENDTRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
);
1713 if (!(infoPtr
->dwStyle
& HDS_FULLDRAG
)) {
1714 hdc
= GetDC (infoPtr
->hwndSelf
);
1715 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1716 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1719 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
))
1721 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= iNewWidth
;
1722 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
);
1725 HEADER_SetItemBounds (infoPtr
);
1726 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1729 if (infoPtr
->bCaptured
) {
1730 infoPtr
->bCaptured
= FALSE
;
1732 HEADER_SendSimpleNotify (infoPtr
, NM_RELEASEDCAPTURE
);
1740 HEADER_NotifyFormat (HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1745 return infoPtr
->nNotifyFormat
;
1748 infoPtr
->nNotifyFormat
=
1749 SendMessageW ((HWND
)wParam
, WM_NOTIFYFORMAT
,
1750 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1751 return infoPtr
->nNotifyFormat
;
1758 HEADER_MouseLeave (HEADER_INFO
*infoPtr
)
1760 /* Reset hot-tracked item when mouse leaves control. */
1761 INT oldHotItem
= infoPtr
->iHotItem
;
1762 HDC hdc
= GetDC (infoPtr
->hwndSelf
);
1764 infoPtr
->iHotItem
= -1;
1765 if (oldHotItem
!= -1) HEADER_RefreshItem (infoPtr
, oldHotItem
);
1766 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1773 HEADER_MouseMove (HEADER_INFO
*infoPtr
, LPARAM lParam
)
1779 /* With theming, hottracking is always enabled */
1780 BOOL hotTrackEnabled
=
1781 ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (infoPtr
->dwStyle
& HDS_HOTTRACK
))
1782 || (GetWindowTheme (infoPtr
->hwndSelf
) != NULL
);
1783 INT oldHotItem
= infoPtr
->iHotItem
;
1785 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1786 pt
.y
= (INT
)(SHORT
)HIWORD(lParam
);
1787 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1789 if (hotTrackEnabled
) {
1790 if (flags
& (HHT_ONHEADER
| HHT_ONDIVIDER
| HHT_ONDIVOPEN
))
1791 infoPtr
->iHotItem
= nItem
;
1793 infoPtr
->iHotItem
= -1;
1796 if (infoPtr
->bCaptured
) {
1797 /* check if we should drag the header */
1798 if (infoPtr
->bPressed
&& !infoPtr
->bDragging
&& (infoPtr
->dwStyle
& HDS_DRAGDROP
)
1799 && HEADER_IsDragDistance(infoPtr
, &pt
))
1801 if (!HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_BEGINDRAG
, infoPtr
->iMoveItem
, NULL
))
1803 HIMAGELIST hDragItem
= (HIMAGELIST
)HEADER_CreateDragImage(infoPtr
, infoPtr
->iMoveItem
);
1804 if (hDragItem
!= NULL
)
1806 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1807 TRACE("Starting item drag\n");
1808 ImageList_BeginDrag(hDragItem
, 0, pt
.x
- lpItem
->rect
.left
, 0);
1809 ImageList_DragShowNolock(TRUE
);
1810 ImageList_Destroy(hDragItem
);
1811 infoPtr
->bDragging
= TRUE
;
1816 if (infoPtr
->bDragging
)
1821 ClientToScreen(infoPtr
->hwndSelf
, &drag
);
1822 ImageList_DragMove(drag
.x
, drag
.y
);
1823 HEADER_SetHotDivider(infoPtr
, TRUE
, lParam
);
1826 if (infoPtr
->bPressed
&& !infoPtr
->bDragging
) {
1827 BOOL oldState
= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
;
1828 if ((nItem
== infoPtr
->iMoveItem
) && (flags
== HHT_ONHEADER
))
1829 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= TRUE
;
1831 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1832 if (oldState
!= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
) {
1833 hdc
= GetDC (infoPtr
->hwndSelf
);
1834 HEADER_RefreshItem (infoPtr
, infoPtr
->iMoveItem
);
1835 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1838 TRACE("Moving pressed item %d!\n", infoPtr
->iMoveItem
);
1840 else if (infoPtr
->bTracking
) {
1841 if (infoPtr
->dwStyle
& HDS_FULLDRAG
) {
1842 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1843 nWidth
= pt
.x
- lpItem
->rect
.left
+ infoPtr
->xTrackOffset
;
1844 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, nWidth
))
1846 INT nOldWidth
= lpItem
->rect
.right
- lpItem
->rect
.left
;
1850 if (nWidth
< 0) nWidth
= 0;
1851 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= nWidth
;
1852 HEADER_SetItemBounds(infoPtr
);
1854 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1855 rcScroll
= rcClient
;
1856 rcScroll
.left
= lpItem
->rect
.left
+ nOldWidth
;
1857 ScrollWindowEx(infoPtr
->hwndSelf
, nWidth
- nOldWidth
, 0, &rcScroll
, &rcClient
, NULL
, NULL
, 0);
1858 InvalidateRect(infoPtr
->hwndSelf
, &lpItem
->rect
, FALSE
);
1859 UpdateWindow(infoPtr
->hwndSelf
);
1861 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, nWidth
);
1866 hdc
= GetDC (infoPtr
->hwndSelf
);
1867 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1868 infoPtr
->xOldTrack
= pt
.x
+ infoPtr
->xTrackOffset
;
1869 if (infoPtr
->xOldTrack
< infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
)
1870 infoPtr
->xOldTrack
= infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1871 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1872 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1873 iTrackWidth
= infoPtr
->xOldTrack
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1874 /* FIXME: should stop tracking if HDN_TRACK returns TRUE */
1875 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_TRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iTrackWidth
);
1878 TRACE("Tracking item %d!\n", infoPtr
->iMoveItem
);
1882 if (hotTrackEnabled
) {
1883 TRACKMOUSEEVENT tme
;
1884 if (oldHotItem
!= infoPtr
->iHotItem
&& !infoPtr
->bDragging
) {
1885 hdc
= GetDC (infoPtr
->hwndSelf
);
1886 if (oldHotItem
!= -1) HEADER_RefreshItem (infoPtr
, oldHotItem
);
1887 if (infoPtr
->iHotItem
!= -1) HEADER_RefreshItem (infoPtr
, infoPtr
->iHotItem
);
1888 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1890 tme
.cbSize
= sizeof( tme
);
1891 tme
.dwFlags
= TME_LEAVE
;
1892 tme
.hwndTrack
= infoPtr
->hwndSelf
;
1893 TrackMouseEvent( &tme
);
1901 HEADER_Paint (HEADER_INFO
*infoPtr
, HDC hdcParam
)
1906 hdc
= hdcParam
==0 ? BeginPaint (infoPtr
->hwndSelf
, &ps
) : hdcParam
;
1907 HEADER_Refresh (infoPtr
, hdc
);
1909 EndPaint (infoPtr
->hwndSelf
, &ps
);
1915 HEADER_RButtonUp (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1923 /* Send a Notify message */
1924 bRet
= HEADER_SendSimpleNotify (infoPtr
, NM_RCLICK
);
1926 /* Change to screen coordinate for WM_CONTEXTMENU */
1927 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
1929 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1930 SendMessageW( infoPtr
->hwndSelf
, WM_CONTEXTMENU
, (WPARAM
) infoPtr
->hwndSelf
, MAKELPARAM(pt
.x
, pt
.y
));
1937 HEADER_SetCursor (HEADER_INFO
*infoPtr
, LPARAM lParam
)
1943 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam
), HIWORD(lParam
));
1946 ScreenToClient (infoPtr
->hwndSelf
, &pt
);
1948 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1950 if (flags
== HHT_ONDIVIDER
)
1951 SetCursor (infoPtr
->hcurDivider
);
1952 else if (flags
== HHT_ONDIVOPEN
)
1953 SetCursor (infoPtr
->hcurDivopen
);
1955 SetCursor (infoPtr
->hcurArrow
);
1962 HEADER_SetFont (HEADER_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
1968 infoPtr
->hFont
= hFont
;
1971 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
));
1972 GetTextMetricsW (hdc
, &tm
);
1973 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
1974 SelectObject (hdc
, hOldFont
);
1977 infoPtr
->bRectsValid
= FALSE
;
1980 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1986 static LRESULT
HEADER_SetRedraw(HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1988 /* ignoring the InvalidateRect calls is handled by user32. But some apps expect
1989 * that we invalidate the header and this has to be done manually */
1992 ret
= DefWindowProcW(infoPtr
->hwndSelf
, WM_SETREDRAW
, wParam
, lParam
);
1994 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1998 static INT
HEADER_StyleChanged(HEADER_INFO
*infoPtr
, WPARAM wStyleType
,
1999 const STYLESTRUCT
*lpss
)
2001 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2002 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
2004 if (wStyleType
!= GWL_STYLE
) return 0;
2006 infoPtr
->dwStyle
= lpss
->styleNew
;
2011 /* Update the theme handle after a theme change */
2012 static LRESULT
HEADER_ThemeChanged(const HEADER_INFO
*infoPtr
)
2014 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
2015 CloseThemeData(theme
);
2016 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
2017 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
2022 static LRESULT WINAPI
2023 HEADER_WindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2025 HEADER_INFO
*infoPtr
= (HEADER_INFO
*)GetWindowLongPtrW(hwnd
, 0);
2027 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, msg
, wParam
, lParam
);
2028 if (!infoPtr
&& (msg
!= WM_CREATE
))
2029 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
2031 /* case HDM_CLEARFILTER: */
2033 case HDM_CREATEDRAGIMAGE
:
2034 return HEADER_CreateDragImage (infoPtr
, (INT
)wParam
);
2036 case HDM_DELETEITEM
:
2037 return HEADER_DeleteItem (infoPtr
, (INT
)wParam
);
2039 /* case HDM_EDITFILTER: */
2041 case HDM_GETBITMAPMARGIN
:
2042 return HEADER_GetBitmapMargin(infoPtr
);
2044 case HDM_GETIMAGELIST
:
2045 return HEADER_GetImageList (infoPtr
);
2049 return HEADER_GetItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_GETITEMW
);
2051 case HDM_GETITEMCOUNT
:
2052 return HEADER_GetItemCount (infoPtr
);
2054 case HDM_GETITEMRECT
:
2055 return HEADER_GetItemRect (infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
2057 case HDM_GETORDERARRAY
:
2058 return HEADER_GetOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
2060 case HDM_GETUNICODEFORMAT
:
2061 return HEADER_GetUnicodeFormat (infoPtr
);
2064 return HEADER_HitTest (infoPtr
, (LPHDHITTESTINFO
)lParam
);
2066 case HDM_INSERTITEMA
:
2067 case HDM_INSERTITEMW
:
2068 return HEADER_InsertItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_INSERTITEMW
);
2071 return HEADER_Layout (infoPtr
, (LPHDLAYOUT
)lParam
);
2073 case HDM_ORDERTOINDEX
:
2074 return HEADER_OrderToIndex(infoPtr
, (INT
)wParam
);
2076 case HDM_SETBITMAPMARGIN
:
2077 return HEADER_SetBitmapMargin(infoPtr
, (INT
)wParam
);
2079 /* case HDM_SETFILTERCHANGETIMEOUT: */
2081 case HDM_SETHOTDIVIDER
:
2082 return HEADER_SetHotDivider(infoPtr
, wParam
, lParam
);
2084 case HDM_SETIMAGELIST
:
2085 return HEADER_SetImageList (infoPtr
, (HIMAGELIST
)lParam
);
2089 return HEADER_SetItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_SETITEMW
);
2091 case HDM_SETORDERARRAY
:
2092 return HEADER_SetOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
2094 case HDM_SETUNICODEFORMAT
:
2095 return HEADER_SetUnicodeFormat (infoPtr
, wParam
);
2098 return HEADER_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
2101 return HEADER_Destroy (infoPtr
);
2104 return HEADER_NCDestroy (infoPtr
);
2110 return DLGC_WANTTAB
| DLGC_WANTARROWS
;
2113 return HEADER_GetFont (infoPtr
);
2115 case WM_LBUTTONDBLCLK
:
2116 return HEADER_LButtonDblClk (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2118 case WM_LBUTTONDOWN
:
2119 return HEADER_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2122 return HEADER_LButtonUp (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2125 return HEADER_MouseLeave (infoPtr
);
2128 return HEADER_MouseMove (infoPtr
, lParam
);
2130 case WM_NOTIFYFORMAT
:
2131 return HEADER_NotifyFormat (infoPtr
, wParam
, lParam
);
2134 return HEADER_Size (infoPtr
);
2136 case WM_THEMECHANGED
:
2137 return HEADER_ThemeChanged (infoPtr
);
2139 case WM_PRINTCLIENT
:
2141 return HEADER_Paint (infoPtr
, (HDC
)wParam
);
2144 return HEADER_RButtonUp (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2147 return HEADER_SetCursor (infoPtr
, lParam
);
2150 return HEADER_SetFont (infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
2153 return HEADER_SetRedraw(infoPtr
, wParam
, lParam
);
2155 case WM_STYLECHANGED
:
2156 return HEADER_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
2158 case WM_SYSCOLORCHANGE
:
2159 COMCTL32_RefreshSysColors();
2163 if ((msg
>= WM_USER
) && (msg
< WM_APP
) && !COMCTL32_IsReflectedMessage(msg
))
2164 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
2165 msg
, wParam
, lParam
);
2166 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
2172 HEADER_Register (void)
2176 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2177 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
2178 wndClass
.lpfnWndProc
= HEADER_WindowProc
;
2179 wndClass
.cbClsExtra
= 0;
2180 wndClass
.cbWndExtra
= sizeof(HEADER_INFO
*);
2181 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2182 wndClass
.lpszClassName
= WC_HEADERW
;
2184 RegisterClassW (&wndClass
);
2189 HEADER_Unregister (void)
2191 UnregisterClassW (WC_HEADERW
, NULL
);