4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 1999 Luc Tourangeau
6 * Copyright 2000 Jason Mawdsley
7 * Copyright 2001 Codeweavers Inc.
8 * Copyright 2002 Dimitrie O. Paun
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * This code was audited for completeness against the documented features
27 * of Comctl32.dll version 6.0 on Oct. 21, 2002, by Dimitrie O. Paun.
29 * Unless otherwise noted, we belive this code to be complete, as per
30 * the specification mentioned above.
31 * If you discover missing features, or bugs, please note them below.
36 * -- Hot item handling, mouse hovering
37 * -- Workareas support
42 * -- Expand large item in ICON mode when the cursor is flying over the icon or text.
43 * -- Support CustonDraw options for _WIN32_IE >= 0x560 (see NMLVCUSTOMDRAW docs.
44 * -- in LISTVIEW_AddGroupSelection, se whould send LVN_ODSTATECHANGED
45 * -- LVA_SNAPTOGRID not implemented
46 * -- LISTVIEW_ApproximateViewRect partially implemented
47 * -- LISTVIEW_[GS]etColumnOrderArray stubs
48 * -- LISTVIEW_SetColumnWidth ignores header images & bitmap
49 * -- LISTVIEW_SetIconSpacing is incomplete
50 * -- LISTVIEW_SortItems is broken
51 * -- LISTVIEW_StyleChanged doesn't handle some changes too well
54 * -- LISTVIEW_GetNextItem needs to be rewritten. It is currently
55 * linear in the number of items in the list, and this is
56 * unacceptable for large lists.
57 * -- in sorted mode, LISTVIEW_InsertItemT sorts the array,
58 * instead of inserting in the right spot
59 * -- we should keep an ordered array of coordinates in iconic mode
60 * this would allow to frame items (iterator_frameditems),
61 * and find nearest item (LVFI_NEARESTXY) a lot more efficiently
69 * -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
76 * -- LVS_NOSCROLL (see Q137520)
77 * -- LVS_SORTASCENDING, LVS_SORTDESCENDING
80 * -- LVS_EX_BORDERSELECT
81 * -- LVS_EX_CHECKBOXES
84 * -- LVS_EX_HEADERDRAGDROP
87 * -- LVS_EX_MULTIWORKAREAS
88 * -- LVS_EX_ONECLICKACTIVATE
90 * -- LVS_EX_SIMPLESELECT
91 * -- LVS_EX_SUBITEMIMAGES
92 * -- LVS_EX_TRACKSELECT
93 * -- LVS_EX_TWOCLICKACTIVATE
94 * -- LVS_EX_UNDERLINECOLD
95 * -- LVS_EX_UNDERLINEHOT
98 * -- LVN_BEGINDRAG, LVN_BEGINRDRAG
99 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
102 * -- LVN_MARQUEEBEGIN
104 * -- LVN_ODSTATECHANGED
109 * -- LVM_CANCELEDITLABEL
110 * -- LVM_CREATEDRAGIMAGE
111 * -- LVM_ENABLEGROUPVIEW
112 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
113 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
114 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
115 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
116 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
117 * -- LVM_GETINSERTMARKRECT
118 * -- LVM_GETNUMBEROFWORKAREAS
119 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
120 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
121 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
122 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
123 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
124 * -- LVM_GETTOOLTIPS, LVM_SETTOOLTIPS
125 * -- LVM_GETUNICODEFORMAT, LVM_SETUNICODEFORMAT
126 * -- LVM_GETVIEW, LVM_SETVIEW
127 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
128 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
129 * -- LVM_INSERTGROUPSORTED
130 * -- LVM_INSERTMARKHITTEST
131 * -- LVM_ISGROUPVIEWENABLED
132 * -- LVM_MAPIDTOINDEX, LVM_MAPINDEXTOID
134 * -- LVM_MOVEITEMTOGROUP
136 * -- LVM_SETTILEWIDTH
140 * Known differences in message stream from native control (not known if
141 * these differences cause problems):
142 * LVM_INSERTITEM issues LVM_SETITEMSTATE and LVM_SETITEM in certain cases.
143 * LVM_SETITEM does not always issue LVN_ITEMCHANGING/LVN_ITEMCHANGED.
144 * WM_CREATE does not issue WM_QUERYUISTATE and associated registry
145 * processing for "USEDOUBLECLICKTIME".
149 #include "wine/port.h"
159 #include "commctrl.h"
160 #include "comctl32.h"
162 #include "wine/debug.h"
163 #include "wine/unicode.h"
165 WINE_DEFAULT_DEBUG_CHANNEL(listview);
167 /* make sure you set this to 0 for production use! */
168 #define DEBUG_RANGES 1
170 typedef struct tagCOLUMN_INFO
172 RECT rcHeader; /* tracks the header's rectangle */
173 int fmt; /* same as LVCOLUMN.fmt */
176 typedef struct tagITEMHDR
180 } ITEMHDR, *LPITEMHDR;
182 typedef struct tagSUBITEM_INFO
188 typedef struct tagITEM_INFO
196 typedef struct tagRANGE
202 typedef struct tagRANGES
207 typedef struct tagITERATOR
216 typedef struct tagLISTVIEW_INFO
223 COLORREF clrTextBkDefault;
224 HIMAGELIST himlNormal;
225 HIMAGELIST himlSmall;
226 HIMAGELIST himlState;
229 BOOL bNoItemMetrics; /* flags if item metrics are not yet computed */
232 RANGES selectionRanges;
236 RECT rcList; /* This rectangle is really the window
237 * client rectangle possibly reduced by the
238 * horizontal scroll bar and/or header - see
239 * LISTVIEW_UpdateSize. This rectangle offset
240 * by the LISTVIEW_GetOrigin value is in
241 * client coordinates */
250 INT ntmHeight; /* Some cached metrics of the font used */
251 INT ntmAveCharWidth; /* by the listview to draw items */
252 BOOL bRedraw; /* Turns on/off repaints & invalidations */
253 BOOL bFirstPaint; /* Flags if the control has never painted before */
254 BOOL bAutoarrange; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
256 BOOL bDoChangeNotify; /* send change notification messages? */
259 DWORD dwStyle; /* the cached window GWL_STYLE */
260 DWORD dwLvExStyle; /* extended listview style */
261 INT nItemCount; /* the number of items in the list */
262 HDPA hdpaItems; /* array ITEM_INFO pointers */
263 HDPA hdpaPosX; /* maintains the (X, Y) coordinates of the */
264 HDPA hdpaPosY; /* items in LVS_ICON, and LVS_SMALLICON modes */
265 HDPA hdpaColumns; /* array of COLUMN_INFO pointers */
266 POINT currIconPos; /* this is the position next icon will be placed */
267 PFNLVCOMPARE pfnCompare;
274 DWORD lastKeyPressTimestamp;
276 INT nSearchParamLength;
277 WCHAR szSearchParam[ MAX_PATH ];
284 /* How many we debug buffer to allocate */
285 #define DEBUG_BUFFERS 20
286 /* The size of a single debug bbuffer */
287 #define DEBUG_BUFFER_SIZE 256
289 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
290 #define SB_INTERNAL -1
292 /* maximum size of a label */
293 #define DISP_TEXT_SIZE 512
295 /* padding for items in list and small icon display modes */
296 #define WIDTH_PADDING 12
298 /* padding for items in list, report and small icon display modes */
299 #define HEIGHT_PADDING 1
301 /* offset of items in report display mode */
302 #define REPORT_MARGINX 2
304 /* padding for icon in large icon display mode
305 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
306 * that HITTEST will see.
307 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
308 * ICON_TOP_PADDING - sum of the two above.
309 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
310 * LABEL_HOR_PADDING - between text and sides of box
311 * LABEL_VERT_PADDING - between bottom of text and end of box
313 * ICON_LR_PADDING - additional width above icon size.
314 * ICON_LR_HALF - half of the above value
316 #define ICON_TOP_PADDING_NOTHITABLE 2
317 #define ICON_TOP_PADDING_HITABLE 2
318 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
319 #define ICON_BOTTOM_PADDING 4
320 #define LABEL_HOR_PADDING 5
321 #define LABEL_VERT_PADDING 7
322 #define ICON_LR_PADDING 16
323 #define ICON_LR_HALF (ICON_LR_PADDING/2)
325 /* default label width for items in list and small icon display modes */
326 #define DEFAULT_LABEL_WIDTH 40
328 /* default column width for items in list display mode */
329 #define DEFAULT_COLUMN_WIDTH 128
331 /* Size of "line" scroll for V & H scrolls */
332 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
334 /* Padding betwen image and label */
335 #define IMAGE_PADDING 2
337 /* Padding behind the label */
338 #define TRAILING_LABEL_PADDING 12
339 #define TRAILING_HEADER_PADDING 11
341 /* Border for the icon caption */
342 #define CAPTION_BORDER 2
344 /* Standard DrawText flags */
345 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
346 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
347 #define LV_SL_DT_FLAGS (DT_TOP | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
349 /* The time in milliseconds to reset the search in the list */
350 #define KEY_DELAY 450
352 /* Dump the LISTVIEW_INFO structure to the debug channel */
353 #define LISTVIEW_DUMP(iP) do { \
354 TRACE("hwndSelf=%p, clrBk=0x%06lx, clrText=0x%06lx, clrTextBk=0x%06lx, ItemHeight=%d, ItemWidth=%d, Style=0x%08lx\n", \
355 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
356 iP->nItemHeight, iP->nItemWidth, infoPtr->dwStyle); \
357 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08lx, Focus=%d\n", \
358 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
359 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
360 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%ld, icSz.cy=%ld, icSp.cx=%ld, icSp.cy=%ld, notifyFmt=%d\n", \
361 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
362 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
363 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, debugrect(&iP->rcList)); \
367 * forward declarations
369 static BOOL LISTVIEW_GetItemT(LISTVIEW_INFO *, LPLVITEMW, BOOL);
370 static void LISTVIEW_GetItemBox(LISTVIEW_INFO *, INT, LPRECT);
371 static void LISTVIEW_GetItemOrigin(LISTVIEW_INFO *, INT, LPPOINT);
372 static BOOL LISTVIEW_GetItemPosition(LISTVIEW_INFO *, INT, LPPOINT);
373 static BOOL LISTVIEW_GetItemRect(LISTVIEW_INFO *, INT, LPRECT);
374 static INT LISTVIEW_GetLabelWidth(LISTVIEW_INFO *, INT);
375 static void LISTVIEW_GetOrigin(LISTVIEW_INFO *, LPPOINT);
376 static BOOL LISTVIEW_GetViewRect(LISTVIEW_INFO *, LPRECT);
377 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO *, INT);
378 static BOOL LISTVIEW_SetItemT(LISTVIEW_INFO *, const LVITEMW *, BOOL);
379 static void LISTVIEW_UpdateScroll(LISTVIEW_INFO *);
380 static void LISTVIEW_SetSelection(LISTVIEW_INFO *, INT);
381 static void LISTVIEW_UpdateSize(LISTVIEW_INFO *);
382 static HWND LISTVIEW_EditLabelT(LISTVIEW_INFO *, INT, BOOL);
383 static LRESULT LISTVIEW_Command(LISTVIEW_INFO *, WPARAM, LPARAM);
384 static BOOL LISTVIEW_SortItems(LISTVIEW_INFO *, PFNLVCOMPARE, LPARAM);
385 static INT LISTVIEW_GetStringWidthT(LISTVIEW_INFO *, LPCWSTR, BOOL);
386 static BOOL LISTVIEW_KeySelection(LISTVIEW_INFO *, INT);
387 static UINT LISTVIEW_GetItemState(LISTVIEW_INFO *, INT, UINT);
388 static BOOL LISTVIEW_SetItemState(LISTVIEW_INFO *, INT, const LVITEMW *);
389 static LRESULT LISTVIEW_VScroll(LISTVIEW_INFO *, INT, INT, HWND);
390 static LRESULT LISTVIEW_HScroll(LISTVIEW_INFO *, INT, INT, HWND);
391 static INT LISTVIEW_GetTopIndex(LISTVIEW_INFO *);
392 static BOOL LISTVIEW_EnsureVisible(LISTVIEW_INFO *, INT, BOOL);
393 static HWND CreateEditLabelT(LISTVIEW_INFO *, LPCWSTR, DWORD, INT, INT, INT, INT, BOOL);
395 /******** Text handling functions *************************************/
397 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
398 * text string. The string may be ANSI or Unicode, in which case
399 * the boolean isW tells us the type of the string.
401 * The name of the function tell what type of strings it expects:
402 * W: Unicode, T: ANSI/Unicode - function of isW
405 static inline BOOL is_textW(LPCWSTR text)
407 return text != NULL && text != LPSTR_TEXTCALLBACKW;
410 static inline BOOL is_textT(LPCWSTR text, BOOL isW)
412 /* we can ignore isW since LPSTR_TEXTCALLBACKW == LPSTR_TEXTCALLBACKA */
413 return is_textW(text);
416 static inline int textlenT(LPCWSTR text, BOOL isW)
418 return !is_textT(text, isW) ? 0 :
419 isW ? lstrlenW(text) : lstrlenA((LPCSTR)text);
422 static inline void textcpynT(LPWSTR dest, BOOL isDestW, LPCWSTR src, BOOL isSrcW, INT max)
425 if (isSrcW) lstrcpynW(dest, src, max);
426 else MultiByteToWideChar(CP_ACP, 0, (LPCSTR)src, -1, dest, max);
428 if (isSrcW) WideCharToMultiByte(CP_ACP, 0, src, -1, (LPSTR)dest, max, NULL, NULL);
429 else lstrcpynA((LPSTR)dest, (LPCSTR)src, max);
432 static inline LPWSTR textdupTtoW(LPCWSTR text, BOOL isW)
434 LPWSTR wstr = (LPWSTR)text;
436 if (!isW && is_textT(text, isW))
438 INT len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)text, -1, NULL, 0);
439 wstr = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
440 if (wstr) MultiByteToWideChar(CP_ACP, 0, (LPCSTR)text, -1, wstr, len);
442 TRACE(" wstr=%s\n", text == LPSTR_TEXTCALLBACKW ? "(callback)" : debugstr_w(wstr));
446 static inline void textfreeT(LPWSTR wstr, BOOL isW)
448 if (!isW && is_textT(wstr, isW)) HeapFree(GetProcessHeap(), 0, wstr);
452 * dest is a pointer to a Unicode string
453 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
455 static BOOL textsetptrT(LPWSTR *dest, LPWSTR src, BOOL isW)
459 if (src == LPSTR_TEXTCALLBACKW)
461 if (is_textW(*dest)) COMCTL32_Free(*dest);
462 *dest = LPSTR_TEXTCALLBACKW;
466 LPWSTR pszText = textdupTtoW(src, isW);
467 if (*dest == LPSTR_TEXTCALLBACKW) *dest = NULL;
468 bResult = Str_SetPtrW(dest, pszText);
469 textfreeT(pszText, isW);
475 * compares a Unicode to a Unicode/ANSI text string
477 static inline int textcmpWT(LPCWSTR aw, LPCWSTR bt, BOOL isW)
479 if (!aw) return bt ? -1 : 0;
480 if (!bt) return aw ? 1 : 0;
481 if (aw == LPSTR_TEXTCALLBACKW)
482 return bt == LPSTR_TEXTCALLBACKW ? 0 : -1;
483 if (bt != LPSTR_TEXTCALLBACKW)
485 LPWSTR bw = textdupTtoW(bt, isW);
486 int r = bw ? lstrcmpW(aw, bw) : 1;
494 static inline int lstrncmpiW(LPCWSTR s1, LPCWSTR s2, int n)
498 n = min(min(n, strlenW(s1)), strlenW(s2));
499 res = CompareStringW(LOCALE_USER_DEFAULT, NORM_IGNORECASE, s1, n, s2, n);
500 return res ? res - sizeof(WCHAR) : res;
503 /******** Debugging functions *****************************************/
505 static inline LPCSTR debugtext_t(LPCWSTR text, BOOL isW)
507 if (text == LPSTR_TEXTCALLBACKW) return "(callback)";
508 return isW ? debugstr_w(text) : debugstr_a((LPCSTR)text);
511 static inline LPCSTR debugtext_tn(LPCWSTR text, BOOL isW, INT n)
513 if (text == LPSTR_TEXTCALLBACKW) return "(callback)";
514 n = min(textlenT(text, isW), n);
515 return isW ? debugstr_wn(text, n) : debugstr_an((LPCSTR)text, n);
518 static char* debug_getbuf()
520 static int index = 0;
521 static char buffers[DEBUG_BUFFERS][DEBUG_BUFFER_SIZE];
522 return buffers[index++ % DEBUG_BUFFERS];
525 static inline char* debugrange(const RANGE *lprng)
529 char* buf = debug_getbuf();
530 snprintf(buf, DEBUG_BUFFER_SIZE, "[%d, %d)", lprng->lower, lprng->upper);
532 } else return "(null)";
535 static inline char* debugpoint(const POINT *lppt)
539 char* buf = debug_getbuf();
540 snprintf(buf, DEBUG_BUFFER_SIZE, "(%ld, %ld)", lppt->x, lppt->y);
542 } else return "(null)";
545 static inline char* debugrect(const RECT *rect)
549 char* buf = debug_getbuf();
550 snprintf(buf, DEBUG_BUFFER_SIZE, "[(%ld, %ld);(%ld, %ld)]",
551 rect->left, rect->top, rect->right, rect->bottom);
553 } else return "(null)";
556 static char * debugscrollinfo(const SCROLLINFO *pScrollInfo)
558 char* buf = debug_getbuf(), *text = buf;
559 int len, size = DEBUG_BUFFER_SIZE;
561 if (pScrollInfo == NULL) return "(null)";
562 len = snprintf(buf, size, "{cbSize=%d, ", pScrollInfo->cbSize);
563 if (len == -1) goto end; buf += len; size -= len;
564 if (pScrollInfo->fMask & SIF_RANGE)
565 len = snprintf(buf, size, "nMin=%d, nMax=%d, ", pScrollInfo->nMin, pScrollInfo->nMax);
567 if (len == -1) goto end; buf += len; size -= len;
568 if (pScrollInfo->fMask & SIF_PAGE)
569 len = snprintf(buf, size, "nPage=%u, ", pScrollInfo->nPage);
571 if (len == -1) goto end; buf += len; size -= len;
572 if (pScrollInfo->fMask & SIF_POS)
573 len = snprintf(buf, size, "nPos=%d, ", pScrollInfo->nPos);
575 if (len == -1) goto end; buf += len; size -= len;
576 if (pScrollInfo->fMask & SIF_TRACKPOS)
577 len = snprintf(buf, size, "nTrackPos=%d, ", pScrollInfo->nTrackPos);
579 if (len == -1) goto end; buf += len; size -= len;
582 buf = text + strlen(text);
584 if (buf - text > 2) { buf[-2] = '}'; buf[-1] = 0; }
588 static char* debugnmlistview(const NMLISTVIEW *plvnm)
592 char* buf = debug_getbuf();
593 snprintf(buf, DEBUG_BUFFER_SIZE, "iItem=%d, iSubItem=%d, uNewState=0x%x,"
594 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld\n",
595 plvnm->iItem, plvnm->iSubItem, plvnm->uNewState, plvnm->uOldState,
596 plvnm->uChanged, debugpoint(&plvnm->ptAction), plvnm->lParam);
598 } else return "(null)";
601 static char* debuglvitem_t(const LVITEMW *lpLVItem, BOOL isW)
603 char* buf = debug_getbuf(), *text = buf;
604 int len, size = DEBUG_BUFFER_SIZE;
606 if (lpLVItem == NULL) return "(null)";
607 len = snprintf(buf, size, "{iItem=%d, iSubItem=%d, ", lpLVItem->iItem, lpLVItem->iSubItem);
608 if (len == -1) goto end; buf += len; size -= len;
609 if (lpLVItem->mask & LVIF_STATE)
610 len = snprintf(buf, size, "state=%x, stateMask=%x, ", lpLVItem->state, lpLVItem->stateMask);
612 if (len == -1) goto end; buf += len; size -= len;
613 if (lpLVItem->mask & LVIF_TEXT)
614 len = snprintf(buf, size, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem->pszText, isW, 80), lpLVItem->cchTextMax);
616 if (len == -1) goto end; buf += len; size -= len;
617 if (lpLVItem->mask & LVIF_IMAGE)
618 len = snprintf(buf, size, "iImage=%d, ", lpLVItem->iImage);
620 if (len == -1) goto end; buf += len; size -= len;
621 if (lpLVItem->mask & LVIF_PARAM)
622 len = snprintf(buf, size, "lParam=%lx, ", lpLVItem->lParam);
624 if (len == -1) goto end; buf += len; size -= len;
625 if (lpLVItem->mask & LVIF_INDENT)
626 len = snprintf(buf, size, "iIndent=%d, ", lpLVItem->iIndent);
628 if (len == -1) goto end; buf += len; size -= len;
631 buf = text + strlen(text);
633 if (buf - text > 2) { buf[-2] = '}'; buf[-1] = 0; }
637 static char* debuglvcolumn_t(const LVCOLUMNW *lpColumn, BOOL isW)
639 char* buf = debug_getbuf(), *text = buf;
640 int len, size = DEBUG_BUFFER_SIZE;
642 if (lpColumn == NULL) return "(null)";
643 len = snprintf(buf, size, "{");
644 if (len == -1) goto end; buf += len; size -= len;
645 if (lpColumn->mask & LVCF_SUBITEM)
646 len = snprintf(buf, size, "iSubItem=%d, ", lpColumn->iSubItem);
648 if (len == -1) goto end; buf += len; size -= len;
649 if (lpColumn->mask & LVCF_FMT)
650 len = snprintf(buf, size, "fmt=%x, ", lpColumn->fmt);
652 if (len == -1) goto end; buf += len; size -= len;
653 if (lpColumn->mask & LVCF_WIDTH)
654 len = snprintf(buf, size, "cx=%d, ", lpColumn->cx);
656 if (len == -1) goto end; buf += len; size -= len;
657 if (lpColumn->mask & LVCF_TEXT)
658 len = snprintf(buf, size, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn->pszText, isW, 80), lpColumn->cchTextMax);
660 if (len == -1) goto end; buf += len; size -= len;
661 if (lpColumn->mask & LVCF_IMAGE)
662 len = snprintf(buf, size, "iImage=%d, ", lpColumn->iImage);
664 if (len == -1) goto end; buf += len; size -= len;
665 if (lpColumn->mask & LVCF_ORDER)
666 len = snprintf(buf, size, "iOrder=%d, ", lpColumn->iOrder);
668 if (len == -1) goto end; buf += len; size -= len;
671 buf = text + strlen(text);
673 if (buf - text > 2) { buf[-2] = '}'; buf[-1] = 0; }
677 static char* debuglvhittestinfo(const LVHITTESTINFO *lpht)
681 char* buf = debug_getbuf();
682 snprintf(buf, DEBUG_BUFFER_SIZE, "{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
683 debugpoint(&lpht->pt), lpht->flags, lpht->iItem, lpht->iSubItem);
685 } else return "(null)";
688 /* Return the corresponding text for a given scroll value */
689 static inline LPCSTR debugscrollcode(int nScrollCode)
693 case SB_LINELEFT: return "SB_LINELEFT";
694 case SB_LINERIGHT: return "SB_LINERIGHT";
695 case SB_PAGELEFT: return "SB_PAGELEFT";
696 case SB_PAGERIGHT: return "SB_PAGERIGHT";
697 case SB_THUMBPOSITION: return "SB_THUMBPOSITION";
698 case SB_THUMBTRACK: return "SB_THUMBTRACK";
699 case SB_ENDSCROLL: return "SB_ENDSCROLL";
700 case SB_INTERNAL: return "SB_INTERNAL";
701 default: return "unknown";
706 /******** Notification functions i************************************/
708 static LRESULT notify_hdr(LISTVIEW_INFO *infoPtr, INT code, LPNMHDR pnmh)
712 TRACE("(code=%d)\n", code);
714 pnmh->hwndFrom = infoPtr->hwndSelf;
715 pnmh->idFrom = GetWindowLongW(infoPtr->hwndSelf, GWL_ID);
717 result = SendMessageW(GetParent(infoPtr->hwndSelf), WM_NOTIFY,
718 (WPARAM)pnmh->idFrom, (LPARAM)pnmh);
720 TRACE(" <= %ld\n", result);
725 static inline LRESULT notify(LISTVIEW_INFO *infoPtr, INT code)
728 return notify_hdr(infoPtr, code, &nmh);
731 static inline void notify_itemactivate(LISTVIEW_INFO *infoPtr)
733 notify(infoPtr, LVN_ITEMACTIVATE);
736 static inline LRESULT notify_listview(LISTVIEW_INFO *infoPtr, INT code, LPNMLISTVIEW plvnm)
738 TRACE("(code=%d, plvnm=%s)\n", code, debugnmlistview(plvnm));
739 return notify_hdr(infoPtr, code, (LPNMHDR)plvnm);
742 static LRESULT notify_click(LISTVIEW_INFO *infoPtr, INT code, LVHITTESTINFO *lvht)
747 TRACE("code=%d, lvht=%s\n", code, debuglvhittestinfo(lvht));
748 ZeroMemory(&nmlv, sizeof(nmlv));
749 nmlv.iItem = lvht->iItem;
750 nmlv.iSubItem = lvht->iSubItem;
751 nmlv.ptAction = lvht->pt;
752 item.mask = LVIF_PARAM;
753 item.iItem = lvht->iItem;
755 if (LISTVIEW_GetItemT(infoPtr, &item, TRUE)) nmlv.lParam = item.lParam;
756 return notify_listview(infoPtr, code, &nmlv);
759 static void notify_deleteitem(LISTVIEW_INFO *infoPtr, INT nItem)
764 ZeroMemory(&nmlv, sizeof (NMLISTVIEW));
766 item.mask = LVIF_PARAM;
769 if (LISTVIEW_GetItemT(infoPtr, &item, TRUE)) nmlv.lParam = item.lParam;
770 notify_listview(infoPtr, LVN_DELETEITEM, &nmlv);
773 static int get_ansi_notification(INT unicodeNotificationCode)
775 switch (unicodeNotificationCode)
777 case LVN_BEGINLABELEDITW: return LVN_BEGINLABELEDITA;
778 case LVN_ENDLABELEDITW: return LVN_ENDLABELEDITA;
779 case LVN_GETDISPINFOW: return LVN_GETDISPINFOA;
780 case LVN_SETDISPINFOW: return LVN_SETDISPINFOA;
781 case LVN_ODFINDITEMW: return LVN_ODFINDITEMA;
782 case LVN_GETINFOTIPW: return LVN_GETINFOTIPA;
784 ERR("unknown notification %x\n", unicodeNotificationCode);
790 With testing on Windows 2000 it looks like the notify format
791 has nothing to do with this message. It ALWAYS seems to be
794 infoPtr : listview struct
795 notificationCode : *Unicode* notification code
796 pdi : dispinfo structure (can be unicode or ansi)
797 isW : TRUE if dispinfo is Unicode
799 static BOOL notify_dispinfoT(LISTVIEW_INFO *infoPtr, INT notificationCode, LPNMLVDISPINFOW pdi, BOOL isW)
801 BOOL bResult = FALSE;
802 BOOL convertToAnsi = FALSE;
803 INT cchTempBufMax = 0, savCchTextMax = 0;
804 LPWSTR pszTempBuf = NULL, savPszText = NULL;
806 if ((pdi->item.mask & LVIF_TEXT) && is_textT(pdi->item.pszText, isW))
811 if (notificationCode != LVN_GETDISPINFOW)
813 cchTempBufMax = WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText,
814 -1, NULL, 0, NULL, NULL);
818 cchTempBufMax = pdi->item.cchTextMax;
819 *pdi->item.pszText = 0; /* make sure we don't process garbage */
822 pszTempBuf = HeapAlloc(GetProcessHeap(), 0, sizeof(CHAR) *
824 if (!pszTempBuf) return FALSE;
826 WideCharToMultiByte(CP_ACP, 0, pdi->item.pszText, -1, (LPSTR)
827 pszTempBuf, cchTempBufMax, NULL, NULL);
829 savCchTextMax = pdi->item.cchTextMax;
830 savPszText = pdi->item.pszText;
831 pdi->item.pszText = pszTempBuf;
832 pdi->item.cchTextMax = cchTempBufMax;
835 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi->item, infoPtr->notifyFormat !=
838 bResult = notify_hdr(infoPtr, get_ansi_notification(notificationCode),
843 MultiByteToWideChar(CP_ACP, 0, (LPSTR) pdi->item.pszText, -1,
844 savPszText, savCchTextMax);
845 pdi->item.pszText = savPszText; /* restores our buffer */
846 pdi->item.cchTextMax = savCchTextMax;
847 HeapFree(GetProcessHeap(), 0, pszTempBuf);
852 static void customdraw_fill(NMLVCUSTOMDRAW *lpnmlvcd, LISTVIEW_INFO *infoPtr, HDC hdc, const RECT *rcBounds)
854 ZeroMemory(lpnmlvcd, sizeof(NMLVCUSTOMDRAW));
855 lpnmlvcd->nmcd.hdc = hdc;
856 lpnmlvcd->nmcd.rc = *rcBounds;
857 lpnmlvcd->clrTextBk = infoPtr->clrTextBk;
858 lpnmlvcd->clrText = infoPtr->clrText;
861 static inline DWORD notify_customdraw (LISTVIEW_INFO *infoPtr, DWORD dwDrawStage, NMLVCUSTOMDRAW *lpnmlvcd)
863 lpnmlvcd->nmcd.dwDrawStage = dwDrawStage;
864 return notify_hdr(infoPtr, NM_CUSTOMDRAW, &lpnmlvcd->nmcd.hdr);
867 /******** Item iterator functions **********************************/
869 static RANGES ranges_create(int count);
870 static void ranges_destroy(RANGES ranges);
871 static BOOL ranges_add(RANGES ranges, RANGE range);
872 static BOOL ranges_del(RANGES ranges, RANGE range);
873 static void ranges_dump(RANGES ranges);
875 static inline BOOL ranges_additem(RANGES ranges, INT nItem)
877 RANGE range = { nItem, nItem + 1 };
879 return ranges_add(ranges, range);
882 static inline BOOL ranges_delitem(RANGES ranges, INT nItem)
884 RANGE range = { nItem, nItem + 1 };
886 return ranges_del(ranges, range);
890 * ITERATOR DOCUMENTATION
892 * The iterator functions allow for easy, and convenient iteration
893 * over items of iterest in the list. Typically, you create a
894 * iterator, use it, and destroy it, as such:
897 * iterator_xxxitems(&i, ...);
898 * while (iterator_{prev,next}(&i)
900 * //code which uses i.nItem
902 * iterator_destroy(&i);
904 * where xxx is either: framed, or visible.
905 * Note that it is important that the code destroys the iterator
906 * after it's done with it, as the creation of the iterator may
907 * allocate memory, which thus needs to be freed.
909 * You can iterate both forwards, and backwards through the list,
910 * by using iterator_next or iterator_prev respectively.
912 * Lower numbered items are draw on top of higher number items in
913 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
914 * items may overlap). So, to test items, you should use
916 * which lists the items top to bottom (in Z-order).
917 * For drawing items, you should use
919 * which lists the items bottom to top (in Z-order).
920 * If you keep iterating over the items after the end-of-items
921 * marker (-1) is returned, the iterator will start from the
922 * beginning. Typically, you don't need to test for -1,
923 * because iterator_{next,prev} will return TRUE if more items
924 * are to be iterated over, or FALSE otherwise.
926 * Note: the iterator is defined to be bidirectional. That is,
927 * any number of prev followed by any number of next, or
928 * five versa, should leave the iterator at the same item:
929 * prev * n, next * n = next * n, prev * n
931 * The iterator has a notion of a out-of-order, special item,
932 * which sits at the start of the list. This is used in
933 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
934 * which needs to be first, as it may overlap other items.
936 * The code is a bit messy because we have:
937 * - a special item to deal with
938 * - simple range, or composite range
940 * If you find bugs, or want to add features, please make sure you
941 * always check/modify *both* iterator_prev, and iterator_next.
945 * This function iterates through the items in increasing order,
946 * but prefixed by the special item, then -1. That is:
947 * special, 1, 2, 3, ..., n, -1.
948 * Each item is listed only once.
950 static inline BOOL iterator_next(ITERATOR* i)
954 i->nItem = i->nSpecial;
955 if (i->nItem != -1) return TRUE;
957 if (i->nItem == i->nSpecial)
959 if (i->ranges) i->index = 0;
965 if (i->nItem == i->nSpecial) i->nItem++;
966 if (i->nItem < i->range.upper) return TRUE;
971 if (i->index < i->ranges->hdpa->nItemCount)
972 i->range = *(RANGE*)DPA_GetPtr(i->ranges->hdpa, i->index++);
975 else if (i->nItem >= i->range.upper) goto end;
977 i->nItem = i->range.lower;
978 if (i->nItem >= 0) goto testitem;
985 * This function iterates through the items in decreasing order,
986 * followed by the special item, then -1. That is:
987 * n, n-1, ..., 3, 2, 1, special, -1.
988 * Each item is listed only once.
990 static inline BOOL iterator_prev(ITERATOR* i)
997 if (i->ranges) i->index = i->ranges->hdpa->nItemCount;
1000 if (i->nItem == i->nSpecial)
1008 if (i->nItem == i->nSpecial) i->nItem--;
1009 if (i->nItem >= i->range.lower) return TRUE;
1015 i->range = *(RANGE*)DPA_GetPtr(i->ranges->hdpa, --i->index);
1018 else if (!start && i->nItem < i->range.lower) goto end;
1020 i->nItem = i->range.upper;
1021 if (i->nItem > 0) goto testitem;
1023 return (i->nItem = i->nSpecial) != -1;
1026 static RANGE iterator_range(ITERATOR* i)
1030 if (!i->ranges) return i->range;
1032 range.lower = (*(RANGE*)DPA_GetPtr(i->ranges->hdpa, 0)).lower;
1033 range.upper = (*(RANGE*)DPA_GetPtr(i->ranges->hdpa, i->ranges->hdpa->nItemCount - 1)).upper;
1038 * Releases resources associated with this ierator.
1040 static inline void iterator_destroy(ITERATOR* i)
1042 ranges_destroy(i->ranges);
1046 * Create an empty iterator.
1048 static inline BOOL iterator_empty(ITERATOR* i)
1050 ZeroMemory(i, sizeof(*i));
1051 i->nItem = i->nSpecial = i->range.lower = i->range.upper = -1;
1056 * Create an iterator over a range.
1058 static inline BOOL iterator_rangeitems(ITERATOR* i, RANGE range)
1066 * Create an iterator over a bunch of ranges.
1067 * Please note that the iterator will take ownership of the ranges,
1068 * and will free them upon destruction.
1070 static inline BOOL iterator_rangesitems(ITERATOR* i, RANGES ranges)
1078 * Creates an iterator over the items which intersect lprc.
1080 static BOOL iterator_frameditems(ITERATOR* i, LISTVIEW_INFO* infoPtr, const RECT *lprc)
1082 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
1083 RECT frame = *lprc, rcItem, rcTemp;
1086 /* in case we fail, we want to return an empty iterator */
1087 if (!iterator_empty(i)) return FALSE;
1089 LISTVIEW_GetOrigin(infoPtr, &Origin);
1091 TRACE("(lprc=%s)\n", debugrect(lprc));
1092 OffsetRect(&frame, -Origin.x, -Origin.y);
1094 if (uView == LVS_ICON || uView == LVS_SMALLICON)
1098 if (uView == LVS_ICON && infoPtr->nFocusedItem != -1)
1100 LISTVIEW_GetItemBox(infoPtr, infoPtr->nFocusedItem, &rcItem);
1101 if (IntersectRect(&rcTemp, &rcItem, lprc))
1102 i->nSpecial = infoPtr->nFocusedItem;
1104 if (!(iterator_rangesitems(i, ranges_create(50)))) return FALSE;
1105 /* to do better here, we need to have PosX, and PosY sorted */
1106 TRACE("building icon ranges:\n");
1107 for (nItem = 0; nItem < infoPtr->nItemCount; nItem++)
1109 rcItem.left = (LONG)DPA_GetPtr(infoPtr->hdpaPosX, nItem);
1110 rcItem.top = (LONG)DPA_GetPtr(infoPtr->hdpaPosY, nItem);
1111 rcItem.right = rcItem.left + infoPtr->nItemWidth;
1112 rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
1113 if (IntersectRect(&rcTemp, &rcItem, &frame))
1114 ranges_additem(i->ranges, nItem);
1118 else if (uView == LVS_REPORT)
1122 if (frame.left >= infoPtr->nItemWidth) return TRUE;
1123 if (frame.top >= infoPtr->nItemHeight * infoPtr->nItemCount) return TRUE;
1125 range.lower = max(frame.top / infoPtr->nItemHeight, 0);
1126 range.upper = min((frame.bottom - 1) / infoPtr->nItemHeight, infoPtr->nItemCount - 1) + 1;
1127 if (range.upper <= range.lower) return TRUE;
1128 if (!iterator_rangeitems(i, range)) return FALSE;
1129 TRACE(" report=%s\n", debugrange(&i->range));
1133 INT nPerCol = max((infoPtr->rcList.bottom - infoPtr->rcList.top) / infoPtr->nItemHeight, 1);
1134 INT nFirstRow = max(frame.top / infoPtr->nItemHeight, 0);
1135 INT nLastRow = min((frame.bottom - 1) / infoPtr->nItemHeight, nPerCol - 1);
1136 INT nFirstCol = max(frame.left / infoPtr->nItemWidth, 0);
1137 INT nLastCol = min((frame.right - 1) / infoPtr->nItemWidth, (infoPtr->nItemCount + nPerCol - 1) / nPerCol);
1138 INT lower = nFirstCol * nPerCol + nFirstRow;
1142 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1143 nPerCol, nFirstRow, nLastRow, nFirstCol, nLastCol, lower);
1145 if (nLastCol < nFirstCol || nLastRow < nFirstRow) return TRUE;
1147 if (!(iterator_rangesitems(i, ranges_create(nLastCol - nFirstCol + 1)))) return FALSE;
1148 TRACE("building list ranges:\n");
1149 for (nCol = nFirstCol; nCol <= nLastCol; nCol++)
1151 item_range.lower = nCol * nPerCol + nFirstRow;
1152 if(item_range.lower >= infoPtr->nItemCount) break;
1153 item_range.upper = min(nCol * nPerCol + nLastRow + 1, infoPtr->nItemCount);
1154 TRACE(" list=%s\n", debugrange(&item_range));
1155 ranges_add(i->ranges, item_range);
1163 * Creates an iterator over the items which intersect the visible region of hdc.
1165 static BOOL iterator_visibleitems(ITERATOR *i, LISTVIEW_INFO *infoPtr, HDC hdc)
1167 POINT Origin, Position;
1168 RECT rcItem, rcClip;
1171 rgntype = GetClipBox(hdc, &rcClip);
1172 if (rgntype == NULLREGION) return iterator_empty(i);
1173 if (!iterator_frameditems(i, infoPtr, &rcClip)) return FALSE;
1174 if (rgntype == SIMPLEREGION) return TRUE;
1176 /* first deal with the special item */
1177 if (i->nSpecial != -1)
1179 LISTVIEW_GetItemBox(infoPtr, i->nSpecial, &rcItem);
1180 if (!RectVisible(hdc, &rcItem)) i->nSpecial = -1;
1183 /* if we can't deal with the region, we'll just go with the simple range */
1184 LISTVIEW_GetOrigin(infoPtr, &Origin);
1185 TRACE("building visible range:\n");
1186 if (!i->ranges && i->range.lower < i->range.upper)
1188 if (!(i->ranges = ranges_create(50))) return TRUE;
1189 if (!ranges_add(i->ranges, i->range))
1191 ranges_destroy(i->ranges);
1197 /* now delete the invisible items from the list */
1198 while(iterator_next(i))
1200 LISTVIEW_GetItemOrigin(infoPtr, i->nItem, &Position);
1201 rcItem.left = Position.x + Origin.x;
1202 rcItem.top = Position.y + Origin.y;
1203 rcItem.right = rcItem.left + infoPtr->nItemWidth;
1204 rcItem.bottom = rcItem.top + infoPtr->nItemHeight;
1205 if (!RectVisible(hdc, &rcItem))
1206 ranges_delitem(i->ranges, i->nItem);
1208 /* the iterator should restart on the next iterator_next */
1214 /******** Misc helper functions ************************************/
1216 static inline LRESULT CallWindowProcT(WNDPROC proc, HWND hwnd, UINT uMsg,
1217 WPARAM wParam, LPARAM lParam, BOOL isW)
1219 if (isW) return CallWindowProcW(proc, hwnd, uMsg, wParam, lParam);
1220 else return CallWindowProcA(proc, hwnd, uMsg, wParam, lParam);
1223 static inline BOOL is_autoarrange(LISTVIEW_INFO *infoPtr)
1225 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
1227 return ((infoPtr->dwStyle & LVS_AUTOARRANGE) || infoPtr->bAutoarrange) &&
1228 (uView == LVS_ICON || uView == LVS_SMALLICON);
1231 /******** Internal API functions ************************************/
1233 static inline COLUMN_INFO * LISTVIEW_GetColumnInfo(LISTVIEW_INFO *infoPtr, INT nSubItem)
1235 static COLUMN_INFO mainItem;
1237 if (nSubItem == 0 && infoPtr->hdpaColumns->nItemCount == 0) return &mainItem;
1238 assert (nSubItem >= 0 && nSubItem < infoPtr->hdpaColumns->nItemCount);
1239 return (COLUMN_INFO *)DPA_GetPtr(infoPtr->hdpaColumns, nSubItem);
1242 static inline void LISTVIEW_GetHeaderRect(LISTVIEW_INFO *infoPtr, INT nSubItem, RECT *lprc)
1244 *lprc = LISTVIEW_GetColumnInfo(infoPtr, nSubItem)->rcHeader;
1247 static inline BOOL LISTVIEW_GetItemW(LISTVIEW_INFO *infoPtr, LPLVITEMW lpLVItem)
1249 return LISTVIEW_GetItemT(infoPtr, lpLVItem, TRUE);
1252 /* Listview invalidation functions: use _only_ these functions to invalidate */
1254 static inline BOOL is_redrawing(LISTVIEW_INFO *infoPtr)
1256 return infoPtr->bRedraw && !infoPtr->bFirstPaint;
1259 static inline void LISTVIEW_InvalidateRect(LISTVIEW_INFO *infoPtr, const RECT* rect)
1261 if(!is_redrawing(infoPtr)) return;
1262 TRACE(" invalidating rect=%s\n", debugrect(rect));
1263 InvalidateRect(infoPtr->hwndSelf, rect, TRUE);
1266 static inline void LISTVIEW_InvalidateItem(LISTVIEW_INFO *infoPtr, INT nItem)
1270 if(!is_redrawing(infoPtr)) return;
1271 LISTVIEW_GetItemBox(infoPtr, nItem, &rcBox);
1272 LISTVIEW_InvalidateRect(infoPtr, &rcBox);
1275 static inline void LISTVIEW_InvalidateSubItem(LISTVIEW_INFO *infoPtr, INT nItem, INT nSubItem)
1277 POINT Origin, Position;
1280 if(!is_redrawing(infoPtr)) return;
1281 assert ((infoPtr->dwStyle & LVS_TYPEMASK) == LVS_REPORT);
1282 LISTVIEW_GetOrigin(infoPtr, &Origin);
1283 LISTVIEW_GetItemOrigin(infoPtr, nItem, &Position);
1284 LISTVIEW_GetHeaderRect(infoPtr, nSubItem, &rcBox);
1286 rcBox.bottom = infoPtr->nItemHeight;
1287 OffsetRect(&rcBox, Origin.x + Position.x, Origin.y + Position.y);
1288 LISTVIEW_InvalidateRect(infoPtr, &rcBox);
1291 static inline void LISTVIEW_InvalidateList(LISTVIEW_INFO *infoPtr)
1293 LISTVIEW_InvalidateRect(infoPtr, NULL);
1296 static inline void LISTVIEW_InvalidateColumn(LISTVIEW_INFO *infoPtr, INT nColumn)
1300 if(!is_redrawing(infoPtr)) return;
1301 LISTVIEW_GetHeaderRect(infoPtr, nColumn, &rcCol);
1302 rcCol.top = infoPtr->rcList.top;
1303 rcCol.bottom = infoPtr->rcList.bottom;
1304 LISTVIEW_InvalidateRect(infoPtr, &rcCol);
1309 * Retrieves the number of items that can fit vertically in the client area.
1312 * [I] infoPtr : valid pointer to the listview structure
1315 * Number of items per row.
1317 static inline INT LISTVIEW_GetCountPerRow(LISTVIEW_INFO *infoPtr)
1319 INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
1321 return max(nListWidth/infoPtr->nItemWidth, 1);
1326 * Retrieves the number of items that can fit horizontally in the client
1330 * [I] infoPtr : valid pointer to the listview structure
1333 * Number of items per column.
1335 static inline INT LISTVIEW_GetCountPerColumn(LISTVIEW_INFO *infoPtr)
1337 INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
1339 return max(nListHeight / infoPtr->nItemHeight, 1);
1343 /*************************************************************************
1344 * LISTVIEW_ProcessLetterKeys
1346 * Processes keyboard messages generated by pressing the letter keys
1348 * What this does is perform a case insensitive search from the
1349 * current position with the following quirks:
1350 * - If two chars or more are pressed in quick succession we search
1351 * for the corresponding string (e.g. 'abc').
1352 * - If there is a delay we wipe away the current search string and
1353 * restart with just that char.
1354 * - If the user keeps pressing the same character, whether slowly or
1355 * fast, so that the search string is entirely composed of this
1356 * character ('aaaaa' for instance), then we search for first item
1357 * that starting with that character.
1358 * - If the user types the above character in quick succession, then
1359 * we must also search for the corresponding string ('aaaaa'), and
1360 * go to that string if there is a match.
1363 * [I] hwnd : handle to the window
1364 * [I] charCode : the character code, the actual character
1365 * [I] keyData : key data
1373 * - The current implementation has a list of characters it will
1374 * accept and it ignores averything else. In particular it will
1375 * ignore accentuated characters which seems to match what
1376 * Windows does. But I'm not sure it makes sense to follow
1378 * - We don't sound a beep when the search fails.
1382 * TREEVIEW_ProcessLetterKeys
1384 static INT LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO *infoPtr, WPARAM charCode, LPARAM keyData)
1389 WCHAR buffer[MAX_PATH];
1390 DWORD lastKeyPressTimestamp = infoPtr->lastKeyPressTimestamp;
1392 /* simple parameter checking */
1393 if (!charCode || !keyData) return 0;
1395 /* only allow the valid WM_CHARs through */
1396 if (!isalnum(charCode) &&
1397 charCode != '.' && charCode != '`' && charCode != '!' &&
1398 charCode != '@' && charCode != '#' && charCode != '$' &&
1399 charCode != '%' && charCode != '^' && charCode != '&' &&
1400 charCode != '*' && charCode != '(' && charCode != ')' &&
1401 charCode != '-' && charCode != '_' && charCode != '+' &&
1402 charCode != '=' && charCode != '\\'&& charCode != ']' &&
1403 charCode != '}' && charCode != '[' && charCode != '{' &&
1404 charCode != '/' && charCode != '?' && charCode != '>' &&
1405 charCode != '<' && charCode != ',' && charCode != '~')
1408 /* if there's one item or less, there is no where to go */
1409 if (infoPtr->nItemCount <= 1) return 0;
1411 /* update the search parameters */
1412 infoPtr->lastKeyPressTimestamp = GetTickCount();
1413 if (infoPtr->lastKeyPressTimestamp - lastKeyPressTimestamp < KEY_DELAY) {
1414 if (infoPtr->nSearchParamLength < MAX_PATH)
1415 infoPtr->szSearchParam[infoPtr->nSearchParamLength++]=charCode;
1416 if (infoPtr->charCode != charCode)
1417 infoPtr->charCode = charCode = 0;
1419 infoPtr->charCode=charCode;
1420 infoPtr->szSearchParam[0]=charCode;
1421 infoPtr->nSearchParamLength=1;
1422 /* Redundant with the 1 char string */
1426 /* and search from the current position */
1428 if (infoPtr->nFocusedItem >= 0) {
1429 endidx=infoPtr->nFocusedItem;
1431 /* if looking for single character match,
1432 * then we must always move forward
1434 if (infoPtr->nSearchParamLength == 1)
1437 endidx=infoPtr->nItemCount;
1441 if (idx == infoPtr->nItemCount) {
1442 if (endidx == infoPtr->nItemCount || endidx == 0)
1448 item.mask = LVIF_TEXT;
1451 item.pszText = buffer;
1452 item.cchTextMax = MAX_PATH;
1453 if (!LISTVIEW_GetItemW(infoPtr, &item)) return 0;
1455 /* check for a match */
1456 if (lstrncmpiW(item.pszText,infoPtr->szSearchParam,infoPtr->nSearchParamLength) == 0) {
1459 } else if ( (charCode != 0) && (nItem == -1) && (nItem != infoPtr->nFocusedItem) &&
1460 (lstrncmpiW(item.pszText,infoPtr->szSearchParam,1) == 0) ) {
1461 /* This would work but we must keep looking for a longer match */
1465 } while (idx != endidx);
1468 LISTVIEW_KeySelection(infoPtr, nItem);
1473 /*************************************************************************
1474 * LISTVIEW_UpdateHeaderSize [Internal]
1476 * Function to resize the header control
1479 * [I] hwnd : handle to a window
1480 * [I] nNewScrollPos : scroll pos to set
1485 static void LISTVIEW_UpdateHeaderSize(LISTVIEW_INFO *infoPtr, INT nNewScrollPos)
1490 TRACE("nNewScrollPos=%d\n", nNewScrollPos);
1492 GetWindowRect(infoPtr->hwndHeader, &winRect);
1493 point[0].x = winRect.left;
1494 point[0].y = winRect.top;
1495 point[1].x = winRect.right;
1496 point[1].y = winRect.bottom;
1498 MapWindowPoints(HWND_DESKTOP, infoPtr->hwndSelf, point, 2);
1499 point[0].x = -nNewScrollPos;
1500 point[1].x += nNewScrollPos;
1502 SetWindowPos(infoPtr->hwndHeader,0,
1503 point[0].x,point[0].y,point[1].x,point[1].y,
1504 SWP_NOZORDER | SWP_NOACTIVATE);
1509 * Update the scrollbars. This functions should be called whenever
1510 * the content, size or view changes.
1513 * [I] infoPtr : valid pointer to the listview structure
1518 static void LISTVIEW_UpdateScroll(LISTVIEW_INFO *infoPtr)
1520 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
1521 SCROLLINFO horzInfo, vertInfo;
1523 if ((infoPtr->dwStyle & LVS_NOSCROLL) || !is_redrawing(infoPtr)) return;
1525 ZeroMemory(&horzInfo, sizeof(SCROLLINFO));
1526 horzInfo.cbSize = sizeof(SCROLLINFO);
1527 horzInfo.nPage = infoPtr->rcList.right - infoPtr->rcList.left;
1529 /* for now, we'll set info.nMax to the _count_, and adjust it later */
1530 if (uView == LVS_LIST)
1532 INT nPerCol = LISTVIEW_GetCountPerColumn(infoPtr);
1533 horzInfo.nMax = (infoPtr->nItemCount + nPerCol - 1) / nPerCol;
1535 /* scroll by at least one column per page */
1536 if(horzInfo.nPage < infoPtr->nItemWidth)
1537 horzInfo.nPage = infoPtr->nItemWidth;
1539 horzInfo.nPage /= infoPtr->nItemWidth;
1541 else if (uView == LVS_REPORT)
1543 horzInfo.nMax = infoPtr->nItemWidth;
1545 else /* LVS_ICON, or LVS_SMALLICON */
1549 if (LISTVIEW_GetViewRect(infoPtr, &rcView)) horzInfo.nMax = rcView.right - rcView.left;
1552 horzInfo.fMask = SIF_RANGE | SIF_PAGE;
1553 horzInfo.nMax = max(horzInfo.nMax - 1, 0);
1554 SetScrollInfo(infoPtr->hwndSelf, SB_HORZ, &horzInfo, TRUE);
1555 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo));
1557 /* Setting the horizontal scroll can change the listview size
1558 * (and potentially everything else) so we need to recompute
1559 * everything again for the vertical scroll
1562 ZeroMemory(&vertInfo, sizeof(SCROLLINFO));
1563 vertInfo.cbSize = sizeof(SCROLLINFO);
1564 vertInfo.nPage = infoPtr->rcList.bottom - infoPtr->rcList.top;
1566 if (uView == LVS_REPORT)
1568 vertInfo.nMax = infoPtr->nItemCount;
1570 /* scroll by at least one page */
1571 if(vertInfo.nPage < infoPtr->nItemHeight)
1572 vertInfo.nPage = infoPtr->nItemHeight;
1574 vertInfo.nPage /= infoPtr->nItemHeight;
1576 else if (uView != LVS_LIST) /* LVS_ICON, or LVS_SMALLICON */
1580 if (LISTVIEW_GetViewRect(infoPtr, &rcView)) vertInfo.nMax = rcView.bottom - rcView.top;
1583 vertInfo.fMask = SIF_RANGE | SIF_PAGE;
1584 vertInfo.nMax = max(vertInfo.nMax - 1, 0);
1585 SetScrollInfo(infoPtr->hwndSelf, SB_VERT, &vertInfo, TRUE);
1586 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo));
1588 /* Update the Header Control */
1589 if (uView == LVS_REPORT)
1591 horzInfo.fMask = SIF_POS;
1592 GetScrollInfo(infoPtr->hwndSelf, SB_HORZ, &horzInfo);
1593 LISTVIEW_UpdateHeaderSize(infoPtr, horzInfo.nPos);
1600 * Shows/hides the focus rectangle.
1603 * [I] infoPtr : valid pointer to the listview structure
1604 * [I] fShow : TRUE to show the focus, FALSE to hide it.
1609 static void LISTVIEW_ShowFocusRect(LISTVIEW_INFO *infoPtr, BOOL fShow)
1611 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
1614 TRACE("fShow=%d, nItem=%d\n", fShow, infoPtr->nFocusedItem);
1616 if (infoPtr->nFocusedItem < 0) return;
1618 /* we need some gymnastics in ICON mode to handle large items */
1619 if ( (infoPtr->dwStyle & LVS_TYPEMASK) == LVS_ICON )
1623 LISTVIEW_GetItemBox(infoPtr, infoPtr->nFocusedItem, &rcBox);
1624 if ((rcBox.bottom - rcBox.top) > infoPtr->nItemHeight)
1626 LISTVIEW_InvalidateRect(infoPtr, &rcBox);
1631 if (!(hdc = GetDC(infoPtr->hwndSelf))) return;
1633 /* for some reason, owner draw should work only in report mode */
1634 if ((infoPtr->dwStyle & LVS_OWNERDRAWFIXED) && (uView == LVS_REPORT))
1639 item.iItem = infoPtr->nFocusedItem;
1641 item.mask = LVIF_PARAM;
1642 if (!LISTVIEW_GetItemW(infoPtr, &item)) goto done;
1644 ZeroMemory(&dis, sizeof(dis));
1645 dis.CtlType = ODT_LISTVIEW;
1646 dis.CtlID = GetWindowLongW(infoPtr->hwndSelf, GWL_ID);
1647 dis.itemID = item.iItem;
1648 dis.itemAction = ODA_FOCUS;
1649 if (fShow) dis.itemState |= ODS_FOCUS;
1650 dis.hwndItem = infoPtr->hwndSelf;
1652 LISTVIEW_GetItemBox(infoPtr, dis.itemID, &dis.rcItem);
1653 dis.itemData = item.lParam;
1655 SendMessageW(GetParent(infoPtr->hwndSelf), WM_DRAWITEM, dis.CtlID, (LPARAM)&dis);
1659 DrawFocusRect(hdc, &infoPtr->rcFocus);
1662 ReleaseDC(infoPtr->hwndSelf, hdc);
1666 * Invalidates all visible selected items.
1668 static void LISTVIEW_InvalidateSelectedItems(LISTVIEW_INFO *infoPtr)
1672 iterator_frameditems(&i, infoPtr, &infoPtr->rcList);
1673 while(iterator_next(&i))
1675 if (LISTVIEW_GetItemState(infoPtr, i.nItem, LVIS_SELECTED))
1676 LISTVIEW_InvalidateItem(infoPtr, i.nItem);
1678 iterator_destroy(&i);
1683 * DESCRIPTION: [INTERNAL]
1684 * Computes an item's (left,top) corner, relative to rcView.
1685 * That is, the position has NOT been made relative to the Origin.
1686 * This is deliberate, to avoid computing the Origin over, and
1687 * over again, when this function is call in a loop. Instead,
1688 * one ca factor the computation of the Origin before the loop,
1689 * and offset the value retured by this function, on every iteration.
1692 * [I] infoPtr : valid pointer to the listview structure
1693 * [I] nItem : item number
1694 * [O] lpptOrig : item top, left corner
1699 static void LISTVIEW_GetItemOrigin(LISTVIEW_INFO *infoPtr, INT nItem, LPPOINT lpptPosition)
1701 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
1703 assert(nItem >= 0 && nItem < infoPtr->nItemCount);
1705 if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
1707 lpptPosition->x = (LONG)DPA_GetPtr(infoPtr->hdpaPosX, nItem);
1708 lpptPosition->y = (LONG)DPA_GetPtr(infoPtr->hdpaPosY, nItem);
1710 else if (uView == LVS_LIST)
1712 INT nCountPerColumn = LISTVIEW_GetCountPerColumn(infoPtr);
1713 lpptPosition->x = nItem / nCountPerColumn * infoPtr->nItemWidth;
1714 lpptPosition->y = nItem % nCountPerColumn * infoPtr->nItemHeight;
1716 else /* LVS_REPORT */
1718 lpptPosition->x = 0;
1719 lpptPosition->y = nItem * infoPtr->nItemHeight;
1724 * DESCRIPTION: [INTERNAL]
1725 * Compute the rectangles of an item. This is to localize all
1726 * the computations in one place. If you are not interested in some
1727 * of these values, simply pass in a NULL -- the fucntion is smart
1728 * enough to compute only what's necessary. The function computes
1729 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
1730 * one, the BOX rectangle. This rectangle is very cheap to compute,
1731 * and is guaranteed to contain all the other rectangles. Computing
1732 * the ICON rect is also cheap, but all the others are potentaily
1733 * expensive. This gives an easy and effective optimization when
1734 * searching (like point inclusion, or rectangle intersection):
1735 * first test against the BOX, and if TRUE, test agains the desired
1737 * If the function does not have all the necessary information
1738 * to computed the requested rectangles, will crash with a
1739 * failed assertion. This is done so we catch all programming
1740 * errors, given that the function is called only from our code.
1742 * We have the following 'special' meanings for a few fields:
1743 * * If LVIS_FOCUSED is set, we assume the item has the focus
1744 * This is important in ICON mode, where it might get a larger
1745 * then usual rectange
1747 * Please note that subitem support works only in REPORT mode.
1750 * [I] infoPtr : valid pointer to the listview structure
1751 * [I] lpLVItem : item to compute the measures for
1752 * [O] lprcBox : ptr to Box rectangle
1753 * The internal LVIR_BOX rectangle
1754 * [0] lprcState : ptr to State icon rectangle
1755 * The internal LVIR_STATE rectangle
1756 * [O] lprcIcon : ptr to Icon rectangle
1757 * Same as LVM_GETITEMRECT with LVIR_ICON
1758 * [O] lprcLabel : ptr to Label rectangle
1759 * Same as LVM_GETITEMRECT with LVIR_LABEL
1764 static void LISTVIEW_GetItemMetrics(LISTVIEW_INFO *infoPtr, const LVITEMW *lpLVItem,
1765 LPRECT lprcBox, LPRECT lprcState,
1766 LPRECT lprcIcon, LPRECT lprcLabel)
1768 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
1769 BOOL doState = FALSE, doIcon = FALSE, doLabel = FALSE, oversizedBox = FALSE;
1770 RECT Box, State, Icon, Label;
1771 COLUMN_INFO *lpColumnInfo = NULL;
1773 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem, TRUE));
1775 /* Be smart and try to figure out the minimum we have to do */
1776 if (lpLVItem->iSubItem) assert(uView == LVS_REPORT);
1777 if (uView == LVS_ICON && (lprcBox || lprcLabel))
1779 assert((lpLVItem->mask & LVIF_STATE) && (lpLVItem->stateMask & LVIS_FOCUSED));
1780 if (lpLVItem->state & LVIS_FOCUSED) oversizedBox = doLabel = TRUE;
1782 if (lprcLabel) doLabel = TRUE;
1783 if (doLabel || lprcIcon) doIcon = TRUE;
1784 if (doIcon || lprcState) doState = TRUE;
1786 /************************************************************/
1787 /* compute the box rectangle (it should be cheap to do) */
1788 /************************************************************/
1789 if (lpLVItem->iSubItem || uView == LVS_REPORT)
1790 lpColumnInfo = LISTVIEW_GetColumnInfo(infoPtr, lpLVItem->iSubItem);
1792 if (lpLVItem->iSubItem)
1794 Box = lpColumnInfo->rcHeader;
1799 Box.right = infoPtr->nItemWidth;
1802 Box.bottom = infoPtr->nItemHeight;
1804 /************************************************************/
1805 /* compute STATEICON bounding box */
1806 /************************************************************/
1809 if (uView == LVS_ICON)
1811 State.left = Box.left - infoPtr->iconStateSize.cx - 2;
1812 if (infoPtr->himlNormal)
1813 State.left += (infoPtr->nItemWidth - infoPtr->iconSize.cx) / 2;
1814 State.top = Box.top + infoPtr->iconSize.cy - infoPtr->iconStateSize.cy + 4;
1818 /* we need the ident in report mode, if we don't have it, we fail */
1819 State.left = Box.left;
1820 if (uView == LVS_REPORT)
1822 if (lpLVItem->iSubItem == 0)
1824 State.left += REPORT_MARGINX;
1825 assert(lpLVItem->mask & LVIF_INDENT);
1826 State.left += infoPtr->iconSize.cx * lpLVItem->iIndent;
1829 State.top = Box.top;
1831 State.right = State.left;
1832 State.bottom = State.top;
1833 if (infoPtr->himlState && lpLVItem->iSubItem == 0)
1835 State.right += infoPtr->iconStateSize.cx;
1836 State.bottom += infoPtr->iconStateSize.cy;
1838 if (lprcState) *lprcState = State;
1839 TRACE(" - state=%s\n", debugrect(&State));
1842 /************************************************************/
1843 /* compute ICON bounding box (ala LVM_GETITEMRECT) */
1844 /************************************************************/
1847 if (uView == LVS_ICON)
1849 Icon.left = Box.left;
1850 if (infoPtr->himlNormal)
1851 Icon.left += (infoPtr->nItemWidth - infoPtr->iconSize.cx) / 2;
1852 Icon.top = Box.top + ICON_TOP_PADDING;
1853 Icon.right = Icon.left;
1854 Icon.bottom = Icon.top;
1855 if (infoPtr->himlNormal)
1857 Icon.right += infoPtr->iconSize.cx;
1858 Icon.bottom += infoPtr->iconSize.cy;
1861 else /* LVS_SMALLICON, LVS_LIST or LVS_REPORT */
1863 Icon.left = State.right;
1865 Icon.right = Icon.left;
1866 if (infoPtr->himlSmall && (!lpColumnInfo || lpLVItem->iSubItem == 0 || (lpColumnInfo->fmt & LVCFMT_IMAGE)))
1867 Icon.right += infoPtr->iconSize.cx;
1868 Icon.bottom = Icon.top + infoPtr->nItemHeight;
1870 if(lprcIcon) *lprcIcon = Icon;
1871 TRACE(" - icon=%s\n", debugrect(&Icon));
1874 /************************************************************/
1875 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
1876 /************************************************************/
1879 SIZE labelSize = { 0, 0 };
1881 /* calculate how far to the right can the label strech */
1882 Label.right = Box.right;
1883 if (uView == LVS_REPORT)
1885 if (lpLVItem->iSubItem == 0) Label = lpColumnInfo->rcHeader;
1888 if (lpLVItem->iSubItem || ((infoPtr->dwStyle & LVS_OWNERDRAWFIXED) && uView == LVS_REPORT))
1890 labelSize.cx = infoPtr->nItemWidth;
1891 labelSize.cy = infoPtr->nItemHeight;
1895 /* we need the text in non owner draw mode */
1896 assert(lpLVItem->mask & LVIF_TEXT);
1897 if (is_textT(lpLVItem->pszText, TRUE))
1899 HFONT hFont = infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont;
1900 HDC hdc = GetDC(infoPtr->hwndSelf);
1901 HFONT hOldFont = SelectObject(hdc, hFont);
1905 /* compute rough rectangle where the label will go */
1906 SetRectEmpty(&rcText);
1907 rcText.right = infoPtr->nItemWidth - TRAILING_LABEL_PADDING;
1908 rcText.bottom = infoPtr->nItemHeight;
1909 if (uView == LVS_ICON)
1910 rcText.bottom -= ICON_TOP_PADDING + infoPtr->iconSize.cy + ICON_BOTTOM_PADDING;
1912 /* now figure out the flags */
1913 if (uView == LVS_ICON)
1914 uFormat = oversizedBox ? LV_FL_DT_FLAGS : LV_ML_DT_FLAGS;
1916 uFormat = LV_SL_DT_FLAGS;
1918 DrawTextW (hdc, lpLVItem->pszText, -1, &rcText, uFormat | DT_CALCRECT);
1920 labelSize.cx = min(rcText.right - rcText.left + TRAILING_LABEL_PADDING, infoPtr->nItemWidth);
1921 labelSize.cy = rcText.bottom - rcText.top;
1923 SelectObject(hdc, hOldFont);
1924 ReleaseDC(infoPtr->hwndSelf, hdc);
1928 if (uView == LVS_ICON)
1930 Label.left = Box.left + (infoPtr->nItemWidth - labelSize.cx) / 2;
1931 Label.top = Box.top + ICON_TOP_PADDING_HITABLE +
1932 infoPtr->iconSize.cy + ICON_BOTTOM_PADDING;
1933 Label.right = Label.left + labelSize.cx;
1934 Label.bottom = Label.top + infoPtr->nItemHeight;
1935 if (!oversizedBox && labelSize.cy > infoPtr->ntmHeight)
1937 labelSize.cy = min(Box.bottom - Label.top, labelSize.cy);
1938 labelSize.cy /= infoPtr->ntmHeight;
1939 labelSize.cy = max(labelSize.cy, 1);
1940 labelSize.cy *= infoPtr->ntmHeight;
1942 Label.bottom = Label.top + labelSize.cy + HEIGHT_PADDING;
1944 else /* LVS_SMALLICON, LVS_LIST or LVS_REPORT */
1946 Label.left = Icon.right;
1947 Label.top = Box.top;
1948 Label.right = min(Label.left + labelSize.cx, Label.right);
1949 Label.bottom = Label.top + infoPtr->nItemHeight;
1952 if (lprcLabel) *lprcLabel = Label;
1953 TRACE(" - label=%s\n", debugrect(&Label));
1956 /* Fix the Box if necessary */
1959 if (oversizedBox) UnionRect(lprcBox, &Box, &Label);
1960 else *lprcBox = Box;
1962 TRACE(" - box=%s\n", debugrect(&Box));
1966 * DESCRIPTION: [INTERNAL]
1969 * [I] infoPtr : valid pointer to the listview structure
1970 * [I] nItem : item number
1971 * [O] lprcBox : ptr to Box rectangle
1976 static void LISTVIEW_GetItemBox(LISTVIEW_INFO *infoPtr, INT nItem, LPRECT lprcBox)
1978 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
1979 WCHAR szDispText[DISP_TEXT_SIZE] = { '\0' };
1980 POINT Position, Origin;
1983 LISTVIEW_GetOrigin(infoPtr, &Origin);
1984 LISTVIEW_GetItemOrigin(infoPtr, nItem, &Position);
1986 /* Be smart and try to figure out the minimum we have to do */
1988 if (uView == LVS_ICON && infoPtr->bFocus && LISTVIEW_GetItemState(infoPtr, nItem, LVIS_FOCUSED))
1989 lvItem.mask |= LVIF_TEXT;
1990 lvItem.iItem = nItem;
1991 lvItem.iSubItem = 0;
1992 lvItem.pszText = szDispText;
1993 lvItem.cchTextMax = DISP_TEXT_SIZE;
1994 if (lvItem.mask) LISTVIEW_GetItemW(infoPtr, &lvItem);
1995 if (uView == LVS_ICON)
1997 lvItem.mask |= LVIF_STATE;
1998 lvItem.stateMask = LVIS_FOCUSED;
1999 lvItem.state = (lvItem.mask & LVIF_TEXT ? LVIS_FOCUSED : 0);
2001 LISTVIEW_GetItemMetrics(infoPtr, &lvItem, lprcBox, 0, 0, 0);
2003 OffsetRect(lprcBox, Position.x + Origin.x, Position.y + Origin.y);
2009 * Returns the current icon position, and advances it along the top.
2010 * The returned position is not offset by Origin.
2013 * [I] infoPtr : valid pointer to the listview structure
2014 * [O] lpPos : will get the current icon position
2019 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO *infoPtr, LPPOINT lpPos)
2021 INT nListWidth = infoPtr->rcList.right - infoPtr->rcList.left;
2023 *lpPos = infoPtr->currIconPos;
2025 infoPtr->currIconPos.x += infoPtr->nItemWidth;
2026 if (infoPtr->currIconPos.x + infoPtr->nItemWidth <= nListWidth) return;
2028 infoPtr->currIconPos.x = 0;
2029 infoPtr->currIconPos.y += infoPtr->nItemHeight;
2035 * Returns the current icon position, and advances it down the left edge.
2036 * The returned position is not offset by Origin.
2039 * [I] infoPtr : valid pointer to the listview structure
2040 * [O] lpPos : will get the current icon position
2045 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO *infoPtr, LPPOINT lpPos)
2047 INT nListHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
2049 *lpPos = infoPtr->currIconPos;
2051 infoPtr->currIconPos.y += infoPtr->nItemHeight;
2052 if (infoPtr->currIconPos.y + infoPtr->nItemHeight <= nListHeight) return;
2054 infoPtr->currIconPos.x += infoPtr->nItemWidth;
2055 infoPtr->currIconPos.y = 0;
2061 * Moves an icon to the specified position.
2062 * It takes care of invalidating the item, etc.
2065 * [I] infoPtr : valid pointer to the listview structure
2066 * [I] nItem : the item to move
2067 * [I] lpPos : the new icon position
2068 * [I] isNew : flags the item as being new
2074 static BOOL LISTVIEW_MoveIconTo(LISTVIEW_INFO *infoPtr, INT nItem, const POINT *lppt, BOOL isNew)
2080 old.x = (LONG)DPA_GetPtr(infoPtr->hdpaPosX, nItem);
2081 old.y = (LONG)DPA_GetPtr(infoPtr->hdpaPosY, nItem);
2083 if (lppt->x == old.x && lppt->y == old.y) return TRUE;
2084 LISTVIEW_InvalidateItem(infoPtr, nItem);
2087 /* Allocating a POINTER for every item is too resource intensive,
2088 * so we'll keep the (x,y) in different arrays */
2089 if (!DPA_SetPtr(infoPtr->hdpaPosX, nItem, (void *)lppt->x)) return FALSE;
2090 if (!DPA_SetPtr(infoPtr->hdpaPosY, nItem, (void *)lppt->y)) return FALSE;
2092 LISTVIEW_InvalidateItem(infoPtr, nItem);
2099 * Arranges listview items in icon display mode.
2102 * [I] infoPtr : valid pointer to the listview structure
2103 * [I] nAlignCode : alignment code
2109 static BOOL LISTVIEW_Arrange(LISTVIEW_INFO *infoPtr, INT nAlignCode)
2111 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
2112 void (*next_pos)(LISTVIEW_INFO *, LPPOINT);
2116 if (uView != LVS_ICON && uView != LVS_SMALLICON) return FALSE;
2118 TRACE("nAlignCode=%d\n", nAlignCode);
2120 if (nAlignCode == LVA_DEFAULT)
2122 if (infoPtr->dwStyle & LVS_ALIGNLEFT) nAlignCode = LVA_ALIGNLEFT;
2123 else nAlignCode = LVA_ALIGNTOP;
2128 case LVA_ALIGNLEFT: next_pos = LISTVIEW_NextIconPosLeft; break;
2129 case LVA_ALIGNTOP: next_pos = LISTVIEW_NextIconPosTop; break;
2130 case LVA_SNAPTOGRID: next_pos = LISTVIEW_NextIconPosTop; break; /* FIXME */
2131 default: return FALSE;
2134 infoPtr->bAutoarrange = TRUE;
2135 infoPtr->currIconPos.x = infoPtr->currIconPos.y = 0;
2136 for (i = 0; i < infoPtr->nItemCount; i++)
2138 next_pos(infoPtr, &pos);
2139 LISTVIEW_MoveIconTo(infoPtr, i, &pos, FALSE);
2147 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2150 * [I] infoPtr : valid pointer to the listview structure
2151 * [O] lprcView : bounding rectangle
2157 static void LISTVIEW_GetAreaRect(LISTVIEW_INFO *infoPtr, LPRECT lprcView)
2161 SetRectEmpty(lprcView);
2163 switch (infoPtr->dwStyle & LVS_TYPEMASK)
2167 for (i = 0; i < infoPtr->nItemCount; i++)
2169 x = (LONG)DPA_GetPtr(infoPtr->hdpaPosX, i);
2170 y = (LONG)DPA_GetPtr(infoPtr->hdpaPosY, i);
2171 lprcView->right = max(lprcView->right, x);
2172 lprcView->bottom = max(lprcView->bottom, y);
2174 if (infoPtr->nItemCount > 0)
2176 lprcView->right += infoPtr->nItemWidth;
2177 lprcView->bottom += infoPtr->nItemHeight;
2182 y = LISTVIEW_GetCountPerColumn(infoPtr);
2183 x = infoPtr->nItemCount / y;
2184 if (infoPtr->nItemCount % y) x++;
2185 lprcView->right = x * infoPtr->nItemWidth;
2186 lprcView->bottom = y * infoPtr->nItemHeight;
2190 lprcView->right = infoPtr->nItemWidth;
2191 lprcView->bottom = infoPtr->nItemCount * infoPtr->nItemHeight;
2198 * Retrieves the bounding rectangle of all the items.
2201 * [I] infoPtr : valid pointer to the listview structure
2202 * [O] lprcView : bounding rectangle
2208 static BOOL LISTVIEW_GetViewRect(LISTVIEW_INFO *infoPtr, LPRECT lprcView)
2212 TRACE("(lprcView=%p)\n", lprcView);
2214 if (!lprcView) return FALSE;
2216 LISTVIEW_GetOrigin(infoPtr, &ptOrigin);
2217 LISTVIEW_GetAreaRect(infoPtr, lprcView);
2218 OffsetRect(lprcView, ptOrigin.x, ptOrigin.y);
2220 TRACE("lprcView=%s\n", debugrect(lprcView));
2227 * Retrieves the subitem pointer associated with the subitem index.
2230 * [I] hdpaSubItems : DPA handle for a specific item
2231 * [I] nSubItem : index of subitem
2234 * SUCCESS : subitem pointer
2237 static SUBITEM_INFO* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems, INT nSubItem)
2239 SUBITEM_INFO *lpSubItem;
2242 /* we should binary search here if need be */
2243 for (i = 1; i < hdpaSubItems->nItemCount; i++)
2245 lpSubItem = (SUBITEM_INFO *)DPA_GetPtr(hdpaSubItems, i);
2246 if (lpSubItem->iSubItem == nSubItem)
2256 * Caclulates the desired item width.
2259 * [I] infoPtr : valid pointer to the listview structure
2262 * The desired item width.
2264 static INT LISTVIEW_CalculateItemWidth(LISTVIEW_INFO *infoPtr)
2266 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
2269 TRACE("uView=%d\n", uView);
2271 if (uView == LVS_ICON)
2272 nItemWidth = infoPtr->iconSpacing.cx;
2273 else if (uView == LVS_REPORT)
2277 if (infoPtr->hdpaColumns->nItemCount > 0)
2279 LISTVIEW_GetHeaderRect(infoPtr, infoPtr->hdpaColumns->nItemCount - 1, &rcHeader);
2280 nItemWidth = rcHeader.right;
2283 else /* LVS_SMALLICON, or LVS_LIST */
2287 for (i = 0; i < infoPtr->nItemCount; i++)
2288 nItemWidth = max(LISTVIEW_GetLabelWidth(infoPtr, i), nItemWidth);
2290 if (infoPtr->himlSmall) nItemWidth += infoPtr->iconSize.cx;
2291 if (infoPtr->himlState) nItemWidth += infoPtr->iconStateSize.cx;
2293 nItemWidth = max(DEFAULT_COLUMN_WIDTH, nItemWidth + WIDTH_PADDING);
2296 return max(nItemWidth, 1);
2301 * Caclulates the desired item height.
2304 * [I] infoPtr : valid pointer to the listview structure
2307 * The desired item height.
2309 static INT LISTVIEW_CalculateItemHeight(LISTVIEW_INFO *infoPtr)
2311 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
2314 TRACE("uView=%d\n", uView);
2316 if (uView == LVS_ICON)
2317 nItemHeight = infoPtr->iconSpacing.cy;
2320 nItemHeight = infoPtr->ntmHeight;
2321 if (infoPtr->himlState)
2322 nItemHeight = max(nItemHeight, infoPtr->iconStateSize.cy);
2323 if (infoPtr->himlSmall)
2324 nItemHeight = max(nItemHeight, infoPtr->iconSize.cy);
2325 if (infoPtr->himlState || infoPtr->himlSmall)
2326 nItemHeight += HEIGHT_PADDING;
2329 return max(nItemHeight, 1);
2334 * Updates the width, and height of an item.
2337 * [I] infoPtr : valid pointer to the listview structure
2342 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO *infoPtr)
2344 infoPtr->nItemWidth = LISTVIEW_CalculateItemWidth(infoPtr);
2345 infoPtr->nItemHeight = LISTVIEW_CalculateItemHeight(infoPtr);
2351 * Retrieves and saves important text metrics info for the current
2355 * [I] infoPtr : valid pointer to the listview structure
2358 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO *infoPtr)
2360 HDC hdc = GetDC(infoPtr->hwndSelf);
2361 HFONT hFont = infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont;
2362 HFONT hOldFont = SelectObject(hdc, hFont);
2365 if (GetTextMetricsW(hdc, &tm))
2367 infoPtr->ntmHeight = tm.tmHeight;
2368 infoPtr->ntmAveCharWidth = tm.tmAveCharWidth;
2370 SelectObject(hdc, hOldFont);
2371 ReleaseDC(infoPtr->hwndSelf, hdc);
2373 TRACE("tmHeight=%d\n", infoPtr->ntmHeight);
2378 * A compare function for ranges
2381 * [I] range1 : pointer to range 1;
2382 * [I] range2 : pointer to range 2;
2386 * > 0 : if range 1 > range 2
2387 * < 0 : if range 2 > range 1
2388 * = 0 : if range intersects range 2
2390 static INT CALLBACK ranges_cmp(LPVOID range1, LPVOID range2, LPARAM flags)
2394 if (((RANGE*)range1)->upper <= ((RANGE*)range2)->lower)
2396 else if (((RANGE*)range2)->upper <= ((RANGE*)range1)->lower)
2401 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange((RANGE*)range1), debugrange((RANGE*)range2), cmp);
2407 #define ranges_check(ranges, desc) ranges_assert(ranges, desc, __FUNCTION__, __LINE__)
2409 #define ranges_check(ranges, desc) do { } while(0)
2412 static void ranges_assert(RANGES ranges, LPCSTR desc, const char *func, int line)
2417 TRACE("*** Checking %s:%d:%s ***\n", func, line, desc);
2419 assert (ranges->hdpa->nItemCount >= 0);
2420 ranges_dump(ranges);
2421 prev = (RANGE *)DPA_GetPtr(ranges->hdpa, 0);
2422 if (ranges->hdpa->nItemCount > 0)
2423 assert (prev->lower >= 0 && prev->lower < prev->upper);
2424 for (i = 1; i < ranges->hdpa->nItemCount; i++)
2426 curr = (RANGE *)DPA_GetPtr(ranges->hdpa, i);
2427 assert (prev->upper <= curr->lower);
2428 assert (curr->lower < curr->upper);
2431 TRACE("--- Done checking---\n");
2434 static RANGES ranges_create(int count)
2436 RANGES ranges = (RANGES)COMCTL32_Alloc(sizeof(struct tagRANGES));
2437 if (!ranges) return NULL;
2438 ranges->hdpa = DPA_Create(count);
2439 if (ranges->hdpa) return ranges;
2440 COMCTL32_Free(ranges);
2444 static void ranges_clear(RANGES ranges)
2448 for(i = 0; i < ranges->hdpa->nItemCount; i++)
2449 COMCTL32_Free(DPA_GetPtr(ranges->hdpa, i));
2450 DPA_DeleteAllPtrs(ranges->hdpa);
2454 static void ranges_destroy(RANGES ranges)
2456 if (!ranges) return;
2457 ranges_clear(ranges);
2458 DPA_Destroy(ranges->hdpa);
2459 COMCTL32_Free(ranges);
2462 static RANGES ranges_clone(RANGES ranges)
2467 if (!(clone = ranges_create(ranges->hdpa->nItemCount))) goto fail;
2469 for (i = 0; i < ranges->hdpa->nItemCount; i++)
2471 RANGE *newrng = (RANGE *)COMCTL32_Alloc(sizeof(RANGE));
2472 if (!newrng) goto fail;
2473 *newrng = *((RANGE*)DPA_GetPtr(ranges->hdpa, i));
2474 DPA_SetPtr(clone->hdpa, i, newrng);
2479 TRACE ("clone failed\n");
2480 ranges_destroy(clone);
2484 static RANGES ranges_diff(RANGES ranges, RANGES sub)
2488 for (i = 0; i < sub->hdpa->nItemCount; i++)
2489 ranges_del(ranges, *((RANGE *)DPA_GetPtr(sub->hdpa, i)));
2494 static void ranges_dump(RANGES ranges)
2498 for (i = 0; i < ranges->hdpa->nItemCount; i++)
2499 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges->hdpa, i)));
2502 static inline BOOL ranges_contain(RANGES ranges, INT nItem)
2504 RANGE srchrng = { nItem, nItem + 1 };
2506 TRACE("(nItem=%d)\n", nItem);
2507 ranges_check(ranges, "before contain");
2508 return DPA_Search(ranges->hdpa, &srchrng, 0, ranges_cmp, 0, DPAS_SORTED) != -1;
2511 static INT ranges_itemcount(RANGES ranges)
2515 for (i = 0; i < ranges->hdpa->nItemCount; i++)
2517 RANGE *sel = DPA_GetPtr(ranges->hdpa, i);
2518 count += sel->upper - sel->lower;
2524 static BOOL ranges_shift(RANGES ranges, INT nItem, INT delta, INT nUpper)
2526 RANGE srchrng = { nItem, nItem + 1 }, *chkrng;
2529 index = DPA_Search(ranges->hdpa, &srchrng, 0, ranges_cmp, 0, DPAS_SORTED | DPAS_INSERTAFTER);
2530 if (index == -1) return TRUE;
2532 for (; index < ranges->hdpa->nItemCount; index++)
2534 chkrng = DPA_GetPtr(ranges->hdpa, index);
2535 if (chkrng->lower >= nItem)
2536 chkrng->lower = max(min(chkrng->lower + delta, nUpper - 1), 0);
2537 if (chkrng->upper > nItem)
2538 chkrng->upper = max(min(chkrng->upper + delta, nUpper), 0);
2543 static BOOL ranges_add(RANGES ranges, RANGE range)
2548 TRACE("(%s)\n", debugrange(&range));
2549 ranges_check(ranges, "before add");
2551 /* try find overlapping regions first */
2552 srchrgn.lower = range.lower - 1;
2553 srchrgn.upper = range.upper + 1;
2554 index = DPA_Search(ranges->hdpa, &srchrgn, 0, ranges_cmp, 0, DPAS_SORTED);
2560 TRACE("Adding new range\n");
2562 /* create the brand new range to insert */
2563 newrgn = (RANGE *)COMCTL32_Alloc(sizeof(RANGE));
2564 if(!newrgn) goto fail;
2567 /* figure out where to insert it */
2568 index = DPA_Search(ranges->hdpa, newrgn, 0, ranges_cmp, 0, DPAS_SORTED | DPAS_INSERTAFTER);
2569 TRACE("index=%d\n", index);
2570 if (index == -1) index = 0;
2572 /* and get it over with */
2573 if (DPA_InsertPtr(ranges->hdpa, index, newrgn) == -1)
2575 COMCTL32_Free(newrgn);
2581 RANGE *chkrgn, *mrgrgn;
2582 INT fromindex, mergeindex;
2584 chkrgn = DPA_GetPtr(ranges->hdpa, index);
2585 TRACE("Merge with %s @%d\n", debugrange(chkrgn), index);
2587 chkrgn->lower = min(range.lower, chkrgn->lower);
2588 chkrgn->upper = max(range.upper, chkrgn->upper);
2590 TRACE("New range %s @%d\n", debugrange(chkrgn), index);
2592 /* merge now common anges */
2594 srchrgn.lower = chkrgn->lower - 1;
2595 srchrgn.upper = chkrgn->upper + 1;
2599 mergeindex = DPA_Search(ranges->hdpa, &srchrgn, fromindex, ranges_cmp, 0, 0);
2600 if (mergeindex == -1) break;
2601 if (mergeindex == index)
2603 fromindex = index + 1;
2607 TRACE("Merge with index %i\n", mergeindex);
2609 mrgrgn = DPA_GetPtr(ranges->hdpa, mergeindex);
2610 chkrgn->lower = min(chkrgn->lower, mrgrgn->lower);
2611 chkrgn->upper = max(chkrgn->upper, mrgrgn->upper);
2612 COMCTL32_Free(mrgrgn);
2613 DPA_DeletePtr(ranges->hdpa, mergeindex);
2614 if (mergeindex < index) index --;
2618 ranges_check(ranges, "after add");
2622 ranges_check(ranges, "failed add");
2626 static BOOL ranges_del(RANGES ranges, RANGE range)
2631 TRACE("(%s)\n", debugrange(&range));
2632 ranges_check(ranges, "before del");
2634 /* we don't use DPAS_SORTED here, since we need *
2635 * to find the first overlapping range */
2636 index = DPA_Search(ranges->hdpa, &range, 0, ranges_cmp, 0, 0);
2639 chkrgn = DPA_GetPtr(ranges->hdpa, index);
2641 TRACE("Matches range %s @%d\n", debugrange(chkrgn), index);
2643 /* case 1: Same range */
2644 if ( (chkrgn->upper == range.upper) &&
2645 (chkrgn->lower == range.lower) )
2647 DPA_DeletePtr(ranges->hdpa, index);
2650 /* case 2: engulf */
2651 else if ( (chkrgn->upper <= range.upper) &&
2652 (chkrgn->lower >= range.lower) )
2654 DPA_DeletePtr(ranges->hdpa, index);
2656 /* case 3: overlap upper */
2657 else if ( (chkrgn->upper <= range.upper) &&
2658 (chkrgn->lower < range.lower) )
2660 chkrgn->upper = range.lower;
2662 /* case 4: overlap lower */
2663 else if ( (chkrgn->upper > range.upper) &&
2664 (chkrgn->lower >= range.lower) )
2666 chkrgn->lower = range.upper;
2669 /* case 5: fully internal */
2672 RANGE tmprgn = *chkrgn, *newrgn;
2674 if (!(newrgn = (RANGE *)COMCTL32_Alloc(sizeof(RANGE)))) goto fail;
2675 newrgn->lower = chkrgn->lower;
2676 newrgn->upper = range.lower;
2677 chkrgn->lower = range.upper;
2678 if (DPA_InsertPtr(ranges->hdpa, index, newrgn) == -1)
2680 COMCTL32_Free(newrgn);
2687 index = DPA_Search(ranges->hdpa, &range, index, ranges_cmp, 0, 0);
2690 ranges_check(ranges, "after del");
2694 ranges_check(ranges, "failed del");
2700 * Removes all selection ranges
2703 * [I] infoPtr : valid pointer to the listview structure
2704 * [I] toSkip : item range to skip removing the selection
2710 static BOOL LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO *infoPtr, RANGES toSkip)
2719 lvItem.stateMask = LVIS_SELECTED;
2721 /* need to clone the DPA because callbacks can change it */
2722 if (!(clone = ranges_clone(infoPtr->selectionRanges))) return FALSE;
2723 iterator_rangesitems(&i, ranges_diff(clone, toSkip));
2724 while(iterator_next(&i))
2725 LISTVIEW_SetItemState(infoPtr, i.nItem, &lvItem);
2726 /* note that the iterator destructor will free the cloned range */
2727 iterator_destroy(&i);
2732 static inline BOOL LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO *infoPtr, INT nItem)
2736 if (!(toSkip = ranges_create(1))) return FALSE;
2737 if (nItem != -1) ranges_additem(toSkip, nItem);
2738 LISTVIEW_DeselectAllSkipItems(infoPtr, toSkip);
2739 ranges_destroy(toSkip);
2743 static inline BOOL LISTVIEW_DeselectAll(LISTVIEW_INFO *infoPtr)
2745 return LISTVIEW_DeselectAllSkipItem(infoPtr, -1);
2750 * Retrieves the number of items that are marked as selected.
2753 * [I] infoPtr : valid pointer to the listview structure
2756 * Number of items selected.
2758 static INT LISTVIEW_GetSelectedCount(LISTVIEW_INFO *infoPtr)
2760 INT nSelectedCount = 0;
2762 if (infoPtr->uCallbackMask & LVIS_SELECTED)
2765 for (i = 0; i < infoPtr->nItemCount; i++)
2767 if (LISTVIEW_GetItemState(infoPtr, i, LVIS_SELECTED))
2772 nSelectedCount = ranges_itemcount(infoPtr->selectionRanges);
2774 TRACE("nSelectedCount=%d\n", nSelectedCount);
2775 return nSelectedCount;
2780 * Manages the item focus.
2783 * [I] infoPtr : valid pointer to the listview structure
2784 * [I] nItem : item index
2787 * TRUE : focused item changed
2788 * FALSE : focused item has NOT changed
2790 static inline BOOL LISTVIEW_SetItemFocus(LISTVIEW_INFO *infoPtr, INT nItem)
2792 INT oldFocus = infoPtr->nFocusedItem;
2795 if (nItem == infoPtr->nFocusedItem) return FALSE;
2797 lvItem.state = nItem == -1 ? 0 : LVIS_FOCUSED;
2798 lvItem.stateMask = LVIS_FOCUSED;
2799 LISTVIEW_SetItemState(infoPtr, nItem == -1 ? infoPtr->nFocusedItem : nItem, &lvItem);
2801 return oldFocus != infoPtr->nFocusedItem;
2804 /* Helper function for LISTVIEW_ShiftIndices *only* */
2805 static INT shift_item(LISTVIEW_INFO *infoPtr, INT nShiftItem, INT nItem, INT direction)
2807 if (nShiftItem < nItem) return nShiftItem;
2809 if (nShiftItem > nItem) return nShiftItem + direction;
2811 if (direction > 0) return nShiftItem + direction;
2813 return min(nShiftItem, infoPtr->nItemCount - 1);
2818 * Updates the various indices after an item has been inserted or deleted.
2821 * [I] infoPtr : valid pointer to the listview structure
2822 * [I] nItem : item index
2823 * [I] direction : Direction of shift, +1 or -1.
2828 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO *infoPtr, INT nItem, INT direction)
2833 /* temporarily disable change notification while shifting items */
2834 bOldChange = infoPtr->bDoChangeNotify;
2835 infoPtr->bDoChangeNotify = FALSE;
2837 TRACE("Shifting %iu, %i steps\n", nItem, direction);
2839 ranges_shift(infoPtr->selectionRanges, nItem, direction, infoPtr->nItemCount);
2841 assert(abs(direction) == 1);
2843 infoPtr->nSelectionMark = shift_item(infoPtr, infoPtr->nSelectionMark, nItem, direction);
2845 nNewFocus = shift_item(infoPtr, infoPtr->nFocusedItem, nItem, direction);
2846 if (nNewFocus != infoPtr->nFocusedItem)
2847 LISTVIEW_SetItemFocus(infoPtr, nNewFocus);
2849 /* But we are not supposed to modify nHotItem! */
2851 infoPtr->bDoChangeNotify = bOldChange;
2857 * Adds a block of selections.
2860 * [I] infoPtr : valid pointer to the listview structure
2861 * [I] nItem : item index
2866 static void LISTVIEW_AddGroupSelection(LISTVIEW_INFO *infoPtr, INT nItem)
2868 INT nFirst = min(infoPtr->nSelectionMark, nItem);
2869 INT nLast = max(infoPtr->nSelectionMark, nItem);
2873 if (nFirst == -1) nFirst = nItem;
2875 item.state = LVIS_SELECTED;
2876 item.stateMask = LVIS_SELECTED;
2878 /* FIXME: this is not correct LVS_OWNERDATA
2879 * setting the item states individually will generate
2880 * a LVN_ITEMCHANGED notification for each one. Instead,
2881 * we have to send a LVN_ODSTATECHANGED notification.
2882 * See MSDN documentation for LVN_ITEMCHANGED.
2884 for (i = nFirst; i <= nLast; i++)
2885 LISTVIEW_SetItemState(infoPtr,i,&item);
2891 * Sets a single group selection.
2894 * [I] infoPtr : valid pointer to the listview structure
2895 * [I] nItem : item index
2900 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO *infoPtr, INT nItem)
2902 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
2907 if (!(selection = ranges_create(100))) return;
2909 item.state = LVIS_SELECTED;
2910 item.stateMask = LVIS_SELECTED;
2912 if ((uView == LVS_LIST) || (uView == LVS_REPORT))
2914 if (infoPtr->nSelectionMark == -1)
2916 infoPtr->nSelectionMark = nItem;
2917 ranges_additem(selection, nItem);
2923 sel.lower = min(infoPtr->nSelectionMark, nItem);
2924 sel.upper = max(infoPtr->nSelectionMark, nItem) + 1;
2925 ranges_add(selection, sel);
2930 RECT rcItem, rcSel, rcSelMark;
2933 rcItem.left = LVIR_BOUNDS;
2934 if (!LISTVIEW_GetItemRect(infoPtr, nItem, &rcItem)) return;
2935 rcSelMark.left = LVIR_BOUNDS;
2936 if (!LISTVIEW_GetItemRect(infoPtr, infoPtr->nSelectionMark, &rcSelMark)) return;
2937 UnionRect(&rcSel, &rcItem, &rcSelMark);
2938 iterator_frameditems(&i, infoPtr, &rcSel);
2939 while(iterator_next(&i))
2941 LISTVIEW_GetItemPosition(infoPtr, i.nItem, &ptItem);
2942 if (PtInRect(&rcSel, ptItem)) ranges_additem(selection, i.nItem);
2944 iterator_destroy(&i);
2947 LISTVIEW_DeselectAllSkipItems(infoPtr, selection);
2948 iterator_rangesitems(&i, selection);
2949 while(iterator_next(&i))
2950 LISTVIEW_SetItemState(infoPtr, i.nItem, &item);
2951 /* this will also destroy the selection */
2952 iterator_destroy(&i);
2954 LISTVIEW_SetItemFocus(infoPtr, nItem);
2959 * Sets a single selection.
2962 * [I] infoPtr : valid pointer to the listview structure
2963 * [I] nItem : item index
2968 static void LISTVIEW_SetSelection(LISTVIEW_INFO *infoPtr, INT nItem)
2972 TRACE("nItem=%d\n", nItem);
2974 LISTVIEW_DeselectAllSkipItem(infoPtr, nItem);
2976 lvItem.state = LVIS_FOCUSED | LVIS_SELECTED;
2977 lvItem.stateMask = LVIS_FOCUSED | LVIS_SELECTED;
2978 LISTVIEW_SetItemState(infoPtr, nItem, &lvItem);
2980 infoPtr->nSelectionMark = nItem;
2985 * Set selection(s) with keyboard.
2988 * [I] infoPtr : valid pointer to the listview structure
2989 * [I] nItem : item index
2992 * SUCCESS : TRUE (needs to be repainted)
2993 * FAILURE : FALSE (nothing has changed)
2995 static BOOL LISTVIEW_KeySelection(LISTVIEW_INFO *infoPtr, INT nItem)
2997 /* FIXME: pass in the state */
2998 WORD wShift = HIWORD(GetKeyState(VK_SHIFT));
2999 WORD wCtrl = HIWORD(GetKeyState(VK_CONTROL));
3000 BOOL bResult = FALSE;
3002 if ((nItem >= 0) && (nItem < infoPtr->nItemCount))
3004 if (infoPtr->dwStyle & LVS_SINGLESEL)
3007 LISTVIEW_SetSelection(infoPtr, nItem);
3014 LISTVIEW_SetGroupSelection(infoPtr, nItem);
3018 bResult = LISTVIEW_SetItemFocus(infoPtr, nItem);
3023 LISTVIEW_SetSelection(infoPtr, nItem);
3026 LISTVIEW_EnsureVisible(infoPtr, nItem, FALSE);
3029 UpdateWindow(infoPtr->hwndSelf); /* update client area */
3036 * Called when the mouse is being actively tracked and has hovered for a specified
3040 * [I] infoPtr : valid pointer to the listview structure
3041 * [I] fwKeys : key indicator
3042 * [I] pts : mouse position
3045 * 0 if the message was processed, non-zero if there was an error
3048 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3049 * over the item for a certain period of time.
3052 static LRESULT LISTVIEW_MouseHover(LISTVIEW_INFO *infoPtr, WORD fwKyes, POINTS pts)
3054 if(infoPtr->dwLvExStyle & LVS_EX_TRACKSELECT)
3055 /* FIXME: select the item!!! */
3056 /*LISTVIEW_GetItemAtPt(infoPtr, pt)*/;
3063 * Called whenever WM_MOUSEMOVE is received.
3066 * [I] infoPtr : valid pointer to the listview structure
3067 * [I] fwKeys : key indicator
3068 * [I] pts : mouse position
3071 * 0 if the message is processed, non-zero if there was an error
3073 static LRESULT LISTVIEW_MouseMove(LISTVIEW_INFO *infoPtr, WORD fwKeys, POINTS pts)
3075 TRACKMOUSEEVENT trackinfo;
3077 /* see if we are supposed to be tracking mouse hovering */
3078 if(infoPtr->dwLvExStyle & LVS_EX_TRACKSELECT) {
3079 /* fill in the trackinfo struct */
3080 trackinfo.cbSize = sizeof(TRACKMOUSEEVENT);
3081 trackinfo.dwFlags = TME_QUERY;
3082 trackinfo.hwndTrack = infoPtr->hwndSelf;
3083 trackinfo.dwHoverTime = infoPtr->dwHoverTime;
3085 /* see if we are already tracking this hwnd */
3086 _TrackMouseEvent(&trackinfo);
3088 if(!(trackinfo.dwFlags & TME_HOVER)) {
3089 trackinfo.dwFlags = TME_HOVER;
3091 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
3092 _TrackMouseEvent(&trackinfo);
3101 * Tests wheather the item is assignable to a list with style lStyle
3103 static inline BOOL is_assignable_item(const LVITEMW *lpLVItem, LONG lStyle)
3105 if ( (lpLVItem->mask & LVIF_TEXT) &&
3106 (lpLVItem->pszText == LPSTR_TEXTCALLBACKW) &&
3107 (lStyle & (LVS_SORTASCENDING | LVS_SORTDESCENDING)) ) return FALSE;
3115 * Helper for LISTVIEW_SetItemT *only*: sets item attributes.
3118 * [I] infoPtr : valid pointer to the listview structure
3119 * [I] lpLVItem : valid pointer to new item atttributes
3120 * [I] isNew : the item being set is being inserted
3121 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3122 * [O] bChanged : will be set to TRUE if the item really changed
3128 static BOOL set_main_item(LISTVIEW_INFO *infoPtr, const LVITEMW *lpLVItem, BOOL isNew, BOOL isW, BOOL *bChanged)
3130 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
3138 assert(lpLVItem->iItem >= 0 && lpLVItem->iItem < infoPtr->nItemCount);
3140 if (lpLVItem->mask == 0) return TRUE;
3142 if (infoPtr->dwStyle & LVS_OWNERDATA)
3144 /* a virtual listview we stores only selection and focus */
3145 if (lpLVItem->mask & ~LVIF_STATE)
3151 HDPA hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, lpLVItem->iItem);
3152 lpItem = (ITEM_INFO *)DPA_GetPtr(hdpaSubItems, 0);
3156 /* we need to get the lParam and state of the item */
3157 item.iItem = lpLVItem->iItem;
3158 item.iSubItem = lpLVItem->iSubItem;
3159 item.mask = LVIF_STATE | LVIF_PARAM;
3160 item.stateMask = ~0;
3163 if (!isNew && !LISTVIEW_GetItemW(infoPtr, &item)) return FALSE;
3165 TRACE("oldState=%x, newState=%x\n", item.state, lpLVItem->state);
3166 /* determine what fields will change */
3167 if ((lpLVItem->mask & LVIF_STATE) && ((item.state ^ lpLVItem->state) & lpLVItem->stateMask & ~infoPtr->uCallbackMask))
3168 uChanged |= LVIF_STATE;
3170 if ((lpLVItem->mask & LVIF_IMAGE) && (lpItem->hdr.iImage != lpLVItem->iImage))
3171 uChanged |= LVIF_IMAGE;
3173 if ((lpLVItem->mask & LVIF_PARAM) && (lpItem->lParam != lpLVItem->lParam))
3174 uChanged |= LVIF_PARAM;
3176 if ((lpLVItem->mask & LVIF_INDENT) && (lpItem->iIndent != lpLVItem->iIndent))
3177 uChanged |= LVIF_INDENT;
3179 if ((lpLVItem->mask & LVIF_TEXT) && textcmpWT(lpItem->hdr.pszText, lpLVItem->pszText, isW))
3180 uChanged |= LVIF_TEXT;
3182 TRACE("uChanged=0x%x\n", uChanged);
3183 if (!uChanged) return TRUE;
3186 ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
3187 nmlv.iItem = lpLVItem->iItem;
3188 nmlv.uNewState = (item.state & ~lpLVItem->stateMask) | (lpLVItem->state & lpLVItem->stateMask);
3189 nmlv.uOldState = item.state;
3190 nmlv.uChanged = uChanged;
3191 nmlv.lParam = item.lParam;
3193 /* send LVN_ITEMCHANGING notification, if the item is not being inserted */
3194 /* and we are _NOT_ virtual (LVS_OWERNDATA), and change notifications */
3196 if(lpItem && !isNew && infoPtr->bDoChangeNotify &&
3197 notify_listview(infoPtr, LVN_ITEMCHANGING, &nmlv))
3200 /* copy information */
3201 if (lpLVItem->mask & LVIF_TEXT)
3202 textsetptrT(&lpItem->hdr.pszText, lpLVItem->pszText, isW);
3204 if (lpLVItem->mask & LVIF_IMAGE)
3205 lpItem->hdr.iImage = lpLVItem->iImage;
3207 if (lpLVItem->mask & LVIF_PARAM)
3208 lpItem->lParam = lpLVItem->lParam;
3210 if (lpLVItem->mask & LVIF_INDENT)
3211 lpItem->iIndent = lpLVItem->iIndent;
3213 if (uChanged & LVIF_STATE)
3215 if (lpItem && (lpLVItem->stateMask & ~infoPtr->uCallbackMask & ~(LVIS_FOCUSED | LVIS_SELECTED)))
3217 lpItem->state &= ~lpLVItem->stateMask;
3218 lpItem->state |= (lpLVItem->state & lpLVItem->stateMask);
3220 if (lpLVItem->state & lpLVItem->stateMask & ~infoPtr->uCallbackMask & LVIS_SELECTED)
3222 if (infoPtr->dwStyle & LVS_SINGLESEL) LISTVIEW_DeselectAllSkipItem(infoPtr, lpLVItem->iItem);
3223 ranges_additem(infoPtr->selectionRanges, lpLVItem->iItem);
3225 else if (lpLVItem->stateMask & LVIS_SELECTED)
3226 ranges_delitem(infoPtr->selectionRanges, lpLVItem->iItem);
3228 /* if we are asked to change focus, and we manage it, do it */
3229 if (lpLVItem->state & lpLVItem->stateMask & ~infoPtr->uCallbackMask & LVIS_FOCUSED)
3231 if (lpLVItem->state & LVIS_FOCUSED)
3233 LISTVIEW_SetItemFocus(infoPtr, -1);
3234 infoPtr->nFocusedItem = lpLVItem->iItem;
3235 LISTVIEW_EnsureVisible(infoPtr, lpLVItem->iItem, uView == LVS_LIST);
3237 else if (infoPtr->nFocusedItem == lpLVItem->iItem)
3238 infoPtr->nFocusedItem = -1;
3242 /* if we're inserting the item, we're done */
3243 if (isNew) return TRUE;
3245 /* send LVN_ITEMCHANGED notification */
3246 if (lpLVItem->mask & LVIF_PARAM) nmlv.lParam = lpLVItem->lParam;
3247 if (infoPtr->bDoChangeNotify) notify_listview(infoPtr, LVN_ITEMCHANGED, &nmlv);
3254 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
3257 * [I] infoPtr : valid pointer to the listview structure
3258 * [I] lpLVItem : valid pointer to new subitem atttributes
3259 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3260 * [O] bChanged : will be set to TRUE if the item really changed
3266 static BOOL set_sub_item(LISTVIEW_INFO *infoPtr, const LVITEMW *lpLVItem, BOOL isW, BOOL *bChanged)
3269 SUBITEM_INFO *lpSubItem;
3271 /* we do not support subitems for virtual listviews */
3272 if (infoPtr->dwStyle & LVS_OWNERDATA) return FALSE;
3274 /* set subitem only if column is present */
3275 if (lpLVItem->iSubItem >= infoPtr->hdpaColumns->nItemCount) return FALSE;
3277 /* First do some sanity checks */
3278 if (lpLVItem->mask & ~(LVIF_TEXT | LVIF_IMAGE)) return FALSE;
3279 if (!(lpLVItem->mask & (LVIF_TEXT | LVIF_IMAGE))) return TRUE;
3281 /* get the subitem structure, and create it if not there */
3282 hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, lpLVItem->iItem);
3283 assert (hdpaSubItems);
3285 lpSubItem = LISTVIEW_GetSubItemPtr(hdpaSubItems, lpLVItem->iSubItem);
3288 SUBITEM_INFO *tmpSubItem;
3291 lpSubItem = (SUBITEM_INFO *)COMCTL32_Alloc(sizeof(SUBITEM_INFO));
3292 if (!lpSubItem) return FALSE;
3293 /* we could binary search here, if need be...*/
3294 for (i = 1; i < hdpaSubItems->nItemCount; i++)
3296 tmpSubItem = (SUBITEM_INFO *)DPA_GetPtr(hdpaSubItems, i);
3297 if (tmpSubItem->iSubItem > lpLVItem->iSubItem) break;
3299 if (DPA_InsertPtr(hdpaSubItems, i, lpSubItem) == -1)
3301 COMCTL32_Free(lpSubItem);
3304 lpSubItem->iSubItem = lpLVItem->iSubItem;
3308 if (lpLVItem->mask & LVIF_IMAGE)
3309 if (lpSubItem->hdr.iImage != lpLVItem->iImage)
3311 lpSubItem->hdr.iImage = lpLVItem->iImage;
3315 if (lpLVItem->mask & LVIF_TEXT)
3316 if (lpSubItem->hdr.pszText != lpLVItem->pszText)
3318 textsetptrT(&lpSubItem->hdr.pszText, lpLVItem->pszText, isW);
3327 * Sets item attributes.
3330 * [I] infoPtr : valid pointer to the listview structure
3331 * [I] lpLVItem : new item atttributes
3332 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3338 static BOOL LISTVIEW_SetItemT(LISTVIEW_INFO *infoPtr, const LVITEMW *lpLVItem, BOOL isW)
3340 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
3341 LPWSTR pszText = NULL;
3342 BOOL bResult, bChanged = FALSE;
3344 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem, isW), isW);
3346 if (!lpLVItem || lpLVItem->iItem < 0 || lpLVItem->iItem >= infoPtr->nItemCount)
3349 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
3350 if ((lpLVItem->mask & LVIF_TEXT) && is_textW(lpLVItem->pszText))
3352 pszText = lpLVItem->pszText;
3353 ((LVITEMW *)lpLVItem)->pszText = textdupTtoW(lpLVItem->pszText, isW);
3356 /* actually set the fields */
3357 if (!is_assignable_item(lpLVItem, infoPtr->dwStyle)) return FALSE;
3359 if (lpLVItem->iSubItem)
3360 bResult = set_sub_item(infoPtr, lpLVItem, TRUE, &bChanged);
3362 bResult = set_main_item(infoPtr, lpLVItem, FALSE, TRUE, &bChanged);
3364 /* redraw item, if necessary */
3365 if (bChanged && !infoPtr->bIsDrawing)
3367 /* this little optimization eliminates some nasty flicker */
3368 if ( uView == LVS_REPORT && !(infoPtr->dwStyle & LVS_OWNERDRAWFIXED) &&
3369 (!(infoPtr->dwLvExStyle & LVS_EX_FULLROWSELECT) || lpLVItem->iSubItem) )
3370 LISTVIEW_InvalidateSubItem(infoPtr, lpLVItem->iItem, lpLVItem->iSubItem);
3372 LISTVIEW_InvalidateItem(infoPtr, lpLVItem->iItem);
3377 textfreeT(lpLVItem->pszText, isW);
3378 ((LVITEMW *)lpLVItem)->pszText = pszText;
3386 * Retrieves the index of the item at coordinate (0, 0) of the client area.
3389 * [I] infoPtr : valid pointer to the listview structure
3394 static INT LISTVIEW_GetTopIndex(LISTVIEW_INFO *infoPtr)
3396 LONG lStyle = infoPtr->dwStyle;
3397 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
3399 SCROLLINFO scrollInfo;
3401 scrollInfo.cbSize = sizeof(SCROLLINFO);
3402 scrollInfo.fMask = SIF_POS;
3404 if (uView == LVS_LIST)
3406 if ((lStyle & WS_HSCROLL) && GetScrollInfo(infoPtr->hwndSelf, SB_HORZ, &scrollInfo))
3407 nItem = scrollInfo.nPos * LISTVIEW_GetCountPerColumn(infoPtr);
3409 else if (uView == LVS_REPORT)
3411 if ((lStyle & WS_VSCROLL) && GetScrollInfo(infoPtr->hwndSelf, SB_VERT, &scrollInfo))
3412 nItem = scrollInfo.nPos;
3416 if ((lStyle & WS_VSCROLL) && GetScrollInfo(infoPtr->hwndSelf, SB_VERT, &scrollInfo))
3417 nItem = LISTVIEW_GetCountPerRow(infoPtr) * (scrollInfo.nPos / infoPtr->nItemHeight);
3420 TRACE("nItem=%d\n", nItem);
3428 * Erases the background of the given rectangle
3431 * [I] infoPtr : valid pointer to the listview structure
3432 * [I] hdc : device context handle
3433 * [I] lprcBox : clipping rectangle
3439 static inline BOOL LISTVIEW_FillBkgnd(LISTVIEW_INFO *infoPtr, HDC hdc, const RECT *lprcBox)
3441 if (!infoPtr->hBkBrush) return FALSE;
3443 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc, debugrect(lprcBox), infoPtr->hBkBrush);
3445 return FillRect(hdc, lprcBox, infoPtr->hBkBrush);
3453 * [I] infoPtr : valid pointer to the listview structure
3454 * [I] hdc : device context handle
3455 * [I] nItem : item index
3456 * [I] nSubItem : subitem index
3457 * [I] pos : item position in client coordinates
3458 * [I] cdmode : custom draw mode
3464 static BOOL LISTVIEW_DrawItem(LISTVIEW_INFO *infoPtr, HDC hdc, INT nItem, INT nSubItem, POINT pos, DWORD cdmode)
3466 UINT uFormat, uView = infoPtr->dwStyle & LVS_TYPEMASK;
3467 WCHAR szDispText[DISP_TEXT_SIZE] = { '\0' };
3468 WCHAR szCallback[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
3469 DWORD cditemmode = CDRF_DODEFAULT;
3470 RECT* lprcFocus, rcSelect, rcBox, rcState, rcIcon, rcLabel;
3471 NMLVCUSTOMDRAW nmlvcd;
3475 TRACE("(hdc=%p, nItem=%d, nSubItem=%d, pos=%s)\n", hdc, nItem, nSubItem, debugpoint(&pos));
3477 /* get information needed for drawing the item */
3478 lvItem.mask = LVIF_TEXT | LVIF_IMAGE;
3479 if (nSubItem == 0) lvItem.mask |= LVIF_STATE | LVIF_PARAM;
3480 if (uView == LVS_REPORT) lvItem.mask |= LVIF_INDENT;
3481 lvItem.stateMask = LVIS_SELECTED | LVIS_FOCUSED | LVIS_STATEIMAGEMASK;
3482 lvItem.iItem = nItem;
3483 lvItem.iSubItem = nSubItem;
3486 lvItem.cchTextMax = DISP_TEXT_SIZE;
3487 lvItem.pszText = szDispText;
3488 if (!LISTVIEW_GetItemW(infoPtr, &lvItem)) return FALSE;
3489 if (nSubItem > 0 && (infoPtr->dwLvExStyle & LVS_EX_FULLROWSELECT))
3490 lvItem.state = LISTVIEW_GetItemState(infoPtr, nItem, LVIS_SELECTED);
3491 if (lvItem.pszText == LPSTR_TEXTCALLBACKW) lvItem.pszText = szCallback;
3492 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem, TRUE));
3494 /* now check if we need to update the focus rectangle */
3495 lprcFocus = infoPtr->bFocus && (lvItem.state & LVIS_FOCUSED) ? &infoPtr->rcFocus : 0;
3497 if (!lprcFocus) lvItem.state &= ~LVIS_FOCUSED;
3498 LISTVIEW_GetItemMetrics(infoPtr, &lvItem, &rcBox, &rcState, &rcIcon, &rcLabel);
3499 OffsetRect(&rcBox, pos.x, pos.y);
3500 OffsetRect(&rcState, pos.x, pos.y);
3501 OffsetRect(&rcIcon, pos.x, pos.y);
3502 OffsetRect(&rcLabel, pos.x, pos.y);
3503 TRACE(" rcBox=%s, rcState=%s, rcIcon=%s. rcLabel=%s\n",
3504 debugrect(&rcBox), debugrect(&rcState), debugrect(&rcIcon), debugrect(&rcLabel));
3506 /* fill in the custom draw structure */
3507 customdraw_fill(&nmlvcd, infoPtr, hdc, &rcBox);
3508 nmlvcd.nmcd.dwItemSpec = lvItem.iItem;
3509 nmlvcd.iSubItem = lvItem.iSubItem;
3510 if (lvItem.state & LVIS_SELECTED) nmlvcd.nmcd.uItemState |= CDIS_SELECTED;
3511 if (lvItem.state & LVIS_FOCUSED) nmlvcd.nmcd.uItemState |= CDIS_FOCUS;
3512 if (lvItem.iItem == infoPtr->nHotItem) nmlvcd.nmcd.uItemState |= CDIS_HOT;
3513 nmlvcd.nmcd.lItemlParam = lvItem.lParam;
3515 if (cdmode & CDRF_NOTIFYITEMDRAW)
3516 cditemmode = notify_customdraw (infoPtr, CDDS_ITEMPREPAINT, &nmlvcd);
3517 if (cditemmode & CDRF_SKIPDEFAULT) goto postpaint;
3519 /* apprently, for selected items, we have to override the returned values */
3520 if (lvItem.state & LVIS_SELECTED)
3522 if (infoPtr->bFocus)
3524 nmlvcd.clrTextBk = comctl32_color.clrHighlight;
3525 nmlvcd.clrText = comctl32_color.clrHighlightText;
3527 else if (infoPtr->dwStyle & LVS_SHOWSELALWAYS)
3529 nmlvcd.clrTextBk = comctl32_color.clr3dFace;
3530 nmlvcd.clrText = comctl32_color.clrBtnText;
3534 /* in full row select, subitems, will just use main item's colors */
3535 if (nSubItem && uView == LVS_REPORT && (infoPtr->dwLvExStyle & LVS_EX_FULLROWSELECT))
3536 nmlvcd.clrTextBk = CLR_NONE;
3539 if (infoPtr->himlState && !IsRectEmpty(&rcState))
3541 UINT uStateImage = (lvItem.state & LVIS_STATEIMAGEMASK) >> 12;
3544 TRACE("uStateImage=%d\n", uStateImage);
3545 ImageList_Draw(infoPtr->himlState, uStateImage - 1, hdc, rcState.left, rcState.top, ILD_NORMAL);
3550 himl = (uView == LVS_ICON ? infoPtr->himlNormal : infoPtr->himlSmall);
3551 if (himl && lvItem.iImage >= 0 && !IsRectEmpty(&rcIcon))
3553 TRACE("iImage=%d\n", lvItem.iImage);
3554 ImageList_Draw(himl, lvItem.iImage, hdc, rcIcon.left, rcIcon.top,
3555 (lvItem.state & LVIS_SELECTED) && (infoPtr->bFocus) ? ILD_SELECTED : ILD_NORMAL);
3558 /* Don't bother painting item being edited */
3559 if (infoPtr->hwndEdit && nItem == infoPtr->nEditLabelItem && nSubItem == 0) goto postpaint;
3561 /* Set the text attributes */
3562 if (nmlvcd.clrTextBk != CLR_NONE)
3564 SetBkMode(hdc, OPAQUE);
3565 SetBkColor(hdc, nmlvcd.clrTextBk == CLR_DEFAULT ? infoPtr->clrTextBkDefault : nmlvcd.clrTextBk);
3568 SetBkMode(hdc, TRANSPARENT);
3569 SetTextColor(hdc, nmlvcd.clrText);
3571 /* draw the selection background, if we're drawing the main item */
3575 if (uView == LVS_REPORT && (infoPtr->dwLvExStyle & LVS_EX_FULLROWSELECT))
3576 rcSelect.right = rcBox.right;
3578 if (nmlvcd.clrTextBk != CLR_NONE)
3579 ExtTextOutW(hdc, rcSelect.left, rcSelect.top, ETO_OPAQUE, &rcSelect, 0, 0, 0);
3580 if(lprcFocus) *lprcFocus = rcSelect;
3583 /* figure out the text drawing flags */
3584 uFormat = (uView == LVS_ICON ? (lprcFocus ? LV_FL_DT_FLAGS : LV_ML_DT_FLAGS) : LV_SL_DT_FLAGS);
3585 if (uView == LVS_ICON)
3586 uFormat = (lprcFocus ? LV_FL_DT_FLAGS : LV_ML_DT_FLAGS);
3589 switch (LISTVIEW_GetColumnInfo(infoPtr, nSubItem)->fmt & LVCFMT_JUSTIFYMASK)
3591 case LVCFMT_RIGHT: uFormat |= DT_RIGHT; break;
3592 case LVCFMT_CENTER: uFormat |= DT_CENTER; break;
3593 default: uFormat |= DT_LEFT;
3596 if (!(uFormat & (DT_RIGHT | DT_CENTER)))
3598 if (himl && lvItem.iImage >= 0 && !IsRectEmpty(&rcIcon)) rcLabel.left += IMAGE_PADDING;
3599 else rcLabel.left += LABEL_HOR_PADDING;
3601 else if (uFormat & DT_RIGHT) rcLabel.right -= LABEL_HOR_PADDING;
3602 DrawTextW(hdc, lvItem.pszText, -1, &rcLabel, uFormat);
3605 if (cditemmode & CDRF_NOTIFYPOSTPAINT)
3606 notify_customdraw(infoPtr, CDDS_ITEMPOSTPAINT, &nmlvcd);
3612 * Draws listview items when in owner draw mode.
3615 * [I] infoPtr : valid pointer to the listview structure
3616 * [I] hdc : device context handle
3621 static void LISTVIEW_RefreshOwnerDraw(LISTVIEW_INFO *infoPtr, HDC hdc)
3623 UINT uID = GetWindowLongW(infoPtr->hwndSelf, GWL_ID);
3624 HWND hwndParent = GetParent(infoPtr->hwndSelf);
3625 POINT Origin, Position;
3632 ZeroMemory(&dis, sizeof(dis));
3634 /* Get scroll info once before loop */
3635 LISTVIEW_GetOrigin(infoPtr, &Origin);
3637 /* figure out what we need to draw */
3638 iterator_visibleitems(&i, infoPtr, hdc);
3640 /* send cache hint notification */
3641 if (infoPtr->dwStyle & LVS_OWNERDATA)
3643 RANGE range = iterator_range(&i);
3646 ZeroMemory(&nmlv, sizeof(NMLVCACHEHINT));
3647 nmlv.iFrom = range.lower;
3648 nmlv.iTo = range.upper - 1;
3649 notify_hdr(infoPtr, LVN_ODCACHEHINT, &nmlv.hdr);
3652 /* iterate through the invalidated rows */
3653 while(iterator_next(&i))
3655 item.iItem = i.nItem;
3657 item.mask = LVIF_PARAM | LVIF_STATE;
3658 item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
3659 if (!LISTVIEW_GetItemW(infoPtr, &item)) continue;
3661 dis.CtlType = ODT_LISTVIEW;
3663 dis.itemID = item.iItem;
3664 dis.itemAction = ODA_DRAWENTIRE;
3666 if (item.state & LVIS_SELECTED) dis.itemState |= ODS_SELECTED;
3667 if (infoPtr->bFocus && (item.state & LVIS_FOCUSED)) dis.itemState |= ODS_FOCUS;
3668 dis.hwndItem = infoPtr->hwndSelf;
3670 LISTVIEW_GetItemOrigin(infoPtr, dis.itemID, &Position);
3671 dis.rcItem.left = Position.x + Origin.x;
3672 dis.rcItem.right = dis.rcItem.left + infoPtr->nItemWidth;
3673 dis.rcItem.top = Position.y + Origin.y;
3674 dis.rcItem.bottom = dis.rcItem.top + infoPtr->nItemHeight;
3675 dis.itemData = item.lParam;
3677 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item, TRUE), debugrect(&dis.rcItem));
3678 SendMessageW(hwndParent, WM_DRAWITEM, dis.CtlID, (LPARAM)&dis);
3680 iterator_destroy(&i);
3685 * Draws listview items when in report display mode.
3688 * [I] infoPtr : valid pointer to the listview structure
3689 * [I] hdc : device context handle
3690 * [I] cdmode : custom draw mode
3695 static void LISTVIEW_RefreshReport(LISTVIEW_INFO *infoPtr, HDC hdc, DWORD cdmode)
3698 RECT rcClip, rcItem;
3699 POINT Origin, Position;
3705 /* figure out what to draw */
3706 rgntype = GetClipBox(hdc, &rcClip);
3707 if (rgntype == NULLREGION) return;
3709 /* Get scroll info once before loop */
3710 LISTVIEW_GetOrigin(infoPtr, &Origin);
3712 /* narrow down the columns we need to paint */
3713 for(colRange.lower = 0; colRange.lower < infoPtr->hdpaColumns->nItemCount; colRange.lower++)
3715 LISTVIEW_GetHeaderRect(infoPtr, colRange.lower, &rcItem);
3716 if (rcItem.right + Origin.x >= rcClip.left) break;
3718 for(colRange.upper = infoPtr->hdpaColumns->nItemCount; colRange.upper > 0; colRange.upper--)
3720 LISTVIEW_GetHeaderRect(infoPtr, colRange.upper - 1, &rcItem);
3721 if (rcItem.left + Origin.x < rcClip.right) break;
3723 iterator_rangeitems(&j, colRange);
3725 /* in full row select, we _have_ to draw the main item */
3726 if (infoPtr->dwLvExStyle & LVS_EX_FULLROWSELECT)
3729 /* figure out what we need to draw */
3730 iterator_visibleitems(&i, infoPtr, hdc);
3732 /* iterate through the invalidated rows */
3733 while(iterator_next(&i))
3735 /* iterate through the invalidated columns */
3736 while(iterator_next(&j))
3738 LISTVIEW_GetItemOrigin(infoPtr, i.nItem, &Position);
3739 Position.x += Origin.x;
3740 Position.y += Origin.y;
3742 if (rgntype == COMPLEXREGION && !((infoPtr->dwLvExStyle & LVS_EX_FULLROWSELECT) && j.nItem == 0))
3744 LISTVIEW_GetHeaderRect(infoPtr, j.nItem, &rcItem);
3746 rcItem.bottom = infoPtr->nItemHeight;
3747 OffsetRect(&rcItem, Position.x, Position.y);
3748 if (!RectVisible(hdc, &rcItem)) continue;
3751 LISTVIEW_DrawItem(infoPtr, hdc, i.nItem, j.nItem, Position, cdmode);
3754 iterator_destroy(&i);
3759 * Draws listview items when in list display mode.
3762 * [I] infoPtr : valid pointer to the listview structure
3763 * [I] hdc : device context handle
3764 * [I] cdmode : custom draw mode
3769 static void LISTVIEW_RefreshList(LISTVIEW_INFO *infoPtr, HDC hdc, DWORD cdmode)
3771 POINT Origin, Position;
3774 /* Get scroll info once before loop */
3775 LISTVIEW_GetOrigin(infoPtr, &Origin);
3777 /* figure out what we need to draw */
3778 iterator_visibleitems(&i, infoPtr, hdc);
3780 while(iterator_prev(&i))
3782 LISTVIEW_GetItemOrigin(infoPtr, i.nItem, &Position);
3783 Position.x += Origin.x;
3784 Position.y += Origin.y;
3786 LISTVIEW_DrawItem(infoPtr, hdc, i.nItem, 0, Position, cdmode);
3788 iterator_destroy(&i);
3794 * Draws listview items.
3797 * [I] infoPtr : valid pointer to the listview structure
3798 * [I] hdc : device context handle
3803 static void LISTVIEW_Refresh(LISTVIEW_INFO *infoPtr, HDC hdc)
3805 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
3806 COLORREF oldTextColor, oldClrTextBk, oldClrText;
3807 NMLVCUSTOMDRAW nmlvcd;
3813 LISTVIEW_DUMP(infoPtr);
3815 infoPtr->bIsDrawing = TRUE;
3817 /* save dc values we're gonna trash while drawing */
3818 hOldFont = SelectObject(hdc, infoPtr->hFont);
3819 oldBkMode = GetBkMode(hdc);
3820 infoPtr->clrTextBkDefault = GetBkColor(hdc);
3821 oldTextColor = GetTextColor(hdc);
3823 oldClrTextBk = infoPtr->clrTextBk;
3824 oldClrText = infoPtr->clrText;
3826 GetClientRect(infoPtr->hwndSelf, &rcClient);
3827 customdraw_fill(&nmlvcd, infoPtr, hdc, &rcClient);
3828 cdmode = notify_customdraw(infoPtr, CDDS_PREPAINT, &nmlvcd);
3829 if (cdmode & CDRF_SKIPDEFAULT) goto enddraw;
3831 /* Use these colors to draw the items */
3832 infoPtr->clrTextBk = nmlvcd.clrTextBk;
3833 infoPtr->clrText = nmlvcd.clrText;
3835 /* nothing to draw */
3836 if(infoPtr->nItemCount == 0) goto enddraw;
3838 if ((infoPtr->dwStyle & LVS_OWNERDRAWFIXED) && (uView == LVS_REPORT))
3839 LISTVIEW_RefreshOwnerDraw(infoPtr, hdc);
3842 if (uView == LVS_REPORT)
3843 LISTVIEW_RefreshReport(infoPtr, hdc, cdmode);
3844 else /* LVS_LIST, LVS_ICON or LVS_SMALLICON */
3845 LISTVIEW_RefreshList(infoPtr, hdc, cdmode);
3847 /* if we have a focus rect, draw it */
3848 if (infoPtr->bFocus)
3849 DrawFocusRect(hdc, &infoPtr->rcFocus);
3853 if (cdmode & CDRF_NOTIFYPOSTPAINT)
3854 notify_customdraw(infoPtr, CDDS_POSTPAINT, &nmlvcd);
3856 infoPtr->clrTextBk = oldClrTextBk;
3857 infoPtr->clrText = oldClrText;
3859 SelectObject(hdc, hOldFont);
3860 SetBkMode(hdc, oldBkMode);
3861 SetBkColor(hdc, infoPtr->clrTextBkDefault);
3862 SetTextColor(hdc, oldTextColor);
3863 infoPtr->bIsDrawing = FALSE;
3869 * Calculates the approximate width and height of a given number of items.
3872 * [I] infoPtr : valid pointer to the listview structure
3873 * [I] nItemCount : number of items
3874 * [I] wWidth : width
3875 * [I] wHeight : height
3878 * Returns a DWORD. The width in the low word and the height in high word.
3880 static DWORD LISTVIEW_ApproximateViewRect(LISTVIEW_INFO *infoPtr, INT nItemCount,
3881 WORD wWidth, WORD wHeight)
3883 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
3884 INT nItemCountPerColumn = 1;
3885 INT nColumnCount = 0;
3886 DWORD dwViewRect = 0;
3888 if (nItemCount == -1)
3889 nItemCount = infoPtr->nItemCount;
3891 if (uView == LVS_LIST)
3893 if (wHeight == 0xFFFF)
3895 /* use current height */
3896 wHeight = infoPtr->rcList.bottom - infoPtr->rcList.top;
3899 if (wHeight < infoPtr->nItemHeight)
3900 wHeight = infoPtr->nItemHeight;
3904 if (infoPtr->nItemHeight > 0)
3906 nItemCountPerColumn = wHeight / infoPtr->nItemHeight;
3907 if (nItemCountPerColumn == 0)
3908 nItemCountPerColumn = 1;
3910 if (nItemCount % nItemCountPerColumn != 0)
3911 nColumnCount = nItemCount / nItemCountPerColumn;
3913 nColumnCount = nItemCount / nItemCountPerColumn + 1;
3917 /* Microsoft padding magic */
3918 wHeight = nItemCountPerColumn * infoPtr->nItemHeight + 2;
3919 wWidth = nColumnCount * infoPtr->nItemWidth + 2;
3921 dwViewRect = MAKELONG(wWidth, wHeight);
3923 else if (uView == LVS_REPORT)
3924 FIXME("uView == LVS_REPORT: not implemented\n");
3925 else if (uView == LVS_SMALLICON)
3926 FIXME("uView == LVS_SMALLICON: not implemented\n");
3927 else if (uView == LVS_ICON)
3928 FIXME("uView == LVS_ICON: not implemented\n");
3933 /* << LISTVIEW_CreateDragImage >> */
3938 * Removes all listview items and subitems.
3941 * [I] infoPtr : valid pointer to the listview structure
3947 static BOOL LISTVIEW_DeleteAllItems(LISTVIEW_INFO *infoPtr)
3950 HDPA hdpaSubItems = NULL;
3957 /* we do it directly, to avoid notifications */
3958 ranges_clear(infoPtr->selectionRanges);
3959 infoPtr->nSelectionMark = -1;
3960 infoPtr->nFocusedItem = -1;
3961 SetRectEmpty(&infoPtr->rcFocus);
3962 /* But we are supposed to leave nHotItem as is! */
3965 /* send LVN_DELETEALLITEMS notification */
3966 ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
3968 bSuppress = notify_listview(infoPtr, LVN_DELETEALLITEMS, &nmlv);
3970 for (i = infoPtr->nItemCount - 1; i >= 0; i--)
3972 /* send LVN_DELETEITEM notification, if not supressed */
3973 if (!bSuppress) notify_deleteitem(infoPtr, i);
3974 if (!(infoPtr->dwStyle & LVS_OWNERDATA))
3976 hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, i);
3977 for (j = 0; j < hdpaSubItems->nItemCount; j++)
3979 hdrItem = (ITEMHDR *)DPA_GetPtr(hdpaSubItems, j);
3980 if (is_textW(hdrItem->pszText)) COMCTL32_Free(hdrItem->pszText);
3981 COMCTL32_Free(hdrItem);
3983 DPA_Destroy(hdpaSubItems);
3984 DPA_DeletePtr(infoPtr->hdpaItems, i);
3986 DPA_DeletePtr(infoPtr->hdpaPosX, i);
3987 DPA_DeletePtr(infoPtr->hdpaPosY, i);
3988 infoPtr->nItemCount --;
3991 LISTVIEW_UpdateScroll(infoPtr);
3993 LISTVIEW_InvalidateList(infoPtr);
4000 * Scrolls, and updates the columns, when a column is changing width.
4003 * [I] infoPtr : valid pointer to the listview structure
4004 * [I] nColumn : column to scroll
4005 * [I] dx : amount of scroll, in pixels
4010 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO *infoPtr, INT nColumn, INT dx)
4012 COLUMN_INFO *lpColumnInfo;
4016 lpColumnInfo = LISTVIEW_GetColumnInfo(infoPtr, min(nColumn, infoPtr->hdpaColumns->nItemCount - 1));
4017 rcCol = lpColumnInfo->rcHeader;
4018 if (nColumn >= infoPtr->hdpaColumns->nItemCount)
4019 rcCol.left = rcCol.right;
4021 /* ajust the other columns */
4022 for (nCol = nColumn; nCol < infoPtr->hdpaColumns->nItemCount; nCol++)
4024 lpColumnInfo = LISTVIEW_GetColumnInfo(infoPtr, nCol);
4025 lpColumnInfo->rcHeader.left += dx;
4026 lpColumnInfo->rcHeader.right += dx;
4029 /* do not update screen if not in report mode */
4030 if (!is_redrawing(infoPtr) || (infoPtr->dwStyle & LVS_TYPEMASK) != LVS_REPORT) return;
4032 /* if we have a focus, must first erase the focus rect */
4033 if (infoPtr->bFocus) LISTVIEW_ShowFocusRect(infoPtr, FALSE);
4035 /* Need to reset the item width when inserting a new column */
4036 infoPtr->nItemWidth += dx;
4038 LISTVIEW_UpdateScroll(infoPtr);
4040 /* scroll to cover the deleted column, and invalidate for redraw */
4041 rcOld = infoPtr->rcList;
4042 rcOld.left = rcCol.left;
4043 ScrollWindowEx(infoPtr->hwndSelf, dx, 0, &rcOld, &rcOld, 0, 0, SW_ERASE | SW_INVALIDATE);
4045 /* we can restore focus now */
4046 if (infoPtr->bFocus) LISTVIEW_ShowFocusRect(infoPtr, TRUE);
4051 * Removes a column from the listview control.
4054 * [I] infoPtr : valid pointer to the listview structure
4055 * [I] nColumn : column index
4061 static BOOL LISTVIEW_DeleteColumn(LISTVIEW_INFO *infoPtr, INT nColumn)
4065 TRACE("nColumn=%d\n", nColumn);
4067 if (nColumn < 0 || infoPtr->hdpaColumns->nItemCount == 0
4068 || nColumn >= infoPtr->hdpaColumns->nItemCount) return FALSE;
4070 /* While the MSDN specifically says that column zero should not be deleted,
4071 it does in fact work on WinNT, and at least one app depends on it. On
4072 WinNT, deleting column zero deletes the last column of items but the
4073 first header. Since no app will ever depend on that bizarre behavior,
4074 we just delete the last column including the header.
4077 nColumn = infoPtr->hdpaColumns->nItemCount - 1;
4079 LISTVIEW_GetHeaderRect(infoPtr, nColumn, &rcCol);
4081 if (!Header_DeleteItem(infoPtr->hwndHeader, nColumn))
4084 COMCTL32_Free(DPA_GetPtr(infoPtr->hdpaColumns, nColumn));
4085 DPA_DeletePtr(infoPtr->hdpaColumns, nColumn);
4087 if (!(infoPtr->dwStyle & LVS_OWNERDATA))
4089 SUBITEM_INFO *lpSubItem, *lpDelItem;
4091 INT nItem, nSubItem, i;
4094 return LISTVIEW_DeleteAllItems(infoPtr);
4096 for (nItem = 0; nItem < infoPtr->nItemCount; nItem++)
4098 hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem);
4101 for (i = 1; i < hdpaSubItems->nItemCount; i++)
4103 lpSubItem = (SUBITEM_INFO *)DPA_GetPtr(hdpaSubItems, i);
4104 if (lpSubItem->iSubItem == nColumn)
4107 lpDelItem = lpSubItem;
4109 else if (lpSubItem->iSubItem > nColumn)
4111 lpSubItem->iSubItem--;
4115 /* if we found our subitem, zapp it */
4119 if (is_textW(lpDelItem->hdr.pszText))
4120 COMCTL32_Free(lpDelItem->hdr.pszText);
4123 COMCTL32_Free(lpDelItem);
4125 /* free dpa memory */
4126 DPA_DeletePtr(hdpaSubItems, nSubItem);
4131 /* update the other column info */
4132 LISTVIEW_ScrollColumns(infoPtr, nColumn, -(rcCol.right - rcCol.left));
4139 * Invalidates the listview after an item's insertion or deletion.
4142 * [I] infoPtr : valid pointer to the listview structure
4143 * [I] nItem : item index
4144 * [I] dir : -1 if deleting, 1 if inserting
4149 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO *infoPtr, INT nItem, INT dir)
4151 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
4152 INT nPerCol, nItemCol, nItemRow;
4156 /* if we don't refresh, what's the point of scrolling? */
4157 if (!is_redrawing(infoPtr)) return;
4159 assert (abs(dir) == 1);
4161 /* arrange icons if autoarrange is on */
4162 if (is_autoarrange(infoPtr))
4164 BOOL arrange = TRUE;
4165 if (dir < 0 && nItem >= infoPtr->nItemCount) arrange = FALSE;
4166 if (dir > 0 && nItem == infoPtr->nItemCount - 1) arrange = FALSE;
4167 if (arrange) LISTVIEW_Arrange(infoPtr, LVA_DEFAULT);
4170 /* scrollbars need updating */
4171 LISTVIEW_UpdateScroll(infoPtr);
4173 /* figure out the item's position */
4174 if (uView == LVS_REPORT)
4175 nPerCol = infoPtr->nItemCount + 1;
4176 else if (uView == LVS_LIST)
4177 nPerCol = LISTVIEW_GetCountPerColumn(infoPtr);
4178 else /* LVS_ICON, or LVS_SMALLICON */
4181 nItemCol = nItem / nPerCol;
4182 nItemRow = nItem % nPerCol;
4183 LISTVIEW_GetOrigin(infoPtr, &Origin);
4185 /* move the items below up a slot */
4186 rcScroll.left = nItemCol * infoPtr->nItemWidth;
4187 rcScroll.top = nItemRow * infoPtr->nItemHeight;
4188 rcScroll.right = rcScroll.left + infoPtr->nItemWidth;
4189 rcScroll.bottom = nPerCol * infoPtr->nItemHeight;
4190 OffsetRect(&rcScroll, Origin.x, Origin.y);
4191 TRACE("rcScroll=%s, dx=%d\n", debugrect(&rcScroll), dir * infoPtr->nItemHeight);
4192 if (IntersectRect(&rcScroll, &rcScroll, &infoPtr->rcList))
4194 TRACE("Scrolling rcScroll=%s, rcList=%s\n", debugrect(&rcScroll), debugrect(&infoPtr->rcList));
4195 ScrollWindowEx(infoPtr->hwndSelf, 0, dir * infoPtr->nItemHeight,
4196 &rcScroll, &rcScroll, 0, 0, SW_ERASE | SW_INVALIDATE);
4199 /* report has only that column, so we're done */
4200 if (uView == LVS_REPORT) return;
4202 /* now for LISTs, we have to deal with the columns to the right */
4203 rcScroll.left = (nItemCol + 1) * infoPtr->nItemWidth;
4205 rcScroll.right = (infoPtr->nItemCount / nPerCol + 1) * infoPtr->nItemWidth;
4206 rcScroll.bottom = nPerCol * infoPtr->nItemHeight;
4207 OffsetRect(&rcScroll, Origin.x, Origin.y);
4208 if (IntersectRect(&rcScroll, &rcScroll, &infoPtr->rcList))
4209 ScrollWindowEx(infoPtr->hwndSelf, 0, dir * infoPtr->nItemHeight,
4210 &rcScroll, &rcScroll, 0, 0, SW_ERASE | SW_INVALIDATE);
4215 * Removes an item from the listview control.
4218 * [I] infoPtr : valid pointer to the listview structure
4219 * [I] nItem : item index
4225 static BOOL LISTVIEW_DeleteItem(LISTVIEW_INFO *infoPtr, INT nItem)
4227 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
4230 TRACE("(nItem=%d)\n", nItem);
4232 if (nItem < 0 || nItem >= infoPtr->nItemCount) return FALSE;
4234 /* remove selection, and focus */
4236 item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
4237 LISTVIEW_SetItemState(infoPtr, nItem, &item);
4239 /* send LVN_DELETEITEM notification. */
4240 notify_deleteitem(infoPtr, nItem);
4242 /* we need to do this here, because we'll be deleting stuff */
4243 if (uView == LVS_SMALLICON || uView == LVS_ICON)
4244 LISTVIEW_InvalidateItem(infoPtr, nItem);
4246 if (!(infoPtr->dwStyle & LVS_OWNERDATA))
4252 hdpaSubItems = (HDPA)DPA_DeletePtr(infoPtr->hdpaItems, nItem);
4253 for (i = 0; i < hdpaSubItems->nItemCount; i++)
4255 hdrItem = (ITEMHDR *)DPA_GetPtr(hdpaSubItems, i);
4256 if (is_textW(hdrItem->pszText)) COMCTL32_Free(hdrItem->pszText);
4257 COMCTL32_Free(hdrItem);
4259 DPA_Destroy(hdpaSubItems);
4262 if (uView == LVS_SMALLICON || uView == LVS_ICON)
4264 DPA_DeletePtr(infoPtr->hdpaPosX, nItem);
4265 DPA_DeletePtr(infoPtr->hdpaPosY, nItem);
4268 infoPtr->nItemCount--;
4269 LISTVIEW_ShiftIndices(infoPtr, nItem, -1);
4271 /* now is the invalidation fun */
4272 LISTVIEW_ScrollOnInsert(infoPtr, nItem, -1);
4279 * Callback implementation for editlabel control
4282 * [I] infoPtr : valid pointer to the listview structure
4283 * [I] pszText : modified text
4284 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
4290 static BOOL LISTVIEW_EndEditLabelT(LISTVIEW_INFO *infoPtr, LPWSTR pszText, BOOL isW)
4292 NMLVDISPINFOW dispInfo;
4294 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText, isW), isW);
4296 ZeroMemory(&dispInfo, sizeof(dispInfo));
4297 dispInfo.item.mask = LVIF_PARAM | LVIF_STATE;
4298 dispInfo.item.iItem = infoPtr->nEditLabelItem;
4299 dispInfo.item.iSubItem = 0;
4300 dispInfo.item.stateMask = ~0;
4301 if (!LISTVIEW_GetItemW(infoPtr, &dispInfo.item)) return FALSE;
4302 /* add the text from the edit in */
4303 dispInfo.item.mask |= LVIF_TEXT;
4304 dispInfo.item.pszText = pszText;
4305 dispInfo.item.cchTextMax = textlenT(pszText, isW);
4307 /* Do we need to update the Item Text */
4308 if (!notify_dispinfoT(infoPtr, LVN_ENDLABELEDITW, &dispInfo, isW)) return FALSE;
4309 if (!pszText) return TRUE;
4311 ZeroMemory(&dispInfo, sizeof(dispInfo));
4312 dispInfo.item.mask = LVIF_TEXT;
4313 dispInfo.item.iItem = infoPtr->nEditLabelItem;
4314 dispInfo.item.iSubItem = 0;
4315 dispInfo.item.pszText = pszText;
4316 dispInfo.item.cchTextMax = textlenT(pszText, isW);
4317 return LISTVIEW_SetItemT(infoPtr, &dispInfo.item, isW);
4322 * Begin in place editing of specified list view item
4325 * [I] infoPtr : valid pointer to the listview structure
4326 * [I] nItem : item index
4327 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
4333 static HWND LISTVIEW_EditLabelT(LISTVIEW_INFO *infoPtr, INT nItem, BOOL isW)
4335 WCHAR szDispText[DISP_TEXT_SIZE] = { 0 };
4336 NMLVDISPINFOW dispInfo;
4339 TRACE("(nItem=%d, isW=%d)\n", nItem, isW);
4341 if (~infoPtr->dwStyle & LVS_EDITLABELS) return 0;
4342 if (nItem < 0 || nItem >= infoPtr->nItemCount) return 0;
4344 infoPtr->nEditLabelItem = nItem;
4346 /* Is the EditBox still there, if so remove it */
4347 if(infoPtr->hwndEdit != 0)
4349 SetFocus(infoPtr->hwndSelf);
4350 infoPtr->hwndEdit = 0;
4353 LISTVIEW_SetSelection(infoPtr, nItem);
4354 LISTVIEW_SetItemFocus(infoPtr, nItem);
4355 LISTVIEW_InvalidateItem(infoPtr, nItem);
4357 rect.left = LVIR_LABEL;
4358 if (!LISTVIEW_GetItemRect(infoPtr, nItem, &rect)) return 0;
4360 ZeroMemory(&dispInfo, sizeof(dispInfo));
4361 dispInfo.item.mask = LVIF_PARAM | LVIF_STATE | LVIF_TEXT;
4362 dispInfo.item.iItem = nItem;
4363 dispInfo.item.iSubItem = 0;
4364 dispInfo.item.stateMask = ~0;
4365 dispInfo.item.pszText = szDispText;
4366 dispInfo.item.cchTextMax = DISP_TEXT_SIZE;
4367 if (!LISTVIEW_GetItemT(infoPtr, &dispInfo.item, isW)) return 0;
4369 infoPtr->hwndEdit = CreateEditLabelT(infoPtr, dispInfo.item.pszText, WS_VISIBLE,
4370 rect.left-2, rect.top-1, 0, rect.bottom - rect.top+2, isW);
4371 if (!infoPtr->hwndEdit) return 0;
4373 if (notify_dispinfoT(infoPtr, LVN_BEGINLABELEDITW, &dispInfo, isW))
4375 SendMessageW(infoPtr->hwndEdit, WM_CLOSE, 0, 0);
4376 infoPtr->hwndEdit = 0;
4380 ShowWindow(infoPtr->hwndEdit, SW_NORMAL);
4381 SetFocus(infoPtr->hwndEdit);
4382 SendMessageW(infoPtr->hwndEdit, EM_SETSEL, 0, -1);
4383 return infoPtr->hwndEdit;
4389 * Ensures the specified item is visible, scrolling into view if necessary.
4392 * [I] infoPtr : valid pointer to the listview structure
4393 * [I] nItem : item index
4394 * [I] bPartial : partially or entirely visible
4400 static BOOL LISTVIEW_EnsureVisible(LISTVIEW_INFO *infoPtr, INT nItem, BOOL bPartial)
4402 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
4403 INT nScrollPosHeight = 0;
4404 INT nScrollPosWidth = 0;
4405 INT nHorzAdjust = 0;
4406 INT nVertAdjust = 0;
4409 RECT rcItem, rcTemp;
4411 rcItem.left = LVIR_BOUNDS;
4412 if (!LISTVIEW_GetItemRect(infoPtr, nItem, &rcItem)) return FALSE;
4414 if (bPartial && IntersectRect(&rcTemp, &infoPtr->rcList, &rcItem)) return TRUE;
4416 if (rcItem.left < infoPtr->rcList.left || rcItem.right > infoPtr->rcList.right)
4418 /* scroll left/right, but in LVS_REPORT mode */
4419 if (uView == LVS_LIST)
4420 nScrollPosWidth = infoPtr->nItemWidth;
4421 else if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
4422 nScrollPosWidth = 1;
4424 if (rcItem.left < infoPtr->rcList.left)
4427 if (uView != LVS_REPORT) nHorzDiff = rcItem.left - infoPtr->rcList.left;
4432 if (uView != LVS_REPORT) nHorzDiff = rcItem.right - infoPtr->rcList.right;
4436 if (rcItem.top < infoPtr->rcList.top || rcItem.bottom > infoPtr->rcList.bottom)
4438 /* scroll up/down, but not in LVS_LIST mode */
4439 if (uView == LVS_REPORT)
4440 nScrollPosHeight = infoPtr->nItemHeight;
4441 else if ((uView == LVS_ICON) || (uView == LVS_SMALLICON))
4442 nScrollPosHeight = 1;
4444 if (rcItem.top < infoPtr->rcList.top)
4447 if (uView != LVS_LIST) nVertDiff = rcItem.top - infoPtr->rcList.top;
4452 if (uView != LVS_LIST) nVertDiff = rcItem.bottom - infoPtr->rcList.bottom;
4456 if (!nScrollPosWidth && !nScrollPosHeight) return TRUE;
4458 if (nScrollPosWidth)
4460 INT diff = nHorzDiff / nScrollPosWidth;
4461 if (nHorzDiff % nScrollPosWidth) diff += nHorzAdjust;
4462 LISTVIEW_HScroll(infoPtr, SB_INTERNAL, diff, 0);
4465 if (nScrollPosHeight)
4467 INT diff = nVertDiff / nScrollPosHeight;
4468 if (nVertDiff % nScrollPosHeight) diff += nVertAdjust;
4469 LISTVIEW_VScroll(infoPtr, SB_INTERNAL, diff, 0);
4477 * Searches for an item with specific characteristics.
4480 * [I] hwnd : window handle
4481 * [I] nStart : base item index
4482 * [I] lpFindInfo : item information to look for
4485 * SUCCESS : index of item
4488 static INT LISTVIEW_FindItemW(LISTVIEW_INFO *infoPtr, INT nStart,
4489 const LVFINDINFOW *lpFindInfo)
4491 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
4492 WCHAR szDispText[DISP_TEXT_SIZE] = { '\0' };
4493 BOOL bWrap = FALSE, bNearest = FALSE;
4494 INT nItem = nStart + 1, nLast = infoPtr->nItemCount, nNearestItem = -1;
4495 ULONG xdist, ydist, dist, mindist = 0x7fffffff;
4496 POINT Position, Destination;
4499 if (!lpFindInfo || nItem < 0) return -1;
4502 if (lpFindInfo->flags & (LVFI_STRING | LVFI_PARTIAL))
4504 lvItem.mask |= LVIF_TEXT;
4505 lvItem.pszText = szDispText;
4506 lvItem.cchTextMax = DISP_TEXT_SIZE;
4509 if (lpFindInfo->flags & LVFI_WRAP)
4512 if ((lpFindInfo->flags & LVFI_NEARESTXY) &&
4513 (uView == LVS_ICON || uView ==LVS_SMALLICON))
4518 LISTVIEW_GetOrigin(infoPtr, &Origin);
4519 Destination.x = lpFindInfo->pt.x - Origin.x;
4520 Destination.y = lpFindInfo->pt.y - Origin.y;
4521 switch(lpFindInfo->vkDirection)
4523 case VK_DOWN: Destination.y += infoPtr->nItemHeight; break;
4524 case VK_UP: Destination.y -= infoPtr->nItemHeight; break;
4525 case VK_RIGHT: Destination.x += infoPtr->nItemWidth; break;
4526 case VK_LEFT: Destination.x -= infoPtr->nItemWidth; break;
4527 case VK_HOME: Destination.x = Destination.y = 0; break;
4528 case VK_NEXT: Destination.y += infoPtr->rcList.bottom - infoPtr->rcList.top; break;
4529 case VK_PRIOR: Destination.y -= infoPtr->rcList.bottom - infoPtr->rcList.top; break;
4531 LISTVIEW_GetAreaRect(infoPtr, &rcArea);
4532 Destination.x = rcArea.right;
4533 Destination.y = rcArea.bottom;
4535 default: ERR("Unknown vkDirection=%d\n", lpFindInfo->vkDirection);
4540 /* if LVFI_PARAM is specified, all other flags are ignored */
4541 if (lpFindInfo->flags & LVFI_PARAM)
4543 lvItem.mask |= LVIF_PARAM;
4545 lvItem.mask &= ~LVIF_TEXT;
4549 for (; nItem < nLast; nItem++)
4551 lvItem.iItem = nItem;
4552 lvItem.iSubItem = 0;
4553 if (!LISTVIEW_GetItemW(infoPtr, &lvItem)) continue;
4555 if (lvItem.mask & LVIF_PARAM)
4557 if (lpFindInfo->lParam == lvItem.lParam)
4563 if (lvItem.mask & LVIF_TEXT)
4565 if (lpFindInfo->flags & LVFI_PARTIAL)
4567 if (strstrW(lvItem.pszText, lpFindInfo->psz) == NULL) continue;
4571 if (lstrcmpW(lvItem.pszText, lpFindInfo->psz) != 0) continue;
4575 if (!bNearest) return nItem;
4577 /* This is very inefficient. To do a good job here,
4578 * we need a sorted array of (x,y) item positions */
4579 LISTVIEW_GetItemOrigin(infoPtr, nItem, &Position);
4581 /* compute the distance^2 to the destination */
4582 xdist = Destination.x - Position.x;
4583 ydist = Destination.y - Position.y;
4584 dist = xdist * xdist + ydist * ydist;
4586 /* remember the distance, and item if it's closer */
4590 nNearestItem = nItem;
4597 nLast = min(nStart + 1, infoPtr->nItemCount);
4602 return nNearestItem;
4607 * Searches for an item with specific characteristics.
4610 * [I] hwnd : window handle
4611 * [I] nStart : base item index
4612 * [I] lpFindInfo : item information to look for
4615 * SUCCESS : index of item
4618 static INT LISTVIEW_FindItemA(LISTVIEW_INFO *infoPtr, INT nStart,
4619 const LVFINDINFOA *lpFindInfo)
4621 BOOL hasText = lpFindInfo->flags & (LVFI_STRING | LVFI_PARTIAL);
4625 memcpy(&fiw, lpFindInfo, sizeof(fiw));
4626 if (hasText) fiw.psz = textdupTtoW((LPCWSTR)lpFindInfo->psz, FALSE);
4627 res = LISTVIEW_FindItemW(infoPtr, nStart, &fiw);
4628 if (hasText) textfreeT((LPWSTR)fiw.psz, FALSE);
4634 * Retrieves the background image of the listview control.
4637 * [I] infoPtr : valid pointer to the listview structure
4638 * [O] lpBkImage : background image attributes
4644 /* static BOOL LISTVIEW_GetBkImage(LISTVIEW_INFO *infoPtr, LPLVBKIMAGE lpBkImage) */
4646 /* FIXME (listview, "empty stub!\n"); */
4652 * Retrieves column attributes.
4655 * [I] infoPtr : valid pointer to the listview structure
4656 * [I] nColumn : column index
4657 * [IO] lpColumn : column information
4658 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
4659 * otherwise it is in fact a LPLVCOLUMNA
4665 static BOOL LISTVIEW_GetColumnT(LISTVIEW_INFO *infoPtr, INT nColumn, LPLVCOLUMNW lpColumn, BOOL isW)
4667 COLUMN_INFO *lpColumnInfo;
4670 if (!lpColumn || nColumn < 0 || nColumn >= infoPtr->hdpaColumns->nItemCount) return FALSE;
4671 lpColumnInfo = LISTVIEW_GetColumnInfo(infoPtr, nColumn);
4673 /* initialize memory */
4674 ZeroMemory(&hdi, sizeof(hdi));
4676 if (lpColumn->mask & LVCF_TEXT)
4678 hdi.mask |= HDI_TEXT;
4679 hdi.pszText = lpColumn->pszText;
4680 hdi.cchTextMax = lpColumn->cchTextMax;
4683 if (lpColumn->mask & LVCF_IMAGE)
4684 hdi.mask |= HDI_IMAGE;
4686 if (lpColumn->mask & LVCF_ORDER)
4687 hdi.mask |= HDI_ORDER;
4689 if (!SendMessageW(infoPtr->hwndHeader, isW ? HDM_GETITEMW : HDM_GETITEMA, nColumn, (LPARAM)&hdi)) return FALSE;
4691 if (lpColumn->mask & LVCF_FMT)
4692 lpColumn->fmt = lpColumnInfo->fmt;
4694 if (lpColumn->mask & LVCF_WIDTH)
4695 lpColumn->cx = lpColumnInfo->rcHeader.right - lpColumnInfo->rcHeader.left;
4697 if (lpColumn->mask & LVCF_IMAGE)
4698 lpColumn->iImage = hdi.iImage;
4700 if (lpColumn->mask & LVCF_ORDER)
4701 lpColumn->iOrder = hdi.iOrder;
4707 static BOOL LISTVIEW_GetColumnOrderArray(LISTVIEW_INFO *infoPtr, INT iCount, LPINT lpiArray)
4714 /* FIXME: little hack */
4715 for (i = 0; i < iCount; i++)
4723 * Retrieves the column width.
4726 * [I] infoPtr : valid pointer to the listview structure
4727 * [I] int : column index
4730 * SUCCESS : column width
4733 static INT LISTVIEW_GetColumnWidth(LISTVIEW_INFO *infoPtr, INT nColumn)
4735 INT nColumnWidth = 0;
4738 TRACE("nColumn=%d\n", nColumn);
4740 /* we have a 'column' in LIST and REPORT mode only */
4741 switch(infoPtr->dwStyle & LVS_TYPEMASK)
4744 nColumnWidth = infoPtr->nItemWidth;
4747 if (nColumn < 0 || nColumn >= infoPtr->hdpaColumns->nItemCount) return 0;
4748 LISTVIEW_GetHeaderRect(infoPtr, nColumn, &rcHeader);
4749 nColumnWidth = rcHeader.right - rcHeader.left;
4753 TRACE("nColumnWidth=%d\n", nColumnWidth);
4754 return nColumnWidth;
4759 * In list or report display mode, retrieves the number of items that can fit
4760 * vertically in the visible area. In icon or small icon display mode,
4761 * retrieves the total number of visible items.
4764 * [I] infoPtr : valid pointer to the listview structure
4767 * Number of fully visible items.
4769 static INT LISTVIEW_GetCountPerPage(LISTVIEW_INFO *infoPtr)
4771 switch (infoPtr->dwStyle & LVS_TYPEMASK)
4775 return infoPtr->nItemCount;
4777 return LISTVIEW_GetCountPerColumn(infoPtr);
4779 return LISTVIEW_GetCountPerRow(infoPtr) * LISTVIEW_GetCountPerColumn(infoPtr);
4787 * Retrieves an image list handle.
4790 * [I] infoPtr : valid pointer to the listview structure
4791 * [I] nImageList : image list identifier
4794 * SUCCESS : image list handle
4797 static HIMAGELIST LISTVIEW_GetImageList(LISTVIEW_INFO *infoPtr, INT nImageList)
4801 case LVSIL_NORMAL: return infoPtr->himlNormal;
4802 case LVSIL_SMALL: return infoPtr->himlSmall;
4803 case LVSIL_STATE: return infoPtr->himlState;
4808 /* LISTVIEW_GetISearchString */
4812 * Retrieves item attributes.
4815 * [I] hwnd : window handle
4816 * [IO] lpLVItem : item info
4817 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
4818 * if FALSE, the lpLVItem is a LPLVITEMA.
4821 * This is the internal 'GetItem' interface -- it tries to
4822 * be smart, and avoids text copies, if possible, by modifing
4823 * lpLVItem->pszText to point to the text string. Please note
4824 * that this is not always possible (e.g. OWNERDATA), so on
4825 * entry you *must* supply valid values for pszText, and cchTextMax.
4826 * The only difference to the documented interface is that upon
4827 * return, you should use *only* the lpLVItem->pszText, rather than
4828 * the buffer pointer you provided on input. Most code already does
4829 * that, so it's not a problem.
4830 * For the two cases when the text must be copied (that is,
4831 * for LVM_GETITEM, and LVMGETITEMTEXT), use LISTVIEW_GetItemExtT.
4837 static BOOL LISTVIEW_GetItemT(LISTVIEW_INFO *infoPtr, LPLVITEMW lpLVItem, BOOL isW)
4839 ITEMHDR callbackHdr = { LPSTR_TEXTCALLBACKW, I_IMAGECALLBACK };
4840 NMLVDISPINFOW dispInfo;
4845 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem, isW), isW);
4847 if (!lpLVItem || lpLVItem->iItem < 0 || lpLVItem->iItem >= infoPtr->nItemCount)
4850 if (lpLVItem->mask == 0) return TRUE;
4852 /* a quick optimization if all we're asked is the focus state
4853 * these queries are worth optimising since they are common,
4854 * and can be answered in constant time, without the heavy accesses */
4855 if ( (lpLVItem->mask == LVIF_STATE) && (lpLVItem->stateMask == LVIS_FOCUSED) &&
4856 !(infoPtr->uCallbackMask & LVIS_FOCUSED) )
4858 lpLVItem->state = 0;
4859 if (infoPtr->nFocusedItem == lpLVItem->iItem)
4860 lpLVItem->state |= LVIS_FOCUSED;
4864 ZeroMemory(&dispInfo, sizeof(dispInfo));
4866 /* if the app stores all the data, handle it separately */
4867 if (infoPtr->dwStyle & LVS_OWNERDATA)
4869 dispInfo.item.state = 0;
4871 /* apprently, we should not callback for lParam in LVS_OWNERDATA */
4872 if ((lpLVItem->mask & ~(LVIF_STATE | LVIF_PARAM)) || infoPtr->uCallbackMask)
4874 /* NOTE: copy only fields which we _know_ are initialized, some apps
4875 * depend on the uninitialized fields being 0 */
4876 dispInfo.item.mask = lpLVItem->mask & ~LVIF_PARAM;
4877 dispInfo.item.iItem = lpLVItem->iItem;
4878 dispInfo.item.iSubItem = lpLVItem->iSubItem;
4879 if (lpLVItem->mask & LVIF_TEXT)
4881 dispInfo.item.pszText = lpLVItem->pszText;
4882 dispInfo.item.cchTextMax = lpLVItem->cchTextMax;
4884 if (lpLVItem->mask & LVIF_STATE)
4885 dispInfo.item.stateMask = lpLVItem->stateMask & infoPtr->uCallbackMask;
4886 notify_dispinfoT(infoPtr, LVN_GETDISPINFOW, &dispInfo, isW);
4887 dispInfo.item.stateMask = lpLVItem->stateMask;
4888 *lpLVItem = dispInfo.item;
4889 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem, isW));
4892 /* make sure lParam is zeroed out */
4893 if (lpLVItem->mask & LVIF_PARAM) lpLVItem->lParam = 0;
4895 /* we store only a little state, so if we're not asked, we're done */
4896 if (!(lpLVItem->mask & LVIF_STATE) || lpLVItem->iSubItem) return TRUE;
4898 /* if focus is handled by us, report it */
4899 if ( lpLVItem->stateMask & ~infoPtr->uCallbackMask & LVIS_FOCUSED )
4901 lpLVItem->state &= ~LVIS_FOCUSED;
4902 if (infoPtr->nFocusedItem == lpLVItem->iItem)
4903 lpLVItem->state |= LVIS_FOCUSED;
4906 /* and do the same for selection, if we handle it */
4907 if ( lpLVItem->stateMask & ~infoPtr->uCallbackMask & LVIS_SELECTED )
4909 lpLVItem->state &= ~LVIS_SELECTED;
4910 if (ranges_contain(infoPtr->selectionRanges, lpLVItem->iItem))
4911 lpLVItem->state |= LVIS_SELECTED;
4917 /* find the item and subitem structures before we proceed */
4918 hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, lpLVItem->iItem);
4919 lpItem = (ITEM_INFO *)DPA_GetPtr(hdpaSubItems, 0);
4922 if (lpLVItem->iSubItem)
4924 SUBITEM_INFO *lpSubItem = LISTVIEW_GetSubItemPtr(hdpaSubItems, lpLVItem->iSubItem);
4925 pItemHdr = lpSubItem ? &lpSubItem->hdr : &callbackHdr;
4928 pItemHdr = &lpItem->hdr;
4930 /* Do we need to query the state from the app? */
4931 if ((lpLVItem->mask & LVIF_STATE) && infoPtr->uCallbackMask && lpLVItem->iSubItem == 0)
4933 dispInfo.item.mask |= LVIF_STATE;
4934 dispInfo.item.stateMask = infoPtr->uCallbackMask;
4937 /* Do we need to enquire about the image? */
4938 if ((lpLVItem->mask & LVIF_IMAGE) && pItemHdr->iImage == I_IMAGECALLBACK)
4939 dispInfo.item.mask |= LVIF_IMAGE;
4941 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
4942 if ((lpLVItem->mask & LVIF_TEXT) && !is_textW(pItemHdr->pszText))
4944 dispInfo.item.mask |= LVIF_TEXT;
4945 dispInfo.item.pszText = lpLVItem->pszText;
4946 dispInfo.item.cchTextMax = lpLVItem->cchTextMax;
4947 if (dispInfo.item.pszText && dispInfo.item.cchTextMax > 0)
4948 *dispInfo.item.pszText = '\0';
4951 /* If we don't have all the requested info, query the application */
4952 if (dispInfo.item.mask != 0)
4954 dispInfo.item.iItem = lpLVItem->iItem;
4955 dispInfo.item.iSubItem = lpLVItem->iSubItem;
4956 dispInfo.item.lParam = lpItem->lParam;
4957 notify_dispinfoT(infoPtr, LVN_GETDISPINFOW, &dispInfo, isW);
4958 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo.item, isW));
4961 /* we should not store values for subitems */
4962 if (lpLVItem->iSubItem) dispInfo.item.mask &= ~LVIF_DI_SETITEM;
4964 /* Now, handle the iImage field */
4965 if (dispInfo.item.mask & LVIF_IMAGE)
4967 lpLVItem->iImage = dispInfo.item.iImage;
4968 if ((dispInfo.item.mask & LVIF_DI_SETITEM) && pItemHdr->iImage == I_IMAGECALLBACK)
4969 pItemHdr->iImage = dispInfo.item.iImage;
4971 else if (lpLVItem->mask & LVIF_IMAGE)
4972 lpLVItem->iImage = pItemHdr->iImage;
4974 /* The pszText field */
4975 if (dispInfo.item.mask & LVIF_TEXT)
4977 if ((dispInfo.item.mask & LVIF_DI_SETITEM) && pItemHdr->pszText)
4978 textsetptrT(&pItemHdr->pszText, dispInfo.item.pszText, isW);
4980 lpLVItem->pszText = dispInfo.item.pszText;
4982 else if (lpLVItem->mask & LVIF_TEXT)
4984 if (isW) lpLVItem->pszText = pItemHdr->pszText;
4985 else textcpynT(lpLVItem->pszText, isW, pItemHdr->pszText, TRUE, lpLVItem->cchTextMax);
4988 /* if this is a subitem, we're done */
4989 if (lpLVItem->iSubItem) return TRUE;
4991 /* Next is the lParam field */
4992 if (dispInfo.item.mask & LVIF_PARAM)
4994 lpLVItem->lParam = dispInfo.item.lParam;
4995 if ((dispInfo.item.mask & LVIF_DI_SETITEM))
4996 lpItem->lParam = dispInfo.item.lParam;
4998 else if (lpLVItem->mask & LVIF_PARAM)
4999 lpLVItem->lParam = lpItem->lParam;
5001 /* ... the state field (this one is different due to uCallbackmask) */
5002 if (lpLVItem->mask & LVIF_STATE)
5004 lpLVItem->state = lpItem->state;
5005 if (dispInfo.item.mask & LVIF_STATE)
5007 lpLVItem->state &= ~dispInfo.item.stateMask;
5008 lpLVItem->state |= (dispInfo.item.state & dispInfo.item.stateMask);
5010 if ( lpLVItem->stateMask & ~infoPtr->uCallbackMask & LVIS_FOCUSED )
5012 lpLVItem->state &= ~LVIS_FOCUSED;
5013 if (infoPtr->nFocusedItem == lpLVItem->iItem)
5014 lpLVItem->state |= LVIS_FOCUSED;
5016 if ( lpLVItem->stateMask & ~infoPtr->uCallbackMask & LVIS_SELECTED )
5018 lpLVItem->state &= ~LVIS_SELECTED;
5019 if (ranges_contain(infoPtr->selectionRanges, lpLVItem->iItem))
5020 lpLVItem->state |= LVIS_SELECTED;
5024 /* and last, but not least, the indent field */
5025 if (lpLVItem->mask & LVIF_INDENT)
5026 lpLVItem->iIndent = lpItem->iIndent;
5033 * Retrieves item attributes.
5036 * [I] hwnd : window handle
5037 * [IO] lpLVItem : item info
5038 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
5039 * if FALSE, the lpLVItem is a LPLVITEMA.
5042 * This is the external 'GetItem' interface -- it properly copies
5043 * the text in the provided buffer.
5049 static BOOL LISTVIEW_GetItemExtT(LISTVIEW_INFO *infoPtr, LPLVITEMW lpLVItem, BOOL isW)
5054 if (!lpLVItem || lpLVItem->iItem < 0 || lpLVItem->iItem >= infoPtr->nItemCount)
5057 pszText = lpLVItem->pszText;
5058 bResult = LISTVIEW_GetItemT(infoPtr, lpLVItem, isW);
5059 if (bResult && lpLVItem->pszText != pszText)
5060 textcpynT(pszText, isW, lpLVItem->pszText, isW, lpLVItem->cchTextMax);
5061 lpLVItem->pszText = pszText;
5069 * Retrieves the position (upper-left) of the listview control item.
5070 * Note that for LVS_ICON style, the upper-left is that of the icon
5071 * and not the bounding box.
5074 * [I] infoPtr : valid pointer to the listview structure
5075 * [I] nItem : item index
5076 * [O] lpptPosition : coordinate information
5082 static BOOL LISTVIEW_GetItemPosition(LISTVIEW_INFO *infoPtr, INT nItem, LPPOINT lpptPosition)
5084 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
5087 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem, lpptPosition);
5089 if (!lpptPosition || nItem < 0 || nItem >= infoPtr->nItemCount) return FALSE;
5091 LISTVIEW_GetOrigin(infoPtr, &Origin);
5092 LISTVIEW_GetItemOrigin(infoPtr, nItem, lpptPosition);
5094 if (uView == LVS_ICON)
5096 lpptPosition->x += (infoPtr->nItemWidth - infoPtr->iconSize.cx) / 2;
5097 lpptPosition->y += ICON_TOP_PADDING;
5099 lpptPosition->x += Origin.x;
5100 lpptPosition->y += Origin.y;
5102 TRACE (" lpptPosition=%s\n", debugpoint(lpptPosition));
5109 * Retrieves the bounding rectangle for a listview control item.
5112 * [I] infoPtr : valid pointer to the listview structure
5113 * [I] nItem : item index
5114 * [IO] lprc : bounding rectangle coordinates
5115 * lprc->left specifies the portion of the item for which the bounding
5116 * rectangle will be retrieved.
5118 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
5119 * including the icon and label.
5122 * * Experiment shows that native control returns:
5123 * * width = min (48, length of text line)
5124 * * .left = position.x - (width - iconsize.cx)/2
5125 * * .right = .left + width
5126 * * height = #lines of text * ntmHeight + icon height + 8
5127 * * .top = position.y - 2
5128 * * .bottom = .top + height
5129 * * separation between items .y = itemSpacing.cy - height
5130 * * .x = itemSpacing.cx - width
5131 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
5134 * * Experiment shows that native control returns:
5135 * * width = iconSize.cx + 16
5136 * * .left = position.x - (width - iconsize.cx)/2
5137 * * .right = .left + width
5138 * * height = iconSize.cy + 4
5139 * * .top = position.y - 2
5140 * * .bottom = .top + height
5141 * * separation between items .y = itemSpacing.cy - height
5142 * * .x = itemSpacing.cx - width
5143 * LVIR_LABEL Returns the bounding rectangle of the item text.
5146 * * Experiment shows that native control returns:
5147 * * width = text length
5148 * * .left = position.x - width/2
5149 * * .right = .left + width
5150 * * height = ntmH * linecount + 2
5151 * * .top = position.y + iconSize.cy + 6
5152 * * .bottom = .top + height
5153 * * separation between items .y = itemSpacing.cy - height
5154 * * .x = itemSpacing.cx - width
5155 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
5156 * rectangles, but excludes columns in report view.
5163 * Note that the bounding rectangle of the label in the LVS_ICON view depends
5164 * upon whether the window has the focus currently and on whether the item
5165 * is the one with the focus. Ensure that the control's record of which
5166 * item has the focus agrees with the items' records.
5168 static BOOL LISTVIEW_GetItemRect(LISTVIEW_INFO *infoPtr, INT nItem, LPRECT lprc)
5170 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
5171 WCHAR szDispText[DISP_TEXT_SIZE] = { '\0' };
5172 BOOL doLabel = TRUE, oversizedBox = FALSE;
5173 POINT Position, Origin;
5177 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr->hwndSelf, nItem, lprc);
5179 if (!lprc || nItem < 0 || nItem >= infoPtr->nItemCount) return FALSE;
5181 LISTVIEW_GetOrigin(infoPtr, &Origin);
5182 LISTVIEW_GetItemOrigin(infoPtr, nItem, &Position);
5184 /* Be smart and try to figure out the minimum we have to do */
5185 if (lprc->left == LVIR_ICON) doLabel = FALSE;
5186 if (uView == LVS_REPORT && lprc->left == LVIR_BOUNDS) doLabel = FALSE;
5187 if (uView == LVS_ICON && lprc->left != LVIR_ICON &&
5188 infoPtr->bFocus && LISTVIEW_GetItemState(infoPtr, nItem, LVIS_FOCUSED))
5189 oversizedBox = TRUE;
5191 /* get what we need from the item before hand, so we make
5192 * only one request. This can speed up things, if data
5193 * is stored on the app side */
5195 if (uView == LVS_REPORT) lvItem.mask |= LVIF_INDENT;
5196 if (doLabel) lvItem.mask |= LVIF_TEXT;
5197 lvItem.iItem = nItem;
5198 lvItem.iSubItem = 0;
5199 lvItem.pszText = szDispText;
5200 lvItem.cchTextMax = DISP_TEXT_SIZE;
5201 if (lvItem.mask && !LISTVIEW_GetItemW(infoPtr, &lvItem)) return FALSE;
5202 /* we got the state already up, simulate it here, to avoid a reget */
5203 if (uView == LVS_ICON && (lprc->left != LVIR_ICON))
5205 lvItem.mask |= LVIF_STATE;
5206 lvItem.stateMask = LVIS_FOCUSED;
5207 lvItem.state = (oversizedBox ? LVIS_FOCUSED : 0);
5210 if (uView == LVS_REPORT && (infoPtr->dwLvExStyle & LVS_EX_FULLROWSELECT) && lprc->left == LVIR_SELECTBOUNDS)
5211 lprc->left = LVIR_BOUNDS;
5215 LISTVIEW_GetItemMetrics(infoPtr, &lvItem, NULL, NULL, lprc, NULL);
5219 LISTVIEW_GetItemMetrics(infoPtr, &lvItem, NULL, NULL, NULL, lprc);
5223 LISTVIEW_GetItemMetrics(infoPtr, &lvItem, lprc, NULL, NULL, NULL);
5226 case LVIR_SELECTBOUNDS:
5227 LISTVIEW_GetItemMetrics(infoPtr, &lvItem, NULL, NULL, lprc, &label_rect);
5228 UnionRect(lprc, lprc, &label_rect);
5232 WARN("Unknown value: %ld\n", lprc->left);
5236 OffsetRect(lprc, Position.x + Origin.x, Position.y + Origin.y);
5238 TRACE(" rect=%s\n", debugrect(lprc));
5245 * Retrieves the spacing between listview control items.
5248 * [I] infoPtr : valid pointer to the listview structure
5249 * [IO] lprc : rectangle to receive the output
5250 * on input, lprc->top = nSubItem
5251 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
5253 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
5254 * not only those of the first column.
5255 * Fortunately, LISTVIEW_GetItemMetrics does the right thing.
5261 static BOOL LISTVIEW_GetSubItemRect(LISTVIEW_INFO *infoPtr, INT nItem, LPRECT lprc)
5266 if (!lprc || (infoPtr->dwStyle & LVS_TYPEMASK) != LVS_REPORT) return FALSE;
5268 TRACE("(nItem=%d, nSubItem=%ld)\n", nItem, lprc->top);
5269 /* On WinNT, a subitem of '0' calls LISTVIEW_GetItemRect */
5271 return LISTVIEW_GetItemRect(infoPtr, nItem, lprc);
5273 if (!LISTVIEW_GetItemPosition(infoPtr, nItem, &Position)) return FALSE;
5275 lvItem.mask = lprc->top == 0 ? LVIF_INDENT : 0;
5276 lvItem.iItem = nItem;
5277 lvItem.iSubItem = lprc->top;
5279 if (lvItem.mask && !LISTVIEW_GetItemW(infoPtr, &lvItem)) return FALSE;
5283 LISTVIEW_GetItemMetrics(infoPtr, &lvItem, NULL, NULL, lprc, NULL);
5288 LISTVIEW_GetItemMetrics(infoPtr, &lvItem, lprc, NULL, NULL, NULL);
5292 ERR("Unknown bounds=%ld\n", lprc->left);
5296 OffsetRect(lprc, Position.x, Position.y);
5303 * Retrieves the width of a label.
5306 * [I] infoPtr : valid pointer to the listview structure
5309 * SUCCESS : string width (in pixels)
5312 static INT LISTVIEW_GetLabelWidth(LISTVIEW_INFO *infoPtr, INT nItem)
5314 WCHAR szDispText[DISP_TEXT_SIZE] = { '\0' };
5317 TRACE("(nItem=%d)\n", nItem);
5319 lvItem.mask = LVIF_TEXT;
5320 lvItem.iItem = nItem;
5321 lvItem.iSubItem = 0;
5322 lvItem.pszText = szDispText;
5323 lvItem.cchTextMax = DISP_TEXT_SIZE;
5324 if (!LISTVIEW_GetItemW(infoPtr, &lvItem)) return 0;
5326 return LISTVIEW_GetStringWidthT(infoPtr, lvItem.pszText, TRUE);
5331 * Retrieves the spacing between listview control items.
5334 * [I] infoPtr : valid pointer to the listview structure
5335 * [I] bSmall : flag for small or large icon
5338 * Horizontal + vertical spacing
5340 static LONG LISTVIEW_GetItemSpacing(LISTVIEW_INFO *infoPtr, BOOL bSmall)
5346 lResult = MAKELONG(infoPtr->iconSpacing.cx, infoPtr->iconSpacing.cy);
5350 if ((infoPtr->dwStyle & LVS_TYPEMASK) == LVS_ICON)
5351 lResult = MAKELONG(DEFAULT_COLUMN_WIDTH, GetSystemMetrics(SM_CXSMICON)+HEIGHT_PADDING);
5353 lResult = MAKELONG(infoPtr->nItemWidth, infoPtr->nItemHeight);
5360 * Retrieves the state of a listview control item.
5363 * [I] infoPtr : valid pointer to the listview structure
5364 * [I] nItem : item index
5365 * [I] uMask : state mask
5368 * State specified by the mask.
5370 static UINT LISTVIEW_GetItemState(LISTVIEW_INFO *infoPtr, INT nItem, UINT uMask)
5374 if (nItem < 0 || nItem >= infoPtr->nItemCount) return 0;
5376 lvItem.iItem = nItem;
5377 lvItem.iSubItem = 0;
5378 lvItem.mask = LVIF_STATE;
5379 lvItem.stateMask = uMask;
5380 if (!LISTVIEW_GetItemW(infoPtr, &lvItem)) return 0;
5382 return lvItem.state & uMask;
5387 * Retrieves the text of a listview control item or subitem.
5390 * [I] hwnd : window handle
5391 * [I] nItem : item index
5392 * [IO] lpLVItem : item information
5393 * [I] isW : TRUE if lpLVItem is Unicode
5396 * SUCCESS : string length
5399 static INT LISTVIEW_GetItemTextT(LISTVIEW_INFO *infoPtr, INT nItem, LPLVITEMW lpLVItem, BOOL isW)
5401 if (!lpLVItem || nItem < 0 || nItem >= infoPtr->nItemCount) return 0;
5403 lpLVItem->mask = LVIF_TEXT;
5404 lpLVItem->iItem = nItem;
5405 if (!LISTVIEW_GetItemExtT(infoPtr, lpLVItem, isW)) return 0;
5407 return textlenT(lpLVItem->pszText, isW);
5412 * Searches for an item based on properties + relationships.
5415 * [I] infoPtr : valid pointer to the listview structure
5416 * [I] nItem : item index
5417 * [I] uFlags : relationship flag
5420 * SUCCESS : item index
5423 static INT LISTVIEW_GetNextItem(LISTVIEW_INFO *infoPtr, INT nItem, UINT uFlags)
5425 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
5427 LVFINDINFOW lvFindInfo;
5428 INT nCountPerColumn;
5432 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem, uFlags, infoPtr->nItemCount);
5433 if (nItem < -1 || nItem >= infoPtr->nItemCount) return -1;
5435 ZeroMemory(&lvFindInfo, sizeof(lvFindInfo));
5437 if (uFlags & LVNI_CUT)
5440 if (uFlags & LVNI_DROPHILITED)
5441 uMask |= LVIS_DROPHILITED;
5443 if (uFlags & LVNI_FOCUSED)
5444 uMask |= LVIS_FOCUSED;
5446 if (uFlags & LVNI_SELECTED)
5447 uMask |= LVIS_SELECTED;
5449 /* if we're asked for the focused item, that's only one,
5450 * so it's worth optimizing */
5451 if (uFlags & LVNI_FOCUSED)
5453 if (!(LISTVIEW_GetItemState(infoPtr, infoPtr->nFocusedItem, uMask) & uMask) == uMask) return -1;
5454 return (infoPtr->nFocusedItem == nItem) ? -1 : infoPtr->nFocusedItem;
5457 if (uFlags & LVNI_ABOVE)
5459 if ((uView == LVS_LIST) || (uView == LVS_REPORT))
5464 if ((ListView_GetItemState(infoPtr->hwndSelf, nItem, uMask) & uMask) == uMask)
5470 /* Special case for autoarrange - move 'til the top of a list */
5471 if (is_autoarrange(infoPtr))
5473 nCountPerRow = LISTVIEW_GetCountPerRow(infoPtr);
5474 while (nItem - nCountPerRow >= 0)
5476 nItem -= nCountPerRow;
5477 if ((LISTVIEW_GetItemState(infoPtr, nItem, uMask) & uMask) == uMask)
5482 lvFindInfo.flags = LVFI_NEARESTXY;
5483 lvFindInfo.vkDirection = VK_UP;
5484 ListView_GetItemPosition(infoPtr->hwndSelf, nItem, &lvFindInfo.pt);
5485 while ((nItem = ListView_FindItemW(infoPtr->hwndSelf, nItem, &lvFindInfo)) != -1)
5487 if ((ListView_GetItemState(infoPtr->hwndSelf, nItem, uMask) & uMask) == uMask)
5492 else if (uFlags & LVNI_BELOW)
5494 if ((uView == LVS_LIST) || (uView == LVS_REPORT))
5496 while (nItem < infoPtr->nItemCount)
5499 if ((LISTVIEW_GetItemState(infoPtr, nItem, uMask) & uMask) == uMask)
5505 /* Special case for autoarrange - move 'til the bottom of a list */
5506 if (is_autoarrange(infoPtr))
5508 nCountPerRow = LISTVIEW_GetCountPerRow(infoPtr);
5509 while (nItem + nCountPerRow < infoPtr->nItemCount )
5511 nItem += nCountPerRow;
5512 if ((LISTVIEW_GetItemState(infoPtr, nItem, uMask) & uMask) == uMask)
5517 lvFindInfo.flags = LVFI_NEARESTXY;
5518 lvFindInfo.vkDirection = VK_DOWN;
5519 ListView_GetItemPosition(infoPtr->hwndSelf, nItem, &lvFindInfo.pt);
5520 while ((nItem = ListView_FindItemW(infoPtr->hwndSelf, nItem, &lvFindInfo)) != -1)
5522 if ((LISTVIEW_GetItemState(infoPtr, nItem, uMask) & uMask) == uMask)
5527 else if (uFlags & LVNI_TOLEFT)
5529 if (uView == LVS_LIST)
5531 nCountPerColumn = LISTVIEW_GetCountPerColumn(infoPtr);
5532 while (nItem - nCountPerColumn >= 0)
5534 nItem -= nCountPerColumn;
5535 if ((LISTVIEW_GetItemState(infoPtr, nItem, uMask) & uMask) == uMask)
5539 else if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
5541 /* Special case for autoarrange - move 'ti the beginning of a row */
5542 if (is_autoarrange(infoPtr))
5544 nCountPerRow = LISTVIEW_GetCountPerRow(infoPtr);
5545 while (nItem % nCountPerRow > 0)
5548 if ((LISTVIEW_GetItemState(infoPtr, nItem, uMask) & uMask) == uMask)
5553 lvFindInfo.flags = LVFI_NEARESTXY;
5554 lvFindInfo.vkDirection = VK_LEFT;
5555 ListView_GetItemPosition(infoPtr->hwndSelf, nItem, &lvFindInfo.pt);
5556 while ((nItem = ListView_FindItemW(infoPtr->hwndSelf, nItem, &lvFindInfo)) != -1)
5558 if ((ListView_GetItemState(infoPtr->hwndSelf, nItem, uMask) & uMask) == uMask)
5563 else if (uFlags & LVNI_TORIGHT)
5565 if (uView == LVS_LIST)
5567 nCountPerColumn = LISTVIEW_GetCountPerColumn(infoPtr);
5568 while (nItem + nCountPerColumn < infoPtr->nItemCount)
5570 nItem += nCountPerColumn;
5571 if ((ListView_GetItemState(infoPtr->hwndSelf, nItem, uMask) & uMask) == uMask)
5575 else if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
5577 /* Special case for autoarrange - move 'til the end of a row */
5578 if (is_autoarrange(infoPtr))
5580 nCountPerRow = LISTVIEW_GetCountPerRow(infoPtr);
5581 while (nItem % nCountPerRow < nCountPerRow - 1 )
5584 if ((LISTVIEW_GetItemState(infoPtr, nItem, uMask) & uMask) == uMask)
5589 lvFindInfo.flags = LVFI_NEARESTXY;
5590 lvFindInfo.vkDirection = VK_RIGHT;
5591 ListView_GetItemPosition(infoPtr->hwndSelf, nItem, &lvFindInfo.pt);
5592 while ((nItem = ListView_FindItemW(infoPtr->hwndSelf, nItem, &lvFindInfo)) != -1)
5594 if ((LISTVIEW_GetItemState(infoPtr, nItem, uMask) & uMask) == uMask)
5603 /* search by index */
5604 for (i = nItem; i < infoPtr->nItemCount; i++)
5606 if ((LISTVIEW_GetItemState(infoPtr, i, uMask) & uMask) == uMask)
5614 /* LISTVIEW_GetNumberOfWorkAreas */
5618 * Retrieves the origin coordinates when in icon or small icon display mode.
5621 * [I] infoPtr : valid pointer to the listview structure
5622 * [O] lpptOrigin : coordinate information
5627 static void LISTVIEW_GetOrigin(LISTVIEW_INFO *infoPtr, LPPOINT lpptOrigin)
5629 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
5630 INT nHorzPos = 0, nVertPos = 0;
5631 SCROLLINFO scrollInfo;
5633 scrollInfo.cbSize = sizeof(SCROLLINFO);
5634 scrollInfo.fMask = SIF_POS;
5636 if ((infoPtr->dwStyle & WS_HSCROLL) && GetScrollInfo(infoPtr->hwndSelf, SB_HORZ, &scrollInfo))
5637 nHorzPos = scrollInfo.nPos;
5638 if ((infoPtr->dwStyle & WS_VSCROLL) && GetScrollInfo(infoPtr->hwndSelf, SB_VERT, &scrollInfo))
5639 nVertPos = scrollInfo.nPos;
5641 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos, nVertPos);
5643 lpptOrigin->x = infoPtr->rcList.left;
5644 lpptOrigin->y = infoPtr->rcList.top;
5645 if (uView == LVS_LIST)
5646 nHorzPos *= infoPtr->nItemWidth;
5647 else if (uView == LVS_REPORT)
5648 nVertPos *= infoPtr->nItemHeight;
5650 lpptOrigin->x -= nHorzPos;
5651 lpptOrigin->y -= nVertPos;
5653 TRACE(" origin=%s\n", debugpoint(lpptOrigin));
5658 * Retrieves the width of a string.
5661 * [I] hwnd : window handle
5662 * [I] lpszText : text string to process
5663 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
5666 * SUCCESS : string width (in pixels)
5669 static INT LISTVIEW_GetStringWidthT(LISTVIEW_INFO *infoPtr, LPCWSTR lpszText, BOOL isW)
5674 if (is_textT(lpszText, isW))
5676 HFONT hFont = infoPtr->hFont ? infoPtr->hFont : infoPtr->hDefaultFont;
5677 HDC hdc = GetDC(infoPtr->hwndSelf);
5678 HFONT hOldFont = SelectObject(hdc, hFont);
5681 GetTextExtentPointW(hdc, lpszText, lstrlenW(lpszText), &stringSize);
5683 GetTextExtentPointA(hdc, (LPCSTR)lpszText, lstrlenA((LPCSTR)lpszText), &stringSize);
5684 SelectObject(hdc, hOldFont);
5685 ReleaseDC(infoPtr->hwndSelf, hdc);
5687 return stringSize.cx;
5692 * Determines which listview item is located at the specified position.
5695 * [I] infoPtr : valid pointer to the listview structure
5696 * [IO] lpht : hit test information
5697 * [I] subitem : fill out iSubItem.
5698 * [I] select : return the index only if the hit selects the item
5701 * (mm 20001022): We must not allow iSubItem to be touched, for
5702 * an app might pass only a structure with space up to iItem!
5703 * (MS Office 97 does that for instance in the file open dialog)
5706 * SUCCESS : item index
5709 static INT LISTVIEW_HitTest(LISTVIEW_INFO *infoPtr, LPLVHITTESTINFO lpht, BOOL subitem, BOOL select)
5711 WCHAR szDispText[DISP_TEXT_SIZE] = { '\0' };
5712 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
5713 RECT rcBox, rcBounds, rcState, rcIcon, rcLabel, rcSearch;
5714 POINT Origin, Position, opt;
5718 TRACE("(pt=%s, subitem=%d, select=%d)\n", debugpoint(&lpht->pt), subitem, select);
5722 if (subitem) lpht->iSubItem = 0;
5724 if (infoPtr->rcList.left > lpht->pt.x)
5725 lpht->flags |= LVHT_TOLEFT;
5726 else if (infoPtr->rcList.right < lpht->pt.x)
5727 lpht->flags |= LVHT_TORIGHT;
5729 if (infoPtr->rcList.top > lpht->pt.y)
5730 lpht->flags |= LVHT_ABOVE;
5731 else if (infoPtr->rcList.bottom < lpht->pt.y)
5732 lpht->flags |= LVHT_BELOW;
5734 TRACE("lpht->flags=0x%x\n", lpht->flags);
5735 if (lpht->flags) return -1;
5737 lpht->flags |= LVHT_NOWHERE;
5739 LISTVIEW_GetOrigin(infoPtr, &Origin);
5741 /* first deal with the large items */
5742 rcSearch.left = lpht->pt.x;
5743 rcSearch.top = lpht->pt.y;
5744 rcSearch.right = rcSearch.left + 1;
5745 rcSearch.bottom = rcSearch.top + 1;
5747 iterator_frameditems(&i, infoPtr, &rcSearch);
5748 iterator_next(&i); /* go to first item in the sequence */
5749 lpht->iItem = i.nItem;
5750 iterator_destroy(&i);
5752 TRACE("lpht->iItem=%d\n", lpht->iItem);
5753 if (lpht->iItem == -1) return -1;
5755 lvItem.mask = LVIF_STATE | LVIF_TEXT;
5756 if (uView == LVS_REPORT) lvItem.mask |= LVIF_INDENT;
5757 lvItem.stateMask = LVIS_STATEIMAGEMASK;
5758 if (uView == LVS_ICON) lvItem.stateMask |= LVIS_FOCUSED;
5759 lvItem.iItem = lpht->iItem;
5760 lvItem.iSubItem = 0;
5761 lvItem.pszText = szDispText;
5762 lvItem.cchTextMax = DISP_TEXT_SIZE;
5763 if (!LISTVIEW_GetItemW(infoPtr, &lvItem)) return -1;
5764 if (!infoPtr->bFocus) lvItem.state &= ~LVIS_FOCUSED;
5766 LISTVIEW_GetItemMetrics(infoPtr, &lvItem, &rcBox, &rcState, &rcIcon, &rcLabel);
5767 LISTVIEW_GetItemOrigin(infoPtr, lpht->iItem, &Position);
5768 opt.x = lpht->pt.x - Position.x - Origin.x;
5769 opt.y = lpht->pt.y - Position.y - Origin.y;
5771 if (uView == LVS_REPORT && (infoPtr->dwLvExStyle & LVS_EX_FULLROWSELECT))
5774 UnionRect(&rcBounds, &rcIcon, &rcLabel);
5775 TRACE("rcBounds=%s\n", debugrect(&rcBounds));
5776 if (!PtInRect(&rcBounds, opt)) return -1;
5778 if (PtInRect(&rcIcon, opt))
5779 lpht->flags |= LVHT_ONITEMICON;
5780 else if (PtInRect(&rcLabel, opt))
5781 lpht->flags |= LVHT_ONITEMLABEL;
5782 else if (infoPtr->himlState && ((lvItem.state & LVIS_STATEIMAGEMASK) >> 12) && PtInRect(&rcState, opt))
5783 lpht->flags |= LVHT_ONITEMSTATEICON;
5784 if (lpht->flags & LVHT_ONITEM)
5785 lpht->flags &= ~LVHT_NOWHERE;
5787 TRACE("lpht->flags=0x%x\n", lpht->flags);
5788 if (uView == LVS_REPORT && lpht->iItem != -1 && subitem)
5792 rcBounds.right = rcBounds.left;
5793 for (j = 0; j < infoPtr->hdpaColumns->nItemCount; j++)
5795 rcBounds.left = rcBounds.right;
5796 rcBounds.right += LISTVIEW_GetColumnWidth(infoPtr, j);
5797 if (PtInRect(&rcBounds, opt))
5805 if (!select || lpht->iItem == -1) return lpht->iItem;
5807 if (uView == LVS_REPORT && (infoPtr->dwLvExStyle & LVS_EX_FULLROWSELECT)) return lpht->iItem;
5809 if (uView == LVS_REPORT) UnionRect(&rcBounds, &rcIcon, &rcLabel);
5810 return PtInRect(&rcBounds, opt) ? lpht->iItem : -1;
5814 /* LISTVIEW_InsertCompare: callback routine for comparing pszText members of the LV_ITEMS
5815 in a LISTVIEW on insert. Passed to DPA_Sort in LISTVIEW_InsertItem.
5816 This function should only be used for inserting items into a sorted list (LVM_INSERTITEM)
5817 and not during the processing of a LVM_SORTITEMS message. Applications should provide
5818 their own sort proc. when sending LVM_SORTITEMS.
5821 (remarks on LVITEM: LVM_INSERTITEM will insert the new item in the proper sort postion...
5823 LVS_SORTXXX must be specified,
5824 LVS_OWNERDRAW is not set,
5825 <item>.pszText is not LPSTR_TEXTCALLBACK.
5827 (LVS_SORT* flags): "For the LVS_SORTASCENDING... styles, item indices
5828 are sorted based on item text..."
5830 static INT WINAPI LISTVIEW_InsertCompare( LPVOID first, LPVOID second, LPARAM lParam)
5832 ITEM_INFO* lv_first = (ITEM_INFO*) DPA_GetPtr( (HDPA)first, 0 );
5833 ITEM_INFO* lv_second = (ITEM_INFO*) DPA_GetPtr( (HDPA)second, 0 );
5834 INT cmpv = textcmpWT(lv_first->hdr.pszText, lv_second->hdr.pszText, TRUE);
5836 /* if we're sorting descending, negate the return value */
5837 return (((LISTVIEW_INFO *)lParam)->dwStyle & LVS_SORTDESCENDING) ? -cmpv : cmpv;
5842 * Inserts a new item in the listview control.
5845 * [I] infoPtr : valid pointer to the listview structure
5846 * [I] lpLVItem : item information
5847 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
5850 * SUCCESS : new item index
5853 static INT LISTVIEW_InsertItemT(LISTVIEW_INFO *infoPtr, const LVITEMW *lpLVItem, BOOL isW)
5855 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
5860 BOOL is_sorted, has_changed;
5863 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem, isW), isW);
5865 if (infoPtr->dwStyle & LVS_OWNERDATA) return infoPtr->nItemCount++;
5867 /* make sure it's an item, and not a subitem; cannot insert a subitem */
5868 if (!lpLVItem || lpLVItem->iItem < 0 || lpLVItem->iSubItem) return -1;
5870 if (!is_assignable_item(lpLVItem, infoPtr->dwStyle)) return -1;
5872 if ( !(lpItem = (ITEM_INFO *)COMCTL32_Alloc(sizeof(ITEM_INFO))) )
5875 /* insert item in listview control data structure */
5876 if ( !(hdpaSubItems = DPA_Create(8)) ) goto fail;
5877 if ( !DPA_SetPtr(hdpaSubItems, 0, lpItem) ) assert (FALSE);
5879 is_sorted = (infoPtr->dwStyle & (LVS_SORTASCENDING | LVS_SORTDESCENDING)) &&
5880 !(infoPtr->dwStyle & LVS_OWNERDRAWFIXED) && (LPSTR_TEXTCALLBACKW != lpLVItem->pszText);
5882 nItem = is_sorted ? infoPtr->nItemCount : min(lpLVItem->iItem, infoPtr->nItemCount);
5883 TRACE(" inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem, is_sorted, infoPtr->nItemCount, lpLVItem->iItem);
5884 nItem = DPA_InsertPtr( infoPtr->hdpaItems, nItem, hdpaSubItems );
5885 if (nItem == -1) goto fail;
5886 infoPtr->nItemCount++;
5888 /* set the item attributes */
5891 item.state &= ~LVIS_STATEIMAGEMASK;
5892 if (!set_main_item(infoPtr, &item, TRUE, isW, &has_changed)) goto undo;
5894 /* if we're sorted, sort the list, and update the index */
5897 DPA_Sort( infoPtr->hdpaItems, LISTVIEW_InsertCompare, (LPARAM)infoPtr );
5898 nItem = DPA_GetPtrIndex( infoPtr->hdpaItems, hdpaSubItems );
5899 assert(nItem != -1);
5902 /* make room for the position, if we are in the right mode */
5903 if ((uView == LVS_SMALLICON) || (uView == LVS_ICON))
5905 if (DPA_InsertPtr(infoPtr->hdpaPosX, nItem, 0) == -1)
5907 if (DPA_InsertPtr(infoPtr->hdpaPosY, nItem, 0) == -1)
5909 DPA_DeletePtr(infoPtr->hdpaPosX, nItem);
5914 /* Add the subitem list to the items array. Do this last in case we go to
5915 * fail during the above.
5917 LISTVIEW_ShiftIndices(infoPtr, nItem, 1);
5919 /* send LVN_INSERTITEM notification */
5920 ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
5922 nmlv.lParam = lpItem->lParam;
5923 notify_listview(infoPtr, LVN_INSERTITEM, &nmlv);
5925 /* align items (set position of each item) */
5926 if ((uView == LVS_SMALLICON || uView == LVS_ICON))
5930 if (infoPtr->dwStyle & LVS_ALIGNLEFT)
5931 LISTVIEW_NextIconPosLeft(infoPtr, &pt);
5933 LISTVIEW_NextIconPosTop(infoPtr, &pt);
5935 LISTVIEW_MoveIconTo(infoPtr, nItem, &pt, TRUE);
5938 /* now is the invalidation fun */
5939 LISTVIEW_ScrollOnInsert(infoPtr, nItem, 1);
5943 DPA_DeletePtr(infoPtr->hdpaItems, nItem);
5944 infoPtr->nItemCount--;
5946 DPA_DeletePtr(hdpaSubItems, 0);
5947 DPA_Destroy (hdpaSubItems);
5948 COMCTL32_Free (lpItem);
5954 * Redraws a range of items.
5957 * [I] infoPtr : valid pointer to the listview structure
5958 * [I] nFirst : first item
5959 * [I] nLast : last item
5965 static BOOL LISTVIEW_RedrawItems(LISTVIEW_INFO *infoPtr, INT nFirst, INT nLast)
5969 if (nLast < nFirst || min(nFirst, nLast) < 0 ||
5970 max(nFirst, nLast) >= infoPtr->nItemCount)
5973 for (i = nFirst; i <= nLast; i++)
5974 LISTVIEW_InvalidateItem(infoPtr, i);
5981 * Scroll the content of a listview.
5984 * [I] infoPtr : valid pointer to the listview structure
5985 * [I] dx : horizontal scroll amount in pixels
5986 * [I] dy : vertical scroll amount in pixels
5993 * If the control is in report mode (LVS_REPORT) the control can
5994 * be scrolled only in line increments. "dy" will be rounded to the
5995 * nearest number of pixels that are a whole line. Ex: if line height
5996 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
5997 * is passed the the scroll will be 0. (per MSDN 7/2002)
5999 * For: (per experimentaion with native control and CSpy ListView)
6000 * LVS_ICON dy=1 = 1 pixel (vertical only)
6002 * LVS_SMALLICON dy=1 = 1 pixel (vertical only)
6004 * LVS_LIST dx=1 = 1 column (horizontal only)
6005 * but will only scroll 1 column per message
6006 * no matter what the value.
6007 * dy must be 0 or FALSE returned.
6008 * LVS_REPORT dx=1 = 1 pixel
6012 static BOOL LISTVIEW_Scroll(LISTVIEW_INFO *infoPtr, INT dx, INT dy)
6014 switch(infoPtr->dwStyle & LVS_TYPEMASK) {
6016 dy += (dy < 0 ? -1 : 1) * infoPtr->nItemHeight/2;
6017 dy /= infoPtr->nItemHeight;
6020 if (dy != 0) return FALSE;
6027 if (dx != 0) LISTVIEW_HScroll(infoPtr, SB_INTERNAL, dx, 0);
6028 if (dy != 0) LISTVIEW_VScroll(infoPtr, SB_INTERNAL, dy, 0);
6035 * Sets the background color.
6038 * [I] infoPtr : valid pointer to the listview structure
6039 * [I] clrBk : background color
6045 static BOOL LISTVIEW_SetBkColor(LISTVIEW_INFO *infoPtr, COLORREF clrBk)
6047 TRACE("(clrBk=%lx)\n", clrBk);
6049 if(infoPtr->clrBk != clrBk) {
6050 if (infoPtr->clrBk != CLR_NONE) DeleteObject(infoPtr->hBkBrush);
6051 infoPtr->clrBk = clrBk;
6052 if (clrBk == CLR_NONE)
6053 infoPtr->hBkBrush = (HBRUSH)GetClassLongW(infoPtr->hwndSelf, GCL_HBRBACKGROUND);
6055 infoPtr->hBkBrush = CreateSolidBrush(clrBk);
6056 LISTVIEW_InvalidateList(infoPtr);
6062 /* LISTVIEW_SetBkImage */
6064 /*** Helper for {Insert,Set}ColumnT *only* */
6065 static void column_fill_hditem(LISTVIEW_INFO *infoPtr, HDITEMW *lphdi, INT nColumn, const LVCOLUMNW *lpColumn, BOOL isW)
6067 if (lpColumn->mask & LVCF_FMT)
6069 /* format member is valid */
6070 lphdi->mask |= HDI_FORMAT;
6072 /* set text alignment (leftmost column must be left-aligned) */
6073 if (nColumn == 0 || lpColumn->fmt & LVCFMT_LEFT)
6074 lphdi->fmt |= HDF_LEFT;
6075 else if (lpColumn->fmt & LVCFMT_RIGHT)
6076 lphdi->fmt |= HDF_RIGHT;
6077 else if (lpColumn->fmt & LVCFMT_CENTER)
6078 lphdi->fmt |= HDF_CENTER;
6080 if (lpColumn->fmt & LVCFMT_BITMAP_ON_RIGHT)
6081 lphdi->fmt |= HDF_BITMAP_ON_RIGHT;
6083 if (lpColumn->fmt & LVCFMT_COL_HAS_IMAGES)
6085 lphdi->fmt |= HDF_IMAGE;
6086 lphdi->iImage = I_IMAGECALLBACK;
6090 if (lpColumn->mask & LVCF_WIDTH)
6092 lphdi->mask |= HDI_WIDTH;
6093 if(lpColumn->cx == LVSCW_AUTOSIZE_USEHEADER)
6095 /* make it fill the remainder of the controls width */
6099 for(item_index = 0; item_index < (nColumn - 1); item_index++)
6101 LISTVIEW_GetHeaderRect(infoPtr, item_index, &rcHeader);
6102 lphdi->cxy += rcHeader.right - rcHeader.left;
6105 /* retrieve the layout of the header */
6106 GetClientRect(infoPtr->hwndSelf, &rcHeader);
6107 TRACE("start cxy=%d rcHeader=%s\n", lphdi->cxy, debugrect(&rcHeader));
6109 lphdi->cxy = (rcHeader.right - rcHeader.left) - lphdi->cxy;
6112 lphdi->cxy = lpColumn->cx;
6115 if (lpColumn->mask & LVCF_TEXT)
6117 lphdi->mask |= HDI_TEXT | HDI_FORMAT;
6118 lphdi->fmt |= HDF_STRING;
6119 lphdi->pszText = lpColumn->pszText;
6120 lphdi->cchTextMax = textlenT(lpColumn->pszText, isW);
6123 if (lpColumn->mask & LVCF_IMAGE)
6125 lphdi->mask |= HDI_IMAGE;
6126 lphdi->iImage = lpColumn->iImage;
6129 if (lpColumn->mask & LVCF_ORDER)
6131 lphdi->mask |= HDI_ORDER;
6132 lphdi->iOrder = lpColumn->iOrder;
6139 * Inserts a new column.
6142 * [I] infoPtr : valid pointer to the listview structure
6143 * [I] nColumn : column index
6144 * [I] lpColumn : column information
6145 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
6148 * SUCCESS : new column index
6151 static INT LISTVIEW_InsertColumnT(LISTVIEW_INFO *infoPtr, INT nColumn,
6152 const LVCOLUMNW *lpColumn, BOOL isW)
6154 COLUMN_INFO *lpColumnInfo;
6158 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn, debuglvcolumn_t(lpColumn, isW), isW);
6160 if (!lpColumn || nColumn < 0) return -1;
6161 nColumn = min(nColumn, infoPtr->hdpaColumns->nItemCount);
6163 ZeroMemory(&hdi, sizeof(HDITEMW));
6164 column_fill_hditem(infoPtr, &hdi, nColumn, lpColumn, isW);
6166 /* insert item in header control */
6167 nNewColumn = SendMessageW(infoPtr->hwndHeader,
6168 isW ? HDM_INSERTITEMW : HDM_INSERTITEMA,
6169 (WPARAM)nColumn, (LPARAM)&hdi);
6170 if (nNewColumn == -1) return -1;
6171 if (nNewColumn != nColumn) ERR("nColumn=%d, nNewColumn=%d\n", nColumn, nNewColumn);
6173 /* create our own column info */
6174 if (!(lpColumnInfo = COMCTL32_Alloc(sizeof(COLUMN_INFO)))) goto fail;
6175 if (DPA_InsertPtr(infoPtr->hdpaColumns, nNewColumn, lpColumnInfo) == -1) goto fail;
6177 if (lpColumn->mask & LVCF_FMT) lpColumnInfo->fmt = lpColumn->fmt;
6178 if (!Header_GetItemRect(infoPtr->hwndHeader, nNewColumn, &lpColumnInfo->rcHeader)) goto fail;
6180 /* now we have to actually adjust the data */
6181 if (!(infoPtr->dwStyle & LVS_OWNERDATA) && infoPtr->nItemCount > 0)
6183 SUBITEM_INFO *lpSubItem, *lpMainItem, **lpNewItems = 0;
6187 /* preallocate memory, so we can fail gracefully */
6188 if (nNewColumn == 0)
6190 lpNewItems = COMCTL32_Alloc(sizeof(SUBITEM_INFO *) * infoPtr->nItemCount);
6191 if (!lpNewItems) goto fail;
6192 for (i = 0; i < infoPtr->nItemCount; i++)
6193 if (!(lpNewItems[i] = COMCTL32_Alloc(sizeof(SUBITEM_INFO)))) break;
6194 if (i != infoPtr->nItemCount)
6196 for(; i >=0; i--) COMCTL32_Free(lpNewItems[i]);
6197 COMCTL32_Free(lpNewItems);
6202 for (nItem = 0; nItem < infoPtr->nItemCount; nItem++)
6204 hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, nItem);
6205 for (i = 1; i < hdpaSubItems->nItemCount; i++)
6207 lpSubItem = (SUBITEM_INFO *)DPA_GetPtr(hdpaSubItems, i);
6208 if (lpSubItem->iSubItem >= nNewColumn)
6209 lpSubItem->iSubItem++;
6212 /* for inserting column 0, we have to special-case the main item */
6213 if (nNewColumn == 0)
6215 lpMainItem = (SUBITEM_INFO *)DPA_GetPtr(hdpaSubItems, 0);
6216 lpSubItem = lpNewItems[nItem];
6217 lpSubItem->hdr = lpMainItem->hdr;
6218 lpSubItem->iSubItem = 1;
6219 ZeroMemory(&lpMainItem->hdr, sizeof(lpMainItem->hdr));
6220 lpMainItem->iSubItem = 0;
6221 DPA_InsertPtr(hdpaSubItems, 1, lpSubItem);
6225 COMCTL32_Free(lpNewItems);
6228 /* make space for the new column */
6229 LISTVIEW_ScrollColumns(infoPtr, nNewColumn + 1, lpColumnInfo->rcHeader.right - lpColumnInfo->rcHeader.left);
6234 if (nNewColumn != -1) SendMessageW(infoPtr->hwndHeader, HDM_DELETEITEM, nNewColumn, 0);
6237 DPA_DeletePtr(infoPtr->hdpaColumns, nNewColumn);
6238 COMCTL32_Free(lpColumnInfo);
6245 * Sets the attributes of a header item.
6248 * [I] infoPtr : valid pointer to the listview structure
6249 * [I] nColumn : column index
6250 * [I] lpColumn : column attributes
6251 * [I] isW: if TRUE, the lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
6257 static BOOL LISTVIEW_SetColumnT(LISTVIEW_INFO *infoPtr, INT nColumn,
6258 const LVCOLUMNW *lpColumn, BOOL isW)
6260 HDITEMW hdi, hdiget;
6263 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn, debuglvcolumn_t(lpColumn, isW), isW);
6265 if (!lpColumn || nColumn < 0 || nColumn >= infoPtr->hdpaColumns->nItemCount) return FALSE;
6267 ZeroMemory(&hdi, sizeof(HDITEMW));
6268 if (lpColumn->mask & LVCF_FMT)
6270 hdi.mask |= HDI_FORMAT;
6271 hdiget.mask = HDI_FORMAT;
6272 if (Header_GetItemW(infoPtr->hwndHeader, nColumn, &hdiget))
6273 hdi.fmt = hdiget.fmt & HDF_STRING;
6275 column_fill_hditem(infoPtr, &hdi, nColumn, lpColumn, isW);
6277 /* set header item attributes */
6278 bResult = SendMessageW(infoPtr->hwndHeader, isW ? HDM_SETITEMW : HDM_SETITEMA, (WPARAM)nColumn, (LPARAM)&hdi);
6279 if (!bResult) return FALSE;
6281 if (lpColumn->mask & LVCF_FMT)
6283 COLUMN_INFO *lpColumnInfo = LISTVIEW_GetColumnInfo(infoPtr, nColumn);
6284 int oldFmt = lpColumnInfo->fmt;
6286 lpColumnInfo->fmt = lpColumn->fmt;
6287 if ((oldFmt ^ lpColumn->fmt) & (LVCFMT_JUSTIFYMASK | LVCFMT_IMAGE))
6289 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
6290 if (uView == LVS_REPORT) LISTVIEW_InvalidateColumn(infoPtr, nColumn);
6299 * Sets the column order array
6302 * [I] infoPtr : valid pointer to the listview structure
6303 * [I] iCount : number of elements in column order array
6304 * [I] lpiArray : pointer to column order array
6310 static BOOL LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO *infoPtr, INT iCount, const INT *lpiArray)
6312 FIXME("iCount %d lpiArray %p\n", iCount, lpiArray);
6323 * Sets the width of a column
6326 * [I] infoPtr : valid pointer to the listview structure
6327 * [I] nColumn : column index
6328 * [I] cx : column width
6334 static BOOL LISTVIEW_SetColumnWidth(LISTVIEW_INFO *infoPtr, INT nColumn, INT cx)
6336 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
6337 WCHAR szDispText[DISP_TEXT_SIZE] = { 0 };
6341 TRACE("(nColumn=%d, cx=%d\n", nColumn, cx);
6343 /* set column width only if in report or list mode */
6344 if (uView != LVS_REPORT && uView != LVS_LIST) return FALSE;
6346 /* take care of invalid cx values */
6347 if(uView == LVS_REPORT && cx < -2) cx = LVSCW_AUTOSIZE;
6348 else if (uView == LVS_LIST && cx < 1) return FALSE;
6350 /* resize all columns if in LVS_LIST mode */
6351 if(uView == LVS_LIST)
6353 infoPtr->nItemWidth = cx;
6354 LISTVIEW_InvalidateList(infoPtr);
6358 if (nColumn < 0 || nColumn >= infoPtr->hdpaColumns->nItemCount) return FALSE;
6360 if (cx == LVSCW_AUTOSIZE || (cx == LVSCW_AUTOSIZE_USEHEADER && nColumn < infoPtr->hdpaColumns->nItemCount -1))
6365 lvItem.mask = LVIF_TEXT;
6367 lvItem.iSubItem = nColumn;
6368 lvItem.pszText = szDispText;
6369 lvItem.cchTextMax = DISP_TEXT_SIZE;
6370 for (; lvItem.iItem < infoPtr->nItemCount; lvItem.iItem++)
6372 if (!LISTVIEW_GetItemW(infoPtr, &lvItem)) continue;
6373 nLabelWidth = LISTVIEW_GetStringWidthT(infoPtr, lvItem.pszText, TRUE);
6374 if (max_cx < nLabelWidth) max_cx = nLabelWidth;
6376 if (infoPtr->himlSmall && (nColumn == 0 || (LISTVIEW_GetColumnInfo(infoPtr, nColumn)->fmt & LVCFMT_IMAGE)))
6377 max_cx += infoPtr->iconSize.cx;
6378 max_cx += TRAILING_LABEL_PADDING;
6381 /* autosize based on listview items width */
6382 if(cx == LVSCW_AUTOSIZE)
6384 else if(cx == LVSCW_AUTOSIZE_USEHEADER)
6386 /* if iCol is the last column make it fill the remainder of the controls width */
6387 if(nColumn == infoPtr->hdpaColumns->nItemCount - 1)
6392 LISTVIEW_GetOrigin(infoPtr, &Origin);
6393 LISTVIEW_GetHeaderRect(infoPtr, nColumn, &rcHeader);
6395 cx = infoPtr->rcList.right - Origin.x - rcHeader.left;
6399 /* Despite what the MS docs say, if this is not the last
6400 column, then MS resizes the column to the width of the
6401 largest text string in the column, including headers
6402 and items. This is different from LVSCW_AUTOSIZE in that
6403 LVSCW_AUTOSIZE ignores the header string length. */
6406 /* retrieve header text */
6407 hdi.mask = HDI_TEXT;
6408 hdi.cchTextMax = DISP_TEXT_SIZE;
6409 hdi.pszText = szDispText;
6410 if (Header_GetItemW(infoPtr->hwndHeader, nColumn, (LPARAM)&hdi))
6412 HDC hdc = GetDC(infoPtr->hwndSelf);
6413 HFONT old_font = SelectObject(hdc, (HFONT)SendMessageW(infoPtr->hwndHeader, WM_GETFONT, 0, 0));
6416 if (GetTextExtentPoint32W(hdc, hdi.pszText, lstrlenW(hdi.pszText), &size))
6417 cx = size.cx + TRAILING_HEADER_PADDING;
6418 /* FIXME: Take into account the header image, if one is present */
6419 SelectObject(hdc, old_font);
6420 ReleaseDC(infoPtr->hwndSelf, hdc);
6422 cx = max (cx, max_cx);
6426 if (cx < 0) return FALSE;
6428 /* call header to update the column change */
6429 hdi.mask = HDI_WIDTH;
6431 TRACE("hdi.cxy=%d\n", hdi.cxy);
6432 return Header_SetItemW(infoPtr->hwndHeader, nColumn, (LPARAM)&hdi);
6437 * Sets the extended listview style.
6440 * [I] infoPtr : valid pointer to the listview structure
6442 * [I] dwStyle : style
6445 * SUCCESS : previous style
6448 static DWORD LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO *infoPtr, DWORD dwMask, DWORD dwStyle)
6450 DWORD dwOldStyle = infoPtr->dwLvExStyle;
6454 infoPtr->dwLvExStyle = (dwOldStyle & ~dwMask) | (dwStyle & dwMask);
6456 infoPtr->dwLvExStyle = dwStyle;
6463 * Sets the new hot cursor used during hot tracking and hover selection.
6466 * [I] infoPtr : valid pointer to the listview structure
6467 * [I} hCurosr : the new hot cursor handle
6470 * Returns the previous hot cursor
6472 static HCURSOR LISTVIEW_SetHotCursor(LISTVIEW_INFO *infoPtr, HCURSOR hCursor)
6474 HCURSOR oldCursor = infoPtr->hHotCursor;
6476 infoPtr->hHotCursor = hCursor;
6484 * Sets the hot item index.
6487 * [I] infoPtr : valid pointer to the listview structure
6488 * [I] iIndex : index
6491 * SUCCESS : previous hot item index
6492 * FAILURE : -1 (no hot item)
6494 static INT LISTVIEW_SetHotItem(LISTVIEW_INFO *infoPtr, INT iIndex)
6496 INT iOldIndex = infoPtr->nHotItem;
6498 infoPtr->nHotItem = iIndex;
6506 * Sets the amount of time the cursor must hover over an item before it is selected.
6509 * [I] infoPtr : valid pointer to the listview structure
6510 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
6513 * Returns the previous hover time
6515 static DWORD LISTVIEW_SetHoverTime(LISTVIEW_INFO *infoPtr, DWORD dwHoverTime)
6517 DWORD oldHoverTime = infoPtr->dwHoverTime;
6519 infoPtr->dwHoverTime = dwHoverTime;
6521 return oldHoverTime;
6526 * Sets spacing for icons of LVS_ICON style.
6529 * [I] infoPtr : valid pointer to the listview structure
6530 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
6531 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
6534 * MAKELONG(oldcx, oldcy)
6536 static DWORD LISTVIEW_SetIconSpacing(LISTVIEW_INFO *infoPtr, INT cx, INT cy)
6538 DWORD oldspacing = MAKELONG(infoPtr->iconSpacing.cx, infoPtr->iconSpacing.cy);
6539 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
6541 TRACE("requested=(%d,%d)\n", cx, cy);
6543 /* this is supported only for LVS_ICON style */
6544 if (uView != LVS_ICON) return oldspacing;
6546 /* set to defaults, if instructed to */
6547 if (cx == -1) cx = GetSystemMetrics(SM_CXICONSPACING);
6548 if (cy == -1) cy = GetSystemMetrics(SM_CYICONSPACING);
6550 /* if 0 then compute width
6551 * FIXME: Should scan each item and determine max width of
6552 * icon or label, then make that the width */
6554 cx = infoPtr->iconSpacing.cx;
6556 /* if 0 then compute height */
6558 cy = infoPtr->iconSize.cy + 2 * infoPtr->ntmHeight +
6559 ICON_BOTTOM_PADDING + ICON_TOP_PADDING + LABEL_VERT_PADDING;
6562 infoPtr->iconSpacing.cx = cx;
6563 infoPtr->iconSpacing.cy = cy;
6565 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%ld,%ld), ntmH=%d\n",
6566 LOWORD(oldspacing), HIWORD(oldspacing), cx, cy,
6567 infoPtr->iconSize.cx, infoPtr->iconSize.cy,
6568 infoPtr->ntmHeight);
6570 /* these depend on the iconSpacing */
6571 LISTVIEW_UpdateItemSize(infoPtr);
6576 inline void set_icon_size(SIZE *size, HIMAGELIST himl, BOOL small)
6580 if (himl && ImageList_GetIconSize(himl, &cx, &cy))
6587 size->cx = GetSystemMetrics(small ? SM_CXSMICON : SM_CXICON);
6588 size->cy = GetSystemMetrics(small ? SM_CYSMICON : SM_CYICON);
6597 * [I] infoPtr : valid pointer to the listview structure
6598 * [I] nType : image list type
6599 * [I] himl : image list handle
6602 * SUCCESS : old image list
6605 static HIMAGELIST LISTVIEW_SetImageList(LISTVIEW_INFO *infoPtr, INT nType, HIMAGELIST himl)
6607 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
6608 INT oldHeight = infoPtr->nItemHeight;
6609 HIMAGELIST himlOld = 0;
6611 TRACE("(nType=%d, himl=%p\n", nType, himl);
6616 himlOld = infoPtr->himlNormal;
6617 infoPtr->himlNormal = himl;
6618 if (uView == LVS_ICON) set_icon_size(&infoPtr->iconSize, himl, FALSE);
6619 LISTVIEW_SetIconSpacing(infoPtr, 0, 0);
6623 himlOld = infoPtr->himlSmall;
6624 infoPtr->himlSmall = himl;
6625 if (uView != LVS_ICON) set_icon_size(&infoPtr->iconSize, himl, TRUE);
6629 himlOld = infoPtr->himlState;
6630 infoPtr->himlState = himl;
6631 set_icon_size(&infoPtr->iconStateSize, himl, TRUE);
6632 ImageList_SetBkColor(infoPtr->himlState, CLR_NONE);
6636 ERR("Unknown icon type=%d\n", nType);
6640 infoPtr->nItemHeight = LISTVIEW_CalculateItemHeight(infoPtr);
6641 if (infoPtr->nItemHeight != oldHeight)
6642 LISTVIEW_UpdateScroll(infoPtr);
6649 * Preallocates memory (does *not* set the actual count of items !)
6652 * [I] infoPtr : valid pointer to the listview structure
6653 * [I] nItems : item count (projected number of items to allocate)
6654 * [I] dwFlags : update flags
6660 static BOOL LISTVIEW_SetItemCount(LISTVIEW_INFO *infoPtr, INT nItems, DWORD dwFlags)
6662 TRACE("(nItems=%d, dwFlags=%lx)\n", nItems, dwFlags);
6664 if (infoPtr->dwStyle & LVS_OWNERDATA)
6666 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
6667 INT nOldCount = infoPtr->nItemCount;
6669 if (nItems < nOldCount)
6671 RANGE range = { nItems, nOldCount };
6672 ranges_del(infoPtr->selectionRanges, range);
6673 if (infoPtr->nFocusedItem >= nItems)
6675 infoPtr->nFocusedItem = -1;
6676 SetRectEmpty(&infoPtr->rcFocus);
6680 infoPtr->nItemCount = nItems;
6681 LISTVIEW_UpdateScroll(infoPtr);
6683 /* the flags are valid only in ownerdata report and list modes */
6684 if (uView == LVS_ICON || uView == LVS_SMALLICON) dwFlags = 0;
6686 if (!(dwFlags & LVSICF_NOSCROLL) && infoPtr->nFocusedItem != -1)
6687 LISTVIEW_EnsureVisible(infoPtr, infoPtr->nFocusedItem, FALSE);
6689 if (!(dwFlags & LVSICF_NOINVALIDATEALL))
6690 LISTVIEW_InvalidateList(infoPtr);
6697 LISTVIEW_GetOrigin(infoPtr, &Origin);
6698 nFrom = min(nOldCount, nItems);
6699 nTo = max(nOldCount, nItems);
6701 if (uView == LVS_REPORT)
6704 rcErase.top = nFrom * infoPtr->nItemHeight;
6705 rcErase.right = infoPtr->nItemWidth;
6706 rcErase.bottom = nTo * infoPtr->nItemHeight;
6707 OffsetRect(&rcErase, Origin.x, Origin.y);
6708 if (IntersectRect(&rcErase, &rcErase, &infoPtr->rcList))
6709 LISTVIEW_InvalidateRect(infoPtr, &rcErase);
6713 INT nPerCol = LISTVIEW_GetCountPerColumn(infoPtr);
6715 rcErase.left = (nFrom / nPerCol) * infoPtr->nItemWidth;
6716 rcErase.top = (nFrom % nPerCol) * infoPtr->nItemHeight;
6717 rcErase.right = rcErase.left + infoPtr->nItemWidth;
6718 rcErase.bottom = nPerCol * infoPtr->nItemHeight;
6719 OffsetRect(&rcErase, Origin.x, Origin.y);
6720 if (IntersectRect(&rcErase, &rcErase, &infoPtr->rcList))
6721 LISTVIEW_InvalidateRect(infoPtr, &rcErase);
6723 rcErase.left = (nFrom / nPerCol + 1) * infoPtr->nItemWidth;
6725 rcErase.right = (nTo / nPerCol + 1) * infoPtr->nItemWidth;
6726 rcErase.bottom = nPerCol * infoPtr->nItemHeight;
6727 OffsetRect(&rcErase, Origin.x, Origin.y);
6728 if (IntersectRect(&rcErase, &rcErase, &infoPtr->rcList))
6729 LISTVIEW_InvalidateRect(infoPtr, &rcErase);
6735 /* According to MSDN for non-LVS_OWNERDATA this is just
6736 * a performance issue. The control allocates its internal
6737 * data structures for the number of items specified. It
6738 * cuts down on the number of memory allocations. Therefore
6739 * we will just issue a WARN here
6741 WARN("for non-ownerdata performance option not implemented.\n");
6749 * Sets the position of an item.
6752 * [I] infoPtr : valid pointer to the listview structure
6753 * [I] nItem : item index
6754 * [I] pt : coordinate
6760 static BOOL LISTVIEW_SetItemPosition(LISTVIEW_INFO *infoPtr, INT nItem, POINT pt)
6762 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
6765 TRACE("(nItem=%d, &pt=%s\n", nItem, debugpoint(&pt));
6767 if (nItem < 0 || nItem >= infoPtr->nItemCount ||
6768 !(uView == LVS_ICON || uView == LVS_SMALLICON)) return FALSE;
6770 LISTVIEW_GetOrigin(infoPtr, &Origin);
6772 /* This point value seems to be an undocumented feature.
6773 * The best guess is that it means either at the origin,
6774 * or at true beginning of the list. I will assume the origin. */
6775 if ((pt.x == -1) && (pt.y == -1))
6778 if (uView == LVS_ICON)
6780 pt.x -= (infoPtr->nItemWidth - infoPtr->iconSize.cx) / 2;
6781 pt.y -= ICON_TOP_PADDING;
6786 infoPtr->bAutoarrange = FALSE;
6788 return LISTVIEW_MoveIconTo(infoPtr, nItem, &pt, FALSE);
6793 * Sets the state of one or many items.
6796 * [I] infoPtr : valid pointer to the listview structure
6797 * [I] nItem : item index
6798 * [I] lpLVItem : item or subitem info
6804 static BOOL LISTVIEW_SetItemState(LISTVIEW_INFO *infoPtr, INT nItem, const LVITEMW *lpLVItem)
6806 BOOL bResult = TRUE;
6809 lvItem.iItem = nItem;
6810 lvItem.iSubItem = 0;
6811 lvItem.mask = LVIF_STATE;
6812 lvItem.state = lpLVItem->state;
6813 lvItem.stateMask = lpLVItem->stateMask;
6814 TRACE("lvItem=%s\n", debuglvitem_t(&lvItem, TRUE));
6818 /* apply to all items */
6819 for (lvItem.iItem = 0; lvItem.iItem < infoPtr->nItemCount; lvItem.iItem++)
6820 if (!LISTVIEW_SetItemT(infoPtr, &lvItem, TRUE)) bResult = FALSE;
6823 bResult = LISTVIEW_SetItemT(infoPtr, &lvItem, TRUE);
6830 * Sets the text of an item or subitem.
6833 * [I] hwnd : window handle
6834 * [I] nItem : item index
6835 * [I] lpLVItem : item or subitem info
6836 * [I] isW : TRUE if input is Unicode
6842 static BOOL LISTVIEW_SetItemTextT(LISTVIEW_INFO *infoPtr, INT nItem, const LVITEMW *lpLVItem, BOOL isW)
6846 if (nItem < 0 && nItem >= infoPtr->nItemCount) return FALSE;
6848 lvItem.iItem = nItem;
6849 lvItem.iSubItem = lpLVItem->iSubItem;
6850 lvItem.mask = LVIF_TEXT;
6851 lvItem.pszText = lpLVItem->pszText;
6852 lvItem.cchTextMax = lpLVItem->cchTextMax;
6854 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem, debuglvitem_t(&lvItem, isW), isW);
6856 return LISTVIEW_SetItemT(infoPtr, &lvItem, isW);
6861 * Set item index that marks the start of a multiple selection.
6864 * [I] infoPtr : valid pointer to the listview structure
6865 * [I] nIndex : index
6868 * Index number or -1 if there is no selection mark.
6870 static INT LISTVIEW_SetSelectionMark(LISTVIEW_INFO *infoPtr, INT nIndex)
6872 INT nOldIndex = infoPtr->nSelectionMark;
6874 TRACE("(nIndex=%d)\n", nIndex);
6876 infoPtr->nSelectionMark = nIndex;
6883 * Sets the text background color.
6886 * [I] infoPtr : valid pointer to the listview structure
6887 * [I] clrTextBk : text background color
6893 static BOOL LISTVIEW_SetTextBkColor(LISTVIEW_INFO *infoPtr, COLORREF clrTextBk)
6895 TRACE("(clrTextBk=%lx)\n", clrTextBk);
6897 if (infoPtr->clrTextBk != clrTextBk)
6899 infoPtr->clrTextBk = clrTextBk;
6900 LISTVIEW_InvalidateList(infoPtr);
6908 * Sets the text foreground color.
6911 * [I] infoPtr : valid pointer to the listview structure
6912 * [I] clrText : text color
6918 static BOOL LISTVIEW_SetTextColor (LISTVIEW_INFO *infoPtr, COLORREF clrText)
6920 TRACE("(clrText=%lx)\n", clrText);
6922 if (infoPtr->clrText != clrText)
6924 infoPtr->clrText = clrText;
6925 LISTVIEW_InvalidateList(infoPtr);
6931 /* LISTVIEW_SetToolTips */
6932 /* LISTVIEW_SetUnicodeFormat */
6933 /* LISTVIEW_SetWorkAreas */
6937 * Callback internally used by LISTVIEW_SortItems()
6940 * [I] first : pointer to first ITEM_INFO to compare
6941 * [I] second : pointer to second ITEM_INFO to compare
6942 * [I] lParam : HWND of control
6945 * if first comes before second : negative
6946 * if first comes after second : positive
6947 * if first and second are equivalent : zero
6949 static INT WINAPI LISTVIEW_CallBackCompare(LPVOID first, LPVOID second, LPARAM lParam)
6951 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW((HWND)lParam, 0);
6952 ITEM_INFO* lv_first = (ITEM_INFO*) DPA_GetPtr( (HDPA)first, 0 );
6953 ITEM_INFO* lv_second = (ITEM_INFO*) DPA_GetPtr( (HDPA)second, 0 );
6955 /* Forward the call to the client defined callback */
6956 return (infoPtr->pfnCompare)( lv_first->lParam , lv_second->lParam, infoPtr->lParamSort );
6961 * Sorts the listview items.
6964 * [I] infoPtr : valid pointer to the listview structure
6965 * [I] pfnCompare : application-defined value
6966 * [I] lParamSort : pointer to comparision callback
6972 static BOOL LISTVIEW_SortItems(LISTVIEW_INFO *infoPtr, PFNLVCOMPARE pfnCompare, LPARAM lParamSort)
6974 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
6977 LPVOID selectionMarkItem;
6981 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare, lParamSort);
6983 if (infoPtr->dwStyle & LVS_OWNERDATA) return FALSE;
6985 if (!infoPtr->hdpaItems) return FALSE;
6987 /* if there are 0 or 1 items, there is no need to sort */
6988 if (infoPtr->nItemCount < 2) return TRUE;
6990 if (infoPtr->nFocusedItem >= 0)
6992 hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, infoPtr->nFocusedItem);
6993 lpItem = (ITEM_INFO *)DPA_GetPtr(hdpaSubItems, 0);
6994 if (lpItem) lpItem->state |= LVIS_FOCUSED;
6996 /* FIXME: go thorugh selected items and mark them so in lpItem->state */
6997 /* clear the lpItem->state for non-selected ones */
6998 /* remove the selection ranges */
7000 infoPtr->pfnCompare = pfnCompare;
7001 infoPtr->lParamSort = lParamSort;
7002 DPA_Sort(infoPtr->hdpaItems, LISTVIEW_CallBackCompare, (LPARAM)infoPtr->hwndSelf);
7004 /* Adjust selections and indices so that they are the way they should
7005 * be after the sort (otherwise, the list items move around, but
7006 * whatever is at the item's previous original position will be
7009 selectionMarkItem=(infoPtr->nSelectionMark>=0)?DPA_GetPtr(infoPtr->hdpaItems, infoPtr->nSelectionMark):NULL;
7010 for (i=0; i < infoPtr->nItemCount; i++)
7012 hdpaSubItems = (HDPA)DPA_GetPtr(infoPtr->hdpaItems, i);
7013 lpItem = (ITEM_INFO *)DPA_GetPtr(hdpaSubItems, 0);
7015 if (lpItem->state & LVIS_SELECTED)
7017 item.state = LVIS_SELECTED;
7018 item.stateMask = LVIS_SELECTED;
7019 LISTVIEW_SetItemState(infoPtr, i, &item);
7021 if (lpItem->state & LVIS_FOCUSED)
7023 infoPtr->nFocusedItem = i;
7024 lpItem->state &= ~LVIS_FOCUSED;
7027 if (selectionMarkItem != NULL)
7028 infoPtr->nSelectionMark = DPA_GetPtrIndex(infoPtr->hdpaItems, selectionMarkItem);
7029 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
7031 /* refresh the display */
7032 if (uView != LVS_ICON && uView != LVS_SMALLICON)
7033 LISTVIEW_InvalidateList(infoPtr);
7040 * Updates an items or rearranges the listview control.
7043 * [I] infoPtr : valid pointer to the listview structure
7044 * [I] nItem : item index
7050 static BOOL LISTVIEW_Update(LISTVIEW_INFO *infoPtr, INT nItem)
7052 TRACE("(nItem=%d)\n", nItem);
7054 if (nItem < 0 || nItem >= infoPtr->nItemCount) return FALSE;
7056 /* rearrange with default alignment style */
7057 if (is_autoarrange(infoPtr))
7058 LISTVIEW_Arrange(infoPtr, LVA_DEFAULT);
7060 LISTVIEW_InvalidateItem(infoPtr, nItem);
7068 * Creates the listview control.
7071 * [I] hwnd : window handle
7072 * [I] lpcs : the create parameters
7078 static LRESULT LISTVIEW_Create(HWND hwnd, const CREATESTRUCTW *lpcs)
7080 LISTVIEW_INFO *infoPtr;
7081 UINT uView = lpcs->style & LVS_TYPEMASK;
7084 TRACE("(lpcs=%p)\n", lpcs);
7086 /* initialize info pointer */
7087 infoPtr = (LISTVIEW_INFO *)COMCTL32_Alloc(sizeof(LISTVIEW_INFO));
7088 if (!infoPtr) return -1;
7090 SetWindowLongW(hwnd, 0, (LONG)infoPtr);
7092 infoPtr->hwndSelf = hwnd;
7093 infoPtr->dwStyle = lpcs->style;
7094 /* determine the type of structures to use */
7095 infoPtr->notifyFormat = SendMessageW(GetParent(infoPtr->hwndSelf), WM_NOTIFYFORMAT,
7096 (WPARAM)infoPtr->hwndSelf, (LPARAM)NF_QUERY);
7098 /* initialize color information */
7099 infoPtr->clrBk = CLR_NONE;
7100 infoPtr->clrText = comctl32_color.clrWindowText;
7101 infoPtr->clrTextBk = CLR_DEFAULT;
7102 LISTVIEW_SetBkColor(infoPtr, comctl32_color.clrWindow);
7104 /* set default values */
7105 infoPtr->nFocusedItem = -1;
7106 infoPtr->nSelectionMark = -1;
7107 infoPtr->nHotItem = -1;
7108 infoPtr->bRedraw = TRUE;
7109 infoPtr->bFirstPaint = TRUE;
7110 infoPtr->bNoItemMetrics = TRUE;
7111 infoPtr->bDoChangeNotify = TRUE;
7112 infoPtr->iconSpacing.cx = GetSystemMetrics(SM_CXICONSPACING);
7113 infoPtr->iconSpacing.cy = GetSystemMetrics(SM_CYICONSPACING);
7114 infoPtr->nEditLabelItem = -1;
7115 infoPtr->dwHoverTime = -1; /* default system hover time */
7117 /* get default font (icon title) */
7118 SystemParametersInfoW(SPI_GETICONTITLELOGFONT, 0, &logFont, 0);
7119 infoPtr->hDefaultFont = CreateFontIndirectW(&logFont);
7120 infoPtr->hFont = infoPtr->hDefaultFont;
7121 LISTVIEW_SaveTextMetrics(infoPtr);
7124 infoPtr->hwndHeader = CreateWindowW(WC_HEADERW, NULL,
7125 WS_CHILD | HDS_HORZ | (DWORD)((LVS_NOSORTHEADER & lpcs->style)?0:HDS_BUTTONS),
7126 0, 0, 0, 0, hwnd, NULL,
7127 lpcs->hInstance, NULL);
7128 if (!infoPtr->hwndHeader) goto fail;
7130 /* set header unicode format */
7131 SendMessageW(infoPtr->hwndHeader, HDM_SETUNICODEFORMAT, (WPARAM)TRUE, (LPARAM)NULL);
7133 /* set header font */
7134 SendMessageW(infoPtr->hwndHeader, WM_SETFONT, (WPARAM)infoPtr->hFont, (LPARAM)TRUE);
7136 /* allocate memory for the data structure */
7137 if (!(infoPtr->selectionRanges = ranges_create(10))) goto fail;
7138 if (!(infoPtr->hdpaItems = DPA_Create(10))) goto fail;
7139 if (!(infoPtr->hdpaPosX = DPA_Create(10))) goto fail;
7140 if (!(infoPtr->hdpaPosY = DPA_Create(10))) goto fail;
7141 if (!(infoPtr->hdpaColumns = DPA_Create(10))) goto fail;
7143 /* initialize the icon sizes */
7144 set_icon_size(&infoPtr->iconSize, infoPtr->himlNormal, uView != LVS_ICON);
7145 set_icon_size(&infoPtr->iconStateSize, infoPtr->himlState, TRUE);
7147 /* init item size to avoid division by 0 */
7148 LISTVIEW_UpdateItemSize (infoPtr);
7150 if (uView == LVS_REPORT)
7152 if (!(LVS_NOCOLUMNHEADER & lpcs->style))
7154 ShowWindow(infoPtr->hwndHeader, SW_SHOWNORMAL);
7158 /* set HDS_HIDDEN flag to hide the header bar */
7159 SetWindowLongW(infoPtr->hwndHeader, GWL_STYLE,
7160 GetWindowLongW(infoPtr->hwndHeader, GWL_STYLE) | HDS_HIDDEN);
7167 DestroyWindow(infoPtr->hwndHeader);
7168 ranges_destroy(infoPtr->selectionRanges);
7169 DPA_Destroy(infoPtr->hdpaItems);
7170 DPA_Destroy(infoPtr->hdpaPosX);
7171 DPA_Destroy(infoPtr->hdpaPosY);
7172 DPA_Destroy(infoPtr->hdpaColumns);
7173 COMCTL32_Free(infoPtr);
7179 * Erases the background of the listview control.
7182 * [I] infoPtr : valid pointer to the listview structure
7183 * [I] hdc : device context handle
7189 static inline BOOL LISTVIEW_EraseBkgnd(LISTVIEW_INFO *infoPtr, HDC hdc)
7193 TRACE("(hdc=%p)\n", hdc);
7195 if (!GetClipBox(hdc, &rc)) return FALSE;
7197 return LISTVIEW_FillBkgnd(infoPtr, hdc, &rc);
7203 * Helper function for LISTVIEW_[HV]Scroll *only*.
7204 * Performs vertical/horizontal scrolling by a give amount.
7207 * [I] infoPtr : valid pointer to the listview structure
7208 * [I] dx : amount of horizontal scroll
7209 * [I] dy : amount of vertical scroll
7211 static void scroll_list(LISTVIEW_INFO *infoPtr, INT dx, INT dy)
7213 /* now we can scroll the list */
7214 ScrollWindowEx(infoPtr->hwndSelf, dx, dy, &infoPtr->rcList,
7215 &infoPtr->rcList, 0, 0, SW_ERASE | SW_INVALIDATE);
7216 /* if we have focus, adjust rect */
7217 OffsetRect(&infoPtr->rcFocus, dx, dy);
7218 UpdateWindow(infoPtr->hwndSelf);
7223 * Performs vertical scrolling.
7226 * [I] infoPtr : valid pointer to the listview structure
7227 * [I] nScrollCode : scroll code
7228 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
7229 * [I] hScrollWnd : scrollbar control window handle
7235 * SB_LINEUP/SB_LINEDOWN:
7236 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
7237 * for LVS_REPORT is 1 line
7238 * for LVS_LIST cannot occur
7241 static LRESULT LISTVIEW_VScroll(LISTVIEW_INFO *infoPtr, INT nScrollCode,
7242 INT nScrollDiff, HWND hScrollWnd)
7244 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
7245 INT nOldScrollPos, nNewScrollPos;
7246 SCROLLINFO scrollInfo;
7249 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode,
7250 debugscrollcode(nScrollCode), nScrollDiff);
7252 if (infoPtr->hwndEdit) SendMessageW(infoPtr->hwndEdit, WM_KILLFOCUS, 0, 0);
7254 scrollInfo.cbSize = sizeof(SCROLLINFO);
7255 scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_TRACKPOS;
7257 is_an_icon = ((uView == LVS_ICON) || (uView == LVS_SMALLICON));
7259 if (!GetScrollInfo(infoPtr->hwndSelf, SB_VERT, &scrollInfo)) return 1;
7261 nOldScrollPos = scrollInfo.nPos;
7262 switch (nScrollCode)
7268 nScrollDiff = (is_an_icon) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE : -1;
7272 nScrollDiff = (is_an_icon) ? LISTVIEW_SCROLL_ICON_LINE_SIZE : 1;
7276 nScrollDiff = -scrollInfo.nPage;
7280 nScrollDiff = scrollInfo.nPage;
7283 case SB_THUMBPOSITION:
7285 nScrollDiff = scrollInfo.nTrackPos - scrollInfo.nPos;
7292 /* quit right away if pos isn't changing */
7293 if (nScrollDiff == 0) return 0;
7295 /* calculate new position, and handle overflows */
7296 nNewScrollPos = scrollInfo.nPos + nScrollDiff;
7297 if (nScrollDiff > 0) {
7298 if (nNewScrollPos < nOldScrollPos ||
7299 nNewScrollPos > scrollInfo.nMax)
7300 nNewScrollPos = scrollInfo.nMax;
7302 if (nNewScrollPos > nOldScrollPos ||
7303 nNewScrollPos < scrollInfo.nMin)
7304 nNewScrollPos = scrollInfo.nMin;
7307 /* set the new position, and reread in case it changed */
7308 scrollInfo.fMask = SIF_POS;
7309 scrollInfo.nPos = nNewScrollPos;
7310 nNewScrollPos = SetScrollInfo(infoPtr->hwndSelf, SB_VERT, &scrollInfo, TRUE);
7312 /* carry on only if it really changed */
7313 if (nNewScrollPos == nOldScrollPos) return 0;
7315 /* now adjust to client coordinates */
7316 nScrollDiff = nOldScrollPos - nNewScrollPos;
7317 if (uView == LVS_REPORT) nScrollDiff *= infoPtr->nItemHeight;
7319 /* and scroll the window */
7320 scroll_list(infoPtr, 0, nScrollDiff);
7327 * Performs horizontal scrolling.
7330 * [I] infoPtr : valid pointer to the listview structure
7331 * [I] nScrollCode : scroll code
7332 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
7333 * [I] hScrollWnd : scrollbar control window handle
7339 * SB_LINELEFT/SB_LINERIGHT:
7340 * for LVS_ICON, LVS_SMALLICON 1 pixel
7341 * for LVS_REPORT is 1 pixel
7342 * for LVS_LIST is 1 column --> which is a 1 because the
7343 * scroll is based on columns not pixels
7346 static LRESULT LISTVIEW_HScroll(LISTVIEW_INFO *infoPtr, INT nScrollCode,
7347 INT nScrollDiff, HWND hScrollWnd)
7349 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
7350 INT nOldScrollPos, nNewScrollPos;
7351 SCROLLINFO scrollInfo;
7353 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode,
7354 debugscrollcode(nScrollCode), nScrollDiff);
7356 if (infoPtr->hwndEdit) SendMessageW(infoPtr->hwndEdit, WM_KILLFOCUS, 0, 0);
7358 scrollInfo.cbSize = sizeof(SCROLLINFO);
7359 scrollInfo.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_TRACKPOS;
7361 if (!GetScrollInfo(infoPtr->hwndSelf, SB_HORZ, &scrollInfo)) return 1;
7363 nOldScrollPos = scrollInfo.nPos;
7365 switch (nScrollCode)
7379 nScrollDiff = -scrollInfo.nPage;
7383 nScrollDiff = scrollInfo.nPage;
7386 case SB_THUMBPOSITION:
7388 nScrollDiff = scrollInfo.nTrackPos - scrollInfo.nPos;
7395 /* quit right away if pos isn't changing */
7396 if (nScrollDiff == 0) return 0;
7398 /* calculate new position, and handle overflows */
7399 nNewScrollPos = scrollInfo.nPos + nScrollDiff;
7400 if (nScrollDiff > 0) {
7401 if (nNewScrollPos < nOldScrollPos ||
7402 nNewScrollPos > scrollInfo.nMax)
7403 nNewScrollPos = scrollInfo.nMax;
7405 if (nNewScrollPos > nOldScrollPos ||
7406 nNewScrollPos < scrollInfo.nMin)
7407 nNewScrollPos = scrollInfo.nMin;
7410 /* set the new position, and reread in case it changed */
7411 scrollInfo.fMask = SIF_POS;
7412 scrollInfo.nPos = nNewScrollPos;
7413 nNewScrollPos = SetScrollInfo(infoPtr->hwndSelf, SB_HORZ, &scrollInfo, TRUE);
7415 /* carry on only if it really changed */
7416 if (nNewScrollPos == nOldScrollPos) return 0;
7418 if(uView == LVS_REPORT)
7419 LISTVIEW_UpdateHeaderSize(infoPtr, nNewScrollPos);
7421 /* now adjust to client coordinates */
7422 nScrollDiff = nOldScrollPos - nNewScrollPos;
7423 if (uView == LVS_LIST) nScrollDiff *= infoPtr->nItemWidth;
7425 /* and scroll the window */
7426 scroll_list(infoPtr, nScrollDiff, 0);
7431 static LRESULT LISTVIEW_MouseWheel(LISTVIEW_INFO *infoPtr, INT wheelDelta)
7433 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
7434 INT gcWheelDelta = 0;
7435 UINT pulScrollLines = 3;
7436 SCROLLINFO scrollInfo;
7438 TRACE("(wheelDelta=%d)\n", wheelDelta);
7440 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES,0, &pulScrollLines, 0);
7441 gcWheelDelta -= wheelDelta;
7443 scrollInfo.cbSize = sizeof(SCROLLINFO);
7444 scrollInfo.fMask = SIF_POS;
7451 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
7452 * should be fixed in the future.
7454 LISTVIEW_VScroll(infoPtr, SB_INTERNAL, (gcWheelDelta < 0) ?
7455 -LISTVIEW_SCROLL_ICON_LINE_SIZE : LISTVIEW_SCROLL_ICON_LINE_SIZE, 0);
7459 if (abs(gcWheelDelta) >= WHEEL_DELTA && pulScrollLines)
7461 int cLineScroll = min(LISTVIEW_GetCountPerColumn(infoPtr), pulScrollLines);
7462 cLineScroll *= (gcWheelDelta / WHEEL_DELTA);
7463 LISTVIEW_VScroll(infoPtr, SB_INTERNAL, cLineScroll, 0);
7468 LISTVIEW_HScroll(infoPtr, (gcWheelDelta < 0) ? SB_LINELEFT : SB_LINERIGHT, 0, 0);
7479 * [I] infoPtr : valid pointer to the listview structure
7480 * [I] nVirtualKey : virtual key
7481 * [I] lKeyData : key data
7486 static LRESULT LISTVIEW_KeyDown(LISTVIEW_INFO *infoPtr, INT nVirtualKey, LONG lKeyData)
7488 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
7490 NMLVKEYDOWN nmKeyDown;
7492 TRACE("(nVirtualKey=%d, lKeyData=%ld)\n", nVirtualKey, lKeyData);
7494 /* send LVN_KEYDOWN notification */
7495 nmKeyDown.wVKey = nVirtualKey;
7496 nmKeyDown.flags = 0;
7497 notify_hdr(infoPtr, LVN_KEYDOWN, &nmKeyDown.hdr);
7499 switch (nVirtualKey)
7502 if ((infoPtr->nItemCount > 0) && (infoPtr->nFocusedItem != -1))
7504 notify(infoPtr, NM_RETURN);
7505 notify(infoPtr, LVN_ITEMACTIVATE);
7510 if (infoPtr->nItemCount > 0)
7515 if (infoPtr->nItemCount > 0)
7516 nItem = infoPtr->nItemCount - 1;
7520 nItem = ListView_GetNextItem(infoPtr->hwndSelf, infoPtr->nFocusedItem, LVNI_TOLEFT);
7524 nItem = ListView_GetNextItem(infoPtr->hwndSelf, infoPtr->nFocusedItem, LVNI_ABOVE);
7528 nItem = ListView_GetNextItem(infoPtr->hwndSelf, infoPtr->nFocusedItem, LVNI_TORIGHT);
7532 nItem = ListView_GetNextItem(infoPtr->hwndSelf, infoPtr->nFocusedItem, LVNI_BELOW);
7536 if (uView == LVS_REPORT)
7537 nItem = infoPtr->nFocusedItem - LISTVIEW_GetCountPerColumn(infoPtr);
7539 nItem = infoPtr->nFocusedItem - LISTVIEW_GetCountPerColumn(infoPtr)
7540 * LISTVIEW_GetCountPerRow(infoPtr);
7541 if(nItem < 0) nItem = 0;
7545 if (uView == LVS_REPORT)
7546 nItem = infoPtr->nFocusedItem + LISTVIEW_GetCountPerColumn(infoPtr);
7548 nItem = infoPtr->nFocusedItem + LISTVIEW_GetCountPerColumn(infoPtr)
7549 * LISTVIEW_GetCountPerRow(infoPtr);
7550 if(nItem >= infoPtr->nItemCount) nItem = infoPtr->nItemCount - 1;
7554 if ((nItem != -1) && (nItem != infoPtr->nFocusedItem))
7555 LISTVIEW_KeySelection(infoPtr, nItem);
7565 * [I] infoPtr : valid pointer to the listview structure
7570 static LRESULT LISTVIEW_KillFocus(LISTVIEW_INFO *infoPtr)
7574 /* if we did not have the focus, there's nothing to do */
7575 if (!infoPtr->bFocus) return 0;
7577 /* send NM_KILLFOCUS notification */
7578 notify(infoPtr, NM_KILLFOCUS);
7580 /* if we have a focus rectagle, get rid of it */
7581 LISTVIEW_ShowFocusRect(infoPtr, FALSE);
7583 /* set window focus flag */
7584 infoPtr->bFocus = FALSE;
7586 /* invalidate the selected items before reseting focus flag */
7587 LISTVIEW_InvalidateSelectedItems(infoPtr);
7594 * Processes double click messages (left mouse button).
7597 * [I] infoPtr : valid pointer to the listview structure
7598 * [I] wKey : key flag
7599 * [I] pts : mouse coordinate
7604 static LRESULT LISTVIEW_LButtonDblClk(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pts)
7606 LVHITTESTINFO htInfo;
7608 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey, pts.x, pts.y);
7610 /* send NM_RELEASEDCAPTURE notification */
7611 notify(infoPtr, NM_RELEASEDCAPTURE);
7613 htInfo.pt.x = pts.x;
7614 htInfo.pt.y = pts.y;
7616 /* send NM_DBLCLK notification */
7617 LISTVIEW_HitTest(infoPtr, &htInfo, TRUE, FALSE);
7618 notify_click(infoPtr, NM_DBLCLK, &htInfo);
7620 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
7621 if(htInfo.iItem != -1) notify(infoPtr, LVN_ITEMACTIVATE);
7628 * Processes mouse down messages (left mouse button).
7631 * [I] infoPtr : valid pointer to the listview structure
7632 * [I] wKey : key flag
7633 * [I] pts : mouse coordinate
7638 static LRESULT LISTVIEW_LButtonDown(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pts)
7640 LVHITTESTINFO lvHitTestInfo;
7641 static BOOL bGroupSelect = TRUE;
7642 POINT pt = { pts.x, pts.y };
7645 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey, pts.x, pts.y);
7647 /* send NM_RELEASEDCAPTURE notification */
7648 notify(infoPtr, NM_RELEASEDCAPTURE);
7650 if (!infoPtr->bFocus) SetFocus(infoPtr->hwndSelf);
7652 /* set left button down flag */
7653 infoPtr->bLButtonDown = TRUE;
7655 lvHitTestInfo.pt.x = pts.x;
7656 lvHitTestInfo.pt.y = pts.y;
7658 nItem = LISTVIEW_HitTest(infoPtr, &lvHitTestInfo, TRUE, TRUE);
7659 TRACE("at %s, nItem=%d\n", debugpoint(&pt), nItem);
7660 infoPtr->nEditLabelItem = -1;
7661 if ((nItem >= 0) && (nItem < infoPtr->nItemCount))
7663 if (infoPtr->dwStyle & LVS_SINGLESEL)
7665 if (LISTVIEW_GetItemState(infoPtr, nItem, LVIS_SELECTED))
7666 infoPtr->nEditLabelItem = nItem;
7668 LISTVIEW_SetSelection(infoPtr, nItem);
7672 if ((wKey & MK_CONTROL) && (wKey & MK_SHIFT))
7676 LISTVIEW_AddGroupSelection(infoPtr, nItem);
7677 LISTVIEW_SetItemFocus(infoPtr, nItem);
7678 infoPtr->nSelectionMark = nItem;
7684 item.state = LVIS_SELECTED | LVIS_FOCUSED;
7685 item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
7687 LISTVIEW_SetItemState(infoPtr,nItem,&item);
7688 infoPtr->nSelectionMark = nItem;
7691 else if (wKey & MK_CONTROL)
7695 bGroupSelect = (LISTVIEW_GetItemState(infoPtr, nItem, LVIS_SELECTED) == 0);
7697 item.state = (bGroupSelect ? LVIS_SELECTED : 0) | LVIS_FOCUSED;
7698 item.stateMask = LVIS_SELECTED | LVIS_FOCUSED;
7699 LISTVIEW_SetItemState(infoPtr, nItem, &item);
7700 infoPtr->nSelectionMark = nItem;
7702 else if (wKey & MK_SHIFT)
7704 LISTVIEW_SetGroupSelection(infoPtr, nItem);
7708 if (LISTVIEW_GetItemState(infoPtr, nItem, LVIS_SELECTED))
7709 infoPtr->nEditLabelItem = nItem;
7711 /* set selection (clears other pre-existing selections) */
7712 LISTVIEW_SetSelection(infoPtr, nItem);
7718 /* remove all selections */
7719 LISTVIEW_DeselectAll(infoPtr);
7727 * Processes mouse up messages (left mouse button).
7730 * [I] infoPtr : valid pointer to the listview structure
7731 * [I] wKey : key flag
7732 * [I] pts : mouse coordinate
7737 static LRESULT LISTVIEW_LButtonUp(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pts)
7739 LVHITTESTINFO lvHitTestInfo;
7741 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey, pts.x, pts.y);
7743 if (!infoPtr->bLButtonDown) return 0;
7745 lvHitTestInfo.pt.x = pts.x;
7746 lvHitTestInfo.pt.y = pts.y;
7748 /* send NM_CLICK notification */
7749 LISTVIEW_HitTest(infoPtr, &lvHitTestInfo, TRUE, FALSE);
7750 notify_click(infoPtr, NM_CLICK, &lvHitTestInfo);
7752 /* set left button flag */
7753 infoPtr->bLButtonDown = FALSE;
7755 /* if we clicked on a selected item, edit the label */
7756 if(lvHitTestInfo.iItem == infoPtr->nEditLabelItem && (lvHitTestInfo.flags & LVHT_ONITEMLABEL))
7757 LISTVIEW_EditLabelT(infoPtr, lvHitTestInfo.iItem, TRUE);
7764 * Destroys the listview control (called after WM_DESTROY).
7767 * [I] infoPtr : valid pointer to the listview structure
7772 static LRESULT LISTVIEW_NCDestroy(LISTVIEW_INFO *infoPtr)
7776 /* delete all items */
7777 LISTVIEW_DeleteAllItems(infoPtr);
7779 /* destroy data structure */
7780 DPA_Destroy(infoPtr->hdpaItems);
7781 DPA_Destroy(infoPtr->hdpaPosX);
7782 DPA_Destroy(infoPtr->hdpaPosY);
7783 DPA_Destroy(infoPtr->hdpaColumns);
7784 ranges_destroy(infoPtr->selectionRanges);
7786 /* destroy image lists */
7787 if (!(infoPtr->dwStyle & LVS_SHAREIMAGELISTS))
7789 if (infoPtr->himlNormal)
7790 ImageList_Destroy(infoPtr->himlNormal);
7791 if (infoPtr->himlSmall)
7792 ImageList_Destroy(infoPtr->himlSmall);
7793 if (infoPtr->himlState)
7794 ImageList_Destroy(infoPtr->himlState);
7797 /* destroy font, bkgnd brush */
7799 if (infoPtr->hDefaultFont) DeleteObject(infoPtr->hDefaultFont);
7800 if (infoPtr->clrBk != CLR_NONE) DeleteObject(infoPtr->hBkBrush);
7802 /* free listview info pointer*/
7803 COMCTL32_Free(infoPtr);
7805 SetWindowLongW(infoPtr->hwndSelf, 0, 0);
7811 * Handles notifications from header.
7814 * [I] infoPtr : valid pointer to the listview structure
7815 * [I] nCtrlId : control identifier
7816 * [I] lpnmh : notification information
7821 static LRESULT LISTVIEW_HeaderNotification(LISTVIEW_INFO *infoPtr, const NMHEADERW *lpnmh)
7823 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
7825 TRACE("(lpnmh=%p)\n", lpnmh);
7827 if (!lpnmh || lpnmh->iItem < 0 || lpnmh->iItem >= infoPtr->hdpaColumns->nItemCount) return 0;
7829 switch (lpnmh->hdr.code)
7833 case HDN_ITEMCHANGEDW:
7834 case HDN_ITEMCHANGEDA:
7836 COLUMN_INFO *lpColumnInfo;
7839 if (!lpnmh->pitem || !(lpnmh->pitem->mask & HDI_WIDTH))
7843 hdi.mask = HDI_WIDTH;
7844 if (!Header_GetItemW(infoPtr->hwndHeader, lpnmh->iItem, (LPARAM)&hdi)) return 0;
7848 cxy = lpnmh->pitem->cxy;
7850 /* determine how much we change since the last know position */
7851 lpColumnInfo = LISTVIEW_GetColumnInfo(infoPtr, lpnmh->iItem);
7852 dx = cxy - (lpColumnInfo->rcHeader.right - lpColumnInfo->rcHeader.left);
7855 RECT rcCol = lpColumnInfo->rcHeader;
7857 lpColumnInfo->rcHeader.right += dx;
7858 LISTVIEW_ScrollColumns(infoPtr, lpnmh->iItem + 1, dx);
7859 if (uView == LVS_REPORT && is_redrawing(infoPtr))
7861 /* this trick works for left aligned columns only */
7862 if ((lpColumnInfo->fmt & LVCFMT_JUSTIFYMASK) == LVCFMT_LEFT)
7864 rcCol.right = min (rcCol.right, lpColumnInfo->rcHeader.right);
7865 rcCol.left = max (rcCol.left, rcCol.right - 3 * infoPtr->ntmAveCharWidth);
7867 rcCol.top = infoPtr->rcList.top;
7868 rcCol.bottom = infoPtr->rcList.bottom;
7869 LISTVIEW_InvalidateRect(infoPtr, &rcCol);
7875 case HDN_ITEMCLICKW:
7876 case HDN_ITEMCLICKA:
7878 /* Handle sorting by Header Column */
7881 ZeroMemory(&nmlv, sizeof(NMLISTVIEW));
7883 nmlv.iSubItem = lpnmh->iItem;
7884 notify_listview(infoPtr, LVN_COLUMNCLICK, &nmlv);
7894 * Determines the type of structure to use.
7897 * [I] infoPtr : valid pointer to the listview structureof the sender
7898 * [I] hwndFrom : listview window handle
7899 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
7904 static LRESULT LISTVIEW_NotifyFormat(LISTVIEW_INFO *infoPtr, HWND hwndFrom, INT nCommand)
7906 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom, nCommand);
7908 if (nCommand != NF_REQUERY) return 0;
7910 infoPtr->notifyFormat = SendMessageW(hwndFrom, WM_NOTIFYFORMAT, (WPARAM)infoPtr->hwndSelf, NF_QUERY);
7917 * Paints/Repaints the listview control.
7920 * [I] infoPtr : valid pointer to the listview structure
7921 * [I] hdc : device context handle
7926 static LRESULT LISTVIEW_Paint(LISTVIEW_INFO *infoPtr, HDC hdc)
7928 TRACE("(hdc=%p)\n", hdc);
7930 infoPtr->bFirstPaint = FALSE;
7931 if (infoPtr->bNoItemMetrics && infoPtr->nItemCount)
7933 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
7935 infoPtr->bNoItemMetrics = FALSE;
7936 LISTVIEW_UpdateItemSize(infoPtr);
7937 if (uView == LVS_ICON || uView == LVS_SMALLICON)
7938 LISTVIEW_Arrange(infoPtr, LVA_DEFAULT);
7939 LISTVIEW_UpdateScroll(infoPtr);
7942 LISTVIEW_Refresh(infoPtr, hdc);
7947 hdc = BeginPaint(infoPtr->hwndSelf, &ps);
7949 if (ps.fErase) LISTVIEW_FillBkgnd(infoPtr, hdc, &ps.rcPaint);
7950 LISTVIEW_Refresh(infoPtr, hdc);
7951 EndPaint(infoPtr->hwndSelf, &ps);
7959 * Processes double click messages (right mouse button).
7962 * [I] infoPtr : valid pointer to the listview structure
7963 * [I] wKey : key flag
7964 * [I] pts : mouse coordinate
7969 static LRESULT LISTVIEW_RButtonDblClk(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pts)
7971 LVHITTESTINFO lvHitTestInfo;
7973 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey, pts.x, pts.y);
7975 /* send NM_RELEASEDCAPTURE notification */
7976 notify(infoPtr, NM_RELEASEDCAPTURE);
7978 /* send NM_RDBLCLK notification */
7979 lvHitTestInfo.pt.x = pts.x;
7980 lvHitTestInfo.pt.y = pts.y;
7981 LISTVIEW_HitTest(infoPtr, &lvHitTestInfo, TRUE, FALSE);
7982 notify_click(infoPtr, NM_RDBLCLK, &lvHitTestInfo);
7989 * Processes mouse down messages (right mouse button).
7992 * [I] infoPtr : valid pointer to the listview structure
7993 * [I] wKey : key flag
7994 * [I] pts : mouse coordinate
7999 static LRESULT LISTVIEW_RButtonDown(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pts)
8001 LVHITTESTINFO lvHitTestInfo;
8004 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey, pts.x, pts.y);
8006 /* send NM_RELEASEDCAPTURE notification */
8007 notify(infoPtr, NM_RELEASEDCAPTURE);
8009 /* make sure the listview control window has the focus */
8010 if (!infoPtr->bFocus) SetFocus(infoPtr->hwndSelf);
8012 /* set right button down flag */
8013 infoPtr->bRButtonDown = TRUE;
8015 /* determine the index of the selected item */
8016 lvHitTestInfo.pt.x = pts.x;
8017 lvHitTestInfo.pt.y = pts.y;
8018 nItem = LISTVIEW_HitTest(infoPtr, &lvHitTestInfo, TRUE, TRUE);
8020 if ((nItem >= 0) && (nItem < infoPtr->nItemCount))
8022 LISTVIEW_SetItemFocus(infoPtr, nItem);
8023 if (!((wKey & MK_SHIFT) || (wKey & MK_CONTROL)) &&
8024 !LISTVIEW_GetItemState(infoPtr, nItem, LVIS_SELECTED))
8025 LISTVIEW_SetSelection(infoPtr, nItem);
8029 LISTVIEW_DeselectAll(infoPtr);
8037 * Processes mouse up messages (right mouse button).
8040 * [I] infoPtr : valid pointer to the listview structure
8041 * [I] wKey : key flag
8042 * [I] pts : mouse coordinate
8047 static LRESULT LISTVIEW_RButtonUp(LISTVIEW_INFO *infoPtr, WORD wKey, POINTS pts)
8049 LVHITTESTINFO lvHitTestInfo;
8052 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey, pts.x, pts.y);
8054 if (!infoPtr->bRButtonDown) return 0;
8056 /* set button flag */
8057 infoPtr->bRButtonDown = FALSE;
8059 /* Send NM_RClICK notification */
8060 lvHitTestInfo.pt.x = pts.x;
8061 lvHitTestInfo.pt.y = pts.y;
8062 LISTVIEW_HitTest(infoPtr, &lvHitTestInfo, TRUE, FALSE);
8063 notify_click(infoPtr, NM_RCLICK, &lvHitTestInfo);
8065 /* Change to screen coordinate for WM_CONTEXTMENU */
8066 pt = lvHitTestInfo.pt;
8067 ClientToScreen(infoPtr->hwndSelf, &pt);
8069 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
8070 SendMessageW(infoPtr->hwndSelf, WM_CONTEXTMENU,
8071 (WPARAM)infoPtr->hwndSelf, MAKELPARAM(pt.x, pt.y));
8082 * [I] infoPtr : valid pointer to the listview structure
8083 * [I] hwnd : window handle of window containing the cursor
8084 * [I] nHittest : hit-test code
8085 * [I] wMouseMsg : ideintifier of the mouse message
8088 * TRUE if cursor is set
8091 static BOOL LISTVIEW_SetCursor(LISTVIEW_INFO *infoPtr, HWND hwnd, UINT nHittest, UINT wMouseMsg)
8093 LVHITTESTINFO lvHitTestInfo;
8095 if(!(infoPtr->dwLvExStyle & LVS_EX_TRACKSELECT)) return FALSE;
8097 if(!infoPtr->hHotCursor) return FALSE;
8099 GetCursorPos(&lvHitTestInfo.pt);
8100 if (LISTVIEW_HitTest(infoPtr, &lvHitTestInfo, FALSE, FALSE) < 0) return FALSE;
8102 SetCursor(infoPtr->hHotCursor);
8112 * [I] infoPtr : valid pointer to the listview structure
8113 * [I] hwndLoseFocus : handle of previously focused window
8118 static LRESULT LISTVIEW_SetFocus(LISTVIEW_INFO *infoPtr, HWND hwndLoseFocus)
8120 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus);
8122 /* if we have the focus already, there's nothing to do */
8123 if (infoPtr->bFocus) return 0;
8125 /* send NM_SETFOCUS notification */
8126 notify(infoPtr, NM_SETFOCUS);
8128 /* set window focus flag */
8129 infoPtr->bFocus = TRUE;
8131 /* put the focus rect back on */
8132 LISTVIEW_ShowFocusRect(infoPtr, TRUE);
8134 /* redraw all visible selected items */
8135 LISTVIEW_InvalidateSelectedItems(infoPtr);
8145 * [I] infoPtr : valid pointer to the listview structure
8146 * [I] fRedraw : font handle
8147 * [I] fRedraw : redraw flag
8152 static LRESULT LISTVIEW_SetFont(LISTVIEW_INFO *infoPtr, HFONT hFont, WORD fRedraw)
8154 HFONT oldFont = infoPtr->hFont;
8156 TRACE("(hfont=%p,redraw=%hu)\n", hFont, fRedraw);
8158 infoPtr->hFont = hFont ? hFont : infoPtr->hDefaultFont;
8159 if (infoPtr->hFont == oldFont) return 0;
8161 LISTVIEW_SaveTextMetrics(infoPtr);
8163 if ((infoPtr->dwStyle & LVS_TYPEMASK) == LVS_REPORT)
8164 SendMessageW(infoPtr->hwndHeader, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(fRedraw, 0));
8166 if (fRedraw) LISTVIEW_InvalidateList(infoPtr);
8173 * Message handling for WM_SETREDRAW.
8174 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
8177 * [I] infoPtr : valid pointer to the listview structure
8178 * [I] bRedraw: state of redraw flag
8181 * DefWinProc return value
8183 static LRESULT LISTVIEW_SetRedraw(LISTVIEW_INFO *infoPtr, BOOL bRedraw)
8185 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr->bRedraw, bRedraw);
8187 /* we can not use straight equality here because _any_ non-zero value is TRUE */
8188 if ((infoPtr->bRedraw && bRedraw) || (!infoPtr->bRedraw && !bRedraw)) return 0;
8190 infoPtr->bRedraw = bRedraw;
8192 if(!bRedraw) return 0;
8194 if (is_autoarrange(infoPtr))
8195 LISTVIEW_Arrange(infoPtr, LVA_DEFAULT);
8196 LISTVIEW_UpdateScroll(infoPtr);
8198 /* despite what the WM_SETREDRAW docs says, apps expect us
8199 * to invalidate the listview here... stupid! */
8200 LISTVIEW_InvalidateList(infoPtr);
8207 * Resizes the listview control. This function processes WM_SIZE
8208 * messages. At this time, the width and height are not used.
8211 * [I] infoPtr : valid pointer to the listview structure
8212 * [I] Width : new width
8213 * [I] Height : new height
8218 static LRESULT LISTVIEW_Size(LISTVIEW_INFO *infoPtr, int Width, int Height)
8220 RECT rcOld = infoPtr->rcList;
8222 TRACE("(width=%d, height=%d)\n", Width, Height);
8224 LISTVIEW_UpdateSize(infoPtr);
8225 if (EqualRect(&rcOld, &infoPtr->rcList)) return 0;
8227 /* do not bother with display related stuff if we're not redrawing */
8228 if (!is_redrawing(infoPtr)) return 0;
8230 if (is_autoarrange(infoPtr))
8231 LISTVIEW_Arrange(infoPtr, LVA_DEFAULT);
8233 LISTVIEW_UpdateScroll(infoPtr);
8235 /* refresh all only for lists whose height changed significantly */
8236 if ((infoPtr->dwStyle & LVS_TYPEMASK) == LVS_LIST &&
8237 (rcOld.bottom - rcOld.top) / infoPtr->nItemHeight !=
8238 (infoPtr->rcList.bottom - infoPtr->rcList.top) / infoPtr->nItemHeight)
8239 LISTVIEW_InvalidateList(infoPtr);
8246 * Sets the size information.
8249 * [I] infoPtr : valid pointer to the listview structure
8254 static void LISTVIEW_UpdateSize(LISTVIEW_INFO *infoPtr)
8256 UINT uView = infoPtr->dwStyle & LVS_TYPEMASK;
8258 TRACE("uView=%d, rcList(old)=%s\n", uView, debugrect(&infoPtr->rcList));
8260 GetClientRect(infoPtr->hwndSelf, &infoPtr->rcList);
8262 if (uView == LVS_LIST)
8264 /* Apparently the "LIST" style is supposed to have the same
8265 * number of items in a column even if there is no scroll bar.
8266 * Since if a scroll bar already exists then the bottom is already
8267 * reduced, only reduce if the scroll bar does not currently exist.
8268 * The "2" is there to mimic the native control. I think it may be
8269 * related to either padding or edges. (GLA 7/2002)
8271 if (!(infoPtr->dwStyle & WS_HSCROLL))
8272 infoPtr->rcList.bottom -= GetSystemMetrics(SM_CYHSCROLL);
8273 infoPtr->rcList.bottom = max (infoPtr->rcList.bottom - 2, 0);
8275 else if (uView == LVS_REPORT && !(infoPtr->dwStyle & LVS_NOCOLUMNHEADER))
8280 hl.prc = &infoPtr->rcList;
8282 Header_Layout(infoPtr->hwndHeader, &hl);
8284 SetWindowPos(wp.hwnd, wp.hwndInsertAfter, wp.x, wp.y, wp.cx, wp.cy, wp.flags);
8286 infoPtr->rcList.top = max(wp.cy, 0);
8289 TRACE(" rcList=%s\n", debugrect(&infoPtr->rcList));
8294 * Processes WM_STYLECHANGED messages.
8297 * [I] infoPtr : valid pointer to the listview structure
8298 * [I] wStyleType : window style type (normal or extended)
8299 * [I] lpss : window style information
8304 static INT LISTVIEW_StyleChanged(LISTVIEW_INFO *infoPtr, WPARAM wStyleType,
8305 const STYLESTRUCT *lpss)
8307 UINT uNewView = lpss->styleNew & LVS_TYPEMASK;
8308 UINT uOldView = lpss->styleOld & LVS_TYPEMASK;
8310 TRACE("(styletype=%x, styleOld=0x%08lx, styleNew=0x%08lx)\n",
8311 wStyleType, lpss->styleOld, lpss->styleNew);
8313 if (wStyleType != GWL_STYLE) return 0;
8315 /* FIXME: if LVS_NOSORTHEADER changed, update header */
8316 /* what if LVS_OWNERDATA changed? */
8317 /* or LVS_SINGLESEL */
8318 /* or LVS_SORT{AS,DES}CENDING */
8320 infoPtr->dwStyle = lpss->styleNew;
8322 if (((lpss->styleOld & WS_HSCROLL) != 0)&&
8323 ((lpss->styleNew & WS_HSCROLL) == 0))
8324 ShowScrollBar(infoPtr->hwndSelf, SB_HORZ, FALSE);
8326 if (((lpss->styleOld & WS_VSCROLL) != 0)&&
8327 ((lpss->styleNew & WS_VSCROLL) == 0))
8328 ShowScrollBar(infoPtr->hwndSelf, SB_VERT, FALSE);
8330 if (uNewView != uOldView)
8332 SIZE oldIconSize = infoPtr->iconSize;
8335 SendMessageW(infoPtr->hwndEdit, WM_KILLFOCUS, 0, 0);
8336 ShowWindow(infoPtr->hwndHeader, SW_HIDE);
8338 ShowScrollBar(infoPtr->hwndSelf, SB_BOTH, FALSE);
8339 SetRectEmpty(&infoPtr->rcFocus);
8341 himl = (uNewView == LVS_ICON ? infoPtr->himlNormal : infoPtr->himlSmall);
8342 set_icon_size(&infoPtr->iconSize, himl, uNewView != LVS_ICON);
8344 if (uNewView == LVS_ICON)
8346 if ((infoPtr->iconSize.cx != oldIconSize.cx) || (infoPtr->iconSize.cy != oldIconSize.cy))
8348 TRACE("icon old size=(%ld,%ld), new size=(%ld,%ld)\n",
8349 oldIconSize.cx, oldIconSize.cy, infoPtr->iconSize.cx, infoPtr->iconSize.cy);
8350 LISTVIEW_SetIconSpacing(infoPtr, 0, 0);
8353 else if (uNewView == LVS_REPORT)
8358 hl.prc = &infoPtr->rcList;
8360 Header_Layout(infoPtr->hwndHeader, &hl);
8361 SetWindowPos(infoPtr->hwndHeader, infoPtr->hwndSelf, wp.x, wp.y, wp.cx, wp.cy, wp.flags);
8364 LISTVIEW_UpdateItemSize(infoPtr);
8367 if (uNewView == LVS_REPORT)
8368 ShowWindow(infoPtr->hwndHeader, (lpss->styleNew & LVS_NOCOLUMNHEADER) ? SW_HIDE : SW_SHOWNORMAL);
8370 if ( (uNewView == LVS_ICON || uNewView == LVS_SMALLICON) &&
8371 (uNewView != uOldView || ((lpss->styleNew ^ lpss->styleOld) & LVS_ALIGNMASK)) )
8372 LISTVIEW_Arrange(infoPtr, LVA_DEFAULT);
8374 /* update the size of the client area */
8375 LISTVIEW_UpdateSize(infoPtr);
8377 /* add scrollbars if needed */
8378 LISTVIEW_UpdateScroll(infoPtr);
8380 /* invalidate client area + erase background */
8381 LISTVIEW_InvalidateList(infoPtr);
8388 * Window procedure of the listview control.
8391 static LRESULT WINAPI
8392 LISTVIEW_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
8394 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(hwnd, 0);
8396 TRACE("(uMsg=%x wParam=%x lParam=%lx)\n", uMsg, wParam, lParam);
8398 if (!infoPtr && (uMsg != WM_CREATE))
8399 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
8403 infoPtr->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
8408 case LVM_APPROXIMATEVIEWRECT:
8409 return LISTVIEW_ApproximateViewRect(infoPtr, (INT)wParam,
8410 LOWORD(lParam), HIWORD(lParam));
8412 return LISTVIEW_Arrange(infoPtr, (INT)wParam);
8414 /* case LVM_CANCELEDITLABEL: */
8416 /* case LVM_CREATEDRAGIMAGE: */
8418 case LVM_DELETEALLITEMS:
8419 return LISTVIEW_DeleteAllItems(infoPtr);
8421 case LVM_DELETECOLUMN:
8422 return LISTVIEW_DeleteColumn(infoPtr, (INT)wParam);
8424 case LVM_DELETEITEM:
8425 return LISTVIEW_DeleteItem(infoPtr, (INT)wParam);
8427 case LVM_EDITLABELW:
8428 return (LRESULT)LISTVIEW_EditLabelT(infoPtr, (INT)wParam, TRUE);
8430 case LVM_EDITLABELA:
8431 return (LRESULT)LISTVIEW_EditLabelT(infoPtr, (INT)wParam, FALSE);
8433 /* case LVM_ENABLEGROUPVIEW: */
8435 case LVM_ENSUREVISIBLE:
8436 return LISTVIEW_EnsureVisible(infoPtr, (INT)wParam, (BOOL)lParam);
8439 return LISTVIEW_FindItemW(infoPtr, (INT)wParam, (LPLVFINDINFOW)lParam);
8442 return LISTVIEW_FindItemA(infoPtr, (INT)wParam, (LPLVFINDINFOA)lParam);
8444 case LVM_GETBKCOLOR:
8445 return infoPtr->clrBk;
8447 /* case LVM_GETBKIMAGE: */
8449 case LVM_GETCALLBACKMASK:
8450 return infoPtr->uCallbackMask;
8452 case LVM_GETCOLUMNA:
8453 return LISTVIEW_GetColumnT(infoPtr, (INT)wParam, (LPLVCOLUMNW)lParam, FALSE);
8455 case LVM_GETCOLUMNW:
8456 return LISTVIEW_GetColumnT(infoPtr, (INT)wParam, (LPLVCOLUMNW)lParam, TRUE);
8458 case LVM_GETCOLUMNORDERARRAY:
8459 return LISTVIEW_GetColumnOrderArray(infoPtr, (INT)wParam, (LPINT)lParam);
8461 case LVM_GETCOLUMNWIDTH:
8462 return LISTVIEW_GetColumnWidth(infoPtr, (INT)wParam);
8464 case LVM_GETCOUNTPERPAGE:
8465 return LISTVIEW_GetCountPerPage(infoPtr);
8467 case LVM_GETEDITCONTROL:
8468 return (LRESULT)infoPtr->hwndEdit;
8470 case LVM_GETEXTENDEDLISTVIEWSTYLE:
8471 return infoPtr->dwLvExStyle;
8473 /* case LVM_GETGROUPINFO: */
8475 /* case LVM_GETGROUPMETRICS: */
8478 return (LRESULT)infoPtr->hwndHeader;
8480 case LVM_GETHOTCURSOR:
8481 return (LRESULT)infoPtr->hHotCursor;
8483 case LVM_GETHOTITEM:
8484 return infoPtr->nHotItem;
8486 case LVM_GETHOVERTIME:
8487 return infoPtr->dwHoverTime;
8489 case LVM_GETIMAGELIST:
8490 return (LRESULT)LISTVIEW_GetImageList(infoPtr, (INT)wParam);
8492 /* case LVM_GETINSERTMARK: */
8494 /* case LVM_GETINSERTMARKCOLOR: */
8496 /* case LVM_GETINSERTMARKRECT: */
8498 case LVM_GETISEARCHSTRINGA:
8499 case LVM_GETISEARCHSTRINGW:
8500 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
8504 return LISTVIEW_GetItemExtT(infoPtr, (LPLVITEMW)lParam, FALSE);
8507 return LISTVIEW_GetItemExtT(infoPtr, (LPLVITEMW)lParam, TRUE);
8509 case LVM_GETITEMCOUNT:
8510 return infoPtr->nItemCount;
8512 case LVM_GETITEMPOSITION:
8513 return LISTVIEW_GetItemPosition(infoPtr, (INT)wParam, (LPPOINT)lParam);
8515 case LVM_GETITEMRECT:
8516 return LISTVIEW_GetItemRect(infoPtr, (INT)wParam, (LPRECT)lParam);
8518 case LVM_GETITEMSPACING:
8519 return LISTVIEW_GetItemSpacing(infoPtr, (BOOL)wParam);
8521 case LVM_GETITEMSTATE:
8522 return LISTVIEW_GetItemState(infoPtr, (INT)wParam, (UINT)lParam);
8524 case LVM_GETITEMTEXTA:
8525 return LISTVIEW_GetItemTextT(infoPtr, (INT)wParam, (LPLVITEMW)lParam, FALSE);
8527 case LVM_GETITEMTEXTW:
8528 return LISTVIEW_GetItemTextT(infoPtr, (INT)wParam, (LPLVITEMW)lParam, TRUE);
8530 case LVM_GETNEXTITEM:
8531 return LISTVIEW_GetNextItem(infoPtr, (INT)wParam, LOWORD(lParam));
8533 case LVM_GETNUMBEROFWORKAREAS:
8534 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
8538 if (!lParam) return FALSE;
8539 LISTVIEW_GetOrigin(infoPtr, (LPPOINT)lParam);
8542 /* case LVM_GETOUTLINECOLOR: */
8544 /* case LVM_GETSELECTEDCOLUMN: */
8546 case LVM_GETSELECTEDCOUNT:
8547 return LISTVIEW_GetSelectedCount(infoPtr);
8549 case LVM_GETSELECTIONMARK:
8550 return infoPtr->nSelectionMark;
8552 case LVM_GETSTRINGWIDTHA:
8553 return LISTVIEW_GetStringWidthT(infoPtr, (LPCWSTR)lParam, FALSE);
8555 case LVM_GETSTRINGWIDTHW:
8556 return LISTVIEW_GetStringWidthT(infoPtr, (LPCWSTR)lParam, TRUE);
8558 case LVM_GETSUBITEMRECT:
8559 return LISTVIEW_GetSubItemRect(infoPtr, (UINT)wParam, (LPRECT)lParam);
8561 case LVM_GETTEXTBKCOLOR:
8562 return infoPtr->clrTextBk;
8564 case LVM_GETTEXTCOLOR:
8565 return infoPtr->clrText;
8567 /* case LVM_GETTILEINFO: */
8569 /* case LVM_GETTILEVIEWINFO: */
8571 case LVM_GETTOOLTIPS:
8572 FIXME("LVM_GETTOOLTIPS: unimplemented\n");
8575 case LVM_GETTOPINDEX:
8576 return LISTVIEW_GetTopIndex(infoPtr);
8578 /*case LVM_GETUNICODEFORMAT:
8579 FIXME("LVM_GETUNICODEFORMAT: unimplemented\n");
8582 /* case LVM_GETVIEW: */
8584 case LVM_GETVIEWRECT:
8585 return LISTVIEW_GetViewRect(infoPtr, (LPRECT)lParam);
8587 case LVM_GETWORKAREAS:
8588 FIXME("LVM_GETWORKAREAS: unimplemented\n");
8591 /* case LVM_HASGROUP: */
8594 return LISTVIEW_HitTest(infoPtr, (LPLVHITTESTINFO)lParam, FALSE, FALSE);
8596 case LVM_INSERTCOLUMNA:
8597 return LISTVIEW_InsertColumnT(infoPtr, (INT)wParam, (LPLVCOLUMNW)lParam, FALSE);
8599 case LVM_INSERTCOLUMNW:
8600 return LISTVIEW_InsertColumnT(infoPtr, (INT)wParam, (LPLVCOLUMNW)lParam, TRUE);
8602 /* case LVM_INSERTGROUP: */
8604 /* case LVM_INSERTGROUPSORTED: */
8606 case LVM_INSERTITEMA:
8607 return LISTVIEW_InsertItemT(infoPtr, (LPLVITEMW)lParam, FALSE);
8609 case LVM_INSERTITEMW:
8610 return LISTVIEW_InsertItemT(infoPtr, (LPLVITEMW)lParam, TRUE);
8612 /* case LVM_INSERTMARKHITTEST: */
8614 /* case LVM_ISGROUPVIEWENABLED: */
8616 /* case LVM_MAPIDTOINDEX: */
8618 /* case LVM_MAPINDEXTOID: */
8620 /* case LVM_MOVEGROUP: */
8622 /* case LVM_MOVEITEMTOGROUP: */
8624 case LVM_REDRAWITEMS:
8625 return LISTVIEW_RedrawItems(infoPtr, (INT)wParam, (INT)lParam);
8627 /* case LVM_REMOVEALLGROUPS: */
8629 /* case LVM_REMOVEGROUP: */
8632 return LISTVIEW_Scroll(infoPtr, (INT)wParam, (INT)lParam);
8634 case LVM_SETBKCOLOR:
8635 return LISTVIEW_SetBkColor(infoPtr, (COLORREF)lParam);
8637 /* case LVM_SETBKIMAGE: */
8639 case LVM_SETCALLBACKMASK:
8640 infoPtr->uCallbackMask = (UINT)wParam;
8643 case LVM_SETCOLUMNA:
8644 return LISTVIEW_SetColumnT(infoPtr, (INT)wParam, (LPLVCOLUMNW)lParam, FALSE);
8646 case LVM_SETCOLUMNW:
8647 return LISTVIEW_SetColumnT(infoPtr, (INT)wParam, (LPLVCOLUMNW)lParam, TRUE);
8649 case LVM_SETCOLUMNORDERARRAY:
8650 return LISTVIEW_SetColumnOrderArray(infoPtr, (INT)wParam, (LPINT)lParam);
8652 case LVM_SETCOLUMNWIDTH:
8653 return LISTVIEW_SetColumnWidth(infoPtr, (INT)wParam, SLOWORD(lParam));
8655 case LVM_SETEXTENDEDLISTVIEWSTYLE:
8656 return LISTVIEW_SetExtendedListViewStyle(infoPtr, (DWORD)wParam, (DWORD)lParam);
8658 /* case LVM_SETGROUPINFO: */
8660 /* case LVM_SETGROUPMETRICS: */
8662 case LVM_SETHOTCURSOR:
8663 return (LRESULT)LISTVIEW_SetHotCursor(infoPtr, (HCURSOR)lParam);
8665 case LVM_SETHOTITEM:
8666 return LISTVIEW_SetHotItem(infoPtr, (INT)wParam);
8668 case LVM_SETHOVERTIME:
8669 return LISTVIEW_SetHoverTime(infoPtr, (DWORD)wParam);
8671 case LVM_SETICONSPACING:
8672 return LISTVIEW_SetIconSpacing(infoPtr, SLOWORD(lParam), SHIWORD(lParam));
8674 case LVM_SETIMAGELIST:
8675 return (LRESULT)LISTVIEW_SetImageList(infoPtr, (INT)wParam, (HIMAGELIST)lParam);
8677 /* case LVM_SETINFOTIP: */
8679 /* case LVM_SETINSERTMARK: */
8681 /* case LVM_SETINSERTMARKCOLOR: */
8684 return LISTVIEW_SetItemT(infoPtr, (LPLVITEMW)lParam, FALSE);
8687 return LISTVIEW_SetItemT(infoPtr, (LPLVITEMW)lParam, TRUE);
8689 case LVM_SETITEMCOUNT:
8690 return LISTVIEW_SetItemCount(infoPtr, (INT)wParam, (DWORD)lParam);
8692 case LVM_SETITEMPOSITION:
8694 POINT pt = { SLOWORD(lParam), SHIWORD(lParam) };
8695 return LISTVIEW_SetItemPosition(infoPtr, (INT)wParam, pt);
8698 case LVM_SETITEMPOSITION32:
8699 if (lParam == 0) return FALSE;
8700 return LISTVIEW_SetItemPosition(infoPtr, (INT)wParam, *((POINT*)lParam));
8702 case LVM_SETITEMSTATE:
8703 return LISTVIEW_SetItemState(infoPtr, (INT)wParam, (LPLVITEMW)lParam);
8705 case LVM_SETITEMTEXTA:
8706 return LISTVIEW_SetItemTextT(infoPtr, (INT)wParam, (LPLVITEMW)lParam, FALSE);
8708 case LVM_SETITEMTEXTW:
8709 return LISTVIEW_SetItemTextT(infoPtr, (INT)wParam, (LPLVITEMW)lParam, TRUE);
8711 /* case LVM_SETOUTLINECOLOR: */
8713 /* case LVM_SETSELECTEDCOLUMN: */
8715 case LVM_SETSELECTIONMARK:
8716 return LISTVIEW_SetSelectionMark(infoPtr, (INT)lParam);
8718 case LVM_SETTEXTBKCOLOR:
8719 return LISTVIEW_SetTextBkColor(infoPtr, (COLORREF)lParam);
8721 case LVM_SETTEXTCOLOR:
8722 return LISTVIEW_SetTextColor(infoPtr, (COLORREF)lParam);
8724 /* case LVM_SETTILEINFO: */
8726 /* case LVM_SETTILEVIEWINFO: */
8728 /* case LVM_SETTILEWIDTH: */
8730 /* case LVM_SETTOOLTIPS: */
8732 /* case LVM_SETUNICODEFORMAT: */
8734 /* case LVM_SETVIEW: */
8736 /* case LVM_SETWORKAREAS: */
8738 /* case LVM_SORTGROUPS: */
8741 return LISTVIEW_SortItems(infoPtr, (PFNLVCOMPARE)lParam, (LPARAM)wParam);
8743 /* LVM_SORTITEMSEX: */
8745 case LVM_SUBITEMHITTEST:
8746 return LISTVIEW_HitTest(infoPtr, (LPLVHITTESTINFO)lParam, TRUE, FALSE);
8749 return LISTVIEW_Update(infoPtr, (INT)wParam);
8752 return LISTVIEW_ProcessLetterKeys( infoPtr, wParam, lParam );
8755 return LISTVIEW_Command(infoPtr, wParam, lParam);
8758 return LISTVIEW_Create(hwnd, (LPCREATESTRUCTW)lParam);
8761 return LISTVIEW_EraseBkgnd(infoPtr, (HDC)wParam);
8764 return DLGC_WANTCHARS | DLGC_WANTARROWS;
8767 return (LRESULT)infoPtr->hFont;
8770 return LISTVIEW_HScroll(infoPtr, (INT)LOWORD(wParam), 0, (HWND)lParam);
8773 return LISTVIEW_KeyDown(infoPtr, (INT)wParam, (LONG)lParam);
8776 return LISTVIEW_KillFocus(infoPtr);
8778 case WM_LBUTTONDBLCLK:
8779 return LISTVIEW_LButtonDblClk(infoPtr, (WORD)wParam, MAKEPOINTS(lParam));
8781 case WM_LBUTTONDOWN:
8782 return LISTVIEW_LButtonDown(infoPtr, (WORD)wParam, MAKEPOINTS(lParam));
8785 return LISTVIEW_LButtonUp(infoPtr, (WORD)wParam, MAKEPOINTS(lParam));
8788 return LISTVIEW_MouseMove (infoPtr, (WORD)wParam, MAKEPOINTS(lParam));
8791 return LISTVIEW_MouseHover(infoPtr, (WORD)wParam, MAKEPOINTS(lParam));
8794 return LISTVIEW_NCDestroy(infoPtr);
8797 if (lParam && ((LPNMHDR)lParam)->hwndFrom == infoPtr->hwndHeader)
8798 return LISTVIEW_HeaderNotification(infoPtr, (LPNMHEADERW)lParam);
8801 case WM_NOTIFYFORMAT:
8802 return LISTVIEW_NotifyFormat(infoPtr, (HWND)wParam, (INT)lParam);
8805 return LISTVIEW_Paint(infoPtr, (HDC)wParam);
8807 case WM_RBUTTONDBLCLK:
8808 return LISTVIEW_RButtonDblClk(infoPtr, (WORD)wParam, MAKEPOINTS(lParam));
8810 case WM_RBUTTONDOWN:
8811 return LISTVIEW_RButtonDown(infoPtr, (WORD)wParam, MAKEPOINTS(lParam));
8814 return LISTVIEW_RButtonUp(infoPtr, (WORD)wParam, MAKEPOINTS(lParam));
8817 if(LISTVIEW_SetCursor(infoPtr, (HWND)wParam, LOWORD(lParam), HIWORD(lParam)))
8822 return LISTVIEW_SetFocus(infoPtr, (HWND)wParam);
8825 return LISTVIEW_SetFont(infoPtr, (HFONT)wParam, (WORD)lParam);
8828 return LISTVIEW_SetRedraw(infoPtr, (BOOL)wParam);
8831 return LISTVIEW_Size(infoPtr, (int)SLOWORD(lParam), (int)SHIWORD(lParam));
8833 case WM_STYLECHANGED:
8834 return LISTVIEW_StyleChanged(infoPtr, wParam, (LPSTYLESTRUCT)lParam);
8836 case WM_SYSCOLORCHANGE:
8837 COMCTL32_RefreshSysColors();
8840 /* case WM_TIMER: */
8843 return LISTVIEW_VScroll(infoPtr, (INT)LOWORD(wParam), 0, (HWND)lParam);
8846 if (wParam & (MK_SHIFT | MK_CONTROL))
8847 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
8848 return LISTVIEW_MouseWheel(infoPtr, (short int)HIWORD(wParam));
8850 case WM_WINDOWPOSCHANGED:
8851 if (!(((WINDOWPOS *)lParam)->flags & SWP_NOSIZE))
8853 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOACTIVATE |
8854 SWP_NOZORDER | SWP_NOMOVE | SWP_NOSIZE);
8855 LISTVIEW_UpdateSize(infoPtr);
8856 LISTVIEW_UpdateScroll(infoPtr);
8858 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
8860 /* case WM_WININICHANGE: */
8863 if ((uMsg >= WM_USER) && (uMsg < WM_APP))
8864 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg, wParam, lParam);
8867 /* call default window procedure */
8868 return DefWindowProcW(hwnd, uMsg, wParam, lParam);
8876 * Registers the window class.
8884 void LISTVIEW_Register(void)
8888 ZeroMemory(&wndClass, sizeof(WNDCLASSW));
8889 wndClass.style = CS_GLOBALCLASS | CS_DBLCLKS;
8890 wndClass.lpfnWndProc = (WNDPROC)LISTVIEW_WindowProc;
8891 wndClass.cbClsExtra = 0;
8892 wndClass.cbWndExtra = sizeof(LISTVIEW_INFO *);
8893 wndClass.hCursor = LoadCursorW(0, IDC_ARROWW);
8894 wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
8895 wndClass.lpszClassName = WC_LISTVIEWW;
8896 RegisterClassW(&wndClass);
8901 * Unregisters the window class.
8909 void LISTVIEW_Unregister(void)
8911 UnregisterClassW(WC_LISTVIEWW, NULL);
8916 * Handle any WM_COMMAND messages
8919 * [I] infoPtr : valid pointer to the listview structure
8920 * [I] wParam : the first message parameter
8921 * [I] lParam : the second message parameter
8926 static LRESULT LISTVIEW_Command(LISTVIEW_INFO *infoPtr, WPARAM wParam, LPARAM lParam)
8928 switch (HIWORD(wParam))
8933 * Adjust the edit window size
8936 HDC hdc = GetDC(infoPtr->hwndEdit);
8937 HFONT hFont, hOldFont = 0;
8942 if (!infoPtr->hwndEdit || !hdc) return 0;
8943 len = GetWindowTextW(infoPtr->hwndEdit, buffer, sizeof(buffer)/sizeof(buffer[0]));
8944 GetWindowRect(infoPtr->hwndEdit, &rect);
8946 /* Select font to get the right dimension of the string */
8947 hFont = (HFONT)SendMessageW(infoPtr->hwndEdit, WM_GETFONT, 0, 0);
8950 hOldFont = SelectObject(hdc, hFont);
8953 if (GetTextExtentPoint32W(hdc, buffer, lstrlenW(buffer), &sz))
8955 TEXTMETRICW textMetric;
8957 /* Add Extra spacing for the next character */
8958 GetTextMetricsW(hdc, &textMetric);
8959 sz.cx += (textMetric.tmMaxCharWidth * 2);
8967 rect.bottom - rect.top,
8968 SWP_DRAWFRAME|SWP_NOMOVE);
8971 SelectObject(hdc, hOldFont);
8973 ReleaseDC(infoPtr->hwndSelf, hdc);
8979 return SendMessageW (GetParent (infoPtr->hwndSelf), WM_COMMAND, wParam, lParam);
8988 * Subclassed edit control windproc function
8991 * [I] hwnd : the edit window handle
8992 * [I] uMsg : the message that is to be processed
8993 * [I] wParam : first message parameter
8994 * [I] lParam : second message parameter
8995 * [I] isW : TRUE if input is Unicode
9000 static LRESULT EditLblWndProcT(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL isW)
9002 LISTVIEW_INFO *infoPtr = (LISTVIEW_INFO *)GetWindowLongW(GetParent(hwnd), 0);
9003 BOOL cancel = FALSE;
9005 TRACE("(hwnd=%p, uMsg=%x, wParam=%x, lParam=%lx, isW=%d)\n",
9006 hwnd, uMsg, wParam, lParam, isW);
9011 return DLGC_WANTARROWS | DLGC_WANTALLKEYS;
9018 WNDPROC editProc = infoPtr->EditWndProc;
9019 infoPtr->EditWndProc = 0;
9020 SetWindowLongW(hwnd, GWL_WNDPROC, (LONG)editProc);
9021 return CallWindowProcT(editProc, hwnd, uMsg, wParam, lParam, isW);
9025 if (VK_ESCAPE == (INT)wParam)
9030 else if (VK_RETURN == (INT)wParam)
9034 return CallWindowProcT(infoPtr->EditWndProc, hwnd, uMsg, wParam, lParam, isW);
9038 if (infoPtr->hwndEdit)
9040 LPWSTR buffer = NULL;
9042 infoPtr->hwndEdit = 0;
9045 DWORD len = isW ? GetWindowTextLengthW(hwnd) : GetWindowTextLengthA(hwnd);
9049 if ( (buffer = COMCTL32_Alloc((len+1) * (isW ? sizeof(WCHAR) : sizeof(CHAR)))) )
9051 if (isW) GetWindowTextW(hwnd, buffer, len+1);
9052 else GetWindowTextA(hwnd, (CHAR*)buffer, len+1);
9056 LISTVIEW_EndEditLabelT(infoPtr, buffer, isW);
9058 if (buffer) COMCTL32_Free(buffer);
9062 SendMessageW(hwnd, WM_CLOSE, 0, 0);
9068 * Subclassed edit control Unicode windproc function
9071 * [I] hwnd : the edit window handle
9072 * [I] uMsg : the message that is to be processed
9073 * [I] wParam : first message parameter
9074 * [I] lParam : second message parameter
9078 LRESULT CALLBACK EditLblWndProcW(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
9080 return EditLblWndProcT(hwnd, uMsg, wParam, lParam, TRUE);
9085 * Subclassed edit control ANSI windproc function
9088 * [I] hwnd : the edit window handle
9089 * [I] uMsg : the message that is to be processed
9090 * [I] wParam : first message parameter
9091 * [I] lParam : second message parameter
9095 LRESULT CALLBACK EditLblWndProcA(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
9097 return EditLblWndProcT(hwnd, uMsg, wParam, lParam, FALSE);
9102 * Creates a subclassed edit cotrol
9105 * [I] infoPtr : valid pointer to the listview structure
9106 * [I] text : initial text for the edit
9107 * [I] style : the window style
9108 * [I] isW : TRUE if input is Unicode
9112 static HWND CreateEditLabelT(LISTVIEW_INFO *infoPtr, LPCWSTR text, DWORD style,
9113 INT x, INT y, INT width, INT height, BOOL isW)
9115 WCHAR editName[5] = { 'E', 'd', 'i', 't', '\0' };
9120 TEXTMETRICW textMetric;
9121 HINSTANCE hinst = (HINSTANCE)GetWindowLongW(infoPtr->hwndSelf, GWL_HINSTANCE);
9123 TRACE("(text=%s, ..., isW=%d)\n", debugtext_t(text, isW), isW);
9125 style |= WS_CHILDWINDOW|WS_CLIPSIBLINGS|ES_LEFT|WS_BORDER;
9126 hdc = GetDC(infoPtr->hwndSelf);
9128 /* Select the font to get appropriate metric dimensions */
9129 if(infoPtr->hFont != 0)
9130 hOldFont = SelectObject(hdc, infoPtr->hFont);
9132 /*Get String Lenght in pixels */
9133 GetTextExtentPoint32W(hdc, text, lstrlenW(text), &sz);
9135 /*Add Extra spacing for the next character */
9136 GetTextMetricsW(hdc, &textMetric);
9137 sz.cx += (textMetric.tmMaxCharWidth * 2);
9139 if(infoPtr->hFont != 0)
9140 SelectObject(hdc, hOldFont);
9142 ReleaseDC(infoPtr->hwndSelf, hdc);
9144 hedit = CreateWindowW(editName, text, style, x, y, sz.cx, height, infoPtr->hwndSelf, 0, hinst, 0);
9146 hedit = CreateWindowA("Edit", (LPCSTR)text, style, x, y, sz.cx, height, infoPtr->hwndSelf, 0, hinst, 0);
9148 if (!hedit) return 0;
9150 infoPtr->EditWndProc = (WNDPROC)
9151 (isW ? SetWindowLongW(hedit, GWL_WNDPROC, (LONG)EditLblWndProcW) :
9152 SetWindowLongA(hedit, GWL_WNDPROC, (LONG)EditLblWndProcA) );
9154 SendMessageW(hedit, WM_SETFONT, (WPARAM)infoPtr->hFont, FALSE);