4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 1999 Luc Tourangeau
8 * Listview control implementation.
11 * 1. No horizontal scrolling when header is larger than the client area.
12 * 2. Drawing optimizations.
13 * 3. Hot item handling.
16 * LISTVIEW_Notify : most notifications from children (editbox and header)
19 * LISTVIEW_SetItemCount : empty stub
22 * LISTVIEW_SetItemW : no unicode support
23 * LISTVIEW_InsertItemW : no unicode support
24 * LISTVIEW_InsertColumnW : no unicode support
25 * LISTVIEW_GetColumnW : no unicode support
26 * LISTVIEW_SetColumnW : no unicode support
28 * Advanced functionality:
29 * LISTVIEW_GetNumberOfWorkAreas : not implemented
30 * LISTVIEW_GetHotCursor : not implemented
31 * LISTVIEW_GetHoverTime : not implemented
32 * LISTVIEW_GetISearchString : not implemented
33 * LISTVIEW_GetBkImage : not implemented
34 * LISTVIEW_EditLabel : REPORT (need to implement a timer)
35 * LISTVIEW_GetColumnOrderArray : not implemented
36 * LISTVIEW_SetColumnOrderArray : not implemented
37 * LISTVIEW_Arrange : empty stub
38 * LISTVIEW_ApproximateViewRect : incomplete
39 * LISTVIEW_Scroll : not implemented
40 * LISTVIEW_RedrawItems : empty stub
41 * LISTVIEW_Update : not completed
49 #include "debugtools.h"
51 DEFAULT_DEBUG_CHANNEL(listview)
57 /* maximum size of a label */
58 #define DISP_TEXT_SIZE 128
60 /* padding for items in list and small icon display modes */
61 #define WIDTH_PADDING 12
63 /* padding for items in list, report and small icon display modes */
64 #define HEIGHT_PADDING 1
66 /* offset of items in report display mode */
67 #define REPORT_MARGINX 2
69 /* padding for icon in large icon display mode */
70 #define ICON_TOP_PADDING 2
71 #define ICON_BOTTOM_PADDING 2
73 /* padding for label in large icon display mode */
74 #define LABEL_VERT_OFFSET 2
76 /* default label width for items in list and small icon display modes */
77 #define DEFAULT_LABEL_WIDTH 40
79 /* default column width for items in list display mode */
80 #define DEFAULT_COLUMN_WIDTH 96
85 #define GETITEMCOUNT(infoPtr) ((infoPtr)->hdpaItems->nItemCount)
86 #define ListView_LVNotify(hwnd,lCtrlId,plvnm) \
87 (BOOL)SendMessageA((hwnd),WM_NOTIFY,(WPARAM)(INT)lCtrlId,(LPARAM)(LPNMLISTVIEW)(plvnm))
88 #define ListView_Notify(hwnd,lCtrlId,pnmh) \
89 (BOOL)SendMessageA((hwnd),WM_NOTIFY,(WPARAM)(INT)lCtrlId,(LPARAM)(LPNMHDR)(pnmh))
90 /* retrieve the number of items in the listview */
91 #define GETITEMCOUNT(infoPtr) ((infoPtr)->hdpaItems->nItemCount)
94 * forward declarations
96 static INT LISTVIEW_HitTestItem(HWND, LPLVHITTESTINFO);
97 static INT LISTVIEW_GetCountPerRow(HWND);
98 static INT LISTVIEW_GetCountPerColumn(HWND);
99 static VOID LISTVIEW_AlignLeft(HWND);
100 static VOID LISTVIEW_AlignTop(HWND);
101 static VOID LISTVIEW_AddGroupSelection(HWND, INT);
102 static VOID LISTVIEW_AddSelection(HWND, INT);
103 static BOOL LISTVIEW_AddSubItem(HWND, LPLVITEMA);
104 static INT LISTVIEW_FindInsertPosition(HDPA, INT);
105 static INT LISTVIEW_GetItemHeight(HWND);
106 static BOOL LISTVIEW_GetItemPosition(HWND, INT, LPPOINT);
107 static LRESULT LISTVIEW_GetItemRect(HWND, INT, LPRECT);
108 static INT LISTVIEW_GetItemWidth(HWND);
109 static INT LISTVIEW_GetLabelWidth(HWND, INT);
110 static LRESULT LISTVIEW_GetOrigin(HWND, LPPOINT);
111 static LISTVIEW_SUBITEM* LISTVIEW_GetSubItem(HDPA, INT);
112 static LRESULT LISTVIEW_GetViewRect(HWND, LPRECT);
113 static BOOL LISTVIEW_InitItem(HWND, LISTVIEW_ITEM *, LPLVITEMA);
114 static BOOL LISTVIEW_InitSubItem(HWND, LISTVIEW_SUBITEM *, LPLVITEMA);
115 static LRESULT LISTVIEW_MouseSelection(HWND, POINT);
116 static BOOL LISTVIEW_RemoveColumn(HDPA, INT);
117 static VOID LISTVIEW_RemoveSelections(HWND, INT, INT);
118 static BOOL LISTVIEW_RemoveSubItem(HDPA, INT);
119 static VOID LISTVIEW_SetGroupSelection(HWND, INT);
120 static BOOL LISTVIEW_SetItem(HWND, LPLVITEMA);
121 static BOOL LISTVIEW_SetItemFocus(HWND, INT);
122 static BOOL LISTVIEW_SetItemPosition(HWND, INT, INT, INT);
123 static VOID LISTVIEW_UpdateScroll(HWND);
124 static VOID LISTVIEW_SetSelection(HWND, INT);
125 static VOID LISTVIEW_UpdateSize(HWND);
126 static BOOL LISTVIEW_SetSubItem(HWND, LPLVITEMA);
127 static LRESULT LISTVIEW_SetViewRect(HWND, LPRECT);
128 static BOOL LISTVIEW_ToggleSelection(HWND, INT);
129 static VOID LISTVIEW_UnsupportedStyles(LONG lStyle);
133 * Update the scrollbars. This functions should be called whenever
134 * the content, size or view changes.
137 * [I] HWND : window handle
142 static VOID LISTVIEW_UpdateScroll(HWND hwnd)
144 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
145 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
146 UINT uView = lStyle & LVS_TYPEMASK;
147 INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
148 INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
149 SCROLLINFO scrollInfo;
151 ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
152 scrollInfo.cbSize = sizeof(SCROLLINFO);
154 if (uView == LVS_LIST)
156 INT nCountPerColumn = LISTVIEW_GetCountPerColumn(hwnd);
157 INT nCountPerPage = LISTVIEW_GetCountPerRow(hwnd) * nCountPerColumn;
158 if (nCountPerPage < GETITEMCOUNT(infoPtr))
160 /* calculate new scrollbar range */
161 INT nHiddenItemCount = GETITEMCOUNT(infoPtr) - nCountPerPage;
162 if (nHiddenItemCount % nCountPerColumn == 0)
164 scrollInfo.nMax = nHiddenItemCount / nCountPerColumn;
168 scrollInfo.nMax = nHiddenItemCount / nCountPerColumn + 1;
171 scrollInfo.nPos = ListView_GetTopIndex(hwnd) / nCountPerColumn;
172 /*scrollInfo.nPage = LISTVIEW_GetCountPerRow(hwnd);*/
173 scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;
174 SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
179 if (lStyle & WS_HSCROLL)
181 ShowScrollBar(hwnd, SB_HORZ, FALSE);
185 else if (uView == LVS_REPORT)
187 /* update vertical scrollbar */
189 scrollInfo.nMax = GETITEMCOUNT(infoPtr) - LISTVIEW_GetCountPerColumn(hwnd);
190 scrollInfo.nPos = ListView_GetTopIndex(hwnd);
191 /*scrollInfo.nPage = nCountPerColumn;*/
192 scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;
193 SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE);
195 /* update horizontal scrollbar */
196 /* if (infoPtr->nItemWidth > nListWidth) */
198 /* scrollInfo.fMask = SIF_RANGE | SIF_POS | SIF_PAGE; */
199 /* SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE); */
202 /* horizontal scrolling has not been implemented yet! I experienced some
203 problems when performing child window scrolling. */
209 if (LISTVIEW_GetViewRect(hwnd, &rcView) != FALSE)
211 INT nViewWidth = rcView.right - rcView.left;
212 INT nViewHeight = rcView.bottom - rcView.top;
214 if (nViewWidth > nListWidth)
217 INT nScrollPosWidth = nListWidth / 10;
219 if (nScrollPosWidth == 0)
222 nHiddenWidth = nViewWidth - nListWidth;
226 nHiddenWidth = nViewWidth - nScrollPosWidth * 10;
229 scrollInfo.fMask = SIF_POS;
230 if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) == FALSE)
235 if (nHiddenWidth % nScrollPosWidth == 0)
237 scrollInfo.nMax = nHiddenWidth / nScrollPosWidth;
241 scrollInfo.nMax = nHiddenWidth / nScrollPosWidth + 1;
245 /*scrollInfo.nPage = 10;*/
246 scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;
247 SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
251 if (lStyle & WS_HSCROLL)
253 ShowScrollBar(hwnd, SB_HORZ, FALSE);
257 if (nViewHeight > nListHeight)
260 INT nScrollPosHeight = nListHeight / 10;
262 if (nScrollPosHeight == 0)
264 nScrollPosHeight = 1;
265 nHiddenHeight = nViewHeight - nListHeight;
269 nHiddenHeight = nViewHeight - nScrollPosHeight * 10;
272 scrollInfo.fMask = SIF_POS;
273 if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) == FALSE)
278 if (nHiddenHeight % nScrollPosHeight == 0)
280 scrollInfo.nMax = nHiddenHeight / nScrollPosHeight;
284 scrollInfo.nMax = nHiddenHeight / nScrollPosHeight + 1;
288 /*scrollInfo.nPage = 10;*/
289 scrollInfo.fMask = SIF_RANGE | SIF_POS /*| SIF_PAGE*/;
290 SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE);
294 if (lStyle & WS_VSCROLL)
296 ShowScrollBar(hwnd, SB_VERT, FALSE);
305 * Prints a message for unsupported window styles.
306 * A kind of TODO list for window styles.
309 * [I] LONG : window style
314 static VOID LISTVIEW_UnsupportedStyles(LONG lStyle)
316 if ((LVS_TYPEMASK & lStyle) == LVS_EDITLABELS)
318 FIXME(" LVS_EDITLABELS\n");
321 if ((LVS_TYPEMASK & lStyle) == LVS_NOLABELWRAP)
323 FIXME(" LVS_NOLABELWRAP\n");
326 if ((LVS_TYPEMASK & lStyle) == LVS_NOSCROLL)
328 FIXME(" LVS_NOSCROLL\n");
331 if ((LVS_TYPEMASK & lStyle) == LVS_NOSORTHEADER)
333 FIXME(" LVS_NOSORTHEADER\n");
336 if ((LVS_TYPEMASK & lStyle) == LVS_OWNERDRAWFIXED)
338 FIXME(" LVS_OWNERDRAWFIXED\n");
341 if ((LVS_TYPEMASK & lStyle) == LVS_SHAREIMAGELISTS)
343 FIXME(" LVS_SHAREIMAGELISTS\n");
346 if ((LVS_TYPEMASK & lStyle) == LVS_SORTASCENDING)
348 FIXME(" LVS_SORTASCENDING\n");
351 if ((LVS_TYPEMASK & lStyle) == LVS_SORTDESCENDING)
353 FIXME(" LVS_SORTDESCENDING\n");
359 * Aligns the items with the top edge of the window.
362 * [I] HWND : window handle
367 static VOID LISTVIEW_AlignTop(HWND hwnd)
369 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
370 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
371 INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
376 if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
378 ZeroMemory(&ptItem, sizeof(POINT));
379 ZeroMemory(&rcView, sizeof(RECT));
381 if (nListWidth > infoPtr->nItemWidth)
383 for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
385 if (ptItem.x + infoPtr->nItemWidth > nListWidth)
388 ptItem.y += infoPtr->nItemHeight;
391 ListView_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
392 ptItem.x += infoPtr->nItemWidth;
393 rcView.right = max(rcView.right, ptItem.x);
396 rcView.bottom = ptItem.y + infoPtr->nItemHeight;
400 for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
402 ListView_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
403 ptItem.y += infoPtr->nItemHeight;
406 rcView.right = infoPtr->nItemWidth;
407 rcView.bottom = ptItem.y;
410 LISTVIEW_SetViewRect(hwnd, &rcView);
416 * Aligns the items with the left edge of the window.
419 * [I] HWND : window handle
424 static VOID LISTVIEW_AlignLeft(HWND hwnd)
426 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
427 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
428 INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
433 if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
435 ZeroMemory(&ptItem, sizeof(POINT));
436 ZeroMemory(&rcView, sizeof(RECT));
438 if (nListHeight > infoPtr->nItemHeight)
440 for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
442 if (ptItem.y + infoPtr->nItemHeight > nListHeight)
445 ptItem.x += infoPtr->nItemWidth;
448 ListView_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
449 ptItem.y += infoPtr->nItemHeight;
450 rcView.bottom = max(rcView.bottom, ptItem.y);
453 rcView.right = ptItem.x + infoPtr->nItemWidth;
457 for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
459 ListView_SetItemPosition(hwnd, i, ptItem.x, ptItem.y);
460 ptItem.x += infoPtr->nItemWidth;
463 rcView.bottom = infoPtr->nItemHeight;
464 rcView.right = ptItem.x;
467 LISTVIEW_SetViewRect(hwnd, &rcView);
473 * Set the bounding rectangle of all the items.
476 * [I] HWND : window handle
477 * [I] LPRECT : bounding rectangle
483 static LRESULT LISTVIEW_SetViewRect(HWND hwnd, LPRECT lprcView)
485 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
486 BOOL bResult = FALSE;
488 TRACE("(hwnd=%x, left=%d, top=%d, right=%d, bottom=%d)\n", hwnd,
489 lprcView->left, lprcView->top, lprcView->right, lprcView->bottom);
491 if (lprcView != NULL)
494 infoPtr->rcView.left = lprcView->left;
495 infoPtr->rcView.top = lprcView->top;
496 infoPtr->rcView.right = lprcView->right;
497 infoPtr->rcView.bottom = lprcView->bottom;
505 * Retrieves the bounding rectangle of all the items.
508 * [I] HWND : window handle
509 * [O] LPRECT : bounding rectangle
515 static LRESULT LISTVIEW_GetViewRect(HWND hwnd, LPRECT lprcView)
517 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
518 BOOL bResult = FALSE;
521 TRACE("(hwnd=%x, lprcView=%p)\n", hwnd, lprcView);
523 if (lprcView != NULL)
525 bResult = LISTVIEW_GetOrigin(hwnd, &ptOrigin);
526 if (bResult != FALSE)
528 lprcView->left = infoPtr->rcView.left + ptOrigin.x;
529 lprcView->top = infoPtr->rcView.top + ptOrigin.y;
530 lprcView->right = infoPtr->rcView.right + ptOrigin.x;
531 lprcView->bottom = infoPtr->rcView.bottom + ptOrigin.y;
534 TRACE("(left=%d, top=%d, right=%d, bottom=%d)\n",
535 lprcView->left, lprcView->top, lprcView->right, lprcView->bottom);
543 * Retrieves the subitem pointer associated with the subitem index.
546 * [I] HDPA : DPA handle for a specific item
547 * [I] INT : index of subitem
550 * SUCCESS : subitem pointer
553 static LISTVIEW_SUBITEM* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems,
556 LISTVIEW_SUBITEM *lpSubItem;
559 for (i = 1; i < hdpaSubItems->nItemCount; i++)
561 lpSubItem = (LISTVIEW_SUBITEM *) DPA_GetPtr(hdpaSubItems, i);
562 if (lpSubItem != NULL)
564 if (lpSubItem->iSubItem == nSubItem)
576 * Calculates the width of an item.
579 * [I] HWND : window handle
580 * [I] LONG : window style
583 * Returns item width.
585 static INT LISTVIEW_GetItemWidth(HWND hwnd)
587 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
588 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
589 INT nHeaderItemCount;
595 TRACE("(hwnd=%x)\n", hwnd);
597 if (uView == LVS_ICON)
599 nItemWidth = infoPtr->iconSpacing.cx;
601 else if (uView == LVS_REPORT)
603 /* calculate width of header */
604 nHeaderItemCount = Header_GetItemCount(infoPtr->hwndHeader);
605 for (i = 0; i < nHeaderItemCount; i++)
607 if (Header_GetItemRect(infoPtr->hwndHeader, i, &rcHeaderItem) != 0)
609 nItemWidth += (rcHeaderItem.right - rcHeaderItem.left);
615 for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
617 nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, i);
618 nItemWidth = max(nItemWidth, nLabelWidth);
621 /* default label size */
622 if (GETITEMCOUNT(infoPtr) == 0)
624 nItemWidth = DEFAULT_COLUMN_WIDTH;
630 nItemWidth = DEFAULT_LABEL_WIDTH;
635 nItemWidth += WIDTH_PADDING;
637 if (infoPtr->himlSmall != NULL)
639 nItemWidth += infoPtr->iconSize.cx;
642 if (infoPtr->himlState != NULL)
644 nItemWidth += infoPtr->iconSize.cx;
655 * Calculates the height of an item.
658 * [I] HWND : window handle
659 * [I] LONG : window style
662 * Returns item height.
664 static INT LISTVIEW_GetItemHeight(HWND hwnd)
666 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
667 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
670 if (uView == LVS_ICON)
672 nItemHeight = infoPtr->iconSpacing.cy;
677 HDC hdc = GetDC(hwnd);
678 HFONT hOldFont = SelectObject(hdc, infoPtr->hFont);
679 GetTextMetricsA(hdc, &tm);
680 nItemHeight = max(tm.tmHeight, infoPtr->iconSize.cy) + HEIGHT_PADDING;
681 SelectObject(hdc, hOldFont);
682 ReleaseDC(hwnd, hdc);
690 * Adds a block of selections.
693 * [I] HWND : window handle
694 * [I] INT : item index
699 static VOID LISTVIEW_AddGroupSelection(HWND hwnd, INT nItem)
701 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
702 INT nFirst = min(infoPtr->nSelectionMark, nItem);
703 INT nLast = max(infoPtr->nSelectionMark, nItem);
707 lvItem.state = LVIS_SELECTED;
708 lvItem.stateMask= LVIS_SELECTED;
710 for (i = nFirst; i <= nLast; i++)
712 ListView_SetItemState(hwnd, i, &lvItem);
715 LISTVIEW_SetItemFocus(hwnd, nItem);
716 infoPtr->nSelectionMark = nItem;
721 * Adds a single selection.
724 * [I] HWND : window handle
725 * [I] INT : item index
730 static VOID LISTVIEW_AddSelection(HWND hwnd, INT nItem)
732 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
735 lvItem.state = LVIS_SELECTED;
736 lvItem.stateMask= LVIS_SELECTED;
738 ListView_SetItemState(hwnd, nItem, &lvItem);
740 LISTVIEW_SetItemFocus(hwnd, nItem);
741 infoPtr->nSelectionMark = nItem;
746 * Selects or unselects an item.
749 * [I] HWND : window handle
750 * [I] INT : item index
756 static BOOL LISTVIEW_ToggleSelection(HWND hwnd, INT nItem)
758 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
762 lvItem.stateMask= LVIS_SELECTED;
764 if (ListView_GetItemState(hwnd, nItem, LVIS_SELECTED) & LVIS_SELECTED)
767 ListView_SetItemState(hwnd, nItem, &lvItem);
772 lvItem.state = LVIS_SELECTED;
773 ListView_SetItemState(hwnd, nItem, &lvItem);
777 LISTVIEW_SetItemFocus(hwnd, nItem);
778 infoPtr->nSelectionMark = nItem;
785 * Selects items based on view coorddiantes.
788 * [I] HWND : window handle
789 * [I] RECT : selection rectangle
794 static VOID LISTVIEW_SetSelectionRect(HWND hwnd, RECT rcSelRect)
796 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
801 lvItem.stateMask = LVIS_SELECTED;
803 for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
805 LISTVIEW_GetItemPosition(hwnd, i, &ptItem);
806 if (PtInRect(&rcSelRect, ptItem) != FALSE)
808 lvItem.state = LVIS_SELECTED;
815 ListView_SetItemState(hwnd, i, &lvItem);
821 * Sets a single group selection.
824 * [I] HWND : window handle
825 * [I] INT : item index
830 static VOID LISTVIEW_SetGroupSelection(HWND hwnd, INT nItem)
832 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
833 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
836 if ((uView == LVS_LIST) || (uView == LVS_REPORT))
839 INT nFirst = min(infoPtr->nSelectionMark, nItem);
840 INT nLast = max(infoPtr->nSelectionMark, nItem);
841 lvItem.stateMask = LVIS_SELECTED;
843 for (i = 0; i <= GETITEMCOUNT(infoPtr); i++)
845 if ((i < nFirst) || (i > nLast))
851 lvItem.state = LVIS_SELECTED;
854 ListView_SetItemState(hwnd, i, &lvItem);
862 LISTVIEW_GetItemPosition(hwnd, nItem, &ptItem);
863 LISTVIEW_GetItemPosition(hwnd, infoPtr->nSelectionMark, &ptSelMark);
864 rcSel.left = min(ptSelMark.x, ptItem.x);
865 rcSel.top = min(ptSelMark.y, ptItem.y);
866 rcSel.right = max(ptSelMark.x, ptItem.x) + infoPtr->nItemWidth;
867 rcSel.bottom = max(ptSelMark.y, ptItem.y) + infoPtr->nItemHeight;
868 LISTVIEW_SetSelectionRect(hwnd, rcSel);
871 LISTVIEW_SetItemFocus(hwnd, nItem);
876 * Manages the item focus.
879 * [I] HWND : window handle
880 * [I] INT : item index
883 * TRUE : focused item changed
884 * FALSE : focused item has NOT changed
886 static BOOL LISTVIEW_SetItemFocus(HWND hwnd, INT nItem)
888 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
889 BOOL bResult = FALSE;
892 if (infoPtr->nFocusedItem != nItem)
895 ZeroMemory(&lvItem, sizeof(LVITEMA));
896 lvItem.stateMask = LVIS_FOCUSED;
897 ListView_SetItemState(hwnd, infoPtr->nFocusedItem, &lvItem);
899 lvItem.state = LVIS_FOCUSED;
900 lvItem.stateMask = LVIS_FOCUSED;
901 ListView_SetItemState(hwnd, nItem, &lvItem);
903 infoPtr->nFocusedItem = nItem;
904 ListView_EnsureVisible(hwnd, nItem, FALSE);
912 * Sets a single selection.
915 * [I] HWND : window handle
916 * [I] INT : item index
921 static VOID LISTVIEW_SetSelection(HWND hwnd, INT nItem)
923 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
928 LISTVIEW_RemoveSelections(hwnd, 0, nItem - 1);
931 if (nItem < GETITEMCOUNT(infoPtr))
933 LISTVIEW_RemoveSelections(hwnd, nItem + 1, GETITEMCOUNT(infoPtr));
936 ZeroMemory(&lvItem, sizeof(LVITEMA));
937 lvItem.stateMask = LVIS_FOCUSED;
938 ListView_SetItemState(hwnd, infoPtr->nFocusedItem, &lvItem);
940 lvItem.state = LVIS_SELECTED | LVIS_FOCUSED;
941 lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
942 ListView_SetItemState(hwnd, nItem, &lvItem);
944 infoPtr->nFocusedItem = nItem;
945 infoPtr->nSelectionMark = nItem;
950 * Set selection(s) with keyboard.
953 * [I] HWND : window handle
954 * [I] INT : item index
957 * SUCCESS : TRUE (needs to be repainted)
958 * FAILURE : FALSE (nothing has changed)
960 static BOOL LISTVIEW_KeySelection(HWND hwnd, INT nItem)
962 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
963 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
964 WORD wShift = HIWORD(GetKeyState(VK_SHIFT));
965 WORD wCtrl = HIWORD(GetKeyState(VK_CONTROL));
966 BOOL bResult = FALSE;
968 if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
970 if (lStyle & LVS_SINGLESEL)
973 LISTVIEW_SetSelection(hwnd, nItem);
974 ListView_EnsureVisible(hwnd, nItem, FALSE);
981 LISTVIEW_SetGroupSelection(hwnd, nItem);
985 bResult = LISTVIEW_SetItemFocus(hwnd, nItem);
990 LISTVIEW_SetSelection(hwnd, nItem);
991 ListView_EnsureVisible(hwnd, nItem, FALSE);
1001 * Selects an item based on coordinates.
1004 * [I] HWND : window handle
1005 * [I] POINT : mouse click ccordinates
1008 * SUCCESS : item index
1011 static LRESULT LISTVIEW_MouseSelection(HWND hwnd, POINT pt)
1013 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
1017 for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
1019 rcItem.left = LVIR_SELECTBOUNDS;
1020 if (LISTVIEW_GetItemRect(hwnd, i, &rcItem) == TRUE)
1022 if (PtInRect(&rcItem, pt) != FALSE)
1034 * Removes all selection states.
1037 * [I] HWND : window handle
1038 * [I] INT : item index
1044 static VOID LISTVIEW_RemoveSelections(HWND hwnd, INT nFirst, INT nLast)
1050 lvItem.stateMask = LVIS_SELECTED;
1052 for (i = nFirst; i <= nLast; i++)
1054 ListView_SetItemState(hwnd, i, &lvItem);
1063 * [IO] HDPA : dynamic pointer array handle
1064 * [I] INT : column index (subitem index)
1070 static BOOL LISTVIEW_RemoveColumn(HDPA hdpaItems, INT nSubItem)
1072 BOOL bResult = TRUE;
1076 for (i = 0; i < hdpaItems->nItemCount; i++)
1078 hdpaSubItems = (HDPA)DPA_GetPtr(hdpaItems, i);
1079 if (hdpaSubItems != NULL)
1081 if (LISTVIEW_RemoveSubItem(hdpaSubItems, nSubItem) == FALSE)
1093 * Removes a subitem at a given position.
1096 * [IO] HDPA : dynamic pointer array handle
1097 * [I] INT : subitem index
1103 static BOOL LISTVIEW_RemoveSubItem(HDPA hdpaSubItems, INT nSubItem)
1105 LISTVIEW_SUBITEM *lpSubItem;
1108 for (i = 1; i < hdpaSubItems->nItemCount; i++)
1110 lpSubItem = (LISTVIEW_SUBITEM *)DPA_GetPtr(hdpaSubItems, i);
1111 if (lpSubItem != NULL)
1113 if (lpSubItem->iSubItem == nSubItem)
1116 if ((lpSubItem->pszText != NULL) &&
1117 (lpSubItem->pszText != LPSTR_TEXTCALLBACKA))
1119 COMCTL32_Free(lpSubItem->pszText);
1123 COMCTL32_Free(lpSubItem);
1125 /* free dpa memory */
1126 if (DPA_DeletePtr(hdpaSubItems, i) == NULL)
1131 else if (lpSubItem->iSubItem > nSubItem)
1143 * Compares the item information.
1146 * [I] LISTVIEW_ITEM *: destination item
1147 * [I] LPLVITEM : source item
1150 * SUCCCESS : TRUE (EQUAL)
1151 * FAILURE : FALSE (NOT EQUAL)
1153 static UINT LISTVIEW_GetItemChanges(LISTVIEW_ITEM *lpItem, LPLVITEMA lpLVItem)
1157 if ((lpItem != NULL) && (lpLVItem != NULL))
1159 if (lpLVItem->mask & LVIF_STATE)
1161 if ((lpItem->state & lpLVItem->stateMask) !=
1162 (lpLVItem->state & lpLVItem->stateMask))
1164 uChanged |= LVIF_STATE;
1168 if (lpLVItem->mask & LVIF_IMAGE)
1170 if (lpItem->iImage != lpLVItem->iImage)
1172 uChanged |= LVIF_IMAGE;
1176 if (lpLVItem->mask & LVIF_PARAM)
1178 if (lpItem->lParam != lpLVItem->lParam)
1180 uChanged |= LVIF_PARAM;
1184 if (lpLVItem->mask & LVIF_INDENT)
1186 if (lpItem->iIndent != lpLVItem->iIndent)
1188 uChanged |= LVIF_INDENT;
1192 if (lpLVItem->mask & LVIF_TEXT)
1194 if (lpLVItem->pszText == LPSTR_TEXTCALLBACKA)
1196 if (lpItem->pszText != LPSTR_TEXTCALLBACKA)
1198 uChanged |= LVIF_TEXT;
1203 if (lpItem->pszText == LPSTR_TEXTCALLBACKA)
1205 uChanged |= LVIF_TEXT;
1209 if (lpLVItem->pszText)
1211 if (lpItem->pszText)
1213 if (strcmp(lpLVItem->pszText, lpItem->pszText) != 0)
1215 uChanged |= LVIF_TEXT;
1220 uChanged |= LVIF_TEXT;
1225 if (lpItem->pszText)
1227 uChanged |= LVIF_TEXT;
1239 * Initializes item attributes.
1242 * [I] HWND : window handle
1243 * [O] LISTVIEW_ITEM *: destination item
1244 * [I] LPLVITEM : source item
1250 static BOOL LISTVIEW_InitItem(HWND hwnd, LISTVIEW_ITEM *lpItem,
1253 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
1254 BOOL bResult = FALSE;
1256 if ((lpItem != NULL) && (lpLVItem != NULL))
1260 if (lpLVItem->mask & LVIF_STATE)
1262 lpItem->state &= ~lpLVItem->stateMask;
1263 lpItem->state |= (lpLVItem->state & lpLVItem->stateMask);
1266 if (lpLVItem->mask & LVIF_IMAGE)
1268 lpItem->iImage = lpLVItem->iImage;
1271 if (lpLVItem->mask & LVIF_PARAM)
1273 lpItem->lParam = lpLVItem->lParam;
1276 if (lpLVItem->mask & LVIF_INDENT)
1278 lpItem->iIndent = lpLVItem->iIndent;
1281 if (lpLVItem->mask & LVIF_TEXT)
1283 if (lpLVItem->pszText == LPSTR_TEXTCALLBACKA)
1285 if ((lStyle & LVS_SORTASCENDING) || (lStyle & LVS_SORTDESCENDING))
1290 if ((lpItem->pszText != NULL) &&
1291 (lpItem->pszText != LPSTR_TEXTCALLBACKA))
1293 COMCTL32_Free(lpItem->pszText);
1296 lpItem->pszText = LPSTR_TEXTCALLBACKA;
1300 if (lpItem->pszText == LPSTR_TEXTCALLBACKA)
1302 lpItem->pszText = NULL;
1305 bResult = Str_SetPtrA(&lpItem->pszText, lpLVItem->pszText);
1315 * Initializes subitem attributes.
1317 * NOTE: The documentation specifies that the operation fails if the user
1318 * tries to set the indent of a subitem.
1321 * [I] HWND : window handle
1322 * [O] LISTVIEW_SUBITEM *: destination subitem
1323 * [I] LPLVITEM : source subitem
1329 static BOOL LISTVIEW_InitSubItem(HWND hwnd, LISTVIEW_SUBITEM *lpSubItem,
1332 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
1333 BOOL bResult = FALSE;
1335 if ((lpSubItem != NULL) && (lpLVItem != NULL))
1337 if (!(lpLVItem->mask & LVIF_INDENT))
1340 ZeroMemory(lpSubItem, sizeof(LISTVIEW_SUBITEM));
1342 lpSubItem->iSubItem = lpLVItem->iSubItem;
1344 if (lpLVItem->mask & LVIF_IMAGE)
1346 lpSubItem->iImage = lpLVItem->iImage;
1349 if (lpLVItem->mask & LVIF_TEXT)
1351 if (lpLVItem->pszText == LPSTR_TEXTCALLBACKA)
1353 if ((lStyle & LVS_SORTASCENDING) || (lStyle & LVS_SORTDESCENDING))
1358 if ((lpSubItem->pszText != NULL) &&
1359 (lpSubItem->pszText != LPSTR_TEXTCALLBACKA))
1361 COMCTL32_Free(lpSubItem->pszText);
1364 lpSubItem->pszText = LPSTR_TEXTCALLBACKA;
1368 if (lpSubItem->pszText == LPSTR_TEXTCALLBACKA)
1370 lpSubItem->pszText = NULL;
1373 bResult = Str_SetPtrA(&lpSubItem->pszText, lpLVItem->pszText);
1384 * Adds a subitem at a given position (column index).
1387 * [I] HWND : window handle
1388 * [I] LPLVITEM : new subitem atttributes
1394 static BOOL LISTVIEW_AddSubItem(HWND hwnd, LPLVITEMA lpLVItem)
1396 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
1397 LISTVIEW_SUBITEM *lpSubItem = NULL;
1398 BOOL bResult = FALSE;
1400 INT nPosition, nItem;
1402 if (lpLVItem != NULL)
1404 hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, lpLVItem->iItem);
1405 if (hdpaSubItems != NULL)
1407 lpSubItem = (LISTVIEW_SUBITEM *)COMCTL32_Alloc(sizeof(LISTVIEW_SUBITEM));
1408 if (lpSubItem != NULL)
1410 if (LISTVIEW_InitSubItem(hwnd, lpSubItem, lpLVItem) != FALSE)
1412 nPosition = LISTVIEW_FindInsertPosition(hdpaSubItems,
1413 lpSubItem->iSubItem);
1414 nItem = DPA_InsertPtr(hdpaSubItems, nPosition, lpSubItem);
1424 /* cleanup if unsuccessful */
1425 if ((bResult == FALSE) && (lpSubItem != NULL))
1427 COMCTL32_Free(lpSubItem);
1435 * Finds the dpa insert position (array index).
1438 * [I] HWND : window handle
1439 * [I] INT : subitem index
1445 static INT LISTVIEW_FindInsertPosition(HDPA hdpaSubItems, INT nSubItem)
1447 LISTVIEW_SUBITEM *lpSubItem;
1450 for (i = 1; i < hdpaSubItems->nItemCount; i++)
1452 lpSubItem = (LISTVIEW_SUBITEM *)DPA_GetPtr(hdpaSubItems, i);
1453 if (lpSubItem != NULL)
1455 if (lpSubItem->iSubItem > nSubItem)
1462 return hdpaSubItems->nItemCount;
1467 * Retrieves a listview subitem at a given position (column index).
1470 * [I] HWND : window handle
1471 * [I] INT : subitem index
1477 static LISTVIEW_SUBITEM* LISTVIEW_GetSubItem(HDPA hdpaSubItems, INT nSubItem)
1479 LISTVIEW_SUBITEM *lpSubItem;
1482 for (i = 1; i < hdpaSubItems->nItemCount; i++)
1484 lpSubItem = (LISTVIEW_SUBITEM *)DPA_GetPtr(hdpaSubItems, i);
1485 if (lpSubItem != NULL)
1487 if (lpSubItem->iSubItem == nSubItem)
1491 else if (lpSubItem->iSubItem > nSubItem)
1503 * Sets item attributes.
1506 * [I] HWND : window handle
1507 * [I] LPLVITEM : new item atttributes
1513 static BOOL LISTVIEW_SetItem(HWND hwnd, LPLVITEMA lpLVItem)
1515 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
1516 BOOL bResult = FALSE;
1518 LISTVIEW_ITEM *lpItem;
1521 LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
1523 if (lpLVItem != NULL)
1525 if (lpLVItem->iSubItem == 0)
1527 hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, lpLVItem->iItem);
1528 if (hdpaSubItems != NULL)
1530 lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, lpLVItem->iSubItem);
1533 ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
1534 nmlv.hdr.hwndFrom = hwnd;
1535 nmlv.hdr.idFrom = lCtrlId;
1536 nmlv.hdr.code = LVN_ITEMCHANGING;
1537 nmlv.lParam = lpItem->lParam;
1538 uChanged = LISTVIEW_GetItemChanges(lpItem, lpLVItem);
1541 if (uChanged & LVIF_STATE)
1543 nmlv.uNewState = lpLVItem->state & lpLVItem->stateMask;
1544 nmlv.uOldState = lpItem->state & lpLVItem->stateMask;
1547 nmlv.uChanged = uChanged;
1548 nmlv.iItem = lpLVItem->iItem;
1549 nmlv.lParam = lpItem->lParam;
1550 /* send LVN_ITEMCHANGING notification */
1551 ListView_LVNotify(GetParent(hwnd), lCtrlId, &nmlv);
1553 /* copy information */
1554 bResult = LISTVIEW_InitItem(hwnd, lpItem, lpLVItem);
1556 /* send LVN_ITEMCHANGED notification */
1557 nmlv.hdr.code = LVN_ITEMCHANGED;
1558 ListView_LVNotify(GetParent(hwnd), lCtrlId, &nmlv);
1565 InvalidateRect(hwnd, NULL, FALSE);
1576 * Sets subitem attributes.
1579 * [I] HWND : window handle
1580 * [I] LPLVITEM : new subitem atttributes
1586 static BOOL LISTVIEW_SetSubItem(HWND hwnd, LPLVITEMA lpLVItem)
1588 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
1589 BOOL bResult = FALSE;
1591 LISTVIEW_SUBITEM *lpSubItem;
1593 if (lpLVItem != NULL)
1595 if (lpLVItem->iSubItem > 0)
1597 hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, lpLVItem->iItem);
1598 if (hdpaSubItems != NULL)
1600 /* set subitem only if column is present */
1601 if (Header_GetItemCount(infoPtr->hwndHeader) > lpLVItem->iSubItem)
1603 lpSubItem = LISTVIEW_GetSubItem(hdpaSubItems, lpLVItem->iSubItem);
1604 if (lpSubItem != NULL)
1606 bResult = LISTVIEW_InitSubItem(hwnd, lpSubItem, lpLVItem);
1610 bResult = LISTVIEW_AddSubItem(hwnd, lpLVItem);
1613 InvalidateRect(hwnd, NULL, FALSE);
1624 * Retrieves the index of the item at coordinate (0, 0) of the client area.
1627 * [I] HWND : window handle
1632 static INT LISTVIEW_GetTopIndex(HWND hwnd)
1634 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
1635 UINT uView = lStyle & LVS_TYPEMASK;
1637 SCROLLINFO scrollInfo;
1639 ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
1640 scrollInfo.cbSize = sizeof(SCROLLINFO);
1641 scrollInfo.fMask = SIF_POS;
1643 if (uView == LVS_LIST)
1645 if (lStyle & WS_HSCROLL)
1647 if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
1649 nItem = scrollInfo.nPos * LISTVIEW_GetCountPerColumn(hwnd);
1653 else if (uView == LVS_REPORT)
1655 if (lStyle & WS_VSCROLL)
1657 if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) != FALSE)
1659 nItem = scrollInfo.nPos;
1672 * [I] HWND : window handle
1673 * [I] HDC : device context handle
1674 * [I] INT : item index
1675 * [I] INT : subitem index
1676 * [I] RECT * : clipping rectangle
1681 static VOID LISTVIEW_DrawSubItem(HWND hwnd, HDC hdc, INT nItem, INT nSubItem,
1684 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
1685 CHAR szDispText[DISP_TEXT_SIZE];
1688 TRACE("(hwnd=%x, hdc=%x, nItem=%d, nSubItem=%d\n", hwnd, hdc,
1691 /* get information needed for drawing the item */
1692 ZeroMemory(&lvItem, sizeof(LVITEMA));
1693 lvItem.mask = LVIF_TEXT;
1694 lvItem.iItem = nItem;
1695 lvItem.iSubItem = nSubItem;
1696 lvItem.cchTextMax = DISP_TEXT_SIZE;
1697 lvItem.pszText = szDispText;
1698 ListView_GetItemA(hwnd, &lvItem);
1700 /* set item colors */
1701 SetBkColor(hdc, infoPtr->clrTextBk);
1702 SetTextColor(hdc, infoPtr->clrText);
1704 ExtTextOutA(hdc, rcItem.left, rcItem.top, ETO_OPAQUE | ETO_CLIPPED,
1705 &rcItem, lvItem.pszText, lstrlenA(lvItem.pszText), NULL);
1714 * [I] HWND : window handle
1715 * [I] HDC : device context handle
1716 * [I] INT : item index
1717 * [I] RECT * : clipping rectangle
1722 static VOID LISTVIEW_DrawItem(HWND hwnd, HDC hdc, INT nItem, RECT rcItem)
1724 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
1725 CHAR szDispText[DISP_TEXT_SIZE];
1732 TRACE("(hwnd=%x, hdc=%x, nItem=%d\n", hwnd, hdc, nItem);
1734 /* get information needed for drawing the item */
1735 ZeroMemory(&lvItem, sizeof(LVITEMA));
1736 lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE | LVIF_INDENT;
1737 lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED | LVIS_STATEIMAGEMASK;
1738 lvItem.iItem = nItem;
1739 lvItem.iSubItem = 0;
1740 lvItem.cchTextMax = DISP_TEXT_SIZE;
1741 lvItem.pszText = szDispText;
1742 ListView_GetItemA(hwnd, &lvItem);
1745 if (infoPtr->himlState != NULL)
1747 UINT uStateImage = (lvItem.state & LVIS_STATEIMAGEMASK) >> 12;
1748 if (uStateImage != 0)
1750 ImageList_Draw(infoPtr->himlState, uStateImage - 1, hdc, rcItem.left,
1751 rcItem.top, ILD_NORMAL);
1754 rcItem.left += infoPtr->iconSize.cx;
1758 if (infoPtr->himlSmall != NULL)
1760 if ((lvItem.state & LVIS_SELECTED) && (infoPtr->bFocus != FALSE))
1762 ImageList_SetBkColor(infoPtr->himlSmall, CLR_NONE);
1763 ImageList_Draw(infoPtr->himlSmall, lvItem.iImage, hdc, rcItem.left,
1764 rcItem.top, ILD_SELECTED);
1768 ImageList_SetBkColor(infoPtr->himlSmall, CLR_NONE);
1769 ImageList_Draw(infoPtr->himlSmall, lvItem.iImage, hdc, rcItem.left,
1770 rcItem.top, ILD_NORMAL);
1773 rcItem.left += infoPtr->iconSize.cx;
1776 if ((lvItem.state & LVIS_SELECTED) && (infoPtr->bFocus != FALSE))
1778 /* set item colors */
1779 dwBkColor = SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
1780 dwTextColor = SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
1781 /* set raster mode */
1782 nMixMode = SetROP2(hdc, R2_XORPEN);
1784 else if ((GetWindowLongA(hwnd, GWL_STYLE) & LVS_SHOWSELALWAYS) &&
1785 (lvItem.state & LVIS_SELECTED) && (infoPtr->bFocus == FALSE))
1787 dwBkColor = SetBkColor(hdc, GetSysColor(COLOR_3DFACE));
1788 dwTextColor = SetTextColor(hdc, GetSysColor(COLOR_BTNTEXT));
1789 /* set raster mode */
1790 nMixMode = SetROP2(hdc, R2_COPYPEN);
1794 /* set item colors */
1795 dwBkColor = SetBkColor(hdc, infoPtr->clrTextBk);
1796 dwTextColor = SetTextColor(hdc, infoPtr->clrText);
1797 /* set raster mode */
1798 nMixMode = SetROP2(hdc, R2_COPYPEN);
1801 nLabelWidth = ListView_GetStringWidthA(hwnd, lvItem.pszText);
1802 if (rcItem.left + nLabelWidth < rcItem.right)
1804 rcItem.right = rcItem.left + nLabelWidth;
1808 ExtTextOutA(hdc, rcItem.left, rcItem.top, ETO_OPAQUE | ETO_CLIPPED,
1809 &rcItem, lvItem.pszText, lstrlenA(lvItem.pszText), NULL);
1811 if ((lvItem.state & LVIS_FOCUSED) && (infoPtr->bFocus == TRUE))
1813 Rectangle(hdc, rcItem.left, rcItem.top, rcItem.right, rcItem.bottom);
1818 SetROP2(hdc, R2_COPYPEN);
1819 SetBkColor(hdc, infoPtr->clrTextBk);
1820 SetTextColor(hdc, infoPtr->clrText);
1826 * Draws an item when in large icon display mode.
1829 * [I] HWND : window handle
1830 * [I] HDC : device context handle
1831 * [I] LISTVIEW_ITEM * : item
1832 * [I] INT : item index
1833 * [I] RECT * : clipping rectangle
1838 static VOID LISTVIEW_DrawLargeItem(HWND hwnd, HDC hdc, INT nItem, RECT rcItem)
1840 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
1841 CHAR szDispText[DISP_TEXT_SIZE];
1842 INT nDrawPosX = rcItem.left;
1847 TRACE("(hwnd=%x, hdc=%x, nItem=%d, left=%d, top=%d, right=%d, \
1848 bottom=%d)\n", hwnd, hdc, nItem, rcItem.left, rcItem.top, rcItem.right,
1851 /* get information needed for drawing the item */
1852 ZeroMemory(&lvItem, sizeof(LVITEMA));
1853 lvItem.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_STATE;
1854 lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
1855 lvItem.iItem = nItem;
1856 lvItem.iSubItem = 0;
1857 lvItem.cchTextMax = DISP_TEXT_SIZE;
1858 lvItem.pszText = szDispText;
1859 ListView_GetItemA(hwnd, &lvItem);
1861 if (lvItem.state & LVIS_SELECTED)
1863 /* set item colors */
1864 SetBkColor(hdc, GetSysColor(COLOR_HIGHLIGHT));
1865 SetTextColor(hdc, GetSysColor(COLOR_HIGHLIGHTTEXT));
1866 /* set raster mode */
1867 SetROP2(hdc, R2_XORPEN);
1871 /* set item colors */
1872 SetBkColor(hdc, infoPtr->clrTextBk);
1873 SetTextColor(hdc, infoPtr->clrText);
1874 /* set raster mode */
1875 SetROP2(hdc, R2_COPYPEN);
1878 if (infoPtr->himlNormal != NULL)
1880 rcItem.top += ICON_TOP_PADDING;
1881 nDrawPosX += (infoPtr->iconSpacing.cx - infoPtr->iconSize.cx) / 2;
1882 if (lvItem.state & LVIS_SELECTED)
1884 ImageList_Draw(infoPtr->himlNormal, lvItem.iImage, hdc, nDrawPosX,
1885 rcItem.top, ILD_SELECTED);
1889 ImageList_Draw(infoPtr->himlNormal, lvItem.iImage, hdc, nDrawPosX,
1890 rcItem.top, ILD_NORMAL);
1894 rcItem.top += infoPtr->iconSize.cy + ICON_BOTTOM_PADDING;
1895 nLabelWidth = ListView_GetStringWidthA(hwnd, lvItem.pszText);
1896 nDrawPosX = infoPtr->iconSpacing.cx - nLabelWidth;
1899 rcItem.left += nDrawPosX / 2;
1900 rcItem.right = rcItem.left + nLabelWidth;
1905 rcItem.right = rcItem.left + infoPtr->iconSpacing.cx - 1;
1909 GetTextMetricsA(hdc, &tm);
1910 rcItem.bottom = rcItem.top + tm.tmHeight + HEIGHT_PADDING;
1911 ExtTextOutA(hdc, rcItem.left, rcItem.top, ETO_OPAQUE | ETO_CLIPPED,
1912 &rcItem, lvItem.pszText, lstrlenA(lvItem.pszText), NULL);
1914 if (lvItem.state & LVIS_FOCUSED)
1916 Rectangle(hdc, rcItem.left, rcItem.top, rcItem.right, rcItem.bottom);
1922 * Draws listview items when in report display mode.
1925 * [I] HWND : window handle
1926 * [I] HDC : device context handle
1931 static VOID LISTVIEW_RefreshReport(HWND hwnd, HDC hdc)
1933 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd,0);
1934 INT nDrawPosY = infoPtr->rcList.top;
1941 nItem = ListView_GetTopIndex(hwnd);
1943 /* add 1 for displaying a partial item at the bottom */
1944 nLast = nItem + LISTVIEW_GetCountPerColumn(hwnd) + 1;
1945 nLast = min(nLast, GETITEMCOUNT(infoPtr));
1946 for (; nItem < nLast; nItem++)
1948 nColumnCount = Header_GetItemCount(infoPtr->hwndHeader);
1949 for (j = 0; j < nColumnCount; j++)
1951 Header_GetItemRect(infoPtr->hwndHeader, j, &rcItem);
1952 rcItem.left += REPORT_MARGINX;
1953 rcItem.right = max(rcItem.left, rcItem.right - REPORT_MARGINX);
1954 rcItem.top = nDrawPosY;
1955 rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
1958 LISTVIEW_DrawItem(hwnd, hdc, nItem, rcItem);
1962 LISTVIEW_DrawSubItem(hwnd, hdc, nItem, j, rcItem);
1966 nDrawPosY += infoPtr->nItemHeight;
1972 * Retrieves the number of items that can fit vertically in the client area.
1975 * [I] HWND : window handle
1978 * Number of items per row.
1980 static INT LISTVIEW_GetCountPerRow(HWND hwnd)
1982 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd,0);
1983 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
1984 INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
1985 INT nCountPerRow = 1;
1989 if (uView == LVS_REPORT)
1995 nCountPerRow = nListWidth / infoPtr->nItemWidth;
1996 if (nCountPerRow == 0)
2003 return nCountPerRow;
2008 * Retrieves the number of items that can fit horizontally in the client
2012 * [I] HWND : window handle
2015 * Number of items per column.
2017 static INT LISTVIEW_GetCountPerColumn(HWND hwnd)
2019 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd,0);
2020 INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
2021 INT nCountPerColumn = 1;
2023 if (nListHeight > 0)
2025 nCountPerColumn = nListHeight / infoPtr->nItemHeight;
2026 if (nCountPerColumn == 0)
2028 nCountPerColumn = 1;
2032 return nCountPerColumn;
2037 * Retrieves the number of columns needed to display all the items when in
2038 * list display mode.
2041 * [I] HWND : window handle
2044 * Number of columns.
2046 static INT LISTVIEW_GetColumnCount(HWND hwnd)
2048 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
2049 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
2050 INT nColumnCount = 0;
2052 if ((lStyle & LVS_TYPEMASK) == LVS_LIST)
2054 if (infoPtr->rcList.right % infoPtr->nItemWidth == 0)
2056 nColumnCount = infoPtr->rcList.right / infoPtr->nItemWidth;
2060 nColumnCount = infoPtr->rcList.right / infoPtr->nItemWidth + 1;
2064 return nColumnCount;
2070 * Draws listview items when in list display mode.
2073 * [I] HWND : window handle
2074 * [I] HDC : device context handle
2079 static VOID LISTVIEW_RefreshList(HWND hwnd, HDC hdc)
2081 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
2086 INT nCountPerColumn;
2088 /* get number of fully visible columns */
2089 nColumnCount = LISTVIEW_GetColumnCount(hwnd);
2090 nCountPerColumn = LISTVIEW_GetCountPerColumn(hwnd);
2091 nItem = ListView_GetTopIndex(hwnd);
2093 for (i = 0; i < nColumnCount; i++)
2095 for (j = 0; j < nCountPerColumn; j++, nItem++)
2097 if (nItem >= GETITEMCOUNT(infoPtr))
2100 rcItem.top = j * infoPtr->nItemHeight;
2101 rcItem.left = i * infoPtr->nItemWidth;
2102 rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
2103 rcItem.right = rcItem.left + infoPtr->nItemWidth;
2104 LISTVIEW_DrawItem(hwnd, hdc, nItem, rcItem);
2111 * Draws listview items when in icon or small icon display mode.
2114 * [I] HWND : window handle
2115 * [I] HDC : device context handle
2120 static VOID LISTVIEW_RefreshIcon(HWND hwnd, HDC hdc, BOOL bSmall)
2122 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
2128 LISTVIEW_GetOrigin(hwnd, &ptOrigin);
2129 for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
2131 LISTVIEW_GetItemPosition(hwnd, i, &ptPosition);
2132 ptPosition.x += ptOrigin.x;
2133 ptPosition.y += ptOrigin.y;
2135 if (ptPosition.y + infoPtr->nItemHeight > infoPtr->rcList.top)
2137 if (ptPosition.x + infoPtr->nItemWidth > infoPtr->rcList.left)
2139 if (ptPosition.y < infoPtr->rcList.bottom)
2141 if (ptPosition.x < infoPtr->rcList.right)
2143 rcItem.top = ptPosition.y;
2144 rcItem.left = ptPosition.x;
2145 rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
2146 rcItem.right = rcItem.left + infoPtr->nItemWidth;
2147 if (bSmall == FALSE)
2149 LISTVIEW_DrawLargeItem(hwnd, hdc, i, rcItem);
2153 LISTVIEW_DrawItem(hwnd, hdc, i, rcItem);
2164 * Draws listview items.
2167 * [I] HWND : window handle
2168 * [I] HDC : device context handle
2173 static VOID LISTVIEW_Refresh(HWND hwnd, HDC hdc)
2175 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
2176 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
2181 hOldFont = SelectObject(hdc, infoPtr->hFont);
2183 /* select the doted pen (for drawing the focus box) */
2184 hPen = CreatePen(PS_DOT, 1, 0);
2185 hOldPen = SelectObject(hdc, hPen);
2187 /* select transparent brush (for drawing the focus box) */
2188 SelectObject(hdc, GetStockObject(NULL_BRUSH));
2190 if (uView == LVS_LIST)
2192 LISTVIEW_RefreshList(hwnd, hdc);
2194 else if (uView == LVS_REPORT)
2196 LISTVIEW_RefreshReport(hwnd, hdc);
2198 else if (uView == LVS_SMALLICON)
2200 LISTVIEW_RefreshIcon(hwnd, hdc, TRUE);
2202 else if (uView == LVS_ICON)
2204 LISTVIEW_RefreshIcon(hwnd, hdc, FALSE);
2207 /* unselect objects */
2208 SelectObject(hdc, hOldFont);
2209 SelectObject(hdc, hOldPen);
2218 * Calculates the approximate width and height of a given number of items.
2221 * [I] HWND : window handle
2222 * [I] INT : number of items
2227 * Returns a DWORD. The width in the low word and the height in high word.
2229 static LRESULT LISTVIEW_ApproximateViewRect(HWND hwnd, INT nItemCount,
2230 WORD wWidth, WORD wHeight)
2232 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
2233 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
2234 INT nItemCountPerColumn = 1;
2235 INT nColumnCount = 0;
2236 DWORD dwViewRect = 0;
2238 if (nItemCount == -1)
2240 nItemCount = GETITEMCOUNT(infoPtr);
2243 if (uView == LVS_LIST)
2245 if (wHeight == 0xFFFF)
2247 /* use current height */
2248 wHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
2251 if (wHeight < infoPtr->nItemHeight)
2253 wHeight = infoPtr->nItemHeight;
2258 if (infoPtr->nItemHeight > 0)
2260 nItemCountPerColumn = wHeight / infoPtr->nItemHeight;
2261 if (nItemCountPerColumn == 0)
2263 nItemCountPerColumn = 1;
2266 if (nItemCount % nItemCountPerColumn != 0)
2268 nColumnCount = nItemCount / nItemCountPerColumn;
2272 nColumnCount = nItemCount / nItemCountPerColumn + 1;
2277 /* Microsoft padding magic */
2278 wHeight = nItemCountPerColumn * infoPtr->nItemHeight + 2;
2279 wWidth = nColumnCount * infoPtr->nItemWidth + 2;
2281 dwViewRect = MAKELONG(wWidth, wHeight);
2283 else if (uView == LVS_REPORT)
2287 else if (uView == LVS_SMALLICON)
2291 else if (uView == LVS_ICON)
2301 * Arranges listview items in icon display mode.
2304 * [I] HWND : window handle
2305 * [I] INT : alignment code
2311 static LRESULT LISTVIEW_Arrange(HWND hwnd, INT nAlignCode)
2313 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
2314 BOOL bResult = FALSE;
2316 if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
2329 case LVA_SNAPTOGRID:
2338 /* << LISTVIEW_CreateDragImage >> */
2342 * Removes all listview items and subitems.
2345 * [I] HWND : window handle
2351 static LRESULT LISTVIEW_DeleteAllItems(HWND hwnd)
2353 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
2354 LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
2355 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
2356 UINT uView = lStyle & LVS_TYPEMASK;
2357 LISTVIEW_ITEM *lpItem;
2358 LISTVIEW_SUBITEM *lpSubItem;
2361 BOOL bResult = FALSE;
2366 TRACE("(hwnd=%x,)\n", hwnd);
2368 if (GETITEMCOUNT(infoPtr) > 0)
2370 /* initialize memory */
2371 ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
2373 /* send LVN_DELETEALLITEMS notification */
2374 nmlv.hdr.hwndFrom = hwnd;
2375 nmlv.hdr.idFrom = lCtrlId;
2376 nmlv.hdr.code = LVN_DELETEALLITEMS;
2379 /* verify if subsequent LVN_DELETEITEM notifications should be
2381 bSuppress = ListView_LVNotify(GetParent(hwnd), lCtrlId, &nmlv);
2383 for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
2385 hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, i);
2386 if (hdpaSubItems != NULL)
2388 for (j = 1; j < hdpaSubItems->nItemCount; j++)
2390 lpSubItem = (LISTVIEW_SUBITEM *)DPA_GetPtr(hdpaSubItems, j);
2391 if (lpSubItem != NULL)
2393 /* free subitem string */
2394 if ((lpSubItem->pszText != NULL) &&
2395 (lpSubItem->pszText != LPSTR_TEXTCALLBACKA))
2397 COMCTL32_Free(lpSubItem->pszText);
2401 COMCTL32_Free(lpSubItem);
2405 lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
2408 if (bSuppress == FALSE)
2410 /* send LVN_DELETEITEM notification */
2411 nmlv.hdr.code = LVN_DELETEITEM;
2413 nmlv.lParam = lpItem->lParam;
2414 ListView_LVNotify(GetParent(hwnd), lCtrlId, &nmlv);
2417 /* free item string */
2418 if ((lpItem->pszText != NULL) &&
2419 (lpItem->pszText != LPSTR_TEXTCALLBACKA))
2421 COMCTL32_Free(lpItem->pszText);
2425 COMCTL32_Free(lpItem);
2428 DPA_Destroy(hdpaSubItems);
2432 /* reinitialize listview memory */
2433 bResult = DPA_DeleteAllPtrs(infoPtr->hdpaItems);
2435 /* align items (set position of each item) */
2436 if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
2438 if (lStyle & LVS_ALIGNLEFT)
2440 LISTVIEW_AlignLeft(hwnd);
2444 LISTVIEW_AlignTop(hwnd);
2448 LISTVIEW_UpdateScroll(hwnd);
2450 /* invalidate client area (optimization needed) */
2451 InvalidateRect(hwnd, NULL, TRUE);
2459 * Removes a column from the listview control.
2462 * [I] HWND : window handle
2463 * [I] INT : column index
2469 static LRESULT LISTVIEW_DeleteColumn(HWND hwnd, INT nColumn)
2471 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
2472 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
2473 BOOL bResult = FALSE;
2475 if (Header_DeleteItem(infoPtr->hwndHeader, nColumn) != FALSE)
2477 bResult = LISTVIEW_RemoveColumn(infoPtr->hdpaItems, nColumn);
2479 /* reset scroll parameters */
2480 if (uView == LVS_REPORT)
2482 /* update scrollbar(s) */
2483 LISTVIEW_UpdateScroll(hwnd);
2485 /* refresh client area */
2486 InvalidateRect(hwnd, NULL, FALSE);
2495 * Removes an item from the listview control.
2498 * [I] HWND : window handle
2499 * [I] INT : item index
2505 static LRESULT LISTVIEW_DeleteItem(HWND hwnd, INT nItem)
2507 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
2508 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
2509 UINT uView = lStyle & LVS_TYPEMASK;
2510 LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
2512 BOOL bResult = FALSE;
2514 LISTVIEW_ITEM *lpItem;
2515 LISTVIEW_SUBITEM *lpSubItem;
2518 TRACE("(hwnd=%x,nItem=%d)\n", hwnd, nItem);
2520 if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
2522 /* initialize memory */
2523 ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
2525 hdpaSubItems = (HDPA)DPA_DeletePtr(infoPtr->hdpaItems, nItem);
2526 if (hdpaSubItems != NULL)
2528 for (i = 1; i < hdpaSubItems->nItemCount; i++)
2530 lpSubItem = (LISTVIEW_SUBITEM *)DPA_GetPtr(hdpaSubItems, i);
2531 if (lpSubItem != NULL)
2533 /* free item string */
2534 if ((lpSubItem->pszText != NULL) &&
2535 (lpSubItem->pszText != LPSTR_TEXTCALLBACKA))
2537 COMCTL32_Free(lpSubItem->pszText);
2541 COMCTL32_Free(lpSubItem);
2545 lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
2548 /* send LVN_DELETEITEM notification */
2549 nmlv.hdr.hwndFrom = hwnd;
2550 nmlv.hdr.idFrom = lCtrlId;
2551 nmlv.hdr.code = LVN_DELETEITEM;
2553 nmlv.lParam = lpItem->lParam;
2554 SendMessageA(GetParent(hwnd), WM_NOTIFY, (WPARAM)lCtrlId,
2557 /* free item string */
2558 if ((lpItem->pszText != NULL) &&
2559 (lpItem->pszText != LPSTR_TEXTCALLBACKA))
2561 COMCTL32_Free(lpItem->pszText);
2565 COMCTL32_Free(lpItem);
2568 bResult = DPA_Destroy(hdpaSubItems);
2571 /* align items (set position of each item) */
2572 if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
2574 if (lStyle & LVS_ALIGNLEFT)
2576 LISTVIEW_AlignLeft(hwnd);
2580 LISTVIEW_AlignTop(hwnd);
2584 LISTVIEW_UpdateScroll(hwnd);
2586 /* refresh client area */
2587 InvalidateRect(hwnd, NULL, TRUE);
2593 /* LISTVIEW_EditLabel */
2597 * Ensures the specified item is visible, scrolling into view if necessary.
2600 * [I] HWND : window handle
2601 * [I] INT : item index
2602 * [I] BOOL : partially or entirely visible
2608 static BOOL LISTVIEW_EnsureVisible(HWND hwnd, INT nItem, BOOL bPartial)
2610 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
2611 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
2612 INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
2613 INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
2614 INT nScrollPosHeight = 0;
2615 INT nScrollPosWidth = 0;
2616 SCROLLINFO scrollInfo;
2619 ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
2620 scrollInfo.cbSize = sizeof(SCROLLINFO);
2621 scrollInfo.fMask = SIF_POS;
2623 /* ALWAYS bPartial == FALSE, FOR NOW! */
2625 rcItem.left = LVIR_BOUNDS;
2626 if (LISTVIEW_GetItemRect(hwnd, nItem, &rcItem) != FALSE)
2628 if (rcItem.left < infoPtr->rcList.left)
2630 if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
2633 if (uView == LVS_LIST)
2635 nScrollPosWidth = infoPtr->nItemWidth;
2636 rcItem.left += infoPtr->rcList.left;
2638 else if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
2640 nScrollPosWidth = max(1, nListWidth / 10);
2641 rcItem.left += infoPtr->rcList.left;
2644 if (rcItem.left % nScrollPosWidth == 0)
2646 scrollInfo.nPos += rcItem.left / nScrollPosWidth;
2650 scrollInfo.nPos += rcItem.left / nScrollPosWidth - 1;
2653 SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
2656 else if (rcItem.right > infoPtr->rcList.right)
2658 if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
2661 if (uView == LVS_LIST)
2663 rcItem.right -= infoPtr->rcList.right;
2664 nScrollPosWidth = infoPtr->nItemWidth;
2666 else if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
2668 rcItem.right -= infoPtr->rcList.right;
2669 nScrollPosWidth = max(1, nListWidth / 10);
2672 if (rcItem.right % nScrollPosWidth == 0)
2674 scrollInfo.nPos += rcItem.right / nScrollPosWidth;
2678 scrollInfo.nPos += rcItem.right / nScrollPosWidth + 1;
2681 SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
2685 if (rcItem.top < infoPtr->rcList.top)
2688 if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) != FALSE)
2690 if (uView == LVS_REPORT)
2692 rcItem.top -= infoPtr->rcList.top;
2693 nScrollPosHeight = infoPtr->nItemHeight;
2695 else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
2697 nScrollPosHeight = max(1, nListHeight / 10);
2698 rcItem.top += infoPtr->rcList.top;
2701 if (rcItem.top % nScrollPosHeight == 0)
2703 scrollInfo.nPos += rcItem.top / nScrollPosHeight;
2707 scrollInfo.nPos += rcItem.top / nScrollPosHeight - 1;
2710 SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE);
2713 else if (rcItem.bottom > infoPtr->rcList.bottom)
2716 if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) != FALSE)
2718 if (uView == LVS_REPORT)
2720 rcItem.bottom -= infoPtr->rcList.bottom;
2721 nScrollPosHeight = infoPtr->nItemHeight;
2723 else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
2725 nScrollPosHeight = max(1, nListHeight / 10);
2726 rcItem.bottom -= infoPtr->rcList.bottom;
2729 if (rcItem.bottom % nScrollPosHeight == 0)
2731 scrollInfo.nPos += rcItem.bottom / nScrollPosHeight;
2735 scrollInfo.nPos += rcItem.bottom / nScrollPosHeight + 1;
2738 SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE);
2748 * Retrieves the nearest item, given a position and a direction.
2751 * [I] HWND : window handle
2752 * [I] POINT : start position
2753 * [I] UINT : direction
2756 * Item index if successdful, -1 otherwise.
2758 static INT LISTVIEW_GetNearestItem(HWND hwnd, POINT pt, UINT vkDirection)
2760 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
2761 LVHITTESTINFO lvHitTestInfo;
2765 if (LISTVIEW_GetViewRect(hwnd, &rcView) != FALSE)
2767 ZeroMemory(&lvHitTestInfo, sizeof(LVHITTESTINFO));
2768 LISTVIEW_GetOrigin(hwnd, &lvHitTestInfo.pt);
2769 lvHitTestInfo.pt.x += pt.x;
2770 lvHitTestInfo.pt.y += pt.y;
2774 if (vkDirection == VK_DOWN)
2776 lvHitTestInfo.pt.y += infoPtr->nItemHeight;
2778 else if (vkDirection == VK_UP)
2780 lvHitTestInfo.pt.y -= infoPtr->nItemHeight;
2782 else if (vkDirection == VK_LEFT)
2784 lvHitTestInfo.pt.x -= infoPtr->nItemWidth;
2786 else if (vkDirection == VK_RIGHT)
2788 lvHitTestInfo.pt.x += infoPtr->nItemWidth;
2791 if (PtInRect(&rcView, lvHitTestInfo.pt) == FALSE)
2797 nItem = LISTVIEW_HitTestItem(hwnd, &lvHitTestInfo);
2801 while (nItem == -1);
2809 * Searches for an item with specific characteristics.
2812 * [I] HWND : window handle
2813 * [I] INT : base item index
2814 * [I] LPLVFINDINFO : item information to look for
2817 * SUCCESS : index of item
2820 static LRESULT LISTVIEW_FindItem(HWND hwnd, INT nStart,
2821 LPLVFINDINFO lpFindInfo)
2823 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
2825 CHAR szDispText[DISP_TEXT_SIZE];
2829 INT nLast = GETITEMCOUNT(infoPtr);
2831 if ((nItem >= -1) && (lpFindInfo != NULL))
2833 ZeroMemory(&lvItem, sizeof(LVITEMA));
2835 if (lpFindInfo->flags & LVFI_PARAM)
2837 lvItem.mask |= LVIF_PARAM;
2840 if (lpFindInfo->flags & LVFI_STRING)
2842 lvItem.mask |= LVIF_TEXT;
2843 lvItem.pszText = szDispText;
2844 lvItem.cchTextMax = DISP_TEXT_SIZE;
2847 if (lpFindInfo->flags & LVFI_PARTIAL)
2849 lvItem.mask |= LVIF_TEXT;
2850 lvItem.pszText = szDispText;
2851 lvItem.cchTextMax = DISP_TEXT_SIZE;
2854 if (lpFindInfo->flags & LVFI_WRAP)
2859 if (lpFindInfo->flags & LVFI_NEARESTXY)
2861 ptItem.x = lpFindInfo->pt.x;
2862 ptItem.y = lpFindInfo->pt.y;
2867 while (nItem < nLast)
2869 if (lpFindInfo->flags & LVFI_NEARESTXY)
2871 nItem = LISTVIEW_GetNearestItem(hwnd, ptItem,
2872 lpFindInfo->vkDirection);
2875 /* get position of the new item index */
2876 if (ListView_GetItemPosition(hwnd, nItem, &ptItem) == FALSE)
2887 lvItem.iItem = nItem;
2888 lvItem.iSubItem = 0;
2889 if (ListView_GetItemA(hwnd, &lvItem) != FALSE)
2891 if (lvItem.mask & LVIF_TEXT)
2893 if (lpFindInfo->flags & LVFI_PARTIAL)
2895 if (strstr(lvItem.pszText, lpFindInfo->psz) == NULL)
2900 if (strcmp(lvItem.pszText, lpFindInfo->psz) != 0)
2905 if (lvItem.mask & LVIF_PARAM)
2907 if (lpFindInfo->lParam != lvItem.lParam)
2933 * Retrieves the background color of the listview control.
2936 * [I] HWND : window handle
2939 * COLORREF associated with the background.
2941 static LRESULT LISTVIEW_GetBkColor(HWND hwnd)
2943 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
2945 return infoPtr->clrBk;
2950 * Retrieves the background image of the listview control.
2953 * [I] HWND : window handle
2954 * [O] LPLVMKBIMAGE : background image attributes
2960 /* static LRESULT LISTVIEW_GetBkImage(HWND hwnd, LPLVBKIMAGE lpBkImage) */
2962 /* FIXME (listview, "empty stub!\n"); */
2968 * Retrieves the callback mask.
2971 * [I] HWND : window handle
2976 static UINT LISTVIEW_GetCallbackMask(HWND hwnd)
2978 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
2980 return infoPtr->uCallbackMask;
2985 * Retrieves column attributes.
2988 * [I] HWND : window handle
2989 * [I] INT : column index
2990 * [IO] LPLVCOLUMNA : column information
2996 static LRESULT LISTVIEW_GetColumnA(HWND hwnd, INT nItem, LPLVCOLUMNA lpColumn)
2998 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
3000 BOOL bResult = FALSE;
3002 if (lpColumn != NULL)
3004 /* initialize memory */
3005 ZeroMemory(&hdi, sizeof(HDITEMA));
3007 if (lpColumn->mask & LVCF_FMT)
3009 hdi.mask |= HDI_FORMAT;
3012 if (lpColumn->mask & LVCF_WIDTH)
3014 hdi.mask |= HDI_WIDTH;
3017 if (lpColumn->mask & LVCF_TEXT)
3019 hdi.mask |= (HDI_TEXT | HDI_FORMAT);
3022 if (lpColumn->mask & LVCF_IMAGE)
3024 hdi.mask |= HDI_IMAGE;
3027 if (lpColumn->mask & LVCF_ORDER)
3029 hdi.mask |= HDI_ORDER;
3032 bResult = Header_GetItemA(infoPtr->hwndHeader, nItem, &hdi);
3033 if (bResult != FALSE)
3035 if (lpColumn->mask & LVCF_FMT)
3039 if (hdi.fmt & HDF_LEFT)
3041 lpColumn->fmt |= LVCFMT_LEFT;
3043 else if (hdi.fmt & HDF_RIGHT)
3045 lpColumn->fmt |= LVCFMT_RIGHT;
3047 else if (hdi.fmt & HDF_CENTER)
3049 lpColumn->fmt |= LVCFMT_CENTER;
3052 if (hdi.fmt & HDF_IMAGE)
3054 lpColumn->fmt |= LVCFMT_COL_HAS_IMAGES;
3057 if (hdi.fmt & HDF_BITMAP_ON_RIGHT)
3059 lpColumn->fmt |= LVCFMT_BITMAP_ON_RIGHT;
3063 if (lpColumn->mask & LVCF_WIDTH)
3065 lpColumn->cx = hdi.cxy;
3068 if ((lpColumn->mask & LVCF_TEXT) && (lpColumn->pszText) && (hdi.pszText))
3070 lstrcpynA (lpColumn->pszText, hdi.pszText, lpColumn->cchTextMax);
3073 if (lpColumn->mask & LVCF_IMAGE)
3075 lpColumn->iImage = hdi.iImage;
3078 if (lpColumn->mask & LVCF_ORDER)
3080 lpColumn->iOrder = hdi.iOrder;
3088 /* LISTVIEW_GetColumnW */
3089 /* LISTVIEW_GetColumnOrderArray */
3093 * Retrieves the column width.
3096 * [I] HWND : window handle
3097 * [I] int : column index
3100 * SUCCESS : column width
3103 static LRESULT LISTVIEW_GetColumnWidth(HWND hwnd, INT nColumn)
3105 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
3106 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
3107 INT nColumnWidth = 0;
3110 if (uView == LVS_LIST)
3112 nColumnWidth = infoPtr->nItemWidth;
3114 else if (uView == LVS_REPORT)
3116 /* get column width from header */
3117 ZeroMemory(&hdi, sizeof(HDITEMA));
3118 hdi.mask = HDI_WIDTH;
3119 if (Header_GetItemA(infoPtr->hwndHeader, nColumn, &hdi) != FALSE)
3121 nColumnWidth = hdi.cxy;
3125 return nColumnWidth;
3130 * In list or report display mode, retrieves the number of items that can fit
3131 * vertically in the visible area. In icon or small icon display mode,
3132 * retrieves the total number of visible items.
3135 * [I] HWND : window handle
3138 * Number of fully visible items.
3140 static LRESULT LISTVIEW_GetCountPerPage(HWND hwnd)
3142 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
3143 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
3146 if (uView == LVS_LIST)
3148 if (infoPtr->rcList.right > infoPtr->nItemWidth)
3150 nItemCount = LISTVIEW_GetCountPerRow(hwnd) *
3151 LISTVIEW_GetCountPerColumn(hwnd);
3154 else if (uView == LVS_REPORT)
3156 nItemCount = LISTVIEW_GetCountPerColumn(hwnd);
3160 nItemCount = GETITEMCOUNT(infoPtr);
3166 /* LISTVIEW_GetEditControl */
3170 * Retrieves the extended listview style.
3173 * [I] HWND : window handle
3176 * SUCCESS : previous style
3179 static LRESULT LISTVIEW_GetExtendedListViewStyle(HWND hwnd)
3181 LISTVIEW_INFO *infoPtr;
3183 /* make sure we can get the listview info */
3184 if (!(infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0)))
3187 return (infoPtr->dwExStyle);
3192 * Retrieves the handle to the header control.
3195 * [I] HWND : window handle
3200 static LRESULT LISTVIEW_GetHeader(HWND hwnd)
3202 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
3204 return infoPtr->hwndHeader;
3207 /* LISTVIEW_GetHotCursor */
3208 /* LISTVIEW_GetHotItem */
3209 /* LISTVIEW_GetHoverTime */
3213 * Retrieves an image list handle.
3216 * [I] HWND : window handle
3217 * [I] INT : image list identifier
3220 * SUCCESS : image list handle
3223 static LRESULT LISTVIEW_GetImageList(HWND hwnd, INT nImageList)
3225 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
3226 HIMAGELIST himl = NULL;
3231 himl = infoPtr->himlNormal;
3234 himl = infoPtr->himlSmall;
3237 himl = infoPtr->himlState;
3241 return (LRESULT)himl;
3244 /* LISTVIEW_GetISearchString */
3248 * Retrieves item attributes.
3251 * [I] HWND : window handle
3252 * [IO] LPLVITEMA : item info
3258 static LRESULT LISTVIEW_GetItemA(HWND hwnd, LPLVITEMA lpLVItem)
3260 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
3261 LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
3262 BOOL bResult = FALSE;
3263 NMLVDISPINFOA dispInfo;
3264 LISTVIEW_SUBITEM *lpSubItem;
3265 LISTVIEW_ITEM *lpItem;
3268 TRACE("(hwnd=%x, lpLVItem=%p)\n", hwnd, lpLVItem);
3270 if (lpLVItem != NULL)
3272 if ((lpLVItem->iItem >= 0) && (lpLVItem->iItem < GETITEMCOUNT(infoPtr)))
3274 ZeroMemory(&dispInfo, sizeof(NMLVDISPINFOA));
3275 hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, lpLVItem->iItem);
3276 if (hdpaSubItems != NULL)
3278 lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
3282 if (lpLVItem->iSubItem == 0)
3284 if ((lpItem->iImage == I_IMAGECALLBACK) &&
3285 (lpLVItem->mask & LVIF_IMAGE))
3287 dispInfo.item.mask |= LVIF_IMAGE;
3290 if ((lpItem->pszText == LPSTR_TEXTCALLBACKA) &&
3291 (lpLVItem->mask & LVIF_TEXT))
3293 dispInfo.item.mask |= LVIF_TEXT;
3294 ZeroMemory(lpLVItem->pszText, sizeof(CHAR)*lpLVItem->cchTextMax);
3295 dispInfo.item.pszText = lpLVItem->pszText;
3296 dispInfo.item.cchTextMax = lpLVItem->cchTextMax;
3299 if ((infoPtr->uCallbackMask != 0) && (lpLVItem->mask & LVIF_STATE))
3301 dispInfo.item.mask |= LVIF_STATE;
3302 dispInfo.item.stateMask = infoPtr->uCallbackMask;
3305 if (dispInfo.item.mask != 0)
3307 dispInfo.hdr.hwndFrom = hwnd;
3308 dispInfo.hdr.idFrom = lCtrlId;
3309 dispInfo.hdr.code = LVN_GETDISPINFOA;
3310 dispInfo.item.iItem = lpLVItem->iItem;
3311 dispInfo.item.iSubItem = 0;
3312 dispInfo.item.lParam = lpItem->lParam;
3313 ListView_Notify(GetParent(hwnd), lCtrlId, &dispInfo);
3316 if (dispInfo.item.mask & LVIF_IMAGE)
3318 lpLVItem->iImage = dispInfo.item.iImage;
3320 else if (lpLVItem->mask & LVIF_IMAGE)
3322 lpLVItem->iImage = lpItem->iImage;
3325 if (dispInfo.item.mask & LVIF_TEXT)
3327 if (dispInfo.item.mask & LVIF_DI_SETITEM)
3329 Str_SetPtrA(&lpItem->pszText, dispInfo.item.pszText);
3331 lpLVItem->pszText = dispInfo.item.pszText;
3333 else if (lpLVItem->mask & LVIF_TEXT)
3335 lpLVItem->pszText = lpItem->pszText;
3338 if (dispInfo.item.mask & LVIF_STATE)
3340 lpLVItem->state = lpItem->state;
3341 lpLVItem->state &= ~dispInfo.item.stateMask;
3342 lpLVItem->state |= (dispInfo.item.state &
3343 dispInfo.item.stateMask);
3345 else if (lpLVItem->mask & LVIF_STATE)
3347 lpLVItem->state = lpItem->state & lpLVItem->stateMask;
3350 if (lpLVItem->mask & LVIF_PARAM)
3352 lpLVItem->lParam = lpItem->lParam;
3355 if (lpLVItem->mask & LVIF_INDENT)
3357 lpLVItem->iIndent = lpItem->iIndent;
3362 lpSubItem = LISTVIEW_GetSubItemPtr(hdpaSubItems,
3363 lpLVItem->iSubItem);
3364 if (lpSubItem != NULL)
3366 if ((lpSubItem->iImage == I_IMAGECALLBACK) &&
3367 (lpLVItem->mask & LVIF_IMAGE))
3369 dispInfo.item.mask |= LVIF_IMAGE;
3372 if ((lpSubItem->pszText == LPSTR_TEXTCALLBACKA) &&
3373 (lpLVItem->mask & LVIF_TEXT))
3375 dispInfo.item.mask |= LVIF_TEXT;
3376 ZeroMemory(lpLVItem->pszText,
3377 sizeof(CHAR)*lpLVItem->cchTextMax);
3378 dispInfo.item.pszText = lpLVItem->pszText;
3379 dispInfo.item.cchTextMax = lpLVItem->cchTextMax;
3384 if (lpLVItem->mask & LVIF_IMAGE)
3386 dispInfo.item.mask |= LVIF_IMAGE;
3389 if (lpLVItem->mask & LVIF_TEXT)
3391 dispInfo.item.mask |= LVIF_TEXT;
3392 ZeroMemory(lpLVItem->pszText,
3393 sizeof(CHAR)*lpLVItem->cchTextMax);
3394 dispInfo.item.pszText = lpLVItem->pszText;
3395 dispInfo.item.cchTextMax = lpLVItem->cchTextMax;
3399 if (dispInfo.item.mask != 0)
3401 dispInfo.hdr.hwndFrom = hwnd;
3402 dispInfo.hdr.idFrom = lCtrlId;
3403 dispInfo.hdr.code = LVN_GETDISPINFOA;
3404 dispInfo.item.iItem = lpLVItem->iItem;
3405 dispInfo.item.iSubItem = lpLVItem->iSubItem;
3406 dispInfo.item.lParam = lpItem->lParam;
3407 ListView_Notify(GetParent(hwnd), lCtrlId, &dispInfo);
3410 if (dispInfo.item.mask & LVIF_IMAGE)
3412 lpLVItem->iImage = dispInfo.item.iImage;
3414 else if (lpLVItem->mask & LVIF_IMAGE)
3416 lpLVItem->iImage = lpItem->iImage;
3419 if (dispInfo.item.mask & LVIF_TEXT)
3421 if (dispInfo.item.mask & LVIF_DI_SETITEM)
3424 Str_SetPtrA(&lpSubItem->pszText, dispInfo.item.pszText);
3426 lpLVItem->pszText = dispInfo.item.pszText;
3428 else if (lpLVItem->mask & LVIF_TEXT)
3430 lpLVItem->pszText = lpSubItem->pszText;
3441 /* LISTVIEW_GetItemW */
3442 /* LISTVIEW_GetHotCursor */
3446 * Retrieves the index of the hot item.
3449 * [I] HWND : window handle
3452 * SUCCESS : hot item index
3453 * FAILURE : -1 (no hot item)
3455 static LRESULT LISTVIEW_GetHotItem(HWND hwnd)
3457 LISTVIEW_INFO *infoPtr;
3459 /* make sure we can get the listview info */
3460 if (!(infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0)))
3463 return (infoPtr->nHotItem);
3466 /* LISTVIEW_GetHoverTime */
3470 * Retrieves the number of items in the listview control.
3473 * [I] HWND : window handle
3478 static LRESULT LISTVIEW_GetItemCount(HWND hwnd)
3480 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
3482 return GETITEMCOUNT(infoPtr);
3487 * Retrieves the position (upper-left) of the listview control item.
3490 * [I] HWND : window handle
3491 * [I] INT : item index
3492 * [O] LPPOINT : coordinate information
3498 static BOOL LISTVIEW_GetItemPosition(HWND hwnd, INT nItem,
3499 LPPOINT lpptPosition)
3501 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
3502 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
3503 BOOL bResult = FALSE;
3505 LISTVIEW_ITEM *lpItem;
3506 INT nCountPerColumn;
3509 TRACE("(hwnd=%x,nItem=%d,lpptPosition=%p)\n", hwnd, nItem,
3512 if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)) &&
3513 (lpptPosition != NULL))
3515 if (uView == LVS_LIST)
3518 nItem = nItem - ListView_GetTopIndex(hwnd);
3519 nCountPerColumn = LISTVIEW_GetCountPerColumn(hwnd);
3522 nRow = nItem % nCountPerColumn;
3525 lpptPosition->x = nItem / nCountPerColumn * infoPtr->nItemWidth;
3526 lpptPosition->y = 0;
3530 lpptPosition->x = (nItem / nCountPerColumn -1) * infoPtr->nItemWidth;
3531 lpptPosition->y = (nRow + nCountPerColumn) * infoPtr->nItemHeight;
3536 lpptPosition->x = nItem / nCountPerColumn * infoPtr->nItemWidth;
3537 lpptPosition->y = nItem % nCountPerColumn * infoPtr->nItemHeight;
3540 else if (uView == LVS_REPORT)
3543 lpptPosition->x = REPORT_MARGINX;
3544 lpptPosition->y = ((nItem - ListView_GetTopIndex(hwnd)) *
3545 infoPtr->nItemHeight) + infoPtr->rcList.top;
3549 hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem);
3550 if (hdpaSubItems != NULL)
3552 lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
3556 lpptPosition->x = lpItem->ptPosition.x;
3557 lpptPosition->y = lpItem->ptPosition.y;
3568 * Retrieves the bounding rectangle for a listview control item.
3571 * [I] HWND : window handle
3572 * [I] INT : item index
3573 * [IO] LPRECT : bounding rectangle coordinates
3579 static LRESULT LISTVIEW_GetItemRect(HWND hwnd, INT nItem, LPRECT lprc)
3581 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
3582 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
3583 BOOL bResult = FALSE;
3592 TRACE("(hwnd=%x, nItem=%d, lprc=%p)\n", hwnd, nItem, lprc);
3594 if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)) && (lprc != NULL))
3596 if (ListView_GetItemPosition(hwnd, nItem, &ptItem) != FALSE)
3601 if (uView == LVS_ICON)
3603 if (infoPtr->himlNormal != NULL)
3605 if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
3608 lprc->left = ptItem.x + ptOrigin.x;
3609 lprc->top = ptItem.y + ptOrigin.y;
3610 lprc->right = lprc->left + infoPtr->iconSize.cx;
3611 lprc->bottom = (lprc->top + infoPtr->iconSize.cy +
3612 ICON_BOTTOM_PADDING + ICON_TOP_PADDING);
3616 else if (uView == LVS_SMALLICON)
3618 if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
3621 lprc->left = ptItem.x + ptOrigin.x;
3622 lprc->top = ptItem.y + ptOrigin.y;
3623 lprc->bottom = lprc->top + infoPtr->nItemHeight;
3625 if (infoPtr->himlState != NULL)
3626 lprc->left += infoPtr->iconSize.cx;
3628 if (infoPtr->himlSmall != NULL)
3629 lprc->right = lprc->left + infoPtr->iconSize.cx;
3631 lprc->right = lprc->left;
3637 lprc->left = ptItem.x;
3638 lprc->top = ptItem.y;
3639 lprc->bottom = lprc->top + infoPtr->nItemHeight;
3641 if (infoPtr->himlState != NULL)
3643 lprc->left += infoPtr->iconSize.cx;
3646 if (infoPtr->himlSmall != NULL)
3648 lprc->right = lprc->left + infoPtr->iconSize.cx;
3652 lprc->right = lprc->left;
3658 if (uView == LVS_ICON)
3660 if (infoPtr->himlNormal != NULL)
3662 if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
3665 lprc->left = ptItem.x + ptOrigin.x;
3666 lprc->top = (ptItem.y + ptOrigin.y + infoPtr->iconSize.cy +
3667 ICON_BOTTOM_PADDING + ICON_TOP_PADDING);
3668 nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
3669 if (infoPtr->iconSpacing.cx - nLabelWidth > 1)
3671 lprc->left += (infoPtr->iconSpacing.cx - nLabelWidth) / 2;
3672 lprc->right = lprc->left + nLabelWidth;
3677 lprc->right = lprc->left + infoPtr->iconSpacing.cx - 1;
3681 hOldFont = SelectObject(hdc, infoPtr->hFont);
3682 GetTextMetricsA(hdc, &tm);
3683 lprc->bottom = lprc->top + tm.tmHeight + HEIGHT_PADDING;
3684 SelectObject(hdc, hOldFont);
3685 ReleaseDC(hwnd, hdc);
3689 else if (uView == LVS_SMALLICON)
3691 if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
3694 nLeftPos = lprc->left = ptItem.x + ptOrigin.x;
3695 lprc->top = ptItem.y + ptOrigin.y;
3696 lprc->bottom = lprc->top + infoPtr->nItemHeight;
3698 if (infoPtr->himlState != NULL)
3700 lprc->left += infoPtr->iconSize.cx;
3703 if (infoPtr->himlSmall != NULL)
3705 lprc->left += infoPtr->iconSize.cx;
3708 nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
3709 if (lprc->left + nLabelWidth < nLeftPos + infoPtr->nItemWidth)
3711 lprc->right = lprc->left + nLabelWidth;
3715 lprc->right = nLeftPos + infoPtr->nItemWidth;
3722 nLeftPos = lprc->left = ptItem.x;
3723 lprc->top = ptItem.y;
3724 lprc->bottom = lprc->top + infoPtr->nItemHeight;
3726 if (infoPtr->himlState != NULL)
3728 lprc->left += infoPtr->iconSize.cx;
3731 if (infoPtr->himlSmall != NULL)
3733 lprc->left += infoPtr->iconSize.cx;
3736 nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
3737 if (lprc->left + nLabelWidth < nLeftPos + infoPtr->nItemWidth)
3739 lprc->right = lprc->left + nLabelWidth;
3743 lprc->right = nLeftPos + infoPtr->nItemWidth;
3749 if (uView == LVS_ICON)
3751 if (infoPtr->himlNormal != NULL)
3753 if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
3756 lprc->left = ptItem.x + ptOrigin.x;
3757 lprc->top = ptItem.y + ptOrigin.y;
3758 lprc->right = lprc->left + infoPtr->iconSpacing.cx;
3759 lprc->bottom = lprc->top + infoPtr->iconSpacing.cy;
3763 else if (uView == LVS_SMALLICON)
3765 if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
3768 lprc->left = ptItem.x + ptOrigin.x;
3769 lprc->right = lprc->left;
3770 lprc->top = ptItem.y + ptOrigin.y;
3771 lprc->bottom = lprc->top + infoPtr->nItemHeight;
3772 if (infoPtr->himlState != NULL)
3773 lprc->right += infoPtr->iconSize.cx;
3774 if (infoPtr->himlSmall != NULL)
3775 lprc->right += infoPtr->iconSize.cx;
3777 nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
3778 if (lprc->right + nLabelWidth < lprc->left + infoPtr->nItemWidth)
3780 lprc->right += nLabelWidth;
3784 lprc->right = lprc->left + infoPtr->nItemWidth;
3791 lprc->left = ptItem.x;
3792 lprc->right = lprc->left;
3793 lprc->top = ptItem.y;
3794 lprc->bottom = lprc->top + infoPtr->nItemHeight;
3796 if (infoPtr->himlState != NULL)
3798 lprc->right += infoPtr->iconSize.cx;
3801 if (infoPtr->himlSmall != NULL)
3803 lprc->right += infoPtr->iconSize.cx;
3806 nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
3807 if (lprc->right + nLabelWidth < lprc->left + infoPtr->nItemWidth)
3809 lprc->right += nLabelWidth;
3813 lprc->right = lprc->left + infoPtr->nItemWidth;
3818 case LVIR_SELECTBOUNDS:
3819 if (uView == LVS_ICON)
3821 if (infoPtr->himlNormal != NULL)
3823 if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
3826 lprc->left = ptItem.x + ptOrigin.x;
3827 lprc->top = ptItem.y + ptOrigin.y;
3828 lprc->right = lprc->left + infoPtr->iconSpacing.cx;
3829 lprc->bottom = lprc->top + infoPtr->iconSpacing.cy;
3833 else if (uView == LVS_SMALLICON)
3835 if (LISTVIEW_GetOrigin(hwnd, &ptOrigin) != FALSE)
3838 nLeftPos= lprc->left = ptItem.x + ptOrigin.x;
3839 lprc->top = ptItem.y + ptOrigin.y;
3840 lprc->bottom = lprc->top + infoPtr->nItemHeight;
3842 if (infoPtr->himlState != NULL)
3844 lprc->left += infoPtr->iconSize.cx;
3847 lprc->right = lprc->left;
3849 if (infoPtr->himlSmall != NULL)
3851 lprc->right += infoPtr->iconSize.cx;
3854 nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
3855 if (lprc->right + nLabelWidth < nLeftPos + infoPtr->nItemWidth)
3857 lprc->right += nLabelWidth;
3861 lprc->right = nLeftPos + infoPtr->nItemWidth;
3868 nLeftPos = lprc->left = ptItem.x;
3869 lprc->top = ptItem.y;
3870 lprc->bottom = lprc->top + infoPtr->nItemHeight;
3872 if (infoPtr->himlState != NULL)
3874 lprc->left += infoPtr->iconSize.cx;
3877 lprc->right = lprc->left;
3879 if (infoPtr->himlSmall != NULL)
3881 lprc->right += infoPtr->iconSize.cx;
3884 nLabelWidth = LISTVIEW_GetLabelWidth(hwnd, nItem);
3885 if (lprc->right + nLabelWidth < nLeftPos + infoPtr->nItemWidth)
3887 lprc->right += nLabelWidth;
3891 lprc->right = nLeftPos + infoPtr->nItemWidth;
3904 * Retrieves the width of a label.
3907 * [I] HWND : window handle
3910 * SUCCESS : string width (in pixels)
3913 static INT LISTVIEW_GetLabelWidth(HWND hwnd, INT nItem)
3915 CHAR szDispText[DISP_TEXT_SIZE];
3916 INT nLabelWidth = 0;
3919 TRACE("(hwnd=%x, nItem=%d)\n", hwnd, nItem);
3921 ZeroMemory(&lvItem, sizeof(LVITEMA));
3922 lvItem.mask = LVIF_TEXT;
3923 lvItem.iItem = nItem;
3924 lvItem.cchTextMax = DISP_TEXT_SIZE;
3925 lvItem.pszText = szDispText;
3926 if (ListView_GetItemA(hwnd, &lvItem) != FALSE)
3928 nLabelWidth = ListView_GetStringWidthA(hwnd, lvItem.pszText);
3936 * Retrieves the spacing between listview control items.
3939 * [I] HWND : window handle
3940 * [I] BOOL : flag for small or large icon
3943 * Horizontal + vertical spacing
3945 static LRESULT LISTVIEW_GetItemSpacing(HWND hwnd, BOOL bSmall)
3947 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
3950 if (bSmall == FALSE)
3952 lResult = MAKELONG(infoPtr->iconSpacing.cx, infoPtr->iconSpacing.cy);
3956 /* TODO: need to store width of smallicon item */
3957 lResult = MAKELONG(0, infoPtr->nItemHeight);
3965 * Retrieves the state of a listview control item.
3968 * [I] HWND : window handle
3969 * [I] INT : item index
3970 * [I] UINT : state mask
3973 * State specified by the mask.
3975 static LRESULT LISTVIEW_GetItemState(HWND hwnd, INT nItem, UINT uMask)
3977 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
3981 if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
3983 ZeroMemory(&lvItem, sizeof(LVITEMA));
3984 lvItem.iItem = nItem;
3985 lvItem.stateMask = uMask;
3986 lvItem.mask = LVIF_STATE;
3987 if (ListView_GetItemA(hwnd, &lvItem) != FALSE)
3989 uState = lvItem.state;
3998 * Retrieves the text of a listview control item or subitem.
4001 * [I] HWND : window handle
4002 * [I] INT : item index
4003 * [IO] LPLVITEMA : item information
4006 * SUCCESS : string length
4009 static LRESULT LISTVIEW_GetItemTextA(HWND hwnd, INT nItem, LPLVITEMA lpLVItem)
4011 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
4014 if (lpLVItem != NULL)
4016 if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
4018 lpLVItem->mask = LVIF_TEXT;
4019 lpLVItem->iItem = nItem;
4020 if (ListView_GetItemA(hwnd, lpLVItem) != FALSE)
4022 nLength = lstrlenA(lpLVItem->pszText);
4032 * Searches for an item based on properties + relationships.
4035 * [I] HWND : window handle
4036 * [I] INT : item index
4037 * [I] INT : relationship flag
4040 * SUCCESS : item index
4043 static LRESULT LISTVIEW_GetNextItem(HWND hwnd, INT nItem, UINT uFlags)
4045 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
4046 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
4048 LVFINDINFO lvFindInfo;
4049 INT nCountPerColumn;
4052 if ((nItem >= -1) && (nItem < GETITEMCOUNT(infoPtr)))
4054 ZeroMemory(&lvFindInfo, sizeof(LVFINDINFO));
4056 if (uFlags & LVNI_CUT)
4059 if (uFlags & LVNI_DROPHILITED)
4060 uMask |= LVIS_DROPHILITED;
4062 if (uFlags & LVNI_FOCUSED)
4063 uMask |= LVIS_FOCUSED;
4065 if (uFlags & LVNI_SELECTED)
4066 uMask |= LVIS_SELECTED;
4068 if (uFlags & LVNI_ABOVE)
4070 if ((uView == LVS_LIST) || (uView == LVS_REPORT))
4075 if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
4081 lvFindInfo.flags = LVFI_NEARESTXY;
4082 lvFindInfo.vkDirection = VK_UP;
4083 ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
4084 while ((nItem = ListView_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
4086 if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
4091 else if (uFlags & LVNI_BELOW)
4093 if ((uView == LVS_LIST) || (uView == LVS_REPORT))
4095 while (nItem < GETITEMCOUNT(infoPtr))
4098 if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
4104 lvFindInfo.flags = LVFI_NEARESTXY;
4105 lvFindInfo.vkDirection = VK_DOWN;
4106 ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
4107 while ((nItem = ListView_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
4109 if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
4114 else if (uFlags & LVNI_TOLEFT)
4116 if (uView == LVS_LIST)
4118 nCountPerColumn = LISTVIEW_GetCountPerColumn(hwnd);
4119 while (nItem - nCountPerColumn >= 0)
4121 nItem -= nCountPerColumn;
4122 if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
4126 else if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
4128 lvFindInfo.flags = LVFI_NEARESTXY;
4129 lvFindInfo.vkDirection = VK_LEFT;
4130 ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
4131 while ((nItem = ListView_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
4133 if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
4138 else if (uFlags & LVNI_TORIGHT)
4140 if (uView == LVS_LIST)
4142 nCountPerColumn = LISTVIEW_GetCountPerColumn(hwnd);
4143 while (nItem + nCountPerColumn < GETITEMCOUNT(infoPtr))
4145 nItem += nCountPerColumn;
4146 if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
4150 else if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
4152 lvFindInfo.flags = LVFI_NEARESTXY;
4153 lvFindInfo.vkDirection = VK_RIGHT;
4154 ListView_GetItemPosition(hwnd, nItem, &lvFindInfo.pt);
4155 while ((nItem = ListView_FindItem(hwnd, nItem, &lvFindInfo)) != -1)
4157 if ((ListView_GetItemState(hwnd, nItem, uMask) & uMask) == uMask)
4166 /* search by index */
4167 for (i = nItem; i < GETITEMCOUNT(infoPtr); i++)
4169 if ((ListView_GetItemState(hwnd, i, uMask) & uMask) == uMask)
4178 /* LISTVIEW_GetNumberOfWorkAreas */
4182 * Retrieves the origin coordinates when in icon or small icon display mode.
4185 * [I] HWND : window handle
4186 * [O] LPPOINT : coordinate information
4192 static LRESULT LISTVIEW_GetOrigin(HWND hwnd, LPPOINT lpptOrigin)
4194 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
4195 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
4196 UINT uView = lStyle & LVS_TYPEMASK;
4197 INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
4198 INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
4199 BOOL bResult = FALSE;
4201 TRACE("(hwnd=%x, lpptOrigin=%p)\n", hwnd, lpptOrigin);
4203 if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
4205 SCROLLINFO scrollInfo;
4206 ZeroMemory(lpptOrigin, sizeof(POINT));
4207 ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
4208 scrollInfo.cbSize = sizeof(SCROLLINFO);
4210 if (lStyle & WS_HSCROLL)
4212 scrollInfo.fMask = SIF_POS;
4213 if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
4215 lpptOrigin->x = -scrollInfo.nPos * max(nListWidth / 10, 1);
4219 if (lStyle & WS_VSCROLL)
4221 scrollInfo.fMask = SIF_POS;
4222 if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) != FALSE)
4224 lpptOrigin->y = -scrollInfo.nPos * max(nListHeight / 10, 1);
4236 * Retrieves the number of items that are marked as selected.
4239 * [I] HWND : window handle
4242 * Number of items selected.
4244 static LRESULT LISTVIEW_GetSelectedCount(HWND hwnd)
4246 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
4247 INT nSelectedCount = 0;
4250 for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
4252 if (ListView_GetItemState(hwnd, i, LVIS_SELECTED) & LVIS_SELECTED)
4258 return nSelectedCount;
4263 * Retrieves item index that marks the start of a multiple selection.
4266 * [I] HWND : window handle
4269 * Index number or -1 if there is no selection mark.
4271 static LRESULT LISTVIEW_GetSelectionMark(HWND hwnd)
4273 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
4275 return infoPtr->nSelectionMark;
4280 * Retrieves the width of a string.
4283 * [I] HWND : window handle
4286 * SUCCESS : string width (in pixels)
4289 static LRESULT LISTVIEW_GetStringWidthA(HWND hwnd, LPCSTR lpszText)
4291 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
4292 HFONT hFont, hOldFont;
4296 ZeroMemory(&stringSize, sizeof(SIZE));
4297 if (lpszText != NULL)
4299 hFont = infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont;
4301 hOldFont = SelectObject(hdc, hFont);
4302 GetTextExtentPointA(hdc, lpszText, lstrlenA(lpszText), &stringSize);
4303 SelectObject(hdc, hOldFont);
4304 ReleaseDC(hwnd, hdc);
4307 return stringSize.cx;
4312 * Retrieves the text backgound color.
4315 * [I] HWND : window handle
4318 * COLORREF associated with the the background.
4320 static LRESULT LISTVIEW_GetTextBkColor(HWND hwnd)
4322 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
4324 return infoPtr->clrTextBk;
4329 * Retrieves the text color.
4332 * [I] HWND : window handle
4335 * COLORREF associated with the text.
4337 static LRESULT LISTVIEW_GetTextColor(HWND hwnd)
4339 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
4341 return infoPtr->clrText;
4346 * Determines which section of the item was selected (if any).
4349 * [I] HWND : window handle
4350 * [IO] LPLVHITTESTINFO : hit test information
4353 * SUCCESS : item index
4356 static INT LISTVIEW_HitTestItem(HWND hwnd, LPLVHITTESTINFO lpHitTestInfo)
4358 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
4362 TRACE("(hwnd=%x, x=%ld, y=%ld)\n", hwnd, lpHitTestInfo->pt.x,
4363 lpHitTestInfo->pt.y);
4365 for (i = 0; i < GETITEMCOUNT(infoPtr); i++)
4367 rcItem.left = LVIR_BOUNDS;
4368 if (LISTVIEW_GetItemRect(hwnd, i, &rcItem) != FALSE)
4370 if (PtInRect(&rcItem, lpHitTestInfo->pt) != FALSE)
4372 rcItem.left = LVIR_ICON;
4373 if (LISTVIEW_GetItemRect(hwnd, i, &rcItem) != FALSE)
4375 if (PtInRect(&rcItem, lpHitTestInfo->pt) != FALSE)
4377 lpHitTestInfo->flags = LVHT_ONITEMICON;
4378 lpHitTestInfo->iItem = i;
4379 lpHitTestInfo->iSubItem = 0;
4384 rcItem.left = LVIR_LABEL;
4385 if (LISTVIEW_GetItemRect(hwnd, i, &rcItem) != FALSE)
4387 if (PtInRect(&rcItem, lpHitTestInfo->pt) != FALSE)
4389 lpHitTestInfo->flags = LVHT_ONITEMLABEL;
4390 lpHitTestInfo->iItem = i;
4391 lpHitTestInfo->iSubItem = 0;
4396 lpHitTestInfo->flags = LVHT_ONITEMSTATEICON;
4397 lpHitTestInfo->iItem = i;
4398 lpHitTestInfo->iSubItem = 0;
4404 lpHitTestInfo->flags = LVHT_NOWHERE;
4411 * Determines which listview item is located at the specified position.
4414 * [I] HWND : window handle
4415 * [IO} LPLVHITTESTINFO : hit test information
4418 * SUCCESS : item index
4421 static LRESULT LISTVIEW_HitTest(HWND hwnd, LPLVHITTESTINFO lpHitTestInfo)
4423 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
4426 lpHitTestInfo->flags = 0;
4428 if (infoPtr->rcList.left > lpHitTestInfo->pt.x)
4430 lpHitTestInfo->flags = LVHT_TOLEFT;
4432 else if (infoPtr->rcList.right < lpHitTestInfo->pt.x)
4434 lpHitTestInfo->flags = LVHT_TORIGHT;
4436 if (infoPtr->rcList.top > lpHitTestInfo->pt.y)
4438 lpHitTestInfo->flags |= LVHT_ABOVE;
4440 else if (infoPtr->rcList.bottom < lpHitTestInfo->pt.y)
4442 lpHitTestInfo->flags |= LVHT_BELOW;
4445 if (lpHitTestInfo->flags == 0)
4447 nItem = LISTVIEW_HitTestItem(hwnd, lpHitTestInfo);
4455 * Inserts a new column.
4458 * [I] HWND : window handle
4459 * [I] INT : column index
4460 * [I] LPLVCOLUMNA : column information
4463 * SUCCESS : new column index
4466 static LRESULT LISTVIEW_InsertColumnA(HWND hwnd, INT nColumn,
4467 LPLVCOLUMNA lpColumn)
4469 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
4471 INT nNewColumn = -1;
4473 TRACE("(hwnd=%x, nColumn=%d, lpColumn=%p)\n",hwnd, nColumn,
4476 if (lpColumn != NULL)
4478 /* initialize memory */
4479 ZeroMemory(&hdi, sizeof(HDITEMA));
4481 if (lpColumn->mask & LVCF_FMT)
4483 /* format member is valid */
4484 hdi.mask |= HDI_FORMAT;
4486 /* set text alignment (leftmost column must be left-aligned) */
4489 hdi.fmt |= HDF_LEFT;
4493 if (lpColumn->fmt & LVCFMT_LEFT)
4495 hdi.fmt |= HDF_LEFT;
4497 else if (lpColumn->fmt & LVCFMT_RIGHT)
4499 hdi.fmt |= HDF_RIGHT;
4501 else if (lpColumn->fmt & LVCFMT_CENTER)
4503 hdi.fmt |= HDF_CENTER;
4507 if (lpColumn->fmt & LVCFMT_BITMAP_ON_RIGHT)
4509 hdi.fmt |= HDF_BITMAP_ON_RIGHT;
4513 if (lpColumn->fmt & LVCFMT_COL_HAS_IMAGES)
4518 if (lpColumn->fmt & LVCFMT_IMAGE)
4520 hdi.fmt |= HDF_IMAGE;
4521 hdi.iImage = I_IMAGECALLBACK;
4525 if (lpColumn->mask & LVCF_WIDTH)
4527 hdi.mask |= HDI_WIDTH;
4528 hdi.cxy = lpColumn->cx;
4531 if (lpColumn->mask & LVCF_TEXT)
4533 hdi.mask |= HDI_TEXT | HDI_FORMAT;
4534 hdi.pszText = lpColumn->pszText;
4535 hdi.cchTextMax = lstrlenA(lpColumn->pszText);
4536 hdi.fmt |= HDF_STRING;
4539 if (lpColumn->mask & LVCF_IMAGE)
4541 hdi.mask |= HDI_IMAGE;
4542 hdi.iImage = lpColumn->iImage;
4545 if (lpColumn->mask & LVCF_ORDER)
4547 hdi.mask |= HDI_ORDER;
4548 hdi.iOrder = lpColumn->iOrder;
4551 /* insert item in header control */
4552 nNewColumn = SendMessageA(infoPtr->hwndHeader, HDM_INSERTITEMA,
4553 (WPARAM)nColumn, (LPARAM)&hdi);
4555 LISTVIEW_UpdateScroll(hwnd);
4556 InvalidateRect(hwnd, NULL, FALSE);
4562 static LRESULT LISTVIEW_InsertColumnW(HWND hwnd, INT nColumn,
4563 LPLVCOLUMNW lpColumn)
4568 memcpy(&lvca,lpColumn,sizeof(lvca));
4569 if (lpColumn->mask & LVCF_TEXT)
4570 lvca.pszText = HEAP_strdupWtoA(GetProcessHeap(),0,lpColumn->pszText);
4571 lres = LISTVIEW_InsertColumnA(hwnd,nColumn,&lvca);
4572 if (lpColumn->mask & LVCF_TEXT)
4573 HeapFree(GetProcessHeap(),0,lvca.pszText);
4580 * Inserts a new item in the listview control.
4583 * [I] HWND : window handle
4584 * [I] LPLVITEMA : item information
4587 * SUCCESS : new item index
4590 static LRESULT LISTVIEW_InsertItemA(HWND hwnd, LPLVITEMA lpLVItem)
4592 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
4593 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
4594 UINT uView = lStyle & LVS_TYPEMASK;
4595 LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
4599 LISTVIEW_ITEM *lpItem = NULL;
4601 TRACE("(hwnd=%x,lpLVItem=%p)\n", hwnd, lpLVItem);
4603 if (lpLVItem != NULL)
4605 /* make sure it's not a subitem; cannot insert a subitem */
4606 if (lpLVItem->iSubItem == 0)
4608 lpItem = (LISTVIEW_ITEM *)COMCTL32_Alloc(sizeof(LISTVIEW_ITEM));
4611 ZeroMemory(lpItem, sizeof(LISTVIEW_ITEM));
4612 if (LISTVIEW_InitItem(hwnd, lpItem, lpLVItem) != FALSE)
4614 /* insert item in listview control data structure */
4615 hdpaSubItems = DPA_Create(8);
4616 if (hdpaSubItems != NULL)
4618 nItem = DPA_InsertPtr(hdpaSubItems, 0, lpItem);
4621 nItem = DPA_InsertPtr(infoPtr->hdpaItems, lpLVItem->iItem,
4625 /* manage item focus */
4626 if (lpLVItem->mask & LVIF_STATE)
4628 if (lpLVItem->stateMask & LVIS_FOCUSED)
4630 LISTVIEW_SetItemFocus(hwnd, nItem);
4634 /* send LVN_INSERTITEM notification */
4635 ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
4636 nmlv.hdr.hwndFrom = hwnd;
4637 nmlv.hdr.idFrom = lCtrlId;
4638 nmlv.hdr.code = LVN_INSERTITEM;
4640 nmlv.lParam = lpItem->lParam;;
4641 ListView_LVNotify(GetParent(hwnd), lCtrlId, &nmlv);
4643 /* align items (set position of each item) */
4644 if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
4646 if (lStyle & LVS_ALIGNLEFT)
4648 LISTVIEW_AlignLeft(hwnd);
4652 LISTVIEW_AlignTop(hwnd);
4656 LISTVIEW_UpdateScroll(hwnd);
4657 /* refresh client area */
4658 InvalidateRect(hwnd, NULL, FALSE);
4667 /* free memory if unsuccessful */
4668 if ((nItem == -1) && (lpItem != NULL))
4670 COMCTL32_Free(lpItem);
4676 static LRESULT LISTVIEW_InsertItemW(HWND hwnd, LPLVITEMW lpLVItem) {
4680 memcpy(&lvia,lpLVItem,sizeof(LVITEMA));
4681 if (lvia.mask & LVIF_TEXT) {
4682 if (lpLVItem->pszText == LPSTR_TEXTCALLBACKW)
4683 lvia.pszText = LPSTR_TEXTCALLBACKA;
4685 lvia.pszText = HEAP_strdupWtoA(GetProcessHeap(),0,lpLVItem->pszText);
4687 lres = LISTVIEW_InsertItemA(hwnd, &lvia);
4688 if (lvia.mask & LVIF_TEXT) {
4689 if (lpLVItem->pszText != LPSTR_TEXTCALLBACKW)
4690 HeapFree(GetProcessHeap(),0,lvia.pszText);
4695 /* LISTVIEW_InsertItemW */
4699 * Redraws a range of items.
4702 * [I] HWND : window handle
4703 * [I] INT : first item
4704 * [I] INT : last item
4710 static LRESULT LISTVIEW_RedrawItems(HWND hwnd, INT nFirst, INT nLast)
4712 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
4713 BOOL bResult = FALSE;
4716 if (nFirst <= nLast)
4718 if ((nFirst >= 0) && (nFirst < GETITEMCOUNT(infoPtr)))
4720 if ((nLast >= 0) && (nLast < GETITEMCOUNT(infoPtr)))
4723 InvalidateRect(hwnd, &rc, FALSE);
4731 /* LISTVIEW_Scroll */
4735 * Sets the background color.
4738 * [I] HWND : window handle
4739 * [I] COLORREF : background color
4745 static LRESULT LISTVIEW_SetBkColor(HWND hwnd, COLORREF clrBk)
4747 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
4749 infoPtr->clrBk = clrBk;
4750 InvalidateRect(hwnd, NULL, TRUE);
4755 /* LISTVIEW_SetBkImage */
4759 * Sets the callback mask. This mask will be used when the parent
4760 * window stores state information (some or all).
4763 * [I] HWND : window handle
4764 * [I] UINT : state mask
4770 static BOOL LISTVIEW_SetCallbackMask(HWND hwnd, UINT uMask)
4772 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
4774 infoPtr->uCallbackMask = uMask;
4781 * Sets the attributes of a header item.
4784 * [I] HWND : window handle
4785 * [I] INT : column index
4786 * [I] LPLVCOLUMNA : column attributes
4792 static LRESULT LISTVIEW_SetColumnA(HWND hwnd, INT nColumn,
4793 LPLVCOLUMNA lpColumn)
4795 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
4796 BOOL bResult = FALSE;
4797 HDITEMA hdi, hdiget;
4799 if ((lpColumn != NULL) && (nColumn >= 0) &&
4800 (nColumn < Header_GetItemCount(infoPtr->hwndHeader)))
4802 /* initialize memory */
4803 ZeroMemory(&hdi, sizeof(HDITEMA));
4805 if (lpColumn->mask & LVCF_FMT)
4807 /* format member is valid */
4808 hdi.mask |= HDI_FORMAT;
4810 /* get current format first */
4811 hdiget.mask = HDI_FORMAT;
4812 if (Header_GetItemA(infoPtr->hwndHeader, nColumn, &hdiget))
4813 /* preserve HDF_STRING if present */
4814 hdi.fmt = hdiget.fmt & HDF_STRING;
4816 /* set text alignment (leftmost column must be left-aligned) */
4819 hdi.fmt |= HDF_LEFT;
4823 if (lpColumn->fmt & LVCFMT_LEFT)
4825 hdi.fmt |= HDF_LEFT;
4827 else if (lpColumn->fmt & LVCFMT_RIGHT)
4829 hdi.fmt |= HDF_RIGHT;
4831 else if (lpColumn->fmt & LVCFMT_CENTER)
4833 hdi.fmt |= HDF_CENTER;
4837 if (lpColumn->fmt & LVCFMT_BITMAP_ON_RIGHT)
4839 hdi.fmt |= HDF_BITMAP_ON_RIGHT;
4842 if (lpColumn->fmt & LVCFMT_COL_HAS_IMAGES)
4844 hdi.fmt |= HDF_IMAGE;
4847 if (lpColumn->fmt & LVCFMT_IMAGE)
4849 hdi.fmt |= HDF_IMAGE;
4850 hdi.iImage = I_IMAGECALLBACK;
4854 if (lpColumn->mask & LVCF_WIDTH)
4856 hdi.mask |= HDI_WIDTH;
4857 hdi.cxy = lpColumn->cx;
4860 if (lpColumn->mask & LVCF_TEXT)
4862 hdi.mask |= HDI_TEXT | HDI_FORMAT;
4863 hdi.pszText = lpColumn->pszText;
4864 hdi.cchTextMax = lstrlenA(lpColumn->pszText);
4865 hdi.fmt |= HDF_STRING;
4868 if (lpColumn->mask & LVCF_IMAGE)
4870 hdi.mask |= HDI_IMAGE;
4871 hdi.iImage = lpColumn->iImage;
4874 if (lpColumn->mask & LVCF_ORDER)
4876 hdi.mask |= HDI_ORDER;
4877 hdi.iOrder = lpColumn->iOrder;
4880 /* set header item attributes */
4881 bResult = Header_SetItemA(infoPtr->hwndHeader, nColumn, &hdi);
4887 /* LISTVIEW_SetColumnW */
4888 /* LISTVIEW_SetColumnOrderArray */
4892 * Sets the width of a column
4895 * [I] HWND : window handle
4896 * [I] INT : column index
4897 * [I] INT : column width
4903 static LRESULT LISTVIEW_SetColumnWidth(HWND hwnd, INT iCol, INT cx)
4905 LISTVIEW_INFO *infoPtr;
4910 /* set column width only if in report mode */
4911 lStyle = GetWindowLongA(hwnd, GWL_STYLE);
4912 if ((lStyle & LVS_TYPEMASK) != LVS_REPORT)
4915 /* make sure we can get the listview info */
4916 if (!(infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0)))
4918 if (!infoPtr->hwndHeader) /* make sure we have a header */
4921 /* FIXME: currently ignoring LVSCW_AUTOSIZE (-1) and
4922 * LVSCV_AUTOSIZE_USEHEADER (-2)
4927 hdi.mask = HDI_WIDTH;
4930 /* call header to update the column change */
4931 lret = Header_SetItemA(infoPtr->hwndHeader, (WPARAM)iCol, (LPARAM)&hdi);
4933 infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
4935 InvalidateRect(hwnd, NULL, TRUE); /* force redraw of the listview */
4942 * Sets the extended listview style.
4945 * [I] HWND : window handle
4950 * SUCCESS : previous style
4953 static LRESULT LISTVIEW_SetExtendedListViewStyle(HWND hwnd, DWORD dwMask, DWORD dwStyle)
4955 LISTVIEW_INFO *infoPtr;
4958 /* make sure we can get the listview info */
4959 if (!(infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0)))
4962 /* store previous style */
4963 dwOldStyle = infoPtr->dwExStyle;
4966 infoPtr->dwExStyle = (dwOldStyle & ~dwMask) | (dwStyle & dwMask);
4968 return (dwOldStyle);
4971 /* LISTVIEW_SetHotCursor */
4975 * Sets the hot item index.
4978 * [I] HWND : window handle
4982 * SUCCESS : previous hot item index
4983 * FAILURE : -1 (no hot item)
4985 static LRESULT LISTVIEW_SetHotItem(HWND hwnd, INT iIndex)
4987 LISTVIEW_INFO *infoPtr;
4990 /* make sure we can get the listview info */
4991 if (!(infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0)))
4994 /* store previous index */
4995 iOldIndex = infoPtr->nHotItem;
4998 infoPtr->nHotItem = iIndex;
5003 /* LISTVIEW_SetIconSpacing */
5010 * [I] HWND : window handle
5011 * [I] INT : image list type
5012 * [I] HIMAGELIST : image list handle
5015 * SUCCESS : old image list
5018 static LRESULT LISTVIEW_SetImageList(HWND hwnd, INT nType, HIMAGELIST himl)
5020 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
5021 HIMAGELIST himlTemp = 0;
5026 himlTemp = infoPtr->himlNormal;
5027 infoPtr->himlNormal = himl;
5028 return (LRESULT)himlTemp;
5031 himlTemp = infoPtr->himlSmall;
5032 infoPtr->himlSmall = himl;
5033 return (LRESULT)himlTemp;
5036 himlTemp = infoPtr->himlState;
5037 infoPtr->himlState = himl;
5038 ImageList_SetBkColor(infoPtr->himlState, CLR_NONE);
5039 return (LRESULT)himlTemp;
5042 return (LRESULT)NULL;
5048 * Sets the attributes of an item.
5051 * [I] HWND : window handle
5052 * [I] LPLVITEM : item information
5058 static LRESULT LISTVIEW_SetItemA(HWND hwnd, LPLVITEMA lpLVItem)
5060 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
5061 BOOL bResult = FALSE;
5063 if (lpLVItem != NULL)
5065 if ((lpLVItem->iItem >= 0) && (lpLVItem->iItem < GETITEMCOUNT(infoPtr)))
5067 if (lpLVItem->iSubItem == 0)
5069 bResult = LISTVIEW_SetItem(hwnd, lpLVItem);
5073 bResult = LISTVIEW_SetSubItem(hwnd, lpLVItem);
5082 /* LISTVIEW_SetItemW */
5086 * Preallocates memory.
5089 * [I] HWND : window handle
5090 * [I] INT : item count (prjected number of items)
5091 * [I] DWORD : update flags
5097 static BOOL LISTVIEW_SetItemCount(HWND hwnd, INT nItems, DWORD dwFlags)
5099 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
5101 FIXME("(%d %08lx)empty stub!\n", nItems, dwFlags);
5104 return LISTVIEW_DeleteAllItems (hwnd);
5106 if (nItems > GETITEMCOUNT(infoPtr))
5109 FIXME("append items\n");
5112 else if (nItems < GETITEMCOUNT(infoPtr))
5115 FIXME("remove items\n");
5124 * Sets the position of an item.
5127 * [I] HWND : window handle
5128 * [I] INT : item index
5129 * [I] INT : x coordinate
5130 * [I] INT : y coordinate
5136 static BOOL LISTVIEW_SetItemPosition(HWND hwnd, INT nItem,
5137 INT nPosX, INT nPosY)
5139 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
5140 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
5141 LISTVIEW_ITEM *lpItem;
5143 BOOL bResult = FALSE;
5145 TRACE("(hwnd=%x,nItem=%d,X=%d,Y=%d)\n", hwnd, nItem, nPosX, nPosY);
5147 if ((nItem >= 0) || (nItem < GETITEMCOUNT(infoPtr)))
5149 if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
5151 hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem);
5152 if (hdpaSubItems != NULL)
5154 lpItem = (LISTVIEW_ITEM *)DPA_GetPtr(hdpaSubItems, 0);
5158 lpItem->ptPosition.x = nPosX;
5159 lpItem->ptPosition.y = nPosY;
5168 /* LISTVIEW_SetItemPosition32 */
5172 * Sets the state of one or many items.
5175 * [I] HWND : window handle
5176 * [I]INT : item index
5177 * [I] LPLVITEM : item or subitem info
5183 static LRESULT LISTVIEW_SetItemState(HWND hwnd, INT nItem, LPLVITEMA lpLVItem)
5185 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
5186 BOOL bResult = FALSE;
5193 ZeroMemory(&lvItem, sizeof(LVITEMA));
5194 lvItem.mask = LVIF_STATE;
5195 lvItem.state = lpLVItem->state;
5196 lvItem.stateMask = lpLVItem->stateMask ;
5198 /* apply to all items */
5199 for (i = 0; i< GETITEMCOUNT(infoPtr); i++)
5202 if (ListView_SetItemA(hwnd, &lvItem) == FALSE)
5210 ZeroMemory(&lvItem, sizeof(LVITEMA));
5211 lvItem.mask = LVIF_STATE;
5212 lvItem.state = lpLVItem->state;
5213 lvItem.stateMask = lpLVItem->stateMask;
5214 lvItem.iItem = nItem;
5215 bResult = ListView_SetItemA(hwnd, &lvItem);
5223 * Sets the text of an item or subitem.
5226 * [I] HWND : window handle
5227 * [I] INT : item index
5228 * [I] LPLVITEMA : item or subitem info
5234 static BOOL LISTVIEW_SetItemTextA(HWND hwnd, INT nItem, LPLVITEMA lpLVItem)
5236 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
5237 BOOL bResult = FALSE;
5240 if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
5242 ZeroMemory(&lvItem, sizeof(LVITEMA));
5243 lvItem.mask = LVIF_TEXT;
5244 lvItem.pszText = lpLVItem->pszText;
5245 lvItem.iItem = nItem;
5246 lvItem.iSubItem = lpLVItem->iSubItem;
5247 bResult = ListView_SetItemA(hwnd, &lvItem);
5253 /* LISTVIEW_SetItemTextW */
5257 * Set item index that marks the start of a multiple selection.
5260 * [I] HWND : window handle
5264 * Index number or -1 if there is no selection mark.
5266 static LRESULT LISTVIEW_SetSelectionMark(HWND hwnd, INT nIndex)
5268 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
5269 INT nOldIndex = infoPtr->nSelectionMark;
5271 infoPtr->nSelectionMark = nIndex;
5278 * Sets the text background color.
5281 * [I] HWND : window handle
5282 * [I] COLORREF : text background color
5288 static LRESULT LISTVIEW_SetTextBkColor(HWND hwnd, COLORREF clrTextBk)
5290 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
5292 infoPtr->clrTextBk = clrTextBk;
5293 InvalidateRect(hwnd, NULL, TRUE);
5300 * Sets the text foreground color.
5303 * [I] HWND : window handle
5304 * [I] COLORREF : text color
5310 static LRESULT LISTVIEW_SetTextColor (HWND hwnd, COLORREF clrText)
5312 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
5314 infoPtr->clrText = clrText;
5315 InvalidateRect(hwnd, NULL, TRUE);
5320 /* LISTVIEW_SetToolTips */
5321 /* LISTVIEW_SetUnicodeFormat */
5322 /* LISTVIEW_SetWorkAreas */
5326 * Callback internally used by LISTVIEW_SortItems()
5329 * [I] LPVOID : first LISTVIEW_ITEM to compare
5330 * [I] LPVOID : second LISTVIEW_ITEM to compare
5331 * [I] LPARAM : HWND of control
5334 * if first comes before second : negative
5335 * if first comes after second : positive
5336 * if first and second are equivalent : zero
5338 static INT WINAPI LISTVIEW_CallBackCompare(
5343 /* Forward the call to the client defined callback */
5344 HWND hwnd = (HWND)lParam;
5345 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
5347 return (infoPtr->pfnCompare)(
5348 ((LISTVIEW_ITEM *)first)->lParam,
5349 ((LISTVIEW_ITEM *)second)->lParam,
5350 infoPtr->lParamSort);
5355 * Sorts the listview items.
5358 * [I] HWND : window handle
5359 * [I] WPARAM : application-defined value
5360 * [I] LPARAM : pointer to comparision callback
5366 static LRESULT LISTVIEW_SortItems(HWND hwnd, WPARAM wParam, LPARAM lParam)
5368 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
5370 LISTVIEW_ITEM *lpItem;
5374 if (!infoPtr || !infoPtr->hdpaItems)
5377 nCount = GETITEMCOUNT(infoPtr);
5378 /* if there are 0 or 1 items, there is no need to sort */
5381 sortList = DPA_Create(nCount);
5383 infoPtr->pfnCompare = (PFNLVCOMPARE)lParam;
5384 infoPtr->lParamSort = (LPARAM)wParam;
5386 /* append pointers one by one to sortList */
5387 for (i = 0; i < nCount; i++)
5389 if ((hdpaSubItems = (HDPA) DPA_GetPtr(infoPtr->hdpaItems, i)))
5390 if ((lpItem = (LISTVIEW_ITEM *) DPA_GetPtr(hdpaSubItems, 0)))
5391 DPA_InsertPtr(sortList, nCount + 1, lpItem);
5394 /* sort the sortList */
5395 DPA_Sort(sortList, LISTVIEW_CallBackCompare, hwnd);
5397 /* copy the pointers back */
5398 for (i = 0; i < nCount; i++)
5400 if ((hdpaSubItems = (HDPA) DPA_GetPtr(infoPtr->hdpaItems, i)) &&
5401 (lpItem = (LISTVIEW_ITEM *) DPA_GetPtr(sortList, i)))
5402 DPA_SetPtr(hdpaSubItems, 0, lpItem);
5405 DPA_Destroy(sortList);
5411 /* LISTVIEW_SubItemHitTest */
5415 * Updates an items or rearranges the listview control.
5418 * [I] HWND : window handle
5419 * [I] INT : item index
5425 static LRESULT LISTVIEW_Update(HWND hwnd, INT nItem)
5427 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
5428 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
5429 BOOL bResult = FALSE;
5432 if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
5436 /* rearrange with default alignment style */
5437 if ((lStyle & LVS_AUTOARRANGE) && (((lStyle & LVS_TYPEMASK) == LVS_ICON) ||
5438 ((lStyle & LVS_TYPEMASK) == LVS_SMALLICON)))
5440 ListView_Arrange(hwnd, 0);
5444 /* get item bounding rectangle */
5445 rc.left = LVIR_BOUNDS;
5446 ListView_GetItemRect(hwnd, nItem, &rc);
5447 InvalidateRect(hwnd, &rc, TRUE);
5456 * Creates the listview control.
5459 * [I] HWND : window handle
5464 static LRESULT LISTVIEW_Create(HWND hwnd, WPARAM wParam, LPARAM lParam)
5466 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
5467 LPCREATESTRUCTA lpcs = (LPCREATESTRUCTA)lParam;
5468 UINT uView = lpcs->style & LVS_TYPEMASK;
5471 /* initialize info pointer */
5472 ZeroMemory(infoPtr, sizeof(LISTVIEW_INFO));
5474 /* determine the type of structures to use */
5475 infoPtr->notifyFormat = SendMessageA(GetParent(hwnd), WM_NOTIFYFORMAT,
5476 (WPARAM)hwnd, (LPARAM)NF_QUERY);
5477 if (infoPtr->notifyFormat != NFR_ANSI)
5479 FIXME("ANSI notify format is NOT used\n");
5482 /* initialize color information */
5483 infoPtr->clrBk = GetSysColor(COLOR_WINDOW);
5484 infoPtr->clrText = GetSysColor(COLOR_WINDOWTEXT);
5485 infoPtr->clrTextBk = GetSysColor(COLOR_WINDOW);
5487 /* set default values */
5488 infoPtr->uCallbackMask = 0;
5489 infoPtr->nFocusedItem = -1;
5490 infoPtr->nSelectionMark = -1;
5491 infoPtr->nHotItem = -1;
5492 infoPtr->iconSpacing.cx = GetSystemMetrics(SM_CXICONSPACING);
5493 infoPtr->iconSpacing.cy = GetSystemMetrics(SM_CYICONSPACING);
5494 ZeroMemory(&infoPtr->rcList, sizeof(RECT));
5496 /* get default font (icon title) */
5497 SystemParametersInfoA(SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
5498 infoPtr->hDefaultFont = CreateFontIndirectA(&logFont);
5499 infoPtr->hFont = infoPtr->hDefaultFont;
5502 infoPtr->hwndHeader = CreateWindowA(WC_HEADERA, (LPCSTR)NULL,
5503 WS_CHILD | HDS_HORZ | HDS_BUTTONS,
5504 0, 0, 0, 0, hwnd, (HMENU)0,
5505 lpcs->hInstance, NULL);
5507 /* set header font */
5508 SendMessageA(infoPtr->hwndHeader, WM_SETFONT, (WPARAM)infoPtr->hFont,
5511 if (uView == LVS_ICON)
5513 infoPtr->iconSize.cx = GetSystemMetrics(SM_CXICON);
5514 infoPtr->iconSize.cy = GetSystemMetrics(SM_CYICON);
5516 else if (uView == LVS_REPORT)
5518 if (!(LVS_NOCOLUMNHEADER & lpcs->style))
5520 ShowWindow(infoPtr->hwndHeader, SW_SHOWNORMAL);
5523 infoPtr->iconSize.cx = GetSystemMetrics(SM_CXSMICON);
5524 infoPtr->iconSize.cy = GetSystemMetrics(SM_CYSMICON);
5528 infoPtr->iconSize.cx = GetSystemMetrics(SM_CXSMICON);
5529 infoPtr->iconSize.cy = GetSystemMetrics(SM_CYSMICON);
5532 /* display unsupported listview window styles */
5533 LISTVIEW_UnsupportedStyles(lpcs->style);
5535 /* allocate memory for the data structure */
5536 infoPtr->hdpaItems = DPA_Create(10);
5538 /* initialize size of items */
5539 infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
5540 infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd);
5547 * Erases the background of the listview control.
5550 * [I] HWND : window handle
5551 * [I] WPARAM : device context handle
5552 * [I] LPARAM : not used
5558 static LRESULT LISTVIEW_EraseBackground(HWND hwnd, WPARAM wParam,
5561 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
5564 if (infoPtr->clrBk == CLR_NONE)
5566 bResult = SendMessageA(GetParent(hwnd), WM_ERASEBKGND, wParam, lParam);
5571 HBRUSH hBrush = CreateSolidBrush(infoPtr->clrBk);
5572 GetClientRect(hwnd, &rc);
5573 FillRect((HDC)wParam, &rc, hBrush);
5574 DeleteObject(hBrush);
5583 * Retrieves the listview control font.
5586 * [I] HWND : window handle
5591 static LRESULT LISTVIEW_GetFont(HWND hwnd)
5593 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
5595 return infoPtr->hFont;
5600 * Performs vertical scrolling.
5603 * [I] HWND : window handle
5604 * [I] INT : scroll code
5605 * [I] SHORT : current scroll position if scroll code is SB_THIMBPOSITION
5607 * [I] HWND : scrollbar control window handle
5612 static LRESULT LISTVIEW_VScroll(HWND hwnd, INT nScrollCode, SHORT nCurrentPos,
5615 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
5616 SCROLLINFO scrollInfo;
5618 ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
5619 scrollInfo.cbSize = sizeof(SCROLLINFO);
5620 scrollInfo.fMask = /*SIF_PAGE |*/ SIF_POS | SIF_RANGE;
5622 if (GetScrollInfo(hwnd, SB_VERT, &scrollInfo) != FALSE)
5624 INT nOldScrollPos = scrollInfo.nPos;
5625 switch (nScrollCode)
5628 if (scrollInfo.nPos > scrollInfo.nMin)
5635 if (scrollInfo.nPos < scrollInfo.nMax)
5642 if (scrollInfo.nPos > scrollInfo.nMin)
5646 if (uView == LVS_REPORT)
5648 nPage = LISTVIEW_GetCountPerColumn(hwnd);
5650 else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
5655 if (scrollInfo.nPos >= nPage)
5657 scrollInfo.nPos -= nPage;
5661 scrollInfo.nPos = scrollInfo.nMin;
5667 if (scrollInfo.nPos < scrollInfo.nMax)
5671 if (uView == LVS_REPORT)
5673 nPage = LISTVIEW_GetCountPerColumn(hwnd);
5675 else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
5680 if (scrollInfo.nPos <= scrollInfo.nMax - nPage)
5682 scrollInfo.nPos += nPage;
5686 scrollInfo.nPos = scrollInfo.nMax;
5691 case SB_THUMBPOSITION:
5695 if (nOldScrollPos != scrollInfo.nPos)
5697 scrollInfo.fMask = SIF_POS;
5698 SetScrollInfo(hwnd, SB_VERT, &scrollInfo, TRUE);
5699 InvalidateRect(hwnd, NULL, TRUE);
5708 * Performs horizontal scrolling.
5711 * [I] HWND : window handle
5712 * [I] INT : scroll code
5713 * [I] SHORT : current scroll position if scroll code is SB_THIMBPOSITION
5715 * [I] HWND : scrollbar control window handle
5720 static LRESULT LISTVIEW_HScroll(HWND hwnd, INT nScrollCode, SHORT nCurrentPos,
5723 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
5724 SCROLLINFO scrollInfo;
5726 ZeroMemory(&scrollInfo, sizeof(SCROLLINFO));
5727 scrollInfo.cbSize = sizeof(SCROLLINFO);
5728 scrollInfo.fMask = /*SIF_PAGE |*/ SIF_POS | SIF_RANGE;
5730 if (GetScrollInfo(hwnd, SB_HORZ, &scrollInfo) != FALSE)
5732 INT nOldScrollPos = scrollInfo.nPos;
5734 switch (nScrollCode)
5737 if (scrollInfo.nPos > scrollInfo.nMin)
5744 if (scrollInfo.nPos < scrollInfo.nMax)
5751 if (scrollInfo.nPos > scrollInfo.nMin)
5755 if (uView == LVS_LIST)
5757 nPage = LISTVIEW_GetCountPerRow(hwnd);
5759 else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
5764 if (scrollInfo.nPos >= nPage)
5766 scrollInfo.nPos -= nPage;
5770 scrollInfo.nPos = scrollInfo.nMin;
5776 if (scrollInfo.nPos < scrollInfo.nMax)
5780 if (uView == LVS_LIST)
5782 nPage = LISTVIEW_GetCountPerRow(hwnd);
5784 else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
5789 if (scrollInfo.nPos <= scrollInfo.nMax - nPage)
5791 scrollInfo.nPos += nPage;
5795 scrollInfo.nPos = scrollInfo.nMax;
5800 case SB_THUMBPOSITION:
5804 if (nOldScrollPos != scrollInfo.nPos)
5806 scrollInfo.fMask = SIF_POS;
5807 SetScrollInfo(hwnd, SB_HORZ, &scrollInfo, TRUE);
5808 InvalidateRect(hwnd, NULL, TRUE);
5820 * [I] HWND : window handle
5821 * [I] INT : virtual key
5822 * [I] LONG : key data
5827 static LRESULT LISTVIEW_KeyDown(HWND hwnd, INT nVirtualKey, LONG lKeyData)
5829 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
5830 INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
5831 HWND hwndParent = GetParent(hwnd);
5832 NMLVKEYDOWN nmKeyDown;
5835 BOOL bRedraw = FALSE;
5837 /* send LVN_KEYDOWN notification */
5838 ZeroMemory(&nmKeyDown, sizeof(NMLVKEYDOWN));
5839 nmKeyDown.hdr.hwndFrom = hwnd;
5840 nmKeyDown.hdr.idFrom = nCtrlId;
5841 nmKeyDown.hdr.code = LVN_KEYDOWN;
5842 nmKeyDown.wVKey = nVirtualKey;
5843 nmKeyDown.flags = 0;
5844 SendMessageA(hwndParent, WM_NOTIFY, (WPARAM)nCtrlId, (LPARAM)&nmKeyDown);
5847 nmh.hwndFrom = hwnd;
5848 nmh.idFrom = nCtrlId;
5850 switch (nVirtualKey)
5853 if ((GETITEMCOUNT(infoPtr) > 0) && (infoPtr->nFocusedItem != -1))
5855 /* send NM_RETURN notification */
5856 nmh.code = NM_RETURN;
5857 ListView_Notify(hwndParent, nCtrlId, &nmh);
5859 /* send LVN_ITEMACTIVATE notification */
5860 nmh.code = LVN_ITEMACTIVATE;
5861 ListView_Notify(hwndParent, nCtrlId, &nmh);
5866 if (GETITEMCOUNT(infoPtr) > 0)
5873 if (GETITEMCOUNT(infoPtr) > 0)
5875 nItem = GETITEMCOUNT(infoPtr) - 1;
5880 nItem = ListView_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_TOLEFT);
5884 nItem = ListView_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_ABOVE);
5888 nItem = ListView_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_TORIGHT);
5892 nItem = ListView_GetNextItem(hwnd, infoPtr->nFocusedItem, LVNI_BELOW);
5904 if ((nItem != -1) && (nItem != infoPtr->nFocusedItem))
5906 bRedraw = LISTVIEW_KeySelection(hwnd, nItem);
5907 if (bRedraw != FALSE)
5909 /* refresh client area */
5910 InvalidateRect(hwnd, NULL, TRUE);
5923 * [I] HWND : window handle
5928 static LRESULT LISTVIEW_KillFocus(HWND hwnd)
5930 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO*)GetWindowLongA(hwnd, 0);
5931 INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
5934 TRACE("(hwnd=%x)\n", hwnd);
5936 /* send NM_KILLFOCUS notification */
5937 nmh.hwndFrom = hwnd;
5938 nmh.idFrom = nCtrlId;
5939 nmh.code = NM_KILLFOCUS;
5940 ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
5942 /* set window focus flag */
5943 infoPtr->bFocus = FALSE;
5945 /* NEED drawing optimization ; redraw the selected items */
5946 InvalidateRect(hwnd, NULL, FALSE);
5953 * Processes double click messages (left mouse button).
5956 * [I] HWND : window handle
5957 * [I] WORD : key flag
5958 * [I] WORD : x coordinate
5959 * [I] WORD : y coordinate
5964 static LRESULT LISTVIEW_LButtonDblClk(HWND hwnd, WORD wKey, WORD wPosX,
5967 LONG nCtrlId = GetWindowLongA(hwnd, GWL_ID);
5970 TRACE("(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
5972 /* send NM_DBLCLK notification */
5973 nmh.hwndFrom = hwnd;
5974 nmh.idFrom = nCtrlId;
5975 nmh.code = NM_DBLCLK;
5976 ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
5978 /* send LVN_ITEMACTIVATE notification */
5979 nmh.code = LVN_ITEMACTIVATE;
5980 ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
5987 * Processes mouse down messages (left mouse button).
5990 * [I] HWND : window handle
5991 * [I] WORD : key flag
5992 * [I] WORD : x coordinate
5993 * [I] WORD : y coordinate
5998 static LRESULT LISTVIEW_LButtonDown(HWND hwnd, WORD wKey, WORD wPosX,
6001 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
6002 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
6003 INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
6004 static BOOL bGroupSelect = TRUE;
6009 TRACE("(hwnd=%x, key=%hu, X=%hu, Y=%hu)\n", hwnd, wKey, wPosX,
6012 /* send NM_RELEASEDCAPTURE notification */
6013 nmh.hwndFrom = hwnd;
6014 nmh.idFrom = nCtrlId;
6015 nmh.code = NM_RELEASEDCAPTURE;
6016 ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
6018 if (infoPtr->bFocus == FALSE)
6023 /* set left button down flag */
6024 infoPtr->bLButtonDown = TRUE;
6026 ptPosition.x = wPosX;
6027 ptPosition.y = wPosY;
6028 nItem = LISTVIEW_MouseSelection(hwnd, ptPosition);
6029 if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
6031 if (lStyle & LVS_SINGLESEL)
6033 LISTVIEW_SetSelection(hwnd, nItem);
6037 if ((wKey & MK_CONTROL) && (wKey & MK_SHIFT))
6039 if (bGroupSelect != FALSE)
6041 LISTVIEW_AddGroupSelection(hwnd, nItem);
6045 LISTVIEW_AddSelection(hwnd, nItem);
6048 else if (wKey & MK_CONTROL)
6050 bGroupSelect = LISTVIEW_ToggleSelection(hwnd, nItem);
6052 else if (wKey & MK_SHIFT)
6054 LISTVIEW_SetGroupSelection(hwnd, nItem);
6058 LISTVIEW_SetSelection(hwnd, nItem);
6064 /* remove all selections */
6065 LISTVIEW_RemoveSelections(hwnd, 0, GETITEMCOUNT(infoPtr));
6068 InvalidateRect(hwnd, NULL, TRUE);
6075 * Processes mouse up messages (left mouse button).
6078 * [I] HWND : window handle
6079 * [I] WORD : key flag
6080 * [I] WORD : x coordinate
6081 * [I] WORD : y coordinate
6086 static LRESULT LISTVIEW_LButtonUp(HWND hwnd, WORD wKey, WORD wPosX,
6089 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
6091 TRACE("(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
6093 if (infoPtr->bLButtonDown != FALSE)
6095 INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
6098 /* send NM_CLICK notification */
6099 nmh.hwndFrom = hwnd;
6100 nmh.idFrom = nCtrlId;
6101 nmh.code = NM_CLICK;
6102 ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
6104 /* set left button flag */
6105 infoPtr->bLButtonDown = FALSE;
6113 * Creates the listview control (called before WM_CREATE).
6116 * [I] HWND : window handle
6117 * [I] WPARAM : unhandled
6118 * [I] LPARAM : widow creation info
6123 static LRESULT LISTVIEW_NCCreate(HWND hwnd, WPARAM wParam, LPARAM lParam)
6125 LISTVIEW_INFO *infoPtr;
6127 TRACE("(hwnd=%x,wParam=%x,lParam=%lx)\n", hwnd, wParam, lParam);
6129 /* allocate memory for info structure */
6130 infoPtr = (LISTVIEW_INFO *)COMCTL32_Alloc(sizeof(LISTVIEW_INFO));
6131 SetWindowLongA(hwnd, 0, (LONG)infoPtr);
6132 if (infoPtr == NULL)
6134 ERR("could not allocate info memory!\n");
6138 if ((LISTVIEW_INFO *)GetWindowLongA(hwnd, 0) != infoPtr)
6140 ERR("pointer assignment error!\n");
6144 return DefWindowProcA(hwnd, WM_NCCREATE, wParam, lParam);
6149 * Destroys the listview control (called after WM_DESTROY).
6152 * [I] HWND : window handle
6157 static LRESULT LISTVIEW_NCDestroy(HWND hwnd)
6159 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
6161 TRACE("(hwnd=%x)\n", hwnd);
6163 /* delete all items */
6164 LISTVIEW_DeleteAllItems(hwnd);
6166 /* destroy data structure */
6167 DPA_Destroy(infoPtr->hdpaItems);
6170 infoPtr->hFont = (HFONT)0;
6171 if (infoPtr->hDefaultFont)
6173 DeleteObject(infoPtr->hDefaultFont);
6176 /* free listview info pointer*/
6177 COMCTL32_Free(infoPtr);
6184 * Handles notifications from children.
6187 * [I] HWND : window handle
6188 * [I] INT : control identifier
6189 * [I] LPNMHDR : notification information
6194 static LRESULT LISTVIEW_Notify(HWND hwnd, INT nCtrlId, LPNMHDR lpnmh)
6196 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
6198 if (lpnmh->hwndFrom == infoPtr->hwndHeader)
6200 /* handle notification from header control */
6201 if (lpnmh->code == HDN_ENDTRACKA)
6203 infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
6204 InvalidateRect(hwnd, NULL, TRUE);
6206 if(lpnmh->code == HDN_ITEMCLICKA)
6208 /* Handle sorting by Header Column */
6210 LPNMHEADERA pnmHeader = (LPNMHEADERA) lpnmh;
6211 LONG lCtrlId = GetWindowLongA(hwnd, GWL_ID);
6213 ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
6214 nmlv.hdr.hwndFrom = hwnd;
6215 nmlv.hdr.idFrom = lCtrlId;
6216 nmlv.hdr.code = LVN_COLUMNCLICK;
6218 nmlv.iSubItem = pnmHeader->iItem;
6220 ListView_LVNotify(GetParent(hwnd),lCtrlId, &nmlv);
6221 InvalidateRect(hwnd, NULL, TRUE);
6232 * Determines the type of structure to use.
6235 * [I] HWND : window handle of the sender
6236 * [I] HWND : listview window handle
6237 * [I] INT : command specifying the nature of the WM_NOTIFYFORMAT
6242 static LRESULT LISTVIEW_NotifyFormat(HWND hwndFrom, HWND hwnd, INT nCommand)
6244 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
6246 if (nCommand == NF_REQUERY)
6248 /* determine the type of structure to use */
6249 infoPtr->notifyFormat = SendMessageA(hwndFrom, WM_NOTIFYFORMAT,
6250 (WPARAM)hwnd, (LPARAM)NF_QUERY);
6251 if (infoPtr->notifyFormat == NFR_UNICODE)
6253 FIXME("NO support for unicode structures");
6262 * Paints/Repaints the listview control.
6265 * [I] HWND : window handle
6266 * [I] HDC : device context handle
6271 static LRESULT LISTVIEW_Paint(HWND hwnd, HDC hdc)
6275 TRACE("(hwnd=%x,hdc=%x)\n", hwnd, hdc);
6279 hdc = BeginPaint(hwnd, &ps);
6280 LISTVIEW_Refresh(hwnd, hdc);
6281 EndPaint(hwnd, &ps);
6285 LISTVIEW_Refresh(hwnd, hdc);
6293 * Processes double click messages (right mouse button).
6296 * [I] HWND : window handle
6297 * [I] WORD : key flag
6298 * [I] WORD : x coordinate
6299 * [I] WORD : y coordinate
6304 static LRESULT LISTVIEW_RButtonDblClk(HWND hwnd, WORD wKey, WORD wPosX,
6307 INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
6310 TRACE("(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
6312 /* send NM_RELEASEDCAPTURE notification */
6313 nmh.hwndFrom = hwnd;
6314 nmh.idFrom = nCtrlId;
6315 nmh.code = NM_RELEASEDCAPTURE;
6316 ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
6318 /* send NM_RDBLCLK notification */
6319 nmh.code = NM_RDBLCLK;
6320 ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
6327 * Processes mouse down messages (right mouse button).
6330 * [I] HWND : window handle
6331 * [I] WORD : key flag
6332 * [I] WORD : x coordinate
6333 * [I] WORD : y coordinate
6338 static LRESULT LISTVIEW_RButtonDown(HWND hwnd, WORD wKey, WORD wPosX,
6341 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
6342 INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
6347 TRACE("(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
6349 /* send NM_RELEASEDCAPTURE notification */
6350 nmh.hwndFrom = hwnd;
6351 nmh.idFrom = nCtrlId;
6352 nmh.code = NM_RELEASEDCAPTURE;
6353 ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
6355 /* make sure the listview control window has the focus */
6356 if (infoPtr->bFocus == FALSE)
6361 /* set right button down flag */
6362 infoPtr->bRButtonDown = TRUE;
6364 /* determine the index of the selected item */
6365 ptPosition.x = wPosX;
6366 ptPosition.y = wPosY;
6367 nItem = LISTVIEW_MouseSelection(hwnd, ptPosition);
6368 if ((nItem >= 0) && (nItem < GETITEMCOUNT(infoPtr)))
6370 if (!((wKey & MK_SHIFT) || (wKey & MK_CONTROL)))
6372 LISTVIEW_SetSelection(hwnd, nItem);
6377 LISTVIEW_RemoveSelections(hwnd, 0, GETITEMCOUNT(infoPtr));
6385 * Processes mouse up messages (right mouse button).
6388 * [I] HWND : window handle
6389 * [I] WORD : key flag
6390 * [I] WORD : x coordinate
6391 * [I] WORD : y coordinate
6396 static LRESULT LISTVIEW_RButtonUp(HWND hwnd, WORD wKey, WORD wPosX,
6399 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
6400 INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
6403 TRACE("(hwnd=%x,key=%hu,X=%hu,Y=%hu)\n", hwnd, wKey, wPosX, wPosY);
6405 if (infoPtr->bRButtonDown != FALSE)
6407 /* send NM_RClICK notification */
6408 ZeroMemory(&nmh, sizeof(NMHDR));
6409 nmh.hwndFrom = hwnd;
6410 nmh.idFrom = nCtrlId;
6411 nmh.code = NM_RCLICK;
6412 ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
6414 /* set button flag */
6415 infoPtr->bRButtonDown = FALSE;
6426 * [I] HWND : window handle
6427 * [I] HWND : window handle of previously focused window
6432 static LRESULT LISTVIEW_SetFocus(HWND hwnd, HWND hwndLoseFocus)
6434 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
6435 INT nCtrlId = GetWindowLongA(hwnd, GWL_ID);
6438 TRACE("(hwnd=%x, hwndLoseFocus=%x)\n", hwnd, hwndLoseFocus);
6440 /* send NM_SETFOCUS notification */
6441 nmh.hwndFrom = hwnd;
6442 nmh.idFrom = nCtrlId;
6443 nmh.code = NM_SETFOCUS;
6444 ListView_Notify(GetParent(hwnd), nCtrlId, &nmh);
6446 /* set window focus flag */
6447 infoPtr->bFocus = TRUE;
6449 InvalidateRect(hwnd, NULL, TRUE);
6460 * [I] HWND : window handle
6461 * [I] HFONT : font handle
6462 * [I] WORD : redraw flag
6467 static LRESULT LISTVIEW_SetFont(HWND hwnd, HFONT hFont, WORD fRedraw)
6469 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
6470 UINT uView = GetWindowLongA(hwnd, GWL_STYLE) & LVS_TYPEMASK;
6472 TRACE("(hwnd=%x,hfont=%x,redraw=%hu)\n", hwnd, hFont, fRedraw);
6476 infoPtr->hFont = infoPtr->hDefaultFont;
6480 infoPtr->hFont = hFont;
6483 if (uView == LVS_REPORT)
6485 /* set header font */
6486 SendMessageA(infoPtr->hwndHeader, WM_SETFONT, (WPARAM)hFont,
6487 MAKELPARAM(fRedraw, 0));
6490 /* invalidate listview control client area */
6491 InvalidateRect(hwnd, NULL, TRUE);
6493 if (fRedraw != FALSE)
6503 * Resizes the listview control. This function processes WM_SIZE
6504 * messages. At this time, the width and height are not used.
6507 * [I] HWND : window handle
6508 * [I] WORD : new width
6509 * [I] WORD : new height
6514 static LRESULT LISTVIEW_Size(HWND hwnd, int Width, int Height)
6516 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
6517 UINT uView = lStyle & LVS_TYPEMASK;
6519 TRACE("(hwnd=%x, width=%d, height=%d)\n",hwnd, Width, Height);
6521 LISTVIEW_UpdateSize(hwnd);
6523 if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
6525 if (lStyle & LVS_ALIGNLEFT)
6527 LISTVIEW_AlignLeft(hwnd);
6531 LISTVIEW_AlignTop(hwnd);
6535 LISTVIEW_UpdateScroll(hwnd);
6537 /* invalidate client area + erase background */
6538 InvalidateRect(hwnd, NULL, TRUE);
6545 * Sets the size information.
6548 * [I] HWND : window handle
6553 static VOID LISTVIEW_UpdateSize(HWND hwnd)
6555 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
6556 LONG lStyle = GetWindowLongA(hwnd, GWL_STYLE);
6557 UINT uView = lStyle & LVS_TYPEMASK;
6560 GetClientRect(hwnd, &rcList);
6561 infoPtr->rcList.left = 0;
6562 infoPtr->rcList.right = max(rcList.right - rcList.left, 1);
6563 infoPtr->rcList.top = 0;
6564 infoPtr->rcList.bottom = max(rcList.bottom - rcList.top, 1);
6566 if (uView == LVS_LIST)
6568 if ((lStyle & WS_HSCROLL) == 0)
6570 INT nHScrollHeight = GetSystemMetrics(SM_CYHSCROLL);
6571 if (infoPtr->rcList.bottom > nHScrollHeight)
6573 infoPtr->rcList.bottom -= nHScrollHeight;
6577 else if (uView == LVS_REPORT)
6584 Header_Layout(infoPtr->hwndHeader, &hl);
6585 if (!(LVS_NOCOLUMNHEADER & lStyle))
6587 infoPtr->rcList.top = max(wp.cy, 0);
6594 * Processes WM_STYLECHANGED messages.
6597 * [I] HWND : window handle
6598 * [I] WPARAM : window style type (normal or extended)
6599 * [I] LPSTYLESTRUCT : window style information
6604 static INT LISTVIEW_StyleChanged(HWND hwnd, WPARAM wStyleType,
6607 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongA(hwnd, 0);
6608 UINT uNewView = lpss->styleNew & LVS_TYPEMASK;
6609 UINT uOldView = lpss->styleOld & LVS_TYPEMASK;
6610 RECT rcList = infoPtr->rcList;
6612 TRACE("(hwnd=%x, styletype=%x, stylestruct=%p)\n",
6613 hwnd, wStyleType, lpss);
6615 if (wStyleType == GWL_STYLE)
6617 if (uOldView == LVS_REPORT)
6619 ShowWindow(infoPtr->hwndHeader, SW_HIDE);
6622 if ((lpss->styleOld & WS_HSCROLL) != 0)
6624 ShowScrollBar(hwnd, SB_HORZ, FALSE);
6627 if ((lpss->styleOld & WS_VSCROLL) != 0)
6629 ShowScrollBar(hwnd, SB_VERT, FALSE);
6632 if (uNewView == LVS_ICON)
6634 infoPtr->iconSize.cx = GetSystemMetrics(SM_CXICON);
6635 infoPtr->iconSize.cy = GetSystemMetrics(SM_CYICON);
6636 infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
6637 infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd);
6638 if (lpss->styleNew & LVS_ALIGNLEFT)
6640 LISTVIEW_AlignLeft(hwnd);
6644 LISTVIEW_AlignTop(hwnd);
6647 else if (uNewView == LVS_REPORT)
6654 Header_Layout(infoPtr->hwndHeader, &hl);
6655 SetWindowPos(infoPtr->hwndHeader, hwnd, wp.x, wp.y, wp.cx, wp.cy,
6657 if (!(LVS_NOCOLUMNHEADER & lpss->styleNew))
6659 ShowWindow(infoPtr->hwndHeader, SW_SHOWNORMAL);
6661 infoPtr->iconSize.cx = GetSystemMetrics(SM_CXSMICON);
6662 infoPtr->iconSize.cy = GetSystemMetrics(SM_CYSMICON);
6663 infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
6664 infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd);
6666 else if (uNewView == LVS_LIST)
6668 infoPtr->iconSize.cx = GetSystemMetrics(SM_CXSMICON);
6669 infoPtr->iconSize.cy = GetSystemMetrics(SM_CYSMICON);
6670 infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
6671 infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd);
6675 infoPtr->iconSize.cx = GetSystemMetrics(SM_CXSMICON);
6676 infoPtr->iconSize.cy = GetSystemMetrics(SM_CYSMICON);
6677 infoPtr->nItemWidth = LISTVIEW_GetItemWidth(hwnd);
6678 infoPtr->nItemHeight = LISTVIEW_GetItemHeight(hwnd);
6679 if (lpss->styleNew & LVS_ALIGNLEFT)
6681 LISTVIEW_AlignLeft(hwnd);
6685 LISTVIEW_AlignTop(hwnd);
6689 /* update the size of the client area */
6690 LISTVIEW_UpdateSize(hwnd);
6692 /* add scrollbars if needed */
6693 LISTVIEW_UpdateScroll(hwnd);
6695 /* invalidate client area + erase background */
6696 InvalidateRect(hwnd, NULL, TRUE);
6698 /* print the list of unsupported window styles */
6699 LISTVIEW_UnsupportedStyles(lpss->styleNew);
6707 * Window procedure of the listview control.
6710 static LRESULT WINAPI LISTVIEW_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
6715 case LVM_APPROXIMATEVIEWRECT:
6716 return LISTVIEW_ApproximateViewRect(hwnd, (INT)wParam,
6717 LOWORD(lParam), HIWORD(lParam));
6719 return LISTVIEW_Arrange(hwnd, (INT)wParam);
6721 /* case LVM_CREATEDRAGIMAGE: */
6723 case LVM_DELETEALLITEMS:
6724 return LISTVIEW_DeleteAllItems(hwnd);
6726 case LVM_DELETECOLUMN:
6727 return LISTVIEW_DeleteColumn(hwnd, (INT)wParam);
6729 case LVM_DELETEITEM:
6730 return LISTVIEW_DeleteItem(hwnd, (INT)wParam);
6732 /* case LVM_EDITLABEL: */
6734 case LVM_ENSUREVISIBLE:
6735 return LISTVIEW_EnsureVisible(hwnd, (INT)wParam, (BOOL)lParam);
6738 return LISTVIEW_FindItem(hwnd, (INT)wParam, (LPLVFINDINFO)lParam);
6740 case LVM_GETBKCOLOR:
6741 return LISTVIEW_GetBkColor(hwnd);
6743 /* case LVM_GETBKIMAGE: */
6745 case LVM_GETCALLBACKMASK:
6746 return LISTVIEW_GetCallbackMask(hwnd);
6748 case LVM_GETCOLUMNA:
6749 return LISTVIEW_GetColumnA(hwnd, (INT)wParam, (LPLVCOLUMNA)lParam);
6751 /* case LVM_GETCOLUMNW: */
6753 case LVM_GETCOLUMNORDERARRAY:
6754 FIXME("Unimplemented msg LVM_GETCOLUMNORDERARRAY\n");
6757 case LVM_GETCOLUMNWIDTH:
6758 return LISTVIEW_GetColumnWidth(hwnd, (INT)wParam);
6760 case LVM_GETCOUNTPERPAGE:
6761 return LISTVIEW_GetCountPerPage(hwnd);
6763 /* case LVM_GETEDITCONTROL: */
6765 case LVM_GETEXTENDEDLISTVIEWSTYLE:
6766 return LISTVIEW_GetExtendedListViewStyle(hwnd);
6769 return LISTVIEW_GetHeader(hwnd);
6771 /* case LVM_GETHOTCURSOR: */
6773 case LVM_GETHOTITEM:
6774 return LISTVIEW_GetHotItem(hwnd);
6776 /* case LVM_GETHOVERTIME: */
6778 case LVM_GETIMAGELIST:
6779 return LISTVIEW_GetImageList(hwnd, (INT)wParam);
6781 /* case LVM_GETISEARCHSTRING: */
6784 return LISTVIEW_GetItemA(hwnd, (LPLVITEMA)lParam);
6786 /* case LVM_GETITEMW: */
6788 case LVM_GETITEMCOUNT:
6789 return LISTVIEW_GetItemCount(hwnd);
6791 case LVM_GETITEMPOSITION:
6792 return LISTVIEW_GetItemPosition(hwnd, (INT)wParam, (LPPOINT)lParam);
6794 case LVM_GETITEMRECT:
6795 return LISTVIEW_GetItemRect(hwnd, (INT)wParam, (LPRECT)lParam);
6797 case LVM_GETITEMSPACING:
6798 return LISTVIEW_GetItemSpacing(hwnd, (BOOL)wParam);
6800 case LVM_GETITEMSTATE:
6801 return LISTVIEW_GetItemState(hwnd, (INT)wParam, (UINT)lParam);
6803 case LVM_GETITEMTEXTA:
6804 LISTVIEW_GetItemTextA(hwnd, (INT)wParam, (LPLVITEMA)lParam);
6807 /* case LVM_GETITEMTEXTW: */
6809 case LVM_GETNEXTITEM:
6810 return LISTVIEW_GetNextItem(hwnd, (INT)wParam, LOWORD(lParam));
6812 /* case LVM_GETNUMBEROFWORKAREAS: */
6815 return LISTVIEW_GetOrigin(hwnd, (LPPOINT)lParam);
6817 case LVM_GETSELECTEDCOUNT:
6818 return LISTVIEW_GetSelectedCount(hwnd);
6820 case LVM_GETSELECTIONMARK:
6821 return LISTVIEW_GetSelectionMark(hwnd);
6823 case LVM_GETSTRINGWIDTHA:
6824 return LISTVIEW_GetStringWidthA (hwnd, (LPCSTR)lParam);
6826 /* case LVM_GETSTRINGWIDTHW: */
6827 /* case LVM_GETSUBITEMRECT: */
6829 case LVM_GETTEXTBKCOLOR:
6830 return LISTVIEW_GetTextBkColor(hwnd);
6832 case LVM_GETTEXTCOLOR:
6833 return LISTVIEW_GetTextColor(hwnd);
6835 /* case LVM_GETTOOLTIPS: */
6837 case LVM_GETTOPINDEX:
6838 return LISTVIEW_GetTopIndex(hwnd);
6840 /* case LVM_GETUNICODEFORMAT: */
6842 case LVM_GETVIEWRECT:
6843 return LISTVIEW_GetViewRect(hwnd, (LPRECT)lParam);
6845 /* case LVM_GETWORKAREAS: */
6848 return LISTVIEW_HitTest(hwnd, (LPLVHITTESTINFO)lParam);
6850 case LVM_INSERTCOLUMNA:
6851 return LISTVIEW_InsertColumnA(hwnd, (INT)wParam, (LPLVCOLUMNA)lParam);
6853 case LVM_INSERTCOLUMNW:
6854 return LISTVIEW_InsertColumnW(hwnd, (INT)wParam, (LPLVCOLUMNW)lParam);
6856 case LVM_INSERTITEMA:
6857 return LISTVIEW_InsertItemA(hwnd, (LPLVITEMA)lParam);
6859 case LVM_INSERTITEMW:
6860 return LISTVIEW_InsertItemW(hwnd, (LPLVITEMW)lParam);
6862 case LVM_REDRAWITEMS:
6863 return LISTVIEW_RedrawItems(hwnd, (INT)wParam, (INT)lParam);
6865 /* case LVM_SCROLL: */
6866 /* return LISTVIEW_Scroll(hwnd, (INT)wParam, (INT)lParam); */
6868 case LVM_SETBKCOLOR:
6869 return LISTVIEW_SetBkColor(hwnd, (COLORREF)lParam);
6871 /* case LVM_SETBKIMAGE: */
6873 case LVM_SETCALLBACKMASK:
6874 return LISTVIEW_SetCallbackMask(hwnd, (UINT)wParam);
6876 case LVM_SETCOLUMNA:
6877 return LISTVIEW_SetColumnA(hwnd, (INT)wParam, (LPLVCOLUMNA)lParam);
6879 case LVM_SETCOLUMNW:
6880 FIXME("Unimplemented msg LVM_SETCOLUMNW\n");
6883 case LVM_SETCOLUMNORDERARRAY:
6884 FIXME("Unimplemented msg LVM_SETCOLUMNORDERARRAY\n");
6887 case LVM_SETCOLUMNWIDTH:
6888 return LISTVIEW_SetColumnWidth(hwnd, (INT)wParam, (INT)lParam);
6890 case LVM_SETEXTENDEDLISTVIEWSTYLE:
6891 return LISTVIEW_SetExtendedListViewStyle(hwnd, (DWORD)wParam, (DWORD)lParam);
6893 /* case LVM_SETHOTCURSOR: */
6895 case LVM_SETHOTITEM:
6896 return LISTVIEW_SetHotItem(hwnd, (INT)wParam);
6898 /* case LVM_SETHOVERTIME: */
6899 /* case LVM_SETICONSPACING: */
6901 case LVM_SETIMAGELIST:
6902 return LISTVIEW_SetImageList(hwnd, (INT)wParam, (HIMAGELIST)lParam);
6905 return LISTVIEW_SetItemA(hwnd, (LPLVITEMA)lParam);
6907 /* case LVM_SETITEMW: */
6909 case LVM_SETITEMCOUNT:
6910 return LISTVIEW_SetItemCount(hwnd, (INT)wParam, (DWORD)lParam);
6912 case LVM_SETITEMPOSITION:
6913 return LISTVIEW_SetItemPosition(hwnd, (INT)wParam, (INT)LOWORD(lParam),
6914 (INT)HIWORD(lParam));
6916 /* case LVM_SETITEMPOSITION32: */
6918 case LVM_SETITEMSTATE:
6919 return LISTVIEW_SetItemState(hwnd, (INT)wParam, (LPLVITEMA)lParam);
6921 case LVM_SETITEMTEXTA:
6922 return LISTVIEW_SetItemTextA(hwnd, (INT)wParam, (LPLVITEMA)lParam);
6924 /* case LVM_SETITEMTEXTW: */
6926 case LVM_SETSELECTIONMARK:
6927 return LISTVIEW_SetSelectionMark(hwnd, (INT)lParam);
6929 case LVM_SETTEXTBKCOLOR:
6930 return LISTVIEW_SetTextBkColor(hwnd, (COLORREF)lParam);
6932 case LVM_SETTEXTCOLOR:
6933 return LISTVIEW_SetTextColor(hwnd, (COLORREF)lParam);
6935 /* case LVM_SETTOOLTIPS: */
6936 /* case LVM_SETUNICODEFORMAT: */
6937 /* case LVM_SETWORKAREAS: */
6940 return LISTVIEW_SortItems(hwnd, wParam, lParam);
6942 /* case LVM_SUBITEMHITTEST: */
6945 return LISTVIEW_Update(hwnd, (INT)wParam);
6948 /* case WM_COMMAND: */
6951 return LISTVIEW_Create(hwnd, wParam, lParam);
6954 return LISTVIEW_EraseBackground(hwnd, wParam, lParam);
6957 return DLGC_WANTCHARS | DLGC_WANTARROWS;
6960 return LISTVIEW_GetFont(hwnd);
6963 return LISTVIEW_HScroll(hwnd, (INT)LOWORD(wParam),
6964 (INT)HIWORD(wParam), (HWND)lParam);
6967 return LISTVIEW_KeyDown(hwnd, (INT)wParam, (LONG)lParam);
6970 return LISTVIEW_KillFocus(hwnd);
6972 case WM_LBUTTONDBLCLK:
6973 return LISTVIEW_LButtonDblClk(hwnd, (WORD)wParam, LOWORD(lParam),
6976 case WM_LBUTTONDOWN:
6977 return LISTVIEW_LButtonDown(hwnd, (WORD)wParam, LOWORD(lParam),
6980 return LISTVIEW_LButtonUp(hwnd, (WORD)wParam, LOWORD(lParam),
6983 /* case WM_MOUSEMOVE: */
6984 /* return LISTVIEW_MouseMove (hwnd, wParam, lParam); */
6987 return LISTVIEW_NCCreate(hwnd, wParam, lParam);
6990 return LISTVIEW_NCDestroy(hwnd);
6993 return LISTVIEW_Notify(hwnd, (INT)wParam, (LPNMHDR)lParam);
6995 case WM_NOTIFYFORMAT:
6996 return LISTVIEW_NotifyFormat(hwnd, (HWND)wParam, (INT)lParam);
6999 return LISTVIEW_Paint(hwnd, (HDC)wParam);
7001 case WM_RBUTTONDBLCLK:
7002 return LISTVIEW_RButtonDblClk(hwnd, (WORD)wParam, LOWORD(lParam),
7005 case WM_RBUTTONDOWN:
7006 return LISTVIEW_RButtonDown(hwnd, (WORD)wParam, LOWORD(lParam),
7010 return LISTVIEW_RButtonUp(hwnd, (WORD)wParam, LOWORD(lParam),
7014 return LISTVIEW_SetFocus(hwnd, (HWND)wParam);
7017 return LISTVIEW_SetFont(hwnd, (HFONT)wParam, (WORD)lParam);
7019 /* case WM_SETREDRAW: */
7022 return LISTVIEW_Size(hwnd, (int)SLOWORD(lParam), (int)SHIWORD(lParam));
7024 case WM_STYLECHANGED:
7025 return LISTVIEW_StyleChanged(hwnd, wParam, (LPSTYLESTRUCT)lParam);
7027 /* case WM_TIMER: */
7030 return LISTVIEW_VScroll(hwnd, (INT)LOWORD(wParam),
7031 (INT)HIWORD(wParam), (HWND)lParam);
7033 /* case WM_WINDOWPOSCHANGED: */
7034 /* case WM_WININICHANGE: */
7037 if (uMsg >= WM_USER)
7039 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam,
7043 /* call default window procedure */
7044 return DefWindowProcA(hwnd, uMsg, wParam, lParam);
7052 * Registers the window class.
7060 VOID LISTVIEW_Register(void)
7064 if (!GlobalFindAtomA(WC_LISTVIEWA))
7066 ZeroMemory(&wndClass, sizeof(WNDCLASSA));
7067 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
7068 wndClass.lpfnWndProc = (WNDPROC)LISTVIEW_WindowProc;
7069 wndClass.cbClsExtra = 0;
7070 wndClass.cbWndExtra = sizeof(LISTVIEW_INFO *);
7071 wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
7072 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
7073 wndClass.lpszClassName = WC_LISTVIEWA;
7074 RegisterClassA(&wndClass);
7080 * Unregisters the window class.
7088 VOID LISTVIEW_Unregister(void)
7090 if (GlobalFindAtomA(WC_LISTVIEWA))
7092 UnregisterClassA(WC_LISTVIEWA, (HINSTANCE)NULL);