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
9 * Copyright 2009-2013 Nikolay Sivov
10 * Copyright 2009 Owen Rudge for CodeWeavers
11 * Copyright 2012-2013 Daniel Jelinski
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 * This code was audited for completeness against the documented features
30 * of Comctl32.dll version 6.0 on May. 20, 2005, by James Hawkins.
32 * Unless otherwise noted, we believe this code to be complete, as per
33 * the specification mentioned above.
34 * If you discover missing features, or bugs, please note them below.
38 * Default Message Processing
39 * -- WM_CREATE: create the icon and small icon image lists at this point only if
40 * the LVS_SHAREIMAGELISTS style is not specified.
41 * -- WM_WINDOWPOSCHANGED: arrange the list items if the current view is icon
42 * or small icon and the LVS_AUTOARRANGE style is specified.
47 * -- Hot item handling, mouse hovering
48 * -- Workareas support
53 * -- Expand large item in ICON mode when the cursor is flying over the icon or text.
54 * -- Support CustomDraw options for _WIN32_IE >= 0x560 (see NMLVCUSTOMDRAW docs).
55 * -- LVA_SNAPTOGRID not implemented
56 * -- LISTVIEW_ApproximateViewRect partially implemented
57 * -- LISTVIEW_SetColumnWidth ignores header images & bitmap
58 * -- LISTVIEW_StyleChanged doesn't handle some changes too well
61 * -- LISTVIEW_GetNextItem needs to be rewritten. It is currently
62 * linear in the number of items in the list, and this is
63 * unacceptable for large lists.
64 * -- if list is sorted by item text LISTVIEW_InsertItemT could use
65 * binary search to calculate item index (e.g. DPA_Search()).
66 * This requires sorted state to be reliably tracked in item modifiers.
67 * -- we should keep an ordered array of coordinates in iconic mode
68 * this would allow to frame items (iterator_frameditems),
69 * and find nearest item (LVFI_NEARESTXY) a lot more efficiently
76 * -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
81 * -- LVS_NOSCROLL (see Q137520)
85 * -- LVS_EX_BORDERSELECT
89 * -- LVS_EX_MULTIWORKAREAS
91 * -- LVS_EX_SIMPLESELECT
92 * -- LVS_EX_TWOCLICKACTIVATE
93 * -- LVS_EX_UNDERLINECOLD
94 * -- LVS_EX_UNDERLINEHOT
97 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
103 * -- LVM_ENABLEGROUPVIEW
104 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
105 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
106 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
107 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
108 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
109 * -- LVM_GETINSERTMARKRECT
110 * -- LVM_GETNUMBEROFWORKAREAS
111 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
112 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
113 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
114 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
115 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
116 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
117 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
118 * -- LVM_INSERTGROUPSORTED
119 * -- LVM_INSERTMARKHITTEST
120 * -- LVM_ISGROUPVIEWENABLED
122 * -- LVM_MOVEITEMTOGROUP
124 * -- LVM_SETTILEWIDTH
128 * -- ListView_GetHoverTime, ListView_SetHoverTime
129 * -- ListView_GetISearchString
130 * -- ListView_GetNumberOfWorkAreas
131 * -- ListView_GetWorkAreas, ListView_SetWorkAreas
137 #include "comctl32.h"
141 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
143 typedef struct tagCOLUMN_INFO
145 RECT rcHeader
; /* tracks the header's rectangle */
146 INT fmt
; /* same as LVCOLUMN.fmt */
150 typedef struct tagITEMHDR
154 } ITEMHDR
, *LPITEMHDR
;
156 typedef struct tagSUBITEM_INFO
162 typedef struct tagITEM_ID ITEM_ID
;
164 typedef struct tagITEM_INFO
175 UINT id
; /* item id */
176 HDPA item
; /* link to item data */
179 typedef struct tagRANGE
185 typedef struct tagRANGES
190 typedef struct tagITERATOR
199 typedef struct tagDELAYED_ITEM_EDIT
205 typedef struct tagLISTVIEW_INFO
209 RECT rcList
; /* This rectangle is really the window
210 * client rectangle possibly reduced by the
211 * horizontal scroll bar and/or header - see
212 * LISTVIEW_UpdateSize. This rectangle offset
213 * by the LISTVIEW_GetOrigin value is in
214 * client coordinates */
216 /* notification window */
219 BOOL bDoChangeNotify
; /* send change notification messages? */
226 INT nItemCount
; /* the number of items in the list */
227 HDPA hdpaItems
; /* array ITEM_INFO pointers */
228 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
229 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
230 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
231 RANGES selectionRanges
;
232 INT nSelectionMark
; /* item to start next multiselection from */
234 BOOL bAutoarrange
; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
237 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
238 BOOL colRectsDirty
; /* trigger column rectangles requery from header */
241 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
246 PFNLVCOMPARE pfnCompare
; /* sorting callback pointer */
250 DWORD dwStyle
; /* the cached window GWL_STYLE */
251 DWORD dwLvExStyle
; /* extended listview style */
252 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
258 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
261 HIMAGELIST himlNormal
;
262 HIMAGELIST himlSmall
;
263 HIMAGELIST himlState
;
268 POINT currIconPos
; /* this is the position next icon will be placed */
272 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
274 /* marquee selection */
275 BOOL bMarqueeSelect
; /* marquee selection/highlight underway */
277 RECT marqueeRect
; /* absolute coordinates of marquee selection */
278 RECT marqueeDrawRect
; /* relative coordinates for drawing marquee */
279 POINT marqueeOrigin
; /* absolute coordinates of marquee click origin */
282 BOOL bFocus
; /* control has focus */
284 RECT rcFocus
; /* focus bounds */
291 BOOL bDefaultBkColor
;
296 INT ntmHeight
; /* Some cached metrics of the font used */
297 INT ntmMaxCharWidth
; /* by the listview to draw items */
300 /* mouse operation */
303 POINT ptClickPos
; /* point where the user clicked */
304 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
309 /* keyboard operation */
310 DWORD lastKeyPressTimestamp
;
312 INT nSearchParamLength
;
313 WCHAR szSearchParam
[ MAX_PATH
];
316 DWORD cditemmode
; /* Keep the custom draw flags for an item/row */
317 BOOL bIsDrawing
; /* Drawing in progress */
318 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
319 BOOL bRedraw
; /* WM_SETREDRAW switch */
322 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
328 /* How many we debug buffer to allocate */
329 #define DEBUG_BUFFERS 20
330 /* The size of a single debug buffer */
331 #define DEBUG_BUFFER_SIZE 256
333 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
334 #define SB_INTERNAL -1
336 /* maximum size of a label */
337 #define DISP_TEXT_SIZE 260
339 /* padding for items in list and small icon display modes */
340 #define WIDTH_PADDING 12
342 /* padding for items in list, report and small icon display modes */
343 #define HEIGHT_PADDING 1
345 /* offset of items in report display mode */
346 #define REPORT_MARGINX 2
348 /* padding for icon in large icon display mode
349 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
350 * that HITTEST will see.
351 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
352 * ICON_TOP_PADDING - sum of the two above.
353 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
354 * LABEL_HOR_PADDING - between text and sides of box
355 * LABEL_VERT_PADDING - between bottom of text and end of box
357 * ICON_LR_PADDING - additional width above icon size.
358 * ICON_LR_HALF - half of the above value
360 #define ICON_TOP_PADDING_NOTHITABLE 2
361 #define ICON_TOP_PADDING_HITABLE 2
362 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
363 #define ICON_BOTTOM_PADDING 4
364 #define LABEL_HOR_PADDING 5
365 #define LABEL_VERT_PADDING 7
366 #define ICON_LR_PADDING 16
367 #define ICON_LR_HALF (ICON_LR_PADDING/2)
369 /* default label width for items in list and small icon display modes */
370 #define DEFAULT_LABEL_WIDTH 40
371 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
372 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
374 /* default column width for items in list display mode */
375 #define DEFAULT_COLUMN_WIDTH 128
377 /* Size of "line" scroll for V & H scrolls */
378 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
380 /* Padding between image and label */
381 #define IMAGE_PADDING 2
383 /* Padding behind the label */
384 #define TRAILING_LABEL_PADDING 12
385 #define TRAILING_HEADER_PADDING 11
387 /* Border for the icon caption */
388 #define CAPTION_BORDER 2
390 /* Standard DrawText flags */
391 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
392 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
393 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
395 /* Image index from state */
396 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
398 /* The time in milliseconds to reset the search in the list */
399 #define KEY_DELAY 450
401 /* Dump the LISTVIEW_INFO structure to the debug channel */
402 #define LISTVIEW_DUMP(iP) do { \
403 TRACE("hwndSelf=%p, clrBk=0x%06x, clrText=0x%06x, clrTextBk=0x%06x, ItemHeight=%d, ItemWidth=%d, Style=0x%08x\n", \
404 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
405 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
406 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08x, Focus=%d\n", \
407 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
408 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
409 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%d, icSz.cy=%d, icSp.cx=%d, icSp.cy=%d, notifyFmt=%d\n", \
410 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
411 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
412 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
415 static const WCHAR themeClass
[] = {'L','i','s','t','V','i','e','w',0};
418 * forward declarations
420 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
421 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
422 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
423 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
424 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
425 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
426 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
427 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
428 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
429 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
430 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
431 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
432 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
433 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
);
434 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
);
435 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
436 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
437 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
438 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
439 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*, INT
, INT
);
441 /******** Text handling functions *************************************/
443 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
444 * text string. The string may be ANSI or Unicode, in which case
445 * the boolean isW tells us the type of the string.
447 * The name of the function tell what type of strings it expects:
448 * W: Unicode, T: ANSI/Unicode - function of isW
451 static inline BOOL
is_text(LPCWSTR text
)
453 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
456 static inline int textlenT(LPCWSTR text
, BOOL isW
)
458 return !is_text(text
) ? 0 :
459 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
462 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
465 if (isSrcW
) lstrcpynW(dest
, src
, max
);
466 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
468 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
469 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
472 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
474 LPWSTR wstr
= (LPWSTR
)text
;
476 if (!isW
&& is_text(text
))
478 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
479 wstr
= Alloc(len
* sizeof(WCHAR
));
480 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
482 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
486 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
488 if (!isW
&& is_text(wstr
)) Free (wstr
);
492 * dest is a pointer to a Unicode string
493 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
495 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
499 if (src
== LPSTR_TEXTCALLBACKW
)
501 if (is_text(*dest
)) Free(*dest
);
502 *dest
= LPSTR_TEXTCALLBACKW
;
506 LPWSTR pszText
= textdupTtoW(src
, isW
);
507 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
508 bResult
= Str_SetPtrW(dest
, pszText
);
509 textfreeT(pszText
, isW
);
515 * compares a Unicode to a Unicode/ANSI text string
517 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
519 if (!aw
) return bt
? -1 : 0;
521 if (aw
== LPSTR_TEXTCALLBACKW
)
522 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
523 if (bt
!= LPSTR_TEXTCALLBACKW
)
525 LPWSTR bw
= textdupTtoW(bt
, isW
);
526 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
534 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
536 n
= min(min(n
, lstrlenW(s1
)), lstrlenW(s2
));
537 return CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
) - CSTR_EQUAL
;
540 /******** Debugging functions *****************************************/
542 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
544 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
545 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
548 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
550 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
551 n
= min(textlenT(text
, isW
), n
);
552 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
555 static char* debug_getbuf(void)
557 static int index
= 0;
558 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
559 return buffers
[index
++ % DEBUG_BUFFERS
];
562 static inline const char* debugrange(const RANGE
*lprng
)
564 if (!lprng
) return "(null)";
565 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
568 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
570 char* buf
= debug_getbuf(), *text
= buf
;
571 int len
, size
= DEBUG_BUFFER_SIZE
;
573 if (pScrollInfo
== NULL
) return "(null)";
574 len
= snprintf(buf
, size
, "{cbSize=%d, ", pScrollInfo
->cbSize
);
575 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
576 if (pScrollInfo
->fMask
& SIF_RANGE
)
577 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
579 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
580 if (pScrollInfo
->fMask
& SIF_PAGE
)
581 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
583 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
584 if (pScrollInfo
->fMask
& SIF_POS
)
585 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
587 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
588 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
589 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
591 if (len
== -1) goto end
; buf
+= len
;
594 buf
= text
+ strlen(text
);
596 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
600 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
602 if (!plvnm
) return "(null)";
603 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
604 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
605 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
606 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
609 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
611 char* buf
= debug_getbuf(), *text
= buf
;
612 int len
, size
= DEBUG_BUFFER_SIZE
;
614 if (lpLVItem
== NULL
) return "(null)";
615 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
616 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
617 if (lpLVItem
->mask
& LVIF_STATE
)
618 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
620 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
621 if (lpLVItem
->mask
& LVIF_TEXT
)
622 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
624 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
625 if (lpLVItem
->mask
& LVIF_IMAGE
)
626 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
628 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
629 if (lpLVItem
->mask
& LVIF_PARAM
)
630 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
632 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
633 if (lpLVItem
->mask
& LVIF_INDENT
)
634 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
636 if (len
== -1) goto end
; buf
+= len
;
639 buf
= text
+ strlen(text
);
641 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
645 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
647 char* buf
= debug_getbuf(), *text
= buf
;
648 int len
, size
= DEBUG_BUFFER_SIZE
;
650 if (lpColumn
== NULL
) return "(null)";
651 len
= snprintf(buf
, size
, "{");
652 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
653 if (lpColumn
->mask
& LVCF_SUBITEM
)
654 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
656 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
657 if (lpColumn
->mask
& LVCF_FMT
)
658 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
660 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
661 if (lpColumn
->mask
& LVCF_WIDTH
)
662 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
664 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
665 if (lpColumn
->mask
& LVCF_TEXT
)
666 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
668 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
669 if (lpColumn
->mask
& LVCF_IMAGE
)
670 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
672 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
673 if (lpColumn
->mask
& LVCF_ORDER
)
674 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
676 if (len
== -1) goto end
; buf
+= len
;
679 buf
= text
+ strlen(text
);
681 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
685 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
687 if (!lpht
) return "(null)";
689 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
690 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
693 /* Return the corresponding text for a given scroll value */
694 static inline LPCSTR
debugscrollcode(int nScrollCode
)
698 case SB_LINELEFT
: return "SB_LINELEFT";
699 case SB_LINERIGHT
: return "SB_LINERIGHT";
700 case SB_PAGELEFT
: return "SB_PAGELEFT";
701 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
702 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
703 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
704 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
705 case SB_INTERNAL
: return "SB_INTERNAL";
706 default: return "unknown";
711 /******** Notification functions ************************************/
713 static int get_ansi_notification(UINT unicodeNotificationCode
)
715 switch (unicodeNotificationCode
)
717 case LVN_BEGINLABELEDITA
:
718 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
719 case LVN_ENDLABELEDITA
:
720 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
721 case LVN_GETDISPINFOA
:
722 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
723 case LVN_SETDISPINFOA
:
724 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
725 case LVN_ODFINDITEMA
:
726 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
727 case LVN_GETINFOTIPA
:
728 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
729 /* header forwards */
731 case HDN_TRACKW
: return HDN_TRACKA
;
733 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
734 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
735 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
736 case HDN_ITEMCHANGINGA
:
737 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
738 case HDN_ITEMCHANGEDA
:
739 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
741 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
742 case HDN_DIVIDERDBLCLICKA
:
743 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
746 FIXME("unknown notification %x\n", unicodeNotificationCode
);
747 return unicodeNotificationCode
;
750 /* forwards header notifications to listview parent */
751 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, NMHEADERW
*lpnmhW
)
753 LPCWSTR text
= NULL
, filter
= NULL
;
755 NMHEADERA
*lpnmh
= (NMHEADERA
*) lpnmhW
;
757 /* on unicode format exit earlier */
758 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
759 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
762 /* header always supplies unicode notifications,
763 all we have to do is to convert strings to ANSI */
766 /* convert item text */
767 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
769 text
= (LPCWSTR
)lpnmh
->pitem
->pszText
;
770 Str_SetPtrWtoA(&lpnmh
->pitem
->pszText
, text
);
772 /* convert filter text */
773 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
774 lpnmh
->pitem
->pvFilter
)
776 filter
= (LPCWSTR
)((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
;
777 Str_SetPtrWtoA(&((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
, filter
);
780 lpnmh
->hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
782 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
788 Free(lpnmh
->pitem
->pszText
);
789 lpnmh
->pitem
->pszText
= (LPSTR
)text
;
793 Free(((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
);
794 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= (LPSTR
)filter
;
800 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
804 TRACE("(code=%d)\n", code
);
806 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
807 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
809 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
811 TRACE(" <= %ld\n", result
);
816 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
819 HWND hwnd
= infoPtr
->hwndSelf
;
820 notify_hdr(infoPtr
, code
, &nmh
);
821 return IsWindow(hwnd
);
824 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
835 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
836 item
.iItem
= htInfo
->iItem
;
838 item
.stateMask
= (UINT
)-1;
839 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
840 nmia
.lParam
= item
.lParam
;
841 nmia
.uOldState
= item
.state
;
842 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
843 nmia
.uChanged
= LVIF_STATE
;
846 nmia
.iItem
= htInfo
->iItem
;
847 nmia
.iSubItem
= htInfo
->iSubItem
;
848 nmia
.ptAction
= htInfo
->pt
;
850 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
851 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
852 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
854 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
857 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
859 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
860 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
863 /* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
864 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
868 HWND hwnd
= infoPtr
->hwndSelf
;
871 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
872 ZeroMemory(&nmia
, sizeof(nmia
));
873 nmia
.iItem
= lvht
->iItem
;
874 nmia
.iSubItem
= lvht
->iSubItem
;
875 nmia
.ptAction
= lvht
->pt
;
876 item
.mask
= LVIF_PARAM
;
877 item
.iItem
= lvht
->iItem
;
879 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
880 ret
= notify_hdr(infoPtr
, code
, (NMHDR
*)&nmia
);
881 return IsWindow(hwnd
) && (code
== NM_RCLICK
? !ret
: TRUE
);
884 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
888 HWND hwnd
= infoPtr
->hwndSelf
;
890 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
892 item
.mask
= LVIF_PARAM
;
895 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
896 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
897 return IsWindow(hwnd
);
901 Send notification. depends on dispinfoW having same
902 structure as dispinfoA.
903 infoPtr : listview struct
904 code : *Unicode* notification code
905 pdi : dispinfo structure (can be unicode or ansi)
906 isW : TRUE if dispinfo is Unicode
908 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
910 INT length
= 0, ret_length
;
911 LPWSTR buffer
= NULL
, ret_text
;
912 BOOL return_ansi
= FALSE
;
913 BOOL return_unicode
= FALSE
;
916 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
918 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
919 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
922 ret_length
= pdi
->item
.cchTextMax
;
923 ret_text
= pdi
->item
.pszText
;
925 if (return_unicode
|| return_ansi
)
927 if (code
!= LVN_GETDISPINFOW
)
929 length
= return_ansi
?
930 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
931 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
935 length
= pdi
->item
.cchTextMax
;
936 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
939 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
940 if (!buffer
) return FALSE
;
943 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
946 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
949 pdi
->item
.pszText
= buffer
;
950 pdi
->item
.cchTextMax
= length
;
953 if (infoPtr
->notifyFormat
== NFR_ANSI
)
954 code
= get_ansi_notification(code
);
956 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
957 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
958 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
960 if (return_ansi
|| return_unicode
)
962 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
964 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
966 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
968 strcpyW(ret_text
, pdi
->item
.pszText
);
970 else if (return_ansi
) /* note : pointer can be changed by app ! */
972 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
973 ret_length
, NULL
, NULL
);
976 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
977 ret_text
, ret_length
);
979 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
980 pdi
->item
.cchTextMax
= ret_length
;
986 /* if dipsinfo holder changed notification code then convert */
987 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
989 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
991 buffer
= Alloc(length
* sizeof(CHAR
));
992 if (!buffer
) return FALSE
;
994 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
995 ret_length
, NULL
, NULL
);
997 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1004 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1005 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1007 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1008 lpnmlvcd
->nmcd
.hdc
= hdc
;
1009 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1010 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1011 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1012 if (!lplvItem
) return;
1013 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1014 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1015 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1016 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1017 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1018 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1021 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1023 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1026 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1027 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1028 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1029 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1030 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1031 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1035 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1037 if (lpnmlvcd
->clrTextBk
== CLR_DEFAULT
)
1038 lpnmlvcd
->clrTextBk
= comctl32_color
.clrWindow
;
1039 if (lpnmlvcd
->clrText
== CLR_DEFAULT
)
1040 lpnmlvcd
->clrText
= comctl32_color
.clrWindowText
;
1042 /* apparently, for selected items, we have to override the returned values */
1045 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1047 if (infoPtr
->bFocus
)
1049 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1050 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1052 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1054 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1055 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1060 /* Set the text attributes */
1061 if (lpnmlvcd
->clrTextBk
!= CLR_NONE
)
1063 SetBkMode(hdc
, OPAQUE
);
1064 SetBkColor(hdc
,lpnmlvcd
->clrTextBk
);
1067 SetBkMode(hdc
, TRANSPARENT
);
1068 SetTextColor(hdc
, lpnmlvcd
->clrText
);
1071 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1073 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1076 /* returns TRUE when repaint needed, FALSE otherwise */
1077 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1079 MEASUREITEMSTRUCT mis
;
1080 mis
.CtlType
= ODT_LISTVIEW
;
1081 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1085 mis
.itemHeight
= infoPtr
->nItemHeight
;
1086 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1087 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1089 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1095 /******** Item iterator functions **********************************/
1097 static RANGES
ranges_create(int count
);
1098 static void ranges_destroy(RANGES ranges
);
1099 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1100 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1101 static void ranges_dump(RANGES ranges
);
1103 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1105 RANGE range
= { nItem
, nItem
+ 1 };
1107 return ranges_add(ranges
, range
);
1110 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1112 RANGE range
= { nItem
, nItem
+ 1 };
1114 return ranges_del(ranges
, range
);
1118 * ITERATOR DOCUMENTATION
1120 * The iterator functions allow for easy, and convenient iteration
1121 * over items of interest in the list. Typically, you create an
1122 * iterator, use it, and destroy it, as such:
1125 * iterator_xxxitems(&i, ...);
1126 * while (iterator_{prev,next}(&i)
1128 * //code which uses i.nItem
1130 * iterator_destroy(&i);
1132 * where xxx is either: framed, or visible.
1133 * Note that it is important that the code destroys the iterator
1134 * after it's done with it, as the creation of the iterator may
1135 * allocate memory, which thus needs to be freed.
1137 * You can iterate both forwards, and backwards through the list,
1138 * by using iterator_next or iterator_prev respectively.
1140 * Lower numbered items are draw on top of higher number items in
1141 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1142 * items may overlap). So, to test items, you should use
1144 * which lists the items top to bottom (in Z-order).
1145 * For drawing items, you should use
1147 * which lists the items bottom to top (in Z-order).
1148 * If you keep iterating over the items after the end-of-items
1149 * marker (-1) is returned, the iterator will start from the
1150 * beginning. Typically, you don't need to test for -1,
1151 * because iterator_{next,prev} will return TRUE if more items
1152 * are to be iterated over, or FALSE otherwise.
1154 * Note: the iterator is defined to be bidirectional. That is,
1155 * any number of prev followed by any number of next, or
1156 * five versa, should leave the iterator at the same item:
1157 * prev * n, next * n = next * n, prev * n
1159 * The iterator has a notion of an out-of-order, special item,
1160 * which sits at the start of the list. This is used in
1161 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1162 * which needs to be first, as it may overlap other items.
1164 * The code is a bit messy because we have:
1165 * - a special item to deal with
1166 * - simple range, or composite range
1168 * If you find bugs, or want to add features, please make sure you
1169 * always check/modify *both* iterator_prev, and iterator_next.
1173 * This function iterates through the items in increasing order,
1174 * but prefixed by the special item, then -1. That is:
1175 * special, 1, 2, 3, ..., n, -1.
1176 * Each item is listed only once.
1178 static inline BOOL
iterator_next(ITERATOR
* i
)
1182 i
->nItem
= i
->nSpecial
;
1183 if (i
->nItem
!= -1) return TRUE
;
1185 if (i
->nItem
== i
->nSpecial
)
1187 if (i
->ranges
) i
->index
= 0;
1193 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1194 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1199 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1200 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1203 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1205 i
->nItem
= i
->range
.lower
;
1206 if (i
->nItem
>= 0) goto testitem
;
1213 * This function iterates through the items in decreasing order,
1214 * followed by the special item, then -1. That is:
1215 * n, n-1, ..., 3, 2, 1, special, -1.
1216 * Each item is listed only once.
1218 static inline BOOL
iterator_prev(ITERATOR
* i
)
1225 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1228 if (i
->nItem
== i
->nSpecial
)
1236 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1237 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1243 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1246 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1248 i
->nItem
= i
->range
.upper
;
1249 if (i
->nItem
> 0) goto testitem
;
1251 return (i
->nItem
= i
->nSpecial
) != -1;
1254 static RANGE
iterator_range(const ITERATOR
*i
)
1258 if (!i
->ranges
) return i
->range
;
1260 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1262 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1263 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1265 else range
.lower
= range
.upper
= 0;
1271 * Releases resources associated with this iterator.
1273 static inline void iterator_destroy(const ITERATOR
*i
)
1275 ranges_destroy(i
->ranges
);
1279 * Create an empty iterator.
1281 static inline BOOL
iterator_empty(ITERATOR
* i
)
1283 ZeroMemory(i
, sizeof(*i
));
1284 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1289 * Create an iterator over a range.
1291 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1299 * Create an iterator over a bunch of ranges.
1300 * Please note that the iterator will take ownership of the ranges,
1301 * and will free them upon destruction.
1303 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1311 * Creates an iterator over the items which intersect frame.
1312 * Uses absolute coordinates rather than compensating for the current offset.
1314 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1316 RECT rcItem
, rcTemp
;
1318 /* in case we fail, we want to return an empty iterator */
1319 if (!iterator_empty(i
)) return FALSE
;
1321 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1323 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1327 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1329 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1330 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1331 i
->nSpecial
= infoPtr
->nFocusedItem
;
1333 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1334 /* to do better here, we need to have PosX, and PosY sorted */
1335 TRACE("building icon ranges:\n");
1336 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1338 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1339 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1340 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1341 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1342 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1343 ranges_additem(i
->ranges
, nItem
);
1347 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1351 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1352 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1354 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1355 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1356 if (range
.upper
<= range
.lower
) return TRUE
;
1357 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1358 TRACE(" report=%s\n", debugrange(&i
->range
));
1362 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1363 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1364 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1371 if (infoPtr
->nItemWidth
)
1373 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1374 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1378 nFirstCol
= max(frame
->left
, 0);
1379 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1382 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1384 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1385 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1387 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1389 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1390 TRACE("building list ranges:\n");
1391 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1393 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1394 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1395 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1396 TRACE(" list=%s\n", debugrange(&item_range
));
1397 ranges_add(i
->ranges
, item_range
);
1405 * Creates an iterator over the items which intersect lprc.
1407 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1412 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1414 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1415 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1417 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1421 * Creates an iterator over the items which intersect the visible region of hdc.
1423 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1425 POINT Origin
, Position
;
1426 RECT rcItem
, rcClip
;
1429 rgntype
= GetClipBox(hdc
, &rcClip
);
1430 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1431 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1432 if (rgntype
== SIMPLEREGION
) return TRUE
;
1434 /* first deal with the special item */
1435 if (i
->nSpecial
!= -1)
1437 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1438 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1441 /* if we can't deal with the region, we'll just go with the simple range */
1442 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1443 TRACE("building visible range:\n");
1444 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1446 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1447 if (!ranges_add(i
->ranges
, i
->range
))
1449 ranges_destroy(i
->ranges
);
1455 /* now delete the invisible items from the list */
1456 while(iterator_next(i
))
1458 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1459 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1460 rcItem
.top
= Position
.y
+ Origin
.y
;
1461 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1462 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1463 if (!RectVisible(hdc
, &rcItem
))
1464 ranges_delitem(i
->ranges
, i
->nItem
);
1466 /* the iterator should restart on the next iterator_next */
1472 /* Remove common elements from two iterators */
1473 /* Passed iterators have to point on the first elements */
1474 static BOOL
iterator_remove_common_items(ITERATOR
*iter1
, ITERATOR
*iter2
)
1476 if(!iter1
->ranges
|| !iter2
->ranges
) {
1479 if(iter1
->ranges
|| iter2
->ranges
||
1480 (iter1
->range
.lower
<iter2
->range
.lower
&& iter1
->range
.upper
>iter2
->range
.upper
) ||
1481 (iter1
->range
.lower
>iter2
->range
.lower
&& iter1
->range
.upper
<iter2
->range
.upper
)) {
1482 ERR("result is not a one range iterator\n");
1486 if(iter1
->range
.lower
==-1 || iter2
->range
.lower
==-1)
1489 lower
= iter1
->range
.lower
;
1490 upper
= iter1
->range
.upper
;
1492 if(lower
< iter2
->range
.lower
)
1493 iter1
->range
.upper
= iter2
->range
.lower
;
1494 else if(upper
> iter2
->range
.upper
)
1495 iter1
->range
.lower
= iter2
->range
.upper
;
1497 iter1
->range
.lower
= iter1
->range
.upper
= -1;
1499 if(iter2
->range
.lower
< lower
)
1500 iter2
->range
.upper
= lower
;
1501 else if(iter2
->range
.upper
> upper
)
1502 iter2
->range
.lower
= upper
;
1504 iter2
->range
.lower
= iter2
->range
.upper
= -1;
1509 iterator_next(iter1
);
1510 iterator_next(iter2
);
1513 if(iter1
->nItem
==-1 || iter2
->nItem
==-1)
1516 if(iter1
->nItem
== iter2
->nItem
) {
1517 int delete = iter1
->nItem
;
1519 iterator_prev(iter1
);
1520 iterator_prev(iter2
);
1521 ranges_delitem(iter1
->ranges
, delete);
1522 ranges_delitem(iter2
->ranges
, delete);
1523 iterator_next(iter1
);
1524 iterator_next(iter2
);
1525 } else if(iter1
->nItem
> iter2
->nItem
)
1526 iterator_next(iter2
);
1528 iterator_next(iter1
);
1531 iter1
->nItem
= iter1
->range
.lower
= iter1
->range
.upper
= -1;
1532 iter2
->nItem
= iter2
->range
.lower
= iter2
->range
.upper
= -1;
1536 /******** Misc helper functions ************************************/
1538 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1539 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1541 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1542 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1545 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1547 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1548 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1551 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1553 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1554 if(state
== 1 || state
== 2)
1558 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1559 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1560 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1564 /* this should be called after window style got updated,
1565 it used to reset view state to match current window style */
1566 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1568 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1571 infoPtr
->uView
= LV_VIEW_ICON
;
1574 infoPtr
->uView
= LV_VIEW_DETAILS
;
1577 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1580 infoPtr
->uView
= LV_VIEW_LIST
;
1584 /* computes next item id value */
1585 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1587 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1591 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1592 return lpID
->id
+ 1;
1597 /******** Internal API functions ************************************/
1599 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1601 static COLUMN_INFO mainItem
;
1603 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1604 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1606 /* update cached column rectangles */
1607 if (infoPtr
->colRectsDirty
)
1610 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1613 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1614 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1615 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1617 Ptr
->colRectsDirty
= FALSE
;
1620 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1623 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1625 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1628 if (infoPtr
->hwndHeader
) return 0;
1630 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1632 /* setup creation flags */
1633 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1634 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1636 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1639 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1640 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1641 if (!infoPtr
->hwndHeader
) return -1;
1643 /* set header unicode format */
1644 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1646 /* set header font */
1647 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1649 /* set header image list */
1650 if (infoPtr
->himlSmall
)
1651 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)infoPtr
->himlSmall
);
1653 LISTVIEW_UpdateSize(infoPtr
);
1658 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1660 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1663 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1665 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1666 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1667 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1670 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1672 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1675 /* used to handle collapse main item column case */
1676 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1680 if (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
)
1682 DWORD dwOldBkColor
, dwOldTextColor
;
1684 dwOldBkColor
= SetBkColor(hdc
, RGB(255, 255, 255));
1685 dwOldTextColor
= SetBkColor(hdc
, RGB(0, 0, 0));
1686 Ret
= DrawFocusRect(hdc
, &infoPtr
->rcFocus
);
1687 SetBkColor(hdc
, dwOldBkColor
);
1688 SetBkColor(hdc
, dwOldTextColor
);
1693 /* Listview invalidation functions: use _only_ these functions to invalidate */
1695 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1697 return infoPtr
->bRedraw
;
1700 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1702 if(!is_redrawing(infoPtr
)) return;
1703 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1704 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1707 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1711 if(!is_redrawing(infoPtr
)) return;
1712 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1713 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1716 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1718 POINT Origin
, Position
;
1721 if(!is_redrawing(infoPtr
)) return;
1722 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1723 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1724 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1725 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1727 rcBox
.bottom
= infoPtr
->nItemHeight
;
1728 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1729 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1732 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1734 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1737 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1741 if(!is_redrawing(infoPtr
)) return;
1742 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1743 rcCol
.top
= infoPtr
->rcList
.top
;
1744 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1745 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1750 * Retrieves the number of items that can fit vertically in the client area.
1753 * [I] infoPtr : valid pointer to the listview structure
1756 * Number of items per row.
1758 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1760 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1762 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1767 * Retrieves the number of items that can fit horizontally in the client
1771 * [I] infoPtr : valid pointer to the listview structure
1774 * Number of items per column.
1776 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1778 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1780 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1784 /*************************************************************************
1785 * LISTVIEW_ProcessLetterKeys
1787 * Processes keyboard messages generated by pressing the letter keys
1789 * What this does is perform a case insensitive search from the
1790 * current position with the following quirks:
1791 * - If two chars or more are pressed in quick succession we search
1792 * for the corresponding string (e.g. 'abc').
1793 * - If there is a delay we wipe away the current search string and
1794 * restart with just that char.
1795 * - If the user keeps pressing the same character, whether slowly or
1796 * fast, so that the search string is entirely composed of this
1797 * character ('aaaaa' for instance), then we search for first item
1798 * that starting with that character.
1799 * - If the user types the above character in quick succession, then
1800 * we must also search for the corresponding string ('aaaaa'), and
1801 * go to that string if there is a match.
1804 * [I] hwnd : handle to the window
1805 * [I] charCode : the character code, the actual character
1806 * [I] keyData : key data
1814 * - The current implementation has a list of characters it will
1815 * accept and it ignores everything else. In particular it will
1816 * ignore accentuated characters which seems to match what
1817 * Windows does. But I'm not sure it makes sense to follow
1819 * - We don't sound a beep when the search fails.
1823 * TREEVIEW_ProcessLetterKeys
1825 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1827 WCHAR buffer
[MAX_PATH
];
1834 /* simple parameter checking */
1835 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1837 /* only allow the valid WM_CHARs through */
1838 if (!isalnumW(charCode
) &&
1839 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1840 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1841 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1842 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1843 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1844 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1845 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1846 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1847 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1850 /* update the search parameters */
1851 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1852 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1853 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1855 if (diff
>= 0 && diff
< KEY_DELAY
)
1857 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1858 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1860 if (infoPtr
->charCode
!= charCode
)
1861 infoPtr
->charCode
= charCode
= 0;
1865 infoPtr
->charCode
= charCode
;
1866 infoPtr
->szSearchParam
[0] = charCode
;
1867 infoPtr
->nSearchParamLength
= 1;
1870 /* should start from next after focused item, so next item that matches
1871 will be selected, if there isn't any and focused matches it will be selected
1872 on second search stage from beginning of the list */
1873 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1875 /* with some accumulated search data available start with current focus, otherwise
1876 it's excluded from search */
1877 startidx
= infoPtr
->nSearchParamLength
> 1 ? infoPtr
->nFocusedItem
: infoPtr
->nFocusedItem
+ 1;
1878 if (startidx
== infoPtr
->nItemCount
) startidx
= 0;
1883 /* let application handle this for virtual listview */
1884 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1888 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1889 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1890 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1891 nmlv
.iStart
= startidx
;
1893 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1895 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1899 int i
= startidx
, endidx
;
1901 /* and search from the current position */
1903 endidx
= infoPtr
->nItemCount
;
1905 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1908 /* start from first item if not found with >= startidx */
1909 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1915 for (i
= startidx
; i
< endidx
; i
++)
1918 item
.mask
= LVIF_TEXT
;
1921 item
.pszText
= buffer
;
1922 item
.cchTextMax
= MAX_PATH
;
1923 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1925 if (!lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
))
1930 /* this is used to find first char match when search string is not available yet,
1931 otherwise every WM_CHAR will search to next item by first char, ignoring that we're
1932 already waiting for user to complete a string */
1933 else if (nItem
== -1 && infoPtr
->nSearchParamLength
== 1 && !lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, 1))
1935 /* this would work but we must keep looking for a longer match */
1940 if ( nItem
!= -1 || /* found something */
1941 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1942 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1948 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1953 /*************************************************************************
1954 * LISTVIEW_UpdateHeaderSize [Internal]
1956 * Function to resize the header control
1959 * [I] hwnd : handle to a window
1960 * [I] nNewScrollPos : scroll pos to set
1965 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1970 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1972 if (!infoPtr
->hwndHeader
) return;
1974 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1975 point
[0].x
= winRect
.left
;
1976 point
[0].y
= winRect
.top
;
1977 point
[1].x
= winRect
.right
;
1978 point
[1].y
= winRect
.bottom
;
1980 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1981 point
[0].x
= -nNewScrollPos
;
1982 point
[1].x
+= nNewScrollPos
;
1984 SetWindowPos(infoPtr
->hwndHeader
,0,
1985 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1986 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
1987 SWP_NOZORDER
| SWP_NOACTIVATE
);
1992 * Update the scrollbars. This functions should be called whenever
1993 * the content, size or view changes.
1996 * [I] infoPtr : valid pointer to the listview structure
2001 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
2003 SCROLLINFO horzInfo
, vertInfo
;
2006 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
2008 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
2009 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
2010 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2012 /* for now, we'll set info.nMax to the _count_, and adjust it later */
2013 if (infoPtr
->uView
== LV_VIEW_LIST
)
2015 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
2016 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
2018 /* scroll by at least one column per page */
2019 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
2020 horzInfo
.nPage
= infoPtr
->nItemWidth
;
2022 if (infoPtr
->nItemWidth
)
2023 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
2025 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2027 horzInfo
.nMax
= infoPtr
->nItemWidth
;
2029 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2033 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
2036 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
2038 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
2043 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2044 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2046 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2047 horzInfo
.nMax
= rcHeader
.right
;
2048 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2052 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2053 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2054 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2055 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2056 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2058 /* Setting the horizontal scroll can change the listview size
2059 * (and potentially everything else) so we need to recompute
2060 * everything again for the vertical scroll
2063 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2064 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2065 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2067 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2069 vertInfo
.nMax
= infoPtr
->nItemCount
;
2071 /* scroll by at least one page */
2072 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2073 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2075 if (infoPtr
->nItemHeight
> 0)
2076 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2078 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2082 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2085 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2086 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2087 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2088 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2089 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2091 /* Change of the range may have changed the scroll pos. If so move the content */
2092 if (dx
!= 0 || dy
!= 0)
2095 listRect
= infoPtr
->rcList
;
2096 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2097 SW_ERASE
| SW_INVALIDATE
);
2100 /* Update the Header Control */
2101 if (infoPtr
->hwndHeader
)
2103 horzInfo
.fMask
= SIF_POS
;
2104 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2105 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2112 * Shows/hides the focus rectangle.
2115 * [I] infoPtr : valid pointer to the listview structure
2116 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2121 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2125 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2127 if (infoPtr
->nFocusedItem
< 0) return;
2129 /* we need some gymnastics in ICON mode to handle large items */
2130 if (infoPtr
->uView
== LV_VIEW_ICON
)
2134 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2135 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2137 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2142 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2144 /* for some reason, owner draw should work only in report mode */
2145 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2150 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2151 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2153 item
.iItem
= infoPtr
->nFocusedItem
;
2155 item
.mask
= LVIF_PARAM
;
2156 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2158 ZeroMemory(&dis
, sizeof(dis
));
2159 dis
.CtlType
= ODT_LISTVIEW
;
2160 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2161 dis
.itemID
= item
.iItem
;
2162 dis
.itemAction
= ODA_FOCUS
;
2163 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2164 dis
.hwndItem
= infoPtr
->hwndSelf
;
2166 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2167 dis
.itemData
= item
.lParam
;
2169 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2171 SelectObject(hdc
, hOldFont
);
2175 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
2178 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2182 * Invalidates all visible selected items.
2184 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2188 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2189 while(iterator_next(&i
))
2191 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2192 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2194 iterator_destroy(&i
);
2199 * DESCRIPTION: [INTERNAL]
2200 * Computes an item's (left,top) corner, relative to rcView.
2201 * That is, the position has NOT been made relative to the Origin.
2202 * This is deliberate, to avoid computing the Origin over, and
2203 * over again, when this function is called in a loop. Instead,
2204 * one can factor the computation of the Origin before the loop,
2205 * and offset the value returned by this function, on every iteration.
2208 * [I] infoPtr : valid pointer to the listview structure
2209 * [I] nItem : item number
2210 * [O] lpptOrig : item top, left corner
2215 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2217 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2219 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2221 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2222 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2224 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2226 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2227 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2228 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2230 else /* LV_VIEW_DETAILS */
2232 lpptPosition
->x
= REPORT_MARGINX
;
2233 /* item is always at zero indexed column */
2234 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2235 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2236 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2241 * DESCRIPTION: [INTERNAL]
2242 * Compute the rectangles of an item. This is to localize all
2243 * the computations in one place. If you are not interested in some
2244 * of these values, simply pass in a NULL -- the function is smart
2245 * enough to compute only what's necessary. The function computes
2246 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2247 * one, the BOX rectangle. This rectangle is very cheap to compute,
2248 * and is guaranteed to contain all the other rectangles. Computing
2249 * the ICON rect is also cheap, but all the others are potentially
2250 * expensive. This gives an easy and effective optimization when
2251 * searching (like point inclusion, or rectangle intersection):
2252 * first test against the BOX, and if TRUE, test against the desired
2254 * If the function does not have all the necessary information
2255 * to computed the requested rectangles, will crash with a
2256 * failed assertion. This is done so we catch all programming
2257 * errors, given that the function is called only from our code.
2259 * We have the following 'special' meanings for a few fields:
2260 * * If LVIS_FOCUSED is set, we assume the item has the focus
2261 * This is important in ICON mode, where it might get a larger
2262 * then usual rectangle
2264 * Please note that subitem support works only in REPORT mode.
2267 * [I] infoPtr : valid pointer to the listview structure
2268 * [I] lpLVItem : item to compute the measures for
2269 * [O] lprcBox : ptr to Box rectangle
2270 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2271 * [0] lprcSelectBox : ptr to select box rectangle
2272 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2273 * [O] lprcIcon : ptr to Icon rectangle
2274 * Same as LVM_GETITEMRECT with LVIR_ICON
2275 * [O] lprcStateIcon: ptr to State Icon rectangle
2276 * [O] lprcLabel : ptr to Label rectangle
2277 * Same as LVM_GETITEMRECT with LVIR_LABEL
2282 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2283 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2284 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2286 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2287 RECT Box
, SelectBox
, Icon
, Label
;
2288 COLUMN_INFO
*lpColumnInfo
= NULL
;
2289 SIZE labelSize
= { 0, 0 };
2291 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2293 /* Be smart and try to figure out the minimum we have to do */
2294 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2295 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2297 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2298 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2300 if (lprcSelectBox
) doSelectBox
= TRUE
;
2301 if (lprcLabel
) doLabel
= TRUE
;
2302 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2309 /************************************************************/
2310 /* compute the box rectangle (it should be cheap to do) */
2311 /************************************************************/
2312 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2313 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2315 if (lpLVItem
->iSubItem
)
2317 Box
= lpColumnInfo
->rcHeader
;
2322 Box
.right
= infoPtr
->nItemWidth
;
2325 Box
.bottom
= infoPtr
->nItemHeight
;
2327 /******************************************************************/
2328 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2329 /******************************************************************/
2332 LONG state_width
= 0;
2334 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2335 state_width
= infoPtr
->iconStateSize
.cx
;
2337 if (infoPtr
->uView
== LV_VIEW_ICON
)
2339 Icon
.left
= Box
.left
+ state_width
;
2340 if (infoPtr
->himlNormal
)
2341 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2342 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2343 Icon
.right
= Icon
.left
;
2344 Icon
.bottom
= Icon
.top
;
2345 if (infoPtr
->himlNormal
)
2347 Icon
.right
+= infoPtr
->iconSize
.cx
;
2348 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2351 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2353 Icon
.left
= Box
.left
+ state_width
;
2355 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2357 /* we need the indent in report mode */
2358 assert(lpLVItem
->mask
& LVIF_INDENT
);
2359 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2363 Icon
.right
= Icon
.left
;
2364 if (infoPtr
->himlSmall
&&
2365 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2366 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2367 Icon
.right
+= infoPtr
->iconSize
.cx
;
2368 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2370 if(lprcIcon
) *lprcIcon
= Icon
;
2371 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2373 /* TODO: is this correct? */
2376 lprcStateIcon
->left
= Icon
.left
- state_width
;
2377 lprcStateIcon
->right
= Icon
.left
;
2378 lprcStateIcon
->top
= Icon
.top
;
2379 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2380 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2383 else Icon
.right
= 0;
2385 /************************************************************/
2386 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2387 /************************************************************/
2390 /* calculate how far to the right can the label stretch */
2391 Label
.right
= Box
.right
;
2392 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2394 if (lpLVItem
->iSubItem
== 0)
2396 /* we need a zero based rect here */
2397 Label
= lpColumnInfo
->rcHeader
;
2398 OffsetRect(&Label
, -Label
.left
, 0);
2402 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2404 labelSize
.cx
= infoPtr
->nItemWidth
;
2405 labelSize
.cy
= infoPtr
->nItemHeight
;
2409 /* we need the text in non owner draw mode */
2410 assert(lpLVItem
->mask
& LVIF_TEXT
);
2411 if (is_text(lpLVItem
->pszText
))
2413 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2414 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2415 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2419 /* compute rough rectangle where the label will go */
2420 SetRectEmpty(&rcText
);
2421 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2422 rcText
.bottom
= infoPtr
->nItemHeight
;
2423 if (infoPtr
->uView
== LV_VIEW_ICON
)
2424 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2426 /* now figure out the flags */
2427 if (infoPtr
->uView
== LV_VIEW_ICON
)
2428 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2430 uFormat
= LV_SL_DT_FLAGS
;
2432 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2434 if (rcText
.right
!= rcText
.left
)
2435 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2437 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2439 SelectObject(hdc
, hOldFont
);
2440 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2444 if (infoPtr
->uView
== LV_VIEW_ICON
)
2446 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2447 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2448 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2449 Label
.right
= Label
.left
+ labelSize
.cx
;
2450 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2451 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2453 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2454 labelSize
.cy
/= infoPtr
->ntmHeight
;
2455 labelSize
.cy
= max(labelSize
.cy
, 1);
2456 labelSize
.cy
*= infoPtr
->ntmHeight
;
2458 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2460 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2462 Label
.left
= Icon
.right
;
2463 Label
.top
= Box
.top
;
2464 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2465 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2466 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2468 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2470 Label
.left
= Icon
.right
;
2471 Label
.top
= Box
.top
;
2472 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2473 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2476 if (lprcLabel
) *lprcLabel
= Label
;
2477 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2480 /************************************************************/
2481 /* compute SELECT bounding box */
2482 /************************************************************/
2485 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2487 SelectBox
.left
= Icon
.left
;
2488 SelectBox
.top
= Box
.top
;
2489 SelectBox
.bottom
= Box
.bottom
;
2492 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2494 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2498 UnionRect(&SelectBox
, &Icon
, &Label
);
2500 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2501 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2504 /* Fix the Box if necessary */
2507 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2508 else *lprcBox
= Box
;
2510 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2514 * DESCRIPTION: [INTERNAL]
2517 * [I] infoPtr : valid pointer to the listview structure
2518 * [I] nItem : item number
2519 * [O] lprcBox : ptr to Box rectangle
2524 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2526 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2527 POINT Position
, Origin
;
2530 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2531 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2533 /* Be smart and try to figure out the minimum we have to do */
2535 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2536 lvItem
.mask
|= LVIF_TEXT
;
2537 lvItem
.iItem
= nItem
;
2538 lvItem
.iSubItem
= 0;
2539 lvItem
.pszText
= szDispText
;
2540 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2541 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2542 if (infoPtr
->uView
== LV_VIEW_ICON
)
2544 lvItem
.mask
|= LVIF_STATE
;
2545 lvItem
.stateMask
= LVIS_FOCUSED
;
2546 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2548 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2550 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2551 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2553 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2556 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2559 /* LISTVIEW_MapIdToIndex helper */
2560 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2562 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2563 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2565 if (id1
->id
== id2
->id
) return 0;
2567 return (id1
->id
< id2
->id
) ? -1 : 1;
2572 * Returns the item index for id specified.
2575 * [I] infoPtr : valid pointer to the listview structure
2576 * [I] iID : item id to get index for
2579 * Item index, or -1 on failure.
2581 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2586 TRACE("iID=%d\n", iID
);
2588 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2589 if (infoPtr
->nItemCount
== 0) return -1;
2592 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2596 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2597 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2605 * Returns the item id for index given.
2608 * [I] infoPtr : valid pointer to the listview structure
2609 * [I] iItem : item index to get id for
2614 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2619 TRACE("iItem=%d\n", iItem
);
2621 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2622 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2624 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2625 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2627 return lpItem
->id
->id
;
2632 * Returns the current icon position, and advances it along the top.
2633 * The returned position is not offset by Origin.
2636 * [I] infoPtr : valid pointer to the listview structure
2637 * [O] lpPos : will get the current icon position
2642 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2644 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2646 *lpPos
= infoPtr
->currIconPos
;
2648 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2649 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2651 infoPtr
->currIconPos
.x
= 0;
2652 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2658 * Returns the current icon position, and advances it down the left edge.
2659 * The returned position is not offset by Origin.
2662 * [I] infoPtr : valid pointer to the listview structure
2663 * [O] lpPos : will get the current icon position
2668 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2670 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2672 *lpPos
= infoPtr
->currIconPos
;
2674 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2675 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2677 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2678 infoPtr
->currIconPos
.y
= 0;
2684 * Moves an icon to the specified position.
2685 * It takes care of invalidating the item, etc.
2688 * [I] infoPtr : valid pointer to the listview structure
2689 * [I] nItem : the item to move
2690 * [I] lpPos : the new icon position
2691 * [I] isNew : flags the item as being new
2697 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2703 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2704 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2706 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2707 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2710 /* Allocating a POINTER for every item is too resource intensive,
2711 * so we'll keep the (x,y) in different arrays */
2712 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2713 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2715 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2722 * Arranges listview items in icon display mode.
2725 * [I] infoPtr : valid pointer to the listview structure
2726 * [I] nAlignCode : alignment code
2732 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2734 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2738 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2740 TRACE("nAlignCode=%d\n", nAlignCode
);
2742 if (nAlignCode
== LVA_DEFAULT
)
2744 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2745 else nAlignCode
= LVA_ALIGNTOP
;
2750 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2751 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2752 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2753 default: return FALSE
;
2756 infoPtr
->bAutoarrange
= TRUE
;
2757 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2758 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2760 next_pos(infoPtr
, &pos
);
2761 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2769 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2770 * For LVS_REPORT always returns empty rectangle.
2773 * [I] infoPtr : valid pointer to the listview structure
2774 * [O] lprcView : bounding rectangle
2780 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2784 SetRectEmpty(lprcView
);
2786 switch (infoPtr
->uView
)
2789 case LV_VIEW_SMALLICON
:
2790 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2792 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2793 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2794 lprcView
->right
= max(lprcView
->right
, x
);
2795 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2797 if (infoPtr
->nItemCount
> 0)
2799 lprcView
->right
+= infoPtr
->nItemWidth
;
2800 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2805 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2806 x
= infoPtr
->nItemCount
/ y
;
2807 if (infoPtr
->nItemCount
% y
) x
++;
2808 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2809 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2816 * Retrieves the bounding rectangle of all the items.
2819 * [I] infoPtr : valid pointer to the listview structure
2820 * [O] lprcView : bounding rectangle
2826 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2830 TRACE("(lprcView=%p)\n", lprcView
);
2832 if (!lprcView
) return FALSE
;
2834 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2836 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2838 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2839 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2842 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2849 * Retrieves the subitem pointer associated with the subitem index.
2852 * [I] hdpaSubItems : DPA handle for a specific item
2853 * [I] nSubItem : index of subitem
2856 * SUCCESS : subitem pointer
2859 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2861 SUBITEM_INFO
*lpSubItem
;
2864 /* we should binary search here if need be */
2865 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2867 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2868 if (lpSubItem
->iSubItem
== nSubItem
)
2878 * Calculates the desired item width.
2881 * [I] infoPtr : valid pointer to the listview structure
2884 * The desired item width.
2886 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2890 TRACE("uView=%d\n", infoPtr
->uView
);
2892 if (infoPtr
->uView
== LV_VIEW_ICON
)
2893 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2894 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2896 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2901 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2902 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2904 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2905 nItemWidth
= rcHeader
.right
;
2908 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2910 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2914 lvItem
.mask
= LVIF_TEXT
;
2915 lvItem
.iSubItem
= 0;
2917 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2920 lvItem
.pszText
= szDispText
;
2921 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2922 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2923 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2927 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2928 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2930 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2938 * Calculates the desired item height.
2941 * [I] infoPtr : valid pointer to the listview structure
2944 * The desired item height.
2946 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2950 TRACE("uView=%d\n", infoPtr
->uView
);
2952 if (infoPtr
->uView
== LV_VIEW_ICON
)
2953 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2956 nItemHeight
= infoPtr
->ntmHeight
;
2957 if (infoPtr
->himlState
)
2958 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2959 if (infoPtr
->himlSmall
)
2960 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2961 nItemHeight
+= HEIGHT_PADDING
;
2962 if (infoPtr
->nMeasureItemHeight
> 0)
2963 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2966 return max(nItemHeight
, 1);
2971 * Updates the width, and height of an item.
2974 * [I] infoPtr : valid pointer to the listview structure
2979 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2981 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2982 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
2988 * Retrieves and saves important text metrics info for the current
2992 * [I] infoPtr : valid pointer to the listview structure
2995 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
2997 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2998 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2999 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3003 if (GetTextMetricsW(hdc
, &tm
))
3005 infoPtr
->ntmHeight
= tm
.tmHeight
;
3006 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3009 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3010 infoPtr
->nEllipsisWidth
= sz
.cx
;
3012 SelectObject(hdc
, hOldFont
);
3013 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3015 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3020 * A compare function for ranges
3023 * [I] range1 : pointer to range 1;
3024 * [I] range2 : pointer to range 2;
3028 * > 0 : if range 1 > range 2
3029 * < 0 : if range 2 > range 1
3030 * = 0 : if range intersects range 2
3032 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3036 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3038 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3043 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3048 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3050 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3055 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3057 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3058 ranges_dump(ranges
);
3059 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3061 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3062 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3063 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3065 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3066 assert (prev
->upper
<= curr
->lower
);
3067 assert (curr
->lower
< curr
->upper
);
3071 TRACE("--- Done checking---\n");
3074 static RANGES
ranges_create(int count
)
3076 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3077 if (!ranges
) return NULL
;
3078 ranges
->hdpa
= DPA_Create(count
);
3079 if (ranges
->hdpa
) return ranges
;
3084 static void ranges_clear(RANGES ranges
)
3088 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3089 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3090 DPA_DeleteAllPtrs(ranges
->hdpa
);
3094 static void ranges_destroy(RANGES ranges
)
3096 if (!ranges
) return;
3097 ranges_clear(ranges
);
3098 DPA_Destroy(ranges
->hdpa
);
3102 static RANGES
ranges_clone(RANGES ranges
)
3107 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3109 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3111 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3112 if (!newrng
) goto fail
;
3113 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3114 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
3119 TRACE ("clone failed\n");
3120 ranges_destroy(clone
);
3124 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3128 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3129 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3134 static void ranges_dump(RANGES ranges
)
3138 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3139 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3142 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3144 RANGE srchrng
= { nItem
, nItem
+ 1 };
3146 TRACE("(nItem=%d)\n", nItem
);
3147 ranges_check(ranges
, "before contain");
3148 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3151 static INT
ranges_itemcount(RANGES ranges
)
3155 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3157 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3158 count
+= sel
->upper
- sel
->lower
;
3164 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3166 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3169 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3170 if (index
== -1) return TRUE
;
3172 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3174 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3175 if (chkrng
->lower
>= nItem
)
3176 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3177 if (chkrng
->upper
> nItem
)
3178 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3183 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3188 TRACE("(%s)\n", debugrange(&range
));
3189 ranges_check(ranges
, "before add");
3191 /* try find overlapping regions first */
3192 srchrgn
.lower
= range
.lower
- 1;
3193 srchrgn
.upper
= range
.upper
+ 1;
3194 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3200 TRACE("Adding new range\n");
3202 /* create the brand new range to insert */
3203 newrgn
= Alloc(sizeof(RANGE
));
3204 if(!newrgn
) goto fail
;
3207 /* figure out where to insert it */
3208 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3209 TRACE("index=%d\n", index
);
3210 if (index
== -1) index
= 0;
3212 /* and get it over with */
3213 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3221 RANGE
*chkrgn
, *mrgrgn
;
3222 INT fromindex
, mergeindex
;
3224 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3225 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3227 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3228 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3230 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3232 /* merge now common ranges */
3234 srchrgn
.lower
= chkrgn
->lower
- 1;
3235 srchrgn
.upper
= chkrgn
->upper
+ 1;
3239 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3240 if (mergeindex
== -1) break;
3241 if (mergeindex
== index
)
3243 fromindex
= index
+ 1;
3247 TRACE("Merge with index %i\n", mergeindex
);
3249 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3250 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3251 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3253 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3254 if (mergeindex
< index
) index
--;
3258 ranges_check(ranges
, "after add");
3262 ranges_check(ranges
, "failed add");
3266 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3271 TRACE("(%s)\n", debugrange(&range
));
3272 ranges_check(ranges
, "before del");
3274 /* we don't use DPAS_SORTED here, since we need *
3275 * to find the first overlapping range */
3276 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3279 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3281 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3283 /* case 1: Same range */
3284 if ( (chkrgn
->upper
== range
.upper
) &&
3285 (chkrgn
->lower
== range
.lower
) )
3287 DPA_DeletePtr(ranges
->hdpa
, index
);
3291 /* case 2: engulf */
3292 else if ( (chkrgn
->upper
<= range
.upper
) &&
3293 (chkrgn
->lower
>= range
.lower
) )
3295 DPA_DeletePtr(ranges
->hdpa
, index
);
3298 /* case 3: overlap upper */
3299 else if ( (chkrgn
->upper
<= range
.upper
) &&
3300 (chkrgn
->lower
< range
.lower
) )
3302 chkrgn
->upper
= range
.lower
;
3304 /* case 4: overlap lower */
3305 else if ( (chkrgn
->upper
> range
.upper
) &&
3306 (chkrgn
->lower
>= range
.lower
) )
3308 chkrgn
->lower
= range
.upper
;
3311 /* case 5: fully internal */
3316 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3317 newrgn
->lower
= chkrgn
->lower
;
3318 newrgn
->upper
= range
.lower
;
3319 chkrgn
->lower
= range
.upper
;
3320 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3328 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3331 ranges_check(ranges
, "after del");
3335 ranges_check(ranges
, "failed del");
3341 * Removes all selection ranges
3344 * [I] infoPtr : valid pointer to the listview structure
3345 * [I] toSkip : item range to skip removing the selection
3351 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3360 lvItem
.stateMask
= LVIS_SELECTED
;
3362 /* need to clone the DPA because callbacks can change it */
3363 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3364 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3365 while(iterator_next(&i
))
3366 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3367 /* note that the iterator destructor will free the cloned range */
3368 iterator_destroy(&i
);
3373 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3377 if (!(toSkip
= ranges_create(1))) return FALSE
;
3378 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3379 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3380 ranges_destroy(toSkip
);
3384 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3386 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3391 * Retrieves the number of items that are marked as selected.
3394 * [I] infoPtr : valid pointer to the listview structure
3397 * Number of items selected.
3399 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3401 INT nSelectedCount
= 0;
3403 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3406 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3408 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3413 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3415 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3416 return nSelectedCount
;
3421 * Manages the item focus.
3424 * [I] infoPtr : valid pointer to the listview structure
3425 * [I] nItem : item index
3428 * TRUE : focused item changed
3429 * FALSE : focused item has NOT changed
3431 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3433 INT oldFocus
= infoPtr
->nFocusedItem
;
3436 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3438 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3439 lvItem
.stateMask
= LVIS_FOCUSED
;
3440 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3442 return oldFocus
!= infoPtr
->nFocusedItem
;
3445 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3447 if (nShiftItem
< nItem
) return nShiftItem
;
3449 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3451 if (direction
> 0) return nShiftItem
+ direction
;
3453 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3456 /* This function updates focus index.
3459 focus : current focus index
3460 item : index of item to be added/removed
3461 direction : add/remove flag
3463 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3465 BOOL old_change
= infoPtr
->bDoChangeNotify
;
3467 infoPtr
->bDoChangeNotify
= FALSE
;
3468 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3469 if (focus
!= infoPtr
->nFocusedItem
)
3470 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3471 infoPtr
->bDoChangeNotify
= old_change
;
3476 * Updates the various indices after an item has been inserted or deleted.
3479 * [I] infoPtr : valid pointer to the listview structure
3480 * [I] nItem : item index
3481 * [I] direction : Direction of shift, +1 or -1.
3486 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3488 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3490 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3491 assert(abs(direction
) == 1);
3492 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3494 /* But we are not supposed to modify nHotItem! */
3499 * Adds a block of selections.
3502 * [I] infoPtr : valid pointer to the listview structure
3503 * [I] nItem : item index
3506 * Whether the window is still valid.
3508 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3510 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3511 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3512 HWND hwndSelf
= infoPtr
->hwndSelf
;
3513 NMLVODSTATECHANGE nmlv
;
3518 /* Temporarily disable change notification
3519 * If the control is LVS_OWNERDATA, we need to send
3520 * only one LVN_ODSTATECHANGED notification.
3521 * See MSDN documentation for LVN_ITEMCHANGED.
3523 bOldChange
= infoPtr
->bDoChangeNotify
;
3524 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3526 if (nFirst
== -1) nFirst
= nItem
;
3528 item
.state
= LVIS_SELECTED
;
3529 item
.stateMask
= LVIS_SELECTED
;
3531 for (i
= nFirst
; i
<= nLast
; i
++)
3532 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3534 ZeroMemory(&nmlv
, sizeof(nmlv
));
3535 nmlv
.iFrom
= nFirst
;
3538 nmlv
.uNewState
= item
.state
;
3540 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3541 if (!IsWindow(hwndSelf
))
3543 infoPtr
->bDoChangeNotify
= bOldChange
;
3550 * Sets a single group selection.
3553 * [I] infoPtr : valid pointer to the listview structure
3554 * [I] nItem : item index
3559 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3566 if (!(selection
= ranges_create(100))) return;
3568 item
.state
= LVIS_SELECTED
;
3569 item
.stateMask
= LVIS_SELECTED
;
3571 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3573 if (infoPtr
->nSelectionMark
== -1)
3575 infoPtr
->nSelectionMark
= nItem
;
3576 ranges_additem(selection
, nItem
);
3582 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3583 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3584 ranges_add(selection
, sel
);
3589 RECT rcItem
, rcSel
, rcSelMark
;
3592 rcItem
.left
= LVIR_BOUNDS
;
3593 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3594 ranges_destroy (selection
);
3597 rcSelMark
.left
= LVIR_BOUNDS
;
3598 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3599 ranges_destroy (selection
);
3602 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3603 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3604 while(iterator_next(&i
))
3606 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3607 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3609 iterator_destroy(&i
);
3612 /* disable per item notifications on LVS_OWNERDATA style
3613 FIXME: single LVN_ODSTATECHANGED should be used */
3614 bOldChange
= infoPtr
->bDoChangeNotify
;
3615 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3617 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3620 iterator_rangesitems(&i
, selection
);
3621 while(iterator_next(&i
))
3622 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3623 /* this will also destroy the selection */
3624 iterator_destroy(&i
);
3626 infoPtr
->bDoChangeNotify
= bOldChange
;
3628 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3633 * Sets a single selection.
3636 * [I] infoPtr : valid pointer to the listview structure
3637 * [I] nItem : item index
3642 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3646 TRACE("nItem=%d\n", nItem
);
3648 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3650 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3651 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3652 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3654 infoPtr
->nSelectionMark
= nItem
;
3659 * Set selection(s) with keyboard.
3662 * [I] infoPtr : valid pointer to the listview structure
3663 * [I] nItem : item index
3664 * [I] space : VK_SPACE code sent
3667 * SUCCESS : TRUE (needs to be repainted)
3668 * FAILURE : FALSE (nothing has changed)
3670 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3672 /* FIXME: pass in the state */
3673 WORD wShift
= GetKeyState(VK_SHIFT
) & 0x8000;
3674 WORD wCtrl
= GetKeyState(VK_CONTROL
) & 0x8000;
3675 BOOL bResult
= FALSE
;
3677 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3678 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3682 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3683 LISTVIEW_SetSelection(infoPtr
, nItem
);
3687 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3691 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3692 lvItem
.stateMask
= LVIS_SELECTED
;
3695 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3696 if (lvItem
.state
& LVIS_SELECTED
)
3697 infoPtr
->nSelectionMark
= nItem
;
3699 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3702 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3705 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3709 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3711 LVHITTESTINFO lvHitTestInfo
;
3713 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3714 lvHitTestInfo
.pt
.x
= pt
.x
;
3715 lvHitTestInfo
.pt
.y
= pt
.y
;
3717 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3719 lpLVItem
->mask
= LVIF_PARAM
;
3720 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3721 lpLVItem
->iSubItem
= 0;
3723 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3726 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3728 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3729 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3730 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3735 * Called when the mouse is being actively tracked and has hovered for a specified
3739 * [I] infoPtr : valid pointer to the listview structure
3740 * [I] fwKeys : key indicator
3741 * [I] x,y : mouse position
3744 * 0 if the message was processed, non-zero if there was an error
3747 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3748 * over the item for a certain period of time.
3751 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3755 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3757 if (LISTVIEW_IsHotTracking(infoPtr
))
3765 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3766 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3768 SetFocus(infoPtr
->hwndSelf
);
3774 #define SCROLL_LEFT 0x1
3775 #define SCROLL_RIGHT 0x2
3776 #define SCROLL_UP 0x4
3777 #define SCROLL_DOWN 0x8
3781 * Utility routine to draw and highlight items within a marquee selection rectangle.
3784 * [I] infoPtr : valid pointer to the listview structure
3785 * [I] coords_orig : original co-ordinates of the cursor
3786 * [I] coords_offs : offsetted coordinates of the cursor
3787 * [I] offset : offset amount
3788 * [I] scroll : Bitmask of which directions we should scroll, if at all
3793 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3794 const POINT
*coords_offs
, const POINT
*offset
,
3797 BOOL controlDown
= FALSE
;
3799 ITERATOR old_elems
, new_elems
;
3802 if (coords_offs
->x
> infoPtr
->marqueeOrigin
.x
)
3804 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3805 rect
.right
= coords_offs
->x
;
3809 rect
.left
= coords_offs
->x
;
3810 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3813 if (coords_offs
->y
> infoPtr
->marqueeOrigin
.y
)
3815 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3816 rect
.bottom
= coords_offs
->y
;
3820 rect
.top
= coords_offs
->y
;
3821 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3824 /* Cancel out the old marquee rectangle and draw the new one */
3825 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3827 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3828 the cursor is further away */
3830 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3831 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3833 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3834 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3836 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3837 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3839 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3840 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3842 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3844 CopyRect(&infoPtr
->marqueeRect
, &rect
);
3846 CopyRect(&infoPtr
->marqueeDrawRect
, &rect
);
3847 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
->x
, offset
->y
);
3849 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3850 iterator_remove_common_items(&old_elems
, &new_elems
);
3852 /* Iterate over no longer selected items */
3853 while (iterator_next(&old_elems
))
3855 if (old_elems
.nItem
> -1)
3857 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3860 item
.state
= LVIS_SELECTED
;
3862 item
.stateMask
= LVIS_SELECTED
;
3864 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3867 iterator_destroy(&old_elems
);
3870 /* Iterate over newly selected items */
3871 if (GetKeyState(VK_CONTROL
) & 0x8000)
3874 while (iterator_next(&new_elems
))
3876 if (new_elems
.nItem
> -1)
3878 /* If CTRL is pressed, invert. If not, always select the item. */
3879 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3882 item
.state
= LVIS_SELECTED
;
3884 item
.stateMask
= LVIS_SELECTED
;
3886 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3889 iterator_destroy(&new_elems
);
3891 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3896 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3897 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3900 * [I] hwnd : Handle to the listview
3901 * [I] uMsg : WM_TIMER (ignored)
3902 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3903 * [I] dwTimer : The elapsed time (ignored)
3908 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3910 LISTVIEW_INFO
*infoPtr
;
3911 SCROLLINFO scrollInfo
;
3917 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3922 /* Get the current cursor position and convert to client coordinates */
3923 GetCursorPos(&coords_orig
);
3924 ScreenToClient(hWnd
, &coords_orig
);
3926 /* Ensure coordinates are within client bounds */
3927 coords_offs
.x
= max(min(coords_orig
.x
, infoPtr
->rcList
.right
), 0);
3928 coords_offs
.y
= max(min(coords_orig
.y
, infoPtr
->rcList
.bottom
), 0);
3931 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3933 /* Offset coordinates by the appropriate amount */
3934 coords_offs
.x
-= offset
.x
;
3935 coords_offs
.y
-= offset
.y
;
3937 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3938 scrollInfo
.fMask
= SIF_ALL
;
3940 /* Work out in which directions we can scroll */
3941 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3943 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3944 scroll
|= SCROLL_UP
;
3946 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3947 scroll
|= SCROLL_DOWN
;
3950 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3952 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3953 scroll
|= SCROLL_LEFT
;
3955 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3956 scroll
|= SCROLL_RIGHT
;
3959 if (((coords_orig
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
3960 ((coords_orig
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
3961 ((coords_orig
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
3962 ((coords_orig
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
3964 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, scroll
);
3970 * Called whenever WM_MOUSEMOVE is received.
3973 * [I] infoPtr : valid pointer to the listview structure
3974 * [I] fwKeys : key indicator
3975 * [I] x,y : mouse position
3978 * 0 if the message is processed, non-zero if there was an error
3980 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3986 if (!(fwKeys
& MK_LBUTTON
))
3987 infoPtr
->bLButtonDown
= FALSE
;
3989 if (infoPtr
->bLButtonDown
)
3991 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
3992 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
3994 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
3997 if (infoPtr
->bLButtonDown
)
3999 if (infoPtr
->bMarqueeSelect
)
4009 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4011 /* Ensure coordinates are within client bounds */
4012 coords_offs
.x
= max(min(x
, infoPtr
->rcList
.right
), 0);
4013 coords_offs
.y
= max(min(y
, infoPtr
->rcList
.bottom
), 0);
4015 /* Offset coordinates by the appropriate amount */
4016 coords_offs
.x
-= offset
.x
;
4017 coords_offs
.y
-= offset
.y
;
4019 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4020 move the mouse again */
4022 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4023 (y
>= infoPtr
->rcList
.bottom
))
4025 if (!infoPtr
->bScrolling
)
4027 infoPtr
->bScrolling
= TRUE
;
4028 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4033 infoPtr
->bScrolling
= FALSE
;
4034 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4037 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, 0);
4045 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4047 /* reset item marker */
4048 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4049 infoPtr
->nLButtonDownItem
= -1;
4051 if (!PtInRect(&rect
, pt
))
4053 /* this path covers the following:
4054 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4055 2. change focus with keys
4056 3. move mouse over item from step 1 selects it and moves focus on it */
4057 if (infoPtr
->nLButtonDownItem
!= -1 &&
4058 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4062 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4063 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4065 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4066 infoPtr
->nLButtonDownItem
= -1;
4069 if (!infoPtr
->bDragging
)
4071 ht
.pt
= infoPtr
->ptClickPos
;
4072 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4074 /* If the click is outside the range of an item, begin a
4075 highlight. If not, begin an item drag. */
4080 /* If we're allowing multiple selections, send notification.
4081 If return value is non-zero, cancel. */
4082 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4084 /* Store the absolute coordinates of the click */
4086 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4088 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4089 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4091 /* Begin selection and capture mouse */
4092 infoPtr
->bMarqueeSelect
= TRUE
;
4093 SetCapture(infoPtr
->hwndSelf
);
4100 ZeroMemory(&nmlv
, sizeof(nmlv
));
4101 nmlv
.iItem
= ht
.iItem
;
4102 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4104 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4105 infoPtr
->bDragging
= TRUE
;
4113 /* see if we are supposed to be tracking mouse hovering */
4114 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4115 TRACKMOUSEEVENT trackinfo
;
4117 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4118 trackinfo
.dwFlags
= TME_QUERY
;
4120 /* see if we are already tracking this hwnd */
4121 _TrackMouseEvent(&trackinfo
);
4123 if(!(trackinfo
.dwFlags
& TME_HOVER
) || trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4124 trackinfo
.dwFlags
= TME_HOVER
;
4125 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4126 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4128 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4129 _TrackMouseEvent(&trackinfo
);
4138 * Tests whether the item is assignable to a list with style lStyle
4140 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4142 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4143 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4144 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4152 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4155 * [I] infoPtr : valid pointer to the listview structure
4156 * [I] lpLVItem : valid pointer to new item attributes
4157 * [I] isNew : the item being set is being inserted
4158 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4159 * [O] bChanged : will be set to TRUE if the item really changed
4165 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4171 /* stateMask is ignored for LVM_INSERTITEM */
4172 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4176 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4178 if (lpLVItem
->mask
== 0) return TRUE
;
4180 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4182 /* a virtual listview only stores selection and focus */
4183 if (lpLVItem
->mask
& ~LVIF_STATE
)
4189 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4190 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4194 /* we need to get the lParam and state of the item */
4195 item
.iItem
= lpLVItem
->iItem
;
4196 item
.iSubItem
= lpLVItem
->iSubItem
;
4197 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4198 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4202 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4204 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4205 /* determine what fields will change */
4206 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4207 uChanged
|= LVIF_STATE
;
4209 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4210 uChanged
|= LVIF_IMAGE
;
4212 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4213 uChanged
|= LVIF_PARAM
;
4215 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4216 uChanged
|= LVIF_INDENT
;
4218 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4219 uChanged
|= LVIF_TEXT
;
4221 TRACE("change mask=0x%x\n", uChanged
);
4223 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4224 nmlv
.iItem
= lpLVItem
->iItem
;
4225 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4226 nmlv
.uOldState
= item
.state
;
4227 nmlv
.uChanged
= uChanged
? uChanged
: lpLVItem
->mask
;
4228 nmlv
.lParam
= item
.lParam
;
4230 /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
4231 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4232 are enabled. Even nothing really changed we still need to send this,
4233 in this case uChanged mask is just set to passed item mask. */
4234 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
4236 HWND hwndSelf
= infoPtr
->hwndSelf
;
4238 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4240 if (!IsWindow(hwndSelf
))
4244 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4245 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4246 /* this means we won't hit a focus change path later */
4247 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4249 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4250 infoPtr
->nFocusedItem
++;
4253 if (!uChanged
) return TRUE
;
4256 /* copy information */
4257 if (lpLVItem
->mask
& LVIF_TEXT
)
4258 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4260 if (lpLVItem
->mask
& LVIF_IMAGE
)
4261 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4263 if (lpLVItem
->mask
& LVIF_PARAM
)
4264 lpItem
->lParam
= lpLVItem
->lParam
;
4266 if (lpLVItem
->mask
& LVIF_INDENT
)
4267 lpItem
->iIndent
= lpLVItem
->iIndent
;
4269 if (uChanged
& LVIF_STATE
)
4271 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4273 lpItem
->state
&= ~stateMask
;
4274 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4276 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4278 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4279 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4281 else if (stateMask
& LVIS_SELECTED
)
4283 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4285 /* If we are asked to change focus, and we manage it, do it.
4286 It's important to have all new item data stored at this point,
4287 because changing existing focus could result in a redrawing operation,
4288 which in turn could ask for disp data, application should see all data
4289 for inserted item when processing LVN_GETDISPINFO.
4291 The way this works application will see nested item change notifications -
4292 changed item notifications interrupted by ones from item losing focus. */
4293 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4295 if (lpLVItem
->state
& LVIS_FOCUSED
)
4297 /* update selection mark */
4298 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4299 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4301 if (infoPtr
->nFocusedItem
!= -1)
4303 /* remove current focus */
4304 item
.mask
= LVIF_STATE
;
4306 item
.stateMask
= LVIS_FOCUSED
;
4308 /* recurse with redrawing an item */
4309 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4312 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4313 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4315 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4317 infoPtr
->nFocusedItem
= -1;
4322 /* if we're inserting the item, we're done */
4323 if (isNew
) return TRUE
;
4325 /* send LVN_ITEMCHANGED notification */
4326 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4327 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4334 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4337 * [I] infoPtr : valid pointer to the listview structure
4338 * [I] lpLVItem : valid pointer to new subitem attributes
4339 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4340 * [O] bChanged : will be set to TRUE if the item really changed
4346 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4349 SUBITEM_INFO
*lpSubItem
;
4351 /* we do not support subitems for virtual listviews */
4352 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4354 /* set subitem only if column is present */
4355 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4357 /* First do some sanity checks */
4358 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4359 particularly useful. We currently do not actually do anything with
4360 the flag on subitems.
4362 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4363 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4365 /* get the subitem structure, and create it if not there */
4366 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4367 assert (hdpaSubItems
);
4369 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4372 SUBITEM_INFO
*tmpSubItem
;
4375 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4376 if (!lpSubItem
) return FALSE
;
4377 /* we could binary search here, if need be...*/
4378 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4380 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4381 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4383 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4388 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4389 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4393 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4395 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4399 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4401 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4410 * Sets item attributes.
4413 * [I] infoPtr : valid pointer to the listview structure
4414 * [I] lpLVItem : new item attributes
4415 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4421 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4423 HWND hwndSelf
= infoPtr
->hwndSelf
;
4424 LPWSTR pszText
= NULL
;
4425 BOOL bResult
, bChanged
= FALSE
;
4428 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4430 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4433 /* Store old item area */
4434 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4436 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4437 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4439 pszText
= lpLVItem
->pszText
;
4440 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4443 /* actually set the fields */
4444 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4446 if (lpLVItem
->iSubItem
)
4447 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4449 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4450 if (!IsWindow(hwndSelf
))
4453 /* redraw item, if necessary */
4454 if (bChanged
&& !infoPtr
->bIsDrawing
)
4456 /* this little optimization eliminates some nasty flicker */
4457 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4458 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4459 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4460 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4463 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4464 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4470 textfreeT(lpLVItem
->pszText
, isW
);
4471 lpLVItem
->pszText
= pszText
;
4479 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4482 * [I] infoPtr : valid pointer to the listview structure
4487 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4490 SCROLLINFO scrollInfo
;
4492 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4493 scrollInfo
.fMask
= SIF_POS
;
4495 if (infoPtr
->uView
== LV_VIEW_LIST
)
4497 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4498 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4500 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4502 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4503 nItem
= scrollInfo
.nPos
;
4507 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4508 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4511 TRACE("nItem=%d\n", nItem
);
4519 * Erases the background of the given rectangle
4522 * [I] infoPtr : valid pointer to the listview structure
4523 * [I] hdc : device context handle
4524 * [I] lprcBox : clipping rectangle
4530 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4532 if (!infoPtr
->hBkBrush
) return FALSE
;
4534 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4536 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4544 * [I] infoPtr : valid pointer to the listview structure
4545 * [I] hdc : device context handle
4546 * [I] nItem : item index
4547 * [I] nSubItem : subitem index
4548 * [I] pos : item position in client coordinates
4549 * [I] cdmode : custom draw mode
4555 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, INT nSubItem
, POINT pos
, DWORD cdmode
)
4558 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4559 static WCHAR szCallback
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4560 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4562 RECT rcSelect
, rcBox
, rcIcon
, rcLabel
, rcStateIcon
;
4563 NMLVCUSTOMDRAW nmlvcd
;
4567 TRACE("(hdc=%p, nItem=%d, nSubItem=%d, pos=%s)\n", hdc
, nItem
, nSubItem
, wine_dbgstr_point(&pos
));
4569 /* get information needed for drawing the item */
4570 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
4571 if (nSubItem
== 0) lvItem
.mask
|= LVIF_STATE
;
4572 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4573 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4574 lvItem
.iItem
= nItem
;
4575 lvItem
.iSubItem
= nSubItem
;
4578 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4579 lvItem
.pszText
= szDispText
;
4580 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4581 if (nSubItem
> 0 && (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4582 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4583 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= szCallback
;
4584 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4586 /* now check if we need to update the focus rectangle */
4587 lprcFocus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4589 if (!lprcFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4590 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4591 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4592 OffsetRect(&rcSelect
, pos
.x
, pos
.y
);
4593 OffsetRect(&rcIcon
, pos
.x
, pos
.y
);
4594 OffsetRect(&rcStateIcon
, pos
.x
, pos
.y
);
4595 OffsetRect(&rcLabel
, pos
.x
, pos
.y
);
4596 TRACE(" rcBox=%s, rcSelect=%s, rcIcon=%s. rcLabel=%s\n",
4597 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4598 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4600 /* fill in the custom draw structure */
4601 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4603 if (nSubItem
> 0) cdmode
= infoPtr
->cditemmode
;
4604 if (cdmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4605 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4606 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4607 if (nSubItem
== 0) infoPtr
->cditemmode
= cdsubitemmode
;
4608 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4609 /* we have to send a CDDS_SUBITEM customdraw explicitly for subitem 0 */
4610 if (nSubItem
== 0 && (cdsubitemmode
& CDRF_NOTIFYITEMDRAW
) != 0)
4612 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4613 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4615 if (nSubItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4616 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4617 else if ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) == FALSE
)
4618 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4620 /* FIXME: temporary hack */
4621 rcSelect
.left
= rcLabel
.left
;
4623 /* in icon mode, the label rect is really what we want to draw the
4625 /* in detail mode, we want to paint background for label rect when
4626 * item is not selected or listview has full row select; otherwise paint
4627 * background for text only */
4628 if (infoPtr
->uView
== LV_VIEW_ICON
||
4629 (infoPtr
->uView
== LV_VIEW_DETAILS
&&
4630 (!(lvItem
.state
& LVIS_SELECTED
) ||
4631 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) != 0)))
4634 if (nmlvcd
.clrTextBk
!= CLR_NONE
)
4635 ExtTextOutW(hdc
, rcSelect
.left
, rcSelect
.top
, ETO_OPAQUE
, &rcSelect
, NULL
, 0, NULL
);
4637 if(nSubItem
== 0 && infoPtr
->nFocusedItem
== nItem
)
4639 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4641 /* we have to update left focus bound too if item isn't in leftmost column
4642 and reduce right box bound */
4643 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4647 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4649 INT Originx
= pos
.x
- LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
4650 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4651 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4653 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, index
)->rcHeader
.right
+ Originx
;
4654 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4658 rcSelect
.right
= rcBox
.right
;
4661 /* store new focus rectangle */
4662 infoPtr
->rcFocus
= rcSelect
;
4666 if (infoPtr
->himlState
&& STATEIMAGEINDEX(lvItem
.state
) && (nSubItem
== 0))
4668 UINT uStateImage
= STATEIMAGEINDEX(lvItem
.state
);
4671 TRACE("uStateImage=%d\n", uStateImage
);
4672 ImageList_Draw(infoPtr
->himlState
, uStateImage
- 1, hdc
,
4673 rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4678 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4679 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4683 TRACE("iImage=%d\n", lvItem
.iImage
);
4685 if (lvItem
.state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4686 style
= ILD_SELECTED
;
4690 ImageList_DrawEx(himl
, lvItem
.iImage
, hdc
, rcIcon
.left
, rcIcon
.top
,
4691 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4692 lvItem
.state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4693 style
| (lvItem
.state
& LVIS_OVERLAYMASK
));
4696 /* Don't bother painting item being edited */
4697 if (infoPtr
->hwndEdit
&& nItem
== infoPtr
->nEditLabelItem
&& nSubItem
== 0) goto postpaint
;
4699 /* figure out the text drawing flags */
4700 uFormat
= (infoPtr
->uView
== LV_VIEW_ICON
? (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4701 if (infoPtr
->uView
== LV_VIEW_ICON
)
4702 uFormat
= (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4705 switch (LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4707 case LVCFMT_RIGHT
: uFormat
|= DT_RIGHT
; break;
4708 case LVCFMT_CENTER
: uFormat
|= DT_CENTER
; break;
4709 default: uFormat
|= DT_LEFT
;
4712 if (!(uFormat
& (DT_RIGHT
| DT_CENTER
)))
4714 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4715 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4717 else if (uFormat
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4719 /* for GRIDLINES reduce the bottom so the text formats correctly */
4720 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4724 if ((!(lvItem
.state
& LVIS_SELECTED
) || !infoPtr
->bFocus
) && (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTSHADOWTEXT
))
4725 DrawShadowText(hdc
, lvItem
.pszText
, -1, &rcLabel
, uFormat
, RGB(255, 255, 255), RGB(0, 0, 0), 2, 2);
4728 DrawTextW(hdc
, lvItem
.pszText
, -1, &rcLabel
, uFormat
);
4731 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4732 notify_postpaint(infoPtr
, &nmlvcd
);
4738 * Draws listview items when in owner draw mode.
4741 * [I] infoPtr : valid pointer to the listview structure
4742 * [I] hdc : device context handle
4747 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4749 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4750 DWORD cditemmode
= CDRF_DODEFAULT
;
4751 NMLVCUSTOMDRAW nmlvcd
;
4752 POINT Origin
, Position
;
4758 ZeroMemory(&dis
, sizeof(dis
));
4760 /* Get scroll info once before loop */
4761 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4763 /* iterate through the invalidated rows */
4764 while(iterator_next(i
))
4766 item
.iItem
= i
->nItem
;
4768 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4769 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4770 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4772 dis
.CtlType
= ODT_LISTVIEW
;
4774 dis
.itemID
= item
.iItem
;
4775 dis
.itemAction
= ODA_DRAWENTIRE
;
4777 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4778 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4779 dis
.hwndItem
= infoPtr
->hwndSelf
;
4781 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4782 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4783 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4784 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4785 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4786 dis
.itemData
= item
.lParam
;
4788 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4791 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4792 * structure for the rest. of the paint cycle
4794 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4795 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4796 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4798 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4800 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4801 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4804 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4805 notify_postpaint(infoPtr
, &nmlvcd
);
4811 * Draws listview items when in report display mode.
4814 * [I] infoPtr : valid pointer to the listview structure
4815 * [I] hdc : device context handle
4816 * [I] cdmode : custom draw mode
4821 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4824 RECT rcClip
, rcItem
;
4825 POINT Origin
, Position
;
4832 /* figure out what to draw */
4833 rgntype
= GetClipBox(hdc
, &rcClip
);
4834 if (rgntype
== NULLREGION
) return;
4836 /* Get scroll info once before loop */
4837 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4839 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4841 /* narrow down the columns we need to paint */
4842 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4844 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4846 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4847 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4848 ranges_additem(colRanges
, index
);
4850 iterator_rangesitems(&j
, colRanges
);
4852 /* in full row select, we _have_ to draw the main item */
4853 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4856 /* iterate through the invalidated rows */
4857 while(iterator_next(i
))
4859 SelectObject(hdc
, infoPtr
->hFont
);
4860 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4861 Position
.y
+= Origin
.y
;
4863 /* iterate through the invalidated columns */
4864 while(iterator_next(&j
))
4866 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4867 Position
.x
= (j
.nItem
== 0) ? rcItem
.left
+ Origin
.x
: Origin
.x
;
4869 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4872 rcItem
.bottom
= infoPtr
->nItemHeight
;
4873 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4874 if (!RectVisible(hdc
, &rcItem
)) continue;
4877 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, j
.nItem
, Position
, cdmode
);
4880 iterator_destroy(&j
);
4885 * Draws the gridlines if necessary when in report display mode.
4888 * [I] infoPtr : valid pointer to the listview structure
4889 * [I] hdc : device context handle
4894 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
4900 RECT rcClip
, rcItem
= {0};
4908 /* figure out what to draw */
4909 rgntype
= GetClipBox(hdc
, &rcClip
);
4910 if (rgntype
== NULLREGION
) return;
4912 /* Get scroll info once before loop */
4913 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4915 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4917 /* narrow down the columns we need to paint */
4918 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4920 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4922 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4923 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4924 ranges_additem(colRanges
, index
);
4927 /* is right most vertical line visible? */
4928 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4930 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4931 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4932 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
4935 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
4937 hOldPen
= SelectObject ( hdc
, hPen
);
4939 /* draw the vertical lines for the columns */
4940 iterator_rangesitems(&j
, colRanges
);
4941 while(iterator_next(&j
))
4943 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4944 if (rcItem
.left
== 0) continue; /* skip leftmost column */
4945 rcItem
.left
+= Origin
.x
;
4946 rcItem
.right
+= Origin
.x
;
4947 rcItem
.top
= infoPtr
->rcList
.top
;
4948 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
4949 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
4950 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4951 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
4953 iterator_destroy(&j
);
4954 /* draw rightmost grid line if visible */
4957 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4958 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4959 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4961 rcItem
.right
+= Origin
.x
;
4963 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
4964 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
4967 /* draw the horizontal lines for the rows */
4968 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
4969 rcItem
.left
= infoPtr
->rcList
.left
;
4970 rcItem
.right
= infoPtr
->rcList
.right
;
4971 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
4973 rcItem
.bottom
= rcItem
.top
= y
;
4974 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
4975 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4976 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
4979 SelectObject( hdc
, hOldPen
);
4980 DeleteObject( hPen
);
4983 ranges_destroy(colRanges
);
4988 * Draws listview items when in list display mode.
4991 * [I] infoPtr : valid pointer to the listview structure
4992 * [I] hdc : device context handle
4993 * [I] cdmode : custom draw mode
4998 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5000 POINT Origin
, Position
;
5002 /* Get scroll info once before loop */
5003 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5005 while(iterator_prev(i
))
5007 SelectObject(hdc
, infoPtr
->hFont
);
5008 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5009 Position
.x
+= Origin
.x
;
5010 Position
.y
+= Origin
.y
;
5012 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, 0, Position
, cdmode
);
5019 * Draws listview items.
5022 * [I] infoPtr : valid pointer to the listview structure
5023 * [I] hdc : device context handle
5024 * [I] prcErase : rect to be erased before refresh (may be NULL)
5029 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5031 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5032 NMLVCUSTOMDRAW nmlvcd
;
5039 HBITMAP hbmp
= NULL
;
5042 LISTVIEW_DUMP(infoPtr
);
5044 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5045 TRACE("double buffering\n");
5047 hdc
= CreateCompatibleDC(hdcOrig
);
5049 ERR("Failed to create DC for backbuffer\n");
5052 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5053 infoPtr
->rcList
.bottom
);
5055 ERR("Failed to create bitmap for backbuffer\n");
5060 SelectObject(hdc
, hbmp
);
5061 SelectObject(hdc
, infoPtr
->hFont
);
5063 if(GetClipBox(hdcOrig
, &rcClient
))
5064 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5066 /* Save dc values we're gonna trash while drawing
5067 * FIXME: Should be done in LISTVIEW_DrawItem() */
5068 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5069 oldBkMode
= GetBkMode(hdc
);
5070 oldBkColor
= GetBkColor(hdc
);
5071 oldTextColor
= GetTextColor(hdc
);
5074 infoPtr
->bIsDrawing
= TRUE
;
5077 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5078 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5079 /* If no erasing was done (usually because RedrawWindow was called
5080 * with RDW_INVALIDATE only) we need to copy the old contents into
5081 * the backbuffer before continuing. */
5082 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5083 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5084 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5085 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5088 infoPtr
->cditemmode
= CDRF_DODEFAULT
;
5090 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5091 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5092 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5093 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5095 /* nothing to draw */
5096 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5098 /* figure out what we need to draw */
5099 iterator_visibleitems(&i
, infoPtr
, hdc
);
5100 range
= iterator_range(&i
);
5102 /* send cache hint notification */
5103 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5107 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5108 nmlv
.iFrom
= range
.lower
;
5109 nmlv
.iTo
= range
.upper
- 1;
5110 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5113 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5114 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5117 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5118 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5119 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5120 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5122 /* if we have a focus rect and it's visible, draw it */
5123 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5124 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5125 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5127 iterator_destroy(&i
);
5130 /* For LVS_EX_GRIDLINES go and draw lines */
5131 /* This includes the case where there were *no* items */
5132 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5133 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5135 /* Draw marquee rectangle if appropriate */
5136 if (infoPtr
->bMarqueeSelect
)
5138 SetBkColor(hdc
, RGB(255, 255, 255));
5139 SetTextColor(hdc
, RGB(0, 0, 0));
5140 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5143 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5144 notify_postpaint(infoPtr
, &nmlvcd
);
5147 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5148 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5149 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5150 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5155 SelectObject(hdc
, hOldFont
);
5156 SetBkMode(hdc
, oldBkMode
);
5157 SetBkColor(hdc
, oldBkColor
);
5158 SetTextColor(hdc
, oldTextColor
);
5161 infoPtr
->bIsDrawing
= FALSE
;
5167 * Calculates the approximate width and height of a given number of items.
5170 * [I] infoPtr : valid pointer to the listview structure
5171 * [I] nItemCount : number of items
5172 * [I] wWidth : width
5173 * [I] wHeight : height
5176 * Returns a DWORD. The width in the low word and the height in high word.
5178 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5179 WORD wWidth
, WORD wHeight
)
5181 DWORD dwViewRect
= 0;
5183 if (nItemCount
== -1)
5184 nItemCount
= infoPtr
->nItemCount
;
5186 if (infoPtr
->uView
== LV_VIEW_LIST
)
5188 INT nItemCountPerColumn
= 1;
5189 INT nColumnCount
= 0;
5191 if (wHeight
== 0xFFFF)
5193 /* use current height */
5194 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5197 if (wHeight
< infoPtr
->nItemHeight
)
5198 wHeight
= infoPtr
->nItemHeight
;
5202 if (infoPtr
->nItemHeight
> 0)
5204 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5205 if (nItemCountPerColumn
== 0)
5206 nItemCountPerColumn
= 1;
5208 if (nItemCount
% nItemCountPerColumn
!= 0)
5209 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5211 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5215 /* Microsoft padding magic */
5216 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5217 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5219 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5221 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5225 if (infoPtr
->nItemCount
> 0)
5227 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5228 wWidth
= rcBox
.right
- rcBox
.left
;
5229 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5233 /* use current height and width */
5234 if (wHeight
== 0xffff)
5235 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5236 if (wWidth
== 0xffff)
5237 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5240 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5242 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5248 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5249 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5251 if (wWidth
== 0xffff)
5252 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5254 if (wWidth
< nItemWidth
)
5255 wWidth
= nItemWidth
;
5257 cols
= wWidth
/ nItemWidth
;
5258 if (cols
> nItemCount
)
5265 rows
= nItemCount
/ cols
;
5266 if (nItemCount
% cols
)
5272 wHeight
= (nItemHeight
* rows
)+2;
5273 wWidth
= (nItemWidth
* cols
)+2;
5275 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5277 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5278 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5285 * Cancel edit label with saving item text.
5288 * [I] infoPtr : valid pointer to the listview structure
5291 * Always returns TRUE.
5293 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5295 if (infoPtr
->hwndEdit
)
5297 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5298 HWND edit
= infoPtr
->hwndEdit
;
5300 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5301 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5309 * Create a drag image list for the specified item.
5312 * [I] infoPtr : valid pointer to the listview structure
5313 * [I] iItem : index of item
5314 * [O] lppt : Upper-left corner of the image
5317 * Returns a handle to the image list if successful, NULL otherwise.
5319 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5325 HBITMAP hbmp
, hOldbmp
;
5327 HIMAGELIST dragList
= 0;
5328 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5330 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5333 rcItem
.left
= LVIR_BOUNDS
;
5334 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5337 lppt
->x
= rcItem
.left
;
5338 lppt
->y
= rcItem
.top
;
5340 size
.cx
= rcItem
.right
- rcItem
.left
;
5341 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5343 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5344 hdc
= CreateCompatibleDC(hdcOrig
);
5345 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5346 hOldbmp
= SelectObject(hdc
, hbmp
);
5347 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5349 rcItem
.left
= rcItem
.top
= 0;
5350 rcItem
.right
= size
.cx
;
5351 rcItem
.bottom
= size
.cy
;
5352 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5355 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, 0, pos
, infoPtr
->cditemmode
))
5357 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5358 SelectObject(hdc
, hOldbmp
);
5359 ImageList_Add(dragList
, hbmp
, 0);
5362 SelectObject(hdc
, hOldbmp
);
5364 SelectObject(hdc
, hOldFont
);
5367 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5369 TRACE("ret=%p\n", dragList
);
5377 * Removes all listview items and subitems.
5380 * [I] infoPtr : valid pointer to the listview structure
5386 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5388 HDPA hdpaSubItems
= NULL
;
5389 BOOL suppress
= FALSE
;
5397 /* we do it directly, to avoid notifications */
5398 ranges_clear(infoPtr
->selectionRanges
);
5399 infoPtr
->nSelectionMark
= -1;
5400 infoPtr
->nFocusedItem
= -1;
5401 SetRectEmpty(&infoPtr
->rcFocus
);
5402 /* But we are supposed to leave nHotItem as is! */
5404 /* send LVN_DELETEALLITEMS notification */
5405 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) || !destroy
)
5409 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
5411 suppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5414 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5416 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5418 /* send LVN_DELETEITEM notification, if not suppressed
5419 and if it is not a virtual listview */
5420 if (!suppress
) notify_deleteitem(infoPtr
, i
);
5421 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5422 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5423 /* free id struct */
5424 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5425 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5426 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5428 /* both item and subitem start with ITEMHDR header */
5429 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5431 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5432 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5435 DPA_Destroy(hdpaSubItems
);
5436 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5438 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5439 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5440 infoPtr
->nItemCount
--;
5445 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5446 LISTVIEW_UpdateScroll(infoPtr
);
5448 LISTVIEW_InvalidateList(infoPtr
);
5455 * Scrolls, and updates the columns, when a column is changing width.
5458 * [I] infoPtr : valid pointer to the listview structure
5459 * [I] nColumn : column to scroll
5460 * [I] dx : amount of scroll, in pixels
5465 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5467 COLUMN_INFO
*lpColumnInfo
;
5473 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5474 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5475 rcCol
= lpColumnInfo
->rcHeader
;
5476 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5477 rcCol
.left
= rcCol
.right
;
5479 /* adjust the other columns */
5480 hdi
.mask
= HDI_ORDER
;
5481 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5483 INT nOrder
= hdi
.iOrder
;
5484 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5486 hdi
.mask
= HDI_ORDER
;
5487 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5488 if (hdi
.iOrder
>= nOrder
) {
5489 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5490 lpColumnInfo
->rcHeader
.left
+= dx
;
5491 lpColumnInfo
->rcHeader
.right
+= dx
;
5496 /* do not update screen if not in report mode */
5497 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5499 /* Need to reset the item width when inserting a new column */
5500 infoPtr
->nItemWidth
+= dx
;
5502 LISTVIEW_UpdateScroll(infoPtr
);
5503 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5505 /* scroll to cover the deleted column, and invalidate for redraw */
5506 rcOld
= infoPtr
->rcList
;
5507 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5508 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5513 * Removes a column from the listview control.
5516 * [I] infoPtr : valid pointer to the listview structure
5517 * [I] nColumn : column index
5523 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5527 TRACE("nColumn=%d\n", nColumn
);
5529 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
5530 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5532 /* While the MSDN specifically says that column zero should not be deleted,
5533 what actually happens is that the column itself is deleted but no items or subitems
5537 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5539 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5542 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5543 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5545 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5547 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5549 INT nItem
, nSubItem
, i
;
5551 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5553 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5556 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5558 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5559 if (lpSubItem
->iSubItem
== nColumn
)
5562 lpDelItem
= lpSubItem
;
5564 else if (lpSubItem
->iSubItem
> nColumn
)
5566 lpSubItem
->iSubItem
--;
5570 /* if we found our subitem, zap it */
5574 if (is_text(lpDelItem
->hdr
.pszText
))
5575 Free(lpDelItem
->hdr
.pszText
);
5580 /* free dpa memory */
5581 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5586 /* update the other column info */
5587 LISTVIEW_UpdateItemSize(infoPtr
);
5588 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5589 LISTVIEW_InvalidateList(infoPtr
);
5591 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5598 * Invalidates the listview after an item's insertion or deletion.
5601 * [I] infoPtr : valid pointer to the listview structure
5602 * [I] nItem : item index
5603 * [I] dir : -1 if deleting, 1 if inserting
5608 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5610 INT nPerCol
, nItemCol
, nItemRow
;
5614 /* if we don't refresh, what's the point of scrolling? */
5615 if (!is_redrawing(infoPtr
)) return;
5617 assert (abs(dir
) == 1);
5619 /* arrange icons if autoarrange is on */
5620 if (is_autoarrange(infoPtr
))
5622 BOOL arrange
= TRUE
;
5623 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5624 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5625 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5628 /* scrollbars need updating */
5629 LISTVIEW_UpdateScroll(infoPtr
);
5631 /* figure out the item's position */
5632 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5633 nPerCol
= infoPtr
->nItemCount
+ 1;
5634 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5635 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5636 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5639 nItemCol
= nItem
/ nPerCol
;
5640 nItemRow
= nItem
% nPerCol
;
5641 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5643 /* move the items below up a slot */
5644 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5645 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5646 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5647 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5648 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5649 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5650 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5652 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5653 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5656 /* report has only that column, so we're done */
5657 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5659 /* now for LISTs, we have to deal with the columns to the right */
5660 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
5662 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
5663 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5664 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5665 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5666 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5671 * Removes an item from the listview control.
5674 * [I] infoPtr : valid pointer to the listview structure
5675 * [I] nItem : item index
5681 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5684 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5685 INT focus
= infoPtr
->nFocusedItem
;
5687 TRACE("(nItem=%d)\n", nItem
);
5689 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5691 /* remove selection, and focus */
5693 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5694 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5696 /* send LVN_DELETEITEM notification. */
5697 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5699 /* we need to do this here, because we'll be deleting stuff */
5701 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5703 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5711 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5712 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5714 /* free id struct */
5715 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5716 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5717 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5719 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5721 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5722 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5725 DPA_Destroy(hdpaSubItems
);
5730 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5731 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5734 infoPtr
->nItemCount
--;
5735 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5736 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5738 /* now is the invalidation fun */
5740 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5747 * Callback implementation for editlabel control
5750 * [I] infoPtr : valid pointer to the listview structure
5751 * [I] storeText : store edit box text as item text
5752 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5758 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5760 HWND hwndSelf
= infoPtr
->hwndSelf
;
5761 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5762 NMLVDISPINFOW dispInfo
;
5763 INT editedItem
= infoPtr
->nEditLabelItem
;
5765 WCHAR
*pszText
= NULL
;
5770 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5774 if ((pszText
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5776 if (isW
) GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
+1);
5777 else GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
+1);
5782 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5784 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5785 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5786 dispInfo
.item
.iItem
= editedItem
;
5787 dispInfo
.item
.iSubItem
= 0;
5788 dispInfo
.item
.stateMask
= ~0;
5789 dispInfo
.item
.pszText
= szDispText
;
5790 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5791 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5798 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5801 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5802 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5803 textfreeT(tmp
, FALSE
);
5806 /* add the text from the edit in */
5807 dispInfo
.item
.mask
|= LVIF_TEXT
;
5808 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5809 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5811 /* Do we need to update the Item Text */
5812 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5814 infoPtr
->nEditLabelItem
= -1;
5815 infoPtr
->hwndEdit
= 0;
5817 if (!res
) goto cleanup
;
5819 if (!IsWindow(hwndSelf
))
5824 if (!pszText
) return TRUE
;
5831 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5833 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5834 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5835 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5837 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5843 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5844 dispInfo
.item
.mask
= LVIF_TEXT
;
5845 dispInfo
.item
.iItem
= editedItem
;
5846 dispInfo
.item
.iSubItem
= 0;
5847 dispInfo
.item
.pszText
= pszText
;
5848 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5849 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5859 * Subclassed edit control windproc function
5862 * [I] hwnd : the edit window handle
5863 * [I] uMsg : the message that is to be processed
5864 * [I] wParam : first message parameter
5865 * [I] lParam : second message parameter
5866 * [I] isW : TRUE if input is Unicode
5871 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5873 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5876 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5877 hwnd
, uMsg
, wParam
, lParam
, isW
);
5882 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
5886 WNDPROC editProc
= infoPtr
->EditWndProc
;
5887 infoPtr
->EditWndProc
= 0;
5888 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
5889 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5893 if (VK_ESCAPE
== (INT
)wParam
)
5898 else if (VK_RETURN
== (INT
)wParam
)
5902 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5906 if (infoPtr
->hwndEdit
)
5907 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
5909 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
5915 * Subclassed edit control Unicode windproc function
5918 * [I] hwnd : the edit window handle
5919 * [I] uMsg : the message that is to be processed
5920 * [I] wParam : first message parameter
5921 * [I] lParam : second message parameter
5925 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5927 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
5932 * Subclassed edit control ANSI windproc function
5935 * [I] hwnd : the edit window handle
5936 * [I] uMsg : the message that is to be processed
5937 * [I] wParam : first message parameter
5938 * [I] lParam : second message parameter
5942 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5944 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
5949 * Creates a subclassed edit control
5952 * [I] infoPtr : valid pointer to the listview structure
5953 * [I] text : initial text for the edit
5954 * [I] style : the window style
5955 * [I] isW : TRUE if input is Unicode
5959 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
5961 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
5962 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
5965 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
5967 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
5969 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
5971 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
5973 if (!hedit
) return 0;
5975 infoPtr
->EditWndProc
= (WNDPROC
)
5976 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
5977 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
5979 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
5980 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
5987 * Begin in place editing of specified list view item
5990 * [I] infoPtr : valid pointer to the listview structure
5991 * [I] nItem : item index
5992 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
5998 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
6000 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
6001 HWND hwndSelf
= infoPtr
->hwndSelf
;
6002 NMLVDISPINFOW dispInfo
;
6003 HFONT hOldFont
= NULL
;
6009 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6011 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6013 /* remove existing edit box */
6014 if (infoPtr
->hwndEdit
)
6016 SetFocus(infoPtr
->hwndSelf
);
6017 infoPtr
->hwndEdit
= 0;
6020 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6022 infoPtr
->nEditLabelItem
= nItem
;
6024 LISTVIEW_SetSelection(infoPtr
, nItem
);
6025 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6026 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6028 rect
.left
= LVIR_LABEL
;
6029 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6031 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6032 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6033 dispInfo
.item
.iItem
= nItem
;
6034 dispInfo
.item
.iSubItem
= 0;
6035 dispInfo
.item
.stateMask
= ~0;
6036 dispInfo
.item
.pszText
= disptextW
;
6037 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6038 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6040 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6041 if (!infoPtr
->hwndEdit
) return 0;
6043 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6045 if (!IsWindow(hwndSelf
))
6047 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6048 infoPtr
->hwndEdit
= 0;
6052 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6054 /* position and display edit box */
6055 hdc
= GetDC(infoPtr
->hwndSelf
);
6057 /* select the font to get appropriate metric dimensions */
6059 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6061 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6062 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6063 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6065 /* get string length in pixels */
6066 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6068 /* add extra spacing for the next character */
6069 GetTextMetricsW(hdc
, &tm
);
6070 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6073 SelectObject(hdc
, hOldFont
);
6075 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6077 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6080 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6081 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6082 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6083 SetFocus(infoPtr
->hwndEdit
);
6084 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6085 return infoPtr
->hwndEdit
;
6091 * Ensures the specified item is visible, scrolling into view if necessary.
6094 * [I] infoPtr : valid pointer to the listview structure
6095 * [I] nItem : item index
6096 * [I] bPartial : partially or entirely visible
6102 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6104 INT nScrollPosHeight
= 0;
6105 INT nScrollPosWidth
= 0;
6106 INT nHorzAdjust
= 0;
6107 INT nVertAdjust
= 0;
6110 RECT rcItem
, rcTemp
;
6112 rcItem
.left
= LVIR_BOUNDS
;
6113 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6115 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6117 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6119 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6120 if (infoPtr
->uView
== LV_VIEW_LIST
)
6121 nScrollPosWidth
= infoPtr
->nItemWidth
;
6122 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6123 nScrollPosWidth
= 1;
6125 if (rcItem
.left
< infoPtr
->rcList
.left
)
6128 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6133 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6137 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6139 /* scroll up/down, but not in LVS_LIST mode */
6140 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6141 nScrollPosHeight
= infoPtr
->nItemHeight
;
6142 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6143 nScrollPosHeight
= 1;
6145 if (rcItem
.top
< infoPtr
->rcList
.top
)
6148 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6153 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6157 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6159 if (nScrollPosWidth
)
6161 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6162 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6163 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6166 if (nScrollPosHeight
)
6168 INT diff
= nVertDiff
/ nScrollPosHeight
;
6169 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6170 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6178 * Searches for an item with specific characteristics.
6181 * [I] hwnd : window handle
6182 * [I] nStart : base item index
6183 * [I] lpFindInfo : item information to look for
6186 * SUCCESS : index of item
6189 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6190 const LVFINDINFOW
*lpFindInfo
)
6192 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6193 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6194 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6195 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6196 POINT Position
, Destination
;
6199 /* Search in virtual listviews should be done by application, not by
6200 listview control, so we just send LVN_ODFINDITEMW and return the result */
6201 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6205 nmlv
.iStart
= nStart
;
6206 nmlv
.lvfi
= *lpFindInfo
;
6207 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6210 if (!lpFindInfo
|| nItem
< 0) return -1;
6213 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6214 lpFindInfo
->flags
& LVFI_SUBSTRING
)
6216 lvItem
.mask
|= LVIF_TEXT
;
6217 lvItem
.pszText
= szDispText
;
6218 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6221 if (lpFindInfo
->flags
& LVFI_WRAP
)
6224 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6225 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6230 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6231 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6232 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6233 switch(lpFindInfo
->vkDirection
)
6235 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6236 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6237 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6238 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6239 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6240 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6241 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6243 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6244 Destination
.x
= rcArea
.right
;
6245 Destination
.y
= rcArea
.bottom
;
6247 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6251 else Destination
.x
= Destination
.y
= 0;
6253 /* if LVFI_PARAM is specified, all other flags are ignored */
6254 if (lpFindInfo
->flags
& LVFI_PARAM
)
6256 lvItem
.mask
|= LVIF_PARAM
;
6258 lvItem
.mask
&= ~LVIF_TEXT
;
6262 for (; nItem
< nLast
; nItem
++)
6264 lvItem
.iItem
= nItem
;
6265 lvItem
.iSubItem
= 0;
6266 lvItem
.pszText
= szDispText
;
6267 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6269 if (lvItem
.mask
& LVIF_PARAM
)
6271 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6277 if (lvItem
.mask
& LVIF_TEXT
)
6279 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6281 WCHAR
*p
= strstrW(lvItem
.pszText
, lpFindInfo
->psz
);
6282 if (!p
|| p
!= lvItem
.pszText
) continue;
6286 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6290 if (!bNearest
) return nItem
;
6292 /* This is very inefficient. To do a good job here,
6293 * we need a sorted array of (x,y) item positions */
6294 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6296 /* compute the distance^2 to the destination */
6297 xdist
= Destination
.x
- Position
.x
;
6298 ydist
= Destination
.y
- Position
.y
;
6299 dist
= xdist
* xdist
+ ydist
* ydist
;
6301 /* remember the distance, and item if it's closer */
6305 nNearestItem
= nItem
;
6312 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6317 return nNearestItem
;
6322 * Searches for an item with specific characteristics.
6325 * [I] hwnd : window handle
6326 * [I] nStart : base item index
6327 * [I] lpFindInfo : item information to look for
6330 * SUCCESS : index of item
6333 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6334 const LVFINDINFOA
*lpFindInfo
)
6336 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6337 lpFindInfo
->flags
& LVFI_SUBSTRING
;
6342 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6343 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6344 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6345 textfreeT(strW
, FALSE
);
6351 * Retrieves column attributes.
6354 * [I] infoPtr : valid pointer to the listview structure
6355 * [I] nColumn : column index
6356 * [IO] lpColumn : column information
6357 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6358 * otherwise it is in fact a LPLVCOLUMNA
6364 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6366 COLUMN_INFO
*lpColumnInfo
;
6369 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6370 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6372 /* initialize memory */
6373 ZeroMemory(&hdi
, sizeof(hdi
));
6375 if (lpColumn
->mask
& LVCF_TEXT
)
6377 hdi
.mask
|= HDI_TEXT
;
6378 hdi
.pszText
= lpColumn
->pszText
;
6379 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6382 if (lpColumn
->mask
& LVCF_IMAGE
)
6383 hdi
.mask
|= HDI_IMAGE
;
6385 if (lpColumn
->mask
& LVCF_ORDER
)
6386 hdi
.mask
|= HDI_ORDER
;
6388 if (lpColumn
->mask
& LVCF_SUBITEM
)
6389 hdi
.mask
|= HDI_LPARAM
;
6391 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6393 if (lpColumn
->mask
& LVCF_FMT
)
6394 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6396 if (lpColumn
->mask
& LVCF_WIDTH
)
6397 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6399 if (lpColumn
->mask
& LVCF_IMAGE
)
6400 lpColumn
->iImage
= hdi
.iImage
;
6402 if (lpColumn
->mask
& LVCF_ORDER
)
6403 lpColumn
->iOrder
= hdi
.iOrder
;
6405 if (lpColumn
->mask
& LVCF_SUBITEM
)
6406 lpColumn
->iSubItem
= hdi
.lParam
;
6408 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6409 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6415 static BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6417 TRACE("iCount=%d, lpiArray=%p\n", iCount
, lpiArray
);
6422 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6427 * Retrieves the column width.
6430 * [I] infoPtr : valid pointer to the listview structure
6431 * [I] int : column index
6434 * SUCCESS : column width
6437 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6439 INT nColumnWidth
= 0;
6442 TRACE("nColumn=%d\n", nColumn
);
6444 /* we have a 'column' in LIST and REPORT mode only */
6445 switch(infoPtr
->uView
)
6448 nColumnWidth
= infoPtr
->nItemWidth
;
6450 case LV_VIEW_DETAILS
:
6451 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6452 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6453 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6455 * TODO: should we do the same in LVM_GETCOLUMN?
6457 hdItem
.mask
= HDI_WIDTH
;
6458 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6460 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6463 nColumnWidth
= hdItem
.cxy
;
6467 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6468 return nColumnWidth
;
6473 * In list or report display mode, retrieves the number of items that can fit
6474 * vertically in the visible area. In icon or small icon display mode,
6475 * retrieves the total number of visible items.
6478 * [I] infoPtr : valid pointer to the listview structure
6481 * Number of fully visible items.
6483 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6485 switch (infoPtr
->uView
)
6488 case LV_VIEW_SMALLICON
:
6489 return infoPtr
->nItemCount
;
6490 case LV_VIEW_DETAILS
:
6491 return LISTVIEW_GetCountPerColumn(infoPtr
);
6493 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6501 * Retrieves an image list handle.
6504 * [I] infoPtr : valid pointer to the listview structure
6505 * [I] nImageList : image list identifier
6508 * SUCCESS : image list handle
6511 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6515 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6516 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6517 case LVSIL_STATE
: return infoPtr
->himlState
;
6518 case LVSIL_GROUPHEADER
:
6519 FIXME("LVSIL_GROUPHEADER not supported\n");
6522 WARN("got unknown imagelist index - %d\n", nImageList
);
6527 /* LISTVIEW_GetISearchString */
6531 * Retrieves item attributes.
6534 * [I] hwnd : window handle
6535 * [IO] lpLVItem : item info
6536 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6537 * if FALSE, then lpLVItem is a LPLVITEMA.
6540 * This is the internal 'GetItem' interface -- it tries to
6541 * be smart and avoid text copies, if possible, by modifying
6542 * lpLVItem->pszText to point to the text string. Please note
6543 * that this is not always possible (e.g. OWNERDATA), so on
6544 * entry you *must* supply valid values for pszText, and cchTextMax.
6545 * The only difference to the documented interface is that upon
6546 * return, you should use *only* the lpLVItem->pszText, rather than
6547 * the buffer pointer you provided on input. Most code already does
6548 * that, so it's not a problem.
6549 * For the two cases when the text must be copied (that is,
6550 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6556 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6558 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6559 NMLVDISPINFOW dispInfo
;
6565 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6567 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6570 if (lpLVItem
->mask
== 0) return TRUE
;
6571 TRACE("mask=%x\n", lpLVItem
->mask
);
6573 /* make a local copy */
6574 isubitem
= lpLVItem
->iSubItem
;
6576 /* a quick optimization if all we're asked is the focus state
6577 * these queries are worth optimising since they are common,
6578 * and can be answered in constant time, without the heavy accesses */
6579 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6580 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6582 lpLVItem
->state
= 0;
6583 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6584 lpLVItem
->state
|= LVIS_FOCUSED
;
6588 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6590 /* if the app stores all the data, handle it separately */
6591 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6593 dispInfo
.item
.state
= 0;
6595 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6596 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6597 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6599 UINT mask
= lpLVItem
->mask
;
6601 /* NOTE: copy only fields which we _know_ are initialized, some apps
6602 * depend on the uninitialized fields being 0 */
6603 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6604 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6605 dispInfo
.item
.iSubItem
= isubitem
;
6606 if (lpLVItem
->mask
& LVIF_TEXT
)
6608 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6610 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6613 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6614 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6617 if (lpLVItem
->mask
& LVIF_STATE
)
6618 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6619 /* could be zeroed on LVIF_NORECOMPUTE case */
6620 if (dispInfo
.item
.mask
)
6622 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6623 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6624 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6626 /* full size structure expected - _WIN32IE >= 0x560 */
6627 *lpLVItem
= dispInfo
.item
;
6629 else if (lpLVItem
->mask
& LVIF_INDENT
)
6631 /* indent member expected - _WIN32IE >= 0x300 */
6632 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6636 /* minimal structure expected */
6637 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6639 lpLVItem
->mask
= mask
;
6640 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6644 /* make sure lParam is zeroed out */
6645 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6647 /* callback marked pointer required here */
6648 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6649 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6651 /* we store only a little state, so if we're not asked, we're done */
6652 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6654 /* if focus is handled by us, report it */
6655 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6657 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6658 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6659 lpLVItem
->state
|= LVIS_FOCUSED
;
6662 /* and do the same for selection, if we handle it */
6663 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6665 lpLVItem
->state
&= ~LVIS_SELECTED
;
6666 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6667 lpLVItem
->state
|= LVIS_SELECTED
;
6673 /* find the item and subitem structures before we proceed */
6674 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6675 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6680 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6681 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6684 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6689 pItemHdr
= &lpItem
->hdr
;
6691 /* Do we need to query the state from the app? */
6692 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6694 dispInfo
.item
.mask
|= LVIF_STATE
;
6695 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6698 /* Do we need to enquire about the image? */
6699 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6700 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6702 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6703 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6706 /* Only items support indentation */
6707 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6710 dispInfo
.item
.mask
|= LVIF_INDENT
;
6711 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6714 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6715 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6716 !is_text(pItemHdr
->pszText
))
6718 dispInfo
.item
.mask
|= LVIF_TEXT
;
6719 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6720 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6721 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6722 *dispInfo
.item
.pszText
= '\0';
6725 /* If we don't have all the requested info, query the application */
6726 if (dispInfo
.item
.mask
)
6728 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6729 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6730 dispInfo
.item
.lParam
= lpItem
->lParam
;
6731 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6732 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6735 /* we should not store values for subitems */
6736 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6738 /* Now, handle the iImage field */
6739 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6741 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6742 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6743 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6745 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6747 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6748 lpLVItem
->iImage
= pItemHdr
->iImage
;
6750 lpLVItem
->iImage
= 0;
6753 /* The pszText field */
6754 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6756 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6757 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6759 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6761 else if (lpLVItem
->mask
& LVIF_TEXT
)
6763 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6764 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6765 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6768 /* Next is the lParam field */
6769 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6771 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6772 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6773 lpItem
->lParam
= dispInfo
.item
.lParam
;
6775 else if (lpLVItem
->mask
& LVIF_PARAM
)
6776 lpLVItem
->lParam
= lpItem
->lParam
;
6778 /* if this is a subitem, we're done */
6779 if (isubitem
) return TRUE
;
6781 /* ... the state field (this one is different due to uCallbackmask) */
6782 if (lpLVItem
->mask
& LVIF_STATE
)
6784 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6785 if (dispInfo
.item
.mask
& LVIF_STATE
)
6787 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6788 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6790 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6792 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6793 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6794 lpLVItem
->state
|= LVIS_FOCUSED
;
6796 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6798 lpLVItem
->state
&= ~LVIS_SELECTED
;
6799 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6800 lpLVItem
->state
|= LVIS_SELECTED
;
6804 /* and last, but not least, the indent field */
6805 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6807 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6808 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6809 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6811 else if (lpLVItem
->mask
& LVIF_INDENT
)
6813 lpLVItem
->iIndent
= lpItem
->iIndent
;
6821 * Retrieves item attributes.
6824 * [I] hwnd : window handle
6825 * [IO] lpLVItem : item info
6826 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6827 * if FALSE, then lpLVItem is a LPLVITEMA.
6830 * This is the external 'GetItem' interface -- it properly copies
6831 * the text in the provided buffer.
6837 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6842 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6845 pszText
= lpLVItem
->pszText
;
6846 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6847 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6849 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6850 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6852 pszText
= LPSTR_TEXTCALLBACKW
;
6854 lpLVItem
->pszText
= pszText
;
6862 * Retrieves the position (upper-left) of the listview control item.
6863 * Note that for LVS_ICON style, the upper-left is that of the icon
6864 * and not the bounding box.
6867 * [I] infoPtr : valid pointer to the listview structure
6868 * [I] nItem : item index
6869 * [O] lpptPosition : coordinate information
6875 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6879 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6881 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6883 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6884 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6886 if (infoPtr
->uView
== LV_VIEW_ICON
)
6888 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6889 lpptPosition
->y
+= ICON_TOP_PADDING
;
6891 lpptPosition
->x
+= Origin
.x
;
6892 lpptPosition
->y
+= Origin
.y
;
6894 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6901 * Retrieves the bounding rectangle for a listview control item.
6904 * [I] infoPtr : valid pointer to the listview structure
6905 * [I] nItem : item index
6906 * [IO] lprc : bounding rectangle coordinates
6907 * lprc->left specifies the portion of the item for which the bounding
6908 * rectangle will be retrieved.
6910 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
6911 * including the icon and label.
6914 * * Experiment shows that native control returns:
6915 * * width = min (48, length of text line)
6916 * * .left = position.x - (width - iconsize.cx)/2
6917 * * .right = .left + width
6918 * * height = #lines of text * ntmHeight + icon height + 8
6919 * * .top = position.y - 2
6920 * * .bottom = .top + height
6921 * * separation between items .y = itemSpacing.cy - height
6922 * * .x = itemSpacing.cx - width
6923 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
6926 * * Experiment shows that native control returns:
6927 * * width = iconSize.cx + 16
6928 * * .left = position.x - (width - iconsize.cx)/2
6929 * * .right = .left + width
6930 * * height = iconSize.cy + 4
6931 * * .top = position.y - 2
6932 * * .bottom = .top + height
6933 * * separation between items .y = itemSpacing.cy - height
6934 * * .x = itemSpacing.cx - width
6935 * LVIR_LABEL Returns the bounding rectangle of the item text.
6938 * * Experiment shows that native control returns:
6939 * * width = text length
6940 * * .left = position.x - width/2
6941 * * .right = .left + width
6942 * * height = ntmH * linecount + 2
6943 * * .top = position.y + iconSize.cy + 6
6944 * * .bottom = .top + height
6945 * * separation between items .y = itemSpacing.cy - height
6946 * * .x = itemSpacing.cx - width
6947 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
6948 * rectangles, but excludes columns in report view.
6955 * Note that the bounding rectangle of the label in the LVS_ICON view depends
6956 * upon whether the window has the focus currently and on whether the item
6957 * is the one with the focus. Ensure that the control's record of which
6958 * item has the focus agrees with the items' records.
6960 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
6962 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6963 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
6964 POINT Position
, Origin
;
6968 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
6970 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6972 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6973 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6975 /* Be smart and try to figure out the minimum we have to do */
6976 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
6977 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
6978 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
6979 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
6980 oversizedBox
= TRUE
;
6982 /* get what we need from the item before hand, so we make
6983 * only one request. This can speed up things, if data
6984 * is stored on the app side */
6986 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
6987 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
6988 lvItem
.iItem
= nItem
;
6989 lvItem
.iSubItem
= 0;
6990 lvItem
.pszText
= szDispText
;
6991 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6992 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
6993 /* we got the state already up, simulate it here, to avoid a reget */
6994 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
6996 lvItem
.mask
|= LVIF_STATE
;
6997 lvItem
.stateMask
= LVIS_FOCUSED
;
6998 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
7001 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
7002 lprc
->left
= LVIR_BOUNDS
;
7008 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7012 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7016 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7019 case LVIR_SELECTBOUNDS
:
7020 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7024 WARN("Unknown value: %d\n", lprc
->left
);
7028 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7030 if (mode
!= LVIR_BOUNDS
)
7031 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7032 Position
.y
+ Origin
.y
);
7034 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7037 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7039 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7046 * Retrieves the spacing between listview control items.
7049 * [I] infoPtr : valid pointer to the listview structure
7050 * [IO] lprc : rectangle to receive the output
7051 * on input, lprc->top = nSubItem
7052 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7054 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7055 * not only those of the first column.
7061 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7063 RECT rect
= { 0, 0, 0, 0 };
7067 if (!lprc
) return FALSE
;
7069 TRACE("(item=%d, subitem=%d, type=%d)\n", item
, lprc
->top
, lprc
->left
);
7070 /* Subitem of '0' means item itself, and this works for all control view modes */
7072 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7074 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7076 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7077 /* this works for any item index, no matter if it exists or not */
7078 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7080 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7083 rect
.bottom
= infoPtr
->nItemHeight
;
7087 /* Native implementation is broken for this case and garbage is left for left and right fields,
7088 we zero them to get predictable output */
7089 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7090 lprc
->bottom
= infoPtr
->nItemHeight
;
7091 OffsetRect(lprc
, origin
.x
, y
);
7092 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7100 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7101 if (infoPtr
->himlSmall
)
7102 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7104 rect
.right
= rect
.left
;
7106 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7114 ERR("Unknown bounds=%d\n", lprc
->left
);
7118 OffsetRect(&rect
, origin
.x
, y
);
7120 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7127 * Retrieves the spacing between listview control items.
7130 * [I] infoPtr : valid pointer to the listview structure
7131 * [I] bSmall : flag for small or large icon
7134 * Horizontal + vertical spacing
7136 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7142 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7146 if (infoPtr
->uView
== LV_VIEW_ICON
)
7147 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7149 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7156 * Retrieves the state of a listview control item.
7159 * [I] infoPtr : valid pointer to the listview structure
7160 * [I] nItem : item index
7161 * [I] uMask : state mask
7164 * State specified by the mask.
7166 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7170 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7172 lvItem
.iItem
= nItem
;
7173 lvItem
.iSubItem
= 0;
7174 lvItem
.mask
= LVIF_STATE
;
7175 lvItem
.stateMask
= uMask
;
7176 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7178 return lvItem
.state
& uMask
;
7183 * Retrieves the text of a listview control item or subitem.
7186 * [I] hwnd : window handle
7187 * [I] nItem : item index
7188 * [IO] lpLVItem : item information
7189 * [I] isW : TRUE if lpLVItem is Unicode
7192 * SUCCESS : string length
7195 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7197 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7199 lpLVItem
->mask
= LVIF_TEXT
;
7200 lpLVItem
->iItem
= nItem
;
7201 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7203 return textlenT(lpLVItem
->pszText
, isW
);
7208 * Searches for an item based on properties + relationships.
7211 * [I] infoPtr : valid pointer to the listview structure
7212 * [I] nItem : item index
7213 * [I] uFlags : relationship flag
7216 * SUCCESS : item index
7219 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7222 LVFINDINFOW lvFindInfo
;
7223 INT nCountPerColumn
;
7227 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7228 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7230 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7232 if (uFlags
& LVNI_CUT
)
7235 if (uFlags
& LVNI_DROPHILITED
)
7236 uMask
|= LVIS_DROPHILITED
;
7238 if (uFlags
& LVNI_FOCUSED
)
7239 uMask
|= LVIS_FOCUSED
;
7241 if (uFlags
& LVNI_SELECTED
)
7242 uMask
|= LVIS_SELECTED
;
7244 /* if we're asked for the focused item, that's only one,
7245 * so it's worth optimizing */
7246 if (uFlags
& LVNI_FOCUSED
)
7248 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7249 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7252 if (uFlags
& LVNI_ABOVE
)
7254 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7259 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7265 /* Special case for autoarrange - move 'til the top of a list */
7266 if (is_autoarrange(infoPtr
))
7268 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7269 while (nItem
- nCountPerRow
>= 0)
7271 nItem
-= nCountPerRow
;
7272 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7277 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7278 lvFindInfo
.vkDirection
= VK_UP
;
7279 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7280 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7282 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7287 else if (uFlags
& LVNI_BELOW
)
7289 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7291 while (nItem
< infoPtr
->nItemCount
)
7294 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7300 /* Special case for autoarrange - move 'til the bottom of a list */
7301 if (is_autoarrange(infoPtr
))
7303 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7304 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7306 nItem
+= nCountPerRow
;
7307 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7312 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7313 lvFindInfo
.vkDirection
= VK_DOWN
;
7314 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7315 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7317 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7322 else if (uFlags
& LVNI_TOLEFT
)
7324 if (infoPtr
->uView
== LV_VIEW_LIST
)
7326 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7327 while (nItem
- nCountPerColumn
>= 0)
7329 nItem
-= nCountPerColumn
;
7330 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7334 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7336 /* Special case for autoarrange - move 'til the beginning of a row */
7337 if (is_autoarrange(infoPtr
))
7339 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7340 while (nItem
% nCountPerRow
> 0)
7343 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7348 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7349 lvFindInfo
.vkDirection
= VK_LEFT
;
7350 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7351 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7353 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7358 else if (uFlags
& LVNI_TORIGHT
)
7360 if (infoPtr
->uView
== LV_VIEW_LIST
)
7362 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7363 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7365 nItem
+= nCountPerColumn
;
7366 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7370 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7372 /* Special case for autoarrange - move 'til the end of a row */
7373 if (is_autoarrange(infoPtr
))
7375 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7376 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7379 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7384 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7385 lvFindInfo
.vkDirection
= VK_RIGHT
;
7386 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7387 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7389 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7398 /* search by index */
7399 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7401 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7409 /* LISTVIEW_GetNumberOfWorkAreas */
7413 * Retrieves the origin coordinates when in icon or small icon display mode.
7416 * [I] infoPtr : valid pointer to the listview structure
7417 * [O] lpptOrigin : coordinate information
7422 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7424 INT nHorzPos
= 0, nVertPos
= 0;
7425 SCROLLINFO scrollInfo
;
7427 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7428 scrollInfo
.fMask
= SIF_POS
;
7430 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7431 nHorzPos
= scrollInfo
.nPos
;
7432 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7433 nVertPos
= scrollInfo
.nPos
;
7435 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7437 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7438 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7439 if (infoPtr
->uView
== LV_VIEW_LIST
)
7440 nHorzPos
*= infoPtr
->nItemWidth
;
7441 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7442 nVertPos
*= infoPtr
->nItemHeight
;
7444 lpptOrigin
->x
-= nHorzPos
;
7445 lpptOrigin
->y
-= nVertPos
;
7447 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7452 * Retrieves the width of a string.
7455 * [I] hwnd : window handle
7456 * [I] lpszText : text string to process
7457 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7460 * SUCCESS : string width (in pixels)
7463 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7468 if (is_text(lpszText
))
7470 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7471 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7472 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7475 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7477 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7478 SelectObject(hdc
, hOldFont
);
7479 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7481 return stringSize
.cx
;
7486 * Determines which listview item is located at the specified position.
7489 * [I] infoPtr : valid pointer to the listview structure
7490 * [IO] lpht : hit test information
7491 * [I] subitem : fill out iSubItem.
7492 * [I] select : return the index only if the hit selects the item
7495 * (mm 20001022): We must not allow iSubItem to be touched, for
7496 * an app might pass only a structure with space up to iItem!
7497 * (MS Office 97 does that for instance in the file open dialog)
7500 * SUCCESS : item index
7503 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7505 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7506 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7507 POINT Origin
, Position
, opt
;
7513 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7517 if (subitem
) lpht
->iSubItem
= 0;
7519 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7521 /* set whole list relation flags */
7522 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7524 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7525 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7526 lpht
->flags
|= LVHT_TOLEFT
;
7528 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7529 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7533 if (infoPtr
->rcList
.bottom
< opt
.y
)
7534 lpht
->flags
|= LVHT_BELOW
;
7538 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7539 lpht
->flags
|= LVHT_TOLEFT
;
7540 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7541 lpht
->flags
|= LVHT_TORIGHT
;
7543 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7544 lpht
->flags
|= LVHT_ABOVE
;
7545 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7546 lpht
->flags
|= LVHT_BELOW
;
7549 /* even if item is invalid try to find subitem */
7550 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7555 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7557 lpht
->iSubItem
= -1;
7558 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7560 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7562 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7568 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7570 /* if we're outside horizontal columns bounds there's nothing to test further */
7571 if (lpht
->iSubItem
== -1)
7574 lpht
->flags
= LVHT_NOWHERE
;
7579 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7580 if (lpht
->flags
) return -1;
7582 lpht
->flags
|= LVHT_NOWHERE
;
7584 /* first deal with the large items */
7585 rcSearch
.left
= lpht
->pt
.x
;
7586 rcSearch
.top
= lpht
->pt
.y
;
7587 rcSearch
.right
= rcSearch
.left
+ 1;
7588 rcSearch
.bottom
= rcSearch
.top
+ 1;
7590 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7591 iterator_next(&i
); /* go to first item in the sequence */
7593 iterator_destroy(&i
);
7595 TRACE("lpht->iItem=%d\n", iItem
);
7596 if (iItem
== -1) return -1;
7598 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7599 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7600 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7601 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7602 lvItem
.iItem
= iItem
;
7603 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7604 lvItem
.pszText
= szDispText
;
7605 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7606 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7607 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7609 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7610 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7611 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7613 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7614 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7616 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7618 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7621 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7622 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7626 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7627 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7629 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7630 if (!PtInRect(&rcBounds
, opt
)) return -1;
7632 /* That's a special case - row rectangle is used as item rectangle and
7633 returned flags contain all item parts. */
7634 is_fullrow
= (infoPtr
->uView
== LV_VIEW_DETAILS
) && ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
));
7636 if (PtInRect(&rcIcon
, opt
))
7637 lpht
->flags
|= LVHT_ONITEMICON
;
7638 else if (PtInRect(&rcLabel
, opt
))
7639 lpht
->flags
|= LVHT_ONITEMLABEL
;
7640 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7641 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7642 if (is_fullrow
&& !(lpht
->flags
& LVHT_ONITEM
))
7644 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7646 if (lpht
->flags
& LVHT_ONITEM
)
7647 lpht
->flags
&= ~LVHT_NOWHERE
;
7648 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7650 if (select
&& !is_fullrow
)
7652 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7654 /* get main item bounds */
7655 lvItem
.iSubItem
= 0;
7656 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7657 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7658 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7660 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7662 return lpht
->iItem
= iItem
;
7667 * Inserts a new item in the listview control.
7670 * [I] infoPtr : valid pointer to the listview structure
7671 * [I] lpLVItem : item information
7672 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7675 * SUCCESS : new item index
7678 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7685 BOOL is_sorted
, has_changed
;
7687 HWND hwndSelf
= infoPtr
->hwndSelf
;
7689 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7691 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7693 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7694 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7696 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7698 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7700 /* insert item in listview control data structure */
7701 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7702 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7704 /* link with id struct */
7705 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7707 lpID
->item
= hdpaSubItems
;
7708 lpID
->id
= get_next_itemid(infoPtr
);
7709 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7711 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7712 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7714 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7716 /* calculate new item index */
7723 while (i
< infoPtr
->nItemCount
)
7725 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7726 item_s
= DPA_GetPtr(hItem
, 0);
7728 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
7729 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7731 if (cmpv
>= 0) break;
7737 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7739 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7740 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7741 if (nItem
== -1) goto fail
;
7742 infoPtr
->nItemCount
++;
7744 /* shift indices first so they don't get tangled */
7745 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7747 /* set the item attributes */
7748 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7750 /* full size structure expected - _WIN32IE >= 0x560 */
7753 else if (lpLVItem
->mask
& LVIF_INDENT
)
7755 /* indent member expected - _WIN32IE >= 0x300 */
7756 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7760 /* minimal structure expected */
7761 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7764 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7766 item
.mask
|= LVIF_STATE
;
7767 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7768 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7769 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7772 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7774 /* make room for the position, if we are in the right mode */
7775 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7777 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7779 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7781 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7786 /* send LVN_INSERTITEM notification */
7787 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7789 nmlv
.lParam
= lpItem
->lParam
;
7790 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7791 if (!IsWindow(hwndSelf
))
7794 /* align items (set position of each item) */
7795 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7799 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7800 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7802 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7804 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7807 /* now is the invalidation fun */
7808 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7812 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7813 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7814 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7815 infoPtr
->nItemCount
--;
7817 DPA_DeletePtr(hdpaSubItems
, 0);
7818 DPA_Destroy (hdpaSubItems
);
7825 * Checks item visibility.
7828 * [I] infoPtr : valid pointer to the listview structure
7829 * [I] nFirst : item index to check for
7832 * Item visible : TRUE
7833 * Item invisible or failure : FALSE
7835 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7837 POINT Origin
, Position
;
7842 TRACE("nItem=%d\n", nItem
);
7844 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7846 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7847 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7848 rcItem
.left
= Position
.x
+ Origin
.x
;
7849 rcItem
.top
= Position
.y
+ Origin
.y
;
7850 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7851 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7853 hdc
= GetDC(infoPtr
->hwndSelf
);
7854 if (!hdc
) return FALSE
;
7855 ret
= RectVisible(hdc
, &rcItem
);
7856 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7863 * Redraws a range of items.
7866 * [I] infoPtr : valid pointer to the listview structure
7867 * [I] nFirst : first item
7868 * [I] nLast : last item
7874 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7878 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
7879 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
7882 for (i
= nFirst
; i
<= nLast
; i
++)
7883 LISTVIEW_InvalidateItem(infoPtr
, i
);
7890 * Scroll the content of a listview.
7893 * [I] infoPtr : valid pointer to the listview structure
7894 * [I] dx : horizontal scroll amount in pixels
7895 * [I] dy : vertical scroll amount in pixels
7902 * If the control is in report view (LV_VIEW_DETAILS) the control can
7903 * be scrolled only in line increments. "dy" will be rounded to the
7904 * nearest number of pixels that are a whole line. Ex: if line height
7905 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
7906 * is passed, then the scroll will be 0. (per MSDN 7/2002)
7908 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7910 switch(infoPtr
->uView
) {
7911 case LV_VIEW_DETAILS
:
7912 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
7913 dy
/= infoPtr
->nItemHeight
;
7916 if (dy
!= 0) return FALSE
;
7922 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
7923 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
7930 * Sets the background color.
7933 * [I] infoPtr : valid pointer to the listview structure
7934 * [I] color : background color
7940 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
7942 TRACE("(color=%x)\n", color
);
7944 infoPtr
->bDefaultBkColor
= FALSE
;
7945 if(infoPtr
->clrBk
!= color
) {
7946 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
7947 infoPtr
->clrBk
= color
;
7948 if (color
== CLR_NONE
)
7949 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
7952 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
7953 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
7960 /* LISTVIEW_SetBkImage */
7962 /*** Helper for {Insert,Set}ColumnT *only* */
7963 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
7964 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7966 if (lpColumn
->mask
& LVCF_FMT
)
7968 /* format member is valid */
7969 lphdi
->mask
|= HDI_FORMAT
;
7971 /* set text alignment (leftmost column must be left-aligned) */
7972 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
7973 lphdi
->fmt
|= HDF_LEFT
;
7974 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
7975 lphdi
->fmt
|= HDF_RIGHT
;
7976 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
7977 lphdi
->fmt
|= HDF_CENTER
;
7979 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
7980 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
7982 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
7984 lphdi
->fmt
|= HDF_IMAGE
;
7985 lphdi
->iImage
= I_IMAGECALLBACK
;
7988 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
7989 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
7992 if (lpColumn
->mask
& LVCF_WIDTH
)
7994 lphdi
->mask
|= HDI_WIDTH
;
7995 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
7997 /* make it fill the remainder of the controls width */
8001 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
8003 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
8004 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8007 /* retrieve the layout of the header */
8008 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8009 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8011 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8014 lphdi
->cxy
= lpColumn
->cx
;
8017 if (lpColumn
->mask
& LVCF_TEXT
)
8019 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8020 lphdi
->fmt
|= HDF_STRING
;
8021 lphdi
->pszText
= lpColumn
->pszText
;
8022 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8025 if (lpColumn
->mask
& LVCF_IMAGE
)
8027 lphdi
->mask
|= HDI_IMAGE
;
8028 lphdi
->iImage
= lpColumn
->iImage
;
8031 if (lpColumn
->mask
& LVCF_ORDER
)
8033 lphdi
->mask
|= HDI_ORDER
;
8034 lphdi
->iOrder
= lpColumn
->iOrder
;
8041 * Inserts a new column.
8044 * [I] infoPtr : valid pointer to the listview structure
8045 * [I] nColumn : column index
8046 * [I] lpColumn : column information
8047 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8050 * SUCCESS : new column index
8053 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8054 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8056 COLUMN_INFO
*lpColumnInfo
;
8060 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8062 if (!lpColumn
|| nColumn
< 0) return -1;
8063 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8065 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8066 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8069 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8070 * (can be seen in SPY) otherwise column never gets added.
8072 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8073 hdi
.mask
|= HDI_WIDTH
;
8078 * when the iSubItem is available Windows copies it to the header lParam. It seems
8079 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8081 if (lpColumn
->mask
& LVCF_SUBITEM
)
8083 hdi
.mask
|= HDI_LPARAM
;
8084 hdi
.lParam
= lpColumn
->iSubItem
;
8087 /* create header if not present */
8088 LISTVIEW_CreateHeader(infoPtr
);
8089 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8090 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8092 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8095 /* insert item in header control */
8096 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8097 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8098 nColumn
, (LPARAM
)&hdi
);
8099 if (nNewColumn
== -1) return -1;
8100 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8102 /* create our own column info */
8103 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8104 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8106 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8107 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8108 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8111 /* now we have to actually adjust the data */
8112 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8114 SUBITEM_INFO
*lpSubItem
;
8120 item
.iSubItem
= nNewColumn
;
8121 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8122 item
.iImage
= I_IMAGECALLBACK
;
8123 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8125 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8127 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8128 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8130 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8131 if (lpSubItem
->iSubItem
>= nNewColumn
)
8132 lpSubItem
->iSubItem
++;
8135 /* add new subitem for each item */
8137 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8141 /* make space for the new column */
8142 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8143 LISTVIEW_UpdateItemSize(infoPtr
);
8148 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8151 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8159 * Sets the attributes of a header item.
8162 * [I] infoPtr : valid pointer to the listview structure
8163 * [I] nColumn : column index
8164 * [I] lpColumn : column attributes
8165 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8171 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8172 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8174 HDITEMW hdi
, hdiget
;
8177 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8179 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8181 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8182 if (lpColumn
->mask
& LVCF_FMT
)
8184 hdi
.mask
|= HDI_FORMAT
;
8185 hdiget
.mask
= HDI_FORMAT
;
8186 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8187 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8189 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8191 /* set header item attributes */
8192 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8193 if (!bResult
) return FALSE
;
8195 if (lpColumn
->mask
& LVCF_FMT
)
8197 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8198 INT oldFmt
= lpColumnInfo
->fmt
;
8200 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8201 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8203 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8207 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8208 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8215 * Sets the column order array
8218 * [I] infoPtr : valid pointer to the listview structure
8219 * [I] iCount : number of elements in column order array
8220 * [I] lpiArray : pointer to column order array
8226 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8228 TRACE("iCount %d lpiArray %p\n", iCount
, lpiArray
);
8230 if (!lpiArray
|| !IsWindow(infoPtr
->hwndHeader
)) return FALSE
;
8232 infoPtr
->colRectsDirty
= TRUE
;
8234 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8239 * Sets the width of a column
8242 * [I] infoPtr : valid pointer to the listview structure
8243 * [I] nColumn : column index
8244 * [I] cx : column width
8250 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8252 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8256 TRACE("(nColumn=%d, cx=%d)\n", nColumn
, cx
);
8258 /* set column width only if in report or list mode */
8259 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8261 /* take care of invalid cx values */
8262 if(infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< -2) cx
= LVSCW_AUTOSIZE
;
8263 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
< 1) return FALSE
;
8265 /* resize all columns if in LV_VIEW_LIST mode */
8266 if(infoPtr
->uView
== LV_VIEW_LIST
)
8268 infoPtr
->nItemWidth
= cx
;
8269 LISTVIEW_InvalidateList(infoPtr
);
8273 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8275 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8280 lvItem
.mask
= LVIF_TEXT
;
8282 lvItem
.iSubItem
= nColumn
;
8283 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8284 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8286 lvItem
.pszText
= szDispText
;
8287 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8288 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8289 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8291 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8292 max_cx
+= infoPtr
->iconSize
.cx
;
8293 max_cx
+= TRAILING_LABEL_PADDING
;
8296 /* autosize based on listview items width */
8297 if(cx
== LVSCW_AUTOSIZE
)
8299 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8301 /* if iCol is the last column make it fill the remainder of the controls width */
8302 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8307 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8308 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8310 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8314 /* Despite what the MS docs say, if this is not the last
8315 column, then MS resizes the column to the width of the
8316 largest text string in the column, including headers
8317 and items. This is different from LVSCW_AUTOSIZE in that
8318 LVSCW_AUTOSIZE ignores the header string length. */
8321 /* retrieve header text */
8322 hdi
.mask
= HDI_TEXT
;
8323 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8324 hdi
.pszText
= szDispText
;
8325 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8327 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8328 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8331 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8332 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8333 /* FIXME: Take into account the header image, if one is present */
8334 SelectObject(hdc
, old_font
);
8335 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8337 cx
= max (cx
, max_cx
);
8341 if (cx
< 0) return FALSE
;
8343 /* call header to update the column change */
8344 hdi
.mask
= HDI_WIDTH
;
8345 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8346 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8347 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8351 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8354 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8357 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8359 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8360 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8363 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8364 ILC_COLOR
| ILC_MASK
, 2, 2);
8365 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8366 hdc
= CreateCompatibleDC(hdc_wnd
);
8367 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8368 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8369 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8371 rc
.left
= rc
.top
= 0;
8372 rc
.right
= GetSystemMetrics(SM_CXSMICON
);
8373 rc
.bottom
= GetSystemMetrics(SM_CYSMICON
);
8375 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8376 FillRect(hdc
, &rc
, hbr_white
);
8377 InflateRect(&rc
, -2, -2);
8378 FillRect(hdc
, &rc
, hbr_black
);
8380 SelectObject(hdc
, hbm_im
);
8381 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8382 SelectObject(hdc
, hbm_orig
);
8383 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8385 SelectObject(hdc
, hbm_im
);
8386 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8387 SelectObject(hdc
, hbm_orig
);
8388 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8390 DeleteObject(hbm_mask
);
8391 DeleteObject(hbm_im
);
8399 * Sets the extended listview style.
8402 * [I] infoPtr : valid pointer to the listview structure
8404 * [I] dwStyle : style
8407 * SUCCESS : previous style
8410 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8412 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8414 TRACE("mask=0x%08x, ex_style=0x%08x\n", mask
, ex_style
);
8418 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8420 infoPtr
->dwLvExStyle
= ex_style
;
8422 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8424 HIMAGELIST himl
= 0;
8425 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8428 item
.mask
= LVIF_STATE
;
8429 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8430 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8431 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8433 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8434 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8435 ImageList_Destroy(infoPtr
->himlState
);
8437 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8438 /* checkbox list replaces previous custom list or... */
8439 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8440 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8441 /* ...previous was checkbox list */
8442 (old_ex_style
& LVS_EX_CHECKBOXES
))
8443 ImageList_Destroy(himl
);
8446 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8450 /* if not already created */
8451 LISTVIEW_CreateHeader(infoPtr
);
8453 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8454 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8455 style
|= HDS_DRAGDROP
;
8457 style
&= ~HDS_DRAGDROP
;
8458 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8461 /* GRIDLINES adds decoration at top so changes sizes */
8462 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8464 LISTVIEW_CreateHeader(infoPtr
);
8465 LISTVIEW_UpdateSize(infoPtr
);
8468 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8470 LISTVIEW_CreateHeader(infoPtr
);
8473 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8475 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8476 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8479 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8481 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8482 LISTVIEW_CreateHeader(infoPtr
);
8484 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8485 LISTVIEW_UpdateSize(infoPtr
);
8486 LISTVIEW_UpdateScroll(infoPtr
);
8489 LISTVIEW_InvalidateList(infoPtr
);
8490 return old_ex_style
;
8495 * Sets the new hot cursor used during hot tracking and hover selection.
8498 * [I] infoPtr : valid pointer to the listview structure
8499 * [I] hCursor : the new hot cursor handle
8502 * Returns the previous hot cursor
8504 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8506 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8508 infoPtr
->hHotCursor
= hCursor
;
8516 * Sets the hot item index.
8519 * [I] infoPtr : valid pointer to the listview structure
8520 * [I] iIndex : index
8523 * SUCCESS : previous hot item index
8524 * FAILURE : -1 (no hot item)
8526 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8528 INT iOldIndex
= infoPtr
->nHotItem
;
8530 infoPtr
->nHotItem
= iIndex
;
8538 * Sets the amount of time the cursor must hover over an item before it is selected.
8541 * [I] infoPtr : valid pointer to the listview structure
8542 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8545 * Returns the previous hover time
8547 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8549 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8551 infoPtr
->dwHoverTime
= dwHoverTime
;
8553 return oldHoverTime
;
8558 * Sets spacing for icons of LVS_ICON style.
8561 * [I] infoPtr : valid pointer to the listview structure
8562 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8563 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8566 * MAKELONG(oldcx, oldcy)
8568 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8570 INT iconWidth
= 0, iconHeight
= 0;
8571 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8573 TRACE("requested=(%d,%d)\n", cx
, cy
);
8575 /* set to defaults, if instructed to */
8576 if (cx
== -1 && cy
== -1)
8578 infoPtr
->autoSpacing
= TRUE
;
8579 if (infoPtr
->himlNormal
)
8580 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8581 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8582 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8585 infoPtr
->autoSpacing
= FALSE
;
8587 /* if 0 then keep width */
8589 infoPtr
->iconSpacing
.cx
= cx
;
8591 /* if 0 then keep height */
8593 infoPtr
->iconSpacing
.cy
= cy
;
8595 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8596 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8597 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8598 infoPtr
->ntmHeight
);
8600 /* these depend on the iconSpacing */
8601 LISTVIEW_UpdateItemSize(infoPtr
);
8606 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL is_small
)
8610 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8617 size
->cx
= GetSystemMetrics(is_small
? SM_CXSMICON
: SM_CXICON
);
8618 size
->cy
= GetSystemMetrics(is_small
? SM_CYSMICON
: SM_CYICON
);
8627 * [I] infoPtr : valid pointer to the listview structure
8628 * [I] nType : image list type
8629 * [I] himl : image list handle
8632 * SUCCESS : old image list
8635 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8637 INT oldHeight
= infoPtr
->nItemHeight
;
8638 HIMAGELIST himlOld
= 0;
8640 TRACE("(nType=%d, himl=%p)\n", nType
, himl
);
8645 himlOld
= infoPtr
->himlNormal
;
8646 infoPtr
->himlNormal
= himl
;
8647 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8648 if (infoPtr
->autoSpacing
)
8649 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8653 himlOld
= infoPtr
->himlSmall
;
8654 infoPtr
->himlSmall
= himl
;
8655 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8656 if (infoPtr
->hwndHeader
)
8657 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8661 himlOld
= infoPtr
->himlState
;
8662 infoPtr
->himlState
= himl
;
8663 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8664 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8668 ERR("Unknown icon type=%d\n", nType
);
8672 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8673 if (infoPtr
->nItemHeight
!= oldHeight
)
8674 LISTVIEW_UpdateScroll(infoPtr
);
8681 * Preallocates memory (does *not* set the actual count of items !)
8684 * [I] infoPtr : valid pointer to the listview structure
8685 * [I] nItems : item count (projected number of items to allocate)
8686 * [I] dwFlags : update flags
8692 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8694 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8696 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8698 INT nOldCount
= infoPtr
->nItemCount
;
8700 if (nItems
< nOldCount
)
8702 RANGE range
= { nItems
, nOldCount
};
8703 ranges_del(infoPtr
->selectionRanges
, range
);
8704 if (infoPtr
->nFocusedItem
>= nItems
)
8706 LISTVIEW_SetItemFocus(infoPtr
, -1);
8707 SetRectEmpty(&infoPtr
->rcFocus
);
8711 infoPtr
->nItemCount
= nItems
;
8712 LISTVIEW_UpdateScroll(infoPtr
);
8714 /* the flags are valid only in ownerdata report and list modes */
8715 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8717 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8718 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8720 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8721 LISTVIEW_InvalidateList(infoPtr
);
8728 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8729 nFrom
= min(nOldCount
, nItems
);
8730 nTo
= max(nOldCount
, nItems
);
8732 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8735 rcErase
.top
= nFrom
* infoPtr
->nItemHeight
;
8736 rcErase
.right
= infoPtr
->nItemWidth
;
8737 rcErase
.bottom
= nTo
* infoPtr
->nItemHeight
;
8738 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8739 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8740 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8742 else /* LV_VIEW_LIST */
8744 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8746 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8747 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8748 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8749 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8750 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8751 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8752 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8754 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8756 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8757 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8758 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8759 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8760 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8766 /* According to MSDN for non-LVS_OWNERDATA this is just
8767 * a performance issue. The control allocates its internal
8768 * data structures for the number of items specified. It
8769 * cuts down on the number of memory allocations. Therefore
8770 * we will just issue a WARN here
8772 WARN("for non-ownerdata performance option not implemented.\n");
8780 * Sets the position of an item.
8783 * [I] infoPtr : valid pointer to the listview structure
8784 * [I] nItem : item index
8785 * [I] pt : coordinate
8791 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8795 TRACE("(nItem=%d, pt=%s)\n", nItem
, wine_dbgstr_point(pt
));
8797 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8798 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8801 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8803 /* This point value seems to be an undocumented feature.
8804 * The best guess is that it means either at the origin,
8805 * or at true beginning of the list. I will assume the origin. */
8806 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8809 if (infoPtr
->uView
== LV_VIEW_ICON
)
8811 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8812 Pt
.y
-= ICON_TOP_PADDING
;
8817 infoPtr
->bAutoarrange
= FALSE
;
8819 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8824 * Sets the state of one or many items.
8827 * [I] infoPtr : valid pointer to the listview structure
8828 * [I] nItem : item index
8829 * [I] item : item or subitem info
8835 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
8840 if (!item
) return FALSE
;
8842 lvItem
.iItem
= nItem
;
8843 lvItem
.iSubItem
= 0;
8844 lvItem
.mask
= LVIF_STATE
;
8845 lvItem
.state
= item
->state
;
8846 lvItem
.stateMask
= item
->stateMask
;
8847 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8854 /* special case optimization for recurring attempt to deselect all */
8855 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
8858 /* select all isn't allowed in LVS_SINGLESEL */
8859 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8862 /* focus all isn't allowed */
8863 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8865 notify
= infoPtr
->bDoChangeNotify
;
8866 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8868 infoPtr
->bDoChangeNotify
= FALSE
;
8869 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
8870 oldstate
|= LVIS_SELECTED
;
8871 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
8874 /* apply to all items */
8875 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8876 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
8878 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8882 infoPtr
->bDoChangeNotify
= notify
;
8886 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
8887 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
8888 nmlv
.uChanged
= LVIF_STATE
;
8889 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
8892 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
8896 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
8903 * Sets the text of an item or subitem.
8906 * [I] hwnd : window handle
8907 * [I] nItem : item index
8908 * [I] lpLVItem : item or subitem info
8909 * [I] isW : TRUE if input is Unicode
8915 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
8919 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
8920 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
8922 lvItem
.iItem
= nItem
;
8923 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
8924 lvItem
.mask
= LVIF_TEXT
;
8925 lvItem
.pszText
= lpLVItem
->pszText
;
8926 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
8928 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
8930 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
8935 * Set item index that marks the start of a multiple selection.
8938 * [I] infoPtr : valid pointer to the listview structure
8939 * [I] nIndex : index
8942 * Index number or -1 if there is no selection mark.
8944 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
8946 INT nOldIndex
= infoPtr
->nSelectionMark
;
8948 TRACE("(nIndex=%d)\n", nIndex
);
8950 infoPtr
->nSelectionMark
= nIndex
;
8957 * Sets the text background color.
8960 * [I] infoPtr : valid pointer to the listview structure
8961 * [I] color : text background color
8967 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8969 TRACE("(color=%x)\n", color
);
8971 infoPtr
->clrTextBk
= color
;
8977 * Sets the text foreground color.
8980 * [I] infoPtr : valid pointer to the listview structure
8981 * [I] color : text color
8987 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8989 TRACE("(color=%x)\n", color
);
8991 infoPtr
->clrText
= color
;
8997 * Sets new ToolTip window to ListView control.
9000 * [I] infoPtr : valid pointer to the listview structure
9001 * [I] hwndNewToolTip : handle to new ToolTip
9006 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9008 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9009 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9010 return hwndOldToolTip
;
9015 * sets the Unicode character format flag for the control
9017 * [I] infoPtr :valid pointer to the listview structure
9018 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9021 * Old Unicode Format
9023 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9025 SHORT rc
= infoPtr
->notifyFormat
;
9026 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9027 return rc
== NFR_UNICODE
;
9032 * sets the control view mode
9034 * [I] infoPtr :valid pointer to the listview structure
9035 * [I] nView :new view mode value
9041 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9045 if (infoPtr
->uView
== nView
) return 1;
9047 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9048 if (nView
== LV_VIEW_TILE
)
9050 FIXME("View LV_VIEW_TILE unimplemented\n");
9054 infoPtr
->uView
= nView
;
9056 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9057 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9059 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9060 SetRectEmpty(&infoPtr
->rcFocus
);
9062 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9063 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9068 case LV_VIEW_SMALLICON
:
9069 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9071 case LV_VIEW_DETAILS
:
9076 LISTVIEW_CreateHeader( infoPtr
);
9078 hl
.prc
= &infoPtr
->rcList
;
9080 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9081 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9082 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9089 LISTVIEW_UpdateItemSize(infoPtr
);
9090 LISTVIEW_UpdateSize(infoPtr
);
9091 LISTVIEW_UpdateScroll(infoPtr
);
9092 LISTVIEW_InvalidateList(infoPtr
);
9094 TRACE("nView=%d\n", nView
);
9099 /* LISTVIEW_SetWorkAreas */
9103 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9106 * [I] first : pointer to first ITEM_INFO to compare
9107 * [I] second : pointer to second ITEM_INFO to compare
9108 * [I] lParam : HWND of control
9111 * if first comes before second : negative
9112 * if first comes after second : positive
9113 * if first and second are equivalent : zero
9115 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9117 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9118 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9119 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9121 /* Forward the call to the client defined callback */
9122 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9127 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9130 * [I] first : pointer to first ITEM_INFO to compare
9131 * [I] second : pointer to second ITEM_INFO to compare
9132 * [I] lParam : HWND of control
9135 * if first comes before second : negative
9136 * if first comes after second : positive
9137 * if first and second are equivalent : zero
9139 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9141 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9142 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9143 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9145 /* Forward the call to the client defined callback */
9146 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9151 * Sorts the listview items.
9154 * [I] infoPtr : valid pointer to the listview structure
9155 * [I] pfnCompare : application-defined value
9156 * [I] lParamSort : pointer to comparison callback
9157 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9163 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9164 LPARAM lParamSort
, BOOL IsEx
)
9168 LPVOID selectionMarkItem
= NULL
;
9169 LPVOID focusedItem
= NULL
;
9172 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9174 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9176 if (!pfnCompare
) return FALSE
;
9177 if (!infoPtr
->hdpaItems
) return FALSE
;
9179 /* if there are 0 or 1 items, there is no need to sort */
9180 if (infoPtr
->nItemCount
< 2) return TRUE
;
9182 /* clear selection */
9183 ranges_clear(infoPtr
->selectionRanges
);
9185 /* save selection mark and focused item */
9186 if (infoPtr
->nSelectionMark
>= 0)
9187 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9188 if (infoPtr
->nFocusedItem
>= 0)
9189 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9191 infoPtr
->pfnCompare
= pfnCompare
;
9192 infoPtr
->lParamSort
= lParamSort
;
9194 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9196 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9198 /* restore selection ranges */
9199 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9201 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9202 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9204 if (lpItem
->state
& LVIS_SELECTED
)
9205 ranges_additem(infoPtr
->selectionRanges
, i
);
9207 /* restore selection mark and focused item */
9208 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9209 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9211 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9213 /* refresh the display */
9214 LISTVIEW_InvalidateList(infoPtr
);
9220 * Update theme handle after a theme change.
9223 * [I] infoPtr : valid pointer to the listview structure
9227 * FAILURE : something else
9229 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9231 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9232 CloseThemeData(theme
);
9233 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9239 * Updates an items or rearranges the listview control.
9242 * [I] infoPtr : valid pointer to the listview structure
9243 * [I] nItem : item index
9249 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9251 TRACE("(nItem=%d)\n", nItem
);
9253 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9255 /* rearrange with default alignment style */
9256 if (is_autoarrange(infoPtr
))
9257 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9259 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9266 * Draw the track line at the place defined in the infoPtr structure.
9267 * The line is drawn with a XOR pen so drawing the line for the second time
9268 * in the same place erases the line.
9271 * [I] infoPtr : valid pointer to the listview structure
9277 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9281 if (infoPtr
->xTrackLine
== -1)
9284 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9286 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9287 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9288 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9294 * Called when an edit control should be displayed. This function is called after
9295 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9298 * [I] hwnd : Handle to the listview
9299 * [I] uMsg : WM_TIMER (ignored)
9300 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9301 * [I] dwTimer : The elapsed time (ignored)
9306 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9308 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9309 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9311 KillTimer(hwnd
, idEvent
);
9312 editItem
->fEnabled
= FALSE
;
9313 /* check if the item is still selected */
9314 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9315 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9320 * Creates the listview control - the WM_NCCREATE phase.
9323 * [I] hwnd : window handle
9324 * [I] lpcs : the create parameters
9330 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9332 LISTVIEW_INFO
*infoPtr
;
9335 TRACE("(lpcs=%p)\n", lpcs
);
9337 /* initialize info pointer */
9338 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9339 if (!infoPtr
) return FALSE
;
9341 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9343 infoPtr
->hwndSelf
= hwnd
;
9344 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9345 map_style_view(infoPtr
);
9346 /* determine the type of structures to use */
9347 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9348 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9350 /* initialize color information */
9351 infoPtr
->clrBk
= CLR_NONE
;
9352 infoPtr
->clrText
= CLR_DEFAULT
;
9353 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9354 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9355 infoPtr
->bDefaultBkColor
= TRUE
;
9357 /* set default values */
9358 infoPtr
->nFocusedItem
= -1;
9359 infoPtr
->nSelectionMark
= -1;
9360 infoPtr
->nHotItem
= -1;
9361 infoPtr
->bRedraw
= TRUE
;
9362 infoPtr
->bNoItemMetrics
= TRUE
;
9363 infoPtr
->bDoChangeNotify
= TRUE
;
9364 infoPtr
->autoSpacing
= TRUE
;
9365 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9366 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9367 infoPtr
->nEditLabelItem
= -1;
9368 infoPtr
->nLButtonDownItem
= -1;
9369 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9370 infoPtr
->cWheelRemainder
= 0;
9371 infoPtr
->nMeasureItemHeight
= 0;
9372 infoPtr
->xTrackLine
= -1; /* no track line */
9373 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9374 infoPtr
->iVersion
= COMCTL32_VERSION
;
9375 infoPtr
->colRectsDirty
= FALSE
;
9377 /* get default font (icon title) */
9378 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9379 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9380 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9381 LISTVIEW_SaveTextMetrics(infoPtr
);
9383 /* allocate memory for the data structure */
9384 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9385 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9386 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9387 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9388 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9389 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9393 DestroyWindow(infoPtr
->hwndHeader
);
9394 ranges_destroy(infoPtr
->selectionRanges
);
9395 DPA_Destroy(infoPtr
->hdpaItems
);
9396 DPA_Destroy(infoPtr
->hdpaItemIds
);
9397 DPA_Destroy(infoPtr
->hdpaPosX
);
9398 DPA_Destroy(infoPtr
->hdpaPosY
);
9399 DPA_Destroy(infoPtr
->hdpaColumns
);
9406 * Creates the listview control - the WM_CREATE phase. Most of the data is
9407 * already set up in LISTVIEW_NCCreate
9410 * [I] hwnd : window handle
9411 * [I] lpcs : the create parameters
9417 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9419 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9421 TRACE("(lpcs=%p, style=0x%08x)\n", lpcs
, lpcs
->style
);
9423 infoPtr
->dwStyle
= lpcs
->style
;
9424 map_style_view(infoPtr
);
9426 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9427 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9428 /* on error defaulting to ANSI notifications */
9429 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9430 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9432 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9434 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9437 infoPtr
->hwndHeader
= 0;
9439 /* init item size to avoid division by 0 */
9440 LISTVIEW_UpdateItemSize (infoPtr
);
9441 LISTVIEW_UpdateSize (infoPtr
);
9443 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9445 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9447 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9449 LISTVIEW_UpdateScroll(infoPtr
);
9450 /* send WM_MEASUREITEM notification */
9451 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9454 OpenThemeData(hwnd
, themeClass
);
9456 /* initialize the icon sizes */
9457 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9458 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9464 * Destroys the listview control.
9467 * [I] infoPtr : valid pointer to the listview structure
9473 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9475 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9476 CloseThemeData(theme
);
9478 /* delete all items */
9479 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9486 * Enables the listview control.
9489 * [I] infoPtr : valid pointer to the listview structure
9490 * [I] bEnable : specifies whether to enable or disable the window
9496 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9498 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9499 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9505 * Erases the background of the listview control.
9508 * [I] infoPtr : valid pointer to the listview structure
9509 * [I] hdc : device context handle
9515 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9519 TRACE("(hdc=%p)\n", hdc
);
9521 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9523 if (infoPtr
->clrBk
== CLR_NONE
)
9525 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9526 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9527 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9529 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9532 /* for double buffered controls we need to do this during refresh */
9533 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9535 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9541 * Helper function for LISTVIEW_[HV]Scroll *only*.
9542 * Performs vertical/horizontal scrolling by a give amount.
9545 * [I] infoPtr : valid pointer to the listview structure
9546 * [I] dx : amount of horizontal scroll
9547 * [I] dy : amount of vertical scroll
9549 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9551 /* now we can scroll the list */
9552 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9553 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9554 /* if we have focus, adjust rect */
9555 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9556 UpdateWindow(infoPtr
->hwndSelf
);
9561 * Performs vertical scrolling.
9564 * [I] infoPtr : valid pointer to the listview structure
9565 * [I] nScrollCode : scroll code
9566 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9567 * [I] hScrollWnd : scrollbar control window handle
9573 * SB_LINEUP/SB_LINEDOWN:
9574 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9575 * for LVS_REPORT is 1 line
9576 * for LVS_LIST cannot occur
9579 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9582 INT nOldScrollPos
, nNewScrollPos
;
9583 SCROLLINFO scrollInfo
;
9586 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9587 debugscrollcode(nScrollCode
), nScrollDiff
);
9589 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9591 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9592 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9594 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9596 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9598 nOldScrollPos
= scrollInfo
.nPos
;
9599 switch (nScrollCode
)
9605 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9609 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9613 nScrollDiff
= -scrollInfo
.nPage
;
9617 nScrollDiff
= scrollInfo
.nPage
;
9620 case SB_THUMBPOSITION
:
9622 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9629 /* quit right away if pos isn't changing */
9630 if (nScrollDiff
== 0) return 0;
9632 /* calculate new position, and handle overflows */
9633 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9634 if (nScrollDiff
> 0) {
9635 if (nNewScrollPos
< nOldScrollPos
||
9636 nNewScrollPos
> scrollInfo
.nMax
)
9637 nNewScrollPos
= scrollInfo
.nMax
;
9639 if (nNewScrollPos
> nOldScrollPos
||
9640 nNewScrollPos
< scrollInfo
.nMin
)
9641 nNewScrollPos
= scrollInfo
.nMin
;
9644 /* set the new position, and reread in case it changed */
9645 scrollInfo
.fMask
= SIF_POS
;
9646 scrollInfo
.nPos
= nNewScrollPos
;
9647 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9649 /* carry on only if it really changed */
9650 if (nNewScrollPos
== nOldScrollPos
) return 0;
9652 /* now adjust to client coordinates */
9653 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9654 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9656 /* and scroll the window */
9657 scroll_list(infoPtr
, 0, nScrollDiff
);
9664 * Performs horizontal scrolling.
9667 * [I] infoPtr : valid pointer to the listview structure
9668 * [I] nScrollCode : scroll code
9669 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9670 * [I] hScrollWnd : scrollbar control window handle
9676 * SB_LINELEFT/SB_LINERIGHT:
9677 * for LVS_ICON, LVS_SMALLICON 1 pixel
9678 * for LVS_REPORT is 1 pixel
9679 * for LVS_LIST is 1 column --> which is a 1 because the
9680 * scroll is based on columns not pixels
9683 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9686 INT nOldScrollPos
, nNewScrollPos
;
9687 SCROLLINFO scrollInfo
;
9690 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9691 debugscrollcode(nScrollCode
), nScrollDiff
);
9693 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9695 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9696 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9698 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9700 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9702 nOldScrollPos
= scrollInfo
.nPos
;
9704 switch (nScrollCode
)
9710 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9714 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9718 nScrollDiff
= -scrollInfo
.nPage
;
9722 nScrollDiff
= scrollInfo
.nPage
;
9725 case SB_THUMBPOSITION
:
9727 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9734 /* quit right away if pos isn't changing */
9735 if (nScrollDiff
== 0) return 0;
9737 /* calculate new position, and handle overflows */
9738 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9739 if (nScrollDiff
> 0) {
9740 if (nNewScrollPos
< nOldScrollPos
||
9741 nNewScrollPos
> scrollInfo
.nMax
)
9742 nNewScrollPos
= scrollInfo
.nMax
;
9744 if (nNewScrollPos
> nOldScrollPos
||
9745 nNewScrollPos
< scrollInfo
.nMin
)
9746 nNewScrollPos
= scrollInfo
.nMin
;
9749 /* set the new position, and reread in case it changed */
9750 scrollInfo
.fMask
= SIF_POS
;
9751 scrollInfo
.nPos
= nNewScrollPos
;
9752 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9754 /* carry on only if it really changed */
9755 if (nNewScrollPos
== nOldScrollPos
) return 0;
9757 if (infoPtr
->hwndHeader
) LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9759 /* now adjust to client coordinates */
9760 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9761 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9763 /* and scroll the window */
9764 scroll_list(infoPtr
, nScrollDiff
, 0);
9769 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9771 UINT pulScrollLines
= 3;
9773 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9775 switch(infoPtr
->uView
)
9778 case LV_VIEW_SMALLICON
:
9780 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9781 * should be fixed in the future.
9783 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9784 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9787 case LV_VIEW_DETAILS
:
9788 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9790 /* if scrolling changes direction, ignore left overs */
9791 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
9792 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
9793 infoPtr
->cWheelRemainder
+= wheelDelta
;
9795 infoPtr
->cWheelRemainder
= wheelDelta
;
9796 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
9799 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9800 cLineScroll
= pulScrollLines
* (float)infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
9801 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ (int)pulScrollLines
;
9802 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
9807 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9818 * [I] infoPtr : valid pointer to the listview structure
9819 * [I] nVirtualKey : virtual key
9820 * [I] lKeyData : key data
9825 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9827 HWND hwndSelf
= infoPtr
->hwndSelf
;
9829 NMLVKEYDOWN nmKeyDown
;
9831 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9833 /* send LVN_KEYDOWN notification */
9834 nmKeyDown
.wVKey
= nVirtualKey
;
9835 nmKeyDown
.flags
= 0;
9836 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9837 if (!IsWindow(hwndSelf
))
9840 switch (nVirtualKey
)
9843 nItem
= infoPtr
->nFocusedItem
;
9844 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9845 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9849 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9851 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9852 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9857 if (infoPtr
->nItemCount
> 0)
9862 if (infoPtr
->nItemCount
> 0)
9863 nItem
= infoPtr
->nItemCount
- 1;
9867 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9871 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9875 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9879 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
9883 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9885 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9886 if (infoPtr
->nFocusedItem
== topidx
)
9887 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
9892 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
9893 * LISTVIEW_GetCountPerRow(infoPtr
);
9894 if(nItem
< 0) nItem
= 0;
9898 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9900 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9901 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
9902 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
9903 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
9905 nItem
= topidx
+ cnt
- 1;
9908 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
9909 * LISTVIEW_GetCountPerRow(infoPtr
);
9910 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
9914 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
9915 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
9925 * [I] infoPtr : valid pointer to the listview structure
9930 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
9934 /* drop any left over scroll amount */
9935 infoPtr
->cWheelRemainder
= 0;
9937 /* if we did not have the focus, there's nothing more to do */
9938 if (!infoPtr
->bFocus
) return 0;
9940 /* send NM_KILLFOCUS notification */
9941 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
9943 /* if we have a focus rectangle, get rid of it */
9944 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
9946 /* if have a marquee selection, stop it */
9947 if (infoPtr
->bMarqueeSelect
)
9949 /* Remove the marquee rectangle and release our mouse capture */
9950 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
9953 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
9955 infoPtr
->bMarqueeSelect
= FALSE
;
9956 infoPtr
->bScrolling
= FALSE
;
9957 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
9960 /* set window focus flag */
9961 infoPtr
->bFocus
= FALSE
;
9963 /* invalidate the selected items before resetting focus flag */
9964 LISTVIEW_InvalidateSelectedItems(infoPtr
);
9971 * Processes double click messages (left mouse button).
9974 * [I] infoPtr : valid pointer to the listview structure
9975 * [I] wKey : key flag
9976 * [I] x,y : mouse coordinate
9981 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9983 LVHITTESTINFO htInfo
;
9985 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
9987 /* Cancel the item edition if any */
9988 if (infoPtr
->itemEdit
.fEnabled
)
9990 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
9991 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9994 /* send NM_RELEASEDCAPTURE notification */
9995 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10000 /* send NM_DBLCLK notification */
10001 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
10002 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
10004 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
10005 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10010 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10015 r
.top
= r
.bottom
= pt
.y
;
10016 r
.left
= r
.right
= pt
.x
;
10018 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10020 SetCapture(infoPtr
->hwndSelf
);
10024 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10026 if (msg
.message
== WM_MOUSEMOVE
)
10028 pt
.x
= (short)LOWORD(msg
.lParam
);
10029 pt
.y
= (short)HIWORD(msg
.lParam
);
10030 if (PtInRect(&r
, pt
))
10038 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10039 msg
.message
<= WM_RBUTTONDBLCLK
)
10044 DispatchMessageW(&msg
);
10047 if (GetCapture() != infoPtr
->hwndSelf
)
10058 * Processes mouse down messages (left mouse button).
10061 * infoPtr [I ] valid pointer to the listview structure
10062 * wKey [I ] key flag
10063 * x,y [I ] mouse coordinate
10068 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10070 LVHITTESTINFO lvHitTestInfo
;
10071 static BOOL bGroupSelect
= TRUE
;
10072 POINT pt
= { x
, y
};
10075 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10077 /* send NM_RELEASEDCAPTURE notification */
10078 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10080 /* set left button down flag and record the click position */
10081 infoPtr
->bLButtonDown
= TRUE
;
10082 infoPtr
->ptClickPos
= pt
;
10083 infoPtr
->bDragging
= FALSE
;
10084 infoPtr
->bMarqueeSelect
= FALSE
;
10085 infoPtr
->bScrolling
= FALSE
;
10087 lvHitTestInfo
.pt
.x
= x
;
10088 lvHitTestInfo
.pt
.y
= y
;
10090 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10091 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10092 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10094 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10096 toggle_checkbox_state(infoPtr
, nItem
);
10100 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10102 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10103 infoPtr
->nEditLabelItem
= nItem
;
10105 LISTVIEW_SetSelection(infoPtr
, nItem
);
10109 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10113 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10114 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10115 infoPtr
->nSelectionMark
= nItem
;
10121 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10122 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10124 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10125 infoPtr
->nSelectionMark
= nItem
;
10128 else if (wKey
& MK_CONTROL
)
10132 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10134 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10135 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10136 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10137 infoPtr
->nSelectionMark
= nItem
;
10139 else if (wKey
& MK_SHIFT
)
10141 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10145 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10147 infoPtr
->nEditLabelItem
= nItem
;
10148 infoPtr
->nLButtonDownItem
= nItem
;
10150 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10153 /* set selection (clears other pre-existing selections) */
10154 LISTVIEW_SetSelection(infoPtr
, nItem
);
10158 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10159 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10163 if (!infoPtr
->bFocus
)
10164 SetFocus(infoPtr
->hwndSelf
);
10166 /* remove all selections */
10167 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10168 LISTVIEW_DeselectAll(infoPtr
);
10177 * Processes mouse up messages (left mouse button).
10180 * infoPtr [I ] valid pointer to the listview structure
10181 * wKey [I ] key flag
10182 * x,y [I ] mouse coordinate
10187 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10189 LVHITTESTINFO lvHitTestInfo
;
10191 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10193 if (!infoPtr
->bLButtonDown
) return 0;
10195 lvHitTestInfo
.pt
.x
= x
;
10196 lvHitTestInfo
.pt
.y
= y
;
10198 /* send NM_CLICK notification */
10199 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10200 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10202 /* set left button flag */
10203 infoPtr
->bLButtonDown
= FALSE
;
10205 /* set a single selection, reset others */
10206 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10207 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10208 infoPtr
->nLButtonDownItem
= -1;
10210 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10212 /* Remove the marquee rectangle and release our mouse capture */
10213 if (infoPtr
->bMarqueeSelect
)
10215 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10219 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
10220 SetRect(&infoPtr
->marqueeDrawRect
, 0, 0, 0, 0);
10222 infoPtr
->bDragging
= FALSE
;
10223 infoPtr
->bMarqueeSelect
= FALSE
;
10224 infoPtr
->bScrolling
= FALSE
;
10226 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10230 /* if we clicked on a selected item, edit the label */
10231 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10233 /* we want to make sure the user doesn't want to do a double click. So we will
10234 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10236 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10237 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10238 SetTimer(infoPtr
->hwndSelf
,
10239 (UINT_PTR
)&infoPtr
->itemEdit
,
10240 GetDoubleClickTime(),
10241 LISTVIEW_DelayedEditItem
);
10244 if (!infoPtr
->bFocus
)
10245 SetFocus(infoPtr
->hwndSelf
);
10252 * Destroys the listview control (called after WM_DESTROY).
10255 * [I] infoPtr : valid pointer to the listview structure
10260 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10266 /* destroy data structure */
10267 DPA_Destroy(infoPtr
->hdpaItems
);
10268 DPA_Destroy(infoPtr
->hdpaItemIds
);
10269 DPA_Destroy(infoPtr
->hdpaPosX
);
10270 DPA_Destroy(infoPtr
->hdpaPosY
);
10272 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10273 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10274 DPA_Destroy(infoPtr
->hdpaColumns
);
10275 ranges_destroy(infoPtr
->selectionRanges
);
10277 /* destroy image lists */
10278 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10280 ImageList_Destroy(infoPtr
->himlNormal
);
10281 ImageList_Destroy(infoPtr
->himlSmall
);
10282 ImageList_Destroy(infoPtr
->himlState
);
10285 /* destroy font, bkgnd brush */
10286 infoPtr
->hFont
= 0;
10287 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10288 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10290 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10292 /* free listview info pointer*/
10300 * Handles notifications.
10303 * [I] infoPtr : valid pointer to the listview structure
10304 * [I] lpnmhdr : notification information
10309 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10313 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10315 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10317 /* remember: HDN_LAST < HDN_FIRST */
10318 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10319 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10321 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10323 switch (lpnmhdr
->code
)
10328 COLUMN_INFO
*lpColumnInfo
;
10332 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10335 /* remove the old line (if any) */
10336 LISTVIEW_DrawTrackLine(infoPtr
);
10338 /* compute & draw the new line */
10339 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10340 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10341 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10342 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10343 LISTVIEW_DrawTrackLine(infoPtr
);
10344 return notify_forward_header(infoPtr
, lpnmh
);
10347 case HDN_ENDTRACKA
:
10348 case HDN_ENDTRACKW
:
10349 /* remove the track line (if any) */
10350 LISTVIEW_DrawTrackLine(infoPtr
);
10351 infoPtr
->xTrackLine
= -1;
10352 return notify_forward_header(infoPtr
, lpnmh
);
10354 case HDN_BEGINDRAG
:
10355 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10356 return notify_forward_header(infoPtr
, lpnmh
);
10359 infoPtr
->colRectsDirty
= TRUE
;
10360 LISTVIEW_InvalidateList(infoPtr
);
10361 return notify_forward_header(infoPtr
, lpnmh
);
10363 case HDN_ITEMCHANGEDW
:
10364 case HDN_ITEMCHANGEDA
:
10366 COLUMN_INFO
*lpColumnInfo
;
10370 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10372 hdi
.mask
= HDI_WIDTH
;
10373 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10377 cxy
= lpnmh
->pitem
->cxy
;
10379 /* determine how much we change since the last know position */
10380 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10381 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10384 lpColumnInfo
->rcHeader
.right
+= dx
;
10386 hdi
.mask
= HDI_ORDER
;
10387 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10389 /* not the rightmost one */
10390 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10392 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10393 hdi
.iOrder
+ 1, 0);
10394 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10398 /* only needs to update the scrolls */
10399 infoPtr
->nItemWidth
+= dx
;
10400 LISTVIEW_UpdateScroll(infoPtr
);
10402 LISTVIEW_UpdateItemSize(infoPtr
);
10403 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10406 RECT rcCol
= lpColumnInfo
->rcHeader
;
10408 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10409 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10411 rcCol
.top
= infoPtr
->rcList
.top
;
10412 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10414 /* resizing left-aligned columns leaves most of the left side untouched */
10415 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10417 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10420 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10423 /* when shrinking the last column clear the now unused field */
10424 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10430 /* deal with right from rightmost column area */
10431 right
.left
= rcCol
.right
;
10432 right
.top
= rcCol
.top
;
10433 right
.bottom
= rcCol
.bottom
;
10434 right
.right
= infoPtr
->rcList
.right
;
10436 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10439 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10445 case HDN_ITEMCLICKW
:
10446 case HDN_ITEMCLICKA
:
10448 /* Handle sorting by Header Column */
10451 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10453 nmlv
.iSubItem
= lpnmh
->iItem
;
10454 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10455 return notify_forward_header(infoPtr
, lpnmh
);
10458 case HDN_DIVIDERDBLCLICKW
:
10459 case HDN_DIVIDERDBLCLICKA
:
10460 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10461 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10462 split needed for that */
10463 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10464 return notify_forward_header(infoPtr
, lpnmh
);
10471 * Paint non-client area of control.
10474 * [I] infoPtr : valid pointer to the listview structureof the sender
10475 * [I] region : update region
10478 * TRUE - frame was painted
10479 * FALSE - call default window proc
10481 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10483 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10487 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10488 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10491 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10493 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10495 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10496 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10497 if (region
!= (HRGN
)1)
10498 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10499 OffsetRect(&r
, -r
.left
, -r
.top
);
10501 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10502 OffsetRect(&r
, -r
.left
, -r
.top
);
10504 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10505 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10506 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10507 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10509 /* Call default proc to get the scrollbars etc. painted */
10510 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10517 * Determines the type of structure to use.
10520 * [I] infoPtr : valid pointer to the listview structureof the sender
10521 * [I] hwndFrom : listview window handle
10522 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10527 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10529 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10531 if (nCommand
== NF_REQUERY
)
10532 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10534 return infoPtr
->notifyFormat
;
10539 * Paints/Repaints the listview control. Internal use.
10542 * [I] infoPtr : valid pointer to the listview structure
10543 * [I] hdc : device context handle
10548 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10550 TRACE("(hdc=%p)\n", hdc
);
10552 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10554 infoPtr
->bNoItemMetrics
= FALSE
;
10555 LISTVIEW_UpdateItemSize(infoPtr
);
10556 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10557 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10558 LISTVIEW_UpdateScroll(infoPtr
);
10561 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10564 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10569 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10570 if (!hdc
) return 1;
10571 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10572 EndPaint(infoPtr
->hwndSelf
, &ps
);
10580 * Paints/Repaints the listview control, WM_PAINT handler.
10583 * [I] infoPtr : valid pointer to the listview structure
10584 * [I] hdc : device context handle
10589 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10591 TRACE("(hdc=%p)\n", hdc
);
10593 if (!is_redrawing(infoPtr
))
10594 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10596 return LISTVIEW_Paint(infoPtr
, hdc
);
10601 * Paints/Repaints the listview control.
10604 * [I] infoPtr : valid pointer to the listview structure
10605 * [I] hdc : device context handle
10606 * [I] options : drawing options
10611 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10613 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
10615 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10618 if (options
& PRF_ERASEBKGND
)
10619 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10621 if (options
& PRF_CLIENT
)
10622 LISTVIEW_Paint(infoPtr
, hdc
);
10630 * Processes double click messages (right mouse button).
10633 * [I] infoPtr : valid pointer to the listview structure
10634 * [I] wKey : key flag
10635 * [I] x,y : mouse coordinate
10640 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10642 LVHITTESTINFO lvHitTestInfo
;
10644 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10646 /* send NM_RELEASEDCAPTURE notification */
10647 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10649 /* send NM_RDBLCLK notification */
10650 lvHitTestInfo
.pt
.x
= x
;
10651 lvHitTestInfo
.pt
.y
= y
;
10652 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10653 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10660 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10663 * [I] infoPtr : valid pointer to the listview structure
10664 * [I] wKey : key flag
10665 * [I] x, y : mouse coordinate
10670 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10675 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10677 /* send NM_RELEASEDCAPTURE notification */
10678 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10680 /* determine the index of the selected item */
10683 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10685 /* make sure the listview control window has the focus */
10686 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10688 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10690 LISTVIEW_SetItemFocus(infoPtr
, item
);
10691 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10692 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10693 LISTVIEW_SetSelection(infoPtr
, item
);
10696 LISTVIEW_DeselectAll(infoPtr
);
10698 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10700 if (ht
.iItem
!= -1)
10704 memset(&nmlv
, 0, sizeof(nmlv
));
10705 nmlv
.iItem
= ht
.iItem
;
10706 nmlv
.ptAction
= ht
.pt
;
10708 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10713 SetFocus(infoPtr
->hwndSelf
);
10717 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10719 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10721 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10722 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10723 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10735 * [I] infoPtr : valid pointer to the listview structure
10736 * [I] hwnd : window handle of window containing the cursor
10737 * [I] nHittest : hit-test code
10738 * [I] wMouseMsg : ideintifier of the mouse message
10741 * TRUE if cursor is set
10744 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10746 LVHITTESTINFO lvHitTestInfo
;
10748 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10750 if (!infoPtr
->hHotCursor
) goto forward
;
10752 GetCursorPos(&lvHitTestInfo
.pt
);
10753 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10755 SetCursor(infoPtr
->hHotCursor
);
10761 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10769 * [I] infoPtr : valid pointer to the listview structure
10770 * [I] hwndLoseFocus : handle of previously focused window
10775 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10777 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10779 /* if we have the focus already, there's nothing to do */
10780 if (infoPtr
->bFocus
) return 0;
10782 /* send NM_SETFOCUS notification */
10783 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10785 /* set window focus flag */
10786 infoPtr
->bFocus
= TRUE
;
10788 /* put the focus rect back on */
10789 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10791 /* redraw all visible selected items */
10792 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10802 * [I] infoPtr : valid pointer to the listview structure
10803 * [I] fRedraw : font handle
10804 * [I] fRedraw : redraw flag
10809 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10811 HFONT oldFont
= infoPtr
->hFont
;
10812 INT oldHeight
= infoPtr
->nItemHeight
;
10814 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10816 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10817 if (infoPtr
->hFont
== oldFont
) return 0;
10819 LISTVIEW_SaveTextMetrics(infoPtr
);
10821 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
10823 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10825 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10826 LISTVIEW_UpdateSize(infoPtr
);
10827 LISTVIEW_UpdateScroll(infoPtr
);
10829 else if (infoPtr
->nItemHeight
!= oldHeight
)
10830 LISTVIEW_UpdateScroll(infoPtr
);
10832 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10839 * Message handling for WM_SETREDRAW.
10840 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10843 * [I] infoPtr : valid pointer to the listview structure
10844 * [I] bRedraw: state of redraw flag
10847 * DefWinProc return value
10849 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
10851 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr
->bRedraw
, bRedraw
);
10853 /* we cannot use straight equality here because _any_ non-zero value is TRUE */
10854 if ((infoPtr
->bRedraw
&& bRedraw
) || (!infoPtr
->bRedraw
&& !bRedraw
)) return 0;
10856 infoPtr
->bRedraw
= bRedraw
;
10858 if(!bRedraw
) return 0;
10860 if (is_autoarrange(infoPtr
))
10861 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10862 LISTVIEW_UpdateScroll(infoPtr
);
10864 /* despite what the WM_SETREDRAW docs says, apps expect us
10865 * to invalidate the listview here... stupid! */
10866 LISTVIEW_InvalidateList(infoPtr
);
10873 * Resizes the listview control. This function processes WM_SIZE
10874 * messages. At this time, the width and height are not used.
10877 * [I] infoPtr : valid pointer to the listview structure
10878 * [I] Width : new width
10879 * [I] Height : new height
10884 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
10886 RECT rcOld
= infoPtr
->rcList
;
10888 TRACE("(width=%d, height=%d)\n", Width
, Height
);
10890 LISTVIEW_UpdateSize(infoPtr
);
10891 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
10893 /* do not bother with display related stuff if we're not redrawing */
10894 if (!is_redrawing(infoPtr
)) return 0;
10896 if (is_autoarrange(infoPtr
))
10897 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10899 LISTVIEW_UpdateScroll(infoPtr
);
10901 /* refresh all only for lists whose height changed significantly */
10902 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
10903 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
10904 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
10905 LISTVIEW_InvalidateList(infoPtr
);
10912 * Sets the size information.
10915 * [I] infoPtr : valid pointer to the listview structure
10920 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
10922 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
10924 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
10926 if (infoPtr
->uView
== LV_VIEW_LIST
)
10928 /* Apparently the "LIST" style is supposed to have the same
10929 * number of items in a column even if there is no scroll bar.
10930 * Since if a scroll bar already exists then the bottom is already
10931 * reduced, only reduce if the scroll bar does not currently exist.
10932 * The "2" is there to mimic the native control. I think it may be
10933 * related to either padding or edges. (GLA 7/2002)
10935 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
10936 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
10937 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
10940 /* if control created invisible header isn't created */
10941 if (infoPtr
->hwndHeader
)
10946 hl
.prc
= &infoPtr
->rcList
;
10948 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
10949 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10951 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
10952 wp
.flags
|= SWP_SHOWWINDOW
;
10955 wp
.flags
|= SWP_HIDEWINDOW
;
10959 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
10960 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10962 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
10964 /* extra padding for grid */
10965 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
10966 infoPtr
->rcList
.top
+= 2;
10968 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
10973 * Processes WM_STYLECHANGED messages.
10976 * [I] infoPtr : valid pointer to the listview structure
10977 * [I] wStyleType : window style type (normal or extended)
10978 * [I] lpss : window style information
10983 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
10984 const STYLESTRUCT
*lpss
)
10986 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
10987 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
10990 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
10991 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
10993 if (wStyleType
!= GWL_STYLE
) return 0;
10995 infoPtr
->dwStyle
= lpss
->styleNew
;
10996 map_style_view(infoPtr
);
10998 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
10999 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
11000 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
11002 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
11003 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
11004 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11006 if (uNewView
!= uOldView
)
11010 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11011 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11013 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11014 SetRectEmpty(&infoPtr
->rcFocus
);
11016 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11017 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11019 if (uNewView
== LVS_REPORT
)
11024 LISTVIEW_CreateHeader( infoPtr
);
11026 hl
.prc
= &infoPtr
->rcList
;
11028 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11029 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11030 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11031 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11034 LISTVIEW_UpdateItemSize(infoPtr
);
11037 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11039 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11041 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11043 /* Turn off the header control */
11044 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11045 TRACE("Hide header control, was 0x%08x\n", style
);
11046 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11048 /* Turn on the header control */
11049 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11051 TRACE("Show header control, was 0x%08x\n", style
);
11052 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11058 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11059 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11060 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11062 /* update the size of the client area */
11063 LISTVIEW_UpdateSize(infoPtr
);
11065 /* add scrollbars if needed */
11066 LISTVIEW_UpdateScroll(infoPtr
);
11068 /* invalidate client area + erase background */
11069 LISTVIEW_InvalidateList(infoPtr
);
11076 * Processes WM_STYLECHANGING messages.
11079 * [I] wStyleType : window style type (normal or extended)
11080 * [I0] lpss : window style information
11085 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11088 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11089 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11091 /* don't forward LVS_OWNERDATA only if not already set to */
11092 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11094 if (lpss
->styleOld
& LVS_OWNERDATA
)
11095 lpss
->styleNew
|= LVS_OWNERDATA
;
11097 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11105 * Processes WM_SHOWWINDOW messages.
11108 * [I] infoPtr : valid pointer to the listview structure
11109 * [I] bShown : window is being shown (FALSE when hidden)
11110 * [I] iStatus : window show status
11115 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11117 /* header delayed creation */
11118 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11120 LISTVIEW_CreateHeader(infoPtr
);
11122 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11123 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11126 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11131 * Processes CCM_GETVERSION messages.
11134 * [I] infoPtr : valid pointer to the listview structure
11139 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11141 return infoPtr
->iVersion
;
11146 * Processes CCM_SETVERSION messages.
11149 * [I] infoPtr : valid pointer to the listview structure
11150 * [I] iVersion : version to be set
11153 * -1 when requested version is greater than DLL version;
11154 * previous version otherwise
11156 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11158 INT iOldVersion
= infoPtr
->iVersion
;
11160 if (iVersion
> COMCTL32_VERSION
)
11163 infoPtr
->iVersion
= iVersion
;
11165 TRACE("new version %d\n", iVersion
);
11167 return iOldVersion
;
11172 * Window procedure of the listview control.
11175 static LRESULT WINAPI
11176 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11178 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11180 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11182 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11183 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11187 case LVM_APPROXIMATEVIEWRECT
:
11188 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11189 LOWORD(lParam
), HIWORD(lParam
));
11191 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11193 case LVM_CANCELEDITLABEL
:
11194 return LISTVIEW_CancelEditLabel(infoPtr
);
11196 case LVM_CREATEDRAGIMAGE
:
11197 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11199 case LVM_DELETEALLITEMS
:
11200 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11202 case LVM_DELETECOLUMN
:
11203 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11205 case LVM_DELETEITEM
:
11206 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11208 case LVM_EDITLABELA
:
11209 case LVM_EDITLABELW
:
11210 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11211 uMsg
== LVM_EDITLABELW
);
11212 /* case LVM_ENABLEGROUPVIEW: */
11214 case LVM_ENSUREVISIBLE
:
11215 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11217 case LVM_FINDITEMW
:
11218 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11220 case LVM_FINDITEMA
:
11221 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11223 case LVM_GETBKCOLOR
:
11224 return infoPtr
->clrBk
;
11226 /* case LVM_GETBKIMAGE: */
11228 case LVM_GETCALLBACKMASK
:
11229 return infoPtr
->uCallbackMask
;
11231 case LVM_GETCOLUMNA
:
11232 case LVM_GETCOLUMNW
:
11233 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11234 uMsg
== LVM_GETCOLUMNW
);
11236 case LVM_GETCOLUMNORDERARRAY
:
11237 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11239 case LVM_GETCOLUMNWIDTH
:
11240 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11242 case LVM_GETCOUNTPERPAGE
:
11243 return LISTVIEW_GetCountPerPage(infoPtr
);
11245 case LVM_GETEDITCONTROL
:
11246 return (LRESULT
)infoPtr
->hwndEdit
;
11248 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11249 return infoPtr
->dwLvExStyle
;
11251 /* case LVM_GETGROUPINFO: */
11253 /* case LVM_GETGROUPMETRICS: */
11255 case LVM_GETHEADER
:
11256 return (LRESULT
)infoPtr
->hwndHeader
;
11258 case LVM_GETHOTCURSOR
:
11259 return (LRESULT
)infoPtr
->hHotCursor
;
11261 case LVM_GETHOTITEM
:
11262 return infoPtr
->nHotItem
;
11264 case LVM_GETHOVERTIME
:
11265 return infoPtr
->dwHoverTime
;
11267 case LVM_GETIMAGELIST
:
11268 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11270 /* case LVM_GETINSERTMARK: */
11272 /* case LVM_GETINSERTMARKCOLOR: */
11274 /* case LVM_GETINSERTMARKRECT: */
11276 case LVM_GETISEARCHSTRINGA
:
11277 case LVM_GETISEARCHSTRINGW
:
11278 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11283 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11285 case LVM_GETITEMCOUNT
:
11286 return infoPtr
->nItemCount
;
11288 case LVM_GETITEMPOSITION
:
11289 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11291 case LVM_GETITEMRECT
:
11292 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11294 case LVM_GETITEMSPACING
:
11295 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11297 case LVM_GETITEMSTATE
:
11298 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11300 case LVM_GETITEMTEXTA
:
11301 case LVM_GETITEMTEXTW
:
11302 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11303 uMsg
== LVM_GETITEMTEXTW
);
11305 case LVM_GETNEXTITEM
:
11306 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11308 case LVM_GETNUMBEROFWORKAREAS
:
11309 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11312 case LVM_GETORIGIN
:
11313 if (!lParam
) return FALSE
;
11314 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11315 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11316 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11319 /* case LVM_GETOUTLINECOLOR: */
11321 /* case LVM_GETSELECTEDCOLUMN: */
11323 case LVM_GETSELECTEDCOUNT
:
11324 return LISTVIEW_GetSelectedCount(infoPtr
);
11326 case LVM_GETSELECTIONMARK
:
11327 return infoPtr
->nSelectionMark
;
11329 case LVM_GETSTRINGWIDTHA
:
11330 case LVM_GETSTRINGWIDTHW
:
11331 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11332 uMsg
== LVM_GETSTRINGWIDTHW
);
11334 case LVM_GETSUBITEMRECT
:
11335 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11337 case LVM_GETTEXTBKCOLOR
:
11338 return infoPtr
->clrTextBk
;
11340 case LVM_GETTEXTCOLOR
:
11341 return infoPtr
->clrText
;
11343 /* case LVM_GETTILEINFO: */
11345 /* case LVM_GETTILEVIEWINFO: */
11347 case LVM_GETTOOLTIPS
:
11348 if( !infoPtr
->hwndToolTip
)
11349 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11350 return (LRESULT
)infoPtr
->hwndToolTip
;
11352 case LVM_GETTOPINDEX
:
11353 return LISTVIEW_GetTopIndex(infoPtr
);
11355 case LVM_GETUNICODEFORMAT
:
11356 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11359 return infoPtr
->uView
;
11361 case LVM_GETVIEWRECT
:
11362 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11364 case LVM_GETWORKAREAS
:
11365 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11368 /* case LVM_HASGROUP: */
11371 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11373 case LVM_INSERTCOLUMNA
:
11374 case LVM_INSERTCOLUMNW
:
11375 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11376 uMsg
== LVM_INSERTCOLUMNW
);
11378 /* case LVM_INSERTGROUP: */
11380 /* case LVM_INSERTGROUPSORTED: */
11382 case LVM_INSERTITEMA
:
11383 case LVM_INSERTITEMW
:
11384 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11386 /* case LVM_INSERTMARKHITTEST: */
11388 /* case LVM_ISGROUPVIEWENABLED: */
11390 case LVM_ISITEMVISIBLE
:
11391 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11393 case LVM_MAPIDTOINDEX
:
11394 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11396 case LVM_MAPINDEXTOID
:
11397 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11399 /* case LVM_MOVEGROUP: */
11401 /* case LVM_MOVEITEMTOGROUP: */
11403 case LVM_REDRAWITEMS
:
11404 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11406 /* case LVM_REMOVEALLGROUPS: */
11408 /* case LVM_REMOVEGROUP: */
11411 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11413 case LVM_SETBKCOLOR
:
11414 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11416 /* case LVM_SETBKIMAGE: */
11418 case LVM_SETCALLBACKMASK
:
11419 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11422 case LVM_SETCOLUMNA
:
11423 case LVM_SETCOLUMNW
:
11424 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11425 uMsg
== LVM_SETCOLUMNW
);
11427 case LVM_SETCOLUMNORDERARRAY
:
11428 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11430 case LVM_SETCOLUMNWIDTH
:
11431 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11433 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11434 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11436 /* case LVM_SETGROUPINFO: */
11438 /* case LVM_SETGROUPMETRICS: */
11440 case LVM_SETHOTCURSOR
:
11441 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11443 case LVM_SETHOTITEM
:
11444 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11446 case LVM_SETHOVERTIME
:
11447 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11449 case LVM_SETICONSPACING
:
11451 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11452 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11454 case LVM_SETIMAGELIST
:
11455 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11457 /* case LVM_SETINFOTIP: */
11459 /* case LVM_SETINSERTMARK: */
11461 /* case LVM_SETINSERTMARKCOLOR: */
11466 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11467 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11470 case LVM_SETITEMCOUNT
:
11471 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11473 case LVM_SETITEMPOSITION
:
11476 pt
.x
= (short)LOWORD(lParam
);
11477 pt
.y
= (short)HIWORD(lParam
);
11478 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11481 case LVM_SETITEMPOSITION32
:
11482 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11484 case LVM_SETITEMSTATE
:
11485 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11487 case LVM_SETITEMTEXTA
:
11488 case LVM_SETITEMTEXTW
:
11489 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11490 uMsg
== LVM_SETITEMTEXTW
);
11492 /* case LVM_SETOUTLINECOLOR: */
11494 /* case LVM_SETSELECTEDCOLUMN: */
11496 case LVM_SETSELECTIONMARK
:
11497 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11499 case LVM_SETTEXTBKCOLOR
:
11500 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11502 case LVM_SETTEXTCOLOR
:
11503 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11505 /* case LVM_SETTILEINFO: */
11507 /* case LVM_SETTILEVIEWINFO: */
11509 /* case LVM_SETTILEWIDTH: */
11511 case LVM_SETTOOLTIPS
:
11512 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11514 case LVM_SETUNICODEFORMAT
:
11515 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11518 return LISTVIEW_SetView(infoPtr
, wParam
);
11520 /* case LVM_SETWORKAREAS: */
11522 /* case LVM_SORTGROUPS: */
11524 case LVM_SORTITEMS
:
11525 case LVM_SORTITEMSEX
:
11526 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11527 uMsg
== LVM_SORTITEMSEX
);
11528 case LVM_SUBITEMHITTEST
:
11529 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11532 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11534 case CCM_GETVERSION
:
11535 return LISTVIEW_GetVersion(infoPtr
);
11537 case CCM_SETVERSION
:
11538 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11541 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11544 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11547 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
11550 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11553 return LISTVIEW_Destroy(infoPtr
);
11556 return LISTVIEW_Enable(infoPtr
);
11558 case WM_ERASEBKGND
:
11559 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11561 case WM_GETDLGCODE
:
11562 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11565 return (LRESULT
)infoPtr
->hFont
;
11568 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11571 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11574 return LISTVIEW_KillFocus(infoPtr
);
11576 case WM_LBUTTONDBLCLK
:
11577 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11579 case WM_LBUTTONDOWN
:
11580 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11583 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11586 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11588 case WM_MOUSEHOVER
:
11589 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11592 return LISTVIEW_NCDestroy(infoPtr
);
11595 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11598 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11600 case WM_NOTIFYFORMAT
:
11601 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11603 case WM_PRINTCLIENT
:
11604 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11607 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11609 case WM_RBUTTONDBLCLK
:
11610 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11612 case WM_RBUTTONDOWN
:
11613 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11616 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11619 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11622 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11625 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11627 case WM_SHOWWINDOW
:
11628 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11630 case WM_STYLECHANGED
:
11631 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11633 case WM_STYLECHANGING
:
11634 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11636 case WM_SYSCOLORCHANGE
:
11637 COMCTL32_RefreshSysColors();
11638 if (infoPtr
->bDefaultBkColor
)
11640 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
11641 infoPtr
->bDefaultBkColor
= TRUE
;
11642 LISTVIEW_InvalidateList(infoPtr
);
11646 /* case WM_TIMER: */
11647 case WM_THEMECHANGED
:
11648 return LISTVIEW_ThemeChanged(infoPtr
);
11651 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11653 case WM_MOUSEWHEEL
:
11654 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11655 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11656 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11658 case WM_WINDOWPOSCHANGED
:
11659 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11661 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11662 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11664 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11666 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11668 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11670 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11672 /* case WM_WININICHANGE: */
11675 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11676 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11678 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11685 * Registers the window class.
11693 void LISTVIEW_Register(void)
11695 WNDCLASSW wndClass
;
11697 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11698 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11699 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11700 wndClass
.cbClsExtra
= 0;
11701 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11702 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11703 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11704 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11705 RegisterClassW(&wndClass
);
11710 * Unregisters the window class.
11718 void LISTVIEW_Unregister(void)
11720 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11725 * Handle any WM_COMMAND messages
11728 * [I] infoPtr : valid pointer to the listview structure
11729 * [I] wParam : the first message parameter
11730 * [I] lParam : the second message parameter
11735 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11738 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11740 if (!infoPtr
->hwndEdit
) return 0;
11742 switch (HIWORD(wParam
))
11747 * Adjust the edit window size
11749 WCHAR buffer
[1024];
11750 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11751 HFONT hFont
, hOldFont
= 0;
11755 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11756 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
11757 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11759 /* Select font to get the right dimension of the string */
11760 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11763 hOldFont
= SelectObject(hdc
, hFont
);
11766 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11768 TEXTMETRICW textMetric
;
11770 /* Add Extra spacing for the next character */
11771 GetTextMetricsW(hdc
, &textMetric
);
11772 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11774 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11775 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11778 SelectObject(hdc
, hOldFont
);
11780 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11786 LISTVIEW_CancelEditLabel(infoPtr
);
11791 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);