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 an 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];
166 INT oldBkMode, cxEdge = GetSystemMetrics(SM_CXEDGE);
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 (GetWindowLongW (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);
194 if (phdi->fmt & HDF_OWNERDRAW) {
196 dis.CtlType = ODT_HEADER;
197 dis.CtlID = GetWindowLongPtrW (hwnd, GWLP_ID);
199 dis.itemAction = ODA_DRAWENTIRE;
200 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
204 dis.itemData = phdi->lParam;
205 oldBkMode = SetBkMode(hdc, TRANSPARENT);
206 SendMessageW (infoPtr->hwndNotify, WM_DRAWITEM,
207 (WPARAM)dis.CtlID, (LPARAM)&dis);
208 if (oldBkMode != TRANSPARENT)
209 SetBkMode(hdc, oldBkMode);
212 UINT rw, rh, /* width and height of r */
213 *x = NULL, *w = NULL; /* x and width of the pic (bmp or img) which is part of cnt */
214 /* cnt,txt,img,bmp */
219 cw = tw = iw = bw = 0;
220 rw = r.right - r.left;
221 rh = r.bottom - r.top;
223 if (phdi->fmt & HDF_STRING) {
226 DrawTextW (hdc, phdi->pszText, -1,
227 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
228 cw = textRect.right - textRect.left + 2 * infoPtr->iMargin;
231 if ((phdi->fmt & HDF_IMAGE) && (infoPtr->himl)) {
232 iw = infoPtr->himl->cx + 2 * infoPtr->iMargin;
237 if ((phdi->fmt & HDF_BITMAP) && (phdi->hbm)) {
238 GetObjectW (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
239 bw = bmp.bmWidth + 2 * infoPtr->iMargin;
249 /* align cx using the unclipped cw */
250 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_LEFT)
252 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
253 cx = r.left + rw / 2 - cw / 2;
260 if (cx + cw > r.right)
263 tx = cx + infoPtr->iMargin;
264 /* since cw might have changed we have to recalculate tw */
265 tw = cw - infoPtr->iMargin * 2;
269 if (phdi->fmt & HDF_BITMAP_ON_RIGHT) {
270 /* put pic behind text */
271 *x = cx + tw + infoPtr->iMargin * 3;
273 *x = cx + infoPtr->iMargin;
274 /* move text behind pic */
280 /* since we're done with the layout we can
281 now calculate the position of bmp which
282 has no influence on alignment and layout
284 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
285 bx = cx - bw + infoPtr->iMargin;
287 bx = cx + cw + infoPtr->iMargin;
291 HDC hClipDC = GetDC(hwnd);
292 HRGN hClipRgn = CreateRectRgn(r.left, r.top, r.right, r.bottom);
293 SelectClipRgn(hClipDC, hClipRgn);
296 HDC hdcBitmap = CreateCompatibleDC (hClipDC);
297 SelectObject (hdcBitmap, phdi->hbm);
298 BitBlt (hClipDC, bx, r.top + ((INT)rh - bmp.bmHeight) / 2,
299 bmp.bmWidth, bmp.bmHeight, hdcBitmap, 0, 0, SRCCOPY);
300 DeleteDC (hdcBitmap);
304 ImageList_DrawEx (infoPtr->himl, phdi->iImage, hClipDC,
305 ix, r.top + ((INT)rh - infoPtr->himl->cy) / 2,
306 infoPtr->himl->cx, infoPtr->himl->cy, CLR_DEFAULT, CLR_DEFAULT, 0);
309 DeleteObject(hClipRgn);
313 if (((phdi->fmt & HDF_STRING)
314 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
315 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
316 && (phdi->pszText)) {
317 oldBkMode = SetBkMode(hdc, TRANSPARENT);
318 SetTextColor (hdc, (bHotTrack) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
321 DrawTextW (hdc, phdi->pszText, -1,
322 &r, DT_LEFT|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
323 if (oldBkMode != TRANSPARENT)
324 SetBkMode(hdc, oldBkMode);
328 return phdi->rect.right;
333 HEADER_Refresh (HWND hwnd, HDC hdc)
335 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
336 HFONT hFont, hOldFont;
342 /* get rect for the bar, adjusted for the border */
343 GetClientRect (hwnd, &rect);
345 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
346 hOldFont = SelectObject (hdc, hFont);
348 /* draw Background */
349 hbrBk = GetSysColorBrush(COLOR_3DFACE);
350 FillRect(hdc, &rect, hbrBk);
353 for (i = 0; i < infoPtr->uNumItem; i++) {
354 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i), FALSE);
357 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
359 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS)
360 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
362 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
365 SelectObject (hdc, hOldFont);
370 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
372 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
373 HFONT hFont, hOldFont;
375 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
376 hOldFont = SelectObject (hdc, hFont);
377 HEADER_DrawItem (hwnd, hdc, iItem, FALSE);
378 SelectObject (hdc, hOldFont);
383 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
385 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
391 GetClientRect (hwnd, &rect);
395 if (PtInRect (&rect, *lpPt))
397 if (infoPtr->uNumItem == 0) {
398 *pFlags |= HHT_NOWHERE;
404 /* somewhere inside */
405 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
406 rect = infoPtr->items[iCount].rect;
407 width = rect.right - rect.left;
412 if (PtInRect (&rect, *lpPt)) {
413 if (width <= 2 * DIVIDER_WIDTH) {
414 *pFlags |= HHT_ONHEADER;
416 TRACE("ON HEADER %d\n", iCount);
421 rcTest.right = rcTest.left + DIVIDER_WIDTH;
422 if (PtInRect (&rcTest, *lpPt)) {
424 *pFlags |= HHT_ONDIVOPEN;
426 TRACE("ON DIVOPEN %d\n", *pItem);
430 *pFlags |= HHT_ONDIVIDER;
432 TRACE("ON DIVIDER %d\n", *pItem);
438 rcTest.left = rcTest.right - DIVIDER_WIDTH;
439 if (PtInRect (&rcTest, *lpPt)) {
440 *pFlags |= HHT_ONDIVIDER;
442 TRACE("ON DIVIDER %d\n", *pItem);
446 *pFlags |= HHT_ONHEADER;
448 TRACE("ON HEADER %d\n", iCount);
453 /* check for last divider part (on nowhere) */
454 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
455 rect.left = rect.right;
456 rect.right += DIVIDER_WIDTH;
457 if (PtInRect (&rect, *lpPt)) {
459 *pFlags |= HHT_ONDIVOPEN;
460 *pItem = infoPtr->uNumItem - 1;
461 TRACE("ON DIVOPEN %d\n", *pItem);
465 *pFlags |= HHT_ONDIVIDER;
466 *pItem = infoPtr->uNumItem-1;
467 TRACE("ON DIVIDER %d\n", *pItem);
472 *pFlags |= HHT_NOWHERE;
479 if (lpPt->x < rect.left) {
481 *pFlags |= HHT_TOLEFT;
483 else if (lpPt->x > rect.right) {
485 *pFlags |= HHT_TORIGHT;
488 if (lpPt->y < rect.top) {
490 *pFlags |= HHT_ABOVE;
492 else if (lpPt->y > rect.bottom) {
494 *pFlags |= HHT_BELOW;
499 TRACE("flags=0x%X\n", *pFlags);
505 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
511 GetClientRect (hwnd, &rect);
513 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
514 oldRop = SetROP2 (hdc, R2_XORPEN);
515 MoveToEx (hdc, x, rect.top, NULL);
516 LineTo (hdc, x, rect.bottom);
517 SetROP2 (hdc, oldRop);
518 SelectObject (hdc, hOldPen);
523 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
525 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
528 nmhdr.hwndFrom = hwnd;
529 nmhdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
532 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
533 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
537 HEADER_SendHeaderNotify (HWND hwnd, UINT code, INT iItem, INT mask)
539 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
543 nmhdr.hdr.hwndFrom = hwnd;
544 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
545 nmhdr.hdr.code = code;
548 nmhdr.pitem = &nmitem;
550 nmitem.cxy = infoPtr->items[iItem].cxy;
551 nmitem.hbm = infoPtr->items[iItem].hbm;
552 nmitem.pszText = NULL;
553 nmitem.cchTextMax = 0;
554 /* nmitem.pszText = infoPtr->items[iItem].pszText; */
555 /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
556 nmitem.fmt = infoPtr->items[iItem].fmt;
557 nmitem.lParam = infoPtr->items[iItem].lParam;
558 nmitem.iOrder = infoPtr->items[iItem].iOrder;
559 nmitem.iImage = infoPtr->items[iItem].iImage;
561 return (BOOL)SendMessageW (infoPtr->hwndNotify, WM_NOTIFY,
562 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
567 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
569 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
572 nmhdr.hdr.hwndFrom = hwnd;
573 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
574 nmhdr.hdr.code = code;
579 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
580 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
585 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
587 FIXME("empty stub!\n");
593 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
595 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
596 INT iItem = (INT)wParam;
598 TRACE("[iItem=%d]\n", iItem);
600 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
603 if (infoPtr->uNumItem == 1) {
604 TRACE("Simple delete!\n");
605 if (infoPtr->items[0].pszText)
606 Free (infoPtr->items[0].pszText);
607 Free (infoPtr->items);
609 infoPtr->uNumItem = 0;
612 HEADER_ITEM *oldItems = infoPtr->items;
616 TRACE("Complex delete! [iItem=%d]\n", iItem);
618 if (infoPtr->items[iItem].pszText)
619 Free (infoPtr->items[iItem].pszText);
620 iOrder = infoPtr->items[iItem].iOrder;
623 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
624 /* pre delete copy */
626 memcpy (&infoPtr->items[0], &oldItems[0],
627 iItem * sizeof(HEADER_ITEM));
630 /* post delete copy */
631 if (iItem < infoPtr->uNumItem) {
632 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
633 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
636 /* Correct the orders */
637 for (i=infoPtr->uNumItem, pItem = infoPtr->items; i; i--, pItem++)
639 if (pItem->iOrder > iOrder)
645 HEADER_SetItemBounds (hwnd);
647 InvalidateRect(hwnd, NULL, FALSE);
654 HEADER_GetImageList (HWND hwnd)
656 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
658 return (LRESULT)infoPtr->himl;
663 HEADER_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
665 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
666 HDITEMA *phdi = (HDITEMA*)lParam;
667 INT nItem = (INT)wParam;
673 TRACE("[nItem=%d]\n", nItem);
678 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem)) {
682 lpItem = &infoPtr->items[nItem];
685 if (phdi->mask & HDI_BITMAP)
686 phdi->hbm = (lpItem != NULL) ? lpItem->hbm : 0;
688 if (phdi->mask & HDI_FORMAT)
689 phdi->fmt = (lpItem != NULL) ? lpItem->fmt : 0;
691 if (phdi->mask & HDI_WIDTH)
692 phdi->cxy = (lpItem != NULL) ? lpItem->cxy : 0;
694 if (phdi->mask & HDI_LPARAM)
695 phdi->lParam = (lpItem != NULL) ? lpItem->lParam : 0;
697 if (phdi->mask & HDI_TEXT) {
698 if (lpItem == NULL) {
701 else if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
703 WideCharToMultiByte (CP_ACP, 0, lpItem->pszText, -1,
704 phdi->pszText, phdi->cchTextMax, NULL, NULL);
709 phdi->pszText = LPSTR_TEXTCALLBACKA;
712 if (phdi->mask & HDI_IMAGE)
713 phdi->iImage = (lpItem != NULL) ? lpItem->iImage : 0;
715 if (phdi->mask & HDI_ORDER)
716 phdi->iOrder = (lpItem != NULL) ? lpItem->iOrder : 0;
723 HEADER_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
725 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
726 HDITEMW *phdi = (HDITEMW*)lParam;
727 INT nItem = (INT)wParam;
733 TRACE("[nItem=%d]\n", nItem);
738 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem)) {
742 lpItem = &infoPtr->items[nItem];
745 if (phdi->mask & HDI_BITMAP)
746 phdi->hbm = (lpItem != NULL) ? lpItem->hbm : 0;
748 if (phdi->mask & HDI_FORMAT)
749 phdi->fmt = (lpItem != NULL) ? lpItem->fmt : 0;
751 if (phdi->mask & HDI_WIDTH)
752 phdi->cxy = (lpItem != NULL) ? lpItem->cxy : 0;
754 if (phdi->mask & HDI_LPARAM)
755 phdi->lParam = (lpItem != NULL) ? lpItem->lParam : 0;
757 if (phdi->mask & HDI_TEXT) {
758 if (lpItem == NULL) {
761 else if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
763 lstrcpynW (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
768 phdi->pszText = LPSTR_TEXTCALLBACKW;
771 if (phdi->mask & HDI_IMAGE)
772 phdi->iImage = (lpItem != NULL) ? lpItem->iImage : 0;
774 if (phdi->mask & HDI_ORDER)
775 phdi->iOrder = (lpItem != NULL) ? lpItem->iOrder : 0;
781 inline static LRESULT
782 HEADER_GetItemCount (HWND hwnd)
784 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
785 return infoPtr->uNumItem;
790 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
792 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
793 INT iItem = (INT)wParam;
794 LPRECT lpRect = (LPRECT)lParam;
796 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
799 lpRect->left = infoPtr->items[iItem].rect.left;
800 lpRect->right = infoPtr->items[iItem].rect.right;
801 lpRect->top = infoPtr->items[iItem].rect.top;
802 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
809 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
812 LPINT order = (LPINT) lParam;
813 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
815 if ((unsigned int)wParam <infoPtr->uNumItem)
817 for (i=0; i<(int)wParam; i++)
818 *order++=HEADER_OrderToIndex(hwnd,i);
823 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
826 LPINT order = (LPINT) lParam;
827 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
830 if ((unsigned int)wParam <infoPtr->uNumItem)
832 for (i=0; i<(int)wParam; i++)
834 lpItem = &infoPtr->items[*order++];
837 infoPtr->bRectsValid=0;
838 InvalidateRect(hwnd, NULL, FALSE);
842 inline static LRESULT
843 HEADER_GetUnicodeFormat (HWND hwnd)
845 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
846 return infoPtr->bUnicode;
851 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
853 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
855 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
857 if (phti->flags == HHT_NOWHERE)
865 HEADER_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
867 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
868 HDITEMA *phdi = (HDITEMA*)lParam;
869 INT nItem = (INT)wParam;
874 if ((phdi == NULL) || (nItem < 0))
877 if (nItem > infoPtr->uNumItem)
878 nItem = infoPtr->uNumItem;
880 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
882 if (infoPtr->uNumItem == 0) {
883 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
887 HEADER_ITEM *oldItems = infoPtr->items;
890 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
892 memcpy (&infoPtr->items[1], &oldItems[0],
893 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
897 /* pre insert copy */
899 memcpy (&infoPtr->items[0], &oldItems[0],
900 nItem * sizeof(HEADER_ITEM));
903 /* post insert copy */
904 if (nItem < infoPtr->uNumItem - 1) {
905 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
906 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
913 for (i=0; i < infoPtr->uNumItem; i++)
915 if (infoPtr->items[i].iOrder >= iOrder)
916 infoPtr->items[i].iOrder++;
919 lpItem = &infoPtr->items[nItem];
920 lpItem->bDown = FALSE;
922 if (phdi->mask & HDI_WIDTH)
923 lpItem->cxy = phdi->cxy;
925 if (phdi->mask & HDI_TEXT) {
926 if (!phdi->pszText) /* null pointer check */
928 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
929 len = MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, NULL, 0);
930 lpItem->pszText = Alloc( len*sizeof(WCHAR) );
931 MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, lpItem->pszText, len);
934 lpItem->pszText = LPSTR_TEXTCALLBACKW;
937 if (phdi->mask & HDI_FORMAT)
938 lpItem->fmt = phdi->fmt;
940 if (lpItem->fmt == 0)
941 lpItem->fmt = HDF_LEFT;
943 if (!(lpItem->fmt & HDF_STRING) && (phdi->mask & HDI_TEXT))
945 lpItem->fmt |= HDF_STRING;
947 if (phdi->mask & HDI_BITMAP)
948 lpItem->hbm = phdi->hbm;
950 if (phdi->mask & HDI_LPARAM)
951 lpItem->lParam = phdi->lParam;
953 if (phdi->mask & HDI_IMAGE)
954 lpItem->iImage = phdi->iImage;
956 lpItem->iOrder = iOrder;
958 HEADER_SetItemBounds (hwnd);
960 InvalidateRect(hwnd, NULL, FALSE);
967 HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
969 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
970 HDITEMW *phdi = (HDITEMW*)lParam;
971 INT nItem = (INT)wParam;
976 if ((phdi == NULL) || (nItem < 0))
979 if (nItem > infoPtr->uNumItem)
980 nItem = infoPtr->uNumItem;
982 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
984 if (infoPtr->uNumItem == 0) {
985 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
989 HEADER_ITEM *oldItems = infoPtr->items;
992 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
994 memcpy (&infoPtr->items[1], &oldItems[0],
995 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
999 /* pre insert copy */
1001 memcpy (&infoPtr->items[0], &oldItems[0],
1002 nItem * sizeof(HEADER_ITEM));
1005 /* post insert copy */
1006 if (nItem < infoPtr->uNumItem - 1) {
1007 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
1008 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
1015 for (i=0; i < infoPtr->uNumItem; i++)
1017 if (infoPtr->items[i].iOrder >= iOrder)
1018 infoPtr->items[i].iOrder++;
1021 lpItem = &infoPtr->items[nItem];
1022 lpItem->bDown = FALSE;
1024 if (phdi->mask & HDI_WIDTH)
1025 lpItem->cxy = phdi->cxy;
1027 if (phdi->mask & HDI_TEXT) {
1028 WCHAR wide_null_char = 0;
1029 if (!phdi->pszText) /* null pointer check */
1030 phdi->pszText = &wide_null_char;
1031 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1032 len = strlenW (phdi->pszText);
1033 lpItem->pszText = Alloc ((len+1)*sizeof(WCHAR));
1034 strcpyW (lpItem->pszText, phdi->pszText);
1037 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1040 if (phdi->mask & HDI_FORMAT)
1041 lpItem->fmt = phdi->fmt;
1043 if (lpItem->fmt == 0)
1044 lpItem->fmt = HDF_LEFT;
1046 if (!(lpItem->fmt &HDF_STRING) && (phdi->mask & HDI_TEXT))
1048 lpItem->fmt |= HDF_STRING;
1050 if (phdi->mask & HDI_BITMAP)
1051 lpItem->hbm = phdi->hbm;
1053 if (phdi->mask & HDI_LPARAM)
1054 lpItem->lParam = phdi->lParam;
1056 if (phdi->mask & HDI_IMAGE)
1057 lpItem->iImage = phdi->iImage;
1059 lpItem->iOrder = iOrder;
1061 HEADER_SetItemBounds (hwnd);
1063 InvalidateRect(hwnd, NULL, FALSE);
1070 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
1072 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1073 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1075 lpLayout->pwpos->hwnd = hwnd;
1076 lpLayout->pwpos->hwndInsertAfter = 0;
1077 lpLayout->pwpos->x = lpLayout->prc->left;
1078 lpLayout->pwpos->y = lpLayout->prc->top;
1079 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1080 if (GetWindowLongW (hwnd, GWL_STYLE) & HDS_HIDDEN)
1081 lpLayout->pwpos->cy = 0;
1083 lpLayout->pwpos->cy = infoPtr->nHeight;
1084 lpLayout->prc->top += infoPtr->nHeight;
1086 lpLayout->pwpos->flags = SWP_NOZORDER;
1088 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1089 lpLayout->pwpos->x, lpLayout->pwpos->y,
1090 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1092 infoPtr->bRectsValid = FALSE;
1099 HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
1101 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1104 TRACE("(himl 0x%x)\n", (int)himl);
1105 himlOld = infoPtr->himl;
1106 infoPtr->himl = himl;
1108 /* FIXME: Refresh needed??? */
1110 return (LRESULT)himlOld;
1115 HEADER_GetBitmapMargin(HWND hwnd)
1117 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
1119 return infoPtr->iMargin;
1123 HEADER_SetBitmapMargin(HWND hwnd, WPARAM wParam)
1125 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1126 INT oldMargin = infoPtr->iMargin;
1128 infoPtr->iMargin = (INT)wParam;
1134 HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1136 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1137 HDITEMA *phdi = (HDITEMA*)lParam;
1138 INT nItem = (INT)wParam;
1139 HEADER_ITEM *lpItem;
1143 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1146 TRACE("[nItem=%d]\n", nItem);
1148 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem, phdi->mask))
1151 lpItem = &infoPtr->items[nItem];
1152 if (phdi->mask & HDI_BITMAP)
1153 lpItem->hbm = phdi->hbm;
1155 if (phdi->mask & HDI_FORMAT)
1156 lpItem->fmt = phdi->fmt;
1158 if (phdi->mask & HDI_LPARAM)
1159 lpItem->lParam = phdi->lParam;
1161 if (phdi->mask & HDI_TEXT) {
1162 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
1163 if (lpItem->pszText) {
1164 Free (lpItem->pszText);
1165 lpItem->pszText = NULL;
1167 if (phdi->pszText) {
1168 INT len = MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,NULL,0);
1169 lpItem->pszText = Alloc( len*sizeof(WCHAR) );
1170 MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,lpItem->pszText,len);
1174 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1177 if (phdi->mask & HDI_WIDTH)
1178 lpItem->cxy = phdi->cxy;
1180 if (phdi->mask & HDI_IMAGE)
1181 lpItem->iImage = phdi->iImage;
1183 if (phdi->mask & HDI_ORDER)
1185 lpItem->iOrder = phdi->iOrder;
1188 HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem, phdi->mask);
1190 HEADER_SetItemBounds (hwnd);
1192 InvalidateRect(hwnd, NULL, FALSE);
1199 HEADER_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1201 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1202 HDITEMW *phdi = (HDITEMW*)lParam;
1203 INT nItem = (INT)wParam;
1204 HEADER_ITEM *lpItem;
1208 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1211 TRACE("[nItem=%d]\n", nItem);
1213 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask))
1216 lpItem = &infoPtr->items[nItem];
1217 if (phdi->mask & HDI_BITMAP)
1218 lpItem->hbm = phdi->hbm;
1220 if (phdi->mask & HDI_FORMAT)
1221 lpItem->fmt = phdi->fmt;
1223 if (phdi->mask & HDI_LPARAM)
1224 lpItem->lParam = phdi->lParam;
1226 if (phdi->mask & HDI_TEXT) {
1227 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1228 if (lpItem->pszText) {
1229 Free (lpItem->pszText);
1230 lpItem->pszText = NULL;
1232 if (phdi->pszText) {
1233 INT len = strlenW (phdi->pszText);
1234 lpItem->pszText = Alloc ((len+1)*sizeof(WCHAR));
1235 strcpyW (lpItem->pszText, phdi->pszText);
1239 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1242 if (phdi->mask & HDI_WIDTH)
1243 lpItem->cxy = phdi->cxy;
1245 if (phdi->mask & HDI_IMAGE)
1246 lpItem->iImage = phdi->iImage;
1248 if (phdi->mask & HDI_ORDER)
1250 lpItem->iOrder = phdi->iOrder;
1253 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDW, nItem, phdi->mask);
1255 HEADER_SetItemBounds (hwnd);
1257 InvalidateRect(hwnd, NULL, FALSE);
1262 inline static LRESULT
1263 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1265 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1266 BOOL bTemp = infoPtr->bUnicode;
1268 infoPtr->bUnicode = (BOOL)wParam;
1275 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1277 HEADER_INFO *infoPtr;
1282 infoPtr = (HEADER_INFO *)Alloc (sizeof(HEADER_INFO));
1283 SetWindowLongPtrW (hwnd, 0, (DWORD_PTR)infoPtr);
1285 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
1286 infoPtr->uNumItem = 0;
1289 infoPtr->bRectsValid = FALSE;
1290 infoPtr->hcurArrow = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1291 infoPtr->hcurDivider = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDER));
1292 infoPtr->hcurDivopen = LoadCursorW (COMCTL32_hModule, MAKEINTRESOURCEW(IDC_DIVIDEROPEN));
1293 infoPtr->bPressed = FALSE;
1294 infoPtr->bTracking = FALSE;
1295 infoPtr->iMoveItem = 0;
1297 infoPtr->iHotItem = -1;
1298 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1299 infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
1300 infoPtr->nNotifyFormat =
1301 SendMessageW (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1304 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1305 GetTextMetricsW (hdc, &tm);
1306 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1307 SelectObject (hdc, hOldFont);
1315 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1317 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1318 HEADER_ITEM *lpItem;
1321 if (infoPtr->items) {
1322 lpItem = infoPtr->items;
1323 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1324 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
1325 Free (lpItem->pszText);
1327 Free (infoPtr->items);
1331 ImageList_Destroy (infoPtr->himl);
1333 SetWindowLongPtrW (hwnd, 0, 0);
1339 static inline LRESULT
1340 HEADER_GetFont (HWND hwnd)
1342 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1344 return (LRESULT)infoPtr->hFont;
1349 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1355 pt.x = (INT)LOWORD(lParam);
1356 pt.y = (INT)HIWORD(lParam);
1357 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1359 if ((GetWindowLongW (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1360 HEADER_SendHeaderNotify (hwnd, HDN_ITEMDBLCLICKA, nItem,0);
1361 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1362 HEADER_SendHeaderNotify (hwnd, HDN_DIVIDERDBLCLICKA, nItem,0);
1369 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1371 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1372 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1378 pt.x = (INT)LOWORD(lParam);
1379 pt.y = (INT)HIWORD(lParam);
1380 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1382 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1384 infoPtr->bCaptured = TRUE;
1385 infoPtr->bPressed = TRUE;
1386 infoPtr->iMoveItem = nItem;
1388 infoPtr->items[nItem].bDown = TRUE;
1390 /* Send WM_CUSTOMDRAW */
1392 HEADER_RefreshItem (hwnd, hdc, nItem);
1393 ReleaseDC (hwnd, hdc);
1395 TRACE("Pressed item %d!\n", nItem);
1397 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1398 if (!(HEADER_SendHeaderNotify (hwnd, HDN_BEGINTRACKA, nItem,0))) {
1400 infoPtr->bCaptured = TRUE;
1401 infoPtr->bTracking = TRUE;
1402 infoPtr->iMoveItem = nItem;
1403 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1404 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1406 if (!(dwStyle & HDS_FULLDRAG)) {
1407 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1409 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1410 ReleaseDC (hwnd, hdc);
1413 TRACE("Begin tracking item %d!\n", nItem);
1422 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1424 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1426 *DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1433 pt.x = (INT)(SHORT)LOWORD(lParam);
1434 pt.y = (INT)(SHORT)HIWORD(lParam);
1435 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1437 if (infoPtr->bPressed) {
1438 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1439 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1441 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1442 ReleaseDC (hwnd, hdc);
1444 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1446 else if (flags == HHT_ONHEADER)
1448 HEADER_ITEM *lpItem;
1449 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1450 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1452 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1453 infoPtr->iMoveItem,oldindex,nItem,newindex);
1454 lpItem= &infoPtr->items[nItem];
1455 lpItem->iOrder=oldindex;
1457 lpItem= &infoPtr->items[infoPtr->iMoveItem];
1458 lpItem->iOrder = newindex;
1460 infoPtr->bRectsValid = FALSE;
1461 InvalidateRect(hwnd, NULL, FALSE);
1462 /* FIXME: Should some WM_NOTIFY be sent */
1465 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1466 infoPtr->bPressed = FALSE;
1468 else if (infoPtr->bTracking) {
1469 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1470 infoPtr->bTracking = FALSE;
1472 HEADER_SendHeaderNotify (hwnd, HDN_ENDTRACKA, infoPtr->iMoveItem,HDI_WIDTH);
1475 * we want to do this even for HDS_FULLDRAG because this is where
1476 * we send the HDN_ITEMCHANGING and HDN_ITEMCHANGED notifications
1478 * if (!(dwStyle & HDS_FULLDRAG)) {
1482 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1483 ReleaseDC (hwnd, hdc);
1484 if (HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1486 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1489 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1492 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1495 HEADER_SetItemBounds (hwnd);
1496 InvalidateRect(hwnd, NULL, TRUE);
1497 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1503 if (infoPtr->bCaptured) {
1504 infoPtr->bCaptured = FALSE;
1506 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1514 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1516 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1521 return infoPtr->nNotifyFormat;
1524 infoPtr->nNotifyFormat =
1525 SendMessageW ((HWND)wParam, WM_NOTIFYFORMAT,
1526 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1527 return infoPtr->nNotifyFormat;
1535 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1537 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1538 DWORD dwStyle = GetWindowLongW (hwnd, GWL_STYLE);
1544 pt.x = (INT)(SHORT)LOWORD(lParam);
1545 pt.y = (INT)(SHORT)HIWORD(lParam);
1546 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1548 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1549 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1550 infoPtr->iHotItem = nItem;
1552 infoPtr->iHotItem = -1;
1553 InvalidateRect(hwnd, NULL, FALSE);
1556 if (infoPtr->bCaptured) {
1557 if (infoPtr->bPressed) {
1558 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1559 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1561 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1563 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1564 ReleaseDC (hwnd, hdc);
1566 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1568 else if (infoPtr->bTracking) {
1569 if (dwStyle & HDS_FULLDRAG) {
1570 if (HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH))
1572 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1575 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1576 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1578 HEADER_SetItemBounds (hwnd);
1582 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1583 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1584 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1585 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1586 infoPtr->items[infoPtr->iMoveItem].cxy =
1587 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1588 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1589 ReleaseDC (hwnd, hdc);
1590 HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH);
1593 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1597 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1598 FIXME("hot track support!\n");
1606 HEADER_Paint (HWND hwnd, WPARAM wParam)
1611 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1612 HEADER_Refresh (hwnd, hdc);
1614 EndPaint (hwnd, &ps);
1620 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1625 pt.x = LOWORD(lParam);
1626 pt.y = HIWORD(lParam);
1628 /* Send a Notify message */
1629 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1631 /* Change to screen coordinate for WM_CONTEXTMENU */
1632 ClientToScreen(hwnd, &pt);
1634 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1635 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1642 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1644 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1649 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1652 ScreenToClient (hwnd, &pt);
1654 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1656 if (flags == HHT_ONDIVIDER)
1657 SetCursor (infoPtr->hcurDivider);
1658 else if (flags == HHT_ONDIVOPEN)
1659 SetCursor (infoPtr->hcurDivopen);
1661 SetCursor (infoPtr->hcurArrow);
1668 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1670 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1672 HFONT hFont, hOldFont;
1675 infoPtr->hFont = (HFONT)wParam;
1677 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1680 hOldFont = SelectObject (hdc, hFont);
1681 GetTextMetricsW (hdc, &tm);
1682 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1683 SelectObject (hdc, hOldFont);
1686 infoPtr->bRectsValid = FALSE;
1689 InvalidateRect(hwnd, NULL, FALSE);
1696 static LRESULT WINAPI
1697 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1699 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1700 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1701 return DefWindowProcW (hwnd, msg, wParam, lParam);
1703 /* case HDM_CLEARFILTER: */
1705 case HDM_CREATEDRAGIMAGE:
1706 return HEADER_CreateDragImage (hwnd, wParam);
1708 case HDM_DELETEITEM:
1709 return HEADER_DeleteItem (hwnd, wParam);
1711 /* case HDM_EDITFILTER: */
1713 case HDM_GETBITMAPMARGIN:
1714 return HEADER_GetBitmapMargin(hwnd);
1716 case HDM_GETIMAGELIST:
1717 return HEADER_GetImageList (hwnd);
1720 return HEADER_GetItemA (hwnd, wParam, lParam);
1723 return HEADER_GetItemW (hwnd, wParam, lParam);
1725 case HDM_GETITEMCOUNT:
1726 return HEADER_GetItemCount (hwnd);
1728 case HDM_GETITEMRECT:
1729 return HEADER_GetItemRect (hwnd, wParam, lParam);
1731 case HDM_GETORDERARRAY:
1732 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1734 case HDM_GETUNICODEFORMAT:
1735 return HEADER_GetUnicodeFormat (hwnd);
1738 return HEADER_HitTest (hwnd, wParam, lParam);
1740 case HDM_INSERTITEMA:
1741 return HEADER_InsertItemA (hwnd, wParam, lParam);
1743 case HDM_INSERTITEMW:
1744 return HEADER_InsertItemW (hwnd, wParam, lParam);
1747 return HEADER_Layout (hwnd, wParam, lParam);
1749 case HDM_ORDERTOINDEX:
1750 return HEADER_OrderToIndex(hwnd, wParam);
1752 case HDM_SETBITMAPMARGIN:
1753 return HEADER_SetBitmapMargin(hwnd, wParam);
1755 /* case HDM_SETFILTERCHANGETIMEOUT: */
1757 /* case HDM_SETHOTDIVIDER: */
1759 case HDM_SETIMAGELIST:
1760 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
1763 return HEADER_SetItemA (hwnd, wParam, lParam);
1766 return HEADER_SetItemW (hwnd, wParam, lParam);
1768 case HDM_SETORDERARRAY:
1769 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1771 case HDM_SETUNICODEFORMAT:
1772 return HEADER_SetUnicodeFormat (hwnd, wParam);
1775 return HEADER_Create (hwnd, wParam, lParam);
1778 return HEADER_Destroy (hwnd, wParam, lParam);
1784 return DLGC_WANTTAB | DLGC_WANTARROWS;
1787 return HEADER_GetFont (hwnd);
1789 case WM_LBUTTONDBLCLK:
1790 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1792 case WM_LBUTTONDOWN:
1793 return HEADER_LButtonDown (hwnd, wParam, lParam);
1796 return HEADER_LButtonUp (hwnd, wParam, lParam);
1799 return HEADER_MouseMove (hwnd, wParam, lParam);
1801 case WM_NOTIFYFORMAT:
1802 return HEADER_NotifyFormat (hwnd, wParam, lParam);
1805 return HEADER_Size (hwnd, wParam);
1808 return HEADER_Paint (hwnd, wParam);
1811 return HEADER_RButtonUp (hwnd, wParam, lParam);
1814 return HEADER_SetCursor (hwnd, wParam, lParam);
1817 return HEADER_SetFont (hwnd, wParam, lParam);
1820 if ((msg >= WM_USER) && (msg < WM_APP))
1821 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1822 msg, wParam, lParam );
1823 return DefWindowProcA (hwnd, msg, wParam, lParam);
1829 HEADER_Register (void)
1833 ZeroMemory (&wndClass, sizeof(WNDCLASSW));
1834 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1835 wndClass.lpfnWndProc = HEADER_WindowProc;
1836 wndClass.cbClsExtra = 0;
1837 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1838 wndClass.hCursor = LoadCursorW (0, (LPWSTR)IDC_ARROW);
1839 wndClass.lpszClassName = WC_HEADERW;
1841 RegisterClassW (&wndClass);
1846 HEADER_Unregister (void)
1848 UnregisterClassW (WC_HEADERW, NULL);