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"
44 #include "wine/debug.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 */
88 HIMAGELIST himl
; /* handle to an image list (may be 0) */
89 HEADER_ITEM
*items
; /* pointer to array of HEADER_ITEM's */
90 INT
*order
; /* array of item IDs indexed by order */
91 BOOL bRectsValid
; /* validity flag for bounding rectangles */
96 #define DIVIDER_WIDTH 10
97 #define HOT_DIVIDER_WIDTH 2
98 #define MAX_HEADER_TEXT_LEN 260
99 #define HDN_UNICODE_OFFSET 20
100 #define HDN_FIRST_UNICODE (HDN_FIRST-HDN_UNICODE_OFFSET)
102 #define HDI_SUPPORTED_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP|HDI_IMAGE|HDI_ORDER)
103 #define HDI_UNSUPPORTED_FIELDS (HDI_FILTER)
104 #define HDI_UNKNOWN_FIELDS (~(HDI_SUPPORTED_FIELDS|HDI_UNSUPPORTED_FIELDS|HDI_DI_SETITEM))
105 #define HDI_COMCTL32_4_0_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP)
108 static BOOL
HEADER_PrepareCallbackItems(const HEADER_INFO
*infoPtr
, INT iItem
, INT reqMask
);
109 static void HEADER_FreeCallbackItems(HEADER_ITEM
*lpItem
);
110 static LRESULT
HEADER_SendNotify(const HEADER_INFO
*infoPtr
, UINT code
, NMHDR
*hdr
);
111 static LRESULT
HEADER_SendCtrlCustomDraw(const HEADER_INFO
*infoPtr
, DWORD dwDrawStage
, HDC hdc
, const RECT
*rect
);
113 static const WCHAR themeClass
[] = {'H','e','a','d','e','r',0};
115 static void HEADER_StoreHDItemInHeader(HEADER_ITEM
*lpItem
, UINT mask
, const HDITEMW
*phdi
, BOOL fUnicode
)
117 if (mask
& HDI_UNSUPPORTED_FIELDS
)
118 FIXME("unsupported header fields %x\n", (mask
& HDI_UNSUPPORTED_FIELDS
));
120 if (mask
& HDI_BITMAP
)
121 lpItem
->hbm
= phdi
->hbm
;
123 if (mask
& HDI_FORMAT
)
124 lpItem
->fmt
= phdi
->fmt
;
126 if (mask
& HDI_LPARAM
)
127 lpItem
->lParam
= phdi
->lParam
;
129 if (mask
& HDI_WIDTH
)
130 lpItem
->cxy
= phdi
->cxy
;
132 if (mask
& HDI_IMAGE
)
134 lpItem
->iImage
= phdi
->iImage
;
135 if (phdi
->iImage
== I_IMAGECALLBACK
)
136 lpItem
->callbackMask
|= HDI_IMAGE
;
138 lpItem
->callbackMask
&= ~HDI_IMAGE
;
143 Free(lpItem
->pszText
);
144 lpItem
->pszText
= NULL
;
146 if (phdi
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers != TEXTCALLBACKA too */
148 static const WCHAR emptyString
[] = {0};
150 LPCWSTR pszText
= (phdi
->pszText
!= NULL
? phdi
->pszText
: emptyString
);
152 Str_SetPtrW(&lpItem
->pszText
, pszText
);
154 Str_SetPtrAtoW(&lpItem
->pszText
, (LPCSTR
)pszText
);
155 lpItem
->callbackMask
&= ~HDI_TEXT
;
159 lpItem
->pszText
= NULL
;
160 lpItem
->callbackMask
|= HDI_TEXT
;
165 static inline LRESULT
166 HEADER_IndexToOrder (const HEADER_INFO
*infoPtr
, INT iItem
)
168 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
169 return lpItem
->iOrder
;
174 HEADER_OrderToIndex(const HEADER_INFO
*infoPtr
, INT iorder
)
176 if ((iorder
<0) || iorder
>= infoPtr
->uNumItem
)
178 return infoPtr
->order
[iorder
];
182 HEADER_ChangeItemOrder(const HEADER_INFO
*infoPtr
, INT iItem
, INT iNewOrder
)
184 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
187 TRACE("%d: %d->%d\n", iItem
, lpItem
->iOrder
, iNewOrder
);
188 if (lpItem
->iOrder
< iNewOrder
)
190 memmove(&infoPtr
->order
[lpItem
->iOrder
],
191 &infoPtr
->order
[lpItem
->iOrder
+ 1],
192 (iNewOrder
- lpItem
->iOrder
) * sizeof(INT
));
194 if (iNewOrder
< lpItem
->iOrder
)
196 memmove(&infoPtr
->order
[iNewOrder
+ 1],
197 &infoPtr
->order
[iNewOrder
],
198 (lpItem
->iOrder
- iNewOrder
) * sizeof(INT
));
200 infoPtr
->order
[iNewOrder
] = iItem
;
201 nMin
= min(lpItem
->iOrder
, iNewOrder
);
202 nMax
= max(lpItem
->iOrder
, iNewOrder
);
203 for (i
= nMin
; i
<= nMax
; i
++)
204 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
207 /* Note: if iItem is the last item then this function returns infoPtr->uNumItem */
209 HEADER_NextItem(const HEADER_INFO
*infoPtr
, INT iItem
)
211 return HEADER_OrderToIndex(infoPtr
, HEADER_IndexToOrder(infoPtr
, iItem
)+1);
215 HEADER_PrevItem(const HEADER_INFO
*infoPtr
, INT iItem
)
217 return HEADER_OrderToIndex(infoPtr
, HEADER_IndexToOrder(infoPtr
, iItem
)-1);
220 /* TRUE when item is not resizable with dividers,
221 note that valid index should be supplied */
223 HEADER_IsItemFixed(const HEADER_INFO
*infoPtr
, INT iItem
)
225 return (infoPtr
->dwStyle
& HDS_NOSIZING
) || (infoPtr
->items
[iItem
].fmt
& HDF_FIXEDWIDTH
);
229 HEADER_SetItemBounds (HEADER_INFO
*infoPtr
)
236 infoPtr
->bRectsValid
= TRUE
;
238 if (infoPtr
->uNumItem
== 0)
241 GetClientRect (infoPtr
->hwndSelf
, &rect
);
244 for (i
= 0; i
< infoPtr
->uNumItem
; i
++) {
245 phdi
= &infoPtr
->items
[HEADER_OrderToIndex(infoPtr
,i
)];
246 phdi
->rect
.top
= rect
.top
;
247 phdi
->rect
.bottom
= rect
.bottom
;
249 phdi
->rect
.right
= phdi
->rect
.left
+ ((phdi
->cxy
>0)?phdi
->cxy
:0);
250 x
= phdi
->rect
.right
;
255 HEADER_Size (HEADER_INFO
*infoPtr
)
257 HEADER_SetItemBounds(infoPtr
);
261 static void HEADER_GetHotDividerRect(const HEADER_INFO
*infoPtr
, RECT
*r
)
263 INT iDivider
= infoPtr
->iHotDivider
;
264 if (infoPtr
->uNumItem
> 0)
268 if (iDivider
< infoPtr
->uNumItem
)
270 lpItem
= &infoPtr
->items
[iDivider
];
271 r
->left
= lpItem
->rect
.left
- HOT_DIVIDER_WIDTH
/2;
272 r
->right
= lpItem
->rect
.left
+ HOT_DIVIDER_WIDTH
/2;
276 lpItem
= &infoPtr
->items
[HEADER_OrderToIndex(infoPtr
, infoPtr
->uNumItem
-1)];
277 r
->left
= lpItem
->rect
.right
- HOT_DIVIDER_WIDTH
/2;
278 r
->right
= lpItem
->rect
.right
+ HOT_DIVIDER_WIDTH
/2;
280 r
->top
= lpItem
->rect
.top
;
281 r
->bottom
= lpItem
->rect
.bottom
;
286 GetClientRect(infoPtr
->hwndSelf
, &clientRect
);
288 r
->right
= r
->left
+ HOT_DIVIDER_WIDTH
/2;
293 HEADER_FillItemFrame(HEADER_INFO
*infoPtr
, HDC hdc
, RECT
*r
, const HEADER_ITEM
*item
, BOOL hottrack
)
295 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
298 int state
= (item
->bDown
) ? HIS_PRESSED
: (hottrack
? HIS_HOT
: HIS_NORMAL
);
299 DrawThemeBackground (theme
, hdc
, HP_HEADERITEM
, state
, r
, NULL
);
300 GetThemeBackgroundContentRect (theme
, hdc
, HP_HEADERITEM
, state
, r
, r
);
304 HBRUSH hbr
= CreateSolidBrush(GetBkColor(hdc
));
305 FillRect(hdc
, r
, hbr
);
311 HEADER_DrawItemFrame(HEADER_INFO
*infoPtr
, HDC hdc
, RECT
*r
, const HEADER_ITEM
*item
)
313 if (GetWindowTheme(infoPtr
->hwndSelf
)) return;
315 if (!(infoPtr
->dwStyle
& HDS_FLAT
))
317 if (infoPtr
->dwStyle
& HDS_BUTTONS
) {
319 DrawEdge (hdc
, r
, BDR_RAISEDOUTER
, BF_RECT
| BF_FLAT
| BF_ADJUST
);
321 DrawEdge (hdc
, r
, EDGE_RAISED
, BF_RECT
| BF_SOFT
| BF_ADJUST
);
324 DrawEdge (hdc
, r
, EDGE_ETCHED
, BF_BOTTOM
| BF_RIGHT
| BF_ADJUST
);
329 HEADER_DrawItem (HEADER_INFO
*infoPtr
, HDC hdc
, INT iItem
, BOOL bHotTrack
, LRESULT lCDFlags
)
331 HEADER_ITEM
*phdi
= &infoPtr
->items
[iItem
];
334 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
337 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem
, bHotTrack
, (infoPtr
->nNotifyFormat
== NFR_UNICODE
));
340 if (r
.right
- r
.left
== 0)
341 return phdi
->rect
.right
;
343 /* Set the colors before sending NM_CUSTOMDRAW so that it can change them */
344 SetTextColor(hdc
, (bHotTrack
&& !theme
) ? COLOR_HIGHLIGHT
: COLOR_BTNTEXT
);
345 SetBkColor(hdc
, comctl32_color
.clr3dFace
);
347 if (lCDFlags
& CDRF_NOTIFYITEMDRAW
&& !(phdi
->fmt
& HDF_OWNERDRAW
))
349 LRESULT lCDItemFlags
;
351 nmcd
.dwDrawStage
= CDDS_PREPAINT
| CDDS_ITEM
;
353 nmcd
.dwItemSpec
= iItem
;
355 nmcd
.uItemState
= phdi
->bDown
? CDIS_SELECTED
: 0;
356 nmcd
.lItemlParam
= phdi
->lParam
;
358 lCDItemFlags
= HEADER_SendNotify(infoPtr
, NM_CUSTOMDRAW
, (NMHDR
*)&nmcd
);
359 if (lCDItemFlags
& CDRF_SKIPDEFAULT
)
360 return phdi
->rect
.right
;
363 /* Fill background, owner could draw over it. */
364 HEADER_FillItemFrame(infoPtr
, hdc
, &r
, phdi
, bHotTrack
);
366 if (phdi
->fmt
& HDF_OWNERDRAW
)
371 dis
.CtlType
= ODT_HEADER
;
372 dis
.CtlID
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
374 dis
.itemAction
= ODA_DRAWENTIRE
;
375 dis
.itemState
= phdi
->bDown
? ODS_SELECTED
: 0;
376 dis
.hwndItem
= infoPtr
->hwndSelf
;
378 dis
.rcItem
= phdi
->rect
;
379 dis
.itemData
= phdi
->lParam
;
380 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
381 ret
= SendMessageW (infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
382 if (oldBkMode
!= TRANSPARENT
)
383 SetBkMode(hdc
, oldBkMode
);
386 HEADER_FillItemFrame(infoPtr
, hdc
, &r
, phdi
, bHotTrack
);
388 /* Edges are always drawn if we don't have attached theme. */
389 HEADER_DrawItemFrame(infoPtr
, hdc
, &r
, phdi
);
390 /* If application processed WM_DRAWITEM we should skip label painting,
391 edges are drawn no matter what. */
392 if (ret
) return phdi
->rect
.right
;
395 HEADER_DrawItemFrame(infoPtr
, hdc
, &r
, phdi
);
402 /* Now text and image */
404 UINT rw
, rh
, /* width and height of r */
405 *x
= NULL
, *w
= NULL
; /* x and width of the pic (bmp or img) which is part of cnt */
406 /* cnt,txt,img,bmp */
412 HEADER_PrepareCallbackItems(infoPtr
, iItem
, HDI_TEXT
|HDI_IMAGE
);
414 rw
= r
.right
- r
.left
;
415 rh
= r
.bottom
- r
.top
;
417 if (phdi
->fmt
& HDF_STRING
) {
420 SetRectEmpty(&textRect
);
421 DrawTextW (hdc
, phdi
->pszText
, -1,
422 &textRect
, DT_LEFT
|DT_VCENTER
|DT_SINGLELINE
|DT_CALCRECT
);
423 cw
= textRect
.right
- textRect
.left
+ 2 * infoPtr
->iMargin
;
426 if ((phdi
->fmt
& HDF_IMAGE
) && ImageList_GetIconSize( infoPtr
->himl
, &img_cx
, &img_cy
)) {
427 iw
= img_cx
+ 2 * infoPtr
->iMargin
;
432 if ((phdi
->fmt
& HDF_BITMAP
) && (phdi
->hbm
)) {
433 GetObjectW (phdi
->hbm
, sizeof(BITMAP
), &bmp
);
434 bw
= bmp
.bmWidth
+ 2 * infoPtr
->iMargin
;
444 /* align cx using the unclipped cw */
445 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_LEFT
)
447 else if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_CENTER
)
448 cx
= r
.left
+ rw
/ 2 - cw
/ 2;
455 if (cx
+ cw
> r
.right
)
458 tx
= cx
+ infoPtr
->iMargin
;
459 /* since cw might have changed we have to recalculate tw */
460 tw
= cw
- infoPtr
->iMargin
* 2;
464 if (phdi
->fmt
& HDF_BITMAP_ON_RIGHT
) {
465 /* put pic behind text */
466 *x
= cx
+ tw
+ infoPtr
->iMargin
* 3;
468 *x
= cx
+ infoPtr
->iMargin
;
469 /* move text behind pic */
475 /* since we're done with the layout we can
476 now calculate the position of bmp which
477 has no influence on alignment and layout
479 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_RIGHT
)
480 bx
= cx
- bw
+ infoPtr
->iMargin
;
482 bx
= cx
+ cw
+ infoPtr
->iMargin
;
486 HDC hClipDC
= GetDC(infoPtr
->hwndSelf
);
487 HRGN hClipRgn
= CreateRectRgn(r
.left
, r
.top
, r
.right
, r
.bottom
);
488 SelectClipRgn(hClipDC
, hClipRgn
);
491 HDC hdcBitmap
= CreateCompatibleDC (hClipDC
);
492 SelectObject (hdcBitmap
, phdi
->hbm
);
493 BitBlt (hClipDC
, bx
, r
.top
+ ((INT
)rh
- bmp
.bmHeight
) / 2,
494 bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
495 DeleteDC (hdcBitmap
);
499 ImageList_DrawEx (infoPtr
->himl
, phdi
->iImage
, hClipDC
,
500 ix
, r
.top
+ ((INT
)rh
- img_cy
) / 2,
501 img_cx
, img_cy
, CLR_DEFAULT
, CLR_DEFAULT
, 0);
504 DeleteObject(hClipRgn
);
505 ReleaseDC(infoPtr
->hwndSelf
, hClipDC
);
508 if (((phdi
->fmt
& HDF_STRING
)
509 || (!(phdi
->fmt
& (HDF_OWNERDRAW
|HDF_STRING
|HDF_BITMAP
|
510 HDF_BITMAP_ON_RIGHT
|HDF_IMAGE
)))) /* no explicit format specified? */
511 && (phdi
->pszText
)) {
512 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
515 DrawTextW (hdc
, phdi
->pszText
, -1,
516 &r
, DT_LEFT
|DT_END_ELLIPSIS
|DT_VCENTER
|DT_SINGLELINE
);
517 if (oldBkMode
!= TRANSPARENT
)
518 SetBkMode(hdc
, oldBkMode
);
520 HEADER_FreeCallbackItems(phdi
);
523 return phdi
->rect
.right
;
527 HEADER_DrawHotDivider(const HEADER_INFO
*infoPtr
, HDC hdc
)
532 HEADER_GetHotDividerRect(infoPtr
, &r
);
533 brush
= CreateSolidBrush(comctl32_color
.clrHighlight
);
534 FillRect(hdc
, &r
, brush
);
539 HEADER_Refresh (HEADER_INFO
*infoPtr
, HDC hdc
)
541 HFONT hFont
, hOldFont
;
547 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
549 if (!infoPtr
->bRectsValid
)
550 HEADER_SetItemBounds(infoPtr
);
552 /* get rect for the bar, adjusted for the border */
553 GetClientRect (infoPtr
->hwndSelf
, &rect
);
554 lCDFlags
= HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_PREPAINT
, hdc
, &rect
);
556 if (infoPtr
->bDragging
)
557 ImageList_DragShowNolock(FALSE
);
559 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
);
560 hOldFont
= SelectObject (hdc
, hFont
);
562 /* draw Background */
563 if (infoPtr
->uNumItem
== 0 && theme
== NULL
) {
564 hbrBk
= GetSysColorBrush(COLOR_3DFACE
);
565 FillRect(hdc
, &rect
, hbrBk
);
569 for (i
= 0; x
<= rect
.right
&& i
< infoPtr
->uNumItem
; i
++) {
570 int idx
= HEADER_OrderToIndex(infoPtr
,i
);
571 if (RectVisible(hdc
, &infoPtr
->items
[idx
].rect
))
572 HEADER_DrawItem(infoPtr
, hdc
, idx
, infoPtr
->iHotItem
== idx
, lCDFlags
);
573 x
= infoPtr
->items
[idx
].rect
.right
;
578 if ((x
<= rect
.right
) && RectVisible(hdc
, &rcRest
) && (infoPtr
->uNumItem
> 0)) {
580 DrawThemeBackground(theme
, hdc
, HP_HEADERITEM
, HIS_NORMAL
, &rcRest
, NULL
);
582 else if (infoPtr
->dwStyle
& HDS_FLAT
) {
583 hbrBk
= GetSysColorBrush(COLOR_3DFACE
);
584 FillRect(hdc
, &rcRest
, hbrBk
);
588 if (infoPtr
->dwStyle
& HDS_BUTTONS
)
589 DrawEdge (hdc
, &rcRest
, EDGE_RAISED
, BF_TOP
|BF_LEFT
|BF_BOTTOM
|BF_SOFT
|BF_MIDDLE
);
591 DrawEdge (hdc
, &rcRest
, EDGE_ETCHED
, BF_BOTTOM
|BF_MIDDLE
);
595 if (infoPtr
->iHotDivider
!= -1)
596 HEADER_DrawHotDivider(infoPtr
, hdc
);
598 if (infoPtr
->bDragging
)
599 ImageList_DragShowNolock(TRUE
);
600 SelectObject (hdc
, hOldFont
);
602 if (lCDFlags
& CDRF_NOTIFYPOSTPAINT
)
603 HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_POSTPAINT
, hdc
, &rect
);
608 HEADER_RefreshItem (HEADER_INFO
*infoPtr
, INT iItem
)
610 if (!infoPtr
->bRectsValid
)
611 HEADER_SetItemBounds(infoPtr
);
613 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->items
[iItem
].rect
, FALSE
);
618 HEADER_InternalHitTest (const HEADER_INFO
*infoPtr
, const POINT
*lpPt
, UINT
*pFlags
, INT
*pItem
)
625 GetClientRect (infoPtr
->hwndSelf
, &rect
);
629 if (PtInRect (&rect
, *lpPt
))
631 if (infoPtr
->uNumItem
== 0) {
632 *pFlags
|= HHT_NOWHERE
;
638 /* somewhere inside */
639 for (iCount
= 0; iCount
< infoPtr
->uNumItem
; iCount
++) {
640 rect
= infoPtr
->items
[iCount
].rect
;
641 width
= rect
.right
- rect
.left
;
646 if (PtInRect (&rect
, *lpPt
)) {
647 if (width
<= 2 * DIVIDER_WIDTH
) {
648 *pFlags
|= HHT_ONHEADER
;
650 TRACE("ON HEADER %d\n", iCount
);
653 if (HEADER_IndexToOrder(infoPtr
, iCount
) > 0) {
655 rcTest
.right
= rcTest
.left
+ DIVIDER_WIDTH
;
656 if (PtInRect (&rcTest
, *lpPt
)) {
657 if (HEADER_IsItemFixed(infoPtr
, HEADER_PrevItem(infoPtr
, iCount
)))
659 *pFlags
|= HHT_ONHEADER
;
661 TRACE("ON HEADER %d\n", *pItem
);
665 *pFlags
|= HHT_ONDIVOPEN
;
666 *pItem
= HEADER_PrevItem(infoPtr
, iCount
);
667 TRACE("ON DIVOPEN %d\n", *pItem
);
671 *pFlags
|= HHT_ONDIVIDER
;
672 *pItem
= HEADER_PrevItem(infoPtr
, iCount
);
673 TRACE("ON DIVIDER %d\n", *pItem
);
679 rcTest
.left
= rcTest
.right
- DIVIDER_WIDTH
;
680 if (!HEADER_IsItemFixed(infoPtr
, iCount
) && PtInRect (&rcTest
, *lpPt
))
682 *pFlags
|= HHT_ONDIVIDER
;
684 TRACE("ON DIVIDER %d\n", *pItem
);
688 *pFlags
|= HHT_ONHEADER
;
690 TRACE("ON HEADER %d\n", iCount
);
695 /* check for last divider part (on nowhere) */
696 if (!HEADER_IsItemFixed(infoPtr
, infoPtr
->uNumItem
- 1))
698 rect
= infoPtr
->items
[infoPtr
->uNumItem
-1].rect
;
699 rect
.left
= rect
.right
;
700 rect
.right
+= DIVIDER_WIDTH
;
701 if (PtInRect (&rect
, *lpPt
)) {
703 *pFlags
|= HHT_ONDIVOPEN
;
704 *pItem
= infoPtr
->uNumItem
- 1;
705 TRACE("ON DIVOPEN %d\n", *pItem
);
709 *pFlags
|= HHT_ONDIVIDER
;
710 *pItem
= infoPtr
->uNumItem
- 1;
711 TRACE("ON DIVIDER %d\n", *pItem
);
717 *pFlags
|= HHT_NOWHERE
;
724 if (lpPt
->x
< rect
.left
) {
726 *pFlags
|= HHT_TOLEFT
;
728 else if (lpPt
->x
> rect
.right
) {
730 *pFlags
|= HHT_TORIGHT
;
733 if (lpPt
->y
< rect
.top
) {
735 *pFlags
|= HHT_ABOVE
;
737 else if (lpPt
->y
> rect
.bottom
) {
739 *pFlags
|= HHT_BELOW
;
744 TRACE("flags=0x%X\n", *pFlags
);
750 HEADER_DrawTrackLine (const HEADER_INFO
*infoPtr
, HDC hdc
, INT x
)
754 GetClientRect (infoPtr
->hwndSelf
, &rect
);
755 PatBlt( hdc
, x
, rect
.top
, 1, rect
.bottom
- rect
.top
, DSTINVERT
);
760 * Convert a HDITEM into the correct format (ANSI/Unicode) to send it in a notify
763 * [I] infoPtr : the header that wants to send the notify
764 * [O] dest : The buffer to store the HDITEM for notify. It may be set to a HDITEMA of HDITEMW
765 * [I] src : The source HDITEM. It may be a HDITEMA or HDITEMW
766 * [I] fSourceUnicode : is src a HDITEMW or HDITEMA
767 * [O] ppvScratch : a pointer to a scratch buffer that needs to be freed after
768 * the HDITEM is no longer in use or NULL if none was needed
770 * NOTE: We depend on HDITEMA and HDITEMW having the same structure
772 static void HEADER_CopyHDItemForNotify(const HEADER_INFO
*infoPtr
, HDITEMW
*dest
,
773 const HDITEMW
*src
, BOOL fSourceUnicode
, LPVOID
*ppvScratch
)
778 if (src
->mask
& HDI_TEXT
&& src
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers TEXTCALLBACKA as well */
780 if (fSourceUnicode
&& infoPtr
->nNotifyFormat
!= NFR_UNICODE
)
782 dest
->pszText
= NULL
;
783 Str_SetPtrWtoA((LPSTR
*)&dest
->pszText
, src
->pszText
);
784 *ppvScratch
= dest
->pszText
;
787 if (!fSourceUnicode
&& infoPtr
->nNotifyFormat
== NFR_UNICODE
)
789 dest
->pszText
= NULL
;
790 Str_SetPtrAtoW(&dest
->pszText
, (LPSTR
)src
->pszText
);
791 *ppvScratch
= dest
->pszText
;
796 static UINT
HEADER_NotifyCodeWtoA(UINT code
)
798 /* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
799 if (code
>= HDN_LAST
&& code
<= HDN_FIRST_UNICODE
)
800 return code
+ HDN_UNICODE_OFFSET
;
806 HEADER_SendNotify(const HEADER_INFO
*infoPtr
, UINT code
, NMHDR
*nmhdr
)
808 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
809 nmhdr
->idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
812 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
813 nmhdr
->idFrom
, (LPARAM
)nmhdr
);
817 HEADER_SendSimpleNotify (const HEADER_INFO
*infoPtr
, UINT code
)
820 return (BOOL
)HEADER_SendNotify(infoPtr
, code
, &nmhdr
);
824 HEADER_SendCtrlCustomDraw(const HEADER_INFO
*infoPtr
, DWORD dwDrawStage
, HDC hdc
, const RECT
*rect
)
827 nm
.dwDrawStage
= dwDrawStage
;
834 return HEADER_SendNotify(infoPtr
, NM_CUSTOMDRAW
, (NMHDR
*)&nm
);
838 HEADER_SendNotifyWithHDItemT(const HEADER_INFO
*infoPtr
, UINT code
, INT iItem
, HDITEMW
*lpItem
)
842 if (infoPtr
->nNotifyFormat
!= NFR_UNICODE
)
843 code
= HEADER_NotifyCodeWtoA(code
);
846 nmhdr
.pitem
= lpItem
;
848 return (BOOL
)HEADER_SendNotify(infoPtr
, code
, (NMHDR
*)&nmhdr
);
852 HEADER_SendNotifyWithIntFieldT(const HEADER_INFO
*infoPtr
, UINT code
, INT iItem
, INT mask
, INT iValue
)
856 /* copying only the iValue should be ok but to make the code more robust we copy everything */
857 nmitem
.cxy
= infoPtr
->items
[iItem
].cxy
;
858 nmitem
.hbm
= infoPtr
->items
[iItem
].hbm
;
859 nmitem
.pszText
= NULL
;
860 nmitem
.cchTextMax
= 0;
861 nmitem
.fmt
= infoPtr
->items
[iItem
].fmt
;
862 nmitem
.lParam
= infoPtr
->items
[iItem
].lParam
;
863 nmitem
.iOrder
= infoPtr
->items
[iItem
].iOrder
;
864 nmitem
.iImage
= infoPtr
->items
[iItem
].iImage
;
873 nmitem
.iOrder
= iValue
;
876 ERR("invalid mask value 0x%x\n", iValue
);
879 return HEADER_SendNotifyWithHDItemT(infoPtr
, code
, iItem
, &nmitem
);
883 * Prepare callback items
884 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
885 * (so we handle the two cases only doing a specific cast for pszText).
886 * Checks if any of the required fields is a callback. If this is the case sends a
887 * NMHDISPINFO notify to retrieve these items. The items are stored in the
888 * HEADER_ITEM pszText and iImage fields. They should be freed with
889 * HEADER_FreeCallbackItems.
891 * @param hwnd : hwnd header container handler
892 * @param iItem : the header item id
893 * @param reqMask : required fields. If any of them is callback this function will fetch it
895 * @return TRUE on success, else FALSE
898 HEADER_PrepareCallbackItems(const HEADER_INFO
*infoPtr
, INT iItem
, INT reqMask
)
900 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
901 DWORD mask
= reqMask
& lpItem
->callbackMask
;
902 NMHDDISPINFOW dispInfo
;
903 void *pvBuffer
= NULL
;
907 if (mask
&HDI_TEXT
&& lpItem
->pszText
!= NULL
)
909 ERR("(): function called without a call to FreeCallbackItems\n");
910 Free(lpItem
->pszText
);
911 lpItem
->pszText
= NULL
;
914 memset(&dispInfo
, 0, sizeof(NMHDDISPINFOW
));
915 dispInfo
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
916 dispInfo
.hdr
.idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
917 if (infoPtr
->nNotifyFormat
== NFR_UNICODE
)
919 dispInfo
.hdr
.code
= HDN_GETDISPINFOW
;
921 pvBuffer
= Alloc(MAX_HEADER_TEXT_LEN
* sizeof(WCHAR
));
925 dispInfo
.hdr
.code
= HDN_GETDISPINFOA
;
927 pvBuffer
= Alloc(MAX_HEADER_TEXT_LEN
* sizeof(CHAR
));
929 dispInfo
.pszText
= pvBuffer
;
930 dispInfo
.cchTextMax
= (pvBuffer
!=NULL
?MAX_HEADER_TEXT_LEN
:0);
931 dispInfo
.iItem
= iItem
;
932 dispInfo
.mask
= mask
;
933 dispInfo
.lParam
= lpItem
->lParam
;
935 TRACE("Sending HDN_GETDISPINFO%c\n", infoPtr
->nNotifyFormat
== NFR_UNICODE
?'W':'A');
936 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, dispInfo
.hdr
.idFrom
, (LPARAM
)&dispInfo
);
938 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
940 (infoPtr
->nNotifyFormat
== NFR_UNICODE
? debugstr_w(dispInfo
.pszText
) : (LPSTR
) dispInfo
.pszText
),
941 (void*) dispInfo
.lParam
);
943 if (mask
& HDI_IMAGE
)
944 lpItem
->iImage
= dispInfo
.iImage
;
947 if (infoPtr
->nNotifyFormat
== NFR_UNICODE
)
949 lpItem
->pszText
= pvBuffer
;
951 /* the user might have used his own buffer */
952 if (dispInfo
.pszText
!= lpItem
->pszText
)
953 Str_GetPtrW(dispInfo
.pszText
, lpItem
->pszText
, MAX_HEADER_TEXT_LEN
);
957 Str_SetPtrAtoW(&lpItem
->pszText
, (LPSTR
)dispInfo
.pszText
);
962 if (dispInfo
.mask
& HDI_DI_SETITEM
)
964 /* make the items permanent */
965 lpItem
->callbackMask
&= ~dispInfo
.mask
;
973 * Free the items that might be allocated with HEADER_PrepareCallbackItems
976 * [I] lpItem : the item to free the data
980 HEADER_FreeCallbackItems(HEADER_ITEM
*lpItem
)
982 if (lpItem
->callbackMask
&HDI_TEXT
)
984 Free(lpItem
->pszText
);
985 lpItem
->pszText
= NULL
;
988 if (lpItem
->callbackMask
&HDI_IMAGE
)
989 lpItem
->iImage
= I_IMAGECALLBACK
;
993 HEADER_CreateDragImage (HEADER_INFO
*infoPtr
, INT iItem
)
997 HBITMAP hMemory
, hOldBitmap
;
1005 if (iItem
>= infoPtr
->uNumItem
)
1008 if (!infoPtr
->bRectsValid
)
1009 HEADER_SetItemBounds(infoPtr
);
1011 lpItem
= &infoPtr
->items
[iItem
];
1012 width
= lpItem
->rect
.right
- lpItem
->rect
.left
;
1013 height
= lpItem
->rect
.bottom
- lpItem
->rect
.top
;
1015 hDeviceDC
= GetDC(NULL
);
1016 hMemoryDC
= CreateCompatibleDC(hDeviceDC
);
1017 hMemory
= CreateCompatibleBitmap(hDeviceDC
, width
, height
);
1018 ReleaseDC(NULL
, hDeviceDC
);
1019 hOldBitmap
= SelectObject(hMemoryDC
, hMemory
);
1020 SetViewportOrgEx(hMemoryDC
, -lpItem
->rect
.left
, -lpItem
->rect
.top
, NULL
);
1021 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject(SYSTEM_FONT
);
1022 SelectObject(hMemoryDC
, hFont
);
1024 GetClientRect(infoPtr
->hwndSelf
, &rc
);
1025 lCDFlags
= HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_PREPAINT
, hMemoryDC
, &rc
);
1026 HEADER_DrawItem(infoPtr
, hMemoryDC
, iItem
, FALSE
, lCDFlags
);
1027 if (lCDFlags
& CDRF_NOTIFYPOSTPAINT
)
1028 HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_POSTPAINT
, hMemoryDC
, &rc
);
1030 hMemory
= SelectObject(hMemoryDC
, hOldBitmap
);
1031 DeleteDC(hMemoryDC
);
1033 if (hMemory
== NULL
) /* if anything failed */
1036 himl
= ImageList_Create(width
, height
, ILC_COLORDDB
, 1, 1);
1037 ImageList_Add(himl
, hMemory
, NULL
);
1038 DeleteObject(hMemory
);
1039 return (LRESULT
)himl
;
1043 HEADER_SetHotDivider(HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1052 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1054 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &iDivider
);
1056 if (flags
& HHT_TOLEFT
)
1058 else if (flags
& HHT_NOWHERE
|| flags
& HHT_TORIGHT
)
1059 iDivider
= infoPtr
->uNumItem
;
1062 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iDivider
];
1063 if (pt
.x
> (lpItem
->rect
.left
+lpItem
->rect
.right
)/2)
1064 iDivider
= HEADER_NextItem(infoPtr
, iDivider
);
1068 iDivider
= (INT
)lParam
;
1070 /* Note; wParam==FALSE, lParam==-1 is valid and is used to clear the hot divider */
1071 if (iDivider
<-1 || iDivider
>(int)infoPtr
->uNumItem
)
1074 if (iDivider
!= infoPtr
->iHotDivider
)
1076 if (infoPtr
->iHotDivider
!= -1)
1078 HEADER_GetHotDividerRect(infoPtr
, &r
);
1079 InvalidateRect(infoPtr
->hwndSelf
, &r
, FALSE
);
1081 infoPtr
->iHotDivider
= iDivider
;
1084 HEADER_GetHotDividerRect(infoPtr
, &r
);
1085 InvalidateRect(infoPtr
->hwndSelf
, &r
, FALSE
);
1092 HEADER_DeleteItem (HEADER_INFO
*infoPtr
, INT iItem
)
1097 TRACE("[iItem=%d]\n", iItem
);
1099 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
1102 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1103 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
1105 iOrder
= infoPtr
->items
[iItem
].iOrder
;
1106 Free(infoPtr
->items
[iItem
].pszText
);
1108 infoPtr
->uNumItem
--;
1109 memmove(&infoPtr
->items
[iItem
], &infoPtr
->items
[iItem
+ 1],
1110 (infoPtr
->uNumItem
- iItem
) * sizeof(HEADER_ITEM
));
1111 memmove(&infoPtr
->order
[iOrder
], &infoPtr
->order
[iOrder
+ 1],
1112 (infoPtr
->uNumItem
- iOrder
) * sizeof(INT
));
1113 infoPtr
->items
= ReAlloc(infoPtr
->items
, sizeof(HEADER_ITEM
) * infoPtr
->uNumItem
);
1114 infoPtr
->order
= ReAlloc(infoPtr
->order
, sizeof(INT
) * infoPtr
->uNumItem
);
1116 /* Correct the orders */
1117 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1119 if (infoPtr
->order
[i
] > iItem
)
1120 infoPtr
->order
[i
]--;
1122 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
1124 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1125 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
1127 HEADER_SetItemBounds (infoPtr
);
1128 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1135 HEADER_GetImageList (const HEADER_INFO
*infoPtr
)
1137 return (LRESULT
)infoPtr
->himl
;
1142 HEADER_GetItemT (const HEADER_INFO
*infoPtr
, INT nItem
, LPHDITEMW phdi
, BOOL bUnicode
)
1144 HEADER_ITEM
*lpItem
;
1150 TRACE("[nItem=%d]\n", nItem
);
1156 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
1159 if (mask
& HDI_UNKNOWN_FIELDS
)
1161 TRACE("mask %x contains unknown fields. Using only comctl32 4.0 fields\n", mask
);
1162 mask
&= HDI_COMCTL32_4_0_FIELDS
;
1165 lpItem
= &infoPtr
->items
[nItem
];
1166 HEADER_PrepareCallbackItems(infoPtr
, nItem
, mask
);
1168 if (mask
& HDI_BITMAP
)
1169 phdi
->hbm
= lpItem
->hbm
;
1171 if (mask
& HDI_FORMAT
)
1172 phdi
->fmt
= lpItem
->fmt
;
1174 if (mask
& HDI_WIDTH
)
1175 phdi
->cxy
= lpItem
->cxy
;
1177 if (mask
& HDI_LPARAM
)
1178 phdi
->lParam
= lpItem
->lParam
;
1180 if (mask
& HDI_IMAGE
)
1181 phdi
->iImage
= lpItem
->iImage
;
1183 if (mask
& HDI_ORDER
)
1184 phdi
->iOrder
= lpItem
->iOrder
;
1186 if (mask
& HDI_TEXT
)
1189 Str_GetPtrW (lpItem
->pszText
, phdi
->pszText
, phdi
->cchTextMax
);
1191 Str_GetPtrWtoA (lpItem
->pszText
, (LPSTR
)phdi
->pszText
, phdi
->cchTextMax
);
1194 HEADER_FreeCallbackItems(lpItem
);
1199 static inline LRESULT
1200 HEADER_GetItemCount (const HEADER_INFO
*infoPtr
)
1202 return infoPtr
->uNumItem
;
1207 HEADER_GetItemRect (const HEADER_INFO
*infoPtr
, INT iItem
, LPRECT lpRect
)
1209 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
1212 lpRect
->left
= infoPtr
->items
[iItem
].rect
.left
;
1213 lpRect
->right
= infoPtr
->items
[iItem
].rect
.right
;
1214 lpRect
->top
= infoPtr
->items
[iItem
].rect
.top
;
1215 lpRect
->bottom
= infoPtr
->items
[iItem
].rect
.bottom
;
1222 HEADER_GetOrderArray(const HEADER_INFO
*infoPtr
, INT size
, LPINT order
)
1224 if ((UINT
)size
<infoPtr
->uNumItem
)
1227 memcpy(order
, infoPtr
->order
, infoPtr
->uNumItem
* sizeof(INT
));
1231 /* Returns index of first duplicate 'value' from [0,to) range,
1232 or -1 if there isn't any */
1233 static INT
has_duplicate(const INT
*array
, INT to
, INT value
)
1236 for(i
= 0; i
< to
; i
++)
1237 if (array
[i
] == value
) return i
;
1241 /* returns next available value from [0,max] not to duplicate in [0,to) */
1242 static INT
get_nextvalue(const INT
*array
, INT to
, INT max
)
1245 for(i
= 0; i
< max
; i
++)
1246 if (has_duplicate(array
, to
, i
) == -1) return i
;
1251 HEADER_SetOrderArray(HEADER_INFO
*infoPtr
, INT size
, const INT
*order
)
1253 HEADER_ITEM
*lpItem
;
1256 if ((UINT
)size
!= infoPtr
->uNumItem
)
1259 if (TRACE_ON(header
))
1261 TRACE("count=%d, order array={", size
);
1262 for (i
= 0; i
< size
; i
++)
1263 TRACE("%d%c", order
[i
], i
!= size
-1 ? ',' : '}');
1267 for (i
=0; i
<size
; i
++)
1269 if (order
[i
] >= size
|| order
[i
] < 0)
1270 /* on invalid index get next available */
1271 /* FIXME: if i==0 array item is out of range behaviour is
1272 different, see tests */
1273 infoPtr
->order
[i
] = get_nextvalue(infoPtr
->order
, i
, size
);
1278 infoPtr
->order
[i
] = order
[i
];
1280 /* remove duplicates */
1281 while ((dup
= has_duplicate(infoPtr
->order
, j
, order
[j
])) != -1)
1285 next
= get_nextvalue(infoPtr
->order
, j
, size
);
1286 infoPtr
->order
[dup
] = next
;
1291 /* sync with item data */
1292 for (i
=0; i
<size
; i
++)
1294 lpItem
= &infoPtr
->items
[infoPtr
->order
[i
]];
1297 HEADER_SetItemBounds(infoPtr
);
1298 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1302 static inline LRESULT
1303 HEADER_GetUnicodeFormat (const HEADER_INFO
*infoPtr
)
1305 return (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1310 HEADER_HitTest (const HEADER_INFO
*infoPtr
, LPHDHITTESTINFO phti
)
1312 UINT outside
= HHT_NOWHERE
| HHT_ABOVE
| HHT_BELOW
| HHT_TOLEFT
| HHT_TORIGHT
;
1314 HEADER_InternalHitTest (infoPtr
, &phti
->pt
, &phti
->flags
, &phti
->iItem
);
1316 if (phti
->flags
& outside
)
1317 return phti
->iItem
= -1;
1324 HEADER_InsertItemT (HEADER_INFO
*infoPtr
, INT nItem
, const HDITEMW
*phdi
, BOOL bUnicode
)
1326 HEADER_ITEM
*lpItem
;
1331 if ((phdi
== NULL
) || (nItem
< 0) || (phdi
->mask
== 0))
1334 if (nItem
> infoPtr
->uNumItem
)
1335 nItem
= infoPtr
->uNumItem
;
1337 iOrder
= (phdi
->mask
& HDI_ORDER
) ? phdi
->iOrder
: nItem
;
1340 else if (infoPtr
->uNumItem
< iOrder
)
1341 iOrder
= infoPtr
->uNumItem
;
1343 infoPtr
->uNumItem
++;
1344 infoPtr
->items
= ReAlloc(infoPtr
->items
, sizeof(HEADER_ITEM
) * infoPtr
->uNumItem
);
1345 infoPtr
->order
= ReAlloc(infoPtr
->order
, sizeof(INT
) * infoPtr
->uNumItem
);
1347 /* make space for the new item */
1348 memmove(&infoPtr
->items
[nItem
+ 1], &infoPtr
->items
[nItem
],
1349 (infoPtr
->uNumItem
- nItem
- 1) * sizeof(HEADER_ITEM
));
1350 memmove(&infoPtr
->order
[iOrder
+ 1], &infoPtr
->order
[iOrder
],
1351 (infoPtr
->uNumItem
- iOrder
- 1) * sizeof(INT
));
1353 /* update the order array */
1354 infoPtr
->order
[iOrder
] = nItem
;
1355 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1357 if (i
!= iOrder
&& infoPtr
->order
[i
] >= nItem
)
1358 infoPtr
->order
[i
]++;
1359 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
1362 lpItem
= &infoPtr
->items
[nItem
];
1363 ZeroMemory(lpItem
, sizeof(HEADER_ITEM
));
1364 /* cxy, fmt and lParam are copied even if not in the HDITEM mask */
1365 copyMask
= phdi
->mask
| HDI_WIDTH
| HDI_FORMAT
| HDI_LPARAM
;
1366 HEADER_StoreHDItemInHeader(lpItem
, copyMask
, phdi
, bUnicode
);
1367 lpItem
->iOrder
= iOrder
;
1369 /* set automatically some format bits */
1370 if (phdi
->mask
& HDI_TEXT
)
1371 lpItem
->fmt
|= HDF_STRING
;
1373 lpItem
->fmt
&= ~HDF_STRING
;
1375 if (lpItem
->hbm
!= NULL
)
1376 lpItem
->fmt
|= HDF_BITMAP
;
1378 lpItem
->fmt
&= ~HDF_BITMAP
;
1380 if (phdi
->mask
& HDI_IMAGE
)
1381 lpItem
->fmt
|= HDF_IMAGE
;
1383 HEADER_SetItemBounds (infoPtr
);
1384 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1391 HEADER_Layout (HEADER_INFO
*infoPtr
, LPHDLAYOUT lpLayout
)
1393 lpLayout
->pwpos
->hwnd
= infoPtr
->hwndSelf
;
1394 lpLayout
->pwpos
->hwndInsertAfter
= 0;
1395 lpLayout
->pwpos
->x
= lpLayout
->prc
->left
;
1396 lpLayout
->pwpos
->y
= lpLayout
->prc
->top
;
1397 lpLayout
->pwpos
->cx
= lpLayout
->prc
->right
- lpLayout
->prc
->left
;
1398 if (infoPtr
->dwStyle
& HDS_HIDDEN
)
1399 lpLayout
->pwpos
->cy
= 0;
1401 lpLayout
->pwpos
->cy
= infoPtr
->nHeight
;
1402 lpLayout
->prc
->top
+= infoPtr
->nHeight
;
1404 lpLayout
->pwpos
->flags
= SWP_NOZORDER
;
1406 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1407 lpLayout
->pwpos
->x
, lpLayout
->pwpos
->y
,
1408 lpLayout
->pwpos
->cx
, lpLayout
->pwpos
->cy
);
1410 infoPtr
->bRectsValid
= FALSE
;
1417 HEADER_SetImageList (HEADER_INFO
*infoPtr
, HIMAGELIST himl
)
1421 TRACE("(himl %p)\n", himl
);
1422 himlOld
= infoPtr
->himl
;
1423 infoPtr
->himl
= himl
;
1425 /* FIXME: Refresh needed??? */
1427 return (LRESULT
)himlOld
;
1432 HEADER_GetBitmapMargin(const HEADER_INFO
*infoPtr
)
1434 return infoPtr
->iMargin
;
1438 HEADER_SetBitmapMargin(HEADER_INFO
*infoPtr
, INT iMargin
)
1440 INT oldMargin
= infoPtr
->iMargin
;
1442 infoPtr
->iMargin
= iMargin
;
1448 HEADER_SetItemT (HEADER_INFO
*infoPtr
, INT nItem
, const HDITEMW
*phdi
, BOOL bUnicode
)
1450 HEADER_ITEM
*lpItem
;
1456 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
1459 TRACE("[nItem=%d]\n", nItem
);
1461 HEADER_CopyHDItemForNotify(infoPtr
, &hdNotify
, phdi
, bUnicode
, &pvScratch
);
1462 if (HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCHANGINGW
, nItem
, &hdNotify
))
1468 lpItem
= &infoPtr
->items
[nItem
];
1469 HEADER_StoreHDItemInHeader(lpItem
, phdi
->mask
, phdi
, bUnicode
);
1471 if (phdi
->mask
& HDI_ORDER
)
1472 if (phdi
->iOrder
>= 0 && phdi
->iOrder
< infoPtr
->uNumItem
)
1473 HEADER_ChangeItemOrder(infoPtr
, nItem
, phdi
->iOrder
);
1475 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCHANGEDW
, nItem
, &hdNotify
);
1477 HEADER_SetItemBounds (infoPtr
);
1479 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1485 static inline LRESULT
1486 HEADER_SetUnicodeFormat (HEADER_INFO
*infoPtr
, WPARAM wParam
)
1488 BOOL bTemp
= (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1490 infoPtr
->nNotifyFormat
= ((BOOL
)wParam
? NFR_UNICODE
: NFR_ANSI
);
1497 HEADER_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1499 HEADER_INFO
*infoPtr
;
1504 infoPtr
= Alloc (sizeof(HEADER_INFO
));
1505 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1507 infoPtr
->hwndSelf
= hwnd
;
1508 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1509 infoPtr
->uNumItem
= 0;
1513 infoPtr
->bRectsValid
= FALSE
;
1514 infoPtr
->hcurArrow
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1515 infoPtr
->hcurDivider
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDER
));
1516 infoPtr
->hcurDivopen
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDEROPEN
));
1517 infoPtr
->bPressed
= FALSE
;
1518 infoPtr
->bTracking
= FALSE
;
1519 infoPtr
->dwStyle
= lpcs
->style
;
1520 infoPtr
->iMoveItem
= 0;
1522 infoPtr
->iHotItem
= -1;
1523 infoPtr
->iHotDivider
= -1;
1524 infoPtr
->iMargin
= 3*GetSystemMetrics(SM_CXEDGE
);
1525 infoPtr
->nNotifyFormat
=
1526 SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_QUERY
);
1529 hOldFont
= SelectObject (hdc
, GetStockObject (SYSTEM_FONT
));
1530 GetTextMetricsW (hdc
, &tm
);
1531 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
1532 SelectObject (hdc
, hOldFont
);
1535 OpenThemeData(hwnd
, themeClass
);
1542 HEADER_Destroy (HEADER_INFO
*infoPtr
)
1544 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
1545 CloseThemeData(theme
);
1550 HEADER_NCDestroy (HEADER_INFO
*infoPtr
)
1552 HEADER_ITEM
*lpItem
;
1555 if (infoPtr
->items
) {
1556 lpItem
= infoPtr
->items
;
1557 for (nItem
= 0; nItem
< infoPtr
->uNumItem
; nItem
++, lpItem
++) {
1558 Free(lpItem
->pszText
);
1560 Free (infoPtr
->items
);
1563 Free(infoPtr
->order
);
1565 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
1572 static inline LRESULT
1573 HEADER_GetFont (const HEADER_INFO
*infoPtr
)
1575 return (LRESULT
)infoPtr
->hFont
;
1580 HEADER_IsDragDistance(const HEADER_INFO
*infoPtr
, const POINT
*pt
)
1582 /* Windows allows for a mouse movement before starting the drag. We use the
1583 * SM_CXDOUBLECLICK/SM_CYDOUBLECLICK as that distance.
1585 return (abs(infoPtr
->ptLButtonDown
.x
- pt
->x
)>GetSystemMetrics(SM_CXDOUBLECLK
) ||
1586 abs(infoPtr
->ptLButtonDown
.y
- pt
->y
)>GetSystemMetrics(SM_CYDOUBLECLK
));
1590 HEADER_LButtonDblClk (const HEADER_INFO
*infoPtr
, INT x
, INT y
)
1598 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1600 if ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (flags
== HHT_ONHEADER
))
1601 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMDBLCLICKW
, nItem
, NULL
);
1602 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
))
1603 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_DIVIDERDBLCLICKW
, nItem
, NULL
);
1610 HEADER_LButtonDown (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1619 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1621 if ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (flags
== HHT_ONHEADER
)) {
1622 SetCapture (infoPtr
->hwndSelf
);
1623 infoPtr
->bCaptured
= TRUE
;
1624 infoPtr
->bPressed
= TRUE
;
1625 infoPtr
->bDragging
= FALSE
;
1626 infoPtr
->iMoveItem
= nItem
;
1627 infoPtr
->ptLButtonDown
= pt
;
1629 infoPtr
->items
[nItem
].bDown
= TRUE
;
1631 /* Send WM_CUSTOMDRAW */
1632 hdc
= GetDC (infoPtr
->hwndSelf
);
1633 HEADER_RefreshItem (infoPtr
, nItem
);
1634 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1636 TRACE("Pressed item %d!\n", nItem
);
1638 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
)) {
1639 INT iCurrWidth
= infoPtr
->items
[nItem
].cxy
;
1640 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_BEGINTRACKW
, nItem
, HDI_WIDTH
, iCurrWidth
))
1642 SetCapture (infoPtr
->hwndSelf
);
1643 infoPtr
->bCaptured
= TRUE
;
1644 infoPtr
->bTracking
= TRUE
;
1645 infoPtr
->iMoveItem
= nItem
;
1646 infoPtr
->xTrackOffset
= infoPtr
->items
[nItem
].rect
.right
- pt
.x
;
1648 if (!(infoPtr
->dwStyle
& HDS_FULLDRAG
)) {
1649 infoPtr
->xOldTrack
= infoPtr
->items
[nItem
].rect
.right
;
1650 hdc
= GetDC (infoPtr
->hwndSelf
);
1651 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1652 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1655 TRACE("Begin tracking item %d!\n", nItem
);
1664 HEADER_LButtonUp (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1673 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1675 if (infoPtr
->bPressed
) {
1677 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1679 if (infoPtr
->bDragging
)
1681 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1684 ImageList_DragShowNolock(FALSE
);
1685 ImageList_EndDrag();
1687 if (infoPtr
->iHotDivider
== -1)
1689 else if (infoPtr
->iHotDivider
== infoPtr
->uNumItem
)
1690 iNewOrder
= infoPtr
->uNumItem
-1;
1693 iNewOrder
= HEADER_IndexToOrder(infoPtr
, infoPtr
->iHotDivider
);
1694 if (iNewOrder
> lpItem
->iOrder
)
1698 if (iNewOrder
!= -1 &&
1699 !HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ENDDRAG
, infoPtr
->iMoveItem
, HDI_ORDER
, iNewOrder
))
1701 HEADER_ChangeItemOrder(infoPtr
, infoPtr
->iMoveItem
, iNewOrder
);
1702 infoPtr
->bRectsValid
= FALSE
;
1703 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1706 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->items
[infoPtr
->iMoveItem
].rect
, FALSE
);
1708 infoPtr
->bDragging
= FALSE
;
1709 HEADER_SetHotDivider(infoPtr
, FALSE
, -1);
1713 hdc
= GetDC (infoPtr
->hwndSelf
);
1714 HEADER_RefreshItem (infoPtr
, infoPtr
->iMoveItem
);
1715 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1717 if (!(infoPtr
->dwStyle
& HDS_DRAGDROP
) || !HEADER_IsDragDistance(infoPtr
, &pt
))
1718 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCLICKW
, infoPtr
->iMoveItem
, NULL
);
1721 TRACE("Released item %d!\n", infoPtr
->iMoveItem
);
1722 infoPtr
->bPressed
= FALSE
;
1724 else if (infoPtr
->bTracking
) {
1725 INT iNewWidth
= pt
.x
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
+ infoPtr
->xTrackOffset
;
1728 TRACE("End tracking item %d!\n", infoPtr
->iMoveItem
);
1729 infoPtr
->bTracking
= FALSE
;
1731 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ENDTRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
);
1733 if (!(infoPtr
->dwStyle
& HDS_FULLDRAG
)) {
1734 hdc
= GetDC (infoPtr
->hwndSelf
);
1735 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1736 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1739 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
))
1741 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= iNewWidth
;
1742 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
);
1745 HEADER_SetItemBounds (infoPtr
);
1746 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1749 if (infoPtr
->bCaptured
) {
1750 infoPtr
->bCaptured
= FALSE
;
1752 HEADER_SendSimpleNotify (infoPtr
, NM_RELEASEDCAPTURE
);
1760 HEADER_NotifyFormat (HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1765 return infoPtr
->nNotifyFormat
;
1768 infoPtr
->nNotifyFormat
=
1769 SendMessageW ((HWND
)wParam
, WM_NOTIFYFORMAT
,
1770 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
1771 return infoPtr
->nNotifyFormat
;
1778 HEADER_MouseLeave (HEADER_INFO
*infoPtr
)
1780 /* Reset hot-tracked item when mouse leaves control. */
1781 INT oldHotItem
= infoPtr
->iHotItem
;
1782 HDC hdc
= GetDC (infoPtr
->hwndSelf
);
1784 infoPtr
->iHotItem
= -1;
1785 if (oldHotItem
!= -1) HEADER_RefreshItem (infoPtr
, oldHotItem
);
1786 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1793 HEADER_MouseMove (HEADER_INFO
*infoPtr
, LPARAM lParam
)
1799 /* With theming, hottracking is always enabled */
1800 BOOL hotTrackEnabled
=
1801 ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (infoPtr
->dwStyle
& HDS_HOTTRACK
))
1802 || (GetWindowTheme (infoPtr
->hwndSelf
) != NULL
);
1803 INT oldHotItem
= infoPtr
->iHotItem
;
1805 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1806 pt
.y
= (INT
)(SHORT
)HIWORD(lParam
);
1807 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1809 if (hotTrackEnabled
) {
1810 if (flags
& (HHT_ONHEADER
| HHT_ONDIVIDER
| HHT_ONDIVOPEN
))
1811 infoPtr
->iHotItem
= nItem
;
1813 infoPtr
->iHotItem
= -1;
1816 if (infoPtr
->bCaptured
) {
1817 /* check if we should drag the header */
1818 if (infoPtr
->bPressed
&& !infoPtr
->bDragging
&& (infoPtr
->dwStyle
& HDS_DRAGDROP
)
1819 && HEADER_IsDragDistance(infoPtr
, &pt
))
1821 if (!HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_BEGINDRAG
, infoPtr
->iMoveItem
, NULL
))
1823 HIMAGELIST hDragItem
= (HIMAGELIST
)HEADER_CreateDragImage(infoPtr
, infoPtr
->iMoveItem
);
1824 if (hDragItem
!= NULL
)
1826 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1827 TRACE("Starting item drag\n");
1828 ImageList_BeginDrag(hDragItem
, 0, pt
.x
- lpItem
->rect
.left
, 0);
1829 ImageList_DragShowNolock(TRUE
);
1830 ImageList_Destroy(hDragItem
);
1831 infoPtr
->bDragging
= TRUE
;
1836 if (infoPtr
->bDragging
)
1841 ClientToScreen(infoPtr
->hwndSelf
, &drag
);
1842 ImageList_DragMove(drag
.x
, drag
.y
);
1843 HEADER_SetHotDivider(infoPtr
, TRUE
, lParam
);
1846 if (infoPtr
->bPressed
&& !infoPtr
->bDragging
) {
1847 BOOL oldState
= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
;
1848 if ((nItem
== infoPtr
->iMoveItem
) && (flags
== HHT_ONHEADER
))
1849 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= TRUE
;
1851 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1852 if (oldState
!= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
) {
1853 hdc
= GetDC (infoPtr
->hwndSelf
);
1854 HEADER_RefreshItem (infoPtr
, infoPtr
->iMoveItem
);
1855 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1858 TRACE("Moving pressed item %d!\n", infoPtr
->iMoveItem
);
1860 else if (infoPtr
->bTracking
) {
1861 if (infoPtr
->dwStyle
& HDS_FULLDRAG
) {
1862 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1863 nWidth
= pt
.x
- lpItem
->rect
.left
+ infoPtr
->xTrackOffset
;
1864 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, nWidth
))
1866 INT nOldWidth
= lpItem
->rect
.right
- lpItem
->rect
.left
;
1870 if (nWidth
< 0) nWidth
= 0;
1871 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= nWidth
;
1872 HEADER_SetItemBounds(infoPtr
);
1874 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1875 rcScroll
= rcClient
;
1876 rcScroll
.left
= lpItem
->rect
.left
+ nOldWidth
;
1877 ScrollWindowEx(infoPtr
->hwndSelf
, nWidth
- nOldWidth
, 0, &rcScroll
, &rcClient
, NULL
, NULL
, 0);
1878 InvalidateRect(infoPtr
->hwndSelf
, &lpItem
->rect
, FALSE
);
1879 UpdateWindow(infoPtr
->hwndSelf
);
1881 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, nWidth
);
1886 hdc
= GetDC (infoPtr
->hwndSelf
);
1887 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1888 infoPtr
->xOldTrack
= pt
.x
+ infoPtr
->xTrackOffset
;
1889 if (infoPtr
->xOldTrack
< infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
)
1890 infoPtr
->xOldTrack
= infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1891 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1892 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1893 iTrackWidth
= infoPtr
->xOldTrack
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1894 /* FIXME: should stop tracking if HDN_TRACK returns TRUE */
1895 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_TRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iTrackWidth
);
1898 TRACE("Tracking item %d!\n", infoPtr
->iMoveItem
);
1902 if (hotTrackEnabled
) {
1903 TRACKMOUSEEVENT tme
;
1904 if (oldHotItem
!= infoPtr
->iHotItem
&& !infoPtr
->bDragging
) {
1905 hdc
= GetDC (infoPtr
->hwndSelf
);
1906 if (oldHotItem
!= -1) HEADER_RefreshItem (infoPtr
, oldHotItem
);
1907 if (infoPtr
->iHotItem
!= -1) HEADER_RefreshItem (infoPtr
, infoPtr
->iHotItem
);
1908 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1910 tme
.cbSize
= sizeof( tme
);
1911 tme
.dwFlags
= TME_LEAVE
;
1912 tme
.hwndTrack
= infoPtr
->hwndSelf
;
1913 TrackMouseEvent( &tme
);
1921 HEADER_Paint (HEADER_INFO
*infoPtr
, HDC hdcParam
)
1926 hdc
= hdcParam
==0 ? BeginPaint (infoPtr
->hwndSelf
, &ps
) : hdcParam
;
1927 HEADER_Refresh (infoPtr
, hdc
);
1929 EndPaint (infoPtr
->hwndSelf
, &ps
);
1935 HEADER_RButtonUp (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1943 /* Send a Notify message */
1944 bRet
= HEADER_SendSimpleNotify (infoPtr
, NM_RCLICK
);
1946 /* Change to screen coordinate for WM_CONTEXTMENU */
1947 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
1949 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1950 SendMessageW( infoPtr
->hwndSelf
, WM_CONTEXTMENU
, (WPARAM
) infoPtr
->hwndSelf
, MAKELPARAM(pt
.x
, pt
.y
));
1957 HEADER_SetCursor (HEADER_INFO
*infoPtr
, LPARAM lParam
)
1963 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam
), HIWORD(lParam
));
1966 ScreenToClient (infoPtr
->hwndSelf
, &pt
);
1968 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1970 if (flags
== HHT_ONDIVIDER
)
1971 SetCursor (infoPtr
->hcurDivider
);
1972 else if (flags
== HHT_ONDIVOPEN
)
1973 SetCursor (infoPtr
->hcurDivopen
);
1975 SetCursor (infoPtr
->hcurArrow
);
1982 HEADER_SetFont (HEADER_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
1988 infoPtr
->hFont
= hFont
;
1991 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
));
1992 GetTextMetricsW (hdc
, &tm
);
1993 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
1994 SelectObject (hdc
, hOldFont
);
1997 infoPtr
->bRectsValid
= FALSE
;
2000 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
2006 static LRESULT
HEADER_SetRedraw(HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
2008 /* ignoring the InvalidateRect calls is handled by user32. But some apps expect
2009 * that we invalidate the header and this has to be done manually */
2012 ret
= DefWindowProcW(infoPtr
->hwndSelf
, WM_SETREDRAW
, wParam
, lParam
);
2014 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
2018 static INT
HEADER_StyleChanged(HEADER_INFO
*infoPtr
, WPARAM wStyleType
,
2019 const STYLESTRUCT
*lpss
)
2021 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
2022 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
2024 if (wStyleType
!= GWL_STYLE
) return 0;
2026 infoPtr
->dwStyle
= lpss
->styleNew
;
2031 /* Update the theme handle after a theme change */
2032 static LRESULT
HEADER_ThemeChanged(const HEADER_INFO
*infoPtr
)
2034 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
2035 CloseThemeData(theme
);
2036 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
2037 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
2042 static LRESULT WINAPI
2043 HEADER_WindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2045 HEADER_INFO
*infoPtr
= (HEADER_INFO
*)GetWindowLongPtrW(hwnd
, 0);
2047 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, msg
, wParam
, lParam
);
2048 if (!infoPtr
&& (msg
!= WM_CREATE
))
2049 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
2051 /* case HDM_CLEARFILTER: */
2053 case HDM_CREATEDRAGIMAGE
:
2054 return HEADER_CreateDragImage (infoPtr
, (INT
)wParam
);
2056 case HDM_DELETEITEM
:
2057 return HEADER_DeleteItem (infoPtr
, (INT
)wParam
);
2059 /* case HDM_EDITFILTER: */
2061 case HDM_GETBITMAPMARGIN
:
2062 return HEADER_GetBitmapMargin(infoPtr
);
2064 case HDM_GETIMAGELIST
:
2065 return HEADER_GetImageList (infoPtr
);
2069 return HEADER_GetItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_GETITEMW
);
2071 case HDM_GETITEMCOUNT
:
2072 return HEADER_GetItemCount (infoPtr
);
2074 case HDM_GETITEMRECT
:
2075 return HEADER_GetItemRect (infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
2077 case HDM_GETORDERARRAY
:
2078 return HEADER_GetOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
2080 case HDM_GETUNICODEFORMAT
:
2081 return HEADER_GetUnicodeFormat (infoPtr
);
2084 return HEADER_HitTest (infoPtr
, (LPHDHITTESTINFO
)lParam
);
2086 case HDM_INSERTITEMA
:
2087 case HDM_INSERTITEMW
:
2088 return HEADER_InsertItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_INSERTITEMW
);
2091 return HEADER_Layout (infoPtr
, (LPHDLAYOUT
)lParam
);
2093 case HDM_ORDERTOINDEX
:
2094 return HEADER_OrderToIndex(infoPtr
, (INT
)wParam
);
2096 case HDM_SETBITMAPMARGIN
:
2097 return HEADER_SetBitmapMargin(infoPtr
, (INT
)wParam
);
2099 /* case HDM_SETFILTERCHANGETIMEOUT: */
2101 case HDM_SETHOTDIVIDER
:
2102 return HEADER_SetHotDivider(infoPtr
, wParam
, lParam
);
2104 case HDM_SETIMAGELIST
:
2105 return HEADER_SetImageList (infoPtr
, (HIMAGELIST
)lParam
);
2109 return HEADER_SetItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_SETITEMW
);
2111 case HDM_SETORDERARRAY
:
2112 return HEADER_SetOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
2114 case HDM_SETUNICODEFORMAT
:
2115 return HEADER_SetUnicodeFormat (infoPtr
, wParam
);
2118 return HEADER_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
2121 return HEADER_Destroy (infoPtr
);
2124 return HEADER_NCDestroy (infoPtr
);
2130 return DLGC_WANTTAB
| DLGC_WANTARROWS
;
2133 return HEADER_GetFont (infoPtr
);
2135 case WM_LBUTTONDBLCLK
:
2136 return HEADER_LButtonDblClk (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2138 case WM_LBUTTONDOWN
:
2139 return HEADER_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2142 return HEADER_LButtonUp (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2145 return HEADER_MouseLeave (infoPtr
);
2148 return HEADER_MouseMove (infoPtr
, lParam
);
2150 case WM_NOTIFYFORMAT
:
2151 return HEADER_NotifyFormat (infoPtr
, wParam
, lParam
);
2154 return HEADER_Size (infoPtr
);
2156 case WM_THEMECHANGED
:
2157 return HEADER_ThemeChanged (infoPtr
);
2159 case WM_PRINTCLIENT
:
2161 return HEADER_Paint (infoPtr
, (HDC
)wParam
);
2164 return HEADER_RButtonUp (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2167 return HEADER_SetCursor (infoPtr
, lParam
);
2170 return HEADER_SetFont (infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
2173 return HEADER_SetRedraw(infoPtr
, wParam
, lParam
);
2175 case WM_STYLECHANGED
:
2176 return HEADER_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
2178 case WM_SYSCOLORCHANGE
:
2179 COMCTL32_RefreshSysColors();
2183 if ((msg
>= WM_USER
) && (msg
< WM_APP
) && !COMCTL32_IsReflectedMessage(msg
))
2184 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
2185 msg
, wParam
, lParam
);
2186 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
2192 HEADER_Register (void)
2196 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2197 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
2198 wndClass
.lpfnWndProc
= HEADER_WindowProc
;
2199 wndClass
.cbClsExtra
= 0;
2200 wndClass
.cbWndExtra
= sizeof(HEADER_INFO
*);
2201 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2202 wndClass
.lpszClassName
= WC_HEADERW
;
2204 RegisterClassW (&wndClass
);
2209 HEADER_Unregister (void)
2211 UnregisterClassW (WC_HEADERW
, NULL
);