4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2003 Maxime Bellenge
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * - Imagelist support (partially).
24 * - Callback items (under construction).
25 * - Hottrack support (partially).
26 * - Custom draw support (including Notifications).
27 * - Drag and Drop support (including Notifications).
29 * - Use notification format
30 * - Correct the order maintenance code to preserve valid order
39 #include "wine/unicode.h"
45 #include "imagelist.h"
48 #include "wine/debug.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(header
);
60 INT iOrder
; /* see documentation of HD_ITEM */
62 BOOL bDown
; /* is item pressed? (used for drawing) */
63 RECT rect
; /* bounding rectangle of the item */
69 HWND hwndNotify
; /* Owner window to send notifications to */
70 INT nNotifyFormat
; /* format used for WM_NOTIFY messages */
71 UINT uNumItem
; /* number of items (columns) */
72 INT nHeight
; /* height of the header (pixels) */
73 HFONT hFont
; /* handle to the current font */
74 HCURSOR hcurArrow
; /* handle to the arrow cursor */
75 HCURSOR hcurDivider
; /* handle to a cursor (used over dividers) <-|-> */
76 HCURSOR hcurDivopen
; /* handle to a cursor (used over dividers) <-||-> */
77 BOOL bCaptured
; /* Is the mouse captured? */
78 BOOL bPressed
; /* Is a header item pressed (down)? */
79 BOOL bTracking
; /* Is in tracking mode? */
80 INT iMoveItem
; /* index of tracked item. (Tracking mode) */
81 INT xTrackOffset
; /* distance between the right side of the tracked item and the cursor */
82 INT xOldTrack
; /* track offset (see above) after the last WM_MOUSEMOVE */
83 INT nOldWidth
; /* width of a sizing item after the last WM_MOUSEMOVE */
84 INT iHotItem
; /* index of hot item (cursor is over this item) */
85 INT iMargin
; /* width of the margin that surrounds a bitmap */
87 HIMAGELIST himl
; /* handle to an image list (may be 0) */
88 HEADER_ITEM
*items
; /* pointer to array of HEADER_ITEM's */
89 INT
*order
; /* array of item IDs indexed by order */
90 BOOL bRectsValid
; /* validity flag for bounding rectangles */
95 #define DIVIDER_WIDTH 10
96 #define HDN_UNICODE_OFFSET 20
97 #define HDN_FIRST_UNICODE (HDN_FIRST-HDN_UNICODE_OFFSET)
99 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongPtrW(hwnd,0))
101 static const WCHAR themeClass
[] = {'H','e','a','d','e','r',0};
102 static WCHAR emptyString
[] = {0};
104 static void HEADER_DisposeItem(HEADER_ITEM
*lpItem
)
106 if (lpItem
->pszText
&& lpItem
->pszText
!= emptyString
&&
107 lpItem
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers LPSTR_TEXTCALLBACKA too */
109 Free(lpItem
->pszText
);
113 static void HEADER_StoreHDItemInHeader(HEADER_ITEM
*lpItem
, HDITEMW
*phdi
, BOOL fUnicode
)
115 if (phdi
->mask
& HDI_BITMAP
)
116 lpItem
->hbm
= phdi
->hbm
;
118 if (phdi
->mask
& HDI_FORMAT
)
119 lpItem
->fmt
= phdi
->fmt
;
121 if (phdi
->mask
& HDI_LPARAM
)
122 lpItem
->lParam
= phdi
->lParam
;
124 if (phdi
->mask
& HDI_WIDTH
)
125 lpItem
->cxy
= phdi
->cxy
;
127 if (phdi
->mask
& HDI_IMAGE
)
129 lpItem
->iImage
= phdi
->iImage
;
132 if (phdi
->mask
& HDI_TEXT
)
136 if (lpItem
->pszText
!= emptyString
&& lpItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
137 Free(lpItem
->pszText
);
138 lpItem
->pszText
= NULL
;
141 if (phdi
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers != TEXTCALLBACKA too */
143 LPWSTR pszText
= (phdi
->pszText
!= NULL
? phdi
->pszText
: emptyString
);
145 Str_SetPtrW(&lpItem
->pszText
, pszText
);
147 Str_SetPtrAtoW(&lpItem
->pszText
, (LPSTR
)pszText
);
151 lpItem
->pszText
= phdi
->pszText
;
156 inline static LRESULT
157 HEADER_IndexToOrder (HWND hwnd
, INT iItem
)
159 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
160 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
161 return lpItem
->iOrder
;
166 HEADER_OrderToIndex(HWND hwnd
, WPARAM wParam
)
168 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
169 INT iorder
= (INT
)wParam
;
171 if ((iorder
<0) || iorder
>= infoPtr
->uNumItem
)
173 return infoPtr
->order
[iorder
];
177 HEADER_SetItemBounds (HWND hwnd
)
179 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
185 infoPtr
->bRectsValid
= TRUE
;
187 if (infoPtr
->uNumItem
== 0)
190 GetClientRect (hwnd
, &rect
);
193 for (i
= 0; i
< infoPtr
->uNumItem
; i
++) {
194 phdi
= &infoPtr
->items
[HEADER_OrderToIndex(hwnd
,i
)];
195 phdi
->rect
.top
= rect
.top
;
196 phdi
->rect
.bottom
= rect
.bottom
;
198 phdi
->rect
.right
= phdi
->rect
.left
+ ((phdi
->cxy
>0)?phdi
->cxy
:0);
199 x
= phdi
->rect
.right
;
204 HEADER_Size (HWND hwnd
, WPARAM wParam
)
206 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
208 infoPtr
->bRectsValid
= FALSE
;
215 HEADER_DrawItem (HWND hwnd
, HDC hdc
, INT iItem
, BOOL bHotTrack
)
217 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
218 HEADER_ITEM
*phdi
= &infoPtr
->items
[iItem
];
220 INT oldBkMode
, cxEdge
= GetSystemMetrics(SM_CXEDGE
);
221 HTHEME theme
= GetWindowTheme (hwnd
);
224 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem
, bHotTrack
, (infoPtr
->nNotifyFormat
== NFR_UNICODE
));
226 if (!infoPtr
->bRectsValid
)
227 HEADER_SetItemBounds(hwnd
);
230 if (r
.right
- r
.left
== 0)
231 return phdi
->rect
.right
;
234 int state
= (phdi
->bDown
) ? HIS_PRESSED
:
235 (bHotTrack
? HIS_HOT
: HIS_NORMAL
);
236 DrawThemeBackground (theme
, hdc
, HP_HEADERITEM
, state
,
238 GetThemeBackgroundContentRect (theme
, hdc
, HP_HEADERITEM
, state
,
242 if (GetWindowLongW (hwnd
, GWL_STYLE
) & HDS_BUTTONS
) {
244 DrawEdge (hdc
, &r
, BDR_RAISEDOUTER
,
245 BF_RECT
| BF_FLAT
| BF_MIDDLE
| BF_ADJUST
);
248 DrawEdge (hdc
, &r
, EDGE_RAISED
,
249 BF_RECT
| BF_SOFT
| BF_MIDDLE
| BF_ADJUST
);
252 DrawEdge (hdc
, &r
, EDGE_ETCHED
, BF_BOTTOM
| BF_RIGHT
| BF_ADJUST
);
262 /* Set the colors before sending NM_CUSTOMDRAW so that it can change them */
263 SetTextColor (hdc
, (bHotTrack
&& !theme
) ? COLOR_HIGHLIGHT
: COLOR_BTNTEXT
);
264 SetBkColor(hdc
, GetSysColor(COLOR_3DFACE
));
266 nmcd
.hdr
.hwndFrom
= hwnd
;
267 nmcd
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
268 nmcd
.hdr
.code
= NM_CUSTOMDRAW
;
269 nmcd
.dwDrawStage
= CDDS_PREPAINT
| CDDS_ITEM
| CDDS_ITEMPOSTERASE
;
271 nmcd
.dwItemSpec
= iItem
;
273 nmcd
.uItemState
= phdi
->bDown
? CDIS_SELECTED
: 0;
274 nmcd
.lItemlParam
= phdi
->lParam
;
276 SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
, nmcd
.hdr
.idFrom
, (LPARAM
)&nmcd
);
278 if (phdi
->fmt
& HDF_OWNERDRAW
) {
281 dis
.CtlType
= ODT_HEADER
;
282 dis
.CtlID
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
284 dis
.itemAction
= ODA_DRAWENTIRE
;
285 dis
.itemState
= phdi
->bDown
? ODS_SELECTED
: 0;
289 dis
.itemData
= phdi
->lParam
;
290 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
291 SendMessageW (infoPtr
->hwndNotify
, WM_DRAWITEM
,
292 (WPARAM
)dis
.CtlID
, (LPARAM
)&dis
);
293 if (oldBkMode
!= TRANSPARENT
)
294 SetBkMode(hdc
, oldBkMode
);
297 UINT rw
, rh
, /* width and height of r */
298 *x
= NULL
, *w
= NULL
; /* x and width of the pic (bmp or img) which is part of cnt */
299 /* cnt,txt,img,bmp */
304 cw
= tw
= iw
= bw
= 0;
305 rw
= r
.right
- r
.left
;
306 rh
= r
.bottom
- r
.top
;
309 HBRUSH hbr
= CreateSolidBrush(GetBkColor(hdc
));
310 RECT rcBackground
= r
;
312 rcBackground
.right
-= cxEdge
;
313 FillRect(hdc
, &rcBackground
, hbr
);
316 if (phdi
->fmt
& HDF_STRING
) {
319 DrawTextW (hdc
, phdi
->pszText
, -1,
320 &textRect
, DT_LEFT
|DT_VCENTER
|DT_SINGLELINE
|DT_CALCRECT
);
321 cw
= textRect
.right
- textRect
.left
+ 2 * infoPtr
->iMargin
;
324 if ((phdi
->fmt
& HDF_IMAGE
) && (infoPtr
->himl
)) {
325 iw
= infoPtr
->himl
->cx
+ 2 * infoPtr
->iMargin
;
330 if ((phdi
->fmt
& HDF_BITMAP
) && (phdi
->hbm
)) {
331 GetObjectW (phdi
->hbm
, sizeof(BITMAP
), (LPVOID
)&bmp
);
332 bw
= bmp
.bmWidth
+ 2 * infoPtr
->iMargin
;
342 /* align cx using the unclipped cw */
343 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_LEFT
)
345 else if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_CENTER
)
346 cx
= r
.left
+ rw
/ 2 - cw
/ 2;
353 if (cx
+ cw
> r
.right
)
356 tx
= cx
+ infoPtr
->iMargin
;
357 /* since cw might have changed we have to recalculate tw */
358 tw
= cw
- infoPtr
->iMargin
* 2;
362 if (phdi
->fmt
& HDF_BITMAP_ON_RIGHT
) {
363 /* put pic behind text */
364 *x
= cx
+ tw
+ infoPtr
->iMargin
* 3;
366 *x
= cx
+ infoPtr
->iMargin
;
367 /* move text behind pic */
373 /* since we're done with the layout we can
374 now calculate the position of bmp which
375 has no influence on alignment and layout
377 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_RIGHT
)
378 bx
= cx
- bw
+ infoPtr
->iMargin
;
380 bx
= cx
+ cw
+ infoPtr
->iMargin
;
384 HDC hClipDC
= GetDC(hwnd
);
385 HRGN hClipRgn
= CreateRectRgn(r
.left
, r
.top
, r
.right
, r
.bottom
);
386 SelectClipRgn(hClipDC
, hClipRgn
);
389 HDC hdcBitmap
= CreateCompatibleDC (hClipDC
);
390 SelectObject (hdcBitmap
, phdi
->hbm
);
391 BitBlt (hClipDC
, bx
, r
.top
+ ((INT
)rh
- bmp
.bmHeight
) / 2,
392 bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
393 DeleteDC (hdcBitmap
);
397 ImageList_DrawEx (infoPtr
->himl
, phdi
->iImage
, hClipDC
,
398 ix
, r
.top
+ ((INT
)rh
- infoPtr
->himl
->cy
) / 2,
399 infoPtr
->himl
->cx
, infoPtr
->himl
->cy
, CLR_DEFAULT
, CLR_DEFAULT
, 0);
402 DeleteObject(hClipRgn
);
403 ReleaseDC(hwnd
, hClipDC
);
406 if (((phdi
->fmt
& HDF_STRING
)
407 || (!(phdi
->fmt
& (HDF_OWNERDRAW
|HDF_STRING
|HDF_BITMAP
|
408 HDF_BITMAP_ON_RIGHT
|HDF_IMAGE
)))) /* no explicit format specified? */
409 && (phdi
->pszText
)) {
410 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
413 DrawTextW (hdc
, phdi
->pszText
, -1,
414 &r
, DT_LEFT
|DT_END_ELLIPSIS
|DT_VCENTER
|DT_SINGLELINE
);
415 if (oldBkMode
!= TRANSPARENT
)
416 SetBkMode(hdc
, oldBkMode
);
420 return phdi
->rect
.right
;
425 HEADER_Refresh (HWND hwnd
, HDC hdc
)
427 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
428 HFONT hFont
, hOldFont
;
433 HTHEME theme
= GetWindowTheme (hwnd
);
435 /* get rect for the bar, adjusted for the border */
436 GetClientRect (hwnd
, &rect
);
438 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
);
439 hOldFont
= SelectObject (hdc
, hFont
);
441 /* draw Background */
443 hbrBk
= GetSysColorBrush(COLOR_3DFACE
);
444 FillRect(hdc
, &rect
, hbrBk
);
448 for (i
= 0; x
<= rect
.right
&& i
< infoPtr
->uNumItem
; i
++) {
449 x
= HEADER_DrawItem (hwnd
, hdc
, HEADER_OrderToIndex(hwnd
,i
),
450 infoPtr
->iHotItem
== i
);
453 if ((x
<= rect
.right
) && (infoPtr
->uNumItem
> 0)) {
456 DrawThemeBackground (theme
, hdc
, HP_HEADERITEM
, HIS_NORMAL
, &rect
,
460 if (GetWindowLongW (hwnd
, GWL_STYLE
) & HDS_BUTTONS
)
461 DrawEdge (hdc
, &rect
, EDGE_RAISED
, BF_TOP
|BF_LEFT
|BF_BOTTOM
|BF_SOFT
);
463 DrawEdge (hdc
, &rect
, EDGE_ETCHED
, BF_BOTTOM
);
467 SelectObject (hdc
, hOldFont
);
472 HEADER_RefreshItem (HWND hwnd
, HDC hdc
, INT iItem
)
474 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
475 HFONT hFont
, hOldFont
;
477 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
);
478 hOldFont
= SelectObject (hdc
, hFont
);
479 HEADER_DrawItem (hwnd
, hdc
, iItem
, infoPtr
->iHotItem
== iItem
);
480 SelectObject (hdc
, hOldFont
);
485 HEADER_InternalHitTest (HWND hwnd
, LPPOINT lpPt
, UINT
*pFlags
, INT
*pItem
)
487 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
493 GetClientRect (hwnd
, &rect
);
497 if (PtInRect (&rect
, *lpPt
))
499 if (infoPtr
->uNumItem
== 0) {
500 *pFlags
|= HHT_NOWHERE
;
506 /* somewhere inside */
507 for (iCount
= 0; iCount
< infoPtr
->uNumItem
; iCount
++) {
508 rect
= infoPtr
->items
[iCount
].rect
;
509 width
= rect
.right
- rect
.left
;
514 if (PtInRect (&rect
, *lpPt
)) {
515 if (width
<= 2 * DIVIDER_WIDTH
) {
516 *pFlags
|= HHT_ONHEADER
;
518 TRACE("ON HEADER %d\n", iCount
);
523 rcTest
.right
= rcTest
.left
+ DIVIDER_WIDTH
;
524 if (PtInRect (&rcTest
, *lpPt
)) {
526 *pFlags
|= HHT_ONDIVOPEN
;
528 TRACE("ON DIVOPEN %d\n", *pItem
);
532 *pFlags
|= HHT_ONDIVIDER
;
534 TRACE("ON DIVIDER %d\n", *pItem
);
540 rcTest
.left
= rcTest
.right
- DIVIDER_WIDTH
;
541 if (PtInRect (&rcTest
, *lpPt
)) {
542 *pFlags
|= HHT_ONDIVIDER
;
544 TRACE("ON DIVIDER %d\n", *pItem
);
548 *pFlags
|= HHT_ONHEADER
;
550 TRACE("ON HEADER %d\n", iCount
);
555 /* check for last divider part (on nowhere) */
556 rect
= infoPtr
->items
[infoPtr
->uNumItem
-1].rect
;
557 rect
.left
= rect
.right
;
558 rect
.right
+= DIVIDER_WIDTH
;
559 if (PtInRect (&rect
, *lpPt
)) {
561 *pFlags
|= HHT_ONDIVOPEN
;
562 *pItem
= infoPtr
->uNumItem
- 1;
563 TRACE("ON DIVOPEN %d\n", *pItem
);
567 *pFlags
|= HHT_ONDIVIDER
;
568 *pItem
= infoPtr
->uNumItem
-1;
569 TRACE("ON DIVIDER %d\n", *pItem
);
574 *pFlags
|= HHT_NOWHERE
;
581 if (lpPt
->x
< rect
.left
) {
583 *pFlags
|= HHT_TOLEFT
;
585 else if (lpPt
->x
> rect
.right
) {
587 *pFlags
|= HHT_TORIGHT
;
590 if (lpPt
->y
< rect
.top
) {
592 *pFlags
|= HHT_ABOVE
;
594 else if (lpPt
->y
> rect
.bottom
) {
596 *pFlags
|= HHT_BELOW
;
601 TRACE("flags=0x%X\n", *pFlags
);
607 HEADER_DrawTrackLine (HWND hwnd
, HDC hdc
, INT x
)
613 GetClientRect (hwnd
, &rect
);
615 hOldPen
= SelectObject (hdc
, GetStockObject (BLACK_PEN
));
616 oldRop
= SetROP2 (hdc
, R2_XORPEN
);
617 MoveToEx (hdc
, x
, rect
.top
, NULL
);
618 LineTo (hdc
, x
, rect
.bottom
);
619 SetROP2 (hdc
, oldRop
);
620 SelectObject (hdc
, hOldPen
);
625 * Convert a HDITEM into the correct format (ANSI/Unicode) to send it in a notify
628 * [I] infoPtr : the header that wants to send the notify
629 * [O] dest : The buffer to store the HDITEM for notify. It may be set to a HDITEMA of HDITEMW
630 * [I] src : The source HDITEM. It may be a HDITEMA or HDITEMW
631 * [I] fSourceUnicode : is src a HDITEMW or HDITEMA
632 * [O] ppvScratch : a pointer to a scratch buffer that needs to be freed after
633 * the HDITEM is no longer in use or NULL if none was needed
635 * NOTE: We depend on HDITEMA and HDITEMW having the same structure
637 static void HEADER_CopyHDItemForNotify(HEADER_INFO
*infoPtr
, HDITEMW
*dest
,
638 HDITEMW
*src
, BOOL fSourceUnicode
, LPVOID
*ppvScratch
)
643 if (src
->mask
& HDI_TEXT
&& src
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers TEXTCALLBACKA as well */
645 if (fSourceUnicode
&& infoPtr
->nNotifyFormat
!= NFR_UNICODE
)
647 dest
->pszText
= NULL
;
648 Str_SetPtrWtoA((LPSTR
*)&dest
->pszText
, src
->pszText
);
649 *ppvScratch
= dest
->pszText
;
652 if (!fSourceUnicode
&& infoPtr
->nNotifyFormat
== NFR_UNICODE
)
654 dest
->pszText
= NULL
;
655 Str_SetPtrAtoW(&dest
->pszText
, (LPSTR
)src
->pszText
);
656 *ppvScratch
= dest
->pszText
;
661 static UINT
HEADER_NotifyCodeWtoA(UINT code
)
663 /* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
664 if (code
>= HDN_LAST
&& code
<= HDN_FIRST_UNICODE
)
665 return code
+ HDN_UNICODE_OFFSET
;
671 HEADER_SendSimpleNotify (HWND hwnd
, UINT code
)
673 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
676 nmhdr
.hwndFrom
= hwnd
;
677 nmhdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
680 return (BOOL
)SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
681 (WPARAM
)nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
685 HEADER_SendHeaderNotifyT (HWND hwnd
, UINT code
, INT iItem
, INT mask
, HDITEMW
*lpItem
)
687 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
693 /* lpItem == NULL means that we should take the actual data from the item */
696 FIXME("(): invalid parameters - lpItem == NULL and (mask & HDI_TEXT)\n");
700 nmitem
.cxy
= infoPtr
->items
[iItem
].cxy
;
701 nmitem
.hbm
= infoPtr
->items
[iItem
].hbm
;
702 nmitem
.pszText
= NULL
;
703 nmitem
.cchTextMax
= 0;
704 nmitem
.fmt
= infoPtr
->items
[iItem
].fmt
;
705 nmitem
.lParam
= infoPtr
->items
[iItem
].lParam
;
706 nmitem
.iOrder
= infoPtr
->items
[iItem
].iOrder
;
707 nmitem
.iImage
= infoPtr
->items
[iItem
].iImage
;
711 nmhdr
.hdr
.hwndFrom
= hwnd
;
712 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
713 nmhdr
.hdr
.code
= (infoPtr
->nNotifyFormat
== NFR_UNICODE
? code
: HEADER_NotifyCodeWtoA(code
));
716 nmhdr
.pitem
= lpItem
;
718 return (BOOL
)SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
719 (WPARAM
)nmhdr
.hdr
.idFrom
, (LPARAM
)&nmhdr
);
723 * Send Disp Info notification.
724 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
725 * (so we handle the two cases only doing a specific cast for pszText).
727 * @param hwnd : hwnd header container handler
728 * @param mask : notification mask (usually HDI_TEXT or HDI_IMAGE)
729 * @param pDispInfo : NMHDDISPINFO structure (can be unicode or ansi)
730 * @param isW : TRUE if dispinfo is Unicode
733 HEADER_SendHeaderDispInfoNotify(HWND hwnd
, INT iItem
, INT mask
, LPHDITEMW phdi
, HEADER_ITEM
* lpItem
, BOOL isW
)
735 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
737 BOOL convertToAnsi
= FALSE
;
738 BOOL convertToUnicode
= FALSE
;
739 BOOL isUnicodeNotify
= FALSE
;
740 NMHDDISPINFOW dispInfo
;
744 convertToAnsi
= (isW
&& infoPtr
->nNotifyFormat
== NFR_ANSI
);
745 convertToUnicode
= (!isW
&& infoPtr
->nNotifyFormat
== NFR_UNICODE
);
747 isUnicodeNotify
= (isW
&& !convertToAnsi
);
749 memset(&dispInfo
, 0, sizeof(NMHDDISPINFOW
));
750 dispInfo
.hdr
.hwndFrom
= hwnd
;
751 dispInfo
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
752 if (isUnicodeNotify
|| convertToUnicode
)
754 dispInfo
.hdr
.code
= HDN_GETDISPINFOW
;
758 dispInfo
.hdr
.code
= HDN_GETDISPINFOA
;
760 dispInfo
.iItem
= iItem
;
761 dispInfo
.mask
= mask
;
763 dispInfo.pszText = Alloc(sizeof(WCHAR) * 260);
764 dispInfo.cchTextMax = 260;
766 ret
= (BOOL
) SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
767 (WPARAM
) dispInfo
.hdr
.idFrom
,
770 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
772 (isUnicodeNotify
? debugstr_w(dispInfo
.pszText
) : (LPSTR
) dispInfo
.pszText
),
773 (void*) dispInfo
.lParam
);
775 if (dispInfo
.mask
& HDI_DI_SETITEM
)
777 if (dispInfo
.mask
& HDI_IMAGE
)
779 lpItem
->iImage
= dispInfo
.iImage
;
781 if (dispInfo
.mask
& HDI_TEXT
)
783 if (isUnicodeNotify
|| convertToUnicode
)
784 Str_SetPtrW(&lpItem
->pszText
, (LPCWSTR
)dispInfo
.pszText
);
785 else /*if (convertToAnsi || !isW)*/
786 Str_SetPtrAtoW(&lpItem
->pszText
, (LPCSTR
)dispInfo
.pszText
);
789 FIXME("NMHDDISPINFO returns with flags HDI_DI_SETITEM\n");
794 if ((phdi
->mask
& mask
) & HDI_IMAGE
)
796 phdi
->iImage
= dispInfo
.iImage
;
798 if ((phdi
->mask
& mask
) & HDI_TEXT
)
801 Str_GetPtrW ((LPCWSTR
)dispInfo
.pszText
, phdi
->pszText
, phdi
->cchTextMax
);
802 else if (convertToUnicode
)
803 Str_GetPtrWtoA ((LPCWSTR
)dispInfo
.pszText
, (LPSTR
)phdi
->pszText
, phdi
->cchTextMax
);
805 Str_GetPtrA ((LPCSTR
)dispInfo
.pszText
, (LPSTR
)phdi
->pszText
, phdi
->cchTextMax
);
813 HEADER_SendClickNotify (HWND hwnd
, UINT code
, INT iItem
)
815 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
818 nmhdr
.hdr
.hwndFrom
= hwnd
;
819 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
820 nmhdr
.hdr
.code
= code
;
825 return (BOOL
)SendMessageA (infoPtr
->hwndNotify
, WM_NOTIFY
,
826 (WPARAM
)nmhdr
.hdr
.idFrom
, (LPARAM
)&nmhdr
);
831 HEADER_CreateDragImage (HWND hwnd
, WPARAM wParam
)
833 FIXME("empty stub!\n");
839 HEADER_DeleteItem (HWND hwnd
, WPARAM wParam
)
841 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr(hwnd
);
842 INT iItem
= (INT
)wParam
;
844 TRACE("[iItem=%d]\n", iItem
);
846 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
849 if (infoPtr
->uNumItem
== 1) {
850 TRACE("Simple delete!\n");
851 HEADER_DisposeItem(&infoPtr
->items
[0]);
852 Free (infoPtr
->items
);
853 Free(infoPtr
->order
);
856 infoPtr
->uNumItem
= 0;
859 HEADER_ITEM
*oldItems
= infoPtr
->items
;
862 TRACE("Complex delete! [iItem=%d]\n", iItem
);
864 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
865 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
866 HEADER_DisposeItem(&infoPtr
->items
[iItem
]);
867 iOrder
= infoPtr
->items
[iItem
].iOrder
;
870 infoPtr
->items
= Alloc (sizeof (HEADER_ITEM
) * infoPtr
->uNumItem
);
871 /* pre delete copy */
873 memcpy (&infoPtr
->items
[0], &oldItems
[0],
874 iItem
* sizeof(HEADER_ITEM
));
877 /* post delete copy */
878 if (iItem
< infoPtr
->uNumItem
) {
879 memcpy (&infoPtr
->items
[iItem
], &oldItems
[iItem
+1],
880 (infoPtr
->uNumItem
- iItem
) * sizeof(HEADER_ITEM
));
883 /* Correct the orders */
884 if (iOrder
< infoPtr
->uNumItem
)
886 memmove(&infoPtr
->order
[iOrder
], &infoPtr
->order
[iOrder
+ 1],
887 (infoPtr
->uNumItem
- iOrder
) * sizeof(INT
));
888 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
890 if (infoPtr
->order
[i
] > iItem
)
893 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= infoPtr
->order
[i
];
897 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
898 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
902 HEADER_SetItemBounds (hwnd
);
904 InvalidateRect(hwnd
, NULL
, FALSE
);
911 HEADER_GetImageList (HWND hwnd
)
913 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
915 return (LRESULT
)infoPtr
->himl
;
920 HEADER_GetItemT (HWND hwnd
, INT nItem
, LPHDITEMW phdi
, BOOL bUnicode
)
922 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
928 TRACE("[nItem=%d]\n", nItem
);
932 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
935 lpItem
= &infoPtr
->items
[nItem
];
937 if (phdi
->mask
& HDI_BITMAP
)
938 phdi
->hbm
= lpItem
->hbm
;
940 if (phdi
->mask
& HDI_FORMAT
)
941 phdi
->fmt
= lpItem
->fmt
;
943 if (phdi
->mask
& HDI_WIDTH
)
944 phdi
->cxy
= lpItem
->cxy
;
946 if (phdi
->mask
& HDI_LPARAM
)
947 phdi
->lParam
= lpItem
->lParam
;
949 if (phdi
->mask
& HDI_IMAGE
)
951 phdi
->iImage
= lpItem
->iImage
;
952 if (lpItem
->iImage
== I_IMAGECALLBACK
)
954 HEADER_SendHeaderDispInfoNotify(hwnd
, nItem
, HDI_IMAGE
, phdi
, lpItem
, bUnicode
);
958 if (phdi
->mask
& HDI_ORDER
)
959 phdi
->iOrder
= lpItem
->iOrder
;
961 if (phdi
->mask
& HDI_TEXT
)
963 if (lpItem
->pszText
== LPSTR_TEXTCALLBACKW
) /* covers == TEXTCALLBACKA too */
965 HEADER_SendHeaderDispInfoNotify(hwnd
, nItem
, HDI_TEXT
, phdi
, lpItem
, bUnicode
);
970 Str_GetPtrW (lpItem
->pszText
, phdi
->pszText
, phdi
->cchTextMax
);
972 Str_GetPtrWtoA (lpItem
->pszText
, (LPSTR
)phdi
->pszText
, phdi
->cchTextMax
);
980 inline static LRESULT
981 HEADER_GetItemCount (HWND hwnd
)
983 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
984 return infoPtr
->uNumItem
;
989 HEADER_GetItemRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
991 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
992 INT iItem
= (INT
)wParam
;
993 LPRECT lpRect
= (LPRECT
)lParam
;
995 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
998 lpRect
->left
= infoPtr
->items
[iItem
].rect
.left
;
999 lpRect
->right
= infoPtr
->items
[iItem
].rect
.right
;
1000 lpRect
->top
= infoPtr
->items
[iItem
].rect
.top
;
1001 lpRect
->bottom
= infoPtr
->items
[iItem
].rect
.bottom
;
1008 HEADER_GetOrderArray(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1010 LPINT order
= (LPINT
) lParam
;
1011 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1013 if ((unsigned int)wParam
<infoPtr
->uNumItem
)
1016 memcpy(order
, infoPtr
->order
, infoPtr
->uNumItem
* sizeof(INT
));
1021 HEADER_SetOrderArray(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1024 LPINT order
= (LPINT
) lParam
;
1025 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1026 HEADER_ITEM
*lpItem
;
1028 if ((unsigned int)wParam
<infoPtr
->uNumItem
)
1030 memcpy(infoPtr
->order
, order
, infoPtr
->uNumItem
* sizeof(INT
));
1031 for (i
=0; i
<(int)wParam
; i
++)
1033 lpItem
= &infoPtr
->items
[*order
++];
1036 infoPtr
->bRectsValid
=0;
1037 InvalidateRect(hwnd
, NULL
, FALSE
);
1041 inline static LRESULT
1042 HEADER_GetUnicodeFormat (HWND hwnd
)
1044 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1045 return (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1050 HEADER_HitTest (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1052 LPHDHITTESTINFO phti
= (LPHDHITTESTINFO
)lParam
;
1054 HEADER_InternalHitTest (hwnd
, &phti
->pt
, &phti
->flags
, &phti
->iItem
);
1056 if (phti
->flags
== HHT_NOWHERE
)
1064 HEADER_InsertItemT (HWND hwnd
, INT nItem
, LPHDITEMW phdi
, BOOL bUnicode
)
1066 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1067 HEADER_ITEM
*lpItem
;
1071 if ((phdi
== NULL
) || (nItem
< 0))
1074 if (nItem
> infoPtr
->uNumItem
)
1075 nItem
= infoPtr
->uNumItem
;
1077 iOrder
= (phdi
->mask
& HDI_ORDER
) ? phdi
->iOrder
: nItem
;
1080 else if (infoPtr
->uNumItem
< iOrder
)
1081 iOrder
= infoPtr
->uNumItem
;
1083 if (infoPtr
->uNumItem
== 0) {
1084 infoPtr
->items
= Alloc (sizeof (HEADER_ITEM
));
1085 infoPtr
->order
= Alloc(sizeof(INT
));
1086 infoPtr
->uNumItem
++;
1089 HEADER_ITEM
*oldItems
= infoPtr
->items
;
1090 INT
*oldOrder
= infoPtr
->order
;
1092 infoPtr
->uNumItem
++;
1093 infoPtr
->items
= Alloc (sizeof (HEADER_ITEM
) * infoPtr
->uNumItem
);
1095 memcpy (&infoPtr
->items
[1], &oldItems
[0],
1096 (infoPtr
->uNumItem
-1) * sizeof(HEADER_ITEM
));
1100 /* pre insert copy */
1102 memcpy (&infoPtr
->items
[0], &oldItems
[0],
1103 nItem
* sizeof(HEADER_ITEM
));
1106 /* post insert copy */
1107 if (nItem
< infoPtr
->uNumItem
- 1) {
1108 memcpy (&infoPtr
->items
[nItem
+1], &oldItems
[nItem
],
1109 (infoPtr
->uNumItem
- nItem
- 1) * sizeof(HEADER_ITEM
));
1113 infoPtr
->order
= Alloc(sizeof(INT
) * infoPtr
->uNumItem
);
1114 memcpy(infoPtr
->order
, oldOrder
, iOrder
* sizeof(INT
));
1115 infoPtr
->order
[iOrder
] = nItem
;
1116 memcpy(&infoPtr
->order
[iOrder
+ 1], &oldOrder
[iOrder
],
1117 (infoPtr
->uNumItem
- iOrder
- 1) * sizeof(INT
));
1123 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1125 if (i
!= iOrder
&& infoPtr
->order
[i
] >= nItem
)
1126 infoPtr
->order
[i
]++;
1127 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= infoPtr
->order
[i
];
1130 lpItem
= &infoPtr
->items
[nItem
];
1131 ZeroMemory(lpItem
, sizeof(HEADER_ITEM
));
1132 HEADER_StoreHDItemInHeader(lpItem
, phdi
, bUnicode
);
1134 if (phdi
->mask
& HDI_TEXT
)
1135 lpItem
->fmt
|= HDF_STRING
;
1137 lpItem
->iOrder
= iOrder
;
1139 HEADER_SetItemBounds (hwnd
);
1141 InvalidateRect(hwnd
, NULL
, FALSE
);
1148 HEADER_Layout (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1150 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1151 LPHDLAYOUT lpLayout
= (LPHDLAYOUT
)lParam
;
1153 lpLayout
->pwpos
->hwnd
= hwnd
;
1154 lpLayout
->pwpos
->hwndInsertAfter
= 0;
1155 lpLayout
->pwpos
->x
= lpLayout
->prc
->left
;
1156 lpLayout
->pwpos
->y
= lpLayout
->prc
->top
;
1157 lpLayout
->pwpos
->cx
= lpLayout
->prc
->right
- lpLayout
->prc
->left
;
1158 if (GetWindowLongW (hwnd
, GWL_STYLE
) & HDS_HIDDEN
)
1159 lpLayout
->pwpos
->cy
= 0;
1161 lpLayout
->pwpos
->cy
= infoPtr
->nHeight
;
1162 lpLayout
->prc
->top
+= infoPtr
->nHeight
;
1164 lpLayout
->pwpos
->flags
= SWP_NOZORDER
;
1166 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1167 lpLayout
->pwpos
->x
, lpLayout
->pwpos
->y
,
1168 lpLayout
->pwpos
->cx
, lpLayout
->pwpos
->cy
);
1170 infoPtr
->bRectsValid
= FALSE
;
1177 HEADER_SetImageList (HWND hwnd
, HIMAGELIST himl
)
1179 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1182 TRACE("(himl %p)\n", himl
);
1183 himlOld
= infoPtr
->himl
;
1184 infoPtr
->himl
= himl
;
1186 /* FIXME: Refresh needed??? */
1188 return (LRESULT
)himlOld
;
1193 HEADER_GetBitmapMargin(HWND hwnd
)
1195 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr(hwnd
);
1197 return infoPtr
->iMargin
;
1201 HEADER_SetBitmapMargin(HWND hwnd
, WPARAM wParam
)
1203 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1204 INT oldMargin
= infoPtr
->iMargin
;
1206 infoPtr
->iMargin
= (INT
)wParam
;
1212 HEADER_SetItemT (HWND hwnd
, INT nItem
, LPHDITEMW phdi
, BOOL bUnicode
)
1214 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1215 HEADER_ITEM
*lpItem
;
1221 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
1224 TRACE("[nItem=%d]\n", nItem
);
1226 HEADER_CopyHDItemForNotify(infoPtr
, &hdNotify
, phdi
, bUnicode
, &pvScratch
);
1227 if (HEADER_SendHeaderNotifyT (hwnd
, HDN_ITEMCHANGINGW
, nItem
, phdi
->mask
, &hdNotify
))
1229 if (pvScratch
) Free(pvScratch
);
1233 lpItem
= &infoPtr
->items
[nItem
];
1234 HEADER_StoreHDItemInHeader(lpItem
, phdi
, bUnicode
);
1236 if (phdi
->mask
& HDI_ORDER
)
1240 if (lpItem
->iOrder
< phdi
->iOrder
)
1242 memmove(&infoPtr
->order
[lpItem
->iOrder
],
1243 &infoPtr
->order
[lpItem
->iOrder
+ 1],
1244 (phdi
->iOrder
- lpItem
->iOrder
) * sizeof(INT
));
1246 if (phdi
->iOrder
< lpItem
->iOrder
)
1248 memmove(&infoPtr
->order
[phdi
->iOrder
+ 1],
1249 &infoPtr
->order
[phdi
->iOrder
],
1250 (lpItem
->iOrder
- phdi
->iOrder
) * sizeof(INT
));
1252 infoPtr
->order
[phdi
->iOrder
] = nItem
;
1253 nMin
= min(lpItem
->iOrder
, phdi
->iOrder
);
1254 nMax
= max(lpItem
->iOrder
, phdi
->iOrder
);
1255 for (i
= nMin
; i
<= nMax
; i
++)
1257 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= infoPtr
->order
[i
];
1261 HEADER_SendHeaderNotifyT (hwnd
, HDN_ITEMCHANGEDW
, nItem
, phdi
->mask
, &hdNotify
);
1263 HEADER_SetItemBounds (hwnd
);
1265 InvalidateRect(hwnd
, NULL
, FALSE
);
1267 if (pvScratch
!= NULL
)
1272 inline static LRESULT
1273 HEADER_SetUnicodeFormat (HWND hwnd
, WPARAM wParam
)
1275 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1276 BOOL bTemp
= (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1278 infoPtr
->nNotifyFormat
= ((BOOL
)wParam
? NFR_UNICODE
: NFR_ANSI
);
1285 HEADER_Create (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1287 HEADER_INFO
*infoPtr
;
1292 infoPtr
= (HEADER_INFO
*)Alloc (sizeof(HEADER_INFO
));
1293 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1295 infoPtr
->hwndNotify
= ((LPCREATESTRUCTA
)lParam
)->hwndParent
;
1296 infoPtr
->uNumItem
= 0;
1300 infoPtr
->bRectsValid
= FALSE
;
1301 infoPtr
->hcurArrow
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1302 infoPtr
->hcurDivider
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDER
));
1303 infoPtr
->hcurDivopen
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDEROPEN
));
1304 infoPtr
->bPressed
= FALSE
;
1305 infoPtr
->bTracking
= FALSE
;
1306 infoPtr
->iMoveItem
= 0;
1308 infoPtr
->iHotItem
= -1;
1309 infoPtr
->iMargin
= 3*GetSystemMetrics(SM_CXEDGE
);
1310 infoPtr
->nNotifyFormat
=
1311 SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_QUERY
);
1314 hOldFont
= SelectObject (hdc
, GetStockObject (SYSTEM_FONT
));
1315 GetTextMetricsW (hdc
, &tm
);
1316 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
1317 SelectObject (hdc
, hOldFont
);
1320 OpenThemeData(hwnd
, themeClass
);
1327 HEADER_Destroy (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1329 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1330 HEADER_ITEM
*lpItem
;
1334 if (infoPtr
->items
) {
1335 lpItem
= infoPtr
->items
;
1336 for (nItem
= 0; nItem
< infoPtr
->uNumItem
; nItem
++, lpItem
++) {
1337 HEADER_DisposeItem(lpItem
);
1339 Free (infoPtr
->items
);
1343 Free(infoPtr
->order
);
1346 ImageList_Destroy (infoPtr
->himl
);
1348 SetWindowLongPtrW (hwnd
, 0, 0);
1351 theme
= GetWindowTheme(hwnd
);
1352 CloseThemeData(theme
);
1357 static inline LRESULT
1358 HEADER_GetFont (HWND hwnd
)
1360 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1362 return (LRESULT
)infoPtr
->hFont
;
1367 HEADER_LButtonDblClk (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1373 pt
.x
= (INT
)LOWORD(lParam
);
1374 pt
.y
= (INT
)HIWORD(lParam
);
1375 HEADER_InternalHitTest (hwnd
, &pt
, &flags
, &nItem
);
1377 if ((GetWindowLongW (hwnd
, GWL_STYLE
) & HDS_BUTTONS
) && (flags
== HHT_ONHEADER
))
1378 HEADER_SendHeaderNotifyT (hwnd
, HDN_ITEMDBLCLICKW
, nItem
, 0, NULL
);
1379 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
))
1380 HEADER_SendHeaderNotifyT (hwnd
, HDN_DIVIDERDBLCLICKW
, nItem
, 0, NULL
);
1387 HEADER_LButtonDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1389 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1390 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1396 pt
.x
= (INT
)LOWORD(lParam
);
1397 pt
.y
= (INT
)HIWORD(lParam
);
1398 HEADER_InternalHitTest (hwnd
, &pt
, &flags
, &nItem
);
1400 if ((dwStyle
& HDS_BUTTONS
) && (flags
== HHT_ONHEADER
)) {
1402 infoPtr
->bCaptured
= TRUE
;
1403 infoPtr
->bPressed
= TRUE
;
1404 infoPtr
->iMoveItem
= nItem
;
1406 infoPtr
->items
[nItem
].bDown
= TRUE
;
1408 /* Send WM_CUSTOMDRAW */
1410 HEADER_RefreshItem (hwnd
, hdc
, nItem
);
1411 ReleaseDC (hwnd
, hdc
);
1413 TRACE("Pressed item %d!\n", nItem
);
1415 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
)) {
1416 if (!(HEADER_SendHeaderNotifyT (hwnd
, HDN_BEGINTRACKW
, nItem
, 0, NULL
))) {
1418 infoPtr
->bCaptured
= TRUE
;
1419 infoPtr
->bTracking
= TRUE
;
1420 infoPtr
->iMoveItem
= nItem
;
1421 infoPtr
->nOldWidth
= infoPtr
->items
[nItem
].cxy
;
1422 infoPtr
->xTrackOffset
= infoPtr
->items
[nItem
].rect
.right
- pt
.x
;
1424 if (!(dwStyle
& HDS_FULLDRAG
)) {
1425 infoPtr
->xOldTrack
= infoPtr
->items
[nItem
].rect
.right
;
1427 HEADER_DrawTrackLine (hwnd
, hdc
, infoPtr
->xOldTrack
);
1428 ReleaseDC (hwnd
, hdc
);
1431 TRACE("Begin tracking item %d!\n", nItem
);
1440 HEADER_LButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1442 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1443 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1449 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1450 pt
.y
= (INT
)(SHORT
)HIWORD(lParam
);
1451 HEADER_InternalHitTest (hwnd
, &pt
, &flags
, &nItem
);
1453 if (infoPtr
->bPressed
) {
1454 if ((nItem
== infoPtr
->iMoveItem
) && (flags
== HHT_ONHEADER
)) {
1455 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1457 HEADER_RefreshItem (hwnd
, hdc
, infoPtr
->iMoveItem
);
1458 ReleaseDC (hwnd
, hdc
);
1460 HEADER_SendClickNotify (hwnd
, HDN_ITEMCLICKA
, infoPtr
->iMoveItem
);
1462 else if (flags
== HHT_ONHEADER
)
1464 HEADER_ITEM
*lpItem
;
1465 INT newindex
= HEADER_IndexToOrder(hwnd
,nItem
);
1466 INT oldindex
= HEADER_IndexToOrder(hwnd
,infoPtr
->iMoveItem
);
1468 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1469 infoPtr
->iMoveItem
,oldindex
,nItem
,newindex
);
1470 lpItem
= &infoPtr
->items
[nItem
];
1471 lpItem
->iOrder
=oldindex
;
1473 lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1474 lpItem
->iOrder
= newindex
;
1476 infoPtr
->order
[oldindex
] = nItem
;
1477 infoPtr
->order
[newindex
] = infoPtr
->iMoveItem
;
1479 infoPtr
->bRectsValid
= FALSE
;
1480 InvalidateRect(hwnd
, NULL
, FALSE
);
1481 /* FIXME: Should some WM_NOTIFY be sent */
1484 TRACE("Released item %d!\n", infoPtr
->iMoveItem
);
1485 infoPtr
->bPressed
= FALSE
;
1487 else if (infoPtr
->bTracking
) {
1488 TRACE("End tracking item %d!\n", infoPtr
->iMoveItem
);
1489 infoPtr
->bTracking
= FALSE
;
1491 HEADER_SendHeaderNotifyT (hwnd
, HDN_ENDTRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, NULL
);
1493 if (!(dwStyle
& HDS_FULLDRAG
)) {
1495 HEADER_DrawTrackLine (hwnd
, hdc
, infoPtr
->xOldTrack
);
1496 ReleaseDC (hwnd
, hdc
);
1499 if (HEADER_SendHeaderNotifyT(hwnd
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, NULL
))
1501 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= infoPtr
->nOldWidth
;
1504 nWidth
= pt
.x
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
+ infoPtr
->xTrackOffset
;
1507 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= nWidth
;
1510 HEADER_SetItemBounds (hwnd
);
1511 InvalidateRect(hwnd
, NULL
, TRUE
);
1512 HEADER_SendHeaderNotifyT(hwnd
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, NULL
);
1515 if (infoPtr
->bCaptured
) {
1516 infoPtr
->bCaptured
= FALSE
;
1518 HEADER_SendSimpleNotify (hwnd
, NM_RELEASEDCAPTURE
);
1526 HEADER_NotifyFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1528 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1533 return infoPtr
->nNotifyFormat
;
1536 infoPtr
->nNotifyFormat
=
1537 SendMessageW ((HWND
)wParam
, WM_NOTIFYFORMAT
,
1538 (WPARAM
)hwnd
, (LPARAM
)NF_QUERY
);
1539 return infoPtr
->nNotifyFormat
;
1547 HEADER_MouseLeave (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1549 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1550 /* Reset hot-tracked item when mouse leaves control. */
1551 INT oldHotItem
= infoPtr
->iHotItem
;
1552 HDC hdc
= GetDC (hwnd
);
1554 infoPtr
->iHotItem
= -1;
1555 if (oldHotItem
!= -1) HEADER_RefreshItem (hwnd
, hdc
, oldHotItem
);
1556 ReleaseDC (hwnd
, hdc
);
1563 HEADER_MouseMove (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1565 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1566 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1571 /* With theming, hottracking is always enabled */
1572 BOOL hotTrackEnabled
=
1573 ((dwStyle
& HDS_BUTTONS
) && (dwStyle
& HDS_HOTTRACK
))
1574 || (GetWindowTheme (hwnd
) != NULL
);
1575 INT oldHotItem
= infoPtr
->iHotItem
;
1577 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1578 pt
.y
= (INT
)(SHORT
)HIWORD(lParam
);
1579 HEADER_InternalHitTest (hwnd
, &pt
, &flags
, &nItem
);
1581 if (hotTrackEnabled
) {
1582 if (flags
& (HHT_ONHEADER
| HHT_ONDIVIDER
| HHT_ONDIVOPEN
))
1583 infoPtr
->iHotItem
= nItem
;
1585 infoPtr
->iHotItem
= -1;
1588 if (infoPtr
->bCaptured
) {
1589 if (infoPtr
->bPressed
) {
1590 BOOL oldState
= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
;
1591 if ((nItem
== infoPtr
->iMoveItem
) && (flags
== HHT_ONHEADER
))
1592 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= TRUE
;
1594 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1595 if (oldState
!= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
) {
1597 HEADER_RefreshItem (hwnd
, hdc
, infoPtr
->iMoveItem
);
1598 ReleaseDC (hwnd
, hdc
);
1601 TRACE("Moving pressed item %d!\n", infoPtr
->iMoveItem
);
1603 else if (infoPtr
->bTracking
) {
1604 if (dwStyle
& HDS_FULLDRAG
) {
1605 if (!HEADER_SendHeaderNotifyT (hwnd
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, NULL
))
1607 nWidth
= pt
.x
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
+ infoPtr
->xTrackOffset
;
1610 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= nWidth
;
1611 HEADER_SendHeaderNotifyT(hwnd
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, NULL
);
1613 HEADER_SetItemBounds (hwnd
);
1614 InvalidateRect(hwnd
, NULL
, FALSE
);
1618 HEADER_DrawTrackLine (hwnd
, hdc
, infoPtr
->xOldTrack
);
1619 infoPtr
->xOldTrack
= pt
.x
+ infoPtr
->xTrackOffset
;
1620 if (infoPtr
->xOldTrack
< infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
)
1621 infoPtr
->xOldTrack
= infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1622 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
=
1623 infoPtr
->xOldTrack
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1624 HEADER_DrawTrackLine (hwnd
, hdc
, infoPtr
->xOldTrack
);
1625 ReleaseDC (hwnd
, hdc
);
1626 HEADER_SendHeaderNotifyT (hwnd
, HDN_TRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, NULL
);
1629 TRACE("Tracking item %d!\n", infoPtr
->iMoveItem
);
1633 if (hotTrackEnabled
) {
1634 TRACKMOUSEEVENT tme
;
1635 if (oldHotItem
!= infoPtr
->iHotItem
) {
1637 if (oldHotItem
!= -1) HEADER_RefreshItem (hwnd
, hdc
, oldHotItem
);
1638 if (infoPtr
->iHotItem
!= -1) HEADER_RefreshItem (hwnd
, hdc
, infoPtr
->iHotItem
);
1639 ReleaseDC (hwnd
, hdc
);
1641 tme
.cbSize
= sizeof( tme
);
1642 tme
.dwFlags
= TME_LEAVE
;
1643 tme
.hwndTrack
= hwnd
;
1644 TrackMouseEvent( &tme
);
1652 HEADER_Paint (HWND hwnd
, WPARAM wParam
)
1657 hdc
= wParam
==0 ? BeginPaint (hwnd
, &ps
) : (HDC
)wParam
;
1658 HEADER_Refresh (hwnd
, hdc
);
1660 EndPaint (hwnd
, &ps
);
1666 HEADER_RButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1671 pt
.x
= LOWORD(lParam
);
1672 pt
.y
= HIWORD(lParam
);
1674 /* Send a Notify message */
1675 bRet
= HEADER_SendSimpleNotify (hwnd
, NM_RCLICK
);
1677 /* Change to screen coordinate for WM_CONTEXTMENU */
1678 ClientToScreen(hwnd
, &pt
);
1680 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1681 SendMessageW( hwnd
, WM_CONTEXTMENU
, (WPARAM
) hwnd
, MAKELPARAM(pt
.x
, pt
.y
));
1688 HEADER_SetCursor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1690 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1695 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam
), HIWORD(lParam
));
1698 ScreenToClient (hwnd
, &pt
);
1700 HEADER_InternalHitTest (hwnd
, &pt
, &flags
, &nItem
);
1702 if (flags
== HHT_ONDIVIDER
)
1703 SetCursor (infoPtr
->hcurDivider
);
1704 else if (flags
== HHT_ONDIVOPEN
)
1705 SetCursor (infoPtr
->hcurDivopen
);
1707 SetCursor (infoPtr
->hcurArrow
);
1714 HEADER_SetFont (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1716 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1718 HFONT hFont
, hOldFont
;
1721 infoPtr
->hFont
= (HFONT
)wParam
;
1723 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
);
1726 hOldFont
= SelectObject (hdc
, hFont
);
1727 GetTextMetricsW (hdc
, &tm
);
1728 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
1729 SelectObject (hdc
, hOldFont
);
1732 infoPtr
->bRectsValid
= FALSE
;
1735 InvalidateRect(hwnd
, NULL
, FALSE
);
1741 /* Update the theme handle after a theme change */
1742 static LRESULT
HEADER_ThemeChanged(HWND hwnd
)
1744 HTHEME theme
= GetWindowTheme(hwnd
);
1745 CloseThemeData(theme
);
1746 OpenThemeData(hwnd
, themeClass
);
1747 InvalidateRect(hwnd
, NULL
, FALSE
);
1752 static LRESULT WINAPI
1753 HEADER_WindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1755 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd
, msg
, wParam
, lParam
);
1756 if (!HEADER_GetInfoPtr (hwnd
) && (msg
!= WM_CREATE
))
1757 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
1759 /* case HDM_CLEARFILTER: */
1761 case HDM_CREATEDRAGIMAGE
:
1762 return HEADER_CreateDragImage (hwnd
, wParam
);
1764 case HDM_DELETEITEM
:
1765 return HEADER_DeleteItem (hwnd
, wParam
);
1767 /* case HDM_EDITFILTER: */
1769 case HDM_GETBITMAPMARGIN
:
1770 return HEADER_GetBitmapMargin(hwnd
);
1772 case HDM_GETIMAGELIST
:
1773 return HEADER_GetImageList (hwnd
);
1777 return HEADER_GetItemT (hwnd
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_GETITEMW
);
1779 case HDM_GETITEMCOUNT
:
1780 return HEADER_GetItemCount (hwnd
);
1782 case HDM_GETITEMRECT
:
1783 return HEADER_GetItemRect (hwnd
, wParam
, lParam
);
1785 case HDM_GETORDERARRAY
:
1786 return HEADER_GetOrderArray(hwnd
, wParam
, lParam
);
1788 case HDM_GETUNICODEFORMAT
:
1789 return HEADER_GetUnicodeFormat (hwnd
);
1792 return HEADER_HitTest (hwnd
, wParam
, lParam
);
1794 case HDM_INSERTITEMA
:
1795 case HDM_INSERTITEMW
:
1796 return HEADER_InsertItemT (hwnd
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_INSERTITEMW
);
1799 return HEADER_Layout (hwnd
, wParam
, lParam
);
1801 case HDM_ORDERTOINDEX
:
1802 return HEADER_OrderToIndex(hwnd
, wParam
);
1804 case HDM_SETBITMAPMARGIN
:
1805 return HEADER_SetBitmapMargin(hwnd
, wParam
);
1807 /* case HDM_SETFILTERCHANGETIMEOUT: */
1809 /* case HDM_SETHOTDIVIDER: */
1811 case HDM_SETIMAGELIST
:
1812 return HEADER_SetImageList (hwnd
, (HIMAGELIST
)lParam
);
1816 return HEADER_SetItemT (hwnd
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_SETITEMW
);
1818 case HDM_SETORDERARRAY
:
1819 return HEADER_SetOrderArray(hwnd
, wParam
, lParam
);
1821 case HDM_SETUNICODEFORMAT
:
1822 return HEADER_SetUnicodeFormat (hwnd
, wParam
);
1825 return HEADER_Create (hwnd
, wParam
, lParam
);
1828 return HEADER_Destroy (hwnd
, wParam
, lParam
);
1834 return DLGC_WANTTAB
| DLGC_WANTARROWS
;
1837 return HEADER_GetFont (hwnd
);
1839 case WM_LBUTTONDBLCLK
:
1840 return HEADER_LButtonDblClk (hwnd
, wParam
, lParam
);
1842 case WM_LBUTTONDOWN
:
1843 return HEADER_LButtonDown (hwnd
, wParam
, lParam
);
1846 return HEADER_LButtonUp (hwnd
, wParam
, lParam
);
1849 return HEADER_MouseLeave (hwnd
, wParam
, lParam
);
1852 return HEADER_MouseMove (hwnd
, wParam
, lParam
);
1854 case WM_NOTIFYFORMAT
:
1855 return HEADER_NotifyFormat (hwnd
, wParam
, lParam
);
1858 return HEADER_Size (hwnd
, wParam
);
1860 case WM_THEMECHANGED
:
1861 return HEADER_ThemeChanged (hwnd
);
1863 case WM_PRINTCLIENT
:
1865 return HEADER_Paint (hwnd
, wParam
);
1868 return HEADER_RButtonUp (hwnd
, wParam
, lParam
);
1871 return HEADER_SetCursor (hwnd
, wParam
, lParam
);
1874 return HEADER_SetFont (hwnd
, wParam
, lParam
);
1877 if ((msg
>= WM_USER
) && (msg
< WM_APP
))
1878 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1879 msg
, wParam
, lParam
);
1880 return DefWindowProcA (hwnd
, msg
, wParam
, lParam
);
1886 HEADER_Register (void)
1890 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
1891 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
1892 wndClass
.lpfnWndProc
= HEADER_WindowProc
;
1893 wndClass
.cbClsExtra
= 0;
1894 wndClass
.cbWndExtra
= sizeof(HEADER_INFO
*);
1895 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1896 wndClass
.lpszClassName
= WC_HEADERW
;
1898 RegisterClassW (&wndClass
);
1903 HEADER_Unregister (void)
1905 UnregisterClassW (WC_HEADERW
, NULL
);