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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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
40 #include "wine/unicode.h"
46 #include "imagelist.h"
49 #include "wine/debug.h"
51 WINE_DEFAULT_DEBUG_CHANNEL(header
);
61 INT iOrder
; /* see documentation of HD_ITEM */
63 BOOL bDown
; /* is item pressed? (used for drawing) */
64 RECT rect
; /* bounding rectangle of the item */
65 DWORD callbackMask
; /* HDI_* flags for items that are callback */
71 HWND hwndNotify
; /* Owner window to send notifications to */
72 INT nNotifyFormat
; /* format used for WM_NOTIFY messages */
73 UINT uNumItem
; /* number of items (columns) */
74 INT nHeight
; /* height of the header (pixels) */
75 HFONT hFont
; /* handle to the current font */
76 HCURSOR hcurArrow
; /* handle to the arrow cursor */
77 HCURSOR hcurDivider
; /* handle to a cursor (used over dividers) <-|-> */
78 HCURSOR hcurDivopen
; /* handle to a cursor (used over dividers) <-||-> */
79 BOOL bCaptured
; /* Is the mouse captured? */
80 BOOL bPressed
; /* Is a header item pressed (down)? */
81 BOOL bDragging
; /* Are we dragging an item? */
82 BOOL bTracking
; /* Is in tracking mode? */
83 POINT ptLButtonDown
; /* The point where the left button was pressed */
84 INT iMoveItem
; /* index of tracked item. (Tracking mode) */
85 INT xTrackOffset
; /* distance between the right side of the tracked item and the cursor */
86 INT xOldTrack
; /* track offset (see above) after the last WM_MOUSEMOVE */
87 INT nOldWidth
; /* width of a sizing item after the last WM_MOUSEMOVE */
88 INT iHotItem
; /* index of hot item (cursor is over this item) */
89 INT iHotDivider
; /* index of the hot divider (used while dragging an item or by HDM_SETHOTDIVIDER) */
90 INT iMargin
; /* width of the margin that surrounds a bitmap */
92 HIMAGELIST himl
; /* handle to an image list (may be 0) */
93 HEADER_ITEM
*items
; /* pointer to array of HEADER_ITEM's */
94 INT
*order
; /* array of item IDs indexed by order */
95 BOOL bRectsValid
; /* validity flag for bounding rectangles */
100 #define DIVIDER_WIDTH 10
101 #define HOT_DIVIDER_WIDTH 2
102 #define MAX_HEADER_TEXT_LEN 260
103 #define HDN_UNICODE_OFFSET 20
104 #define HDN_FIRST_UNICODE (HDN_FIRST-HDN_UNICODE_OFFSET)
106 #define HDI_SUPPORTED_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP|HDI_IMAGE|HDI_ORDER)
107 #define HDI_UNSUPPORTED_FIELDS (HDI_FILTER)
108 #define HDI_UNKNOWN_FIELDS (~(HDI_SUPPORTED_FIELDS|HDI_UNSUPPORTED_FIELDS|HDI_DI_SETITEM))
109 #define HDI_COMCTL32_4_0_FIELDS (HDI_WIDTH|HDI_TEXT|HDI_FORMAT|HDI_LPARAM|HDI_BITMAP)
111 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongPtrW(hwnd,0))
113 static BOOL
HEADER_PrepareCallbackItems(HWND hwnd
, INT iItem
, INT reqMask
);
114 static void HEADER_FreeCallbackItems(HEADER_ITEM
*lpItem
);
116 static const WCHAR themeClass
[] = {'H','e','a','d','e','r',0};
117 static WCHAR emptyString
[] = {0};
119 static void HEADER_DisposeItem(HEADER_ITEM
*lpItem
)
123 Free(lpItem
->pszText
);
127 static void HEADER_StoreHDItemInHeader(HEADER_ITEM
*lpItem
, UINT mask
, HDITEMW
*phdi
, BOOL fUnicode
)
129 if (mask
& HDI_UNSUPPORTED_FIELDS
)
130 FIXME("unsupported header fields %x\n", (mask
& HDI_UNSUPPORTED_FIELDS
));
132 if (mask
& HDI_BITMAP
)
133 lpItem
->hbm
= phdi
->hbm
;
135 if (mask
& HDI_FORMAT
)
136 lpItem
->fmt
= phdi
->fmt
;
138 if (mask
& HDI_LPARAM
)
139 lpItem
->lParam
= phdi
->lParam
;
141 if (mask
& HDI_WIDTH
)
142 lpItem
->cxy
= phdi
->cxy
;
144 if (mask
& HDI_IMAGE
)
146 lpItem
->iImage
= phdi
->iImage
;
147 if (phdi
->iImage
== I_IMAGECALLBACK
)
148 lpItem
->callbackMask
|= HDI_IMAGE
;
150 lpItem
->callbackMask
&= ~HDI_IMAGE
;
157 Free(lpItem
->pszText
);
158 lpItem
->pszText
= NULL
;
161 if (phdi
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers != TEXTCALLBACKA too */
163 LPWSTR pszText
= (phdi
->pszText
!= NULL
? phdi
->pszText
: emptyString
);
165 Str_SetPtrW(&lpItem
->pszText
, pszText
);
167 Str_SetPtrAtoW(&lpItem
->pszText
, (LPSTR
)pszText
);
168 lpItem
->callbackMask
&= ~HDI_TEXT
;
172 lpItem
->pszText
= NULL
;
173 lpItem
->callbackMask
|= HDI_TEXT
;
178 inline static LRESULT
179 HEADER_IndexToOrder (HWND hwnd
, INT iItem
)
181 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
182 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
183 return lpItem
->iOrder
;
188 HEADER_OrderToIndex(HWND hwnd
, WPARAM wParam
)
190 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
191 INT iorder
= (INT
)wParam
;
193 if ((iorder
<0) || iorder
>= infoPtr
->uNumItem
)
195 return infoPtr
->order
[iorder
];
199 HEADER_ChangeItemOrder(HEADER_INFO
*infoPtr
, INT iItem
, INT iNewOrder
)
201 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
204 TRACE("%d: %d->%d\n", iItem
, lpItem
->iOrder
, iNewOrder
);
205 if (lpItem
->iOrder
< iNewOrder
)
207 memmove(&infoPtr
->order
[lpItem
->iOrder
],
208 &infoPtr
->order
[lpItem
->iOrder
+ 1],
209 (iNewOrder
- lpItem
->iOrder
) * sizeof(INT
));
211 if (iNewOrder
< lpItem
->iOrder
)
213 memmove(&infoPtr
->order
[iNewOrder
+ 1],
214 &infoPtr
->order
[iNewOrder
],
215 (lpItem
->iOrder
- iNewOrder
) * sizeof(INT
));
217 infoPtr
->order
[iNewOrder
] = iItem
;
218 nMin
= min(lpItem
->iOrder
, iNewOrder
);
219 nMax
= max(lpItem
->iOrder
, iNewOrder
);
220 for (i
= nMin
; i
<= nMax
; i
++)
221 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= i
;
224 /* Note: if iItem is the last item then this function returns infoPtr->uNumItem */
226 HEADER_NextItem(HWND hwnd
, INT iItem
)
228 return HEADER_OrderToIndex(hwnd
, HEADER_IndexToOrder(hwnd
, iItem
)+1);
232 HEADER_PrevItem(HWND hwnd
, INT iItem
)
234 return HEADER_OrderToIndex(hwnd
, HEADER_IndexToOrder(hwnd
, iItem
)-1);
238 HEADER_SetItemBounds (HWND hwnd
)
240 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
246 infoPtr
->bRectsValid
= TRUE
;
248 if (infoPtr
->uNumItem
== 0)
251 GetClientRect (hwnd
, &rect
);
254 for (i
= 0; i
< infoPtr
->uNumItem
; i
++) {
255 phdi
= &infoPtr
->items
[HEADER_OrderToIndex(hwnd
,i
)];
256 phdi
->rect
.top
= rect
.top
;
257 phdi
->rect
.bottom
= rect
.bottom
;
259 phdi
->rect
.right
= phdi
->rect
.left
+ ((phdi
->cxy
>0)?phdi
->cxy
:0);
260 x
= phdi
->rect
.right
;
265 HEADER_Size (HWND hwnd
, WPARAM wParam
)
267 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
269 infoPtr
->bRectsValid
= FALSE
;
274 static void HEADER_GetHotDividerRect(HWND hwnd
, HEADER_INFO
*infoPtr
, RECT
*r
)
276 INT iDivider
= infoPtr
->iHotDivider
;
277 if (infoPtr
->uNumItem
> 0)
281 if (iDivider
< infoPtr
->uNumItem
)
283 lpItem
= &infoPtr
->items
[iDivider
];
284 r
->left
= lpItem
->rect
.left
- HOT_DIVIDER_WIDTH
/2;
285 r
->right
= lpItem
->rect
.left
+ HOT_DIVIDER_WIDTH
/2;
289 lpItem
= &infoPtr
->items
[HEADER_OrderToIndex(hwnd
, infoPtr
->uNumItem
-1)];
290 r
->left
= lpItem
->rect
.right
- HOT_DIVIDER_WIDTH
/2;
291 r
->right
= lpItem
->rect
.right
+ HOT_DIVIDER_WIDTH
/2;
293 r
->top
= lpItem
->rect
.top
;
294 r
->bottom
= lpItem
->rect
.bottom
;
299 GetClientRect(hwnd
, &clientRect
);
301 r
->right
= r
->left
+ HOT_DIVIDER_WIDTH
/2;
307 HEADER_DrawItem (HWND hwnd
, HDC hdc
, INT iItem
, BOOL bHotTrack
)
309 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
310 HEADER_ITEM
*phdi
= &infoPtr
->items
[iItem
];
312 INT oldBkMode
, cxEdge
= GetSystemMetrics(SM_CXEDGE
);
313 HTHEME theme
= GetWindowTheme (hwnd
);
316 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem
, bHotTrack
, (infoPtr
->nNotifyFormat
== NFR_UNICODE
));
318 if (!infoPtr
->bRectsValid
)
319 HEADER_SetItemBounds(hwnd
);
322 if (r
.right
- r
.left
== 0)
323 return phdi
->rect
.right
;
326 int state
= (phdi
->bDown
) ? HIS_PRESSED
:
327 (bHotTrack
? HIS_HOT
: HIS_NORMAL
);
328 DrawThemeBackground (theme
, hdc
, HP_HEADERITEM
, state
,
330 GetThemeBackgroundContentRect (theme
, hdc
, HP_HEADERITEM
, state
,
334 if (GetWindowLongW (hwnd
, GWL_STYLE
) & 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
);
354 /* Set the colors before sending NM_CUSTOMDRAW so that it can change them */
355 SetTextColor (hdc
, (bHotTrack
&& !theme
) ? COLOR_HIGHLIGHT
: COLOR_BTNTEXT
);
356 SetBkColor(hdc
, GetSysColor(COLOR_3DFACE
));
358 nmcd
.hdr
.hwndFrom
= hwnd
;
359 nmcd
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
360 nmcd
.hdr
.code
= NM_CUSTOMDRAW
;
361 nmcd
.dwDrawStage
= CDDS_PREPAINT
| CDDS_ITEM
| CDDS_ITEMPOSTERASE
;
363 nmcd
.dwItemSpec
= iItem
;
365 nmcd
.uItemState
= phdi
->bDown
? CDIS_SELECTED
: 0;
366 nmcd
.lItemlParam
= phdi
->lParam
;
368 SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
, nmcd
.hdr
.idFrom
, (LPARAM
)&nmcd
);
370 if (phdi
->fmt
& HDF_OWNERDRAW
) {
373 dis
.CtlType
= ODT_HEADER
;
374 dis
.CtlID
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
376 dis
.itemAction
= ODA_DRAWENTIRE
;
377 dis
.itemState
= phdi
->bDown
? ODS_SELECTED
: 0;
381 dis
.itemData
= phdi
->lParam
;
382 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
383 SendMessageW (infoPtr
->hwndNotify
, WM_DRAWITEM
,
384 (WPARAM
)dis
.CtlID
, (LPARAM
)&dis
);
385 if (oldBkMode
!= TRANSPARENT
)
386 SetBkMode(hdc
, oldBkMode
);
389 UINT rw
, rh
, /* width and height of r */
390 *x
= NULL
, *w
= NULL
; /* x and width of the pic (bmp or img) which is part of cnt */
391 /* cnt,txt,img,bmp */
396 HEADER_PrepareCallbackItems(hwnd
, iItem
, HDI_TEXT
|HDI_IMAGE
);
397 cw
= tw
= iw
= bw
= 0;
398 rw
= r
.right
- r
.left
;
399 rh
= r
.bottom
- r
.top
;
402 HBRUSH hbr
= CreateSolidBrush(GetBkColor(hdc
));
403 RECT rcBackground
= r
;
405 rcBackground
.right
-= cxEdge
;
406 rcBackground
.left
+= cxEdge
;
407 FillRect(hdc
, &rcBackground
, hbr
);
410 if (phdi
->fmt
& HDF_STRING
) {
413 DrawTextW (hdc
, phdi
->pszText
, -1,
414 &textRect
, DT_LEFT
|DT_VCENTER
|DT_SINGLELINE
|DT_CALCRECT
);
415 cw
= textRect
.right
- textRect
.left
+ 2 * infoPtr
->iMargin
;
418 if ((phdi
->fmt
& HDF_IMAGE
) && (infoPtr
->himl
)) {
419 iw
= infoPtr
->himl
->cx
+ 2 * infoPtr
->iMargin
;
424 if ((phdi
->fmt
& HDF_BITMAP
) && (phdi
->hbm
)) {
425 GetObjectW (phdi
->hbm
, sizeof(BITMAP
), (LPVOID
)&bmp
);
426 bw
= bmp
.bmWidth
+ 2 * infoPtr
->iMargin
;
436 /* align cx using the unclipped cw */
437 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_LEFT
)
439 else if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_CENTER
)
440 cx
= r
.left
+ rw
/ 2 - cw
/ 2;
447 if (cx
+ cw
> r
.right
)
450 tx
= cx
+ infoPtr
->iMargin
;
451 /* since cw might have changed we have to recalculate tw */
452 tw
= cw
- infoPtr
->iMargin
* 2;
456 if (phdi
->fmt
& HDF_BITMAP_ON_RIGHT
) {
457 /* put pic behind text */
458 *x
= cx
+ tw
+ infoPtr
->iMargin
* 3;
460 *x
= cx
+ infoPtr
->iMargin
;
461 /* move text behind pic */
467 /* since we're done with the layout we can
468 now calculate the position of bmp which
469 has no influence on alignment and layout
471 if ((phdi
->fmt
& HDF_JUSTIFYMASK
) == HDF_RIGHT
)
472 bx
= cx
- bw
+ infoPtr
->iMargin
;
474 bx
= cx
+ cw
+ infoPtr
->iMargin
;
478 HDC hClipDC
= GetDC(hwnd
);
479 HRGN hClipRgn
= CreateRectRgn(r
.left
, r
.top
, r
.right
, r
.bottom
);
480 SelectClipRgn(hClipDC
, hClipRgn
);
483 HDC hdcBitmap
= CreateCompatibleDC (hClipDC
);
484 SelectObject (hdcBitmap
, phdi
->hbm
);
485 BitBlt (hClipDC
, bx
, r
.top
+ ((INT
)rh
- bmp
.bmHeight
) / 2,
486 bmp
.bmWidth
, bmp
.bmHeight
, hdcBitmap
, 0, 0, SRCCOPY
);
487 DeleteDC (hdcBitmap
);
491 ImageList_DrawEx (infoPtr
->himl
, phdi
->iImage
, hClipDC
,
492 ix
, r
.top
+ ((INT
)rh
- infoPtr
->himl
->cy
) / 2,
493 infoPtr
->himl
->cx
, infoPtr
->himl
->cy
, CLR_DEFAULT
, CLR_DEFAULT
, 0);
496 DeleteObject(hClipRgn
);
497 ReleaseDC(hwnd
, hClipDC
);
500 if (((phdi
->fmt
& HDF_STRING
)
501 || (!(phdi
->fmt
& (HDF_OWNERDRAW
|HDF_STRING
|HDF_BITMAP
|
502 HDF_BITMAP_ON_RIGHT
|HDF_IMAGE
)))) /* no explicit format specified? */
503 && (phdi
->pszText
)) {
504 oldBkMode
= SetBkMode(hdc
, TRANSPARENT
);
507 DrawTextW (hdc
, phdi
->pszText
, -1,
508 &r
, DT_LEFT
|DT_END_ELLIPSIS
|DT_VCENTER
|DT_SINGLELINE
);
509 if (oldBkMode
!= TRANSPARENT
)
510 SetBkMode(hdc
, oldBkMode
);
512 HEADER_FreeCallbackItems(phdi
);
515 return phdi
->rect
.right
;
519 HEADER_DrawHotDivider(HWND hwnd
, HDC hdc
)
521 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
525 HEADER_GetHotDividerRect(hwnd
, infoPtr
, &r
);
526 brush
= CreateSolidBrush(GetSysColor(COLOR_HIGHLIGHT
));
527 FillRect(hdc
, &r
, brush
);
532 HEADER_Refresh (HWND hwnd
, HDC hdc
)
534 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
535 HFONT hFont
, hOldFont
;
540 HTHEME theme
= GetWindowTheme (hwnd
);
542 /* get rect for the bar, adjusted for the border */
543 GetClientRect (hwnd
, &rect
);
545 if (infoPtr
->bDragging
)
546 ImageList_DragShowNolock(FALSE
);
548 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
);
549 hOldFont
= SelectObject (hdc
, hFont
);
551 /* draw Background */
552 if (infoPtr
->uNumItem
== 0 && theme
== NULL
) {
553 hbrBk
= GetSysColorBrush(COLOR_3DFACE
);
554 FillRect(hdc
, &rect
, hbrBk
);
558 for (i
= 0; x
<= rect
.right
&& i
< infoPtr
->uNumItem
; i
++) {
559 int idx
= HEADER_OrderToIndex(hwnd
,i
);
560 if (RectVisible(hdc
, &infoPtr
->items
[idx
].rect
))
561 HEADER_DrawItem (hwnd
, hdc
, idx
, infoPtr
->iHotItem
== i
);
562 x
= infoPtr
->items
[idx
].rect
.right
;
565 if ((x
<= rect
.right
) && (infoPtr
->uNumItem
> 0)) {
568 DrawThemeBackground (theme
, hdc
, HP_HEADERITEM
, HIS_NORMAL
, &rect
,
572 if (GetWindowLongW (hwnd
, GWL_STYLE
) & HDS_BUTTONS
)
573 DrawEdge (hdc
, &rect
, EDGE_RAISED
, BF_TOP
|BF_LEFT
|BF_BOTTOM
|BF_SOFT
|BF_MIDDLE
);
575 DrawEdge (hdc
, &rect
, EDGE_ETCHED
, BF_BOTTOM
|BF_MIDDLE
);
579 if (infoPtr
->iHotDivider
!= -1)
580 HEADER_DrawHotDivider(hwnd
, hdc
);
582 if (infoPtr
->bDragging
)
583 ImageList_DragShowNolock(TRUE
);
584 SelectObject (hdc
, hOldFont
);
589 HEADER_RefreshItem (HWND hwnd
, HDC hdc
, INT iItem
)
591 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
592 HFONT hFont
, hOldFont
;
594 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
);
595 hOldFont
= SelectObject (hdc
, hFont
);
596 HEADER_DrawItem (hwnd
, hdc
, iItem
, infoPtr
->iHotItem
== iItem
);
597 SelectObject (hdc
, hOldFont
);
602 HEADER_InternalHitTest (HWND hwnd
, LPPOINT lpPt
, UINT
*pFlags
, INT
*pItem
)
604 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
610 GetClientRect (hwnd
, &rect
);
614 if (PtInRect (&rect
, *lpPt
))
616 if (infoPtr
->uNumItem
== 0) {
617 *pFlags
|= HHT_NOWHERE
;
623 /* somewhere inside */
624 for (iCount
= 0; iCount
< infoPtr
->uNumItem
; iCount
++) {
625 rect
= infoPtr
->items
[iCount
].rect
;
626 width
= rect
.right
- rect
.left
;
631 if (PtInRect (&rect
, *lpPt
)) {
632 if (width
<= 2 * DIVIDER_WIDTH
) {
633 *pFlags
|= HHT_ONHEADER
;
635 TRACE("ON HEADER %d\n", iCount
);
638 if (HEADER_IndexToOrder(hwnd
, iCount
) > 0) {
640 rcTest
.right
= rcTest
.left
+ DIVIDER_WIDTH
;
641 if (PtInRect (&rcTest
, *lpPt
)) {
643 *pFlags
|= HHT_ONDIVOPEN
;
644 *pItem
= HEADER_PrevItem(hwnd
, iCount
);
645 TRACE("ON DIVOPEN %d\n", *pItem
);
649 *pFlags
|= HHT_ONDIVIDER
;
650 *pItem
= HEADER_PrevItem(hwnd
, iCount
);
651 TRACE("ON DIVIDER %d\n", *pItem
);
657 rcTest
.left
= rcTest
.right
- DIVIDER_WIDTH
;
658 if (PtInRect (&rcTest
, *lpPt
)) {
659 *pFlags
|= HHT_ONDIVIDER
;
661 TRACE("ON DIVIDER %d\n", *pItem
);
665 *pFlags
|= HHT_ONHEADER
;
667 TRACE("ON HEADER %d\n", iCount
);
672 /* check for last divider part (on nowhere) */
673 rect
= infoPtr
->items
[infoPtr
->uNumItem
-1].rect
;
674 rect
.left
= rect
.right
;
675 rect
.right
+= DIVIDER_WIDTH
;
676 if (PtInRect (&rect
, *lpPt
)) {
678 *pFlags
|= HHT_ONDIVOPEN
;
679 *pItem
= infoPtr
->uNumItem
- 1;
680 TRACE("ON DIVOPEN %d\n", *pItem
);
684 *pFlags
|= HHT_ONDIVIDER
;
685 *pItem
= infoPtr
->uNumItem
-1;
686 TRACE("ON DIVIDER %d\n", *pItem
);
691 *pFlags
|= HHT_NOWHERE
;
698 if (lpPt
->x
< rect
.left
) {
700 *pFlags
|= HHT_TOLEFT
;
702 else if (lpPt
->x
> rect
.right
) {
704 *pFlags
|= HHT_TORIGHT
;
707 if (lpPt
->y
< rect
.top
) {
709 *pFlags
|= HHT_ABOVE
;
711 else if (lpPt
->y
> rect
.bottom
) {
713 *pFlags
|= HHT_BELOW
;
718 TRACE("flags=0x%X\n", *pFlags
);
724 HEADER_DrawTrackLine (HWND hwnd
, HDC hdc
, INT x
)
730 GetClientRect (hwnd
, &rect
);
732 hOldPen
= SelectObject (hdc
, GetStockObject (BLACK_PEN
));
733 oldRop
= SetROP2 (hdc
, R2_XORPEN
);
734 MoveToEx (hdc
, x
, rect
.top
, NULL
);
735 LineTo (hdc
, x
, rect
.bottom
);
736 SetROP2 (hdc
, oldRop
);
737 SelectObject (hdc
, hOldPen
);
742 * Convert a HDITEM into the correct format (ANSI/Unicode) to send it in a notify
745 * [I] infoPtr : the header that wants to send the notify
746 * [O] dest : The buffer to store the HDITEM for notify. It may be set to a HDITEMA of HDITEMW
747 * [I] src : The source HDITEM. It may be a HDITEMA or HDITEMW
748 * [I] fSourceUnicode : is src a HDITEMW or HDITEMA
749 * [O] ppvScratch : a pointer to a scratch buffer that needs to be freed after
750 * the HDITEM is no longer in use or NULL if none was needed
752 * NOTE: We depend on HDITEMA and HDITEMW having the same structure
754 static void HEADER_CopyHDItemForNotify(HEADER_INFO
*infoPtr
, HDITEMW
*dest
,
755 HDITEMW
*src
, BOOL fSourceUnicode
, LPVOID
*ppvScratch
)
760 if (src
->mask
& HDI_TEXT
&& src
->pszText
!= LPSTR_TEXTCALLBACKW
) /* covers TEXTCALLBACKA as well */
762 if (fSourceUnicode
&& infoPtr
->nNotifyFormat
!= NFR_UNICODE
)
764 dest
->pszText
= NULL
;
765 Str_SetPtrWtoA((LPSTR
*)&dest
->pszText
, src
->pszText
);
766 *ppvScratch
= dest
->pszText
;
769 if (!fSourceUnicode
&& infoPtr
->nNotifyFormat
== NFR_UNICODE
)
771 dest
->pszText
= NULL
;
772 Str_SetPtrAtoW(&dest
->pszText
, (LPSTR
)src
->pszText
);
773 *ppvScratch
= dest
->pszText
;
778 static UINT
HEADER_NotifyCodeWtoA(UINT code
)
780 /* we use the fact that all the unicode messages are in HDN_FIRST_UNICODE..HDN_LAST*/
781 if (code
>= HDN_LAST
&& code
<= HDN_FIRST_UNICODE
)
782 return code
+ HDN_UNICODE_OFFSET
;
788 HEADER_SendSimpleNotify (HWND hwnd
, UINT code
)
790 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
793 nmhdr
.hwndFrom
= hwnd
;
794 nmhdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
797 return (BOOL
)SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
798 (WPARAM
)nmhdr
.idFrom
, (LPARAM
)&nmhdr
);
802 HEADER_SendHeaderNotifyT (HWND hwnd
, UINT code
, INT iItem
, INT mask
, HDITEMW
*lpItem
)
804 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
810 /* lpItem == NULL means that we should take the actual data from the item */
813 FIXME("(): invalid parameters - lpItem == NULL and (mask & HDI_TEXT)\n");
817 nmitem
.cxy
= infoPtr
->items
[iItem
].cxy
;
818 nmitem
.hbm
= infoPtr
->items
[iItem
].hbm
;
819 nmitem
.pszText
= NULL
;
820 nmitem
.cchTextMax
= 0;
821 nmitem
.fmt
= infoPtr
->items
[iItem
].fmt
;
822 nmitem
.lParam
= infoPtr
->items
[iItem
].lParam
;
823 nmitem
.iOrder
= infoPtr
->items
[iItem
].iOrder
;
824 nmitem
.iImage
= infoPtr
->items
[iItem
].iImage
;
828 nmhdr
.hdr
.hwndFrom
= hwnd
;
829 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
830 nmhdr
.hdr
.code
= (infoPtr
->nNotifyFormat
== NFR_UNICODE
? code
: HEADER_NotifyCodeWtoA(code
));
833 nmhdr
.pitem
= lpItem
;
835 return (BOOL
)SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFY
,
836 (WPARAM
)nmhdr
.hdr
.idFrom
, (LPARAM
)&nmhdr
);
840 * Prepare callback items
841 * depends on NMHDDISPINFOW having same structure as NMHDDISPINFOA
842 * (so we handle the two cases only doing a specific cast for pszText).
843 * Checks if any of the required field are callback. If there are sends a
844 * NMHDISPINFO notify to retrieve these items. The items are stored in the
845 * HEADER_ITEM pszText and iImage fields. They should be freed with
846 * HEADER_FreeCallbackItems.
848 * @param hwnd : hwnd header container handler
849 * @param iItem : the header item id
850 * @param reqMask : required fields. If any of them is callback this function will fetch it
852 * @return TRUE on success, else FALSE
855 HEADER_PrepareCallbackItems(HWND hwnd
, INT iItem
, INT reqMask
)
857 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
858 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iItem
];
859 DWORD mask
= reqMask
& lpItem
->callbackMask
;
860 NMHDDISPINFOW dispInfo
;
861 void *pvBuffer
= NULL
;
865 if (mask
&HDI_TEXT
&& lpItem
->pszText
!= NULL
)
867 ERR("(): function called without a call to FreeCallbackItems\n");
868 Free(lpItem
->pszText
);
869 lpItem
->pszText
= NULL
;
872 memset(&dispInfo
, 0, sizeof(NMHDDISPINFOW
));
873 dispInfo
.hdr
.hwndFrom
= hwnd
;
874 dispInfo
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
875 if (infoPtr
->nNotifyFormat
== NFR_UNICODE
)
877 dispInfo
.hdr
.code
= HDN_GETDISPINFOW
;
879 pvBuffer
= Alloc(MAX_HEADER_TEXT_LEN
* sizeof(WCHAR
));
883 dispInfo
.hdr
.code
= HDN_GETDISPINFOA
;
885 pvBuffer
= Alloc(MAX_HEADER_TEXT_LEN
* sizeof(CHAR
));
887 dispInfo
.pszText
= (LPWSTR
)pvBuffer
;
888 dispInfo
.cchTextMax
= (pvBuffer
!=NULL
?MAX_HEADER_TEXT_LEN
:0);
889 dispInfo
.iItem
= iItem
;
890 dispInfo
.mask
= mask
;
891 dispInfo
.lParam
= lpItem
->lParam
;
893 TRACE("Sending HDN_GETDISPINFO%c\n", infoPtr
->nNotifyFormat
== NFR_UNICODE
?'W':'A');
894 SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
895 (WPARAM
) dispInfo
.hdr
.idFrom
,
898 TRACE("SendMessage returns(mask:0x%x,str:%s,lParam:%p)\n",
900 (infoPtr
->nNotifyFormat
== NFR_UNICODE
? debugstr_w(dispInfo
.pszText
) : (LPSTR
) dispInfo
.pszText
),
901 (void*) dispInfo
.lParam
);
903 if (mask
& HDI_IMAGE
)
904 lpItem
->iImage
= dispInfo
.iImage
;
907 if (infoPtr
->nNotifyFormat
== NFR_UNICODE
)
909 lpItem
->pszText
= (LPWSTR
)pvBuffer
;
911 /* the user might have used his own buffer */
912 if (dispInfo
.pszText
!= lpItem
->pszText
)
913 Str_GetPtrW(dispInfo
.pszText
, lpItem
->pszText
, MAX_HEADER_TEXT_LEN
);
917 Str_SetPtrAtoW(&lpItem
->pszText
, (LPSTR
)dispInfo
.pszText
);
922 if (dispInfo
.mask
& HDI_DI_SETITEM
)
924 /* make the items permanent */
925 lpItem
->callbackMask
&= ~dispInfo
.mask
;
933 * Free the items that might be allocated with HEADER_PrepareCallbackItems
936 * [I] lpItem : the item to free the data
940 HEADER_FreeCallbackItems(HEADER_ITEM
*lpItem
)
942 if (lpItem
->callbackMask
&HDI_TEXT
&& lpItem
->pszText
!= NULL
)
944 Free(lpItem
->pszText
);
945 lpItem
->pszText
= NULL
;
948 if (lpItem
->callbackMask
&HDI_IMAGE
)
949 lpItem
->iImage
= I_IMAGECALLBACK
;
953 HEADER_SendClickNotify (HWND hwnd
, UINT code
, INT iItem
)
955 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
958 nmhdr
.hdr
.hwndFrom
= hwnd
;
959 nmhdr
.hdr
.idFrom
= GetWindowLongPtrW (hwnd
, GWLP_ID
);
960 nmhdr
.hdr
.code
= code
;
965 return (BOOL
)SendMessageA (infoPtr
->hwndNotify
, WM_NOTIFY
,
966 (WPARAM
)nmhdr
.hdr
.idFrom
, (LPARAM
)&nmhdr
);
970 HEADER_CreateDragImage (HWND hwnd
, WPARAM wParam
)
972 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr(hwnd
);
975 HBITMAP hMemory
, hOldBitmap
;
980 if (wParam
< 0 || wParam
>= infoPtr
->uNumItem
)
982 lpItem
= &infoPtr
->items
[wParam
];
983 width
= lpItem
->rect
.right
- lpItem
->rect
.left
;
984 height
= lpItem
->rect
.bottom
- lpItem
->rect
.top
;
986 hDeviceDC
= GetDC(NULL
);
987 hMemoryDC
= CreateCompatibleDC(hDeviceDC
);
988 hMemory
= CreateCompatibleBitmap(hDeviceDC
, width
, height
);
989 ReleaseDC(NULL
, hDeviceDC
);
990 hOldBitmap
= SelectObject(hMemoryDC
, hMemory
);
991 SetViewportOrgEx(hMemoryDC
, -lpItem
->rect
.left
, -lpItem
->rect
.top
, NULL
);
992 HEADER_DrawItem(hwnd
, hMemoryDC
, wParam
, FALSE
);
993 hMemory
= SelectObject(hMemoryDC
, hOldBitmap
);
996 if (hMemory
== NULL
) /* if anything failed */
999 himl
= ImageList_Create(width
, height
, ILC_COLORDDB
, 1, 1);
1000 ImageList_Add(himl
, hMemory
, NULL
);
1001 DeleteObject(hMemory
);
1002 return (LRESULT
)himl
;
1006 HEADER_SetHotDivider(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1008 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr(hwnd
);
1016 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1018 HEADER_InternalHitTest (hwnd
, &pt
, &flags
, &iDivider
);
1020 if (flags
& HHT_TOLEFT
)
1022 else if (flags
& HHT_NOWHERE
|| flags
& HHT_TORIGHT
)
1023 iDivider
= infoPtr
->uNumItem
;
1026 HEADER_ITEM
*lpItem
= &infoPtr
->items
[iDivider
];
1027 if (pt
.x
> (lpItem
->rect
.left
+lpItem
->rect
.right
)/2)
1028 iDivider
= HEADER_NextItem(hwnd
, iDivider
);
1032 iDivider
= (INT
)lParam
;
1034 /* Note; wParam==FALSE, lParam==-1 is valid and is used to clear the hot divider */
1035 if (iDivider
<-1 || iDivider
>(int)infoPtr
->uNumItem
)
1038 if (iDivider
!= infoPtr
->iHotDivider
)
1040 if (infoPtr
->iHotDivider
!= -1)
1042 HEADER_GetHotDividerRect(hwnd
, infoPtr
, &r
);
1043 InvalidateRect(hwnd
, &r
, FALSE
);
1045 infoPtr
->iHotDivider
= iDivider
;
1048 HEADER_GetHotDividerRect(hwnd
, infoPtr
, &r
);
1049 InvalidateRect(hwnd
, &r
, FALSE
);
1056 HEADER_DeleteItem (HWND hwnd
, WPARAM wParam
)
1058 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr(hwnd
);
1059 INT iItem
= (INT
)wParam
;
1061 TRACE("[iItem=%d]\n", iItem
);
1063 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
1066 if (infoPtr
->uNumItem
== 1) {
1067 TRACE("Simple delete!\n");
1068 HEADER_DisposeItem(&infoPtr
->items
[0]);
1069 Free (infoPtr
->items
);
1070 Free(infoPtr
->order
);
1073 infoPtr
->uNumItem
= 0;
1076 HEADER_ITEM
*oldItems
= infoPtr
->items
;
1079 TRACE("Complex delete! [iItem=%d]\n", iItem
);
1081 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1082 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
1083 HEADER_DisposeItem(&infoPtr
->items
[iItem
]);
1084 iOrder
= infoPtr
->items
[iItem
].iOrder
;
1086 infoPtr
->uNumItem
--;
1087 infoPtr
->items
= Alloc (sizeof (HEADER_ITEM
) * infoPtr
->uNumItem
);
1088 /* pre delete copy */
1090 memcpy (&infoPtr
->items
[0], &oldItems
[0],
1091 iItem
* sizeof(HEADER_ITEM
));
1094 /* post delete copy */
1095 if (iItem
< infoPtr
->uNumItem
) {
1096 memcpy (&infoPtr
->items
[iItem
], &oldItems
[iItem
+1],
1097 (infoPtr
->uNumItem
- iItem
) * sizeof(HEADER_ITEM
));
1100 /* Correct the orders */
1101 if (iOrder
< infoPtr
->uNumItem
)
1103 memmove(&infoPtr
->order
[iOrder
], &infoPtr
->order
[iOrder
+ 1],
1104 (infoPtr
->uNumItem
- iOrder
) * sizeof(INT
));
1105 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1107 if (infoPtr
->order
[i
] > iItem
)
1108 infoPtr
->order
[i
]--;
1110 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= infoPtr
->order
[i
];
1114 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1115 TRACE("%d: order=%d, iOrder=%d, ->iOrder=%d\n", i
, infoPtr
->order
[i
], infoPtr
->items
[i
].iOrder
, infoPtr
->items
[infoPtr
->order
[i
]].iOrder
);
1119 HEADER_SetItemBounds (hwnd
);
1121 InvalidateRect(hwnd
, NULL
, FALSE
);
1128 HEADER_GetImageList (HWND hwnd
)
1130 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1132 return (LRESULT
)infoPtr
->himl
;
1137 HEADER_GetItemT (HWND hwnd
, INT nItem
, LPHDITEMW phdi
, BOOL bUnicode
)
1139 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1140 HEADER_ITEM
*lpItem
;
1141 UINT mask
= phdi
->mask
;
1146 TRACE("[nItem=%d]\n", nItem
);
1150 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
1153 if (mask
& HDI_UNKNOWN_FIELDS
)
1155 TRACE("mask %x contains unknown fields. Using only comctl32 4.0 fields\n", mask
);
1156 mask
&= HDI_COMCTL32_4_0_FIELDS
;
1159 lpItem
= &infoPtr
->items
[nItem
];
1160 HEADER_PrepareCallbackItems(hwnd
, nItem
, mask
);
1162 if (mask
& HDI_BITMAP
)
1163 phdi
->hbm
= lpItem
->hbm
;
1165 if (mask
& HDI_FORMAT
)
1166 phdi
->fmt
= lpItem
->fmt
;
1168 if (mask
& HDI_WIDTH
)
1169 phdi
->cxy
= lpItem
->cxy
;
1171 if (mask
& HDI_LPARAM
)
1172 phdi
->lParam
= lpItem
->lParam
;
1174 if (mask
& HDI_IMAGE
)
1175 phdi
->iImage
= lpItem
->iImage
;
1177 if (mask
& HDI_ORDER
)
1178 phdi
->iOrder
= lpItem
->iOrder
;
1180 if (mask
& HDI_TEXT
)
1183 Str_GetPtrW (lpItem
->pszText
, phdi
->pszText
, phdi
->cchTextMax
);
1185 Str_GetPtrWtoA (lpItem
->pszText
, (LPSTR
)phdi
->pszText
, phdi
->cchTextMax
);
1188 HEADER_FreeCallbackItems(lpItem
);
1193 inline static LRESULT
1194 HEADER_GetItemCount (HWND hwnd
)
1196 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1197 return infoPtr
->uNumItem
;
1202 HEADER_GetItemRect (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1204 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1205 INT iItem
= (INT
)wParam
;
1206 LPRECT lpRect
= (LPRECT
)lParam
;
1208 if ((iItem
< 0) || (iItem
>= (INT
)infoPtr
->uNumItem
))
1211 lpRect
->left
= infoPtr
->items
[iItem
].rect
.left
;
1212 lpRect
->right
= infoPtr
->items
[iItem
].rect
.right
;
1213 lpRect
->top
= infoPtr
->items
[iItem
].rect
.top
;
1214 lpRect
->bottom
= infoPtr
->items
[iItem
].rect
.bottom
;
1221 HEADER_GetOrderArray(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1223 LPINT order
= (LPINT
) lParam
;
1224 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1226 if ((unsigned int)wParam
<infoPtr
->uNumItem
)
1229 memcpy(order
, infoPtr
->order
, infoPtr
->uNumItem
* sizeof(INT
));
1234 HEADER_SetOrderArray(HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1237 LPINT order
= (LPINT
) lParam
;
1238 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1239 HEADER_ITEM
*lpItem
;
1241 if ((unsigned int)wParam
<infoPtr
->uNumItem
)
1243 memcpy(infoPtr
->order
, order
, infoPtr
->uNumItem
* sizeof(INT
));
1244 for (i
=0; i
<(int)wParam
; i
++)
1246 lpItem
= &infoPtr
->items
[*order
++];
1249 infoPtr
->bRectsValid
=0;
1250 InvalidateRect(hwnd
, NULL
, FALSE
);
1254 inline static LRESULT
1255 HEADER_GetUnicodeFormat (HWND hwnd
)
1257 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1258 return (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1263 HEADER_HitTest (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1265 LPHDHITTESTINFO phti
= (LPHDHITTESTINFO
)lParam
;
1267 HEADER_InternalHitTest (hwnd
, &phti
->pt
, &phti
->flags
, &phti
->iItem
);
1269 if (phti
->flags
== HHT_NOWHERE
)
1277 HEADER_InsertItemT (HWND hwnd
, INT nItem
, LPHDITEMW phdi
, BOOL bUnicode
)
1279 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1280 HEADER_ITEM
*lpItem
;
1285 if ((phdi
== NULL
) || (nItem
< 0) || (phdi
->mask
== 0))
1288 if (nItem
> infoPtr
->uNumItem
)
1289 nItem
= infoPtr
->uNumItem
;
1291 iOrder
= (phdi
->mask
& HDI_ORDER
) ? phdi
->iOrder
: nItem
;
1294 else if (infoPtr
->uNumItem
< iOrder
)
1295 iOrder
= infoPtr
->uNumItem
;
1297 if (infoPtr
->uNumItem
== 0) {
1298 infoPtr
->items
= Alloc (sizeof (HEADER_ITEM
));
1299 infoPtr
->order
= Alloc(sizeof(INT
));
1300 infoPtr
->uNumItem
++;
1303 HEADER_ITEM
*oldItems
= infoPtr
->items
;
1304 INT
*oldOrder
= infoPtr
->order
;
1306 infoPtr
->uNumItem
++;
1307 infoPtr
->items
= Alloc (sizeof (HEADER_ITEM
) * infoPtr
->uNumItem
);
1309 memcpy (&infoPtr
->items
[1], &oldItems
[0],
1310 (infoPtr
->uNumItem
-1) * sizeof(HEADER_ITEM
));
1314 /* pre insert copy */
1316 memcpy (&infoPtr
->items
[0], &oldItems
[0],
1317 nItem
* sizeof(HEADER_ITEM
));
1320 /* post insert copy */
1321 if (nItem
< infoPtr
->uNumItem
- 1) {
1322 memcpy (&infoPtr
->items
[nItem
+1], &oldItems
[nItem
],
1323 (infoPtr
->uNumItem
- nItem
- 1) * sizeof(HEADER_ITEM
));
1327 infoPtr
->order
= Alloc(sizeof(INT
) * infoPtr
->uNumItem
);
1328 memcpy(infoPtr
->order
, oldOrder
, iOrder
* sizeof(INT
));
1329 infoPtr
->order
[iOrder
] = nItem
;
1330 memcpy(&infoPtr
->order
[iOrder
+ 1], &oldOrder
[iOrder
],
1331 (infoPtr
->uNumItem
- iOrder
- 1) * sizeof(INT
));
1337 for (i
= 0; i
< infoPtr
->uNumItem
; i
++)
1339 if (i
!= iOrder
&& infoPtr
->order
[i
] >= nItem
)
1340 infoPtr
->order
[i
]++;
1341 infoPtr
->items
[infoPtr
->order
[i
]].iOrder
= infoPtr
->order
[i
];
1344 lpItem
= &infoPtr
->items
[nItem
];
1345 ZeroMemory(lpItem
, sizeof(HEADER_ITEM
));
1346 /* cxy, fmt and lParam are copied even if not in the HDITEM mask */
1347 copyMask
= phdi
->mask
| HDI_WIDTH
| HDI_FORMAT
| HDI_LPARAM
;
1348 HEADER_StoreHDItemInHeader(lpItem
, copyMask
, phdi
, bUnicode
);
1350 /* set automatically some format bits */
1351 if (phdi
->mask
& HDI_TEXT
)
1352 lpItem
->fmt
|= HDF_STRING
;
1354 lpItem
->fmt
&= ~HDF_STRING
;
1356 if (lpItem
->hbm
!= NULL
)
1357 lpItem
->fmt
|= HDF_BITMAP
;
1359 lpItem
->fmt
&= ~HDF_BITMAP
;
1361 if (phdi
->mask
& HDI_IMAGE
)
1362 lpItem
->fmt
|= HDF_IMAGE
;
1364 lpItem
->iOrder
= iOrder
;
1366 HEADER_SetItemBounds (hwnd
);
1368 InvalidateRect(hwnd
, NULL
, FALSE
);
1375 HEADER_Layout (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1377 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1378 LPHDLAYOUT lpLayout
= (LPHDLAYOUT
)lParam
;
1380 lpLayout
->pwpos
->hwnd
= hwnd
;
1381 lpLayout
->pwpos
->hwndInsertAfter
= 0;
1382 lpLayout
->pwpos
->x
= lpLayout
->prc
->left
;
1383 lpLayout
->pwpos
->y
= lpLayout
->prc
->top
;
1384 lpLayout
->pwpos
->cx
= lpLayout
->prc
->right
- lpLayout
->prc
->left
;
1385 if (GetWindowLongW (hwnd
, GWL_STYLE
) & HDS_HIDDEN
)
1386 lpLayout
->pwpos
->cy
= 0;
1388 lpLayout
->pwpos
->cy
= infoPtr
->nHeight
;
1389 lpLayout
->prc
->top
+= infoPtr
->nHeight
;
1391 lpLayout
->pwpos
->flags
= SWP_NOZORDER
;
1393 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1394 lpLayout
->pwpos
->x
, lpLayout
->pwpos
->y
,
1395 lpLayout
->pwpos
->cx
, lpLayout
->pwpos
->cy
);
1397 infoPtr
->bRectsValid
= FALSE
;
1404 HEADER_SetImageList (HWND hwnd
, HIMAGELIST himl
)
1406 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1409 TRACE("(himl %p)\n", himl
);
1410 himlOld
= infoPtr
->himl
;
1411 infoPtr
->himl
= himl
;
1413 /* FIXME: Refresh needed??? */
1415 return (LRESULT
)himlOld
;
1420 HEADER_GetBitmapMargin(HWND hwnd
)
1422 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr(hwnd
);
1424 return infoPtr
->iMargin
;
1428 HEADER_SetBitmapMargin(HWND hwnd
, WPARAM wParam
)
1430 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1431 INT oldMargin
= infoPtr
->iMargin
;
1433 infoPtr
->iMargin
= (INT
)wParam
;
1439 HEADER_SetItemT (HWND hwnd
, INT nItem
, LPHDITEMW phdi
, BOOL bUnicode
)
1441 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1442 HEADER_ITEM
*lpItem
;
1448 if ((nItem
< 0) || (nItem
>= (INT
)infoPtr
->uNumItem
))
1451 TRACE("[nItem=%d]\n", nItem
);
1453 HEADER_CopyHDItemForNotify(infoPtr
, &hdNotify
, phdi
, bUnicode
, &pvScratch
);
1454 if (HEADER_SendHeaderNotifyT (hwnd
, HDN_ITEMCHANGINGW
, nItem
, phdi
->mask
, &hdNotify
))
1456 if (pvScratch
) Free(pvScratch
);
1460 lpItem
= &infoPtr
->items
[nItem
];
1461 HEADER_StoreHDItemInHeader(lpItem
, phdi
->mask
, phdi
, bUnicode
);
1463 /* FIXME: check it order is not out of bound */
1464 if (phdi
->mask
& HDI_ORDER
)
1465 HEADER_ChangeItemOrder(infoPtr
, nItem
, phdi
->iOrder
);
1467 HEADER_SendHeaderNotifyT (hwnd
, HDN_ITEMCHANGEDW
, nItem
, phdi
->mask
, &hdNotify
);
1469 HEADER_SetItemBounds (hwnd
);
1471 InvalidateRect(hwnd
, NULL
, FALSE
);
1473 if (pvScratch
!= NULL
)
1478 inline static LRESULT
1479 HEADER_SetUnicodeFormat (HWND hwnd
, WPARAM wParam
)
1481 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1482 BOOL bTemp
= (infoPtr
->nNotifyFormat
== NFR_UNICODE
);
1484 infoPtr
->nNotifyFormat
= ((BOOL
)wParam
? NFR_UNICODE
: NFR_ANSI
);
1491 HEADER_Create (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1493 HEADER_INFO
*infoPtr
;
1498 infoPtr
= (HEADER_INFO
*)Alloc (sizeof(HEADER_INFO
));
1499 SetWindowLongPtrW (hwnd
, 0, (DWORD_PTR
)infoPtr
);
1501 infoPtr
->hwndNotify
= ((LPCREATESTRUCTA
)lParam
)->hwndParent
;
1502 infoPtr
->uNumItem
= 0;
1506 infoPtr
->bRectsValid
= FALSE
;
1507 infoPtr
->hcurArrow
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
1508 infoPtr
->hcurDivider
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDER
));
1509 infoPtr
->hcurDivopen
= LoadCursorW (COMCTL32_hModule
, MAKEINTRESOURCEW(IDC_DIVIDEROPEN
));
1510 infoPtr
->bPressed
= FALSE
;
1511 infoPtr
->bTracking
= FALSE
;
1512 infoPtr
->iMoveItem
= 0;
1514 infoPtr
->iHotItem
= -1;
1515 infoPtr
->iHotDivider
= -1;
1516 infoPtr
->iMargin
= 3*GetSystemMetrics(SM_CXEDGE
);
1517 infoPtr
->nNotifyFormat
=
1518 SendMessageW (infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)hwnd
, NF_QUERY
);
1521 hOldFont
= SelectObject (hdc
, GetStockObject (SYSTEM_FONT
));
1522 GetTextMetricsW (hdc
, &tm
);
1523 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
1524 SelectObject (hdc
, hOldFont
);
1527 OpenThemeData(hwnd
, themeClass
);
1534 HEADER_Destroy (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1536 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1537 HEADER_ITEM
*lpItem
;
1541 if (infoPtr
->items
) {
1542 lpItem
= infoPtr
->items
;
1543 for (nItem
= 0; nItem
< infoPtr
->uNumItem
; nItem
++, lpItem
++) {
1544 HEADER_DisposeItem(lpItem
);
1546 Free (infoPtr
->items
);
1550 Free(infoPtr
->order
);
1553 ImageList_Destroy (infoPtr
->himl
);
1555 SetWindowLongPtrW (hwnd
, 0, 0);
1558 theme
= GetWindowTheme(hwnd
);
1559 CloseThemeData(theme
);
1564 static inline LRESULT
1565 HEADER_GetFont (HWND hwnd
)
1567 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1569 return (LRESULT
)infoPtr
->hFont
;
1574 HEADER_IsDragDistance(HEADER_INFO
*infoPtr
, POINT
*pt
)
1576 /* Windows allows for a mouse movement before starting the drag. We use the
1577 * SM_CXDOUBLECLICK/SM_CYDOUBLECLICK as that distance.
1579 return (abs(infoPtr
->ptLButtonDown
.x
- pt
->x
)>GetSystemMetrics(SM_CXDOUBLECLK
) ||
1580 abs(infoPtr
->ptLButtonDown
.y
- pt
->y
)>GetSystemMetrics(SM_CYDOUBLECLK
));
1584 HEADER_LButtonDblClk (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1590 pt
.x
= (INT
)LOWORD(lParam
);
1591 pt
.y
= (INT
)HIWORD(lParam
);
1592 HEADER_InternalHitTest (hwnd
, &pt
, &flags
, &nItem
);
1594 if ((GetWindowLongW (hwnd
, GWL_STYLE
) & HDS_BUTTONS
) && (flags
== HHT_ONHEADER
))
1595 HEADER_SendHeaderNotifyT (hwnd
, HDN_ITEMDBLCLICKW
, nItem
, 0, NULL
);
1596 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
))
1597 HEADER_SendHeaderNotifyT (hwnd
, HDN_DIVIDERDBLCLICKW
, nItem
, 0, NULL
);
1604 HEADER_LButtonDown (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1606 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1607 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1613 pt
.x
= (INT
)LOWORD(lParam
);
1614 pt
.y
= (INT
)HIWORD(lParam
);
1615 HEADER_InternalHitTest (hwnd
, &pt
, &flags
, &nItem
);
1617 if ((dwStyle
& HDS_BUTTONS
) && (flags
== HHT_ONHEADER
)) {
1619 infoPtr
->bCaptured
= TRUE
;
1620 infoPtr
->bPressed
= TRUE
;
1621 infoPtr
->bDragging
= FALSE
;
1622 infoPtr
->iMoveItem
= nItem
;
1623 infoPtr
->ptLButtonDown
= pt
;
1625 infoPtr
->items
[nItem
].bDown
= TRUE
;
1627 /* Send WM_CUSTOMDRAW */
1629 HEADER_RefreshItem (hwnd
, hdc
, nItem
);
1630 ReleaseDC (hwnd
, hdc
);
1632 TRACE("Pressed item %d!\n", nItem
);
1634 else if ((flags
== HHT_ONDIVIDER
) || (flags
== HHT_ONDIVOPEN
)) {
1635 if (!(HEADER_SendHeaderNotifyT (hwnd
, HDN_BEGINTRACKW
, nItem
, HDI_WIDTH
, NULL
))) {
1637 infoPtr
->bCaptured
= TRUE
;
1638 infoPtr
->bTracking
= TRUE
;
1639 infoPtr
->iMoveItem
= nItem
;
1640 infoPtr
->nOldWidth
= infoPtr
->items
[nItem
].cxy
;
1641 infoPtr
->xTrackOffset
= infoPtr
->items
[nItem
].rect
.right
- pt
.x
;
1643 if (!(dwStyle
& HDS_FULLDRAG
)) {
1644 infoPtr
->xOldTrack
= infoPtr
->items
[nItem
].rect
.right
;
1646 HEADER_DrawTrackLine (hwnd
, hdc
, infoPtr
->xOldTrack
);
1647 ReleaseDC (hwnd
, hdc
);
1650 TRACE("Begin tracking item %d!\n", nItem
);
1659 HEADER_LButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1661 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1662 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1668 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1669 pt
.y
= (INT
)(SHORT
)HIWORD(lParam
);
1670 HEADER_InternalHitTest (hwnd
, &pt
, &flags
, &nItem
);
1672 if (infoPtr
->bPressed
) {
1673 if (infoPtr
->bDragging
)
1675 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1678 ImageList_DragShowNolock(FALSE
);
1679 ImageList_EndDrag();
1680 lpItem
->bDown
=FALSE
;
1682 if (infoPtr
->iHotDivider
== -1)
1684 else if (infoPtr
->iHotDivider
== infoPtr
->uNumItem
)
1685 iNewOrder
= infoPtr
->uNumItem
-1;
1688 iNewOrder
= HEADER_IndexToOrder(hwnd
, infoPtr
->iHotDivider
);
1689 if (iNewOrder
> lpItem
->iOrder
)
1693 /* FIXME: the new order field should be sent, not the old one */
1694 if (iNewOrder
!= -1 &&
1695 !HEADER_SendHeaderNotifyT(hwnd
, HDN_ENDDRAG
, infoPtr
->iMoveItem
, HDI_ORDER
, NULL
))
1697 HEADER_ChangeItemOrder(infoPtr
, infoPtr
->iMoveItem
, iNewOrder
);
1698 infoPtr
->bRectsValid
= FALSE
;
1699 InvalidateRect(hwnd
, NULL
, FALSE
);
1702 InvalidateRect(hwnd
, &infoPtr
->items
[infoPtr
->iMoveItem
].rect
, FALSE
);
1704 HEADER_SetHotDivider(hwnd
, FALSE
, -1);
1706 else if (!(dwStyle
&HDS_DRAGDROP
) || !HEADER_IsDragDistance(infoPtr
, &pt
))
1708 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1710 HEADER_RefreshItem (hwnd
, hdc
, infoPtr
->iMoveItem
);
1711 ReleaseDC (hwnd
, hdc
);
1713 HEADER_SendClickNotify (hwnd
, HDN_ITEMCLICKA
, infoPtr
->iMoveItem
);
1716 TRACE("Released item %d!\n", infoPtr
->iMoveItem
);
1717 infoPtr
->bPressed
= FALSE
;
1719 else if (infoPtr
->bTracking
) {
1720 TRACE("End tracking item %d!\n", infoPtr
->iMoveItem
);
1721 infoPtr
->bTracking
= FALSE
;
1723 HEADER_SendHeaderNotifyT (hwnd
, HDN_ENDTRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, NULL
);
1725 if (!(dwStyle
& HDS_FULLDRAG
)) {
1727 HEADER_DrawTrackLine (hwnd
, hdc
, infoPtr
->xOldTrack
);
1728 ReleaseDC (hwnd
, hdc
);
1731 if (HEADER_SendHeaderNotifyT(hwnd
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, NULL
))
1733 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= infoPtr
->nOldWidth
;
1736 nWidth
= pt
.x
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
+ infoPtr
->xTrackOffset
;
1739 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= nWidth
;
1742 HEADER_SetItemBounds (hwnd
);
1743 InvalidateRect(hwnd
, NULL
, TRUE
);
1744 HEADER_SendHeaderNotifyT(hwnd
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, NULL
);
1747 if (infoPtr
->bCaptured
) {
1748 infoPtr
->bCaptured
= FALSE
;
1750 HEADER_SendSimpleNotify (hwnd
, NM_RELEASEDCAPTURE
);
1758 HEADER_NotifyFormat (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1760 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1765 return infoPtr
->nNotifyFormat
;
1768 infoPtr
->nNotifyFormat
=
1769 SendMessageW ((HWND
)wParam
, WM_NOTIFYFORMAT
,
1770 (WPARAM
)hwnd
, (LPARAM
)NF_QUERY
);
1771 return infoPtr
->nNotifyFormat
;
1778 HEADER_MouseLeave (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1780 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1781 /* Reset hot-tracked item when mouse leaves control. */
1782 INT oldHotItem
= infoPtr
->iHotItem
;
1783 HDC hdc
= GetDC (hwnd
);
1785 infoPtr
->iHotItem
= -1;
1786 if (oldHotItem
!= -1) HEADER_RefreshItem (hwnd
, hdc
, oldHotItem
);
1787 ReleaseDC (hwnd
, hdc
);
1794 HEADER_MouseMove (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1796 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1797 DWORD dwStyle
= GetWindowLongW (hwnd
, GWL_STYLE
);
1802 /* With theming, hottracking is always enabled */
1803 BOOL hotTrackEnabled
=
1804 ((dwStyle
& HDS_BUTTONS
) && (dwStyle
& HDS_HOTTRACK
))
1805 || (GetWindowTheme (hwnd
) != NULL
);
1806 INT oldHotItem
= infoPtr
->iHotItem
;
1808 pt
.x
= (INT
)(SHORT
)LOWORD(lParam
);
1809 pt
.y
= (INT
)(SHORT
)HIWORD(lParam
);
1810 HEADER_InternalHitTest (hwnd
, &pt
, &flags
, &nItem
);
1812 if (hotTrackEnabled
) {
1813 if (flags
& (HHT_ONHEADER
| HHT_ONDIVIDER
| HHT_ONDIVOPEN
))
1814 infoPtr
->iHotItem
= nItem
;
1816 infoPtr
->iHotItem
= -1;
1819 if (infoPtr
->bCaptured
) {
1820 /* check if we should drag the header */
1821 if (infoPtr
->bPressed
&& !infoPtr
->bDragging
&& dwStyle
&HDS_DRAGDROP
1822 && HEADER_IsDragDistance(infoPtr
, &pt
))
1824 if (!HEADER_SendHeaderNotifyT(hwnd
, HDN_BEGINDRAG
, infoPtr
->iMoveItem
, 0, NULL
))
1826 HIMAGELIST hDragItem
= (HIMAGELIST
)HEADER_CreateDragImage(hwnd
, infoPtr
->iMoveItem
);
1827 if (hDragItem
!= NULL
)
1829 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1830 TRACE("Starting item drag\n");
1831 ImageList_BeginDrag(hDragItem
, 0, pt
.x
- lpItem
->rect
.left
, 0);
1832 ImageList_DragShowNolock(TRUE
);
1833 ImageList_Destroy(hDragItem
);
1834 infoPtr
->bDragging
= TRUE
;
1839 if (infoPtr
->bDragging
)
1844 ClientToScreen(hwnd
, &drag
);
1845 ImageList_DragMove(drag
.x
, drag
.y
);
1846 HEADER_SetHotDivider(hwnd
, TRUE
, lParam
);
1849 if (infoPtr
->bPressed
&& !infoPtr
->bDragging
) {
1850 BOOL oldState
= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
;
1851 if ((nItem
== infoPtr
->iMoveItem
) && (flags
== HHT_ONHEADER
))
1852 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= TRUE
;
1854 infoPtr
->items
[infoPtr
->iMoveItem
].bDown
= FALSE
;
1855 if (oldState
!= infoPtr
->items
[infoPtr
->iMoveItem
].bDown
) {
1857 HEADER_RefreshItem (hwnd
, hdc
, infoPtr
->iMoveItem
);
1858 ReleaseDC (hwnd
, hdc
);
1861 TRACE("Moving pressed item %d!\n", infoPtr
->iMoveItem
);
1863 else if (infoPtr
->bTracking
) {
1864 if (dwStyle
& HDS_FULLDRAG
) {
1865 if (!HEADER_SendHeaderNotifyT (hwnd
, HDN_ITEMCHANGINGW
, infoPtr
->iMoveItem
, HDI_WIDTH
, NULL
))
1867 HEADER_ITEM
*lpItem
= &infoPtr
->items
[infoPtr
->iMoveItem
];
1868 INT nOldWidth
= lpItem
->rect
.right
- lpItem
->rect
.left
;
1872 nWidth
= pt
.x
- lpItem
->rect
.left
+ infoPtr
->xTrackOffset
;
1873 if (nWidth
< 0) nWidth
= 0;
1874 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
= nWidth
;
1875 HEADER_SetItemBounds(hwnd
);
1877 GetClientRect(hwnd
, &rcClient
);
1878 rcScroll
= rcClient
;
1879 rcScroll
.left
= lpItem
->rect
.left
+ nOldWidth
;
1880 ScrollWindowEx(hwnd
, nWidth
- nOldWidth
, 0, &rcScroll
, &rcClient
, NULL
, NULL
, 0);
1881 InvalidateRect(hwnd
, &lpItem
->rect
, FALSE
);
1884 HEADER_SendHeaderNotifyT(hwnd
, HDN_ITEMCHANGEDW
, infoPtr
->iMoveItem
, HDI_WIDTH
, NULL
);
1889 HEADER_DrawTrackLine (hwnd
, hdc
, infoPtr
->xOldTrack
);
1890 infoPtr
->xOldTrack
= pt
.x
+ infoPtr
->xTrackOffset
;
1891 if (infoPtr
->xOldTrack
< infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
)
1892 infoPtr
->xOldTrack
= infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1893 infoPtr
->items
[infoPtr
->iMoveItem
].cxy
=
1894 infoPtr
->xOldTrack
- infoPtr
->items
[infoPtr
->iMoveItem
].rect
.left
;
1895 HEADER_DrawTrackLine (hwnd
, hdc
, infoPtr
->xOldTrack
);
1896 ReleaseDC (hwnd
, hdc
);
1897 HEADER_SendHeaderNotifyT (hwnd
, HDN_TRACKW
, infoPtr
->iMoveItem
, HDI_WIDTH
, NULL
);
1900 TRACE("Tracking item %d!\n", infoPtr
->iMoveItem
);
1904 if (hotTrackEnabled
) {
1905 TRACKMOUSEEVENT tme
;
1906 if (oldHotItem
!= infoPtr
->iHotItem
&& !infoPtr
->bDragging
) {
1908 if (oldHotItem
!= -1) HEADER_RefreshItem (hwnd
, hdc
, oldHotItem
);
1909 if (infoPtr
->iHotItem
!= -1) HEADER_RefreshItem (hwnd
, hdc
, infoPtr
->iHotItem
);
1910 ReleaseDC (hwnd
, hdc
);
1912 tme
.cbSize
= sizeof( tme
);
1913 tme
.dwFlags
= TME_LEAVE
;
1914 tme
.hwndTrack
= hwnd
;
1915 TrackMouseEvent( &tme
);
1923 HEADER_Paint (HWND hwnd
, WPARAM wParam
)
1928 hdc
= wParam
==0 ? BeginPaint (hwnd
, &ps
) : (HDC
)wParam
;
1929 HEADER_Refresh (hwnd
, hdc
);
1931 EndPaint (hwnd
, &ps
);
1937 HEADER_RButtonUp (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1942 pt
.x
= LOWORD(lParam
);
1943 pt
.y
= HIWORD(lParam
);
1945 /* Send a Notify message */
1946 bRet
= HEADER_SendSimpleNotify (hwnd
, NM_RCLICK
);
1948 /* Change to screen coordinate for WM_CONTEXTMENU */
1949 ClientToScreen(hwnd
, &pt
);
1951 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1952 SendMessageW( hwnd
, WM_CONTEXTMENU
, (WPARAM
) hwnd
, MAKELPARAM(pt
.x
, pt
.y
));
1959 HEADER_SetCursor (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1961 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1966 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam
), HIWORD(lParam
));
1969 ScreenToClient (hwnd
, &pt
);
1971 HEADER_InternalHitTest (hwnd
, &pt
, &flags
, &nItem
);
1973 if (flags
== HHT_ONDIVIDER
)
1974 SetCursor (infoPtr
->hcurDivider
);
1975 else if (flags
== HHT_ONDIVOPEN
)
1976 SetCursor (infoPtr
->hcurDivopen
);
1978 SetCursor (infoPtr
->hcurArrow
);
1985 HEADER_SetFont (HWND hwnd
, WPARAM wParam
, LPARAM lParam
)
1987 HEADER_INFO
*infoPtr
= HEADER_GetInfoPtr (hwnd
);
1989 HFONT hFont
, hOldFont
;
1992 infoPtr
->hFont
= (HFONT
)wParam
;
1994 hFont
= infoPtr
->hFont
? infoPtr
->hFont
: GetStockObject (SYSTEM_FONT
);
1997 hOldFont
= SelectObject (hdc
, hFont
);
1998 GetTextMetricsW (hdc
, &tm
);
1999 infoPtr
->nHeight
= tm
.tmHeight
+ VERT_BORDER
;
2000 SelectObject (hdc
, hOldFont
);
2003 infoPtr
->bRectsValid
= FALSE
;
2006 InvalidateRect(hwnd
, NULL
, FALSE
);
2012 /* Update the theme handle after a theme change */
2013 static LRESULT
HEADER_ThemeChanged(HWND hwnd
)
2015 HTHEME theme
= GetWindowTheme(hwnd
);
2016 CloseThemeData(theme
);
2017 OpenThemeData(hwnd
, themeClass
);
2018 InvalidateRect(hwnd
, NULL
, FALSE
);
2023 static LRESULT WINAPI
2024 HEADER_WindowProc (HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2026 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd
, msg
, wParam
, lParam
);
2027 if (!HEADER_GetInfoPtr (hwnd
) && (msg
!= WM_CREATE
))
2028 return DefWindowProcW (hwnd
, msg
, wParam
, lParam
);
2030 /* case HDM_CLEARFILTER: */
2032 case HDM_CREATEDRAGIMAGE
:
2033 return HEADER_CreateDragImage (hwnd
, wParam
);
2035 case HDM_DELETEITEM
:
2036 return HEADER_DeleteItem (hwnd
, wParam
);
2038 /* case HDM_EDITFILTER: */
2040 case HDM_GETBITMAPMARGIN
:
2041 return HEADER_GetBitmapMargin(hwnd
);
2043 case HDM_GETIMAGELIST
:
2044 return HEADER_GetImageList (hwnd
);
2048 return HEADER_GetItemT (hwnd
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_GETITEMW
);
2050 case HDM_GETITEMCOUNT
:
2051 return HEADER_GetItemCount (hwnd
);
2053 case HDM_GETITEMRECT
:
2054 return HEADER_GetItemRect (hwnd
, wParam
, lParam
);
2056 case HDM_GETORDERARRAY
:
2057 return HEADER_GetOrderArray(hwnd
, wParam
, lParam
);
2059 case HDM_GETUNICODEFORMAT
:
2060 return HEADER_GetUnicodeFormat (hwnd
);
2063 return HEADER_HitTest (hwnd
, wParam
, lParam
);
2065 case HDM_INSERTITEMA
:
2066 case HDM_INSERTITEMW
:
2067 return HEADER_InsertItemT (hwnd
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_INSERTITEMW
);
2070 return HEADER_Layout (hwnd
, wParam
, lParam
);
2072 case HDM_ORDERTOINDEX
:
2073 return HEADER_OrderToIndex(hwnd
, wParam
);
2075 case HDM_SETBITMAPMARGIN
:
2076 return HEADER_SetBitmapMargin(hwnd
, wParam
);
2078 /* case HDM_SETFILTERCHANGETIMEOUT: */
2080 case HDM_SETHOTDIVIDER
:
2081 return HEADER_SetHotDivider(hwnd
, wParam
, lParam
);
2083 case HDM_SETIMAGELIST
:
2084 return HEADER_SetImageList (hwnd
, (HIMAGELIST
)lParam
);
2088 return HEADER_SetItemT (hwnd
, (INT
)wParam
, (LPHDITEMW
)lParam
, msg
== HDM_SETITEMW
);
2090 case HDM_SETORDERARRAY
:
2091 return HEADER_SetOrderArray(hwnd
, wParam
, lParam
);
2093 case HDM_SETUNICODEFORMAT
:
2094 return HEADER_SetUnicodeFormat (hwnd
, wParam
);
2097 return HEADER_Create (hwnd
, wParam
, lParam
);
2100 return HEADER_Destroy (hwnd
, wParam
, lParam
);
2106 return DLGC_WANTTAB
| DLGC_WANTARROWS
;
2109 return HEADER_GetFont (hwnd
);
2111 case WM_LBUTTONDBLCLK
:
2112 return HEADER_LButtonDblClk (hwnd
, wParam
, lParam
);
2114 case WM_LBUTTONDOWN
:
2115 return HEADER_LButtonDown (hwnd
, wParam
, lParam
);
2118 return HEADER_LButtonUp (hwnd
, wParam
, lParam
);
2121 return HEADER_MouseLeave (hwnd
, wParam
, lParam
);
2124 return HEADER_MouseMove (hwnd
, wParam
, lParam
);
2126 case WM_NOTIFYFORMAT
:
2127 return HEADER_NotifyFormat (hwnd
, wParam
, lParam
);
2130 return HEADER_Size (hwnd
, wParam
);
2132 case WM_THEMECHANGED
:
2133 return HEADER_ThemeChanged (hwnd
);
2135 case WM_PRINTCLIENT
:
2137 return HEADER_Paint (hwnd
, wParam
);
2140 return HEADER_RButtonUp (hwnd
, wParam
, lParam
);
2143 return HEADER_SetCursor (hwnd
, wParam
, lParam
);
2146 return HEADER_SetFont (hwnd
, wParam
, lParam
);
2149 if ((msg
>= WM_USER
) && (msg
< WM_APP
))
2150 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
2151 msg
, wParam
, lParam
);
2152 return DefWindowProcA (hwnd
, msg
, wParam
, lParam
);
2158 HEADER_Register (void)
2162 ZeroMemory (&wndClass
, sizeof(WNDCLASSW
));
2163 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
2164 wndClass
.lpfnWndProc
= HEADER_WindowProc
;
2165 wndClass
.cbClsExtra
= 0;
2166 wndClass
.cbWndExtra
= sizeof(HEADER_INFO
*);
2167 wndClass
.hCursor
= LoadCursorW (0, (LPWSTR
)IDC_ARROW
);
2168 wndClass
.lpszClassName
= WC_HEADERW
;
2170 RegisterClassW (&wndClass
);
2175 HEADER_Unregister (void)
2177 UnregisterClassW (WC_HEADERW
, NULL
);