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
,
378 (WPARAM
)dis
.CtlID
, (LPARAM
)&dis
);
379 if (oldBkMode
!= TRANSPARENT
)
380 SetBkMode(hdc
, oldBkMode
);
383 UINT rw
, rh
, /* width and height of r */
384 *x
= NULL
, *w
= NULL
; /* x and width of the pic (bmp or img) which is part of cnt */
385 /* cnt,txt,img,bmp */
390 HEADER_PrepareCallbackItems(infoPtr
, iItem
, HDI_TEXT
|HDI_IMAGE
);
391 cw
= tw
= iw
= bw
= 0;
392 rw
= r
.right
- r
.left
;
393 rh
= r
.bottom
- r
.top
;
395 if (phdi
->fmt
& HDF_STRING
) {
398 SetRectEmpty(&textRect
);
399 DrawTextW (hdc
, phdi
->pszText
, -1,
400 &textRect
, DT_LEFT
|DT_VCENTER
|DT_SINGLELINE
|DT_CALCRECT
);
401 cw
= textRect
.right
- textRect
.left
+ 2 * infoPtr
->iMargin
;
404 if ((phdi
->fmt
& HDF_IMAGE
) && (infoPtr
->himl
)) {
405 iw
= infoPtr
->himl
->cx
+ 2 * infoPtr
->iMargin
;
410 if ((phdi
->fmt
& HDF_BITMAP
) && (phdi
->hbm
)) {
411 GetObjectW (phdi
->hbm
, sizeof(BITMAP
), &bmp
);
412 bw
= bmp
.bmWidth
+ 2 * infoPtr
->iMargin
;
422 /* align cx using the unclipped cw */
423 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_LEFT
)
425 else if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_CENTER
)
426 cx
= r
.left
+ rw
/ 2 - cw
/ 2;
433 if (cx
+ cw
> r
.right
)
436 tx
= cx
+ infoPtr
->iMargin
;
437 /* since cw might have changed we have to recalculate tw */
438 tw
= cw
- infoPtr
->iMargin
* 2;
442 if (phdi
->fmt
& HDF_BITMAP_ON_RIGHT
) {
443 /* put pic behind text */
444 *x
= cx
+ tw
+ infoPtr
->iMargin
* 3;
446 *x
= cx
+ infoPtr
->iMargin
;
447 /* move text behind pic */
453 /* since we're done with the layout we can
454 now calculate the position of bmp which
455 has no influence on alignment and layout
457 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_RIGHT
)
458 bx
= cx
- bw
+ infoPtr
->iMargin
;
460 bx
= cx
+ cw
+ infoPtr
->iMargin
;
464 HDC hClipDC
= GetDC(infoPtr
->hwndSelf
);
465 HRGN hClipRgn
= CreateRectRgn(r
.left
, r
.top
, r
.right
, r
.bottom
);
466 SelectClipRgn(hClipDC
, hClipRgn
);
469 HDC hdcBitmap
= CreateCompatibleDC (hClipDC
);
470 SelectObject (hdcBitmap
, phdi
->hbm
);
471 BitBlt (hClipDC
, bx
, r
.top
+ ((INT
)rh
- bmp
.bmHeight
) / 2,
472 bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
473 DeleteDC (hdcBitmap
);
477 ImageList_DrawEx (infoPtr
->himl
, phdi
->iImage
, hClipDC
,
478 ix
, r
.top
+ ((INT
)rh
- infoPtr
->himl
->cy
) / 2,
479 infoPtr
->himl
->cx
, infoPtr
->himl
->cy
, CLR_DEFAULT
, CLR_DEFAULT
, 0);
482 DeleteObject(hClipRgn
);
483 ReleaseDC(infoPtr
->hwndSelf
, hClipDC
);
486 if (((phdi
->fmt
& HDF_STRING
)
487 || (!(phdi
->fmt
& (HDF_OWNERDRAW
|HDF_STRING
|HDF_BITMAP
|
488 HDF_BITMAP_ON_RIGHT
|HDF_IMAGE
)))) /* no explicit format specified? */
489 && (phdi
->pszText
)) {
490 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
493 DrawTextW (hdc
, phdi
->pszText
, -1,
494 &r
, DT_LEFT
|DT_END_ELLIPSIS
|DT_VCENTER
|DT_SINGLELINE
);
495 if (oldBkMode
!= TRANSPARENT
)
496 SetBkMode(hdc
, oldBkMode
);
498 HEADER_FreeCallbackItems(phdi
);
501 return phdi
->rect
.right
;
505 HEADER_DrawHotDivider(const HEADER_INFO
*infoPtr
, HDC hdc
)
510 HEADER_GetHotDividerRect(infoPtr
, &r
);
511 brush
= CreateSolidBrush(comctl32_color
.clrHighlight
);
512 FillRect(hdc
, &r
, brush
);
517 HEADER_Refresh (HEADER_INFO
*infoPtr
, HDC hdc
)
519 HFONT hFont
, hOldFont
;
525 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
527 if (!infoPtr
->bRectsValid
)
528 HEADER_SetItemBounds(infoPtr
);
530 /* get rect for the bar, adjusted for the border */
531 GetClientRect (infoPtr
->hwndSelf
, &rect
);
532 lCDFlags
= HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_PREPAINT
, hdc
, &rect
);
534 if (infoPtr
->bDragging
)
535 ImageList_DragShowNolock(FALSE
);
537 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
);
538 hOldFont
= SelectObject (hdc
, hFont
);
540 /* draw Background */
541 if (infoPtr
->uNumItem
== 0 && theme
== NULL
) {
542 hbrBk
= GetSysColorBrush(COLOR_3DFACE
);
543 FillRect(hdc
, &rect
, hbrBk
);
547 for (i
= 0; x
<= rect
.right
&& i
< infoPtr
->uNumItem
; i
++) {
548 int idx
= HEADER_OrderToIndex(infoPtr
,i
);
549 if (RectVisible(hdc
, &infoPtr
->items
[idx
].rect
))
550 HEADER_DrawItem(infoPtr
, hdc
, idx
, infoPtr
->iHotItem
== idx
, lCDFlags
);
551 x
= infoPtr
->items
[idx
].rect
.right
;
556 if ((x
<= rect
.right
) && RectVisible(hdc
, &rcRest
) && (infoPtr
->uNumItem
> 0)) {
558 DrawThemeBackground(theme
, hdc
, HP_HEADERITEM
, HIS_NORMAL
, &rcRest
, NULL
);
560 else if (infoPtr
->dwStyle
& HDS_FLAT
) {
561 hbrBk
= GetSysColorBrush(COLOR_3DFACE
);
562 FillRect(hdc
, &rcRest
, hbrBk
);
566 if (infoPtr
->dwStyle
& HDS_BUTTONS
)
567 DrawEdge (hdc
, &rcRest
, EDGE_RAISED
, BF_TOP
|BF_LEFT
|BF_BOTTOM
|BF_SOFT
|BF_MIDDLE
);
569 DrawEdge (hdc
, &rcRest
, EDGE_ETCHED
, BF_BOTTOM
|BF_MIDDLE
);
573 if (infoPtr
->iHotDivider
!= -1)
574 HEADER_DrawHotDivider(infoPtr
, hdc
);
576 if (infoPtr
->bDragging
)
577 ImageList_DragShowNolock(TRUE
);
578 SelectObject (hdc
, hOldFont
);
580 if (lCDFlags
& CDRF_NOTIFYPOSTPAINT
)
581 HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_POSTPAINT
, hdc
, &rect
);
586 HEADER_RefreshItem (HEADER_INFO
*infoPtr
, INT iItem
)
588 if (!infoPtr
->bRectsValid
)
589 HEADER_SetItemBounds(infoPtr
);
591 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->items
[iItem
].rect
, FALSE
);
596 HEADER_InternalHitTest (const HEADER_INFO
*infoPtr
, const POINT
*lpPt
, UINT
*pFlags
, INT
*pItem
)
603 GetClientRect (infoPtr
->hwndSelf
, &rect
);
607 if (PtInRect (&rect
, *lpPt
))
609 if (infoPtr
->uNumItem
== 0) {
610 *pFlags
|= HHT_NOWHERE
;
616 /* somewhere inside */
617 for (iCount
= 0; iCount
< infoPtr
->uNumItem
; iCount
++) {
618 rect
= infoPtr
->items
[iCount
].rect
;
619 width
= rect
.right
- rect
.left
;
624 if (PtInRect (&rect
, *lpPt
)) {
625 if (width
<= 2 * DIVIDER_WIDTH
) {
626 *pFlags
|= HHT_ONHEADER
;
628 TRACE("ON HEADER %d\n", iCount
);
631 if (HEADER_IndexToOrder(infoPtr
, iCount
) > 0) {
633 rcTest
.right
= rcTest
.left
+ DIVIDER_WIDTH
;
634 if (PtInRect (&rcTest
, *lpPt
)) {
635 if (HEADER_IsItemFixed(infoPtr
, HEADER_PrevItem(infoPtr
, iCount
)))
637 *pFlags
|= HHT_ONHEADER
;
639 TRACE("ON HEADER %d\n", *pItem
);
643 *pFlags
|= HHT_ONDIVOPEN
;
644 *pItem
= HEADER_PrevItem(infoPtr
, iCount
);
645 TRACE("ON DIVOPEN %d\n", *pItem
);
649 *pFlags
|= HHT_ONDIVIDER
;
650 *pItem
= HEADER_PrevItem(infoPtr
, iCount
);
651 TRACE("ON DIVIDER %d\n", *pItem
);
657 rcTest
.left
= rcTest
.right
- DIVIDER_WIDTH
;
658 if (!HEADER_IsItemFixed(infoPtr
, iCount
) && PtInRect (&rcTest
, *lpPt
))
660 *pFlags
|= HHT_ONDIVIDER
;
662 TRACE("ON DIVIDER %d\n", *pItem
);
666 *pFlags
|= HHT_ONHEADER
;
668 TRACE("ON HEADER %d\n", iCount
);
673 /* check for last divider part (on nowhere) */
674 if (!HEADER_IsItemFixed(infoPtr
, infoPtr
->uNumItem
- 1))
676 rect
= infoPtr
->items
[infoPtr
->uNumItem
-1].rect
;
677 rect
.left
= rect
.right
;
678 rect
.right
+= DIVIDER_WIDTH
;
679 if (PtInRect (&rect
, *lpPt
)) {
681 *pFlags
|= HHT_ONDIVOPEN
;
682 *pItem
= infoPtr
->uNumItem
- 1;
683 TRACE("ON DIVOPEN %d\n", *pItem
);
687 *pFlags
|= HHT_ONDIVIDER
;
688 *pItem
= infoPtr
->uNumItem
- 1;
689 TRACE("ON DIVIDER %d\n", *pItem
);
695 *pFlags
|= HHT_NOWHERE
;
702 if (lpPt
->x
< rect
.left
) {
704 *pFlags
|= HHT_TOLEFT
;
706 else if (lpPt
->x
> rect
.right
) {
708 *pFlags
|= HHT_TORIGHT
;
711 if (lpPt
->y
< rect
.top
) {
713 *pFlags
|= HHT_ABOVE
;
715 else if (lpPt
->y
> rect
.bottom
) {
717 *pFlags
|= HHT_BELOW
;
722 TRACE("flags=0x%X\n", *pFlags
);
728 HEADER_DrawTrackLine (const HEADER_INFO
*infoPtr
, HDC hdc
, INT x
)
734 GetClientRect (infoPtr
->hwndSelf
, &rect
);
736 hOldPen
= SelectObject (hdc
, GetStockObject (BLACK_PEN
));
737 oldRop
= SetROP2 (hdc
, R2_XORPEN
);
738 MoveToEx (hdc
, x
, rect
.top
, NULL
);
739 LineTo (hdc
, x
, rect
.bottom
);
740 SetROP2 (hdc
, oldRop
);
741 SelectObject (hdc
, hOldPen
);
746 * Convert a HDITEM into the correct format (ANSI/Unicode) to send it in a notify
749 * [I] infoPtr : the header that wants to send the notify
750 * [O] dest : The buffer to store the HDITEM for notify. It may be set to a HDITEMA of HDITEMW
751 * [I] src : The source HDITEM. It may be a HDITEMA or HDITEMW
752 * [I] fSourceUnicode : is src a HDITEMW or HDITEMA
753 * [O] ppvScratch : a pointer to a scratch buffer that needs to be freed after
754 * the HDITEM is no longer in use or NULL if none was needed
756 * NOTE: We depend on HDITEMA and HDITEMW having the same structure
758 static void HEADER_CopyHDItemForNotify(const HEADER_INFO
*infoPtr
, HDITEMW
*dest
,
759 const HDITEMW
*src
, BOOL fSourceUnicode
, LPVOID
*ppvScratch
)
764 if (src
->mask
& HDI_TEXT
&& src
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers TEXTCALLBACKA as well */
766 if (fSourceUnicode
&& infoPtr
->nNotifyFormat
!= NFR_UNICODE
)
768 dest
->pszText
= NULL
;
769 Str_SetPtrWtoA((LPSTR
*)&dest
->pszText
, src
->pszText
);
770 *ppvScratch
= dest
->pszText
;
773 if (!fSourceUnicode
&& infoPtr
->nNotifyFormat
== NFR_UNICODE
)
775 dest
->pszText
= NULL
;
776 Str_SetPtrAtoW(&dest
->pszText
, (LPSTR
)src
->pszText
);
777 *ppvScratch
= dest
->pszText
;
782 static UINT
HEADER_NotifyCodeWtoA(UINT code
)
784 /* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
785 if (code
>= HDN_LAST
&& code
<= HDN_FIRST_UNICODE
)
786 return code
+ HDN_UNICODE_OFFSET
;
792 HEADER_SendNotify(const HEADER_INFO
*infoPtr
, UINT code
, NMHDR
*nmhdr
)
794 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
795 nmhdr
->idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
798 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
799 nmhdr
->idFrom
, (LPARAM
)nmhdr
);
803 HEADER_SendSimpleNotify (const HEADER_INFO
*infoPtr
, UINT code
)
806 return (BOOL
)HEADER_SendNotify(infoPtr
, code
, &nmhdr
);
810 HEADER_SendCtrlCustomDraw(const HEADER_INFO
*infoPtr
, DWORD dwDrawStage
, HDC hdc
, const RECT
*rect
)
813 nm
.dwDrawStage
= dwDrawStage
;
820 return HEADER_SendNotify(infoPtr
, NM_CUSTOMDRAW
, (NMHDR
*)&nm
);
824 HEADER_SendNotifyWithHDItemT(const HEADER_INFO
*infoPtr
, UINT code
, INT iItem
, HDITEMW
*lpItem
)
828 if (infoPtr
->nNotifyFormat
!= NFR_UNICODE
)
829 code
= HEADER_NotifyCodeWtoA(code
);
832 nmhdr
.pitem
= lpItem
;
834 return (BOOL
)HEADER_SendNotify(infoPtr
, code
, (NMHDR
*)&nmhdr
);
838 HEADER_SendNotifyWithIntFieldT(const HEADER_INFO
*infoPtr
, UINT code
, INT iItem
, INT mask
, INT iValue
)
842 /* copying only the iValue should be ok but to make the code more robust we copy everything */
843 nmitem
.cxy
= infoPtr
->items
[iItem
].cxy
;
844 nmitem
.hbm
= infoPtr
->items
[iItem
].hbm
;
845 nmitem
.pszText
= NULL
;
846 nmitem
.cchTextMax
= 0;
847 nmitem
.fmt
= infoPtr
->items
[iItem
].fmt
;
848 nmitem
.lParam
= infoPtr
->items
[iItem
].lParam
;
849 nmitem
.iOrder
= infoPtr
->items
[iItem
].iOrder
;
850 nmitem
.iImage
= infoPtr
->items
[iItem
].iImage
;
859 nmitem
.iOrder
= iValue
;
862 ERR("invalid mask value 0x%x\n", iValue
);
865 return HEADER_SendNotifyWithHDItemT(infoPtr
, code
, iItem
, &nmitem
);
869 * Prepare callback items
870 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
871 * (so we handle the two cases only doing a specific cast for pszText).
872 * Checks if any of the required field are callback. If there are sends a
873 * NMHDISPINFO notify to retrieve these items. The items are stored in the
874 * HEADER_ITEM pszText and iImage fields. They should be freed with
875 * HEADER_FreeCallbackItems.
877 * @param hwnd : hwnd header container handler
878 * @param iItem : the header item id
879 * @param reqMask : required fields. If any of them is callback this function will fetch it
881 * @return TRUE on success, else FALSE
884 HEADER_PrepareCallbackItems(const HEADER_INFO
*infoPtr
, INT iItem
, INT reqMask
)
886 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
887 DWORD mask
= reqMask
& lpItem
->callbackMask
;
888 NMHDDISPINFOW dispInfo
;
889 void *pvBuffer
= NULL
;
893 if (mask
&HDI_TEXT
&& lpItem
->pszText
!= NULL
)
895 ERR("(): function called without a call to FreeCallbackItems\n");
896 Free(lpItem
->pszText
);
897 lpItem
->pszText
= NULL
;
900 memset(&dispInfo
, 0, sizeof(NMHDDISPINFOW
));
901 dispInfo
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
902 dispInfo
.hdr
.idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
903 if (infoPtr
->nNotifyFormat
== NFR_UNICODE
)
905 dispInfo
.hdr
.code
= HDN_GETDISPINFOW
;
907 pvBuffer
= Alloc(MAX_HEADER_TEXT_LEN
* sizeof(WCHAR
));
911 dispInfo
.hdr
.code
= HDN_GETDISPINFOA
;
913 pvBuffer
= Alloc(MAX_HEADER_TEXT_LEN
* sizeof(CHAR
));
915 dispInfo
.pszText
= pvBuffer
;
916 dispInfo
.cchTextMax
= (pvBuffer
!=NULL
?MAX_HEADER_TEXT_LEN
:0);
917 dispInfo
.iItem
= iItem
;
918 dispInfo
.mask
= mask
;
919 dispInfo
.lParam
= lpItem
->lParam
;
921 TRACE("Sending HDN_GETDISPINFO%c\n", infoPtr
->nNotifyFormat
== NFR_UNICODE
?'W':'A');
922 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, dispInfo
.hdr
.idFrom
, (LPARAM
)&dispInfo
);
924 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
926 (infoPtr
->nNotifyFormat
== NFR_UNICODE
? debugstr_w(dispInfo
.pszText
) : (LPSTR
) dispInfo
.pszText
),
927 (void*) dispInfo
.lParam
);
929 if (mask
& HDI_IMAGE
)
930 lpItem
->iImage
= dispInfo
.iImage
;
933 if (infoPtr
->nNotifyFormat
== NFR_UNICODE
)
935 lpItem
->pszText
= pvBuffer
;
937 /* the user might have used his own buffer */
938 if (dispInfo
.pszText
!= lpItem
->pszText
)
939 Str_GetPtrW(dispInfo
.pszText
, lpItem
->pszText
, MAX_HEADER_TEXT_LEN
);
943 Str_SetPtrAtoW(&lpItem
->pszText
, (LPSTR
)dispInfo
.pszText
);
948 if (dispInfo
.mask
& HDI_DI_SETITEM
)
950 /* make the items permanent */
951 lpItem
->callbackMask
&= ~dispInfo
.mask
;
959 * Free the items that might be allocated with HEADER_PrepareCallbackItems
962 * [I] lpItem : the item to free the data
966 HEADER_FreeCallbackItems(HEADER_ITEM
*lpItem
)
968 if (lpItem
->callbackMask
&HDI_TEXT
)
970 Free(lpItem
->pszText
);
971 lpItem
->pszText
= NULL
;
974 if (lpItem
->callbackMask
&HDI_IMAGE
)
975 lpItem
->iImage
= I_IMAGECALLBACK
;
979 HEADER_CreateDragImage (HEADER_INFO
*infoPtr
, INT iItem
)
983 HBITMAP hMemory
, hOldBitmap
;
991 if (iItem
>= infoPtr
->uNumItem
)
994 if (!infoPtr
->bRectsValid
)
995 HEADER_SetItemBounds(infoPtr
);
997 lpItem
= &infoPtr
->items
[iItem
];
998 width
= lpItem
->rect
.right
- lpItem
->rect
.left
;
999 height
= lpItem
->rect
.bottom
- lpItem
->rect
.top
;
1001 hDeviceDC
= GetDC(NULL
);
1002 hMemoryDC
= CreateCompatibleDC(hDeviceDC
);
1003 hMemory
= CreateCompatibleBitmap(hDeviceDC
, width
, height
);
1004 ReleaseDC(NULL
, hDeviceDC
);
1005 hOldBitmap
= SelectObject(hMemoryDC
, hMemory
);
1006 SetViewportOrgEx(hMemoryDC
, -lpItem
->rect
.left
, -lpItem
->rect
.top
, NULL
);
1007 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject(SYSTEM_FONT
);
1008 SelectObject(hMemoryDC
, hFont
);
1010 GetClientRect(infoPtr
->hwndSelf
, &rc
);
1011 lCDFlags
= HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_PREPAINT
, hMemoryDC
, &rc
);
1012 HEADER_DrawItem(infoPtr
, hMemoryDC
, iItem
, FALSE
, lCDFlags
);
1013 if (lCDFlags
& CDRF_NOTIFYPOSTPAINT
)
1014 HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_POSTPAINT
, hMemoryDC
, &rc
);
1016 hMemory
= SelectObject(hMemoryDC
, hOldBitmap
);
1017 DeleteDC(hMemoryDC
);
1019 if (hMemory
== NULL
) /* if anything failed */
1022 himl
= ImageList_Create(width
, height
, ILC_COLORDDB
, 1, 1);
1023 ImageList_Add(himl
, hMemory
, NULL
);
1024 DeleteObject(hMemory
);
1025 return (LRESULT
)himl
;
1029 HEADER_SetHotDivider(HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1038 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1040 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &iDivider
);
1042 if (flags
& HHT_TOLEFT
)
1044 else if (flags
& HHT_NOWHERE
|| flags
& HHT_TORIGHT
)
1045 iDivider
= infoPtr
->uNumItem
;
1048 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iDivider
];
1049 if (pt
.x
> (lpItem
->rect
.left
+lpItem
->rect
.right
)/2)
1050 iDivider
= HEADER_NextItem(infoPtr
, iDivider
);
1054 iDivider
= (INT
)lParam
;
1056 /* Note; wParam==FALSE, lParam==-1 is valid and is used to clear the hot divider */
1057 if (iDivider
<-1 || iDivider
>(int)infoPtr
->uNumItem
)
1060 if (iDivider
!= infoPtr
->iHotDivider
)
1062 if (infoPtr
->iHotDivider
!= -1)
1064 HEADER_GetHotDividerRect(infoPtr
, &r
);
1065 InvalidateRect(infoPtr
->hwndSelf
, &r
, FALSE
);
1067 infoPtr
->iHotDivider
= iDivider
;
1070 HEADER_GetHotDividerRect(infoPtr
, &r
);
1071 InvalidateRect(infoPtr
->hwndSelf
, &r
, FALSE
);
1078 HEADER_DeleteItem (HEADER_INFO
*infoPtr
, INT iItem
)
1083 TRACE("[iItem=%d]\n", iItem
);
1085 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
1088 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1089 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
1091 iOrder
= infoPtr
->items
[iItem
].iOrder
;
1092 Free(infoPtr
->items
[iItem
].pszText
);
1094 infoPtr
->uNumItem
--;
1095 memmove(&infoPtr
->items
[iItem
], &infoPtr
->items
[iItem
+ 1],
1096 (infoPtr
->uNumItem
- iItem
) * sizeof(HEADER_ITEM
));
1097 memmove(&infoPtr
->order
[iOrder
], &infoPtr
->order
[iOrder
+ 1],
1098 (infoPtr
->uNumItem
- iOrder
) * sizeof(INT
));
1099 infoPtr
->items
= ReAlloc(infoPtr
->items
, sizeof(HEADER_ITEM
) * infoPtr
->uNumItem
);
1100 infoPtr
->order
= ReAlloc(infoPtr
->order
, sizeof(INT
) * infoPtr
->uNumItem
);
1102 /* Correct the orders */
1103 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1105 if (infoPtr
->order
[i
] > iItem
)
1106 infoPtr
->order
[i
]--;
1108 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
1110 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1111 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
1113 HEADER_SetItemBounds (infoPtr
);
1114 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1121 HEADER_GetImageList (const HEADER_INFO
*infoPtr
)
1123 return (LRESULT
)infoPtr
->himl
;
1128 HEADER_GetItemT (const HEADER_INFO
*infoPtr
, INT nItem
, LPHDITEMW phdi
, BOOL bUnicode
)
1130 HEADER_ITEM
*lpItem
;
1136 TRACE("[nItem=%d]\n", nItem
);
1142 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
1145 if (mask
& HDI_UNKNOWN_FIELDS
)
1147 TRACE("mask %x contains unknown fields. Using only comctl32 4.0 fields\n", mask
);
1148 mask
&= HDI_COMCTL32_4_0_FIELDS
;
1151 lpItem
= &infoPtr
->items
[nItem
];
1152 HEADER_PrepareCallbackItems(infoPtr
, nItem
, mask
);
1154 if (mask
& HDI_BITMAP
)
1155 phdi
->hbm
= lpItem
->hbm
;
1157 if (mask
& HDI_FORMAT
)
1158 phdi
->fmt
= lpItem
->fmt
;
1160 if (mask
& HDI_WIDTH
)
1161 phdi
->cxy
= lpItem
->cxy
;
1163 if (mask
& HDI_LPARAM
)
1164 phdi
->lParam
= lpItem
->lParam
;
1166 if (mask
& HDI_IMAGE
)
1167 phdi
->iImage
= lpItem
->iImage
;
1169 if (mask
& HDI_ORDER
)
1170 phdi
->iOrder
= lpItem
->iOrder
;
1172 if (mask
& HDI_TEXT
)
1175 Str_GetPtrW (lpItem
->pszText
, phdi
->pszText
, phdi
->cchTextMax
);
1177 Str_GetPtrWtoA (lpItem
->pszText
, (LPSTR
)phdi
->pszText
, phdi
->cchTextMax
);
1180 HEADER_FreeCallbackItems(lpItem
);
1185 static inline LRESULT
1186 HEADER_GetItemCount (const HEADER_INFO
*infoPtr
)
1188 return infoPtr
->uNumItem
;
1193 HEADER_GetItemRect (const HEADER_INFO
*infoPtr
, INT iItem
, LPRECT lpRect
)
1195 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
1198 lpRect
->left
= infoPtr
->items
[iItem
].rect
.left
;
1199 lpRect
->right
= infoPtr
->items
[iItem
].rect
.right
;
1200 lpRect
->top
= infoPtr
->items
[iItem
].rect
.top
;
1201 lpRect
->bottom
= infoPtr
->items
[iItem
].rect
.bottom
;
1208 HEADER_GetOrderArray(const HEADER_INFO
*infoPtr
, INT size
, LPINT order
)
1210 if ((UINT
)size
<infoPtr
->uNumItem
)
1213 memcpy(order
, infoPtr
->order
, infoPtr
->uNumItem
* sizeof(INT
));
1217 /* Returns index of first duplicate 'value' from [0,to) range,
1218 or -1 if there isn't any */
1219 static INT
has_duplicate(INT
*array
, INT to
, INT value
)
1222 for(i
= 0; i
< to
; i
++)
1223 if (array
[i
] == value
) return i
;
1227 /* returns next available value from [0,max] not to duplicate in [0,to) */
1228 static INT
get_nextvalue(INT
*array
, INT to
, INT max
)
1231 for(i
= 0; i
< max
; i
++)
1232 if (has_duplicate(array
, to
, i
) == -1) return i
;
1237 HEADER_SetOrderArray(HEADER_INFO
*infoPtr
, INT size
, const INT
*order
)
1239 HEADER_ITEM
*lpItem
;
1242 if ((UINT
)size
!= infoPtr
->uNumItem
)
1245 for (i
=0; i
<size
; i
++)
1247 if (order
[i
] >= size
|| order
[i
] < 0)
1248 /* on invalid index get next available */
1249 /* FIXME: if i==0 array item is out of range behaviour is
1250 different, see tests */
1251 infoPtr
->order
[i
] = get_nextvalue(infoPtr
->order
, i
, size
);
1256 infoPtr
->order
[i
] = order
[i
];
1258 /* remove duplicates */
1259 while ((dup
= has_duplicate(infoPtr
->order
, j
, order
[j
])) != -1)
1263 next
= get_nextvalue(infoPtr
->order
, j
, size
);
1264 infoPtr
->order
[dup
] = next
;
1269 /* sync with item data */
1270 for (i
=0; i
<size
; i
++)
1272 lpItem
= &infoPtr
->items
[infoPtr
->order
[i
]];
1275 HEADER_SetItemBounds(infoPtr
);
1276 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1280 static inline LRESULT
1281 HEADER_GetUnicodeFormat (const HEADER_INFO
*infoPtr
)
1283 return (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1288 HEADER_HitTest (const HEADER_INFO
*infoPtr
, LPHDHITTESTINFO phti
)
1290 UINT outside
= HHT_NOWHERE
| HHT_ABOVE
| HHT_BELOW
| HHT_TOLEFT
| HHT_TORIGHT
;
1292 HEADER_InternalHitTest (infoPtr
, &phti
->pt
, &phti
->flags
, &phti
->iItem
);
1294 if (phti
->flags
& outside
)
1295 return phti
->iItem
= -1;
1302 HEADER_InsertItemT (HEADER_INFO
*infoPtr
, INT nItem
, const HDITEMW
*phdi
, BOOL bUnicode
)
1304 HEADER_ITEM
*lpItem
;
1309 if ((phdi
== NULL
) || (nItem
< 0) || (phdi
->mask
== 0))
1312 if (nItem
> infoPtr
->uNumItem
)
1313 nItem
= infoPtr
->uNumItem
;
1315 iOrder
= (phdi
->mask
& HDI_ORDER
) ? phdi
->iOrder
: nItem
;
1318 else if (infoPtr
->uNumItem
< iOrder
)
1319 iOrder
= infoPtr
->uNumItem
;
1321 infoPtr
->uNumItem
++;
1322 infoPtr
->items
= ReAlloc(infoPtr
->items
, sizeof(HEADER_ITEM
) * infoPtr
->uNumItem
);
1323 infoPtr
->order
= ReAlloc(infoPtr
->order
, sizeof(INT
) * infoPtr
->uNumItem
);
1325 /* make space for the new item */
1326 memmove(&infoPtr
->items
[nItem
+ 1], &infoPtr
->items
[nItem
],
1327 (infoPtr
->uNumItem
- nItem
- 1) * sizeof(HEADER_ITEM
));
1328 memmove(&infoPtr
->order
[iOrder
+ 1], &infoPtr
->order
[iOrder
],
1329 (infoPtr
->uNumItem
- iOrder
- 1) * sizeof(INT
));
1331 /* update the order array */
1332 infoPtr
->order
[iOrder
] = nItem
;
1333 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1335 if (i
!= iOrder
&& infoPtr
->order
[i
] >= nItem
)
1336 infoPtr
->order
[i
]++;
1337 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
1340 lpItem
= &infoPtr
->items
[nItem
];
1341 ZeroMemory(lpItem
, sizeof(HEADER_ITEM
));
1342 /* cxy, fmt and lParam are copied even if not in the HDITEM mask */
1343 copyMask
= phdi
->mask
| HDI_WIDTH
| HDI_FORMAT
| HDI_LPARAM
;
1344 HEADER_StoreHDItemInHeader(lpItem
, copyMask
, phdi
, bUnicode
);
1345 lpItem
->iOrder
= iOrder
;
1347 /* set automatically some format bits */
1348 if (phdi
->mask
& HDI_TEXT
)
1349 lpItem
->fmt
|= HDF_STRING
;
1351 lpItem
->fmt
&= ~HDF_STRING
;
1353 if (lpItem
->hbm
!= NULL
)
1354 lpItem
->fmt
|= HDF_BITMAP
;
1356 lpItem
->fmt
&= ~HDF_BITMAP
;
1358 if (phdi
->mask
& HDI_IMAGE
)
1359 lpItem
->fmt
|= HDF_IMAGE
;
1361 HEADER_SetItemBounds (infoPtr
);
1362 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1369 HEADER_Layout (HEADER_INFO
*infoPtr
, LPHDLAYOUT lpLayout
)
1371 lpLayout
->pwpos
->hwnd
= infoPtr
->hwndSelf
;
1372 lpLayout
->pwpos
->hwndInsertAfter
= 0;
1373 lpLayout
->pwpos
->x
= lpLayout
->prc
->left
;
1374 lpLayout
->pwpos
->y
= lpLayout
->prc
->top
;
1375 lpLayout
->pwpos
->cx
= lpLayout
->prc
->right
- lpLayout
->prc
->left
;
1376 if (infoPtr
->dwStyle
& HDS_HIDDEN
)
1377 lpLayout
->pwpos
->cy
= 0;
1379 lpLayout
->pwpos
->cy
= infoPtr
->nHeight
;
1380 lpLayout
->prc
->top
+= infoPtr
->nHeight
;
1382 lpLayout
->pwpos
->flags
= SWP_NOZORDER
;
1384 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1385 lpLayout
->pwpos
->x
, lpLayout
->pwpos
->y
,
1386 lpLayout
->pwpos
->cx
, lpLayout
->pwpos
->cy
);
1388 infoPtr
->bRectsValid
= FALSE
;
1395 HEADER_SetImageList (HEADER_INFO
*infoPtr
, HIMAGELIST himl
)
1399 TRACE("(himl %p)\n", himl
);
1400 himlOld
= infoPtr
->himl
;
1401 infoPtr
->himl
= himl
;
1403 /* FIXME: Refresh needed??? */
1405 return (LRESULT
)himlOld
;
1410 HEADER_GetBitmapMargin(const HEADER_INFO
*infoPtr
)
1412 return infoPtr
->iMargin
;
1416 HEADER_SetBitmapMargin(HEADER_INFO
*infoPtr
, INT iMargin
)
1418 INT oldMargin
= infoPtr
->iMargin
;
1420 infoPtr
->iMargin
= iMargin
;
1426 HEADER_SetItemT (HEADER_INFO
*infoPtr
, INT nItem
, const HDITEMW
*phdi
, BOOL bUnicode
)
1428 HEADER_ITEM
*lpItem
;
1434 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
1437 TRACE("[nItem=%d]\n", nItem
);
1439 HEADER_CopyHDItemForNotify(infoPtr
, &hdNotify
, phdi
, bUnicode
, &pvScratch
);
1440 if (HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCHANGINGW
, nItem
, &hdNotify
))
1446 lpItem
= &infoPtr
->items
[nItem
];
1447 HEADER_StoreHDItemInHeader(lpItem
, phdi
->mask
, phdi
, bUnicode
);
1449 if (phdi
->mask
& HDI_ORDER
)
1450 if (phdi
->iOrder
>= 0 && phdi
->iOrder
< infoPtr
->uNumItem
)
1451 HEADER_ChangeItemOrder(infoPtr
, nItem
, phdi
->iOrder
);
1453 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCHANGEDW
, nItem
, &hdNotify
);
1455 HEADER_SetItemBounds (infoPtr
);
1457 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1463 static inline LRESULT
1464 HEADER_SetUnicodeFormat (HEADER_INFO
*infoPtr
, WPARAM wParam
)
1466 BOOL bTemp
= (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1468 infoPtr
->nNotifyFormat
= ((BOOL
)wParam
? NFR_UNICODE
: NFR_ANSI
);
1475 HEADER_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1477 HEADER_INFO
*infoPtr
;
1482 infoPtr
= Alloc (sizeof(HEADER_INFO
));
1483 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1485 infoPtr
->hwndSelf
= hwnd
;
1486 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1487 infoPtr
->uNumItem
= 0;
1491 infoPtr
->bRectsValid
= FALSE
;
1492 infoPtr
->hcurArrow
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1493 infoPtr
->hcurDivider
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDER
));
1494 infoPtr
->hcurDivopen
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDEROPEN
));
1495 infoPtr
->bPressed
= FALSE
;
1496 infoPtr
->bTracking
= FALSE
;
1497 infoPtr
->dwStyle
= lpcs
->style
;
1498 infoPtr
->iMoveItem
= 0;
1500 infoPtr
->iHotItem
= -1;
1501 infoPtr
->iHotDivider
= -1;
1502 infoPtr
->iMargin
= 3*GetSystemMetrics(SM_CXEDGE
);
1503 infoPtr
->nNotifyFormat
=
1504 SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_QUERY
);
1507 hOldFont
= SelectObject (hdc
, GetStockObject (SYSTEM_FONT
));
1508 GetTextMetricsW (hdc
, &tm
);
1509 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
1510 SelectObject (hdc
, hOldFont
);
1513 OpenThemeData(hwnd
, themeClass
);
1520 HEADER_Destroy (HEADER_INFO
*infoPtr
)
1522 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
1523 CloseThemeData(theme
);
1528 HEADER_NCDestroy (HEADER_INFO
*infoPtr
)
1530 HEADER_ITEM
*lpItem
;
1533 if (infoPtr
->items
) {
1534 lpItem
= infoPtr
->items
;
1535 for (nItem
= 0; nItem
< infoPtr
->uNumItem
; nItem
++, lpItem
++) {
1536 Free(lpItem
->pszText
);
1538 Free (infoPtr
->items
);
1541 Free(infoPtr
->order
);
1544 ImageList_Destroy (infoPtr
->himl
);
1546 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
1553 static inline LRESULT
1554 HEADER_GetFont (const HEADER_INFO
*infoPtr
)
1556 return (LRESULT
)infoPtr
->hFont
;
1561 HEADER_IsDragDistance(const HEADER_INFO
*infoPtr
, const POINT
*pt
)
1563 /* Windows allows for a mouse movement before starting the drag. We use the
1564 * SM_CXDOUBLECLICK/SM_CYDOUBLECLICK as that distance.
1566 return (abs(infoPtr
->ptLButtonDown
.x
- pt
->x
)>GetSystemMetrics(SM_CXDOUBLECLK
) ||
1567 abs(infoPtr
->ptLButtonDown
.y
- pt
->y
)>GetSystemMetrics(SM_CYDOUBLECLK
));
1571 HEADER_LButtonDblClk (const HEADER_INFO
*infoPtr
, INT x
, INT y
)
1579 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1581 if ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (flags
== HHT_ONHEADER
))
1582 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMDBLCLICKW
, nItem
, NULL
);
1583 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
))
1584 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_DIVIDERDBLCLICKW
, nItem
, NULL
);
1591 HEADER_LButtonDown (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1600 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1602 if ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (flags
== HHT_ONHEADER
)) {
1603 SetCapture (infoPtr
->hwndSelf
);
1604 infoPtr
->bCaptured
= TRUE
;
1605 infoPtr
->bPressed
= TRUE
;
1606 infoPtr
->bDragging
= FALSE
;
1607 infoPtr
->iMoveItem
= nItem
;
1608 infoPtr
->ptLButtonDown
= pt
;
1610 infoPtr
->items
[nItem
].bDown
= TRUE
;
1612 /* Send WM_CUSTOMDRAW */
1613 hdc
= GetDC (infoPtr
->hwndSelf
);
1614 HEADER_RefreshItem (infoPtr
, nItem
);
1615 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1617 TRACE("Pressed item %d!\n", nItem
);
1619 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
)) {
1620 INT iCurrWidth
= infoPtr
->items
[nItem
].cxy
;
1621 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_BEGINTRACKW
, nItem
, HDI_WIDTH
, iCurrWidth
))
1623 SetCapture (infoPtr
->hwndSelf
);
1624 infoPtr
->bCaptured
= TRUE
;
1625 infoPtr
->bTracking
= TRUE
;
1626 infoPtr
->iMoveItem
= nItem
;
1627 infoPtr
->xTrackOffset
= infoPtr
->items
[nItem
].rect
.right
- pt
.x
;
1629 if (!(infoPtr
->dwStyle
& HDS_FULLDRAG
)) {
1630 infoPtr
->xOldTrack
= infoPtr
->items
[nItem
].rect
.right
;
1631 hdc
= GetDC (infoPtr
->hwndSelf
);
1632 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1633 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1636 TRACE("Begin tracking item %d!\n", nItem
);
1645 HEADER_LButtonUp (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1654 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1656 if (infoPtr
->bPressed
) {
1658 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1660 if (infoPtr
->bDragging
)
1662 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1665 ImageList_DragShowNolock(FALSE
);
1666 ImageList_EndDrag();
1668 if (infoPtr
->iHotDivider
== -1)
1670 else if (infoPtr
->iHotDivider
== infoPtr
->uNumItem
)
1671 iNewOrder
= infoPtr
->uNumItem
-1;
1674 iNewOrder
= HEADER_IndexToOrder(infoPtr
, infoPtr
->iHotDivider
);
1675 if (iNewOrder
> lpItem
->iOrder
)
1679 if (iNewOrder
!= -1 &&
1680 !HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ENDDRAG
, infoPtr
->iMoveItem
, HDI_ORDER
, iNewOrder
))
1682 HEADER_ChangeItemOrder(infoPtr
, infoPtr
->iMoveItem
, iNewOrder
);
1683 infoPtr
->bRectsValid
= FALSE
;
1684 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1687 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->items
[infoPtr
->iMoveItem
].rect
, FALSE
);
1689 infoPtr
->bDragging
= FALSE
;
1690 HEADER_SetHotDivider(infoPtr
, FALSE
, -1);
1694 hdc
= GetDC (infoPtr
->hwndSelf
);
1695 HEADER_RefreshItem (infoPtr
, infoPtr
->iMoveItem
);
1696 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1698 if (!(infoPtr
->dwStyle
& HDS_DRAGDROP
) || !HEADER_IsDragDistance(infoPtr
, &pt
))
1699 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCLICKW
, infoPtr
->iMoveItem
, NULL
);
1702 TRACE("Released item %d!\n", infoPtr
->iMoveItem
);
1703 infoPtr
->bPressed
= FALSE
;
1705 else if (infoPtr
->bTracking
) {
1706 INT iNewWidth
= pt
.x
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
+ infoPtr
->xTrackOffset
;
1709 TRACE("End tracking item %d!\n", infoPtr
->iMoveItem
);
1710 infoPtr
->bTracking
= FALSE
;
1712 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ENDTRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
);
1714 if (!(infoPtr
->dwStyle
& HDS_FULLDRAG
)) {
1715 hdc
= GetDC (infoPtr
->hwndSelf
);
1716 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1717 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1720 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
))
1722 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= iNewWidth
;
1723 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
);
1726 HEADER_SetItemBounds (infoPtr
);
1727 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1730 if (infoPtr
->bCaptured
) {
1731 infoPtr
->bCaptured
= FALSE
;
1733 HEADER_SendSimpleNotify (infoPtr
, NM_RELEASEDCAPTURE
);
1741 HEADER_NotifyFormat (HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1746 return infoPtr
->nNotifyFormat
;
1749 infoPtr
->nNotifyFormat
=
1750 SendMessageW ((HWND
)wParam
, WM_NOTIFYFORMAT
,
1751 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)NF_QUERY
);
1752 return infoPtr
->nNotifyFormat
;
1759 HEADER_MouseLeave (HEADER_INFO
*infoPtr
)
1761 /* Reset hot-tracked item when mouse leaves control. */
1762 INT oldHotItem
= infoPtr
->iHotItem
;
1763 HDC hdc
= GetDC (infoPtr
->hwndSelf
);
1765 infoPtr
->iHotItem
= -1;
1766 if (oldHotItem
!= -1) HEADER_RefreshItem (infoPtr
, oldHotItem
);
1767 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1774 HEADER_MouseMove (HEADER_INFO
*infoPtr
, LPARAM lParam
)
1780 /* With theming, hottracking is always enabled */
1781 BOOL hotTrackEnabled
=
1782 ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (infoPtr
->dwStyle
& HDS_HOTTRACK
))
1783 || (GetWindowTheme (infoPtr
->hwndSelf
) != NULL
);
1784 INT oldHotItem
= infoPtr
->iHotItem
;
1786 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1787 pt
.y
= (INT
)(SHORT
)HIWORD(lParam
);
1788 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1790 if (hotTrackEnabled
) {
1791 if (flags
& (HHT_ONHEADER
| HHT_ONDIVIDER
| HHT_ONDIVOPEN
))
1792 infoPtr
->iHotItem
= nItem
;
1794 infoPtr
->iHotItem
= -1;
1797 if (infoPtr
->bCaptured
) {
1798 /* check if we should drag the header */
1799 if (infoPtr
->bPressed
&& !infoPtr
->bDragging
&& (infoPtr
->dwStyle
& HDS_DRAGDROP
)
1800 && HEADER_IsDragDistance(infoPtr
, &pt
))
1802 if (!HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_BEGINDRAG
, infoPtr
->iMoveItem
, NULL
))
1804 HIMAGELIST hDragItem
= (HIMAGELIST
)HEADER_CreateDragImage(infoPtr
, infoPtr
->iMoveItem
);
1805 if (hDragItem
!= NULL
)
1807 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1808 TRACE("Starting item drag\n");
1809 ImageList_BeginDrag(hDragItem
, 0, pt
.x
- lpItem
->rect
.left
, 0);
1810 ImageList_DragShowNolock(TRUE
);
1811 ImageList_Destroy(hDragItem
);
1812 infoPtr
->bDragging
= TRUE
;
1817 if (infoPtr
->bDragging
)
1822 ClientToScreen(infoPtr
->hwndSelf
, &drag
);
1823 ImageList_DragMove(drag
.x
, drag
.y
);
1824 HEADER_SetHotDivider(infoPtr
, TRUE
, lParam
);
1827 if (infoPtr
->bPressed
&& !infoPtr
->bDragging
) {
1828 BOOL oldState
= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
;
1829 if ((nItem
== infoPtr
->iMoveItem
) && (flags
== HHT_ONHEADER
))
1830 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= TRUE
;
1832 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1833 if (oldState
!= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
) {
1834 hdc
= GetDC (infoPtr
->hwndSelf
);
1835 HEADER_RefreshItem (infoPtr
, infoPtr
->iMoveItem
);
1836 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1839 TRACE("Moving pressed item %d!\n", infoPtr
->iMoveItem
);
1841 else if (infoPtr
->bTracking
) {
1842 if (infoPtr
->dwStyle
& HDS_FULLDRAG
) {
1843 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1844 nWidth
= pt
.x
- lpItem
->rect
.left
+ infoPtr
->xTrackOffset
;
1845 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, nWidth
))
1847 INT nOldWidth
= lpItem
->rect
.right
- lpItem
->rect
.left
;
1851 if (nWidth
< 0) nWidth
= 0;
1852 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= nWidth
;
1853 HEADER_SetItemBounds(infoPtr
);
1855 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1856 rcScroll
= rcClient
;
1857 rcScroll
.left
= lpItem
->rect
.left
+ nOldWidth
;
1858 ScrollWindowEx(infoPtr
->hwndSelf
, nWidth
- nOldWidth
, 0, &rcScroll
, &rcClient
, NULL
, NULL
, 0);
1859 InvalidateRect(infoPtr
->hwndSelf
, &lpItem
->rect
, FALSE
);
1860 UpdateWindow(infoPtr
->hwndSelf
);
1862 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, nWidth
);
1867 hdc
= GetDC (infoPtr
->hwndSelf
);
1868 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1869 infoPtr
->xOldTrack
= pt
.x
+ infoPtr
->xTrackOffset
;
1870 if (infoPtr
->xOldTrack
< infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
)
1871 infoPtr
->xOldTrack
= infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1872 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1873 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1874 iTrackWidth
= infoPtr
->xOldTrack
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1875 /* FIXME: should stop tracking if HDN_TRACK returns TRUE */
1876 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_TRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iTrackWidth
);
1879 TRACE("Tracking item %d!\n", infoPtr
->iMoveItem
);
1883 if (hotTrackEnabled
) {
1884 TRACKMOUSEEVENT tme
;
1885 if (oldHotItem
!= infoPtr
->iHotItem
&& !infoPtr
->bDragging
) {
1886 hdc
= GetDC (infoPtr
->hwndSelf
);
1887 if (oldHotItem
!= -1) HEADER_RefreshItem (infoPtr
, oldHotItem
);
1888 if (infoPtr
->iHotItem
!= -1) HEADER_RefreshItem (infoPtr
, infoPtr
->iHotItem
);
1889 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1891 tme
.cbSize
= sizeof( tme
);
1892 tme
.dwFlags
= TME_LEAVE
;
1893 tme
.hwndTrack
= infoPtr
->hwndSelf
;
1894 TrackMouseEvent( &tme
);
1902 HEADER_Paint (HEADER_INFO
*infoPtr
, HDC hdcParam
)
1907 hdc
= hdcParam
==0 ? BeginPaint (infoPtr
->hwndSelf
, &ps
) : hdcParam
;
1908 HEADER_Refresh (infoPtr
, hdc
);
1910 EndPaint (infoPtr
->hwndSelf
, &ps
);
1916 HEADER_RButtonUp (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1924 /* Send a Notify message */
1925 bRet
= HEADER_SendSimpleNotify (infoPtr
, NM_RCLICK
);
1927 /* Change to screen coordinate for WM_CONTEXTMENU */
1928 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
1930 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1931 SendMessageW( infoPtr
->hwndSelf
, WM_CONTEXTMENU
, (WPARAM
) infoPtr
->hwndSelf
, MAKELPARAM(pt
.x
, pt
.y
));
1938 HEADER_SetCursor (HEADER_INFO
*infoPtr
, LPARAM lParam
)
1944 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam
), HIWORD(lParam
));
1947 ScreenToClient (infoPtr
->hwndSelf
, &pt
);
1949 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1951 if (flags
== HHT_ONDIVIDER
)
1952 SetCursor (infoPtr
->hcurDivider
);
1953 else if (flags
== HHT_ONDIVOPEN
)
1954 SetCursor (infoPtr
->hcurDivopen
);
1956 SetCursor (infoPtr
->hcurArrow
);
1963 HEADER_SetFont (HEADER_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
1969 infoPtr
->hFont
= hFont
;
1972 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
));
1973 GetTextMetricsW (hdc
, &tm
);
1974 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
1975 SelectObject (hdc
, hOldFont
);
1978 infoPtr
->bRectsValid
= FALSE
;
1981 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1987 static LRESULT
HEADER_SetRedraw(HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1989 /* ignoring the InvalidateRect calls is handled by user32. But some apps expect
1990 * that we invalidate the header and this has to be done manually */
1993 ret
= DefWindowProcW(infoPtr
->hwndSelf
, WM_SETREDRAW
, wParam
, lParam
);
1995 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1999 static INT
HEADER_StyleChanged(HEADER_INFO
*infoPtr
, WPARAM wStyleType
,
2000 const STYLESTRUCT
*lpss
)
2002 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2003 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
2005 if (wStyleType
!= GWL_STYLE
) return 0;
2007 infoPtr
->dwStyle
= lpss
->styleNew
;
2012 /* Update the theme handle after a theme change */
2013 static LRESULT
HEADER_ThemeChanged(const HEADER_INFO
*infoPtr
)
2015 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
2016 CloseThemeData(theme
);
2017 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
2018 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
2023 static LRESULT WINAPI
2024 HEADER_WindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2026 HEADER_INFO
*infoPtr
= (HEADER_INFO
*)GetWindowLongPtrW(hwnd
, 0);
2028 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, msg
, wParam
, lParam
);
2029 if (!infoPtr
&& (msg
!= WM_CREATE
))
2030 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
2032 /* case HDM_CLEARFILTER: */
2034 case HDM_CREATEDRAGIMAGE
:
2035 return HEADER_CreateDragImage (infoPtr
, (INT
)wParam
);
2037 case HDM_DELETEITEM
:
2038 return HEADER_DeleteItem (infoPtr
, (INT
)wParam
);
2040 /* case HDM_EDITFILTER: */
2042 case HDM_GETBITMAPMARGIN
:
2043 return HEADER_GetBitmapMargin(infoPtr
);
2045 case HDM_GETIMAGELIST
:
2046 return HEADER_GetImageList (infoPtr
);
2050 return HEADER_GetItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_GETITEMW
);
2052 case HDM_GETITEMCOUNT
:
2053 return HEADER_GetItemCount (infoPtr
);
2055 case HDM_GETITEMRECT
:
2056 return HEADER_GetItemRect (infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
2058 case HDM_GETORDERARRAY
:
2059 return HEADER_GetOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
2061 case HDM_GETUNICODEFORMAT
:
2062 return HEADER_GetUnicodeFormat (infoPtr
);
2065 return HEADER_HitTest (infoPtr
, (LPHDHITTESTINFO
)lParam
);
2067 case HDM_INSERTITEMA
:
2068 case HDM_INSERTITEMW
:
2069 return HEADER_InsertItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_INSERTITEMW
);
2072 return HEADER_Layout (infoPtr
, (LPHDLAYOUT
)lParam
);
2074 case HDM_ORDERTOINDEX
:
2075 return HEADER_OrderToIndex(infoPtr
, (INT
)wParam
);
2077 case HDM_SETBITMAPMARGIN
:
2078 return HEADER_SetBitmapMargin(infoPtr
, (INT
)wParam
);
2080 /* case HDM_SETFILTERCHANGETIMEOUT: */
2082 case HDM_SETHOTDIVIDER
:
2083 return HEADER_SetHotDivider(infoPtr
, wParam
, lParam
);
2085 case HDM_SETIMAGELIST
:
2086 return HEADER_SetImageList (infoPtr
, (HIMAGELIST
)lParam
);
2090 return HEADER_SetItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_SETITEMW
);
2092 case HDM_SETORDERARRAY
:
2093 return HEADER_SetOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
2095 case HDM_SETUNICODEFORMAT
:
2096 return HEADER_SetUnicodeFormat (infoPtr
, wParam
);
2099 return HEADER_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
2102 return HEADER_Destroy (infoPtr
);
2105 return HEADER_NCDestroy (infoPtr
);
2111 return DLGC_WANTTAB
| DLGC_WANTARROWS
;
2114 return HEADER_GetFont (infoPtr
);
2116 case WM_LBUTTONDBLCLK
:
2117 return HEADER_LButtonDblClk (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2119 case WM_LBUTTONDOWN
:
2120 return HEADER_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2123 return HEADER_LButtonUp (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2126 return HEADER_MouseLeave (infoPtr
);
2129 return HEADER_MouseMove (infoPtr
, lParam
);
2131 case WM_NOTIFYFORMAT
:
2132 return HEADER_NotifyFormat (infoPtr
, wParam
, lParam
);
2135 return HEADER_Size (infoPtr
);
2137 case WM_THEMECHANGED
:
2138 return HEADER_ThemeChanged (infoPtr
);
2140 case WM_PRINTCLIENT
:
2142 return HEADER_Paint (infoPtr
, (HDC
)wParam
);
2145 return HEADER_RButtonUp (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2148 return HEADER_SetCursor (infoPtr
, lParam
);
2151 return HEADER_SetFont (infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
2154 return HEADER_SetRedraw(infoPtr
, wParam
, lParam
);
2156 case WM_STYLECHANGED
:
2157 return HEADER_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
2159 case WM_SYSCOLORCHANGE
:
2160 COMCTL32_RefreshSysColors();
2164 if ((msg
>= WM_USER
) && (msg
< WM_APP
) && !COMCTL32_IsReflectedMessage(msg
))
2165 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
2166 msg
, wParam
, lParam
);
2167 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
2173 HEADER_Register (void)
2177 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2178 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
2179 wndClass
.lpfnWndProc
= HEADER_WindowProc
;
2180 wndClass
.cbClsExtra
= 0;
2181 wndClass
.cbWndExtra
= sizeof(HEADER_INFO
*);
2182 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2183 wndClass
.lpszClassName
= WC_HEADERW
;
2185 RegisterClassW (&wndClass
);
2190 HEADER_Unregister (void)
2192 UnregisterClassW (WC_HEADERW
, NULL
);