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"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(header);
58 INT iOrder; /* see documentation of HD_ITEM */
60 BOOL bDown; /* is item pressed? (used for drawing) */
61 RECT rect; /* bounding rectangle of the item */
67 HWND hwndNotify; /* Owner window to send notifications to */
68 INT nNotifyFormat; /* format used for WM_NOTIFY messages */
69 UINT uNumItem; /* number of items (columns) */
70 INT nHeight; /* height of the header (pixels) */
71 HFONT hFont; /* handle to the current font */
72 HCURSOR hcurArrow; /* handle to the arrow cursor */
73 HCURSOR hcurDivider; /* handle to a cursor (used over dividers) <-|-> */
74 HCURSOR hcurDivopen; /* handle to a cursor (used over dividers) <-||-> */
75 BOOL bCaptured; /* Is the mouse captured? */
76 BOOL bPressed; /* Is a header item pressed (down)? */
77 BOOL bTracking; /* Is in tracking mode? */
78 BOOL bUnicode; /* Unicode flag */
79 INT iMoveItem; /* index of tracked item. (Tracking mode) */
80 INT xTrackOffset; /* distance between the right side of the tracked item and the cursor */
81 INT xOldTrack; /* track offset (see above) after the last WM_MOUSEMOVE */
82 INT nOldWidth; /* width of a sizing item after the last WM_MOUSEMOVE */
83 INT iHotItem; /* index of hot item (cursor is over this item) */
84 INT iMargin; /* width of the margin that surrounds a bitmap */
86 HIMAGELIST himl; /* handle to a image list (may be 0) */
87 HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */
88 BOOL bRectsValid; /* validity flag for bounding rectangles */
93 #define DIVIDER_WIDTH 10
95 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongPtrW(hwnd,0))
99 HEADER_IndexToOrder (HWND hwnd, INT iItem)
101 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
102 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
103 return lpItem->iOrder;
108 HEADER_OrderToIndex(HWND hwnd, WPARAM wParam)
110 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
111 INT iorder = (INT)wParam;
114 if ((iorder <0) || iorder >infoPtr->uNumItem)
116 for (i=0; i<infoPtr->uNumItem; i++)
117 if (HEADER_IndexToOrder(hwnd,i) == iorder)
123 HEADER_SetItemBounds (HWND hwnd)
125 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
131 infoPtr->bRectsValid = TRUE;
133 if (infoPtr->uNumItem == 0)
136 GetClientRect (hwnd, &rect);
139 for (i = 0; i < infoPtr->uNumItem; i++) {
140 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
141 phdi->rect.top = rect.top;
142 phdi->rect.bottom = rect.bottom;
144 phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
145 x = phdi->rect.right;
150 HEADER_Size (HWND hwnd, WPARAM wParam)
152 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
154 infoPtr->bRectsValid = FALSE;
161 HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
163 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
164 HEADER_ITEM *phdi = &infoPtr->items[iItem];
168 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, infoPtr->bUnicode);
170 if (!infoPtr->bRectsValid)
171 HEADER_SetItemBounds(hwnd);
174 if (r.right - r.left == 0)
175 return phdi->rect.right;
177 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) {
179 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
180 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
185 DrawEdge (hdc, &r, EDGE_RAISED,
186 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
189 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
191 if (phdi->fmt & HDF_OWNERDRAW) {
193 dis.CtlType = ODT_HEADER;
194 dis.CtlID = GetWindowLongPtrW (hwnd, GWLP_ID);
196 dis.itemAction = ODA_DRAWENTIRE;
197 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
201 dis.itemData = phdi->lParam;
202 oldBkMode = SetBkMode(hdc, TRANSPARENT);
203 SendMessageA (infoPtr->hwndNotify, WM_DRAWITEM,
204 (WPARAM)dis.CtlID, (LPARAM)&dis);
205 if (oldBkMode != TRANSPARENT)
206 SetBkMode(hdc, oldBkMode);
209 UINT uTextJustify = DT_LEFT;
211 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
212 uTextJustify = DT_CENTER;
213 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
214 uTextJustify = DT_RIGHT;
216 if ((phdi->fmt & HDF_BITMAP) && !(phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
219 INT yD, yS, cx, cy, rx, ry;
221 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
223 ry = r.bottom - r.top;
224 rx = r.right - r.left;
226 if (ry >= bmp.bmHeight) {
228 yD = r.top + (ry - bmp.bmHeight) / 2;
234 yS = (bmp.bmHeight - ry) / 2;
238 if (rx >= bmp.bmWidth + infoPtr->iMargin) {
242 cx = rx - infoPtr->iMargin;
245 hdcBitmap = CreateCompatibleDC (hdc);
246 SelectObject (hdcBitmap, phdi->hbm);
247 BitBlt (hdc, r.left + infoPtr->iMargin, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
248 DeleteDC (hdcBitmap);
250 r.left += (bmp.bmWidth + infoPtr->iMargin);
254 if ((phdi->fmt & HDF_BITMAP) && (phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
257 INT xD, yD, yS, cx, cy, rx, ry, tx;
260 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
263 if (phdi->fmt & HDF_STRING) {
264 DrawTextW (hdc, phdi->pszText, -1,
265 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
266 tx = textRect.right - textRect.left;
270 ry = r.bottom - r.top;
271 rx = r.right - r.left;
273 if (ry >= bmp.bmHeight) {
275 yD = r.top + (ry - bmp.bmHeight) / 2;
281 yS = (bmp.bmHeight - ry) / 2;
285 if (r.left + tx + bmp.bmWidth + 2*infoPtr->iMargin <= r.right) {
287 xD = r.left + tx + infoPtr->iMargin;
290 if (rx >= bmp.bmWidth + infoPtr->iMargin ) {
292 xD = r.right - bmp.bmWidth - infoPtr->iMargin;
293 r.right = xD - infoPtr->iMargin;
296 cx = rx - infoPtr->iMargin;
302 hdcBitmap = CreateCompatibleDC (hdc);
303 SelectObject (hdcBitmap, phdi->hbm);
304 BitBlt (hdc, xD, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
305 DeleteDC (hdcBitmap);
308 if ((phdi->fmt & HDF_IMAGE) && !(phdi->fmt & HDF_BITMAP_ON_RIGHT) && (infoPtr->himl)) {
309 r.left += infoPtr->iMargin;
310 ImageList_DrawEx(infoPtr->himl, phdi->iImage, hdc, r.left, r.top + (r.bottom-r.top- infoPtr->himl->cy)/2,
311 infoPtr->himl->cx, r.bottom-r.top, CLR_DEFAULT, CLR_DEFAULT, 0);
312 r.left += infoPtr->himl->cx;
315 if ((phdi->fmt & HDF_IMAGE) && (phdi->fmt & HDF_BITMAP_ON_RIGHT) && (infoPtr->himl)) {
320 if (phdi->fmt & HDF_STRING) {
321 DrawTextW (hdc, phdi->pszText, -1,
322 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
323 tx = textRect.right - textRect.left;
327 ImageList_DrawEx(infoPtr->himl, phdi->iImage, hdc, r.left + tx + 2*infoPtr->iMargin,
328 r.top + (r.bottom-r.top-infoPtr->himl->cy)/2, infoPtr->himl->cx, r.bottom-r.top,
329 CLR_DEFAULT, CLR_DEFAULT, 0);
332 if (((phdi->fmt & HDF_STRING)
333 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
334 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
335 && (phdi->pszText)) {
336 oldBkMode = SetBkMode(hdc, TRANSPARENT);
337 r.left += infoPtr->iMargin;
338 r.right -= infoPtr->iMargin;
339 SetTextColor (hdc, (bHotTrack) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
340 DrawTextW (hdc, phdi->pszText, -1,
341 &r, uTextJustify|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
342 if (oldBkMode != TRANSPARENT)
343 SetBkMode(hdc, oldBkMode);
347 return phdi->rect.right;
352 HEADER_Refresh (HWND hwnd, HDC hdc)
354 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
355 HFONT hFont, hOldFont;
361 /* get rect for the bar, adjusted for the border */
362 GetClientRect (hwnd, &rect);
364 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
365 hOldFont = SelectObject (hdc, hFont);
367 /* draw Background */
368 hbrBk = GetSysColorBrush(COLOR_3DFACE);
369 FillRect(hdc, &rect, hbrBk);
372 for (i = 0; i < infoPtr->uNumItem; i++) {
373 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i), FALSE);
376 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
378 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS)
379 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
381 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
384 SelectObject (hdc, hOldFont);
389 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
391 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
392 HFONT hFont, hOldFont;
394 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
395 hOldFont = SelectObject (hdc, hFont);
396 HEADER_DrawItem (hwnd, hdc, iItem, FALSE);
397 SelectObject (hdc, hOldFont);
402 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
404 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
410 GetClientRect (hwnd, &rect);
414 if (PtInRect (&rect, *lpPt))
416 if (infoPtr->uNumItem == 0) {
417 *pFlags |= HHT_NOWHERE;
423 /* somewhere inside */
424 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
425 rect = infoPtr->items[iCount].rect;
426 width = rect.right - rect.left;
431 if (PtInRect (&rect, *lpPt)) {
432 if (width <= 2 * DIVIDER_WIDTH) {
433 *pFlags |= HHT_ONHEADER;
435 TRACE("ON HEADER %d\n", iCount);
440 rcTest.right = rcTest.left + DIVIDER_WIDTH;
441 if (PtInRect (&rcTest, *lpPt)) {
443 *pFlags |= HHT_ONDIVOPEN;
445 TRACE("ON DIVOPEN %d\n", *pItem);
449 *pFlags |= HHT_ONDIVIDER;
451 TRACE("ON DIVIDER %d\n", *pItem);
457 rcTest.left = rcTest.right - DIVIDER_WIDTH;
458 if (PtInRect (&rcTest, *lpPt)) {
459 *pFlags |= HHT_ONDIVIDER;
461 TRACE("ON DIVIDER %d\n", *pItem);
465 *pFlags |= HHT_ONHEADER;
467 TRACE("ON HEADER %d\n", iCount);
472 /* check for last divider part (on nowhere) */
473 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
474 rect.left = rect.right;
475 rect.right += DIVIDER_WIDTH;
476 if (PtInRect (&rect, *lpPt)) {
478 *pFlags |= HHT_ONDIVOPEN;
479 *pItem = infoPtr->uNumItem - 1;
480 TRACE("ON DIVOPEN %d\n", *pItem);
484 *pFlags |= HHT_ONDIVIDER;
485 *pItem = infoPtr->uNumItem-1;
486 TRACE("ON DIVIDER %d\n", *pItem);
491 *pFlags |= HHT_NOWHERE;
498 if (lpPt->x < rect.left) {
500 *pFlags |= HHT_TOLEFT;
502 else if (lpPt->x > rect.right) {
504 *pFlags |= HHT_TORIGHT;
507 if (lpPt->y < rect.top) {
509 *pFlags |= HHT_ABOVE;
511 else if (lpPt->y > rect.bottom) {
513 *pFlags |= HHT_BELOW;
518 TRACE("flags=0x%X\n", *pFlags);
524 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
530 GetClientRect (hwnd, &rect);
532 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
533 oldRop = SetROP2 (hdc, R2_XORPEN);
534 MoveToEx (hdc, x, rect.top, NULL);
535 LineTo (hdc, x, rect.bottom);
536 SetROP2 (hdc, oldRop);
537 SelectObject (hdc, hOldPen);
542 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
544 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
547 nmhdr.hwndFrom = hwnd;
548 nmhdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
551 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
552 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
556 HEADER_SendHeaderNotify (HWND hwnd, UINT code, INT iItem, INT mask)
558 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
562 nmhdr.hdr.hwndFrom = hwnd;
563 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
564 nmhdr.hdr.code = code;
567 nmhdr.pitem = &nmitem;
569 nmitem.cxy = infoPtr->items[iItem].cxy;
570 nmitem.hbm = infoPtr->items[iItem].hbm;
571 nmitem.pszText = NULL;
572 nmitem.cchTextMax = 0;
573 /* nmitem.pszText = infoPtr->items[iItem].pszText; */
574 /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
575 nmitem.fmt = infoPtr->items[iItem].fmt;
576 nmitem.lParam = infoPtr->items[iItem].lParam;
577 nmitem.iOrder = infoPtr->items[iItem].iOrder;
578 nmitem.iImage = infoPtr->items[iItem].iImage;
580 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
581 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
586 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
588 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
591 nmhdr.hdr.hwndFrom = hwnd;
592 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
593 nmhdr.hdr.code = code;
598 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
599 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
604 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
606 FIXME("empty stub!\n");
612 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
614 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
615 INT iItem = (INT)wParam;
617 TRACE("[iItem=%d]\n", iItem);
619 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
622 if (infoPtr->uNumItem == 1) {
623 TRACE("Simple delete!\n");
624 if (infoPtr->items[0].pszText)
625 Free (infoPtr->items[0].pszText);
626 Free (infoPtr->items);
628 infoPtr->uNumItem = 0;
631 HEADER_ITEM *oldItems = infoPtr->items;
635 TRACE("Complex delete! [iItem=%d]\n", iItem);
637 if (infoPtr->items[iItem].pszText)
638 Free (infoPtr->items[iItem].pszText);
639 iOrder = infoPtr->items[iItem].iOrder;
642 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
643 /* pre delete copy */
645 memcpy (&infoPtr->items[0], &oldItems[0],
646 iItem * sizeof(HEADER_ITEM));
649 /* post delete copy */
650 if (iItem < infoPtr->uNumItem) {
651 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
652 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
655 /* Correct the orders */
656 for (i=infoPtr->uNumItem, pItem = infoPtr->items; i; i--, pItem++)
658 if (pItem->iOrder > iOrder)
664 HEADER_SetItemBounds (hwnd);
666 InvalidateRect(hwnd, NULL, FALSE);
673 HEADER_GetImageList (HWND hwnd)
675 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
677 return (LRESULT)infoPtr->himl;
682 HEADER_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
684 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
685 HDITEMA *phdi = (HDITEMA*)lParam;
686 INT nItem = (INT)wParam;
691 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
694 TRACE("[nItem=%d]\n", nItem);
699 lpItem = &infoPtr->items[nItem];
700 if (phdi->mask & HDI_BITMAP)
701 phdi->hbm = lpItem->hbm;
703 if (phdi->mask & HDI_FORMAT)
704 phdi->fmt = lpItem->fmt;
706 if (phdi->mask & HDI_WIDTH)
707 phdi->cxy = lpItem->cxy;
709 if (phdi->mask & HDI_LPARAM)
710 phdi->lParam = lpItem->lParam;
712 if (phdi->mask & HDI_TEXT) {
713 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
715 WideCharToMultiByte (CP_ACP, 0, lpItem->pszText, -1,
716 phdi->pszText, phdi->cchTextMax, NULL, NULL);
721 phdi->pszText = LPSTR_TEXTCALLBACKA;
724 if (phdi->mask & HDI_IMAGE)
725 phdi->iImage = lpItem->iImage;
727 if (phdi->mask & HDI_ORDER)
728 phdi->iOrder = lpItem->iOrder;
735 HEADER_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
737 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
738 HDITEMW *phdi = (HDITEMW*)lParam;
739 INT nItem = (INT)wParam;
744 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
747 TRACE("[nItem=%d]\n", nItem);
752 lpItem = &infoPtr->items[nItem];
753 if (phdi->mask & HDI_BITMAP)
754 phdi->hbm = lpItem->hbm;
756 if (phdi->mask & HDI_FORMAT)
757 phdi->fmt = lpItem->fmt;
759 if (phdi->mask & HDI_WIDTH)
760 phdi->cxy = lpItem->cxy;
762 if (phdi->mask & HDI_LPARAM)
763 phdi->lParam = lpItem->lParam;
765 if (phdi->mask & HDI_TEXT) {
766 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
768 lstrcpynW (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
773 phdi->pszText = LPSTR_TEXTCALLBACKW;
776 if (phdi->mask & HDI_IMAGE)
777 phdi->iImage = lpItem->iImage;
779 if (phdi->mask & HDI_ORDER)
780 phdi->iOrder = lpItem->iOrder;
786 inline static LRESULT
787 HEADER_GetItemCount (HWND hwnd)
789 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
790 return infoPtr->uNumItem;
795 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
797 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
798 INT iItem = (INT)wParam;
799 LPRECT lpRect = (LPRECT)lParam;
801 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
804 lpRect->left = infoPtr->items[iItem].rect.left;
805 lpRect->right = infoPtr->items[iItem].rect.right;
806 lpRect->top = infoPtr->items[iItem].rect.top;
807 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
814 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
817 LPINT order = (LPINT) lParam;
818 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
820 if ((unsigned int)wParam <infoPtr->uNumItem)
822 for (i=0; i<(int)wParam; i++)
823 *order++=HEADER_OrderToIndex(hwnd,i);
828 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
831 LPINT order = (LPINT) lParam;
832 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
835 if ((unsigned int)wParam <infoPtr->uNumItem)
837 for (i=0; i<(int)wParam; i++)
839 lpItem = &infoPtr->items[*order++];
842 infoPtr->bRectsValid=0;
843 InvalidateRect(hwnd, NULL, FALSE);
847 inline static LRESULT
848 HEADER_GetUnicodeFormat (HWND hwnd)
850 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
851 return infoPtr->bUnicode;
856 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
858 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
860 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
862 if (phti->flags == HHT_NOWHERE)
870 HEADER_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
872 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
873 HDITEMA *phdi = (HDITEMA*)lParam;
874 INT nItem = (INT)wParam;
879 if ((phdi == NULL) || (nItem < 0))
882 if (nItem > infoPtr->uNumItem)
883 nItem = infoPtr->uNumItem;
885 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
887 if (infoPtr->uNumItem == 0) {
888 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
892 HEADER_ITEM *oldItems = infoPtr->items;
895 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
897 memcpy (&infoPtr->items[1], &oldItems[0],
898 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
902 /* pre insert copy */
904 memcpy (&infoPtr->items[0], &oldItems[0],
905 nItem * sizeof(HEADER_ITEM));
908 /* post insert copy */
909 if (nItem < infoPtr->uNumItem - 1) {
910 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
911 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
918 for (i=0; i < infoPtr->uNumItem; i++)
920 if (infoPtr->items[i].iOrder >= iOrder)
921 infoPtr->items[i].iOrder++;
924 lpItem = &infoPtr->items[nItem];
925 lpItem->bDown = FALSE;
927 if (phdi->mask & HDI_WIDTH)
928 lpItem->cxy = phdi->cxy;
930 if (phdi->mask & HDI_TEXT) {
931 if (!phdi->pszText) /* null pointer check */
933 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
934 len = MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, NULL, 0);
935 lpItem->pszText = Alloc( len*sizeof(WCHAR) );
936 MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, lpItem->pszText, len);
939 lpItem->pszText = LPSTR_TEXTCALLBACKW;
942 if (phdi->mask & HDI_FORMAT)
943 lpItem->fmt = phdi->fmt;
945 if (lpItem->fmt == 0)
946 lpItem->fmt = HDF_LEFT;
948 if (!(lpItem->fmt & HDF_STRING) && (phdi->mask & HDI_TEXT))
950 lpItem->fmt |= HDF_STRING;
952 if (phdi->mask & HDI_BITMAP)
953 lpItem->hbm = phdi->hbm;
955 if (phdi->mask & HDI_LPARAM)
956 lpItem->lParam = phdi->lParam;
958 if (phdi->mask & HDI_IMAGE)
959 lpItem->iImage = phdi->iImage;
961 lpItem->iOrder = iOrder;
963 HEADER_SetItemBounds (hwnd);
965 InvalidateRect(hwnd, NULL, FALSE);
972 HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
974 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
975 HDITEMW *phdi = (HDITEMW*)lParam;
976 INT nItem = (INT)wParam;
981 if ((phdi == NULL) || (nItem < 0))
984 if (nItem > infoPtr->uNumItem)
985 nItem = infoPtr->uNumItem;
987 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
989 if (infoPtr->uNumItem == 0) {
990 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
994 HEADER_ITEM *oldItems = infoPtr->items;
997 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
999 memcpy (&infoPtr->items[1], &oldItems[0],
1000 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
1004 /* pre insert copy */
1006 memcpy (&infoPtr->items[0], &oldItems[0],
1007 nItem * sizeof(HEADER_ITEM));
1010 /* post insert copy */
1011 if (nItem < infoPtr->uNumItem - 1) {
1012 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
1013 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
1020 for (i=0; i < infoPtr->uNumItem; i++)
1022 if (infoPtr->items[i].iOrder >= iOrder)
1023 infoPtr->items[i].iOrder++;
1026 lpItem = &infoPtr->items[nItem];
1027 lpItem->bDown = FALSE;
1029 if (phdi->mask & HDI_WIDTH)
1030 lpItem->cxy = phdi->cxy;
1032 if (phdi->mask & HDI_TEXT) {
1033 WCHAR wide_null_char = 0;
1034 if (!phdi->pszText) /* null pointer check */
1035 phdi->pszText = &wide_null_char;
1036 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1037 len = strlenW (phdi->pszText);
1038 lpItem->pszText = Alloc ((len+1)*sizeof(WCHAR));
1039 strcpyW (lpItem->pszText, phdi->pszText);
1042 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1045 if (phdi->mask & HDI_FORMAT)
1046 lpItem->fmt = phdi->fmt;
1048 if (lpItem->fmt == 0)
1049 lpItem->fmt = HDF_LEFT;
1051 if (!(lpItem->fmt &HDF_STRING) && (phdi->mask & HDI_TEXT))
1053 lpItem->fmt |= HDF_STRING;
1055 if (phdi->mask & HDI_BITMAP)
1056 lpItem->hbm = phdi->hbm;
1058 if (phdi->mask & HDI_LPARAM)
1059 lpItem->lParam = phdi->lParam;
1061 if (phdi->mask & HDI_IMAGE)
1062 lpItem->iImage = phdi->iImage;
1064 lpItem->iOrder = iOrder;
1066 HEADER_SetItemBounds (hwnd);
1068 InvalidateRect(hwnd, NULL, FALSE);
1075 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
1077 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1078 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1080 lpLayout->pwpos->hwnd = hwnd;
1081 lpLayout->pwpos->hwndInsertAfter = 0;
1082 lpLayout->pwpos->x = lpLayout->prc->left;
1083 lpLayout->pwpos->y = lpLayout->prc->top;
1084 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1085 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_HIDDEN)
1086 lpLayout->pwpos->cy = 0;
1088 lpLayout->pwpos->cy = infoPtr->nHeight;
1089 lpLayout->prc->top += infoPtr->nHeight;
1091 lpLayout->pwpos->flags = SWP_NOZORDER;
1093 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1094 lpLayout->pwpos->x, lpLayout->pwpos->y,
1095 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1097 infoPtr->bRectsValid = FALSE;
1104 HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
1106 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1109 TRACE("(himl 0x%x)\n", (int)himl);
1110 himlOld = infoPtr->himl;
1111 infoPtr->himl = himl;
1113 /* FIXME: Refresh needed??? */
1115 return (LRESULT)himlOld;
1120 HEADER_GetBitmapMargin(HWND hwnd)
1122 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
1124 return infoPtr->iMargin;
1128 HEADER_SetBitmapMargin(HWND hwnd, WPARAM wParam)
1130 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1131 INT oldMargin = infoPtr->iMargin;
1133 infoPtr->iMargin = (INT)wParam;
1139 HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1141 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1142 HDITEMA *phdi = (HDITEMA*)lParam;
1143 INT nItem = (INT)wParam;
1144 HEADER_ITEM *lpItem;
1148 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1151 TRACE("[nItem=%d]\n", nItem);
1153 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem, phdi->mask))
1156 lpItem = &infoPtr->items[nItem];
1157 if (phdi->mask & HDI_BITMAP)
1158 lpItem->hbm = phdi->hbm;
1160 if (phdi->mask & HDI_FORMAT)
1161 lpItem->fmt = phdi->fmt;
1163 if (phdi->mask & HDI_LPARAM)
1164 lpItem->lParam = phdi->lParam;
1166 if (phdi->mask & HDI_TEXT) {
1167 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
1168 if (lpItem->pszText) {
1169 Free (lpItem->pszText);
1170 lpItem->pszText = NULL;
1172 if (phdi->pszText) {
1173 INT len = MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,NULL,0);
1174 lpItem->pszText = Alloc( len*sizeof(WCHAR) );
1175 MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,lpItem->pszText,len);
1179 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1182 if (phdi->mask & HDI_WIDTH)
1183 lpItem->cxy = phdi->cxy;
1185 if (phdi->mask & HDI_IMAGE)
1186 lpItem->iImage = phdi->iImage;
1188 if (phdi->mask & HDI_ORDER)
1190 lpItem->iOrder = phdi->iOrder;
1193 lpItem->iOrder = nItem;
1195 HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem, phdi->mask);
1197 HEADER_SetItemBounds (hwnd);
1199 InvalidateRect(hwnd, NULL, FALSE);
1206 HEADER_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1208 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1209 HDITEMW *phdi = (HDITEMW*)lParam;
1210 INT nItem = (INT)wParam;
1211 HEADER_ITEM *lpItem;
1215 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1218 TRACE("[nItem=%d]\n", nItem);
1220 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask))
1223 lpItem = &infoPtr->items[nItem];
1224 if (phdi->mask & HDI_BITMAP)
1225 lpItem->hbm = phdi->hbm;
1227 if (phdi->mask & HDI_FORMAT)
1228 lpItem->fmt = phdi->fmt;
1230 if (phdi->mask & HDI_LPARAM)
1231 lpItem->lParam = phdi->lParam;
1233 if (phdi->mask & HDI_TEXT) {
1234 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1235 if (lpItem->pszText) {
1236 Free (lpItem->pszText);
1237 lpItem->pszText = NULL;
1239 if (phdi->pszText) {
1240 INT len = strlenW (phdi->pszText);
1241 lpItem->pszText = Alloc ((len+1)*sizeof(WCHAR));
1242 strcpyW (lpItem->pszText, phdi->pszText);
1246 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1249 if (phdi->mask & HDI_WIDTH)
1250 lpItem->cxy = phdi->cxy;
1252 if (phdi->mask & HDI_IMAGE)
1253 lpItem->iImage = phdi->iImage;
1255 if (phdi->mask & HDI_ORDER)
1257 lpItem->iOrder = phdi->iOrder;
1260 lpItem->iOrder = nItem;
1262 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDW, nItem, phdi->mask);
1264 HEADER_SetItemBounds (hwnd);
1266 InvalidateRect(hwnd, NULL, FALSE);
1271 inline static LRESULT
1272 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1274 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1275 BOOL bTemp = infoPtr->bUnicode;
1277 infoPtr->bUnicode = (BOOL)wParam;
1284 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1286 HEADER_INFO *infoPtr;
1291 infoPtr = (HEADER_INFO *)Alloc (sizeof(HEADER_INFO));
1292 SetWindowLongPtrA (hwnd, 0, (DWORD_PTR)infoPtr);
1294 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
1295 infoPtr->uNumItem = 0;
1298 infoPtr->bRectsValid = FALSE;
1299 infoPtr->hcurArrow = LoadCursorA (0, (LPSTR)IDC_ARROW);
1300 infoPtr->hcurDivider = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDER));
1301 infoPtr->hcurDivopen = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDEROPEN));
1302 infoPtr->bPressed = FALSE;
1303 infoPtr->bTracking = FALSE;
1304 infoPtr->iMoveItem = 0;
1306 infoPtr->iHotItem = -1;
1307 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1308 infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
1309 infoPtr->nNotifyFormat =
1310 SendMessageA (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1313 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1314 GetTextMetricsA (hdc, &tm);
1315 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1316 SelectObject (hdc, hOldFont);
1324 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1326 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1327 HEADER_ITEM *lpItem;
1330 if (infoPtr->items) {
1331 lpItem = infoPtr->items;
1332 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1333 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
1334 Free (lpItem->pszText);
1336 Free (infoPtr->items);
1340 ImageList_Destroy (infoPtr->himl);
1343 SetWindowLongPtrA (hwnd, 0, 0);
1348 static inline LRESULT
1349 HEADER_GetFont (HWND hwnd)
1351 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1353 return (LRESULT)infoPtr->hFont;
1358 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1364 pt.x = (INT)LOWORD(lParam);
1365 pt.y = (INT)HIWORD(lParam);
1366 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1368 if ((GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1369 HEADER_SendHeaderNotify (hwnd, HDN_ITEMDBLCLICKA, nItem,0);
1370 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1371 HEADER_SendHeaderNotify (hwnd, HDN_DIVIDERDBLCLICKA, nItem,0);
1378 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1380 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1381 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1387 pt.x = (INT)LOWORD(lParam);
1388 pt.y = (INT)HIWORD(lParam);
1389 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1391 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1393 infoPtr->bCaptured = TRUE;
1394 infoPtr->bPressed = TRUE;
1395 infoPtr->iMoveItem = nItem;
1397 infoPtr->items[nItem].bDown = TRUE;
1399 /* Send WM_CUSTOMDRAW */
1401 HEADER_RefreshItem (hwnd, hdc, nItem);
1402 ReleaseDC (hwnd, hdc);
1404 TRACE("Pressed item %d!\n", nItem);
1406 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1407 if (!(HEADER_SendHeaderNotify (hwnd, HDN_BEGINTRACKA, nItem,0))) {
1409 infoPtr->bCaptured = TRUE;
1410 infoPtr->bTracking = TRUE;
1411 infoPtr->iMoveItem = nItem;
1412 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1413 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1415 if (!(dwStyle & HDS_FULLDRAG)) {
1416 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1418 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1419 ReleaseDC (hwnd, hdc);
1422 TRACE("Begin tracking item %d!\n", nItem);
1431 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1433 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1435 *DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1442 pt.x = (INT)(SHORT)LOWORD(lParam);
1443 pt.y = (INT)(SHORT)HIWORD(lParam);
1444 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1446 if (infoPtr->bPressed) {
1447 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1448 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1450 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1451 ReleaseDC (hwnd, hdc);
1453 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1455 else if (flags == HHT_ONHEADER)
1457 HEADER_ITEM *lpItem;
1458 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1459 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1461 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1462 infoPtr->iMoveItem,oldindex,nItem,newindex);
1463 lpItem= &infoPtr->items[nItem];
1464 lpItem->iOrder=oldindex;
1466 lpItem= &infoPtr->items[infoPtr->iMoveItem];
1467 lpItem->iOrder = newindex;
1469 infoPtr->bRectsValid = FALSE;
1470 InvalidateRect(hwnd, NULL, FALSE);
1471 /* FIXME: Should some WM_NOTIFY be sent */
1474 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1475 infoPtr->bPressed = FALSE;
1477 else if (infoPtr->bTracking) {
1478 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1479 infoPtr->bTracking = FALSE;
1481 HEADER_SendHeaderNotify (hwnd, HDN_ENDTRACKA, infoPtr->iMoveItem,HDI_WIDTH);
1484 * we want to do this even for HDS_FULLDRAG because this is where
1485 * we send the HDN_ITEMCHANGING and HDN_ITEMCHANGED notifications
1487 * if (!(dwStyle & HDS_FULLDRAG)) {
1491 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1492 ReleaseDC (hwnd, hdc);
1493 if (HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1495 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1498 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1501 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1504 HEADER_SetItemBounds (hwnd);
1505 InvalidateRect(hwnd, NULL, TRUE);
1506 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1512 if (infoPtr->bCaptured) {
1513 infoPtr->bCaptured = FALSE;
1515 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1523 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1525 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1530 return infoPtr->nNotifyFormat;
1533 infoPtr->nNotifyFormat =
1534 SendMessageA ((HWND)wParam, WM_NOTIFYFORMAT,
1535 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1536 return infoPtr->nNotifyFormat;
1544 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1546 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1547 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1553 pt.x = (INT)(SHORT)LOWORD(lParam);
1554 pt.y = (INT)(SHORT)HIWORD(lParam);
1555 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1557 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1558 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1559 infoPtr->iHotItem = nItem;
1561 infoPtr->iHotItem = -1;
1562 InvalidateRect(hwnd, NULL, FALSE);
1565 if (infoPtr->bCaptured) {
1566 if (infoPtr->bPressed) {
1567 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1568 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1570 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1572 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1573 ReleaseDC (hwnd, hdc);
1575 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1577 else if (infoPtr->bTracking) {
1578 if (dwStyle & HDS_FULLDRAG) {
1579 if (HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH))
1581 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1584 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1585 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1587 HEADER_SetItemBounds (hwnd);
1591 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1592 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1593 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1594 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1595 infoPtr->items[infoPtr->iMoveItem].cxy =
1596 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1597 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1598 ReleaseDC (hwnd, hdc);
1599 HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH);
1602 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1606 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1607 FIXME("hot track support!\n");
1615 HEADER_Paint (HWND hwnd, WPARAM wParam)
1620 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1621 HEADER_Refresh (hwnd, hdc);
1623 EndPaint (hwnd, &ps);
1629 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1634 pt.x = LOWORD(lParam);
1635 pt.y = HIWORD(lParam);
1637 /* Send a Notify message */
1638 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1640 /* Change to screen coordinate for WM_CONTEXTMENU */
1641 ClientToScreen(hwnd, &pt);
1643 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1644 SendMessageA( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1651 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1653 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1658 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1661 ScreenToClient (hwnd, &pt);
1663 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1665 if (flags == HHT_ONDIVIDER)
1666 SetCursor (infoPtr->hcurDivider);
1667 else if (flags == HHT_ONDIVOPEN)
1668 SetCursor (infoPtr->hcurDivopen);
1670 SetCursor (infoPtr->hcurArrow);
1677 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1679 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1681 HFONT hFont, hOldFont;
1684 infoPtr->hFont = (HFONT)wParam;
1686 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1689 hOldFont = SelectObject (hdc, hFont);
1690 GetTextMetricsA (hdc, &tm);
1691 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1692 SelectObject (hdc, hOldFont);
1695 infoPtr->bRectsValid = FALSE;
1698 InvalidateRect(hwnd, NULL, FALSE);
1705 static LRESULT WINAPI
1706 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1708 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1709 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1710 return DefWindowProcA (hwnd, msg, wParam, lParam);
1712 /* case HDM_CLEARFILTER: */
1714 case HDM_CREATEDRAGIMAGE:
1715 return HEADER_CreateDragImage (hwnd, wParam);
1717 case HDM_DELETEITEM:
1718 return HEADER_DeleteItem (hwnd, wParam);
1720 /* case HDM_EDITFILTER: */
1722 case HDM_GETBITMAPMARGIN:
1723 return HEADER_GetBitmapMargin(hwnd);
1725 case HDM_GETIMAGELIST:
1726 return HEADER_GetImageList (hwnd);
1729 return HEADER_GetItemA (hwnd, wParam, lParam);
1732 return HEADER_GetItemW (hwnd, wParam, lParam);
1734 case HDM_GETITEMCOUNT:
1735 return HEADER_GetItemCount (hwnd);
1737 case HDM_GETITEMRECT:
1738 return HEADER_GetItemRect (hwnd, wParam, lParam);
1740 case HDM_GETORDERARRAY:
1741 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1743 case HDM_GETUNICODEFORMAT:
1744 return HEADER_GetUnicodeFormat (hwnd);
1747 return HEADER_HitTest (hwnd, wParam, lParam);
1749 case HDM_INSERTITEMA:
1750 return HEADER_InsertItemA (hwnd, wParam, lParam);
1752 case HDM_INSERTITEMW:
1753 return HEADER_InsertItemW (hwnd, wParam, lParam);
1756 return HEADER_Layout (hwnd, wParam, lParam);
1758 case HDM_ORDERTOINDEX:
1759 return HEADER_OrderToIndex(hwnd, wParam);
1761 case HDM_SETBITMAPMARGIN:
1762 return HEADER_SetBitmapMargin(hwnd, wParam);
1764 /* case HDM_SETFILTERCHANGETIMEOUT: */
1766 /* case HDM_SETHOTDIVIDER: */
1768 case HDM_SETIMAGELIST:
1769 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
1772 return HEADER_SetItemA (hwnd, wParam, lParam);
1775 return HEADER_SetItemW (hwnd, wParam, lParam);
1777 case HDM_SETORDERARRAY:
1778 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1780 case HDM_SETUNICODEFORMAT:
1781 return HEADER_SetUnicodeFormat (hwnd, wParam);
1784 return HEADER_Create (hwnd, wParam, lParam);
1787 return HEADER_Destroy (hwnd, wParam, lParam);
1793 return DLGC_WANTTAB | DLGC_WANTARROWS;
1796 return HEADER_GetFont (hwnd);
1798 case WM_LBUTTONDBLCLK:
1799 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1801 case WM_LBUTTONDOWN:
1802 return HEADER_LButtonDown (hwnd, wParam, lParam);
1805 return HEADER_LButtonUp (hwnd, wParam, lParam);
1808 return HEADER_MouseMove (hwnd, wParam, lParam);
1810 case WM_NOTIFYFORMAT:
1811 return HEADER_NotifyFormat (hwnd, wParam, lParam);
1814 return HEADER_Size (hwnd, wParam);
1817 return HEADER_Paint (hwnd, wParam);
1820 return HEADER_RButtonUp (hwnd, wParam, lParam);
1823 return HEADER_SetCursor (hwnd, wParam, lParam);
1826 return HEADER_SetFont (hwnd, wParam, lParam);
1829 if ((msg >= WM_USER) && (msg < WM_APP))
1830 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1831 msg, wParam, lParam );
1832 return DefWindowProcA (hwnd, msg, wParam, lParam);
1839 HEADER_Register (void)
1843 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1844 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1845 wndClass.lpfnWndProc = (WNDPROC)HEADER_WindowProc;
1846 wndClass.cbClsExtra = 0;
1847 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1848 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
1849 wndClass.lpszClassName = WC_HEADERA;
1851 RegisterClassA (&wndClass);
1856 HEADER_Unregister (void)
1858 UnregisterClassA (WC_HEADERA, NULL);