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
43 #include "wine/debug.h"
44 #include "wine/heap.h"
46 WINE_DEFAULT_DEBUG_CHANNEL(header
);
56 INT iOrder
; /* see documentation of HD_ITEM */
58 BOOL bDown
; /* is item pressed? (used for drawing) */
59 RECT rect
; /* bounding rectangle of the item */
60 DWORD callbackMask
; /* HDI_* flags for items that are callback */
66 HWND hwndSelf
; /* Control window */
67 HWND hwndNotify
; /* Owner window to send notifications to */
68 INT nNotifyFormat
; /* format used for WM_NOTIFY messages */
69 UINT uNumItem
; /* number of items (columns) */
70 INT nHeight
; /* height of the header (pixels) */
71 HFONT hFont
; /* handle to the current font */
72 HCURSOR hcurArrow
; /* handle to the arrow cursor */
73 HCURSOR hcurDivider
; /* handle to a cursor (used over dividers) <-|-> */
74 HCURSOR hcurDivopen
; /* handle to a cursor (used over dividers) <-||-> */
75 BOOL bCaptured
; /* Is the mouse captured? */
76 BOOL bPressed
; /* Is a header item pressed (down)? */
77 BOOL bDragging
; /* Are we dragging an item? */
78 BOOL bTracking
; /* Is in tracking mode? */
79 POINT ptLButtonDown
; /* The point where the left button was pressed */
80 DWORD dwStyle
; /* the cached window GWL_STYLE */
81 INT iMoveItem
; /* index of tracked item. (Tracking mode) */
82 INT xTrackOffset
; /* distance between the right side of the tracked item and the cursor */
83 INT xOldTrack
; /* track offset (see above) after the last WM_MOUSEMOVE */
84 INT iHotItem
; /* index of hot item (cursor is over this item) */
85 INT iHotDivider
; /* index of the hot divider (used while dragging an item or by HDM_SETHOTDIVIDER) */
86 INT iMargin
; /* width of the margin that surrounds a bitmap */
87 INT filter_change_timeout
; /* change timeout set with HDM_SETFILTERCHANGETIMEOUT */
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
[] = L
"Header";
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 heap_free(lpItem
->pszText
);
145 lpItem
->pszText
= NULL
;
147 if (phdi
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers != TEXTCALLBACKA too */
149 const WCHAR
*pszText
= phdi
->pszText
!= NULL
? phdi
->pszText
: L
"";
151 Str_SetPtrW(&lpItem
->pszText
, pszText
);
153 Str_SetPtrAtoW(&lpItem
->pszText
, (LPCSTR
)pszText
);
154 lpItem
->callbackMask
&= ~HDI_TEXT
;
158 lpItem
->pszText
= NULL
;
159 lpItem
->callbackMask
|= HDI_TEXT
;
164 static inline LRESULT
165 HEADER_IndexToOrder (const HEADER_INFO
*infoPtr
, INT iItem
)
167 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
168 return lpItem
->iOrder
;
173 HEADER_OrderToIndex(const HEADER_INFO
*infoPtr
, INT iorder
)
175 if ((iorder
<0) || iorder
>= infoPtr
->uNumItem
)
177 return infoPtr
->order
[iorder
];
181 HEADER_ChangeItemOrder(const HEADER_INFO
*infoPtr
, INT iItem
, INT iNewOrder
)
183 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
186 TRACE("%d: %d->%d\n", iItem
, lpItem
->iOrder
, iNewOrder
);
187 if (lpItem
->iOrder
< iNewOrder
)
189 memmove(&infoPtr
->order
[lpItem
->iOrder
],
190 &infoPtr
->order
[lpItem
->iOrder
+ 1],
191 (iNewOrder
- lpItem
->iOrder
) * sizeof(INT
));
193 if (iNewOrder
< lpItem
->iOrder
)
195 memmove(&infoPtr
->order
[iNewOrder
+ 1],
196 &infoPtr
->order
[iNewOrder
],
197 (lpItem
->iOrder
- iNewOrder
) * sizeof(INT
));
199 infoPtr
->order
[iNewOrder
] = iItem
;
200 nMin
= min(lpItem
->iOrder
, iNewOrder
);
201 nMax
= max(lpItem
->iOrder
, iNewOrder
);
202 for (i
= nMin
; i
<= nMax
; i
++)
203 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
206 /* Note: if iItem is the last item then this function returns infoPtr->uNumItem */
208 HEADER_NextItem(const HEADER_INFO
*infoPtr
, INT iItem
)
210 return HEADER_OrderToIndex(infoPtr
, HEADER_IndexToOrder(infoPtr
, iItem
)+1);
214 HEADER_PrevItem(const HEADER_INFO
*infoPtr
, INT iItem
)
216 return HEADER_OrderToIndex(infoPtr
, HEADER_IndexToOrder(infoPtr
, iItem
)-1);
219 /* TRUE when item is not resizable with dividers,
220 note that valid index should be supplied */
222 HEADER_IsItemFixed(const HEADER_INFO
*infoPtr
, INT iItem
)
224 return (infoPtr
->dwStyle
& HDS_NOSIZING
) || (infoPtr
->items
[iItem
].fmt
& HDF_FIXEDWIDTH
);
228 HEADER_SetItemBounds (HEADER_INFO
*infoPtr
)
235 infoPtr
->bRectsValid
= TRUE
;
237 if (infoPtr
->uNumItem
== 0)
240 GetClientRect (infoPtr
->hwndSelf
, &rect
);
243 for (i
= 0; i
< infoPtr
->uNumItem
; i
++) {
244 phdi
= &infoPtr
->items
[HEADER_OrderToIndex(infoPtr
,i
)];
245 phdi
->rect
.top
= rect
.top
;
246 phdi
->rect
.bottom
= rect
.bottom
;
248 phdi
->rect
.right
= phdi
->rect
.left
+ ((phdi
->cxy
>0)?phdi
->cxy
:0);
249 x
= phdi
->rect
.right
;
254 HEADER_Size (HEADER_INFO
*infoPtr
)
256 HEADER_SetItemBounds(infoPtr
);
260 static void HEADER_GetHotDividerRect(const HEADER_INFO
*infoPtr
, RECT
*r
)
262 INT iDivider
= infoPtr
->iHotDivider
;
263 if (infoPtr
->uNumItem
> 0)
267 if (iDivider
< infoPtr
->uNumItem
)
269 lpItem
= &infoPtr
->items
[iDivider
];
270 r
->left
= lpItem
->rect
.left
- HOT_DIVIDER_WIDTH
/2;
271 r
->right
= lpItem
->rect
.left
+ HOT_DIVIDER_WIDTH
/2;
275 lpItem
= &infoPtr
->items
[HEADER_OrderToIndex(infoPtr
, infoPtr
->uNumItem
-1)];
276 r
->left
= lpItem
->rect
.right
- HOT_DIVIDER_WIDTH
/2;
277 r
->right
= lpItem
->rect
.right
+ HOT_DIVIDER_WIDTH
/2;
279 r
->top
= lpItem
->rect
.top
;
280 r
->bottom
= lpItem
->rect
.bottom
;
285 GetClientRect(infoPtr
->hwndSelf
, &clientRect
);
287 r
->right
= r
->left
+ HOT_DIVIDER_WIDTH
/2;
292 HEADER_FillItemFrame(HEADER_INFO
*infoPtr
, HDC hdc
, RECT
*r
, const HEADER_ITEM
*item
, BOOL hottrack
)
294 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
297 int state
= (item
->bDown
) ? HIS_PRESSED
: (hottrack
? HIS_HOT
: HIS_NORMAL
);
298 DrawThemeBackground (theme
, hdc
, HP_HEADERITEM
, state
, r
, NULL
);
299 GetThemeBackgroundContentRect (theme
, hdc
, HP_HEADERITEM
, state
, r
, r
);
303 HBRUSH hbr
= CreateSolidBrush(GetBkColor(hdc
));
304 FillRect(hdc
, r
, hbr
);
310 HEADER_DrawItemFrame(HEADER_INFO
*infoPtr
, HDC hdc
, RECT
*r
, const HEADER_ITEM
*item
)
312 if (GetWindowTheme(infoPtr
->hwndSelf
)) return;
314 if (!(infoPtr
->dwStyle
& HDS_FLAT
))
316 if (infoPtr
->dwStyle
& HDS_BUTTONS
) {
318 DrawEdge (hdc
, r
, BDR_RAISEDOUTER
, BF_RECT
| BF_FLAT
| BF_ADJUST
);
320 DrawEdge (hdc
, r
, EDGE_RAISED
, BF_RECT
| BF_SOFT
| BF_ADJUST
);
323 DrawEdge (hdc
, r
, EDGE_ETCHED
, BF_BOTTOM
| BF_RIGHT
| BF_ADJUST
);
327 /* Create a region for the sort arrow with its bounding rect's top-left
328 co-ord x,y and its height h. */
329 static HRGN
create_sort_arrow( INT x
, INT y
, INT h
, BOOL is_up
)
332 RGNDATA
*data
= (RGNDATA
*)buffer
;
333 DWORD size
= FIELD_OFFSET(RGNDATA
, Buffer
[h
* sizeof(RECT
)]);
337 if (size
> sizeof(buffer
))
339 data
= heap_alloc( size
);
340 if (!data
) return NULL
;
342 data
->rdh
.dwSize
= sizeof(data
->rdh
);
343 data
->rdh
.iType
= RDH_RECTANGLES
;
344 data
->rdh
.nCount
= 0;
345 data
->rdh
.nRgnSize
= h
* sizeof(RECT
);
353 x
+= h
- 1; /* set x to the centre */
355 for (i
= 0; i
< h
; i
++, y
+= yinc
)
357 RECT
*rect
= (RECT
*)data
->Buffer
+ data
->rdh
.nCount
;
360 rect
->right
= x
+ i
+ 1;
361 rect
->bottom
= y
+ 1;
364 rgn
= ExtCreateRegion( NULL
, size
, data
);
365 if (data
!= (RGNDATA
*)buffer
) heap_free( data
);
370 HEADER_DrawItem (HEADER_INFO
*infoPtr
, HDC hdc
, INT iItem
, BOOL bHotTrack
, LRESULT lCDFlags
)
372 HEADER_ITEM
*phdi
= &infoPtr
->items
[iItem
];
375 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
379 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem
, bHotTrack
, (infoPtr
->nNotifyFormat
== NFR_UNICODE
));
382 if (r
.right
- r
.left
== 0)
383 return phdi
->rect
.right
;
386 state
= (phdi
->bDown
) ? HIS_PRESSED
: (bHotTrack
? HIS_HOT
: HIS_NORMAL
);
388 /* Set the colors before sending NM_CUSTOMDRAW so that it can change them */
389 SetTextColor(hdc
, (bHotTrack
&& !theme
) ? comctl32_color
.clrHighlight
: comctl32_color
.clrBtnText
);
390 SetBkColor(hdc
, comctl32_color
.clr3dFace
);
392 if (lCDFlags
& CDRF_NOTIFYITEMDRAW
&& !(phdi
->fmt
& HDF_OWNERDRAW
))
394 LRESULT lCDItemFlags
;
396 nmcd
.dwDrawStage
= CDDS_PREPAINT
| CDDS_ITEM
;
398 nmcd
.dwItemSpec
= iItem
;
400 nmcd
.uItemState
= phdi
->bDown
? CDIS_SELECTED
: 0;
401 nmcd
.lItemlParam
= phdi
->lParam
;
403 lCDItemFlags
= HEADER_SendNotify(infoPtr
, NM_CUSTOMDRAW
, (NMHDR
*)&nmcd
);
404 if (lCDItemFlags
& CDRF_SKIPDEFAULT
)
405 return phdi
->rect
.right
;
408 /* Fill background, owner could draw over it. */
409 HEADER_FillItemFrame(infoPtr
, hdc
, &r
, phdi
, bHotTrack
);
411 if (phdi
->fmt
& HDF_OWNERDRAW
)
416 dis
.CtlType
= ODT_HEADER
;
417 dis
.CtlID
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
419 dis
.itemAction
= ODA_DRAWENTIRE
;
420 dis
.itemState
= phdi
->bDown
? ODS_SELECTED
: 0;
421 dis
.hwndItem
= infoPtr
->hwndSelf
;
423 dis
.rcItem
= phdi
->rect
;
424 dis
.itemData
= phdi
->lParam
;
425 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
426 ret
= SendMessageW (infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
427 if (oldBkMode
!= TRANSPARENT
)
428 SetBkMode(hdc
, oldBkMode
);
431 HEADER_FillItemFrame(infoPtr
, hdc
, &r
, phdi
, bHotTrack
);
433 /* Edges are always drawn if we don't have attached theme. */
434 HEADER_DrawItemFrame(infoPtr
, hdc
, &r
, phdi
);
435 /* If application processed WM_DRAWITEM we should skip label painting,
436 edges are drawn no matter what. */
437 if (ret
) return phdi
->rect
.right
;
440 HEADER_DrawItemFrame(infoPtr
, hdc
, &r
, phdi
);
447 /* Now text and image */
449 INT rw
, rh
; /* width and height of r */
450 INT
*x
= NULL
; /* x and ... */
451 UINT
*w
= NULL
; /* ... width of the pic (bmp or img) which is part of cnt */
452 /* cnt,txt,img,bmp */
456 INT sort_w
, sort_x
, sort_h
;
459 HEADER_PrepareCallbackItems(infoPtr
, iItem
, HDI_TEXT
|HDI_IMAGE
);
460 cw
= iw
= bw
= sort_w
= sort_h
= 0;
461 rw
= r
.right
- r
.left
;
462 rh
= r
.bottom
- r
.top
;
464 if (phdi
->fmt
& HDF_STRING
) {
467 SetRectEmpty(&textRect
);
470 GetThemeTextExtent(theme
, hdc
, HP_HEADERITEM
, state
, phdi
->pszText
, -1,
471 DT_LEFT
|DT_VCENTER
|DT_SINGLELINE
, NULL
, &textRect
);
473 DrawTextW (hdc
, phdi
->pszText
, -1,
474 &textRect
, DT_LEFT
|DT_VCENTER
|DT_SINGLELINE
|DT_CALCRECT
);
476 cw
= textRect
.right
- textRect
.left
+ 2 * infoPtr
->iMargin
;
479 if (phdi
->fmt
& (HDF_SORTUP
| HDF_SORTDOWN
)) {
480 sort_h
= MulDiv( infoPtr
->nHeight
- VERT_BORDER
, 4, 13 );
481 sort_w
= 2 * sort_h
- 1 + infoPtr
->iMargin
* 2;
483 } else { /* sort arrows take precedent over images/bitmaps */
484 if ((phdi
->fmt
& HDF_IMAGE
) && ImageList_GetIconSize( infoPtr
->himl
, &img_cx
, &img_cy
)) {
485 iw
= img_cx
+ 2 * infoPtr
->iMargin
;
490 if ((phdi
->fmt
& HDF_BITMAP
) && (phdi
->hbm
)) {
491 GetObjectW (phdi
->hbm
, sizeof(BITMAP
), &bmp
);
492 bw
= bmp
.bmWidth
+ 2 * infoPtr
->iMargin
;
502 /* align cx using the unclipped cw */
503 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_LEFT
)
505 else if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_CENTER
)
506 cx
= r
.left
+ rw
/ 2 - cw
/ 2;
513 if (cx
+ cw
> r
.right
)
516 tx
= cx
+ infoPtr
->iMargin
;
517 /* since cw might have changed we have to recalculate tw */
518 tw
= cw
- infoPtr
->iMargin
* 2;
521 sort_x
= cx
+ tw
+ infoPtr
->iMargin
* 3;
525 if (phdi
->fmt
& HDF_BITMAP_ON_RIGHT
) {
526 /* put pic behind text */
527 *x
= cx
+ tw
+ infoPtr
->iMargin
* 3;
529 *x
= cx
+ infoPtr
->iMargin
;
530 /* move text behind pic */
536 /* since we're done with the layout we can
537 now calculate the position of bmp which
538 has no influence on alignment and layout
540 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_RIGHT
)
541 bx
= cx
- bw
+ infoPtr
->iMargin
;
543 bx
= cx
+ cw
+ infoPtr
->iMargin
;
546 if (sort_w
|| iw
|| bw
) {
547 HDC hClipDC
= GetDC(infoPtr
->hwndSelf
);
548 HRGN hClipRgn
= CreateRectRgn(r
.left
, r
.top
, r
.right
, r
.bottom
);
549 SelectClipRgn(hClipDC
, hClipRgn
);
552 HRGN arrow
= create_sort_arrow( sort_x
, r
.top
+ (rh
- sort_h
) / 2,
553 sort_h
, phdi
->fmt
& HDF_SORTUP
);
555 FillRgn( hClipDC
, arrow
, GetSysColorBrush( COLOR_GRAYTEXT
) );
556 DeleteObject( arrow
);
561 HDC hdcBitmap
= CreateCompatibleDC (hClipDC
);
562 SelectObject (hdcBitmap
, phdi
->hbm
);
563 BitBlt (hClipDC
, bx
, r
.top
+ (rh
- bmp
.bmHeight
) / 2,
564 bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
565 DeleteDC (hdcBitmap
);
569 ImageList_DrawEx (infoPtr
->himl
, phdi
->iImage
, hClipDC
,
570 ix
, r
.top
+ (rh
- img_cy
) / 2,
571 img_cx
, img_cy
, CLR_DEFAULT
, CLR_DEFAULT
, 0);
574 DeleteObject(hClipRgn
);
575 ReleaseDC(infoPtr
->hwndSelf
, hClipDC
);
578 if (((phdi
->fmt
& HDF_STRING
)
579 || (!(phdi
->fmt
& (HDF_OWNERDRAW
|HDF_STRING
|HDF_BITMAP
|
580 HDF_BITMAP_ON_RIGHT
|HDF_IMAGE
)))) /* no explicit format specified? */
581 && (phdi
->pszText
)) {
582 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
586 DrawThemeText(theme
, hdc
, HP_HEADERITEM
, state
, phdi
->pszText
,
587 -1, DT_LEFT
|DT_END_ELLIPSIS
|DT_VCENTER
|DT_SINGLELINE
,
590 DrawTextW (hdc
, phdi
->pszText
, -1,
591 &r
, DT_LEFT
|DT_END_ELLIPSIS
|DT_VCENTER
|DT_SINGLELINE
);
593 if (oldBkMode
!= TRANSPARENT
)
594 SetBkMode(hdc
, oldBkMode
);
596 HEADER_FreeCallbackItems(phdi
);
599 return phdi
->rect
.right
;
603 HEADER_DrawHotDivider(const HEADER_INFO
*infoPtr
, HDC hdc
)
608 HEADER_GetHotDividerRect(infoPtr
, &r
);
609 brush
= CreateSolidBrush(comctl32_color
.clrHighlight
);
610 FillRect(hdc
, &r
, brush
);
615 HEADER_Refresh (HEADER_INFO
*infoPtr
, HDC hdc
)
617 HFONT hFont
, hOldFont
;
623 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
625 if (!infoPtr
->bRectsValid
)
626 HEADER_SetItemBounds(infoPtr
);
628 /* get rect for the bar, adjusted for the border */
629 GetClientRect (infoPtr
->hwndSelf
, &rect
);
630 lCDFlags
= HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_PREPAINT
, hdc
, &rect
);
632 if (infoPtr
->bDragging
)
633 ImageList_DragShowNolock(FALSE
);
635 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
);
636 hOldFont
= SelectObject (hdc
, hFont
);
638 /* draw Background */
639 if (infoPtr
->uNumItem
== 0 && theme
== NULL
) {
640 hbrBk
= GetSysColorBrush(COLOR_3DFACE
);
641 FillRect(hdc
, &rect
, hbrBk
);
645 for (i
= 0; x
<= rect
.right
&& i
< infoPtr
->uNumItem
; i
++) {
646 int idx
= HEADER_OrderToIndex(infoPtr
,i
);
647 if (RectVisible(hdc
, &infoPtr
->items
[idx
].rect
))
648 HEADER_DrawItem(infoPtr
, hdc
, idx
, infoPtr
->iHotItem
== idx
, lCDFlags
);
649 x
= infoPtr
->items
[idx
].rect
.right
;
654 if ((x
<= rect
.right
) && RectVisible(hdc
, &rcRest
) && (infoPtr
->uNumItem
> 0)) {
656 DrawThemeBackground(theme
, hdc
, HP_HEADERITEM
, HIS_NORMAL
, &rcRest
, NULL
);
658 else if (infoPtr
->dwStyle
& HDS_FLAT
) {
659 hbrBk
= GetSysColorBrush(COLOR_3DFACE
);
660 FillRect(hdc
, &rcRest
, hbrBk
);
664 if (infoPtr
->dwStyle
& HDS_BUTTONS
)
665 DrawEdge (hdc
, &rcRest
, EDGE_RAISED
, BF_TOP
|BF_LEFT
|BF_BOTTOM
|BF_SOFT
|BF_MIDDLE
);
667 DrawEdge (hdc
, &rcRest
, EDGE_ETCHED
, BF_BOTTOM
|BF_MIDDLE
);
671 if (infoPtr
->iHotDivider
!= -1)
672 HEADER_DrawHotDivider(infoPtr
, hdc
);
674 if (infoPtr
->bDragging
)
675 ImageList_DragShowNolock(TRUE
);
676 SelectObject (hdc
, hOldFont
);
678 if (lCDFlags
& CDRF_NOTIFYPOSTPAINT
)
679 HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_POSTPAINT
, hdc
, &rect
);
684 HEADER_RefreshItem (HEADER_INFO
*infoPtr
, INT iItem
)
686 if (!infoPtr
->bRectsValid
)
687 HEADER_SetItemBounds(infoPtr
);
689 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->items
[iItem
].rect
, FALSE
);
694 HEADER_InternalHitTest (const HEADER_INFO
*infoPtr
, const POINT
*lpPt
, UINT
*pFlags
, INT
*pItem
)
701 GetClientRect (infoPtr
->hwndSelf
, &rect
);
705 if (PtInRect (&rect
, *lpPt
))
707 if (infoPtr
->uNumItem
== 0) {
708 *pFlags
|= HHT_NOWHERE
;
714 /* somewhere inside */
715 for (iCount
= 0; iCount
< infoPtr
->uNumItem
; iCount
++) {
716 rect
= infoPtr
->items
[iCount
].rect
;
717 width
= rect
.right
- rect
.left
;
722 if (PtInRect (&rect
, *lpPt
)) {
723 if (width
<= 2 * DIVIDER_WIDTH
) {
724 *pFlags
|= HHT_ONHEADER
;
726 TRACE("ON HEADER %d\n", iCount
);
729 if (HEADER_IndexToOrder(infoPtr
, iCount
) > 0) {
731 rcTest
.right
= rcTest
.left
+ DIVIDER_WIDTH
;
732 if (PtInRect (&rcTest
, *lpPt
)) {
733 if (HEADER_IsItemFixed(infoPtr
, HEADER_PrevItem(infoPtr
, iCount
)))
735 *pFlags
|= HHT_ONHEADER
;
737 TRACE("ON HEADER %d\n", *pItem
);
741 *pFlags
|= HHT_ONDIVOPEN
;
742 *pItem
= HEADER_PrevItem(infoPtr
, iCount
);
743 TRACE("ON DIVOPEN %d\n", *pItem
);
747 *pFlags
|= HHT_ONDIVIDER
;
748 *pItem
= HEADER_PrevItem(infoPtr
, iCount
);
749 TRACE("ON DIVIDER %d\n", *pItem
);
755 rcTest
.left
= rcTest
.right
- DIVIDER_WIDTH
;
756 if (!HEADER_IsItemFixed(infoPtr
, iCount
) && PtInRect (&rcTest
, *lpPt
))
758 *pFlags
|= HHT_ONDIVIDER
;
760 TRACE("ON DIVIDER %d\n", *pItem
);
764 *pFlags
|= HHT_ONHEADER
;
766 TRACE("ON HEADER %d\n", iCount
);
771 /* check for last divider part (on nowhere) */
772 if (!HEADER_IsItemFixed(infoPtr
, infoPtr
->uNumItem
- 1))
774 rect
= infoPtr
->items
[infoPtr
->uNumItem
-1].rect
;
775 rect
.left
= rect
.right
;
776 rect
.right
+= DIVIDER_WIDTH
;
777 if (PtInRect (&rect
, *lpPt
)) {
779 *pFlags
|= HHT_ONDIVOPEN
;
780 *pItem
= infoPtr
->uNumItem
- 1;
781 TRACE("ON DIVOPEN %d\n", *pItem
);
785 *pFlags
|= HHT_ONDIVIDER
;
786 *pItem
= infoPtr
->uNumItem
- 1;
787 TRACE("ON DIVIDER %d\n", *pItem
);
793 *pFlags
|= HHT_NOWHERE
;
800 if (lpPt
->x
< rect
.left
) {
802 *pFlags
|= HHT_TOLEFT
;
804 else if (lpPt
->x
> rect
.right
) {
806 *pFlags
|= HHT_TORIGHT
;
809 if (lpPt
->y
< rect
.top
) {
811 *pFlags
|= HHT_ABOVE
;
813 else if (lpPt
->y
> rect
.bottom
) {
815 *pFlags
|= HHT_BELOW
;
820 TRACE("flags=0x%X\n", *pFlags
);
826 HEADER_DrawTrackLine (const HEADER_INFO
*infoPtr
, HDC hdc
, INT x
)
830 GetClientRect (infoPtr
->hwndSelf
, &rect
);
831 PatBlt( hdc
, x
, rect
.top
, 1, rect
.bottom
- rect
.top
, DSTINVERT
);
836 * Convert a HDITEM into the correct format (ANSI/Unicode) to send it in a notify
839 * [I] infoPtr : the header that wants to send the notify
840 * [O] dest : The buffer to store the HDITEM for notify. It may be set to a HDITEMA of HDITEMW
841 * [I] src : The source HDITEM. It may be a HDITEMA or HDITEMW
842 * [I] fSourceUnicode : is src a HDITEMW or HDITEMA
843 * [O] ppvScratch : a pointer to a scratch buffer that needs to be freed after
844 * the HDITEM is no longer in use or NULL if none was needed
846 * NOTE: We depend on HDITEMA and HDITEMW having the same structure
848 static void HEADER_CopyHDItemForNotify(const HEADER_INFO
*infoPtr
, HDITEMW
*dest
,
849 const HDITEMW
*src
, BOOL fSourceUnicode
, LPVOID
*ppvScratch
)
854 if (src
->mask
& HDI_TEXT
&& src
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers TEXTCALLBACKA as well */
856 if (fSourceUnicode
&& infoPtr
->nNotifyFormat
!= NFR_UNICODE
)
858 dest
->pszText
= NULL
;
859 Str_SetPtrWtoA((LPSTR
*)&dest
->pszText
, src
->pszText
);
860 *ppvScratch
= dest
->pszText
;
863 if (!fSourceUnicode
&& infoPtr
->nNotifyFormat
== NFR_UNICODE
)
865 dest
->pszText
= NULL
;
866 Str_SetPtrAtoW(&dest
->pszText
, (LPSTR
)src
->pszText
);
867 *ppvScratch
= dest
->pszText
;
872 static UINT
HEADER_NotifyCodeWtoA(UINT code
)
874 /* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
875 if (code
>= HDN_LAST
&& code
<= HDN_FIRST_UNICODE
)
876 return code
+ HDN_UNICODE_OFFSET
;
882 HEADER_SendNotify(const HEADER_INFO
*infoPtr
, UINT code
, NMHDR
*nmhdr
)
884 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
885 nmhdr
->idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
888 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
889 nmhdr
->idFrom
, (LPARAM
)nmhdr
);
893 HEADER_SendSimpleNotify (const HEADER_INFO
*infoPtr
, UINT code
)
896 return (BOOL
)HEADER_SendNotify(infoPtr
, code
, &nmhdr
);
900 HEADER_SendCtrlCustomDraw(const HEADER_INFO
*infoPtr
, DWORD dwDrawStage
, HDC hdc
, const RECT
*rect
)
903 nm
.dwDrawStage
= dwDrawStage
;
910 return HEADER_SendNotify(infoPtr
, NM_CUSTOMDRAW
, (NMHDR
*)&nm
);
914 HEADER_SendNotifyWithHDItemT(const HEADER_INFO
*infoPtr
, UINT code
, INT iItem
, HDITEMW
*lpItem
)
918 if (infoPtr
->nNotifyFormat
!= NFR_UNICODE
)
919 code
= HEADER_NotifyCodeWtoA(code
);
922 nmhdr
.pitem
= lpItem
;
924 return (BOOL
)HEADER_SendNotify(infoPtr
, code
, (NMHDR
*)&nmhdr
);
928 HEADER_SendNotifyWithIntFieldT(const HEADER_INFO
*infoPtr
, UINT code
, INT iItem
, INT mask
, INT iValue
)
932 /* copying only the iValue should be ok but to make the code more robust we copy everything */
933 nmitem
.cxy
= infoPtr
->items
[iItem
].cxy
;
934 nmitem
.hbm
= infoPtr
->items
[iItem
].hbm
;
935 nmitem
.pszText
= NULL
;
936 nmitem
.cchTextMax
= 0;
937 nmitem
.fmt
= infoPtr
->items
[iItem
].fmt
;
938 nmitem
.lParam
= infoPtr
->items
[iItem
].lParam
;
939 nmitem
.iOrder
= infoPtr
->items
[iItem
].iOrder
;
940 nmitem
.iImage
= infoPtr
->items
[iItem
].iImage
;
949 nmitem
.iOrder
= iValue
;
952 ERR("invalid mask value 0x%x\n", iValue
);
955 return HEADER_SendNotifyWithHDItemT(infoPtr
, code
, iItem
, &nmitem
);
959 * Prepare callback items
960 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
961 * (so we handle the two cases only doing a specific cast for pszText).
962 * Checks if any of the required fields is a callback. If this is the case sends a
963 * NMHDISPINFO notify to retrieve these items. The items are stored in the
964 * HEADER_ITEM pszText and iImage fields. They should be freed with
965 * HEADER_FreeCallbackItems.
967 * @param hwnd : hwnd header container handler
968 * @param iItem : the header item id
969 * @param reqMask : required fields. If any of them is callback this function will fetch it
971 * @return TRUE on success, else FALSE
974 HEADER_PrepareCallbackItems(const HEADER_INFO
*infoPtr
, INT iItem
, INT reqMask
)
976 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
977 DWORD mask
= reqMask
& lpItem
->callbackMask
;
978 NMHDDISPINFOW dispInfo
;
979 void *pvBuffer
= NULL
;
983 if (mask
&HDI_TEXT
&& lpItem
->pszText
!= NULL
)
985 ERR("(): function called without a call to FreeCallbackItems\n");
986 heap_free(lpItem
->pszText
);
987 lpItem
->pszText
= NULL
;
990 memset(&dispInfo
, 0, sizeof(NMHDDISPINFOW
));
991 dispInfo
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
992 dispInfo
.hdr
.idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
993 if (infoPtr
->nNotifyFormat
== NFR_UNICODE
)
995 dispInfo
.hdr
.code
= HDN_GETDISPINFOW
;
997 pvBuffer
= heap_alloc_zero(MAX_HEADER_TEXT_LEN
* sizeof(WCHAR
));
1001 dispInfo
.hdr
.code
= HDN_GETDISPINFOA
;
1002 if (mask
& HDI_TEXT
)
1003 pvBuffer
= heap_alloc_zero(MAX_HEADER_TEXT_LEN
* sizeof(CHAR
));
1005 dispInfo
.pszText
= pvBuffer
;
1006 dispInfo
.cchTextMax
= (pvBuffer
!=NULL
?MAX_HEADER_TEXT_LEN
:0);
1007 dispInfo
.iItem
= iItem
;
1008 dispInfo
.mask
= mask
;
1009 dispInfo
.lParam
= lpItem
->lParam
;
1011 TRACE("Sending HDN_GETDISPINFO%c\n", infoPtr
->nNotifyFormat
== NFR_UNICODE
?'W':'A');
1012 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, dispInfo
.hdr
.idFrom
, (LPARAM
)&dispInfo
);
1014 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
1016 (infoPtr
->nNotifyFormat
== NFR_UNICODE
? debugstr_w(dispInfo
.pszText
) : (LPSTR
) dispInfo
.pszText
),
1017 (void*) dispInfo
.lParam
);
1019 if (mask
& HDI_IMAGE
)
1020 lpItem
->iImage
= dispInfo
.iImage
;
1021 if (mask
& HDI_TEXT
)
1023 if (infoPtr
->nNotifyFormat
== NFR_UNICODE
)
1025 lpItem
->pszText
= pvBuffer
;
1027 /* the user might have used his own buffer */
1028 if (dispInfo
.pszText
!= lpItem
->pszText
)
1029 Str_GetPtrW(dispInfo
.pszText
, lpItem
->pszText
, MAX_HEADER_TEXT_LEN
);
1033 Str_SetPtrAtoW(&lpItem
->pszText
, (LPSTR
)dispInfo
.pszText
);
1034 heap_free(pvBuffer
);
1038 if (dispInfo
.mask
& HDI_DI_SETITEM
)
1040 /* make the items permanent */
1041 lpItem
->callbackMask
&= ~dispInfo
.mask
;
1049 * Free the items that might be allocated with HEADER_PrepareCallbackItems
1052 * [I] lpItem : the item to free the data
1056 HEADER_FreeCallbackItems(HEADER_ITEM
*lpItem
)
1058 if (lpItem
->callbackMask
&HDI_TEXT
)
1060 heap_free(lpItem
->pszText
);
1061 lpItem
->pszText
= NULL
;
1064 if (lpItem
->callbackMask
&HDI_IMAGE
)
1065 lpItem
->iImage
= I_IMAGECALLBACK
;
1069 HEADER_CreateDragImage (HEADER_INFO
*infoPtr
, INT iItem
)
1071 HEADER_ITEM
*lpItem
;
1073 HBITMAP hMemory
, hOldBitmap
;
1081 if (iItem
>= infoPtr
->uNumItem
)
1084 if (!infoPtr
->bRectsValid
)
1085 HEADER_SetItemBounds(infoPtr
);
1087 lpItem
= &infoPtr
->items
[iItem
];
1088 width
= lpItem
->rect
.right
- lpItem
->rect
.left
;
1089 height
= lpItem
->rect
.bottom
- lpItem
->rect
.top
;
1091 hDeviceDC
= GetDC(NULL
);
1092 hMemoryDC
= CreateCompatibleDC(hDeviceDC
);
1093 hMemory
= CreateCompatibleBitmap(hDeviceDC
, width
, height
);
1094 ReleaseDC(NULL
, hDeviceDC
);
1095 hOldBitmap
= SelectObject(hMemoryDC
, hMemory
);
1096 SetViewportOrgEx(hMemoryDC
, -lpItem
->rect
.left
, -lpItem
->rect
.top
, NULL
);
1097 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject(SYSTEM_FONT
);
1098 SelectObject(hMemoryDC
, hFont
);
1100 GetClientRect(infoPtr
->hwndSelf
, &rc
);
1101 lCDFlags
= HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_PREPAINT
, hMemoryDC
, &rc
);
1102 HEADER_DrawItem(infoPtr
, hMemoryDC
, iItem
, FALSE
, lCDFlags
);
1103 if (lCDFlags
& CDRF_NOTIFYPOSTPAINT
)
1104 HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_POSTPAINT
, hMemoryDC
, &rc
);
1106 hMemory
= SelectObject(hMemoryDC
, hOldBitmap
);
1107 DeleteDC(hMemoryDC
);
1109 if (hMemory
== NULL
) /* if anything failed */
1112 himl
= ImageList_Create(width
, height
, ILC_COLORDDB
, 1, 1);
1113 ImageList_Add(himl
, hMemory
, NULL
);
1114 DeleteObject(hMemory
);
1119 HEADER_SetHotDivider(HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1128 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1130 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &iDivider
);
1132 if (flags
& HHT_TOLEFT
)
1134 else if (flags
& HHT_NOWHERE
|| flags
& HHT_TORIGHT
)
1135 iDivider
= infoPtr
->uNumItem
;
1138 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iDivider
];
1139 if (pt
.x
> (lpItem
->rect
.left
+lpItem
->rect
.right
)/2)
1140 iDivider
= HEADER_NextItem(infoPtr
, iDivider
);
1144 iDivider
= (INT
)lParam
;
1146 /* Note; wParam==FALSE, lParam==-1 is valid and is used to clear the hot divider */
1147 if (iDivider
<-1 || iDivider
>(int)infoPtr
->uNumItem
)
1150 if (iDivider
!= infoPtr
->iHotDivider
)
1152 if (infoPtr
->iHotDivider
!= -1)
1154 HEADER_GetHotDividerRect(infoPtr
, &r
);
1155 InvalidateRect(infoPtr
->hwndSelf
, &r
, FALSE
);
1157 infoPtr
->iHotDivider
= iDivider
;
1160 HEADER_GetHotDividerRect(infoPtr
, &r
);
1161 InvalidateRect(infoPtr
->hwndSelf
, &r
, FALSE
);
1168 HEADER_DeleteItem (HEADER_INFO
*infoPtr
, INT iItem
)
1173 TRACE("[iItem=%d]\n", iItem
);
1175 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
1178 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1179 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
1181 iOrder
= infoPtr
->items
[iItem
].iOrder
;
1182 heap_free(infoPtr
->items
[iItem
].pszText
);
1184 infoPtr
->uNumItem
--;
1185 memmove(&infoPtr
->items
[iItem
], &infoPtr
->items
[iItem
+ 1],
1186 (infoPtr
->uNumItem
- iItem
) * sizeof(HEADER_ITEM
));
1187 memmove(&infoPtr
->order
[iOrder
], &infoPtr
->order
[iOrder
+ 1],
1188 (infoPtr
->uNumItem
- iOrder
) * sizeof(INT
));
1189 infoPtr
->items
= heap_realloc(infoPtr
->items
, sizeof(HEADER_ITEM
) * infoPtr
->uNumItem
);
1190 infoPtr
->order
= heap_realloc(infoPtr
->order
, sizeof(INT
) * infoPtr
->uNumItem
);
1192 /* Correct the orders */
1193 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1195 if (infoPtr
->order
[i
] > iItem
)
1196 infoPtr
->order
[i
]--;
1198 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
1200 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1201 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
1203 HEADER_SetItemBounds (infoPtr
);
1204 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1211 HEADER_GetImageList (const HEADER_INFO
*infoPtr
)
1213 return (LRESULT
)infoPtr
->himl
;
1218 HEADER_GetItemT (const HEADER_INFO
*infoPtr
, INT nItem
, LPHDITEMW phdi
, BOOL bUnicode
)
1220 HEADER_ITEM
*lpItem
;
1226 TRACE("[nItem=%d]\n", nItem
);
1232 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
1235 if (mask
& HDI_UNKNOWN_FIELDS
)
1237 TRACE("mask %x contains unknown fields. Using only comctl32 4.0 fields\n", mask
);
1238 mask
&= HDI_COMCTL32_4_0_FIELDS
;
1241 lpItem
= &infoPtr
->items
[nItem
];
1242 HEADER_PrepareCallbackItems(infoPtr
, nItem
, mask
);
1244 if (mask
& HDI_BITMAP
)
1245 phdi
->hbm
= lpItem
->hbm
;
1247 if (mask
& HDI_FORMAT
)
1248 phdi
->fmt
= lpItem
->fmt
;
1250 if (mask
& HDI_WIDTH
)
1251 phdi
->cxy
= lpItem
->cxy
;
1253 if (mask
& HDI_LPARAM
)
1254 phdi
->lParam
= lpItem
->lParam
;
1256 if (mask
& HDI_IMAGE
)
1257 phdi
->iImage
= lpItem
->iImage
;
1259 if (mask
& HDI_ORDER
)
1260 phdi
->iOrder
= lpItem
->iOrder
;
1262 if (mask
& HDI_TEXT
)
1265 Str_GetPtrW (lpItem
->pszText
, phdi
->pszText
, phdi
->cchTextMax
);
1267 Str_GetPtrWtoA (lpItem
->pszText
, (LPSTR
)phdi
->pszText
, phdi
->cchTextMax
);
1270 HEADER_FreeCallbackItems(lpItem
);
1275 static inline LRESULT
1276 HEADER_GetItemCount (const HEADER_INFO
*infoPtr
)
1278 return infoPtr
->uNumItem
;
1283 HEADER_GetItemRect (const HEADER_INFO
*infoPtr
, INT iItem
, LPRECT lpRect
)
1285 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
1288 lpRect
->left
= infoPtr
->items
[iItem
].rect
.left
;
1289 lpRect
->right
= infoPtr
->items
[iItem
].rect
.right
;
1290 lpRect
->top
= infoPtr
->items
[iItem
].rect
.top
;
1291 lpRect
->bottom
= infoPtr
->items
[iItem
].rect
.bottom
;
1298 HEADER_GetOrderArray(const HEADER_INFO
*infoPtr
, INT size
, LPINT order
)
1300 if ((UINT
)size
<infoPtr
->uNumItem
)
1303 memcpy(order
, infoPtr
->order
, infoPtr
->uNumItem
* sizeof(INT
));
1307 /* Returns index of first duplicate 'value' from [0,to) range,
1308 or -1 if there isn't any */
1309 static INT
has_duplicate(const INT
*array
, INT to
, INT value
)
1312 for(i
= 0; i
< to
; i
++)
1313 if (array
[i
] == value
) return i
;
1317 /* returns next available value from [0,max] not to duplicate in [0,to) */
1318 static INT
get_nextvalue(const INT
*array
, INT to
, INT max
)
1321 for(i
= 0; i
< max
; i
++)
1322 if (has_duplicate(array
, to
, i
) == -1) return i
;
1327 HEADER_SetOrderArray(HEADER_INFO
*infoPtr
, INT size
, const INT
*order
)
1329 HEADER_ITEM
*lpItem
;
1332 if ((UINT
)size
!= infoPtr
->uNumItem
)
1335 if (TRACE_ON(header
))
1337 TRACE("count=%d, order array={", size
);
1338 for (i
= 0; i
< size
; i
++)
1339 TRACE("%d%c", order
[i
], i
!= size
-1 ? ',' : '}');
1343 for (i
=0; i
<size
; i
++)
1345 if (order
[i
] >= size
|| order
[i
] < 0)
1346 /* on invalid index get next available */
1347 /* FIXME: if i==0 array item is out of range behaviour is
1348 different, see tests */
1349 infoPtr
->order
[i
] = get_nextvalue(infoPtr
->order
, i
, size
);
1354 infoPtr
->order
[i
] = order
[i
];
1356 /* remove duplicates */
1357 while ((dup
= has_duplicate(infoPtr
->order
, j
, order
[j
])) != -1)
1361 next
= get_nextvalue(infoPtr
->order
, j
, size
);
1362 infoPtr
->order
[dup
] = next
;
1367 /* sync with item data */
1368 for (i
=0; i
<size
; i
++)
1370 lpItem
= &infoPtr
->items
[infoPtr
->order
[i
]];
1373 HEADER_SetItemBounds(infoPtr
);
1374 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1378 static inline LRESULT
1379 HEADER_GetUnicodeFormat (const HEADER_INFO
*infoPtr
)
1381 return (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1386 HEADER_HitTest (const HEADER_INFO
*infoPtr
, LPHDHITTESTINFO phti
)
1388 UINT outside
= HHT_NOWHERE
| HHT_ABOVE
| HHT_BELOW
| HHT_TOLEFT
| HHT_TORIGHT
;
1390 HEADER_InternalHitTest (infoPtr
, &phti
->pt
, &phti
->flags
, &phti
->iItem
);
1392 if (phti
->flags
& outside
)
1393 return phti
->iItem
= -1;
1400 HEADER_InsertItemT (HEADER_INFO
*infoPtr
, INT nItem
, const HDITEMW
*phdi
, BOOL bUnicode
)
1402 HEADER_ITEM
*lpItem
;
1407 if ((phdi
== NULL
) || (nItem
< 0) || (phdi
->mask
== 0))
1410 if (nItem
> infoPtr
->uNumItem
)
1411 nItem
= infoPtr
->uNumItem
;
1413 iOrder
= (phdi
->mask
& HDI_ORDER
) ? phdi
->iOrder
: nItem
;
1416 else if (infoPtr
->uNumItem
< iOrder
)
1417 iOrder
= infoPtr
->uNumItem
;
1419 infoPtr
->uNumItem
++;
1420 infoPtr
->items
= heap_realloc(infoPtr
->items
, sizeof(HEADER_ITEM
) * infoPtr
->uNumItem
);
1421 infoPtr
->order
= heap_realloc(infoPtr
->order
, sizeof(INT
) * infoPtr
->uNumItem
);
1423 /* make space for the new item */
1424 memmove(&infoPtr
->items
[nItem
+ 1], &infoPtr
->items
[nItem
],
1425 (infoPtr
->uNumItem
- nItem
- 1) * sizeof(HEADER_ITEM
));
1426 memmove(&infoPtr
->order
[iOrder
+ 1], &infoPtr
->order
[iOrder
],
1427 (infoPtr
->uNumItem
- iOrder
- 1) * sizeof(INT
));
1429 /* update the order array */
1430 infoPtr
->order
[iOrder
] = nItem
;
1431 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1433 if (i
!= iOrder
&& infoPtr
->order
[i
] >= nItem
)
1434 infoPtr
->order
[i
]++;
1435 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
1438 lpItem
= &infoPtr
->items
[nItem
];
1439 ZeroMemory(lpItem
, sizeof(HEADER_ITEM
));
1440 /* cxy, fmt and lParam are copied even if not in the HDITEM mask */
1441 copyMask
= phdi
->mask
| HDI_WIDTH
| HDI_FORMAT
| HDI_LPARAM
;
1442 HEADER_StoreHDItemInHeader(lpItem
, copyMask
, phdi
, bUnicode
);
1443 lpItem
->iOrder
= iOrder
;
1445 /* set automatically some format bits */
1446 if (phdi
->mask
& HDI_TEXT
)
1447 lpItem
->fmt
|= HDF_STRING
;
1449 lpItem
->fmt
&= ~HDF_STRING
;
1451 if (lpItem
->hbm
!= NULL
)
1452 lpItem
->fmt
|= HDF_BITMAP
;
1454 lpItem
->fmt
&= ~HDF_BITMAP
;
1456 if (phdi
->mask
& HDI_IMAGE
)
1457 lpItem
->fmt
|= HDF_IMAGE
;
1459 HEADER_SetItemBounds (infoPtr
);
1460 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1467 HEADER_Layout (HEADER_INFO
*infoPtr
, LPHDLAYOUT lpLayout
)
1469 lpLayout
->pwpos
->hwnd
= infoPtr
->hwndSelf
;
1470 lpLayout
->pwpos
->hwndInsertAfter
= 0;
1471 lpLayout
->pwpos
->x
= lpLayout
->prc
->left
;
1472 lpLayout
->pwpos
->y
= lpLayout
->prc
->top
;
1473 lpLayout
->pwpos
->cx
= lpLayout
->prc
->right
- lpLayout
->prc
->left
;
1474 if (infoPtr
->dwStyle
& HDS_HIDDEN
)
1475 lpLayout
->pwpos
->cy
= 0;
1477 lpLayout
->pwpos
->cy
= infoPtr
->nHeight
;
1478 lpLayout
->prc
->top
+= infoPtr
->nHeight
;
1480 lpLayout
->pwpos
->flags
= SWP_NOZORDER
;
1482 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1483 lpLayout
->pwpos
->x
, lpLayout
->pwpos
->y
,
1484 lpLayout
->pwpos
->cx
, lpLayout
->pwpos
->cy
);
1486 infoPtr
->bRectsValid
= FALSE
;
1493 HEADER_SetImageList (HEADER_INFO
*infoPtr
, HIMAGELIST himl
)
1497 TRACE("(himl %p)\n", himl
);
1498 himlOld
= infoPtr
->himl
;
1499 infoPtr
->himl
= himl
;
1501 /* FIXME: Refresh needed??? */
1503 return (LRESULT
)himlOld
;
1508 HEADER_GetBitmapMargin(const HEADER_INFO
*infoPtr
)
1510 return infoPtr
->iMargin
;
1514 HEADER_SetBitmapMargin(HEADER_INFO
*infoPtr
, INT iMargin
)
1516 INT oldMargin
= infoPtr
->iMargin
;
1518 infoPtr
->iMargin
= iMargin
;
1524 HEADER_SetItemT (HEADER_INFO
*infoPtr
, INT nItem
, const HDITEMW
*phdi
, BOOL bUnicode
)
1526 HEADER_ITEM
*lpItem
;
1532 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
1535 TRACE("[nItem=%d]\n", nItem
);
1537 HEADER_CopyHDItemForNotify(infoPtr
, &hdNotify
, phdi
, bUnicode
, &pvScratch
);
1538 if (HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCHANGINGW
, nItem
, &hdNotify
))
1540 heap_free(pvScratch
);
1544 lpItem
= &infoPtr
->items
[nItem
];
1545 HEADER_StoreHDItemInHeader(lpItem
, phdi
->mask
, phdi
, bUnicode
);
1547 if (phdi
->mask
& HDI_ORDER
)
1548 if (phdi
->iOrder
>= 0 && phdi
->iOrder
< infoPtr
->uNumItem
)
1549 HEADER_ChangeItemOrder(infoPtr
, nItem
, phdi
->iOrder
);
1551 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCHANGEDW
, nItem
, &hdNotify
);
1553 HEADER_SetItemBounds (infoPtr
);
1555 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1557 heap_free(pvScratch
);
1561 static inline LRESULT
1562 HEADER_SetUnicodeFormat (HEADER_INFO
*infoPtr
, WPARAM wParam
)
1564 BOOL bTemp
= (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1566 infoPtr
->nNotifyFormat
= ((BOOL
)wParam
? NFR_UNICODE
: NFR_ANSI
);
1573 HEADER_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1575 HEADER_INFO
*infoPtr
;
1580 infoPtr
= heap_alloc_zero (sizeof(*infoPtr
));
1581 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1583 infoPtr
->hwndSelf
= hwnd
;
1584 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1585 infoPtr
->uNumItem
= 0;
1589 infoPtr
->bRectsValid
= FALSE
;
1590 infoPtr
->hcurArrow
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1591 infoPtr
->hcurDivider
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDER
));
1592 infoPtr
->hcurDivopen
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDEROPEN
));
1593 infoPtr
->bPressed
= FALSE
;
1594 infoPtr
->bTracking
= FALSE
;
1595 infoPtr
->dwStyle
= lpcs
->style
;
1596 infoPtr
->iMoveItem
= 0;
1598 infoPtr
->iHotItem
= -1;
1599 infoPtr
->iHotDivider
= -1;
1600 infoPtr
->iMargin
= 3*GetSystemMetrics(SM_CXEDGE
);
1601 infoPtr
->nNotifyFormat
=
1602 SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_QUERY
);
1603 infoPtr
->filter_change_timeout
= 1000;
1606 hOldFont
= SelectObject (hdc
, GetStockObject (SYSTEM_FONT
));
1607 GetTextMetricsW (hdc
, &tm
);
1608 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
1609 SelectObject (hdc
, hOldFont
);
1612 OpenThemeData(hwnd
, themeClass
);
1619 HEADER_Destroy (HEADER_INFO
*infoPtr
)
1621 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
1622 CloseThemeData(theme
);
1627 HEADER_NCDestroy (HEADER_INFO
*infoPtr
)
1629 HEADER_ITEM
*lpItem
;
1632 if (infoPtr
->items
) {
1633 lpItem
= infoPtr
->items
;
1634 for (nItem
= 0; nItem
< infoPtr
->uNumItem
; nItem
++, lpItem
++)
1635 heap_free(lpItem
->pszText
);
1636 heap_free(infoPtr
->items
);
1639 heap_free(infoPtr
->order
);
1641 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
1648 static inline LRESULT
1649 HEADER_GetFont (const HEADER_INFO
*infoPtr
)
1651 return (LRESULT
)infoPtr
->hFont
;
1656 HEADER_IsDragDistance(const HEADER_INFO
*infoPtr
, const POINT
*pt
)
1658 /* Windows allows for a mouse movement before starting the drag. We use the
1659 * SM_CXDOUBLECLICK/SM_CYDOUBLECLICK as that distance.
1661 return (abs(infoPtr
->ptLButtonDown
.x
- pt
->x
)>GetSystemMetrics(SM_CXDOUBLECLK
) ||
1662 abs(infoPtr
->ptLButtonDown
.y
- pt
->y
)>GetSystemMetrics(SM_CYDOUBLECLK
));
1666 HEADER_LButtonDblClk (const HEADER_INFO
*infoPtr
, INT x
, INT y
)
1674 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1676 if ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (flags
== HHT_ONHEADER
))
1677 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMDBLCLICKW
, nItem
, NULL
);
1678 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
))
1679 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_DIVIDERDBLCLICKW
, nItem
, NULL
);
1686 HEADER_LButtonDown (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1695 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1697 if ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (flags
== HHT_ONHEADER
)) {
1698 SetCapture (infoPtr
->hwndSelf
);
1699 infoPtr
->bCaptured
= TRUE
;
1700 infoPtr
->bPressed
= TRUE
;
1701 infoPtr
->bDragging
= FALSE
;
1702 infoPtr
->iMoveItem
= nItem
;
1703 infoPtr
->ptLButtonDown
= pt
;
1705 infoPtr
->items
[nItem
].bDown
= TRUE
;
1707 /* Send WM_CUSTOMDRAW */
1708 hdc
= GetDC (infoPtr
->hwndSelf
);
1709 HEADER_RefreshItem (infoPtr
, nItem
);
1710 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1712 TRACE("Pressed item %d.\n", nItem
);
1714 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
)) {
1715 INT iCurrWidth
= infoPtr
->items
[nItem
].cxy
;
1716 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_BEGINTRACKW
, nItem
, HDI_WIDTH
, iCurrWidth
))
1718 SetCapture (infoPtr
->hwndSelf
);
1719 infoPtr
->bCaptured
= TRUE
;
1720 infoPtr
->bTracking
= TRUE
;
1721 infoPtr
->iMoveItem
= nItem
;
1722 infoPtr
->xTrackOffset
= infoPtr
->items
[nItem
].rect
.right
- pt
.x
;
1724 if (!(infoPtr
->dwStyle
& HDS_FULLDRAG
)) {
1725 infoPtr
->xOldTrack
= infoPtr
->items
[nItem
].rect
.right
;
1726 hdc
= GetDC (infoPtr
->hwndSelf
);
1727 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1728 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1731 TRACE("Begin tracking item %d.\n", nItem
);
1740 HEADER_LButtonUp (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1749 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1751 if (infoPtr
->bPressed
) {
1753 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1755 if (infoPtr
->bDragging
)
1757 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1760 ImageList_DragShowNolock(FALSE
);
1761 ImageList_EndDrag();
1763 if (infoPtr
->iHotDivider
== -1)
1765 else if (infoPtr
->iHotDivider
== infoPtr
->uNumItem
)
1766 iNewOrder
= infoPtr
->uNumItem
-1;
1769 iNewOrder
= HEADER_IndexToOrder(infoPtr
, infoPtr
->iHotDivider
);
1770 if (iNewOrder
> lpItem
->iOrder
)
1774 if (iNewOrder
!= -1 &&
1775 !HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ENDDRAG
, infoPtr
->iMoveItem
, HDI_ORDER
, iNewOrder
))
1777 HEADER_ChangeItemOrder(infoPtr
, infoPtr
->iMoveItem
, iNewOrder
);
1778 infoPtr
->bRectsValid
= FALSE
;
1779 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1782 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->items
[infoPtr
->iMoveItem
].rect
, FALSE
);
1784 infoPtr
->bDragging
= FALSE
;
1785 HEADER_SetHotDivider(infoPtr
, FALSE
, -1);
1789 hdc
= GetDC (infoPtr
->hwndSelf
);
1790 HEADER_RefreshItem (infoPtr
, infoPtr
->iMoveItem
);
1791 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1793 if (!(infoPtr
->dwStyle
& HDS_DRAGDROP
) || !HEADER_IsDragDistance(infoPtr
, &pt
))
1794 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCLICKW
, infoPtr
->iMoveItem
, NULL
);
1797 TRACE("Released item %d.\n", infoPtr
->iMoveItem
);
1798 infoPtr
->bPressed
= FALSE
;
1800 else if (infoPtr
->bTracking
) {
1801 INT iNewWidth
= pt
.x
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
+ infoPtr
->xTrackOffset
;
1804 TRACE("End tracking item %d.\n", infoPtr
->iMoveItem
);
1805 infoPtr
->bTracking
= FALSE
;
1807 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ENDTRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
);
1809 if (!(infoPtr
->dwStyle
& HDS_FULLDRAG
)) {
1810 hdc
= GetDC (infoPtr
->hwndSelf
);
1811 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1812 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1815 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
))
1817 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= iNewWidth
;
1818 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
);
1821 HEADER_SetItemBounds (infoPtr
);
1822 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1825 if (infoPtr
->bCaptured
) {
1826 infoPtr
->bCaptured
= FALSE
;
1828 HEADER_SendSimpleNotify (infoPtr
, NM_RELEASEDCAPTURE
);
1836 HEADER_NotifyFormat (HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1841 return infoPtr
->nNotifyFormat
;
1844 infoPtr
->nNotifyFormat
=
1845 SendMessageW ((HWND
)wParam
, WM_NOTIFYFORMAT
,
1846 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1847 return infoPtr
->nNotifyFormat
;
1854 HEADER_MouseLeave (HEADER_INFO
*infoPtr
)
1856 /* Reset hot-tracked item when mouse leaves control. */
1857 INT oldHotItem
= infoPtr
->iHotItem
;
1858 HDC hdc
= GetDC (infoPtr
->hwndSelf
);
1860 infoPtr
->iHotItem
= -1;
1861 if (oldHotItem
!= -1) HEADER_RefreshItem (infoPtr
, oldHotItem
);
1862 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1869 HEADER_MouseMove (HEADER_INFO
*infoPtr
, LPARAM lParam
)
1875 /* With theming, hottracking is always enabled */
1876 BOOL hotTrackEnabled
=
1877 ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (infoPtr
->dwStyle
& HDS_HOTTRACK
))
1878 || (GetWindowTheme (infoPtr
->hwndSelf
) != NULL
);
1879 INT oldHotItem
= infoPtr
->iHotItem
;
1881 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1882 pt
.y
= (INT
)(SHORT
)HIWORD(lParam
);
1883 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1885 if (hotTrackEnabled
) {
1886 if (flags
& (HHT_ONHEADER
| HHT_ONDIVIDER
| HHT_ONDIVOPEN
))
1887 infoPtr
->iHotItem
= nItem
;
1889 infoPtr
->iHotItem
= -1;
1892 if (infoPtr
->bCaptured
) {
1893 /* check if we should drag the header */
1894 if (infoPtr
->bPressed
&& !infoPtr
->bDragging
&& (infoPtr
->dwStyle
& HDS_DRAGDROP
)
1895 && HEADER_IsDragDistance(infoPtr
, &pt
))
1897 if (!HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_BEGINDRAG
, infoPtr
->iMoveItem
, NULL
))
1899 HIMAGELIST hDragItem
= HEADER_CreateDragImage(infoPtr
, infoPtr
->iMoveItem
);
1900 if (hDragItem
!= NULL
)
1902 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1903 TRACE("Starting item drag\n");
1904 ImageList_BeginDrag(hDragItem
, 0, pt
.x
- lpItem
->rect
.left
, 0);
1905 ImageList_DragShowNolock(TRUE
);
1906 ImageList_Destroy(hDragItem
);
1907 infoPtr
->bDragging
= TRUE
;
1912 if (infoPtr
->bDragging
)
1917 ClientToScreen(infoPtr
->hwndSelf
, &drag
);
1918 ImageList_DragMove(drag
.x
, drag
.y
);
1919 HEADER_SetHotDivider(infoPtr
, TRUE
, lParam
);
1922 if (infoPtr
->bPressed
&& !infoPtr
->bDragging
) {
1923 BOOL oldState
= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
;
1924 if ((nItem
== infoPtr
->iMoveItem
) && (flags
== HHT_ONHEADER
))
1925 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= TRUE
;
1927 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1928 if (oldState
!= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
) {
1929 hdc
= GetDC (infoPtr
->hwndSelf
);
1930 HEADER_RefreshItem (infoPtr
, infoPtr
->iMoveItem
);
1931 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1934 TRACE("Moving pressed item %d.\n", infoPtr
->iMoveItem
);
1936 else if (infoPtr
->bTracking
) {
1937 if (infoPtr
->dwStyle
& HDS_FULLDRAG
) {
1938 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1939 nWidth
= pt
.x
- lpItem
->rect
.left
+ infoPtr
->xTrackOffset
;
1940 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, nWidth
))
1942 INT nOldWidth
= lpItem
->rect
.right
- lpItem
->rect
.left
;
1946 if (nWidth
< 0) nWidth
= 0;
1947 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= nWidth
;
1948 HEADER_SetItemBounds(infoPtr
);
1950 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1951 rcScroll
= rcClient
;
1952 rcScroll
.left
= lpItem
->rect
.left
+ nOldWidth
;
1953 ScrollWindowEx(infoPtr
->hwndSelf
, nWidth
- nOldWidth
, 0, &rcScroll
, &rcClient
, NULL
, NULL
, 0);
1954 InvalidateRect(infoPtr
->hwndSelf
, &lpItem
->rect
, FALSE
);
1955 UpdateWindow(infoPtr
->hwndSelf
);
1957 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, nWidth
);
1962 hdc
= GetDC (infoPtr
->hwndSelf
);
1963 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1964 infoPtr
->xOldTrack
= pt
.x
+ infoPtr
->xTrackOffset
;
1965 if (infoPtr
->xOldTrack
< infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
)
1966 infoPtr
->xOldTrack
= infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1967 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1968 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1969 iTrackWidth
= infoPtr
->xOldTrack
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1970 /* FIXME: should stop tracking if HDN_TRACK returns TRUE */
1971 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_TRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iTrackWidth
);
1974 TRACE("Tracking item %d.\n", infoPtr
->iMoveItem
);
1978 if (hotTrackEnabled
) {
1979 TRACKMOUSEEVENT tme
;
1980 if (oldHotItem
!= infoPtr
->iHotItem
&& !infoPtr
->bDragging
) {
1981 hdc
= GetDC (infoPtr
->hwndSelf
);
1982 if (oldHotItem
!= -1) HEADER_RefreshItem (infoPtr
, oldHotItem
);
1983 if (infoPtr
->iHotItem
!= -1) HEADER_RefreshItem (infoPtr
, infoPtr
->iHotItem
);
1984 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1986 tme
.cbSize
= sizeof( tme
);
1987 tme
.dwFlags
= TME_LEAVE
;
1988 tme
.hwndTrack
= infoPtr
->hwndSelf
;
1989 TrackMouseEvent( &tme
);
1997 HEADER_Paint (HEADER_INFO
*infoPtr
, HDC hdcParam
)
2002 hdc
= hdcParam
==0 ? BeginPaint (infoPtr
->hwndSelf
, &ps
) : hdcParam
;
2003 HEADER_Refresh (infoPtr
, hdc
);
2005 EndPaint (infoPtr
->hwndSelf
, &ps
);
2011 HEADER_RButtonUp (HEADER_INFO
*infoPtr
, INT x
, INT y
)
2019 /* Send a Notify message */
2020 bRet
= HEADER_SendSimpleNotify (infoPtr
, NM_RCLICK
);
2022 /* Change to screen coordinate for WM_CONTEXTMENU */
2023 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
2025 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
2026 SendMessageW( infoPtr
->hwndSelf
, WM_CONTEXTMENU
, (WPARAM
) infoPtr
->hwndSelf
, MAKELPARAM(pt
.x
, pt
.y
));
2033 HEADER_SetCursor (HEADER_INFO
*infoPtr
, LPARAM lParam
)
2039 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam
), HIWORD(lParam
));
2042 ScreenToClient (infoPtr
->hwndSelf
, &pt
);
2044 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
2046 if (flags
== HHT_ONDIVIDER
)
2047 SetCursor (infoPtr
->hcurDivider
);
2048 else if (flags
== HHT_ONDIVOPEN
)
2049 SetCursor (infoPtr
->hcurDivopen
);
2051 SetCursor (infoPtr
->hcurArrow
);
2058 HEADER_SetFont (HEADER_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
2064 infoPtr
->hFont
= hFont
;
2067 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
));
2068 GetTextMetricsW (hdc
, &tm
);
2069 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
2070 SelectObject (hdc
, hOldFont
);
2073 infoPtr
->bRectsValid
= FALSE
;
2076 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
2082 static LRESULT
HEADER_SetRedraw(HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
2084 /* ignoring the InvalidateRect calls is handled by user32. But some apps expect
2085 * that we invalidate the header and this has to be done manually */
2088 ret
= DefWindowProcW(infoPtr
->hwndSelf
, WM_SETREDRAW
, wParam
, lParam
);
2090 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2094 static INT
HEADER_StyleChanged(HEADER_INFO
*infoPtr
, WPARAM wStyleType
,
2095 const STYLESTRUCT
*lpss
)
2097 TRACE("styletype %Ix, styleOld %#lx, styleNew %#lx\n", wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
2099 if (wStyleType
!= GWL_STYLE
) return 0;
2101 infoPtr
->dwStyle
= lpss
->styleNew
;
2106 /* Update the theme handle after a theme change */
2107 static LRESULT
HEADER_ThemeChanged(const HEADER_INFO
*infoPtr
)
2109 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
2110 CloseThemeData(theme
);
2111 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
2112 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2116 static INT
HEADER_SetFilterChangeTimeout(HEADER_INFO
*infoPtr
, INT timeout
)
2118 INT old_timeout
= infoPtr
->filter_change_timeout
;
2121 infoPtr
->filter_change_timeout
= timeout
;
2125 static LRESULT WINAPI
2126 HEADER_WindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2128 HEADER_INFO
*infoPtr
= (HEADER_INFO
*)GetWindowLongPtrW(hwnd
, 0);
2130 TRACE("hwnd %p, msg %x, wparam %Ix, lParam %Ix\n", hwnd
, msg
, wParam
, lParam
);
2132 if (!infoPtr
&& (msg
!= WM_CREATE
))
2133 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
2135 /* case HDM_CLEARFILTER: */
2137 case HDM_CREATEDRAGIMAGE
:
2138 return (LRESULT
)HEADER_CreateDragImage (infoPtr
, (INT
)wParam
);
2140 case HDM_DELETEITEM
:
2141 return HEADER_DeleteItem (infoPtr
, (INT
)wParam
);
2143 /* case HDM_EDITFILTER: */
2145 case HDM_GETBITMAPMARGIN
:
2146 return HEADER_GetBitmapMargin(infoPtr
);
2148 case HDM_GETIMAGELIST
:
2149 return HEADER_GetImageList (infoPtr
);
2153 return HEADER_GetItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_GETITEMW
);
2155 case HDM_GETITEMCOUNT
:
2156 return HEADER_GetItemCount (infoPtr
);
2158 case HDM_GETITEMRECT
:
2159 return HEADER_GetItemRect (infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
2161 case HDM_GETORDERARRAY
:
2162 return HEADER_GetOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
2164 case HDM_GETUNICODEFORMAT
:
2165 return HEADER_GetUnicodeFormat (infoPtr
);
2168 return HEADER_HitTest (infoPtr
, (LPHDHITTESTINFO
)lParam
);
2170 case HDM_INSERTITEMA
:
2171 case HDM_INSERTITEMW
:
2172 return HEADER_InsertItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_INSERTITEMW
);
2175 return HEADER_Layout (infoPtr
, (LPHDLAYOUT
)lParam
);
2177 case HDM_ORDERTOINDEX
:
2178 return HEADER_OrderToIndex(infoPtr
, (INT
)wParam
);
2180 case HDM_SETBITMAPMARGIN
:
2181 return HEADER_SetBitmapMargin(infoPtr
, (INT
)wParam
);
2183 case HDM_SETFILTERCHANGETIMEOUT
:
2184 return HEADER_SetFilterChangeTimeout(infoPtr
, (INT
)lParam
);
2186 case HDM_SETHOTDIVIDER
:
2187 return HEADER_SetHotDivider(infoPtr
, wParam
, lParam
);
2189 case HDM_SETIMAGELIST
:
2190 return HEADER_SetImageList (infoPtr
, (HIMAGELIST
)lParam
);
2194 return HEADER_SetItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_SETITEMW
);
2196 case HDM_SETORDERARRAY
:
2197 return HEADER_SetOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
2199 case HDM_SETUNICODEFORMAT
:
2200 return HEADER_SetUnicodeFormat (infoPtr
, wParam
);
2203 return HEADER_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
2206 return HEADER_Destroy (infoPtr
);
2209 return HEADER_NCDestroy (infoPtr
);
2215 return DLGC_WANTTAB
| DLGC_WANTARROWS
;
2218 return HEADER_GetFont (infoPtr
);
2220 case WM_LBUTTONDBLCLK
:
2221 return HEADER_LButtonDblClk (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2223 case WM_LBUTTONDOWN
:
2224 return HEADER_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2227 return HEADER_LButtonUp (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2230 return HEADER_MouseLeave (infoPtr
);
2233 return HEADER_MouseMove (infoPtr
, lParam
);
2235 case WM_NOTIFYFORMAT
:
2236 return HEADER_NotifyFormat (infoPtr
, wParam
, lParam
);
2239 return HEADER_Size (infoPtr
);
2241 case WM_THEMECHANGED
:
2242 return HEADER_ThemeChanged (infoPtr
);
2244 case WM_PRINTCLIENT
:
2246 return HEADER_Paint (infoPtr
, (HDC
)wParam
);
2249 return HEADER_RButtonUp (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2252 return HEADER_SetCursor (infoPtr
, lParam
);
2255 return HEADER_SetFont (infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
2258 return HEADER_SetRedraw(infoPtr
, wParam
, lParam
);
2260 case WM_STYLECHANGED
:
2261 return HEADER_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
2263 case WM_SYSCOLORCHANGE
:
2264 COMCTL32_RefreshSysColors();
2268 if ((msg
>= WM_USER
) && (msg
< WM_APP
) && !COMCTL32_IsReflectedMessage(msg
))
2269 ERR("unknown msg %04x, wp %#Ix, lp %#Ix\n", msg
, wParam
, lParam
);
2270 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
2276 HEADER_Register (void)
2280 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2281 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
2282 wndClass
.lpfnWndProc
= HEADER_WindowProc
;
2283 wndClass
.cbClsExtra
= 0;
2284 wndClass
.cbWndExtra
= sizeof(HEADER_INFO
*);
2285 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2286 wndClass
.lpszClassName
= WC_HEADERW
;
2288 RegisterClassW (&wndClass
);
2293 HEADER_Unregister (void)
2295 UnregisterClassW (WC_HEADERW
, NULL
);