4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2003 Maxime Bellenge
7 * Copyright 2006 Mikolaj Zalewski
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 * - Imagelist support (completed?)
25 * - Hottrack support (completed?)
26 * - Filters support (HDS_FILTER, HDI_FILTER, HDM_*FILTER*, HDN_*FILTER*)
27 * - New Windows Vista features
36 #include "wine/unicode.h"
42 #include "imagelist.h"
45 #include "wine/debug.h"
47 WINE_DEFAULT_DEBUG_CHANNEL(header
);
57 INT iOrder
; /* see documentation of HD_ITEM */
59 BOOL bDown
; /* is item pressed? (used for drawing) */
60 RECT rect
; /* bounding rectangle of the item */
61 DWORD callbackMask
; /* HDI_* flags for items that are callback */
67 HWND hwndSelf
; /* Control window */
68 HWND hwndNotify
; /* Owner window to send notifications to */
69 INT nNotifyFormat
; /* format used for WM_NOTIFY messages */
70 UINT uNumItem
; /* number of items (columns) */
71 INT nHeight
; /* height of the header (pixels) */
72 HFONT hFont
; /* handle to the current font */
73 HCURSOR hcurArrow
; /* handle to the arrow cursor */
74 HCURSOR hcurDivider
; /* handle to a cursor (used over dividers) <-|-> */
75 HCURSOR hcurDivopen
; /* handle to a cursor (used over dividers) <-||-> */
76 BOOL bCaptured
; /* Is the mouse captured? */
77 BOOL bPressed
; /* Is a header item pressed (down)? */
78 BOOL bDragging
; /* Are we dragging an item? */
79 BOOL bTracking
; /* Is in tracking mode? */
80 POINT ptLButtonDown
; /* The point where the left button was pressed */
81 DWORD dwStyle
; /* the cached window GWL_STYLE */
82 INT iMoveItem
; /* index of tracked item. (Tracking mode) */
83 INT xTrackOffset
; /* distance between the right side of the tracked item and the cursor */
84 INT xOldTrack
; /* track offset (see above) after the last WM_MOUSEMOVE */
85 INT iHotItem
; /* index of hot item (cursor is over this item) */
86 INT iHotDivider
; /* index of the hot divider (used while dragging an item or by HDM_SETHOTDIVIDER) */
87 INT iMargin
; /* width of the margin that surrounds a bitmap */
89 HIMAGELIST himl
; /* handle to an image list (may be 0) */
90 HEADER_ITEM
*items
; /* pointer to array of HEADER_ITEM's */
91 INT
*order
; /* array of item IDs indexed by order */
92 BOOL bRectsValid
; /* validity flag for bounding rectangles */
97 #define DIVIDER_WIDTH 10
98 #define HOT_DIVIDER_WIDTH 2
99 #define MAX_HEADER_TEXT_LEN 260
100 #define HDN_UNICODE_OFFSET 20
101 #define HDN_FIRST_UNICODE (HDN_FIRST-HDN_UNICODE_OFFSET)
103 #define HDI_SUPPORTED_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP|HDI_IMAGE|HDI_ORDER)
104 #define HDI_UNSUPPORTED_FIELDS (HDI_FILTER)
105 #define HDI_UNKNOWN_FIELDS (~(HDI_SUPPORTED_FIELDS|HDI_UNSUPPORTED_FIELDS|HDI_DI_SETITEM))
106 #define HDI_COMCTL32_4_0_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP)
109 static BOOL
HEADER_PrepareCallbackItems(const HEADER_INFO
*infoPtr
, INT iItem
, INT reqMask
);
110 static void HEADER_FreeCallbackItems(HEADER_ITEM
*lpItem
);
111 static LRESULT
HEADER_SendNotify(const HEADER_INFO
*infoPtr
, UINT code
, NMHDR
*hdr
);
112 static LRESULT
HEADER_SendCtrlCustomDraw(const HEADER_INFO
*infoPtr
, DWORD dwDrawStage
, HDC hdc
, const RECT
*rect
);
114 static const WCHAR themeClass
[] = {'H','e','a','d','e','r',0};
116 static void HEADER_StoreHDItemInHeader(HEADER_ITEM
*lpItem
, UINT mask
, const HDITEMW
*phdi
, BOOL fUnicode
)
118 if (mask
& HDI_UNSUPPORTED_FIELDS
)
119 FIXME("unsupported header fields %x\n", (mask
& HDI_UNSUPPORTED_FIELDS
));
121 if (mask
& HDI_BITMAP
)
122 lpItem
->hbm
= phdi
->hbm
;
124 if (mask
& HDI_FORMAT
)
125 lpItem
->fmt
= phdi
->fmt
;
127 if (mask
& HDI_LPARAM
)
128 lpItem
->lParam
= phdi
->lParam
;
130 if (mask
& HDI_WIDTH
)
131 lpItem
->cxy
= phdi
->cxy
;
133 if (mask
& HDI_IMAGE
)
135 lpItem
->iImage
= phdi
->iImage
;
136 if (phdi
->iImage
== I_IMAGECALLBACK
)
137 lpItem
->callbackMask
|= HDI_IMAGE
;
139 lpItem
->callbackMask
&= ~HDI_IMAGE
;
144 Free(lpItem
->pszText
);
145 lpItem
->pszText
= NULL
;
147 if (phdi
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers != TEXTCALLBACKA too */
149 static const WCHAR emptyString
[] = {0};
151 LPCWSTR pszText
= (phdi
->pszText
!= NULL
? phdi
->pszText
: emptyString
);
153 Str_SetPtrW(&lpItem
->pszText
, pszText
);
155 Str_SetPtrAtoW(&lpItem
->pszText
, (LPCSTR
)pszText
);
156 lpItem
->callbackMask
&= ~HDI_TEXT
;
160 lpItem
->pszText
= NULL
;
161 lpItem
->callbackMask
|= HDI_TEXT
;
166 static inline LRESULT
167 HEADER_IndexToOrder (const HEADER_INFO
*infoPtr
, INT iItem
)
169 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
170 return lpItem
->iOrder
;
175 HEADER_OrderToIndex(const HEADER_INFO
*infoPtr
, INT iorder
)
177 if ((iorder
<0) || iorder
>= infoPtr
->uNumItem
)
179 return infoPtr
->order
[iorder
];
183 HEADER_ChangeItemOrder(const HEADER_INFO
*infoPtr
, INT iItem
, INT iNewOrder
)
185 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
188 TRACE("%d: %d->%d\n", iItem
, lpItem
->iOrder
, iNewOrder
);
189 if (lpItem
->iOrder
< iNewOrder
)
191 memmove(&infoPtr
->order
[lpItem
->iOrder
],
192 &infoPtr
->order
[lpItem
->iOrder
+ 1],
193 (iNewOrder
- lpItem
->iOrder
) * sizeof(INT
));
195 if (iNewOrder
< lpItem
->iOrder
)
197 memmove(&infoPtr
->order
[iNewOrder
+ 1],
198 &infoPtr
->order
[iNewOrder
],
199 (lpItem
->iOrder
- iNewOrder
) * sizeof(INT
));
201 infoPtr
->order
[iNewOrder
] = iItem
;
202 nMin
= min(lpItem
->iOrder
, iNewOrder
);
203 nMax
= max(lpItem
->iOrder
, iNewOrder
);
204 for (i
= nMin
; i
<= nMax
; i
++)
205 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
208 /* Note: if iItem is the last item then this function returns infoPtr->uNumItem */
210 HEADER_NextItem(const HEADER_INFO
*infoPtr
, INT iItem
)
212 return HEADER_OrderToIndex(infoPtr
, HEADER_IndexToOrder(infoPtr
, iItem
)+1);
216 HEADER_PrevItem(const HEADER_INFO
*infoPtr
, INT iItem
)
218 return HEADER_OrderToIndex(infoPtr
, HEADER_IndexToOrder(infoPtr
, iItem
)-1);
222 HEADER_SetItemBounds (HEADER_INFO
*infoPtr
)
229 infoPtr
->bRectsValid
= TRUE
;
231 if (infoPtr
->uNumItem
== 0)
234 GetClientRect (infoPtr
->hwndSelf
, &rect
);
237 for (i
= 0; i
< infoPtr
->uNumItem
; i
++) {
238 phdi
= &infoPtr
->items
[HEADER_OrderToIndex(infoPtr
,i
)];
239 phdi
->rect
.top
= rect
.top
;
240 phdi
->rect
.bottom
= rect
.bottom
;
242 phdi
->rect
.right
= phdi
->rect
.left
+ ((phdi
->cxy
>0)?phdi
->cxy
:0);
243 x
= phdi
->rect
.right
;
248 HEADER_Size (HEADER_INFO
*infoPtr
)
250 HEADER_SetItemBounds(infoPtr
);
254 static void HEADER_GetHotDividerRect(const HEADER_INFO
*infoPtr
, RECT
*r
)
256 INT iDivider
= infoPtr
->iHotDivider
;
257 if (infoPtr
->uNumItem
> 0)
261 if (iDivider
< infoPtr
->uNumItem
)
263 lpItem
= &infoPtr
->items
[iDivider
];
264 r
->left
= lpItem
->rect
.left
- HOT_DIVIDER_WIDTH
/2;
265 r
->right
= lpItem
->rect
.left
+ HOT_DIVIDER_WIDTH
/2;
269 lpItem
= &infoPtr
->items
[HEADER_OrderToIndex(infoPtr
, infoPtr
->uNumItem
-1)];
270 r
->left
= lpItem
->rect
.right
- HOT_DIVIDER_WIDTH
/2;
271 r
->right
= lpItem
->rect
.right
+ HOT_DIVIDER_WIDTH
/2;
273 r
->top
= lpItem
->rect
.top
;
274 r
->bottom
= lpItem
->rect
.bottom
;
279 GetClientRect(infoPtr
->hwndSelf
, &clientRect
);
281 r
->right
= r
->left
+ HOT_DIVIDER_WIDTH
/2;
287 HEADER_DrawItem (HEADER_INFO
*infoPtr
, HDC hdc
, INT iItem
, BOOL bHotTrack
, LRESULT lCDFlags
)
289 HEADER_ITEM
*phdi
= &infoPtr
->items
[iItem
];
292 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
295 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem
, bHotTrack
, (infoPtr
->nNotifyFormat
== NFR_UNICODE
));
298 if (r
.right
- r
.left
== 0)
299 return phdi
->rect
.right
;
301 /* Set the colors before sending NM_CUSTOMDRAW so that it can change them */
302 SetTextColor(hdc
, (bHotTrack
&& !theme
) ? COLOR_HIGHLIGHT
: COLOR_BTNTEXT
);
303 SetBkColor(hdc
, comctl32_color
.clr3dFace
);
305 if (lCDFlags
& CDRF_NOTIFYITEMDRAW
&& !(phdi
->fmt
& HDF_OWNERDRAW
))
307 LRESULT lCDItemFlags
;
309 nmcd
.dwDrawStage
= CDDS_PREPAINT
| CDDS_ITEM
;
311 nmcd
.dwItemSpec
= iItem
;
313 nmcd
.uItemState
= phdi
->bDown
? CDIS_SELECTED
: 0;
314 nmcd
.lItemlParam
= phdi
->lParam
;
316 lCDItemFlags
= HEADER_SendNotify(infoPtr
, NM_CUSTOMDRAW
, (NMHDR
*)&nmcd
);
317 if (lCDItemFlags
& CDRF_SKIPDEFAULT
)
318 return phdi
->rect
.right
;
322 int state
= (phdi
->bDown
) ? HIS_PRESSED
:
323 (bHotTrack
? HIS_HOT
: HIS_NORMAL
);
324 DrawThemeBackground (theme
, hdc
, HP_HEADERITEM
, state
,
326 GetThemeBackgroundContentRect (theme
, hdc
, HP_HEADERITEM
, state
,
332 if (!(infoPtr
->dwStyle
& HDS_FLAT
))
334 if (infoPtr
->dwStyle
& HDS_BUTTONS
) {
336 DrawEdge (hdc
, &r
, BDR_RAISEDOUTER
,
337 BF_RECT
| BF_FLAT
| BF_MIDDLE
| BF_ADJUST
);
340 DrawEdge (hdc
, &r
, EDGE_RAISED
,
341 BF_RECT
| BF_SOFT
| BF_MIDDLE
| BF_ADJUST
);
344 DrawEdge (hdc
, &r
, EDGE_ETCHED
, BF_BOTTOM
| BF_RIGHT
| BF_ADJUST
);
347 hbr
= CreateSolidBrush(GetBkColor(hdc
));
348 FillRect(hdc
, &r
, hbr
);
356 if (phdi
->fmt
& HDF_OWNERDRAW
) {
359 dis
.CtlType
= ODT_HEADER
;
360 dis
.CtlID
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
362 dis
.itemAction
= ODA_DRAWENTIRE
;
363 dis
.itemState
= phdi
->bDown
? ODS_SELECTED
: 0;
364 dis
.hwndItem
= infoPtr
->hwndSelf
;
366 dis
.rcItem
= phdi
->rect
;
367 dis
.itemData
= phdi
->lParam
;
368 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
369 SendMessageW (infoPtr
->hwndNotify
, WM_DRAWITEM
,
370 (WPARAM
)dis
.CtlID
, (LPARAM
)&dis
);
371 if (oldBkMode
!= TRANSPARENT
)
372 SetBkMode(hdc
, oldBkMode
);
375 UINT rw
, rh
, /* width and height of r */
376 *x
= NULL
, *w
= NULL
; /* x and width of the pic (bmp or img) which is part of cnt */
377 /* cnt,txt,img,bmp */
382 HEADER_PrepareCallbackItems(infoPtr
, iItem
, HDI_TEXT
|HDI_IMAGE
);
383 cw
= tw
= iw
= bw
= 0;
384 rw
= r
.right
- r
.left
;
385 rh
= r
.bottom
- r
.top
;
387 if (phdi
->fmt
& HDF_STRING
) {
390 SetRectEmpty(&textRect
);
391 DrawTextW (hdc
, phdi
->pszText
, -1,
392 &textRect
, DT_LEFT
|DT_VCENTER
|DT_SINGLELINE
|DT_CALCRECT
);
393 cw
= textRect
.right
- textRect
.left
+ 2 * infoPtr
->iMargin
;
396 if ((phdi
->fmt
& HDF_IMAGE
) && (infoPtr
->himl
)) {
397 iw
= infoPtr
->himl
->cx
+ 2 * infoPtr
->iMargin
;
402 if ((phdi
->fmt
& HDF_BITMAP
) && (phdi
->hbm
)) {
403 GetObjectW (phdi
->hbm
, sizeof(BITMAP
), &bmp
);
404 bw
= bmp
.bmWidth
+ 2 * infoPtr
->iMargin
;
414 /* align cx using the unclipped cw */
415 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_LEFT
)
417 else if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_CENTER
)
418 cx
= r
.left
+ rw
/ 2 - cw
/ 2;
425 if (cx
+ cw
> r
.right
)
428 tx
= cx
+ infoPtr
->iMargin
;
429 /* since cw might have changed we have to recalculate tw */
430 tw
= cw
- infoPtr
->iMargin
* 2;
434 if (phdi
->fmt
& HDF_BITMAP_ON_RIGHT
) {
435 /* put pic behind text */
436 *x
= cx
+ tw
+ infoPtr
->iMargin
* 3;
438 *x
= cx
+ infoPtr
->iMargin
;
439 /* move text behind pic */
445 /* since we're done with the layout we can
446 now calculate the position of bmp which
447 has no influence on alignment and layout
449 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_RIGHT
)
450 bx
= cx
- bw
+ infoPtr
->iMargin
;
452 bx
= cx
+ cw
+ infoPtr
->iMargin
;
456 HDC hClipDC
= GetDC(infoPtr
->hwndSelf
);
457 HRGN hClipRgn
= CreateRectRgn(r
.left
, r
.top
, r
.right
, r
.bottom
);
458 SelectClipRgn(hClipDC
, hClipRgn
);
461 HDC hdcBitmap
= CreateCompatibleDC (hClipDC
);
462 SelectObject (hdcBitmap
, phdi
->hbm
);
463 BitBlt (hClipDC
, bx
, r
.top
+ ((INT
)rh
- bmp
.bmHeight
) / 2,
464 bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
465 DeleteDC (hdcBitmap
);
469 ImageList_DrawEx (infoPtr
->himl
, phdi
->iImage
, hClipDC
,
470 ix
, r
.top
+ ((INT
)rh
- infoPtr
->himl
->cy
) / 2,
471 infoPtr
->himl
->cx
, infoPtr
->himl
->cy
, CLR_DEFAULT
, CLR_DEFAULT
, 0);
474 DeleteObject(hClipRgn
);
475 ReleaseDC(infoPtr
->hwndSelf
, hClipDC
);
478 if (((phdi
->fmt
& HDF_STRING
)
479 || (!(phdi
->fmt
& (HDF_OWNERDRAW
|HDF_STRING
|HDF_BITMAP
|
480 HDF_BITMAP_ON_RIGHT
|HDF_IMAGE
)))) /* no explicit format specified? */
481 && (phdi
->pszText
)) {
482 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
485 DrawTextW (hdc
, phdi
->pszText
, -1,
486 &r
, DT_LEFT
|DT_END_ELLIPSIS
|DT_VCENTER
|DT_SINGLELINE
);
487 if (oldBkMode
!= TRANSPARENT
)
488 SetBkMode(hdc
, oldBkMode
);
490 HEADER_FreeCallbackItems(phdi
);
493 return phdi
->rect
.right
;
497 HEADER_DrawHotDivider(const HEADER_INFO
*infoPtr
, HDC hdc
)
502 HEADER_GetHotDividerRect(infoPtr
, &r
);
503 brush
= CreateSolidBrush(comctl32_color
.clrHighlight
);
504 FillRect(hdc
, &r
, brush
);
509 HEADER_Refresh (HEADER_INFO
*infoPtr
, HDC hdc
)
511 HFONT hFont
, hOldFont
;
517 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
519 if (!infoPtr
->bRectsValid
)
520 HEADER_SetItemBounds(infoPtr
);
522 /* get rect for the bar, adjusted for the border */
523 GetClientRect (infoPtr
->hwndSelf
, &rect
);
524 lCDFlags
= HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_PREPAINT
, hdc
, &rect
);
526 if (infoPtr
->bDragging
)
527 ImageList_DragShowNolock(FALSE
);
529 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
);
530 hOldFont
= SelectObject (hdc
, hFont
);
532 /* draw Background */
533 if (infoPtr
->uNumItem
== 0 && theme
== NULL
) {
534 hbrBk
= GetSysColorBrush(COLOR_3DFACE
);
535 FillRect(hdc
, &rect
, hbrBk
);
539 for (i
= 0; x
<= rect
.right
&& i
< infoPtr
->uNumItem
; i
++) {
540 int idx
= HEADER_OrderToIndex(infoPtr
,i
);
541 if (RectVisible(hdc
, &infoPtr
->items
[idx
].rect
))
542 HEADER_DrawItem(infoPtr
, hdc
, idx
, infoPtr
->iHotItem
== idx
, lCDFlags
);
543 x
= infoPtr
->items
[idx
].rect
.right
;
548 if ((x
<= rect
.right
) && RectVisible(hdc
, &rcRest
) && (infoPtr
->uNumItem
> 0)) {
550 DrawThemeBackground(theme
, hdc
, HP_HEADERITEM
, HIS_NORMAL
, &rcRest
, NULL
);
552 else if (infoPtr
->dwStyle
& HDS_FLAT
) {
553 hbrBk
= GetSysColorBrush(COLOR_3DFACE
);
554 FillRect(hdc
, &rcRest
, hbrBk
);
558 if (infoPtr
->dwStyle
& HDS_BUTTONS
)
559 DrawEdge (hdc
, &rcRest
, EDGE_RAISED
, BF_TOP
|BF_LEFT
|BF_BOTTOM
|BF_SOFT
|BF_MIDDLE
);
561 DrawEdge (hdc
, &rcRest
, EDGE_ETCHED
, BF_BOTTOM
|BF_MIDDLE
);
565 if (infoPtr
->iHotDivider
!= -1)
566 HEADER_DrawHotDivider(infoPtr
, hdc
);
568 if (infoPtr
->bDragging
)
569 ImageList_DragShowNolock(TRUE
);
570 SelectObject (hdc
, hOldFont
);
572 if (lCDFlags
& CDRF_NOTIFYPOSTPAINT
)
573 HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_POSTPAINT
, hdc
, &rect
);
578 HEADER_RefreshItem (HEADER_INFO
*infoPtr
, INT iItem
)
580 if (!infoPtr
->bRectsValid
)
581 HEADER_SetItemBounds(infoPtr
);
583 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->items
[iItem
].rect
, FALSE
);
588 HEADER_InternalHitTest (const HEADER_INFO
*infoPtr
, const POINT
*lpPt
, UINT
*pFlags
, INT
*pItem
)
595 GetClientRect (infoPtr
->hwndSelf
, &rect
);
599 if (PtInRect (&rect
, *lpPt
))
601 if (infoPtr
->uNumItem
== 0) {
602 *pFlags
|= HHT_NOWHERE
;
608 /* somewhere inside */
609 for (iCount
= 0; iCount
< infoPtr
->uNumItem
; iCount
++) {
610 rect
= infoPtr
->items
[iCount
].rect
;
611 width
= rect
.right
- rect
.left
;
616 if (PtInRect (&rect
, *lpPt
)) {
617 if (width
<= 2 * DIVIDER_WIDTH
) {
618 *pFlags
|= HHT_ONHEADER
;
620 TRACE("ON HEADER %d\n", iCount
);
623 if (HEADER_IndexToOrder(infoPtr
, iCount
) > 0) {
625 rcTest
.right
= rcTest
.left
+ DIVIDER_WIDTH
;
626 if (PtInRect (&rcTest
, *lpPt
)) {
628 *pFlags
|= HHT_ONDIVOPEN
;
629 *pItem
= HEADER_PrevItem(infoPtr
, iCount
);
630 TRACE("ON DIVOPEN %d\n", *pItem
);
634 *pFlags
|= HHT_ONDIVIDER
;
635 *pItem
= HEADER_PrevItem(infoPtr
, iCount
);
636 TRACE("ON DIVIDER %d\n", *pItem
);
642 rcTest
.left
= rcTest
.right
- DIVIDER_WIDTH
;
643 if (PtInRect (&rcTest
, *lpPt
)) {
644 *pFlags
|= HHT_ONDIVIDER
;
646 TRACE("ON DIVIDER %d\n", *pItem
);
650 *pFlags
|= HHT_ONHEADER
;
652 TRACE("ON HEADER %d\n", iCount
);
657 /* check for last divider part (on nowhere) */
658 rect
= infoPtr
->items
[infoPtr
->uNumItem
-1].rect
;
659 rect
.left
= rect
.right
;
660 rect
.right
+= DIVIDER_WIDTH
;
661 if (PtInRect (&rect
, *lpPt
)) {
663 *pFlags
|= HHT_ONDIVOPEN
;
664 *pItem
= infoPtr
->uNumItem
- 1;
665 TRACE("ON DIVOPEN %d\n", *pItem
);
669 *pFlags
|= HHT_ONDIVIDER
;
670 *pItem
= infoPtr
->uNumItem
-1;
671 TRACE("ON DIVIDER %d\n", *pItem
);
676 *pFlags
|= HHT_NOWHERE
;
683 if (lpPt
->x
< rect
.left
) {
685 *pFlags
|= HHT_TOLEFT
;
687 else if (lpPt
->x
> rect
.right
) {
689 *pFlags
|= HHT_TORIGHT
;
692 if (lpPt
->y
< rect
.top
) {
694 *pFlags
|= HHT_ABOVE
;
696 else if (lpPt
->y
> rect
.bottom
) {
698 *pFlags
|= HHT_BELOW
;
703 TRACE("flags=0x%X\n", *pFlags
);
709 HEADER_DrawTrackLine (const HEADER_INFO
*infoPtr
, HDC hdc
, INT x
)
715 GetClientRect (infoPtr
->hwndSelf
, &rect
);
717 hOldPen
= SelectObject (hdc
, GetStockObject (BLACK_PEN
));
718 oldRop
= SetROP2 (hdc
, R2_XORPEN
);
719 MoveToEx (hdc
, x
, rect
.top
, NULL
);
720 LineTo (hdc
, x
, rect
.bottom
);
721 SetROP2 (hdc
, oldRop
);
722 SelectObject (hdc
, hOldPen
);
727 * Convert a HDITEM into the correct format (ANSI/Unicode) to send it in a notify
730 * [I] infoPtr : the header that wants to send the notify
731 * [O] dest : The buffer to store the HDITEM for notify. It may be set to a HDITEMA of HDITEMW
732 * [I] src : The source HDITEM. It may be a HDITEMA or HDITEMW
733 * [I] fSourceUnicode : is src a HDITEMW or HDITEMA
734 * [O] ppvScratch : a pointer to a scratch buffer that needs to be freed after
735 * the HDITEM is no longer in use or NULL if none was needed
737 * NOTE: We depend on HDITEMA and HDITEMW having the same structure
739 static void HEADER_CopyHDItemForNotify(const HEADER_INFO
*infoPtr
, HDITEMW
*dest
,
740 const HDITEMW
*src
, BOOL fSourceUnicode
, LPVOID
*ppvScratch
)
745 if (src
->mask
& HDI_TEXT
&& src
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers TEXTCALLBACKA as well */
747 if (fSourceUnicode
&& infoPtr
->nNotifyFormat
!= NFR_UNICODE
)
749 dest
->pszText
= NULL
;
750 Str_SetPtrWtoA((LPSTR
*)&dest
->pszText
, src
->pszText
);
751 *ppvScratch
= dest
->pszText
;
754 if (!fSourceUnicode
&& infoPtr
->nNotifyFormat
== NFR_UNICODE
)
756 dest
->pszText
= NULL
;
757 Str_SetPtrAtoW(&dest
->pszText
, (LPSTR
)src
->pszText
);
758 *ppvScratch
= dest
->pszText
;
763 static UINT
HEADER_NotifyCodeWtoA(UINT code
)
765 /* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
766 if (code
>= HDN_LAST
&& code
<= HDN_FIRST_UNICODE
)
767 return code
+ HDN_UNICODE_OFFSET
;
773 HEADER_SendNotify(const HEADER_INFO
*infoPtr
, UINT code
, NMHDR
*nmhdr
)
775 nmhdr
->hwndFrom
= infoPtr
->hwndSelf
;
776 nmhdr
->idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
779 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
780 nmhdr
->idFrom
, (LPARAM
)nmhdr
);
784 HEADER_SendSimpleNotify (const HEADER_INFO
*infoPtr
, UINT code
)
787 return (BOOL
)HEADER_SendNotify(infoPtr
, code
, &nmhdr
);
791 HEADER_SendCtrlCustomDraw(const HEADER_INFO
*infoPtr
, DWORD dwDrawStage
, HDC hdc
, const RECT
*rect
)
794 nm
.dwDrawStage
= dwDrawStage
;
801 return HEADER_SendNotify(infoPtr
, NM_CUSTOMDRAW
, (NMHDR
*)&nm
);
805 HEADER_SendNotifyWithHDItemT(const HEADER_INFO
*infoPtr
, UINT code
, INT iItem
, HDITEMW
*lpItem
)
809 if (infoPtr
->nNotifyFormat
!= NFR_UNICODE
)
810 code
= HEADER_NotifyCodeWtoA(code
);
813 nmhdr
.pitem
= lpItem
;
815 return (BOOL
)HEADER_SendNotify(infoPtr
, code
, (NMHDR
*)&nmhdr
);
819 HEADER_SendNotifyWithIntFieldT(const HEADER_INFO
*infoPtr
, UINT code
, INT iItem
, INT mask
, INT iValue
)
823 /* copying only the iValue should be ok but to make the code more robust we copy everything */
824 nmitem
.cxy
= infoPtr
->items
[iItem
].cxy
;
825 nmitem
.hbm
= infoPtr
->items
[iItem
].hbm
;
826 nmitem
.pszText
= NULL
;
827 nmitem
.cchTextMax
= 0;
828 nmitem
.fmt
= infoPtr
->items
[iItem
].fmt
;
829 nmitem
.lParam
= infoPtr
->items
[iItem
].lParam
;
830 nmitem
.iOrder
= infoPtr
->items
[iItem
].iOrder
;
831 nmitem
.iImage
= infoPtr
->items
[iItem
].iImage
;
840 nmitem
.iOrder
= iValue
;
843 ERR("invalid mask value 0x%x\n", iValue
);
846 return HEADER_SendNotifyWithHDItemT(infoPtr
, code
, iItem
, &nmitem
);
850 * Prepare callback items
851 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
852 * (so we handle the two cases only doing a specific cast for pszText).
853 * Checks if any of the required field are callback. If there are sends a
854 * NMHDISPINFO notify to retrieve these items. The items are stored in the
855 * HEADER_ITEM pszText and iImage fields. They should be freed with
856 * HEADER_FreeCallbackItems.
858 * @param hwnd : hwnd header container handler
859 * @param iItem : the header item id
860 * @param reqMask : required fields. If any of them is callback this function will fetch it
862 * @return TRUE on success, else FALSE
865 HEADER_PrepareCallbackItems(const HEADER_INFO
*infoPtr
, INT iItem
, INT reqMask
)
867 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
868 DWORD mask
= reqMask
& lpItem
->callbackMask
;
869 NMHDDISPINFOW dispInfo
;
870 void *pvBuffer
= NULL
;
874 if (mask
&HDI_TEXT
&& lpItem
->pszText
!= NULL
)
876 ERR("(): function called without a call to FreeCallbackItems\n");
877 Free(lpItem
->pszText
);
878 lpItem
->pszText
= NULL
;
881 memset(&dispInfo
, 0, sizeof(NMHDDISPINFOW
));
882 dispInfo
.hdr
.hwndFrom
= infoPtr
->hwndSelf
;
883 dispInfo
.hdr
.idFrom
= GetWindowLongPtrW (infoPtr
->hwndSelf
, GWLP_ID
);
884 if (infoPtr
->nNotifyFormat
== NFR_UNICODE
)
886 dispInfo
.hdr
.code
= HDN_GETDISPINFOW
;
888 pvBuffer
= Alloc(MAX_HEADER_TEXT_LEN
* sizeof(WCHAR
));
892 dispInfo
.hdr
.code
= HDN_GETDISPINFOA
;
894 pvBuffer
= Alloc(MAX_HEADER_TEXT_LEN
* sizeof(CHAR
));
896 dispInfo
.pszText
= pvBuffer
;
897 dispInfo
.cchTextMax
= (pvBuffer
!=NULL
?MAX_HEADER_TEXT_LEN
:0);
898 dispInfo
.iItem
= iItem
;
899 dispInfo
.mask
= mask
;
900 dispInfo
.lParam
= lpItem
->lParam
;
902 TRACE("Sending HDN_GETDISPINFO%c\n", infoPtr
->nNotifyFormat
== NFR_UNICODE
?'W':'A');
903 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, dispInfo
.hdr
.idFrom
, (LPARAM
)&dispInfo
);
905 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
907 (infoPtr
->nNotifyFormat
== NFR_UNICODE
? debugstr_w(dispInfo
.pszText
) : (LPSTR
) dispInfo
.pszText
),
908 (void*) dispInfo
.lParam
);
910 if (mask
& HDI_IMAGE
)
911 lpItem
->iImage
= dispInfo
.iImage
;
914 if (infoPtr
->nNotifyFormat
== NFR_UNICODE
)
916 lpItem
->pszText
= pvBuffer
;
918 /* the user might have used his own buffer */
919 if (dispInfo
.pszText
!= lpItem
->pszText
)
920 Str_GetPtrW(dispInfo
.pszText
, lpItem
->pszText
, MAX_HEADER_TEXT_LEN
);
924 Str_SetPtrAtoW(&lpItem
->pszText
, (LPSTR
)dispInfo
.pszText
);
929 if (dispInfo
.mask
& HDI_DI_SETITEM
)
931 /* make the items permanent */
932 lpItem
->callbackMask
&= ~dispInfo
.mask
;
940 * Free the items that might be allocated with HEADER_PrepareCallbackItems
943 * [I] lpItem : the item to free the data
947 HEADER_FreeCallbackItems(HEADER_ITEM
*lpItem
)
949 if (lpItem
->callbackMask
&HDI_TEXT
)
951 Free(lpItem
->pszText
);
952 lpItem
->pszText
= NULL
;
955 if (lpItem
->callbackMask
&HDI_IMAGE
)
956 lpItem
->iImage
= I_IMAGECALLBACK
;
960 HEADER_CreateDragImage (HEADER_INFO
*infoPtr
, INT iItem
)
964 HBITMAP hMemory
, hOldBitmap
;
972 if (iItem
>= infoPtr
->uNumItem
)
975 if (!infoPtr
->bRectsValid
)
976 HEADER_SetItemBounds(infoPtr
);
978 lpItem
= &infoPtr
->items
[iItem
];
979 width
= lpItem
->rect
.right
- lpItem
->rect
.left
;
980 height
= lpItem
->rect
.bottom
- lpItem
->rect
.top
;
982 hDeviceDC
= GetDC(NULL
);
983 hMemoryDC
= CreateCompatibleDC(hDeviceDC
);
984 hMemory
= CreateCompatibleBitmap(hDeviceDC
, width
, height
);
985 ReleaseDC(NULL
, hDeviceDC
);
986 hOldBitmap
= SelectObject(hMemoryDC
, hMemory
);
987 SetViewportOrgEx(hMemoryDC
, -lpItem
->rect
.left
, -lpItem
->rect
.top
, NULL
);
988 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject(SYSTEM_FONT
);
989 SelectObject(hMemoryDC
, hFont
);
991 GetClientRect(infoPtr
->hwndSelf
, &rc
);
992 lCDFlags
= HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_PREPAINT
, hMemoryDC
, &rc
);
993 HEADER_DrawItem(infoPtr
, hMemoryDC
, iItem
, FALSE
, lCDFlags
);
994 if (lCDFlags
& CDRF_NOTIFYPOSTPAINT
)
995 HEADER_SendCtrlCustomDraw(infoPtr
, CDDS_POSTPAINT
, hMemoryDC
, &rc
);
997 hMemory
= SelectObject(hMemoryDC
, hOldBitmap
);
1000 if (hMemory
== NULL
) /* if anything failed */
1003 himl
= ImageList_Create(width
, height
, ILC_COLORDDB
, 1, 1);
1004 ImageList_Add(himl
, hMemory
, NULL
);
1005 DeleteObject(hMemory
);
1006 return (LRESULT
)himl
;
1010 HEADER_SetHotDivider(HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1019 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1021 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &iDivider
);
1023 if (flags
& HHT_TOLEFT
)
1025 else if (flags
& HHT_NOWHERE
|| flags
& HHT_TORIGHT
)
1026 iDivider
= infoPtr
->uNumItem
;
1029 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iDivider
];
1030 if (pt
.x
> (lpItem
->rect
.left
+lpItem
->rect
.right
)/2)
1031 iDivider
= HEADER_NextItem(infoPtr
, iDivider
);
1035 iDivider
= (INT
)lParam
;
1037 /* Note; wParam==FALSE, lParam==-1 is valid and is used to clear the hot divider */
1038 if (iDivider
<-1 || iDivider
>(int)infoPtr
->uNumItem
)
1041 if (iDivider
!= infoPtr
->iHotDivider
)
1043 if (infoPtr
->iHotDivider
!= -1)
1045 HEADER_GetHotDividerRect(infoPtr
, &r
);
1046 InvalidateRect(infoPtr
->hwndSelf
, &r
, FALSE
);
1048 infoPtr
->iHotDivider
= iDivider
;
1051 HEADER_GetHotDividerRect(infoPtr
, &r
);
1052 InvalidateRect(infoPtr
->hwndSelf
, &r
, FALSE
);
1059 HEADER_DeleteItem (HEADER_INFO
*infoPtr
, INT iItem
)
1064 TRACE("[iItem=%d]\n", iItem
);
1066 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
1069 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1070 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
1072 iOrder
= infoPtr
->items
[iItem
].iOrder
;
1073 Free(infoPtr
->items
[iItem
].pszText
);
1075 infoPtr
->uNumItem
--;
1076 memmove(&infoPtr
->items
[iItem
], &infoPtr
->items
[iItem
+ 1],
1077 (infoPtr
->uNumItem
- iItem
) * sizeof(HEADER_ITEM
));
1078 memmove(&infoPtr
->order
[iOrder
], &infoPtr
->order
[iOrder
+ 1],
1079 (infoPtr
->uNumItem
- iOrder
) * sizeof(INT
));
1080 infoPtr
->items
= ReAlloc(infoPtr
->items
, sizeof(HEADER_ITEM
) * infoPtr
->uNumItem
);
1081 infoPtr
->order
= ReAlloc(infoPtr
->order
, sizeof(INT
) * infoPtr
->uNumItem
);
1083 /* Correct the orders */
1084 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1086 if (infoPtr
->order
[i
] > iItem
)
1087 infoPtr
->order
[i
]--;
1089 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
1091 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1092 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
1094 HEADER_SetItemBounds (infoPtr
);
1095 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1102 HEADER_GetImageList (const HEADER_INFO
*infoPtr
)
1104 return (LRESULT
)infoPtr
->himl
;
1109 HEADER_GetItemT (const HEADER_INFO
*infoPtr
, INT nItem
, LPHDITEMW phdi
, BOOL bUnicode
)
1111 HEADER_ITEM
*lpItem
;
1117 TRACE("[nItem=%d]\n", nItem
);
1123 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
1126 if (mask
& HDI_UNKNOWN_FIELDS
)
1128 TRACE("mask %x contains unknown fields. Using only comctl32 4.0 fields\n", mask
);
1129 mask
&= HDI_COMCTL32_4_0_FIELDS
;
1132 lpItem
= &infoPtr
->items
[nItem
];
1133 HEADER_PrepareCallbackItems(infoPtr
, nItem
, mask
);
1135 if (mask
& HDI_BITMAP
)
1136 phdi
->hbm
= lpItem
->hbm
;
1138 if (mask
& HDI_FORMAT
)
1139 phdi
->fmt
= lpItem
->fmt
;
1141 if (mask
& HDI_WIDTH
)
1142 phdi
->cxy
= lpItem
->cxy
;
1144 if (mask
& HDI_LPARAM
)
1145 phdi
->lParam
= lpItem
->lParam
;
1147 if (mask
& HDI_IMAGE
)
1148 phdi
->iImage
= lpItem
->iImage
;
1150 if (mask
& HDI_ORDER
)
1151 phdi
->iOrder
= lpItem
->iOrder
;
1153 if (mask
& HDI_TEXT
)
1156 Str_GetPtrW (lpItem
->pszText
, phdi
->pszText
, phdi
->cchTextMax
);
1158 Str_GetPtrWtoA (lpItem
->pszText
, (LPSTR
)phdi
->pszText
, phdi
->cchTextMax
);
1161 HEADER_FreeCallbackItems(lpItem
);
1166 static inline LRESULT
1167 HEADER_GetItemCount (const HEADER_INFO
*infoPtr
)
1169 return infoPtr
->uNumItem
;
1174 HEADER_GetItemRect (const HEADER_INFO
*infoPtr
, INT iItem
, LPRECT lpRect
)
1176 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
1179 lpRect
->left
= infoPtr
->items
[iItem
].rect
.left
;
1180 lpRect
->right
= infoPtr
->items
[iItem
].rect
.right
;
1181 lpRect
->top
= infoPtr
->items
[iItem
].rect
.top
;
1182 lpRect
->bottom
= infoPtr
->items
[iItem
].rect
.bottom
;
1189 HEADER_GetOrderArray(const HEADER_INFO
*infoPtr
, INT size
, LPINT order
)
1191 if ((UINT
)size
<infoPtr
->uNumItem
)
1194 memcpy(order
, infoPtr
->order
, infoPtr
->uNumItem
* sizeof(INT
));
1199 HEADER_SetOrderArray(HEADER_INFO
*infoPtr
, INT size
, const INT
*order
)
1202 HEADER_ITEM
*lpItem
;
1204 if ((UINT
)size
<infoPtr
->uNumItem
)
1206 memcpy(infoPtr
->order
, order
, infoPtr
->uNumItem
* sizeof(INT
));
1207 for (i
=0; i
<size
; i
++)
1209 lpItem
= &infoPtr
->items
[*order
++];
1212 HEADER_SetItemBounds(infoPtr
);
1213 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1217 static inline LRESULT
1218 HEADER_GetUnicodeFormat (const HEADER_INFO
*infoPtr
)
1220 return (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1225 HEADER_HitTest (const HEADER_INFO
*infoPtr
, LPHDHITTESTINFO phti
)
1227 HEADER_InternalHitTest (infoPtr
, &phti
->pt
, &phti
->flags
, &phti
->iItem
);
1229 if (phti
->flags
== HHT_NOWHERE
)
1237 HEADER_InsertItemT (HEADER_INFO
*infoPtr
, INT nItem
, const HDITEMW
*phdi
, BOOL bUnicode
)
1239 HEADER_ITEM
*lpItem
;
1244 if ((phdi
== NULL
) || (nItem
< 0) || (phdi
->mask
== 0))
1247 if (nItem
> infoPtr
->uNumItem
)
1248 nItem
= infoPtr
->uNumItem
;
1250 iOrder
= (phdi
->mask
& HDI_ORDER
) ? phdi
->iOrder
: nItem
;
1253 else if (infoPtr
->uNumItem
< iOrder
)
1254 iOrder
= infoPtr
->uNumItem
;
1256 infoPtr
->uNumItem
++;
1257 infoPtr
->items
= ReAlloc(infoPtr
->items
, sizeof(HEADER_ITEM
) * infoPtr
->uNumItem
);
1258 infoPtr
->order
= ReAlloc(infoPtr
->order
, sizeof(INT
) * infoPtr
->uNumItem
);
1260 /* make space for the new item */
1261 memmove(&infoPtr
->items
[nItem
+ 1], &infoPtr
->items
[nItem
],
1262 (infoPtr
->uNumItem
- nItem
- 1) * sizeof(HEADER_ITEM
));
1263 memmove(&infoPtr
->order
[iOrder
+ 1], &infoPtr
->order
[iOrder
],
1264 (infoPtr
->uNumItem
- iOrder
- 1) * sizeof(INT
));
1266 /* update the order array */
1267 infoPtr
->order
[iOrder
] = nItem
;
1268 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1270 if (i
!= iOrder
&& infoPtr
->order
[i
] >= nItem
)
1271 infoPtr
->order
[i
]++;
1272 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
1275 lpItem
= &infoPtr
->items
[nItem
];
1276 ZeroMemory(lpItem
, sizeof(HEADER_ITEM
));
1277 /* cxy, fmt and lParam are copied even if not in the HDITEM mask */
1278 copyMask
= phdi
->mask
| HDI_WIDTH
| HDI_FORMAT
| HDI_LPARAM
;
1279 HEADER_StoreHDItemInHeader(lpItem
, copyMask
, phdi
, bUnicode
);
1280 lpItem
->iOrder
= iOrder
;
1282 /* set automatically some format bits */
1283 if (phdi
->mask
& HDI_TEXT
)
1284 lpItem
->fmt
|= HDF_STRING
;
1286 lpItem
->fmt
&= ~HDF_STRING
;
1288 if (lpItem
->hbm
!= NULL
)
1289 lpItem
->fmt
|= HDF_BITMAP
;
1291 lpItem
->fmt
&= ~HDF_BITMAP
;
1293 if (phdi
->mask
& HDI_IMAGE
)
1294 lpItem
->fmt
|= HDF_IMAGE
;
1296 HEADER_SetItemBounds (infoPtr
);
1297 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1304 HEADER_Layout (HEADER_INFO
*infoPtr
, LPHDLAYOUT lpLayout
)
1306 lpLayout
->pwpos
->hwnd
= infoPtr
->hwndSelf
;
1307 lpLayout
->pwpos
->hwndInsertAfter
= 0;
1308 lpLayout
->pwpos
->x
= lpLayout
->prc
->left
;
1309 lpLayout
->pwpos
->y
= lpLayout
->prc
->top
;
1310 lpLayout
->pwpos
->cx
= lpLayout
->prc
->right
- lpLayout
->prc
->left
;
1311 if (infoPtr
->dwStyle
& HDS_HIDDEN
)
1312 lpLayout
->pwpos
->cy
= 0;
1314 lpLayout
->pwpos
->cy
= infoPtr
->nHeight
;
1315 lpLayout
->prc
->top
+= infoPtr
->nHeight
;
1317 lpLayout
->pwpos
->flags
= SWP_NOZORDER
;
1319 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1320 lpLayout
->pwpos
->x
, lpLayout
->pwpos
->y
,
1321 lpLayout
->pwpos
->cx
, lpLayout
->pwpos
->cy
);
1323 infoPtr
->bRectsValid
= FALSE
;
1330 HEADER_SetImageList (HEADER_INFO
*infoPtr
, HIMAGELIST himl
)
1334 TRACE("(himl %p)\n", himl
);
1335 himlOld
= infoPtr
->himl
;
1336 infoPtr
->himl
= himl
;
1338 /* FIXME: Refresh needed??? */
1340 return (LRESULT
)himlOld
;
1345 HEADER_GetBitmapMargin(const HEADER_INFO
*infoPtr
)
1347 return infoPtr
->iMargin
;
1351 HEADER_SetBitmapMargin(HEADER_INFO
*infoPtr
, INT iMargin
)
1353 INT oldMargin
= infoPtr
->iMargin
;
1355 infoPtr
->iMargin
= iMargin
;
1361 HEADER_SetItemT (HEADER_INFO
*infoPtr
, INT nItem
, const HDITEMW
*phdi
, BOOL bUnicode
)
1363 HEADER_ITEM
*lpItem
;
1369 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
1372 TRACE("[nItem=%d]\n", nItem
);
1374 HEADER_CopyHDItemForNotify(infoPtr
, &hdNotify
, phdi
, bUnicode
, &pvScratch
);
1375 if (HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCHANGINGW
, nItem
, &hdNotify
))
1381 lpItem
= &infoPtr
->items
[nItem
];
1382 HEADER_StoreHDItemInHeader(lpItem
, phdi
->mask
, phdi
, bUnicode
);
1384 if (phdi
->mask
& HDI_ORDER
)
1385 if (phdi
->iOrder
>= 0 && phdi
->iOrder
< infoPtr
->uNumItem
)
1386 HEADER_ChangeItemOrder(infoPtr
, nItem
, phdi
->iOrder
);
1388 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCHANGEDW
, nItem
, &hdNotify
);
1390 HEADER_SetItemBounds (infoPtr
);
1392 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1398 static inline LRESULT
1399 HEADER_SetUnicodeFormat (HEADER_INFO
*infoPtr
, WPARAM wParam
)
1401 BOOL bTemp
= (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1403 infoPtr
->nNotifyFormat
= ((BOOL
)wParam
? NFR_UNICODE
: NFR_ANSI
);
1410 HEADER_Create (HWND hwnd
, const CREATESTRUCTW
*lpcs
)
1412 HEADER_INFO
*infoPtr
;
1417 infoPtr
= Alloc (sizeof(HEADER_INFO
));
1418 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1420 infoPtr
->hwndSelf
= hwnd
;
1421 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
1422 infoPtr
->uNumItem
= 0;
1426 infoPtr
->bRectsValid
= FALSE
;
1427 infoPtr
->hcurArrow
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1428 infoPtr
->hcurDivider
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDER
));
1429 infoPtr
->hcurDivopen
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDEROPEN
));
1430 infoPtr
->bPressed
= FALSE
;
1431 infoPtr
->bTracking
= FALSE
;
1432 infoPtr
->dwStyle
= lpcs
->style
;
1433 infoPtr
->iMoveItem
= 0;
1435 infoPtr
->iHotItem
= -1;
1436 infoPtr
->iHotDivider
= -1;
1437 infoPtr
->iMargin
= 3*GetSystemMetrics(SM_CXEDGE
);
1438 infoPtr
->nNotifyFormat
=
1439 SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_QUERY
);
1442 hOldFont
= SelectObject (hdc
, GetStockObject (SYSTEM_FONT
));
1443 GetTextMetricsW (hdc
, &tm
);
1444 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
1445 SelectObject (hdc
, hOldFont
);
1448 OpenThemeData(hwnd
, themeClass
);
1455 HEADER_Destroy (HEADER_INFO
*infoPtr
)
1457 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
1458 CloseThemeData(theme
);
1463 HEADER_NCDestroy (HEADER_INFO
*infoPtr
)
1465 HEADER_ITEM
*lpItem
;
1468 if (infoPtr
->items
) {
1469 lpItem
= infoPtr
->items
;
1470 for (nItem
= 0; nItem
< infoPtr
->uNumItem
; nItem
++, lpItem
++) {
1471 Free(lpItem
->pszText
);
1473 Free (infoPtr
->items
);
1476 Free(infoPtr
->order
);
1479 ImageList_Destroy (infoPtr
->himl
);
1481 SetWindowLongPtrW (infoPtr
->hwndSelf
, 0, 0);
1488 static inline LRESULT
1489 HEADER_GetFont (const HEADER_INFO
*infoPtr
)
1491 return (LRESULT
)infoPtr
->hFont
;
1496 HEADER_IsDragDistance(const HEADER_INFO
*infoPtr
, const POINT
*pt
)
1498 /* Windows allows for a mouse movement before starting the drag. We use the
1499 * SM_CXDOUBLECLICK/SM_CYDOUBLECLICK as that distance.
1501 return (abs(infoPtr
->ptLButtonDown
.x
- pt
->x
)>GetSystemMetrics(SM_CXDOUBLECLK
) ||
1502 abs(infoPtr
->ptLButtonDown
.y
- pt
->y
)>GetSystemMetrics(SM_CYDOUBLECLK
));
1506 HEADER_LButtonDblClk (const HEADER_INFO
*infoPtr
, INT x
, INT y
)
1514 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1516 if ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (flags
== HHT_ONHEADER
))
1517 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMDBLCLICKW
, nItem
, NULL
);
1518 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
))
1519 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_DIVIDERDBLCLICKW
, nItem
, NULL
);
1526 HEADER_LButtonDown (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1535 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1537 if ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (flags
== HHT_ONHEADER
)) {
1538 SetCapture (infoPtr
->hwndSelf
);
1539 infoPtr
->bCaptured
= TRUE
;
1540 infoPtr
->bPressed
= TRUE
;
1541 infoPtr
->bDragging
= FALSE
;
1542 infoPtr
->iMoveItem
= nItem
;
1543 infoPtr
->ptLButtonDown
= pt
;
1545 infoPtr
->items
[nItem
].bDown
= TRUE
;
1547 /* Send WM_CUSTOMDRAW */
1548 hdc
= GetDC (infoPtr
->hwndSelf
);
1549 HEADER_RefreshItem (infoPtr
, nItem
);
1550 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1552 TRACE("Pressed item %d!\n", nItem
);
1554 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
)) {
1555 INT iCurrWidth
= infoPtr
->items
[nItem
].cxy
;
1556 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_BEGINTRACKW
, nItem
, HDI_WIDTH
, iCurrWidth
))
1558 SetCapture (infoPtr
->hwndSelf
);
1559 infoPtr
->bCaptured
= TRUE
;
1560 infoPtr
->bTracking
= TRUE
;
1561 infoPtr
->iMoveItem
= nItem
;
1562 infoPtr
->xTrackOffset
= infoPtr
->items
[nItem
].rect
.right
- pt
.x
;
1564 if (!(infoPtr
->dwStyle
& HDS_FULLDRAG
)) {
1565 infoPtr
->xOldTrack
= infoPtr
->items
[nItem
].rect
.right
;
1566 hdc
= GetDC (infoPtr
->hwndSelf
);
1567 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1568 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1571 TRACE("Begin tracking item %d!\n", nItem
);
1580 HEADER_LButtonUp (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1589 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1591 if (infoPtr
->bPressed
) {
1593 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1595 if (infoPtr
->bDragging
)
1597 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1600 ImageList_DragShowNolock(FALSE
);
1601 ImageList_EndDrag();
1603 if (infoPtr
->iHotDivider
== -1)
1605 else if (infoPtr
->iHotDivider
== infoPtr
->uNumItem
)
1606 iNewOrder
= infoPtr
->uNumItem
-1;
1609 iNewOrder
= HEADER_IndexToOrder(infoPtr
, infoPtr
->iHotDivider
);
1610 if (iNewOrder
> lpItem
->iOrder
)
1614 if (iNewOrder
!= -1 &&
1615 !HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ENDDRAG
, infoPtr
->iMoveItem
, HDI_ORDER
, iNewOrder
))
1617 HEADER_ChangeItemOrder(infoPtr
, infoPtr
->iMoveItem
, iNewOrder
);
1618 infoPtr
->bRectsValid
= FALSE
;
1619 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1622 InvalidateRect(infoPtr
->hwndSelf
, &infoPtr
->items
[infoPtr
->iMoveItem
].rect
, FALSE
);
1624 infoPtr
->bDragging
= FALSE
;
1625 HEADER_SetHotDivider(infoPtr
, FALSE
, -1);
1629 hdc
= GetDC (infoPtr
->hwndSelf
);
1630 HEADER_RefreshItem (infoPtr
, infoPtr
->iMoveItem
);
1631 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1633 if (!(infoPtr
->dwStyle
& HDS_DRAGDROP
) || !HEADER_IsDragDistance(infoPtr
, &pt
))
1634 HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_ITEMCLICKW
, infoPtr
->iMoveItem
, NULL
);
1637 TRACE("Released item %d!\n", infoPtr
->iMoveItem
);
1638 infoPtr
->bPressed
= FALSE
;
1640 else if (infoPtr
->bTracking
) {
1641 INT iNewWidth
= pt
.x
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
+ infoPtr
->xTrackOffset
;
1644 TRACE("End tracking item %d!\n", infoPtr
->iMoveItem
);
1645 infoPtr
->bTracking
= FALSE
;
1647 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ENDTRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
);
1649 if (!(infoPtr
->dwStyle
& HDS_FULLDRAG
)) {
1650 hdc
= GetDC (infoPtr
->hwndSelf
);
1651 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1652 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1655 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
))
1657 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= iNewWidth
;
1658 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iNewWidth
);
1661 HEADER_SetItemBounds (infoPtr
);
1662 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1665 if (infoPtr
->bCaptured
) {
1666 infoPtr
->bCaptured
= FALSE
;
1668 HEADER_SendSimpleNotify (infoPtr
, NM_RELEASEDCAPTURE
);
1676 HEADER_NotifyFormat (HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1681 return infoPtr
->nNotifyFormat
;
1684 infoPtr
->nNotifyFormat
=
1685 SendMessageW ((HWND
)wParam
, WM_NOTIFYFORMAT
,
1686 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)NF_QUERY
);
1687 return infoPtr
->nNotifyFormat
;
1694 HEADER_MouseLeave (HEADER_INFO
*infoPtr
)
1696 /* Reset hot-tracked item when mouse leaves control. */
1697 INT oldHotItem
= infoPtr
->iHotItem
;
1698 HDC hdc
= GetDC (infoPtr
->hwndSelf
);
1700 infoPtr
->iHotItem
= -1;
1701 if (oldHotItem
!= -1) HEADER_RefreshItem (infoPtr
, oldHotItem
);
1702 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1709 HEADER_MouseMove (HEADER_INFO
*infoPtr
, LPARAM lParam
)
1715 /* With theming, hottracking is always enabled */
1716 BOOL hotTrackEnabled
=
1717 ((infoPtr
->dwStyle
& HDS_BUTTONS
) && (infoPtr
->dwStyle
& HDS_HOTTRACK
))
1718 || (GetWindowTheme (infoPtr
->hwndSelf
) != NULL
);
1719 INT oldHotItem
= infoPtr
->iHotItem
;
1721 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1722 pt
.y
= (INT
)(SHORT
)HIWORD(lParam
);
1723 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1725 if (hotTrackEnabled
) {
1726 if (flags
& (HHT_ONHEADER
| HHT_ONDIVIDER
| HHT_ONDIVOPEN
))
1727 infoPtr
->iHotItem
= nItem
;
1729 infoPtr
->iHotItem
= -1;
1732 if (infoPtr
->bCaptured
) {
1733 /* check if we should drag the header */
1734 if (infoPtr
->bPressed
&& !infoPtr
->bDragging
&& (infoPtr
->dwStyle
& HDS_DRAGDROP
)
1735 && HEADER_IsDragDistance(infoPtr
, &pt
))
1737 if (!HEADER_SendNotifyWithHDItemT(infoPtr
, HDN_BEGINDRAG
, infoPtr
->iMoveItem
, NULL
))
1739 HIMAGELIST hDragItem
= (HIMAGELIST
)HEADER_CreateDragImage(infoPtr
, infoPtr
->iMoveItem
);
1740 if (hDragItem
!= NULL
)
1742 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1743 TRACE("Starting item drag\n");
1744 ImageList_BeginDrag(hDragItem
, 0, pt
.x
- lpItem
->rect
.left
, 0);
1745 ImageList_DragShowNolock(TRUE
);
1746 ImageList_Destroy(hDragItem
);
1747 infoPtr
->bDragging
= TRUE
;
1752 if (infoPtr
->bDragging
)
1757 ClientToScreen(infoPtr
->hwndSelf
, &drag
);
1758 ImageList_DragMove(drag
.x
, drag
.y
);
1759 HEADER_SetHotDivider(infoPtr
, TRUE
, lParam
);
1762 if (infoPtr
->bPressed
&& !infoPtr
->bDragging
) {
1763 BOOL oldState
= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
;
1764 if ((nItem
== infoPtr
->iMoveItem
) && (flags
== HHT_ONHEADER
))
1765 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= TRUE
;
1767 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1768 if (oldState
!= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
) {
1769 hdc
= GetDC (infoPtr
->hwndSelf
);
1770 HEADER_RefreshItem (infoPtr
, infoPtr
->iMoveItem
);
1771 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1774 TRACE("Moving pressed item %d!\n", infoPtr
->iMoveItem
);
1776 else if (infoPtr
->bTracking
) {
1777 if (infoPtr
->dwStyle
& HDS_FULLDRAG
) {
1778 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1779 nWidth
= pt
.x
- lpItem
->rect
.left
+ infoPtr
->xTrackOffset
;
1780 if (!HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, nWidth
))
1782 INT nOldWidth
= lpItem
->rect
.right
- lpItem
->rect
.left
;
1786 if (nWidth
< 0) nWidth
= 0;
1787 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= nWidth
;
1788 HEADER_SetItemBounds(infoPtr
);
1790 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
1791 rcScroll
= rcClient
;
1792 rcScroll
.left
= lpItem
->rect
.left
+ nOldWidth
;
1793 ScrollWindowEx(infoPtr
->hwndSelf
, nWidth
- nOldWidth
, 0, &rcScroll
, &rcClient
, NULL
, NULL
, 0);
1794 InvalidateRect(infoPtr
->hwndSelf
, &lpItem
->rect
, FALSE
);
1795 UpdateWindow(infoPtr
->hwndSelf
);
1797 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, nWidth
);
1802 hdc
= GetDC (infoPtr
->hwndSelf
);
1803 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1804 infoPtr
->xOldTrack
= pt
.x
+ infoPtr
->xTrackOffset
;
1805 if (infoPtr
->xOldTrack
< infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
)
1806 infoPtr
->xOldTrack
= infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1807 HEADER_DrawTrackLine (infoPtr
, hdc
, infoPtr
->xOldTrack
);
1808 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1809 iTrackWidth
= infoPtr
->xOldTrack
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1810 /* FIXME: should stop tracking if HDN_TRACK returns TRUE */
1811 HEADER_SendNotifyWithIntFieldT(infoPtr
, HDN_TRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, iTrackWidth
);
1814 TRACE("Tracking item %d!\n", infoPtr
->iMoveItem
);
1818 if (hotTrackEnabled
) {
1819 TRACKMOUSEEVENT tme
;
1820 if (oldHotItem
!= infoPtr
->iHotItem
&& !infoPtr
->bDragging
) {
1821 hdc
= GetDC (infoPtr
->hwndSelf
);
1822 if (oldHotItem
!= -1) HEADER_RefreshItem (infoPtr
, oldHotItem
);
1823 if (infoPtr
->iHotItem
!= -1) HEADER_RefreshItem (infoPtr
, infoPtr
->iHotItem
);
1824 ReleaseDC (infoPtr
->hwndSelf
, hdc
);
1826 tme
.cbSize
= sizeof( tme
);
1827 tme
.dwFlags
= TME_LEAVE
;
1828 tme
.hwndTrack
= infoPtr
->hwndSelf
;
1829 TrackMouseEvent( &tme
);
1837 HEADER_Paint (HEADER_INFO
*infoPtr
, HDC hdcParam
)
1842 hdc
= hdcParam
==0 ? BeginPaint (infoPtr
->hwndSelf
, &ps
) : hdcParam
;
1843 HEADER_Refresh (infoPtr
, hdc
);
1845 EndPaint (infoPtr
->hwndSelf
, &ps
);
1851 HEADER_RButtonUp (HEADER_INFO
*infoPtr
, INT x
, INT y
)
1859 /* Send a Notify message */
1860 bRet
= HEADER_SendSimpleNotify (infoPtr
, NM_RCLICK
);
1862 /* Change to screen coordinate for WM_CONTEXTMENU */
1863 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
1865 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1866 SendMessageW( infoPtr
->hwndSelf
, WM_CONTEXTMENU
, (WPARAM
) infoPtr
->hwndSelf
, MAKELPARAM(pt
.x
, pt
.y
));
1873 HEADER_SetCursor (HEADER_INFO
*infoPtr
, LPARAM lParam
)
1879 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam
), HIWORD(lParam
));
1882 ScreenToClient (infoPtr
->hwndSelf
, &pt
);
1884 HEADER_InternalHitTest (infoPtr
, &pt
, &flags
, &nItem
);
1886 if (flags
== HHT_ONDIVIDER
)
1887 SetCursor (infoPtr
->hcurDivider
);
1888 else if (flags
== HHT_ONDIVOPEN
)
1889 SetCursor (infoPtr
->hcurDivopen
);
1891 SetCursor (infoPtr
->hcurArrow
);
1898 HEADER_SetFont (HEADER_INFO
*infoPtr
, HFONT hFont
, WORD Redraw
)
1904 infoPtr
->hFont
= hFont
;
1907 hOldFont
= SelectObject (hdc
, infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
));
1908 GetTextMetricsW (hdc
, &tm
);
1909 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
1910 SelectObject (hdc
, hOldFont
);
1913 infoPtr
->bRectsValid
= FALSE
;
1916 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1922 static LRESULT
HEADER_SetRedraw(HEADER_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
1924 /* ignoring the InvalidateRect calls is handled by user32. But some apps expect
1925 * that we invalidate the header and this has to be done manually */
1928 ret
= DefWindowProcW(infoPtr
->hwndSelf
, WM_SETREDRAW
, wParam
, lParam
);
1930 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
1934 static INT
HEADER_StyleChanged(HEADER_INFO
*infoPtr
, WPARAM wStyleType
,
1935 const STYLESTRUCT
*lpss
)
1937 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
1938 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
1940 if (wStyleType
!= GWL_STYLE
) return 0;
1942 infoPtr
->dwStyle
= lpss
->styleNew
;
1947 /* Update the theme handle after a theme change */
1948 static LRESULT
HEADER_ThemeChanged(const HEADER_INFO
*infoPtr
)
1950 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
1951 CloseThemeData(theme
);
1952 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
1953 InvalidateRect(infoPtr
->hwndSelf
, NULL
, FALSE
);
1958 static LRESULT WINAPI
1959 HEADER_WindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1961 HEADER_INFO
*infoPtr
= (HEADER_INFO
*)GetWindowLongPtrW(hwnd
, 0);
1963 TRACE("hwnd=%p msg=%x wparam=%lx lParam=%lx\n", hwnd
, msg
, wParam
, lParam
);
1964 if (!infoPtr
&& (msg
!= WM_CREATE
))
1965 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1967 /* case HDM_CLEARFILTER: */
1969 case HDM_CREATEDRAGIMAGE
:
1970 return HEADER_CreateDragImage (infoPtr
, (INT
)wParam
);
1972 case HDM_DELETEITEM
:
1973 return HEADER_DeleteItem (infoPtr
, (INT
)wParam
);
1975 /* case HDM_EDITFILTER: */
1977 case HDM_GETBITMAPMARGIN
:
1978 return HEADER_GetBitmapMargin(infoPtr
);
1980 case HDM_GETIMAGELIST
:
1981 return HEADER_GetImageList (infoPtr
);
1985 return HEADER_GetItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_GETITEMW
);
1987 case HDM_GETITEMCOUNT
:
1988 return HEADER_GetItemCount (infoPtr
);
1990 case HDM_GETITEMRECT
:
1991 return HEADER_GetItemRect (infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
1993 case HDM_GETORDERARRAY
:
1994 return HEADER_GetOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
1996 case HDM_GETUNICODEFORMAT
:
1997 return HEADER_GetUnicodeFormat (infoPtr
);
2000 return HEADER_HitTest (infoPtr
, (LPHDHITTESTINFO
)lParam
);
2002 case HDM_INSERTITEMA
:
2003 case HDM_INSERTITEMW
:
2004 return HEADER_InsertItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_INSERTITEMW
);
2007 return HEADER_Layout (infoPtr
, (LPHDLAYOUT
)lParam
);
2009 case HDM_ORDERTOINDEX
:
2010 return HEADER_OrderToIndex(infoPtr
, (INT
)wParam
);
2012 case HDM_SETBITMAPMARGIN
:
2013 return HEADER_SetBitmapMargin(infoPtr
, (INT
)wParam
);
2015 /* case HDM_SETFILTERCHANGETIMEOUT: */
2017 case HDM_SETHOTDIVIDER
:
2018 return HEADER_SetHotDivider(infoPtr
, wParam
, lParam
);
2020 case HDM_SETIMAGELIST
:
2021 return HEADER_SetImageList (infoPtr
, (HIMAGELIST
)lParam
);
2025 return HEADER_SetItemT (infoPtr
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_SETITEMW
);
2027 case HDM_SETORDERARRAY
:
2028 return HEADER_SetOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
2030 case HDM_SETUNICODEFORMAT
:
2031 return HEADER_SetUnicodeFormat (infoPtr
, wParam
);
2034 return HEADER_Create (hwnd
, (LPCREATESTRUCTW
)lParam
);
2037 return HEADER_Destroy (infoPtr
);
2040 return HEADER_NCDestroy (infoPtr
);
2046 return DLGC_WANTTAB
| DLGC_WANTARROWS
;
2049 return HEADER_GetFont (infoPtr
);
2051 case WM_LBUTTONDBLCLK
:
2052 return HEADER_LButtonDblClk (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2054 case WM_LBUTTONDOWN
:
2055 return HEADER_LButtonDown (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2058 return HEADER_LButtonUp (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2061 return HEADER_MouseLeave (infoPtr
);
2064 return HEADER_MouseMove (infoPtr
, lParam
);
2066 case WM_NOTIFYFORMAT
:
2067 return HEADER_NotifyFormat (infoPtr
, wParam
, lParam
);
2070 return HEADER_Size (infoPtr
);
2072 case WM_THEMECHANGED
:
2073 return HEADER_ThemeChanged (infoPtr
);
2075 case WM_PRINTCLIENT
:
2077 return HEADER_Paint (infoPtr
, (HDC
)wParam
);
2080 return HEADER_RButtonUp (infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
2083 return HEADER_SetCursor (infoPtr
, lParam
);
2086 return HEADER_SetFont (infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
2089 return HEADER_SetRedraw(infoPtr
, wParam
, lParam
);
2091 case WM_STYLECHANGED
:
2092 return HEADER_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
2094 case WM_SYSCOLORCHANGE
:
2095 COMCTL32_RefreshSysColors();
2099 if ((msg
>= WM_USER
) && (msg
< WM_APP
) && !COMCTL32_IsReflectedMessage(msg
))
2100 ERR("unknown msg %04x wp=%04lx lp=%08lx\n",
2101 msg
, wParam
, lParam
);
2102 return DefWindowProcW(hwnd
, msg
, wParam
, lParam
);
2108 HEADER_Register (void)
2112 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2113 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
2114 wndClass
.lpfnWndProc
= HEADER_WindowProc
;
2115 wndClass
.cbClsExtra
= 0;
2116 wndClass
.cbWndExtra
= sizeof(HEADER_INFO
*);
2117 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2118 wndClass
.lpszClassName
= WC_HEADERW
;
2120 RegisterClassW (&wndClass
);
2125 HEADER_Unregister (void)
2127 UnregisterClassW (WC_HEADERW
, NULL
);