4 * Copyright 1998 Eric Kohl
5 * Copyright 2000 Eric Kohl for CodeWeavers
6 * Copyright 2003 Maxime Bellenge
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 * - Imagelist support (partially).
24 * - Callback items (under construction).
25 * - Hottrack support (partially).
26 * - Custom draw support (including Notifications).
27 * - Drag and Drop support (including Notifications).
29 * - Use notification format
30 * - Correct the order maintenance code to preserve valid order
39 #include "wine/unicode.h"
45 #include "imagelist.h"
46 #include "wine/debug.h"
48 WINE_DEFAULT_DEBUG_CHANNEL(header);
58 INT iOrder; /* see documentation of HD_ITEM */
60 BOOL bDown; /* is item pressed? (used for drawing) */
61 RECT rect; /* bounding rectangle of the item */
67 HWND hwndNotify; /* Owner window to send notifications to */
68 INT nNotifyFormat; /* format used for WM_NOTIFY messages */
69 UINT uNumItem; /* number of items (columns) */
70 INT nHeight; /* height of the header (pixels) */
71 HFONT hFont; /* handle to the current font */
72 HCURSOR hcurArrow; /* handle to the arrow cursor */
73 HCURSOR hcurDivider; /* handle to a cursor (used over dividers) <-|-> */
74 HCURSOR hcurDivopen; /* handle to a cursor (used over dividers) <-||-> */
75 BOOL bCaptured; /* Is the mouse captured? */
76 BOOL bPressed; /* Is a header item pressed (down)? */
77 BOOL bTracking; /* Is in tracking mode? */
78 BOOL bUnicode; /* Unicode flag */
79 INT iMoveItem; /* index of tracked item. (Tracking mode) */
80 INT xTrackOffset; /* distance between the right side of the tracked item and the cursor */
81 INT xOldTrack; /* track offset (see above) after the last WM_MOUSEMOVE */
82 INT nOldWidth; /* width of a sizing item after the last WM_MOUSEMOVE */
83 INT iHotItem; /* index of hot item (cursor is over this item) */
84 INT iMargin; /* width of the margin that surrounds a bitmap */
86 HIMAGELIST himl; /* handle to a image list (may be 0) */
87 HEADER_ITEM *items; /* pointer to array of HEADER_ITEM's */
88 BOOL bRectsValid; /* validity flag for bounding rectangles */
93 #define DIVIDER_WIDTH 10
95 #define HEADER_GetInfoPtr(hwnd) ((HEADER_INFO *)GetWindowLongPtrW(hwnd,0))
99 HEADER_IndexToOrder (HWND hwnd, INT iItem)
101 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
102 HEADER_ITEM *lpItem = &infoPtr->items[iItem];
103 return lpItem->iOrder;
108 HEADER_OrderToIndex(HWND hwnd, WPARAM wParam)
110 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
111 INT iorder = (INT)wParam;
114 if ((iorder <0) || iorder >infoPtr->uNumItem)
116 for (i=0; i<infoPtr->uNumItem; i++)
117 if (HEADER_IndexToOrder(hwnd,i) == iorder)
123 HEADER_SetItemBounds (HWND hwnd)
125 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
131 infoPtr->bRectsValid = TRUE;
133 if (infoPtr->uNumItem == 0)
136 GetClientRect (hwnd, &rect);
139 for (i = 0; i < infoPtr->uNumItem; i++) {
140 phdi = &infoPtr->items[HEADER_OrderToIndex(hwnd,i)];
141 phdi->rect.top = rect.top;
142 phdi->rect.bottom = rect.bottom;
144 phdi->rect.right = phdi->rect.left + ((phdi->cxy>0)?phdi->cxy:0);
145 x = phdi->rect.right;
150 HEADER_Size (HWND hwnd, WPARAM wParam)
152 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
154 infoPtr->bRectsValid = FALSE;
161 HEADER_DrawItem (HWND hwnd, HDC hdc, INT iItem, BOOL bHotTrack)
163 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
164 HEADER_ITEM *phdi = &infoPtr->items[iItem];
168 TRACE("DrawItem(iItem %d bHotTrack %d unicode flag %d)\n", iItem, bHotTrack, infoPtr->bUnicode);
170 if (!infoPtr->bRectsValid)
171 HEADER_SetItemBounds(hwnd);
174 if (r.right - r.left == 0)
175 return phdi->rect.right;
177 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) {
179 DrawEdge (hdc, &r, BDR_RAISEDOUTER,
180 BF_RECT | BF_FLAT | BF_MIDDLE | BF_ADJUST);
185 DrawEdge (hdc, &r, EDGE_RAISED,
186 BF_RECT | BF_SOFT | BF_MIDDLE | BF_ADJUST);
189 DrawEdge (hdc, &r, EDGE_ETCHED, BF_BOTTOM | BF_RIGHT | BF_ADJUST);
191 if (phdi->fmt & HDF_OWNERDRAW) {
193 dis.CtlType = ODT_HEADER;
194 dis.CtlID = GetWindowLongPtrW (hwnd, GWLP_ID);
196 dis.itemAction = ODA_DRAWENTIRE;
197 dis.itemState = phdi->bDown ? ODS_SELECTED : 0;
201 dis.itemData = phdi->lParam;
202 oldBkMode = SetBkMode(hdc, TRANSPARENT);
203 SendMessageA (infoPtr->hwndNotify, WM_DRAWITEM,
204 (WPARAM)dis.CtlID, (LPARAM)&dis);
205 if (oldBkMode != TRANSPARENT)
206 SetBkMode(hdc, oldBkMode);
209 UINT uTextJustify = DT_LEFT;
211 if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_CENTER)
212 uTextJustify = DT_CENTER;
213 else if ((phdi->fmt & HDF_JUSTIFYMASK) == HDF_RIGHT)
214 uTextJustify = DT_RIGHT;
216 if ((phdi->fmt & HDF_BITMAP) && !(phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
219 INT yD, yS, cx, cy, rx, ry;
221 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
223 ry = r.bottom - r.top;
224 rx = r.right - r.left;
226 if (ry >= bmp.bmHeight) {
228 yD = r.top + (ry - bmp.bmHeight) / 2;
234 yS = (bmp.bmHeight - ry) / 2;
238 if (rx >= bmp.bmWidth + infoPtr->iMargin) {
242 cx = rx - infoPtr->iMargin;
245 hdcBitmap = CreateCompatibleDC (hdc);
246 SelectObject (hdcBitmap, phdi->hbm);
247 BitBlt (hdc, r.left + infoPtr->iMargin, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
248 DeleteDC (hdcBitmap);
250 r.left += (bmp.bmWidth + infoPtr->iMargin);
254 if ((phdi->fmt & HDF_BITMAP) && (phdi->fmt & HDF_BITMAP_ON_RIGHT) && (phdi->hbm)) {
257 INT xD, yD, yS, cx, cy, rx, ry, tx;
260 GetObjectA (phdi->hbm, sizeof(BITMAP), (LPVOID)&bmp);
263 if (phdi->fmt & HDF_STRING) {
264 DrawTextW (hdc, phdi->pszText, -1,
265 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
266 tx = textRect.right - textRect.left;
270 ry = r.bottom - r.top;
271 rx = r.right - r.left;
273 if (ry >= bmp.bmHeight) {
275 yD = r.top + (ry - bmp.bmHeight) / 2;
281 yS = (bmp.bmHeight - ry) / 2;
285 if (r.left + tx + bmp.bmWidth + 2*infoPtr->iMargin <= r.right) {
287 xD = r.left + tx + infoPtr->iMargin;
290 if (rx >= bmp.bmWidth + infoPtr->iMargin ) {
292 xD = r.right - bmp.bmWidth - infoPtr->iMargin;
293 r.right = xD - infoPtr->iMargin;
296 cx = rx - infoPtr->iMargin;
302 hdcBitmap = CreateCompatibleDC (hdc);
303 SelectObject (hdcBitmap, phdi->hbm);
304 BitBlt (hdc, xD, yD, cx, cy, hdcBitmap, 0, yS, SRCCOPY);
305 DeleteDC (hdcBitmap);
308 if ((phdi->fmt & HDF_IMAGE) && !(phdi->fmt & HDF_BITMAP_ON_RIGHT) && (infoPtr->himl)) {
309 r.left += infoPtr->iMargin;
310 ImageList_DrawEx(infoPtr->himl, phdi->iImage, hdc, r.left, r.top + (r.bottom-r.top- infoPtr->himl->cy)/2,
311 infoPtr->himl->cx, r.bottom-r.top, CLR_DEFAULT, CLR_DEFAULT, 0);
312 r.left += infoPtr->himl->cx;
315 if ((phdi->fmt & HDF_IMAGE) && (phdi->fmt & HDF_BITMAP_ON_RIGHT) && (infoPtr->himl)) {
320 if (phdi->fmt & HDF_STRING) {
321 DrawTextW (hdc, phdi->pszText, -1,
322 &textRect, DT_LEFT|DT_VCENTER|DT_SINGLELINE|DT_CALCRECT);
323 tx = textRect.right - textRect.left;
327 ImageList_DrawEx(infoPtr->himl, phdi->iImage, hdc, r.left + tx + 2*infoPtr->iMargin,
328 r.top + (r.bottom-r.top-infoPtr->himl->cy)/2, infoPtr->himl->cx, r.bottom-r.top,
329 CLR_DEFAULT, CLR_DEFAULT, 0);
332 if (((phdi->fmt & HDF_STRING)
333 || (!(phdi->fmt & (HDF_OWNERDRAW|HDF_STRING|HDF_BITMAP|
334 HDF_BITMAP_ON_RIGHT|HDF_IMAGE)))) /* no explicit format specified? */
335 && (phdi->pszText)) {
336 oldBkMode = SetBkMode(hdc, TRANSPARENT);
337 r.left += infoPtr->iMargin;
338 r.right -= infoPtr->iMargin;
339 SetTextColor (hdc, (bHotTrack) ? COLOR_HIGHLIGHT : COLOR_BTNTEXT);
340 DrawTextW (hdc, phdi->pszText, -1,
341 &r, uTextJustify|DT_END_ELLIPSIS|DT_VCENTER|DT_SINGLELINE);
342 if (oldBkMode != TRANSPARENT)
343 SetBkMode(hdc, oldBkMode);
347 return phdi->rect.right;
352 HEADER_Refresh (HWND hwnd, HDC hdc)
354 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
355 HFONT hFont, hOldFont;
361 /* get rect for the bar, adjusted for the border */
362 GetClientRect (hwnd, &rect);
364 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
365 hOldFont = SelectObject (hdc, hFont);
367 /* draw Background */
368 hbrBk = GetSysColorBrush(COLOR_3DFACE);
369 FillRect(hdc, &rect, hbrBk);
372 for (i = 0; i < infoPtr->uNumItem; i++) {
373 x = HEADER_DrawItem (hwnd, hdc, HEADER_OrderToIndex(hwnd,i), FALSE);
376 if ((x <= rect.right) && (infoPtr->uNumItem > 0)) {
378 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS)
379 DrawEdge (hdc, &rect, EDGE_RAISED, BF_TOP|BF_LEFT|BF_BOTTOM|BF_SOFT);
381 DrawEdge (hdc, &rect, EDGE_ETCHED, BF_BOTTOM);
384 SelectObject (hdc, hOldFont);
389 HEADER_RefreshItem (HWND hwnd, HDC hdc, INT iItem)
391 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
392 HFONT hFont, hOldFont;
394 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
395 hOldFont = SelectObject (hdc, hFont);
396 HEADER_DrawItem (hwnd, hdc, iItem, FALSE);
397 SelectObject (hdc, hOldFont);
402 HEADER_InternalHitTest (HWND hwnd, LPPOINT lpPt, UINT *pFlags, INT *pItem)
404 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
410 GetClientRect (hwnd, &rect);
414 if (PtInRect (&rect, *lpPt))
416 if (infoPtr->uNumItem == 0) {
417 *pFlags |= HHT_NOWHERE;
423 /* somewhere inside */
424 for (iCount = 0; iCount < infoPtr->uNumItem; iCount++) {
425 rect = infoPtr->items[iCount].rect;
426 width = rect.right - rect.left;
431 if (PtInRect (&rect, *lpPt)) {
432 if (width <= 2 * DIVIDER_WIDTH) {
433 *pFlags |= HHT_ONHEADER;
435 TRACE("ON HEADER %d\n", iCount);
440 rcTest.right = rcTest.left + DIVIDER_WIDTH;
441 if (PtInRect (&rcTest, *lpPt)) {
443 *pFlags |= HHT_ONDIVOPEN;
445 TRACE("ON DIVOPEN %d\n", *pItem);
449 *pFlags |= HHT_ONDIVIDER;
451 TRACE("ON DIVIDER %d\n", *pItem);
457 rcTest.left = rcTest.right - DIVIDER_WIDTH;
458 if (PtInRect (&rcTest, *lpPt)) {
459 *pFlags |= HHT_ONDIVIDER;
461 TRACE("ON DIVIDER %d\n", *pItem);
465 *pFlags |= HHT_ONHEADER;
467 TRACE("ON HEADER %d\n", iCount);
472 /* check for last divider part (on nowhere) */
473 rect = infoPtr->items[infoPtr->uNumItem-1].rect;
474 rect.left = rect.right;
475 rect.right += DIVIDER_WIDTH;
476 if (PtInRect (&rect, *lpPt)) {
478 *pFlags |= HHT_ONDIVOPEN;
479 *pItem = infoPtr->uNumItem - 1;
480 TRACE("ON DIVOPEN %d\n", *pItem);
484 *pFlags |= HHT_ONDIVIDER;
485 *pItem = infoPtr->uNumItem-1;
486 TRACE("ON DIVIDER %d\n", *pItem);
491 *pFlags |= HHT_NOWHERE;
498 if (lpPt->x < rect.left) {
500 *pFlags |= HHT_TOLEFT;
502 else if (lpPt->x > rect.right) {
504 *pFlags |= HHT_TORIGHT;
507 if (lpPt->y < rect.top) {
509 *pFlags |= HHT_ABOVE;
511 else if (lpPt->y > rect.bottom) {
513 *pFlags |= HHT_BELOW;
518 TRACE("flags=0x%X\n", *pFlags);
524 HEADER_DrawTrackLine (HWND hwnd, HDC hdc, INT x)
530 GetClientRect (hwnd, &rect);
532 hOldPen = SelectObject (hdc, GetStockObject (BLACK_PEN));
533 oldRop = SetROP2 (hdc, R2_XORPEN);
534 MoveToEx (hdc, x, rect.top, NULL);
535 LineTo (hdc, x, rect.bottom);
536 SetROP2 (hdc, oldRop);
537 SelectObject (hdc, hOldPen);
542 HEADER_SendSimpleNotify (HWND hwnd, UINT code)
544 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
547 nmhdr.hwndFrom = hwnd;
548 nmhdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
551 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
552 (WPARAM)nmhdr.idFrom, (LPARAM)&nmhdr);
556 HEADER_SendHeaderNotify (HWND hwnd, UINT code, INT iItem, INT mask)
558 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
562 nmhdr.hdr.hwndFrom = hwnd;
563 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
564 nmhdr.hdr.code = code;
567 nmhdr.pitem = &nmitem;
569 nmitem.cxy = infoPtr->items[iItem].cxy;
570 nmitem.hbm = infoPtr->items[iItem].hbm;
571 nmitem.pszText = NULL;
572 nmitem.cchTextMax = 0;
573 /* nmitem.pszText = infoPtr->items[iItem].pszText; */
574 /* nmitem.cchTextMax = infoPtr->items[iItem].cchTextMax; */
575 nmitem.fmt = infoPtr->items[iItem].fmt;
576 nmitem.lParam = infoPtr->items[iItem].lParam;
577 nmitem.iOrder = infoPtr->items[iItem].iOrder;
578 nmitem.iImage = infoPtr->items[iItem].iImage;
580 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
581 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
586 HEADER_SendClickNotify (HWND hwnd, UINT code, INT iItem)
588 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
591 nmhdr.hdr.hwndFrom = hwnd;
592 nmhdr.hdr.idFrom = GetWindowLongPtrW (hwnd, GWLP_ID);
593 nmhdr.hdr.code = code;
598 return (BOOL)SendMessageA (infoPtr->hwndNotify, WM_NOTIFY,
599 (WPARAM)nmhdr.hdr.idFrom, (LPARAM)&nmhdr);
604 HEADER_CreateDragImage (HWND hwnd, WPARAM wParam)
606 FIXME("empty stub!\n");
612 HEADER_DeleteItem (HWND hwnd, WPARAM wParam)
614 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
615 INT iItem = (INT)wParam;
617 TRACE("[iItem=%d]\n", iItem);
619 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
622 if (infoPtr->uNumItem == 1) {
623 TRACE("Simple delete!\n");
624 if (infoPtr->items[0].pszText)
625 Free (infoPtr->items[0].pszText);
626 Free (infoPtr->items);
628 infoPtr->uNumItem = 0;
631 HEADER_ITEM *oldItems = infoPtr->items;
635 TRACE("Complex delete! [iItem=%d]\n", iItem);
637 if (infoPtr->items[iItem].pszText)
638 Free (infoPtr->items[iItem].pszText);
639 iOrder = infoPtr->items[iItem].iOrder;
642 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
643 /* pre delete copy */
645 memcpy (&infoPtr->items[0], &oldItems[0],
646 iItem * sizeof(HEADER_ITEM));
649 /* post delete copy */
650 if (iItem < infoPtr->uNumItem) {
651 memcpy (&infoPtr->items[iItem], &oldItems[iItem+1],
652 (infoPtr->uNumItem - iItem) * sizeof(HEADER_ITEM));
655 /* Correct the orders */
656 for (i=infoPtr->uNumItem, pItem = infoPtr->items; i; i--, pItem++)
658 if (pItem->iOrder > iOrder)
664 HEADER_SetItemBounds (hwnd);
666 InvalidateRect(hwnd, NULL, FALSE);
673 HEADER_GetImageList (HWND hwnd)
675 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
677 return (LRESULT)infoPtr->himl;
682 HEADER_GetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
684 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
685 HDITEMA *phdi = (HDITEMA*)lParam;
686 INT nItem = (INT)wParam;
692 TRACE("[nItem=%d]\n", nItem);
697 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem)) {
701 lpItem = &infoPtr->items[nItem];
704 if (phdi->mask & HDI_BITMAP)
705 phdi->hbm = (lpItem != NULL) ? lpItem->hbm : 0;
707 if (phdi->mask & HDI_FORMAT)
708 phdi->fmt = (lpItem != NULL) ? lpItem->fmt : 0;
710 if (phdi->mask & HDI_WIDTH)
711 phdi->cxy = (lpItem != NULL) ? lpItem->cxy : 0;
713 if (phdi->mask & HDI_LPARAM)
714 phdi->lParam = (lpItem != NULL) ? lpItem->lParam : 0;
716 if (phdi->mask & HDI_TEXT) {
717 if (lpItem == NULL) {
720 else if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
722 WideCharToMultiByte (CP_ACP, 0, lpItem->pszText, -1,
723 phdi->pszText, phdi->cchTextMax, NULL, NULL);
728 phdi->pszText = LPSTR_TEXTCALLBACKA;
731 if (phdi->mask & HDI_IMAGE)
732 phdi->iImage = (lpItem != NULL) ? lpItem->iImage : 0;
734 if (phdi->mask & HDI_ORDER)
735 phdi->iOrder = (lpItem != NULL) ? lpItem->iOrder : 0;
742 HEADER_GetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
744 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
745 HDITEMW *phdi = (HDITEMW*)lParam;
746 INT nItem = (INT)wParam;
752 TRACE("[nItem=%d]\n", nItem);
757 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem)) {
761 lpItem = &infoPtr->items[nItem];
764 if (phdi->mask & HDI_BITMAP)
765 phdi->hbm = (lpItem != NULL) ? lpItem->hbm : 0;
767 if (phdi->mask & HDI_FORMAT)
768 phdi->fmt = (lpItem != NULL) ? lpItem->fmt : 0;
770 if (phdi->mask & HDI_WIDTH)
771 phdi->cxy = (lpItem != NULL) ? lpItem->cxy : 0;
773 if (phdi->mask & HDI_LPARAM)
774 phdi->lParam = (lpItem != NULL) ? lpItem->lParam : 0;
776 if (phdi->mask & HDI_TEXT) {
777 if (lpItem == NULL) {
780 else if (lpItem->pszText != LPSTR_TEXTCALLBACKW) {
782 lstrcpynW (phdi->pszText, lpItem->pszText, phdi->cchTextMax);
787 phdi->pszText = LPSTR_TEXTCALLBACKW;
790 if (phdi->mask & HDI_IMAGE)
791 phdi->iImage = (lpItem != NULL) ? lpItem->iImage : 0;
793 if (phdi->mask & HDI_ORDER)
794 phdi->iOrder = (lpItem != NULL) ? lpItem->iOrder : 0;
800 inline static LRESULT
801 HEADER_GetItemCount (HWND hwnd)
803 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
804 return infoPtr->uNumItem;
809 HEADER_GetItemRect (HWND hwnd, WPARAM wParam, LPARAM lParam)
811 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
812 INT iItem = (INT)wParam;
813 LPRECT lpRect = (LPRECT)lParam;
815 if ((iItem < 0) || (iItem >= (INT)infoPtr->uNumItem))
818 lpRect->left = infoPtr->items[iItem].rect.left;
819 lpRect->right = infoPtr->items[iItem].rect.right;
820 lpRect->top = infoPtr->items[iItem].rect.top;
821 lpRect->bottom = infoPtr->items[iItem].rect.bottom;
828 HEADER_GetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
831 LPINT order = (LPINT) lParam;
832 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
834 if ((unsigned int)wParam <infoPtr->uNumItem)
836 for (i=0; i<(int)wParam; i++)
837 *order++=HEADER_OrderToIndex(hwnd,i);
842 HEADER_SetOrderArray(HWND hwnd, WPARAM wParam, LPARAM lParam)
845 LPINT order = (LPINT) lParam;
846 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
849 if ((unsigned int)wParam <infoPtr->uNumItem)
851 for (i=0; i<(int)wParam; i++)
853 lpItem = &infoPtr->items[*order++];
856 infoPtr->bRectsValid=0;
857 InvalidateRect(hwnd, NULL, FALSE);
861 inline static LRESULT
862 HEADER_GetUnicodeFormat (HWND hwnd)
864 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
865 return infoPtr->bUnicode;
870 HEADER_HitTest (HWND hwnd, WPARAM wParam, LPARAM lParam)
872 LPHDHITTESTINFO phti = (LPHDHITTESTINFO)lParam;
874 HEADER_InternalHitTest (hwnd, &phti->pt, &phti->flags, &phti->iItem);
876 if (phti->flags == HHT_NOWHERE)
884 HEADER_InsertItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
886 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
887 HDITEMA *phdi = (HDITEMA*)lParam;
888 INT nItem = (INT)wParam;
893 if ((phdi == NULL) || (nItem < 0))
896 if (nItem > infoPtr->uNumItem)
897 nItem = infoPtr->uNumItem;
899 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
901 if (infoPtr->uNumItem == 0) {
902 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
906 HEADER_ITEM *oldItems = infoPtr->items;
909 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
911 memcpy (&infoPtr->items[1], &oldItems[0],
912 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
916 /* pre insert copy */
918 memcpy (&infoPtr->items[0], &oldItems[0],
919 nItem * sizeof(HEADER_ITEM));
922 /* post insert copy */
923 if (nItem < infoPtr->uNumItem - 1) {
924 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
925 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
932 for (i=0; i < infoPtr->uNumItem; i++)
934 if (infoPtr->items[i].iOrder >= iOrder)
935 infoPtr->items[i].iOrder++;
938 lpItem = &infoPtr->items[nItem];
939 lpItem->bDown = FALSE;
941 if (phdi->mask & HDI_WIDTH)
942 lpItem->cxy = phdi->cxy;
944 if (phdi->mask & HDI_TEXT) {
945 if (!phdi->pszText) /* null pointer check */
947 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
948 len = MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, NULL, 0);
949 lpItem->pszText = Alloc( len*sizeof(WCHAR) );
950 MultiByteToWideChar(CP_ACP, 0, phdi->pszText, -1, lpItem->pszText, len);
953 lpItem->pszText = LPSTR_TEXTCALLBACKW;
956 if (phdi->mask & HDI_FORMAT)
957 lpItem->fmt = phdi->fmt;
959 if (lpItem->fmt == 0)
960 lpItem->fmt = HDF_LEFT;
962 if (!(lpItem->fmt & HDF_STRING) && (phdi->mask & HDI_TEXT))
964 lpItem->fmt |= HDF_STRING;
966 if (phdi->mask & HDI_BITMAP)
967 lpItem->hbm = phdi->hbm;
969 if (phdi->mask & HDI_LPARAM)
970 lpItem->lParam = phdi->lParam;
972 if (phdi->mask & HDI_IMAGE)
973 lpItem->iImage = phdi->iImage;
975 lpItem->iOrder = iOrder;
977 HEADER_SetItemBounds (hwnd);
979 InvalidateRect(hwnd, NULL, FALSE);
986 HEADER_InsertItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
988 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
989 HDITEMW *phdi = (HDITEMW*)lParam;
990 INT nItem = (INT)wParam;
995 if ((phdi == NULL) || (nItem < 0))
998 if (nItem > infoPtr->uNumItem)
999 nItem = infoPtr->uNumItem;
1001 iOrder = (phdi->mask & HDI_ORDER) ? phdi->iOrder : nItem;
1003 if (infoPtr->uNumItem == 0) {
1004 infoPtr->items = Alloc (sizeof (HEADER_ITEM));
1005 infoPtr->uNumItem++;
1008 HEADER_ITEM *oldItems = infoPtr->items;
1010 infoPtr->uNumItem++;
1011 infoPtr->items = Alloc (sizeof (HEADER_ITEM) * infoPtr->uNumItem);
1013 memcpy (&infoPtr->items[1], &oldItems[0],
1014 (infoPtr->uNumItem-1) * sizeof(HEADER_ITEM));
1018 /* pre insert copy */
1020 memcpy (&infoPtr->items[0], &oldItems[0],
1021 nItem * sizeof(HEADER_ITEM));
1024 /* post insert copy */
1025 if (nItem < infoPtr->uNumItem - 1) {
1026 memcpy (&infoPtr->items[nItem+1], &oldItems[nItem],
1027 (infoPtr->uNumItem - nItem - 1) * sizeof(HEADER_ITEM));
1034 for (i=0; i < infoPtr->uNumItem; i++)
1036 if (infoPtr->items[i].iOrder >= iOrder)
1037 infoPtr->items[i].iOrder++;
1040 lpItem = &infoPtr->items[nItem];
1041 lpItem->bDown = FALSE;
1043 if (phdi->mask & HDI_WIDTH)
1044 lpItem->cxy = phdi->cxy;
1046 if (phdi->mask & HDI_TEXT) {
1047 WCHAR wide_null_char = 0;
1048 if (!phdi->pszText) /* null pointer check */
1049 phdi->pszText = &wide_null_char;
1050 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1051 len = strlenW (phdi->pszText);
1052 lpItem->pszText = Alloc ((len+1)*sizeof(WCHAR));
1053 strcpyW (lpItem->pszText, phdi->pszText);
1056 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1059 if (phdi->mask & HDI_FORMAT)
1060 lpItem->fmt = phdi->fmt;
1062 if (lpItem->fmt == 0)
1063 lpItem->fmt = HDF_LEFT;
1065 if (!(lpItem->fmt &HDF_STRING) && (phdi->mask & HDI_TEXT))
1067 lpItem->fmt |= HDF_STRING;
1069 if (phdi->mask & HDI_BITMAP)
1070 lpItem->hbm = phdi->hbm;
1072 if (phdi->mask & HDI_LPARAM)
1073 lpItem->lParam = phdi->lParam;
1075 if (phdi->mask & HDI_IMAGE)
1076 lpItem->iImage = phdi->iImage;
1078 lpItem->iOrder = iOrder;
1080 HEADER_SetItemBounds (hwnd);
1082 InvalidateRect(hwnd, NULL, FALSE);
1089 HEADER_Layout (HWND hwnd, WPARAM wParam, LPARAM lParam)
1091 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1092 LPHDLAYOUT lpLayout = (LPHDLAYOUT)lParam;
1094 lpLayout->pwpos->hwnd = hwnd;
1095 lpLayout->pwpos->hwndInsertAfter = 0;
1096 lpLayout->pwpos->x = lpLayout->prc->left;
1097 lpLayout->pwpos->y = lpLayout->prc->top;
1098 lpLayout->pwpos->cx = lpLayout->prc->right - lpLayout->prc->left;
1099 if (GetWindowLongA (hwnd, GWL_STYLE) & HDS_HIDDEN)
1100 lpLayout->pwpos->cy = 0;
1102 lpLayout->pwpos->cy = infoPtr->nHeight;
1103 lpLayout->prc->top += infoPtr->nHeight;
1105 lpLayout->pwpos->flags = SWP_NOZORDER;
1107 TRACE("Layout x=%d y=%d cx=%d cy=%d\n",
1108 lpLayout->pwpos->x, lpLayout->pwpos->y,
1109 lpLayout->pwpos->cx, lpLayout->pwpos->cy);
1111 infoPtr->bRectsValid = FALSE;
1118 HEADER_SetImageList (HWND hwnd, HIMAGELIST himl)
1120 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1123 TRACE("(himl 0x%x)\n", (int)himl);
1124 himlOld = infoPtr->himl;
1125 infoPtr->himl = himl;
1127 /* FIXME: Refresh needed??? */
1129 return (LRESULT)himlOld;
1134 HEADER_GetBitmapMargin(HWND hwnd)
1136 HEADER_INFO *infoPtr = HEADER_GetInfoPtr(hwnd);
1138 return infoPtr->iMargin;
1142 HEADER_SetBitmapMargin(HWND hwnd, WPARAM wParam)
1144 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1145 INT oldMargin = infoPtr->iMargin;
1147 infoPtr->iMargin = (INT)wParam;
1153 HEADER_SetItemA (HWND hwnd, WPARAM wParam, LPARAM lParam)
1155 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1156 HDITEMA *phdi = (HDITEMA*)lParam;
1157 INT nItem = (INT)wParam;
1158 HEADER_ITEM *lpItem;
1162 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1165 TRACE("[nItem=%d]\n", nItem);
1167 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGA, nItem, phdi->mask))
1170 lpItem = &infoPtr->items[nItem];
1171 if (phdi->mask & HDI_BITMAP)
1172 lpItem->hbm = phdi->hbm;
1174 if (phdi->mask & HDI_FORMAT)
1175 lpItem->fmt = phdi->fmt;
1177 if (phdi->mask & HDI_LPARAM)
1178 lpItem->lParam = phdi->lParam;
1180 if (phdi->mask & HDI_TEXT) {
1181 if (phdi->pszText != LPSTR_TEXTCALLBACKA) {
1182 if (lpItem->pszText) {
1183 Free (lpItem->pszText);
1184 lpItem->pszText = NULL;
1186 if (phdi->pszText) {
1187 INT len = MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,NULL,0);
1188 lpItem->pszText = Alloc( len*sizeof(WCHAR) );
1189 MultiByteToWideChar (CP_ACP,0,phdi->pszText,-1,lpItem->pszText,len);
1193 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1196 if (phdi->mask & HDI_WIDTH)
1197 lpItem->cxy = phdi->cxy;
1199 if (phdi->mask & HDI_IMAGE)
1200 lpItem->iImage = phdi->iImage;
1202 if (phdi->mask & HDI_ORDER)
1204 lpItem->iOrder = phdi->iOrder;
1207 lpItem->iOrder = nItem;
1209 HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGEDA, nItem, phdi->mask);
1211 HEADER_SetItemBounds (hwnd);
1213 InvalidateRect(hwnd, NULL, FALSE);
1220 HEADER_SetItemW (HWND hwnd, WPARAM wParam, LPARAM lParam)
1222 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1223 HDITEMW *phdi = (HDITEMW*)lParam;
1224 INT nItem = (INT)wParam;
1225 HEADER_ITEM *lpItem;
1229 if ((nItem < 0) || (nItem >= (INT)infoPtr->uNumItem))
1232 TRACE("[nItem=%d]\n", nItem);
1234 if (HEADER_SendHeaderNotify (hwnd, HDN_ITEMCHANGINGW, nItem, phdi->mask))
1237 lpItem = &infoPtr->items[nItem];
1238 if (phdi->mask & HDI_BITMAP)
1239 lpItem->hbm = phdi->hbm;
1241 if (phdi->mask & HDI_FORMAT)
1242 lpItem->fmt = phdi->fmt;
1244 if (phdi->mask & HDI_LPARAM)
1245 lpItem->lParam = phdi->lParam;
1247 if (phdi->mask & HDI_TEXT) {
1248 if (phdi->pszText != LPSTR_TEXTCALLBACKW) {
1249 if (lpItem->pszText) {
1250 Free (lpItem->pszText);
1251 lpItem->pszText = NULL;
1253 if (phdi->pszText) {
1254 INT len = strlenW (phdi->pszText);
1255 lpItem->pszText = Alloc ((len+1)*sizeof(WCHAR));
1256 strcpyW (lpItem->pszText, phdi->pszText);
1260 lpItem->pszText = LPSTR_TEXTCALLBACKW;
1263 if (phdi->mask & HDI_WIDTH)
1264 lpItem->cxy = phdi->cxy;
1266 if (phdi->mask & HDI_IMAGE)
1267 lpItem->iImage = phdi->iImage;
1269 if (phdi->mask & HDI_ORDER)
1271 lpItem->iOrder = phdi->iOrder;
1274 lpItem->iOrder = nItem;
1276 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDW, nItem, phdi->mask);
1278 HEADER_SetItemBounds (hwnd);
1280 InvalidateRect(hwnd, NULL, FALSE);
1285 inline static LRESULT
1286 HEADER_SetUnicodeFormat (HWND hwnd, WPARAM wParam)
1288 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1289 BOOL bTemp = infoPtr->bUnicode;
1291 infoPtr->bUnicode = (BOOL)wParam;
1298 HEADER_Create (HWND hwnd, WPARAM wParam, LPARAM lParam)
1300 HEADER_INFO *infoPtr;
1305 infoPtr = (HEADER_INFO *)Alloc (sizeof(HEADER_INFO));
1306 SetWindowLongPtrA (hwnd, 0, (DWORD_PTR)infoPtr);
1308 infoPtr->hwndNotify = ((LPCREATESTRUCTA)lParam)->hwndParent;
1309 infoPtr->uNumItem = 0;
1312 infoPtr->bRectsValid = FALSE;
1313 infoPtr->hcurArrow = LoadCursorA (0, (LPSTR)IDC_ARROW);
1314 infoPtr->hcurDivider = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDER));
1315 infoPtr->hcurDivopen = LoadCursorA (COMCTL32_hModule, MAKEINTRESOURCEA(IDC_DIVIDEROPEN));
1316 infoPtr->bPressed = FALSE;
1317 infoPtr->bTracking = FALSE;
1318 infoPtr->iMoveItem = 0;
1320 infoPtr->iHotItem = -1;
1321 infoPtr->bUnicode = IsWindowUnicode (hwnd);
1322 infoPtr->iMargin = 3*GetSystemMetrics(SM_CXEDGE);
1323 infoPtr->nNotifyFormat =
1324 SendMessageA (infoPtr->hwndNotify, WM_NOTIFYFORMAT, (WPARAM)hwnd, NF_QUERY);
1327 hOldFont = SelectObject (hdc, GetStockObject (SYSTEM_FONT));
1328 GetTextMetricsA (hdc, &tm);
1329 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1330 SelectObject (hdc, hOldFont);
1338 HEADER_Destroy (HWND hwnd, WPARAM wParam, LPARAM lParam)
1340 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1341 HEADER_ITEM *lpItem;
1344 if (infoPtr->items) {
1345 lpItem = infoPtr->items;
1346 for (nItem = 0; nItem < infoPtr->uNumItem; nItem++, lpItem++) {
1347 if ((lpItem->pszText) && (lpItem->pszText != LPSTR_TEXTCALLBACKW))
1348 Free (lpItem->pszText);
1350 Free (infoPtr->items);
1354 ImageList_Destroy (infoPtr->himl);
1357 SetWindowLongPtrA (hwnd, 0, 0);
1362 static inline LRESULT
1363 HEADER_GetFont (HWND hwnd)
1365 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1367 return (LRESULT)infoPtr->hFont;
1372 HEADER_LButtonDblClk (HWND hwnd, WPARAM wParam, LPARAM lParam)
1378 pt.x = (INT)LOWORD(lParam);
1379 pt.y = (INT)HIWORD(lParam);
1380 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1382 if ((GetWindowLongA (hwnd, GWL_STYLE) & HDS_BUTTONS) && (flags == HHT_ONHEADER))
1383 HEADER_SendHeaderNotify (hwnd, HDN_ITEMDBLCLICKA, nItem,0);
1384 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN))
1385 HEADER_SendHeaderNotify (hwnd, HDN_DIVIDERDBLCLICKA, nItem,0);
1392 HEADER_LButtonDown (HWND hwnd, WPARAM wParam, LPARAM lParam)
1394 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1395 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1401 pt.x = (INT)LOWORD(lParam);
1402 pt.y = (INT)HIWORD(lParam);
1403 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1405 if ((dwStyle & HDS_BUTTONS) && (flags == HHT_ONHEADER)) {
1407 infoPtr->bCaptured = TRUE;
1408 infoPtr->bPressed = TRUE;
1409 infoPtr->iMoveItem = nItem;
1411 infoPtr->items[nItem].bDown = TRUE;
1413 /* Send WM_CUSTOMDRAW */
1415 HEADER_RefreshItem (hwnd, hdc, nItem);
1416 ReleaseDC (hwnd, hdc);
1418 TRACE("Pressed item %d!\n", nItem);
1420 else if ((flags == HHT_ONDIVIDER) || (flags == HHT_ONDIVOPEN)) {
1421 if (!(HEADER_SendHeaderNotify (hwnd, HDN_BEGINTRACKA, nItem,0))) {
1423 infoPtr->bCaptured = TRUE;
1424 infoPtr->bTracking = TRUE;
1425 infoPtr->iMoveItem = nItem;
1426 infoPtr->nOldWidth = infoPtr->items[nItem].cxy;
1427 infoPtr->xTrackOffset = infoPtr->items[nItem].rect.right - pt.x;
1429 if (!(dwStyle & HDS_FULLDRAG)) {
1430 infoPtr->xOldTrack = infoPtr->items[nItem].rect.right;
1432 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1433 ReleaseDC (hwnd, hdc);
1436 TRACE("Begin tracking item %d!\n", nItem);
1445 HEADER_LButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1447 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1449 *DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1456 pt.x = (INT)(SHORT)LOWORD(lParam);
1457 pt.y = (INT)(SHORT)HIWORD(lParam);
1458 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1460 if (infoPtr->bPressed) {
1461 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER)) {
1462 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1464 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1465 ReleaseDC (hwnd, hdc);
1467 HEADER_SendClickNotify (hwnd, HDN_ITEMCLICKA, infoPtr->iMoveItem);
1469 else if (flags == HHT_ONHEADER)
1471 HEADER_ITEM *lpItem;
1472 INT newindex = HEADER_IndexToOrder(hwnd,nItem);
1473 INT oldindex = HEADER_IndexToOrder(hwnd,infoPtr->iMoveItem);
1475 TRACE("Exchanging [index:order] [%d:%d] [%d:%d]\n",
1476 infoPtr->iMoveItem,oldindex,nItem,newindex);
1477 lpItem= &infoPtr->items[nItem];
1478 lpItem->iOrder=oldindex;
1480 lpItem= &infoPtr->items[infoPtr->iMoveItem];
1481 lpItem->iOrder = newindex;
1483 infoPtr->bRectsValid = FALSE;
1484 InvalidateRect(hwnd, NULL, FALSE);
1485 /* FIXME: Should some WM_NOTIFY be sent */
1488 TRACE("Released item %d!\n", infoPtr->iMoveItem);
1489 infoPtr->bPressed = FALSE;
1491 else if (infoPtr->bTracking) {
1492 TRACE("End tracking item %d!\n", infoPtr->iMoveItem);
1493 infoPtr->bTracking = FALSE;
1495 HEADER_SendHeaderNotify (hwnd, HDN_ENDTRACKA, infoPtr->iMoveItem,HDI_WIDTH);
1498 * we want to do this even for HDS_FULLDRAG because this is where
1499 * we send the HDN_ITEMCHANGING and HDN_ITEMCHANGED notifications
1501 * if (!(dwStyle & HDS_FULLDRAG)) {
1505 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1506 ReleaseDC (hwnd, hdc);
1507 if (HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGINGA, infoPtr->iMoveItem, HDI_WIDTH))
1509 infoPtr->items[infoPtr->iMoveItem].cxy = infoPtr->nOldWidth;
1512 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1515 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1518 HEADER_SetItemBounds (hwnd);
1519 InvalidateRect(hwnd, NULL, TRUE);
1520 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1526 if (infoPtr->bCaptured) {
1527 infoPtr->bCaptured = FALSE;
1529 HEADER_SendSimpleNotify (hwnd, NM_RELEASEDCAPTURE);
1537 HEADER_NotifyFormat (HWND hwnd, WPARAM wParam, LPARAM lParam)
1539 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1544 return infoPtr->nNotifyFormat;
1547 infoPtr->nNotifyFormat =
1548 SendMessageA ((HWND)wParam, WM_NOTIFYFORMAT,
1549 (WPARAM)hwnd, (LPARAM)NF_QUERY);
1550 return infoPtr->nNotifyFormat;
1558 HEADER_MouseMove (HWND hwnd, WPARAM wParam, LPARAM lParam)
1560 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1561 DWORD dwStyle = GetWindowLongA (hwnd, GWL_STYLE);
1567 pt.x = (INT)(SHORT)LOWORD(lParam);
1568 pt.y = (INT)(SHORT)HIWORD(lParam);
1569 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1571 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1572 if (flags & (HHT_ONHEADER | HHT_ONDIVIDER | HHT_ONDIVOPEN))
1573 infoPtr->iHotItem = nItem;
1575 infoPtr->iHotItem = -1;
1576 InvalidateRect(hwnd, NULL, FALSE);
1579 if (infoPtr->bCaptured) {
1580 if (infoPtr->bPressed) {
1581 if ((nItem == infoPtr->iMoveItem) && (flags == HHT_ONHEADER))
1582 infoPtr->items[infoPtr->iMoveItem].bDown = TRUE;
1584 infoPtr->items[infoPtr->iMoveItem].bDown = FALSE;
1586 HEADER_RefreshItem (hwnd, hdc, infoPtr->iMoveItem);
1587 ReleaseDC (hwnd, hdc);
1589 TRACE("Moving pressed item %d!\n", infoPtr->iMoveItem);
1591 else if (infoPtr->bTracking) {
1592 if (dwStyle & HDS_FULLDRAG) {
1593 if (HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH))
1595 nWidth = pt.x - infoPtr->items[infoPtr->iMoveItem].rect.left + infoPtr->xTrackOffset;
1598 infoPtr->items[infoPtr->iMoveItem].cxy = nWidth;
1599 HEADER_SendHeaderNotify(hwnd, HDN_ITEMCHANGEDA, infoPtr->iMoveItem, HDI_WIDTH);
1601 HEADER_SetItemBounds (hwnd);
1605 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1606 infoPtr->xOldTrack = pt.x + infoPtr->xTrackOffset;
1607 if (infoPtr->xOldTrack < infoPtr->items[infoPtr->iMoveItem].rect.left)
1608 infoPtr->xOldTrack = infoPtr->items[infoPtr->iMoveItem].rect.left;
1609 infoPtr->items[infoPtr->iMoveItem].cxy =
1610 infoPtr->xOldTrack - infoPtr->items[infoPtr->iMoveItem].rect.left;
1611 HEADER_DrawTrackLine (hwnd, hdc, infoPtr->xOldTrack);
1612 ReleaseDC (hwnd, hdc);
1613 HEADER_SendHeaderNotify (hwnd, HDN_TRACKA, infoPtr->iMoveItem, HDI_WIDTH);
1616 TRACE("Tracking item %d!\n", infoPtr->iMoveItem);
1620 if ((dwStyle & HDS_BUTTONS) && (dwStyle & HDS_HOTTRACK)) {
1621 FIXME("hot track support!\n");
1629 HEADER_Paint (HWND hwnd, WPARAM wParam)
1634 hdc = wParam==0 ? BeginPaint (hwnd, &ps) : (HDC)wParam;
1635 HEADER_Refresh (hwnd, hdc);
1637 EndPaint (hwnd, &ps);
1643 HEADER_RButtonUp (HWND hwnd, WPARAM wParam, LPARAM lParam)
1648 pt.x = LOWORD(lParam);
1649 pt.y = HIWORD(lParam);
1651 /* Send a Notify message */
1652 bRet = HEADER_SendSimpleNotify (hwnd, NM_RCLICK);
1654 /* Change to screen coordinate for WM_CONTEXTMENU */
1655 ClientToScreen(hwnd, &pt);
1657 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
1658 SendMessageA( hwnd, WM_CONTEXTMENU, (WPARAM) hwnd, MAKELPARAM(pt.x, pt.y));
1665 HEADER_SetCursor (HWND hwnd, WPARAM wParam, LPARAM lParam)
1667 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1672 TRACE("code=0x%X id=0x%X\n", LOWORD(lParam), HIWORD(lParam));
1675 ScreenToClient (hwnd, &pt);
1677 HEADER_InternalHitTest (hwnd, &pt, &flags, &nItem);
1679 if (flags == HHT_ONDIVIDER)
1680 SetCursor (infoPtr->hcurDivider);
1681 else if (flags == HHT_ONDIVOPEN)
1682 SetCursor (infoPtr->hcurDivopen);
1684 SetCursor (infoPtr->hcurArrow);
1691 HEADER_SetFont (HWND hwnd, WPARAM wParam, LPARAM lParam)
1693 HEADER_INFO *infoPtr = HEADER_GetInfoPtr (hwnd);
1695 HFONT hFont, hOldFont;
1698 infoPtr->hFont = (HFONT)wParam;
1700 hFont = infoPtr->hFont ? infoPtr->hFont : GetStockObject (SYSTEM_FONT);
1703 hOldFont = SelectObject (hdc, hFont);
1704 GetTextMetricsA (hdc, &tm);
1705 infoPtr->nHeight = tm.tmHeight + VERT_BORDER;
1706 SelectObject (hdc, hOldFont);
1709 infoPtr->bRectsValid = FALSE;
1712 InvalidateRect(hwnd, NULL, FALSE);
1719 static LRESULT WINAPI
1720 HEADER_WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
1722 TRACE("hwnd=%p msg=%x wparam=%x lParam=%lx\n", hwnd, msg, wParam, lParam);
1723 if (!HEADER_GetInfoPtr (hwnd) && (msg != WM_CREATE))
1724 return DefWindowProcA (hwnd, msg, wParam, lParam);
1726 /* case HDM_CLEARFILTER: */
1728 case HDM_CREATEDRAGIMAGE:
1729 return HEADER_CreateDragImage (hwnd, wParam);
1731 case HDM_DELETEITEM:
1732 return HEADER_DeleteItem (hwnd, wParam);
1734 /* case HDM_EDITFILTER: */
1736 case HDM_GETBITMAPMARGIN:
1737 return HEADER_GetBitmapMargin(hwnd);
1739 case HDM_GETIMAGELIST:
1740 return HEADER_GetImageList (hwnd);
1743 return HEADER_GetItemA (hwnd, wParam, lParam);
1746 return HEADER_GetItemW (hwnd, wParam, lParam);
1748 case HDM_GETITEMCOUNT:
1749 return HEADER_GetItemCount (hwnd);
1751 case HDM_GETITEMRECT:
1752 return HEADER_GetItemRect (hwnd, wParam, lParam);
1754 case HDM_GETORDERARRAY:
1755 return HEADER_GetOrderArray(hwnd, wParam, lParam);
1757 case HDM_GETUNICODEFORMAT:
1758 return HEADER_GetUnicodeFormat (hwnd);
1761 return HEADER_HitTest (hwnd, wParam, lParam);
1763 case HDM_INSERTITEMA:
1764 return HEADER_InsertItemA (hwnd, wParam, lParam);
1766 case HDM_INSERTITEMW:
1767 return HEADER_InsertItemW (hwnd, wParam, lParam);
1770 return HEADER_Layout (hwnd, wParam, lParam);
1772 case HDM_ORDERTOINDEX:
1773 return HEADER_OrderToIndex(hwnd, wParam);
1775 case HDM_SETBITMAPMARGIN:
1776 return HEADER_SetBitmapMargin(hwnd, wParam);
1778 /* case HDM_SETFILTERCHANGETIMEOUT: */
1780 /* case HDM_SETHOTDIVIDER: */
1782 case HDM_SETIMAGELIST:
1783 return HEADER_SetImageList (hwnd, (HIMAGELIST)lParam);
1786 return HEADER_SetItemA (hwnd, wParam, lParam);
1789 return HEADER_SetItemW (hwnd, wParam, lParam);
1791 case HDM_SETORDERARRAY:
1792 return HEADER_SetOrderArray(hwnd, wParam, lParam);
1794 case HDM_SETUNICODEFORMAT:
1795 return HEADER_SetUnicodeFormat (hwnd, wParam);
1798 return HEADER_Create (hwnd, wParam, lParam);
1801 return HEADER_Destroy (hwnd, wParam, lParam);
1807 return DLGC_WANTTAB | DLGC_WANTARROWS;
1810 return HEADER_GetFont (hwnd);
1812 case WM_LBUTTONDBLCLK:
1813 return HEADER_LButtonDblClk (hwnd, wParam, lParam);
1815 case WM_LBUTTONDOWN:
1816 return HEADER_LButtonDown (hwnd, wParam, lParam);
1819 return HEADER_LButtonUp (hwnd, wParam, lParam);
1822 return HEADER_MouseMove (hwnd, wParam, lParam);
1824 case WM_NOTIFYFORMAT:
1825 return HEADER_NotifyFormat (hwnd, wParam, lParam);
1828 return HEADER_Size (hwnd, wParam);
1831 return HEADER_Paint (hwnd, wParam);
1834 return HEADER_RButtonUp (hwnd, wParam, lParam);
1837 return HEADER_SetCursor (hwnd, wParam, lParam);
1840 return HEADER_SetFont (hwnd, wParam, lParam);
1843 if ((msg >= WM_USER) && (msg < WM_APP))
1844 ERR("unknown msg %04x wp=%04x lp=%08lx\n",
1845 msg, wParam, lParam );
1846 return DefWindowProcA (hwnd, msg, wParam, lParam);
1852 HEADER_Register (void)
1856 ZeroMemory (&wndClass, sizeof(WNDCLASSA));
1857 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
1858 wndClass.lpfnWndProc = HEADER_WindowProc;
1859 wndClass.cbClsExtra = 0;
1860 wndClass.cbWndExtra = sizeof(HEADER_INFO *);
1861 wndClass.hCursor = LoadCursorA (0, (LPSTR)IDC_ARROW);
1862 wndClass.lpszClassName = WC_HEADERA;
1864 RegisterClassA (&wndClass);
1869 HEADER_Unregister (void)
1871 UnregisterClassA (WC_HEADERA, NULL);