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 *)GetWindowLongA(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 i,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);
130 infoPtr->bRectsValid = TRUE;
132 if (infoPtr->uNumItem == 0)
135 GetClientRect (hwnd, &rect);
138 for (i = 0; i < infoPtr->uNumItem; i++) {
139 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
140 phdi->rect.top = rect.top;
141 phdi->rect.bottom = rect.bottom;
143 phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
144 x = phdi->rect.right;
149 HEADER_Size (HWND hwnd, WPARAM wParam)
151 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
153 infoPtr->bRectsValid = FALSE;
160 HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
162 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
163 HEADER_ITEM *phdi = &infoPtr->items[iItem];
167 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, infoPtr->bUnicode);
169 if (!infoPtr->bRectsValid)
170 HEADER_SetItemBounds(hwnd);
173 if (r.right - r.left == 0)
174 return phdi->rect.right;
176 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) {
178 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
179 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
184 DrawEdge (hdc, &r, EDGE_RAISED,
185 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
188 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
190 if (phdi->fmt & HDF_OWNERDRAW) {
192 dis.CtlType = ODT_HEADER;
193 dis.CtlID = GetWindowLongA (hwnd, GWL_ID);
195 dis.itemAction = ODA_DRAWENTIRE;
196 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
200 dis.itemData = phdi->lParam;
201 oldBkMode = SetBkMode(hdc, TRANSPARENT);
202 SendMessageA (infoPtr->hwndNotify, WM_DRAWITEM,
203 (WPARAM)dis.CtlID, (LPARAM)&dis);
204 if (oldBkMode != TRANSPARENT)
205 SetBkMode(hdc, oldBkMode);
208 UINT uTextJustify = DT_LEFT;
210 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
211 uTextJustify = DT_CENTER;
212 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
213 uTextJustify = DT_RIGHT;
215 if ((phdi->fmt & HDF_BITMAP) && !(phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
218 INT yD, yS, cx, cy, rx, ry;
220 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
222 ry = r.bottom - r.top;
223 rx = r.right - r.left;
225 if (ry >= bmp.bmHeight) {
227 yD = r.top + (ry - bmp.bmHeight) / 2;
233 yS = (bmp.bmHeight - ry) / 2;
237 if (rx >= bmp.bmWidth + infoPtr->iMargin) {
241 cx = rx - infoPtr->iMargin;
244 hdcBitmap = CreateCompatibleDC (hdc);
245 SelectObject (hdcBitmap, phdi->hbm);
246 BitBlt (hdc, r.left + infoPtr->iMargin, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
247 DeleteDC (hdcBitmap);
249 r.left += (bmp.bmWidth + infoPtr->iMargin);
253 if ((phdi->fmt & HDF_BITMAP) && (phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
256 INT xD, yD, yS, cx, cy, rx, ry, tx;
259 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
262 if (phdi->fmt & HDF_STRING) {
263 DrawTextW (hdc, phdi->pszText, -1,
264 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
265 tx = textRect.right - textRect.left;
269 ry = r.bottom - r.top;
270 rx = r.right - r.left;
272 if (ry >= bmp.bmHeight) {
274 yD = r.top + (ry - bmp.bmHeight) / 2;
280 yS = (bmp.bmHeight - ry) / 2;
284 if (r.left + tx + bmp.bmWidth + 2*infoPtr->iMargin <= r.right) {
286 xD = r.left + tx + infoPtr->iMargin;
289 if (rx >= bmp.bmWidth + infoPtr->iMargin ) {
291 xD = r.right - bmp.bmWidth - infoPtr->iMargin;
292 r.right = xD - infoPtr->iMargin;
295 cx = rx - infoPtr->iMargin;
301 hdcBitmap = CreateCompatibleDC (hdc);
302 SelectObject (hdcBitmap, phdi->hbm);
303 BitBlt (hdc, xD, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
304 DeleteDC (hdcBitmap);
307 if ((phdi->fmt & HDF_IMAGE) && !(phdi->fmt & HDF_BITMAP_ON_RIGHT) && (infoPtr->himl)) {
308 r.left += infoPtr->iMargin;
309 ImageList_DrawEx(infoPtr->himl, phdi->iImage, hdc, r.left, r.top + (r.bottom-r.top- infoPtr->himl->cy)/2,
310 infoPtr->himl->cx, r.bottom-r.top, CLR_DEFAULT, CLR_DEFAULT, 0);
311 r.left += infoPtr->himl->cx;
314 if ((phdi->fmt & HDF_IMAGE) && (phdi->fmt & HDF_BITMAP_ON_RIGHT) && (infoPtr->himl)) {
319 if (phdi->fmt & HDF_STRING) {
320 DrawTextW (hdc, phdi->pszText, -1,
321 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
322 tx = textRect.right - textRect.left;
326 ImageList_DrawEx(infoPtr->himl, phdi->iImage, hdc, r.left + tx + 2*infoPtr->iMargin,
327 r.top + (r.bottom-r.top-infoPtr->himl->cy)/2, infoPtr->himl->cx, r.bottom-r.top,
328 CLR_DEFAULT, CLR_DEFAULT, 0);
331 if (((phdi->fmt & HDF_STRING)
332 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
333 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
334 && (phdi->pszText)) {
335 oldBkMode = SetBkMode(hdc, TRANSPARENT);
336 r.left += infoPtr->iMargin;
337 r.right -= infoPtr->iMargin;
338 SetTextColor (hdc, (bHotTrack) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
339 DrawTextW (hdc, phdi->pszText, -1,
340 &r, uTextJustify|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
341 if (oldBkMode != TRANSPARENT)
342 SetBkMode(hdc, oldBkMode);
346 return phdi->rect.right;
351 HEADER_Refresh (HWND hwnd, HDC hdc)
353 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
354 HFONT hFont, hOldFont;
359 /* get rect for the bar, adjusted for the border */
360 GetClientRect (hwnd, &rect);
362 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
363 hOldFont = SelectObject (hdc, hFont);
365 /* draw Background */
366 hbrBk = GetSysColorBrush(COLOR_3DFACE);
367 FillRect(hdc, &rect, hbrBk);
370 for (i = 0; i < infoPtr->uNumItem; i++) {
371 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i), FALSE);
374 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
376 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS)
377 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
379 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
382 SelectObject (hdc, hOldFont);
387 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
389 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
390 HFONT hFont, hOldFont;
392 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
393 hOldFont = SelectObject (hdc, hFont);
394 HEADER_DrawItem (hwnd, hdc, iItem, FALSE);
395 SelectObject (hdc, hOldFont);
400 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
402 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
407 GetClientRect (hwnd, &rect);
411 if (PtInRect (&rect, *lpPt))
413 if (infoPtr->uNumItem == 0) {
414 *pFlags |= HHT_NOWHERE;
420 /* somewhere inside */
421 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
422 rect = infoPtr->items[iCount].rect;
423 width = rect.right - rect.left;
428 if (PtInRect (&rect, *lpPt)) {
429 if (width <= 2 * DIVIDER_WIDTH) {
430 *pFlags |= HHT_ONHEADER;
432 TRACE("ON HEADER %d\n", iCount);
437 rcTest.right = rcTest.left + DIVIDER_WIDTH;
438 if (PtInRect (&rcTest, *lpPt)) {
440 *pFlags |= HHT_ONDIVOPEN;
442 TRACE("ON DIVOPEN %d\n", *pItem);
446 *pFlags |= HHT_ONDIVIDER;
448 TRACE("ON DIVIDER %d\n", *pItem);
454 rcTest.left = rcTest.right - DIVIDER_WIDTH;
455 if (PtInRect (&rcTest, *lpPt)) {
456 *pFlags |= HHT_ONDIVIDER;
458 TRACE("ON DIVIDER %d\n", *pItem);
462 *pFlags |= HHT_ONHEADER;
464 TRACE("ON HEADER %d\n", iCount);
469 /* check for last divider part (on nowhere) */
470 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
471 rect.left = rect.right;
472 rect.right += DIVIDER_WIDTH;
473 if (PtInRect (&rect, *lpPt)) {
475 *pFlags |= HHT_ONDIVOPEN;
476 *pItem = infoPtr->uNumItem - 1;
477 TRACE("ON DIVOPEN %d\n", *pItem);
481 *pFlags |= HHT_ONDIVIDER;
482 *pItem = infoPtr->uNumItem-1;
483 TRACE("ON DIVIDER %d\n", *pItem);
488 *pFlags |= HHT_NOWHERE;
495 if (lpPt->x < rect.left) {
497 *pFlags |= HHT_TOLEFT;
499 else if (lpPt->x > rect.right) {
501 *pFlags |= HHT_TORIGHT;
504 if (lpPt->y < rect.top) {
506 *pFlags |= HHT_ABOVE;
508 else if (lpPt->y > rect.bottom) {
510 *pFlags |= HHT_BELOW;
515 TRACE("flags=0x%X\n", *pFlags);
521 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
527 GetClientRect (hwnd, &rect);
529 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
530 oldRop = SetROP2 (hdc, R2_XORPEN);
531 MoveToEx (hdc, x, rect.top, NULL);
532 LineTo (hdc, x, rect.bottom);
533 SetROP2 (hdc, oldRop);
534 SelectObject (hdc, hOldPen);
539 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
541 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
544 nmhdr.hwndFrom = hwnd;
545 nmhdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
548 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
549 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
553 HEADER_SendHeaderNotify (HWND hwnd, UINT code, INT iItem, INT mask)
555 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
559 nmhdr.hdr.hwndFrom = hwnd;
560 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
561 nmhdr.hdr.code = code;
564 nmhdr.pitem = &nmitem;
566 nmitem.cxy = infoPtr->items[iItem].cxy;
567 nmitem.hbm = infoPtr->items[iItem].hbm;
568 nmitem.pszText = NULL;
569 nmitem.cchTextMax = 0;
570 /* nmitem.pszText = infoPtr->items[iItem].pszText; */
571 /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
572 nmitem.fmt = infoPtr->items[iItem].fmt;
573 nmitem.lParam = infoPtr->items[iItem].lParam;
574 nmitem.iOrder = infoPtr->items[iItem].iOrder;
575 nmitem.iImage = infoPtr->items[iItem].iImage;
577 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
578 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
583 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
585 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
588 nmhdr.hdr.hwndFrom = hwnd;
589 nmhdr.hdr.idFrom = GetWindowLongA (hwnd, GWL_ID);
590 nmhdr.hdr.code = code;
595 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
596 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
601 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
603 FIXME("empty stub!\n");
609 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
611 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
612 INT iItem = (INT)wParam;
614 TRACE("[iItem=%d]\n", iItem);
616 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
619 if (infoPtr->uNumItem == 1) {
620 TRACE("Simple delete!\n");
621 if (infoPtr->items[0].pszText)
622 Free (infoPtr->items[0].pszText);
623 Free (infoPtr->items);
625 infoPtr->uNumItem = 0;
628 HEADER_ITEM *oldItems = infoPtr->items;
632 TRACE("Complex delete! [iItem=%d]\n", iItem);
634 if (infoPtr->items[iItem].pszText)
635 Free (infoPtr->items[iItem].pszText);
636 iOrder = infoPtr->items[iItem].iOrder;
639 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
640 /* pre delete copy */
642 memcpy (&infoPtr->items[0], &oldItems[0],
643 iItem * sizeof(HEADER_ITEM));
646 /* post delete copy */
647 if (iItem < infoPtr->uNumItem) {
648 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
649 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
652 /* Correct the orders */
653 for (i=infoPtr->uNumItem, pItem = infoPtr->items; i; i--, pItem++)
655 if (pItem->iOrder > iOrder)
661 HEADER_SetItemBounds (hwnd);
663 InvalidateRect(hwnd, NULL, FALSE);
670 HEADER_GetImageList (HWND hwnd)
672 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
674 return (LRESULT)infoPtr->himl;
679 HEADER_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
681 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
682 HDITEMA *phdi = (HDITEMA*)lParam;
683 INT nItem = (INT)wParam;
688 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
691 TRACE("[nItem=%d]\n", nItem);
696 lpItem = &infoPtr->items[nItem];
697 if (phdi->mask & HDI_BITMAP)
698 phdi->hbm = lpItem->hbm;
700 if (phdi->mask & HDI_FORMAT)
701 phdi->fmt = lpItem->fmt;
703 if (phdi->mask & HDI_WIDTH)
704 phdi->cxy = lpItem->cxy;
706 if (phdi->mask & HDI_LPARAM)
707 phdi->lParam = lpItem->lParam;
709 if (phdi->mask & HDI_TEXT) {
710 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
712 WideCharToMultiByte (CP_ACP, 0, lpItem->pszText, -1,
713 phdi->pszText, phdi->cchTextMax, NULL, NULL);
718 phdi->pszText = LPSTR_TEXTCALLBACKA;
721 if (phdi->mask & HDI_IMAGE)
722 phdi->iImage = lpItem->iImage;
724 if (phdi->mask & HDI_ORDER)
725 phdi->iOrder = lpItem->iOrder;
732 HEADER_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
734 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
735 HDITEMW *phdi = (HDITEMW*)lParam;
736 INT nItem = (INT)wParam;
741 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
744 TRACE("[nItem=%d]\n", nItem);
749 lpItem = &infoPtr->items[nItem];
750 if (phdi->mask & HDI_BITMAP)
751 phdi->hbm = lpItem->hbm;
753 if (phdi->mask & HDI_FORMAT)
754 phdi->fmt = lpItem->fmt;
756 if (phdi->mask & HDI_WIDTH)
757 phdi->cxy = lpItem->cxy;
759 if (phdi->mask & HDI_LPARAM)
760 phdi->lParam = lpItem->lParam;
762 if (phdi->mask & HDI_TEXT) {
763 if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
765 lstrcpynW (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
770 phdi->pszText = LPSTR_TEXTCALLBACKW;
773 if (phdi->mask & HDI_IMAGE)
774 phdi->iImage = lpItem->iImage;
776 if (phdi->mask & HDI_ORDER)
777 phdi->iOrder = lpItem->iOrder;
783 inline static LRESULT
784 HEADER_GetItemCount (HWND hwnd)
786 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
787 return infoPtr->uNumItem;
792 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
794 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
795 INT iItem = (INT)wParam;
796 LPRECT lpRect = (LPRECT)lParam;
798 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
801 lpRect->left = infoPtr->items[iItem].rect.left;
802 lpRect->right = infoPtr->items[iItem].rect.right;
803 lpRect->top = infoPtr->items[iItem].rect.top;
804 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
811 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
814 LPINT order = (LPINT) lParam;
815 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
817 if ((int)wParam <infoPtr->uNumItem)
819 for (i=0; i<(int)wParam; i++)
820 *order++=HEADER_OrderToIndex(hwnd,i);
825 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
828 LPINT order = (LPINT) lParam;
829 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
832 if ((int)wParam <infoPtr->uNumItem)
834 for (i=0; i<(int)wParam; i++)
836 lpItem = &infoPtr->items[*order++];
839 infoPtr->bRectsValid=0;
840 InvalidateRect(hwnd, NULL, FALSE);
844 inline static LRESULT
845 HEADER_GetUnicodeFormat (HWND hwnd)
847 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
848 return infoPtr->bUnicode;
853 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
855 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
857 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
859 if (phti->flags == HHT_ONHEADER)
867 HEADER_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
869 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
870 HDITEMA *phdi = (HDITEMA*)lParam;
871 INT nItem = (INT)wParam;
875 if ((phdi == NULL) || (nItem < 0))
878 if (nItem > infoPtr->uNumItem)
879 nItem = infoPtr->uNumItem;
881 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
883 if (infoPtr->uNumItem == 0) {
884 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
888 HEADER_ITEM *oldItems = infoPtr->items;
891 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
893 memcpy (&infoPtr->items[1], &oldItems[0],
894 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
898 /* pre insert copy */
900 memcpy (&infoPtr->items[0], &oldItems[0],
901 nItem * sizeof(HEADER_ITEM));
904 /* post insert copy */
905 if (nItem < infoPtr->uNumItem - 1) {
906 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
907 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
914 for (i=0; i < infoPtr->uNumItem; i++)
916 if (infoPtr->items[i].iOrder >= iOrder)
917 infoPtr->items[i].iOrder++;
920 lpItem = &infoPtr->items[nItem];
921 lpItem->bDown = FALSE;
923 if (phdi->mask & HDI_WIDTH)
924 lpItem->cxy = phdi->cxy;
926 if (phdi->mask & HDI_TEXT) {
927 static char empty[] = "";
928 if (!phdi->pszText) /* null pointer check */
929 phdi->pszText = empty;
930 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
931 len = MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, NULL, 0);
932 lpItem->pszText = Alloc( len*sizeof(WCHAR) );
933 MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, lpItem->pszText, len);
936 lpItem->pszText = LPSTR_TEXTCALLBACKW;
939 if (phdi->mask & HDI_FORMAT)
940 lpItem->fmt = phdi->fmt;
942 if (lpItem->fmt == 0)
943 lpItem->fmt = HDF_LEFT;
945 if (!(lpItem->fmt & HDF_STRING) && (phdi->mask & HDI_TEXT))
947 lpItem->fmt |= HDF_STRING;
949 if (phdi->mask & HDI_BITMAP)
950 lpItem->hbm = phdi->hbm;
952 if (phdi->mask & HDI_LPARAM)
953 lpItem->lParam = phdi->lParam;
955 if (phdi->mask & HDI_IMAGE)
956 lpItem->iImage = phdi->iImage;
958 lpItem->iOrder = iOrder;
960 HEADER_SetItemBounds (hwnd);
962 InvalidateRect(hwnd, NULL, FALSE);
969 HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
971 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
972 HDITEMW *phdi = (HDITEMW*)lParam;
973 INT nItem = (INT)wParam;
977 if ((phdi == NULL) || (nItem < 0))
980 if (nItem > infoPtr->uNumItem)
981 nItem = infoPtr->uNumItem;
983 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
985 if (infoPtr->uNumItem == 0) {
986 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
990 HEADER_ITEM *oldItems = infoPtr->items;
993 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
995 memcpy (&infoPtr->items[1], &oldItems[0],
996 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
1000 /* pre insert copy */
1002 memcpy (&infoPtr->items[0], &oldItems[0],
1003 nItem * sizeof(HEADER_ITEM));
1006 /* post insert copy */
1007 if (nItem < infoPtr->uNumItem - 1) {
1008 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
1009 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
1016 for (i=0; i < infoPtr->uNumItem; i++)
1018 if (infoPtr->items[i].iOrder >= iOrder)
1019 infoPtr->items[i].iOrder++;
1022 lpItem = &infoPtr->items[nItem];
1023 lpItem->bDown = FALSE;
1025 if (phdi->mask & HDI_WIDTH)
1026 lpItem->cxy = phdi->cxy;
1028 if (phdi->mask & HDI_TEXT) {
1029 WCHAR wide_null_char = 0;
1030 if (!phdi->pszText) /* null pointer check */
1031 phdi->pszText = &wide_null_char;
1032 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1033 len = strlenW (phdi->pszText);
1034 lpItem->pszText = Alloc ((len+1)*sizeof(WCHAR));
1035 strcpyW (lpItem->pszText, phdi->pszText);
1038 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1041 if (phdi->mask & HDI_FORMAT)
1042 lpItem->fmt = phdi->fmt;
1044 if (lpItem->fmt == 0)
1045 lpItem->fmt = HDF_LEFT;
1047 if (!(lpItem->fmt &HDF_STRING) && (phdi->mask & HDI_TEXT))
1049 lpItem->fmt |= HDF_STRING;
1051 if (phdi->mask & HDI_BITMAP)
1052 lpItem->hbm = phdi->hbm;
1054 if (phdi->mask & HDI_LPARAM)
1055 lpItem->lParam = phdi->lParam;
1057 if (phdi->mask & HDI_IMAGE)
1058 lpItem->iImage = phdi->iImage;
1060 lpItem->iOrder = iOrder;
1062 HEADER_SetItemBounds (hwnd);
1064 InvalidateRect(hwnd, NULL, FALSE);
1071 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
1073 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1074 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1076 lpLayout->pwpos->hwnd = hwnd;
1077 lpLayout->pwpos->hwndInsertAfter = 0;
1078 lpLayout->pwpos->x = lpLayout->prc->left;
1079 lpLayout->pwpos->y = lpLayout->prc->top;
1080 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1081 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_HIDDEN)
1082 lpLayout->pwpos->cy = 0;
1084 lpLayout->pwpos->cy = infoPtr->nHeight;
1085 lpLayout->prc->top += infoPtr->nHeight;
1087 lpLayout->pwpos->flags = SWP_NOZORDER;
1089 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1090 lpLayout->pwpos->x, lpLayout->pwpos->y,
1091 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1093 infoPtr->bRectsValid = FALSE;
1100 HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
1102 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1105 TRACE("(himl 0x%x)\n", (int)himl);
1106 himlOld = infoPtr->himl;
1107 infoPtr->himl = himl;
1109 /* FIXME: Refresh needed??? */
1111 return (LRESULT)himlOld;
1116 HEADER_GetBitmapMargin(HWND hwnd)
1118 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
1120 return infoPtr->iMargin;
1124 HEADER_SetBitmapMargin(HWND hwnd, WPARAM wParam)
1126 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1127 INT oldMargin = infoPtr->iMargin;
1129 infoPtr->iMargin = (INT)wParam;
1135 HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1137 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1138 HDITEMA *phdi = (HDITEMA*)lParam;
1139 INT nItem = (INT)wParam;
1140 HEADER_ITEM *lpItem;
1144 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1147 TRACE("[nItem=%d]\n", nItem);
1149 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem, phdi->mask))
1152 lpItem = &infoPtr->items[nItem];
1153 if (phdi->mask & HDI_BITMAP)
1154 lpItem->hbm = phdi->hbm;
1156 if (phdi->mask & HDI_FORMAT)
1157 lpItem->fmt = phdi->fmt;
1159 if (phdi->mask & HDI_LPARAM)
1160 lpItem->lParam = phdi->lParam;
1162 if (phdi->mask & HDI_TEXT) {
1163 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
1164 if (lpItem->pszText) {
1165 Free (lpItem->pszText);
1166 lpItem->pszText = NULL;
1168 if (phdi->pszText) {
1169 INT len = MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,NULL,0);
1170 lpItem->pszText = Alloc( len*sizeof(WCHAR) );
1171 MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,lpItem->pszText,len);
1175 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1178 if (phdi->mask & HDI_WIDTH)
1179 lpItem->cxy = phdi->cxy;
1181 if (phdi->mask & HDI_IMAGE)
1182 lpItem->iImage = phdi->iImage;
1184 if (phdi->mask & HDI_ORDER)
1186 lpItem->iOrder = phdi->iOrder;
1189 lpItem->iOrder = nItem;
1191 HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem, phdi->mask);
1193 HEADER_SetItemBounds (hwnd);
1195 InvalidateRect(hwnd, NULL, FALSE);
1202 HEADER_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1204 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1205 HDITEMW *phdi = (HDITEMW*)lParam;
1206 INT nItem = (INT)wParam;
1207 HEADER_ITEM *lpItem;
1211 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1214 TRACE("[nItem=%d]\n", nItem);
1216 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask))
1219 lpItem = &infoPtr->items[nItem];
1220 if (phdi->mask & HDI_BITMAP)
1221 lpItem->hbm = phdi->hbm;
1223 if (phdi->mask & HDI_FORMAT)
1224 lpItem->fmt = phdi->fmt;
1226 if (phdi->mask & HDI_LPARAM)
1227 lpItem->lParam = phdi->lParam;
1229 if (phdi->mask & HDI_TEXT) {
1230 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1231 if (lpItem->pszText) {
1232 Free (lpItem->pszText);
1233 lpItem->pszText = NULL;
1235 if (phdi->pszText) {
1236 INT len = strlenW (phdi->pszText);
1237 lpItem->pszText = Alloc ((len+1)*sizeof(WCHAR));
1238 strcpyW (lpItem->pszText, phdi->pszText);
1242 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1245 if (phdi->mask & HDI_WIDTH)
1246 lpItem->cxy = phdi->cxy;
1248 if (phdi->mask & HDI_IMAGE)
1249 lpItem->iImage = phdi->iImage;
1251 if (phdi->mask & HDI_ORDER)
1253 lpItem->iOrder = phdi->iOrder;
1256 lpItem->iOrder = nItem;
1258 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDW, nItem, phdi->mask);
1260 HEADER_SetItemBounds (hwnd);
1262 InvalidateRect(hwnd, NULL, FALSE);
1267 inline static LRESULT
1268 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1270 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1271 BOOL bTemp = infoPtr->bUnicode;
1273 infoPtr->bUnicode = (BOOL)wParam;
1280 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1282 HEADER_INFO *infoPtr;
1287 infoPtr = (HEADER_INFO *)Alloc (sizeof(HEADER_INFO));
1288 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1290 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
1291 infoPtr->uNumItem = 0;
1294 infoPtr->bRectsValid = FALSE;
1295 infoPtr->hcurArrow = LoadCursorA (0, (LPSTR)IDC_ARROW);
1296 infoPtr->hcurDivider = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDER));
1297 infoPtr->hcurDivopen = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDEROPEN));
1298 infoPtr->bPressed = FALSE;
1299 infoPtr->bTracking = FALSE;
1300 infoPtr->iMoveItem = 0;
1302 infoPtr->iHotItem = -1;
1303 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1304 infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
1305 infoPtr->nNotifyFormat =
1306 SendMessageA (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1309 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1310 GetTextMetricsA (hdc, &tm);
1311 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1312 SelectObject (hdc, hOldFont);
1320 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1322 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1323 HEADER_ITEM *lpItem;
1326 if (infoPtr->items) {
1327 lpItem = infoPtr->items;
1328 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1329 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
1330 Free (lpItem->pszText);
1332 Free (infoPtr->items);
1336 ImageList_Destroy (infoPtr->himl);
1339 SetWindowLongA (hwnd, 0, 0);
1344 static inline LRESULT
1345 HEADER_GetFont (HWND hwnd)
1347 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1349 return (LRESULT)infoPtr->hFont;
1354 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1360 pt.x = (INT)LOWORD(lParam);
1361 pt.y = (INT)HIWORD(lParam);
1362 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1364 if ((GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1365 HEADER_SendHeaderNotify (hwnd, HDN_ITEMDBLCLICKA, nItem,0);
1366 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1367 HEADER_SendHeaderNotify (hwnd, HDN_DIVIDERDBLCLICKA, nItem,0);
1374 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1376 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1377 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1383 pt.x = (INT)LOWORD(lParam);
1384 pt.y = (INT)HIWORD(lParam);
1385 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1387 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1389 infoPtr->bCaptured = TRUE;
1390 infoPtr->bPressed = TRUE;
1391 infoPtr->iMoveItem = nItem;
1393 infoPtr->items[nItem].bDown = TRUE;
1395 /* Send WM_CUSTOMDRAW */
1397 HEADER_RefreshItem (hwnd, hdc, nItem);
1398 ReleaseDC (hwnd, hdc);
1400 TRACE("Pressed item %d!\n", nItem);
1402 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1403 if (!(HEADER_SendHeaderNotify (hwnd, HDN_BEGINTRACKA, nItem,0))) {
1405 infoPtr->bCaptured = TRUE;
1406 infoPtr->bTracking = TRUE;
1407 infoPtr->iMoveItem = nItem;
1408 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1409 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1411 if (!(dwStyle & HDS_FULLDRAG)) {
1412 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1414 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1415 ReleaseDC (hwnd, hdc);
1418 TRACE("Begin tracking item %d!\n", nItem);
1427 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1429 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1431 *DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1438 pt.x = (INT)(SHORT)LOWORD(lParam);
1439 pt.y = (INT)(SHORT)HIWORD(lParam);
1440 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1442 if (infoPtr->bPressed) {
1443 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1444 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1446 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1447 ReleaseDC (hwnd, hdc);
1449 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1451 else if (flags == HHT_ONHEADER)
1453 HEADER_ITEM *lpItem;
1454 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1455 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1457 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1458 infoPtr->iMoveItem,oldindex,nItem,newindex);
1459 lpItem= &infoPtr->items[nItem];
1460 lpItem->iOrder=oldindex;
1462 lpItem= &infoPtr->items[infoPtr->iMoveItem];
1463 lpItem->iOrder = newindex;
1465 infoPtr->bRectsValid = FALSE;
1466 InvalidateRect(hwnd, NULL, FALSE);
1467 /* FIXME: Should some WM_NOTIFY be sent */
1470 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1471 infoPtr->bPressed = FALSE;
1473 else if (infoPtr->bTracking) {
1474 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1475 infoPtr->bTracking = FALSE;
1477 HEADER_SendHeaderNotify (hwnd, HDN_ENDTRACKA, infoPtr->iMoveItem,HDI_WIDTH);
1480 * we want to do this even for HDS_FULLDRAG because this is where
1481 * we send the HDN_ITEMCHANGING and HDN_ITEMCHANGED notifications
1483 * if (!(dwStyle & HDS_FULLDRAG)) {
1487 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1488 ReleaseDC (hwnd, hdc);
1489 if (HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1491 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1494 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1497 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1500 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH);
1501 HEADER_SetItemBounds (hwnd);
1502 InvalidateRect(hwnd, NULL, FALSE);
1508 if (infoPtr->bCaptured) {
1509 infoPtr->bCaptured = FALSE;
1511 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1519 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1521 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1526 return infoPtr->nNotifyFormat;
1529 infoPtr->nNotifyFormat =
1530 SendMessageA ((HWND)wParam, WM_NOTIFYFORMAT,
1531 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1532 return infoPtr->nNotifyFormat;
1540 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1542 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1543 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1549 pt.x = (INT)(SHORT)LOWORD(lParam);
1550 pt.y = (INT)(SHORT)HIWORD(lParam);
1551 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1553 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1554 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1555 infoPtr->iHotItem = nItem;
1557 infoPtr->iHotItem = -1;
1558 InvalidateRect(hwnd, NULL, FALSE);
1561 if (infoPtr->bCaptured) {
1562 if (infoPtr->bPressed) {
1563 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1564 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1566 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1568 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1569 ReleaseDC (hwnd, hdc);
1571 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1573 else if (infoPtr->bTracking) {
1574 if (dwStyle & HDS_FULLDRAG) {
1575 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1577 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1580 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1581 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1583 HEADER_SetItemBounds (hwnd);
1584 InvalidateRect(hwnd, NULL, FALSE);
1588 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1589 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1590 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1591 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1592 infoPtr->items[infoPtr->iMoveItem].cxy =
1593 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1594 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1595 ReleaseDC (hwnd, hdc);
1596 HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH);
1599 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1603 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1604 FIXME("hot track support!\n");
1612 HEADER_Paint (HWND hwnd, WPARAM wParam)
1617 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1618 HEADER_Refresh (hwnd, hdc);
1620 EndPaint (hwnd, &ps);
1626 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1631 pt.x = LOWORD(lParam);
1632 pt.y = HIWORD(lParam);
1634 /* Send a Notify message */
1635 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1637 /* Change to screen coordinate for WM_CONTEXTMENU */
1638 ClientToScreen(hwnd, &pt);
1640 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1641 SendMessageA( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1648 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1650 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1655 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1658 ScreenToClient (hwnd, &pt);
1660 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1662 if (flags == HHT_ONDIVIDER)
1663 SetCursor (infoPtr->hcurDivider);
1664 else if (flags == HHT_ONDIVOPEN)
1665 SetCursor (infoPtr->hcurDivopen);
1667 SetCursor (infoPtr->hcurArrow);
1674 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1676 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1678 HFONT hFont, hOldFont;
1681 infoPtr->hFont = (HFONT)wParam;
1683 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1686 hOldFont = SelectObject (hdc, hFont);
1687 GetTextMetricsA (hdc, &tm);
1688 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1689 SelectObject (hdc, hOldFont);
1692 infoPtr->bRectsValid = FALSE;
1695 InvalidateRect(hwnd, NULL, FALSE);
1702 static LRESULT WINAPI
1703 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1705 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1706 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1707 return DefWindowProcA (hwnd, msg, wParam, lParam);
1709 /* case HDM_CLEARFILTER: */
1711 case HDM_CREATEDRAGIMAGE:
1712 return HEADER_CreateDragImage (hwnd, wParam);
1714 case HDM_DELETEITEM:
1715 return HEADER_DeleteItem (hwnd, wParam);
1717 /* case HDM_EDITFILTER: */
1719 case HDM_GETBITMAPMARGIN:
1720 return HEADER_GetBitmapMargin(hwnd);
1722 case HDM_GETIMAGELIST:
1723 return HEADER_GetImageList (hwnd);
1726 return HEADER_GetItemA (hwnd, wParam, lParam);
1729 return HEADER_GetItemW (hwnd, wParam, lParam);
1731 case HDM_GETITEMCOUNT:
1732 return HEADER_GetItemCount (hwnd);
1734 case HDM_GETITEMRECT:
1735 return HEADER_GetItemRect (hwnd, wParam, lParam);
1737 case HDM_GETORDERARRAY:
1738 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1740 case HDM_GETUNICODEFORMAT:
1741 return HEADER_GetUnicodeFormat (hwnd);
1744 return HEADER_HitTest (hwnd, wParam, lParam);
1746 case HDM_INSERTITEMA:
1747 return HEADER_InsertItemA (hwnd, wParam, lParam);
1749 case HDM_INSERTITEMW:
1750 return HEADER_InsertItemW (hwnd, wParam, lParam);
1753 return HEADER_Layout (hwnd, wParam, lParam);
1755 case HDM_ORDERTOINDEX:
1756 return HEADER_OrderToIndex(hwnd, wParam);
1758 case HDM_SETBITMAPMARGIN:
1759 return HEADER_SetBitmapMargin(hwnd, wParam);
1761 /* case HDM_SETFILTERCHANGETIMEOUT: */
1763 /* case HDM_SETHOTDIVIDER: */
1765 case HDM_SETIMAGELIST:
1766 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
1769 return HEADER_SetItemA (hwnd, wParam, lParam);
1772 return HEADER_SetItemW (hwnd, wParam, lParam);
1774 case HDM_SETORDERARRAY:
1775 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1777 case HDM_SETUNICODEFORMAT:
1778 return HEADER_SetUnicodeFormat (hwnd, wParam);
1781 return HEADER_Create (hwnd, wParam, lParam);
1784 return HEADER_Destroy (hwnd, wParam, lParam);
1790 return DLGC_WANTTAB | DLGC_WANTARROWS;
1793 return HEADER_GetFont (hwnd);
1795 case WM_LBUTTONDBLCLK:
1796 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1798 case WM_LBUTTONDOWN:
1799 return HEADER_LButtonDown (hwnd, wParam, lParam);
1802 return HEADER_LButtonUp (hwnd, wParam, lParam);
1805 return HEADER_MouseMove (hwnd, wParam, lParam);
1807 case WM_NOTIFYFORMAT:
1808 return HEADER_NotifyFormat (hwnd, wParam, lParam);
1811 return HEADER_Size (hwnd, wParam);
1814 return HEADER_Paint (hwnd, wParam);
1817 return HEADER_RButtonUp (hwnd, wParam, lParam);
1820 return HEADER_SetCursor (hwnd, wParam, lParam);
1823 return HEADER_SetFont (hwnd, wParam, lParam);
1826 if ((msg >= WM_USER) && (msg < WM_APP))
1827 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1828 msg, wParam, lParam );
1829 return DefWindowProcA (hwnd, msg, wParam, lParam);
1836 HEADER_Register (void)
1840 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1841 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1842 wndClass.lpfnWndProc = (WNDPROC)HEADER_WindowProc;
1843 wndClass.cbClsExtra = 0;
1844 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1845 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
1846 wndClass.lpszClassName = WC_HEADERA;
1848 RegisterClassA (&wndClass);
1853 HEADER_Unregister (void)
1855 UnregisterClassA (WC_HEADERA, NULL);