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 if (!phdi->pszText) /* null pointer check */
929 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
930 len = MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, NULL, 0);
931 lpItem->pszText = Alloc( len*sizeof(WCHAR) );
932 MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, lpItem->pszText, len);
935 lpItem->pszText = LPSTR_TEXTCALLBACKW;
938 if (phdi->mask & HDI_FORMAT)
939 lpItem->fmt = phdi->fmt;
941 if (lpItem->fmt == 0)
942 lpItem->fmt = HDF_LEFT;
944 if (!(lpItem->fmt & HDF_STRING) && (phdi->mask & HDI_TEXT))
946 lpItem->fmt |= HDF_STRING;
948 if (phdi->mask & HDI_BITMAP)
949 lpItem->hbm = phdi->hbm;
951 if (phdi->mask & HDI_LPARAM)
952 lpItem->lParam = phdi->lParam;
954 if (phdi->mask & HDI_IMAGE)
955 lpItem->iImage = phdi->iImage;
957 lpItem->iOrder = iOrder;
959 HEADER_SetItemBounds (hwnd);
961 InvalidateRect(hwnd, NULL, FALSE);
968 HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
970 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
971 HDITEMW *phdi = (HDITEMW*)lParam;
972 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 (GetWindowLongA (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 lpItem->iOrder = nItem;
1190 HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem, phdi->mask);
1192 HEADER_SetItemBounds (hwnd);
1194 InvalidateRect(hwnd, NULL, FALSE);
1201 HEADER_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1203 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1204 HDITEMW *phdi = (HDITEMW*)lParam;
1205 INT nItem = (INT)wParam;
1206 HEADER_ITEM *lpItem;
1210 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1213 TRACE("[nItem=%d]\n", nItem);
1215 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask))
1218 lpItem = &infoPtr->items[nItem];
1219 if (phdi->mask & HDI_BITMAP)
1220 lpItem->hbm = phdi->hbm;
1222 if (phdi->mask & HDI_FORMAT)
1223 lpItem->fmt = phdi->fmt;
1225 if (phdi->mask & HDI_LPARAM)
1226 lpItem->lParam = phdi->lParam;
1228 if (phdi->mask & HDI_TEXT) {
1229 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1230 if (lpItem->pszText) {
1231 Free (lpItem->pszText);
1232 lpItem->pszText = NULL;
1234 if (phdi->pszText) {
1235 INT len = strlenW (phdi->pszText);
1236 lpItem->pszText = Alloc ((len+1)*sizeof(WCHAR));
1237 strcpyW (lpItem->pszText, phdi->pszText);
1241 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1244 if (phdi->mask & HDI_WIDTH)
1245 lpItem->cxy = phdi->cxy;
1247 if (phdi->mask & HDI_IMAGE)
1248 lpItem->iImage = phdi->iImage;
1250 if (phdi->mask & HDI_ORDER)
1252 lpItem->iOrder = phdi->iOrder;
1255 lpItem->iOrder = nItem;
1257 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDW, nItem, phdi->mask);
1259 HEADER_SetItemBounds (hwnd);
1261 InvalidateRect(hwnd, NULL, FALSE);
1266 inline static LRESULT
1267 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1269 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1270 BOOL bTemp = infoPtr->bUnicode;
1272 infoPtr->bUnicode = (BOOL)wParam;
1279 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1281 HEADER_INFO *infoPtr;
1286 infoPtr = (HEADER_INFO *)Alloc (sizeof(HEADER_INFO));
1287 SetWindowLongA (hwnd, 0, (DWORD)infoPtr);
1289 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
1290 infoPtr->uNumItem = 0;
1293 infoPtr->bRectsValid = FALSE;
1294 infoPtr->hcurArrow = LoadCursorA (0, (LPSTR)IDC_ARROW);
1295 infoPtr->hcurDivider = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDER));
1296 infoPtr->hcurDivopen = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDEROPEN));
1297 infoPtr->bPressed = FALSE;
1298 infoPtr->bTracking = FALSE;
1299 infoPtr->iMoveItem = 0;
1301 infoPtr->iHotItem = -1;
1302 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1303 infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
1304 infoPtr->nNotifyFormat =
1305 SendMessageA (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1308 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1309 GetTextMetricsA (hdc, &tm);
1310 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1311 SelectObject (hdc, hOldFont);
1319 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1321 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1322 HEADER_ITEM *lpItem;
1325 if (infoPtr->items) {
1326 lpItem = infoPtr->items;
1327 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1328 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
1329 Free (lpItem->pszText);
1331 Free (infoPtr->items);
1335 ImageList_Destroy (infoPtr->himl);
1338 SetWindowLongA (hwnd, 0, 0);
1343 static inline LRESULT
1344 HEADER_GetFont (HWND hwnd)
1346 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1348 return (LRESULT)infoPtr->hFont;
1353 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1359 pt.x = (INT)LOWORD(lParam);
1360 pt.y = (INT)HIWORD(lParam);
1361 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1363 if ((GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1364 HEADER_SendHeaderNotify (hwnd, HDN_ITEMDBLCLICKA, nItem,0);
1365 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1366 HEADER_SendHeaderNotify (hwnd, HDN_DIVIDERDBLCLICKA, nItem,0);
1373 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1375 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1376 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1382 pt.x = (INT)LOWORD(lParam);
1383 pt.y = (INT)HIWORD(lParam);
1384 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1386 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1388 infoPtr->bCaptured = TRUE;
1389 infoPtr->bPressed = TRUE;
1390 infoPtr->iMoveItem = nItem;
1392 infoPtr->items[nItem].bDown = TRUE;
1394 /* Send WM_CUSTOMDRAW */
1396 HEADER_RefreshItem (hwnd, hdc, nItem);
1397 ReleaseDC (hwnd, hdc);
1399 TRACE("Pressed item %d!\n", nItem);
1401 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1402 if (!(HEADER_SendHeaderNotify (hwnd, HDN_BEGINTRACKA, nItem,0))) {
1404 infoPtr->bCaptured = TRUE;
1405 infoPtr->bTracking = TRUE;
1406 infoPtr->iMoveItem = nItem;
1407 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1408 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1410 if (!(dwStyle & HDS_FULLDRAG)) {
1411 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1413 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1414 ReleaseDC (hwnd, hdc);
1417 TRACE("Begin tracking item %d!\n", nItem);
1426 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1428 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1430 *DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1437 pt.x = (INT)(SHORT)LOWORD(lParam);
1438 pt.y = (INT)(SHORT)HIWORD(lParam);
1439 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1441 if (infoPtr->bPressed) {
1442 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1443 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1445 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1446 ReleaseDC (hwnd, hdc);
1448 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1450 else if (flags == HHT_ONHEADER)
1452 HEADER_ITEM *lpItem;
1453 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1454 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1456 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1457 infoPtr->iMoveItem,oldindex,nItem,newindex);
1458 lpItem= &infoPtr->items[nItem];
1459 lpItem->iOrder=oldindex;
1461 lpItem= &infoPtr->items[infoPtr->iMoveItem];
1462 lpItem->iOrder = newindex;
1464 infoPtr->bRectsValid = FALSE;
1465 InvalidateRect(hwnd, NULL, FALSE);
1466 /* FIXME: Should some WM_NOTIFY be sent */
1469 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1470 infoPtr->bPressed = FALSE;
1472 else if (infoPtr->bTracking) {
1473 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1474 infoPtr->bTracking = FALSE;
1476 HEADER_SendHeaderNotify (hwnd, HDN_ENDTRACKA, infoPtr->iMoveItem,HDI_WIDTH);
1479 * we want to do this even for HDS_FULLDRAG because this is where
1480 * we send the HDN_ITEMCHANGING and HDN_ITEMCHANGED notifications
1482 * if (!(dwStyle & HDS_FULLDRAG)) {
1486 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1487 ReleaseDC (hwnd, hdc);
1488 if (HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1490 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1493 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1496 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1499 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH);
1500 HEADER_SetItemBounds (hwnd);
1501 InvalidateRect(hwnd, NULL, FALSE);
1507 if (infoPtr->bCaptured) {
1508 infoPtr->bCaptured = FALSE;
1510 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1518 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1520 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1525 return infoPtr->nNotifyFormat;
1528 infoPtr->nNotifyFormat =
1529 SendMessageA ((HWND)wParam, WM_NOTIFYFORMAT,
1530 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1531 return infoPtr->nNotifyFormat;
1539 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1541 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1542 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1548 pt.x = (INT)(SHORT)LOWORD(lParam);
1549 pt.y = (INT)(SHORT)HIWORD(lParam);
1550 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1552 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1553 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1554 infoPtr->iHotItem = nItem;
1556 infoPtr->iHotItem = -1;
1557 InvalidateRect(hwnd, NULL, FALSE);
1560 if (infoPtr->bCaptured) {
1561 if (infoPtr->bPressed) {
1562 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1563 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1565 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1567 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1568 ReleaseDC (hwnd, hdc);
1570 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1572 else if (infoPtr->bTracking) {
1573 if (dwStyle & HDS_FULLDRAG) {
1574 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1576 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1579 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1580 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1582 HEADER_SetItemBounds (hwnd);
1583 InvalidateRect(hwnd, NULL, FALSE);
1587 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1588 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1589 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1590 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1591 infoPtr->items[infoPtr->iMoveItem].cxy =
1592 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1593 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1594 ReleaseDC (hwnd, hdc);
1595 HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH);
1598 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1602 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1603 FIXME("hot track support!\n");
1611 HEADER_Paint (HWND hwnd, WPARAM wParam)
1616 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1617 HEADER_Refresh (hwnd, hdc);
1619 EndPaint (hwnd, &ps);
1625 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1630 pt.x = LOWORD(lParam);
1631 pt.y = HIWORD(lParam);
1633 /* Send a Notify message */
1634 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1636 /* Change to screen coordinate for WM_CONTEXTMENU */
1637 ClientToScreen(hwnd, &pt);
1639 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1640 SendMessageA( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1647 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1649 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1654 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1657 ScreenToClient (hwnd, &pt);
1659 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1661 if (flags == HHT_ONDIVIDER)
1662 SetCursor (infoPtr->hcurDivider);
1663 else if (flags == HHT_ONDIVOPEN)
1664 SetCursor (infoPtr->hcurDivopen);
1666 SetCursor (infoPtr->hcurArrow);
1673 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1675 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1677 HFONT hFont, hOldFont;
1680 infoPtr->hFont = (HFONT)wParam;
1682 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1685 hOldFont = SelectObject (hdc, hFont);
1686 GetTextMetricsA (hdc, &tm);
1687 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1688 SelectObject (hdc, hOldFont);
1691 infoPtr->bRectsValid = FALSE;
1694 InvalidateRect(hwnd, NULL, FALSE);
1701 static LRESULT WINAPI
1702 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1704 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1705 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1706 return DefWindowProcA (hwnd, msg, wParam, lParam);
1708 /* case HDM_CLEARFILTER: */
1710 case HDM_CREATEDRAGIMAGE:
1711 return HEADER_CreateDragImage (hwnd, wParam);
1713 case HDM_DELETEITEM:
1714 return HEADER_DeleteItem (hwnd, wParam);
1716 /* case HDM_EDITFILTER: */
1718 case HDM_GETBITMAPMARGIN:
1719 return HEADER_GetBitmapMargin(hwnd);
1721 case HDM_GETIMAGELIST:
1722 return HEADER_GetImageList (hwnd);
1725 return HEADER_GetItemA (hwnd, wParam, lParam);
1728 return HEADER_GetItemW (hwnd, wParam, lParam);
1730 case HDM_GETITEMCOUNT:
1731 return HEADER_GetItemCount (hwnd);
1733 case HDM_GETITEMRECT:
1734 return HEADER_GetItemRect (hwnd, wParam, lParam);
1736 case HDM_GETORDERARRAY:
1737 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1739 case HDM_GETUNICODEFORMAT:
1740 return HEADER_GetUnicodeFormat (hwnd);
1743 return HEADER_HitTest (hwnd, wParam, lParam);
1745 case HDM_INSERTITEMA:
1746 return HEADER_InsertItemA (hwnd, wParam, lParam);
1748 case HDM_INSERTITEMW:
1749 return HEADER_InsertItemW (hwnd, wParam, lParam);
1752 return HEADER_Layout (hwnd, wParam, lParam);
1754 case HDM_ORDERTOINDEX:
1755 return HEADER_OrderToIndex(hwnd, wParam);
1757 case HDM_SETBITMAPMARGIN:
1758 return HEADER_SetBitmapMargin(hwnd, wParam);
1760 /* case HDM_SETFILTERCHANGETIMEOUT: */
1762 /* case HDM_SETHOTDIVIDER: */
1764 case HDM_SETIMAGELIST:
1765 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
1768 return HEADER_SetItemA (hwnd, wParam, lParam);
1771 return HEADER_SetItemW (hwnd, wParam, lParam);
1773 case HDM_SETORDERARRAY:
1774 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1776 case HDM_SETUNICODEFORMAT:
1777 return HEADER_SetUnicodeFormat (hwnd, wParam);
1780 return HEADER_Create (hwnd, wParam, lParam);
1783 return HEADER_Destroy (hwnd, wParam, lParam);
1789 return DLGC_WANTTAB | DLGC_WANTARROWS;
1792 return HEADER_GetFont (hwnd);
1794 case WM_LBUTTONDBLCLK:
1795 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1797 case WM_LBUTTONDOWN:
1798 return HEADER_LButtonDown (hwnd, wParam, lParam);
1801 return HEADER_LButtonUp (hwnd, wParam, lParam);
1804 return HEADER_MouseMove (hwnd, wParam, lParam);
1806 case WM_NOTIFYFORMAT:
1807 return HEADER_NotifyFormat (hwnd, wParam, lParam);
1810 return HEADER_Size (hwnd, wParam);
1813 return HEADER_Paint (hwnd, wParam);
1816 return HEADER_RButtonUp (hwnd, wParam, lParam);
1819 return HEADER_SetCursor (hwnd, wParam, lParam);
1822 return HEADER_SetFont (hwnd, wParam, lParam);
1825 if ((msg >= WM_USER) && (msg < WM_APP))
1826 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1827 msg, wParam, lParam );
1828 return DefWindowProcA (hwnd, msg, wParam, lParam);
1835 HEADER_Register (void)
1839 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1840 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1841 wndClass.lpfnWndProc = (WNDPROC)HEADER_WindowProc;
1842 wndClass.cbClsExtra = 0;
1843 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1844 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
1845 wndClass.lpszClassName = WC_HEADERA;
1847 RegisterClassA (&wndClass);
1852 HEADER_Unregister (void)
1854 UnregisterClassA (WC_HEADERA, NULL);